]>
Commit | Line | Data |
---|---|---|
a3f97cbb | 1 | /* Output Dwarf2 format symbol table information from the GNU C compiler. |
54ba1f0d | 2 | Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 |
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 | 7 | |
1322177d | 8 | This file is part of GCC. |
a3f97cbb | 9 | |
1322177d LB |
10 | GCC is free software; you can redistribute it and/or modify it under |
11 | the terms of the GNU General Public License as published by the Free | |
12 | Software Foundation; either version 2, or (at your option) any later | |
13 | version. | |
a3f97cbb | 14 | |
1322177d LB |
15 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
16 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
18 | for more details. | |
a3f97cbb JW |
19 | |
20 | You should have received a copy of the GNU General Public License | |
1322177d LB |
21 | along with GCC; see the file COPYING. If not, write to the Free |
22 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
23 | 02111-1307, USA. */ | |
a3f97cbb | 24 | |
9eb4015a | 25 | /* TODO: Emit .debug_line header even when there are no functions, since |
348bb3c7 JM |
26 | the file numbers are used by .debug_info. Alternately, leave |
27 | out locations for types and decls. | |
28 | Avoid talking about ctors and op= for PODs. | |
29 | Factor out common prologue sequences into multiple CIEs. */ | |
30 | ||
3f76745e JM |
31 | /* The first part of this file deals with the DWARF 2 frame unwind |
32 | information, which is also used by the GCC efficient exception handling | |
33 | mechanism. The second part, controlled only by an #ifdef | |
34 | DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging | |
35 | information. */ | |
36 | ||
0021b564 | 37 | #include "config.h" |
670ee920 | 38 | #include "system.h" |
a3f97cbb JW |
39 | #include "tree.h" |
40 | #include "flags.h" | |
41 | #include "rtl.h" | |
42 | #include "hard-reg-set.h" | |
43 | #include "regs.h" | |
44 | #include "insn-config.h" | |
45 | #include "reload.h" | |
52a11cbf | 46 | #include "function.h" |
a3f97cbb | 47 | #include "output.h" |
71dfc51f | 48 | #include "expr.h" |
e78d8e51 | 49 | #include "libfuncs.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" |
2a2b2d43 | 59 | #include "diagnostic.h" |
a51d908e | 60 | #include "debug.h" |
07c9d2eb | 61 | #include "target.h" |
3ac88239 | 62 | #include "langhooks.h" |
9eb4015a | 63 | #include "hashtable.h" |
a3f97cbb | 64 | |
653e276c NB |
65 | #ifdef DWARF2_DEBUGGING_INFO |
66 | static void dwarf2out_source_line PARAMS ((unsigned int, const char *)); | |
67 | #endif | |
68 | ||
770ca8c6 JO |
69 | /* DWARF2 Abbreviation Glossary: |
70 | CFA = Canonical Frame Address | |
00a42e21 JM |
71 | a fixed address on the stack which identifies a call frame. |
72 | We define it to be the value of SP just before the call insn. | |
73 | The CFA register and offset, which may change during the course | |
74 | of the function, are used to calculate its value at runtime. | |
a401107d JO |
75 | CFI = Call Frame Instruction |
76 | an instruction for the DWARF2 abstract machine | |
770ca8c6 JO |
77 | CIE = Common Information Entry |
78 | information describing information common to one or more FDEs | |
79 | DIE = Debugging Information Entry | |
80 | FDE = Frame Description Entry | |
81 | information describing the stack call frame, in particular, | |
82 | how to restore registers | |
83 | ||
84 | DW_CFA_... = DWARF2 CFA call frame instruction | |
85 | DW_TAG_... = DWARF2 DIE tag */ | |
86 | ||
0021b564 JM |
87 | /* Decide whether we want to emit frame unwind information for the current |
88 | translation unit. */ | |
89 | ||
90 | int | |
91 | dwarf2out_do_frame () | |
92 | { | |
93 | return (write_symbols == DWARF2_DEBUG | |
7a0c8d71 | 94 | || write_symbols == VMS_AND_DWARF2_DEBUG |
9ec36da5 | 95 | #ifdef DWARF2_FRAME_INFO |
556273e0 | 96 | || DWARF2_FRAME_INFO |
9ec36da5 | 97 | #endif |
0021b564 | 98 | #ifdef DWARF2_UNWIND_INFO |
14a774a9 | 99 | || flag_unwind_tables |
531073e7 | 100 | || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS) |
0021b564 JM |
101 | #endif |
102 | ); | |
103 | } | |
104 | ||
b1e6ab03 RH |
105 | /* The number of the current function definition for which debugging |
106 | information is being generated. These numbers range from 1 up to the | |
107 | maximum number of function definitions contained within the current | |
108 | compilation unit. These numbers are used to create unique label id's | |
109 | unique to each function definition. */ | |
110 | unsigned current_funcdef_number = 0; | |
111 | ||
f3a8e4f5 KG |
112 | /* The size of the target's pointer type. */ |
113 | #ifndef PTR_SIZE | |
114 | #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT) | |
115 | #endif | |
116 | ||
117 | /* Default version of targetm.eh_frame_section. Note this must appear | |
118 | outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro | |
119 | guards. */ | |
120 | ||
121 | void | |
122 | default_eh_frame_section () | |
123 | { | |
124 | #ifdef EH_FRAME_SECTION_NAME | |
125 | named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE); | |
126 | #else | |
127 | tree label = get_file_function_name ('F'); | |
128 | ||
129 | data_section (); | |
130 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); | |
131 | ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); | |
132 | ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); | |
133 | #endif | |
134 | } | |
135 | ||
0021b564 JM |
136 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) |
137 | ||
eaf95893 RK |
138 | /* How to start an assembler comment. */ |
139 | #ifndef ASM_COMMENT_START | |
140 | #define ASM_COMMENT_START ";#" | |
141 | #endif | |
142 | ||
a3f97cbb JW |
143 | typedef struct dw_cfi_struct *dw_cfi_ref; |
144 | typedef struct dw_fde_struct *dw_fde_ref; | |
145 | typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref; | |
a3f97cbb JW |
146 | |
147 | /* Call frames are described using a sequence of Call Frame | |
148 | Information instructions. The register number, offset | |
149 | and address fields are provided as possible operands; | |
150 | their use is selected by the opcode field. */ | |
71dfc51f | 151 | |
a3f97cbb | 152 | typedef union dw_cfi_oprnd_struct |
71dfc51f RK |
153 | { |
154 | unsigned long dw_cfi_reg_num; | |
155 | long int dw_cfi_offset; | |
d3e3972c | 156 | const char *dw_cfi_addr; |
7d9d8943 | 157 | struct dw_loc_descr_struct *dw_cfi_loc; |
71dfc51f | 158 | } |
a3f97cbb JW |
159 | dw_cfi_oprnd; |
160 | ||
161 | typedef struct dw_cfi_struct | |
71dfc51f RK |
162 | { |
163 | dw_cfi_ref dw_cfi_next; | |
164 | enum dwarf_call_frame_info dw_cfi_opc; | |
165 | dw_cfi_oprnd dw_cfi_oprnd1; | |
166 | dw_cfi_oprnd dw_cfi_oprnd2; | |
167 | } | |
a3f97cbb JW |
168 | dw_cfi_node; |
169 | ||
7d9d8943 AM |
170 | /* This is how we define the location of the CFA. We use to handle it |
171 | as REG + OFFSET all the time, but now it can be more complex. | |
172 | It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET. | |
556273e0 | 173 | Instead of passing around REG and OFFSET, we pass a copy |
7d9d8943 AM |
174 | of this structure. */ |
175 | typedef struct cfa_loc | |
176 | { | |
556273e0 | 177 | unsigned long reg; |
7d9d8943 AM |
178 | long offset; |
179 | long base_offset; | |
180 | int indirect; /* 1 if CFA is accessed via a dereference. */ | |
181 | } dw_cfa_location; | |
182 | ||
a3f97cbb | 183 | /* All call frame descriptions (FDE's) in the GCC generated DWARF |
4b674448 | 184 | refer to a single Common Information Entry (CIE), defined at |
fb530c07 | 185 | the beginning of the .debug_frame section. This use of a single |
a3f97cbb JW |
186 | CIE obviates the need to keep track of multiple CIE's |
187 | in the DWARF generation routines below. */ | |
71dfc51f | 188 | |
a3f97cbb | 189 | typedef struct dw_fde_struct |
71dfc51f | 190 | { |
d3e3972c KG |
191 | const char *dw_fde_begin; |
192 | const char *dw_fde_current_label; | |
193 | const char *dw_fde_end; | |
71dfc51f | 194 | dw_cfi_ref dw_fde_cfi; |
52a11cbf RH |
195 | unsigned funcdef_number; |
196 | unsigned nothrow : 1; | |
197 | unsigned uses_eh_lsda : 1; | |
71dfc51f | 198 | } |
a3f97cbb JW |
199 | dw_fde_node; |
200 | ||
6d2f8887 | 201 | /* Maximum size (in bytes) of an artificially generated label. */ |
a3f97cbb JW |
202 | #define MAX_ARTIFICIAL_LABEL_BYTES 30 |
203 | ||
a1a4189d JB |
204 | /* The size of addresses as they appear in the Dwarf 2 data. |
205 | Some architectures use word addresses to refer to code locations, | |
206 | but Dwarf 2 info always uses byte addresses. On such machines, | |
207 | Dwarf 2 addresses need to be larger than the architecture's | |
208 | pointers. */ | |
209 | #ifndef DWARF2_ADDR_SIZE | |
210 | #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT) | |
211 | #endif | |
212 | ||
7e23cb16 | 213 | /* The size in bytes of a DWARF field indicating an offset or length |
a1a4189d JB |
214 | relative to a debug info section, specified to be 4 bytes in the |
215 | DWARF-2 specification. The SGI/MIPS ABI defines it to be the same | |
b13fe8bf | 216 | as PTR_SIZE. */ |
71dfc51f | 217 | |
7e23cb16 JM |
218 | #ifndef DWARF_OFFSET_SIZE |
219 | #define DWARF_OFFSET_SIZE 4 | |
220 | #endif | |
221 | ||
9a666dda JM |
222 | #define DWARF_VERSION 2 |
223 | ||
7e23cb16 JM |
224 | /* Round SIZE up to the nearest BOUNDARY. */ |
225 | #define DWARF_ROUND(SIZE,BOUNDARY) \ | |
262b6384 | 226 | ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY)) |
a3f97cbb | 227 | |
a3f97cbb | 228 | /* Offsets recorded in opcodes are a multiple of this alignment factor. */ |
27c35f4b | 229 | #ifndef DWARF_CIE_DATA_ALIGNMENT |
469ac993 | 230 | #ifdef STACK_GROWS_DOWNWARD |
08cb3d38 | 231 | #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD)) |
469ac993 | 232 | #else |
08cb3d38 | 233 | #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD) |
469ac993 | 234 | #endif |
2ad9852d | 235 | #endif |
a3f97cbb | 236 | |
3f76745e JM |
237 | /* A pointer to the base of a table that contains frame description |
238 | information for each routine. */ | |
239 | static dw_fde_ref fde_table; | |
a3f97cbb | 240 | |
3f76745e JM |
241 | /* Number of elements currently allocated for fde_table. */ |
242 | static unsigned fde_table_allocated; | |
a94dbf2c | 243 | |
3f76745e JM |
244 | /* Number of elements in fde_table currently in use. */ |
245 | static unsigned fde_table_in_use; | |
a3f97cbb | 246 | |
3f76745e JM |
247 | /* Size (in elements) of increments by which we may expand the |
248 | fde_table. */ | |
249 | #define FDE_TABLE_INCREMENT 256 | |
a3f97cbb | 250 | |
a94dbf2c JM |
251 | /* A list of call frame insns for the CIE. */ |
252 | static dw_cfi_ref cie_cfi_head; | |
253 | ||
a3f97cbb JW |
254 | /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram |
255 | attribute that accelerates the lookup of the FDE associated | |
556273e0 | 256 | with the subprogram. This variable holds the table index of the FDE |
a3f97cbb JW |
257 | associated with the current function (body) definition. */ |
258 | static unsigned current_funcdef_fde; | |
259 | ||
9eb4015a JJ |
260 | struct ht *debug_str_hash; |
261 | ||
262 | struct indirect_string_node | |
263 | { | |
264 | struct ht_identifier id; | |
265 | unsigned int refcount; | |
266 | unsigned int form; | |
267 | char *label; | |
268 | }; | |
269 | ||
a3f97cbb | 270 | /* Forward declarations for functions defined in this file. */ |
71dfc51f | 271 | |
83d2b3b9 KG |
272 | static char *stripattributes PARAMS ((const char *)); |
273 | static const char *dwarf_cfi_name PARAMS ((unsigned)); | |
274 | static dw_cfi_ref new_cfi PARAMS ((void)); | |
275 | static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref)); | |
d3e3972c | 276 | static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref)); |
2ad9852d RK |
277 | static void lookup_cfa_1 PARAMS ((dw_cfi_ref, |
278 | dw_cfa_location *)); | |
7d9d8943 | 279 | static void lookup_cfa PARAMS ((dw_cfa_location *)); |
d3e3972c KG |
280 | static void reg_save PARAMS ((const char *, unsigned, |
281 | unsigned, long)); | |
83d2b3b9 | 282 | static void initial_return_save PARAMS ((rtx)); |
5e640c56 | 283 | static long stack_adjust_offset PARAMS ((rtx)); |
12f0b96b | 284 | static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int)); |
83d2b3b9 | 285 | static void output_call_frame_info PARAMS ((int)); |
83d2b3b9 | 286 | static void dwarf2out_stack_adjust PARAMS ((rtx)); |
fbfa55b0 RH |
287 | static void queue_reg_save PARAMS ((const char *, rtx, long)); |
288 | static void flush_queued_reg_saves PARAMS ((void)); | |
289 | static bool clobbers_queued_reg_save PARAMS ((rtx)); | |
d3e3972c | 290 | static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *)); |
a3f97cbb | 291 | |
7d9d8943 AM |
292 | /* Support for complex CFA locations. */ |
293 | static void output_cfa_loc PARAMS ((dw_cfi_ref)); | |
556273e0 | 294 | static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *, |
7d9d8943 AM |
295 | struct dw_loc_descr_struct *)); |
296 | static struct dw_loc_descr_struct *build_cfa_loc | |
297 | PARAMS ((dw_cfa_location *)); | |
2ad9852d RK |
298 | static void def_cfa_1 PARAMS ((const char *, |
299 | dw_cfa_location *)); | |
7d9d8943 | 300 | |
2e4b9b8c RH |
301 | /* How to start an assembler comment. */ |
302 | #ifndef ASM_COMMENT_START | |
303 | #define ASM_COMMENT_START ";#" | |
a3f97cbb JW |
304 | #endif |
305 | ||
7e23cb16 JM |
306 | /* Data and reference forms for relocatable data. */ |
307 | #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4) | |
308 | #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4) | |
309 | ||
a3f97cbb JW |
310 | /* Pseudo-op for defining a new section. */ |
311 | #ifndef SECTION_ASM_OP | |
0a3e1f45 | 312 | #define SECTION_ASM_OP "\t.section\t" |
a3f97cbb JW |
313 | #endif |
314 | ||
cf2fe500 RH |
315 | #ifndef DEBUG_FRAME_SECTION |
316 | #define DEBUG_FRAME_SECTION ".debug_frame" | |
a3f97cbb | 317 | #endif |
a3f97cbb | 318 | |
5c90448c JM |
319 | #ifndef FUNC_BEGIN_LABEL |
320 | #define FUNC_BEGIN_LABEL "LFB" | |
a3f97cbb | 321 | #endif |
2ad9852d | 322 | |
5c90448c JM |
323 | #ifndef FUNC_END_LABEL |
324 | #define FUNC_END_LABEL "LFE" | |
a3f97cbb | 325 | #endif |
2ad9852d | 326 | |
27d95cbe | 327 | #define FRAME_BEGIN_LABEL "Lframe" |
a6ab3aad JM |
328 | #define CIE_AFTER_SIZE_LABEL "LSCIE" |
329 | #define CIE_END_LABEL "LECIE" | |
2ed2af28 | 330 | #define CIE_LENGTH_LABEL "LLCIE" |
2e4b9b8c RH |
331 | #define FDE_LABEL "LSFDE" |
332 | #define FDE_AFTER_SIZE_LABEL "LASFDE" | |
a6ab3aad | 333 | #define FDE_END_LABEL "LEFDE" |
2ed2af28 | 334 | #define FDE_LENGTH_LABEL "LLFDE" |
981975b6 RH |
335 | #define LINE_NUMBER_BEGIN_LABEL "LSLT" |
336 | #define LINE_NUMBER_END_LABEL "LELT" | |
337 | #define LN_PROLOG_AS_LABEL "LASLTP" | |
338 | #define LN_PROLOG_END_LABEL "LELTP" | |
881c6935 | 339 | #define DIE_LABEL_PREFIX "DW" |
a3f97cbb | 340 | |
a3f97cbb JW |
341 | /* Definitions of defaults for various types of primitive assembly language |
342 | output operations. These may be overridden from within the tm.h file, | |
956d6950 | 343 | but typically, that is unnecessary. */ |
71dfc51f | 344 | |
2ed2af28 PDM |
345 | #ifdef SET_ASM_OP |
346 | #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL | |
7bb9fb0e JM |
347 | #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \ |
348 | do { \ | |
e8638df0 | 349 | fprintf (FILE, "%s", SET_ASM_OP); \ |
7bb9fb0e JM |
350 | assemble_name (FILE, SY); \ |
351 | fputc (',', FILE); \ | |
352 | assemble_name (FILE, HI); \ | |
353 | fputc ('-', FILE); \ | |
354 | assemble_name (FILE, LO); \ | |
355 | } while (0) | |
2ed2af28 | 356 | #endif |
2ad9852d | 357 | #endif |
2ed2af28 | 358 | |
c8cc5c4a | 359 | /* The DWARF 2 CFA column which tracks the return address. Normally this |
a94dbf2c JM |
360 | is the column for PC, or the first column after all of the hard |
361 | registers. */ | |
c8cc5c4a | 362 | #ifndef DWARF_FRAME_RETURN_COLUMN |
a94dbf2c JM |
363 | #ifdef PC_REGNUM |
364 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM) | |
365 | #else | |
3073d01c | 366 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS |
a94dbf2c | 367 | #endif |
c8cc5c4a JM |
368 | #endif |
369 | ||
370 | /* The mapping from gcc register number to DWARF 2 CFA column number. By | |
469ac993 | 371 | default, we just provide columns for all registers. */ |
c8cc5c4a | 372 | #ifndef DWARF_FRAME_REGNUM |
469ac993 | 373 | #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG) |
c8cc5c4a | 374 | #endif |
3f76745e | 375 | |
2ad9852d RK |
376 | /* The offset from the incoming value of %sp to the top of the stack frame |
377 | for the current function. */ | |
378 | #ifndef INCOMING_FRAME_SP_OFFSET | |
379 | #define INCOMING_FRAME_SP_OFFSET 0 | |
380 | #endif | |
381 | \f | |
0021b564 JM |
382 | /* Hook used by __throw. */ |
383 | ||
384 | rtx | |
385 | expand_builtin_dwarf_fp_regnum () | |
386 | { | |
387 | return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM)); | |
388 | } | |
389 | ||
71dfc51f | 390 | /* Return a pointer to a copy of the section string name S with all |
bf20f341 | 391 | attributes stripped off, and an asterisk prepended (for assemble_name). */ |
71dfc51f RK |
392 | |
393 | static inline char * | |
a3f97cbb | 394 | stripattributes (s) |
d560ee52 | 395 | const char *s; |
a3f97cbb | 396 | { |
bf20f341 | 397 | char *stripped = xmalloc (strlen (s) + 2); |
71dfc51f RK |
398 | char *p = stripped; |
399 | ||
bf20f341 JW |
400 | *p++ = '*'; |
401 | ||
402 | while (*s && *s != ',') | |
403 | *p++ = *s++; | |
71dfc51f | 404 | |
a3f97cbb JW |
405 | *p = '\0'; |
406 | return stripped; | |
407 | } | |
408 | ||
d9d5c9de | 409 | /* Generate code to initialize the register size table. */ |
2f3ca9e7 | 410 | |
d9d5c9de BS |
411 | void |
412 | expand_builtin_init_dwarf_reg_sizes (address) | |
413 | tree address; | |
2f3ca9e7 | 414 | { |
d9d5c9de BS |
415 | int i; |
416 | enum machine_mode mode = TYPE_MODE (char_type_node); | |
417 | rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0); | |
2ad9852d | 418 | rtx mem = gen_rtx_MEM (BLKmode, addr); |
2f3ca9e7 | 419 | |
2ad9852d | 420 | for (i = 0; i < DWARF_FRAME_REGISTERS; i++) |
2f3ca9e7 | 421 | { |
2ad9852d RK |
422 | HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode); |
423 | HOST_WIDE_INT size = GET_MODE_SIZE (reg_raw_mode[i]); | |
2f3ca9e7 | 424 | |
c699cee9 JM |
425 | if (offset < 0) |
426 | continue; | |
427 | ||
f4ef873c | 428 | emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size)); |
2f3ca9e7 | 429 | } |
2f3ca9e7 JM |
430 | } |
431 | ||
3f76745e | 432 | /* Convert a DWARF call frame info. operation to its string name */ |
a3f97cbb | 433 | |
d560ee52 | 434 | static const char * |
3f76745e | 435 | dwarf_cfi_name (cfi_opc) |
b3694847 | 436 | unsigned cfi_opc; |
3f76745e JM |
437 | { |
438 | switch (cfi_opc) | |
439 | { | |
440 | case DW_CFA_advance_loc: | |
441 | return "DW_CFA_advance_loc"; | |
442 | case DW_CFA_offset: | |
443 | return "DW_CFA_offset"; | |
444 | case DW_CFA_restore: | |
445 | return "DW_CFA_restore"; | |
446 | case DW_CFA_nop: | |
447 | return "DW_CFA_nop"; | |
448 | case DW_CFA_set_loc: | |
449 | return "DW_CFA_set_loc"; | |
450 | case DW_CFA_advance_loc1: | |
451 | return "DW_CFA_advance_loc1"; | |
452 | case DW_CFA_advance_loc2: | |
453 | return "DW_CFA_advance_loc2"; | |
454 | case DW_CFA_advance_loc4: | |
455 | return "DW_CFA_advance_loc4"; | |
456 | case DW_CFA_offset_extended: | |
457 | return "DW_CFA_offset_extended"; | |
458 | case DW_CFA_restore_extended: | |
459 | return "DW_CFA_restore_extended"; | |
460 | case DW_CFA_undefined: | |
461 | return "DW_CFA_undefined"; | |
462 | case DW_CFA_same_value: | |
463 | return "DW_CFA_same_value"; | |
464 | case DW_CFA_register: | |
465 | return "DW_CFA_register"; | |
466 | case DW_CFA_remember_state: | |
467 | return "DW_CFA_remember_state"; | |
468 | case DW_CFA_restore_state: | |
469 | return "DW_CFA_restore_state"; | |
470 | case DW_CFA_def_cfa: | |
471 | return "DW_CFA_def_cfa"; | |
472 | case DW_CFA_def_cfa_register: | |
473 | return "DW_CFA_def_cfa_register"; | |
474 | case DW_CFA_def_cfa_offset: | |
475 | return "DW_CFA_def_cfa_offset"; | |
7d9d8943 AM |
476 | case DW_CFA_def_cfa_expression: |
477 | return "DW_CFA_def_cfa_expression"; | |
c53aa195 | 478 | |
3f76745e JM |
479 | /* SGI/MIPS specific */ |
480 | case DW_CFA_MIPS_advance_loc8: | |
481 | return "DW_CFA_MIPS_advance_loc8"; | |
c53aa195 JM |
482 | |
483 | /* GNU extensions */ | |
484 | case DW_CFA_GNU_window_save: | |
485 | return "DW_CFA_GNU_window_save"; | |
0021b564 JM |
486 | case DW_CFA_GNU_args_size: |
487 | return "DW_CFA_GNU_args_size"; | |
3f388b42 GK |
488 | case DW_CFA_GNU_negative_offset_extended: |
489 | return "DW_CFA_GNU_negative_offset_extended"; | |
c53aa195 | 490 | |
3f76745e JM |
491 | default: |
492 | return "DW_CFA_<unknown>"; | |
493 | } | |
494 | } | |
a3f97cbb | 495 | |
3f76745e | 496 | /* Return a pointer to a newly allocated Call Frame Instruction. */ |
71dfc51f | 497 | |
3f76745e JM |
498 | static inline dw_cfi_ref |
499 | new_cfi () | |
500 | { | |
b3694847 | 501 | dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node)); |
71dfc51f | 502 | |
3f76745e JM |
503 | cfi->dw_cfi_next = NULL; |
504 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0; | |
505 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0; | |
a3f97cbb | 506 | |
3f76745e JM |
507 | return cfi; |
508 | } | |
a3f97cbb | 509 | |
3f76745e | 510 | /* Add a Call Frame Instruction to list of instructions. */ |
a3f97cbb | 511 | |
3f76745e JM |
512 | static inline void |
513 | add_cfi (list_head, cfi) | |
b3694847 SS |
514 | dw_cfi_ref *list_head; |
515 | dw_cfi_ref cfi; | |
3f76745e | 516 | { |
b3694847 | 517 | dw_cfi_ref *p; |
a3f97cbb | 518 | |
3f76745e JM |
519 | /* Find the end of the chain. */ |
520 | for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next) | |
521 | ; | |
522 | ||
523 | *p = cfi; | |
a3f97cbb JW |
524 | } |
525 | ||
3f76745e | 526 | /* Generate a new label for the CFI info to refer to. */ |
71dfc51f | 527 | |
c53aa195 | 528 | char * |
3f76745e | 529 | dwarf2out_cfi_label () |
a3f97cbb | 530 | { |
3f76745e JM |
531 | static char label[20]; |
532 | static unsigned long label_num = 0; | |
556273e0 | 533 | |
3f76745e JM |
534 | ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++); |
535 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
3f76745e | 536 | return label; |
a3f97cbb JW |
537 | } |
538 | ||
3f76745e JM |
539 | /* Add CFI to the current fde at the PC value indicated by LABEL if specified, |
540 | or to the CIE if LABEL is NULL. */ | |
71dfc51f | 541 | |
3f76745e JM |
542 | static void |
543 | add_fde_cfi (label, cfi) | |
b3694847 SS |
544 | const char *label; |
545 | dw_cfi_ref cfi; | |
a3f97cbb | 546 | { |
3f76745e JM |
547 | if (label) |
548 | { | |
b3694847 | 549 | dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
a3f97cbb | 550 | |
3f76745e JM |
551 | if (*label == 0) |
552 | label = dwarf2out_cfi_label (); | |
71dfc51f | 553 | |
3f76745e JM |
554 | if (fde->dw_fde_current_label == NULL |
555 | || strcmp (label, fde->dw_fde_current_label) != 0) | |
556 | { | |
b3694847 | 557 | dw_cfi_ref xcfi; |
a3f97cbb | 558 | |
3f76745e | 559 | fde->dw_fde_current_label = label = xstrdup (label); |
71dfc51f | 560 | |
3f76745e JM |
561 | /* Set the location counter to the new label. */ |
562 | xcfi = new_cfi (); | |
563 | xcfi->dw_cfi_opc = DW_CFA_advance_loc4; | |
564 | xcfi->dw_cfi_oprnd1.dw_cfi_addr = label; | |
565 | add_cfi (&fde->dw_fde_cfi, xcfi); | |
566 | } | |
71dfc51f | 567 | |
3f76745e JM |
568 | add_cfi (&fde->dw_fde_cfi, cfi); |
569 | } | |
570 | ||
571 | else | |
572 | add_cfi (&cie_cfi_head, cfi); | |
a3f97cbb JW |
573 | } |
574 | ||
3f76745e | 575 | /* Subroutine of lookup_cfa. */ |
71dfc51f | 576 | |
3f76745e | 577 | static inline void |
7d9d8943 | 578 | lookup_cfa_1 (cfi, loc) |
b3694847 SS |
579 | dw_cfi_ref cfi; |
580 | dw_cfa_location *loc; | |
a3f97cbb | 581 | { |
3f76745e JM |
582 | switch (cfi->dw_cfi_opc) |
583 | { | |
584 | case DW_CFA_def_cfa_offset: | |
7d9d8943 | 585 | loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset; |
3f76745e JM |
586 | break; |
587 | case DW_CFA_def_cfa_register: | |
7d9d8943 | 588 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
3f76745e JM |
589 | break; |
590 | case DW_CFA_def_cfa: | |
7d9d8943 AM |
591 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
592 | loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset; | |
593 | break; | |
594 | case DW_CFA_def_cfa_expression: | |
595 | get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc); | |
3f76745e | 596 | break; |
e9a25f70 JL |
597 | default: |
598 | break; | |
3f76745e | 599 | } |
a3f97cbb JW |
600 | } |
601 | ||
3f76745e | 602 | /* Find the previous value for the CFA. */ |
71dfc51f | 603 | |
3f76745e | 604 | static void |
7d9d8943 | 605 | lookup_cfa (loc) |
b3694847 | 606 | dw_cfa_location *loc; |
a3f97cbb | 607 | { |
b3694847 | 608 | dw_cfi_ref cfi; |
3f76745e | 609 | |
7d9d8943 AM |
610 | loc->reg = (unsigned long) -1; |
611 | loc->offset = 0; | |
612 | loc->indirect = 0; | |
613 | loc->base_offset = 0; | |
3f76745e JM |
614 | |
615 | for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next) | |
7d9d8943 | 616 | lookup_cfa_1 (cfi, loc); |
3f76745e JM |
617 | |
618 | if (fde_table_in_use) | |
a3f97cbb | 619 | { |
b3694847 | 620 | dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
3f76745e | 621 | for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next) |
7d9d8943 | 622 | lookup_cfa_1 (cfi, loc); |
a3f97cbb JW |
623 | } |
624 | } | |
625 | ||
3f76745e | 626 | /* The current rule for calculating the DWARF2 canonical frame address. */ |
fbfa55b0 | 627 | static dw_cfa_location cfa; |
71dfc51f | 628 | |
3f76745e JM |
629 | /* The register used for saving registers to the stack, and its offset |
630 | from the CFA. */ | |
fbfa55b0 | 631 | static dw_cfa_location cfa_store; |
3f76745e | 632 | |
0021b564 JM |
633 | /* The running total of the size of arguments pushed onto the stack. */ |
634 | static long args_size; | |
635 | ||
b57d9225 JM |
636 | /* The last args_size we actually output. */ |
637 | static long old_args_size; | |
638 | ||
3f76745e JM |
639 | /* Entry point to update the canonical frame address (CFA). |
640 | LABEL is passed to add_fde_cfi. The value of CFA is now to be | |
641 | calculated from REG+OFFSET. */ | |
642 | ||
643 | void | |
644 | dwarf2out_def_cfa (label, reg, offset) | |
b3694847 | 645 | const char *label; |
7d9d8943 AM |
646 | unsigned reg; |
647 | long offset; | |
648 | { | |
649 | dw_cfa_location loc; | |
650 | loc.indirect = 0; | |
651 | loc.base_offset = 0; | |
652 | loc.reg = reg; | |
653 | loc.offset = offset; | |
654 | def_cfa_1 (label, &loc); | |
655 | } | |
656 | ||
770ca8c6 | 657 | /* This routine does the actual work. The CFA is now calculated from |
7d9d8943 | 658 | the dw_cfa_location structure. */ |
2ad9852d | 659 | |
7d9d8943 AM |
660 | static void |
661 | def_cfa_1 (label, loc_p) | |
b3694847 | 662 | const char *label; |
7d9d8943 | 663 | dw_cfa_location *loc_p; |
a3f97cbb | 664 | { |
b3694847 | 665 | dw_cfi_ref cfi; |
7d9d8943 | 666 | dw_cfa_location old_cfa, loc; |
3f76745e | 667 | |
7d9d8943 AM |
668 | cfa = *loc_p; |
669 | loc = *loc_p; | |
5bef9b1f | 670 | |
7d9d8943 AM |
671 | if (cfa_store.reg == loc.reg && loc.indirect == 0) |
672 | cfa_store.offset = loc.offset; | |
3f76745e | 673 | |
7d9d8943 AM |
674 | loc.reg = DWARF_FRAME_REGNUM (loc.reg); |
675 | lookup_cfa (&old_cfa); | |
676 | ||
2ad9852d RK |
677 | /* If nothing changed, no need to issue any call frame instructions. */ |
678 | if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset | |
679 | && loc.indirect == old_cfa.indirect | |
680 | && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset)) | |
681 | return; | |
3f76745e JM |
682 | |
683 | cfi = new_cfi (); | |
684 | ||
e09bbb25 | 685 | if (loc.reg == old_cfa.reg && !loc.indirect) |
a3f97cbb | 686 | { |
770ca8c6 JO |
687 | /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, |
688 | indicating the CFA register did not change but the offset | |
689 | did. */ | |
3f76745e | 690 | cfi->dw_cfi_opc = DW_CFA_def_cfa_offset; |
7d9d8943 | 691 | cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset; |
3f76745e | 692 | } |
a3f97cbb | 693 | |
3f76745e | 694 | #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */ |
7d9d8943 | 695 | else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1 |
e09bbb25 | 696 | && !loc.indirect) |
3f76745e | 697 | { |
770ca8c6 JO |
698 | /* Construct a "DW_CFA_def_cfa_register <register>" instruction, |
699 | indicating the CFA register has changed to <register> but the | |
700 | offset has not changed. */ | |
3f76745e | 701 | cfi->dw_cfi_opc = DW_CFA_def_cfa_register; |
7d9d8943 | 702 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
3f76745e JM |
703 | } |
704 | #endif | |
a3f97cbb | 705 | |
7d9d8943 | 706 | else if (loc.indirect == 0) |
3f76745e | 707 | { |
770ca8c6 JO |
708 | /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction, |
709 | indicating the CFA register has changed to <register> with | |
710 | the specified offset. */ | |
3f76745e | 711 | cfi->dw_cfi_opc = DW_CFA_def_cfa; |
7d9d8943 AM |
712 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
713 | cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset; | |
714 | } | |
715 | else | |
716 | { | |
770ca8c6 JO |
717 | /* Construct a DW_CFA_def_cfa_expression instruction to |
718 | calculate the CFA using a full location expression since no | |
719 | register-offset pair is available. */ | |
556273e0 | 720 | struct dw_loc_descr_struct *loc_list; |
2ad9852d | 721 | |
7d9d8943 AM |
722 | cfi->dw_cfi_opc = DW_CFA_def_cfa_expression; |
723 | loc_list = build_cfa_loc (&loc); | |
724 | cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list; | |
a3f97cbb | 725 | } |
3f76745e JM |
726 | |
727 | add_fde_cfi (label, cfi); | |
a3f97cbb JW |
728 | } |
729 | ||
3f76745e JM |
730 | /* Add the CFI for saving a register. REG is the CFA column number. |
731 | LABEL is passed to add_fde_cfi. | |
732 | If SREG is -1, the register is saved at OFFSET from the CFA; | |
733 | otherwise it is saved in SREG. */ | |
71dfc51f | 734 | |
3f76745e JM |
735 | static void |
736 | reg_save (label, reg, sreg, offset) | |
b3694847 SS |
737 | const char *label; |
738 | unsigned reg; | |
739 | unsigned sreg; | |
740 | long offset; | |
a3f97cbb | 741 | { |
b3694847 | 742 | dw_cfi_ref cfi = new_cfi (); |
3f76745e JM |
743 | |
744 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
745 | ||
85066503 MH |
746 | /* The following comparison is correct. -1 is used to indicate that |
747 | the value isn't a register number. */ | |
748 | if (sreg == (unsigned int) -1) | |
a3f97cbb | 749 | { |
3f76745e JM |
750 | if (reg & ~0x3f) |
751 | /* The register number won't fit in 6 bits, so we have to use | |
752 | the long form. */ | |
753 | cfi->dw_cfi_opc = DW_CFA_offset_extended; | |
754 | else | |
755 | cfi->dw_cfi_opc = DW_CFA_offset; | |
756 | ||
27c35f4b HPN |
757 | #ifdef ENABLE_CHECKING |
758 | { | |
759 | /* If we get an offset that is not a multiple of | |
760 | DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the | |
761 | definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine | |
762 | description. */ | |
763 | long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT; | |
764 | ||
765 | if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset) | |
766 | abort (); | |
767 | } | |
768 | #endif | |
3f76745e | 769 | offset /= DWARF_CIE_DATA_ALIGNMENT; |
3a88cbd1 | 770 | if (offset < 0) |
3f388b42 GK |
771 | { |
772 | cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended; | |
773 | offset = -offset; | |
774 | } | |
2ad9852d | 775 | |
3f76745e JM |
776 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; |
777 | } | |
2c849145 JM |
778 | else if (sreg == reg) |
779 | /* We could emit a DW_CFA_same_value in this case, but don't bother. */ | |
780 | return; | |
3f76745e JM |
781 | else |
782 | { | |
783 | cfi->dw_cfi_opc = DW_CFA_register; | |
784 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg; | |
785 | } | |
786 | ||
787 | add_fde_cfi (label, cfi); | |
788 | } | |
789 | ||
c53aa195 JM |
790 | /* Add the CFI for saving a register window. LABEL is passed to reg_save. |
791 | This CFI tells the unwinder that it needs to restore the window registers | |
792 | from the previous frame's window save area. | |
556273e0 | 793 | |
c53aa195 JM |
794 | ??? Perhaps we should note in the CIE where windows are saved (instead of |
795 | assuming 0(cfa)) and what registers are in the window. */ | |
796 | ||
797 | void | |
798 | dwarf2out_window_save (label) | |
b3694847 | 799 | const char *label; |
c53aa195 | 800 | { |
b3694847 | 801 | dw_cfi_ref cfi = new_cfi (); |
2ad9852d | 802 | |
c53aa195 JM |
803 | cfi->dw_cfi_opc = DW_CFA_GNU_window_save; |
804 | add_fde_cfi (label, cfi); | |
805 | } | |
806 | ||
0021b564 JM |
807 | /* Add a CFI to update the running total of the size of arguments |
808 | pushed onto the stack. */ | |
809 | ||
810 | void | |
811 | dwarf2out_args_size (label, size) | |
d3e3972c | 812 | const char *label; |
0021b564 JM |
813 | long size; |
814 | { | |
b3694847 | 815 | dw_cfi_ref cfi; |
b57d9225 JM |
816 | |
817 | if (size == old_args_size) | |
818 | return; | |
2ad9852d | 819 | |
b57d9225 JM |
820 | old_args_size = size; |
821 | ||
822 | cfi = new_cfi (); | |
0021b564 JM |
823 | cfi->dw_cfi_opc = DW_CFA_GNU_args_size; |
824 | cfi->dw_cfi_oprnd1.dw_cfi_offset = size; | |
825 | add_fde_cfi (label, cfi); | |
826 | } | |
827 | ||
c53aa195 JM |
828 | /* Entry point for saving a register to the stack. REG is the GCC register |
829 | number. LABEL and OFFSET are passed to reg_save. */ | |
3f76745e JM |
830 | |
831 | void | |
832 | dwarf2out_reg_save (label, reg, offset) | |
b3694847 SS |
833 | const char *label; |
834 | unsigned reg; | |
835 | long offset; | |
3f76745e JM |
836 | { |
837 | reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset); | |
838 | } | |
839 | ||
c53aa195 JM |
840 | /* Entry point for saving the return address in the stack. |
841 | LABEL and OFFSET are passed to reg_save. */ | |
842 | ||
843 | void | |
844 | dwarf2out_return_save (label, offset) | |
b3694847 SS |
845 | const char *label; |
846 | long offset; | |
c53aa195 JM |
847 | { |
848 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset); | |
849 | } | |
850 | ||
851 | /* Entry point for saving the return address in a register. | |
852 | LABEL and SREG are passed to reg_save. */ | |
853 | ||
854 | void | |
855 | dwarf2out_return_reg (label, sreg) | |
b3694847 SS |
856 | const char *label; |
857 | unsigned sreg; | |
c53aa195 JM |
858 | { |
859 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0); | |
860 | } | |
861 | ||
3f76745e JM |
862 | /* Record the initial position of the return address. RTL is |
863 | INCOMING_RETURN_ADDR_RTX. */ | |
864 | ||
865 | static void | |
866 | initial_return_save (rtl) | |
b3694847 | 867 | rtx rtl; |
3f76745e | 868 | { |
973838fd | 869 | unsigned int reg = (unsigned int) -1; |
2ad9852d | 870 | HOST_WIDE_INT offset = 0; |
3f76745e JM |
871 | |
872 | switch (GET_CODE (rtl)) | |
873 | { | |
874 | case REG: | |
875 | /* RA is in a register. */ | |
2c849145 | 876 | reg = DWARF_FRAME_REGNUM (REGNO (rtl)); |
3f76745e | 877 | break; |
2ad9852d | 878 | |
3f76745e JM |
879 | case MEM: |
880 | /* RA is on the stack. */ | |
881 | rtl = XEXP (rtl, 0); | |
882 | switch (GET_CODE (rtl)) | |
883 | { | |
884 | case REG: | |
3a88cbd1 JL |
885 | if (REGNO (rtl) != STACK_POINTER_REGNUM) |
886 | abort (); | |
3f76745e JM |
887 | offset = 0; |
888 | break; | |
2ad9852d | 889 | |
3f76745e | 890 | case PLUS: |
3a88cbd1 JL |
891 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
892 | abort (); | |
3f76745e JM |
893 | offset = INTVAL (XEXP (rtl, 1)); |
894 | break; | |
2ad9852d | 895 | |
3f76745e | 896 | case MINUS: |
3a88cbd1 JL |
897 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
898 | abort (); | |
3f76745e JM |
899 | offset = -INTVAL (XEXP (rtl, 1)); |
900 | break; | |
2ad9852d | 901 | |
3f76745e JM |
902 | default: |
903 | abort (); | |
904 | } | |
2ad9852d | 905 | |
3f76745e | 906 | break; |
2ad9852d | 907 | |
c53aa195 JM |
908 | case PLUS: |
909 | /* The return address is at some offset from any value we can | |
910 | actually load. For instance, on the SPARC it is in %i7+8. Just | |
911 | ignore the offset for now; it doesn't matter for unwinding frames. */ | |
3a88cbd1 JL |
912 | if (GET_CODE (XEXP (rtl, 1)) != CONST_INT) |
913 | abort (); | |
c53aa195 JM |
914 | initial_return_save (XEXP (rtl, 0)); |
915 | return; | |
2ad9852d | 916 | |
a3f97cbb | 917 | default: |
3f76745e | 918 | abort (); |
a3f97cbb | 919 | } |
3f76745e | 920 | |
7d9d8943 | 921 | reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset); |
a3f97cbb JW |
922 | } |
923 | ||
1ba5ae8f | 924 | /* Given a SET, calculate the amount of stack adjustment it |
30f7a378 | 925 | contains. */ |
1ba5ae8f | 926 | |
5e640c56 AH |
927 | static long |
928 | stack_adjust_offset (pattern) | |
173bf5be | 929 | rtx pattern; |
1ba5ae8f AH |
930 | { |
931 | rtx src = SET_SRC (pattern); | |
932 | rtx dest = SET_DEST (pattern); | |
2ad9852d | 933 | HOST_WIDE_INT offset = 0; |
1ba5ae8f AH |
934 | enum rtx_code code; |
935 | ||
936 | if (dest == stack_pointer_rtx) | |
937 | { | |
938 | /* (set (reg sp) (plus (reg sp) (const_int))) */ | |
939 | code = GET_CODE (src); | |
940 | if (! (code == PLUS || code == MINUS) | |
941 | || XEXP (src, 0) != stack_pointer_rtx | |
942 | || GET_CODE (XEXP (src, 1)) != CONST_INT) | |
943 | return 0; | |
944 | ||
945 | offset = INTVAL (XEXP (src, 1)); | |
946 | } | |
947 | else if (GET_CODE (dest) == MEM) | |
948 | { | |
949 | /* (set (mem (pre_dec (reg sp))) (foo)) */ | |
950 | src = XEXP (dest, 0); | |
951 | code = GET_CODE (src); | |
952 | ||
2ad9852d | 953 | if ((code != PRE_DEC && code != PRE_INC && code != PRE_MODIFY) |
1ba5ae8f AH |
954 | || XEXP (src, 0) != stack_pointer_rtx) |
955 | return 0; | |
956 | ||
e2134eea JH |
957 | if (code == PRE_MODIFY) |
958 | { | |
959 | rtx val = XEXP (XEXP (src, 1), 1); | |
2ad9852d | 960 | |
e2134eea JH |
961 | /* We handle only adjustments by constant amount. */ |
962 | if (GET_CODE (XEXP (src, 1)) != PLUS || | |
963 | GET_CODE (val) != CONST_INT) | |
173bf5be | 964 | abort (); |
2ad9852d | 965 | |
e2134eea JH |
966 | offset = -INTVAL (val); |
967 | } | |
2ad9852d RK |
968 | else |
969 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1ba5ae8f AH |
970 | } |
971 | else | |
972 | return 0; | |
973 | ||
974 | if (code == PLUS || code == PRE_INC) | |
975 | offset = -offset; | |
976 | ||
977 | return offset; | |
978 | } | |
979 | ||
0021b564 JM |
980 | /* Check INSN to see if it looks like a push or a stack adjustment, and |
981 | make a note of it if it does. EH uses this information to find out how | |
982 | much extra space it needs to pop off the stack. */ | |
983 | ||
984 | static void | |
985 | dwarf2out_stack_adjust (insn) | |
986 | rtx insn; | |
987 | { | |
2ad9852d | 988 | HOST_WIDE_INT offset; |
d3e3972c | 989 | const char *label; |
2ad9852d | 990 | int i; |
0021b564 | 991 | |
2ad9852d | 992 | if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN) |
b57d9225 JM |
993 | { |
994 | /* Extract the size of the args from the CALL rtx itself. */ | |
b57d9225 JM |
995 | insn = PATTERN (insn); |
996 | if (GET_CODE (insn) == PARALLEL) | |
997 | insn = XVECEXP (insn, 0, 0); | |
998 | if (GET_CODE (insn) == SET) | |
999 | insn = SET_SRC (insn); | |
3db35af4 MM |
1000 | if (GET_CODE (insn) != CALL) |
1001 | abort (); | |
2ad9852d | 1002 | |
b57d9225 JM |
1003 | dwarf2out_args_size ("", INTVAL (XEXP (insn, 1))); |
1004 | return; | |
1005 | } | |
1006 | ||
1007 | /* If only calls can throw, and we have a frame pointer, | |
1008 | save up adjustments until we see the CALL_INSN. */ | |
2ad9852d | 1009 | else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM) |
b57d9225 JM |
1010 | return; |
1011 | ||
6020d360 | 1012 | if (GET_CODE (insn) == BARRIER) |
0021b564 | 1013 | { |
6020d360 JM |
1014 | /* When we see a BARRIER, we know to reset args_size to 0. Usually |
1015 | the compiler will have already emitted a stack adjustment, but | |
1016 | doesn't bother for calls to noreturn functions. */ | |
1017 | #ifdef STACK_GROWS_DOWNWARD | |
1018 | offset = -args_size; | |
1019 | #else | |
1020 | offset = args_size; | |
1021 | #endif | |
0021b564 | 1022 | } |
6020d360 | 1023 | else if (GET_CODE (PATTERN (insn)) == SET) |
2ad9852d | 1024 | offset = stack_adjust_offset (PATTERN (insn)); |
1ba5ae8f AH |
1025 | else if (GET_CODE (PATTERN (insn)) == PARALLEL |
1026 | || GET_CODE (PATTERN (insn)) == SEQUENCE) | |
1027 | { | |
1028 | /* There may be stack adjustments inside compound insns. Search | |
2ad9852d RK |
1029 | for them. */ |
1030 | for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--) | |
1031 | if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET) | |
1032 | offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i)); | |
0021b564 JM |
1033 | } |
1034 | else | |
1035 | return; | |
0b34cf1e | 1036 | |
6020d360 JM |
1037 | if (offset == 0) |
1038 | return; | |
1039 | ||
7d9d8943 AM |
1040 | if (cfa.reg == STACK_POINTER_REGNUM) |
1041 | cfa.offset += offset; | |
0021b564 JM |
1042 | |
1043 | #ifndef STACK_GROWS_DOWNWARD | |
1044 | offset = -offset; | |
1045 | #endif | |
2ad9852d | 1046 | |
0021b564 JM |
1047 | args_size += offset; |
1048 | if (args_size < 0) | |
1049 | args_size = 0; | |
1050 | ||
1051 | label = dwarf2out_cfi_label (); | |
7d9d8943 | 1052 | def_cfa_1 (label, &cfa); |
0021b564 JM |
1053 | dwarf2out_args_size (label, args_size); |
1054 | } | |
1055 | ||
fbfa55b0 RH |
1056 | /* We delay emitting a register save until either (a) we reach the end |
1057 | of the prologue or (b) the register is clobbered. This clusters | |
1058 | register saves so that there are fewer pc advances. */ | |
1059 | ||
1060 | struct queued_reg_save | |
1061 | { | |
1062 | struct queued_reg_save *next; | |
1063 | rtx reg; | |
1064 | long cfa_offset; | |
1065 | }; | |
1066 | ||
1067 | static struct queued_reg_save *queued_reg_saves; | |
1068 | static const char *last_reg_save_label; | |
1069 | ||
1070 | static void | |
1071 | queue_reg_save (label, reg, offset) | |
1072 | const char *label; | |
1073 | rtx reg; | |
1074 | long offset; | |
1075 | { | |
1076 | struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q)); | |
1077 | ||
1078 | q->next = queued_reg_saves; | |
1079 | q->reg = reg; | |
1080 | q->cfa_offset = offset; | |
1081 | queued_reg_saves = q; | |
1082 | ||
1083 | last_reg_save_label = label; | |
1084 | } | |
1085 | ||
1086 | static void | |
1087 | flush_queued_reg_saves () | |
1088 | { | |
1089 | struct queued_reg_save *q, *next; | |
1090 | ||
1091 | for (q = queued_reg_saves; q ; q = next) | |
1092 | { | |
1093 | dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset); | |
1094 | next = q->next; | |
1095 | free (q); | |
1096 | } | |
1097 | ||
1098 | queued_reg_saves = NULL; | |
1099 | last_reg_save_label = NULL; | |
1100 | } | |
1101 | ||
1102 | static bool | |
1103 | clobbers_queued_reg_save (insn) | |
1104 | rtx insn; | |
1105 | { | |
1106 | struct queued_reg_save *q; | |
1107 | ||
1108 | for (q = queued_reg_saves; q ; q = q->next) | |
1109 | if (modified_in_p (q->reg, insn)) | |
1110 | return true; | |
1111 | ||
1112 | return false; | |
1113 | } | |
1114 | ||
1115 | ||
770ca8c6 JO |
1116 | /* A temporary register holding an integral value used in adjusting SP |
1117 | or setting up the store_reg. The "offset" field holds the integer | |
1118 | value, not an offset. */ | |
fbfa55b0 | 1119 | static dw_cfa_location cfa_temp; |
770ca8c6 JO |
1120 | |
1121 | /* Record call frame debugging information for an expression EXPR, | |
1122 | which either sets SP or FP (adjusting how we calculate the frame | |
1123 | address) or saves a register to the stack. LABEL indicates the | |
1124 | address of EXPR. | |
1125 | ||
1126 | This function encodes a state machine mapping rtxes to actions on | |
1127 | cfa, cfa_store, and cfa_temp.reg. We describe these rules so | |
1128 | users need not read the source code. | |
1129 | ||
a401107d JO |
1130 | The High-Level Picture |
1131 | ||
1132 | Changes in the register we use to calculate the CFA: Currently we | |
1133 | assume that if you copy the CFA register into another register, we | |
1134 | should take the other one as the new CFA register; this seems to | |
1135 | work pretty well. If it's wrong for some target, it's simple | |
1136 | enough not to set RTX_FRAME_RELATED_P on the insn in question. | |
1137 | ||
1138 | Changes in the register we use for saving registers to the stack: | |
1139 | This is usually SP, but not always. Again, we deduce that if you | |
1140 | copy SP into another register (and SP is not the CFA register), | |
1141 | then the new register is the one we will be using for register | |
1142 | saves. This also seems to work. | |
1143 | ||
1144 | Register saves: There's not much guesswork about this one; if | |
1145 | RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a | |
1146 | register save, and the register used to calculate the destination | |
1147 | had better be the one we think we're using for this purpose. | |
1148 | ||
1149 | Except: If the register being saved is the CFA register, and the | |
1150 | offset is non-zero, we are saving the CFA, so we assume we have to | |
1151 | use DW_CFA_def_cfa_expression. If the offset is 0, we assume that | |
1152 | the intent is to save the value of SP from the previous frame. | |
1153 | ||
770ca8c6 JO |
1154 | Invariants / Summaries of Rules |
1155 | ||
a401107d JO |
1156 | cfa current rule for calculating the CFA. It usually |
1157 | consists of a register and an offset. | |
770ca8c6 JO |
1158 | cfa_store register used by prologue code to save things to the stack |
1159 | cfa_store.offset is the offset from the value of | |
1160 | cfa_store.reg to the actual CFA | |
1161 | cfa_temp register holding an integral value. cfa_temp.offset | |
1162 | stores the value, which will be used to adjust the | |
19ec6a36 AM |
1163 | stack pointer. cfa_temp is also used like cfa_store, |
1164 | to track stores to the stack via fp or a temp reg. | |
770ca8c6 JO |
1165 | |
1166 | Rules 1- 4: Setting a register's value to cfa.reg or an expression | |
1167 | with cfa.reg as the first operand changes the cfa.reg and its | |
19ec6a36 AM |
1168 | cfa.offset. Rule 1 and 4 also set cfa_temp.reg and |
1169 | cfa_temp.offset. | |
770ca8c6 JO |
1170 | |
1171 | Rules 6- 9: Set a non-cfa.reg register value to a constant or an | |
1172 | expression yielding a constant. This sets cfa_temp.reg | |
1173 | and cfa_temp.offset. | |
1174 | ||
1175 | Rule 5: Create a new register cfa_store used to save items to the | |
1176 | stack. | |
1177 | ||
19ec6a36 | 1178 | Rules 10-14: Save a register to the stack. Define offset as the |
a401107d | 1179 | difference of the original location and cfa_store's |
19ec6a36 | 1180 | location (or cfa_temp's location if cfa_temp is used). |
770ca8c6 JO |
1181 | |
1182 | The Rules | |
1183 | ||
1184 | "{a,b}" indicates a choice of a xor b. | |
1185 | "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg. | |
1186 | ||
1187 | Rule 1: | |
1188 | (set <reg1> <reg2>:cfa.reg) | |
19ec6a36 | 1189 | effects: cfa.reg = <reg1> |
770ca8c6 | 1190 | cfa.offset unchanged |
19ec6a36 AM |
1191 | cfa_temp.reg = <reg1> |
1192 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1193 | |
1194 | Rule 2: | |
2ad9852d RK |
1195 | (set sp ({minus,plus,losum} {sp,fp}:cfa.reg |
1196 | {<const_int>,<reg>:cfa_temp.reg})) | |
770ca8c6 JO |
1197 | effects: cfa.reg = sp if fp used |
1198 | cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp | |
1199 | cfa_store.offset += {+/- <const_int>, cfa_temp.offset} | |
1200 | if cfa_store.reg==sp | |
1201 | ||
1202 | Rule 3: | |
19ec6a36 | 1203 | (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>)) |
770ca8c6 JO |
1204 | effects: cfa.reg = fp |
1205 | cfa_offset += +/- <const_int> | |
1206 | ||
1207 | Rule 4: | |
19ec6a36 | 1208 | (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>)) |
770ca8c6 JO |
1209 | constraints: <reg1> != fp |
1210 | <reg1> != sp | |
1211 | effects: cfa.reg = <reg1> | |
19ec6a36 AM |
1212 | cfa_temp.reg = <reg1> |
1213 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1214 | |
1215 | Rule 5: | |
1216 | (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg)) | |
1217 | constraints: <reg1> != fp | |
1218 | <reg1> != sp | |
1219 | effects: cfa_store.reg = <reg1> | |
1220 | cfa_store.offset = cfa.offset - cfa_temp.offset | |
1221 | ||
1222 | Rule 6: | |
1223 | (set <reg> <const_int>) | |
1224 | effects: cfa_temp.reg = <reg> | |
1225 | cfa_temp.offset = <const_int> | |
1226 | ||
1227 | Rule 7: | |
1228 | (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>)) | |
1229 | effects: cfa_temp.reg = <reg1> | |
1230 | cfa_temp.offset |= <const_int> | |
1231 | ||
1232 | Rule 8: | |
1233 | (set <reg> (high <exp>)) | |
1234 | effects: none | |
1235 | ||
1236 | Rule 9: | |
1237 | (set <reg> (lo_sum <exp> <const_int>)) | |
1238 | effects: cfa_temp.reg = <reg> | |
1239 | cfa_temp.offset = <const_int> | |
1240 | ||
1241 | Rule 10: | |
1242 | (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>) | |
1243 | effects: cfa_store.offset -= <const_int> | |
1244 | cfa.offset = cfa_store.offset if cfa.reg == sp | |
770ca8c6 | 1245 | cfa.reg = sp |
19ec6a36 | 1246 | cfa.base_offset = -cfa_store.offset |
770ca8c6 JO |
1247 | |
1248 | Rule 11: | |
1249 | (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>) | |
1250 | effects: cfa_store.offset += -/+ mode_size(mem) | |
1251 | cfa.offset = cfa_store.offset if cfa.reg == sp | |
770ca8c6 | 1252 | cfa.reg = sp |
19ec6a36 | 1253 | cfa.base_offset = -cfa_store.offset |
770ca8c6 JO |
1254 | |
1255 | Rule 12: | |
2ad9852d RK |
1256 | (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) |
1257 | ||
1258 | <reg2>) | |
19ec6a36 AM |
1259 | effects: cfa.reg = <reg1> |
1260 | cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset | |
770ca8c6 JO |
1261 | |
1262 | Rule 13: | |
19ec6a36 AM |
1263 | (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>) |
1264 | effects: cfa.reg = <reg1> | |
1265 | cfa.base_offset = -{cfa_store,cfa_temp}.offset | |
1266 | ||
1267 | Rule 14: | |
1268 | (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>) | |
1269 | effects: cfa.reg = <reg1> | |
1270 | cfa.base_offset = -cfa_temp.offset | |
1271 | cfa_temp.offset -= mode_size(mem) */ | |
b664de3a AM |
1272 | |
1273 | static void | |
1274 | dwarf2out_frame_debug_expr (expr, label) | |
1275 | rtx expr; | |
d3e3972c | 1276 | const char *label; |
b664de3a AM |
1277 | { |
1278 | rtx src, dest; | |
2ad9852d | 1279 | HOST_WIDE_INT offset; |
556273e0 KH |
1280 | |
1281 | /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of | |
1282 | the PARALLEL independently. The first element is always processed if | |
770ca8c6 | 1283 | it is a SET. This is for backward compatibility. Other elements |
556273e0 KH |
1284 | are processed only if they are SETs and the RTX_FRAME_RELATED_P |
1285 | flag is set in them. */ | |
2ad9852d | 1286 | if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE) |
556273e0 | 1287 | { |
b664de3a AM |
1288 | int par_index; |
1289 | int limit = XVECLEN (expr, 0); | |
1290 | ||
1291 | for (par_index = 0; par_index < limit; par_index++) | |
2ad9852d RK |
1292 | if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET |
1293 | && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index)) | |
1294 | || par_index == 0)) | |
1295 | dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label); | |
556273e0 | 1296 | |
b664de3a AM |
1297 | return; |
1298 | } | |
556273e0 | 1299 | |
b664de3a AM |
1300 | if (GET_CODE (expr) != SET) |
1301 | abort (); | |
1302 | ||
1303 | src = SET_SRC (expr); | |
1304 | dest = SET_DEST (expr); | |
1305 | ||
1306 | switch (GET_CODE (dest)) | |
1307 | { | |
1308 | case REG: | |
770ca8c6 | 1309 | /* Rule 1 */ |
b664de3a AM |
1310 | /* Update the CFA rule wrt SP or FP. Make sure src is |
1311 | relative to the current CFA register. */ | |
1312 | switch (GET_CODE (src)) | |
556273e0 KH |
1313 | { |
1314 | /* Setting FP from SP. */ | |
1315 | case REG: | |
1316 | if (cfa.reg == (unsigned) REGNO (src)) | |
1317 | /* OK. */ | |
1318 | ; | |
626d1efd | 1319 | else |
556273e0 | 1320 | abort (); |
2c849145 JM |
1321 | |
1322 | /* We used to require that dest be either SP or FP, but the | |
1323 | ARM copies SP to a temporary register, and from there to | |
1324 | FP. So we just rely on the backends to only set | |
1325 | RTX_FRAME_RELATED_P on appropriate insns. */ | |
556273e0 | 1326 | cfa.reg = REGNO (dest); |
19ec6a36 AM |
1327 | cfa_temp.reg = cfa.reg; |
1328 | cfa_temp.offset = cfa.offset; | |
556273e0 | 1329 | break; |
b664de3a | 1330 | |
556273e0 KH |
1331 | case PLUS: |
1332 | case MINUS: | |
19ec6a36 | 1333 | case LO_SUM: |
556273e0 KH |
1334 | if (dest == stack_pointer_rtx) |
1335 | { | |
770ca8c6 | 1336 | /* Rule 2 */ |
2618f955 MM |
1337 | /* Adjusting SP. */ |
1338 | switch (GET_CODE (XEXP (src, 1))) | |
1339 | { | |
1340 | case CONST_INT: | |
1341 | offset = INTVAL (XEXP (src, 1)); | |
1342 | break; | |
1343 | case REG: | |
770ca8c6 | 1344 | if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg) |
2618f955 | 1345 | abort (); |
770ca8c6 | 1346 | offset = cfa_temp.offset; |
2618f955 MM |
1347 | break; |
1348 | default: | |
1349 | abort (); | |
1350 | } | |
1351 | ||
1352 | if (XEXP (src, 0) == hard_frame_pointer_rtx) | |
1353 | { | |
1354 | /* Restoring SP from FP in the epilogue. */ | |
7d9d8943 | 1355 | if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM) |
2618f955 | 1356 | abort (); |
7d9d8943 | 1357 | cfa.reg = STACK_POINTER_REGNUM; |
2618f955 | 1358 | } |
19ec6a36 AM |
1359 | else if (GET_CODE (src) == LO_SUM) |
1360 | /* Assume we've set the source reg of the LO_SUM from sp. */ | |
1361 | ; | |
2618f955 MM |
1362 | else if (XEXP (src, 0) != stack_pointer_rtx) |
1363 | abort (); | |
1364 | ||
19ec6a36 | 1365 | if (GET_CODE (src) != MINUS) |
2618f955 | 1366 | offset = -offset; |
7d9d8943 AM |
1367 | if (cfa.reg == STACK_POINTER_REGNUM) |
1368 | cfa.offset += offset; | |
1369 | if (cfa_store.reg == STACK_POINTER_REGNUM) | |
1370 | cfa_store.offset += offset; | |
556273e0 KH |
1371 | } |
1372 | else if (dest == hard_frame_pointer_rtx) | |
1373 | { | |
770ca8c6 | 1374 | /* Rule 3 */ |
2618f955 MM |
1375 | /* Either setting the FP from an offset of the SP, |
1376 | or adjusting the FP */ | |
2c849145 | 1377 | if (! frame_pointer_needed) |
2618f955 MM |
1378 | abort (); |
1379 | ||
2c849145 | 1380 | if (GET_CODE (XEXP (src, 0)) == REG |
7d9d8943 | 1381 | && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg |
2618f955 MM |
1382 | && GET_CODE (XEXP (src, 1)) == CONST_INT) |
1383 | { | |
2618f955 | 1384 | offset = INTVAL (XEXP (src, 1)); |
19ec6a36 | 1385 | if (GET_CODE (src) != MINUS) |
2618f955 | 1386 | offset = -offset; |
7d9d8943 AM |
1387 | cfa.offset += offset; |
1388 | cfa.reg = HARD_FRAME_POINTER_REGNUM; | |
2618f955 | 1389 | } |
556273e0 KH |
1390 | else |
1391 | abort (); | |
1392 | } | |
1393 | else | |
1394 | { | |
19ec6a36 | 1395 | if (GET_CODE (src) == MINUS) |
2618f955 | 1396 | abort (); |
b53ef1a2 | 1397 | |
770ca8c6 | 1398 | /* Rule 4 */ |
b53ef1a2 NC |
1399 | if (GET_CODE (XEXP (src, 0)) == REG |
1400 | && REGNO (XEXP (src, 0)) == cfa.reg | |
1401 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
34ce3d7b JM |
1402 | { |
1403 | /* Setting a temporary CFA register that will be copied | |
1404 | into the FP later on. */ | |
19ec6a36 | 1405 | offset = - INTVAL (XEXP (src, 1)); |
34ce3d7b JM |
1406 | cfa.offset += offset; |
1407 | cfa.reg = REGNO (dest); | |
19ec6a36 AM |
1408 | /* Or used to save regs to the stack. */ |
1409 | cfa_temp.reg = cfa.reg; | |
1410 | cfa_temp.offset = cfa.offset; | |
34ce3d7b | 1411 | } |
2ad9852d | 1412 | |
770ca8c6 | 1413 | /* Rule 5 */ |
19ec6a36 AM |
1414 | else if (GET_CODE (XEXP (src, 0)) == REG |
1415 | && REGNO (XEXP (src, 0)) == cfa_temp.reg | |
1416 | && XEXP (src, 1) == stack_pointer_rtx) | |
b53ef1a2 | 1417 | { |
00a42e21 JM |
1418 | /* Setting a scratch register that we will use instead |
1419 | of SP for saving registers to the stack. */ | |
b53ef1a2 NC |
1420 | if (cfa.reg != STACK_POINTER_REGNUM) |
1421 | abort (); | |
1422 | cfa_store.reg = REGNO (dest); | |
770ca8c6 | 1423 | cfa_store.offset = cfa.offset - cfa_temp.offset; |
b53ef1a2 | 1424 | } |
2ad9852d | 1425 | |
19ec6a36 AM |
1426 | /* Rule 9 */ |
1427 | else if (GET_CODE (src) == LO_SUM | |
1428 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
1429 | { | |
1430 | cfa_temp.reg = REGNO (dest); | |
1431 | cfa_temp.offset = INTVAL (XEXP (src, 1)); | |
1432 | } | |
1433 | else | |
1434 | abort (); | |
556273e0 KH |
1435 | } |
1436 | break; | |
b664de3a | 1437 | |
770ca8c6 | 1438 | /* Rule 6 */ |
556273e0 | 1439 | case CONST_INT: |
770ca8c6 JO |
1440 | cfa_temp.reg = REGNO (dest); |
1441 | cfa_temp.offset = INTVAL (src); | |
556273e0 | 1442 | break; |
b664de3a | 1443 | |
770ca8c6 | 1444 | /* Rule 7 */ |
556273e0 KH |
1445 | case IOR: |
1446 | if (GET_CODE (XEXP (src, 0)) != REG | |
770ca8c6 | 1447 | || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg |
2618f955 | 1448 | || GET_CODE (XEXP (src, 1)) != CONST_INT) |
556273e0 | 1449 | abort (); |
2ad9852d | 1450 | |
770ca8c6 JO |
1451 | if ((unsigned) REGNO (dest) != cfa_temp.reg) |
1452 | cfa_temp.reg = REGNO (dest); | |
1453 | cfa_temp.offset |= INTVAL (XEXP (src, 1)); | |
556273e0 | 1454 | break; |
b664de3a | 1455 | |
9ae21d2a AM |
1456 | /* Skip over HIGH, assuming it will be followed by a LO_SUM, |
1457 | which will fill in all of the bits. */ | |
1458 | /* Rule 8 */ | |
1459 | case HIGH: | |
1460 | break; | |
1461 | ||
556273e0 KH |
1462 | default: |
1463 | abort (); | |
1464 | } | |
2ad9852d | 1465 | |
7d9d8943 | 1466 | def_cfa_1 (label, &cfa); |
2618f955 | 1467 | break; |
b664de3a | 1468 | |
2618f955 | 1469 | case MEM: |
2618f955 MM |
1470 | if (GET_CODE (src) != REG) |
1471 | abort (); | |
7d9d8943 | 1472 | |
7d9d8943 AM |
1473 | /* Saving a register to the stack. Make sure dest is relative to the |
1474 | CFA register. */ | |
2618f955 MM |
1475 | switch (GET_CODE (XEXP (dest, 0))) |
1476 | { | |
770ca8c6 | 1477 | /* Rule 10 */ |
2618f955 | 1478 | /* With a push. */ |
e2134eea JH |
1479 | case PRE_MODIFY: |
1480 | /* We can't handle variable size modifications. */ | |
1481 | if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT) | |
173bf5be | 1482 | abort (); |
e2134eea JH |
1483 | offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1)); |
1484 | ||
1485 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM | |
1486 | || cfa_store.reg != STACK_POINTER_REGNUM) | |
1487 | abort (); | |
2ad9852d | 1488 | |
e2134eea JH |
1489 | cfa_store.offset += offset; |
1490 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1491 | cfa.offset = cfa_store.offset; | |
1492 | ||
1493 | offset = -cfa_store.offset; | |
1494 | break; | |
2ad9852d | 1495 | |
770ca8c6 | 1496 | /* Rule 11 */ |
2618f955 MM |
1497 | case PRE_INC: |
1498 | case PRE_DEC: | |
1499 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1500 | if (GET_CODE (XEXP (dest, 0)) == PRE_INC) | |
1501 | offset = -offset; | |
b664de3a | 1502 | |
2618f955 | 1503 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM |
7d9d8943 | 1504 | || cfa_store.reg != STACK_POINTER_REGNUM) |
2618f955 | 1505 | abort (); |
2ad9852d | 1506 | |
7d9d8943 AM |
1507 | cfa_store.offset += offset; |
1508 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1509 | cfa.offset = cfa_store.offset; | |
b664de3a | 1510 | |
7d9d8943 | 1511 | offset = -cfa_store.offset; |
2618f955 | 1512 | break; |
b664de3a | 1513 | |
770ca8c6 | 1514 | /* Rule 12 */ |
2618f955 MM |
1515 | /* With an offset. */ |
1516 | case PLUS: | |
1517 | case MINUS: | |
19ec6a36 | 1518 | case LO_SUM: |
770ca8c6 JO |
1519 | if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT) |
1520 | abort (); | |
2618f955 MM |
1521 | offset = INTVAL (XEXP (XEXP (dest, 0), 1)); |
1522 | if (GET_CODE (XEXP (dest, 0)) == MINUS) | |
1523 | offset = -offset; | |
b664de3a | 1524 | |
19ec6a36 AM |
1525 | if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) |
1526 | offset -= cfa_store.offset; | |
1527 | else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) | |
1528 | offset -= cfa_temp.offset; | |
1529 | else | |
2618f955 | 1530 | abort (); |
2618f955 MM |
1531 | break; |
1532 | ||
770ca8c6 | 1533 | /* Rule 13 */ |
2618f955 MM |
1534 | /* Without an offset. */ |
1535 | case REG: | |
19ec6a36 AM |
1536 | if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0))) |
1537 | offset = -cfa_store.offset; | |
1538 | else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0))) | |
1539 | offset = -cfa_temp.offset; | |
1540 | else | |
556273e0 | 1541 | abort (); |
19ec6a36 AM |
1542 | break; |
1543 | ||
1544 | /* Rule 14 */ | |
1545 | case POST_INC: | |
1546 | if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) | |
1547 | abort (); | |
1548 | offset = -cfa_temp.offset; | |
1549 | cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest)); | |
2618f955 MM |
1550 | break; |
1551 | ||
1552 | default: | |
1553 | abort (); | |
1554 | } | |
e09bbb25 | 1555 | |
556273e0 | 1556 | if (REGNO (src) != STACK_POINTER_REGNUM |
e09bbb25 JM |
1557 | && REGNO (src) != HARD_FRAME_POINTER_REGNUM |
1558 | && (unsigned) REGNO (src) == cfa.reg) | |
1559 | { | |
1560 | /* We're storing the current CFA reg into the stack. */ | |
1561 | ||
1562 | if (cfa.offset == 0) | |
1563 | { | |
1564 | /* If the source register is exactly the CFA, assume | |
1565 | we're saving SP like any other register; this happens | |
1566 | on the ARM. */ | |
e09bbb25 | 1567 | def_cfa_1 (label, &cfa); |
fbfa55b0 | 1568 | queue_reg_save (label, stack_pointer_rtx, offset); |
e09bbb25 JM |
1569 | break; |
1570 | } | |
1571 | else | |
1572 | { | |
1573 | /* Otherwise, we'll need to look in the stack to | |
1574 | calculate the CFA. */ | |
e09bbb25 | 1575 | rtx x = XEXP (dest, 0); |
2ad9852d | 1576 | |
e09bbb25 JM |
1577 | if (GET_CODE (x) != REG) |
1578 | x = XEXP (x, 0); | |
1579 | if (GET_CODE (x) != REG) | |
1580 | abort (); | |
2ad9852d RK |
1581 | |
1582 | cfa.reg = REGNO (x); | |
e09bbb25 JM |
1583 | cfa.base_offset = offset; |
1584 | cfa.indirect = 1; | |
1585 | def_cfa_1 (label, &cfa); | |
1586 | break; | |
1587 | } | |
1588 | } | |
1589 | ||
7d9d8943 | 1590 | def_cfa_1 (label, &cfa); |
fbfa55b0 | 1591 | queue_reg_save (label, src, offset); |
2618f955 MM |
1592 | break; |
1593 | ||
1594 | default: | |
1595 | abort (); | |
1596 | } | |
b664de3a AM |
1597 | } |
1598 | ||
3f76745e JM |
1599 | /* Record call frame debugging information for INSN, which either |
1600 | sets SP or FP (adjusting how we calculate the frame address) or saves a | |
1601 | register to the stack. If INSN is NULL_RTX, initialize our state. */ | |
71dfc51f | 1602 | |
3f76745e JM |
1603 | void |
1604 | dwarf2out_frame_debug (insn) | |
1605 | rtx insn; | |
a3f97cbb | 1606 | { |
d3e3972c | 1607 | const char *label; |
b664de3a | 1608 | rtx src; |
3f76745e JM |
1609 | |
1610 | if (insn == NULL_RTX) | |
a3f97cbb | 1611 | { |
fbfa55b0 RH |
1612 | /* Flush any queued register saves. */ |
1613 | flush_queued_reg_saves (); | |
1614 | ||
3f76745e | 1615 | /* Set up state for generating call frame debug info. */ |
7d9d8943 AM |
1616 | lookup_cfa (&cfa); |
1617 | if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)) | |
3a88cbd1 | 1618 | abort (); |
2ad9852d | 1619 | |
7d9d8943 AM |
1620 | cfa.reg = STACK_POINTER_REGNUM; |
1621 | cfa_store = cfa; | |
770ca8c6 JO |
1622 | cfa_temp.reg = -1; |
1623 | cfa_temp.offset = 0; | |
3f76745e JM |
1624 | return; |
1625 | } | |
1626 | ||
fbfa55b0 RH |
1627 | if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn)) |
1628 | flush_queued_reg_saves (); | |
1629 | ||
0021b564 JM |
1630 | if (! RTX_FRAME_RELATED_P (insn)) |
1631 | { | |
fbfa55b0 RH |
1632 | if (!ACCUMULATE_OUTGOING_ARGS) |
1633 | dwarf2out_stack_adjust (insn); | |
2ad9852d | 1634 | |
0021b564 JM |
1635 | return; |
1636 | } | |
1637 | ||
3f76745e | 1638 | label = dwarf2out_cfi_label (); |
07ebc930 RH |
1639 | src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX); |
1640 | if (src) | |
1641 | insn = XEXP (src, 0); | |
556273e0 | 1642 | else |
07ebc930 RH |
1643 | insn = PATTERN (insn); |
1644 | ||
b664de3a | 1645 | dwarf2out_frame_debug_expr (insn, label); |
3f76745e JM |
1646 | } |
1647 | ||
3f76745e JM |
1648 | /* Output a Call Frame Information opcode and its operand(s). */ |
1649 | ||
1650 | static void | |
12f0b96b | 1651 | output_cfi (cfi, fde, for_eh) |
b3694847 SS |
1652 | dw_cfi_ref cfi; |
1653 | dw_fde_ref fde; | |
12f0b96b | 1654 | int for_eh; |
3f76745e JM |
1655 | { |
1656 | if (cfi->dw_cfi_opc == DW_CFA_advance_loc) | |
2ad9852d RK |
1657 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1658 | | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)), | |
1659 | "DW_CFA_advance_loc 0x%lx", | |
1660 | cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
3f76745e JM |
1661 | else if (cfi->dw_cfi_opc == DW_CFA_offset) |
1662 | { | |
2e4b9b8c RH |
1663 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1664 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)), | |
1665 | "DW_CFA_offset, column 0x%lx", | |
1666 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1667 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); | |
3f76745e JM |
1668 | } |
1669 | else if (cfi->dw_cfi_opc == DW_CFA_restore) | |
2ad9852d RK |
1670 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1671 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)), | |
1672 | "DW_CFA_restore, column 0x%lx", | |
1673 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
3f76745e JM |
1674 | else |
1675 | { | |
2e4b9b8c RH |
1676 | dw2_asm_output_data (1, cfi->dw_cfi_opc, |
1677 | "%s", dwarf_cfi_name (cfi->dw_cfi_opc)); | |
3f76745e | 1678 | |
3f76745e JM |
1679 | switch (cfi->dw_cfi_opc) |
1680 | { | |
1681 | case DW_CFA_set_loc: | |
e1f9550a RH |
1682 | if (for_eh) |
1683 | dw2_asm_output_encoded_addr_rtx ( | |
1684 | ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0), | |
1685 | gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr), | |
1686 | NULL); | |
1687 | else | |
1688 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, | |
1689 | cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL); | |
3f76745e | 1690 | break; |
2ad9852d | 1691 | |
3f76745e | 1692 | case DW_CFA_advance_loc1: |
2e4b9b8c RH |
1693 | dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1694 | fde->dw_fde_current_label, NULL); | |
bb727b5a | 1695 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
3f76745e | 1696 | break; |
2ad9852d | 1697 | |
3f76745e | 1698 | case DW_CFA_advance_loc2: |
2e4b9b8c RH |
1699 | dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1700 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
1701 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
1702 | break; | |
2ad9852d | 1703 | |
3f76745e | 1704 | case DW_CFA_advance_loc4: |
2e4b9b8c RH |
1705 | dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1706 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
1707 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
1708 | break; | |
2ad9852d | 1709 | |
3f76745e | 1710 | case DW_CFA_MIPS_advance_loc8: |
2e4b9b8c RH |
1711 | dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1712 | fde->dw_fde_current_label, NULL); | |
1713 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
3f76745e | 1714 | break; |
2ad9852d | 1715 | |
3f76745e | 1716 | case DW_CFA_offset_extended: |
3f388b42 | 1717 | case DW_CFA_GNU_negative_offset_extended: |
3f76745e | 1718 | case DW_CFA_def_cfa: |
2ad9852d RK |
1719 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, |
1720 | NULL); | |
2e4b9b8c | 1721 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); |
3f76745e | 1722 | break; |
2ad9852d | 1723 | |
3f76745e JM |
1724 | case DW_CFA_restore_extended: |
1725 | case DW_CFA_undefined: | |
3f76745e JM |
1726 | case DW_CFA_same_value: |
1727 | case DW_CFA_def_cfa_register: | |
2ad9852d RK |
1728 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, |
1729 | NULL); | |
3f76745e | 1730 | break; |
2ad9852d | 1731 | |
3f76745e | 1732 | case DW_CFA_register: |
2ad9852d RK |
1733 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, |
1734 | NULL); | |
1735 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, | |
1736 | NULL); | |
3f76745e | 1737 | break; |
2ad9852d | 1738 | |
3f76745e | 1739 | case DW_CFA_def_cfa_offset: |
2e4b9b8c RH |
1740 | case DW_CFA_GNU_args_size: |
1741 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL); | |
3f76745e | 1742 | break; |
2ad9852d | 1743 | |
c53aa195 JM |
1744 | case DW_CFA_GNU_window_save: |
1745 | break; | |
2ad9852d | 1746 | |
7d9d8943 AM |
1747 | case DW_CFA_def_cfa_expression: |
1748 | output_cfa_loc (cfi); | |
1749 | break; | |
2ad9852d | 1750 | |
3f76745e JM |
1751 | default: |
1752 | break; | |
1753 | } | |
556273e0 | 1754 | } |
3f76745e JM |
1755 | } |
1756 | ||
1757 | /* Output the call frame information used to used to record information | |
1758 | that relates to calculating the frame pointer, and records the | |
1759 | location of saved registers. */ | |
1760 | ||
1761 | static void | |
1762 | output_call_frame_info (for_eh) | |
1763 | int for_eh; | |
1764 | { | |
b3694847 SS |
1765 | unsigned int i; |
1766 | dw_fde_ref fde; | |
1767 | dw_cfi_ref cfi; | |
27d95cbe | 1768 | char l1[20], l2[20], section_start_label[20]; |
52a11cbf RH |
1769 | int any_lsda_needed = 0; |
1770 | char augmentation[6]; | |
e1f9550a RH |
1771 | int augmentation_size; |
1772 | int fde_encoding = DW_EH_PE_absptr; | |
1773 | int per_encoding = DW_EH_PE_absptr; | |
1774 | int lsda_encoding = DW_EH_PE_absptr; | |
3f76745e | 1775 | |
2ad9852d RK |
1776 | /* If we don't have any functions we'll want to unwind out of, don't emit any |
1777 | EH unwind information. */ | |
737faf14 JM |
1778 | if (for_eh) |
1779 | { | |
b932f770 | 1780 | int any_eh_needed = flag_asynchronous_unwind_tables; |
2ad9852d RK |
1781 | |
1782 | for (i = 0; i < fde_table_in_use; i++) | |
52a11cbf RH |
1783 | if (fde_table[i].uses_eh_lsda) |
1784 | any_eh_needed = any_lsda_needed = 1; | |
1785 | else if (! fde_table[i].nothrow) | |
1786 | any_eh_needed = 1; | |
1787 | ||
1788 | if (! any_eh_needed) | |
1789 | return; | |
737faf14 JM |
1790 | } |
1791 | ||
aa0c1401 JL |
1792 | /* We're going to be generating comments, so turn on app. */ |
1793 | if (flag_debug_asm) | |
1794 | app_enable (); | |
956d6950 | 1795 | |
3f76745e | 1796 | if (for_eh) |
07c9d2eb | 1797 | (*targetm.asm_out.eh_frame_section) (); |
3f76745e | 1798 | else |
715bdd29 | 1799 | named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG); |
3f76745e | 1800 | |
27d95cbe RH |
1801 | ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh); |
1802 | ASM_OUTPUT_LABEL (asm_out_file, section_start_label); | |
1803 | ||
556273e0 | 1804 | /* Output the CIE. */ |
a6ab3aad JM |
1805 | ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh); |
1806 | ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh); | |
2e4b9b8c RH |
1807 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
1808 | "Length of Common Information Entry"); | |
a6ab3aad JM |
1809 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1810 | ||
2e4b9b8c RH |
1811 | /* Now that the CIE pointer is PC-relative for EH, |
1812 | use 0 to identify the CIE. */ | |
1813 | dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE), | |
1814 | (for_eh ? 0 : DW_CIE_ID), | |
1815 | "CIE Identifier Tag"); | |
3f76745e | 1816 | |
2e4b9b8c | 1817 | dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version"); |
3f76745e | 1818 | |
52a11cbf | 1819 | augmentation[0] = 0; |
e1f9550a | 1820 | augmentation_size = 0; |
52a11cbf | 1821 | if (for_eh) |
a6ab3aad | 1822 | { |
e1f9550a RH |
1823 | char *p; |
1824 | ||
52a11cbf RH |
1825 | /* Augmentation: |
1826 | z Indicates that a uleb128 is present to size the | |
1827 | augmentation section. | |
e1f9550a RH |
1828 | L Indicates the encoding (and thus presence) of |
1829 | an LSDA pointer in the FDE augmentation. | |
1830 | R Indicates a non-default pointer encoding for | |
1831 | FDE code pointers. | |
1832 | P Indicates the presence of an encoding + language | |
1833 | personality routine in the CIE augmentation. */ | |
1834 | ||
1835 | fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0); | |
1836 | per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1); | |
1837 | lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0); | |
1838 | ||
1839 | p = augmentation + 1; | |
1840 | if (eh_personality_libfunc) | |
1841 | { | |
1842 | *p++ = 'P'; | |
1843 | augmentation_size += 1 + size_of_encoded_value (per_encoding); | |
1844 | } | |
52a11cbf | 1845 | if (any_lsda_needed) |
e1f9550a RH |
1846 | { |
1847 | *p++ = 'L'; | |
1848 | augmentation_size += 1; | |
1849 | } | |
1850 | if (fde_encoding != DW_EH_PE_absptr) | |
1851 | { | |
1852 | *p++ = 'R'; | |
1853 | augmentation_size += 1; | |
1854 | } | |
1855 | if (p > augmentation + 1) | |
1856 | { | |
1857 | augmentation[0] = 'z'; | |
1858 | *p = '\0'; | |
1859 | } | |
099c8b17 RH |
1860 | |
1861 | /* Ug. Some platforms can't do unaligned dynamic relocations at all. */ | |
1862 | if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned) | |
1863 | { | |
1864 | int offset = ( 4 /* Length */ | |
1865 | + 4 /* CIE Id */ | |
1866 | + 1 /* CIE version */ | |
1867 | + strlen (augmentation) + 1 /* Augmentation */ | |
1868 | + size_of_uleb128 (1) /* Code alignment */ | |
1869 | + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT) | |
1870 | + 1 /* RA column */ | |
1871 | + 1 /* Augmentation size */ | |
1872 | + 1 /* Personality encoding */ ); | |
1873 | int pad = -offset & (PTR_SIZE - 1); | |
1874 | ||
1875 | augmentation_size += pad; | |
1876 | ||
1877 | /* Augmentations should be small, so there's scarce need to | |
1878 | iterate for a solution. Die if we exceed one uleb128 byte. */ | |
1879 | if (size_of_uleb128 (augmentation_size) != 1) | |
1880 | abort (); | |
1881 | } | |
a6ab3aad | 1882 | } |
3f76745e | 1883 | |
2ad9852d | 1884 | dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation"); |
2e4b9b8c | 1885 | dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor"); |
2e4b9b8c RH |
1886 | dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT, |
1887 | "CIE Data Alignment Factor"); | |
2e4b9b8c | 1888 | dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column"); |
3f76745e | 1889 | |
52a11cbf RH |
1890 | if (augmentation[0]) |
1891 | { | |
e1f9550a | 1892 | dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size"); |
52a11cbf | 1893 | if (eh_personality_libfunc) |
e1f9550a RH |
1894 | { |
1895 | dw2_asm_output_data (1, per_encoding, "Personality (%s)", | |
1896 | eh_data_format_name (per_encoding)); | |
1897 | dw2_asm_output_encoded_addr_rtx (per_encoding, | |
1898 | eh_personality_libfunc, NULL); | |
1899 | } | |
2ad9852d | 1900 | |
e1f9550a RH |
1901 | if (any_lsda_needed) |
1902 | dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)", | |
1903 | eh_data_format_name (lsda_encoding)); | |
2ad9852d | 1904 | |
e1f9550a RH |
1905 | if (fde_encoding != DW_EH_PE_absptr) |
1906 | dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)", | |
1907 | eh_data_format_name (fde_encoding)); | |
52a11cbf RH |
1908 | } |
1909 | ||
3f76745e | 1910 | for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next) |
12f0b96b | 1911 | output_cfi (cfi, NULL, for_eh); |
3f76745e JM |
1912 | |
1913 | /* Pad the CIE out to an address sized boundary. */ | |
12f0b96b AM |
1914 | ASM_OUTPUT_ALIGN (asm_out_file, |
1915 | floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)); | |
a6ab3aad | 1916 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e JM |
1917 | |
1918 | /* Loop through all of the FDE's. */ | |
2ad9852d | 1919 | for (i = 0; i < fde_table_in_use; i++) |
3f76745e JM |
1920 | { |
1921 | fde = &fde_table[i]; | |
3f76745e | 1922 | |
52a11cbf RH |
1923 | /* Don't emit EH unwind info for leaf functions that don't need it. */ |
1924 | if (for_eh && fde->nothrow && ! fde->uses_eh_lsda) | |
737faf14 JM |
1925 | continue; |
1926 | ||
2e4b9b8c | 1927 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2); |
556273e0 KH |
1928 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2); |
1929 | ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2); | |
2e4b9b8c RH |
1930 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
1931 | "FDE Length"); | |
a6ab3aad JM |
1932 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1933 | ||
3f76745e | 1934 | if (for_eh) |
27d95cbe | 1935 | dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset"); |
3f76745e | 1936 | else |
27d95cbe | 1937 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label, |
2e4b9b8c | 1938 | "FDE CIE offset"); |
3f76745e | 1939 | |
e1f9550a RH |
1940 | if (for_eh) |
1941 | { | |
1942 | dw2_asm_output_encoded_addr_rtx (fde_encoding, | |
1943 | gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin), | |
1944 | "FDE initial location"); | |
1945 | dw2_asm_output_delta (size_of_encoded_value (fde_encoding), | |
1946 | fde->dw_fde_end, fde->dw_fde_begin, | |
1947 | "FDE address range"); | |
1948 | } | |
1949 | else | |
1950 | { | |
1951 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin, | |
1952 | "FDE initial location"); | |
1953 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, | |
1954 | fde->dw_fde_end, fde->dw_fde_begin, | |
1955 | "FDE address range"); | |
1956 | } | |
3f76745e | 1957 | |
52a11cbf RH |
1958 | if (augmentation[0]) |
1959 | { | |
e1f9550a | 1960 | if (any_lsda_needed) |
52a11cbf | 1961 | { |
099c8b17 RH |
1962 | int size = size_of_encoded_value (lsda_encoding); |
1963 | ||
1964 | if (lsda_encoding == DW_EH_PE_aligned) | |
1965 | { | |
1966 | int offset = ( 4 /* Length */ | |
1967 | + 4 /* CIE offset */ | |
1968 | + 2 * size_of_encoded_value (fde_encoding) | |
1969 | + 1 /* Augmentation size */ ); | |
1970 | int pad = -offset & (PTR_SIZE - 1); | |
1971 | ||
1972 | size += pad; | |
1973 | if (size_of_uleb128 (size) != 1) | |
1974 | abort (); | |
1975 | } | |
1976 | ||
1977 | dw2_asm_output_data_uleb128 (size, "Augmentation size"); | |
e1f9550a RH |
1978 | |
1979 | if (fde->uses_eh_lsda) | |
1980 | { | |
1981 | ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA", | |
1982 | fde->funcdef_number); | |
1983 | dw2_asm_output_encoded_addr_rtx ( | |
1984 | lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1), | |
1985 | "Language Specific Data Area"); | |
1986 | } | |
1987 | else | |
099c8b17 RH |
1988 | { |
1989 | if (lsda_encoding == DW_EH_PE_aligned) | |
1990 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); | |
2ad9852d RK |
1991 | dw2_asm_output_data |
1992 | (size_of_encoded_value (lsda_encoding), 0, | |
1993 | "Language Specific Data Area (none)"); | |
099c8b17 | 1994 | } |
52a11cbf RH |
1995 | } |
1996 | else | |
e1f9550a | 1997 | dw2_asm_output_data_uleb128 (0, "Augmentation size"); |
52a11cbf RH |
1998 | } |
1999 | ||
3f76745e JM |
2000 | /* Loop through the Call Frame Instructions associated with |
2001 | this FDE. */ | |
2002 | fde->dw_fde_current_label = fde->dw_fde_begin; | |
2003 | for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next) | |
12f0b96b | 2004 | output_cfi (cfi, fde, for_eh); |
3f76745e | 2005 | |
a6ab3aad | 2006 | /* Pad the FDE out to an address sized boundary. */ |
12f0b96b | 2007 | ASM_OUTPUT_ALIGN (asm_out_file, |
e1f9550a | 2008 | floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE))); |
a6ab3aad | 2009 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e | 2010 | } |
2e4b9b8c | 2011 | |
7c262518 | 2012 | #ifndef EH_FRAME_SECTION_NAME |
3f76745e | 2013 | if (for_eh) |
2e4b9b8c | 2014 | dw2_asm_output_data (4, 0, "End of Table"); |
3f76745e | 2015 | #endif |
a6ab3aad JM |
2016 | #ifdef MIPS_DEBUGGING_INFO |
2017 | /* Work around Irix 6 assembler bug whereby labels at the end of a section | |
2018 | get a value of 0. Putting .align 0 after the label fixes it. */ | |
2019 | ASM_OUTPUT_ALIGN (asm_out_file, 0); | |
2020 | #endif | |
aa0c1401 JL |
2021 | |
2022 | /* Turn off app to make assembly quicker. */ | |
2023 | if (flag_debug_asm) | |
2024 | app_disable (); | |
a6ab3aad JM |
2025 | } |
2026 | ||
3f76745e JM |
2027 | /* Output a marker (i.e. a label) for the beginning of a function, before |
2028 | the prologue. */ | |
2029 | ||
2030 | void | |
653e276c NB |
2031 | dwarf2out_begin_prologue (line, file) |
2032 | unsigned int line ATTRIBUTE_UNUSED; | |
2033 | const char *file ATTRIBUTE_UNUSED; | |
3f76745e JM |
2034 | { |
2035 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 | 2036 | dw_fde_ref fde; |
3f76745e | 2037 | |
2a1ee410 RH |
2038 | current_function_func_begin_label = 0; |
2039 | ||
2040 | #ifdef IA64_UNWIND_INFO | |
2041 | /* ??? current_function_func_begin_label is also used by except.c | |
2042 | for call-site information. We must emit this label if it might | |
2043 | be used. */ | |
2044 | if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS) | |
2045 | && ! dwarf2out_do_frame ()) | |
2046 | return; | |
2047 | #else | |
2048 | if (! dwarf2out_do_frame ()) | |
2049 | return; | |
2050 | #endif | |
2051 | ||
2ad9852d | 2052 | current_funcdef_number++; |
3f76745e JM |
2053 | function_section (current_function_decl); |
2054 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL, | |
2055 | current_funcdef_number); | |
2a1ee410 RH |
2056 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL, |
2057 | current_funcdef_number); | |
00262c8a | 2058 | current_function_func_begin_label = get_identifier (label); |
3f76745e | 2059 | |
2a1ee410 RH |
2060 | #ifdef IA64_UNWIND_INFO |
2061 | /* We can elide the fde allocation if we're not emitting debug info. */ | |
2062 | if (! dwarf2out_do_frame ()) | |
2063 | return; | |
2064 | #endif | |
2065 | ||
3f76745e JM |
2066 | /* Expand the fde table if necessary. */ |
2067 | if (fde_table_in_use == fde_table_allocated) | |
2068 | { | |
2069 | fde_table_allocated += FDE_TABLE_INCREMENT; | |
2070 | fde_table | |
2071 | = (dw_fde_ref) xrealloc (fde_table, | |
2072 | fde_table_allocated * sizeof (dw_fde_node)); | |
a3f97cbb | 2073 | } |
3f76745e JM |
2074 | |
2075 | /* Record the FDE associated with this function. */ | |
2076 | current_funcdef_fde = fde_table_in_use; | |
2077 | ||
2078 | /* Add the new FDE at the end of the fde_table. */ | |
2079 | fde = &fde_table[fde_table_in_use++]; | |
2080 | fde->dw_fde_begin = xstrdup (label); | |
2081 | fde->dw_fde_current_label = NULL; | |
2082 | fde->dw_fde_end = NULL; | |
2083 | fde->dw_fde_cfi = NULL; | |
52a11cbf | 2084 | fde->funcdef_number = current_funcdef_number; |
fb13d4d0 | 2085 | fde->nothrow = current_function_nothrow; |
52a11cbf | 2086 | fde->uses_eh_lsda = cfun->uses_eh_lsda; |
737faf14 | 2087 | |
b57d9225 | 2088 | args_size = old_args_size = 0; |
653e276c | 2089 | |
2ad9852d RK |
2090 | /* We only want to output line number information for the genuine dwarf2 |
2091 | prologue case, not the eh frame case. */ | |
653e276c NB |
2092 | #ifdef DWARF2_DEBUGGING_INFO |
2093 | if (file) | |
2094 | dwarf2out_source_line (line, file); | |
2095 | #endif | |
3f76745e JM |
2096 | } |
2097 | ||
2098 | /* Output a marker (i.e. a label) for the absolute end of the generated code | |
2099 | for a function definition. This gets called *after* the epilogue code has | |
2100 | been generated. */ | |
2101 | ||
2102 | void | |
2103 | dwarf2out_end_epilogue () | |
2104 | { | |
2105 | dw_fde_ref fde; | |
2106 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2107 | ||
2108 | /* Output a label to mark the endpoint of the code generated for this | |
3ef42a0c | 2109 | function. */ |
3f76745e JM |
2110 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number); |
2111 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
2112 | fde = &fde_table[fde_table_in_use - 1]; | |
2113 | fde->dw_fde_end = xstrdup (label); | |
3f76745e JM |
2114 | } |
2115 | ||
2116 | void | |
2117 | dwarf2out_frame_init () | |
2118 | { | |
2119 | /* Allocate the initial hunk of the fde_table. */ | |
3de90026 | 2120 | fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node)); |
3f76745e JM |
2121 | fde_table_allocated = FDE_TABLE_INCREMENT; |
2122 | fde_table_in_use = 0; | |
2123 | ||
2124 | /* Generate the CFA instructions common to all FDE's. Do it now for the | |
2125 | sake of lookup_cfa. */ | |
2126 | ||
a6ab3aad | 2127 | #ifdef DWARF2_UNWIND_INFO |
91193900 AS |
2128 | /* On entry, the Canonical Frame Address is at SP. */ |
2129 | dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET); | |
2130 | initial_return_save (INCOMING_RETURN_ADDR_RTX); | |
3f76745e JM |
2131 | #endif |
2132 | } | |
2133 | ||
2134 | void | |
2135 | dwarf2out_frame_finish () | |
2136 | { | |
3f76745e | 2137 | /* Output call frame information. */ |
7a0c8d71 | 2138 | if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG) |
3f76745e | 2139 | output_call_frame_info (0); |
2ad9852d | 2140 | |
ddee9e8d | 2141 | if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions)) |
3f76745e | 2142 | output_call_frame_info (1); |
556273e0 | 2143 | } |
7d9d8943 AM |
2144 | \f |
2145 | /* And now, the subset of the debugging information support code necessary | |
2146 | for emitting location expressions. */ | |
3f76745e | 2147 | |
7d9d8943 AM |
2148 | typedef struct dw_val_struct *dw_val_ref; |
2149 | typedef struct die_struct *dw_die_ref; | |
2150 | typedef struct dw_loc_descr_struct *dw_loc_descr_ref; | |
63e46568 | 2151 | typedef struct dw_loc_list_struct *dw_loc_list_ref; |
3f76745e JM |
2152 | |
2153 | /* Each DIE may have a series of attribute/value pairs. Values | |
2154 | can take on several forms. The forms that are used in this | |
2155 | implementation are listed below. */ | |
2156 | ||
2157 | typedef enum | |
2158 | { | |
2159 | dw_val_class_addr, | |
a20612aa | 2160 | dw_val_class_offset, |
3f76745e | 2161 | dw_val_class_loc, |
63e46568 | 2162 | dw_val_class_loc_list, |
2bee6045 | 2163 | dw_val_class_range_list, |
3f76745e JM |
2164 | dw_val_class_const, |
2165 | dw_val_class_unsigned_const, | |
2166 | dw_val_class_long_long, | |
2167 | dw_val_class_float, | |
2168 | dw_val_class_flag, | |
2169 | dw_val_class_die_ref, | |
2170 | dw_val_class_fde_ref, | |
2171 | dw_val_class_lbl_id, | |
8b790721 | 2172 | dw_val_class_lbl_offset, |
3f76745e | 2173 | dw_val_class_str |
a3f97cbb | 2174 | } |
3f76745e | 2175 | dw_val_class; |
a3f97cbb | 2176 | |
3f76745e | 2177 | /* Describe a double word constant value. */ |
21217bd0 | 2178 | /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */ |
3f76745e JM |
2179 | |
2180 | typedef struct dw_long_long_struct | |
a3f97cbb | 2181 | { |
3f76745e JM |
2182 | unsigned long hi; |
2183 | unsigned long low; | |
2184 | } | |
2185 | dw_long_long_const; | |
2186 | ||
2187 | /* Describe a floating point constant value. */ | |
2188 | ||
2189 | typedef struct dw_fp_struct | |
2190 | { | |
2191 | long *array; | |
2192 | unsigned length; | |
2193 | } | |
2194 | dw_float_const; | |
2195 | ||
956d6950 | 2196 | /* The dw_val_node describes an attribute's value, as it is |
3f76745e JM |
2197 | represented internally. */ |
2198 | ||
2199 | typedef struct dw_val_struct | |
2200 | { | |
2201 | dw_val_class val_class; | |
2202 | union | |
a3f97cbb | 2203 | { |
1865dbb5 | 2204 | rtx val_addr; |
a20612aa | 2205 | long unsigned val_offset; |
63e46568 | 2206 | dw_loc_list_ref val_loc_list; |
3f76745e JM |
2207 | dw_loc_descr_ref val_loc; |
2208 | long int val_int; | |
2209 | long unsigned val_unsigned; | |
2210 | dw_long_long_const val_long_long; | |
2211 | dw_float_const val_float; | |
2ad9852d RK |
2212 | struct |
2213 | { | |
2214 | dw_die_ref die; | |
2215 | int external; | |
2216 | } val_die_ref; | |
3f76745e | 2217 | unsigned val_fde_index; |
9eb4015a | 2218 | struct indirect_string_node *val_str; |
3f76745e | 2219 | char *val_lbl_id; |
3f76745e | 2220 | unsigned char val_flag; |
a3f97cbb | 2221 | } |
3f76745e JM |
2222 | v; |
2223 | } | |
2224 | dw_val_node; | |
2225 | ||
2226 | /* Locations in memory are described using a sequence of stack machine | |
2227 | operations. */ | |
2228 | ||
2229 | typedef struct dw_loc_descr_struct | |
2230 | { | |
2231 | dw_loc_descr_ref dw_loc_next; | |
2232 | enum dwarf_location_atom dw_loc_opc; | |
2233 | dw_val_node dw_loc_oprnd1; | |
2234 | dw_val_node dw_loc_oprnd2; | |
d8041cc8 | 2235 | int dw_loc_addr; |
3f76745e JM |
2236 | } |
2237 | dw_loc_descr_node; | |
2238 | ||
63e46568 DB |
2239 | /* Location lists are ranges + location descriptions for that range, |
2240 | so you can track variables that are in different places over | |
30f7a378 | 2241 | their entire life. */ |
63e46568 DB |
2242 | typedef struct dw_loc_list_struct |
2243 | { | |
2244 | dw_loc_list_ref dw_loc_next; | |
2245 | const char *begin; /* Label for begin address of range */ | |
2246 | const char *end; /* Label for end address of range */ | |
2ad9852d RK |
2247 | char *ll_symbol; /* Label for beginning of location list. |
2248 | Only on head of list */ | |
63e46568 DB |
2249 | const char *section; /* Section this loclist is relative to */ |
2250 | dw_loc_descr_ref expr; | |
2251 | } dw_loc_list_node; | |
2252 | ||
7d9d8943 AM |
2253 | static const char *dwarf_stack_op_name PARAMS ((unsigned)); |
2254 | static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom, | |
2255 | unsigned long, | |
2256 | unsigned long)); | |
2257 | static void add_loc_descr PARAMS ((dw_loc_descr_ref *, | |
2258 | dw_loc_descr_ref)); | |
2259 | static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref)); | |
2260 | static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref)); | |
2261 | static void output_loc_operands PARAMS ((dw_loc_descr_ref)); | |
2262 | static void output_loc_sequence PARAMS ((dw_loc_descr_ref)); | |
3f76745e | 2263 | |
7d9d8943 | 2264 | /* Convert a DWARF stack opcode into its string name. */ |
3f76745e | 2265 | |
7d9d8943 AM |
2266 | static const char * |
2267 | dwarf_stack_op_name (op) | |
b3694847 | 2268 | unsigned op; |
ef76d03b | 2269 | { |
7d9d8943 AM |
2270 | switch (op) |
2271 | { | |
2272 | case DW_OP_addr: | |
2273 | return "DW_OP_addr"; | |
2274 | case DW_OP_deref: | |
2275 | return "DW_OP_deref"; | |
2276 | case DW_OP_const1u: | |
2277 | return "DW_OP_const1u"; | |
2278 | case DW_OP_const1s: | |
2279 | return "DW_OP_const1s"; | |
2280 | case DW_OP_const2u: | |
2281 | return "DW_OP_const2u"; | |
2282 | case DW_OP_const2s: | |
2283 | return "DW_OP_const2s"; | |
2284 | case DW_OP_const4u: | |
2285 | return "DW_OP_const4u"; | |
2286 | case DW_OP_const4s: | |
2287 | return "DW_OP_const4s"; | |
2288 | case DW_OP_const8u: | |
2289 | return "DW_OP_const8u"; | |
2290 | case DW_OP_const8s: | |
2291 | return "DW_OP_const8s"; | |
2292 | case DW_OP_constu: | |
2293 | return "DW_OP_constu"; | |
2294 | case DW_OP_consts: | |
2295 | return "DW_OP_consts"; | |
2296 | case DW_OP_dup: | |
2297 | return "DW_OP_dup"; | |
2298 | case DW_OP_drop: | |
2299 | return "DW_OP_drop"; | |
2300 | case DW_OP_over: | |
2301 | return "DW_OP_over"; | |
2302 | case DW_OP_pick: | |
2303 | return "DW_OP_pick"; | |
2304 | case DW_OP_swap: | |
2305 | return "DW_OP_swap"; | |
2306 | case DW_OP_rot: | |
2307 | return "DW_OP_rot"; | |
2308 | case DW_OP_xderef: | |
2309 | return "DW_OP_xderef"; | |
2310 | case DW_OP_abs: | |
2311 | return "DW_OP_abs"; | |
2312 | case DW_OP_and: | |
2313 | return "DW_OP_and"; | |
2314 | case DW_OP_div: | |
2315 | return "DW_OP_div"; | |
2316 | case DW_OP_minus: | |
2317 | return "DW_OP_minus"; | |
2318 | case DW_OP_mod: | |
2319 | return "DW_OP_mod"; | |
2320 | case DW_OP_mul: | |
2321 | return "DW_OP_mul"; | |
2322 | case DW_OP_neg: | |
2323 | return "DW_OP_neg"; | |
2324 | case DW_OP_not: | |
2325 | return "DW_OP_not"; | |
2326 | case DW_OP_or: | |
2327 | return "DW_OP_or"; | |
2328 | case DW_OP_plus: | |
2329 | return "DW_OP_plus"; | |
2330 | case DW_OP_plus_uconst: | |
2331 | return "DW_OP_plus_uconst"; | |
2332 | case DW_OP_shl: | |
2333 | return "DW_OP_shl"; | |
2334 | case DW_OP_shr: | |
2335 | return "DW_OP_shr"; | |
2336 | case DW_OP_shra: | |
2337 | return "DW_OP_shra"; | |
2338 | case DW_OP_xor: | |
2339 | return "DW_OP_xor"; | |
2340 | case DW_OP_bra: | |
2341 | return "DW_OP_bra"; | |
2342 | case DW_OP_eq: | |
2343 | return "DW_OP_eq"; | |
2344 | case DW_OP_ge: | |
2345 | return "DW_OP_ge"; | |
2346 | case DW_OP_gt: | |
2347 | return "DW_OP_gt"; | |
2348 | case DW_OP_le: | |
2349 | return "DW_OP_le"; | |
2350 | case DW_OP_lt: | |
2351 | return "DW_OP_lt"; | |
2352 | case DW_OP_ne: | |
2353 | return "DW_OP_ne"; | |
2354 | case DW_OP_skip: | |
2355 | return "DW_OP_skip"; | |
2356 | case DW_OP_lit0: | |
2357 | return "DW_OP_lit0"; | |
2358 | case DW_OP_lit1: | |
2359 | return "DW_OP_lit1"; | |
2360 | case DW_OP_lit2: | |
2361 | return "DW_OP_lit2"; | |
2362 | case DW_OP_lit3: | |
2363 | return "DW_OP_lit3"; | |
2364 | case DW_OP_lit4: | |
2365 | return "DW_OP_lit4"; | |
2366 | case DW_OP_lit5: | |
2367 | return "DW_OP_lit5"; | |
2368 | case DW_OP_lit6: | |
2369 | return "DW_OP_lit6"; | |
2370 | case DW_OP_lit7: | |
2371 | return "DW_OP_lit7"; | |
2372 | case DW_OP_lit8: | |
2373 | return "DW_OP_lit8"; | |
2374 | case DW_OP_lit9: | |
2375 | return "DW_OP_lit9"; | |
2376 | case DW_OP_lit10: | |
2377 | return "DW_OP_lit10"; | |
2378 | case DW_OP_lit11: | |
2379 | return "DW_OP_lit11"; | |
2380 | case DW_OP_lit12: | |
2381 | return "DW_OP_lit12"; | |
2382 | case DW_OP_lit13: | |
2383 | return "DW_OP_lit13"; | |
2384 | case DW_OP_lit14: | |
2385 | return "DW_OP_lit14"; | |
2386 | case DW_OP_lit15: | |
2387 | return "DW_OP_lit15"; | |
2388 | case DW_OP_lit16: | |
2389 | return "DW_OP_lit16"; | |
2390 | case DW_OP_lit17: | |
2391 | return "DW_OP_lit17"; | |
2392 | case DW_OP_lit18: | |
2393 | return "DW_OP_lit18"; | |
2394 | case DW_OP_lit19: | |
2395 | return "DW_OP_lit19"; | |
2396 | case DW_OP_lit20: | |
2397 | return "DW_OP_lit20"; | |
2398 | case DW_OP_lit21: | |
2399 | return "DW_OP_lit21"; | |
2400 | case DW_OP_lit22: | |
2401 | return "DW_OP_lit22"; | |
2402 | case DW_OP_lit23: | |
2403 | return "DW_OP_lit23"; | |
2404 | case DW_OP_lit24: | |
2405 | return "DW_OP_lit24"; | |
2406 | case DW_OP_lit25: | |
2407 | return "DW_OP_lit25"; | |
2408 | case DW_OP_lit26: | |
2409 | return "DW_OP_lit26"; | |
2410 | case DW_OP_lit27: | |
2411 | return "DW_OP_lit27"; | |
2412 | case DW_OP_lit28: | |
2413 | return "DW_OP_lit28"; | |
2414 | case DW_OP_lit29: | |
2415 | return "DW_OP_lit29"; | |
2416 | case DW_OP_lit30: | |
2417 | return "DW_OP_lit30"; | |
2418 | case DW_OP_lit31: | |
2419 | return "DW_OP_lit31"; | |
2420 | case DW_OP_reg0: | |
2421 | return "DW_OP_reg0"; | |
2422 | case DW_OP_reg1: | |
2423 | return "DW_OP_reg1"; | |
2424 | case DW_OP_reg2: | |
2425 | return "DW_OP_reg2"; | |
2426 | case DW_OP_reg3: | |
2427 | return "DW_OP_reg3"; | |
2428 | case DW_OP_reg4: | |
2429 | return "DW_OP_reg4"; | |
2430 | case DW_OP_reg5: | |
2431 | return "DW_OP_reg5"; | |
2432 | case DW_OP_reg6: | |
2433 | return "DW_OP_reg6"; | |
2434 | case DW_OP_reg7: | |
2435 | return "DW_OP_reg7"; | |
2436 | case DW_OP_reg8: | |
2437 | return "DW_OP_reg8"; | |
2438 | case DW_OP_reg9: | |
2439 | return "DW_OP_reg9"; | |
2440 | case DW_OP_reg10: | |
2441 | return "DW_OP_reg10"; | |
2442 | case DW_OP_reg11: | |
2443 | return "DW_OP_reg11"; | |
2444 | case DW_OP_reg12: | |
2445 | return "DW_OP_reg12"; | |
2446 | case DW_OP_reg13: | |
2447 | return "DW_OP_reg13"; | |
2448 | case DW_OP_reg14: | |
2449 | return "DW_OP_reg14"; | |
2450 | case DW_OP_reg15: | |
2451 | return "DW_OP_reg15"; | |
2452 | case DW_OP_reg16: | |
2453 | return "DW_OP_reg16"; | |
2454 | case DW_OP_reg17: | |
2455 | return "DW_OP_reg17"; | |
2456 | case DW_OP_reg18: | |
2457 | return "DW_OP_reg18"; | |
2458 | case DW_OP_reg19: | |
2459 | return "DW_OP_reg19"; | |
2460 | case DW_OP_reg20: | |
2461 | return "DW_OP_reg20"; | |
2462 | case DW_OP_reg21: | |
2463 | return "DW_OP_reg21"; | |
2464 | case DW_OP_reg22: | |
2465 | return "DW_OP_reg22"; | |
2466 | case DW_OP_reg23: | |
2467 | return "DW_OP_reg23"; | |
2468 | case DW_OP_reg24: | |
2469 | return "DW_OP_reg24"; | |
2470 | case DW_OP_reg25: | |
2471 | return "DW_OP_reg25"; | |
2472 | case DW_OP_reg26: | |
2473 | return "DW_OP_reg26"; | |
2474 | case DW_OP_reg27: | |
2475 | return "DW_OP_reg27"; | |
2476 | case DW_OP_reg28: | |
2477 | return "DW_OP_reg28"; | |
2478 | case DW_OP_reg29: | |
2479 | return "DW_OP_reg29"; | |
2480 | case DW_OP_reg30: | |
2481 | return "DW_OP_reg30"; | |
2482 | case DW_OP_reg31: | |
2483 | return "DW_OP_reg31"; | |
2484 | case DW_OP_breg0: | |
2485 | return "DW_OP_breg0"; | |
2486 | case DW_OP_breg1: | |
2487 | return "DW_OP_breg1"; | |
2488 | case DW_OP_breg2: | |
2489 | return "DW_OP_breg2"; | |
2490 | case DW_OP_breg3: | |
2491 | return "DW_OP_breg3"; | |
2492 | case DW_OP_breg4: | |
2493 | return "DW_OP_breg4"; | |
2494 | case DW_OP_breg5: | |
2495 | return "DW_OP_breg5"; | |
2496 | case DW_OP_breg6: | |
2497 | return "DW_OP_breg6"; | |
2498 | case DW_OP_breg7: | |
2499 | return "DW_OP_breg7"; | |
2500 | case DW_OP_breg8: | |
2501 | return "DW_OP_breg8"; | |
2502 | case DW_OP_breg9: | |
2503 | return "DW_OP_breg9"; | |
2504 | case DW_OP_breg10: | |
2505 | return "DW_OP_breg10"; | |
2506 | case DW_OP_breg11: | |
2507 | return "DW_OP_breg11"; | |
2508 | case DW_OP_breg12: | |
2509 | return "DW_OP_breg12"; | |
2510 | case DW_OP_breg13: | |
2511 | return "DW_OP_breg13"; | |
2512 | case DW_OP_breg14: | |
2513 | return "DW_OP_breg14"; | |
2514 | case DW_OP_breg15: | |
2515 | return "DW_OP_breg15"; | |
2516 | case DW_OP_breg16: | |
2517 | return "DW_OP_breg16"; | |
2518 | case DW_OP_breg17: | |
2519 | return "DW_OP_breg17"; | |
2520 | case DW_OP_breg18: | |
2521 | return "DW_OP_breg18"; | |
2522 | case DW_OP_breg19: | |
2523 | return "DW_OP_breg19"; | |
2524 | case DW_OP_breg20: | |
2525 | return "DW_OP_breg20"; | |
2526 | case DW_OP_breg21: | |
2527 | return "DW_OP_breg21"; | |
2528 | case DW_OP_breg22: | |
2529 | return "DW_OP_breg22"; | |
2530 | case DW_OP_breg23: | |
2531 | return "DW_OP_breg23"; | |
2532 | case DW_OP_breg24: | |
2533 | return "DW_OP_breg24"; | |
2534 | case DW_OP_breg25: | |
2535 | return "DW_OP_breg25"; | |
2536 | case DW_OP_breg26: | |
2537 | return "DW_OP_breg26"; | |
2538 | case DW_OP_breg27: | |
2539 | return "DW_OP_breg27"; | |
2540 | case DW_OP_breg28: | |
2541 | return "DW_OP_breg28"; | |
2542 | case DW_OP_breg29: | |
2543 | return "DW_OP_breg29"; | |
2544 | case DW_OP_breg30: | |
2545 | return "DW_OP_breg30"; | |
2546 | case DW_OP_breg31: | |
2547 | return "DW_OP_breg31"; | |
2548 | case DW_OP_regx: | |
2549 | return "DW_OP_regx"; | |
2550 | case DW_OP_fbreg: | |
2551 | return "DW_OP_fbreg"; | |
2552 | case DW_OP_bregx: | |
2553 | return "DW_OP_bregx"; | |
2554 | case DW_OP_piece: | |
2555 | return "DW_OP_piece"; | |
2556 | case DW_OP_deref_size: | |
2557 | return "DW_OP_deref_size"; | |
2558 | case DW_OP_xderef_size: | |
2559 | return "DW_OP_xderef_size"; | |
2560 | case DW_OP_nop: | |
2561 | return "DW_OP_nop"; | |
3f76745e | 2562 | default: |
7d9d8943 | 2563 | return "OP_<unknown>"; |
3f76745e | 2564 | } |
bdb669cb | 2565 | } |
a3f97cbb | 2566 | |
7d9d8943 AM |
2567 | /* Return a pointer to a newly allocated location description. Location |
2568 | descriptions are simple expression terms that can be strung | |
2569 | together to form more complicated location (address) descriptions. */ | |
2570 | ||
2571 | static inline dw_loc_descr_ref | |
2572 | new_loc_descr (op, oprnd1, oprnd2) | |
b3694847 SS |
2573 | enum dwarf_location_atom op; |
2574 | unsigned long oprnd1; | |
2575 | unsigned long oprnd2; | |
4b674448 | 2576 | { |
5de0e8d4 JM |
2577 | /* Use xcalloc here so we clear out all of the long_long constant in |
2578 | the union. */ | |
b3694847 | 2579 | dw_loc_descr_ref descr |
5de0e8d4 | 2580 | = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node)); |
71dfc51f | 2581 | |
7d9d8943 AM |
2582 | descr->dw_loc_opc = op; |
2583 | descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const; | |
2584 | descr->dw_loc_oprnd1.v.val_unsigned = oprnd1; | |
2585 | descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const; | |
2586 | descr->dw_loc_oprnd2.v.val_unsigned = oprnd2; | |
71dfc51f | 2587 | |
7d9d8943 AM |
2588 | return descr; |
2589 | } | |
2590 | ||
63e46568 | 2591 | |
7d9d8943 AM |
2592 | /* Add a location description term to a location description expression. */ |
2593 | ||
2594 | static inline void | |
2595 | add_loc_descr (list_head, descr) | |
b3694847 SS |
2596 | dw_loc_descr_ref *list_head; |
2597 | dw_loc_descr_ref descr; | |
7d9d8943 | 2598 | { |
b3694847 | 2599 | dw_loc_descr_ref *d; |
7d9d8943 AM |
2600 | |
2601 | /* Find the end of the chain. */ | |
2602 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
2603 | ; | |
2604 | ||
2605 | *d = descr; | |
2606 | } | |
2607 | ||
2608 | /* Return the size of a location descriptor. */ | |
2609 | ||
2610 | static unsigned long | |
2611 | size_of_loc_descr (loc) | |
b3694847 | 2612 | dw_loc_descr_ref loc; |
7d9d8943 | 2613 | { |
b3694847 | 2614 | unsigned long size = 1; |
7d9d8943 AM |
2615 | |
2616 | switch (loc->dw_loc_opc) | |
2617 | { | |
2618 | case DW_OP_addr: | |
2619 | size += DWARF2_ADDR_SIZE; | |
2620 | break; | |
2621 | case DW_OP_const1u: | |
2622 | case DW_OP_const1s: | |
2623 | size += 1; | |
2624 | break; | |
2625 | case DW_OP_const2u: | |
2626 | case DW_OP_const2s: | |
2627 | size += 2; | |
2628 | break; | |
2629 | case DW_OP_const4u: | |
2630 | case DW_OP_const4s: | |
2631 | size += 4; | |
2632 | break; | |
2633 | case DW_OP_const8u: | |
2634 | case DW_OP_const8s: | |
2635 | size += 8; | |
2636 | break; | |
2637 | case DW_OP_constu: | |
2638 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2639 | break; | |
2640 | case DW_OP_consts: | |
2641 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2642 | break; | |
2643 | case DW_OP_pick: | |
2644 | size += 1; | |
2645 | break; | |
2646 | case DW_OP_plus_uconst: | |
2647 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2648 | break; | |
2649 | case DW_OP_skip: | |
2650 | case DW_OP_bra: | |
2651 | size += 2; | |
2652 | break; | |
2653 | case DW_OP_breg0: | |
2654 | case DW_OP_breg1: | |
2655 | case DW_OP_breg2: | |
2656 | case DW_OP_breg3: | |
2657 | case DW_OP_breg4: | |
2658 | case DW_OP_breg5: | |
2659 | case DW_OP_breg6: | |
2660 | case DW_OP_breg7: | |
2661 | case DW_OP_breg8: | |
2662 | case DW_OP_breg9: | |
2663 | case DW_OP_breg10: | |
2664 | case DW_OP_breg11: | |
2665 | case DW_OP_breg12: | |
2666 | case DW_OP_breg13: | |
2667 | case DW_OP_breg14: | |
2668 | case DW_OP_breg15: | |
2669 | case DW_OP_breg16: | |
2670 | case DW_OP_breg17: | |
2671 | case DW_OP_breg18: | |
2672 | case DW_OP_breg19: | |
2673 | case DW_OP_breg20: | |
2674 | case DW_OP_breg21: | |
2675 | case DW_OP_breg22: | |
2676 | case DW_OP_breg23: | |
2677 | case DW_OP_breg24: | |
2678 | case DW_OP_breg25: | |
2679 | case DW_OP_breg26: | |
2680 | case DW_OP_breg27: | |
2681 | case DW_OP_breg28: | |
2682 | case DW_OP_breg29: | |
2683 | case DW_OP_breg30: | |
2684 | case DW_OP_breg31: | |
2685 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2686 | break; | |
2687 | case DW_OP_regx: | |
2688 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2689 | break; | |
2690 | case DW_OP_fbreg: | |
2691 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2692 | break; | |
2693 | case DW_OP_bregx: | |
2694 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2695 | size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int); | |
2696 | break; | |
2697 | case DW_OP_piece: | |
2698 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2699 | break; | |
2700 | case DW_OP_deref_size: | |
2701 | case DW_OP_xderef_size: | |
2702 | size += 1; | |
2703 | break; | |
3f76745e | 2704 | default: |
7d9d8943 | 2705 | break; |
4b674448 | 2706 | } |
7d9d8943 AM |
2707 | |
2708 | return size; | |
4b674448 JM |
2709 | } |
2710 | ||
7d9d8943 | 2711 | /* Return the size of a series of location descriptors. */ |
71dfc51f | 2712 | |
7d9d8943 AM |
2713 | static unsigned long |
2714 | size_of_locs (loc) | |
b3694847 | 2715 | dw_loc_descr_ref loc; |
4b674448 | 2716 | { |
2ad9852d | 2717 | unsigned long size; |
7d9d8943 | 2718 | |
2ad9852d | 2719 | for (size = 0; loc != NULL; loc = loc->dw_loc_next) |
d8041cc8 RH |
2720 | { |
2721 | loc->dw_loc_addr = size; | |
2722 | size += size_of_loc_descr (loc); | |
2723 | } | |
7d9d8943 AM |
2724 | |
2725 | return size; | |
4b674448 JM |
2726 | } |
2727 | ||
7d9d8943 | 2728 | /* Output location description stack opcode's operands (if any). */ |
71dfc51f | 2729 | |
7d9d8943 AM |
2730 | static void |
2731 | output_loc_operands (loc) | |
b3694847 | 2732 | dw_loc_descr_ref loc; |
a3f97cbb | 2733 | { |
b3694847 SS |
2734 | dw_val_ref val1 = &loc->dw_loc_oprnd1; |
2735 | dw_val_ref val2 = &loc->dw_loc_oprnd2; | |
7d9d8943 AM |
2736 | |
2737 | switch (loc->dw_loc_opc) | |
a3f97cbb | 2738 | { |
0517872a | 2739 | #ifdef DWARF2_DEBUGGING_INFO |
3f76745e | 2740 | case DW_OP_addr: |
2e4b9b8c | 2741 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL); |
7d9d8943 | 2742 | break; |
3f76745e | 2743 | case DW_OP_const2u: |
3f76745e | 2744 | case DW_OP_const2s: |
2e4b9b8c | 2745 | dw2_asm_output_data (2, val1->v.val_int, NULL); |
7d9d8943 | 2746 | break; |
3f76745e | 2747 | case DW_OP_const4u: |
3f76745e | 2748 | case DW_OP_const4s: |
2e4b9b8c | 2749 | dw2_asm_output_data (4, val1->v.val_int, NULL); |
7d9d8943 | 2750 | break; |
3f76745e | 2751 | case DW_OP_const8u: |
3f76745e | 2752 | case DW_OP_const8s: |
2e4b9b8c RH |
2753 | if (HOST_BITS_PER_LONG < 64) |
2754 | abort (); | |
2755 | dw2_asm_output_data (8, val1->v.val_int, NULL); | |
7d9d8943 | 2756 | break; |
0517872a JM |
2757 | case DW_OP_skip: |
2758 | case DW_OP_bra: | |
d8041cc8 RH |
2759 | { |
2760 | int offset; | |
2761 | ||
2762 | if (val1->val_class == dw_val_class_loc) | |
2763 | offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3); | |
2764 | else | |
2765 | abort (); | |
2766 | ||
2e4b9b8c | 2767 | dw2_asm_output_data (2, offset, NULL); |
d8041cc8 | 2768 | } |
0517872a | 2769 | break; |
3139472f JM |
2770 | #else |
2771 | case DW_OP_addr: | |
2772 | case DW_OP_const2u: | |
2773 | case DW_OP_const2s: | |
2774 | case DW_OP_const4u: | |
2775 | case DW_OP_const4s: | |
2776 | case DW_OP_const8u: | |
2777 | case DW_OP_const8s: | |
2778 | case DW_OP_skip: | |
2779 | case DW_OP_bra: | |
2780 | /* We currently don't make any attempt to make sure these are | |
2781 | aligned properly like we do for the main unwind info, so | |
2782 | don't support emitting things larger than a byte if we're | |
2783 | only doing unwinding. */ | |
2784 | abort (); | |
0517872a JM |
2785 | #endif |
2786 | case DW_OP_const1u: | |
2787 | case DW_OP_const1s: | |
2e4b9b8c | 2788 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
0517872a | 2789 | break; |
3f76745e | 2790 | case DW_OP_constu: |
2e4b9b8c | 2791 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2792 | break; |
3f76745e | 2793 | case DW_OP_consts: |
2e4b9b8c | 2794 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 AM |
2795 | break; |
2796 | case DW_OP_pick: | |
2e4b9b8c | 2797 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 AM |
2798 | break; |
2799 | case DW_OP_plus_uconst: | |
2e4b9b8c | 2800 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2801 | break; |
3f76745e | 2802 | case DW_OP_breg0: |
3f76745e | 2803 | case DW_OP_breg1: |
3f76745e | 2804 | case DW_OP_breg2: |
3f76745e | 2805 | case DW_OP_breg3: |
3f76745e | 2806 | case DW_OP_breg4: |
3f76745e | 2807 | case DW_OP_breg5: |
3f76745e | 2808 | case DW_OP_breg6: |
3f76745e | 2809 | case DW_OP_breg7: |
3f76745e | 2810 | case DW_OP_breg8: |
3f76745e | 2811 | case DW_OP_breg9: |
3f76745e | 2812 | case DW_OP_breg10: |
3f76745e | 2813 | case DW_OP_breg11: |
3f76745e | 2814 | case DW_OP_breg12: |
3f76745e | 2815 | case DW_OP_breg13: |
3f76745e | 2816 | case DW_OP_breg14: |
3f76745e | 2817 | case DW_OP_breg15: |
3f76745e | 2818 | case DW_OP_breg16: |
3f76745e | 2819 | case DW_OP_breg17: |
3f76745e | 2820 | case DW_OP_breg18: |
3f76745e | 2821 | case DW_OP_breg19: |
3f76745e | 2822 | case DW_OP_breg20: |
3f76745e | 2823 | case DW_OP_breg21: |
3f76745e | 2824 | case DW_OP_breg22: |
3f76745e | 2825 | case DW_OP_breg23: |
3f76745e | 2826 | case DW_OP_breg24: |
3f76745e | 2827 | case DW_OP_breg25: |
3f76745e | 2828 | case DW_OP_breg26: |
3f76745e | 2829 | case DW_OP_breg27: |
3f76745e | 2830 | case DW_OP_breg28: |
3f76745e | 2831 | case DW_OP_breg29: |
3f76745e | 2832 | case DW_OP_breg30: |
3f76745e | 2833 | case DW_OP_breg31: |
2e4b9b8c | 2834 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 2835 | break; |
3f76745e | 2836 | case DW_OP_regx: |
2e4b9b8c | 2837 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2838 | break; |
3f76745e | 2839 | case DW_OP_fbreg: |
2e4b9b8c | 2840 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 2841 | break; |
3f76745e | 2842 | case DW_OP_bregx: |
2e4b9b8c RH |
2843 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
2844 | dw2_asm_output_data_sleb128 (val2->v.val_int, NULL); | |
7d9d8943 | 2845 | break; |
3f76745e | 2846 | case DW_OP_piece: |
2e4b9b8c | 2847 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2848 | break; |
3f76745e | 2849 | case DW_OP_deref_size: |
3f76745e | 2850 | case DW_OP_xderef_size: |
2e4b9b8c | 2851 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 AM |
2852 | break; |
2853 | default: | |
3139472f JM |
2854 | /* Other codes have no operands. */ |
2855 | break; | |
7d9d8943 AM |
2856 | } |
2857 | } | |
2858 | ||
2859 | /* Output a sequence of location operations. */ | |
2860 | ||
2861 | static void | |
2862 | output_loc_sequence (loc) | |
2863 | dw_loc_descr_ref loc; | |
2864 | { | |
2865 | for (; loc != NULL; loc = loc->dw_loc_next) | |
2866 | { | |
2867 | /* Output the opcode. */ | |
2e4b9b8c RH |
2868 | dw2_asm_output_data (1, loc->dw_loc_opc, |
2869 | "%s", dwarf_stack_op_name (loc->dw_loc_opc)); | |
7d9d8943 AM |
2870 | |
2871 | /* Output the operand(s) (if any). */ | |
2872 | output_loc_operands (loc); | |
2873 | } | |
2874 | } | |
2875 | ||
2876 | /* This routine will generate the correct assembly data for a location | |
2877 | description based on a cfi entry with a complex address. */ | |
2878 | ||
2879 | static void | |
2880 | output_cfa_loc (cfi) | |
2881 | dw_cfi_ref cfi; | |
2882 | { | |
2883 | dw_loc_descr_ref loc; | |
2884 | unsigned long size; | |
2885 | ||
2886 | /* Output the size of the block. */ | |
2887 | loc = cfi->dw_cfi_oprnd1.dw_cfi_loc; | |
2888 | size = size_of_locs (loc); | |
2e4b9b8c | 2889 | dw2_asm_output_data_uleb128 (size, NULL); |
7d9d8943 AM |
2890 | |
2891 | /* Now output the operations themselves. */ | |
2892 | output_loc_sequence (loc); | |
2893 | } | |
2894 | ||
dd49a9ec | 2895 | /* This function builds a dwarf location descriptor sequence from |
556273e0 | 2896 | a dw_cfa_location. */ |
7d9d8943 AM |
2897 | |
2898 | static struct dw_loc_descr_struct * | |
2899 | build_cfa_loc (cfa) | |
2900 | dw_cfa_location *cfa; | |
2901 | { | |
2902 | struct dw_loc_descr_struct *head, *tmp; | |
2903 | ||
2904 | if (cfa->indirect == 0) | |
2905 | abort (); | |
2906 | ||
2907 | if (cfa->base_offset) | |
f299afab HPN |
2908 | { |
2909 | if (cfa->reg <= 31) | |
2910 | head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0); | |
2911 | else | |
2912 | head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset); | |
2913 | } | |
2914 | else if (cfa->reg <= 31) | |
7d9d8943 | 2915 | head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0); |
f299afab HPN |
2916 | else |
2917 | head = new_loc_descr (DW_OP_regx, cfa->reg, 0); | |
2ad9852d | 2918 | |
7d9d8943 AM |
2919 | head->dw_loc_oprnd1.val_class = dw_val_class_const; |
2920 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
2921 | add_loc_descr (&head, tmp); | |
2922 | if (cfa->offset != 0) | |
2923 | { | |
2924 | tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0); | |
2925 | add_loc_descr (&head, tmp); | |
2926 | } | |
2ad9852d | 2927 | |
7d9d8943 AM |
2928 | return head; |
2929 | } | |
2930 | ||
2ad9852d RK |
2931 | /* This function fills in aa dw_cfa_location structure from a dwarf location |
2932 | descriptor sequence. */ | |
7d9d8943 AM |
2933 | |
2934 | static void | |
2935 | get_cfa_from_loc_descr (cfa, loc) | |
2936 | dw_cfa_location *cfa; | |
556273e0 | 2937 | struct dw_loc_descr_struct *loc; |
7d9d8943 | 2938 | { |
556273e0 | 2939 | struct dw_loc_descr_struct *ptr; |
7d9d8943 AM |
2940 | cfa->offset = 0; |
2941 | cfa->base_offset = 0; | |
2942 | cfa->indirect = 0; | |
2943 | cfa->reg = -1; | |
2944 | ||
2945 | for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next) | |
2946 | { | |
2947 | enum dwarf_location_atom op = ptr->dw_loc_opc; | |
2ad9852d | 2948 | |
7d9d8943 | 2949 | switch (op) |
556273e0 | 2950 | { |
7d9d8943 AM |
2951 | case DW_OP_reg0: |
2952 | case DW_OP_reg1: | |
2953 | case DW_OP_reg2: | |
2954 | case DW_OP_reg3: | |
2955 | case DW_OP_reg4: | |
2956 | case DW_OP_reg5: | |
2957 | case DW_OP_reg6: | |
2958 | case DW_OP_reg7: | |
2959 | case DW_OP_reg8: | |
2960 | case DW_OP_reg9: | |
2961 | case DW_OP_reg10: | |
2962 | case DW_OP_reg11: | |
2963 | case DW_OP_reg12: | |
2964 | case DW_OP_reg13: | |
2965 | case DW_OP_reg14: | |
2966 | case DW_OP_reg15: | |
2967 | case DW_OP_reg16: | |
2968 | case DW_OP_reg17: | |
2969 | case DW_OP_reg18: | |
2970 | case DW_OP_reg19: | |
2971 | case DW_OP_reg20: | |
2972 | case DW_OP_reg21: | |
2973 | case DW_OP_reg22: | |
2974 | case DW_OP_reg23: | |
2975 | case DW_OP_reg24: | |
2976 | case DW_OP_reg25: | |
2977 | case DW_OP_reg26: | |
2978 | case DW_OP_reg27: | |
2979 | case DW_OP_reg28: | |
2980 | case DW_OP_reg29: | |
2981 | case DW_OP_reg30: | |
2982 | case DW_OP_reg31: | |
2983 | cfa->reg = op - DW_OP_reg0; | |
2984 | break; | |
2985 | case DW_OP_regx: | |
2986 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
2987 | break; | |
2988 | case DW_OP_breg0: | |
2989 | case DW_OP_breg1: | |
2990 | case DW_OP_breg2: | |
2991 | case DW_OP_breg3: | |
2992 | case DW_OP_breg4: | |
2993 | case DW_OP_breg5: | |
2994 | case DW_OP_breg6: | |
2995 | case DW_OP_breg7: | |
2996 | case DW_OP_breg8: | |
2997 | case DW_OP_breg9: | |
2998 | case DW_OP_breg10: | |
2999 | case DW_OP_breg11: | |
3000 | case DW_OP_breg12: | |
3001 | case DW_OP_breg13: | |
3002 | case DW_OP_breg14: | |
3003 | case DW_OP_breg15: | |
3004 | case DW_OP_breg16: | |
3005 | case DW_OP_breg17: | |
3006 | case DW_OP_breg18: | |
3007 | case DW_OP_breg19: | |
3008 | case DW_OP_breg20: | |
3009 | case DW_OP_breg21: | |
3010 | case DW_OP_breg22: | |
3011 | case DW_OP_breg23: | |
3012 | case DW_OP_breg24: | |
3013 | case DW_OP_breg25: | |
3014 | case DW_OP_breg26: | |
3015 | case DW_OP_breg27: | |
3016 | case DW_OP_breg28: | |
3017 | case DW_OP_breg29: | |
3018 | case DW_OP_breg30: | |
3019 | case DW_OP_breg31: | |
3020 | cfa->reg = op - DW_OP_breg0; | |
3021 | cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int; | |
3022 | break; | |
3023 | case DW_OP_bregx: | |
3024 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
3025 | cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int; | |
3026 | break; | |
3027 | case DW_OP_deref: | |
3028 | cfa->indirect = 1; | |
3029 | break; | |
3030 | case DW_OP_plus_uconst: | |
556273e0 | 3031 | cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned; |
7d9d8943 AM |
3032 | break; |
3033 | default: | |
a1f300c0 | 3034 | internal_error ("DW_LOC_OP %s not implemented\n", |
400500c4 | 3035 | dwarf_stack_op_name (ptr->dw_loc_opc)); |
7d9d8943 AM |
3036 | } |
3037 | } | |
3038 | } | |
3039 | #endif /* .debug_frame support */ | |
3040 | \f | |
3041 | /* And now, the support for symbolic debugging information. */ | |
3042 | #ifdef DWARF2_DEBUGGING_INFO | |
3043 | ||
117f9d28 GS |
3044 | /* .debug_str support. */ |
3045 | static hashnode indirect_string_alloc PARAMS ((hash_table *)); | |
3046 | static int output_indirect_string PARAMS ((struct cpp_reader *, | |
3047 | hashnode, const PTR)); | |
3048 | ||
3049 | ||
e2a12aca NB |
3050 | static void dwarf2out_init PARAMS ((const char *)); |
3051 | static void dwarf2out_finish PARAMS ((const char *)); | |
7f905405 NB |
3052 | static void dwarf2out_define PARAMS ((unsigned int, const char *)); |
3053 | static void dwarf2out_undef PARAMS ((unsigned int, const char *)); | |
3054 | static void dwarf2out_start_source_file PARAMS ((unsigned, const char *)); | |
3055 | static void dwarf2out_end_source_file PARAMS ((unsigned)); | |
e2a12aca NB |
3056 | static void dwarf2out_begin_block PARAMS ((unsigned, unsigned)); |
3057 | static void dwarf2out_end_block PARAMS ((unsigned, unsigned)); | |
e1772ac0 | 3058 | static bool dwarf2out_ignore_block PARAMS ((tree)); |
2b85879e | 3059 | static void dwarf2out_global_decl PARAMS ((tree)); |
e1772ac0 | 3060 | static void dwarf2out_abstract_function PARAMS ((tree)); |
7f905405 NB |
3061 | |
3062 | /* The debug hooks structure. */ | |
3063 | ||
3064 | struct gcc_debug_hooks dwarf2_debug_hooks = | |
3065 | { | |
3066 | dwarf2out_init, | |
3067 | dwarf2out_finish, | |
3068 | dwarf2out_define, | |
3069 | dwarf2out_undef, | |
3070 | dwarf2out_start_source_file, | |
a5a42b92 NB |
3071 | dwarf2out_end_source_file, |
3072 | dwarf2out_begin_block, | |
e2a12aca | 3073 | dwarf2out_end_block, |
e1772ac0 | 3074 | dwarf2out_ignore_block, |
e2a12aca | 3075 | dwarf2out_source_line, |
653e276c NB |
3076 | dwarf2out_begin_prologue, |
3077 | debug_nothing_int, /* end_prologue */ | |
e2a12aca | 3078 | dwarf2out_end_epilogue, |
653e276c | 3079 | debug_nothing_tree, /* begin_function */ |
2b85879e NB |
3080 | debug_nothing_int, /* end_function */ |
3081 | dwarf2out_decl, /* function_decl */ | |
3082 | dwarf2out_global_decl, | |
e1772ac0 NB |
3083 | debug_nothing_tree, /* deferred_inline_function */ |
3084 | /* The DWARF 2 backend tries to reduce debugging bloat by not | |
3085 | emitting the abstract description of inline functions until | |
3086 | something tries to reference them. */ | |
3087 | dwarf2out_abstract_function, /* outlining_inline_function */ | |
3088 | debug_nothing_rtx /* label */ | |
7f905405 NB |
3089 | }; |
3090 | \f | |
7d9d8943 AM |
3091 | /* NOTE: In the comments in this file, many references are made to |
3092 | "Debugging Information Entries". This term is abbreviated as `DIE' | |
3093 | throughout the remainder of this file. */ | |
3094 | ||
3095 | /* An internal representation of the DWARF output is built, and then | |
3096 | walked to generate the DWARF debugging info. The walk of the internal | |
3097 | representation is done after the entire program has been compiled. | |
3098 | The types below are used to describe the internal representation. */ | |
3099 | ||
3100 | /* Various DIE's use offsets relative to the beginning of the | |
3101 | .debug_info section to refer to each other. */ | |
3102 | ||
3103 | typedef long int dw_offset; | |
3104 | ||
3105 | /* Define typedefs here to avoid circular dependencies. */ | |
3106 | ||
3107 | typedef struct dw_attr_struct *dw_attr_ref; | |
3108 | typedef struct dw_line_info_struct *dw_line_info_ref; | |
3109 | typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref; | |
3110 | typedef struct pubname_struct *pubname_ref; | |
a20612aa | 3111 | typedef struct dw_ranges_struct *dw_ranges_ref; |
7d9d8943 AM |
3112 | |
3113 | /* Each entry in the line_info_table maintains the file and | |
3114 | line number associated with the label generated for that | |
3115 | entry. The label gives the PC value associated with | |
3116 | the line number entry. */ | |
3117 | ||
3118 | typedef struct dw_line_info_struct | |
3119 | { | |
3120 | unsigned long dw_file_num; | |
3121 | unsigned long dw_line_num; | |
3122 | } | |
3123 | dw_line_info_entry; | |
3124 | ||
3125 | /* Line information for functions in separate sections; each one gets its | |
3126 | own sequence. */ | |
3127 | typedef struct dw_separate_line_info_struct | |
3128 | { | |
3129 | unsigned long dw_file_num; | |
3130 | unsigned long dw_line_num; | |
3131 | unsigned long function; | |
3132 | } | |
3133 | dw_separate_line_info_entry; | |
3134 | ||
3135 | /* Each DIE attribute has a field specifying the attribute kind, | |
3136 | a link to the next attribute in the chain, and an attribute value. | |
3137 | Attributes are typically linked below the DIE they modify. */ | |
3138 | ||
3139 | typedef struct dw_attr_struct | |
3140 | { | |
3141 | enum dwarf_attribute dw_attr; | |
3142 | dw_attr_ref dw_attr_next; | |
3143 | dw_val_node dw_attr_val; | |
3144 | } | |
3145 | dw_attr_node; | |
3146 | ||
3147 | /* The Debugging Information Entry (DIE) structure */ | |
3148 | ||
3149 | typedef struct die_struct | |
3150 | { | |
3151 | enum dwarf_tag die_tag; | |
881c6935 | 3152 | char *die_symbol; |
7d9d8943 AM |
3153 | dw_attr_ref die_attr; |
3154 | dw_die_ref die_parent; | |
3155 | dw_die_ref die_child; | |
3156 | dw_die_ref die_sib; | |
3157 | dw_offset die_offset; | |
3158 | unsigned long die_abbrev; | |
1bfb5f8f | 3159 | int die_mark; |
7d9d8943 AM |
3160 | } |
3161 | die_node; | |
3162 | ||
3163 | /* The pubname structure */ | |
3164 | ||
3165 | typedef struct pubname_struct | |
3166 | { | |
3167 | dw_die_ref die; | |
556273e0 | 3168 | char *name; |
7d9d8943 AM |
3169 | } |
3170 | pubname_entry; | |
3171 | ||
a20612aa RH |
3172 | struct dw_ranges_struct |
3173 | { | |
3174 | int block_num; | |
3175 | }; | |
3176 | ||
7d9d8943 AM |
3177 | /* The limbo die list structure. */ |
3178 | typedef struct limbo_die_struct | |
3179 | { | |
3180 | dw_die_ref die; | |
54ba1f0d | 3181 | tree created_for; |
7d9d8943 AM |
3182 | struct limbo_die_struct *next; |
3183 | } | |
3184 | limbo_die_node; | |
3185 | ||
3186 | /* How to start an assembler comment. */ | |
3187 | #ifndef ASM_COMMENT_START | |
3188 | #define ASM_COMMENT_START ";#" | |
3189 | #endif | |
3190 | ||
3191 | /* Define a macro which returns non-zero for a TYPE_DECL which was | |
3192 | implicitly generated for a tagged type. | |
3193 | ||
3194 | Note that unlike the gcc front end (which generates a NULL named | |
3195 | TYPE_DECL node for each complete tagged type, each array type, and | |
3196 | each function type node created) the g++ front end generates a | |
3197 | _named_ TYPE_DECL node for each tagged type node created. | |
3198 | These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to | |
3199 | generate a DW_TAG_typedef DIE for them. */ | |
3200 | ||
3201 | #define TYPE_DECL_IS_STUB(decl) \ | |
3202 | (DECL_NAME (decl) == NULL_TREE \ | |
3203 | || (DECL_ARTIFICIAL (decl) \ | |
3204 | && is_tagged_type (TREE_TYPE (decl)) \ | |
3205 | && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \ | |
3206 | /* This is necessary for stub decls that \ | |
3207 | appear in nested inline functions. */ \ | |
3208 | || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \ | |
3209 | && (decl_ultimate_origin (decl) \ | |
3210 | == TYPE_STUB_DECL (TREE_TYPE (decl))))))) | |
3211 | ||
3212 | /* Information concerning the compilation unit's programming | |
3213 | language, and compiler version. */ | |
3214 | ||
3215 | extern int flag_traditional; | |
3216 | ||
3217 | /* Fixed size portion of the DWARF compilation unit header. */ | |
3218 | #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3) | |
3219 | ||
3220 | /* Fixed size portion of debugging line information prolog. */ | |
3221 | #define DWARF_LINE_PROLOG_HEADER_SIZE 5 | |
3222 | ||
3223 | /* Fixed size portion of public names info. */ | |
3224 | #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2) | |
3225 | ||
3226 | /* Fixed size portion of the address range info. */ | |
3227 | #define DWARF_ARANGES_HEADER_SIZE \ | |
3228 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ | |
3229 | - DWARF_OFFSET_SIZE) | |
3230 | ||
3231 | /* Size of padding portion in the address range info. It must be | |
3232 | aligned to twice the pointer size. */ | |
3233 | #define DWARF_ARANGES_PAD_SIZE \ | |
3234 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ | |
3235 | - (2 * DWARF_OFFSET_SIZE + 4)) | |
3236 | ||
9d147085 | 3237 | /* Use assembler line directives if available. */ |
7d9d8943 | 3238 | #ifndef DWARF2_ASM_LINE_DEBUG_INFO |
9d147085 RH |
3239 | #ifdef HAVE_AS_DWARF2_DEBUG_LINE |
3240 | #define DWARF2_ASM_LINE_DEBUG_INFO 1 | |
3241 | #else | |
7d9d8943 AM |
3242 | #define DWARF2_ASM_LINE_DEBUG_INFO 0 |
3243 | #endif | |
9d147085 | 3244 | #endif |
7d9d8943 AM |
3245 | |
3246 | /* Define the architecture-dependent minimum instruction length (in bytes). | |
3247 | In this implementation of DWARF, this field is used for information | |
3248 | purposes only. Since GCC generates assembly language, we have | |
3249 | no a priori knowledge of how many instruction bytes are generated | |
3250 | for each source line, and therefore can use only the DW_LNE_set_address | |
3251 | and DW_LNS_fixed_advance_pc line information commands. */ | |
7d9d8943 AM |
3252 | #ifndef DWARF_LINE_MIN_INSTR_LENGTH |
3253 | #define DWARF_LINE_MIN_INSTR_LENGTH 4 | |
3254 | #endif | |
3255 | ||
3256 | /* Minimum line offset in a special line info. opcode. | |
3257 | This value was chosen to give a reasonable range of values. */ | |
3258 | #define DWARF_LINE_BASE -10 | |
3259 | ||
a1f300c0 | 3260 | /* First special line opcode - leave room for the standard opcodes. */ |
7d9d8943 AM |
3261 | #define DWARF_LINE_OPCODE_BASE 10 |
3262 | ||
3263 | /* Range of line offsets in a special line info. opcode. */ | |
3264 | #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1) | |
3265 | ||
3266 | /* Flag that indicates the initial value of the is_stmt_start flag. | |
3267 | In the present implementation, we do not mark any lines as | |
3268 | the beginning of a source statement, because that information | |
3269 | is not made available by the GCC front-end. */ | |
3270 | #define DWARF_LINE_DEFAULT_IS_STMT_START 1 | |
3271 | ||
3272 | /* This location is used by calc_die_sizes() to keep track | |
3273 | the offset of each DIE within the .debug_info section. */ | |
3274 | static unsigned long next_die_offset; | |
3275 | ||
3276 | /* Record the root of the DIE's built for the current compilation unit. */ | |
3277 | static dw_die_ref comp_unit_die; | |
3278 | ||
3279 | /* A list of DIEs with a NULL parent waiting to be relocated. */ | |
3280 | static limbo_die_node *limbo_die_list = 0; | |
3281 | ||
2e18bbae RH |
3282 | /* Structure used by lookup_filename to manage sets of filenames. */ |
3283 | struct file_table | |
3284 | { | |
3285 | char **table; | |
3286 | unsigned allocated; | |
3287 | unsigned in_use; | |
3288 | unsigned last_lookup_index; | |
3289 | }; | |
7d9d8943 AM |
3290 | |
3291 | /* Size (in elements) of increments by which we may expand the filename | |
3292 | table. */ | |
3293 | #define FILE_TABLE_INCREMENT 64 | |
3294 | ||
981975b6 RH |
3295 | /* Filenames referenced by this compilation unit. */ |
3296 | static struct file_table file_table; | |
2e18bbae | 3297 | |
7d9d8943 AM |
3298 | /* Local pointer to the name of the main input file. Initialized in |
3299 | dwarf2out_init. */ | |
3300 | static const char *primary_filename; | |
3301 | ||
3302 | /* A pointer to the base of a table of references to DIE's that describe | |
3303 | declarations. The table is indexed by DECL_UID() which is a unique | |
3304 | number identifying each decl. */ | |
3305 | static dw_die_ref *decl_die_table; | |
3306 | ||
3307 | /* Number of elements currently allocated for the decl_die_table. */ | |
3308 | static unsigned decl_die_table_allocated; | |
3309 | ||
3310 | /* Number of elements in decl_die_table currently in use. */ | |
3311 | static unsigned decl_die_table_in_use; | |
3312 | ||
3313 | /* Size (in elements) of increments by which we may expand the | |
3314 | decl_die_table. */ | |
3315 | #define DECL_DIE_TABLE_INCREMENT 256 | |
3316 | ||
3317 | /* A pointer to the base of a table of references to declaration | |
3318 | scopes. This table is a display which tracks the nesting | |
3319 | of declaration scopes at the current scope and containing | |
3320 | scopes. This table is used to find the proper place to | |
3321 | define type declaration DIE's. */ | |
244a4af0 | 3322 | varray_type decl_scope_table; |
7d9d8943 AM |
3323 | |
3324 | /* A pointer to the base of a list of references to DIE's that | |
3325 | are uniquely identified by their tag, presence/absence of | |
3326 | children DIE's, and list of attribute/value pairs. */ | |
3327 | static dw_die_ref *abbrev_die_table; | |
3328 | ||
3329 | /* Number of elements currently allocated for abbrev_die_table. */ | |
3330 | static unsigned abbrev_die_table_allocated; | |
3331 | ||
3332 | /* Number of elements in type_die_table currently in use. */ | |
3333 | static unsigned abbrev_die_table_in_use; | |
3334 | ||
3335 | /* Size (in elements) of increments by which we may expand the | |
3336 | abbrev_die_table. */ | |
3337 | #define ABBREV_DIE_TABLE_INCREMENT 256 | |
3338 | ||
3339 | /* A pointer to the base of a table that contains line information | |
3340 | for each source code line in .text in the compilation unit. */ | |
3341 | static dw_line_info_ref line_info_table; | |
3342 | ||
3343 | /* Number of elements currently allocated for line_info_table. */ | |
3344 | static unsigned line_info_table_allocated; | |
3345 | ||
3346 | /* Number of elements in separate_line_info_table currently in use. */ | |
3347 | static unsigned separate_line_info_table_in_use; | |
3348 | ||
3349 | /* A pointer to the base of a table that contains line information | |
3350 | for each source code line outside of .text in the compilation unit. */ | |
3351 | static dw_separate_line_info_ref separate_line_info_table; | |
3352 | ||
3353 | /* Number of elements currently allocated for separate_line_info_table. */ | |
3354 | static unsigned separate_line_info_table_allocated; | |
3355 | ||
3356 | /* Number of elements in line_info_table currently in use. */ | |
3357 | static unsigned line_info_table_in_use; | |
3358 | ||
3359 | /* Size (in elements) of increments by which we may expand the | |
3360 | line_info_table. */ | |
3361 | #define LINE_INFO_TABLE_INCREMENT 1024 | |
3362 | ||
3363 | /* A pointer to the base of a table that contains a list of publicly | |
3364 | accessible names. */ | |
3365 | static pubname_ref pubname_table; | |
3366 | ||
3367 | /* Number of elements currently allocated for pubname_table. */ | |
3368 | static unsigned pubname_table_allocated; | |
3369 | ||
3370 | /* Number of elements in pubname_table currently in use. */ | |
3371 | static unsigned pubname_table_in_use; | |
3372 | ||
3373 | /* Size (in elements) of increments by which we may expand the | |
3374 | pubname_table. */ | |
3375 | #define PUBNAME_TABLE_INCREMENT 64 | |
3376 | ||
a20612aa RH |
3377 | /* Array of dies for which we should generate .debug_arange info. */ |
3378 | static dw_die_ref *arange_table; | |
7d9d8943 AM |
3379 | |
3380 | /* Number of elements currently allocated for arange_table. */ | |
3381 | static unsigned arange_table_allocated; | |
3382 | ||
3383 | /* Number of elements in arange_table currently in use. */ | |
3384 | static unsigned arange_table_in_use; | |
3385 | ||
3386 | /* Size (in elements) of increments by which we may expand the | |
3387 | arange_table. */ | |
3388 | #define ARANGE_TABLE_INCREMENT 64 | |
3389 | ||
a20612aa RH |
3390 | /* Array of dies for which we should generate .debug_ranges info. */ |
3391 | static dw_ranges_ref ranges_table; | |
3392 | ||
3393 | /* Number of elements currently allocated for ranges_table. */ | |
3394 | static unsigned ranges_table_allocated; | |
3395 | ||
3396 | /* Number of elements in ranges_table currently in use. */ | |
3397 | static unsigned ranges_table_in_use; | |
3398 | ||
3399 | /* Size (in elements) of increments by which we may expand the | |
3400 | ranges_table. */ | |
3401 | #define RANGES_TABLE_INCREMENT 64 | |
3402 | ||
63e46568 DB |
3403 | /* Whether we have location lists that need outputting */ |
3404 | static unsigned have_location_lists; | |
3405 | ||
7d9d8943 | 3406 | /* A pointer to the base of a list of incomplete types which might be |
244a4af0 | 3407 | completed at some later time. incomplete_types_list needs to be a VARRAY |
2ad9852d | 3408 | because we want to tell the garbage collector about it. */ |
244a4af0 | 3409 | varray_type incomplete_types; |
7d9d8943 AM |
3410 | |
3411 | /* Record whether the function being analyzed contains inlined functions. */ | |
3412 | static int current_function_has_inlines; | |
3413 | #if 0 && defined (MIPS_DEBUGGING_INFO) | |
3414 | static int comp_unit_has_inlines; | |
3415 | #endif | |
3416 | ||
3417 | /* Array of RTXes referenced by the debugging information, which therefore | |
c470afad | 3418 | must be kept around forever. This is a GC root. */ |
7d9d8943 AM |
3419 | static varray_type used_rtx_varray; |
3420 | ||
3421 | /* Forward declarations for functions defined in this file. */ | |
3422 | ||
3423 | static int is_pseudo_reg PARAMS ((rtx)); | |
3424 | static tree type_main_variant PARAMS ((tree)); | |
3425 | static int is_tagged_type PARAMS ((tree)); | |
3426 | static const char *dwarf_tag_name PARAMS ((unsigned)); | |
3427 | static const char *dwarf_attr_name PARAMS ((unsigned)); | |
3428 | static const char *dwarf_form_name PARAMS ((unsigned)); | |
3429 | #if 0 | |
3430 | static const char *dwarf_type_encoding_name PARAMS ((unsigned)); | |
3431 | #endif | |
3432 | static tree decl_ultimate_origin PARAMS ((tree)); | |
3433 | static tree block_ultimate_origin PARAMS ((tree)); | |
3434 | static tree decl_class_context PARAMS ((tree)); | |
3435 | static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref)); | |
2ad9852d | 3436 | static inline dw_val_class AT_class PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3437 | static void add_AT_flag PARAMS ((dw_die_ref, |
3438 | enum dwarf_attribute, | |
3439 | unsigned)); | |
2ad9852d | 3440 | static inline unsigned AT_flag PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3441 | static void add_AT_int PARAMS ((dw_die_ref, |
3442 | enum dwarf_attribute, long)); | |
2ad9852d | 3443 | static inline long int AT_int PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3444 | static void add_AT_unsigned PARAMS ((dw_die_ref, |
3445 | enum dwarf_attribute, | |
3446 | unsigned long)); | |
2ad9852d | 3447 | static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3448 | static void add_AT_long_long PARAMS ((dw_die_ref, |
3449 | enum dwarf_attribute, | |
3450 | unsigned long, | |
3451 | unsigned long)); | |
3452 | static void add_AT_float PARAMS ((dw_die_ref, | |
3453 | enum dwarf_attribute, | |
3454 | unsigned, long *)); | |
3455 | static void add_AT_string PARAMS ((dw_die_ref, | |
3456 | enum dwarf_attribute, | |
3457 | const char *)); | |
2ad9852d RK |
3458 | static inline const char *AT_string PARAMS ((dw_attr_ref)); |
3459 | static int AT_string_form PARAMS ((dw_attr_ref)); | |
7d9d8943 AM |
3460 | static void add_AT_die_ref PARAMS ((dw_die_ref, |
3461 | enum dwarf_attribute, | |
3462 | dw_die_ref)); | |
2ad9852d RK |
3463 | static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref)); |
3464 | static inline int AT_ref_external PARAMS ((dw_attr_ref)); | |
3465 | static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int)); | |
7d9d8943 AM |
3466 | static void add_AT_fde_ref PARAMS ((dw_die_ref, |
3467 | enum dwarf_attribute, | |
3468 | unsigned)); | |
3469 | static void add_AT_loc PARAMS ((dw_die_ref, | |
3470 | enum dwarf_attribute, | |
3471 | dw_loc_descr_ref)); | |
2ad9852d | 3472 | static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref)); |
63e46568 DB |
3473 | static void add_AT_loc_list PARAMS ((dw_die_ref, |
3474 | enum dwarf_attribute, | |
3475 | dw_loc_list_ref)); | |
2ad9852d | 3476 | static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3477 | static void add_AT_addr PARAMS ((dw_die_ref, |
3478 | enum dwarf_attribute, | |
3479 | rtx)); | |
2ad9852d | 3480 | static inline rtx AT_addr PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3481 | static void add_AT_lbl_id PARAMS ((dw_die_ref, |
3482 | enum dwarf_attribute, | |
3483 | const char *)); | |
3484 | static void add_AT_lbl_offset PARAMS ((dw_die_ref, | |
3485 | enum dwarf_attribute, | |
3486 | const char *)); | |
a20612aa RH |
3487 | static void add_AT_offset PARAMS ((dw_die_ref, |
3488 | enum dwarf_attribute, | |
3489 | unsigned long)); | |
2bee6045 JJ |
3490 | static void add_AT_range_list PARAMS ((dw_die_ref, |
3491 | enum dwarf_attribute, | |
3492 | unsigned long)); | |
2ad9852d | 3493 | static inline const char *AT_lbl PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3494 | static dw_attr_ref get_AT PARAMS ((dw_die_ref, |
3495 | enum dwarf_attribute)); | |
3496 | static const char *get_AT_low_pc PARAMS ((dw_die_ref)); | |
3497 | static const char *get_AT_hi_pc PARAMS ((dw_die_ref)); | |
3498 | static const char *get_AT_string PARAMS ((dw_die_ref, | |
3499 | enum dwarf_attribute)); | |
3500 | static int get_AT_flag PARAMS ((dw_die_ref, | |
3501 | enum dwarf_attribute)); | |
3502 | static unsigned get_AT_unsigned PARAMS ((dw_die_ref, | |
3503 | enum dwarf_attribute)); | |
3504 | static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref, | |
3505 | enum dwarf_attribute)); | |
3506 | static int is_c_family PARAMS ((void)); | |
710af899 | 3507 | static int is_cxx PARAMS ((void)); |
28985b81 | 3508 | static int is_java PARAMS ((void)); |
7d9d8943 AM |
3509 | static int is_fortran PARAMS ((void)); |
3510 | static void remove_AT PARAMS ((dw_die_ref, | |
3511 | enum dwarf_attribute)); | |
2ad9852d | 3512 | static inline void free_die PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3513 | static void remove_children PARAMS ((dw_die_ref)); |
3514 | static void add_child_die PARAMS ((dw_die_ref, dw_die_ref)); | |
54ba1f0d RH |
3515 | static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref, |
3516 | tree)); | |
7d9d8943 AM |
3517 | static dw_die_ref lookup_type_die PARAMS ((tree)); |
3518 | static void equate_type_number_to_die PARAMS ((tree, dw_die_ref)); | |
3519 | static dw_die_ref lookup_decl_die PARAMS ((tree)); | |
3520 | static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref)); | |
3521 | static void print_spaces PARAMS ((FILE *)); | |
3522 | static void print_die PARAMS ((dw_die_ref, FILE *)); | |
3523 | static void print_dwarf_line_table PARAMS ((FILE *)); | |
881c6935 JM |
3524 | static void reverse_die_lists PARAMS ((dw_die_ref)); |
3525 | static void reverse_all_dies PARAMS ((dw_die_ref)); | |
3526 | static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref)); | |
3527 | static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref)); | |
2ad9852d RK |
3528 | static void loc_checksum PARAMS ((dw_loc_descr_ref, |
3529 | struct md5_ctx *)); | |
3530 | static void attr_checksum PARAMS ((dw_attr_ref, | |
3531 | struct md5_ctx *)); | |
3532 | static void die_checksum PARAMS ((dw_die_ref, | |
3533 | struct md5_ctx *)); | |
881c6935 JM |
3534 | static void compute_section_prefix PARAMS ((dw_die_ref)); |
3535 | static int is_type_die PARAMS ((dw_die_ref)); | |
3536 | static int is_comdat_die PARAMS ((dw_die_ref)); | |
3537 | static int is_symbol_die PARAMS ((dw_die_ref)); | |
881c6935 JM |
3538 | static void assign_symbol_names PARAMS ((dw_die_ref)); |
3539 | static void break_out_includes PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3540 | static void add_sibling_attributes PARAMS ((dw_die_ref)); |
3541 | static void build_abbrev_table PARAMS ((dw_die_ref)); | |
63e46568 | 3542 | static void output_location_lists PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3543 | static int constant_size PARAMS ((long unsigned)); |
3544 | static unsigned long size_of_die PARAMS ((dw_die_ref)); | |
3545 | static void calc_die_sizes PARAMS ((dw_die_ref)); | |
1bfb5f8f JM |
3546 | static void mark_dies PARAMS ((dw_die_ref)); |
3547 | static void unmark_dies PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3548 | static unsigned long size_of_pubnames PARAMS ((void)); |
3549 | static unsigned long size_of_aranges PARAMS ((void)); | |
3550 | static enum dwarf_form value_format PARAMS ((dw_attr_ref)); | |
3551 | static void output_value_format PARAMS ((dw_attr_ref)); | |
3552 | static void output_abbrev_section PARAMS ((void)); | |
881c6935 | 3553 | static void output_die_symbol PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3554 | static void output_die PARAMS ((dw_die_ref)); |
3555 | static void output_compilation_unit_header PARAMS ((void)); | |
881c6935 | 3556 | static void output_comp_unit PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3557 | static const char *dwarf2_name PARAMS ((tree, int)); |
3558 | static void add_pubname PARAMS ((tree, dw_die_ref)); | |
3559 | static void output_pubnames PARAMS ((void)); | |
3560 | static void add_arange PARAMS ((tree, dw_die_ref)); | |
3561 | static void output_aranges PARAMS ((void)); | |
a20612aa RH |
3562 | static unsigned int add_ranges PARAMS ((tree)); |
3563 | static void output_ranges PARAMS ((void)); | |
7d9d8943 | 3564 | static void output_line_info PARAMS ((void)); |
0b34cf1e | 3565 | static void output_file_names PARAMS ((void)); |
7d9d8943 AM |
3566 | static dw_die_ref base_type_die PARAMS ((tree)); |
3567 | static tree root_type PARAMS ((tree)); | |
3568 | static int is_base_type PARAMS ((tree)); | |
3569 | static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref)); | |
3570 | static int type_is_enum PARAMS ((tree)); | |
3571 | static unsigned int reg_number PARAMS ((rtx)); | |
3572 | static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx)); | |
d8041cc8 | 3573 | static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT)); |
7d9d8943 AM |
3574 | static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long)); |
3575 | static int is_based_loc PARAMS ((rtx)); | |
3576 | static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode)); | |
3577 | static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx)); | |
3578 | static dw_loc_descr_ref loc_descriptor PARAMS ((rtx)); | |
d8041cc8 | 3579 | static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int)); |
7d9d8943 AM |
3580 | static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int)); |
3581 | static tree field_type PARAMS ((tree)); | |
3582 | static unsigned int simple_type_align_in_bits PARAMS ((tree)); | |
5f446d21 | 3583 | static unsigned int simple_decl_align_in_bits PARAMS ((tree)); |
7d9d8943 AM |
3584 | static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree)); |
3585 | static HOST_WIDE_INT field_byte_offset PARAMS ((tree)); | |
3586 | static void add_AT_location_description PARAMS ((dw_die_ref, | |
3587 | enum dwarf_attribute, rtx)); | |
3588 | static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree)); | |
3589 | static void add_const_value_attribute PARAMS ((dw_die_ref, rtx)); | |
d8041cc8 | 3590 | static rtx rtl_for_decl_location PARAMS ((tree)); |
7d9d8943 | 3591 | static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree)); |
1bfb5f8f | 3592 | static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree)); |
7d9d8943 AM |
3593 | static void add_name_attribute PARAMS ((dw_die_ref, const char *)); |
3594 | static void add_bound_info PARAMS ((dw_die_ref, | |
3595 | enum dwarf_attribute, tree)); | |
3596 | static void add_subscript_info PARAMS ((dw_die_ref, tree)); | |
3597 | static void add_byte_size_attribute PARAMS ((dw_die_ref, tree)); | |
3598 | static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree)); | |
3599 | static void add_bit_size_attribute PARAMS ((dw_die_ref, tree)); | |
3600 | static void add_prototyped_attribute PARAMS ((dw_die_ref, tree)); | |
3601 | static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree)); | |
3602 | static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree)); | |
3603 | static void add_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
3604 | static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
3605 | static void push_decl_scope PARAMS ((tree)); | |
7d9d8943 | 3606 | static void pop_decl_scope PARAMS ((void)); |
2ad9852d RK |
3607 | static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref)); |
3608 | static inline int local_scope_p PARAMS ((dw_die_ref)); | |
3609 | static inline int class_scope_p PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3610 | static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int, |
3611 | dw_die_ref)); | |
3612 | static const char *type_tag PARAMS ((tree)); | |
3613 | static tree member_declared_type PARAMS ((tree)); | |
3614 | #if 0 | |
3615 | static const char *decl_start_label PARAMS ((tree)); | |
3616 | #endif | |
3617 | static void gen_array_type_die PARAMS ((tree, dw_die_ref)); | |
3618 | static void gen_set_type_die PARAMS ((tree, dw_die_ref)); | |
3619 | #if 0 | |
3620 | static void gen_entry_point_die PARAMS ((tree, dw_die_ref)); | |
3621 | #endif | |
3622 | static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
3623 | static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref)); | |
3624 | static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref)); | |
3625 | static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
3626 | static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref)); | |
3627 | static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref)); | |
3628 | static void gen_formal_types_die PARAMS ((tree, dw_die_ref)); | |
3629 | static void gen_subprogram_die PARAMS ((tree, dw_die_ref)); | |
3630 | static void gen_variable_die PARAMS ((tree, dw_die_ref)); | |
3631 | static void gen_label_die PARAMS ((tree, dw_die_ref)); | |
3632 | static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int)); | |
3633 | static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int)); | |
3634 | static void gen_field_die PARAMS ((tree, dw_die_ref)); | |
3635 | static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref)); | |
3636 | static dw_die_ref gen_compile_unit_die PARAMS ((const char *)); | |
3637 | static void gen_string_type_die PARAMS ((tree, dw_die_ref)); | |
3638 | static void gen_inheritance_die PARAMS ((tree, dw_die_ref)); | |
3639 | static void gen_member_die PARAMS ((tree, dw_die_ref)); | |
3640 | static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref)); | |
3641 | static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref)); | |
3642 | static void gen_typedef_die PARAMS ((tree, dw_die_ref)); | |
3643 | static void gen_type_die PARAMS ((tree, dw_die_ref)); | |
3644 | static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref)); | |
3645 | static void gen_block_die PARAMS ((tree, dw_die_ref, int)); | |
3646 | static void decls_for_scope PARAMS ((tree, dw_die_ref, int)); | |
3647 | static int is_redundant_typedef PARAMS ((tree)); | |
3648 | static void gen_decl_die PARAMS ((tree, dw_die_ref)); | |
981975b6 RH |
3649 | static unsigned lookup_filename PARAMS ((const char *)); |
3650 | static void init_file_table PARAMS ((void)); | |
7d9d8943 AM |
3651 | static void retry_incomplete_types PARAMS ((void)); |
3652 | static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref)); | |
7d9d8943 | 3653 | static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref)); |
fc608b03 | 3654 | static int file_info_cmp PARAMS ((const void *, const void *)); |
84a5b4f8 DB |
3655 | static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref, |
3656 | const char *, const char *, | |
3657 | const char *, unsigned)); | |
3658 | static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *, | |
3659 | dw_loc_descr_ref, | |
3660 | const char *, const char *, const char *)); | |
3661 | static void output_loc_list PARAMS ((dw_loc_list_ref)); | |
3662 | static char *gen_internal_sym PARAMS ((const char *)); | |
54ba1f0d | 3663 | static void mark_limbo_die_list PARAMS ((void *)); |
7d9d8943 AM |
3664 | |
3665 | /* Section names used to hold DWARF debugging information. */ | |
3666 | #ifndef DEBUG_INFO_SECTION | |
3667 | #define DEBUG_INFO_SECTION ".debug_info" | |
3668 | #endif | |
9d2f2c45 RH |
3669 | #ifndef DEBUG_ABBREV_SECTION |
3670 | #define DEBUG_ABBREV_SECTION ".debug_abbrev" | |
7d9d8943 | 3671 | #endif |
9d2f2c45 RH |
3672 | #ifndef DEBUG_ARANGES_SECTION |
3673 | #define DEBUG_ARANGES_SECTION ".debug_aranges" | |
7d9d8943 | 3674 | #endif |
9d2f2c45 RH |
3675 | #ifndef DEBUG_MACINFO_SECTION |
3676 | #define DEBUG_MACINFO_SECTION ".debug_macinfo" | |
7d9d8943 AM |
3677 | #endif |
3678 | #ifndef DEBUG_LINE_SECTION | |
3679 | #define DEBUG_LINE_SECTION ".debug_line" | |
3680 | #endif | |
9d2f2c45 RH |
3681 | #ifndef DEBUG_LOC_SECTION |
3682 | #define DEBUG_LOC_SECTION ".debug_loc" | |
7d9d8943 | 3683 | #endif |
9d2f2c45 RH |
3684 | #ifndef DEBUG_PUBNAMES_SECTION |
3685 | #define DEBUG_PUBNAMES_SECTION ".debug_pubnames" | |
7d9d8943 | 3686 | #endif |
9d2f2c45 RH |
3687 | #ifndef DEBUG_STR_SECTION |
3688 | #define DEBUG_STR_SECTION ".debug_str" | |
7d9d8943 | 3689 | #endif |
a20612aa RH |
3690 | #ifndef DEBUG_RANGES_SECTION |
3691 | #define DEBUG_RANGES_SECTION ".debug_ranges" | |
3692 | #endif | |
7d9d8943 AM |
3693 | |
3694 | /* Standard ELF section names for compiled code and data. */ | |
f99ffb60 RH |
3695 | #ifndef TEXT_SECTION_NAME |
3696 | #define TEXT_SECTION_NAME ".text" | |
7d9d8943 AM |
3697 | #endif |
3698 | ||
9eb4015a JJ |
3699 | /* Section flags for .debug_str section. */ |
3700 | #ifdef HAVE_GAS_SHF_MERGE | |
3701 | #define DEBUG_STR_SECTION_FLAGS \ | |
3702 | (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1) | |
3703 | #else | |
3704 | #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG | |
3705 | #endif | |
3706 | ||
7d9d8943 | 3707 | /* Labels we insert at beginning sections we can reference instead of |
556273e0 | 3708 | the section names themselves. */ |
7d9d8943 AM |
3709 | |
3710 | #ifndef TEXT_SECTION_LABEL | |
9d2f2c45 | 3711 | #define TEXT_SECTION_LABEL "Ltext" |
7d9d8943 AM |
3712 | #endif |
3713 | #ifndef DEBUG_LINE_SECTION_LABEL | |
9d2f2c45 | 3714 | #define DEBUG_LINE_SECTION_LABEL "Ldebug_line" |
7d9d8943 AM |
3715 | #endif |
3716 | #ifndef DEBUG_INFO_SECTION_LABEL | |
9d2f2c45 | 3717 | #define DEBUG_INFO_SECTION_LABEL "Ldebug_info" |
7d9d8943 | 3718 | #endif |
9d2f2c45 RH |
3719 | #ifndef DEBUG_ABBREV_SECTION_LABEL |
3720 | #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev" | |
7d9d8943 | 3721 | #endif |
9d2f2c45 RH |
3722 | #ifndef DEBUG_LOC_SECTION_LABEL |
3723 | #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc" | |
63e46568 | 3724 | #endif |
2bee6045 JJ |
3725 | #ifndef DEBUG_RANGES_SECTION_LABEL |
3726 | #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges" | |
3727 | #endif | |
84a5b4f8 DB |
3728 | #ifndef DEBUG_MACINFO_SECTION_LABEL |
3729 | #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo" | |
3730 | #endif | |
a20612aa | 3731 | |
7d9d8943 AM |
3732 | /* Definitions of defaults for formats and names of various special |
3733 | (artificial) labels which may be generated within this file (when the -g | |
3734 | options is used and DWARF_DEBUGGING_INFO is in effect. | |
3735 | If necessary, these may be overridden from within the tm.h file, but | |
3736 | typically, overriding these defaults is unnecessary. */ | |
3737 | ||
3738 | static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3739 | static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3740 | static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3741 | static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3742 | static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
84a5b4f8 | 3743 | static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
63e46568 | 3744 | static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
2bee6045 | 3745 | static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES]; |
2ad9852d | 3746 | |
7d9d8943 AM |
3747 | #ifndef TEXT_END_LABEL |
3748 | #define TEXT_END_LABEL "Letext" | |
3749 | #endif | |
3750 | #ifndef DATA_END_LABEL | |
3751 | #define DATA_END_LABEL "Ledata" | |
3752 | #endif | |
3753 | #ifndef BSS_END_LABEL | |
3754 | #define BSS_END_LABEL "Lebss" | |
3755 | #endif | |
7d9d8943 AM |
3756 | #ifndef BLOCK_BEGIN_LABEL |
3757 | #define BLOCK_BEGIN_LABEL "LBB" | |
3758 | #endif | |
3759 | #ifndef BLOCK_END_LABEL | |
3760 | #define BLOCK_END_LABEL "LBE" | |
3761 | #endif | |
3762 | #ifndef BODY_BEGIN_LABEL | |
3763 | #define BODY_BEGIN_LABEL "Lbb" | |
3764 | #endif | |
3765 | #ifndef BODY_END_LABEL | |
3766 | #define BODY_END_LABEL "Lbe" | |
3767 | #endif | |
3768 | #ifndef LINE_CODE_LABEL | |
3769 | #define LINE_CODE_LABEL "LM" | |
3770 | #endif | |
3771 | #ifndef SEPARATE_LINE_CODE_LABEL | |
3772 | #define SEPARATE_LINE_CODE_LABEL "LSM" | |
3773 | #endif | |
3774 | \f | |
3775 | /* We allow a language front-end to designate a function that is to be | |
3776 | called to "demangle" any name before it it put into a DIE. */ | |
3777 | ||
3778 | static const char *(*demangle_name_func) PARAMS ((const char *)); | |
3779 | ||
3780 | void | |
3781 | dwarf2out_set_demangle_name_func (func) | |
3782 | const char *(*func) PARAMS ((const char *)); | |
3783 | { | |
3784 | demangle_name_func = func; | |
3785 | } | |
7d9d8943 AM |
3786 | |
3787 | /* Test if rtl node points to a pseudo register. */ | |
3788 | ||
3789 | static inline int | |
3790 | is_pseudo_reg (rtl) | |
b3694847 | 3791 | rtx rtl; |
7d9d8943 AM |
3792 | { |
3793 | return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER) | |
3794 | || (GET_CODE (rtl) == SUBREG | |
ddef6bc7 | 3795 | && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)); |
7d9d8943 AM |
3796 | } |
3797 | ||
3798 | /* Return a reference to a type, with its const and volatile qualifiers | |
3799 | removed. */ | |
3800 | ||
3801 | static inline tree | |
3802 | type_main_variant (type) | |
b3694847 | 3803 | tree type; |
7d9d8943 AM |
3804 | { |
3805 | type = TYPE_MAIN_VARIANT (type); | |
3806 | ||
2ad9852d RK |
3807 | /* ??? There really should be only one main variant among any group of |
3808 | variants of a given type (and all of the MAIN_VARIANT values for all | |
3809 | members of the group should point to that one type) but sometimes the C | |
3810 | front-end messes this up for array types, so we work around that bug | |
3811 | here. */ | |
7d9d8943 AM |
3812 | if (TREE_CODE (type) == ARRAY_TYPE) |
3813 | while (type != TYPE_MAIN_VARIANT (type)) | |
3814 | type = TYPE_MAIN_VARIANT (type); | |
3815 | ||
3816 | return type; | |
3817 | } | |
3818 | ||
3819 | /* Return non-zero if the given type node represents a tagged type. */ | |
3820 | ||
3821 | static inline int | |
3822 | is_tagged_type (type) | |
b3694847 | 3823 | tree type; |
7d9d8943 | 3824 | { |
b3694847 | 3825 | enum tree_code code = TREE_CODE (type); |
7d9d8943 AM |
3826 | |
3827 | return (code == RECORD_TYPE || code == UNION_TYPE | |
3828 | || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); | |
3829 | } | |
3830 | ||
3831 | /* Convert a DIE tag into its string name. */ | |
3832 | ||
3833 | static const char * | |
3834 | dwarf_tag_name (tag) | |
b3694847 | 3835 | unsigned tag; |
7d9d8943 AM |
3836 | { |
3837 | switch (tag) | |
3838 | { | |
3839 | case DW_TAG_padding: | |
3840 | return "DW_TAG_padding"; | |
3841 | case DW_TAG_array_type: | |
3842 | return "DW_TAG_array_type"; | |
3843 | case DW_TAG_class_type: | |
3844 | return "DW_TAG_class_type"; | |
3845 | case DW_TAG_entry_point: | |
3846 | return "DW_TAG_entry_point"; | |
3847 | case DW_TAG_enumeration_type: | |
3848 | return "DW_TAG_enumeration_type"; | |
3849 | case DW_TAG_formal_parameter: | |
3850 | return "DW_TAG_formal_parameter"; | |
3851 | case DW_TAG_imported_declaration: | |
3852 | return "DW_TAG_imported_declaration"; | |
3853 | case DW_TAG_label: | |
3854 | return "DW_TAG_label"; | |
3855 | case DW_TAG_lexical_block: | |
3856 | return "DW_TAG_lexical_block"; | |
3857 | case DW_TAG_member: | |
3858 | return "DW_TAG_member"; | |
3859 | case DW_TAG_pointer_type: | |
3860 | return "DW_TAG_pointer_type"; | |
3861 | case DW_TAG_reference_type: | |
3862 | return "DW_TAG_reference_type"; | |
3863 | case DW_TAG_compile_unit: | |
3864 | return "DW_TAG_compile_unit"; | |
3865 | case DW_TAG_string_type: | |
3866 | return "DW_TAG_string_type"; | |
3867 | case DW_TAG_structure_type: | |
3868 | return "DW_TAG_structure_type"; | |
3869 | case DW_TAG_subroutine_type: | |
3870 | return "DW_TAG_subroutine_type"; | |
3871 | case DW_TAG_typedef: | |
3872 | return "DW_TAG_typedef"; | |
3873 | case DW_TAG_union_type: | |
3874 | return "DW_TAG_union_type"; | |
3875 | case DW_TAG_unspecified_parameters: | |
3876 | return "DW_TAG_unspecified_parameters"; | |
3877 | case DW_TAG_variant: | |
3878 | return "DW_TAG_variant"; | |
3879 | case DW_TAG_common_block: | |
3880 | return "DW_TAG_common_block"; | |
3881 | case DW_TAG_common_inclusion: | |
3882 | return "DW_TAG_common_inclusion"; | |
3883 | case DW_TAG_inheritance: | |
3884 | return "DW_TAG_inheritance"; | |
3885 | case DW_TAG_inlined_subroutine: | |
3886 | return "DW_TAG_inlined_subroutine"; | |
3887 | case DW_TAG_module: | |
3888 | return "DW_TAG_module"; | |
3889 | case DW_TAG_ptr_to_member_type: | |
3890 | return "DW_TAG_ptr_to_member_type"; | |
3891 | case DW_TAG_set_type: | |
3892 | return "DW_TAG_set_type"; | |
3893 | case DW_TAG_subrange_type: | |
3894 | return "DW_TAG_subrange_type"; | |
3895 | case DW_TAG_with_stmt: | |
3896 | return "DW_TAG_with_stmt"; | |
3897 | case DW_TAG_access_declaration: | |
3898 | return "DW_TAG_access_declaration"; | |
3899 | case DW_TAG_base_type: | |
3900 | return "DW_TAG_base_type"; | |
3901 | case DW_TAG_catch_block: | |
3902 | return "DW_TAG_catch_block"; | |
3903 | case DW_TAG_const_type: | |
3904 | return "DW_TAG_const_type"; | |
3905 | case DW_TAG_constant: | |
3906 | return "DW_TAG_constant"; | |
3907 | case DW_TAG_enumerator: | |
3908 | return "DW_TAG_enumerator"; | |
3909 | case DW_TAG_file_type: | |
3910 | return "DW_TAG_file_type"; | |
3911 | case DW_TAG_friend: | |
3912 | return "DW_TAG_friend"; | |
3913 | case DW_TAG_namelist: | |
3914 | return "DW_TAG_namelist"; | |
3915 | case DW_TAG_namelist_item: | |
3916 | return "DW_TAG_namelist_item"; | |
3917 | case DW_TAG_packed_type: | |
3918 | return "DW_TAG_packed_type"; | |
3919 | case DW_TAG_subprogram: | |
3920 | return "DW_TAG_subprogram"; | |
3921 | case DW_TAG_template_type_param: | |
3922 | return "DW_TAG_template_type_param"; | |
3923 | case DW_TAG_template_value_param: | |
3924 | return "DW_TAG_template_value_param"; | |
3925 | case DW_TAG_thrown_type: | |
3926 | return "DW_TAG_thrown_type"; | |
3927 | case DW_TAG_try_block: | |
3928 | return "DW_TAG_try_block"; | |
3929 | case DW_TAG_variant_part: | |
3930 | return "DW_TAG_variant_part"; | |
3931 | case DW_TAG_variable: | |
3932 | return "DW_TAG_variable"; | |
3933 | case DW_TAG_volatile_type: | |
3934 | return "DW_TAG_volatile_type"; | |
3935 | case DW_TAG_MIPS_loop: | |
3936 | return "DW_TAG_MIPS_loop"; | |
3937 | case DW_TAG_format_label: | |
3938 | return "DW_TAG_format_label"; | |
3939 | case DW_TAG_function_template: | |
3940 | return "DW_TAG_function_template"; | |
3941 | case DW_TAG_class_template: | |
3942 | return "DW_TAG_class_template"; | |
881c6935 JM |
3943 | case DW_TAG_GNU_BINCL: |
3944 | return "DW_TAG_GNU_BINCL"; | |
3945 | case DW_TAG_GNU_EINCL: | |
3946 | return "DW_TAG_GNU_EINCL"; | |
7d9d8943 AM |
3947 | default: |
3948 | return "DW_TAG_<unknown>"; | |
3949 | } | |
3950 | } | |
3951 | ||
3952 | /* Convert a DWARF attribute code into its string name. */ | |
3953 | ||
3954 | static const char * | |
3955 | dwarf_attr_name (attr) | |
b3694847 | 3956 | unsigned attr; |
7d9d8943 AM |
3957 | { |
3958 | switch (attr) | |
3959 | { | |
3960 | case DW_AT_sibling: | |
3961 | return "DW_AT_sibling"; | |
3962 | case DW_AT_location: | |
3963 | return "DW_AT_location"; | |
3964 | case DW_AT_name: | |
3965 | return "DW_AT_name"; | |
3966 | case DW_AT_ordering: | |
3967 | return "DW_AT_ordering"; | |
3968 | case DW_AT_subscr_data: | |
3969 | return "DW_AT_subscr_data"; | |
3970 | case DW_AT_byte_size: | |
3971 | return "DW_AT_byte_size"; | |
3972 | case DW_AT_bit_offset: | |
3973 | return "DW_AT_bit_offset"; | |
3974 | case DW_AT_bit_size: | |
3975 | return "DW_AT_bit_size"; | |
3976 | case DW_AT_element_list: | |
3977 | return "DW_AT_element_list"; | |
3978 | case DW_AT_stmt_list: | |
3979 | return "DW_AT_stmt_list"; | |
3980 | case DW_AT_low_pc: | |
3981 | return "DW_AT_low_pc"; | |
3982 | case DW_AT_high_pc: | |
3983 | return "DW_AT_high_pc"; | |
3984 | case DW_AT_language: | |
3985 | return "DW_AT_language"; | |
3986 | case DW_AT_member: | |
3987 | return "DW_AT_member"; | |
3988 | case DW_AT_discr: | |
3989 | return "DW_AT_discr"; | |
3990 | case DW_AT_discr_value: | |
3991 | return "DW_AT_discr_value"; | |
3992 | case DW_AT_visibility: | |
3993 | return "DW_AT_visibility"; | |
3994 | case DW_AT_import: | |
3995 | return "DW_AT_import"; | |
3996 | case DW_AT_string_length: | |
3997 | return "DW_AT_string_length"; | |
3998 | case DW_AT_common_reference: | |
3999 | return "DW_AT_common_reference"; | |
4000 | case DW_AT_comp_dir: | |
4001 | return "DW_AT_comp_dir"; | |
4002 | case DW_AT_const_value: | |
4003 | return "DW_AT_const_value"; | |
4004 | case DW_AT_containing_type: | |
4005 | return "DW_AT_containing_type"; | |
4006 | case DW_AT_default_value: | |
4007 | return "DW_AT_default_value"; | |
4008 | case DW_AT_inline: | |
4009 | return "DW_AT_inline"; | |
4010 | case DW_AT_is_optional: | |
4011 | return "DW_AT_is_optional"; | |
4012 | case DW_AT_lower_bound: | |
4013 | return "DW_AT_lower_bound"; | |
4014 | case DW_AT_producer: | |
4015 | return "DW_AT_producer"; | |
4016 | case DW_AT_prototyped: | |
4017 | return "DW_AT_prototyped"; | |
4018 | case DW_AT_return_addr: | |
4019 | return "DW_AT_return_addr"; | |
4020 | case DW_AT_start_scope: | |
4021 | return "DW_AT_start_scope"; | |
4022 | case DW_AT_stride_size: | |
4023 | return "DW_AT_stride_size"; | |
4024 | case DW_AT_upper_bound: | |
4025 | return "DW_AT_upper_bound"; | |
4026 | case DW_AT_abstract_origin: | |
4027 | return "DW_AT_abstract_origin"; | |
4028 | case DW_AT_accessibility: | |
4029 | return "DW_AT_accessibility"; | |
4030 | case DW_AT_address_class: | |
4031 | return "DW_AT_address_class"; | |
4032 | case DW_AT_artificial: | |
4033 | return "DW_AT_artificial"; | |
4034 | case DW_AT_base_types: | |
4035 | return "DW_AT_base_types"; | |
4036 | case DW_AT_calling_convention: | |
4037 | return "DW_AT_calling_convention"; | |
4038 | case DW_AT_count: | |
4039 | return "DW_AT_count"; | |
4040 | case DW_AT_data_member_location: | |
4041 | return "DW_AT_data_member_location"; | |
4042 | case DW_AT_decl_column: | |
4043 | return "DW_AT_decl_column"; | |
4044 | case DW_AT_decl_file: | |
4045 | return "DW_AT_decl_file"; | |
4046 | case DW_AT_decl_line: | |
4047 | return "DW_AT_decl_line"; | |
4048 | case DW_AT_declaration: | |
4049 | return "DW_AT_declaration"; | |
4050 | case DW_AT_discr_list: | |
4051 | return "DW_AT_discr_list"; | |
4052 | case DW_AT_encoding: | |
4053 | return "DW_AT_encoding"; | |
4054 | case DW_AT_external: | |
4055 | return "DW_AT_external"; | |
4056 | case DW_AT_frame_base: | |
4057 | return "DW_AT_frame_base"; | |
4058 | case DW_AT_friend: | |
4059 | return "DW_AT_friend"; | |
4060 | case DW_AT_identifier_case: | |
4061 | return "DW_AT_identifier_case"; | |
4062 | case DW_AT_macro_info: | |
4063 | return "DW_AT_macro_info"; | |
4064 | case DW_AT_namelist_items: | |
4065 | return "DW_AT_namelist_items"; | |
4066 | case DW_AT_priority: | |
4067 | return "DW_AT_priority"; | |
4068 | case DW_AT_segment: | |
4069 | return "DW_AT_segment"; | |
4070 | case DW_AT_specification: | |
4071 | return "DW_AT_specification"; | |
4072 | case DW_AT_static_link: | |
4073 | return "DW_AT_static_link"; | |
4074 | case DW_AT_type: | |
4075 | return "DW_AT_type"; | |
4076 | case DW_AT_use_location: | |
4077 | return "DW_AT_use_location"; | |
4078 | case DW_AT_variable_parameter: | |
4079 | return "DW_AT_variable_parameter"; | |
4080 | case DW_AT_virtuality: | |
4081 | return "DW_AT_virtuality"; | |
4082 | case DW_AT_vtable_elem_location: | |
4083 | return "DW_AT_vtable_elem_location"; | |
4084 | ||
a20612aa RH |
4085 | case DW_AT_allocated: |
4086 | return "DW_AT_allocated"; | |
4087 | case DW_AT_associated: | |
4088 | return "DW_AT_associated"; | |
4089 | case DW_AT_data_location: | |
4090 | return "DW_AT_data_location"; | |
4091 | case DW_AT_stride: | |
4092 | return "DW_AT_stride"; | |
4093 | case DW_AT_entry_pc: | |
4094 | return "DW_AT_entry_pc"; | |
4095 | case DW_AT_use_UTF8: | |
4096 | return "DW_AT_use_UTF8"; | |
4097 | case DW_AT_extension: | |
4098 | return "DW_AT_extension"; | |
4099 | case DW_AT_ranges: | |
4100 | return "DW_AT_ranges"; | |
4101 | case DW_AT_trampoline: | |
4102 | return "DW_AT_trampoline"; | |
4103 | case DW_AT_call_column: | |
4104 | return "DW_AT_call_column"; | |
4105 | case DW_AT_call_file: | |
4106 | return "DW_AT_call_file"; | |
4107 | case DW_AT_call_line: | |
4108 | return "DW_AT_call_line"; | |
4109 | ||
7d9d8943 AM |
4110 | case DW_AT_MIPS_fde: |
4111 | return "DW_AT_MIPS_fde"; | |
4112 | case DW_AT_MIPS_loop_begin: | |
4113 | return "DW_AT_MIPS_loop_begin"; | |
4114 | case DW_AT_MIPS_tail_loop_begin: | |
4115 | return "DW_AT_MIPS_tail_loop_begin"; | |
4116 | case DW_AT_MIPS_epilog_begin: | |
4117 | return "DW_AT_MIPS_epilog_begin"; | |
4118 | case DW_AT_MIPS_loop_unroll_factor: | |
4119 | return "DW_AT_MIPS_loop_unroll_factor"; | |
4120 | case DW_AT_MIPS_software_pipeline_depth: | |
4121 | return "DW_AT_MIPS_software_pipeline_depth"; | |
4122 | case DW_AT_MIPS_linkage_name: | |
4123 | return "DW_AT_MIPS_linkage_name"; | |
4124 | case DW_AT_MIPS_stride: | |
4125 | return "DW_AT_MIPS_stride"; | |
4126 | case DW_AT_MIPS_abstract_name: | |
4127 | return "DW_AT_MIPS_abstract_name"; | |
4128 | case DW_AT_MIPS_clone_origin: | |
4129 | return "DW_AT_MIPS_clone_origin"; | |
4130 | case DW_AT_MIPS_has_inlines: | |
4131 | return "DW_AT_MIPS_has_inlines"; | |
4132 | ||
4133 | case DW_AT_sf_names: | |
4134 | return "DW_AT_sf_names"; | |
4135 | case DW_AT_src_info: | |
4136 | return "DW_AT_src_info"; | |
4137 | case DW_AT_mac_info: | |
4138 | return "DW_AT_mac_info"; | |
4139 | case DW_AT_src_coords: | |
4140 | return "DW_AT_src_coords"; | |
4141 | case DW_AT_body_begin: | |
4142 | return "DW_AT_body_begin"; | |
4143 | case DW_AT_body_end: | |
4144 | return "DW_AT_body_end"; | |
7a0c8d71 DR |
4145 | case DW_AT_VMS_rtnbeg_pd_address: |
4146 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
4147 | ||
7d9d8943 AM |
4148 | default: |
4149 | return "DW_AT_<unknown>"; | |
4150 | } | |
4151 | } | |
4152 | ||
4153 | /* Convert a DWARF value form code into its string name. */ | |
4154 | ||
4155 | static const char * | |
4156 | dwarf_form_name (form) | |
b3694847 | 4157 | unsigned form; |
7d9d8943 AM |
4158 | { |
4159 | switch (form) | |
4160 | { | |
4161 | case DW_FORM_addr: | |
4162 | return "DW_FORM_addr"; | |
4163 | case DW_FORM_block2: | |
4164 | return "DW_FORM_block2"; | |
4165 | case DW_FORM_block4: | |
4166 | return "DW_FORM_block4"; | |
4167 | case DW_FORM_data2: | |
4168 | return "DW_FORM_data2"; | |
4169 | case DW_FORM_data4: | |
4170 | return "DW_FORM_data4"; | |
4171 | case DW_FORM_data8: | |
4172 | return "DW_FORM_data8"; | |
4173 | case DW_FORM_string: | |
4174 | return "DW_FORM_string"; | |
4175 | case DW_FORM_block: | |
4176 | return "DW_FORM_block"; | |
4177 | case DW_FORM_block1: | |
4178 | return "DW_FORM_block1"; | |
4179 | case DW_FORM_data1: | |
4180 | return "DW_FORM_data1"; | |
4181 | case DW_FORM_flag: | |
4182 | return "DW_FORM_flag"; | |
4183 | case DW_FORM_sdata: | |
4184 | return "DW_FORM_sdata"; | |
4185 | case DW_FORM_strp: | |
4186 | return "DW_FORM_strp"; | |
4187 | case DW_FORM_udata: | |
4188 | return "DW_FORM_udata"; | |
4189 | case DW_FORM_ref_addr: | |
4190 | return "DW_FORM_ref_addr"; | |
4191 | case DW_FORM_ref1: | |
4192 | return "DW_FORM_ref1"; | |
4193 | case DW_FORM_ref2: | |
4194 | return "DW_FORM_ref2"; | |
4195 | case DW_FORM_ref4: | |
4196 | return "DW_FORM_ref4"; | |
4197 | case DW_FORM_ref8: | |
4198 | return "DW_FORM_ref8"; | |
4199 | case DW_FORM_ref_udata: | |
4200 | return "DW_FORM_ref_udata"; | |
4201 | case DW_FORM_indirect: | |
4202 | return "DW_FORM_indirect"; | |
3f76745e | 4203 | default: |
7d9d8943 | 4204 | return "DW_FORM_<unknown>"; |
a3f97cbb JW |
4205 | } |
4206 | } | |
4207 | ||
3f76745e | 4208 | /* Convert a DWARF type code into its string name. */ |
71dfc51f | 4209 | |
487a6e06 | 4210 | #if 0 |
d560ee52 | 4211 | static const char * |
3f76745e | 4212 | dwarf_type_encoding_name (enc) |
b3694847 | 4213 | unsigned enc; |
a3f97cbb | 4214 | { |
3f76745e | 4215 | switch (enc) |
a3f97cbb | 4216 | { |
3f76745e JM |
4217 | case DW_ATE_address: |
4218 | return "DW_ATE_address"; | |
4219 | case DW_ATE_boolean: | |
4220 | return "DW_ATE_boolean"; | |
4221 | case DW_ATE_complex_float: | |
4222 | return "DW_ATE_complex_float"; | |
4223 | case DW_ATE_float: | |
4224 | return "DW_ATE_float"; | |
4225 | case DW_ATE_signed: | |
4226 | return "DW_ATE_signed"; | |
4227 | case DW_ATE_signed_char: | |
4228 | return "DW_ATE_signed_char"; | |
4229 | case DW_ATE_unsigned: | |
4230 | return "DW_ATE_unsigned"; | |
4231 | case DW_ATE_unsigned_char: | |
4232 | return "DW_ATE_unsigned_char"; | |
4233 | default: | |
4234 | return "DW_ATE_<unknown>"; | |
4235 | } | |
a3f97cbb | 4236 | } |
487a6e06 | 4237 | #endif |
3f76745e JM |
4238 | \f |
4239 | /* Determine the "ultimate origin" of a decl. The decl may be an inlined | |
4240 | instance of an inlined instance of a decl which is local to an inline | |
4241 | function, so we have to trace all of the way back through the origin chain | |
4242 | to find out what sort of node actually served as the original seed for the | |
4243 | given block. */ | |
a3f97cbb | 4244 | |
3f76745e JM |
4245 | static tree |
4246 | decl_ultimate_origin (decl) | |
b3694847 | 4247 | tree decl; |
a3f97cbb | 4248 | { |
10a11b75 JM |
4249 | /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the |
4250 | nodes in the function to point to themselves; ignore that if | |
4251 | we're trying to output the abstract instance of this function. */ | |
4252 | if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl) | |
4253 | return NULL_TREE; | |
4254 | ||
556273e0 | 4255 | #ifdef ENABLE_CHECKING |
02e24c7a MM |
4256 | if (DECL_FROM_INLINE (DECL_ORIGIN (decl))) |
4257 | /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the | |
4258 | most distant ancestor, this should never happen. */ | |
4259 | abort (); | |
4260 | #endif | |
3f76745e | 4261 | |
02e24c7a | 4262 | return DECL_ABSTRACT_ORIGIN (decl); |
a3f97cbb JW |
4263 | } |
4264 | ||
3f76745e JM |
4265 | /* Determine the "ultimate origin" of a block. The block may be an inlined |
4266 | instance of an inlined instance of a block which is local to an inline | |
4267 | function, so we have to trace all of the way back through the origin chain | |
4268 | to find out what sort of node actually served as the original seed for the | |
4269 | given block. */ | |
71dfc51f | 4270 | |
3f76745e JM |
4271 | static tree |
4272 | block_ultimate_origin (block) | |
b3694847 | 4273 | tree block; |
a3f97cbb | 4274 | { |
b3694847 | 4275 | tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); |
71dfc51f | 4276 | |
10a11b75 JM |
4277 | /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the |
4278 | nodes in the function to point to themselves; ignore that if | |
4279 | we're trying to output the abstract instance of this function. */ | |
4280 | if (BLOCK_ABSTRACT (block) && immediate_origin == block) | |
4281 | return NULL_TREE; | |
4282 | ||
3f76745e JM |
4283 | if (immediate_origin == NULL_TREE) |
4284 | return NULL_TREE; | |
4285 | else | |
4286 | { | |
b3694847 SS |
4287 | tree ret_val; |
4288 | tree lookahead = immediate_origin; | |
71dfc51f | 4289 | |
3f76745e JM |
4290 | do |
4291 | { | |
4292 | ret_val = lookahead; | |
2ad9852d RK |
4293 | lookahead = (TREE_CODE (ret_val) == BLOCK |
4294 | ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL); | |
3f76745e JM |
4295 | } |
4296 | while (lookahead != NULL && lookahead != ret_val); | |
4297 | ||
4298 | return ret_val; | |
4299 | } | |
a3f97cbb JW |
4300 | } |
4301 | ||
3f76745e JM |
4302 | /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT |
4303 | of a virtual function may refer to a base class, so we check the 'this' | |
4304 | parameter. */ | |
71dfc51f | 4305 | |
3f76745e JM |
4306 | static tree |
4307 | decl_class_context (decl) | |
4308 | tree decl; | |
a3f97cbb | 4309 | { |
3f76745e | 4310 | tree context = NULL_TREE; |
71dfc51f | 4311 | |
3f76745e JM |
4312 | if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl)) |
4313 | context = DECL_CONTEXT (decl); | |
4314 | else | |
4315 | context = TYPE_MAIN_VARIANT | |
4316 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
71dfc51f | 4317 | |
2f939d94 | 4318 | if (context && !TYPE_P (context)) |
3f76745e JM |
4319 | context = NULL_TREE; |
4320 | ||
4321 | return context; | |
a3f97cbb JW |
4322 | } |
4323 | \f | |
a96c67ec | 4324 | /* Add an attribute/value pair to a DIE. We build the lists up in reverse |
881c6935 | 4325 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f RK |
4326 | |
4327 | static inline void | |
3f76745e | 4328 | add_dwarf_attr (die, attr) |
b3694847 SS |
4329 | dw_die_ref die; |
4330 | dw_attr_ref attr; | |
a3f97cbb | 4331 | { |
3f76745e | 4332 | if (die != NULL && attr != NULL) |
a3f97cbb | 4333 | { |
a96c67ec JM |
4334 | attr->dw_attr_next = die->die_attr; |
4335 | die->die_attr = attr; | |
a3f97cbb JW |
4336 | } |
4337 | } | |
4338 | ||
a96c67ec JM |
4339 | static inline dw_val_class |
4340 | AT_class (a) | |
4341 | dw_attr_ref a; | |
4342 | { | |
4343 | return a->dw_attr_val.val_class; | |
4344 | } | |
4345 | ||
3f76745e | 4346 | /* Add a flag value attribute to a DIE. */ |
71dfc51f | 4347 | |
3f76745e JM |
4348 | static inline void |
4349 | add_AT_flag (die, attr_kind, flag) | |
b3694847 SS |
4350 | dw_die_ref die; |
4351 | enum dwarf_attribute attr_kind; | |
4352 | unsigned flag; | |
a3f97cbb | 4353 | { |
b3694847 | 4354 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4355 | |
3f76745e JM |
4356 | attr->dw_attr_next = NULL; |
4357 | attr->dw_attr = attr_kind; | |
4358 | attr->dw_attr_val.val_class = dw_val_class_flag; | |
4359 | attr->dw_attr_val.v.val_flag = flag; | |
4360 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4361 | } |
4362 | ||
a96c67ec JM |
4363 | static inline unsigned |
4364 | AT_flag (a) | |
b3694847 | 4365 | dw_attr_ref a; |
a96c67ec JM |
4366 | { |
4367 | if (a && AT_class (a) == dw_val_class_flag) | |
4368 | return a->dw_attr_val.v.val_flag; | |
4369 | ||
40e8cc95 | 4370 | abort (); |
a96c67ec JM |
4371 | } |
4372 | ||
3f76745e | 4373 | /* Add a signed integer attribute value to a DIE. */ |
71dfc51f | 4374 | |
3f76745e JM |
4375 | static inline void |
4376 | add_AT_int (die, attr_kind, int_val) | |
b3694847 SS |
4377 | dw_die_ref die; |
4378 | enum dwarf_attribute attr_kind; | |
4379 | long int int_val; | |
a3f97cbb | 4380 | { |
b3694847 | 4381 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3f76745e JM |
4382 | |
4383 | attr->dw_attr_next = NULL; | |
4384 | attr->dw_attr = attr_kind; | |
4385 | attr->dw_attr_val.val_class = dw_val_class_const; | |
4386 | attr->dw_attr_val.v.val_int = int_val; | |
4387 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4388 | } |
4389 | ||
a96c67ec JM |
4390 | static inline long int |
4391 | AT_int (a) | |
b3694847 | 4392 | dw_attr_ref a; |
a96c67ec JM |
4393 | { |
4394 | if (a && AT_class (a) == dw_val_class_const) | |
4395 | return a->dw_attr_val.v.val_int; | |
4396 | ||
40e8cc95 | 4397 | abort (); |
a96c67ec JM |
4398 | } |
4399 | ||
3f76745e | 4400 | /* Add an unsigned integer attribute value to a DIE. */ |
71dfc51f | 4401 | |
3f76745e JM |
4402 | static inline void |
4403 | add_AT_unsigned (die, attr_kind, unsigned_val) | |
b3694847 SS |
4404 | dw_die_ref die; |
4405 | enum dwarf_attribute attr_kind; | |
4406 | unsigned long unsigned_val; | |
a3f97cbb | 4407 | { |
b3694847 | 4408 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3f76745e JM |
4409 | |
4410 | attr->dw_attr_next = NULL; | |
4411 | attr->dw_attr = attr_kind; | |
4412 | attr->dw_attr_val.val_class = dw_val_class_unsigned_const; | |
4413 | attr->dw_attr_val.v.val_unsigned = unsigned_val; | |
4414 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4415 | } |
71dfc51f | 4416 | |
a96c67ec JM |
4417 | static inline unsigned long |
4418 | AT_unsigned (a) | |
b3694847 | 4419 | dw_attr_ref a; |
a96c67ec JM |
4420 | { |
4421 | if (a && AT_class (a) == dw_val_class_unsigned_const) | |
4422 | return a->dw_attr_val.v.val_unsigned; | |
4423 | ||
40e8cc95 | 4424 | abort (); |
a96c67ec JM |
4425 | } |
4426 | ||
3f76745e JM |
4427 | /* Add an unsigned double integer attribute value to a DIE. */ |
4428 | ||
4429 | static inline void | |
4430 | add_AT_long_long (die, attr_kind, val_hi, val_low) | |
b3694847 SS |
4431 | dw_die_ref die; |
4432 | enum dwarf_attribute attr_kind; | |
4433 | unsigned long val_hi; | |
4434 | unsigned long val_low; | |
a3f97cbb | 4435 | { |
b3694847 | 4436 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4437 | |
3f76745e JM |
4438 | attr->dw_attr_next = NULL; |
4439 | attr->dw_attr = attr_kind; | |
4440 | attr->dw_attr_val.val_class = dw_val_class_long_long; | |
4441 | attr->dw_attr_val.v.val_long_long.hi = val_hi; | |
4442 | attr->dw_attr_val.v.val_long_long.low = val_low; | |
4443 | add_dwarf_attr (die, attr); | |
4444 | } | |
71dfc51f | 4445 | |
3f76745e | 4446 | /* Add a floating point attribute value to a DIE and return it. */ |
71dfc51f | 4447 | |
3f76745e JM |
4448 | static inline void |
4449 | add_AT_float (die, attr_kind, length, array) | |
b3694847 SS |
4450 | dw_die_ref die; |
4451 | enum dwarf_attribute attr_kind; | |
4452 | unsigned length; | |
4453 | long *array; | |
3f76745e | 4454 | { |
b3694847 | 4455 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3f76745e JM |
4456 | |
4457 | attr->dw_attr_next = NULL; | |
4458 | attr->dw_attr = attr_kind; | |
4459 | attr->dw_attr_val.val_class = dw_val_class_float; | |
4460 | attr->dw_attr_val.v.val_float.length = length; | |
4461 | attr->dw_attr_val.v.val_float.array = array; | |
4462 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4463 | } |
4464 | ||
3f76745e | 4465 | /* Add a string attribute value to a DIE. */ |
71dfc51f | 4466 | |
3f76745e JM |
4467 | static inline void |
4468 | add_AT_string (die, attr_kind, str) | |
b3694847 SS |
4469 | dw_die_ref die; |
4470 | enum dwarf_attribute attr_kind; | |
4471 | const char *str; | |
a3f97cbb | 4472 | { |
b3694847 | 4473 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
9eb4015a JJ |
4474 | struct indirect_string_node *node; |
4475 | ||
4476 | if (! debug_str_hash) | |
4477 | { | |
4478 | debug_str_hash = ht_create (10); | |
4479 | debug_str_hash->alloc_node = indirect_string_alloc; | |
4480 | } | |
4481 | ||
4482 | node = (struct indirect_string_node *) | |
4483 | ht_lookup (debug_str_hash, (const unsigned char *) str, | |
4484 | strlen (str), HT_ALLOC); | |
4485 | node->refcount++; | |
71dfc51f | 4486 | |
3f76745e JM |
4487 | attr->dw_attr_next = NULL; |
4488 | attr->dw_attr = attr_kind; | |
4489 | attr->dw_attr_val.val_class = dw_val_class_str; | |
9eb4015a | 4490 | attr->dw_attr_val.v.val_str = node; |
3f76745e JM |
4491 | add_dwarf_attr (die, attr); |
4492 | } | |
71dfc51f | 4493 | |
a96c67ec JM |
4494 | static inline const char * |
4495 | AT_string (a) | |
b3694847 | 4496 | dw_attr_ref a; |
a96c67ec JM |
4497 | { |
4498 | if (a && AT_class (a) == dw_val_class_str) | |
9eb4015a JJ |
4499 | return (const char *) HT_STR (&a->dw_attr_val.v.val_str->id); |
4500 | ||
4501 | abort (); | |
4502 | } | |
4503 | ||
4504 | /* Find out whether a string should be output inline in DIE | |
4505 | or out-of-line in .debug_str section. */ | |
4506 | ||
9eb4015a JJ |
4507 | static int |
4508 | AT_string_form (a) | |
4509 | dw_attr_ref a; | |
4510 | { | |
4511 | if (a && AT_class (a) == dw_val_class_str) | |
4512 | { | |
4513 | struct indirect_string_node *node; | |
4514 | unsigned int len; | |
4515 | extern int const_labelno; | |
4516 | char label[32]; | |
4517 | ||
4518 | node = a->dw_attr_val.v.val_str; | |
4519 | if (node->form) | |
4520 | return node->form; | |
4521 | ||
4522 | len = HT_LEN (&node->id) + 1; | |
4523 | ||
2ad9852d RK |
4524 | /* If the string is shorter or equal to the size of the reference, it is |
4525 | always better to put it inline. */ | |
9eb4015a JJ |
4526 | if (len <= DWARF_OFFSET_SIZE || node->refcount == 0) |
4527 | return node->form = DW_FORM_string; | |
4528 | ||
2ad9852d RK |
4529 | /* If we cannot expect the linker to merge strings in .debug_str |
4530 | section, only put it into .debug_str if it is worth even in this | |
4531 | single module. */ | |
4532 | if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0 | |
4533 | && (len - DWARF_OFFSET_SIZE) * node->refcount <= len) | |
4534 | return node->form = DW_FORM_string; | |
9eb4015a JJ |
4535 | |
4536 | ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno); | |
4537 | ++const_labelno; | |
4538 | node->label = xstrdup (label); | |
2ad9852d | 4539 | |
9eb4015a JJ |
4540 | return node->form = DW_FORM_strp; |
4541 | } | |
a96c67ec | 4542 | |
40e8cc95 | 4543 | abort (); |
a96c67ec JM |
4544 | } |
4545 | ||
3f76745e | 4546 | /* Add a DIE reference attribute value to a DIE. */ |
71dfc51f | 4547 | |
3f76745e JM |
4548 | static inline void |
4549 | add_AT_die_ref (die, attr_kind, targ_die) | |
b3694847 SS |
4550 | dw_die_ref die; |
4551 | enum dwarf_attribute attr_kind; | |
4552 | dw_die_ref targ_die; | |
3f76745e | 4553 | { |
b3694847 | 4554 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4555 | |
3f76745e JM |
4556 | attr->dw_attr_next = NULL; |
4557 | attr->dw_attr = attr_kind; | |
4558 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
881c6935 JM |
4559 | attr->dw_attr_val.v.val_die_ref.die = targ_die; |
4560 | attr->dw_attr_val.v.val_die_ref.external = 0; | |
3f76745e JM |
4561 | add_dwarf_attr (die, attr); |
4562 | } | |
b1ccbc24 | 4563 | |
a96c67ec JM |
4564 | static inline dw_die_ref |
4565 | AT_ref (a) | |
b3694847 | 4566 | dw_attr_ref a; |
a96c67ec JM |
4567 | { |
4568 | if (a && AT_class (a) == dw_val_class_die_ref) | |
881c6935 | 4569 | return a->dw_attr_val.v.val_die_ref.die; |
a96c67ec | 4570 | |
40e8cc95 | 4571 | abort (); |
a96c67ec JM |
4572 | } |
4573 | ||
881c6935 JM |
4574 | static inline int |
4575 | AT_ref_external (a) | |
b3694847 | 4576 | dw_attr_ref a; |
881c6935 JM |
4577 | { |
4578 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4579 | return a->dw_attr_val.v.val_die_ref.external; | |
4580 | ||
4581 | return 0; | |
4582 | } | |
4583 | ||
881c6935 JM |
4584 | static inline void |
4585 | set_AT_ref_external (a, i) | |
b3694847 | 4586 | dw_attr_ref a; |
881c6935 JM |
4587 | int i; |
4588 | { | |
4589 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4590 | a->dw_attr_val.v.val_die_ref.external = i; | |
4591 | else | |
4592 | abort (); | |
4593 | } | |
4594 | ||
3f76745e | 4595 | /* Add an FDE reference attribute value to a DIE. */ |
b1ccbc24 | 4596 | |
3f76745e JM |
4597 | static inline void |
4598 | add_AT_fde_ref (die, attr_kind, targ_fde) | |
b3694847 SS |
4599 | dw_die_ref die; |
4600 | enum dwarf_attribute attr_kind; | |
4601 | unsigned targ_fde; | |
3f76745e | 4602 | { |
b3694847 | 4603 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
b1ccbc24 | 4604 | |
3f76745e JM |
4605 | attr->dw_attr_next = NULL; |
4606 | attr->dw_attr = attr_kind; | |
4607 | attr->dw_attr_val.val_class = dw_val_class_fde_ref; | |
4608 | attr->dw_attr_val.v.val_fde_index = targ_fde; | |
4609 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4610 | } |
71dfc51f | 4611 | |
3f76745e | 4612 | /* Add a location description attribute value to a DIE. */ |
71dfc51f | 4613 | |
3f76745e JM |
4614 | static inline void |
4615 | add_AT_loc (die, attr_kind, loc) | |
b3694847 SS |
4616 | dw_die_ref die; |
4617 | enum dwarf_attribute attr_kind; | |
4618 | dw_loc_descr_ref loc; | |
3f76745e | 4619 | { |
b3694847 | 4620 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4621 | |
3f76745e JM |
4622 | attr->dw_attr_next = NULL; |
4623 | attr->dw_attr = attr_kind; | |
4624 | attr->dw_attr_val.val_class = dw_val_class_loc; | |
4625 | attr->dw_attr_val.v.val_loc = loc; | |
4626 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4627 | } |
4628 | ||
a96c67ec JM |
4629 | static inline dw_loc_descr_ref |
4630 | AT_loc (a) | |
b3694847 | 4631 | dw_attr_ref a; |
a96c67ec JM |
4632 | { |
4633 | if (a && AT_class (a) == dw_val_class_loc) | |
4634 | return a->dw_attr_val.v.val_loc; | |
4635 | ||
40e8cc95 | 4636 | abort (); |
a96c67ec JM |
4637 | } |
4638 | ||
63e46568 DB |
4639 | static inline void |
4640 | add_AT_loc_list (die, attr_kind, loc_list) | |
b3694847 SS |
4641 | dw_die_ref die; |
4642 | enum dwarf_attribute attr_kind; | |
4643 | dw_loc_list_ref loc_list; | |
63e46568 | 4644 | { |
b3694847 | 4645 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
63e46568 DB |
4646 | |
4647 | attr->dw_attr_next = NULL; | |
4648 | attr->dw_attr = attr_kind; | |
4649 | attr->dw_attr_val.val_class = dw_val_class_loc_list; | |
4650 | attr->dw_attr_val.v.val_loc_list = loc_list; | |
4651 | add_dwarf_attr (die, attr); | |
4652 | have_location_lists = 1; | |
4653 | } | |
4654 | ||
63e46568 DB |
4655 | static inline dw_loc_list_ref |
4656 | AT_loc_list (a) | |
b3694847 | 4657 | dw_attr_ref a; |
63e46568 DB |
4658 | { |
4659 | if (a && AT_class (a) == dw_val_class_loc_list) | |
4660 | return a->dw_attr_val.v.val_loc_list; | |
4661 | ||
4662 | abort (); | |
4663 | } | |
4664 | ||
3f76745e | 4665 | /* Add an address constant attribute value to a DIE. */ |
71dfc51f | 4666 | |
3f76745e JM |
4667 | static inline void |
4668 | add_AT_addr (die, attr_kind, addr) | |
b3694847 SS |
4669 | dw_die_ref die; |
4670 | enum dwarf_attribute attr_kind; | |
1865dbb5 | 4671 | rtx addr; |
a3f97cbb | 4672 | { |
b3694847 | 4673 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4674 | |
3f76745e JM |
4675 | attr->dw_attr_next = NULL; |
4676 | attr->dw_attr = attr_kind; | |
4677 | attr->dw_attr_val.val_class = dw_val_class_addr; | |
4678 | attr->dw_attr_val.v.val_addr = addr; | |
4679 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4680 | } |
4681 | ||
1865dbb5 | 4682 | static inline rtx |
a96c67ec | 4683 | AT_addr (a) |
b3694847 | 4684 | dw_attr_ref a; |
a96c67ec JM |
4685 | { |
4686 | if (a && AT_class (a) == dw_val_class_addr) | |
4687 | return a->dw_attr_val.v.val_addr; | |
4688 | ||
40e8cc95 | 4689 | abort (); |
a96c67ec JM |
4690 | } |
4691 | ||
3f76745e | 4692 | /* Add a label identifier attribute value to a DIE. */ |
71dfc51f | 4693 | |
3f76745e JM |
4694 | static inline void |
4695 | add_AT_lbl_id (die, attr_kind, lbl_id) | |
b3694847 SS |
4696 | dw_die_ref die; |
4697 | enum dwarf_attribute attr_kind; | |
4698 | const char *lbl_id; | |
a3f97cbb | 4699 | { |
b3694847 | 4700 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4701 | |
3f76745e JM |
4702 | attr->dw_attr_next = NULL; |
4703 | attr->dw_attr = attr_kind; | |
4704 | attr->dw_attr_val.val_class = dw_val_class_lbl_id; | |
4705 | attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); | |
4706 | add_dwarf_attr (die, attr); | |
4707 | } | |
71dfc51f | 4708 | |
3f76745e JM |
4709 | /* Add a section offset attribute value to a DIE. */ |
4710 | ||
4711 | static inline void | |
8b790721 | 4712 | add_AT_lbl_offset (die, attr_kind, label) |
b3694847 SS |
4713 | dw_die_ref die; |
4714 | enum dwarf_attribute attr_kind; | |
4715 | const char *label; | |
3f76745e | 4716 | { |
b3694847 | 4717 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4718 | |
3f76745e JM |
4719 | attr->dw_attr_next = NULL; |
4720 | attr->dw_attr = attr_kind; | |
8b790721 | 4721 | attr->dw_attr_val.val_class = dw_val_class_lbl_offset; |
a96c67ec | 4722 | attr->dw_attr_val.v.val_lbl_id = xstrdup (label); |
3f76745e | 4723 | add_dwarf_attr (die, attr); |
a3f97cbb JW |
4724 | } |
4725 | ||
a20612aa RH |
4726 | /* Add an offset attribute value to a DIE. */ |
4727 | ||
2bee6045 | 4728 | static inline void |
a20612aa | 4729 | add_AT_offset (die, attr_kind, offset) |
b3694847 SS |
4730 | dw_die_ref die; |
4731 | enum dwarf_attribute attr_kind; | |
4732 | unsigned long offset; | |
a20612aa | 4733 | { |
b3694847 | 4734 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
a20612aa RH |
4735 | |
4736 | attr->dw_attr_next = NULL; | |
4737 | attr->dw_attr = attr_kind; | |
4738 | attr->dw_attr_val.val_class = dw_val_class_offset; | |
4739 | attr->dw_attr_val.v.val_offset = offset; | |
4740 | add_dwarf_attr (die, attr); | |
4741 | } | |
4742 | ||
2bee6045 JJ |
4743 | /* Add an range_list attribute value to a DIE. */ |
4744 | ||
4745 | static void | |
4746 | add_AT_range_list (die, attr_kind, offset) | |
4747 | dw_die_ref die; | |
4748 | enum dwarf_attribute attr_kind; | |
4749 | unsigned long offset; | |
4750 | { | |
4751 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
4752 | ||
4753 | attr->dw_attr_next = NULL; | |
4754 | attr->dw_attr = attr_kind; | |
4755 | attr->dw_attr_val.val_class = dw_val_class_range_list; | |
4756 | attr->dw_attr_val.v.val_offset = offset; | |
4757 | add_dwarf_attr (die, attr); | |
4758 | } | |
4759 | ||
a96c67ec JM |
4760 | static inline const char * |
4761 | AT_lbl (a) | |
b3694847 | 4762 | dw_attr_ref a; |
a3f97cbb | 4763 | { |
a96c67ec JM |
4764 | if (a && (AT_class (a) == dw_val_class_lbl_id |
4765 | || AT_class (a) == dw_val_class_lbl_offset)) | |
4766 | return a->dw_attr_val.v.val_lbl_id; | |
71dfc51f | 4767 | |
40e8cc95 | 4768 | abort (); |
a3f97cbb JW |
4769 | } |
4770 | ||
3f76745e | 4771 | /* Get the attribute of type attr_kind. */ |
71dfc51f | 4772 | |
3f76745e JM |
4773 | static inline dw_attr_ref |
4774 | get_AT (die, attr_kind) | |
b3694847 SS |
4775 | dw_die_ref die; |
4776 | enum dwarf_attribute attr_kind; | |
f37230f0 | 4777 | { |
b3694847 SS |
4778 | dw_attr_ref a; |
4779 | dw_die_ref spec = NULL; | |
556273e0 | 4780 | |
3f76745e JM |
4781 | if (die != NULL) |
4782 | { | |
4783 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
2ad9852d RK |
4784 | if (a->dw_attr == attr_kind) |
4785 | return a; | |
4786 | else if (a->dw_attr == DW_AT_specification | |
4787 | || a->dw_attr == DW_AT_abstract_origin) | |
4788 | spec = AT_ref (a); | |
71dfc51f | 4789 | |
3f76745e JM |
4790 | if (spec) |
4791 | return get_AT (spec, attr_kind); | |
4792 | } | |
4793 | ||
4794 | return NULL; | |
f37230f0 JM |
4795 | } |
4796 | ||
2ad9852d RK |
4797 | /* Return the "low pc" attribute value, typically associated with a subprogram |
4798 | DIE. Return null if the "low pc" attribute is either not present, or if it | |
4799 | cannot be represented as an assembler label identifier. */ | |
71dfc51f | 4800 | |
a96c67ec | 4801 | static inline const char * |
3f76745e | 4802 | get_AT_low_pc (die) |
b3694847 | 4803 | dw_die_ref die; |
7e23cb16 | 4804 | { |
b3694847 | 4805 | dw_attr_ref a = get_AT (die, DW_AT_low_pc); |
2ad9852d | 4806 | |
40e8cc95 | 4807 | return a ? AT_lbl (a) : NULL; |
7e23cb16 JM |
4808 | } |
4809 | ||
2ad9852d RK |
4810 | /* Return the "high pc" attribute value, typically associated with a subprogram |
4811 | DIE. Return null if the "high pc" attribute is either not present, or if it | |
4812 | cannot be represented as an assembler label identifier. */ | |
71dfc51f | 4813 | |
a96c67ec | 4814 | static inline const char * |
3f76745e | 4815 | get_AT_hi_pc (die) |
b3694847 | 4816 | dw_die_ref die; |
a3f97cbb | 4817 | { |
b3694847 | 4818 | dw_attr_ref a = get_AT (die, DW_AT_high_pc); |
2ad9852d | 4819 | |
40e8cc95 | 4820 | return a ? AT_lbl (a) : NULL; |
3f76745e JM |
4821 | } |
4822 | ||
4823 | /* Return the value of the string attribute designated by ATTR_KIND, or | |
4824 | NULL if it is not present. */ | |
71dfc51f | 4825 | |
a96c67ec | 4826 | static inline const char * |
3f76745e | 4827 | get_AT_string (die, attr_kind) |
b3694847 SS |
4828 | dw_die_ref die; |
4829 | enum dwarf_attribute attr_kind; | |
3f76745e | 4830 | { |
b3694847 | 4831 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4832 | |
40e8cc95 | 4833 | return a ? AT_string (a) : NULL; |
a3f97cbb JW |
4834 | } |
4835 | ||
3f76745e JM |
4836 | /* Return the value of the flag attribute designated by ATTR_KIND, or -1 |
4837 | if it is not present. */ | |
71dfc51f | 4838 | |
3f76745e JM |
4839 | static inline int |
4840 | get_AT_flag (die, attr_kind) | |
b3694847 SS |
4841 | dw_die_ref die; |
4842 | enum dwarf_attribute attr_kind; | |
a3f97cbb | 4843 | { |
b3694847 | 4844 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4845 | |
40e8cc95 | 4846 | return a ? AT_flag (a) : 0; |
a3f97cbb JW |
4847 | } |
4848 | ||
3f76745e JM |
4849 | /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0 |
4850 | if it is not present. */ | |
71dfc51f | 4851 | |
3f76745e JM |
4852 | static inline unsigned |
4853 | get_AT_unsigned (die, attr_kind) | |
b3694847 SS |
4854 | dw_die_ref die; |
4855 | enum dwarf_attribute attr_kind; | |
a3f97cbb | 4856 | { |
b3694847 | 4857 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4858 | |
40e8cc95 | 4859 | return a ? AT_unsigned (a) : 0; |
a96c67ec | 4860 | } |
71dfc51f | 4861 | |
a96c67ec JM |
4862 | static inline dw_die_ref |
4863 | get_AT_ref (die, attr_kind) | |
4864 | dw_die_ref die; | |
b3694847 | 4865 | enum dwarf_attribute attr_kind; |
a96c67ec | 4866 | { |
b3694847 | 4867 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4868 | |
40e8cc95 | 4869 | return a ? AT_ref (a) : NULL; |
3f76745e | 4870 | } |
71dfc51f | 4871 | |
3f76745e JM |
4872 | static inline int |
4873 | is_c_family () | |
4874 | { | |
b3694847 | 4875 | unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
71dfc51f | 4876 | |
3f76745e JM |
4877 | return (lang == DW_LANG_C || lang == DW_LANG_C89 |
4878 | || lang == DW_LANG_C_plus_plus); | |
556273e0 | 4879 | } |
71dfc51f | 4880 | |
1d3d6b1e JM |
4881 | static inline int |
4882 | is_cxx () | |
4883 | { | |
4884 | return (get_AT_unsigned (comp_unit_die, DW_AT_language) | |
4885 | == DW_LANG_C_plus_plus); | |
4886 | } | |
4887 | ||
3f76745e JM |
4888 | static inline int |
4889 | is_fortran () | |
4890 | { | |
b3694847 | 4891 | unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
71dfc51f | 4892 | |
3f76745e | 4893 | return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90); |
556273e0 | 4894 | } |
71dfc51f | 4895 | |
28985b81 AG |
4896 | static inline int |
4897 | is_java () | |
4898 | { | |
b3694847 | 4899 | unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
28985b81 AG |
4900 | |
4901 | return (lang == DW_LANG_Java); | |
4902 | } | |
4903 | ||
10a11b75 | 4904 | /* Free up the memory used by A. */ |
71dfc51f | 4905 | |
c6991660 | 4906 | static inline void free_AT PARAMS ((dw_attr_ref)); |
3f76745e | 4907 | static inline void |
10a11b75 JM |
4908 | free_AT (a) |
4909 | dw_attr_ref a; | |
4910 | { | |
4911 | switch (AT_class (a)) | |
4912 | { | |
10a11b75 | 4913 | case dw_val_class_str: |
9eb4015a JJ |
4914 | if (a->dw_attr_val.v.val_str->refcount) |
4915 | a->dw_attr_val.v.val_str->refcount--; | |
4916 | break; | |
4917 | ||
10a11b75 JM |
4918 | case dw_val_class_lbl_id: |
4919 | case dw_val_class_lbl_offset: | |
9eb4015a | 4920 | free (a->dw_attr_val.v.val_lbl_id); |
10a11b75 JM |
4921 | break; |
4922 | ||
3724ec07 WC |
4923 | case dw_val_class_float: |
4924 | free (a->dw_attr_val.v.val_float.array); | |
4925 | break; | |
0b34cf1e | 4926 | |
10a11b75 JM |
4927 | default: |
4928 | break; | |
4929 | } | |
4930 | ||
4931 | free (a); | |
556273e0 | 4932 | } |
10a11b75 JM |
4933 | |
4934 | /* Remove the specified attribute if present. */ | |
4935 | ||
4936 | static void | |
3f76745e | 4937 | remove_AT (die, attr_kind) |
b3694847 SS |
4938 | dw_die_ref die; |
4939 | enum dwarf_attribute attr_kind; | |
3f76745e | 4940 | { |
b3694847 SS |
4941 | dw_attr_ref *p; |
4942 | dw_attr_ref removed = NULL; | |
a3f97cbb | 4943 | |
3f76745e JM |
4944 | if (die != NULL) |
4945 | { | |
a96c67ec JM |
4946 | for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next)) |
4947 | if ((*p)->dw_attr == attr_kind) | |
4948 | { | |
4949 | removed = *p; | |
4950 | *p = (*p)->dw_attr_next; | |
4951 | break; | |
4952 | } | |
71dfc51f | 4953 | |
a96c67ec | 4954 | if (removed != 0) |
10a11b75 JM |
4955 | free_AT (removed); |
4956 | } | |
4957 | } | |
71dfc51f | 4958 | |
10a11b75 | 4959 | /* Free up the memory used by DIE. */ |
71dfc51f | 4960 | |
10a11b75 JM |
4961 | static inline void |
4962 | free_die (die) | |
4963 | dw_die_ref die; | |
4964 | { | |
4965 | remove_children (die); | |
4966 | free (die); | |
3f76745e | 4967 | } |
71dfc51f | 4968 | |
3f76745e | 4969 | /* Discard the children of this DIE. */ |
71dfc51f | 4970 | |
10a11b75 | 4971 | static void |
3f76745e | 4972 | remove_children (die) |
b3694847 | 4973 | dw_die_ref die; |
3f76745e | 4974 | { |
b3694847 | 4975 | dw_die_ref child_die = die->die_child; |
3f76745e JM |
4976 | |
4977 | die->die_child = NULL; | |
3f76745e JM |
4978 | |
4979 | while (child_die != NULL) | |
a3f97cbb | 4980 | { |
b3694847 SS |
4981 | dw_die_ref tmp_die = child_die; |
4982 | dw_attr_ref a; | |
71dfc51f | 4983 | |
3f76745e | 4984 | child_die = child_die->die_sib; |
556273e0 KH |
4985 | |
4986 | for (a = tmp_die->die_attr; a != NULL;) | |
a3f97cbb | 4987 | { |
b3694847 | 4988 | dw_attr_ref tmp_a = a; |
71dfc51f | 4989 | |
3f76745e | 4990 | a = a->dw_attr_next; |
10a11b75 | 4991 | free_AT (tmp_a); |
a3f97cbb | 4992 | } |
71dfc51f | 4993 | |
10a11b75 | 4994 | free_die (tmp_die); |
3f76745e JM |
4995 | } |
4996 | } | |
71dfc51f | 4997 | |
a96c67ec | 4998 | /* Add a child DIE below its parent. We build the lists up in reverse |
881c6935 | 4999 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f | 5000 | |
3f76745e JM |
5001 | static inline void |
5002 | add_child_die (die, child_die) | |
b3694847 SS |
5003 | dw_die_ref die; |
5004 | dw_die_ref child_die; | |
3f76745e JM |
5005 | { |
5006 | if (die != NULL && child_die != NULL) | |
e90b62db | 5007 | { |
3a88cbd1 JL |
5008 | if (die == child_die) |
5009 | abort (); | |
2ad9852d | 5010 | |
3f76745e | 5011 | child_die->die_parent = die; |
a96c67ec JM |
5012 | child_die->die_sib = die->die_child; |
5013 | die->die_child = child_die; | |
3f76745e JM |
5014 | } |
5015 | } | |
5016 | ||
2081603c JM |
5017 | /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT |
5018 | is the specification, to the front of PARENT's list of children. */ | |
10a11b75 JM |
5019 | |
5020 | static void | |
5021 | splice_child_die (parent, child) | |
5022 | dw_die_ref parent, child; | |
5023 | { | |
5024 | dw_die_ref *p; | |
5025 | ||
5026 | /* We want the declaration DIE from inside the class, not the | |
5027 | specification DIE at toplevel. */ | |
5028 | if (child->die_parent != parent) | |
2081603c JM |
5029 | { |
5030 | dw_die_ref tmp = get_AT_ref (child, DW_AT_specification); | |
2ad9852d | 5031 | |
2081603c JM |
5032 | if (tmp) |
5033 | child = tmp; | |
5034 | } | |
10a11b75 | 5035 | |
2081603c JM |
5036 | if (child->die_parent != parent |
5037 | && child->die_parent != get_AT_ref (parent, DW_AT_specification)) | |
10a11b75 JM |
5038 | abort (); |
5039 | ||
5de0e8d4 | 5040 | for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib)) |
10a11b75 JM |
5041 | if (*p == child) |
5042 | { | |
5043 | *p = child->die_sib; | |
5044 | break; | |
5045 | } | |
5046 | ||
5047 | child->die_sib = parent->die_child; | |
5048 | parent->die_child = child; | |
5049 | } | |
5050 | ||
3f76745e JM |
5051 | /* Return a pointer to a newly created DIE node. */ |
5052 | ||
5053 | static inline dw_die_ref | |
54ba1f0d | 5054 | new_die (tag_value, parent_die, t) |
b3694847 SS |
5055 | enum dwarf_tag tag_value; |
5056 | dw_die_ref parent_die; | |
54ba1f0d | 5057 | tree t; |
3f76745e | 5058 | { |
b3694847 | 5059 | dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node)); |
3f76745e JM |
5060 | |
5061 | die->die_tag = tag_value; | |
3f76745e JM |
5062 | |
5063 | if (parent_die != NULL) | |
5064 | add_child_die (parent_die, die); | |
5065 | else | |
ef76d03b JW |
5066 | { |
5067 | limbo_die_node *limbo_node; | |
5068 | ||
5069 | limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node)); | |
5070 | limbo_node->die = die; | |
54ba1f0d | 5071 | limbo_node->created_for = t; |
ef76d03b JW |
5072 | limbo_node->next = limbo_die_list; |
5073 | limbo_die_list = limbo_node; | |
5074 | } | |
71dfc51f | 5075 | |
3f76745e JM |
5076 | return die; |
5077 | } | |
71dfc51f | 5078 | |
3f76745e | 5079 | /* Return the DIE associated with the given type specifier. */ |
71dfc51f | 5080 | |
3f76745e JM |
5081 | static inline dw_die_ref |
5082 | lookup_type_die (type) | |
b3694847 | 5083 | tree type; |
3f76745e | 5084 | { |
4061f623 BS |
5085 | if (TREE_CODE (type) == VECTOR_TYPE) |
5086 | type = TYPE_DEBUG_REPRESENTATION_TYPE (type); | |
2ad9852d | 5087 | |
3f76745e JM |
5088 | return (dw_die_ref) TYPE_SYMTAB_POINTER (type); |
5089 | } | |
e90b62db | 5090 | |
3f76745e | 5091 | /* Equate a DIE to a given type specifier. */ |
71dfc51f | 5092 | |
10a11b75 | 5093 | static inline void |
3f76745e | 5094 | equate_type_number_to_die (type, type_die) |
b3694847 SS |
5095 | tree type; |
5096 | dw_die_ref type_die; | |
3f76745e JM |
5097 | { |
5098 | TYPE_SYMTAB_POINTER (type) = (char *) type_die; | |
5099 | } | |
71dfc51f | 5100 | |
3f76745e | 5101 | /* Return the DIE associated with a given declaration. */ |
71dfc51f | 5102 | |
3f76745e JM |
5103 | static inline dw_die_ref |
5104 | lookup_decl_die (decl) | |
b3694847 | 5105 | tree decl; |
3f76745e | 5106 | { |
b3694847 | 5107 | unsigned decl_id = DECL_UID (decl); |
3f76745e | 5108 | |
2ad9852d | 5109 | return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL); |
a3f97cbb JW |
5110 | } |
5111 | ||
3f76745e | 5112 | /* Equate a DIE to a particular declaration. */ |
71dfc51f | 5113 | |
3f76745e JM |
5114 | static void |
5115 | equate_decl_number_to_die (decl, decl_die) | |
b3694847 SS |
5116 | tree decl; |
5117 | dw_die_ref decl_die; | |
a3f97cbb | 5118 | { |
aea9695c RK |
5119 | unsigned int decl_id = DECL_UID (decl); |
5120 | unsigned int num_allocated; | |
d291dd49 | 5121 | |
3f76745e | 5122 | if (decl_id >= decl_die_table_allocated) |
a3f97cbb | 5123 | { |
3f76745e JM |
5124 | num_allocated |
5125 | = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1) | |
5126 | / DECL_DIE_TABLE_INCREMENT) | |
5127 | * DECL_DIE_TABLE_INCREMENT; | |
5128 | ||
5129 | decl_die_table | |
5130 | = (dw_die_ref *) xrealloc (decl_die_table, | |
5131 | sizeof (dw_die_ref) * num_allocated); | |
5132 | ||
961192e1 | 5133 | memset ((char *) &decl_die_table[decl_die_table_allocated], 0, |
3f76745e JM |
5134 | (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref)); |
5135 | decl_die_table_allocated = num_allocated; | |
a3f97cbb | 5136 | } |
71dfc51f | 5137 | |
3f76745e JM |
5138 | if (decl_id >= decl_die_table_in_use) |
5139 | decl_die_table_in_use = (decl_id + 1); | |
5140 | ||
5141 | decl_die_table[decl_id] = decl_die; | |
a3f97cbb | 5142 | } |
3f76745e JM |
5143 | \f |
5144 | /* Keep track of the number of spaces used to indent the | |
5145 | output of the debugging routines that print the structure of | |
5146 | the DIE internal representation. */ | |
5147 | static int print_indent; | |
71dfc51f | 5148 | |
3f76745e JM |
5149 | /* Indent the line the number of spaces given by print_indent. */ |
5150 | ||
5151 | static inline void | |
5152 | print_spaces (outfile) | |
5153 | FILE *outfile; | |
5154 | { | |
5155 | fprintf (outfile, "%*s", print_indent, ""); | |
a3f97cbb JW |
5156 | } |
5157 | ||
956d6950 | 5158 | /* Print the information associated with a given DIE, and its children. |
3f76745e | 5159 | This routine is a debugging aid only. */ |
71dfc51f | 5160 | |
a3f97cbb | 5161 | static void |
3f76745e JM |
5162 | print_die (die, outfile) |
5163 | dw_die_ref die; | |
5164 | FILE *outfile; | |
a3f97cbb | 5165 | { |
b3694847 SS |
5166 | dw_attr_ref a; |
5167 | dw_die_ref c; | |
71dfc51f | 5168 | |
3f76745e | 5169 | print_spaces (outfile); |
2d8b0f3a | 5170 | fprintf (outfile, "DIE %4lu: %s\n", |
3f76745e JM |
5171 | die->die_offset, dwarf_tag_name (die->die_tag)); |
5172 | print_spaces (outfile); | |
2d8b0f3a JL |
5173 | fprintf (outfile, " abbrev id: %lu", die->die_abbrev); |
5174 | fprintf (outfile, " offset: %lu\n", die->die_offset); | |
3f76745e JM |
5175 | |
5176 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
a3f97cbb | 5177 | { |
3f76745e JM |
5178 | print_spaces (outfile); |
5179 | fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr)); | |
5180 | ||
a96c67ec | 5181 | switch (AT_class (a)) |
3f76745e JM |
5182 | { |
5183 | case dw_val_class_addr: | |
5184 | fprintf (outfile, "address"); | |
5185 | break; | |
a20612aa RH |
5186 | case dw_val_class_offset: |
5187 | fprintf (outfile, "offset"); | |
5188 | break; | |
3f76745e JM |
5189 | case dw_val_class_loc: |
5190 | fprintf (outfile, "location descriptor"); | |
5191 | break; | |
63e46568 | 5192 | case dw_val_class_loc_list: |
a20612aa RH |
5193 | fprintf (outfile, "location list -> label:%s", |
5194 | AT_loc_list (a)->ll_symbol); | |
63e46568 | 5195 | break; |
2bee6045 JJ |
5196 | case dw_val_class_range_list: |
5197 | fprintf (outfile, "range list"); | |
5198 | break; | |
3f76745e | 5199 | case dw_val_class_const: |
a96c67ec | 5200 | fprintf (outfile, "%ld", AT_int (a)); |
3f76745e JM |
5201 | break; |
5202 | case dw_val_class_unsigned_const: | |
a96c67ec | 5203 | fprintf (outfile, "%lu", AT_unsigned (a)); |
3f76745e JM |
5204 | break; |
5205 | case dw_val_class_long_long: | |
2d8b0f3a | 5206 | fprintf (outfile, "constant (%lu,%lu)", |
556273e0 KH |
5207 | a->dw_attr_val.v.val_long_long.hi, |
5208 | a->dw_attr_val.v.val_long_long.low); | |
3f76745e JM |
5209 | break; |
5210 | case dw_val_class_float: | |
5211 | fprintf (outfile, "floating-point constant"); | |
5212 | break; | |
5213 | case dw_val_class_flag: | |
a96c67ec | 5214 | fprintf (outfile, "%u", AT_flag (a)); |
3f76745e JM |
5215 | break; |
5216 | case dw_val_class_die_ref: | |
a96c67ec | 5217 | if (AT_ref (a) != NULL) |
881c6935 | 5218 | { |
1bfb5f8f | 5219 | if (AT_ref (a)->die_symbol) |
881c6935 JM |
5220 | fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol); |
5221 | else | |
5222 | fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset); | |
5223 | } | |
3f76745e JM |
5224 | else |
5225 | fprintf (outfile, "die -> <null>"); | |
5226 | break; | |
5227 | case dw_val_class_lbl_id: | |
8b790721 | 5228 | case dw_val_class_lbl_offset: |
a96c67ec | 5229 | fprintf (outfile, "label: %s", AT_lbl (a)); |
3f76745e | 5230 | break; |
3f76745e | 5231 | case dw_val_class_str: |
a96c67ec JM |
5232 | if (AT_string (a) != NULL) |
5233 | fprintf (outfile, "\"%s\"", AT_string (a)); | |
3f76745e JM |
5234 | else |
5235 | fprintf (outfile, "<null>"); | |
5236 | break; | |
e9a25f70 JL |
5237 | default: |
5238 | break; | |
3f76745e JM |
5239 | } |
5240 | ||
5241 | fprintf (outfile, "\n"); | |
5242 | } | |
5243 | ||
5244 | if (die->die_child != NULL) | |
5245 | { | |
5246 | print_indent += 4; | |
5247 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5248 | print_die (c, outfile); | |
71dfc51f | 5249 | |
3f76745e | 5250 | print_indent -= 4; |
a3f97cbb | 5251 | } |
881c6935 JM |
5252 | if (print_indent == 0) |
5253 | fprintf (outfile, "\n"); | |
a3f97cbb JW |
5254 | } |
5255 | ||
3f76745e JM |
5256 | /* Print the contents of the source code line number correspondence table. |
5257 | This routine is a debugging aid only. */ | |
71dfc51f | 5258 | |
3f76745e JM |
5259 | static void |
5260 | print_dwarf_line_table (outfile) | |
5261 | FILE *outfile; | |
a3f97cbb | 5262 | { |
b3694847 SS |
5263 | unsigned i; |
5264 | dw_line_info_ref line_info; | |
3f76745e JM |
5265 | |
5266 | fprintf (outfile, "\n\nDWARF source line information\n"); | |
2ad9852d | 5267 | for (i = 1; i < line_info_table_in_use; i++) |
a3f97cbb | 5268 | { |
3f76745e JM |
5269 | line_info = &line_info_table[i]; |
5270 | fprintf (outfile, "%5d: ", i); | |
981975b6 | 5271 | fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]); |
2d8b0f3a | 5272 | fprintf (outfile, "%6ld", line_info->dw_line_num); |
3f76745e | 5273 | fprintf (outfile, "\n"); |
a3f97cbb | 5274 | } |
3f76745e JM |
5275 | |
5276 | fprintf (outfile, "\n\n"); | |
f37230f0 JM |
5277 | } |
5278 | ||
3f76745e JM |
5279 | /* Print the information collected for a given DIE. */ |
5280 | ||
5281 | void | |
5282 | debug_dwarf_die (die) | |
5283 | dw_die_ref die; | |
5284 | { | |
5285 | print_die (die, stderr); | |
5286 | } | |
5287 | ||
5288 | /* Print all DWARF information collected for the compilation unit. | |
5289 | This routine is a debugging aid only. */ | |
5290 | ||
5291 | void | |
5292 | debug_dwarf () | |
5293 | { | |
5294 | print_indent = 0; | |
5295 | print_die (comp_unit_die, stderr); | |
b2244e22 JW |
5296 | if (! DWARF2_ASM_LINE_DEBUG_INFO) |
5297 | print_dwarf_line_table (stderr); | |
3f76745e JM |
5298 | } |
5299 | \f | |
a96c67ec JM |
5300 | /* We build up the lists of children and attributes by pushing new ones |
5301 | onto the beginning of the list. Reverse the lists for DIE so that | |
5302 | they are in order of addition. */ | |
71dfc51f | 5303 | |
f37230f0 | 5304 | static void |
a96c67ec | 5305 | reverse_die_lists (die) |
b3694847 | 5306 | dw_die_ref die; |
f37230f0 | 5307 | { |
b3694847 SS |
5308 | dw_die_ref c, cp, cn; |
5309 | dw_attr_ref a, ap, an; | |
71dfc51f | 5310 | |
a96c67ec | 5311 | for (a = die->die_attr, ap = 0; a; a = an) |
7d9d8943 AM |
5312 | { |
5313 | an = a->dw_attr_next; | |
5314 | a->dw_attr_next = ap; | |
5315 | ap = a; | |
a3f97cbb | 5316 | } |
2ad9852d | 5317 | |
7d9d8943 | 5318 | die->die_attr = ap; |
3f76745e | 5319 | |
7d9d8943 AM |
5320 | for (c = die->die_child, cp = 0; c; c = cn) |
5321 | { | |
5322 | cn = c->die_sib; | |
5323 | c->die_sib = cp; | |
5324 | cp = c; | |
5325 | } | |
2ad9852d | 5326 | |
7d9d8943 | 5327 | die->die_child = cp; |
a3f97cbb JW |
5328 | } |
5329 | ||
2ad9852d RK |
5330 | /* reverse_die_lists only reverses the single die you pass it. Since we used to |
5331 | reverse all dies in add_sibling_attributes, which runs through all the dies, | |
5332 | it would reverse all the dies. Now, however, since we don't call | |
5333 | reverse_die_lists in add_sibling_attributes, we need a routine to | |
5334 | recursively reverse all the dies. This is that routine. */ | |
71dfc51f | 5335 | |
7d9d8943 | 5336 | static void |
881c6935 | 5337 | reverse_all_dies (die) |
b3694847 | 5338 | dw_die_ref die; |
a3f97cbb | 5339 | { |
b3694847 | 5340 | dw_die_ref c; |
71dfc51f | 5341 | |
7d9d8943 | 5342 | reverse_die_lists (die); |
3f76745e | 5343 | |
881c6935 JM |
5344 | for (c = die->die_child; c; c = c->die_sib) |
5345 | reverse_all_dies (c); | |
5346 | } | |
5347 | ||
2ad9852d RK |
5348 | /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU |
5349 | for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL | |
5350 | DIE that marks the start of the DIEs for this include file. */ | |
881c6935 JM |
5351 | |
5352 | static dw_die_ref | |
5353 | push_new_compile_unit (old_unit, bincl_die) | |
5354 | dw_die_ref old_unit, bincl_die; | |
5355 | { | |
5356 | const char *filename = get_AT_string (bincl_die, DW_AT_name); | |
5357 | dw_die_ref new_unit = gen_compile_unit_die (filename); | |
2ad9852d | 5358 | |
881c6935 JM |
5359 | new_unit->die_sib = old_unit; |
5360 | return new_unit; | |
5361 | } | |
5362 | ||
5363 | /* Close an include-file CU and reopen the enclosing one. */ | |
5364 | ||
5365 | static dw_die_ref | |
5366 | pop_compile_unit (old_unit) | |
5367 | dw_die_ref old_unit; | |
5368 | { | |
5369 | dw_die_ref new_unit = old_unit->die_sib; | |
2ad9852d | 5370 | |
881c6935 JM |
5371 | old_unit->die_sib = NULL; |
5372 | return new_unit; | |
5373 | } | |
5374 | ||
2ad9852d RK |
5375 | #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx) |
5376 | #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx) | |
881c6935 JM |
5377 | |
5378 | /* Calculate the checksum of a location expression. */ | |
5379 | ||
5380 | static inline void | |
5381 | loc_checksum (loc, ctx) | |
5382 | dw_loc_descr_ref loc; | |
5383 | struct md5_ctx *ctx; | |
5384 | { | |
2ad9852d RK |
5385 | CHECKSUM (loc->dw_loc_opc); |
5386 | CHECKSUM (loc->dw_loc_oprnd1); | |
5387 | CHECKSUM (loc->dw_loc_oprnd2); | |
881c6935 JM |
5388 | } |
5389 | ||
5390 | /* Calculate the checksum of an attribute. */ | |
5391 | ||
5392 | static void | |
5393 | attr_checksum (at, ctx) | |
5394 | dw_attr_ref at; | |
5395 | struct md5_ctx *ctx; | |
5396 | { | |
5397 | dw_loc_descr_ref loc; | |
5398 | rtx r; | |
5399 | ||
2ad9852d | 5400 | CHECKSUM (at->dw_attr); |
881c6935 JM |
5401 | |
5402 | /* We don't care about differences in file numbering. */ | |
5f632b5e JM |
5403 | if (at->dw_attr == DW_AT_decl_file |
5404 | /* Or that this was compiled with a different compiler snapshot; if | |
5405 | the output is the same, that's what matters. */ | |
5406 | || at->dw_attr == DW_AT_producer) | |
881c6935 JM |
5407 | return; |
5408 | ||
5409 | switch (AT_class (at)) | |
5410 | { | |
5411 | case dw_val_class_const: | |
2ad9852d | 5412 | CHECKSUM (at->dw_attr_val.v.val_int); |
881c6935 JM |
5413 | break; |
5414 | case dw_val_class_unsigned_const: | |
2ad9852d | 5415 | CHECKSUM (at->dw_attr_val.v.val_unsigned); |
881c6935 JM |
5416 | break; |
5417 | case dw_val_class_long_long: | |
2ad9852d | 5418 | CHECKSUM (at->dw_attr_val.v.val_long_long); |
881c6935 JM |
5419 | break; |
5420 | case dw_val_class_float: | |
2ad9852d | 5421 | CHECKSUM (at->dw_attr_val.v.val_float); |
881c6935 JM |
5422 | break; |
5423 | case dw_val_class_flag: | |
2ad9852d | 5424 | CHECKSUM (at->dw_attr_val.v.val_flag); |
881c6935 | 5425 | break; |
881c6935 | 5426 | case dw_val_class_str: |
2ad9852d | 5427 | CHECKSUM_STRING (AT_string (at)); |
881c6935 | 5428 | break; |
a20612aa | 5429 | |
881c6935 JM |
5430 | case dw_val_class_addr: |
5431 | r = AT_addr (at); | |
5432 | switch (GET_CODE (r)) | |
5433 | { | |
5434 | case SYMBOL_REF: | |
2ad9852d | 5435 | CHECKSUM_STRING (XSTR (r, 0)); |
881c6935 JM |
5436 | break; |
5437 | ||
5438 | default: | |
5439 | abort (); | |
5440 | } | |
5441 | break; | |
5442 | ||
a20612aa | 5443 | case dw_val_class_offset: |
2ad9852d | 5444 | CHECKSUM (at->dw_attr_val.v.val_offset); |
a20612aa RH |
5445 | break; |
5446 | ||
881c6935 JM |
5447 | case dw_val_class_loc: |
5448 | for (loc = AT_loc (at); loc; loc = loc->dw_loc_next) | |
5449 | loc_checksum (loc, ctx); | |
5450 | break; | |
5451 | ||
5452 | case dw_val_class_die_ref: | |
5453 | if (AT_ref (at)->die_offset) | |
2ad9852d | 5454 | CHECKSUM (AT_ref (at)->die_offset); |
881c6935 JM |
5455 | /* FIXME else use target die name or something. */ |
5456 | ||
5457 | case dw_val_class_fde_ref: | |
5458 | case dw_val_class_lbl_id: | |
5459 | case dw_val_class_lbl_offset: | |
a20612aa | 5460 | break; |
881c6935 JM |
5461 | |
5462 | default: | |
5463 | break; | |
5464 | } | |
5465 | } | |
5466 | ||
5467 | /* Calculate the checksum of a DIE. */ | |
5468 | ||
5469 | static void | |
5470 | die_checksum (die, ctx) | |
5471 | dw_die_ref die; | |
5472 | struct md5_ctx *ctx; | |
5473 | { | |
5474 | dw_die_ref c; | |
5475 | dw_attr_ref a; | |
5476 | ||
2ad9852d | 5477 | CHECKSUM (die->die_tag); |
881c6935 JM |
5478 | |
5479 | for (a = die->die_attr; a; a = a->dw_attr_next) | |
5480 | attr_checksum (a, ctx); | |
5481 | ||
5482 | for (c = die->die_child; c; c = c->die_sib) | |
5483 | die_checksum (c, ctx); | |
5484 | } | |
5485 | ||
2ad9852d RK |
5486 | #undef CHECKSUM |
5487 | #undef CHECKSUM_STRING | |
881c6935 JM |
5488 | |
5489 | /* The prefix to attach to symbols on DIEs in the current comdat debug | |
5490 | info section. */ | |
5491 | static char *comdat_symbol_id; | |
5492 | ||
5493 | /* The index of the current symbol within the current comdat CU. */ | |
5494 | static unsigned int comdat_symbol_number; | |
5495 | ||
5496 | /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its | |
5497 | children, and set comdat_symbol_id accordingly. */ | |
5498 | ||
5499 | static void | |
5500 | compute_section_prefix (unit_die) | |
5501 | dw_die_ref unit_die; | |
5502 | { | |
f11c3043 RK |
5503 | const char *base = lbasename (get_AT_string (unit_die, DW_AT_name)); |
5504 | char *name = (char *) alloca (strlen (base) + 64); | |
5505 | char *p; | |
881c6935 JM |
5506 | int i; |
5507 | unsigned char checksum[16]; | |
5508 | struct md5_ctx ctx; | |
5509 | ||
f11c3043 RK |
5510 | /* Compute the checksum of the DIE, then append part of it as hex digits to |
5511 | the name filename of the unit. */ | |
5512 | ||
881c6935 JM |
5513 | md5_init_ctx (&ctx); |
5514 | die_checksum (unit_die, &ctx); | |
5515 | md5_finish_ctx (&ctx, checksum); | |
5516 | ||
0023400b | 5517 | sprintf (name, "%s.", base); |
881c6935 JM |
5518 | clean_symbol_name (name); |
5519 | ||
2ad9852d RK |
5520 | p = name + strlen (name); |
5521 | for (i = 0; i < 4; i++) | |
5522 | { | |
5523 | sprintf (p, "%.2x", checksum[i]); | |
5524 | p += 2; | |
5525 | } | |
881c6935 JM |
5526 | |
5527 | comdat_symbol_id = unit_die->die_symbol = xstrdup (name); | |
5528 | comdat_symbol_number = 0; | |
5529 | } | |
5530 | ||
f11c3043 | 5531 | /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */ |
881c6935 JM |
5532 | |
5533 | static int | |
5534 | is_type_die (die) | |
5535 | dw_die_ref die; | |
5536 | { | |
5537 | switch (die->die_tag) | |
5538 | { | |
5539 | case DW_TAG_array_type: | |
5540 | case DW_TAG_class_type: | |
5541 | case DW_TAG_enumeration_type: | |
5542 | case DW_TAG_pointer_type: | |
5543 | case DW_TAG_reference_type: | |
5544 | case DW_TAG_string_type: | |
5545 | case DW_TAG_structure_type: | |
5546 | case DW_TAG_subroutine_type: | |
5547 | case DW_TAG_union_type: | |
5548 | case DW_TAG_ptr_to_member_type: | |
5549 | case DW_TAG_set_type: | |
5550 | case DW_TAG_subrange_type: | |
5551 | case DW_TAG_base_type: | |
5552 | case DW_TAG_const_type: | |
5553 | case DW_TAG_file_type: | |
5554 | case DW_TAG_packed_type: | |
5555 | case DW_TAG_volatile_type: | |
5556 | return 1; | |
5557 | default: | |
5558 | return 0; | |
5559 | } | |
5560 | } | |
5561 | ||
5562 | /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU. | |
5563 | Basically, we want to choose the bits that are likely to be shared between | |
5564 | compilations (types) and leave out the bits that are specific to individual | |
5565 | compilations (functions). */ | |
5566 | ||
5567 | static int | |
5568 | is_comdat_die (c) | |
5569 | dw_die_ref c; | |
5570 | { | |
2ad9852d RK |
5571 | /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as |
5572 | we do for stabs. The advantage is a greater likelihood of sharing between | |
5573 | objects that don't include headers in the same order (and therefore would | |
5574 | put the base types in a different comdat). jason 8/28/00 */ | |
5575 | ||
881c6935 JM |
5576 | if (c->die_tag == DW_TAG_base_type) |
5577 | return 0; | |
5578 | ||
5579 | if (c->die_tag == DW_TAG_pointer_type | |
5580 | || c->die_tag == DW_TAG_reference_type | |
5581 | || c->die_tag == DW_TAG_const_type | |
5582 | || c->die_tag == DW_TAG_volatile_type) | |
5583 | { | |
5584 | dw_die_ref t = get_AT_ref (c, DW_AT_type); | |
2ad9852d | 5585 | |
881c6935 JM |
5586 | return t ? is_comdat_die (t) : 0; |
5587 | } | |
881c6935 JM |
5588 | |
5589 | return is_type_die (c); | |
5590 | } | |
5591 | ||
5592 | /* Returns 1 iff C is the sort of DIE that might be referred to from another | |
5593 | compilation unit. */ | |
5594 | ||
5595 | static int | |
5596 | is_symbol_die (c) | |
5597 | dw_die_ref c; | |
5598 | { | |
2ad9852d RK |
5599 | return (is_type_die (c) |
5600 | || (get_AT (c, DW_AT_declaration) | |
5601 | && !get_AT (c, DW_AT_specification))); | |
881c6935 JM |
5602 | } |
5603 | ||
5604 | static char * | |
63e46568 | 5605 | gen_internal_sym (prefix) |
173bf5be | 5606 | const char *prefix; |
881c6935 JM |
5607 | { |
5608 | char buf[256]; | |
5609 | static int label_num; | |
2ad9852d | 5610 | |
63e46568 | 5611 | ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++); |
881c6935 JM |
5612 | return xstrdup (buf); |
5613 | } | |
5614 | ||
5615 | /* Assign symbols to all worthy DIEs under DIE. */ | |
5616 | ||
5617 | static void | |
5618 | assign_symbol_names (die) | |
b3694847 | 5619 | dw_die_ref die; |
881c6935 | 5620 | { |
b3694847 | 5621 | dw_die_ref c; |
881c6935 JM |
5622 | |
5623 | if (is_symbol_die (die)) | |
5624 | { | |
5625 | if (comdat_symbol_id) | |
5626 | { | |
5627 | char *p = alloca (strlen (comdat_symbol_id) + 64); | |
2ad9852d | 5628 | |
881c6935 JM |
5629 | sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX, |
5630 | comdat_symbol_id, comdat_symbol_number++); | |
5631 | die->die_symbol = xstrdup (p); | |
5632 | } | |
5633 | else | |
63e46568 | 5634 | die->die_symbol = gen_internal_sym ("LDIE"); |
881c6935 JM |
5635 | } |
5636 | ||
5637 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5638 | assign_symbol_names (c); | |
5639 | } | |
5640 | ||
5641 | /* Traverse the DIE (which is always comp_unit_die), and set up | |
5642 | additional compilation units for each of the include files we see | |
5643 | bracketed by BINCL/EINCL. */ | |
5644 | ||
5645 | static void | |
5646 | break_out_includes (die) | |
b3694847 | 5647 | dw_die_ref die; |
881c6935 JM |
5648 | { |
5649 | dw_die_ref *ptr; | |
b3694847 | 5650 | dw_die_ref unit = NULL; |
881c6935 JM |
5651 | limbo_die_node *node; |
5652 | ||
5653 | for (ptr = &(die->die_child); *ptr; ) | |
5654 | { | |
b3694847 | 5655 | dw_die_ref c = *ptr; |
881c6935 | 5656 | |
2ad9852d | 5657 | if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL |
881c6935 JM |
5658 | || (unit && is_comdat_die (c))) |
5659 | { | |
5660 | /* This DIE is for a secondary CU; remove it from the main one. */ | |
5661 | *ptr = c->die_sib; | |
5662 | ||
5663 | if (c->die_tag == DW_TAG_GNU_BINCL) | |
5664 | { | |
5665 | unit = push_new_compile_unit (unit, c); | |
5666 | free_die (c); | |
5667 | } | |
5668 | else if (c->die_tag == DW_TAG_GNU_EINCL) | |
5669 | { | |
5670 | unit = pop_compile_unit (unit); | |
5671 | free_die (c); | |
5672 | } | |
5673 | else | |
5674 | add_child_die (unit, c); | |
5675 | } | |
5676 | else | |
5677 | { | |
5678 | /* Leave this DIE in the main CU. */ | |
5679 | ptr = &(c->die_sib); | |
5680 | continue; | |
5681 | } | |
5682 | } | |
5683 | ||
5684 | #if 0 | |
5685 | /* We can only use this in debugging, since the frontend doesn't check | |
0b34cf1e | 5686 | to make sure that we leave every include file we enter. */ |
881c6935 JM |
5687 | if (unit != NULL) |
5688 | abort (); | |
5689 | #endif | |
5690 | ||
5691 | assign_symbol_names (die); | |
5692 | for (node = limbo_die_list; node; node = node->next) | |
5693 | { | |
5694 | compute_section_prefix (node->die); | |
5695 | assign_symbol_names (node->die); | |
5696 | } | |
5697 | } | |
5698 | ||
5699 | /* Traverse the DIE and add a sibling attribute if it may have the | |
5700 | effect of speeding up access to siblings. To save some space, | |
5701 | avoid generating sibling attributes for DIE's without children. */ | |
5702 | ||
5703 | static void | |
5704 | add_sibling_attributes (die) | |
b3694847 | 5705 | dw_die_ref die; |
881c6935 | 5706 | { |
b3694847 | 5707 | dw_die_ref c; |
881c6935 JM |
5708 | |
5709 | if (die->die_tag != DW_TAG_compile_unit | |
5710 | && die->die_sib && die->die_child != NULL) | |
7d9d8943 AM |
5711 | /* Add the sibling link to the front of the attribute list. */ |
5712 | add_AT_die_ref (die, DW_AT_sibling, die->die_sib); | |
5713 | ||
5714 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5715 | add_sibling_attributes (c); | |
5716 | } | |
5717 | ||
2ad9852d RK |
5718 | /* Output all location lists for the DIE and its children. */ |
5719 | ||
63e46568 DB |
5720 | static void |
5721 | output_location_lists (die) | |
b3694847 | 5722 | dw_die_ref die; |
63e46568 DB |
5723 | { |
5724 | dw_die_ref c; | |
5725 | dw_attr_ref d_attr; | |
2ad9852d | 5726 | |
63e46568 | 5727 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) |
2ad9852d RK |
5728 | if (AT_class (d_attr) == dw_val_class_loc_list) |
5729 | output_loc_list (AT_loc_list (d_attr)); | |
5730 | ||
63e46568 DB |
5731 | for (c = die->die_child; c != NULL; c = c->die_sib) |
5732 | output_location_lists (c); | |
5733 | ||
5734 | } | |
2ad9852d RK |
5735 | /* The format of each DIE (and its attribute value pairs) is encoded in an |
5736 | abbreviation table. This routine builds the abbreviation table and assigns | |
5737 | a unique abbreviation id for each abbreviation entry. The children of each | |
5738 | die are visited recursively. */ | |
7d9d8943 AM |
5739 | |
5740 | static void | |
5741 | build_abbrev_table (die) | |
b3694847 | 5742 | dw_die_ref die; |
7d9d8943 | 5743 | { |
b3694847 SS |
5744 | unsigned long abbrev_id; |
5745 | unsigned int n_alloc; | |
5746 | dw_die_ref c; | |
5747 | dw_attr_ref d_attr, a_attr; | |
881c6935 JM |
5748 | |
5749 | /* Scan the DIE references, and mark as external any that refer to | |
1bfb5f8f | 5750 | DIEs from other CUs (i.e. those which are not marked). */ |
881c6935 | 5751 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) |
2ad9852d RK |
5752 | if (AT_class (d_attr) == dw_val_class_die_ref |
5753 | && AT_ref (d_attr)->die_mark == 0) | |
5754 | { | |
5755 | if (AT_ref (d_attr)->die_symbol == 0) | |
5756 | abort (); | |
5757 | ||
5758 | set_AT_ref_external (d_attr, 1); | |
5759 | } | |
881c6935 | 5760 | |
7d9d8943 AM |
5761 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
5762 | { | |
b3694847 | 5763 | dw_die_ref abbrev = abbrev_die_table[abbrev_id]; |
7d9d8943 AM |
5764 | |
5765 | if (abbrev->die_tag == die->die_tag) | |
5766 | { | |
5767 | if ((abbrev->die_child != NULL) == (die->die_child != NULL)) | |
5768 | { | |
5769 | a_attr = abbrev->die_attr; | |
5770 | d_attr = die->die_attr; | |
5771 | ||
5772 | while (a_attr != NULL && d_attr != NULL) | |
5773 | { | |
5774 | if ((a_attr->dw_attr != d_attr->dw_attr) | |
5775 | || (value_format (a_attr) != value_format (d_attr))) | |
5776 | break; | |
5777 | ||
5778 | a_attr = a_attr->dw_attr_next; | |
5779 | d_attr = d_attr->dw_attr_next; | |
5780 | } | |
5781 | ||
5782 | if (a_attr == NULL && d_attr == NULL) | |
5783 | break; | |
5784 | } | |
5785 | } | |
5786 | } | |
5787 | ||
5788 | if (abbrev_id >= abbrev_die_table_in_use) | |
5789 | { | |
5790 | if (abbrev_die_table_in_use >= abbrev_die_table_allocated) | |
5791 | { | |
5792 | n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT; | |
556273e0 | 5793 | abbrev_die_table |
7d9d8943 AM |
5794 | = (dw_die_ref *) xrealloc (abbrev_die_table, |
5795 | sizeof (dw_die_ref) * n_alloc); | |
5796 | ||
961192e1 | 5797 | memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0, |
7d9d8943 AM |
5798 | (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref)); |
5799 | abbrev_die_table_allocated = n_alloc; | |
5800 | } | |
5801 | ||
5802 | ++abbrev_die_table_in_use; | |
5803 | abbrev_die_table[abbrev_id] = die; | |
5804 | } | |
5805 | ||
5806 | die->die_abbrev = abbrev_id; | |
5807 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5808 | build_abbrev_table (c); | |
5809 | } | |
5810 | \f | |
3f76745e JM |
5811 | /* Return the power-of-two number of bytes necessary to represent VALUE. */ |
5812 | ||
5813 | static int | |
5814 | constant_size (value) | |
5815 | long unsigned value; | |
5816 | { | |
5817 | int log; | |
5818 | ||
5819 | if (value == 0) | |
5820 | log = 0; | |
a3f97cbb | 5821 | else |
3f76745e | 5822 | log = floor_log2 (value); |
71dfc51f | 5823 | |
3f76745e JM |
5824 | log = log / 8; |
5825 | log = 1 << (floor_log2 (log) + 1); | |
5826 | ||
5827 | return log; | |
a3f97cbb JW |
5828 | } |
5829 | ||
2ad9852d | 5830 | /* Return the size of a DIE as it is represented in the |
3f76745e | 5831 | .debug_info section. */ |
71dfc51f | 5832 | |
3f76745e JM |
5833 | static unsigned long |
5834 | size_of_die (die) | |
b3694847 | 5835 | dw_die_ref die; |
a3f97cbb | 5836 | { |
b3694847 SS |
5837 | unsigned long size = 0; |
5838 | dw_attr_ref a; | |
71dfc51f | 5839 | |
3f76745e | 5840 | size += size_of_uleb128 (die->die_abbrev); |
a3f97cbb JW |
5841 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
5842 | { | |
a96c67ec | 5843 | switch (AT_class (a)) |
a3f97cbb JW |
5844 | { |
5845 | case dw_val_class_addr: | |
a1a4189d | 5846 | size += DWARF2_ADDR_SIZE; |
a3f97cbb | 5847 | break; |
a20612aa RH |
5848 | case dw_val_class_offset: |
5849 | size += DWARF_OFFSET_SIZE; | |
5850 | break; | |
a3f97cbb | 5851 | case dw_val_class_loc: |
3f76745e | 5852 | { |
b3694847 | 5853 | unsigned long lsize = size_of_locs (AT_loc (a)); |
71dfc51f | 5854 | |
3f76745e JM |
5855 | /* Block length. */ |
5856 | size += constant_size (lsize); | |
5857 | size += lsize; | |
5858 | } | |
a3f97cbb | 5859 | break; |
63e46568 DB |
5860 | case dw_val_class_loc_list: |
5861 | size += DWARF_OFFSET_SIZE; | |
5862 | break; | |
2bee6045 JJ |
5863 | case dw_val_class_range_list: |
5864 | size += DWARF_OFFSET_SIZE; | |
5865 | break; | |
a3f97cbb | 5866 | case dw_val_class_const: |
25dd13ec | 5867 | size += size_of_sleb128 (AT_int (a)); |
a3f97cbb JW |
5868 | break; |
5869 | case dw_val_class_unsigned_const: | |
a96c67ec | 5870 | size += constant_size (AT_unsigned (a)); |
a3f97cbb | 5871 | break; |
469ac993 | 5872 | case dw_val_class_long_long: |
2e4b9b8c | 5873 | size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */ |
469ac993 JM |
5874 | break; |
5875 | case dw_val_class_float: | |
3f76745e | 5876 | size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */ |
a3f97cbb JW |
5877 | break; |
5878 | case dw_val_class_flag: | |
3f76745e | 5879 | size += 1; |
a3f97cbb JW |
5880 | break; |
5881 | case dw_val_class_die_ref: | |
3f76745e | 5882 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
5883 | break; |
5884 | case dw_val_class_fde_ref: | |
3f76745e | 5885 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
5886 | break; |
5887 | case dw_val_class_lbl_id: | |
a1a4189d | 5888 | size += DWARF2_ADDR_SIZE; |
3f76745e | 5889 | break; |
8b790721 | 5890 | case dw_val_class_lbl_offset: |
3f76745e JM |
5891 | size += DWARF_OFFSET_SIZE; |
5892 | break; | |
5893 | case dw_val_class_str: | |
9eb4015a JJ |
5894 | if (AT_string_form (a) == DW_FORM_strp) |
5895 | size += DWARF_OFFSET_SIZE; | |
5896 | else | |
5897 | size += HT_LEN (&a->dw_attr_val.v.val_str->id) + 1; | |
3f76745e JM |
5898 | break; |
5899 | default: | |
5900 | abort (); | |
5901 | } | |
a3f97cbb | 5902 | } |
3f76745e JM |
5903 | |
5904 | return size; | |
a3f97cbb JW |
5905 | } |
5906 | ||
2ad9852d RK |
5907 | /* Size the debugging information associated with a given DIE. Visits the |
5908 | DIE's children recursively. Updates the global variable next_die_offset, on | |
5909 | each time through. Uses the current value of next_die_offset to update the | |
5910 | die_offset field in each DIE. */ | |
71dfc51f | 5911 | |
a3f97cbb | 5912 | static void |
3f76745e JM |
5913 | calc_die_sizes (die) |
5914 | dw_die_ref die; | |
a3f97cbb | 5915 | { |
b3694847 | 5916 | dw_die_ref c; |
2ad9852d | 5917 | |
3f76745e JM |
5918 | die->die_offset = next_die_offset; |
5919 | next_die_offset += size_of_die (die); | |
71dfc51f | 5920 | |
3f76745e JM |
5921 | for (c = die->die_child; c != NULL; c = c->die_sib) |
5922 | calc_die_sizes (c); | |
71dfc51f | 5923 | |
3f76745e JM |
5924 | if (die->die_child != NULL) |
5925 | /* Count the null byte used to terminate sibling lists. */ | |
5926 | next_die_offset += 1; | |
a3f97cbb JW |
5927 | } |
5928 | ||
1bfb5f8f | 5929 | /* Set the marks for a die and its children. We do this so |
881c6935 | 5930 | that we know whether or not a reference needs to use FORM_ref_addr; only |
1bfb5f8f JM |
5931 | DIEs in the same CU will be marked. We used to clear out the offset |
5932 | and use that as the flag, but ran into ordering problems. */ | |
881c6935 JM |
5933 | |
5934 | static void | |
1bfb5f8f | 5935 | mark_dies (die) |
881c6935 JM |
5936 | dw_die_ref die; |
5937 | { | |
b3694847 | 5938 | dw_die_ref c; |
2ad9852d | 5939 | |
1bfb5f8f JM |
5940 | die->die_mark = 1; |
5941 | for (c = die->die_child; c; c = c->die_sib) | |
5942 | mark_dies (c); | |
5943 | } | |
5944 | ||
5945 | /* Clear the marks for a die and its children. */ | |
5946 | ||
5947 | static void | |
5948 | unmark_dies (die) | |
5949 | dw_die_ref die; | |
5950 | { | |
b3694847 | 5951 | dw_die_ref c; |
2ad9852d | 5952 | |
1bfb5f8f | 5953 | die->die_mark = 0; |
881c6935 | 5954 | for (c = die->die_child; c; c = c->die_sib) |
1bfb5f8f | 5955 | unmark_dies (c); |
881c6935 JM |
5956 | } |
5957 | ||
3f76745e JM |
5958 | /* Return the size of the .debug_pubnames table generated for the |
5959 | compilation unit. */ | |
a94dbf2c | 5960 | |
3f76745e JM |
5961 | static unsigned long |
5962 | size_of_pubnames () | |
a94dbf2c | 5963 | { |
b3694847 SS |
5964 | unsigned long size; |
5965 | unsigned i; | |
469ac993 | 5966 | |
3f76745e | 5967 | size = DWARF_PUBNAMES_HEADER_SIZE; |
2ad9852d | 5968 | for (i = 0; i < pubname_table_in_use; i++) |
a94dbf2c | 5969 | { |
b3694847 | 5970 | pubname_ref p = &pubname_table[i]; |
9eb4015a | 5971 | size += DWARF_OFFSET_SIZE + strlen (p->name) + 1; |
a94dbf2c JM |
5972 | } |
5973 | ||
3f76745e JM |
5974 | size += DWARF_OFFSET_SIZE; |
5975 | return size; | |
a94dbf2c JM |
5976 | } |
5977 | ||
956d6950 | 5978 | /* Return the size of the information in the .debug_aranges section. */ |
469ac993 | 5979 | |
3f76745e JM |
5980 | static unsigned long |
5981 | size_of_aranges () | |
469ac993 | 5982 | { |
b3694847 | 5983 | unsigned long size; |
469ac993 | 5984 | |
3f76745e | 5985 | size = DWARF_ARANGES_HEADER_SIZE; |
469ac993 | 5986 | |
3f76745e | 5987 | /* Count the address/length pair for this compilation unit. */ |
a1a4189d JB |
5988 | size += 2 * DWARF2_ADDR_SIZE; |
5989 | size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use; | |
469ac993 | 5990 | |
3f76745e | 5991 | /* Count the two zero words used to terminated the address range table. */ |
a1a4189d | 5992 | size += 2 * DWARF2_ADDR_SIZE; |
3f76745e JM |
5993 | return size; |
5994 | } | |
5995 | \f | |
5996 | /* Select the encoding of an attribute value. */ | |
5997 | ||
5998 | static enum dwarf_form | |
a96c67ec JM |
5999 | value_format (a) |
6000 | dw_attr_ref a; | |
3f76745e | 6001 | { |
a96c67ec | 6002 | switch (a->dw_attr_val.val_class) |
469ac993 | 6003 | { |
3f76745e JM |
6004 | case dw_val_class_addr: |
6005 | return DW_FORM_addr; | |
2bee6045 | 6006 | case dw_val_class_range_list: |
a20612aa RH |
6007 | case dw_val_class_offset: |
6008 | if (DWARF_OFFSET_SIZE == 4) | |
6009 | return DW_FORM_data4; | |
6010 | if (DWARF_OFFSET_SIZE == 8) | |
6011 | return DW_FORM_data8; | |
6012 | abort (); | |
63e46568 | 6013 | case dw_val_class_loc_list: |
9d2f2c45 RH |
6014 | /* FIXME: Could be DW_FORM_data8, with a > 32 bit size |
6015 | .debug_loc section */ | |
6016 | return DW_FORM_data4; | |
3f76745e | 6017 | case dw_val_class_loc: |
a96c67ec | 6018 | switch (constant_size (size_of_locs (AT_loc (a)))) |
469ac993 | 6019 | { |
3f76745e JM |
6020 | case 1: |
6021 | return DW_FORM_block1; | |
6022 | case 2: | |
6023 | return DW_FORM_block2; | |
469ac993 JM |
6024 | default: |
6025 | abort (); | |
6026 | } | |
3f76745e | 6027 | case dw_val_class_const: |
25dd13ec | 6028 | return DW_FORM_sdata; |
3f76745e | 6029 | case dw_val_class_unsigned_const: |
a96c67ec | 6030 | switch (constant_size (AT_unsigned (a))) |
3f76745e JM |
6031 | { |
6032 | case 1: | |
6033 | return DW_FORM_data1; | |
6034 | case 2: | |
6035 | return DW_FORM_data2; | |
6036 | case 4: | |
6037 | return DW_FORM_data4; | |
6038 | case 8: | |
6039 | return DW_FORM_data8; | |
6040 | default: | |
6041 | abort (); | |
6042 | } | |
6043 | case dw_val_class_long_long: | |
6044 | return DW_FORM_block1; | |
6045 | case dw_val_class_float: | |
6046 | return DW_FORM_block1; | |
6047 | case dw_val_class_flag: | |
6048 | return DW_FORM_flag; | |
6049 | case dw_val_class_die_ref: | |
881c6935 JM |
6050 | if (AT_ref_external (a)) |
6051 | return DW_FORM_ref_addr; | |
6052 | else | |
6053 | return DW_FORM_ref; | |
3f76745e JM |
6054 | case dw_val_class_fde_ref: |
6055 | return DW_FORM_data; | |
6056 | case dw_val_class_lbl_id: | |
6057 | return DW_FORM_addr; | |
8b790721 | 6058 | case dw_val_class_lbl_offset: |
3f76745e JM |
6059 | return DW_FORM_data; |
6060 | case dw_val_class_str: | |
9eb4015a | 6061 | return AT_string_form (a); |
a20612aa | 6062 | |
469ac993 JM |
6063 | default: |
6064 | abort (); | |
6065 | } | |
a94dbf2c JM |
6066 | } |
6067 | ||
3f76745e | 6068 | /* Output the encoding of an attribute value. */ |
469ac993 | 6069 | |
3f76745e | 6070 | static void |
a96c67ec JM |
6071 | output_value_format (a) |
6072 | dw_attr_ref a; | |
a94dbf2c | 6073 | { |
a96c67ec | 6074 | enum dwarf_form form = value_format (a); |
2ad9852d | 6075 | |
2e4b9b8c | 6076 | dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form)); |
3f76745e | 6077 | } |
469ac993 | 6078 | |
3f76745e JM |
6079 | /* Output the .debug_abbrev section which defines the DIE abbreviation |
6080 | table. */ | |
469ac993 | 6081 | |
3f76745e JM |
6082 | static void |
6083 | output_abbrev_section () | |
6084 | { | |
6085 | unsigned long abbrev_id; | |
71dfc51f | 6086 | |
3f76745e | 6087 | dw_attr_ref a_attr; |
2ad9852d | 6088 | |
3f76745e JM |
6089 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
6090 | { | |
b3694847 | 6091 | dw_die_ref abbrev = abbrev_die_table[abbrev_id]; |
71dfc51f | 6092 | |
2e4b9b8c | 6093 | dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)"); |
2e4b9b8c RH |
6094 | dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)", |
6095 | dwarf_tag_name (abbrev->die_tag)); | |
71dfc51f | 6096 | |
2e4b9b8c RH |
6097 | if (abbrev->die_child != NULL) |
6098 | dw2_asm_output_data (1, DW_children_yes, "DW_children_yes"); | |
6099 | else | |
6100 | dw2_asm_output_data (1, DW_children_no, "DW_children_no"); | |
3f76745e JM |
6101 | |
6102 | for (a_attr = abbrev->die_attr; a_attr != NULL; | |
6103 | a_attr = a_attr->dw_attr_next) | |
6104 | { | |
2e4b9b8c RH |
6105 | dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)", |
6106 | dwarf_attr_name (a_attr->dw_attr)); | |
a96c67ec | 6107 | output_value_format (a_attr); |
469ac993 | 6108 | } |
469ac993 | 6109 | |
2e4b9b8c RH |
6110 | dw2_asm_output_data (1, 0, NULL); |
6111 | dw2_asm_output_data (1, 0, NULL); | |
469ac993 | 6112 | } |
81f374eb HPN |
6113 | |
6114 | /* Terminate the table. */ | |
2e4b9b8c | 6115 | dw2_asm_output_data (1, 0, NULL); |
a94dbf2c JM |
6116 | } |
6117 | ||
881c6935 JM |
6118 | /* Output a symbol we can use to refer to this DIE from another CU. */ |
6119 | ||
6120 | static inline void | |
6121 | output_die_symbol (die) | |
b3694847 | 6122 | dw_die_ref die; |
881c6935 JM |
6123 | { |
6124 | char *sym = die->die_symbol; | |
6125 | ||
6126 | if (sym == 0) | |
6127 | return; | |
6128 | ||
6129 | if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0) | |
6130 | /* We make these global, not weak; if the target doesn't support | |
6131 | .linkonce, it doesn't support combining the sections, so debugging | |
6132 | will break. */ | |
6133 | ASM_GLOBALIZE_LABEL (asm_out_file, sym); | |
2ad9852d | 6134 | |
881c6935 JM |
6135 | ASM_OUTPUT_LABEL (asm_out_file, sym); |
6136 | } | |
6137 | ||
84a5b4f8 | 6138 | /* Return a new location list, given the begin and end range, and the |
2ad9852d RK |
6139 | expression. gensym tells us whether to generate a new internal symbol for |
6140 | this location list node, which is done for the head of the list only. */ | |
6141 | ||
84a5b4f8 DB |
6142 | static inline dw_loc_list_ref |
6143 | new_loc_list (expr, begin, end, section, gensym) | |
b3694847 SS |
6144 | dw_loc_descr_ref expr; |
6145 | const char *begin; | |
6146 | const char *end; | |
6147 | const char *section; | |
6148 | unsigned gensym; | |
84a5b4f8 | 6149 | { |
b3694847 | 6150 | dw_loc_list_ref retlist |
84a5b4f8 | 6151 | = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node)); |
2ad9852d | 6152 | |
84a5b4f8 DB |
6153 | retlist->begin = begin; |
6154 | retlist->end = end; | |
6155 | retlist->expr = expr; | |
6156 | retlist->section = section; | |
6157 | if (gensym) | |
6158 | retlist->ll_symbol = gen_internal_sym ("LLST"); | |
2ad9852d | 6159 | |
84a5b4f8 DB |
6160 | return retlist; |
6161 | } | |
6162 | ||
6163 | /* Add a location description expression to a location list */ | |
2ad9852d | 6164 | |
84a5b4f8 DB |
6165 | static inline void |
6166 | add_loc_descr_to_loc_list (list_head, descr, begin, end, section) | |
b3694847 SS |
6167 | dw_loc_list_ref *list_head; |
6168 | dw_loc_descr_ref descr; | |
6169 | const char *begin; | |
6170 | const char *end; | |
6171 | const char *section; | |
84a5b4f8 | 6172 | { |
b3694847 | 6173 | dw_loc_list_ref *d; |
84a5b4f8 | 6174 | |
30f7a378 | 6175 | /* Find the end of the chain. */ |
84a5b4f8 DB |
6176 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) |
6177 | ; | |
2ad9852d | 6178 | |
84a5b4f8 DB |
6179 | /* Add a new location list node to the list */ |
6180 | *d = new_loc_list (descr, begin, end, section, 0); | |
6181 | } | |
6182 | ||
63e46568 | 6183 | /* Output the location list given to us */ |
2ad9852d | 6184 | |
63e46568 DB |
6185 | static void |
6186 | output_loc_list (list_head) | |
b3694847 | 6187 | dw_loc_list_ref list_head; |
63e46568 | 6188 | { |
2ad9852d RK |
6189 | dw_loc_list_ref curr = list_head; |
6190 | ||
63e46568 | 6191 | ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol); |
a20612aa RH |
6192 | |
6193 | /* ??? This shouldn't be needed now that we've forced the | |
6194 | compilation unit base address to zero when there is code | |
6195 | in more than one section. */ | |
63e46568 DB |
6196 | if (strcmp (curr->section, ".text") == 0) |
6197 | { | |
aafdcfcd | 6198 | /* dw2_asm_output_data will mask off any extra bits in the ~0. */ |
c4f2c499 | 6199 | dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0, |
aafdcfcd NS |
6200 | "Location list base address specifier fake entry"); |
6201 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section, | |
6202 | "Location list base address specifier base"); | |
63e46568 | 6203 | } |
2ad9852d | 6204 | |
63e46568 DB |
6205 | for (curr = list_head; curr != NULL; curr=curr->dw_loc_next) |
6206 | { | |
2bee6045 | 6207 | unsigned long size; |
2ad9852d | 6208 | |
aafdcfcd NS |
6209 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section, |
6210 | "Location list begin address (%s)", | |
6211 | list_head->ll_symbol); | |
6212 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section, | |
6213 | "Location list end address (%s)", | |
6214 | list_head->ll_symbol); | |
63e46568 DB |
6215 | size = size_of_locs (curr->expr); |
6216 | ||
6217 | /* Output the block length for this list of location operations. */ | |
2bee6045 JJ |
6218 | if (size > 0xffff) |
6219 | abort (); | |
6220 | dw2_asm_output_data (2, size, "%s", "Location expression size"); | |
6221 | ||
63e46568 DB |
6222 | output_loc_sequence (curr->expr); |
6223 | } | |
2ad9852d | 6224 | |
aafdcfcd NS |
6225 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, |
6226 | "Location list terminator begin (%s)", | |
6227 | list_head->ll_symbol); | |
6228 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, | |
6229 | "Location list terminator end (%s)", | |
6230 | list_head->ll_symbol); | |
63e46568 | 6231 | } |
9eb4015a | 6232 | |
3f76745e JM |
6233 | /* Output the DIE and its attributes. Called recursively to generate |
6234 | the definitions of each child DIE. */ | |
71dfc51f | 6235 | |
a3f97cbb | 6236 | static void |
3f76745e | 6237 | output_die (die) |
b3694847 | 6238 | dw_die_ref die; |
a3f97cbb | 6239 | { |
b3694847 SS |
6240 | dw_attr_ref a; |
6241 | dw_die_ref c; | |
6242 | unsigned long size; | |
a94dbf2c | 6243 | |
881c6935 JM |
6244 | /* If someone in another CU might refer to us, set up a symbol for |
6245 | them to point to. */ | |
6246 | if (die->die_symbol) | |
6247 | output_die_symbol (die); | |
6248 | ||
2e4b9b8c RH |
6249 | dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)", |
6250 | die->die_offset, dwarf_tag_name (die->die_tag)); | |
a94dbf2c | 6251 | |
3f76745e | 6252 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
a3f97cbb | 6253 | { |
2e4b9b8c RH |
6254 | const char *name = dwarf_attr_name (a->dw_attr); |
6255 | ||
a96c67ec | 6256 | switch (AT_class (a)) |
3f76745e JM |
6257 | { |
6258 | case dw_val_class_addr: | |
2e4b9b8c | 6259 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name); |
3f76745e | 6260 | break; |
a3f97cbb | 6261 | |
a20612aa RH |
6262 | case dw_val_class_offset: |
6263 | dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset, | |
6264 | "%s", name); | |
6265 | break; | |
6266 | ||
2bee6045 JJ |
6267 | case dw_val_class_range_list: |
6268 | { | |
6269 | char *p = strchr (ranges_section_label, '\0'); | |
6270 | ||
6271 | sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset); | |
6272 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label, | |
6273 | "%s", name); | |
6274 | *p = '\0'; | |
6275 | } | |
6276 | break; | |
6277 | ||
3f76745e | 6278 | case dw_val_class_loc: |
a96c67ec | 6279 | size = size_of_locs (AT_loc (a)); |
71dfc51f | 6280 | |
3f76745e | 6281 | /* Output the block length for this list of location operations. */ |
2e4b9b8c | 6282 | dw2_asm_output_data (constant_size (size), size, "%s", name); |
71dfc51f | 6283 | |
7d9d8943 | 6284 | output_loc_sequence (AT_loc (a)); |
a3f97cbb | 6285 | break; |
3f76745e JM |
6286 | |
6287 | case dw_val_class_const: | |
25dd13ec JW |
6288 | /* ??? It would be slightly more efficient to use a scheme like is |
6289 | used for unsigned constants below, but gdb 4.x does not sign | |
6290 | extend. Gdb 5.x does sign extend. */ | |
2e4b9b8c | 6291 | dw2_asm_output_data_sleb128 (AT_int (a), "%s", name); |
a3f97cbb | 6292 | break; |
3f76745e JM |
6293 | |
6294 | case dw_val_class_unsigned_const: | |
2e4b9b8c RH |
6295 | dw2_asm_output_data (constant_size (AT_unsigned (a)), |
6296 | AT_unsigned (a), "%s", name); | |
a3f97cbb | 6297 | break; |
3f76745e JM |
6298 | |
6299 | case dw_val_class_long_long: | |
2e4b9b8c RH |
6300 | { |
6301 | unsigned HOST_WIDE_INT first, second; | |
3f76745e | 6302 | |
2ad9852d RK |
6303 | dw2_asm_output_data (1, |
6304 | 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, | |
2e4b9b8c | 6305 | "%s", name); |
556273e0 | 6306 | |
2e4b9b8c RH |
6307 | if (WORDS_BIG_ENDIAN) |
6308 | { | |
6309 | first = a->dw_attr_val.v.val_long_long.hi; | |
6310 | second = a->dw_attr_val.v.val_long_long.low; | |
6311 | } | |
6312 | else | |
6313 | { | |
6314 | first = a->dw_attr_val.v.val_long_long.low; | |
6315 | second = a->dw_attr_val.v.val_long_long.hi; | |
6316 | } | |
2ad9852d RK |
6317 | |
6318 | dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, | |
2e4b9b8c | 6319 | first, "long long constant"); |
2ad9852d | 6320 | dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, |
2e4b9b8c RH |
6321 | second, NULL); |
6322 | } | |
a3f97cbb | 6323 | break; |
3f76745e JM |
6324 | |
6325 | case dw_val_class_float: | |
c84e2712 | 6326 | { |
b3694847 | 6327 | unsigned int i; |
c84e2712 | 6328 | |
2e4b9b8c RH |
6329 | dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4, |
6330 | "%s", name); | |
c84e2712 | 6331 | |
2ad9852d | 6332 | for (i = 0; i < a->dw_attr_val.v.val_float.length; i++) |
2e4b9b8c RH |
6333 | dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i], |
6334 | "fp constant word %u", i); | |
556273e0 | 6335 | break; |
c84e2712 | 6336 | } |
3f76745e JM |
6337 | |
6338 | case dw_val_class_flag: | |
2e4b9b8c | 6339 | dw2_asm_output_data (1, AT_flag (a), "%s", name); |
a3f97cbb | 6340 | break; |
a20612aa | 6341 | |
63e46568 DB |
6342 | case dw_val_class_loc_list: |
6343 | { | |
6344 | char *sym = AT_loc_list (a)->ll_symbol; | |
2ad9852d | 6345 | |
63e46568 | 6346 | if (sym == 0) |
173bf5be | 6347 | abort (); |
a20612aa RH |
6348 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, |
6349 | loc_section_label, "%s", name); | |
63e46568 DB |
6350 | } |
6351 | break; | |
a20612aa | 6352 | |
3f76745e | 6353 | case dw_val_class_die_ref: |
881c6935 | 6354 | if (AT_ref_external (a)) |
2e4b9b8c RH |
6355 | { |
6356 | char *sym = AT_ref (a)->die_symbol; | |
2ad9852d | 6357 | |
2e4b9b8c RH |
6358 | if (sym == 0) |
6359 | abort (); | |
6360 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name); | |
6361 | } | |
3f4907a6 JM |
6362 | else if (AT_ref (a)->die_offset == 0) |
6363 | abort (); | |
881c6935 | 6364 | else |
2e4b9b8c RH |
6365 | dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset, |
6366 | "%s", name); | |
a3f97cbb | 6367 | break; |
3f76745e JM |
6368 | |
6369 | case dw_val_class_fde_ref: | |
a6ab3aad JM |
6370 | { |
6371 | char l1[20]; | |
2ad9852d | 6372 | |
2e4b9b8c RH |
6373 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL, |
6374 | a->dw_attr_val.v.val_fde_index * 2); | |
6375 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name); | |
a6ab3aad | 6376 | } |
a3f97cbb | 6377 | break; |
a3f97cbb | 6378 | |
3f76745e | 6379 | case dw_val_class_lbl_id: |
8e7fa2c8 | 6380 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 6381 | break; |
71dfc51f | 6382 | |
8b790721 | 6383 | case dw_val_class_lbl_offset: |
2e4b9b8c | 6384 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 6385 | break; |
a3f97cbb | 6386 | |
3f76745e | 6387 | case dw_val_class_str: |
9eb4015a JJ |
6388 | if (AT_string_form (a) == DW_FORM_strp) |
6389 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, | |
6390 | a->dw_attr_val.v.val_str->label, | |
a4cf1d85 | 6391 | "%s: \"%s\"", name, AT_string (a)); |
9eb4015a JJ |
6392 | else |
6393 | dw2_asm_output_nstring (AT_string (a), -1, "%s", name); | |
3f76745e | 6394 | break; |
b2932ae5 | 6395 | |
3f76745e JM |
6396 | default: |
6397 | abort (); | |
6398 | } | |
3f76745e | 6399 | } |
71dfc51f | 6400 | |
3f76745e JM |
6401 | for (c = die->die_child; c != NULL; c = c->die_sib) |
6402 | output_die (c); | |
71dfc51f | 6403 | |
2ad9852d | 6404 | /* Add null byte to terminate sibling list. */ |
3f76745e | 6405 | if (die->die_child != NULL) |
2ad9852d RK |
6406 | dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx", |
6407 | die->die_offset); | |
3f76745e | 6408 | } |
71dfc51f | 6409 | |
3f76745e JM |
6410 | /* Output the compilation unit that appears at the beginning of the |
6411 | .debug_info section, and precedes the DIE descriptions. */ | |
71dfc51f | 6412 | |
3f76745e JM |
6413 | static void |
6414 | output_compilation_unit_header () | |
6415 | { | |
2e4b9b8c RH |
6416 | dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE, |
6417 | "Length of Compilation Unit Info"); | |
2e4b9b8c | 6418 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number"); |
2e4b9b8c RH |
6419 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label, |
6420 | "Offset Into Abbrev. Section"); | |
2e4b9b8c | 6421 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)"); |
a3f97cbb JW |
6422 | } |
6423 | ||
881c6935 JM |
6424 | /* Output the compilation unit DIE and its children. */ |
6425 | ||
6426 | static void | |
6427 | output_comp_unit (die) | |
6428 | dw_die_ref die; | |
6429 | { | |
ce1cc601 | 6430 | const char *secname; |
881c6935 | 6431 | |
2ad9852d RK |
6432 | /* Even if there are no children of this DIE, we must output the information |
6433 | about the compilation unit. Otherwise, on an empty translation unit, we | |
6434 | will generate a present, but empty, .debug_info section. IRIX 6.5 `nm' | |
6435 | will then complain when examining the file. First mark all the DIEs in | |
6436 | this CU so we know which get local refs. */ | |
1bfb5f8f JM |
6437 | mark_dies (die); |
6438 | ||
6439 | build_abbrev_table (die); | |
6440 | ||
6d2f8887 | 6441 | /* Initialize the beginning DIE offset - and calculate sizes/offsets. */ |
881c6935 JM |
6442 | next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE; |
6443 | calc_die_sizes (die); | |
6444 | ||
881c6935 JM |
6445 | if (die->die_symbol) |
6446 | { | |
ce1cc601 | 6447 | char *tmp = (char *) alloca (strlen (die->die_symbol) + 24); |
2ad9852d | 6448 | |
ce1cc601 KG |
6449 | sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol); |
6450 | secname = tmp; | |
881c6935 JM |
6451 | die->die_symbol = NULL; |
6452 | } | |
6453 | else | |
ce1cc601 | 6454 | secname = (const char *) DEBUG_INFO_SECTION; |
881c6935 JM |
6455 | |
6456 | /* Output debugging information. */ | |
715bdd29 | 6457 | named_section_flags (secname, SECTION_DEBUG); |
881c6935 JM |
6458 | output_compilation_unit_header (); |
6459 | output_die (die); | |
6460 | ||
1bfb5f8f JM |
6461 | /* Leave the marks on the main CU, so we can check them in |
6462 | output_pubnames. */ | |
881c6935 | 6463 | if (die->die_symbol) |
1bfb5f8f | 6464 | unmark_dies (die); |
881c6935 JM |
6465 | } |
6466 | ||
a1d7ffe3 JM |
6467 | /* The DWARF2 pubname for a nested thingy looks like "A::f". The output |
6468 | of decl_printable_name for C++ looks like "A::f(int)". Let's drop the | |
6469 | argument list, and maybe the scope. */ | |
6470 | ||
d560ee52 | 6471 | static const char * |
a1d7ffe3 JM |
6472 | dwarf2_name (decl, scope) |
6473 | tree decl; | |
6474 | int scope; | |
6475 | { | |
6476 | return (*decl_printable_name) (decl, scope ? 1 : 0); | |
6477 | } | |
6478 | ||
d291dd49 | 6479 | /* Add a new entry to .debug_pubnames if appropriate. */ |
71dfc51f | 6480 | |
d291dd49 JM |
6481 | static void |
6482 | add_pubname (decl, die) | |
6483 | tree decl; | |
6484 | dw_die_ref die; | |
6485 | { | |
6486 | pubname_ref p; | |
6487 | ||
6488 | if (! TREE_PUBLIC (decl)) | |
6489 | return; | |
6490 | ||
6491 | if (pubname_table_in_use == pubname_table_allocated) | |
6492 | { | |
6493 | pubname_table_allocated += PUBNAME_TABLE_INCREMENT; | |
2ad9852d RK |
6494 | pubname_table |
6495 | = (pubname_ref) xrealloc (pubname_table, | |
6496 | (pubname_table_allocated | |
6497 | * sizeof (pubname_entry))); | |
d291dd49 | 6498 | } |
71dfc51f | 6499 | |
d291dd49 JM |
6500 | p = &pubname_table[pubname_table_in_use++]; |
6501 | p->die = die; | |
a1d7ffe3 | 6502 | p->name = xstrdup (dwarf2_name (decl, 1)); |
d291dd49 JM |
6503 | } |
6504 | ||
a3f97cbb JW |
6505 | /* Output the public names table used to speed up access to externally |
6506 | visible names. For now, only generate entries for externally | |
6507 | visible procedures. */ | |
71dfc51f | 6508 | |
a3f97cbb JW |
6509 | static void |
6510 | output_pubnames () | |
6511 | { | |
b3694847 SS |
6512 | unsigned i; |
6513 | unsigned long pubnames_length = size_of_pubnames (); | |
71dfc51f | 6514 | |
2e4b9b8c RH |
6515 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, |
6516 | "Length of Public Names Info"); | |
2e4b9b8c | 6517 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
2e4b9b8c RH |
6518 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
6519 | "Offset of Compilation Unit Info"); | |
2e4b9b8c RH |
6520 | dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset, |
6521 | "Compilation Unit Length"); | |
71dfc51f | 6522 | |
2ad9852d | 6523 | for (i = 0; i < pubname_table_in_use; i++) |
a3f97cbb | 6524 | { |
b3694847 | 6525 | pubname_ref pub = &pubname_table[i]; |
71dfc51f | 6526 | |
881c6935 | 6527 | /* We shouldn't see pubnames for DIEs outside of the main CU. */ |
1bfb5f8f | 6528 | if (pub->die->die_mark == 0) |
881c6935 JM |
6529 | abort (); |
6530 | ||
2e4b9b8c RH |
6531 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset, |
6532 | "DIE offset"); | |
71dfc51f | 6533 | |
2e4b9b8c | 6534 | dw2_asm_output_nstring (pub->name, -1, "external name"); |
a3f97cbb | 6535 | } |
71dfc51f | 6536 | |
2e4b9b8c | 6537 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL); |
a3f97cbb JW |
6538 | } |
6539 | ||
d291dd49 | 6540 | /* Add a new entry to .debug_aranges if appropriate. */ |
71dfc51f | 6541 | |
d291dd49 JM |
6542 | static void |
6543 | add_arange (decl, die) | |
6544 | tree decl; | |
6545 | dw_die_ref die; | |
6546 | { | |
6547 | if (! DECL_SECTION_NAME (decl)) | |
6548 | return; | |
6549 | ||
6550 | if (arange_table_in_use == arange_table_allocated) | |
6551 | { | |
6552 | arange_table_allocated += ARANGE_TABLE_INCREMENT; | |
a20612aa RH |
6553 | arange_table = (dw_die_ref *) |
6554 | xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref)); | |
d291dd49 | 6555 | } |
71dfc51f | 6556 | |
d291dd49 JM |
6557 | arange_table[arange_table_in_use++] = die; |
6558 | } | |
6559 | ||
a3f97cbb JW |
6560 | /* Output the information that goes into the .debug_aranges table. |
6561 | Namely, define the beginning and ending address range of the | |
6562 | text section generated for this compilation unit. */ | |
71dfc51f | 6563 | |
a3f97cbb JW |
6564 | static void |
6565 | output_aranges () | |
6566 | { | |
b3694847 SS |
6567 | unsigned i; |
6568 | unsigned long aranges_length = size_of_aranges (); | |
71dfc51f | 6569 | |
2e4b9b8c RH |
6570 | dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length, |
6571 | "Length of Address Ranges Info"); | |
2e4b9b8c | 6572 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
2e4b9b8c RH |
6573 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
6574 | "Offset of Compilation Unit Info"); | |
2e4b9b8c | 6575 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address"); |
2e4b9b8c | 6576 | dw2_asm_output_data (1, 0, "Size of Segment Descriptor"); |
71dfc51f | 6577 | |
262b6384 SC |
6578 | /* We need to align to twice the pointer size here. */ |
6579 | if (DWARF_ARANGES_PAD_SIZE) | |
6580 | { | |
2e4b9b8c RH |
6581 | /* Pad using a 2 byte words so that padding is correct for any |
6582 | pointer size. */ | |
6583 | dw2_asm_output_data (2, 0, "Pad to %d byte boundary", | |
6584 | 2 * DWARF2_ADDR_SIZE); | |
770ca8c6 | 6585 | for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2) |
2e4b9b8c | 6586 | dw2_asm_output_data (2, 0, NULL); |
262b6384 | 6587 | } |
71dfc51f | 6588 | |
8e7fa2c8 | 6589 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address"); |
2e4b9b8c RH |
6590 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label, |
6591 | text_section_label, "Length"); | |
71dfc51f | 6592 | |
2ad9852d | 6593 | for (i = 0; i < arange_table_in_use; i++) |
d291dd49 | 6594 | { |
e689ae67 | 6595 | dw_die_ref die = arange_table[i]; |
71dfc51f | 6596 | |
881c6935 | 6597 | /* We shouldn't see aranges for DIEs outside of the main CU. */ |
1bfb5f8f | 6598 | if (die->die_mark == 0) |
881c6935 JM |
6599 | abort (); |
6600 | ||
e689ae67 | 6601 | if (die->die_tag == DW_TAG_subprogram) |
2e4b9b8c | 6602 | { |
8e7fa2c8 | 6603 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die), |
173bf5be | 6604 | "Address"); |
2e4b9b8c RH |
6605 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die), |
6606 | get_AT_low_pc (die), "Length"); | |
6607 | } | |
d291dd49 | 6608 | else |
a1d7ffe3 | 6609 | { |
e689ae67 JM |
6610 | /* A static variable; extract the symbol from DW_AT_location. |
6611 | Note that this code isn't currently hit, as we only emit | |
6612 | aranges for functions (jason 9/23/99). */ | |
e689ae67 JM |
6613 | dw_attr_ref a = get_AT (die, DW_AT_location); |
6614 | dw_loc_descr_ref loc; | |
2ad9852d | 6615 | |
a96c67ec | 6616 | if (! a || AT_class (a) != dw_val_class_loc) |
e689ae67 JM |
6617 | abort (); |
6618 | ||
a96c67ec | 6619 | loc = AT_loc (a); |
e689ae67 JM |
6620 | if (loc->dw_loc_opc != DW_OP_addr) |
6621 | abort (); | |
6622 | ||
2e4b9b8c RH |
6623 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, |
6624 | loc->dw_loc_oprnd1.v.val_addr, "Address"); | |
6625 | dw2_asm_output_data (DWARF2_ADDR_SIZE, | |
6626 | get_AT_unsigned (die, DW_AT_byte_size), | |
6627 | "Length"); | |
a1d7ffe3 | 6628 | } |
d291dd49 | 6629 | } |
71dfc51f | 6630 | |
a3f97cbb | 6631 | /* Output the terminator words. */ |
2e4b9b8c RH |
6632 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); |
6633 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
a3f97cbb JW |
6634 | } |
6635 | ||
a20612aa RH |
6636 | /* Add a new entry to .debug_ranges. Return the offset at which it |
6637 | was placed. */ | |
6638 | ||
6639 | static unsigned int | |
6640 | add_ranges (block) | |
6641 | tree block; | |
6642 | { | |
6643 | unsigned int in_use = ranges_table_in_use; | |
6644 | ||
6645 | if (in_use == ranges_table_allocated) | |
6646 | { | |
6647 | ranges_table_allocated += RANGES_TABLE_INCREMENT; | |
6648 | ranges_table = (dw_ranges_ref) | |
6649 | xrealloc (ranges_table, (ranges_table_allocated | |
6650 | * sizeof (struct dw_ranges_struct))); | |
6651 | } | |
6652 | ||
6653 | ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0); | |
6654 | ranges_table_in_use = in_use + 1; | |
6655 | ||
6656 | return in_use * 2 * DWARF2_ADDR_SIZE; | |
6657 | } | |
6658 | ||
6659 | static void | |
6660 | output_ranges () | |
6661 | { | |
b3694847 | 6662 | unsigned i; |
83182544 | 6663 | static const char *const start_fmt = "Offset 0x%x"; |
a20612aa RH |
6664 | const char *fmt = start_fmt; |
6665 | ||
2ad9852d | 6666 | for (i = 0; i < ranges_table_in_use; i++) |
a20612aa RH |
6667 | { |
6668 | int block_num = ranges_table[i].block_num; | |
6669 | ||
6670 | if (block_num) | |
6671 | { | |
6672 | char blabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6673 | char elabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6674 | ||
6675 | ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num); | |
6676 | ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num); | |
6677 | ||
6678 | /* If all code is in the text section, then the compilation | |
6679 | unit base address defaults to DW_AT_low_pc, which is the | |
6680 | base of the text section. */ | |
6681 | if (separate_line_info_table_in_use == 0) | |
6682 | { | |
6683 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel, | |
6684 | text_section_label, | |
6685 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
6686 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel, | |
6687 | text_section_label, NULL); | |
6688 | } | |
2ad9852d | 6689 | |
a20612aa RH |
6690 | /* Otherwise, we add a DW_AT_entry_pc attribute to force the |
6691 | compilation unit base address to zero, which allows us to | |
6692 | use absolute addresses, and not worry about whether the | |
6693 | target supports cross-section arithmetic. */ | |
6694 | else | |
6695 | { | |
6696 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel, | |
6697 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
6698 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL); | |
6699 | } | |
6700 | ||
6701 | fmt = NULL; | |
6702 | } | |
6703 | else | |
6704 | { | |
6705 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
6706 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
6707 | fmt = start_fmt; | |
6708 | } | |
6709 | } | |
6710 | } | |
0b34cf1e UD |
6711 | |
6712 | /* Data structure containing information about input files. */ | |
6713 | struct file_info | |
6714 | { | |
6715 | char *path; /* Complete file name. */ | |
6716 | char *fname; /* File name part. */ | |
6717 | int length; /* Length of entire string. */ | |
6718 | int file_idx; /* Index in input file table. */ | |
6719 | int dir_idx; /* Index in directory table. */ | |
6720 | }; | |
6721 | ||
6722 | /* Data structure containing information about directories with source | |
6723 | files. */ | |
6724 | struct dir_info | |
6725 | { | |
6726 | char *path; /* Path including directory name. */ | |
6727 | int length; /* Path length. */ | |
6728 | int prefix; /* Index of directory entry which is a prefix. */ | |
0b34cf1e UD |
6729 | int count; /* Number of files in this directory. */ |
6730 | int dir_idx; /* Index of directory used as base. */ | |
6731 | int used; /* Used in the end? */ | |
6732 | }; | |
6733 | ||
6734 | /* Callback function for file_info comparison. We sort by looking at | |
6735 | the directories in the path. */ | |
356b0698 | 6736 | |
0b34cf1e UD |
6737 | static int |
6738 | file_info_cmp (p1, p2) | |
6739 | const void *p1; | |
6740 | const void *p2; | |
6741 | { | |
6742 | const struct file_info *s1 = p1; | |
6743 | const struct file_info *s2 = p2; | |
6744 | unsigned char *cp1; | |
6745 | unsigned char *cp2; | |
6746 | ||
356b0698 RK |
6747 | /* Take care of file names without directories. We need to make sure that |
6748 | we return consistent values to qsort since some will get confused if | |
6749 | we return the same value when identical operands are passed in opposite | |
6750 | orders. So if neither has a directory, return 0 and otherwise return | |
6751 | 1 or -1 depending on which one has the directory. */ | |
6752 | if ((s1->path == s1->fname || s2->path == s2->fname)) | |
6753 | return (s2->path == s2->fname) - (s1->path == s1->fname); | |
0b34cf1e UD |
6754 | |
6755 | cp1 = (unsigned char *) s1->path; | |
6756 | cp2 = (unsigned char *) s2->path; | |
6757 | ||
6758 | while (1) | |
6759 | { | |
6760 | ++cp1; | |
6761 | ++cp2; | |
356b0698 RK |
6762 | /* Reached the end of the first path? If so, handle like above. */ |
6763 | if ((cp1 == (unsigned char *) s1->fname) | |
6764 | || (cp2 == (unsigned char *) s2->fname)) | |
6765 | return ((cp2 == (unsigned char *) s2->fname) | |
6766 | - (cp1 == (unsigned char *) s1->fname)); | |
0b34cf1e UD |
6767 | |
6768 | /* Character of current path component the same? */ | |
356b0698 | 6769 | else if (*cp1 != *cp2) |
0b34cf1e UD |
6770 | return *cp1 - *cp2; |
6771 | } | |
6772 | } | |
6773 | ||
6774 | /* Output the directory table and the file name table. We try to minimize | |
6775 | the total amount of memory needed. A heuristic is used to avoid large | |
6776 | slowdowns with many input files. */ | |
2ad9852d | 6777 | |
0b34cf1e UD |
6778 | static void |
6779 | output_file_names () | |
6780 | { | |
6781 | struct file_info *files; | |
6782 | struct dir_info *dirs; | |
6783 | int *saved; | |
6784 | int *savehere; | |
6785 | int *backmap; | |
6786 | int ndirs; | |
6787 | int idx_offset; | |
6788 | int i; | |
6789 | int idx; | |
6790 | ||
6791 | /* Allocate the various arrays we need. */ | |
981975b6 | 6792 | files = (struct file_info *) alloca (file_table.in_use |
0b34cf1e | 6793 | * sizeof (struct file_info)); |
981975b6 | 6794 | dirs = (struct dir_info *) alloca (file_table.in_use |
0b34cf1e UD |
6795 | * sizeof (struct dir_info)); |
6796 | ||
6797 | /* Sort the file names. */ | |
2ad9852d | 6798 | for (i = 1; i < (int) file_table.in_use; i++) |
0b34cf1e UD |
6799 | { |
6800 | char *f; | |
6801 | ||
6802 | /* Skip all leading "./". */ | |
981975b6 | 6803 | f = file_table.table[i]; |
0b34cf1e UD |
6804 | while (f[0] == '.' && f[1] == '/') |
6805 | f += 2; | |
6806 | ||
6807 | /* Create a new array entry. */ | |
6808 | files[i].path = f; | |
6809 | files[i].length = strlen (f); | |
6810 | files[i].file_idx = i; | |
6811 | ||
6812 | /* Search for the file name part. */ | |
6813 | f = strrchr (f, '/'); | |
6814 | files[i].fname = f == NULL ? files[i].path : f + 1; | |
6815 | } | |
2ad9852d | 6816 | |
981975b6 | 6817 | qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp); |
0b34cf1e UD |
6818 | |
6819 | /* Find all the different directories used. */ | |
6820 | dirs[0].path = files[1].path; | |
6821 | dirs[0].length = files[1].fname - files[1].path; | |
6822 | dirs[0].prefix = -1; | |
0b34cf1e UD |
6823 | dirs[0].count = 1; |
6824 | dirs[0].dir_idx = 0; | |
6825 | dirs[0].used = 0; | |
6826 | files[1].dir_idx = 0; | |
6827 | ndirs = 1; | |
6828 | ||
2ad9852d | 6829 | for (i = 2; i < (int) file_table.in_use; i++) |
0b34cf1e UD |
6830 | if (files[i].fname - files[i].path == dirs[ndirs - 1].length |
6831 | && memcmp (dirs[ndirs - 1].path, files[i].path, | |
6832 | dirs[ndirs - 1].length) == 0) | |
6833 | { | |
6834 | /* Same directory as last entry. */ | |
6835 | files[i].dir_idx = ndirs - 1; | |
0b34cf1e UD |
6836 | ++dirs[ndirs - 1].count; |
6837 | } | |
6838 | else | |
6839 | { | |
6840 | int j; | |
6841 | ||
6842 | /* This is a new directory. */ | |
6843 | dirs[ndirs].path = files[i].path; | |
6844 | dirs[ndirs].length = files[i].fname - files[i].path; | |
0b34cf1e UD |
6845 | dirs[ndirs].count = 1; |
6846 | dirs[ndirs].dir_idx = ndirs; | |
6847 | dirs[ndirs].used = 0; | |
6848 | files[i].dir_idx = ndirs; | |
6849 | ||
6850 | /* Search for a prefix. */ | |
981975b6 | 6851 | dirs[ndirs].prefix = -1; |
2ad9852d | 6852 | for (j = 0; j < ndirs; j++) |
981975b6 RH |
6853 | if (dirs[j].length < dirs[ndirs].length |
6854 | && dirs[j].length > 1 | |
6855 | && (dirs[ndirs].prefix == -1 | |
6856 | || dirs[j].length > dirs[dirs[ndirs].prefix].length) | |
6857 | && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0) | |
6858 | dirs[ndirs].prefix = j; | |
0b34cf1e UD |
6859 | |
6860 | ++ndirs; | |
6861 | } | |
6862 | ||
2ad9852d RK |
6863 | /* Now to the actual work. We have to find a subset of the directories which |
6864 | allow expressing the file name using references to the directory table | |
6865 | with the least amount of characters. We do not do an exhaustive search | |
6866 | where we would have to check out every combination of every single | |
6867 | possible prefix. Instead we use a heuristic which provides nearly optimal | |
6868 | results in most cases and never is much off. */ | |
0b34cf1e UD |
6869 | saved = (int *) alloca (ndirs * sizeof (int)); |
6870 | savehere = (int *) alloca (ndirs * sizeof (int)); | |
6871 | ||
6872 | memset (saved, '\0', ndirs * sizeof (saved[0])); | |
2ad9852d | 6873 | for (i = 0; i < ndirs; i++) |
0b34cf1e UD |
6874 | { |
6875 | int j; | |
6876 | int total; | |
6877 | ||
2ad9852d RK |
6878 | /* We can always save some space for the current directory. But this |
6879 | does not mean it will be enough to justify adding the directory. */ | |
0b34cf1e UD |
6880 | savehere[i] = dirs[i].length; |
6881 | total = (savehere[i] - saved[i]) * dirs[i].count; | |
6882 | ||
2ad9852d | 6883 | for (j = i + 1; j < ndirs; j++) |
0b34cf1e UD |
6884 | { |
6885 | savehere[j] = 0; | |
0b34cf1e UD |
6886 | if (saved[j] < dirs[i].length) |
6887 | { | |
6888 | /* Determine whether the dirs[i] path is a prefix of the | |
6889 | dirs[j] path. */ | |
6890 | int k; | |
6891 | ||
981975b6 RH |
6892 | k = dirs[j].prefix; |
6893 | while (k != -1 && k != i) | |
6894 | k = dirs[k].prefix; | |
6895 | ||
6896 | if (k == i) | |
6897 | { | |
6898 | /* Yes it is. We can possibly safe some memory but | |
6899 | writing the filenames in dirs[j] relative to | |
6900 | dirs[i]. */ | |
6901 | savehere[j] = dirs[i].length; | |
6902 | total += (savehere[j] - saved[j]) * dirs[j].count; | |
6903 | } | |
0b34cf1e UD |
6904 | } |
6905 | } | |
6906 | ||
6907 | /* Check whether we can safe enough to justify adding the dirs[i] | |
6908 | directory. */ | |
6909 | if (total > dirs[i].length + 1) | |
6910 | { | |
981975b6 | 6911 | /* It's worthwhile adding. */ |
2ad9852d | 6912 | for (j = i; j < ndirs; j++) |
0b34cf1e UD |
6913 | if (savehere[j] > 0) |
6914 | { | |
6915 | /* Remember how much we saved for this directory so far. */ | |
6916 | saved[j] = savehere[j]; | |
6917 | ||
6918 | /* Remember the prefix directory. */ | |
6919 | dirs[j].dir_idx = i; | |
6920 | } | |
6921 | } | |
6922 | } | |
6923 | ||
2ad9852d RK |
6924 | /* We have to emit them in the order they appear in the file_table array |
6925 | since the index is used in the debug info generation. To do this | |
6926 | efficiently we generate a back-mapping of the indices first. */ | |
981975b6 | 6927 | backmap = (int *) alloca (file_table.in_use * sizeof (int)); |
2ad9852d | 6928 | for (i = 1; i < (int) file_table.in_use; i++) |
0b34cf1e UD |
6929 | { |
6930 | backmap[files[i].file_idx] = i; | |
2ad9852d | 6931 | |
0b34cf1e UD |
6932 | /* Mark this directory as used. */ |
6933 | dirs[dirs[files[i].dir_idx].dir_idx].used = 1; | |
6934 | } | |
6935 | ||
2ad9852d RK |
6936 | /* That was it. We are ready to emit the information. First emit the |
6937 | directory name table. We have to make sure the first actually emitted | |
6938 | directory name has index one; zero is reserved for the current working | |
6939 | directory. Make sure we do not confuse these indices with the one for the | |
6940 | constructed table (even though most of the time they are identical). */ | |
0b34cf1e | 6941 | idx = 1; |
e57cabac | 6942 | idx_offset = dirs[0].length > 0 ? 1 : 0; |
2ad9852d | 6943 | for (i = 1 - idx_offset; i < ndirs; i++) |
0b34cf1e UD |
6944 | if (dirs[i].used != 0) |
6945 | { | |
6946 | dirs[i].used = idx++; | |
2e4b9b8c RH |
6947 | dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1, |
6948 | "Directory Entry: 0x%x", dirs[i].used); | |
0b34cf1e | 6949 | } |
2ad9852d | 6950 | |
2e4b9b8c RH |
6951 | dw2_asm_output_data (1, 0, "End directory table"); |
6952 | ||
0b34cf1e UD |
6953 | /* Correct the index for the current working directory entry if it |
6954 | exists. */ | |
6955 | if (idx_offset == 0) | |
6956 | dirs[0].used = 0; | |
0b34cf1e UD |
6957 | |
6958 | /* Now write all the file names. */ | |
2ad9852d | 6959 | for (i = 1; i < (int) file_table.in_use; i++) |
0b34cf1e UD |
6960 | { |
6961 | int file_idx = backmap[i]; | |
6962 | int dir_idx = dirs[files[file_idx].dir_idx].dir_idx; | |
6963 | ||
2e4b9b8c RH |
6964 | dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1, |
6965 | "File Entry: 0x%x", i); | |
0b34cf1e UD |
6966 | |
6967 | /* Include directory index. */ | |
2e4b9b8c | 6968 | dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL); |
0b34cf1e UD |
6969 | |
6970 | /* Modification time. */ | |
2e4b9b8c | 6971 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e UD |
6972 | |
6973 | /* File length in bytes. */ | |
2e4b9b8c | 6974 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e | 6975 | } |
2ad9852d | 6976 | |
2e4b9b8c | 6977 | dw2_asm_output_data (1, 0, "End file name table"); |
0b34cf1e UD |
6978 | } |
6979 | ||
6980 | ||
a3f97cbb | 6981 | /* Output the source line number correspondence information. This |
14a774a9 | 6982 | information goes into the .debug_line section. */ |
71dfc51f | 6983 | |
a3f97cbb JW |
6984 | static void |
6985 | output_line_info () | |
6986 | { | |
981975b6 | 6987 | char l1[20], l2[20], p1[20], p2[20]; |
a3f97cbb JW |
6988 | char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
6989 | char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 SS |
6990 | unsigned opc; |
6991 | unsigned n_op_args; | |
6992 | unsigned long lt_index; | |
6993 | unsigned long current_line; | |
6994 | long line_offset; | |
6995 | long line_delta; | |
6996 | unsigned long current_file; | |
6997 | unsigned long function; | |
71dfc51f | 6998 | |
2e4b9b8c RH |
6999 | ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0); |
7000 | ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0); | |
981975b6 RH |
7001 | ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0); |
7002 | ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0); | |
71dfc51f | 7003 | |
2e4b9b8c RH |
7004 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1, |
7005 | "Length of Source Line Info"); | |
7006 | ASM_OUTPUT_LABEL (asm_out_file, l1); | |
71dfc51f | 7007 | |
2e4b9b8c | 7008 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
981975b6 RH |
7009 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length"); |
7010 | ASM_OUTPUT_LABEL (asm_out_file, p1); | |
71dfc51f | 7011 | |
2e4b9b8c RH |
7012 | dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH, |
7013 | "Minimum Instruction Length"); | |
2e4b9b8c RH |
7014 | dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START, |
7015 | "Default is_stmt_start flag"); | |
2e4b9b8c RH |
7016 | dw2_asm_output_data (1, DWARF_LINE_BASE, |
7017 | "Line Base Value (Special Opcodes)"); | |
2e4b9b8c RH |
7018 | dw2_asm_output_data (1, DWARF_LINE_RANGE, |
7019 | "Line Range Value (Special Opcodes)"); | |
2e4b9b8c RH |
7020 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE, |
7021 | "Special Opcode Base"); | |
71dfc51f | 7022 | |
2ad9852d | 7023 | for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++) |
a3f97cbb JW |
7024 | { |
7025 | switch (opc) | |
7026 | { | |
7027 | case DW_LNS_advance_pc: | |
7028 | case DW_LNS_advance_line: | |
7029 | case DW_LNS_set_file: | |
7030 | case DW_LNS_set_column: | |
7031 | case DW_LNS_fixed_advance_pc: | |
7032 | n_op_args = 1; | |
7033 | break; | |
7034 | default: | |
7035 | n_op_args = 0; | |
7036 | break; | |
7037 | } | |
2e4b9b8c RH |
7038 | |
7039 | dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args", | |
7040 | opc, n_op_args); | |
a3f97cbb | 7041 | } |
71dfc51f | 7042 | |
0b34cf1e UD |
7043 | /* Write out the information about the files we use. */ |
7044 | output_file_names (); | |
981975b6 | 7045 | ASM_OUTPUT_LABEL (asm_out_file, p2); |
a3f97cbb | 7046 | |
2f22d404 JM |
7047 | /* We used to set the address register to the first location in the text |
7048 | section here, but that didn't accomplish anything since we already | |
7049 | have a line note for the opening brace of the first function. */ | |
a3f97cbb JW |
7050 | |
7051 | /* Generate the line number to PC correspondence table, encoded as | |
7052 | a series of state machine operations. */ | |
7053 | current_file = 1; | |
7054 | current_line = 1; | |
8b790721 | 7055 | strcpy (prev_line_label, text_section_label); |
a3f97cbb JW |
7056 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) |
7057 | { | |
b3694847 | 7058 | dw_line_info_ref line_info = &line_info_table[lt_index]; |
2f22d404 | 7059 | |
10a11b75 JM |
7060 | #if 0 |
7061 | /* Disable this optimization for now; GDB wants to see two line notes | |
7062 | at the beginning of a function so it can find the end of the | |
7063 | prologue. */ | |
7064 | ||
2f22d404 JM |
7065 | /* Don't emit anything for redundant notes. Just updating the |
7066 | address doesn't accomplish anything, because we already assume | |
7067 | that anything after the last address is this line. */ | |
7068 | if (line_info->dw_line_num == current_line | |
7069 | && line_info->dw_file_num == current_file) | |
7070 | continue; | |
10a11b75 | 7071 | #endif |
71dfc51f | 7072 | |
2e4b9b8c RH |
7073 | /* Emit debug info for the address of the current line. |
7074 | ||
7075 | Unfortunately, we have little choice here currently, and must always | |
2ad9852d | 7076 | use the most general form. GCC does not know the address delta |
2e4b9b8c RH |
7077 | itself, so we can't use DW_LNS_advance_pc. Many ports do have length |
7078 | attributes which will give an upper bound on the address range. We | |
7079 | could perhaps use length attributes to determine when it is safe to | |
7080 | use DW_LNS_fixed_advance_pc. */ | |
7081 | ||
5c90448c | 7082 | ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index); |
f19a6894 JW |
7083 | if (0) |
7084 | { | |
7085 | /* This can handle deltas up to 0xffff. This takes 3 bytes. */ | |
2e4b9b8c RH |
7086 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7087 | "DW_LNS_fixed_advance_pc"); | |
7088 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7089 | } |
7090 | else | |
7091 | { | |
a1a4189d JB |
7092 | /* This can handle any delta. This takes |
7093 | 4+DWARF2_ADDR_SIZE bytes. */ | |
2e4b9b8c RH |
7094 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7095 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7096 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7097 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7098 | } |
2ad9852d | 7099 | |
f19a6894 JW |
7100 | strcpy (prev_line_label, line_label); |
7101 | ||
7102 | /* Emit debug info for the source file of the current line, if | |
7103 | different from the previous line. */ | |
a3f97cbb JW |
7104 | if (line_info->dw_file_num != current_file) |
7105 | { | |
7106 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
7107 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
7108 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
981975b6 | 7109 | file_table.table[current_file]); |
a3f97cbb | 7110 | } |
71dfc51f | 7111 | |
f19a6894 JW |
7112 | /* Emit debug info for the current line number, choosing the encoding |
7113 | that uses the least amount of space. */ | |
2f22d404 | 7114 | if (line_info->dw_line_num != current_line) |
a3f97cbb | 7115 | { |
2f22d404 JM |
7116 | line_offset = line_info->dw_line_num - current_line; |
7117 | line_delta = line_offset - DWARF_LINE_BASE; | |
7118 | current_line = line_info->dw_line_num; | |
7119 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
2ad9852d RK |
7120 | /* This can handle deltas from -10 to 234, using the current |
7121 | definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This | |
7122 | takes 1 byte. */ | |
7123 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, | |
7124 | "line %lu", current_line); | |
2f22d404 JM |
7125 | else |
7126 | { | |
7127 | /* This can handle any delta. This takes at least 4 bytes, | |
7128 | depending on the value being encoded. */ | |
2e4b9b8c RH |
7129 | dw2_asm_output_data (1, DW_LNS_advance_line, |
7130 | "advance to line %lu", current_line); | |
7131 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
7132 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
2f22d404 | 7133 | } |
a94dbf2c JM |
7134 | } |
7135 | else | |
2ad9852d RK |
7136 | /* We still need to start a new row, so output a copy insn. */ |
7137 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
a3f97cbb JW |
7138 | } |
7139 | ||
f19a6894 JW |
7140 | /* Emit debug info for the address of the end of the function. */ |
7141 | if (0) | |
7142 | { | |
2e4b9b8c RH |
7143 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7144 | "DW_LNS_fixed_advance_pc"); | |
7145 | dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL); | |
f19a6894 JW |
7146 | } |
7147 | else | |
7148 | { | |
2e4b9b8c RH |
7149 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7150 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7151 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7152 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL); |
f19a6894 | 7153 | } |
bdb669cb | 7154 | |
2e4b9b8c RH |
7155 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
7156 | dw2_asm_output_data_uleb128 (1, NULL); | |
7157 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
7158 | |
7159 | function = 0; | |
7160 | current_file = 1; | |
7161 | current_line = 1; | |
556273e0 | 7162 | for (lt_index = 0; lt_index < separate_line_info_table_in_use;) |
e90b62db | 7163 | { |
b3694847 | 7164 | dw_separate_line_info_ref line_info |
e90b62db | 7165 | = &separate_line_info_table[lt_index]; |
71dfc51f | 7166 | |
10a11b75 | 7167 | #if 0 |
2f22d404 JM |
7168 | /* Don't emit anything for redundant notes. */ |
7169 | if (line_info->dw_line_num == current_line | |
7170 | && line_info->dw_file_num == current_file | |
7171 | && line_info->function == function) | |
7172 | goto cont; | |
10a11b75 | 7173 | #endif |
2f22d404 | 7174 | |
f19a6894 JW |
7175 | /* Emit debug info for the address of the current line. If this is |
7176 | a new function, or the first line of a function, then we need | |
7177 | to handle it differently. */ | |
5c90448c JM |
7178 | ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL, |
7179 | lt_index); | |
e90b62db JM |
7180 | if (function != line_info->function) |
7181 | { | |
7182 | function = line_info->function; | |
71dfc51f | 7183 | |
e90b62db | 7184 | /* Set the address register to the first line in the function */ |
2e4b9b8c RH |
7185 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7186 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7187 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7188 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
e90b62db JM |
7189 | } |
7190 | else | |
7191 | { | |
f19a6894 JW |
7192 | /* ??? See the DW_LNS_advance_pc comment above. */ |
7193 | if (0) | |
7194 | { | |
2e4b9b8c RH |
7195 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7196 | "DW_LNS_fixed_advance_pc"); | |
7197 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7198 | } |
7199 | else | |
7200 | { | |
2e4b9b8c RH |
7201 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7202 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7203 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7204 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7205 | } |
e90b62db | 7206 | } |
2ad9852d | 7207 | |
f19a6894 | 7208 | strcpy (prev_line_label, line_label); |
71dfc51f | 7209 | |
f19a6894 JW |
7210 | /* Emit debug info for the source file of the current line, if |
7211 | different from the previous line. */ | |
e90b62db JM |
7212 | if (line_info->dw_file_num != current_file) |
7213 | { | |
7214 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
7215 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
7216 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
981975b6 | 7217 | file_table.table[current_file]); |
e90b62db | 7218 | } |
71dfc51f | 7219 | |
f19a6894 JW |
7220 | /* Emit debug info for the current line number, choosing the encoding |
7221 | that uses the least amount of space. */ | |
e90b62db JM |
7222 | if (line_info->dw_line_num != current_line) |
7223 | { | |
7224 | line_offset = line_info->dw_line_num - current_line; | |
7225 | line_delta = line_offset - DWARF_LINE_BASE; | |
7226 | current_line = line_info->dw_line_num; | |
7227 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
2e4b9b8c RH |
7228 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, |
7229 | "line %lu", current_line); | |
e90b62db JM |
7230 | else |
7231 | { | |
2e4b9b8c RH |
7232 | dw2_asm_output_data (1, DW_LNS_advance_line, |
7233 | "advance to line %lu", current_line); | |
7234 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
7235 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
e90b62db JM |
7236 | } |
7237 | } | |
2f22d404 | 7238 | else |
2e4b9b8c | 7239 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); |
71dfc51f | 7240 | |
10a11b75 | 7241 | #if 0 |
2f22d404 | 7242 | cont: |
10a11b75 | 7243 | #endif |
2ad9852d RK |
7244 | |
7245 | lt_index++; | |
e90b62db JM |
7246 | |
7247 | /* If we're done with a function, end its sequence. */ | |
7248 | if (lt_index == separate_line_info_table_in_use | |
7249 | || separate_line_info_table[lt_index].function != function) | |
7250 | { | |
7251 | current_file = 1; | |
7252 | current_line = 1; | |
71dfc51f | 7253 | |
f19a6894 | 7254 | /* Emit debug info for the address of the end of the function. */ |
5c90448c | 7255 | ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function); |
f19a6894 JW |
7256 | if (0) |
7257 | { | |
2e4b9b8c RH |
7258 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7259 | "DW_LNS_fixed_advance_pc"); | |
7260 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7261 | } |
7262 | else | |
7263 | { | |
2e4b9b8c RH |
7264 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7265 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7266 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7267 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7268 | } |
e90b62db JM |
7269 | |
7270 | /* Output the marker for the end of this sequence. */ | |
2e4b9b8c RH |
7271 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
7272 | dw2_asm_output_data_uleb128 (1, NULL); | |
7273 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
7274 | } |
7275 | } | |
f19f17e0 JM |
7276 | |
7277 | /* Output the marker for the end of the line number info. */ | |
2e4b9b8c | 7278 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
a3f97cbb JW |
7279 | } |
7280 | \f | |
a3f97cbb JW |
7281 | /* Given a pointer to a tree node for some base type, return a pointer to |
7282 | a DIE that describes the given type. | |
7283 | ||
7284 | This routine must only be called for GCC type nodes that correspond to | |
7285 | Dwarf base (fundamental) types. */ | |
71dfc51f | 7286 | |
a3f97cbb JW |
7287 | static dw_die_ref |
7288 | base_type_die (type) | |
b3694847 | 7289 | tree type; |
a3f97cbb | 7290 | { |
b3694847 SS |
7291 | dw_die_ref base_type_result; |
7292 | const char *type_name; | |
7293 | enum dwarf_type encoding; | |
7294 | tree name = TYPE_NAME (type); | |
a3f97cbb | 7295 | |
2ad9852d | 7296 | if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE) |
a3f97cbb JW |
7297 | return 0; |
7298 | ||
405f63da MM |
7299 | if (name) |
7300 | { | |
7301 | if (TREE_CODE (name) == TYPE_DECL) | |
7302 | name = DECL_NAME (name); | |
7303 | ||
7304 | type_name = IDENTIFIER_POINTER (name); | |
7305 | } | |
7306 | else | |
7307 | type_name = "__unknown__"; | |
a9d38797 | 7308 | |
a3f97cbb JW |
7309 | switch (TREE_CODE (type)) |
7310 | { | |
a3f97cbb | 7311 | case INTEGER_TYPE: |
a9d38797 | 7312 | /* Carefully distinguish the C character types, without messing |
a3f97cbb | 7313 | up if the language is not C. Note that we check only for the names |
556273e0 | 7314 | that contain spaces; other names might occur by coincidence in other |
a3f97cbb | 7315 | languages. */ |
a9d38797 JM |
7316 | if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE |
7317 | && (type == char_type_node | |
7318 | || ! strcmp (type_name, "signed char") | |
7319 | || ! strcmp (type_name, "unsigned char")))) | |
a3f97cbb | 7320 | { |
a9d38797 JM |
7321 | if (TREE_UNSIGNED (type)) |
7322 | encoding = DW_ATE_unsigned; | |
7323 | else | |
7324 | encoding = DW_ATE_signed; | |
7325 | break; | |
a3f97cbb | 7326 | } |
556273e0 | 7327 | /* else fall through. */ |
a3f97cbb | 7328 | |
a9d38797 JM |
7329 | case CHAR_TYPE: |
7330 | /* GNU Pascal/Ada CHAR type. Not used in C. */ | |
7331 | if (TREE_UNSIGNED (type)) | |
7332 | encoding = DW_ATE_unsigned_char; | |
7333 | else | |
7334 | encoding = DW_ATE_signed_char; | |
a3f97cbb JW |
7335 | break; |
7336 | ||
7337 | case REAL_TYPE: | |
a9d38797 | 7338 | encoding = DW_ATE_float; |
a3f97cbb JW |
7339 | break; |
7340 | ||
405f63da MM |
7341 | /* Dwarf2 doesn't know anything about complex ints, so use |
7342 | a user defined type for it. */ | |
a3f97cbb | 7343 | case COMPLEX_TYPE: |
405f63da MM |
7344 | if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE) |
7345 | encoding = DW_ATE_complex_float; | |
7346 | else | |
7347 | encoding = DW_ATE_lo_user; | |
a3f97cbb JW |
7348 | break; |
7349 | ||
7350 | case BOOLEAN_TYPE: | |
a9d38797 JM |
7351 | /* GNU FORTRAN/Ada/C++ BOOLEAN type. */ |
7352 | encoding = DW_ATE_boolean; | |
a3f97cbb JW |
7353 | break; |
7354 | ||
7355 | default: | |
2ad9852d RK |
7356 | /* No other TREE_CODEs are Dwarf fundamental types. */ |
7357 | abort (); | |
a3f97cbb JW |
7358 | } |
7359 | ||
54ba1f0d | 7360 | base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type); |
14a774a9 RK |
7361 | if (demangle_name_func) |
7362 | type_name = (*demangle_name_func) (type_name); | |
7363 | ||
a9d38797 JM |
7364 | add_AT_string (base_type_result, DW_AT_name, type_name); |
7365 | add_AT_unsigned (base_type_result, DW_AT_byte_size, | |
4e5a8d7b | 7366 | int_size_in_bytes (type)); |
a9d38797 | 7367 | add_AT_unsigned (base_type_result, DW_AT_encoding, encoding); |
a3f97cbb JW |
7368 | |
7369 | return base_type_result; | |
7370 | } | |
7371 | ||
7372 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to | |
7373 | the Dwarf "root" type for the given input type. The Dwarf "root" type of | |
7374 | a given type is generally the same as the given type, except that if the | |
7375 | given type is a pointer or reference type, then the root type of the given | |
7376 | type is the root type of the "basis" type for the pointer or reference | |
7377 | type. (This definition of the "root" type is recursive.) Also, the root | |
7378 | type of a `const' qualified type or a `volatile' qualified type is the | |
7379 | root type of the given type without the qualifiers. */ | |
71dfc51f | 7380 | |
a3f97cbb JW |
7381 | static tree |
7382 | root_type (type) | |
b3694847 | 7383 | tree type; |
a3f97cbb JW |
7384 | { |
7385 | if (TREE_CODE (type) == ERROR_MARK) | |
7386 | return error_mark_node; | |
7387 | ||
7388 | switch (TREE_CODE (type)) | |
7389 | { | |
7390 | case ERROR_MARK: | |
7391 | return error_mark_node; | |
7392 | ||
7393 | case POINTER_TYPE: | |
7394 | case REFERENCE_TYPE: | |
7395 | return type_main_variant (root_type (TREE_TYPE (type))); | |
7396 | ||
7397 | default: | |
7398 | return type_main_variant (type); | |
7399 | } | |
7400 | } | |
7401 | ||
7402 | /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the | |
7403 | given input type is a Dwarf "fundamental" type. Otherwise return null. */ | |
71dfc51f RK |
7404 | |
7405 | static inline int | |
a3f97cbb | 7406 | is_base_type (type) |
b3694847 | 7407 | tree type; |
a3f97cbb JW |
7408 | { |
7409 | switch (TREE_CODE (type)) | |
7410 | { | |
7411 | case ERROR_MARK: | |
7412 | case VOID_TYPE: | |
7413 | case INTEGER_TYPE: | |
7414 | case REAL_TYPE: | |
7415 | case COMPLEX_TYPE: | |
7416 | case BOOLEAN_TYPE: | |
7417 | case CHAR_TYPE: | |
7418 | return 1; | |
7419 | ||
7420 | case SET_TYPE: | |
7421 | case ARRAY_TYPE: | |
7422 | case RECORD_TYPE: | |
7423 | case UNION_TYPE: | |
7424 | case QUAL_UNION_TYPE: | |
7425 | case ENUMERAL_TYPE: | |
7426 | case FUNCTION_TYPE: | |
7427 | case METHOD_TYPE: | |
7428 | case POINTER_TYPE: | |
7429 | case REFERENCE_TYPE: | |
7430 | case FILE_TYPE: | |
7431 | case OFFSET_TYPE: | |
7432 | case LANG_TYPE: | |
604bb87d | 7433 | case VECTOR_TYPE: |
a3f97cbb JW |
7434 | return 0; |
7435 | ||
7436 | default: | |
7437 | abort (); | |
7438 | } | |
71dfc51f | 7439 | |
a3f97cbb JW |
7440 | return 0; |
7441 | } | |
7442 | ||
7443 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging | |
7444 | entry that chains various modifiers in front of the given type. */ | |
71dfc51f | 7445 | |
a3f97cbb JW |
7446 | static dw_die_ref |
7447 | modified_type_die (type, is_const_type, is_volatile_type, context_die) | |
b3694847 SS |
7448 | tree type; |
7449 | int is_const_type; | |
7450 | int is_volatile_type; | |
7451 | dw_die_ref context_die; | |
a3f97cbb | 7452 | { |
b3694847 SS |
7453 | enum tree_code code = TREE_CODE (type); |
7454 | dw_die_ref mod_type_die = NULL; | |
7455 | dw_die_ref sub_die = NULL; | |
7456 | tree item_type = NULL; | |
a3f97cbb JW |
7457 | |
7458 | if (code != ERROR_MARK) | |
7459 | { | |
5101b304 MM |
7460 | tree qualified_type; |
7461 | ||
7462 | /* See if we already have the appropriately qualified variant of | |
7463 | this type. */ | |
7464 | qualified_type | |
7465 | = get_qualified_type (type, | |
7466 | ((is_const_type ? TYPE_QUAL_CONST : 0) | |
7467 | | (is_volatile_type | |
7468 | ? TYPE_QUAL_VOLATILE : 0))); | |
2ad9852d | 7469 | |
5101b304 MM |
7470 | /* If we do, then we can just use its DIE, if it exists. */ |
7471 | if (qualified_type) | |
7472 | { | |
7473 | mod_type_die = lookup_type_die (qualified_type); | |
7474 | if (mod_type_die) | |
7475 | return mod_type_die; | |
7476 | } | |
bdb669cb | 7477 | |
556273e0 | 7478 | /* Handle C typedef types. */ |
5101b304 MM |
7479 | if (qualified_type && TYPE_NAME (qualified_type) |
7480 | && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL | |
7481 | && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type))) | |
a94dbf2c | 7482 | { |
5101b304 MM |
7483 | tree type_name = TYPE_NAME (qualified_type); |
7484 | tree dtype = TREE_TYPE (type_name); | |
2ad9852d | 7485 | |
5101b304 | 7486 | if (qualified_type == dtype) |
a94dbf2c JM |
7487 | { |
7488 | /* For a named type, use the typedef. */ | |
5101b304 MM |
7489 | gen_type_die (qualified_type, context_die); |
7490 | mod_type_die = lookup_type_die (qualified_type); | |
a94dbf2c JM |
7491 | } |
7492 | else if (is_const_type < TYPE_READONLY (dtype) | |
7493 | || is_volatile_type < TYPE_VOLATILE (dtype)) | |
7494 | /* cv-unqualified version of named type. Just use the unnamed | |
7495 | type to which it refers. */ | |
71dfc51f | 7496 | mod_type_die |
5101b304 | 7497 | = modified_type_die (DECL_ORIGINAL_TYPE (type_name), |
71dfc51f RK |
7498 | is_const_type, is_volatile_type, |
7499 | context_die); | |
2ad9852d | 7500 | |
71dfc51f | 7501 | /* Else cv-qualified version of named type; fall through. */ |
a94dbf2c JM |
7502 | } |
7503 | ||
7504 | if (mod_type_die) | |
556273e0 KH |
7505 | /* OK. */ |
7506 | ; | |
a94dbf2c | 7507 | else if (is_const_type) |
a3f97cbb | 7508 | { |
54ba1f0d | 7509 | mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type); |
a9d38797 | 7510 | sub_die = modified_type_die (type, 0, is_volatile_type, context_die); |
a3f97cbb JW |
7511 | } |
7512 | else if (is_volatile_type) | |
7513 | { | |
54ba1f0d | 7514 | mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type); |
a9d38797 | 7515 | sub_die = modified_type_die (type, 0, 0, context_die); |
a3f97cbb JW |
7516 | } |
7517 | else if (code == POINTER_TYPE) | |
7518 | { | |
54ba1f0d | 7519 | mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type); |
a3f97cbb | 7520 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 7521 | #if 0 |
a3f97cbb | 7522 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
61b32c02 | 7523 | #endif |
a3f97cbb | 7524 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
7525 | } |
7526 | else if (code == REFERENCE_TYPE) | |
7527 | { | |
54ba1f0d | 7528 | mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type); |
a3f97cbb | 7529 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 7530 | #if 0 |
a3f97cbb | 7531 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
556273e0 | 7532 | #endif |
a3f97cbb | 7533 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
7534 | } |
7535 | else if (is_base_type (type)) | |
71dfc51f | 7536 | mod_type_die = base_type_die (type); |
a3f97cbb JW |
7537 | else |
7538 | { | |
4b674448 JM |
7539 | gen_type_die (type, context_die); |
7540 | ||
a3f97cbb JW |
7541 | /* We have to get the type_main_variant here (and pass that to the |
7542 | `lookup_type_die' routine) because the ..._TYPE node we have | |
7543 | might simply be a *copy* of some original type node (where the | |
7544 | copy was created to help us keep track of typedef names) and | |
7545 | that copy might have a different TYPE_UID from the original | |
a94dbf2c | 7546 | ..._TYPE node. */ |
a3f97cbb | 7547 | mod_type_die = lookup_type_die (type_main_variant (type)); |
3a88cbd1 JL |
7548 | if (mod_type_die == NULL) |
7549 | abort (); | |
a3f97cbb | 7550 | } |
3d2999ba MK |
7551 | |
7552 | /* We want to equate the qualified type to the die below. */ | |
7553 | if (qualified_type) | |
7554 | type = qualified_type; | |
a3f97cbb | 7555 | } |
71dfc51f | 7556 | |
dfcf9891 JW |
7557 | equate_type_number_to_die (type, mod_type_die); |
7558 | if (item_type) | |
71dfc51f RK |
7559 | /* We must do this after the equate_type_number_to_die call, in case |
7560 | this is a recursive type. This ensures that the modified_type_die | |
7561 | recursion will terminate even if the type is recursive. Recursive | |
7562 | types are possible in Ada. */ | |
7563 | sub_die = modified_type_die (item_type, | |
7564 | TYPE_READONLY (item_type), | |
7565 | TYPE_VOLATILE (item_type), | |
7566 | context_die); | |
7567 | ||
a3f97cbb | 7568 | if (sub_die != NULL) |
71dfc51f RK |
7569 | add_AT_die_ref (mod_type_die, DW_AT_type, sub_die); |
7570 | ||
a3f97cbb JW |
7571 | return mod_type_die; |
7572 | } | |
7573 | ||
a3f97cbb | 7574 | /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is |
6d2f8887 | 7575 | an enumerated type. */ |
71dfc51f RK |
7576 | |
7577 | static inline int | |
a3f97cbb | 7578 | type_is_enum (type) |
b3694847 | 7579 | tree type; |
a3f97cbb JW |
7580 | { |
7581 | return TREE_CODE (type) == ENUMERAL_TYPE; | |
7582 | } | |
7583 | ||
7d9d8943 AM |
7584 | /* Return the register number described by a given RTL node. */ |
7585 | ||
7586 | static unsigned int | |
7587 | reg_number (rtl) | |
b3694847 | 7588 | rtx rtl; |
7d9d8943 | 7589 | { |
b3694847 | 7590 | unsigned regno = REGNO (rtl); |
7d9d8943 AM |
7591 | |
7592 | if (regno >= FIRST_PSEUDO_REGISTER) | |
e7af1d45 | 7593 | abort (); |
7d9d8943 | 7594 | |
e7af1d45 | 7595 | return DBX_REGISTER_NUMBER (regno); |
7d9d8943 AM |
7596 | } |
7597 | ||
e7af1d45 RK |
7598 | /* Return a location descriptor that designates a machine register or |
7599 | zero if there is no such. */ | |
71dfc51f | 7600 | |
a3f97cbb JW |
7601 | static dw_loc_descr_ref |
7602 | reg_loc_descriptor (rtl) | |
b3694847 | 7603 | rtx rtl; |
a3f97cbb | 7604 | { |
b3694847 | 7605 | dw_loc_descr_ref loc_result = NULL; |
e7af1d45 | 7606 | unsigned reg; |
71dfc51f | 7607 | |
e7af1d45 RK |
7608 | if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER) |
7609 | return 0; | |
7610 | ||
7611 | reg = reg_number (rtl); | |
85066503 | 7612 | if (reg <= 31) |
71dfc51f | 7613 | loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0); |
a3f97cbb | 7614 | else |
71dfc51f RK |
7615 | loc_result = new_loc_descr (DW_OP_regx, reg, 0); |
7616 | ||
a3f97cbb JW |
7617 | return loc_result; |
7618 | } | |
7619 | ||
d8041cc8 RH |
7620 | /* Return a location descriptor that designates a constant. */ |
7621 | ||
7622 | static dw_loc_descr_ref | |
7623 | int_loc_descriptor (i) | |
7624 | HOST_WIDE_INT i; | |
7625 | { | |
7626 | enum dwarf_location_atom op; | |
7627 | ||
7628 | /* Pick the smallest representation of a constant, rather than just | |
7629 | defaulting to the LEB encoding. */ | |
7630 | if (i >= 0) | |
7631 | { | |
7632 | if (i <= 31) | |
7633 | op = DW_OP_lit0 + i; | |
7634 | else if (i <= 0xff) | |
7635 | op = DW_OP_const1u; | |
7636 | else if (i <= 0xffff) | |
7637 | op = DW_OP_const2u; | |
7638 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
7639 | || i <= 0xffffffff) | |
7640 | op = DW_OP_const4u; | |
7641 | else | |
7642 | op = DW_OP_constu; | |
7643 | } | |
7644 | else | |
7645 | { | |
7646 | if (i >= -0x80) | |
7647 | op = DW_OP_const1s; | |
7648 | else if (i >= -0x8000) | |
7649 | op = DW_OP_const2s; | |
7650 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
7651 | || i >= -0x80000000) | |
7652 | op = DW_OP_const4s; | |
7653 | else | |
7654 | op = DW_OP_consts; | |
7655 | } | |
7656 | ||
7657 | return new_loc_descr (op, i, 0); | |
7658 | } | |
7659 | ||
a3f97cbb | 7660 | /* Return a location descriptor that designates a base+offset location. */ |
71dfc51f | 7661 | |
a3f97cbb JW |
7662 | static dw_loc_descr_ref |
7663 | based_loc_descr (reg, offset) | |
7664 | unsigned reg; | |
7665 | long int offset; | |
7666 | { | |
b3694847 | 7667 | dw_loc_descr_ref loc_result; |
810429b7 JM |
7668 | /* For the "frame base", we use the frame pointer or stack pointer |
7669 | registers, since the RTL for local variables is relative to one of | |
7670 | them. */ | |
b3694847 SS |
7671 | unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed |
7672 | ? HARD_FRAME_POINTER_REGNUM | |
7673 | : STACK_POINTER_REGNUM); | |
71dfc51f | 7674 | |
a3f97cbb | 7675 | if (reg == fp_reg) |
71dfc51f | 7676 | loc_result = new_loc_descr (DW_OP_fbreg, offset, 0); |
85066503 | 7677 | else if (reg <= 31) |
71dfc51f | 7678 | loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0); |
a3f97cbb | 7679 | else |
71dfc51f RK |
7680 | loc_result = new_loc_descr (DW_OP_bregx, reg, offset); |
7681 | ||
a3f97cbb JW |
7682 | return loc_result; |
7683 | } | |
7684 | ||
7685 | /* Return true if this RTL expression describes a base+offset calculation. */ | |
71dfc51f RK |
7686 | |
7687 | static inline int | |
a3f97cbb | 7688 | is_based_loc (rtl) |
b3694847 | 7689 | rtx rtl; |
a3f97cbb | 7690 | { |
173bf5be KH |
7691 | return (GET_CODE (rtl) == PLUS |
7692 | && ((GET_CODE (XEXP (rtl, 0)) == REG | |
7693 | && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER | |
7694 | && GET_CODE (XEXP (rtl, 1)) == CONST_INT))); | |
a3f97cbb JW |
7695 | } |
7696 | ||
7697 | /* The following routine converts the RTL for a variable or parameter | |
7698 | (resident in memory) into an equivalent Dwarf representation of a | |
7699 | mechanism for getting the address of that same variable onto the top of a | |
7700 | hypothetical "address evaluation" stack. | |
71dfc51f | 7701 | |
a3f97cbb JW |
7702 | When creating memory location descriptors, we are effectively transforming |
7703 | the RTL for a memory-resident object into its Dwarf postfix expression | |
7704 | equivalent. This routine recursively descends an RTL tree, turning | |
e60d4d7b JL |
7705 | it into Dwarf postfix code as it goes. |
7706 | ||
7707 | MODE is the mode of the memory reference, needed to handle some | |
e7af1d45 RK |
7708 | autoincrement addressing modes. |
7709 | ||
7710 | Return 0 if we can't represent the location. */ | |
71dfc51f | 7711 | |
a3f97cbb | 7712 | static dw_loc_descr_ref |
e60d4d7b | 7713 | mem_loc_descriptor (rtl, mode) |
b3694847 | 7714 | rtx rtl; |
e60d4d7b | 7715 | enum machine_mode mode; |
a3f97cbb JW |
7716 | { |
7717 | dw_loc_descr_ref mem_loc_result = NULL; | |
e7af1d45 | 7718 | |
556273e0 | 7719 | /* Note that for a dynamically sized array, the location we will generate a |
a3f97cbb JW |
7720 | description of here will be the lowest numbered location which is |
7721 | actually within the array. That's *not* necessarily the same as the | |
7722 | zeroth element of the array. */ | |
71dfc51f | 7723 | |
1865dbb5 JM |
7724 | #ifdef ASM_SIMPLIFY_DWARF_ADDR |
7725 | rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); | |
7726 | #endif | |
7727 | ||
a3f97cbb JW |
7728 | switch (GET_CODE (rtl)) |
7729 | { | |
e60d4d7b JL |
7730 | case POST_INC: |
7731 | case POST_DEC: | |
e2134eea | 7732 | case POST_MODIFY: |
e60d4d7b JL |
7733 | /* POST_INC and POST_DEC can be handled just like a SUBREG. So we |
7734 | just fall into the SUBREG code. */ | |
7735 | ||
2ad9852d | 7736 | /* ... fall through ... */ |
e60d4d7b | 7737 | |
a3f97cbb JW |
7738 | case SUBREG: |
7739 | /* The case of a subreg may arise when we have a local (register) | |
7740 | variable or a formal (register) parameter which doesn't quite fill | |
7741 | up an entire register. For now, just assume that it is | |
7742 | legitimate to make the Dwarf info refer to the whole register which | |
7743 | contains the given subreg. */ | |
ddef6bc7 | 7744 | rtl = SUBREG_REG (rtl); |
71dfc51f | 7745 | |
2ad9852d | 7746 | /* ... fall through ... */ |
a3f97cbb JW |
7747 | |
7748 | case REG: | |
7749 | /* Whenever a register number forms a part of the description of the | |
7750 | method for calculating the (dynamic) address of a memory resident | |
556273e0 | 7751 | object, DWARF rules require the register number be referred to as |
a3f97cbb JW |
7752 | a "base register". This distinction is not based in any way upon |
7753 | what category of register the hardware believes the given register | |
7754 | belongs to. This is strictly DWARF terminology we're dealing with | |
7755 | here. Note that in cases where the location of a memory-resident | |
7756 | data object could be expressed as: OP_ADD (OP_BASEREG (basereg), | |
7757 | OP_CONST (0)) the actual DWARF location descriptor that we generate | |
7758 | may just be OP_BASEREG (basereg). This may look deceptively like | |
7759 | the object in question was allocated to a register (rather than in | |
7760 | memory) so DWARF consumers need to be aware of the subtle | |
7761 | distinction between OP_REG and OP_BASEREG. */ | |
e7af1d45 RK |
7762 | if (REGNO (rtl) < FIRST_PSEUDO_REGISTER) |
7763 | mem_loc_result = based_loc_descr (reg_number (rtl), 0); | |
a3f97cbb JW |
7764 | break; |
7765 | ||
7766 | case MEM: | |
f7d2b0ed | 7767 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
e7af1d45 RK |
7768 | if (mem_loc_result != 0) |
7769 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0)); | |
a3f97cbb JW |
7770 | break; |
7771 | ||
d8041cc8 RH |
7772 | case LABEL_REF: |
7773 | /* Some ports can transform a symbol ref into a label ref, because | |
368f4cd6 NC |
7774 | the symbol ref is too far away and has to be dumped into a constant |
7775 | pool. */ | |
a3f97cbb JW |
7776 | case CONST: |
7777 | case SYMBOL_REF: | |
6331d1c1 | 7778 | /* Alternatively, the symbol in the constant pool might be referenced |
c6f9b9a1 | 7779 | by a different symbol. */ |
2ad9852d | 7780 | if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl)) |
79cdfa4b TM |
7781 | { |
7782 | rtx tmp = get_pool_constant (rtl); | |
2ad9852d | 7783 | |
6331d1c1 | 7784 | if (GET_CODE (tmp) == SYMBOL_REF) |
79cdfa4b TM |
7785 | rtl = tmp; |
7786 | } | |
7787 | ||
a3f97cbb JW |
7788 | mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0); |
7789 | mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
c470afad RK |
7790 | mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl; |
7791 | VARRAY_PUSH_RTX (used_rtx_varray, rtl); | |
a3f97cbb JW |
7792 | break; |
7793 | ||
e2134eea JH |
7794 | case PRE_MODIFY: |
7795 | /* Extract the PLUS expression nested inside and fall into | |
0407c02b | 7796 | PLUS code below. */ |
e2134eea JH |
7797 | rtl = XEXP (rtl, 1); |
7798 | goto plus; | |
7799 | ||
e60d4d7b JL |
7800 | case PRE_INC: |
7801 | case PRE_DEC: | |
7802 | /* Turn these into a PLUS expression and fall into the PLUS code | |
7803 | below. */ | |
7804 | rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0), | |
7805 | GEN_INT (GET_CODE (rtl) == PRE_INC | |
556273e0 KH |
7806 | ? GET_MODE_UNIT_SIZE (mode) |
7807 | : -GET_MODE_UNIT_SIZE (mode))); | |
7808 | ||
2ad9852d | 7809 | /* ... fall through ... */ |
e60d4d7b | 7810 | |
a3f97cbb | 7811 | case PLUS: |
e2134eea | 7812 | plus: |
a3f97cbb | 7813 | if (is_based_loc (rtl)) |
71dfc51f RK |
7814 | mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)), |
7815 | INTVAL (XEXP (rtl, 1))); | |
a3f97cbb JW |
7816 | else |
7817 | { | |
d8041cc8 | 7818 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode); |
e7af1d45 RK |
7819 | if (mem_loc_result == 0) |
7820 | break; | |
d8041cc8 RH |
7821 | |
7822 | if (GET_CODE (XEXP (rtl, 1)) == CONST_INT | |
7823 | && INTVAL (XEXP (rtl, 1)) >= 0) | |
e7af1d45 RK |
7824 | add_loc_descr (&mem_loc_result, |
7825 | new_loc_descr (DW_OP_plus_uconst, | |
7826 | INTVAL (XEXP (rtl, 1)), 0)); | |
d8041cc8 RH |
7827 | else |
7828 | { | |
7829 | add_loc_descr (&mem_loc_result, | |
7830 | mem_loc_descriptor (XEXP (rtl, 1), mode)); | |
7831 | add_loc_descr (&mem_loc_result, | |
7832 | new_loc_descr (DW_OP_plus, 0, 0)); | |
7833 | } | |
a3f97cbb JW |
7834 | } |
7835 | break; | |
7836 | ||
dd2478ae | 7837 | case MULT: |
e7af1d45 RK |
7838 | { |
7839 | /* If a pseudo-reg is optimized away, it is possible for it to | |
7840 | be replaced with a MEM containing a multiply. */ | |
7841 | dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode); | |
7842 | dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode); | |
7843 | ||
7844 | if (op0 == 0 || op1 == 0) | |
7845 | break; | |
7846 | ||
7847 | mem_loc_result = op0; | |
7848 | add_loc_descr (&mem_loc_result, op1); | |
7849 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0)); | |
7850 | break; | |
7851 | } | |
dd2478ae | 7852 | |
a3f97cbb | 7853 | case CONST_INT: |
d8041cc8 | 7854 | mem_loc_result = int_loc_descriptor (INTVAL (rtl)); |
a3f97cbb JW |
7855 | break; |
7856 | ||
a9e8a5ee RK |
7857 | case ADDRESSOF: |
7858 | /* If this is a MEM, return its address. Otherwise, we can't | |
7859 | represent this. */ | |
7860 | if (GET_CODE (XEXP (rtl, 0)) == MEM) | |
7861 | return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode); | |
7862 | else | |
7863 | return 0; | |
7864 | ||
a3f97cbb JW |
7865 | default: |
7866 | abort (); | |
7867 | } | |
71dfc51f | 7868 | |
a3f97cbb JW |
7869 | return mem_loc_result; |
7870 | } | |
7871 | ||
956d6950 | 7872 | /* Return a descriptor that describes the concatenation of two locations. |
4401bf24 JL |
7873 | This is typically a complex variable. */ |
7874 | ||
7875 | static dw_loc_descr_ref | |
7876 | concat_loc_descriptor (x0, x1) | |
b3694847 | 7877 | rtx x0, x1; |
4401bf24 JL |
7878 | { |
7879 | dw_loc_descr_ref cc_loc_result = NULL; | |
e7af1d45 RK |
7880 | dw_loc_descr_ref x0_ref = loc_descriptor (x0); |
7881 | dw_loc_descr_ref x1_ref = loc_descriptor (x1); | |
4401bf24 | 7882 | |
e7af1d45 RK |
7883 | if (x0_ref == 0 || x1_ref == 0) |
7884 | return 0; | |
7885 | ||
7886 | cc_loc_result = x0_ref; | |
4401bf24 | 7887 | add_loc_descr (&cc_loc_result, |
e7af1d45 RK |
7888 | new_loc_descr (DW_OP_piece, |
7889 | GET_MODE_SIZE (GET_MODE (x0)), 0)); | |
4401bf24 | 7890 | |
e7af1d45 | 7891 | add_loc_descr (&cc_loc_result, x1_ref); |
4401bf24 | 7892 | add_loc_descr (&cc_loc_result, |
e7af1d45 RK |
7893 | new_loc_descr (DW_OP_piece, |
7894 | GET_MODE_SIZE (GET_MODE (x1)), 0)); | |
4401bf24 JL |
7895 | |
7896 | return cc_loc_result; | |
7897 | } | |
7898 | ||
a3f97cbb JW |
7899 | /* Output a proper Dwarf location descriptor for a variable or parameter |
7900 | which is either allocated in a register or in a memory location. For a | |
7901 | register, we just generate an OP_REG and the register number. For a | |
7902 | memory location we provide a Dwarf postfix expression describing how to | |
e7af1d45 RK |
7903 | generate the (dynamic) address of the object onto the address stack. |
7904 | ||
7905 | If we don't know how to describe it, return 0. */ | |
71dfc51f | 7906 | |
a3f97cbb JW |
7907 | static dw_loc_descr_ref |
7908 | loc_descriptor (rtl) | |
b3694847 | 7909 | rtx rtl; |
a3f97cbb JW |
7910 | { |
7911 | dw_loc_descr_ref loc_result = NULL; | |
e7af1d45 | 7912 | |
a3f97cbb JW |
7913 | switch (GET_CODE (rtl)) |
7914 | { | |
7915 | case SUBREG: | |
a3f97cbb JW |
7916 | /* The case of a subreg may arise when we have a local (register) |
7917 | variable or a formal (register) parameter which doesn't quite fill | |
71dfc51f | 7918 | up an entire register. For now, just assume that it is |
a3f97cbb JW |
7919 | legitimate to make the Dwarf info refer to the whole register which |
7920 | contains the given subreg. */ | |
ddef6bc7 | 7921 | rtl = SUBREG_REG (rtl); |
71dfc51f | 7922 | |
2ad9852d | 7923 | /* ... fall through ... */ |
a3f97cbb JW |
7924 | |
7925 | case REG: | |
5c90448c | 7926 | loc_result = reg_loc_descriptor (rtl); |
a3f97cbb JW |
7927 | break; |
7928 | ||
7929 | case MEM: | |
e60d4d7b | 7930 | loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
a3f97cbb JW |
7931 | break; |
7932 | ||
4401bf24 JL |
7933 | case CONCAT: |
7934 | loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1)); | |
7935 | break; | |
7936 | ||
a3f97cbb | 7937 | default: |
71dfc51f | 7938 | abort (); |
a3f97cbb | 7939 | } |
71dfc51f | 7940 | |
a3f97cbb JW |
7941 | return loc_result; |
7942 | } | |
7943 | ||
2ad9852d RK |
7944 | /* Similar, but generate the descriptor from trees instead of rtl. This comes |
7945 | up particularly with variable length arrays. If ADDRESSP is nonzero, we are | |
7946 | looking for an address. Otherwise, we return a value. If we can't make a | |
7947 | descriptor, return 0. */ | |
d8041cc8 RH |
7948 | |
7949 | static dw_loc_descr_ref | |
7950 | loc_descriptor_from_tree (loc, addressp) | |
7951 | tree loc; | |
7952 | int addressp; | |
7953 | { | |
e7af1d45 RK |
7954 | dw_loc_descr_ref ret, ret1; |
7955 | int indirect_p = 0; | |
d8041cc8 RH |
7956 | int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc)); |
7957 | enum dwarf_location_atom op; | |
7958 | ||
7959 | /* ??? Most of the time we do not take proper care for sign/zero | |
7960 | extending the values properly. Hopefully this won't be a real | |
7961 | problem... */ | |
7962 | ||
7963 | switch (TREE_CODE (loc)) | |
7964 | { | |
7965 | case ERROR_MARK: | |
e7af1d45 | 7966 | return 0; |
d8041cc8 | 7967 | |
b4ae5201 | 7968 | case WITH_RECORD_EXPR: |
e7af1d45 | 7969 | case PLACEHOLDER_EXPR: |
b4ae5201 RK |
7970 | /* This case involves extracting fields from an object to determine the |
7971 | position of other fields. We don't try to encode this here. The | |
7972 | only user of this is Ada, which encodes the needed information using | |
7973 | the names of types. */ | |
e7af1d45 | 7974 | return 0; |
b4ae5201 | 7975 | |
aea9695c RK |
7976 | case CALL_EXPR: |
7977 | return 0; | |
7978 | ||
7979 | case ADDR_EXPR: | |
7980 | /* We can support this only if we can look through conversions and | |
7981 | find an INDIRECT_EXPR. */ | |
7982 | for (loc = TREE_OPERAND (loc, 0); | |
7983 | TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR | |
7984 | || TREE_CODE (loc) == NON_LVALUE_EXPR | |
7985 | || TREE_CODE (loc) == VIEW_CONVERT_EXPR | |
7986 | || TREE_CODE (loc) == SAVE_EXPR; | |
7987 | loc = TREE_OPERAND (loc, 0)) | |
7988 | ; | |
7989 | ||
7990 | return (TREE_CODE (loc) == INDIRECT_REF | |
7991 | ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp) | |
7992 | : 0); | |
7993 | ||
d8041cc8 RH |
7994 | case VAR_DECL: |
7995 | case PARM_DECL: | |
7996 | { | |
7997 | rtx rtl = rtl_for_decl_location (loc); | |
d8041cc8 | 7998 | |
a97c9600 | 7999 | if (rtl == NULL_RTX) |
e7af1d45 | 8000 | return 0; |
a97c9600 | 8001 | else if (CONSTANT_P (rtl)) |
d8041cc8 RH |
8002 | { |
8003 | ret = new_loc_descr (DW_OP_addr, 0, 0); | |
8004 | ret->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
8005 | ret->dw_loc_oprnd1.v.val_addr = rtl; | |
e7af1d45 | 8006 | indirect_p = 1; |
d8041cc8 RH |
8007 | } |
8008 | else | |
8009 | { | |
c28abdf0 RH |
8010 | enum machine_mode mode = GET_MODE (rtl); |
8011 | ||
d8041cc8 RH |
8012 | if (GET_CODE (rtl) == MEM) |
8013 | { | |
e7af1d45 | 8014 | indirect_p = 1; |
d8041cc8 RH |
8015 | rtl = XEXP (rtl, 0); |
8016 | } | |
2ad9852d | 8017 | |
d8041cc8 RH |
8018 | ret = mem_loc_descriptor (rtl, mode); |
8019 | } | |
8020 | } | |
8021 | break; | |
8022 | ||
8023 | case INDIRECT_REF: | |
8024 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 | 8025 | indirect_p = 1; |
d8041cc8 RH |
8026 | break; |
8027 | ||
749552c4 RK |
8028 | case COMPOUND_EXPR: |
8029 | return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp); | |
8030 | ||
ed972b14 RK |
8031 | case NOP_EXPR: |
8032 | case CONVERT_EXPR: | |
8033 | case NON_LVALUE_EXPR: | |
ed239f5a | 8034 | case VIEW_CONVERT_EXPR: |
b4ae5201 | 8035 | case SAVE_EXPR: |
ed972b14 | 8036 | return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp); |
e57cabac | 8037 | |
d8041cc8 RH |
8038 | case COMPONENT_REF: |
8039 | case BIT_FIELD_REF: | |
8040 | case ARRAY_REF: | |
b4e3fabb | 8041 | case ARRAY_RANGE_REF: |
d8041cc8 RH |
8042 | { |
8043 | tree obj, offset; | |
8044 | HOST_WIDE_INT bitsize, bitpos, bytepos; | |
8045 | enum machine_mode mode; | |
8046 | int volatilep; | |
d8041cc8 RH |
8047 | |
8048 | obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode, | |
a06ef755 | 8049 | &unsignedp, &volatilep); |
e7af1d45 RK |
8050 | |
8051 | if (obj == loc) | |
8052 | return 0; | |
8053 | ||
d8041cc8 | 8054 | ret = loc_descriptor_from_tree (obj, 1); |
e7af1d45 | 8055 | if (ret == 0 |
2ad9852d | 8056 | || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0) |
e7af1d45 | 8057 | return 0; |
d8041cc8 RH |
8058 | |
8059 | if (offset != NULL_TREE) | |
8060 | { | |
8061 | /* Variable offset. */ | |
8062 | add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0)); | |
8063 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
8064 | } | |
8065 | ||
e7af1d45 RK |
8066 | if (!addressp) |
8067 | indirect_p = 1; | |
d8041cc8 RH |
8068 | |
8069 | bytepos = bitpos / BITS_PER_UNIT; | |
8070 | if (bytepos > 0) | |
8071 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0)); | |
8072 | else if (bytepos < 0) | |
8073 | { | |
8074 | add_loc_descr (&ret, int_loc_descriptor (bytepos)); | |
8075 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
8076 | } | |
8077 | break; | |
8078 | } | |
8079 | ||
8080 | case INTEGER_CST: | |
8081 | if (host_integerp (loc, 0)) | |
8082 | ret = int_loc_descriptor (tree_low_cst (loc, 0)); | |
e7af1d45 RK |
8083 | else |
8084 | return 0; | |
d8041cc8 | 8085 | break; |
d8041cc8 | 8086 | |
9702143f RK |
8087 | case TRUTH_AND_EXPR: |
8088 | case TRUTH_ANDIF_EXPR: | |
d8041cc8 RH |
8089 | case BIT_AND_EXPR: |
8090 | op = DW_OP_and; | |
8091 | goto do_binop; | |
e7af1d45 | 8092 | |
9702143f | 8093 | case TRUTH_XOR_EXPR: |
d8041cc8 RH |
8094 | case BIT_XOR_EXPR: |
8095 | op = DW_OP_xor; | |
8096 | goto do_binop; | |
e7af1d45 | 8097 | |
9702143f RK |
8098 | case TRUTH_OR_EXPR: |
8099 | case TRUTH_ORIF_EXPR: | |
d8041cc8 RH |
8100 | case BIT_IOR_EXPR: |
8101 | op = DW_OP_or; | |
8102 | goto do_binop; | |
e7af1d45 | 8103 | |
d8041cc8 RH |
8104 | case TRUNC_DIV_EXPR: |
8105 | op = DW_OP_div; | |
8106 | goto do_binop; | |
e7af1d45 | 8107 | |
d8041cc8 RH |
8108 | case MINUS_EXPR: |
8109 | op = DW_OP_minus; | |
8110 | goto do_binop; | |
e7af1d45 | 8111 | |
d8041cc8 RH |
8112 | case TRUNC_MOD_EXPR: |
8113 | op = DW_OP_mod; | |
8114 | goto do_binop; | |
e7af1d45 | 8115 | |
d8041cc8 RH |
8116 | case MULT_EXPR: |
8117 | op = DW_OP_mul; | |
8118 | goto do_binop; | |
e7af1d45 | 8119 | |
d8041cc8 RH |
8120 | case LSHIFT_EXPR: |
8121 | op = DW_OP_shl; | |
8122 | goto do_binop; | |
e7af1d45 | 8123 | |
d8041cc8 RH |
8124 | case RSHIFT_EXPR: |
8125 | op = (unsignedp ? DW_OP_shr : DW_OP_shra); | |
8126 | goto do_binop; | |
e7af1d45 | 8127 | |
d8041cc8 RH |
8128 | case PLUS_EXPR: |
8129 | if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST | |
8130 | && host_integerp (TREE_OPERAND (loc, 1), 0)) | |
8131 | { | |
8132 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8133 | if (ret == 0) |
8134 | return 0; | |
8135 | ||
d8041cc8 RH |
8136 | add_loc_descr (&ret, |
8137 | new_loc_descr (DW_OP_plus_uconst, | |
8138 | tree_low_cst (TREE_OPERAND (loc, 1), | |
8139 | 0), | |
8140 | 0)); | |
8141 | break; | |
8142 | } | |
e7af1d45 | 8143 | |
d8041cc8 RH |
8144 | op = DW_OP_plus; |
8145 | goto do_binop; | |
2ad9852d | 8146 | |
d8041cc8 RH |
8147 | case LE_EXPR: |
8148 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8149 | return 0; |
8150 | ||
d8041cc8 RH |
8151 | op = DW_OP_le; |
8152 | goto do_binop; | |
e7af1d45 | 8153 | |
d8041cc8 RH |
8154 | case GE_EXPR: |
8155 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8156 | return 0; |
8157 | ||
d8041cc8 RH |
8158 | op = DW_OP_ge; |
8159 | goto do_binop; | |
e7af1d45 | 8160 | |
d8041cc8 RH |
8161 | case LT_EXPR: |
8162 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8163 | return 0; |
8164 | ||
d8041cc8 RH |
8165 | op = DW_OP_lt; |
8166 | goto do_binop; | |
e7af1d45 | 8167 | |
d8041cc8 RH |
8168 | case GT_EXPR: |
8169 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8170 | return 0; |
8171 | ||
d8041cc8 RH |
8172 | op = DW_OP_gt; |
8173 | goto do_binop; | |
e7af1d45 | 8174 | |
d8041cc8 RH |
8175 | case EQ_EXPR: |
8176 | op = DW_OP_eq; | |
8177 | goto do_binop; | |
e7af1d45 | 8178 | |
d8041cc8 RH |
8179 | case NE_EXPR: |
8180 | op = DW_OP_ne; | |
8181 | goto do_binop; | |
8182 | ||
8183 | do_binop: | |
8184 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8185 | ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); |
8186 | if (ret == 0 || ret1 == 0) | |
8187 | return 0; | |
8188 | ||
8189 | add_loc_descr (&ret, ret1); | |
d8041cc8 RH |
8190 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); |
8191 | break; | |
8192 | ||
9702143f | 8193 | case TRUTH_NOT_EXPR: |
d8041cc8 RH |
8194 | case BIT_NOT_EXPR: |
8195 | op = DW_OP_not; | |
8196 | goto do_unop; | |
e7af1d45 | 8197 | |
d8041cc8 RH |
8198 | case ABS_EXPR: |
8199 | op = DW_OP_abs; | |
8200 | goto do_unop; | |
e7af1d45 | 8201 | |
d8041cc8 RH |
8202 | case NEGATE_EXPR: |
8203 | op = DW_OP_neg; | |
8204 | goto do_unop; | |
8205 | ||
8206 | do_unop: | |
8207 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8208 | if (ret == 0) |
8209 | return 0; | |
8210 | ||
d8041cc8 RH |
8211 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); |
8212 | break; | |
8213 | ||
8214 | case MAX_EXPR: | |
8215 | loc = build (COND_EXPR, TREE_TYPE (loc), | |
8216 | build (LT_EXPR, integer_type_node, | |
8217 | TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)), | |
8218 | TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0)); | |
2ad9852d | 8219 | |
3ef42a0c | 8220 | /* ... fall through ... */ |
d8041cc8 RH |
8221 | |
8222 | case COND_EXPR: | |
8223 | { | |
e7af1d45 RK |
8224 | dw_loc_descr_ref lhs |
8225 | = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); | |
8226 | dw_loc_descr_ref rhs | |
8227 | = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0); | |
d8041cc8 RH |
8228 | dw_loc_descr_ref bra_node, jump_node, tmp; |
8229 | ||
8230 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8231 | if (ret == 0 || lhs == 0 || rhs == 0) |
8232 | return 0; | |
8233 | ||
d8041cc8 RH |
8234 | bra_node = new_loc_descr (DW_OP_bra, 0, 0); |
8235 | add_loc_descr (&ret, bra_node); | |
8236 | ||
e7af1d45 | 8237 | add_loc_descr (&ret, rhs); |
d8041cc8 RH |
8238 | jump_node = new_loc_descr (DW_OP_skip, 0, 0); |
8239 | add_loc_descr (&ret, jump_node); | |
8240 | ||
e7af1d45 | 8241 | add_loc_descr (&ret, lhs); |
d8041cc8 | 8242 | bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc; |
e7af1d45 | 8243 | bra_node->dw_loc_oprnd1.v.val_loc = lhs; |
d8041cc8 RH |
8244 | |
8245 | /* ??? Need a node to point the skip at. Use a nop. */ | |
8246 | tmp = new_loc_descr (DW_OP_nop, 0, 0); | |
8247 | add_loc_descr (&ret, tmp); | |
8248 | jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc; | |
8249 | jump_node->dw_loc_oprnd1.v.val_loc = tmp; | |
8250 | } | |
8251 | break; | |
8252 | ||
8253 | default: | |
8254 | abort (); | |
8255 | } | |
8256 | ||
e7af1d45 RK |
8257 | /* Show if we can't fill the request for an address. */ |
8258 | if (addressp && indirect_p == 0) | |
8259 | return 0; | |
d8041cc8 RH |
8260 | |
8261 | /* If we've got an address and don't want one, dereference. */ | |
e7af1d45 | 8262 | if (!addressp && indirect_p > 0) |
d8041cc8 | 8263 | { |
e7af1d45 RK |
8264 | HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc)); |
8265 | ||
8266 | if (size > DWARF2_ADDR_SIZE || size == -1) | |
8267 | return 0; | |
2ad9852d | 8268 | else if (size == DWARF2_ADDR_SIZE) |
d8041cc8 RH |
8269 | op = DW_OP_deref; |
8270 | else | |
8271 | op = DW_OP_deref_size; | |
e7af1d45 RK |
8272 | |
8273 | add_loc_descr (&ret, new_loc_descr (op, size, 0)); | |
d8041cc8 RH |
8274 | } |
8275 | ||
8276 | return ret; | |
8277 | } | |
8278 | ||
665f2503 | 8279 | /* Given a value, round it up to the lowest multiple of `boundary' |
a3f97cbb | 8280 | which is not less than the value itself. */ |
71dfc51f | 8281 | |
665f2503 | 8282 | static inline HOST_WIDE_INT |
a3f97cbb | 8283 | ceiling (value, boundary) |
665f2503 RK |
8284 | HOST_WIDE_INT value; |
8285 | unsigned int boundary; | |
a3f97cbb JW |
8286 | { |
8287 | return (((value + boundary - 1) / boundary) * boundary); | |
8288 | } | |
8289 | ||
8290 | /* Given a pointer to what is assumed to be a FIELD_DECL node, return a | |
8291 | pointer to the declared type for the relevant field variable, or return | |
8292 | `integer_type_node' if the given node turns out to be an | |
8293 | ERROR_MARK node. */ | |
71dfc51f RK |
8294 | |
8295 | static inline tree | |
a3f97cbb | 8296 | field_type (decl) |
b3694847 | 8297 | tree decl; |
a3f97cbb | 8298 | { |
b3694847 | 8299 | tree type; |
a3f97cbb JW |
8300 | |
8301 | if (TREE_CODE (decl) == ERROR_MARK) | |
8302 | return integer_type_node; | |
8303 | ||
8304 | type = DECL_BIT_FIELD_TYPE (decl); | |
71dfc51f | 8305 | if (type == NULL_TREE) |
a3f97cbb JW |
8306 | type = TREE_TYPE (decl); |
8307 | ||
8308 | return type; | |
8309 | } | |
8310 | ||
5f446d21 DD |
8311 | /* Given a pointer to a tree node, return the alignment in bits for |
8312 | it, or else return BITS_PER_WORD if the node actually turns out to | |
8313 | be an ERROR_MARK node. */ | |
71dfc51f RK |
8314 | |
8315 | static inline unsigned | |
a3f97cbb | 8316 | simple_type_align_in_bits (type) |
b3694847 | 8317 | tree type; |
a3f97cbb JW |
8318 | { |
8319 | return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; | |
8320 | } | |
8321 | ||
5f446d21 DD |
8322 | static inline unsigned |
8323 | simple_decl_align_in_bits (decl) | |
b3694847 | 8324 | tree decl; |
5f446d21 DD |
8325 | { |
8326 | return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD; | |
8327 | } | |
8328 | ||
a3f97cbb JW |
8329 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE |
8330 | node, return the size in bits for the type if it is a constant, or else | |
8331 | return the alignment for the type if the type's size is not constant, or | |
8332 | else return BITS_PER_WORD if the type actually turns out to be an | |
8333 | ERROR_MARK node. */ | |
71dfc51f | 8334 | |
665f2503 | 8335 | static inline unsigned HOST_WIDE_INT |
a3f97cbb | 8336 | simple_type_size_in_bits (type) |
b3694847 | 8337 | tree type; |
a3f97cbb | 8338 | { |
3df18884 | 8339 | |
a3f97cbb JW |
8340 | if (TREE_CODE (type) == ERROR_MARK) |
8341 | return BITS_PER_WORD; | |
2ad9852d | 8342 | else if (TYPE_SIZE (type) == NULL_TREE) |
3df18884 | 8343 | return 0; |
2ad9852d RK |
8344 | else if (host_integerp (TYPE_SIZE (type), 1)) |
8345 | return tree_low_cst (TYPE_SIZE (type), 1); | |
8346 | else | |
3df18884 | 8347 | return TYPE_ALIGN (type); |
a3f97cbb JW |
8348 | } |
8349 | ||
2ad9852d RK |
8350 | /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the |
8351 | lowest addressed byte of the "containing object" for the given FIELD_DECL, | |
8352 | or return 0 if we are unable to determine what that offset is, either | |
8353 | because the argument turns out to be a pointer to an ERROR_MARK node, or | |
8354 | because the offset is actually variable. (We can't handle the latter case | |
8355 | just yet). */ | |
71dfc51f | 8356 | |
665f2503 | 8357 | static HOST_WIDE_INT |
a3f97cbb | 8358 | field_byte_offset (decl) |
b3694847 | 8359 | tree decl; |
a3f97cbb | 8360 | { |
665f2503 | 8361 | unsigned int type_align_in_bits; |
5f446d21 | 8362 | unsigned int decl_align_in_bits; |
665f2503 | 8363 | unsigned HOST_WIDE_INT type_size_in_bits; |
665f2503 | 8364 | HOST_WIDE_INT object_offset_in_bits; |
665f2503 RK |
8365 | tree type; |
8366 | tree field_size_tree; | |
8367 | HOST_WIDE_INT bitpos_int; | |
8368 | HOST_WIDE_INT deepest_bitpos; | |
8369 | unsigned HOST_WIDE_INT field_size_in_bits; | |
a3f97cbb JW |
8370 | |
8371 | if (TREE_CODE (decl) == ERROR_MARK) | |
8372 | return 0; | |
2ad9852d | 8373 | else if (TREE_CODE (decl) != FIELD_DECL) |
a3f97cbb JW |
8374 | abort (); |
8375 | ||
8376 | type = field_type (decl); | |
a3f97cbb JW |
8377 | field_size_tree = DECL_SIZE (decl); |
8378 | ||
3df18884 RH |
8379 | /* The size could be unspecified if there was an error, or for |
8380 | a flexible array member. */ | |
50352c9c | 8381 | if (! field_size_tree) |
3df18884 | 8382 | field_size_tree = bitsize_zero_node; |
50352c9c | 8383 | |
556273e0 | 8384 | /* We cannot yet cope with fields whose positions are variable, so |
a3f97cbb JW |
8385 | for now, when we see such things, we simply return 0. Someday, we may |
8386 | be able to handle such cases, but it will be damn difficult. */ | |
665f2503 | 8387 | if (! host_integerp (bit_position (decl), 0)) |
a3f97cbb | 8388 | return 0; |
14a774a9 | 8389 | |
665f2503 | 8390 | bitpos_int = int_bit_position (decl); |
a3f97cbb | 8391 | |
3df18884 | 8392 | /* If we don't know the size of the field, pretend it's a full word. */ |
665f2503 RK |
8393 | if (host_integerp (field_size_tree, 1)) |
8394 | field_size_in_bits = tree_low_cst (field_size_tree, 1); | |
14a774a9 RK |
8395 | else |
8396 | field_size_in_bits = BITS_PER_WORD; | |
a3f97cbb JW |
8397 | |
8398 | type_size_in_bits = simple_type_size_in_bits (type); | |
a3f97cbb | 8399 | type_align_in_bits = simple_type_align_in_bits (type); |
5f446d21 | 8400 | decl_align_in_bits = simple_decl_align_in_bits (decl); |
a3f97cbb | 8401 | |
2ad9852d RK |
8402 | /* The GCC front-end doesn't make any attempt to keep track of the starting |
8403 | bit offset (relative to the start of the containing structure type) of the | |
8404 | hypothetical "containing object" for a bit-field. Thus, when computing | |
8405 | the byte offset value for the start of the "containing object" of a | |
8406 | bit-field, we must deduce this information on our own. This can be rather | |
8407 | tricky to do in some cases. For example, handling the following structure | |
8408 | type definition when compiling for an i386/i486 target (which only aligns | |
8409 | long long's to 32-bit boundaries) can be very tricky: | |
a3f97cbb JW |
8410 | |
8411 | struct S { int field1; long long field2:31; }; | |
8412 | ||
2ad9852d RK |
8413 | Fortunately, there is a simple rule-of-thumb which can be used in such |
8414 | cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the | |
8415 | structure shown above. It decides to do this based upon one simple rule | |
8416 | for bit-field allocation. GCC allocates each "containing object" for each | |
8417 | bit-field at the first (i.e. lowest addressed) legitimate alignment | |
8418 | boundary (based upon the required minimum alignment for the declared type | |
8419 | of the field) which it can possibly use, subject to the condition that | |
8420 | there is still enough available space remaining in the containing object | |
8421 | (when allocated at the selected point) to fully accommodate all of the | |
8422 | bits of the bit-field itself. | |
8423 | ||
8424 | This simple rule makes it obvious why GCC allocates 8 bytes for each | |
8425 | object of the structure type shown above. When looking for a place to | |
8426 | allocate the "containing object" for `field2', the compiler simply tries | |
8427 | to allocate a 64-bit "containing object" at each successive 32-bit | |
8428 | boundary (starting at zero) until it finds a place to allocate that 64- | |
8429 | bit field such that at least 31 contiguous (and previously unallocated) | |
8430 | bits remain within that selected 64 bit field. (As it turns out, for the | |
8431 | example above, the compiler finds it is OK to allocate the "containing | |
8432 | object" 64-bit field at bit-offset zero within the structure type.) | |
8433 | ||
8434 | Here we attempt to work backwards from the limited set of facts we're | |
8435 | given, and we try to deduce from those facts, where GCC must have believed | |
8436 | that the containing object started (within the structure type). The value | |
8437 | we deduce is then used (by the callers of this routine) to generate | |
8438 | DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields | |
8439 | and, in the case of DW_AT_location, regular fields as well). */ | |
a3f97cbb JW |
8440 | |
8441 | /* Figure out the bit-distance from the start of the structure to the | |
8442 | "deepest" bit of the bit-field. */ | |
8443 | deepest_bitpos = bitpos_int + field_size_in_bits; | |
8444 | ||
8445 | /* This is the tricky part. Use some fancy footwork to deduce where the | |
8446 | lowest addressed bit of the containing object must be. */ | |
5f446d21 DD |
8447 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; |
8448 | ||
8449 | /* Round up to type_align by default. This works best for bitfields. */ | |
8450 | object_offset_in_bits += type_align_in_bits - 1; | |
8451 | object_offset_in_bits /= type_align_in_bits; | |
8452 | object_offset_in_bits *= type_align_in_bits; | |
a3f97cbb | 8453 | |
5f446d21 DD |
8454 | if (object_offset_in_bits > bitpos_int) |
8455 | { | |
8456 | /* Sigh, the decl must be packed. */ | |
8457 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; | |
8458 | ||
8459 | /* Round up to decl_align instead. */ | |
8460 | object_offset_in_bits += decl_align_in_bits - 1; | |
8461 | object_offset_in_bits /= decl_align_in_bits; | |
8462 | object_offset_in_bits *= decl_align_in_bits; | |
8463 | } | |
a3f97cbb | 8464 | |
2ad9852d | 8465 | return object_offset_in_bits / BITS_PER_UNIT; |
a3f97cbb | 8466 | } |
a3f97cbb | 8467 | \f |
71dfc51f RK |
8468 | /* The following routines define various Dwarf attributes and any data |
8469 | associated with them. */ | |
a3f97cbb | 8470 | |
ef76d03b | 8471 | /* Add a location description attribute value to a DIE. |
a3f97cbb | 8472 | |
ef76d03b | 8473 | This emits location attributes suitable for whole variables and |
a3f97cbb JW |
8474 | whole parameters. Note that the location attributes for struct fields are |
8475 | generated by the routine `data_member_location_attribute' below. */ | |
71dfc51f | 8476 | |
a3f97cbb | 8477 | static void |
ef76d03b | 8478 | add_AT_location_description (die, attr_kind, rtl) |
a3f97cbb | 8479 | dw_die_ref die; |
ef76d03b | 8480 | enum dwarf_attribute attr_kind; |
b3694847 | 8481 | rtx rtl; |
a3f97cbb | 8482 | { |
e7af1d45 | 8483 | dw_loc_descr_ref descr = loc_descriptor (rtl); |
a3f97cbb | 8484 | |
e7af1d45 RK |
8485 | if (descr != 0) |
8486 | add_AT_loc (die, attr_kind, descr); | |
a3f97cbb JW |
8487 | } |
8488 | ||
2ad9852d RK |
8489 | /* Attach the specialized form of location attribute used for data members of |
8490 | struct and union types. In the special case of a FIELD_DECL node which | |
8491 | represents a bit-field, the "offset" part of this special location | |
8492 | descriptor must indicate the distance in bytes from the lowest-addressed | |
8493 | byte of the containing struct or union type to the lowest-addressed byte of | |
8494 | the "containing object" for the bit-field. (See the `field_byte_offset' | |
8495 | function above). | |
8496 | ||
8497 | For any given bit-field, the "containing object" is a hypothetical object | |
8498 | (of some integral or enum type) within which the given bit-field lives. The | |
8499 | type of this hypothetical "containing object" is always the same as the | |
8500 | declared type of the individual bit-field itself (for GCC anyway... the | |
8501 | DWARF spec doesn't actually mandate this). Note that it is the size (in | |
8502 | bytes) of the hypothetical "containing object" which will be given in the | |
8503 | DW_AT_byte_size attribute for this bit-field. (See the | |
8504 | `byte_size_attribute' function below.) It is also used when calculating the | |
8505 | value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute' | |
8506 | function below.) */ | |
71dfc51f | 8507 | |
a3f97cbb JW |
8508 | static void |
8509 | add_data_member_location_attribute (die, decl) | |
b3694847 SS |
8510 | dw_die_ref die; |
8511 | tree decl; | |
a3f97cbb | 8512 | { |
649ce3f2 JM |
8513 | long offset; |
8514 | dw_loc_descr_ref loc_descr = 0; | |
a3f97cbb | 8515 | |
61b32c02 | 8516 | if (TREE_CODE (decl) == TREE_VEC) |
649ce3f2 JM |
8517 | { |
8518 | /* We're working on the TAG_inheritance for a base class. */ | |
1d3d6b1e | 8519 | if (TREE_VIA_VIRTUAL (decl) && is_cxx ()) |
649ce3f2 JM |
8520 | { |
8521 | /* For C++ virtual bases we can't just use BINFO_OFFSET, as they | |
8522 | aren't at a fixed offset from all (sub)objects of the same | |
8523 | type. We need to extract the appropriate offset from our | |
8524 | vtable. The following dwarf expression means | |
8525 | ||
8526 | BaseAddr = ObAddr + *((*ObAddr) - Offset) | |
8527 | ||
8528 | This is specific to the V3 ABI, of course. */ | |
8529 | ||
8530 | dw_loc_descr_ref tmp; | |
2ad9852d | 8531 | |
649ce3f2 JM |
8532 | /* Make a copy of the object address. */ |
8533 | tmp = new_loc_descr (DW_OP_dup, 0, 0); | |
8534 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 8535 | |
649ce3f2 JM |
8536 | /* Extract the vtable address. */ |
8537 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
8538 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 8539 | |
649ce3f2 JM |
8540 | /* Calculate the address of the offset. */ |
8541 | offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0); | |
8542 | if (offset >= 0) | |
8543 | abort (); | |
2ad9852d | 8544 | |
649ce3f2 JM |
8545 | tmp = int_loc_descriptor (-offset); |
8546 | add_loc_descr (&loc_descr, tmp); | |
8547 | tmp = new_loc_descr (DW_OP_minus, 0, 0); | |
8548 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 8549 | |
649ce3f2 JM |
8550 | /* Extract the offset. */ |
8551 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
8552 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 8553 | |
649ce3f2 JM |
8554 | /* Add it to the object address. */ |
8555 | tmp = new_loc_descr (DW_OP_plus, 0, 0); | |
8556 | add_loc_descr (&loc_descr, tmp); | |
8557 | } | |
8558 | else | |
8559 | offset = tree_low_cst (BINFO_OFFSET (decl), 0); | |
8560 | } | |
61b32c02 JM |
8561 | else |
8562 | offset = field_byte_offset (decl); | |
8563 | ||
649ce3f2 JM |
8564 | if (! loc_descr) |
8565 | { | |
8566 | enum dwarf_location_atom op; | |
8567 | ||
2ad9852d RK |
8568 | /* The DWARF2 standard says that we should assume that the structure |
8569 | address is already on the stack, so we can specify a structure field | |
8570 | address by using DW_OP_plus_uconst. */ | |
71dfc51f | 8571 | |
a3f97cbb | 8572 | #ifdef MIPS_DEBUGGING_INFO |
2ad9852d RK |
8573 | /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst |
8574 | operator correctly. It works only if we leave the offset on the | |
8575 | stack. */ | |
649ce3f2 | 8576 | op = DW_OP_constu; |
a3f97cbb | 8577 | #else |
649ce3f2 | 8578 | op = DW_OP_plus_uconst; |
a3f97cbb | 8579 | #endif |
71dfc51f | 8580 | |
649ce3f2 JM |
8581 | loc_descr = new_loc_descr (op, offset, 0); |
8582 | } | |
2ad9852d | 8583 | |
a3f97cbb JW |
8584 | add_AT_loc (die, DW_AT_data_member_location, loc_descr); |
8585 | } | |
8586 | ||
8587 | /* Attach an DW_AT_const_value attribute for a variable or a parameter which | |
8588 | does not have a "location" either in memory or in a register. These | |
8589 | things can arise in GNU C when a constant is passed as an actual parameter | |
8590 | to an inlined function. They can also arise in C++ where declared | |
8591 | constants do not necessarily get memory "homes". */ | |
71dfc51f | 8592 | |
a3f97cbb JW |
8593 | static void |
8594 | add_const_value_attribute (die, rtl) | |
b3694847 SS |
8595 | dw_die_ref die; |
8596 | rtx rtl; | |
a3f97cbb JW |
8597 | { |
8598 | switch (GET_CODE (rtl)) | |
8599 | { | |
8600 | case CONST_INT: | |
2e4b9b8c RH |
8601 | /* Note that a CONST_INT rtx could represent either an integer |
8602 | or a floating-point constant. A CONST_INT is used whenever | |
8603 | the constant will fit into a single word. In all such | |
8604 | cases, the original mode of the constant value is wiped | |
8605 | out, and the CONST_INT rtx is assigned VOIDmode. */ | |
8606 | { | |
8607 | HOST_WIDE_INT val = INTVAL (rtl); | |
8608 | ||
8609 | /* ??? We really should be using HOST_WIDE_INT throughout. */ | |
5929a2f0 | 8610 | if (val < 0 && (long) val == val) |
3d7a191f | 8611 | add_AT_int (die, DW_AT_const_value, (long) val); |
5929a2f0 RH |
8612 | else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val) |
8613 | add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val); | |
94784fb9 RK |
8614 | else |
8615 | { | |
e7af1d45 | 8616 | #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT |
94784fb9 RK |
8617 | add_AT_long_long (die, DW_AT_const_value, |
8618 | val >> HOST_BITS_PER_LONG, val); | |
e7af1d45 | 8619 | #else |
94784fb9 | 8620 | abort (); |
e7af1d45 | 8621 | #endif |
94784fb9 | 8622 | } |
2e4b9b8c | 8623 | } |
a3f97cbb JW |
8624 | break; |
8625 | ||
8626 | case CONST_DOUBLE: | |
8627 | /* Note that a CONST_DOUBLE rtx could represent either an integer or a | |
8628 | floating-point constant. A CONST_DOUBLE is used whenever the | |
8629 | constant requires more than one word in order to be adequately | |
469ac993 JM |
8630 | represented. We output CONST_DOUBLEs as blocks. */ |
8631 | { | |
b3694847 | 8632 | enum machine_mode mode = GET_MODE (rtl); |
469ac993 JM |
8633 | |
8634 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
8635 | { | |
b3694847 | 8636 | unsigned length = GET_MODE_SIZE (mode) / 4; |
1bfb5f8f | 8637 | long *array = (long *) xmalloc (sizeof (long) * length); |
71dfc51f | 8638 | REAL_VALUE_TYPE rv; |
469ac993 | 8639 | |
71dfc51f | 8640 | REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl); |
469ac993 JM |
8641 | switch (mode) |
8642 | { | |
8643 | case SFmode: | |
71dfc51f | 8644 | REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]); |
469ac993 JM |
8645 | break; |
8646 | ||
8647 | case DFmode: | |
71dfc51f | 8648 | REAL_VALUE_TO_TARGET_DOUBLE (rv, array); |
469ac993 JM |
8649 | break; |
8650 | ||
8651 | case XFmode: | |
8652 | case TFmode: | |
71dfc51f | 8653 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array); |
469ac993 JM |
8654 | break; |
8655 | ||
8656 | default: | |
8657 | abort (); | |
8658 | } | |
8659 | ||
469ac993 JM |
8660 | add_AT_float (die, DW_AT_const_value, length, array); |
8661 | } | |
8662 | else | |
2e4b9b8c RH |
8663 | { |
8664 | /* ??? We really should be using HOST_WIDE_INT throughout. */ | |
8665 | if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT) | |
8666 | abort (); | |
2ad9852d | 8667 | |
2e4b9b8c RH |
8668 | add_AT_long_long (die, DW_AT_const_value, |
8669 | CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl)); | |
8670 | } | |
469ac993 | 8671 | } |
a3f97cbb JW |
8672 | break; |
8673 | ||
8674 | case CONST_STRING: | |
8675 | add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0)); | |
8676 | break; | |
8677 | ||
8678 | case SYMBOL_REF: | |
8679 | case LABEL_REF: | |
8680 | case CONST: | |
c470afad RK |
8681 | add_AT_addr (die, DW_AT_const_value, rtl); |
8682 | VARRAY_PUSH_RTX (used_rtx_varray, rtl); | |
a3f97cbb JW |
8683 | break; |
8684 | ||
8685 | case PLUS: | |
8686 | /* In cases where an inlined instance of an inline function is passed | |
8687 | the address of an `auto' variable (which is local to the caller) we | |
8688 | can get a situation where the DECL_RTL of the artificial local | |
8689 | variable (for the inlining) which acts as a stand-in for the | |
8690 | corresponding formal parameter (of the inline function) will look | |
8691 | like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not | |
556273e0 KH |
8692 | exactly a compile-time constant expression, but it isn't the address |
8693 | of the (artificial) local variable either. Rather, it represents the | |
a3f97cbb | 8694 | *value* which the artificial local variable always has during its |
556273e0 | 8695 | lifetime. We currently have no way to represent such quasi-constant |
6a7a9f01 | 8696 | values in Dwarf, so for now we just punt and generate nothing. */ |
a3f97cbb JW |
8697 | break; |
8698 | ||
8699 | default: | |
8700 | /* No other kinds of rtx should be possible here. */ | |
8701 | abort (); | |
8702 | } | |
8703 | ||
8704 | } | |
8705 | ||
d8041cc8 RH |
8706 | static rtx |
8707 | rtl_for_decl_location (decl) | |
8708 | tree decl; | |
a3f97cbb | 8709 | { |
b3694847 | 8710 | rtx rtl; |
71dfc51f | 8711 | |
a3f97cbb JW |
8712 | /* Here we have to decide where we are going to say the parameter "lives" |
8713 | (as far as the debugger is concerned). We only have a couple of | |
8714 | choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. | |
71dfc51f | 8715 | |
556273e0 | 8716 | DECL_RTL normally indicates where the parameter lives during most of the |
71dfc51f | 8717 | activation of the function. If optimization is enabled however, this |
556273e0 | 8718 | could be either NULL or else a pseudo-reg. Both of those cases indicate |
a3f97cbb JW |
8719 | that the parameter doesn't really live anywhere (as far as the code |
8720 | generation parts of GCC are concerned) during most of the function's | |
8721 | activation. That will happen (for example) if the parameter is never | |
71dfc51f RK |
8722 | referenced within the function. |
8723 | ||
8724 | We could just generate a location descriptor here for all non-NULL | |
8725 | non-pseudo values of DECL_RTL and ignore all of the rest, but we can be | |
8726 | a little nicer than that if we also consider DECL_INCOMING_RTL in cases | |
8727 | where DECL_RTL is NULL or is a pseudo-reg. | |
8728 | ||
8729 | Note however that we can only get away with using DECL_INCOMING_RTL as | |
8730 | a backup substitute for DECL_RTL in certain limited cases. In cases | |
8731 | where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl), | |
8732 | we can be sure that the parameter was passed using the same type as it is | |
8733 | declared to have within the function, and that its DECL_INCOMING_RTL | |
8734 | points us to a place where a value of that type is passed. | |
8735 | ||
8736 | In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different, | |
8737 | we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL | |
8738 | because in these cases DECL_INCOMING_RTL points us to a value of some | |
8739 | type which is *different* from the type of the parameter itself. Thus, | |
8740 | if we tried to use DECL_INCOMING_RTL to generate a location attribute in | |
8741 | such cases, the debugger would end up (for example) trying to fetch a | |
8742 | `float' from a place which actually contains the first part of a | |
8743 | `double'. That would lead to really incorrect and confusing | |
8744 | output at debug-time. | |
8745 | ||
8746 | So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL | |
8747 | in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There | |
8748 | are a couple of exceptions however. On little-endian machines we can | |
8749 | get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is | |
8750 | not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is | |
8751 | an integral type that is smaller than TREE_TYPE (decl). These cases arise | |
8752 | when (on a little-endian machine) a non-prototyped function has a | |
8753 | parameter declared to be of type `short' or `char'. In such cases, | |
8754 | TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will | |
8755 | be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the | |
8756 | passed `int' value. If the debugger then uses that address to fetch | |
8757 | a `short' or a `char' (on a little-endian machine) the result will be | |
8758 | the correct data, so we allow for such exceptional cases below. | |
8759 | ||
8760 | Note that our goal here is to describe the place where the given formal | |
2ad9852d RK |
8761 | parameter lives during most of the function's activation (i.e. between the |
8762 | end of the prologue and the start of the epilogue). We'll do that as best | |
8763 | as we can. Note however that if the given formal parameter is modified | |
8764 | sometime during the execution of the function, then a stack backtrace (at | |
8765 | debug-time) will show the function as having been called with the *new* | |
8766 | value rather than the value which was originally passed in. This happens | |
8767 | rarely enough that it is not a major problem, but it *is* a problem, and | |
8768 | I'd like to fix it. | |
8769 | ||
8770 | A future version of dwarf2out.c may generate two additional attributes for | |
8771 | any given DW_TAG_formal_parameter DIE which will describe the "passed | |
8772 | type" and the "passed location" for the given formal parameter in addition | |
8773 | to the attributes we now generate to indicate the "declared type" and the | |
8774 | "active location" for each parameter. This additional set of attributes | |
8775 | could be used by debuggers for stack backtraces. Separately, note that | |
8776 | sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also. | |
8777 | This happens (for example) for inlined-instances of inline function formal | |
8778 | parameters which are never referenced. This really shouldn't be | |
8779 | happening. All PARM_DECL nodes should get valid non-NULL | |
8780 | DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these | |
8781 | values for inlined instances of inline function parameters, so when we see | |
8782 | such cases, we are just out-of-luck for the time being (until integrate.c | |
a3f97cbb JW |
8783 | gets fixed). */ |
8784 | ||
8785 | /* Use DECL_RTL as the "location" unless we find something better. */ | |
110c3568 | 8786 | rtl = DECL_RTL_IF_SET (decl); |
a3f97cbb | 8787 | |
c28abdf0 RH |
8788 | /* When generating abstract instances, ignore everything except |
8789 | constants and symbols living in memory. */ | |
8790 | if (! reload_completed) | |
8791 | { | |
8792 | if (rtl | |
8793 | && (CONSTANT_P (rtl) | |
8794 | || (GET_CODE (rtl) == MEM | |
8795 | && CONSTANT_P (XEXP (rtl, 0))))) | |
8796 | return rtl; | |
8797 | rtl = NULL_RTX; | |
8798 | } | |
8799 | else if (TREE_CODE (decl) == PARM_DECL) | |
a3f97cbb JW |
8800 | { |
8801 | if (rtl == NULL_RTX || is_pseudo_reg (rtl)) | |
8802 | { | |
d8041cc8 RH |
8803 | tree declared_type = type_main_variant (TREE_TYPE (decl)); |
8804 | tree passed_type = type_main_variant (DECL_ARG_TYPE (decl)); | |
a3f97cbb | 8805 | |
71dfc51f | 8806 | /* This decl represents a formal parameter which was optimized out. |
a3f97cbb | 8807 | Note that DECL_INCOMING_RTL may be NULL in here, but we handle |
2ad9852d | 8808 | all cases where (rtl == NULL_RTX) just below. */ |
a3f97cbb | 8809 | if (declared_type == passed_type) |
71dfc51f RK |
8810 | rtl = DECL_INCOMING_RTL (decl); |
8811 | else if (! BYTES_BIG_ENDIAN | |
8812 | && TREE_CODE (declared_type) == INTEGER_TYPE | |
555b6442 HPN |
8813 | && (GET_MODE_SIZE (TYPE_MODE (declared_type)) |
8814 | <= GET_MODE_SIZE (TYPE_MODE (passed_type)))) | |
556273e0 | 8815 | rtl = DECL_INCOMING_RTL (decl); |
a3f97cbb | 8816 | } |
5a904a61 JW |
8817 | |
8818 | /* If the parm was passed in registers, but lives on the stack, then | |
8819 | make a big endian correction if the mode of the type of the | |
8820 | parameter is not the same as the mode of the rtl. */ | |
8821 | /* ??? This is the same series of checks that are made in dbxout.c before | |
8822 | we reach the big endian correction code there. It isn't clear if all | |
8823 | of these checks are necessary here, but keeping them all is the safe | |
8824 | thing to do. */ | |
8825 | else if (GET_CODE (rtl) == MEM | |
8826 | && XEXP (rtl, 0) != const0_rtx | |
8827 | && ! CONSTANT_P (XEXP (rtl, 0)) | |
8828 | /* Not passed in memory. */ | |
8829 | && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM | |
8830 | /* Not passed by invisible reference. */ | |
8831 | && (GET_CODE (XEXP (rtl, 0)) != REG | |
8832 | || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM | |
8833 | || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM | |
8834 | #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM | |
8835 | || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM | |
8836 | #endif | |
8837 | ) | |
8838 | /* Big endian correction check. */ | |
8839 | && BYTES_BIG_ENDIAN | |
8840 | && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl) | |
8841 | && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))) | |
8842 | < UNITS_PER_WORD)) | |
8843 | { | |
8844 | int offset = (UNITS_PER_WORD | |
8845 | - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))); | |
2ad9852d | 8846 | |
5a904a61 JW |
8847 | rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)), |
8848 | plus_constant (XEXP (rtl, 0), offset)); | |
8849 | } | |
a3f97cbb | 8850 | } |
71dfc51f | 8851 | |
d8041cc8 RH |
8852 | if (rtl != NULL_RTX) |
8853 | { | |
8854 | rtl = eliminate_regs (rtl, 0, NULL_RTX); | |
6a7a9f01 | 8855 | #ifdef LEAF_REG_REMAP |
d8041cc8 RH |
8856 | if (current_function_uses_only_leaf_regs) |
8857 | leaf_renumber_regs_insn (rtl); | |
6a7a9f01 | 8858 | #endif |
d8041cc8 RH |
8859 | } |
8860 | ||
2ad9852d RK |
8861 | /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant, |
8862 | and will have been substituted directly into all expressions that use it. | |
8863 | C does not have such a concept, but C++ and other languages do. */ | |
c28abdf0 | 8864 | else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl)) |
2ad9852d RK |
8865 | rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode, |
8866 | EXPAND_INITIALIZER); | |
8063ddcf | 8867 | |
d8041cc8 RH |
8868 | return rtl; |
8869 | } | |
8870 | ||
8871 | /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value | |
8872 | data attribute for a variable or a parameter. We generate the | |
8873 | DW_AT_const_value attribute only in those cases where the given variable | |
8874 | or parameter does not have a true "location" either in memory or in a | |
8875 | register. This can happen (for example) when a constant is passed as an | |
8876 | actual argument in a call to an inline function. (It's possible that | |
8877 | these things can crop up in other ways also.) Note that one type of | |
8878 | constant value which can be passed into an inlined function is a constant | |
8879 | pointer. This can happen for example if an actual argument in an inlined | |
8880 | function call evaluates to a compile-time constant address. */ | |
8881 | ||
8882 | static void | |
8883 | add_location_or_const_value_attribute (die, decl) | |
b3694847 SS |
8884 | dw_die_ref die; |
8885 | tree decl; | |
d8041cc8 | 8886 | { |
b3694847 | 8887 | rtx rtl; |
d8041cc8 RH |
8888 | |
8889 | if (TREE_CODE (decl) == ERROR_MARK) | |
8890 | return; | |
2ad9852d | 8891 | else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL) |
d8041cc8 RH |
8892 | abort (); |
8893 | ||
8894 | rtl = rtl_for_decl_location (decl); | |
a97c9600 RH |
8895 | if (rtl == NULL_RTX) |
8896 | return; | |
6a7a9f01 | 8897 | |
732910b9 RH |
8898 | /* If we don't look past the constant pool, we risk emitting a |
8899 | reference to a constant pool entry that isn't referenced from | |
8900 | code, and thus is not emitted. */ | |
8901 | rtl = avoid_constant_pool_reference (rtl); | |
8902 | ||
a3f97cbb JW |
8903 | switch (GET_CODE (rtl)) |
8904 | { | |
e9a25f70 JL |
8905 | case ADDRESSOF: |
8906 | /* The address of a variable that was optimized away; don't emit | |
8907 | anything. */ | |
8908 | break; | |
8909 | ||
a3f97cbb JW |
8910 | case CONST_INT: |
8911 | case CONST_DOUBLE: | |
8912 | case CONST_STRING: | |
8913 | case SYMBOL_REF: | |
8914 | case LABEL_REF: | |
8915 | case CONST: | |
8916 | case PLUS: | |
8917 | /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ | |
8918 | add_const_value_attribute (die, rtl); | |
8919 | break; | |
8920 | ||
8921 | case MEM: | |
8922 | case REG: | |
8923 | case SUBREG: | |
4401bf24 | 8924 | case CONCAT: |
ef76d03b | 8925 | add_AT_location_description (die, DW_AT_location, rtl); |
a3f97cbb JW |
8926 | break; |
8927 | ||
8928 | default: | |
71dfc51f | 8929 | abort (); |
a3f97cbb JW |
8930 | } |
8931 | } | |
8932 | ||
1bfb5f8f JM |
8933 | /* If we don't have a copy of this variable in memory for some reason (such |
8934 | as a C++ member constant that doesn't have an out-of-line definition), | |
8935 | we should tell the debugger about the constant value. */ | |
8936 | ||
8937 | static void | |
8938 | tree_add_const_value_attribute (var_die, decl) | |
8939 | dw_die_ref var_die; | |
8940 | tree decl; | |
8941 | { | |
8942 | tree init = DECL_INITIAL (decl); | |
8943 | tree type = TREE_TYPE (decl); | |
8944 | ||
8945 | if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init | |
8946 | && initializer_constant_valid_p (init, type) == null_pointer_node) | |
8947 | /* OK */; | |
8948 | else | |
8949 | return; | |
8950 | ||
8951 | switch (TREE_CODE (type)) | |
8952 | { | |
8953 | case INTEGER_TYPE: | |
8954 | if (host_integerp (init, 0)) | |
8955 | add_AT_unsigned (var_die, DW_AT_const_value, | |
2ad9852d | 8956 | tree_low_cst (init, 0)); |
1bfb5f8f JM |
8957 | else |
8958 | add_AT_long_long (var_die, DW_AT_const_value, | |
8959 | TREE_INT_CST_HIGH (init), | |
8960 | TREE_INT_CST_LOW (init)); | |
8961 | break; | |
8962 | ||
8963 | default:; | |
8964 | } | |
8965 | } | |
0b34cf1e | 8966 | |
a3f97cbb JW |
8967 | /* Generate an DW_AT_name attribute given some string value to be included as |
8968 | the value of the attribute. */ | |
71dfc51f RK |
8969 | |
8970 | static inline void | |
a3f97cbb | 8971 | add_name_attribute (die, name_string) |
b3694847 SS |
8972 | dw_die_ref die; |
8973 | const char *name_string; | |
a3f97cbb | 8974 | { |
71dfc51f | 8975 | if (name_string != NULL && *name_string != 0) |
14a774a9 RK |
8976 | { |
8977 | if (demangle_name_func) | |
8978 | name_string = (*demangle_name_func) (name_string); | |
8979 | ||
8980 | add_AT_string (die, DW_AT_name, name_string); | |
8981 | } | |
a3f97cbb JW |
8982 | } |
8983 | ||
8984 | /* Given a tree node describing an array bound (either lower or upper) output | |
466446b0 | 8985 | a representation for that bound. */ |
71dfc51f | 8986 | |
a3f97cbb JW |
8987 | static void |
8988 | add_bound_info (subrange_die, bound_attr, bound) | |
b3694847 SS |
8989 | dw_die_ref subrange_die; |
8990 | enum dwarf_attribute bound_attr; | |
8991 | tree bound; | |
a3f97cbb | 8992 | { |
a3f97cbb JW |
8993 | switch (TREE_CODE (bound)) |
8994 | { | |
8995 | case ERROR_MARK: | |
8996 | return; | |
8997 | ||
3ef42a0c | 8998 | /* All fixed-bounds are represented by INTEGER_CST nodes. */ |
a3f97cbb | 8999 | case INTEGER_CST: |
665f2503 RK |
9000 | if (! host_integerp (bound, 0) |
9001 | || (bound_attr == DW_AT_lower_bound | |
28985b81 | 9002 | && (((is_c_family () || is_java ()) && integer_zerop (bound)) |
665f2503 RK |
9003 | || (is_fortran () && integer_onep (bound))))) |
9004 | /* use the default */ | |
9005 | ; | |
141719a8 | 9006 | else |
665f2503 | 9007 | add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0)); |
a3f97cbb JW |
9008 | break; |
9009 | ||
b1ccbc24 | 9010 | case CONVERT_EXPR: |
a3f97cbb | 9011 | case NOP_EXPR: |
b1ccbc24 | 9012 | case NON_LVALUE_EXPR: |
ed239f5a | 9013 | case VIEW_CONVERT_EXPR: |
b1ccbc24 RK |
9014 | add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0)); |
9015 | break; | |
556273e0 | 9016 | |
a3f97cbb JW |
9017 | case SAVE_EXPR: |
9018 | /* If optimization is turned on, the SAVE_EXPRs that describe how to | |
466446b0 JM |
9019 | access the upper bound values may be bogus. If they refer to a |
9020 | register, they may only describe how to get at these values at the | |
9021 | points in the generated code right after they have just been | |
9022 | computed. Worse yet, in the typical case, the upper bound values | |
9023 | will not even *be* computed in the optimized code (though the | |
9024 | number of elements will), so these SAVE_EXPRs are entirely | |
9025 | bogus. In order to compensate for this fact, we check here to see | |
9026 | if optimization is enabled, and if so, we don't add an attribute | |
9027 | for the (unknown and unknowable) upper bound. This should not | |
9028 | cause too much trouble for existing (stupid?) debuggers because | |
9029 | they have to deal with empty upper bounds location descriptions | |
9030 | anyway in order to be able to deal with incomplete array types. | |
9031 | Of course an intelligent debugger (GDB?) should be able to | |
4fe9b91c | 9032 | comprehend that a missing upper bound specification in an array |
466446b0 JM |
9033 | type used for a storage class `auto' local array variable |
9034 | indicates that the upper bound is both unknown (at compile- time) | |
9035 | and unknowable (at run-time) due to optimization. | |
9036 | ||
9037 | We assume that a MEM rtx is safe because gcc wouldn't put the | |
9038 | value there unless it was going to be used repeatedly in the | |
9039 | function, i.e. for cleanups. */ | |
1edf43d6 JM |
9040 | if (SAVE_EXPR_RTL (bound) |
9041 | && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)) | |
a3f97cbb | 9042 | { |
b3694847 | 9043 | dw_die_ref ctx = lookup_decl_die (current_function_decl); |
54ba1f0d | 9044 | dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound); |
b3694847 | 9045 | rtx loc = SAVE_EXPR_RTL (bound); |
f5963e61 JL |
9046 | |
9047 | /* If the RTL for the SAVE_EXPR is memory, handle the case where | |
9048 | it references an outer function's frame. */ | |
f5963e61 JL |
9049 | if (GET_CODE (loc) == MEM) |
9050 | { | |
9051 | rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound); | |
9052 | ||
9053 | if (XEXP (loc, 0) != new_addr) | |
c5c76735 | 9054 | loc = gen_rtx_MEM (GET_MODE (loc), new_addr); |
f5963e61 JL |
9055 | } |
9056 | ||
466446b0 JM |
9057 | add_AT_flag (decl_die, DW_AT_artificial, 1); |
9058 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
f5963e61 | 9059 | add_AT_location_description (decl_die, DW_AT_location, loc); |
466446b0 | 9060 | add_AT_die_ref (subrange_die, bound_attr, decl_die); |
a3f97cbb | 9061 | } |
71dfc51f RK |
9062 | |
9063 | /* Else leave out the attribute. */ | |
a3f97cbb | 9064 | break; |
3f76745e | 9065 | |
ef76d03b | 9066 | case VAR_DECL: |
d8041cc8 RH |
9067 | case PARM_DECL: |
9068 | { | |
9069 | dw_die_ref decl_die = lookup_decl_die (bound); | |
9070 | ||
9071 | /* ??? Can this happen, or should the variable have been bound | |
9072 | first? Probably it can, since I imagine that we try to create | |
9073 | the types of parameters in the order in which they exist in | |
0b34cf1e | 9074 | the list, and won't have created a forward reference to a |
d8041cc8 RH |
9075 | later parameter. */ |
9076 | if (decl_die != NULL) | |
9077 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
9078 | break; | |
9079 | } | |
ef76d03b | 9080 | |
3f76745e | 9081 | default: |
d8041cc8 RH |
9082 | { |
9083 | /* Otherwise try to create a stack operation procedure to | |
9084 | evaluate the value of the array bound. */ | |
9085 | ||
9086 | dw_die_ref ctx, decl_die; | |
9087 | dw_loc_descr_ref loc; | |
9088 | ||
9089 | loc = loc_descriptor_from_tree (bound, 0); | |
9090 | if (loc == NULL) | |
9091 | break; | |
9092 | ||
e7af1d45 RK |
9093 | if (current_function_decl == 0) |
9094 | ctx = comp_unit_die; | |
9095 | else | |
9096 | ctx = lookup_decl_die (current_function_decl); | |
d8041cc8 | 9097 | |
aea9695c RK |
9098 | /* If we weren't able to find a context, it's most likely the case |
9099 | that we are processing the return type of the function. So | |
9100 | make a SAVE_EXPR to point to it and have the limbo DIE code | |
9101 | find the proper die. The save_expr function doesn't always | |
9102 | make a SAVE_EXPR, so do it ourselves. */ | |
9103 | if (ctx == 0) | |
9104 | bound = build (SAVE_EXPR, TREE_TYPE (bound), bound, | |
9105 | current_function_decl, NULL_TREE); | |
9106 | ||
54ba1f0d | 9107 | decl_die = new_die (DW_TAG_variable, ctx, bound); |
d8041cc8 RH |
9108 | add_AT_flag (decl_die, DW_AT_artificial, 1); |
9109 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
9110 | add_AT_loc (decl_die, DW_AT_location, loc); | |
9111 | ||
9112 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
9113 | break; | |
9114 | } | |
a3f97cbb JW |
9115 | } |
9116 | } | |
9117 | ||
9118 | /* Note that the block of subscript information for an array type also | |
9119 | includes information about the element type of type given array type. */ | |
71dfc51f | 9120 | |
a3f97cbb JW |
9121 | static void |
9122 | add_subscript_info (type_die, type) | |
b3694847 SS |
9123 | dw_die_ref type_die; |
9124 | tree type; | |
a3f97cbb | 9125 | { |
081f5e7e | 9126 | #ifndef MIPS_DEBUGGING_INFO |
b3694847 | 9127 | unsigned dimension_number; |
081f5e7e | 9128 | #endif |
b3694847 SS |
9129 | tree lower, upper; |
9130 | dw_die_ref subrange_die; | |
a3f97cbb | 9131 | |
556273e0 | 9132 | /* The GNU compilers represent multidimensional array types as sequences of |
a3f97cbb JW |
9133 | one dimensional array types whose element types are themselves array |
9134 | types. Here we squish that down, so that each multidimensional array | |
556273e0 | 9135 | type gets only one array_type DIE in the Dwarf debugging info. The draft |
a3f97cbb JW |
9136 | Dwarf specification say that we are allowed to do this kind of |
9137 | compression in C (because there is no difference between an array or | |
556273e0 | 9138 | arrays and a multidimensional array in C) but for other source languages |
a3f97cbb | 9139 | (e.g. Ada) we probably shouldn't do this. */ |
71dfc51f | 9140 | |
a3f97cbb JW |
9141 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
9142 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
9143 | We work around this by disabling this feature. See also | |
9144 | gen_array_type_die. */ | |
9145 | #ifndef MIPS_DEBUGGING_INFO | |
9146 | for (dimension_number = 0; | |
9147 | TREE_CODE (type) == ARRAY_TYPE; | |
9148 | type = TREE_TYPE (type), dimension_number++) | |
a3f97cbb | 9149 | #endif |
2ad9852d | 9150 | { |
b3694847 | 9151 | tree domain = TYPE_DOMAIN (type); |
a3f97cbb JW |
9152 | |
9153 | /* Arrays come in three flavors: Unspecified bounds, fixed bounds, | |
556273e0 | 9154 | and (in GNU C only) variable bounds. Handle all three forms |
a3f97cbb | 9155 | here. */ |
54ba1f0d | 9156 | subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL); |
a3f97cbb JW |
9157 | if (domain) |
9158 | { | |
9159 | /* We have an array type with specified bounds. */ | |
9160 | lower = TYPE_MIN_VALUE (domain); | |
9161 | upper = TYPE_MAX_VALUE (domain); | |
9162 | ||
a9d38797 JM |
9163 | /* define the index type. */ |
9164 | if (TREE_TYPE (domain)) | |
ef76d03b JW |
9165 | { |
9166 | /* ??? This is probably an Ada unnamed subrange type. Ignore the | |
9167 | TREE_TYPE field. We can't emit debug info for this | |
9168 | because it is an unnamed integral type. */ | |
9169 | if (TREE_CODE (domain) == INTEGER_TYPE | |
9170 | && TYPE_NAME (domain) == NULL_TREE | |
9171 | && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE | |
9172 | && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE) | |
556273e0 | 9173 | ; |
ef76d03b JW |
9174 | else |
9175 | add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0, | |
9176 | type_die); | |
9177 | } | |
a9d38797 | 9178 | |
e1ee5cdc RH |
9179 | /* ??? If upper is NULL, the array has unspecified length, |
9180 | but it does have a lower bound. This happens with Fortran | |
9181 | dimension arr(N:*) | |
9182 | Since the debugger is definitely going to need to know N | |
9183 | to produce useful results, go ahead and output the lower | |
9184 | bound solo, and hope the debugger can cope. */ | |
9185 | ||
141719a8 | 9186 | add_bound_info (subrange_die, DW_AT_lower_bound, lower); |
e1ee5cdc RH |
9187 | if (upper) |
9188 | add_bound_info (subrange_die, DW_AT_upper_bound, upper); | |
a3f97cbb | 9189 | } |
71dfc51f | 9190 | |
2ad9852d RK |
9191 | /* Otherwise we have an array type with an unspecified length. The |
9192 | DWARF-2 spec does not say how to handle this; let's just leave out the | |
9193 | bounds. */ | |
a3f97cbb | 9194 | } |
a3f97cbb JW |
9195 | } |
9196 | ||
9197 | static void | |
9198 | add_byte_size_attribute (die, tree_node) | |
9199 | dw_die_ref die; | |
b3694847 | 9200 | tree tree_node; |
a3f97cbb | 9201 | { |
b3694847 | 9202 | unsigned size; |
a3f97cbb JW |
9203 | |
9204 | switch (TREE_CODE (tree_node)) | |
9205 | { | |
9206 | case ERROR_MARK: | |
9207 | size = 0; | |
9208 | break; | |
9209 | case ENUMERAL_TYPE: | |
9210 | case RECORD_TYPE: | |
9211 | case UNION_TYPE: | |
9212 | case QUAL_UNION_TYPE: | |
9213 | size = int_size_in_bytes (tree_node); | |
9214 | break; | |
9215 | case FIELD_DECL: | |
9216 | /* For a data member of a struct or union, the DW_AT_byte_size is | |
9217 | generally given as the number of bytes normally allocated for an | |
9218 | object of the *declared* type of the member itself. This is true | |
9219 | even for bit-fields. */ | |
9220 | size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT; | |
9221 | break; | |
9222 | default: | |
9223 | abort (); | |
9224 | } | |
9225 | ||
9226 | /* Note that `size' might be -1 when we get to this point. If it is, that | |
9227 | indicates that the byte size of the entity in question is variable. We | |
9228 | have no good way of expressing this fact in Dwarf at the present time, | |
9229 | so just let the -1 pass on through. */ | |
a3f97cbb JW |
9230 | add_AT_unsigned (die, DW_AT_byte_size, size); |
9231 | } | |
9232 | ||
9233 | /* For a FIELD_DECL node which represents a bit-field, output an attribute | |
9234 | which specifies the distance in bits from the highest order bit of the | |
9235 | "containing object" for the bit-field to the highest order bit of the | |
9236 | bit-field itself. | |
9237 | ||
2ad9852d RK |
9238 | For any given bit-field, the "containing object" is a hypothetical object |
9239 | (of some integral or enum type) within which the given bit-field lives. The | |
9240 | type of this hypothetical "containing object" is always the same as the | |
9241 | declared type of the individual bit-field itself. The determination of the | |
9242 | exact location of the "containing object" for a bit-field is rather | |
9243 | complicated. It's handled by the `field_byte_offset' function (above). | |
a3f97cbb JW |
9244 | |
9245 | Note that it is the size (in bytes) of the hypothetical "containing object" | |
9246 | which will be given in the DW_AT_byte_size attribute for this bit-field. | |
9247 | (See `byte_size_attribute' above). */ | |
71dfc51f RK |
9248 | |
9249 | static inline void | |
a3f97cbb | 9250 | add_bit_offset_attribute (die, decl) |
b3694847 SS |
9251 | dw_die_ref die; |
9252 | tree decl; | |
a3f97cbb | 9253 | { |
665f2503 RK |
9254 | HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl); |
9255 | tree type = DECL_BIT_FIELD_TYPE (decl); | |
9256 | HOST_WIDE_INT bitpos_int; | |
9257 | HOST_WIDE_INT highest_order_object_bit_offset; | |
9258 | HOST_WIDE_INT highest_order_field_bit_offset; | |
9259 | HOST_WIDE_INT unsigned bit_offset; | |
a3f97cbb | 9260 | |
3a88cbd1 JL |
9261 | /* Must be a field and a bit field. */ |
9262 | if (!type | |
9263 | || TREE_CODE (decl) != FIELD_DECL) | |
9264 | abort (); | |
a3f97cbb JW |
9265 | |
9266 | /* We can't yet handle bit-fields whose offsets are variable, so if we | |
9267 | encounter such things, just return without generating any attribute | |
665f2503 RK |
9268 | whatsoever. Likewise for variable or too large size. */ |
9269 | if (! host_integerp (bit_position (decl), 0) | |
9270 | || ! host_integerp (DECL_SIZE (decl), 1)) | |
71dfc51f RK |
9271 | return; |
9272 | ||
665f2503 | 9273 | bitpos_int = int_bit_position (decl); |
a3f97cbb JW |
9274 | |
9275 | /* Note that the bit offset is always the distance (in bits) from the | |
556273e0 KH |
9276 | highest-order bit of the "containing object" to the highest-order bit of |
9277 | the bit-field itself. Since the "high-order end" of any object or field | |
a3f97cbb JW |
9278 | is different on big-endian and little-endian machines, the computation |
9279 | below must take account of these differences. */ | |
9280 | highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; | |
9281 | highest_order_field_bit_offset = bitpos_int; | |
9282 | ||
71dfc51f | 9283 | if (! BYTES_BIG_ENDIAN) |
a3f97cbb | 9284 | { |
665f2503 | 9285 | highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0); |
a3f97cbb JW |
9286 | highest_order_object_bit_offset += simple_type_size_in_bits (type); |
9287 | } | |
71dfc51f RK |
9288 | |
9289 | bit_offset | |
9290 | = (! BYTES_BIG_ENDIAN | |
9291 | ? highest_order_object_bit_offset - highest_order_field_bit_offset | |
9292 | : highest_order_field_bit_offset - highest_order_object_bit_offset); | |
a3f97cbb JW |
9293 | |
9294 | add_AT_unsigned (die, DW_AT_bit_offset, bit_offset); | |
9295 | } | |
9296 | ||
9297 | /* For a FIELD_DECL node which represents a bit field, output an attribute | |
9298 | which specifies the length in bits of the given field. */ | |
71dfc51f RK |
9299 | |
9300 | static inline void | |
a3f97cbb | 9301 | add_bit_size_attribute (die, decl) |
b3694847 SS |
9302 | dw_die_ref die; |
9303 | tree decl; | |
a3f97cbb | 9304 | { |
3a88cbd1 JL |
9305 | /* Must be a field and a bit field. */ |
9306 | if (TREE_CODE (decl) != FIELD_DECL | |
9307 | || ! DECL_BIT_FIELD_TYPE (decl)) | |
9308 | abort (); | |
665f2503 RK |
9309 | |
9310 | if (host_integerp (DECL_SIZE (decl), 1)) | |
9311 | add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1)); | |
a3f97cbb JW |
9312 | } |
9313 | ||
88dad228 | 9314 | /* If the compiled language is ANSI C, then add a 'prototyped' |
a3f97cbb | 9315 | attribute, if arg types are given for the parameters of a function. */ |
71dfc51f RK |
9316 | |
9317 | static inline void | |
a3f97cbb | 9318 | add_prototyped_attribute (die, func_type) |
b3694847 SS |
9319 | dw_die_ref die; |
9320 | tree func_type; | |
a3f97cbb | 9321 | { |
88dad228 JM |
9322 | if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89 |
9323 | && TYPE_ARG_TYPES (func_type) != NULL) | |
9324 | add_AT_flag (die, DW_AT_prototyped, 1); | |
a3f97cbb JW |
9325 | } |
9326 | ||
a3f97cbb JW |
9327 | /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found |
9328 | by looking in either the type declaration or object declaration | |
9329 | equate table. */ | |
71dfc51f RK |
9330 | |
9331 | static inline void | |
a3f97cbb | 9332 | add_abstract_origin_attribute (die, origin) |
b3694847 SS |
9333 | dw_die_ref die; |
9334 | tree origin; | |
a3f97cbb JW |
9335 | { |
9336 | dw_die_ref origin_die = NULL; | |
bbc6ae08 | 9337 | |
d10b8e05 | 9338 | if (TREE_CODE (origin) != FUNCTION_DECL) |
e40a1c67 JM |
9339 | { |
9340 | /* We may have gotten separated from the block for the inlined | |
9341 | function, if we're in an exception handler or some such; make | |
9342 | sure that the abstract function has been written out. | |
9343 | ||
9344 | Doing this for nested functions is wrong, however; functions are | |
9345 | distinct units, and our context might not even be inline. */ | |
fb13d4d0 | 9346 | tree fn = origin; |
2ad9852d | 9347 | |
fb13d4d0 JM |
9348 | if (TYPE_P (fn)) |
9349 | fn = TYPE_STUB_DECL (fn); | |
2ad9852d | 9350 | |
fb13d4d0 | 9351 | fn = decl_function_context (fn); |
e40a1c67 | 9352 | if (fn) |
1edf43d6 | 9353 | dwarf2out_abstract_function (fn); |
e40a1c67 | 9354 | } |
44db1d9c | 9355 | |
2f939d94 | 9356 | if (DECL_P (origin)) |
71dfc51f | 9357 | origin_die = lookup_decl_die (origin); |
2f939d94 | 9358 | else if (TYPE_P (origin)) |
71dfc51f RK |
9359 | origin_die = lookup_type_die (origin); |
9360 | ||
bbc6ae08 | 9361 | if (origin_die == NULL) |
1ae8994f | 9362 | abort (); |
556273e0 | 9363 | |
a3f97cbb JW |
9364 | add_AT_die_ref (die, DW_AT_abstract_origin, origin_die); |
9365 | } | |
9366 | ||
bdb669cb JM |
9367 | /* We do not currently support the pure_virtual attribute. */ |
9368 | ||
71dfc51f | 9369 | static inline void |
a3f97cbb | 9370 | add_pure_or_virtual_attribute (die, func_decl) |
b3694847 SS |
9371 | dw_die_ref die; |
9372 | tree func_decl; | |
a3f97cbb | 9373 | { |
a94dbf2c | 9374 | if (DECL_VINDEX (func_decl)) |
a3f97cbb | 9375 | { |
bdb669cb | 9376 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); |
665f2503 RK |
9377 | |
9378 | if (host_integerp (DECL_VINDEX (func_decl), 0)) | |
9379 | add_AT_loc (die, DW_AT_vtable_elem_location, | |
9380 | new_loc_descr (DW_OP_constu, | |
9381 | tree_low_cst (DECL_VINDEX (func_decl), 0), | |
9382 | 0)); | |
71dfc51f | 9383 | |
a94dbf2c JM |
9384 | /* GNU extension: Record what type this method came from originally. */ |
9385 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
9386 | add_AT_die_ref (die, DW_AT_containing_type, | |
9387 | lookup_type_die (DECL_CONTEXT (func_decl))); | |
a3f97cbb JW |
9388 | } |
9389 | } | |
9390 | \f | |
b2932ae5 | 9391 | /* Add source coordinate attributes for the given decl. */ |
71dfc51f | 9392 | |
b2932ae5 JM |
9393 | static void |
9394 | add_src_coords_attributes (die, decl) | |
b3694847 SS |
9395 | dw_die_ref die; |
9396 | tree decl; | |
b2932ae5 | 9397 | { |
b3694847 | 9398 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
71dfc51f | 9399 | |
b2932ae5 JM |
9400 | add_AT_unsigned (die, DW_AT_decl_file, file_index); |
9401 | add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
9402 | } | |
9403 | ||
a3f97cbb JW |
9404 | /* Add an DW_AT_name attribute and source coordinate attribute for the |
9405 | given decl, but only if it actually has a name. */ | |
71dfc51f | 9406 | |
a3f97cbb JW |
9407 | static void |
9408 | add_name_and_src_coords_attributes (die, decl) | |
b3694847 SS |
9409 | dw_die_ref die; |
9410 | tree decl; | |
a3f97cbb | 9411 | { |
b3694847 | 9412 | tree decl_name; |
71dfc51f | 9413 | |
556273e0 | 9414 | decl_name = DECL_NAME (decl); |
71dfc51f | 9415 | if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL) |
a3f97cbb | 9416 | { |
a1d7ffe3 | 9417 | add_name_attribute (die, dwarf2_name (decl, 0)); |
a96c67ec JM |
9418 | if (! DECL_ARTIFICIAL (decl)) |
9419 | add_src_coords_attributes (die, decl); | |
e689ae67 | 9420 | |
a1d7ffe3 | 9421 | if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) |
bc808e0b | 9422 | && TREE_PUBLIC (decl) |
5daf7c0a JM |
9423 | && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) |
9424 | && !DECL_ABSTRACT (decl)) | |
a1d7ffe3 JM |
9425 | add_AT_string (die, DW_AT_MIPS_linkage_name, |
9426 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
a3f97cbb | 9427 | } |
7a0c8d71 DR |
9428 | |
9429 | #ifdef VMS_DEBUGGING_INFO | |
7a0c8d71 DR |
9430 | /* Get the function's name, as described by its RTL. This may be different |
9431 | from the DECL_NAME name used in the source file. */ | |
9432 | if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl)) | |
c470afad RK |
9433 | { |
9434 | add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address, | |
9435 | XEXP (DECL_RTL (decl), 0)); | |
9436 | VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0)); | |
9437 | } | |
7a0c8d71 | 9438 | #endif |
a3f97cbb JW |
9439 | } |
9440 | ||
556273e0 | 9441 | /* Push a new declaration scope. */ |
71dfc51f | 9442 | |
a3f97cbb JW |
9443 | static void |
9444 | push_decl_scope (scope) | |
9445 | tree scope; | |
9446 | { | |
244a4af0 | 9447 | VARRAY_PUSH_TREE (decl_scope_table, scope); |
a3f97cbb JW |
9448 | } |
9449 | ||
777ad4c2 | 9450 | /* Pop a declaration scope. */ |
2ad9852d | 9451 | |
777ad4c2 JM |
9452 | static inline void |
9453 | pop_decl_scope () | |
9454 | { | |
244a4af0 | 9455 | if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0) |
777ad4c2 | 9456 | abort (); |
2ad9852d | 9457 | |
244a4af0 | 9458 | VARRAY_POP (decl_scope_table); |
777ad4c2 JM |
9459 | } |
9460 | ||
9461 | /* Return the DIE for the scope that immediately contains this type. | |
9462 | Non-named types get global scope. Named types nested in other | |
9463 | types get their containing scope if it's open, or global scope | |
9464 | otherwise. All other types (i.e. function-local named types) get | |
9465 | the current active scope. */ | |
71dfc51f | 9466 | |
a3f97cbb | 9467 | static dw_die_ref |
ab72d377 | 9468 | scope_die_for (t, context_die) |
b3694847 SS |
9469 | tree t; |
9470 | dw_die_ref context_die; | |
a3f97cbb | 9471 | { |
b3694847 SS |
9472 | dw_die_ref scope_die = NULL; |
9473 | tree containing_scope; | |
9474 | int i; | |
a3f97cbb | 9475 | |
777ad4c2 JM |
9476 | /* Non-types always go in the current scope. */ |
9477 | if (! TYPE_P (t)) | |
9478 | abort (); | |
9479 | ||
9480 | containing_scope = TYPE_CONTEXT (t); | |
ab72d377 | 9481 | |
2addbe1d JM |
9482 | /* Ignore namespaces for the moment. */ |
9483 | if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL) | |
9484 | containing_scope = NULL_TREE; | |
9485 | ||
5f2f160c JM |
9486 | /* Ignore function type "scopes" from the C frontend. They mean that |
9487 | a tagged type is local to a parmlist of a function declarator, but | |
9488 | that isn't useful to DWARF. */ | |
9489 | if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE) | |
9490 | containing_scope = NULL_TREE; | |
9491 | ||
71dfc51f RK |
9492 | if (containing_scope == NULL_TREE) |
9493 | scope_die = comp_unit_die; | |
777ad4c2 | 9494 | else if (TYPE_P (containing_scope)) |
348bb3c7 | 9495 | { |
777ad4c2 JM |
9496 | /* For types, we can just look up the appropriate DIE. But |
9497 | first we check to see if we're in the middle of emitting it | |
9498 | so we know where the new DIE should go. */ | |
244a4af0 TF |
9499 | for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i) |
9500 | if (VARRAY_TREE (decl_scope_table, i) == containing_scope) | |
348bb3c7 JM |
9501 | break; |
9502 | ||
9503 | if (i < 0) | |
9504 | { | |
348bb3c7 JM |
9505 | if (debug_info_level > DINFO_LEVEL_TERSE |
9506 | && !TREE_ASM_WRITTEN (containing_scope)) | |
9507 | abort (); | |
9508 | ||
9509 | /* If none of the current dies are suitable, we get file scope. */ | |
9510 | scope_die = comp_unit_die; | |
9511 | } | |
9512 | else | |
777ad4c2 | 9513 | scope_die = lookup_type_die (containing_scope); |
348bb3c7 | 9514 | } |
a3f97cbb | 9515 | else |
777ad4c2 | 9516 | scope_die = context_die; |
71dfc51f | 9517 | |
a3f97cbb JW |
9518 | return scope_die; |
9519 | } | |
9520 | ||
2ad9852d | 9521 | /* Returns nonzero if CONTEXT_DIE is internal to a function. */ |
777ad4c2 JM |
9522 | |
9523 | static inline int | |
9524 | local_scope_p (context_die) | |
9525 | dw_die_ref context_die; | |
a3f97cbb | 9526 | { |
777ad4c2 JM |
9527 | for (; context_die; context_die = context_die->die_parent) |
9528 | if (context_die->die_tag == DW_TAG_inlined_subroutine | |
9529 | || context_die->die_tag == DW_TAG_subprogram) | |
9530 | return 1; | |
2ad9852d | 9531 | |
777ad4c2 | 9532 | return 0; |
a3f97cbb JW |
9533 | } |
9534 | ||
2ad9852d | 9535 | /* Returns nonzero if CONTEXT_DIE is a class. */ |
9765e357 JM |
9536 | |
9537 | static inline int | |
9538 | class_scope_p (context_die) | |
9539 | dw_die_ref context_die; | |
9540 | { | |
9541 | return (context_die | |
9542 | && (context_die->die_tag == DW_TAG_structure_type | |
9543 | || context_die->die_tag == DW_TAG_union_type)); | |
9544 | } | |
9545 | ||
a3f97cbb JW |
9546 | /* Many forms of DIEs require a "type description" attribute. This |
9547 | routine locates the proper "type descriptor" die for the type given | |
9548 | by 'type', and adds an DW_AT_type attribute below the given die. */ | |
71dfc51f | 9549 | |
a3f97cbb JW |
9550 | static void |
9551 | add_type_attribute (object_die, type, decl_const, decl_volatile, context_die) | |
b3694847 SS |
9552 | dw_die_ref object_die; |
9553 | tree type; | |
9554 | int decl_const; | |
9555 | int decl_volatile; | |
9556 | dw_die_ref context_die; | |
a3f97cbb | 9557 | { |
b3694847 SS |
9558 | enum tree_code code = TREE_CODE (type); |
9559 | dw_die_ref type_die = NULL; | |
a3f97cbb | 9560 | |
ef76d03b JW |
9561 | /* ??? If this type is an unnamed subrange type of an integral or |
9562 | floating-point type, use the inner type. This is because we have no | |
9563 | support for unnamed types in base_type_die. This can happen if this is | |
9564 | an Ada subrange type. Correct solution is emit a subrange type die. */ | |
b1ccbc24 RK |
9565 | if ((code == INTEGER_TYPE || code == REAL_TYPE) |
9566 | && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0) | |
9567 | type = TREE_TYPE (type), code = TREE_CODE (type); | |
9568 | ||
2ad9852d RK |
9569 | if (code == ERROR_MARK |
9570 | /* Handle a special case. For functions whose return type is void, we | |
9571 | generate *no* type attribute. (Note that no object may have type | |
9572 | `void', so this only applies to function return types). */ | |
9573 | || code == VOID_TYPE) | |
b1ccbc24 | 9574 | return; |
a3f97cbb | 9575 | |
a3f97cbb JW |
9576 | type_die = modified_type_die (type, |
9577 | decl_const || TYPE_READONLY (type), | |
9578 | decl_volatile || TYPE_VOLATILE (type), | |
ab72d377 | 9579 | context_die); |
2ad9852d | 9580 | |
a3f97cbb | 9581 | if (type_die != NULL) |
71dfc51f | 9582 | add_AT_die_ref (object_die, DW_AT_type, type_die); |
a3f97cbb JW |
9583 | } |
9584 | ||
9585 | /* Given a tree pointer to a struct, class, union, or enum type node, return | |
9586 | a pointer to the (string) tag name for the given type, or zero if the type | |
9587 | was declared without a tag. */ | |
71dfc51f | 9588 | |
d3e3972c | 9589 | static const char * |
a3f97cbb | 9590 | type_tag (type) |
b3694847 | 9591 | tree type; |
a3f97cbb | 9592 | { |
b3694847 | 9593 | const char *name = 0; |
a3f97cbb JW |
9594 | |
9595 | if (TYPE_NAME (type) != 0) | |
9596 | { | |
b3694847 | 9597 | tree t = 0; |
a3f97cbb JW |
9598 | |
9599 | /* Find the IDENTIFIER_NODE for the type name. */ | |
9600 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
9601 | t = TYPE_NAME (type); | |
bdb669cb | 9602 | |
556273e0 | 9603 | /* The g++ front end makes the TYPE_NAME of *each* tagged type point to |
a3f97cbb | 9604 | a TYPE_DECL node, regardless of whether or not a `typedef' was |
bdb669cb | 9605 | involved. */ |
a94dbf2c JM |
9606 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
9607 | && ! DECL_IGNORED_P (TYPE_NAME (type))) | |
a3f97cbb | 9608 | t = DECL_NAME (TYPE_NAME (type)); |
bdb669cb | 9609 | |
a3f97cbb JW |
9610 | /* Now get the name as a string, or invent one. */ |
9611 | if (t != 0) | |
a94dbf2c | 9612 | name = IDENTIFIER_POINTER (t); |
a3f97cbb | 9613 | } |
71dfc51f | 9614 | |
a3f97cbb JW |
9615 | return (name == 0 || *name == '\0') ? 0 : name; |
9616 | } | |
9617 | ||
9618 | /* Return the type associated with a data member, make a special check | |
9619 | for bit field types. */ | |
71dfc51f RK |
9620 | |
9621 | static inline tree | |
a3f97cbb | 9622 | member_declared_type (member) |
b3694847 | 9623 | tree member; |
a3f97cbb | 9624 | { |
71dfc51f | 9625 | return (DECL_BIT_FIELD_TYPE (member) |
2ad9852d | 9626 | ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member)); |
a3f97cbb JW |
9627 | } |
9628 | ||
d291dd49 | 9629 | /* Get the decl's label, as described by its RTL. This may be different |
a3f97cbb | 9630 | from the DECL_NAME name used in the source file. */ |
71dfc51f | 9631 | |
487a6e06 | 9632 | #if 0 |
d3e3972c | 9633 | static const char * |
d291dd49 | 9634 | decl_start_label (decl) |
b3694847 | 9635 | tree decl; |
a3f97cbb JW |
9636 | { |
9637 | rtx x; | |
d3e3972c | 9638 | const char *fnname; |
2ad9852d | 9639 | |
a3f97cbb JW |
9640 | x = DECL_RTL (decl); |
9641 | if (GET_CODE (x) != MEM) | |
71dfc51f RK |
9642 | abort (); |
9643 | ||
a3f97cbb JW |
9644 | x = XEXP (x, 0); |
9645 | if (GET_CODE (x) != SYMBOL_REF) | |
71dfc51f RK |
9646 | abort (); |
9647 | ||
a3f97cbb JW |
9648 | fnname = XSTR (x, 0); |
9649 | return fnname; | |
9650 | } | |
487a6e06 | 9651 | #endif |
a3f97cbb | 9652 | \f |
956d6950 | 9653 | /* These routines generate the internal representation of the DIE's for |
a3f97cbb | 9654 | the compilation unit. Debugging information is collected by walking |
88dad228 | 9655 | the declaration trees passed in from dwarf2out_decl(). */ |
a3f97cbb JW |
9656 | |
9657 | static void | |
9658 | gen_array_type_die (type, context_die) | |
b3694847 SS |
9659 | tree type; |
9660 | dw_die_ref context_die; | |
a3f97cbb | 9661 | { |
b3694847 SS |
9662 | dw_die_ref scope_die = scope_die_for (type, context_die); |
9663 | dw_die_ref array_die; | |
9664 | tree element_type; | |
bdb669cb | 9665 | |
a9d38797 JM |
9666 | /* ??? The SGI dwarf reader fails for array of array of enum types unless |
9667 | the inner array type comes before the outer array type. Thus we must | |
9668 | call gen_type_die before we call new_die. See below also. */ | |
9669 | #ifdef MIPS_DEBUGGING_INFO | |
9670 | gen_type_die (TREE_TYPE (type), context_die); | |
9671 | #endif | |
9672 | ||
54ba1f0d | 9673 | array_die = new_die (DW_TAG_array_type, scope_die, type); |
a9d38797 | 9674 | |
a3f97cbb JW |
9675 | #if 0 |
9676 | /* We default the array ordering. SDB will probably do | |
9677 | the right things even if DW_AT_ordering is not present. It's not even | |
9678 | an issue until we start to get into multidimensional arrays anyway. If | |
9679 | SDB is ever caught doing the Wrong Thing for multi-dimensional arrays, | |
9680 | then we'll have to put the DW_AT_ordering attribute back in. (But if | |
9681 | and when we find out that we need to put these in, we will only do so | |
9682 | for multidimensional arrays. */ | |
9683 | add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major); | |
9684 | #endif | |
9685 | ||
a9d38797 | 9686 | #ifdef MIPS_DEBUGGING_INFO |
4edb7b60 JM |
9687 | /* The SGI compilers handle arrays of unknown bound by setting |
9688 | AT_declaration and not emitting any subrange DIEs. */ | |
a9d38797 JM |
9689 | if (! TYPE_DOMAIN (type)) |
9690 | add_AT_unsigned (array_die, DW_AT_declaration, 1); | |
9691 | else | |
9692 | #endif | |
9693 | add_subscript_info (array_die, type); | |
a3f97cbb | 9694 | |
14a774a9 | 9695 | add_name_attribute (array_die, type_tag (type)); |
a3f97cbb JW |
9696 | equate_type_number_to_die (type, array_die); |
9697 | ||
9698 | /* Add representation of the type of the elements of this array type. */ | |
9699 | element_type = TREE_TYPE (type); | |
71dfc51f | 9700 | |
a3f97cbb JW |
9701 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
9702 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
9703 | We work around this by disabling this feature. See also | |
9704 | add_subscript_info. */ | |
9705 | #ifndef MIPS_DEBUGGING_INFO | |
71dfc51f RK |
9706 | while (TREE_CODE (element_type) == ARRAY_TYPE) |
9707 | element_type = TREE_TYPE (element_type); | |
9708 | ||
a3f97cbb | 9709 | gen_type_die (element_type, context_die); |
a9d38797 | 9710 | #endif |
a3f97cbb JW |
9711 | |
9712 | add_type_attribute (array_die, element_type, 0, 0, context_die); | |
9713 | } | |
9714 | ||
9715 | static void | |
9716 | gen_set_type_die (type, context_die) | |
b3694847 SS |
9717 | tree type; |
9718 | dw_die_ref context_die; | |
a3f97cbb | 9719 | { |
b3694847 | 9720 | dw_die_ref type_die |
54ba1f0d | 9721 | = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type); |
71dfc51f | 9722 | |
a3f97cbb | 9723 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
9724 | add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die); |
9725 | } | |
9726 | ||
d6f4ec51 | 9727 | #if 0 |
a3f97cbb JW |
9728 | static void |
9729 | gen_entry_point_die (decl, context_die) | |
b3694847 SS |
9730 | tree decl; |
9731 | dw_die_ref context_die; | |
a3f97cbb | 9732 | { |
b3694847 | 9733 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 9734 | dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl); |
2ad9852d | 9735 | |
a3f97cbb | 9736 | if (origin != NULL) |
71dfc51f | 9737 | add_abstract_origin_attribute (decl_die, origin); |
a3f97cbb JW |
9738 | else |
9739 | { | |
9740 | add_name_and_src_coords_attributes (decl_die, decl); | |
a3f97cbb JW |
9741 | add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)), |
9742 | 0, 0, context_die); | |
9743 | } | |
71dfc51f | 9744 | |
a3f97cbb | 9745 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 9746 | equate_decl_number_to_die (decl, decl_die); |
a3f97cbb | 9747 | else |
71dfc51f | 9748 | add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl)); |
a3f97cbb | 9749 | } |
d6f4ec51 | 9750 | #endif |
a3f97cbb | 9751 | |
8a8c3656 JM |
9752 | /* Walk through the list of incomplete types again, trying once more to |
9753 | emit full debugging info for them. */ | |
9754 | ||
9755 | static void | |
9756 | retry_incomplete_types () | |
9757 | { | |
244a4af0 | 9758 | int i; |
2ad9852d | 9759 | |
244a4af0 | 9760 | for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--) |
2ad9852d | 9761 | gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die); |
8a8c3656 JM |
9762 | } |
9763 | ||
a3f97cbb | 9764 | /* Generate a DIE to represent an inlined instance of an enumeration type. */ |
71dfc51f | 9765 | |
a3f97cbb JW |
9766 | static void |
9767 | gen_inlined_enumeration_type_die (type, context_die) | |
b3694847 SS |
9768 | tree type; |
9769 | dw_die_ref context_die; | |
a3f97cbb | 9770 | { |
54ba1f0d | 9771 | dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type); |
2ad9852d | 9772 | |
bbc6ae08 NC |
9773 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9774 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9775 | add_abstract_origin_attribute (type_die, type); |
9776 | } | |
9777 | ||
9778 | /* Generate a DIE to represent an inlined instance of a structure type. */ | |
71dfc51f | 9779 | |
a3f97cbb JW |
9780 | static void |
9781 | gen_inlined_structure_type_die (type, context_die) | |
b3694847 SS |
9782 | tree type; |
9783 | dw_die_ref context_die; | |
a3f97cbb | 9784 | { |
54ba1f0d | 9785 | dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type); |
777ad4c2 | 9786 | |
bbc6ae08 NC |
9787 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9788 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9789 | add_abstract_origin_attribute (type_die, type); |
9790 | } | |
9791 | ||
9792 | /* Generate a DIE to represent an inlined instance of a union type. */ | |
71dfc51f | 9793 | |
a3f97cbb JW |
9794 | static void |
9795 | gen_inlined_union_type_die (type, context_die) | |
b3694847 SS |
9796 | tree type; |
9797 | dw_die_ref context_die; | |
a3f97cbb | 9798 | { |
54ba1f0d | 9799 | dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type); |
777ad4c2 | 9800 | |
bbc6ae08 NC |
9801 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9802 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9803 | add_abstract_origin_attribute (type_die, type); |
9804 | } | |
9805 | ||
9806 | /* Generate a DIE to represent an enumeration type. Note that these DIEs | |
9807 | include all of the information about the enumeration values also. Each | |
273dbe67 JM |
9808 | enumerated type name/value is listed as a child of the enumerated type |
9809 | DIE. */ | |
71dfc51f | 9810 | |
a3f97cbb | 9811 | static void |
273dbe67 | 9812 | gen_enumeration_type_die (type, context_die) |
b3694847 SS |
9813 | tree type; |
9814 | dw_die_ref context_die; | |
a3f97cbb | 9815 | { |
b3694847 | 9816 | dw_die_ref type_die = lookup_type_die (type); |
273dbe67 | 9817 | |
a3f97cbb JW |
9818 | if (type_die == NULL) |
9819 | { | |
9820 | type_die = new_die (DW_TAG_enumeration_type, | |
54ba1f0d | 9821 | scope_die_for (type, context_die), type); |
a3f97cbb JW |
9822 | equate_type_number_to_die (type, type_die); |
9823 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 9824 | } |
273dbe67 JM |
9825 | else if (! TYPE_SIZE (type)) |
9826 | return; | |
9827 | else | |
9828 | remove_AT (type_die, DW_AT_declaration); | |
9829 | ||
9830 | /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the | |
9831 | given enum type is incomplete, do not generate the DW_AT_byte_size | |
9832 | attribute or the DW_AT_element_list attribute. */ | |
9833 | if (TYPE_SIZE (type)) | |
a3f97cbb | 9834 | { |
b3694847 | 9835 | tree link; |
71dfc51f | 9836 | |
a082c85a | 9837 | TREE_ASM_WRITTEN (type) = 1; |
273dbe67 | 9838 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 9839 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 9840 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 9841 | |
ef76d03b JW |
9842 | /* If the first reference to this type was as the return type of an |
9843 | inline function, then it may not have a parent. Fix this now. */ | |
9844 | if (type_die->die_parent == NULL) | |
9845 | add_child_die (scope_die_for (type, context_die), type_die); | |
9846 | ||
273dbe67 JM |
9847 | for (link = TYPE_FIELDS (type); |
9848 | link != NULL; link = TREE_CHAIN (link)) | |
a3f97cbb | 9849 | { |
54ba1f0d | 9850 | dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link); |
71dfc51f | 9851 | |
273dbe67 JM |
9852 | add_name_attribute (enum_die, |
9853 | IDENTIFIER_POINTER (TREE_PURPOSE (link))); | |
665f2503 RK |
9854 | |
9855 | if (host_integerp (TREE_VALUE (link), 0)) | |
fc9e8a14 JJ |
9856 | { |
9857 | if (tree_int_cst_sgn (TREE_VALUE (link)) < 0) | |
9858 | add_AT_int (enum_die, DW_AT_const_value, | |
9859 | tree_low_cst (TREE_VALUE (link), 0)); | |
9860 | else | |
9861 | add_AT_unsigned (enum_die, DW_AT_const_value, | |
9862 | tree_low_cst (TREE_VALUE (link), 0)); | |
9863 | } | |
a3f97cbb JW |
9864 | } |
9865 | } | |
273dbe67 JM |
9866 | else |
9867 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a3f97cbb JW |
9868 | } |
9869 | ||
a3f97cbb JW |
9870 | /* Generate a DIE to represent either a real live formal parameter decl or to |
9871 | represent just the type of some formal parameter position in some function | |
9872 | type. | |
71dfc51f | 9873 | |
a3f97cbb JW |
9874 | Note that this routine is a bit unusual because its argument may be a |
9875 | ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which | |
9876 | represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE | |
9877 | node. If it's the former then this function is being called to output a | |
9878 | DIE to represent a formal parameter object (or some inlining thereof). If | |
9879 | it's the latter, then this function is only being called to output a | |
9880 | DW_TAG_formal_parameter DIE to stand as a placeholder for some formal | |
9881 | argument type of some subprogram type. */ | |
71dfc51f | 9882 | |
a94dbf2c | 9883 | static dw_die_ref |
a3f97cbb | 9884 | gen_formal_parameter_die (node, context_die) |
b3694847 SS |
9885 | tree node; |
9886 | dw_die_ref context_die; | |
a3f97cbb | 9887 | { |
b3694847 | 9888 | dw_die_ref parm_die |
54ba1f0d | 9889 | = new_die (DW_TAG_formal_parameter, context_die, node); |
b3694847 | 9890 | tree origin; |
71dfc51f | 9891 | |
a3f97cbb JW |
9892 | switch (TREE_CODE_CLASS (TREE_CODE (node))) |
9893 | { | |
a3f97cbb JW |
9894 | case 'd': |
9895 | origin = decl_ultimate_origin (node); | |
9896 | if (origin != NULL) | |
a94dbf2c | 9897 | add_abstract_origin_attribute (parm_die, origin); |
a3f97cbb JW |
9898 | else |
9899 | { | |
9900 | add_name_and_src_coords_attributes (parm_die, node); | |
9901 | add_type_attribute (parm_die, TREE_TYPE (node), | |
9902 | TREE_READONLY (node), | |
9903 | TREE_THIS_VOLATILE (node), | |
9904 | context_die); | |
bdb669cb JM |
9905 | if (DECL_ARTIFICIAL (node)) |
9906 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb | 9907 | } |
71dfc51f | 9908 | |
141719a8 JM |
9909 | equate_decl_number_to_die (node, parm_die); |
9910 | if (! DECL_ABSTRACT (node)) | |
a94dbf2c | 9911 | add_location_or_const_value_attribute (parm_die, node); |
71dfc51f | 9912 | |
a3f97cbb JW |
9913 | break; |
9914 | ||
a3f97cbb | 9915 | case 't': |
71dfc51f | 9916 | /* We were called with some kind of a ..._TYPE node. */ |
a3f97cbb JW |
9917 | add_type_attribute (parm_die, node, 0, 0, context_die); |
9918 | break; | |
9919 | ||
a3f97cbb JW |
9920 | default: |
9921 | abort (); | |
9922 | } | |
71dfc51f | 9923 | |
a94dbf2c | 9924 | return parm_die; |
a3f97cbb JW |
9925 | } |
9926 | ||
9927 | /* Generate a special type of DIE used as a stand-in for a trailing ellipsis | |
9928 | at the end of an (ANSI prototyped) formal parameters list. */ | |
71dfc51f | 9929 | |
a3f97cbb JW |
9930 | static void |
9931 | gen_unspecified_parameters_die (decl_or_type, context_die) | |
54ba1f0d | 9932 | tree decl_or_type; |
b3694847 | 9933 | dw_die_ref context_die; |
a3f97cbb | 9934 | { |
54ba1f0d | 9935 | new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type); |
a3f97cbb JW |
9936 | } |
9937 | ||
9938 | /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a | |
9939 | DW_TAG_unspecified_parameters DIE) to represent the types of the formal | |
9940 | parameters as specified in some function type specification (except for | |
1cfdcc15 | 9941 | those which appear as part of a function *definition*). */ |
71dfc51f | 9942 | |
a3f97cbb JW |
9943 | static void |
9944 | gen_formal_types_die (function_or_method_type, context_die) | |
b3694847 SS |
9945 | tree function_or_method_type; |
9946 | dw_die_ref context_die; | |
a3f97cbb | 9947 | { |
b3694847 SS |
9948 | tree link; |
9949 | tree formal_type = NULL; | |
9950 | tree first_parm_type; | |
5daf7c0a | 9951 | tree arg; |
a3f97cbb | 9952 | |
5daf7c0a JM |
9953 | if (TREE_CODE (function_or_method_type) == FUNCTION_DECL) |
9954 | { | |
9955 | arg = DECL_ARGUMENTS (function_or_method_type); | |
9956 | function_or_method_type = TREE_TYPE (function_or_method_type); | |
9957 | } | |
9958 | else | |
9959 | arg = NULL_TREE; | |
9960 | ||
9961 | first_parm_type = TYPE_ARG_TYPES (function_or_method_type); | |
a3f97cbb | 9962 | |
556273e0 | 9963 | /* Make our first pass over the list of formal parameter types and output a |
a3f97cbb | 9964 | DW_TAG_formal_parameter DIE for each one. */ |
5daf7c0a | 9965 | for (link = first_parm_type; link; ) |
a3f97cbb | 9966 | { |
b3694847 | 9967 | dw_die_ref parm_die; |
556273e0 | 9968 | |
a3f97cbb JW |
9969 | formal_type = TREE_VALUE (link); |
9970 | if (formal_type == void_type_node) | |
9971 | break; | |
9972 | ||
9973 | /* Output a (nameless) DIE to represent the formal parameter itself. */ | |
a94dbf2c | 9974 | parm_die = gen_formal_parameter_die (formal_type, context_die); |
5daf7c0a JM |
9975 | if ((TREE_CODE (function_or_method_type) == METHOD_TYPE |
9976 | && link == first_parm_type) | |
9977 | || (arg && DECL_ARTIFICIAL (arg))) | |
a94dbf2c | 9978 | add_AT_flag (parm_die, DW_AT_artificial, 1); |
5daf7c0a JM |
9979 | |
9980 | link = TREE_CHAIN (link); | |
9981 | if (arg) | |
9982 | arg = TREE_CHAIN (arg); | |
a3f97cbb JW |
9983 | } |
9984 | ||
9985 | /* If this function type has an ellipsis, add a | |
9986 | DW_TAG_unspecified_parameters DIE to the end of the parameter list. */ | |
9987 | if (formal_type != void_type_node) | |
9988 | gen_unspecified_parameters_die (function_or_method_type, context_die); | |
9989 | ||
556273e0 | 9990 | /* Make our second (and final) pass over the list of formal parameter types |
a3f97cbb JW |
9991 | and output DIEs to represent those types (as necessary). */ |
9992 | for (link = TYPE_ARG_TYPES (function_or_method_type); | |
2ad9852d | 9993 | link && TREE_VALUE (link); |
a3f97cbb | 9994 | link = TREE_CHAIN (link)) |
2ad9852d | 9995 | gen_type_die (TREE_VALUE (link), context_die); |
a3f97cbb JW |
9996 | } |
9997 | ||
10a11b75 JM |
9998 | /* We want to generate the DIE for TYPE so that we can generate the |
9999 | die for MEMBER, which has been defined; we will need to refer back | |
10000 | to the member declaration nested within TYPE. If we're trying to | |
10001 | generate minimal debug info for TYPE, processing TYPE won't do the | |
10002 | trick; we need to attach the member declaration by hand. */ | |
10003 | ||
10004 | static void | |
10005 | gen_type_die_for_member (type, member, context_die) | |
10006 | tree type, member; | |
10007 | dw_die_ref context_die; | |
10008 | { | |
10009 | gen_type_die (type, context_die); | |
10010 | ||
10011 | /* If we're trying to avoid duplicate debug info, we may not have | |
10012 | emitted the member decl for this function. Emit it now. */ | |
10013 | if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)) | |
10014 | && ! lookup_decl_die (member)) | |
10015 | { | |
10016 | if (decl_ultimate_origin (member)) | |
10017 | abort (); | |
10018 | ||
10019 | push_decl_scope (type); | |
10020 | if (TREE_CODE (member) == FUNCTION_DECL) | |
10021 | gen_subprogram_die (member, lookup_type_die (type)); | |
10022 | else | |
10023 | gen_variable_die (member, lookup_type_die (type)); | |
2ad9852d | 10024 | |
10a11b75 JM |
10025 | pop_decl_scope (); |
10026 | } | |
10027 | } | |
10028 | ||
2ad9852d RK |
10029 | /* Generate the DWARF2 info for the "abstract" instance of a function which we |
10030 | may later generate inlined and/or out-of-line instances of. */ | |
10a11b75 | 10031 | |
e1772ac0 | 10032 | static void |
1edf43d6 | 10033 | dwarf2out_abstract_function (decl) |
10a11b75 JM |
10034 | tree decl; |
10035 | { | |
b3694847 | 10036 | dw_die_ref old_die; |
777ad4c2 | 10037 | tree save_fn; |
5daf7c0a JM |
10038 | tree context; |
10039 | int was_abstract = DECL_ABSTRACT (decl); | |
10040 | ||
10041 | /* Make sure we have the actual abstract inline, not a clone. */ | |
10042 | decl = DECL_ORIGIN (decl); | |
10a11b75 | 10043 | |
5daf7c0a | 10044 | old_die = lookup_decl_die (decl); |
10a11b75 JM |
10045 | if (old_die && get_AT_unsigned (old_die, DW_AT_inline)) |
10046 | /* We've already generated the abstract instance. */ | |
10047 | return; | |
10048 | ||
5daf7c0a JM |
10049 | /* Be sure we've emitted the in-class declaration DIE (if any) first, so |
10050 | we don't get confused by DECL_ABSTRACT. */ | |
8458e954 JS |
10051 | if (debug_info_level > DINFO_LEVEL_TERSE) |
10052 | { | |
10053 | context = decl_class_context (decl); | |
10054 | if (context) | |
10055 | gen_type_die_for_member | |
10056 | (context, decl, decl_function_context (decl) ? NULL : comp_unit_die); | |
10057 | } | |
5daf7c0a JM |
10058 | |
10059 | /* Pretend we've just finished compiling this function. */ | |
777ad4c2 JM |
10060 | save_fn = current_function_decl; |
10061 | current_function_decl = decl; | |
10062 | ||
10a11b75 JM |
10063 | set_decl_abstract_flags (decl, 1); |
10064 | dwarf2out_decl (decl); | |
5daf7c0a JM |
10065 | if (! was_abstract) |
10066 | set_decl_abstract_flags (decl, 0); | |
777ad4c2 JM |
10067 | |
10068 | current_function_decl = save_fn; | |
10a11b75 JM |
10069 | } |
10070 | ||
a3f97cbb JW |
10071 | /* Generate a DIE to represent a declared function (either file-scope or |
10072 | block-local). */ | |
71dfc51f | 10073 | |
a3f97cbb JW |
10074 | static void |
10075 | gen_subprogram_die (decl, context_die) | |
b3694847 SS |
10076 | tree decl; |
10077 | dw_die_ref context_die; | |
a3f97cbb JW |
10078 | { |
10079 | char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 SS |
10080 | tree origin = decl_ultimate_origin (decl); |
10081 | dw_die_ref subr_die; | |
10082 | rtx fp_reg; | |
10083 | tree fn_arg_types; | |
10084 | tree outer_scope; | |
10085 | dw_die_ref old_die = lookup_decl_die (decl); | |
10086 | int declaration = (current_function_decl != decl | |
10087 | || class_scope_p (context_die)); | |
a3f97cbb | 10088 | |
2ad9852d RK |
10089 | /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we |
10090 | started to generate the abstract instance of an inline, decided to output | |
10091 | its containing class, and proceeded to emit the declaration of the inline | |
10092 | from the member list for the class. If so, DECLARATION takes priority; | |
10093 | we'll get back to the abstract instance when done with the class. */ | |
10a11b75 | 10094 | |
1cfdcc15 JM |
10095 | /* The class-scope declaration DIE must be the primary DIE. */ |
10096 | if (origin && declaration && class_scope_p (context_die)) | |
10097 | { | |
10098 | origin = NULL; | |
10099 | if (old_die) | |
10100 | abort (); | |
10101 | } | |
10102 | ||
a3f97cbb JW |
10103 | if (origin != NULL) |
10104 | { | |
777ad4c2 | 10105 | if (declaration && ! local_scope_p (context_die)) |
10a11b75 JM |
10106 | abort (); |
10107 | ||
8d8238b6 JM |
10108 | /* Fixup die_parent for the abstract instance of a nested |
10109 | inline function. */ | |
10110 | if (old_die && old_die->die_parent == NULL) | |
10111 | add_child_die (context_die, old_die); | |
10112 | ||
54ba1f0d | 10113 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
a3f97cbb JW |
10114 | add_abstract_origin_attribute (subr_die, origin); |
10115 | } | |
bdb669cb JM |
10116 | else if (old_die) |
10117 | { | |
981975b6 | 10118 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
a94dbf2c | 10119 | |
1edf43d6 JM |
10120 | if (!get_AT_flag (old_die, DW_AT_declaration) |
10121 | /* We can have a normal definition following an inline one in the | |
10122 | case of redefinition of GNU C extern inlines. | |
10123 | It seems reasonable to use AT_specification in this case. */ | |
10124 | && !get_AT_unsigned (old_die, DW_AT_inline)) | |
b75ab88b NC |
10125 | { |
10126 | /* ??? This can happen if there is a bug in the program, for | |
10127 | instance, if it has duplicate function definitions. Ideally, | |
10128 | we should detect this case and ignore it. For now, if we have | |
10129 | already reported an error, any error at all, then assume that | |
4fe9b91c | 10130 | we got here because of an input error, not a dwarf2 bug. */ |
b75ab88b NC |
10131 | if (errorcount) |
10132 | return; | |
10133 | abort (); | |
10134 | } | |
4b674448 JM |
10135 | |
10136 | /* If the definition comes from the same place as the declaration, | |
a94dbf2c JM |
10137 | maybe use the old DIE. We always want the DIE for this function |
10138 | that has the *_pc attributes to be under comp_unit_die so the | |
cb9e9d8d JM |
10139 | debugger can find it. We also need to do this for abstract |
10140 | instances of inlines, since the spec requires the out-of-line copy | |
10141 | to have the same parent. For local class methods, this doesn't | |
10142 | apply; we just use the old DIE. */ | |
10143 | if ((old_die->die_parent == comp_unit_die || context_die == NULL) | |
a96c67ec JM |
10144 | && (DECL_ARTIFICIAL (decl) |
10145 | || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index | |
10146 | && (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 10147 | == (unsigned) DECL_SOURCE_LINE (decl))))) |
bdb669cb | 10148 | { |
4b674448 JM |
10149 | subr_die = old_die; |
10150 | ||
10151 | /* Clear out the declaration attribute and the parm types. */ | |
10152 | remove_AT (subr_die, DW_AT_declaration); | |
10153 | remove_children (subr_die); | |
10154 | } | |
10155 | else | |
10156 | { | |
54ba1f0d | 10157 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
4b674448 | 10158 | add_AT_die_ref (subr_die, DW_AT_specification, old_die); |
bdb669cb JM |
10159 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
10160 | add_AT_unsigned (subr_die, DW_AT_decl_file, file_index); | |
10161 | if (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 10162 | != (unsigned) DECL_SOURCE_LINE (decl)) |
bdb669cb JM |
10163 | add_AT_unsigned |
10164 | (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
10165 | } | |
10166 | } | |
a3f97cbb JW |
10167 | else |
10168 | { | |
54ba1f0d | 10169 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
556273e0 | 10170 | |
273dbe67 JM |
10171 | if (TREE_PUBLIC (decl)) |
10172 | add_AT_flag (subr_die, DW_AT_external, 1); | |
71dfc51f | 10173 | |
a3f97cbb | 10174 | add_name_and_src_coords_attributes (subr_die, decl); |
4927276d JM |
10175 | if (debug_info_level > DINFO_LEVEL_TERSE) |
10176 | { | |
2ad9852d RK |
10177 | add_prototyped_attribute (subr_die, TREE_TYPE (decl)); |
10178 | add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)), | |
10179 | 0, 0, context_die); | |
4927276d | 10180 | } |
71dfc51f | 10181 | |
a3f97cbb | 10182 | add_pure_or_virtual_attribute (subr_die, decl); |
273dbe67 JM |
10183 | if (DECL_ARTIFICIAL (decl)) |
10184 | add_AT_flag (subr_die, DW_AT_artificial, 1); | |
2ad9852d | 10185 | |
a94dbf2c JM |
10186 | if (TREE_PROTECTED (decl)) |
10187 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected); | |
10188 | else if (TREE_PRIVATE (decl)) | |
10189 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 10190 | } |
4edb7b60 | 10191 | |
a94dbf2c JM |
10192 | if (declaration) |
10193 | { | |
2ad9852d | 10194 | if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline)) |
1edf43d6 JM |
10195 | { |
10196 | add_AT_flag (subr_die, DW_AT_declaration, 1); | |
10197 | ||
10198 | /* The first time we see a member function, it is in the context of | |
10199 | the class to which it belongs. We make sure of this by emitting | |
10200 | the class first. The next time is the definition, which is | |
10201 | handled above. The two may come from the same source text. */ | |
10202 | if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl)) | |
10203 | equate_decl_number_to_die (decl, subr_die); | |
10204 | } | |
a94dbf2c JM |
10205 | } |
10206 | else if (DECL_ABSTRACT (decl)) | |
a3f97cbb | 10207 | { |
10a11b75 | 10208 | if (DECL_INLINE (decl) && !flag_no_inline) |
61b32c02 | 10209 | { |
10a11b75 JM |
10210 | /* ??? Checking DECL_DEFER_OUTPUT is correct for static |
10211 | inline functions, but not for extern inline functions. | |
10212 | We can't get this completely correct because information | |
10213 | about whether the function was declared inline is not | |
10214 | saved anywhere. */ | |
10215 | if (DECL_DEFER_OUTPUT (decl)) | |
61b32c02 JM |
10216 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined); |
10217 | else | |
10a11b75 | 10218 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined); |
61b32c02 | 10219 | } |
61b32c02 | 10220 | else |
10a11b75 | 10221 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined); |
61b32c02 | 10222 | |
a3f97cbb JW |
10223 | equate_decl_number_to_die (decl, subr_die); |
10224 | } | |
10225 | else if (!DECL_EXTERNAL (decl)) | |
10226 | { | |
2ad9852d | 10227 | if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline)) |
ba7b35df | 10228 | equate_decl_number_to_die (decl, subr_die); |
71dfc51f | 10229 | |
5c90448c JM |
10230 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL, |
10231 | current_funcdef_number); | |
7d4440be | 10232 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id); |
5c90448c JM |
10233 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, |
10234 | current_funcdef_number); | |
a3f97cbb JW |
10235 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id); |
10236 | ||
d291dd49 JM |
10237 | add_pubname (decl, subr_die); |
10238 | add_arange (decl, subr_die); | |
10239 | ||
a3f97cbb | 10240 | #ifdef MIPS_DEBUGGING_INFO |
a3f97cbb JW |
10241 | /* Add a reference to the FDE for this routine. */ |
10242 | add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde); | |
10243 | #endif | |
10244 | ||
810429b7 JM |
10245 | /* Define the "frame base" location for this routine. We use the |
10246 | frame pointer or stack pointer registers, since the RTL for local | |
10247 | variables is relative to one of them. */ | |
b1ccbc24 RK |
10248 | fp_reg |
10249 | = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx; | |
10250 | add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg)); | |
a3f97cbb | 10251 | |
ef76d03b JW |
10252 | #if 0 |
10253 | /* ??? This fails for nested inline functions, because context_display | |
10254 | is not part of the state saved/restored for inline functions. */ | |
88dad228 | 10255 | if (current_function_needs_context) |
ef76d03b JW |
10256 | add_AT_location_description (subr_die, DW_AT_static_link, |
10257 | lookup_static_chain (decl)); | |
10258 | #endif | |
a3f97cbb JW |
10259 | } |
10260 | ||
10261 | /* Now output descriptions of the arguments for this function. This gets | |
556273e0 | 10262 | (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list |
a3f97cbb JW |
10263 | for a FUNCTION_DECL doesn't indicate cases where there was a trailing |
10264 | `...' at the end of the formal parameter list. In order to find out if | |
10265 | there was a trailing ellipsis or not, we must instead look at the type | |
10266 | associated with the FUNCTION_DECL. This will be a node of type | |
10267 | FUNCTION_TYPE. If the chain of type nodes hanging off of this | |
556273e0 | 10268 | FUNCTION_TYPE node ends with a void_type_node then there should *not* be |
a3f97cbb | 10269 | an ellipsis at the end. */ |
71dfc51f | 10270 | |
a3f97cbb | 10271 | /* In the case where we are describing a mere function declaration, all we |
556273e0 | 10272 | need to do here (and all we *can* do here) is to describe the *types* of |
a3f97cbb | 10273 | its formal parameters. */ |
4927276d | 10274 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 10275 | ; |
4edb7b60 | 10276 | else if (declaration) |
5daf7c0a | 10277 | gen_formal_types_die (decl, subr_die); |
a3f97cbb JW |
10278 | else |
10279 | { | |
10280 | /* Generate DIEs to represent all known formal parameters */ | |
b3694847 SS |
10281 | tree arg_decls = DECL_ARGUMENTS (decl); |
10282 | tree parm; | |
a3f97cbb JW |
10283 | |
10284 | /* When generating DIEs, generate the unspecified_parameters DIE | |
10285 | instead if we come across the arg "__builtin_va_alist" */ | |
10286 | for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) | |
71dfc51f RK |
10287 | if (TREE_CODE (parm) == PARM_DECL) |
10288 | { | |
db3cf6fb MS |
10289 | if (DECL_NAME (parm) |
10290 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), | |
10291 | "__builtin_va_alist")) | |
71dfc51f RK |
10292 | gen_unspecified_parameters_die (parm, subr_die); |
10293 | else | |
10294 | gen_decl_die (parm, subr_die); | |
10295 | } | |
a3f97cbb | 10296 | |
4fe9b91c | 10297 | /* Decide whether we need an unspecified_parameters DIE at the end. |
556273e0 | 10298 | There are 2 more cases to do this for: 1) the ansi ... declaration - |
a3f97cbb JW |
10299 | this is detectable when the end of the arg list is not a |
10300 | void_type_node 2) an unprototyped function declaration (not a | |
10301 | definition). This just means that we have no info about the | |
10302 | parameters at all. */ | |
10303 | fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
71dfc51f | 10304 | if (fn_arg_types != NULL) |
a3f97cbb JW |
10305 | { |
10306 | /* this is the prototyped case, check for ... */ | |
10307 | if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) | |
71dfc51f | 10308 | gen_unspecified_parameters_die (decl, subr_die); |
a3f97cbb | 10309 | } |
71dfc51f RK |
10310 | else if (DECL_INITIAL (decl) == NULL_TREE) |
10311 | gen_unspecified_parameters_die (decl, subr_die); | |
a3f97cbb JW |
10312 | } |
10313 | ||
10314 | /* Output Dwarf info for all of the stuff within the body of the function | |
10315 | (if it has one - it may be just a declaration). */ | |
10316 | outer_scope = DECL_INITIAL (decl); | |
10317 | ||
2ad9852d RK |
10318 | /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent |
10319 | a function. This BLOCK actually represents the outermost binding contour | |
10320 | for the function, i.e. the contour in which the function's formal | |
10321 | parameters and labels get declared. Curiously, it appears that the front | |
10322 | end doesn't actually put the PARM_DECL nodes for the current function onto | |
10323 | the BLOCK_VARS list for this outer scope, but are strung off of the | |
10324 | DECL_ARGUMENTS list for the function instead. | |
10325 | ||
10326 | The BLOCK_VARS list for the `outer_scope' does provide us with a list of | |
10327 | the LABEL_DECL nodes for the function however, and we output DWARF info | |
10328 | for those in decls_for_scope. Just within the `outer_scope' there will be | |
10329 | a BLOCK node representing the function's outermost pair of curly braces, | |
10330 | and any blocks used for the base and member initializers of a C++ | |
d7248bff | 10331 | constructor function. */ |
4edb7b60 | 10332 | if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK) |
7e23cb16 JM |
10333 | { |
10334 | current_function_has_inlines = 0; | |
10335 | decls_for_scope (outer_scope, subr_die, 0); | |
71dfc51f | 10336 | |
ce61cc73 | 10337 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
7e23cb16 JM |
10338 | if (current_function_has_inlines) |
10339 | { | |
10340 | add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1); | |
10341 | if (! comp_unit_has_inlines) | |
10342 | { | |
10343 | add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1); | |
10344 | comp_unit_has_inlines = 1; | |
10345 | } | |
10346 | } | |
10347 | #endif | |
10348 | } | |
a3f97cbb JW |
10349 | } |
10350 | ||
10351 | /* Generate a DIE to represent a declared data object. */ | |
71dfc51f | 10352 | |
a3f97cbb JW |
10353 | static void |
10354 | gen_variable_die (decl, context_die) | |
b3694847 SS |
10355 | tree decl; |
10356 | dw_die_ref context_die; | |
a3f97cbb | 10357 | { |
b3694847 | 10358 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 10359 | dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl); |
71dfc51f | 10360 | |
bdb669cb | 10361 | dw_die_ref old_die = lookup_decl_die (decl); |
9765e357 JM |
10362 | int declaration = (DECL_EXTERNAL (decl) |
10363 | || class_scope_p (context_die)); | |
4edb7b60 | 10364 | |
a3f97cbb | 10365 | if (origin != NULL) |
71dfc51f | 10366 | add_abstract_origin_attribute (var_die, origin); |
2ad9852d | 10367 | |
f76b8156 | 10368 | /* Loop unrolling can create multiple blocks that refer to the same |
2ad9852d RK |
10369 | static variable, so we must test for the DW_AT_declaration flag. |
10370 | ||
10371 | ??? Loop unrolling/reorder_blocks should perhaps be rewritten to | |
f76b8156 | 10372 | copy decls and set the DECL_ABSTRACT flag on them instead of |
2ad9852d RK |
10373 | sharing them. |
10374 | ||
10375 | ??? Duplicated blocks have been rewritten to use .debug_ranges. */ | |
f76b8156 JW |
10376 | else if (old_die && TREE_STATIC (decl) |
10377 | && get_AT_flag (old_die, DW_AT_declaration) == 1) | |
bdb669cb | 10378 | { |
e689ae67 | 10379 | /* This is a definition of a C++ class level static. */ |
bdb669cb JM |
10380 | add_AT_die_ref (var_die, DW_AT_specification, old_die); |
10381 | if (DECL_NAME (decl)) | |
10382 | { | |
981975b6 | 10383 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
71dfc51f | 10384 | |
bdb669cb JM |
10385 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
10386 | add_AT_unsigned (var_die, DW_AT_decl_file, file_index); | |
71dfc51f | 10387 | |
bdb669cb | 10388 | if (get_AT_unsigned (old_die, DW_AT_decl_line) |
556273e0 | 10389 | != (unsigned) DECL_SOURCE_LINE (decl)) |
71dfc51f RK |
10390 | |
10391 | add_AT_unsigned (var_die, DW_AT_decl_line, | |
10392 | DECL_SOURCE_LINE (decl)); | |
bdb669cb JM |
10393 | } |
10394 | } | |
a3f97cbb JW |
10395 | else |
10396 | { | |
10397 | add_name_and_src_coords_attributes (var_die, decl); | |
2ad9852d | 10398 | add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl), |
a3f97cbb | 10399 | TREE_THIS_VOLATILE (decl), context_die); |
71dfc51f | 10400 | |
273dbe67 JM |
10401 | if (TREE_PUBLIC (decl)) |
10402 | add_AT_flag (var_die, DW_AT_external, 1); | |
71dfc51f | 10403 | |
273dbe67 JM |
10404 | if (DECL_ARTIFICIAL (decl)) |
10405 | add_AT_flag (var_die, DW_AT_artificial, 1); | |
71dfc51f | 10406 | |
a94dbf2c JM |
10407 | if (TREE_PROTECTED (decl)) |
10408 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected); | |
10409 | else if (TREE_PRIVATE (decl)) | |
10410 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 10411 | } |
4edb7b60 JM |
10412 | |
10413 | if (declaration) | |
10414 | add_AT_flag (var_die, DW_AT_declaration, 1); | |
556273e0 | 10415 | |
9765e357 | 10416 | if (class_scope_p (context_die) || DECL_ABSTRACT (decl)) |
4edb7b60 JM |
10417 | equate_decl_number_to_die (decl, var_die); |
10418 | ||
10419 | if (! declaration && ! DECL_ABSTRACT (decl)) | |
a3f97cbb JW |
10420 | { |
10421 | add_location_or_const_value_attribute (var_die, decl); | |
d291dd49 | 10422 | add_pubname (decl, var_die); |
a3f97cbb | 10423 | } |
1bfb5f8f JM |
10424 | else |
10425 | tree_add_const_value_attribute (var_die, decl); | |
a3f97cbb JW |
10426 | } |
10427 | ||
10428 | /* Generate a DIE to represent a label identifier. */ | |
71dfc51f | 10429 | |
a3f97cbb JW |
10430 | static void |
10431 | gen_label_die (decl, context_die) | |
b3694847 SS |
10432 | tree decl; |
10433 | dw_die_ref context_die; | |
a3f97cbb | 10434 | { |
b3694847 | 10435 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 10436 | dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl); |
b3694847 | 10437 | rtx insn; |
a3f97cbb | 10438 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 10439 | |
a3f97cbb | 10440 | if (origin != NULL) |
71dfc51f | 10441 | add_abstract_origin_attribute (lbl_die, origin); |
a3f97cbb | 10442 | else |
71dfc51f RK |
10443 | add_name_and_src_coords_attributes (lbl_die, decl); |
10444 | ||
a3f97cbb | 10445 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 10446 | equate_decl_number_to_die (decl, lbl_die); |
a3f97cbb JW |
10447 | else |
10448 | { | |
10449 | insn = DECL_RTL (decl); | |
088e7160 NC |
10450 | |
10451 | /* Deleted labels are programmer specified labels which have been | |
10452 | eliminated because of various optimisations. We still emit them | |
10453 | here so that it is possible to put breakpoints on them. */ | |
10454 | if (GET_CODE (insn) == CODE_LABEL | |
10455 | || ((GET_CODE (insn) == NOTE | |
10456 | && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))) | |
a3f97cbb | 10457 | { |
556273e0 KH |
10458 | /* When optimization is enabled (via -O) some parts of the compiler |
10459 | (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which | |
a3f97cbb JW |
10460 | represent source-level labels which were explicitly declared by |
10461 | the user. This really shouldn't be happening though, so catch | |
10462 | it if it ever does happen. */ | |
10463 | if (INSN_DELETED_P (insn)) | |
71dfc51f RK |
10464 | abort (); |
10465 | ||
66234570 | 10466 | ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn)); |
a3f97cbb JW |
10467 | add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); |
10468 | } | |
10469 | } | |
10470 | } | |
10471 | ||
10472 | /* Generate a DIE for a lexical block. */ | |
71dfc51f | 10473 | |
a3f97cbb | 10474 | static void |
d7248bff | 10475 | gen_lexical_block_die (stmt, context_die, depth) |
b3694847 SS |
10476 | tree stmt; |
10477 | dw_die_ref context_die; | |
d7248bff | 10478 | int depth; |
a3f97cbb | 10479 | { |
54ba1f0d | 10480 | dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt); |
a3f97cbb | 10481 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f RK |
10482 | |
10483 | if (! BLOCK_ABSTRACT (stmt)) | |
a3f97cbb | 10484 | { |
a20612aa RH |
10485 | if (BLOCK_FRAGMENT_CHAIN (stmt)) |
10486 | { | |
10487 | tree chain; | |
10488 | ||
2bee6045 | 10489 | add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt)); |
a20612aa RH |
10490 | |
10491 | chain = BLOCK_FRAGMENT_CHAIN (stmt); | |
10492 | do | |
10493 | { | |
10494 | add_ranges (chain); | |
10495 | chain = BLOCK_FRAGMENT_CHAIN (chain); | |
10496 | } | |
10497 | while (chain); | |
10498 | add_ranges (NULL); | |
10499 | } | |
10500 | else | |
10501 | { | |
10502 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, | |
10503 | BLOCK_NUMBER (stmt)); | |
10504 | add_AT_lbl_id (stmt_die, DW_AT_low_pc, label); | |
10505 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, | |
10506 | BLOCK_NUMBER (stmt)); | |
10507 | add_AT_lbl_id (stmt_die, DW_AT_high_pc, label); | |
10508 | } | |
a3f97cbb | 10509 | } |
71dfc51f | 10510 | |
d7248bff | 10511 | decls_for_scope (stmt, stmt_die, depth); |
a3f97cbb JW |
10512 | } |
10513 | ||
10514 | /* Generate a DIE for an inlined subprogram. */ | |
71dfc51f | 10515 | |
a3f97cbb | 10516 | static void |
d7248bff | 10517 | gen_inlined_subroutine_die (stmt, context_die, depth) |
b3694847 SS |
10518 | tree stmt; |
10519 | dw_die_ref context_die; | |
d7248bff | 10520 | int depth; |
a3f97cbb | 10521 | { |
71dfc51f | 10522 | if (! BLOCK_ABSTRACT (stmt)) |
a3f97cbb | 10523 | { |
b3694847 | 10524 | dw_die_ref subr_die |
54ba1f0d | 10525 | = new_die (DW_TAG_inlined_subroutine, context_die, stmt); |
b3694847 | 10526 | tree decl = block_ultimate_origin (stmt); |
d7248bff | 10527 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 10528 | |
10a11b75 | 10529 | /* Emit info for the abstract instance first, if we haven't yet. */ |
1edf43d6 | 10530 | dwarf2out_abstract_function (decl); |
10a11b75 | 10531 | |
ab72d377 | 10532 | add_abstract_origin_attribute (subr_die, decl); |
5c90448c | 10533 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
18c038b9 | 10534 | BLOCK_NUMBER (stmt)); |
a3f97cbb | 10535 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label); |
18c038b9 MM |
10536 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, |
10537 | BLOCK_NUMBER (stmt)); | |
a3f97cbb | 10538 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label); |
d7248bff | 10539 | decls_for_scope (stmt, subr_die, depth); |
7e23cb16 | 10540 | current_function_has_inlines = 1; |
a3f97cbb | 10541 | } |
a3f97cbb JW |
10542 | } |
10543 | ||
10544 | /* Generate a DIE for a field in a record, or structure. */ | |
71dfc51f | 10545 | |
a3f97cbb JW |
10546 | static void |
10547 | gen_field_die (decl, context_die) | |
b3694847 SS |
10548 | tree decl; |
10549 | dw_die_ref context_die; | |
a3f97cbb | 10550 | { |
54ba1f0d | 10551 | dw_die_ref decl_die = new_die (DW_TAG_member, context_die, decl); |
71dfc51f | 10552 | |
a3f97cbb | 10553 | add_name_and_src_coords_attributes (decl_die, decl); |
a3f97cbb JW |
10554 | add_type_attribute (decl_die, member_declared_type (decl), |
10555 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl), | |
10556 | context_die); | |
71dfc51f | 10557 | |
a3f97cbb JW |
10558 | if (DECL_BIT_FIELD_TYPE (decl)) |
10559 | { | |
10560 | add_byte_size_attribute (decl_die, decl); | |
10561 | add_bit_size_attribute (decl_die, decl); | |
10562 | add_bit_offset_attribute (decl_die, decl); | |
10563 | } | |
71dfc51f | 10564 | |
a94dbf2c JM |
10565 | if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE) |
10566 | add_data_member_location_attribute (decl_die, decl); | |
71dfc51f | 10567 | |
273dbe67 JM |
10568 | if (DECL_ARTIFICIAL (decl)) |
10569 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
71dfc51f | 10570 | |
a94dbf2c JM |
10571 | if (TREE_PROTECTED (decl)) |
10572 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected); | |
10573 | else if (TREE_PRIVATE (decl)) | |
10574 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb JW |
10575 | } |
10576 | ||
ab72d377 JM |
10577 | #if 0 |
10578 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. | |
10579 | Use modified_type_die instead. | |
a3f97cbb JW |
10580 | We keep this code here just in case these types of DIEs may be needed to |
10581 | represent certain things in other languages (e.g. Pascal) someday. */ | |
2ad9852d | 10582 | |
a3f97cbb JW |
10583 | static void |
10584 | gen_pointer_type_die (type, context_die) | |
b3694847 SS |
10585 | tree type; |
10586 | dw_die_ref context_die; | |
a3f97cbb | 10587 | { |
b3694847 | 10588 | dw_die_ref ptr_die |
54ba1f0d | 10589 | = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type); |
71dfc51f | 10590 | |
a3f97cbb | 10591 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 10592 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 10593 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb JW |
10594 | } |
10595 | ||
ab72d377 JM |
10596 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. |
10597 | Use modified_type_die instead. | |
a3f97cbb JW |
10598 | We keep this code here just in case these types of DIEs may be needed to |
10599 | represent certain things in other languages (e.g. Pascal) someday. */ | |
2ad9852d | 10600 | |
a3f97cbb JW |
10601 | static void |
10602 | gen_reference_type_die (type, context_die) | |
b3694847 SS |
10603 | tree type; |
10604 | dw_die_ref context_die; | |
a3f97cbb | 10605 | { |
b3694847 | 10606 | dw_die_ref ref_die |
54ba1f0d | 10607 | = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type); |
71dfc51f | 10608 | |
a3f97cbb | 10609 | equate_type_number_to_die (type, ref_die); |
a3f97cbb | 10610 | add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 10611 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb | 10612 | } |
ab72d377 | 10613 | #endif |
a3f97cbb JW |
10614 | |
10615 | /* Generate a DIE for a pointer to a member type. */ | |
2ad9852d | 10616 | |
a3f97cbb JW |
10617 | static void |
10618 | gen_ptr_to_mbr_type_die (type, context_die) | |
b3694847 SS |
10619 | tree type; |
10620 | dw_die_ref context_die; | |
a3f97cbb | 10621 | { |
b3694847 | 10622 | dw_die_ref ptr_die |
54ba1f0d RH |
10623 | = new_die (DW_TAG_ptr_to_member_type, |
10624 | scope_die_for (type, context_die), type); | |
71dfc51f | 10625 | |
a3f97cbb | 10626 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 10627 | add_AT_die_ref (ptr_die, DW_AT_containing_type, |
bdb669cb | 10628 | lookup_type_die (TYPE_OFFSET_BASETYPE (type))); |
a3f97cbb JW |
10629 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
10630 | } | |
10631 | ||
10632 | /* Generate the DIE for the compilation unit. */ | |
71dfc51f | 10633 | |
a96c67ec JM |
10634 | static dw_die_ref |
10635 | gen_compile_unit_die (filename) | |
b3694847 | 10636 | const char *filename; |
a3f97cbb | 10637 | { |
b3694847 | 10638 | dw_die_ref die; |
a3f97cbb | 10639 | char producer[250]; |
d3e3972c | 10640 | const char *wd = getpwd (); |
3ac88239 | 10641 | const char *language_string = lang_hooks.name; |
a96c67ec | 10642 | int language; |
a3f97cbb | 10643 | |
54ba1f0d | 10644 | die = new_die (DW_TAG_compile_unit, NULL, NULL); |
a96c67ec | 10645 | add_name_attribute (die, filename); |
bdb669cb | 10646 | |
a96c67ec JM |
10647 | if (wd != NULL && filename[0] != DIR_SEPARATOR) |
10648 | add_AT_string (die, DW_AT_comp_dir, wd); | |
a3f97cbb JW |
10649 | |
10650 | sprintf (producer, "%s %s", language_string, version_string); | |
10651 | ||
10652 | #ifdef MIPS_DEBUGGING_INFO | |
10653 | /* The MIPS/SGI compilers place the 'cc' command line options in the producer | |
10654 | string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do | |
10655 | not appear in the producer string, the debugger reaches the conclusion | |
10656 | that the object file is stripped and has no debugging information. | |
10657 | To get the MIPS/SGI debugger to believe that there is debugging | |
10658 | information in the object file, we add a -g to the producer string. */ | |
4927276d JM |
10659 | if (debug_info_level > DINFO_LEVEL_TERSE) |
10660 | strcat (producer, " -g"); | |
a3f97cbb JW |
10661 | #endif |
10662 | ||
a96c67ec | 10663 | add_AT_string (die, DW_AT_producer, producer); |
a9d38797 | 10664 | |
a3f97cbb | 10665 | if (strcmp (language_string, "GNU C++") == 0) |
a96c67ec | 10666 | language = DW_LANG_C_plus_plus; |
a3f97cbb | 10667 | else if (strcmp (language_string, "GNU Ada") == 0) |
a96c67ec | 10668 | language = DW_LANG_Ada83; |
a9d38797 | 10669 | else if (strcmp (language_string, "GNU F77") == 0) |
a96c67ec | 10670 | language = DW_LANG_Fortran77; |
bc28c45b | 10671 | else if (strcmp (language_string, "GNU Pascal") == 0) |
a96c67ec | 10672 | language = DW_LANG_Pascal83; |
28985b81 AG |
10673 | else if (strcmp (language_string, "GNU Java") == 0) |
10674 | language = DW_LANG_Java; | |
a3f97cbb | 10675 | else if (flag_traditional) |
a96c67ec | 10676 | language = DW_LANG_C; |
a3f97cbb | 10677 | else |
a96c67ec | 10678 | language = DW_LANG_C89; |
a9d38797 | 10679 | |
a96c67ec | 10680 | add_AT_unsigned (die, DW_AT_language, language); |
a96c67ec | 10681 | return die; |
a3f97cbb JW |
10682 | } |
10683 | ||
10684 | /* Generate a DIE for a string type. */ | |
71dfc51f | 10685 | |
a3f97cbb JW |
10686 | static void |
10687 | gen_string_type_die (type, context_die) | |
b3694847 SS |
10688 | tree type; |
10689 | dw_die_ref context_die; | |
a3f97cbb | 10690 | { |
b3694847 | 10691 | dw_die_ref type_die |
54ba1f0d | 10692 | = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type); |
71dfc51f | 10693 | |
bdb669cb | 10694 | equate_type_number_to_die (type, type_die); |
a3f97cbb | 10695 | |
2ad9852d RK |
10696 | /* ??? Fudge the string length attribute for now. |
10697 | TODO: add string length info. */ | |
10698 | #if 0 | |
10699 | string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type))); | |
10700 | bound_representation (upper_bound, 0, 'u'); | |
10701 | #endif | |
a3f97cbb JW |
10702 | } |
10703 | ||
61b32c02 | 10704 | /* Generate the DIE for a base class. */ |
71dfc51f | 10705 | |
61b32c02 JM |
10706 | static void |
10707 | gen_inheritance_die (binfo, context_die) | |
b3694847 SS |
10708 | tree binfo; |
10709 | dw_die_ref context_die; | |
61b32c02 | 10710 | { |
54ba1f0d | 10711 | dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo); |
71dfc51f | 10712 | |
61b32c02 JM |
10713 | add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die); |
10714 | add_data_member_location_attribute (die, binfo); | |
71dfc51f | 10715 | |
61b32c02 JM |
10716 | if (TREE_VIA_VIRTUAL (binfo)) |
10717 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); | |
2ad9852d | 10718 | |
61b32c02 JM |
10719 | if (TREE_VIA_PUBLIC (binfo)) |
10720 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public); | |
10721 | else if (TREE_VIA_PROTECTED (binfo)) | |
10722 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected); | |
10723 | } | |
10724 | ||
956d6950 | 10725 | /* Generate a DIE for a class member. */ |
71dfc51f | 10726 | |
a3f97cbb JW |
10727 | static void |
10728 | gen_member_die (type, context_die) | |
b3694847 SS |
10729 | tree type; |
10730 | dw_die_ref context_die; | |
a3f97cbb | 10731 | { |
b3694847 | 10732 | tree member; |
10a11b75 | 10733 | dw_die_ref child; |
71dfc51f | 10734 | |
a3f97cbb JW |
10735 | /* If this is not an incomplete type, output descriptions of each of its |
10736 | members. Note that as we output the DIEs necessary to represent the | |
10737 | members of this record or union type, we will also be trying to output | |
10738 | DIEs to represent the *types* of those members. However the `type' | |
556273e0 | 10739 | function (above) will specifically avoid generating type DIEs for member |
eaec9b3d | 10740 | types *within* the list of member DIEs for this (containing) type except |
a3f97cbb JW |
10741 | for those types (of members) which are explicitly marked as also being |
10742 | members of this (containing) type themselves. The g++ front- end can | |
2ad9852d RK |
10743 | force any given type to be treated as a member of some other (containing) |
10744 | type by setting the TYPE_CONTEXT of the given (member) type to point to | |
10745 | the TREE node representing the appropriate (containing) type. */ | |
a3f97cbb | 10746 | |
61b32c02 JM |
10747 | /* First output info about the base classes. */ |
10748 | if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type)) | |
a3f97cbb | 10749 | { |
b3694847 SS |
10750 | tree bases = TYPE_BINFO_BASETYPES (type); |
10751 | int n_bases = TREE_VEC_LENGTH (bases); | |
10752 | int i; | |
61b32c02 JM |
10753 | |
10754 | for (i = 0; i < n_bases; i++) | |
10755 | gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die); | |
a3f97cbb JW |
10756 | } |
10757 | ||
61b32c02 JM |
10758 | /* Now output info about the data members and type members. */ |
10759 | for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member)) | |
10a11b75 JM |
10760 | { |
10761 | /* If we thought we were generating minimal debug info for TYPE | |
10762 | and then changed our minds, some of the member declarations | |
10763 | may have already been defined. Don't define them again, but | |
10764 | do put them in the right order. */ | |
10765 | ||
10766 | child = lookup_decl_die (member); | |
10767 | if (child) | |
10768 | splice_child_die (context_die, child); | |
10769 | else | |
10770 | gen_decl_die (member, context_die); | |
10771 | } | |
61b32c02 | 10772 | |
a3f97cbb | 10773 | /* Now output info about the function members (if any). */ |
61b32c02 | 10774 | for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member)) |
10a11b75 | 10775 | { |
5daf7c0a JM |
10776 | /* Don't include clones in the member list. */ |
10777 | if (DECL_ABSTRACT_ORIGIN (member)) | |
10778 | continue; | |
10779 | ||
10a11b75 JM |
10780 | child = lookup_decl_die (member); |
10781 | if (child) | |
10782 | splice_child_die (context_die, child); | |
10783 | else | |
10784 | gen_decl_die (member, context_die); | |
10785 | } | |
a3f97cbb JW |
10786 | } |
10787 | ||
10a11b75 JM |
10788 | /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG |
10789 | is set, we pretend that the type was never defined, so we only get the | |
10790 | member DIEs needed by later specification DIEs. */ | |
71dfc51f | 10791 | |
a3f97cbb | 10792 | static void |
273dbe67 | 10793 | gen_struct_or_union_type_die (type, context_die) |
b3694847 SS |
10794 | tree type; |
10795 | dw_die_ref context_die; | |
a3f97cbb | 10796 | { |
b3694847 SS |
10797 | dw_die_ref type_die = lookup_type_die (type); |
10798 | dw_die_ref scope_die = 0; | |
10799 | int nested = 0; | |
10a11b75 | 10800 | int complete = (TYPE_SIZE (type) |
65e1263a JW |
10801 | && (! TYPE_STUB_DECL (type) |
10802 | || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)))); | |
273dbe67 | 10803 | |
10a11b75 | 10804 | if (type_die && ! complete) |
273dbe67 | 10805 | return; |
a082c85a | 10806 | |
71dfc51f | 10807 | if (TYPE_CONTEXT (type) != NULL_TREE |
5f2f160c | 10808 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))) |
a082c85a JM |
10809 | nested = 1; |
10810 | ||
a94dbf2c | 10811 | scope_die = scope_die_for (type, context_die); |
a082c85a JM |
10812 | |
10813 | if (! type_die || (nested && scope_die == comp_unit_die)) | |
273dbe67 | 10814 | /* First occurrence of type or toplevel definition of nested class. */ |
a3f97cbb | 10815 | { |
b3694847 | 10816 | dw_die_ref old_die = type_die; |
71dfc51f | 10817 | |
a3f97cbb JW |
10818 | type_die = new_die (TREE_CODE (type) == RECORD_TYPE |
10819 | ? DW_TAG_structure_type : DW_TAG_union_type, | |
54ba1f0d | 10820 | scope_die, type); |
a3f97cbb | 10821 | equate_type_number_to_die (type, type_die); |
273dbe67 JM |
10822 | if (old_die) |
10823 | add_AT_die_ref (type_die, DW_AT_specification, old_die); | |
5de0e8d4 JM |
10824 | else |
10825 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 10826 | } |
4b674448 | 10827 | else |
273dbe67 | 10828 | remove_AT (type_die, DW_AT_declaration); |
a3f97cbb JW |
10829 | |
10830 | /* If this type has been completed, then give it a byte_size attribute and | |
10831 | then give a list of members. */ | |
2081603c | 10832 | if (complete) |
a3f97cbb | 10833 | { |
556273e0 | 10834 | /* Prevent infinite recursion in cases where the type of some member of |
a3f97cbb JW |
10835 | this type is expressed in terms of this type itself. */ |
10836 | TREE_ASM_WRITTEN (type) = 1; | |
273dbe67 | 10837 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 10838 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 10839 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 10840 | |
ef76d03b JW |
10841 | /* If the first reference to this type was as the return type of an |
10842 | inline function, then it may not have a parent. Fix this now. */ | |
10843 | if (type_die->die_parent == NULL) | |
10844 | add_child_die (scope_die, type_die); | |
10845 | ||
273dbe67 JM |
10846 | push_decl_scope (type); |
10847 | gen_member_die (type, type_die); | |
10848 | pop_decl_scope (); | |
71dfc51f | 10849 | |
a94dbf2c JM |
10850 | /* GNU extension: Record what type our vtable lives in. */ |
10851 | if (TYPE_VFIELD (type)) | |
10852 | { | |
10853 | tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type)); | |
71dfc51f | 10854 | |
de6e505e JM |
10855 | gen_type_die (vtype, context_die); |
10856 | add_AT_die_ref (type_die, DW_AT_containing_type, | |
10857 | lookup_type_die (vtype)); | |
a94dbf2c | 10858 | } |
a3f97cbb | 10859 | } |
4b674448 | 10860 | else |
8a8c3656 JM |
10861 | { |
10862 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a30d4514 | 10863 | |
9765e357 | 10864 | /* We don't need to do this for function-local types. */ |
9702143f RK |
10865 | if (TYPE_STUB_DECL (type) |
10866 | && ! decl_function_context (TYPE_STUB_DECL (type))) | |
2ad9852d | 10867 | VARRAY_PUSH_TREE (incomplete_types, type); |
8a8c3656 | 10868 | } |
a3f97cbb JW |
10869 | } |
10870 | ||
10871 | /* Generate a DIE for a subroutine _type_. */ | |
71dfc51f | 10872 | |
a3f97cbb JW |
10873 | static void |
10874 | gen_subroutine_type_die (type, context_die) | |
b3694847 SS |
10875 | tree type; |
10876 | dw_die_ref context_die; | |
a3f97cbb | 10877 | { |
b3694847 SS |
10878 | tree return_type = TREE_TYPE (type); |
10879 | dw_die_ref subr_die | |
54ba1f0d RH |
10880 | = new_die (DW_TAG_subroutine_type, |
10881 | scope_die_for (type, context_die), type); | |
71dfc51f | 10882 | |
a3f97cbb JW |
10883 | equate_type_number_to_die (type, subr_die); |
10884 | add_prototyped_attribute (subr_die, type); | |
a3f97cbb | 10885 | add_type_attribute (subr_die, return_type, 0, 0, context_die); |
a94dbf2c | 10886 | gen_formal_types_die (type, subr_die); |
a3f97cbb JW |
10887 | } |
10888 | ||
10889 | /* Generate a DIE for a type definition */ | |
71dfc51f | 10890 | |
a3f97cbb JW |
10891 | static void |
10892 | gen_typedef_die (decl, context_die) | |
b3694847 SS |
10893 | tree decl; |
10894 | dw_die_ref context_die; | |
a3f97cbb | 10895 | { |
b3694847 SS |
10896 | dw_die_ref type_die; |
10897 | tree origin; | |
a94dbf2c JM |
10898 | |
10899 | if (TREE_ASM_WRITTEN (decl)) | |
10900 | return; | |
a94dbf2c | 10901 | |
2ad9852d | 10902 | TREE_ASM_WRITTEN (decl) = 1; |
54ba1f0d | 10903 | type_die = new_die (DW_TAG_typedef, context_die, decl); |
a94dbf2c | 10904 | origin = decl_ultimate_origin (decl); |
a3f97cbb | 10905 | if (origin != NULL) |
a94dbf2c | 10906 | add_abstract_origin_attribute (type_die, origin); |
a3f97cbb JW |
10907 | else |
10908 | { | |
b3694847 | 10909 | tree type; |
2ad9852d | 10910 | |
a3f97cbb | 10911 | add_name_and_src_coords_attributes (type_die, decl); |
a94dbf2c JM |
10912 | if (DECL_ORIGINAL_TYPE (decl)) |
10913 | { | |
10914 | type = DECL_ORIGINAL_TYPE (decl); | |
62e3bf54 JM |
10915 | |
10916 | if (type == TREE_TYPE (decl)) | |
10917 | abort (); | |
10918 | else | |
10919 | equate_type_number_to_die (TREE_TYPE (decl), type_die); | |
a94dbf2c JM |
10920 | } |
10921 | else | |
10922 | type = TREE_TYPE (decl); | |
2ad9852d | 10923 | |
a94dbf2c JM |
10924 | add_type_attribute (type_die, type, TREE_READONLY (decl), |
10925 | TREE_THIS_VOLATILE (decl), context_die); | |
a3f97cbb | 10926 | } |
71dfc51f | 10927 | |
a3f97cbb | 10928 | if (DECL_ABSTRACT (decl)) |
a94dbf2c | 10929 | equate_decl_number_to_die (decl, type_die); |
a3f97cbb JW |
10930 | } |
10931 | ||
10932 | /* Generate a type description DIE. */ | |
71dfc51f | 10933 | |
a3f97cbb JW |
10934 | static void |
10935 | gen_type_die (type, context_die) | |
b3694847 SS |
10936 | tree type; |
10937 | dw_die_ref context_die; | |
a3f97cbb | 10938 | { |
348bb3c7 JM |
10939 | int need_pop; |
10940 | ||
71dfc51f RK |
10941 | if (type == NULL_TREE || type == error_mark_node) |
10942 | return; | |
a3f97cbb | 10943 | |
38e01259 | 10944 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
10945 | this type (i.e. without any const or volatile qualifiers) so get the |
10946 | main variant (i.e. the unqualified version) of this type now. */ | |
10947 | type = type_main_variant (type); | |
10948 | ||
10949 | if (TREE_ASM_WRITTEN (type)) | |
71dfc51f | 10950 | return; |
a3f97cbb | 10951 | |
a94dbf2c JM |
10952 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
10953 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
556273e0 | 10954 | { |
a94dbf2c JM |
10955 | TREE_ASM_WRITTEN (type) = 1; |
10956 | gen_decl_die (TYPE_NAME (type), context_die); | |
10957 | return; | |
10958 | } | |
10959 | ||
a3f97cbb JW |
10960 | switch (TREE_CODE (type)) |
10961 | { | |
10962 | case ERROR_MARK: | |
10963 | break; | |
10964 | ||
10965 | case POINTER_TYPE: | |
10966 | case REFERENCE_TYPE: | |
956d6950 JL |
10967 | /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This |
10968 | ensures that the gen_type_die recursion will terminate even if the | |
10969 | type is recursive. Recursive types are possible in Ada. */ | |
10970 | /* ??? We could perhaps do this for all types before the switch | |
10971 | statement. */ | |
10972 | TREE_ASM_WRITTEN (type) = 1; | |
10973 | ||
a3f97cbb JW |
10974 | /* For these types, all that is required is that we output a DIE (or a |
10975 | set of DIEs) to represent the "basis" type. */ | |
10976 | gen_type_die (TREE_TYPE (type), context_die); | |
10977 | break; | |
10978 | ||
10979 | case OFFSET_TYPE: | |
556273e0 | 10980 | /* This code is used for C++ pointer-to-data-member types. |
71dfc51f | 10981 | Output a description of the relevant class type. */ |
a3f97cbb | 10982 | gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die); |
71dfc51f | 10983 | |
a3f97cbb JW |
10984 | /* Output a description of the type of the object pointed to. */ |
10985 | gen_type_die (TREE_TYPE (type), context_die); | |
71dfc51f | 10986 | |
a3f97cbb JW |
10987 | /* Now output a DIE to represent this pointer-to-data-member type |
10988 | itself. */ | |
10989 | gen_ptr_to_mbr_type_die (type, context_die); | |
10990 | break; | |
10991 | ||
10992 | case SET_TYPE: | |
10993 | gen_type_die (TYPE_DOMAIN (type), context_die); | |
10994 | gen_set_type_die (type, context_die); | |
10995 | break; | |
10996 | ||
10997 | case FILE_TYPE: | |
10998 | gen_type_die (TREE_TYPE (type), context_die); | |
10999 | abort (); /* No way to represent these in Dwarf yet! */ | |
11000 | break; | |
11001 | ||
11002 | case FUNCTION_TYPE: | |
11003 | /* Force out return type (in case it wasn't forced out already). */ | |
11004 | gen_type_die (TREE_TYPE (type), context_die); | |
11005 | gen_subroutine_type_die (type, context_die); | |
11006 | break; | |
11007 | ||
11008 | case METHOD_TYPE: | |
11009 | /* Force out return type (in case it wasn't forced out already). */ | |
11010 | gen_type_die (TREE_TYPE (type), context_die); | |
11011 | gen_subroutine_type_die (type, context_die); | |
11012 | break; | |
11013 | ||
11014 | case ARRAY_TYPE: | |
11015 | if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE) | |
11016 | { | |
11017 | gen_type_die (TREE_TYPE (type), context_die); | |
11018 | gen_string_type_die (type, context_die); | |
11019 | } | |
11020 | else | |
71dfc51f | 11021 | gen_array_type_die (type, context_die); |
a3f97cbb JW |
11022 | break; |
11023 | ||
4061f623 BS |
11024 | case VECTOR_TYPE: |
11025 | gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die); | |
11026 | break; | |
11027 | ||
a3f97cbb JW |
11028 | case ENUMERAL_TYPE: |
11029 | case RECORD_TYPE: | |
11030 | case UNION_TYPE: | |
11031 | case QUAL_UNION_TYPE: | |
2ad9852d RK |
11032 | /* If this is a nested type whose containing class hasn't been written |
11033 | out yet, writing it out will cover this one, too. This does not apply | |
11034 | to instantiations of member class templates; they need to be added to | |
11035 | the containing class as they are generated. FIXME: This hurts the | |
11036 | idea of combining type decls from multiple TUs, since we can't predict | |
11037 | what set of template instantiations we'll get. */ | |
a082c85a | 11038 | if (TYPE_CONTEXT (type) |
5f2f160c | 11039 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) |
a082c85a | 11040 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) |
a94dbf2c JM |
11041 | { |
11042 | gen_type_die (TYPE_CONTEXT (type), context_die); | |
11043 | ||
348bb3c7 | 11044 | if (TREE_ASM_WRITTEN (type)) |
a94dbf2c JM |
11045 | return; |
11046 | ||
11047 | /* If that failed, attach ourselves to the stub. */ | |
11048 | push_decl_scope (TYPE_CONTEXT (type)); | |
11049 | context_die = lookup_type_die (TYPE_CONTEXT (type)); | |
348bb3c7 | 11050 | need_pop = 1; |
a94dbf2c | 11051 | } |
348bb3c7 JM |
11052 | else |
11053 | need_pop = 0; | |
a94dbf2c JM |
11054 | |
11055 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
273dbe67 | 11056 | gen_enumeration_type_die (type, context_die); |
a3f97cbb | 11057 | else |
273dbe67 | 11058 | gen_struct_or_union_type_die (type, context_die); |
4b674448 | 11059 | |
348bb3c7 | 11060 | if (need_pop) |
a94dbf2c JM |
11061 | pop_decl_scope (); |
11062 | ||
4b674448 | 11063 | /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix |
a082c85a JM |
11064 | it up if it is ever completed. gen_*_type_die will set it for us |
11065 | when appropriate. */ | |
11066 | return; | |
a3f97cbb JW |
11067 | |
11068 | case VOID_TYPE: | |
11069 | case INTEGER_TYPE: | |
11070 | case REAL_TYPE: | |
11071 | case COMPLEX_TYPE: | |
11072 | case BOOLEAN_TYPE: | |
11073 | case CHAR_TYPE: | |
11074 | /* No DIEs needed for fundamental types. */ | |
11075 | break; | |
11076 | ||
11077 | case LANG_TYPE: | |
11078 | /* No Dwarf representation currently defined. */ | |
11079 | break; | |
11080 | ||
11081 | default: | |
11082 | abort (); | |
11083 | } | |
11084 | ||
11085 | TREE_ASM_WRITTEN (type) = 1; | |
11086 | } | |
11087 | ||
11088 | /* Generate a DIE for a tagged type instantiation. */ | |
71dfc51f | 11089 | |
a3f97cbb JW |
11090 | static void |
11091 | gen_tagged_type_instantiation_die (type, context_die) | |
b3694847 SS |
11092 | tree type; |
11093 | dw_die_ref context_die; | |
a3f97cbb | 11094 | { |
71dfc51f RK |
11095 | if (type == NULL_TREE || type == error_mark_node) |
11096 | return; | |
a3f97cbb | 11097 | |
38e01259 | 11098 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
11099 | this type (i.e. without any const or volatile qualifiers) so make sure |
11100 | that we have the main variant (i.e. the unqualified version) of this | |
11101 | type now. */ | |
bbc6ae08 | 11102 | if (type != type_main_variant (type)) |
3a88cbd1 | 11103 | abort (); |
a3f97cbb | 11104 | |
203588e7 | 11105 | /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is |
bbc6ae08 | 11106 | an instance of an unresolved type. */ |
556273e0 | 11107 | |
a3f97cbb JW |
11108 | switch (TREE_CODE (type)) |
11109 | { | |
11110 | case ERROR_MARK: | |
11111 | break; | |
11112 | ||
11113 | case ENUMERAL_TYPE: | |
11114 | gen_inlined_enumeration_type_die (type, context_die); | |
11115 | break; | |
11116 | ||
11117 | case RECORD_TYPE: | |
11118 | gen_inlined_structure_type_die (type, context_die); | |
11119 | break; | |
11120 | ||
11121 | case UNION_TYPE: | |
11122 | case QUAL_UNION_TYPE: | |
11123 | gen_inlined_union_type_die (type, context_die); | |
11124 | break; | |
11125 | ||
11126 | default: | |
71dfc51f | 11127 | abort (); |
a3f97cbb JW |
11128 | } |
11129 | } | |
11130 | ||
11131 | /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the | |
11132 | things which are local to the given block. */ | |
71dfc51f | 11133 | |
a3f97cbb | 11134 | static void |
d7248bff | 11135 | gen_block_die (stmt, context_die, depth) |
b3694847 SS |
11136 | tree stmt; |
11137 | dw_die_ref context_die; | |
d7248bff | 11138 | int depth; |
a3f97cbb | 11139 | { |
b3694847 SS |
11140 | int must_output_die = 0; |
11141 | tree origin; | |
11142 | tree decl; | |
11143 | enum tree_code origin_code; | |
a3f97cbb JW |
11144 | |
11145 | /* Ignore blocks never really used to make RTL. */ | |
1e7f092a JM |
11146 | if (stmt == NULL_TREE || !TREE_USED (stmt) |
11147 | || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt))) | |
71dfc51f | 11148 | return; |
a3f97cbb | 11149 | |
a20612aa RH |
11150 | /* If the block is one fragment of a non-contiguous block, do not |
11151 | process the variables, since they will have been done by the | |
11152 | origin block. Do process subblocks. */ | |
11153 | if (BLOCK_FRAGMENT_ORIGIN (stmt)) | |
11154 | { | |
11155 | tree sub; | |
11156 | ||
2ad9852d | 11157 | for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub)) |
a20612aa | 11158 | gen_block_die (sub, context_die, depth + 1); |
2ad9852d | 11159 | |
a20612aa RH |
11160 | return; |
11161 | } | |
11162 | ||
a3f97cbb JW |
11163 | /* Determine the "ultimate origin" of this block. This block may be an |
11164 | inlined instance of an inlined instance of inline function, so we have | |
11165 | to trace all of the way back through the origin chain to find out what | |
11166 | sort of node actually served as the original seed for the creation of | |
11167 | the current block. */ | |
11168 | origin = block_ultimate_origin (stmt); | |
11169 | origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; | |
11170 | ||
11171 | /* Determine if we need to output any Dwarf DIEs at all to represent this | |
11172 | block. */ | |
11173 | if (origin_code == FUNCTION_DECL) | |
71dfc51f RK |
11174 | /* The outer scopes for inlinings *must* always be represented. We |
11175 | generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */ | |
11176 | must_output_die = 1; | |
a3f97cbb JW |
11177 | else |
11178 | { | |
11179 | /* In the case where the current block represents an inlining of the | |
556273e0 | 11180 | "body block" of an inline function, we must *NOT* output any DIE for |
2ad9852d RK |
11181 | this block because we have already output a DIE to represent the whole |
11182 | inlined function scope and the "body block" of any function doesn't | |
11183 | really represent a different scope according to ANSI C rules. So we | |
11184 | check here to make sure that this block does not represent a "body | |
11185 | block inlining" before trying to set the MUST_OUTPUT_DIE flag. */ | |
d7248bff | 11186 | if (! is_body_block (origin ? origin : stmt)) |
a3f97cbb JW |
11187 | { |
11188 | /* Determine if this block directly contains any "significant" | |
11189 | local declarations which we will need to output DIEs for. */ | |
11190 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
71dfc51f RK |
11191 | /* We are not in terse mode so *any* local declaration counts |
11192 | as being a "significant" one. */ | |
11193 | must_output_die = (BLOCK_VARS (stmt) != NULL); | |
a3f97cbb | 11194 | else |
71dfc51f RK |
11195 | /* We are in terse mode, so only local (nested) function |
11196 | definitions count as "significant" local declarations. */ | |
11197 | for (decl = BLOCK_VARS (stmt); | |
11198 | decl != NULL; decl = TREE_CHAIN (decl)) | |
11199 | if (TREE_CODE (decl) == FUNCTION_DECL | |
11200 | && DECL_INITIAL (decl)) | |
a3f97cbb | 11201 | { |
71dfc51f RK |
11202 | must_output_die = 1; |
11203 | break; | |
a3f97cbb | 11204 | } |
a3f97cbb JW |
11205 | } |
11206 | } | |
11207 | ||
11208 | /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block | |
11209 | DIE for any block which contains no significant local declarations at | |
11210 | all. Rather, in such cases we just call `decls_for_scope' so that any | |
11211 | needed Dwarf info for any sub-blocks will get properly generated. Note | |
11212 | that in terse mode, our definition of what constitutes a "significant" | |
11213 | local declaration gets restricted to include only inlined function | |
11214 | instances and local (nested) function definitions. */ | |
11215 | if (must_output_die) | |
11216 | { | |
11217 | if (origin_code == FUNCTION_DECL) | |
71dfc51f | 11218 | gen_inlined_subroutine_die (stmt, context_die, depth); |
a3f97cbb | 11219 | else |
71dfc51f | 11220 | gen_lexical_block_die (stmt, context_die, depth); |
a3f97cbb JW |
11221 | } |
11222 | else | |
d7248bff | 11223 | decls_for_scope (stmt, context_die, depth); |
a3f97cbb JW |
11224 | } |
11225 | ||
11226 | /* Generate all of the decls declared within a given scope and (recursively) | |
9ec36da5 | 11227 | all of its sub-blocks. */ |
71dfc51f | 11228 | |
a3f97cbb | 11229 | static void |
d7248bff | 11230 | decls_for_scope (stmt, context_die, depth) |
b3694847 SS |
11231 | tree stmt; |
11232 | dw_die_ref context_die; | |
d7248bff | 11233 | int depth; |
a3f97cbb | 11234 | { |
b3694847 SS |
11235 | tree decl; |
11236 | tree subblocks; | |
71dfc51f | 11237 | |
a3f97cbb | 11238 | /* Ignore blocks never really used to make RTL. */ |
71dfc51f RK |
11239 | if (stmt == NULL_TREE || ! TREE_USED (stmt)) |
11240 | return; | |
11241 | ||
88dad228 JM |
11242 | /* Output the DIEs to represent all of the data objects and typedefs |
11243 | declared directly within this block but not within any nested | |
11244 | sub-blocks. Also, nested function and tag DIEs have been | |
11245 | generated with a parent of NULL; fix that up now. */ | |
2ad9852d | 11246 | for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl)) |
a3f97cbb | 11247 | { |
b3694847 | 11248 | dw_die_ref die; |
a94dbf2c | 11249 | |
88dad228 | 11250 | if (TREE_CODE (decl) == FUNCTION_DECL) |
a94dbf2c | 11251 | die = lookup_decl_die (decl); |
88dad228 | 11252 | else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)) |
a94dbf2c JM |
11253 | die = lookup_type_die (TREE_TYPE (decl)); |
11254 | else | |
11255 | die = NULL; | |
11256 | ||
71dfc51f | 11257 | if (die != NULL && die->die_parent == NULL) |
ef76d03b | 11258 | add_child_die (context_die, die); |
88dad228 JM |
11259 | else |
11260 | gen_decl_die (decl, context_die); | |
a3f97cbb JW |
11261 | } |
11262 | ||
11263 | /* Output the DIEs to represent all sub-blocks (and the items declared | |
11264 | therein) of this block. */ | |
11265 | for (subblocks = BLOCK_SUBBLOCKS (stmt); | |
11266 | subblocks != NULL; | |
11267 | subblocks = BLOCK_CHAIN (subblocks)) | |
71dfc51f | 11268 | gen_block_die (subblocks, context_die, depth + 1); |
a3f97cbb JW |
11269 | } |
11270 | ||
a94dbf2c | 11271 | /* Is this a typedef we can avoid emitting? */ |
71dfc51f RK |
11272 | |
11273 | static inline int | |
a94dbf2c | 11274 | is_redundant_typedef (decl) |
b3694847 | 11275 | tree decl; |
a94dbf2c JM |
11276 | { |
11277 | if (TYPE_DECL_IS_STUB (decl)) | |
11278 | return 1; | |
71dfc51f | 11279 | |
a94dbf2c JM |
11280 | if (DECL_ARTIFICIAL (decl) |
11281 | && DECL_CONTEXT (decl) | |
11282 | && is_tagged_type (DECL_CONTEXT (decl)) | |
11283 | && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL | |
11284 | && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) | |
11285 | /* Also ignore the artificial member typedef for the class name. */ | |
11286 | return 1; | |
71dfc51f | 11287 | |
a94dbf2c JM |
11288 | return 0; |
11289 | } | |
11290 | ||
a3f97cbb | 11291 | /* Generate Dwarf debug information for a decl described by DECL. */ |
71dfc51f | 11292 | |
a3f97cbb JW |
11293 | static void |
11294 | gen_decl_die (decl, context_die) | |
b3694847 SS |
11295 | tree decl; |
11296 | dw_die_ref context_die; | |
a3f97cbb | 11297 | { |
b3694847 | 11298 | tree origin; |
71dfc51f | 11299 | |
f11c3043 | 11300 | if (DECL_P (decl) && DECL_IGNORED_P (decl)) |
71dfc51f | 11301 | return; |
a3f97cbb | 11302 | |
a3f97cbb JW |
11303 | switch (TREE_CODE (decl)) |
11304 | { | |
2ad9852d RK |
11305 | case ERROR_MARK: |
11306 | break; | |
11307 | ||
a3f97cbb | 11308 | case CONST_DECL: |
556273e0 | 11309 | /* The individual enumerators of an enum type get output when we output |
a3f97cbb JW |
11310 | the Dwarf representation of the relevant enum type itself. */ |
11311 | break; | |
11312 | ||
11313 | case FUNCTION_DECL: | |
4edb7b60 JM |
11314 | /* Don't output any DIEs to represent mere function declarations, |
11315 | unless they are class members or explicit block externs. */ | |
11316 | if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE | |
777ad4c2 | 11317 | && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl))) |
71dfc51f | 11318 | break; |
bdb669cb | 11319 | |
5daf7c0a JM |
11320 | /* If we're emitting a clone, emit info for the abstract instance. */ |
11321 | if (DECL_ORIGIN (decl) != decl) | |
11322 | dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl)); | |
2ad9852d | 11323 | |
1cfdcc15 JM |
11324 | /* If we're emitting an out-of-line copy of an inline function, |
11325 | emit info for the abstract instance and set up to refer to it. */ | |
5daf7c0a JM |
11326 | else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl) |
11327 | && ! class_scope_p (context_die) | |
11328 | /* dwarf2out_abstract_function won't emit a die if this is just | |
11329 | a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in | |
11330 | that case, because that works only if we have a die. */ | |
11331 | && DECL_INITIAL (decl) != NULL_TREE) | |
1cfdcc15 | 11332 | { |
1edf43d6 | 11333 | dwarf2out_abstract_function (decl); |
1cfdcc15 JM |
11334 | set_decl_origin_self (decl); |
11335 | } | |
2ad9852d | 11336 | |
5daf7c0a JM |
11337 | /* Otherwise we're emitting the primary DIE for this decl. */ |
11338 | else if (debug_info_level > DINFO_LEVEL_TERSE) | |
a94dbf2c JM |
11339 | { |
11340 | /* Before we describe the FUNCTION_DECL itself, make sure that we | |
11341 | have described its return type. */ | |
11342 | gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); | |
11343 | ||
2081603c JM |
11344 | /* And its virtual context. */ |
11345 | if (DECL_VINDEX (decl) != NULL_TREE) | |
11346 | gen_type_die (DECL_CONTEXT (decl), context_die); | |
11347 | ||
a94dbf2c JM |
11348 | /* And its containing type. */ |
11349 | origin = decl_class_context (decl); | |
71dfc51f | 11350 | if (origin != NULL_TREE) |
10a11b75 | 11351 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 11352 | } |
a3f97cbb JW |
11353 | |
11354 | /* Now output a DIE to represent the function itself. */ | |
11355 | gen_subprogram_die (decl, context_die); | |
11356 | break; | |
11357 | ||
11358 | case TYPE_DECL: | |
11359 | /* If we are in terse mode, don't generate any DIEs to represent any | |
4927276d | 11360 | actual typedefs. */ |
a3f97cbb | 11361 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 11362 | break; |
a3f97cbb | 11363 | |
2ad9852d RK |
11364 | /* In the special case of a TYPE_DECL node representing the declaration |
11365 | of some type tag, if the given TYPE_DECL is marked as having been | |
11366 | instantiated from some other (original) TYPE_DECL node (e.g. one which | |
11367 | was generated within the original definition of an inline function) we | |
11368 | have to generate a special (abbreviated) DW_TAG_structure_type, | |
11369 | DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */ | |
2081603c | 11370 | if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE) |
a3f97cbb JW |
11371 | { |
11372 | gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die); | |
11373 | break; | |
11374 | } | |
a3f97cbb | 11375 | |
a94dbf2c JM |
11376 | if (is_redundant_typedef (decl)) |
11377 | gen_type_die (TREE_TYPE (decl), context_die); | |
11378 | else | |
71dfc51f RK |
11379 | /* Output a DIE to represent the typedef itself. */ |
11380 | gen_typedef_die (decl, context_die); | |
a3f97cbb JW |
11381 | break; |
11382 | ||
11383 | case LABEL_DECL: | |
11384 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
71dfc51f | 11385 | gen_label_die (decl, context_die); |
a3f97cbb JW |
11386 | break; |
11387 | ||
11388 | case VAR_DECL: | |
11389 | /* If we are in terse mode, don't generate any DIEs to represent any | |
11390 | variable declarations or definitions. */ | |
11391 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 11392 | break; |
a3f97cbb JW |
11393 | |
11394 | /* Output any DIEs that are needed to specify the type of this data | |
11395 | object. */ | |
11396 | gen_type_die (TREE_TYPE (decl), context_die); | |
11397 | ||
a94dbf2c JM |
11398 | /* And its containing type. */ |
11399 | origin = decl_class_context (decl); | |
71dfc51f | 11400 | if (origin != NULL_TREE) |
10a11b75 | 11401 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 11402 | |
a3f97cbb JW |
11403 | /* Now output the DIE to represent the data object itself. This gets |
11404 | complicated because of the possibility that the VAR_DECL really | |
11405 | represents an inlined instance of a formal parameter for an inline | |
11406 | function. */ | |
11407 | origin = decl_ultimate_origin (decl); | |
71dfc51f RK |
11408 | if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL) |
11409 | gen_formal_parameter_die (decl, context_die); | |
a3f97cbb | 11410 | else |
71dfc51f | 11411 | gen_variable_die (decl, context_die); |
a3f97cbb JW |
11412 | break; |
11413 | ||
11414 | case FIELD_DECL: | |
2ad9852d RK |
11415 | /* Ignore the nameless fields that are used to skip bits but handle C++ |
11416 | anonymous unions. */ | |
71dfc51f RK |
11417 | if (DECL_NAME (decl) != NULL_TREE |
11418 | || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE) | |
a3f97cbb JW |
11419 | { |
11420 | gen_type_die (member_declared_type (decl), context_die); | |
11421 | gen_field_die (decl, context_die); | |
11422 | } | |
11423 | break; | |
11424 | ||
11425 | case PARM_DECL: | |
11426 | gen_type_die (TREE_TYPE (decl), context_die); | |
11427 | gen_formal_parameter_die (decl, context_die); | |
11428 | break; | |
11429 | ||
348bb3c7 JM |
11430 | case NAMESPACE_DECL: |
11431 | /* Ignore for now. */ | |
11432 | break; | |
11433 | ||
a3f97cbb JW |
11434 | default: |
11435 | abort (); | |
11436 | } | |
a3f97cbb | 11437 | } |
54ba1f0d RH |
11438 | |
11439 | static void | |
11440 | mark_limbo_die_list (ptr) | |
11441 | void *ptr ATTRIBUTE_UNUSED; | |
11442 | { | |
11443 | limbo_die_node *node; | |
11444 | for (node = limbo_die_list; node ; node = node->next) | |
11445 | ggc_mark_tree (node->created_for); | |
11446 | } | |
a3f97cbb | 11447 | \f |
14a774a9 RK |
11448 | /* Add Ada "use" clause information for SGI Workshop debugger. */ |
11449 | ||
11450 | void | |
11451 | dwarf2out_add_library_unit_info (filename, context_list) | |
c6991660 KG |
11452 | const char *filename; |
11453 | const char *context_list; | |
14a774a9 RK |
11454 | { |
11455 | unsigned int file_index; | |
11456 | ||
11457 | if (filename != NULL) | |
11458 | { | |
54ba1f0d | 11459 | dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL); |
556273e0 | 11460 | tree context_list_decl |
14a774a9 RK |
11461 | = build_decl (LABEL_DECL, get_identifier (context_list), |
11462 | void_type_node); | |
11463 | ||
11464 | TREE_PUBLIC (context_list_decl) = TRUE; | |
11465 | add_name_attribute (unit_die, context_list); | |
981975b6 | 11466 | file_index = lookup_filename (filename); |
14a774a9 RK |
11467 | add_AT_unsigned (unit_die, DW_AT_decl_file, file_index); |
11468 | add_pubname (context_list_decl, unit_die); | |
11469 | } | |
11470 | } | |
11471 | ||
2ad9852d | 11472 | /* Output debug information for global decl DECL. Called from toplev.c after |
2b85879e | 11473 | compilation proper has finished. */ |
2ad9852d | 11474 | |
2b85879e NB |
11475 | static void |
11476 | dwarf2out_global_decl (decl) | |
11477 | tree decl; | |
11478 | { | |
11479 | /* Output DWARF2 information for file-scope tentative data object | |
2ad9852d RK |
11480 | declarations, file-scope (extern) function declarations (which had no |
11481 | corresponding body) and file-scope tagged type declarations and | |
11482 | definitions which have not yet been forced out. */ | |
2b85879e NB |
11483 | if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)) |
11484 | dwarf2out_decl (decl); | |
11485 | } | |
11486 | ||
71dfc51f RK |
11487 | /* Write the debugging output for DECL. */ |
11488 | ||
a3f97cbb | 11489 | void |
88dad228 | 11490 | dwarf2out_decl (decl) |
b3694847 | 11491 | tree decl; |
a3f97cbb | 11492 | { |
b3694847 | 11493 | dw_die_ref context_die = comp_unit_die; |
88dad228 | 11494 | |
a3f97cbb JW |
11495 | switch (TREE_CODE (decl)) |
11496 | { | |
2ad9852d RK |
11497 | case ERROR_MARK: |
11498 | return; | |
11499 | ||
a3f97cbb | 11500 | case FUNCTION_DECL: |
556273e0 | 11501 | /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a |
a3f97cbb JW |
11502 | builtin function. Explicit programmer-supplied declarations of |
11503 | these same functions should NOT be ignored however. */ | |
9765e357 | 11504 | if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl)) |
b1ccbc24 | 11505 | return; |
a3f97cbb JW |
11506 | |
11507 | /* What we would really like to do here is to filter out all mere | |
11508 | file-scope declarations of file-scope functions which are never | |
11509 | referenced later within this translation unit (and keep all of ones | |
556273e0 KH |
11510 | that *are* referenced later on) but we aren't clairvoyant, so we have |
11511 | no idea which functions will be referenced in the future (i.e. later | |
a3f97cbb | 11512 | on within the current translation unit). So here we just ignore all |
556273e0 | 11513 | file-scope function declarations which are not also definitions. If |
956d6950 | 11514 | and when the debugger needs to know something about these functions, |
556273e0 | 11515 | it will have to hunt around and find the DWARF information associated |
2ad9852d RK |
11516 | with the definition of the function. |
11517 | ||
11518 | We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL | |
11519 | nodes represent definitions and which ones represent mere | |
11520 | declarations. We have to check DECL_INITIAL instead. That's because | |
11521 | the C front-end supports some weird semantics for "extern inline" | |
11522 | function definitions. These can get inlined within the current | |
11523 | translation unit (an thus, we need to generate Dwarf info for their | |
11524 | abstract instances so that the Dwarf info for the concrete inlined | |
11525 | instances can have something to refer to) but the compiler never | |
11526 | generates any out-of-lines instances of such things (despite the fact | |
11527 | that they *are* definitions). | |
11528 | ||
11529 | The important point is that the C front-end marks these "extern | |
11530 | inline" functions as DECL_EXTERNAL, but we need to generate DWARF for | |
11531 | them anyway. Note that the C++ front-end also plays some similar games | |
11532 | for inline function definitions appearing within include files which | |
11533 | also contain `#pragma interface' pragmas. */ | |
a3f97cbb | 11534 | if (DECL_INITIAL (decl) == NULL_TREE) |
b1ccbc24 | 11535 | return; |
88dad228 | 11536 | |
9c6cd30e JM |
11537 | /* If we're a nested function, initially use a parent of NULL; if we're |
11538 | a plain function, this will be fixed up in decls_for_scope. If | |
11539 | we're a method, it will be ignored, since we already have a DIE. */ | |
88dad228 | 11540 | if (decl_function_context (decl)) |
9c6cd30e | 11541 | context_die = NULL; |
a3f97cbb JW |
11542 | break; |
11543 | ||
11544 | case VAR_DECL: | |
556273e0 | 11545 | /* Ignore this VAR_DECL if it refers to a file-scope extern data object |
a3f97cbb JW |
11546 | declaration and if the declaration was never even referenced from |
11547 | within this entire compilation unit. We suppress these DIEs in | |
11548 | order to save space in the .debug section (by eliminating entries | |
11549 | which are probably useless). Note that we must not suppress | |
11550 | block-local extern declarations (whether used or not) because that | |
11551 | would screw-up the debugger's name lookup mechanism and cause it to | |
11552 | miss things which really ought to be in scope at a given point. */ | |
11553 | if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) | |
71dfc51f | 11554 | return; |
a3f97cbb JW |
11555 | |
11556 | /* If we are in terse mode, don't generate any DIEs to represent any | |
11557 | variable declarations or definitions. */ | |
11558 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 11559 | return; |
a3f97cbb JW |
11560 | break; |
11561 | ||
11562 | case TYPE_DECL: | |
57fb7689 JM |
11563 | /* Don't emit stubs for types unless they are needed by other DIEs. */ |
11564 | if (TYPE_DECL_SUPPRESS_DEBUG (decl)) | |
11565 | return; | |
11566 | ||
a3f97cbb | 11567 | /* Don't bother trying to generate any DIEs to represent any of the |
a9d38797 JM |
11568 | normal built-in types for the language we are compiling. */ |
11569 | if (DECL_SOURCE_LINE (decl) == 0) | |
a94dbf2c JM |
11570 | { |
11571 | /* OK, we need to generate one for `bool' so GDB knows what type | |
11572 | comparisons have. */ | |
11573 | if ((get_AT_unsigned (comp_unit_die, DW_AT_language) | |
11574 | == DW_LANG_C_plus_plus) | |
f11c3043 RK |
11575 | && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE |
11576 | && ! DECL_IGNORED_P (decl)) | |
a94dbf2c | 11577 | modified_type_die (TREE_TYPE (decl), 0, 0, NULL); |
71dfc51f | 11578 | |
a94dbf2c JM |
11579 | return; |
11580 | } | |
a3f97cbb | 11581 | |
88dad228 | 11582 | /* If we are in terse mode, don't generate any DIEs for types. */ |
a3f97cbb | 11583 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 11584 | return; |
88dad228 JM |
11585 | |
11586 | /* If we're a function-scope tag, initially use a parent of NULL; | |
11587 | this will be fixed up in decls_for_scope. */ | |
11588 | if (decl_function_context (decl)) | |
3f76745e | 11589 | context_die = NULL; |
88dad228 | 11590 | |
a3f97cbb JW |
11591 | break; |
11592 | ||
11593 | default: | |
11594 | return; | |
11595 | } | |
11596 | ||
88dad228 | 11597 | gen_decl_die (decl, context_die); |
a3f97cbb JW |
11598 | } |
11599 | ||
11600 | /* Output a marker (i.e. a label) for the beginning of the generated code for | |
11601 | a lexical block. */ | |
71dfc51f | 11602 | |
a5a42b92 | 11603 | static void |
e2a12aca | 11604 | dwarf2out_begin_block (line, blocknum) |
a5a42b92 NB |
11605 | unsigned int line ATTRIBUTE_UNUSED; |
11606 | unsigned int blocknum; | |
a3f97cbb | 11607 | { |
a3f97cbb | 11608 | function_section (current_function_decl); |
8215347e | 11609 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum); |
a3f97cbb JW |
11610 | } |
11611 | ||
11612 | /* Output a marker (i.e. a label) for the end of the generated code for a | |
11613 | lexical block. */ | |
71dfc51f | 11614 | |
a5a42b92 | 11615 | static void |
e2a12aca | 11616 | dwarf2out_end_block (line, blocknum) |
a5a42b92 NB |
11617 | unsigned int line ATTRIBUTE_UNUSED; |
11618 | unsigned int blocknum; | |
a3f97cbb | 11619 | { |
a3f97cbb | 11620 | function_section (current_function_decl); |
8215347e | 11621 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum); |
a3f97cbb JW |
11622 | } |
11623 | ||
64b59a80 JM |
11624 | /* Returns nonzero if it is appropriate not to emit any debugging |
11625 | information for BLOCK, because it doesn't contain any instructions. | |
fcd7f76b | 11626 | |
64b59a80 JM |
11627 | Don't allow this for blocks with nested functions or local classes |
11628 | as we would end up with orphans, and in the presence of scheduling | |
11629 | we may end up calling them anyway. */ | |
11630 | ||
e1772ac0 | 11631 | static bool |
fcd7f76b JM |
11632 | dwarf2out_ignore_block (block) |
11633 | tree block; | |
11634 | { | |
11635 | tree decl; | |
2ad9852d | 11636 | |
fcd7f76b | 11637 | for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) |
64b59a80 JM |
11638 | if (TREE_CODE (decl) == FUNCTION_DECL |
11639 | || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))) | |
11640 | return 0; | |
2ad9852d | 11641 | |
64b59a80 | 11642 | return 1; |
fcd7f76b JM |
11643 | } |
11644 | ||
2ad9852d | 11645 | /* Lookup FILE_NAME (in the list of filenames that we know about here in |
9a666dda | 11646 | dwarf2out.c) and return its "index". The index of each (known) filename is |
2ad9852d RK |
11647 | just a unique number which is associated with only that one filename. We |
11648 | need such numbers for the sake of generating labels (in the .debug_sfnames | |
11649 | section) and references to those files numbers (in the .debug_srcinfo | |
11650 | and.debug_macinfo sections). If the filename given as an argument is not | |
11651 | found in our current list, add it to the list and assign it the next | |
11652 | available unique index number. In order to speed up searches, we remember | |
11653 | the index of the filename was looked up last. This handles the majority of | |
11654 | all searches. */ | |
71dfc51f | 11655 | |
a3f97cbb | 11656 | static unsigned |
981975b6 | 11657 | lookup_filename (file_name) |
d560ee52 | 11658 | const char *file_name; |
a3f97cbb | 11659 | { |
b3694847 | 11660 | unsigned i; |
a3f97cbb | 11661 | |
981975b6 RH |
11662 | /* ??? Why isn't DECL_SOURCE_FILE left null instead. */ |
11663 | if (strcmp (file_name, "<internal>") == 0 | |
11664 | || strcmp (file_name, "<built-in>") == 0) | |
11665 | return 0; | |
11666 | ||
2e18bbae RH |
11667 | /* Check to see if the file name that was searched on the previous |
11668 | call matches this file name. If so, return the index. */ | |
981975b6 | 11669 | if (file_table.last_lookup_index != 0) |
2ad9852d RK |
11670 | if (0 == strcmp (file_name, |
11671 | file_table.table[file_table.last_lookup_index])) | |
981975b6 | 11672 | return file_table.last_lookup_index; |
a3f97cbb JW |
11673 | |
11674 | /* Didn't match the previous lookup, search the table */ | |
2ad9852d | 11675 | for (i = 1; i < file_table.in_use; i++) |
981975b6 | 11676 | if (strcmp (file_name, file_table.table[i]) == 0) |
71dfc51f | 11677 | { |
981975b6 | 11678 | file_table.last_lookup_index = i; |
71dfc51f RK |
11679 | return i; |
11680 | } | |
a3f97cbb | 11681 | |
556273e0 | 11682 | /* Prepare to add a new table entry by making sure there is enough space in |
a3f97cbb | 11683 | the table to do so. If not, expand the current table. */ |
981975b6 | 11684 | if (i == file_table.allocated) |
a3f97cbb | 11685 | { |
981975b6 RH |
11686 | file_table.allocated = i + FILE_TABLE_INCREMENT; |
11687 | file_table.table = (char **) | |
11688 | xrealloc (file_table.table, file_table.allocated * sizeof (char *)); | |
a3f97cbb JW |
11689 | } |
11690 | ||
71dfc51f | 11691 | /* Add the new entry to the end of the filename table. */ |
981975b6 RH |
11692 | file_table.table[i] = xstrdup (file_name); |
11693 | file_table.in_use = i + 1; | |
11694 | file_table.last_lookup_index = i; | |
2e18bbae | 11695 | |
acc187f5 RH |
11696 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
11697 | fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name); | |
11698 | ||
2e18bbae RH |
11699 | return i; |
11700 | } | |
11701 | ||
11702 | static void | |
981975b6 | 11703 | init_file_table () |
2e18bbae RH |
11704 | { |
11705 | /* Allocate the initial hunk of the file_table. */ | |
981975b6 RH |
11706 | file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *)); |
11707 | file_table.allocated = FILE_TABLE_INCREMENT; | |
71dfc51f | 11708 | |
2e18bbae | 11709 | /* Skip the first entry - file numbers begin at 1. */ |
981975b6 RH |
11710 | file_table.in_use = 1; |
11711 | file_table.last_lookup_index = 0; | |
a3f97cbb JW |
11712 | } |
11713 | ||
11714 | /* Output a label to mark the beginning of a source code line entry | |
11715 | and record information relating to this source line, in | |
11716 | 'line_info_table' for later output of the .debug_line section. */ | |
71dfc51f | 11717 | |
e2a12aca | 11718 | static void |
653e276c NB |
11719 | dwarf2out_source_line (line, filename) |
11720 | unsigned int line; | |
b3694847 | 11721 | const char *filename; |
a3f97cbb | 11722 | { |
a3f97cbb JW |
11723 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
11724 | { | |
11725 | function_section (current_function_decl); | |
a3f97cbb | 11726 | |
8aaf55ac JM |
11727 | /* If requested, emit something human-readable. */ |
11728 | if (flag_debug_asm) | |
11729 | fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, | |
11730 | filename, line); | |
11731 | ||
b2244e22 JW |
11732 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
11733 | { | |
981975b6 | 11734 | unsigned file_num = lookup_filename (filename); |
b2244e22 | 11735 | |
981975b6 | 11736 | /* Emit the .loc directive understood by GNU as. */ |
2e18bbae | 11737 | fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line); |
b2244e22 JW |
11738 | |
11739 | /* Indicate that line number info exists. */ | |
2ad9852d | 11740 | line_info_table_in_use++; |
b2244e22 JW |
11741 | |
11742 | /* Indicate that multiple line number tables exist. */ | |
11743 | if (DECL_SECTION_NAME (current_function_decl)) | |
2ad9852d | 11744 | separate_line_info_table_in_use++; |
b2244e22 JW |
11745 | } |
11746 | else if (DECL_SECTION_NAME (current_function_decl)) | |
a3f97cbb | 11747 | { |
b3694847 | 11748 | dw_separate_line_info_ref line_info; |
5c90448c JM |
11749 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL, |
11750 | separate_line_info_table_in_use); | |
e90b62db JM |
11751 | |
11752 | /* expand the line info table if necessary */ | |
11753 | if (separate_line_info_table_in_use | |
11754 | == separate_line_info_table_allocated) | |
11755 | { | |
11756 | separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
11757 | separate_line_info_table | |
71dfc51f RK |
11758 | = (dw_separate_line_info_ref) |
11759 | xrealloc (separate_line_info_table, | |
11760 | separate_line_info_table_allocated | |
11761 | * sizeof (dw_separate_line_info_entry)); | |
e90b62db | 11762 | } |
71dfc51f RK |
11763 | |
11764 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
11765 | line_info |
11766 | = &separate_line_info_table[separate_line_info_table_in_use++]; | |
981975b6 | 11767 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db JM |
11768 | line_info->dw_line_num = line; |
11769 | line_info->function = current_funcdef_number; | |
11770 | } | |
11771 | else | |
11772 | { | |
b3694847 | 11773 | dw_line_info_ref line_info; |
71dfc51f | 11774 | |
5c90448c JM |
11775 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL, |
11776 | line_info_table_in_use); | |
e90b62db | 11777 | |
71dfc51f | 11778 | /* Expand the line info table if necessary. */ |
e90b62db JM |
11779 | if (line_info_table_in_use == line_info_table_allocated) |
11780 | { | |
11781 | line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
11782 | line_info_table | |
71dfc51f RK |
11783 | = (dw_line_info_ref) |
11784 | xrealloc (line_info_table, | |
11785 | (line_info_table_allocated | |
11786 | * sizeof (dw_line_info_entry))); | |
e90b62db | 11787 | } |
71dfc51f RK |
11788 | |
11789 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db | 11790 | line_info = &line_info_table[line_info_table_in_use++]; |
981975b6 | 11791 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db | 11792 | line_info->dw_line_num = line; |
a3f97cbb | 11793 | } |
a3f97cbb JW |
11794 | } |
11795 | } | |
11796 | ||
30f7a378 | 11797 | /* Record the beginning of a new source file. */ |
71dfc51f | 11798 | |
7f905405 | 11799 | static void |
84a5b4f8 | 11800 | dwarf2out_start_source_file (lineno, filename) |
b3694847 SS |
11801 | unsigned int lineno; |
11802 | const char *filename; | |
a3f97cbb | 11803 | { |
881c6935 JM |
11804 | if (flag_eliminate_dwarf2_dups) |
11805 | { | |
11806 | /* Record the beginning of the file for break_out_includes. */ | |
54ba1f0d | 11807 | dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL); |
881c6935 JM |
11808 | add_AT_string (bincl_die, DW_AT_name, filename); |
11809 | } | |
2ad9852d | 11810 | |
84a5b4f8 DB |
11811 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11812 | { | |
715bdd29 | 11813 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 | 11814 | dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file"); |
7c262518 RH |
11815 | dw2_asm_output_data_uleb128 (lineno, "Included from line number %d", |
11816 | lineno); | |
11817 | dw2_asm_output_data_uleb128 (lookup_filename (filename), | |
11818 | "Filename we just started"); | |
84a5b4f8 | 11819 | } |
a3f97cbb JW |
11820 | } |
11821 | ||
cc260610 | 11822 | /* Record the end of a source file. */ |
71dfc51f | 11823 | |
7f905405 NB |
11824 | static void |
11825 | dwarf2out_end_source_file (lineno) | |
11826 | unsigned int lineno ATTRIBUTE_UNUSED; | |
a3f97cbb | 11827 | { |
881c6935 | 11828 | if (flag_eliminate_dwarf2_dups) |
2ad9852d | 11829 | /* Record the end of the file for break_out_includes. */ |
54ba1f0d | 11830 | new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL); |
2ad9852d | 11831 | |
84a5b4f8 DB |
11832 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11833 | { | |
715bdd29 | 11834 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
11835 | dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); |
11836 | } | |
a3f97cbb JW |
11837 | } |
11838 | ||
cc260610 | 11839 | /* Called from debug_define in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
11840 | the tail part of the directive line, i.e. the part which is past the |
11841 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 11842 | |
7f905405 | 11843 | static void |
9a666dda | 11844 | dwarf2out_define (lineno, buffer) |
b3694847 SS |
11845 | unsigned lineno ATTRIBUTE_UNUSED; |
11846 | const char *buffer ATTRIBUTE_UNUSED; | |
a3f97cbb JW |
11847 | { |
11848 | static int initialized = 0; | |
11849 | if (!initialized) | |
11850 | { | |
84a5b4f8 | 11851 | dwarf2out_start_source_file (0, primary_filename); |
a3f97cbb JW |
11852 | initialized = 1; |
11853 | } | |
2ad9852d | 11854 | |
84a5b4f8 DB |
11855 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11856 | { | |
715bdd29 | 11857 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
11858 | dw2_asm_output_data (1, DW_MACINFO_define, "Define macro"); |
11859 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
11860 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
11861 | } | |
a3f97cbb JW |
11862 | } |
11863 | ||
cc260610 | 11864 | /* Called from debug_undef in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
11865 | the tail part of the directive line, i.e. the part which is past the |
11866 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 11867 | |
7f905405 | 11868 | static void |
9a666dda | 11869 | dwarf2out_undef (lineno, buffer) |
b3694847 SS |
11870 | unsigned lineno ATTRIBUTE_UNUSED; |
11871 | const char *buffer ATTRIBUTE_UNUSED; | |
a3f97cbb | 11872 | { |
84a5b4f8 DB |
11873 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11874 | { | |
715bdd29 | 11875 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
11876 | dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro"); |
11877 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
11878 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
11879 | } | |
a3f97cbb JW |
11880 | } |
11881 | ||
11882 | /* Set up for Dwarf output at the start of compilation. */ | |
71dfc51f | 11883 | |
a51d908e | 11884 | static void |
e2a12aca | 11885 | dwarf2out_init (main_input_filename) |
b3694847 | 11886 | const char *main_input_filename; |
a3f97cbb | 11887 | { |
acc187f5 RH |
11888 | init_file_table (); |
11889 | ||
a3f97cbb JW |
11890 | /* Remember the name of the primary input file. */ |
11891 | primary_filename = main_input_filename; | |
11892 | ||
acc187f5 RH |
11893 | /* Add it to the file table first, under the assumption that we'll |
11894 | be emitting line number data for it first, which avoids having | |
11895 | to add an initial DW_LNS_set_file. */ | |
11896 | lookup_filename (main_input_filename); | |
a3f97cbb | 11897 | |
a3f97cbb JW |
11898 | /* Allocate the initial hunk of the decl_die_table. */ |
11899 | decl_die_table | |
3de90026 | 11900 | = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref)); |
a3f97cbb JW |
11901 | decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT; |
11902 | decl_die_table_in_use = 0; | |
11903 | ||
11904 | /* Allocate the initial hunk of the decl_scope_table. */ | |
244a4af0 TF |
11905 | VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table"); |
11906 | ggc_add_tree_varray_root (&decl_scope_table, 1); | |
a3f97cbb JW |
11907 | |
11908 | /* Allocate the initial hunk of the abbrev_die_table. */ | |
11909 | abbrev_die_table | |
3de90026 RH |
11910 | = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT, |
11911 | sizeof (dw_die_ref)); | |
a3f97cbb | 11912 | abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT; |
71dfc51f | 11913 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
11914 | abbrev_die_table_in_use = 1; |
11915 | ||
11916 | /* Allocate the initial hunk of the line_info_table. */ | |
11917 | line_info_table | |
3de90026 RH |
11918 | = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT, |
11919 | sizeof (dw_line_info_entry)); | |
a3f97cbb | 11920 | line_info_table_allocated = LINE_INFO_TABLE_INCREMENT; |
2ad9852d | 11921 | |
71dfc51f | 11922 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
11923 | line_info_table_in_use = 1; |
11924 | ||
556273e0 | 11925 | /* Generate the initial DIE for the .debug section. Note that the (string) |
a3f97cbb | 11926 | value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE |
556273e0 | 11927 | will (typically) be a relative pathname and that this pathname should be |
a3f97cbb JW |
11928 | taken as being relative to the directory from which the compiler was |
11929 | invoked when the given (base) source file was compiled. */ | |
a96c67ec | 11930 | comp_unit_die = gen_compile_unit_die (main_input_filename); |
a3f97cbb | 11931 | |
244a4af0 TF |
11932 | VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types"); |
11933 | ggc_add_tree_varray_root (&incomplete_types, 1); | |
11934 | ||
1f8f4a0b MM |
11935 | VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray"); |
11936 | ggc_add_rtx_varray_root (&used_rtx_varray, 1); | |
1865dbb5 | 11937 | |
54ba1f0d RH |
11938 | ggc_add_root (&limbo_die_list, 1, 1, mark_limbo_die_list); |
11939 | ||
5c90448c | 11940 | ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0); |
9d2f2c45 RH |
11941 | ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, |
11942 | DEBUG_ABBREV_SECTION_LABEL, 0); | |
b366352b MM |
11943 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) |
11944 | ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0); | |
11945 | else | |
f99ffb60 | 11946 | strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME)); |
2ad9852d | 11947 | |
556273e0 | 11948 | ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label, |
8b790721 | 11949 | DEBUG_INFO_SECTION_LABEL, 0); |
556273e0 | 11950 | ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label, |
8b790721 | 11951 | DEBUG_LINE_SECTION_LABEL, 0); |
2bee6045 JJ |
11952 | ASM_GENERATE_INTERNAL_LABEL (ranges_section_label, |
11953 | DEBUG_RANGES_SECTION_LABEL, 0); | |
715bdd29 | 11954 | named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG); |
8b790721 | 11955 | ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label); |
715bdd29 | 11956 | named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG); |
8b790721 | 11957 | ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label); |
715bdd29 | 11958 | named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG); |
8b790721 | 11959 | ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label); |
2ad9852d | 11960 | |
84a5b4f8 DB |
11961 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11962 | { | |
715bdd29 | 11963 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
11964 | ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label, |
11965 | DEBUG_MACINFO_SECTION_LABEL, 0); | |
11966 | ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label); | |
11967 | } | |
7c262518 RH |
11968 | |
11969 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) | |
11970 | { | |
11971 | text_section (); | |
11972 | ASM_OUTPUT_LABEL (asm_out_file, text_section_label); | |
11973 | } | |
a3f97cbb JW |
11974 | } |
11975 | ||
9eb4015a JJ |
11976 | /* Allocate a string in .debug_str hash table. */ |
11977 | ||
11978 | static hashnode | |
11979 | indirect_string_alloc (tab) | |
11980 | hash_table *tab ATTRIBUTE_UNUSED; | |
11981 | { | |
11982 | struct indirect_string_node *node; | |
11983 | ||
11984 | node = xmalloc (sizeof (struct indirect_string_node)); | |
11985 | node->refcount = 0; | |
11986 | node->form = 0; | |
11987 | node->label = NULL; | |
2ad9852d | 11988 | |
9eb4015a JJ |
11989 | return (hashnode) node; |
11990 | } | |
11991 | ||
11992 | /* A helper function for dwarf2out_finish called through | |
11993 | ht_forall. Emit one queued .debug_str string. */ | |
11994 | ||
11995 | static int | |
11996 | output_indirect_string (pfile, h, v) | |
11997 | struct cpp_reader *pfile ATTRIBUTE_UNUSED; | |
11998 | hashnode h; | |
11999 | const PTR v ATTRIBUTE_UNUSED; | |
12000 | { | |
2ad9852d | 12001 | struct indirect_string_node *node = (struct indirect_string_node *) h; |
9eb4015a | 12002 | |
9eb4015a JJ |
12003 | if (node->form == DW_FORM_strp) |
12004 | { | |
12005 | named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS); | |
12006 | ASM_OUTPUT_LABEL (asm_out_file, node->label); | |
12007 | assemble_string ((const char *) HT_STR (&node->id), | |
12008 | HT_LEN (&node->id) + 1); | |
12009 | } | |
2ad9852d | 12010 | |
9eb4015a JJ |
12011 | return 1; |
12012 | } | |
12013 | ||
a3f97cbb JW |
12014 | /* Output stuff that dwarf requires at the end of every file, |
12015 | and generate the DWARF-2 debugging info. */ | |
71dfc51f | 12016 | |
a51d908e | 12017 | static void |
e2a12aca | 12018 | dwarf2out_finish (input_filename) |
b3694847 | 12019 | const char *input_filename ATTRIBUTE_UNUSED; |
a3f97cbb | 12020 | { |
ef76d03b | 12021 | limbo_die_node *node, *next_node; |
ae0ed63a | 12022 | dw_die_ref die = 0; |
ef76d03b JW |
12023 | |
12024 | /* Traverse the limbo die list, and add parent/child links. The only | |
12025 | dies without parents that should be here are concrete instances of | |
12026 | inline functions, and the comp_unit_die. We can ignore the comp_unit_die. | |
12027 | For concrete instances, we can get the parent die from the abstract | |
12028 | instance. */ | |
12029 | for (node = limbo_die_list; node; node = next_node) | |
12030 | { | |
12031 | next_node = node->next; | |
12032 | die = node->die; | |
12033 | ||
12034 | if (die->die_parent == NULL) | |
12035 | { | |
a96c67ec | 12036 | dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin); |
54ba1f0d | 12037 | tree context; |
2ad9852d | 12038 | |
a96c67ec JM |
12039 | if (origin) |
12040 | add_child_die (origin->die_parent, die); | |
ef76d03b | 12041 | else if (die == comp_unit_die) |
a96c67ec | 12042 | ; |
aea9695c RK |
12043 | /* If this was an expression for a bound involved in a function |
12044 | return type, it may be a SAVE_EXPR for which we weren't able | |
12045 | to find a DIE previously. So try now. */ | |
12046 | else if (node->created_for | |
12047 | && TREE_CODE (node->created_for) == SAVE_EXPR | |
12048 | && 0 != (origin = (lookup_decl_die | |
12049 | (SAVE_EXPR_CONTEXT | |
12050 | (node->created_for))))) | |
12051 | add_child_die (origin, die); | |
54ba1f0d RH |
12052 | else if (node->created_for |
12053 | && ((DECL_P (node->created_for) | |
12054 | && (context = DECL_CONTEXT (node->created_for))) | |
12055 | || (TYPE_P (node->created_for) | |
12056 | && (context = TYPE_CONTEXT (node->created_for)))) | |
12057 | && TREE_CODE (context) == FUNCTION_DECL) | |
12058 | { | |
12059 | /* In certain situations, the lexical block containing a | |
12060 | nested function can be optimized away, which results | |
12061 | in the nested function die being orphaned. Likewise | |
12062 | with the return type of that nested function. Force | |
12063 | this to be a child of the containing function. */ | |
12064 | origin = lookup_decl_die (context); | |
12065 | if (! origin) | |
12066 | abort (); | |
12067 | add_child_die (origin, die); | |
12068 | } | |
18b5b8d6 JM |
12069 | else if (errorcount > 0 || sorrycount > 0) |
12070 | /* It's OK to be confused by errors in the input. */ | |
12071 | add_child_die (comp_unit_die, die); | |
ef76d03b JW |
12072 | else |
12073 | abort (); | |
12074 | } | |
2ad9852d | 12075 | |
ef76d03b JW |
12076 | free (node); |
12077 | } | |
2ad9852d | 12078 | |
a96c67ec | 12079 | limbo_die_list = NULL; |
ef76d03b | 12080 | |
8a8c3656 JM |
12081 | /* Walk through the list of incomplete types again, trying once more to |
12082 | emit full debugging info for them. */ | |
12083 | retry_incomplete_types (); | |
12084 | ||
881c6935 JM |
12085 | /* We need to reverse all the dies before break_out_includes, or |
12086 | we'll see the end of an include file before the beginning. */ | |
12087 | reverse_all_dies (comp_unit_die); | |
12088 | ||
12089 | /* Generate separate CUs for each of the include files we've seen. | |
12090 | They will go into limbo_die_list. */ | |
5f632b5e JM |
12091 | if (flag_eliminate_dwarf2_dups) |
12092 | break_out_includes (comp_unit_die); | |
881c6935 JM |
12093 | |
12094 | /* Traverse the DIE's and add add sibling attributes to those DIE's | |
12095 | that have children. */ | |
a3f97cbb | 12096 | add_sibling_attributes (comp_unit_die); |
881c6935 JM |
12097 | for (node = limbo_die_list; node; node = node->next) |
12098 | add_sibling_attributes (node->die); | |
a3f97cbb JW |
12099 | |
12100 | /* Output a terminator label for the .text section. */ | |
7c262518 | 12101 | text_section (); |
5c90448c | 12102 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0); |
a3f97cbb | 12103 | |
db3c0315 MM |
12104 | /* Output the source line correspondence table. We must do this |
12105 | even if there is no line information. Otherwise, on an empty | |
12106 | translation unit, we will generate a present, but empty, | |
12107 | .debug_info section. IRIX 6.5 `nm' will then complain when | |
12108 | examining the file. */ | |
12109 | if (! DWARF2_ASM_LINE_DEBUG_INFO) | |
e90b62db | 12110 | { |
715bdd29 | 12111 | named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG); |
db3c0315 MM |
12112 | output_line_info (); |
12113 | } | |
71dfc51f | 12114 | |
b38a75e5 RH |
12115 | /* Output location list section if necessary. */ |
12116 | if (have_location_lists) | |
12117 | { | |
12118 | /* Output the location lists info. */ | |
12119 | named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG); | |
12120 | ASM_GENERATE_INTERNAL_LABEL (loc_section_label, | |
12121 | DEBUG_LOC_SECTION_LABEL, 0); | |
12122 | ASM_OUTPUT_LABEL (asm_out_file, loc_section_label); | |
12123 | output_location_lists (die); | |
12124 | have_location_lists = 0; | |
12125 | } | |
12126 | ||
db3c0315 MM |
12127 | /* We can only use the low/high_pc attributes if all of the code was |
12128 | in .text. */ | |
12129 | if (separate_line_info_table_in_use == 0) | |
12130 | { | |
12131 | add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label); | |
12132 | add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label); | |
e90b62db | 12133 | } |
2ad9852d RK |
12134 | |
12135 | /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate | |
12136 | "base address". Use zero so that these addresses become absolute. */ | |
a20612aa RH |
12137 | else if (have_location_lists || ranges_table_in_use) |
12138 | add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx); | |
e90b62db | 12139 | |
fe7cd37f RH |
12140 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
12141 | add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list, | |
12142 | debug_line_section_label); | |
db3c0315 | 12143 | |
84a5b4f8 DB |
12144 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12145 | add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label); | |
a96c67ec | 12146 | |
881c6935 JM |
12147 | /* Output all of the compilation units. We put the main one last so that |
12148 | the offsets are available to output_pubnames. */ | |
12149 | for (node = limbo_die_list; node; node = node->next) | |
12150 | output_comp_unit (node->die); | |
2ad9852d | 12151 | |
881c6935 JM |
12152 | output_comp_unit (comp_unit_die); |
12153 | ||
a3f97cbb | 12154 | /* Output the abbreviation table. */ |
715bdd29 | 12155 | named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG); |
a3f97cbb JW |
12156 | output_abbrev_section (); |
12157 | ||
2ad9852d | 12158 | /* Output public names table if necessary. */ |
d291dd49 JM |
12159 | if (pubname_table_in_use) |
12160 | { | |
715bdd29 | 12161 | named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG); |
d291dd49 JM |
12162 | output_pubnames (); |
12163 | } | |
12164 | ||
2ad9852d RK |
12165 | /* Output the address range information. We only put functions in the arange |
12166 | table, so don't write it out if we don't have any. */ | |
a3f97cbb JW |
12167 | if (fde_table_in_use) |
12168 | { | |
715bdd29 | 12169 | named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG); |
a3f97cbb JW |
12170 | output_aranges (); |
12171 | } | |
a20612aa | 12172 | |
a20612aa RH |
12173 | /* Output ranges section if necessary. */ |
12174 | if (ranges_table_in_use) | |
12175 | { | |
715bdd29 | 12176 | named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG); |
2bee6045 | 12177 | ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label); |
a20612aa RH |
12178 | output_ranges (); |
12179 | } | |
12180 | ||
30f7a378 | 12181 | /* Have to end the primary source file. */ |
cc260610 DB |
12182 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12183 | { | |
715bdd29 | 12184 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
cc260610 DB |
12185 | dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); |
12186 | } | |
9eb4015a | 12187 | |
2ad9852d | 12188 | /* If we emitted any DW_FORM_strp form attribute, output the string |
9eb4015a JJ |
12189 | table too. */ |
12190 | if (debug_str_hash) | |
12191 | ht_forall (debug_str_hash, output_indirect_string, NULL); | |
a3f97cbb | 12192 | } |
f3a8e4f5 | 12193 | #endif /* DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO */ |