]>
Commit | Line | Data |
---|---|---|
5e6908ea | 1 | /* Output Dwarf2 format symbol table information from GCC. |
69bd9368 | 2 | Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, |
2e2c7ce2 | 3 | 2003, 2004, 2005, 2006, 2007, 2008 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 | |
9dcd6f09 | 12 | Software Foundation; either version 3, or (at your option) any later |
1322177d | 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 | |
9dcd6f09 NC |
21 | along with GCC; see the file COPYING3. If not see |
22 | <http://www.gnu.org/licenses/>. */ | |
a3f97cbb | 23 | |
9eb4015a | 24 | /* TODO: Emit .debug_line header even when there are no functions, since |
348bb3c7 JM |
25 | the file numbers are used by .debug_info. Alternately, leave |
26 | out locations for types and decls. | |
27 | Avoid talking about ctors and op= for PODs. | |
28 | Factor out common prologue sequences into multiple CIEs. */ | |
29 | ||
3f76745e JM |
30 | /* The first part of this file deals with the DWARF 2 frame unwind |
31 | information, which is also used by the GCC efficient exception handling | |
32 | mechanism. The second part, controlled only by an #ifdef | |
33 | DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging | |
34 | information. */ | |
35 | ||
f01d40db BE |
36 | /* DWARF2 Abbreviation Glossary: |
37 | ||
38 | CFA = Canonical Frame Address | |
39 | a fixed address on the stack which identifies a call frame. | |
40 | We define it to be the value of SP just before the call insn. | |
41 | The CFA register and offset, which may change during the course | |
42 | of the function, are used to calculate its value at runtime. | |
43 | ||
44 | CFI = Call Frame Instruction | |
45 | an instruction for the DWARF2 abstract machine | |
46 | ||
47 | CIE = Common Information Entry | |
48 | information describing information common to one or more FDEs | |
49 | ||
50 | DIE = Debugging Information Entry | |
51 | ||
52 | FDE = Frame Description Entry | |
53 | information describing the stack call frame, in particular, | |
54 | how to restore registers | |
55 | ||
56 | DW_CFA_... = DWARF2 CFA call frame instruction | |
57 | DW_TAG_... = DWARF2 DIE tag */ | |
58 | ||
0021b564 | 59 | #include "config.h" |
670ee920 | 60 | #include "system.h" |
4977bab6 ZW |
61 | #include "coretypes.h" |
62 | #include "tm.h" | |
a3f97cbb | 63 | #include "tree.h" |
a757585a | 64 | #include "version.h" |
a3f97cbb | 65 | #include "flags.h" |
11ad4784 | 66 | #include "real.h" |
a3f97cbb JW |
67 | #include "rtl.h" |
68 | #include "hard-reg-set.h" | |
69 | #include "regs.h" | |
70 | #include "insn-config.h" | |
71 | #include "reload.h" | |
52a11cbf | 72 | #include "function.h" |
a3f97cbb | 73 | #include "output.h" |
71dfc51f | 74 | #include "expr.h" |
e78d8e51 | 75 | #include "libfuncs.h" |
3f76745e | 76 | #include "except.h" |
a7cc7f29 | 77 | #include "dwarf2.h" |
76ead72b | 78 | #include "dwarf2out.h" |
2e4b9b8c | 79 | #include "dwarf2asm.h" |
10f0ad3d | 80 | #include "toplev.h" |
1865dbb5 | 81 | #include "varray.h" |
951a525f | 82 | #include "ggc.h" |
881c6935 | 83 | #include "md5.h" |
57bed152 | 84 | #include "tm_p.h" |
2a2b2d43 | 85 | #include "diagnostic.h" |
a51d908e | 86 | #include "debug.h" |
07c9d2eb | 87 | #include "target.h" |
3ac88239 | 88 | #include "langhooks.h" |
cc0017a9 | 89 | #include "hashtab.h" |
1bb17c21 | 90 | #include "cgraph.h" |
6097b0c3 | 91 | #include "input.h" |
a3f97cbb | 92 | |
653e276c | 93 | #ifdef DWARF2_DEBUGGING_INFO |
7080f735 | 94 | static void dwarf2out_source_line (unsigned int, const char *); |
653e276c NB |
95 | #endif |
96 | ||
658f32fd AO |
97 | #ifndef DWARF2_FRAME_INFO |
98 | # ifdef DWARF2_DEBUGGING_INFO | |
99 | # define DWARF2_FRAME_INFO \ | |
100 | (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG) | |
101 | # else | |
102 | # define DWARF2_FRAME_INFO 0 | |
103 | # endif | |
104 | #endif | |
105 | ||
fb638355 GK |
106 | /* Map register numbers held in the call frame info that gcc has |
107 | collected using DWARF_FRAME_REGNUM to those that should be output in | |
108 | .debug_frame and .eh_frame. */ | |
109 | #ifndef DWARF2_FRAME_REG_OUT | |
110 | #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO) | |
111 | #endif | |
112 | ||
0021b564 JM |
113 | /* Decide whether we want to emit frame unwind information for the current |
114 | translation unit. */ | |
115 | ||
116 | int | |
7080f735 | 117 | dwarf2out_do_frame (void) |
0021b564 | 118 | { |
658f32fd AO |
119 | /* We want to emit correct CFA location expressions or lists, so we |
120 | have to return true if we're going to output debug info, even if | |
121 | we're not going to output frame or unwind info. */ | |
0021b564 | 122 | return (write_symbols == DWARF2_DEBUG |
7a0c8d71 | 123 | || write_symbols == VMS_AND_DWARF2_DEBUG |
556273e0 | 124 | || DWARF2_FRAME_INFO |
0021b564 | 125 | #ifdef DWARF2_UNWIND_INFO |
658f32fd AO |
126 | || (DWARF2_UNWIND_INFO |
127 | && (flag_unwind_tables | |
128 | || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS))) | |
0021b564 JM |
129 | #endif |
130 | ); | |
131 | } | |
132 | ||
f3a8e4f5 KG |
133 | /* The size of the target's pointer type. */ |
134 | #ifndef PTR_SIZE | |
135 | #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT) | |
136 | #endif | |
137 | ||
e2500fed GK |
138 | /* Array of RTXes referenced by the debugging information, which therefore |
139 | must be kept around forever. */ | |
a1bbd445 | 140 | static GTY(()) VEC(rtx,gc) *used_rtx_array; |
e2500fed GK |
141 | |
142 | /* A pointer to the base of a list of incomplete types which might be | |
887fb69b KH |
143 | completed at some later time. incomplete_types_list needs to be a |
144 | VEC(tree,gc) because we want to tell the garbage collector about | |
145 | it. */ | |
146 | static GTY(()) VEC(tree,gc) *incomplete_types; | |
e2500fed GK |
147 | |
148 | /* A pointer to the base of a table of references to declaration | |
149 | scopes. This table is a display which tracks the nesting | |
150 | of declaration scopes at the current scope and containing | |
151 | scopes. This table is used to find the proper place to | |
152 | define type declaration DIE's. */ | |
0fdc587b | 153 | static GTY(()) VEC(tree,gc) *decl_scope_table; |
e2500fed | 154 | |
d6b5193b RS |
155 | /* Pointers to various DWARF2 sections. */ |
156 | static GTY(()) section *debug_info_section; | |
157 | static GTY(()) section *debug_abbrev_section; | |
158 | static GTY(()) section *debug_aranges_section; | |
159 | static GTY(()) section *debug_macinfo_section; | |
160 | static GTY(()) section *debug_line_section; | |
161 | static GTY(()) section *debug_loc_section; | |
162 | static GTY(()) section *debug_pubnames_section; | |
89708594 | 163 | static GTY(()) section *debug_pubtypes_section; |
d6b5193b RS |
164 | static GTY(()) section *debug_str_section; |
165 | static GTY(()) section *debug_ranges_section; | |
192d0f89 | 166 | static GTY(()) section *debug_frame_section; |
d6b5193b | 167 | |
eaf95893 RK |
168 | /* How to start an assembler comment. */ |
169 | #ifndef ASM_COMMENT_START | |
170 | #define ASM_COMMENT_START ";#" | |
171 | #endif | |
172 | ||
a3f97cbb JW |
173 | typedef struct dw_cfi_struct *dw_cfi_ref; |
174 | typedef struct dw_fde_struct *dw_fde_ref; | |
175 | typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref; | |
a3f97cbb JW |
176 | |
177 | /* Call frames are described using a sequence of Call Frame | |
178 | Information instructions. The register number, offset | |
179 | and address fields are provided as possible operands; | |
180 | their use is selected by the opcode field. */ | |
71dfc51f | 181 | |
17211ab5 GK |
182 | enum dw_cfi_oprnd_type { |
183 | dw_cfi_oprnd_unused, | |
184 | dw_cfi_oprnd_reg_num, | |
185 | dw_cfi_oprnd_offset, | |
186 | dw_cfi_oprnd_addr, | |
187 | dw_cfi_oprnd_loc | |
188 | }; | |
189 | ||
190 | typedef union dw_cfi_oprnd_struct GTY(()) | |
71dfc51f | 191 | { |
f6672e8e | 192 | unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num; |
799f628a | 193 | HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset; |
17211ab5 GK |
194 | const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr; |
195 | struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc; | |
71dfc51f | 196 | } |
a3f97cbb JW |
197 | dw_cfi_oprnd; |
198 | ||
17211ab5 | 199 | typedef struct dw_cfi_struct GTY(()) |
71dfc51f RK |
200 | { |
201 | dw_cfi_ref dw_cfi_next; | |
202 | enum dwarf_call_frame_info dw_cfi_opc; | |
7080f735 | 203 | dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)"))) |
17211ab5 | 204 | dw_cfi_oprnd1; |
7080f735 | 205 | dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)"))) |
17211ab5 | 206 | dw_cfi_oprnd2; |
71dfc51f | 207 | } |
a3f97cbb JW |
208 | dw_cfi_node; |
209 | ||
7d9d8943 AM |
210 | /* This is how we define the location of the CFA. We use to handle it |
211 | as REG + OFFSET all the time, but now it can be more complex. | |
212 | It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET. | |
556273e0 | 213 | Instead of passing around REG and OFFSET, we pass a copy |
7d9d8943 | 214 | of this structure. */ |
17211ab5 | 215 | typedef struct cfa_loc GTY(()) |
7d9d8943 | 216 | { |
799f628a JH |
217 | HOST_WIDE_INT offset; |
218 | HOST_WIDE_INT base_offset; | |
30e6f306 | 219 | unsigned int reg; |
7d9d8943 AM |
220 | int indirect; /* 1 if CFA is accessed via a dereference. */ |
221 | } dw_cfa_location; | |
222 | ||
a3f97cbb | 223 | /* All call frame descriptions (FDE's) in the GCC generated DWARF |
4b674448 | 224 | refer to a single Common Information Entry (CIE), defined at |
fb530c07 | 225 | the beginning of the .debug_frame section. This use of a single |
a3f97cbb JW |
226 | CIE obviates the need to keep track of multiple CIE's |
227 | in the DWARF generation routines below. */ | |
71dfc51f | 228 | |
17211ab5 | 229 | typedef struct dw_fde_struct GTY(()) |
71dfc51f | 230 | { |
4746cf84 | 231 | tree decl; |
d3e3972c KG |
232 | const char *dw_fde_begin; |
233 | const char *dw_fde_current_label; | |
234 | const char *dw_fde_end; | |
87c8b4be CT |
235 | const char *dw_fde_hot_section_label; |
236 | const char *dw_fde_hot_section_end_label; | |
237 | const char *dw_fde_unlikely_section_label; | |
238 | const char *dw_fde_unlikely_section_end_label; | |
239 | bool dw_fde_switched_sections; | |
71dfc51f | 240 | dw_cfi_ref dw_fde_cfi; |
52a11cbf | 241 | unsigned funcdef_number; |
b6128b8c | 242 | unsigned all_throwers_are_sibcalls : 1; |
52a11cbf RH |
243 | unsigned nothrow : 1; |
244 | unsigned uses_eh_lsda : 1; | |
71dfc51f | 245 | } |
a3f97cbb JW |
246 | dw_fde_node; |
247 | ||
6d2f8887 | 248 | /* Maximum size (in bytes) of an artificially generated label. */ |
a3f97cbb JW |
249 | #define MAX_ARTIFICIAL_LABEL_BYTES 30 |
250 | ||
a1a4189d JB |
251 | /* The size of addresses as they appear in the Dwarf 2 data. |
252 | Some architectures use word addresses to refer to code locations, | |
253 | but Dwarf 2 info always uses byte addresses. On such machines, | |
254 | Dwarf 2 addresses need to be larger than the architecture's | |
255 | pointers. */ | |
256 | #ifndef DWARF2_ADDR_SIZE | |
257 | #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT) | |
258 | #endif | |
259 | ||
7e23cb16 | 260 | /* The size in bytes of a DWARF field indicating an offset or length |
a1a4189d JB |
261 | relative to a debug info section, specified to be 4 bytes in the |
262 | DWARF-2 specification. The SGI/MIPS ABI defines it to be the same | |
b13fe8bf | 263 | as PTR_SIZE. */ |
71dfc51f | 264 | |
7e23cb16 JM |
265 | #ifndef DWARF_OFFSET_SIZE |
266 | #define DWARF_OFFSET_SIZE 4 | |
267 | #endif | |
268 | ||
9eb0ef7a KB |
269 | /* According to the (draft) DWARF 3 specification, the initial length |
270 | should either be 4 or 12 bytes. When it's 12 bytes, the first 4 | |
271 | bytes are 0xffffffff, followed by the length stored in the next 8 | |
272 | bytes. | |
273 | ||
274 | However, the SGI/MIPS ABI uses an initial length which is equal to | |
275 | DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */ | |
276 | ||
277 | #ifndef DWARF_INITIAL_LENGTH_SIZE | |
278 | #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12) | |
279 | #endif | |
280 | ||
9a666dda JM |
281 | #define DWARF_VERSION 2 |
282 | ||
7e23cb16 JM |
283 | /* Round SIZE up to the nearest BOUNDARY. */ |
284 | #define DWARF_ROUND(SIZE,BOUNDARY) \ | |
262b6384 | 285 | ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY)) |
a3f97cbb | 286 | |
a3f97cbb | 287 | /* Offsets recorded in opcodes are a multiple of this alignment factor. */ |
27c35f4b | 288 | #ifndef DWARF_CIE_DATA_ALIGNMENT |
469ac993 | 289 | #ifdef STACK_GROWS_DOWNWARD |
08cb3d38 | 290 | #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD)) |
469ac993 | 291 | #else |
08cb3d38 | 292 | #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD) |
469ac993 | 293 | #endif |
2ad9852d | 294 | #endif |
a3f97cbb | 295 | |
0c33762a JM |
296 | /* CIE identifier. */ |
297 | #if HOST_BITS_PER_WIDE_INT >= 64 | |
298 | #define DWARF_CIE_ID \ | |
299 | (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID) | |
300 | #else | |
301 | #define DWARF_CIE_ID DW_CIE_ID | |
302 | #endif | |
303 | ||
3f76745e JM |
304 | /* A pointer to the base of a table that contains frame description |
305 | information for each routine. */ | |
17211ab5 | 306 | static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table; |
a3f97cbb | 307 | |
3f76745e | 308 | /* Number of elements currently allocated for fde_table. */ |
c2e9147c | 309 | static GTY(()) unsigned fde_table_allocated; |
a94dbf2c | 310 | |
3f76745e | 311 | /* Number of elements in fde_table currently in use. */ |
044b4de3 | 312 | static GTY(()) unsigned fde_table_in_use; |
a3f97cbb | 313 | |
3f76745e JM |
314 | /* Size (in elements) of increments by which we may expand the |
315 | fde_table. */ | |
316 | #define FDE_TABLE_INCREMENT 256 | |
a3f97cbb | 317 | |
3395aa05 L |
318 | /* Get the current fde_table entry we should use. */ |
319 | ||
320 | static inline dw_fde_ref | |
321 | current_fde (void) | |
322 | { | |
323 | return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL; | |
324 | } | |
325 | ||
a94dbf2c | 326 | /* A list of call frame insns for the CIE. */ |
17211ab5 | 327 | static GTY(()) dw_cfi_ref cie_cfi_head; |
a94dbf2c | 328 | |
c1b50e49 | 329 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) |
a3f97cbb JW |
330 | /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram |
331 | attribute that accelerates the lookup of the FDE associated | |
556273e0 | 332 | with the subprogram. This variable holds the table index of the FDE |
a3f97cbb JW |
333 | associated with the current function (body) definition. */ |
334 | static unsigned current_funcdef_fde; | |
c1b50e49 | 335 | #endif |
a3f97cbb | 336 | |
17211ab5 | 337 | struct indirect_string_node GTY(()) |
9eb4015a | 338 | { |
17211ab5 | 339 | const char *str; |
9eb4015a JJ |
340 | unsigned int refcount; |
341 | unsigned int form; | |
342 | char *label; | |
343 | }; | |
344 | ||
17211ab5 GK |
345 | static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash; |
346 | ||
347 | static GTY(()) int dw2_string_counter; | |
044b4de3 | 348 | static GTY(()) unsigned long dwarf2out_cfi_label_num; |
17211ab5 | 349 | |
74ab34d3 UB |
350 | /* True if the compilation unit places functions in more than one section. */ |
351 | static GTY(()) bool have_multiple_function_sections = false; | |
352 | ||
353 | /* Whether the default text and cold text sections have been used at all. */ | |
354 | ||
355 | static GTY(()) bool text_section_used = false; | |
356 | static GTY(()) bool cold_text_section_used = false; | |
357 | ||
358 | /* The default cold text section. */ | |
359 | static GTY(()) section *cold_text_section; | |
360 | ||
17211ab5 GK |
361 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) |
362 | ||
a3f97cbb | 363 | /* Forward declarations for functions defined in this file. */ |
71dfc51f | 364 | |
7080f735 AJ |
365 | static char *stripattributes (const char *); |
366 | static const char *dwarf_cfi_name (unsigned); | |
367 | static dw_cfi_ref new_cfi (void); | |
368 | static void add_cfi (dw_cfi_ref *, dw_cfi_ref); | |
369 | static void add_fde_cfi (const char *, dw_cfi_ref); | |
370 | static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *); | |
371 | static void lookup_cfa (dw_cfa_location *); | |
799f628a | 372 | static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT); |
36bd4303 | 373 | #ifdef DWARF2_UNWIND_INFO |
7080f735 | 374 | static void initial_return_save (rtx); |
36bd4303 | 375 | #endif |
9678086d | 376 | static HOST_WIDE_INT stack_adjust_offset (const_rtx); |
7080f735 AJ |
377 | static void output_cfi (dw_cfi_ref, dw_fde_ref, int); |
378 | static void output_call_frame_info (int); | |
74ab34d3 | 379 | static void dwarf2out_note_section_used (void); |
e0c0490b | 380 | static void dwarf2out_stack_adjust (rtx, bool); |
7080f735 | 381 | static void flush_queued_reg_saves (void); |
9678086d | 382 | static bool clobbers_queued_reg_save (const_rtx); |
7080f735 | 383 | static void dwarf2out_frame_debug_expr (rtx, const char *); |
a3f97cbb | 384 | |
7d9d8943 | 385 | /* Support for complex CFA locations. */ |
7080f735 AJ |
386 | static void output_cfa_loc (dw_cfi_ref); |
387 | static void get_cfa_from_loc_descr (dw_cfa_location *, | |
388 | struct dw_loc_descr_struct *); | |
7d9d8943 | 389 | static struct dw_loc_descr_struct *build_cfa_loc |
35d177a2 | 390 | (dw_cfa_location *, HOST_WIDE_INT); |
7080f735 | 391 | static void def_cfa_1 (const char *, dw_cfa_location *); |
7d9d8943 | 392 | |
2e4b9b8c RH |
393 | /* How to start an assembler comment. */ |
394 | #ifndef ASM_COMMENT_START | |
395 | #define ASM_COMMENT_START ";#" | |
a3f97cbb JW |
396 | #endif |
397 | ||
7e23cb16 JM |
398 | /* Data and reference forms for relocatable data. */ |
399 | #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4) | |
400 | #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4) | |
401 | ||
cf2fe500 RH |
402 | #ifndef DEBUG_FRAME_SECTION |
403 | #define DEBUG_FRAME_SECTION ".debug_frame" | |
a3f97cbb | 404 | #endif |
a3f97cbb | 405 | |
5c90448c JM |
406 | #ifndef FUNC_BEGIN_LABEL |
407 | #define FUNC_BEGIN_LABEL "LFB" | |
a3f97cbb | 408 | #endif |
2ad9852d | 409 | |
5c90448c JM |
410 | #ifndef FUNC_END_LABEL |
411 | #define FUNC_END_LABEL "LFE" | |
a3f97cbb | 412 | #endif |
2ad9852d | 413 | |
4746cf84 | 414 | #ifndef FRAME_BEGIN_LABEL |
27d95cbe | 415 | #define FRAME_BEGIN_LABEL "Lframe" |
4746cf84 | 416 | #endif |
a6ab3aad JM |
417 | #define CIE_AFTER_SIZE_LABEL "LSCIE" |
418 | #define CIE_END_LABEL "LECIE" | |
2e4b9b8c RH |
419 | #define FDE_LABEL "LSFDE" |
420 | #define FDE_AFTER_SIZE_LABEL "LASFDE" | |
a6ab3aad | 421 | #define FDE_END_LABEL "LEFDE" |
981975b6 RH |
422 | #define LINE_NUMBER_BEGIN_LABEL "LSLT" |
423 | #define LINE_NUMBER_END_LABEL "LELT" | |
424 | #define LN_PROLOG_AS_LABEL "LASLTP" | |
425 | #define LN_PROLOG_END_LABEL "LELTP" | |
881c6935 | 426 | #define DIE_LABEL_PREFIX "DW" |
a3f97cbb | 427 | |
c8cc5c4a | 428 | /* The DWARF 2 CFA column which tracks the return address. Normally this |
a94dbf2c JM |
429 | is the column for PC, or the first column after all of the hard |
430 | registers. */ | |
c8cc5c4a | 431 | #ifndef DWARF_FRAME_RETURN_COLUMN |
a94dbf2c | 432 | #ifdef PC_REGNUM |
7080f735 | 433 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM) |
a94dbf2c | 434 | #else |
7080f735 | 435 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS |
a94dbf2c | 436 | #endif |
c8cc5c4a JM |
437 | #endif |
438 | ||
439 | /* The mapping from gcc register number to DWARF 2 CFA column number. By | |
469ac993 | 440 | default, we just provide columns for all registers. */ |
c8cc5c4a | 441 | #ifndef DWARF_FRAME_REGNUM |
469ac993 | 442 | #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG) |
c8cc5c4a | 443 | #endif |
2ad9852d | 444 | \f |
0021b564 JM |
445 | /* Hook used by __throw. */ |
446 | ||
447 | rtx | |
7080f735 | 448 | expand_builtin_dwarf_sp_column (void) |
0021b564 | 449 | { |
8f4fc766 | 450 | unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM); |
fb638355 | 451 | return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1)); |
0021b564 JM |
452 | } |
453 | ||
71dfc51f | 454 | /* Return a pointer to a copy of the section string name S with all |
bf20f341 | 455 | attributes stripped off, and an asterisk prepended (for assemble_name). */ |
71dfc51f RK |
456 | |
457 | static inline char * | |
7080f735 | 458 | stripattributes (const char *s) |
a3f97cbb | 459 | { |
5ed6ace5 | 460 | char *stripped = XNEWVEC (char, strlen (s) + 2); |
71dfc51f RK |
461 | char *p = stripped; |
462 | ||
bf20f341 JW |
463 | *p++ = '*'; |
464 | ||
465 | while (*s && *s != ',') | |
466 | *p++ = *s++; | |
71dfc51f | 467 | |
a3f97cbb JW |
468 | *p = '\0'; |
469 | return stripped; | |
470 | } | |
471 | ||
5cd0f915 RS |
472 | /* MEM is a memory reference for the register size table, each element of |
473 | which has mode MODE. Initialize column C as a return address column. */ | |
474 | ||
475 | static void | |
476 | init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c) | |
477 | { | |
478 | HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode); | |
479 | HOST_WIDE_INT size = GET_MODE_SIZE (Pmode); | |
480 | emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size)); | |
481 | } | |
482 | ||
d9d5c9de | 483 | /* Generate code to initialize the register size table. */ |
2f3ca9e7 | 484 | |
d9d5c9de | 485 | void |
7080f735 | 486 | expand_builtin_init_dwarf_reg_sizes (tree address) |
2f3ca9e7 | 487 | { |
8f4fc766 | 488 | unsigned int i; |
d9d5c9de | 489 | enum machine_mode mode = TYPE_MODE (char_type_node); |
84217346 | 490 | rtx addr = expand_normal (address); |
2ad9852d | 491 | rtx mem = gen_rtx_MEM (BLKmode, addr); |
71628aa0 | 492 | bool wrote_return_column = false; |
2f3ca9e7 | 493 | |
91ea38f9 | 494 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) |
fb638355 GK |
495 | { |
496 | int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1); | |
2878ea73 | 497 | |
fb638355 GK |
498 | if (rnum < DWARF_FRAME_REGISTERS) |
499 | { | |
500 | HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode); | |
501 | enum machine_mode save_mode = reg_raw_mode[i]; | |
502 | HOST_WIDE_INT size; | |
2878ea73 | 503 | |
fb638355 GK |
504 | if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode)) |
505 | save_mode = choose_hard_reg_mode (i, 1, true); | |
506 | if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN) | |
507 | { | |
508 | if (save_mode == VOIDmode) | |
509 | continue; | |
510 | wrote_return_column = true; | |
511 | } | |
512 | size = GET_MODE_SIZE (save_mode); | |
513 | if (offset < 0) | |
514 | continue; | |
2878ea73 | 515 | |
fb638355 GK |
516 | emit_move_insn (adjust_address (mem, mode, offset), |
517 | gen_int_mode (size, mode)); | |
518 | } | |
519 | } | |
ed80cd68 | 520 | |
5cd0f915 RS |
521 | if (!wrote_return_column) |
522 | init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN); | |
523 | ||
ed80cd68 | 524 | #ifdef DWARF_ALT_FRAME_RETURN_COLUMN |
5cd0f915 | 525 | init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN); |
ed80cd68 | 526 | #endif |
37ea0b7e JM |
527 | |
528 | targetm.init_dwarf_reg_sizes_extra (address); | |
2f3ca9e7 JM |
529 | } |
530 | ||
3f76745e | 531 | /* Convert a DWARF call frame info. operation to its string name */ |
a3f97cbb | 532 | |
d560ee52 | 533 | static const char * |
7080f735 | 534 | dwarf_cfi_name (unsigned int cfi_opc) |
3f76745e JM |
535 | { |
536 | switch (cfi_opc) | |
537 | { | |
538 | case DW_CFA_advance_loc: | |
539 | return "DW_CFA_advance_loc"; | |
540 | case DW_CFA_offset: | |
541 | return "DW_CFA_offset"; | |
542 | case DW_CFA_restore: | |
543 | return "DW_CFA_restore"; | |
544 | case DW_CFA_nop: | |
545 | return "DW_CFA_nop"; | |
546 | case DW_CFA_set_loc: | |
547 | return "DW_CFA_set_loc"; | |
548 | case DW_CFA_advance_loc1: | |
549 | return "DW_CFA_advance_loc1"; | |
550 | case DW_CFA_advance_loc2: | |
551 | return "DW_CFA_advance_loc2"; | |
552 | case DW_CFA_advance_loc4: | |
553 | return "DW_CFA_advance_loc4"; | |
554 | case DW_CFA_offset_extended: | |
555 | return "DW_CFA_offset_extended"; | |
556 | case DW_CFA_restore_extended: | |
557 | return "DW_CFA_restore_extended"; | |
558 | case DW_CFA_undefined: | |
559 | return "DW_CFA_undefined"; | |
560 | case DW_CFA_same_value: | |
561 | return "DW_CFA_same_value"; | |
562 | case DW_CFA_register: | |
563 | return "DW_CFA_register"; | |
564 | case DW_CFA_remember_state: | |
565 | return "DW_CFA_remember_state"; | |
566 | case DW_CFA_restore_state: | |
567 | return "DW_CFA_restore_state"; | |
568 | case DW_CFA_def_cfa: | |
569 | return "DW_CFA_def_cfa"; | |
570 | case DW_CFA_def_cfa_register: | |
571 | return "DW_CFA_def_cfa_register"; | |
572 | case DW_CFA_def_cfa_offset: | |
573 | return "DW_CFA_def_cfa_offset"; | |
6bb28965 JM |
574 | |
575 | /* DWARF 3 */ | |
7d9d8943 AM |
576 | case DW_CFA_def_cfa_expression: |
577 | return "DW_CFA_def_cfa_expression"; | |
6bb28965 JM |
578 | case DW_CFA_expression: |
579 | return "DW_CFA_expression"; | |
580 | case DW_CFA_offset_extended_sf: | |
581 | return "DW_CFA_offset_extended_sf"; | |
582 | case DW_CFA_def_cfa_sf: | |
583 | return "DW_CFA_def_cfa_sf"; | |
584 | case DW_CFA_def_cfa_offset_sf: | |
585 | return "DW_CFA_def_cfa_offset_sf"; | |
c53aa195 | 586 | |
3f76745e JM |
587 | /* SGI/MIPS specific */ |
588 | case DW_CFA_MIPS_advance_loc8: | |
589 | return "DW_CFA_MIPS_advance_loc8"; | |
c53aa195 JM |
590 | |
591 | /* GNU extensions */ | |
592 | case DW_CFA_GNU_window_save: | |
593 | return "DW_CFA_GNU_window_save"; | |
0021b564 JM |
594 | case DW_CFA_GNU_args_size: |
595 | return "DW_CFA_GNU_args_size"; | |
3f388b42 GK |
596 | case DW_CFA_GNU_negative_offset_extended: |
597 | return "DW_CFA_GNU_negative_offset_extended"; | |
c53aa195 | 598 | |
3f76745e JM |
599 | default: |
600 | return "DW_CFA_<unknown>"; | |
601 | } | |
602 | } | |
a3f97cbb | 603 | |
3f76745e | 604 | /* Return a pointer to a newly allocated Call Frame Instruction. */ |
71dfc51f | 605 | |
3f76745e | 606 | static inline dw_cfi_ref |
7080f735 | 607 | new_cfi (void) |
3f76745e | 608 | { |
1b4572a8 | 609 | dw_cfi_ref cfi = GGC_NEW (dw_cfi_node); |
71dfc51f | 610 | |
3f76745e JM |
611 | cfi->dw_cfi_next = NULL; |
612 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0; | |
613 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0; | |
a3f97cbb | 614 | |
3f76745e JM |
615 | return cfi; |
616 | } | |
a3f97cbb | 617 | |
3f76745e | 618 | /* Add a Call Frame Instruction to list of instructions. */ |
a3f97cbb | 619 | |
3f76745e | 620 | static inline void |
7080f735 | 621 | add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi) |
3f76745e | 622 | { |
b3694847 | 623 | dw_cfi_ref *p; |
a3f97cbb | 624 | |
3f76745e JM |
625 | /* Find the end of the chain. */ |
626 | for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next) | |
627 | ; | |
628 | ||
629 | *p = cfi; | |
a3f97cbb JW |
630 | } |
631 | ||
3f76745e | 632 | /* Generate a new label for the CFI info to refer to. */ |
71dfc51f | 633 | |
c53aa195 | 634 | char * |
7080f735 | 635 | dwarf2out_cfi_label (void) |
a3f97cbb | 636 | { |
3f76745e | 637 | static char label[20]; |
556273e0 | 638 | |
044b4de3 | 639 | ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++); |
3f76745e | 640 | ASM_OUTPUT_LABEL (asm_out_file, label); |
3f76745e | 641 | return label; |
a3f97cbb JW |
642 | } |
643 | ||
3f76745e JM |
644 | /* Add CFI to the current fde at the PC value indicated by LABEL if specified, |
645 | or to the CIE if LABEL is NULL. */ | |
71dfc51f | 646 | |
3f76745e | 647 | static void |
7080f735 | 648 | add_fde_cfi (const char *label, dw_cfi_ref cfi) |
a3f97cbb | 649 | { |
3f76745e JM |
650 | if (label) |
651 | { | |
3ce6e42e XG |
652 | dw_fde_ref fde = current_fde (); |
653 | ||
654 | gcc_assert (fde != NULL); | |
a3f97cbb | 655 | |
3f76745e JM |
656 | if (*label == 0) |
657 | label = dwarf2out_cfi_label (); | |
71dfc51f | 658 | |
3f76745e JM |
659 | if (fde->dw_fde_current_label == NULL |
660 | || strcmp (label, fde->dw_fde_current_label) != 0) | |
661 | { | |
b3694847 | 662 | dw_cfi_ref xcfi; |
a3f97cbb | 663 | |
6a10f7b3 | 664 | label = xstrdup (label); |
71dfc51f | 665 | |
3f76745e JM |
666 | /* Set the location counter to the new label. */ |
667 | xcfi = new_cfi (); | |
6a10f7b3 RS |
668 | /* If we have a current label, advance from there, otherwise |
669 | set the location directly using set_loc. */ | |
670 | xcfi->dw_cfi_opc = fde->dw_fde_current_label | |
671 | ? DW_CFA_advance_loc4 | |
672 | : DW_CFA_set_loc; | |
3f76745e JM |
673 | xcfi->dw_cfi_oprnd1.dw_cfi_addr = label; |
674 | add_cfi (&fde->dw_fde_cfi, xcfi); | |
6a10f7b3 RS |
675 | |
676 | fde->dw_fde_current_label = label; | |
3f76745e | 677 | } |
71dfc51f | 678 | |
3f76745e JM |
679 | add_cfi (&fde->dw_fde_cfi, cfi); |
680 | } | |
681 | ||
682 | else | |
683 | add_cfi (&cie_cfi_head, cfi); | |
a3f97cbb JW |
684 | } |
685 | ||
3f76745e | 686 | /* Subroutine of lookup_cfa. */ |
71dfc51f | 687 | |
30e6f306 | 688 | static void |
7080f735 | 689 | lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc) |
a3f97cbb | 690 | { |
3f76745e JM |
691 | switch (cfi->dw_cfi_opc) |
692 | { | |
693 | case DW_CFA_def_cfa_offset: | |
7d9d8943 | 694 | loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset; |
3f76745e | 695 | break; |
f6672e8e RH |
696 | case DW_CFA_def_cfa_offset_sf: |
697 | loc->offset | |
698 | = cfi->dw_cfi_oprnd1.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT; | |
699 | break; | |
3f76745e | 700 | case DW_CFA_def_cfa_register: |
7d9d8943 | 701 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
3f76745e JM |
702 | break; |
703 | case DW_CFA_def_cfa: | |
7d9d8943 AM |
704 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
705 | loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset; | |
706 | break; | |
f6672e8e RH |
707 | case DW_CFA_def_cfa_sf: |
708 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; | |
709 | loc->offset | |
710 | = cfi->dw_cfi_oprnd2.dw_cfi_offset * DWARF_CIE_DATA_ALIGNMENT; | |
711 | break; | |
7d9d8943 AM |
712 | case DW_CFA_def_cfa_expression: |
713 | get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc); | |
3f76745e | 714 | break; |
e9a25f70 JL |
715 | default: |
716 | break; | |
3f76745e | 717 | } |
a3f97cbb JW |
718 | } |
719 | ||
3f76745e | 720 | /* Find the previous value for the CFA. */ |
71dfc51f | 721 | |
3f76745e | 722 | static void |
7080f735 | 723 | lookup_cfa (dw_cfa_location *loc) |
a3f97cbb | 724 | { |
b3694847 | 725 | dw_cfi_ref cfi; |
3ce6e42e | 726 | dw_fde_ref fde; |
3f76745e | 727 | |
30e6f306 | 728 | loc->reg = INVALID_REGNUM; |
7d9d8943 AM |
729 | loc->offset = 0; |
730 | loc->indirect = 0; | |
731 | loc->base_offset = 0; | |
3f76745e JM |
732 | |
733 | for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next) | |
7d9d8943 | 734 | lookup_cfa_1 (cfi, loc); |
3f76745e | 735 | |
3ce6e42e XG |
736 | fde = current_fde (); |
737 | if (fde) | |
738 | for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next) | |
739 | lookup_cfa_1 (cfi, loc); | |
a3f97cbb JW |
740 | } |
741 | ||
3f76745e | 742 | /* The current rule for calculating the DWARF2 canonical frame address. */ |
fbfa55b0 | 743 | static dw_cfa_location cfa; |
71dfc51f | 744 | |
3f76745e JM |
745 | /* The register used for saving registers to the stack, and its offset |
746 | from the CFA. */ | |
fbfa55b0 | 747 | static dw_cfa_location cfa_store; |
3f76745e | 748 | |
0021b564 | 749 | /* The running total of the size of arguments pushed onto the stack. */ |
799f628a | 750 | static HOST_WIDE_INT args_size; |
0021b564 | 751 | |
b57d9225 | 752 | /* The last args_size we actually output. */ |
799f628a | 753 | static HOST_WIDE_INT old_args_size; |
b57d9225 | 754 | |
3f76745e JM |
755 | /* Entry point to update the canonical frame address (CFA). |
756 | LABEL is passed to add_fde_cfi. The value of CFA is now to be | |
757 | calculated from REG+OFFSET. */ | |
758 | ||
759 | void | |
799f628a | 760 | dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset) |
7d9d8943 AM |
761 | { |
762 | dw_cfa_location loc; | |
763 | loc.indirect = 0; | |
764 | loc.base_offset = 0; | |
765 | loc.reg = reg; | |
766 | loc.offset = offset; | |
767 | def_cfa_1 (label, &loc); | |
768 | } | |
769 | ||
30e6f306 RH |
770 | /* Determine if two dw_cfa_location structures define the same data. */ |
771 | ||
772 | static bool | |
773 | cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2) | |
774 | { | |
775 | return (loc1->reg == loc2->reg | |
776 | && loc1->offset == loc2->offset | |
777 | && loc1->indirect == loc2->indirect | |
778 | && (loc1->indirect == 0 | |
779 | || loc1->base_offset == loc2->base_offset)); | |
780 | } | |
781 | ||
770ca8c6 | 782 | /* This routine does the actual work. The CFA is now calculated from |
7d9d8943 | 783 | the dw_cfa_location structure. */ |
2ad9852d | 784 | |
7d9d8943 | 785 | static void |
7080f735 | 786 | def_cfa_1 (const char *label, dw_cfa_location *loc_p) |
a3f97cbb | 787 | { |
b3694847 | 788 | dw_cfi_ref cfi; |
7d9d8943 | 789 | dw_cfa_location old_cfa, loc; |
3f76745e | 790 | |
7d9d8943 AM |
791 | cfa = *loc_p; |
792 | loc = *loc_p; | |
5bef9b1f | 793 | |
7d9d8943 AM |
794 | if (cfa_store.reg == loc.reg && loc.indirect == 0) |
795 | cfa_store.offset = loc.offset; | |
3f76745e | 796 | |
7d9d8943 AM |
797 | loc.reg = DWARF_FRAME_REGNUM (loc.reg); |
798 | lookup_cfa (&old_cfa); | |
799 | ||
2ad9852d | 800 | /* If nothing changed, no need to issue any call frame instructions. */ |
30e6f306 | 801 | if (cfa_equal_p (&loc, &old_cfa)) |
2ad9852d | 802 | return; |
3f76745e JM |
803 | |
804 | cfi = new_cfi (); | |
805 | ||
e09bbb25 | 806 | if (loc.reg == old_cfa.reg && !loc.indirect) |
a3f97cbb | 807 | { |
f6672e8e RH |
808 | /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating |
809 | the CFA register did not change but the offset did. */ | |
810 | if (loc.offset < 0) | |
811 | { | |
812 | HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT; | |
813 | gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset); | |
814 | ||
815 | cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf; | |
816 | cfi->dw_cfi_oprnd1.dw_cfi_offset = f_offset; | |
817 | } | |
818 | else | |
819 | { | |
820 | cfi->dw_cfi_opc = DW_CFA_def_cfa_offset; | |
821 | cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset; | |
822 | } | |
3f76745e | 823 | } |
a3f97cbb | 824 | |
3f76745e | 825 | #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */ |
30e6f306 RH |
826 | else if (loc.offset == old_cfa.offset |
827 | && old_cfa.reg != INVALID_REGNUM | |
e09bbb25 | 828 | && !loc.indirect) |
3f76745e | 829 | { |
770ca8c6 JO |
830 | /* Construct a "DW_CFA_def_cfa_register <register>" instruction, |
831 | indicating the CFA register has changed to <register> but the | |
832 | offset has not changed. */ | |
3f76745e | 833 | cfi->dw_cfi_opc = DW_CFA_def_cfa_register; |
7d9d8943 | 834 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
3f76745e JM |
835 | } |
836 | #endif | |
a3f97cbb | 837 | |
7d9d8943 | 838 | else if (loc.indirect == 0) |
3f76745e | 839 | { |
770ca8c6 JO |
840 | /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction, |
841 | indicating the CFA register has changed to <register> with | |
842 | the specified offset. */ | |
f6672e8e RH |
843 | if (loc.offset < 0) |
844 | { | |
845 | HOST_WIDE_INT f_offset = loc.offset / DWARF_CIE_DATA_ALIGNMENT; | |
846 | gcc_assert (f_offset * DWARF_CIE_DATA_ALIGNMENT == loc.offset); | |
847 | ||
848 | cfi->dw_cfi_opc = DW_CFA_def_cfa_sf; | |
849 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; | |
850 | cfi->dw_cfi_oprnd2.dw_cfi_offset = f_offset; | |
851 | } | |
852 | else | |
853 | { | |
854 | cfi->dw_cfi_opc = DW_CFA_def_cfa; | |
855 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; | |
856 | cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset; | |
857 | } | |
7d9d8943 AM |
858 | } |
859 | else | |
860 | { | |
770ca8c6 JO |
861 | /* Construct a DW_CFA_def_cfa_expression instruction to |
862 | calculate the CFA using a full location expression since no | |
863 | register-offset pair is available. */ | |
556273e0 | 864 | struct dw_loc_descr_struct *loc_list; |
2ad9852d | 865 | |
7d9d8943 | 866 | cfi->dw_cfi_opc = DW_CFA_def_cfa_expression; |
35d177a2 | 867 | loc_list = build_cfa_loc (&loc, 0); |
7d9d8943 | 868 | cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list; |
a3f97cbb | 869 | } |
3f76745e JM |
870 | |
871 | add_fde_cfi (label, cfi); | |
a3f97cbb JW |
872 | } |
873 | ||
3f76745e JM |
874 | /* Add the CFI for saving a register. REG is the CFA column number. |
875 | LABEL is passed to add_fde_cfi. | |
876 | If SREG is -1, the register is saved at OFFSET from the CFA; | |
877 | otherwise it is saved in SREG. */ | |
71dfc51f | 878 | |
3f76745e | 879 | static void |
799f628a | 880 | reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset) |
a3f97cbb | 881 | { |
b3694847 | 882 | dw_cfi_ref cfi = new_cfi (); |
3f76745e JM |
883 | |
884 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
885 | ||
1bac3811 | 886 | if (sreg == INVALID_REGNUM) |
a3f97cbb | 887 | { |
3f76745e JM |
888 | if (reg & ~0x3f) |
889 | /* The register number won't fit in 6 bits, so we have to use | |
890 | the long form. */ | |
891 | cfi->dw_cfi_opc = DW_CFA_offset_extended; | |
892 | else | |
893 | cfi->dw_cfi_opc = DW_CFA_offset; | |
894 | ||
27c35f4b HPN |
895 | #ifdef ENABLE_CHECKING |
896 | { | |
897 | /* If we get an offset that is not a multiple of | |
898 | DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the | |
899 | definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine | |
900 | description. */ | |
799f628a | 901 | HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT; |
27c35f4b | 902 | |
ced3f397 | 903 | gcc_assert (check_offset * DWARF_CIE_DATA_ALIGNMENT == offset); |
27c35f4b HPN |
904 | } |
905 | #endif | |
3f76745e | 906 | offset /= DWARF_CIE_DATA_ALIGNMENT; |
3a88cbd1 | 907 | if (offset < 0) |
6bb28965 | 908 | cfi->dw_cfi_opc = DW_CFA_offset_extended_sf; |
2ad9852d | 909 | |
3f76745e JM |
910 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; |
911 | } | |
2c849145 | 912 | else if (sreg == reg) |
f8a57be8 | 913 | cfi->dw_cfi_opc = DW_CFA_same_value; |
3f76745e JM |
914 | else |
915 | { | |
916 | cfi->dw_cfi_opc = DW_CFA_register; | |
917 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg; | |
918 | } | |
919 | ||
920 | add_fde_cfi (label, cfi); | |
921 | } | |
922 | ||
c53aa195 JM |
923 | /* Add the CFI for saving a register window. LABEL is passed to reg_save. |
924 | This CFI tells the unwinder that it needs to restore the window registers | |
925 | from the previous frame's window save area. | |
556273e0 | 926 | |
c53aa195 JM |
927 | ??? Perhaps we should note in the CIE where windows are saved (instead of |
928 | assuming 0(cfa)) and what registers are in the window. */ | |
929 | ||
930 | void | |
7080f735 | 931 | dwarf2out_window_save (const char *label) |
c53aa195 | 932 | { |
b3694847 | 933 | dw_cfi_ref cfi = new_cfi (); |
2ad9852d | 934 | |
c53aa195 JM |
935 | cfi->dw_cfi_opc = DW_CFA_GNU_window_save; |
936 | add_fde_cfi (label, cfi); | |
937 | } | |
938 | ||
0021b564 JM |
939 | /* Add a CFI to update the running total of the size of arguments |
940 | pushed onto the stack. */ | |
941 | ||
942 | void | |
799f628a | 943 | dwarf2out_args_size (const char *label, HOST_WIDE_INT size) |
0021b564 | 944 | { |
b3694847 | 945 | dw_cfi_ref cfi; |
b57d9225 JM |
946 | |
947 | if (size == old_args_size) | |
948 | return; | |
2ad9852d | 949 | |
b57d9225 JM |
950 | old_args_size = size; |
951 | ||
952 | cfi = new_cfi (); | |
0021b564 JM |
953 | cfi->dw_cfi_opc = DW_CFA_GNU_args_size; |
954 | cfi->dw_cfi_oprnd1.dw_cfi_offset = size; | |
955 | add_fde_cfi (label, cfi); | |
956 | } | |
957 | ||
c53aa195 JM |
958 | /* Entry point for saving a register to the stack. REG is the GCC register |
959 | number. LABEL and OFFSET are passed to reg_save. */ | |
3f76745e JM |
960 | |
961 | void | |
799f628a | 962 | dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset) |
3f76745e | 963 | { |
1bac3811 | 964 | reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset); |
3f76745e JM |
965 | } |
966 | ||
c53aa195 JM |
967 | /* Entry point for saving the return address in the stack. |
968 | LABEL and OFFSET are passed to reg_save. */ | |
969 | ||
970 | void | |
799f628a | 971 | dwarf2out_return_save (const char *label, HOST_WIDE_INT offset) |
c53aa195 | 972 | { |
1bac3811 | 973 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset); |
c53aa195 JM |
974 | } |
975 | ||
976 | /* Entry point for saving the return address in a register. | |
977 | LABEL and SREG are passed to reg_save. */ | |
978 | ||
979 | void | |
7080f735 | 980 | dwarf2out_return_reg (const char *label, unsigned int sreg) |
c53aa195 | 981 | { |
1bac3811 | 982 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0); |
c53aa195 JM |
983 | } |
984 | ||
36bd4303 | 985 | #ifdef DWARF2_UNWIND_INFO |
3f76745e JM |
986 | /* Record the initial position of the return address. RTL is |
987 | INCOMING_RETURN_ADDR_RTX. */ | |
988 | ||
989 | static void | |
7080f735 | 990 | initial_return_save (rtx rtl) |
3f76745e | 991 | { |
1bac3811 | 992 | unsigned int reg = INVALID_REGNUM; |
2ad9852d | 993 | HOST_WIDE_INT offset = 0; |
3f76745e JM |
994 | |
995 | switch (GET_CODE (rtl)) | |
996 | { | |
997 | case REG: | |
998 | /* RA is in a register. */ | |
2c849145 | 999 | reg = DWARF_FRAME_REGNUM (REGNO (rtl)); |
3f76745e | 1000 | break; |
2ad9852d | 1001 | |
3f76745e JM |
1002 | case MEM: |
1003 | /* RA is on the stack. */ | |
1004 | rtl = XEXP (rtl, 0); | |
1005 | switch (GET_CODE (rtl)) | |
1006 | { | |
1007 | case REG: | |
ced3f397 | 1008 | gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM); |
3f76745e JM |
1009 | offset = 0; |
1010 | break; | |
2ad9852d | 1011 | |
3f76745e | 1012 | case PLUS: |
ced3f397 | 1013 | gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM); |
3f76745e JM |
1014 | offset = INTVAL (XEXP (rtl, 1)); |
1015 | break; | |
2ad9852d | 1016 | |
3f76745e | 1017 | case MINUS: |
ced3f397 | 1018 | gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM); |
3f76745e JM |
1019 | offset = -INTVAL (XEXP (rtl, 1)); |
1020 | break; | |
2ad9852d | 1021 | |
3f76745e | 1022 | default: |
ced3f397 | 1023 | gcc_unreachable (); |
3f76745e | 1024 | } |
2ad9852d | 1025 | |
3f76745e | 1026 | break; |
2ad9852d | 1027 | |
c53aa195 JM |
1028 | case PLUS: |
1029 | /* The return address is at some offset from any value we can | |
1030 | actually load. For instance, on the SPARC it is in %i7+8. Just | |
1031 | ignore the offset for now; it doesn't matter for unwinding frames. */ | |
ced3f397 | 1032 | gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT); |
c53aa195 JM |
1033 | initial_return_save (XEXP (rtl, 0)); |
1034 | return; | |
2ad9852d | 1035 | |
a3f97cbb | 1036 | default: |
ced3f397 | 1037 | gcc_unreachable (); |
a3f97cbb | 1038 | } |
3f76745e | 1039 | |
f8a57be8 GK |
1040 | if (reg != DWARF_FRAME_RETURN_COLUMN) |
1041 | reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset); | |
a3f97cbb | 1042 | } |
36bd4303 | 1043 | #endif |
a3f97cbb | 1044 | |
1ba5ae8f | 1045 | /* Given a SET, calculate the amount of stack adjustment it |
30f7a378 | 1046 | contains. */ |
1ba5ae8f | 1047 | |
799f628a | 1048 | static HOST_WIDE_INT |
9678086d | 1049 | stack_adjust_offset (const_rtx pattern) |
1ba5ae8f | 1050 | { |
9678086d KG |
1051 | const_rtx src = SET_SRC (pattern); |
1052 | const_rtx dest = SET_DEST (pattern); | |
2ad9852d | 1053 | HOST_WIDE_INT offset = 0; |
1ba5ae8f AH |
1054 | enum rtx_code code; |
1055 | ||
1056 | if (dest == stack_pointer_rtx) | |
1057 | { | |
1058 | /* (set (reg sp) (plus (reg sp) (const_int))) */ | |
1059 | code = GET_CODE (src); | |
1060 | if (! (code == PLUS || code == MINUS) | |
1061 | || XEXP (src, 0) != stack_pointer_rtx | |
1062 | || GET_CODE (XEXP (src, 1)) != CONST_INT) | |
1063 | return 0; | |
1064 | ||
1065 | offset = INTVAL (XEXP (src, 1)); | |
f472fa29 AM |
1066 | if (code == PLUS) |
1067 | offset = -offset; | |
1ba5ae8f | 1068 | } |
3c0cb5de | 1069 | else if (MEM_P (dest)) |
1ba5ae8f AH |
1070 | { |
1071 | /* (set (mem (pre_dec (reg sp))) (foo)) */ | |
1072 | src = XEXP (dest, 0); | |
1073 | code = GET_CODE (src); | |
1074 | ||
c26fbbca KH |
1075 | switch (code) |
1076 | { | |
f472fa29 AM |
1077 | case PRE_MODIFY: |
1078 | case POST_MODIFY: | |
1079 | if (XEXP (src, 0) == stack_pointer_rtx) | |
1080 | { | |
1081 | rtx val = XEXP (XEXP (src, 1), 1); | |
1082 | /* We handle only adjustments by constant amount. */ | |
ced3f397 NS |
1083 | gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS |
1084 | && GET_CODE (val) == CONST_INT); | |
f472fa29 AM |
1085 | offset = -INTVAL (val); |
1086 | break; | |
1087 | } | |
1088 | return 0; | |
1089 | ||
1090 | case PRE_DEC: | |
1091 | case POST_DEC: | |
1092 | if (XEXP (src, 0) == stack_pointer_rtx) | |
1093 | { | |
1094 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1095 | break; | |
1096 | } | |
1097 | return 0; | |
1098 | ||
1099 | case PRE_INC: | |
1100 | case POST_INC: | |
1101 | if (XEXP (src, 0) == stack_pointer_rtx) | |
1102 | { | |
1103 | offset = -GET_MODE_SIZE (GET_MODE (dest)); | |
1104 | break; | |
1105 | } | |
1106 | return 0; | |
2ad9852d | 1107 | |
f472fa29 AM |
1108 | default: |
1109 | return 0; | |
e2134eea | 1110 | } |
1ba5ae8f AH |
1111 | } |
1112 | else | |
1113 | return 0; | |
1114 | ||
1ba5ae8f AH |
1115 | return offset; |
1116 | } | |
1117 | ||
0021b564 JM |
1118 | /* Check INSN to see if it looks like a push or a stack adjustment, and |
1119 | make a note of it if it does. EH uses this information to find out how | |
1120 | much extra space it needs to pop off the stack. */ | |
1121 | ||
1122 | static void | |
b73aec4f | 1123 | dwarf2out_stack_adjust (rtx insn, bool after_p) |
0021b564 | 1124 | { |
2ad9852d | 1125 | HOST_WIDE_INT offset; |
d3e3972c | 1126 | const char *label; |
2ad9852d | 1127 | int i; |
0021b564 | 1128 | |
b298f00f RH |
1129 | /* Don't handle epilogues at all. Certainly it would be wrong to do so |
1130 | with this function. Proper support would require all frame-related | |
1131 | insns to be marked, and to be able to handle saving state around | |
1132 | epilogues textually in the middle of the function. */ | |
1133 | if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn)) | |
1134 | return; | |
1135 | ||
b73aec4f GK |
1136 | /* If only calls can throw, and we have a frame pointer, |
1137 | save up adjustments until we see the CALL_INSN. */ | |
1138 | if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM) | |
1139 | { | |
1140 | if (CALL_P (insn) && !after_p) | |
1141 | { | |
1142 | /* Extract the size of the args from the CALL rtx itself. */ | |
1143 | insn = PATTERN (insn); | |
1144 | if (GET_CODE (insn) == PARALLEL) | |
1145 | insn = XVECEXP (insn, 0, 0); | |
1146 | if (GET_CODE (insn) == SET) | |
1147 | insn = SET_SRC (insn); | |
1148 | gcc_assert (GET_CODE (insn) == CALL); | |
1149 | dwarf2out_args_size ("", INTVAL (XEXP (insn, 1))); | |
1150 | } | |
1151 | return; | |
1152 | } | |
1153 | ||
1154 | if (CALL_P (insn) && !after_p) | |
1155 | { | |
1156 | if (!flag_asynchronous_unwind_tables) | |
1157 | dwarf2out_args_size ("", args_size); | |
1158 | return; | |
1159 | } | |
1160 | else if (BARRIER_P (insn)) | |
0021b564 | 1161 | { |
6020d360 JM |
1162 | /* When we see a BARRIER, we know to reset args_size to 0. Usually |
1163 | the compiler will have already emitted a stack adjustment, but | |
1164 | doesn't bother for calls to noreturn functions. */ | |
1165 | #ifdef STACK_GROWS_DOWNWARD | |
1166 | offset = -args_size; | |
1167 | #else | |
1168 | offset = args_size; | |
1169 | #endif | |
0021b564 | 1170 | } |
6020d360 | 1171 | else if (GET_CODE (PATTERN (insn)) == SET) |
2ad9852d | 1172 | offset = stack_adjust_offset (PATTERN (insn)); |
1ba5ae8f AH |
1173 | else if (GET_CODE (PATTERN (insn)) == PARALLEL |
1174 | || GET_CODE (PATTERN (insn)) == SEQUENCE) | |
1175 | { | |
1176 | /* There may be stack adjustments inside compound insns. Search | |
2ad9852d RK |
1177 | for them. */ |
1178 | for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--) | |
1179 | if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET) | |
1180 | offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i)); | |
0021b564 JM |
1181 | } |
1182 | else | |
1183 | return; | |
0b34cf1e | 1184 | |
6020d360 JM |
1185 | if (offset == 0) |
1186 | return; | |
1187 | ||
7d9d8943 AM |
1188 | if (cfa.reg == STACK_POINTER_REGNUM) |
1189 | cfa.offset += offset; | |
0021b564 JM |
1190 | |
1191 | #ifndef STACK_GROWS_DOWNWARD | |
1192 | offset = -offset; | |
1193 | #endif | |
2ad9852d | 1194 | |
0021b564 JM |
1195 | args_size += offset; |
1196 | if (args_size < 0) | |
1197 | args_size = 0; | |
1198 | ||
1199 | label = dwarf2out_cfi_label (); | |
7d9d8943 | 1200 | def_cfa_1 (label, &cfa); |
e0c0490b RH |
1201 | if (flag_asynchronous_unwind_tables) |
1202 | dwarf2out_args_size (label, args_size); | |
0021b564 JM |
1203 | } |
1204 | ||
17211ab5 GK |
1205 | #endif |
1206 | ||
fbfa55b0 RH |
1207 | /* We delay emitting a register save until either (a) we reach the end |
1208 | of the prologue or (b) the register is clobbered. This clusters | |
1209 | register saves so that there are fewer pc advances. */ | |
1210 | ||
17211ab5 | 1211 | struct queued_reg_save GTY(()) |
fbfa55b0 RH |
1212 | { |
1213 | struct queued_reg_save *next; | |
1214 | rtx reg; | |
799f628a | 1215 | HOST_WIDE_INT cfa_offset; |
f8a57be8 | 1216 | rtx saved_reg; |
fbfa55b0 RH |
1217 | }; |
1218 | ||
17211ab5 GK |
1219 | static GTY(()) struct queued_reg_save *queued_reg_saves; |
1220 | ||
f8a57be8 GK |
1221 | /* The caller's ORIG_REG is saved in SAVED_IN_REG. */ |
1222 | struct reg_saved_in_data GTY(()) { | |
1223 | rtx orig_reg; | |
1224 | rtx saved_in_reg; | |
1225 | }; | |
1226 | ||
1227 | /* A list of registers saved in other registers. | |
1228 | The list intentionally has a small maximum capacity of 4; if your | |
1229 | port needs more than that, you might consider implementing a | |
1230 | more efficient data structure. */ | |
1231 | static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4]; | |
1232 | static GTY(()) size_t num_regs_saved_in_regs; | |
a1c496cb | 1233 | |
17211ab5 | 1234 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) |
fbfa55b0 RH |
1235 | static const char *last_reg_save_label; |
1236 | ||
f8a57be8 GK |
1237 | /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at |
1238 | SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */ | |
1239 | ||
fbfa55b0 | 1240 | static void |
f8a57be8 | 1241 | queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset) |
fbfa55b0 | 1242 | { |
f8a57be8 GK |
1243 | struct queued_reg_save *q; |
1244 | ||
1245 | /* Duplicates waste space, but it's also necessary to remove them | |
1246 | for correctness, since the queue gets output in reverse | |
1247 | order. */ | |
1248 | for (q = queued_reg_saves; q != NULL; q = q->next) | |
1249 | if (REGNO (q->reg) == REGNO (reg)) | |
1250 | break; | |
1251 | ||
1252 | if (q == NULL) | |
1253 | { | |
1b4572a8 | 1254 | q = GGC_NEW (struct queued_reg_save); |
f8a57be8 GK |
1255 | q->next = queued_reg_saves; |
1256 | queued_reg_saves = q; | |
1257 | } | |
fbfa55b0 | 1258 | |
fbfa55b0 RH |
1259 | q->reg = reg; |
1260 | q->cfa_offset = offset; | |
f8a57be8 | 1261 | q->saved_reg = sreg; |
fbfa55b0 RH |
1262 | |
1263 | last_reg_save_label = label; | |
1264 | } | |
1265 | ||
f8a57be8 GK |
1266 | /* Output all the entries in QUEUED_REG_SAVES. */ |
1267 | ||
fbfa55b0 | 1268 | static void |
7080f735 | 1269 | flush_queued_reg_saves (void) |
fbfa55b0 | 1270 | { |
f8a57be8 | 1271 | struct queued_reg_save *q; |
fbfa55b0 | 1272 | |
f8a57be8 | 1273 | for (q = queued_reg_saves; q; q = q->next) |
fbfa55b0 | 1274 | { |
f8a57be8 | 1275 | size_t i; |
1bac3811 RH |
1276 | unsigned int reg, sreg; |
1277 | ||
f8a57be8 GK |
1278 | for (i = 0; i < num_regs_saved_in_regs; i++) |
1279 | if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg)) | |
1280 | break; | |
1281 | if (q->saved_reg && i == num_regs_saved_in_regs) | |
1282 | { | |
ced3f397 | 1283 | gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs)); |
f8a57be8 GK |
1284 | num_regs_saved_in_regs++; |
1285 | } | |
1286 | if (i != num_regs_saved_in_regs) | |
1287 | { | |
1288 | regs_saved_in_regs[i].orig_reg = q->reg; | |
1289 | regs_saved_in_regs[i].saved_in_reg = q->saved_reg; | |
1290 | } | |
1291 | ||
1bac3811 RH |
1292 | reg = DWARF_FRAME_REGNUM (REGNO (q->reg)); |
1293 | if (q->saved_reg) | |
1294 | sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg)); | |
1295 | else | |
1296 | sreg = INVALID_REGNUM; | |
1297 | reg_save (last_reg_save_label, reg, sreg, q->cfa_offset); | |
fbfa55b0 RH |
1298 | } |
1299 | ||
1300 | queued_reg_saves = NULL; | |
1301 | last_reg_save_label = NULL; | |
1302 | } | |
1303 | ||
f8a57be8 GK |
1304 | /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved |
1305 | location for? Or, does it clobber a register which we've previously | |
1306 | said that some other register is saved in, and for which we now | |
1307 | have a new location for? */ | |
1308 | ||
fbfa55b0 | 1309 | static bool |
9678086d | 1310 | clobbers_queued_reg_save (const_rtx insn) |
fbfa55b0 RH |
1311 | { |
1312 | struct queued_reg_save *q; | |
1313 | ||
c26fbbca | 1314 | for (q = queued_reg_saves; q; q = q->next) |
f8a57be8 GK |
1315 | { |
1316 | size_t i; | |
1317 | if (modified_in_p (q->reg, insn)) | |
1318 | return true; | |
1319 | for (i = 0; i < num_regs_saved_in_regs; i++) | |
1320 | if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg) | |
1321 | && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn)) | |
1322 | return true; | |
1323 | } | |
fbfa55b0 RH |
1324 | |
1325 | return false; | |
1326 | } | |
c26fbbca | 1327 | |
150cdc9e RH |
1328 | /* Entry point for saving the first register into the second. */ |
1329 | ||
1330 | void | |
1331 | dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg) | |
1332 | { | |
1333 | size_t i; | |
1334 | unsigned int regno, sregno; | |
1335 | ||
1336 | for (i = 0; i < num_regs_saved_in_regs; i++) | |
1337 | if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg)) | |
1338 | break; | |
1339 | if (i == num_regs_saved_in_regs) | |
1340 | { | |
1341 | gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs)); | |
1342 | num_regs_saved_in_regs++; | |
1343 | } | |
1344 | regs_saved_in_regs[i].orig_reg = reg; | |
1345 | regs_saved_in_regs[i].saved_in_reg = sreg; | |
1346 | ||
1347 | regno = DWARF_FRAME_REGNUM (REGNO (reg)); | |
1348 | sregno = DWARF_FRAME_REGNUM (REGNO (sreg)); | |
1349 | reg_save (label, regno, sregno, 0); | |
1350 | } | |
1351 | ||
f8a57be8 GK |
1352 | /* What register, if any, is currently saved in REG? */ |
1353 | ||
1354 | static rtx | |
1355 | reg_saved_in (rtx reg) | |
1356 | { | |
1357 | unsigned int regn = REGNO (reg); | |
1358 | size_t i; | |
1359 | struct queued_reg_save *q; | |
a1c496cb | 1360 | |
f8a57be8 GK |
1361 | for (q = queued_reg_saves; q; q = q->next) |
1362 | if (q->saved_reg && regn == REGNO (q->saved_reg)) | |
1363 | return q->reg; | |
1364 | ||
1365 | for (i = 0; i < num_regs_saved_in_regs; i++) | |
1366 | if (regs_saved_in_regs[i].saved_in_reg | |
1367 | && regn == REGNO (regs_saved_in_regs[i].saved_in_reg)) | |
1368 | return regs_saved_in_regs[i].orig_reg; | |
1369 | ||
1370 | return NULL_RTX; | |
1371 | } | |
1372 | ||
fbfa55b0 | 1373 | |
770ca8c6 JO |
1374 | /* A temporary register holding an integral value used in adjusting SP |
1375 | or setting up the store_reg. The "offset" field holds the integer | |
1376 | value, not an offset. */ | |
fbfa55b0 | 1377 | static dw_cfa_location cfa_temp; |
770ca8c6 JO |
1378 | |
1379 | /* Record call frame debugging information for an expression EXPR, | |
1380 | which either sets SP or FP (adjusting how we calculate the frame | |
f8a57be8 GK |
1381 | address) or saves a register to the stack or another register. |
1382 | LABEL indicates the address of EXPR. | |
770ca8c6 JO |
1383 | |
1384 | This function encodes a state machine mapping rtxes to actions on | |
1385 | cfa, cfa_store, and cfa_temp.reg. We describe these rules so | |
1386 | users need not read the source code. | |
1387 | ||
a401107d JO |
1388 | The High-Level Picture |
1389 | ||
1390 | Changes in the register we use to calculate the CFA: Currently we | |
1391 | assume that if you copy the CFA register into another register, we | |
1392 | should take the other one as the new CFA register; this seems to | |
1393 | work pretty well. If it's wrong for some target, it's simple | |
1394 | enough not to set RTX_FRAME_RELATED_P on the insn in question. | |
1395 | ||
1396 | Changes in the register we use for saving registers to the stack: | |
1397 | This is usually SP, but not always. Again, we deduce that if you | |
1398 | copy SP into another register (and SP is not the CFA register), | |
1399 | then the new register is the one we will be using for register | |
1400 | saves. This also seems to work. | |
1401 | ||
1402 | Register saves: There's not much guesswork about this one; if | |
1403 | RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a | |
1404 | register save, and the register used to calculate the destination | |
1405 | had better be the one we think we're using for this purpose. | |
f8a57be8 GK |
1406 | It's also assumed that a copy from a call-saved register to another |
1407 | register is saving that register if RTX_FRAME_RELATED_P is set on | |
1408 | that instruction. If the copy is from a call-saved register to | |
1409 | the *same* register, that means that the register is now the same | |
1410 | value as in the caller. | |
a401107d JO |
1411 | |
1412 | Except: If the register being saved is the CFA register, and the | |
cc2902df | 1413 | offset is nonzero, we are saving the CFA, so we assume we have to |
a401107d JO |
1414 | use DW_CFA_def_cfa_expression. If the offset is 0, we assume that |
1415 | the intent is to save the value of SP from the previous frame. | |
1416 | ||
f8a57be8 | 1417 | In addition, if a register has previously been saved to a different |
a1c496cb | 1418 | register, |
f8a57be8 | 1419 | |
770ca8c6 JO |
1420 | Invariants / Summaries of Rules |
1421 | ||
a401107d JO |
1422 | cfa current rule for calculating the CFA. It usually |
1423 | consists of a register and an offset. | |
770ca8c6 JO |
1424 | cfa_store register used by prologue code to save things to the stack |
1425 | cfa_store.offset is the offset from the value of | |
1426 | cfa_store.reg to the actual CFA | |
1427 | cfa_temp register holding an integral value. cfa_temp.offset | |
1428 | stores the value, which will be used to adjust the | |
19ec6a36 AM |
1429 | stack pointer. cfa_temp is also used like cfa_store, |
1430 | to track stores to the stack via fp or a temp reg. | |
c26fbbca | 1431 | |
770ca8c6 | 1432 | Rules 1- 4: Setting a register's value to cfa.reg or an expression |
7080f735 | 1433 | with cfa.reg as the first operand changes the cfa.reg and its |
19ec6a36 AM |
1434 | cfa.offset. Rule 1 and 4 also set cfa_temp.reg and |
1435 | cfa_temp.offset. | |
770ca8c6 JO |
1436 | |
1437 | Rules 6- 9: Set a non-cfa.reg register value to a constant or an | |
1438 | expression yielding a constant. This sets cfa_temp.reg | |
1439 | and cfa_temp.offset. | |
1440 | ||
1441 | Rule 5: Create a new register cfa_store used to save items to the | |
1442 | stack. | |
1443 | ||
19ec6a36 | 1444 | Rules 10-14: Save a register to the stack. Define offset as the |
a401107d | 1445 | difference of the original location and cfa_store's |
19ec6a36 | 1446 | location (or cfa_temp's location if cfa_temp is used). |
770ca8c6 JO |
1447 | |
1448 | The Rules | |
1449 | ||
1450 | "{a,b}" indicates a choice of a xor b. | |
1451 | "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg. | |
1452 | ||
1453 | Rule 1: | |
1454 | (set <reg1> <reg2>:cfa.reg) | |
19ec6a36 | 1455 | effects: cfa.reg = <reg1> |
73c68f61 | 1456 | cfa.offset unchanged |
19ec6a36 AM |
1457 | cfa_temp.reg = <reg1> |
1458 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1459 | |
1460 | Rule 2: | |
2ad9852d RK |
1461 | (set sp ({minus,plus,losum} {sp,fp}:cfa.reg |
1462 | {<const_int>,<reg>:cfa_temp.reg})) | |
770ca8c6 | 1463 | effects: cfa.reg = sp if fp used |
7080f735 | 1464 | cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp |
770ca8c6 JO |
1465 | cfa_store.offset += {+/- <const_int>, cfa_temp.offset} |
1466 | if cfa_store.reg==sp | |
1467 | ||
1468 | Rule 3: | |
19ec6a36 | 1469 | (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>)) |
770ca8c6 | 1470 | effects: cfa.reg = fp |
7080f735 | 1471 | cfa_offset += +/- <const_int> |
770ca8c6 JO |
1472 | |
1473 | Rule 4: | |
19ec6a36 | 1474 | (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>)) |
770ca8c6 | 1475 | constraints: <reg1> != fp |
7080f735 | 1476 | <reg1> != sp |
770ca8c6 | 1477 | effects: cfa.reg = <reg1> |
19ec6a36 AM |
1478 | cfa_temp.reg = <reg1> |
1479 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1480 | |
1481 | Rule 5: | |
1482 | (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg)) | |
1483 | constraints: <reg1> != fp | |
7080f735 | 1484 | <reg1> != sp |
770ca8c6 | 1485 | effects: cfa_store.reg = <reg1> |
7080f735 | 1486 | cfa_store.offset = cfa.offset - cfa_temp.offset |
770ca8c6 JO |
1487 | |
1488 | Rule 6: | |
1489 | (set <reg> <const_int>) | |
1490 | effects: cfa_temp.reg = <reg> | |
7080f735 | 1491 | cfa_temp.offset = <const_int> |
770ca8c6 JO |
1492 | |
1493 | Rule 7: | |
1494 | (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>)) | |
1495 | effects: cfa_temp.reg = <reg1> | |
1496 | cfa_temp.offset |= <const_int> | |
1497 | ||
1498 | Rule 8: | |
1499 | (set <reg> (high <exp>)) | |
1500 | effects: none | |
1501 | ||
1502 | Rule 9: | |
1503 | (set <reg> (lo_sum <exp> <const_int>)) | |
1504 | effects: cfa_temp.reg = <reg> | |
7080f735 | 1505 | cfa_temp.offset = <const_int> |
770ca8c6 JO |
1506 | |
1507 | Rule 10: | |
1508 | (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>) | |
1509 | effects: cfa_store.offset -= <const_int> | |
1510 | cfa.offset = cfa_store.offset if cfa.reg == sp | |
770ca8c6 | 1511 | cfa.reg = sp |
19ec6a36 | 1512 | cfa.base_offset = -cfa_store.offset |
770ca8c6 JO |
1513 | |
1514 | Rule 11: | |
1515 | (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>) | |
1516 | effects: cfa_store.offset += -/+ mode_size(mem) | |
1517 | cfa.offset = cfa_store.offset if cfa.reg == sp | |
770ca8c6 | 1518 | cfa.reg = sp |
19ec6a36 | 1519 | cfa.base_offset = -cfa_store.offset |
770ca8c6 JO |
1520 | |
1521 | Rule 12: | |
2ad9852d RK |
1522 | (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) |
1523 | ||
1524 | <reg2>) | |
19ec6a36 AM |
1525 | effects: cfa.reg = <reg1> |
1526 | cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset | |
770ca8c6 JO |
1527 | |
1528 | Rule 13: | |
19ec6a36 AM |
1529 | (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>) |
1530 | effects: cfa.reg = <reg1> | |
1531 | cfa.base_offset = -{cfa_store,cfa_temp}.offset | |
1532 | ||
1533 | Rule 14: | |
1534 | (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>) | |
1535 | effects: cfa.reg = <reg1> | |
1536 | cfa.base_offset = -cfa_temp.offset | |
e54c7471 EB |
1537 | cfa_temp.offset -= mode_size(mem) |
1538 | ||
10b01bca GK |
1539 | Rule 15: |
1540 | (set <reg> {unspec, unspec_volatile}) | |
1541 | effects: target-dependent */ | |
b664de3a AM |
1542 | |
1543 | static void | |
7080f735 | 1544 | dwarf2out_frame_debug_expr (rtx expr, const char *label) |
b664de3a | 1545 | { |
48081aae | 1546 | rtx src, dest, span; |
2ad9852d | 1547 | HOST_WIDE_INT offset; |
556273e0 KH |
1548 | |
1549 | /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of | |
1550 | the PARALLEL independently. The first element is always processed if | |
770ca8c6 | 1551 | it is a SET. This is for backward compatibility. Other elements |
556273e0 KH |
1552 | are processed only if they are SETs and the RTX_FRAME_RELATED_P |
1553 | flag is set in them. */ | |
2ad9852d | 1554 | if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE) |
556273e0 | 1555 | { |
b664de3a AM |
1556 | int par_index; |
1557 | int limit = XVECLEN (expr, 0); | |
55d6f631 RS |
1558 | rtx elem; |
1559 | ||
1560 | /* PARALLELs have strict read-modify-write semantics, so we | |
1561 | ought to evaluate every rvalue before changing any lvalue. | |
1562 | It's cumbersome to do that in general, but there's an | |
1563 | easy approximation that is enough for all current users: | |
1564 | handle register saves before register assignments. */ | |
1565 | if (GET_CODE (expr) == PARALLEL) | |
1566 | for (par_index = 0; par_index < limit; par_index++) | |
1567 | { | |
1568 | elem = XVECEXP (expr, 0, par_index); | |
1569 | if (GET_CODE (elem) == SET | |
1570 | && MEM_P (SET_DEST (elem)) | |
1571 | && (RTX_FRAME_RELATED_P (elem) || par_index == 0)) | |
1572 | dwarf2out_frame_debug_expr (elem, label); | |
1573 | } | |
b664de3a AM |
1574 | |
1575 | for (par_index = 0; par_index < limit; par_index++) | |
55d6f631 RS |
1576 | { |
1577 | elem = XVECEXP (expr, 0, par_index); | |
1578 | if (GET_CODE (elem) == SET | |
1579 | && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE) | |
1580 | && (RTX_FRAME_RELATED_P (elem) || par_index == 0)) | |
1581 | dwarf2out_frame_debug_expr (elem, label); | |
a182fb6b JJ |
1582 | else if (GET_CODE (elem) == SET |
1583 | && par_index != 0 | |
1584 | && !RTX_FRAME_RELATED_P (elem)) | |
1585 | { | |
1586 | /* Stack adjustment combining might combine some post-prologue | |
1587 | stack adjustment into a prologue stack adjustment. */ | |
1588 | HOST_WIDE_INT offset = stack_adjust_offset (elem); | |
1589 | ||
1590 | if (offset != 0) | |
1591 | { | |
1592 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1593 | cfa.offset += offset; | |
1594 | ||
1595 | #ifndef STACK_GROWS_DOWNWARD | |
1596 | offset = -offset; | |
1597 | #endif | |
1598 | ||
1599 | args_size += offset; | |
1600 | if (args_size < 0) | |
1601 | args_size = 0; | |
1602 | ||
1603 | def_cfa_1 (label, &cfa); | |
1604 | if (flag_asynchronous_unwind_tables) | |
1605 | dwarf2out_args_size (label, args_size); | |
1606 | } | |
1607 | } | |
55d6f631 | 1608 | } |
b664de3a AM |
1609 | return; |
1610 | } | |
556273e0 | 1611 | |
ced3f397 | 1612 | gcc_assert (GET_CODE (expr) == SET); |
b664de3a AM |
1613 | |
1614 | src = SET_SRC (expr); | |
1615 | dest = SET_DEST (expr); | |
1616 | ||
2ca202e7 | 1617 | if (REG_P (src)) |
f8a57be8 GK |
1618 | { |
1619 | rtx rsi = reg_saved_in (src); | |
1620 | if (rsi) | |
1621 | src = rsi; | |
1622 | } | |
1623 | ||
b664de3a AM |
1624 | switch (GET_CODE (dest)) |
1625 | { | |
1626 | case REG: | |
b664de3a | 1627 | switch (GET_CODE (src)) |
556273e0 KH |
1628 | { |
1629 | /* Setting FP from SP. */ | |
1630 | case REG: | |
1631 | if (cfa.reg == (unsigned) REGNO (src)) | |
f8a57be8 GK |
1632 | { |
1633 | /* Rule 1 */ | |
1634 | /* Update the CFA rule wrt SP or FP. Make sure src is | |
a1c496cb | 1635 | relative to the current CFA register. |
f8a57be8 GK |
1636 | |
1637 | We used to require that dest be either SP or FP, but the | |
1638 | ARM copies SP to a temporary register, and from there to | |
1639 | FP. So we just rely on the backends to only set | |
1640 | RTX_FRAME_RELATED_P on appropriate insns. */ | |
1641 | cfa.reg = REGNO (dest); | |
1642 | cfa_temp.reg = cfa.reg; | |
1643 | cfa_temp.offset = cfa.offset; | |
1644 | } | |
ced3f397 | 1645 | else |
f8a57be8 GK |
1646 | { |
1647 | /* Saving a register in a register. */ | |
2c42e193 AM |
1648 | gcc_assert (!fixed_regs [REGNO (dest)] |
1649 | /* For the SPARC and its register window. */ | |
1650 | || (DWARF_FRAME_REGNUM (REGNO (src)) | |
1651 | == DWARF_FRAME_RETURN_COLUMN)); | |
f8a57be8 GK |
1652 | queue_reg_save (label, src, dest, 0); |
1653 | } | |
556273e0 | 1654 | break; |
b664de3a | 1655 | |
556273e0 KH |
1656 | case PLUS: |
1657 | case MINUS: | |
19ec6a36 | 1658 | case LO_SUM: |
556273e0 KH |
1659 | if (dest == stack_pointer_rtx) |
1660 | { | |
770ca8c6 | 1661 | /* Rule 2 */ |
2618f955 MM |
1662 | /* Adjusting SP. */ |
1663 | switch (GET_CODE (XEXP (src, 1))) | |
1664 | { | |
1665 | case CONST_INT: | |
1666 | offset = INTVAL (XEXP (src, 1)); | |
1667 | break; | |
1668 | case REG: | |
ced3f397 NS |
1669 | gcc_assert ((unsigned) REGNO (XEXP (src, 1)) |
1670 | == cfa_temp.reg); | |
770ca8c6 | 1671 | offset = cfa_temp.offset; |
2618f955 MM |
1672 | break; |
1673 | default: | |
ced3f397 | 1674 | gcc_unreachable (); |
2618f955 MM |
1675 | } |
1676 | ||
1677 | if (XEXP (src, 0) == hard_frame_pointer_rtx) | |
1678 | { | |
1679 | /* Restoring SP from FP in the epilogue. */ | |
ced3f397 | 1680 | gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM); |
7d9d8943 | 1681 | cfa.reg = STACK_POINTER_REGNUM; |
2618f955 | 1682 | } |
19ec6a36 AM |
1683 | else if (GET_CODE (src) == LO_SUM) |
1684 | /* Assume we've set the source reg of the LO_SUM from sp. */ | |
1685 | ; | |
ced3f397 NS |
1686 | else |
1687 | gcc_assert (XEXP (src, 0) == stack_pointer_rtx); | |
2618f955 | 1688 | |
19ec6a36 | 1689 | if (GET_CODE (src) != MINUS) |
2618f955 | 1690 | offset = -offset; |
7d9d8943 AM |
1691 | if (cfa.reg == STACK_POINTER_REGNUM) |
1692 | cfa.offset += offset; | |
1693 | if (cfa_store.reg == STACK_POINTER_REGNUM) | |
1694 | cfa_store.offset += offset; | |
556273e0 KH |
1695 | } |
1696 | else if (dest == hard_frame_pointer_rtx) | |
1697 | { | |
770ca8c6 | 1698 | /* Rule 3 */ |
2618f955 MM |
1699 | /* Either setting the FP from an offset of the SP, |
1700 | or adjusting the FP */ | |
ced3f397 | 1701 | gcc_assert (frame_pointer_needed); |
2618f955 | 1702 | |
ced3f397 NS |
1703 | gcc_assert (REG_P (XEXP (src, 0)) |
1704 | && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg | |
1705 | && GET_CODE (XEXP (src, 1)) == CONST_INT); | |
1706 | offset = INTVAL (XEXP (src, 1)); | |
1707 | if (GET_CODE (src) != MINUS) | |
1708 | offset = -offset; | |
1709 | cfa.offset += offset; | |
1710 | cfa.reg = HARD_FRAME_POINTER_REGNUM; | |
556273e0 KH |
1711 | } |
1712 | else | |
1713 | { | |
ced3f397 | 1714 | gcc_assert (GET_CODE (src) != MINUS); |
b53ef1a2 | 1715 | |
770ca8c6 | 1716 | /* Rule 4 */ |
f8cfc6aa | 1717 | if (REG_P (XEXP (src, 0)) |
b53ef1a2 NC |
1718 | && REGNO (XEXP (src, 0)) == cfa.reg |
1719 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
34ce3d7b JM |
1720 | { |
1721 | /* Setting a temporary CFA register that will be copied | |
1722 | into the FP later on. */ | |
19ec6a36 | 1723 | offset = - INTVAL (XEXP (src, 1)); |
34ce3d7b JM |
1724 | cfa.offset += offset; |
1725 | cfa.reg = REGNO (dest); | |
19ec6a36 AM |
1726 | /* Or used to save regs to the stack. */ |
1727 | cfa_temp.reg = cfa.reg; | |
1728 | cfa_temp.offset = cfa.offset; | |
34ce3d7b | 1729 | } |
2ad9852d | 1730 | |
770ca8c6 | 1731 | /* Rule 5 */ |
f8cfc6aa | 1732 | else if (REG_P (XEXP (src, 0)) |
19ec6a36 AM |
1733 | && REGNO (XEXP (src, 0)) == cfa_temp.reg |
1734 | && XEXP (src, 1) == stack_pointer_rtx) | |
b53ef1a2 | 1735 | { |
00a42e21 JM |
1736 | /* Setting a scratch register that we will use instead |
1737 | of SP for saving registers to the stack. */ | |
ced3f397 | 1738 | gcc_assert (cfa.reg == STACK_POINTER_REGNUM); |
b53ef1a2 | 1739 | cfa_store.reg = REGNO (dest); |
770ca8c6 | 1740 | cfa_store.offset = cfa.offset - cfa_temp.offset; |
b53ef1a2 | 1741 | } |
2ad9852d | 1742 | |
19ec6a36 AM |
1743 | /* Rule 9 */ |
1744 | else if (GET_CODE (src) == LO_SUM | |
1745 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
1746 | { | |
1747 | cfa_temp.reg = REGNO (dest); | |
1748 | cfa_temp.offset = INTVAL (XEXP (src, 1)); | |
1749 | } | |
1750 | else | |
ced3f397 | 1751 | gcc_unreachable (); |
556273e0 KH |
1752 | } |
1753 | break; | |
b664de3a | 1754 | |
770ca8c6 | 1755 | /* Rule 6 */ |
556273e0 | 1756 | case CONST_INT: |
770ca8c6 JO |
1757 | cfa_temp.reg = REGNO (dest); |
1758 | cfa_temp.offset = INTVAL (src); | |
556273e0 | 1759 | break; |
b664de3a | 1760 | |
770ca8c6 | 1761 | /* Rule 7 */ |
556273e0 | 1762 | case IOR: |
ced3f397 NS |
1763 | gcc_assert (REG_P (XEXP (src, 0)) |
1764 | && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg | |
1765 | && GET_CODE (XEXP (src, 1)) == CONST_INT); | |
2ad9852d | 1766 | |
770ca8c6 JO |
1767 | if ((unsigned) REGNO (dest) != cfa_temp.reg) |
1768 | cfa_temp.reg = REGNO (dest); | |
1769 | cfa_temp.offset |= INTVAL (XEXP (src, 1)); | |
556273e0 | 1770 | break; |
b664de3a | 1771 | |
9ae21d2a AM |
1772 | /* Skip over HIGH, assuming it will be followed by a LO_SUM, |
1773 | which will fill in all of the bits. */ | |
1774 | /* Rule 8 */ | |
1775 | case HIGH: | |
1776 | break; | |
1777 | ||
e54c7471 EB |
1778 | /* Rule 15 */ |
1779 | case UNSPEC: | |
1780 | case UNSPEC_VOLATILE: | |
1781 | gcc_assert (targetm.dwarf_handle_frame_unspec); | |
1782 | targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1)); | |
150cdc9e | 1783 | return; |
e54c7471 | 1784 | |
556273e0 | 1785 | default: |
ced3f397 | 1786 | gcc_unreachable (); |
556273e0 | 1787 | } |
2ad9852d | 1788 | |
7d9d8943 | 1789 | def_cfa_1 (label, &cfa); |
2618f955 | 1790 | break; |
b664de3a | 1791 | |
2618f955 | 1792 | case MEM: |
ced3f397 | 1793 | gcc_assert (REG_P (src)); |
7d9d8943 | 1794 | |
7d9d8943 AM |
1795 | /* Saving a register to the stack. Make sure dest is relative to the |
1796 | CFA register. */ | |
2618f955 MM |
1797 | switch (GET_CODE (XEXP (dest, 0))) |
1798 | { | |
770ca8c6 | 1799 | /* Rule 10 */ |
2618f955 | 1800 | /* With a push. */ |
e2134eea JH |
1801 | case PRE_MODIFY: |
1802 | /* We can't handle variable size modifications. */ | |
ced3f397 NS |
1803 | gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) |
1804 | == CONST_INT); | |
e2134eea JH |
1805 | offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1)); |
1806 | ||
ced3f397 NS |
1807 | gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM |
1808 | && cfa_store.reg == STACK_POINTER_REGNUM); | |
2ad9852d | 1809 | |
e2134eea JH |
1810 | cfa_store.offset += offset; |
1811 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1812 | cfa.offset = cfa_store.offset; | |
1813 | ||
1814 | offset = -cfa_store.offset; | |
1815 | break; | |
2ad9852d | 1816 | |
770ca8c6 | 1817 | /* Rule 11 */ |
2618f955 MM |
1818 | case PRE_INC: |
1819 | case PRE_DEC: | |
1820 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1821 | if (GET_CODE (XEXP (dest, 0)) == PRE_INC) | |
1822 | offset = -offset; | |
b664de3a | 1823 | |
ced3f397 NS |
1824 | gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM |
1825 | && cfa_store.reg == STACK_POINTER_REGNUM); | |
2ad9852d | 1826 | |
7d9d8943 AM |
1827 | cfa_store.offset += offset; |
1828 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1829 | cfa.offset = cfa_store.offset; | |
b664de3a | 1830 | |
7d9d8943 | 1831 | offset = -cfa_store.offset; |
2618f955 | 1832 | break; |
b664de3a | 1833 | |
770ca8c6 | 1834 | /* Rule 12 */ |
2618f955 MM |
1835 | /* With an offset. */ |
1836 | case PLUS: | |
1837 | case MINUS: | |
19ec6a36 | 1838 | case LO_SUM: |
ced3f397 NS |
1839 | { |
1840 | int regno; | |
a1c496cb | 1841 | |
66a5ab40 AM |
1842 | gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT |
1843 | && REG_P (XEXP (XEXP (dest, 0), 0))); | |
ced3f397 NS |
1844 | offset = INTVAL (XEXP (XEXP (dest, 0), 1)); |
1845 | if (GET_CODE (XEXP (dest, 0)) == MINUS) | |
1846 | offset = -offset; | |
1847 | ||
1848 | regno = REGNO (XEXP (XEXP (dest, 0), 0)); | |
a1c496cb | 1849 | |
ced3f397 NS |
1850 | if (cfa_store.reg == (unsigned) regno) |
1851 | offset -= cfa_store.offset; | |
1852 | else | |
1853 | { | |
1854 | gcc_assert (cfa_temp.reg == (unsigned) regno); | |
1855 | offset -= cfa_temp.offset; | |
1856 | } | |
1857 | } | |
2618f955 MM |
1858 | break; |
1859 | ||
770ca8c6 | 1860 | /* Rule 13 */ |
2618f955 MM |
1861 | /* Without an offset. */ |
1862 | case REG: | |
ced3f397 NS |
1863 | { |
1864 | int regno = REGNO (XEXP (dest, 0)); | |
a1c496cb | 1865 | |
ced3f397 NS |
1866 | if (cfa_store.reg == (unsigned) regno) |
1867 | offset = -cfa_store.offset; | |
1868 | else | |
1869 | { | |
1870 | gcc_assert (cfa_temp.reg == (unsigned) regno); | |
1871 | offset = -cfa_temp.offset; | |
1872 | } | |
1873 | } | |
19ec6a36 AM |
1874 | break; |
1875 | ||
1876 | /* Rule 14 */ | |
1877 | case POST_INC: | |
ced3f397 NS |
1878 | gcc_assert (cfa_temp.reg |
1879 | == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))); | |
19ec6a36 AM |
1880 | offset = -cfa_temp.offset; |
1881 | cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest)); | |
2618f955 MM |
1882 | break; |
1883 | ||
1884 | default: | |
ced3f397 | 1885 | gcc_unreachable (); |
2618f955 | 1886 | } |
e09bbb25 | 1887 | |
556273e0 | 1888 | if (REGNO (src) != STACK_POINTER_REGNUM |
e09bbb25 JM |
1889 | && REGNO (src) != HARD_FRAME_POINTER_REGNUM |
1890 | && (unsigned) REGNO (src) == cfa.reg) | |
1891 | { | |
1892 | /* We're storing the current CFA reg into the stack. */ | |
1893 | ||
1894 | if (cfa.offset == 0) | |
1895 | { | |
1896 | /* If the source register is exactly the CFA, assume | |
1897 | we're saving SP like any other register; this happens | |
1898 | on the ARM. */ | |
e09bbb25 | 1899 | def_cfa_1 (label, &cfa); |
f8a57be8 | 1900 | queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset); |
e09bbb25 JM |
1901 | break; |
1902 | } | |
1903 | else | |
1904 | { | |
1905 | /* Otherwise, we'll need to look in the stack to | |
73c68f61 | 1906 | calculate the CFA. */ |
e09bbb25 | 1907 | rtx x = XEXP (dest, 0); |
2ad9852d | 1908 | |
f8cfc6aa | 1909 | if (!REG_P (x)) |
e09bbb25 | 1910 | x = XEXP (x, 0); |
ced3f397 | 1911 | gcc_assert (REG_P (x)); |
2ad9852d RK |
1912 | |
1913 | cfa.reg = REGNO (x); | |
e09bbb25 JM |
1914 | cfa.base_offset = offset; |
1915 | cfa.indirect = 1; | |
1916 | def_cfa_1 (label, &cfa); | |
1917 | break; | |
1918 | } | |
1919 | } | |
1920 | ||
7d9d8943 | 1921 | def_cfa_1 (label, &cfa); |
48081aae NF |
1922 | { |
1923 | span = targetm.dwarf_register_span (src); | |
1924 | ||
1925 | if (!span) | |
1926 | queue_reg_save (label, src, NULL_RTX, offset); | |
1927 | else | |
1928 | { | |
1929 | /* We have a PARALLEL describing where the contents of SRC | |
1930 | live. Queue register saves for each piece of the | |
1931 | PARALLEL. */ | |
1932 | int par_index; | |
1933 | int limit; | |
1934 | HOST_WIDE_INT span_offset = offset; | |
1935 | ||
1936 | gcc_assert (GET_CODE (span) == PARALLEL); | |
1937 | ||
1938 | limit = XVECLEN (span, 0); | |
1939 | for (par_index = 0; par_index < limit; par_index++) | |
1940 | { | |
1941 | rtx elem = XVECEXP (span, 0, par_index); | |
1942 | ||
1943 | queue_reg_save (label, elem, NULL_RTX, span_offset); | |
1944 | span_offset += GET_MODE_SIZE (GET_MODE (elem)); | |
1945 | } | |
1946 | } | |
1947 | } | |
2618f955 MM |
1948 | break; |
1949 | ||
1950 | default: | |
ced3f397 | 1951 | gcc_unreachable (); |
2618f955 | 1952 | } |
b664de3a AM |
1953 | } |
1954 | ||
3f76745e JM |
1955 | /* Record call frame debugging information for INSN, which either |
1956 | sets SP or FP (adjusting how we calculate the frame address) or saves a | |
e0c0490b RH |
1957 | register to the stack. If INSN is NULL_RTX, initialize our state. |
1958 | ||
1959 | If AFTER_P is false, we're being called before the insn is emitted, | |
1960 | otherwise after. Call instructions get invoked twice. */ | |
71dfc51f | 1961 | |
3f76745e | 1962 | void |
e0c0490b | 1963 | dwarf2out_frame_debug (rtx insn, bool after_p) |
a3f97cbb | 1964 | { |
d3e3972c | 1965 | const char *label; |
b664de3a | 1966 | rtx src; |
3f76745e JM |
1967 | |
1968 | if (insn == NULL_RTX) | |
a3f97cbb | 1969 | { |
f8a57be8 | 1970 | size_t i; |
a1c496cb | 1971 | |
fbfa55b0 RH |
1972 | /* Flush any queued register saves. */ |
1973 | flush_queued_reg_saves (); | |
1974 | ||
3f76745e | 1975 | /* Set up state for generating call frame debug info. */ |
7d9d8943 | 1976 | lookup_cfa (&cfa); |
ced3f397 NS |
1977 | gcc_assert (cfa.reg |
1978 | == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)); | |
2ad9852d | 1979 | |
7d9d8943 AM |
1980 | cfa.reg = STACK_POINTER_REGNUM; |
1981 | cfa_store = cfa; | |
770ca8c6 JO |
1982 | cfa_temp.reg = -1; |
1983 | cfa_temp.offset = 0; | |
a1c496cb | 1984 | |
f8a57be8 GK |
1985 | for (i = 0; i < num_regs_saved_in_regs; i++) |
1986 | { | |
1987 | regs_saved_in_regs[i].orig_reg = NULL_RTX; | |
1988 | regs_saved_in_regs[i].saved_in_reg = NULL_RTX; | |
1989 | } | |
1990 | num_regs_saved_in_regs = 0; | |
3f76745e JM |
1991 | return; |
1992 | } | |
1993 | ||
4b4bf941 | 1994 | if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn)) |
fbfa55b0 RH |
1995 | flush_queued_reg_saves (); |
1996 | ||
0021b564 JM |
1997 | if (! RTX_FRAME_RELATED_P (insn)) |
1998 | { | |
fbfa55b0 | 1999 | if (!ACCUMULATE_OUTGOING_ARGS) |
e0c0490b | 2000 | dwarf2out_stack_adjust (insn, after_p); |
0021b564 JM |
2001 | return; |
2002 | } | |
2003 | ||
3f76745e | 2004 | label = dwarf2out_cfi_label (); |
07ebc930 RH |
2005 | src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX); |
2006 | if (src) | |
2007 | insn = XEXP (src, 0); | |
556273e0 | 2008 | else |
07ebc930 RH |
2009 | insn = PATTERN (insn); |
2010 | ||
b664de3a | 2011 | dwarf2out_frame_debug_expr (insn, label); |
3f76745e JM |
2012 | } |
2013 | ||
17211ab5 GK |
2014 | #endif |
2015 | ||
2016 | /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */ | |
7080f735 AJ |
2017 | static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc |
2018 | (enum dwarf_call_frame_info cfi); | |
17211ab5 GK |
2019 | |
2020 | static enum dw_cfi_oprnd_type | |
7080f735 | 2021 | dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi) |
17211ab5 GK |
2022 | { |
2023 | switch (cfi) | |
2024 | { | |
2025 | case DW_CFA_nop: | |
2026 | case DW_CFA_GNU_window_save: | |
2027 | return dw_cfi_oprnd_unused; | |
2028 | ||
2029 | case DW_CFA_set_loc: | |
2030 | case DW_CFA_advance_loc1: | |
2031 | case DW_CFA_advance_loc2: | |
2032 | case DW_CFA_advance_loc4: | |
2033 | case DW_CFA_MIPS_advance_loc8: | |
2034 | return dw_cfi_oprnd_addr; | |
2035 | ||
2036 | case DW_CFA_offset: | |
2037 | case DW_CFA_offset_extended: | |
2038 | case DW_CFA_def_cfa: | |
2039 | case DW_CFA_offset_extended_sf: | |
2040 | case DW_CFA_def_cfa_sf: | |
2041 | case DW_CFA_restore_extended: | |
2042 | case DW_CFA_undefined: | |
2043 | case DW_CFA_same_value: | |
2044 | case DW_CFA_def_cfa_register: | |
2045 | case DW_CFA_register: | |
2046 | return dw_cfi_oprnd_reg_num; | |
2047 | ||
2048 | case DW_CFA_def_cfa_offset: | |
2049 | case DW_CFA_GNU_args_size: | |
2050 | case DW_CFA_def_cfa_offset_sf: | |
2051 | return dw_cfi_oprnd_offset; | |
7080f735 | 2052 | |
17211ab5 GK |
2053 | case DW_CFA_def_cfa_expression: |
2054 | case DW_CFA_expression: | |
2055 | return dw_cfi_oprnd_loc; | |
2056 | ||
2057 | default: | |
ced3f397 | 2058 | gcc_unreachable (); |
17211ab5 GK |
2059 | } |
2060 | } | |
2061 | ||
2062 | /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */ | |
7080f735 AJ |
2063 | static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc |
2064 | (enum dwarf_call_frame_info cfi); | |
17211ab5 GK |
2065 | |
2066 | static enum dw_cfi_oprnd_type | |
7080f735 | 2067 | dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi) |
17211ab5 GK |
2068 | { |
2069 | switch (cfi) | |
2070 | { | |
2071 | case DW_CFA_def_cfa: | |
2072 | case DW_CFA_def_cfa_sf: | |
2073 | case DW_CFA_offset: | |
2074 | case DW_CFA_offset_extended_sf: | |
2075 | case DW_CFA_offset_extended: | |
2076 | return dw_cfi_oprnd_offset; | |
2077 | ||
2078 | case DW_CFA_register: | |
2079 | return dw_cfi_oprnd_reg_num; | |
2080 | ||
2081 | default: | |
2082 | return dw_cfi_oprnd_unused; | |
2083 | } | |
2084 | } | |
2085 | ||
2086 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) | |
2087 | ||
d6b5193b RS |
2088 | /* Switch to eh_frame_section. If we don't have an eh_frame_section, |
2089 | switch to the data section instead, and write out a synthetic label | |
2090 | for collect2. */ | |
2091 | ||
2092 | static void | |
2093 | switch_to_eh_frame_section (void) | |
2094 | { | |
2095 | tree label; | |
2096 | ||
0f67af1c RS |
2097 | #ifdef EH_FRAME_SECTION_NAME |
2098 | if (eh_frame_section == 0) | |
2099 | { | |
2100 | int flags; | |
2101 | ||
2102 | if (EH_TABLES_CAN_BE_READ_ONLY) | |
2103 | { | |
2104 | int fde_encoding; | |
2105 | int per_encoding; | |
2106 | int lsda_encoding; | |
2107 | ||
2108 | fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, | |
2109 | /*global=*/0); | |
2110 | per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, | |
2111 | /*global=*/1); | |
2112 | lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, | |
2113 | /*global=*/0); | |
2114 | flags = ((! flag_pic | |
2115 | || ((fde_encoding & 0x70) != DW_EH_PE_absptr | |
2116 | && (fde_encoding & 0x70) != DW_EH_PE_aligned | |
2117 | && (per_encoding & 0x70) != DW_EH_PE_absptr | |
2118 | && (per_encoding & 0x70) != DW_EH_PE_aligned | |
2119 | && (lsda_encoding & 0x70) != DW_EH_PE_absptr | |
2120 | && (lsda_encoding & 0x70) != DW_EH_PE_aligned)) | |
2121 | ? 0 : SECTION_WRITE); | |
2122 | } | |
2123 | else | |
2124 | flags = SECTION_WRITE; | |
2125 | eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL); | |
2126 | } | |
2127 | #endif | |
2128 | ||
d6b5193b RS |
2129 | if (eh_frame_section) |
2130 | switch_to_section (eh_frame_section); | |
2131 | else | |
2132 | { | |
0f67af1c RS |
2133 | /* We have no special eh_frame section. Put the information in |
2134 | the data section and emit special labels to guide collect2. */ | |
d6b5193b | 2135 | switch_to_section (data_section); |
5880f14f | 2136 | label = get_file_function_name ("F"); |
d6b5193b RS |
2137 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); |
2138 | targetm.asm_out.globalize_label (asm_out_file, | |
2139 | IDENTIFIER_POINTER (label)); | |
2140 | ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); | |
2141 | } | |
2142 | } | |
2143 | ||
3f76745e JM |
2144 | /* Output a Call Frame Information opcode and its operand(s). */ |
2145 | ||
2146 | static void | |
7080f735 | 2147 | output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh) |
3f76745e | 2148 | { |
34c80057 | 2149 | unsigned long r; |
3f76745e | 2150 | if (cfi->dw_cfi_opc == DW_CFA_advance_loc) |
2ad9852d RK |
2151 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
2152 | | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)), | |
38f9cd4c | 2153 | "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX, |
3d57d7ce DK |
2154 | ((unsigned HOST_WIDE_INT) |
2155 | cfi->dw_cfi_oprnd1.dw_cfi_offset)); | |
3f76745e JM |
2156 | else if (cfi->dw_cfi_opc == DW_CFA_offset) |
2157 | { | |
34c80057 AM |
2158 | r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh); |
2159 | dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)), | |
2160 | "DW_CFA_offset, column 0x%lx", r); | |
2e4b9b8c | 2161 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); |
3f76745e JM |
2162 | } |
2163 | else if (cfi->dw_cfi_opc == DW_CFA_restore) | |
34c80057 AM |
2164 | { |
2165 | r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh); | |
2166 | dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)), | |
2167 | "DW_CFA_restore, column 0x%lx", r); | |
2168 | } | |
3f76745e JM |
2169 | else |
2170 | { | |
2e4b9b8c RH |
2171 | dw2_asm_output_data (1, cfi->dw_cfi_opc, |
2172 | "%s", dwarf_cfi_name (cfi->dw_cfi_opc)); | |
3f76745e | 2173 | |
3f76745e JM |
2174 | switch (cfi->dw_cfi_opc) |
2175 | { | |
2176 | case DW_CFA_set_loc: | |
e1f9550a RH |
2177 | if (for_eh) |
2178 | dw2_asm_output_encoded_addr_rtx ( | |
2179 | ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0), | |
2180 | gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr), | |
b03e9863 | 2181 | false, NULL); |
e1f9550a RH |
2182 | else |
2183 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, | |
2184 | cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL); | |
6a10f7b3 | 2185 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
3f76745e | 2186 | break; |
2ad9852d | 2187 | |
3f76745e | 2188 | case DW_CFA_advance_loc1: |
2e4b9b8c RH |
2189 | dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
2190 | fde->dw_fde_current_label, NULL); | |
bb727b5a | 2191 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
3f76745e | 2192 | break; |
2ad9852d | 2193 | |
3f76745e | 2194 | case DW_CFA_advance_loc2: |
2e4b9b8c RH |
2195 | dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
2196 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
2197 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
2198 | break; | |
2ad9852d | 2199 | |
3f76745e | 2200 | case DW_CFA_advance_loc4: |
2e4b9b8c RH |
2201 | dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
2202 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
2203 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
2204 | break; | |
2ad9852d | 2205 | |
3f76745e | 2206 | case DW_CFA_MIPS_advance_loc8: |
2e4b9b8c RH |
2207 | dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
2208 | fde->dw_fde_current_label, NULL); | |
2209 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
3f76745e | 2210 | break; |
2ad9852d | 2211 | |
3f76745e JM |
2212 | case DW_CFA_offset_extended: |
2213 | case DW_CFA_def_cfa: | |
34c80057 AM |
2214 | r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh); |
2215 | dw2_asm_output_data_uleb128 (r, NULL); | |
2e4b9b8c | 2216 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); |
3f76745e | 2217 | break; |
2ad9852d | 2218 | |
6bb28965 JM |
2219 | case DW_CFA_offset_extended_sf: |
2220 | case DW_CFA_def_cfa_sf: | |
34c80057 AM |
2221 | r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh); |
2222 | dw2_asm_output_data_uleb128 (r, NULL); | |
6bb28965 JM |
2223 | dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); |
2224 | break; | |
2225 | ||
3f76745e JM |
2226 | case DW_CFA_restore_extended: |
2227 | case DW_CFA_undefined: | |
3f76745e JM |
2228 | case DW_CFA_same_value: |
2229 | case DW_CFA_def_cfa_register: | |
34c80057 AM |
2230 | r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh); |
2231 | dw2_asm_output_data_uleb128 (r, NULL); | |
3f76745e | 2232 | break; |
2ad9852d | 2233 | |
3f76745e | 2234 | case DW_CFA_register: |
34c80057 AM |
2235 | r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh); |
2236 | dw2_asm_output_data_uleb128 (r, NULL); | |
2237 | r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh); | |
2238 | dw2_asm_output_data_uleb128 (r, NULL); | |
3f76745e | 2239 | break; |
2ad9852d | 2240 | |
3f76745e | 2241 | case DW_CFA_def_cfa_offset: |
2e4b9b8c RH |
2242 | case DW_CFA_GNU_args_size: |
2243 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL); | |
3f76745e | 2244 | break; |
2ad9852d | 2245 | |
6bb28965 JM |
2246 | case DW_CFA_def_cfa_offset_sf: |
2247 | dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL); | |
2248 | break; | |
2249 | ||
c53aa195 JM |
2250 | case DW_CFA_GNU_window_save: |
2251 | break; | |
2ad9852d | 2252 | |
7d9d8943 | 2253 | case DW_CFA_def_cfa_expression: |
6bb28965 | 2254 | case DW_CFA_expression: |
7d9d8943 AM |
2255 | output_cfa_loc (cfi); |
2256 | break; | |
2ad9852d | 2257 | |
6bb28965 JM |
2258 | case DW_CFA_GNU_negative_offset_extended: |
2259 | /* Obsoleted by DW_CFA_offset_extended_sf. */ | |
ced3f397 | 2260 | gcc_unreachable (); |
6bb28965 | 2261 | |
3f76745e JM |
2262 | default: |
2263 | break; | |
2264 | } | |
556273e0 | 2265 | } |
3f76745e JM |
2266 | } |
2267 | ||
34c80057 | 2268 | /* Output the call frame information used to record information |
3f76745e JM |
2269 | that relates to calculating the frame pointer, and records the |
2270 | location of saved registers. */ | |
2271 | ||
2272 | static void | |
7080f735 | 2273 | output_call_frame_info (int for_eh) |
3f76745e | 2274 | { |
b3694847 SS |
2275 | unsigned int i; |
2276 | dw_fde_ref fde; | |
2277 | dw_cfi_ref cfi; | |
27d95cbe | 2278 | char l1[20], l2[20], section_start_label[20]; |
ad5eeaa9 | 2279 | bool any_lsda_needed = false; |
52a11cbf | 2280 | char augmentation[6]; |
e1f9550a RH |
2281 | int augmentation_size; |
2282 | int fde_encoding = DW_EH_PE_absptr; | |
2283 | int per_encoding = DW_EH_PE_absptr; | |
2284 | int lsda_encoding = DW_EH_PE_absptr; | |
32df413a | 2285 | int return_reg; |
3f76745e | 2286 | |
29b91443 JM |
2287 | /* Don't emit a CIE if there won't be any FDEs. */ |
2288 | if (fde_table_in_use == 0) | |
2289 | return; | |
2290 | ||
4746cf84 MA |
2291 | /* If we make FDEs linkonce, we may have to emit an empty label for |
2292 | an FDE that wouldn't otherwise be emitted. We want to avoid | |
2293 | having an FDE kept around when the function it refers to is | |
f1a66265 | 2294 | discarded. Example where this matters: a primary function |
4746cf84 | 2295 | template in C++ requires EH information, but an explicit |
9cf737f8 | 2296 | specialization doesn't. */ |
4746cf84 MA |
2297 | if (TARGET_USES_WEAK_UNWIND_INFO |
2298 | && ! flag_asynchronous_unwind_tables | |
c3b07ec2 | 2299 | && flag_exceptions |
4746cf84 MA |
2300 | && for_eh) |
2301 | for (i = 0; i < fde_table_in_use; i++) | |
2302 | if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls) | |
2878ea73 | 2303 | && !fde_table[i].uses_eh_lsda |
f1a66265 | 2304 | && ! DECL_WEAK (fde_table[i].decl)) |
5fd9b178 | 2305 | targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl, |
eeab4d81 | 2306 | for_eh, /* empty */ 1); |
4746cf84 | 2307 | |
ad5eeaa9 RH |
2308 | /* If we don't have any functions we'll want to unwind out of, don't |
2309 | emit any EH unwind information. Note that if exceptions aren't | |
2310 | enabled, we won't have collected nothrow information, and if we | |
2311 | asked for asynchronous tables, we always want this info. */ | |
737faf14 JM |
2312 | if (for_eh) |
2313 | { | |
ad5eeaa9 | 2314 | bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables; |
2ad9852d RK |
2315 | |
2316 | for (i = 0; i < fde_table_in_use; i++) | |
52a11cbf | 2317 | if (fde_table[i].uses_eh_lsda) |
ad5eeaa9 | 2318 | any_eh_needed = any_lsda_needed = true; |
2878ea73 | 2319 | else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl)) |
aeb732c1 | 2320 | any_eh_needed = true; |
0366359a GK |
2321 | else if (! fde_table[i].nothrow |
2322 | && ! fde_table[i].all_throwers_are_sibcalls) | |
ad5eeaa9 | 2323 | any_eh_needed = true; |
52a11cbf RH |
2324 | |
2325 | if (! any_eh_needed) | |
2326 | return; | |
737faf14 JM |
2327 | } |
2328 | ||
aa0c1401 JL |
2329 | /* We're going to be generating comments, so turn on app. */ |
2330 | if (flag_debug_asm) | |
2331 | app_enable (); | |
956d6950 | 2332 | |
3f76745e | 2333 | if (for_eh) |
d6b5193b | 2334 | switch_to_eh_frame_section (); |
3f76745e | 2335 | else |
10934c3b RS |
2336 | { |
2337 | if (!debug_frame_section) | |
2338 | debug_frame_section = get_section (DEBUG_FRAME_SECTION, | |
2339 | SECTION_DEBUG, NULL); | |
2340 | switch_to_section (debug_frame_section); | |
2341 | } | |
3f76745e | 2342 | |
27d95cbe RH |
2343 | ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh); |
2344 | ASM_OUTPUT_LABEL (asm_out_file, section_start_label); | |
2345 | ||
556273e0 | 2346 | /* Output the CIE. */ |
a6ab3aad JM |
2347 | ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh); |
2348 | ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh); | |
0c33762a JM |
2349 | if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh) |
2350 | dw2_asm_output_data (4, 0xffffffff, | |
2351 | "Initial length escape value indicating 64-bit DWARF extension"); | |
2e4b9b8c RH |
2352 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
2353 | "Length of Common Information Entry"); | |
a6ab3aad JM |
2354 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
2355 | ||
2e4b9b8c RH |
2356 | /* Now that the CIE pointer is PC-relative for EH, |
2357 | use 0 to identify the CIE. */ | |
2358 | dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE), | |
0c33762a | 2359 | (for_eh ? 0 : DWARF_CIE_ID), |
2e4b9b8c | 2360 | "CIE Identifier Tag"); |
3f76745e | 2361 | |
2e4b9b8c | 2362 | dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version"); |
3f76745e | 2363 | |
52a11cbf | 2364 | augmentation[0] = 0; |
e1f9550a | 2365 | augmentation_size = 0; |
52a11cbf | 2366 | if (for_eh) |
a6ab3aad | 2367 | { |
e1f9550a RH |
2368 | char *p; |
2369 | ||
52a11cbf RH |
2370 | /* Augmentation: |
2371 | z Indicates that a uleb128 is present to size the | |
7080f735 | 2372 | augmentation section. |
e1f9550a RH |
2373 | L Indicates the encoding (and thus presence) of |
2374 | an LSDA pointer in the FDE augmentation. | |
2375 | R Indicates a non-default pointer encoding for | |
2376 | FDE code pointers. | |
2377 | P Indicates the presence of an encoding + language | |
2378 | personality routine in the CIE augmentation. */ | |
2379 | ||
aeb732c1 | 2380 | fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0); |
e1f9550a RH |
2381 | per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1); |
2382 | lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0); | |
2383 | ||
2384 | p = augmentation + 1; | |
2385 | if (eh_personality_libfunc) | |
2386 | { | |
2387 | *p++ = 'P'; | |
2388 | augmentation_size += 1 + size_of_encoded_value (per_encoding); | |
2a6acff7 | 2389 | assemble_external_libcall (eh_personality_libfunc); |
e1f9550a | 2390 | } |
52a11cbf | 2391 | if (any_lsda_needed) |
e1f9550a RH |
2392 | { |
2393 | *p++ = 'L'; | |
2394 | augmentation_size += 1; | |
2395 | } | |
2396 | if (fde_encoding != DW_EH_PE_absptr) | |
2397 | { | |
2398 | *p++ = 'R'; | |
2399 | augmentation_size += 1; | |
2400 | } | |
2401 | if (p > augmentation + 1) | |
2402 | { | |
2403 | augmentation[0] = 'z'; | |
c26fbbca | 2404 | *p = '\0'; |
e1f9550a | 2405 | } |
099c8b17 RH |
2406 | |
2407 | /* Ug. Some platforms can't do unaligned dynamic relocations at all. */ | |
2408 | if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned) | |
2409 | { | |
2410 | int offset = ( 4 /* Length */ | |
2411 | + 4 /* CIE Id */ | |
2412 | + 1 /* CIE version */ | |
2413 | + strlen (augmentation) + 1 /* Augmentation */ | |
2414 | + size_of_uleb128 (1) /* Code alignment */ | |
2415 | + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT) | |
2416 | + 1 /* RA column */ | |
2417 | + 1 /* Augmentation size */ | |
2418 | + 1 /* Personality encoding */ ); | |
2419 | int pad = -offset & (PTR_SIZE - 1); | |
2420 | ||
2421 | augmentation_size += pad; | |
2422 | ||
2423 | /* Augmentations should be small, so there's scarce need to | |
2424 | iterate for a solution. Die if we exceed one uleb128 byte. */ | |
ced3f397 | 2425 | gcc_assert (size_of_uleb128 (augmentation_size) == 1); |
099c8b17 | 2426 | } |
a6ab3aad | 2427 | } |
3f76745e | 2428 | |
2ad9852d | 2429 | dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation"); |
2e4b9b8c | 2430 | dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor"); |
2e4b9b8c RH |
2431 | dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT, |
2432 | "CIE Data Alignment Factor"); | |
fc9c8ce1 | 2433 | |
32df413a | 2434 | return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh); |
fc9c8ce1 | 2435 | if (DW_CIE_VERSION == 1) |
32df413a | 2436 | dw2_asm_output_data (1, return_reg, "CIE RA Column"); |
fc9c8ce1 | 2437 | else |
32df413a | 2438 | dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column"); |
3f76745e | 2439 | |
52a11cbf RH |
2440 | if (augmentation[0]) |
2441 | { | |
e1f9550a | 2442 | dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size"); |
52a11cbf | 2443 | if (eh_personality_libfunc) |
e1f9550a RH |
2444 | { |
2445 | dw2_asm_output_data (1, per_encoding, "Personality (%s)", | |
2446 | eh_data_format_name (per_encoding)); | |
2447 | dw2_asm_output_encoded_addr_rtx (per_encoding, | |
b03e9863 EB |
2448 | eh_personality_libfunc, |
2449 | true, NULL); | |
e1f9550a | 2450 | } |
2ad9852d | 2451 | |
e1f9550a RH |
2452 | if (any_lsda_needed) |
2453 | dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)", | |
2454 | eh_data_format_name (lsda_encoding)); | |
2ad9852d | 2455 | |
e1f9550a RH |
2456 | if (fde_encoding != DW_EH_PE_absptr) |
2457 | dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)", | |
2458 | eh_data_format_name (fde_encoding)); | |
52a11cbf RH |
2459 | } |
2460 | ||
3f76745e | 2461 | for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next) |
12f0b96b | 2462 | output_cfi (cfi, NULL, for_eh); |
3f76745e JM |
2463 | |
2464 | /* Pad the CIE out to an address sized boundary. */ | |
c26fbbca | 2465 | ASM_OUTPUT_ALIGN (asm_out_file, |
12f0b96b | 2466 | floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)); |
a6ab3aad | 2467 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e JM |
2468 | |
2469 | /* Loop through all of the FDE's. */ | |
2ad9852d | 2470 | for (i = 0; i < fde_table_in_use; i++) |
3f76745e JM |
2471 | { |
2472 | fde = &fde_table[i]; | |
3f76745e | 2473 | |
52a11cbf | 2474 | /* Don't emit EH unwind info for leaf functions that don't need it. */ |
ad5eeaa9 | 2475 | if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions |
b6128b8c | 2476 | && (fde->nothrow || fde->all_throwers_are_sibcalls) |
f1a66265 | 2477 | && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl)) |
b6128b8c | 2478 | && !fde->uses_eh_lsda) |
737faf14 JM |
2479 | continue; |
2480 | ||
eeab4d81 | 2481 | targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0); |
5fd9b178 | 2482 | targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2); |
556273e0 KH |
2483 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2); |
2484 | ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2); | |
0c33762a JM |
2485 | if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh) |
2486 | dw2_asm_output_data (4, 0xffffffff, | |
2487 | "Initial length escape value indicating 64-bit DWARF extension"); | |
2e4b9b8c RH |
2488 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
2489 | "FDE Length"); | |
a6ab3aad JM |
2490 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
2491 | ||
3f76745e | 2492 | if (for_eh) |
27d95cbe | 2493 | dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset"); |
3f76745e | 2494 | else |
27d95cbe | 2495 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label, |
192d0f89 | 2496 | debug_frame_section, "FDE CIE offset"); |
3f76745e | 2497 | |
e1f9550a RH |
2498 | if (for_eh) |
2499 | { | |
87c8b4be CT |
2500 | if (fde->dw_fde_switched_sections) |
2501 | { | |
2878ea73 | 2502 | rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode, |
87c8b4be | 2503 | fde->dw_fde_unlikely_section_label); |
2878ea73 | 2504 | rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode, |
87c8b4be CT |
2505 | fde->dw_fde_hot_section_label); |
2506 | SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL; | |
2507 | SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL; | |
b03e9863 | 2508 | dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3, false, |
87c8b4be CT |
2509 | "FDE initial location"); |
2510 | dw2_asm_output_delta (size_of_encoded_value (fde_encoding), | |
2511 | fde->dw_fde_hot_section_end_label, | |
2512 | fde->dw_fde_hot_section_label, | |
2513 | "FDE address range"); | |
b03e9863 | 2514 | dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2, false, |
87c8b4be CT |
2515 | "FDE initial location"); |
2516 | dw2_asm_output_delta (size_of_encoded_value (fde_encoding), | |
2517 | fde->dw_fde_unlikely_section_end_label, | |
2518 | fde->dw_fde_unlikely_section_label, | |
2519 | "FDE address range"); | |
2520 | } | |
2521 | else | |
2e2c7ce2 UB |
2522 | { |
2523 | rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin); | |
2524 | SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL; | |
2525 | dw2_asm_output_encoded_addr_rtx (fde_encoding, | |
2526 | sym_ref, | |
2527 | false, | |
2528 | "FDE initial location"); | |
2529 | dw2_asm_output_delta (size_of_encoded_value (fde_encoding), | |
2530 | fde->dw_fde_end, fde->dw_fde_begin, | |
2531 | "FDE address range"); | |
2532 | } | |
e1f9550a RH |
2533 | } |
2534 | else | |
2535 | { | |
87c8b4be CT |
2536 | if (fde->dw_fde_switched_sections) |
2537 | { | |
2538 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, | |
2539 | fde->dw_fde_hot_section_label, | |
2540 | "FDE initial location"); | |
2541 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, | |
2542 | fde->dw_fde_hot_section_end_label, | |
2543 | fde->dw_fde_hot_section_label, | |
2544 | "FDE address range"); | |
2545 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, | |
2546 | fde->dw_fde_unlikely_section_label, | |
2547 | "FDE initial location"); | |
2878ea73 | 2548 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, |
87c8b4be CT |
2549 | fde->dw_fde_unlikely_section_end_label, |
2550 | fde->dw_fde_unlikely_section_label, | |
2551 | "FDE address range"); | |
2552 | } | |
2553 | else | |
2e2c7ce2 UB |
2554 | { |
2555 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin, | |
2556 | "FDE initial location"); | |
2557 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, | |
2558 | fde->dw_fde_end, fde->dw_fde_begin, | |
2559 | "FDE address range"); | |
2560 | } | |
e1f9550a | 2561 | } |
3f76745e | 2562 | |
52a11cbf RH |
2563 | if (augmentation[0]) |
2564 | { | |
e1f9550a | 2565 | if (any_lsda_needed) |
52a11cbf | 2566 | { |
099c8b17 RH |
2567 | int size = size_of_encoded_value (lsda_encoding); |
2568 | ||
2569 | if (lsda_encoding == DW_EH_PE_aligned) | |
2570 | { | |
2571 | int offset = ( 4 /* Length */ | |
2572 | + 4 /* CIE offset */ | |
2573 | + 2 * size_of_encoded_value (fde_encoding) | |
2574 | + 1 /* Augmentation size */ ); | |
2575 | int pad = -offset & (PTR_SIZE - 1); | |
2576 | ||
2577 | size += pad; | |
ced3f397 | 2578 | gcc_assert (size_of_uleb128 (size) == 1); |
099c8b17 RH |
2579 | } |
2580 | ||
2581 | dw2_asm_output_data_uleb128 (size, "Augmentation size"); | |
e1f9550a RH |
2582 | |
2583 | if (fde->uses_eh_lsda) | |
73c68f61 SS |
2584 | { |
2585 | ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA", | |
e1f9550a | 2586 | fde->funcdef_number); |
73c68f61 | 2587 | dw2_asm_output_encoded_addr_rtx ( |
e1f9550a | 2588 | lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1), |
b03e9863 | 2589 | false, "Language Specific Data Area"); |
73c68f61 | 2590 | } |
e1f9550a | 2591 | else |
099c8b17 RH |
2592 | { |
2593 | if (lsda_encoding == DW_EH_PE_aligned) | |
2594 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); | |
2ad9852d RK |
2595 | dw2_asm_output_data |
2596 | (size_of_encoded_value (lsda_encoding), 0, | |
2597 | "Language Specific Data Area (none)"); | |
099c8b17 | 2598 | } |
52a11cbf RH |
2599 | } |
2600 | else | |
e1f9550a | 2601 | dw2_asm_output_data_uleb128 (0, "Augmentation size"); |
52a11cbf RH |
2602 | } |
2603 | ||
3f76745e JM |
2604 | /* Loop through the Call Frame Instructions associated with |
2605 | this FDE. */ | |
2606 | fde->dw_fde_current_label = fde->dw_fde_begin; | |
2607 | for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next) | |
12f0b96b | 2608 | output_cfi (cfi, fde, for_eh); |
3f76745e | 2609 | |
a6ab3aad | 2610 | /* Pad the FDE out to an address sized boundary. */ |
c26fbbca | 2611 | ASM_OUTPUT_ALIGN (asm_out_file, |
73c68f61 | 2612 | floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE))); |
a6ab3aad | 2613 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e | 2614 | } |
2e4b9b8c | 2615 | |
7606e68f | 2616 | if (for_eh && targetm.terminate_dw2_eh_frame_info) |
2e4b9b8c | 2617 | dw2_asm_output_data (4, 0, "End of Table"); |
a6ab3aad JM |
2618 | #ifdef MIPS_DEBUGGING_INFO |
2619 | /* Work around Irix 6 assembler bug whereby labels at the end of a section | |
2620 | get a value of 0. Putting .align 0 after the label fixes it. */ | |
2621 | ASM_OUTPUT_ALIGN (asm_out_file, 0); | |
2622 | #endif | |
aa0c1401 JL |
2623 | |
2624 | /* Turn off app to make assembly quicker. */ | |
2625 | if (flag_debug_asm) | |
2626 | app_disable (); | |
a6ab3aad JM |
2627 | } |
2628 | ||
3f76745e JM |
2629 | /* Output a marker (i.e. a label) for the beginning of a function, before |
2630 | the prologue. */ | |
2631 | ||
2632 | void | |
7080f735 AJ |
2633 | dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED, |
2634 | const char *file ATTRIBUTE_UNUSED) | |
3f76745e JM |
2635 | { |
2636 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
375d2edc | 2637 | char * dup_label; |
b3694847 | 2638 | dw_fde_ref fde; |
3f76745e | 2639 | |
375d2edc | 2640 | current_function_func_begin_label = NULL; |
2a1ee410 | 2641 | |
951120ea | 2642 | #ifdef TARGET_UNWIND_INFO |
2a1ee410 RH |
2643 | /* ??? current_function_func_begin_label is also used by except.c |
2644 | for call-site information. We must emit this label if it might | |
2645 | be used. */ | |
2646 | if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS) | |
2647 | && ! dwarf2out_do_frame ()) | |
2648 | return; | |
2649 | #else | |
2650 | if (! dwarf2out_do_frame ()) | |
2651 | return; | |
2652 | #endif | |
2653 | ||
d6b5193b | 2654 | switch_to_section (function_section (current_function_decl)); |
3f76745e | 2655 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL, |
df696a75 | 2656 | current_function_funcdef_no); |
2a1ee410 | 2657 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL, |
df696a75 | 2658 | current_function_funcdef_no); |
375d2edc GK |
2659 | dup_label = xstrdup (label); |
2660 | current_function_func_begin_label = dup_label; | |
3f76745e | 2661 | |
951120ea | 2662 | #ifdef TARGET_UNWIND_INFO |
2a1ee410 RH |
2663 | /* We can elide the fde allocation if we're not emitting debug info. */ |
2664 | if (! dwarf2out_do_frame ()) | |
2665 | return; | |
2666 | #endif | |
2667 | ||
3f76745e JM |
2668 | /* Expand the fde table if necessary. */ |
2669 | if (fde_table_in_use == fde_table_allocated) | |
2670 | { | |
2671 | fde_table_allocated += FDE_TABLE_INCREMENT; | |
1b4572a8 | 2672 | fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated); |
17211ab5 GK |
2673 | memset (fde_table + fde_table_in_use, 0, |
2674 | FDE_TABLE_INCREMENT * sizeof (dw_fde_node)); | |
a3f97cbb | 2675 | } |
3f76745e JM |
2676 | |
2677 | /* Record the FDE associated with this function. */ | |
2678 | current_funcdef_fde = fde_table_in_use; | |
2679 | ||
2680 | /* Add the new FDE at the end of the fde_table. */ | |
2681 | fde = &fde_table[fde_table_in_use++]; | |
4746cf84 | 2682 | fde->decl = current_function_decl; |
375d2edc | 2683 | fde->dw_fde_begin = dup_label; |
72478f32 | 2684 | fde->dw_fde_current_label = dup_label; |
87c8b4be CT |
2685 | fde->dw_fde_hot_section_label = NULL; |
2686 | fde->dw_fde_hot_section_end_label = NULL; | |
2687 | fde->dw_fde_unlikely_section_label = NULL; | |
2688 | fde->dw_fde_unlikely_section_end_label = NULL; | |
2689 | fde->dw_fde_switched_sections = false; | |
3f76745e JM |
2690 | fde->dw_fde_end = NULL; |
2691 | fde->dw_fde_cfi = NULL; | |
df696a75 | 2692 | fde->funcdef_number = current_function_funcdef_no; |
97b0ade3 | 2693 | fde->nothrow = TREE_NOTHROW (current_function_decl); |
e3b5732b JH |
2694 | fde->uses_eh_lsda = crtl->uses_eh_lsda; |
2695 | fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls; | |
737faf14 | 2696 | |
b57d9225 | 2697 | args_size = old_args_size = 0; |
653e276c | 2698 | |
2ad9852d RK |
2699 | /* We only want to output line number information for the genuine dwarf2 |
2700 | prologue case, not the eh frame case. */ | |
653e276c NB |
2701 | #ifdef DWARF2_DEBUGGING_INFO |
2702 | if (file) | |
2703 | dwarf2out_source_line (line, file); | |
2704 | #endif | |
3f76745e JM |
2705 | } |
2706 | ||
2707 | /* Output a marker (i.e. a label) for the absolute end of the generated code | |
2708 | for a function definition. This gets called *after* the epilogue code has | |
2709 | been generated. */ | |
2710 | ||
2711 | void | |
7080f735 AJ |
2712 | dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED, |
2713 | const char *file ATTRIBUTE_UNUSED) | |
3f76745e JM |
2714 | { |
2715 | dw_fde_ref fde; | |
2716 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2717 | ||
2718 | /* Output a label to mark the endpoint of the code generated for this | |
3ef42a0c | 2719 | function. */ |
df696a75 RH |
2720 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, |
2721 | current_function_funcdef_no); | |
3f76745e | 2722 | ASM_OUTPUT_LABEL (asm_out_file, label); |
3ce6e42e XG |
2723 | fde = current_fde (); |
2724 | gcc_assert (fde != NULL); | |
3f76745e | 2725 | fde->dw_fde_end = xstrdup (label); |
3f76745e JM |
2726 | } |
2727 | ||
2728 | void | |
7080f735 | 2729 | dwarf2out_frame_init (void) |
3f76745e JM |
2730 | { |
2731 | /* Allocate the initial hunk of the fde_table. */ | |
1b4572a8 | 2732 | fde_table = GGC_CNEWVEC (dw_fde_node, FDE_TABLE_INCREMENT); |
3f76745e JM |
2733 | fde_table_allocated = FDE_TABLE_INCREMENT; |
2734 | fde_table_in_use = 0; | |
2735 | ||
2736 | /* Generate the CFA instructions common to all FDE's. Do it now for the | |
2737 | sake of lookup_cfa. */ | |
2738 | ||
91193900 AS |
2739 | /* On entry, the Canonical Frame Address is at SP. */ |
2740 | dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET); | |
658f32fd AO |
2741 | |
2742 | #ifdef DWARF2_UNWIND_INFO | |
1d8604ec | 2743 | if (DWARF2_UNWIND_INFO || DWARF2_FRAME_INFO) |
658f32fd | 2744 | initial_return_save (INCOMING_RETURN_ADDR_RTX); |
3f76745e JM |
2745 | #endif |
2746 | } | |
2747 | ||
2748 | void | |
7080f735 | 2749 | dwarf2out_frame_finish (void) |
3f76745e | 2750 | { |
3f76745e | 2751 | /* Output call frame information. */ |
658f32fd | 2752 | if (DWARF2_FRAME_INFO) |
3f76745e | 2753 | output_call_frame_info (0); |
2ad9852d | 2754 | |
5cf58f28 PB |
2755 | #ifndef TARGET_UNWIND_INFO |
2756 | /* Output another copy for the unwinder. */ | |
ddee9e8d | 2757 | if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions)) |
3f76745e | 2758 | output_call_frame_info (1); |
5cf58f28 | 2759 | #endif |
556273e0 | 2760 | } |
74ab34d3 UB |
2761 | |
2762 | /* Note that the current function section is being used for code. */ | |
2763 | ||
2764 | static void | |
2765 | dwarf2out_note_section_used (void) | |
2766 | { | |
2767 | section *sec = current_function_section (); | |
2768 | if (sec == text_section) | |
2769 | text_section_used = true; | |
2770 | else if (sec == cold_text_section) | |
2771 | cold_text_section_used = true; | |
2772 | } | |
2773 | ||
2774 | void | |
2775 | dwarf2out_switch_text_section (void) | |
2776 | { | |
3ce6e42e | 2777 | dw_fde_ref fde = current_fde (); |
74ab34d3 | 2778 | |
3ce6e42e | 2779 | gcc_assert (cfun && fde); |
74ab34d3 | 2780 | |
74ab34d3 | 2781 | fde->dw_fde_switched_sections = true; |
38173d38 JH |
2782 | fde->dw_fde_hot_section_label = crtl->subsections.hot_section_label; |
2783 | fde->dw_fde_hot_section_end_label = crtl->subsections.hot_section_end_label; | |
2784 | fde->dw_fde_unlikely_section_label = crtl->subsections.cold_section_label; | |
2785 | fde->dw_fde_unlikely_section_end_label = crtl->subsections.cold_section_end_label; | |
74ab34d3 UB |
2786 | have_multiple_function_sections = true; |
2787 | ||
2788 | /* Reset the current label on switching text sections, so that we | |
2789 | don't attempt to advance_loc4 between labels in different sections. */ | |
2790 | fde->dw_fde_current_label = NULL; | |
2791 | ||
d0b9dbd5 UB |
2792 | /* There is no need to mark used sections when not debugging. */ |
2793 | if (cold_text_section != NULL) | |
2794 | dwarf2out_note_section_used (); | |
74ab34d3 | 2795 | } |
17211ab5 | 2796 | #endif |
7d9d8943 AM |
2797 | \f |
2798 | /* And now, the subset of the debugging information support code necessary | |
2799 | for emitting location expressions. */ | |
3f76745e | 2800 | |
d5688810 GK |
2801 | /* Data about a single source file. */ |
2802 | struct dwarf_file_data GTY(()) | |
2803 | { | |
2804 | const char * filename; | |
2805 | int emitted_number; | |
2806 | }; | |
2807 | ||
b9203463 RH |
2808 | /* We need some way to distinguish DW_OP_addr with a direct symbol |
2809 | relocation from DW_OP_addr with a dtp-relative symbol relocation. */ | |
2810 | #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr) | |
2811 | ||
2812 | ||
7d9d8943 AM |
2813 | typedef struct dw_val_struct *dw_val_ref; |
2814 | typedef struct die_struct *dw_die_ref; | |
5f754896 | 2815 | typedef const struct die_struct *const_dw_die_ref; |
7d9d8943 | 2816 | typedef struct dw_loc_descr_struct *dw_loc_descr_ref; |
63e46568 | 2817 | typedef struct dw_loc_list_struct *dw_loc_list_ref; |
3f76745e JM |
2818 | |
2819 | /* Each DIE may have a series of attribute/value pairs. Values | |
2820 | can take on several forms. The forms that are used in this | |
2821 | implementation are listed below. */ | |
2822 | ||
17211ab5 | 2823 | enum dw_val_class |
3f76745e JM |
2824 | { |
2825 | dw_val_class_addr, | |
a20612aa | 2826 | dw_val_class_offset, |
3f76745e | 2827 | dw_val_class_loc, |
63e46568 | 2828 | dw_val_class_loc_list, |
2bee6045 | 2829 | dw_val_class_range_list, |
3f76745e JM |
2830 | dw_val_class_const, |
2831 | dw_val_class_unsigned_const, | |
2832 | dw_val_class_long_long, | |
e7ee3914 | 2833 | dw_val_class_vec, |
3f76745e JM |
2834 | dw_val_class_flag, |
2835 | dw_val_class_die_ref, | |
2836 | dw_val_class_fde_ref, | |
2837 | dw_val_class_lbl_id, | |
192d0f89 GK |
2838 | dw_val_class_lineptr, |
2839 | dw_val_class_str, | |
d5688810 GK |
2840 | dw_val_class_macptr, |
2841 | dw_val_class_file | |
17211ab5 | 2842 | }; |
a3f97cbb | 2843 | |
3f76745e | 2844 | /* Describe a double word constant value. */ |
21217bd0 | 2845 | /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */ |
3f76745e | 2846 | |
17211ab5 | 2847 | typedef struct dw_long_long_struct GTY(()) |
a3f97cbb | 2848 | { |
3f76745e JM |
2849 | unsigned long hi; |
2850 | unsigned long low; | |
2851 | } | |
2852 | dw_long_long_const; | |
2853 | ||
e7ee3914 | 2854 | /* Describe a floating point constant value, or a vector constant value. */ |
3f76745e | 2855 | |
e7ee3914 | 2856 | typedef struct dw_vec_struct GTY(()) |
3f76745e | 2857 | { |
e7ee3914 | 2858 | unsigned char * GTY((length ("%h.length"))) array; |
3f76745e | 2859 | unsigned length; |
e7ee3914 | 2860 | unsigned elt_size; |
3f76745e | 2861 | } |
e7ee3914 | 2862 | dw_vec_const; |
3f76745e | 2863 | |
956d6950 | 2864 | /* The dw_val_node describes an attribute's value, as it is |
3f76745e JM |
2865 | represented internally. */ |
2866 | ||
17211ab5 | 2867 | typedef struct dw_val_struct GTY(()) |
3f76745e | 2868 | { |
17211ab5 GK |
2869 | enum dw_val_class val_class; |
2870 | union dw_val_struct_union | |
a3f97cbb | 2871 | { |
17211ab5 | 2872 | rtx GTY ((tag ("dw_val_class_addr"))) val_addr; |
799f628a | 2873 | unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset; |
17211ab5 GK |
2874 | dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list; |
2875 | dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc; | |
1431042e | 2876 | HOST_WIDE_INT GTY ((default)) val_int; |
799f628a | 2877 | unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned; |
17211ab5 | 2878 | dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long; |
e7ee3914 | 2879 | dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec; |
17211ab5 | 2880 | struct dw_val_die_union |
2ad9852d RK |
2881 | { |
2882 | dw_die_ref die; | |
2883 | int external; | |
17211ab5 GK |
2884 | } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref; |
2885 | unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index; | |
2886 | struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str; | |
2887 | char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id; | |
2888 | unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag; | |
d5688810 | 2889 | struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file; |
a3f97cbb | 2890 | } |
17211ab5 | 2891 | GTY ((desc ("%1.val_class"))) v; |
3f76745e JM |
2892 | } |
2893 | dw_val_node; | |
2894 | ||
2895 | /* Locations in memory are described using a sequence of stack machine | |
2896 | operations. */ | |
2897 | ||
17211ab5 | 2898 | typedef struct dw_loc_descr_struct GTY(()) |
3f76745e JM |
2899 | { |
2900 | dw_loc_descr_ref dw_loc_next; | |
2901 | enum dwarf_location_atom dw_loc_opc; | |
2902 | dw_val_node dw_loc_oprnd1; | |
2903 | dw_val_node dw_loc_oprnd2; | |
d8041cc8 | 2904 | int dw_loc_addr; |
3f76745e JM |
2905 | } |
2906 | dw_loc_descr_node; | |
2907 | ||
63e46568 DB |
2908 | /* Location lists are ranges + location descriptions for that range, |
2909 | so you can track variables that are in different places over | |
30f7a378 | 2910 | their entire life. */ |
17211ab5 | 2911 | typedef struct dw_loc_list_struct GTY(()) |
63e46568 DB |
2912 | { |
2913 | dw_loc_list_ref dw_loc_next; | |
2914 | const char *begin; /* Label for begin address of range */ | |
2915 | const char *end; /* Label for end address of range */ | |
2ad9852d RK |
2916 | char *ll_symbol; /* Label for beginning of location list. |
2917 | Only on head of list */ | |
63e46568 DB |
2918 | const char *section; /* Section this loclist is relative to */ |
2919 | dw_loc_descr_ref expr; | |
2920 | } dw_loc_list_node; | |
2921 | ||
17211ab5 GK |
2922 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) |
2923 | ||
7080f735 AJ |
2924 | static const char *dwarf_stack_op_name (unsigned); |
2925 | static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom, | |
799f628a | 2926 | unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT); |
7080f735 AJ |
2927 | static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref); |
2928 | static unsigned long size_of_loc_descr (dw_loc_descr_ref); | |
2929 | static unsigned long size_of_locs (dw_loc_descr_ref); | |
2930 | static void output_loc_operands (dw_loc_descr_ref); | |
2931 | static void output_loc_sequence (dw_loc_descr_ref); | |
3f76745e | 2932 | |
7d9d8943 | 2933 | /* Convert a DWARF stack opcode into its string name. */ |
3f76745e | 2934 | |
7d9d8943 | 2935 | static const char * |
7080f735 | 2936 | dwarf_stack_op_name (unsigned int op) |
ef76d03b | 2937 | { |
7d9d8943 AM |
2938 | switch (op) |
2939 | { | |
2940 | case DW_OP_addr: | |
b9203463 | 2941 | case INTERNAL_DW_OP_tls_addr: |
7d9d8943 AM |
2942 | return "DW_OP_addr"; |
2943 | case DW_OP_deref: | |
2944 | return "DW_OP_deref"; | |
2945 | case DW_OP_const1u: | |
2946 | return "DW_OP_const1u"; | |
2947 | case DW_OP_const1s: | |
2948 | return "DW_OP_const1s"; | |
2949 | case DW_OP_const2u: | |
2950 | return "DW_OP_const2u"; | |
2951 | case DW_OP_const2s: | |
2952 | return "DW_OP_const2s"; | |
2953 | case DW_OP_const4u: | |
2954 | return "DW_OP_const4u"; | |
2955 | case DW_OP_const4s: | |
2956 | return "DW_OP_const4s"; | |
2957 | case DW_OP_const8u: | |
2958 | return "DW_OP_const8u"; | |
2959 | case DW_OP_const8s: | |
2960 | return "DW_OP_const8s"; | |
2961 | case DW_OP_constu: | |
2962 | return "DW_OP_constu"; | |
2963 | case DW_OP_consts: | |
2964 | return "DW_OP_consts"; | |
2965 | case DW_OP_dup: | |
2966 | return "DW_OP_dup"; | |
2967 | case DW_OP_drop: | |
2968 | return "DW_OP_drop"; | |
2969 | case DW_OP_over: | |
2970 | return "DW_OP_over"; | |
2971 | case DW_OP_pick: | |
2972 | return "DW_OP_pick"; | |
2973 | case DW_OP_swap: | |
2974 | return "DW_OP_swap"; | |
2975 | case DW_OP_rot: | |
2976 | return "DW_OP_rot"; | |
2977 | case DW_OP_xderef: | |
2978 | return "DW_OP_xderef"; | |
2979 | case DW_OP_abs: | |
2980 | return "DW_OP_abs"; | |
2981 | case DW_OP_and: | |
2982 | return "DW_OP_and"; | |
2983 | case DW_OP_div: | |
2984 | return "DW_OP_div"; | |
2985 | case DW_OP_minus: | |
2986 | return "DW_OP_minus"; | |
2987 | case DW_OP_mod: | |
2988 | return "DW_OP_mod"; | |
2989 | case DW_OP_mul: | |
2990 | return "DW_OP_mul"; | |
2991 | case DW_OP_neg: | |
2992 | return "DW_OP_neg"; | |
2993 | case DW_OP_not: | |
2994 | return "DW_OP_not"; | |
2995 | case DW_OP_or: | |
2996 | return "DW_OP_or"; | |
2997 | case DW_OP_plus: | |
2998 | return "DW_OP_plus"; | |
2999 | case DW_OP_plus_uconst: | |
3000 | return "DW_OP_plus_uconst"; | |
3001 | case DW_OP_shl: | |
3002 | return "DW_OP_shl"; | |
3003 | case DW_OP_shr: | |
3004 | return "DW_OP_shr"; | |
3005 | case DW_OP_shra: | |
3006 | return "DW_OP_shra"; | |
3007 | case DW_OP_xor: | |
3008 | return "DW_OP_xor"; | |
3009 | case DW_OP_bra: | |
3010 | return "DW_OP_bra"; | |
3011 | case DW_OP_eq: | |
3012 | return "DW_OP_eq"; | |
3013 | case DW_OP_ge: | |
3014 | return "DW_OP_ge"; | |
3015 | case DW_OP_gt: | |
3016 | return "DW_OP_gt"; | |
3017 | case DW_OP_le: | |
3018 | return "DW_OP_le"; | |
3019 | case DW_OP_lt: | |
3020 | return "DW_OP_lt"; | |
3021 | case DW_OP_ne: | |
3022 | return "DW_OP_ne"; | |
3023 | case DW_OP_skip: | |
3024 | return "DW_OP_skip"; | |
3025 | case DW_OP_lit0: | |
3026 | return "DW_OP_lit0"; | |
3027 | case DW_OP_lit1: | |
3028 | return "DW_OP_lit1"; | |
3029 | case DW_OP_lit2: | |
3030 | return "DW_OP_lit2"; | |
3031 | case DW_OP_lit3: | |
3032 | return "DW_OP_lit3"; | |
3033 | case DW_OP_lit4: | |
3034 | return "DW_OP_lit4"; | |
3035 | case DW_OP_lit5: | |
3036 | return "DW_OP_lit5"; | |
3037 | case DW_OP_lit6: | |
3038 | return "DW_OP_lit6"; | |
3039 | case DW_OP_lit7: | |
3040 | return "DW_OP_lit7"; | |
3041 | case DW_OP_lit8: | |
3042 | return "DW_OP_lit8"; | |
3043 | case DW_OP_lit9: | |
3044 | return "DW_OP_lit9"; | |
3045 | case DW_OP_lit10: | |
3046 | return "DW_OP_lit10"; | |
3047 | case DW_OP_lit11: | |
3048 | return "DW_OP_lit11"; | |
3049 | case DW_OP_lit12: | |
3050 | return "DW_OP_lit12"; | |
3051 | case DW_OP_lit13: | |
3052 | return "DW_OP_lit13"; | |
3053 | case DW_OP_lit14: | |
3054 | return "DW_OP_lit14"; | |
3055 | case DW_OP_lit15: | |
3056 | return "DW_OP_lit15"; | |
3057 | case DW_OP_lit16: | |
3058 | return "DW_OP_lit16"; | |
3059 | case DW_OP_lit17: | |
3060 | return "DW_OP_lit17"; | |
3061 | case DW_OP_lit18: | |
3062 | return "DW_OP_lit18"; | |
3063 | case DW_OP_lit19: | |
3064 | return "DW_OP_lit19"; | |
3065 | case DW_OP_lit20: | |
3066 | return "DW_OP_lit20"; | |
3067 | case DW_OP_lit21: | |
3068 | return "DW_OP_lit21"; | |
3069 | case DW_OP_lit22: | |
3070 | return "DW_OP_lit22"; | |
3071 | case DW_OP_lit23: | |
3072 | return "DW_OP_lit23"; | |
3073 | case DW_OP_lit24: | |
3074 | return "DW_OP_lit24"; | |
3075 | case DW_OP_lit25: | |
3076 | return "DW_OP_lit25"; | |
3077 | case DW_OP_lit26: | |
3078 | return "DW_OP_lit26"; | |
3079 | case DW_OP_lit27: | |
3080 | return "DW_OP_lit27"; | |
3081 | case DW_OP_lit28: | |
3082 | return "DW_OP_lit28"; | |
3083 | case DW_OP_lit29: | |
3084 | return "DW_OP_lit29"; | |
3085 | case DW_OP_lit30: | |
3086 | return "DW_OP_lit30"; | |
3087 | case DW_OP_lit31: | |
3088 | return "DW_OP_lit31"; | |
3089 | case DW_OP_reg0: | |
3090 | return "DW_OP_reg0"; | |
3091 | case DW_OP_reg1: | |
3092 | return "DW_OP_reg1"; | |
3093 | case DW_OP_reg2: | |
3094 | return "DW_OP_reg2"; | |
3095 | case DW_OP_reg3: | |
3096 | return "DW_OP_reg3"; | |
3097 | case DW_OP_reg4: | |
3098 | return "DW_OP_reg4"; | |
3099 | case DW_OP_reg5: | |
3100 | return "DW_OP_reg5"; | |
3101 | case DW_OP_reg6: | |
3102 | return "DW_OP_reg6"; | |
3103 | case DW_OP_reg7: | |
3104 | return "DW_OP_reg7"; | |
3105 | case DW_OP_reg8: | |
3106 | return "DW_OP_reg8"; | |
3107 | case DW_OP_reg9: | |
3108 | return "DW_OP_reg9"; | |
3109 | case DW_OP_reg10: | |
3110 | return "DW_OP_reg10"; | |
3111 | case DW_OP_reg11: | |
3112 | return "DW_OP_reg11"; | |
3113 | case DW_OP_reg12: | |
3114 | return "DW_OP_reg12"; | |
3115 | case DW_OP_reg13: | |
3116 | return "DW_OP_reg13"; | |
3117 | case DW_OP_reg14: | |
3118 | return "DW_OP_reg14"; | |
3119 | case DW_OP_reg15: | |
3120 | return "DW_OP_reg15"; | |
3121 | case DW_OP_reg16: | |
3122 | return "DW_OP_reg16"; | |
3123 | case DW_OP_reg17: | |
3124 | return "DW_OP_reg17"; | |
3125 | case DW_OP_reg18: | |
3126 | return "DW_OP_reg18"; | |
3127 | case DW_OP_reg19: | |
3128 | return "DW_OP_reg19"; | |
3129 | case DW_OP_reg20: | |
3130 | return "DW_OP_reg20"; | |
3131 | case DW_OP_reg21: | |
3132 | return "DW_OP_reg21"; | |
3133 | case DW_OP_reg22: | |
3134 | return "DW_OP_reg22"; | |
3135 | case DW_OP_reg23: | |
3136 | return "DW_OP_reg23"; | |
3137 | case DW_OP_reg24: | |
3138 | return "DW_OP_reg24"; | |
3139 | case DW_OP_reg25: | |
3140 | return "DW_OP_reg25"; | |
3141 | case DW_OP_reg26: | |
3142 | return "DW_OP_reg26"; | |
3143 | case DW_OP_reg27: | |
3144 | return "DW_OP_reg27"; | |
3145 | case DW_OP_reg28: | |
3146 | return "DW_OP_reg28"; | |
3147 | case DW_OP_reg29: | |
3148 | return "DW_OP_reg29"; | |
3149 | case DW_OP_reg30: | |
3150 | return "DW_OP_reg30"; | |
3151 | case DW_OP_reg31: | |
3152 | return "DW_OP_reg31"; | |
3153 | case DW_OP_breg0: | |
3154 | return "DW_OP_breg0"; | |
3155 | case DW_OP_breg1: | |
3156 | return "DW_OP_breg1"; | |
3157 | case DW_OP_breg2: | |
3158 | return "DW_OP_breg2"; | |
3159 | case DW_OP_breg3: | |
3160 | return "DW_OP_breg3"; | |
3161 | case DW_OP_breg4: | |
3162 | return "DW_OP_breg4"; | |
3163 | case DW_OP_breg5: | |
3164 | return "DW_OP_breg5"; | |
3165 | case DW_OP_breg6: | |
3166 | return "DW_OP_breg6"; | |
3167 | case DW_OP_breg7: | |
3168 | return "DW_OP_breg7"; | |
3169 | case DW_OP_breg8: | |
3170 | return "DW_OP_breg8"; | |
3171 | case DW_OP_breg9: | |
3172 | return "DW_OP_breg9"; | |
3173 | case DW_OP_breg10: | |
3174 | return "DW_OP_breg10"; | |
3175 | case DW_OP_breg11: | |
3176 | return "DW_OP_breg11"; | |
3177 | case DW_OP_breg12: | |
3178 | return "DW_OP_breg12"; | |
3179 | case DW_OP_breg13: | |
3180 | return "DW_OP_breg13"; | |
3181 | case DW_OP_breg14: | |
3182 | return "DW_OP_breg14"; | |
3183 | case DW_OP_breg15: | |
3184 | return "DW_OP_breg15"; | |
3185 | case DW_OP_breg16: | |
3186 | return "DW_OP_breg16"; | |
3187 | case DW_OP_breg17: | |
3188 | return "DW_OP_breg17"; | |
3189 | case DW_OP_breg18: | |
3190 | return "DW_OP_breg18"; | |
3191 | case DW_OP_breg19: | |
3192 | return "DW_OP_breg19"; | |
3193 | case DW_OP_breg20: | |
3194 | return "DW_OP_breg20"; | |
3195 | case DW_OP_breg21: | |
3196 | return "DW_OP_breg21"; | |
3197 | case DW_OP_breg22: | |
3198 | return "DW_OP_breg22"; | |
3199 | case DW_OP_breg23: | |
3200 | return "DW_OP_breg23"; | |
3201 | case DW_OP_breg24: | |
3202 | return "DW_OP_breg24"; | |
3203 | case DW_OP_breg25: | |
3204 | return "DW_OP_breg25"; | |
3205 | case DW_OP_breg26: | |
3206 | return "DW_OP_breg26"; | |
3207 | case DW_OP_breg27: | |
3208 | return "DW_OP_breg27"; | |
3209 | case DW_OP_breg28: | |
3210 | return "DW_OP_breg28"; | |
3211 | case DW_OP_breg29: | |
3212 | return "DW_OP_breg29"; | |
3213 | case DW_OP_breg30: | |
3214 | return "DW_OP_breg30"; | |
3215 | case DW_OP_breg31: | |
3216 | return "DW_OP_breg31"; | |
3217 | case DW_OP_regx: | |
3218 | return "DW_OP_regx"; | |
3219 | case DW_OP_fbreg: | |
3220 | return "DW_OP_fbreg"; | |
3221 | case DW_OP_bregx: | |
3222 | return "DW_OP_bregx"; | |
3223 | case DW_OP_piece: | |
3224 | return "DW_OP_piece"; | |
3225 | case DW_OP_deref_size: | |
3226 | return "DW_OP_deref_size"; | |
3227 | case DW_OP_xderef_size: | |
3228 | return "DW_OP_xderef_size"; | |
3229 | case DW_OP_nop: | |
3230 | return "DW_OP_nop"; | |
b9203463 RH |
3231 | case DW_OP_push_object_address: |
3232 | return "DW_OP_push_object_address"; | |
3233 | case DW_OP_call2: | |
3234 | return "DW_OP_call2"; | |
3235 | case DW_OP_call4: | |
3236 | return "DW_OP_call4"; | |
3237 | case DW_OP_call_ref: | |
3238 | return "DW_OP_call_ref"; | |
3239 | case DW_OP_GNU_push_tls_address: | |
3240 | return "DW_OP_GNU_push_tls_address"; | |
62760ffd CT |
3241 | case DW_OP_GNU_uninit: |
3242 | return "DW_OP_GNU_uninit"; | |
3f76745e | 3243 | default: |
7d9d8943 | 3244 | return "OP_<unknown>"; |
3f76745e | 3245 | } |
bdb669cb | 3246 | } |
a3f97cbb | 3247 | |
7d9d8943 AM |
3248 | /* Return a pointer to a newly allocated location description. Location |
3249 | descriptions are simple expression terms that can be strung | |
3250 | together to form more complicated location (address) descriptions. */ | |
3251 | ||
3252 | static inline dw_loc_descr_ref | |
799f628a JH |
3253 | new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1, |
3254 | unsigned HOST_WIDE_INT oprnd2) | |
4b674448 | 3255 | { |
1b4572a8 | 3256 | dw_loc_descr_ref descr = GGC_CNEW (dw_loc_descr_node); |
71dfc51f | 3257 | |
7d9d8943 AM |
3258 | descr->dw_loc_opc = op; |
3259 | descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const; | |
3260 | descr->dw_loc_oprnd1.v.val_unsigned = oprnd1; | |
3261 | descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const; | |
3262 | descr->dw_loc_oprnd2.v.val_unsigned = oprnd2; | |
71dfc51f | 3263 | |
7d9d8943 AM |
3264 | return descr; |
3265 | } | |
3266 | ||
3267 | /* Add a location description term to a location description expression. */ | |
3268 | ||
3269 | static inline void | |
7080f735 | 3270 | add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr) |
7d9d8943 | 3271 | { |
b3694847 | 3272 | dw_loc_descr_ref *d; |
7d9d8943 AM |
3273 | |
3274 | /* Find the end of the chain. */ | |
3275 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
3276 | ; | |
3277 | ||
3278 | *d = descr; | |
3279 | } | |
3280 | ||
3281 | /* Return the size of a location descriptor. */ | |
3282 | ||
3283 | static unsigned long | |
7080f735 | 3284 | size_of_loc_descr (dw_loc_descr_ref loc) |
7d9d8943 | 3285 | { |
b3694847 | 3286 | unsigned long size = 1; |
7d9d8943 AM |
3287 | |
3288 | switch (loc->dw_loc_opc) | |
3289 | { | |
3290 | case DW_OP_addr: | |
b9203463 | 3291 | case INTERNAL_DW_OP_tls_addr: |
7d9d8943 AM |
3292 | size += DWARF2_ADDR_SIZE; |
3293 | break; | |
3294 | case DW_OP_const1u: | |
3295 | case DW_OP_const1s: | |
3296 | size += 1; | |
3297 | break; | |
3298 | case DW_OP_const2u: | |
3299 | case DW_OP_const2s: | |
3300 | size += 2; | |
3301 | break; | |
3302 | case DW_OP_const4u: | |
3303 | case DW_OP_const4s: | |
3304 | size += 4; | |
3305 | break; | |
3306 | case DW_OP_const8u: | |
3307 | case DW_OP_const8s: | |
3308 | size += 8; | |
3309 | break; | |
3310 | case DW_OP_constu: | |
3311 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
3312 | break; | |
3313 | case DW_OP_consts: | |
3314 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
3315 | break; | |
3316 | case DW_OP_pick: | |
3317 | size += 1; | |
3318 | break; | |
3319 | case DW_OP_plus_uconst: | |
3320 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
3321 | break; | |
3322 | case DW_OP_skip: | |
3323 | case DW_OP_bra: | |
3324 | size += 2; | |
3325 | break; | |
3326 | case DW_OP_breg0: | |
3327 | case DW_OP_breg1: | |
3328 | case DW_OP_breg2: | |
3329 | case DW_OP_breg3: | |
3330 | case DW_OP_breg4: | |
3331 | case DW_OP_breg5: | |
3332 | case DW_OP_breg6: | |
3333 | case DW_OP_breg7: | |
3334 | case DW_OP_breg8: | |
3335 | case DW_OP_breg9: | |
3336 | case DW_OP_breg10: | |
3337 | case DW_OP_breg11: | |
3338 | case DW_OP_breg12: | |
3339 | case DW_OP_breg13: | |
3340 | case DW_OP_breg14: | |
3341 | case DW_OP_breg15: | |
3342 | case DW_OP_breg16: | |
3343 | case DW_OP_breg17: | |
3344 | case DW_OP_breg18: | |
3345 | case DW_OP_breg19: | |
3346 | case DW_OP_breg20: | |
3347 | case DW_OP_breg21: | |
3348 | case DW_OP_breg22: | |
3349 | case DW_OP_breg23: | |
3350 | case DW_OP_breg24: | |
3351 | case DW_OP_breg25: | |
3352 | case DW_OP_breg26: | |
3353 | case DW_OP_breg27: | |
3354 | case DW_OP_breg28: | |
3355 | case DW_OP_breg29: | |
3356 | case DW_OP_breg30: | |
3357 | case DW_OP_breg31: | |
3358 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
3359 | break; | |
3360 | case DW_OP_regx: | |
3361 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
3362 | break; | |
3363 | case DW_OP_fbreg: | |
3364 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
3365 | break; | |
3366 | case DW_OP_bregx: | |
3367 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
3368 | size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int); | |
3369 | break; | |
3370 | case DW_OP_piece: | |
3371 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
3372 | break; | |
3373 | case DW_OP_deref_size: | |
3374 | case DW_OP_xderef_size: | |
3375 | size += 1; | |
3376 | break; | |
b9203463 RH |
3377 | case DW_OP_call2: |
3378 | size += 2; | |
3379 | break; | |
3380 | case DW_OP_call4: | |
3381 | size += 4; | |
3382 | break; | |
3383 | case DW_OP_call_ref: | |
3384 | size += DWARF2_ADDR_SIZE; | |
3385 | break; | |
3f76745e | 3386 | default: |
7d9d8943 | 3387 | break; |
4b674448 | 3388 | } |
7d9d8943 AM |
3389 | |
3390 | return size; | |
4b674448 JM |
3391 | } |
3392 | ||
7d9d8943 | 3393 | /* Return the size of a series of location descriptors. */ |
71dfc51f | 3394 | |
7d9d8943 | 3395 | static unsigned long |
7080f735 | 3396 | size_of_locs (dw_loc_descr_ref loc) |
4b674448 | 3397 | { |
887dc802 | 3398 | dw_loc_descr_ref l; |
2ad9852d | 3399 | unsigned long size; |
7d9d8943 | 3400 | |
887dc802 GK |
3401 | /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr |
3402 | field, to avoid writing to a PCH file. */ | |
3403 | for (size = 0, l = loc; l != NULL; l = l->dw_loc_next) | |
d8041cc8 | 3404 | { |
887dc802 GK |
3405 | if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra) |
3406 | break; | |
3407 | size += size_of_loc_descr (l); | |
3408 | } | |
3409 | if (! l) | |
3410 | return size; | |
3411 | ||
3412 | for (size = 0, l = loc; l != NULL; l = l->dw_loc_next) | |
3413 | { | |
3414 | l->dw_loc_addr = size; | |
3415 | size += size_of_loc_descr (l); | |
d8041cc8 | 3416 | } |
7d9d8943 AM |
3417 | |
3418 | return size; | |
4b674448 JM |
3419 | } |
3420 | ||
7d9d8943 | 3421 | /* Output location description stack opcode's operands (if any). */ |
71dfc51f | 3422 | |
7d9d8943 | 3423 | static void |
7080f735 | 3424 | output_loc_operands (dw_loc_descr_ref loc) |
a3f97cbb | 3425 | { |
b3694847 SS |
3426 | dw_val_ref val1 = &loc->dw_loc_oprnd1; |
3427 | dw_val_ref val2 = &loc->dw_loc_oprnd2; | |
7d9d8943 AM |
3428 | |
3429 | switch (loc->dw_loc_opc) | |
a3f97cbb | 3430 | { |
0517872a | 3431 | #ifdef DWARF2_DEBUGGING_INFO |
3f76745e | 3432 | case DW_OP_addr: |
2e4b9b8c | 3433 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL); |
7d9d8943 | 3434 | break; |
3f76745e | 3435 | case DW_OP_const2u: |
3f76745e | 3436 | case DW_OP_const2s: |
2e4b9b8c | 3437 | dw2_asm_output_data (2, val1->v.val_int, NULL); |
7d9d8943 | 3438 | break; |
3f76745e | 3439 | case DW_OP_const4u: |
3f76745e | 3440 | case DW_OP_const4s: |
2e4b9b8c | 3441 | dw2_asm_output_data (4, val1->v.val_int, NULL); |
7d9d8943 | 3442 | break; |
3f76745e | 3443 | case DW_OP_const8u: |
3f76745e | 3444 | case DW_OP_const8s: |
ced3f397 | 3445 | gcc_assert (HOST_BITS_PER_LONG >= 64); |
2e4b9b8c | 3446 | dw2_asm_output_data (8, val1->v.val_int, NULL); |
7d9d8943 | 3447 | break; |
0517872a JM |
3448 | case DW_OP_skip: |
3449 | case DW_OP_bra: | |
d8041cc8 RH |
3450 | { |
3451 | int offset; | |
3452 | ||
ced3f397 NS |
3453 | gcc_assert (val1->val_class == dw_val_class_loc); |
3454 | offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3); | |
d8041cc8 | 3455 | |
2e4b9b8c | 3456 | dw2_asm_output_data (2, offset, NULL); |
d8041cc8 | 3457 | } |
0517872a | 3458 | break; |
3139472f JM |
3459 | #else |
3460 | case DW_OP_addr: | |
3461 | case DW_OP_const2u: | |
3462 | case DW_OP_const2s: | |
3463 | case DW_OP_const4u: | |
3464 | case DW_OP_const4s: | |
3465 | case DW_OP_const8u: | |
3466 | case DW_OP_const8s: | |
3467 | case DW_OP_skip: | |
3468 | case DW_OP_bra: | |
3469 | /* We currently don't make any attempt to make sure these are | |
73c68f61 SS |
3470 | aligned properly like we do for the main unwind info, so |
3471 | don't support emitting things larger than a byte if we're | |
3472 | only doing unwinding. */ | |
ced3f397 | 3473 | gcc_unreachable (); |
0517872a JM |
3474 | #endif |
3475 | case DW_OP_const1u: | |
3476 | case DW_OP_const1s: | |
2e4b9b8c | 3477 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
0517872a | 3478 | break; |
3f76745e | 3479 | case DW_OP_constu: |
2e4b9b8c | 3480 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 3481 | break; |
3f76745e | 3482 | case DW_OP_consts: |
2e4b9b8c | 3483 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 AM |
3484 | break; |
3485 | case DW_OP_pick: | |
2e4b9b8c | 3486 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 AM |
3487 | break; |
3488 | case DW_OP_plus_uconst: | |
2e4b9b8c | 3489 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 3490 | break; |
3f76745e | 3491 | case DW_OP_breg0: |
3f76745e | 3492 | case DW_OP_breg1: |
3f76745e | 3493 | case DW_OP_breg2: |
3f76745e | 3494 | case DW_OP_breg3: |
3f76745e | 3495 | case DW_OP_breg4: |
3f76745e | 3496 | case DW_OP_breg5: |
3f76745e | 3497 | case DW_OP_breg6: |
3f76745e | 3498 | case DW_OP_breg7: |
3f76745e | 3499 | case DW_OP_breg8: |
3f76745e | 3500 | case DW_OP_breg9: |
3f76745e | 3501 | case DW_OP_breg10: |
3f76745e | 3502 | case DW_OP_breg11: |
3f76745e | 3503 | case DW_OP_breg12: |
3f76745e | 3504 | case DW_OP_breg13: |
3f76745e | 3505 | case DW_OP_breg14: |
3f76745e | 3506 | case DW_OP_breg15: |
3f76745e | 3507 | case DW_OP_breg16: |
3f76745e | 3508 | case DW_OP_breg17: |
3f76745e | 3509 | case DW_OP_breg18: |
3f76745e | 3510 | case DW_OP_breg19: |
3f76745e | 3511 | case DW_OP_breg20: |
3f76745e | 3512 | case DW_OP_breg21: |
3f76745e | 3513 | case DW_OP_breg22: |
3f76745e | 3514 | case DW_OP_breg23: |
3f76745e | 3515 | case DW_OP_breg24: |
3f76745e | 3516 | case DW_OP_breg25: |
3f76745e | 3517 | case DW_OP_breg26: |
3f76745e | 3518 | case DW_OP_breg27: |
3f76745e | 3519 | case DW_OP_breg28: |
3f76745e | 3520 | case DW_OP_breg29: |
3f76745e | 3521 | case DW_OP_breg30: |
3f76745e | 3522 | case DW_OP_breg31: |
2e4b9b8c | 3523 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 3524 | break; |
3f76745e | 3525 | case DW_OP_regx: |
2e4b9b8c | 3526 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 3527 | break; |
3f76745e | 3528 | case DW_OP_fbreg: |
2e4b9b8c | 3529 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 3530 | break; |
3f76745e | 3531 | case DW_OP_bregx: |
2e4b9b8c RH |
3532 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
3533 | dw2_asm_output_data_sleb128 (val2->v.val_int, NULL); | |
7d9d8943 | 3534 | break; |
3f76745e | 3535 | case DW_OP_piece: |
2e4b9b8c | 3536 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 3537 | break; |
3f76745e | 3538 | case DW_OP_deref_size: |
3f76745e | 3539 | case DW_OP_xderef_size: |
2e4b9b8c | 3540 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 | 3541 | break; |
b9203463 RH |
3542 | |
3543 | case INTERNAL_DW_OP_tls_addr: | |
fdbe66f2 EB |
3544 | if (targetm.asm_out.output_dwarf_dtprel) |
3545 | { | |
3546 | targetm.asm_out.output_dwarf_dtprel (asm_out_file, | |
3547 | DWARF2_ADDR_SIZE, | |
3548 | val1->v.val_addr); | |
3549 | fputc ('\n', asm_out_file); | |
3550 | } | |
3551 | else | |
3552 | gcc_unreachable (); | |
b9203463 RH |
3553 | break; |
3554 | ||
7d9d8943 | 3555 | default: |
3139472f JM |
3556 | /* Other codes have no operands. */ |
3557 | break; | |
7d9d8943 AM |
3558 | } |
3559 | } | |
3560 | ||
3561 | /* Output a sequence of location operations. */ | |
3562 | ||
3563 | static void | |
7080f735 | 3564 | output_loc_sequence (dw_loc_descr_ref loc) |
7d9d8943 AM |
3565 | { |
3566 | for (; loc != NULL; loc = loc->dw_loc_next) | |
3567 | { | |
3568 | /* Output the opcode. */ | |
2e4b9b8c RH |
3569 | dw2_asm_output_data (1, loc->dw_loc_opc, |
3570 | "%s", dwarf_stack_op_name (loc->dw_loc_opc)); | |
7d9d8943 AM |
3571 | |
3572 | /* Output the operand(s) (if any). */ | |
3573 | output_loc_operands (loc); | |
3574 | } | |
3575 | } | |
3576 | ||
3577 | /* This routine will generate the correct assembly data for a location | |
3578 | description based on a cfi entry with a complex address. */ | |
3579 | ||
3580 | static void | |
7080f735 | 3581 | output_cfa_loc (dw_cfi_ref cfi) |
7d9d8943 AM |
3582 | { |
3583 | dw_loc_descr_ref loc; | |
3584 | unsigned long size; | |
3585 | ||
3586 | /* Output the size of the block. */ | |
3587 | loc = cfi->dw_cfi_oprnd1.dw_cfi_loc; | |
3588 | size = size_of_locs (loc); | |
2e4b9b8c | 3589 | dw2_asm_output_data_uleb128 (size, NULL); |
7d9d8943 AM |
3590 | |
3591 | /* Now output the operations themselves. */ | |
3592 | output_loc_sequence (loc); | |
3593 | } | |
3594 | ||
35d177a2 AO |
3595 | /* This function builds a dwarf location descriptor sequence from a |
3596 | dw_cfa_location, adding the given OFFSET to the result of the | |
3597 | expression. */ | |
7d9d8943 AM |
3598 | |
3599 | static struct dw_loc_descr_struct * | |
35d177a2 | 3600 | build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset) |
7d9d8943 AM |
3601 | { |
3602 | struct dw_loc_descr_struct *head, *tmp; | |
3603 | ||
35d177a2 AO |
3604 | offset += cfa->offset; |
3605 | ||
30e6f306 | 3606 | if (cfa->indirect) |
f299afab | 3607 | { |
30e6f306 RH |
3608 | if (cfa->base_offset) |
3609 | { | |
3610 | if (cfa->reg <= 31) | |
3611 | head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0); | |
3612 | else | |
3613 | head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset); | |
3614 | } | |
3615 | else if (cfa->reg <= 31) | |
3616 | head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0); | |
f299afab | 3617 | else |
30e6f306 RH |
3618 | head = new_loc_descr (DW_OP_regx, cfa->reg, 0); |
3619 | ||
3620 | head->dw_loc_oprnd1.val_class = dw_val_class_const; | |
3621 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
3622 | add_loc_descr (&head, tmp); | |
35d177a2 | 3623 | if (offset != 0) |
30e6f306 | 3624 | { |
35d177a2 | 3625 | tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0); |
30e6f306 RH |
3626 | add_loc_descr (&head, tmp); |
3627 | } | |
f299afab | 3628 | } |
f299afab | 3629 | else |
7d9d8943 | 3630 | { |
35d177a2 | 3631 | if (offset == 0) |
30e6f306 RH |
3632 | if (cfa->reg <= 31) |
3633 | head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0); | |
3634 | else | |
3635 | head = new_loc_descr (DW_OP_regx, cfa->reg, 0); | |
3636 | else if (cfa->reg <= 31) | |
35d177a2 | 3637 | head = new_loc_descr (DW_OP_breg0 + cfa->reg, offset, 0); |
30e6f306 | 3638 | else |
35d177a2 | 3639 | head = new_loc_descr (DW_OP_bregx, cfa->reg, offset); |
7d9d8943 | 3640 | } |
2ad9852d | 3641 | |
7d9d8943 AM |
3642 | return head; |
3643 | } | |
3644 | ||
2ad9852d RK |
3645 | /* This function fills in aa dw_cfa_location structure from a dwarf location |
3646 | descriptor sequence. */ | |
7d9d8943 AM |
3647 | |
3648 | static void | |
7080f735 | 3649 | get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc) |
7d9d8943 | 3650 | { |
556273e0 | 3651 | struct dw_loc_descr_struct *ptr; |
7d9d8943 AM |
3652 | cfa->offset = 0; |
3653 | cfa->base_offset = 0; | |
3654 | cfa->indirect = 0; | |
3655 | cfa->reg = -1; | |
3656 | ||
3657 | for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next) | |
3658 | { | |
3659 | enum dwarf_location_atom op = ptr->dw_loc_opc; | |
2ad9852d | 3660 | |
7d9d8943 | 3661 | switch (op) |
556273e0 | 3662 | { |
7d9d8943 AM |
3663 | case DW_OP_reg0: |
3664 | case DW_OP_reg1: | |
3665 | case DW_OP_reg2: | |
3666 | case DW_OP_reg3: | |
3667 | case DW_OP_reg4: | |
3668 | case DW_OP_reg5: | |
3669 | case DW_OP_reg6: | |
3670 | case DW_OP_reg7: | |
3671 | case DW_OP_reg8: | |
3672 | case DW_OP_reg9: | |
3673 | case DW_OP_reg10: | |
3674 | case DW_OP_reg11: | |
3675 | case DW_OP_reg12: | |
3676 | case DW_OP_reg13: | |
3677 | case DW_OP_reg14: | |
3678 | case DW_OP_reg15: | |
3679 | case DW_OP_reg16: | |
3680 | case DW_OP_reg17: | |
3681 | case DW_OP_reg18: | |
3682 | case DW_OP_reg19: | |
3683 | case DW_OP_reg20: | |
3684 | case DW_OP_reg21: | |
3685 | case DW_OP_reg22: | |
3686 | case DW_OP_reg23: | |
3687 | case DW_OP_reg24: | |
3688 | case DW_OP_reg25: | |
3689 | case DW_OP_reg26: | |
3690 | case DW_OP_reg27: | |
3691 | case DW_OP_reg28: | |
3692 | case DW_OP_reg29: | |
3693 | case DW_OP_reg30: | |
3694 | case DW_OP_reg31: | |
3695 | cfa->reg = op - DW_OP_reg0; | |
3696 | break; | |
3697 | case DW_OP_regx: | |
3698 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
3699 | break; | |
3700 | case DW_OP_breg0: | |
3701 | case DW_OP_breg1: | |
3702 | case DW_OP_breg2: | |
3703 | case DW_OP_breg3: | |
3704 | case DW_OP_breg4: | |
3705 | case DW_OP_breg5: | |
3706 | case DW_OP_breg6: | |
3707 | case DW_OP_breg7: | |
3708 | case DW_OP_breg8: | |
3709 | case DW_OP_breg9: | |
3710 | case DW_OP_breg10: | |
3711 | case DW_OP_breg11: | |
3712 | case DW_OP_breg12: | |
3713 | case DW_OP_breg13: | |
3714 | case DW_OP_breg14: | |
3715 | case DW_OP_breg15: | |
3716 | case DW_OP_breg16: | |
3717 | case DW_OP_breg17: | |
3718 | case DW_OP_breg18: | |
3719 | case DW_OP_breg19: | |
3720 | case DW_OP_breg20: | |
3721 | case DW_OP_breg21: | |
3722 | case DW_OP_breg22: | |
3723 | case DW_OP_breg23: | |
3724 | case DW_OP_breg24: | |
3725 | case DW_OP_breg25: | |
3726 | case DW_OP_breg26: | |
3727 | case DW_OP_breg27: | |
3728 | case DW_OP_breg28: | |
3729 | case DW_OP_breg29: | |
3730 | case DW_OP_breg30: | |
3731 | case DW_OP_breg31: | |
3732 | cfa->reg = op - DW_OP_breg0; | |
3733 | cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int; | |
3734 | break; | |
3735 | case DW_OP_bregx: | |
3736 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
3737 | cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int; | |
3738 | break; | |
3739 | case DW_OP_deref: | |
3740 | cfa->indirect = 1; | |
3741 | break; | |
3742 | case DW_OP_plus_uconst: | |
556273e0 | 3743 | cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned; |
7d9d8943 AM |
3744 | break; |
3745 | default: | |
ab532386 | 3746 | internal_error ("DW_LOC_OP %s not implemented", |
400500c4 | 3747 | dwarf_stack_op_name (ptr->dw_loc_opc)); |
7d9d8943 AM |
3748 | } |
3749 | } | |
3750 | } | |
3751 | #endif /* .debug_frame support */ | |
3752 | \f | |
3753 | /* And now, the support for symbolic debugging information. */ | |
3754 | #ifdef DWARF2_DEBUGGING_INFO | |
3755 | ||
117f9d28 | 3756 | /* .debug_str support. */ |
7080f735 AJ |
3757 | static int output_indirect_string (void **, void *); |
3758 | ||
3759 | static void dwarf2out_init (const char *); | |
3760 | static void dwarf2out_finish (const char *); | |
3761 | static void dwarf2out_define (unsigned int, const char *); | |
3762 | static void dwarf2out_undef (unsigned int, const char *); | |
3763 | static void dwarf2out_start_source_file (unsigned, const char *); | |
3764 | static void dwarf2out_end_source_file (unsigned); | |
3765 | static void dwarf2out_begin_block (unsigned, unsigned); | |
3766 | static void dwarf2out_end_block (unsigned, unsigned); | |
9678086d | 3767 | static bool dwarf2out_ignore_block (const_tree); |
7080f735 | 3768 | static void dwarf2out_global_decl (tree); |
21d13d83 | 3769 | static void dwarf2out_type_decl (tree, int); |
6097b0c3 | 3770 | static void dwarf2out_imported_module_or_decl (tree, tree); |
7080f735 | 3771 | static void dwarf2out_abstract_function (tree); |
0a2d3d69 DB |
3772 | static void dwarf2out_var_location (rtx); |
3773 | static void dwarf2out_begin_function (tree); | |
7f905405 NB |
3774 | |
3775 | /* The debug hooks structure. */ | |
3776 | ||
54b6670a | 3777 | const struct gcc_debug_hooks dwarf2_debug_hooks = |
7f905405 NB |
3778 | { |
3779 | dwarf2out_init, | |
3780 | dwarf2out_finish, | |
3781 | dwarf2out_define, | |
3782 | dwarf2out_undef, | |
3783 | dwarf2out_start_source_file, | |
a5a42b92 NB |
3784 | dwarf2out_end_source_file, |
3785 | dwarf2out_begin_block, | |
e2a12aca | 3786 | dwarf2out_end_block, |
e1772ac0 | 3787 | dwarf2out_ignore_block, |
e2a12aca | 3788 | dwarf2out_source_line, |
653e276c | 3789 | dwarf2out_begin_prologue, |
702ada3d | 3790 | debug_nothing_int_charstar, /* end_prologue */ |
e2a12aca | 3791 | dwarf2out_end_epilogue, |
0a2d3d69 | 3792 | dwarf2out_begin_function, |
2b85879e NB |
3793 | debug_nothing_int, /* end_function */ |
3794 | dwarf2out_decl, /* function_decl */ | |
3795 | dwarf2out_global_decl, | |
21d13d83 | 3796 | dwarf2out_type_decl, /* type_decl */ |
6097b0c3 | 3797 | dwarf2out_imported_module_or_decl, |
e1772ac0 NB |
3798 | debug_nothing_tree, /* deferred_inline_function */ |
3799 | /* The DWARF 2 backend tries to reduce debugging bloat by not | |
3800 | emitting the abstract description of inline functions until | |
3801 | something tries to reference them. */ | |
3802 | dwarf2out_abstract_function, /* outlining_inline_function */ | |
33b49800 | 3803 | debug_nothing_rtx, /* label */ |
014a1138 | 3804 | debug_nothing_int, /* handle_pch */ |
9e9945c5 | 3805 | dwarf2out_var_location, |
87c8b4be | 3806 | dwarf2out_switch_text_section, |
9e9945c5 | 3807 | 1 /* start_end_main_source_file */ |
7f905405 | 3808 | }; |
17211ab5 | 3809 | #endif |
7f905405 | 3810 | \f |
7d9d8943 AM |
3811 | /* NOTE: In the comments in this file, many references are made to |
3812 | "Debugging Information Entries". This term is abbreviated as `DIE' | |
3813 | throughout the remainder of this file. */ | |
3814 | ||
3815 | /* An internal representation of the DWARF output is built, and then | |
3816 | walked to generate the DWARF debugging info. The walk of the internal | |
3817 | representation is done after the entire program has been compiled. | |
3818 | The types below are used to describe the internal representation. */ | |
3819 | ||
3820 | /* Various DIE's use offsets relative to the beginning of the | |
3821 | .debug_info section to refer to each other. */ | |
3822 | ||
3823 | typedef long int dw_offset; | |
3824 | ||
3825 | /* Define typedefs here to avoid circular dependencies. */ | |
3826 | ||
3827 | typedef struct dw_attr_struct *dw_attr_ref; | |
3828 | typedef struct dw_line_info_struct *dw_line_info_ref; | |
3829 | typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref; | |
3830 | typedef struct pubname_struct *pubname_ref; | |
a20612aa | 3831 | typedef struct dw_ranges_struct *dw_ranges_ref; |
0435c1d5 | 3832 | typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref; |
7d9d8943 AM |
3833 | |
3834 | /* Each entry in the line_info_table maintains the file and | |
3835 | line number associated with the label generated for that | |
3836 | entry. The label gives the PC value associated with | |
3837 | the line number entry. */ | |
3838 | ||
17211ab5 | 3839 | typedef struct dw_line_info_struct GTY(()) |
7d9d8943 AM |
3840 | { |
3841 | unsigned long dw_file_num; | |
3842 | unsigned long dw_line_num; | |
3843 | } | |
3844 | dw_line_info_entry; | |
3845 | ||
3846 | /* Line information for functions in separate sections; each one gets its | |
3847 | own sequence. */ | |
17211ab5 | 3848 | typedef struct dw_separate_line_info_struct GTY(()) |
7d9d8943 AM |
3849 | { |
3850 | unsigned long dw_file_num; | |
3851 | unsigned long dw_line_num; | |
3852 | unsigned long function; | |
3853 | } | |
3854 | dw_separate_line_info_entry; | |
3855 | ||
3856 | /* Each DIE attribute has a field specifying the attribute kind, | |
3857 | a link to the next attribute in the chain, and an attribute value. | |
3858 | Attributes are typically linked below the DIE they modify. */ | |
3859 | ||
17211ab5 | 3860 | typedef struct dw_attr_struct GTY(()) |
7d9d8943 AM |
3861 | { |
3862 | enum dwarf_attribute dw_attr; | |
7d9d8943 AM |
3863 | dw_val_node dw_attr_val; |
3864 | } | |
3865 | dw_attr_node; | |
3866 | ||
1a27722f GK |
3867 | DEF_VEC_O(dw_attr_node); |
3868 | DEF_VEC_ALLOC_O(dw_attr_node,gc); | |
3869 | ||
d6eeb3ba GK |
3870 | /* The Debugging Information Entry (DIE) structure. DIEs form a tree. |
3871 | The children of each node form a circular list linked by | |
3872 | die_sib. die_child points to the node *before* the "first" child node. */ | |
7d9d8943 | 3873 | |
623f8e39 | 3874 | typedef struct die_struct GTY((chain_circular ("%h.die_sib"))) |
7d9d8943 AM |
3875 | { |
3876 | enum dwarf_tag die_tag; | |
881c6935 | 3877 | char *die_symbol; |
1a27722f | 3878 | VEC(dw_attr_node,gc) * die_attr; |
7d9d8943 AM |
3879 | dw_die_ref die_parent; |
3880 | dw_die_ref die_child; | |
3881 | dw_die_ref die_sib; | |
47fcfa7b | 3882 | dw_die_ref die_definition; /* ref from a specification to its definition */ |
7d9d8943 AM |
3883 | dw_offset die_offset; |
3884 | unsigned long die_abbrev; | |
1bfb5f8f | 3885 | int die_mark; |
33c9159e AH |
3886 | /* Die is used and must not be pruned as unused. */ |
3887 | int die_perennial_p; | |
636c7bc4 | 3888 | unsigned int decl_id; |
7d9d8943 AM |
3889 | } |
3890 | die_node; | |
3891 | ||
d6eeb3ba GK |
3892 | /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */ |
3893 | #define FOR_EACH_CHILD(die, c, expr) do { \ | |
3894 | c = die->die_child; \ | |
3895 | if (c) do { \ | |
3896 | c = c->die_sib; \ | |
3897 | expr; \ | |
3898 | } while (c != die->die_child); \ | |
3899 | } while (0) | |
3900 | ||
7d9d8943 AM |
3901 | /* The pubname structure */ |
3902 | ||
17211ab5 | 3903 | typedef struct pubname_struct GTY(()) |
7d9d8943 AM |
3904 | { |
3905 | dw_die_ref die; | |
e01e0201 | 3906 | const char *name; |
7d9d8943 AM |
3907 | } |
3908 | pubname_entry; | |
3909 | ||
89708594 CT |
3910 | DEF_VEC_O(pubname_entry); |
3911 | DEF_VEC_ALLOC_O(pubname_entry, gc); | |
3912 | ||
17211ab5 | 3913 | struct dw_ranges_struct GTY(()) |
a20612aa | 3914 | { |
0435c1d5 AO |
3915 | /* If this is positive, it's a block number, otherwise it's a |
3916 | bitwise-negated index into dw_ranges_by_label. */ | |
3917 | int num; | |
3918 | }; | |
3919 | ||
3920 | struct dw_ranges_by_label_struct GTY(()) | |
3921 | { | |
3922 | const char *begin; | |
3923 | const char *end; | |
a20612aa RH |
3924 | }; |
3925 | ||
7d9d8943 | 3926 | /* The limbo die list structure. */ |
17211ab5 | 3927 | typedef struct limbo_die_struct GTY(()) |
7d9d8943 AM |
3928 | { |
3929 | dw_die_ref die; | |
54ba1f0d | 3930 | tree created_for; |
7d9d8943 AM |
3931 | struct limbo_die_struct *next; |
3932 | } | |
3933 | limbo_die_node; | |
3934 | ||
3935 | /* How to start an assembler comment. */ | |
3936 | #ifndef ASM_COMMENT_START | |
3937 | #define ASM_COMMENT_START ";#" | |
3938 | #endif | |
3939 | ||
cc2902df | 3940 | /* Define a macro which returns nonzero for a TYPE_DECL which was |
7d9d8943 AM |
3941 | implicitly generated for a tagged type. |
3942 | ||
3943 | Note that unlike the gcc front end (which generates a NULL named | |
3944 | TYPE_DECL node for each complete tagged type, each array type, and | |
3945 | each function type node created) the g++ front end generates a | |
3946 | _named_ TYPE_DECL node for each tagged type node created. | |
3947 | These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to | |
3948 | generate a DW_TAG_typedef DIE for them. */ | |
3949 | ||
3950 | #define TYPE_DECL_IS_STUB(decl) \ | |
3951 | (DECL_NAME (decl) == NULL_TREE \ | |
3952 | || (DECL_ARTIFICIAL (decl) \ | |
3953 | && is_tagged_type (TREE_TYPE (decl)) \ | |
3954 | && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \ | |
3955 | /* This is necessary for stub decls that \ | |
3956 | appear in nested inline functions. */ \ | |
3957 | || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \ | |
3958 | && (decl_ultimate_origin (decl) \ | |
3959 | == TYPE_STUB_DECL (TREE_TYPE (decl))))))) | |
3960 | ||
3961 | /* Information concerning the compilation unit's programming | |
3962 | language, and compiler version. */ | |
3963 | ||
7d9d8943 | 3964 | /* Fixed size portion of the DWARF compilation unit header. */ |
9eb0ef7a KB |
3965 | #define DWARF_COMPILE_UNIT_HEADER_SIZE \ |
3966 | (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3) | |
7d9d8943 | 3967 | |
7d9d8943 AM |
3968 | /* Fixed size portion of public names info. */ |
3969 | #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2) | |
3970 | ||
3971 | /* Fixed size portion of the address range info. */ | |
3972 | #define DWARF_ARANGES_HEADER_SIZE \ | |
c583e7c3 | 3973 | (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \ |
2878ea73 | 3974 | DWARF2_ADDR_SIZE * 2) \ |
c583e7c3 | 3975 | - DWARF_INITIAL_LENGTH_SIZE) |
7d9d8943 AM |
3976 | |
3977 | /* Size of padding portion in the address range info. It must be | |
3978 | aligned to twice the pointer size. */ | |
3979 | #define DWARF_ARANGES_PAD_SIZE \ | |
c583e7c3 | 3980 | (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \ |
2878ea73 | 3981 | DWARF2_ADDR_SIZE * 2) \ |
c583e7c3 | 3982 | - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4)) |
7d9d8943 | 3983 | |
9d147085 | 3984 | /* Use assembler line directives if available. */ |
7d9d8943 | 3985 | #ifndef DWARF2_ASM_LINE_DEBUG_INFO |
9d147085 RH |
3986 | #ifdef HAVE_AS_DWARF2_DEBUG_LINE |
3987 | #define DWARF2_ASM_LINE_DEBUG_INFO 1 | |
3988 | #else | |
7d9d8943 AM |
3989 | #define DWARF2_ASM_LINE_DEBUG_INFO 0 |
3990 | #endif | |
9d147085 | 3991 | #endif |
7d9d8943 | 3992 | |
7d9d8943 AM |
3993 | /* Minimum line offset in a special line info. opcode. |
3994 | This value was chosen to give a reasonable range of values. */ | |
3995 | #define DWARF_LINE_BASE -10 | |
3996 | ||
a1f300c0 | 3997 | /* First special line opcode - leave room for the standard opcodes. */ |
7d9d8943 AM |
3998 | #define DWARF_LINE_OPCODE_BASE 10 |
3999 | ||
4000 | /* Range of line offsets in a special line info. opcode. */ | |
4001 | #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1) | |
4002 | ||
4003 | /* Flag that indicates the initial value of the is_stmt_start flag. | |
4004 | In the present implementation, we do not mark any lines as | |
4005 | the beginning of a source statement, because that information | |
4006 | is not made available by the GCC front-end. */ | |
4007 | #define DWARF_LINE_DEFAULT_IS_STMT_START 1 | |
4008 | ||
c1b50e49 | 4009 | #ifdef DWARF2_DEBUGGING_INFO |
7d9d8943 AM |
4010 | /* This location is used by calc_die_sizes() to keep track |
4011 | the offset of each DIE within the .debug_info section. */ | |
4012 | static unsigned long next_die_offset; | |
c1b50e49 | 4013 | #endif |
7d9d8943 AM |
4014 | |
4015 | /* Record the root of the DIE's built for the current compilation unit. */ | |
17211ab5 | 4016 | static GTY(()) dw_die_ref comp_unit_die; |
7d9d8943 AM |
4017 | |
4018 | /* A list of DIEs with a NULL parent waiting to be relocated. */ | |
17211ab5 | 4019 | static GTY(()) limbo_die_node *limbo_die_list; |
7d9d8943 | 4020 | |
981975b6 | 4021 | /* Filenames referenced by this compilation unit. */ |
d5688810 | 4022 | static GTY((param_is (struct dwarf_file_data))) htab_t file_table; |
2e18bbae | 4023 | |
636c7bc4 JZ |
4024 | /* A hash table of references to DIE's that describe declarations. |
4025 | The key is a DECL_UID() which is a unique number identifying each decl. */ | |
4026 | static GTY ((param_is (struct die_struct))) htab_t decl_die_table; | |
7d9d8943 | 4027 | |
0a2d3d69 DB |
4028 | /* Node of the variable location list. */ |
4029 | struct var_loc_node GTY ((chain_next ("%h.next"))) | |
4030 | { | |
4031 | rtx GTY (()) var_loc_note; | |
4032 | const char * GTY (()) label; | |
87c8b4be | 4033 | const char * GTY (()) section_label; |
0a2d3d69 DB |
4034 | struct var_loc_node * GTY (()) next; |
4035 | }; | |
4036 | ||
4037 | /* Variable location list. */ | |
4038 | struct var_loc_list_def GTY (()) | |
4039 | { | |
4040 | struct var_loc_node * GTY (()) first; | |
4041 | ||
4042 | /* Do not mark the last element of the chained list because | |
4043 | it is marked through the chain. */ | |
4044 | struct var_loc_node * GTY ((skip ("%h"))) last; | |
4045 | ||
4046 | /* DECL_UID of the variable decl. */ | |
4047 | unsigned int decl_id; | |
4048 | }; | |
4049 | typedef struct var_loc_list_def var_loc_list; | |
4050 | ||
0a2d3d69 DB |
4051 | |
4052 | /* Table of decl location linked lists. */ | |
4053 | static GTY ((param_is (var_loc_list))) htab_t decl_loc_table; | |
4054 | ||
7d9d8943 AM |
4055 | /* A pointer to the base of a list of references to DIE's that |
4056 | are uniquely identified by their tag, presence/absence of | |
4057 | children DIE's, and list of attribute/value pairs. */ | |
7080f735 | 4058 | static GTY((length ("abbrev_die_table_allocated"))) |
17211ab5 | 4059 | dw_die_ref *abbrev_die_table; |
7d9d8943 AM |
4060 | |
4061 | /* Number of elements currently allocated for abbrev_die_table. */ | |
c2e9147c | 4062 | static GTY(()) unsigned abbrev_die_table_allocated; |
7d9d8943 AM |
4063 | |
4064 | /* Number of elements in type_die_table currently in use. */ | |
c2e9147c | 4065 | static GTY(()) unsigned abbrev_die_table_in_use; |
7d9d8943 AM |
4066 | |
4067 | /* Size (in elements) of increments by which we may expand the | |
4068 | abbrev_die_table. */ | |
4069 | #define ABBREV_DIE_TABLE_INCREMENT 256 | |
4070 | ||
4071 | /* A pointer to the base of a table that contains line information | |
4072 | for each source code line in .text in the compilation unit. */ | |
7080f735 | 4073 | static GTY((length ("line_info_table_allocated"))) |
17211ab5 | 4074 | dw_line_info_ref line_info_table; |
7d9d8943 AM |
4075 | |
4076 | /* Number of elements currently allocated for line_info_table. */ | |
c2e9147c | 4077 | static GTY(()) unsigned line_info_table_allocated; |
7d9d8943 | 4078 | |
17211ab5 | 4079 | /* Number of elements in line_info_table currently in use. */ |
c2e9147c | 4080 | static GTY(()) unsigned line_info_table_in_use; |
7d9d8943 AM |
4081 | |
4082 | /* A pointer to the base of a table that contains line information | |
4083 | for each source code line outside of .text in the compilation unit. */ | |
17211ab5 GK |
4084 | static GTY ((length ("separate_line_info_table_allocated"))) |
4085 | dw_separate_line_info_ref separate_line_info_table; | |
7d9d8943 AM |
4086 | |
4087 | /* Number of elements currently allocated for separate_line_info_table. */ | |
c2e9147c | 4088 | static GTY(()) unsigned separate_line_info_table_allocated; |
7d9d8943 | 4089 | |
17211ab5 | 4090 | /* Number of elements in separate_line_info_table currently in use. */ |
c2e9147c | 4091 | static GTY(()) unsigned separate_line_info_table_in_use; |
7d9d8943 AM |
4092 | |
4093 | /* Size (in elements) of increments by which we may expand the | |
4094 | line_info_table. */ | |
4095 | #define LINE_INFO_TABLE_INCREMENT 1024 | |
4096 | ||
4097 | /* A pointer to the base of a table that contains a list of publicly | |
4098 | accessible names. */ | |
89708594 | 4099 | static GTY (()) VEC (pubname_entry, gc) * pubname_table; |
7d9d8943 | 4100 | |
89708594 CT |
4101 | /* A pointer to the base of a table that contains a list of publicly |
4102 | accessible types. */ | |
4103 | static GTY (()) VEC (pubname_entry, gc) * pubtype_table; | |
7d9d8943 | 4104 | |
a20612aa | 4105 | /* Array of dies for which we should generate .debug_arange info. */ |
17211ab5 | 4106 | static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table; |
7d9d8943 AM |
4107 | |
4108 | /* Number of elements currently allocated for arange_table. */ | |
c2e9147c | 4109 | static GTY(()) unsigned arange_table_allocated; |
7d9d8943 AM |
4110 | |
4111 | /* Number of elements in arange_table currently in use. */ | |
c2e9147c | 4112 | static GTY(()) unsigned arange_table_in_use; |
7d9d8943 AM |
4113 | |
4114 | /* Size (in elements) of increments by which we may expand the | |
4115 | arange_table. */ | |
4116 | #define ARANGE_TABLE_INCREMENT 64 | |
4117 | ||
a20612aa | 4118 | /* Array of dies for which we should generate .debug_ranges info. */ |
17211ab5 | 4119 | static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table; |
a20612aa RH |
4120 | |
4121 | /* Number of elements currently allocated for ranges_table. */ | |
c2e9147c | 4122 | static GTY(()) unsigned ranges_table_allocated; |
a20612aa RH |
4123 | |
4124 | /* Number of elements in ranges_table currently in use. */ | |
c2e9147c | 4125 | static GTY(()) unsigned ranges_table_in_use; |
a20612aa | 4126 | |
0435c1d5 AO |
4127 | /* Array of pairs of labels referenced in ranges_table. */ |
4128 | static GTY ((length ("ranges_by_label_allocated"))) | |
4129 | dw_ranges_by_label_ref ranges_by_label; | |
4130 | ||
4131 | /* Number of elements currently allocated for ranges_by_label. */ | |
4132 | static GTY(()) unsigned ranges_by_label_allocated; | |
4133 | ||
4134 | /* Number of elements in ranges_by_label currently in use. */ | |
4135 | static GTY(()) unsigned ranges_by_label_in_use; | |
4136 | ||
a20612aa RH |
4137 | /* Size (in elements) of increments by which we may expand the |
4138 | ranges_table. */ | |
4139 | #define RANGES_TABLE_INCREMENT 64 | |
4140 | ||
63e46568 | 4141 | /* Whether we have location lists that need outputting */ |
1146e682 | 4142 | static GTY(()) bool have_location_lists; |
63e46568 | 4143 | |
57d4f65c ZW |
4144 | /* Unique label counter. */ |
4145 | static GTY(()) unsigned int loclabel_num; | |
4146 | ||
c2e9147c | 4147 | #ifdef DWARF2_DEBUGGING_INFO |
7d9d8943 AM |
4148 | /* Record whether the function being analyzed contains inlined functions. */ |
4149 | static int current_function_has_inlines; | |
c1b50e49 | 4150 | #endif |
7d9d8943 AM |
4151 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
4152 | static int comp_unit_has_inlines; | |
4153 | #endif | |
4154 | ||
d5688810 GK |
4155 | /* The last file entry emitted by maybe_emit_file(). */ |
4156 | static GTY(()) struct dwarf_file_data * last_emitted_file; | |
c2e9147c | 4157 | |
71c0e7fc | 4158 | /* Number of internal labels generated by gen_internal_sym(). */ |
c2e9147c GK |
4159 | static GTY(()) int label_num; |
4160 | ||
66cccea6 AP |
4161 | /* Cached result of previous call to lookup_filename. */ |
4162 | static GTY(()) struct dwarf_file_data * file_table_last_lookup; | |
4163 | ||
17211ab5 GK |
4164 | #ifdef DWARF2_DEBUGGING_INFO |
4165 | ||
35d177a2 | 4166 | /* Offset from the "steady-state frame pointer" to the frame base, |
30e6f306 | 4167 | within the current function. */ |
35d177a2 | 4168 | static HOST_WIDE_INT frame_pointer_fb_offset; |
30e6f306 | 4169 | |
7d9d8943 AM |
4170 | /* Forward declarations for functions defined in this file. */ |
4171 | ||
9678086d | 4172 | static int is_pseudo_reg (const_rtx); |
7080f735 | 4173 | static tree type_main_variant (tree); |
9678086d | 4174 | static int is_tagged_type (const_tree); |
7080f735 AJ |
4175 | static const char *dwarf_tag_name (unsigned); |
4176 | static const char *dwarf_attr_name (unsigned); | |
4177 | static const char *dwarf_form_name (unsigned); | |
9678086d KG |
4178 | static tree decl_ultimate_origin (const_tree); |
4179 | static tree block_ultimate_origin (const_tree); | |
7080f735 AJ |
4180 | static tree decl_class_context (tree); |
4181 | static void add_dwarf_attr (dw_die_ref, dw_attr_ref); | |
4182 | static inline enum dw_val_class AT_class (dw_attr_ref); | |
4183 | static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned); | |
4184 | static inline unsigned AT_flag (dw_attr_ref); | |
799f628a JH |
4185 | static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT); |
4186 | static inline HOST_WIDE_INT AT_int (dw_attr_ref); | |
4187 | static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT); | |
4188 | static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref); | |
7080f735 AJ |
4189 | static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long, |
4190 | unsigned long); | |
e7ee3914 AM |
4191 | static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int, |
4192 | unsigned int, unsigned char *); | |
7080f735 AJ |
4193 | static hashval_t debug_str_do_hash (const void *); |
4194 | static int debug_str_eq (const void *, const void *); | |
4195 | static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *); | |
4196 | static inline const char *AT_string (dw_attr_ref); | |
4197 | static int AT_string_form (dw_attr_ref); | |
4198 | static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref); | |
47fcfa7b | 4199 | static void add_AT_specification (dw_die_ref, dw_die_ref); |
7080f735 AJ |
4200 | static inline dw_die_ref AT_ref (dw_attr_ref); |
4201 | static inline int AT_ref_external (dw_attr_ref); | |
4202 | static inline void set_AT_ref_external (dw_attr_ref, int); | |
4203 | static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned); | |
4204 | static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref); | |
4205 | static inline dw_loc_descr_ref AT_loc (dw_attr_ref); | |
4206 | static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute, | |
4207 | dw_loc_list_ref); | |
4208 | static inline dw_loc_list_ref AT_loc_list (dw_attr_ref); | |
4209 | static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx); | |
4210 | static inline rtx AT_addr (dw_attr_ref); | |
4211 | static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *); | |
192d0f89 GK |
4212 | static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *); |
4213 | static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *); | |
799f628a JH |
4214 | static void add_AT_offset (dw_die_ref, enum dwarf_attribute, |
4215 | unsigned HOST_WIDE_INT); | |
7080f735 AJ |
4216 | static void add_AT_range_list (dw_die_ref, enum dwarf_attribute, |
4217 | unsigned long); | |
4218 | static inline const char *AT_lbl (dw_attr_ref); | |
4219 | static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute); | |
4220 | static const char *get_AT_low_pc (dw_die_ref); | |
4221 | static const char *get_AT_hi_pc (dw_die_ref); | |
4222 | static const char *get_AT_string (dw_die_ref, enum dwarf_attribute); | |
4223 | static int get_AT_flag (dw_die_ref, enum dwarf_attribute); | |
4224 | static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute); | |
4225 | static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute); | |
4226 | static bool is_c_family (void); | |
4227 | static bool is_cxx (void); | |
4228 | static bool is_java (void); | |
4229 | static bool is_fortran (void); | |
4230 | static bool is_ada (void); | |
4231 | static void remove_AT (dw_die_ref, enum dwarf_attribute); | |
6097b0c3 | 4232 | static void remove_child_TAG (dw_die_ref, enum dwarf_tag); |
7080f735 AJ |
4233 | static void add_child_die (dw_die_ref, dw_die_ref); |
4234 | static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree); | |
4235 | static dw_die_ref lookup_type_die (tree); | |
4236 | static void equate_type_number_to_die (tree, dw_die_ref); | |
636c7bc4 JZ |
4237 | static hashval_t decl_die_table_hash (const void *); |
4238 | static int decl_die_table_eq (const void *, const void *); | |
7080f735 | 4239 | static dw_die_ref lookup_decl_die (tree); |
0a2d3d69 DB |
4240 | static hashval_t decl_loc_table_hash (const void *); |
4241 | static int decl_loc_table_eq (const void *, const void *); | |
9678086d | 4242 | static var_loc_list *lookup_decl_loc (const_tree); |
7080f735 | 4243 | static void equate_decl_number_to_die (tree, dw_die_ref); |
0a2d3d69 | 4244 | static void add_var_loc_to_decl (tree, struct var_loc_node *); |
7080f735 AJ |
4245 | static void print_spaces (FILE *); |
4246 | static void print_die (dw_die_ref, FILE *); | |
4247 | static void print_dwarf_line_table (FILE *); | |
7080f735 AJ |
4248 | static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref); |
4249 | static dw_die_ref pop_compile_unit (dw_die_ref); | |
4250 | static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *); | |
4251 | static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *); | |
4252 | static void die_checksum (dw_die_ref, struct md5_ctx *, int *); | |
4253 | static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *); | |
9678086d | 4254 | static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *); |
7080f735 AJ |
4255 | static int same_attr_p (dw_attr_ref, dw_attr_ref, int *); |
4256 | static int same_die_p (dw_die_ref, dw_die_ref, int *); | |
4257 | static int same_die_p_wrap (dw_die_ref, dw_die_ref); | |
4258 | static void compute_section_prefix (dw_die_ref); | |
4259 | static int is_type_die (dw_die_ref); | |
4260 | static int is_comdat_die (dw_die_ref); | |
4261 | static int is_symbol_die (dw_die_ref); | |
4262 | static void assign_symbol_names (dw_die_ref); | |
4263 | static void break_out_includes (dw_die_ref); | |
4264 | static hashval_t htab_cu_hash (const void *); | |
4265 | static int htab_cu_eq (const void *, const void *); | |
4266 | static void htab_cu_del (void *); | |
4267 | static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *); | |
4268 | static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned); | |
4269 | static void add_sibling_attributes (dw_die_ref); | |
4270 | static void build_abbrev_table (dw_die_ref); | |
4271 | static void output_location_lists (dw_die_ref); | |
4272 | static int constant_size (long unsigned); | |
4273 | static unsigned long size_of_die (dw_die_ref); | |
4274 | static void calc_die_sizes (dw_die_ref); | |
4275 | static void mark_dies (dw_die_ref); | |
4276 | static void unmark_dies (dw_die_ref); | |
4277 | static void unmark_all_dies (dw_die_ref); | |
89708594 | 4278 | static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *); |
7080f735 AJ |
4279 | static unsigned long size_of_aranges (void); |
4280 | static enum dwarf_form value_format (dw_attr_ref); | |
4281 | static void output_value_format (dw_attr_ref); | |
4282 | static void output_abbrev_section (void); | |
4283 | static void output_die_symbol (dw_die_ref); | |
4284 | static void output_die (dw_die_ref); | |
4285 | static void output_compilation_unit_header (void); | |
4286 | static void output_comp_unit (dw_die_ref, int); | |
4287 | static const char *dwarf2_name (tree, int); | |
4288 | static void add_pubname (tree, dw_die_ref); | |
7151ffbe | 4289 | static void add_pubname_string (const char *, dw_die_ref); |
89708594 CT |
4290 | static void add_pubtype (tree, dw_die_ref); |
4291 | static void output_pubnames (VEC (pubname_entry,gc) *); | |
7080f735 AJ |
4292 | static void add_arange (tree, dw_die_ref); |
4293 | static void output_aranges (void); | |
0435c1d5 | 4294 | static unsigned int add_ranges_num (int); |
9678086d | 4295 | static unsigned int add_ranges (const_tree); |
0435c1d5 | 4296 | static unsigned int add_ranges_by_labels (const char *, const char *); |
7080f735 AJ |
4297 | static void output_ranges (void); |
4298 | static void output_line_info (void); | |
4299 | static void output_file_names (void); | |
4300 | static dw_die_ref base_type_die (tree); | |
7080f735 | 4301 | static int is_base_type (tree); |
9678086d | 4302 | static bool is_subrange_type (const_tree); |
fbfd77b8 | 4303 | static dw_die_ref subrange_type_die (tree, dw_die_ref); |
7080f735 | 4304 | static dw_die_ref modified_type_die (tree, int, int, dw_die_ref); |
9678086d KG |
4305 | static int type_is_enum (const_tree); |
4306 | static unsigned int dbx_reg_number (const_rtx); | |
216448c7 | 4307 | static void add_loc_descr_op_piece (dw_loc_descr_ref *, int); |
62760ffd | 4308 | static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status); |
4b570560 | 4309 | static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int, |
62760ffd CT |
4310 | enum var_init_status); |
4311 | static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx, | |
4312 | enum var_init_status); | |
7080f735 | 4313 | static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT); |
62760ffd CT |
4314 | static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT, |
4315 | enum var_init_status); | |
9678086d | 4316 | static int is_based_loc (const_rtx); |
62760ffd CT |
4317 | static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode, |
4318 | enum var_init_status); | |
4319 | static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx, | |
4320 | enum var_init_status); | |
4321 | static dw_loc_descr_ref loc_descriptor (rtx, enum var_init_status); | |
1a186ec5 RH |
4322 | static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int); |
4323 | static dw_loc_descr_ref loc_descriptor_from_tree (tree); | |
7080f735 | 4324 | static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int); |
9678086d KG |
4325 | static tree field_type (const_tree); |
4326 | static unsigned int simple_type_align_in_bits (const_tree); | |
4327 | static unsigned int simple_decl_align_in_bits (const_tree); | |
4328 | static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree); | |
4329 | static HOST_WIDE_INT field_byte_offset (const_tree); | |
7080f735 AJ |
4330 | static void add_AT_location_description (dw_die_ref, enum dwarf_attribute, |
4331 | dw_loc_descr_ref); | |
4332 | static void add_data_member_location_attribute (dw_die_ref, tree); | |
4333 | static void add_const_value_attribute (dw_die_ref, rtx); | |
e7ee3914 AM |
4334 | static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *); |
4335 | static HOST_WIDE_INT extract_int (const unsigned char *, unsigned); | |
9678086d | 4336 | static void insert_float (const_rtx, unsigned char *); |
7080f735 | 4337 | static rtx rtl_for_decl_location (tree); |
0a2d3d69 DB |
4338 | static void add_location_or_const_value_attribute (dw_die_ref, tree, |
4339 | enum dwarf_attribute); | |
7080f735 AJ |
4340 | static void tree_add_const_value_attribute (dw_die_ref, tree); |
4341 | static void add_name_attribute (dw_die_ref, const char *); | |
4342 | static void add_comp_dir_attribute (dw_die_ref); | |
4343 | static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree); | |
4344 | static void add_subscript_info (dw_die_ref, tree); | |
4345 | static void add_byte_size_attribute (dw_die_ref, tree); | |
4346 | static void add_bit_offset_attribute (dw_die_ref, tree); | |
4347 | static void add_bit_size_attribute (dw_die_ref, tree); | |
4348 | static void add_prototyped_attribute (dw_die_ref, tree); | |
4349 | static void add_abstract_origin_attribute (dw_die_ref, tree); | |
4350 | static void add_pure_or_virtual_attribute (dw_die_ref, tree); | |
4351 | static void add_src_coords_attributes (dw_die_ref, tree); | |
4352 | static void add_name_and_src_coords_attributes (dw_die_ref, tree); | |
4353 | static void push_decl_scope (tree); | |
4354 | static void pop_decl_scope (void); | |
4355 | static dw_die_ref scope_die_for (tree, dw_die_ref); | |
4356 | static inline int local_scope_p (dw_die_ref); | |
66c78aa9 | 4357 | static inline int class_or_namespace_scope_p (dw_die_ref); |
7080f735 | 4358 | static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref); |
a1c496cb | 4359 | static void add_calling_convention_attribute (dw_die_ref, tree); |
9678086d KG |
4360 | static const char *type_tag (const_tree); |
4361 | static tree member_declared_type (const_tree); | |
7d9d8943 | 4362 | #if 0 |
7080f735 | 4363 | static const char *decl_start_label (tree); |
7d9d8943 | 4364 | #endif |
7080f735 | 4365 | static void gen_array_type_die (tree, dw_die_ref); |
fad0afd7 | 4366 | static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref); |
7d9d8943 | 4367 | #if 0 |
7080f735 | 4368 | static void gen_entry_point_die (tree, dw_die_ref); |
7d9d8943 | 4369 | #endif |
7080f735 AJ |
4370 | static void gen_inlined_enumeration_type_die (tree, dw_die_ref); |
4371 | static void gen_inlined_structure_type_die (tree, dw_die_ref); | |
4372 | static void gen_inlined_union_type_die (tree, dw_die_ref); | |
de99511b | 4373 | static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref); |
7080f735 AJ |
4374 | static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref); |
4375 | static void gen_unspecified_parameters_die (tree, dw_die_ref); | |
4376 | static void gen_formal_types_die (tree, dw_die_ref); | |
4377 | static void gen_subprogram_die (tree, dw_die_ref); | |
4378 | static void gen_variable_die (tree, dw_die_ref); | |
4379 | static void gen_label_die (tree, dw_die_ref); | |
4380 | static void gen_lexical_block_die (tree, dw_die_ref, int); | |
4381 | static void gen_inlined_subroutine_die (tree, dw_die_ref, int); | |
4382 | static void gen_field_die (tree, dw_die_ref); | |
4383 | static void gen_ptr_to_mbr_type_die (tree, dw_die_ref); | |
4384 | static dw_die_ref gen_compile_unit_die (const char *); | |
7080f735 AJ |
4385 | static void gen_inheritance_die (tree, tree, dw_die_ref); |
4386 | static void gen_member_die (tree, dw_die_ref); | |
39ef6592 LC |
4387 | static void gen_struct_or_union_type_die (tree, dw_die_ref, |
4388 | enum debug_info_usage); | |
7080f735 AJ |
4389 | static void gen_subroutine_type_die (tree, dw_die_ref); |
4390 | static void gen_typedef_die (tree, dw_die_ref); | |
4391 | static void gen_type_die (tree, dw_die_ref); | |
4392 | static void gen_tagged_type_instantiation_die (tree, dw_die_ref); | |
4393 | static void gen_block_die (tree, dw_die_ref, int); | |
4394 | static void decls_for_scope (tree, dw_die_ref, int); | |
9678086d | 4395 | static int is_redundant_typedef (const_tree); |
66c78aa9 | 4396 | static void gen_namespace_die (tree); |
7080f735 | 4397 | static void gen_decl_die (tree, dw_die_ref); |
6097b0c3 DP |
4398 | static dw_die_ref force_decl_die (tree); |
4399 | static dw_die_ref force_type_die (tree); | |
66c78aa9 JM |
4400 | static dw_die_ref setup_namespace_context (tree, dw_die_ref); |
4401 | static void declare_in_namespace (tree, dw_die_ref); | |
d5688810 | 4402 | static struct dwarf_file_data * lookup_filename (const char *); |
7080f735 AJ |
4403 | static void retry_incomplete_types (void); |
4404 | static void gen_type_die_for_member (tree, tree, dw_die_ref); | |
4405 | static void splice_child_die (dw_die_ref, dw_die_ref); | |
4406 | static int file_info_cmp (const void *, const void *); | |
4407 | static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *, | |
4408 | const char *, const char *, unsigned); | |
4409 | static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref, | |
4410 | const char *, const char *, | |
4411 | const char *); | |
4412 | static void output_loc_list (dw_loc_list_ref); | |
4413 | static char *gen_internal_sym (const char *); | |
4414 | ||
4415 | static void prune_unmark_dies (dw_die_ref); | |
4416 | static void prune_unused_types_mark (dw_die_ref, int); | |
4417 | static void prune_unused_types_walk (dw_die_ref); | |
4418 | static void prune_unused_types_walk_attribs (dw_die_ref); | |
4419 | static void prune_unused_types_prune (dw_die_ref); | |
4420 | static void prune_unused_types (void); | |
d5688810 | 4421 | static int maybe_emit_file (struct dwarf_file_data *fd); |
73c68f61 | 4422 | |
7d9d8943 AM |
4423 | /* Section names used to hold DWARF debugging information. */ |
4424 | #ifndef DEBUG_INFO_SECTION | |
4425 | #define DEBUG_INFO_SECTION ".debug_info" | |
4426 | #endif | |
9d2f2c45 RH |
4427 | #ifndef DEBUG_ABBREV_SECTION |
4428 | #define DEBUG_ABBREV_SECTION ".debug_abbrev" | |
7d9d8943 | 4429 | #endif |
9d2f2c45 RH |
4430 | #ifndef DEBUG_ARANGES_SECTION |
4431 | #define DEBUG_ARANGES_SECTION ".debug_aranges" | |
7d9d8943 | 4432 | #endif |
9d2f2c45 RH |
4433 | #ifndef DEBUG_MACINFO_SECTION |
4434 | #define DEBUG_MACINFO_SECTION ".debug_macinfo" | |
7d9d8943 AM |
4435 | #endif |
4436 | #ifndef DEBUG_LINE_SECTION | |
4437 | #define DEBUG_LINE_SECTION ".debug_line" | |
4438 | #endif | |
9d2f2c45 RH |
4439 | #ifndef DEBUG_LOC_SECTION |
4440 | #define DEBUG_LOC_SECTION ".debug_loc" | |
7d9d8943 | 4441 | #endif |
9d2f2c45 RH |
4442 | #ifndef DEBUG_PUBNAMES_SECTION |
4443 | #define DEBUG_PUBNAMES_SECTION ".debug_pubnames" | |
7d9d8943 | 4444 | #endif |
9d2f2c45 RH |
4445 | #ifndef DEBUG_STR_SECTION |
4446 | #define DEBUG_STR_SECTION ".debug_str" | |
7d9d8943 | 4447 | #endif |
a20612aa RH |
4448 | #ifndef DEBUG_RANGES_SECTION |
4449 | #define DEBUG_RANGES_SECTION ".debug_ranges" | |
4450 | #endif | |
7d9d8943 AM |
4451 | |
4452 | /* Standard ELF section names for compiled code and data. */ | |
f99ffb60 RH |
4453 | #ifndef TEXT_SECTION_NAME |
4454 | #define TEXT_SECTION_NAME ".text" | |
7d9d8943 AM |
4455 | #endif |
4456 | ||
9eb4015a | 4457 | /* Section flags for .debug_str section. */ |
9eb4015a | 4458 | #define DEBUG_STR_SECTION_FLAGS \ |
28a08168 | 4459 | (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \ |
b0c242c0 AM |
4460 | ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \ |
4461 | : SECTION_DEBUG) | |
9eb4015a | 4462 | |
7d9d8943 | 4463 | /* Labels we insert at beginning sections we can reference instead of |
556273e0 | 4464 | the section names themselves. */ |
7d9d8943 AM |
4465 | |
4466 | #ifndef TEXT_SECTION_LABEL | |
9d2f2c45 | 4467 | #define TEXT_SECTION_LABEL "Ltext" |
7d9d8943 | 4468 | #endif |
c7466dee CT |
4469 | #ifndef COLD_TEXT_SECTION_LABEL |
4470 | #define COLD_TEXT_SECTION_LABEL "Ltext_cold" | |
4471 | #endif | |
7d9d8943 | 4472 | #ifndef DEBUG_LINE_SECTION_LABEL |
9d2f2c45 | 4473 | #define DEBUG_LINE_SECTION_LABEL "Ldebug_line" |
7d9d8943 AM |
4474 | #endif |
4475 | #ifndef DEBUG_INFO_SECTION_LABEL | |
9d2f2c45 | 4476 | #define DEBUG_INFO_SECTION_LABEL "Ldebug_info" |
7d9d8943 | 4477 | #endif |
9d2f2c45 RH |
4478 | #ifndef DEBUG_ABBREV_SECTION_LABEL |
4479 | #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev" | |
7d9d8943 | 4480 | #endif |
9d2f2c45 RH |
4481 | #ifndef DEBUG_LOC_SECTION_LABEL |
4482 | #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc" | |
63e46568 | 4483 | #endif |
2bee6045 JJ |
4484 | #ifndef DEBUG_RANGES_SECTION_LABEL |
4485 | #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges" | |
4486 | #endif | |
84a5b4f8 DB |
4487 | #ifndef DEBUG_MACINFO_SECTION_LABEL |
4488 | #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo" | |
4489 | #endif | |
a20612aa | 4490 | |
7d9d8943 AM |
4491 | /* Definitions of defaults for formats and names of various special |
4492 | (artificial) labels which may be generated within this file (when the -g | |
def66b10 | 4493 | options is used and DWARF2_DEBUGGING_INFO is in effect. |
7d9d8943 AM |
4494 | If necessary, these may be overridden from within the tm.h file, but |
4495 | typically, overriding these defaults is unnecessary. */ | |
4496 | ||
4497 | static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4498 | static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
c7466dee | 4499 | static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
2878ea73 | 4500 | static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
7d9d8943 AM |
4501 | static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
4502 | static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4503 | static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
84a5b4f8 | 4504 | static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
63e46568 | 4505 | static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
2bee6045 | 4506 | static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES]; |
2ad9852d | 4507 | |
7d9d8943 AM |
4508 | #ifndef TEXT_END_LABEL |
4509 | #define TEXT_END_LABEL "Letext" | |
4510 | #endif | |
c7466dee CT |
4511 | #ifndef COLD_END_LABEL |
4512 | #define COLD_END_LABEL "Letext_cold" | |
4513 | #endif | |
7d9d8943 AM |
4514 | #ifndef BLOCK_BEGIN_LABEL |
4515 | #define BLOCK_BEGIN_LABEL "LBB" | |
4516 | #endif | |
4517 | #ifndef BLOCK_END_LABEL | |
4518 | #define BLOCK_END_LABEL "LBE" | |
4519 | #endif | |
7d9d8943 AM |
4520 | #ifndef LINE_CODE_LABEL |
4521 | #define LINE_CODE_LABEL "LM" | |
4522 | #endif | |
4523 | #ifndef SEPARATE_LINE_CODE_LABEL | |
4524 | #define SEPARATE_LINE_CODE_LABEL "LSM" | |
4525 | #endif | |
9e9f8522 | 4526 | |
7d9d8943 AM |
4527 | \f |
4528 | /* We allow a language front-end to designate a function that is to be | |
3f117656 | 4529 | called to "demangle" any name before it is put into a DIE. */ |
7d9d8943 | 4530 | |
7080f735 | 4531 | static const char *(*demangle_name_func) (const char *); |
7d9d8943 AM |
4532 | |
4533 | void | |
7080f735 | 4534 | dwarf2out_set_demangle_name_func (const char *(*func) (const char *)) |
7d9d8943 AM |
4535 | { |
4536 | demangle_name_func = func; | |
4537 | } | |
7d9d8943 AM |
4538 | |
4539 | /* Test if rtl node points to a pseudo register. */ | |
4540 | ||
4541 | static inline int | |
9678086d | 4542 | is_pseudo_reg (const_rtx rtl) |
7d9d8943 | 4543 | { |
f8cfc6aa | 4544 | return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER) |
7d9d8943 | 4545 | || (GET_CODE (rtl) == SUBREG |
ddef6bc7 | 4546 | && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)); |
7d9d8943 AM |
4547 | } |
4548 | ||
4549 | /* Return a reference to a type, with its const and volatile qualifiers | |
4550 | removed. */ | |
4551 | ||
4552 | static inline tree | |
7080f735 | 4553 | type_main_variant (tree type) |
7d9d8943 AM |
4554 | { |
4555 | type = TYPE_MAIN_VARIANT (type); | |
4556 | ||
2ad9852d RK |
4557 | /* ??? There really should be only one main variant among any group of |
4558 | variants of a given type (and all of the MAIN_VARIANT values for all | |
4559 | members of the group should point to that one type) but sometimes the C | |
4560 | front-end messes this up for array types, so we work around that bug | |
4561 | here. */ | |
7d9d8943 AM |
4562 | if (TREE_CODE (type) == ARRAY_TYPE) |
4563 | while (type != TYPE_MAIN_VARIANT (type)) | |
4564 | type = TYPE_MAIN_VARIANT (type); | |
4565 | ||
4566 | return type; | |
4567 | } | |
4568 | ||
cc2902df | 4569 | /* Return nonzero if the given type node represents a tagged type. */ |
7d9d8943 AM |
4570 | |
4571 | static inline int | |
9678086d | 4572 | is_tagged_type (const_tree type) |
7d9d8943 | 4573 | { |
b3694847 | 4574 | enum tree_code code = TREE_CODE (type); |
7d9d8943 AM |
4575 | |
4576 | return (code == RECORD_TYPE || code == UNION_TYPE | |
4577 | || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); | |
4578 | } | |
4579 | ||
4580 | /* Convert a DIE tag into its string name. */ | |
4581 | ||
4582 | static const char * | |
7080f735 | 4583 | dwarf_tag_name (unsigned int tag) |
7d9d8943 AM |
4584 | { |
4585 | switch (tag) | |
4586 | { | |
4587 | case DW_TAG_padding: | |
4588 | return "DW_TAG_padding"; | |
4589 | case DW_TAG_array_type: | |
4590 | return "DW_TAG_array_type"; | |
4591 | case DW_TAG_class_type: | |
4592 | return "DW_TAG_class_type"; | |
4593 | case DW_TAG_entry_point: | |
4594 | return "DW_TAG_entry_point"; | |
4595 | case DW_TAG_enumeration_type: | |
4596 | return "DW_TAG_enumeration_type"; | |
4597 | case DW_TAG_formal_parameter: | |
4598 | return "DW_TAG_formal_parameter"; | |
4599 | case DW_TAG_imported_declaration: | |
4600 | return "DW_TAG_imported_declaration"; | |
4601 | case DW_TAG_label: | |
4602 | return "DW_TAG_label"; | |
4603 | case DW_TAG_lexical_block: | |
4604 | return "DW_TAG_lexical_block"; | |
4605 | case DW_TAG_member: | |
4606 | return "DW_TAG_member"; | |
4607 | case DW_TAG_pointer_type: | |
4608 | return "DW_TAG_pointer_type"; | |
4609 | case DW_TAG_reference_type: | |
4610 | return "DW_TAG_reference_type"; | |
4611 | case DW_TAG_compile_unit: | |
4612 | return "DW_TAG_compile_unit"; | |
4613 | case DW_TAG_string_type: | |
4614 | return "DW_TAG_string_type"; | |
4615 | case DW_TAG_structure_type: | |
4616 | return "DW_TAG_structure_type"; | |
4617 | case DW_TAG_subroutine_type: | |
4618 | return "DW_TAG_subroutine_type"; | |
4619 | case DW_TAG_typedef: | |
4620 | return "DW_TAG_typedef"; | |
4621 | case DW_TAG_union_type: | |
4622 | return "DW_TAG_union_type"; | |
4623 | case DW_TAG_unspecified_parameters: | |
4624 | return "DW_TAG_unspecified_parameters"; | |
4625 | case DW_TAG_variant: | |
4626 | return "DW_TAG_variant"; | |
4627 | case DW_TAG_common_block: | |
4628 | return "DW_TAG_common_block"; | |
4629 | case DW_TAG_common_inclusion: | |
4630 | return "DW_TAG_common_inclusion"; | |
4631 | case DW_TAG_inheritance: | |
4632 | return "DW_TAG_inheritance"; | |
4633 | case DW_TAG_inlined_subroutine: | |
4634 | return "DW_TAG_inlined_subroutine"; | |
4635 | case DW_TAG_module: | |
4636 | return "DW_TAG_module"; | |
4637 | case DW_TAG_ptr_to_member_type: | |
4638 | return "DW_TAG_ptr_to_member_type"; | |
4639 | case DW_TAG_set_type: | |
4640 | return "DW_TAG_set_type"; | |
4641 | case DW_TAG_subrange_type: | |
4642 | return "DW_TAG_subrange_type"; | |
4643 | case DW_TAG_with_stmt: | |
4644 | return "DW_TAG_with_stmt"; | |
4645 | case DW_TAG_access_declaration: | |
4646 | return "DW_TAG_access_declaration"; | |
4647 | case DW_TAG_base_type: | |
4648 | return "DW_TAG_base_type"; | |
4649 | case DW_TAG_catch_block: | |
4650 | return "DW_TAG_catch_block"; | |
4651 | case DW_TAG_const_type: | |
4652 | return "DW_TAG_const_type"; | |
4653 | case DW_TAG_constant: | |
4654 | return "DW_TAG_constant"; | |
4655 | case DW_TAG_enumerator: | |
4656 | return "DW_TAG_enumerator"; | |
4657 | case DW_TAG_file_type: | |
4658 | return "DW_TAG_file_type"; | |
4659 | case DW_TAG_friend: | |
4660 | return "DW_TAG_friend"; | |
4661 | case DW_TAG_namelist: | |
4662 | return "DW_TAG_namelist"; | |
4663 | case DW_TAG_namelist_item: | |
4664 | return "DW_TAG_namelist_item"; | |
4665 | case DW_TAG_packed_type: | |
4666 | return "DW_TAG_packed_type"; | |
4667 | case DW_TAG_subprogram: | |
4668 | return "DW_TAG_subprogram"; | |
4669 | case DW_TAG_template_type_param: | |
4670 | return "DW_TAG_template_type_param"; | |
4671 | case DW_TAG_template_value_param: | |
4672 | return "DW_TAG_template_value_param"; | |
4673 | case DW_TAG_thrown_type: | |
4674 | return "DW_TAG_thrown_type"; | |
4675 | case DW_TAG_try_block: | |
4676 | return "DW_TAG_try_block"; | |
4677 | case DW_TAG_variant_part: | |
4678 | return "DW_TAG_variant_part"; | |
4679 | case DW_TAG_variable: | |
4680 | return "DW_TAG_variable"; | |
4681 | case DW_TAG_volatile_type: | |
4682 | return "DW_TAG_volatile_type"; | |
394d9fe7 AO |
4683 | case DW_TAG_dwarf_procedure: |
4684 | return "DW_TAG_dwarf_procedure"; | |
4685 | case DW_TAG_restrict_type: | |
4686 | return "DW_TAG_restrict_type"; | |
4687 | case DW_TAG_interface_type: | |
4688 | return "DW_TAG_interface_type"; | |
4689 | case DW_TAG_namespace: | |
4690 | return "DW_TAG_namespace"; | |
6097b0c3 DP |
4691 | case DW_TAG_imported_module: |
4692 | return "DW_TAG_imported_module"; | |
394d9fe7 AO |
4693 | case DW_TAG_unspecified_type: |
4694 | return "DW_TAG_unspecified_type"; | |
4695 | case DW_TAG_partial_unit: | |
4696 | return "DW_TAG_partial_unit"; | |
4697 | case DW_TAG_imported_unit: | |
4698 | return "DW_TAG_imported_unit"; | |
4699 | case DW_TAG_condition: | |
4700 | return "DW_TAG_condition"; | |
4701 | case DW_TAG_shared_type: | |
4702 | return "DW_TAG_shared_type"; | |
7d9d8943 AM |
4703 | case DW_TAG_MIPS_loop: |
4704 | return "DW_TAG_MIPS_loop"; | |
4705 | case DW_TAG_format_label: | |
4706 | return "DW_TAG_format_label"; | |
4707 | case DW_TAG_function_template: | |
4708 | return "DW_TAG_function_template"; | |
4709 | case DW_TAG_class_template: | |
4710 | return "DW_TAG_class_template"; | |
881c6935 JM |
4711 | case DW_TAG_GNU_BINCL: |
4712 | return "DW_TAG_GNU_BINCL"; | |
4713 | case DW_TAG_GNU_EINCL: | |
4714 | return "DW_TAG_GNU_EINCL"; | |
7d9d8943 AM |
4715 | default: |
4716 | return "DW_TAG_<unknown>"; | |
4717 | } | |
4718 | } | |
4719 | ||
4720 | /* Convert a DWARF attribute code into its string name. */ | |
4721 | ||
4722 | static const char * | |
7080f735 | 4723 | dwarf_attr_name (unsigned int attr) |
7d9d8943 AM |
4724 | { |
4725 | switch (attr) | |
4726 | { | |
4727 | case DW_AT_sibling: | |
4728 | return "DW_AT_sibling"; | |
4729 | case DW_AT_location: | |
4730 | return "DW_AT_location"; | |
4731 | case DW_AT_name: | |
4732 | return "DW_AT_name"; | |
4733 | case DW_AT_ordering: | |
4734 | return "DW_AT_ordering"; | |
4735 | case DW_AT_subscr_data: | |
4736 | return "DW_AT_subscr_data"; | |
4737 | case DW_AT_byte_size: | |
4738 | return "DW_AT_byte_size"; | |
4739 | case DW_AT_bit_offset: | |
4740 | return "DW_AT_bit_offset"; | |
4741 | case DW_AT_bit_size: | |
4742 | return "DW_AT_bit_size"; | |
4743 | case DW_AT_element_list: | |
4744 | return "DW_AT_element_list"; | |
4745 | case DW_AT_stmt_list: | |
4746 | return "DW_AT_stmt_list"; | |
4747 | case DW_AT_low_pc: | |
4748 | return "DW_AT_low_pc"; | |
4749 | case DW_AT_high_pc: | |
4750 | return "DW_AT_high_pc"; | |
4751 | case DW_AT_language: | |
4752 | return "DW_AT_language"; | |
4753 | case DW_AT_member: | |
4754 | return "DW_AT_member"; | |
4755 | case DW_AT_discr: | |
4756 | return "DW_AT_discr"; | |
4757 | case DW_AT_discr_value: | |
4758 | return "DW_AT_discr_value"; | |
4759 | case DW_AT_visibility: | |
4760 | return "DW_AT_visibility"; | |
4761 | case DW_AT_import: | |
4762 | return "DW_AT_import"; | |
4763 | case DW_AT_string_length: | |
4764 | return "DW_AT_string_length"; | |
4765 | case DW_AT_common_reference: | |
4766 | return "DW_AT_common_reference"; | |
4767 | case DW_AT_comp_dir: | |
4768 | return "DW_AT_comp_dir"; | |
4769 | case DW_AT_const_value: | |
4770 | return "DW_AT_const_value"; | |
4771 | case DW_AT_containing_type: | |
4772 | return "DW_AT_containing_type"; | |
4773 | case DW_AT_default_value: | |
4774 | return "DW_AT_default_value"; | |
4775 | case DW_AT_inline: | |
4776 | return "DW_AT_inline"; | |
4777 | case DW_AT_is_optional: | |
4778 | return "DW_AT_is_optional"; | |
4779 | case DW_AT_lower_bound: | |
4780 | return "DW_AT_lower_bound"; | |
4781 | case DW_AT_producer: | |
4782 | return "DW_AT_producer"; | |
4783 | case DW_AT_prototyped: | |
4784 | return "DW_AT_prototyped"; | |
4785 | case DW_AT_return_addr: | |
4786 | return "DW_AT_return_addr"; | |
4787 | case DW_AT_start_scope: | |
4788 | return "DW_AT_start_scope"; | |
fad0afd7 JJ |
4789 | case DW_AT_bit_stride: |
4790 | return "DW_AT_bit_stride"; | |
7d9d8943 AM |
4791 | case DW_AT_upper_bound: |
4792 | return "DW_AT_upper_bound"; | |
4793 | case DW_AT_abstract_origin: | |
4794 | return "DW_AT_abstract_origin"; | |
4795 | case DW_AT_accessibility: | |
4796 | return "DW_AT_accessibility"; | |
4797 | case DW_AT_address_class: | |
4798 | return "DW_AT_address_class"; | |
4799 | case DW_AT_artificial: | |
4800 | return "DW_AT_artificial"; | |
4801 | case DW_AT_base_types: | |
4802 | return "DW_AT_base_types"; | |
4803 | case DW_AT_calling_convention: | |
4804 | return "DW_AT_calling_convention"; | |
4805 | case DW_AT_count: | |
4806 | return "DW_AT_count"; | |
4807 | case DW_AT_data_member_location: | |
4808 | return "DW_AT_data_member_location"; | |
4809 | case DW_AT_decl_column: | |
4810 | return "DW_AT_decl_column"; | |
4811 | case DW_AT_decl_file: | |
4812 | return "DW_AT_decl_file"; | |
4813 | case DW_AT_decl_line: | |
4814 | return "DW_AT_decl_line"; | |
4815 | case DW_AT_declaration: | |
4816 | return "DW_AT_declaration"; | |
4817 | case DW_AT_discr_list: | |
4818 | return "DW_AT_discr_list"; | |
4819 | case DW_AT_encoding: | |
4820 | return "DW_AT_encoding"; | |
4821 | case DW_AT_external: | |
4822 | return "DW_AT_external"; | |
4823 | case DW_AT_frame_base: | |
4824 | return "DW_AT_frame_base"; | |
4825 | case DW_AT_friend: | |
4826 | return "DW_AT_friend"; | |
4827 | case DW_AT_identifier_case: | |
4828 | return "DW_AT_identifier_case"; | |
4829 | case DW_AT_macro_info: | |
4830 | return "DW_AT_macro_info"; | |
4831 | case DW_AT_namelist_items: | |
4832 | return "DW_AT_namelist_items"; | |
4833 | case DW_AT_priority: | |
4834 | return "DW_AT_priority"; | |
4835 | case DW_AT_segment: | |
4836 | return "DW_AT_segment"; | |
4837 | case DW_AT_specification: | |
4838 | return "DW_AT_specification"; | |
4839 | case DW_AT_static_link: | |
4840 | return "DW_AT_static_link"; | |
4841 | case DW_AT_type: | |
4842 | return "DW_AT_type"; | |
4843 | case DW_AT_use_location: | |
4844 | return "DW_AT_use_location"; | |
4845 | case DW_AT_variable_parameter: | |
4846 | return "DW_AT_variable_parameter"; | |
4847 | case DW_AT_virtuality: | |
4848 | return "DW_AT_virtuality"; | |
4849 | case DW_AT_vtable_elem_location: | |
4850 | return "DW_AT_vtable_elem_location"; | |
4851 | ||
a20612aa RH |
4852 | case DW_AT_allocated: |
4853 | return "DW_AT_allocated"; | |
4854 | case DW_AT_associated: | |
4855 | return "DW_AT_associated"; | |
4856 | case DW_AT_data_location: | |
4857 | return "DW_AT_data_location"; | |
fad0afd7 JJ |
4858 | case DW_AT_byte_stride: |
4859 | return "DW_AT_byte_stride"; | |
a20612aa RH |
4860 | case DW_AT_entry_pc: |
4861 | return "DW_AT_entry_pc"; | |
4862 | case DW_AT_use_UTF8: | |
4863 | return "DW_AT_use_UTF8"; | |
4864 | case DW_AT_extension: | |
4865 | return "DW_AT_extension"; | |
4866 | case DW_AT_ranges: | |
4867 | return "DW_AT_ranges"; | |
4868 | case DW_AT_trampoline: | |
4869 | return "DW_AT_trampoline"; | |
4870 | case DW_AT_call_column: | |
4871 | return "DW_AT_call_column"; | |
4872 | case DW_AT_call_file: | |
4873 | return "DW_AT_call_file"; | |
4874 | case DW_AT_call_line: | |
4875 | return "DW_AT_call_line"; | |
4876 | ||
7d9d8943 AM |
4877 | case DW_AT_MIPS_fde: |
4878 | return "DW_AT_MIPS_fde"; | |
4879 | case DW_AT_MIPS_loop_begin: | |
4880 | return "DW_AT_MIPS_loop_begin"; | |
4881 | case DW_AT_MIPS_tail_loop_begin: | |
4882 | return "DW_AT_MIPS_tail_loop_begin"; | |
4883 | case DW_AT_MIPS_epilog_begin: | |
4884 | return "DW_AT_MIPS_epilog_begin"; | |
4885 | case DW_AT_MIPS_loop_unroll_factor: | |
4886 | return "DW_AT_MIPS_loop_unroll_factor"; | |
4887 | case DW_AT_MIPS_software_pipeline_depth: | |
4888 | return "DW_AT_MIPS_software_pipeline_depth"; | |
4889 | case DW_AT_MIPS_linkage_name: | |
4890 | return "DW_AT_MIPS_linkage_name"; | |
4891 | case DW_AT_MIPS_stride: | |
4892 | return "DW_AT_MIPS_stride"; | |
4893 | case DW_AT_MIPS_abstract_name: | |
4894 | return "DW_AT_MIPS_abstract_name"; | |
4895 | case DW_AT_MIPS_clone_origin: | |
4896 | return "DW_AT_MIPS_clone_origin"; | |
4897 | case DW_AT_MIPS_has_inlines: | |
4898 | return "DW_AT_MIPS_has_inlines"; | |
4899 | ||
4900 | case DW_AT_sf_names: | |
4901 | return "DW_AT_sf_names"; | |
4902 | case DW_AT_src_info: | |
4903 | return "DW_AT_src_info"; | |
4904 | case DW_AT_mac_info: | |
4905 | return "DW_AT_mac_info"; | |
4906 | case DW_AT_src_coords: | |
4907 | return "DW_AT_src_coords"; | |
4908 | case DW_AT_body_begin: | |
4909 | return "DW_AT_body_begin"; | |
4910 | case DW_AT_body_end: | |
4911 | return "DW_AT_body_end"; | |
84f0ace0 JM |
4912 | case DW_AT_GNU_vector: |
4913 | return "DW_AT_GNU_vector"; | |
4914 | ||
7a0c8d71 DR |
4915 | case DW_AT_VMS_rtnbeg_pd_address: |
4916 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
4917 | ||
7d9d8943 AM |
4918 | default: |
4919 | return "DW_AT_<unknown>"; | |
4920 | } | |
4921 | } | |
4922 | ||
4923 | /* Convert a DWARF value form code into its string name. */ | |
4924 | ||
4925 | static const char * | |
7080f735 | 4926 | dwarf_form_name (unsigned int form) |
7d9d8943 AM |
4927 | { |
4928 | switch (form) | |
4929 | { | |
4930 | case DW_FORM_addr: | |
4931 | return "DW_FORM_addr"; | |
4932 | case DW_FORM_block2: | |
4933 | return "DW_FORM_block2"; | |
4934 | case DW_FORM_block4: | |
4935 | return "DW_FORM_block4"; | |
4936 | case DW_FORM_data2: | |
4937 | return "DW_FORM_data2"; | |
4938 | case DW_FORM_data4: | |
4939 | return "DW_FORM_data4"; | |
4940 | case DW_FORM_data8: | |
4941 | return "DW_FORM_data8"; | |
4942 | case DW_FORM_string: | |
4943 | return "DW_FORM_string"; | |
4944 | case DW_FORM_block: | |
4945 | return "DW_FORM_block"; | |
4946 | case DW_FORM_block1: | |
4947 | return "DW_FORM_block1"; | |
4948 | case DW_FORM_data1: | |
4949 | return "DW_FORM_data1"; | |
4950 | case DW_FORM_flag: | |
4951 | return "DW_FORM_flag"; | |
4952 | case DW_FORM_sdata: | |
4953 | return "DW_FORM_sdata"; | |
4954 | case DW_FORM_strp: | |
4955 | return "DW_FORM_strp"; | |
4956 | case DW_FORM_udata: | |
4957 | return "DW_FORM_udata"; | |
4958 | case DW_FORM_ref_addr: | |
4959 | return "DW_FORM_ref_addr"; | |
4960 | case DW_FORM_ref1: | |
4961 | return "DW_FORM_ref1"; | |
4962 | case DW_FORM_ref2: | |
4963 | return "DW_FORM_ref2"; | |
4964 | case DW_FORM_ref4: | |
4965 | return "DW_FORM_ref4"; | |
4966 | case DW_FORM_ref8: | |
4967 | return "DW_FORM_ref8"; | |
4968 | case DW_FORM_ref_udata: | |
4969 | return "DW_FORM_ref_udata"; | |
4970 | case DW_FORM_indirect: | |
4971 | return "DW_FORM_indirect"; | |
3f76745e | 4972 | default: |
7d9d8943 | 4973 | return "DW_FORM_<unknown>"; |
a3f97cbb JW |
4974 | } |
4975 | } | |
3f76745e JM |
4976 | \f |
4977 | /* Determine the "ultimate origin" of a decl. The decl may be an inlined | |
4978 | instance of an inlined instance of a decl which is local to an inline | |
4979 | function, so we have to trace all of the way back through the origin chain | |
4980 | to find out what sort of node actually served as the original seed for the | |
4981 | given block. */ | |
a3f97cbb | 4982 | |
3f76745e | 4983 | static tree |
9678086d | 4984 | decl_ultimate_origin (const_tree decl) |
a3f97cbb | 4985 | { |
820cc88f DB |
4986 | if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON)) |
4987 | return NULL_TREE; | |
4988 | ||
10a11b75 JM |
4989 | /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the |
4990 | nodes in the function to point to themselves; ignore that if | |
4991 | we're trying to output the abstract instance of this function. */ | |
4992 | if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl) | |
4993 | return NULL_TREE; | |
4994 | ||
ced3f397 NS |
4995 | /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the |
4996 | most distant ancestor, this should never happen. */ | |
4997 | gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl))); | |
3f76745e | 4998 | |
02e24c7a | 4999 | return DECL_ABSTRACT_ORIGIN (decl); |
a3f97cbb JW |
5000 | } |
5001 | ||
3f76745e JM |
5002 | /* Determine the "ultimate origin" of a block. The block may be an inlined |
5003 | instance of an inlined instance of a block which is local to an inline | |
5004 | function, so we have to trace all of the way back through the origin chain | |
5005 | to find out what sort of node actually served as the original seed for the | |
5006 | given block. */ | |
71dfc51f | 5007 | |
3f76745e | 5008 | static tree |
9678086d | 5009 | block_ultimate_origin (const_tree block) |
a3f97cbb | 5010 | { |
b3694847 | 5011 | tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); |
71dfc51f | 5012 | |
10a11b75 JM |
5013 | /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the |
5014 | nodes in the function to point to themselves; ignore that if | |
5015 | we're trying to output the abstract instance of this function. */ | |
5016 | if (BLOCK_ABSTRACT (block) && immediate_origin == block) | |
5017 | return NULL_TREE; | |
5018 | ||
3f76745e JM |
5019 | if (immediate_origin == NULL_TREE) |
5020 | return NULL_TREE; | |
5021 | else | |
5022 | { | |
b3694847 SS |
5023 | tree ret_val; |
5024 | tree lookahead = immediate_origin; | |
71dfc51f | 5025 | |
3f76745e JM |
5026 | do |
5027 | { | |
5028 | ret_val = lookahead; | |
2ad9852d RK |
5029 | lookahead = (TREE_CODE (ret_val) == BLOCK |
5030 | ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL); | |
3f76745e JM |
5031 | } |
5032 | while (lookahead != NULL && lookahead != ret_val); | |
2878ea73 | 5033 | |
1eb3331e DB |
5034 | /* The block's abstract origin chain may not be the *ultimate* origin of |
5035 | the block. It could lead to a DECL that has an abstract origin set. | |
5036 | If so, we want that DECL's abstract origin (which is what DECL_ORIGIN | |
5037 | will give us if it has one). Note that DECL's abstract origins are | |
5038 | supposed to be the most distant ancestor (or so decl_ultimate_origin | |
5039 | claims), so we don't need to loop following the DECL origins. */ | |
5040 | if (DECL_P (ret_val)) | |
5041 | return DECL_ORIGIN (ret_val); | |
3f76745e JM |
5042 | |
5043 | return ret_val; | |
5044 | } | |
a3f97cbb JW |
5045 | } |
5046 | ||
3f76745e JM |
5047 | /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT |
5048 | of a virtual function may refer to a base class, so we check the 'this' | |
5049 | parameter. */ | |
71dfc51f | 5050 | |
3f76745e | 5051 | static tree |
7080f735 | 5052 | decl_class_context (tree decl) |
a3f97cbb | 5053 | { |
3f76745e | 5054 | tree context = NULL_TREE; |
71dfc51f | 5055 | |
3f76745e JM |
5056 | if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl)) |
5057 | context = DECL_CONTEXT (decl); | |
5058 | else | |
5059 | context = TYPE_MAIN_VARIANT | |
5060 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
71dfc51f | 5061 | |
2f939d94 | 5062 | if (context && !TYPE_P (context)) |
3f76745e JM |
5063 | context = NULL_TREE; |
5064 | ||
5065 | return context; | |
a3f97cbb JW |
5066 | } |
5067 | \f | |
d6eeb3ba | 5068 | /* Add an attribute/value pair to a DIE. */ |
71dfc51f RK |
5069 | |
5070 | static inline void | |
7080f735 | 5071 | add_dwarf_attr (dw_die_ref die, dw_attr_ref attr) |
a3f97cbb | 5072 | { |
1a27722f GK |
5073 | /* Maybe this should be an assert? */ |
5074 | if (die == NULL) | |
5075 | return; | |
2878ea73 | 5076 | |
1a27722f GK |
5077 | if (die->die_attr == NULL) |
5078 | die->die_attr = VEC_alloc (dw_attr_node, gc, 1); | |
5079 | VEC_safe_push (dw_attr_node, gc, die->die_attr, attr); | |
a3f97cbb JW |
5080 | } |
5081 | ||
17211ab5 | 5082 | static inline enum dw_val_class |
7080f735 | 5083 | AT_class (dw_attr_ref a) |
a96c67ec JM |
5084 | { |
5085 | return a->dw_attr_val.val_class; | |
5086 | } | |
5087 | ||
3f76745e | 5088 | /* Add a flag value attribute to a DIE. */ |
71dfc51f | 5089 | |
3f76745e | 5090 | static inline void |
7080f735 | 5091 | add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag) |
a3f97cbb | 5092 | { |
1a27722f | 5093 | dw_attr_node attr; |
71dfc51f | 5094 | |
1a27722f GK |
5095 | attr.dw_attr = attr_kind; |
5096 | attr.dw_attr_val.val_class = dw_val_class_flag; | |
5097 | attr.dw_attr_val.v.val_flag = flag; | |
5098 | add_dwarf_attr (die, &attr); | |
a3f97cbb JW |
5099 | } |
5100 | ||
a96c67ec | 5101 | static inline unsigned |
7080f735 | 5102 | AT_flag (dw_attr_ref a) |
a96c67ec | 5103 | { |
ced3f397 NS |
5104 | gcc_assert (a && AT_class (a) == dw_val_class_flag); |
5105 | return a->dw_attr_val.v.val_flag; | |
a96c67ec JM |
5106 | } |
5107 | ||
3f76745e | 5108 | /* Add a signed integer attribute value to a DIE. */ |
71dfc51f | 5109 | |
3f76745e | 5110 | static inline void |
799f628a | 5111 | add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val) |
a3f97cbb | 5112 | { |
1a27722f | 5113 | dw_attr_node attr; |
3f76745e | 5114 | |
1a27722f GK |
5115 | attr.dw_attr = attr_kind; |
5116 | attr.dw_attr_val.val_class = dw_val_class_const; | |
5117 | attr.dw_attr_val.v.val_int = int_val; | |
5118 | add_dwarf_attr (die, &attr); | |
a3f97cbb JW |
5119 | } |
5120 | ||
799f628a | 5121 | static inline HOST_WIDE_INT |
7080f735 | 5122 | AT_int (dw_attr_ref a) |
a96c67ec | 5123 | { |
ced3f397 NS |
5124 | gcc_assert (a && AT_class (a) == dw_val_class_const); |
5125 | return a->dw_attr_val.v.val_int; | |
a96c67ec JM |
5126 | } |
5127 | ||
3f76745e | 5128 | /* Add an unsigned integer attribute value to a DIE. */ |
71dfc51f | 5129 | |
3f76745e | 5130 | static inline void |
7080f735 | 5131 | add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind, |
799f628a | 5132 | unsigned HOST_WIDE_INT unsigned_val) |
a3f97cbb | 5133 | { |
1a27722f | 5134 | dw_attr_node attr; |
3f76745e | 5135 | |
1a27722f GK |
5136 | attr.dw_attr = attr_kind; |
5137 | attr.dw_attr_val.val_class = dw_val_class_unsigned_const; | |
5138 | attr.dw_attr_val.v.val_unsigned = unsigned_val; | |
5139 | add_dwarf_attr (die, &attr); | |
a3f97cbb | 5140 | } |
71dfc51f | 5141 | |
799f628a | 5142 | static inline unsigned HOST_WIDE_INT |
7080f735 | 5143 | AT_unsigned (dw_attr_ref a) |
a96c67ec | 5144 | { |
ced3f397 NS |
5145 | gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const); |
5146 | return a->dw_attr_val.v.val_unsigned; | |
a96c67ec JM |
5147 | } |
5148 | ||
3f76745e JM |
5149 | /* Add an unsigned double integer attribute value to a DIE. */ |
5150 | ||
5151 | static inline void | |
7080f735 AJ |
5152 | add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind, |
5153 | long unsigned int val_hi, long unsigned int val_low) | |
a3f97cbb | 5154 | { |
1a27722f | 5155 | dw_attr_node attr; |
71dfc51f | 5156 | |
1a27722f GK |
5157 | attr.dw_attr = attr_kind; |
5158 | attr.dw_attr_val.val_class = dw_val_class_long_long; | |
5159 | attr.dw_attr_val.v.val_long_long.hi = val_hi; | |
5160 | attr.dw_attr_val.v.val_long_long.low = val_low; | |
5161 | add_dwarf_attr (die, &attr); | |
3f76745e | 5162 | } |
71dfc51f | 5163 | |
3f76745e | 5164 | /* Add a floating point attribute value to a DIE and return it. */ |
71dfc51f | 5165 | |
3f76745e | 5166 | static inline void |
e7ee3914 AM |
5167 | add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind, |
5168 | unsigned int length, unsigned int elt_size, unsigned char *array) | |
3f76745e | 5169 | { |
1a27722f | 5170 | dw_attr_node attr; |
3f76745e | 5171 | |
1a27722f GK |
5172 | attr.dw_attr = attr_kind; |
5173 | attr.dw_attr_val.val_class = dw_val_class_vec; | |
5174 | attr.dw_attr_val.v.val_vec.length = length; | |
5175 | attr.dw_attr_val.v.val_vec.elt_size = elt_size; | |
5176 | attr.dw_attr_val.v.val_vec.array = array; | |
5177 | add_dwarf_attr (die, &attr); | |
a3f97cbb JW |
5178 | } |
5179 | ||
17211ab5 GK |
5180 | /* Hash and equality functions for debug_str_hash. */ |
5181 | ||
5182 | static hashval_t | |
7080f735 | 5183 | debug_str_do_hash (const void *x) |
17211ab5 GK |
5184 | { |
5185 | return htab_hash_string (((const struct indirect_string_node *)x)->str); | |
5186 | } | |
5187 | ||
5188 | static int | |
7080f735 | 5189 | debug_str_eq (const void *x1, const void *x2) |
17211ab5 GK |
5190 | { |
5191 | return strcmp ((((const struct indirect_string_node *)x1)->str), | |
5192 | (const char *)x2) == 0; | |
5193 | } | |
5194 | ||
3f76745e | 5195 | /* Add a string attribute value to a DIE. */ |
71dfc51f | 5196 | |
3f76745e | 5197 | static inline void |
7080f735 | 5198 | add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str) |
a3f97cbb | 5199 | { |
1a27722f | 5200 | dw_attr_node attr; |
9eb4015a | 5201 | struct indirect_string_node *node; |
fad205ff | 5202 | void **slot; |
c26fbbca | 5203 | |
9eb4015a | 5204 | if (! debug_str_hash) |
7080f735 | 5205 | debug_str_hash = htab_create_ggc (10, debug_str_do_hash, |
17211ab5 GK |
5206 | debug_str_eq, NULL); |
5207 | ||
5208 | slot = htab_find_slot_with_hash (debug_str_hash, str, | |
5209 | htab_hash_string (str), INSERT); | |
5210 | if (*slot == NULL) | |
a0ad3539 MM |
5211 | { |
5212 | node = (struct indirect_string_node *) | |
5213 | ggc_alloc_cleared (sizeof (struct indirect_string_node)); | |
5214 | node->str = ggc_strdup (str); | |
5215 | *slot = node; | |
5216 | } | |
5217 | else | |
5218 | node = (struct indirect_string_node *) *slot; | |
5219 | ||
9eb4015a | 5220 | node->refcount++; |
71dfc51f | 5221 | |
1a27722f GK |
5222 | attr.dw_attr = attr_kind; |
5223 | attr.dw_attr_val.val_class = dw_val_class_str; | |
5224 | attr.dw_attr_val.v.val_str = node; | |
5225 | add_dwarf_attr (die, &attr); | |
3f76745e | 5226 | } |
71dfc51f | 5227 | |
a96c67ec | 5228 | static inline const char * |
7080f735 | 5229 | AT_string (dw_attr_ref a) |
a96c67ec | 5230 | { |
ced3f397 NS |
5231 | gcc_assert (a && AT_class (a) == dw_val_class_str); |
5232 | return a->dw_attr_val.v.val_str->str; | |
9eb4015a JJ |
5233 | } |
5234 | ||
5235 | /* Find out whether a string should be output inline in DIE | |
5236 | or out-of-line in .debug_str section. */ | |
5237 | ||
9eb4015a | 5238 | static int |
7080f735 | 5239 | AT_string_form (dw_attr_ref a) |
9eb4015a | 5240 | { |
ced3f397 NS |
5241 | struct indirect_string_node *node; |
5242 | unsigned int len; | |
5243 | char label[32]; | |
9eb4015a | 5244 | |
ced3f397 | 5245 | gcc_assert (a && AT_class (a) == dw_val_class_str); |
a1c496cb | 5246 | |
ced3f397 NS |
5247 | node = a->dw_attr_val.v.val_str; |
5248 | if (node->form) | |
5249 | return node->form; | |
a1c496cb | 5250 | |
ced3f397 | 5251 | len = strlen (node->str) + 1; |
9eb4015a | 5252 | |
ced3f397 NS |
5253 | /* If the string is shorter or equal to the size of the reference, it is |
5254 | always better to put it inline. */ | |
5255 | if (len <= DWARF_OFFSET_SIZE || node->refcount == 0) | |
5256 | return node->form = DW_FORM_string; | |
9eb4015a | 5257 | |
ced3f397 NS |
5258 | /* If we cannot expect the linker to merge strings in .debug_str |
5259 | section, only put it into .debug_str if it is worth even in this | |
5260 | single module. */ | |
d6b5193b | 5261 | if ((debug_str_section->common.flags & SECTION_MERGE) == 0 |
ced3f397 NS |
5262 | && (len - DWARF_OFFSET_SIZE) * node->refcount <= len) |
5263 | return node->form = DW_FORM_string; | |
2ad9852d | 5264 | |
ced3f397 NS |
5265 | ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter); |
5266 | ++dw2_string_counter; | |
5267 | node->label = xstrdup (label); | |
a96c67ec | 5268 | |
ced3f397 | 5269 | return node->form = DW_FORM_strp; |
a96c67ec JM |
5270 | } |
5271 | ||
3f76745e | 5272 | /* Add a DIE reference attribute value to a DIE. */ |
71dfc51f | 5273 | |
3f76745e | 5274 | static inline void |
7080f735 | 5275 | add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die) |
3f76745e | 5276 | { |
1a27722f | 5277 | dw_attr_node attr; |
71dfc51f | 5278 | |
1a27722f GK |
5279 | attr.dw_attr = attr_kind; |
5280 | attr.dw_attr_val.val_class = dw_val_class_die_ref; | |
5281 | attr.dw_attr_val.v.val_die_ref.die = targ_die; | |
5282 | attr.dw_attr_val.v.val_die_ref.external = 0; | |
5283 | add_dwarf_attr (die, &attr); | |
3f76745e | 5284 | } |
b1ccbc24 | 5285 | |
47fcfa7b | 5286 | /* Add an AT_specification attribute to a DIE, and also make the back |
6614fd40 | 5287 | pointer from the specification to the definition. */ |
47fcfa7b SS |
5288 | |
5289 | static inline void | |
5290 | add_AT_specification (dw_die_ref die, dw_die_ref targ_die) | |
5291 | { | |
5292 | add_AT_die_ref (die, DW_AT_specification, targ_die); | |
ced3f397 | 5293 | gcc_assert (!targ_die->die_definition); |
47fcfa7b SS |
5294 | targ_die->die_definition = die; |
5295 | } | |
5296 | ||
a96c67ec | 5297 | static inline dw_die_ref |
7080f735 | 5298 | AT_ref (dw_attr_ref a) |
a96c67ec | 5299 | { |
ced3f397 NS |
5300 | gcc_assert (a && AT_class (a) == dw_val_class_die_ref); |
5301 | return a->dw_attr_val.v.val_die_ref.die; | |
a96c67ec JM |
5302 | } |
5303 | ||
881c6935 | 5304 | static inline int |
7080f735 | 5305 | AT_ref_external (dw_attr_ref a) |
881c6935 JM |
5306 | { |
5307 | if (a && AT_class (a) == dw_val_class_die_ref) | |
5308 | return a->dw_attr_val.v.val_die_ref.external; | |
5309 | ||
5310 | return 0; | |
5311 | } | |
5312 | ||
881c6935 | 5313 | static inline void |
7080f735 | 5314 | set_AT_ref_external (dw_attr_ref a, int i) |
881c6935 | 5315 | { |
ced3f397 NS |
5316 | gcc_assert (a && AT_class (a) == dw_val_class_die_ref); |
5317 | a->dw_attr_val.v.val_die_ref.external = i; | |
881c6935 JM |
5318 | } |
5319 | ||
3f76745e | 5320 | /* Add an FDE reference attribute value to a DIE. */ |
b1ccbc24 | 5321 | |
3f76745e | 5322 | static inline void |
7080f735 | 5323 | add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde) |
3f76745e | 5324 | { |
1a27722f | 5325 | dw_attr_node attr; |
b1ccbc24 | 5326 | |
1a27722f GK |
5327 | attr.dw_attr = attr_kind; |
5328 | attr.dw_attr_val.val_class = dw_val_class_fde_ref; | |
5329 | attr.dw_attr_val.v.val_fde_index = targ_fde; | |
5330 | add_dwarf_attr (die, &attr); | |
a3f97cbb | 5331 | } |
71dfc51f | 5332 | |
3f76745e | 5333 | /* Add a location description attribute value to a DIE. */ |
71dfc51f | 5334 | |
3f76745e | 5335 | static inline void |
7080f735 | 5336 | add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc) |
3f76745e | 5337 | { |
1a27722f | 5338 | dw_attr_node attr; |
71dfc51f | 5339 | |
1a27722f GK |
5340 | attr.dw_attr = attr_kind; |
5341 | attr.dw_attr_val.val_class = dw_val_class_loc; | |
5342 | attr.dw_attr_val.v.val_loc = loc; | |
5343 | add_dwarf_attr (die, &attr); | |
a3f97cbb JW |
5344 | } |
5345 | ||
a96c67ec | 5346 | static inline dw_loc_descr_ref |
7080f735 | 5347 | AT_loc (dw_attr_ref a) |
a96c67ec | 5348 | { |
ced3f397 NS |
5349 | gcc_assert (a && AT_class (a) == dw_val_class_loc); |
5350 | return a->dw_attr_val.v.val_loc; | |
a96c67ec JM |
5351 | } |
5352 | ||
63e46568 | 5353 | static inline void |
7080f735 | 5354 | add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list) |
63e46568 | 5355 | { |
1a27722f | 5356 | dw_attr_node attr; |
63e46568 | 5357 | |
1a27722f GK |
5358 | attr.dw_attr = attr_kind; |
5359 | attr.dw_attr_val.val_class = dw_val_class_loc_list; | |
5360 | attr.dw_attr_val.v.val_loc_list = loc_list; | |
5361 | add_dwarf_attr (die, &attr); | |
1146e682 | 5362 | have_location_lists = true; |
63e46568 DB |
5363 | } |
5364 | ||
63e46568 | 5365 | static inline dw_loc_list_ref |
7080f735 | 5366 | AT_loc_list (dw_attr_ref a) |
63e46568 | 5367 | { |
ced3f397 NS |
5368 | gcc_assert (a && AT_class (a) == dw_val_class_loc_list); |
5369 | return a->dw_attr_val.v.val_loc_list; | |
63e46568 DB |
5370 | } |
5371 | ||
3f76745e | 5372 | /* Add an address constant attribute value to a DIE. */ |
71dfc51f | 5373 | |
3f76745e | 5374 | static inline void |
7080f735 | 5375 | add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr) |
a3f97cbb | 5376 | { |
1a27722f | 5377 | dw_attr_node attr; |
71dfc51f | 5378 | |
1a27722f GK |
5379 | attr.dw_attr = attr_kind; |
5380 | attr.dw_attr_val.val_class = dw_val_class_addr; | |
5381 | attr.dw_attr_val.v.val_addr = addr; | |
5382 | add_dwarf_attr (die, &attr); | |
a3f97cbb JW |
5383 | } |
5384 | ||
d5688810 GK |
5385 | /* Get the RTX from to an address DIE attribute. */ |
5386 | ||
1865dbb5 | 5387 | static inline rtx |
7080f735 | 5388 | AT_addr (dw_attr_ref a) |
a96c67ec | 5389 | { |
ced3f397 NS |
5390 | gcc_assert (a && AT_class (a) == dw_val_class_addr); |
5391 | return a->dw_attr_val.v.val_addr; | |
a96c67ec JM |
5392 | } |
5393 | ||
d5688810 GK |
5394 | /* Add a file attribute value to a DIE. */ |
5395 | ||
5396 | static inline void | |
5397 | add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind, | |
5398 | struct dwarf_file_data *fd) | |
5399 | { | |
5400 | dw_attr_node attr; | |
5401 | ||
5402 | attr.dw_attr = attr_kind; | |
5403 | attr.dw_attr_val.val_class = dw_val_class_file; | |
5404 | attr.dw_attr_val.v.val_file = fd; | |
5405 | add_dwarf_attr (die, &attr); | |
5406 | } | |
5407 | ||
5408 | /* Get the dwarf_file_data from a file DIE attribute. */ | |
5409 | ||
5410 | static inline struct dwarf_file_data * | |
5411 | AT_file (dw_attr_ref a) | |
5412 | { | |
5413 | gcc_assert (a && AT_class (a) == dw_val_class_file); | |
5414 | return a->dw_attr_val.v.val_file; | |
5415 | } | |
5416 | ||
3f76745e | 5417 | /* Add a label identifier attribute value to a DIE. */ |
71dfc51f | 5418 | |
3f76745e | 5419 | static inline void |
7080f735 | 5420 | add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id) |
a3f97cbb | 5421 | { |
1a27722f | 5422 | dw_attr_node attr; |
71dfc51f | 5423 | |
1a27722f GK |
5424 | attr.dw_attr = attr_kind; |
5425 | attr.dw_attr_val.val_class = dw_val_class_lbl_id; | |
5426 | attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); | |
5427 | add_dwarf_attr (die, &attr); | |
3f76745e | 5428 | } |
71dfc51f | 5429 | |
192d0f89 GK |
5430 | /* Add a section offset attribute value to a DIE, an offset into the |
5431 | debug_line section. */ | |
3f76745e JM |
5432 | |
5433 | static inline void | |
192d0f89 GK |
5434 | add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind, |
5435 | const char *label) | |
3f76745e | 5436 | { |
1a27722f | 5437 | dw_attr_node attr; |
71dfc51f | 5438 | |
1a27722f GK |
5439 | attr.dw_attr = attr_kind; |
5440 | attr.dw_attr_val.val_class = dw_val_class_lineptr; | |
5441 | attr.dw_attr_val.v.val_lbl_id = xstrdup (label); | |
5442 | add_dwarf_attr (die, &attr); | |
192d0f89 GK |
5443 | } |
5444 | ||
5445 | /* Add a section offset attribute value to a DIE, an offset into the | |
5446 | debug_macinfo section. */ | |
5447 | ||
5448 | static inline void | |
5449 | add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind, | |
5450 | const char *label) | |
5451 | { | |
1a27722f | 5452 | dw_attr_node attr; |
192d0f89 | 5453 | |
1a27722f GK |
5454 | attr.dw_attr = attr_kind; |
5455 | attr.dw_attr_val.val_class = dw_val_class_macptr; | |
5456 | attr.dw_attr_val.v.val_lbl_id = xstrdup (label); | |
5457 | add_dwarf_attr (die, &attr); | |
a3f97cbb JW |
5458 | } |
5459 | ||
a20612aa RH |
5460 | /* Add an offset attribute value to a DIE. */ |
5461 | ||
2bee6045 | 5462 | static inline void |
799f628a JH |
5463 | add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind, |
5464 | unsigned HOST_WIDE_INT offset) | |
a20612aa | 5465 | { |
1a27722f | 5466 | dw_attr_node attr; |
a20612aa | 5467 | |
1a27722f GK |
5468 | attr.dw_attr = attr_kind; |
5469 | attr.dw_attr_val.val_class = dw_val_class_offset; | |
5470 | attr.dw_attr_val.v.val_offset = offset; | |
5471 | add_dwarf_attr (die, &attr); | |
a20612aa RH |
5472 | } |
5473 | ||
2bee6045 JJ |
5474 | /* Add an range_list attribute value to a DIE. */ |
5475 | ||
5476 | static void | |
7080f735 AJ |
5477 | add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind, |
5478 | long unsigned int offset) | |
2bee6045 | 5479 | { |
1a27722f | 5480 | dw_attr_node attr; |
2bee6045 | 5481 | |
1a27722f GK |
5482 | attr.dw_attr = attr_kind; |
5483 | attr.dw_attr_val.val_class = dw_val_class_range_list; | |
5484 | attr.dw_attr_val.v.val_offset = offset; | |
5485 | add_dwarf_attr (die, &attr); | |
2bee6045 JJ |
5486 | } |
5487 | ||
a96c67ec | 5488 | static inline const char * |
7080f735 | 5489 | AT_lbl (dw_attr_ref a) |
a3f97cbb | 5490 | { |
ced3f397 | 5491 | gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id |
192d0f89 GK |
5492 | || AT_class (a) == dw_val_class_lineptr |
5493 | || AT_class (a) == dw_val_class_macptr)); | |
ced3f397 | 5494 | return a->dw_attr_val.v.val_lbl_id; |
a3f97cbb JW |
5495 | } |
5496 | ||
3f76745e | 5497 | /* Get the attribute of type attr_kind. */ |
71dfc51f | 5498 | |
965514bd | 5499 | static dw_attr_ref |
7080f735 | 5500 | get_AT (dw_die_ref die, enum dwarf_attribute attr_kind) |
f37230f0 | 5501 | { |
b3694847 | 5502 | dw_attr_ref a; |
1a27722f | 5503 | unsigned ix; |
b3694847 | 5504 | dw_die_ref spec = NULL; |
556273e0 | 5505 | |
1a27722f GK |
5506 | if (! die) |
5507 | return NULL; | |
71dfc51f | 5508 | |
1a27722f GK |
5509 | for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++) |
5510 | if (a->dw_attr == attr_kind) | |
5511 | return a; | |
5512 | else if (a->dw_attr == DW_AT_specification | |
5513 | || a->dw_attr == DW_AT_abstract_origin) | |
5514 | spec = AT_ref (a); | |
2878ea73 | 5515 | |
1a27722f GK |
5516 | if (spec) |
5517 | return get_AT (spec, attr_kind); | |
3f76745e JM |
5518 | |
5519 | return NULL; | |
f37230f0 JM |
5520 | } |
5521 | ||
2ad9852d RK |
5522 | /* Return the "low pc" attribute value, typically associated with a subprogram |
5523 | DIE. Return null if the "low pc" attribute is either not present, or if it | |
5524 | cannot be represented as an assembler label identifier. */ | |
71dfc51f | 5525 | |
a96c67ec | 5526 | static inline const char * |
7080f735 | 5527 | get_AT_low_pc (dw_die_ref die) |
7e23cb16 | 5528 | { |
b3694847 | 5529 | dw_attr_ref a = get_AT (die, DW_AT_low_pc); |
2ad9852d | 5530 | |
40e8cc95 | 5531 | return a ? AT_lbl (a) : NULL; |
7e23cb16 JM |
5532 | } |
5533 | ||
2ad9852d RK |
5534 | /* Return the "high pc" attribute value, typically associated with a subprogram |
5535 | DIE. Return null if the "high pc" attribute is either not present, or if it | |
5536 | cannot be represented as an assembler label identifier. */ | |
71dfc51f | 5537 | |
a96c67ec | 5538 | static inline const char * |
7080f735 | 5539 | get_AT_hi_pc (dw_die_ref die) |
a3f97cbb | 5540 | { |
b3694847 | 5541 | dw_attr_ref a = get_AT (die, DW_AT_high_pc); |
2ad9852d | 5542 | |
40e8cc95 | 5543 | return a ? AT_lbl (a) : NULL; |
3f76745e JM |
5544 | } |
5545 | ||
5546 | /* Return the value of the string attribute designated by ATTR_KIND, or | |
5547 | NULL if it is not present. */ | |
71dfc51f | 5548 | |
a96c67ec | 5549 | static inline const char * |
7080f735 | 5550 | get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind) |
3f76745e | 5551 | { |
b3694847 | 5552 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 5553 | |
40e8cc95 | 5554 | return a ? AT_string (a) : NULL; |
a3f97cbb JW |
5555 | } |
5556 | ||
3f76745e JM |
5557 | /* Return the value of the flag attribute designated by ATTR_KIND, or -1 |
5558 | if it is not present. */ | |
71dfc51f | 5559 | |
3f76745e | 5560 | static inline int |
7080f735 | 5561 | get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind) |
a3f97cbb | 5562 | { |
b3694847 | 5563 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 5564 | |
40e8cc95 | 5565 | return a ? AT_flag (a) : 0; |
a3f97cbb JW |
5566 | } |
5567 | ||
3f76745e JM |
5568 | /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0 |
5569 | if it is not present. */ | |
71dfc51f | 5570 | |
3f76745e | 5571 | static inline unsigned |
7080f735 | 5572 | get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind) |
a3f97cbb | 5573 | { |
b3694847 | 5574 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 5575 | |
40e8cc95 | 5576 | return a ? AT_unsigned (a) : 0; |
a96c67ec | 5577 | } |
71dfc51f | 5578 | |
a96c67ec | 5579 | static inline dw_die_ref |
7080f735 | 5580 | get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind) |
a96c67ec | 5581 | { |
b3694847 | 5582 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 5583 | |
40e8cc95 | 5584 | return a ? AT_ref (a) : NULL; |
3f76745e | 5585 | } |
71dfc51f | 5586 | |
d5688810 GK |
5587 | static inline struct dwarf_file_data * |
5588 | get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind) | |
5589 | { | |
5590 | dw_attr_ref a = get_AT (die, attr_kind); | |
5591 | ||
5592 | return a ? AT_file (a) : NULL; | |
5593 | } | |
5594 | ||
c3cdeef4 JB |
5595 | /* Return TRUE if the language is C or C++. */ |
5596 | ||
5597 | static inline bool | |
7080f735 | 5598 | is_c_family (void) |
3f76745e | 5599 | { |
c3cdeef4 | 5600 | unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
71dfc51f | 5601 | |
9e51ddaa GK |
5602 | return (lang == DW_LANG_C || lang == DW_LANG_C89 || lang == DW_LANG_ObjC |
5603 | || lang == DW_LANG_C99 | |
5604 | || lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus); | |
556273e0 | 5605 | } |
71dfc51f | 5606 | |
c3cdeef4 JB |
5607 | /* Return TRUE if the language is C++. */ |
5608 | ||
5609 | static inline bool | |
7080f735 | 5610 | is_cxx (void) |
1d3d6b1e | 5611 | { |
9e51ddaa | 5612 | unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
2878ea73 | 5613 | |
9e51ddaa | 5614 | return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus; |
c26fbbca | 5615 | } |
1d3d6b1e | 5616 | |
c3cdeef4 JB |
5617 | /* Return TRUE if the language is Fortran. */ |
5618 | ||
5619 | static inline bool | |
7080f735 | 5620 | is_fortran (void) |
3f76745e | 5621 | { |
c3cdeef4 | 5622 | unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
71dfc51f | 5623 | |
6de9cd9a DN |
5624 | return (lang == DW_LANG_Fortran77 |
5625 | || lang == DW_LANG_Fortran90 | |
5626 | || lang == DW_LANG_Fortran95); | |
556273e0 | 5627 | } |
71dfc51f | 5628 | |
c3cdeef4 JB |
5629 | /* Return TRUE if the language is Java. */ |
5630 | ||
5631 | static inline bool | |
7080f735 | 5632 | is_java (void) |
28985b81 | 5633 | { |
c3cdeef4 | 5634 | unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
28985b81 | 5635 | |
c3cdeef4 JB |
5636 | return lang == DW_LANG_Java; |
5637 | } | |
5638 | ||
5639 | /* Return TRUE if the language is Ada. */ | |
5640 | ||
5641 | static inline bool | |
7080f735 | 5642 | is_ada (void) |
c3cdeef4 JB |
5643 | { |
5644 | unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
7080f735 | 5645 | |
c3cdeef4 | 5646 | return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83; |
28985b81 AG |
5647 | } |
5648 | ||
10a11b75 JM |
5649 | /* Remove the specified attribute if present. */ |
5650 | ||
5651 | static void | |
7080f735 | 5652 | remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind) |
3f76745e | 5653 | { |
1a27722f GK |
5654 | dw_attr_ref a; |
5655 | unsigned ix; | |
a3f97cbb | 5656 | |
1a27722f GK |
5657 | if (! die) |
5658 | return; | |
71dfc51f | 5659 | |
1a27722f GK |
5660 | for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++) |
5661 | if (a->dw_attr == attr_kind) | |
5662 | { | |
e26303c2 GK |
5663 | if (AT_class (a) == dw_val_class_str) |
5664 | if (a->dw_attr_val.v.val_str->refcount) | |
5665 | a->dw_attr_val.v.val_str->refcount--; | |
5666 | ||
1a27722f GK |
5667 | /* VEC_ordered_remove should help reduce the number of abbrevs |
5668 | that are needed. */ | |
5669 | VEC_ordered_remove (dw_attr_node, die->die_attr, ix); | |
5670 | return; | |
5671 | } | |
10a11b75 | 5672 | } |
71dfc51f | 5673 | |
d6eeb3ba GK |
5674 | /* Remove CHILD from its parent. PREV must have the property that |
5675 | PREV->DIE_SIB == CHILD. Does not alter CHILD. */ | |
6097b0c3 DP |
5676 | |
5677 | static void | |
d6eeb3ba | 5678 | remove_child_with_prev (dw_die_ref child, dw_die_ref prev) |
6097b0c3 | 5679 | { |
d6eeb3ba GK |
5680 | gcc_assert (child->die_parent == prev->die_parent); |
5681 | gcc_assert (prev->die_sib == child); | |
5682 | if (prev == child) | |
6097b0c3 | 5683 | { |
d6eeb3ba GK |
5684 | gcc_assert (child->die_parent->die_child == child); |
5685 | prev = NULL; | |
6097b0c3 | 5686 | } |
d6eeb3ba GK |
5687 | else |
5688 | prev->die_sib = child->die_sib; | |
5689 | if (child->die_parent->die_child == child) | |
5690 | child->die_parent->die_child = prev; | |
6097b0c3 DP |
5691 | } |
5692 | ||
d6eeb3ba GK |
5693 | /* Remove child DIE whose die_tag is TAG. Do nothing if no child |
5694 | matches TAG. */ | |
71dfc51f | 5695 | |
d6eeb3ba GK |
5696 | static void |
5697 | remove_child_TAG (dw_die_ref die, enum dwarf_tag tag) | |
5698 | { | |
5699 | dw_die_ref c; | |
2878ea73 | 5700 | |
d6eeb3ba GK |
5701 | c = die->die_child; |
5702 | if (c) do { | |
5703 | dw_die_ref prev = c; | |
5704 | c = c->die_sib; | |
5705 | while (c->die_tag == tag) | |
5706 | { | |
5707 | remove_child_with_prev (c, prev); | |
5708 | /* Might have removed every child. */ | |
5709 | if (c == c->die_sib) | |
5710 | return; | |
5711 | c = c->die_sib; | |
5712 | } | |
5713 | } while (c != die->die_child); | |
5714 | } | |
5715 | ||
5716 | /* Add a CHILD_DIE as the last child of DIE. */ | |
5717 | ||
5718 | static void | |
7080f735 | 5719 | add_child_die (dw_die_ref die, dw_die_ref child_die) |
3f76745e | 5720 | { |
d6eeb3ba GK |
5721 | /* FIXME this should probably be an assert. */ |
5722 | if (! die || ! child_die) | |
5723 | return; | |
5724 | gcc_assert (die != child_die); | |
2ad9852d | 5725 | |
d6eeb3ba GK |
5726 | child_die->die_parent = die; |
5727 | if (die->die_child) | |
5728 | { | |
5729 | child_die->die_sib = die->die_child->die_sib; | |
5730 | die->die_child->die_sib = child_die; | |
3f76745e | 5731 | } |
d6eeb3ba GK |
5732 | else |
5733 | child_die->die_sib = child_die; | |
5734 | die->die_child = child_die; | |
3f76745e JM |
5735 | } |
5736 | ||
2081603c | 5737 | /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT |
2878ea73 | 5738 | is the specification, to the end of PARENT's list of children. |
d6eeb3ba | 5739 | This is done by removing and re-adding it. */ |
10a11b75 JM |
5740 | |
5741 | static void | |
7080f735 | 5742 | splice_child_die (dw_die_ref parent, dw_die_ref child) |
10a11b75 | 5743 | { |
d6eeb3ba | 5744 | dw_die_ref p; |
10a11b75 JM |
5745 | |
5746 | /* We want the declaration DIE from inside the class, not the | |
5747 | specification DIE at toplevel. */ | |
5748 | if (child->die_parent != parent) | |
2081603c JM |
5749 | { |
5750 | dw_die_ref tmp = get_AT_ref (child, DW_AT_specification); | |
2ad9852d | 5751 | |
2081603c JM |
5752 | if (tmp) |
5753 | child = tmp; | |
5754 | } | |
10a11b75 | 5755 | |
ced3f397 NS |
5756 | gcc_assert (child->die_parent == parent |
5757 | || (child->die_parent | |
5758 | == get_AT_ref (parent, DW_AT_specification))); | |
2878ea73 | 5759 | |
d6eeb3ba GK |
5760 | for (p = child->die_parent->die_child; ; p = p->die_sib) |
5761 | if (p->die_sib == child) | |
10a11b75 | 5762 | { |
d6eeb3ba | 5763 | remove_child_with_prev (child, p); |
10a11b75 JM |
5764 | break; |
5765 | } | |
5766 | ||
d6eeb3ba | 5767 | add_child_die (parent, child); |
10a11b75 JM |
5768 | } |
5769 | ||
3f76745e JM |
5770 | /* Return a pointer to a newly created DIE node. */ |
5771 | ||
5772 | static inline dw_die_ref | |
7080f735 | 5773 | new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t) |
3f76745e | 5774 | { |
1b4572a8 | 5775 | dw_die_ref die = GGC_CNEW (die_node); |
3f76745e JM |
5776 | |
5777 | die->die_tag = tag_value; | |
3f76745e JM |
5778 | |
5779 | if (parent_die != NULL) | |
5780 | add_child_die (parent_die, die); | |
5781 | else | |
ef76d03b JW |
5782 | { |
5783 | limbo_die_node *limbo_node; | |
5784 | ||
1b4572a8 | 5785 | limbo_node = GGC_CNEW (limbo_die_node); |
ef76d03b | 5786 | limbo_node->die = die; |
54ba1f0d | 5787 | limbo_node->created_for = t; |
ef76d03b JW |
5788 | limbo_node->next = limbo_die_list; |
5789 | limbo_die_list = limbo_node; | |
5790 | } | |
71dfc51f | 5791 | |
3f76745e JM |
5792 | return die; |
5793 | } | |
71dfc51f | 5794 | |
3f76745e | 5795 | /* Return the DIE associated with the given type specifier. */ |
71dfc51f | 5796 | |
3f76745e | 5797 | static inline dw_die_ref |
7080f735 | 5798 | lookup_type_die (tree type) |
3f76745e | 5799 | { |
e2500fed | 5800 | return TYPE_SYMTAB_DIE (type); |
3f76745e | 5801 | } |
e90b62db | 5802 | |
3f76745e | 5803 | /* Equate a DIE to a given type specifier. */ |
71dfc51f | 5804 | |
10a11b75 | 5805 | static inline void |
7080f735 | 5806 | equate_type_number_to_die (tree type, dw_die_ref type_die) |
3f76745e | 5807 | { |
e2500fed | 5808 | TYPE_SYMTAB_DIE (type) = type_die; |
3f76745e | 5809 | } |
71dfc51f | 5810 | |
636c7bc4 JZ |
5811 | /* Returns a hash value for X (which really is a die_struct). */ |
5812 | ||
5813 | static hashval_t | |
5814 | decl_die_table_hash (const void *x) | |
5815 | { | |
5f754896 | 5816 | return (hashval_t) ((const_dw_die_ref) x)->decl_id; |
636c7bc4 JZ |
5817 | } |
5818 | ||
5819 | /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */ | |
5820 | ||
5821 | static int | |
5822 | decl_die_table_eq (const void *x, const void *y) | |
5823 | { | |
741ac903 | 5824 | return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y)); |
636c7bc4 JZ |
5825 | } |
5826 | ||
3f76745e | 5827 | /* Return the DIE associated with a given declaration. */ |
71dfc51f | 5828 | |
3f76745e | 5829 | static inline dw_die_ref |
7080f735 | 5830 | lookup_decl_die (tree decl) |
3f76745e | 5831 | { |
1b4572a8 | 5832 | return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl)); |
a3f97cbb JW |
5833 | } |
5834 | ||
0a2d3d69 DB |
5835 | /* Returns a hash value for X (which really is a var_loc_list). */ |
5836 | ||
5837 | static hashval_t | |
5838 | decl_loc_table_hash (const void *x) | |
5839 | { | |
5840 | return (hashval_t) ((const var_loc_list *) x)->decl_id; | |
5841 | } | |
5842 | ||
5843 | /* Return nonzero if decl_id of var_loc_list X is the same as | |
5844 | UID of decl *Y. */ | |
5845 | ||
5846 | static int | |
5847 | decl_loc_table_eq (const void *x, const void *y) | |
5848 | { | |
741ac903 | 5849 | return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y)); |
0a2d3d69 DB |
5850 | } |
5851 | ||
5852 | /* Return the var_loc list associated with a given declaration. */ | |
5853 | ||
5854 | static inline var_loc_list * | |
9678086d | 5855 | lookup_decl_loc (const_tree decl) |
0a2d3d69 | 5856 | { |
1b4572a8 KG |
5857 | return (var_loc_list *) |
5858 | htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl)); | |
0a2d3d69 DB |
5859 | } |
5860 | ||
3f76745e | 5861 | /* Equate a DIE to a particular declaration. */ |
71dfc51f | 5862 | |
3f76745e | 5863 | static void |
7080f735 | 5864 | equate_decl_number_to_die (tree decl, dw_die_ref decl_die) |
a3f97cbb | 5865 | { |
aea9695c | 5866 | unsigned int decl_id = DECL_UID (decl); |
636c7bc4 | 5867 | void **slot; |
3f76745e | 5868 | |
636c7bc4 JZ |
5869 | slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT); |
5870 | *slot = decl_die; | |
5871 | decl_die->decl_id = decl_id; | |
a3f97cbb | 5872 | } |
0a2d3d69 DB |
5873 | |
5874 | /* Add a variable location node to the linked list for DECL. */ | |
5875 | ||
5876 | static void | |
5877 | add_var_loc_to_decl (tree decl, struct var_loc_node *loc) | |
5878 | { | |
5879 | unsigned int decl_id = DECL_UID (decl); | |
5880 | var_loc_list *temp; | |
5881 | void **slot; | |
5882 | ||
5883 | slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT); | |
5884 | if (*slot == NULL) | |
5885 | { | |
1b4572a8 | 5886 | temp = GGC_CNEW (var_loc_list); |
0a2d3d69 DB |
5887 | temp->decl_id = decl_id; |
5888 | *slot = temp; | |
5889 | } | |
5890 | else | |
1b4572a8 | 5891 | temp = (var_loc_list *) *slot; |
0a2d3d69 DB |
5892 | |
5893 | if (temp->last) | |
5894 | { | |
5895 | /* If the current location is the same as the end of the list, | |
62760ffd | 5896 | and either both or neither of the locations is uninitialized, |
0a2d3d69 | 5897 | we have nothing to do. */ |
62760ffd CT |
5898 | if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note), |
5899 | NOTE_VAR_LOCATION_LOC (loc->var_loc_note))) | |
5900 | || ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note) | |
5901 | != NOTE_VAR_LOCATION_STATUS (loc->var_loc_note)) | |
5902 | && ((NOTE_VAR_LOCATION_STATUS (temp->last->var_loc_note) | |
5903 | == VAR_INIT_STATUS_UNINITIALIZED) | |
5904 | || (NOTE_VAR_LOCATION_STATUS (loc->var_loc_note) | |
5905 | == VAR_INIT_STATUS_UNINITIALIZED)))) | |
0a2d3d69 DB |
5906 | { |
5907 | /* Add LOC to the end of list and update LAST. */ | |
5908 | temp->last->next = loc; | |
5909 | temp->last = loc; | |
5910 | } | |
5911 | } | |
5912 | /* Do not add empty location to the beginning of the list. */ | |
5913 | else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX) | |
5914 | { | |
5915 | temp->first = loc; | |
5916 | temp->last = loc; | |
5917 | } | |
5918 | } | |
3f76745e JM |
5919 | \f |
5920 | /* Keep track of the number of spaces used to indent the | |
5921 | output of the debugging routines that print the structure of | |
5922 | the DIE internal representation. */ | |
5923 | static int print_indent; | |
71dfc51f | 5924 | |
3f76745e JM |
5925 | /* Indent the line the number of spaces given by print_indent. */ |
5926 | ||
5927 | static inline void | |
7080f735 | 5928 | print_spaces (FILE *outfile) |
3f76745e JM |
5929 | { |
5930 | fprintf (outfile, "%*s", print_indent, ""); | |
a3f97cbb JW |
5931 | } |
5932 | ||
956d6950 | 5933 | /* Print the information associated with a given DIE, and its children. |
3f76745e | 5934 | This routine is a debugging aid only. */ |
71dfc51f | 5935 | |
a3f97cbb | 5936 | static void |
7080f735 | 5937 | print_die (dw_die_ref die, FILE *outfile) |
a3f97cbb | 5938 | { |
b3694847 SS |
5939 | dw_attr_ref a; |
5940 | dw_die_ref c; | |
1a27722f | 5941 | unsigned ix; |
71dfc51f | 5942 | |
3f76745e | 5943 | print_spaces (outfile); |
8d5b1b67 | 5944 | fprintf (outfile, "DIE %4ld: %s\n", |
3f76745e JM |
5945 | die->die_offset, dwarf_tag_name (die->die_tag)); |
5946 | print_spaces (outfile); | |
2d8b0f3a | 5947 | fprintf (outfile, " abbrev id: %lu", die->die_abbrev); |
8d5b1b67 | 5948 | fprintf (outfile, " offset: %ld\n", die->die_offset); |
3f76745e | 5949 | |
1a27722f | 5950 | for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++) |
a3f97cbb | 5951 | { |
3f76745e JM |
5952 | print_spaces (outfile); |
5953 | fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr)); | |
5954 | ||
a96c67ec | 5955 | switch (AT_class (a)) |
3f76745e JM |
5956 | { |
5957 | case dw_val_class_addr: | |
5958 | fprintf (outfile, "address"); | |
5959 | break; | |
a20612aa RH |
5960 | case dw_val_class_offset: |
5961 | fprintf (outfile, "offset"); | |
5962 | break; | |
3f76745e JM |
5963 | case dw_val_class_loc: |
5964 | fprintf (outfile, "location descriptor"); | |
5965 | break; | |
63e46568 | 5966 | case dw_val_class_loc_list: |
a20612aa RH |
5967 | fprintf (outfile, "location list -> label:%s", |
5968 | AT_loc_list (a)->ll_symbol); | |
63e46568 | 5969 | break; |
2bee6045 JJ |
5970 | case dw_val_class_range_list: |
5971 | fprintf (outfile, "range list"); | |
5972 | break; | |
3f76745e | 5973 | case dw_val_class_const: |
38f9cd4c | 5974 | fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a)); |
3f76745e JM |
5975 | break; |
5976 | case dw_val_class_unsigned_const: | |
38f9cd4c | 5977 | fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a)); |
3f76745e JM |
5978 | break; |
5979 | case dw_val_class_long_long: | |
2d8b0f3a | 5980 | fprintf (outfile, "constant (%lu,%lu)", |
556273e0 KH |
5981 | a->dw_attr_val.v.val_long_long.hi, |
5982 | a->dw_attr_val.v.val_long_long.low); | |
3f76745e | 5983 | break; |
e7ee3914 AM |
5984 | case dw_val_class_vec: |
5985 | fprintf (outfile, "floating-point or vector constant"); | |
3f76745e JM |
5986 | break; |
5987 | case dw_val_class_flag: | |
a96c67ec | 5988 | fprintf (outfile, "%u", AT_flag (a)); |
3f76745e JM |
5989 | break; |
5990 | case dw_val_class_die_ref: | |
a96c67ec | 5991 | if (AT_ref (a) != NULL) |
881c6935 | 5992 | { |
1bfb5f8f | 5993 | if (AT_ref (a)->die_symbol) |
881c6935 JM |
5994 | fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol); |
5995 | else | |
8d5b1b67 | 5996 | fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset); |
881c6935 | 5997 | } |
3f76745e JM |
5998 | else |
5999 | fprintf (outfile, "die -> <null>"); | |
6000 | break; | |
6001 | case dw_val_class_lbl_id: | |
192d0f89 GK |
6002 | case dw_val_class_lineptr: |
6003 | case dw_val_class_macptr: | |
a96c67ec | 6004 | fprintf (outfile, "label: %s", AT_lbl (a)); |
3f76745e | 6005 | break; |
3f76745e | 6006 | case dw_val_class_str: |
a96c67ec JM |
6007 | if (AT_string (a) != NULL) |
6008 | fprintf (outfile, "\"%s\"", AT_string (a)); | |
3f76745e JM |
6009 | else |
6010 | fprintf (outfile, "<null>"); | |
6011 | break; | |
d5688810 GK |
6012 | case dw_val_class_file: |
6013 | fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename, | |
6014 | AT_file (a)->emitted_number); | |
6015 | break; | |
e9a25f70 JL |
6016 | default: |
6017 | break; | |
3f76745e JM |
6018 | } |
6019 | ||
6020 | fprintf (outfile, "\n"); | |
6021 | } | |
6022 | ||
6023 | if (die->die_child != NULL) | |
6024 | { | |
6025 | print_indent += 4; | |
d6eeb3ba | 6026 | FOR_EACH_CHILD (die, c, print_die (c, outfile)); |
3f76745e | 6027 | print_indent -= 4; |
a3f97cbb | 6028 | } |
881c6935 JM |
6029 | if (print_indent == 0) |
6030 | fprintf (outfile, "\n"); | |
a3f97cbb JW |
6031 | } |
6032 | ||
3f76745e JM |
6033 | /* Print the contents of the source code line number correspondence table. |
6034 | This routine is a debugging aid only. */ | |
71dfc51f | 6035 | |
3f76745e | 6036 | static void |
7080f735 | 6037 | print_dwarf_line_table (FILE *outfile) |
a3f97cbb | 6038 | { |
b3694847 SS |
6039 | unsigned i; |
6040 | dw_line_info_ref line_info; | |
3f76745e JM |
6041 | |
6042 | fprintf (outfile, "\n\nDWARF source line information\n"); | |
2ad9852d | 6043 | for (i = 1; i < line_info_table_in_use; i++) |
a3f97cbb | 6044 | { |
3f76745e | 6045 | line_info = &line_info_table[i]; |
d5688810 GK |
6046 | fprintf (outfile, "%5d: %4ld %6ld\n", i, |
6047 | line_info->dw_file_num, | |
6048 | line_info->dw_line_num); | |
a3f97cbb | 6049 | } |
3f76745e JM |
6050 | |
6051 | fprintf (outfile, "\n\n"); | |
f37230f0 JM |
6052 | } |
6053 | ||
3f76745e JM |
6054 | /* Print the information collected for a given DIE. */ |
6055 | ||
6056 | void | |
7080f735 | 6057 | debug_dwarf_die (dw_die_ref die) |
3f76745e JM |
6058 | { |
6059 | print_die (die, stderr); | |
6060 | } | |
6061 | ||
6062 | /* Print all DWARF information collected for the compilation unit. | |
6063 | This routine is a debugging aid only. */ | |
6064 | ||
6065 | void | |
7080f735 | 6066 | debug_dwarf (void) |
3f76745e JM |
6067 | { |
6068 | print_indent = 0; | |
6069 | print_die (comp_unit_die, stderr); | |
b2244e22 JW |
6070 | if (! DWARF2_ASM_LINE_DEBUG_INFO) |
6071 | print_dwarf_line_table (stderr); | |
3f76745e JM |
6072 | } |
6073 | \f | |
2ad9852d RK |
6074 | /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU |
6075 | for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL | |
6076 | DIE that marks the start of the DIEs for this include file. */ | |
881c6935 JM |
6077 | |
6078 | static dw_die_ref | |
7080f735 | 6079 | push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die) |
881c6935 JM |
6080 | { |
6081 | const char *filename = get_AT_string (bincl_die, DW_AT_name); | |
6082 | dw_die_ref new_unit = gen_compile_unit_die (filename); | |
2ad9852d | 6083 | |
881c6935 JM |
6084 | new_unit->die_sib = old_unit; |
6085 | return new_unit; | |
6086 | } | |
6087 | ||
6088 | /* Close an include-file CU and reopen the enclosing one. */ | |
6089 | ||
6090 | static dw_die_ref | |
7080f735 | 6091 | pop_compile_unit (dw_die_ref old_unit) |
881c6935 JM |
6092 | { |
6093 | dw_die_ref new_unit = old_unit->die_sib; | |
2ad9852d | 6094 | |
881c6935 JM |
6095 | old_unit->die_sib = NULL; |
6096 | return new_unit; | |
6097 | } | |
6098 | ||
2ad9852d RK |
6099 | #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx) |
6100 | #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx) | |
881c6935 JM |
6101 | |
6102 | /* Calculate the checksum of a location expression. */ | |
6103 | ||
6104 | static inline void | |
7080f735 | 6105 | loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx) |
881c6935 | 6106 | { |
2ad9852d RK |
6107 | CHECKSUM (loc->dw_loc_opc); |
6108 | CHECKSUM (loc->dw_loc_oprnd1); | |
6109 | CHECKSUM (loc->dw_loc_oprnd2); | |
881c6935 JM |
6110 | } |
6111 | ||
6112 | /* Calculate the checksum of an attribute. */ | |
6113 | ||
6114 | static void | |
7080f735 | 6115 | attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark) |
881c6935 JM |
6116 | { |
6117 | dw_loc_descr_ref loc; | |
6118 | rtx r; | |
6119 | ||
2ad9852d | 6120 | CHECKSUM (at->dw_attr); |
881c6935 | 6121 | |
d5688810 GK |
6122 | /* We don't care that this was compiled with a different compiler |
6123 | snapshot; if the output is the same, that's what matters. */ | |
6124 | if (at->dw_attr == DW_AT_producer) | |
881c6935 JM |
6125 | return; |
6126 | ||
6127 | switch (AT_class (at)) | |
6128 | { | |
6129 | case dw_val_class_const: | |
2ad9852d | 6130 | CHECKSUM (at->dw_attr_val.v.val_int); |
881c6935 JM |
6131 | break; |
6132 | case dw_val_class_unsigned_const: | |
2ad9852d | 6133 | CHECKSUM (at->dw_attr_val.v.val_unsigned); |
881c6935 JM |
6134 | break; |
6135 | case dw_val_class_long_long: | |
2ad9852d | 6136 | CHECKSUM (at->dw_attr_val.v.val_long_long); |
881c6935 | 6137 | break; |
e7ee3914 AM |
6138 | case dw_val_class_vec: |
6139 | CHECKSUM (at->dw_attr_val.v.val_vec); | |
881c6935 JM |
6140 | break; |
6141 | case dw_val_class_flag: | |
2ad9852d | 6142 | CHECKSUM (at->dw_attr_val.v.val_flag); |
881c6935 | 6143 | break; |
881c6935 | 6144 | case dw_val_class_str: |
2ad9852d | 6145 | CHECKSUM_STRING (AT_string (at)); |
881c6935 | 6146 | break; |
a20612aa | 6147 | |
881c6935 JM |
6148 | case dw_val_class_addr: |
6149 | r = AT_addr (at); | |
ced3f397 NS |
6150 | gcc_assert (GET_CODE (r) == SYMBOL_REF); |
6151 | CHECKSUM_STRING (XSTR (r, 0)); | |
881c6935 JM |
6152 | break; |
6153 | ||
a20612aa | 6154 | case dw_val_class_offset: |
2ad9852d | 6155 | CHECKSUM (at->dw_attr_val.v.val_offset); |
a20612aa RH |
6156 | break; |
6157 | ||
881c6935 JM |
6158 | case dw_val_class_loc: |
6159 | for (loc = AT_loc (at); loc; loc = loc->dw_loc_next) | |
6160 | loc_checksum (loc, ctx); | |
6161 | break; | |
6162 | ||
6163 | case dw_val_class_die_ref: | |
cc0017a9 ZD |
6164 | die_checksum (AT_ref (at), ctx, mark); |
6165 | break; | |
881c6935 JM |
6166 | |
6167 | case dw_val_class_fde_ref: | |
6168 | case dw_val_class_lbl_id: | |
192d0f89 GK |
6169 | case dw_val_class_lineptr: |
6170 | case dw_val_class_macptr: | |
a20612aa | 6171 | break; |
881c6935 | 6172 | |
d5688810 GK |
6173 | case dw_val_class_file: |
6174 | CHECKSUM_STRING (AT_file (at)->filename); | |
6175 | break; | |
6176 | ||
881c6935 JM |
6177 | default: |
6178 | break; | |
6179 | } | |
6180 | } | |
6181 | ||
6182 | /* Calculate the checksum of a DIE. */ | |
6183 | ||
6184 | static void | |
7080f735 | 6185 | die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark) |
881c6935 JM |
6186 | { |
6187 | dw_die_ref c; | |
6188 | dw_attr_ref a; | |
1a27722f | 6189 | unsigned ix; |
881c6935 | 6190 | |
cc0017a9 ZD |
6191 | /* To avoid infinite recursion. */ |
6192 | if (die->die_mark) | |
6193 | { | |
6194 | CHECKSUM (die->die_mark); | |
6195 | return; | |
6196 | } | |
6197 | die->die_mark = ++(*mark); | |
6198 | ||
2ad9852d | 6199 | CHECKSUM (die->die_tag); |
881c6935 | 6200 | |
1a27722f | 6201 | for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++) |
cc0017a9 | 6202 | attr_checksum (a, ctx, mark); |
881c6935 | 6203 | |
d6eeb3ba | 6204 | FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark)); |
881c6935 JM |
6205 | } |
6206 | ||
2ad9852d RK |
6207 | #undef CHECKSUM |
6208 | #undef CHECKSUM_STRING | |
881c6935 | 6209 | |
cc0017a9 ZD |
6210 | /* Do the location expressions look same? */ |
6211 | static inline int | |
7080f735 | 6212 | same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark) |
cc0017a9 ZD |
6213 | { |
6214 | return loc1->dw_loc_opc == loc2->dw_loc_opc | |
6215 | && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark) | |
6216 | && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark); | |
6217 | } | |
6218 | ||
6219 | /* Do the values look the same? */ | |
6220 | static int | |
9678086d | 6221 | same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark) |
cc0017a9 ZD |
6222 | { |
6223 | dw_loc_descr_ref loc1, loc2; | |
6224 | rtx r1, r2; | |
cc0017a9 ZD |
6225 | |
6226 | if (v1->val_class != v2->val_class) | |
6227 | return 0; | |
6228 | ||
6229 | switch (v1->val_class) | |
6230 | { | |
6231 | case dw_val_class_const: | |
6232 | return v1->v.val_int == v2->v.val_int; | |
6233 | case dw_val_class_unsigned_const: | |
6234 | return v1->v.val_unsigned == v2->v.val_unsigned; | |
6235 | case dw_val_class_long_long: | |
6236 | return v1->v.val_long_long.hi == v2->v.val_long_long.hi | |
73c68f61 | 6237 | && v1->v.val_long_long.low == v2->v.val_long_long.low; |
e7ee3914 AM |
6238 | case dw_val_class_vec: |
6239 | if (v1->v.val_vec.length != v2->v.val_vec.length | |
6240 | || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size) | |
6241 | return 0; | |
6242 | if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array, | |
6243 | v1->v.val_vec.length * v1->v.val_vec.elt_size)) | |
cc0017a9 | 6244 | return 0; |
cc0017a9 ZD |
6245 | return 1; |
6246 | case dw_val_class_flag: | |
6247 | return v1->v.val_flag == v2->v.val_flag; | |
6248 | case dw_val_class_str: | |
17211ab5 | 6249 | return !strcmp(v1->v.val_str->str, v2->v.val_str->str); |
cc0017a9 ZD |
6250 | |
6251 | case dw_val_class_addr: | |
6252 | r1 = v1->v.val_addr; | |
6253 | r2 = v2->v.val_addr; | |
6254 | if (GET_CODE (r1) != GET_CODE (r2)) | |
6255 | return 0; | |
ced3f397 NS |
6256 | gcc_assert (GET_CODE (r1) == SYMBOL_REF); |
6257 | return !strcmp (XSTR (r1, 0), XSTR (r2, 0)); | |
cc0017a9 ZD |
6258 | |
6259 | case dw_val_class_offset: | |
6260 | return v1->v.val_offset == v2->v.val_offset; | |
6261 | ||
6262 | case dw_val_class_loc: | |
6263 | for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc; | |
6264 | loc1 && loc2; | |
6265 | loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next) | |
6266 | if (!same_loc_p (loc1, loc2, mark)) | |
6267 | return 0; | |
6268 | return !loc1 && !loc2; | |
6269 | ||
6270 | case dw_val_class_die_ref: | |
6271 | return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark); | |
6272 | ||
6273 | case dw_val_class_fde_ref: | |
6274 | case dw_val_class_lbl_id: | |
192d0f89 GK |
6275 | case dw_val_class_lineptr: |
6276 | case dw_val_class_macptr: | |
cc0017a9 ZD |
6277 | return 1; |
6278 | ||
d5688810 GK |
6279 | case dw_val_class_file: |
6280 | return v1->v.val_file == v2->v.val_file; | |
6281 | ||
cc0017a9 ZD |
6282 | default: |
6283 | return 1; | |
6284 | } | |
6285 | } | |
6286 | ||
6287 | /* Do the attributes look the same? */ | |
6288 | ||
6289 | static int | |
7080f735 | 6290 | same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark) |
cc0017a9 ZD |
6291 | { |
6292 | if (at1->dw_attr != at2->dw_attr) | |
6293 | return 0; | |
6294 | ||
d5688810 GK |
6295 | /* We don't care that this was compiled with a different compiler |
6296 | snapshot; if the output is the same, that's what matters. */ | |
6297 | if (at1->dw_attr == DW_AT_producer) | |
cc0017a9 ZD |
6298 | return 1; |
6299 | ||
6300 | return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark); | |
6301 | } | |
6302 | ||
6303 | /* Do the dies look the same? */ | |
6304 | ||
6305 | static int | |
7080f735 | 6306 | same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark) |
cc0017a9 ZD |
6307 | { |
6308 | dw_die_ref c1, c2; | |
1a27722f GK |
6309 | dw_attr_ref a1; |
6310 | unsigned ix; | |
cc0017a9 ZD |
6311 | |
6312 | /* To avoid infinite recursion. */ | |
6313 | if (die1->die_mark) | |
6314 | return die1->die_mark == die2->die_mark; | |
6315 | die1->die_mark = die2->die_mark = ++(*mark); | |
6316 | ||
6317 | if (die1->die_tag != die2->die_tag) | |
6318 | return 0; | |
6319 | ||
1a27722f GK |
6320 | if (VEC_length (dw_attr_node, die1->die_attr) |
6321 | != VEC_length (dw_attr_node, die2->die_attr)) | |
cc0017a9 | 6322 | return 0; |
2878ea73 | 6323 | |
1a27722f GK |
6324 | for (ix = 0; VEC_iterate (dw_attr_node, die1->die_attr, ix, a1); ix++) |
6325 | if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark)) | |
6326 | return 0; | |
cc0017a9 | 6327 | |
d6eeb3ba GK |
6328 | c1 = die1->die_child; |
6329 | c2 = die2->die_child; | |
6330 | if (! c1) | |
6331 | { | |
6332 | if (c2) | |
6333 | return 0; | |
6334 | } | |
6335 | else | |
6336 | for (;;) | |
6337 | { | |
6338 | if (!same_die_p (c1, c2, mark)) | |
6339 | return 0; | |
6340 | c1 = c1->die_sib; | |
6341 | c2 = c2->die_sib; | |
6342 | if (c1 == die1->die_child) | |
6343 | { | |
6344 | if (c2 == die2->die_child) | |
6345 | break; | |
6346 | else | |
6347 | return 0; | |
6348 | } | |
6349 | } | |
cc0017a9 ZD |
6350 | |
6351 | return 1; | |
6352 | } | |
6353 | ||
6354 | /* Do the dies look the same? Wrapper around same_die_p. */ | |
6355 | ||
6356 | static int | |
7080f735 | 6357 | same_die_p_wrap (dw_die_ref die1, dw_die_ref die2) |
cc0017a9 ZD |
6358 | { |
6359 | int mark = 0; | |
6360 | int ret = same_die_p (die1, die2, &mark); | |
6361 | ||
6362 | unmark_all_dies (die1); | |
6363 | unmark_all_dies (die2); | |
6364 | ||
6365 | return ret; | |
6366 | } | |
6367 | ||
881c6935 JM |
6368 | /* The prefix to attach to symbols on DIEs in the current comdat debug |
6369 | info section. */ | |
6370 | static char *comdat_symbol_id; | |
6371 | ||
6372 | /* The index of the current symbol within the current comdat CU. */ | |
6373 | static unsigned int comdat_symbol_number; | |
6374 | ||
6375 | /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its | |
6376 | children, and set comdat_symbol_id accordingly. */ | |
6377 | ||
6378 | static void | |
7080f735 | 6379 | compute_section_prefix (dw_die_ref unit_die) |
881c6935 | 6380 | { |
cc0017a9 ZD |
6381 | const char *die_name = get_AT_string (unit_die, DW_AT_name); |
6382 | const char *base = die_name ? lbasename (die_name) : "anonymous"; | |
1b4572a8 | 6383 | char *name = XALLOCAVEC (char, strlen (base) + 64); |
f11c3043 | 6384 | char *p; |
cc0017a9 | 6385 | int i, mark; |
881c6935 JM |
6386 | unsigned char checksum[16]; |
6387 | struct md5_ctx ctx; | |
6388 | ||
f11c3043 RK |
6389 | /* Compute the checksum of the DIE, then append part of it as hex digits to |
6390 | the name filename of the unit. */ | |
6391 | ||
881c6935 | 6392 | md5_init_ctx (&ctx); |
cc0017a9 ZD |
6393 | mark = 0; |
6394 | die_checksum (unit_die, &ctx, &mark); | |
6395 | unmark_all_dies (unit_die); | |
881c6935 JM |
6396 | md5_finish_ctx (&ctx, checksum); |
6397 | ||
0023400b | 6398 | sprintf (name, "%s.", base); |
881c6935 JM |
6399 | clean_symbol_name (name); |
6400 | ||
2ad9852d RK |
6401 | p = name + strlen (name); |
6402 | for (i = 0; i < 4; i++) | |
6403 | { | |
6404 | sprintf (p, "%.2x", checksum[i]); | |
6405 | p += 2; | |
6406 | } | |
881c6935 JM |
6407 | |
6408 | comdat_symbol_id = unit_die->die_symbol = xstrdup (name); | |
6409 | comdat_symbol_number = 0; | |
6410 | } | |
6411 | ||
f11c3043 | 6412 | /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */ |
881c6935 JM |
6413 | |
6414 | static int | |
7080f735 | 6415 | is_type_die (dw_die_ref die) |
881c6935 JM |
6416 | { |
6417 | switch (die->die_tag) | |
6418 | { | |
6419 | case DW_TAG_array_type: | |
6420 | case DW_TAG_class_type: | |
394d9fe7 | 6421 | case DW_TAG_interface_type: |
881c6935 JM |
6422 | case DW_TAG_enumeration_type: |
6423 | case DW_TAG_pointer_type: | |
6424 | case DW_TAG_reference_type: | |
6425 | case DW_TAG_string_type: | |
6426 | case DW_TAG_structure_type: | |
6427 | case DW_TAG_subroutine_type: | |
6428 | case DW_TAG_union_type: | |
6429 | case DW_TAG_ptr_to_member_type: | |
6430 | case DW_TAG_set_type: | |
6431 | case DW_TAG_subrange_type: | |
6432 | case DW_TAG_base_type: | |
6433 | case DW_TAG_const_type: | |
6434 | case DW_TAG_file_type: | |
6435 | case DW_TAG_packed_type: | |
6436 | case DW_TAG_volatile_type: | |
cc0017a9 | 6437 | case DW_TAG_typedef: |
881c6935 JM |
6438 | return 1; |
6439 | default: | |
6440 | return 0; | |
6441 | } | |
6442 | } | |
6443 | ||
6444 | /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU. | |
6445 | Basically, we want to choose the bits that are likely to be shared between | |
6446 | compilations (types) and leave out the bits that are specific to individual | |
6447 | compilations (functions). */ | |
6448 | ||
6449 | static int | |
7080f735 | 6450 | is_comdat_die (dw_die_ref c) |
881c6935 | 6451 | { |
2ad9852d RK |
6452 | /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as |
6453 | we do for stabs. The advantage is a greater likelihood of sharing between | |
6454 | objects that don't include headers in the same order (and therefore would | |
6455 | put the base types in a different comdat). jason 8/28/00 */ | |
6456 | ||
881c6935 JM |
6457 | if (c->die_tag == DW_TAG_base_type) |
6458 | return 0; | |
6459 | ||
6460 | if (c->die_tag == DW_TAG_pointer_type | |
6461 | || c->die_tag == DW_TAG_reference_type | |
6462 | || c->die_tag == DW_TAG_const_type | |
6463 | || c->die_tag == DW_TAG_volatile_type) | |
6464 | { | |
6465 | dw_die_ref t = get_AT_ref (c, DW_AT_type); | |
2ad9852d | 6466 | |
881c6935 JM |
6467 | return t ? is_comdat_die (t) : 0; |
6468 | } | |
881c6935 JM |
6469 | |
6470 | return is_type_die (c); | |
6471 | } | |
6472 | ||
6473 | /* Returns 1 iff C is the sort of DIE that might be referred to from another | |
6474 | compilation unit. */ | |
6475 | ||
6476 | static int | |
7080f735 | 6477 | is_symbol_die (dw_die_ref c) |
881c6935 | 6478 | { |
2ad9852d | 6479 | return (is_type_die (c) |
c26fbbca | 6480 | || (get_AT (c, DW_AT_declaration) |
ef85ac9a JJ |
6481 | && !get_AT (c, DW_AT_specification)) |
6482 | || c->die_tag == DW_TAG_namespace); | |
881c6935 JM |
6483 | } |
6484 | ||
6485 | static char * | |
7080f735 | 6486 | gen_internal_sym (const char *prefix) |
881c6935 JM |
6487 | { |
6488 | char buf[256]; | |
2ad9852d | 6489 | |
63e46568 | 6490 | ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++); |
881c6935 JM |
6491 | return xstrdup (buf); |
6492 | } | |
6493 | ||
6494 | /* Assign symbols to all worthy DIEs under DIE. */ | |
6495 | ||
6496 | static void | |
7080f735 | 6497 | assign_symbol_names (dw_die_ref die) |
881c6935 | 6498 | { |
b3694847 | 6499 | dw_die_ref c; |
881c6935 JM |
6500 | |
6501 | if (is_symbol_die (die)) | |
6502 | { | |
6503 | if (comdat_symbol_id) | |
6504 | { | |
1b4572a8 | 6505 | char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64); |
2ad9852d | 6506 | |
881c6935 JM |
6507 | sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX, |
6508 | comdat_symbol_id, comdat_symbol_number++); | |
6509 | die->die_symbol = xstrdup (p); | |
6510 | } | |
6511 | else | |
63e46568 | 6512 | die->die_symbol = gen_internal_sym ("LDIE"); |
881c6935 JM |
6513 | } |
6514 | ||
d6eeb3ba | 6515 | FOR_EACH_CHILD (die, c, assign_symbol_names (c)); |
881c6935 JM |
6516 | } |
6517 | ||
cc0017a9 ZD |
6518 | struct cu_hash_table_entry |
6519 | { | |
6520 | dw_die_ref cu; | |
6521 | unsigned min_comdat_num, max_comdat_num; | |
6522 | struct cu_hash_table_entry *next; | |
6523 | }; | |
6524 | ||
6525 | /* Routines to manipulate hash table of CUs. */ | |
6526 | static hashval_t | |
7080f735 | 6527 | htab_cu_hash (const void *of) |
cc0017a9 | 6528 | { |
1b4572a8 KG |
6529 | const struct cu_hash_table_entry *const entry = |
6530 | (const struct cu_hash_table_entry *) of; | |
cc0017a9 ZD |
6531 | |
6532 | return htab_hash_string (entry->cu->die_symbol); | |
6533 | } | |
6534 | ||
6535 | static int | |
7080f735 | 6536 | htab_cu_eq (const void *of1, const void *of2) |
cc0017a9 | 6537 | { |
1b4572a8 KG |
6538 | const struct cu_hash_table_entry *const entry1 = |
6539 | (const struct cu_hash_table_entry *) of1; | |
6540 | const struct die_struct *const entry2 = (const struct die_struct *) of2; | |
cc0017a9 ZD |
6541 | |
6542 | return !strcmp (entry1->cu->die_symbol, entry2->die_symbol); | |
6543 | } | |
6544 | ||
6545 | static void | |
7080f735 | 6546 | htab_cu_del (void *what) |
cc0017a9 | 6547 | { |
1b4572a8 KG |
6548 | struct cu_hash_table_entry *next, |
6549 | *entry = (struct cu_hash_table_entry *) what; | |
cc0017a9 ZD |
6550 | |
6551 | while (entry) | |
6552 | { | |
6553 | next = entry->next; | |
6554 | free (entry); | |
6555 | entry = next; | |
6556 | } | |
6557 | } | |
6558 | ||
6559 | /* Check whether we have already seen this CU and set up SYM_NUM | |
6560 | accordingly. */ | |
6561 | static int | |
7080f735 | 6562 | check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num) |
cc0017a9 ZD |
6563 | { |
6564 | struct cu_hash_table_entry dummy; | |
6565 | struct cu_hash_table_entry **slot, *entry, *last = &dummy; | |
6566 | ||
6567 | dummy.max_comdat_num = 0; | |
6568 | ||
6569 | slot = (struct cu_hash_table_entry **) | |
6570 | htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol), | |
6571 | INSERT); | |
6572 | entry = *slot; | |
6573 | ||
6574 | for (; entry; last = entry, entry = entry->next) | |
6575 | { | |
6576 | if (same_die_p_wrap (cu, entry->cu)) | |
6577 | break; | |
6578 | } | |
6579 | ||
6580 | if (entry) | |
6581 | { | |
6582 | *sym_num = entry->min_comdat_num; | |
6583 | return 1; | |
6584 | } | |
6585 | ||
5ed6ace5 | 6586 | entry = XCNEW (struct cu_hash_table_entry); |
cc0017a9 ZD |
6587 | entry->cu = cu; |
6588 | entry->min_comdat_num = *sym_num = last->max_comdat_num; | |
6589 | entry->next = *slot; | |
6590 | *slot = entry; | |
6591 | ||
6592 | return 0; | |
6593 | } | |
6594 | ||
6595 | /* Record SYM_NUM to record of CU in HTABLE. */ | |
6596 | static void | |
7080f735 | 6597 | record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num) |
cc0017a9 ZD |
6598 | { |
6599 | struct cu_hash_table_entry **slot, *entry; | |
6600 | ||
6601 | slot = (struct cu_hash_table_entry **) | |
6602 | htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol), | |
6603 | NO_INSERT); | |
6604 | entry = *slot; | |
6605 | ||
6606 | entry->max_comdat_num = sym_num; | |
6607 | } | |
6608 | ||
881c6935 JM |
6609 | /* Traverse the DIE (which is always comp_unit_die), and set up |
6610 | additional compilation units for each of the include files we see | |
6611 | bracketed by BINCL/EINCL. */ | |
6612 | ||
6613 | static void | |
7080f735 | 6614 | break_out_includes (dw_die_ref die) |
881c6935 | 6615 | { |
d6eeb3ba | 6616 | dw_die_ref c; |
b3694847 | 6617 | dw_die_ref unit = NULL; |
cc0017a9 ZD |
6618 | limbo_die_node *node, **pnode; |
6619 | htab_t cu_hash_table; | |
881c6935 | 6620 | |
d6eeb3ba GK |
6621 | c = die->die_child; |
6622 | if (c) do { | |
6623 | dw_die_ref prev = c; | |
6624 | c = c->die_sib; | |
6625 | while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL | |
6626 | || (unit && is_comdat_die (c))) | |
6627 | { | |
6628 | dw_die_ref next = c->die_sib; | |
6629 | ||
6630 | /* This DIE is for a secondary CU; remove it from the main one. */ | |
6631 | remove_child_with_prev (c, prev); | |
2878ea73 | 6632 | |
d6eeb3ba GK |
6633 | if (c->die_tag == DW_TAG_GNU_BINCL) |
6634 | unit = push_new_compile_unit (unit, c); | |
6635 | else if (c->die_tag == DW_TAG_GNU_EINCL) | |
6636 | unit = pop_compile_unit (unit); | |
6637 | else | |
6638 | add_child_die (unit, c); | |
6639 | c = next; | |
6640 | if (c == die->die_child) | |
6641 | break; | |
6642 | } | |
6643 | } while (c != die->die_child); | |
881c6935 JM |
6644 | |
6645 | #if 0 | |
6646 | /* We can only use this in debugging, since the frontend doesn't check | |
0b34cf1e | 6647 | to make sure that we leave every include file we enter. */ |
ced3f397 | 6648 | gcc_assert (!unit); |
881c6935 JM |
6649 | #endif |
6650 | ||
6651 | assign_symbol_names (die); | |
cc0017a9 ZD |
6652 | cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del); |
6653 | for (node = limbo_die_list, pnode = &limbo_die_list; | |
6654 | node; | |
6655 | node = node->next) | |
881c6935 | 6656 | { |
cc0017a9 ZD |
6657 | int is_dupl; |
6658 | ||
881c6935 | 6659 | compute_section_prefix (node->die); |
cc0017a9 ZD |
6660 | is_dupl = check_duplicate_cu (node->die, cu_hash_table, |
6661 | &comdat_symbol_number); | |
881c6935 | 6662 | assign_symbol_names (node->die); |
cc0017a9 ZD |
6663 | if (is_dupl) |
6664 | *pnode = node->next; | |
6665 | else | |
73c68f61 | 6666 | { |
cc0017a9 ZD |
6667 | pnode = &node->next; |
6668 | record_comdat_symbol_number (node->die, cu_hash_table, | |
6669 | comdat_symbol_number); | |
6670 | } | |
881c6935 | 6671 | } |
cc0017a9 | 6672 | htab_delete (cu_hash_table); |
881c6935 JM |
6673 | } |
6674 | ||
6675 | /* Traverse the DIE and add a sibling attribute if it may have the | |
6676 | effect of speeding up access to siblings. To save some space, | |
6677 | avoid generating sibling attributes for DIE's without children. */ | |
6678 | ||
6679 | static void | |
7080f735 | 6680 | add_sibling_attributes (dw_die_ref die) |
881c6935 | 6681 | { |
b3694847 | 6682 | dw_die_ref c; |
881c6935 | 6683 | |
d6eeb3ba GK |
6684 | if (! die->die_child) |
6685 | return; | |
6686 | ||
6687 | if (die->die_parent && die != die->die_parent->die_child) | |
7d9d8943 AM |
6688 | add_AT_die_ref (die, DW_AT_sibling, die->die_sib); |
6689 | ||
d6eeb3ba | 6690 | FOR_EACH_CHILD (die, c, add_sibling_attributes (c)); |
7d9d8943 AM |
6691 | } |
6692 | ||
2ad9852d RK |
6693 | /* Output all location lists for the DIE and its children. */ |
6694 | ||
63e46568 | 6695 | static void |
7080f735 | 6696 | output_location_lists (dw_die_ref die) |
63e46568 DB |
6697 | { |
6698 | dw_die_ref c; | |
1a27722f GK |
6699 | dw_attr_ref a; |
6700 | unsigned ix; | |
2ad9852d | 6701 | |
1a27722f GK |
6702 | for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++) |
6703 | if (AT_class (a) == dw_val_class_loc_list) | |
6704 | output_loc_list (AT_loc_list (a)); | |
2ad9852d | 6705 | |
d6eeb3ba | 6706 | FOR_EACH_CHILD (die, c, output_location_lists (c)); |
63e46568 | 6707 | } |
c26fbbca | 6708 | |
2ad9852d RK |
6709 | /* The format of each DIE (and its attribute value pairs) is encoded in an |
6710 | abbreviation table. This routine builds the abbreviation table and assigns | |
6711 | a unique abbreviation id for each abbreviation entry. The children of each | |
6712 | die are visited recursively. */ | |
7d9d8943 AM |
6713 | |
6714 | static void | |
7080f735 | 6715 | build_abbrev_table (dw_die_ref die) |
7d9d8943 | 6716 | { |
b3694847 SS |
6717 | unsigned long abbrev_id; |
6718 | unsigned int n_alloc; | |
6719 | dw_die_ref c; | |
1a27722f GK |
6720 | dw_attr_ref a; |
6721 | unsigned ix; | |
881c6935 JM |
6722 | |
6723 | /* Scan the DIE references, and mark as external any that refer to | |
1bfb5f8f | 6724 | DIEs from other CUs (i.e. those which are not marked). */ |
1a27722f GK |
6725 | for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++) |
6726 | if (AT_class (a) == dw_val_class_die_ref | |
6727 | && AT_ref (a)->die_mark == 0) | |
2ad9852d | 6728 | { |
1a27722f | 6729 | gcc_assert (AT_ref (a)->die_symbol); |
2ad9852d | 6730 | |
1a27722f | 6731 | set_AT_ref_external (a, 1); |
2ad9852d | 6732 | } |
881c6935 | 6733 | |
7d9d8943 AM |
6734 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
6735 | { | |
b3694847 | 6736 | dw_die_ref abbrev = abbrev_die_table[abbrev_id]; |
1a27722f GK |
6737 | dw_attr_ref die_a, abbrev_a; |
6738 | unsigned ix; | |
6739 | bool ok = true; | |
2878ea73 | 6740 | |
1a27722f GK |
6741 | if (abbrev->die_tag != die->die_tag) |
6742 | continue; | |
6743 | if ((abbrev->die_child != NULL) != (die->die_child != NULL)) | |
6744 | continue; | |
2878ea73 | 6745 | |
1a27722f GK |
6746 | if (VEC_length (dw_attr_node, abbrev->die_attr) |
6747 | != VEC_length (dw_attr_node, die->die_attr)) | |
6748 | continue; | |
2878ea73 | 6749 | |
1a27722f | 6750 | for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, die_a); ix++) |
7d9d8943 | 6751 | { |
1a27722f GK |
6752 | abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix); |
6753 | if ((abbrev_a->dw_attr != die_a->dw_attr) | |
6754 | || (value_format (abbrev_a) != value_format (die_a))) | |
7d9d8943 | 6755 | { |
1a27722f GK |
6756 | ok = false; |
6757 | break; | |
7d9d8943 AM |
6758 | } |
6759 | } | |
1a27722f GK |
6760 | if (ok) |
6761 | break; | |
7d9d8943 AM |
6762 | } |
6763 | ||
6764 | if (abbrev_id >= abbrev_die_table_in_use) | |
6765 | { | |
6766 | if (abbrev_die_table_in_use >= abbrev_die_table_allocated) | |
6767 | { | |
6768 | n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT; | |
1b4572a8 KG |
6769 | abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table, |
6770 | n_alloc); | |
7d9d8943 | 6771 | |
703ad42b | 6772 | memset (&abbrev_die_table[abbrev_die_table_allocated], 0, |
7d9d8943 AM |
6773 | (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref)); |
6774 | abbrev_die_table_allocated = n_alloc; | |
6775 | } | |
6776 | ||
6777 | ++abbrev_die_table_in_use; | |
6778 | abbrev_die_table[abbrev_id] = die; | |
6779 | } | |
6780 | ||
6781 | die->die_abbrev = abbrev_id; | |
d6eeb3ba | 6782 | FOR_EACH_CHILD (die, c, build_abbrev_table (c)); |
7d9d8943 AM |
6783 | } |
6784 | \f | |
3f76745e JM |
6785 | /* Return the power-of-two number of bytes necessary to represent VALUE. */ |
6786 | ||
6787 | static int | |
7080f735 | 6788 | constant_size (long unsigned int value) |
3f76745e JM |
6789 | { |
6790 | int log; | |
6791 | ||
6792 | if (value == 0) | |
6793 | log = 0; | |
a3f97cbb | 6794 | else |
3f76745e | 6795 | log = floor_log2 (value); |
71dfc51f | 6796 | |
3f76745e JM |
6797 | log = log / 8; |
6798 | log = 1 << (floor_log2 (log) + 1); | |
6799 | ||
6800 | return log; | |
a3f97cbb JW |
6801 | } |
6802 | ||
2ad9852d | 6803 | /* Return the size of a DIE as it is represented in the |
3f76745e | 6804 | .debug_info section. */ |
71dfc51f | 6805 | |
3f76745e | 6806 | static unsigned long |
7080f735 | 6807 | size_of_die (dw_die_ref die) |
a3f97cbb | 6808 | { |
b3694847 SS |
6809 | unsigned long size = 0; |
6810 | dw_attr_ref a; | |
1a27722f | 6811 | unsigned ix; |
71dfc51f | 6812 | |
3f76745e | 6813 | size += size_of_uleb128 (die->die_abbrev); |
1a27722f | 6814 | for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++) |
a3f97cbb | 6815 | { |
a96c67ec | 6816 | switch (AT_class (a)) |
a3f97cbb JW |
6817 | { |
6818 | case dw_val_class_addr: | |
a1a4189d | 6819 | size += DWARF2_ADDR_SIZE; |
a3f97cbb | 6820 | break; |
a20612aa RH |
6821 | case dw_val_class_offset: |
6822 | size += DWARF_OFFSET_SIZE; | |
6823 | break; | |
a3f97cbb | 6824 | case dw_val_class_loc: |
3f76745e | 6825 | { |
b3694847 | 6826 | unsigned long lsize = size_of_locs (AT_loc (a)); |
71dfc51f | 6827 | |
3f76745e JM |
6828 | /* Block length. */ |
6829 | size += constant_size (lsize); | |
6830 | size += lsize; | |
6831 | } | |
a3f97cbb | 6832 | break; |
63e46568 DB |
6833 | case dw_val_class_loc_list: |
6834 | size += DWARF_OFFSET_SIZE; | |
6835 | break; | |
2bee6045 JJ |
6836 | case dw_val_class_range_list: |
6837 | size += DWARF_OFFSET_SIZE; | |
6838 | break; | |
a3f97cbb | 6839 | case dw_val_class_const: |
25dd13ec | 6840 | size += size_of_sleb128 (AT_int (a)); |
a3f97cbb JW |
6841 | break; |
6842 | case dw_val_class_unsigned_const: | |
a96c67ec | 6843 | size += constant_size (AT_unsigned (a)); |
a3f97cbb | 6844 | break; |
469ac993 | 6845 | case dw_val_class_long_long: |
2e4b9b8c | 6846 | size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */ |
469ac993 | 6847 | break; |
e7ee3914 AM |
6848 | case dw_val_class_vec: |
6849 | size += 1 + (a->dw_attr_val.v.val_vec.length | |
6850 | * a->dw_attr_val.v.val_vec.elt_size); /* block */ | |
a3f97cbb JW |
6851 | break; |
6852 | case dw_val_class_flag: | |
3f76745e | 6853 | size += 1; |
a3f97cbb JW |
6854 | break; |
6855 | case dw_val_class_die_ref: | |
323658ea ZD |
6856 | if (AT_ref_external (a)) |
6857 | size += DWARF2_ADDR_SIZE; | |
6858 | else | |
6859 | size += DWARF_OFFSET_SIZE; | |
a3f97cbb JW |
6860 | break; |
6861 | case dw_val_class_fde_ref: | |
3f76745e | 6862 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
6863 | break; |
6864 | case dw_val_class_lbl_id: | |
a1a4189d | 6865 | size += DWARF2_ADDR_SIZE; |
3f76745e | 6866 | break; |
192d0f89 GK |
6867 | case dw_val_class_lineptr: |
6868 | case dw_val_class_macptr: | |
3f76745e JM |
6869 | size += DWARF_OFFSET_SIZE; |
6870 | break; | |
6871 | case dw_val_class_str: | |
9eb4015a JJ |
6872 | if (AT_string_form (a) == DW_FORM_strp) |
6873 | size += DWARF_OFFSET_SIZE; | |
6874 | else | |
17211ab5 | 6875 | size += strlen (a->dw_attr_val.v.val_str->str) + 1; |
3f76745e | 6876 | break; |
d5688810 GK |
6877 | case dw_val_class_file: |
6878 | size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)); | |
6879 | break; | |
3f76745e | 6880 | default: |
ced3f397 | 6881 | gcc_unreachable (); |
3f76745e | 6882 | } |
a3f97cbb | 6883 | } |
3f76745e JM |
6884 | |
6885 | return size; | |
a3f97cbb JW |
6886 | } |
6887 | ||
2ad9852d RK |
6888 | /* Size the debugging information associated with a given DIE. Visits the |
6889 | DIE's children recursively. Updates the global variable next_die_offset, on | |
6890 | each time through. Uses the current value of next_die_offset to update the | |
6891 | die_offset field in each DIE. */ | |
71dfc51f | 6892 | |
a3f97cbb | 6893 | static void |
7080f735 | 6894 | calc_die_sizes (dw_die_ref die) |
a3f97cbb | 6895 | { |
b3694847 | 6896 | dw_die_ref c; |
2ad9852d | 6897 | |
3f76745e JM |
6898 | die->die_offset = next_die_offset; |
6899 | next_die_offset += size_of_die (die); | |
71dfc51f | 6900 | |
d6eeb3ba | 6901 | FOR_EACH_CHILD (die, c, calc_die_sizes (c)); |
71dfc51f | 6902 | |
3f76745e JM |
6903 | if (die->die_child != NULL) |
6904 | /* Count the null byte used to terminate sibling lists. */ | |
6905 | next_die_offset += 1; | |
a3f97cbb JW |
6906 | } |
6907 | ||
1bfb5f8f | 6908 | /* Set the marks for a die and its children. We do this so |
881c6935 | 6909 | that we know whether or not a reference needs to use FORM_ref_addr; only |
1bfb5f8f JM |
6910 | DIEs in the same CU will be marked. We used to clear out the offset |
6911 | and use that as the flag, but ran into ordering problems. */ | |
881c6935 JM |
6912 | |
6913 | static void | |
7080f735 | 6914 | mark_dies (dw_die_ref die) |
881c6935 | 6915 | { |
b3694847 | 6916 | dw_die_ref c; |
2ad9852d | 6917 | |
ced3f397 | 6918 | gcc_assert (!die->die_mark); |
7080f735 | 6919 | |
1bfb5f8f | 6920 | die->die_mark = 1; |
d6eeb3ba | 6921 | FOR_EACH_CHILD (die, c, mark_dies (c)); |
1bfb5f8f JM |
6922 | } |
6923 | ||
6924 | /* Clear the marks for a die and its children. */ | |
6925 | ||
6926 | static void | |
7080f735 | 6927 | unmark_dies (dw_die_ref die) |
1bfb5f8f | 6928 | { |
b3694847 | 6929 | dw_die_ref c; |
2ad9852d | 6930 | |
ced3f397 | 6931 | gcc_assert (die->die_mark); |
7080f735 | 6932 | |
1bfb5f8f | 6933 | die->die_mark = 0; |
d6eeb3ba | 6934 | FOR_EACH_CHILD (die, c, unmark_dies (c)); |
881c6935 JM |
6935 | } |
6936 | ||
cc0017a9 ZD |
6937 | /* Clear the marks for a die, its children and referred dies. */ |
6938 | ||
6939 | static void | |
7080f735 | 6940 | unmark_all_dies (dw_die_ref die) |
cc0017a9 ZD |
6941 | { |
6942 | dw_die_ref c; | |
6943 | dw_attr_ref a; | |
1a27722f | 6944 | unsigned ix; |
cc0017a9 ZD |
6945 | |
6946 | if (!die->die_mark) | |
6947 | return; | |
6948 | die->die_mark = 0; | |
6949 | ||
d6eeb3ba | 6950 | FOR_EACH_CHILD (die, c, unmark_all_dies (c)); |
cc0017a9 | 6951 | |
1a27722f | 6952 | for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++) |
cc0017a9 ZD |
6953 | if (AT_class (a) == dw_val_class_die_ref) |
6954 | unmark_all_dies (AT_ref (a)); | |
6955 | } | |
6956 | ||
2878ea73 | 6957 | /* Return the size of the .debug_pubnames or .debug_pubtypes table |
89708594 | 6958 | generated for the compilation unit. */ |
a94dbf2c | 6959 | |
3f76745e | 6960 | static unsigned long |
89708594 | 6961 | size_of_pubnames (VEC (pubname_entry, gc) * names) |
a94dbf2c | 6962 | { |
b3694847 SS |
6963 | unsigned long size; |
6964 | unsigned i; | |
89708594 | 6965 | pubname_ref p; |
469ac993 | 6966 | |
3f76745e | 6967 | size = DWARF_PUBNAMES_HEADER_SIZE; |
89708594 CT |
6968 | for (i = 0; VEC_iterate (pubname_entry, names, i, p); i++) |
6969 | if (names != pubtype_table | |
6970 | || p->die->die_offset != 0 | |
6971 | || !flag_eliminate_unused_debug_types) | |
6972 | size += strlen (p->name) + DWARF_OFFSET_SIZE + 1; | |
a94dbf2c | 6973 | |
3f76745e JM |
6974 | size += DWARF_OFFSET_SIZE; |
6975 | return size; | |
a94dbf2c JM |
6976 | } |
6977 | ||
956d6950 | 6978 | /* Return the size of the information in the .debug_aranges section. */ |
469ac993 | 6979 | |
3f76745e | 6980 | static unsigned long |
7080f735 | 6981 | size_of_aranges (void) |
469ac993 | 6982 | { |
b3694847 | 6983 | unsigned long size; |
469ac993 | 6984 | |
3f76745e | 6985 | size = DWARF_ARANGES_HEADER_SIZE; |
469ac993 | 6986 | |
3f76745e | 6987 | /* Count the address/length pair for this compilation unit. */ |
9e9f8522 JM |
6988 | if (text_section_used) |
6989 | size += 2 * DWARF2_ADDR_SIZE; | |
6990 | if (cold_text_section_used) | |
6991 | size += 2 * DWARF2_ADDR_SIZE; | |
a1a4189d | 6992 | size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use; |
469ac993 | 6993 | |
3f76745e | 6994 | /* Count the two zero words used to terminated the address range table. */ |
a1a4189d | 6995 | size += 2 * DWARF2_ADDR_SIZE; |
3f76745e JM |
6996 | return size; |
6997 | } | |
6998 | \f | |
6999 | /* Select the encoding of an attribute value. */ | |
7000 | ||
7001 | static enum dwarf_form | |
7080f735 | 7002 | value_format (dw_attr_ref a) |
3f76745e | 7003 | { |
a96c67ec | 7004 | switch (a->dw_attr_val.val_class) |
469ac993 | 7005 | { |
3f76745e JM |
7006 | case dw_val_class_addr: |
7007 | return DW_FORM_addr; | |
2bee6045 | 7008 | case dw_val_class_range_list: |
a20612aa | 7009 | case dw_val_class_offset: |
0c33762a | 7010 | case dw_val_class_loc_list: |
ced3f397 NS |
7011 | switch (DWARF_OFFSET_SIZE) |
7012 | { | |
7013 | case 4: | |
7014 | return DW_FORM_data4; | |
7015 | case 8: | |
7016 | return DW_FORM_data8; | |
7017 | default: | |
7018 | gcc_unreachable (); | |
7019 | } | |
3f76745e | 7020 | case dw_val_class_loc: |
a96c67ec | 7021 | switch (constant_size (size_of_locs (AT_loc (a)))) |
469ac993 | 7022 | { |
3f76745e JM |
7023 | case 1: |
7024 | return DW_FORM_block1; | |
7025 | case 2: | |
7026 | return DW_FORM_block2; | |
469ac993 | 7027 | default: |
ced3f397 | 7028 | gcc_unreachable (); |
469ac993 | 7029 | } |
3f76745e | 7030 | case dw_val_class_const: |
25dd13ec | 7031 | return DW_FORM_sdata; |
3f76745e | 7032 | case dw_val_class_unsigned_const: |
a96c67ec | 7033 | switch (constant_size (AT_unsigned (a))) |
3f76745e JM |
7034 | { |
7035 | case 1: | |
7036 | return DW_FORM_data1; | |
7037 | case 2: | |
7038 | return DW_FORM_data2; | |
7039 | case 4: | |
7040 | return DW_FORM_data4; | |
7041 | case 8: | |
7042 | return DW_FORM_data8; | |
7043 | default: | |
ced3f397 | 7044 | gcc_unreachable (); |
3f76745e JM |
7045 | } |
7046 | case dw_val_class_long_long: | |
7047 | return DW_FORM_block1; | |
e7ee3914 | 7048 | case dw_val_class_vec: |
3f76745e JM |
7049 | return DW_FORM_block1; |
7050 | case dw_val_class_flag: | |
7051 | return DW_FORM_flag; | |
7052 | case dw_val_class_die_ref: | |
881c6935 JM |
7053 | if (AT_ref_external (a)) |
7054 | return DW_FORM_ref_addr; | |
7055 | else | |
7056 | return DW_FORM_ref; | |
3f76745e JM |
7057 | case dw_val_class_fde_ref: |
7058 | return DW_FORM_data; | |
7059 | case dw_val_class_lbl_id: | |
7060 | return DW_FORM_addr; | |
192d0f89 GK |
7061 | case dw_val_class_lineptr: |
7062 | case dw_val_class_macptr: | |
3f76745e JM |
7063 | return DW_FORM_data; |
7064 | case dw_val_class_str: | |
9eb4015a | 7065 | return AT_string_form (a); |
d5688810 GK |
7066 | case dw_val_class_file: |
7067 | switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file))) | |
7068 | { | |
7069 | case 1: | |
7070 | return DW_FORM_data1; | |
7071 | case 2: | |
7072 | return DW_FORM_data2; | |
7073 | case 4: | |
7074 | return DW_FORM_data4; | |
7075 | default: | |
7076 | gcc_unreachable (); | |
7077 | } | |
a20612aa | 7078 | |
469ac993 | 7079 | default: |
ced3f397 | 7080 | gcc_unreachable (); |
469ac993 | 7081 | } |
a94dbf2c JM |
7082 | } |
7083 | ||
3f76745e | 7084 | /* Output the encoding of an attribute value. */ |
469ac993 | 7085 | |
3f76745e | 7086 | static void |
7080f735 | 7087 | output_value_format (dw_attr_ref a) |
a94dbf2c | 7088 | { |
a96c67ec | 7089 | enum dwarf_form form = value_format (a); |
2ad9852d | 7090 | |
2e4b9b8c | 7091 | dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form)); |
3f76745e | 7092 | } |
469ac993 | 7093 | |
3f76745e JM |
7094 | /* Output the .debug_abbrev section which defines the DIE abbreviation |
7095 | table. */ | |
469ac993 | 7096 | |
3f76745e | 7097 | static void |
7080f735 | 7098 | output_abbrev_section (void) |
3f76745e JM |
7099 | { |
7100 | unsigned long abbrev_id; | |
71dfc51f | 7101 | |
3f76745e JM |
7102 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
7103 | { | |
b3694847 | 7104 | dw_die_ref abbrev = abbrev_die_table[abbrev_id]; |
1a27722f GK |
7105 | unsigned ix; |
7106 | dw_attr_ref a_attr; | |
71dfc51f | 7107 | |
2e4b9b8c | 7108 | dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)"); |
2e4b9b8c RH |
7109 | dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)", |
7110 | dwarf_tag_name (abbrev->die_tag)); | |
71dfc51f | 7111 | |
2e4b9b8c RH |
7112 | if (abbrev->die_child != NULL) |
7113 | dw2_asm_output_data (1, DW_children_yes, "DW_children_yes"); | |
7114 | else | |
7115 | dw2_asm_output_data (1, DW_children_no, "DW_children_no"); | |
3f76745e | 7116 | |
1a27722f GK |
7117 | for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr); |
7118 | ix++) | |
3f76745e | 7119 | { |
2e4b9b8c RH |
7120 | dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)", |
7121 | dwarf_attr_name (a_attr->dw_attr)); | |
a96c67ec | 7122 | output_value_format (a_attr); |
469ac993 | 7123 | } |
469ac993 | 7124 | |
2e4b9b8c RH |
7125 | dw2_asm_output_data (1, 0, NULL); |
7126 | dw2_asm_output_data (1, 0, NULL); | |
469ac993 | 7127 | } |
81f374eb HPN |
7128 | |
7129 | /* Terminate the table. */ | |
2e4b9b8c | 7130 | dw2_asm_output_data (1, 0, NULL); |
a94dbf2c JM |
7131 | } |
7132 | ||
881c6935 JM |
7133 | /* Output a symbol we can use to refer to this DIE from another CU. */ |
7134 | ||
7135 | static inline void | |
7080f735 | 7136 | output_die_symbol (dw_die_ref die) |
881c6935 JM |
7137 | { |
7138 | char *sym = die->die_symbol; | |
7139 | ||
7140 | if (sym == 0) | |
7141 | return; | |
7142 | ||
7143 | if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0) | |
7144 | /* We make these global, not weak; if the target doesn't support | |
7145 | .linkonce, it doesn't support combining the sections, so debugging | |
7146 | will break. */ | |
5fd9b178 | 7147 | targetm.asm_out.globalize_label (asm_out_file, sym); |
2ad9852d | 7148 | |
881c6935 JM |
7149 | ASM_OUTPUT_LABEL (asm_out_file, sym); |
7150 | } | |
7151 | ||
84a5b4f8 | 7152 | /* Return a new location list, given the begin and end range, and the |
2ad9852d RK |
7153 | expression. gensym tells us whether to generate a new internal symbol for |
7154 | this location list node, which is done for the head of the list only. */ | |
7155 | ||
84a5b4f8 | 7156 | static inline dw_loc_list_ref |
7080f735 AJ |
7157 | new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end, |
7158 | const char *section, unsigned int gensym) | |
84a5b4f8 | 7159 | { |
1b4572a8 | 7160 | dw_loc_list_ref retlist = GGC_CNEW (dw_loc_list_node); |
2ad9852d | 7161 | |
84a5b4f8 DB |
7162 | retlist->begin = begin; |
7163 | retlist->end = end; | |
7164 | retlist->expr = expr; | |
7165 | retlist->section = section; | |
c26fbbca | 7166 | if (gensym) |
84a5b4f8 | 7167 | retlist->ll_symbol = gen_internal_sym ("LLST"); |
2ad9852d | 7168 | |
84a5b4f8 DB |
7169 | return retlist; |
7170 | } | |
7171 | ||
f9da5064 | 7172 | /* Add a location description expression to a location list. */ |
2ad9852d | 7173 | |
84a5b4f8 | 7174 | static inline void |
7080f735 AJ |
7175 | add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr, |
7176 | const char *begin, const char *end, | |
7177 | const char *section) | |
84a5b4f8 | 7178 | { |
b3694847 | 7179 | dw_loc_list_ref *d; |
c26fbbca | 7180 | |
30f7a378 | 7181 | /* Find the end of the chain. */ |
84a5b4f8 DB |
7182 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) |
7183 | ; | |
2ad9852d | 7184 | |
f9da5064 | 7185 | /* Add a new location list node to the list. */ |
84a5b4f8 DB |
7186 | *d = new_loc_list (descr, begin, end, section, 0); |
7187 | } | |
7188 | ||
f9da5064 | 7189 | /* Output the location list given to us. */ |
2ad9852d | 7190 | |
63e46568 | 7191 | static void |
7080f735 | 7192 | output_loc_list (dw_loc_list_ref list_head) |
63e46568 | 7193 | { |
2ad9852d RK |
7194 | dw_loc_list_ref curr = list_head; |
7195 | ||
63e46568 | 7196 | ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol); |
a20612aa | 7197 | |
1711adc2 | 7198 | /* Walk the location list, and output each range + expression. */ |
c26fbbca | 7199 | for (curr = list_head; curr != NULL; curr = curr->dw_loc_next) |
63e46568 | 7200 | { |
2bee6045 | 7201 | unsigned long size; |
62760ffd CT |
7202 | /* Don't output an entry that starts and ends at the same address. */ |
7203 | if (strcmp (curr->begin, curr->end) == 0) | |
7204 | continue; | |
1146e682 | 7205 | if (!have_multiple_function_sections) |
1711adc2 DB |
7206 | { |
7207 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section, | |
7208 | "Location list begin address (%s)", | |
7209 | list_head->ll_symbol); | |
7210 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section, | |
7211 | "Location list end address (%s)", | |
7212 | list_head->ll_symbol); | |
7213 | } | |
7214 | else | |
7215 | { | |
7216 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin, | |
7217 | "Location list begin address (%s)", | |
7218 | list_head->ll_symbol); | |
7219 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end, | |
7220 | "Location list end address (%s)", | |
7221 | list_head->ll_symbol); | |
7222 | } | |
63e46568 | 7223 | size = size_of_locs (curr->expr); |
c26fbbca | 7224 | |
63e46568 | 7225 | /* Output the block length for this list of location operations. */ |
ced3f397 | 7226 | gcc_assert (size <= 0xffff); |
2bee6045 JJ |
7227 | dw2_asm_output_data (2, size, "%s", "Location expression size"); |
7228 | ||
63e46568 DB |
7229 | output_loc_sequence (curr->expr); |
7230 | } | |
2ad9852d | 7231 | |
1711adc2 | 7232 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, |
aafdcfcd NS |
7233 | "Location list terminator begin (%s)", |
7234 | list_head->ll_symbol); | |
1711adc2 | 7235 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, |
aafdcfcd NS |
7236 | "Location list terminator end (%s)", |
7237 | list_head->ll_symbol); | |
63e46568 | 7238 | } |
9eb4015a | 7239 | |
3f76745e JM |
7240 | /* Output the DIE and its attributes. Called recursively to generate |
7241 | the definitions of each child DIE. */ | |
71dfc51f | 7242 | |
a3f97cbb | 7243 | static void |
7080f735 | 7244 | output_die (dw_die_ref die) |
a3f97cbb | 7245 | { |
b3694847 SS |
7246 | dw_attr_ref a; |
7247 | dw_die_ref c; | |
7248 | unsigned long size; | |
1a27722f | 7249 | unsigned ix; |
a94dbf2c | 7250 | |
881c6935 JM |
7251 | /* If someone in another CU might refer to us, set up a symbol for |
7252 | them to point to. */ | |
7253 | if (die->die_symbol) | |
7254 | output_die_symbol (die); | |
7255 | ||
2e4b9b8c | 7256 | dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)", |
8d5b1b67 GK |
7257 | (unsigned long)die->die_offset, |
7258 | dwarf_tag_name (die->die_tag)); | |
a94dbf2c | 7259 | |
1a27722f | 7260 | for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++) |
a3f97cbb | 7261 | { |
2e4b9b8c RH |
7262 | const char *name = dwarf_attr_name (a->dw_attr); |
7263 | ||
a96c67ec | 7264 | switch (AT_class (a)) |
3f76745e JM |
7265 | { |
7266 | case dw_val_class_addr: | |
2e4b9b8c | 7267 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name); |
3f76745e | 7268 | break; |
a3f97cbb | 7269 | |
a20612aa RH |
7270 | case dw_val_class_offset: |
7271 | dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset, | |
7272 | "%s", name); | |
7273 | break; | |
7274 | ||
2bee6045 JJ |
7275 | case dw_val_class_range_list: |
7276 | { | |
7277 | char *p = strchr (ranges_section_label, '\0'); | |
7278 | ||
38f9cd4c AJ |
7279 | sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX, |
7280 | a->dw_attr_val.v.val_offset); | |
2bee6045 | 7281 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label, |
192d0f89 | 7282 | debug_ranges_section, "%s", name); |
2bee6045 JJ |
7283 | *p = '\0'; |
7284 | } | |
7285 | break; | |
7286 | ||
3f76745e | 7287 | case dw_val_class_loc: |
a96c67ec | 7288 | size = size_of_locs (AT_loc (a)); |
71dfc51f | 7289 | |
3f76745e | 7290 | /* Output the block length for this list of location operations. */ |
2e4b9b8c | 7291 | dw2_asm_output_data (constant_size (size), size, "%s", name); |
71dfc51f | 7292 | |
7d9d8943 | 7293 | output_loc_sequence (AT_loc (a)); |
a3f97cbb | 7294 | break; |
3f76745e JM |
7295 | |
7296 | case dw_val_class_const: | |
25dd13ec JW |
7297 | /* ??? It would be slightly more efficient to use a scheme like is |
7298 | used for unsigned constants below, but gdb 4.x does not sign | |
7299 | extend. Gdb 5.x does sign extend. */ | |
2e4b9b8c | 7300 | dw2_asm_output_data_sleb128 (AT_int (a), "%s", name); |
a3f97cbb | 7301 | break; |
3f76745e JM |
7302 | |
7303 | case dw_val_class_unsigned_const: | |
2e4b9b8c RH |
7304 | dw2_asm_output_data (constant_size (AT_unsigned (a)), |
7305 | AT_unsigned (a), "%s", name); | |
a3f97cbb | 7306 | break; |
3f76745e JM |
7307 | |
7308 | case dw_val_class_long_long: | |
2e4b9b8c RH |
7309 | { |
7310 | unsigned HOST_WIDE_INT first, second; | |
3f76745e | 7311 | |
2ad9852d RK |
7312 | dw2_asm_output_data (1, |
7313 | 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, | |
c26fbbca | 7314 | "%s", name); |
556273e0 | 7315 | |
2e4b9b8c RH |
7316 | if (WORDS_BIG_ENDIAN) |
7317 | { | |
7318 | first = a->dw_attr_val.v.val_long_long.hi; | |
7319 | second = a->dw_attr_val.v.val_long_long.low; | |
7320 | } | |
7321 | else | |
7322 | { | |
7323 | first = a->dw_attr_val.v.val_long_long.low; | |
7324 | second = a->dw_attr_val.v.val_long_long.hi; | |
7325 | } | |
2ad9852d RK |
7326 | |
7327 | dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, | |
2e4b9b8c | 7328 | first, "long long constant"); |
2ad9852d | 7329 | dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, |
2e4b9b8c RH |
7330 | second, NULL); |
7331 | } | |
a3f97cbb | 7332 | break; |
3f76745e | 7333 | |
e7ee3914 | 7334 | case dw_val_class_vec: |
c84e2712 | 7335 | { |
e7ee3914 AM |
7336 | unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size; |
7337 | unsigned int len = a->dw_attr_val.v.val_vec.length; | |
b3694847 | 7338 | unsigned int i; |
e7ee3914 | 7339 | unsigned char *p; |
c84e2712 | 7340 | |
e7ee3914 AM |
7341 | dw2_asm_output_data (1, len * elt_size, "%s", name); |
7342 | if (elt_size > sizeof (HOST_WIDE_INT)) | |
7343 | { | |
7344 | elt_size /= 2; | |
7345 | len *= 2; | |
7346 | } | |
7347 | for (i = 0, p = a->dw_attr_val.v.val_vec.array; | |
7348 | i < len; | |
7349 | i++, p += elt_size) | |
7350 | dw2_asm_output_data (elt_size, extract_int (p, elt_size), | |
7351 | "fp or vector constant word %u", i); | |
556273e0 | 7352 | break; |
c84e2712 | 7353 | } |
3f76745e JM |
7354 | |
7355 | case dw_val_class_flag: | |
2e4b9b8c | 7356 | dw2_asm_output_data (1, AT_flag (a), "%s", name); |
a3f97cbb | 7357 | break; |
a20612aa | 7358 | |
c26fbbca | 7359 | case dw_val_class_loc_list: |
63e46568 DB |
7360 | { |
7361 | char *sym = AT_loc_list (a)->ll_symbol; | |
2ad9852d | 7362 | |
ced3f397 | 7363 | gcc_assert (sym); |
192d0f89 GK |
7364 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section, |
7365 | "%s", name); | |
63e46568 DB |
7366 | } |
7367 | break; | |
a20612aa | 7368 | |
3f76745e | 7369 | case dw_val_class_die_ref: |
881c6935 | 7370 | if (AT_ref_external (a)) |
2e4b9b8c RH |
7371 | { |
7372 | char *sym = AT_ref (a)->die_symbol; | |
2ad9852d | 7373 | |
ced3f397 | 7374 | gcc_assert (sym); |
192d0f89 GK |
7375 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, debug_info_section, |
7376 | "%s", name); | |
2e4b9b8c | 7377 | } |
881c6935 | 7378 | else |
ced3f397 NS |
7379 | { |
7380 | gcc_assert (AT_ref (a)->die_offset); | |
7381 | dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset, | |
7382 | "%s", name); | |
7383 | } | |
a3f97cbb | 7384 | break; |
3f76745e JM |
7385 | |
7386 | case dw_val_class_fde_ref: | |
a6ab3aad JM |
7387 | { |
7388 | char l1[20]; | |
2ad9852d | 7389 | |
2e4b9b8c RH |
7390 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL, |
7391 | a->dw_attr_val.v.val_fde_index * 2); | |
192d0f89 GK |
7392 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section, |
7393 | "%s", name); | |
a6ab3aad | 7394 | } |
a3f97cbb | 7395 | break; |
a3f97cbb | 7396 | |
3f76745e | 7397 | case dw_val_class_lbl_id: |
8e7fa2c8 | 7398 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 7399 | break; |
71dfc51f | 7400 | |
192d0f89 GK |
7401 | case dw_val_class_lineptr: |
7402 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), | |
7403 | debug_line_section, "%s", name); | |
7404 | break; | |
7405 | ||
7406 | case dw_val_class_macptr: | |
7407 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), | |
7408 | debug_macinfo_section, "%s", name); | |
3f76745e | 7409 | break; |
a3f97cbb | 7410 | |
3f76745e | 7411 | case dw_val_class_str: |
9eb4015a JJ |
7412 | if (AT_string_form (a) == DW_FORM_strp) |
7413 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, | |
7414 | a->dw_attr_val.v.val_str->label, | |
192d0f89 | 7415 | debug_str_section, |
a4cf1d85 | 7416 | "%s: \"%s\"", name, AT_string (a)); |
9eb4015a JJ |
7417 | else |
7418 | dw2_asm_output_nstring (AT_string (a), -1, "%s", name); | |
3f76745e | 7419 | break; |
b2932ae5 | 7420 | |
d5688810 GK |
7421 | case dw_val_class_file: |
7422 | { | |
7423 | int f = maybe_emit_file (a->dw_attr_val.v.val_file); | |
2878ea73 | 7424 | |
d5688810 GK |
7425 | dw2_asm_output_data (constant_size (f), f, "%s (%s)", name, |
7426 | a->dw_attr_val.v.val_file->filename); | |
7427 | break; | |
7428 | } | |
7429 | ||
3f76745e | 7430 | default: |
ced3f397 | 7431 | gcc_unreachable (); |
3f76745e | 7432 | } |
3f76745e | 7433 | } |
71dfc51f | 7434 | |
d6eeb3ba | 7435 | FOR_EACH_CHILD (die, c, output_die (c)); |
71dfc51f | 7436 | |
2ad9852d | 7437 | /* Add null byte to terminate sibling list. */ |
3f76745e | 7438 | if (die->die_child != NULL) |
2ad9852d | 7439 | dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx", |
8d5b1b67 | 7440 | (unsigned long) die->die_offset); |
3f76745e | 7441 | } |
71dfc51f | 7442 | |
3f76745e JM |
7443 | /* Output the compilation unit that appears at the beginning of the |
7444 | .debug_info section, and precedes the DIE descriptions. */ | |
71dfc51f | 7445 | |
3f76745e | 7446 | static void |
7080f735 | 7447 | output_compilation_unit_header (void) |
3f76745e | 7448 | { |
9eb0ef7a KB |
7449 | if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4) |
7450 | dw2_asm_output_data (4, 0xffffffff, | |
7451 | "Initial length escape value indicating 64-bit DWARF extension"); | |
7452 | dw2_asm_output_data (DWARF_OFFSET_SIZE, | |
2878ea73 | 7453 | next_die_offset - DWARF_INITIAL_LENGTH_SIZE, |
2e4b9b8c | 7454 | "Length of Compilation Unit Info"); |
2e4b9b8c | 7455 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number"); |
2e4b9b8c | 7456 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label, |
192d0f89 | 7457 | debug_abbrev_section, |
2e4b9b8c | 7458 | "Offset Into Abbrev. Section"); |
2e4b9b8c | 7459 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)"); |
a3f97cbb JW |
7460 | } |
7461 | ||
881c6935 JM |
7462 | /* Output the compilation unit DIE and its children. */ |
7463 | ||
7464 | static void | |
7080f735 | 7465 | output_comp_unit (dw_die_ref die, int output_if_empty) |
881c6935 | 7466 | { |
ce1cc601 | 7467 | const char *secname; |
cc0017a9 ZD |
7468 | char *oldsym, *tmp; |
7469 | ||
7470 | /* Unless we are outputting main CU, we may throw away empty ones. */ | |
7471 | if (!output_if_empty && die->die_child == NULL) | |
7472 | return; | |
881c6935 | 7473 | |
2ad9852d RK |
7474 | /* Even if there are no children of this DIE, we must output the information |
7475 | about the compilation unit. Otherwise, on an empty translation unit, we | |
7476 | will generate a present, but empty, .debug_info section. IRIX 6.5 `nm' | |
7477 | will then complain when examining the file. First mark all the DIEs in | |
7478 | this CU so we know which get local refs. */ | |
1bfb5f8f JM |
7479 | mark_dies (die); |
7480 | ||
7481 | build_abbrev_table (die); | |
7482 | ||
6d2f8887 | 7483 | /* Initialize the beginning DIE offset - and calculate sizes/offsets. */ |
881c6935 JM |
7484 | next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE; |
7485 | calc_die_sizes (die); | |
7486 | ||
cc0017a9 ZD |
7487 | oldsym = die->die_symbol; |
7488 | if (oldsym) | |
881c6935 | 7489 | { |
1b4572a8 | 7490 | tmp = XALLOCAVEC (char, strlen (oldsym) + 24); |
2ad9852d | 7491 | |
cc0017a9 | 7492 | sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym); |
ce1cc601 | 7493 | secname = tmp; |
881c6935 | 7494 | die->die_symbol = NULL; |
d6b5193b | 7495 | switch_to_section (get_section (secname, SECTION_DEBUG, NULL)); |
881c6935 JM |
7496 | } |
7497 | else | |
d6b5193b | 7498 | switch_to_section (debug_info_section); |
881c6935 JM |
7499 | |
7500 | /* Output debugging information. */ | |
881c6935 JM |
7501 | output_compilation_unit_header (); |
7502 | output_die (die); | |
7503 | ||
1bfb5f8f JM |
7504 | /* Leave the marks on the main CU, so we can check them in |
7505 | output_pubnames. */ | |
cc0017a9 ZD |
7506 | if (oldsym) |
7507 | { | |
7508 | unmark_dies (die); | |
7509 | die->die_symbol = oldsym; | |
7510 | } | |
881c6935 JM |
7511 | } |
7512 | ||
721a8ac5 | 7513 | /* Return the DWARF2/3 pubname associated with a decl. */ |
a1d7ffe3 | 7514 | |
d560ee52 | 7515 | static const char * |
7080f735 | 7516 | dwarf2_name (tree decl, int scope) |
a1d7ffe3 | 7517 | { |
721a8ac5 | 7518 | return lang_hooks.dwarf_name (decl, scope ? 1 : 0); |
a1d7ffe3 JM |
7519 | } |
7520 | ||
d291dd49 | 7521 | /* Add a new entry to .debug_pubnames if appropriate. */ |
71dfc51f | 7522 | |
d291dd49 | 7523 | static void |
7151ffbe | 7524 | add_pubname_string (const char *str, dw_die_ref die) |
d291dd49 | 7525 | { |
89708594 | 7526 | pubname_entry e; |
d291dd49 | 7527 | |
89708594 | 7528 | e.die = die; |
7151ffbe | 7529 | e.name = xstrdup (str); |
89708594 CT |
7530 | VEC_safe_push (pubname_entry, gc, pubname_table, &e); |
7531 | } | |
7532 | ||
7151ffbe GH |
7533 | static void |
7534 | add_pubname (tree decl, dw_die_ref die) | |
7535 | { | |
7536 | ||
7537 | if (TREE_PUBLIC (decl)) | |
7538 | add_pubname_string (dwarf2_name (decl, 1), die); | |
7539 | } | |
7540 | ||
89708594 CT |
7541 | /* Add a new entry to .debug_pubtypes if appropriate. */ |
7542 | ||
7543 | static void | |
7544 | add_pubtype (tree decl, dw_die_ref die) | |
7545 | { | |
7546 | pubname_entry e; | |
7547 | ||
7548 | e.name = NULL; | |
7549 | if ((TREE_PUBLIC (decl) | |
7550 | || die->die_parent == comp_unit_die) | |
7551 | && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl))) | |
d291dd49 | 7552 | { |
89708594 CT |
7553 | e.die = die; |
7554 | if (TYPE_P (decl)) | |
7555 | { | |
7556 | if (TYPE_NAME (decl)) | |
7557 | { | |
7558 | if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE) | |
e01e0201 | 7559 | e.name = IDENTIFIER_POINTER (TYPE_NAME (decl)); |
89708594 CT |
7560 | else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL |
7561 | && DECL_NAME (TYPE_NAME (decl))) | |
e01e0201 | 7562 | e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl))); |
2878ea73 | 7563 | else |
89708594 CT |
7564 | e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name)); |
7565 | } | |
7566 | } | |
2878ea73 | 7567 | else |
89708594 | 7568 | e.name = xstrdup (dwarf2_name (decl, 1)); |
71dfc51f | 7569 | |
89708594 CT |
7570 | /* If we don't have a name for the type, there's no point in adding |
7571 | it to the table. */ | |
7572 | if (e.name && e.name[0] != '\0') | |
7573 | VEC_safe_push (pubname_entry, gc, pubtype_table, &e); | |
7574 | } | |
d291dd49 JM |
7575 | } |
7576 | ||
a3f97cbb | 7577 | /* Output the public names table used to speed up access to externally |
89708594 | 7578 | visible names; or the public types table used to find type definitions. */ |
71dfc51f | 7579 | |
a3f97cbb | 7580 | static void |
89708594 | 7581 | output_pubnames (VEC (pubname_entry, gc) * names) |
a3f97cbb | 7582 | { |
b3694847 | 7583 | unsigned i; |
89708594 CT |
7584 | unsigned long pubnames_length = size_of_pubnames (names); |
7585 | pubname_ref pub; | |
71dfc51f | 7586 | |
9eb0ef7a KB |
7587 | if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4) |
7588 | dw2_asm_output_data (4, 0xffffffff, | |
7589 | "Initial length escape value indicating 64-bit DWARF extension"); | |
89708594 CT |
7590 | if (names == pubname_table) |
7591 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, | |
7592 | "Length of Public Names Info"); | |
7593 | else | |
7594 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, | |
7595 | "Length of Public Type Names Info"); | |
2e4b9b8c | 7596 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
2e4b9b8c | 7597 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
192d0f89 | 7598 | debug_info_section, |
2e4b9b8c | 7599 | "Offset of Compilation Unit Info"); |
2e4b9b8c RH |
7600 | dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset, |
7601 | "Compilation Unit Length"); | |
71dfc51f | 7602 | |
89708594 | 7603 | for (i = 0; VEC_iterate (pubname_entry, names, i, pub); i++) |
a3f97cbb | 7604 | { |
2878ea73 | 7605 | /* We shouldn't see pubnames for DIEs outside of the main CU. */ |
89708594 CT |
7606 | if (names == pubname_table) |
7607 | gcc_assert (pub->die->die_mark); | |
881c6935 | 7608 | |
89708594 CT |
7609 | if (names != pubtype_table |
7610 | || pub->die->die_offset != 0 | |
7611 | || !flag_eliminate_unused_debug_types) | |
7612 | { | |
7613 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset, | |
7614 | "DIE offset"); | |
71dfc51f | 7615 | |
89708594 CT |
7616 | dw2_asm_output_nstring (pub->name, -1, "external name"); |
7617 | } | |
a3f97cbb | 7618 | } |
71dfc51f | 7619 | |
2e4b9b8c | 7620 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL); |
a3f97cbb JW |
7621 | } |
7622 | ||
d291dd49 | 7623 | /* Add a new entry to .debug_aranges if appropriate. */ |
71dfc51f | 7624 | |
d291dd49 | 7625 | static void |
7080f735 | 7626 | add_arange (tree decl, dw_die_ref die) |
d291dd49 JM |
7627 | { |
7628 | if (! DECL_SECTION_NAME (decl)) | |
7629 | return; | |
7630 | ||
7631 | if (arange_table_in_use == arange_table_allocated) | |
7632 | { | |
7633 | arange_table_allocated += ARANGE_TABLE_INCREMENT; | |
1b4572a8 KG |
7634 | arange_table = GGC_RESIZEVEC (dw_die_ref, arange_table, |
7635 | arange_table_allocated); | |
17211ab5 GK |
7636 | memset (arange_table + arange_table_in_use, 0, |
7637 | ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref)); | |
d291dd49 | 7638 | } |
71dfc51f | 7639 | |
d291dd49 JM |
7640 | arange_table[arange_table_in_use++] = die; |
7641 | } | |
7642 | ||
a3f97cbb JW |
7643 | /* Output the information that goes into the .debug_aranges table. |
7644 | Namely, define the beginning and ending address range of the | |
7645 | text section generated for this compilation unit. */ | |
71dfc51f | 7646 | |
a3f97cbb | 7647 | static void |
7080f735 | 7648 | output_aranges (void) |
a3f97cbb | 7649 | { |
b3694847 SS |
7650 | unsigned i; |
7651 | unsigned long aranges_length = size_of_aranges (); | |
71dfc51f | 7652 | |
9eb0ef7a KB |
7653 | if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4) |
7654 | dw2_asm_output_data (4, 0xffffffff, | |
7655 | "Initial length escape value indicating 64-bit DWARF extension"); | |
2e4b9b8c RH |
7656 | dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length, |
7657 | "Length of Address Ranges Info"); | |
2e4b9b8c | 7658 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
2e4b9b8c | 7659 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
192d0f89 | 7660 | debug_info_section, |
2e4b9b8c | 7661 | "Offset of Compilation Unit Info"); |
2e4b9b8c | 7662 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address"); |
2e4b9b8c | 7663 | dw2_asm_output_data (1, 0, "Size of Segment Descriptor"); |
71dfc51f | 7664 | |
262b6384 SC |
7665 | /* We need to align to twice the pointer size here. */ |
7666 | if (DWARF_ARANGES_PAD_SIZE) | |
7667 | { | |
2e4b9b8c | 7668 | /* Pad using a 2 byte words so that padding is correct for any |
73c68f61 | 7669 | pointer size. */ |
2e4b9b8c RH |
7670 | dw2_asm_output_data (2, 0, "Pad to %d byte boundary", |
7671 | 2 * DWARF2_ADDR_SIZE); | |
770ca8c6 | 7672 | for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2) |
2e4b9b8c | 7673 | dw2_asm_output_data (2, 0, NULL); |
262b6384 | 7674 | } |
71dfc51f | 7675 | |
9e9f8522 JM |
7676 | /* It is necessary not to output these entries if the sections were |
7677 | not used; if the sections were not used, the length will be 0 and | |
7678 | the address may end up as 0 if the section is discarded by ld | |
7679 | --gc-sections, leaving an invalid (0, 0) entry that can be | |
7680 | confused with the terminator. */ | |
7681 | if (text_section_used) | |
7682 | { | |
7683 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address"); | |
7684 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label, | |
7685 | text_section_label, "Length"); | |
7686 | } | |
7687 | if (cold_text_section_used) | |
c7466dee | 7688 | { |
2878ea73 | 7689 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label, |
c7466dee CT |
7690 | "Address"); |
7691 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label, | |
7692 | cold_text_section_label, "Length"); | |
7693 | } | |
71dfc51f | 7694 | |
2ad9852d | 7695 | for (i = 0; i < arange_table_in_use; i++) |
d291dd49 | 7696 | { |
e689ae67 | 7697 | dw_die_ref die = arange_table[i]; |
71dfc51f | 7698 | |
881c6935 | 7699 | /* We shouldn't see aranges for DIEs outside of the main CU. */ |
ced3f397 | 7700 | gcc_assert (die->die_mark); |
881c6935 | 7701 | |
e689ae67 | 7702 | if (die->die_tag == DW_TAG_subprogram) |
2e4b9b8c | 7703 | { |
8e7fa2c8 | 7704 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die), |
173bf5be | 7705 | "Address"); |
2e4b9b8c RH |
7706 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die), |
7707 | get_AT_low_pc (die), "Length"); | |
7708 | } | |
d291dd49 | 7709 | else |
a1d7ffe3 | 7710 | { |
e689ae67 JM |
7711 | /* A static variable; extract the symbol from DW_AT_location. |
7712 | Note that this code isn't currently hit, as we only emit | |
7713 | aranges for functions (jason 9/23/99). */ | |
e689ae67 JM |
7714 | dw_attr_ref a = get_AT (die, DW_AT_location); |
7715 | dw_loc_descr_ref loc; | |
2ad9852d | 7716 | |
ced3f397 | 7717 | gcc_assert (a && AT_class (a) == dw_val_class_loc); |
e689ae67 | 7718 | |
a96c67ec | 7719 | loc = AT_loc (a); |
ced3f397 | 7720 | gcc_assert (loc->dw_loc_opc == DW_OP_addr); |
e689ae67 | 7721 | |
2e4b9b8c RH |
7722 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, |
7723 | loc->dw_loc_oprnd1.v.val_addr, "Address"); | |
7724 | dw2_asm_output_data (DWARF2_ADDR_SIZE, | |
7725 | get_AT_unsigned (die, DW_AT_byte_size), | |
7726 | "Length"); | |
a1d7ffe3 | 7727 | } |
d291dd49 | 7728 | } |
71dfc51f | 7729 | |
a3f97cbb | 7730 | /* Output the terminator words. */ |
2e4b9b8c RH |
7731 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); |
7732 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
a3f97cbb JW |
7733 | } |
7734 | ||
a20612aa RH |
7735 | /* Add a new entry to .debug_ranges. Return the offset at which it |
7736 | was placed. */ | |
7737 | ||
7738 | static unsigned int | |
0435c1d5 | 7739 | add_ranges_num (int num) |
a20612aa RH |
7740 | { |
7741 | unsigned int in_use = ranges_table_in_use; | |
7742 | ||
7743 | if (in_use == ranges_table_allocated) | |
7744 | { | |
7745 | ranges_table_allocated += RANGES_TABLE_INCREMENT; | |
1b4572a8 KG |
7746 | ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table, |
7747 | ranges_table_allocated); | |
17211ab5 GK |
7748 | memset (ranges_table + ranges_table_in_use, 0, |
7749 | RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct)); | |
a20612aa RH |
7750 | } |
7751 | ||
0435c1d5 | 7752 | ranges_table[in_use].num = num; |
a20612aa RH |
7753 | ranges_table_in_use = in_use + 1; |
7754 | ||
7755 | return in_use * 2 * DWARF2_ADDR_SIZE; | |
7756 | } | |
7757 | ||
0435c1d5 AO |
7758 | /* Add a new entry to .debug_ranges corresponding to a block, or a |
7759 | range terminator if BLOCK is NULL. */ | |
7760 | ||
7761 | static unsigned int | |
9678086d | 7762 | add_ranges (const_tree block) |
0435c1d5 AO |
7763 | { |
7764 | return add_ranges_num (block ? BLOCK_NUMBER (block) : 0); | |
7765 | } | |
7766 | ||
7767 | /* Add a new entry to .debug_ranges corresponding to a pair of | |
7768 | labels. */ | |
7769 | ||
7770 | static unsigned int | |
7771 | add_ranges_by_labels (const char *begin, const char *end) | |
7772 | { | |
7773 | unsigned int in_use = ranges_by_label_in_use; | |
7774 | ||
7775 | if (in_use == ranges_by_label_allocated) | |
7776 | { | |
7777 | ranges_by_label_allocated += RANGES_TABLE_INCREMENT; | |
1b4572a8 KG |
7778 | ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct, |
7779 | ranges_by_label, | |
7780 | ranges_by_label_allocated); | |
0435c1d5 AO |
7781 | memset (ranges_by_label + ranges_by_label_in_use, 0, |
7782 | RANGES_TABLE_INCREMENT | |
7783 | * sizeof (struct dw_ranges_by_label_struct)); | |
7784 | } | |
7785 | ||
7786 | ranges_by_label[in_use].begin = begin; | |
7787 | ranges_by_label[in_use].end = end; | |
7788 | ranges_by_label_in_use = in_use + 1; | |
7789 | ||
7790 | return add_ranges_num (-(int)in_use - 1); | |
7791 | } | |
7792 | ||
a20612aa | 7793 | static void |
7080f735 | 7794 | output_ranges (void) |
a20612aa | 7795 | { |
b3694847 | 7796 | unsigned i; |
83182544 | 7797 | static const char *const start_fmt = "Offset 0x%x"; |
a20612aa RH |
7798 | const char *fmt = start_fmt; |
7799 | ||
2ad9852d | 7800 | for (i = 0; i < ranges_table_in_use; i++) |
a20612aa | 7801 | { |
0435c1d5 | 7802 | int block_num = ranges_table[i].num; |
a20612aa | 7803 | |
0435c1d5 | 7804 | if (block_num > 0) |
a20612aa RH |
7805 | { |
7806 | char blabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
7807 | char elabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
7808 | ||
7809 | ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num); | |
7810 | ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num); | |
7811 | ||
7812 | /* If all code is in the text section, then the compilation | |
7813 | unit base address defaults to DW_AT_low_pc, which is the | |
7814 | base of the text section. */ | |
1146e682 | 7815 | if (!have_multiple_function_sections) |
a20612aa | 7816 | { |
c7466dee CT |
7817 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel, |
7818 | text_section_label, | |
7819 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
7820 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel, | |
7821 | text_section_label, NULL); | |
a20612aa | 7822 | } |
2ad9852d | 7823 | |
0435c1d5 AO |
7824 | /* Otherwise, the compilation unit base address is zero, |
7825 | which allows us to use absolute addresses, and not worry | |
7826 | about whether the target supports cross-section | |
7827 | arithmetic. */ | |
a20612aa RH |
7828 | else |
7829 | { | |
7830 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel, | |
7831 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
7832 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL); | |
7833 | } | |
7834 | ||
7835 | fmt = NULL; | |
7836 | } | |
0435c1d5 AO |
7837 | |
7838 | /* Negative block_num stands for an index into ranges_by_label. */ | |
7839 | else if (block_num < 0) | |
7840 | { | |
7841 | int lab_idx = - block_num - 1; | |
7842 | ||
7843 | if (!have_multiple_function_sections) | |
7844 | { | |
7845 | gcc_unreachable (); | |
7846 | #if 0 | |
7847 | /* If we ever use add_ranges_by_labels () for a single | |
7848 | function section, all we have to do is to take out | |
7849 | the #if 0 above. */ | |
7850 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, | |
7851 | ranges_by_label[lab_idx].begin, | |
7852 | text_section_label, | |
7853 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
7854 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, | |
7855 | ranges_by_label[lab_idx].end, | |
7856 | text_section_label, NULL); | |
7857 | #endif | |
7858 | } | |
7859 | else | |
7860 | { | |
7861 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, | |
7862 | ranges_by_label[lab_idx].begin, | |
7863 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
7864 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, | |
7865 | ranges_by_label[lab_idx].end, | |
7866 | NULL); | |
7867 | } | |
7868 | } | |
a20612aa RH |
7869 | else |
7870 | { | |
7871 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
7872 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
7873 | fmt = start_fmt; | |
7874 | } | |
7875 | } | |
7876 | } | |
0b34cf1e UD |
7877 | |
7878 | /* Data structure containing information about input files. */ | |
7879 | struct file_info | |
7880 | { | |
d5688810 GK |
7881 | const char *path; /* Complete file name. */ |
7882 | const char *fname; /* File name part. */ | |
0b34cf1e | 7883 | int length; /* Length of entire string. */ |
d5688810 | 7884 | struct dwarf_file_data * file_idx; /* Index in input file table. */ |
0b34cf1e UD |
7885 | int dir_idx; /* Index in directory table. */ |
7886 | }; | |
7887 | ||
7888 | /* Data structure containing information about directories with source | |
7889 | files. */ | |
7890 | struct dir_info | |
7891 | { | |
d5688810 | 7892 | const char *path; /* Path including directory name. */ |
0b34cf1e UD |
7893 | int length; /* Path length. */ |
7894 | int prefix; /* Index of directory entry which is a prefix. */ | |
0b34cf1e UD |
7895 | int count; /* Number of files in this directory. */ |
7896 | int dir_idx; /* Index of directory used as base. */ | |
0b34cf1e UD |
7897 | }; |
7898 | ||
7899 | /* Callback function for file_info comparison. We sort by looking at | |
7900 | the directories in the path. */ | |
356b0698 | 7901 | |
0b34cf1e | 7902 | static int |
7080f735 | 7903 | file_info_cmp (const void *p1, const void *p2) |
0b34cf1e | 7904 | { |
1b4572a8 KG |
7905 | const struct file_info *const s1 = (const struct file_info *) p1; |
7906 | const struct file_info *const s2 = (const struct file_info *) p2; | |
5f754896 KG |
7907 | const unsigned char *cp1; |
7908 | const unsigned char *cp2; | |
0b34cf1e | 7909 | |
356b0698 RK |
7910 | /* Take care of file names without directories. We need to make sure that |
7911 | we return consistent values to qsort since some will get confused if | |
7912 | we return the same value when identical operands are passed in opposite | |
7913 | orders. So if neither has a directory, return 0 and otherwise return | |
7914 | 1 or -1 depending on which one has the directory. */ | |
7915 | if ((s1->path == s1->fname || s2->path == s2->fname)) | |
7916 | return (s2->path == s2->fname) - (s1->path == s1->fname); | |
0b34cf1e | 7917 | |
5f754896 KG |
7918 | cp1 = (const unsigned char *) s1->path; |
7919 | cp2 = (const unsigned char *) s2->path; | |
0b34cf1e UD |
7920 | |
7921 | while (1) | |
7922 | { | |
7923 | ++cp1; | |
7924 | ++cp2; | |
356b0698 | 7925 | /* Reached the end of the first path? If so, handle like above. */ |
5f754896 KG |
7926 | if ((cp1 == (const unsigned char *) s1->fname) |
7927 | || (cp2 == (const unsigned char *) s2->fname)) | |
7928 | return ((cp2 == (const unsigned char *) s2->fname) | |
7929 | - (cp1 == (const unsigned char *) s1->fname)); | |
0b34cf1e UD |
7930 | |
7931 | /* Character of current path component the same? */ | |
356b0698 | 7932 | else if (*cp1 != *cp2) |
0b34cf1e UD |
7933 | return *cp1 - *cp2; |
7934 | } | |
7935 | } | |
7936 | ||
2878ea73 | 7937 | struct file_name_acquire_data |
d5688810 GK |
7938 | { |
7939 | struct file_info *files; | |
7940 | int used_files; | |
7941 | int max_files; | |
7942 | }; | |
7943 | ||
7944 | /* Traversal function for the hash table. */ | |
7945 | ||
7946 | static int | |
7947 | file_name_acquire (void ** slot, void *data) | |
7948 | { | |
1b4572a8 KG |
7949 | struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data; |
7950 | struct dwarf_file_data *d = (struct dwarf_file_data *) *slot; | |
d5688810 GK |
7951 | struct file_info *fi; |
7952 | const char *f; | |
7953 | ||
7954 | gcc_assert (fnad->max_files >= d->emitted_number); | |
7955 | ||
7956 | if (! d->emitted_number) | |
7957 | return 1; | |
7958 | ||
7959 | gcc_assert (fnad->max_files != fnad->used_files); | |
7960 | ||
7961 | fi = fnad->files + fnad->used_files++; | |
7962 | ||
7963 | /* Skip all leading "./". */ | |
7964 | f = d->filename; | |
1d2c2b96 | 7965 | while (f[0] == '.' && IS_DIR_SEPARATOR (f[1])) |
d5688810 | 7966 | f += 2; |
2878ea73 | 7967 | |
d5688810 GK |
7968 | /* Create a new array entry. */ |
7969 | fi->path = f; | |
7970 | fi->length = strlen (f); | |
7971 | fi->file_idx = d; | |
2878ea73 | 7972 | |
d5688810 | 7973 | /* Search for the file name part. */ |
1d2c2b96 NF |
7974 | f = strrchr (f, DIR_SEPARATOR); |
7975 | #if defined (DIR_SEPARATOR_2) | |
7976 | { | |
2310f1f8 | 7977 | char *g = strrchr (fi->path, DIR_SEPARATOR_2); |
1d2c2b96 NF |
7978 | |
7979 | if (g != NULL) | |
7980 | { | |
7981 | if (f == NULL || f < g) | |
7982 | f = g; | |
7983 | } | |
7984 | } | |
7985 | #endif | |
7986 | ||
d5688810 GK |
7987 | fi->fname = f == NULL ? fi->path : f + 1; |
7988 | return 1; | |
7989 | } | |
7990 | ||
0b34cf1e UD |
7991 | /* Output the directory table and the file name table. We try to minimize |
7992 | the total amount of memory needed. A heuristic is used to avoid large | |
7993 | slowdowns with many input files. */ | |
2ad9852d | 7994 | |
0b34cf1e | 7995 | static void |
7080f735 | 7996 | output_file_names (void) |
0b34cf1e | 7997 | { |
d5688810 GK |
7998 | struct file_name_acquire_data fnad; |
7999 | int numfiles; | |
0b34cf1e UD |
8000 | struct file_info *files; |
8001 | struct dir_info *dirs; | |
8002 | int *saved; | |
8003 | int *savehere; | |
8004 | int *backmap; | |
d5688810 | 8005 | int ndirs; |
0b34cf1e | 8006 | int idx_offset; |
d5688810 | 8007 | int i; |
0b34cf1e UD |
8008 | int idx; |
8009 | ||
d5688810 | 8010 | if (!last_emitted_file) |
f0b886ab UW |
8011 | { |
8012 | dw2_asm_output_data (1, 0, "End directory table"); | |
8013 | dw2_asm_output_data (1, 0, "End file name table"); | |
8014 | return; | |
8015 | } | |
8016 | ||
d5688810 | 8017 | numfiles = last_emitted_file->emitted_number; |
0b34cf1e | 8018 | |
d5688810 | 8019 | /* Allocate the various arrays we need. */ |
1b4572a8 KG |
8020 | files = XALLOCAVEC (struct file_info, numfiles); |
8021 | dirs = XALLOCAVEC (struct dir_info, numfiles); | |
0b34cf1e | 8022 | |
d5688810 GK |
8023 | fnad.files = files; |
8024 | fnad.used_files = 0; | |
8025 | fnad.max_files = numfiles; | |
8026 | htab_traverse (file_table, file_name_acquire, &fnad); | |
8027 | gcc_assert (fnad.used_files == fnad.max_files); | |
2ad9852d | 8028 | |
d5688810 | 8029 | qsort (files, numfiles, sizeof (files[0]), file_info_cmp); |
0b34cf1e UD |
8030 | |
8031 | /* Find all the different directories used. */ | |
d5688810 GK |
8032 | dirs[0].path = files[0].path; |
8033 | dirs[0].length = files[0].fname - files[0].path; | |
0b34cf1e | 8034 | dirs[0].prefix = -1; |
0b34cf1e UD |
8035 | dirs[0].count = 1; |
8036 | dirs[0].dir_idx = 0; | |
d5688810 | 8037 | files[0].dir_idx = 0; |
0b34cf1e UD |
8038 | ndirs = 1; |
8039 | ||
d5688810 | 8040 | for (i = 1; i < numfiles; i++) |
0b34cf1e UD |
8041 | if (files[i].fname - files[i].path == dirs[ndirs - 1].length |
8042 | && memcmp (dirs[ndirs - 1].path, files[i].path, | |
8043 | dirs[ndirs - 1].length) == 0) | |
8044 | { | |
8045 | /* Same directory as last entry. */ | |
8046 | files[i].dir_idx = ndirs - 1; | |
0b34cf1e UD |
8047 | ++dirs[ndirs - 1].count; |
8048 | } | |
8049 | else | |
8050 | { | |
d5688810 | 8051 | int j; |
0b34cf1e UD |
8052 | |
8053 | /* This is a new directory. */ | |
8054 | dirs[ndirs].path = files[i].path; | |
8055 | dirs[ndirs].length = files[i].fname - files[i].path; | |
0b34cf1e UD |
8056 | dirs[ndirs].count = 1; |
8057 | dirs[ndirs].dir_idx = ndirs; | |
0b34cf1e UD |
8058 | files[i].dir_idx = ndirs; |
8059 | ||
8060 | /* Search for a prefix. */ | |
981975b6 | 8061 | dirs[ndirs].prefix = -1; |
2ad9852d | 8062 | for (j = 0; j < ndirs; j++) |
981975b6 RH |
8063 | if (dirs[j].length < dirs[ndirs].length |
8064 | && dirs[j].length > 1 | |
8065 | && (dirs[ndirs].prefix == -1 | |
8066 | || dirs[j].length > dirs[dirs[ndirs].prefix].length) | |
8067 | && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0) | |
8068 | dirs[ndirs].prefix = j; | |
0b34cf1e UD |
8069 | |
8070 | ++ndirs; | |
8071 | } | |
8072 | ||
2ad9852d RK |
8073 | /* Now to the actual work. We have to find a subset of the directories which |
8074 | allow expressing the file name using references to the directory table | |
8075 | with the least amount of characters. We do not do an exhaustive search | |
8076 | where we would have to check out every combination of every single | |
8077 | possible prefix. Instead we use a heuristic which provides nearly optimal | |
8078 | results in most cases and never is much off. */ | |
1b4572a8 KG |
8079 | saved = XALLOCAVEC (int, ndirs); |
8080 | savehere = XALLOCAVEC (int, ndirs); | |
0b34cf1e UD |
8081 | |
8082 | memset (saved, '\0', ndirs * sizeof (saved[0])); | |
2ad9852d | 8083 | for (i = 0; i < ndirs; i++) |
0b34cf1e | 8084 | { |
d5688810 | 8085 | int j; |
0b34cf1e UD |
8086 | int total; |
8087 | ||
2ad9852d RK |
8088 | /* We can always save some space for the current directory. But this |
8089 | does not mean it will be enough to justify adding the directory. */ | |
0b34cf1e UD |
8090 | savehere[i] = dirs[i].length; |
8091 | total = (savehere[i] - saved[i]) * dirs[i].count; | |
8092 | ||
2ad9852d | 8093 | for (j = i + 1; j < ndirs; j++) |
0b34cf1e UD |
8094 | { |
8095 | savehere[j] = 0; | |
0b34cf1e UD |
8096 | if (saved[j] < dirs[i].length) |
8097 | { | |
8098 | /* Determine whether the dirs[i] path is a prefix of the | |
8099 | dirs[j] path. */ | |
8100 | int k; | |
8101 | ||
981975b6 | 8102 | k = dirs[j].prefix; |
c4274b22 | 8103 | while (k != -1 && k != (int) i) |
981975b6 RH |
8104 | k = dirs[k].prefix; |
8105 | ||
c4274b22 | 8106 | if (k == (int) i) |
981975b6 | 8107 | { |
d5688810 | 8108 | /* Yes it is. We can possibly save some memory by |
981975b6 RH |
8109 | writing the filenames in dirs[j] relative to |
8110 | dirs[i]. */ | |
8111 | savehere[j] = dirs[i].length; | |
8112 | total += (savehere[j] - saved[j]) * dirs[j].count; | |
8113 | } | |
0b34cf1e UD |
8114 | } |
8115 | } | |
8116 | ||
d5688810 | 8117 | /* Check whether we can save enough to justify adding the dirs[i] |
0b34cf1e UD |
8118 | directory. */ |
8119 | if (total > dirs[i].length + 1) | |
8120 | { | |
981975b6 | 8121 | /* It's worthwhile adding. */ |
c26fbbca | 8122 | for (j = i; j < ndirs; j++) |
0b34cf1e UD |
8123 | if (savehere[j] > 0) |
8124 | { | |
8125 | /* Remember how much we saved for this directory so far. */ | |
8126 | saved[j] = savehere[j]; | |
8127 | ||
8128 | /* Remember the prefix directory. */ | |
8129 | dirs[j].dir_idx = i; | |
8130 | } | |
8131 | } | |
8132 | } | |
8133 | ||
d5688810 | 8134 | /* Emit the directory name table. */ |
0b34cf1e | 8135 | idx = 1; |
e57cabac | 8136 | idx_offset = dirs[0].length > 0 ? 1 : 0; |
2ad9852d | 8137 | for (i = 1 - idx_offset; i < ndirs; i++) |
d5688810 GK |
8138 | dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1, |
8139 | "Directory Entry: 0x%x", i + idx_offset); | |
2ad9852d | 8140 | |
2e4b9b8c RH |
8141 | dw2_asm_output_data (1, 0, "End directory table"); |
8142 | ||
d5688810 GK |
8143 | /* We have to emit them in the order of emitted_number since that's |
8144 | used in the debug info generation. To do this efficiently we | |
8145 | generate a back-mapping of the indices first. */ | |
1b4572a8 | 8146 | backmap = XALLOCAVEC (int, numfiles); |
d5688810 GK |
8147 | for (i = 0; i < numfiles; i++) |
8148 | backmap[files[i].file_idx->emitted_number - 1] = i; | |
0b34cf1e UD |
8149 | |
8150 | /* Now write all the file names. */ | |
d5688810 | 8151 | for (i = 0; i < numfiles; i++) |
0b34cf1e UD |
8152 | { |
8153 | int file_idx = backmap[i]; | |
8154 | int dir_idx = dirs[files[file_idx].dir_idx].dir_idx; | |
8155 | ||
2e4b9b8c | 8156 | dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1, |
d5688810 | 8157 | "File Entry: 0x%x", (unsigned) i + 1); |
0b34cf1e UD |
8158 | |
8159 | /* Include directory index. */ | |
d5688810 | 8160 | dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL); |
0b34cf1e UD |
8161 | |
8162 | /* Modification time. */ | |
2e4b9b8c | 8163 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e UD |
8164 | |
8165 | /* File length in bytes. */ | |
2e4b9b8c | 8166 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e | 8167 | } |
2ad9852d | 8168 | |
2e4b9b8c | 8169 | dw2_asm_output_data (1, 0, "End file name table"); |
0b34cf1e UD |
8170 | } |
8171 | ||
8172 | ||
a3f97cbb | 8173 | /* Output the source line number correspondence information. This |
14a774a9 | 8174 | information goes into the .debug_line section. */ |
71dfc51f | 8175 | |
a3f97cbb | 8176 | static void |
7080f735 | 8177 | output_line_info (void) |
a3f97cbb | 8178 | { |
981975b6 | 8179 | char l1[20], l2[20], p1[20], p2[20]; |
a3f97cbb JW |
8180 | char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
8181 | char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 SS |
8182 | unsigned opc; |
8183 | unsigned n_op_args; | |
8184 | unsigned long lt_index; | |
8185 | unsigned long current_line; | |
8186 | long line_offset; | |
8187 | long line_delta; | |
8188 | unsigned long current_file; | |
8189 | unsigned long function; | |
71dfc51f | 8190 | |
2e4b9b8c RH |
8191 | ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0); |
8192 | ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0); | |
981975b6 RH |
8193 | ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0); |
8194 | ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0); | |
71dfc51f | 8195 | |
9eb0ef7a KB |
8196 | if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4) |
8197 | dw2_asm_output_data (4, 0xffffffff, | |
8198 | "Initial length escape value indicating 64-bit DWARF extension"); | |
2e4b9b8c RH |
8199 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1, |
8200 | "Length of Source Line Info"); | |
8201 | ASM_OUTPUT_LABEL (asm_out_file, l1); | |
71dfc51f | 8202 | |
2e4b9b8c | 8203 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
981975b6 RH |
8204 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length"); |
8205 | ASM_OUTPUT_LABEL (asm_out_file, p1); | |
71dfc51f | 8206 | |
c1a046e5 TT |
8207 | /* Define the architecture-dependent minimum instruction length (in |
8208 | bytes). In this implementation of DWARF, this field is used for | |
8209 | information purposes only. Since GCC generates assembly language, | |
8210 | we have no a priori knowledge of how many instruction bytes are | |
8211 | generated for each source line, and therefore can use only the | |
8212 | DW_LNE_set_address and DW_LNS_fixed_advance_pc line information | |
8213 | commands. Accordingly, we fix this as `1', which is "correct | |
8214 | enough" for all architectures, and don't let the target override. */ | |
8215 | dw2_asm_output_data (1, 1, | |
2e4b9b8c | 8216 | "Minimum Instruction Length"); |
c1a046e5 | 8217 | |
2e4b9b8c RH |
8218 | dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START, |
8219 | "Default is_stmt_start flag"); | |
2e4b9b8c RH |
8220 | dw2_asm_output_data (1, DWARF_LINE_BASE, |
8221 | "Line Base Value (Special Opcodes)"); | |
2e4b9b8c RH |
8222 | dw2_asm_output_data (1, DWARF_LINE_RANGE, |
8223 | "Line Range Value (Special Opcodes)"); | |
2e4b9b8c RH |
8224 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE, |
8225 | "Special Opcode Base"); | |
71dfc51f | 8226 | |
2ad9852d | 8227 | for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++) |
a3f97cbb JW |
8228 | { |
8229 | switch (opc) | |
8230 | { | |
8231 | case DW_LNS_advance_pc: | |
8232 | case DW_LNS_advance_line: | |
8233 | case DW_LNS_set_file: | |
8234 | case DW_LNS_set_column: | |
8235 | case DW_LNS_fixed_advance_pc: | |
8236 | n_op_args = 1; | |
8237 | break; | |
8238 | default: | |
8239 | n_op_args = 0; | |
8240 | break; | |
8241 | } | |
2e4b9b8c RH |
8242 | |
8243 | dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args", | |
8244 | opc, n_op_args); | |
a3f97cbb | 8245 | } |
71dfc51f | 8246 | |
0b34cf1e UD |
8247 | /* Write out the information about the files we use. */ |
8248 | output_file_names (); | |
981975b6 | 8249 | ASM_OUTPUT_LABEL (asm_out_file, p2); |
a3f97cbb | 8250 | |
2f22d404 JM |
8251 | /* We used to set the address register to the first location in the text |
8252 | section here, but that didn't accomplish anything since we already | |
8253 | have a line note for the opening brace of the first function. */ | |
a3f97cbb JW |
8254 | |
8255 | /* Generate the line number to PC correspondence table, encoded as | |
8256 | a series of state machine operations. */ | |
8257 | current_file = 1; | |
8258 | current_line = 1; | |
c7466dee | 8259 | |
c543ca49 | 8260 | if (cfun && in_cold_section_p) |
38173d38 | 8261 | strcpy (prev_line_label, crtl->subsections.cold_section_label); |
87c8b4be CT |
8262 | else |
8263 | strcpy (prev_line_label, text_section_label); | |
a3f97cbb JW |
8264 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) |
8265 | { | |
b3694847 | 8266 | dw_line_info_ref line_info = &line_info_table[lt_index]; |
2f22d404 | 8267 | |
10a11b75 JM |
8268 | #if 0 |
8269 | /* Disable this optimization for now; GDB wants to see two line notes | |
8270 | at the beginning of a function so it can find the end of the | |
8271 | prologue. */ | |
8272 | ||
2f22d404 | 8273 | /* Don't emit anything for redundant notes. Just updating the |
73c68f61 SS |
8274 | address doesn't accomplish anything, because we already assume |
8275 | that anything after the last address is this line. */ | |
2f22d404 JM |
8276 | if (line_info->dw_line_num == current_line |
8277 | && line_info->dw_file_num == current_file) | |
8278 | continue; | |
10a11b75 | 8279 | #endif |
71dfc51f | 8280 | |
2e4b9b8c RH |
8281 | /* Emit debug info for the address of the current line. |
8282 | ||
8283 | Unfortunately, we have little choice here currently, and must always | |
2ad9852d | 8284 | use the most general form. GCC does not know the address delta |
2e4b9b8c RH |
8285 | itself, so we can't use DW_LNS_advance_pc. Many ports do have length |
8286 | attributes which will give an upper bound on the address range. We | |
8287 | could perhaps use length attributes to determine when it is safe to | |
8288 | use DW_LNS_fixed_advance_pc. */ | |
8289 | ||
5c90448c | 8290 | ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index); |
f19a6894 JW |
8291 | if (0) |
8292 | { | |
8293 | /* This can handle deltas up to 0xffff. This takes 3 bytes. */ | |
2e4b9b8c RH |
8294 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
8295 | "DW_LNS_fixed_advance_pc"); | |
8296 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
8297 | } |
8298 | else | |
8299 | { | |
a1a4189d | 8300 | /* This can handle any delta. This takes |
73c68f61 | 8301 | 4+DWARF2_ADDR_SIZE bytes. */ |
2e4b9b8c RH |
8302 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
8303 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
8304 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 8305 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 8306 | } |
2ad9852d | 8307 | |
f19a6894 JW |
8308 | strcpy (prev_line_label, line_label); |
8309 | ||
8310 | /* Emit debug info for the source file of the current line, if | |
8311 | different from the previous line. */ | |
a3f97cbb JW |
8312 | if (line_info->dw_file_num != current_file) |
8313 | { | |
8314 | current_file = line_info->dw_file_num; | |
2e4b9b8c | 8315 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
d5688810 | 8316 | dw2_asm_output_data_uleb128 (current_file, "%lu", current_file); |
a3f97cbb | 8317 | } |
71dfc51f | 8318 | |
f19a6894 JW |
8319 | /* Emit debug info for the current line number, choosing the encoding |
8320 | that uses the least amount of space. */ | |
2f22d404 | 8321 | if (line_info->dw_line_num != current_line) |
a3f97cbb | 8322 | { |
2f22d404 JM |
8323 | line_offset = line_info->dw_line_num - current_line; |
8324 | line_delta = line_offset - DWARF_LINE_BASE; | |
8325 | current_line = line_info->dw_line_num; | |
8326 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
2ad9852d RK |
8327 | /* This can handle deltas from -10 to 234, using the current |
8328 | definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This | |
8329 | takes 1 byte. */ | |
8330 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, | |
8331 | "line %lu", current_line); | |
2f22d404 JM |
8332 | else |
8333 | { | |
8334 | /* This can handle any delta. This takes at least 4 bytes, | |
8335 | depending on the value being encoded. */ | |
2e4b9b8c RH |
8336 | dw2_asm_output_data (1, DW_LNS_advance_line, |
8337 | "advance to line %lu", current_line); | |
8338 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
8339 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
2f22d404 | 8340 | } |
a94dbf2c JM |
8341 | } |
8342 | else | |
2ad9852d RK |
8343 | /* We still need to start a new row, so output a copy insn. */ |
8344 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
a3f97cbb JW |
8345 | } |
8346 | ||
f19a6894 JW |
8347 | /* Emit debug info for the address of the end of the function. */ |
8348 | if (0) | |
8349 | { | |
2e4b9b8c RH |
8350 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
8351 | "DW_LNS_fixed_advance_pc"); | |
8352 | dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL); | |
f19a6894 JW |
8353 | } |
8354 | else | |
8355 | { | |
2e4b9b8c RH |
8356 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
8357 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
8358 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 8359 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL); |
f19a6894 | 8360 | } |
bdb669cb | 8361 | |
2e4b9b8c RH |
8362 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
8363 | dw2_asm_output_data_uleb128 (1, NULL); | |
8364 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
8365 | |
8366 | function = 0; | |
8367 | current_file = 1; | |
8368 | current_line = 1; | |
556273e0 | 8369 | for (lt_index = 0; lt_index < separate_line_info_table_in_use;) |
e90b62db | 8370 | { |
b3694847 | 8371 | dw_separate_line_info_ref line_info |
e90b62db | 8372 | = &separate_line_info_table[lt_index]; |
71dfc51f | 8373 | |
10a11b75 | 8374 | #if 0 |
2f22d404 JM |
8375 | /* Don't emit anything for redundant notes. */ |
8376 | if (line_info->dw_line_num == current_line | |
8377 | && line_info->dw_file_num == current_file | |
8378 | && line_info->function == function) | |
8379 | goto cont; | |
10a11b75 | 8380 | #endif |
2f22d404 | 8381 | |
f19a6894 JW |
8382 | /* Emit debug info for the address of the current line. If this is |
8383 | a new function, or the first line of a function, then we need | |
8384 | to handle it differently. */ | |
5c90448c JM |
8385 | ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL, |
8386 | lt_index); | |
e90b62db JM |
8387 | if (function != line_info->function) |
8388 | { | |
8389 | function = line_info->function; | |
71dfc51f | 8390 | |
f9da5064 | 8391 | /* Set the address register to the first line in the function. */ |
2e4b9b8c RH |
8392 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
8393 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
8394 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 8395 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
e90b62db JM |
8396 | } |
8397 | else | |
8398 | { | |
f19a6894 JW |
8399 | /* ??? See the DW_LNS_advance_pc comment above. */ |
8400 | if (0) | |
8401 | { | |
2e4b9b8c RH |
8402 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
8403 | "DW_LNS_fixed_advance_pc"); | |
8404 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
8405 | } |
8406 | else | |
8407 | { | |
2e4b9b8c RH |
8408 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
8409 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
8410 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 8411 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 8412 | } |
e90b62db | 8413 | } |
2ad9852d | 8414 | |
f19a6894 | 8415 | strcpy (prev_line_label, line_label); |
71dfc51f | 8416 | |
f19a6894 JW |
8417 | /* Emit debug info for the source file of the current line, if |
8418 | different from the previous line. */ | |
e90b62db JM |
8419 | if (line_info->dw_file_num != current_file) |
8420 | { | |
8421 | current_file = line_info->dw_file_num; | |
2e4b9b8c | 8422 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
d5688810 | 8423 | dw2_asm_output_data_uleb128 (current_file, "%lu", current_file); |
e90b62db | 8424 | } |
71dfc51f | 8425 | |
f19a6894 JW |
8426 | /* Emit debug info for the current line number, choosing the encoding |
8427 | that uses the least amount of space. */ | |
e90b62db JM |
8428 | if (line_info->dw_line_num != current_line) |
8429 | { | |
8430 | line_offset = line_info->dw_line_num - current_line; | |
8431 | line_delta = line_offset - DWARF_LINE_BASE; | |
8432 | current_line = line_info->dw_line_num; | |
8433 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
2e4b9b8c RH |
8434 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, |
8435 | "line %lu", current_line); | |
e90b62db JM |
8436 | else |
8437 | { | |
2e4b9b8c RH |
8438 | dw2_asm_output_data (1, DW_LNS_advance_line, |
8439 | "advance to line %lu", current_line); | |
8440 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
8441 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
e90b62db JM |
8442 | } |
8443 | } | |
2f22d404 | 8444 | else |
2e4b9b8c | 8445 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); |
71dfc51f | 8446 | |
10a11b75 | 8447 | #if 0 |
2f22d404 | 8448 | cont: |
10a11b75 | 8449 | #endif |
2ad9852d RK |
8450 | |
8451 | lt_index++; | |
e90b62db JM |
8452 | |
8453 | /* If we're done with a function, end its sequence. */ | |
8454 | if (lt_index == separate_line_info_table_in_use | |
8455 | || separate_line_info_table[lt_index].function != function) | |
8456 | { | |
8457 | current_file = 1; | |
8458 | current_line = 1; | |
71dfc51f | 8459 | |
f19a6894 | 8460 | /* Emit debug info for the address of the end of the function. */ |
5c90448c | 8461 | ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function); |
f19a6894 JW |
8462 | if (0) |
8463 | { | |
2e4b9b8c RH |
8464 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
8465 | "DW_LNS_fixed_advance_pc"); | |
8466 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
8467 | } |
8468 | else | |
8469 | { | |
2e4b9b8c RH |
8470 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
8471 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
8472 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 8473 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 8474 | } |
e90b62db JM |
8475 | |
8476 | /* Output the marker for the end of this sequence. */ | |
2e4b9b8c RH |
8477 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
8478 | dw2_asm_output_data_uleb128 (1, NULL); | |
8479 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
8480 | } |
8481 | } | |
f19f17e0 JM |
8482 | |
8483 | /* Output the marker for the end of the line number info. */ | |
2e4b9b8c | 8484 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
a3f97cbb JW |
8485 | } |
8486 | \f | |
a3f97cbb JW |
8487 | /* Given a pointer to a tree node for some base type, return a pointer to |
8488 | a DIE that describes the given type. | |
8489 | ||
8490 | This routine must only be called for GCC type nodes that correspond to | |
8491 | Dwarf base (fundamental) types. */ | |
71dfc51f | 8492 | |
a3f97cbb | 8493 | static dw_die_ref |
7080f735 | 8494 | base_type_die (tree type) |
a3f97cbb | 8495 | { |
b3694847 | 8496 | dw_die_ref base_type_result; |
b3694847 | 8497 | enum dwarf_type encoding; |
a3f97cbb | 8498 | |
2ad9852d | 8499 | if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE) |
a3f97cbb JW |
8500 | return 0; |
8501 | ||
8502 | switch (TREE_CODE (type)) | |
8503 | { | |
a3f97cbb | 8504 | case INTEGER_TYPE: |
05fa7d54 | 8505 | if (TYPE_STRING_FLAG (type)) |
a3f97cbb | 8506 | { |
8df83eae | 8507 | if (TYPE_UNSIGNED (type)) |
05fa7d54 | 8508 | encoding = DW_ATE_unsigned_char; |
a9d38797 | 8509 | else |
05fa7d54 | 8510 | encoding = DW_ATE_signed_char; |
a3f97cbb | 8511 | } |
05fa7d54 RS |
8512 | else if (TYPE_UNSIGNED (type)) |
8513 | encoding = DW_ATE_unsigned; | |
a9d38797 | 8514 | else |
05fa7d54 | 8515 | encoding = DW_ATE_signed; |
a3f97cbb JW |
8516 | break; |
8517 | ||
8518 | case REAL_TYPE: | |
15ed7b52 JG |
8519 | if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type))) |
8520 | encoding = DW_ATE_decimal_float; | |
8521 | else | |
8522 | encoding = DW_ATE_float; | |
a3f97cbb JW |
8523 | break; |
8524 | ||
325217ed CF |
8525 | case FIXED_POINT_TYPE: |
8526 | if (TYPE_UNSIGNED (type)) | |
325217ed | 8527 | encoding = DW_ATE_unsigned_fixed; |
9a9f6b52 CF |
8528 | else |
8529 | encoding = DW_ATE_signed_fixed; | |
325217ed CF |
8530 | break; |
8531 | ||
405f63da MM |
8532 | /* Dwarf2 doesn't know anything about complex ints, so use |
8533 | a user defined type for it. */ | |
a3f97cbb | 8534 | case COMPLEX_TYPE: |
405f63da MM |
8535 | if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE) |
8536 | encoding = DW_ATE_complex_float; | |
8537 | else | |
8538 | encoding = DW_ATE_lo_user; | |
a3f97cbb JW |
8539 | break; |
8540 | ||
8541 | case BOOLEAN_TYPE: | |
a9d38797 JM |
8542 | /* GNU FORTRAN/Ada/C++ BOOLEAN type. */ |
8543 | encoding = DW_ATE_boolean; | |
a3f97cbb JW |
8544 | break; |
8545 | ||
8546 | default: | |
2ad9852d | 8547 | /* No other TREE_CODEs are Dwarf fundamental types. */ |
ced3f397 | 8548 | gcc_unreachable (); |
a3f97cbb JW |
8549 | } |
8550 | ||
54ba1f0d | 8551 | base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type); |
14a774a9 | 8552 | |
7cdfcf60 GK |
8553 | /* This probably indicates a bug. */ |
8554 | if (! TYPE_NAME (type)) | |
8555 | add_name_attribute (base_type_result, "__unknown__"); | |
8556 | ||
a9d38797 | 8557 | add_AT_unsigned (base_type_result, DW_AT_byte_size, |
4e5a8d7b | 8558 | int_size_in_bytes (type)); |
a9d38797 | 8559 | add_AT_unsigned (base_type_result, DW_AT_encoding, encoding); |
a3f97cbb JW |
8560 | |
8561 | return base_type_result; | |
8562 | } | |
8563 | ||
cc2902df | 8564 | /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the |
a3f97cbb | 8565 | given input type is a Dwarf "fundamental" type. Otherwise return null. */ |
71dfc51f RK |
8566 | |
8567 | static inline int | |
7080f735 | 8568 | is_base_type (tree type) |
a3f97cbb JW |
8569 | { |
8570 | switch (TREE_CODE (type)) | |
8571 | { | |
8572 | case ERROR_MARK: | |
8573 | case VOID_TYPE: | |
8574 | case INTEGER_TYPE: | |
8575 | case REAL_TYPE: | |
325217ed | 8576 | case FIXED_POINT_TYPE: |
a3f97cbb JW |
8577 | case COMPLEX_TYPE: |
8578 | case BOOLEAN_TYPE: | |
a3f97cbb JW |
8579 | return 1; |
8580 | ||
a3f97cbb JW |
8581 | case ARRAY_TYPE: |
8582 | case RECORD_TYPE: | |
8583 | case UNION_TYPE: | |
8584 | case QUAL_UNION_TYPE: | |
8585 | case ENUMERAL_TYPE: | |
8586 | case FUNCTION_TYPE: | |
8587 | case METHOD_TYPE: | |
8588 | case POINTER_TYPE: | |
8589 | case REFERENCE_TYPE: | |
a3f97cbb JW |
8590 | case OFFSET_TYPE: |
8591 | case LANG_TYPE: | |
604bb87d | 8592 | case VECTOR_TYPE: |
a3f97cbb JW |
8593 | return 0; |
8594 | ||
8595 | default: | |
ced3f397 | 8596 | gcc_unreachable (); |
a3f97cbb | 8597 | } |
71dfc51f | 8598 | |
a3f97cbb JW |
8599 | return 0; |
8600 | } | |
8601 | ||
4977bab6 ZW |
8602 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE |
8603 | node, return the size in bits for the type if it is a constant, or else | |
8604 | return the alignment for the type if the type's size is not constant, or | |
8605 | else return BITS_PER_WORD if the type actually turns out to be an | |
8606 | ERROR_MARK node. */ | |
8607 | ||
8608 | static inline unsigned HOST_WIDE_INT | |
9678086d | 8609 | simple_type_size_in_bits (const_tree type) |
4977bab6 | 8610 | { |
4977bab6 ZW |
8611 | if (TREE_CODE (type) == ERROR_MARK) |
8612 | return BITS_PER_WORD; | |
8613 | else if (TYPE_SIZE (type) == NULL_TREE) | |
8614 | return 0; | |
8615 | else if (host_integerp (TYPE_SIZE (type), 1)) | |
8616 | return tree_low_cst (TYPE_SIZE (type), 1); | |
8617 | else | |
8618 | return TYPE_ALIGN (type); | |
8619 | } | |
8620 | ||
c3cdeef4 JB |
8621 | /* Return true if the debug information for the given type should be |
8622 | emitted as a subrange type. */ | |
8623 | ||
8624 | static inline bool | |
9678086d | 8625 | is_subrange_type (const_tree type) |
e7d23ce3 | 8626 | { |
de99511b B |
8627 | tree subtype = TREE_TYPE (type); |
8628 | ||
886de2d4 JB |
8629 | /* Subrange types are identified by the fact that they are integer |
8630 | types, and that they have a subtype which is either an integer type | |
8631 | or an enumeral type. */ | |
8632 | ||
8633 | if (TREE_CODE (type) != INTEGER_TYPE | |
8634 | || subtype == NULL_TREE) | |
8635 | return false; | |
8636 | ||
8637 | if (TREE_CODE (subtype) != INTEGER_TYPE | |
8638 | && TREE_CODE (subtype) != ENUMERAL_TYPE) | |
8639 | return false; | |
8640 | ||
d6672e91 JB |
8641 | if (TREE_CODE (type) == TREE_CODE (subtype) |
8642 | && int_size_in_bytes (type) == int_size_in_bytes (subtype) | |
8643 | && TYPE_MIN_VALUE (type) != NULL | |
8644 | && TYPE_MIN_VALUE (subtype) != NULL | |
8645 | && tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype)) | |
8646 | && TYPE_MAX_VALUE (type) != NULL | |
8647 | && TYPE_MAX_VALUE (subtype) != NULL | |
8648 | && tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype))) | |
8649 | { | |
8650 | /* The type and its subtype have the same representation. If in | |
2878ea73 MS |
8651 | addition the two types also have the same name, then the given |
8652 | type is not a subrange type, but rather a plain base type. */ | |
d6672e91 | 8653 | /* FIXME: brobecker/2004-03-22: |
2878ea73 MS |
8654 | Sizetype INTEGER_CSTs nodes are canonicalized. It should |
8655 | therefore be sufficient to check the TYPE_SIZE node pointers | |
8656 | rather than checking the actual size. Unfortunately, we have | |
8657 | found some cases, such as in the Ada "integer" type, where | |
8658 | this is not the case. Until this problem is solved, we need to | |
8659 | keep checking the actual size. */ | |
d6672e91 JB |
8660 | tree type_name = TYPE_NAME (type); |
8661 | tree subtype_name = TYPE_NAME (subtype); | |
8662 | ||
8663 | if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL) | |
2878ea73 | 8664 | type_name = DECL_NAME (type_name); |
d6672e91 JB |
8665 | |
8666 | if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL) | |
2878ea73 | 8667 | subtype_name = DECL_NAME (subtype_name); |
d6672e91 JB |
8668 | |
8669 | if (type_name == subtype_name) | |
2878ea73 | 8670 | return false; |
d6672e91 JB |
8671 | } |
8672 | ||
886de2d4 | 8673 | return true; |
c3cdeef4 JB |
8674 | } |
8675 | ||
8676 | /* Given a pointer to a tree node for a subrange type, return a pointer | |
8677 | to a DIE that describes the given type. */ | |
8678 | ||
8679 | static dw_die_ref | |
fbfd77b8 | 8680 | subrange_type_die (tree type, dw_die_ref context_die) |
c3cdeef4 | 8681 | { |
c3cdeef4 | 8682 | dw_die_ref subrange_die; |
e7d23ce3 | 8683 | const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type); |
7080f735 | 8684 | |
fbfd77b8 JB |
8685 | if (context_die == NULL) |
8686 | context_die = comp_unit_die; | |
8687 | ||
fbfd77b8 | 8688 | subrange_die = new_die (DW_TAG_subrange_type, context_die, type); |
b98d154e | 8689 | |
7cdfcf60 | 8690 | if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes) |
e7d23ce3 B |
8691 | { |
8692 | /* The size of the subrange type and its base type do not match, | |
2878ea73 | 8693 | so we need to generate a size attribute for the subrange type. */ |
e7d23ce3 B |
8694 | add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes); |
8695 | } | |
8696 | ||
c3cdeef4 JB |
8697 | if (TYPE_MIN_VALUE (type) != NULL) |
8698 | add_bound_info (subrange_die, DW_AT_lower_bound, | |
2878ea73 | 8699 | TYPE_MIN_VALUE (type)); |
c3cdeef4 JB |
8700 | if (TYPE_MAX_VALUE (type) != NULL) |
8701 | add_bound_info (subrange_die, DW_AT_upper_bound, | |
2878ea73 | 8702 | TYPE_MAX_VALUE (type)); |
c3cdeef4 JB |
8703 | |
8704 | return subrange_die; | |
8705 | } | |
8706 | ||
a3f97cbb JW |
8707 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging |
8708 | entry that chains various modifiers in front of the given type. */ | |
71dfc51f | 8709 | |
a3f97cbb | 8710 | static dw_die_ref |
7080f735 AJ |
8711 | modified_type_die (tree type, int is_const_type, int is_volatile_type, |
8712 | dw_die_ref context_die) | |
a3f97cbb | 8713 | { |
b3694847 | 8714 | enum tree_code code = TREE_CODE (type); |
7cdfcf60 | 8715 | dw_die_ref mod_type_die; |
b3694847 SS |
8716 | dw_die_ref sub_die = NULL; |
8717 | tree item_type = NULL; | |
7cdfcf60 GK |
8718 | tree qualified_type; |
8719 | tree name; | |
8720 | ||
8721 | if (code == ERROR_MARK) | |
8722 | return NULL; | |
8723 | ||
8724 | /* See if we already have the appropriately qualified variant of | |
8725 | this type. */ | |
8726 | qualified_type | |
8727 | = get_qualified_type (type, | |
8728 | ((is_const_type ? TYPE_QUAL_CONST : 0) | |
8729 | | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0))); | |
2878ea73 | 8730 | |
7cdfcf60 GK |
8731 | /* If we do, then we can just use its DIE, if it exists. */ |
8732 | if (qualified_type) | |
a3f97cbb | 8733 | { |
7cdfcf60 | 8734 | mod_type_die = lookup_type_die (qualified_type); |
a94dbf2c | 8735 | if (mod_type_die) |
7cdfcf60 GK |
8736 | return mod_type_die; |
8737 | } | |
2878ea73 | 8738 | |
7cdfcf60 | 8739 | name = qualified_type ? TYPE_NAME (qualified_type) : NULL; |
2878ea73 | 8740 | |
7cdfcf60 GK |
8741 | /* Handle C typedef types. */ |
8742 | if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)) | |
8743 | { | |
8744 | tree dtype = TREE_TYPE (name); | |
2878ea73 | 8745 | |
7cdfcf60 | 8746 | if (qualified_type == dtype) |
a3f97cbb | 8747 | { |
7cdfcf60 GK |
8748 | /* For a named type, use the typedef. */ |
8749 | gen_type_die (qualified_type, context_die); | |
8750 | return lookup_type_die (qualified_type); | |
a3f97cbb | 8751 | } |
792eaee2 AO |
8752 | else if (is_const_type < TYPE_READONLY (dtype) |
8753 | || is_volatile_type < TYPE_VOLATILE (dtype) | |
8754 | || (is_const_type <= TYPE_READONLY (dtype) | |
8755 | && is_volatile_type <= TYPE_VOLATILE (dtype) | |
8756 | && DECL_ORIGINAL_TYPE (name) != type)) | |
7cdfcf60 GK |
8757 | /* cv-unqualified version of named type. Just use the unnamed |
8758 | type to which it refers. */ | |
8759 | return modified_type_die (DECL_ORIGINAL_TYPE (name), | |
8760 | is_const_type, is_volatile_type, | |
8761 | context_die); | |
8762 | /* Else cv-qualified version of named type; fall through. */ | |
8763 | } | |
2878ea73 | 8764 | |
7cdfcf60 GK |
8765 | if (is_const_type) |
8766 | { | |
8767 | mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type); | |
8768 | sub_die = modified_type_die (type, 0, is_volatile_type, context_die); | |
8769 | } | |
8770 | else if (is_volatile_type) | |
8771 | { | |
8772 | mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type); | |
8773 | sub_die = modified_type_die (type, 0, 0, context_die); | |
8774 | } | |
8775 | else if (code == POINTER_TYPE) | |
8776 | { | |
8777 | mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type); | |
8778 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, | |
8779 | simple_type_size_in_bits (type) / BITS_PER_UNIT); | |
8780 | item_type = TREE_TYPE (type); | |
8781 | } | |
8782 | else if (code == REFERENCE_TYPE) | |
8783 | { | |
8784 | mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type); | |
8785 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, | |
8786 | simple_type_size_in_bits (type) / BITS_PER_UNIT); | |
8787 | item_type = TREE_TYPE (type); | |
8788 | } | |
8789 | else if (is_subrange_type (type)) | |
8790 | { | |
8791 | mod_type_die = subrange_type_die (type, context_die); | |
8792 | item_type = TREE_TYPE (type); | |
8793 | } | |
8794 | else if (is_base_type (type)) | |
8795 | mod_type_die = base_type_die (type); | |
8796 | else | |
8797 | { | |
8798 | gen_type_die (type, context_die); | |
2878ea73 | 8799 | |
7cdfcf60 GK |
8800 | /* We have to get the type_main_variant here (and pass that to the |
8801 | `lookup_type_die' routine) because the ..._TYPE node we have | |
8802 | might simply be a *copy* of some original type node (where the | |
8803 | copy was created to help us keep track of typedef names) and | |
8804 | that copy might have a different TYPE_UID from the original | |
8805 | ..._TYPE node. */ | |
8806 | if (TREE_CODE (type) != VECTOR_TYPE) | |
8807 | return lookup_type_die (type_main_variant (type)); | |
a3f97cbb | 8808 | else |
7cdfcf60 GK |
8809 | /* Vectors have the debugging information in the type, |
8810 | not the main variant. */ | |
8811 | return lookup_type_die (type); | |
8812 | } | |
2878ea73 | 8813 | |
7cdfcf60 GK |
8814 | /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those, |
8815 | don't output a DW_TAG_typedef, since there isn't one in the | |
8816 | user's program; just attach a DW_AT_name to the type. */ | |
8817 | if (name | |
cc459ab4 JJ |
8818 | && (TREE_CODE (name) != TYPE_DECL |
8819 | || (TREE_TYPE (name) == qualified_type && DECL_NAME (name)))) | |
7cdfcf60 GK |
8820 | { |
8821 | if (TREE_CODE (name) == TYPE_DECL) | |
8822 | /* Could just call add_name_and_src_coords_attributes here, | |
8823 | but since this is a builtin type it doesn't have any | |
8824 | useful source coordinates anyway. */ | |
8825 | name = DECL_NAME (name); | |
8826 | add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name)); | |
a3f97cbb | 8827 | } |
2878ea73 | 8828 | |
7cdfcf60 GK |
8829 | if (qualified_type) |
8830 | equate_type_number_to_die (qualified_type, mod_type_die); | |
71dfc51f | 8831 | |
dfcf9891 | 8832 | if (item_type) |
71dfc51f RK |
8833 | /* We must do this after the equate_type_number_to_die call, in case |
8834 | this is a recursive type. This ensures that the modified_type_die | |
8835 | recursion will terminate even if the type is recursive. Recursive | |
8836 | types are possible in Ada. */ | |
8837 | sub_die = modified_type_die (item_type, | |
8838 | TYPE_READONLY (item_type), | |
8839 | TYPE_VOLATILE (item_type), | |
8840 | context_die); | |
8841 | ||
a3f97cbb | 8842 | if (sub_die != NULL) |
71dfc51f RK |
8843 | add_AT_die_ref (mod_type_die, DW_AT_type, sub_die); |
8844 | ||
a3f97cbb JW |
8845 | return mod_type_die; |
8846 | } | |
8847 | ||
a3f97cbb | 8848 | /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is |
6d2f8887 | 8849 | an enumerated type. */ |
71dfc51f RK |
8850 | |
8851 | static inline int | |
9678086d | 8852 | type_is_enum (const_tree type) |
a3f97cbb JW |
8853 | { |
8854 | return TREE_CODE (type) == ENUMERAL_TYPE; | |
8855 | } | |
8856 | ||
23959f19 | 8857 | /* Return the DBX register number described by a given RTL node. */ |
7d9d8943 AM |
8858 | |
8859 | static unsigned int | |
9678086d | 8860 | dbx_reg_number (const_rtx rtl) |
7d9d8943 | 8861 | { |
b3694847 | 8862 | unsigned regno = REGNO (rtl); |
7d9d8943 | 8863 | |
ced3f397 | 8864 | gcc_assert (regno < FIRST_PSEUDO_REGISTER); |
7d9d8943 | 8865 | |
30e6f306 | 8866 | #ifdef LEAF_REG_REMAP |
ea049a41 EB |
8867 | if (current_function_uses_only_leaf_regs) |
8868 | { | |
8869 | int leaf_reg = LEAF_REG_REMAP (regno); | |
8870 | if (leaf_reg != -1) | |
8871 | regno = (unsigned) leaf_reg; | |
8872 | } | |
30e6f306 RH |
8873 | #endif |
8874 | ||
e7af1d45 | 8875 | return DBX_REGISTER_NUMBER (regno); |
7d9d8943 AM |
8876 | } |
8877 | ||
216448c7 EB |
8878 | /* Optionally add a DW_OP_piece term to a location description expression. |
8879 | DW_OP_piece is only added if the location description expression already | |
8880 | doesn't end with DW_OP_piece. */ | |
8881 | ||
8882 | static void | |
8883 | add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size) | |
8884 | { | |
8885 | dw_loc_descr_ref loc; | |
8886 | ||
8887 | if (*list_head != NULL) | |
8888 | { | |
8889 | /* Find the end of the chain. */ | |
8890 | for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next) | |
8891 | ; | |
8892 | ||
8893 | if (loc->dw_loc_opc != DW_OP_piece) | |
8894 | loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0); | |
8895 | } | |
8896 | } | |
8897 | ||
e7af1d45 | 8898 | /* Return a location descriptor that designates a machine register or |
96714395 | 8899 | zero if there is none. */ |
71dfc51f | 8900 | |
a3f97cbb | 8901 | static dw_loc_descr_ref |
62760ffd | 8902 | reg_loc_descriptor (rtx rtl, enum var_init_status initialized) |
a3f97cbb | 8903 | { |
96714395 | 8904 | rtx regs; |
71dfc51f | 8905 | |
e7af1d45 RK |
8906 | if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER) |
8907 | return 0; | |
8908 | ||
5fd9b178 | 8909 | regs = targetm.dwarf_register_span (rtl); |
96714395 | 8910 | |
30e6f306 | 8911 | if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs) |
62760ffd | 8912 | return multiple_reg_loc_descriptor (rtl, regs, initialized); |
96714395 | 8913 | else |
62760ffd | 8914 | return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized); |
96714395 AH |
8915 | } |
8916 | ||
8917 | /* Return a location descriptor that designates a machine register for | |
8918 | a given hard register number. */ | |
8919 | ||
8920 | static dw_loc_descr_ref | |
62760ffd | 8921 | one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized) |
96714395 | 8922 | { |
62760ffd | 8923 | dw_loc_descr_ref reg_loc_descr; |
96714395 | 8924 | if (regno <= 31) |
62760ffd | 8925 | reg_loc_descr = new_loc_descr (DW_OP_reg0 + regno, 0, 0); |
d22c2324 | 8926 | else |
62760ffd CT |
8927 | reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0); |
8928 | ||
8929 | if (initialized == VAR_INIT_STATUS_UNINITIALIZED) | |
8930 | add_loc_descr (®_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0)); | |
8931 | ||
8932 | return reg_loc_descr; | |
96714395 AH |
8933 | } |
8934 | ||
8935 | /* Given an RTL of a register, return a location descriptor that | |
8936 | designates a value that spans more than one register. */ | |
8937 | ||
8938 | static dw_loc_descr_ref | |
4b570560 | 8939 | multiple_reg_loc_descriptor (rtx rtl, rtx regs, |
62760ffd | 8940 | enum var_init_status initialized) |
96714395 AH |
8941 | { |
8942 | int nregs, size, i; | |
8943 | unsigned reg; | |
8944 | dw_loc_descr_ref loc_result = NULL; | |
71dfc51f | 8945 | |
f9918968 JJ |
8946 | reg = REGNO (rtl); |
8947 | #ifdef LEAF_REG_REMAP | |
ea049a41 EB |
8948 | if (current_function_uses_only_leaf_regs) |
8949 | { | |
8950 | int leaf_reg = LEAF_REG_REMAP (reg); | |
8951 | if (leaf_reg != -1) | |
8952 | reg = (unsigned) leaf_reg; | |
8953 | } | |
f9918968 JJ |
8954 | #endif |
8955 | gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl)); | |
23959f19 | 8956 | nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)]; |
96714395 AH |
8957 | |
8958 | /* Simple, contiguous registers. */ | |
8959 | if (regs == NULL_RTX) | |
8960 | { | |
8961 | size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs; | |
8962 | ||
8963 | loc_result = NULL; | |
8964 | while (nregs--) | |
8965 | { | |
8966 | dw_loc_descr_ref t; | |
8967 | ||
62760ffd CT |
8968 | t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg), |
8969 | VAR_INIT_STATUS_INITIALIZED); | |
96714395 | 8970 | add_loc_descr (&loc_result, t); |
c938250d | 8971 | add_loc_descr_op_piece (&loc_result, size); |
31ca3635 | 8972 | ++reg; |
96714395 AH |
8973 | } |
8974 | return loc_result; | |
8975 | } | |
8976 | ||
8977 | /* Now onto stupid register sets in non contiguous locations. */ | |
8978 | ||
ced3f397 | 8979 | gcc_assert (GET_CODE (regs) == PARALLEL); |
96714395 AH |
8980 | |
8981 | size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0))); | |
8982 | loc_result = NULL; | |
8983 | ||
8984 | for (i = 0; i < XVECLEN (regs, 0); ++i) | |
8985 | { | |
8986 | dw_loc_descr_ref t; | |
8987 | ||
62760ffd CT |
8988 | t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)), |
8989 | VAR_INIT_STATUS_INITIALIZED); | |
96714395 AH |
8990 | add_loc_descr (&loc_result, t); |
8991 | size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0))); | |
c938250d | 8992 | add_loc_descr_op_piece (&loc_result, size); |
96714395 | 8993 | } |
62760ffd CT |
8994 | |
8995 | if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED) | |
8996 | add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0)); | |
a3f97cbb JW |
8997 | return loc_result; |
8998 | } | |
8999 | ||
d8041cc8 RH |
9000 | /* Return a location descriptor that designates a constant. */ |
9001 | ||
9002 | static dw_loc_descr_ref | |
7080f735 | 9003 | int_loc_descriptor (HOST_WIDE_INT i) |
d8041cc8 RH |
9004 | { |
9005 | enum dwarf_location_atom op; | |
9006 | ||
9007 | /* Pick the smallest representation of a constant, rather than just | |
9008 | defaulting to the LEB encoding. */ | |
9009 | if (i >= 0) | |
9010 | { | |
9011 | if (i <= 31) | |
9012 | op = DW_OP_lit0 + i; | |
9013 | else if (i <= 0xff) | |
9014 | op = DW_OP_const1u; | |
9015 | else if (i <= 0xffff) | |
9016 | op = DW_OP_const2u; | |
9017 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
9018 | || i <= 0xffffffff) | |
9019 | op = DW_OP_const4u; | |
9020 | else | |
9021 | op = DW_OP_constu; | |
9022 | } | |
9023 | else | |
9024 | { | |
9025 | if (i >= -0x80) | |
9026 | op = DW_OP_const1s; | |
9027 | else if (i >= -0x8000) | |
9028 | op = DW_OP_const2s; | |
9029 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
9030 | || i >= -0x80000000) | |
9031 | op = DW_OP_const4s; | |
9032 | else | |
9033 | op = DW_OP_consts; | |
9034 | } | |
9035 | ||
9036 | return new_loc_descr (op, i, 0); | |
9037 | } | |
9038 | ||
a3f97cbb | 9039 | /* Return a location descriptor that designates a base+offset location. */ |
71dfc51f | 9040 | |
a3f97cbb | 9041 | static dw_loc_descr_ref |
62760ffd CT |
9042 | based_loc_descr (rtx reg, HOST_WIDE_INT offset, |
9043 | enum var_init_status initialized) | |
a3f97cbb | 9044 | { |
f6672e8e | 9045 | unsigned int regno; |
62760ffd | 9046 | dw_loc_descr_ref result; |
30e6f306 RH |
9047 | |
9048 | /* We only use "frame base" when we're sure we're talking about the | |
9049 | post-prologue local stack frame. We do this by *not* running | |
9050 | register elimination until this point, and recognizing the special | |
9051 | argument pointer and soft frame pointer rtx's. */ | |
9052 | if (reg == arg_pointer_rtx || reg == frame_pointer_rtx) | |
9053 | { | |
f6672e8e | 9054 | rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX); |
30e6f306 | 9055 | |
f6672e8e RH |
9056 | if (elim != reg) |
9057 | { | |
9058 | if (GET_CODE (elim) == PLUS) | |
9059 | { | |
9060 | offset += INTVAL (XEXP (elim, 1)); | |
9061 | elim = XEXP (elim, 0); | |
9062 | } | |
9063 | gcc_assert (elim == (frame_pointer_needed ? hard_frame_pointer_rtx | |
9064 | : stack_pointer_rtx)); | |
2878ea73 | 9065 | offset += frame_pointer_fb_offset; |
30e6f306 | 9066 | |
2878ea73 | 9067 | return new_loc_descr (DW_OP_fbreg, offset, 0); |
f6672e8e | 9068 | } |
30e6f306 | 9069 | } |
71dfc51f | 9070 | |
f6672e8e RH |
9071 | regno = dbx_reg_number (reg); |
9072 | if (regno <= 31) | |
62760ffd | 9073 | result = new_loc_descr (DW_OP_breg0 + regno, offset, 0); |
f6672e8e | 9074 | else |
62760ffd CT |
9075 | result = new_loc_descr (DW_OP_bregx, regno, offset); |
9076 | ||
9077 | if (initialized == VAR_INIT_STATUS_UNINITIALIZED) | |
9078 | add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0)); | |
9079 | ||
9080 | return result; | |
a3f97cbb JW |
9081 | } |
9082 | ||
9083 | /* Return true if this RTL expression describes a base+offset calculation. */ | |
71dfc51f RK |
9084 | |
9085 | static inline int | |
9678086d | 9086 | is_based_loc (const_rtx rtl) |
a3f97cbb | 9087 | { |
173bf5be | 9088 | return (GET_CODE (rtl) == PLUS |
f8cfc6aa | 9089 | && ((REG_P (XEXP (rtl, 0)) |
173bf5be KH |
9090 | && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER |
9091 | && GET_CODE (XEXP (rtl, 1)) == CONST_INT))); | |
a3f97cbb JW |
9092 | } |
9093 | ||
0c5c188f ILT |
9094 | /* Return a descriptor that describes the concatenation of N locations |
9095 | used to form the address of a memory location. */ | |
9096 | ||
9097 | static dw_loc_descr_ref | |
62760ffd CT |
9098 | concatn_mem_loc_descriptor (rtx concatn, enum machine_mode mode, |
9099 | enum var_init_status initialized) | |
0c5c188f ILT |
9100 | { |
9101 | unsigned int i; | |
9102 | dw_loc_descr_ref cc_loc_result = NULL; | |
9103 | unsigned int n = XVECLEN (concatn, 0); | |
9104 | ||
9105 | for (i = 0; i < n; ++i) | |
9106 | { | |
9107 | dw_loc_descr_ref ref; | |
9108 | rtx x = XVECEXP (concatn, 0, i); | |
9109 | ||
62760ffd | 9110 | ref = mem_loc_descriptor (x, mode, VAR_INIT_STATUS_INITIALIZED); |
0c5c188f ILT |
9111 | if (ref == NULL) |
9112 | return NULL; | |
9113 | ||
9114 | add_loc_descr (&cc_loc_result, ref); | |
9115 | add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x))); | |
9116 | } | |
9117 | ||
62760ffd CT |
9118 | if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED) |
9119 | add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0)); | |
9120 | ||
0c5c188f ILT |
9121 | return cc_loc_result; |
9122 | } | |
9123 | ||
a3f97cbb JW |
9124 | /* The following routine converts the RTL for a variable or parameter |
9125 | (resident in memory) into an equivalent Dwarf representation of a | |
9126 | mechanism for getting the address of that same variable onto the top of a | |
9127 | hypothetical "address evaluation" stack. | |
71dfc51f | 9128 | |
a3f97cbb JW |
9129 | When creating memory location descriptors, we are effectively transforming |
9130 | the RTL for a memory-resident object into its Dwarf postfix expression | |
9131 | equivalent. This routine recursively descends an RTL tree, turning | |
e60d4d7b JL |
9132 | it into Dwarf postfix code as it goes. |
9133 | ||
9134 | MODE is the mode of the memory reference, needed to handle some | |
e7af1d45 RK |
9135 | autoincrement addressing modes. |
9136 | ||
30e6f306 RH |
9137 | CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the |
9138 | location list for RTL. | |
0a2d3d69 | 9139 | |
e7af1d45 | 9140 | Return 0 if we can't represent the location. */ |
71dfc51f | 9141 | |
a3f97cbb | 9142 | static dw_loc_descr_ref |
62760ffd CT |
9143 | mem_loc_descriptor (rtx rtl, enum machine_mode mode, |
9144 | enum var_init_status initialized) | |
a3f97cbb JW |
9145 | { |
9146 | dw_loc_descr_ref mem_loc_result = NULL; | |
40f0b3ee | 9147 | enum dwarf_location_atom op; |
e7af1d45 | 9148 | |
556273e0 | 9149 | /* Note that for a dynamically sized array, the location we will generate a |
a3f97cbb JW |
9150 | description of here will be the lowest numbered location which is |
9151 | actually within the array. That's *not* necessarily the same as the | |
9152 | zeroth element of the array. */ | |
71dfc51f | 9153 | |
5fd9b178 | 9154 | rtl = targetm.delegitimize_address (rtl); |
1865dbb5 | 9155 | |
a3f97cbb JW |
9156 | switch (GET_CODE (rtl)) |
9157 | { | |
e60d4d7b JL |
9158 | case POST_INC: |
9159 | case POST_DEC: | |
e2134eea | 9160 | case POST_MODIFY: |
e60d4d7b JL |
9161 | /* POST_INC and POST_DEC can be handled just like a SUBREG. So we |
9162 | just fall into the SUBREG code. */ | |
9163 | ||
2ad9852d | 9164 | /* ... fall through ... */ |
e60d4d7b | 9165 | |
a3f97cbb JW |
9166 | case SUBREG: |
9167 | /* The case of a subreg may arise when we have a local (register) | |
73c68f61 SS |
9168 | variable or a formal (register) parameter which doesn't quite fill |
9169 | up an entire register. For now, just assume that it is | |
9170 | legitimate to make the Dwarf info refer to the whole register which | |
9171 | contains the given subreg. */ | |
75735872 | 9172 | rtl = XEXP (rtl, 0); |
71dfc51f | 9173 | |
2ad9852d | 9174 | /* ... fall through ... */ |
a3f97cbb JW |
9175 | |
9176 | case REG: | |
9177 | /* Whenever a register number forms a part of the description of the | |
73c68f61 SS |
9178 | method for calculating the (dynamic) address of a memory resident |
9179 | object, DWARF rules require the register number be referred to as | |
9180 | a "base register". This distinction is not based in any way upon | |
9181 | what category of register the hardware believes the given register | |
9182 | belongs to. This is strictly DWARF terminology we're dealing with | |
9183 | here. Note that in cases where the location of a memory-resident | |
9184 | data object could be expressed as: OP_ADD (OP_BASEREG (basereg), | |
9185 | OP_CONST (0)) the actual DWARF location descriptor that we generate | |
9186 | may just be OP_BASEREG (basereg). This may look deceptively like | |
9187 | the object in question was allocated to a register (rather than in | |
9188 | memory) so DWARF consumers need to be aware of the subtle | |
9189 | distinction between OP_REG and OP_BASEREG. */ | |
e7af1d45 | 9190 | if (REGNO (rtl) < FIRST_PSEUDO_REGISTER) |
62760ffd | 9191 | mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED); |
a3f97cbb JW |
9192 | break; |
9193 | ||
9194 | case MEM: | |
62760ffd CT |
9195 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl), |
9196 | VAR_INIT_STATUS_INITIALIZED); | |
e7af1d45 RK |
9197 | if (mem_loc_result != 0) |
9198 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0)); | |
a3f97cbb JW |
9199 | break; |
9200 | ||
1ce324c3 EB |
9201 | case LO_SUM: |
9202 | rtl = XEXP (rtl, 1); | |
9203 | ||
9204 | /* ... fall through ... */ | |
9205 | ||
d8041cc8 RH |
9206 | case LABEL_REF: |
9207 | /* Some ports can transform a symbol ref into a label ref, because | |
7080f735 AJ |
9208 | the symbol ref is too far away and has to be dumped into a constant |
9209 | pool. */ | |
a3f97cbb JW |
9210 | case CONST: |
9211 | case SYMBOL_REF: | |
6331d1c1 | 9212 | /* Alternatively, the symbol in the constant pool might be referenced |
c6f9b9a1 | 9213 | by a different symbol. */ |
2ad9852d | 9214 | if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl)) |
79cdfa4b | 9215 | { |
149d6f9e JJ |
9216 | bool marked; |
9217 | rtx tmp = get_pool_constant_mark (rtl, &marked); | |
2ad9852d | 9218 | |
6331d1c1 | 9219 | if (GET_CODE (tmp) == SYMBOL_REF) |
149d6f9e JJ |
9220 | { |
9221 | rtl = tmp; | |
9222 | if (CONSTANT_POOL_ADDRESS_P (tmp)) | |
9223 | get_pool_constant_mark (tmp, &marked); | |
9224 | else | |
9225 | marked = true; | |
9226 | } | |
9227 | ||
9228 | /* If all references to this pool constant were optimized away, | |
9229 | it was not output and thus we can't represent it. | |
9230 | FIXME: might try to use DW_OP_const_value here, though | |
9231 | DW_OP_piece complicates it. */ | |
9232 | if (!marked) | |
9233 | return 0; | |
79cdfa4b TM |
9234 | } |
9235 | ||
a3f97cbb JW |
9236 | mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0); |
9237 | mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
c470afad | 9238 | mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl; |
a1bbd445 | 9239 | VEC_safe_push (rtx, gc, used_rtx_array, rtl); |
a3f97cbb JW |
9240 | break; |
9241 | ||
e2134eea JH |
9242 | case PRE_MODIFY: |
9243 | /* Extract the PLUS expression nested inside and fall into | |
73c68f61 | 9244 | PLUS code below. */ |
e2134eea JH |
9245 | rtl = XEXP (rtl, 1); |
9246 | goto plus; | |
9247 | ||
e60d4d7b JL |
9248 | case PRE_INC: |
9249 | case PRE_DEC: | |
9250 | /* Turn these into a PLUS expression and fall into the PLUS code | |
9251 | below. */ | |
9252 | rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0), | |
9253 | GEN_INT (GET_CODE (rtl) == PRE_INC | |
556273e0 KH |
9254 | ? GET_MODE_UNIT_SIZE (mode) |
9255 | : -GET_MODE_UNIT_SIZE (mode))); | |
9256 | ||
2ad9852d | 9257 | /* ... fall through ... */ |
e60d4d7b | 9258 | |
a3f97cbb | 9259 | case PLUS: |
e2134eea | 9260 | plus: |
a3f97cbb | 9261 | if (is_based_loc (rtl)) |
30e6f306 | 9262 | mem_loc_result = based_loc_descr (XEXP (rtl, 0), |
62760ffd CT |
9263 | INTVAL (XEXP (rtl, 1)), |
9264 | VAR_INIT_STATUS_INITIALIZED); | |
a3f97cbb JW |
9265 | else |
9266 | { | |
62760ffd CT |
9267 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, |
9268 | VAR_INIT_STATUS_INITIALIZED); | |
e7af1d45 RK |
9269 | if (mem_loc_result == 0) |
9270 | break; | |
d8041cc8 RH |
9271 | |
9272 | if (GET_CODE (XEXP (rtl, 1)) == CONST_INT | |
9273 | && INTVAL (XEXP (rtl, 1)) >= 0) | |
e7af1d45 RK |
9274 | add_loc_descr (&mem_loc_result, |
9275 | new_loc_descr (DW_OP_plus_uconst, | |
9276 | INTVAL (XEXP (rtl, 1)), 0)); | |
d8041cc8 RH |
9277 | else |
9278 | { | |
9279 | add_loc_descr (&mem_loc_result, | |
62760ffd CT |
9280 | mem_loc_descriptor (XEXP (rtl, 1), mode, |
9281 | VAR_INIT_STATUS_INITIALIZED)); | |
d8041cc8 RH |
9282 | add_loc_descr (&mem_loc_result, |
9283 | new_loc_descr (DW_OP_plus, 0, 0)); | |
9284 | } | |
a3f97cbb JW |
9285 | } |
9286 | break; | |
9287 | ||
40f0b3ee PB |
9288 | /* If a pseudo-reg is optimized away, it is possible for it to |
9289 | be replaced with a MEM containing a multiply or shift. */ | |
dd2478ae | 9290 | case MULT: |
40f0b3ee PB |
9291 | op = DW_OP_mul; |
9292 | goto do_binop; | |
9293 | ||
9294 | case ASHIFT: | |
9295 | op = DW_OP_shl; | |
9296 | goto do_binop; | |
a1c496cb | 9297 | |
40f0b3ee PB |
9298 | case ASHIFTRT: |
9299 | op = DW_OP_shra; | |
9300 | goto do_binop; | |
9301 | ||
9302 | case LSHIFTRT: | |
9303 | op = DW_OP_shr; | |
9304 | goto do_binop; | |
9305 | ||
9306 | do_binop: | |
e7af1d45 | 9307 | { |
62760ffd CT |
9308 | dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, |
9309 | VAR_INIT_STATUS_INITIALIZED); | |
9310 | dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, | |
9311 | VAR_INIT_STATUS_INITIALIZED); | |
e7af1d45 RK |
9312 | |
9313 | if (op0 == 0 || op1 == 0) | |
9314 | break; | |
9315 | ||
9316 | mem_loc_result = op0; | |
9317 | add_loc_descr (&mem_loc_result, op1); | |
40f0b3ee | 9318 | add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0)); |
e7af1d45 RK |
9319 | break; |
9320 | } | |
dd2478ae | 9321 | |
a3f97cbb | 9322 | case CONST_INT: |
d8041cc8 | 9323 | mem_loc_result = int_loc_descriptor (INTVAL (rtl)); |
a3f97cbb JW |
9324 | break; |
9325 | ||
0c5c188f | 9326 | case CONCATN: |
4b570560 | 9327 | mem_loc_result = concatn_mem_loc_descriptor (rtl, mode, |
62760ffd | 9328 | VAR_INIT_STATUS_INITIALIZED); |
0c5c188f ILT |
9329 | break; |
9330 | ||
a3f97cbb | 9331 | default: |
ced3f397 | 9332 | gcc_unreachable (); |
a3f97cbb | 9333 | } |
71dfc51f | 9334 | |
62760ffd CT |
9335 | if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED) |
9336 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0)); | |
9337 | ||
a3f97cbb JW |
9338 | return mem_loc_result; |
9339 | } | |
9340 | ||
956d6950 | 9341 | /* Return a descriptor that describes the concatenation of two locations. |
4401bf24 JL |
9342 | This is typically a complex variable. */ |
9343 | ||
9344 | static dw_loc_descr_ref | |
62760ffd | 9345 | concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized) |
4401bf24 JL |
9346 | { |
9347 | dw_loc_descr_ref cc_loc_result = NULL; | |
62760ffd CT |
9348 | dw_loc_descr_ref x0_ref = loc_descriptor (x0, VAR_INIT_STATUS_INITIALIZED); |
9349 | dw_loc_descr_ref x1_ref = loc_descriptor (x1, VAR_INIT_STATUS_INITIALIZED); | |
4401bf24 | 9350 | |
e7af1d45 RK |
9351 | if (x0_ref == 0 || x1_ref == 0) |
9352 | return 0; | |
9353 | ||
9354 | cc_loc_result = x0_ref; | |
c938250d | 9355 | add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0))); |
4401bf24 | 9356 | |
e7af1d45 | 9357 | add_loc_descr (&cc_loc_result, x1_ref); |
c938250d | 9358 | add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1))); |
4401bf24 | 9359 | |
62760ffd CT |
9360 | if (initialized == VAR_INIT_STATUS_UNINITIALIZED) |
9361 | add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0)); | |
9362 | ||
4401bf24 JL |
9363 | return cc_loc_result; |
9364 | } | |
9365 | ||
e53a16e7 ILT |
9366 | /* Return a descriptor that describes the concatenation of N |
9367 | locations. */ | |
9368 | ||
9369 | static dw_loc_descr_ref | |
62760ffd | 9370 | concatn_loc_descriptor (rtx concatn, enum var_init_status initialized) |
e53a16e7 ILT |
9371 | { |
9372 | unsigned int i; | |
9373 | dw_loc_descr_ref cc_loc_result = NULL; | |
9374 | unsigned int n = XVECLEN (concatn, 0); | |
9375 | ||
9376 | for (i = 0; i < n; ++i) | |
9377 | { | |
9378 | dw_loc_descr_ref ref; | |
9379 | rtx x = XVECEXP (concatn, 0, i); | |
9380 | ||
62760ffd | 9381 | ref = loc_descriptor (x, VAR_INIT_STATUS_INITIALIZED); |
e53a16e7 ILT |
9382 | if (ref == NULL) |
9383 | return NULL; | |
9384 | ||
9385 | add_loc_descr (&cc_loc_result, ref); | |
9386 | add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x))); | |
9387 | } | |
9388 | ||
62760ffd CT |
9389 | if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED) |
9390 | add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0)); | |
9391 | ||
e53a16e7 ILT |
9392 | return cc_loc_result; |
9393 | } | |
9394 | ||
a3f97cbb JW |
9395 | /* Output a proper Dwarf location descriptor for a variable or parameter |
9396 | which is either allocated in a register or in a memory location. For a | |
9397 | register, we just generate an OP_REG and the register number. For a | |
9398 | memory location we provide a Dwarf postfix expression describing how to | |
e7af1d45 RK |
9399 | generate the (dynamic) address of the object onto the address stack. |
9400 | ||
9401 | If we don't know how to describe it, return 0. */ | |
71dfc51f | 9402 | |
a3f97cbb | 9403 | static dw_loc_descr_ref |
62760ffd | 9404 | loc_descriptor (rtx rtl, enum var_init_status initialized) |
a3f97cbb JW |
9405 | { |
9406 | dw_loc_descr_ref loc_result = NULL; | |
e7af1d45 | 9407 | |
a3f97cbb JW |
9408 | switch (GET_CODE (rtl)) |
9409 | { | |
9410 | case SUBREG: | |
a3f97cbb | 9411 | /* The case of a subreg may arise when we have a local (register) |
73c68f61 SS |
9412 | variable or a formal (register) parameter which doesn't quite fill |
9413 | up an entire register. For now, just assume that it is | |
9414 | legitimate to make the Dwarf info refer to the whole register which | |
9415 | contains the given subreg. */ | |
ddef6bc7 | 9416 | rtl = SUBREG_REG (rtl); |
71dfc51f | 9417 | |
2ad9852d | 9418 | /* ... fall through ... */ |
a3f97cbb JW |
9419 | |
9420 | case REG: | |
62760ffd | 9421 | loc_result = reg_loc_descriptor (rtl, initialized); |
a3f97cbb JW |
9422 | break; |
9423 | ||
9424 | case MEM: | |
62760ffd CT |
9425 | loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl), |
9426 | initialized); | |
a3f97cbb JW |
9427 | break; |
9428 | ||
4401bf24 | 9429 | case CONCAT: |
62760ffd CT |
9430 | loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1), |
9431 | initialized); | |
4401bf24 JL |
9432 | break; |
9433 | ||
e53a16e7 | 9434 | case CONCATN: |
62760ffd | 9435 | loc_result = concatn_loc_descriptor (rtl, initialized); |
e53a16e7 ILT |
9436 | break; |
9437 | ||
0a2d3d69 DB |
9438 | case VAR_LOCATION: |
9439 | /* Single part. */ | |
9440 | if (GET_CODE (XEXP (rtl, 1)) != PARALLEL) | |
9441 | { | |
62760ffd | 9442 | loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), initialized); |
1a186ec5 | 9443 | break; |
0a2d3d69 | 9444 | } |
0a2d3d69 | 9445 | |
1a186ec5 RH |
9446 | rtl = XEXP (rtl, 1); |
9447 | /* FALLTHRU */ | |
0a2d3d69 | 9448 | |
1a186ec5 RH |
9449 | case PARALLEL: |
9450 | { | |
9451 | rtvec par_elems = XVEC (rtl, 0); | |
9452 | int num_elem = GET_NUM_ELEM (par_elems); | |
9453 | enum machine_mode mode; | |
9454 | int i; | |
9455 | ||
9456 | /* Create the first one, so we have something to add to. */ | |
62760ffd CT |
9457 | loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0), |
9458 | initialized); | |
1a186ec5 | 9459 | mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0)); |
c938250d | 9460 | add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode)); |
1a186ec5 RH |
9461 | for (i = 1; i < num_elem; i++) |
9462 | { | |
9463 | dw_loc_descr_ref temp; | |
9464 | ||
62760ffd CT |
9465 | temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0), |
9466 | initialized); | |
1a186ec5 RH |
9467 | add_loc_descr (&loc_result, temp); |
9468 | mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0)); | |
c938250d | 9469 | add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode)); |
1a186ec5 RH |
9470 | } |
9471 | } | |
0a2d3d69 DB |
9472 | break; |
9473 | ||
a3f97cbb | 9474 | default: |
ced3f397 | 9475 | gcc_unreachable (); |
a3f97cbb | 9476 | } |
71dfc51f | 9477 | |
a3f97cbb JW |
9478 | return loc_result; |
9479 | } | |
9480 | ||
2ad9852d | 9481 | /* Similar, but generate the descriptor from trees instead of rtl. This comes |
1a186ec5 RH |
9482 | up particularly with variable length arrays. WANT_ADDRESS is 2 if this is |
9483 | a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a | |
9484 | top-level invocation, and we require the address of LOC; is 0 if we require | |
9485 | the value of LOC. */ | |
d8041cc8 RH |
9486 | |
9487 | static dw_loc_descr_ref | |
1a186ec5 | 9488 | loc_descriptor_from_tree_1 (tree loc, int want_address) |
d8041cc8 | 9489 | { |
e7af1d45 | 9490 | dw_loc_descr_ref ret, ret1; |
1a186ec5 | 9491 | int have_address = 0; |
d8041cc8 RH |
9492 | enum dwarf_location_atom op; |
9493 | ||
9494 | /* ??? Most of the time we do not take proper care for sign/zero | |
9495 | extending the values properly. Hopefully this won't be a real | |
9496 | problem... */ | |
9497 | ||
9498 | switch (TREE_CODE (loc)) | |
9499 | { | |
9500 | case ERROR_MARK: | |
e7af1d45 | 9501 | return 0; |
d8041cc8 | 9502 | |
e7af1d45 | 9503 | case PLACEHOLDER_EXPR: |
b4ae5201 RK |
9504 | /* This case involves extracting fields from an object to determine the |
9505 | position of other fields. We don't try to encode this here. The | |
9506 | only user of this is Ada, which encodes the needed information using | |
9507 | the names of types. */ | |
e7af1d45 | 9508 | return 0; |
b4ae5201 | 9509 | |
aea9695c RK |
9510 | case CALL_EXPR: |
9511 | return 0; | |
9512 | ||
4ada538b MM |
9513 | case PREINCREMENT_EXPR: |
9514 | case PREDECREMENT_EXPR: | |
9515 | case POSTINCREMENT_EXPR: | |
9516 | case POSTDECREMENT_EXPR: | |
9517 | /* There are no opcodes for these operations. */ | |
9518 | return 0; | |
9519 | ||
aea9695c | 9520 | case ADDR_EXPR: |
1a186ec5 RH |
9521 | /* If we already want an address, there's nothing we can do. */ |
9522 | if (want_address) | |
9523 | return 0; | |
aea9695c | 9524 | |
1a186ec5 RH |
9525 | /* Otherwise, process the argument and look for the address. */ |
9526 | return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1); | |
aea9695c | 9527 | |
d8041cc8 | 9528 | case VAR_DECL: |
c2f7fa15 | 9529 | if (DECL_THREAD_LOCAL_P (loc)) |
b9203463 RH |
9530 | { |
9531 | rtx rtl; | |
feb60f03 NS |
9532 | unsigned first_op; |
9533 | unsigned second_op; | |
b9203463 | 9534 | |
feb60f03 NS |
9535 | if (targetm.have_tls) |
9536 | { | |
9537 | /* If this is not defined, we have no way to emit the | |
9538 | data. */ | |
9539 | if (!targetm.asm_out.output_dwarf_dtprel) | |
9540 | return 0; | |
9541 | ||
9542 | /* The way DW_OP_GNU_push_tls_address is specified, we | |
9543 | can only look up addresses of objects in the current | |
9544 | module. */ | |
9545 | if (DECL_EXTERNAL (loc)) | |
9546 | return 0; | |
9547 | first_op = INTERNAL_DW_OP_tls_addr; | |
9548 | second_op = DW_OP_GNU_push_tls_address; | |
9549 | } | |
9550 | else | |
9551 | { | |
9552 | if (!targetm.emutls.debug_form_tls_address) | |
9553 | return 0; | |
9554 | loc = emutls_decl (loc); | |
9555 | first_op = DW_OP_addr; | |
9556 | second_op = DW_OP_form_tls_address; | |
9557 | } | |
4b570560 | 9558 | |
b9203463 RH |
9559 | rtl = rtl_for_decl_location (loc); |
9560 | if (rtl == NULL_RTX) | |
9561 | return 0; | |
9562 | ||
3c0cb5de | 9563 | if (!MEM_P (rtl)) |
b9203463 RH |
9564 | return 0; |
9565 | rtl = XEXP (rtl, 0); | |
9566 | if (! CONSTANT_P (rtl)) | |
9567 | return 0; | |
9568 | ||
feb60f03 | 9569 | ret = new_loc_descr (first_op, 0, 0); |
b9203463 RH |
9570 | ret->dw_loc_oprnd1.val_class = dw_val_class_addr; |
9571 | ret->dw_loc_oprnd1.v.val_addr = rtl; | |
4b570560 | 9572 | |
feb60f03 | 9573 | ret1 = new_loc_descr (second_op, 0, 0); |
b9203463 RH |
9574 | add_loc_descr (&ret, ret1); |
9575 | ||
1a186ec5 | 9576 | have_address = 1; |
b9203463 RH |
9577 | break; |
9578 | } | |
1a186ec5 | 9579 | /* FALLTHRU */ |
b9203463 | 9580 | |
d8041cc8 | 9581 | case PARM_DECL: |
833b3afe DB |
9582 | if (DECL_HAS_VALUE_EXPR_P (loc)) |
9583 | return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc), | |
9584 | want_address); | |
1a186ec5 RH |
9585 | /* FALLTHRU */ |
9586 | ||
6de9cd9a | 9587 | case RESULT_DECL: |
3c3f1a6f | 9588 | case FUNCTION_DECL: |
d8041cc8 RH |
9589 | { |
9590 | rtx rtl = rtl_for_decl_location (loc); | |
d8041cc8 | 9591 | |
a97c9600 | 9592 | if (rtl == NULL_RTX) |
e7af1d45 | 9593 | return 0; |
2878ea73 | 9594 | else if (GET_CODE (rtl) == CONST_INT) |
1a186ec5 RH |
9595 | { |
9596 | HOST_WIDE_INT val = INTVAL (rtl); | |
9597 | if (TYPE_UNSIGNED (TREE_TYPE (loc))) | |
9598 | val &= GET_MODE_MASK (DECL_MODE (loc)); | |
9599 | ret = int_loc_descriptor (val); | |
9600 | } | |
9601 | else if (GET_CODE (rtl) == CONST_STRING) | |
9602 | return 0; | |
a97c9600 | 9603 | else if (CONSTANT_P (rtl)) |
d8041cc8 RH |
9604 | { |
9605 | ret = new_loc_descr (DW_OP_addr, 0, 0); | |
9606 | ret->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
9607 | ret->dw_loc_oprnd1.v.val_addr = rtl; | |
d8041cc8 RH |
9608 | } |
9609 | else | |
9610 | { | |
1a186ec5 RH |
9611 | enum machine_mode mode; |
9612 | ||
9613 | /* Certain constructs can only be represented at top-level. */ | |
9614 | if (want_address == 2) | |
62760ffd | 9615 | return loc_descriptor (rtl, VAR_INIT_STATUS_INITIALIZED); |
c28abdf0 | 9616 | |
1a186ec5 | 9617 | mode = GET_MODE (rtl); |
3c0cb5de | 9618 | if (MEM_P (rtl)) |
d8041cc8 | 9619 | { |
d8041cc8 | 9620 | rtl = XEXP (rtl, 0); |
1a186ec5 | 9621 | have_address = 1; |
d8041cc8 | 9622 | } |
62760ffd | 9623 | ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED); |
d8041cc8 RH |
9624 | } |
9625 | } | |
9626 | break; | |
9627 | ||
9628 | case INDIRECT_REF: | |
1a186ec5 RH |
9629 | ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0); |
9630 | have_address = 1; | |
d8041cc8 RH |
9631 | break; |
9632 | ||
749552c4 | 9633 | case COMPOUND_EXPR: |
1a186ec5 | 9634 | return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address); |
749552c4 | 9635 | |
1043771b | 9636 | CASE_CONVERT: |
ed239f5a | 9637 | case VIEW_CONVERT_EXPR: |
b4ae5201 | 9638 | case SAVE_EXPR: |
07beea0d AH |
9639 | case GIMPLE_MODIFY_STMT: |
9640 | return loc_descriptor_from_tree_1 (GENERIC_TREE_OPERAND (loc, 0), | |
9641 | want_address); | |
e57cabac | 9642 | |
d8041cc8 RH |
9643 | case COMPONENT_REF: |
9644 | case BIT_FIELD_REF: | |
9645 | case ARRAY_REF: | |
b4e3fabb | 9646 | case ARRAY_RANGE_REF: |
d8041cc8 RH |
9647 | { |
9648 | tree obj, offset; | |
9649 | HOST_WIDE_INT bitsize, bitpos, bytepos; | |
9650 | enum machine_mode mode; | |
9651 | int volatilep; | |
953ff289 | 9652 | int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc)); |
d8041cc8 RH |
9653 | |
9654 | obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode, | |
2614034e | 9655 | &unsignedp, &volatilep, false); |
e7af1d45 RK |
9656 | |
9657 | if (obj == loc) | |
9658 | return 0; | |
9659 | ||
1a186ec5 | 9660 | ret = loc_descriptor_from_tree_1 (obj, 1); |
e7af1d45 | 9661 | if (ret == 0 |
2ad9852d | 9662 | || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0) |
e7af1d45 | 9663 | return 0; |
d8041cc8 RH |
9664 | |
9665 | if (offset != NULL_TREE) | |
9666 | { | |
9667 | /* Variable offset. */ | |
1a186ec5 | 9668 | add_loc_descr (&ret, loc_descriptor_from_tree_1 (offset, 0)); |
d8041cc8 RH |
9669 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); |
9670 | } | |
9671 | ||
d8041cc8 RH |
9672 | bytepos = bitpos / BITS_PER_UNIT; |
9673 | if (bytepos > 0) | |
9674 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0)); | |
9675 | else if (bytepos < 0) | |
9676 | { | |
9677 | add_loc_descr (&ret, int_loc_descriptor (bytepos)); | |
9678 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
9679 | } | |
1a186ec5 RH |
9680 | |
9681 | have_address = 1; | |
d8041cc8 RH |
9682 | break; |
9683 | } | |
9684 | ||
9685 | case INTEGER_CST: | |
9686 | if (host_integerp (loc, 0)) | |
9687 | ret = int_loc_descriptor (tree_low_cst (loc, 0)); | |
e7af1d45 RK |
9688 | else |
9689 | return 0; | |
d8041cc8 | 9690 | break; |
d8041cc8 | 9691 | |
c67b2a58 RK |
9692 | case CONSTRUCTOR: |
9693 | { | |
75c20980 RH |
9694 | /* Get an RTL for this, if something has been emitted. */ |
9695 | rtx rtl = lookup_constant_def (loc); | |
9696 | enum machine_mode mode; | |
9697 | ||
1a186ec5 | 9698 | if (!rtl || !MEM_P (rtl)) |
75c20980 RH |
9699 | return 0; |
9700 | mode = GET_MODE (rtl); | |
9701 | rtl = XEXP (rtl, 0); | |
62760ffd | 9702 | ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED); |
1a186ec5 | 9703 | have_address = 1; |
c67b2a58 RK |
9704 | break; |
9705 | } | |
9706 | ||
c26fbbca | 9707 | case TRUTH_AND_EXPR: |
9702143f | 9708 | case TRUTH_ANDIF_EXPR: |
d8041cc8 RH |
9709 | case BIT_AND_EXPR: |
9710 | op = DW_OP_and; | |
9711 | goto do_binop; | |
e7af1d45 | 9712 | |
9702143f | 9713 | case TRUTH_XOR_EXPR: |
d8041cc8 RH |
9714 | case BIT_XOR_EXPR: |
9715 | op = DW_OP_xor; | |
9716 | goto do_binop; | |
e7af1d45 | 9717 | |
9702143f RK |
9718 | case TRUTH_OR_EXPR: |
9719 | case TRUTH_ORIF_EXPR: | |
d8041cc8 RH |
9720 | case BIT_IOR_EXPR: |
9721 | op = DW_OP_or; | |
9722 | goto do_binop; | |
e7af1d45 | 9723 | |
8dcea3f3 VC |
9724 | case FLOOR_DIV_EXPR: |
9725 | case CEIL_DIV_EXPR: | |
9726 | case ROUND_DIV_EXPR: | |
d8041cc8 RH |
9727 | case TRUNC_DIV_EXPR: |
9728 | op = DW_OP_div; | |
9729 | goto do_binop; | |
e7af1d45 | 9730 | |
d8041cc8 RH |
9731 | case MINUS_EXPR: |
9732 | op = DW_OP_minus; | |
9733 | goto do_binop; | |
e7af1d45 | 9734 | |
8dcea3f3 VC |
9735 | case FLOOR_MOD_EXPR: |
9736 | case CEIL_MOD_EXPR: | |
9737 | case ROUND_MOD_EXPR: | |
d8041cc8 RH |
9738 | case TRUNC_MOD_EXPR: |
9739 | op = DW_OP_mod; | |
9740 | goto do_binop; | |
e7af1d45 | 9741 | |
d8041cc8 RH |
9742 | case MULT_EXPR: |
9743 | op = DW_OP_mul; | |
9744 | goto do_binop; | |
e7af1d45 | 9745 | |
d8041cc8 RH |
9746 | case LSHIFT_EXPR: |
9747 | op = DW_OP_shl; | |
9748 | goto do_binop; | |
e7af1d45 | 9749 | |
d8041cc8 | 9750 | case RSHIFT_EXPR: |
953ff289 | 9751 | op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra); |
d8041cc8 | 9752 | goto do_binop; |
e7af1d45 | 9753 | |
5be014d5 | 9754 | case POINTER_PLUS_EXPR: |
d8041cc8 RH |
9755 | case PLUS_EXPR: |
9756 | if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST | |
9757 | && host_integerp (TREE_OPERAND (loc, 1), 0)) | |
9758 | { | |
1a186ec5 | 9759 | ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0); |
e7af1d45 RK |
9760 | if (ret == 0) |
9761 | return 0; | |
9762 | ||
d8041cc8 RH |
9763 | add_loc_descr (&ret, |
9764 | new_loc_descr (DW_OP_plus_uconst, | |
9765 | tree_low_cst (TREE_OPERAND (loc, 1), | |
9766 | 0), | |
9767 | 0)); | |
9768 | break; | |
9769 | } | |
e7af1d45 | 9770 | |
d8041cc8 RH |
9771 | op = DW_OP_plus; |
9772 | goto do_binop; | |
2ad9852d | 9773 | |
d8041cc8 | 9774 | case LE_EXPR: |
8df83eae | 9775 | if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) |
e7af1d45 RK |
9776 | return 0; |
9777 | ||
d8041cc8 RH |
9778 | op = DW_OP_le; |
9779 | goto do_binop; | |
e7af1d45 | 9780 | |
d8041cc8 | 9781 | case GE_EXPR: |
8df83eae | 9782 | if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) |
e7af1d45 RK |
9783 | return 0; |
9784 | ||
d8041cc8 RH |
9785 | op = DW_OP_ge; |
9786 | goto do_binop; | |
e7af1d45 | 9787 | |
d8041cc8 | 9788 | case LT_EXPR: |
8df83eae | 9789 | if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) |
e7af1d45 RK |
9790 | return 0; |
9791 | ||
d8041cc8 RH |
9792 | op = DW_OP_lt; |
9793 | goto do_binop; | |
e7af1d45 | 9794 | |
d8041cc8 | 9795 | case GT_EXPR: |
8df83eae | 9796 | if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) |
e7af1d45 RK |
9797 | return 0; |
9798 | ||
d8041cc8 RH |
9799 | op = DW_OP_gt; |
9800 | goto do_binop; | |
e7af1d45 | 9801 | |
d8041cc8 RH |
9802 | case EQ_EXPR: |
9803 | op = DW_OP_eq; | |
9804 | goto do_binop; | |
e7af1d45 | 9805 | |
d8041cc8 RH |
9806 | case NE_EXPR: |
9807 | op = DW_OP_ne; | |
9808 | goto do_binop; | |
9809 | ||
9810 | do_binop: | |
1a186ec5 RH |
9811 | ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0); |
9812 | ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0); | |
e7af1d45 RK |
9813 | if (ret == 0 || ret1 == 0) |
9814 | return 0; | |
9815 | ||
9816 | add_loc_descr (&ret, ret1); | |
d8041cc8 RH |
9817 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); |
9818 | break; | |
9819 | ||
9702143f | 9820 | case TRUTH_NOT_EXPR: |
d8041cc8 RH |
9821 | case BIT_NOT_EXPR: |
9822 | op = DW_OP_not; | |
9823 | goto do_unop; | |
e7af1d45 | 9824 | |
d8041cc8 RH |
9825 | case ABS_EXPR: |
9826 | op = DW_OP_abs; | |
9827 | goto do_unop; | |
e7af1d45 | 9828 | |
d8041cc8 RH |
9829 | case NEGATE_EXPR: |
9830 | op = DW_OP_neg; | |
9831 | goto do_unop; | |
9832 | ||
9833 | do_unop: | |
1a186ec5 | 9834 | ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0); |
e7af1d45 RK |
9835 | if (ret == 0) |
9836 | return 0; | |
9837 | ||
d8041cc8 RH |
9838 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); |
9839 | break; | |
9840 | ||
fd5580cb | 9841 | case MIN_EXPR: |
d8041cc8 | 9842 | case MAX_EXPR: |
fd5580cb | 9843 | { |
2878ea73 MS |
9844 | const enum tree_code code = |
9845 | TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR; | |
fd5580cb | 9846 | |
2878ea73 | 9847 | loc = build3 (COND_EXPR, TREE_TYPE (loc), |
3244e67d RS |
9848 | build2 (code, integer_type_node, |
9849 | TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)), | |
2878ea73 | 9850 | TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0)); |
fd5580cb | 9851 | } |
2ad9852d | 9852 | |
3ef42a0c | 9853 | /* ... fall through ... */ |
d8041cc8 RH |
9854 | |
9855 | case COND_EXPR: | |
9856 | { | |
e7af1d45 | 9857 | dw_loc_descr_ref lhs |
1a186ec5 | 9858 | = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0); |
e7af1d45 | 9859 | dw_loc_descr_ref rhs |
1a186ec5 | 9860 | = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0); |
d8041cc8 RH |
9861 | dw_loc_descr_ref bra_node, jump_node, tmp; |
9862 | ||
1a186ec5 | 9863 | ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0); |
e7af1d45 RK |
9864 | if (ret == 0 || lhs == 0 || rhs == 0) |
9865 | return 0; | |
9866 | ||
d8041cc8 RH |
9867 | bra_node = new_loc_descr (DW_OP_bra, 0, 0); |
9868 | add_loc_descr (&ret, bra_node); | |
9869 | ||
e7af1d45 | 9870 | add_loc_descr (&ret, rhs); |
d8041cc8 RH |
9871 | jump_node = new_loc_descr (DW_OP_skip, 0, 0); |
9872 | add_loc_descr (&ret, jump_node); | |
9873 | ||
e7af1d45 | 9874 | add_loc_descr (&ret, lhs); |
d8041cc8 | 9875 | bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc; |
e7af1d45 | 9876 | bra_node->dw_loc_oprnd1.v.val_loc = lhs; |
d8041cc8 RH |
9877 | |
9878 | /* ??? Need a node to point the skip at. Use a nop. */ | |
9879 | tmp = new_loc_descr (DW_OP_nop, 0, 0); | |
9880 | add_loc_descr (&ret, tmp); | |
9881 | jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc; | |
9882 | jump_node->dw_loc_oprnd1.v.val_loc = tmp; | |
9883 | } | |
9884 | break; | |
9885 | ||
0ba6c56d | 9886 | case FIX_TRUNC_EXPR: |
0ba6c56d RH |
9887 | return 0; |
9888 | ||
d8041cc8 | 9889 | default: |
7d445f15 RH |
9890 | /* Leave front-end specific codes as simply unknown. This comes |
9891 | up, for instance, with the C STMT_EXPR. */ | |
9892 | if ((unsigned int) TREE_CODE (loc) | |
2878ea73 | 9893 | >= (unsigned int) LAST_AND_UNUSED_TREE_CODE) |
7d445f15 RH |
9894 | return 0; |
9895 | ||
c3f216e2 | 9896 | #ifdef ENABLE_CHECKING |
7d445f15 | 9897 | /* Otherwise this is a generic code; we should just lists all of |
535a42b1 | 9898 | these explicitly. We forgot one. */ |
ced3f397 | 9899 | gcc_unreachable (); |
c3f216e2 MM |
9900 | #else |
9901 | /* In a release build, we want to degrade gracefully: better to | |
9902 | generate incomplete debugging information than to crash. */ | |
9903 | return NULL; | |
9904 | #endif | |
d8041cc8 RH |
9905 | } |
9906 | ||
e7af1d45 | 9907 | /* Show if we can't fill the request for an address. */ |
1a186ec5 | 9908 | if (want_address && !have_address) |
e7af1d45 | 9909 | return 0; |
d8041cc8 RH |
9910 | |
9911 | /* If we've got an address and don't want one, dereference. */ | |
434eba35 | 9912 | if (!want_address && have_address && ret) |
d8041cc8 | 9913 | { |
e7af1d45 RK |
9914 | HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc)); |
9915 | ||
9916 | if (size > DWARF2_ADDR_SIZE || size == -1) | |
9917 | return 0; | |
2ad9852d | 9918 | else if (size == DWARF2_ADDR_SIZE) |
d8041cc8 RH |
9919 | op = DW_OP_deref; |
9920 | else | |
9921 | op = DW_OP_deref_size; | |
e7af1d45 RK |
9922 | |
9923 | add_loc_descr (&ret, new_loc_descr (op, size, 0)); | |
d8041cc8 RH |
9924 | } |
9925 | ||
9926 | return ret; | |
9927 | } | |
9928 | ||
1a186ec5 RH |
9929 | static inline dw_loc_descr_ref |
9930 | loc_descriptor_from_tree (tree loc) | |
9931 | { | |
9932 | return loc_descriptor_from_tree_1 (loc, 2); | |
9933 | } | |
9934 | ||
665f2503 | 9935 | /* Given a value, round it up to the lowest multiple of `boundary' |
a3f97cbb | 9936 | which is not less than the value itself. */ |
71dfc51f | 9937 | |
665f2503 | 9938 | static inline HOST_WIDE_INT |
7080f735 | 9939 | ceiling (HOST_WIDE_INT value, unsigned int boundary) |
a3f97cbb JW |
9940 | { |
9941 | return (((value + boundary - 1) / boundary) * boundary); | |
9942 | } | |
9943 | ||
9944 | /* Given a pointer to what is assumed to be a FIELD_DECL node, return a | |
9945 | pointer to the declared type for the relevant field variable, or return | |
9946 | `integer_type_node' if the given node turns out to be an | |
9947 | ERROR_MARK node. */ | |
71dfc51f RK |
9948 | |
9949 | static inline tree | |
9678086d | 9950 | field_type (const_tree decl) |
a3f97cbb | 9951 | { |
b3694847 | 9952 | tree type; |
a3f97cbb JW |
9953 | |
9954 | if (TREE_CODE (decl) == ERROR_MARK) | |
9955 | return integer_type_node; | |
9956 | ||
9957 | type = DECL_BIT_FIELD_TYPE (decl); | |
71dfc51f | 9958 | if (type == NULL_TREE) |
a3f97cbb JW |
9959 | type = TREE_TYPE (decl); |
9960 | ||
9961 | return type; | |
9962 | } | |
9963 | ||
5f446d21 DD |
9964 | /* Given a pointer to a tree node, return the alignment in bits for |
9965 | it, or else return BITS_PER_WORD if the node actually turns out to | |
9966 | be an ERROR_MARK node. */ | |
71dfc51f RK |
9967 | |
9968 | static inline unsigned | |
9678086d | 9969 | simple_type_align_in_bits (const_tree type) |
a3f97cbb JW |
9970 | { |
9971 | return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; | |
9972 | } | |
9973 | ||
5f446d21 | 9974 | static inline unsigned |
9678086d | 9975 | simple_decl_align_in_bits (const_tree decl) |
5f446d21 DD |
9976 | { |
9977 | return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD; | |
9978 | } | |
9979 | ||
d996473d EB |
9980 | /* Return the result of rounding T up to ALIGN. */ |
9981 | ||
9982 | static inline HOST_WIDE_INT | |
9983 | round_up_to_align (HOST_WIDE_INT t, unsigned int align) | |
9984 | { | |
9985 | /* We must be careful if T is negative because HOST_WIDE_INT can be | |
9986 | either "above" or "below" unsigned int as per the C promotion | |
9987 | rules, depending on the host, thus making the signedness of the | |
9988 | direct multiplication and division unpredictable. */ | |
9989 | unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t; | |
9990 | ||
9991 | u += align - 1; | |
9992 | u /= align; | |
9993 | u *= align; | |
9994 | ||
9995 | return (HOST_WIDE_INT) u; | |
9996 | } | |
9997 | ||
2ad9852d RK |
9998 | /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the |
9999 | lowest addressed byte of the "containing object" for the given FIELD_DECL, | |
10000 | or return 0 if we are unable to determine what that offset is, either | |
10001 | because the argument turns out to be a pointer to an ERROR_MARK node, or | |
10002 | because the offset is actually variable. (We can't handle the latter case | |
10003 | just yet). */ | |
71dfc51f | 10004 | |
665f2503 | 10005 | static HOST_WIDE_INT |
9678086d | 10006 | field_byte_offset (const_tree decl) |
a3f97cbb | 10007 | { |
665f2503 | 10008 | HOST_WIDE_INT object_offset_in_bits; |
665f2503 | 10009 | HOST_WIDE_INT bitpos_int; |
a3f97cbb JW |
10010 | |
10011 | if (TREE_CODE (decl) == ERROR_MARK) | |
10012 | return 0; | |
a1c496cb | 10013 | |
ced3f397 | 10014 | gcc_assert (TREE_CODE (decl) == FIELD_DECL); |
a3f97cbb | 10015 | |
556273e0 | 10016 | /* We cannot yet cope with fields whose positions are variable, so |
a3f97cbb JW |
10017 | for now, when we see such things, we simply return 0. Someday, we may |
10018 | be able to handle such cases, but it will be damn difficult. */ | |
665f2503 | 10019 | if (! host_integerp (bit_position (decl), 0)) |
a3f97cbb | 10020 | return 0; |
14a774a9 | 10021 | |
665f2503 | 10022 | bitpos_int = int_bit_position (decl); |
a3f97cbb | 10023 | |
cd0a10dd NF |
10024 | #ifdef PCC_BITFIELD_TYPE_MATTERS |
10025 | if (PCC_BITFIELD_TYPE_MATTERS) | |
10026 | { | |
10027 | tree type; | |
10028 | tree field_size_tree; | |
10029 | HOST_WIDE_INT deepest_bitpos; | |
10030 | unsigned HOST_WIDE_INT field_size_in_bits; | |
10031 | unsigned int type_align_in_bits; | |
10032 | unsigned int decl_align_in_bits; | |
10033 | unsigned HOST_WIDE_INT type_size_in_bits; | |
a3f97cbb | 10034 | |
cd0a10dd NF |
10035 | type = field_type (decl); |
10036 | field_size_tree = DECL_SIZE (decl); | |
a3f97cbb | 10037 | |
cd0a10dd NF |
10038 | /* The size could be unspecified if there was an error, or for |
10039 | a flexible array member. */ | |
10040 | if (! field_size_tree) | |
10041 | field_size_tree = bitsize_zero_node; | |
10042 | ||
10043 | /* If we don't know the size of the field, pretend it's a full word. */ | |
10044 | if (host_integerp (field_size_tree, 1)) | |
10045 | field_size_in_bits = tree_low_cst (field_size_tree, 1); | |
10046 | else | |
10047 | field_size_in_bits = BITS_PER_WORD; | |
10048 | ||
10049 | type_size_in_bits = simple_type_size_in_bits (type); | |
10050 | type_align_in_bits = simple_type_align_in_bits (type); | |
10051 | decl_align_in_bits = simple_decl_align_in_bits (decl); | |
10052 | ||
10053 | /* The GCC front-end doesn't make any attempt to keep track of the | |
10054 | starting bit offset (relative to the start of the containing | |
10055 | structure type) of the hypothetical "containing object" for a | |
10056 | bit-field. Thus, when computing the byte offset value for the | |
10057 | start of the "containing object" of a bit-field, we must deduce | |
10058 | this information on our own. This can be rather tricky to do in | |
10059 | some cases. For example, handling the following structure type | |
10060 | definition when compiling for an i386/i486 target (which only | |
10061 | aligns long long's to 32-bit boundaries) can be very tricky: | |
a3f97cbb JW |
10062 | |
10063 | struct S { int field1; long long field2:31; }; | |
10064 | ||
cd0a10dd NF |
10065 | Fortunately, there is a simple rule-of-thumb which can be used |
10066 | in such cases. When compiling for an i386/i486, GCC will | |
10067 | allocate 8 bytes for the structure shown above. It decides to | |
10068 | do this based upon one simple rule for bit-field allocation. | |
10069 | GCC allocates each "containing object" for each bit-field at | |
10070 | the first (i.e. lowest addressed) legitimate alignment boundary | |
10071 | (based upon the required minimum alignment for the declared | |
10072 | type of the field) which it can possibly use, subject to the | |
10073 | condition that there is still enough available space remaining | |
10074 | in the containing object (when allocated at the selected point) | |
10075 | to fully accommodate all of the bits of the bit-field itself. | |
10076 | ||
10077 | This simple rule makes it obvious why GCC allocates 8 bytes for | |
10078 | each object of the structure type shown above. When looking | |
10079 | for a place to allocate the "containing object" for `field2', | |
10080 | the compiler simply tries to allocate a 64-bit "containing | |
10081 | object" at each successive 32-bit boundary (starting at zero) | |
10082 | until it finds a place to allocate that 64- bit field such that | |
10083 | at least 31 contiguous (and previously unallocated) bits remain | |
10084 | within that selected 64 bit field. (As it turns out, for the | |
10085 | example above, the compiler finds it is OK to allocate the | |
10086 | "containing object" 64-bit field at bit-offset zero within the | |
10087 | structure type.) | |
10088 | ||
10089 | Here we attempt to work backwards from the limited set of facts | |
10090 | we're given, and we try to deduce from those facts, where GCC | |
10091 | must have believed that the containing object started (within | |
10092 | the structure type). The value we deduce is then used (by the | |
10093 | callers of this routine) to generate DW_AT_location and | |
10094 | DW_AT_bit_offset attributes for fields (both bit-fields and, in | |
10095 | the case of DW_AT_location, regular fields as well). */ | |
10096 | ||
10097 | /* Figure out the bit-distance from the start of the structure to | |
10098 | the "deepest" bit of the bit-field. */ | |
10099 | deepest_bitpos = bitpos_int + field_size_in_bits; | |
10100 | ||
10101 | /* This is the tricky part. Use some fancy footwork to deduce | |
10102 | where the lowest addressed bit of the containing object must | |
10103 | be. */ | |
5f446d21 DD |
10104 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; |
10105 | ||
cd0a10dd NF |
10106 | /* Round up to type_align by default. This works best for |
10107 | bitfields. */ | |
d996473d | 10108 | object_offset_in_bits |
cd0a10dd NF |
10109 | = round_up_to_align (object_offset_in_bits, type_align_in_bits); |
10110 | ||
10111 | if (object_offset_in_bits > bitpos_int) | |
10112 | { | |
10113 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; | |
10114 | ||
10115 | /* Round up to decl_align instead. */ | |
10116 | object_offset_in_bits | |
10117 | = round_up_to_align (object_offset_in_bits, decl_align_in_bits); | |
10118 | } | |
5f446d21 | 10119 | } |
cd0a10dd NF |
10120 | else |
10121 | #endif | |
10122 | object_offset_in_bits = bitpos_int; | |
a3f97cbb | 10123 | |
2ad9852d | 10124 | return object_offset_in_bits / BITS_PER_UNIT; |
a3f97cbb | 10125 | } |
a3f97cbb | 10126 | \f |
71dfc51f RK |
10127 | /* The following routines define various Dwarf attributes and any data |
10128 | associated with them. */ | |
a3f97cbb | 10129 | |
ef76d03b | 10130 | /* Add a location description attribute value to a DIE. |
a3f97cbb | 10131 | |
ef76d03b | 10132 | This emits location attributes suitable for whole variables and |
a3f97cbb JW |
10133 | whole parameters. Note that the location attributes for struct fields are |
10134 | generated by the routine `data_member_location_attribute' below. */ | |
71dfc51f | 10135 | |
b9203463 | 10136 | static inline void |
7080f735 AJ |
10137 | add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind, |
10138 | dw_loc_descr_ref descr) | |
a3f97cbb | 10139 | { |
e7af1d45 RK |
10140 | if (descr != 0) |
10141 | add_AT_loc (die, attr_kind, descr); | |
a3f97cbb JW |
10142 | } |
10143 | ||
2ad9852d RK |
10144 | /* Attach the specialized form of location attribute used for data members of |
10145 | struct and union types. In the special case of a FIELD_DECL node which | |
10146 | represents a bit-field, the "offset" part of this special location | |
10147 | descriptor must indicate the distance in bytes from the lowest-addressed | |
10148 | byte of the containing struct or union type to the lowest-addressed byte of | |
10149 | the "containing object" for the bit-field. (See the `field_byte_offset' | |
10150 | function above). | |
10151 | ||
10152 | For any given bit-field, the "containing object" is a hypothetical object | |
10153 | (of some integral or enum type) within which the given bit-field lives. The | |
10154 | type of this hypothetical "containing object" is always the same as the | |
10155 | declared type of the individual bit-field itself (for GCC anyway... the | |
10156 | DWARF spec doesn't actually mandate this). Note that it is the size (in | |
10157 | bytes) of the hypothetical "containing object" which will be given in the | |
10158 | DW_AT_byte_size attribute for this bit-field. (See the | |
10159 | `byte_size_attribute' function below.) It is also used when calculating the | |
10160 | value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute' | |
10161 | function below.) */ | |
71dfc51f | 10162 | |
a3f97cbb | 10163 | static void |
7080f735 | 10164 | add_data_member_location_attribute (dw_die_ref die, tree decl) |
a3f97cbb | 10165 | { |
799f628a | 10166 | HOST_WIDE_INT offset; |
649ce3f2 | 10167 | dw_loc_descr_ref loc_descr = 0; |
a3f97cbb | 10168 | |
95b4aca6 | 10169 | if (TREE_CODE (decl) == TREE_BINFO) |
649ce3f2 JM |
10170 | { |
10171 | /* We're working on the TAG_inheritance for a base class. */ | |
809e3e7f | 10172 | if (BINFO_VIRTUAL_P (decl) && is_cxx ()) |
649ce3f2 JM |
10173 | { |
10174 | /* For C++ virtual bases we can't just use BINFO_OFFSET, as they | |
10175 | aren't at a fixed offset from all (sub)objects of the same | |
10176 | type. We need to extract the appropriate offset from our | |
10177 | vtable. The following dwarf expression means | |
10178 | ||
10179 | BaseAddr = ObAddr + *((*ObAddr) - Offset) | |
10180 | ||
10181 | This is specific to the V3 ABI, of course. */ | |
10182 | ||
10183 | dw_loc_descr_ref tmp; | |
2ad9852d | 10184 | |
649ce3f2 JM |
10185 | /* Make a copy of the object address. */ |
10186 | tmp = new_loc_descr (DW_OP_dup, 0, 0); | |
10187 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 10188 | |
649ce3f2 JM |
10189 | /* Extract the vtable address. */ |
10190 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
10191 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 10192 | |
649ce3f2 JM |
10193 | /* Calculate the address of the offset. */ |
10194 | offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0); | |
ced3f397 | 10195 | gcc_assert (offset < 0); |
2ad9852d | 10196 | |
649ce3f2 JM |
10197 | tmp = int_loc_descriptor (-offset); |
10198 | add_loc_descr (&loc_descr, tmp); | |
10199 | tmp = new_loc_descr (DW_OP_minus, 0, 0); | |
10200 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 10201 | |
649ce3f2 JM |
10202 | /* Extract the offset. */ |
10203 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
10204 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 10205 | |
649ce3f2 JM |
10206 | /* Add it to the object address. */ |
10207 | tmp = new_loc_descr (DW_OP_plus, 0, 0); | |
10208 | add_loc_descr (&loc_descr, tmp); | |
10209 | } | |
10210 | else | |
10211 | offset = tree_low_cst (BINFO_OFFSET (decl), 0); | |
10212 | } | |
61b32c02 JM |
10213 | else |
10214 | offset = field_byte_offset (decl); | |
10215 | ||
649ce3f2 JM |
10216 | if (! loc_descr) |
10217 | { | |
10218 | enum dwarf_location_atom op; | |
10219 | ||
2ad9852d RK |
10220 | /* The DWARF2 standard says that we should assume that the structure |
10221 | address is already on the stack, so we can specify a structure field | |
10222 | address by using DW_OP_plus_uconst. */ | |
71dfc51f | 10223 | |
a3f97cbb | 10224 | #ifdef MIPS_DEBUGGING_INFO |
2ad9852d RK |
10225 | /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst |
10226 | operator correctly. It works only if we leave the offset on the | |
10227 | stack. */ | |
649ce3f2 | 10228 | op = DW_OP_constu; |
a3f97cbb | 10229 | #else |
649ce3f2 | 10230 | op = DW_OP_plus_uconst; |
a3f97cbb | 10231 | #endif |
71dfc51f | 10232 | |
649ce3f2 JM |
10233 | loc_descr = new_loc_descr (op, offset, 0); |
10234 | } | |
2ad9852d | 10235 | |
a3f97cbb JW |
10236 | add_AT_loc (die, DW_AT_data_member_location, loc_descr); |
10237 | } | |
10238 | ||
e7ee3914 AM |
10239 | /* Writes integer values to dw_vec_const array. */ |
10240 | ||
10241 | static void | |
10242 | insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest) | |
10243 | { | |
10244 | while (size != 0) | |
10245 | { | |
10246 | *dest++ = val & 0xff; | |
10247 | val >>= 8; | |
10248 | --size; | |
10249 | } | |
10250 | } | |
10251 | ||
10252 | /* Reads integers from dw_vec_const array. Inverse of insert_int. */ | |
10253 | ||
10254 | static HOST_WIDE_INT | |
10255 | extract_int (const unsigned char *src, unsigned int size) | |
10256 | { | |
10257 | HOST_WIDE_INT val = 0; | |
10258 | ||
10259 | src += size; | |
10260 | while (size != 0) | |
10261 | { | |
10262 | val <<= 8; | |
10263 | val |= *--src & 0xff; | |
10264 | --size; | |
10265 | } | |
10266 | return val; | |
10267 | } | |
10268 | ||
10269 | /* Writes floating point values to dw_vec_const array. */ | |
10270 | ||
10271 | static void | |
9678086d | 10272 | insert_float (const_rtx rtl, unsigned char *array) |
e7ee3914 AM |
10273 | { |
10274 | REAL_VALUE_TYPE rv; | |
10275 | long val[4]; | |
10276 | int i; | |
10277 | ||
10278 | REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl); | |
10279 | real_to_target (val, &rv, GET_MODE (rtl)); | |
10280 | ||
10281 | /* real_to_target puts 32-bit pieces in each long. Pack them. */ | |
10282 | for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++) | |
10283 | { | |
10284 | insert_int (val[i], 4, array); | |
10285 | array += 4; | |
10286 | } | |
10287 | } | |
10288 | ||
b20b352b | 10289 | /* Attach a DW_AT_const_value attribute for a variable or a parameter which |
a3f97cbb JW |
10290 | does not have a "location" either in memory or in a register. These |
10291 | things can arise in GNU C when a constant is passed as an actual parameter | |
10292 | to an inlined function. They can also arise in C++ where declared | |
10293 | constants do not necessarily get memory "homes". */ | |
71dfc51f | 10294 | |
a3f97cbb | 10295 | static void |
7080f735 | 10296 | add_const_value_attribute (dw_die_ref die, rtx rtl) |
a3f97cbb JW |
10297 | { |
10298 | switch (GET_CODE (rtl)) | |
10299 | { | |
10300 | case CONST_INT: | |
2e4b9b8c RH |
10301 | { |
10302 | HOST_WIDE_INT val = INTVAL (rtl); | |
c26fbbca | 10303 | |
799f628a JH |
10304 | if (val < 0) |
10305 | add_AT_int (die, DW_AT_const_value, val); | |
a1c496cb | 10306 | else |
799f628a | 10307 | add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val); |
2e4b9b8c | 10308 | } |
a3f97cbb JW |
10309 | break; |
10310 | ||
10311 | case CONST_DOUBLE: | |
10312 | /* Note that a CONST_DOUBLE rtx could represent either an integer or a | |
73c68f61 SS |
10313 | floating-point constant. A CONST_DOUBLE is used whenever the |
10314 | constant requires more than one word in order to be adequately | |
10315 | represented. We output CONST_DOUBLEs as blocks. */ | |
469ac993 | 10316 | { |
b3694847 | 10317 | enum machine_mode mode = GET_MODE (rtl); |
469ac993 | 10318 | |
3d8bf70f | 10319 | if (SCALAR_FLOAT_MODE_P (mode)) |
469ac993 | 10320 | { |
e7ee3914 | 10321 | unsigned int length = GET_MODE_SIZE (mode); |
1b4572a8 | 10322 | unsigned char *array = GGC_NEWVEC (unsigned char, length); |
469ac993 | 10323 | |
e7ee3914 AM |
10324 | insert_float (rtl, array); |
10325 | add_AT_vec (die, DW_AT_const_value, length / 4, 4, array); | |
469ac993 JM |
10326 | } |
10327 | else | |
2e4b9b8c RH |
10328 | { |
10329 | /* ??? We really should be using HOST_WIDE_INT throughout. */ | |
ced3f397 | 10330 | gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT); |
2ad9852d | 10331 | |
2e4b9b8c RH |
10332 | add_AT_long_long (die, DW_AT_const_value, |
10333 | CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl)); | |
10334 | } | |
469ac993 | 10335 | } |
a3f97cbb JW |
10336 | break; |
10337 | ||
e7ee3914 AM |
10338 | case CONST_VECTOR: |
10339 | { | |
10340 | enum machine_mode mode = GET_MODE (rtl); | |
10341 | unsigned int elt_size = GET_MODE_UNIT_SIZE (mode); | |
10342 | unsigned int length = CONST_VECTOR_NUNITS (rtl); | |
1b4572a8 | 10343 | unsigned char *array = GGC_NEWVEC (unsigned char, length * elt_size); |
e7ee3914 AM |
10344 | unsigned int i; |
10345 | unsigned char *p; | |
10346 | ||
ced3f397 | 10347 | switch (GET_MODE_CLASS (mode)) |
e7ee3914 | 10348 | { |
ced3f397 | 10349 | case MODE_VECTOR_INT: |
e7ee3914 AM |
10350 | for (i = 0, p = array; i < length; i++, p += elt_size) |
10351 | { | |
10352 | rtx elt = CONST_VECTOR_ELT (rtl, i); | |
10353 | HOST_WIDE_INT lo, hi; | |
a1c496cb | 10354 | |
ced3f397 | 10355 | switch (GET_CODE (elt)) |
e7ee3914 | 10356 | { |
ced3f397 | 10357 | case CONST_INT: |
e7ee3914 AM |
10358 | lo = INTVAL (elt); |
10359 | hi = -(lo < 0); | |
ced3f397 | 10360 | break; |
a1c496cb | 10361 | |
ced3f397 | 10362 | case CONST_DOUBLE: |
e7ee3914 AM |
10363 | lo = CONST_DOUBLE_LOW (elt); |
10364 | hi = CONST_DOUBLE_HIGH (elt); | |
ced3f397 | 10365 | break; |
a1c496cb | 10366 | |
ced3f397 NS |
10367 | default: |
10368 | gcc_unreachable (); | |
e7ee3914 | 10369 | } |
a1c496cb | 10370 | |
e7ee3914 AM |
10371 | if (elt_size <= sizeof (HOST_WIDE_INT)) |
10372 | insert_int (lo, elt_size, p); | |
ced3f397 | 10373 | else |
e7ee3914 AM |
10374 | { |
10375 | unsigned char *p0 = p; | |
10376 | unsigned char *p1 = p + sizeof (HOST_WIDE_INT); | |
a1c496cb | 10377 | |
ced3f397 | 10378 | gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT)); |
e7ee3914 AM |
10379 | if (WORDS_BIG_ENDIAN) |
10380 | { | |
10381 | p0 = p1; | |
10382 | p1 = p; | |
10383 | } | |
10384 | insert_int (lo, sizeof (HOST_WIDE_INT), p0); | |
10385 | insert_int (hi, sizeof (HOST_WIDE_INT), p1); | |
10386 | } | |
e7ee3914 | 10387 | } |
ced3f397 NS |
10388 | break; |
10389 | ||
10390 | case MODE_VECTOR_FLOAT: | |
e7ee3914 AM |
10391 | for (i = 0, p = array; i < length; i++, p += elt_size) |
10392 | { | |
10393 | rtx elt = CONST_VECTOR_ELT (rtl, i); | |
10394 | insert_float (elt, p); | |
10395 | } | |
ced3f397 NS |
10396 | break; |
10397 | ||
10398 | default: | |
10399 | gcc_unreachable (); | |
e7ee3914 | 10400 | } |
e7ee3914 AM |
10401 | |
10402 | add_AT_vec (die, DW_AT_const_value, length, elt_size, array); | |
10403 | } | |
10404 | break; | |
10405 | ||
a3f97cbb JW |
10406 | case CONST_STRING: |
10407 | add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0)); | |
10408 | break; | |
10409 | ||
10410 | case SYMBOL_REF: | |
10411 | case LABEL_REF: | |
10412 | case CONST: | |
c470afad | 10413 | add_AT_addr (die, DW_AT_const_value, rtl); |
a1bbd445 | 10414 | VEC_safe_push (rtx, gc, used_rtx_array, rtl); |
a3f97cbb JW |
10415 | break; |
10416 | ||
10417 | case PLUS: | |
10418 | /* In cases where an inlined instance of an inline function is passed | |
73c68f61 SS |
10419 | the address of an `auto' variable (which is local to the caller) we |
10420 | can get a situation where the DECL_RTL of the artificial local | |
10421 | variable (for the inlining) which acts as a stand-in for the | |
10422 | corresponding formal parameter (of the inline function) will look | |
10423 | like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not | |
10424 | exactly a compile-time constant expression, but it isn't the address | |
10425 | of the (artificial) local variable either. Rather, it represents the | |
10426 | *value* which the artificial local variable always has during its | |
10427 | lifetime. We currently have no way to represent such quasi-constant | |
10428 | values in Dwarf, so for now we just punt and generate nothing. */ | |
a3f97cbb JW |
10429 | break; |
10430 | ||
10431 | default: | |
10432 | /* No other kinds of rtx should be possible here. */ | |
ced3f397 | 10433 | gcc_unreachable (); |
a3f97cbb JW |
10434 | } |
10435 | ||
10436 | } | |
10437 | ||
0d06ead5 GK |
10438 | /* Determine whether the evaluation of EXPR references any variables |
10439 | or functions which aren't otherwise used (and therefore may not be | |
10440 | output). */ | |
10441 | static tree | |
10442 | reference_to_unused (tree * tp, int * walk_subtrees, | |
10443 | void * data ATTRIBUTE_UNUSED) | |
10444 | { | |
07beea0d | 10445 | if (! EXPR_P (*tp) && ! GIMPLE_STMT_P (*tp) && ! CONSTANT_CLASS_P (*tp)) |
0d06ead5 | 10446 | *walk_subtrees = 0; |
2878ea73 | 10447 | |
0d06ead5 GK |
10448 | if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp) |
10449 | && ! TREE_ASM_WRITTEN (*tp)) | |
10450 | return *tp; | |
4f40bddf JH |
10451 | else if (!flag_unit_at_a_time) |
10452 | return NULL_TREE; | |
7a3c4b3e DK |
10453 | /* ??? The C++ FE emits debug information for using decls, so |
10454 | putting gcc_unreachable here falls over. See PR31899. For now | |
10455 | be conservative. */ | |
4f40bddf JH |
10456 | else if (!cgraph_global_info_ready |
10457 | && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL)) | |
7a3c4b3e | 10458 | return *tp; |
4f40bddf | 10459 | else if (DECL_P (*tp) && TREE_CODE (*tp) == VAR_DECL) |
9b1959ff RG |
10460 | { |
10461 | struct varpool_node *node = varpool_node (*tp); | |
10462 | if (!node->needed) | |
10463 | return *tp; | |
10464 | } | |
4f40bddf JH |
10465 | else if (DECL_P (*tp) && TREE_CODE (*tp) == FUNCTION_DECL |
10466 | && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp))) | |
10467 | { | |
10468 | struct cgraph_node *node = cgraph_node (*tp); | |
10469 | if (!node->output) | |
2878ea73 | 10470 | return *tp; |
4f40bddf | 10471 | } |
d2f08d98 AO |
10472 | else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp)) |
10473 | return *tp; | |
9b1959ff RG |
10474 | |
10475 | return NULL_TREE; | |
0d06ead5 GK |
10476 | } |
10477 | ||
77270e03 JW |
10478 | /* Generate an RTL constant from a decl initializer INIT with decl type TYPE, |
10479 | for use in a later add_const_value_attribute call. */ | |
10480 | ||
10481 | static rtx | |
10482 | rtl_for_decl_init (tree init, tree type) | |
10483 | { | |
10484 | rtx rtl = NULL_RTX; | |
10485 | ||
10486 | /* If a variable is initialized with a string constant without embedded | |
10487 | zeros, build CONST_STRING. */ | |
10488 | if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE) | |
10489 | { | |
10490 | tree enttype = TREE_TYPE (type); | |
10491 | tree domain = TYPE_DOMAIN (type); | |
10492 | enum machine_mode mode = TYPE_MODE (enttype); | |
10493 | ||
10494 | if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1 | |
10495 | && domain | |
10496 | && integer_zerop (TYPE_MIN_VALUE (domain)) | |
10497 | && compare_tree_int (TYPE_MAX_VALUE (domain), | |
10498 | TREE_STRING_LENGTH (init) - 1) == 0 | |
10499 | && ((size_t) TREE_STRING_LENGTH (init) | |
10500 | == strlen (TREE_STRING_POINTER (init)) + 1)) | |
10501 | rtl = gen_rtx_CONST_STRING (VOIDmode, | |
10502 | ggc_strdup (TREE_STRING_POINTER (init))); | |
10503 | } | |
9a23b833 GK |
10504 | /* Other aggregates, and complex values, could be represented using |
10505 | CONCAT: FIXME! */ | |
10506 | else if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE) | |
10507 | ; | |
2878ea73 | 10508 | /* Vectors only work if their mode is supported by the target. |
9a23b833 GK |
10509 | FIXME: generic vectors ought to work too. */ |
10510 | else if (TREE_CODE (type) == VECTOR_TYPE && TYPE_MODE (type) == BLKmode) | |
0d06ead5 | 10511 | ; |
77270e03 | 10512 | /* If the initializer is something that we know will expand into an |
0d06ead5 GK |
10513 | immediate RTL constant, expand it now. We must be careful not to |
10514 | reference variables which won't be output. */ | |
10515 | else if (initializer_constant_valid_p (init, type) | |
10516 | && ! walk_tree (&init, reference_to_unused, NULL, NULL)) | |
77270e03 | 10517 | { |
a7d0852d JJ |
10518 | /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if |
10519 | possible. */ | |
10520 | if (TREE_CODE (type) == VECTOR_TYPE) | |
10521 | switch (TREE_CODE (init)) | |
10522 | { | |
10523 | case VECTOR_CST: | |
10524 | break; | |
10525 | case CONSTRUCTOR: | |
10526 | if (TREE_CONSTANT (init)) | |
10527 | { | |
10528 | VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init); | |
10529 | bool constant_p = true; | |
10530 | tree value; | |
10531 | unsigned HOST_WIDE_INT ix; | |
10532 | ||
10533 | /* Even when ctor is constant, it might contain non-*_CST | |
10534 | elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't | |
10535 | belong into VECTOR_CST nodes. */ | |
10536 | FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value) | |
10537 | if (!CONSTANT_CLASS_P (value)) | |
10538 | { | |
10539 | constant_p = false; | |
10540 | break; | |
10541 | } | |
10542 | ||
10543 | if (constant_p) | |
10544 | { | |
10545 | init = build_vector_from_ctor (type, elts); | |
10546 | break; | |
10547 | } | |
10548 | } | |
10549 | /* FALLTHRU */ | |
10550 | ||
10551 | default: | |
10552 | return NULL; | |
10553 | } | |
10554 | ||
77270e03 JW |
10555 | rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER); |
10556 | ||
10557 | /* If expand_expr returns a MEM, it wasn't immediate. */ | |
10558 | gcc_assert (!rtl || !MEM_P (rtl)); | |
10559 | } | |
10560 | ||
10561 | return rtl; | |
10562 | } | |
10563 | ||
10564 | /* Generate RTL for the variable DECL to represent its location. */ | |
10565 | ||
d8041cc8 | 10566 | static rtx |
7080f735 | 10567 | rtl_for_decl_location (tree decl) |
a3f97cbb | 10568 | { |
b3694847 | 10569 | rtx rtl; |
71dfc51f | 10570 | |
a3f97cbb JW |
10571 | /* Here we have to decide where we are going to say the parameter "lives" |
10572 | (as far as the debugger is concerned). We only have a couple of | |
10573 | choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. | |
71dfc51f | 10574 | |
556273e0 | 10575 | DECL_RTL normally indicates where the parameter lives during most of the |
71dfc51f | 10576 | activation of the function. If optimization is enabled however, this |
556273e0 | 10577 | could be either NULL or else a pseudo-reg. Both of those cases indicate |
a3f97cbb JW |
10578 | that the parameter doesn't really live anywhere (as far as the code |
10579 | generation parts of GCC are concerned) during most of the function's | |
10580 | activation. That will happen (for example) if the parameter is never | |
71dfc51f RK |
10581 | referenced within the function. |
10582 | ||
10583 | We could just generate a location descriptor here for all non-NULL | |
10584 | non-pseudo values of DECL_RTL and ignore all of the rest, but we can be | |
10585 | a little nicer than that if we also consider DECL_INCOMING_RTL in cases | |
10586 | where DECL_RTL is NULL or is a pseudo-reg. | |
10587 | ||
10588 | Note however that we can only get away with using DECL_INCOMING_RTL as | |
10589 | a backup substitute for DECL_RTL in certain limited cases. In cases | |
10590 | where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl), | |
10591 | we can be sure that the parameter was passed using the same type as it is | |
10592 | declared to have within the function, and that its DECL_INCOMING_RTL | |
10593 | points us to a place where a value of that type is passed. | |
10594 | ||
10595 | In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different, | |
10596 | we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL | |
10597 | because in these cases DECL_INCOMING_RTL points us to a value of some | |
10598 | type which is *different* from the type of the parameter itself. Thus, | |
10599 | if we tried to use DECL_INCOMING_RTL to generate a location attribute in | |
10600 | such cases, the debugger would end up (for example) trying to fetch a | |
10601 | `float' from a place which actually contains the first part of a | |
10602 | `double'. That would lead to really incorrect and confusing | |
10603 | output at debug-time. | |
10604 | ||
10605 | So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL | |
10606 | in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There | |
10607 | are a couple of exceptions however. On little-endian machines we can | |
10608 | get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is | |
10609 | not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is | |
10610 | an integral type that is smaller than TREE_TYPE (decl). These cases arise | |
10611 | when (on a little-endian machine) a non-prototyped function has a | |
10612 | parameter declared to be of type `short' or `char'. In such cases, | |
10613 | TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will | |
10614 | be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the | |
10615 | passed `int' value. If the debugger then uses that address to fetch | |
10616 | a `short' or a `char' (on a little-endian machine) the result will be | |
10617 | the correct data, so we allow for such exceptional cases below. | |
10618 | ||
10619 | Note that our goal here is to describe the place where the given formal | |
2ad9852d RK |
10620 | parameter lives during most of the function's activation (i.e. between the |
10621 | end of the prologue and the start of the epilogue). We'll do that as best | |
10622 | as we can. Note however that if the given formal parameter is modified | |
10623 | sometime during the execution of the function, then a stack backtrace (at | |
10624 | debug-time) will show the function as having been called with the *new* | |
10625 | value rather than the value which was originally passed in. This happens | |
10626 | rarely enough that it is not a major problem, but it *is* a problem, and | |
10627 | I'd like to fix it. | |
10628 | ||
10629 | A future version of dwarf2out.c may generate two additional attributes for | |
10630 | any given DW_TAG_formal_parameter DIE which will describe the "passed | |
10631 | type" and the "passed location" for the given formal parameter in addition | |
10632 | to the attributes we now generate to indicate the "declared type" and the | |
10633 | "active location" for each parameter. This additional set of attributes | |
10634 | could be used by debuggers for stack backtraces. Separately, note that | |
10635 | sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also. | |
10636 | This happens (for example) for inlined-instances of inline function formal | |
10637 | parameters which are never referenced. This really shouldn't be | |
10638 | happening. All PARM_DECL nodes should get valid non-NULL | |
6de9cd9a | 10639 | DECL_INCOMING_RTL values. FIXME. */ |
a3f97cbb JW |
10640 | |
10641 | /* Use DECL_RTL as the "location" unless we find something better. */ | |
110c3568 | 10642 | rtl = DECL_RTL_IF_SET (decl); |
a3f97cbb | 10643 | |
c28abdf0 | 10644 | /* When generating abstract instances, ignore everything except |
234c071b KB |
10645 | constants, symbols living in memory, and symbols living in |
10646 | fixed registers. */ | |
c28abdf0 RH |
10647 | if (! reload_completed) |
10648 | { | |
10649 | if (rtl | |
10650 | && (CONSTANT_P (rtl) | |
3c0cb5de | 10651 | || (MEM_P (rtl) |
234c071b | 10652 | && CONSTANT_P (XEXP (rtl, 0))) |
f8cfc6aa | 10653 | || (REG_P (rtl) |
234c071b KB |
10654 | && TREE_CODE (decl) == VAR_DECL |
10655 | && TREE_STATIC (decl)))) | |
4c8c0dec | 10656 | { |
5fd9b178 | 10657 | rtl = targetm.delegitimize_address (rtl); |
4c8c0dec JJ |
10658 | return rtl; |
10659 | } | |
c28abdf0 RH |
10660 | rtl = NULL_RTX; |
10661 | } | |
10662 | else if (TREE_CODE (decl) == PARM_DECL) | |
a3f97cbb JW |
10663 | { |
10664 | if (rtl == NULL_RTX || is_pseudo_reg (rtl)) | |
10665 | { | |
d8cb0614 RH |
10666 | tree declared_type = TREE_TYPE (decl); |
10667 | tree passed_type = DECL_ARG_TYPE (decl); | |
10668 | enum machine_mode dmode = TYPE_MODE (declared_type); | |
10669 | enum machine_mode pmode = TYPE_MODE (passed_type); | |
a3f97cbb | 10670 | |
71dfc51f | 10671 | /* This decl represents a formal parameter which was optimized out. |
a3f97cbb | 10672 | Note that DECL_INCOMING_RTL may be NULL in here, but we handle |
2ad9852d | 10673 | all cases where (rtl == NULL_RTX) just below. */ |
d8cb0614 | 10674 | if (dmode == pmode) |
556273e0 | 10675 | rtl = DECL_INCOMING_RTL (decl); |
d8cb0614 | 10676 | else if (SCALAR_INT_MODE_P (dmode) |
3401a17f JJ |
10677 | && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode) |
10678 | && DECL_INCOMING_RTL (decl)) | |
d8cb0614 RH |
10679 | { |
10680 | rtx inc = DECL_INCOMING_RTL (decl); | |
10681 | if (REG_P (inc)) | |
10682 | rtl = inc; | |
10683 | else if (MEM_P (inc)) | |
10684 | { | |
10685 | if (BYTES_BIG_ENDIAN) | |
10686 | rtl = adjust_address_nv (inc, dmode, | |
10687 | GET_MODE_SIZE (pmode) | |
10688 | - GET_MODE_SIZE (dmode)); | |
10689 | else | |
10690 | rtl = inc; | |
10691 | } | |
10692 | } | |
a3f97cbb | 10693 | } |
5a904a61 JW |
10694 | |
10695 | /* If the parm was passed in registers, but lives on the stack, then | |
10696 | make a big endian correction if the mode of the type of the | |
10697 | parameter is not the same as the mode of the rtl. */ | |
10698 | /* ??? This is the same series of checks that are made in dbxout.c before | |
10699 | we reach the big endian correction code there. It isn't clear if all | |
10700 | of these checks are necessary here, but keeping them all is the safe | |
10701 | thing to do. */ | |
3c0cb5de | 10702 | else if (MEM_P (rtl) |
5a904a61 JW |
10703 | && XEXP (rtl, 0) != const0_rtx |
10704 | && ! CONSTANT_P (XEXP (rtl, 0)) | |
10705 | /* Not passed in memory. */ | |
3c0cb5de | 10706 | && !MEM_P (DECL_INCOMING_RTL (decl)) |
5a904a61 | 10707 | /* Not passed by invisible reference. */ |
f8cfc6aa | 10708 | && (!REG_P (XEXP (rtl, 0)) |
5a904a61 JW |
10709 | || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM |
10710 | || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM | |
10711 | #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM | |
10712 | || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM | |
10713 | #endif | |
10714 | ) | |
10715 | /* Big endian correction check. */ | |
10716 | && BYTES_BIG_ENDIAN | |
10717 | && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl) | |
10718 | && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))) | |
10719 | < UNITS_PER_WORD)) | |
10720 | { | |
10721 | int offset = (UNITS_PER_WORD | |
10722 | - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))); | |
2ad9852d | 10723 | |
5a904a61 JW |
10724 | rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)), |
10725 | plus_constant (XEXP (rtl, 0), offset)); | |
10726 | } | |
a3f97cbb | 10727 | } |
8b495402 | 10728 | else if (TREE_CODE (decl) == VAR_DECL |
de3c6d93 | 10729 | && rtl |
3c0cb5de | 10730 | && MEM_P (rtl) |
8b495402 DD |
10731 | && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl)) |
10732 | && BYTES_BIG_ENDIAN) | |
10733 | { | |
10734 | int rsize = GET_MODE_SIZE (GET_MODE (rtl)); | |
10735 | int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))); | |
10736 | ||
10737 | /* If a variable is declared "register" yet is smaller than | |
10738 | a register, then if we store the variable to memory, it | |
10739 | looks like we're storing a register-sized value, when in | |
10740 | fact we are not. We need to adjust the offset of the | |
10741 | storage location to reflect the actual value's bytes, | |
10742 | else gdb will not be able to display it. */ | |
10743 | if (rsize > dsize) | |
10744 | rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)), | |
10745 | plus_constant (XEXP (rtl, 0), rsize-dsize)); | |
10746 | } | |
71dfc51f | 10747 | |
2ad9852d RK |
10748 | /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant, |
10749 | and will have been substituted directly into all expressions that use it. | |
10750 | C does not have such a concept, but C++ and other languages do. */ | |
30e6f306 | 10751 | if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl)) |
77270e03 | 10752 | rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl)); |
8063ddcf | 10753 | |
4c8c0dec | 10754 | if (rtl) |
5fd9b178 | 10755 | rtl = targetm.delegitimize_address (rtl); |
b9203463 RH |
10756 | |
10757 | /* If we don't look past the constant pool, we risk emitting a | |
10758 | reference to a constant pool entry that isn't referenced from | |
10759 | code, and thus is not emitted. */ | |
10760 | if (rtl) | |
10761 | rtl = avoid_constant_pool_reference (rtl); | |
10762 | ||
d8041cc8 RH |
10763 | return rtl; |
10764 | } | |
10765 | ||
30e6f306 RH |
10766 | /* We need to figure out what section we should use as the base for the |
10767 | address ranges where a given location is valid. | |
10768 | 1. If this particular DECL has a section associated with it, use that. | |
10769 | 2. If this function has a section associated with it, use that. | |
10770 | 3. Otherwise, use the text section. | |
10771 | XXX: If you split a variable across multiple sections, we won't notice. */ | |
10772 | ||
10773 | static const char * | |
9678086d | 10774 | secname_for_decl (const_tree decl) |
30e6f306 RH |
10775 | { |
10776 | const char *secname; | |
10777 | ||
10778 | if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl)) | |
10779 | { | |
10780 | tree sectree = DECL_SECTION_NAME (decl); | |
10781 | secname = TREE_STRING_POINTER (sectree); | |
10782 | } | |
10783 | else if (current_function_decl && DECL_SECTION_NAME (current_function_decl)) | |
10784 | { | |
10785 | tree sectree = DECL_SECTION_NAME (current_function_decl); | |
10786 | secname = TREE_STRING_POINTER (sectree); | |
10787 | } | |
c543ca49 | 10788 | else if (cfun && in_cold_section_p) |
38173d38 | 10789 | secname = crtl->subsections.cold_section_label; |
30e6f306 RH |
10790 | else |
10791 | secname = text_section_label; | |
10792 | ||
10793 | return secname; | |
10794 | } | |
10795 | ||
7151ffbe GH |
10796 | /* Check whether decl is a Fortran COMMON symbol. If not, NULL_RTX is returned. |
10797 | If so, the rtx for the SYMBOL_REF for the COMMON block is returned, and the | |
10798 | value is the offset into the common block for the symbol. */ | |
10799 | ||
1f16b47c JJ |
10800 | static tree |
10801 | fortran_common (tree decl, HOST_WIDE_INT *value) | |
7151ffbe | 10802 | { |
1f16b47c JJ |
10803 | tree val_expr, cvar; |
10804 | enum machine_mode mode; | |
10805 | HOST_WIDE_INT bitsize, bitpos; | |
10806 | tree offset; | |
10807 | int volatilep = 0, unsignedp = 0; | |
10808 | ||
7151ffbe GH |
10809 | /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if |
10810 | it does not have a value (the offset into the common area), or if it | |
10811 | is thread local (as opposed to global) then it isn't common, and shouldn't | |
10812 | be handled as such. */ | |
10813 | if (TREE_CODE (decl) != VAR_DECL | |
1f16b47c JJ |
10814 | || !TREE_PUBLIC (decl) |
10815 | || !TREE_STATIC (decl) | |
10816 | || !DECL_HAS_VALUE_EXPR_P (decl) | |
10817 | || !is_fortran ()) | |
10818 | return NULL_TREE; | |
7151ffbe | 10819 | |
1f16b47c JJ |
10820 | val_expr = DECL_VALUE_EXPR (decl); |
10821 | if (TREE_CODE (val_expr) != COMPONENT_REF) | |
10822 | return NULL_TREE; | |
7151ffbe | 10823 | |
1f16b47c JJ |
10824 | cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset, |
10825 | &mode, &unsignedp, &volatilep, true); | |
7151ffbe | 10826 | |
1f16b47c JJ |
10827 | if (cvar == NULL_TREE |
10828 | || TREE_CODE (cvar) != VAR_DECL | |
10829 | || DECL_ARTIFICIAL (cvar) | |
10830 | || !TREE_PUBLIC (cvar)) | |
10831 | return NULL_TREE; | |
7151ffbe | 10832 | |
1f16b47c JJ |
10833 | *value = 0; |
10834 | if (offset != NULL) | |
10835 | { | |
10836 | if (!host_integerp (offset, 0)) | |
10837 | return NULL_TREE; | |
10838 | *value = tree_low_cst (offset, 0); | |
7151ffbe | 10839 | } |
1f16b47c JJ |
10840 | if (bitpos != 0) |
10841 | *value += bitpos / BITS_PER_UNIT; | |
7151ffbe | 10842 | |
1f16b47c | 10843 | return cvar; |
7151ffbe GH |
10844 | } |
10845 | ||
10846 | ||
b20b352b | 10847 | /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value |
d8041cc8 RH |
10848 | data attribute for a variable or a parameter. We generate the |
10849 | DW_AT_const_value attribute only in those cases where the given variable | |
10850 | or parameter does not have a true "location" either in memory or in a | |
10851 | register. This can happen (for example) when a constant is passed as an | |
10852 | actual argument in a call to an inline function. (It's possible that | |
10853 | these things can crop up in other ways also.) Note that one type of | |
10854 | constant value which can be passed into an inlined function is a constant | |
10855 | pointer. This can happen for example if an actual argument in an inlined | |
10856 | function call evaluates to a compile-time constant address. */ | |
10857 | ||
10858 | static void | |
0a2d3d69 DB |
10859 | add_location_or_const_value_attribute (dw_die_ref die, tree decl, |
10860 | enum dwarf_attribute attr) | |
d8041cc8 | 10861 | { |
b3694847 | 10862 | rtx rtl; |
b9203463 | 10863 | dw_loc_descr_ref descr; |
0a2d3d69 | 10864 | var_loc_list *loc_list; |
3c46c513 | 10865 | struct var_loc_node *node; |
d8041cc8 RH |
10866 | if (TREE_CODE (decl) == ERROR_MARK) |
10867 | return; | |
ced3f397 NS |
10868 | |
10869 | gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL | |
10870 | || TREE_CODE (decl) == RESULT_DECL); | |
2878ea73 | 10871 | |
0a2d3d69 DB |
10872 | /* See if we possibly have multiple locations for this variable. */ |
10873 | loc_list = lookup_decl_loc (decl); | |
10874 | ||
10875 | /* If it truly has multiple locations, the first and last node will | |
10876 | differ. */ | |
10877 | if (loc_list && loc_list->first != loc_list->last) | |
10878 | { | |
30e6f306 | 10879 | const char *endname, *secname; |
0a2d3d69 DB |
10880 | dw_loc_list_ref list; |
10881 | rtx varloc; | |
62760ffd | 10882 | enum var_init_status initialized; |
3c46c513 | 10883 | |
0a2d3d69 | 10884 | /* Now that we know what section we are using for a base, |
2878ea73 | 10885 | actually construct the list of locations. |
0a2d3d69 DB |
10886 | The first location information is what is passed to the |
10887 | function that creates the location list, and the remaining | |
10888 | locations just get added on to that list. | |
10889 | Note that we only know the start address for a location | |
10890 | (IE location changes), so to build the range, we use | |
10891 | the range [current location start, next location start]. | |
10892 | This means we have to special case the last node, and generate | |
10893 | a range of [last location start, end of function label]. */ | |
10894 | ||
10895 | node = loc_list->first; | |
10896 | varloc = NOTE_VAR_LOCATION (node->var_loc_note); | |
30e6f306 RH |
10897 | secname = secname_for_decl (decl); |
10898 | ||
62760ffd CT |
10899 | if (NOTE_VAR_LOCATION_LOC (node->var_loc_note)) |
10900 | initialized = NOTE_VAR_LOCATION_STATUS (node->var_loc_note); | |
10901 | else | |
10902 | initialized = VAR_INIT_STATUS_INITIALIZED; | |
10903 | ||
10904 | list = new_loc_list (loc_descriptor (varloc, initialized), | |
0a2d3d69 DB |
10905 | node->label, node->next->label, secname, 1); |
10906 | node = node->next; | |
10907 | ||
10908 | for (; node->next; node = node->next) | |
10909 | if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX) | |
10910 | { | |
10911 | /* The variable has a location between NODE->LABEL and | |
10912 | NODE->NEXT->LABEL. */ | |
62760ffd CT |
10913 | enum var_init_status initialized = |
10914 | NOTE_VAR_LOCATION_STATUS (node->var_loc_note); | |
0a2d3d69 | 10915 | varloc = NOTE_VAR_LOCATION (node->var_loc_note); |
4b570560 | 10916 | add_loc_descr_to_loc_list (&list, |
62760ffd | 10917 | loc_descriptor (varloc, initialized), |
0a2d3d69 DB |
10918 | node->label, node->next->label, secname); |
10919 | } | |
10920 | ||
10921 | /* If the variable has a location at the last label | |
10922 | it keeps its location until the end of function. */ | |
10923 | if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX) | |
10924 | { | |
10925 | char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; | |
62760ffd CT |
10926 | enum var_init_status initialized = |
10927 | NOTE_VAR_LOCATION_STATUS (node->var_loc_note); | |
0a2d3d69 DB |
10928 | |
10929 | varloc = NOTE_VAR_LOCATION (node->var_loc_note); | |
10930 | if (!current_function_decl) | |
10931 | endname = text_end_label; | |
10932 | else | |
10933 | { | |
10934 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, | |
10935 | current_function_funcdef_no); | |
10936 | endname = ggc_strdup (label_id); | |
10937 | } | |
4b570560 | 10938 | add_loc_descr_to_loc_list (&list, |
62760ffd | 10939 | loc_descriptor (varloc, initialized), |
0a2d3d69 DB |
10940 | node->label, endname, secname); |
10941 | } | |
10942 | ||
10943 | /* Finally, add the location list to the DIE, and we are done. */ | |
10944 | add_AT_loc_list (die, attr, list); | |
10945 | return; | |
10946 | } | |
10947 | ||
3c46c513 DB |
10948 | /* Try to get some constant RTL for this decl, and use that as the value of |
10949 | the location. */ | |
2878ea73 | 10950 | |
d8041cc8 | 10951 | rtl = rtl_for_decl_location (decl); |
1a186ec5 | 10952 | if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)) |
a3f97cbb | 10953 | { |
a3f97cbb | 10954 | add_const_value_attribute (die, rtl); |
1a186ec5 | 10955 | return; |
a3f97cbb | 10956 | } |
2878ea73 | 10957 | |
86bd8ebf | 10958 | /* If we have tried to generate the location otherwise, and it |
3c46c513 DB |
10959 | didn't work out (we wouldn't be here if we did), and we have a one entry |
10960 | location list, try generating a location from that. */ | |
10961 | if (loc_list && loc_list->first) | |
10962 | { | |
62760ffd | 10963 | enum var_init_status status; |
3c46c513 | 10964 | node = loc_list->first; |
62760ffd CT |
10965 | status = NOTE_VAR_LOCATION_STATUS (node->var_loc_note); |
10966 | descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note), status); | |
3c46c513 | 10967 | if (descr) |
86bd8ebf JJ |
10968 | { |
10969 | add_AT_location_description (die, attr, descr); | |
10970 | return; | |
10971 | } | |
10972 | } | |
10973 | ||
10974 | /* We couldn't get any rtl, so try directly generating the location | |
10975 | description from the tree. */ | |
10976 | descr = loc_descriptor_from_tree (decl); | |
10977 | if (descr) | |
10978 | { | |
10979 | add_AT_location_description (die, attr, descr); | |
10980 | return; | |
3c46c513 | 10981 | } |
0d06ead5 GK |
10982 | /* None of that worked, so it must not really have a location; |
10983 | try adding a constant value attribute from the DECL_INITIAL. */ | |
10984 | tree_add_const_value_attribute (die, decl); | |
a3f97cbb JW |
10985 | } |
10986 | ||
1bfb5f8f JM |
10987 | /* If we don't have a copy of this variable in memory for some reason (such |
10988 | as a C++ member constant that doesn't have an out-of-line definition), | |
10989 | we should tell the debugger about the constant value. */ | |
10990 | ||
10991 | static void | |
7080f735 | 10992 | tree_add_const_value_attribute (dw_die_ref var_die, tree decl) |
1bfb5f8f JM |
10993 | { |
10994 | tree init = DECL_INITIAL (decl); | |
10995 | tree type = TREE_TYPE (decl); | |
77270e03 | 10996 | rtx rtl; |
1bfb5f8f | 10997 | |
77270e03 | 10998 | if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init) |
1bfb5f8f JM |
10999 | /* OK */; |
11000 | else | |
11001 | return; | |
11002 | ||
77270e03 JW |
11003 | rtl = rtl_for_decl_init (init, type); |
11004 | if (rtl) | |
11005 | add_const_value_attribute (var_die, rtl); | |
1bfb5f8f | 11006 | } |
0b34cf1e | 11007 | |
35d177a2 AO |
11008 | /* Convert the CFI instructions for the current function into a |
11009 | location list. This is used for DW_AT_frame_base when we targeting | |
11010 | a dwarf2 consumer that does not support the dwarf3 | |
11011 | DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA | |
11012 | expressions. */ | |
30e6f306 RH |
11013 | |
11014 | static dw_loc_list_ref | |
35d177a2 | 11015 | convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset) |
30e6f306 RH |
11016 | { |
11017 | dw_fde_ref fde; | |
11018 | dw_loc_list_ref list, *list_tail; | |
11019 | dw_cfi_ref cfi; | |
11020 | dw_cfa_location last_cfa, next_cfa; | |
11021 | const char *start_label, *last_label, *section; | |
11022 | ||
3ce6e42e XG |
11023 | fde = current_fde (); |
11024 | gcc_assert (fde != NULL); | |
30e6f306 RH |
11025 | |
11026 | section = secname_for_decl (current_function_decl); | |
11027 | list_tail = &list; | |
11028 | list = NULL; | |
11029 | ||
11030 | next_cfa.reg = INVALID_REGNUM; | |
11031 | next_cfa.offset = 0; | |
11032 | next_cfa.indirect = 0; | |
11033 | next_cfa.base_offset = 0; | |
11034 | ||
11035 | start_label = fde->dw_fde_begin; | |
11036 | ||
11037 | /* ??? Bald assumption that the CIE opcode list does not contain | |
11038 | advance opcodes. */ | |
11039 | for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next) | |
11040 | lookup_cfa_1 (cfi, &next_cfa); | |
11041 | ||
11042 | last_cfa = next_cfa; | |
11043 | last_label = start_label; | |
11044 | ||
11045 | for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next) | |
11046 | switch (cfi->dw_cfi_opc) | |
11047 | { | |
66cc7362 | 11048 | case DW_CFA_set_loc: |
30e6f306 RH |
11049 | case DW_CFA_advance_loc1: |
11050 | case DW_CFA_advance_loc2: | |
11051 | case DW_CFA_advance_loc4: | |
11052 | if (!cfa_equal_p (&last_cfa, &next_cfa)) | |
11053 | { | |
35d177a2 AO |
11054 | *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset), |
11055 | start_label, last_label, section, | |
11056 | list == NULL); | |
30e6f306 RH |
11057 | |
11058 | list_tail = &(*list_tail)->dw_loc_next; | |
11059 | last_cfa = next_cfa; | |
11060 | start_label = last_label; | |
11061 | } | |
11062 | last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
11063 | break; | |
11064 | ||
11065 | case DW_CFA_advance_loc: | |
11066 | /* The encoding is complex enough that we should never emit this. */ | |
11067 | case DW_CFA_remember_state: | |
11068 | case DW_CFA_restore_state: | |
11069 | /* We don't handle these two in this function. It would be possible | |
11070 | if it were to be required. */ | |
11071 | gcc_unreachable (); | |
11072 | ||
11073 | default: | |
11074 | lookup_cfa_1 (cfi, &next_cfa); | |
11075 | break; | |
11076 | } | |
11077 | ||
11078 | if (!cfa_equal_p (&last_cfa, &next_cfa)) | |
11079 | { | |
35d177a2 AO |
11080 | *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset), |
11081 | start_label, last_label, section, | |
11082 | list == NULL); | |
30e6f306 RH |
11083 | list_tail = &(*list_tail)->dw_loc_next; |
11084 | start_label = last_label; | |
11085 | } | |
35d177a2 AO |
11086 | *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset), |
11087 | start_label, fde->dw_fde_end, section, | |
11088 | list == NULL); | |
30e6f306 RH |
11089 | |
11090 | return list; | |
11091 | } | |
11092 | ||
35d177a2 AO |
11093 | /* Compute a displacement from the "steady-state frame pointer" to the |
11094 | frame base (often the same as the CFA), and store it in | |
11095 | frame_pointer_fb_offset. OFFSET is added to the displacement | |
11096 | before the latter is negated. */ | |
30e6f306 RH |
11097 | |
11098 | static void | |
35d177a2 | 11099 | compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset) |
30e6f306 | 11100 | { |
f6672e8e RH |
11101 | rtx reg, elim; |
11102 | ||
11103 | #ifdef FRAME_POINTER_CFA_OFFSET | |
11104 | reg = frame_pointer_rtx; | |
35d177a2 | 11105 | offset += FRAME_POINTER_CFA_OFFSET (current_function_decl); |
f6672e8e RH |
11106 | #else |
11107 | reg = arg_pointer_rtx; | |
35d177a2 | 11108 | offset += ARG_POINTER_CFA_OFFSET (current_function_decl); |
f6672e8e | 11109 | #endif |
30e6f306 | 11110 | |
f6672e8e RH |
11111 | elim = eliminate_regs (reg, VOIDmode, NULL_RTX); |
11112 | if (GET_CODE (elim) == PLUS) | |
11113 | { | |
11114 | offset += INTVAL (XEXP (elim, 1)); | |
11115 | elim = XEXP (elim, 0); | |
11116 | } | |
11117 | gcc_assert (elim == (frame_pointer_needed ? hard_frame_pointer_rtx | |
11118 | : stack_pointer_rtx)); | |
30e6f306 | 11119 | |
35d177a2 | 11120 | frame_pointer_fb_offset = -offset; |
30e6f306 RH |
11121 | } |
11122 | ||
b20b352b | 11123 | /* Generate a DW_AT_name attribute given some string value to be included as |
a3f97cbb | 11124 | the value of the attribute. */ |
71dfc51f | 11125 | |
c4274b22 | 11126 | static void |
7080f735 | 11127 | add_name_attribute (dw_die_ref die, const char *name_string) |
a3f97cbb | 11128 | { |
71dfc51f | 11129 | if (name_string != NULL && *name_string != 0) |
14a774a9 RK |
11130 | { |
11131 | if (demangle_name_func) | |
11132 | name_string = (*demangle_name_func) (name_string); | |
11133 | ||
11134 | add_AT_string (die, DW_AT_name, name_string); | |
11135 | } | |
a3f97cbb JW |
11136 | } |
11137 | ||
b20b352b | 11138 | /* Generate a DW_AT_comp_dir attribute for DIE. */ |
c4274b22 RH |
11139 | |
11140 | static void | |
7080f735 | 11141 | add_comp_dir_attribute (dw_die_ref die) |
c4274b22 | 11142 | { |
b20d9f0c | 11143 | const char *wd = get_src_pwd (); |
c4274b22 | 11144 | if (wd != NULL) |
c8aea42c | 11145 | add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd)); |
c4274b22 RH |
11146 | } |
11147 | ||
a3f97cbb | 11148 | /* Given a tree node describing an array bound (either lower or upper) output |
466446b0 | 11149 | a representation for that bound. */ |
71dfc51f | 11150 | |
a3f97cbb | 11151 | static void |
7080f735 | 11152 | add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound) |
a3f97cbb | 11153 | { |
a3f97cbb JW |
11154 | switch (TREE_CODE (bound)) |
11155 | { | |
11156 | case ERROR_MARK: | |
11157 | return; | |
11158 | ||
3ef42a0c | 11159 | /* All fixed-bounds are represented by INTEGER_CST nodes. */ |
a3f97cbb | 11160 | case INTEGER_CST: |
665f2503 RK |
11161 | if (! host_integerp (bound, 0) |
11162 | || (bound_attr == DW_AT_lower_bound | |
28985b81 | 11163 | && (((is_c_family () || is_java ()) && integer_zerop (bound)) |
665f2503 | 11164 | || (is_fortran () && integer_onep (bound))))) |
a1105617 | 11165 | /* Use the default. */ |
665f2503 | 11166 | ; |
141719a8 | 11167 | else |
665f2503 | 11168 | add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0)); |
a3f97cbb JW |
11169 | break; |
11170 | ||
1043771b | 11171 | CASE_CONVERT: |
ed239f5a | 11172 | case VIEW_CONVERT_EXPR: |
b1ccbc24 RK |
11173 | add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0)); |
11174 | break; | |
556273e0 | 11175 | |
a3f97cbb | 11176 | case SAVE_EXPR: |
a3f97cbb | 11177 | break; |
3f76745e | 11178 | |
ef76d03b | 11179 | case VAR_DECL: |
d8041cc8 | 11180 | case PARM_DECL: |
6de9cd9a | 11181 | case RESULT_DECL: |
d8041cc8 RH |
11182 | { |
11183 | dw_die_ref decl_die = lookup_decl_die (bound); | |
11184 | ||
11185 | /* ??? Can this happen, or should the variable have been bound | |
11186 | first? Probably it can, since I imagine that we try to create | |
11187 | the types of parameters in the order in which they exist in | |
0b34cf1e | 11188 | the list, and won't have created a forward reference to a |
d8041cc8 RH |
11189 | later parameter. */ |
11190 | if (decl_die != NULL) | |
11191 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
11192 | break; | |
11193 | } | |
ef76d03b | 11194 | |
3f76745e | 11195 | default: |
d8041cc8 RH |
11196 | { |
11197 | /* Otherwise try to create a stack operation procedure to | |
11198 | evaluate the value of the array bound. */ | |
11199 | ||
11200 | dw_die_ref ctx, decl_die; | |
11201 | dw_loc_descr_ref loc; | |
11202 | ||
1a186ec5 | 11203 | loc = loc_descriptor_from_tree (bound); |
d8041cc8 RH |
11204 | if (loc == NULL) |
11205 | break; | |
11206 | ||
e7af1d45 RK |
11207 | if (current_function_decl == 0) |
11208 | ctx = comp_unit_die; | |
11209 | else | |
11210 | ctx = lookup_decl_die (current_function_decl); | |
d8041cc8 | 11211 | |
54ba1f0d | 11212 | decl_die = new_die (DW_TAG_variable, ctx, bound); |
d8041cc8 RH |
11213 | add_AT_flag (decl_die, DW_AT_artificial, 1); |
11214 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
11215 | add_AT_loc (decl_die, DW_AT_location, loc); | |
11216 | ||
11217 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
11218 | break; | |
11219 | } | |
a3f97cbb JW |
11220 | } |
11221 | } | |
11222 | ||
11223 | /* Note that the block of subscript information for an array type also | |
11224 | includes information about the element type of type given array type. */ | |
71dfc51f | 11225 | |
a3f97cbb | 11226 | static void |
7080f735 | 11227 | add_subscript_info (dw_die_ref type_die, tree type) |
a3f97cbb | 11228 | { |
081f5e7e | 11229 | #ifndef MIPS_DEBUGGING_INFO |
b3694847 | 11230 | unsigned dimension_number; |
081f5e7e | 11231 | #endif |
b3694847 SS |
11232 | tree lower, upper; |
11233 | dw_die_ref subrange_die; | |
a3f97cbb | 11234 | |
556273e0 | 11235 | /* The GNU compilers represent multidimensional array types as sequences of |
a3f97cbb JW |
11236 | one dimensional array types whose element types are themselves array |
11237 | types. Here we squish that down, so that each multidimensional array | |
556273e0 | 11238 | type gets only one array_type DIE in the Dwarf debugging info. The draft |
a3f97cbb JW |
11239 | Dwarf specification say that we are allowed to do this kind of |
11240 | compression in C (because there is no difference between an array or | |
556273e0 | 11241 | arrays and a multidimensional array in C) but for other source languages |
a3f97cbb | 11242 | (e.g. Ada) we probably shouldn't do this. */ |
71dfc51f | 11243 | |
a3f97cbb JW |
11244 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
11245 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
11246 | We work around this by disabling this feature. See also | |
11247 | gen_array_type_die. */ | |
11248 | #ifndef MIPS_DEBUGGING_INFO | |
11249 | for (dimension_number = 0; | |
11250 | TREE_CODE (type) == ARRAY_TYPE; | |
11251 | type = TREE_TYPE (type), dimension_number++) | |
a3f97cbb | 11252 | #endif |
2ad9852d | 11253 | { |
b3694847 | 11254 | tree domain = TYPE_DOMAIN (type); |
a3f97cbb JW |
11255 | |
11256 | /* Arrays come in three flavors: Unspecified bounds, fixed bounds, | |
556273e0 | 11257 | and (in GNU C only) variable bounds. Handle all three forms |
73c68f61 | 11258 | here. */ |
54ba1f0d | 11259 | subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL); |
a3f97cbb JW |
11260 | if (domain) |
11261 | { | |
11262 | /* We have an array type with specified bounds. */ | |
11263 | lower = TYPE_MIN_VALUE (domain); | |
11264 | upper = TYPE_MAX_VALUE (domain); | |
11265 | ||
beb235f8 | 11266 | /* Define the index type. */ |
a9d38797 | 11267 | if (TREE_TYPE (domain)) |
ef76d03b JW |
11268 | { |
11269 | /* ??? This is probably an Ada unnamed subrange type. Ignore the | |
11270 | TREE_TYPE field. We can't emit debug info for this | |
11271 | because it is an unnamed integral type. */ | |
11272 | if (TREE_CODE (domain) == INTEGER_TYPE | |
11273 | && TYPE_NAME (domain) == NULL_TREE | |
11274 | && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE | |
11275 | && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE) | |
556273e0 | 11276 | ; |
ef76d03b JW |
11277 | else |
11278 | add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0, | |
11279 | type_die); | |
11280 | } | |
a9d38797 | 11281 | |
e1ee5cdc RH |
11282 | /* ??? If upper is NULL, the array has unspecified length, |
11283 | but it does have a lower bound. This happens with Fortran | |
11284 | dimension arr(N:*) | |
7080f735 | 11285 | Since the debugger is definitely going to need to know N |
e1ee5cdc RH |
11286 | to produce useful results, go ahead and output the lower |
11287 | bound solo, and hope the debugger can cope. */ | |
11288 | ||
141719a8 | 11289 | add_bound_info (subrange_die, DW_AT_lower_bound, lower); |
e1ee5cdc RH |
11290 | if (upper) |
11291 | add_bound_info (subrange_die, DW_AT_upper_bound, upper); | |
a3f97cbb | 11292 | } |
71dfc51f | 11293 | |
2ad9852d RK |
11294 | /* Otherwise we have an array type with an unspecified length. The |
11295 | DWARF-2 spec does not say how to handle this; let's just leave out the | |
11296 | bounds. */ | |
a3f97cbb | 11297 | } |
a3f97cbb JW |
11298 | } |
11299 | ||
11300 | static void | |
7080f735 | 11301 | add_byte_size_attribute (dw_die_ref die, tree tree_node) |
a3f97cbb | 11302 | { |
b3694847 | 11303 | unsigned size; |
a3f97cbb JW |
11304 | |
11305 | switch (TREE_CODE (tree_node)) | |
11306 | { | |
11307 | case ERROR_MARK: | |
11308 | size = 0; | |
11309 | break; | |
11310 | case ENUMERAL_TYPE: | |
11311 | case RECORD_TYPE: | |
11312 | case UNION_TYPE: | |
11313 | case QUAL_UNION_TYPE: | |
11314 | size = int_size_in_bytes (tree_node); | |
11315 | break; | |
11316 | case FIELD_DECL: | |
11317 | /* For a data member of a struct or union, the DW_AT_byte_size is | |
73c68f61 SS |
11318 | generally given as the number of bytes normally allocated for an |
11319 | object of the *declared* type of the member itself. This is true | |
11320 | even for bit-fields. */ | |
a3f97cbb JW |
11321 | size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT; |
11322 | break; | |
11323 | default: | |
ced3f397 | 11324 | gcc_unreachable (); |
a3f97cbb JW |
11325 | } |
11326 | ||
11327 | /* Note that `size' might be -1 when we get to this point. If it is, that | |
11328 | indicates that the byte size of the entity in question is variable. We | |
11329 | have no good way of expressing this fact in Dwarf at the present time, | |
11330 | so just let the -1 pass on through. */ | |
a3f97cbb JW |
11331 | add_AT_unsigned (die, DW_AT_byte_size, size); |
11332 | } | |
11333 | ||
11334 | /* For a FIELD_DECL node which represents a bit-field, output an attribute | |
11335 | which specifies the distance in bits from the highest order bit of the | |
11336 | "containing object" for the bit-field to the highest order bit of the | |
11337 | bit-field itself. | |
11338 | ||
2ad9852d RK |
11339 | For any given bit-field, the "containing object" is a hypothetical object |
11340 | (of some integral or enum type) within which the given bit-field lives. The | |
11341 | type of this hypothetical "containing object" is always the same as the | |
11342 | declared type of the individual bit-field itself. The determination of the | |
11343 | exact location of the "containing object" for a bit-field is rather | |
11344 | complicated. It's handled by the `field_byte_offset' function (above). | |
a3f97cbb JW |
11345 | |
11346 | Note that it is the size (in bytes) of the hypothetical "containing object" | |
11347 | which will be given in the DW_AT_byte_size attribute for this bit-field. | |
11348 | (See `byte_size_attribute' above). */ | |
71dfc51f RK |
11349 | |
11350 | static inline void | |
7080f735 | 11351 | add_bit_offset_attribute (dw_die_ref die, tree decl) |
a3f97cbb | 11352 | { |
665f2503 RK |
11353 | HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl); |
11354 | tree type = DECL_BIT_FIELD_TYPE (decl); | |
11355 | HOST_WIDE_INT bitpos_int; | |
11356 | HOST_WIDE_INT highest_order_object_bit_offset; | |
11357 | HOST_WIDE_INT highest_order_field_bit_offset; | |
11358 | HOST_WIDE_INT unsigned bit_offset; | |
a3f97cbb | 11359 | |
3a88cbd1 | 11360 | /* Must be a field and a bit field. */ |
ced3f397 | 11361 | gcc_assert (type && TREE_CODE (decl) == FIELD_DECL); |
a3f97cbb JW |
11362 | |
11363 | /* We can't yet handle bit-fields whose offsets are variable, so if we | |
11364 | encounter such things, just return without generating any attribute | |
665f2503 RK |
11365 | whatsoever. Likewise for variable or too large size. */ |
11366 | if (! host_integerp (bit_position (decl), 0) | |
11367 | || ! host_integerp (DECL_SIZE (decl), 1)) | |
71dfc51f RK |
11368 | return; |
11369 | ||
665f2503 | 11370 | bitpos_int = int_bit_position (decl); |
a3f97cbb JW |
11371 | |
11372 | /* Note that the bit offset is always the distance (in bits) from the | |
556273e0 KH |
11373 | highest-order bit of the "containing object" to the highest-order bit of |
11374 | the bit-field itself. Since the "high-order end" of any object or field | |
a3f97cbb JW |
11375 | is different on big-endian and little-endian machines, the computation |
11376 | below must take account of these differences. */ | |
11377 | highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; | |
11378 | highest_order_field_bit_offset = bitpos_int; | |
11379 | ||
71dfc51f | 11380 | if (! BYTES_BIG_ENDIAN) |
a3f97cbb | 11381 | { |
665f2503 | 11382 | highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0); |
a3f97cbb JW |
11383 | highest_order_object_bit_offset += simple_type_size_in_bits (type); |
11384 | } | |
71dfc51f RK |
11385 | |
11386 | bit_offset | |
11387 | = (! BYTES_BIG_ENDIAN | |
11388 | ? highest_order_object_bit_offset - highest_order_field_bit_offset | |
11389 | : highest_order_field_bit_offset - highest_order_object_bit_offset); | |
a3f97cbb JW |
11390 | |
11391 | add_AT_unsigned (die, DW_AT_bit_offset, bit_offset); | |
11392 | } | |
11393 | ||
11394 | /* For a FIELD_DECL node which represents a bit field, output an attribute | |
11395 | which specifies the length in bits of the given field. */ | |
71dfc51f RK |
11396 | |
11397 | static inline void | |
7080f735 | 11398 | add_bit_size_attribute (dw_die_ref die, tree decl) |
a3f97cbb | 11399 | { |
3a88cbd1 | 11400 | /* Must be a field and a bit field. */ |
ced3f397 NS |
11401 | gcc_assert (TREE_CODE (decl) == FIELD_DECL |
11402 | && DECL_BIT_FIELD_TYPE (decl)); | |
665f2503 RK |
11403 | |
11404 | if (host_integerp (DECL_SIZE (decl), 1)) | |
11405 | add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1)); | |
a3f97cbb JW |
11406 | } |
11407 | ||
88dad228 | 11408 | /* If the compiled language is ANSI C, then add a 'prototyped' |
a3f97cbb | 11409 | attribute, if arg types are given for the parameters of a function. */ |
71dfc51f RK |
11410 | |
11411 | static inline void | |
7080f735 | 11412 | add_prototyped_attribute (dw_die_ref die, tree func_type) |
a3f97cbb | 11413 | { |
88dad228 JM |
11414 | if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89 |
11415 | && TYPE_ARG_TYPES (func_type) != NULL) | |
11416 | add_AT_flag (die, DW_AT_prototyped, 1); | |
a3f97cbb JW |
11417 | } |
11418 | ||
a3f97cbb JW |
11419 | /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found |
11420 | by looking in either the type declaration or object declaration | |
11421 | equate table. */ | |
71dfc51f RK |
11422 | |
11423 | static inline void | |
7080f735 | 11424 | add_abstract_origin_attribute (dw_die_ref die, tree origin) |
a3f97cbb JW |
11425 | { |
11426 | dw_die_ref origin_die = NULL; | |
bbc6ae08 | 11427 | |
d10b8e05 | 11428 | if (TREE_CODE (origin) != FUNCTION_DECL) |
e40a1c67 JM |
11429 | { |
11430 | /* We may have gotten separated from the block for the inlined | |
11431 | function, if we're in an exception handler or some such; make | |
11432 | sure that the abstract function has been written out. | |
11433 | ||
73c68f61 | 11434 | Doing this for nested functions is wrong, however; functions are |
e40a1c67 | 11435 | distinct units, and our context might not even be inline. */ |
fb13d4d0 | 11436 | tree fn = origin; |
2ad9852d | 11437 | |
fb13d4d0 JM |
11438 | if (TYPE_P (fn)) |
11439 | fn = TYPE_STUB_DECL (fn); | |
2878ea73 | 11440 | |
596b98ce | 11441 | fn = decl_function_context (fn); |
e40a1c67 | 11442 | if (fn) |
1edf43d6 | 11443 | dwarf2out_abstract_function (fn); |
e40a1c67 | 11444 | } |
44db1d9c | 11445 | |
2f939d94 | 11446 | if (DECL_P (origin)) |
71dfc51f | 11447 | origin_die = lookup_decl_die (origin); |
2f939d94 | 11448 | else if (TYPE_P (origin)) |
71dfc51f RK |
11449 | origin_die = lookup_type_die (origin); |
11450 | ||
9acf766f DB |
11451 | /* XXX: Functions that are never lowered don't always have correct block |
11452 | trees (in the case of java, they simply have no block tree, in some other | |
11453 | languages). For these functions, there is nothing we can really do to | |
11454 | output correct debug info for inlined functions in all cases. Rather | |
535a42b1 | 11455 | than die, we'll just produce deficient debug info now, in that we will |
9acf766f DB |
11456 | have variables without a proper abstract origin. In the future, when all |
11457 | functions are lowered, we should re-add a gcc_assert (origin_die) | |
11458 | here. */ | |
556273e0 | 11459 | |
9acf766f DB |
11460 | if (origin_die) |
11461 | add_AT_die_ref (die, DW_AT_abstract_origin, origin_die); | |
a3f97cbb JW |
11462 | } |
11463 | ||
bdb669cb JM |
11464 | /* We do not currently support the pure_virtual attribute. */ |
11465 | ||
71dfc51f | 11466 | static inline void |
7080f735 | 11467 | add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl) |
a3f97cbb | 11468 | { |
a94dbf2c | 11469 | if (DECL_VINDEX (func_decl)) |
a3f97cbb | 11470 | { |
bdb669cb | 11471 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); |
665f2503 RK |
11472 | |
11473 | if (host_integerp (DECL_VINDEX (func_decl), 0)) | |
11474 | add_AT_loc (die, DW_AT_vtable_elem_location, | |
11475 | new_loc_descr (DW_OP_constu, | |
11476 | tree_low_cst (DECL_VINDEX (func_decl), 0), | |
11477 | 0)); | |
71dfc51f | 11478 | |
a94dbf2c JM |
11479 | /* GNU extension: Record what type this method came from originally. */ |
11480 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
11481 | add_AT_die_ref (die, DW_AT_containing_type, | |
11482 | lookup_type_die (DECL_CONTEXT (func_decl))); | |
a3f97cbb JW |
11483 | } |
11484 | } | |
11485 | \f | |
b2932ae5 | 11486 | /* Add source coordinate attributes for the given decl. */ |
71dfc51f | 11487 | |
b2932ae5 | 11488 | static void |
7080f735 | 11489 | add_src_coords_attributes (dw_die_ref die, tree decl) |
b2932ae5 | 11490 | { |
6773e15f | 11491 | expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl)); |
71dfc51f | 11492 | |
d5688810 | 11493 | add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file)); |
6773e15f | 11494 | add_AT_unsigned (die, DW_AT_decl_line, s.line); |
b2932ae5 JM |
11495 | } |
11496 | ||
b20b352b | 11497 | /* Add a DW_AT_name attribute and source coordinate attribute for the |
a3f97cbb | 11498 | given decl, but only if it actually has a name. */ |
71dfc51f | 11499 | |
a3f97cbb | 11500 | static void |
7080f735 | 11501 | add_name_and_src_coords_attributes (dw_die_ref die, tree decl) |
a3f97cbb | 11502 | { |
b3694847 | 11503 | tree decl_name; |
71dfc51f | 11504 | |
556273e0 | 11505 | decl_name = DECL_NAME (decl); |
71dfc51f | 11506 | if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL) |
a3f97cbb | 11507 | { |
a1d7ffe3 | 11508 | add_name_attribute (die, dwarf2_name (decl, 0)); |
a96c67ec JM |
11509 | if (! DECL_ARTIFICIAL (decl)) |
11510 | add_src_coords_attributes (die, decl); | |
e689ae67 | 11511 | |
a1d7ffe3 | 11512 | if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) |
bc808e0b | 11513 | && TREE_PUBLIC (decl) |
5daf7c0a | 11514 | && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) |
fcc207bf | 11515 | && !DECL_ABSTRACT (decl) |
9adfa70e FXC |
11516 | && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl)) |
11517 | && !is_fortran ()) | |
a1d7ffe3 JM |
11518 | add_AT_string (die, DW_AT_MIPS_linkage_name, |
11519 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
a3f97cbb | 11520 | } |
7a0c8d71 DR |
11521 | |
11522 | #ifdef VMS_DEBUGGING_INFO | |
7a0c8d71 DR |
11523 | /* Get the function's name, as described by its RTL. This may be different |
11524 | from the DECL_NAME name used in the source file. */ | |
11525 | if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl)) | |
c470afad RK |
11526 | { |
11527 | add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address, | |
11528 | XEXP (DECL_RTL (decl), 0)); | |
a1bbd445 | 11529 | VEC_safe_push (tree, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0)); |
c470afad | 11530 | } |
7a0c8d71 | 11531 | #endif |
a3f97cbb JW |
11532 | } |
11533 | ||
556273e0 | 11534 | /* Push a new declaration scope. */ |
71dfc51f | 11535 | |
a3f97cbb | 11536 | static void |
7080f735 | 11537 | push_decl_scope (tree scope) |
a3f97cbb | 11538 | { |
0fdc587b | 11539 | VEC_safe_push (tree, gc, decl_scope_table, scope); |
a3f97cbb JW |
11540 | } |
11541 | ||
777ad4c2 | 11542 | /* Pop a declaration scope. */ |
2ad9852d | 11543 | |
777ad4c2 | 11544 | static inline void |
7080f735 | 11545 | pop_decl_scope (void) |
777ad4c2 | 11546 | { |
0fdc587b | 11547 | VEC_pop (tree, decl_scope_table); |
777ad4c2 JM |
11548 | } |
11549 | ||
11550 | /* Return the DIE for the scope that immediately contains this type. | |
11551 | Non-named types get global scope. Named types nested in other | |
11552 | types get their containing scope if it's open, or global scope | |
11553 | otherwise. All other types (i.e. function-local named types) get | |
11554 | the current active scope. */ | |
71dfc51f | 11555 | |
a3f97cbb | 11556 | static dw_die_ref |
7080f735 | 11557 | scope_die_for (tree t, dw_die_ref context_die) |
a3f97cbb | 11558 | { |
b3694847 SS |
11559 | dw_die_ref scope_die = NULL; |
11560 | tree containing_scope; | |
11561 | int i; | |
a3f97cbb | 11562 | |
777ad4c2 | 11563 | /* Non-types always go in the current scope. */ |
ced3f397 | 11564 | gcc_assert (TYPE_P (t)); |
777ad4c2 JM |
11565 | |
11566 | containing_scope = TYPE_CONTEXT (t); | |
ab72d377 | 11567 | |
66c78aa9 | 11568 | /* Use the containing namespace if it was passed in (for a declaration). */ |
2addbe1d | 11569 | if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL) |
66c78aa9 JM |
11570 | { |
11571 | if (context_die == lookup_decl_die (containing_scope)) | |
11572 | /* OK */; | |
11573 | else | |
11574 | containing_scope = NULL_TREE; | |
11575 | } | |
2addbe1d | 11576 | |
5f2f160c JM |
11577 | /* Ignore function type "scopes" from the C frontend. They mean that |
11578 | a tagged type is local to a parmlist of a function declarator, but | |
11579 | that isn't useful to DWARF. */ | |
11580 | if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE) | |
11581 | containing_scope = NULL_TREE; | |
11582 | ||
71dfc51f RK |
11583 | if (containing_scope == NULL_TREE) |
11584 | scope_die = comp_unit_die; | |
777ad4c2 | 11585 | else if (TYPE_P (containing_scope)) |
348bb3c7 | 11586 | { |
777ad4c2 JM |
11587 | /* For types, we can just look up the appropriate DIE. But |
11588 | first we check to see if we're in the middle of emitting it | |
11589 | so we know where the new DIE should go. */ | |
0fdc587b KH |
11590 | for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i) |
11591 | if (VEC_index (tree, decl_scope_table, i) == containing_scope) | |
348bb3c7 JM |
11592 | break; |
11593 | ||
11594 | if (i < 0) | |
11595 | { | |
ced3f397 NS |
11596 | gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE |
11597 | || TREE_ASM_WRITTEN (containing_scope)); | |
348bb3c7 JM |
11598 | |
11599 | /* If none of the current dies are suitable, we get file scope. */ | |
11600 | scope_die = comp_unit_die; | |
11601 | } | |
11602 | else | |
777ad4c2 | 11603 | scope_die = lookup_type_die (containing_scope); |
348bb3c7 | 11604 | } |
a3f97cbb | 11605 | else |
777ad4c2 | 11606 | scope_die = context_die; |
71dfc51f | 11607 | |
a3f97cbb JW |
11608 | return scope_die; |
11609 | } | |
11610 | ||
2ad9852d | 11611 | /* Returns nonzero if CONTEXT_DIE is internal to a function. */ |
777ad4c2 JM |
11612 | |
11613 | static inline int | |
7080f735 | 11614 | local_scope_p (dw_die_ref context_die) |
a3f97cbb | 11615 | { |
777ad4c2 JM |
11616 | for (; context_die; context_die = context_die->die_parent) |
11617 | if (context_die->die_tag == DW_TAG_inlined_subroutine | |
11618 | || context_die->die_tag == DW_TAG_subprogram) | |
11619 | return 1; | |
2ad9852d | 11620 | |
777ad4c2 | 11621 | return 0; |
a3f97cbb JW |
11622 | } |
11623 | ||
66c78aa9 JM |
11624 | /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding |
11625 | whether or not to treat a DIE in this context as a declaration. */ | |
9765e357 JM |
11626 | |
11627 | static inline int | |
66c78aa9 | 11628 | class_or_namespace_scope_p (dw_die_ref context_die) |
9765e357 JM |
11629 | { |
11630 | return (context_die | |
11631 | && (context_die->die_tag == DW_TAG_structure_type | |
394d9fe7 AO |
11632 | || context_die->die_tag == DW_TAG_class_type |
11633 | || context_die->die_tag == DW_TAG_interface_type | |
66c78aa9 JM |
11634 | || context_die->die_tag == DW_TAG_union_type |
11635 | || context_die->die_tag == DW_TAG_namespace)); | |
9765e357 JM |
11636 | } |
11637 | ||
a3f97cbb JW |
11638 | /* Many forms of DIEs require a "type description" attribute. This |
11639 | routine locates the proper "type descriptor" die for the type given | |
b20b352b | 11640 | by 'type', and adds a DW_AT_type attribute below the given die. */ |
71dfc51f | 11641 | |
a3f97cbb | 11642 | static void |
7080f735 AJ |
11643 | add_type_attribute (dw_die_ref object_die, tree type, int decl_const, |
11644 | int decl_volatile, dw_die_ref context_die) | |
a3f97cbb | 11645 | { |
b3694847 SS |
11646 | enum tree_code code = TREE_CODE (type); |
11647 | dw_die_ref type_die = NULL; | |
a3f97cbb | 11648 | |
325217ed CF |
11649 | /* ??? If this type is an unnamed subrange type of an integral, floating-point |
11650 | or fixed-point type, use the inner type. This is because we have no | |
ef76d03b JW |
11651 | support for unnamed types in base_type_die. This can happen if this is |
11652 | an Ada subrange type. Correct solution is emit a subrange type die. */ | |
325217ed | 11653 | if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE) |
b1ccbc24 RK |
11654 | && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0) |
11655 | type = TREE_TYPE (type), code = TREE_CODE (type); | |
11656 | ||
2ad9852d RK |
11657 | if (code == ERROR_MARK |
11658 | /* Handle a special case. For functions whose return type is void, we | |
11659 | generate *no* type attribute. (Note that no object may have type | |
11660 | `void', so this only applies to function return types). */ | |
11661 | || code == VOID_TYPE) | |
b1ccbc24 | 11662 | return; |
a3f97cbb | 11663 | |
a3f97cbb JW |
11664 | type_die = modified_type_die (type, |
11665 | decl_const || TYPE_READONLY (type), | |
11666 | decl_volatile || TYPE_VOLATILE (type), | |
ab72d377 | 11667 | context_die); |
2ad9852d | 11668 | |
a3f97cbb | 11669 | if (type_die != NULL) |
71dfc51f | 11670 | add_AT_die_ref (object_die, DW_AT_type, type_die); |
a3f97cbb JW |
11671 | } |
11672 | ||
a1c496cb EC |
11673 | /* Given an object die, add the calling convention attribute for the |
11674 | function call type. */ | |
11675 | static void | |
9adfa70e | 11676 | add_calling_convention_attribute (dw_die_ref subr_die, tree decl) |
a1c496cb EC |
11677 | { |
11678 | enum dwarf_calling_convention value = DW_CC_normal; | |
11679 | ||
9adfa70e FXC |
11680 | value = targetm.dwarf_calling_convention (TREE_TYPE (decl)); |
11681 | ||
11682 | /* DWARF doesn't provide a way to identify a program's source-level | |
11683 | entry point. DW_AT_calling_convention attributes are only meant | |
11684 | to describe functions' calling conventions. However, lacking a | |
11685 | better way to signal the Fortran main program, we use this for the | |
11686 | time being, following existing custom. */ | |
11687 | if (is_fortran () | |
11688 | && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__")) | |
11689 | value = DW_CC_program; | |
a1c496cb | 11690 | |
b9e6959b EC |
11691 | /* Only add the attribute if the backend requests it, and |
11692 | is not DW_CC_normal. */ | |
11693 | if (value && (value != DW_CC_normal)) | |
a1c496cb EC |
11694 | add_AT_unsigned (subr_die, DW_AT_calling_convention, value); |
11695 | } | |
11696 | ||
a3f97cbb JW |
11697 | /* Given a tree pointer to a struct, class, union, or enum type node, return |
11698 | a pointer to the (string) tag name for the given type, or zero if the type | |
11699 | was declared without a tag. */ | |
71dfc51f | 11700 | |
d3e3972c | 11701 | static const char * |
9678086d | 11702 | type_tag (const_tree type) |
a3f97cbb | 11703 | { |
b3694847 | 11704 | const char *name = 0; |
a3f97cbb JW |
11705 | |
11706 | if (TYPE_NAME (type) != 0) | |
11707 | { | |
b3694847 | 11708 | tree t = 0; |
a3f97cbb JW |
11709 | |
11710 | /* Find the IDENTIFIER_NODE for the type name. */ | |
11711 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
11712 | t = TYPE_NAME (type); | |
bdb669cb | 11713 | |
556273e0 | 11714 | /* The g++ front end makes the TYPE_NAME of *each* tagged type point to |
73c68f61 SS |
11715 | a TYPE_DECL node, regardless of whether or not a `typedef' was |
11716 | involved. */ | |
a94dbf2c JM |
11717 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
11718 | && ! DECL_IGNORED_P (TYPE_NAME (type))) | |
a0ad3539 MM |
11719 | { |
11720 | /* We want to be extra verbose. Don't call dwarf_name if | |
11721 | DECL_NAME isn't set. The default hook for decl_printable_name | |
11722 | doesn't like that, and in this context it's correct to return | |
11723 | 0, instead of "<anonymous>" or the like. */ | |
11724 | if (DECL_NAME (TYPE_NAME (type))) | |
11725 | name = lang_hooks.dwarf_name (TYPE_NAME (type), 2); | |
11726 | } | |
bdb669cb | 11727 | |
a3f97cbb | 11728 | /* Now get the name as a string, or invent one. */ |
a0ad3539 | 11729 | if (!name && t != 0) |
a94dbf2c | 11730 | name = IDENTIFIER_POINTER (t); |
a3f97cbb | 11731 | } |
71dfc51f | 11732 | |
a3f97cbb JW |
11733 | return (name == 0 || *name == '\0') ? 0 : name; |
11734 | } | |
11735 | ||
11736 | /* Return the type associated with a data member, make a special check | |
11737 | for bit field types. */ | |
71dfc51f RK |
11738 | |
11739 | static inline tree | |
9678086d | 11740 | member_declared_type (const_tree member) |
a3f97cbb | 11741 | { |
71dfc51f | 11742 | return (DECL_BIT_FIELD_TYPE (member) |
2ad9852d | 11743 | ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member)); |
a3f97cbb JW |
11744 | } |
11745 | ||
d291dd49 | 11746 | /* Get the decl's label, as described by its RTL. This may be different |
a3f97cbb | 11747 | from the DECL_NAME name used in the source file. */ |
71dfc51f | 11748 | |
487a6e06 | 11749 | #if 0 |
d3e3972c | 11750 | static const char * |
7080f735 | 11751 | decl_start_label (tree decl) |
a3f97cbb JW |
11752 | { |
11753 | rtx x; | |
d3e3972c | 11754 | const char *fnname; |
2ad9852d | 11755 | |
a3f97cbb | 11756 | x = DECL_RTL (decl); |
ced3f397 | 11757 | gcc_assert (MEM_P (x)); |
71dfc51f | 11758 | |
a3f97cbb | 11759 | x = XEXP (x, 0); |
ced3f397 | 11760 | gcc_assert (GET_CODE (x) == SYMBOL_REF); |
71dfc51f | 11761 | |
a3f97cbb JW |
11762 | fnname = XSTR (x, 0); |
11763 | return fnname; | |
11764 | } | |
487a6e06 | 11765 | #endif |
a3f97cbb | 11766 | \f |
956d6950 | 11767 | /* These routines generate the internal representation of the DIE's for |
a3f97cbb | 11768 | the compilation unit. Debugging information is collected by walking |
88dad228 | 11769 | the declaration trees passed in from dwarf2out_decl(). */ |
a3f97cbb JW |
11770 | |
11771 | static void | |
7080f735 | 11772 | gen_array_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 11773 | { |
b3694847 SS |
11774 | dw_die_ref scope_die = scope_die_for (type, context_die); |
11775 | dw_die_ref array_die; | |
11776 | tree element_type; | |
bdb669cb | 11777 | |
a9d38797 JM |
11778 | /* ??? The SGI dwarf reader fails for array of array of enum types unless |
11779 | the inner array type comes before the outer array type. Thus we must | |
11780 | call gen_type_die before we call new_die. See below also. */ | |
11781 | #ifdef MIPS_DEBUGGING_INFO | |
11782 | gen_type_die (TREE_TYPE (type), context_die); | |
11783 | #endif | |
11784 | ||
54ba1f0d | 11785 | array_die = new_die (DW_TAG_array_type, scope_die, type); |
84f0ace0 JM |
11786 | add_name_attribute (array_die, type_tag (type)); |
11787 | equate_type_number_to_die (type, array_die); | |
11788 | ||
11789 | if (TREE_CODE (type) == VECTOR_TYPE) | |
11790 | { | |
11791 | /* The frontend feeds us a representation for the vector as a struct | |
11792 | containing an array. Pull out the array type. */ | |
11793 | type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type))); | |
11794 | add_AT_flag (array_die, DW_AT_GNU_vector, 1); | |
11795 | } | |
a9d38797 | 11796 | |
502630f4 JJ |
11797 | /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */ |
11798 | if (is_fortran () | |
11799 | && TREE_CODE (type) == ARRAY_TYPE | |
11800 | && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE) | |
11801 | add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major); | |
11802 | ||
a3f97cbb JW |
11803 | #if 0 |
11804 | /* We default the array ordering. SDB will probably do | |
11805 | the right things even if DW_AT_ordering is not present. It's not even | |
11806 | an issue until we start to get into multidimensional arrays anyway. If | |
11807 | SDB is ever caught doing the Wrong Thing for multi-dimensional arrays, | |
11808 | then we'll have to put the DW_AT_ordering attribute back in. (But if | |
11809 | and when we find out that we need to put these in, we will only do so | |
11810 | for multidimensional arrays. */ | |
11811 | add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major); | |
11812 | #endif | |
11813 | ||
a9d38797 | 11814 | #ifdef MIPS_DEBUGGING_INFO |
4edb7b60 JM |
11815 | /* The SGI compilers handle arrays of unknown bound by setting |
11816 | AT_declaration and not emitting any subrange DIEs. */ | |
a9d38797 | 11817 | if (! TYPE_DOMAIN (type)) |
371e8c4f | 11818 | add_AT_flag (array_die, DW_AT_declaration, 1); |
a9d38797 JM |
11819 | else |
11820 | #endif | |
11821 | add_subscript_info (array_die, type); | |
a3f97cbb | 11822 | |
a3f97cbb JW |
11823 | /* Add representation of the type of the elements of this array type. */ |
11824 | element_type = TREE_TYPE (type); | |
71dfc51f | 11825 | |
a3f97cbb JW |
11826 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
11827 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
11828 | We work around this by disabling this feature. See also | |
11829 | add_subscript_info. */ | |
11830 | #ifndef MIPS_DEBUGGING_INFO | |
71dfc51f RK |
11831 | while (TREE_CODE (element_type) == ARRAY_TYPE) |
11832 | element_type = TREE_TYPE (element_type); | |
11833 | ||
a3f97cbb | 11834 | gen_type_die (element_type, context_die); |
a9d38797 | 11835 | #endif |
a3f97cbb JW |
11836 | |
11837 | add_type_attribute (array_die, element_type, 0, 0, context_die); | |
89708594 CT |
11838 | |
11839 | if (get_AT (array_die, DW_AT_name)) | |
11840 | add_pubtype (type, array_die); | |
a3f97cbb JW |
11841 | } |
11842 | ||
fad0afd7 JJ |
11843 | static dw_loc_descr_ref |
11844 | descr_info_loc (tree val, tree base_decl) | |
11845 | { | |
11846 | HOST_WIDE_INT size; | |
11847 | dw_loc_descr_ref loc, loc2; | |
11848 | enum dwarf_location_atom op; | |
11849 | ||
11850 | if (val == base_decl) | |
11851 | return new_loc_descr (DW_OP_push_object_address, 0, 0); | |
11852 | ||
11853 | switch (TREE_CODE (val)) | |
11854 | { | |
1043771b | 11855 | CASE_CONVERT: |
fad0afd7 JJ |
11856 | return descr_info_loc (TREE_OPERAND (val, 0), base_decl); |
11857 | case INTEGER_CST: | |
11858 | if (host_integerp (val, 0)) | |
11859 | return int_loc_descriptor (tree_low_cst (val, 0)); | |
11860 | break; | |
11861 | case INDIRECT_REF: | |
11862 | size = int_size_in_bytes (TREE_TYPE (val)); | |
11863 | if (size < 0) | |
11864 | break; | |
11865 | loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl); | |
11866 | if (!loc) | |
11867 | break; | |
11868 | if (size == DWARF2_ADDR_SIZE) | |
11869 | add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0)); | |
11870 | else | |
11871 | add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0)); | |
11872 | return loc; | |
11873 | case POINTER_PLUS_EXPR: | |
11874 | case PLUS_EXPR: | |
11875 | if (host_integerp (TREE_OPERAND (val, 1), 1) | |
11876 | && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1) | |
11877 | < 16384) | |
11878 | { | |
11879 | loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl); | |
11880 | if (!loc) | |
11881 | break; | |
11882 | add_loc_descr (&loc, | |
11883 | new_loc_descr (DW_OP_plus_uconst, | |
11884 | tree_low_cst (TREE_OPERAND (val, 1), | |
11885 | 1), 0)); | |
11886 | } | |
11887 | else | |
11888 | { | |
11889 | op = DW_OP_plus; | |
11890 | do_binop: | |
11891 | loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl); | |
11892 | if (!loc) | |
11893 | break; | |
11894 | loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl); | |
11895 | if (!loc2) | |
11896 | break; | |
11897 | add_loc_descr (&loc, loc2); | |
11898 | add_loc_descr (&loc2, new_loc_descr (op, 0, 0)); | |
11899 | } | |
11900 | return loc; | |
11901 | case MINUS_EXPR: | |
11902 | op = DW_OP_minus; | |
11903 | goto do_binop; | |
11904 | case MULT_EXPR: | |
11905 | op = DW_OP_mul; | |
11906 | goto do_binop; | |
11907 | case EQ_EXPR: | |
11908 | op = DW_OP_eq; | |
11909 | goto do_binop; | |
11910 | case NE_EXPR: | |
11911 | op = DW_OP_ne; | |
11912 | goto do_binop; | |
11913 | default: | |
11914 | break; | |
11915 | } | |
11916 | return NULL; | |
11917 | } | |
11918 | ||
11919 | static void | |
11920 | add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr, | |
11921 | tree val, tree base_decl) | |
11922 | { | |
11923 | dw_loc_descr_ref loc; | |
11924 | ||
11925 | if (host_integerp (val, 0)) | |
11926 | { | |
11927 | add_AT_unsigned (die, attr, tree_low_cst (val, 0)); | |
11928 | return; | |
11929 | } | |
11930 | ||
11931 | loc = descr_info_loc (val, base_decl); | |
11932 | if (!loc) | |
11933 | return; | |
11934 | ||
11935 | add_AT_loc (die, attr, loc); | |
11936 | } | |
11937 | ||
11938 | /* This routine generates DIE for array with hidden descriptor, details | |
11939 | are filled into *info by a langhook. */ | |
11940 | ||
11941 | static void | |
11942 | gen_descr_array_type_die (tree type, struct array_descr_info *info, | |
11943 | dw_die_ref context_die) | |
11944 | { | |
11945 | dw_die_ref scope_die = scope_die_for (type, context_die); | |
11946 | dw_die_ref array_die; | |
11947 | int dim; | |
11948 | ||
11949 | array_die = new_die (DW_TAG_array_type, scope_die, type); | |
11950 | add_name_attribute (array_die, type_tag (type)); | |
11951 | equate_type_number_to_die (type, array_die); | |
11952 | ||
502630f4 JJ |
11953 | /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */ |
11954 | if (is_fortran () | |
11955 | && info->ndimensions >= 2) | |
11956 | add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major); | |
11957 | ||
fad0afd7 JJ |
11958 | if (info->data_location) |
11959 | add_descr_info_field (array_die, DW_AT_data_location, info->data_location, | |
11960 | info->base_decl); | |
11961 | if (info->associated) | |
11962 | add_descr_info_field (array_die, DW_AT_associated, info->associated, | |
11963 | info->base_decl); | |
11964 | if (info->allocated) | |
11965 | add_descr_info_field (array_die, DW_AT_allocated, info->allocated, | |
11966 | info->base_decl); | |
11967 | ||
11968 | for (dim = 0; dim < info->ndimensions; dim++) | |
11969 | { | |
11970 | dw_die_ref subrange_die | |
11971 | = new_die (DW_TAG_subrange_type, array_die, NULL); | |
11972 | ||
11973 | if (info->dimen[dim].lower_bound) | |
11974 | { | |
11975 | /* If it is the default value, omit it. */ | |
11976 | if ((is_c_family () || is_java ()) | |
11977 | && integer_zerop (info->dimen[dim].lower_bound)) | |
11978 | ; | |
11979 | else if (is_fortran () | |
11980 | && integer_onep (info->dimen[dim].lower_bound)) | |
11981 | ; | |
11982 | else | |
11983 | add_descr_info_field (subrange_die, DW_AT_lower_bound, | |
11984 | info->dimen[dim].lower_bound, | |
11985 | info->base_decl); | |
11986 | } | |
11987 | if (info->dimen[dim].upper_bound) | |
11988 | add_descr_info_field (subrange_die, DW_AT_upper_bound, | |
11989 | info->dimen[dim].upper_bound, | |
11990 | info->base_decl); | |
11991 | if (info->dimen[dim].stride) | |
11992 | add_descr_info_field (subrange_die, DW_AT_byte_stride, | |
11993 | info->dimen[dim].stride, | |
11994 | info->base_decl); | |
11995 | } | |
11996 | ||
11997 | gen_type_die (info->element_type, context_die); | |
11998 | add_type_attribute (array_die, info->element_type, 0, 0, context_die); | |
11999 | ||
12000 | if (get_AT (array_die, DW_AT_name)) | |
12001 | add_pubtype (type, array_die); | |
12002 | } | |
12003 | ||
d6f4ec51 | 12004 | #if 0 |
a3f97cbb | 12005 | static void |
7080f735 | 12006 | gen_entry_point_die (tree decl, dw_die_ref context_die) |
a3f97cbb | 12007 | { |
b3694847 | 12008 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 12009 | dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl); |
2ad9852d | 12010 | |
a3f97cbb | 12011 | if (origin != NULL) |
71dfc51f | 12012 | add_abstract_origin_attribute (decl_die, origin); |
a3f97cbb JW |
12013 | else |
12014 | { | |
12015 | add_name_and_src_coords_attributes (decl_die, decl); | |
a3f97cbb JW |
12016 | add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)), |
12017 | 0, 0, context_die); | |
12018 | } | |
71dfc51f | 12019 | |
a3f97cbb | 12020 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 12021 | equate_decl_number_to_die (decl, decl_die); |
a3f97cbb | 12022 | else |
71dfc51f | 12023 | add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl)); |
a3f97cbb | 12024 | } |
d6f4ec51 | 12025 | #endif |
a3f97cbb | 12026 | |
8a8c3656 JM |
12027 | /* Walk through the list of incomplete types again, trying once more to |
12028 | emit full debugging info for them. */ | |
12029 | ||
12030 | static void | |
7080f735 | 12031 | retry_incomplete_types (void) |
8a8c3656 | 12032 | { |
244a4af0 | 12033 | int i; |
2ad9852d | 12034 | |
887fb69b KH |
12035 | for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--) |
12036 | gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die); | |
8a8c3656 JM |
12037 | } |
12038 | ||
a3f97cbb | 12039 | /* Generate a DIE to represent an inlined instance of an enumeration type. */ |
71dfc51f | 12040 | |
a3f97cbb | 12041 | static void |
7080f735 | 12042 | gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 12043 | { |
54ba1f0d | 12044 | dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type); |
2ad9852d | 12045 | |
bbc6ae08 NC |
12046 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
12047 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
12048 | add_abstract_origin_attribute (type_die, type); |
12049 | } | |
12050 | ||
394d9fe7 AO |
12051 | /* Determine what tag to use for a record type. */ |
12052 | ||
12053 | static enum dwarf_tag | |
12054 | record_type_tag (tree type) | |
12055 | { | |
12056 | if (! lang_hooks.types.classify_record) | |
12057 | return DW_TAG_structure_type; | |
12058 | ||
12059 | switch (lang_hooks.types.classify_record (type)) | |
12060 | { | |
12061 | case RECORD_IS_STRUCT: | |
12062 | return DW_TAG_structure_type; | |
12063 | ||
12064 | case RECORD_IS_CLASS: | |
12065 | return DW_TAG_class_type; | |
12066 | ||
12067 | case RECORD_IS_INTERFACE: | |
12068 | return DW_TAG_interface_type; | |
12069 | ||
12070 | default: | |
12071 | gcc_unreachable (); | |
12072 | } | |
12073 | } | |
12074 | ||
a3f97cbb | 12075 | /* Generate a DIE to represent an inlined instance of a structure type. */ |
71dfc51f | 12076 | |
a3f97cbb | 12077 | static void |
7080f735 | 12078 | gen_inlined_structure_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 12079 | { |
394d9fe7 | 12080 | dw_die_ref type_die = new_die (record_type_tag (type), context_die, type); |
777ad4c2 | 12081 | |
bbc6ae08 NC |
12082 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
12083 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
12084 | add_abstract_origin_attribute (type_die, type); |
12085 | } | |
12086 | ||
12087 | /* Generate a DIE to represent an inlined instance of a union type. */ | |
71dfc51f | 12088 | |
a3f97cbb | 12089 | static void |
7080f735 | 12090 | gen_inlined_union_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 12091 | { |
54ba1f0d | 12092 | dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type); |
777ad4c2 | 12093 | |
bbc6ae08 NC |
12094 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
12095 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
12096 | add_abstract_origin_attribute (type_die, type); |
12097 | } | |
12098 | ||
12099 | /* Generate a DIE to represent an enumeration type. Note that these DIEs | |
12100 | include all of the information about the enumeration values also. Each | |
273dbe67 JM |
12101 | enumerated type name/value is listed as a child of the enumerated type |
12102 | DIE. */ | |
71dfc51f | 12103 | |
de99511b | 12104 | static dw_die_ref |
7080f735 | 12105 | gen_enumeration_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 12106 | { |
b3694847 | 12107 | dw_die_ref type_die = lookup_type_die (type); |
273dbe67 | 12108 | |
a3f97cbb JW |
12109 | if (type_die == NULL) |
12110 | { | |
12111 | type_die = new_die (DW_TAG_enumeration_type, | |
54ba1f0d | 12112 | scope_die_for (type, context_die), type); |
a3f97cbb JW |
12113 | equate_type_number_to_die (type, type_die); |
12114 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 12115 | } |
273dbe67 | 12116 | else if (! TYPE_SIZE (type)) |
de99511b | 12117 | return type_die; |
273dbe67 JM |
12118 | else |
12119 | remove_AT (type_die, DW_AT_declaration); | |
12120 | ||
12121 | /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the | |
12122 | given enum type is incomplete, do not generate the DW_AT_byte_size | |
12123 | attribute or the DW_AT_element_list attribute. */ | |
12124 | if (TYPE_SIZE (type)) | |
a3f97cbb | 12125 | { |
b3694847 | 12126 | tree link; |
71dfc51f | 12127 | |
a082c85a | 12128 | TREE_ASM_WRITTEN (type) = 1; |
273dbe67 | 12129 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 12130 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 12131 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 12132 | |
ef76d03b JW |
12133 | /* If the first reference to this type was as the return type of an |
12134 | inline function, then it may not have a parent. Fix this now. */ | |
12135 | if (type_die->die_parent == NULL) | |
12136 | add_child_die (scope_die_for (type, context_die), type_die); | |
12137 | ||
eb34af89 | 12138 | for (link = TYPE_VALUES (type); |
273dbe67 | 12139 | link != NULL; link = TREE_CHAIN (link)) |
a3f97cbb | 12140 | { |
54ba1f0d | 12141 | dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link); |
5bb2ed2c | 12142 | tree value = TREE_VALUE (link); |
71dfc51f | 12143 | |
273dbe67 JM |
12144 | add_name_attribute (enum_die, |
12145 | IDENTIFIER_POINTER (TREE_PURPOSE (link))); | |
665f2503 | 12146 | |
8df83eae | 12147 | if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value)))) |
5bb2ed2c MM |
12148 | /* DWARF2 does not provide a way of indicating whether or |
12149 | not enumeration constants are signed or unsigned. GDB | |
12150 | always assumes the values are signed, so we output all | |
12151 | values as if they were signed. That means that | |
12152 | enumeration constants with very large unsigned values | |
12153 | will appear to have negative values in the debugger. */ | |
12154 | add_AT_int (enum_die, DW_AT_const_value, | |
12155 | tree_low_cst (value, tree_int_cst_sgn (value) > 0)); | |
a3f97cbb JW |
12156 | } |
12157 | } | |
273dbe67 JM |
12158 | else |
12159 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
de99511b | 12160 | |
89708594 CT |
12161 | if (get_AT (type_die, DW_AT_name)) |
12162 | add_pubtype (type, type_die); | |
12163 | ||
de99511b | 12164 | return type_die; |
a3f97cbb JW |
12165 | } |
12166 | ||
a3f97cbb JW |
12167 | /* Generate a DIE to represent either a real live formal parameter decl or to |
12168 | represent just the type of some formal parameter position in some function | |
12169 | type. | |
71dfc51f | 12170 | |
a3f97cbb JW |
12171 | Note that this routine is a bit unusual because its argument may be a |
12172 | ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which | |
12173 | represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE | |
12174 | node. If it's the former then this function is being called to output a | |
12175 | DIE to represent a formal parameter object (or some inlining thereof). If | |
12176 | it's the latter, then this function is only being called to output a | |
12177 | DW_TAG_formal_parameter DIE to stand as a placeholder for some formal | |
12178 | argument type of some subprogram type. */ | |
71dfc51f | 12179 | |
a94dbf2c | 12180 | static dw_die_ref |
7080f735 | 12181 | gen_formal_parameter_die (tree node, dw_die_ref context_die) |
a3f97cbb | 12182 | { |
b3694847 | 12183 | dw_die_ref parm_die |
54ba1f0d | 12184 | = new_die (DW_TAG_formal_parameter, context_die, node); |
b3694847 | 12185 | tree origin; |
71dfc51f | 12186 | |
a3f97cbb JW |
12187 | switch (TREE_CODE_CLASS (TREE_CODE (node))) |
12188 | { | |
6615c446 | 12189 | case tcc_declaration: |
a3f97cbb JW |
12190 | origin = decl_ultimate_origin (node); |
12191 | if (origin != NULL) | |
a94dbf2c | 12192 | add_abstract_origin_attribute (parm_die, origin); |
a3f97cbb JW |
12193 | else |
12194 | { | |
611cd333 | 12195 | tree type = TREE_TYPE (node); |
a3f97cbb | 12196 | add_name_and_src_coords_attributes (parm_die, node); |
611cd333 JJ |
12197 | if (DECL_BY_REFERENCE (node)) |
12198 | type = TREE_TYPE (type); | |
12199 | add_type_attribute (parm_die, type, | |
a3f97cbb JW |
12200 | TREE_READONLY (node), |
12201 | TREE_THIS_VOLATILE (node), | |
12202 | context_die); | |
bdb669cb JM |
12203 | if (DECL_ARTIFICIAL (node)) |
12204 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb | 12205 | } |
71dfc51f | 12206 | |
141719a8 JM |
12207 | equate_decl_number_to_die (node, parm_die); |
12208 | if (! DECL_ABSTRACT (node)) | |
0a2d3d69 | 12209 | add_location_or_const_value_attribute (parm_die, node, DW_AT_location); |
71dfc51f | 12210 | |
a3f97cbb JW |
12211 | break; |
12212 | ||
6615c446 | 12213 | case tcc_type: |
71dfc51f | 12214 | /* We were called with some kind of a ..._TYPE node. */ |
a3f97cbb JW |
12215 | add_type_attribute (parm_die, node, 0, 0, context_die); |
12216 | break; | |
12217 | ||
a3f97cbb | 12218 | default: |
ced3f397 | 12219 | gcc_unreachable (); |
a3f97cbb | 12220 | } |
71dfc51f | 12221 | |
a94dbf2c | 12222 | return parm_die; |
a3f97cbb JW |
12223 | } |
12224 | ||
12225 | /* Generate a special type of DIE used as a stand-in for a trailing ellipsis | |
12226 | at the end of an (ANSI prototyped) formal parameters list. */ | |
71dfc51f | 12227 | |
a3f97cbb | 12228 | static void |
7080f735 | 12229 | gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die) |
a3f97cbb | 12230 | { |
54ba1f0d | 12231 | new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type); |
a3f97cbb JW |
12232 | } |
12233 | ||
12234 | /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a | |
12235 | DW_TAG_unspecified_parameters DIE) to represent the types of the formal | |
12236 | parameters as specified in some function type specification (except for | |
1cfdcc15 | 12237 | those which appear as part of a function *definition*). */ |
71dfc51f | 12238 | |
a3f97cbb | 12239 | static void |
7080f735 | 12240 | gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die) |
a3f97cbb | 12241 | { |
b3694847 SS |
12242 | tree link; |
12243 | tree formal_type = NULL; | |
12244 | tree first_parm_type; | |
5daf7c0a | 12245 | tree arg; |
a3f97cbb | 12246 | |
5daf7c0a JM |
12247 | if (TREE_CODE (function_or_method_type) == FUNCTION_DECL) |
12248 | { | |
12249 | arg = DECL_ARGUMENTS (function_or_method_type); | |
12250 | function_or_method_type = TREE_TYPE (function_or_method_type); | |
12251 | } | |
12252 | else | |
12253 | arg = NULL_TREE; | |
c26fbbca | 12254 | |
5daf7c0a | 12255 | first_parm_type = TYPE_ARG_TYPES (function_or_method_type); |
a3f97cbb | 12256 | |
556273e0 | 12257 | /* Make our first pass over the list of formal parameter types and output a |
a3f97cbb | 12258 | DW_TAG_formal_parameter DIE for each one. */ |
5daf7c0a | 12259 | for (link = first_parm_type; link; ) |
a3f97cbb | 12260 | { |
b3694847 | 12261 | dw_die_ref parm_die; |
556273e0 | 12262 | |
a3f97cbb JW |
12263 | formal_type = TREE_VALUE (link); |
12264 | if (formal_type == void_type_node) | |
12265 | break; | |
12266 | ||
12267 | /* Output a (nameless) DIE to represent the formal parameter itself. */ | |
a94dbf2c | 12268 | parm_die = gen_formal_parameter_die (formal_type, context_die); |
5daf7c0a JM |
12269 | if ((TREE_CODE (function_or_method_type) == METHOD_TYPE |
12270 | && link == first_parm_type) | |
12271 | || (arg && DECL_ARTIFICIAL (arg))) | |
a94dbf2c | 12272 | add_AT_flag (parm_die, DW_AT_artificial, 1); |
5daf7c0a JM |
12273 | |
12274 | link = TREE_CHAIN (link); | |
12275 | if (arg) | |
12276 | arg = TREE_CHAIN (arg); | |
a3f97cbb JW |
12277 | } |
12278 | ||
12279 | /* If this function type has an ellipsis, add a | |
12280 | DW_TAG_unspecified_parameters DIE to the end of the parameter list. */ | |
12281 | if (formal_type != void_type_node) | |
12282 | gen_unspecified_parameters_die (function_or_method_type, context_die); | |
12283 | ||
556273e0 | 12284 | /* Make our second (and final) pass over the list of formal parameter types |
a3f97cbb JW |
12285 | and output DIEs to represent those types (as necessary). */ |
12286 | for (link = TYPE_ARG_TYPES (function_or_method_type); | |
2ad9852d | 12287 | link && TREE_VALUE (link); |
a3f97cbb | 12288 | link = TREE_CHAIN (link)) |
2ad9852d | 12289 | gen_type_die (TREE_VALUE (link), context_die); |
a3f97cbb JW |
12290 | } |
12291 | ||
10a11b75 JM |
12292 | /* We want to generate the DIE for TYPE so that we can generate the |
12293 | die for MEMBER, which has been defined; we will need to refer back | |
12294 | to the member declaration nested within TYPE. If we're trying to | |
12295 | generate minimal debug info for TYPE, processing TYPE won't do the | |
12296 | trick; we need to attach the member declaration by hand. */ | |
12297 | ||
12298 | static void | |
7080f735 | 12299 | gen_type_die_for_member (tree type, tree member, dw_die_ref context_die) |
10a11b75 JM |
12300 | { |
12301 | gen_type_die (type, context_die); | |
12302 | ||
12303 | /* If we're trying to avoid duplicate debug info, we may not have | |
12304 | emitted the member decl for this function. Emit it now. */ | |
12305 | if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)) | |
12306 | && ! lookup_decl_die (member)) | |
12307 | { | |
a288c5cd | 12308 | dw_die_ref type_die; |
ced3f397 | 12309 | gcc_assert (!decl_ultimate_origin (member)); |
10a11b75 JM |
12310 | |
12311 | push_decl_scope (type); | |
a288c5cd | 12312 | type_die = lookup_type_die (type); |
10a11b75 | 12313 | if (TREE_CODE (member) == FUNCTION_DECL) |
a288c5cd JJ |
12314 | gen_subprogram_die (member, type_die); |
12315 | else if (TREE_CODE (member) == FIELD_DECL) | |
12316 | { | |
12317 | /* Ignore the nameless fields that are used to skip bits but handle | |
12318 | C++ anonymous unions and structs. */ | |
12319 | if (DECL_NAME (member) != NULL_TREE | |
12320 | || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE | |
12321 | || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE) | |
12322 | { | |
12323 | gen_type_die (member_declared_type (member), type_die); | |
12324 | gen_field_die (member, type_die); | |
12325 | } | |
12326 | } | |
10a11b75 | 12327 | else |
a288c5cd | 12328 | gen_variable_die (member, type_die); |
2ad9852d | 12329 | |
10a11b75 JM |
12330 | pop_decl_scope (); |
12331 | } | |
12332 | } | |
12333 | ||
2ad9852d RK |
12334 | /* Generate the DWARF2 info for the "abstract" instance of a function which we |
12335 | may later generate inlined and/or out-of-line instances of. */ | |
10a11b75 | 12336 | |
e1772ac0 | 12337 | static void |
7080f735 | 12338 | dwarf2out_abstract_function (tree decl) |
10a11b75 | 12339 | { |
b3694847 | 12340 | dw_die_ref old_die; |
777ad4c2 | 12341 | tree save_fn; |
5daf7c0a JM |
12342 | tree context; |
12343 | int was_abstract = DECL_ABSTRACT (decl); | |
12344 | ||
12345 | /* Make sure we have the actual abstract inline, not a clone. */ | |
12346 | decl = DECL_ORIGIN (decl); | |
10a11b75 | 12347 | |
c26fbbca | 12348 | old_die = lookup_decl_die (decl); |
ae0f3477 | 12349 | if (old_die && get_AT (old_die, DW_AT_inline)) |
10a11b75 JM |
12350 | /* We've already generated the abstract instance. */ |
12351 | return; | |
12352 | ||
5daf7c0a JM |
12353 | /* Be sure we've emitted the in-class declaration DIE (if any) first, so |
12354 | we don't get confused by DECL_ABSTRACT. */ | |
8458e954 JS |
12355 | if (debug_info_level > DINFO_LEVEL_TERSE) |
12356 | { | |
12357 | context = decl_class_context (decl); | |
12358 | if (context) | |
12359 | gen_type_die_for_member | |
12360 | (context, decl, decl_function_context (decl) ? NULL : comp_unit_die); | |
12361 | } | |
c26fbbca | 12362 | |
5daf7c0a | 12363 | /* Pretend we've just finished compiling this function. */ |
777ad4c2 JM |
12364 | save_fn = current_function_decl; |
12365 | current_function_decl = decl; | |
db2960f4 | 12366 | push_cfun (DECL_STRUCT_FUNCTION (decl)); |
777ad4c2 | 12367 | |
10a11b75 JM |
12368 | set_decl_abstract_flags (decl, 1); |
12369 | dwarf2out_decl (decl); | |
5daf7c0a JM |
12370 | if (! was_abstract) |
12371 | set_decl_abstract_flags (decl, 0); | |
777ad4c2 JM |
12372 | |
12373 | current_function_decl = save_fn; | |
db2960f4 | 12374 | pop_cfun (); |
10a11b75 JM |
12375 | } |
12376 | ||
33c9159e AH |
12377 | /* Helper function of premark_used_types() which gets called through |
12378 | htab_traverse_resize(). | |
12379 | ||
12380 | Marks the DIE of a given type in *SLOT as perennial, so it never gets | |
12381 | marked as unused by prune_unused_types. */ | |
12382 | static int | |
12383 | premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED) | |
12384 | { | |
12385 | tree type; | |
12386 | dw_die_ref die; | |
12387 | ||
1b4572a8 | 12388 | type = (tree) *slot; |
33c9159e AH |
12389 | die = lookup_type_die (type); |
12390 | if (die != NULL) | |
12391 | die->die_perennial_p = 1; | |
12392 | return 1; | |
12393 | } | |
12394 | ||
12395 | /* Mark all members of used_types_hash as perennial. */ | |
12396 | static void | |
12397 | premark_used_types (void) | |
12398 | { | |
12399 | if (cfun && cfun->used_types_hash) | |
12400 | htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL); | |
12401 | } | |
12402 | ||
a3f97cbb JW |
12403 | /* Generate a DIE to represent a declared function (either file-scope or |
12404 | block-local). */ | |
71dfc51f | 12405 | |
a3f97cbb | 12406 | static void |
7080f735 | 12407 | gen_subprogram_die (tree decl, dw_die_ref context_die) |
a3f97cbb JW |
12408 | { |
12409 | char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 SS |
12410 | tree origin = decl_ultimate_origin (decl); |
12411 | dw_die_ref subr_die; | |
b3694847 SS |
12412 | tree fn_arg_types; |
12413 | tree outer_scope; | |
12414 | dw_die_ref old_die = lookup_decl_die (decl); | |
12415 | int declaration = (current_function_decl != decl | |
66c78aa9 | 12416 | || class_or_namespace_scope_p (context_die)); |
a3f97cbb | 12417 | |
6193b8b7 | 12418 | premark_used_types (); |
33c9159e | 12419 | |
2ad9852d RK |
12420 | /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we |
12421 | started to generate the abstract instance of an inline, decided to output | |
12422 | its containing class, and proceeded to emit the declaration of the inline | |
12423 | from the member list for the class. If so, DECLARATION takes priority; | |
12424 | we'll get back to the abstract instance when done with the class. */ | |
10a11b75 | 12425 | |
1cfdcc15 | 12426 | /* The class-scope declaration DIE must be the primary DIE. */ |
66c78aa9 | 12427 | if (origin && declaration && class_or_namespace_scope_p (context_die)) |
1cfdcc15 JM |
12428 | { |
12429 | origin = NULL; | |
ced3f397 | 12430 | gcc_assert (!old_die); |
1cfdcc15 JM |
12431 | } |
12432 | ||
d3e4cd01 JM |
12433 | /* Now that the C++ front end lazily declares artificial member fns, we |
12434 | might need to retrofit the declaration into its class. */ | |
12435 | if (!declaration && !origin && !old_die | |
12436 | && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)) | |
12437 | && !class_or_namespace_scope_p (context_die) | |
12438 | && debug_info_level > DINFO_LEVEL_TERSE) | |
12439 | old_die = force_decl_die (decl); | |
12440 | ||
a3f97cbb JW |
12441 | if (origin != NULL) |
12442 | { | |
ced3f397 | 12443 | gcc_assert (!declaration || local_scope_p (context_die)); |
10a11b75 | 12444 | |
8d8238b6 JM |
12445 | /* Fixup die_parent for the abstract instance of a nested |
12446 | inline function. */ | |
12447 | if (old_die && old_die->die_parent == NULL) | |
12448 | add_child_die (context_die, old_die); | |
12449 | ||
54ba1f0d | 12450 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
a3f97cbb JW |
12451 | add_abstract_origin_attribute (subr_die, origin); |
12452 | } | |
bdb669cb JM |
12453 | else if (old_die) |
12454 | { | |
6773e15f | 12455 | expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl)); |
d5688810 | 12456 | struct dwarf_file_data * file_index = lookup_filename (s.file); |
a94dbf2c | 12457 | |
1edf43d6 JM |
12458 | if (!get_AT_flag (old_die, DW_AT_declaration) |
12459 | /* We can have a normal definition following an inline one in the | |
12460 | case of redefinition of GNU C extern inlines. | |
12461 | It seems reasonable to use AT_specification in this case. */ | |
ae0f3477 | 12462 | && !get_AT (old_die, DW_AT_inline)) |
b75ab88b | 12463 | { |
9acf766f DB |
12464 | /* Detect and ignore this case, where we are trying to output |
12465 | something we have already output. */ | |
ced3f397 | 12466 | return; |
b75ab88b | 12467 | } |
4b674448 JM |
12468 | |
12469 | /* If the definition comes from the same place as the declaration, | |
a94dbf2c JM |
12470 | maybe use the old DIE. We always want the DIE for this function |
12471 | that has the *_pc attributes to be under comp_unit_die so the | |
cb9e9d8d JM |
12472 | debugger can find it. We also need to do this for abstract |
12473 | instances of inlines, since the spec requires the out-of-line copy | |
12474 | to have the same parent. For local class methods, this doesn't | |
12475 | apply; we just use the old DIE. */ | |
12476 | if ((old_die->die_parent == comp_unit_die || context_die == NULL) | |
a96c67ec | 12477 | && (DECL_ARTIFICIAL (decl) |
d5688810 | 12478 | || (get_AT_file (old_die, DW_AT_decl_file) == file_index |
a96c67ec | 12479 | && (get_AT_unsigned (old_die, DW_AT_decl_line) |
6773e15f | 12480 | == (unsigned) s.line)))) |
bdb669cb | 12481 | { |
4b674448 JM |
12482 | subr_die = old_die; |
12483 | ||
6097b0c3 | 12484 | /* Clear out the declaration attribute and the formal parameters. |
a1c496cb | 12485 | Do not remove all children, because it is possible that this |
6097b0c3 DP |
12486 | declaration die was forced using force_decl_die(). In such |
12487 | cases die that forced declaration die (e.g. TAG_imported_module) | |
12488 | is one of the children that we do not want to remove. */ | |
4b674448 | 12489 | remove_AT (subr_die, DW_AT_declaration); |
6097b0c3 | 12490 | remove_child_TAG (subr_die, DW_TAG_formal_parameter); |
4b674448 JM |
12491 | } |
12492 | else | |
12493 | { | |
54ba1f0d | 12494 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
47fcfa7b | 12495 | add_AT_specification (subr_die, old_die); |
d5688810 GK |
12496 | if (get_AT_file (old_die, DW_AT_decl_file) != file_index) |
12497 | add_AT_file (subr_die, DW_AT_decl_file, file_index); | |
12498 | if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line) | |
12499 | add_AT_unsigned (subr_die, DW_AT_decl_line, s.line); | |
bdb669cb JM |
12500 | } |
12501 | } | |
a3f97cbb JW |
12502 | else |
12503 | { | |
54ba1f0d | 12504 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
556273e0 | 12505 | |
273dbe67 JM |
12506 | if (TREE_PUBLIC (decl)) |
12507 | add_AT_flag (subr_die, DW_AT_external, 1); | |
71dfc51f | 12508 | |
a3f97cbb | 12509 | add_name_and_src_coords_attributes (subr_die, decl); |
4927276d JM |
12510 | if (debug_info_level > DINFO_LEVEL_TERSE) |
12511 | { | |
2ad9852d RK |
12512 | add_prototyped_attribute (subr_die, TREE_TYPE (decl)); |
12513 | add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)), | |
12514 | 0, 0, context_die); | |
4927276d | 12515 | } |
71dfc51f | 12516 | |
a3f97cbb | 12517 | add_pure_or_virtual_attribute (subr_die, decl); |
273dbe67 JM |
12518 | if (DECL_ARTIFICIAL (decl)) |
12519 | add_AT_flag (subr_die, DW_AT_artificial, 1); | |
2ad9852d | 12520 | |
a94dbf2c JM |
12521 | if (TREE_PROTECTED (decl)) |
12522 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected); | |
12523 | else if (TREE_PRIVATE (decl)) | |
12524 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 12525 | } |
4edb7b60 | 12526 | |
a94dbf2c JM |
12527 | if (declaration) |
12528 | { | |
ae0f3477 | 12529 | if (!old_die || !get_AT (old_die, DW_AT_inline)) |
1edf43d6 JM |
12530 | { |
12531 | add_AT_flag (subr_die, DW_AT_declaration, 1); | |
12532 | ||
12533 | /* The first time we see a member function, it is in the context of | |
12534 | the class to which it belongs. We make sure of this by emitting | |
12535 | the class first. The next time is the definition, which is | |
a1c496cb | 12536 | handled above. The two may come from the same source text. |
6097b0c3 DP |
12537 | |
12538 | Note that force_decl_die() forces function declaration die. It is | |
12539 | later reused to represent definition. */ | |
d3e4cd01 | 12540 | equate_decl_number_to_die (decl, subr_die); |
1edf43d6 | 12541 | } |
a94dbf2c JM |
12542 | } |
12543 | else if (DECL_ABSTRACT (decl)) | |
a3f97cbb | 12544 | { |
1bb17c21 | 12545 | if (DECL_DECLARED_INLINE_P (decl)) |
61b32c02 | 12546 | { |
2878ea73 | 12547 | if (cgraph_function_possibly_inlined_p (decl)) |
61b32c02 JM |
12548 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined); |
12549 | else | |
1bb17c21 | 12550 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined); |
61b32c02 | 12551 | } |
61b32c02 | 12552 | else |
1bb17c21 JH |
12553 | { |
12554 | if (cgraph_function_possibly_inlined_p (decl)) | |
2878ea73 | 12555 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined); |
1bb17c21 | 12556 | else |
2878ea73 | 12557 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined); |
1bb17c21 | 12558 | } |
61b32c02 | 12559 | |
d752cfdb JJ |
12560 | if (DECL_DECLARED_INLINE_P (decl) |
12561 | && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl))) | |
12562 | add_AT_flag (subr_die, DW_AT_artificial, 1); | |
12563 | ||
a3f97cbb JW |
12564 | equate_decl_number_to_die (decl, subr_die); |
12565 | } | |
12566 | else if (!DECL_EXTERNAL (decl)) | |
12567 | { | |
35d177a2 AO |
12568 | HOST_WIDE_INT cfa_fb_offset; |
12569 | ||
ae0f3477 | 12570 | if (!old_die || !get_AT (old_die, DW_AT_inline)) |
ba7b35df | 12571 | equate_decl_number_to_die (decl, subr_die); |
71dfc51f | 12572 | |
87c8b4be CT |
12573 | if (!flag_reorder_blocks_and_partition) |
12574 | { | |
12575 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL, | |
12576 | current_function_funcdef_no); | |
12577 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id); | |
12578 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, | |
12579 | current_function_funcdef_no); | |
12580 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id); | |
2878ea73 | 12581 | |
87c8b4be CT |
12582 | add_pubname (decl, subr_die); |
12583 | add_arange (decl, subr_die); | |
12584 | } | |
12585 | else | |
12586 | { /* Do nothing for now; maybe need to duplicate die, one for | |
fa10beec | 12587 | hot section and one for cold section, then use the hot/cold |
87c8b4be CT |
12588 | section begin/end labels to generate the aranges... */ |
12589 | /* | |
12590 | add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label); | |
12591 | add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label); | |
12592 | add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label); | |
12593 | add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label); | |
12594 | ||
12595 | add_pubname (decl, subr_die); | |
12596 | add_arange (decl, subr_die); | |
12597 | add_arange (decl, subr_die); | |
12598 | */ | |
12599 | } | |
d291dd49 | 12600 | |
a3f97cbb | 12601 | #ifdef MIPS_DEBUGGING_INFO |
a3f97cbb JW |
12602 | /* Add a reference to the FDE for this routine. */ |
12603 | add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde); | |
12604 | #endif | |
12605 | ||
35d177a2 AO |
12606 | cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl); |
12607 | ||
30e6f306 RH |
12608 | /* We define the "frame base" as the function's CFA. This is more |
12609 | convenient for several reasons: (1) It's stable across the prologue | |
12610 | and epilogue, which makes it better than just a frame pointer, | |
12611 | (2) With dwarf3, there exists a one-byte encoding that allows us | |
12612 | to reference the .debug_frame data by proxy, but failing that, | |
12613 | (3) We can at least reuse the code inspection and interpretation | |
12614 | code that determines the CFA position at various points in the | |
12615 | function. */ | |
12616 | /* ??? Use some command-line or configury switch to enable the use | |
12617 | of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf | |
12618 | consumers that understand it; fall back to "pure" dwarf2 and | |
12619 | convert the CFA data into a location list. */ | |
12620 | { | |
35d177a2 | 12621 | dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset); |
30e6f306 RH |
12622 | if (list->dw_loc_next) |
12623 | add_AT_loc_list (subr_die, DW_AT_frame_base, list); | |
12624 | else | |
12625 | add_AT_loc (subr_die, DW_AT_frame_base, list->expr); | |
12626 | } | |
12627 | ||
12628 | /* Compute a displacement from the "steady-state frame pointer" to | |
12629 | the CFA. The former is what all stack slots and argument slots | |
2878ea73 | 12630 | will reference in the rtl; the later is what we've told the |
30e6f306 RH |
12631 | debugger about. We'll need to adjust all frame_base references |
12632 | by this displacement. */ | |
35d177a2 | 12633 | compute_frame_pointer_to_fb_displacement (cfa_fb_offset); |
a3f97cbb | 12634 | |
6de9cd9a | 12635 | if (cfun->static_chain_decl) |
ef76d03b | 12636 | add_AT_location_description (subr_die, DW_AT_static_link, |
1a186ec5 | 12637 | loc_descriptor_from_tree (cfun->static_chain_decl)); |
a3f97cbb JW |
12638 | } |
12639 | ||
12640 | /* Now output descriptions of the arguments for this function. This gets | |
556273e0 | 12641 | (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list |
a3f97cbb JW |
12642 | for a FUNCTION_DECL doesn't indicate cases where there was a trailing |
12643 | `...' at the end of the formal parameter list. In order to find out if | |
12644 | there was a trailing ellipsis or not, we must instead look at the type | |
12645 | associated with the FUNCTION_DECL. This will be a node of type | |
12646 | FUNCTION_TYPE. If the chain of type nodes hanging off of this | |
556273e0 | 12647 | FUNCTION_TYPE node ends with a void_type_node then there should *not* be |
a3f97cbb | 12648 | an ellipsis at the end. */ |
71dfc51f | 12649 | |
a3f97cbb | 12650 | /* In the case where we are describing a mere function declaration, all we |
556273e0 | 12651 | need to do here (and all we *can* do here) is to describe the *types* of |
a3f97cbb | 12652 | its formal parameters. */ |
4927276d | 12653 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 12654 | ; |
4edb7b60 | 12655 | else if (declaration) |
5daf7c0a | 12656 | gen_formal_types_die (decl, subr_die); |
a3f97cbb JW |
12657 | else |
12658 | { | |
f9da5064 | 12659 | /* Generate DIEs to represent all known formal parameters. */ |
b3694847 SS |
12660 | tree arg_decls = DECL_ARGUMENTS (decl); |
12661 | tree parm; | |
a3f97cbb JW |
12662 | |
12663 | /* When generating DIEs, generate the unspecified_parameters DIE | |
73c68f61 | 12664 | instead if we come across the arg "__builtin_va_alist" */ |
a3f97cbb | 12665 | for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) |
71dfc51f RK |
12666 | if (TREE_CODE (parm) == PARM_DECL) |
12667 | { | |
db3cf6fb MS |
12668 | if (DECL_NAME (parm) |
12669 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), | |
12670 | "__builtin_va_alist")) | |
71dfc51f RK |
12671 | gen_unspecified_parameters_die (parm, subr_die); |
12672 | else | |
12673 | gen_decl_die (parm, subr_die); | |
12674 | } | |
a3f97cbb | 12675 | |
4fe9b91c | 12676 | /* Decide whether we need an unspecified_parameters DIE at the end. |
73c68f61 SS |
12677 | There are 2 more cases to do this for: 1) the ansi ... declaration - |
12678 | this is detectable when the end of the arg list is not a | |
12679 | void_type_node 2) an unprototyped function declaration (not a | |
12680 | definition). This just means that we have no info about the | |
12681 | parameters at all. */ | |
a3f97cbb | 12682 | fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); |
71dfc51f | 12683 | if (fn_arg_types != NULL) |
a3f97cbb | 12684 | { |
beb235f8 | 12685 | /* This is the prototyped case, check for.... */ |
a3f97cbb | 12686 | if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) |
71dfc51f | 12687 | gen_unspecified_parameters_die (decl, subr_die); |
a3f97cbb | 12688 | } |
71dfc51f RK |
12689 | else if (DECL_INITIAL (decl) == NULL_TREE) |
12690 | gen_unspecified_parameters_die (decl, subr_die); | |
a3f97cbb JW |
12691 | } |
12692 | ||
12693 | /* Output Dwarf info for all of the stuff within the body of the function | |
12694 | (if it has one - it may be just a declaration). */ | |
12695 | outer_scope = DECL_INITIAL (decl); | |
12696 | ||
2ad9852d RK |
12697 | /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent |
12698 | a function. This BLOCK actually represents the outermost binding contour | |
12699 | for the function, i.e. the contour in which the function's formal | |
12700 | parameters and labels get declared. Curiously, it appears that the front | |
12701 | end doesn't actually put the PARM_DECL nodes for the current function onto | |
12702 | the BLOCK_VARS list for this outer scope, but are strung off of the | |
12703 | DECL_ARGUMENTS list for the function instead. | |
12704 | ||
12705 | The BLOCK_VARS list for the `outer_scope' does provide us with a list of | |
12706 | the LABEL_DECL nodes for the function however, and we output DWARF info | |
12707 | for those in decls_for_scope. Just within the `outer_scope' there will be | |
12708 | a BLOCK node representing the function's outermost pair of curly braces, | |
12709 | and any blocks used for the base and member initializers of a C++ | |
d7248bff | 12710 | constructor function. */ |
4edb7b60 | 12711 | if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK) |
7e23cb16 | 12712 | { |
6de9cd9a DN |
12713 | /* Emit a DW_TAG_variable DIE for a named return value. */ |
12714 | if (DECL_NAME (DECL_RESULT (decl))) | |
12715 | gen_decl_die (DECL_RESULT (decl), subr_die); | |
12716 | ||
7e23cb16 JM |
12717 | current_function_has_inlines = 0; |
12718 | decls_for_scope (outer_scope, subr_die, 0); | |
71dfc51f | 12719 | |
ce61cc73 | 12720 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
7e23cb16 JM |
12721 | if (current_function_has_inlines) |
12722 | { | |
12723 | add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1); | |
12724 | if (! comp_unit_has_inlines) | |
12725 | { | |
12726 | add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1); | |
12727 | comp_unit_has_inlines = 1; | |
12728 | } | |
12729 | } | |
12730 | #endif | |
12731 | } | |
5c70192c | 12732 | /* Add the calling convention attribute if requested. */ |
9adfa70e | 12733 | add_calling_convention_attribute (subr_die, decl); |
5c70192c | 12734 | |
a3f97cbb JW |
12735 | } |
12736 | ||
12737 | /* Generate a DIE to represent a declared data object. */ | |
71dfc51f | 12738 | |
a3f97cbb | 12739 | static void |
7080f735 | 12740 | gen_variable_die (tree decl, dw_die_ref context_die) |
a3f97cbb | 12741 | { |
7151ffbe | 12742 | HOST_WIDE_INT off; |
1f16b47c | 12743 | tree com_decl; |
7151ffbe | 12744 | dw_die_ref var_die; |
b3694847 | 12745 | tree origin = decl_ultimate_origin (decl); |
bdb669cb | 12746 | dw_die_ref old_die = lookup_decl_die (decl); |
9765e357 | 12747 | int declaration = (DECL_EXTERNAL (decl) |
2b402955 MM |
12748 | /* If DECL is COMDAT and has not actually been |
12749 | emitted, we cannot take its address; there | |
12750 | might end up being no definition anywhere in | |
12751 | the program. For example, consider the C++ | |
12752 | test case: | |
12753 | ||
2878ea73 MS |
12754 | template <class T> |
12755 | struct S { static const int i = 7; }; | |
2b402955 | 12756 | |
2878ea73 MS |
12757 | template <class T> |
12758 | const int S<T>::i; | |
12759 | ||
12760 | int f() { return S<int>::i; } | |
2b402955 | 12761 | |
2b402955 MM |
12762 | Here, S<int>::i is not DECL_EXTERNAL, but no |
12763 | definition is required, so the compiler will | |
2878ea73 | 12764 | not emit a definition. */ |
2b402955 MM |
12765 | || (TREE_CODE (decl) == VAR_DECL |
12766 | && DECL_COMDAT (decl) && !TREE_ASM_WRITTEN (decl)) | |
66c78aa9 | 12767 | || class_or_namespace_scope_p (context_die)); |
4edb7b60 | 12768 | |
1f16b47c | 12769 | com_decl = fortran_common (decl, &off); |
7151ffbe GH |
12770 | |
12771 | /* Symbol in common gets emitted as a child of the common block, in the form | |
12772 | of a data member. | |
12773 | ||
12774 | ??? This creates a new common block die for every common block symbol. | |
12775 | Better to share same common block die for all symbols in that block. */ | |
1f16b47c | 12776 | if (com_decl) |
7151ffbe | 12777 | { |
1f16b47c | 12778 | tree field; |
7151ffbe | 12779 | dw_die_ref com_die; |
1f16b47c JJ |
12780 | const char *cnam = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl)); |
12781 | dw_loc_descr_ref loc = loc_descriptor_from_tree (com_decl); | |
7151ffbe | 12782 | |
1f16b47c | 12783 | field = TREE_OPERAND (DECL_VALUE_EXPR (decl), 0); |
7151ffbe | 12784 | var_die = new_die (DW_TAG_common_block, context_die, decl); |
1f16b47c | 12785 | add_name_and_src_coords_attributes (var_die, field); |
7151ffbe GH |
12786 | add_AT_flag (var_die, DW_AT_external, 1); |
12787 | add_AT_loc (var_die, DW_AT_location, loc); | |
12788 | com_die = new_die (DW_TAG_member, var_die, decl); | |
12789 | add_name_and_src_coords_attributes (com_die, decl); | |
12790 | add_type_attribute (com_die, TREE_TYPE (decl), TREE_READONLY (decl), | |
1f16b47c JJ |
12791 | TREE_THIS_VOLATILE (decl), context_die); |
12792 | add_AT_loc (com_die, DW_AT_data_member_location, | |
12793 | int_loc_descriptor (off)); | |
7151ffbe GH |
12794 | add_pubname_string (cnam, var_die); /* ??? needed? */ |
12795 | return; | |
12796 | } | |
12797 | ||
12798 | var_die = new_die (DW_TAG_variable, context_die, decl); | |
12799 | ||
a3f97cbb | 12800 | if (origin != NULL) |
71dfc51f | 12801 | add_abstract_origin_attribute (var_die, origin); |
2ad9852d | 12802 | |
f76b8156 | 12803 | /* Loop unrolling can create multiple blocks that refer to the same |
2ad9852d RK |
12804 | static variable, so we must test for the DW_AT_declaration flag. |
12805 | ||
12806 | ??? Loop unrolling/reorder_blocks should perhaps be rewritten to | |
f76b8156 | 12807 | copy decls and set the DECL_ABSTRACT flag on them instead of |
2ad9852d RK |
12808 | sharing them. |
12809 | ||
4424eb91 JW |
12810 | ??? Duplicated blocks have been rewritten to use .debug_ranges. |
12811 | ||
12812 | ??? The declare_in_namespace support causes us to get two DIEs for one | |
12813 | variable, both of which are declarations. We want to avoid considering | |
12814 | one to be a specification, so we must test that this DIE is not a | |
12815 | declaration. */ | |
12816 | else if (old_die && TREE_STATIC (decl) && ! declaration | |
c26fbbca | 12817 | && get_AT_flag (old_die, DW_AT_declaration) == 1) |
bdb669cb | 12818 | { |
e689ae67 | 12819 | /* This is a definition of a C++ class level static. */ |
47fcfa7b | 12820 | add_AT_specification (var_die, old_die); |
bdb669cb JM |
12821 | if (DECL_NAME (decl)) |
12822 | { | |
6773e15f | 12823 | expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl)); |
d5688810 | 12824 | struct dwarf_file_data * file_index = lookup_filename (s.file); |
71dfc51f | 12825 | |
d5688810 GK |
12826 | if (get_AT_file (old_die, DW_AT_decl_file) != file_index) |
12827 | add_AT_file (var_die, DW_AT_decl_file, file_index); | |
71dfc51f | 12828 | |
d5688810 | 12829 | if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line) |
6773e15f | 12830 | add_AT_unsigned (var_die, DW_AT_decl_line, s.line); |
bdb669cb JM |
12831 | } |
12832 | } | |
a3f97cbb JW |
12833 | else |
12834 | { | |
611cd333 JJ |
12835 | tree type = TREE_TYPE (decl); |
12836 | if ((TREE_CODE (decl) == PARM_DECL | |
12837 | || TREE_CODE (decl) == RESULT_DECL) | |
12838 | && DECL_BY_REFERENCE (decl)) | |
12839 | type = TREE_TYPE (type); | |
12840 | ||
a3f97cbb | 12841 | add_name_and_src_coords_attributes (var_die, decl); |
611cd333 | 12842 | add_type_attribute (var_die, type, TREE_READONLY (decl), |
a3f97cbb | 12843 | TREE_THIS_VOLATILE (decl), context_die); |
71dfc51f | 12844 | |
273dbe67 JM |
12845 | if (TREE_PUBLIC (decl)) |
12846 | add_AT_flag (var_die, DW_AT_external, 1); | |
71dfc51f | 12847 | |
273dbe67 JM |
12848 | if (DECL_ARTIFICIAL (decl)) |
12849 | add_AT_flag (var_die, DW_AT_artificial, 1); | |
71dfc51f | 12850 | |
a94dbf2c JM |
12851 | if (TREE_PROTECTED (decl)) |
12852 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected); | |
12853 | else if (TREE_PRIVATE (decl)) | |
12854 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 12855 | } |
4edb7b60 JM |
12856 | |
12857 | if (declaration) | |
12858 | add_AT_flag (var_die, DW_AT_declaration, 1); | |
556273e0 | 12859 | |
6097b0c3 | 12860 | if (DECL_ABSTRACT (decl) || declaration) |
4edb7b60 JM |
12861 | equate_decl_number_to_die (decl, var_die); |
12862 | ||
12863 | if (! declaration && ! DECL_ABSTRACT (decl)) | |
a3f97cbb | 12864 | { |
0a2d3d69 | 12865 | add_location_or_const_value_attribute (var_die, decl, DW_AT_location); |
d291dd49 | 12866 | add_pubname (decl, var_die); |
a3f97cbb | 12867 | } |
1bfb5f8f JM |
12868 | else |
12869 | tree_add_const_value_attribute (var_die, decl); | |
a3f97cbb JW |
12870 | } |
12871 | ||
12872 | /* Generate a DIE to represent a label identifier. */ | |
71dfc51f | 12873 | |
a3f97cbb | 12874 | static void |
7080f735 | 12875 | gen_label_die (tree decl, dw_die_ref context_die) |
a3f97cbb | 12876 | { |
b3694847 | 12877 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 12878 | dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl); |
b3694847 | 12879 | rtx insn; |
a3f97cbb | 12880 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 12881 | |
a3f97cbb | 12882 | if (origin != NULL) |
71dfc51f | 12883 | add_abstract_origin_attribute (lbl_die, origin); |
a3f97cbb | 12884 | else |
71dfc51f RK |
12885 | add_name_and_src_coords_attributes (lbl_die, decl); |
12886 | ||
a3f97cbb | 12887 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 12888 | equate_decl_number_to_die (decl, lbl_die); |
a3f97cbb JW |
12889 | else |
12890 | { | |
d0585b99 | 12891 | insn = DECL_RTL_IF_SET (decl); |
088e7160 NC |
12892 | |
12893 | /* Deleted labels are programmer specified labels which have been | |
6356f892 | 12894 | eliminated because of various optimizations. We still emit them |
088e7160 | 12895 | here so that it is possible to put breakpoints on them. */ |
d0585b99 | 12896 | if (insn |
4b4bf941 JQ |
12897 | && (LABEL_P (insn) |
12898 | || ((NOTE_P (insn) | |
a38e7aa5 | 12899 | && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL)))) |
a3f97cbb | 12900 | { |
556273e0 KH |
12901 | /* When optimization is enabled (via -O) some parts of the compiler |
12902 | (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which | |
a3f97cbb JW |
12903 | represent source-level labels which were explicitly declared by |
12904 | the user. This really shouldn't be happening though, so catch | |
12905 | it if it ever does happen. */ | |
ced3f397 | 12906 | gcc_assert (!INSN_DELETED_P (insn)); |
71dfc51f | 12907 | |
66234570 | 12908 | ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn)); |
a3f97cbb JW |
12909 | add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); |
12910 | } | |
12911 | } | |
12912 | } | |
12913 | ||
3e2844cb JW |
12914 | /* A helper function for gen_inlined_subroutine_die. Add source coordinate |
12915 | attributes to the DIE for a block STMT, to describe where the inlined | |
12916 | function was called from. This is similar to add_src_coords_attributes. */ | |
12917 | ||
12918 | static inline void | |
12919 | add_call_src_coords_attributes (tree stmt, dw_die_ref die) | |
12920 | { | |
12921 | expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt)); | |
3e2844cb | 12922 | |
d5688810 | 12923 | add_AT_file (die, DW_AT_call_file, lookup_filename (s.file)); |
3e2844cb JW |
12924 | add_AT_unsigned (die, DW_AT_call_line, s.line); |
12925 | } | |
12926 | ||
dfad806e AO |
12927 | |
12928 | /* If STMT's abstract origin is a function declaration and STMT's | |
12929 | first subblock's abstract origin is the function's outermost block, | |
12930 | then we're looking at the main entry point. */ | |
12931 | static bool | |
9678086d | 12932 | is_inlined_entry_point (const_tree stmt) |
dfad806e AO |
12933 | { |
12934 | tree decl, block; | |
12935 | ||
12936 | if (!stmt || TREE_CODE (stmt) != BLOCK) | |
12937 | return false; | |
12938 | ||
12939 | decl = block_ultimate_origin (stmt); | |
12940 | ||
12941 | if (!decl || TREE_CODE (decl) != FUNCTION_DECL) | |
12942 | return false; | |
12943 | ||
12944 | block = BLOCK_SUBBLOCKS (stmt); | |
12945 | ||
12946 | if (block) | |
12947 | { | |
12948 | if (TREE_CODE (block) != BLOCK) | |
12949 | return false; | |
12950 | ||
12951 | block = block_ultimate_origin (block); | |
12952 | } | |
12953 | ||
12954 | return block == DECL_INITIAL (decl); | |
12955 | } | |
12956 | ||
fdfa76bd JW |
12957 | /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die. |
12958 | Add low_pc and high_pc attributes to the DIE for a block STMT. */ | |
71dfc51f | 12959 | |
fdfa76bd JW |
12960 | static inline void |
12961 | add_high_low_attributes (tree stmt, dw_die_ref die) | |
a3f97cbb | 12962 | { |
a3f97cbb | 12963 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 12964 | |
fdfa76bd | 12965 | if (BLOCK_FRAGMENT_CHAIN (stmt)) |
a3f97cbb | 12966 | { |
fdfa76bd | 12967 | tree chain; |
a20612aa | 12968 | |
dfad806e AO |
12969 | if (is_inlined_entry_point (stmt)) |
12970 | { | |
12971 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, | |
12972 | BLOCK_NUMBER (stmt)); | |
12973 | add_AT_lbl_id (die, DW_AT_entry_pc, label); | |
12974 | } | |
12975 | ||
fdfa76bd | 12976 | add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt)); |
a20612aa | 12977 | |
fdfa76bd JW |
12978 | chain = BLOCK_FRAGMENT_CHAIN (stmt); |
12979 | do | |
a20612aa | 12980 | { |
fdfa76bd JW |
12981 | add_ranges (chain); |
12982 | chain = BLOCK_FRAGMENT_CHAIN (chain); | |
a20612aa | 12983 | } |
fdfa76bd JW |
12984 | while (chain); |
12985 | add_ranges (NULL); | |
12986 | } | |
12987 | else | |
12988 | { | |
12989 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, | |
12990 | BLOCK_NUMBER (stmt)); | |
12991 | add_AT_lbl_id (die, DW_AT_low_pc, label); | |
12992 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, | |
12993 | BLOCK_NUMBER (stmt)); | |
12994 | add_AT_lbl_id (die, DW_AT_high_pc, label); | |
a3f97cbb | 12995 | } |
fdfa76bd JW |
12996 | } |
12997 | ||
12998 | /* Generate a DIE for a lexical block. */ | |
12999 | ||
13000 | static void | |
13001 | gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth) | |
13002 | { | |
13003 | dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt); | |
13004 | ||
13005 | if (! BLOCK_ABSTRACT (stmt)) | |
13006 | add_high_low_attributes (stmt, stmt_die); | |
71dfc51f | 13007 | |
d7248bff | 13008 | decls_for_scope (stmt, stmt_die, depth); |
a3f97cbb JW |
13009 | } |
13010 | ||
13011 | /* Generate a DIE for an inlined subprogram. */ | |
71dfc51f | 13012 | |
a3f97cbb | 13013 | static void |
7080f735 | 13014 | gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth) |
a3f97cbb | 13015 | { |
9bdca184 AO |
13016 | tree decl = block_ultimate_origin (stmt); |
13017 | ||
13018 | /* Emit info for the abstract instance first, if we haven't yet. We | |
13019 | must emit this even if the block is abstract, otherwise when we | |
13020 | emit the block below (or elsewhere), we may end up trying to emit | |
13021 | a die whose origin die hasn't been emitted, and crashing. */ | |
13022 | dwarf2out_abstract_function (decl); | |
13023 | ||
71dfc51f | 13024 | if (! BLOCK_ABSTRACT (stmt)) |
a3f97cbb | 13025 | { |
b3694847 | 13026 | dw_die_ref subr_die |
54ba1f0d | 13027 | = new_die (DW_TAG_inlined_subroutine, context_die, stmt); |
71dfc51f | 13028 | |
ab72d377 | 13029 | add_abstract_origin_attribute (subr_die, decl); |
fdfa76bd | 13030 | add_high_low_attributes (stmt, subr_die); |
3e2844cb | 13031 | add_call_src_coords_attributes (stmt, subr_die); |
fdfa76bd | 13032 | |
d7248bff | 13033 | decls_for_scope (stmt, subr_die, depth); |
7e23cb16 | 13034 | current_function_has_inlines = 1; |
a3f97cbb | 13035 | } |
06e224f7 AO |
13036 | else |
13037 | /* We may get here if we're the outer block of function A that was | |
13038 | inlined into function B that was inlined into function C. When | |
13039 | generating debugging info for C, dwarf2out_abstract_function(B) | |
13040 | would mark all inlined blocks as abstract, including this one. | |
13041 | So, we wouldn't (and shouldn't) expect labels to be generated | |
13042 | for this one. Instead, just emit debugging info for | |
13043 | declarations within the block. This is particularly important | |
13044 | in the case of initializers of arguments passed from B to us: | |
13045 | if they're statement expressions containing declarations, we | |
13046 | wouldn't generate dies for their abstract variables, and then, | |
13047 | when generating dies for the real variables, we'd die (pun | |
13048 | intended :-) */ | |
13049 | gen_lexical_block_die (stmt, context_die, depth); | |
a3f97cbb JW |
13050 | } |
13051 | ||
13052 | /* Generate a DIE for a field in a record, or structure. */ | |
71dfc51f | 13053 | |
a3f97cbb | 13054 | static void |
7080f735 | 13055 | gen_field_die (tree decl, dw_die_ref context_die) |
a3f97cbb | 13056 | { |
a53efda2 | 13057 | dw_die_ref decl_die; |
71dfc51f | 13058 | |
a53efda2 JZ |
13059 | if (TREE_TYPE (decl) == error_mark_node) |
13060 | return; | |
7080f735 | 13061 | |
a53efda2 | 13062 | decl_die = new_die (DW_TAG_member, context_die, decl); |
a3f97cbb | 13063 | add_name_and_src_coords_attributes (decl_die, decl); |
a3f97cbb JW |
13064 | add_type_attribute (decl_die, member_declared_type (decl), |
13065 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl), | |
13066 | context_die); | |
71dfc51f | 13067 | |
a3f97cbb JW |
13068 | if (DECL_BIT_FIELD_TYPE (decl)) |
13069 | { | |
13070 | add_byte_size_attribute (decl_die, decl); | |
13071 | add_bit_size_attribute (decl_die, decl); | |
13072 | add_bit_offset_attribute (decl_die, decl); | |
13073 | } | |
71dfc51f | 13074 | |
a94dbf2c JM |
13075 | if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE) |
13076 | add_data_member_location_attribute (decl_die, decl); | |
71dfc51f | 13077 | |
273dbe67 JM |
13078 | if (DECL_ARTIFICIAL (decl)) |
13079 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
71dfc51f | 13080 | |
a94dbf2c JM |
13081 | if (TREE_PROTECTED (decl)) |
13082 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected); | |
13083 | else if (TREE_PRIVATE (decl)) | |
13084 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private); | |
90300b8c DP |
13085 | |
13086 | /* Equate decl number to die, so that we can look up this decl later on. */ | |
13087 | equate_decl_number_to_die (decl, decl_die); | |
a3f97cbb JW |
13088 | } |
13089 | ||
ab72d377 JM |
13090 | #if 0 |
13091 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. | |
13092 | Use modified_type_die instead. | |
a3f97cbb JW |
13093 | We keep this code here just in case these types of DIEs may be needed to |
13094 | represent certain things in other languages (e.g. Pascal) someday. */ | |
2ad9852d | 13095 | |
a3f97cbb | 13096 | static void |
7080f735 | 13097 | gen_pointer_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 13098 | { |
b3694847 | 13099 | dw_die_ref ptr_die |
54ba1f0d | 13100 | = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type); |
71dfc51f | 13101 | |
a3f97cbb | 13102 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 13103 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 13104 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb JW |
13105 | } |
13106 | ||
ab72d377 JM |
13107 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. |
13108 | Use modified_type_die instead. | |
a3f97cbb JW |
13109 | We keep this code here just in case these types of DIEs may be needed to |
13110 | represent certain things in other languages (e.g. Pascal) someday. */ | |
2ad9852d | 13111 | |
a3f97cbb | 13112 | static void |
7080f735 | 13113 | gen_reference_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 13114 | { |
b3694847 | 13115 | dw_die_ref ref_die |
54ba1f0d | 13116 | = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type); |
71dfc51f | 13117 | |
a3f97cbb | 13118 | equate_type_number_to_die (type, ref_die); |
a3f97cbb | 13119 | add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 13120 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb | 13121 | } |
ab72d377 | 13122 | #endif |
a3f97cbb JW |
13123 | |
13124 | /* Generate a DIE for a pointer to a member type. */ | |
2ad9852d | 13125 | |
a3f97cbb | 13126 | static void |
7080f735 | 13127 | gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 13128 | { |
b3694847 | 13129 | dw_die_ref ptr_die |
54ba1f0d RH |
13130 | = new_die (DW_TAG_ptr_to_member_type, |
13131 | scope_die_for (type, context_die), type); | |
71dfc51f | 13132 | |
a3f97cbb | 13133 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 13134 | add_AT_die_ref (ptr_die, DW_AT_containing_type, |
bdb669cb | 13135 | lookup_type_die (TYPE_OFFSET_BASETYPE (type))); |
a3f97cbb JW |
13136 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
13137 | } | |
13138 | ||
13139 | /* Generate the DIE for the compilation unit. */ | |
71dfc51f | 13140 | |
a96c67ec | 13141 | static dw_die_ref |
7080f735 | 13142 | gen_compile_unit_die (const char *filename) |
a3f97cbb | 13143 | { |
b3694847 | 13144 | dw_die_ref die; |
a3f97cbb | 13145 | char producer[250]; |
3ac88239 | 13146 | const char *language_string = lang_hooks.name; |
a96c67ec | 13147 | int language; |
a3f97cbb | 13148 | |
54ba1f0d | 13149 | die = new_die (DW_TAG_compile_unit, NULL, NULL); |
bdb669cb | 13150 | |
c4274b22 RH |
13151 | if (filename) |
13152 | { | |
13153 | add_name_attribute (die, filename); | |
e3091a5f | 13154 | /* Don't add cwd for <built-in>. */ |
1d2c2b96 | 13155 | if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<') |
c4274b22 RH |
13156 | add_comp_dir_attribute (die); |
13157 | } | |
a3f97cbb JW |
13158 | |
13159 | sprintf (producer, "%s %s", language_string, version_string); | |
13160 | ||
13161 | #ifdef MIPS_DEBUGGING_INFO | |
13162 | /* The MIPS/SGI compilers place the 'cc' command line options in the producer | |
13163 | string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do | |
13164 | not appear in the producer string, the debugger reaches the conclusion | |
13165 | that the object file is stripped and has no debugging information. | |
13166 | To get the MIPS/SGI debugger to believe that there is debugging | |
13167 | information in the object file, we add a -g to the producer string. */ | |
4927276d JM |
13168 | if (debug_info_level > DINFO_LEVEL_TERSE) |
13169 | strcat (producer, " -g"); | |
a3f97cbb JW |
13170 | #endif |
13171 | ||
a96c67ec | 13172 | add_AT_string (die, DW_AT_producer, producer); |
a9d38797 | 13173 | |
a3f97cbb | 13174 | if (strcmp (language_string, "GNU C++") == 0) |
a96c67ec | 13175 | language = DW_LANG_C_plus_plus; |
a3f97cbb | 13176 | else if (strcmp (language_string, "GNU Ada") == 0) |
8cb5fbbf | 13177 | language = DW_LANG_Ada95; |
a9d38797 | 13178 | else if (strcmp (language_string, "GNU F77") == 0) |
a96c67ec | 13179 | language = DW_LANG_Fortran77; |
3135ce84 | 13180 | else if (strcmp (language_string, "GNU Fortran") == 0) |
6de9cd9a | 13181 | language = DW_LANG_Fortran95; |
bc28c45b | 13182 | else if (strcmp (language_string, "GNU Pascal") == 0) |
a96c67ec | 13183 | language = DW_LANG_Pascal83; |
28985b81 AG |
13184 | else if (strcmp (language_string, "GNU Java") == 0) |
13185 | language = DW_LANG_Java; | |
9e51ddaa GK |
13186 | else if (strcmp (language_string, "GNU Objective-C") == 0) |
13187 | language = DW_LANG_ObjC; | |
13188 | else if (strcmp (language_string, "GNU Objective-C++") == 0) | |
13189 | language = DW_LANG_ObjC_plus_plus; | |
a3f97cbb | 13190 | else |
a96c67ec | 13191 | language = DW_LANG_C89; |
a9d38797 | 13192 | |
a96c67ec | 13193 | add_AT_unsigned (die, DW_AT_language, language); |
a96c67ec | 13194 | return die; |
a3f97cbb JW |
13195 | } |
13196 | ||
61b32c02 | 13197 | /* Generate the DIE for a base class. */ |
71dfc51f | 13198 | |
61b32c02 | 13199 | static void |
7080f735 | 13200 | gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die) |
61b32c02 | 13201 | { |
54ba1f0d | 13202 | dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo); |
71dfc51f | 13203 | |
61b32c02 JM |
13204 | add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die); |
13205 | add_data_member_location_attribute (die, binfo); | |
71dfc51f | 13206 | |
809e3e7f | 13207 | if (BINFO_VIRTUAL_P (binfo)) |
61b32c02 | 13208 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); |
2ad9852d | 13209 | |
dbbf88d1 | 13210 | if (access == access_public_node) |
61b32c02 | 13211 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public); |
dbbf88d1 | 13212 | else if (access == access_protected_node) |
61b32c02 JM |
13213 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected); |
13214 | } | |
13215 | ||
956d6950 | 13216 | /* Generate a DIE for a class member. */ |
71dfc51f | 13217 | |
a3f97cbb | 13218 | static void |
7080f735 | 13219 | gen_member_die (tree type, dw_die_ref context_die) |
a3f97cbb | 13220 | { |
b3694847 | 13221 | tree member; |
dbbf88d1 | 13222 | tree binfo = TYPE_BINFO (type); |
10a11b75 | 13223 | dw_die_ref child; |
71dfc51f | 13224 | |
a3f97cbb JW |
13225 | /* If this is not an incomplete type, output descriptions of each of its |
13226 | members. Note that as we output the DIEs necessary to represent the | |
13227 | members of this record or union type, we will also be trying to output | |
13228 | DIEs to represent the *types* of those members. However the `type' | |
556273e0 | 13229 | function (above) will specifically avoid generating type DIEs for member |
eaec9b3d | 13230 | types *within* the list of member DIEs for this (containing) type except |
a3f97cbb JW |
13231 | for those types (of members) which are explicitly marked as also being |
13232 | members of this (containing) type themselves. The g++ front- end can | |
2ad9852d RK |
13233 | force any given type to be treated as a member of some other (containing) |
13234 | type by setting the TYPE_CONTEXT of the given (member) type to point to | |
13235 | the TREE node representing the appropriate (containing) type. */ | |
a3f97cbb | 13236 | |
61b32c02 | 13237 | /* First output info about the base classes. */ |
fa743e8c | 13238 | if (binfo) |
a3f97cbb | 13239 | { |
d4e6fecb | 13240 | VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo); |
b3694847 | 13241 | int i; |
fa743e8c | 13242 | tree base; |
61b32c02 | 13243 | |
fa743e8c NS |
13244 | for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++) |
13245 | gen_inheritance_die (base, | |
63d1c7b3 | 13246 | (accesses ? VEC_index (tree, accesses, i) |
dbbf88d1 | 13247 | : access_public_node), context_die); |
a3f97cbb JW |
13248 | } |
13249 | ||
61b32c02 JM |
13250 | /* Now output info about the data members and type members. */ |
13251 | for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member)) | |
10a11b75 JM |
13252 | { |
13253 | /* If we thought we were generating minimal debug info for TYPE | |
13254 | and then changed our minds, some of the member declarations | |
13255 | may have already been defined. Don't define them again, but | |
13256 | do put them in the right order. */ | |
13257 | ||
13258 | child = lookup_decl_die (member); | |
13259 | if (child) | |
13260 | splice_child_die (context_die, child); | |
13261 | else | |
13262 | gen_decl_die (member, context_die); | |
13263 | } | |
61b32c02 | 13264 | |
a3f97cbb | 13265 | /* Now output info about the function members (if any). */ |
61b32c02 | 13266 | for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member)) |
10a11b75 | 13267 | { |
5daf7c0a JM |
13268 | /* Don't include clones in the member list. */ |
13269 | if (DECL_ABSTRACT_ORIGIN (member)) | |
13270 | continue; | |
13271 | ||
10a11b75 JM |
13272 | child = lookup_decl_die (member); |
13273 | if (child) | |
13274 | splice_child_die (context_die, child); | |
13275 | else | |
13276 | gen_decl_die (member, context_die); | |
13277 | } | |
a3f97cbb JW |
13278 | } |
13279 | ||
10a11b75 JM |
13280 | /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG |
13281 | is set, we pretend that the type was never defined, so we only get the | |
13282 | member DIEs needed by later specification DIEs. */ | |
71dfc51f | 13283 | |
a3f97cbb | 13284 | static void |
39ef6592 LC |
13285 | gen_struct_or_union_type_die (tree type, dw_die_ref context_die, |
13286 | enum debug_info_usage usage) | |
a3f97cbb | 13287 | { |
b3694847 SS |
13288 | dw_die_ref type_die = lookup_type_die (type); |
13289 | dw_die_ref scope_die = 0; | |
13290 | int nested = 0; | |
10a11b75 | 13291 | int complete = (TYPE_SIZE (type) |
65e1263a JW |
13292 | && (! TYPE_STUB_DECL (type) |
13293 | || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)))); | |
66c78aa9 | 13294 | int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace); |
39ef6592 | 13295 | complete = complete && should_emit_struct_debug (type, usage); |
273dbe67 | 13296 | |
10a11b75 | 13297 | if (type_die && ! complete) |
273dbe67 | 13298 | return; |
a082c85a | 13299 | |
71dfc51f | 13300 | if (TYPE_CONTEXT (type) != NULL_TREE |
66c78aa9 JM |
13301 | && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) |
13302 | || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)) | |
a082c85a JM |
13303 | nested = 1; |
13304 | ||
a94dbf2c | 13305 | scope_die = scope_die_for (type, context_die); |
a082c85a JM |
13306 | |
13307 | if (! type_die || (nested && scope_die == comp_unit_die)) | |
273dbe67 | 13308 | /* First occurrence of type or toplevel definition of nested class. */ |
a3f97cbb | 13309 | { |
b3694847 | 13310 | dw_die_ref old_die = type_die; |
71dfc51f | 13311 | |
a3f97cbb | 13312 | type_die = new_die (TREE_CODE (type) == RECORD_TYPE |
394d9fe7 | 13313 | ? record_type_tag (type) : DW_TAG_union_type, |
54ba1f0d | 13314 | scope_die, type); |
a3f97cbb | 13315 | equate_type_number_to_die (type, type_die); |
273dbe67 | 13316 | if (old_die) |
47fcfa7b | 13317 | add_AT_specification (type_die, old_die); |
5de0e8d4 JM |
13318 | else |
13319 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 13320 | } |
4b674448 | 13321 | else |
273dbe67 | 13322 | remove_AT (type_die, DW_AT_declaration); |
a3f97cbb JW |
13323 | |
13324 | /* If this type has been completed, then give it a byte_size attribute and | |
13325 | then give a list of members. */ | |
66c78aa9 | 13326 | if (complete && !ns_decl) |
a3f97cbb | 13327 | { |
556273e0 | 13328 | /* Prevent infinite recursion in cases where the type of some member of |
73c68f61 | 13329 | this type is expressed in terms of this type itself. */ |
a3f97cbb | 13330 | TREE_ASM_WRITTEN (type) = 1; |
273dbe67 | 13331 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 13332 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 13333 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 13334 | |
ef76d03b JW |
13335 | /* If the first reference to this type was as the return type of an |
13336 | inline function, then it may not have a parent. Fix this now. */ | |
13337 | if (type_die->die_parent == NULL) | |
13338 | add_child_die (scope_die, type_die); | |
13339 | ||
273dbe67 JM |
13340 | push_decl_scope (type); |
13341 | gen_member_die (type, type_die); | |
13342 | pop_decl_scope (); | |
71dfc51f | 13343 | |
a94dbf2c JM |
13344 | /* GNU extension: Record what type our vtable lives in. */ |
13345 | if (TYPE_VFIELD (type)) | |
13346 | { | |
13347 | tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type)); | |
71dfc51f | 13348 | |
de6e505e JM |
13349 | gen_type_die (vtype, context_die); |
13350 | add_AT_die_ref (type_die, DW_AT_containing_type, | |
13351 | lookup_type_die (vtype)); | |
a94dbf2c | 13352 | } |
a3f97cbb | 13353 | } |
4b674448 | 13354 | else |
8a8c3656 JM |
13355 | { |
13356 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a30d4514 | 13357 | |
9765e357 | 13358 | /* We don't need to do this for function-local types. */ |
9702143f RK |
13359 | if (TYPE_STUB_DECL (type) |
13360 | && ! decl_function_context (TYPE_STUB_DECL (type))) | |
887fb69b | 13361 | VEC_safe_push (tree, gc, incomplete_types, type); |
8a8c3656 | 13362 | } |
89708594 CT |
13363 | |
13364 | if (get_AT (type_die, DW_AT_name)) | |
13365 | add_pubtype (type, type_die); | |
a3f97cbb JW |
13366 | } |
13367 | ||
13368 | /* Generate a DIE for a subroutine _type_. */ | |
71dfc51f | 13369 | |
a3f97cbb | 13370 | static void |
7080f735 | 13371 | gen_subroutine_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 13372 | { |
b3694847 SS |
13373 | tree return_type = TREE_TYPE (type); |
13374 | dw_die_ref subr_die | |
54ba1f0d RH |
13375 | = new_die (DW_TAG_subroutine_type, |
13376 | scope_die_for (type, context_die), type); | |
71dfc51f | 13377 | |
a3f97cbb JW |
13378 | equate_type_number_to_die (type, subr_die); |
13379 | add_prototyped_attribute (subr_die, type); | |
a3f97cbb | 13380 | add_type_attribute (subr_die, return_type, 0, 0, context_die); |
a94dbf2c | 13381 | gen_formal_types_die (type, subr_die); |
89708594 CT |
13382 | |
13383 | if (get_AT (subr_die, DW_AT_name)) | |
13384 | add_pubtype (type, subr_die); | |
a3f97cbb JW |
13385 | } |
13386 | ||
f9da5064 | 13387 | /* Generate a DIE for a type definition. */ |
71dfc51f | 13388 | |
a3f97cbb | 13389 | static void |
7080f735 | 13390 | gen_typedef_die (tree decl, dw_die_ref context_die) |
a3f97cbb | 13391 | { |
b3694847 SS |
13392 | dw_die_ref type_die; |
13393 | tree origin; | |
a94dbf2c JM |
13394 | |
13395 | if (TREE_ASM_WRITTEN (decl)) | |
13396 | return; | |
a94dbf2c | 13397 | |
2ad9852d | 13398 | TREE_ASM_WRITTEN (decl) = 1; |
54ba1f0d | 13399 | type_die = new_die (DW_TAG_typedef, context_die, decl); |
a94dbf2c | 13400 | origin = decl_ultimate_origin (decl); |
a3f97cbb | 13401 | if (origin != NULL) |
a94dbf2c | 13402 | add_abstract_origin_attribute (type_die, origin); |
a3f97cbb JW |
13403 | else |
13404 | { | |
b3694847 | 13405 | tree type; |
2ad9852d | 13406 | |
a3f97cbb | 13407 | add_name_and_src_coords_attributes (type_die, decl); |
a94dbf2c JM |
13408 | if (DECL_ORIGINAL_TYPE (decl)) |
13409 | { | |
13410 | type = DECL_ORIGINAL_TYPE (decl); | |
62e3bf54 | 13411 | |
ced3f397 NS |
13412 | gcc_assert (type != TREE_TYPE (decl)); |
13413 | equate_type_number_to_die (TREE_TYPE (decl), type_die); | |
a94dbf2c JM |
13414 | } |
13415 | else | |
13416 | type = TREE_TYPE (decl); | |
2ad9852d | 13417 | |
a94dbf2c JM |
13418 | add_type_attribute (type_die, type, TREE_READONLY (decl), |
13419 | TREE_THIS_VOLATILE (decl), context_die); | |
a3f97cbb | 13420 | } |
71dfc51f | 13421 | |
a3f97cbb | 13422 | if (DECL_ABSTRACT (decl)) |
a94dbf2c | 13423 | equate_decl_number_to_die (decl, type_die); |
89708594 CT |
13424 | |
13425 | if (get_AT (type_die, DW_AT_name)) | |
13426 | add_pubtype (decl, type_die); | |
a3f97cbb JW |
13427 | } |
13428 | ||
13429 | /* Generate a type description DIE. */ | |
71dfc51f | 13430 | |
a3f97cbb | 13431 | static void |
39ef6592 LC |
13432 | gen_type_die_with_usage (tree type, dw_die_ref context_die, |
13433 | enum debug_info_usage usage) | |
a3f97cbb | 13434 | { |
348bb3c7 | 13435 | int need_pop; |
fad0afd7 | 13436 | struct array_descr_info info; |
348bb3c7 | 13437 | |
71dfc51f RK |
13438 | if (type == NULL_TREE || type == error_mark_node) |
13439 | return; | |
a3f97cbb | 13440 | |
a94dbf2c JM |
13441 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
13442 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
556273e0 | 13443 | { |
5d7bed9d DJ |
13444 | if (TREE_ASM_WRITTEN (type)) |
13445 | return; | |
13446 | ||
29b91443 | 13447 | /* Prevent broken recursion; we can't hand off to the same type. */ |
ced3f397 | 13448 | gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type); |
29b91443 | 13449 | |
a94dbf2c JM |
13450 | TREE_ASM_WRITTEN (type) = 1; |
13451 | gen_decl_die (TYPE_NAME (type), context_die); | |
13452 | return; | |
13453 | } | |
13454 | ||
fad0afd7 JJ |
13455 | /* If this is an array type with hidden descriptor, handle it first. */ |
13456 | if (!TREE_ASM_WRITTEN (type) | |
13457 | && lang_hooks.types.get_array_descr_info | |
13458 | && lang_hooks.types.get_array_descr_info (type, &info)) | |
13459 | { | |
13460 | gen_descr_array_type_die (type, &info, context_die); | |
13461 | TREE_ASM_WRITTEN (type) = 1; | |
13462 | return; | |
13463 | } | |
13464 | ||
5d7bed9d DJ |
13465 | /* We are going to output a DIE to represent the unqualified version |
13466 | of this type (i.e. without any const or volatile qualifiers) so | |
13467 | get the main variant (i.e. the unqualified version) of this type | |
13468 | now. (Vectors are special because the debugging info is in the | |
13469 | cloned type itself). */ | |
13470 | if (TREE_CODE (type) != VECTOR_TYPE) | |
13471 | type = type_main_variant (type); | |
13472 | ||
13473 | if (TREE_ASM_WRITTEN (type)) | |
13474 | return; | |
13475 | ||
a3f97cbb JW |
13476 | switch (TREE_CODE (type)) |
13477 | { | |
13478 | case ERROR_MARK: | |
13479 | break; | |
13480 | ||
13481 | case POINTER_TYPE: | |
13482 | case REFERENCE_TYPE: | |
956d6950 JL |
13483 | /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This |
13484 | ensures that the gen_type_die recursion will terminate even if the | |
13485 | type is recursive. Recursive types are possible in Ada. */ | |
13486 | /* ??? We could perhaps do this for all types before the switch | |
13487 | statement. */ | |
13488 | TREE_ASM_WRITTEN (type) = 1; | |
13489 | ||
a3f97cbb | 13490 | /* For these types, all that is required is that we output a DIE (or a |
73c68f61 | 13491 | set of DIEs) to represent the "basis" type. */ |
39ef6592 LC |
13492 | gen_type_die_with_usage (TREE_TYPE (type), context_die, |
13493 | DINFO_USAGE_IND_USE); | |
a3f97cbb JW |
13494 | break; |
13495 | ||
13496 | case OFFSET_TYPE: | |
556273e0 | 13497 | /* This code is used for C++ pointer-to-data-member types. |
71dfc51f | 13498 | Output a description of the relevant class type. */ |
39ef6592 LC |
13499 | gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die, |
13500 | DINFO_USAGE_IND_USE); | |
71dfc51f | 13501 | |
a3f97cbb | 13502 | /* Output a description of the type of the object pointed to. */ |
39ef6592 LC |
13503 | gen_type_die_with_usage (TREE_TYPE (type), context_die, |
13504 | DINFO_USAGE_IND_USE); | |
71dfc51f | 13505 | |
a3f97cbb | 13506 | /* Now output a DIE to represent this pointer-to-data-member type |
73c68f61 | 13507 | itself. */ |
a3f97cbb JW |
13508 | gen_ptr_to_mbr_type_die (type, context_die); |
13509 | break; | |
13510 | ||
a3f97cbb JW |
13511 | case FUNCTION_TYPE: |
13512 | /* Force out return type (in case it wasn't forced out already). */ | |
39ef6592 LC |
13513 | gen_type_die_with_usage (TREE_TYPE (type), context_die, |
13514 | DINFO_USAGE_DIR_USE); | |
a3f97cbb JW |
13515 | gen_subroutine_type_die (type, context_die); |
13516 | break; | |
13517 | ||
13518 | case METHOD_TYPE: | |
13519 | /* Force out return type (in case it wasn't forced out already). */ | |
39ef6592 LC |
13520 | gen_type_die_with_usage (TREE_TYPE (type), context_die, |
13521 | DINFO_USAGE_DIR_USE); | |
a3f97cbb JW |
13522 | gen_subroutine_type_die (type, context_die); |
13523 | break; | |
13524 | ||
13525 | case ARRAY_TYPE: | |
71d59383 | 13526 | gen_array_type_die (type, context_die); |
a3f97cbb JW |
13527 | break; |
13528 | ||
4061f623 | 13529 | case VECTOR_TYPE: |
84f0ace0 | 13530 | gen_array_type_die (type, context_die); |
4061f623 BS |
13531 | break; |
13532 | ||
a3f97cbb JW |
13533 | case ENUMERAL_TYPE: |
13534 | case RECORD_TYPE: | |
13535 | case UNION_TYPE: | |
13536 | case QUAL_UNION_TYPE: | |
2ad9852d | 13537 | /* If this is a nested type whose containing class hasn't been written |
73c68f61 SS |
13538 | out yet, writing it out will cover this one, too. This does not apply |
13539 | to instantiations of member class templates; they need to be added to | |
13540 | the containing class as they are generated. FIXME: This hurts the | |
13541 | idea of combining type decls from multiple TUs, since we can't predict | |
13542 | what set of template instantiations we'll get. */ | |
a082c85a | 13543 | if (TYPE_CONTEXT (type) |
5f2f160c | 13544 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) |
a082c85a | 13545 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) |
a94dbf2c | 13546 | { |
39ef6592 | 13547 | gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage); |
a94dbf2c | 13548 | |
348bb3c7 | 13549 | if (TREE_ASM_WRITTEN (type)) |
a94dbf2c JM |
13550 | return; |
13551 | ||
13552 | /* If that failed, attach ourselves to the stub. */ | |
13553 | push_decl_scope (TYPE_CONTEXT (type)); | |
13554 | context_die = lookup_type_die (TYPE_CONTEXT (type)); | |
348bb3c7 | 13555 | need_pop = 1; |
a94dbf2c | 13556 | } |
348bb3c7 | 13557 | else |
66c78aa9 JM |
13558 | { |
13559 | declare_in_namespace (type, context_die); | |
13560 | need_pop = 0; | |
13561 | } | |
a94dbf2c JM |
13562 | |
13563 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
ae64e535 ILT |
13564 | { |
13565 | /* This might have been written out by the call to | |
13566 | declare_in_namespace. */ | |
13567 | if (!TREE_ASM_WRITTEN (type)) | |
13568 | gen_enumeration_type_die (type, context_die); | |
13569 | } | |
a3f97cbb | 13570 | else |
39ef6592 | 13571 | gen_struct_or_union_type_die (type, context_die, usage); |
4b674448 | 13572 | |
348bb3c7 | 13573 | if (need_pop) |
a94dbf2c JM |
13574 | pop_decl_scope (); |
13575 | ||
4b674448 | 13576 | /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix |
a082c85a JM |
13577 | it up if it is ever completed. gen_*_type_die will set it for us |
13578 | when appropriate. */ | |
13579 | return; | |
a3f97cbb JW |
13580 | |
13581 | case VOID_TYPE: | |
13582 | case INTEGER_TYPE: | |
13583 | case REAL_TYPE: | |
325217ed | 13584 | case FIXED_POINT_TYPE: |
a3f97cbb JW |
13585 | case COMPLEX_TYPE: |
13586 | case BOOLEAN_TYPE: | |
a3f97cbb JW |
13587 | /* No DIEs needed for fundamental types. */ |
13588 | break; | |
13589 | ||
13590 | case LANG_TYPE: | |
13591 | /* No Dwarf representation currently defined. */ | |
13592 | break; | |
13593 | ||
13594 | default: | |
ced3f397 | 13595 | gcc_unreachable (); |
a3f97cbb JW |
13596 | } |
13597 | ||
13598 | TREE_ASM_WRITTEN (type) = 1; | |
13599 | } | |
13600 | ||
39ef6592 LC |
13601 | static void |
13602 | gen_type_die (tree type, dw_die_ref context_die) | |
13603 | { | |
13604 | gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE); | |
13605 | } | |
13606 | ||
a3f97cbb | 13607 | /* Generate a DIE for a tagged type instantiation. */ |
71dfc51f | 13608 | |
a3f97cbb | 13609 | static void |
7080f735 | 13610 | gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die) |
a3f97cbb | 13611 | { |
71dfc51f RK |
13612 | if (type == NULL_TREE || type == error_mark_node) |
13613 | return; | |
a3f97cbb | 13614 | |
38e01259 | 13615 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
13616 | this type (i.e. without any const or volatile qualifiers) so make sure |
13617 | that we have the main variant (i.e. the unqualified version) of this | |
13618 | type now. */ | |
ced3f397 | 13619 | gcc_assert (type == type_main_variant (type)); |
a3f97cbb | 13620 | |
203588e7 | 13621 | /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is |
bbc6ae08 | 13622 | an instance of an unresolved type. */ |
556273e0 | 13623 | |
a3f97cbb JW |
13624 | switch (TREE_CODE (type)) |
13625 | { | |
13626 | case ERROR_MARK: | |
13627 | break; | |
13628 | ||
13629 | case ENUMERAL_TYPE: | |
13630 | gen_inlined_enumeration_type_die (type, context_die); | |
13631 | break; | |
13632 | ||
13633 | case RECORD_TYPE: | |
13634 | gen_inlined_structure_type_die (type, context_die); | |
13635 | break; | |
13636 | ||
13637 | case UNION_TYPE: | |
13638 | case QUAL_UNION_TYPE: | |
13639 | gen_inlined_union_type_die (type, context_die); | |
13640 | break; | |
13641 | ||
13642 | default: | |
ced3f397 | 13643 | gcc_unreachable (); |
a3f97cbb JW |
13644 | } |
13645 | } | |
13646 | ||
13647 | /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the | |
13648 | things which are local to the given block. */ | |
71dfc51f | 13649 | |
a3f97cbb | 13650 | static void |
7080f735 | 13651 | gen_block_die (tree stmt, dw_die_ref context_die, int depth) |
a3f97cbb | 13652 | { |
b3694847 SS |
13653 | int must_output_die = 0; |
13654 | tree origin; | |
13655 | tree decl; | |
13656 | enum tree_code origin_code; | |
a3f97cbb | 13657 | |
9acf766f DB |
13658 | /* Ignore blocks that are NULL. */ |
13659 | if (stmt == NULL_TREE) | |
71dfc51f | 13660 | return; |
a3f97cbb | 13661 | |
a20612aa RH |
13662 | /* If the block is one fragment of a non-contiguous block, do not |
13663 | process the variables, since they will have been done by the | |
13664 | origin block. Do process subblocks. */ | |
13665 | if (BLOCK_FRAGMENT_ORIGIN (stmt)) | |
13666 | { | |
13667 | tree sub; | |
13668 | ||
2ad9852d | 13669 | for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub)) |
a20612aa | 13670 | gen_block_die (sub, context_die, depth + 1); |
2ad9852d | 13671 | |
a20612aa RH |
13672 | return; |
13673 | } | |
13674 | ||
a3f97cbb JW |
13675 | /* Determine the "ultimate origin" of this block. This block may be an |
13676 | inlined instance of an inlined instance of inline function, so we have | |
13677 | to trace all of the way back through the origin chain to find out what | |
13678 | sort of node actually served as the original seed for the creation of | |
13679 | the current block. */ | |
13680 | origin = block_ultimate_origin (stmt); | |
13681 | origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; | |
13682 | ||
13683 | /* Determine if we need to output any Dwarf DIEs at all to represent this | |
13684 | block. */ | |
13685 | if (origin_code == FUNCTION_DECL) | |
71dfc51f RK |
13686 | /* The outer scopes for inlinings *must* always be represented. We |
13687 | generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */ | |
13688 | must_output_die = 1; | |
a3f97cbb JW |
13689 | else |
13690 | { | |
13691 | /* In the case where the current block represents an inlining of the | |
73c68f61 SS |
13692 | "body block" of an inline function, we must *NOT* output any DIE for |
13693 | this block because we have already output a DIE to represent the whole | |
13694 | inlined function scope and the "body block" of any function doesn't | |
13695 | really represent a different scope according to ANSI C rules. So we | |
13696 | check here to make sure that this block does not represent a "body | |
13697 | block inlining" before trying to set the MUST_OUTPUT_DIE flag. */ | |
d7248bff | 13698 | if (! is_body_block (origin ? origin : stmt)) |
a3f97cbb JW |
13699 | { |
13700 | /* Determine if this block directly contains any "significant" | |
13701 | local declarations which we will need to output DIEs for. */ | |
13702 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
71dfc51f RK |
13703 | /* We are not in terse mode so *any* local declaration counts |
13704 | as being a "significant" one. */ | |
2878ea73 MS |
13705 | must_output_die = (BLOCK_VARS (stmt) != NULL |
13706 | && (TREE_USED (stmt) | |
9acf766f DB |
13707 | || TREE_ASM_WRITTEN (stmt) |
13708 | || BLOCK_ABSTRACT (stmt))); | |
a3f97cbb | 13709 | else |
71dfc51f RK |
13710 | /* We are in terse mode, so only local (nested) function |
13711 | definitions count as "significant" local declarations. */ | |
13712 | for (decl = BLOCK_VARS (stmt); | |
13713 | decl != NULL; decl = TREE_CHAIN (decl)) | |
13714 | if (TREE_CODE (decl) == FUNCTION_DECL | |
13715 | && DECL_INITIAL (decl)) | |
a3f97cbb | 13716 | { |
71dfc51f RK |
13717 | must_output_die = 1; |
13718 | break; | |
a3f97cbb | 13719 | } |
a3f97cbb JW |
13720 | } |
13721 | } | |
13722 | ||
13723 | /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block | |
13724 | DIE for any block which contains no significant local declarations at | |
13725 | all. Rather, in such cases we just call `decls_for_scope' so that any | |
13726 | needed Dwarf info for any sub-blocks will get properly generated. Note | |
13727 | that in terse mode, our definition of what constitutes a "significant" | |
13728 | local declaration gets restricted to include only inlined function | |
13729 | instances and local (nested) function definitions. */ | |
13730 | if (must_output_die) | |
13731 | { | |
13732 | if (origin_code == FUNCTION_DECL) | |
71dfc51f | 13733 | gen_inlined_subroutine_die (stmt, context_die, depth); |
a3f97cbb | 13734 | else |
71dfc51f | 13735 | gen_lexical_block_die (stmt, context_die, depth); |
a3f97cbb JW |
13736 | } |
13737 | else | |
d7248bff | 13738 | decls_for_scope (stmt, context_die, depth); |
a3f97cbb JW |
13739 | } |
13740 | ||
13741 | /* Generate all of the decls declared within a given scope and (recursively) | |
9ec36da5 | 13742 | all of its sub-blocks. */ |
71dfc51f | 13743 | |
a3f97cbb | 13744 | static void |
7080f735 | 13745 | decls_for_scope (tree stmt, dw_die_ref context_die, int depth) |
a3f97cbb | 13746 | { |
b3694847 SS |
13747 | tree decl; |
13748 | tree subblocks; | |
71dfc51f | 13749 | |
9acf766f DB |
13750 | /* Ignore NULL blocks. */ |
13751 | if (stmt == NULL_TREE) | |
71dfc51f RK |
13752 | return; |
13753 | ||
9acf766f | 13754 | if (TREE_USED (stmt)) |
a3f97cbb | 13755 | { |
9acf766f DB |
13756 | /* Output the DIEs to represent all of the data objects and typedefs |
13757 | declared directly within this block but not within any nested | |
13758 | sub-blocks. Also, nested function and tag DIEs have been | |
13759 | generated with a parent of NULL; fix that up now. */ | |
13760 | for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl)) | |
13761 | { | |
13762 | dw_die_ref die; | |
2878ea73 | 13763 | |
9acf766f DB |
13764 | if (TREE_CODE (decl) == FUNCTION_DECL) |
13765 | die = lookup_decl_die (decl); | |
13766 | else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)) | |
13767 | die = lookup_type_die (TREE_TYPE (decl)); | |
13768 | else | |
13769 | die = NULL; | |
2878ea73 | 13770 | |
9acf766f DB |
13771 | if (die != NULL && die->die_parent == NULL) |
13772 | add_child_die (context_die, die); | |
30be951a JH |
13773 | /* Do not produce debug information for static variables since |
13774 | these might be optimized out. We are called for these later | |
7151ffbe GH |
13775 | in varpool_analyze_pending_decls. |
13776 | ||
13777 | But *do* produce it for Fortran COMMON variables because, | |
13778 | even though they are static, their names can differ depending | |
13779 | on the scope, which we need to preserve. */ | |
13780 | if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl) | |
13781 | && !(is_fortran () && TREE_PUBLIC (decl))) | |
30be951a | 13782 | ; |
9acf766f DB |
13783 | else |
13784 | gen_decl_die (decl, context_die); | |
13785 | } | |
a3f97cbb JW |
13786 | } |
13787 | ||
8cadae7e JM |
13788 | /* If we're at -g1, we're not interested in subblocks. */ |
13789 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
13790 | return; | |
13791 | ||
a3f97cbb JW |
13792 | /* Output the DIEs to represent all sub-blocks (and the items declared |
13793 | therein) of this block. */ | |
13794 | for (subblocks = BLOCK_SUBBLOCKS (stmt); | |
13795 | subblocks != NULL; | |
13796 | subblocks = BLOCK_CHAIN (subblocks)) | |
71dfc51f | 13797 | gen_block_die (subblocks, context_die, depth + 1); |
a3f97cbb JW |
13798 | } |
13799 | ||
a94dbf2c | 13800 | /* Is this a typedef we can avoid emitting? */ |
71dfc51f RK |
13801 | |
13802 | static inline int | |
9678086d | 13803 | is_redundant_typedef (const_tree decl) |
a94dbf2c JM |
13804 | { |
13805 | if (TYPE_DECL_IS_STUB (decl)) | |
13806 | return 1; | |
71dfc51f | 13807 | |
a94dbf2c JM |
13808 | if (DECL_ARTIFICIAL (decl) |
13809 | && DECL_CONTEXT (decl) | |
13810 | && is_tagged_type (DECL_CONTEXT (decl)) | |
13811 | && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL | |
13812 | && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) | |
13813 | /* Also ignore the artificial member typedef for the class name. */ | |
13814 | return 1; | |
71dfc51f | 13815 | |
a94dbf2c JM |
13816 | return 0; |
13817 | } | |
13818 | ||
535a42b1 | 13819 | /* Returns the DIE for decl. A DIE will always be returned. */ |
6097b0c3 DP |
13820 | |
13821 | static dw_die_ref | |
13822 | force_decl_die (tree decl) | |
13823 | { | |
13824 | dw_die_ref decl_die; | |
13825 | unsigned saved_external_flag; | |
13826 | tree save_fn = NULL_TREE; | |
13827 | decl_die = lookup_decl_die (decl); | |
13828 | if (!decl_die) | |
13829 | { | |
13830 | dw_die_ref context_die; | |
13831 | tree decl_context = DECL_CONTEXT (decl); | |
13832 | if (decl_context) | |
13833 | { | |
13834 | /* Find die that represents this context. */ | |
13835 | if (TYPE_P (decl_context)) | |
13836 | context_die = force_type_die (decl_context); | |
13837 | else | |
13838 | context_die = force_decl_die (decl_context); | |
13839 | } | |
13840 | else | |
13841 | context_die = comp_unit_die; | |
13842 | ||
d3e4cd01 JM |
13843 | decl_die = lookup_decl_die (decl); |
13844 | if (decl_die) | |
13845 | return decl_die; | |
13846 | ||
6097b0c3 DP |
13847 | switch (TREE_CODE (decl)) |
13848 | { | |
13849 | case FUNCTION_DECL: | |
13850 | /* Clear current_function_decl, so that gen_subprogram_die thinks | |
13851 | that this is a declaration. At this point, we just want to force | |
13852 | declaration die. */ | |
13853 | save_fn = current_function_decl; | |
13854 | current_function_decl = NULL_TREE; | |
13855 | gen_subprogram_die (decl, context_die); | |
a1c496cb | 13856 | current_function_decl = save_fn; |
6097b0c3 DP |
13857 | break; |
13858 | ||
13859 | case VAR_DECL: | |
13860 | /* Set external flag to force declaration die. Restore it after | |
13861 | gen_decl_die() call. */ | |
13862 | saved_external_flag = DECL_EXTERNAL (decl); | |
13863 | DECL_EXTERNAL (decl) = 1; | |
13864 | gen_decl_die (decl, context_die); | |
13865 | DECL_EXTERNAL (decl) = saved_external_flag; | |
13866 | break; | |
13867 | ||
13868 | case NAMESPACE_DECL: | |
13869 | dwarf2out_decl (decl); | |
13870 | break; | |
13871 | ||
13872 | default: | |
ced3f397 | 13873 | gcc_unreachable (); |
6097b0c3 | 13874 | } |
a1c496cb | 13875 | |
535a42b1 | 13876 | /* We should be able to find the DIE now. */ |
6097b0c3 DP |
13877 | if (!decl_die) |
13878 | decl_die = lookup_decl_die (decl); | |
ced3f397 | 13879 | gcc_assert (decl_die); |
6097b0c3 | 13880 | } |
a1c496cb | 13881 | |
6097b0c3 DP |
13882 | return decl_die; |
13883 | } | |
66c78aa9 | 13884 | |
8857ae1c AO |
13885 | /* Returns the DIE for TYPE, that must not be a base type. A DIE is |
13886 | always returned. */ | |
66c78aa9 JM |
13887 | |
13888 | static dw_die_ref | |
6097b0c3 | 13889 | force_type_die (tree type) |
66c78aa9 | 13890 | { |
6097b0c3 | 13891 | dw_die_ref type_die; |
66c78aa9 | 13892 | |
9733d507 | 13893 | type_die = lookup_type_die (type); |
6097b0c3 DP |
13894 | if (!type_die) |
13895 | { | |
13896 | dw_die_ref context_die; | |
13897 | if (TYPE_CONTEXT (type)) | |
d3e4cd01 JM |
13898 | { |
13899 | if (TYPE_P (TYPE_CONTEXT (type))) | |
13900 | context_die = force_type_die (TYPE_CONTEXT (type)); | |
13901 | else | |
13902 | context_die = force_decl_die (TYPE_CONTEXT (type)); | |
13903 | } | |
6097b0c3 DP |
13904 | else |
13905 | context_die = comp_unit_die; | |
66c78aa9 | 13906 | |
b4da9f9d MM |
13907 | type_die = modified_type_die (type, TYPE_READONLY (type), |
13908 | TYPE_VOLATILE (type), context_die); | |
ced3f397 | 13909 | gcc_assert (type_die); |
6097b0c3 DP |
13910 | } |
13911 | return type_die; | |
66c78aa9 JM |
13912 | } |
13913 | ||
13914 | /* Force out any required namespaces to be able to output DECL, | |
13915 | and return the new context_die for it, if it's changed. */ | |
13916 | ||
13917 | static dw_die_ref | |
13918 | setup_namespace_context (tree thing, dw_die_ref context_die) | |
13919 | { | |
6615c446 JO |
13920 | tree context = (DECL_P (thing) |
13921 | ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing)); | |
66c78aa9 | 13922 | if (context && TREE_CODE (context) == NAMESPACE_DECL) |
6614fd40 | 13923 | /* Force out the namespace. */ |
6097b0c3 | 13924 | context_die = force_decl_die (context); |
66c78aa9 JM |
13925 | |
13926 | return context_die; | |
13927 | } | |
13928 | ||
13929 | /* Emit a declaration DIE for THING (which is either a DECL or a tagged | |
13930 | type) within its namespace, if appropriate. | |
13931 | ||
13932 | For compatibility with older debuggers, namespace DIEs only contain | |
13933 | declarations; all definitions are emitted at CU scope. */ | |
13934 | ||
13935 | static void | |
13936 | declare_in_namespace (tree thing, dw_die_ref context_die) | |
13937 | { | |
13938 | dw_die_ref ns_context; | |
13939 | ||
13940 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
13941 | return; | |
13942 | ||
0eb971bd JW |
13943 | /* If this decl is from an inlined function, then don't try to emit it in its |
13944 | namespace, as we will get confused. It would have already been emitted | |
13945 | when the abstract instance of the inline function was emitted anyways. */ | |
13946 | if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing)) | |
13947 | return; | |
13948 | ||
66c78aa9 JM |
13949 | ns_context = setup_namespace_context (thing, context_die); |
13950 | ||
13951 | if (ns_context != context_die) | |
13952 | { | |
13953 | if (DECL_P (thing)) | |
13954 | gen_decl_die (thing, ns_context); | |
13955 | else | |
13956 | gen_type_die (thing, ns_context); | |
13957 | } | |
13958 | } | |
13959 | ||
6614fd40 | 13960 | /* Generate a DIE for a namespace or namespace alias. */ |
66c78aa9 JM |
13961 | |
13962 | static void | |
13963 | gen_namespace_die (tree decl) | |
13964 | { | |
13965 | dw_die_ref context_die = setup_namespace_context (decl, comp_unit_die); | |
13966 | ||
13967 | /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace | |
e0a21ab9 | 13968 | they are an alias of. */ |
66c78aa9 JM |
13969 | if (DECL_ABSTRACT_ORIGIN (decl) == NULL) |
13970 | { | |
6614fd40 | 13971 | /* Output a real namespace. */ |
66c78aa9 JM |
13972 | dw_die_ref namespace_die |
13973 | = new_die (DW_TAG_namespace, context_die, decl); | |
13974 | add_name_and_src_coords_attributes (namespace_die, decl); | |
13975 | equate_decl_number_to_die (decl, namespace_die); | |
13976 | } | |
13977 | else | |
13978 | { | |
6614fd40 | 13979 | /* Output a namespace alias. */ |
66c78aa9 | 13980 | |
6614fd40 | 13981 | /* Force out the namespace we are an alias of, if necessary. */ |
66c78aa9 | 13982 | dw_die_ref origin_die |
6097b0c3 | 13983 | = force_decl_die (DECL_ABSTRACT_ORIGIN (decl)); |
66c78aa9 | 13984 | |
6614fd40 | 13985 | /* Now create the namespace alias DIE. */ |
66c78aa9 JM |
13986 | dw_die_ref namespace_die |
13987 | = new_die (DW_TAG_imported_declaration, context_die, decl); | |
13988 | add_name_and_src_coords_attributes (namespace_die, decl); | |
13989 | add_AT_die_ref (namespace_die, DW_AT_import, origin_die); | |
13990 | equate_decl_number_to_die (decl, namespace_die); | |
13991 | } | |
13992 | } | |
13993 | ||
a3f97cbb | 13994 | /* Generate Dwarf debug information for a decl described by DECL. */ |
71dfc51f | 13995 | |
a3f97cbb | 13996 | static void |
7080f735 | 13997 | gen_decl_die (tree decl, dw_die_ref context_die) |
a3f97cbb | 13998 | { |
b3694847 | 13999 | tree origin; |
71dfc51f | 14000 | |
f11c3043 | 14001 | if (DECL_P (decl) && DECL_IGNORED_P (decl)) |
71dfc51f | 14002 | return; |
a3f97cbb | 14003 | |
a3f97cbb JW |
14004 | switch (TREE_CODE (decl)) |
14005 | { | |
2ad9852d RK |
14006 | case ERROR_MARK: |
14007 | break; | |
14008 | ||
a3f97cbb | 14009 | case CONST_DECL: |
556273e0 | 14010 | /* The individual enumerators of an enum type get output when we output |
73c68f61 | 14011 | the Dwarf representation of the relevant enum type itself. */ |
a3f97cbb JW |
14012 | break; |
14013 | ||
14014 | case FUNCTION_DECL: | |
4edb7b60 JM |
14015 | /* Don't output any DIEs to represent mere function declarations, |
14016 | unless they are class members or explicit block externs. */ | |
14017 | if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE | |
777ad4c2 | 14018 | && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl))) |
71dfc51f | 14019 | break; |
bdb669cb | 14020 | |
6de9cd9a DN |
14021 | #if 0 |
14022 | /* FIXME */ | |
14023 | /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN | |
14024 | on local redeclarations of global functions. That seems broken. */ | |
14025 | if (current_function_decl != decl) | |
14026 | /* This is only a declaration. */; | |
14027 | #endif | |
14028 | ||
5daf7c0a JM |
14029 | /* If we're emitting a clone, emit info for the abstract instance. */ |
14030 | if (DECL_ORIGIN (decl) != decl) | |
14031 | dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl)); | |
2ad9852d | 14032 | |
1cfdcc15 JM |
14033 | /* If we're emitting an out-of-line copy of an inline function, |
14034 | emit info for the abstract instance and set up to refer to it. */ | |
1bb17c21 JH |
14035 | else if (cgraph_function_possibly_inlined_p (decl) |
14036 | && ! DECL_ABSTRACT (decl) | |
66c78aa9 | 14037 | && ! class_or_namespace_scope_p (context_die) |
5daf7c0a JM |
14038 | /* dwarf2out_abstract_function won't emit a die if this is just |
14039 | a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in | |
14040 | that case, because that works only if we have a die. */ | |
14041 | && DECL_INITIAL (decl) != NULL_TREE) | |
1cfdcc15 | 14042 | { |
1edf43d6 | 14043 | dwarf2out_abstract_function (decl); |
1cfdcc15 JM |
14044 | set_decl_origin_self (decl); |
14045 | } | |
2ad9852d | 14046 | |
5daf7c0a JM |
14047 | /* Otherwise we're emitting the primary DIE for this decl. */ |
14048 | else if (debug_info_level > DINFO_LEVEL_TERSE) | |
a94dbf2c JM |
14049 | { |
14050 | /* Before we describe the FUNCTION_DECL itself, make sure that we | |
14051 | have described its return type. */ | |
14052 | gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); | |
14053 | ||
2081603c JM |
14054 | /* And its virtual context. */ |
14055 | if (DECL_VINDEX (decl) != NULL_TREE) | |
14056 | gen_type_die (DECL_CONTEXT (decl), context_die); | |
14057 | ||
a94dbf2c JM |
14058 | /* And its containing type. */ |
14059 | origin = decl_class_context (decl); | |
71dfc51f | 14060 | if (origin != NULL_TREE) |
10a11b75 | 14061 | gen_type_die_for_member (origin, decl, context_die); |
66c78aa9 JM |
14062 | |
14063 | /* And its containing namespace. */ | |
14064 | declare_in_namespace (decl, context_die); | |
a94dbf2c | 14065 | } |
a3f97cbb JW |
14066 | |
14067 | /* Now output a DIE to represent the function itself. */ | |
14068 | gen_subprogram_die (decl, context_die); | |
14069 | break; | |
14070 | ||
14071 | case TYPE_DECL: | |
14072 | /* If we are in terse mode, don't generate any DIEs to represent any | |
73c68f61 | 14073 | actual typedefs. */ |
a3f97cbb | 14074 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 14075 | break; |
a3f97cbb | 14076 | |
2ad9852d | 14077 | /* In the special case of a TYPE_DECL node representing the declaration |
73c68f61 SS |
14078 | of some type tag, if the given TYPE_DECL is marked as having been |
14079 | instantiated from some other (original) TYPE_DECL node (e.g. one which | |
14080 | was generated within the original definition of an inline function) we | |
14081 | have to generate a special (abbreviated) DW_TAG_structure_type, | |
14082 | DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */ | |
d6b3c797 JJ |
14083 | if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE |
14084 | && is_tagged_type (TREE_TYPE (decl))) | |
a3f97cbb JW |
14085 | { |
14086 | gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die); | |
14087 | break; | |
14088 | } | |
a3f97cbb | 14089 | |
a94dbf2c JM |
14090 | if (is_redundant_typedef (decl)) |
14091 | gen_type_die (TREE_TYPE (decl), context_die); | |
14092 | else | |
71dfc51f RK |
14093 | /* Output a DIE to represent the typedef itself. */ |
14094 | gen_typedef_die (decl, context_die); | |
a3f97cbb JW |
14095 | break; |
14096 | ||
14097 | case LABEL_DECL: | |
14098 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
71dfc51f | 14099 | gen_label_die (decl, context_die); |
a3f97cbb JW |
14100 | break; |
14101 | ||
14102 | case VAR_DECL: | |
6de9cd9a | 14103 | case RESULT_DECL: |
a3f97cbb | 14104 | /* If we are in terse mode, don't generate any DIEs to represent any |
73c68f61 | 14105 | variable declarations or definitions. */ |
a3f97cbb | 14106 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 14107 | break; |
a3f97cbb | 14108 | |
7151ffbe GH |
14109 | /* If this is the global definition of the Fortran COMMON block, we don't |
14110 | need to do anything. Syntactically, the block itself has no identity, | |
14111 | just its constituent identifiers. */ | |
14112 | if (TREE_CODE (decl) == VAR_DECL | |
14113 | && TREE_PUBLIC (decl) | |
14114 | && TREE_STATIC (decl) | |
14115 | && is_fortran () | |
14116 | && !DECL_HAS_VALUE_EXPR_P (decl)) | |
14117 | break; | |
14118 | ||
a3f97cbb | 14119 | /* Output any DIEs that are needed to specify the type of this data |
73c68f61 | 14120 | object. */ |
611cd333 JJ |
14121 | if (TREE_CODE (decl) == RESULT_DECL && DECL_BY_REFERENCE (decl)) |
14122 | gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); | |
14123 | else | |
14124 | gen_type_die (TREE_TYPE (decl), context_die); | |
a3f97cbb | 14125 | |
a94dbf2c JM |
14126 | /* And its containing type. */ |
14127 | origin = decl_class_context (decl); | |
71dfc51f | 14128 | if (origin != NULL_TREE) |
10a11b75 | 14129 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 14130 | |
66c78aa9 JM |
14131 | /* And its containing namespace. */ |
14132 | declare_in_namespace (decl, context_die); | |
14133 | ||
a3f97cbb | 14134 | /* Now output the DIE to represent the data object itself. This gets |
73c68f61 SS |
14135 | complicated because of the possibility that the VAR_DECL really |
14136 | represents an inlined instance of a formal parameter for an inline | |
14137 | function. */ | |
a3f97cbb | 14138 | origin = decl_ultimate_origin (decl); |
71dfc51f RK |
14139 | if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL) |
14140 | gen_formal_parameter_die (decl, context_die); | |
a3f97cbb | 14141 | else |
71dfc51f | 14142 | gen_variable_die (decl, context_die); |
a3f97cbb JW |
14143 | break; |
14144 | ||
14145 | case FIELD_DECL: | |
2ad9852d | 14146 | /* Ignore the nameless fields that are used to skip bits but handle C++ |
3199cb41 | 14147 | anonymous unions and structs. */ |
71dfc51f | 14148 | if (DECL_NAME (decl) != NULL_TREE |
3199cb41 UW |
14149 | || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE |
14150 | || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE) | |
a3f97cbb JW |
14151 | { |
14152 | gen_type_die (member_declared_type (decl), context_die); | |
14153 | gen_field_die (decl, context_die); | |
14154 | } | |
14155 | break; | |
14156 | ||
14157 | case PARM_DECL: | |
611cd333 JJ |
14158 | if (DECL_BY_REFERENCE (decl)) |
14159 | gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); | |
14160 | else | |
14161 | gen_type_die (TREE_TYPE (decl), context_die); | |
a3f97cbb JW |
14162 | gen_formal_parameter_die (decl, context_die); |
14163 | break; | |
14164 | ||
348bb3c7 | 14165 | case NAMESPACE_DECL: |
66c78aa9 | 14166 | gen_namespace_die (decl); |
348bb3c7 JM |
14167 | break; |
14168 | ||
a3f97cbb | 14169 | default: |
ced3f397 NS |
14170 | /* Probably some frontend-internal decl. Assume we don't care. */ |
14171 | gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES); | |
14172 | break; | |
a3f97cbb | 14173 | } |
a3f97cbb JW |
14174 | } |
14175 | \f | |
2ad9852d | 14176 | /* Output debug information for global decl DECL. Called from toplev.c after |
2b85879e | 14177 | compilation proper has finished. */ |
2ad9852d | 14178 | |
2b85879e | 14179 | static void |
7080f735 | 14180 | dwarf2out_global_decl (tree decl) |
2b85879e NB |
14181 | { |
14182 | /* Output DWARF2 information for file-scope tentative data object | |
4b570560 L |
14183 | declarations, file-scope (extern) function declarations (which |
14184 | had no corresponding body) and file-scope tagged type declarations | |
14185 | and definitions which have not yet been forced out. | |
7151ffbe | 14186 | |
4b570560 L |
14187 | Ignore the global decl of any Fortran COMMON blocks which also |
14188 | wind up here though they have already been described in the local | |
14189 | scope for the procedures using them. */ | |
7151ffbe GH |
14190 | if (TREE_CODE (decl) == VAR_DECL |
14191 | && TREE_PUBLIC (decl) && TREE_STATIC (decl) && is_fortran ()) | |
14192 | return; | |
14193 | ||
2b85879e NB |
14194 | if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)) |
14195 | dwarf2out_decl (decl); | |
14196 | } | |
14197 | ||
21d13d83 ZW |
14198 | /* Output debug information for type decl DECL. Called from toplev.c |
14199 | and from language front ends (to record built-in types). */ | |
14200 | static void | |
14201 | dwarf2out_type_decl (tree decl, int local) | |
14202 | { | |
14203 | if (!local) | |
14204 | dwarf2out_decl (decl); | |
14205 | } | |
14206 | ||
a1c496cb EC |
14207 | /* Output debug information for imported module or decl. */ |
14208 | ||
6097b0c3 DP |
14209 | static void |
14210 | dwarf2out_imported_module_or_decl (tree decl, tree context) | |
14211 | { | |
14212 | dw_die_ref imported_die, at_import_die; | |
14213 | dw_die_ref scope_die; | |
6773e15f | 14214 | expanded_location xloc; |
a1c496cb | 14215 | |
6097b0c3 DP |
14216 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
14217 | return; | |
14218 | ||
ced3f397 | 14219 | gcc_assert (decl); |
6097b0c3 DP |
14220 | |
14221 | /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs. | |
a1c496cb | 14222 | We need decl DIE for reference and scope die. First, get DIE for the decl |
6097b0c3 DP |
14223 | itself. */ |
14224 | ||
14225 | /* Get the scope die for decl context. Use comp_unit_die for global module | |
14226 | or decl. If die is not found for non globals, force new die. */ | |
14227 | if (!context) | |
14228 | scope_die = comp_unit_die; | |
14229 | else if (TYPE_P (context)) | |
39ef6592 LC |
14230 | { |
14231 | if (!should_emit_struct_debug (context, DINFO_USAGE_DIR_USE)) | |
14232 | return; | |
6097b0c3 | 14233 | scope_die = force_type_die (context); |
39ef6592 | 14234 | } |
6097b0c3 DP |
14235 | else |
14236 | scope_die = force_decl_die (context); | |
14237 | ||
834eb1f0 GS |
14238 | /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */ |
14239 | if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL) | |
8857ae1c AO |
14240 | { |
14241 | if (is_base_type (TREE_TYPE (decl))) | |
14242 | at_import_die = base_type_die (TREE_TYPE (decl)); | |
14243 | else | |
14244 | at_import_die = force_type_die (TREE_TYPE (decl)); | |
14245 | } | |
6097b0c3 | 14246 | else |
a288c5cd JJ |
14247 | { |
14248 | at_import_die = lookup_decl_die (decl); | |
14249 | if (!at_import_die) | |
14250 | { | |
14251 | /* If we're trying to avoid duplicate debug info, we may not have | |
14252 | emitted the member decl for this field. Emit it now. */ | |
14253 | if (TREE_CODE (decl) == FIELD_DECL) | |
14254 | { | |
14255 | tree type = DECL_CONTEXT (decl); | |
14256 | dw_die_ref type_context_die; | |
14257 | ||
14258 | if (TYPE_CONTEXT (type)) | |
14259 | if (TYPE_P (TYPE_CONTEXT (type))) | |
39ef6592 LC |
14260 | { |
14261 | if (!should_emit_struct_debug (TYPE_CONTEXT (type), | |
14262 | DINFO_USAGE_DIR_USE)) | |
14263 | return; | |
a288c5cd | 14264 | type_context_die = force_type_die (TYPE_CONTEXT (type)); |
39ef6592 | 14265 | } |
a288c5cd JJ |
14266 | else |
14267 | type_context_die = force_decl_die (TYPE_CONTEXT (type)); | |
14268 | else | |
14269 | type_context_die = comp_unit_die; | |
14270 | gen_type_die_for_member (type, decl, type_context_die); | |
14271 | } | |
14272 | at_import_die = force_decl_die (decl); | |
14273 | } | |
14274 | } | |
a1c496cb EC |
14275 | |
14276 | /* OK, now we have DIEs for decl as well as scope. Emit imported die. */ | |
6097b0c3 DP |
14277 | if (TREE_CODE (decl) == NAMESPACE_DECL) |
14278 | imported_die = new_die (DW_TAG_imported_module, scope_die, context); | |
14279 | else | |
14280 | imported_die = new_die (DW_TAG_imported_declaration, scope_die, context); | |
6773e15f PB |
14281 | |
14282 | xloc = expand_location (input_location); | |
d5688810 | 14283 | add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file)); |
6773e15f | 14284 | add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line); |
6097b0c3 DP |
14285 | add_AT_die_ref (imported_die, DW_AT_import, at_import_die); |
14286 | } | |
14287 | ||
71dfc51f RK |
14288 | /* Write the debugging output for DECL. */ |
14289 | ||
a3f97cbb | 14290 | void |
7080f735 | 14291 | dwarf2out_decl (tree decl) |
a3f97cbb | 14292 | { |
b3694847 | 14293 | dw_die_ref context_die = comp_unit_die; |
88dad228 | 14294 | |
a3f97cbb JW |
14295 | switch (TREE_CODE (decl)) |
14296 | { | |
2ad9852d RK |
14297 | case ERROR_MARK: |
14298 | return; | |
14299 | ||
a3f97cbb | 14300 | case FUNCTION_DECL: |
a3f97cbb | 14301 | /* What we would really like to do here is to filter out all mere |
73c68f61 SS |
14302 | file-scope declarations of file-scope functions which are never |
14303 | referenced later within this translation unit (and keep all of ones | |
14304 | that *are* referenced later on) but we aren't clairvoyant, so we have | |
14305 | no idea which functions will be referenced in the future (i.e. later | |
14306 | on within the current translation unit). So here we just ignore all | |
14307 | file-scope function declarations which are not also definitions. If | |
14308 | and when the debugger needs to know something about these functions, | |
14309 | it will have to hunt around and find the DWARF information associated | |
14310 | with the definition of the function. | |
2ad9852d RK |
14311 | |
14312 | We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL | |
73c68f61 SS |
14313 | nodes represent definitions and which ones represent mere |
14314 | declarations. We have to check DECL_INITIAL instead. That's because | |
14315 | the C front-end supports some weird semantics for "extern inline" | |
14316 | function definitions. These can get inlined within the current | |
569b7f6a | 14317 | translation unit (and thus, we need to generate Dwarf info for their |
73c68f61 SS |
14318 | abstract instances so that the Dwarf info for the concrete inlined |
14319 | instances can have something to refer to) but the compiler never | |
14320 | generates any out-of-lines instances of such things (despite the fact | |
14321 | that they *are* definitions). | |
2ad9852d RK |
14322 | |
14323 | The important point is that the C front-end marks these "extern | |
14324 | inline" functions as DECL_EXTERNAL, but we need to generate DWARF for | |
14325 | them anyway. Note that the C++ front-end also plays some similar games | |
14326 | for inline function definitions appearing within include files which | |
14327 | also contain `#pragma interface' pragmas. */ | |
a3f97cbb | 14328 | if (DECL_INITIAL (decl) == NULL_TREE) |
b1ccbc24 | 14329 | return; |
88dad228 | 14330 | |
9c6cd30e JM |
14331 | /* If we're a nested function, initially use a parent of NULL; if we're |
14332 | a plain function, this will be fixed up in decls_for_scope. If | |
14333 | we're a method, it will be ignored, since we already have a DIE. */ | |
8cadae7e JM |
14334 | if (decl_function_context (decl) |
14335 | /* But if we're in terse mode, we don't care about scope. */ | |
14336 | && debug_info_level > DINFO_LEVEL_TERSE) | |
9c6cd30e | 14337 | context_die = NULL; |
a3f97cbb JW |
14338 | break; |
14339 | ||
14340 | case VAR_DECL: | |
556273e0 | 14341 | /* Ignore this VAR_DECL if it refers to a file-scope extern data object |
73c68f61 SS |
14342 | declaration and if the declaration was never even referenced from |
14343 | within this entire compilation unit. We suppress these DIEs in | |
14344 | order to save space in the .debug section (by eliminating entries | |
14345 | which are probably useless). Note that we must not suppress | |
14346 | block-local extern declarations (whether used or not) because that | |
14347 | would screw-up the debugger's name lookup mechanism and cause it to | |
14348 | miss things which really ought to be in scope at a given point. */ | |
a3f97cbb | 14349 | if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) |
71dfc51f | 14350 | return; |
a3f97cbb | 14351 | |
30be951a JH |
14352 | /* For local statics lookup proper context die. */ |
14353 | if (TREE_STATIC (decl) && decl_function_context (decl)) | |
14354 | context_die = lookup_decl_die (DECL_CONTEXT (decl)); | |
14355 | ||
a3f97cbb | 14356 | /* If we are in terse mode, don't generate any DIEs to represent any |
73c68f61 | 14357 | variable declarations or definitions. */ |
a3f97cbb | 14358 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 14359 | return; |
a3f97cbb JW |
14360 | break; |
14361 | ||
66c78aa9 JM |
14362 | case NAMESPACE_DECL: |
14363 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
14364 | return; | |
14365 | if (lookup_decl_die (decl) != NULL) | |
2878ea73 | 14366 | return; |
66c78aa9 JM |
14367 | break; |
14368 | ||
a3f97cbb | 14369 | case TYPE_DECL: |
57fb7689 JM |
14370 | /* Don't emit stubs for types unless they are needed by other DIEs. */ |
14371 | if (TYPE_DECL_SUPPRESS_DEBUG (decl)) | |
14372 | return; | |
14373 | ||
a3f97cbb | 14374 | /* Don't bother trying to generate any DIEs to represent any of the |
73c68f61 | 14375 | normal built-in types for the language we are compiling. */ |
6773e15f | 14376 | if (DECL_IS_BUILTIN (decl)) |
a94dbf2c JM |
14377 | { |
14378 | /* OK, we need to generate one for `bool' so GDB knows what type | |
73c68f61 | 14379 | comparisons have. */ |
9e51ddaa | 14380 | if (is_cxx () |
f11c3043 RK |
14381 | && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE |
14382 | && ! DECL_IGNORED_P (decl)) | |
a94dbf2c | 14383 | modified_type_die (TREE_TYPE (decl), 0, 0, NULL); |
71dfc51f | 14384 | |
a94dbf2c JM |
14385 | return; |
14386 | } | |
a3f97cbb | 14387 | |
88dad228 | 14388 | /* If we are in terse mode, don't generate any DIEs for types. */ |
a3f97cbb | 14389 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 14390 | return; |
88dad228 JM |
14391 | |
14392 | /* If we're a function-scope tag, initially use a parent of NULL; | |
14393 | this will be fixed up in decls_for_scope. */ | |
14394 | if (decl_function_context (decl)) | |
3f76745e | 14395 | context_die = NULL; |
88dad228 | 14396 | |
a3f97cbb JW |
14397 | break; |
14398 | ||
14399 | default: | |
14400 | return; | |
14401 | } | |
14402 | ||
88dad228 | 14403 | gen_decl_die (decl, context_die); |
a3f97cbb JW |
14404 | } |
14405 | ||
14406 | /* Output a marker (i.e. a label) for the beginning of the generated code for | |
14407 | a lexical block. */ | |
71dfc51f | 14408 | |
a5a42b92 | 14409 | static void |
7080f735 AJ |
14410 | dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED, |
14411 | unsigned int blocknum) | |
a3f97cbb | 14412 | { |
d6b5193b | 14413 | switch_to_section (current_function_section ()); |
8215347e | 14414 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum); |
a3f97cbb JW |
14415 | } |
14416 | ||
14417 | /* Output a marker (i.e. a label) for the end of the generated code for a | |
14418 | lexical block. */ | |
71dfc51f | 14419 | |
a5a42b92 | 14420 | static void |
7080f735 | 14421 | dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum) |
a3f97cbb | 14422 | { |
d6b5193b | 14423 | switch_to_section (current_function_section ()); |
8215347e | 14424 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum); |
a3f97cbb JW |
14425 | } |
14426 | ||
64b59a80 JM |
14427 | /* Returns nonzero if it is appropriate not to emit any debugging |
14428 | information for BLOCK, because it doesn't contain any instructions. | |
fcd7f76b | 14429 | |
64b59a80 JM |
14430 | Don't allow this for blocks with nested functions or local classes |
14431 | as we would end up with orphans, and in the presence of scheduling | |
14432 | we may end up calling them anyway. */ | |
14433 | ||
e1772ac0 | 14434 | static bool |
9678086d | 14435 | dwarf2out_ignore_block (const_tree block) |
fcd7f76b JM |
14436 | { |
14437 | tree decl; | |
2ad9852d | 14438 | |
fcd7f76b | 14439 | for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) |
64b59a80 JM |
14440 | if (TREE_CODE (decl) == FUNCTION_DECL |
14441 | || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))) | |
14442 | return 0; | |
2ad9852d | 14443 | |
64b59a80 | 14444 | return 1; |
fcd7f76b JM |
14445 | } |
14446 | ||
d5688810 GK |
14447 | /* Hash table routines for file_hash. */ |
14448 | ||
14449 | static int | |
14450 | file_table_eq (const void *p1_p, const void *p2_p) | |
14451 | { | |
1b4572a8 KG |
14452 | const struct dwarf_file_data *const p1 = |
14453 | (const struct dwarf_file_data *) p1_p; | |
14454 | const char *const p2 = (const char *) p2_p; | |
d5688810 GK |
14455 | return strcmp (p1->filename, p2) == 0; |
14456 | } | |
14457 | ||
14458 | static hashval_t | |
14459 | file_table_hash (const void *p_p) | |
14460 | { | |
1b4572a8 | 14461 | const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p; |
d5688810 GK |
14462 | return htab_hash_string (p->filename); |
14463 | } | |
14464 | ||
2ad9852d | 14465 | /* Lookup FILE_NAME (in the list of filenames that we know about here in |
9a666dda | 14466 | dwarf2out.c) and return its "index". The index of each (known) filename is |
2ad9852d RK |
14467 | just a unique number which is associated with only that one filename. We |
14468 | need such numbers for the sake of generating labels (in the .debug_sfnames | |
14469 | section) and references to those files numbers (in the .debug_srcinfo | |
14470 | and.debug_macinfo sections). If the filename given as an argument is not | |
14471 | found in our current list, add it to the list and assign it the next | |
14472 | available unique index number. In order to speed up searches, we remember | |
14473 | the index of the filename was looked up last. This handles the majority of | |
14474 | all searches. */ | |
71dfc51f | 14475 | |
d5688810 | 14476 | static struct dwarf_file_data * |
7080f735 | 14477 | lookup_filename (const char *file_name) |
a3f97cbb | 14478 | { |
d5688810 GK |
14479 | void ** slot; |
14480 | struct dwarf_file_data * created; | |
a3f97cbb | 14481 | |
2e18bbae RH |
14482 | /* Check to see if the file name that was searched on the previous |
14483 | call matches this file name. If so, return the index. */ | |
d5688810 GK |
14484 | if (file_table_last_lookup |
14485 | && (file_name == file_table_last_lookup->filename | |
14486 | || strcmp (file_table_last_lookup->filename, file_name) == 0)) | |
14487 | return file_table_last_lookup; | |
a3f97cbb | 14488 | |
ea4b7848 | 14489 | /* Didn't match the previous lookup, search the table. */ |
d5688810 GK |
14490 | slot = htab_find_slot_with_hash (file_table, file_name, |
14491 | htab_hash_string (file_name), INSERT); | |
14492 | if (*slot) | |
1b4572a8 | 14493 | return (struct dwarf_file_data *) *slot; |
a3f97cbb | 14494 | |
1b4572a8 | 14495 | created = GGC_NEW (struct dwarf_file_data); |
d5688810 GK |
14496 | created->filename = file_name; |
14497 | created->emitted_number = 0; | |
14498 | *slot = created; | |
14499 | return created; | |
73c68f61 SS |
14500 | } |
14501 | ||
3e2844cb JW |
14502 | /* If the assembler will construct the file table, then translate the compiler |
14503 | internal file table number into the assembler file table number, and emit | |
14504 | a .file directive if we haven't already emitted one yet. The file table | |
14505 | numbers are different because we prune debug info for unused variables and | |
14506 | types, which may include filenames. */ | |
14507 | ||
73c68f61 | 14508 | static int |
d5688810 | 14509 | maybe_emit_file (struct dwarf_file_data * fd) |
73c68f61 | 14510 | { |
d5688810 | 14511 | if (! fd->emitted_number) |
211a0cbe | 14512 | { |
d5688810 GK |
14513 | if (last_emitted_file) |
14514 | fd->emitted_number = last_emitted_file->emitted_number + 1; | |
14515 | else | |
14516 | fd->emitted_number = 1; | |
14517 | last_emitted_file = fd; | |
2878ea73 | 14518 | |
d5688810 | 14519 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
73c68f61 | 14520 | { |
d5688810 | 14521 | fprintf (asm_out_file, "\t.file %u ", fd->emitted_number); |
c8aea42c PB |
14522 | output_quoted_string (asm_out_file, |
14523 | remap_debug_filename (fd->filename)); | |
73c68f61 SS |
14524 | fputc ('\n', asm_out_file); |
14525 | } | |
211a0cbe | 14526 | } |
2878ea73 | 14527 | |
d5688810 | 14528 | return fd->emitted_number; |
a3f97cbb JW |
14529 | } |
14530 | ||
0a2d3d69 DB |
14531 | /* Called by the final INSN scan whenever we see a var location. We |
14532 | use it to drop labels in the right places, and throw the location in | |
14533 | our lookup table. */ | |
14534 | ||
14535 | static void | |
14536 | dwarf2out_var_location (rtx loc_note) | |
14537 | { | |
14538 | char loclabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
14539 | struct var_loc_node *newloc; | |
14540 | rtx prev_insn; | |
14541 | static rtx last_insn; | |
14542 | static const char *last_label; | |
ac3bfd86 | 14543 | tree decl; |
0a2d3d69 DB |
14544 | |
14545 | if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note))) | |
14546 | return; | |
14547 | prev_insn = PREV_INSN (loc_note); | |
14548 | ||
1b4572a8 | 14549 | newloc = GGC_CNEW (struct var_loc_node); |
0a2d3d69 DB |
14550 | /* If the insn we processed last time is the previous insn |
14551 | and it is also a var location note, use the label we emitted | |
14552 | last time. */ | |
14553 | if (last_insn != NULL_RTX | |
14554 | && last_insn == prev_insn | |
4b4bf941 | 14555 | && NOTE_P (prev_insn) |
a38e7aa5 | 14556 | && NOTE_KIND (prev_insn) == NOTE_INSN_VAR_LOCATION) |
0a2d3d69 DB |
14557 | { |
14558 | newloc->label = last_label; | |
14559 | } | |
14560 | else | |
14561 | { | |
14562 | ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num); | |
14563 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num); | |
14564 | loclabel_num++; | |
14565 | newloc->label = ggc_strdup (loclabel); | |
14566 | } | |
14567 | newloc->var_loc_note = loc_note; | |
14568 | newloc->next = NULL; | |
14569 | ||
c543ca49 | 14570 | if (cfun && in_cold_section_p) |
38173d38 | 14571 | newloc->section_label = crtl->subsections.cold_section_label; |
87c8b4be CT |
14572 | else |
14573 | newloc->section_label = text_section_label; | |
14574 | ||
0a2d3d69 DB |
14575 | last_insn = loc_note; |
14576 | last_label = newloc->label; | |
ac3bfd86 | 14577 | decl = NOTE_VAR_LOCATION_DECL (loc_note); |
ac3bfd86 | 14578 | add_var_loc_to_decl (decl, newloc); |
0a2d3d69 DB |
14579 | } |
14580 | ||
14581 | /* We need to reset the locations at the beginning of each | |
14582 | function. We can't do this in the end_function hook, because the | |
1146e682 GK |
14583 | declarations that use the locations won't have been output when |
14584 | that hook is called. Also compute have_multiple_function_sections here. */ | |
0a2d3d69 DB |
14585 | |
14586 | static void | |
1146e682 | 14587 | dwarf2out_begin_function (tree fun) |
0a2d3d69 DB |
14588 | { |
14589 | htab_empty (decl_loc_table); | |
2878ea73 | 14590 | |
1146e682 GK |
14591 | if (function_section (fun) != text_section) |
14592 | have_multiple_function_sections = true; | |
9e9f8522 JM |
14593 | |
14594 | dwarf2out_note_section_used (); | |
0a2d3d69 DB |
14595 | } |
14596 | ||
a3f97cbb JW |
14597 | /* Output a label to mark the beginning of a source code line entry |
14598 | and record information relating to this source line, in | |
14599 | 'line_info_table' for later output of the .debug_line section. */ | |
71dfc51f | 14600 | |
e2a12aca | 14601 | static void |
7080f735 | 14602 | dwarf2out_source_line (unsigned int line, const char *filename) |
a3f97cbb | 14603 | { |
7bf6b23d JM |
14604 | if (debug_info_level >= DINFO_LEVEL_NORMAL |
14605 | && line != 0) | |
a3f97cbb | 14606 | { |
d5688810 | 14607 | int file_num = maybe_emit_file (lookup_filename (filename)); |
2878ea73 | 14608 | |
d6b5193b | 14609 | switch_to_section (current_function_section ()); |
a3f97cbb | 14610 | |
8aaf55ac JM |
14611 | /* If requested, emit something human-readable. */ |
14612 | if (flag_debug_asm) | |
14613 | fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, | |
14614 | filename, line); | |
14615 | ||
b2244e22 JW |
14616 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
14617 | { | |
981975b6 | 14618 | /* Emit the .loc directive understood by GNU as. */ |
2e18bbae | 14619 | fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line); |
b2244e22 JW |
14620 | |
14621 | /* Indicate that line number info exists. */ | |
2ad9852d | 14622 | line_info_table_in_use++; |
b2244e22 | 14623 | } |
1146e682 | 14624 | else if (function_section (current_function_decl) != text_section) |
a3f97cbb | 14625 | { |
b3694847 | 14626 | dw_separate_line_info_ref line_info; |
2878ea73 | 14627 | targetm.asm_out.internal_label (asm_out_file, |
d5688810 GK |
14628 | SEPARATE_LINE_CODE_LABEL, |
14629 | separate_line_info_table_in_use); | |
e90b62db | 14630 | |
a1105617 | 14631 | /* Expand the line info table if necessary. */ |
e90b62db JM |
14632 | if (separate_line_info_table_in_use |
14633 | == separate_line_info_table_allocated) | |
14634 | { | |
14635 | separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
14636 | separate_line_info_table | |
1b4572a8 KG |
14637 | = GGC_RESIZEVEC (dw_separate_line_info_entry, |
14638 | separate_line_info_table, | |
14639 | separate_line_info_table_allocated); | |
703ad42b KG |
14640 | memset (separate_line_info_table |
14641 | + separate_line_info_table_in_use, | |
17211ab5 | 14642 | 0, |
7080f735 | 14643 | (LINE_INFO_TABLE_INCREMENT |
17211ab5 | 14644 | * sizeof (dw_separate_line_info_entry))); |
e90b62db | 14645 | } |
71dfc51f RK |
14646 | |
14647 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
14648 | line_info |
14649 | = &separate_line_info_table[separate_line_info_table_in_use++]; | |
d5688810 | 14650 | line_info->dw_file_num = file_num; |
e90b62db | 14651 | line_info->dw_line_num = line; |
df696a75 | 14652 | line_info->function = current_function_funcdef_no; |
e90b62db JM |
14653 | } |
14654 | else | |
14655 | { | |
b3694847 | 14656 | dw_line_info_ref line_info; |
71dfc51f | 14657 | |
5fd9b178 | 14658 | targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, |
5c90448c | 14659 | line_info_table_in_use); |
e90b62db | 14660 | |
71dfc51f | 14661 | /* Expand the line info table if necessary. */ |
e90b62db JM |
14662 | if (line_info_table_in_use == line_info_table_allocated) |
14663 | { | |
14664 | line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
14665 | line_info_table | |
1b4572a8 KG |
14666 | = GGC_RESIZEVEC (dw_line_info_entry, line_info_table, |
14667 | line_info_table_allocated); | |
17211ab5 GK |
14668 | memset (line_info_table + line_info_table_in_use, 0, |
14669 | LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry)); | |
e90b62db | 14670 | } |
71dfc51f RK |
14671 | |
14672 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db | 14673 | line_info = &line_info_table[line_info_table_in_use++]; |
d5688810 | 14674 | line_info->dw_file_num = file_num; |
e90b62db | 14675 | line_info->dw_line_num = line; |
a3f97cbb | 14676 | } |
a3f97cbb JW |
14677 | } |
14678 | } | |
14679 | ||
30f7a378 | 14680 | /* Record the beginning of a new source file. */ |
71dfc51f | 14681 | |
7f905405 | 14682 | static void |
7080f735 | 14683 | dwarf2out_start_source_file (unsigned int lineno, const char *filename) |
a3f97cbb | 14684 | { |
8a7a6f4d | 14685 | if (flag_eliminate_dwarf2_dups) |
881c6935 JM |
14686 | { |
14687 | /* Record the beginning of the file for break_out_includes. */ | |
cc0017a9 ZD |
14688 | dw_die_ref bincl_die; |
14689 | ||
14690 | bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL); | |
c8aea42c | 14691 | add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename)); |
881c6935 | 14692 | } |
2ad9852d | 14693 | |
84a5b4f8 DB |
14694 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
14695 | { | |
d5688810 | 14696 | int file_num = maybe_emit_file (lookup_filename (filename)); |
5597a350 | 14697 | |
d6b5193b | 14698 | switch_to_section (debug_macinfo_section); |
84a5b4f8 | 14699 | dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file"); |
7c262518 RH |
14700 | dw2_asm_output_data_uleb128 (lineno, "Included from line number %d", |
14701 | lineno); | |
5597a350 | 14702 | |
d5688810 | 14703 | dw2_asm_output_data_uleb128 (file_num, "file %s", filename); |
84a5b4f8 | 14704 | } |
a3f97cbb JW |
14705 | } |
14706 | ||
cc260610 | 14707 | /* Record the end of a source file. */ |
71dfc51f | 14708 | |
7f905405 | 14709 | static void |
7080f735 | 14710 | dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED) |
a3f97cbb | 14711 | { |
881c6935 | 14712 | if (flag_eliminate_dwarf2_dups) |
2ad9852d | 14713 | /* Record the end of the file for break_out_includes. */ |
54ba1f0d | 14714 | new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL); |
2ad9852d | 14715 | |
84a5b4f8 DB |
14716 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
14717 | { | |
d6b5193b | 14718 | switch_to_section (debug_macinfo_section); |
84a5b4f8 DB |
14719 | dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); |
14720 | } | |
a3f97cbb JW |
14721 | } |
14722 | ||
cc260610 | 14723 | /* Called from debug_define in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
14724 | the tail part of the directive line, i.e. the part which is past the |
14725 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 14726 | |
7f905405 | 14727 | static void |
7080f735 AJ |
14728 | dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED, |
14729 | const char *buffer ATTRIBUTE_UNUSED) | |
a3f97cbb | 14730 | { |
84a5b4f8 DB |
14731 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
14732 | { | |
d6b5193b | 14733 | switch_to_section (debug_macinfo_section); |
84a5b4f8 DB |
14734 | dw2_asm_output_data (1, DW_MACINFO_define, "Define macro"); |
14735 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
14736 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
14737 | } | |
a3f97cbb JW |
14738 | } |
14739 | ||
cc260610 | 14740 | /* Called from debug_undef in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
14741 | the tail part of the directive line, i.e. the part which is past the |
14742 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 14743 | |
7f905405 | 14744 | static void |
7080f735 AJ |
14745 | dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED, |
14746 | const char *buffer ATTRIBUTE_UNUSED) | |
a3f97cbb | 14747 | { |
84a5b4f8 DB |
14748 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
14749 | { | |
d6b5193b | 14750 | switch_to_section (debug_macinfo_section); |
84a5b4f8 DB |
14751 | dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro"); |
14752 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
14753 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
14754 | } | |
a3f97cbb JW |
14755 | } |
14756 | ||
14757 | /* Set up for Dwarf output at the start of compilation. */ | |
71dfc51f | 14758 | |
a51d908e | 14759 | static void |
7080f735 | 14760 | dwarf2out_init (const char *filename ATTRIBUTE_UNUSED) |
a3f97cbb | 14761 | { |
d5688810 GK |
14762 | /* Allocate the file_table. */ |
14763 | file_table = htab_create_ggc (50, file_table_hash, | |
14764 | file_table_eq, NULL); | |
acc187f5 | 14765 | |
0a2d3d69 | 14766 | /* Allocate the decl_die_table. */ |
636c7bc4 JZ |
14767 | decl_die_table = htab_create_ggc (10, decl_die_table_hash, |
14768 | decl_die_table_eq, NULL); | |
0a2d3d69 DB |
14769 | |
14770 | /* Allocate the decl_loc_table. */ | |
14771 | decl_loc_table = htab_create_ggc (10, decl_loc_table_hash, | |
14772 | decl_loc_table_eq, NULL); | |
a3f97cbb JW |
14773 | |
14774 | /* Allocate the initial hunk of the decl_scope_table. */ | |
0fdc587b | 14775 | decl_scope_table = VEC_alloc (tree, gc, 256); |
a3f97cbb JW |
14776 | |
14777 | /* Allocate the initial hunk of the abbrev_die_table. */ | |
1b4572a8 | 14778 | abbrev_die_table = GGC_CNEWVEC (dw_die_ref, ABBREV_DIE_TABLE_INCREMENT); |
a3f97cbb | 14779 | abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT; |
ea4b7848 | 14780 | /* Zero-th entry is allocated, but unused. */ |
a3f97cbb JW |
14781 | abbrev_die_table_in_use = 1; |
14782 | ||
14783 | /* Allocate the initial hunk of the line_info_table. */ | |
1b4572a8 | 14784 | line_info_table = GGC_CNEWVEC (dw_line_info_entry, LINE_INFO_TABLE_INCREMENT); |
a3f97cbb | 14785 | line_info_table_allocated = LINE_INFO_TABLE_INCREMENT; |
2ad9852d | 14786 | |
ea4b7848 | 14787 | /* Zero-th entry is allocated, but unused. */ |
a3f97cbb JW |
14788 | line_info_table_in_use = 1; |
14789 | ||
89708594 CT |
14790 | /* Allocate the pubtypes and pubnames vectors. */ |
14791 | pubname_table = VEC_alloc (pubname_entry, gc, 32); | |
14792 | pubtype_table = VEC_alloc (pubname_entry, gc, 32); | |
14793 | ||
556273e0 | 14794 | /* Generate the initial DIE for the .debug section. Note that the (string) |
a3f97cbb | 14795 | value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE |
556273e0 | 14796 | will (typically) be a relative pathname and that this pathname should be |
a3f97cbb | 14797 | taken as being relative to the directory from which the compiler was |
c4274b22 RH |
14798 | invoked when the given (base) source file was compiled. We will fill |
14799 | in this value in dwarf2out_finish. */ | |
14800 | comp_unit_die = gen_compile_unit_die (NULL); | |
a3f97cbb | 14801 | |
887fb69b | 14802 | incomplete_types = VEC_alloc (tree, gc, 64); |
244a4af0 | 14803 | |
a1bbd445 | 14804 | used_rtx_array = VEC_alloc (rtx, gc, 32); |
1865dbb5 | 14805 | |
d6b5193b RS |
14806 | debug_info_section = get_section (DEBUG_INFO_SECTION, |
14807 | SECTION_DEBUG, NULL); | |
14808 | debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION, | |
14809 | SECTION_DEBUG, NULL); | |
14810 | debug_aranges_section = get_section (DEBUG_ARANGES_SECTION, | |
14811 | SECTION_DEBUG, NULL); | |
14812 | debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION, | |
14813 | SECTION_DEBUG, NULL); | |
14814 | debug_line_section = get_section (DEBUG_LINE_SECTION, | |
14815 | SECTION_DEBUG, NULL); | |
14816 | debug_loc_section = get_section (DEBUG_LOC_SECTION, | |
14817 | SECTION_DEBUG, NULL); | |
14818 | debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION, | |
14819 | SECTION_DEBUG, NULL); | |
89708594 CT |
14820 | #ifdef DEBUG_PUBTYPES_SECTION |
14821 | debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION, | |
14822 | SECTION_DEBUG, NULL); | |
14823 | #endif | |
d6b5193b RS |
14824 | debug_str_section = get_section (DEBUG_STR_SECTION, |
14825 | DEBUG_STR_SECTION_FLAGS, NULL); | |
14826 | debug_ranges_section = get_section (DEBUG_RANGES_SECTION, | |
14827 | SECTION_DEBUG, NULL); | |
192d0f89 GK |
14828 | debug_frame_section = get_section (DEBUG_FRAME_SECTION, |
14829 | SECTION_DEBUG, NULL); | |
d6b5193b | 14830 | |
5c90448c | 14831 | ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0); |
9d2f2c45 RH |
14832 | ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, |
14833 | DEBUG_ABBREV_SECTION_LABEL, 0); | |
9e749a8b | 14834 | ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0); |
2878ea73 | 14835 | ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label, |
c7466dee CT |
14836 | COLD_TEXT_SECTION_LABEL, 0); |
14837 | ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0); | |
2ad9852d | 14838 | |
556273e0 | 14839 | ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label, |
8b790721 | 14840 | DEBUG_INFO_SECTION_LABEL, 0); |
556273e0 | 14841 | ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label, |
8b790721 | 14842 | DEBUG_LINE_SECTION_LABEL, 0); |
2bee6045 JJ |
14843 | ASM_GENERATE_INTERNAL_LABEL (ranges_section_label, |
14844 | DEBUG_RANGES_SECTION_LABEL, 0); | |
d6b5193b | 14845 | switch_to_section (debug_abbrev_section); |
8b790721 | 14846 | ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label); |
d6b5193b | 14847 | switch_to_section (debug_info_section); |
8b790721 | 14848 | ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label); |
d6b5193b | 14849 | switch_to_section (debug_line_section); |
8b790721 | 14850 | ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label); |
2ad9852d | 14851 | |
84a5b4f8 DB |
14852 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
14853 | { | |
d6b5193b | 14854 | switch_to_section (debug_macinfo_section); |
84a5b4f8 DB |
14855 | ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label, |
14856 | DEBUG_MACINFO_SECTION_LABEL, 0); | |
14857 | ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label); | |
14858 | } | |
7c262518 | 14859 | |
d6b5193b | 14860 | switch_to_section (text_section); |
9e749a8b | 14861 | ASM_OUTPUT_LABEL (asm_out_file, text_section_label); |
c7466dee CT |
14862 | if (flag_reorder_blocks_and_partition) |
14863 | { | |
9e9f8522 JM |
14864 | cold_text_section = unlikely_text_section (); |
14865 | switch_to_section (cold_text_section); | |
c7466dee CT |
14866 | ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label); |
14867 | } | |
a3f97cbb JW |
14868 | } |
14869 | ||
9eb4015a JJ |
14870 | /* A helper function for dwarf2out_finish called through |
14871 | ht_forall. Emit one queued .debug_str string. */ | |
14872 | ||
14873 | static int | |
7080f735 | 14874 | output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED) |
9eb4015a | 14875 | { |
17211ab5 | 14876 | struct indirect_string_node *node = (struct indirect_string_node *) *h; |
9eb4015a | 14877 | |
9eb4015a JJ |
14878 | if (node->form == DW_FORM_strp) |
14879 | { | |
d6b5193b | 14880 | switch_to_section (debug_str_section); |
9eb4015a | 14881 | ASM_OUTPUT_LABEL (asm_out_file, node->label); |
17211ab5 | 14882 | assemble_string (node->str, strlen (node->str) + 1); |
9eb4015a | 14883 | } |
2ad9852d | 14884 | |
9eb4015a JJ |
14885 | return 1; |
14886 | } | |
14887 | ||
6f8d8ef0 GK |
14888 | #if ENABLE_ASSERT_CHECKING |
14889 | /* Verify that all marks are clear. */ | |
73c68f61 | 14890 | |
6f8d8ef0 GK |
14891 | static void |
14892 | verify_marks_clear (dw_die_ref die) | |
14893 | { | |
14894 | dw_die_ref c; | |
2878ea73 | 14895 | |
6f8d8ef0 GK |
14896 | gcc_assert (! die->die_mark); |
14897 | FOR_EACH_CHILD (die, c, verify_marks_clear (c)); | |
14898 | } | |
14899 | #endif /* ENABLE_ASSERT_CHECKING */ | |
73c68f61 SS |
14900 | |
14901 | /* Clear the marks for a die and its children. | |
3dc575ff | 14902 | Be cool if the mark isn't set. */ |
73c68f61 SS |
14903 | |
14904 | static void | |
7080f735 | 14905 | prune_unmark_dies (dw_die_ref die) |
73c68f61 SS |
14906 | { |
14907 | dw_die_ref c; | |
2878ea73 | 14908 | |
d6eeb3ba GK |
14909 | if (die->die_mark) |
14910 | die->die_mark = 0; | |
14911 | FOR_EACH_CHILD (die, c, prune_unmark_dies (c)); | |
73c68f61 SS |
14912 | } |
14913 | ||
73c68f61 SS |
14914 | /* Given DIE that we're marking as used, find any other dies |
14915 | it references as attributes and mark them as used. */ | |
14916 | ||
14917 | static void | |
7080f735 | 14918 | prune_unused_types_walk_attribs (dw_die_ref die) |
73c68f61 SS |
14919 | { |
14920 | dw_attr_ref a; | |
1a27722f | 14921 | unsigned ix; |
73c68f61 | 14922 | |
1a27722f | 14923 | for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++) |
73c68f61 SS |
14924 | { |
14925 | if (a->dw_attr_val.val_class == dw_val_class_die_ref) | |
14926 | { | |
14927 | /* A reference to another DIE. | |
14928 | Make sure that it will get emitted. */ | |
14929 | prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1); | |
14930 | } | |
e26303c2 GK |
14931 | /* Set the string's refcount to 0 so that prune_unused_types_mark |
14932 | accounts properly for it. */ | |
14933 | if (AT_class (a) == dw_val_class_str) | |
14934 | a->dw_attr_val.v.val_str->refcount = 0; | |
73c68f61 SS |
14935 | } |
14936 | } | |
14937 | ||
14938 | ||
14939 | /* Mark DIE as being used. If DOKIDS is true, then walk down | |
14940 | to DIE's children. */ | |
14941 | ||
14942 | static void | |
7080f735 | 14943 | prune_unused_types_mark (dw_die_ref die, int dokids) |
73c68f61 SS |
14944 | { |
14945 | dw_die_ref c; | |
14946 | ||
14947 | if (die->die_mark == 0) | |
14948 | { | |
14949 | /* We haven't done this node yet. Mark it as used. */ | |
14950 | die->die_mark = 1; | |
14951 | ||
14952 | /* We also have to mark its parents as used. | |
14953 | (But we don't want to mark our parents' kids due to this.) */ | |
14954 | if (die->die_parent) | |
14955 | prune_unused_types_mark (die->die_parent, 0); | |
14956 | ||
14957 | /* Mark any referenced nodes. */ | |
14958 | prune_unused_types_walk_attribs (die); | |
47fcfa7b SS |
14959 | |
14960 | /* If this node is a specification, | |
2878ea73 | 14961 | also mark the definition, if it exists. */ |
47fcfa7b | 14962 | if (get_AT_flag (die, DW_AT_declaration) && die->die_definition) |
2878ea73 | 14963 | prune_unused_types_mark (die->die_definition, 1); |
73c68f61 SS |
14964 | } |
14965 | ||
14966 | if (dokids && die->die_mark != 2) | |
14967 | { | |
14968 | /* We need to walk the children, but haven't done so yet. | |
14969 | Remember that we've walked the kids. */ | |
14970 | die->die_mark = 2; | |
14971 | ||
d6eeb3ba GK |
14972 | /* If this is an array type, we need to make sure our |
14973 | kids get marked, even if they're types. */ | |
14974 | if (die->die_tag == DW_TAG_array_type) | |
14975 | FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1)); | |
14976 | else | |
14977 | FOR_EACH_CHILD (die, c, prune_unused_types_walk (c)); | |
73c68f61 SS |
14978 | } |
14979 | } | |
14980 | ||
14981 | ||
14982 | /* Walk the tree DIE and mark types that we actually use. */ | |
14983 | ||
14984 | static void | |
7080f735 | 14985 | prune_unused_types_walk (dw_die_ref die) |
73c68f61 SS |
14986 | { |
14987 | dw_die_ref c; | |
14988 | ||
14989 | /* Don't do anything if this node is already marked. */ | |
14990 | if (die->die_mark) | |
14991 | return; | |
14992 | ||
428aba16 RS |
14993 | switch (die->die_tag) |
14994 | { | |
14995 | case DW_TAG_const_type: | |
14996 | case DW_TAG_packed_type: | |
14997 | case DW_TAG_pointer_type: | |
14998 | case DW_TAG_reference_type: | |
14999 | case DW_TAG_volatile_type: | |
15000 | case DW_TAG_typedef: | |
15001 | case DW_TAG_array_type: | |
15002 | case DW_TAG_structure_type: | |
15003 | case DW_TAG_union_type: | |
15004 | case DW_TAG_class_type: | |
394d9fe7 | 15005 | case DW_TAG_interface_type: |
428aba16 RS |
15006 | case DW_TAG_friend: |
15007 | case DW_TAG_variant_part: | |
15008 | case DW_TAG_enumeration_type: | |
15009 | case DW_TAG_subroutine_type: | |
15010 | case DW_TAG_string_type: | |
15011 | case DW_TAG_set_type: | |
15012 | case DW_TAG_subrange_type: | |
15013 | case DW_TAG_ptr_to_member_type: | |
15014 | case DW_TAG_file_type: | |
15015 | if (die->die_perennial_p) | |
15016 | break; | |
33c9159e | 15017 | |
428aba16 RS |
15018 | /* It's a type node --- don't mark it. */ |
15019 | return; | |
73c68f61 | 15020 | |
428aba16 RS |
15021 | default: |
15022 | /* Mark everything else. */ | |
15023 | break; | |
73c68f61 SS |
15024 | } |
15025 | ||
15026 | die->die_mark = 1; | |
15027 | ||
15028 | /* Now, mark any dies referenced from here. */ | |
15029 | prune_unused_types_walk_attribs (die); | |
15030 | ||
15031 | /* Mark children. */ | |
d6eeb3ba | 15032 | FOR_EACH_CHILD (die, c, prune_unused_types_walk (c)); |
73c68f61 SS |
15033 | } |
15034 | ||
e26303c2 GK |
15035 | /* Increment the string counts on strings referred to from DIE's |
15036 | attributes. */ | |
15037 | ||
15038 | static void | |
15039 | prune_unused_types_update_strings (dw_die_ref die) | |
15040 | { | |
15041 | dw_attr_ref a; | |
15042 | unsigned ix; | |
15043 | ||
15044 | for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++) | |
15045 | if (AT_class (a) == dw_val_class_str) | |
15046 | { | |
15047 | struct indirect_string_node *s = a->dw_attr_val.v.val_str; | |
15048 | s->refcount++; | |
15049 | /* Avoid unnecessarily putting strings that are used less than | |
15050 | twice in the hash table. */ | |
76f7a74f GK |
15051 | if (s->refcount |
15052 | == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2)) | |
e26303c2 GK |
15053 | { |
15054 | void ** slot; | |
15055 | slot = htab_find_slot_with_hash (debug_str_hash, s->str, | |
15056 | htab_hash_string (s->str), | |
15057 | INSERT); | |
15058 | gcc_assert (*slot == NULL); | |
15059 | *slot = s; | |
15060 | } | |
15061 | } | |
15062 | } | |
73c68f61 SS |
15063 | |
15064 | /* Remove from the tree DIE any dies that aren't marked. */ | |
15065 | ||
15066 | static void | |
7080f735 | 15067 | prune_unused_types_prune (dw_die_ref die) |
73c68f61 | 15068 | { |
d6eeb3ba | 15069 | dw_die_ref c; |
a1c496cb | 15070 | |
ced3f397 | 15071 | gcc_assert (die->die_mark); |
19450f2b | 15072 | prune_unused_types_update_strings (die); |
73c68f61 | 15073 | |
d6eeb3ba GK |
15074 | if (! die->die_child) |
15075 | return; | |
2878ea73 | 15076 | |
d6eeb3ba GK |
15077 | c = die->die_child; |
15078 | do { | |
15079 | dw_die_ref prev = c; | |
15080 | for (c = c->die_sib; ! c->die_mark; c = c->die_sib) | |
15081 | if (c == die->die_child) | |
73c68f61 | 15082 | { |
d6eeb3ba GK |
15083 | /* No marked children between 'prev' and the end of the list. */ |
15084 | if (prev == c) | |
15085 | /* No marked children at all. */ | |
15086 | die->die_child = NULL; | |
15087 | else | |
15088 | { | |
15089 | prev->die_sib = c->die_sib; | |
15090 | die->die_child = prev; | |
15091 | } | |
15092 | return; | |
73c68f61 | 15093 | } |
d6eeb3ba GK |
15094 | |
15095 | if (c != prev->die_sib) | |
15096 | prev->die_sib = c; | |
d6eeb3ba GK |
15097 | prune_unused_types_prune (c); |
15098 | } while (c != die->die_child); | |
73c68f61 SS |
15099 | } |
15100 | ||
15101 | ||
15102 | /* Remove dies representing declarations that we never use. */ | |
15103 | ||
15104 | static void | |
7080f735 | 15105 | prune_unused_types (void) |
73c68f61 SS |
15106 | { |
15107 | unsigned int i; | |
15108 | limbo_die_node *node; | |
89708594 | 15109 | pubname_ref pub; |
73c68f61 | 15110 | |
6f8d8ef0 GK |
15111 | #if ENABLE_ASSERT_CHECKING |
15112 | /* All the marks should already be clear. */ | |
15113 | verify_marks_clear (comp_unit_die); | |
73c68f61 | 15114 | for (node = limbo_die_list; node; node = node->next) |
6f8d8ef0 GK |
15115 | verify_marks_clear (node->die); |
15116 | #endif /* ENABLE_ASSERT_CHECKING */ | |
73c68f61 SS |
15117 | |
15118 | /* Set the mark on nodes that are actually used. */ | |
15119 | prune_unused_types_walk (comp_unit_die); | |
15120 | for (node = limbo_die_list; node; node = node->next) | |
15121 | prune_unused_types_walk (node->die); | |
15122 | ||
15123 | /* Also set the mark on nodes referenced from the | |
15124 | pubname_table or arange_table. */ | |
89708594 CT |
15125 | for (i = 0; VEC_iterate (pubname_entry, pubname_table, i, pub); i++) |
15126 | prune_unused_types_mark (pub->die, 1); | |
6a87d634 RS |
15127 | for (i = 0; i < arange_table_in_use; i++) |
15128 | prune_unused_types_mark (arange_table[i], 1); | |
73c68f61 | 15129 | |
e26303c2 GK |
15130 | /* Get rid of nodes that aren't marked; and update the string counts. */ |
15131 | if (debug_str_hash) | |
15132 | htab_empty (debug_str_hash); | |
73c68f61 SS |
15133 | prune_unused_types_prune (comp_unit_die); |
15134 | for (node = limbo_die_list; node; node = node->next) | |
15135 | prune_unused_types_prune (node->die); | |
15136 | ||
15137 | /* Leave the marks clear. */ | |
15138 | prune_unmark_dies (comp_unit_die); | |
15139 | for (node = limbo_die_list; node; node = node->next) | |
15140 | prune_unmark_dies (node->die); | |
15141 | } | |
15142 | ||
d5688810 GK |
15143 | /* Set the parameter to true if there are any relative pathnames in |
15144 | the file table. */ | |
15145 | static int | |
15146 | file_table_relative_p (void ** slot, void *param) | |
15147 | { | |
1b4572a8 KG |
15148 | bool *p = (bool *) param; |
15149 | struct dwarf_file_data *d = (struct dwarf_file_data *) *slot; | |
c8aea42c | 15150 | if (!IS_ABSOLUTE_PATH (d->filename)) |
d5688810 GK |
15151 | { |
15152 | *p = true; | |
15153 | return 0; | |
15154 | } | |
15155 | return 1; | |
15156 | } | |
15157 | ||
a3f97cbb JW |
15158 | /* Output stuff that dwarf requires at the end of every file, |
15159 | and generate the DWARF-2 debugging info. */ | |
71dfc51f | 15160 | |
a51d908e | 15161 | static void |
7080f735 | 15162 | dwarf2out_finish (const char *filename) |
a3f97cbb | 15163 | { |
ef76d03b | 15164 | limbo_die_node *node, *next_node; |
ae0ed63a | 15165 | dw_die_ref die = 0; |
ef76d03b | 15166 | |
c4274b22 RH |
15167 | /* Add the name for the main input file now. We delayed this from |
15168 | dwarf2out_init to avoid complications with PCH. */ | |
c8aea42c | 15169 | add_name_attribute (comp_unit_die, remap_debug_filename (filename)); |
1d2c2b96 | 15170 | if (!IS_ABSOLUTE_PATH (filename)) |
c4274b22 | 15171 | add_comp_dir_attribute (comp_unit_die); |
79c758fb JJ |
15172 | else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL) |
15173 | { | |
d5688810 GK |
15174 | bool p = false; |
15175 | htab_traverse (file_table, file_table_relative_p, &p); | |
15176 | if (p) | |
15177 | add_comp_dir_attribute (comp_unit_die); | |
79c758fb | 15178 | } |
c4274b22 | 15179 | |
ef76d03b JW |
15180 | /* Traverse the limbo die list, and add parent/child links. The only |
15181 | dies without parents that should be here are concrete instances of | |
15182 | inline functions, and the comp_unit_die. We can ignore the comp_unit_die. | |
15183 | For concrete instances, we can get the parent die from the abstract | |
15184 | instance. */ | |
15185 | for (node = limbo_die_list; node; node = next_node) | |
15186 | { | |
15187 | next_node = node->next; | |
15188 | die = node->die; | |
15189 | ||
15190 | if (die->die_parent == NULL) | |
15191 | { | |
a96c67ec | 15192 | dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin); |
2ad9852d | 15193 | |
a96c67ec JM |
15194 | if (origin) |
15195 | add_child_die (origin->die_parent, die); | |
ef76d03b | 15196 | else if (die == comp_unit_die) |
a96c67ec | 15197 | ; |
6bb28965 JM |
15198 | else if (errorcount > 0 || sorrycount > 0) |
15199 | /* It's OK to be confused by errors in the input. */ | |
15200 | add_child_die (comp_unit_die, die); | |
ced3f397 | 15201 | else |
54ba1f0d RH |
15202 | { |
15203 | /* In certain situations, the lexical block containing a | |
15204 | nested function can be optimized away, which results | |
15205 | in the nested function die being orphaned. Likewise | |
15206 | with the return type of that nested function. Force | |
60108d34 JH |
15207 | this to be a child of the containing function. |
15208 | ||
15209 | It may happen that even the containing function got fully | |
15210 | inlined and optimized out. In that case we are lost and | |
15211 | assign the empty child. This should not be big issue as | |
15212 | the function is likely unreachable too. */ | |
ced3f397 NS |
15213 | tree context = NULL_TREE; |
15214 | ||
15215 | gcc_assert (node->created_for); | |
15216 | ||
15217 | if (DECL_P (node->created_for)) | |
15218 | context = DECL_CONTEXT (node->created_for); | |
15219 | else if (TYPE_P (node->created_for)) | |
15220 | context = TYPE_CONTEXT (node->created_for); | |
a1c496cb | 15221 | |
db9e0d2a AO |
15222 | gcc_assert (context |
15223 | && (TREE_CODE (context) == FUNCTION_DECL | |
15224 | || TREE_CODE (context) == NAMESPACE_DECL)); | |
a1c496cb | 15225 | |
54ba1f0d | 15226 | origin = lookup_decl_die (context); |
60108d34 JH |
15227 | if (origin) |
15228 | add_child_die (origin, die); | |
1168d30f JH |
15229 | else |
15230 | add_child_die (comp_unit_die, die); | |
54ba1f0d | 15231 | } |
ef76d03b | 15232 | } |
ef76d03b | 15233 | } |
2ad9852d | 15234 | |
a96c67ec | 15235 | limbo_die_list = NULL; |
ef76d03b | 15236 | |
8a8c3656 JM |
15237 | /* Walk through the list of incomplete types again, trying once more to |
15238 | emit full debugging info for them. */ | |
15239 | retry_incomplete_types (); | |
15240 | ||
03275f81 ZD |
15241 | if (flag_eliminate_unused_debug_types) |
15242 | prune_unused_types (); | |
15243 | ||
881c6935 JM |
15244 | /* Generate separate CUs for each of the include files we've seen. |
15245 | They will go into limbo_die_list. */ | |
5f632b5e JM |
15246 | if (flag_eliminate_dwarf2_dups) |
15247 | break_out_includes (comp_unit_die); | |
881c6935 JM |
15248 | |
15249 | /* Traverse the DIE's and add add sibling attributes to those DIE's | |
15250 | that have children. */ | |
a3f97cbb | 15251 | add_sibling_attributes (comp_unit_die); |
881c6935 JM |
15252 | for (node = limbo_die_list; node; node = node->next) |
15253 | add_sibling_attributes (node->die); | |
a3f97cbb JW |
15254 | |
15255 | /* Output a terminator label for the .text section. */ | |
d6b5193b | 15256 | switch_to_section (text_section); |
5fd9b178 | 15257 | targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0); |
c7466dee CT |
15258 | if (flag_reorder_blocks_and_partition) |
15259 | { | |
c543ca49 | 15260 | switch_to_section (unlikely_text_section ()); |
c7466dee CT |
15261 | targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0); |
15262 | } | |
a3f97cbb | 15263 | |
db3c0315 MM |
15264 | /* We can only use the low/high_pc attributes if all of the code was |
15265 | in .text. */ | |
1146e682 | 15266 | if (!have_multiple_function_sections) |
db3c0315 MM |
15267 | { |
15268 | add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label); | |
15269 | add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label); | |
e90b62db | 15270 | } |
2ad9852d | 15271 | |
0435c1d5 AO |
15272 | else |
15273 | { | |
15274 | unsigned fde_idx = 0; | |
15275 | ||
15276 | /* We need to give .debug_loc and .debug_ranges an appropriate | |
15277 | "base address". Use zero so that these addresses become | |
15278 | absolute. Historically, we've emitted the unexpected | |
15279 | DW_AT_entry_pc instead of DW_AT_low_pc for this purpose. | |
15280 | Emit both to give time for other tools to adapt. */ | |
15281 | add_AT_addr (comp_unit_die, DW_AT_low_pc, const0_rtx); | |
15282 | add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx); | |
15283 | ||
15284 | add_AT_range_list (comp_unit_die, DW_AT_ranges, | |
15285 | add_ranges_by_labels (text_section_label, | |
15286 | text_end_label)); | |
15287 | if (flag_reorder_blocks_and_partition) | |
15288 | add_ranges_by_labels (cold_text_section_label, | |
15289 | cold_end_label); | |
15290 | ||
15291 | for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++) | |
15292 | { | |
15293 | dw_fde_ref fde = &fde_table[fde_idx]; | |
15294 | ||
15295 | if (fde->dw_fde_switched_sections) | |
15296 | { | |
15297 | add_ranges_by_labels (fde->dw_fde_hot_section_label, | |
15298 | fde->dw_fde_hot_section_end_label); | |
15299 | add_ranges_by_labels (fde->dw_fde_unlikely_section_label, | |
15300 | fde->dw_fde_unlikely_section_end_label); | |
15301 | } | |
15302 | else | |
15303 | add_ranges_by_labels (fde->dw_fde_begin, | |
15304 | fde->dw_fde_end); | |
15305 | } | |
15306 | ||
15307 | add_ranges (NULL); | |
15308 | } | |
e90b62db | 15309 | |
1146e682 GK |
15310 | /* Output location list section if necessary. */ |
15311 | if (have_location_lists) | |
15312 | { | |
15313 | /* Output the location lists info. */ | |
15314 | switch_to_section (debug_loc_section); | |
15315 | ASM_GENERATE_INTERNAL_LABEL (loc_section_label, | |
15316 | DEBUG_LOC_SECTION_LABEL, 0); | |
15317 | ASM_OUTPUT_LABEL (asm_out_file, loc_section_label); | |
15318 | output_location_lists (die); | |
15319 | } | |
15320 | ||
fe7cd37f | 15321 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
192d0f89 GK |
15322 | add_AT_lineptr (comp_unit_die, DW_AT_stmt_list, |
15323 | debug_line_section_label); | |
db3c0315 | 15324 | |
84a5b4f8 | 15325 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
192d0f89 | 15326 | add_AT_macptr (comp_unit_die, DW_AT_macro_info, macinfo_section_label); |
a96c67ec | 15327 | |
881c6935 JM |
15328 | /* Output all of the compilation units. We put the main one last so that |
15329 | the offsets are available to output_pubnames. */ | |
15330 | for (node = limbo_die_list; node; node = node->next) | |
cc0017a9 | 15331 | output_comp_unit (node->die, 0); |
2ad9852d | 15332 | |
cc0017a9 | 15333 | output_comp_unit (comp_unit_die, 0); |
881c6935 | 15334 | |
a3f97cbb | 15335 | /* Output the abbreviation table. */ |
d6b5193b | 15336 | switch_to_section (debug_abbrev_section); |
a3f97cbb JW |
15337 | output_abbrev_section (); |
15338 | ||
2ad9852d | 15339 | /* Output public names table if necessary. */ |
89708594 | 15340 | if (!VEC_empty (pubname_entry, pubname_table)) |
d291dd49 | 15341 | { |
d6b5193b | 15342 | switch_to_section (debug_pubnames_section); |
89708594 | 15343 | output_pubnames (pubname_table); |
d291dd49 JM |
15344 | } |
15345 | ||
89708594 CT |
15346 | #ifdef DEBUG_PUBTYPES_SECTION |
15347 | /* Output public types table if necessary. */ | |
15348 | if (!VEC_empty (pubname_entry, pubtype_table)) | |
15349 | { | |
15350 | switch_to_section (debug_pubtypes_section); | |
15351 | output_pubnames (pubtype_table); | |
15352 | } | |
15353 | #endif | |
2878ea73 | 15354 | |
2ad9852d RK |
15355 | /* Output the address range information. We only put functions in the arange |
15356 | table, so don't write it out if we don't have any. */ | |
a3f97cbb JW |
15357 | if (fde_table_in_use) |
15358 | { | |
d6b5193b | 15359 | switch_to_section (debug_aranges_section); |
a3f97cbb JW |
15360 | output_aranges (); |
15361 | } | |
a20612aa | 15362 | |
a20612aa RH |
15363 | /* Output ranges section if necessary. */ |
15364 | if (ranges_table_in_use) | |
15365 | { | |
d6b5193b | 15366 | switch_to_section (debug_ranges_section); |
2bee6045 | 15367 | ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label); |
a20612aa RH |
15368 | output_ranges (); |
15369 | } | |
15370 | ||
d5688810 GK |
15371 | /* Output the source line correspondence table. We must do this |
15372 | even if there is no line information. Otherwise, on an empty | |
15373 | translation unit, we will generate a present, but empty, | |
15374 | .debug_info section. IRIX 6.5 `nm' will then complain when | |
15375 | examining the file. This is done late so that any filenames | |
15376 | used by the debug_info section are marked as 'used'. */ | |
15377 | if (! DWARF2_ASM_LINE_DEBUG_INFO) | |
15378 | { | |
15379 | switch_to_section (debug_line_section); | |
15380 | output_line_info (); | |
15381 | } | |
15382 | ||
3c0d1020 | 15383 | /* Have to end the macro section. */ |
cc260610 | 15384 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
c26fbbca | 15385 | { |
d6b5193b | 15386 | switch_to_section (debug_macinfo_section); |
2f8d482e | 15387 | dw2_asm_output_data (1, 0, "End compilation unit"); |
cc260610 | 15388 | } |
9eb4015a | 15389 | |
2ad9852d | 15390 | /* If we emitted any DW_FORM_strp form attribute, output the string |
9eb4015a JJ |
15391 | table too. */ |
15392 | if (debug_str_hash) | |
17211ab5 | 15393 | htab_traverse (debug_str_hash, output_indirect_string, NULL); |
a3f97cbb | 15394 | } |
e2500fed GK |
15395 | #else |
15396 | ||
15397 | /* This should never be used, but its address is needed for comparisons. */ | |
15398 | const struct gcc_debug_hooks dwarf2_debug_hooks; | |
15399 | ||
15400 | #endif /* DWARF2_DEBUGGING_INFO */ | |
15401 | ||
15402 | #include "gt-dwarf2out.h" |