]>
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, |
affad9a4 | 3 | 2003, 2004 Free Software Foundation, Inc. |
e9a25f70 JL |
4 | Contributed by Gary Funck (gary@intrepid.com). |
5 | Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com). | |
469ac993 | 6 | Extensively modified by Jason Merrill (jason@cygnus.com). |
a3f97cbb | 7 | |
1322177d | 8 | This file is part of GCC. |
a3f97cbb | 9 | |
1322177d LB |
10 | GCC is free software; you can redistribute it and/or modify it under |
11 | the terms of the GNU General Public License as published by the Free | |
12 | Software Foundation; either version 2, or (at your option) any later | |
13 | version. | |
a3f97cbb | 14 | |
1322177d LB |
15 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
16 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
18 | for more details. | |
a3f97cbb JW |
19 | |
20 | You should have received a copy of the GNU General Public License | |
1322177d LB |
21 | along with GCC; see the file COPYING. If not, write to the Free |
22 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
23 | 02111-1307, USA. */ | |
a3f97cbb | 24 | |
9eb4015a | 25 | /* TODO: Emit .debug_line header even when there are no functions, since |
348bb3c7 JM |
26 | the file numbers are used by .debug_info. Alternately, leave |
27 | out locations for types and decls. | |
28 | Avoid talking about ctors and op= for PODs. | |
29 | Factor out common prologue sequences into multiple CIEs. */ | |
30 | ||
3f76745e JM |
31 | /* The first part of this file deals with the DWARF 2 frame unwind |
32 | information, which is also used by the GCC efficient exception handling | |
33 | mechanism. The second part, controlled only by an #ifdef | |
34 | DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging | |
35 | information. */ | |
36 | ||
0021b564 | 37 | #include "config.h" |
670ee920 | 38 | #include "system.h" |
4977bab6 ZW |
39 | #include "coretypes.h" |
40 | #include "tm.h" | |
a3f97cbb | 41 | #include "tree.h" |
a757585a | 42 | #include "version.h" |
a3f97cbb | 43 | #include "flags.h" |
11ad4784 | 44 | #include "real.h" |
a3f97cbb JW |
45 | #include "rtl.h" |
46 | #include "hard-reg-set.h" | |
47 | #include "regs.h" | |
48 | #include "insn-config.h" | |
49 | #include "reload.h" | |
52a11cbf | 50 | #include "function.h" |
a3f97cbb | 51 | #include "output.h" |
71dfc51f | 52 | #include "expr.h" |
e78d8e51 | 53 | #include "libfuncs.h" |
3f76745e | 54 | #include "except.h" |
a7cc7f29 | 55 | #include "dwarf2.h" |
76ead72b | 56 | #include "dwarf2out.h" |
2e4b9b8c | 57 | #include "dwarf2asm.h" |
10f0ad3d | 58 | #include "toplev.h" |
1865dbb5 | 59 | #include "varray.h" |
951a525f | 60 | #include "ggc.h" |
881c6935 | 61 | #include "md5.h" |
57bed152 | 62 | #include "tm_p.h" |
2a2b2d43 | 63 | #include "diagnostic.h" |
a51d908e | 64 | #include "debug.h" |
07c9d2eb | 65 | #include "target.h" |
3ac88239 | 66 | #include "langhooks.h" |
cc0017a9 | 67 | #include "hashtab.h" |
1bb17c21 | 68 | #include "cgraph.h" |
6097b0c3 | 69 | #include "input.h" |
a3f97cbb | 70 | |
653e276c | 71 | #ifdef DWARF2_DEBUGGING_INFO |
7080f735 | 72 | static void dwarf2out_source_line (unsigned int, const char *); |
653e276c NB |
73 | #endif |
74 | ||
770ca8c6 JO |
75 | /* DWARF2 Abbreviation Glossary: |
76 | CFA = Canonical Frame Address | |
00a42e21 JM |
77 | a fixed address on the stack which identifies a call frame. |
78 | We define it to be the value of SP just before the call insn. | |
79 | The CFA register and offset, which may change during the course | |
80 | of the function, are used to calculate its value at runtime. | |
a401107d JO |
81 | CFI = Call Frame Instruction |
82 | an instruction for the DWARF2 abstract machine | |
770ca8c6 JO |
83 | CIE = Common Information Entry |
84 | information describing information common to one or more FDEs | |
85 | DIE = Debugging Information Entry | |
86 | FDE = Frame Description Entry | |
87 | information describing the stack call frame, in particular, | |
88 | how to restore registers | |
89 | ||
90 | DW_CFA_... = DWARF2 CFA call frame instruction | |
91 | DW_TAG_... = DWARF2 DIE tag */ | |
92 | ||
0021b564 JM |
93 | /* Decide whether we want to emit frame unwind information for the current |
94 | translation unit. */ | |
95 | ||
96 | int | |
7080f735 | 97 | dwarf2out_do_frame (void) |
0021b564 JM |
98 | { |
99 | return (write_symbols == DWARF2_DEBUG | |
7a0c8d71 | 100 | || write_symbols == VMS_AND_DWARF2_DEBUG |
9ec36da5 | 101 | #ifdef DWARF2_FRAME_INFO |
556273e0 | 102 | || DWARF2_FRAME_INFO |
9ec36da5 | 103 | #endif |
0021b564 | 104 | #ifdef DWARF2_UNWIND_INFO |
14a774a9 | 105 | || flag_unwind_tables |
531073e7 | 106 | || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS) |
0021b564 JM |
107 | #endif |
108 | ); | |
109 | } | |
110 | ||
f3a8e4f5 KG |
111 | /* The size of the target's pointer type. */ |
112 | #ifndef PTR_SIZE | |
113 | #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT) | |
114 | #endif | |
115 | ||
9d340419 RO |
116 | /* Various versions of targetm.eh_frame_section. Note these must appear |
117 | outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro guards. */ | |
f3a8e4f5 | 118 | |
9d340419 | 119 | /* Version of targetm.eh_frame_section for systems with named sections. */ |
f3a8e4f5 | 120 | void |
9d340419 | 121 | named_section_eh_frame_section (void) |
f3a8e4f5 KG |
122 | { |
123 | #ifdef EH_FRAME_SECTION_NAME | |
96d0f4dc JJ |
124 | #ifdef HAVE_LD_RO_RW_SECTION_MIXING |
125 | int fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0); | |
126 | int per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1); | |
127 | int lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0); | |
128 | int flags; | |
129 | ||
130 | flags = (! flag_pic | |
131 | || ((fde_encoding & 0x70) != DW_EH_PE_absptr | |
132 | && (fde_encoding & 0x70) != DW_EH_PE_aligned | |
133 | && (per_encoding & 0x70) != DW_EH_PE_absptr | |
134 | && (per_encoding & 0x70) != DW_EH_PE_aligned | |
135 | && (lsda_encoding & 0x70) != DW_EH_PE_absptr | |
136 | && (lsda_encoding & 0x70) != DW_EH_PE_aligned)) | |
137 | ? 0 : SECTION_WRITE; | |
138 | named_section_flags (EH_FRAME_SECTION_NAME, flags); | |
139 | #else | |
f3a8e4f5 | 140 | named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE); |
96d0f4dc | 141 | #endif |
9d340419 RO |
142 | #endif |
143 | } | |
144 | ||
145 | /* Version of targetm.eh_frame_section for systems using collect2. */ | |
146 | void | |
147 | collect2_eh_frame_section (void) | |
148 | { | |
f3a8e4f5 KG |
149 | tree label = get_file_function_name ('F'); |
150 | ||
151 | data_section (); | |
152 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); | |
5fd9b178 | 153 | targetm.asm_out.globalize_label (asm_out_file, IDENTIFIER_POINTER (label)); |
f3a8e4f5 | 154 | ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); |
9d340419 RO |
155 | } |
156 | ||
157 | /* Default version of targetm.eh_frame_section. */ | |
158 | void | |
159 | default_eh_frame_section (void) | |
160 | { | |
161 | #ifdef EH_FRAME_SECTION_NAME | |
162 | named_section_eh_frame_section (); | |
163 | #else | |
164 | collect2_eh_frame_section (); | |
f3a8e4f5 KG |
165 | #endif |
166 | } | |
167 | ||
e2500fed GK |
168 | /* Array of RTXes referenced by the debugging information, which therefore |
169 | must be kept around forever. */ | |
170 | static GTY(()) varray_type used_rtx_varray; | |
171 | ||
172 | /* A pointer to the base of a list of incomplete types which might be | |
173 | completed at some later time. incomplete_types_list needs to be a VARRAY | |
174 | because we want to tell the garbage collector about it. */ | |
175 | static GTY(()) varray_type incomplete_types; | |
176 | ||
177 | /* A pointer to the base of a table of references to declaration | |
178 | scopes. This table is a display which tracks the nesting | |
179 | of declaration scopes at the current scope and containing | |
180 | scopes. This table is used to find the proper place to | |
181 | define type declaration DIE's. */ | |
182 | static GTY(()) varray_type decl_scope_table; | |
183 | ||
eaf95893 RK |
184 | /* How to start an assembler comment. */ |
185 | #ifndef ASM_COMMENT_START | |
186 | #define ASM_COMMENT_START ";#" | |
187 | #endif | |
188 | ||
a3f97cbb JW |
189 | typedef struct dw_cfi_struct *dw_cfi_ref; |
190 | typedef struct dw_fde_struct *dw_fde_ref; | |
191 | typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref; | |
a3f97cbb JW |
192 | |
193 | /* Call frames are described using a sequence of Call Frame | |
194 | Information instructions. The register number, offset | |
195 | and address fields are provided as possible operands; | |
196 | their use is selected by the opcode field. */ | |
71dfc51f | 197 | |
17211ab5 GK |
198 | enum dw_cfi_oprnd_type { |
199 | dw_cfi_oprnd_unused, | |
200 | dw_cfi_oprnd_reg_num, | |
201 | dw_cfi_oprnd_offset, | |
202 | dw_cfi_oprnd_addr, | |
203 | dw_cfi_oprnd_loc | |
204 | }; | |
205 | ||
206 | typedef union dw_cfi_oprnd_struct GTY(()) | |
71dfc51f | 207 | { |
17211ab5 | 208 | unsigned long GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num; |
799f628a | 209 | HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset; |
17211ab5 GK |
210 | const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr; |
211 | struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc; | |
71dfc51f | 212 | } |
a3f97cbb JW |
213 | dw_cfi_oprnd; |
214 | ||
17211ab5 | 215 | typedef struct dw_cfi_struct GTY(()) |
71dfc51f RK |
216 | { |
217 | dw_cfi_ref dw_cfi_next; | |
218 | enum dwarf_call_frame_info dw_cfi_opc; | |
7080f735 | 219 | dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)"))) |
17211ab5 | 220 | dw_cfi_oprnd1; |
7080f735 | 221 | dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)"))) |
17211ab5 | 222 | dw_cfi_oprnd2; |
71dfc51f | 223 | } |
a3f97cbb JW |
224 | dw_cfi_node; |
225 | ||
7d9d8943 AM |
226 | /* This is how we define the location of the CFA. We use to handle it |
227 | as REG + OFFSET all the time, but now it can be more complex. | |
228 | It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET. | |
556273e0 | 229 | Instead of passing around REG and OFFSET, we pass a copy |
7d9d8943 | 230 | of this structure. */ |
17211ab5 | 231 | typedef struct cfa_loc GTY(()) |
7d9d8943 | 232 | { |
556273e0 | 233 | unsigned long reg; |
799f628a JH |
234 | HOST_WIDE_INT offset; |
235 | HOST_WIDE_INT base_offset; | |
7d9d8943 AM |
236 | int indirect; /* 1 if CFA is accessed via a dereference. */ |
237 | } dw_cfa_location; | |
238 | ||
a3f97cbb | 239 | /* All call frame descriptions (FDE's) in the GCC generated DWARF |
4b674448 | 240 | refer to a single Common Information Entry (CIE), defined at |
fb530c07 | 241 | the beginning of the .debug_frame section. This use of a single |
a3f97cbb JW |
242 | CIE obviates the need to keep track of multiple CIE's |
243 | in the DWARF generation routines below. */ | |
71dfc51f | 244 | |
17211ab5 | 245 | typedef struct dw_fde_struct GTY(()) |
71dfc51f | 246 | { |
4746cf84 | 247 | tree decl; |
d3e3972c KG |
248 | const char *dw_fde_begin; |
249 | const char *dw_fde_current_label; | |
250 | const char *dw_fde_end; | |
71dfc51f | 251 | dw_cfi_ref dw_fde_cfi; |
52a11cbf | 252 | unsigned funcdef_number; |
b6128b8c | 253 | unsigned all_throwers_are_sibcalls : 1; |
52a11cbf RH |
254 | unsigned nothrow : 1; |
255 | unsigned uses_eh_lsda : 1; | |
71dfc51f | 256 | } |
a3f97cbb JW |
257 | dw_fde_node; |
258 | ||
6d2f8887 | 259 | /* Maximum size (in bytes) of an artificially generated label. */ |
a3f97cbb JW |
260 | #define MAX_ARTIFICIAL_LABEL_BYTES 30 |
261 | ||
a1a4189d JB |
262 | /* The size of addresses as they appear in the Dwarf 2 data. |
263 | Some architectures use word addresses to refer to code locations, | |
264 | but Dwarf 2 info always uses byte addresses. On such machines, | |
265 | Dwarf 2 addresses need to be larger than the architecture's | |
266 | pointers. */ | |
267 | #ifndef DWARF2_ADDR_SIZE | |
268 | #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT) | |
269 | #endif | |
270 | ||
7e23cb16 | 271 | /* The size in bytes of a DWARF field indicating an offset or length |
a1a4189d JB |
272 | relative to a debug info section, specified to be 4 bytes in the |
273 | DWARF-2 specification. The SGI/MIPS ABI defines it to be the same | |
b13fe8bf | 274 | as PTR_SIZE. */ |
71dfc51f | 275 | |
7e23cb16 JM |
276 | #ifndef DWARF_OFFSET_SIZE |
277 | #define DWARF_OFFSET_SIZE 4 | |
278 | #endif | |
279 | ||
9eb0ef7a KB |
280 | /* According to the (draft) DWARF 3 specification, the initial length |
281 | should either be 4 or 12 bytes. When it's 12 bytes, the first 4 | |
282 | bytes are 0xffffffff, followed by the length stored in the next 8 | |
283 | bytes. | |
284 | ||
285 | However, the SGI/MIPS ABI uses an initial length which is equal to | |
286 | DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */ | |
287 | ||
288 | #ifndef DWARF_INITIAL_LENGTH_SIZE | |
289 | #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12) | |
290 | #endif | |
291 | ||
9a666dda JM |
292 | #define DWARF_VERSION 2 |
293 | ||
7e23cb16 JM |
294 | /* Round SIZE up to the nearest BOUNDARY. */ |
295 | #define DWARF_ROUND(SIZE,BOUNDARY) \ | |
262b6384 | 296 | ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY)) |
a3f97cbb | 297 | |
a3f97cbb | 298 | /* Offsets recorded in opcodes are a multiple of this alignment factor. */ |
27c35f4b | 299 | #ifndef DWARF_CIE_DATA_ALIGNMENT |
469ac993 | 300 | #ifdef STACK_GROWS_DOWNWARD |
08cb3d38 | 301 | #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD)) |
469ac993 | 302 | #else |
08cb3d38 | 303 | #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD) |
469ac993 | 304 | #endif |
2ad9852d | 305 | #endif |
a3f97cbb | 306 | |
3f76745e JM |
307 | /* A pointer to the base of a table that contains frame description |
308 | information for each routine. */ | |
17211ab5 | 309 | static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table; |
a3f97cbb | 310 | |
3f76745e | 311 | /* Number of elements currently allocated for fde_table. */ |
c2e9147c | 312 | static GTY(()) unsigned fde_table_allocated; |
a94dbf2c | 313 | |
3f76745e | 314 | /* Number of elements in fde_table currently in use. */ |
044b4de3 | 315 | static GTY(()) unsigned fde_table_in_use; |
a3f97cbb | 316 | |
3f76745e JM |
317 | /* Size (in elements) of increments by which we may expand the |
318 | fde_table. */ | |
319 | #define FDE_TABLE_INCREMENT 256 | |
a3f97cbb | 320 | |
a94dbf2c | 321 | /* A list of call frame insns for the CIE. */ |
17211ab5 | 322 | static GTY(()) dw_cfi_ref cie_cfi_head; |
a94dbf2c | 323 | |
c1b50e49 | 324 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) |
a3f97cbb JW |
325 | /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram |
326 | attribute that accelerates the lookup of the FDE associated | |
556273e0 | 327 | with the subprogram. This variable holds the table index of the FDE |
a3f97cbb JW |
328 | associated with the current function (body) definition. */ |
329 | static unsigned current_funcdef_fde; | |
c1b50e49 | 330 | #endif |
a3f97cbb | 331 | |
17211ab5 | 332 | struct indirect_string_node GTY(()) |
9eb4015a | 333 | { |
17211ab5 | 334 | const char *str; |
9eb4015a JJ |
335 | unsigned int refcount; |
336 | unsigned int form; | |
337 | char *label; | |
338 | }; | |
339 | ||
17211ab5 GK |
340 | static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash; |
341 | ||
342 | static GTY(()) int dw2_string_counter; | |
044b4de3 | 343 | static GTY(()) unsigned long dwarf2out_cfi_label_num; |
17211ab5 GK |
344 | |
345 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) | |
346 | ||
a3f97cbb | 347 | /* Forward declarations for functions defined in this file. */ |
71dfc51f | 348 | |
7080f735 AJ |
349 | static char *stripattributes (const char *); |
350 | static const char *dwarf_cfi_name (unsigned); | |
351 | static dw_cfi_ref new_cfi (void); | |
352 | static void add_cfi (dw_cfi_ref *, dw_cfi_ref); | |
353 | static void add_fde_cfi (const char *, dw_cfi_ref); | |
354 | static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *); | |
355 | static void lookup_cfa (dw_cfa_location *); | |
799f628a | 356 | static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT); |
7080f735 | 357 | static void initial_return_save (rtx); |
799f628a | 358 | static HOST_WIDE_INT stack_adjust_offset (rtx); |
7080f735 AJ |
359 | static void output_cfi (dw_cfi_ref, dw_fde_ref, int); |
360 | static void output_call_frame_info (int); | |
361 | static void dwarf2out_stack_adjust (rtx); | |
7080f735 AJ |
362 | static void flush_queued_reg_saves (void); |
363 | static bool clobbers_queued_reg_save (rtx); | |
364 | static void dwarf2out_frame_debug_expr (rtx, const char *); | |
a3f97cbb | 365 | |
7d9d8943 | 366 | /* Support for complex CFA locations. */ |
7080f735 AJ |
367 | static void output_cfa_loc (dw_cfi_ref); |
368 | static void get_cfa_from_loc_descr (dw_cfa_location *, | |
369 | struct dw_loc_descr_struct *); | |
7d9d8943 | 370 | static struct dw_loc_descr_struct *build_cfa_loc |
7080f735 AJ |
371 | (dw_cfa_location *); |
372 | static void def_cfa_1 (const char *, dw_cfa_location *); | |
7d9d8943 | 373 | |
2e4b9b8c RH |
374 | /* How to start an assembler comment. */ |
375 | #ifndef ASM_COMMENT_START | |
376 | #define ASM_COMMENT_START ";#" | |
a3f97cbb JW |
377 | #endif |
378 | ||
7e23cb16 JM |
379 | /* Data and reference forms for relocatable data. */ |
380 | #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4) | |
381 | #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4) | |
382 | ||
cf2fe500 RH |
383 | #ifndef DEBUG_FRAME_SECTION |
384 | #define DEBUG_FRAME_SECTION ".debug_frame" | |
a3f97cbb | 385 | #endif |
a3f97cbb | 386 | |
5c90448c JM |
387 | #ifndef FUNC_BEGIN_LABEL |
388 | #define FUNC_BEGIN_LABEL "LFB" | |
a3f97cbb | 389 | #endif |
2ad9852d | 390 | |
5c90448c JM |
391 | #ifndef FUNC_END_LABEL |
392 | #define FUNC_END_LABEL "LFE" | |
a3f97cbb | 393 | #endif |
2ad9852d | 394 | |
4746cf84 | 395 | #ifndef FRAME_BEGIN_LABEL |
27d95cbe | 396 | #define FRAME_BEGIN_LABEL "Lframe" |
4746cf84 | 397 | #endif |
a6ab3aad JM |
398 | #define CIE_AFTER_SIZE_LABEL "LSCIE" |
399 | #define CIE_END_LABEL "LECIE" | |
2e4b9b8c RH |
400 | #define FDE_LABEL "LSFDE" |
401 | #define FDE_AFTER_SIZE_LABEL "LASFDE" | |
a6ab3aad | 402 | #define FDE_END_LABEL "LEFDE" |
981975b6 RH |
403 | #define LINE_NUMBER_BEGIN_LABEL "LSLT" |
404 | #define LINE_NUMBER_END_LABEL "LELT" | |
405 | #define LN_PROLOG_AS_LABEL "LASLTP" | |
406 | #define LN_PROLOG_END_LABEL "LELTP" | |
881c6935 | 407 | #define DIE_LABEL_PREFIX "DW" |
a3f97cbb | 408 | |
c8cc5c4a | 409 | /* The DWARF 2 CFA column which tracks the return address. Normally this |
a94dbf2c JM |
410 | is the column for PC, or the first column after all of the hard |
411 | registers. */ | |
c8cc5c4a | 412 | #ifndef DWARF_FRAME_RETURN_COLUMN |
a94dbf2c | 413 | #ifdef PC_REGNUM |
7080f735 | 414 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM) |
a94dbf2c | 415 | #else |
7080f735 | 416 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS |
a94dbf2c | 417 | #endif |
c8cc5c4a JM |
418 | #endif |
419 | ||
420 | /* The mapping from gcc register number to DWARF 2 CFA column number. By | |
469ac993 | 421 | default, we just provide columns for all registers. */ |
c8cc5c4a | 422 | #ifndef DWARF_FRAME_REGNUM |
469ac993 | 423 | #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG) |
c8cc5c4a | 424 | #endif |
3f76745e | 425 | |
2ad9852d RK |
426 | /* The offset from the incoming value of %sp to the top of the stack frame |
427 | for the current function. */ | |
428 | #ifndef INCOMING_FRAME_SP_OFFSET | |
429 | #define INCOMING_FRAME_SP_OFFSET 0 | |
430 | #endif | |
431 | \f | |
0021b564 JM |
432 | /* Hook used by __throw. */ |
433 | ||
434 | rtx | |
7080f735 | 435 | expand_builtin_dwarf_sp_column (void) |
0021b564 | 436 | { |
9c80ff25 | 437 | return GEN_INT (DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)); |
0021b564 JM |
438 | } |
439 | ||
71dfc51f | 440 | /* Return a pointer to a copy of the section string name S with all |
bf20f341 | 441 | attributes stripped off, and an asterisk prepended (for assemble_name). */ |
71dfc51f RK |
442 | |
443 | static inline char * | |
7080f735 | 444 | stripattributes (const char *s) |
a3f97cbb | 445 | { |
bf20f341 | 446 | char *stripped = xmalloc (strlen (s) + 2); |
71dfc51f RK |
447 | char *p = stripped; |
448 | ||
bf20f341 JW |
449 | *p++ = '*'; |
450 | ||
451 | while (*s && *s != ',') | |
452 | *p++ = *s++; | |
71dfc51f | 453 | |
a3f97cbb JW |
454 | *p = '\0'; |
455 | return stripped; | |
456 | } | |
457 | ||
d9d5c9de | 458 | /* Generate code to initialize the register size table. */ |
2f3ca9e7 | 459 | |
d9d5c9de | 460 | void |
7080f735 | 461 | expand_builtin_init_dwarf_reg_sizes (tree address) |
2f3ca9e7 | 462 | { |
d9d5c9de BS |
463 | int i; |
464 | enum machine_mode mode = TYPE_MODE (char_type_node); | |
465 | rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0); | |
2ad9852d | 466 | rtx mem = gen_rtx_MEM (BLKmode, addr); |
71628aa0 | 467 | bool wrote_return_column = false; |
2f3ca9e7 | 468 | |
91ea38f9 JH |
469 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) |
470 | if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS) | |
471 | { | |
472 | HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode); | |
fee226d2 R |
473 | enum machine_mode save_mode = reg_raw_mode[i]; |
474 | HOST_WIDE_INT size; | |
2f3ca9e7 | 475 | |
fee226d2 R |
476 | if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode)) |
477 | save_mode = choose_hard_reg_mode (i, 1, true); | |
71628aa0 R |
478 | if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN) |
479 | { | |
480 | if (save_mode == VOIDmode) | |
481 | continue; | |
482 | wrote_return_column = true; | |
483 | } | |
fee226d2 | 484 | size = GET_MODE_SIZE (save_mode); |
91ea38f9 JH |
485 | if (offset < 0) |
486 | continue; | |
c699cee9 | 487 | |
91ea38f9 JH |
488 | emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size)); |
489 | } | |
ed80cd68 RH |
490 | |
491 | #ifdef DWARF_ALT_FRAME_RETURN_COLUMN | |
492 | if (! wrote_return_column) | |
493 | abort (); | |
494 | i = DWARF_ALT_FRAME_RETURN_COLUMN; | |
495 | wrote_return_column = false; | |
496 | #else | |
497 | i = DWARF_FRAME_RETURN_COLUMN; | |
498 | #endif | |
499 | ||
71628aa0 R |
500 | if (! wrote_return_column) |
501 | { | |
502 | enum machine_mode save_mode = Pmode; | |
ed80cd68 | 503 | HOST_WIDE_INT offset = i * GET_MODE_SIZE (mode); |
71628aa0 R |
504 | HOST_WIDE_INT size = GET_MODE_SIZE (save_mode); |
505 | emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size)); | |
506 | } | |
2f3ca9e7 JM |
507 | } |
508 | ||
3f76745e | 509 | /* Convert a DWARF call frame info. operation to its string name */ |
a3f97cbb | 510 | |
d560ee52 | 511 | static const char * |
7080f735 | 512 | dwarf_cfi_name (unsigned int cfi_opc) |
3f76745e JM |
513 | { |
514 | switch (cfi_opc) | |
515 | { | |
516 | case DW_CFA_advance_loc: | |
517 | return "DW_CFA_advance_loc"; | |
518 | case DW_CFA_offset: | |
519 | return "DW_CFA_offset"; | |
520 | case DW_CFA_restore: | |
521 | return "DW_CFA_restore"; | |
522 | case DW_CFA_nop: | |
523 | return "DW_CFA_nop"; | |
524 | case DW_CFA_set_loc: | |
525 | return "DW_CFA_set_loc"; | |
526 | case DW_CFA_advance_loc1: | |
527 | return "DW_CFA_advance_loc1"; | |
528 | case DW_CFA_advance_loc2: | |
529 | return "DW_CFA_advance_loc2"; | |
530 | case DW_CFA_advance_loc4: | |
531 | return "DW_CFA_advance_loc4"; | |
532 | case DW_CFA_offset_extended: | |
533 | return "DW_CFA_offset_extended"; | |
534 | case DW_CFA_restore_extended: | |
535 | return "DW_CFA_restore_extended"; | |
536 | case DW_CFA_undefined: | |
537 | return "DW_CFA_undefined"; | |
538 | case DW_CFA_same_value: | |
539 | return "DW_CFA_same_value"; | |
540 | case DW_CFA_register: | |
541 | return "DW_CFA_register"; | |
542 | case DW_CFA_remember_state: | |
543 | return "DW_CFA_remember_state"; | |
544 | case DW_CFA_restore_state: | |
545 | return "DW_CFA_restore_state"; | |
546 | case DW_CFA_def_cfa: | |
547 | return "DW_CFA_def_cfa"; | |
548 | case DW_CFA_def_cfa_register: | |
549 | return "DW_CFA_def_cfa_register"; | |
550 | case DW_CFA_def_cfa_offset: | |
551 | return "DW_CFA_def_cfa_offset"; | |
6bb28965 JM |
552 | |
553 | /* DWARF 3 */ | |
7d9d8943 AM |
554 | case DW_CFA_def_cfa_expression: |
555 | return "DW_CFA_def_cfa_expression"; | |
6bb28965 JM |
556 | case DW_CFA_expression: |
557 | return "DW_CFA_expression"; | |
558 | case DW_CFA_offset_extended_sf: | |
559 | return "DW_CFA_offset_extended_sf"; | |
560 | case DW_CFA_def_cfa_sf: | |
561 | return "DW_CFA_def_cfa_sf"; | |
562 | case DW_CFA_def_cfa_offset_sf: | |
563 | return "DW_CFA_def_cfa_offset_sf"; | |
c53aa195 | 564 | |
3f76745e JM |
565 | /* SGI/MIPS specific */ |
566 | case DW_CFA_MIPS_advance_loc8: | |
567 | return "DW_CFA_MIPS_advance_loc8"; | |
c53aa195 JM |
568 | |
569 | /* GNU extensions */ | |
570 | case DW_CFA_GNU_window_save: | |
571 | return "DW_CFA_GNU_window_save"; | |
0021b564 JM |
572 | case DW_CFA_GNU_args_size: |
573 | return "DW_CFA_GNU_args_size"; | |
3f388b42 GK |
574 | case DW_CFA_GNU_negative_offset_extended: |
575 | return "DW_CFA_GNU_negative_offset_extended"; | |
c53aa195 | 576 | |
3f76745e JM |
577 | default: |
578 | return "DW_CFA_<unknown>"; | |
579 | } | |
580 | } | |
a3f97cbb | 581 | |
3f76745e | 582 | /* Return a pointer to a newly allocated Call Frame Instruction. */ |
71dfc51f | 583 | |
3f76745e | 584 | static inline dw_cfi_ref |
7080f735 | 585 | new_cfi (void) |
3f76745e | 586 | { |
703ad42b | 587 | dw_cfi_ref cfi = ggc_alloc (sizeof (dw_cfi_node)); |
71dfc51f | 588 | |
3f76745e JM |
589 | cfi->dw_cfi_next = NULL; |
590 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0; | |
591 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0; | |
a3f97cbb | 592 | |
3f76745e JM |
593 | return cfi; |
594 | } | |
a3f97cbb | 595 | |
3f76745e | 596 | /* Add a Call Frame Instruction to list of instructions. */ |
a3f97cbb | 597 | |
3f76745e | 598 | static inline void |
7080f735 | 599 | add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi) |
3f76745e | 600 | { |
b3694847 | 601 | dw_cfi_ref *p; |
a3f97cbb | 602 | |
3f76745e JM |
603 | /* Find the end of the chain. */ |
604 | for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next) | |
605 | ; | |
606 | ||
607 | *p = cfi; | |
a3f97cbb JW |
608 | } |
609 | ||
3f76745e | 610 | /* Generate a new label for the CFI info to refer to. */ |
71dfc51f | 611 | |
c53aa195 | 612 | char * |
7080f735 | 613 | dwarf2out_cfi_label (void) |
a3f97cbb | 614 | { |
3f76745e | 615 | static char label[20]; |
556273e0 | 616 | |
044b4de3 | 617 | ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++); |
3f76745e | 618 | ASM_OUTPUT_LABEL (asm_out_file, label); |
3f76745e | 619 | return label; |
a3f97cbb JW |
620 | } |
621 | ||
3f76745e JM |
622 | /* Add CFI to the current fde at the PC value indicated by LABEL if specified, |
623 | or to the CIE if LABEL is NULL. */ | |
71dfc51f | 624 | |
3f76745e | 625 | static void |
7080f735 | 626 | add_fde_cfi (const char *label, dw_cfi_ref cfi) |
a3f97cbb | 627 | { |
3f76745e JM |
628 | if (label) |
629 | { | |
b3694847 | 630 | dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
a3f97cbb | 631 | |
3f76745e JM |
632 | if (*label == 0) |
633 | label = dwarf2out_cfi_label (); | |
71dfc51f | 634 | |
3f76745e JM |
635 | if (fde->dw_fde_current_label == NULL |
636 | || strcmp (label, fde->dw_fde_current_label) != 0) | |
637 | { | |
b3694847 | 638 | dw_cfi_ref xcfi; |
a3f97cbb | 639 | |
3f76745e | 640 | fde->dw_fde_current_label = label = xstrdup (label); |
71dfc51f | 641 | |
3f76745e JM |
642 | /* Set the location counter to the new label. */ |
643 | xcfi = new_cfi (); | |
644 | xcfi->dw_cfi_opc = DW_CFA_advance_loc4; | |
645 | xcfi->dw_cfi_oprnd1.dw_cfi_addr = label; | |
646 | add_cfi (&fde->dw_fde_cfi, xcfi); | |
647 | } | |
71dfc51f | 648 | |
3f76745e JM |
649 | add_cfi (&fde->dw_fde_cfi, cfi); |
650 | } | |
651 | ||
652 | else | |
653 | add_cfi (&cie_cfi_head, cfi); | |
a3f97cbb JW |
654 | } |
655 | ||
3f76745e | 656 | /* Subroutine of lookup_cfa. */ |
71dfc51f | 657 | |
3f76745e | 658 | static inline void |
7080f735 | 659 | lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc) |
a3f97cbb | 660 | { |
3f76745e JM |
661 | switch (cfi->dw_cfi_opc) |
662 | { | |
663 | case DW_CFA_def_cfa_offset: | |
7d9d8943 | 664 | loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset; |
3f76745e JM |
665 | break; |
666 | case DW_CFA_def_cfa_register: | |
7d9d8943 | 667 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
3f76745e JM |
668 | break; |
669 | case DW_CFA_def_cfa: | |
7d9d8943 AM |
670 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
671 | loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset; | |
672 | break; | |
673 | case DW_CFA_def_cfa_expression: | |
674 | get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc); | |
3f76745e | 675 | break; |
e9a25f70 JL |
676 | default: |
677 | break; | |
3f76745e | 678 | } |
a3f97cbb JW |
679 | } |
680 | ||
3f76745e | 681 | /* Find the previous value for the CFA. */ |
71dfc51f | 682 | |
3f76745e | 683 | static void |
7080f735 | 684 | lookup_cfa (dw_cfa_location *loc) |
a3f97cbb | 685 | { |
b3694847 | 686 | dw_cfi_ref cfi; |
3f76745e | 687 | |
7d9d8943 AM |
688 | loc->reg = (unsigned long) -1; |
689 | loc->offset = 0; | |
690 | loc->indirect = 0; | |
691 | loc->base_offset = 0; | |
3f76745e JM |
692 | |
693 | for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next) | |
7d9d8943 | 694 | lookup_cfa_1 (cfi, loc); |
3f76745e JM |
695 | |
696 | if (fde_table_in_use) | |
a3f97cbb | 697 | { |
b3694847 | 698 | dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
3f76745e | 699 | for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next) |
7d9d8943 | 700 | lookup_cfa_1 (cfi, loc); |
a3f97cbb JW |
701 | } |
702 | } | |
703 | ||
3f76745e | 704 | /* The current rule for calculating the DWARF2 canonical frame address. */ |
fbfa55b0 | 705 | static dw_cfa_location cfa; |
71dfc51f | 706 | |
3f76745e JM |
707 | /* The register used for saving registers to the stack, and its offset |
708 | from the CFA. */ | |
fbfa55b0 | 709 | static dw_cfa_location cfa_store; |
3f76745e | 710 | |
0021b564 | 711 | /* The running total of the size of arguments pushed onto the stack. */ |
799f628a | 712 | static HOST_WIDE_INT args_size; |
0021b564 | 713 | |
b57d9225 | 714 | /* The last args_size we actually output. */ |
799f628a | 715 | static HOST_WIDE_INT old_args_size; |
b57d9225 | 716 | |
3f76745e JM |
717 | /* Entry point to update the canonical frame address (CFA). |
718 | LABEL is passed to add_fde_cfi. The value of CFA is now to be | |
719 | calculated from REG+OFFSET. */ | |
720 | ||
721 | void | |
799f628a | 722 | dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset) |
7d9d8943 AM |
723 | { |
724 | dw_cfa_location loc; | |
725 | loc.indirect = 0; | |
726 | loc.base_offset = 0; | |
727 | loc.reg = reg; | |
728 | loc.offset = offset; | |
729 | def_cfa_1 (label, &loc); | |
730 | } | |
731 | ||
770ca8c6 | 732 | /* This routine does the actual work. The CFA is now calculated from |
7d9d8943 | 733 | the dw_cfa_location structure. */ |
2ad9852d | 734 | |
7d9d8943 | 735 | static void |
7080f735 | 736 | def_cfa_1 (const char *label, dw_cfa_location *loc_p) |
a3f97cbb | 737 | { |
b3694847 | 738 | dw_cfi_ref cfi; |
7d9d8943 | 739 | dw_cfa_location old_cfa, loc; |
3f76745e | 740 | |
7d9d8943 AM |
741 | cfa = *loc_p; |
742 | loc = *loc_p; | |
5bef9b1f | 743 | |
7d9d8943 AM |
744 | if (cfa_store.reg == loc.reg && loc.indirect == 0) |
745 | cfa_store.offset = loc.offset; | |
3f76745e | 746 | |
7d9d8943 AM |
747 | loc.reg = DWARF_FRAME_REGNUM (loc.reg); |
748 | lookup_cfa (&old_cfa); | |
749 | ||
2ad9852d RK |
750 | /* If nothing changed, no need to issue any call frame instructions. */ |
751 | if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset | |
752 | && loc.indirect == old_cfa.indirect | |
753 | && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset)) | |
754 | return; | |
3f76745e JM |
755 | |
756 | cfi = new_cfi (); | |
757 | ||
e09bbb25 | 758 | if (loc.reg == old_cfa.reg && !loc.indirect) |
a3f97cbb | 759 | { |
770ca8c6 JO |
760 | /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, |
761 | indicating the CFA register did not change but the offset | |
762 | did. */ | |
3f76745e | 763 | cfi->dw_cfi_opc = DW_CFA_def_cfa_offset; |
7d9d8943 | 764 | cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset; |
3f76745e | 765 | } |
a3f97cbb | 766 | |
3f76745e | 767 | #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */ |
7d9d8943 | 768 | else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1 |
e09bbb25 | 769 | && !loc.indirect) |
3f76745e | 770 | { |
770ca8c6 JO |
771 | /* Construct a "DW_CFA_def_cfa_register <register>" instruction, |
772 | indicating the CFA register has changed to <register> but the | |
773 | offset has not changed. */ | |
3f76745e | 774 | cfi->dw_cfi_opc = DW_CFA_def_cfa_register; |
7d9d8943 | 775 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
3f76745e JM |
776 | } |
777 | #endif | |
a3f97cbb | 778 | |
7d9d8943 | 779 | else if (loc.indirect == 0) |
3f76745e | 780 | { |
770ca8c6 JO |
781 | /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction, |
782 | indicating the CFA register has changed to <register> with | |
783 | the specified offset. */ | |
3f76745e | 784 | cfi->dw_cfi_opc = DW_CFA_def_cfa; |
7d9d8943 AM |
785 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
786 | cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset; | |
787 | } | |
788 | else | |
789 | { | |
770ca8c6 JO |
790 | /* Construct a DW_CFA_def_cfa_expression instruction to |
791 | calculate the CFA using a full location expression since no | |
792 | register-offset pair is available. */ | |
556273e0 | 793 | struct dw_loc_descr_struct *loc_list; |
2ad9852d | 794 | |
7d9d8943 AM |
795 | cfi->dw_cfi_opc = DW_CFA_def_cfa_expression; |
796 | loc_list = build_cfa_loc (&loc); | |
797 | cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list; | |
a3f97cbb | 798 | } |
3f76745e JM |
799 | |
800 | add_fde_cfi (label, cfi); | |
a3f97cbb JW |
801 | } |
802 | ||
3f76745e JM |
803 | /* Add the CFI for saving a register. REG is the CFA column number. |
804 | LABEL is passed to add_fde_cfi. | |
805 | If SREG is -1, the register is saved at OFFSET from the CFA; | |
806 | otherwise it is saved in SREG. */ | |
71dfc51f | 807 | |
3f76745e | 808 | static void |
799f628a | 809 | reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset) |
a3f97cbb | 810 | { |
b3694847 | 811 | dw_cfi_ref cfi = new_cfi (); |
3f76745e JM |
812 | |
813 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
814 | ||
1bac3811 | 815 | if (sreg == INVALID_REGNUM) |
a3f97cbb | 816 | { |
3f76745e JM |
817 | if (reg & ~0x3f) |
818 | /* The register number won't fit in 6 bits, so we have to use | |
819 | the long form. */ | |
820 | cfi->dw_cfi_opc = DW_CFA_offset_extended; | |
821 | else | |
822 | cfi->dw_cfi_opc = DW_CFA_offset; | |
823 | ||
27c35f4b HPN |
824 | #ifdef ENABLE_CHECKING |
825 | { | |
826 | /* If we get an offset that is not a multiple of | |
827 | DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the | |
828 | definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine | |
829 | description. */ | |
799f628a | 830 | HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT; |
27c35f4b HPN |
831 | |
832 | if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset) | |
833 | abort (); | |
834 | } | |
835 | #endif | |
3f76745e | 836 | offset /= DWARF_CIE_DATA_ALIGNMENT; |
3a88cbd1 | 837 | if (offset < 0) |
6bb28965 | 838 | cfi->dw_cfi_opc = DW_CFA_offset_extended_sf; |
2ad9852d | 839 | |
3f76745e JM |
840 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; |
841 | } | |
2c849145 | 842 | else if (sreg == reg) |
f8a57be8 | 843 | cfi->dw_cfi_opc = DW_CFA_same_value; |
3f76745e JM |
844 | else |
845 | { | |
846 | cfi->dw_cfi_opc = DW_CFA_register; | |
847 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg; | |
848 | } | |
849 | ||
850 | add_fde_cfi (label, cfi); | |
851 | } | |
852 | ||
c53aa195 JM |
853 | /* Add the CFI for saving a register window. LABEL is passed to reg_save. |
854 | This CFI tells the unwinder that it needs to restore the window registers | |
855 | from the previous frame's window save area. | |
556273e0 | 856 | |
c53aa195 JM |
857 | ??? Perhaps we should note in the CIE where windows are saved (instead of |
858 | assuming 0(cfa)) and what registers are in the window. */ | |
859 | ||
860 | void | |
7080f735 | 861 | dwarf2out_window_save (const char *label) |
c53aa195 | 862 | { |
b3694847 | 863 | dw_cfi_ref cfi = new_cfi (); |
2ad9852d | 864 | |
c53aa195 JM |
865 | cfi->dw_cfi_opc = DW_CFA_GNU_window_save; |
866 | add_fde_cfi (label, cfi); | |
867 | } | |
868 | ||
0021b564 JM |
869 | /* Add a CFI to update the running total of the size of arguments |
870 | pushed onto the stack. */ | |
871 | ||
872 | void | |
799f628a | 873 | dwarf2out_args_size (const char *label, HOST_WIDE_INT size) |
0021b564 | 874 | { |
b3694847 | 875 | dw_cfi_ref cfi; |
b57d9225 JM |
876 | |
877 | if (size == old_args_size) | |
878 | return; | |
2ad9852d | 879 | |
b57d9225 JM |
880 | old_args_size = size; |
881 | ||
882 | cfi = new_cfi (); | |
0021b564 JM |
883 | cfi->dw_cfi_opc = DW_CFA_GNU_args_size; |
884 | cfi->dw_cfi_oprnd1.dw_cfi_offset = size; | |
885 | add_fde_cfi (label, cfi); | |
886 | } | |
887 | ||
c53aa195 JM |
888 | /* Entry point for saving a register to the stack. REG is the GCC register |
889 | number. LABEL and OFFSET are passed to reg_save. */ | |
3f76745e JM |
890 | |
891 | void | |
799f628a | 892 | dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset) |
3f76745e | 893 | { |
1bac3811 | 894 | reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset); |
3f76745e JM |
895 | } |
896 | ||
c53aa195 JM |
897 | /* Entry point for saving the return address in the stack. |
898 | LABEL and OFFSET are passed to reg_save. */ | |
899 | ||
900 | void | |
799f628a | 901 | dwarf2out_return_save (const char *label, HOST_WIDE_INT offset) |
c53aa195 | 902 | { |
1bac3811 | 903 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset); |
c53aa195 JM |
904 | } |
905 | ||
906 | /* Entry point for saving the return address in a register. | |
907 | LABEL and SREG are passed to reg_save. */ | |
908 | ||
909 | void | |
7080f735 | 910 | dwarf2out_return_reg (const char *label, unsigned int sreg) |
c53aa195 | 911 | { |
1bac3811 | 912 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0); |
c53aa195 JM |
913 | } |
914 | ||
3f76745e JM |
915 | /* Record the initial position of the return address. RTL is |
916 | INCOMING_RETURN_ADDR_RTX. */ | |
917 | ||
918 | static void | |
7080f735 | 919 | initial_return_save (rtx rtl) |
3f76745e | 920 | { |
1bac3811 | 921 | unsigned int reg = INVALID_REGNUM; |
2ad9852d | 922 | HOST_WIDE_INT offset = 0; |
3f76745e JM |
923 | |
924 | switch (GET_CODE (rtl)) | |
925 | { | |
926 | case REG: | |
927 | /* RA is in a register. */ | |
2c849145 | 928 | reg = DWARF_FRAME_REGNUM (REGNO (rtl)); |
3f76745e | 929 | break; |
2ad9852d | 930 | |
3f76745e JM |
931 | case MEM: |
932 | /* RA is on the stack. */ | |
933 | rtl = XEXP (rtl, 0); | |
934 | switch (GET_CODE (rtl)) | |
935 | { | |
936 | case REG: | |
3a88cbd1 JL |
937 | if (REGNO (rtl) != STACK_POINTER_REGNUM) |
938 | abort (); | |
3f76745e JM |
939 | offset = 0; |
940 | break; | |
2ad9852d | 941 | |
3f76745e | 942 | case PLUS: |
3a88cbd1 JL |
943 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
944 | abort (); | |
3f76745e JM |
945 | offset = INTVAL (XEXP (rtl, 1)); |
946 | break; | |
2ad9852d | 947 | |
3f76745e | 948 | case MINUS: |
3a88cbd1 JL |
949 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
950 | abort (); | |
3f76745e JM |
951 | offset = -INTVAL (XEXP (rtl, 1)); |
952 | break; | |
2ad9852d | 953 | |
3f76745e JM |
954 | default: |
955 | abort (); | |
956 | } | |
2ad9852d | 957 | |
3f76745e | 958 | break; |
2ad9852d | 959 | |
c53aa195 JM |
960 | case PLUS: |
961 | /* The return address is at some offset from any value we can | |
962 | actually load. For instance, on the SPARC it is in %i7+8. Just | |
963 | ignore the offset for now; it doesn't matter for unwinding frames. */ | |
3a88cbd1 JL |
964 | if (GET_CODE (XEXP (rtl, 1)) != CONST_INT) |
965 | abort (); | |
c53aa195 JM |
966 | initial_return_save (XEXP (rtl, 0)); |
967 | return; | |
2ad9852d | 968 | |
a3f97cbb | 969 | default: |
3f76745e | 970 | abort (); |
a3f97cbb | 971 | } |
3f76745e | 972 | |
f8a57be8 GK |
973 | if (reg != DWARF_FRAME_RETURN_COLUMN) |
974 | reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset); | |
a3f97cbb JW |
975 | } |
976 | ||
1ba5ae8f | 977 | /* Given a SET, calculate the amount of stack adjustment it |
30f7a378 | 978 | contains. */ |
1ba5ae8f | 979 | |
799f628a | 980 | static HOST_WIDE_INT |
7080f735 | 981 | stack_adjust_offset (rtx pattern) |
1ba5ae8f AH |
982 | { |
983 | rtx src = SET_SRC (pattern); | |
984 | rtx dest = SET_DEST (pattern); | |
2ad9852d | 985 | HOST_WIDE_INT offset = 0; |
1ba5ae8f AH |
986 | enum rtx_code code; |
987 | ||
988 | if (dest == stack_pointer_rtx) | |
989 | { | |
990 | /* (set (reg sp) (plus (reg sp) (const_int))) */ | |
991 | code = GET_CODE (src); | |
992 | if (! (code == PLUS || code == MINUS) | |
993 | || XEXP (src, 0) != stack_pointer_rtx | |
994 | || GET_CODE (XEXP (src, 1)) != CONST_INT) | |
995 | return 0; | |
996 | ||
997 | offset = INTVAL (XEXP (src, 1)); | |
f472fa29 AM |
998 | if (code == PLUS) |
999 | offset = -offset; | |
1ba5ae8f | 1000 | } |
3c0cb5de | 1001 | else if (MEM_P (dest)) |
1ba5ae8f AH |
1002 | { |
1003 | /* (set (mem (pre_dec (reg sp))) (foo)) */ | |
1004 | src = XEXP (dest, 0); | |
1005 | code = GET_CODE (src); | |
1006 | ||
c26fbbca KH |
1007 | switch (code) |
1008 | { | |
f472fa29 AM |
1009 | case PRE_MODIFY: |
1010 | case POST_MODIFY: | |
1011 | if (XEXP (src, 0) == stack_pointer_rtx) | |
1012 | { | |
1013 | rtx val = XEXP (XEXP (src, 1), 1); | |
1014 | /* We handle only adjustments by constant amount. */ | |
1015 | if (GET_CODE (XEXP (src, 1)) != PLUS || | |
1016 | GET_CODE (val) != CONST_INT) | |
c26fbbca | 1017 | abort (); |
f472fa29 AM |
1018 | offset = -INTVAL (val); |
1019 | break; | |
1020 | } | |
1021 | return 0; | |
1022 | ||
1023 | case PRE_DEC: | |
1024 | case POST_DEC: | |
1025 | if (XEXP (src, 0) == stack_pointer_rtx) | |
1026 | { | |
1027 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1028 | break; | |
1029 | } | |
1030 | return 0; | |
1031 | ||
1032 | case PRE_INC: | |
1033 | case POST_INC: | |
1034 | if (XEXP (src, 0) == stack_pointer_rtx) | |
1035 | { | |
1036 | offset = -GET_MODE_SIZE (GET_MODE (dest)); | |
1037 | break; | |
1038 | } | |
1039 | return 0; | |
2ad9852d | 1040 | |
f472fa29 AM |
1041 | default: |
1042 | return 0; | |
e2134eea | 1043 | } |
1ba5ae8f AH |
1044 | } |
1045 | else | |
1046 | return 0; | |
1047 | ||
1ba5ae8f AH |
1048 | return offset; |
1049 | } | |
1050 | ||
0021b564 JM |
1051 | /* Check INSN to see if it looks like a push or a stack adjustment, and |
1052 | make a note of it if it does. EH uses this information to find out how | |
1053 | much extra space it needs to pop off the stack. */ | |
1054 | ||
1055 | static void | |
7080f735 | 1056 | dwarf2out_stack_adjust (rtx insn) |
0021b564 | 1057 | { |
2ad9852d | 1058 | HOST_WIDE_INT offset; |
d3e3972c | 1059 | const char *label; |
2ad9852d | 1060 | int i; |
0021b564 | 1061 | |
b298f00f RH |
1062 | /* Don't handle epilogues at all. Certainly it would be wrong to do so |
1063 | with this function. Proper support would require all frame-related | |
1064 | insns to be marked, and to be able to handle saving state around | |
1065 | epilogues textually in the middle of the function. */ | |
1066 | if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn)) | |
1067 | return; | |
1068 | ||
4b4bf941 | 1069 | if (!flag_asynchronous_unwind_tables && CALL_P (insn)) |
b57d9225 JM |
1070 | { |
1071 | /* Extract the size of the args from the CALL rtx itself. */ | |
b57d9225 JM |
1072 | insn = PATTERN (insn); |
1073 | if (GET_CODE (insn) == PARALLEL) | |
1074 | insn = XVECEXP (insn, 0, 0); | |
1075 | if (GET_CODE (insn) == SET) | |
1076 | insn = SET_SRC (insn); | |
3db35af4 MM |
1077 | if (GET_CODE (insn) != CALL) |
1078 | abort (); | |
2ad9852d | 1079 | |
b57d9225 JM |
1080 | dwarf2out_args_size ("", INTVAL (XEXP (insn, 1))); |
1081 | return; | |
1082 | } | |
1083 | ||
1084 | /* If only calls can throw, and we have a frame pointer, | |
1085 | save up adjustments until we see the CALL_INSN. */ | |
2ad9852d | 1086 | else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM) |
b57d9225 JM |
1087 | return; |
1088 | ||
4b4bf941 | 1089 | if (BARRIER_P (insn)) |
0021b564 | 1090 | { |
6020d360 JM |
1091 | /* When we see a BARRIER, we know to reset args_size to 0. Usually |
1092 | the compiler will have already emitted a stack adjustment, but | |
1093 | doesn't bother for calls to noreturn functions. */ | |
1094 | #ifdef STACK_GROWS_DOWNWARD | |
1095 | offset = -args_size; | |
1096 | #else | |
1097 | offset = args_size; | |
1098 | #endif | |
0021b564 | 1099 | } |
6020d360 | 1100 | else if (GET_CODE (PATTERN (insn)) == SET) |
2ad9852d | 1101 | offset = stack_adjust_offset (PATTERN (insn)); |
1ba5ae8f AH |
1102 | else if (GET_CODE (PATTERN (insn)) == PARALLEL |
1103 | || GET_CODE (PATTERN (insn)) == SEQUENCE) | |
1104 | { | |
1105 | /* There may be stack adjustments inside compound insns. Search | |
2ad9852d RK |
1106 | for them. */ |
1107 | for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--) | |
1108 | if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET) | |
1109 | offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i)); | |
0021b564 JM |
1110 | } |
1111 | else | |
1112 | return; | |
0b34cf1e | 1113 | |
6020d360 JM |
1114 | if (offset == 0) |
1115 | return; | |
1116 | ||
7d9d8943 AM |
1117 | if (cfa.reg == STACK_POINTER_REGNUM) |
1118 | cfa.offset += offset; | |
0021b564 JM |
1119 | |
1120 | #ifndef STACK_GROWS_DOWNWARD | |
1121 | offset = -offset; | |
1122 | #endif | |
2ad9852d | 1123 | |
0021b564 JM |
1124 | args_size += offset; |
1125 | if (args_size < 0) | |
1126 | args_size = 0; | |
1127 | ||
1128 | label = dwarf2out_cfi_label (); | |
7d9d8943 | 1129 | def_cfa_1 (label, &cfa); |
0021b564 JM |
1130 | dwarf2out_args_size (label, args_size); |
1131 | } | |
1132 | ||
17211ab5 GK |
1133 | #endif |
1134 | ||
fbfa55b0 RH |
1135 | /* We delay emitting a register save until either (a) we reach the end |
1136 | of the prologue or (b) the register is clobbered. This clusters | |
1137 | register saves so that there are fewer pc advances. */ | |
1138 | ||
17211ab5 | 1139 | struct queued_reg_save GTY(()) |
fbfa55b0 RH |
1140 | { |
1141 | struct queued_reg_save *next; | |
1142 | rtx reg; | |
799f628a | 1143 | HOST_WIDE_INT cfa_offset; |
f8a57be8 | 1144 | rtx saved_reg; |
fbfa55b0 RH |
1145 | }; |
1146 | ||
17211ab5 GK |
1147 | static GTY(()) struct queued_reg_save *queued_reg_saves; |
1148 | ||
f8a57be8 GK |
1149 | /* The caller's ORIG_REG is saved in SAVED_IN_REG. */ |
1150 | struct reg_saved_in_data GTY(()) { | |
1151 | rtx orig_reg; | |
1152 | rtx saved_in_reg; | |
1153 | }; | |
1154 | ||
1155 | /* A list of registers saved in other registers. | |
1156 | The list intentionally has a small maximum capacity of 4; if your | |
1157 | port needs more than that, you might consider implementing a | |
1158 | more efficient data structure. */ | |
1159 | static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4]; | |
1160 | static GTY(()) size_t num_regs_saved_in_regs; | |
1161 | ||
17211ab5 | 1162 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) |
fbfa55b0 RH |
1163 | static const char *last_reg_save_label; |
1164 | ||
f8a57be8 GK |
1165 | /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at |
1166 | SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */ | |
1167 | ||
fbfa55b0 | 1168 | static void |
f8a57be8 | 1169 | queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset) |
fbfa55b0 | 1170 | { |
f8a57be8 GK |
1171 | struct queued_reg_save *q; |
1172 | ||
1173 | /* Duplicates waste space, but it's also necessary to remove them | |
1174 | for correctness, since the queue gets output in reverse | |
1175 | order. */ | |
1176 | for (q = queued_reg_saves; q != NULL; q = q->next) | |
1177 | if (REGNO (q->reg) == REGNO (reg)) | |
1178 | break; | |
1179 | ||
1180 | if (q == NULL) | |
1181 | { | |
1182 | q = ggc_alloc (sizeof (*q)); | |
1183 | q->next = queued_reg_saves; | |
1184 | queued_reg_saves = q; | |
1185 | } | |
fbfa55b0 | 1186 | |
fbfa55b0 RH |
1187 | q->reg = reg; |
1188 | q->cfa_offset = offset; | |
f8a57be8 | 1189 | q->saved_reg = sreg; |
fbfa55b0 RH |
1190 | |
1191 | last_reg_save_label = label; | |
1192 | } | |
1193 | ||
f8a57be8 GK |
1194 | /* Output all the entries in QUEUED_REG_SAVES. */ |
1195 | ||
fbfa55b0 | 1196 | static void |
7080f735 | 1197 | flush_queued_reg_saves (void) |
fbfa55b0 | 1198 | { |
f8a57be8 | 1199 | struct queued_reg_save *q; |
fbfa55b0 | 1200 | |
f8a57be8 | 1201 | for (q = queued_reg_saves; q; q = q->next) |
fbfa55b0 | 1202 | { |
f8a57be8 | 1203 | size_t i; |
1bac3811 RH |
1204 | unsigned int reg, sreg; |
1205 | ||
f8a57be8 GK |
1206 | for (i = 0; i < num_regs_saved_in_regs; i++) |
1207 | if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg)) | |
1208 | break; | |
1209 | if (q->saved_reg && i == num_regs_saved_in_regs) | |
1210 | { | |
1211 | if (i == ARRAY_SIZE (regs_saved_in_regs)) | |
1212 | abort (); | |
1213 | num_regs_saved_in_regs++; | |
1214 | } | |
1215 | if (i != num_regs_saved_in_regs) | |
1216 | { | |
1217 | regs_saved_in_regs[i].orig_reg = q->reg; | |
1218 | regs_saved_in_regs[i].saved_in_reg = q->saved_reg; | |
1219 | } | |
1220 | ||
1bac3811 RH |
1221 | reg = DWARF_FRAME_REGNUM (REGNO (q->reg)); |
1222 | if (q->saved_reg) | |
1223 | sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg)); | |
1224 | else | |
1225 | sreg = INVALID_REGNUM; | |
1226 | reg_save (last_reg_save_label, reg, sreg, q->cfa_offset); | |
fbfa55b0 RH |
1227 | } |
1228 | ||
1229 | queued_reg_saves = NULL; | |
1230 | last_reg_save_label = NULL; | |
1231 | } | |
1232 | ||
f8a57be8 GK |
1233 | /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved |
1234 | location for? Or, does it clobber a register which we've previously | |
1235 | said that some other register is saved in, and for which we now | |
1236 | have a new location for? */ | |
1237 | ||
fbfa55b0 | 1238 | static bool |
7080f735 | 1239 | clobbers_queued_reg_save (rtx insn) |
fbfa55b0 RH |
1240 | { |
1241 | struct queued_reg_save *q; | |
1242 | ||
c26fbbca | 1243 | for (q = queued_reg_saves; q; q = q->next) |
f8a57be8 GK |
1244 | { |
1245 | size_t i; | |
1246 | if (modified_in_p (q->reg, insn)) | |
1247 | return true; | |
1248 | for (i = 0; i < num_regs_saved_in_regs; i++) | |
1249 | if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg) | |
1250 | && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn)) | |
1251 | return true; | |
1252 | } | |
fbfa55b0 RH |
1253 | |
1254 | return false; | |
1255 | } | |
c26fbbca | 1256 | |
f8a57be8 GK |
1257 | /* What register, if any, is currently saved in REG? */ |
1258 | ||
1259 | static rtx | |
1260 | reg_saved_in (rtx reg) | |
1261 | { | |
1262 | unsigned int regn = REGNO (reg); | |
1263 | size_t i; | |
1264 | struct queued_reg_save *q; | |
1265 | ||
1266 | for (q = queued_reg_saves; q; q = q->next) | |
1267 | if (q->saved_reg && regn == REGNO (q->saved_reg)) | |
1268 | return q->reg; | |
1269 | ||
1270 | for (i = 0; i < num_regs_saved_in_regs; i++) | |
1271 | if (regs_saved_in_regs[i].saved_in_reg | |
1272 | && regn == REGNO (regs_saved_in_regs[i].saved_in_reg)) | |
1273 | return regs_saved_in_regs[i].orig_reg; | |
1274 | ||
1275 | return NULL_RTX; | |
1276 | } | |
1277 | ||
fbfa55b0 | 1278 | |
770ca8c6 JO |
1279 | /* A temporary register holding an integral value used in adjusting SP |
1280 | or setting up the store_reg. The "offset" field holds the integer | |
1281 | value, not an offset. */ | |
fbfa55b0 | 1282 | static dw_cfa_location cfa_temp; |
770ca8c6 JO |
1283 | |
1284 | /* Record call frame debugging information for an expression EXPR, | |
1285 | which either sets SP or FP (adjusting how we calculate the frame | |
f8a57be8 GK |
1286 | address) or saves a register to the stack or another register. |
1287 | LABEL indicates the address of EXPR. | |
770ca8c6 JO |
1288 | |
1289 | This function encodes a state machine mapping rtxes to actions on | |
1290 | cfa, cfa_store, and cfa_temp.reg. We describe these rules so | |
1291 | users need not read the source code. | |
1292 | ||
a401107d JO |
1293 | The High-Level Picture |
1294 | ||
1295 | Changes in the register we use to calculate the CFA: Currently we | |
1296 | assume that if you copy the CFA register into another register, we | |
1297 | should take the other one as the new CFA register; this seems to | |
1298 | work pretty well. If it's wrong for some target, it's simple | |
1299 | enough not to set RTX_FRAME_RELATED_P on the insn in question. | |
1300 | ||
1301 | Changes in the register we use for saving registers to the stack: | |
1302 | This is usually SP, but not always. Again, we deduce that if you | |
1303 | copy SP into another register (and SP is not the CFA register), | |
1304 | then the new register is the one we will be using for register | |
1305 | saves. This also seems to work. | |
1306 | ||
1307 | Register saves: There's not much guesswork about this one; if | |
1308 | RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a | |
1309 | register save, and the register used to calculate the destination | |
1310 | had better be the one we think we're using for this purpose. | |
f8a57be8 GK |
1311 | It's also assumed that a copy from a call-saved register to another |
1312 | register is saving that register if RTX_FRAME_RELATED_P is set on | |
1313 | that instruction. If the copy is from a call-saved register to | |
1314 | the *same* register, that means that the register is now the same | |
1315 | value as in the caller. | |
a401107d JO |
1316 | |
1317 | Except: If the register being saved is the CFA register, and the | |
cc2902df | 1318 | offset is nonzero, we are saving the CFA, so we assume we have to |
a401107d JO |
1319 | use DW_CFA_def_cfa_expression. If the offset is 0, we assume that |
1320 | the intent is to save the value of SP from the previous frame. | |
1321 | ||
f8a57be8 GK |
1322 | In addition, if a register has previously been saved to a different |
1323 | register, | |
1324 | ||
770ca8c6 JO |
1325 | Invariants / Summaries of Rules |
1326 | ||
a401107d JO |
1327 | cfa current rule for calculating the CFA. It usually |
1328 | consists of a register and an offset. | |
770ca8c6 JO |
1329 | cfa_store register used by prologue code to save things to the stack |
1330 | cfa_store.offset is the offset from the value of | |
1331 | cfa_store.reg to the actual CFA | |
1332 | cfa_temp register holding an integral value. cfa_temp.offset | |
1333 | stores the value, which will be used to adjust the | |
19ec6a36 AM |
1334 | stack pointer. cfa_temp is also used like cfa_store, |
1335 | to track stores to the stack via fp or a temp reg. | |
c26fbbca | 1336 | |
770ca8c6 | 1337 | Rules 1- 4: Setting a register's value to cfa.reg or an expression |
7080f735 | 1338 | with cfa.reg as the first operand changes the cfa.reg and its |
19ec6a36 AM |
1339 | cfa.offset. Rule 1 and 4 also set cfa_temp.reg and |
1340 | cfa_temp.offset. | |
770ca8c6 JO |
1341 | |
1342 | Rules 6- 9: Set a non-cfa.reg register value to a constant or an | |
1343 | expression yielding a constant. This sets cfa_temp.reg | |
1344 | and cfa_temp.offset. | |
1345 | ||
1346 | Rule 5: Create a new register cfa_store used to save items to the | |
1347 | stack. | |
1348 | ||
19ec6a36 | 1349 | Rules 10-14: Save a register to the stack. Define offset as the |
a401107d | 1350 | difference of the original location and cfa_store's |
19ec6a36 | 1351 | location (or cfa_temp's location if cfa_temp is used). |
770ca8c6 JO |
1352 | |
1353 | The Rules | |
1354 | ||
1355 | "{a,b}" indicates a choice of a xor b. | |
1356 | "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg. | |
1357 | ||
1358 | Rule 1: | |
1359 | (set <reg1> <reg2>:cfa.reg) | |
19ec6a36 | 1360 | effects: cfa.reg = <reg1> |
73c68f61 | 1361 | cfa.offset unchanged |
19ec6a36 AM |
1362 | cfa_temp.reg = <reg1> |
1363 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1364 | |
1365 | Rule 2: | |
2ad9852d RK |
1366 | (set sp ({minus,plus,losum} {sp,fp}:cfa.reg |
1367 | {<const_int>,<reg>:cfa_temp.reg})) | |
770ca8c6 | 1368 | effects: cfa.reg = sp if fp used |
7080f735 | 1369 | cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp |
770ca8c6 JO |
1370 | cfa_store.offset += {+/- <const_int>, cfa_temp.offset} |
1371 | if cfa_store.reg==sp | |
1372 | ||
1373 | Rule 3: | |
19ec6a36 | 1374 | (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>)) |
770ca8c6 | 1375 | effects: cfa.reg = fp |
7080f735 | 1376 | cfa_offset += +/- <const_int> |
770ca8c6 JO |
1377 | |
1378 | Rule 4: | |
19ec6a36 | 1379 | (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>)) |
770ca8c6 | 1380 | constraints: <reg1> != fp |
7080f735 | 1381 | <reg1> != sp |
770ca8c6 | 1382 | effects: cfa.reg = <reg1> |
19ec6a36 AM |
1383 | cfa_temp.reg = <reg1> |
1384 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1385 | |
1386 | Rule 5: | |
1387 | (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg)) | |
1388 | constraints: <reg1> != fp | |
7080f735 | 1389 | <reg1> != sp |
770ca8c6 | 1390 | effects: cfa_store.reg = <reg1> |
7080f735 | 1391 | cfa_store.offset = cfa.offset - cfa_temp.offset |
770ca8c6 JO |
1392 | |
1393 | Rule 6: | |
1394 | (set <reg> <const_int>) | |
1395 | effects: cfa_temp.reg = <reg> | |
7080f735 | 1396 | cfa_temp.offset = <const_int> |
770ca8c6 JO |
1397 | |
1398 | Rule 7: | |
1399 | (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>)) | |
1400 | effects: cfa_temp.reg = <reg1> | |
1401 | cfa_temp.offset |= <const_int> | |
1402 | ||
1403 | Rule 8: | |
1404 | (set <reg> (high <exp>)) | |
1405 | effects: none | |
1406 | ||
1407 | Rule 9: | |
1408 | (set <reg> (lo_sum <exp> <const_int>)) | |
1409 | effects: cfa_temp.reg = <reg> | |
7080f735 | 1410 | cfa_temp.offset = <const_int> |
770ca8c6 JO |
1411 | |
1412 | Rule 10: | |
1413 | (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>) | |
1414 | effects: cfa_store.offset -= <const_int> | |
1415 | cfa.offset = cfa_store.offset if cfa.reg == sp | |
770ca8c6 | 1416 | cfa.reg = sp |
19ec6a36 | 1417 | cfa.base_offset = -cfa_store.offset |
770ca8c6 JO |
1418 | |
1419 | Rule 11: | |
1420 | (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>) | |
1421 | effects: cfa_store.offset += -/+ mode_size(mem) | |
1422 | cfa.offset = cfa_store.offset if cfa.reg == sp | |
770ca8c6 | 1423 | cfa.reg = sp |
19ec6a36 | 1424 | cfa.base_offset = -cfa_store.offset |
770ca8c6 JO |
1425 | |
1426 | Rule 12: | |
2ad9852d RK |
1427 | (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) |
1428 | ||
1429 | <reg2>) | |
19ec6a36 AM |
1430 | effects: cfa.reg = <reg1> |
1431 | cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset | |
770ca8c6 JO |
1432 | |
1433 | Rule 13: | |
19ec6a36 AM |
1434 | (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>) |
1435 | effects: cfa.reg = <reg1> | |
1436 | cfa.base_offset = -{cfa_store,cfa_temp}.offset | |
1437 | ||
1438 | Rule 14: | |
1439 | (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>) | |
1440 | effects: cfa.reg = <reg1> | |
1441 | cfa.base_offset = -cfa_temp.offset | |
1442 | cfa_temp.offset -= mode_size(mem) */ | |
b664de3a AM |
1443 | |
1444 | static void | |
7080f735 | 1445 | dwarf2out_frame_debug_expr (rtx expr, const char *label) |
b664de3a AM |
1446 | { |
1447 | rtx src, dest; | |
2ad9852d | 1448 | HOST_WIDE_INT offset; |
556273e0 KH |
1449 | |
1450 | /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of | |
1451 | the PARALLEL independently. The first element is always processed if | |
770ca8c6 | 1452 | it is a SET. This is for backward compatibility. Other elements |
556273e0 KH |
1453 | are processed only if they are SETs and the RTX_FRAME_RELATED_P |
1454 | flag is set in them. */ | |
2ad9852d | 1455 | if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE) |
556273e0 | 1456 | { |
b664de3a AM |
1457 | int par_index; |
1458 | int limit = XVECLEN (expr, 0); | |
1459 | ||
1460 | for (par_index = 0; par_index < limit; par_index++) | |
2ad9852d RK |
1461 | if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET |
1462 | && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index)) | |
1463 | || par_index == 0)) | |
1464 | dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label); | |
556273e0 | 1465 | |
b664de3a AM |
1466 | return; |
1467 | } | |
556273e0 | 1468 | |
b664de3a AM |
1469 | if (GET_CODE (expr) != SET) |
1470 | abort (); | |
1471 | ||
1472 | src = SET_SRC (expr); | |
1473 | dest = SET_DEST (expr); | |
1474 | ||
f8a57be8 GK |
1475 | if (GET_CODE (src) == REG) |
1476 | { | |
1477 | rtx rsi = reg_saved_in (src); | |
1478 | if (rsi) | |
1479 | src = rsi; | |
1480 | } | |
1481 | ||
b664de3a AM |
1482 | switch (GET_CODE (dest)) |
1483 | { | |
1484 | case REG: | |
b664de3a | 1485 | switch (GET_CODE (src)) |
556273e0 KH |
1486 | { |
1487 | /* Setting FP from SP. */ | |
1488 | case REG: | |
1489 | if (cfa.reg == (unsigned) REGNO (src)) | |
f8a57be8 GK |
1490 | { |
1491 | /* Rule 1 */ | |
1492 | /* Update the CFA rule wrt SP or FP. Make sure src is | |
1493 | relative to the current CFA register. | |
1494 | ||
1495 | We used to require that dest be either SP or FP, but the | |
1496 | ARM copies SP to a temporary register, and from there to | |
1497 | FP. So we just rely on the backends to only set | |
1498 | RTX_FRAME_RELATED_P on appropriate insns. */ | |
1499 | cfa.reg = REGNO (dest); | |
1500 | cfa_temp.reg = cfa.reg; | |
1501 | cfa_temp.offset = cfa.offset; | |
1502 | } | |
1503 | else if (call_used_regs [REGNO (dest)] | |
1504 | && ! fixed_regs [REGNO (dest)]) | |
1505 | { | |
1506 | /* Saving a register in a register. */ | |
1507 | queue_reg_save (label, src, dest, 0); | |
1508 | } | |
626d1efd | 1509 | else |
556273e0 | 1510 | abort (); |
556273e0 | 1511 | break; |
b664de3a | 1512 | |
556273e0 KH |
1513 | case PLUS: |
1514 | case MINUS: | |
19ec6a36 | 1515 | case LO_SUM: |
556273e0 KH |
1516 | if (dest == stack_pointer_rtx) |
1517 | { | |
770ca8c6 | 1518 | /* Rule 2 */ |
2618f955 MM |
1519 | /* Adjusting SP. */ |
1520 | switch (GET_CODE (XEXP (src, 1))) | |
1521 | { | |
1522 | case CONST_INT: | |
1523 | offset = INTVAL (XEXP (src, 1)); | |
1524 | break; | |
1525 | case REG: | |
770ca8c6 | 1526 | if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg) |
2618f955 | 1527 | abort (); |
770ca8c6 | 1528 | offset = cfa_temp.offset; |
2618f955 MM |
1529 | break; |
1530 | default: | |
1531 | abort (); | |
1532 | } | |
1533 | ||
1534 | if (XEXP (src, 0) == hard_frame_pointer_rtx) | |
1535 | { | |
1536 | /* Restoring SP from FP in the epilogue. */ | |
7d9d8943 | 1537 | if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM) |
2618f955 | 1538 | abort (); |
7d9d8943 | 1539 | cfa.reg = STACK_POINTER_REGNUM; |
2618f955 | 1540 | } |
19ec6a36 AM |
1541 | else if (GET_CODE (src) == LO_SUM) |
1542 | /* Assume we've set the source reg of the LO_SUM from sp. */ | |
1543 | ; | |
2618f955 MM |
1544 | else if (XEXP (src, 0) != stack_pointer_rtx) |
1545 | abort (); | |
1546 | ||
19ec6a36 | 1547 | if (GET_CODE (src) != MINUS) |
2618f955 | 1548 | offset = -offset; |
7d9d8943 AM |
1549 | if (cfa.reg == STACK_POINTER_REGNUM) |
1550 | cfa.offset += offset; | |
1551 | if (cfa_store.reg == STACK_POINTER_REGNUM) | |
1552 | cfa_store.offset += offset; | |
556273e0 KH |
1553 | } |
1554 | else if (dest == hard_frame_pointer_rtx) | |
1555 | { | |
770ca8c6 | 1556 | /* Rule 3 */ |
2618f955 MM |
1557 | /* Either setting the FP from an offset of the SP, |
1558 | or adjusting the FP */ | |
2c849145 | 1559 | if (! frame_pointer_needed) |
2618f955 MM |
1560 | abort (); |
1561 | ||
f8cfc6aa | 1562 | if (REG_P (XEXP (src, 0)) |
7d9d8943 | 1563 | && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg |
2618f955 MM |
1564 | && GET_CODE (XEXP (src, 1)) == CONST_INT) |
1565 | { | |
2618f955 | 1566 | offset = INTVAL (XEXP (src, 1)); |
19ec6a36 | 1567 | if (GET_CODE (src) != MINUS) |
2618f955 | 1568 | offset = -offset; |
7d9d8943 AM |
1569 | cfa.offset += offset; |
1570 | cfa.reg = HARD_FRAME_POINTER_REGNUM; | |
2618f955 | 1571 | } |
556273e0 KH |
1572 | else |
1573 | abort (); | |
1574 | } | |
1575 | else | |
1576 | { | |
19ec6a36 | 1577 | if (GET_CODE (src) == MINUS) |
2618f955 | 1578 | abort (); |
b53ef1a2 | 1579 | |
770ca8c6 | 1580 | /* Rule 4 */ |
f8cfc6aa | 1581 | if (REG_P (XEXP (src, 0)) |
b53ef1a2 NC |
1582 | && REGNO (XEXP (src, 0)) == cfa.reg |
1583 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
34ce3d7b JM |
1584 | { |
1585 | /* Setting a temporary CFA register that will be copied | |
1586 | into the FP later on. */ | |
19ec6a36 | 1587 | offset = - INTVAL (XEXP (src, 1)); |
34ce3d7b JM |
1588 | cfa.offset += offset; |
1589 | cfa.reg = REGNO (dest); | |
19ec6a36 AM |
1590 | /* Or used to save regs to the stack. */ |
1591 | cfa_temp.reg = cfa.reg; | |
1592 | cfa_temp.offset = cfa.offset; | |
34ce3d7b | 1593 | } |
2ad9852d | 1594 | |
770ca8c6 | 1595 | /* Rule 5 */ |
f8cfc6aa | 1596 | else if (REG_P (XEXP (src, 0)) |
19ec6a36 AM |
1597 | && REGNO (XEXP (src, 0)) == cfa_temp.reg |
1598 | && XEXP (src, 1) == stack_pointer_rtx) | |
b53ef1a2 | 1599 | { |
00a42e21 JM |
1600 | /* Setting a scratch register that we will use instead |
1601 | of SP for saving registers to the stack. */ | |
b53ef1a2 NC |
1602 | if (cfa.reg != STACK_POINTER_REGNUM) |
1603 | abort (); | |
1604 | cfa_store.reg = REGNO (dest); | |
770ca8c6 | 1605 | cfa_store.offset = cfa.offset - cfa_temp.offset; |
b53ef1a2 | 1606 | } |
2ad9852d | 1607 | |
19ec6a36 AM |
1608 | /* Rule 9 */ |
1609 | else if (GET_CODE (src) == LO_SUM | |
1610 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
1611 | { | |
1612 | cfa_temp.reg = REGNO (dest); | |
1613 | cfa_temp.offset = INTVAL (XEXP (src, 1)); | |
1614 | } | |
1615 | else | |
1616 | abort (); | |
556273e0 KH |
1617 | } |
1618 | break; | |
b664de3a | 1619 | |
770ca8c6 | 1620 | /* Rule 6 */ |
556273e0 | 1621 | case CONST_INT: |
770ca8c6 JO |
1622 | cfa_temp.reg = REGNO (dest); |
1623 | cfa_temp.offset = INTVAL (src); | |
556273e0 | 1624 | break; |
b664de3a | 1625 | |
770ca8c6 | 1626 | /* Rule 7 */ |
556273e0 | 1627 | case IOR: |
f8cfc6aa | 1628 | if (!REG_P (XEXP (src, 0)) |
770ca8c6 | 1629 | || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg |
2618f955 | 1630 | || GET_CODE (XEXP (src, 1)) != CONST_INT) |
556273e0 | 1631 | abort (); |
2ad9852d | 1632 | |
770ca8c6 JO |
1633 | if ((unsigned) REGNO (dest) != cfa_temp.reg) |
1634 | cfa_temp.reg = REGNO (dest); | |
1635 | cfa_temp.offset |= INTVAL (XEXP (src, 1)); | |
556273e0 | 1636 | break; |
b664de3a | 1637 | |
9ae21d2a AM |
1638 | /* Skip over HIGH, assuming it will be followed by a LO_SUM, |
1639 | which will fill in all of the bits. */ | |
1640 | /* Rule 8 */ | |
1641 | case HIGH: | |
1642 | break; | |
1643 | ||
556273e0 KH |
1644 | default: |
1645 | abort (); | |
1646 | } | |
2ad9852d | 1647 | |
7d9d8943 | 1648 | def_cfa_1 (label, &cfa); |
2618f955 | 1649 | break; |
b664de3a | 1650 | |
2618f955 | 1651 | case MEM: |
f8cfc6aa | 1652 | if (!REG_P (src)) |
2618f955 | 1653 | abort (); |
7d9d8943 | 1654 | |
7d9d8943 AM |
1655 | /* Saving a register to the stack. Make sure dest is relative to the |
1656 | CFA register. */ | |
2618f955 MM |
1657 | switch (GET_CODE (XEXP (dest, 0))) |
1658 | { | |
770ca8c6 | 1659 | /* Rule 10 */ |
2618f955 | 1660 | /* With a push. */ |
e2134eea JH |
1661 | case PRE_MODIFY: |
1662 | /* We can't handle variable size modifications. */ | |
1663 | if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT) | |
173bf5be | 1664 | abort (); |
e2134eea JH |
1665 | offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1)); |
1666 | ||
1667 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM | |
1668 | || cfa_store.reg != STACK_POINTER_REGNUM) | |
1669 | abort (); | |
2ad9852d | 1670 | |
e2134eea JH |
1671 | cfa_store.offset += offset; |
1672 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1673 | cfa.offset = cfa_store.offset; | |
1674 | ||
1675 | offset = -cfa_store.offset; | |
1676 | break; | |
2ad9852d | 1677 | |
770ca8c6 | 1678 | /* Rule 11 */ |
2618f955 MM |
1679 | case PRE_INC: |
1680 | case PRE_DEC: | |
1681 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1682 | if (GET_CODE (XEXP (dest, 0)) == PRE_INC) | |
1683 | offset = -offset; | |
b664de3a | 1684 | |
2618f955 | 1685 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM |
7d9d8943 | 1686 | || cfa_store.reg != STACK_POINTER_REGNUM) |
2618f955 | 1687 | abort (); |
2ad9852d | 1688 | |
7d9d8943 AM |
1689 | cfa_store.offset += offset; |
1690 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1691 | cfa.offset = cfa_store.offset; | |
b664de3a | 1692 | |
7d9d8943 | 1693 | offset = -cfa_store.offset; |
2618f955 | 1694 | break; |
b664de3a | 1695 | |
770ca8c6 | 1696 | /* Rule 12 */ |
2618f955 MM |
1697 | /* With an offset. */ |
1698 | case PLUS: | |
1699 | case MINUS: | |
19ec6a36 | 1700 | case LO_SUM: |
770ca8c6 JO |
1701 | if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT) |
1702 | abort (); | |
2618f955 MM |
1703 | offset = INTVAL (XEXP (XEXP (dest, 0), 1)); |
1704 | if (GET_CODE (XEXP (dest, 0)) == MINUS) | |
1705 | offset = -offset; | |
b664de3a | 1706 | |
19ec6a36 AM |
1707 | if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) |
1708 | offset -= cfa_store.offset; | |
1709 | else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) | |
1710 | offset -= cfa_temp.offset; | |
1711 | else | |
2618f955 | 1712 | abort (); |
2618f955 MM |
1713 | break; |
1714 | ||
770ca8c6 | 1715 | /* Rule 13 */ |
2618f955 MM |
1716 | /* Without an offset. */ |
1717 | case REG: | |
19ec6a36 AM |
1718 | if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0))) |
1719 | offset = -cfa_store.offset; | |
1720 | else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0))) | |
1721 | offset = -cfa_temp.offset; | |
1722 | else | |
556273e0 | 1723 | abort (); |
19ec6a36 AM |
1724 | break; |
1725 | ||
1726 | /* Rule 14 */ | |
1727 | case POST_INC: | |
1728 | if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) | |
1729 | abort (); | |
1730 | offset = -cfa_temp.offset; | |
1731 | cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest)); | |
2618f955 MM |
1732 | break; |
1733 | ||
1734 | default: | |
1735 | abort (); | |
1736 | } | |
e09bbb25 | 1737 | |
556273e0 | 1738 | if (REGNO (src) != STACK_POINTER_REGNUM |
e09bbb25 JM |
1739 | && REGNO (src) != HARD_FRAME_POINTER_REGNUM |
1740 | && (unsigned) REGNO (src) == cfa.reg) | |
1741 | { | |
1742 | /* We're storing the current CFA reg into the stack. */ | |
1743 | ||
1744 | if (cfa.offset == 0) | |
1745 | { | |
1746 | /* If the source register is exactly the CFA, assume | |
1747 | we're saving SP like any other register; this happens | |
1748 | on the ARM. */ | |
e09bbb25 | 1749 | def_cfa_1 (label, &cfa); |
f8a57be8 | 1750 | queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset); |
e09bbb25 JM |
1751 | break; |
1752 | } | |
1753 | else | |
1754 | { | |
1755 | /* Otherwise, we'll need to look in the stack to | |
73c68f61 | 1756 | calculate the CFA. */ |
e09bbb25 | 1757 | rtx x = XEXP (dest, 0); |
2ad9852d | 1758 | |
f8cfc6aa | 1759 | if (!REG_P (x)) |
e09bbb25 | 1760 | x = XEXP (x, 0); |
f8cfc6aa | 1761 | if (!REG_P (x)) |
e09bbb25 | 1762 | abort (); |
2ad9852d RK |
1763 | |
1764 | cfa.reg = REGNO (x); | |
e09bbb25 JM |
1765 | cfa.base_offset = offset; |
1766 | cfa.indirect = 1; | |
1767 | def_cfa_1 (label, &cfa); | |
1768 | break; | |
1769 | } | |
1770 | } | |
1771 | ||
7d9d8943 | 1772 | def_cfa_1 (label, &cfa); |
f8a57be8 | 1773 | queue_reg_save (label, src, NULL_RTX, offset); |
2618f955 MM |
1774 | break; |
1775 | ||
1776 | default: | |
1777 | abort (); | |
1778 | } | |
b664de3a AM |
1779 | } |
1780 | ||
3f76745e JM |
1781 | /* Record call frame debugging information for INSN, which either |
1782 | sets SP or FP (adjusting how we calculate the frame address) or saves a | |
1783 | register to the stack. If INSN is NULL_RTX, initialize our state. */ | |
71dfc51f | 1784 | |
3f76745e | 1785 | void |
7080f735 | 1786 | dwarf2out_frame_debug (rtx insn) |
a3f97cbb | 1787 | { |
d3e3972c | 1788 | const char *label; |
b664de3a | 1789 | rtx src; |
3f76745e JM |
1790 | |
1791 | if (insn == NULL_RTX) | |
a3f97cbb | 1792 | { |
f8a57be8 GK |
1793 | size_t i; |
1794 | ||
fbfa55b0 RH |
1795 | /* Flush any queued register saves. */ |
1796 | flush_queued_reg_saves (); | |
1797 | ||
3f76745e | 1798 | /* Set up state for generating call frame debug info. */ |
7d9d8943 AM |
1799 | lookup_cfa (&cfa); |
1800 | if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)) | |
3a88cbd1 | 1801 | abort (); |
2ad9852d | 1802 | |
7d9d8943 AM |
1803 | cfa.reg = STACK_POINTER_REGNUM; |
1804 | cfa_store = cfa; | |
770ca8c6 JO |
1805 | cfa_temp.reg = -1; |
1806 | cfa_temp.offset = 0; | |
f8a57be8 GK |
1807 | |
1808 | for (i = 0; i < num_regs_saved_in_regs; i++) | |
1809 | { | |
1810 | regs_saved_in_regs[i].orig_reg = NULL_RTX; | |
1811 | regs_saved_in_regs[i].saved_in_reg = NULL_RTX; | |
1812 | } | |
1813 | num_regs_saved_in_regs = 0; | |
3f76745e JM |
1814 | return; |
1815 | } | |
1816 | ||
4b4bf941 | 1817 | if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn)) |
fbfa55b0 RH |
1818 | flush_queued_reg_saves (); |
1819 | ||
0021b564 JM |
1820 | if (! RTX_FRAME_RELATED_P (insn)) |
1821 | { | |
fbfa55b0 | 1822 | if (!ACCUMULATE_OUTGOING_ARGS) |
c26fbbca | 1823 | dwarf2out_stack_adjust (insn); |
2ad9852d | 1824 | |
0021b564 JM |
1825 | return; |
1826 | } | |
1827 | ||
3f76745e | 1828 | label = dwarf2out_cfi_label (); |
07ebc930 RH |
1829 | src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX); |
1830 | if (src) | |
1831 | insn = XEXP (src, 0); | |
556273e0 | 1832 | else |
07ebc930 RH |
1833 | insn = PATTERN (insn); |
1834 | ||
b664de3a | 1835 | dwarf2out_frame_debug_expr (insn, label); |
3f76745e JM |
1836 | } |
1837 | ||
17211ab5 GK |
1838 | #endif |
1839 | ||
1840 | /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */ | |
7080f735 AJ |
1841 | static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc |
1842 | (enum dwarf_call_frame_info cfi); | |
17211ab5 GK |
1843 | |
1844 | static enum dw_cfi_oprnd_type | |
7080f735 | 1845 | dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi) |
17211ab5 GK |
1846 | { |
1847 | switch (cfi) | |
1848 | { | |
1849 | case DW_CFA_nop: | |
1850 | case DW_CFA_GNU_window_save: | |
1851 | return dw_cfi_oprnd_unused; | |
1852 | ||
1853 | case DW_CFA_set_loc: | |
1854 | case DW_CFA_advance_loc1: | |
1855 | case DW_CFA_advance_loc2: | |
1856 | case DW_CFA_advance_loc4: | |
1857 | case DW_CFA_MIPS_advance_loc8: | |
1858 | return dw_cfi_oprnd_addr; | |
1859 | ||
1860 | case DW_CFA_offset: | |
1861 | case DW_CFA_offset_extended: | |
1862 | case DW_CFA_def_cfa: | |
1863 | case DW_CFA_offset_extended_sf: | |
1864 | case DW_CFA_def_cfa_sf: | |
1865 | case DW_CFA_restore_extended: | |
1866 | case DW_CFA_undefined: | |
1867 | case DW_CFA_same_value: | |
1868 | case DW_CFA_def_cfa_register: | |
1869 | case DW_CFA_register: | |
1870 | return dw_cfi_oprnd_reg_num; | |
1871 | ||
1872 | case DW_CFA_def_cfa_offset: | |
1873 | case DW_CFA_GNU_args_size: | |
1874 | case DW_CFA_def_cfa_offset_sf: | |
1875 | return dw_cfi_oprnd_offset; | |
7080f735 | 1876 | |
17211ab5 GK |
1877 | case DW_CFA_def_cfa_expression: |
1878 | case DW_CFA_expression: | |
1879 | return dw_cfi_oprnd_loc; | |
1880 | ||
1881 | default: | |
1882 | abort (); | |
1883 | } | |
1884 | } | |
1885 | ||
1886 | /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */ | |
7080f735 AJ |
1887 | static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc |
1888 | (enum dwarf_call_frame_info cfi); | |
17211ab5 GK |
1889 | |
1890 | static enum dw_cfi_oprnd_type | |
7080f735 | 1891 | dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi) |
17211ab5 GK |
1892 | { |
1893 | switch (cfi) | |
1894 | { | |
1895 | case DW_CFA_def_cfa: | |
1896 | case DW_CFA_def_cfa_sf: | |
1897 | case DW_CFA_offset: | |
1898 | case DW_CFA_offset_extended_sf: | |
1899 | case DW_CFA_offset_extended: | |
1900 | return dw_cfi_oprnd_offset; | |
1901 | ||
1902 | case DW_CFA_register: | |
1903 | return dw_cfi_oprnd_reg_num; | |
1904 | ||
1905 | default: | |
1906 | return dw_cfi_oprnd_unused; | |
1907 | } | |
1908 | } | |
1909 | ||
1910 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) | |
1911 | ||
34c80057 AM |
1912 | /* Map register numbers held in the call frame info that gcc has |
1913 | collected using DWARF_FRAME_REGNUM to those that should be output in | |
1914 | .debug_frame and .eh_frame. */ | |
1915 | #ifndef DWARF2_FRAME_REG_OUT | |
1916 | #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO) | |
1917 | #endif | |
1918 | ||
3f76745e JM |
1919 | /* Output a Call Frame Information opcode and its operand(s). */ |
1920 | ||
1921 | static void | |
7080f735 | 1922 | output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh) |
3f76745e | 1923 | { |
34c80057 | 1924 | unsigned long r; |
3f76745e | 1925 | if (cfi->dw_cfi_opc == DW_CFA_advance_loc) |
2ad9852d RK |
1926 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1927 | | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)), | |
38f9cd4c | 1928 | "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX, |
2ad9852d | 1929 | cfi->dw_cfi_oprnd1.dw_cfi_offset); |
3f76745e JM |
1930 | else if (cfi->dw_cfi_opc == DW_CFA_offset) |
1931 | { | |
34c80057 AM |
1932 | r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh); |
1933 | dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)), | |
1934 | "DW_CFA_offset, column 0x%lx", r); | |
2e4b9b8c | 1935 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); |
3f76745e JM |
1936 | } |
1937 | else if (cfi->dw_cfi_opc == DW_CFA_restore) | |
34c80057 AM |
1938 | { |
1939 | r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh); | |
1940 | dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)), | |
1941 | "DW_CFA_restore, column 0x%lx", r); | |
1942 | } | |
3f76745e JM |
1943 | else |
1944 | { | |
2e4b9b8c RH |
1945 | dw2_asm_output_data (1, cfi->dw_cfi_opc, |
1946 | "%s", dwarf_cfi_name (cfi->dw_cfi_opc)); | |
3f76745e | 1947 | |
3f76745e JM |
1948 | switch (cfi->dw_cfi_opc) |
1949 | { | |
1950 | case DW_CFA_set_loc: | |
e1f9550a RH |
1951 | if (for_eh) |
1952 | dw2_asm_output_encoded_addr_rtx ( | |
1953 | ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0), | |
1954 | gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr), | |
1955 | NULL); | |
1956 | else | |
1957 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, | |
1958 | cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL); | |
3f76745e | 1959 | break; |
2ad9852d | 1960 | |
3f76745e | 1961 | case DW_CFA_advance_loc1: |
2e4b9b8c RH |
1962 | dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1963 | fde->dw_fde_current_label, NULL); | |
bb727b5a | 1964 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
3f76745e | 1965 | break; |
2ad9852d | 1966 | |
3f76745e | 1967 | case DW_CFA_advance_loc2: |
2e4b9b8c RH |
1968 | dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1969 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
1970 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
1971 | break; | |
2ad9852d | 1972 | |
3f76745e | 1973 | case DW_CFA_advance_loc4: |
2e4b9b8c RH |
1974 | dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1975 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
1976 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
1977 | break; | |
2ad9852d | 1978 | |
3f76745e | 1979 | case DW_CFA_MIPS_advance_loc8: |
2e4b9b8c RH |
1980 | dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1981 | fde->dw_fde_current_label, NULL); | |
1982 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
3f76745e | 1983 | break; |
2ad9852d | 1984 | |
3f76745e JM |
1985 | case DW_CFA_offset_extended: |
1986 | case DW_CFA_def_cfa: | |
34c80057 AM |
1987 | r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh); |
1988 | dw2_asm_output_data_uleb128 (r, NULL); | |
2e4b9b8c | 1989 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); |
3f76745e | 1990 | break; |
2ad9852d | 1991 | |
6bb28965 JM |
1992 | case DW_CFA_offset_extended_sf: |
1993 | case DW_CFA_def_cfa_sf: | |
34c80057 AM |
1994 | r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh); |
1995 | dw2_asm_output_data_uleb128 (r, NULL); | |
6bb28965 JM |
1996 | dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); |
1997 | break; | |
1998 | ||
3f76745e JM |
1999 | case DW_CFA_restore_extended: |
2000 | case DW_CFA_undefined: | |
3f76745e JM |
2001 | case DW_CFA_same_value: |
2002 | case DW_CFA_def_cfa_register: | |
34c80057 AM |
2003 | r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh); |
2004 | dw2_asm_output_data_uleb128 (r, NULL); | |
3f76745e | 2005 | break; |
2ad9852d | 2006 | |
3f76745e | 2007 | case DW_CFA_register: |
34c80057 AM |
2008 | r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh); |
2009 | dw2_asm_output_data_uleb128 (r, NULL); | |
2010 | r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh); | |
2011 | dw2_asm_output_data_uleb128 (r, NULL); | |
3f76745e | 2012 | break; |
2ad9852d | 2013 | |
3f76745e | 2014 | case DW_CFA_def_cfa_offset: |
2e4b9b8c RH |
2015 | case DW_CFA_GNU_args_size: |
2016 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL); | |
3f76745e | 2017 | break; |
2ad9852d | 2018 | |
6bb28965 JM |
2019 | case DW_CFA_def_cfa_offset_sf: |
2020 | dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL); | |
2021 | break; | |
2022 | ||
c53aa195 JM |
2023 | case DW_CFA_GNU_window_save: |
2024 | break; | |
2ad9852d | 2025 | |
7d9d8943 | 2026 | case DW_CFA_def_cfa_expression: |
6bb28965 | 2027 | case DW_CFA_expression: |
7d9d8943 AM |
2028 | output_cfa_loc (cfi); |
2029 | break; | |
2ad9852d | 2030 | |
6bb28965 JM |
2031 | case DW_CFA_GNU_negative_offset_extended: |
2032 | /* Obsoleted by DW_CFA_offset_extended_sf. */ | |
2033 | abort (); | |
2034 | ||
3f76745e JM |
2035 | default: |
2036 | break; | |
2037 | } | |
556273e0 | 2038 | } |
3f76745e JM |
2039 | } |
2040 | ||
34c80057 | 2041 | /* Output the call frame information used to record information |
3f76745e JM |
2042 | that relates to calculating the frame pointer, and records the |
2043 | location of saved registers. */ | |
2044 | ||
2045 | static void | |
7080f735 | 2046 | output_call_frame_info (int for_eh) |
3f76745e | 2047 | { |
b3694847 SS |
2048 | unsigned int i; |
2049 | dw_fde_ref fde; | |
2050 | dw_cfi_ref cfi; | |
27d95cbe | 2051 | char l1[20], l2[20], section_start_label[20]; |
ad5eeaa9 | 2052 | bool any_lsda_needed = false; |
52a11cbf | 2053 | char augmentation[6]; |
e1f9550a RH |
2054 | int augmentation_size; |
2055 | int fde_encoding = DW_EH_PE_absptr; | |
2056 | int per_encoding = DW_EH_PE_absptr; | |
2057 | int lsda_encoding = DW_EH_PE_absptr; | |
3f76745e | 2058 | |
29b91443 JM |
2059 | /* Don't emit a CIE if there won't be any FDEs. */ |
2060 | if (fde_table_in_use == 0) | |
2061 | return; | |
2062 | ||
4746cf84 MA |
2063 | /* If we make FDEs linkonce, we may have to emit an empty label for |
2064 | an FDE that wouldn't otherwise be emitted. We want to avoid | |
2065 | having an FDE kept around when the function it refers to is | |
2066 | discarded. (Example where this matters: a primary function | |
2067 | template in C++ requires EH information, but an explicit | |
9cf737f8 | 2068 | specialization doesn't. */ |
4746cf84 MA |
2069 | if (TARGET_USES_WEAK_UNWIND_INFO |
2070 | && ! flag_asynchronous_unwind_tables | |
2071 | && for_eh) | |
2072 | for (i = 0; i < fde_table_in_use; i++) | |
2073 | if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls) | |
2074 | && !fde_table[i].uses_eh_lsda | |
2075 | && ! DECL_ONE_ONLY (fde_table[i].decl)) | |
5fd9b178 | 2076 | targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl, |
eeab4d81 | 2077 | for_eh, /* empty */ 1); |
4746cf84 | 2078 | |
ad5eeaa9 RH |
2079 | /* If we don't have any functions we'll want to unwind out of, don't |
2080 | emit any EH unwind information. Note that if exceptions aren't | |
2081 | enabled, we won't have collected nothrow information, and if we | |
2082 | asked for asynchronous tables, we always want this info. */ | |
737faf14 JM |
2083 | if (for_eh) |
2084 | { | |
ad5eeaa9 | 2085 | bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables; |
2ad9852d RK |
2086 | |
2087 | for (i = 0; i < fde_table_in_use; i++) | |
52a11cbf | 2088 | if (fde_table[i].uses_eh_lsda) |
ad5eeaa9 | 2089 | any_eh_needed = any_lsda_needed = true; |
4746cf84 MA |
2090 | else if (TARGET_USES_WEAK_UNWIND_INFO |
2091 | && DECL_ONE_ONLY (fde_table[i].decl)) | |
2092 | any_eh_needed = 1; | |
0366359a GK |
2093 | else if (! fde_table[i].nothrow |
2094 | && ! fde_table[i].all_throwers_are_sibcalls) | |
ad5eeaa9 | 2095 | any_eh_needed = true; |
52a11cbf RH |
2096 | |
2097 | if (! any_eh_needed) | |
2098 | return; | |
737faf14 JM |
2099 | } |
2100 | ||
aa0c1401 JL |
2101 | /* We're going to be generating comments, so turn on app. */ |
2102 | if (flag_debug_asm) | |
2103 | app_enable (); | |
956d6950 | 2104 | |
3f76745e | 2105 | if (for_eh) |
5fd9b178 | 2106 | targetm.asm_out.eh_frame_section (); |
3f76745e | 2107 | else |
715bdd29 | 2108 | named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG); |
3f76745e | 2109 | |
27d95cbe RH |
2110 | ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh); |
2111 | ASM_OUTPUT_LABEL (asm_out_file, section_start_label); | |
2112 | ||
556273e0 | 2113 | /* Output the CIE. */ |
a6ab3aad JM |
2114 | ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh); |
2115 | ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh); | |
2e4b9b8c RH |
2116 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
2117 | "Length of Common Information Entry"); | |
a6ab3aad JM |
2118 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
2119 | ||
2e4b9b8c RH |
2120 | /* Now that the CIE pointer is PC-relative for EH, |
2121 | use 0 to identify the CIE. */ | |
2122 | dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE), | |
2123 | (for_eh ? 0 : DW_CIE_ID), | |
2124 | "CIE Identifier Tag"); | |
3f76745e | 2125 | |
2e4b9b8c | 2126 | dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version"); |
3f76745e | 2127 | |
52a11cbf | 2128 | augmentation[0] = 0; |
e1f9550a | 2129 | augmentation_size = 0; |
52a11cbf | 2130 | if (for_eh) |
a6ab3aad | 2131 | { |
e1f9550a RH |
2132 | char *p; |
2133 | ||
52a11cbf RH |
2134 | /* Augmentation: |
2135 | z Indicates that a uleb128 is present to size the | |
7080f735 | 2136 | augmentation section. |
e1f9550a RH |
2137 | L Indicates the encoding (and thus presence) of |
2138 | an LSDA pointer in the FDE augmentation. | |
2139 | R Indicates a non-default pointer encoding for | |
2140 | FDE code pointers. | |
2141 | P Indicates the presence of an encoding + language | |
2142 | personality routine in the CIE augmentation. */ | |
2143 | ||
4746cf84 MA |
2144 | fde_encoding = TARGET_USES_WEAK_UNWIND_INFO |
2145 | ? ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1) | |
2146 | : ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0); | |
e1f9550a RH |
2147 | per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1); |
2148 | lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0); | |
2149 | ||
2150 | p = augmentation + 1; | |
2151 | if (eh_personality_libfunc) | |
2152 | { | |
2153 | *p++ = 'P'; | |
2154 | augmentation_size += 1 + size_of_encoded_value (per_encoding); | |
2155 | } | |
52a11cbf | 2156 | if (any_lsda_needed) |
e1f9550a RH |
2157 | { |
2158 | *p++ = 'L'; | |
2159 | augmentation_size += 1; | |
2160 | } | |
2161 | if (fde_encoding != DW_EH_PE_absptr) | |
2162 | { | |
2163 | *p++ = 'R'; | |
2164 | augmentation_size += 1; | |
2165 | } | |
2166 | if (p > augmentation + 1) | |
2167 | { | |
2168 | augmentation[0] = 'z'; | |
c26fbbca | 2169 | *p = '\0'; |
e1f9550a | 2170 | } |
099c8b17 RH |
2171 | |
2172 | /* Ug. Some platforms can't do unaligned dynamic relocations at all. */ | |
2173 | if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned) | |
2174 | { | |
2175 | int offset = ( 4 /* Length */ | |
2176 | + 4 /* CIE Id */ | |
2177 | + 1 /* CIE version */ | |
2178 | + strlen (augmentation) + 1 /* Augmentation */ | |
2179 | + size_of_uleb128 (1) /* Code alignment */ | |
2180 | + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT) | |
2181 | + 1 /* RA column */ | |
2182 | + 1 /* Augmentation size */ | |
2183 | + 1 /* Personality encoding */ ); | |
2184 | int pad = -offset & (PTR_SIZE - 1); | |
2185 | ||
2186 | augmentation_size += pad; | |
2187 | ||
2188 | /* Augmentations should be small, so there's scarce need to | |
2189 | iterate for a solution. Die if we exceed one uleb128 byte. */ | |
2190 | if (size_of_uleb128 (augmentation_size) != 1) | |
2191 | abort (); | |
2192 | } | |
a6ab3aad | 2193 | } |
3f76745e | 2194 | |
2ad9852d | 2195 | dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation"); |
2e4b9b8c | 2196 | dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor"); |
2e4b9b8c RH |
2197 | dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT, |
2198 | "CIE Data Alignment Factor"); | |
fc9c8ce1 PB |
2199 | |
2200 | if (DW_CIE_VERSION == 1) | |
2201 | dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column"); | |
2202 | else | |
2203 | dw2_asm_output_data_uleb128 (DWARF_FRAME_RETURN_COLUMN, "CIE RA Column"); | |
3f76745e | 2204 | |
52a11cbf RH |
2205 | if (augmentation[0]) |
2206 | { | |
e1f9550a | 2207 | dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size"); |
52a11cbf | 2208 | if (eh_personality_libfunc) |
e1f9550a RH |
2209 | { |
2210 | dw2_asm_output_data (1, per_encoding, "Personality (%s)", | |
2211 | eh_data_format_name (per_encoding)); | |
2212 | dw2_asm_output_encoded_addr_rtx (per_encoding, | |
2213 | eh_personality_libfunc, NULL); | |
2214 | } | |
2ad9852d | 2215 | |
e1f9550a RH |
2216 | if (any_lsda_needed) |
2217 | dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)", | |
2218 | eh_data_format_name (lsda_encoding)); | |
2ad9852d | 2219 | |
e1f9550a RH |
2220 | if (fde_encoding != DW_EH_PE_absptr) |
2221 | dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)", | |
2222 | eh_data_format_name (fde_encoding)); | |
52a11cbf RH |
2223 | } |
2224 | ||
3f76745e | 2225 | for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next) |
12f0b96b | 2226 | output_cfi (cfi, NULL, for_eh); |
3f76745e JM |
2227 | |
2228 | /* Pad the CIE out to an address sized boundary. */ | |
c26fbbca | 2229 | ASM_OUTPUT_ALIGN (asm_out_file, |
12f0b96b | 2230 | floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)); |
a6ab3aad | 2231 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e JM |
2232 | |
2233 | /* Loop through all of the FDE's. */ | |
2ad9852d | 2234 | for (i = 0; i < fde_table_in_use; i++) |
3f76745e JM |
2235 | { |
2236 | fde = &fde_table[i]; | |
3f76745e | 2237 | |
52a11cbf | 2238 | /* Don't emit EH unwind info for leaf functions that don't need it. */ |
ad5eeaa9 | 2239 | if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions |
b6128b8c | 2240 | && (fde->nothrow || fde->all_throwers_are_sibcalls) |
4746cf84 | 2241 | && (! TARGET_USES_WEAK_UNWIND_INFO || ! DECL_ONE_ONLY (fde->decl)) |
b6128b8c | 2242 | && !fde->uses_eh_lsda) |
737faf14 JM |
2243 | continue; |
2244 | ||
eeab4d81 | 2245 | targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0); |
5fd9b178 | 2246 | targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2); |
556273e0 KH |
2247 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2); |
2248 | ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2); | |
2e4b9b8c RH |
2249 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
2250 | "FDE Length"); | |
a6ab3aad JM |
2251 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
2252 | ||
3f76745e | 2253 | if (for_eh) |
27d95cbe | 2254 | dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset"); |
3f76745e | 2255 | else |
27d95cbe | 2256 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label, |
2e4b9b8c | 2257 | "FDE CIE offset"); |
3f76745e | 2258 | |
e1f9550a RH |
2259 | if (for_eh) |
2260 | { | |
4746cf84 MA |
2261 | if (TARGET_USES_WEAK_UNWIND_INFO |
2262 | && DECL_ONE_ONLY (fde->decl)) | |
2263 | dw2_asm_output_encoded_addr_rtx (fde_encoding, | |
2264 | gen_rtx_SYMBOL_REF (Pmode, IDENTIFIER_POINTER | |
2265 | (DECL_ASSEMBLER_NAME (fde->decl))), | |
2266 | "FDE initial location"); | |
2267 | else | |
11abc112 MM |
2268 | { |
2269 | rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin); | |
2270 | SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL; | |
2271 | dw2_asm_output_encoded_addr_rtx (fde_encoding, | |
2272 | sym_ref, | |
2273 | "FDE initial location"); | |
2274 | } | |
e1f9550a | 2275 | dw2_asm_output_delta (size_of_encoded_value (fde_encoding), |
c26fbbca | 2276 | fde->dw_fde_end, fde->dw_fde_begin, |
e1f9550a RH |
2277 | "FDE address range"); |
2278 | } | |
2279 | else | |
2280 | { | |
2281 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin, | |
2282 | "FDE initial location"); | |
c26fbbca KH |
2283 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, |
2284 | fde->dw_fde_end, fde->dw_fde_begin, | |
e1f9550a RH |
2285 | "FDE address range"); |
2286 | } | |
3f76745e | 2287 | |
52a11cbf RH |
2288 | if (augmentation[0]) |
2289 | { | |
e1f9550a | 2290 | if (any_lsda_needed) |
52a11cbf | 2291 | { |
099c8b17 RH |
2292 | int size = size_of_encoded_value (lsda_encoding); |
2293 | ||
2294 | if (lsda_encoding == DW_EH_PE_aligned) | |
2295 | { | |
2296 | int offset = ( 4 /* Length */ | |
2297 | + 4 /* CIE offset */ | |
2298 | + 2 * size_of_encoded_value (fde_encoding) | |
2299 | + 1 /* Augmentation size */ ); | |
2300 | int pad = -offset & (PTR_SIZE - 1); | |
2301 | ||
2302 | size += pad; | |
2303 | if (size_of_uleb128 (size) != 1) | |
2304 | abort (); | |
2305 | } | |
2306 | ||
2307 | dw2_asm_output_data_uleb128 (size, "Augmentation size"); | |
e1f9550a RH |
2308 | |
2309 | if (fde->uses_eh_lsda) | |
73c68f61 SS |
2310 | { |
2311 | ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA", | |
e1f9550a | 2312 | fde->funcdef_number); |
73c68f61 | 2313 | dw2_asm_output_encoded_addr_rtx ( |
e1f9550a | 2314 | lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1), |
7080f735 | 2315 | "Language Specific Data Area"); |
73c68f61 | 2316 | } |
e1f9550a | 2317 | else |
099c8b17 RH |
2318 | { |
2319 | if (lsda_encoding == DW_EH_PE_aligned) | |
2320 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); | |
2ad9852d RK |
2321 | dw2_asm_output_data |
2322 | (size_of_encoded_value (lsda_encoding), 0, | |
2323 | "Language Specific Data Area (none)"); | |
099c8b17 | 2324 | } |
52a11cbf RH |
2325 | } |
2326 | else | |
e1f9550a | 2327 | dw2_asm_output_data_uleb128 (0, "Augmentation size"); |
52a11cbf RH |
2328 | } |
2329 | ||
3f76745e JM |
2330 | /* Loop through the Call Frame Instructions associated with |
2331 | this FDE. */ | |
2332 | fde->dw_fde_current_label = fde->dw_fde_begin; | |
2333 | for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next) | |
12f0b96b | 2334 | output_cfi (cfi, fde, for_eh); |
3f76745e | 2335 | |
a6ab3aad | 2336 | /* Pad the FDE out to an address sized boundary. */ |
c26fbbca | 2337 | ASM_OUTPUT_ALIGN (asm_out_file, |
73c68f61 | 2338 | floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE))); |
a6ab3aad | 2339 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e | 2340 | } |
2e4b9b8c | 2341 | |
7606e68f | 2342 | if (for_eh && targetm.terminate_dw2_eh_frame_info) |
2e4b9b8c | 2343 | dw2_asm_output_data (4, 0, "End of Table"); |
a6ab3aad JM |
2344 | #ifdef MIPS_DEBUGGING_INFO |
2345 | /* Work around Irix 6 assembler bug whereby labels at the end of a section | |
2346 | get a value of 0. Putting .align 0 after the label fixes it. */ | |
2347 | ASM_OUTPUT_ALIGN (asm_out_file, 0); | |
2348 | #endif | |
aa0c1401 JL |
2349 | |
2350 | /* Turn off app to make assembly quicker. */ | |
2351 | if (flag_debug_asm) | |
2352 | app_disable (); | |
a6ab3aad JM |
2353 | } |
2354 | ||
3f76745e JM |
2355 | /* Output a marker (i.e. a label) for the beginning of a function, before |
2356 | the prologue. */ | |
2357 | ||
2358 | void | |
7080f735 AJ |
2359 | dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED, |
2360 | const char *file ATTRIBUTE_UNUSED) | |
3f76745e JM |
2361 | { |
2362 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 | 2363 | dw_fde_ref fde; |
3f76745e | 2364 | |
2a1ee410 RH |
2365 | current_function_func_begin_label = 0; |
2366 | ||
951120ea | 2367 | #ifdef TARGET_UNWIND_INFO |
2a1ee410 RH |
2368 | /* ??? current_function_func_begin_label is also used by except.c |
2369 | for call-site information. We must emit this label if it might | |
2370 | be used. */ | |
2371 | if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS) | |
2372 | && ! dwarf2out_do_frame ()) | |
2373 | return; | |
2374 | #else | |
2375 | if (! dwarf2out_do_frame ()) | |
2376 | return; | |
2377 | #endif | |
2378 | ||
3f76745e JM |
2379 | function_section (current_function_decl); |
2380 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL, | |
df696a75 | 2381 | current_function_funcdef_no); |
2a1ee410 | 2382 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL, |
df696a75 | 2383 | current_function_funcdef_no); |
00262c8a | 2384 | current_function_func_begin_label = get_identifier (label); |
3f76745e | 2385 | |
951120ea | 2386 | #ifdef TARGET_UNWIND_INFO |
2a1ee410 RH |
2387 | /* We can elide the fde allocation if we're not emitting debug info. */ |
2388 | if (! dwarf2out_do_frame ()) | |
2389 | return; | |
2390 | #endif | |
2391 | ||
3f76745e JM |
2392 | /* Expand the fde table if necessary. */ |
2393 | if (fde_table_in_use == fde_table_allocated) | |
2394 | { | |
2395 | fde_table_allocated += FDE_TABLE_INCREMENT; | |
17211ab5 GK |
2396 | fde_table = ggc_realloc (fde_table, |
2397 | fde_table_allocated * sizeof (dw_fde_node)); | |
2398 | memset (fde_table + fde_table_in_use, 0, | |
2399 | FDE_TABLE_INCREMENT * sizeof (dw_fde_node)); | |
a3f97cbb | 2400 | } |
3f76745e JM |
2401 | |
2402 | /* Record the FDE associated with this function. */ | |
2403 | current_funcdef_fde = fde_table_in_use; | |
2404 | ||
2405 | /* Add the new FDE at the end of the fde_table. */ | |
2406 | fde = &fde_table[fde_table_in_use++]; | |
4746cf84 | 2407 | fde->decl = current_function_decl; |
3f76745e JM |
2408 | fde->dw_fde_begin = xstrdup (label); |
2409 | fde->dw_fde_current_label = NULL; | |
2410 | fde->dw_fde_end = NULL; | |
2411 | fde->dw_fde_cfi = NULL; | |
df696a75 | 2412 | fde->funcdef_number = current_function_funcdef_no; |
97b0ade3 | 2413 | fde->nothrow = TREE_NOTHROW (current_function_decl); |
52a11cbf | 2414 | fde->uses_eh_lsda = cfun->uses_eh_lsda; |
b6128b8c | 2415 | fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls; |
737faf14 | 2416 | |
b57d9225 | 2417 | args_size = old_args_size = 0; |
653e276c | 2418 | |
2ad9852d RK |
2419 | /* We only want to output line number information for the genuine dwarf2 |
2420 | prologue case, not the eh frame case. */ | |
653e276c NB |
2421 | #ifdef DWARF2_DEBUGGING_INFO |
2422 | if (file) | |
2423 | dwarf2out_source_line (line, file); | |
2424 | #endif | |
3f76745e JM |
2425 | } |
2426 | ||
2427 | /* Output a marker (i.e. a label) for the absolute end of the generated code | |
2428 | for a function definition. This gets called *after* the epilogue code has | |
2429 | been generated. */ | |
2430 | ||
2431 | void | |
7080f735 AJ |
2432 | dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED, |
2433 | const char *file ATTRIBUTE_UNUSED) | |
3f76745e JM |
2434 | { |
2435 | dw_fde_ref fde; | |
2436 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2437 | ||
2438 | /* Output a label to mark the endpoint of the code generated for this | |
3ef42a0c | 2439 | function. */ |
df696a75 RH |
2440 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, |
2441 | current_function_funcdef_no); | |
3f76745e JM |
2442 | ASM_OUTPUT_LABEL (asm_out_file, label); |
2443 | fde = &fde_table[fde_table_in_use - 1]; | |
2444 | fde->dw_fde_end = xstrdup (label); | |
3f76745e JM |
2445 | } |
2446 | ||
2447 | void | |
7080f735 | 2448 | dwarf2out_frame_init (void) |
3f76745e JM |
2449 | { |
2450 | /* Allocate the initial hunk of the fde_table. */ | |
703ad42b | 2451 | fde_table = ggc_alloc_cleared (FDE_TABLE_INCREMENT * sizeof (dw_fde_node)); |
3f76745e JM |
2452 | fde_table_allocated = FDE_TABLE_INCREMENT; |
2453 | fde_table_in_use = 0; | |
2454 | ||
2455 | /* Generate the CFA instructions common to all FDE's. Do it now for the | |
2456 | sake of lookup_cfa. */ | |
2457 | ||
a6ab3aad | 2458 | #ifdef DWARF2_UNWIND_INFO |
91193900 AS |
2459 | /* On entry, the Canonical Frame Address is at SP. */ |
2460 | dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET); | |
2461 | initial_return_save (INCOMING_RETURN_ADDR_RTX); | |
3f76745e JM |
2462 | #endif |
2463 | } | |
2464 | ||
2465 | void | |
7080f735 | 2466 | dwarf2out_frame_finish (void) |
3f76745e | 2467 | { |
3f76745e | 2468 | /* Output call frame information. */ |
7a0c8d71 | 2469 | if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG) |
3f76745e | 2470 | output_call_frame_info (0); |
2ad9852d | 2471 | |
ddee9e8d | 2472 | if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions)) |
3f76745e | 2473 | output_call_frame_info (1); |
556273e0 | 2474 | } |
17211ab5 | 2475 | #endif |
7d9d8943 AM |
2476 | \f |
2477 | /* And now, the subset of the debugging information support code necessary | |
2478 | for emitting location expressions. */ | |
3f76745e | 2479 | |
b9203463 RH |
2480 | /* We need some way to distinguish DW_OP_addr with a direct symbol |
2481 | relocation from DW_OP_addr with a dtp-relative symbol relocation. */ | |
2482 | #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr) | |
2483 | ||
2484 | ||
7d9d8943 AM |
2485 | typedef struct dw_val_struct *dw_val_ref; |
2486 | typedef struct die_struct *dw_die_ref; | |
2487 | typedef struct dw_loc_descr_struct *dw_loc_descr_ref; | |
63e46568 | 2488 | typedef struct dw_loc_list_struct *dw_loc_list_ref; |
3f76745e JM |
2489 | |
2490 | /* Each DIE may have a series of attribute/value pairs. Values | |
2491 | can take on several forms. The forms that are used in this | |
2492 | implementation are listed below. */ | |
2493 | ||
17211ab5 | 2494 | enum dw_val_class |
3f76745e JM |
2495 | { |
2496 | dw_val_class_addr, | |
a20612aa | 2497 | dw_val_class_offset, |
3f76745e | 2498 | dw_val_class_loc, |
63e46568 | 2499 | dw_val_class_loc_list, |
2bee6045 | 2500 | dw_val_class_range_list, |
3f76745e JM |
2501 | dw_val_class_const, |
2502 | dw_val_class_unsigned_const, | |
2503 | dw_val_class_long_long, | |
e7ee3914 | 2504 | dw_val_class_vec, |
3f76745e JM |
2505 | dw_val_class_flag, |
2506 | dw_val_class_die_ref, | |
2507 | dw_val_class_fde_ref, | |
2508 | dw_val_class_lbl_id, | |
8b790721 | 2509 | dw_val_class_lbl_offset, |
3f76745e | 2510 | dw_val_class_str |
17211ab5 | 2511 | }; |
a3f97cbb | 2512 | |
3f76745e | 2513 | /* Describe a double word constant value. */ |
21217bd0 | 2514 | /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */ |
3f76745e | 2515 | |
17211ab5 | 2516 | typedef struct dw_long_long_struct GTY(()) |
a3f97cbb | 2517 | { |
3f76745e JM |
2518 | unsigned long hi; |
2519 | unsigned long low; | |
2520 | } | |
2521 | dw_long_long_const; | |
2522 | ||
e7ee3914 | 2523 | /* Describe a floating point constant value, or a vector constant value. */ |
3f76745e | 2524 | |
e7ee3914 | 2525 | typedef struct dw_vec_struct GTY(()) |
3f76745e | 2526 | { |
e7ee3914 | 2527 | unsigned char * GTY((length ("%h.length"))) array; |
3f76745e | 2528 | unsigned length; |
e7ee3914 | 2529 | unsigned elt_size; |
3f76745e | 2530 | } |
e7ee3914 | 2531 | dw_vec_const; |
3f76745e | 2532 | |
956d6950 | 2533 | /* The dw_val_node describes an attribute's value, as it is |
3f76745e JM |
2534 | represented internally. */ |
2535 | ||
17211ab5 | 2536 | typedef struct dw_val_struct GTY(()) |
3f76745e | 2537 | { |
17211ab5 GK |
2538 | enum dw_val_class val_class; |
2539 | union dw_val_struct_union | |
a3f97cbb | 2540 | { |
17211ab5 | 2541 | rtx GTY ((tag ("dw_val_class_addr"))) val_addr; |
799f628a | 2542 | unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset; |
17211ab5 GK |
2543 | dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list; |
2544 | dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc; | |
1431042e | 2545 | HOST_WIDE_INT GTY ((default)) val_int; |
799f628a | 2546 | unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned; |
17211ab5 | 2547 | dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long; |
e7ee3914 | 2548 | dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec; |
17211ab5 | 2549 | struct dw_val_die_union |
2ad9852d RK |
2550 | { |
2551 | dw_die_ref die; | |
2552 | int external; | |
17211ab5 GK |
2553 | } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref; |
2554 | unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index; | |
2555 | struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str; | |
2556 | char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id; | |
2557 | unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag; | |
a3f97cbb | 2558 | } |
17211ab5 | 2559 | GTY ((desc ("%1.val_class"))) v; |
3f76745e JM |
2560 | } |
2561 | dw_val_node; | |
2562 | ||
2563 | /* Locations in memory are described using a sequence of stack machine | |
2564 | operations. */ | |
2565 | ||
17211ab5 | 2566 | typedef struct dw_loc_descr_struct GTY(()) |
3f76745e JM |
2567 | { |
2568 | dw_loc_descr_ref dw_loc_next; | |
2569 | enum dwarf_location_atom dw_loc_opc; | |
2570 | dw_val_node dw_loc_oprnd1; | |
2571 | dw_val_node dw_loc_oprnd2; | |
d8041cc8 | 2572 | int dw_loc_addr; |
3f76745e JM |
2573 | } |
2574 | dw_loc_descr_node; | |
2575 | ||
63e46568 DB |
2576 | /* Location lists are ranges + location descriptions for that range, |
2577 | so you can track variables that are in different places over | |
30f7a378 | 2578 | their entire life. */ |
17211ab5 | 2579 | typedef struct dw_loc_list_struct GTY(()) |
63e46568 DB |
2580 | { |
2581 | dw_loc_list_ref dw_loc_next; | |
2582 | const char *begin; /* Label for begin address of range */ | |
2583 | const char *end; /* Label for end address of range */ | |
2ad9852d RK |
2584 | char *ll_symbol; /* Label for beginning of location list. |
2585 | Only on head of list */ | |
63e46568 DB |
2586 | const char *section; /* Section this loclist is relative to */ |
2587 | dw_loc_descr_ref expr; | |
2588 | } dw_loc_list_node; | |
2589 | ||
17211ab5 GK |
2590 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) |
2591 | ||
7080f735 AJ |
2592 | static const char *dwarf_stack_op_name (unsigned); |
2593 | static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom, | |
799f628a | 2594 | unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT); |
7080f735 AJ |
2595 | static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref); |
2596 | static unsigned long size_of_loc_descr (dw_loc_descr_ref); | |
2597 | static unsigned long size_of_locs (dw_loc_descr_ref); | |
2598 | static void output_loc_operands (dw_loc_descr_ref); | |
2599 | static void output_loc_sequence (dw_loc_descr_ref); | |
3f76745e | 2600 | |
7d9d8943 | 2601 | /* Convert a DWARF stack opcode into its string name. */ |
3f76745e | 2602 | |
7d9d8943 | 2603 | static const char * |
7080f735 | 2604 | dwarf_stack_op_name (unsigned int op) |
ef76d03b | 2605 | { |
7d9d8943 AM |
2606 | switch (op) |
2607 | { | |
2608 | case DW_OP_addr: | |
b9203463 | 2609 | case INTERNAL_DW_OP_tls_addr: |
7d9d8943 AM |
2610 | return "DW_OP_addr"; |
2611 | case DW_OP_deref: | |
2612 | return "DW_OP_deref"; | |
2613 | case DW_OP_const1u: | |
2614 | return "DW_OP_const1u"; | |
2615 | case DW_OP_const1s: | |
2616 | return "DW_OP_const1s"; | |
2617 | case DW_OP_const2u: | |
2618 | return "DW_OP_const2u"; | |
2619 | case DW_OP_const2s: | |
2620 | return "DW_OP_const2s"; | |
2621 | case DW_OP_const4u: | |
2622 | return "DW_OP_const4u"; | |
2623 | case DW_OP_const4s: | |
2624 | return "DW_OP_const4s"; | |
2625 | case DW_OP_const8u: | |
2626 | return "DW_OP_const8u"; | |
2627 | case DW_OP_const8s: | |
2628 | return "DW_OP_const8s"; | |
2629 | case DW_OP_constu: | |
2630 | return "DW_OP_constu"; | |
2631 | case DW_OP_consts: | |
2632 | return "DW_OP_consts"; | |
2633 | case DW_OP_dup: | |
2634 | return "DW_OP_dup"; | |
2635 | case DW_OP_drop: | |
2636 | return "DW_OP_drop"; | |
2637 | case DW_OP_over: | |
2638 | return "DW_OP_over"; | |
2639 | case DW_OP_pick: | |
2640 | return "DW_OP_pick"; | |
2641 | case DW_OP_swap: | |
2642 | return "DW_OP_swap"; | |
2643 | case DW_OP_rot: | |
2644 | return "DW_OP_rot"; | |
2645 | case DW_OP_xderef: | |
2646 | return "DW_OP_xderef"; | |
2647 | case DW_OP_abs: | |
2648 | return "DW_OP_abs"; | |
2649 | case DW_OP_and: | |
2650 | return "DW_OP_and"; | |
2651 | case DW_OP_div: | |
2652 | return "DW_OP_div"; | |
2653 | case DW_OP_minus: | |
2654 | return "DW_OP_minus"; | |
2655 | case DW_OP_mod: | |
2656 | return "DW_OP_mod"; | |
2657 | case DW_OP_mul: | |
2658 | return "DW_OP_mul"; | |
2659 | case DW_OP_neg: | |
2660 | return "DW_OP_neg"; | |
2661 | case DW_OP_not: | |
2662 | return "DW_OP_not"; | |
2663 | case DW_OP_or: | |
2664 | return "DW_OP_or"; | |
2665 | case DW_OP_plus: | |
2666 | return "DW_OP_plus"; | |
2667 | case DW_OP_plus_uconst: | |
2668 | return "DW_OP_plus_uconst"; | |
2669 | case DW_OP_shl: | |
2670 | return "DW_OP_shl"; | |
2671 | case DW_OP_shr: | |
2672 | return "DW_OP_shr"; | |
2673 | case DW_OP_shra: | |
2674 | return "DW_OP_shra"; | |
2675 | case DW_OP_xor: | |
2676 | return "DW_OP_xor"; | |
2677 | case DW_OP_bra: | |
2678 | return "DW_OP_bra"; | |
2679 | case DW_OP_eq: | |
2680 | return "DW_OP_eq"; | |
2681 | case DW_OP_ge: | |
2682 | return "DW_OP_ge"; | |
2683 | case DW_OP_gt: | |
2684 | return "DW_OP_gt"; | |
2685 | case DW_OP_le: | |
2686 | return "DW_OP_le"; | |
2687 | case DW_OP_lt: | |
2688 | return "DW_OP_lt"; | |
2689 | case DW_OP_ne: | |
2690 | return "DW_OP_ne"; | |
2691 | case DW_OP_skip: | |
2692 | return "DW_OP_skip"; | |
2693 | case DW_OP_lit0: | |
2694 | return "DW_OP_lit0"; | |
2695 | case DW_OP_lit1: | |
2696 | return "DW_OP_lit1"; | |
2697 | case DW_OP_lit2: | |
2698 | return "DW_OP_lit2"; | |
2699 | case DW_OP_lit3: | |
2700 | return "DW_OP_lit3"; | |
2701 | case DW_OP_lit4: | |
2702 | return "DW_OP_lit4"; | |
2703 | case DW_OP_lit5: | |
2704 | return "DW_OP_lit5"; | |
2705 | case DW_OP_lit6: | |
2706 | return "DW_OP_lit6"; | |
2707 | case DW_OP_lit7: | |
2708 | return "DW_OP_lit7"; | |
2709 | case DW_OP_lit8: | |
2710 | return "DW_OP_lit8"; | |
2711 | case DW_OP_lit9: | |
2712 | return "DW_OP_lit9"; | |
2713 | case DW_OP_lit10: | |
2714 | return "DW_OP_lit10"; | |
2715 | case DW_OP_lit11: | |
2716 | return "DW_OP_lit11"; | |
2717 | case DW_OP_lit12: | |
2718 | return "DW_OP_lit12"; | |
2719 | case DW_OP_lit13: | |
2720 | return "DW_OP_lit13"; | |
2721 | case DW_OP_lit14: | |
2722 | return "DW_OP_lit14"; | |
2723 | case DW_OP_lit15: | |
2724 | return "DW_OP_lit15"; | |
2725 | case DW_OP_lit16: | |
2726 | return "DW_OP_lit16"; | |
2727 | case DW_OP_lit17: | |
2728 | return "DW_OP_lit17"; | |
2729 | case DW_OP_lit18: | |
2730 | return "DW_OP_lit18"; | |
2731 | case DW_OP_lit19: | |
2732 | return "DW_OP_lit19"; | |
2733 | case DW_OP_lit20: | |
2734 | return "DW_OP_lit20"; | |
2735 | case DW_OP_lit21: | |
2736 | return "DW_OP_lit21"; | |
2737 | case DW_OP_lit22: | |
2738 | return "DW_OP_lit22"; | |
2739 | case DW_OP_lit23: | |
2740 | return "DW_OP_lit23"; | |
2741 | case DW_OP_lit24: | |
2742 | return "DW_OP_lit24"; | |
2743 | case DW_OP_lit25: | |
2744 | return "DW_OP_lit25"; | |
2745 | case DW_OP_lit26: | |
2746 | return "DW_OP_lit26"; | |
2747 | case DW_OP_lit27: | |
2748 | return "DW_OP_lit27"; | |
2749 | case DW_OP_lit28: | |
2750 | return "DW_OP_lit28"; | |
2751 | case DW_OP_lit29: | |
2752 | return "DW_OP_lit29"; | |
2753 | case DW_OP_lit30: | |
2754 | return "DW_OP_lit30"; | |
2755 | case DW_OP_lit31: | |
2756 | return "DW_OP_lit31"; | |
2757 | case DW_OP_reg0: | |
2758 | return "DW_OP_reg0"; | |
2759 | case DW_OP_reg1: | |
2760 | return "DW_OP_reg1"; | |
2761 | case DW_OP_reg2: | |
2762 | return "DW_OP_reg2"; | |
2763 | case DW_OP_reg3: | |
2764 | return "DW_OP_reg3"; | |
2765 | case DW_OP_reg4: | |
2766 | return "DW_OP_reg4"; | |
2767 | case DW_OP_reg5: | |
2768 | return "DW_OP_reg5"; | |
2769 | case DW_OP_reg6: | |
2770 | return "DW_OP_reg6"; | |
2771 | case DW_OP_reg7: | |
2772 | return "DW_OP_reg7"; | |
2773 | case DW_OP_reg8: | |
2774 | return "DW_OP_reg8"; | |
2775 | case DW_OP_reg9: | |
2776 | return "DW_OP_reg9"; | |
2777 | case DW_OP_reg10: | |
2778 | return "DW_OP_reg10"; | |
2779 | case DW_OP_reg11: | |
2780 | return "DW_OP_reg11"; | |
2781 | case DW_OP_reg12: | |
2782 | return "DW_OP_reg12"; | |
2783 | case DW_OP_reg13: | |
2784 | return "DW_OP_reg13"; | |
2785 | case DW_OP_reg14: | |
2786 | return "DW_OP_reg14"; | |
2787 | case DW_OP_reg15: | |
2788 | return "DW_OP_reg15"; | |
2789 | case DW_OP_reg16: | |
2790 | return "DW_OP_reg16"; | |
2791 | case DW_OP_reg17: | |
2792 | return "DW_OP_reg17"; | |
2793 | case DW_OP_reg18: | |
2794 | return "DW_OP_reg18"; | |
2795 | case DW_OP_reg19: | |
2796 | return "DW_OP_reg19"; | |
2797 | case DW_OP_reg20: | |
2798 | return "DW_OP_reg20"; | |
2799 | case DW_OP_reg21: | |
2800 | return "DW_OP_reg21"; | |
2801 | case DW_OP_reg22: | |
2802 | return "DW_OP_reg22"; | |
2803 | case DW_OP_reg23: | |
2804 | return "DW_OP_reg23"; | |
2805 | case DW_OP_reg24: | |
2806 | return "DW_OP_reg24"; | |
2807 | case DW_OP_reg25: | |
2808 | return "DW_OP_reg25"; | |
2809 | case DW_OP_reg26: | |
2810 | return "DW_OP_reg26"; | |
2811 | case DW_OP_reg27: | |
2812 | return "DW_OP_reg27"; | |
2813 | case DW_OP_reg28: | |
2814 | return "DW_OP_reg28"; | |
2815 | case DW_OP_reg29: | |
2816 | return "DW_OP_reg29"; | |
2817 | case DW_OP_reg30: | |
2818 | return "DW_OP_reg30"; | |
2819 | case DW_OP_reg31: | |
2820 | return "DW_OP_reg31"; | |
2821 | case DW_OP_breg0: | |
2822 | return "DW_OP_breg0"; | |
2823 | case DW_OP_breg1: | |
2824 | return "DW_OP_breg1"; | |
2825 | case DW_OP_breg2: | |
2826 | return "DW_OP_breg2"; | |
2827 | case DW_OP_breg3: | |
2828 | return "DW_OP_breg3"; | |
2829 | case DW_OP_breg4: | |
2830 | return "DW_OP_breg4"; | |
2831 | case DW_OP_breg5: | |
2832 | return "DW_OP_breg5"; | |
2833 | case DW_OP_breg6: | |
2834 | return "DW_OP_breg6"; | |
2835 | case DW_OP_breg7: | |
2836 | return "DW_OP_breg7"; | |
2837 | case DW_OP_breg8: | |
2838 | return "DW_OP_breg8"; | |
2839 | case DW_OP_breg9: | |
2840 | return "DW_OP_breg9"; | |
2841 | case DW_OP_breg10: | |
2842 | return "DW_OP_breg10"; | |
2843 | case DW_OP_breg11: | |
2844 | return "DW_OP_breg11"; | |
2845 | case DW_OP_breg12: | |
2846 | return "DW_OP_breg12"; | |
2847 | case DW_OP_breg13: | |
2848 | return "DW_OP_breg13"; | |
2849 | case DW_OP_breg14: | |
2850 | return "DW_OP_breg14"; | |
2851 | case DW_OP_breg15: | |
2852 | return "DW_OP_breg15"; | |
2853 | case DW_OP_breg16: | |
2854 | return "DW_OP_breg16"; | |
2855 | case DW_OP_breg17: | |
2856 | return "DW_OP_breg17"; | |
2857 | case DW_OP_breg18: | |
2858 | return "DW_OP_breg18"; | |
2859 | case DW_OP_breg19: | |
2860 | return "DW_OP_breg19"; | |
2861 | case DW_OP_breg20: | |
2862 | return "DW_OP_breg20"; | |
2863 | case DW_OP_breg21: | |
2864 | return "DW_OP_breg21"; | |
2865 | case DW_OP_breg22: | |
2866 | return "DW_OP_breg22"; | |
2867 | case DW_OP_breg23: | |
2868 | return "DW_OP_breg23"; | |
2869 | case DW_OP_breg24: | |
2870 | return "DW_OP_breg24"; | |
2871 | case DW_OP_breg25: | |
2872 | return "DW_OP_breg25"; | |
2873 | case DW_OP_breg26: | |
2874 | return "DW_OP_breg26"; | |
2875 | case DW_OP_breg27: | |
2876 | return "DW_OP_breg27"; | |
2877 | case DW_OP_breg28: | |
2878 | return "DW_OP_breg28"; | |
2879 | case DW_OP_breg29: | |
2880 | return "DW_OP_breg29"; | |
2881 | case DW_OP_breg30: | |
2882 | return "DW_OP_breg30"; | |
2883 | case DW_OP_breg31: | |
2884 | return "DW_OP_breg31"; | |
2885 | case DW_OP_regx: | |
2886 | return "DW_OP_regx"; | |
2887 | case DW_OP_fbreg: | |
2888 | return "DW_OP_fbreg"; | |
2889 | case DW_OP_bregx: | |
2890 | return "DW_OP_bregx"; | |
2891 | case DW_OP_piece: | |
2892 | return "DW_OP_piece"; | |
2893 | case DW_OP_deref_size: | |
2894 | return "DW_OP_deref_size"; | |
2895 | case DW_OP_xderef_size: | |
2896 | return "DW_OP_xderef_size"; | |
2897 | case DW_OP_nop: | |
2898 | return "DW_OP_nop"; | |
b9203463 RH |
2899 | case DW_OP_push_object_address: |
2900 | return "DW_OP_push_object_address"; | |
2901 | case DW_OP_call2: | |
2902 | return "DW_OP_call2"; | |
2903 | case DW_OP_call4: | |
2904 | return "DW_OP_call4"; | |
2905 | case DW_OP_call_ref: | |
2906 | return "DW_OP_call_ref"; | |
2907 | case DW_OP_GNU_push_tls_address: | |
2908 | return "DW_OP_GNU_push_tls_address"; | |
3f76745e | 2909 | default: |
7d9d8943 | 2910 | return "OP_<unknown>"; |
3f76745e | 2911 | } |
bdb669cb | 2912 | } |
a3f97cbb | 2913 | |
7d9d8943 AM |
2914 | /* Return a pointer to a newly allocated location description. Location |
2915 | descriptions are simple expression terms that can be strung | |
2916 | together to form more complicated location (address) descriptions. */ | |
2917 | ||
2918 | static inline dw_loc_descr_ref | |
799f628a JH |
2919 | new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1, |
2920 | unsigned HOST_WIDE_INT oprnd2) | |
4b674448 | 2921 | { |
703ad42b | 2922 | dw_loc_descr_ref descr = ggc_alloc_cleared (sizeof (dw_loc_descr_node)); |
71dfc51f | 2923 | |
7d9d8943 AM |
2924 | descr->dw_loc_opc = op; |
2925 | descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const; | |
2926 | descr->dw_loc_oprnd1.v.val_unsigned = oprnd1; | |
2927 | descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const; | |
2928 | descr->dw_loc_oprnd2.v.val_unsigned = oprnd2; | |
71dfc51f | 2929 | |
7d9d8943 AM |
2930 | return descr; |
2931 | } | |
2932 | ||
63e46568 | 2933 | |
7d9d8943 AM |
2934 | /* Add a location description term to a location description expression. */ |
2935 | ||
2936 | static inline void | |
7080f735 | 2937 | add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr) |
7d9d8943 | 2938 | { |
b3694847 | 2939 | dw_loc_descr_ref *d; |
7d9d8943 AM |
2940 | |
2941 | /* Find the end of the chain. */ | |
2942 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
2943 | ; | |
2944 | ||
2945 | *d = descr; | |
2946 | } | |
2947 | ||
2948 | /* Return the size of a location descriptor. */ | |
2949 | ||
2950 | static unsigned long | |
7080f735 | 2951 | size_of_loc_descr (dw_loc_descr_ref loc) |
7d9d8943 | 2952 | { |
b3694847 | 2953 | unsigned long size = 1; |
7d9d8943 AM |
2954 | |
2955 | switch (loc->dw_loc_opc) | |
2956 | { | |
2957 | case DW_OP_addr: | |
b9203463 | 2958 | case INTERNAL_DW_OP_tls_addr: |
7d9d8943 AM |
2959 | size += DWARF2_ADDR_SIZE; |
2960 | break; | |
2961 | case DW_OP_const1u: | |
2962 | case DW_OP_const1s: | |
2963 | size += 1; | |
2964 | break; | |
2965 | case DW_OP_const2u: | |
2966 | case DW_OP_const2s: | |
2967 | size += 2; | |
2968 | break; | |
2969 | case DW_OP_const4u: | |
2970 | case DW_OP_const4s: | |
2971 | size += 4; | |
2972 | break; | |
2973 | case DW_OP_const8u: | |
2974 | case DW_OP_const8s: | |
2975 | size += 8; | |
2976 | break; | |
2977 | case DW_OP_constu: | |
2978 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2979 | break; | |
2980 | case DW_OP_consts: | |
2981 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2982 | break; | |
2983 | case DW_OP_pick: | |
2984 | size += 1; | |
2985 | break; | |
2986 | case DW_OP_plus_uconst: | |
2987 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2988 | break; | |
2989 | case DW_OP_skip: | |
2990 | case DW_OP_bra: | |
2991 | size += 2; | |
2992 | break; | |
2993 | case DW_OP_breg0: | |
2994 | case DW_OP_breg1: | |
2995 | case DW_OP_breg2: | |
2996 | case DW_OP_breg3: | |
2997 | case DW_OP_breg4: | |
2998 | case DW_OP_breg5: | |
2999 | case DW_OP_breg6: | |
3000 | case DW_OP_breg7: | |
3001 | case DW_OP_breg8: | |
3002 | case DW_OP_breg9: | |
3003 | case DW_OP_breg10: | |
3004 | case DW_OP_breg11: | |
3005 | case DW_OP_breg12: | |
3006 | case DW_OP_breg13: | |
3007 | case DW_OP_breg14: | |
3008 | case DW_OP_breg15: | |
3009 | case DW_OP_breg16: | |
3010 | case DW_OP_breg17: | |
3011 | case DW_OP_breg18: | |
3012 | case DW_OP_breg19: | |
3013 | case DW_OP_breg20: | |
3014 | case DW_OP_breg21: | |
3015 | case DW_OP_breg22: | |
3016 | case DW_OP_breg23: | |
3017 | case DW_OP_breg24: | |
3018 | case DW_OP_breg25: | |
3019 | case DW_OP_breg26: | |
3020 | case DW_OP_breg27: | |
3021 | case DW_OP_breg28: | |
3022 | case DW_OP_breg29: | |
3023 | case DW_OP_breg30: | |
3024 | case DW_OP_breg31: | |
3025 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
3026 | break; | |
3027 | case DW_OP_regx: | |
3028 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
3029 | break; | |
3030 | case DW_OP_fbreg: | |
3031 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
3032 | break; | |
3033 | case DW_OP_bregx: | |
3034 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
3035 | size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int); | |
3036 | break; | |
3037 | case DW_OP_piece: | |
3038 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
3039 | break; | |
3040 | case DW_OP_deref_size: | |
3041 | case DW_OP_xderef_size: | |
3042 | size += 1; | |
3043 | break; | |
b9203463 RH |
3044 | case DW_OP_call2: |
3045 | size += 2; | |
3046 | break; | |
3047 | case DW_OP_call4: | |
3048 | size += 4; | |
3049 | break; | |
3050 | case DW_OP_call_ref: | |
3051 | size += DWARF2_ADDR_SIZE; | |
3052 | break; | |
3f76745e | 3053 | default: |
7d9d8943 | 3054 | break; |
4b674448 | 3055 | } |
7d9d8943 AM |
3056 | |
3057 | return size; | |
4b674448 JM |
3058 | } |
3059 | ||
7d9d8943 | 3060 | /* Return the size of a series of location descriptors. */ |
71dfc51f | 3061 | |
7d9d8943 | 3062 | static unsigned long |
7080f735 | 3063 | size_of_locs (dw_loc_descr_ref loc) |
4b674448 | 3064 | { |
2ad9852d | 3065 | unsigned long size; |
7d9d8943 | 3066 | |
2ad9852d | 3067 | for (size = 0; loc != NULL; loc = loc->dw_loc_next) |
d8041cc8 RH |
3068 | { |
3069 | loc->dw_loc_addr = size; | |
3070 | size += size_of_loc_descr (loc); | |
3071 | } | |
7d9d8943 AM |
3072 | |
3073 | return size; | |
4b674448 JM |
3074 | } |
3075 | ||
7d9d8943 | 3076 | /* Output location description stack opcode's operands (if any). */ |
71dfc51f | 3077 | |
7d9d8943 | 3078 | static void |
7080f735 | 3079 | output_loc_operands (dw_loc_descr_ref loc) |
a3f97cbb | 3080 | { |
b3694847 SS |
3081 | dw_val_ref val1 = &loc->dw_loc_oprnd1; |
3082 | dw_val_ref val2 = &loc->dw_loc_oprnd2; | |
7d9d8943 AM |
3083 | |
3084 | switch (loc->dw_loc_opc) | |
a3f97cbb | 3085 | { |
0517872a | 3086 | #ifdef DWARF2_DEBUGGING_INFO |
3f76745e | 3087 | case DW_OP_addr: |
2e4b9b8c | 3088 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL); |
7d9d8943 | 3089 | break; |
3f76745e | 3090 | case DW_OP_const2u: |
3f76745e | 3091 | case DW_OP_const2s: |
2e4b9b8c | 3092 | dw2_asm_output_data (2, val1->v.val_int, NULL); |
7d9d8943 | 3093 | break; |
3f76745e | 3094 | case DW_OP_const4u: |
3f76745e | 3095 | case DW_OP_const4s: |
2e4b9b8c | 3096 | dw2_asm_output_data (4, val1->v.val_int, NULL); |
7d9d8943 | 3097 | break; |
3f76745e | 3098 | case DW_OP_const8u: |
3f76745e | 3099 | case DW_OP_const8s: |
2e4b9b8c RH |
3100 | if (HOST_BITS_PER_LONG < 64) |
3101 | abort (); | |
3102 | dw2_asm_output_data (8, val1->v.val_int, NULL); | |
7d9d8943 | 3103 | break; |
0517872a JM |
3104 | case DW_OP_skip: |
3105 | case DW_OP_bra: | |
d8041cc8 RH |
3106 | { |
3107 | int offset; | |
3108 | ||
3109 | if (val1->val_class == dw_val_class_loc) | |
3110 | offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3); | |
3111 | else | |
3112 | abort (); | |
3113 | ||
2e4b9b8c | 3114 | dw2_asm_output_data (2, offset, NULL); |
d8041cc8 | 3115 | } |
0517872a | 3116 | break; |
3139472f JM |
3117 | #else |
3118 | case DW_OP_addr: | |
3119 | case DW_OP_const2u: | |
3120 | case DW_OP_const2s: | |
3121 | case DW_OP_const4u: | |
3122 | case DW_OP_const4s: | |
3123 | case DW_OP_const8u: | |
3124 | case DW_OP_const8s: | |
3125 | case DW_OP_skip: | |
3126 | case DW_OP_bra: | |
3127 | /* We currently don't make any attempt to make sure these are | |
73c68f61 SS |
3128 | aligned properly like we do for the main unwind info, so |
3129 | don't support emitting things larger than a byte if we're | |
3130 | only doing unwinding. */ | |
3139472f | 3131 | abort (); |
0517872a JM |
3132 | #endif |
3133 | case DW_OP_const1u: | |
3134 | case DW_OP_const1s: | |
2e4b9b8c | 3135 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
0517872a | 3136 | break; |
3f76745e | 3137 | case DW_OP_constu: |
2e4b9b8c | 3138 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 3139 | break; |
3f76745e | 3140 | case DW_OP_consts: |
2e4b9b8c | 3141 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 AM |
3142 | break; |
3143 | case DW_OP_pick: | |
2e4b9b8c | 3144 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 AM |
3145 | break; |
3146 | case DW_OP_plus_uconst: | |
2e4b9b8c | 3147 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 3148 | break; |
3f76745e | 3149 | case DW_OP_breg0: |
3f76745e | 3150 | case DW_OP_breg1: |
3f76745e | 3151 | case DW_OP_breg2: |
3f76745e | 3152 | case DW_OP_breg3: |
3f76745e | 3153 | case DW_OP_breg4: |
3f76745e | 3154 | case DW_OP_breg5: |
3f76745e | 3155 | case DW_OP_breg6: |
3f76745e | 3156 | case DW_OP_breg7: |
3f76745e | 3157 | case DW_OP_breg8: |
3f76745e | 3158 | case DW_OP_breg9: |
3f76745e | 3159 | case DW_OP_breg10: |
3f76745e | 3160 | case DW_OP_breg11: |
3f76745e | 3161 | case DW_OP_breg12: |
3f76745e | 3162 | case DW_OP_breg13: |
3f76745e | 3163 | case DW_OP_breg14: |
3f76745e | 3164 | case DW_OP_breg15: |
3f76745e | 3165 | case DW_OP_breg16: |
3f76745e | 3166 | case DW_OP_breg17: |
3f76745e | 3167 | case DW_OP_breg18: |
3f76745e | 3168 | case DW_OP_breg19: |
3f76745e | 3169 | case DW_OP_breg20: |
3f76745e | 3170 | case DW_OP_breg21: |
3f76745e | 3171 | case DW_OP_breg22: |
3f76745e | 3172 | case DW_OP_breg23: |
3f76745e | 3173 | case DW_OP_breg24: |
3f76745e | 3174 | case DW_OP_breg25: |
3f76745e | 3175 | case DW_OP_breg26: |
3f76745e | 3176 | case DW_OP_breg27: |
3f76745e | 3177 | case DW_OP_breg28: |
3f76745e | 3178 | case DW_OP_breg29: |
3f76745e | 3179 | case DW_OP_breg30: |
3f76745e | 3180 | case DW_OP_breg31: |
2e4b9b8c | 3181 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 3182 | break; |
3f76745e | 3183 | case DW_OP_regx: |
2e4b9b8c | 3184 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 3185 | break; |
3f76745e | 3186 | case DW_OP_fbreg: |
2e4b9b8c | 3187 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 3188 | break; |
3f76745e | 3189 | case DW_OP_bregx: |
2e4b9b8c RH |
3190 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
3191 | dw2_asm_output_data_sleb128 (val2->v.val_int, NULL); | |
7d9d8943 | 3192 | break; |
3f76745e | 3193 | case DW_OP_piece: |
2e4b9b8c | 3194 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 3195 | break; |
3f76745e | 3196 | case DW_OP_deref_size: |
3f76745e | 3197 | case DW_OP_xderef_size: |
2e4b9b8c | 3198 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 | 3199 | break; |
b9203463 RH |
3200 | |
3201 | case INTERNAL_DW_OP_tls_addr: | |
3202 | #ifdef ASM_OUTPUT_DWARF_DTPREL | |
3203 | ASM_OUTPUT_DWARF_DTPREL (asm_out_file, DWARF2_ADDR_SIZE, | |
3204 | val1->v.val_addr); | |
3205 | fputc ('\n', asm_out_file); | |
3206 | #else | |
3207 | abort (); | |
3208 | #endif | |
3209 | break; | |
3210 | ||
7d9d8943 | 3211 | default: |
3139472f JM |
3212 | /* Other codes have no operands. */ |
3213 | break; | |
7d9d8943 AM |
3214 | } |
3215 | } | |
3216 | ||
3217 | /* Output a sequence of location operations. */ | |
3218 | ||
3219 | static void | |
7080f735 | 3220 | output_loc_sequence (dw_loc_descr_ref loc) |
7d9d8943 AM |
3221 | { |
3222 | for (; loc != NULL; loc = loc->dw_loc_next) | |
3223 | { | |
3224 | /* Output the opcode. */ | |
2e4b9b8c RH |
3225 | dw2_asm_output_data (1, loc->dw_loc_opc, |
3226 | "%s", dwarf_stack_op_name (loc->dw_loc_opc)); | |
7d9d8943 AM |
3227 | |
3228 | /* Output the operand(s) (if any). */ | |
3229 | output_loc_operands (loc); | |
3230 | } | |
3231 | } | |
3232 | ||
3233 | /* This routine will generate the correct assembly data for a location | |
3234 | description based on a cfi entry with a complex address. */ | |
3235 | ||
3236 | static void | |
7080f735 | 3237 | output_cfa_loc (dw_cfi_ref cfi) |
7d9d8943 AM |
3238 | { |
3239 | dw_loc_descr_ref loc; | |
3240 | unsigned long size; | |
3241 | ||
3242 | /* Output the size of the block. */ | |
3243 | loc = cfi->dw_cfi_oprnd1.dw_cfi_loc; | |
3244 | size = size_of_locs (loc); | |
2e4b9b8c | 3245 | dw2_asm_output_data_uleb128 (size, NULL); |
7d9d8943 AM |
3246 | |
3247 | /* Now output the operations themselves. */ | |
3248 | output_loc_sequence (loc); | |
3249 | } | |
3250 | ||
dd49a9ec | 3251 | /* This function builds a dwarf location descriptor sequence from |
556273e0 | 3252 | a dw_cfa_location. */ |
7d9d8943 AM |
3253 | |
3254 | static struct dw_loc_descr_struct * | |
7080f735 | 3255 | build_cfa_loc (dw_cfa_location *cfa) |
7d9d8943 AM |
3256 | { |
3257 | struct dw_loc_descr_struct *head, *tmp; | |
3258 | ||
3259 | if (cfa->indirect == 0) | |
3260 | abort (); | |
3261 | ||
3262 | if (cfa->base_offset) | |
f299afab HPN |
3263 | { |
3264 | if (cfa->reg <= 31) | |
3265 | head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0); | |
3266 | else | |
3267 | head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset); | |
3268 | } | |
3269 | else if (cfa->reg <= 31) | |
7d9d8943 | 3270 | head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0); |
f299afab HPN |
3271 | else |
3272 | head = new_loc_descr (DW_OP_regx, cfa->reg, 0); | |
2ad9852d | 3273 | |
7d9d8943 AM |
3274 | head->dw_loc_oprnd1.val_class = dw_val_class_const; |
3275 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
3276 | add_loc_descr (&head, tmp); | |
3277 | if (cfa->offset != 0) | |
3278 | { | |
3279 | tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0); | |
3280 | add_loc_descr (&head, tmp); | |
3281 | } | |
2ad9852d | 3282 | |
7d9d8943 AM |
3283 | return head; |
3284 | } | |
3285 | ||
2ad9852d RK |
3286 | /* This function fills in aa dw_cfa_location structure from a dwarf location |
3287 | descriptor sequence. */ | |
7d9d8943 AM |
3288 | |
3289 | static void | |
7080f735 | 3290 | get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc) |
7d9d8943 | 3291 | { |
556273e0 | 3292 | struct dw_loc_descr_struct *ptr; |
7d9d8943 AM |
3293 | cfa->offset = 0; |
3294 | cfa->base_offset = 0; | |
3295 | cfa->indirect = 0; | |
3296 | cfa->reg = -1; | |
3297 | ||
3298 | for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next) | |
3299 | { | |
3300 | enum dwarf_location_atom op = ptr->dw_loc_opc; | |
2ad9852d | 3301 | |
7d9d8943 | 3302 | switch (op) |
556273e0 | 3303 | { |
7d9d8943 AM |
3304 | case DW_OP_reg0: |
3305 | case DW_OP_reg1: | |
3306 | case DW_OP_reg2: | |
3307 | case DW_OP_reg3: | |
3308 | case DW_OP_reg4: | |
3309 | case DW_OP_reg5: | |
3310 | case DW_OP_reg6: | |
3311 | case DW_OP_reg7: | |
3312 | case DW_OP_reg8: | |
3313 | case DW_OP_reg9: | |
3314 | case DW_OP_reg10: | |
3315 | case DW_OP_reg11: | |
3316 | case DW_OP_reg12: | |
3317 | case DW_OP_reg13: | |
3318 | case DW_OP_reg14: | |
3319 | case DW_OP_reg15: | |
3320 | case DW_OP_reg16: | |
3321 | case DW_OP_reg17: | |
3322 | case DW_OP_reg18: | |
3323 | case DW_OP_reg19: | |
3324 | case DW_OP_reg20: | |
3325 | case DW_OP_reg21: | |
3326 | case DW_OP_reg22: | |
3327 | case DW_OP_reg23: | |
3328 | case DW_OP_reg24: | |
3329 | case DW_OP_reg25: | |
3330 | case DW_OP_reg26: | |
3331 | case DW_OP_reg27: | |
3332 | case DW_OP_reg28: | |
3333 | case DW_OP_reg29: | |
3334 | case DW_OP_reg30: | |
3335 | case DW_OP_reg31: | |
3336 | cfa->reg = op - DW_OP_reg0; | |
3337 | break; | |
3338 | case DW_OP_regx: | |
3339 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
3340 | break; | |
3341 | case DW_OP_breg0: | |
3342 | case DW_OP_breg1: | |
3343 | case DW_OP_breg2: | |
3344 | case DW_OP_breg3: | |
3345 | case DW_OP_breg4: | |
3346 | case DW_OP_breg5: | |
3347 | case DW_OP_breg6: | |
3348 | case DW_OP_breg7: | |
3349 | case DW_OP_breg8: | |
3350 | case DW_OP_breg9: | |
3351 | case DW_OP_breg10: | |
3352 | case DW_OP_breg11: | |
3353 | case DW_OP_breg12: | |
3354 | case DW_OP_breg13: | |
3355 | case DW_OP_breg14: | |
3356 | case DW_OP_breg15: | |
3357 | case DW_OP_breg16: | |
3358 | case DW_OP_breg17: | |
3359 | case DW_OP_breg18: | |
3360 | case DW_OP_breg19: | |
3361 | case DW_OP_breg20: | |
3362 | case DW_OP_breg21: | |
3363 | case DW_OP_breg22: | |
3364 | case DW_OP_breg23: | |
3365 | case DW_OP_breg24: | |
3366 | case DW_OP_breg25: | |
3367 | case DW_OP_breg26: | |
3368 | case DW_OP_breg27: | |
3369 | case DW_OP_breg28: | |
3370 | case DW_OP_breg29: | |
3371 | case DW_OP_breg30: | |
3372 | case DW_OP_breg31: | |
3373 | cfa->reg = op - DW_OP_breg0; | |
3374 | cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int; | |
3375 | break; | |
3376 | case DW_OP_bregx: | |
3377 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
3378 | cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int; | |
3379 | break; | |
3380 | case DW_OP_deref: | |
3381 | cfa->indirect = 1; | |
3382 | break; | |
3383 | case DW_OP_plus_uconst: | |
556273e0 | 3384 | cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned; |
7d9d8943 AM |
3385 | break; |
3386 | default: | |
a1f300c0 | 3387 | internal_error ("DW_LOC_OP %s not implemented\n", |
400500c4 | 3388 | dwarf_stack_op_name (ptr->dw_loc_opc)); |
7d9d8943 AM |
3389 | } |
3390 | } | |
3391 | } | |
3392 | #endif /* .debug_frame support */ | |
3393 | \f | |
3394 | /* And now, the support for symbolic debugging information. */ | |
3395 | #ifdef DWARF2_DEBUGGING_INFO | |
3396 | ||
117f9d28 | 3397 | /* .debug_str support. */ |
7080f735 AJ |
3398 | static int output_indirect_string (void **, void *); |
3399 | ||
3400 | static void dwarf2out_init (const char *); | |
3401 | static void dwarf2out_finish (const char *); | |
3402 | static void dwarf2out_define (unsigned int, const char *); | |
3403 | static void dwarf2out_undef (unsigned int, const char *); | |
3404 | static void dwarf2out_start_source_file (unsigned, const char *); | |
3405 | static void dwarf2out_end_source_file (unsigned); | |
3406 | static void dwarf2out_begin_block (unsigned, unsigned); | |
3407 | static void dwarf2out_end_block (unsigned, unsigned); | |
3408 | static bool dwarf2out_ignore_block (tree); | |
3409 | static void dwarf2out_global_decl (tree); | |
21d13d83 | 3410 | static void dwarf2out_type_decl (tree, int); |
6097b0c3 | 3411 | static void dwarf2out_imported_module_or_decl (tree, tree); |
7080f735 | 3412 | static void dwarf2out_abstract_function (tree); |
0a2d3d69 DB |
3413 | static void dwarf2out_var_location (rtx); |
3414 | static void dwarf2out_begin_function (tree); | |
7f905405 NB |
3415 | |
3416 | /* The debug hooks structure. */ | |
3417 | ||
54b6670a | 3418 | const struct gcc_debug_hooks dwarf2_debug_hooks = |
7f905405 NB |
3419 | { |
3420 | dwarf2out_init, | |
3421 | dwarf2out_finish, | |
3422 | dwarf2out_define, | |
3423 | dwarf2out_undef, | |
3424 | dwarf2out_start_source_file, | |
a5a42b92 NB |
3425 | dwarf2out_end_source_file, |
3426 | dwarf2out_begin_block, | |
e2a12aca | 3427 | dwarf2out_end_block, |
e1772ac0 | 3428 | dwarf2out_ignore_block, |
e2a12aca | 3429 | dwarf2out_source_line, |
653e276c | 3430 | dwarf2out_begin_prologue, |
702ada3d | 3431 | debug_nothing_int_charstar, /* end_prologue */ |
e2a12aca | 3432 | dwarf2out_end_epilogue, |
0a2d3d69 | 3433 | dwarf2out_begin_function, |
2b85879e NB |
3434 | debug_nothing_int, /* end_function */ |
3435 | dwarf2out_decl, /* function_decl */ | |
3436 | dwarf2out_global_decl, | |
21d13d83 | 3437 | dwarf2out_type_decl, /* type_decl */ |
6097b0c3 | 3438 | dwarf2out_imported_module_or_decl, |
e1772ac0 NB |
3439 | debug_nothing_tree, /* deferred_inline_function */ |
3440 | /* The DWARF 2 backend tries to reduce debugging bloat by not | |
3441 | emitting the abstract description of inline functions until | |
3442 | something tries to reference them. */ | |
3443 | dwarf2out_abstract_function, /* outlining_inline_function */ | |
33b49800 | 3444 | debug_nothing_rtx, /* label */ |
014a1138 | 3445 | debug_nothing_int, /* handle_pch */ |
0a2d3d69 | 3446 | dwarf2out_var_location |
7f905405 | 3447 | }; |
17211ab5 | 3448 | #endif |
7f905405 | 3449 | \f |
7d9d8943 AM |
3450 | /* NOTE: In the comments in this file, many references are made to |
3451 | "Debugging Information Entries". This term is abbreviated as `DIE' | |
3452 | throughout the remainder of this file. */ | |
3453 | ||
3454 | /* An internal representation of the DWARF output is built, and then | |
3455 | walked to generate the DWARF debugging info. The walk of the internal | |
3456 | representation is done after the entire program has been compiled. | |
3457 | The types below are used to describe the internal representation. */ | |
3458 | ||
3459 | /* Various DIE's use offsets relative to the beginning of the | |
3460 | .debug_info section to refer to each other. */ | |
3461 | ||
3462 | typedef long int dw_offset; | |
3463 | ||
3464 | /* Define typedefs here to avoid circular dependencies. */ | |
3465 | ||
3466 | typedef struct dw_attr_struct *dw_attr_ref; | |
3467 | typedef struct dw_line_info_struct *dw_line_info_ref; | |
3468 | typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref; | |
3469 | typedef struct pubname_struct *pubname_ref; | |
a20612aa | 3470 | typedef struct dw_ranges_struct *dw_ranges_ref; |
7d9d8943 AM |
3471 | |
3472 | /* Each entry in the line_info_table maintains the file and | |
3473 | line number associated with the label generated for that | |
3474 | entry. The label gives the PC value associated with | |
3475 | the line number entry. */ | |
3476 | ||
17211ab5 | 3477 | typedef struct dw_line_info_struct GTY(()) |
7d9d8943 AM |
3478 | { |
3479 | unsigned long dw_file_num; | |
3480 | unsigned long dw_line_num; | |
3481 | } | |
3482 | dw_line_info_entry; | |
3483 | ||
3484 | /* Line information for functions in separate sections; each one gets its | |
3485 | own sequence. */ | |
17211ab5 | 3486 | typedef struct dw_separate_line_info_struct GTY(()) |
7d9d8943 AM |
3487 | { |
3488 | unsigned long dw_file_num; | |
3489 | unsigned long dw_line_num; | |
3490 | unsigned long function; | |
3491 | } | |
3492 | dw_separate_line_info_entry; | |
3493 | ||
3494 | /* Each DIE attribute has a field specifying the attribute kind, | |
3495 | a link to the next attribute in the chain, and an attribute value. | |
3496 | Attributes are typically linked below the DIE they modify. */ | |
3497 | ||
17211ab5 | 3498 | typedef struct dw_attr_struct GTY(()) |
7d9d8943 AM |
3499 | { |
3500 | enum dwarf_attribute dw_attr; | |
3501 | dw_attr_ref dw_attr_next; | |
3502 | dw_val_node dw_attr_val; | |
3503 | } | |
3504 | dw_attr_node; | |
3505 | ||
3506 | /* The Debugging Information Entry (DIE) structure */ | |
3507 | ||
17211ab5 | 3508 | typedef struct die_struct GTY(()) |
7d9d8943 AM |
3509 | { |
3510 | enum dwarf_tag die_tag; | |
881c6935 | 3511 | char *die_symbol; |
7d9d8943 AM |
3512 | dw_attr_ref die_attr; |
3513 | dw_die_ref die_parent; | |
3514 | dw_die_ref die_child; | |
3515 | dw_die_ref die_sib; | |
47fcfa7b | 3516 | dw_die_ref die_definition; /* ref from a specification to its definition */ |
7d9d8943 AM |
3517 | dw_offset die_offset; |
3518 | unsigned long die_abbrev; | |
1bfb5f8f | 3519 | int die_mark; |
636c7bc4 | 3520 | unsigned int decl_id; |
7d9d8943 AM |
3521 | } |
3522 | die_node; | |
3523 | ||
3524 | /* The pubname structure */ | |
3525 | ||
17211ab5 | 3526 | typedef struct pubname_struct GTY(()) |
7d9d8943 AM |
3527 | { |
3528 | dw_die_ref die; | |
556273e0 | 3529 | char *name; |
7d9d8943 AM |
3530 | } |
3531 | pubname_entry; | |
3532 | ||
17211ab5 | 3533 | struct dw_ranges_struct GTY(()) |
a20612aa RH |
3534 | { |
3535 | int block_num; | |
3536 | }; | |
3537 | ||
7d9d8943 | 3538 | /* The limbo die list structure. */ |
17211ab5 | 3539 | typedef struct limbo_die_struct GTY(()) |
7d9d8943 AM |
3540 | { |
3541 | dw_die_ref die; | |
54ba1f0d | 3542 | tree created_for; |
7d9d8943 AM |
3543 | struct limbo_die_struct *next; |
3544 | } | |
3545 | limbo_die_node; | |
3546 | ||
3547 | /* How to start an assembler comment. */ | |
3548 | #ifndef ASM_COMMENT_START | |
3549 | #define ASM_COMMENT_START ";#" | |
3550 | #endif | |
3551 | ||
cc2902df | 3552 | /* Define a macro which returns nonzero for a TYPE_DECL which was |
7d9d8943 AM |
3553 | implicitly generated for a tagged type. |
3554 | ||
3555 | Note that unlike the gcc front end (which generates a NULL named | |
3556 | TYPE_DECL node for each complete tagged type, each array type, and | |
3557 | each function type node created) the g++ front end generates a | |
3558 | _named_ TYPE_DECL node for each tagged type node created. | |
3559 | These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to | |
3560 | generate a DW_TAG_typedef DIE for them. */ | |
3561 | ||
3562 | #define TYPE_DECL_IS_STUB(decl) \ | |
3563 | (DECL_NAME (decl) == NULL_TREE \ | |
3564 | || (DECL_ARTIFICIAL (decl) \ | |
3565 | && is_tagged_type (TREE_TYPE (decl)) \ | |
3566 | && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \ | |
3567 | /* This is necessary for stub decls that \ | |
3568 | appear in nested inline functions. */ \ | |
3569 | || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \ | |
3570 | && (decl_ultimate_origin (decl) \ | |
3571 | == TYPE_STUB_DECL (TREE_TYPE (decl))))))) | |
3572 | ||
3573 | /* Information concerning the compilation unit's programming | |
3574 | language, and compiler version. */ | |
3575 | ||
7d9d8943 | 3576 | /* Fixed size portion of the DWARF compilation unit header. */ |
9eb0ef7a KB |
3577 | #define DWARF_COMPILE_UNIT_HEADER_SIZE \ |
3578 | (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3) | |
7d9d8943 | 3579 | |
7d9d8943 AM |
3580 | /* Fixed size portion of public names info. */ |
3581 | #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2) | |
3582 | ||
3583 | /* Fixed size portion of the address range info. */ | |
3584 | #define DWARF_ARANGES_HEADER_SIZE \ | |
c583e7c3 KB |
3585 | (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \ |
3586 | DWARF2_ADDR_SIZE * 2) \ | |
3587 | - DWARF_INITIAL_LENGTH_SIZE) | |
7d9d8943 AM |
3588 | |
3589 | /* Size of padding portion in the address range info. It must be | |
3590 | aligned to twice the pointer size. */ | |
3591 | #define DWARF_ARANGES_PAD_SIZE \ | |
c583e7c3 KB |
3592 | (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \ |
3593 | DWARF2_ADDR_SIZE * 2) \ | |
3594 | - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4)) | |
7d9d8943 | 3595 | |
9d147085 | 3596 | /* Use assembler line directives if available. */ |
7d9d8943 | 3597 | #ifndef DWARF2_ASM_LINE_DEBUG_INFO |
9d147085 RH |
3598 | #ifdef HAVE_AS_DWARF2_DEBUG_LINE |
3599 | #define DWARF2_ASM_LINE_DEBUG_INFO 1 | |
3600 | #else | |
7d9d8943 AM |
3601 | #define DWARF2_ASM_LINE_DEBUG_INFO 0 |
3602 | #endif | |
9d147085 | 3603 | #endif |
7d9d8943 | 3604 | |
7d9d8943 AM |
3605 | /* Minimum line offset in a special line info. opcode. |
3606 | This value was chosen to give a reasonable range of values. */ | |
3607 | #define DWARF_LINE_BASE -10 | |
3608 | ||
a1f300c0 | 3609 | /* First special line opcode - leave room for the standard opcodes. */ |
7d9d8943 AM |
3610 | #define DWARF_LINE_OPCODE_BASE 10 |
3611 | ||
3612 | /* Range of line offsets in a special line info. opcode. */ | |
3613 | #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1) | |
3614 | ||
3615 | /* Flag that indicates the initial value of the is_stmt_start flag. | |
3616 | In the present implementation, we do not mark any lines as | |
3617 | the beginning of a source statement, because that information | |
3618 | is not made available by the GCC front-end. */ | |
3619 | #define DWARF_LINE_DEFAULT_IS_STMT_START 1 | |
3620 | ||
c1b50e49 | 3621 | #ifdef DWARF2_DEBUGGING_INFO |
7d9d8943 AM |
3622 | /* This location is used by calc_die_sizes() to keep track |
3623 | the offset of each DIE within the .debug_info section. */ | |
3624 | static unsigned long next_die_offset; | |
c1b50e49 | 3625 | #endif |
7d9d8943 AM |
3626 | |
3627 | /* Record the root of the DIE's built for the current compilation unit. */ | |
17211ab5 | 3628 | static GTY(()) dw_die_ref comp_unit_die; |
7d9d8943 AM |
3629 | |
3630 | /* A list of DIEs with a NULL parent waiting to be relocated. */ | |
17211ab5 | 3631 | static GTY(()) limbo_die_node *limbo_die_list; |
7d9d8943 | 3632 | |
981975b6 | 3633 | /* Filenames referenced by this compilation unit. */ |
c4274b22 | 3634 | static GTY(()) varray_type file_table; |
73c68f61 | 3635 | static GTY(()) varray_type file_table_emitted; |
c4274b22 | 3636 | static GTY(()) size_t file_table_last_lookup_index; |
2e18bbae | 3637 | |
636c7bc4 JZ |
3638 | /* A hash table of references to DIE's that describe declarations. |
3639 | The key is a DECL_UID() which is a unique number identifying each decl. */ | |
3640 | static GTY ((param_is (struct die_struct))) htab_t decl_die_table; | |
7d9d8943 | 3641 | |
0a2d3d69 DB |
3642 | /* Node of the variable location list. */ |
3643 | struct var_loc_node GTY ((chain_next ("%h.next"))) | |
3644 | { | |
3645 | rtx GTY (()) var_loc_note; | |
3646 | const char * GTY (()) label; | |
3647 | struct var_loc_node * GTY (()) next; | |
3648 | }; | |
3649 | ||
3650 | /* Variable location list. */ | |
3651 | struct var_loc_list_def GTY (()) | |
3652 | { | |
3653 | struct var_loc_node * GTY (()) first; | |
3654 | ||
3655 | /* Do not mark the last element of the chained list because | |
3656 | it is marked through the chain. */ | |
3657 | struct var_loc_node * GTY ((skip ("%h"))) last; | |
3658 | ||
3659 | /* DECL_UID of the variable decl. */ | |
3660 | unsigned int decl_id; | |
3661 | }; | |
3662 | typedef struct var_loc_list_def var_loc_list; | |
3663 | ||
0a2d3d69 DB |
3664 | |
3665 | /* Table of decl location linked lists. */ | |
3666 | static GTY ((param_is (var_loc_list))) htab_t decl_loc_table; | |
3667 | ||
7d9d8943 AM |
3668 | /* A pointer to the base of a list of references to DIE's that |
3669 | are uniquely identified by their tag, presence/absence of | |
3670 | children DIE's, and list of attribute/value pairs. */ | |
7080f735 | 3671 | static GTY((length ("abbrev_die_table_allocated"))) |
17211ab5 | 3672 | dw_die_ref *abbrev_die_table; |
7d9d8943 AM |
3673 | |
3674 | /* Number of elements currently allocated for abbrev_die_table. */ | |
c2e9147c | 3675 | static GTY(()) unsigned abbrev_die_table_allocated; |
7d9d8943 AM |
3676 | |
3677 | /* Number of elements in type_die_table currently in use. */ | |
c2e9147c | 3678 | static GTY(()) unsigned abbrev_die_table_in_use; |
7d9d8943 AM |
3679 | |
3680 | /* Size (in elements) of increments by which we may expand the | |
3681 | abbrev_die_table. */ | |
3682 | #define ABBREV_DIE_TABLE_INCREMENT 256 | |
3683 | ||
3684 | /* A pointer to the base of a table that contains line information | |
3685 | for each source code line in .text in the compilation unit. */ | |
7080f735 | 3686 | static GTY((length ("line_info_table_allocated"))) |
17211ab5 | 3687 | dw_line_info_ref line_info_table; |
7d9d8943 AM |
3688 | |
3689 | /* Number of elements currently allocated for line_info_table. */ | |
c2e9147c | 3690 | static GTY(()) unsigned line_info_table_allocated; |
7d9d8943 | 3691 | |
17211ab5 | 3692 | /* Number of elements in line_info_table currently in use. */ |
c2e9147c | 3693 | static GTY(()) unsigned line_info_table_in_use; |
7d9d8943 AM |
3694 | |
3695 | /* A pointer to the base of a table that contains line information | |
3696 | for each source code line outside of .text in the compilation unit. */ | |
17211ab5 GK |
3697 | static GTY ((length ("separate_line_info_table_allocated"))) |
3698 | dw_separate_line_info_ref separate_line_info_table; | |
7d9d8943 AM |
3699 | |
3700 | /* Number of elements currently allocated for separate_line_info_table. */ | |
c2e9147c | 3701 | static GTY(()) unsigned separate_line_info_table_allocated; |
7d9d8943 | 3702 | |
17211ab5 | 3703 | /* Number of elements in separate_line_info_table currently in use. */ |
c2e9147c | 3704 | static GTY(()) unsigned separate_line_info_table_in_use; |
7d9d8943 AM |
3705 | |
3706 | /* Size (in elements) of increments by which we may expand the | |
3707 | line_info_table. */ | |
3708 | #define LINE_INFO_TABLE_INCREMENT 1024 | |
3709 | ||
3710 | /* A pointer to the base of a table that contains a list of publicly | |
3711 | accessible names. */ | |
17211ab5 | 3712 | static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table; |
7d9d8943 AM |
3713 | |
3714 | /* Number of elements currently allocated for pubname_table. */ | |
c2e9147c | 3715 | static GTY(()) unsigned pubname_table_allocated; |
7d9d8943 AM |
3716 | |
3717 | /* Number of elements in pubname_table currently in use. */ | |
c2e9147c | 3718 | static GTY(()) unsigned pubname_table_in_use; |
7d9d8943 AM |
3719 | |
3720 | /* Size (in elements) of increments by which we may expand the | |
3721 | pubname_table. */ | |
3722 | #define PUBNAME_TABLE_INCREMENT 64 | |
3723 | ||
a20612aa | 3724 | /* Array of dies for which we should generate .debug_arange info. */ |
17211ab5 | 3725 | static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table; |
7d9d8943 AM |
3726 | |
3727 | /* Number of elements currently allocated for arange_table. */ | |
c2e9147c | 3728 | static GTY(()) unsigned arange_table_allocated; |
7d9d8943 AM |
3729 | |
3730 | /* Number of elements in arange_table currently in use. */ | |
c2e9147c | 3731 | static GTY(()) unsigned arange_table_in_use; |
7d9d8943 AM |
3732 | |
3733 | /* Size (in elements) of increments by which we may expand the | |
3734 | arange_table. */ | |
3735 | #define ARANGE_TABLE_INCREMENT 64 | |
3736 | ||
a20612aa | 3737 | /* Array of dies for which we should generate .debug_ranges info. */ |
17211ab5 | 3738 | static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table; |
a20612aa RH |
3739 | |
3740 | /* Number of elements currently allocated for ranges_table. */ | |
c2e9147c | 3741 | static GTY(()) unsigned ranges_table_allocated; |
a20612aa RH |
3742 | |
3743 | /* Number of elements in ranges_table currently in use. */ | |
c2e9147c | 3744 | static GTY(()) unsigned ranges_table_in_use; |
a20612aa RH |
3745 | |
3746 | /* Size (in elements) of increments by which we may expand the | |
3747 | ranges_table. */ | |
3748 | #define RANGES_TABLE_INCREMENT 64 | |
3749 | ||
63e46568 | 3750 | /* Whether we have location lists that need outputting */ |
c2e9147c | 3751 | static GTY(()) unsigned have_location_lists; |
63e46568 | 3752 | |
57d4f65c ZW |
3753 | /* Unique label counter. */ |
3754 | static GTY(()) unsigned int loclabel_num; | |
3755 | ||
c2e9147c | 3756 | #ifdef DWARF2_DEBUGGING_INFO |
7d9d8943 AM |
3757 | /* Record whether the function being analyzed contains inlined functions. */ |
3758 | static int current_function_has_inlines; | |
c1b50e49 | 3759 | #endif |
7d9d8943 AM |
3760 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
3761 | static int comp_unit_has_inlines; | |
3762 | #endif | |
3763 | ||
e0bb17a8 | 3764 | /* Number of file tables emitted in maybe_emit_file(). */ |
c2e9147c GK |
3765 | static GTY(()) int emitcount = 0; |
3766 | ||
71c0e7fc | 3767 | /* Number of internal labels generated by gen_internal_sym(). */ |
c2e9147c GK |
3768 | static GTY(()) int label_num; |
3769 | ||
17211ab5 GK |
3770 | #ifdef DWARF2_DEBUGGING_INFO |
3771 | ||
7d9d8943 AM |
3772 | /* Forward declarations for functions defined in this file. */ |
3773 | ||
7080f735 AJ |
3774 | static int is_pseudo_reg (rtx); |
3775 | static tree type_main_variant (tree); | |
3776 | static int is_tagged_type (tree); | |
3777 | static const char *dwarf_tag_name (unsigned); | |
3778 | static const char *dwarf_attr_name (unsigned); | |
3779 | static const char *dwarf_form_name (unsigned); | |
7d9d8943 | 3780 | #if 0 |
7080f735 | 3781 | static const char *dwarf_type_encoding_name (unsigned); |
7d9d8943 | 3782 | #endif |
7080f735 AJ |
3783 | static tree decl_ultimate_origin (tree); |
3784 | static tree block_ultimate_origin (tree); | |
3785 | static tree decl_class_context (tree); | |
3786 | static void add_dwarf_attr (dw_die_ref, dw_attr_ref); | |
3787 | static inline enum dw_val_class AT_class (dw_attr_ref); | |
3788 | static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned); | |
3789 | static inline unsigned AT_flag (dw_attr_ref); | |
799f628a JH |
3790 | static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT); |
3791 | static inline HOST_WIDE_INT AT_int (dw_attr_ref); | |
3792 | static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT); | |
3793 | static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref); | |
7080f735 AJ |
3794 | static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long, |
3795 | unsigned long); | |
e7ee3914 AM |
3796 | static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int, |
3797 | unsigned int, unsigned char *); | |
7080f735 AJ |
3798 | static hashval_t debug_str_do_hash (const void *); |
3799 | static int debug_str_eq (const void *, const void *); | |
3800 | static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *); | |
3801 | static inline const char *AT_string (dw_attr_ref); | |
3802 | static int AT_string_form (dw_attr_ref); | |
3803 | static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref); | |
47fcfa7b | 3804 | static void add_AT_specification (dw_die_ref, dw_die_ref); |
7080f735 AJ |
3805 | static inline dw_die_ref AT_ref (dw_attr_ref); |
3806 | static inline int AT_ref_external (dw_attr_ref); | |
3807 | static inline void set_AT_ref_external (dw_attr_ref, int); | |
3808 | static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned); | |
3809 | static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref); | |
3810 | static inline dw_loc_descr_ref AT_loc (dw_attr_ref); | |
3811 | static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute, | |
3812 | dw_loc_list_ref); | |
3813 | static inline dw_loc_list_ref AT_loc_list (dw_attr_ref); | |
3814 | static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx); | |
3815 | static inline rtx AT_addr (dw_attr_ref); | |
3816 | static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *); | |
3817 | static void add_AT_lbl_offset (dw_die_ref, enum dwarf_attribute, const char *); | |
799f628a JH |
3818 | static void add_AT_offset (dw_die_ref, enum dwarf_attribute, |
3819 | unsigned HOST_WIDE_INT); | |
7080f735 AJ |
3820 | static void add_AT_range_list (dw_die_ref, enum dwarf_attribute, |
3821 | unsigned long); | |
3822 | static inline const char *AT_lbl (dw_attr_ref); | |
3823 | static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute); | |
3824 | static const char *get_AT_low_pc (dw_die_ref); | |
3825 | static const char *get_AT_hi_pc (dw_die_ref); | |
3826 | static const char *get_AT_string (dw_die_ref, enum dwarf_attribute); | |
3827 | static int get_AT_flag (dw_die_ref, enum dwarf_attribute); | |
3828 | static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute); | |
3829 | static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute); | |
3830 | static bool is_c_family (void); | |
3831 | static bool is_cxx (void); | |
3832 | static bool is_java (void); | |
3833 | static bool is_fortran (void); | |
3834 | static bool is_ada (void); | |
3835 | static void remove_AT (dw_die_ref, enum dwarf_attribute); | |
6097b0c3 | 3836 | static void remove_child_TAG (dw_die_ref, enum dwarf_tag); |
7080f735 AJ |
3837 | static inline void free_die (dw_die_ref); |
3838 | static void remove_children (dw_die_ref); | |
3839 | static void add_child_die (dw_die_ref, dw_die_ref); | |
3840 | static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree); | |
3841 | static dw_die_ref lookup_type_die (tree); | |
3842 | static void equate_type_number_to_die (tree, dw_die_ref); | |
636c7bc4 JZ |
3843 | static hashval_t decl_die_table_hash (const void *); |
3844 | static int decl_die_table_eq (const void *, const void *); | |
7080f735 | 3845 | static dw_die_ref lookup_decl_die (tree); |
0a2d3d69 DB |
3846 | static hashval_t decl_loc_table_hash (const void *); |
3847 | static int decl_loc_table_eq (const void *, const void *); | |
3848 | static var_loc_list *lookup_decl_loc (tree); | |
7080f735 | 3849 | static void equate_decl_number_to_die (tree, dw_die_ref); |
0a2d3d69 | 3850 | static void add_var_loc_to_decl (tree, struct var_loc_node *); |
7080f735 AJ |
3851 | static void print_spaces (FILE *); |
3852 | static void print_die (dw_die_ref, FILE *); | |
3853 | static void print_dwarf_line_table (FILE *); | |
3854 | static void reverse_die_lists (dw_die_ref); | |
3855 | static void reverse_all_dies (dw_die_ref); | |
3856 | static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref); | |
3857 | static dw_die_ref pop_compile_unit (dw_die_ref); | |
3858 | static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *); | |
3859 | static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *); | |
3860 | static void die_checksum (dw_die_ref, struct md5_ctx *, int *); | |
3861 | static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *); | |
3862 | static int same_dw_val_p (dw_val_node *, dw_val_node *, int *); | |
3863 | static int same_attr_p (dw_attr_ref, dw_attr_ref, int *); | |
3864 | static int same_die_p (dw_die_ref, dw_die_ref, int *); | |
3865 | static int same_die_p_wrap (dw_die_ref, dw_die_ref); | |
3866 | static void compute_section_prefix (dw_die_ref); | |
3867 | static int is_type_die (dw_die_ref); | |
3868 | static int is_comdat_die (dw_die_ref); | |
3869 | static int is_symbol_die (dw_die_ref); | |
3870 | static void assign_symbol_names (dw_die_ref); | |
3871 | static void break_out_includes (dw_die_ref); | |
3872 | static hashval_t htab_cu_hash (const void *); | |
3873 | static int htab_cu_eq (const void *, const void *); | |
3874 | static void htab_cu_del (void *); | |
3875 | static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *); | |
3876 | static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned); | |
3877 | static void add_sibling_attributes (dw_die_ref); | |
3878 | static void build_abbrev_table (dw_die_ref); | |
3879 | static void output_location_lists (dw_die_ref); | |
3880 | static int constant_size (long unsigned); | |
3881 | static unsigned long size_of_die (dw_die_ref); | |
3882 | static void calc_die_sizes (dw_die_ref); | |
3883 | static void mark_dies (dw_die_ref); | |
3884 | static void unmark_dies (dw_die_ref); | |
3885 | static void unmark_all_dies (dw_die_ref); | |
3886 | static unsigned long size_of_pubnames (void); | |
3887 | static unsigned long size_of_aranges (void); | |
3888 | static enum dwarf_form value_format (dw_attr_ref); | |
3889 | static void output_value_format (dw_attr_ref); | |
3890 | static void output_abbrev_section (void); | |
3891 | static void output_die_symbol (dw_die_ref); | |
3892 | static void output_die (dw_die_ref); | |
3893 | static void output_compilation_unit_header (void); | |
3894 | static void output_comp_unit (dw_die_ref, int); | |
3895 | static const char *dwarf2_name (tree, int); | |
3896 | static void add_pubname (tree, dw_die_ref); | |
3897 | static void output_pubnames (void); | |
3898 | static void add_arange (tree, dw_die_ref); | |
3899 | static void output_aranges (void); | |
3900 | static unsigned int add_ranges (tree); | |
3901 | static void output_ranges (void); | |
3902 | static void output_line_info (void); | |
3903 | static void output_file_names (void); | |
3904 | static dw_die_ref base_type_die (tree); | |
3905 | static tree root_type (tree); | |
3906 | static int is_base_type (tree); | |
e7d23ce3 | 3907 | static bool is_subrange_type (tree); |
fbfd77b8 | 3908 | static dw_die_ref subrange_type_die (tree, dw_die_ref); |
7080f735 AJ |
3909 | static dw_die_ref modified_type_die (tree, int, int, dw_die_ref); |
3910 | static int type_is_enum (tree); | |
23959f19 | 3911 | static unsigned int dbx_reg_number (rtx); |
7080f735 AJ |
3912 | static dw_loc_descr_ref reg_loc_descriptor (rtx); |
3913 | static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int); | |
3914 | static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx); | |
3915 | static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT); | |
0a2d3d69 | 3916 | static dw_loc_descr_ref based_loc_descr (unsigned, HOST_WIDE_INT, bool); |
7080f735 | 3917 | static int is_based_loc (rtx); |
0a2d3d69 | 3918 | static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode, bool); |
7080f735 | 3919 | static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx); |
0a2d3d69 | 3920 | static dw_loc_descr_ref loc_descriptor (rtx, bool); |
7080f735 AJ |
3921 | static dw_loc_descr_ref loc_descriptor_from_tree (tree, int); |
3922 | static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int); | |
3923 | static tree field_type (tree); | |
3924 | static unsigned int simple_type_align_in_bits (tree); | |
3925 | static unsigned int simple_decl_align_in_bits (tree); | |
3926 | static unsigned HOST_WIDE_INT simple_type_size_in_bits (tree); | |
3927 | static HOST_WIDE_INT field_byte_offset (tree); | |
3928 | static void add_AT_location_description (dw_die_ref, enum dwarf_attribute, | |
3929 | dw_loc_descr_ref); | |
3930 | static void add_data_member_location_attribute (dw_die_ref, tree); | |
3931 | static void add_const_value_attribute (dw_die_ref, rtx); | |
e7ee3914 AM |
3932 | static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *); |
3933 | static HOST_WIDE_INT extract_int (const unsigned char *, unsigned); | |
3934 | static void insert_float (rtx, unsigned char *); | |
7080f735 | 3935 | static rtx rtl_for_decl_location (tree); |
0a2d3d69 DB |
3936 | static void add_location_or_const_value_attribute (dw_die_ref, tree, |
3937 | enum dwarf_attribute); | |
7080f735 AJ |
3938 | static void tree_add_const_value_attribute (dw_die_ref, tree); |
3939 | static void add_name_attribute (dw_die_ref, const char *); | |
3940 | static void add_comp_dir_attribute (dw_die_ref); | |
3941 | static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree); | |
3942 | static void add_subscript_info (dw_die_ref, tree); | |
3943 | static void add_byte_size_attribute (dw_die_ref, tree); | |
3944 | static void add_bit_offset_attribute (dw_die_ref, tree); | |
3945 | static void add_bit_size_attribute (dw_die_ref, tree); | |
3946 | static void add_prototyped_attribute (dw_die_ref, tree); | |
3947 | static void add_abstract_origin_attribute (dw_die_ref, tree); | |
3948 | static void add_pure_or_virtual_attribute (dw_die_ref, tree); | |
3949 | static void add_src_coords_attributes (dw_die_ref, tree); | |
3950 | static void add_name_and_src_coords_attributes (dw_die_ref, tree); | |
3951 | static void push_decl_scope (tree); | |
3952 | static void pop_decl_scope (void); | |
3953 | static dw_die_ref scope_die_for (tree, dw_die_ref); | |
3954 | static inline int local_scope_p (dw_die_ref); | |
66c78aa9 | 3955 | static inline int class_or_namespace_scope_p (dw_die_ref); |
7080f735 AJ |
3956 | static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref); |
3957 | static const char *type_tag (tree); | |
3958 | static tree member_declared_type (tree); | |
7d9d8943 | 3959 | #if 0 |
7080f735 | 3960 | static const char *decl_start_label (tree); |
7d9d8943 | 3961 | #endif |
7080f735 AJ |
3962 | static void gen_array_type_die (tree, dw_die_ref); |
3963 | static void gen_set_type_die (tree, dw_die_ref); | |
7d9d8943 | 3964 | #if 0 |
7080f735 | 3965 | static void gen_entry_point_die (tree, dw_die_ref); |
7d9d8943 | 3966 | #endif |
7080f735 AJ |
3967 | static void gen_inlined_enumeration_type_die (tree, dw_die_ref); |
3968 | static void gen_inlined_structure_type_die (tree, dw_die_ref); | |
3969 | static void gen_inlined_union_type_die (tree, dw_die_ref); | |
de99511b | 3970 | static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref); |
7080f735 AJ |
3971 | static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref); |
3972 | static void gen_unspecified_parameters_die (tree, dw_die_ref); | |
3973 | static void gen_formal_types_die (tree, dw_die_ref); | |
3974 | static void gen_subprogram_die (tree, dw_die_ref); | |
3975 | static void gen_variable_die (tree, dw_die_ref); | |
3976 | static void gen_label_die (tree, dw_die_ref); | |
3977 | static void gen_lexical_block_die (tree, dw_die_ref, int); | |
3978 | static void gen_inlined_subroutine_die (tree, dw_die_ref, int); | |
3979 | static void gen_field_die (tree, dw_die_ref); | |
3980 | static void gen_ptr_to_mbr_type_die (tree, dw_die_ref); | |
3981 | static dw_die_ref gen_compile_unit_die (const char *); | |
3982 | static void gen_string_type_die (tree, dw_die_ref); | |
3983 | static void gen_inheritance_die (tree, tree, dw_die_ref); | |
3984 | static void gen_member_die (tree, dw_die_ref); | |
3985 | static void gen_struct_or_union_type_die (tree, dw_die_ref); | |
3986 | static void gen_subroutine_type_die (tree, dw_die_ref); | |
3987 | static void gen_typedef_die (tree, dw_die_ref); | |
3988 | static void gen_type_die (tree, dw_die_ref); | |
3989 | static void gen_tagged_type_instantiation_die (tree, dw_die_ref); | |
3990 | static void gen_block_die (tree, dw_die_ref, int); | |
3991 | static void decls_for_scope (tree, dw_die_ref, int); | |
3992 | static int is_redundant_typedef (tree); | |
66c78aa9 | 3993 | static void gen_namespace_die (tree); |
7080f735 | 3994 | static void gen_decl_die (tree, dw_die_ref); |
6097b0c3 DP |
3995 | static dw_die_ref force_decl_die (tree); |
3996 | static dw_die_ref force_type_die (tree); | |
66c78aa9 JM |
3997 | static dw_die_ref setup_namespace_context (tree, dw_die_ref); |
3998 | static void declare_in_namespace (tree, dw_die_ref); | |
7080f735 AJ |
3999 | static unsigned lookup_filename (const char *); |
4000 | static void init_file_table (void); | |
4001 | static void retry_incomplete_types (void); | |
4002 | static void gen_type_die_for_member (tree, tree, dw_die_ref); | |
4003 | static void splice_child_die (dw_die_ref, dw_die_ref); | |
4004 | static int file_info_cmp (const void *, const void *); | |
4005 | static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *, | |
4006 | const char *, const char *, unsigned); | |
4007 | static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref, | |
4008 | const char *, const char *, | |
4009 | const char *); | |
4010 | static void output_loc_list (dw_loc_list_ref); | |
4011 | static char *gen_internal_sym (const char *); | |
4012 | ||
4013 | static void prune_unmark_dies (dw_die_ref); | |
4014 | static void prune_unused_types_mark (dw_die_ref, int); | |
4015 | static void prune_unused_types_walk (dw_die_ref); | |
4016 | static void prune_unused_types_walk_attribs (dw_die_ref); | |
4017 | static void prune_unused_types_prune (dw_die_ref); | |
4018 | static void prune_unused_types (void); | |
4019 | static int maybe_emit_file (int); | |
73c68f61 | 4020 | |
7d9d8943 AM |
4021 | /* Section names used to hold DWARF debugging information. */ |
4022 | #ifndef DEBUG_INFO_SECTION | |
4023 | #define DEBUG_INFO_SECTION ".debug_info" | |
4024 | #endif | |
9d2f2c45 RH |
4025 | #ifndef DEBUG_ABBREV_SECTION |
4026 | #define DEBUG_ABBREV_SECTION ".debug_abbrev" | |
7d9d8943 | 4027 | #endif |
9d2f2c45 RH |
4028 | #ifndef DEBUG_ARANGES_SECTION |
4029 | #define DEBUG_ARANGES_SECTION ".debug_aranges" | |
7d9d8943 | 4030 | #endif |
9d2f2c45 RH |
4031 | #ifndef DEBUG_MACINFO_SECTION |
4032 | #define DEBUG_MACINFO_SECTION ".debug_macinfo" | |
7d9d8943 AM |
4033 | #endif |
4034 | #ifndef DEBUG_LINE_SECTION | |
4035 | #define DEBUG_LINE_SECTION ".debug_line" | |
4036 | #endif | |
9d2f2c45 RH |
4037 | #ifndef DEBUG_LOC_SECTION |
4038 | #define DEBUG_LOC_SECTION ".debug_loc" | |
7d9d8943 | 4039 | #endif |
9d2f2c45 RH |
4040 | #ifndef DEBUG_PUBNAMES_SECTION |
4041 | #define DEBUG_PUBNAMES_SECTION ".debug_pubnames" | |
7d9d8943 | 4042 | #endif |
9d2f2c45 RH |
4043 | #ifndef DEBUG_STR_SECTION |
4044 | #define DEBUG_STR_SECTION ".debug_str" | |
7d9d8943 | 4045 | #endif |
a20612aa RH |
4046 | #ifndef DEBUG_RANGES_SECTION |
4047 | #define DEBUG_RANGES_SECTION ".debug_ranges" | |
4048 | #endif | |
7d9d8943 AM |
4049 | |
4050 | /* Standard ELF section names for compiled code and data. */ | |
f99ffb60 RH |
4051 | #ifndef TEXT_SECTION_NAME |
4052 | #define TEXT_SECTION_NAME ".text" | |
7d9d8943 AM |
4053 | #endif |
4054 | ||
9eb4015a | 4055 | /* Section flags for .debug_str section. */ |
9eb4015a | 4056 | #define DEBUG_STR_SECTION_FLAGS \ |
5d4856a0 | 4057 | (HAVE_GAS_SHF_MERGE && flag_merge_constants \ |
b0c242c0 AM |
4058 | ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \ |
4059 | : SECTION_DEBUG) | |
9eb4015a | 4060 | |
7d9d8943 | 4061 | /* Labels we insert at beginning sections we can reference instead of |
556273e0 | 4062 | the section names themselves. */ |
7d9d8943 AM |
4063 | |
4064 | #ifndef TEXT_SECTION_LABEL | |
9d2f2c45 | 4065 | #define TEXT_SECTION_LABEL "Ltext" |
7d9d8943 AM |
4066 | #endif |
4067 | #ifndef DEBUG_LINE_SECTION_LABEL | |
9d2f2c45 | 4068 | #define DEBUG_LINE_SECTION_LABEL "Ldebug_line" |
7d9d8943 AM |
4069 | #endif |
4070 | #ifndef DEBUG_INFO_SECTION_LABEL | |
9d2f2c45 | 4071 | #define DEBUG_INFO_SECTION_LABEL "Ldebug_info" |
7d9d8943 | 4072 | #endif |
9d2f2c45 RH |
4073 | #ifndef DEBUG_ABBREV_SECTION_LABEL |
4074 | #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev" | |
7d9d8943 | 4075 | #endif |
9d2f2c45 RH |
4076 | #ifndef DEBUG_LOC_SECTION_LABEL |
4077 | #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc" | |
63e46568 | 4078 | #endif |
2bee6045 JJ |
4079 | #ifndef DEBUG_RANGES_SECTION_LABEL |
4080 | #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges" | |
4081 | #endif | |
84a5b4f8 DB |
4082 | #ifndef DEBUG_MACINFO_SECTION_LABEL |
4083 | #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo" | |
4084 | #endif | |
a20612aa | 4085 | |
7d9d8943 AM |
4086 | /* Definitions of defaults for formats and names of various special |
4087 | (artificial) labels which may be generated within this file (when the -g | |
def66b10 | 4088 | options is used and DWARF2_DEBUGGING_INFO is in effect. |
7d9d8943 AM |
4089 | If necessary, these may be overridden from within the tm.h file, but |
4090 | typically, overriding these defaults is unnecessary. */ | |
4091 | ||
4092 | static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4093 | static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4094 | static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4095 | static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4096 | static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
84a5b4f8 | 4097 | static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
63e46568 | 4098 | static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
2bee6045 | 4099 | static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES]; |
2ad9852d | 4100 | |
7d9d8943 AM |
4101 | #ifndef TEXT_END_LABEL |
4102 | #define TEXT_END_LABEL "Letext" | |
4103 | #endif | |
7d9d8943 AM |
4104 | #ifndef BLOCK_BEGIN_LABEL |
4105 | #define BLOCK_BEGIN_LABEL "LBB" | |
4106 | #endif | |
4107 | #ifndef BLOCK_END_LABEL | |
4108 | #define BLOCK_END_LABEL "LBE" | |
4109 | #endif | |
7d9d8943 AM |
4110 | #ifndef LINE_CODE_LABEL |
4111 | #define LINE_CODE_LABEL "LM" | |
4112 | #endif | |
4113 | #ifndef SEPARATE_LINE_CODE_LABEL | |
4114 | #define SEPARATE_LINE_CODE_LABEL "LSM" | |
4115 | #endif | |
4116 | \f | |
4117 | /* We allow a language front-end to designate a function that is to be | |
4118 | called to "demangle" any name before it it put into a DIE. */ | |
4119 | ||
7080f735 | 4120 | static const char *(*demangle_name_func) (const char *); |
7d9d8943 AM |
4121 | |
4122 | void | |
7080f735 | 4123 | dwarf2out_set_demangle_name_func (const char *(*func) (const char *)) |
7d9d8943 AM |
4124 | { |
4125 | demangle_name_func = func; | |
4126 | } | |
7d9d8943 AM |
4127 | |
4128 | /* Test if rtl node points to a pseudo register. */ | |
4129 | ||
4130 | static inline int | |
7080f735 | 4131 | is_pseudo_reg (rtx rtl) |
7d9d8943 | 4132 | { |
f8cfc6aa | 4133 | return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER) |
7d9d8943 | 4134 | || (GET_CODE (rtl) == SUBREG |
ddef6bc7 | 4135 | && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)); |
7d9d8943 AM |
4136 | } |
4137 | ||
4138 | /* Return a reference to a type, with its const and volatile qualifiers | |
4139 | removed. */ | |
4140 | ||
4141 | static inline tree | |
7080f735 | 4142 | type_main_variant (tree type) |
7d9d8943 AM |
4143 | { |
4144 | type = TYPE_MAIN_VARIANT (type); | |
4145 | ||
2ad9852d RK |
4146 | /* ??? There really should be only one main variant among any group of |
4147 | variants of a given type (and all of the MAIN_VARIANT values for all | |
4148 | members of the group should point to that one type) but sometimes the C | |
4149 | front-end messes this up for array types, so we work around that bug | |
4150 | here. */ | |
7d9d8943 AM |
4151 | if (TREE_CODE (type) == ARRAY_TYPE) |
4152 | while (type != TYPE_MAIN_VARIANT (type)) | |
4153 | type = TYPE_MAIN_VARIANT (type); | |
4154 | ||
4155 | return type; | |
4156 | } | |
4157 | ||
cc2902df | 4158 | /* Return nonzero if the given type node represents a tagged type. */ |
7d9d8943 AM |
4159 | |
4160 | static inline int | |
7080f735 | 4161 | is_tagged_type (tree type) |
7d9d8943 | 4162 | { |
b3694847 | 4163 | enum tree_code code = TREE_CODE (type); |
7d9d8943 AM |
4164 | |
4165 | return (code == RECORD_TYPE || code == UNION_TYPE | |
4166 | || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); | |
4167 | } | |
4168 | ||
4169 | /* Convert a DIE tag into its string name. */ | |
4170 | ||
4171 | static const char * | |
7080f735 | 4172 | dwarf_tag_name (unsigned int tag) |
7d9d8943 AM |
4173 | { |
4174 | switch (tag) | |
4175 | { | |
4176 | case DW_TAG_padding: | |
4177 | return "DW_TAG_padding"; | |
4178 | case DW_TAG_array_type: | |
4179 | return "DW_TAG_array_type"; | |
4180 | case DW_TAG_class_type: | |
4181 | return "DW_TAG_class_type"; | |
4182 | case DW_TAG_entry_point: | |
4183 | return "DW_TAG_entry_point"; | |
4184 | case DW_TAG_enumeration_type: | |
4185 | return "DW_TAG_enumeration_type"; | |
4186 | case DW_TAG_formal_parameter: | |
4187 | return "DW_TAG_formal_parameter"; | |
4188 | case DW_TAG_imported_declaration: | |
4189 | return "DW_TAG_imported_declaration"; | |
4190 | case DW_TAG_label: | |
4191 | return "DW_TAG_label"; | |
4192 | case DW_TAG_lexical_block: | |
4193 | return "DW_TAG_lexical_block"; | |
4194 | case DW_TAG_member: | |
4195 | return "DW_TAG_member"; | |
4196 | case DW_TAG_pointer_type: | |
4197 | return "DW_TAG_pointer_type"; | |
4198 | case DW_TAG_reference_type: | |
4199 | return "DW_TAG_reference_type"; | |
4200 | case DW_TAG_compile_unit: | |
4201 | return "DW_TAG_compile_unit"; | |
4202 | case DW_TAG_string_type: | |
4203 | return "DW_TAG_string_type"; | |
4204 | case DW_TAG_structure_type: | |
4205 | return "DW_TAG_structure_type"; | |
4206 | case DW_TAG_subroutine_type: | |
4207 | return "DW_TAG_subroutine_type"; | |
4208 | case DW_TAG_typedef: | |
4209 | return "DW_TAG_typedef"; | |
4210 | case DW_TAG_union_type: | |
4211 | return "DW_TAG_union_type"; | |
4212 | case DW_TAG_unspecified_parameters: | |
4213 | return "DW_TAG_unspecified_parameters"; | |
4214 | case DW_TAG_variant: | |
4215 | return "DW_TAG_variant"; | |
4216 | case DW_TAG_common_block: | |
4217 | return "DW_TAG_common_block"; | |
4218 | case DW_TAG_common_inclusion: | |
4219 | return "DW_TAG_common_inclusion"; | |
4220 | case DW_TAG_inheritance: | |
4221 | return "DW_TAG_inheritance"; | |
4222 | case DW_TAG_inlined_subroutine: | |
4223 | return "DW_TAG_inlined_subroutine"; | |
4224 | case DW_TAG_module: | |
4225 | return "DW_TAG_module"; | |
4226 | case DW_TAG_ptr_to_member_type: | |
4227 | return "DW_TAG_ptr_to_member_type"; | |
4228 | case DW_TAG_set_type: | |
4229 | return "DW_TAG_set_type"; | |
4230 | case DW_TAG_subrange_type: | |
4231 | return "DW_TAG_subrange_type"; | |
4232 | case DW_TAG_with_stmt: | |
4233 | return "DW_TAG_with_stmt"; | |
4234 | case DW_TAG_access_declaration: | |
4235 | return "DW_TAG_access_declaration"; | |
4236 | case DW_TAG_base_type: | |
4237 | return "DW_TAG_base_type"; | |
4238 | case DW_TAG_catch_block: | |
4239 | return "DW_TAG_catch_block"; | |
4240 | case DW_TAG_const_type: | |
4241 | return "DW_TAG_const_type"; | |
4242 | case DW_TAG_constant: | |
4243 | return "DW_TAG_constant"; | |
4244 | case DW_TAG_enumerator: | |
4245 | return "DW_TAG_enumerator"; | |
4246 | case DW_TAG_file_type: | |
4247 | return "DW_TAG_file_type"; | |
4248 | case DW_TAG_friend: | |
4249 | return "DW_TAG_friend"; | |
4250 | case DW_TAG_namelist: | |
4251 | return "DW_TAG_namelist"; | |
4252 | case DW_TAG_namelist_item: | |
4253 | return "DW_TAG_namelist_item"; | |
66c78aa9 JM |
4254 | case DW_TAG_namespace: |
4255 | return "DW_TAG_namespace"; | |
7d9d8943 AM |
4256 | case DW_TAG_packed_type: |
4257 | return "DW_TAG_packed_type"; | |
4258 | case DW_TAG_subprogram: | |
4259 | return "DW_TAG_subprogram"; | |
4260 | case DW_TAG_template_type_param: | |
4261 | return "DW_TAG_template_type_param"; | |
4262 | case DW_TAG_template_value_param: | |
4263 | return "DW_TAG_template_value_param"; | |
4264 | case DW_TAG_thrown_type: | |
4265 | return "DW_TAG_thrown_type"; | |
4266 | case DW_TAG_try_block: | |
4267 | return "DW_TAG_try_block"; | |
4268 | case DW_TAG_variant_part: | |
4269 | return "DW_TAG_variant_part"; | |
4270 | case DW_TAG_variable: | |
4271 | return "DW_TAG_variable"; | |
4272 | case DW_TAG_volatile_type: | |
4273 | return "DW_TAG_volatile_type"; | |
6097b0c3 DP |
4274 | case DW_TAG_imported_module: |
4275 | return "DW_TAG_imported_module"; | |
7d9d8943 AM |
4276 | case DW_TAG_MIPS_loop: |
4277 | return "DW_TAG_MIPS_loop"; | |
4278 | case DW_TAG_format_label: | |
4279 | return "DW_TAG_format_label"; | |
4280 | case DW_TAG_function_template: | |
4281 | return "DW_TAG_function_template"; | |
4282 | case DW_TAG_class_template: | |
4283 | return "DW_TAG_class_template"; | |
881c6935 JM |
4284 | case DW_TAG_GNU_BINCL: |
4285 | return "DW_TAG_GNU_BINCL"; | |
4286 | case DW_TAG_GNU_EINCL: | |
4287 | return "DW_TAG_GNU_EINCL"; | |
7d9d8943 AM |
4288 | default: |
4289 | return "DW_TAG_<unknown>"; | |
4290 | } | |
4291 | } | |
4292 | ||
4293 | /* Convert a DWARF attribute code into its string name. */ | |
4294 | ||
4295 | static const char * | |
7080f735 | 4296 | dwarf_attr_name (unsigned int attr) |
7d9d8943 AM |
4297 | { |
4298 | switch (attr) | |
4299 | { | |
4300 | case DW_AT_sibling: | |
4301 | return "DW_AT_sibling"; | |
4302 | case DW_AT_location: | |
4303 | return "DW_AT_location"; | |
4304 | case DW_AT_name: | |
4305 | return "DW_AT_name"; | |
4306 | case DW_AT_ordering: | |
4307 | return "DW_AT_ordering"; | |
4308 | case DW_AT_subscr_data: | |
4309 | return "DW_AT_subscr_data"; | |
4310 | case DW_AT_byte_size: | |
4311 | return "DW_AT_byte_size"; | |
4312 | case DW_AT_bit_offset: | |
4313 | return "DW_AT_bit_offset"; | |
4314 | case DW_AT_bit_size: | |
4315 | return "DW_AT_bit_size"; | |
4316 | case DW_AT_element_list: | |
4317 | return "DW_AT_element_list"; | |
4318 | case DW_AT_stmt_list: | |
4319 | return "DW_AT_stmt_list"; | |
4320 | case DW_AT_low_pc: | |
4321 | return "DW_AT_low_pc"; | |
4322 | case DW_AT_high_pc: | |
4323 | return "DW_AT_high_pc"; | |
4324 | case DW_AT_language: | |
4325 | return "DW_AT_language"; | |
4326 | case DW_AT_member: | |
4327 | return "DW_AT_member"; | |
4328 | case DW_AT_discr: | |
4329 | return "DW_AT_discr"; | |
4330 | case DW_AT_discr_value: | |
4331 | return "DW_AT_discr_value"; | |
4332 | case DW_AT_visibility: | |
4333 | return "DW_AT_visibility"; | |
4334 | case DW_AT_import: | |
4335 | return "DW_AT_import"; | |
4336 | case DW_AT_string_length: | |
4337 | return "DW_AT_string_length"; | |
4338 | case DW_AT_common_reference: | |
4339 | return "DW_AT_common_reference"; | |
4340 | case DW_AT_comp_dir: | |
4341 | return "DW_AT_comp_dir"; | |
4342 | case DW_AT_const_value: | |
4343 | return "DW_AT_const_value"; | |
4344 | case DW_AT_containing_type: | |
4345 | return "DW_AT_containing_type"; | |
4346 | case DW_AT_default_value: | |
4347 | return "DW_AT_default_value"; | |
4348 | case DW_AT_inline: | |
4349 | return "DW_AT_inline"; | |
4350 | case DW_AT_is_optional: | |
4351 | return "DW_AT_is_optional"; | |
4352 | case DW_AT_lower_bound: | |
4353 | return "DW_AT_lower_bound"; | |
4354 | case DW_AT_producer: | |
4355 | return "DW_AT_producer"; | |
4356 | case DW_AT_prototyped: | |
4357 | return "DW_AT_prototyped"; | |
4358 | case DW_AT_return_addr: | |
4359 | return "DW_AT_return_addr"; | |
4360 | case DW_AT_start_scope: | |
4361 | return "DW_AT_start_scope"; | |
4362 | case DW_AT_stride_size: | |
4363 | return "DW_AT_stride_size"; | |
4364 | case DW_AT_upper_bound: | |
4365 | return "DW_AT_upper_bound"; | |
4366 | case DW_AT_abstract_origin: | |
4367 | return "DW_AT_abstract_origin"; | |
4368 | case DW_AT_accessibility: | |
4369 | return "DW_AT_accessibility"; | |
4370 | case DW_AT_address_class: | |
4371 | return "DW_AT_address_class"; | |
4372 | case DW_AT_artificial: | |
4373 | return "DW_AT_artificial"; | |
4374 | case DW_AT_base_types: | |
4375 | return "DW_AT_base_types"; | |
4376 | case DW_AT_calling_convention: | |
4377 | return "DW_AT_calling_convention"; | |
4378 | case DW_AT_count: | |
4379 | return "DW_AT_count"; | |
4380 | case DW_AT_data_member_location: | |
4381 | return "DW_AT_data_member_location"; | |
4382 | case DW_AT_decl_column: | |
4383 | return "DW_AT_decl_column"; | |
4384 | case DW_AT_decl_file: | |
4385 | return "DW_AT_decl_file"; | |
4386 | case DW_AT_decl_line: | |
4387 | return "DW_AT_decl_line"; | |
4388 | case DW_AT_declaration: | |
4389 | return "DW_AT_declaration"; | |
4390 | case DW_AT_discr_list: | |
4391 | return "DW_AT_discr_list"; | |
4392 | case DW_AT_encoding: | |
4393 | return "DW_AT_encoding"; | |
4394 | case DW_AT_external: | |
4395 | return "DW_AT_external"; | |
4396 | case DW_AT_frame_base: | |
4397 | return "DW_AT_frame_base"; | |
4398 | case DW_AT_friend: | |
4399 | return "DW_AT_friend"; | |
4400 | case DW_AT_identifier_case: | |
4401 | return "DW_AT_identifier_case"; | |
4402 | case DW_AT_macro_info: | |
4403 | return "DW_AT_macro_info"; | |
4404 | case DW_AT_namelist_items: | |
4405 | return "DW_AT_namelist_items"; | |
4406 | case DW_AT_priority: | |
4407 | return "DW_AT_priority"; | |
4408 | case DW_AT_segment: | |
4409 | return "DW_AT_segment"; | |
4410 | case DW_AT_specification: | |
4411 | return "DW_AT_specification"; | |
4412 | case DW_AT_static_link: | |
4413 | return "DW_AT_static_link"; | |
4414 | case DW_AT_type: | |
4415 | return "DW_AT_type"; | |
4416 | case DW_AT_use_location: | |
4417 | return "DW_AT_use_location"; | |
4418 | case DW_AT_variable_parameter: | |
4419 | return "DW_AT_variable_parameter"; | |
4420 | case DW_AT_virtuality: | |
4421 | return "DW_AT_virtuality"; | |
4422 | case DW_AT_vtable_elem_location: | |
4423 | return "DW_AT_vtable_elem_location"; | |
4424 | ||
a20612aa RH |
4425 | case DW_AT_allocated: |
4426 | return "DW_AT_allocated"; | |
4427 | case DW_AT_associated: | |
4428 | return "DW_AT_associated"; | |
4429 | case DW_AT_data_location: | |
4430 | return "DW_AT_data_location"; | |
4431 | case DW_AT_stride: | |
4432 | return "DW_AT_stride"; | |
4433 | case DW_AT_entry_pc: | |
4434 | return "DW_AT_entry_pc"; | |
4435 | case DW_AT_use_UTF8: | |
4436 | return "DW_AT_use_UTF8"; | |
4437 | case DW_AT_extension: | |
4438 | return "DW_AT_extension"; | |
4439 | case DW_AT_ranges: | |
4440 | return "DW_AT_ranges"; | |
4441 | case DW_AT_trampoline: | |
4442 | return "DW_AT_trampoline"; | |
4443 | case DW_AT_call_column: | |
4444 | return "DW_AT_call_column"; | |
4445 | case DW_AT_call_file: | |
4446 | return "DW_AT_call_file"; | |
4447 | case DW_AT_call_line: | |
4448 | return "DW_AT_call_line"; | |
4449 | ||
7d9d8943 AM |
4450 | case DW_AT_MIPS_fde: |
4451 | return "DW_AT_MIPS_fde"; | |
4452 | case DW_AT_MIPS_loop_begin: | |
4453 | return "DW_AT_MIPS_loop_begin"; | |
4454 | case DW_AT_MIPS_tail_loop_begin: | |
4455 | return "DW_AT_MIPS_tail_loop_begin"; | |
4456 | case DW_AT_MIPS_epilog_begin: | |
4457 | return "DW_AT_MIPS_epilog_begin"; | |
4458 | case DW_AT_MIPS_loop_unroll_factor: | |
4459 | return "DW_AT_MIPS_loop_unroll_factor"; | |
4460 | case DW_AT_MIPS_software_pipeline_depth: | |
4461 | return "DW_AT_MIPS_software_pipeline_depth"; | |
4462 | case DW_AT_MIPS_linkage_name: | |
4463 | return "DW_AT_MIPS_linkage_name"; | |
4464 | case DW_AT_MIPS_stride: | |
4465 | return "DW_AT_MIPS_stride"; | |
4466 | case DW_AT_MIPS_abstract_name: | |
4467 | return "DW_AT_MIPS_abstract_name"; | |
4468 | case DW_AT_MIPS_clone_origin: | |
4469 | return "DW_AT_MIPS_clone_origin"; | |
4470 | case DW_AT_MIPS_has_inlines: | |
4471 | return "DW_AT_MIPS_has_inlines"; | |
4472 | ||
4473 | case DW_AT_sf_names: | |
4474 | return "DW_AT_sf_names"; | |
4475 | case DW_AT_src_info: | |
4476 | return "DW_AT_src_info"; | |
4477 | case DW_AT_mac_info: | |
4478 | return "DW_AT_mac_info"; | |
4479 | case DW_AT_src_coords: | |
4480 | return "DW_AT_src_coords"; | |
4481 | case DW_AT_body_begin: | |
4482 | return "DW_AT_body_begin"; | |
4483 | case DW_AT_body_end: | |
4484 | return "DW_AT_body_end"; | |
84f0ace0 JM |
4485 | case DW_AT_GNU_vector: |
4486 | return "DW_AT_GNU_vector"; | |
4487 | ||
7a0c8d71 DR |
4488 | case DW_AT_VMS_rtnbeg_pd_address: |
4489 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
4490 | ||
7d9d8943 AM |
4491 | default: |
4492 | return "DW_AT_<unknown>"; | |
4493 | } | |
4494 | } | |
4495 | ||
4496 | /* Convert a DWARF value form code into its string name. */ | |
4497 | ||
4498 | static const char * | |
7080f735 | 4499 | dwarf_form_name (unsigned int form) |
7d9d8943 AM |
4500 | { |
4501 | switch (form) | |
4502 | { | |
4503 | case DW_FORM_addr: | |
4504 | return "DW_FORM_addr"; | |
4505 | case DW_FORM_block2: | |
4506 | return "DW_FORM_block2"; | |
4507 | case DW_FORM_block4: | |
4508 | return "DW_FORM_block4"; | |
4509 | case DW_FORM_data2: | |
4510 | return "DW_FORM_data2"; | |
4511 | case DW_FORM_data4: | |
4512 | return "DW_FORM_data4"; | |
4513 | case DW_FORM_data8: | |
4514 | return "DW_FORM_data8"; | |
4515 | case DW_FORM_string: | |
4516 | return "DW_FORM_string"; | |
4517 | case DW_FORM_block: | |
4518 | return "DW_FORM_block"; | |
4519 | case DW_FORM_block1: | |
4520 | return "DW_FORM_block1"; | |
4521 | case DW_FORM_data1: | |
4522 | return "DW_FORM_data1"; | |
4523 | case DW_FORM_flag: | |
4524 | return "DW_FORM_flag"; | |
4525 | case DW_FORM_sdata: | |
4526 | return "DW_FORM_sdata"; | |
4527 | case DW_FORM_strp: | |
4528 | return "DW_FORM_strp"; | |
4529 | case DW_FORM_udata: | |
4530 | return "DW_FORM_udata"; | |
4531 | case DW_FORM_ref_addr: | |
4532 | return "DW_FORM_ref_addr"; | |
4533 | case DW_FORM_ref1: | |
4534 | return "DW_FORM_ref1"; | |
4535 | case DW_FORM_ref2: | |
4536 | return "DW_FORM_ref2"; | |
4537 | case DW_FORM_ref4: | |
4538 | return "DW_FORM_ref4"; | |
4539 | case DW_FORM_ref8: | |
4540 | return "DW_FORM_ref8"; | |
4541 | case DW_FORM_ref_udata: | |
4542 | return "DW_FORM_ref_udata"; | |
4543 | case DW_FORM_indirect: | |
4544 | return "DW_FORM_indirect"; | |
3f76745e | 4545 | default: |
7d9d8943 | 4546 | return "DW_FORM_<unknown>"; |
a3f97cbb JW |
4547 | } |
4548 | } | |
4549 | ||
3f76745e | 4550 | /* Convert a DWARF type code into its string name. */ |
71dfc51f | 4551 | |
487a6e06 | 4552 | #if 0 |
d560ee52 | 4553 | static const char * |
7080f735 | 4554 | dwarf_type_encoding_name (unsigned enc) |
a3f97cbb | 4555 | { |
3f76745e | 4556 | switch (enc) |
a3f97cbb | 4557 | { |
3f76745e JM |
4558 | case DW_ATE_address: |
4559 | return "DW_ATE_address"; | |
4560 | case DW_ATE_boolean: | |
4561 | return "DW_ATE_boolean"; | |
4562 | case DW_ATE_complex_float: | |
4563 | return "DW_ATE_complex_float"; | |
4564 | case DW_ATE_float: | |
4565 | return "DW_ATE_float"; | |
4566 | case DW_ATE_signed: | |
4567 | return "DW_ATE_signed"; | |
4568 | case DW_ATE_signed_char: | |
4569 | return "DW_ATE_signed_char"; | |
4570 | case DW_ATE_unsigned: | |
4571 | return "DW_ATE_unsigned"; | |
4572 | case DW_ATE_unsigned_char: | |
4573 | return "DW_ATE_unsigned_char"; | |
4574 | default: | |
4575 | return "DW_ATE_<unknown>"; | |
4576 | } | |
a3f97cbb | 4577 | } |
487a6e06 | 4578 | #endif |
3f76745e JM |
4579 | \f |
4580 | /* Determine the "ultimate origin" of a decl. The decl may be an inlined | |
4581 | instance of an inlined instance of a decl which is local to an inline | |
4582 | function, so we have to trace all of the way back through the origin chain | |
4583 | to find out what sort of node actually served as the original seed for the | |
4584 | given block. */ | |
a3f97cbb | 4585 | |
3f76745e | 4586 | static tree |
7080f735 | 4587 | decl_ultimate_origin (tree decl) |
a3f97cbb | 4588 | { |
10a11b75 JM |
4589 | /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the |
4590 | nodes in the function to point to themselves; ignore that if | |
4591 | we're trying to output the abstract instance of this function. */ | |
4592 | if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl) | |
4593 | return NULL_TREE; | |
4594 | ||
556273e0 | 4595 | #ifdef ENABLE_CHECKING |
02e24c7a MM |
4596 | if (DECL_FROM_INLINE (DECL_ORIGIN (decl))) |
4597 | /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the | |
4598 | most distant ancestor, this should never happen. */ | |
4599 | abort (); | |
4600 | #endif | |
3f76745e | 4601 | |
02e24c7a | 4602 | return DECL_ABSTRACT_ORIGIN (decl); |
a3f97cbb JW |
4603 | } |
4604 | ||
3f76745e JM |
4605 | /* Determine the "ultimate origin" of a block. The block may be an inlined |
4606 | instance of an inlined instance of a block which is local to an inline | |
4607 | function, so we have to trace all of the way back through the origin chain | |
4608 | to find out what sort of node actually served as the original seed for the | |
4609 | given block. */ | |
71dfc51f | 4610 | |
3f76745e | 4611 | static tree |
7080f735 | 4612 | block_ultimate_origin (tree block) |
a3f97cbb | 4613 | { |
b3694847 | 4614 | tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); |
71dfc51f | 4615 | |
10a11b75 JM |
4616 | /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the |
4617 | nodes in the function to point to themselves; ignore that if | |
4618 | we're trying to output the abstract instance of this function. */ | |
4619 | if (BLOCK_ABSTRACT (block) && immediate_origin == block) | |
4620 | return NULL_TREE; | |
4621 | ||
3f76745e JM |
4622 | if (immediate_origin == NULL_TREE) |
4623 | return NULL_TREE; | |
4624 | else | |
4625 | { | |
b3694847 SS |
4626 | tree ret_val; |
4627 | tree lookahead = immediate_origin; | |
71dfc51f | 4628 | |
3f76745e JM |
4629 | do |
4630 | { | |
4631 | ret_val = lookahead; | |
2ad9852d RK |
4632 | lookahead = (TREE_CODE (ret_val) == BLOCK |
4633 | ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL); | |
3f76745e JM |
4634 | } |
4635 | while (lookahead != NULL && lookahead != ret_val); | |
4636 | ||
4637 | return ret_val; | |
4638 | } | |
a3f97cbb JW |
4639 | } |
4640 | ||
3f76745e JM |
4641 | /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT |
4642 | of a virtual function may refer to a base class, so we check the 'this' | |
4643 | parameter. */ | |
71dfc51f | 4644 | |
3f76745e | 4645 | static tree |
7080f735 | 4646 | decl_class_context (tree decl) |
a3f97cbb | 4647 | { |
3f76745e | 4648 | tree context = NULL_TREE; |
71dfc51f | 4649 | |
3f76745e JM |
4650 | if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl)) |
4651 | context = DECL_CONTEXT (decl); | |
4652 | else | |
4653 | context = TYPE_MAIN_VARIANT | |
4654 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
71dfc51f | 4655 | |
2f939d94 | 4656 | if (context && !TYPE_P (context)) |
3f76745e JM |
4657 | context = NULL_TREE; |
4658 | ||
4659 | return context; | |
a3f97cbb JW |
4660 | } |
4661 | \f | |
a96c67ec | 4662 | /* Add an attribute/value pair to a DIE. We build the lists up in reverse |
881c6935 | 4663 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f RK |
4664 | |
4665 | static inline void | |
7080f735 | 4666 | add_dwarf_attr (dw_die_ref die, dw_attr_ref attr) |
a3f97cbb | 4667 | { |
3f76745e | 4668 | if (die != NULL && attr != NULL) |
a3f97cbb | 4669 | { |
a96c67ec JM |
4670 | attr->dw_attr_next = die->die_attr; |
4671 | die->die_attr = attr; | |
a3f97cbb JW |
4672 | } |
4673 | } | |
4674 | ||
17211ab5 | 4675 | static inline enum dw_val_class |
7080f735 | 4676 | AT_class (dw_attr_ref a) |
a96c67ec JM |
4677 | { |
4678 | return a->dw_attr_val.val_class; | |
4679 | } | |
4680 | ||
3f76745e | 4681 | /* Add a flag value attribute to a DIE. */ |
71dfc51f | 4682 | |
3f76745e | 4683 | static inline void |
7080f735 | 4684 | add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag) |
a3f97cbb | 4685 | { |
703ad42b | 4686 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
71dfc51f | 4687 | |
3f76745e JM |
4688 | attr->dw_attr_next = NULL; |
4689 | attr->dw_attr = attr_kind; | |
4690 | attr->dw_attr_val.val_class = dw_val_class_flag; | |
4691 | attr->dw_attr_val.v.val_flag = flag; | |
4692 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4693 | } |
4694 | ||
a96c67ec | 4695 | static inline unsigned |
7080f735 | 4696 | AT_flag (dw_attr_ref a) |
a96c67ec JM |
4697 | { |
4698 | if (a && AT_class (a) == dw_val_class_flag) | |
4699 | return a->dw_attr_val.v.val_flag; | |
4700 | ||
40e8cc95 | 4701 | abort (); |
a96c67ec JM |
4702 | } |
4703 | ||
3f76745e | 4704 | /* Add a signed integer attribute value to a DIE. */ |
71dfc51f | 4705 | |
3f76745e | 4706 | static inline void |
799f628a | 4707 | add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val) |
a3f97cbb | 4708 | { |
703ad42b | 4709 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
3f76745e JM |
4710 | |
4711 | attr->dw_attr_next = NULL; | |
4712 | attr->dw_attr = attr_kind; | |
4713 | attr->dw_attr_val.val_class = dw_val_class_const; | |
4714 | attr->dw_attr_val.v.val_int = int_val; | |
4715 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4716 | } |
4717 | ||
799f628a | 4718 | static inline HOST_WIDE_INT |
7080f735 | 4719 | AT_int (dw_attr_ref a) |
a96c67ec JM |
4720 | { |
4721 | if (a && AT_class (a) == dw_val_class_const) | |
4722 | return a->dw_attr_val.v.val_int; | |
4723 | ||
40e8cc95 | 4724 | abort (); |
a96c67ec JM |
4725 | } |
4726 | ||
3f76745e | 4727 | /* Add an unsigned integer attribute value to a DIE. */ |
71dfc51f | 4728 | |
3f76745e | 4729 | static inline void |
7080f735 | 4730 | add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind, |
799f628a | 4731 | unsigned HOST_WIDE_INT unsigned_val) |
a3f97cbb | 4732 | { |
703ad42b | 4733 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
3f76745e JM |
4734 | |
4735 | attr->dw_attr_next = NULL; | |
4736 | attr->dw_attr = attr_kind; | |
4737 | attr->dw_attr_val.val_class = dw_val_class_unsigned_const; | |
4738 | attr->dw_attr_val.v.val_unsigned = unsigned_val; | |
4739 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4740 | } |
71dfc51f | 4741 | |
799f628a | 4742 | static inline unsigned HOST_WIDE_INT |
7080f735 | 4743 | AT_unsigned (dw_attr_ref a) |
a96c67ec JM |
4744 | { |
4745 | if (a && AT_class (a) == dw_val_class_unsigned_const) | |
4746 | return a->dw_attr_val.v.val_unsigned; | |
4747 | ||
40e8cc95 | 4748 | abort (); |
a96c67ec JM |
4749 | } |
4750 | ||
3f76745e JM |
4751 | /* Add an unsigned double integer attribute value to a DIE. */ |
4752 | ||
4753 | static inline void | |
7080f735 AJ |
4754 | add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind, |
4755 | long unsigned int val_hi, long unsigned int val_low) | |
a3f97cbb | 4756 | { |
703ad42b | 4757 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
71dfc51f | 4758 | |
3f76745e JM |
4759 | attr->dw_attr_next = NULL; |
4760 | attr->dw_attr = attr_kind; | |
4761 | attr->dw_attr_val.val_class = dw_val_class_long_long; | |
4762 | attr->dw_attr_val.v.val_long_long.hi = val_hi; | |
4763 | attr->dw_attr_val.v.val_long_long.low = val_low; | |
4764 | add_dwarf_attr (die, attr); | |
4765 | } | |
71dfc51f | 4766 | |
3f76745e | 4767 | /* Add a floating point attribute value to a DIE and return it. */ |
71dfc51f | 4768 | |
3f76745e | 4769 | static inline void |
e7ee3914 AM |
4770 | add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind, |
4771 | unsigned int length, unsigned int elt_size, unsigned char *array) | |
3f76745e | 4772 | { |
703ad42b | 4773 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
3f76745e JM |
4774 | |
4775 | attr->dw_attr_next = NULL; | |
4776 | attr->dw_attr = attr_kind; | |
e7ee3914 AM |
4777 | attr->dw_attr_val.val_class = dw_val_class_vec; |
4778 | attr->dw_attr_val.v.val_vec.length = length; | |
4779 | attr->dw_attr_val.v.val_vec.elt_size = elt_size; | |
4780 | attr->dw_attr_val.v.val_vec.array = array; | |
3f76745e | 4781 | add_dwarf_attr (die, attr); |
a3f97cbb JW |
4782 | } |
4783 | ||
17211ab5 GK |
4784 | /* Hash and equality functions for debug_str_hash. */ |
4785 | ||
4786 | static hashval_t | |
7080f735 | 4787 | debug_str_do_hash (const void *x) |
17211ab5 GK |
4788 | { |
4789 | return htab_hash_string (((const struct indirect_string_node *)x)->str); | |
4790 | } | |
4791 | ||
4792 | static int | |
7080f735 | 4793 | debug_str_eq (const void *x1, const void *x2) |
17211ab5 GK |
4794 | { |
4795 | return strcmp ((((const struct indirect_string_node *)x1)->str), | |
4796 | (const char *)x2) == 0; | |
4797 | } | |
4798 | ||
3f76745e | 4799 | /* Add a string attribute value to a DIE. */ |
71dfc51f | 4800 | |
3f76745e | 4801 | static inline void |
7080f735 | 4802 | add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str) |
a3f97cbb | 4803 | { |
703ad42b | 4804 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
9eb4015a | 4805 | struct indirect_string_node *node; |
fad205ff | 4806 | void **slot; |
c26fbbca | 4807 | |
9eb4015a | 4808 | if (! debug_str_hash) |
7080f735 | 4809 | debug_str_hash = htab_create_ggc (10, debug_str_do_hash, |
17211ab5 GK |
4810 | debug_str_eq, NULL); |
4811 | ||
4812 | slot = htab_find_slot_with_hash (debug_str_hash, str, | |
4813 | htab_hash_string (str), INSERT); | |
4814 | if (*slot == NULL) | |
4815 | *slot = ggc_alloc_cleared (sizeof (struct indirect_string_node)); | |
4816 | node = (struct indirect_string_node *) *slot; | |
485bad26 | 4817 | node->str = ggc_strdup (str); |
9eb4015a | 4818 | node->refcount++; |
71dfc51f | 4819 | |
3f76745e JM |
4820 | attr->dw_attr_next = NULL; |
4821 | attr->dw_attr = attr_kind; | |
4822 | attr->dw_attr_val.val_class = dw_val_class_str; | |
9eb4015a | 4823 | attr->dw_attr_val.v.val_str = node; |
3f76745e JM |
4824 | add_dwarf_attr (die, attr); |
4825 | } | |
71dfc51f | 4826 | |
a96c67ec | 4827 | static inline const char * |
7080f735 | 4828 | AT_string (dw_attr_ref a) |
a96c67ec JM |
4829 | { |
4830 | if (a && AT_class (a) == dw_val_class_str) | |
17211ab5 | 4831 | return a->dw_attr_val.v.val_str->str; |
9eb4015a JJ |
4832 | |
4833 | abort (); | |
4834 | } | |
4835 | ||
4836 | /* Find out whether a string should be output inline in DIE | |
4837 | or out-of-line in .debug_str section. */ | |
4838 | ||
9eb4015a | 4839 | static int |
7080f735 | 4840 | AT_string_form (dw_attr_ref a) |
9eb4015a JJ |
4841 | { |
4842 | if (a && AT_class (a) == dw_val_class_str) | |
4843 | { | |
4844 | struct indirect_string_node *node; | |
4845 | unsigned int len; | |
9eb4015a JJ |
4846 | char label[32]; |
4847 | ||
4848 | node = a->dw_attr_val.v.val_str; | |
4849 | if (node->form) | |
4850 | return node->form; | |
4851 | ||
17211ab5 | 4852 | len = strlen (node->str) + 1; |
9eb4015a | 4853 | |
2ad9852d RK |
4854 | /* If the string is shorter or equal to the size of the reference, it is |
4855 | always better to put it inline. */ | |
9eb4015a JJ |
4856 | if (len <= DWARF_OFFSET_SIZE || node->refcount == 0) |
4857 | return node->form = DW_FORM_string; | |
4858 | ||
2ad9852d RK |
4859 | /* If we cannot expect the linker to merge strings in .debug_str |
4860 | section, only put it into .debug_str if it is worth even in this | |
4861 | single module. */ | |
4862 | if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0 | |
4863 | && (len - DWARF_OFFSET_SIZE) * node->refcount <= len) | |
4864 | return node->form = DW_FORM_string; | |
9eb4015a | 4865 | |
17211ab5 GK |
4866 | ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter); |
4867 | ++dw2_string_counter; | |
9eb4015a | 4868 | node->label = xstrdup (label); |
2ad9852d | 4869 | |
9eb4015a JJ |
4870 | return node->form = DW_FORM_strp; |
4871 | } | |
a96c67ec | 4872 | |
40e8cc95 | 4873 | abort (); |
a96c67ec JM |
4874 | } |
4875 | ||
3f76745e | 4876 | /* Add a DIE reference attribute value to a DIE. */ |
71dfc51f | 4877 | |
3f76745e | 4878 | static inline void |
7080f735 | 4879 | add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die) |
3f76745e | 4880 | { |
703ad42b | 4881 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
71dfc51f | 4882 | |
3f76745e JM |
4883 | attr->dw_attr_next = NULL; |
4884 | attr->dw_attr = attr_kind; | |
4885 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
881c6935 JM |
4886 | attr->dw_attr_val.v.val_die_ref.die = targ_die; |
4887 | attr->dw_attr_val.v.val_die_ref.external = 0; | |
3f76745e JM |
4888 | add_dwarf_attr (die, attr); |
4889 | } | |
b1ccbc24 | 4890 | |
47fcfa7b | 4891 | /* Add an AT_specification attribute to a DIE, and also make the back |
6614fd40 | 4892 | pointer from the specification to the definition. */ |
47fcfa7b SS |
4893 | |
4894 | static inline void | |
4895 | add_AT_specification (dw_die_ref die, dw_die_ref targ_die) | |
4896 | { | |
4897 | add_AT_die_ref (die, DW_AT_specification, targ_die); | |
4898 | if (targ_die->die_definition) | |
4899 | abort (); | |
4900 | targ_die->die_definition = die; | |
4901 | } | |
4902 | ||
a96c67ec | 4903 | static inline dw_die_ref |
7080f735 | 4904 | AT_ref (dw_attr_ref a) |
a96c67ec JM |
4905 | { |
4906 | if (a && AT_class (a) == dw_val_class_die_ref) | |
881c6935 | 4907 | return a->dw_attr_val.v.val_die_ref.die; |
a96c67ec | 4908 | |
40e8cc95 | 4909 | abort (); |
a96c67ec JM |
4910 | } |
4911 | ||
881c6935 | 4912 | static inline int |
7080f735 | 4913 | AT_ref_external (dw_attr_ref a) |
881c6935 JM |
4914 | { |
4915 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4916 | return a->dw_attr_val.v.val_die_ref.external; | |
4917 | ||
4918 | return 0; | |
4919 | } | |
4920 | ||
881c6935 | 4921 | static inline void |
7080f735 | 4922 | set_AT_ref_external (dw_attr_ref a, int i) |
881c6935 JM |
4923 | { |
4924 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4925 | a->dw_attr_val.v.val_die_ref.external = i; | |
4926 | else | |
4927 | abort (); | |
4928 | } | |
4929 | ||
3f76745e | 4930 | /* Add an FDE reference attribute value to a DIE. */ |
b1ccbc24 | 4931 | |
3f76745e | 4932 | static inline void |
7080f735 | 4933 | add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde) |
3f76745e | 4934 | { |
703ad42b | 4935 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
b1ccbc24 | 4936 | |
3f76745e JM |
4937 | attr->dw_attr_next = NULL; |
4938 | attr->dw_attr = attr_kind; | |
4939 | attr->dw_attr_val.val_class = dw_val_class_fde_ref; | |
4940 | attr->dw_attr_val.v.val_fde_index = targ_fde; | |
4941 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4942 | } |
71dfc51f | 4943 | |
3f76745e | 4944 | /* Add a location description attribute value to a DIE. */ |
71dfc51f | 4945 | |
3f76745e | 4946 | static inline void |
7080f735 | 4947 | add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc) |
3f76745e | 4948 | { |
703ad42b | 4949 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
71dfc51f | 4950 | |
3f76745e JM |
4951 | attr->dw_attr_next = NULL; |
4952 | attr->dw_attr = attr_kind; | |
4953 | attr->dw_attr_val.val_class = dw_val_class_loc; | |
4954 | attr->dw_attr_val.v.val_loc = loc; | |
4955 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4956 | } |
4957 | ||
a96c67ec | 4958 | static inline dw_loc_descr_ref |
7080f735 | 4959 | AT_loc (dw_attr_ref a) |
a96c67ec JM |
4960 | { |
4961 | if (a && AT_class (a) == dw_val_class_loc) | |
4962 | return a->dw_attr_val.v.val_loc; | |
4963 | ||
40e8cc95 | 4964 | abort (); |
a96c67ec JM |
4965 | } |
4966 | ||
63e46568 | 4967 | static inline void |
7080f735 | 4968 | add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list) |
63e46568 | 4969 | { |
703ad42b | 4970 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
63e46568 DB |
4971 | |
4972 | attr->dw_attr_next = NULL; | |
4973 | attr->dw_attr = attr_kind; | |
4974 | attr->dw_attr_val.val_class = dw_val_class_loc_list; | |
4975 | attr->dw_attr_val.v.val_loc_list = loc_list; | |
4976 | add_dwarf_attr (die, attr); | |
4977 | have_location_lists = 1; | |
4978 | } | |
4979 | ||
63e46568 | 4980 | static inline dw_loc_list_ref |
7080f735 | 4981 | AT_loc_list (dw_attr_ref a) |
63e46568 DB |
4982 | { |
4983 | if (a && AT_class (a) == dw_val_class_loc_list) | |
4984 | return a->dw_attr_val.v.val_loc_list; | |
4985 | ||
4986 | abort (); | |
4987 | } | |
4988 | ||
3f76745e | 4989 | /* Add an address constant attribute value to a DIE. */ |
71dfc51f | 4990 | |
3f76745e | 4991 | static inline void |
7080f735 | 4992 | add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr) |
a3f97cbb | 4993 | { |
703ad42b | 4994 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
71dfc51f | 4995 | |
3f76745e JM |
4996 | attr->dw_attr_next = NULL; |
4997 | attr->dw_attr = attr_kind; | |
4998 | attr->dw_attr_val.val_class = dw_val_class_addr; | |
4999 | attr->dw_attr_val.v.val_addr = addr; | |
5000 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
5001 | } |
5002 | ||
1865dbb5 | 5003 | static inline rtx |
7080f735 | 5004 | AT_addr (dw_attr_ref a) |
a96c67ec JM |
5005 | { |
5006 | if (a && AT_class (a) == dw_val_class_addr) | |
5007 | return a->dw_attr_val.v.val_addr; | |
5008 | ||
40e8cc95 | 5009 | abort (); |
a96c67ec JM |
5010 | } |
5011 | ||
3f76745e | 5012 | /* Add a label identifier attribute value to a DIE. */ |
71dfc51f | 5013 | |
3f76745e | 5014 | static inline void |
7080f735 | 5015 | add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id) |
a3f97cbb | 5016 | { |
703ad42b | 5017 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
71dfc51f | 5018 | |
3f76745e JM |
5019 | attr->dw_attr_next = NULL; |
5020 | attr->dw_attr = attr_kind; | |
5021 | attr->dw_attr_val.val_class = dw_val_class_lbl_id; | |
5022 | attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); | |
5023 | add_dwarf_attr (die, attr); | |
5024 | } | |
71dfc51f | 5025 | |
3f76745e JM |
5026 | /* Add a section offset attribute value to a DIE. */ |
5027 | ||
5028 | static inline void | |
7080f735 | 5029 | add_AT_lbl_offset (dw_die_ref die, enum dwarf_attribute attr_kind, const char *label) |
3f76745e | 5030 | { |
703ad42b | 5031 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
71dfc51f | 5032 | |
3f76745e JM |
5033 | attr->dw_attr_next = NULL; |
5034 | attr->dw_attr = attr_kind; | |
8b790721 | 5035 | attr->dw_attr_val.val_class = dw_val_class_lbl_offset; |
a96c67ec | 5036 | attr->dw_attr_val.v.val_lbl_id = xstrdup (label); |
3f76745e | 5037 | add_dwarf_attr (die, attr); |
a3f97cbb JW |
5038 | } |
5039 | ||
a20612aa RH |
5040 | /* Add an offset attribute value to a DIE. */ |
5041 | ||
2bee6045 | 5042 | static inline void |
799f628a JH |
5043 | add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind, |
5044 | unsigned HOST_WIDE_INT offset) | |
a20612aa | 5045 | { |
703ad42b | 5046 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
a20612aa RH |
5047 | |
5048 | attr->dw_attr_next = NULL; | |
5049 | attr->dw_attr = attr_kind; | |
5050 | attr->dw_attr_val.val_class = dw_val_class_offset; | |
5051 | attr->dw_attr_val.v.val_offset = offset; | |
5052 | add_dwarf_attr (die, attr); | |
5053 | } | |
5054 | ||
2bee6045 JJ |
5055 | /* Add an range_list attribute value to a DIE. */ |
5056 | ||
5057 | static void | |
7080f735 AJ |
5058 | add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind, |
5059 | long unsigned int offset) | |
2bee6045 | 5060 | { |
703ad42b | 5061 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
2bee6045 JJ |
5062 | |
5063 | attr->dw_attr_next = NULL; | |
5064 | attr->dw_attr = attr_kind; | |
5065 | attr->dw_attr_val.val_class = dw_val_class_range_list; | |
5066 | attr->dw_attr_val.v.val_offset = offset; | |
5067 | add_dwarf_attr (die, attr); | |
5068 | } | |
5069 | ||
a96c67ec | 5070 | static inline const char * |
7080f735 | 5071 | AT_lbl (dw_attr_ref a) |
a3f97cbb | 5072 | { |
a96c67ec JM |
5073 | if (a && (AT_class (a) == dw_val_class_lbl_id |
5074 | || AT_class (a) == dw_val_class_lbl_offset)) | |
5075 | return a->dw_attr_val.v.val_lbl_id; | |
71dfc51f | 5076 | |
40e8cc95 | 5077 | abort (); |
a3f97cbb JW |
5078 | } |
5079 | ||
3f76745e | 5080 | /* Get the attribute of type attr_kind. */ |
71dfc51f | 5081 | |
965514bd | 5082 | static dw_attr_ref |
7080f735 | 5083 | get_AT (dw_die_ref die, enum dwarf_attribute attr_kind) |
f37230f0 | 5084 | { |
b3694847 SS |
5085 | dw_attr_ref a; |
5086 | dw_die_ref spec = NULL; | |
556273e0 | 5087 | |
3f76745e JM |
5088 | if (die != NULL) |
5089 | { | |
5090 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
2ad9852d RK |
5091 | if (a->dw_attr == attr_kind) |
5092 | return a; | |
5093 | else if (a->dw_attr == DW_AT_specification | |
5094 | || a->dw_attr == DW_AT_abstract_origin) | |
5095 | spec = AT_ref (a); | |
71dfc51f | 5096 | |
3f76745e JM |
5097 | if (spec) |
5098 | return get_AT (spec, attr_kind); | |
5099 | } | |
5100 | ||
5101 | return NULL; | |
f37230f0 JM |
5102 | } |
5103 | ||
2ad9852d RK |
5104 | /* Return the "low pc" attribute value, typically associated with a subprogram |
5105 | DIE. Return null if the "low pc" attribute is either not present, or if it | |
5106 | cannot be represented as an assembler label identifier. */ | |
71dfc51f | 5107 | |
a96c67ec | 5108 | static inline const char * |
7080f735 | 5109 | get_AT_low_pc (dw_die_ref die) |
7e23cb16 | 5110 | { |
b3694847 | 5111 | dw_attr_ref a = get_AT (die, DW_AT_low_pc); |
2ad9852d | 5112 | |
40e8cc95 | 5113 | return a ? AT_lbl (a) : NULL; |
7e23cb16 JM |
5114 | } |
5115 | ||
2ad9852d RK |
5116 | /* Return the "high pc" attribute value, typically associated with a subprogram |
5117 | DIE. Return null if the "high pc" attribute is either not present, or if it | |
5118 | cannot be represented as an assembler label identifier. */ | |
71dfc51f | 5119 | |
a96c67ec | 5120 | static inline const char * |
7080f735 | 5121 | get_AT_hi_pc (dw_die_ref die) |
a3f97cbb | 5122 | { |
b3694847 | 5123 | dw_attr_ref a = get_AT (die, DW_AT_high_pc); |
2ad9852d | 5124 | |
40e8cc95 | 5125 | return a ? AT_lbl (a) : NULL; |
3f76745e JM |
5126 | } |
5127 | ||
5128 | /* Return the value of the string attribute designated by ATTR_KIND, or | |
5129 | NULL if it is not present. */ | |
71dfc51f | 5130 | |
a96c67ec | 5131 | static inline const char * |
7080f735 | 5132 | get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind) |
3f76745e | 5133 | { |
b3694847 | 5134 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 5135 | |
40e8cc95 | 5136 | return a ? AT_string (a) : NULL; |
a3f97cbb JW |
5137 | } |
5138 | ||
3f76745e JM |
5139 | /* Return the value of the flag attribute designated by ATTR_KIND, or -1 |
5140 | if it is not present. */ | |
71dfc51f | 5141 | |
3f76745e | 5142 | static inline int |
7080f735 | 5143 | get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind) |
a3f97cbb | 5144 | { |
b3694847 | 5145 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 5146 | |
40e8cc95 | 5147 | return a ? AT_flag (a) : 0; |
a3f97cbb JW |
5148 | } |
5149 | ||
3f76745e JM |
5150 | /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0 |
5151 | if it is not present. */ | |
71dfc51f | 5152 | |
3f76745e | 5153 | static inline unsigned |
7080f735 | 5154 | get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind) |
a3f97cbb | 5155 | { |
b3694847 | 5156 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 5157 | |
40e8cc95 | 5158 | return a ? AT_unsigned (a) : 0; |
a96c67ec | 5159 | } |
71dfc51f | 5160 | |
a96c67ec | 5161 | static inline dw_die_ref |
7080f735 | 5162 | get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind) |
a96c67ec | 5163 | { |
b3694847 | 5164 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 5165 | |
40e8cc95 | 5166 | return a ? AT_ref (a) : NULL; |
3f76745e | 5167 | } |
71dfc51f | 5168 | |
c3cdeef4 JB |
5169 | /* Return TRUE if the language is C or C++. */ |
5170 | ||
5171 | static inline bool | |
7080f735 | 5172 | is_c_family (void) |
3f76745e | 5173 | { |
c3cdeef4 | 5174 | unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
71dfc51f | 5175 | |
3f76745e JM |
5176 | return (lang == DW_LANG_C || lang == DW_LANG_C89 |
5177 | || lang == DW_LANG_C_plus_plus); | |
556273e0 | 5178 | } |
71dfc51f | 5179 | |
c3cdeef4 JB |
5180 | /* Return TRUE if the language is C++. */ |
5181 | ||
5182 | static inline bool | |
7080f735 | 5183 | is_cxx (void) |
1d3d6b1e JM |
5184 | { |
5185 | return (get_AT_unsigned (comp_unit_die, DW_AT_language) | |
5186 | == DW_LANG_C_plus_plus); | |
c26fbbca | 5187 | } |
1d3d6b1e | 5188 | |
c3cdeef4 JB |
5189 | /* Return TRUE if the language is Fortran. */ |
5190 | ||
5191 | static inline bool | |
7080f735 | 5192 | is_fortran (void) |
3f76745e | 5193 | { |
c3cdeef4 | 5194 | unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
71dfc51f | 5195 | |
6de9cd9a DN |
5196 | return (lang == DW_LANG_Fortran77 |
5197 | || lang == DW_LANG_Fortran90 | |
5198 | || lang == DW_LANG_Fortran95); | |
556273e0 | 5199 | } |
71dfc51f | 5200 | |
c3cdeef4 JB |
5201 | /* Return TRUE if the language is Java. */ |
5202 | ||
5203 | static inline bool | |
7080f735 | 5204 | is_java (void) |
28985b81 | 5205 | { |
c3cdeef4 | 5206 | unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
28985b81 | 5207 | |
c3cdeef4 JB |
5208 | return lang == DW_LANG_Java; |
5209 | } | |
5210 | ||
5211 | /* Return TRUE if the language is Ada. */ | |
5212 | ||
5213 | static inline bool | |
7080f735 | 5214 | is_ada (void) |
c3cdeef4 JB |
5215 | { |
5216 | unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
7080f735 | 5217 | |
c3cdeef4 | 5218 | return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83; |
28985b81 AG |
5219 | } |
5220 | ||
10a11b75 | 5221 | /* Free up the memory used by A. */ |
71dfc51f | 5222 | |
7080f735 | 5223 | static inline void free_AT (dw_attr_ref); |
3f76745e | 5224 | static inline void |
7080f735 | 5225 | free_AT (dw_attr_ref a) |
10a11b75 | 5226 | { |
17211ab5 GK |
5227 | if (AT_class (a) == dw_val_class_str) |
5228 | if (a->dw_attr_val.v.val_str->refcount) | |
5229 | a->dw_attr_val.v.val_str->refcount--; | |
556273e0 | 5230 | } |
10a11b75 JM |
5231 | |
5232 | /* Remove the specified attribute if present. */ | |
5233 | ||
5234 | static void | |
7080f735 | 5235 | remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind) |
3f76745e | 5236 | { |
b3694847 SS |
5237 | dw_attr_ref *p; |
5238 | dw_attr_ref removed = NULL; | |
a3f97cbb | 5239 | |
3f76745e JM |
5240 | if (die != NULL) |
5241 | { | |
a96c67ec JM |
5242 | for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next)) |
5243 | if ((*p)->dw_attr == attr_kind) | |
5244 | { | |
5245 | removed = *p; | |
5246 | *p = (*p)->dw_attr_next; | |
5247 | break; | |
5248 | } | |
71dfc51f | 5249 | |
a96c67ec | 5250 | if (removed != 0) |
10a11b75 JM |
5251 | free_AT (removed); |
5252 | } | |
5253 | } | |
71dfc51f | 5254 | |
6097b0c3 DP |
5255 | /* Remove child die whose die_tag is specified tag. */ |
5256 | ||
5257 | static void | |
5258 | remove_child_TAG (dw_die_ref die, enum dwarf_tag tag) | |
5259 | { | |
5260 | dw_die_ref current, prev, next; | |
5261 | current = die->die_child; | |
5262 | prev = NULL; | |
5263 | while (current != NULL) | |
5264 | { | |
5265 | if (current->die_tag == tag) | |
5266 | { | |
5267 | next = current->die_sib; | |
5268 | if (prev == NULL) | |
5269 | die->die_child = next; | |
5270 | else | |
5271 | prev->die_sib = next; | |
5272 | free_die (current); | |
5273 | current = next; | |
5274 | } | |
5275 | else | |
5276 | { | |
5277 | prev = current; | |
5278 | current = current->die_sib; | |
5279 | } | |
5280 | } | |
5281 | } | |
5282 | ||
10a11b75 | 5283 | /* Free up the memory used by DIE. */ |
71dfc51f | 5284 | |
10a11b75 | 5285 | static inline void |
7080f735 | 5286 | free_die (dw_die_ref die) |
10a11b75 JM |
5287 | { |
5288 | remove_children (die); | |
3f76745e | 5289 | } |
71dfc51f | 5290 | |
3f76745e | 5291 | /* Discard the children of this DIE. */ |
71dfc51f | 5292 | |
10a11b75 | 5293 | static void |
7080f735 | 5294 | remove_children (dw_die_ref die) |
3f76745e | 5295 | { |
b3694847 | 5296 | dw_die_ref child_die = die->die_child; |
3f76745e JM |
5297 | |
5298 | die->die_child = NULL; | |
3f76745e JM |
5299 | |
5300 | while (child_die != NULL) | |
a3f97cbb | 5301 | { |
b3694847 SS |
5302 | dw_die_ref tmp_die = child_die; |
5303 | dw_attr_ref a; | |
71dfc51f | 5304 | |
3f76745e | 5305 | child_die = child_die->die_sib; |
556273e0 KH |
5306 | |
5307 | for (a = tmp_die->die_attr; a != NULL;) | |
a3f97cbb | 5308 | { |
b3694847 | 5309 | dw_attr_ref tmp_a = a; |
71dfc51f | 5310 | |
3f76745e | 5311 | a = a->dw_attr_next; |
10a11b75 | 5312 | free_AT (tmp_a); |
a3f97cbb | 5313 | } |
71dfc51f | 5314 | |
10a11b75 | 5315 | free_die (tmp_die); |
3f76745e JM |
5316 | } |
5317 | } | |
71dfc51f | 5318 | |
a96c67ec | 5319 | /* Add a child DIE below its parent. We build the lists up in reverse |
881c6935 | 5320 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f | 5321 | |
3f76745e | 5322 | static inline void |
7080f735 | 5323 | add_child_die (dw_die_ref die, dw_die_ref child_die) |
3f76745e JM |
5324 | { |
5325 | if (die != NULL && child_die != NULL) | |
e90b62db | 5326 | { |
3a88cbd1 JL |
5327 | if (die == child_die) |
5328 | abort (); | |
2ad9852d | 5329 | |
3f76745e | 5330 | child_die->die_parent = die; |
a96c67ec JM |
5331 | child_die->die_sib = die->die_child; |
5332 | die->die_child = child_die; | |
3f76745e JM |
5333 | } |
5334 | } | |
5335 | ||
2081603c JM |
5336 | /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT |
5337 | is the specification, to the front of PARENT's list of children. */ | |
10a11b75 JM |
5338 | |
5339 | static void | |
7080f735 | 5340 | splice_child_die (dw_die_ref parent, dw_die_ref child) |
10a11b75 JM |
5341 | { |
5342 | dw_die_ref *p; | |
5343 | ||
5344 | /* We want the declaration DIE from inside the class, not the | |
5345 | specification DIE at toplevel. */ | |
5346 | if (child->die_parent != parent) | |
2081603c JM |
5347 | { |
5348 | dw_die_ref tmp = get_AT_ref (child, DW_AT_specification); | |
2ad9852d | 5349 | |
2081603c JM |
5350 | if (tmp) |
5351 | child = tmp; | |
5352 | } | |
10a11b75 | 5353 | |
2081603c JM |
5354 | if (child->die_parent != parent |
5355 | && child->die_parent != get_AT_ref (parent, DW_AT_specification)) | |
10a11b75 JM |
5356 | abort (); |
5357 | ||
5de0e8d4 | 5358 | for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib)) |
10a11b75 JM |
5359 | if (*p == child) |
5360 | { | |
5361 | *p = child->die_sib; | |
5362 | break; | |
5363 | } | |
5364 | ||
73c68f61 | 5365 | child->die_parent = parent; |
10a11b75 JM |
5366 | child->die_sib = parent->die_child; |
5367 | parent->die_child = child; | |
5368 | } | |
5369 | ||
3f76745e JM |
5370 | /* Return a pointer to a newly created DIE node. */ |
5371 | ||
5372 | static inline dw_die_ref | |
7080f735 | 5373 | new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t) |
3f76745e | 5374 | { |
703ad42b | 5375 | dw_die_ref die = ggc_alloc_cleared (sizeof (die_node)); |
3f76745e JM |
5376 | |
5377 | die->die_tag = tag_value; | |
3f76745e JM |
5378 | |
5379 | if (parent_die != NULL) | |
5380 | add_child_die (parent_die, die); | |
5381 | else | |
ef76d03b JW |
5382 | { |
5383 | limbo_die_node *limbo_node; | |
5384 | ||
17211ab5 | 5385 | limbo_node = ggc_alloc_cleared (sizeof (limbo_die_node)); |
ef76d03b | 5386 | limbo_node->die = die; |
54ba1f0d | 5387 | limbo_node->created_for = t; |
ef76d03b JW |
5388 | limbo_node->next = limbo_die_list; |
5389 | limbo_die_list = limbo_node; | |
5390 | } | |
71dfc51f | 5391 | |
3f76745e JM |
5392 | return die; |
5393 | } | |
71dfc51f | 5394 | |
3f76745e | 5395 | /* Return the DIE associated with the given type specifier. */ |
71dfc51f | 5396 | |
3f76745e | 5397 | static inline dw_die_ref |
7080f735 | 5398 | lookup_type_die (tree type) |
3f76745e | 5399 | { |
e2500fed | 5400 | return TYPE_SYMTAB_DIE (type); |
3f76745e | 5401 | } |
e90b62db | 5402 | |
3f76745e | 5403 | /* Equate a DIE to a given type specifier. */ |
71dfc51f | 5404 | |
10a11b75 | 5405 | static inline void |
7080f735 | 5406 | equate_type_number_to_die (tree type, dw_die_ref type_die) |
3f76745e | 5407 | { |
e2500fed | 5408 | TYPE_SYMTAB_DIE (type) = type_die; |
3f76745e | 5409 | } |
71dfc51f | 5410 | |
636c7bc4 JZ |
5411 | /* Returns a hash value for X (which really is a die_struct). */ |
5412 | ||
5413 | static hashval_t | |
5414 | decl_die_table_hash (const void *x) | |
5415 | { | |
5416 | return (hashval_t) ((const dw_die_ref) x)->decl_id; | |
5417 | } | |
5418 | ||
5419 | /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */ | |
5420 | ||
5421 | static int | |
5422 | decl_die_table_eq (const void *x, const void *y) | |
5423 | { | |
5424 | return (((const dw_die_ref) x)->decl_id == DECL_UID ((const tree) y)); | |
5425 | } | |
5426 | ||
3f76745e | 5427 | /* Return the DIE associated with a given declaration. */ |
71dfc51f | 5428 | |
3f76745e | 5429 | static inline dw_die_ref |
7080f735 | 5430 | lookup_decl_die (tree decl) |
3f76745e | 5431 | { |
636c7bc4 | 5432 | return htab_find_with_hash (decl_die_table, decl, DECL_UID (decl)); |
a3f97cbb JW |
5433 | } |
5434 | ||
0a2d3d69 DB |
5435 | /* Returns a hash value for X (which really is a var_loc_list). */ |
5436 | ||
5437 | static hashval_t | |
5438 | decl_loc_table_hash (const void *x) | |
5439 | { | |
5440 | return (hashval_t) ((const var_loc_list *) x)->decl_id; | |
5441 | } | |
5442 | ||
5443 | /* Return nonzero if decl_id of var_loc_list X is the same as | |
5444 | UID of decl *Y. */ | |
5445 | ||
5446 | static int | |
5447 | decl_loc_table_eq (const void *x, const void *y) | |
5448 | { | |
5449 | return (((const var_loc_list *) x)->decl_id == DECL_UID ((const tree) y)); | |
5450 | } | |
5451 | ||
5452 | /* Return the var_loc list associated with a given declaration. */ | |
5453 | ||
5454 | static inline var_loc_list * | |
5455 | lookup_decl_loc (tree decl) | |
5456 | { | |
5457 | return htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl)); | |
5458 | } | |
5459 | ||
3f76745e | 5460 | /* Equate a DIE to a particular declaration. */ |
71dfc51f | 5461 | |
3f76745e | 5462 | static void |
7080f735 | 5463 | equate_decl_number_to_die (tree decl, dw_die_ref decl_die) |
a3f97cbb | 5464 | { |
aea9695c | 5465 | unsigned int decl_id = DECL_UID (decl); |
636c7bc4 | 5466 | void **slot; |
3f76745e | 5467 | |
636c7bc4 JZ |
5468 | slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT); |
5469 | *slot = decl_die; | |
5470 | decl_die->decl_id = decl_id; | |
a3f97cbb | 5471 | } |
0a2d3d69 DB |
5472 | |
5473 | /* Add a variable location node to the linked list for DECL. */ | |
5474 | ||
5475 | static void | |
5476 | add_var_loc_to_decl (tree decl, struct var_loc_node *loc) | |
5477 | { | |
5478 | unsigned int decl_id = DECL_UID (decl); | |
5479 | var_loc_list *temp; | |
5480 | void **slot; | |
5481 | ||
5482 | slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT); | |
5483 | if (*slot == NULL) | |
5484 | { | |
5485 | temp = ggc_alloc_cleared (sizeof (var_loc_list)); | |
5486 | temp->decl_id = decl_id; | |
5487 | *slot = temp; | |
5488 | } | |
5489 | else | |
5490 | temp = *slot; | |
5491 | ||
5492 | if (temp->last) | |
5493 | { | |
5494 | /* If the current location is the same as the end of the list, | |
5495 | we have nothing to do. */ | |
5496 | if (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note), | |
5497 | NOTE_VAR_LOCATION_LOC (loc->var_loc_note))) | |
5498 | { | |
5499 | /* Add LOC to the end of list and update LAST. */ | |
5500 | temp->last->next = loc; | |
5501 | temp->last = loc; | |
5502 | } | |
5503 | } | |
5504 | /* Do not add empty location to the beginning of the list. */ | |
5505 | else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX) | |
5506 | { | |
5507 | temp->first = loc; | |
5508 | temp->last = loc; | |
5509 | } | |
5510 | } | |
3f76745e JM |
5511 | \f |
5512 | /* Keep track of the number of spaces used to indent the | |
5513 | output of the debugging routines that print the structure of | |
5514 | the DIE internal representation. */ | |
5515 | static int print_indent; | |
71dfc51f | 5516 | |
3f76745e JM |
5517 | /* Indent the line the number of spaces given by print_indent. */ |
5518 | ||
5519 | static inline void | |
7080f735 | 5520 | print_spaces (FILE *outfile) |
3f76745e JM |
5521 | { |
5522 | fprintf (outfile, "%*s", print_indent, ""); | |
a3f97cbb JW |
5523 | } |
5524 | ||
956d6950 | 5525 | /* Print the information associated with a given DIE, and its children. |
3f76745e | 5526 | This routine is a debugging aid only. */ |
71dfc51f | 5527 | |
a3f97cbb | 5528 | static void |
7080f735 | 5529 | print_die (dw_die_ref die, FILE *outfile) |
a3f97cbb | 5530 | { |
b3694847 SS |
5531 | dw_attr_ref a; |
5532 | dw_die_ref c; | |
71dfc51f | 5533 | |
3f76745e | 5534 | print_spaces (outfile); |
2d8b0f3a | 5535 | fprintf (outfile, "DIE %4lu: %s\n", |
3f76745e JM |
5536 | die->die_offset, dwarf_tag_name (die->die_tag)); |
5537 | print_spaces (outfile); | |
2d8b0f3a JL |
5538 | fprintf (outfile, " abbrev id: %lu", die->die_abbrev); |
5539 | fprintf (outfile, " offset: %lu\n", die->die_offset); | |
3f76745e JM |
5540 | |
5541 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
a3f97cbb | 5542 | { |
3f76745e JM |
5543 | print_spaces (outfile); |
5544 | fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr)); | |
5545 | ||
a96c67ec | 5546 | switch (AT_class (a)) |
3f76745e JM |
5547 | { |
5548 | case dw_val_class_addr: | |
5549 | fprintf (outfile, "address"); | |
5550 | break; | |
a20612aa RH |
5551 | case dw_val_class_offset: |
5552 | fprintf (outfile, "offset"); | |
5553 | break; | |
3f76745e JM |
5554 | case dw_val_class_loc: |
5555 | fprintf (outfile, "location descriptor"); | |
5556 | break; | |
63e46568 | 5557 | case dw_val_class_loc_list: |
a20612aa RH |
5558 | fprintf (outfile, "location list -> label:%s", |
5559 | AT_loc_list (a)->ll_symbol); | |
63e46568 | 5560 | break; |
2bee6045 JJ |
5561 | case dw_val_class_range_list: |
5562 | fprintf (outfile, "range list"); | |
5563 | break; | |
3f76745e | 5564 | case dw_val_class_const: |
38f9cd4c | 5565 | fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a)); |
3f76745e JM |
5566 | break; |
5567 | case dw_val_class_unsigned_const: | |
38f9cd4c | 5568 | fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a)); |
3f76745e JM |
5569 | break; |
5570 | case dw_val_class_long_long: | |
2d8b0f3a | 5571 | fprintf (outfile, "constant (%lu,%lu)", |
556273e0 KH |
5572 | a->dw_attr_val.v.val_long_long.hi, |
5573 | a->dw_attr_val.v.val_long_long.low); | |
3f76745e | 5574 | break; |
e7ee3914 AM |
5575 | case dw_val_class_vec: |
5576 | fprintf (outfile, "floating-point or vector constant"); | |
3f76745e JM |
5577 | break; |
5578 | case dw_val_class_flag: | |
a96c67ec | 5579 | fprintf (outfile, "%u", AT_flag (a)); |
3f76745e JM |
5580 | break; |
5581 | case dw_val_class_die_ref: | |
a96c67ec | 5582 | if (AT_ref (a) != NULL) |
881c6935 | 5583 | { |
1bfb5f8f | 5584 | if (AT_ref (a)->die_symbol) |
881c6935 JM |
5585 | fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol); |
5586 | else | |
5587 | fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset); | |
5588 | } | |
3f76745e JM |
5589 | else |
5590 | fprintf (outfile, "die -> <null>"); | |
5591 | break; | |
5592 | case dw_val_class_lbl_id: | |
8b790721 | 5593 | case dw_val_class_lbl_offset: |
a96c67ec | 5594 | fprintf (outfile, "label: %s", AT_lbl (a)); |
3f76745e | 5595 | break; |
3f76745e | 5596 | case dw_val_class_str: |
a96c67ec JM |
5597 | if (AT_string (a) != NULL) |
5598 | fprintf (outfile, "\"%s\"", AT_string (a)); | |
3f76745e JM |
5599 | else |
5600 | fprintf (outfile, "<null>"); | |
5601 | break; | |
e9a25f70 JL |
5602 | default: |
5603 | break; | |
3f76745e JM |
5604 | } |
5605 | ||
5606 | fprintf (outfile, "\n"); | |
5607 | } | |
5608 | ||
5609 | if (die->die_child != NULL) | |
5610 | { | |
5611 | print_indent += 4; | |
5612 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5613 | print_die (c, outfile); | |
71dfc51f | 5614 | |
3f76745e | 5615 | print_indent -= 4; |
a3f97cbb | 5616 | } |
881c6935 JM |
5617 | if (print_indent == 0) |
5618 | fprintf (outfile, "\n"); | |
a3f97cbb JW |
5619 | } |
5620 | ||
3f76745e JM |
5621 | /* Print the contents of the source code line number correspondence table. |
5622 | This routine is a debugging aid only. */ | |
71dfc51f | 5623 | |
3f76745e | 5624 | static void |
7080f735 | 5625 | print_dwarf_line_table (FILE *outfile) |
a3f97cbb | 5626 | { |
b3694847 SS |
5627 | unsigned i; |
5628 | dw_line_info_ref line_info; | |
3f76745e JM |
5629 | |
5630 | fprintf (outfile, "\n\nDWARF source line information\n"); | |
2ad9852d | 5631 | for (i = 1; i < line_info_table_in_use; i++) |
a3f97cbb | 5632 | { |
3f76745e JM |
5633 | line_info = &line_info_table[i]; |
5634 | fprintf (outfile, "%5d: ", i); | |
c4274b22 RH |
5635 | fprintf (outfile, "%-20s", |
5636 | VARRAY_CHAR_PTR (file_table, line_info->dw_file_num)); | |
2d8b0f3a | 5637 | fprintf (outfile, "%6ld", line_info->dw_line_num); |
3f76745e | 5638 | fprintf (outfile, "\n"); |
a3f97cbb | 5639 | } |
3f76745e JM |
5640 | |
5641 | fprintf (outfile, "\n\n"); | |
f37230f0 JM |
5642 | } |
5643 | ||
3f76745e JM |
5644 | /* Print the information collected for a given DIE. */ |
5645 | ||
5646 | void | |
7080f735 | 5647 | debug_dwarf_die (dw_die_ref die) |
3f76745e JM |
5648 | { |
5649 | print_die (die, stderr); | |
5650 | } | |
5651 | ||
5652 | /* Print all DWARF information collected for the compilation unit. | |
5653 | This routine is a debugging aid only. */ | |
5654 | ||
5655 | void | |
7080f735 | 5656 | debug_dwarf (void) |
3f76745e JM |
5657 | { |
5658 | print_indent = 0; | |
5659 | print_die (comp_unit_die, stderr); | |
b2244e22 JW |
5660 | if (! DWARF2_ASM_LINE_DEBUG_INFO) |
5661 | print_dwarf_line_table (stderr); | |
3f76745e JM |
5662 | } |
5663 | \f | |
a96c67ec JM |
5664 | /* We build up the lists of children and attributes by pushing new ones |
5665 | onto the beginning of the list. Reverse the lists for DIE so that | |
5666 | they are in order of addition. */ | |
71dfc51f | 5667 | |
f37230f0 | 5668 | static void |
7080f735 | 5669 | reverse_die_lists (dw_die_ref die) |
f37230f0 | 5670 | { |
b3694847 SS |
5671 | dw_die_ref c, cp, cn; |
5672 | dw_attr_ref a, ap, an; | |
71dfc51f | 5673 | |
a96c67ec | 5674 | for (a = die->die_attr, ap = 0; a; a = an) |
7d9d8943 AM |
5675 | { |
5676 | an = a->dw_attr_next; | |
5677 | a->dw_attr_next = ap; | |
5678 | ap = a; | |
a3f97cbb | 5679 | } |
2ad9852d | 5680 | |
7d9d8943 | 5681 | die->die_attr = ap; |
3f76745e | 5682 | |
7d9d8943 AM |
5683 | for (c = die->die_child, cp = 0; c; c = cn) |
5684 | { | |
5685 | cn = c->die_sib; | |
5686 | c->die_sib = cp; | |
5687 | cp = c; | |
5688 | } | |
2ad9852d | 5689 | |
7d9d8943 | 5690 | die->die_child = cp; |
a3f97cbb JW |
5691 | } |
5692 | ||
2ad9852d RK |
5693 | /* reverse_die_lists only reverses the single die you pass it. Since we used to |
5694 | reverse all dies in add_sibling_attributes, which runs through all the dies, | |
5695 | it would reverse all the dies. Now, however, since we don't call | |
5696 | reverse_die_lists in add_sibling_attributes, we need a routine to | |
5697 | recursively reverse all the dies. This is that routine. */ | |
71dfc51f | 5698 | |
7d9d8943 | 5699 | static void |
7080f735 | 5700 | reverse_all_dies (dw_die_ref die) |
a3f97cbb | 5701 | { |
b3694847 | 5702 | dw_die_ref c; |
71dfc51f | 5703 | |
7d9d8943 | 5704 | reverse_die_lists (die); |
3f76745e | 5705 | |
881c6935 JM |
5706 | for (c = die->die_child; c; c = c->die_sib) |
5707 | reverse_all_dies (c); | |
5708 | } | |
5709 | ||
2ad9852d RK |
5710 | /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU |
5711 | for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL | |
5712 | DIE that marks the start of the DIEs for this include file. */ | |
881c6935 JM |
5713 | |
5714 | static dw_die_ref | |
7080f735 | 5715 | push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die) |
881c6935 JM |
5716 | { |
5717 | const char *filename = get_AT_string (bincl_die, DW_AT_name); | |
5718 | dw_die_ref new_unit = gen_compile_unit_die (filename); | |
2ad9852d | 5719 | |
881c6935 JM |
5720 | new_unit->die_sib = old_unit; |
5721 | return new_unit; | |
5722 | } | |
5723 | ||
5724 | /* Close an include-file CU and reopen the enclosing one. */ | |
5725 | ||
5726 | static dw_die_ref | |
7080f735 | 5727 | pop_compile_unit (dw_die_ref old_unit) |
881c6935 JM |
5728 | { |
5729 | dw_die_ref new_unit = old_unit->die_sib; | |
2ad9852d | 5730 | |
881c6935 JM |
5731 | old_unit->die_sib = NULL; |
5732 | return new_unit; | |
5733 | } | |
5734 | ||
2ad9852d RK |
5735 | #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx) |
5736 | #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx) | |
881c6935 JM |
5737 | |
5738 | /* Calculate the checksum of a location expression. */ | |
5739 | ||
5740 | static inline void | |
7080f735 | 5741 | loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx) |
881c6935 | 5742 | { |
2ad9852d RK |
5743 | CHECKSUM (loc->dw_loc_opc); |
5744 | CHECKSUM (loc->dw_loc_oprnd1); | |
5745 | CHECKSUM (loc->dw_loc_oprnd2); | |
881c6935 JM |
5746 | } |
5747 | ||
5748 | /* Calculate the checksum of an attribute. */ | |
5749 | ||
5750 | static void | |
7080f735 | 5751 | attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark) |
881c6935 JM |
5752 | { |
5753 | dw_loc_descr_ref loc; | |
5754 | rtx r; | |
5755 | ||
2ad9852d | 5756 | CHECKSUM (at->dw_attr); |
881c6935 JM |
5757 | |
5758 | /* We don't care about differences in file numbering. */ | |
5f632b5e JM |
5759 | if (at->dw_attr == DW_AT_decl_file |
5760 | /* Or that this was compiled with a different compiler snapshot; if | |
5761 | the output is the same, that's what matters. */ | |
5762 | || at->dw_attr == DW_AT_producer) | |
881c6935 JM |
5763 | return; |
5764 | ||
5765 | switch (AT_class (at)) | |
5766 | { | |
5767 | case dw_val_class_const: | |
2ad9852d | 5768 | CHECKSUM (at->dw_attr_val.v.val_int); |
881c6935 JM |
5769 | break; |
5770 | case dw_val_class_unsigned_const: | |
2ad9852d | 5771 | CHECKSUM (at->dw_attr_val.v.val_unsigned); |
881c6935 JM |
5772 | break; |
5773 | case dw_val_class_long_long: | |
2ad9852d | 5774 | CHECKSUM (at->dw_attr_val.v.val_long_long); |
881c6935 | 5775 | break; |
e7ee3914 AM |
5776 | case dw_val_class_vec: |
5777 | CHECKSUM (at->dw_attr_val.v.val_vec); | |
881c6935 JM |
5778 | break; |
5779 | case dw_val_class_flag: | |
2ad9852d | 5780 | CHECKSUM (at->dw_attr_val.v.val_flag); |
881c6935 | 5781 | break; |
881c6935 | 5782 | case dw_val_class_str: |
2ad9852d | 5783 | CHECKSUM_STRING (AT_string (at)); |
881c6935 | 5784 | break; |
a20612aa | 5785 | |
881c6935 JM |
5786 | case dw_val_class_addr: |
5787 | r = AT_addr (at); | |
5788 | switch (GET_CODE (r)) | |
5789 | { | |
5790 | case SYMBOL_REF: | |
2ad9852d | 5791 | CHECKSUM_STRING (XSTR (r, 0)); |
881c6935 JM |
5792 | break; |
5793 | ||
5794 | default: | |
5795 | abort (); | |
5796 | } | |
5797 | break; | |
5798 | ||
a20612aa | 5799 | case dw_val_class_offset: |
2ad9852d | 5800 | CHECKSUM (at->dw_attr_val.v.val_offset); |
a20612aa RH |
5801 | break; |
5802 | ||
881c6935 JM |
5803 | case dw_val_class_loc: |
5804 | for (loc = AT_loc (at); loc; loc = loc->dw_loc_next) | |
5805 | loc_checksum (loc, ctx); | |
5806 | break; | |
5807 | ||
5808 | case dw_val_class_die_ref: | |
cc0017a9 ZD |
5809 | die_checksum (AT_ref (at), ctx, mark); |
5810 | break; | |
881c6935 JM |
5811 | |
5812 | case dw_val_class_fde_ref: | |
5813 | case dw_val_class_lbl_id: | |
5814 | case dw_val_class_lbl_offset: | |
a20612aa | 5815 | break; |
881c6935 JM |
5816 | |
5817 | default: | |
5818 | break; | |
5819 | } | |
5820 | } | |
5821 | ||
5822 | /* Calculate the checksum of a DIE. */ | |
5823 | ||
5824 | static void | |
7080f735 | 5825 | die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark) |
881c6935 JM |
5826 | { |
5827 | dw_die_ref c; | |
5828 | dw_attr_ref a; | |
5829 | ||
cc0017a9 ZD |
5830 | /* To avoid infinite recursion. */ |
5831 | if (die->die_mark) | |
5832 | { | |
5833 | CHECKSUM (die->die_mark); | |
5834 | return; | |
5835 | } | |
5836 | die->die_mark = ++(*mark); | |
5837 | ||
2ad9852d | 5838 | CHECKSUM (die->die_tag); |
881c6935 JM |
5839 | |
5840 | for (a = die->die_attr; a; a = a->dw_attr_next) | |
cc0017a9 | 5841 | attr_checksum (a, ctx, mark); |
881c6935 JM |
5842 | |
5843 | for (c = die->die_child; c; c = c->die_sib) | |
cc0017a9 | 5844 | die_checksum (c, ctx, mark); |
881c6935 JM |
5845 | } |
5846 | ||
2ad9852d RK |
5847 | #undef CHECKSUM |
5848 | #undef CHECKSUM_STRING | |
881c6935 | 5849 | |
cc0017a9 ZD |
5850 | /* Do the location expressions look same? */ |
5851 | static inline int | |
7080f735 | 5852 | same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark) |
cc0017a9 ZD |
5853 | { |
5854 | return loc1->dw_loc_opc == loc2->dw_loc_opc | |
5855 | && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark) | |
5856 | && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark); | |
5857 | } | |
5858 | ||
5859 | /* Do the values look the same? */ | |
5860 | static int | |
7080f735 | 5861 | same_dw_val_p (dw_val_node *v1, dw_val_node *v2, int *mark) |
cc0017a9 ZD |
5862 | { |
5863 | dw_loc_descr_ref loc1, loc2; | |
5864 | rtx r1, r2; | |
cc0017a9 ZD |
5865 | |
5866 | if (v1->val_class != v2->val_class) | |
5867 | return 0; | |
5868 | ||
5869 | switch (v1->val_class) | |
5870 | { | |
5871 | case dw_val_class_const: | |
5872 | return v1->v.val_int == v2->v.val_int; | |
5873 | case dw_val_class_unsigned_const: | |
5874 | return v1->v.val_unsigned == v2->v.val_unsigned; | |
5875 | case dw_val_class_long_long: | |
5876 | return v1->v.val_long_long.hi == v2->v.val_long_long.hi | |
73c68f61 | 5877 | && v1->v.val_long_long.low == v2->v.val_long_long.low; |
e7ee3914 AM |
5878 | case dw_val_class_vec: |
5879 | if (v1->v.val_vec.length != v2->v.val_vec.length | |
5880 | || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size) | |
5881 | return 0; | |
5882 | if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array, | |
5883 | v1->v.val_vec.length * v1->v.val_vec.elt_size)) | |
cc0017a9 | 5884 | return 0; |
cc0017a9 ZD |
5885 | return 1; |
5886 | case dw_val_class_flag: | |
5887 | return v1->v.val_flag == v2->v.val_flag; | |
5888 | case dw_val_class_str: | |
17211ab5 | 5889 | return !strcmp(v1->v.val_str->str, v2->v.val_str->str); |
cc0017a9 ZD |
5890 | |
5891 | case dw_val_class_addr: | |
5892 | r1 = v1->v.val_addr; | |
5893 | r2 = v2->v.val_addr; | |
5894 | if (GET_CODE (r1) != GET_CODE (r2)) | |
5895 | return 0; | |
5896 | switch (GET_CODE (r1)) | |
5897 | { | |
5898 | case SYMBOL_REF: | |
5899 | return !strcmp (XSTR (r1, 0), XSTR (r2, 0)); | |
5900 | ||
5901 | default: | |
5902 | abort (); | |
5903 | } | |
5904 | ||
5905 | case dw_val_class_offset: | |
5906 | return v1->v.val_offset == v2->v.val_offset; | |
5907 | ||
5908 | case dw_val_class_loc: | |
5909 | for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc; | |
5910 | loc1 && loc2; | |
5911 | loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next) | |
5912 | if (!same_loc_p (loc1, loc2, mark)) | |
5913 | return 0; | |
5914 | return !loc1 && !loc2; | |
5915 | ||
5916 | case dw_val_class_die_ref: | |
5917 | return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark); | |
5918 | ||
5919 | case dw_val_class_fde_ref: | |
5920 | case dw_val_class_lbl_id: | |
5921 | case dw_val_class_lbl_offset: | |
5922 | return 1; | |
5923 | ||
5924 | default: | |
5925 | return 1; | |
5926 | } | |
5927 | } | |
5928 | ||
5929 | /* Do the attributes look the same? */ | |
5930 | ||
5931 | static int | |
7080f735 | 5932 | same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark) |
cc0017a9 ZD |
5933 | { |
5934 | if (at1->dw_attr != at2->dw_attr) | |
5935 | return 0; | |
5936 | ||
5937 | /* We don't care about differences in file numbering. */ | |
5938 | if (at1->dw_attr == DW_AT_decl_file | |
5939 | /* Or that this was compiled with a different compiler snapshot; if | |
5940 | the output is the same, that's what matters. */ | |
5941 | || at1->dw_attr == DW_AT_producer) | |
5942 | return 1; | |
5943 | ||
5944 | return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark); | |
5945 | } | |
5946 | ||
5947 | /* Do the dies look the same? */ | |
5948 | ||
5949 | static int | |
7080f735 | 5950 | same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark) |
cc0017a9 ZD |
5951 | { |
5952 | dw_die_ref c1, c2; | |
5953 | dw_attr_ref a1, a2; | |
5954 | ||
5955 | /* To avoid infinite recursion. */ | |
5956 | if (die1->die_mark) | |
5957 | return die1->die_mark == die2->die_mark; | |
5958 | die1->die_mark = die2->die_mark = ++(*mark); | |
5959 | ||
5960 | if (die1->die_tag != die2->die_tag) | |
5961 | return 0; | |
5962 | ||
5963 | for (a1 = die1->die_attr, a2 = die2->die_attr; | |
5964 | a1 && a2; | |
5965 | a1 = a1->dw_attr_next, a2 = a2->dw_attr_next) | |
5966 | if (!same_attr_p (a1, a2, mark)) | |
5967 | return 0; | |
5968 | if (a1 || a2) | |
5969 | return 0; | |
5970 | ||
5971 | for (c1 = die1->die_child, c2 = die2->die_child; | |
5972 | c1 && c2; | |
5973 | c1 = c1->die_sib, c2 = c2->die_sib) | |
5974 | if (!same_die_p (c1, c2, mark)) | |
5975 | return 0; | |
5976 | if (c1 || c2) | |
5977 | return 0; | |
5978 | ||
5979 | return 1; | |
5980 | } | |
5981 | ||
5982 | /* Do the dies look the same? Wrapper around same_die_p. */ | |
5983 | ||
5984 | static int | |
7080f735 | 5985 | same_die_p_wrap (dw_die_ref die1, dw_die_ref die2) |
cc0017a9 ZD |
5986 | { |
5987 | int mark = 0; | |
5988 | int ret = same_die_p (die1, die2, &mark); | |
5989 | ||
5990 | unmark_all_dies (die1); | |
5991 | unmark_all_dies (die2); | |
5992 | ||
5993 | return ret; | |
5994 | } | |
5995 | ||
881c6935 JM |
5996 | /* The prefix to attach to symbols on DIEs in the current comdat debug |
5997 | info section. */ | |
5998 | static char *comdat_symbol_id; | |
5999 | ||
6000 | /* The index of the current symbol within the current comdat CU. */ | |
6001 | static unsigned int comdat_symbol_number; | |
6002 | ||
6003 | /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its | |
6004 | children, and set comdat_symbol_id accordingly. */ | |
6005 | ||
6006 | static void | |
7080f735 | 6007 | compute_section_prefix (dw_die_ref unit_die) |
881c6935 | 6008 | { |
cc0017a9 ZD |
6009 | const char *die_name = get_AT_string (unit_die, DW_AT_name); |
6010 | const char *base = die_name ? lbasename (die_name) : "anonymous"; | |
703ad42b | 6011 | char *name = alloca (strlen (base) + 64); |
f11c3043 | 6012 | char *p; |
cc0017a9 | 6013 | int i, mark; |
881c6935 JM |
6014 | unsigned char checksum[16]; |
6015 | struct md5_ctx ctx; | |
6016 | ||
f11c3043 RK |
6017 | /* Compute the checksum of the DIE, then append part of it as hex digits to |
6018 | the name filename of the unit. */ | |
6019 | ||
881c6935 | 6020 | md5_init_ctx (&ctx); |
cc0017a9 ZD |
6021 | mark = 0; |
6022 | die_checksum (unit_die, &ctx, &mark); | |
6023 | unmark_all_dies (unit_die); | |
881c6935 JM |
6024 | md5_finish_ctx (&ctx, checksum); |
6025 | ||
0023400b | 6026 | sprintf (name, "%s.", base); |
881c6935 JM |
6027 | clean_symbol_name (name); |
6028 | ||
2ad9852d RK |
6029 | p = name + strlen (name); |
6030 | for (i = 0; i < 4; i++) | |
6031 | { | |
6032 | sprintf (p, "%.2x", checksum[i]); | |
6033 | p += 2; | |
6034 | } | |
881c6935 JM |
6035 | |
6036 | comdat_symbol_id = unit_die->die_symbol = xstrdup (name); | |
6037 | comdat_symbol_number = 0; | |
6038 | } | |
6039 | ||
f11c3043 | 6040 | /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */ |
881c6935 JM |
6041 | |
6042 | static int | |
7080f735 | 6043 | is_type_die (dw_die_ref die) |
881c6935 JM |
6044 | { |
6045 | switch (die->die_tag) | |
6046 | { | |
6047 | case DW_TAG_array_type: | |
6048 | case DW_TAG_class_type: | |
6049 | case DW_TAG_enumeration_type: | |
6050 | case DW_TAG_pointer_type: | |
6051 | case DW_TAG_reference_type: | |
6052 | case DW_TAG_string_type: | |
6053 | case DW_TAG_structure_type: | |
6054 | case DW_TAG_subroutine_type: | |
6055 | case DW_TAG_union_type: | |
6056 | case DW_TAG_ptr_to_member_type: | |
6057 | case DW_TAG_set_type: | |
6058 | case DW_TAG_subrange_type: | |
6059 | case DW_TAG_base_type: | |
6060 | case DW_TAG_const_type: | |
6061 | case DW_TAG_file_type: | |
6062 | case DW_TAG_packed_type: | |
6063 | case DW_TAG_volatile_type: | |
cc0017a9 | 6064 | case DW_TAG_typedef: |
881c6935 JM |
6065 | return 1; |
6066 | default: | |
6067 | return 0; | |
6068 | } | |
6069 | } | |
6070 | ||
6071 | /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU. | |
6072 | Basically, we want to choose the bits that are likely to be shared between | |
6073 | compilations (types) and leave out the bits that are specific to individual | |
6074 | compilations (functions). */ | |
6075 | ||
6076 | static int | |
7080f735 | 6077 | is_comdat_die (dw_die_ref c) |
881c6935 | 6078 | { |
2ad9852d RK |
6079 | /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as |
6080 | we do for stabs. The advantage is a greater likelihood of sharing between | |
6081 | objects that don't include headers in the same order (and therefore would | |
6082 | put the base types in a different comdat). jason 8/28/00 */ | |
6083 | ||
881c6935 JM |
6084 | if (c->die_tag == DW_TAG_base_type) |
6085 | return 0; | |
6086 | ||
6087 | if (c->die_tag == DW_TAG_pointer_type | |
6088 | || c->die_tag == DW_TAG_reference_type | |
6089 | || c->die_tag == DW_TAG_const_type | |
6090 | || c->die_tag == DW_TAG_volatile_type) | |
6091 | { | |
6092 | dw_die_ref t = get_AT_ref (c, DW_AT_type); | |
2ad9852d | 6093 | |
881c6935 JM |
6094 | return t ? is_comdat_die (t) : 0; |
6095 | } | |
881c6935 JM |
6096 | |
6097 | return is_type_die (c); | |
6098 | } | |
6099 | ||
6100 | /* Returns 1 iff C is the sort of DIE that might be referred to from another | |
6101 | compilation unit. */ | |
6102 | ||
6103 | static int | |
7080f735 | 6104 | is_symbol_die (dw_die_ref c) |
881c6935 | 6105 | { |
2ad9852d | 6106 | return (is_type_die (c) |
c26fbbca | 6107 | || (get_AT (c, DW_AT_declaration) |
2ad9852d | 6108 | && !get_AT (c, DW_AT_specification))); |
881c6935 JM |
6109 | } |
6110 | ||
6111 | static char * | |
7080f735 | 6112 | gen_internal_sym (const char *prefix) |
881c6935 JM |
6113 | { |
6114 | char buf[256]; | |
2ad9852d | 6115 | |
63e46568 | 6116 | ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++); |
881c6935 JM |
6117 | return xstrdup (buf); |
6118 | } | |
6119 | ||
6120 | /* Assign symbols to all worthy DIEs under DIE. */ | |
6121 | ||
6122 | static void | |
7080f735 | 6123 | assign_symbol_names (dw_die_ref die) |
881c6935 | 6124 | { |
b3694847 | 6125 | dw_die_ref c; |
881c6935 JM |
6126 | |
6127 | if (is_symbol_die (die)) | |
6128 | { | |
6129 | if (comdat_symbol_id) | |
6130 | { | |
6131 | char *p = alloca (strlen (comdat_symbol_id) + 64); | |
2ad9852d | 6132 | |
881c6935 JM |
6133 | sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX, |
6134 | comdat_symbol_id, comdat_symbol_number++); | |
6135 | die->die_symbol = xstrdup (p); | |
6136 | } | |
6137 | else | |
63e46568 | 6138 | die->die_symbol = gen_internal_sym ("LDIE"); |
881c6935 JM |
6139 | } |
6140 | ||
6141 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
6142 | assign_symbol_names (c); | |
6143 | } | |
6144 | ||
cc0017a9 ZD |
6145 | struct cu_hash_table_entry |
6146 | { | |
6147 | dw_die_ref cu; | |
6148 | unsigned min_comdat_num, max_comdat_num; | |
6149 | struct cu_hash_table_entry *next; | |
6150 | }; | |
6151 | ||
6152 | /* Routines to manipulate hash table of CUs. */ | |
6153 | static hashval_t | |
7080f735 | 6154 | htab_cu_hash (const void *of) |
cc0017a9 ZD |
6155 | { |
6156 | const struct cu_hash_table_entry *entry = of; | |
6157 | ||
6158 | return htab_hash_string (entry->cu->die_symbol); | |
6159 | } | |
6160 | ||
6161 | static int | |
7080f735 | 6162 | htab_cu_eq (const void *of1, const void *of2) |
cc0017a9 ZD |
6163 | { |
6164 | const struct cu_hash_table_entry *entry1 = of1; | |
6165 | const struct die_struct *entry2 = of2; | |
6166 | ||
6167 | return !strcmp (entry1->cu->die_symbol, entry2->die_symbol); | |
6168 | } | |
6169 | ||
6170 | static void | |
7080f735 | 6171 | htab_cu_del (void *what) |
cc0017a9 ZD |
6172 | { |
6173 | struct cu_hash_table_entry *next, *entry = what; | |
6174 | ||
6175 | while (entry) | |
6176 | { | |
6177 | next = entry->next; | |
6178 | free (entry); | |
6179 | entry = next; | |
6180 | } | |
6181 | } | |
6182 | ||
6183 | /* Check whether we have already seen this CU and set up SYM_NUM | |
6184 | accordingly. */ | |
6185 | static int | |
7080f735 | 6186 | check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num) |
cc0017a9 ZD |
6187 | { |
6188 | struct cu_hash_table_entry dummy; | |
6189 | struct cu_hash_table_entry **slot, *entry, *last = &dummy; | |
6190 | ||
6191 | dummy.max_comdat_num = 0; | |
6192 | ||
6193 | slot = (struct cu_hash_table_entry **) | |
6194 | htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol), | |
6195 | INSERT); | |
6196 | entry = *slot; | |
6197 | ||
6198 | for (; entry; last = entry, entry = entry->next) | |
6199 | { | |
6200 | if (same_die_p_wrap (cu, entry->cu)) | |
6201 | break; | |
6202 | } | |
6203 | ||
6204 | if (entry) | |
6205 | { | |
6206 | *sym_num = entry->min_comdat_num; | |
6207 | return 1; | |
6208 | } | |
6209 | ||
6210 | entry = xcalloc (1, sizeof (struct cu_hash_table_entry)); | |
6211 | entry->cu = cu; | |
6212 | entry->min_comdat_num = *sym_num = last->max_comdat_num; | |
6213 | entry->next = *slot; | |
6214 | *slot = entry; | |
6215 | ||
6216 | return 0; | |
6217 | } | |
6218 | ||
6219 | /* Record SYM_NUM to record of CU in HTABLE. */ | |
6220 | static void | |
7080f735 | 6221 | record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num) |
cc0017a9 ZD |
6222 | { |
6223 | struct cu_hash_table_entry **slot, *entry; | |
6224 | ||
6225 | slot = (struct cu_hash_table_entry **) | |
6226 | htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol), | |
6227 | NO_INSERT); | |
6228 | entry = *slot; | |
6229 | ||
6230 | entry->max_comdat_num = sym_num; | |
6231 | } | |
6232 | ||
881c6935 JM |
6233 | /* Traverse the DIE (which is always comp_unit_die), and set up |
6234 | additional compilation units for each of the include files we see | |
6235 | bracketed by BINCL/EINCL. */ | |
6236 | ||
6237 | static void | |
7080f735 | 6238 | break_out_includes (dw_die_ref die) |
881c6935 JM |
6239 | { |
6240 | dw_die_ref *ptr; | |
b3694847 | 6241 | dw_die_ref unit = NULL; |
cc0017a9 ZD |
6242 | limbo_die_node *node, **pnode; |
6243 | htab_t cu_hash_table; | |
881c6935 | 6244 | |
c26fbbca | 6245 | for (ptr = &(die->die_child); *ptr;) |
881c6935 | 6246 | { |
b3694847 | 6247 | dw_die_ref c = *ptr; |
881c6935 | 6248 | |
2ad9852d | 6249 | if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL |
881c6935 JM |
6250 | || (unit && is_comdat_die (c))) |
6251 | { | |
6252 | /* This DIE is for a secondary CU; remove it from the main one. */ | |
6253 | *ptr = c->die_sib; | |
6254 | ||
6255 | if (c->die_tag == DW_TAG_GNU_BINCL) | |
6256 | { | |
6257 | unit = push_new_compile_unit (unit, c); | |
6258 | free_die (c); | |
6259 | } | |
6260 | else if (c->die_tag == DW_TAG_GNU_EINCL) | |
6261 | { | |
6262 | unit = pop_compile_unit (unit); | |
6263 | free_die (c); | |
6264 | } | |
6265 | else | |
6266 | add_child_die (unit, c); | |
6267 | } | |
6268 | else | |
6269 | { | |
6270 | /* Leave this DIE in the main CU. */ | |
6271 | ptr = &(c->die_sib); | |
6272 | continue; | |
6273 | } | |
6274 | } | |
6275 | ||
6276 | #if 0 | |
6277 | /* We can only use this in debugging, since the frontend doesn't check | |
0b34cf1e | 6278 | to make sure that we leave every include file we enter. */ |
881c6935 JM |
6279 | if (unit != NULL) |
6280 | abort (); | |
6281 | #endif | |
6282 | ||
6283 | assign_symbol_names (die); | |
cc0017a9 ZD |
6284 | cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del); |
6285 | for (node = limbo_die_list, pnode = &limbo_die_list; | |
6286 | node; | |
6287 | node = node->next) | |
881c6935 | 6288 | { |
cc0017a9 ZD |
6289 | int is_dupl; |
6290 | ||
881c6935 | 6291 | compute_section_prefix (node->die); |
cc0017a9 ZD |
6292 | is_dupl = check_duplicate_cu (node->die, cu_hash_table, |
6293 | &comdat_symbol_number); | |
881c6935 | 6294 | assign_symbol_names (node->die); |
cc0017a9 ZD |
6295 | if (is_dupl) |
6296 | *pnode = node->next; | |
6297 | else | |
73c68f61 | 6298 | { |
cc0017a9 ZD |
6299 | pnode = &node->next; |
6300 | record_comdat_symbol_number (node->die, cu_hash_table, | |
6301 | comdat_symbol_number); | |
6302 | } | |
881c6935 | 6303 | } |
cc0017a9 | 6304 | htab_delete (cu_hash_table); |
881c6935 JM |
6305 | } |
6306 | ||
6307 | /* Traverse the DIE and add a sibling attribute if it may have the | |
6308 | effect of speeding up access to siblings. To save some space, | |
6309 | avoid generating sibling attributes for DIE's without children. */ | |
6310 | ||
6311 | static void | |
7080f735 | 6312 | add_sibling_attributes (dw_die_ref die) |
881c6935 | 6313 | { |
b3694847 | 6314 | dw_die_ref c; |
881c6935 JM |
6315 | |
6316 | if (die->die_tag != DW_TAG_compile_unit | |
6317 | && die->die_sib && die->die_child != NULL) | |
7d9d8943 AM |
6318 | /* Add the sibling link to the front of the attribute list. */ |
6319 | add_AT_die_ref (die, DW_AT_sibling, die->die_sib); | |
6320 | ||
6321 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
6322 | add_sibling_attributes (c); | |
6323 | } | |
6324 | ||
2ad9852d RK |
6325 | /* Output all location lists for the DIE and its children. */ |
6326 | ||
63e46568 | 6327 | static void |
7080f735 | 6328 | output_location_lists (dw_die_ref die) |
63e46568 DB |
6329 | { |
6330 | dw_die_ref c; | |
6331 | dw_attr_ref d_attr; | |
2ad9852d | 6332 | |
63e46568 | 6333 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) |
2ad9852d RK |
6334 | if (AT_class (d_attr) == dw_val_class_loc_list) |
6335 | output_loc_list (AT_loc_list (d_attr)); | |
6336 | ||
63e46568 DB |
6337 | for (c = die->die_child; c != NULL; c = c->die_sib) |
6338 | output_location_lists (c); | |
6339 | ||
6340 | } | |
c26fbbca | 6341 | |
2ad9852d RK |
6342 | /* The format of each DIE (and its attribute value pairs) is encoded in an |
6343 | abbreviation table. This routine builds the abbreviation table and assigns | |
6344 | a unique abbreviation id for each abbreviation entry. The children of each | |
6345 | die are visited recursively. */ | |
7d9d8943 AM |
6346 | |
6347 | static void | |
7080f735 | 6348 | build_abbrev_table (dw_die_ref die) |
7d9d8943 | 6349 | { |
b3694847 SS |
6350 | unsigned long abbrev_id; |
6351 | unsigned int n_alloc; | |
6352 | dw_die_ref c; | |
6353 | dw_attr_ref d_attr, a_attr; | |
881c6935 JM |
6354 | |
6355 | /* Scan the DIE references, and mark as external any that refer to | |
1bfb5f8f | 6356 | DIEs from other CUs (i.e. those which are not marked). */ |
881c6935 | 6357 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) |
2ad9852d RK |
6358 | if (AT_class (d_attr) == dw_val_class_die_ref |
6359 | && AT_ref (d_attr)->die_mark == 0) | |
6360 | { | |
6361 | if (AT_ref (d_attr)->die_symbol == 0) | |
6362 | abort (); | |
6363 | ||
6364 | set_AT_ref_external (d_attr, 1); | |
6365 | } | |
881c6935 | 6366 | |
7d9d8943 AM |
6367 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
6368 | { | |
b3694847 | 6369 | dw_die_ref abbrev = abbrev_die_table[abbrev_id]; |
7d9d8943 AM |
6370 | |
6371 | if (abbrev->die_tag == die->die_tag) | |
6372 | { | |
6373 | if ((abbrev->die_child != NULL) == (die->die_child != NULL)) | |
6374 | { | |
6375 | a_attr = abbrev->die_attr; | |
6376 | d_attr = die->die_attr; | |
6377 | ||
6378 | while (a_attr != NULL && d_attr != NULL) | |
6379 | { | |
6380 | if ((a_attr->dw_attr != d_attr->dw_attr) | |
6381 | || (value_format (a_attr) != value_format (d_attr))) | |
6382 | break; | |
6383 | ||
6384 | a_attr = a_attr->dw_attr_next; | |
6385 | d_attr = d_attr->dw_attr_next; | |
6386 | } | |
6387 | ||
6388 | if (a_attr == NULL && d_attr == NULL) | |
6389 | break; | |
6390 | } | |
6391 | } | |
6392 | } | |
6393 | ||
6394 | if (abbrev_id >= abbrev_die_table_in_use) | |
6395 | { | |
6396 | if (abbrev_die_table_in_use >= abbrev_die_table_allocated) | |
6397 | { | |
6398 | n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT; | |
17211ab5 GK |
6399 | abbrev_die_table = ggc_realloc (abbrev_die_table, |
6400 | sizeof (dw_die_ref) * n_alloc); | |
7d9d8943 | 6401 | |
703ad42b | 6402 | memset (&abbrev_die_table[abbrev_die_table_allocated], 0, |
7d9d8943 AM |
6403 | (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref)); |
6404 | abbrev_die_table_allocated = n_alloc; | |
6405 | } | |
6406 | ||
6407 | ++abbrev_die_table_in_use; | |
6408 | abbrev_die_table[abbrev_id] = die; | |
6409 | } | |
6410 | ||
6411 | die->die_abbrev = abbrev_id; | |
6412 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
6413 | build_abbrev_table (c); | |
6414 | } | |
6415 | \f | |
3f76745e JM |
6416 | /* Return the power-of-two number of bytes necessary to represent VALUE. */ |
6417 | ||
6418 | static int | |
7080f735 | 6419 | constant_size (long unsigned int value) |
3f76745e JM |
6420 | { |
6421 | int log; | |
6422 | ||
6423 | if (value == 0) | |
6424 | log = 0; | |
a3f97cbb | 6425 | else |
3f76745e | 6426 | log = floor_log2 (value); |
71dfc51f | 6427 | |
3f76745e JM |
6428 | log = log / 8; |
6429 | log = 1 << (floor_log2 (log) + 1); | |
6430 | ||
6431 | return log; | |
a3f97cbb JW |
6432 | } |
6433 | ||
2ad9852d | 6434 | /* Return the size of a DIE as it is represented in the |
3f76745e | 6435 | .debug_info section. */ |
71dfc51f | 6436 | |
3f76745e | 6437 | static unsigned long |
7080f735 | 6438 | size_of_die (dw_die_ref die) |
a3f97cbb | 6439 | { |
b3694847 SS |
6440 | unsigned long size = 0; |
6441 | dw_attr_ref a; | |
71dfc51f | 6442 | |
3f76745e | 6443 | size += size_of_uleb128 (die->die_abbrev); |
a3f97cbb JW |
6444 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
6445 | { | |
a96c67ec | 6446 | switch (AT_class (a)) |
a3f97cbb JW |
6447 | { |
6448 | case dw_val_class_addr: | |
a1a4189d | 6449 | size += DWARF2_ADDR_SIZE; |
a3f97cbb | 6450 | break; |
a20612aa RH |
6451 | case dw_val_class_offset: |
6452 | size += DWARF_OFFSET_SIZE; | |
6453 | break; | |
a3f97cbb | 6454 | case dw_val_class_loc: |
3f76745e | 6455 | { |
b3694847 | 6456 | unsigned long lsize = size_of_locs (AT_loc (a)); |
71dfc51f | 6457 | |
3f76745e JM |
6458 | /* Block length. */ |
6459 | size += constant_size (lsize); | |
6460 | size += lsize; | |
6461 | } | |
a3f97cbb | 6462 | break; |
63e46568 DB |
6463 | case dw_val_class_loc_list: |
6464 | size += DWARF_OFFSET_SIZE; | |
6465 | break; | |
2bee6045 JJ |
6466 | case dw_val_class_range_list: |
6467 | size += DWARF_OFFSET_SIZE; | |
6468 | break; | |
a3f97cbb | 6469 | case dw_val_class_const: |
25dd13ec | 6470 | size += size_of_sleb128 (AT_int (a)); |
a3f97cbb JW |
6471 | break; |
6472 | case dw_val_class_unsigned_const: | |
a96c67ec | 6473 | size += constant_size (AT_unsigned (a)); |
a3f97cbb | 6474 | break; |
469ac993 | 6475 | case dw_val_class_long_long: |
2e4b9b8c | 6476 | size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */ |
469ac993 | 6477 | break; |
e7ee3914 AM |
6478 | case dw_val_class_vec: |
6479 | size += 1 + (a->dw_attr_val.v.val_vec.length | |
6480 | * a->dw_attr_val.v.val_vec.elt_size); /* block */ | |
a3f97cbb JW |
6481 | break; |
6482 | case dw_val_class_flag: | |
3f76745e | 6483 | size += 1; |
a3f97cbb JW |
6484 | break; |
6485 | case dw_val_class_die_ref: | |
323658ea ZD |
6486 | if (AT_ref_external (a)) |
6487 | size += DWARF2_ADDR_SIZE; | |
6488 | else | |
6489 | size += DWARF_OFFSET_SIZE; | |
a3f97cbb JW |
6490 | break; |
6491 | case dw_val_class_fde_ref: | |
3f76745e | 6492 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
6493 | break; |
6494 | case dw_val_class_lbl_id: | |
a1a4189d | 6495 | size += DWARF2_ADDR_SIZE; |
3f76745e | 6496 | break; |
8b790721 | 6497 | case dw_val_class_lbl_offset: |
3f76745e JM |
6498 | size += DWARF_OFFSET_SIZE; |
6499 | break; | |
6500 | case dw_val_class_str: | |
9eb4015a JJ |
6501 | if (AT_string_form (a) == DW_FORM_strp) |
6502 | size += DWARF_OFFSET_SIZE; | |
6503 | else | |
17211ab5 | 6504 | size += strlen (a->dw_attr_val.v.val_str->str) + 1; |
3f76745e JM |
6505 | break; |
6506 | default: | |
6507 | abort (); | |
6508 | } | |
a3f97cbb | 6509 | } |
3f76745e JM |
6510 | |
6511 | return size; | |
a3f97cbb JW |
6512 | } |
6513 | ||
2ad9852d RK |
6514 | /* Size the debugging information associated with a given DIE. Visits the |
6515 | DIE's children recursively. Updates the global variable next_die_offset, on | |
6516 | each time through. Uses the current value of next_die_offset to update the | |
6517 | die_offset field in each DIE. */ | |
71dfc51f | 6518 | |
a3f97cbb | 6519 | static void |
7080f735 | 6520 | calc_die_sizes (dw_die_ref die) |
a3f97cbb | 6521 | { |
b3694847 | 6522 | dw_die_ref c; |
2ad9852d | 6523 | |
3f76745e JM |
6524 | die->die_offset = next_die_offset; |
6525 | next_die_offset += size_of_die (die); | |
71dfc51f | 6526 | |
3f76745e JM |
6527 | for (c = die->die_child; c != NULL; c = c->die_sib) |
6528 | calc_die_sizes (c); | |
71dfc51f | 6529 | |
3f76745e JM |
6530 | if (die->die_child != NULL) |
6531 | /* Count the null byte used to terminate sibling lists. */ | |
6532 | next_die_offset += 1; | |
a3f97cbb JW |
6533 | } |
6534 | ||
1bfb5f8f | 6535 | /* Set the marks for a die and its children. We do this so |
881c6935 | 6536 | that we know whether or not a reference needs to use FORM_ref_addr; only |
1bfb5f8f JM |
6537 | DIEs in the same CU will be marked. We used to clear out the offset |
6538 | and use that as the flag, but ran into ordering problems. */ | |
881c6935 JM |
6539 | |
6540 | static void | |
7080f735 | 6541 | mark_dies (dw_die_ref die) |
881c6935 | 6542 | { |
b3694847 | 6543 | dw_die_ref c; |
2ad9852d | 6544 | |
cc0017a9 ZD |
6545 | if (die->die_mark) |
6546 | abort (); | |
7080f735 | 6547 | |
1bfb5f8f JM |
6548 | die->die_mark = 1; |
6549 | for (c = die->die_child; c; c = c->die_sib) | |
6550 | mark_dies (c); | |
6551 | } | |
6552 | ||
6553 | /* Clear the marks for a die and its children. */ | |
6554 | ||
6555 | static void | |
7080f735 | 6556 | unmark_dies (dw_die_ref die) |
1bfb5f8f | 6557 | { |
b3694847 | 6558 | dw_die_ref c; |
2ad9852d | 6559 | |
cc0017a9 ZD |
6560 | if (!die->die_mark) |
6561 | abort (); | |
7080f735 | 6562 | |
1bfb5f8f | 6563 | die->die_mark = 0; |
881c6935 | 6564 | for (c = die->die_child; c; c = c->die_sib) |
1bfb5f8f | 6565 | unmark_dies (c); |
881c6935 JM |
6566 | } |
6567 | ||
cc0017a9 ZD |
6568 | /* Clear the marks for a die, its children and referred dies. */ |
6569 | ||
6570 | static void | |
7080f735 | 6571 | unmark_all_dies (dw_die_ref die) |
cc0017a9 ZD |
6572 | { |
6573 | dw_die_ref c; | |
6574 | dw_attr_ref a; | |
6575 | ||
6576 | if (!die->die_mark) | |
6577 | return; | |
6578 | die->die_mark = 0; | |
6579 | ||
6580 | for (c = die->die_child; c; c = c->die_sib) | |
6581 | unmark_all_dies (c); | |
6582 | ||
6583 | for (a = die->die_attr; a; a = a->dw_attr_next) | |
6584 | if (AT_class (a) == dw_val_class_die_ref) | |
6585 | unmark_all_dies (AT_ref (a)); | |
6586 | } | |
6587 | ||
3f76745e JM |
6588 | /* Return the size of the .debug_pubnames table generated for the |
6589 | compilation unit. */ | |
a94dbf2c | 6590 | |
3f76745e | 6591 | static unsigned long |
7080f735 | 6592 | size_of_pubnames (void) |
a94dbf2c | 6593 | { |
b3694847 SS |
6594 | unsigned long size; |
6595 | unsigned i; | |
469ac993 | 6596 | |
3f76745e | 6597 | size = DWARF_PUBNAMES_HEADER_SIZE; |
2ad9852d | 6598 | for (i = 0; i < pubname_table_in_use; i++) |
a94dbf2c | 6599 | { |
b3694847 | 6600 | pubname_ref p = &pubname_table[i]; |
9eb4015a | 6601 | size += DWARF_OFFSET_SIZE + strlen (p->name) + 1; |
a94dbf2c JM |
6602 | } |
6603 | ||
3f76745e JM |
6604 | size += DWARF_OFFSET_SIZE; |
6605 | return size; | |
a94dbf2c JM |
6606 | } |
6607 | ||
956d6950 | 6608 | /* Return the size of the information in the .debug_aranges section. */ |
469ac993 | 6609 | |
3f76745e | 6610 | static unsigned long |
7080f735 | 6611 | size_of_aranges (void) |
469ac993 | 6612 | { |
b3694847 | 6613 | unsigned long size; |
469ac993 | 6614 | |
3f76745e | 6615 | size = DWARF_ARANGES_HEADER_SIZE; |
469ac993 | 6616 | |
3f76745e | 6617 | /* Count the address/length pair for this compilation unit. */ |
a1a4189d JB |
6618 | size += 2 * DWARF2_ADDR_SIZE; |
6619 | size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use; | |
469ac993 | 6620 | |
3f76745e | 6621 | /* Count the two zero words used to terminated the address range table. */ |
a1a4189d | 6622 | size += 2 * DWARF2_ADDR_SIZE; |
3f76745e JM |
6623 | return size; |
6624 | } | |
6625 | \f | |
6626 | /* Select the encoding of an attribute value. */ | |
6627 | ||
6628 | static enum dwarf_form | |
7080f735 | 6629 | value_format (dw_attr_ref a) |
3f76745e | 6630 | { |
a96c67ec | 6631 | switch (a->dw_attr_val.val_class) |
469ac993 | 6632 | { |
3f76745e JM |
6633 | case dw_val_class_addr: |
6634 | return DW_FORM_addr; | |
2bee6045 | 6635 | case dw_val_class_range_list: |
a20612aa RH |
6636 | case dw_val_class_offset: |
6637 | if (DWARF_OFFSET_SIZE == 4) | |
6638 | return DW_FORM_data4; | |
6639 | if (DWARF_OFFSET_SIZE == 8) | |
6640 | return DW_FORM_data8; | |
6641 | abort (); | |
63e46568 | 6642 | case dw_val_class_loc_list: |
9d2f2c45 RH |
6643 | /* FIXME: Could be DW_FORM_data8, with a > 32 bit size |
6644 | .debug_loc section */ | |
6645 | return DW_FORM_data4; | |
3f76745e | 6646 | case dw_val_class_loc: |
a96c67ec | 6647 | switch (constant_size (size_of_locs (AT_loc (a)))) |
469ac993 | 6648 | { |
3f76745e JM |
6649 | case 1: |
6650 | return DW_FORM_block1; | |
6651 | case 2: | |
6652 | return DW_FORM_block2; | |
469ac993 JM |
6653 | default: |
6654 | abort (); | |
6655 | } | |
3f76745e | 6656 | case dw_val_class_const: |
25dd13ec | 6657 | return DW_FORM_sdata; |
3f76745e | 6658 | case dw_val_class_unsigned_const: |
a96c67ec | 6659 | switch (constant_size (AT_unsigned (a))) |
3f76745e JM |
6660 | { |
6661 | case 1: | |
6662 | return DW_FORM_data1; | |
6663 | case 2: | |
6664 | return DW_FORM_data2; | |
6665 | case 4: | |
6666 | return DW_FORM_data4; | |
6667 | case 8: | |
6668 | return DW_FORM_data8; | |
6669 | default: | |
6670 | abort (); | |
6671 | } | |
6672 | case dw_val_class_long_long: | |
6673 | return DW_FORM_block1; | |
e7ee3914 | 6674 | case dw_val_class_vec: |
3f76745e JM |
6675 | return DW_FORM_block1; |
6676 | case dw_val_class_flag: | |
6677 | return DW_FORM_flag; | |
6678 | case dw_val_class_die_ref: | |
881c6935 JM |
6679 | if (AT_ref_external (a)) |
6680 | return DW_FORM_ref_addr; | |
6681 | else | |
6682 | return DW_FORM_ref; | |
3f76745e JM |
6683 | case dw_val_class_fde_ref: |
6684 | return DW_FORM_data; | |
6685 | case dw_val_class_lbl_id: | |
6686 | return DW_FORM_addr; | |
8b790721 | 6687 | case dw_val_class_lbl_offset: |
3f76745e JM |
6688 | return DW_FORM_data; |
6689 | case dw_val_class_str: | |
9eb4015a | 6690 | return AT_string_form (a); |
a20612aa | 6691 | |
469ac993 JM |
6692 | default: |
6693 | abort (); | |
6694 | } | |
a94dbf2c JM |
6695 | } |
6696 | ||
3f76745e | 6697 | /* Output the encoding of an attribute value. */ |
469ac993 | 6698 | |
3f76745e | 6699 | static void |
7080f735 | 6700 | output_value_format (dw_attr_ref a) |
a94dbf2c | 6701 | { |
a96c67ec | 6702 | enum dwarf_form form = value_format (a); |
2ad9852d | 6703 | |
2e4b9b8c | 6704 | dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form)); |
3f76745e | 6705 | } |
469ac993 | 6706 | |
3f76745e JM |
6707 | /* Output the .debug_abbrev section which defines the DIE abbreviation |
6708 | table. */ | |
469ac993 | 6709 | |
3f76745e | 6710 | static void |
7080f735 | 6711 | output_abbrev_section (void) |
3f76745e JM |
6712 | { |
6713 | unsigned long abbrev_id; | |
71dfc51f | 6714 | |
3f76745e | 6715 | dw_attr_ref a_attr; |
2ad9852d | 6716 | |
3f76745e JM |
6717 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
6718 | { | |
b3694847 | 6719 | dw_die_ref abbrev = abbrev_die_table[abbrev_id]; |
71dfc51f | 6720 | |
2e4b9b8c | 6721 | dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)"); |
2e4b9b8c RH |
6722 | dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)", |
6723 | dwarf_tag_name (abbrev->die_tag)); | |
71dfc51f | 6724 | |
2e4b9b8c RH |
6725 | if (abbrev->die_child != NULL) |
6726 | dw2_asm_output_data (1, DW_children_yes, "DW_children_yes"); | |
6727 | else | |
6728 | dw2_asm_output_data (1, DW_children_no, "DW_children_no"); | |
3f76745e JM |
6729 | |
6730 | for (a_attr = abbrev->die_attr; a_attr != NULL; | |
6731 | a_attr = a_attr->dw_attr_next) | |
6732 | { | |
2e4b9b8c RH |
6733 | dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)", |
6734 | dwarf_attr_name (a_attr->dw_attr)); | |
a96c67ec | 6735 | output_value_format (a_attr); |
469ac993 | 6736 | } |
469ac993 | 6737 | |
2e4b9b8c RH |
6738 | dw2_asm_output_data (1, 0, NULL); |
6739 | dw2_asm_output_data (1, 0, NULL); | |
469ac993 | 6740 | } |
81f374eb HPN |
6741 | |
6742 | /* Terminate the table. */ | |
2e4b9b8c | 6743 | dw2_asm_output_data (1, 0, NULL); |
a94dbf2c JM |
6744 | } |
6745 | ||
881c6935 JM |
6746 | /* Output a symbol we can use to refer to this DIE from another CU. */ |
6747 | ||
6748 | static inline void | |
7080f735 | 6749 | output_die_symbol (dw_die_ref die) |
881c6935 JM |
6750 | { |
6751 | char *sym = die->die_symbol; | |
6752 | ||
6753 | if (sym == 0) | |
6754 | return; | |
6755 | ||
6756 | if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0) | |
6757 | /* We make these global, not weak; if the target doesn't support | |
6758 | .linkonce, it doesn't support combining the sections, so debugging | |
6759 | will break. */ | |
5fd9b178 | 6760 | targetm.asm_out.globalize_label (asm_out_file, sym); |
2ad9852d | 6761 | |
881c6935 JM |
6762 | ASM_OUTPUT_LABEL (asm_out_file, sym); |
6763 | } | |
6764 | ||
84a5b4f8 | 6765 | /* Return a new location list, given the begin and end range, and the |
2ad9852d RK |
6766 | expression. gensym tells us whether to generate a new internal symbol for |
6767 | this location list node, which is done for the head of the list only. */ | |
6768 | ||
84a5b4f8 | 6769 | static inline dw_loc_list_ref |
7080f735 AJ |
6770 | new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end, |
6771 | const char *section, unsigned int gensym) | |
84a5b4f8 | 6772 | { |
17211ab5 | 6773 | dw_loc_list_ref retlist = ggc_alloc_cleared (sizeof (dw_loc_list_node)); |
2ad9852d | 6774 | |
84a5b4f8 DB |
6775 | retlist->begin = begin; |
6776 | retlist->end = end; | |
6777 | retlist->expr = expr; | |
6778 | retlist->section = section; | |
c26fbbca | 6779 | if (gensym) |
84a5b4f8 | 6780 | retlist->ll_symbol = gen_internal_sym ("LLST"); |
2ad9852d | 6781 | |
84a5b4f8 DB |
6782 | return retlist; |
6783 | } | |
6784 | ||
f9da5064 | 6785 | /* Add a location description expression to a location list. */ |
2ad9852d | 6786 | |
84a5b4f8 | 6787 | static inline void |
7080f735 AJ |
6788 | add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr, |
6789 | const char *begin, const char *end, | |
6790 | const char *section) | |
84a5b4f8 | 6791 | { |
b3694847 | 6792 | dw_loc_list_ref *d; |
c26fbbca | 6793 | |
30f7a378 | 6794 | /* Find the end of the chain. */ |
84a5b4f8 DB |
6795 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) |
6796 | ; | |
2ad9852d | 6797 | |
f9da5064 | 6798 | /* Add a new location list node to the list. */ |
84a5b4f8 DB |
6799 | *d = new_loc_list (descr, begin, end, section, 0); |
6800 | } | |
6801 | ||
f9da5064 | 6802 | /* Output the location list given to us. */ |
2ad9852d | 6803 | |
63e46568 | 6804 | static void |
7080f735 | 6805 | output_loc_list (dw_loc_list_ref list_head) |
63e46568 | 6806 | { |
2ad9852d RK |
6807 | dw_loc_list_ref curr = list_head; |
6808 | ||
63e46568 | 6809 | ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol); |
a20612aa | 6810 | |
1711adc2 | 6811 | /* Walk the location list, and output each range + expression. */ |
c26fbbca | 6812 | for (curr = list_head; curr != NULL; curr = curr->dw_loc_next) |
63e46568 | 6813 | { |
2bee6045 | 6814 | unsigned long size; |
1711adc2 DB |
6815 | if (separate_line_info_table_in_use == 0) |
6816 | { | |
6817 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section, | |
6818 | "Location list begin address (%s)", | |
6819 | list_head->ll_symbol); | |
6820 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section, | |
6821 | "Location list end address (%s)", | |
6822 | list_head->ll_symbol); | |
6823 | } | |
6824 | else | |
6825 | { | |
6826 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin, | |
6827 | "Location list begin address (%s)", | |
6828 | list_head->ll_symbol); | |
6829 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end, | |
6830 | "Location list end address (%s)", | |
6831 | list_head->ll_symbol); | |
6832 | } | |
63e46568 | 6833 | size = size_of_locs (curr->expr); |
c26fbbca | 6834 | |
63e46568 | 6835 | /* Output the block length for this list of location operations. */ |
2bee6045 JJ |
6836 | if (size > 0xffff) |
6837 | abort (); | |
6838 | dw2_asm_output_data (2, size, "%s", "Location expression size"); | |
6839 | ||
63e46568 DB |
6840 | output_loc_sequence (curr->expr); |
6841 | } | |
2ad9852d | 6842 | |
1711adc2 | 6843 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, |
aafdcfcd NS |
6844 | "Location list terminator begin (%s)", |
6845 | list_head->ll_symbol); | |
1711adc2 | 6846 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, |
aafdcfcd NS |
6847 | "Location list terminator end (%s)", |
6848 | list_head->ll_symbol); | |
63e46568 | 6849 | } |
9eb4015a | 6850 | |
3f76745e JM |
6851 | /* Output the DIE and its attributes. Called recursively to generate |
6852 | the definitions of each child DIE. */ | |
71dfc51f | 6853 | |
a3f97cbb | 6854 | static void |
7080f735 | 6855 | output_die (dw_die_ref die) |
a3f97cbb | 6856 | { |
b3694847 SS |
6857 | dw_attr_ref a; |
6858 | dw_die_ref c; | |
6859 | unsigned long size; | |
a94dbf2c | 6860 | |
881c6935 JM |
6861 | /* If someone in another CU might refer to us, set up a symbol for |
6862 | them to point to. */ | |
6863 | if (die->die_symbol) | |
6864 | output_die_symbol (die); | |
6865 | ||
2e4b9b8c RH |
6866 | dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)", |
6867 | die->die_offset, dwarf_tag_name (die->die_tag)); | |
a94dbf2c | 6868 | |
3f76745e | 6869 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
a3f97cbb | 6870 | { |
2e4b9b8c RH |
6871 | const char *name = dwarf_attr_name (a->dw_attr); |
6872 | ||
a96c67ec | 6873 | switch (AT_class (a)) |
3f76745e JM |
6874 | { |
6875 | case dw_val_class_addr: | |
2e4b9b8c | 6876 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name); |
3f76745e | 6877 | break; |
a3f97cbb | 6878 | |
a20612aa RH |
6879 | case dw_val_class_offset: |
6880 | dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset, | |
6881 | "%s", name); | |
6882 | break; | |
6883 | ||
2bee6045 JJ |
6884 | case dw_val_class_range_list: |
6885 | { | |
6886 | char *p = strchr (ranges_section_label, '\0'); | |
6887 | ||
38f9cd4c AJ |
6888 | sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX, |
6889 | a->dw_attr_val.v.val_offset); | |
2bee6045 JJ |
6890 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label, |
6891 | "%s", name); | |
6892 | *p = '\0'; | |
6893 | } | |
6894 | break; | |
6895 | ||
3f76745e | 6896 | case dw_val_class_loc: |
a96c67ec | 6897 | size = size_of_locs (AT_loc (a)); |
71dfc51f | 6898 | |
3f76745e | 6899 | /* Output the block length for this list of location operations. */ |
2e4b9b8c | 6900 | dw2_asm_output_data (constant_size (size), size, "%s", name); |
71dfc51f | 6901 | |
7d9d8943 | 6902 | output_loc_sequence (AT_loc (a)); |
a3f97cbb | 6903 | break; |
3f76745e JM |
6904 | |
6905 | case dw_val_class_const: | |
25dd13ec JW |
6906 | /* ??? It would be slightly more efficient to use a scheme like is |
6907 | used for unsigned constants below, but gdb 4.x does not sign | |
6908 | extend. Gdb 5.x does sign extend. */ | |
2e4b9b8c | 6909 | dw2_asm_output_data_sleb128 (AT_int (a), "%s", name); |
a3f97cbb | 6910 | break; |
3f76745e JM |
6911 | |
6912 | case dw_val_class_unsigned_const: | |
2e4b9b8c RH |
6913 | dw2_asm_output_data (constant_size (AT_unsigned (a)), |
6914 | AT_unsigned (a), "%s", name); | |
a3f97cbb | 6915 | break; |
3f76745e JM |
6916 | |
6917 | case dw_val_class_long_long: | |
2e4b9b8c RH |
6918 | { |
6919 | unsigned HOST_WIDE_INT first, second; | |
3f76745e | 6920 | |
2ad9852d RK |
6921 | dw2_asm_output_data (1, |
6922 | 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, | |
c26fbbca | 6923 | "%s", name); |
556273e0 | 6924 | |
2e4b9b8c RH |
6925 | if (WORDS_BIG_ENDIAN) |
6926 | { | |
6927 | first = a->dw_attr_val.v.val_long_long.hi; | |
6928 | second = a->dw_attr_val.v.val_long_long.low; | |
6929 | } | |
6930 | else | |
6931 | { | |
6932 | first = a->dw_attr_val.v.val_long_long.low; | |
6933 | second = a->dw_attr_val.v.val_long_long.hi; | |
6934 | } | |
2ad9852d RK |
6935 | |
6936 | dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, | |
2e4b9b8c | 6937 | first, "long long constant"); |
2ad9852d | 6938 | dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, |
2e4b9b8c RH |
6939 | second, NULL); |
6940 | } | |
a3f97cbb | 6941 | break; |
3f76745e | 6942 | |
e7ee3914 | 6943 | case dw_val_class_vec: |
c84e2712 | 6944 | { |
e7ee3914 AM |
6945 | unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size; |
6946 | unsigned int len = a->dw_attr_val.v.val_vec.length; | |
b3694847 | 6947 | unsigned int i; |
e7ee3914 | 6948 | unsigned char *p; |
c84e2712 | 6949 | |
e7ee3914 AM |
6950 | dw2_asm_output_data (1, len * elt_size, "%s", name); |
6951 | if (elt_size > sizeof (HOST_WIDE_INT)) | |
6952 | { | |
6953 | elt_size /= 2; | |
6954 | len *= 2; | |
6955 | } | |
6956 | for (i = 0, p = a->dw_attr_val.v.val_vec.array; | |
6957 | i < len; | |
6958 | i++, p += elt_size) | |
6959 | dw2_asm_output_data (elt_size, extract_int (p, elt_size), | |
6960 | "fp or vector constant word %u", i); | |
556273e0 | 6961 | break; |
c84e2712 | 6962 | } |
3f76745e JM |
6963 | |
6964 | case dw_val_class_flag: | |
2e4b9b8c | 6965 | dw2_asm_output_data (1, AT_flag (a), "%s", name); |
a3f97cbb | 6966 | break; |
a20612aa | 6967 | |
c26fbbca | 6968 | case dw_val_class_loc_list: |
63e46568 DB |
6969 | { |
6970 | char *sym = AT_loc_list (a)->ll_symbol; | |
2ad9852d | 6971 | |
63e46568 | 6972 | if (sym == 0) |
173bf5be | 6973 | abort (); |
1711adc2 | 6974 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, "%s", name); |
63e46568 DB |
6975 | } |
6976 | break; | |
a20612aa | 6977 | |
3f76745e | 6978 | case dw_val_class_die_ref: |
881c6935 | 6979 | if (AT_ref_external (a)) |
2e4b9b8c RH |
6980 | { |
6981 | char *sym = AT_ref (a)->die_symbol; | |
2ad9852d | 6982 | |
2e4b9b8c RH |
6983 | if (sym == 0) |
6984 | abort (); | |
6985 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name); | |
6986 | } | |
3f4907a6 JM |
6987 | else if (AT_ref (a)->die_offset == 0) |
6988 | abort (); | |
881c6935 | 6989 | else |
2e4b9b8c RH |
6990 | dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset, |
6991 | "%s", name); | |
a3f97cbb | 6992 | break; |
3f76745e JM |
6993 | |
6994 | case dw_val_class_fde_ref: | |
a6ab3aad JM |
6995 | { |
6996 | char l1[20]; | |
2ad9852d | 6997 | |
2e4b9b8c RH |
6998 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL, |
6999 | a->dw_attr_val.v.val_fde_index * 2); | |
7000 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name); | |
a6ab3aad | 7001 | } |
a3f97cbb | 7002 | break; |
a3f97cbb | 7003 | |
3f76745e | 7004 | case dw_val_class_lbl_id: |
8e7fa2c8 | 7005 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 7006 | break; |
71dfc51f | 7007 | |
8b790721 | 7008 | case dw_val_class_lbl_offset: |
2e4b9b8c | 7009 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 7010 | break; |
a3f97cbb | 7011 | |
3f76745e | 7012 | case dw_val_class_str: |
9eb4015a JJ |
7013 | if (AT_string_form (a) == DW_FORM_strp) |
7014 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, | |
7015 | a->dw_attr_val.v.val_str->label, | |
a4cf1d85 | 7016 | "%s: \"%s\"", name, AT_string (a)); |
9eb4015a JJ |
7017 | else |
7018 | dw2_asm_output_nstring (AT_string (a), -1, "%s", name); | |
3f76745e | 7019 | break; |
b2932ae5 | 7020 | |
3f76745e JM |
7021 | default: |
7022 | abort (); | |
7023 | } | |
3f76745e | 7024 | } |
71dfc51f | 7025 | |
3f76745e JM |
7026 | for (c = die->die_child; c != NULL; c = c->die_sib) |
7027 | output_die (c); | |
71dfc51f | 7028 | |
2ad9852d | 7029 | /* Add null byte to terminate sibling list. */ |
3f76745e | 7030 | if (die->die_child != NULL) |
2ad9852d RK |
7031 | dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx", |
7032 | die->die_offset); | |
3f76745e | 7033 | } |
71dfc51f | 7034 | |
3f76745e JM |
7035 | /* Output the compilation unit that appears at the beginning of the |
7036 | .debug_info section, and precedes the DIE descriptions. */ | |
71dfc51f | 7037 | |
3f76745e | 7038 | static void |
7080f735 | 7039 | output_compilation_unit_header (void) |
3f76745e | 7040 | { |
9eb0ef7a KB |
7041 | if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4) |
7042 | dw2_asm_output_data (4, 0xffffffff, | |
7043 | "Initial length escape value indicating 64-bit DWARF extension"); | |
7044 | dw2_asm_output_data (DWARF_OFFSET_SIZE, | |
7045 | next_die_offset - DWARF_INITIAL_LENGTH_SIZE, | |
2e4b9b8c | 7046 | "Length of Compilation Unit Info"); |
2e4b9b8c | 7047 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number"); |
2e4b9b8c RH |
7048 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label, |
7049 | "Offset Into Abbrev. Section"); | |
2e4b9b8c | 7050 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)"); |
a3f97cbb JW |
7051 | } |
7052 | ||
881c6935 JM |
7053 | /* Output the compilation unit DIE and its children. */ |
7054 | ||
7055 | static void | |
7080f735 | 7056 | output_comp_unit (dw_die_ref die, int output_if_empty) |
881c6935 | 7057 | { |
ce1cc601 | 7058 | const char *secname; |
cc0017a9 ZD |
7059 | char *oldsym, *tmp; |
7060 | ||
7061 | /* Unless we are outputting main CU, we may throw away empty ones. */ | |
7062 | if (!output_if_empty && die->die_child == NULL) | |
7063 | return; | |
881c6935 | 7064 | |
2ad9852d RK |
7065 | /* Even if there are no children of this DIE, we must output the information |
7066 | about the compilation unit. Otherwise, on an empty translation unit, we | |
7067 | will generate a present, but empty, .debug_info section. IRIX 6.5 `nm' | |
7068 | will then complain when examining the file. First mark all the DIEs in | |
7069 | this CU so we know which get local refs. */ | |
1bfb5f8f JM |
7070 | mark_dies (die); |
7071 | ||
7072 | build_abbrev_table (die); | |
7073 | ||
6d2f8887 | 7074 | /* Initialize the beginning DIE offset - and calculate sizes/offsets. */ |
881c6935 JM |
7075 | next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE; |
7076 | calc_die_sizes (die); | |
7077 | ||
cc0017a9 ZD |
7078 | oldsym = die->die_symbol; |
7079 | if (oldsym) | |
881c6935 | 7080 | { |
703ad42b | 7081 | tmp = alloca (strlen (oldsym) + 24); |
2ad9852d | 7082 | |
cc0017a9 | 7083 | sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym); |
ce1cc601 | 7084 | secname = tmp; |
881c6935 JM |
7085 | die->die_symbol = NULL; |
7086 | } | |
7087 | else | |
ce1cc601 | 7088 | secname = (const char *) DEBUG_INFO_SECTION; |
881c6935 JM |
7089 | |
7090 | /* Output debugging information. */ | |
715bdd29 | 7091 | named_section_flags (secname, SECTION_DEBUG); |
881c6935 JM |
7092 | output_compilation_unit_header (); |
7093 | output_die (die); | |
7094 | ||
1bfb5f8f JM |
7095 | /* Leave the marks on the main CU, so we can check them in |
7096 | output_pubnames. */ | |
cc0017a9 ZD |
7097 | if (oldsym) |
7098 | { | |
7099 | unmark_dies (die); | |
7100 | die->die_symbol = oldsym; | |
7101 | } | |
881c6935 JM |
7102 | } |
7103 | ||
7afff7cf NB |
7104 | /* The DWARF2 pubname for a nested thingy looks like "A::f". The |
7105 | output of lang_hooks.decl_printable_name for C++ looks like | |
7106 | "A::f(int)". Let's drop the argument list, and maybe the scope. */ | |
a1d7ffe3 | 7107 | |
d560ee52 | 7108 | static const char * |
7080f735 | 7109 | dwarf2_name (tree decl, int scope) |
a1d7ffe3 | 7110 | { |
ae2bcd98 | 7111 | return lang_hooks.decl_printable_name (decl, scope ? 1 : 0); |
a1d7ffe3 JM |
7112 | } |
7113 | ||
d291dd49 | 7114 | /* Add a new entry to .debug_pubnames if appropriate. */ |
71dfc51f | 7115 | |
d291dd49 | 7116 | static void |
7080f735 | 7117 | add_pubname (tree decl, dw_die_ref die) |
d291dd49 JM |
7118 | { |
7119 | pubname_ref p; | |
7120 | ||
7121 | if (! TREE_PUBLIC (decl)) | |
7122 | return; | |
7123 | ||
7124 | if (pubname_table_in_use == pubname_table_allocated) | |
7125 | { | |
7126 | pubname_table_allocated += PUBNAME_TABLE_INCREMENT; | |
2ad9852d | 7127 | pubname_table |
703ad42b KG |
7128 | = ggc_realloc (pubname_table, |
7129 | (pubname_table_allocated * sizeof (pubname_entry))); | |
17211ab5 GK |
7130 | memset (pubname_table + pubname_table_in_use, 0, |
7131 | PUBNAME_TABLE_INCREMENT * sizeof (pubname_entry)); | |
d291dd49 | 7132 | } |
71dfc51f | 7133 | |
d291dd49 JM |
7134 | p = &pubname_table[pubname_table_in_use++]; |
7135 | p->die = die; | |
a1d7ffe3 | 7136 | p->name = xstrdup (dwarf2_name (decl, 1)); |
d291dd49 JM |
7137 | } |
7138 | ||
a3f97cbb JW |
7139 | /* Output the public names table used to speed up access to externally |
7140 | visible names. For now, only generate entries for externally | |
7141 | visible procedures. */ | |
71dfc51f | 7142 | |
a3f97cbb | 7143 | static void |
7080f735 | 7144 | output_pubnames (void) |
a3f97cbb | 7145 | { |
b3694847 SS |
7146 | unsigned i; |
7147 | unsigned long pubnames_length = size_of_pubnames (); | |
71dfc51f | 7148 | |
9eb0ef7a KB |
7149 | if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4) |
7150 | dw2_asm_output_data (4, 0xffffffff, | |
7151 | "Initial length escape value indicating 64-bit DWARF extension"); | |
2e4b9b8c RH |
7152 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, |
7153 | "Length of Public Names Info"); | |
2e4b9b8c | 7154 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
2e4b9b8c RH |
7155 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
7156 | "Offset of Compilation Unit Info"); | |
2e4b9b8c RH |
7157 | dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset, |
7158 | "Compilation Unit Length"); | |
71dfc51f | 7159 | |
2ad9852d | 7160 | for (i = 0; i < pubname_table_in_use; i++) |
a3f97cbb | 7161 | { |
b3694847 | 7162 | pubname_ref pub = &pubname_table[i]; |
71dfc51f | 7163 | |
881c6935 | 7164 | /* We shouldn't see pubnames for DIEs outside of the main CU. */ |
1bfb5f8f | 7165 | if (pub->die->die_mark == 0) |
881c6935 JM |
7166 | abort (); |
7167 | ||
2e4b9b8c RH |
7168 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset, |
7169 | "DIE offset"); | |
71dfc51f | 7170 | |
2e4b9b8c | 7171 | dw2_asm_output_nstring (pub->name, -1, "external name"); |
a3f97cbb | 7172 | } |
71dfc51f | 7173 | |
2e4b9b8c | 7174 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL); |
a3f97cbb JW |
7175 | } |
7176 | ||
d291dd49 | 7177 | /* Add a new entry to .debug_aranges if appropriate. */ |
71dfc51f | 7178 | |
d291dd49 | 7179 | static void |
7080f735 | 7180 | add_arange (tree decl, dw_die_ref die) |
d291dd49 JM |
7181 | { |
7182 | if (! DECL_SECTION_NAME (decl)) | |
7183 | return; | |
7184 | ||
7185 | if (arange_table_in_use == arange_table_allocated) | |
7186 | { | |
7187 | arange_table_allocated += ARANGE_TABLE_INCREMENT; | |
7080f735 AJ |
7188 | arange_table = ggc_realloc (arange_table, |
7189 | (arange_table_allocated | |
17211ab5 GK |
7190 | * sizeof (dw_die_ref))); |
7191 | memset (arange_table + arange_table_in_use, 0, | |
7192 | ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref)); | |
d291dd49 | 7193 | } |
71dfc51f | 7194 | |
d291dd49 JM |
7195 | arange_table[arange_table_in_use++] = die; |
7196 | } | |
7197 | ||
a3f97cbb JW |
7198 | /* Output the information that goes into the .debug_aranges table. |
7199 | Namely, define the beginning and ending address range of the | |
7200 | text section generated for this compilation unit. */ | |
71dfc51f | 7201 | |
a3f97cbb | 7202 | static void |
7080f735 | 7203 | output_aranges (void) |
a3f97cbb | 7204 | { |
b3694847 SS |
7205 | unsigned i; |
7206 | unsigned long aranges_length = size_of_aranges (); | |
71dfc51f | 7207 | |
9eb0ef7a KB |
7208 | if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4) |
7209 | dw2_asm_output_data (4, 0xffffffff, | |
7210 | "Initial length escape value indicating 64-bit DWARF extension"); | |
2e4b9b8c RH |
7211 | dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length, |
7212 | "Length of Address Ranges Info"); | |
2e4b9b8c | 7213 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
2e4b9b8c RH |
7214 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
7215 | "Offset of Compilation Unit Info"); | |
2e4b9b8c | 7216 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address"); |
2e4b9b8c | 7217 | dw2_asm_output_data (1, 0, "Size of Segment Descriptor"); |
71dfc51f | 7218 | |
262b6384 SC |
7219 | /* We need to align to twice the pointer size here. */ |
7220 | if (DWARF_ARANGES_PAD_SIZE) | |
7221 | { | |
2e4b9b8c | 7222 | /* Pad using a 2 byte words so that padding is correct for any |
73c68f61 | 7223 | pointer size. */ |
2e4b9b8c RH |
7224 | dw2_asm_output_data (2, 0, "Pad to %d byte boundary", |
7225 | 2 * DWARF2_ADDR_SIZE); | |
770ca8c6 | 7226 | for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2) |
2e4b9b8c | 7227 | dw2_asm_output_data (2, 0, NULL); |
262b6384 | 7228 | } |
71dfc51f | 7229 | |
8e7fa2c8 | 7230 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address"); |
2e4b9b8c RH |
7231 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label, |
7232 | text_section_label, "Length"); | |
71dfc51f | 7233 | |
2ad9852d | 7234 | for (i = 0; i < arange_table_in_use; i++) |
d291dd49 | 7235 | { |
e689ae67 | 7236 | dw_die_ref die = arange_table[i]; |
71dfc51f | 7237 | |
881c6935 | 7238 | /* We shouldn't see aranges for DIEs outside of the main CU. */ |
1bfb5f8f | 7239 | if (die->die_mark == 0) |
881c6935 JM |
7240 | abort (); |
7241 | ||
e689ae67 | 7242 | if (die->die_tag == DW_TAG_subprogram) |
2e4b9b8c | 7243 | { |
8e7fa2c8 | 7244 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die), |
173bf5be | 7245 | "Address"); |
2e4b9b8c RH |
7246 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die), |
7247 | get_AT_low_pc (die), "Length"); | |
7248 | } | |
d291dd49 | 7249 | else |
a1d7ffe3 | 7250 | { |
e689ae67 JM |
7251 | /* A static variable; extract the symbol from DW_AT_location. |
7252 | Note that this code isn't currently hit, as we only emit | |
7253 | aranges for functions (jason 9/23/99). */ | |
e689ae67 JM |
7254 | dw_attr_ref a = get_AT (die, DW_AT_location); |
7255 | dw_loc_descr_ref loc; | |
2ad9852d | 7256 | |
a96c67ec | 7257 | if (! a || AT_class (a) != dw_val_class_loc) |
e689ae67 JM |
7258 | abort (); |
7259 | ||
a96c67ec | 7260 | loc = AT_loc (a); |
e689ae67 JM |
7261 | if (loc->dw_loc_opc != DW_OP_addr) |
7262 | abort (); | |
7263 | ||
2e4b9b8c RH |
7264 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, |
7265 | loc->dw_loc_oprnd1.v.val_addr, "Address"); | |
7266 | dw2_asm_output_data (DWARF2_ADDR_SIZE, | |
7267 | get_AT_unsigned (die, DW_AT_byte_size), | |
7268 | "Length"); | |
a1d7ffe3 | 7269 | } |
d291dd49 | 7270 | } |
71dfc51f | 7271 | |
a3f97cbb | 7272 | /* Output the terminator words. */ |
2e4b9b8c RH |
7273 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); |
7274 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
a3f97cbb JW |
7275 | } |
7276 | ||
a20612aa RH |
7277 | /* Add a new entry to .debug_ranges. Return the offset at which it |
7278 | was placed. */ | |
7279 | ||
7280 | static unsigned int | |
7080f735 | 7281 | add_ranges (tree block) |
a20612aa RH |
7282 | { |
7283 | unsigned int in_use = ranges_table_in_use; | |
7284 | ||
7285 | if (in_use == ranges_table_allocated) | |
7286 | { | |
7287 | ranges_table_allocated += RANGES_TABLE_INCREMENT; | |
703ad42b KG |
7288 | ranges_table |
7289 | = ggc_realloc (ranges_table, (ranges_table_allocated | |
7290 | * sizeof (struct dw_ranges_struct))); | |
17211ab5 GK |
7291 | memset (ranges_table + ranges_table_in_use, 0, |
7292 | RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct)); | |
a20612aa RH |
7293 | } |
7294 | ||
7295 | ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0); | |
7296 | ranges_table_in_use = in_use + 1; | |
7297 | ||
7298 | return in_use * 2 * DWARF2_ADDR_SIZE; | |
7299 | } | |
7300 | ||
7301 | static void | |
7080f735 | 7302 | output_ranges (void) |
a20612aa | 7303 | { |
b3694847 | 7304 | unsigned i; |
83182544 | 7305 | static const char *const start_fmt = "Offset 0x%x"; |
a20612aa RH |
7306 | const char *fmt = start_fmt; |
7307 | ||
2ad9852d | 7308 | for (i = 0; i < ranges_table_in_use; i++) |
a20612aa RH |
7309 | { |
7310 | int block_num = ranges_table[i].block_num; | |
7311 | ||
7312 | if (block_num) | |
7313 | { | |
7314 | char blabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
7315 | char elabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
7316 | ||
7317 | ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num); | |
7318 | ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num); | |
7319 | ||
7320 | /* If all code is in the text section, then the compilation | |
7321 | unit base address defaults to DW_AT_low_pc, which is the | |
7322 | base of the text section. */ | |
7323 | if (separate_line_info_table_in_use == 0) | |
7324 | { | |
7325 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel, | |
7326 | text_section_label, | |
7327 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
7328 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel, | |
7329 | text_section_label, NULL); | |
7330 | } | |
2ad9852d | 7331 | |
a20612aa RH |
7332 | /* Otherwise, we add a DW_AT_entry_pc attribute to force the |
7333 | compilation unit base address to zero, which allows us to | |
7334 | use absolute addresses, and not worry about whether the | |
7335 | target supports cross-section arithmetic. */ | |
7336 | else | |
7337 | { | |
7338 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel, | |
7339 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
7340 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL); | |
7341 | } | |
7342 | ||
7343 | fmt = NULL; | |
7344 | } | |
7345 | else | |
7346 | { | |
7347 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
7348 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
7349 | fmt = start_fmt; | |
7350 | } | |
7351 | } | |
7352 | } | |
0b34cf1e UD |
7353 | |
7354 | /* Data structure containing information about input files. */ | |
7355 | struct file_info | |
7356 | { | |
7357 | char *path; /* Complete file name. */ | |
7358 | char *fname; /* File name part. */ | |
7359 | int length; /* Length of entire string. */ | |
7360 | int file_idx; /* Index in input file table. */ | |
7361 | int dir_idx; /* Index in directory table. */ | |
7362 | }; | |
7363 | ||
7364 | /* Data structure containing information about directories with source | |
7365 | files. */ | |
7366 | struct dir_info | |
7367 | { | |
7368 | char *path; /* Path including directory name. */ | |
7369 | int length; /* Path length. */ | |
7370 | int prefix; /* Index of directory entry which is a prefix. */ | |
0b34cf1e UD |
7371 | int count; /* Number of files in this directory. */ |
7372 | int dir_idx; /* Index of directory used as base. */ | |
7373 | int used; /* Used in the end? */ | |
7374 | }; | |
7375 | ||
7376 | /* Callback function for file_info comparison. We sort by looking at | |
7377 | the directories in the path. */ | |
356b0698 | 7378 | |
0b34cf1e | 7379 | static int |
7080f735 | 7380 | file_info_cmp (const void *p1, const void *p2) |
0b34cf1e UD |
7381 | { |
7382 | const struct file_info *s1 = p1; | |
7383 | const struct file_info *s2 = p2; | |
7384 | unsigned char *cp1; | |
7385 | unsigned char *cp2; | |
7386 | ||
356b0698 RK |
7387 | /* Take care of file names without directories. We need to make sure that |
7388 | we return consistent values to qsort since some will get confused if | |
7389 | we return the same value when identical operands are passed in opposite | |
7390 | orders. So if neither has a directory, return 0 and otherwise return | |
7391 | 1 or -1 depending on which one has the directory. */ | |
7392 | if ((s1->path == s1->fname || s2->path == s2->fname)) | |
7393 | return (s2->path == s2->fname) - (s1->path == s1->fname); | |
0b34cf1e UD |
7394 | |
7395 | cp1 = (unsigned char *) s1->path; | |
7396 | cp2 = (unsigned char *) s2->path; | |
7397 | ||
7398 | while (1) | |
7399 | { | |
7400 | ++cp1; | |
7401 | ++cp2; | |
356b0698 RK |
7402 | /* Reached the end of the first path? If so, handle like above. */ |
7403 | if ((cp1 == (unsigned char *) s1->fname) | |
7404 | || (cp2 == (unsigned char *) s2->fname)) | |
7405 | return ((cp2 == (unsigned char *) s2->fname) | |
7406 | - (cp1 == (unsigned char *) s1->fname)); | |
0b34cf1e UD |
7407 | |
7408 | /* Character of current path component the same? */ | |
356b0698 | 7409 | else if (*cp1 != *cp2) |
0b34cf1e UD |
7410 | return *cp1 - *cp2; |
7411 | } | |
7412 | } | |
7413 | ||
7414 | /* Output the directory table and the file name table. We try to minimize | |
7415 | the total amount of memory needed. A heuristic is used to avoid large | |
7416 | slowdowns with many input files. */ | |
2ad9852d | 7417 | |
0b34cf1e | 7418 | static void |
7080f735 | 7419 | output_file_names (void) |
0b34cf1e UD |
7420 | { |
7421 | struct file_info *files; | |
7422 | struct dir_info *dirs; | |
7423 | int *saved; | |
7424 | int *savehere; | |
7425 | int *backmap; | |
c4274b22 | 7426 | size_t ndirs; |
0b34cf1e | 7427 | int idx_offset; |
c4274b22 | 7428 | size_t i; |
0b34cf1e UD |
7429 | int idx; |
7430 | ||
f0b886ab UW |
7431 | /* Handle the case where file_table is empty. */ |
7432 | if (VARRAY_ACTIVE_SIZE (file_table) <= 1) | |
7433 | { | |
7434 | dw2_asm_output_data (1, 0, "End directory table"); | |
7435 | dw2_asm_output_data (1, 0, "End file name table"); | |
7436 | return; | |
7437 | } | |
7438 | ||
0b34cf1e | 7439 | /* Allocate the various arrays we need. */ |
703ad42b KG |
7440 | files = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (struct file_info)); |
7441 | dirs = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (struct dir_info)); | |
0b34cf1e UD |
7442 | |
7443 | /* Sort the file names. */ | |
c4274b22 | 7444 | for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++) |
0b34cf1e UD |
7445 | { |
7446 | char *f; | |
7447 | ||
7448 | /* Skip all leading "./". */ | |
c4274b22 | 7449 | f = VARRAY_CHAR_PTR (file_table, i); |
0b34cf1e UD |
7450 | while (f[0] == '.' && f[1] == '/') |
7451 | f += 2; | |
7452 | ||
7453 | /* Create a new array entry. */ | |
7454 | files[i].path = f; | |
7455 | files[i].length = strlen (f); | |
7456 | files[i].file_idx = i; | |
7457 | ||
7458 | /* Search for the file name part. */ | |
7459 | f = strrchr (f, '/'); | |
7460 | files[i].fname = f == NULL ? files[i].path : f + 1; | |
7461 | } | |
2ad9852d | 7462 | |
c4274b22 RH |
7463 | qsort (files + 1, VARRAY_ACTIVE_SIZE (file_table) - 1, |
7464 | sizeof (files[0]), file_info_cmp); | |
0b34cf1e UD |
7465 | |
7466 | /* Find all the different directories used. */ | |
7467 | dirs[0].path = files[1].path; | |
7468 | dirs[0].length = files[1].fname - files[1].path; | |
7469 | dirs[0].prefix = -1; | |
0b34cf1e UD |
7470 | dirs[0].count = 1; |
7471 | dirs[0].dir_idx = 0; | |
7472 | dirs[0].used = 0; | |
7473 | files[1].dir_idx = 0; | |
7474 | ndirs = 1; | |
7475 | ||
c4274b22 | 7476 | for (i = 2; i < VARRAY_ACTIVE_SIZE (file_table); i++) |
0b34cf1e UD |
7477 | if (files[i].fname - files[i].path == dirs[ndirs - 1].length |
7478 | && memcmp (dirs[ndirs - 1].path, files[i].path, | |
7479 | dirs[ndirs - 1].length) == 0) | |
7480 | { | |
7481 | /* Same directory as last entry. */ | |
7482 | files[i].dir_idx = ndirs - 1; | |
0b34cf1e UD |
7483 | ++dirs[ndirs - 1].count; |
7484 | } | |
7485 | else | |
7486 | { | |
c4274b22 | 7487 | size_t j; |
0b34cf1e UD |
7488 | |
7489 | /* This is a new directory. */ | |
7490 | dirs[ndirs].path = files[i].path; | |
7491 | dirs[ndirs].length = files[i].fname - files[i].path; | |
0b34cf1e UD |
7492 | dirs[ndirs].count = 1; |
7493 | dirs[ndirs].dir_idx = ndirs; | |
7494 | dirs[ndirs].used = 0; | |
7495 | files[i].dir_idx = ndirs; | |
7496 | ||
7497 | /* Search for a prefix. */ | |
981975b6 | 7498 | dirs[ndirs].prefix = -1; |
2ad9852d | 7499 | for (j = 0; j < ndirs; j++) |
981975b6 RH |
7500 | if (dirs[j].length < dirs[ndirs].length |
7501 | && dirs[j].length > 1 | |
7502 | && (dirs[ndirs].prefix == -1 | |
7503 | || dirs[j].length > dirs[dirs[ndirs].prefix].length) | |
7504 | && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0) | |
7505 | dirs[ndirs].prefix = j; | |
0b34cf1e UD |
7506 | |
7507 | ++ndirs; | |
7508 | } | |
7509 | ||
2ad9852d RK |
7510 | /* Now to the actual work. We have to find a subset of the directories which |
7511 | allow expressing the file name using references to the directory table | |
7512 | with the least amount of characters. We do not do an exhaustive search | |
7513 | where we would have to check out every combination of every single | |
7514 | possible prefix. Instead we use a heuristic which provides nearly optimal | |
7515 | results in most cases and never is much off. */ | |
703ad42b KG |
7516 | saved = alloca (ndirs * sizeof (int)); |
7517 | savehere = alloca (ndirs * sizeof (int)); | |
0b34cf1e UD |
7518 | |
7519 | memset (saved, '\0', ndirs * sizeof (saved[0])); | |
2ad9852d | 7520 | for (i = 0; i < ndirs; i++) |
0b34cf1e | 7521 | { |
c4274b22 | 7522 | size_t j; |
0b34cf1e UD |
7523 | int total; |
7524 | ||
2ad9852d RK |
7525 | /* We can always save some space for the current directory. But this |
7526 | does not mean it will be enough to justify adding the directory. */ | |
0b34cf1e UD |
7527 | savehere[i] = dirs[i].length; |
7528 | total = (savehere[i] - saved[i]) * dirs[i].count; | |
7529 | ||
2ad9852d | 7530 | for (j = i + 1; j < ndirs; j++) |
0b34cf1e UD |
7531 | { |
7532 | savehere[j] = 0; | |
0b34cf1e UD |
7533 | if (saved[j] < dirs[i].length) |
7534 | { | |
7535 | /* Determine whether the dirs[i] path is a prefix of the | |
7536 | dirs[j] path. */ | |
7537 | int k; | |
7538 | ||
981975b6 | 7539 | k = dirs[j].prefix; |
c4274b22 | 7540 | while (k != -1 && k != (int) i) |
981975b6 RH |
7541 | k = dirs[k].prefix; |
7542 | ||
c4274b22 | 7543 | if (k == (int) i) |
981975b6 RH |
7544 | { |
7545 | /* Yes it is. We can possibly safe some memory but | |
7546 | writing the filenames in dirs[j] relative to | |
7547 | dirs[i]. */ | |
7548 | savehere[j] = dirs[i].length; | |
7549 | total += (savehere[j] - saved[j]) * dirs[j].count; | |
7550 | } | |
0b34cf1e UD |
7551 | } |
7552 | } | |
7553 | ||
7554 | /* Check whether we can safe enough to justify adding the dirs[i] | |
7555 | directory. */ | |
7556 | if (total > dirs[i].length + 1) | |
7557 | { | |
981975b6 | 7558 | /* It's worthwhile adding. */ |
c26fbbca | 7559 | for (j = i; j < ndirs; j++) |
0b34cf1e UD |
7560 | if (savehere[j] > 0) |
7561 | { | |
7562 | /* Remember how much we saved for this directory so far. */ | |
7563 | saved[j] = savehere[j]; | |
7564 | ||
7565 | /* Remember the prefix directory. */ | |
7566 | dirs[j].dir_idx = i; | |
7567 | } | |
7568 | } | |
7569 | } | |
7570 | ||
2ad9852d RK |
7571 | /* We have to emit them in the order they appear in the file_table array |
7572 | since the index is used in the debug info generation. To do this | |
7573 | efficiently we generate a back-mapping of the indices first. */ | |
703ad42b | 7574 | backmap = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (int)); |
c4274b22 | 7575 | for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++) |
0b34cf1e UD |
7576 | { |
7577 | backmap[files[i].file_idx] = i; | |
2ad9852d | 7578 | |
0b34cf1e UD |
7579 | /* Mark this directory as used. */ |
7580 | dirs[dirs[files[i].dir_idx].dir_idx].used = 1; | |
7581 | } | |
7582 | ||
2ad9852d RK |
7583 | /* That was it. We are ready to emit the information. First emit the |
7584 | directory name table. We have to make sure the first actually emitted | |
7585 | directory name has index one; zero is reserved for the current working | |
7586 | directory. Make sure we do not confuse these indices with the one for the | |
7587 | constructed table (even though most of the time they are identical). */ | |
0b34cf1e | 7588 | idx = 1; |
e57cabac | 7589 | idx_offset = dirs[0].length > 0 ? 1 : 0; |
2ad9852d | 7590 | for (i = 1 - idx_offset; i < ndirs; i++) |
0b34cf1e UD |
7591 | if (dirs[i].used != 0) |
7592 | { | |
7593 | dirs[i].used = idx++; | |
2e4b9b8c RH |
7594 | dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1, |
7595 | "Directory Entry: 0x%x", dirs[i].used); | |
0b34cf1e | 7596 | } |
2ad9852d | 7597 | |
2e4b9b8c RH |
7598 | dw2_asm_output_data (1, 0, "End directory table"); |
7599 | ||
0b34cf1e UD |
7600 | /* Correct the index for the current working directory entry if it |
7601 | exists. */ | |
7602 | if (idx_offset == 0) | |
7603 | dirs[0].used = 0; | |
0b34cf1e UD |
7604 | |
7605 | /* Now write all the file names. */ | |
c4274b22 | 7606 | for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++) |
0b34cf1e UD |
7607 | { |
7608 | int file_idx = backmap[i]; | |
7609 | int dir_idx = dirs[files[file_idx].dir_idx].dir_idx; | |
7610 | ||
2e4b9b8c | 7611 | dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1, |
94e001a9 | 7612 | "File Entry: 0x%lx", (unsigned long) i); |
0b34cf1e UD |
7613 | |
7614 | /* Include directory index. */ | |
2e4b9b8c | 7615 | dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL); |
0b34cf1e UD |
7616 | |
7617 | /* Modification time. */ | |
2e4b9b8c | 7618 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e UD |
7619 | |
7620 | /* File length in bytes. */ | |
2e4b9b8c | 7621 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e | 7622 | } |
2ad9852d | 7623 | |
2e4b9b8c | 7624 | dw2_asm_output_data (1, 0, "End file name table"); |
0b34cf1e UD |
7625 | } |
7626 | ||
7627 | ||
a3f97cbb | 7628 | /* Output the source line number correspondence information. This |
14a774a9 | 7629 | information goes into the .debug_line section. */ |
71dfc51f | 7630 | |
a3f97cbb | 7631 | static void |
7080f735 | 7632 | output_line_info (void) |
a3f97cbb | 7633 | { |
981975b6 | 7634 | char l1[20], l2[20], p1[20], p2[20]; |
a3f97cbb JW |
7635 | char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
7636 | char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 SS |
7637 | unsigned opc; |
7638 | unsigned n_op_args; | |
7639 | unsigned long lt_index; | |
7640 | unsigned long current_line; | |
7641 | long line_offset; | |
7642 | long line_delta; | |
7643 | unsigned long current_file; | |
7644 | unsigned long function; | |
71dfc51f | 7645 | |
2e4b9b8c RH |
7646 | ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0); |
7647 | ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0); | |
981975b6 RH |
7648 | ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0); |
7649 | ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0); | |
71dfc51f | 7650 | |
9eb0ef7a KB |
7651 | if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4) |
7652 | dw2_asm_output_data (4, 0xffffffff, | |
7653 | "Initial length escape value indicating 64-bit DWARF extension"); | |
2e4b9b8c RH |
7654 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1, |
7655 | "Length of Source Line Info"); | |
7656 | ASM_OUTPUT_LABEL (asm_out_file, l1); | |
71dfc51f | 7657 | |
2e4b9b8c | 7658 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
981975b6 RH |
7659 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length"); |
7660 | ASM_OUTPUT_LABEL (asm_out_file, p1); | |
71dfc51f | 7661 | |
c1a046e5 TT |
7662 | /* Define the architecture-dependent minimum instruction length (in |
7663 | bytes). In this implementation of DWARF, this field is used for | |
7664 | information purposes only. Since GCC generates assembly language, | |
7665 | we have no a priori knowledge of how many instruction bytes are | |
7666 | generated for each source line, and therefore can use only the | |
7667 | DW_LNE_set_address and DW_LNS_fixed_advance_pc line information | |
7668 | commands. Accordingly, we fix this as `1', which is "correct | |
7669 | enough" for all architectures, and don't let the target override. */ | |
7670 | dw2_asm_output_data (1, 1, | |
2e4b9b8c | 7671 | "Minimum Instruction Length"); |
c1a046e5 | 7672 | |
2e4b9b8c RH |
7673 | dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START, |
7674 | "Default is_stmt_start flag"); | |
2e4b9b8c RH |
7675 | dw2_asm_output_data (1, DWARF_LINE_BASE, |
7676 | "Line Base Value (Special Opcodes)"); | |
2e4b9b8c RH |
7677 | dw2_asm_output_data (1, DWARF_LINE_RANGE, |
7678 | "Line Range Value (Special Opcodes)"); | |
2e4b9b8c RH |
7679 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE, |
7680 | "Special Opcode Base"); | |
71dfc51f | 7681 | |
2ad9852d | 7682 | for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++) |
a3f97cbb JW |
7683 | { |
7684 | switch (opc) | |
7685 | { | |
7686 | case DW_LNS_advance_pc: | |
7687 | case DW_LNS_advance_line: | |
7688 | case DW_LNS_set_file: | |
7689 | case DW_LNS_set_column: | |
7690 | case DW_LNS_fixed_advance_pc: | |
7691 | n_op_args = 1; | |
7692 | break; | |
7693 | default: | |
7694 | n_op_args = 0; | |
7695 | break; | |
7696 | } | |
2e4b9b8c RH |
7697 | |
7698 | dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args", | |
7699 | opc, n_op_args); | |
a3f97cbb | 7700 | } |
71dfc51f | 7701 | |
0b34cf1e UD |
7702 | /* Write out the information about the files we use. */ |
7703 | output_file_names (); | |
981975b6 | 7704 | ASM_OUTPUT_LABEL (asm_out_file, p2); |
a3f97cbb | 7705 | |
2f22d404 JM |
7706 | /* We used to set the address register to the first location in the text |
7707 | section here, but that didn't accomplish anything since we already | |
7708 | have a line note for the opening brace of the first function. */ | |
a3f97cbb JW |
7709 | |
7710 | /* Generate the line number to PC correspondence table, encoded as | |
7711 | a series of state machine operations. */ | |
7712 | current_file = 1; | |
7713 | current_line = 1; | |
8b790721 | 7714 | strcpy (prev_line_label, text_section_label); |
a3f97cbb JW |
7715 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) |
7716 | { | |
b3694847 | 7717 | dw_line_info_ref line_info = &line_info_table[lt_index]; |
2f22d404 | 7718 | |
10a11b75 JM |
7719 | #if 0 |
7720 | /* Disable this optimization for now; GDB wants to see two line notes | |
7721 | at the beginning of a function so it can find the end of the | |
7722 | prologue. */ | |
7723 | ||
2f22d404 | 7724 | /* Don't emit anything for redundant notes. Just updating the |
73c68f61 SS |
7725 | address doesn't accomplish anything, because we already assume |
7726 | that anything after the last address is this line. */ | |
2f22d404 JM |
7727 | if (line_info->dw_line_num == current_line |
7728 | && line_info->dw_file_num == current_file) | |
7729 | continue; | |
10a11b75 | 7730 | #endif |
71dfc51f | 7731 | |
2e4b9b8c RH |
7732 | /* Emit debug info for the address of the current line. |
7733 | ||
7734 | Unfortunately, we have little choice here currently, and must always | |
2ad9852d | 7735 | use the most general form. GCC does not know the address delta |
2e4b9b8c RH |
7736 | itself, so we can't use DW_LNS_advance_pc. Many ports do have length |
7737 | attributes which will give an upper bound on the address range. We | |
7738 | could perhaps use length attributes to determine when it is safe to | |
7739 | use DW_LNS_fixed_advance_pc. */ | |
7740 | ||
5c90448c | 7741 | ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index); |
f19a6894 JW |
7742 | if (0) |
7743 | { | |
7744 | /* This can handle deltas up to 0xffff. This takes 3 bytes. */ | |
2e4b9b8c RH |
7745 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7746 | "DW_LNS_fixed_advance_pc"); | |
7747 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7748 | } |
7749 | else | |
7750 | { | |
a1a4189d | 7751 | /* This can handle any delta. This takes |
73c68f61 | 7752 | 4+DWARF2_ADDR_SIZE bytes. */ |
2e4b9b8c RH |
7753 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7754 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7755 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7756 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7757 | } |
2ad9852d | 7758 | |
f19a6894 JW |
7759 | strcpy (prev_line_label, line_label); |
7760 | ||
7761 | /* Emit debug info for the source file of the current line, if | |
7762 | different from the previous line. */ | |
a3f97cbb JW |
7763 | if (line_info->dw_file_num != current_file) |
7764 | { | |
7765 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
7766 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
7767 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
c4274b22 RH |
7768 | VARRAY_CHAR_PTR (file_table, |
7769 | current_file)); | |
a3f97cbb | 7770 | } |
71dfc51f | 7771 | |
f19a6894 JW |
7772 | /* Emit debug info for the current line number, choosing the encoding |
7773 | that uses the least amount of space. */ | |
2f22d404 | 7774 | if (line_info->dw_line_num != current_line) |
a3f97cbb | 7775 | { |
2f22d404 JM |
7776 | line_offset = line_info->dw_line_num - current_line; |
7777 | line_delta = line_offset - DWARF_LINE_BASE; | |
7778 | current_line = line_info->dw_line_num; | |
7779 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
2ad9852d RK |
7780 | /* This can handle deltas from -10 to 234, using the current |
7781 | definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This | |
7782 | takes 1 byte. */ | |
7783 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, | |
7784 | "line %lu", current_line); | |
2f22d404 JM |
7785 | else |
7786 | { | |
7787 | /* This can handle any delta. This takes at least 4 bytes, | |
7788 | depending on the value being encoded. */ | |
2e4b9b8c RH |
7789 | dw2_asm_output_data (1, DW_LNS_advance_line, |
7790 | "advance to line %lu", current_line); | |
7791 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
7792 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
2f22d404 | 7793 | } |
a94dbf2c JM |
7794 | } |
7795 | else | |
2ad9852d RK |
7796 | /* We still need to start a new row, so output a copy insn. */ |
7797 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
a3f97cbb JW |
7798 | } |
7799 | ||
f19a6894 JW |
7800 | /* Emit debug info for the address of the end of the function. */ |
7801 | if (0) | |
7802 | { | |
2e4b9b8c RH |
7803 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7804 | "DW_LNS_fixed_advance_pc"); | |
7805 | dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL); | |
f19a6894 JW |
7806 | } |
7807 | else | |
7808 | { | |
2e4b9b8c RH |
7809 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7810 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7811 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7812 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL); |
f19a6894 | 7813 | } |
bdb669cb | 7814 | |
2e4b9b8c RH |
7815 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
7816 | dw2_asm_output_data_uleb128 (1, NULL); | |
7817 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
7818 | |
7819 | function = 0; | |
7820 | current_file = 1; | |
7821 | current_line = 1; | |
556273e0 | 7822 | for (lt_index = 0; lt_index < separate_line_info_table_in_use;) |
e90b62db | 7823 | { |
b3694847 | 7824 | dw_separate_line_info_ref line_info |
e90b62db | 7825 | = &separate_line_info_table[lt_index]; |
71dfc51f | 7826 | |
10a11b75 | 7827 | #if 0 |
2f22d404 JM |
7828 | /* Don't emit anything for redundant notes. */ |
7829 | if (line_info->dw_line_num == current_line | |
7830 | && line_info->dw_file_num == current_file | |
7831 | && line_info->function == function) | |
7832 | goto cont; | |
10a11b75 | 7833 | #endif |
2f22d404 | 7834 | |
f19a6894 JW |
7835 | /* Emit debug info for the address of the current line. If this is |
7836 | a new function, or the first line of a function, then we need | |
7837 | to handle it differently. */ | |
5c90448c JM |
7838 | ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL, |
7839 | lt_index); | |
e90b62db JM |
7840 | if (function != line_info->function) |
7841 | { | |
7842 | function = line_info->function; | |
71dfc51f | 7843 | |
f9da5064 | 7844 | /* Set the address register to the first line in the function. */ |
2e4b9b8c RH |
7845 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7846 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7847 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7848 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
e90b62db JM |
7849 | } |
7850 | else | |
7851 | { | |
f19a6894 JW |
7852 | /* ??? See the DW_LNS_advance_pc comment above. */ |
7853 | if (0) | |
7854 | { | |
2e4b9b8c RH |
7855 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7856 | "DW_LNS_fixed_advance_pc"); | |
7857 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7858 | } |
7859 | else | |
7860 | { | |
2e4b9b8c RH |
7861 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7862 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7863 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7864 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7865 | } |
e90b62db | 7866 | } |
2ad9852d | 7867 | |
f19a6894 | 7868 | strcpy (prev_line_label, line_label); |
71dfc51f | 7869 | |
f19a6894 JW |
7870 | /* Emit debug info for the source file of the current line, if |
7871 | different from the previous line. */ | |
e90b62db JM |
7872 | if (line_info->dw_file_num != current_file) |
7873 | { | |
7874 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
7875 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
7876 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
c4274b22 RH |
7877 | VARRAY_CHAR_PTR (file_table, |
7878 | current_file)); | |
e90b62db | 7879 | } |
71dfc51f | 7880 | |
f19a6894 JW |
7881 | /* Emit debug info for the current line number, choosing the encoding |
7882 | that uses the least amount of space. */ | |
e90b62db JM |
7883 | if (line_info->dw_line_num != current_line) |
7884 | { | |
7885 | line_offset = line_info->dw_line_num - current_line; | |
7886 | line_delta = line_offset - DWARF_LINE_BASE; | |
7887 | current_line = line_info->dw_line_num; | |
7888 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
2e4b9b8c RH |
7889 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, |
7890 | "line %lu", current_line); | |
e90b62db JM |
7891 | else |
7892 | { | |
2e4b9b8c RH |
7893 | dw2_asm_output_data (1, DW_LNS_advance_line, |
7894 | "advance to line %lu", current_line); | |
7895 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
7896 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
e90b62db JM |
7897 | } |
7898 | } | |
2f22d404 | 7899 | else |
2e4b9b8c | 7900 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); |
71dfc51f | 7901 | |
10a11b75 | 7902 | #if 0 |
2f22d404 | 7903 | cont: |
10a11b75 | 7904 | #endif |
2ad9852d RK |
7905 | |
7906 | lt_index++; | |
e90b62db JM |
7907 | |
7908 | /* If we're done with a function, end its sequence. */ | |
7909 | if (lt_index == separate_line_info_table_in_use | |
7910 | || separate_line_info_table[lt_index].function != function) | |
7911 | { | |
7912 | current_file = 1; | |
7913 | current_line = 1; | |
71dfc51f | 7914 | |
f19a6894 | 7915 | /* Emit debug info for the address of the end of the function. */ |
5c90448c | 7916 | ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function); |
f19a6894 JW |
7917 | if (0) |
7918 | { | |
2e4b9b8c RH |
7919 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7920 | "DW_LNS_fixed_advance_pc"); | |
7921 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7922 | } |
7923 | else | |
7924 | { | |
2e4b9b8c RH |
7925 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7926 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7927 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7928 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7929 | } |
e90b62db JM |
7930 | |
7931 | /* Output the marker for the end of this sequence. */ | |
2e4b9b8c RH |
7932 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
7933 | dw2_asm_output_data_uleb128 (1, NULL); | |
7934 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
7935 | } |
7936 | } | |
f19f17e0 JM |
7937 | |
7938 | /* Output the marker for the end of the line number info. */ | |
2e4b9b8c | 7939 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
a3f97cbb JW |
7940 | } |
7941 | \f | |
a3f97cbb JW |
7942 | /* Given a pointer to a tree node for some base type, return a pointer to |
7943 | a DIE that describes the given type. | |
7944 | ||
7945 | This routine must only be called for GCC type nodes that correspond to | |
7946 | Dwarf base (fundamental) types. */ | |
71dfc51f | 7947 | |
a3f97cbb | 7948 | static dw_die_ref |
7080f735 | 7949 | base_type_die (tree type) |
a3f97cbb | 7950 | { |
b3694847 SS |
7951 | dw_die_ref base_type_result; |
7952 | const char *type_name; | |
7953 | enum dwarf_type encoding; | |
7954 | tree name = TYPE_NAME (type); | |
a3f97cbb | 7955 | |
2ad9852d | 7956 | if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE) |
a3f97cbb JW |
7957 | return 0; |
7958 | ||
405f63da MM |
7959 | if (name) |
7960 | { | |
7961 | if (TREE_CODE (name) == TYPE_DECL) | |
7962 | name = DECL_NAME (name); | |
7963 | ||
7964 | type_name = IDENTIFIER_POINTER (name); | |
7965 | } | |
7966 | else | |
7967 | type_name = "__unknown__"; | |
a9d38797 | 7968 | |
a3f97cbb JW |
7969 | switch (TREE_CODE (type)) |
7970 | { | |
a3f97cbb | 7971 | case INTEGER_TYPE: |
a9d38797 | 7972 | /* Carefully distinguish the C character types, without messing |
73c68f61 SS |
7973 | up if the language is not C. Note that we check only for the names |
7974 | that contain spaces; other names might occur by coincidence in other | |
7975 | languages. */ | |
a9d38797 JM |
7976 | if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE |
7977 | && (type == char_type_node | |
7978 | || ! strcmp (type_name, "signed char") | |
7979 | || ! strcmp (type_name, "unsigned char")))) | |
a3f97cbb | 7980 | { |
8df83eae | 7981 | if (TYPE_UNSIGNED (type)) |
a9d38797 JM |
7982 | encoding = DW_ATE_unsigned; |
7983 | else | |
7984 | encoding = DW_ATE_signed; | |
7985 | break; | |
a3f97cbb | 7986 | } |
556273e0 | 7987 | /* else fall through. */ |
a3f97cbb | 7988 | |
a9d38797 JM |
7989 | case CHAR_TYPE: |
7990 | /* GNU Pascal/Ada CHAR type. Not used in C. */ | |
8df83eae | 7991 | if (TYPE_UNSIGNED (type)) |
a9d38797 JM |
7992 | encoding = DW_ATE_unsigned_char; |
7993 | else | |
7994 | encoding = DW_ATE_signed_char; | |
a3f97cbb JW |
7995 | break; |
7996 | ||
7997 | case REAL_TYPE: | |
a9d38797 | 7998 | encoding = DW_ATE_float; |
a3f97cbb JW |
7999 | break; |
8000 | ||
405f63da MM |
8001 | /* Dwarf2 doesn't know anything about complex ints, so use |
8002 | a user defined type for it. */ | |
a3f97cbb | 8003 | case COMPLEX_TYPE: |
405f63da MM |
8004 | if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE) |
8005 | encoding = DW_ATE_complex_float; | |
8006 | else | |
8007 | encoding = DW_ATE_lo_user; | |
a3f97cbb JW |
8008 | break; |
8009 | ||
8010 | case BOOLEAN_TYPE: | |
a9d38797 JM |
8011 | /* GNU FORTRAN/Ada/C++ BOOLEAN type. */ |
8012 | encoding = DW_ATE_boolean; | |
a3f97cbb JW |
8013 | break; |
8014 | ||
8015 | default: | |
2ad9852d RK |
8016 | /* No other TREE_CODEs are Dwarf fundamental types. */ |
8017 | abort (); | |
a3f97cbb JW |
8018 | } |
8019 | ||
54ba1f0d | 8020 | base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type); |
14a774a9 RK |
8021 | if (demangle_name_func) |
8022 | type_name = (*demangle_name_func) (type_name); | |
8023 | ||
a9d38797 JM |
8024 | add_AT_string (base_type_result, DW_AT_name, type_name); |
8025 | add_AT_unsigned (base_type_result, DW_AT_byte_size, | |
4e5a8d7b | 8026 | int_size_in_bytes (type)); |
a9d38797 | 8027 | add_AT_unsigned (base_type_result, DW_AT_encoding, encoding); |
a3f97cbb JW |
8028 | |
8029 | return base_type_result; | |
8030 | } | |
8031 | ||
8032 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to | |
8033 | the Dwarf "root" type for the given input type. The Dwarf "root" type of | |
8034 | a given type is generally the same as the given type, except that if the | |
8035 | given type is a pointer or reference type, then the root type of the given | |
8036 | type is the root type of the "basis" type for the pointer or reference | |
8037 | type. (This definition of the "root" type is recursive.) Also, the root | |
8038 | type of a `const' qualified type or a `volatile' qualified type is the | |
8039 | root type of the given type without the qualifiers. */ | |
71dfc51f | 8040 | |
a3f97cbb | 8041 | static tree |
7080f735 | 8042 | root_type (tree type) |
a3f97cbb JW |
8043 | { |
8044 | if (TREE_CODE (type) == ERROR_MARK) | |
8045 | return error_mark_node; | |
8046 | ||
8047 | switch (TREE_CODE (type)) | |
8048 | { | |
8049 | case ERROR_MARK: | |
8050 | return error_mark_node; | |
8051 | ||
8052 | case POINTER_TYPE: | |
8053 | case REFERENCE_TYPE: | |
8054 | return type_main_variant (root_type (TREE_TYPE (type))); | |
8055 | ||
8056 | default: | |
8057 | return type_main_variant (type); | |
8058 | } | |
8059 | } | |
8060 | ||
cc2902df | 8061 | /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the |
a3f97cbb | 8062 | given input type is a Dwarf "fundamental" type. Otherwise return null. */ |
71dfc51f RK |
8063 | |
8064 | static inline int | |
7080f735 | 8065 | is_base_type (tree type) |
a3f97cbb JW |
8066 | { |
8067 | switch (TREE_CODE (type)) | |
8068 | { | |
8069 | case ERROR_MARK: | |
8070 | case VOID_TYPE: | |
8071 | case INTEGER_TYPE: | |
8072 | case REAL_TYPE: | |
8073 | case COMPLEX_TYPE: | |
8074 | case BOOLEAN_TYPE: | |
8075 | case CHAR_TYPE: | |
8076 | return 1; | |
8077 | ||
8078 | case SET_TYPE: | |
8079 | case ARRAY_TYPE: | |
8080 | case RECORD_TYPE: | |
8081 | case UNION_TYPE: | |
8082 | case QUAL_UNION_TYPE: | |
8083 | case ENUMERAL_TYPE: | |
8084 | case FUNCTION_TYPE: | |
8085 | case METHOD_TYPE: | |
8086 | case POINTER_TYPE: | |
8087 | case REFERENCE_TYPE: | |
8088 | case FILE_TYPE: | |
8089 | case OFFSET_TYPE: | |
8090 | case LANG_TYPE: | |
604bb87d | 8091 | case VECTOR_TYPE: |
a3f97cbb JW |
8092 | return 0; |
8093 | ||
8094 | default: | |
8095 | abort (); | |
8096 | } | |
71dfc51f | 8097 | |
a3f97cbb JW |
8098 | return 0; |
8099 | } | |
8100 | ||
4977bab6 ZW |
8101 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE |
8102 | node, return the size in bits for the type if it is a constant, or else | |
8103 | return the alignment for the type if the type's size is not constant, or | |
8104 | else return BITS_PER_WORD if the type actually turns out to be an | |
8105 | ERROR_MARK node. */ | |
8106 | ||
8107 | static inline unsigned HOST_WIDE_INT | |
7080f735 | 8108 | simple_type_size_in_bits (tree type) |
4977bab6 | 8109 | { |
4977bab6 ZW |
8110 | if (TREE_CODE (type) == ERROR_MARK) |
8111 | return BITS_PER_WORD; | |
8112 | else if (TYPE_SIZE (type) == NULL_TREE) | |
8113 | return 0; | |
8114 | else if (host_integerp (TYPE_SIZE (type), 1)) | |
8115 | return tree_low_cst (TYPE_SIZE (type), 1); | |
8116 | else | |
8117 | return TYPE_ALIGN (type); | |
8118 | } | |
8119 | ||
c3cdeef4 JB |
8120 | /* Return true if the debug information for the given type should be |
8121 | emitted as a subrange type. */ | |
8122 | ||
8123 | static inline bool | |
e7d23ce3 B |
8124 | is_subrange_type (tree type) |
8125 | { | |
de99511b B |
8126 | tree subtype = TREE_TYPE (type); |
8127 | ||
886de2d4 JB |
8128 | /* Subrange types are identified by the fact that they are integer |
8129 | types, and that they have a subtype which is either an integer type | |
8130 | or an enumeral type. */ | |
8131 | ||
8132 | if (TREE_CODE (type) != INTEGER_TYPE | |
8133 | || subtype == NULL_TREE) | |
8134 | return false; | |
8135 | ||
8136 | if (TREE_CODE (subtype) != INTEGER_TYPE | |
8137 | && TREE_CODE (subtype) != ENUMERAL_TYPE) | |
8138 | return false; | |
8139 | ||
d6672e91 JB |
8140 | if (TREE_CODE (type) == TREE_CODE (subtype) |
8141 | && int_size_in_bytes (type) == int_size_in_bytes (subtype) | |
8142 | && TYPE_MIN_VALUE (type) != NULL | |
8143 | && TYPE_MIN_VALUE (subtype) != NULL | |
8144 | && tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype)) | |
8145 | && TYPE_MAX_VALUE (type) != NULL | |
8146 | && TYPE_MAX_VALUE (subtype) != NULL | |
8147 | && tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype))) | |
8148 | { | |
8149 | /* The type and its subtype have the same representation. If in | |
8150 | addition the two types also have the same name, then the given | |
8151 | type is not a subrange type, but rather a plain base type. */ | |
8152 | /* FIXME: brobecker/2004-03-22: | |
8153 | Sizetype INTEGER_CSTs nodes are canonicalized. It should | |
8154 | therefore be sufficient to check the TYPE_SIZE node pointers | |
8155 | rather than checking the actual size. Unfortunately, we have | |
8156 | found some cases, such as in the Ada "integer" type, where | |
8157 | this is not the case. Until this problem is solved, we need to | |
8158 | keep checking the actual size. */ | |
8159 | tree type_name = TYPE_NAME (type); | |
8160 | tree subtype_name = TYPE_NAME (subtype); | |
8161 | ||
8162 | if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL) | |
8163 | type_name = DECL_NAME (type_name); | |
8164 | ||
8165 | if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL) | |
8166 | subtype_name = DECL_NAME (subtype_name); | |
8167 | ||
8168 | if (type_name == subtype_name) | |
8169 | return false; | |
8170 | } | |
8171 | ||
886de2d4 | 8172 | return true; |
c3cdeef4 JB |
8173 | } |
8174 | ||
8175 | /* Given a pointer to a tree node for a subrange type, return a pointer | |
8176 | to a DIE that describes the given type. */ | |
8177 | ||
8178 | static dw_die_ref | |
fbfd77b8 | 8179 | subrange_type_die (tree type, dw_die_ref context_die) |
c3cdeef4 JB |
8180 | { |
8181 | dw_die_ref subtype_die; | |
8182 | dw_die_ref subrange_die; | |
8183 | tree name = TYPE_NAME (type); | |
e7d23ce3 | 8184 | const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type); |
6582c808 | 8185 | tree subtype = TREE_TYPE (type); |
7080f735 | 8186 | |
fbfd77b8 JB |
8187 | if (context_die == NULL) |
8188 | context_die = comp_unit_die; | |
8189 | ||
6582c808 JB |
8190 | if (TREE_CODE (subtype) == ENUMERAL_TYPE) |
8191 | subtype_die = gen_enumeration_type_die (subtype, context_die); | |
de99511b | 8192 | else |
6582c808 | 8193 | subtype_die = base_type_die (subtype); |
c3cdeef4 | 8194 | |
fbfd77b8 | 8195 | subrange_die = new_die (DW_TAG_subrange_type, context_die, type); |
b98d154e B |
8196 | |
8197 | if (name != NULL) | |
8198 | { | |
8199 | if (TREE_CODE (name) == TYPE_DECL) | |
8200 | name = DECL_NAME (name); | |
8201 | add_name_attribute (subrange_die, IDENTIFIER_POINTER (name)); | |
8202 | } | |
8203 | ||
6582c808 | 8204 | if (int_size_in_bytes (subtype) != size_in_bytes) |
e7d23ce3 B |
8205 | { |
8206 | /* The size of the subrange type and its base type do not match, | |
8207 | so we need to generate a size attribute for the subrange type. */ | |
8208 | add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes); | |
8209 | } | |
8210 | ||
c3cdeef4 JB |
8211 | if (TYPE_MIN_VALUE (type) != NULL) |
8212 | add_bound_info (subrange_die, DW_AT_lower_bound, | |
8213 | TYPE_MIN_VALUE (type)); | |
8214 | if (TYPE_MAX_VALUE (type) != NULL) | |
8215 | add_bound_info (subrange_die, DW_AT_upper_bound, | |
8216 | TYPE_MAX_VALUE (type)); | |
8217 | add_AT_die_ref (subrange_die, DW_AT_type, subtype_die); | |
8218 | ||
8219 | return subrange_die; | |
8220 | } | |
8221 | ||
a3f97cbb JW |
8222 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging |
8223 | entry that chains various modifiers in front of the given type. */ | |
71dfc51f | 8224 | |
a3f97cbb | 8225 | static dw_die_ref |
7080f735 AJ |
8226 | modified_type_die (tree type, int is_const_type, int is_volatile_type, |
8227 | dw_die_ref context_die) | |
a3f97cbb | 8228 | { |
b3694847 SS |
8229 | enum tree_code code = TREE_CODE (type); |
8230 | dw_die_ref mod_type_die = NULL; | |
8231 | dw_die_ref sub_die = NULL; | |
8232 | tree item_type = NULL; | |
a3f97cbb JW |
8233 | |
8234 | if (code != ERROR_MARK) | |
8235 | { | |
5101b304 MM |
8236 | tree qualified_type; |
8237 | ||
8238 | /* See if we already have the appropriately qualified variant of | |
8239 | this type. */ | |
c26fbbca | 8240 | qualified_type |
5101b304 MM |
8241 | = get_qualified_type (type, |
8242 | ((is_const_type ? TYPE_QUAL_CONST : 0) | |
c26fbbca | 8243 | | (is_volatile_type |
5101b304 | 8244 | ? TYPE_QUAL_VOLATILE : 0))); |
2ad9852d | 8245 | |
5101b304 MM |
8246 | /* If we do, then we can just use its DIE, if it exists. */ |
8247 | if (qualified_type) | |
8248 | { | |
8249 | mod_type_die = lookup_type_die (qualified_type); | |
8250 | if (mod_type_die) | |
8251 | return mod_type_die; | |
8252 | } | |
bdb669cb | 8253 | |
556273e0 | 8254 | /* Handle C typedef types. */ |
c26fbbca | 8255 | if (qualified_type && TYPE_NAME (qualified_type) |
5101b304 MM |
8256 | && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL |
8257 | && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type))) | |
a94dbf2c | 8258 | { |
5101b304 MM |
8259 | tree type_name = TYPE_NAME (qualified_type); |
8260 | tree dtype = TREE_TYPE (type_name); | |
2ad9852d | 8261 | |
5101b304 | 8262 | if (qualified_type == dtype) |
a94dbf2c JM |
8263 | { |
8264 | /* For a named type, use the typedef. */ | |
5101b304 MM |
8265 | gen_type_die (qualified_type, context_die); |
8266 | mod_type_die = lookup_type_die (qualified_type); | |
a94dbf2c JM |
8267 | } |
8268 | else if (is_const_type < TYPE_READONLY (dtype) | |
8269 | || is_volatile_type < TYPE_VOLATILE (dtype)) | |
8270 | /* cv-unqualified version of named type. Just use the unnamed | |
8271 | type to which it refers. */ | |
71dfc51f | 8272 | mod_type_die |
5101b304 | 8273 | = modified_type_die (DECL_ORIGINAL_TYPE (type_name), |
71dfc51f RK |
8274 | is_const_type, is_volatile_type, |
8275 | context_die); | |
2ad9852d | 8276 | |
71dfc51f | 8277 | /* Else cv-qualified version of named type; fall through. */ |
a94dbf2c JM |
8278 | } |
8279 | ||
8280 | if (mod_type_die) | |
556273e0 KH |
8281 | /* OK. */ |
8282 | ; | |
a94dbf2c | 8283 | else if (is_const_type) |
a3f97cbb | 8284 | { |
54ba1f0d | 8285 | mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type); |
a9d38797 | 8286 | sub_die = modified_type_die (type, 0, is_volatile_type, context_die); |
a3f97cbb JW |
8287 | } |
8288 | else if (is_volatile_type) | |
8289 | { | |
54ba1f0d | 8290 | mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type); |
a9d38797 | 8291 | sub_die = modified_type_die (type, 0, 0, context_die); |
a3f97cbb JW |
8292 | } |
8293 | else if (code == POINTER_TYPE) | |
8294 | { | |
54ba1f0d | 8295 | mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type); |
4977bab6 ZW |
8296 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, |
8297 | simple_type_size_in_bits (type) / BITS_PER_UNIT); | |
61b32c02 | 8298 | #if 0 |
a3f97cbb | 8299 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
61b32c02 | 8300 | #endif |
a3f97cbb | 8301 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
8302 | } |
8303 | else if (code == REFERENCE_TYPE) | |
8304 | { | |
54ba1f0d | 8305 | mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type); |
4977bab6 ZW |
8306 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, |
8307 | simple_type_size_in_bits (type) / BITS_PER_UNIT); | |
61b32c02 | 8308 | #if 0 |
a3f97cbb | 8309 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
556273e0 | 8310 | #endif |
a3f97cbb | 8311 | item_type = TREE_TYPE (type); |
a3f97cbb | 8312 | } |
e7d23ce3 | 8313 | else if (is_subrange_type (type)) |
fbfd77b8 | 8314 | mod_type_die = subrange_type_die (type, context_die); |
a3f97cbb | 8315 | else if (is_base_type (type)) |
71dfc51f | 8316 | mod_type_die = base_type_die (type); |
a3f97cbb JW |
8317 | else |
8318 | { | |
4b674448 JM |
8319 | gen_type_die (type, context_die); |
8320 | ||
a3f97cbb JW |
8321 | /* We have to get the type_main_variant here (and pass that to the |
8322 | `lookup_type_die' routine) because the ..._TYPE node we have | |
8323 | might simply be a *copy* of some original type node (where the | |
8324 | copy was created to help us keep track of typedef names) and | |
8325 | that copy might have a different TYPE_UID from the original | |
a94dbf2c | 8326 | ..._TYPE node. */ |
0e98f924 AH |
8327 | if (TREE_CODE (type) != VECTOR_TYPE) |
8328 | mod_type_die = lookup_type_die (type_main_variant (type)); | |
8329 | else | |
8330 | /* Vectors have the debugging information in the type, | |
8331 | not the main variant. */ | |
8332 | mod_type_die = lookup_type_die (type); | |
3a88cbd1 JL |
8333 | if (mod_type_die == NULL) |
8334 | abort (); | |
a3f97cbb | 8335 | } |
3d2999ba MK |
8336 | |
8337 | /* We want to equate the qualified type to the die below. */ | |
8370aa3a | 8338 | type = qualified_type; |
a3f97cbb | 8339 | } |
71dfc51f | 8340 | |
8370aa3a RH |
8341 | if (type) |
8342 | equate_type_number_to_die (type, mod_type_die); | |
dfcf9891 | 8343 | if (item_type) |
71dfc51f RK |
8344 | /* We must do this after the equate_type_number_to_die call, in case |
8345 | this is a recursive type. This ensures that the modified_type_die | |
8346 | recursion will terminate even if the type is recursive. Recursive | |
8347 | types are possible in Ada. */ | |
8348 | sub_die = modified_type_die (item_type, | |
8349 | TYPE_READONLY (item_type), | |
8350 | TYPE_VOLATILE (item_type), | |
8351 | context_die); | |
8352 | ||
a3f97cbb | 8353 | if (sub_die != NULL) |
71dfc51f RK |
8354 | add_AT_die_ref (mod_type_die, DW_AT_type, sub_die); |
8355 | ||
a3f97cbb JW |
8356 | return mod_type_die; |
8357 | } | |
8358 | ||
a3f97cbb | 8359 | /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is |
6d2f8887 | 8360 | an enumerated type. */ |
71dfc51f RK |
8361 | |
8362 | static inline int | |
7080f735 | 8363 | type_is_enum (tree type) |
a3f97cbb JW |
8364 | { |
8365 | return TREE_CODE (type) == ENUMERAL_TYPE; | |
8366 | } | |
8367 | ||
23959f19 | 8368 | /* Return the DBX register number described by a given RTL node. */ |
7d9d8943 AM |
8369 | |
8370 | static unsigned int | |
23959f19 | 8371 | dbx_reg_number (rtx rtl) |
7d9d8943 | 8372 | { |
b3694847 | 8373 | unsigned regno = REGNO (rtl); |
7d9d8943 AM |
8374 | |
8375 | if (regno >= FIRST_PSEUDO_REGISTER) | |
e7af1d45 | 8376 | abort (); |
7d9d8943 | 8377 | |
e7af1d45 | 8378 | return DBX_REGISTER_NUMBER (regno); |
7d9d8943 AM |
8379 | } |
8380 | ||
e7af1d45 | 8381 | /* Return a location descriptor that designates a machine register or |
96714395 | 8382 | zero if there is none. */ |
71dfc51f | 8383 | |
a3f97cbb | 8384 | static dw_loc_descr_ref |
7080f735 | 8385 | reg_loc_descriptor (rtx rtl) |
a3f97cbb | 8386 | { |
d22c2324 | 8387 | unsigned reg; |
96714395 | 8388 | rtx regs; |
71dfc51f | 8389 | |
e7af1d45 RK |
8390 | if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER) |
8391 | return 0; | |
8392 | ||
23959f19 | 8393 | reg = dbx_reg_number (rtl); |
5fd9b178 | 8394 | regs = targetm.dwarf_register_span (rtl); |
96714395 | 8395 | |
23959f19 | 8396 | if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 |
96714395 AH |
8397 | || regs) |
8398 | return multiple_reg_loc_descriptor (rtl, regs); | |
8399 | else | |
8400 | return one_reg_loc_descriptor (reg); | |
8401 | } | |
8402 | ||
8403 | /* Return a location descriptor that designates a machine register for | |
8404 | a given hard register number. */ | |
8405 | ||
8406 | static dw_loc_descr_ref | |
7080f735 | 8407 | one_reg_loc_descriptor (unsigned int regno) |
96714395 AH |
8408 | { |
8409 | if (regno <= 31) | |
8410 | return new_loc_descr (DW_OP_reg0 + regno, 0, 0); | |
d22c2324 | 8411 | else |
96714395 AH |
8412 | return new_loc_descr (DW_OP_regx, regno, 0); |
8413 | } | |
8414 | ||
8415 | /* Given an RTL of a register, return a location descriptor that | |
8416 | designates a value that spans more than one register. */ | |
8417 | ||
8418 | static dw_loc_descr_ref | |
7080f735 | 8419 | multiple_reg_loc_descriptor (rtx rtl, rtx regs) |
96714395 AH |
8420 | { |
8421 | int nregs, size, i; | |
8422 | unsigned reg; | |
8423 | dw_loc_descr_ref loc_result = NULL; | |
71dfc51f | 8424 | |
23959f19 JDA |
8425 | reg = dbx_reg_number (rtl); |
8426 | nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)]; | |
96714395 AH |
8427 | |
8428 | /* Simple, contiguous registers. */ | |
8429 | if (regs == NULL_RTX) | |
8430 | { | |
8431 | size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs; | |
8432 | ||
8433 | loc_result = NULL; | |
8434 | while (nregs--) | |
8435 | { | |
8436 | dw_loc_descr_ref t; | |
8437 | ||
96714395 AH |
8438 | t = one_reg_loc_descriptor (reg); |
8439 | add_loc_descr (&loc_result, t); | |
8440 | add_loc_descr (&loc_result, new_loc_descr (DW_OP_piece, size, 0)); | |
31ca3635 | 8441 | ++reg; |
96714395 AH |
8442 | } |
8443 | return loc_result; | |
8444 | } | |
8445 | ||
8446 | /* Now onto stupid register sets in non contiguous locations. */ | |
8447 | ||
8448 | if (GET_CODE (regs) != PARALLEL) | |
8449 | abort (); | |
8450 | ||
8451 | size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0))); | |
8452 | loc_result = NULL; | |
8453 | ||
8454 | for (i = 0; i < XVECLEN (regs, 0); ++i) | |
8455 | { | |
8456 | dw_loc_descr_ref t; | |
8457 | ||
8458 | t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i))); | |
8459 | add_loc_descr (&loc_result, t); | |
8460 | size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0))); | |
8461 | add_loc_descr (&loc_result, new_loc_descr (DW_OP_piece, size, 0)); | |
8462 | } | |
a3f97cbb JW |
8463 | return loc_result; |
8464 | } | |
8465 | ||
d8041cc8 RH |
8466 | /* Return a location descriptor that designates a constant. */ |
8467 | ||
8468 | static dw_loc_descr_ref | |
7080f735 | 8469 | int_loc_descriptor (HOST_WIDE_INT i) |
d8041cc8 RH |
8470 | { |
8471 | enum dwarf_location_atom op; | |
8472 | ||
8473 | /* Pick the smallest representation of a constant, rather than just | |
8474 | defaulting to the LEB encoding. */ | |
8475 | if (i >= 0) | |
8476 | { | |
8477 | if (i <= 31) | |
8478 | op = DW_OP_lit0 + i; | |
8479 | else if (i <= 0xff) | |
8480 | op = DW_OP_const1u; | |
8481 | else if (i <= 0xffff) | |
8482 | op = DW_OP_const2u; | |
8483 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
8484 | || i <= 0xffffffff) | |
8485 | op = DW_OP_const4u; | |
8486 | else | |
8487 | op = DW_OP_constu; | |
8488 | } | |
8489 | else | |
8490 | { | |
8491 | if (i >= -0x80) | |
8492 | op = DW_OP_const1s; | |
8493 | else if (i >= -0x8000) | |
8494 | op = DW_OP_const2s; | |
8495 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
8496 | || i >= -0x80000000) | |
8497 | op = DW_OP_const4s; | |
8498 | else | |
8499 | op = DW_OP_consts; | |
8500 | } | |
8501 | ||
8502 | return new_loc_descr (op, i, 0); | |
8503 | } | |
8504 | ||
a3f97cbb | 8505 | /* Return a location descriptor that designates a base+offset location. */ |
71dfc51f | 8506 | |
a3f97cbb | 8507 | static dw_loc_descr_ref |
0a2d3d69 | 8508 | based_loc_descr (unsigned int reg, HOST_WIDE_INT offset, bool can_use_fbreg) |
a3f97cbb | 8509 | { |
b3694847 | 8510 | dw_loc_descr_ref loc_result; |
810429b7 JM |
8511 | /* For the "frame base", we use the frame pointer or stack pointer |
8512 | registers, since the RTL for local variables is relative to one of | |
8513 | them. */ | |
b3694847 SS |
8514 | unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed |
8515 | ? HARD_FRAME_POINTER_REGNUM | |
8516 | : STACK_POINTER_REGNUM); | |
71dfc51f | 8517 | |
0a2d3d69 | 8518 | if (reg == fp_reg && can_use_fbreg) |
71dfc51f | 8519 | loc_result = new_loc_descr (DW_OP_fbreg, offset, 0); |
85066503 | 8520 | else if (reg <= 31) |
71dfc51f | 8521 | loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0); |
a3f97cbb | 8522 | else |
71dfc51f RK |
8523 | loc_result = new_loc_descr (DW_OP_bregx, reg, offset); |
8524 | ||
a3f97cbb JW |
8525 | return loc_result; |
8526 | } | |
8527 | ||
8528 | /* Return true if this RTL expression describes a base+offset calculation. */ | |
71dfc51f RK |
8529 | |
8530 | static inline int | |
7080f735 | 8531 | is_based_loc (rtx rtl) |
a3f97cbb | 8532 | { |
173bf5be | 8533 | return (GET_CODE (rtl) == PLUS |
f8cfc6aa | 8534 | && ((REG_P (XEXP (rtl, 0)) |
173bf5be KH |
8535 | && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER |
8536 | && GET_CODE (XEXP (rtl, 1)) == CONST_INT))); | |
a3f97cbb JW |
8537 | } |
8538 | ||
8539 | /* The following routine converts the RTL for a variable or parameter | |
8540 | (resident in memory) into an equivalent Dwarf representation of a | |
8541 | mechanism for getting the address of that same variable onto the top of a | |
8542 | hypothetical "address evaluation" stack. | |
71dfc51f | 8543 | |
a3f97cbb JW |
8544 | When creating memory location descriptors, we are effectively transforming |
8545 | the RTL for a memory-resident object into its Dwarf postfix expression | |
8546 | equivalent. This routine recursively descends an RTL tree, turning | |
e60d4d7b JL |
8547 | it into Dwarf postfix code as it goes. |
8548 | ||
8549 | MODE is the mode of the memory reference, needed to handle some | |
e7af1d45 RK |
8550 | autoincrement addressing modes. |
8551 | ||
0a2d3d69 DB |
8552 | CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the location |
8553 | list for RTL. We can't use it when we are emitting location list for | |
8554 | virtual variable frame_base_decl (i.e. a location list for DW_AT_frame_base) | |
8555 | which describes how frame base changes when !frame_pointer_needed. | |
8556 | ||
e7af1d45 | 8557 | Return 0 if we can't represent the location. */ |
71dfc51f | 8558 | |
a3f97cbb | 8559 | static dw_loc_descr_ref |
0a2d3d69 | 8560 | mem_loc_descriptor (rtx rtl, enum machine_mode mode, bool can_use_fbreg) |
a3f97cbb JW |
8561 | { |
8562 | dw_loc_descr_ref mem_loc_result = NULL; | |
40f0b3ee | 8563 | enum dwarf_location_atom op; |
e7af1d45 | 8564 | |
556273e0 | 8565 | /* Note that for a dynamically sized array, the location we will generate a |
a3f97cbb JW |
8566 | description of here will be the lowest numbered location which is |
8567 | actually within the array. That's *not* necessarily the same as the | |
8568 | zeroth element of the array. */ | |
71dfc51f | 8569 | |
5fd9b178 | 8570 | rtl = targetm.delegitimize_address (rtl); |
1865dbb5 | 8571 | |
a3f97cbb JW |
8572 | switch (GET_CODE (rtl)) |
8573 | { | |
e60d4d7b JL |
8574 | case POST_INC: |
8575 | case POST_DEC: | |
e2134eea | 8576 | case POST_MODIFY: |
e60d4d7b JL |
8577 | /* POST_INC and POST_DEC can be handled just like a SUBREG. So we |
8578 | just fall into the SUBREG code. */ | |
8579 | ||
2ad9852d | 8580 | /* ... fall through ... */ |
e60d4d7b | 8581 | |
a3f97cbb JW |
8582 | case SUBREG: |
8583 | /* The case of a subreg may arise when we have a local (register) | |
73c68f61 SS |
8584 | variable or a formal (register) parameter which doesn't quite fill |
8585 | up an entire register. For now, just assume that it is | |
8586 | legitimate to make the Dwarf info refer to the whole register which | |
8587 | contains the given subreg. */ | |
ddef6bc7 | 8588 | rtl = SUBREG_REG (rtl); |
71dfc51f | 8589 | |
2ad9852d | 8590 | /* ... fall through ... */ |
a3f97cbb JW |
8591 | |
8592 | case REG: | |
8593 | /* Whenever a register number forms a part of the description of the | |
73c68f61 SS |
8594 | method for calculating the (dynamic) address of a memory resident |
8595 | object, DWARF rules require the register number be referred to as | |
8596 | a "base register". This distinction is not based in any way upon | |
8597 | what category of register the hardware believes the given register | |
8598 | belongs to. This is strictly DWARF terminology we're dealing with | |
8599 | here. Note that in cases where the location of a memory-resident | |
8600 | data object could be expressed as: OP_ADD (OP_BASEREG (basereg), | |
8601 | OP_CONST (0)) the actual DWARF location descriptor that we generate | |
8602 | may just be OP_BASEREG (basereg). This may look deceptively like | |
8603 | the object in question was allocated to a register (rather than in | |
8604 | memory) so DWARF consumers need to be aware of the subtle | |
8605 | distinction between OP_REG and OP_BASEREG. */ | |
e7af1d45 | 8606 | if (REGNO (rtl) < FIRST_PSEUDO_REGISTER) |
23959f19 JDA |
8607 | mem_loc_result = based_loc_descr (dbx_reg_number (rtl), 0, |
8608 | can_use_fbreg); | |
a3f97cbb JW |
8609 | break; |
8610 | ||
8611 | case MEM: | |
0a2d3d69 DB |
8612 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl), |
8613 | can_use_fbreg); | |
e7af1d45 RK |
8614 | if (mem_loc_result != 0) |
8615 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0)); | |
a3f97cbb JW |
8616 | break; |
8617 | ||
1ce324c3 EB |
8618 | case LO_SUM: |
8619 | rtl = XEXP (rtl, 1); | |
8620 | ||
8621 | /* ... fall through ... */ | |
8622 | ||
d8041cc8 RH |
8623 | case LABEL_REF: |
8624 | /* Some ports can transform a symbol ref into a label ref, because | |
7080f735 AJ |
8625 | the symbol ref is too far away and has to be dumped into a constant |
8626 | pool. */ | |
a3f97cbb JW |
8627 | case CONST: |
8628 | case SYMBOL_REF: | |
6331d1c1 | 8629 | /* Alternatively, the symbol in the constant pool might be referenced |
c6f9b9a1 | 8630 | by a different symbol. */ |
2ad9852d | 8631 | if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl)) |
79cdfa4b | 8632 | { |
149d6f9e JJ |
8633 | bool marked; |
8634 | rtx tmp = get_pool_constant_mark (rtl, &marked); | |
2ad9852d | 8635 | |
6331d1c1 | 8636 | if (GET_CODE (tmp) == SYMBOL_REF) |
149d6f9e JJ |
8637 | { |
8638 | rtl = tmp; | |
8639 | if (CONSTANT_POOL_ADDRESS_P (tmp)) | |
8640 | get_pool_constant_mark (tmp, &marked); | |
8641 | else | |
8642 | marked = true; | |
8643 | } | |
8644 | ||
8645 | /* If all references to this pool constant were optimized away, | |
8646 | it was not output and thus we can't represent it. | |
8647 | FIXME: might try to use DW_OP_const_value here, though | |
8648 | DW_OP_piece complicates it. */ | |
8649 | if (!marked) | |
8650 | return 0; | |
79cdfa4b TM |
8651 | } |
8652 | ||
a3f97cbb JW |
8653 | mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0); |
8654 | mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
c470afad RK |
8655 | mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl; |
8656 | VARRAY_PUSH_RTX (used_rtx_varray, rtl); | |
a3f97cbb JW |
8657 | break; |
8658 | ||
e2134eea JH |
8659 | case PRE_MODIFY: |
8660 | /* Extract the PLUS expression nested inside and fall into | |
73c68f61 | 8661 | PLUS code below. */ |
e2134eea JH |
8662 | rtl = XEXP (rtl, 1); |
8663 | goto plus; | |
8664 | ||
e60d4d7b JL |
8665 | case PRE_INC: |
8666 | case PRE_DEC: | |
8667 | /* Turn these into a PLUS expression and fall into the PLUS code | |
8668 | below. */ | |
8669 | rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0), | |
8670 | GEN_INT (GET_CODE (rtl) == PRE_INC | |
556273e0 KH |
8671 | ? GET_MODE_UNIT_SIZE (mode) |
8672 | : -GET_MODE_UNIT_SIZE (mode))); | |
8673 | ||
2ad9852d | 8674 | /* ... fall through ... */ |
e60d4d7b | 8675 | |
a3f97cbb | 8676 | case PLUS: |
e2134eea | 8677 | plus: |
a3f97cbb | 8678 | if (is_based_loc (rtl)) |
23959f19 | 8679 | mem_loc_result = based_loc_descr (dbx_reg_number (XEXP (rtl, 0)), |
0a2d3d69 DB |
8680 | INTVAL (XEXP (rtl, 1)), |
8681 | can_use_fbreg); | |
a3f97cbb JW |
8682 | else |
8683 | { | |
0a2d3d69 DB |
8684 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, |
8685 | can_use_fbreg); | |
e7af1d45 RK |
8686 | if (mem_loc_result == 0) |
8687 | break; | |
d8041cc8 RH |
8688 | |
8689 | if (GET_CODE (XEXP (rtl, 1)) == CONST_INT | |
8690 | && INTVAL (XEXP (rtl, 1)) >= 0) | |
e7af1d45 RK |
8691 | add_loc_descr (&mem_loc_result, |
8692 | new_loc_descr (DW_OP_plus_uconst, | |
8693 | INTVAL (XEXP (rtl, 1)), 0)); | |
d8041cc8 RH |
8694 | else |
8695 | { | |
8696 | add_loc_descr (&mem_loc_result, | |
0a2d3d69 DB |
8697 | mem_loc_descriptor (XEXP (rtl, 1), mode, |
8698 | can_use_fbreg)); | |
d8041cc8 RH |
8699 | add_loc_descr (&mem_loc_result, |
8700 | new_loc_descr (DW_OP_plus, 0, 0)); | |
8701 | } | |
a3f97cbb JW |
8702 | } |
8703 | break; | |
8704 | ||
40f0b3ee PB |
8705 | /* If a pseudo-reg is optimized away, it is possible for it to |
8706 | be replaced with a MEM containing a multiply or shift. */ | |
dd2478ae | 8707 | case MULT: |
40f0b3ee PB |
8708 | op = DW_OP_mul; |
8709 | goto do_binop; | |
8710 | ||
8711 | case ASHIFT: | |
8712 | op = DW_OP_shl; | |
8713 | goto do_binop; | |
8714 | ||
8715 | case ASHIFTRT: | |
8716 | op = DW_OP_shra; | |
8717 | goto do_binop; | |
8718 | ||
8719 | case LSHIFTRT: | |
8720 | op = DW_OP_shr; | |
8721 | goto do_binop; | |
8722 | ||
8723 | do_binop: | |
e7af1d45 | 8724 | { |
0a2d3d69 DB |
8725 | dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, |
8726 | can_use_fbreg); | |
8727 | dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, | |
8728 | can_use_fbreg); | |
e7af1d45 RK |
8729 | |
8730 | if (op0 == 0 || op1 == 0) | |
8731 | break; | |
8732 | ||
8733 | mem_loc_result = op0; | |
8734 | add_loc_descr (&mem_loc_result, op1); | |
40f0b3ee | 8735 | add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0)); |
e7af1d45 RK |
8736 | break; |
8737 | } | |
dd2478ae | 8738 | |
a3f97cbb | 8739 | case CONST_INT: |
d8041cc8 | 8740 | mem_loc_result = int_loc_descriptor (INTVAL (rtl)); |
a3f97cbb JW |
8741 | break; |
8742 | ||
8743 | default: | |
8744 | abort (); | |
8745 | } | |
71dfc51f | 8746 | |
a3f97cbb JW |
8747 | return mem_loc_result; |
8748 | } | |
8749 | ||
956d6950 | 8750 | /* Return a descriptor that describes the concatenation of two locations. |
4401bf24 JL |
8751 | This is typically a complex variable. */ |
8752 | ||
8753 | static dw_loc_descr_ref | |
7080f735 | 8754 | concat_loc_descriptor (rtx x0, rtx x1) |
4401bf24 JL |
8755 | { |
8756 | dw_loc_descr_ref cc_loc_result = NULL; | |
0a2d3d69 DB |
8757 | dw_loc_descr_ref x0_ref = loc_descriptor (x0, true); |
8758 | dw_loc_descr_ref x1_ref = loc_descriptor (x1, true); | |
4401bf24 | 8759 | |
e7af1d45 RK |
8760 | if (x0_ref == 0 || x1_ref == 0) |
8761 | return 0; | |
8762 | ||
8763 | cc_loc_result = x0_ref; | |
4401bf24 | 8764 | add_loc_descr (&cc_loc_result, |
e7af1d45 RK |
8765 | new_loc_descr (DW_OP_piece, |
8766 | GET_MODE_SIZE (GET_MODE (x0)), 0)); | |
4401bf24 | 8767 | |
e7af1d45 | 8768 | add_loc_descr (&cc_loc_result, x1_ref); |
4401bf24 | 8769 | add_loc_descr (&cc_loc_result, |
e7af1d45 RK |
8770 | new_loc_descr (DW_OP_piece, |
8771 | GET_MODE_SIZE (GET_MODE (x1)), 0)); | |
4401bf24 JL |
8772 | |
8773 | return cc_loc_result; | |
8774 | } | |
8775 | ||
a3f97cbb JW |
8776 | /* Output a proper Dwarf location descriptor for a variable or parameter |
8777 | which is either allocated in a register or in a memory location. For a | |
8778 | register, we just generate an OP_REG and the register number. For a | |
8779 | memory location we provide a Dwarf postfix expression describing how to | |
e7af1d45 RK |
8780 | generate the (dynamic) address of the object onto the address stack. |
8781 | ||
8782 | If we don't know how to describe it, return 0. */ | |
71dfc51f | 8783 | |
a3f97cbb | 8784 | static dw_loc_descr_ref |
0a2d3d69 | 8785 | loc_descriptor (rtx rtl, bool can_use_fbreg) |
a3f97cbb JW |
8786 | { |
8787 | dw_loc_descr_ref loc_result = NULL; | |
e7af1d45 | 8788 | |
a3f97cbb JW |
8789 | switch (GET_CODE (rtl)) |
8790 | { | |
8791 | case SUBREG: | |
a3f97cbb | 8792 | /* The case of a subreg may arise when we have a local (register) |
73c68f61 SS |
8793 | variable or a formal (register) parameter which doesn't quite fill |
8794 | up an entire register. For now, just assume that it is | |
8795 | legitimate to make the Dwarf info refer to the whole register which | |
8796 | contains the given subreg. */ | |
ddef6bc7 | 8797 | rtl = SUBREG_REG (rtl); |
71dfc51f | 8798 | |
2ad9852d | 8799 | /* ... fall through ... */ |
a3f97cbb JW |
8800 | |
8801 | case REG: | |
5c90448c | 8802 | loc_result = reg_loc_descriptor (rtl); |
a3f97cbb JW |
8803 | break; |
8804 | ||
8805 | case MEM: | |
0a2d3d69 DB |
8806 | loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl), |
8807 | can_use_fbreg); | |
a3f97cbb JW |
8808 | break; |
8809 | ||
4401bf24 JL |
8810 | case CONCAT: |
8811 | loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1)); | |
8812 | break; | |
8813 | ||
0a2d3d69 DB |
8814 | case VAR_LOCATION: |
8815 | /* Single part. */ | |
8816 | if (GET_CODE (XEXP (rtl, 1)) != PARALLEL) | |
8817 | { | |
8818 | loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), can_use_fbreg); | |
8819 | } | |
8820 | /* Multiple parts. */ | |
8821 | else | |
8822 | { | |
8823 | rtvec par_elems = XVEC (XEXP (rtl, 1), 0); | |
8824 | int num_elem = GET_NUM_ELEM (par_elems); | |
8825 | enum machine_mode mode; | |
8826 | int i; | |
8827 | ||
8828 | /* Create the first one, so we have something to add to. */ | |
8829 | loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0), | |
8830 | can_use_fbreg); | |
8831 | mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0)); | |
8832 | add_loc_descr (&loc_result, | |
8833 | new_loc_descr (DW_OP_piece, GET_MODE_SIZE (mode), 0)); | |
8834 | for (i = 1; i < num_elem; i++) | |
8835 | { | |
8836 | dw_loc_descr_ref temp; | |
8837 | ||
8838 | temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0), | |
8839 | can_use_fbreg); | |
8840 | add_loc_descr (&loc_result, temp); | |
8841 | mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0)); | |
8842 | add_loc_descr (&loc_result, | |
8843 | new_loc_descr (DW_OP_piece, | |
8844 | GET_MODE_SIZE (mode), 0)); | |
8845 | } | |
8846 | } | |
8847 | break; | |
8848 | ||
a3f97cbb | 8849 | default: |
71dfc51f | 8850 | abort (); |
a3f97cbb | 8851 | } |
71dfc51f | 8852 | |
a3f97cbb JW |
8853 | return loc_result; |
8854 | } | |
8855 | ||
2ad9852d RK |
8856 | /* Similar, but generate the descriptor from trees instead of rtl. This comes |
8857 | up particularly with variable length arrays. If ADDRESSP is nonzero, we are | |
8858 | looking for an address. Otherwise, we return a value. If we can't make a | |
8859 | descriptor, return 0. */ | |
d8041cc8 RH |
8860 | |
8861 | static dw_loc_descr_ref | |
7080f735 | 8862 | loc_descriptor_from_tree (tree loc, int addressp) |
d8041cc8 | 8863 | { |
e7af1d45 RK |
8864 | dw_loc_descr_ref ret, ret1; |
8865 | int indirect_p = 0; | |
8df83eae | 8866 | int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc)); |
d8041cc8 RH |
8867 | enum dwarf_location_atom op; |
8868 | ||
8869 | /* ??? Most of the time we do not take proper care for sign/zero | |
8870 | extending the values properly. Hopefully this won't be a real | |
8871 | problem... */ | |
8872 | ||
8873 | switch (TREE_CODE (loc)) | |
8874 | { | |
8875 | case ERROR_MARK: | |
e7af1d45 | 8876 | return 0; |
d8041cc8 | 8877 | |
e7af1d45 | 8878 | case PLACEHOLDER_EXPR: |
b4ae5201 RK |
8879 | /* This case involves extracting fields from an object to determine the |
8880 | position of other fields. We don't try to encode this here. The | |
8881 | only user of this is Ada, which encodes the needed information using | |
8882 | the names of types. */ | |
e7af1d45 | 8883 | return 0; |
b4ae5201 | 8884 | |
aea9695c RK |
8885 | case CALL_EXPR: |
8886 | return 0; | |
8887 | ||
4ada538b MM |
8888 | case PREINCREMENT_EXPR: |
8889 | case PREDECREMENT_EXPR: | |
8890 | case POSTINCREMENT_EXPR: | |
8891 | case POSTDECREMENT_EXPR: | |
8892 | /* There are no opcodes for these operations. */ | |
8893 | return 0; | |
8894 | ||
aea9695c RK |
8895 | case ADDR_EXPR: |
8896 | /* We can support this only if we can look through conversions and | |
8897 | find an INDIRECT_EXPR. */ | |
8898 | for (loc = TREE_OPERAND (loc, 0); | |
8899 | TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR | |
8900 | || TREE_CODE (loc) == NON_LVALUE_EXPR | |
8901 | || TREE_CODE (loc) == VIEW_CONVERT_EXPR | |
8902 | || TREE_CODE (loc) == SAVE_EXPR; | |
8903 | loc = TREE_OPERAND (loc, 0)) | |
8904 | ; | |
8905 | ||
8906 | return (TREE_CODE (loc) == INDIRECT_REF | |
8907 | ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp) | |
8908 | : 0); | |
8909 | ||
d8041cc8 | 8910 | case VAR_DECL: |
b9203463 RH |
8911 | if (DECL_THREAD_LOCAL (loc)) |
8912 | { | |
8913 | rtx rtl; | |
8914 | ||
8915 | #ifndef ASM_OUTPUT_DWARF_DTPREL | |
8916 | /* If this is not defined, we have no way to emit the data. */ | |
8917 | return 0; | |
8918 | #endif | |
8919 | ||
8920 | /* The way DW_OP_GNU_push_tls_address is specified, we can only | |
8921 | look up addresses of objects in the current module. */ | |
3c655f42 | 8922 | if (DECL_EXTERNAL (loc)) |
b9203463 RH |
8923 | return 0; |
8924 | ||
8925 | rtl = rtl_for_decl_location (loc); | |
8926 | if (rtl == NULL_RTX) | |
8927 | return 0; | |
8928 | ||
3c0cb5de | 8929 | if (!MEM_P (rtl)) |
b9203463 RH |
8930 | return 0; |
8931 | rtl = XEXP (rtl, 0); | |
8932 | if (! CONSTANT_P (rtl)) | |
8933 | return 0; | |
8934 | ||
8935 | ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0); | |
8936 | ret->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
8937 | ret->dw_loc_oprnd1.v.val_addr = rtl; | |
8938 | ||
8939 | ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0); | |
8940 | add_loc_descr (&ret, ret1); | |
8941 | ||
8942 | indirect_p = 1; | |
8943 | break; | |
8944 | } | |
5d3cc252 | 8945 | /* Fall through. */ |
b9203463 | 8946 | |
d8041cc8 | 8947 | case PARM_DECL: |
6de9cd9a | 8948 | case RESULT_DECL: |
d8041cc8 RH |
8949 | { |
8950 | rtx rtl = rtl_for_decl_location (loc); | |
d8041cc8 | 8951 | |
a97c9600 | 8952 | if (rtl == NULL_RTX) |
e7af1d45 | 8953 | return 0; |
a97c9600 | 8954 | else if (CONSTANT_P (rtl)) |
d8041cc8 RH |
8955 | { |
8956 | ret = new_loc_descr (DW_OP_addr, 0, 0); | |
8957 | ret->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
8958 | ret->dw_loc_oprnd1.v.val_addr = rtl; | |
e7af1d45 | 8959 | indirect_p = 1; |
d8041cc8 RH |
8960 | } |
8961 | else | |
8962 | { | |
c28abdf0 RH |
8963 | enum machine_mode mode = GET_MODE (rtl); |
8964 | ||
3c0cb5de | 8965 | if (MEM_P (rtl)) |
d8041cc8 | 8966 | { |
e7af1d45 | 8967 | indirect_p = 1; |
d8041cc8 RH |
8968 | rtl = XEXP (rtl, 0); |
8969 | } | |
2ad9852d | 8970 | |
0a2d3d69 | 8971 | ret = mem_loc_descriptor (rtl, mode, true); |
d8041cc8 RH |
8972 | } |
8973 | } | |
8974 | break; | |
8975 | ||
8976 | case INDIRECT_REF: | |
8977 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 | 8978 | indirect_p = 1; |
d8041cc8 RH |
8979 | break; |
8980 | ||
749552c4 RK |
8981 | case COMPOUND_EXPR: |
8982 | return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp); | |
8983 | ||
ed972b14 RK |
8984 | case NOP_EXPR: |
8985 | case CONVERT_EXPR: | |
8986 | case NON_LVALUE_EXPR: | |
ed239f5a | 8987 | case VIEW_CONVERT_EXPR: |
b4ae5201 | 8988 | case SAVE_EXPR: |
032cb602 | 8989 | case MODIFY_EXPR: |
ed972b14 | 8990 | return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp); |
e57cabac | 8991 | |
d8041cc8 RH |
8992 | case COMPONENT_REF: |
8993 | case BIT_FIELD_REF: | |
8994 | case ARRAY_REF: | |
b4e3fabb | 8995 | case ARRAY_RANGE_REF: |
d8041cc8 RH |
8996 | { |
8997 | tree obj, offset; | |
8998 | HOST_WIDE_INT bitsize, bitpos, bytepos; | |
8999 | enum machine_mode mode; | |
9000 | int volatilep; | |
d8041cc8 RH |
9001 | |
9002 | obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode, | |
a06ef755 | 9003 | &unsignedp, &volatilep); |
e7af1d45 RK |
9004 | |
9005 | if (obj == loc) | |
9006 | return 0; | |
9007 | ||
d8041cc8 | 9008 | ret = loc_descriptor_from_tree (obj, 1); |
e7af1d45 | 9009 | if (ret == 0 |
2ad9852d | 9010 | || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0) |
e7af1d45 | 9011 | return 0; |
d8041cc8 RH |
9012 | |
9013 | if (offset != NULL_TREE) | |
9014 | { | |
9015 | /* Variable offset. */ | |
9016 | add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0)); | |
9017 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
9018 | } | |
9019 | ||
e7af1d45 RK |
9020 | if (!addressp) |
9021 | indirect_p = 1; | |
d8041cc8 RH |
9022 | |
9023 | bytepos = bitpos / BITS_PER_UNIT; | |
9024 | if (bytepos > 0) | |
9025 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0)); | |
9026 | else if (bytepos < 0) | |
9027 | { | |
9028 | add_loc_descr (&ret, int_loc_descriptor (bytepos)); | |
9029 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
9030 | } | |
9031 | break; | |
9032 | } | |
9033 | ||
9034 | case INTEGER_CST: | |
9035 | if (host_integerp (loc, 0)) | |
9036 | ret = int_loc_descriptor (tree_low_cst (loc, 0)); | |
e7af1d45 RK |
9037 | else |
9038 | return 0; | |
d8041cc8 | 9039 | break; |
d8041cc8 | 9040 | |
c67b2a58 RK |
9041 | case CONSTRUCTOR: |
9042 | { | |
75c20980 RH |
9043 | /* Get an RTL for this, if something has been emitted. */ |
9044 | rtx rtl = lookup_constant_def (loc); | |
9045 | enum machine_mode mode; | |
9046 | ||
3c0cb5de | 9047 | if (!MEM_P (rtl)) |
75c20980 RH |
9048 | return 0; |
9049 | mode = GET_MODE (rtl); | |
9050 | rtl = XEXP (rtl, 0); | |
9051 | ||
5fd9b178 | 9052 | rtl = targetm.delegitimize_address (rtl); |
75c20980 | 9053 | |
c67b2a58 | 9054 | indirect_p = 1; |
0a2d3d69 | 9055 | ret = mem_loc_descriptor (rtl, mode, true); |
c67b2a58 RK |
9056 | break; |
9057 | } | |
9058 | ||
c26fbbca | 9059 | case TRUTH_AND_EXPR: |
9702143f | 9060 | case TRUTH_ANDIF_EXPR: |
d8041cc8 RH |
9061 | case BIT_AND_EXPR: |
9062 | op = DW_OP_and; | |
9063 | goto do_binop; | |
e7af1d45 | 9064 | |
9702143f | 9065 | case TRUTH_XOR_EXPR: |
d8041cc8 RH |
9066 | case BIT_XOR_EXPR: |
9067 | op = DW_OP_xor; | |
9068 | goto do_binop; | |
e7af1d45 | 9069 | |
9702143f RK |
9070 | case TRUTH_OR_EXPR: |
9071 | case TRUTH_ORIF_EXPR: | |
d8041cc8 RH |
9072 | case BIT_IOR_EXPR: |
9073 | op = DW_OP_or; | |
9074 | goto do_binop; | |
e7af1d45 | 9075 | |
8dcea3f3 VC |
9076 | case FLOOR_DIV_EXPR: |
9077 | case CEIL_DIV_EXPR: | |
9078 | case ROUND_DIV_EXPR: | |
d8041cc8 RH |
9079 | case TRUNC_DIV_EXPR: |
9080 | op = DW_OP_div; | |
9081 | goto do_binop; | |
e7af1d45 | 9082 | |
d8041cc8 RH |
9083 | case MINUS_EXPR: |
9084 | op = DW_OP_minus; | |
9085 | goto do_binop; | |
e7af1d45 | 9086 | |
8dcea3f3 VC |
9087 | case FLOOR_MOD_EXPR: |
9088 | case CEIL_MOD_EXPR: | |
9089 | case ROUND_MOD_EXPR: | |
d8041cc8 RH |
9090 | case TRUNC_MOD_EXPR: |
9091 | op = DW_OP_mod; | |
9092 | goto do_binop; | |
e7af1d45 | 9093 | |
d8041cc8 RH |
9094 | case MULT_EXPR: |
9095 | op = DW_OP_mul; | |
9096 | goto do_binop; | |
e7af1d45 | 9097 | |
d8041cc8 RH |
9098 | case LSHIFT_EXPR: |
9099 | op = DW_OP_shl; | |
9100 | goto do_binop; | |
e7af1d45 | 9101 | |
d8041cc8 RH |
9102 | case RSHIFT_EXPR: |
9103 | op = (unsignedp ? DW_OP_shr : DW_OP_shra); | |
9104 | goto do_binop; | |
e7af1d45 | 9105 | |
d8041cc8 RH |
9106 | case PLUS_EXPR: |
9107 | if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST | |
9108 | && host_integerp (TREE_OPERAND (loc, 1), 0)) | |
9109 | { | |
9110 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
9111 | if (ret == 0) |
9112 | return 0; | |
9113 | ||
d8041cc8 RH |
9114 | add_loc_descr (&ret, |
9115 | new_loc_descr (DW_OP_plus_uconst, | |
9116 | tree_low_cst (TREE_OPERAND (loc, 1), | |
9117 | 0), | |
9118 | 0)); | |
9119 | break; | |
9120 | } | |
e7af1d45 | 9121 | |
d8041cc8 RH |
9122 | op = DW_OP_plus; |
9123 | goto do_binop; | |
2ad9852d | 9124 | |
d8041cc8 | 9125 | case LE_EXPR: |
8df83eae | 9126 | if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) |
e7af1d45 RK |
9127 | return 0; |
9128 | ||
d8041cc8 RH |
9129 | op = DW_OP_le; |
9130 | goto do_binop; | |
e7af1d45 | 9131 | |
d8041cc8 | 9132 | case GE_EXPR: |
8df83eae | 9133 | if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) |
e7af1d45 RK |
9134 | return 0; |
9135 | ||
d8041cc8 RH |
9136 | op = DW_OP_ge; |
9137 | goto do_binop; | |
e7af1d45 | 9138 | |
d8041cc8 | 9139 | case LT_EXPR: |
8df83eae | 9140 | if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) |
e7af1d45 RK |
9141 | return 0; |
9142 | ||
d8041cc8 RH |
9143 | op = DW_OP_lt; |
9144 | goto do_binop; | |
e7af1d45 | 9145 | |
d8041cc8 | 9146 | case GT_EXPR: |
8df83eae | 9147 | if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) |
e7af1d45 RK |
9148 | return 0; |
9149 | ||
d8041cc8 RH |
9150 | op = DW_OP_gt; |
9151 | goto do_binop; | |
e7af1d45 | 9152 | |
d8041cc8 RH |
9153 | case EQ_EXPR: |
9154 | op = DW_OP_eq; | |
9155 | goto do_binop; | |
e7af1d45 | 9156 | |
d8041cc8 RH |
9157 | case NE_EXPR: |
9158 | op = DW_OP_ne; | |
9159 | goto do_binop; | |
9160 | ||
9161 | do_binop: | |
9162 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
9163 | ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); |
9164 | if (ret == 0 || ret1 == 0) | |
9165 | return 0; | |
9166 | ||
9167 | add_loc_descr (&ret, ret1); | |
d8041cc8 RH |
9168 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); |
9169 | break; | |
9170 | ||
9702143f | 9171 | case TRUTH_NOT_EXPR: |
d8041cc8 RH |
9172 | case BIT_NOT_EXPR: |
9173 | op = DW_OP_not; | |
9174 | goto do_unop; | |
e7af1d45 | 9175 | |
d8041cc8 RH |
9176 | case ABS_EXPR: |
9177 | op = DW_OP_abs; | |
9178 | goto do_unop; | |
e7af1d45 | 9179 | |
d8041cc8 RH |
9180 | case NEGATE_EXPR: |
9181 | op = DW_OP_neg; | |
9182 | goto do_unop; | |
9183 | ||
9184 | do_unop: | |
9185 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
9186 | if (ret == 0) |
9187 | return 0; | |
9188 | ||
d8041cc8 RH |
9189 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); |
9190 | break; | |
9191 | ||
fd5580cb | 9192 | case MIN_EXPR: |
d8041cc8 | 9193 | case MAX_EXPR: |
fd5580cb B |
9194 | { |
9195 | const enum tree_code code = | |
9196 | TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR; | |
9197 | ||
9198 | loc = build (COND_EXPR, TREE_TYPE (loc), | |
9199 | build (code, integer_type_node, | |
9200 | TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)), | |
9201 | TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0)); | |
9202 | } | |
2ad9852d | 9203 | |
3ef42a0c | 9204 | /* ... fall through ... */ |
d8041cc8 RH |
9205 | |
9206 | case COND_EXPR: | |
9207 | { | |
e7af1d45 RK |
9208 | dw_loc_descr_ref lhs |
9209 | = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); | |
9210 | dw_loc_descr_ref rhs | |
9211 | = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0); | |
d8041cc8 RH |
9212 | dw_loc_descr_ref bra_node, jump_node, tmp; |
9213 | ||
9214 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
9215 | if (ret == 0 || lhs == 0 || rhs == 0) |
9216 | return 0; | |
9217 | ||
d8041cc8 RH |
9218 | bra_node = new_loc_descr (DW_OP_bra, 0, 0); |
9219 | add_loc_descr (&ret, bra_node); | |
9220 | ||
e7af1d45 | 9221 | add_loc_descr (&ret, rhs); |
d8041cc8 RH |
9222 | jump_node = new_loc_descr (DW_OP_skip, 0, 0); |
9223 | add_loc_descr (&ret, jump_node); | |
9224 | ||
e7af1d45 | 9225 | add_loc_descr (&ret, lhs); |
d8041cc8 | 9226 | bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc; |
e7af1d45 | 9227 | bra_node->dw_loc_oprnd1.v.val_loc = lhs; |
d8041cc8 RH |
9228 | |
9229 | /* ??? Need a node to point the skip at. Use a nop. */ | |
9230 | tmp = new_loc_descr (DW_OP_nop, 0, 0); | |
9231 | add_loc_descr (&ret, tmp); | |
9232 | jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc; | |
9233 | jump_node->dw_loc_oprnd1.v.val_loc = tmp; | |
9234 | } | |
9235 | break; | |
9236 | ||
9237 | default: | |
7d445f15 RH |
9238 | /* Leave front-end specific codes as simply unknown. This comes |
9239 | up, for instance, with the C STMT_EXPR. */ | |
9240 | if ((unsigned int) TREE_CODE (loc) | |
9241 | >= (unsigned int) LAST_AND_UNUSED_TREE_CODE) | |
9242 | return 0; | |
9243 | ||
9244 | /* Otherwise this is a generic code; we should just lists all of | |
9245 | these explicitly. Aborting means we forgot one. */ | |
d8041cc8 RH |
9246 | abort (); |
9247 | } | |
9248 | ||
e7af1d45 RK |
9249 | /* Show if we can't fill the request for an address. */ |
9250 | if (addressp && indirect_p == 0) | |
9251 | return 0; | |
d8041cc8 RH |
9252 | |
9253 | /* If we've got an address and don't want one, dereference. */ | |
e7af1d45 | 9254 | if (!addressp && indirect_p > 0) |
d8041cc8 | 9255 | { |
e7af1d45 RK |
9256 | HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc)); |
9257 | ||
9258 | if (size > DWARF2_ADDR_SIZE || size == -1) | |
9259 | return 0; | |
2ad9852d | 9260 | else if (size == DWARF2_ADDR_SIZE) |
d8041cc8 RH |
9261 | op = DW_OP_deref; |
9262 | else | |
9263 | op = DW_OP_deref_size; | |
e7af1d45 RK |
9264 | |
9265 | add_loc_descr (&ret, new_loc_descr (op, size, 0)); | |
d8041cc8 RH |
9266 | } |
9267 | ||
9268 | return ret; | |
9269 | } | |
9270 | ||
665f2503 | 9271 | /* Given a value, round it up to the lowest multiple of `boundary' |
a3f97cbb | 9272 | which is not less than the value itself. */ |
71dfc51f | 9273 | |
665f2503 | 9274 | static inline HOST_WIDE_INT |
7080f735 | 9275 | ceiling (HOST_WIDE_INT value, unsigned int boundary) |
a3f97cbb JW |
9276 | { |
9277 | return (((value + boundary - 1) / boundary) * boundary); | |
9278 | } | |
9279 | ||
9280 | /* Given a pointer to what is assumed to be a FIELD_DECL node, return a | |
9281 | pointer to the declared type for the relevant field variable, or return | |
9282 | `integer_type_node' if the given node turns out to be an | |
9283 | ERROR_MARK node. */ | |
71dfc51f RK |
9284 | |
9285 | static inline tree | |
7080f735 | 9286 | field_type (tree decl) |
a3f97cbb | 9287 | { |
b3694847 | 9288 | tree type; |
a3f97cbb JW |
9289 | |
9290 | if (TREE_CODE (decl) == ERROR_MARK) | |
9291 | return integer_type_node; | |
9292 | ||
9293 | type = DECL_BIT_FIELD_TYPE (decl); | |
71dfc51f | 9294 | if (type == NULL_TREE) |
a3f97cbb JW |
9295 | type = TREE_TYPE (decl); |
9296 | ||
9297 | return type; | |
9298 | } | |
9299 | ||
5f446d21 DD |
9300 | /* Given a pointer to a tree node, return the alignment in bits for |
9301 | it, or else return BITS_PER_WORD if the node actually turns out to | |
9302 | be an ERROR_MARK node. */ | |
71dfc51f RK |
9303 | |
9304 | static inline unsigned | |
7080f735 | 9305 | simple_type_align_in_bits (tree type) |
a3f97cbb JW |
9306 | { |
9307 | return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; | |
9308 | } | |
9309 | ||
5f446d21 | 9310 | static inline unsigned |
7080f735 | 9311 | simple_decl_align_in_bits (tree decl) |
5f446d21 DD |
9312 | { |
9313 | return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD; | |
9314 | } | |
9315 | ||
2ad9852d RK |
9316 | /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the |
9317 | lowest addressed byte of the "containing object" for the given FIELD_DECL, | |
9318 | or return 0 if we are unable to determine what that offset is, either | |
9319 | because the argument turns out to be a pointer to an ERROR_MARK node, or | |
9320 | because the offset is actually variable. (We can't handle the latter case | |
9321 | just yet). */ | |
71dfc51f | 9322 | |
665f2503 | 9323 | static HOST_WIDE_INT |
7080f735 | 9324 | field_byte_offset (tree decl) |
a3f97cbb | 9325 | { |
665f2503 | 9326 | unsigned int type_align_in_bits; |
5f446d21 | 9327 | unsigned int decl_align_in_bits; |
665f2503 | 9328 | unsigned HOST_WIDE_INT type_size_in_bits; |
665f2503 | 9329 | HOST_WIDE_INT object_offset_in_bits; |
665f2503 RK |
9330 | tree type; |
9331 | tree field_size_tree; | |
9332 | HOST_WIDE_INT bitpos_int; | |
9333 | HOST_WIDE_INT deepest_bitpos; | |
9334 | unsigned HOST_WIDE_INT field_size_in_bits; | |
a3f97cbb JW |
9335 | |
9336 | if (TREE_CODE (decl) == ERROR_MARK) | |
9337 | return 0; | |
2ad9852d | 9338 | else if (TREE_CODE (decl) != FIELD_DECL) |
a3f97cbb JW |
9339 | abort (); |
9340 | ||
9341 | type = field_type (decl); | |
a3f97cbb JW |
9342 | field_size_tree = DECL_SIZE (decl); |
9343 | ||
3df18884 RH |
9344 | /* The size could be unspecified if there was an error, or for |
9345 | a flexible array member. */ | |
50352c9c | 9346 | if (! field_size_tree) |
3df18884 | 9347 | field_size_tree = bitsize_zero_node; |
50352c9c | 9348 | |
556273e0 | 9349 | /* We cannot yet cope with fields whose positions are variable, so |
a3f97cbb JW |
9350 | for now, when we see such things, we simply return 0. Someday, we may |
9351 | be able to handle such cases, but it will be damn difficult. */ | |
665f2503 | 9352 | if (! host_integerp (bit_position (decl), 0)) |
a3f97cbb | 9353 | return 0; |
14a774a9 | 9354 | |
665f2503 | 9355 | bitpos_int = int_bit_position (decl); |
a3f97cbb | 9356 | |
3df18884 | 9357 | /* If we don't know the size of the field, pretend it's a full word. */ |
665f2503 RK |
9358 | if (host_integerp (field_size_tree, 1)) |
9359 | field_size_in_bits = tree_low_cst (field_size_tree, 1); | |
14a774a9 RK |
9360 | else |
9361 | field_size_in_bits = BITS_PER_WORD; | |
a3f97cbb JW |
9362 | |
9363 | type_size_in_bits = simple_type_size_in_bits (type); | |
a3f97cbb | 9364 | type_align_in_bits = simple_type_align_in_bits (type); |
5f446d21 | 9365 | decl_align_in_bits = simple_decl_align_in_bits (decl); |
a3f97cbb | 9366 | |
2ad9852d RK |
9367 | /* The GCC front-end doesn't make any attempt to keep track of the starting |
9368 | bit offset (relative to the start of the containing structure type) of the | |
9369 | hypothetical "containing object" for a bit-field. Thus, when computing | |
9370 | the byte offset value for the start of the "containing object" of a | |
9371 | bit-field, we must deduce this information on our own. This can be rather | |
9372 | tricky to do in some cases. For example, handling the following structure | |
9373 | type definition when compiling for an i386/i486 target (which only aligns | |
9374 | long long's to 32-bit boundaries) can be very tricky: | |
a3f97cbb JW |
9375 | |
9376 | struct S { int field1; long long field2:31; }; | |
9377 | ||
2ad9852d RK |
9378 | Fortunately, there is a simple rule-of-thumb which can be used in such |
9379 | cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the | |
9380 | structure shown above. It decides to do this based upon one simple rule | |
9381 | for bit-field allocation. GCC allocates each "containing object" for each | |
9382 | bit-field at the first (i.e. lowest addressed) legitimate alignment | |
9383 | boundary (based upon the required minimum alignment for the declared type | |
9384 | of the field) which it can possibly use, subject to the condition that | |
9385 | there is still enough available space remaining in the containing object | |
9386 | (when allocated at the selected point) to fully accommodate all of the | |
9387 | bits of the bit-field itself. | |
9388 | ||
9389 | This simple rule makes it obvious why GCC allocates 8 bytes for each | |
9390 | object of the structure type shown above. When looking for a place to | |
9391 | allocate the "containing object" for `field2', the compiler simply tries | |
9392 | to allocate a 64-bit "containing object" at each successive 32-bit | |
9393 | boundary (starting at zero) until it finds a place to allocate that 64- | |
9394 | bit field such that at least 31 contiguous (and previously unallocated) | |
9395 | bits remain within that selected 64 bit field. (As it turns out, for the | |
9396 | example above, the compiler finds it is OK to allocate the "containing | |
9397 | object" 64-bit field at bit-offset zero within the structure type.) | |
9398 | ||
9399 | Here we attempt to work backwards from the limited set of facts we're | |
9400 | given, and we try to deduce from those facts, where GCC must have believed | |
9401 | that the containing object started (within the structure type). The value | |
9402 | we deduce is then used (by the callers of this routine) to generate | |
9403 | DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields | |
9404 | and, in the case of DW_AT_location, regular fields as well). */ | |
a3f97cbb JW |
9405 | |
9406 | /* Figure out the bit-distance from the start of the structure to the | |
9407 | "deepest" bit of the bit-field. */ | |
9408 | deepest_bitpos = bitpos_int + field_size_in_bits; | |
9409 | ||
9410 | /* This is the tricky part. Use some fancy footwork to deduce where the | |
9411 | lowest addressed bit of the containing object must be. */ | |
5f446d21 DD |
9412 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; |
9413 | ||
9414 | /* Round up to type_align by default. This works best for bitfields. */ | |
9415 | object_offset_in_bits += type_align_in_bits - 1; | |
9416 | object_offset_in_bits /= type_align_in_bits; | |
9417 | object_offset_in_bits *= type_align_in_bits; | |
a3f97cbb | 9418 | |
5f446d21 DD |
9419 | if (object_offset_in_bits > bitpos_int) |
9420 | { | |
9421 | /* Sigh, the decl must be packed. */ | |
9422 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; | |
9423 | ||
9424 | /* Round up to decl_align instead. */ | |
9425 | object_offset_in_bits += decl_align_in_bits - 1; | |
9426 | object_offset_in_bits /= decl_align_in_bits; | |
9427 | object_offset_in_bits *= decl_align_in_bits; | |
9428 | } | |
a3f97cbb | 9429 | |
2ad9852d | 9430 | return object_offset_in_bits / BITS_PER_UNIT; |
a3f97cbb | 9431 | } |
a3f97cbb | 9432 | \f |
71dfc51f RK |
9433 | /* The following routines define various Dwarf attributes and any data |
9434 | associated with them. */ | |
a3f97cbb | 9435 | |
ef76d03b | 9436 | /* Add a location description attribute value to a DIE. |
a3f97cbb | 9437 | |
ef76d03b | 9438 | This emits location attributes suitable for whole variables and |
a3f97cbb JW |
9439 | whole parameters. Note that the location attributes for struct fields are |
9440 | generated by the routine `data_member_location_attribute' below. */ | |
71dfc51f | 9441 | |
b9203463 | 9442 | static inline void |
7080f735 AJ |
9443 | add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind, |
9444 | dw_loc_descr_ref descr) | |
a3f97cbb | 9445 | { |
e7af1d45 RK |
9446 | if (descr != 0) |
9447 | add_AT_loc (die, attr_kind, descr); | |
a3f97cbb JW |
9448 | } |
9449 | ||
2ad9852d RK |
9450 | /* Attach the specialized form of location attribute used for data members of |
9451 | struct and union types. In the special case of a FIELD_DECL node which | |
9452 | represents a bit-field, the "offset" part of this special location | |
9453 | descriptor must indicate the distance in bytes from the lowest-addressed | |
9454 | byte of the containing struct or union type to the lowest-addressed byte of | |
9455 | the "containing object" for the bit-field. (See the `field_byte_offset' | |
9456 | function above). | |
9457 | ||
9458 | For any given bit-field, the "containing object" is a hypothetical object | |
9459 | (of some integral or enum type) within which the given bit-field lives. The | |
9460 | type of this hypothetical "containing object" is always the same as the | |
9461 | declared type of the individual bit-field itself (for GCC anyway... the | |
9462 | DWARF spec doesn't actually mandate this). Note that it is the size (in | |
9463 | bytes) of the hypothetical "containing object" which will be given in the | |
9464 | DW_AT_byte_size attribute for this bit-field. (See the | |
9465 | `byte_size_attribute' function below.) It is also used when calculating the | |
9466 | value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute' | |
9467 | function below.) */ | |
71dfc51f | 9468 | |
a3f97cbb | 9469 | static void |
7080f735 | 9470 | add_data_member_location_attribute (dw_die_ref die, tree decl) |
a3f97cbb | 9471 | { |
799f628a | 9472 | HOST_WIDE_INT offset; |
649ce3f2 | 9473 | dw_loc_descr_ref loc_descr = 0; |
a3f97cbb | 9474 | |
95b4aca6 | 9475 | if (TREE_CODE (decl) == TREE_BINFO) |
649ce3f2 JM |
9476 | { |
9477 | /* We're working on the TAG_inheritance for a base class. */ | |
809e3e7f | 9478 | if (BINFO_VIRTUAL_P (decl) && is_cxx ()) |
649ce3f2 JM |
9479 | { |
9480 | /* For C++ virtual bases we can't just use BINFO_OFFSET, as they | |
9481 | aren't at a fixed offset from all (sub)objects of the same | |
9482 | type. We need to extract the appropriate offset from our | |
9483 | vtable. The following dwarf expression means | |
9484 | ||
9485 | BaseAddr = ObAddr + *((*ObAddr) - Offset) | |
9486 | ||
9487 | This is specific to the V3 ABI, of course. */ | |
9488 | ||
9489 | dw_loc_descr_ref tmp; | |
2ad9852d | 9490 | |
649ce3f2 JM |
9491 | /* Make a copy of the object address. */ |
9492 | tmp = new_loc_descr (DW_OP_dup, 0, 0); | |
9493 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 9494 | |
649ce3f2 JM |
9495 | /* Extract the vtable address. */ |
9496 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
9497 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 9498 | |
649ce3f2 JM |
9499 | /* Calculate the address of the offset. */ |
9500 | offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0); | |
9501 | if (offset >= 0) | |
9502 | abort (); | |
2ad9852d | 9503 | |
649ce3f2 JM |
9504 | tmp = int_loc_descriptor (-offset); |
9505 | add_loc_descr (&loc_descr, tmp); | |
9506 | tmp = new_loc_descr (DW_OP_minus, 0, 0); | |
9507 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 9508 | |
649ce3f2 JM |
9509 | /* Extract the offset. */ |
9510 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
9511 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 9512 | |
649ce3f2 JM |
9513 | /* Add it to the object address. */ |
9514 | tmp = new_loc_descr (DW_OP_plus, 0, 0); | |
9515 | add_loc_descr (&loc_descr, tmp); | |
9516 | } | |
9517 | else | |
9518 | offset = tree_low_cst (BINFO_OFFSET (decl), 0); | |
9519 | } | |
61b32c02 JM |
9520 | else |
9521 | offset = field_byte_offset (decl); | |
9522 | ||
649ce3f2 JM |
9523 | if (! loc_descr) |
9524 | { | |
9525 | enum dwarf_location_atom op; | |
9526 | ||
2ad9852d RK |
9527 | /* The DWARF2 standard says that we should assume that the structure |
9528 | address is already on the stack, so we can specify a structure field | |
9529 | address by using DW_OP_plus_uconst. */ | |
71dfc51f | 9530 | |
a3f97cbb | 9531 | #ifdef MIPS_DEBUGGING_INFO |
2ad9852d RK |
9532 | /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst |
9533 | operator correctly. It works only if we leave the offset on the | |
9534 | stack. */ | |
649ce3f2 | 9535 | op = DW_OP_constu; |
a3f97cbb | 9536 | #else |
649ce3f2 | 9537 | op = DW_OP_plus_uconst; |
a3f97cbb | 9538 | #endif |
71dfc51f | 9539 | |
649ce3f2 JM |
9540 | loc_descr = new_loc_descr (op, offset, 0); |
9541 | } | |
2ad9852d | 9542 | |
a3f97cbb JW |
9543 | add_AT_loc (die, DW_AT_data_member_location, loc_descr); |
9544 | } | |
9545 | ||
e7ee3914 AM |
9546 | /* Writes integer values to dw_vec_const array. */ |
9547 | ||
9548 | static void | |
9549 | insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest) | |
9550 | { | |
9551 | while (size != 0) | |
9552 | { | |
9553 | *dest++ = val & 0xff; | |
9554 | val >>= 8; | |
9555 | --size; | |
9556 | } | |
9557 | } | |
9558 | ||
9559 | /* Reads integers from dw_vec_const array. Inverse of insert_int. */ | |
9560 | ||
9561 | static HOST_WIDE_INT | |
9562 | extract_int (const unsigned char *src, unsigned int size) | |
9563 | { | |
9564 | HOST_WIDE_INT val = 0; | |
9565 | ||
9566 | src += size; | |
9567 | while (size != 0) | |
9568 | { | |
9569 | val <<= 8; | |
9570 | val |= *--src & 0xff; | |
9571 | --size; | |
9572 | } | |
9573 | return val; | |
9574 | } | |
9575 | ||
9576 | /* Writes floating point values to dw_vec_const array. */ | |
9577 | ||
9578 | static void | |
9579 | insert_float (rtx rtl, unsigned char *array) | |
9580 | { | |
9581 | REAL_VALUE_TYPE rv; | |
9582 | long val[4]; | |
9583 | int i; | |
9584 | ||
9585 | REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl); | |
9586 | real_to_target (val, &rv, GET_MODE (rtl)); | |
9587 | ||
9588 | /* real_to_target puts 32-bit pieces in each long. Pack them. */ | |
9589 | for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++) | |
9590 | { | |
9591 | insert_int (val[i], 4, array); | |
9592 | array += 4; | |
9593 | } | |
9594 | } | |
9595 | ||
b20b352b | 9596 | /* Attach a DW_AT_const_value attribute for a variable or a parameter which |
a3f97cbb JW |
9597 | does not have a "location" either in memory or in a register. These |
9598 | things can arise in GNU C when a constant is passed as an actual parameter | |
9599 | to an inlined function. They can also arise in C++ where declared | |
9600 | constants do not necessarily get memory "homes". */ | |
71dfc51f | 9601 | |
a3f97cbb | 9602 | static void |
7080f735 | 9603 | add_const_value_attribute (dw_die_ref die, rtx rtl) |
a3f97cbb JW |
9604 | { |
9605 | switch (GET_CODE (rtl)) | |
9606 | { | |
9607 | case CONST_INT: | |
2e4b9b8c RH |
9608 | { |
9609 | HOST_WIDE_INT val = INTVAL (rtl); | |
c26fbbca | 9610 | |
799f628a JH |
9611 | if (val < 0) |
9612 | add_AT_int (die, DW_AT_const_value, val); | |
9613 | else | |
9614 | add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val); | |
2e4b9b8c | 9615 | } |
a3f97cbb JW |
9616 | break; |
9617 | ||
9618 | case CONST_DOUBLE: | |
9619 | /* Note that a CONST_DOUBLE rtx could represent either an integer or a | |
73c68f61 SS |
9620 | floating-point constant. A CONST_DOUBLE is used whenever the |
9621 | constant requires more than one word in order to be adequately | |
9622 | represented. We output CONST_DOUBLEs as blocks. */ | |
469ac993 | 9623 | { |
b3694847 | 9624 | enum machine_mode mode = GET_MODE (rtl); |
469ac993 JM |
9625 | |
9626 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
9627 | { | |
e7ee3914 AM |
9628 | unsigned int length = GET_MODE_SIZE (mode); |
9629 | unsigned char *array = ggc_alloc (length); | |
469ac993 | 9630 | |
e7ee3914 AM |
9631 | insert_float (rtl, array); |
9632 | add_AT_vec (die, DW_AT_const_value, length / 4, 4, array); | |
469ac993 JM |
9633 | } |
9634 | else | |
2e4b9b8c RH |
9635 | { |
9636 | /* ??? We really should be using HOST_WIDE_INT throughout. */ | |
9637 | if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT) | |
9638 | abort (); | |
2ad9852d | 9639 | |
2e4b9b8c RH |
9640 | add_AT_long_long (die, DW_AT_const_value, |
9641 | CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl)); | |
9642 | } | |
469ac993 | 9643 | } |
a3f97cbb JW |
9644 | break; |
9645 | ||
e7ee3914 AM |
9646 | case CONST_VECTOR: |
9647 | { | |
9648 | enum machine_mode mode = GET_MODE (rtl); | |
9649 | unsigned int elt_size = GET_MODE_UNIT_SIZE (mode); | |
9650 | unsigned int length = CONST_VECTOR_NUNITS (rtl); | |
9651 | unsigned char *array = ggc_alloc (length * elt_size); | |
9652 | unsigned int i; | |
9653 | unsigned char *p; | |
9654 | ||
9655 | if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT) | |
9656 | { | |
9657 | for (i = 0, p = array; i < length; i++, p += elt_size) | |
9658 | { | |
9659 | rtx elt = CONST_VECTOR_ELT (rtl, i); | |
9660 | HOST_WIDE_INT lo, hi; | |
9661 | if (GET_CODE (elt) == CONST_INT) | |
9662 | { | |
9663 | lo = INTVAL (elt); | |
9664 | hi = -(lo < 0); | |
9665 | } | |
9666 | else if (GET_CODE (elt) == CONST_DOUBLE) | |
9667 | { | |
9668 | lo = CONST_DOUBLE_LOW (elt); | |
9669 | hi = CONST_DOUBLE_HIGH (elt); | |
9670 | } | |
9671 | else | |
9672 | abort (); | |
9673 | ||
9674 | if (elt_size <= sizeof (HOST_WIDE_INT)) | |
9675 | insert_int (lo, elt_size, p); | |
9676 | else if (elt_size == 2 * sizeof (HOST_WIDE_INT)) | |
9677 | { | |
9678 | unsigned char *p0 = p; | |
9679 | unsigned char *p1 = p + sizeof (HOST_WIDE_INT); | |
9680 | ||
9681 | if (WORDS_BIG_ENDIAN) | |
9682 | { | |
9683 | p0 = p1; | |
9684 | p1 = p; | |
9685 | } | |
9686 | insert_int (lo, sizeof (HOST_WIDE_INT), p0); | |
9687 | insert_int (hi, sizeof (HOST_WIDE_INT), p1); | |
9688 | } | |
9689 | else | |
9690 | abort (); | |
9691 | } | |
9692 | } | |
9693 | else if (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT) | |
9694 | { | |
9695 | for (i = 0, p = array; i < length; i++, p += elt_size) | |
9696 | { | |
9697 | rtx elt = CONST_VECTOR_ELT (rtl, i); | |
9698 | insert_float (elt, p); | |
9699 | } | |
9700 | } | |
9701 | else | |
9702 | abort (); | |
9703 | ||
9704 | add_AT_vec (die, DW_AT_const_value, length, elt_size, array); | |
9705 | } | |
9706 | break; | |
9707 | ||
a3f97cbb JW |
9708 | case CONST_STRING: |
9709 | add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0)); | |
9710 | break; | |
9711 | ||
9712 | case SYMBOL_REF: | |
9713 | case LABEL_REF: | |
9714 | case CONST: | |
c470afad RK |
9715 | add_AT_addr (die, DW_AT_const_value, rtl); |
9716 | VARRAY_PUSH_RTX (used_rtx_varray, rtl); | |
a3f97cbb JW |
9717 | break; |
9718 | ||
9719 | case PLUS: | |
9720 | /* In cases where an inlined instance of an inline function is passed | |
73c68f61 SS |
9721 | the address of an `auto' variable (which is local to the caller) we |
9722 | can get a situation where the DECL_RTL of the artificial local | |
9723 | variable (for the inlining) which acts as a stand-in for the | |
9724 | corresponding formal parameter (of the inline function) will look | |
9725 | like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not | |
9726 | exactly a compile-time constant expression, but it isn't the address | |
9727 | of the (artificial) local variable either. Rather, it represents the | |
9728 | *value* which the artificial local variable always has during its | |
9729 | lifetime. We currently have no way to represent such quasi-constant | |
9730 | values in Dwarf, so for now we just punt and generate nothing. */ | |
a3f97cbb JW |
9731 | break; |
9732 | ||
9733 | default: | |
9734 | /* No other kinds of rtx should be possible here. */ | |
9735 | abort (); | |
9736 | } | |
9737 | ||
9738 | } | |
9739 | ||
d8041cc8 | 9740 | static rtx |
7080f735 | 9741 | rtl_for_decl_location (tree decl) |
a3f97cbb | 9742 | { |
b3694847 | 9743 | rtx rtl; |
71dfc51f | 9744 | |
a3f97cbb JW |
9745 | /* Here we have to decide where we are going to say the parameter "lives" |
9746 | (as far as the debugger is concerned). We only have a couple of | |
9747 | choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. | |
71dfc51f | 9748 | |
556273e0 | 9749 | DECL_RTL normally indicates where the parameter lives during most of the |
71dfc51f | 9750 | activation of the function. If optimization is enabled however, this |
556273e0 | 9751 | could be either NULL or else a pseudo-reg. Both of those cases indicate |
a3f97cbb JW |
9752 | that the parameter doesn't really live anywhere (as far as the code |
9753 | generation parts of GCC are concerned) during most of the function's | |
9754 | activation. That will happen (for example) if the parameter is never | |
71dfc51f RK |
9755 | referenced within the function. |
9756 | ||
9757 | We could just generate a location descriptor here for all non-NULL | |
9758 | non-pseudo values of DECL_RTL and ignore all of the rest, but we can be | |
9759 | a little nicer than that if we also consider DECL_INCOMING_RTL in cases | |
9760 | where DECL_RTL is NULL or is a pseudo-reg. | |
9761 | ||
9762 | Note however that we can only get away with using DECL_INCOMING_RTL as | |
9763 | a backup substitute for DECL_RTL in certain limited cases. In cases | |
9764 | where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl), | |
9765 | we can be sure that the parameter was passed using the same type as it is | |
9766 | declared to have within the function, and that its DECL_INCOMING_RTL | |
9767 | points us to a place where a value of that type is passed. | |
9768 | ||
9769 | In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different, | |
9770 | we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL | |
9771 | because in these cases DECL_INCOMING_RTL points us to a value of some | |
9772 | type which is *different* from the type of the parameter itself. Thus, | |
9773 | if we tried to use DECL_INCOMING_RTL to generate a location attribute in | |
9774 | such cases, the debugger would end up (for example) trying to fetch a | |
9775 | `float' from a place which actually contains the first part of a | |
9776 | `double'. That would lead to really incorrect and confusing | |
9777 | output at debug-time. | |
9778 | ||
9779 | So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL | |
9780 | in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There | |
9781 | are a couple of exceptions however. On little-endian machines we can | |
9782 | get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is | |
9783 | not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is | |
9784 | an integral type that is smaller than TREE_TYPE (decl). These cases arise | |
9785 | when (on a little-endian machine) a non-prototyped function has a | |
9786 | parameter declared to be of type `short' or `char'. In such cases, | |
9787 | TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will | |
9788 | be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the | |
9789 | passed `int' value. If the debugger then uses that address to fetch | |
9790 | a `short' or a `char' (on a little-endian machine) the result will be | |
9791 | the correct data, so we allow for such exceptional cases below. | |
9792 | ||
9793 | Note that our goal here is to describe the place where the given formal | |
2ad9852d RK |
9794 | parameter lives during most of the function's activation (i.e. between the |
9795 | end of the prologue and the start of the epilogue). We'll do that as best | |
9796 | as we can. Note however that if the given formal parameter is modified | |
9797 | sometime during the execution of the function, then a stack backtrace (at | |
9798 | debug-time) will show the function as having been called with the *new* | |
9799 | value rather than the value which was originally passed in. This happens | |
9800 | rarely enough that it is not a major problem, but it *is* a problem, and | |
9801 | I'd like to fix it. | |
9802 | ||
9803 | A future version of dwarf2out.c may generate two additional attributes for | |
9804 | any given DW_TAG_formal_parameter DIE which will describe the "passed | |
9805 | type" and the "passed location" for the given formal parameter in addition | |
9806 | to the attributes we now generate to indicate the "declared type" and the | |
9807 | "active location" for each parameter. This additional set of attributes | |
9808 | could be used by debuggers for stack backtraces. Separately, note that | |
9809 | sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also. | |
9810 | This happens (for example) for inlined-instances of inline function formal | |
9811 | parameters which are never referenced. This really shouldn't be | |
9812 | happening. All PARM_DECL nodes should get valid non-NULL | |
6de9cd9a | 9813 | DECL_INCOMING_RTL values. FIXME. */ |
a3f97cbb JW |
9814 | |
9815 | /* Use DECL_RTL as the "location" unless we find something better. */ | |
110c3568 | 9816 | rtl = DECL_RTL_IF_SET (decl); |
a3f97cbb | 9817 | |
c28abdf0 | 9818 | /* When generating abstract instances, ignore everything except |
234c071b KB |
9819 | constants, symbols living in memory, and symbols living in |
9820 | fixed registers. */ | |
c28abdf0 RH |
9821 | if (! reload_completed) |
9822 | { | |
9823 | if (rtl | |
9824 | && (CONSTANT_P (rtl) | |
3c0cb5de | 9825 | || (MEM_P (rtl) |
234c071b | 9826 | && CONSTANT_P (XEXP (rtl, 0))) |
f8cfc6aa | 9827 | || (REG_P (rtl) |
234c071b KB |
9828 | && TREE_CODE (decl) == VAR_DECL |
9829 | && TREE_STATIC (decl)))) | |
4c8c0dec | 9830 | { |
5fd9b178 | 9831 | rtl = targetm.delegitimize_address (rtl); |
4c8c0dec JJ |
9832 | return rtl; |
9833 | } | |
c28abdf0 RH |
9834 | rtl = NULL_RTX; |
9835 | } | |
9836 | else if (TREE_CODE (decl) == PARM_DECL) | |
a3f97cbb JW |
9837 | { |
9838 | if (rtl == NULL_RTX || is_pseudo_reg (rtl)) | |
9839 | { | |
d8041cc8 RH |
9840 | tree declared_type = type_main_variant (TREE_TYPE (decl)); |
9841 | tree passed_type = type_main_variant (DECL_ARG_TYPE (decl)); | |
a3f97cbb | 9842 | |
71dfc51f | 9843 | /* This decl represents a formal parameter which was optimized out. |
a3f97cbb | 9844 | Note that DECL_INCOMING_RTL may be NULL in here, but we handle |
2ad9852d | 9845 | all cases where (rtl == NULL_RTX) just below. */ |
a3f97cbb | 9846 | if (declared_type == passed_type) |
71dfc51f RK |
9847 | rtl = DECL_INCOMING_RTL (decl); |
9848 | else if (! BYTES_BIG_ENDIAN | |
9849 | && TREE_CODE (declared_type) == INTEGER_TYPE | |
555b6442 HPN |
9850 | && (GET_MODE_SIZE (TYPE_MODE (declared_type)) |
9851 | <= GET_MODE_SIZE (TYPE_MODE (passed_type)))) | |
556273e0 | 9852 | rtl = DECL_INCOMING_RTL (decl); |
a3f97cbb | 9853 | } |
5a904a61 JW |
9854 | |
9855 | /* If the parm was passed in registers, but lives on the stack, then | |
9856 | make a big endian correction if the mode of the type of the | |
9857 | parameter is not the same as the mode of the rtl. */ | |
9858 | /* ??? This is the same series of checks that are made in dbxout.c before | |
9859 | we reach the big endian correction code there. It isn't clear if all | |
9860 | of these checks are necessary here, but keeping them all is the safe | |
9861 | thing to do. */ | |
3c0cb5de | 9862 | else if (MEM_P (rtl) |
5a904a61 JW |
9863 | && XEXP (rtl, 0) != const0_rtx |
9864 | && ! CONSTANT_P (XEXP (rtl, 0)) | |
9865 | /* Not passed in memory. */ | |
3c0cb5de | 9866 | && !MEM_P (DECL_INCOMING_RTL (decl)) |
5a904a61 | 9867 | /* Not passed by invisible reference. */ |
f8cfc6aa | 9868 | && (!REG_P (XEXP (rtl, 0)) |
5a904a61 JW |
9869 | || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM |
9870 | || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM | |
9871 | #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM | |
9872 | || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM | |
9873 | #endif | |
9874 | ) | |
9875 | /* Big endian correction check. */ | |
9876 | && BYTES_BIG_ENDIAN | |
9877 | && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl) | |
9878 | && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))) | |
9879 | < UNITS_PER_WORD)) | |
9880 | { | |
9881 | int offset = (UNITS_PER_WORD | |
9882 | - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))); | |
2ad9852d | 9883 | |
5a904a61 JW |
9884 | rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)), |
9885 | plus_constant (XEXP (rtl, 0), offset)); | |
9886 | } | |
a3f97cbb | 9887 | } |
8b495402 | 9888 | else if (TREE_CODE (decl) == VAR_DECL |
de3c6d93 | 9889 | && rtl |
3c0cb5de | 9890 | && MEM_P (rtl) |
8b495402 DD |
9891 | && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl)) |
9892 | && BYTES_BIG_ENDIAN) | |
9893 | { | |
9894 | int rsize = GET_MODE_SIZE (GET_MODE (rtl)); | |
9895 | int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))); | |
9896 | ||
9897 | /* If a variable is declared "register" yet is smaller than | |
9898 | a register, then if we store the variable to memory, it | |
9899 | looks like we're storing a register-sized value, when in | |
9900 | fact we are not. We need to adjust the offset of the | |
9901 | storage location to reflect the actual value's bytes, | |
9902 | else gdb will not be able to display it. */ | |
9903 | if (rsize > dsize) | |
9904 | rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)), | |
9905 | plus_constant (XEXP (rtl, 0), rsize-dsize)); | |
9906 | } | |
71dfc51f | 9907 | |
d8041cc8 RH |
9908 | if (rtl != NULL_RTX) |
9909 | { | |
9910 | rtl = eliminate_regs (rtl, 0, NULL_RTX); | |
6a7a9f01 | 9911 | #ifdef LEAF_REG_REMAP |
d8041cc8 RH |
9912 | if (current_function_uses_only_leaf_regs) |
9913 | leaf_renumber_regs_insn (rtl); | |
6a7a9f01 | 9914 | #endif |
d8041cc8 RH |
9915 | } |
9916 | ||
2ad9852d RK |
9917 | /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant, |
9918 | and will have been substituted directly into all expressions that use it. | |
9919 | C does not have such a concept, but C++ and other languages do. */ | |
c28abdf0 | 9920 | else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl)) |
6d73371a JJ |
9921 | { |
9922 | /* If a variable is initialized with a string constant without embedded | |
9923 | zeros, build CONST_STRING. */ | |
9924 | if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST | |
9925 | && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) | |
9926 | { | |
9927 | tree arrtype = TREE_TYPE (decl); | |
9928 | tree enttype = TREE_TYPE (arrtype); | |
9929 | tree domain = TYPE_DOMAIN (arrtype); | |
9930 | tree init = DECL_INITIAL (decl); | |
9931 | enum machine_mode mode = TYPE_MODE (enttype); | |
9932 | ||
9933 | if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1 | |
9934 | && domain | |
9935 | && integer_zerop (TYPE_MIN_VALUE (domain)) | |
9936 | && compare_tree_int (TYPE_MAX_VALUE (domain), | |
9937 | TREE_STRING_LENGTH (init) - 1) == 0 | |
9938 | && ((size_t) TREE_STRING_LENGTH (init) | |
9939 | == strlen (TREE_STRING_POINTER (init)) + 1)) | |
839ee4bc | 9940 | rtl = gen_rtx_CONST_STRING (VOIDmode, TREE_STRING_POINTER (init)); |
6d73371a | 9941 | } |
29b91443 JM |
9942 | /* If the initializer is something that we know will expand into an |
9943 | immediate RTL constant, expand it now. Expanding anything else | |
9944 | tends to produce unresolved symbols; see debug/5770 and c++/6381. */ | |
9945 | else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST | |
9946 | || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST) | |
6d73371a JJ |
9947 | { |
9948 | rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode, | |
9949 | EXPAND_INITIALIZER); | |
29b91443 | 9950 | /* If expand_expr returns a MEM, it wasn't immediate. */ |
3c0cb5de | 9951 | if (rtl && MEM_P (rtl)) |
29b91443 | 9952 | abort (); |
6d73371a JJ |
9953 | } |
9954 | } | |
8063ddcf | 9955 | |
4c8c0dec | 9956 | if (rtl) |
5fd9b178 | 9957 | rtl = targetm.delegitimize_address (rtl); |
b9203463 RH |
9958 | |
9959 | /* If we don't look past the constant pool, we risk emitting a | |
9960 | reference to a constant pool entry that isn't referenced from | |
9961 | code, and thus is not emitted. */ | |
9962 | if (rtl) | |
9963 | rtl = avoid_constant_pool_reference (rtl); | |
9964 | ||
d8041cc8 RH |
9965 | return rtl; |
9966 | } | |
9967 | ||
b20b352b | 9968 | /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value |
d8041cc8 RH |
9969 | data attribute for a variable or a parameter. We generate the |
9970 | DW_AT_const_value attribute only in those cases where the given variable | |
9971 | or parameter does not have a true "location" either in memory or in a | |
9972 | register. This can happen (for example) when a constant is passed as an | |
9973 | actual argument in a call to an inline function. (It's possible that | |
9974 | these things can crop up in other ways also.) Note that one type of | |
9975 | constant value which can be passed into an inlined function is a constant | |
9976 | pointer. This can happen for example if an actual argument in an inlined | |
9977 | function call evaluates to a compile-time constant address. */ | |
9978 | ||
9979 | static void | |
0a2d3d69 DB |
9980 | add_location_or_const_value_attribute (dw_die_ref die, tree decl, |
9981 | enum dwarf_attribute attr) | |
d8041cc8 | 9982 | { |
b3694847 | 9983 | rtx rtl; |
b9203463 | 9984 | dw_loc_descr_ref descr; |
0a2d3d69 | 9985 | var_loc_list *loc_list; |
d8041cc8 RH |
9986 | |
9987 | if (TREE_CODE (decl) == ERROR_MARK) | |
9988 | return; | |
6de9cd9a DN |
9989 | else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL |
9990 | && TREE_CODE (decl) != RESULT_DECL) | |
d8041cc8 RH |
9991 | abort (); |
9992 | ||
0a2d3d69 DB |
9993 | /* See if we possibly have multiple locations for this variable. */ |
9994 | loc_list = lookup_decl_loc (decl); | |
9995 | ||
9996 | /* If it truly has multiple locations, the first and last node will | |
9997 | differ. */ | |
9998 | if (loc_list && loc_list->first != loc_list->last) | |
9999 | { | |
10000 | const char *secname; | |
10001 | const char *endname; | |
10002 | dw_loc_list_ref list; | |
10003 | rtx varloc; | |
10004 | struct var_loc_node *node; | |
10005 | ||
10006 | /* We need to figure out what section we should use as the base | |
10007 | for the address ranges where a given location is valid. | |
10008 | 1. If this particular DECL has a section associated with it, | |
10009 | use that. | |
10010 | 2. If this function has a section associated with it, use | |
10011 | that. | |
10012 | 3. Otherwise, use the text section. | |
10013 | XXX: If you split a variable across multiple sections, this | |
10014 | won't notice. */ | |
10015 | ||
10016 | if (DECL_SECTION_NAME (decl)) | |
10017 | { | |
10018 | tree sectree = DECL_SECTION_NAME (decl); | |
10019 | secname = TREE_STRING_POINTER (sectree); | |
10020 | } | |
10021 | else if (current_function_decl | |
10022 | && DECL_SECTION_NAME (current_function_decl)) | |
10023 | { | |
10024 | tree sectree = DECL_SECTION_NAME (current_function_decl); | |
10025 | secname = TREE_STRING_POINTER (sectree); | |
10026 | } | |
10027 | else | |
e193b408 | 10028 | secname = text_section_label; |
0a2d3d69 DB |
10029 | |
10030 | /* Now that we know what section we are using for a base, | |
10031 | actually construct the list of locations. | |
10032 | The first location information is what is passed to the | |
10033 | function that creates the location list, and the remaining | |
10034 | locations just get added on to that list. | |
10035 | Note that we only know the start address for a location | |
10036 | (IE location changes), so to build the range, we use | |
10037 | the range [current location start, next location start]. | |
10038 | This means we have to special case the last node, and generate | |
10039 | a range of [last location start, end of function label]. */ | |
10040 | ||
10041 | node = loc_list->first; | |
10042 | varloc = NOTE_VAR_LOCATION (node->var_loc_note); | |
10043 | list = new_loc_list (loc_descriptor (varloc, attr != DW_AT_frame_base), | |
10044 | node->label, node->next->label, secname, 1); | |
10045 | node = node->next; | |
10046 | ||
10047 | for (; node->next; node = node->next) | |
10048 | if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX) | |
10049 | { | |
10050 | /* The variable has a location between NODE->LABEL and | |
10051 | NODE->NEXT->LABEL. */ | |
10052 | varloc = NOTE_VAR_LOCATION (node->var_loc_note); | |
10053 | add_loc_descr_to_loc_list (&list, | |
10054 | loc_descriptor (varloc, | |
10055 | attr != DW_AT_frame_base), | |
10056 | node->label, node->next->label, secname); | |
10057 | } | |
10058 | ||
10059 | /* If the variable has a location at the last label | |
10060 | it keeps its location until the end of function. */ | |
10061 | if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX) | |
10062 | { | |
10063 | char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; | |
10064 | ||
10065 | varloc = NOTE_VAR_LOCATION (node->var_loc_note); | |
10066 | if (!current_function_decl) | |
10067 | endname = text_end_label; | |
10068 | else | |
10069 | { | |
10070 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, | |
10071 | current_function_funcdef_no); | |
10072 | endname = ggc_strdup (label_id); | |
10073 | } | |
10074 | add_loc_descr_to_loc_list (&list, | |
10075 | loc_descriptor (varloc, | |
10076 | attr != DW_AT_frame_base), | |
10077 | node->label, endname, secname); | |
10078 | } | |
10079 | ||
10080 | /* Finally, add the location list to the DIE, and we are done. */ | |
10081 | add_AT_loc_list (die, attr, list); | |
10082 | return; | |
10083 | } | |
10084 | ||
d8041cc8 | 10085 | rtl = rtl_for_decl_location (decl); |
a97c9600 RH |
10086 | if (rtl == NULL_RTX) |
10087 | return; | |
6a7a9f01 | 10088 | |
a3f97cbb JW |
10089 | switch (GET_CODE (rtl)) |
10090 | { | |
10091 | case CONST_INT: | |
10092 | case CONST_DOUBLE: | |
e7ee3914 | 10093 | case CONST_VECTOR: |
a3f97cbb JW |
10094 | case CONST_STRING: |
10095 | case SYMBOL_REF: | |
10096 | case LABEL_REF: | |
10097 | case CONST: | |
10098 | case PLUS: | |
10099 | /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ | |
10100 | add_const_value_attribute (die, rtl); | |
10101 | break; | |
10102 | ||
10103 | case MEM: | |
b9203463 RH |
10104 | if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl)) |
10105 | { | |
10106 | /* Need loc_descriptor_from_tree since that's where we know | |
10107 | how to handle TLS variables. Want the object's address | |
10108 | since the top-level DW_AT_location assumes such. See | |
10109 | the confusion in loc_descriptor for reference. */ | |
10110 | descr = loc_descriptor_from_tree (decl, 1); | |
10111 | } | |
10112 | else | |
10113 | { | |
10114 | case REG: | |
10115 | case SUBREG: | |
10116 | case CONCAT: | |
0a2d3d69 | 10117 | descr = loc_descriptor (rtl, true); |
b9203463 | 10118 | } |
0a2d3d69 | 10119 | add_AT_location_description (die, attr, descr); |
a3f97cbb | 10120 | break; |
7080f735 | 10121 | |
d44c7e36 DB |
10122 | case PARALLEL: |
10123 | { | |
10124 | rtvec par_elems = XVEC (rtl, 0); | |
10125 | int num_elem = GET_NUM_ELEM (par_elems); | |
10126 | enum machine_mode mode; | |
10127 | int i; | |
10128 | ||
10129 | /* Create the first one, so we have something to add to. */ | |
0a2d3d69 | 10130 | descr = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0), true); |
d44c7e36 DB |
10131 | mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0)); |
10132 | add_loc_descr (&descr, | |
10133 | new_loc_descr (DW_OP_piece, GET_MODE_SIZE (mode), 0)); | |
10134 | for (i = 1; i < num_elem; i++) | |
10135 | { | |
10136 | dw_loc_descr_ref temp; | |
10137 | ||
0a2d3d69 | 10138 | temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0), true); |
d44c7e36 DB |
10139 | add_loc_descr (&descr, temp); |
10140 | mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0)); | |
10141 | add_loc_descr (&descr, | |
10142 | new_loc_descr (DW_OP_piece, | |
10143 | GET_MODE_SIZE (mode), 0)); | |
10144 | } | |
10145 | } | |
10146 | add_AT_location_description (die, DW_AT_location, descr); | |
10147 | break; | |
10148 | ||
a3f97cbb | 10149 | default: |
71dfc51f | 10150 | abort (); |
a3f97cbb JW |
10151 | } |
10152 | } | |
10153 | ||
1bfb5f8f JM |
10154 | /* If we don't have a copy of this variable in memory for some reason (such |
10155 | as a C++ member constant that doesn't have an out-of-line definition), | |
10156 | we should tell the debugger about the constant value. */ | |
10157 | ||
10158 | static void | |
7080f735 | 10159 | tree_add_const_value_attribute (dw_die_ref var_die, tree decl) |
1bfb5f8f JM |
10160 | { |
10161 | tree init = DECL_INITIAL (decl); | |
10162 | tree type = TREE_TYPE (decl); | |
10163 | ||
10164 | if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init | |
10165 | && initializer_constant_valid_p (init, type) == null_pointer_node) | |
10166 | /* OK */; | |
10167 | else | |
10168 | return; | |
10169 | ||
10170 | switch (TREE_CODE (type)) | |
10171 | { | |
10172 | case INTEGER_TYPE: | |
10173 | if (host_integerp (init, 0)) | |
10174 | add_AT_unsigned (var_die, DW_AT_const_value, | |
2ad9852d | 10175 | tree_low_cst (init, 0)); |
1bfb5f8f JM |
10176 | else |
10177 | add_AT_long_long (var_die, DW_AT_const_value, | |
10178 | TREE_INT_CST_HIGH (init), | |
10179 | TREE_INT_CST_LOW (init)); | |
10180 | break; | |
10181 | ||
10182 | default:; | |
10183 | } | |
10184 | } | |
0b34cf1e | 10185 | |
b20b352b | 10186 | /* Generate a DW_AT_name attribute given some string value to be included as |
a3f97cbb | 10187 | the value of the attribute. */ |
71dfc51f | 10188 | |
c4274b22 | 10189 | static void |
7080f735 | 10190 | add_name_attribute (dw_die_ref die, const char *name_string) |
a3f97cbb | 10191 | { |
71dfc51f | 10192 | if (name_string != NULL && *name_string != 0) |
14a774a9 RK |
10193 | { |
10194 | if (demangle_name_func) | |
10195 | name_string = (*demangle_name_func) (name_string); | |
10196 | ||
10197 | add_AT_string (die, DW_AT_name, name_string); | |
10198 | } | |
a3f97cbb JW |
10199 | } |
10200 | ||
b20b352b | 10201 | /* Generate a DW_AT_comp_dir attribute for DIE. */ |
c4274b22 RH |
10202 | |
10203 | static void | |
7080f735 | 10204 | add_comp_dir_attribute (dw_die_ref die) |
c4274b22 | 10205 | { |
b20d9f0c | 10206 | const char *wd = get_src_pwd (); |
c4274b22 RH |
10207 | if (wd != NULL) |
10208 | add_AT_string (die, DW_AT_comp_dir, wd); | |
10209 | } | |
10210 | ||
a3f97cbb | 10211 | /* Given a tree node describing an array bound (either lower or upper) output |
466446b0 | 10212 | a representation for that bound. */ |
71dfc51f | 10213 | |
a3f97cbb | 10214 | static void |
7080f735 | 10215 | add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound) |
a3f97cbb | 10216 | { |
a3f97cbb JW |
10217 | switch (TREE_CODE (bound)) |
10218 | { | |
10219 | case ERROR_MARK: | |
10220 | return; | |
10221 | ||
3ef42a0c | 10222 | /* All fixed-bounds are represented by INTEGER_CST nodes. */ |
a3f97cbb | 10223 | case INTEGER_CST: |
665f2503 RK |
10224 | if (! host_integerp (bound, 0) |
10225 | || (bound_attr == DW_AT_lower_bound | |
28985b81 | 10226 | && (((is_c_family () || is_java ()) && integer_zerop (bound)) |
665f2503 | 10227 | || (is_fortran () && integer_onep (bound))))) |
a1105617 | 10228 | /* Use the default. */ |
665f2503 | 10229 | ; |
141719a8 | 10230 | else |
665f2503 | 10231 | add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0)); |
a3f97cbb JW |
10232 | break; |
10233 | ||
b1ccbc24 | 10234 | case CONVERT_EXPR: |
a3f97cbb | 10235 | case NOP_EXPR: |
b1ccbc24 | 10236 | case NON_LVALUE_EXPR: |
ed239f5a | 10237 | case VIEW_CONVERT_EXPR: |
b1ccbc24 RK |
10238 | add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0)); |
10239 | break; | |
556273e0 | 10240 | |
a3f97cbb | 10241 | case SAVE_EXPR: |
a3f97cbb | 10242 | break; |
3f76745e | 10243 | |
ef76d03b | 10244 | case VAR_DECL: |
d8041cc8 | 10245 | case PARM_DECL: |
6de9cd9a | 10246 | case RESULT_DECL: |
d8041cc8 RH |
10247 | { |
10248 | dw_die_ref decl_die = lookup_decl_die (bound); | |
10249 | ||
10250 | /* ??? Can this happen, or should the variable have been bound | |
10251 | first? Probably it can, since I imagine that we try to create | |
10252 | the types of parameters in the order in which they exist in | |
0b34cf1e | 10253 | the list, and won't have created a forward reference to a |
d8041cc8 RH |
10254 | later parameter. */ |
10255 | if (decl_die != NULL) | |
10256 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
10257 | break; | |
10258 | } | |
ef76d03b | 10259 | |
3f76745e | 10260 | default: |
d8041cc8 RH |
10261 | { |
10262 | /* Otherwise try to create a stack operation procedure to | |
10263 | evaluate the value of the array bound. */ | |
10264 | ||
10265 | dw_die_ref ctx, decl_die; | |
10266 | dw_loc_descr_ref loc; | |
10267 | ||
10268 | loc = loc_descriptor_from_tree (bound, 0); | |
10269 | if (loc == NULL) | |
10270 | break; | |
10271 | ||
e7af1d45 RK |
10272 | if (current_function_decl == 0) |
10273 | ctx = comp_unit_die; | |
10274 | else | |
10275 | ctx = lookup_decl_die (current_function_decl); | |
d8041cc8 | 10276 | |
54ba1f0d | 10277 | decl_die = new_die (DW_TAG_variable, ctx, bound); |
d8041cc8 RH |
10278 | add_AT_flag (decl_die, DW_AT_artificial, 1); |
10279 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
10280 | add_AT_loc (decl_die, DW_AT_location, loc); | |
10281 | ||
10282 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
10283 | break; | |
10284 | } | |
a3f97cbb JW |
10285 | } |
10286 | } | |
10287 | ||
10288 | /* Note that the block of subscript information for an array type also | |
10289 | includes information about the element type of type given array type. */ | |
71dfc51f | 10290 | |
a3f97cbb | 10291 | static void |
7080f735 | 10292 | add_subscript_info (dw_die_ref type_die, tree type) |
a3f97cbb | 10293 | { |
081f5e7e | 10294 | #ifndef MIPS_DEBUGGING_INFO |
b3694847 | 10295 | unsigned dimension_number; |
081f5e7e | 10296 | #endif |
b3694847 SS |
10297 | tree lower, upper; |
10298 | dw_die_ref subrange_die; | |
a3f97cbb | 10299 | |
556273e0 | 10300 | /* The GNU compilers represent multidimensional array types as sequences of |
a3f97cbb JW |
10301 | one dimensional array types whose element types are themselves array |
10302 | types. Here we squish that down, so that each multidimensional array | |
556273e0 | 10303 | type gets only one array_type DIE in the Dwarf debugging info. The draft |
a3f97cbb JW |
10304 | Dwarf specification say that we are allowed to do this kind of |
10305 | compression in C (because there is no difference between an array or | |
556273e0 | 10306 | arrays and a multidimensional array in C) but for other source languages |
a3f97cbb | 10307 | (e.g. Ada) we probably shouldn't do this. */ |
71dfc51f | 10308 | |
a3f97cbb JW |
10309 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
10310 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
10311 | We work around this by disabling this feature. See also | |
10312 | gen_array_type_die. */ | |
10313 | #ifndef MIPS_DEBUGGING_INFO | |
10314 | for (dimension_number = 0; | |
10315 | TREE_CODE (type) == ARRAY_TYPE; | |
10316 | type = TREE_TYPE (type), dimension_number++) | |
a3f97cbb | 10317 | #endif |
2ad9852d | 10318 | { |
b3694847 | 10319 | tree domain = TYPE_DOMAIN (type); |
a3f97cbb JW |
10320 | |
10321 | /* Arrays come in three flavors: Unspecified bounds, fixed bounds, | |
556273e0 | 10322 | and (in GNU C only) variable bounds. Handle all three forms |
73c68f61 | 10323 | here. */ |
54ba1f0d | 10324 | subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL); |
a3f97cbb JW |
10325 | if (domain) |
10326 | { | |
10327 | /* We have an array type with specified bounds. */ | |
10328 | lower = TYPE_MIN_VALUE (domain); | |
10329 | upper = TYPE_MAX_VALUE (domain); | |
10330 | ||
beb235f8 | 10331 | /* Define the index type. */ |
a9d38797 | 10332 | if (TREE_TYPE (domain)) |
ef76d03b JW |
10333 | { |
10334 | /* ??? This is probably an Ada unnamed subrange type. Ignore the | |
10335 | TREE_TYPE field. We can't emit debug info for this | |
10336 | because it is an unnamed integral type. */ | |
10337 | if (TREE_CODE (domain) == INTEGER_TYPE | |
10338 | && TYPE_NAME (domain) == NULL_TREE | |
10339 | && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE | |
10340 | && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE) | |
556273e0 | 10341 | ; |
ef76d03b JW |
10342 | else |
10343 | add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0, | |
10344 | type_die); | |
10345 | } | |
a9d38797 | 10346 | |
e1ee5cdc RH |
10347 | /* ??? If upper is NULL, the array has unspecified length, |
10348 | but it does have a lower bound. This happens with Fortran | |
10349 | dimension arr(N:*) | |
7080f735 | 10350 | Since the debugger is definitely going to need to know N |
e1ee5cdc RH |
10351 | to produce useful results, go ahead and output the lower |
10352 | bound solo, and hope the debugger can cope. */ | |
10353 | ||
141719a8 | 10354 | add_bound_info (subrange_die, DW_AT_lower_bound, lower); |
e1ee5cdc RH |
10355 | if (upper) |
10356 | add_bound_info (subrange_die, DW_AT_upper_bound, upper); | |
a3f97cbb | 10357 | } |
71dfc51f | 10358 | |
2ad9852d RK |
10359 | /* Otherwise we have an array type with an unspecified length. The |
10360 | DWARF-2 spec does not say how to handle this; let's just leave out the | |
10361 | bounds. */ | |
a3f97cbb | 10362 | } |
a3f97cbb JW |
10363 | } |
10364 | ||
10365 | static void | |
7080f735 | 10366 | add_byte_size_attribute (dw_die_ref die, tree tree_node) |
a3f97cbb | 10367 | { |
b3694847 | 10368 | unsigned size; |
a3f97cbb JW |
10369 | |
10370 | switch (TREE_CODE (tree_node)) | |
10371 | { | |
10372 | case ERROR_MARK: | |
10373 | size = 0; | |
10374 | break; | |
10375 | case ENUMERAL_TYPE: | |
10376 | case RECORD_TYPE: | |
10377 | case UNION_TYPE: | |
10378 | case QUAL_UNION_TYPE: | |
10379 | size = int_size_in_bytes (tree_node); | |
10380 | break; | |
10381 | case FIELD_DECL: | |
10382 | /* For a data member of a struct or union, the DW_AT_byte_size is | |
73c68f61 SS |
10383 | generally given as the number of bytes normally allocated for an |
10384 | object of the *declared* type of the member itself. This is true | |
10385 | even for bit-fields. */ | |
a3f97cbb JW |
10386 | size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT; |
10387 | break; | |
10388 | default: | |
10389 | abort (); | |
10390 | } | |
10391 | ||
10392 | /* Note that `size' might be -1 when we get to this point. If it is, that | |
10393 | indicates that the byte size of the entity in question is variable. We | |
10394 | have no good way of expressing this fact in Dwarf at the present time, | |
10395 | so just let the -1 pass on through. */ | |
a3f97cbb JW |
10396 | add_AT_unsigned (die, DW_AT_byte_size, size); |
10397 | } | |
10398 | ||
10399 | /* For a FIELD_DECL node which represents a bit-field, output an attribute | |
10400 | which specifies the distance in bits from the highest order bit of the | |
10401 | "containing object" for the bit-field to the highest order bit of the | |
10402 | bit-field itself. | |
10403 | ||
2ad9852d RK |
10404 | For any given bit-field, the "containing object" is a hypothetical object |
10405 | (of some integral or enum type) within which the given bit-field lives. The | |
10406 | type of this hypothetical "containing object" is always the same as the | |
10407 | declared type of the individual bit-field itself. The determination of the | |
10408 | exact location of the "containing object" for a bit-field is rather | |
10409 | complicated. It's handled by the `field_byte_offset' function (above). | |
a3f97cbb JW |
10410 | |
10411 | Note that it is the size (in bytes) of the hypothetical "containing object" | |
10412 | which will be given in the DW_AT_byte_size attribute for this bit-field. | |
10413 | (See `byte_size_attribute' above). */ | |
71dfc51f RK |
10414 | |
10415 | static inline void | |
7080f735 | 10416 | add_bit_offset_attribute (dw_die_ref die, tree decl) |
a3f97cbb | 10417 | { |
665f2503 RK |
10418 | HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl); |
10419 | tree type = DECL_BIT_FIELD_TYPE (decl); | |
10420 | HOST_WIDE_INT bitpos_int; | |
10421 | HOST_WIDE_INT highest_order_object_bit_offset; | |
10422 | HOST_WIDE_INT highest_order_field_bit_offset; | |
10423 | HOST_WIDE_INT unsigned bit_offset; | |
a3f97cbb | 10424 | |
3a88cbd1 JL |
10425 | /* Must be a field and a bit field. */ |
10426 | if (!type | |
10427 | || TREE_CODE (decl) != FIELD_DECL) | |
10428 | abort (); | |
a3f97cbb JW |
10429 | |
10430 | /* We can't yet handle bit-fields whose offsets are variable, so if we | |
10431 | encounter such things, just return without generating any attribute | |
665f2503 RK |
10432 | whatsoever. Likewise for variable or too large size. */ |
10433 | if (! host_integerp (bit_position (decl), 0) | |
10434 | || ! host_integerp (DECL_SIZE (decl), 1)) | |
71dfc51f RK |
10435 | return; |
10436 | ||
665f2503 | 10437 | bitpos_int = int_bit_position (decl); |
a3f97cbb JW |
10438 | |
10439 | /* Note that the bit offset is always the distance (in bits) from the | |
556273e0 KH |
10440 | highest-order bit of the "containing object" to the highest-order bit of |
10441 | the bit-field itself. Since the "high-order end" of any object or field | |
a3f97cbb JW |
10442 | is different on big-endian and little-endian machines, the computation |
10443 | below must take account of these differences. */ | |
10444 | highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; | |
10445 | highest_order_field_bit_offset = bitpos_int; | |
10446 | ||
71dfc51f | 10447 | if (! BYTES_BIG_ENDIAN) |
a3f97cbb | 10448 | { |
665f2503 | 10449 | highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0); |
a3f97cbb JW |
10450 | highest_order_object_bit_offset += simple_type_size_in_bits (type); |
10451 | } | |
71dfc51f RK |
10452 | |
10453 | bit_offset | |
10454 | = (! BYTES_BIG_ENDIAN | |
10455 | ? highest_order_object_bit_offset - highest_order_field_bit_offset | |
10456 | : highest_order_field_bit_offset - highest_order_object_bit_offset); | |
a3f97cbb JW |
10457 | |
10458 | add_AT_unsigned (die, DW_AT_bit_offset, bit_offset); | |
10459 | } | |
10460 | ||
10461 | /* For a FIELD_DECL node which represents a bit field, output an attribute | |
10462 | which specifies the length in bits of the given field. */ | |
71dfc51f RK |
10463 | |
10464 | static inline void | |
7080f735 | 10465 | add_bit_size_attribute (dw_die_ref die, tree decl) |
a3f97cbb | 10466 | { |
3a88cbd1 JL |
10467 | /* Must be a field and a bit field. */ |
10468 | if (TREE_CODE (decl) != FIELD_DECL | |
10469 | || ! DECL_BIT_FIELD_TYPE (decl)) | |
10470 | abort (); | |
665f2503 RK |
10471 | |
10472 | if (host_integerp (DECL_SIZE (decl), 1)) | |
10473 | add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1)); | |
a3f97cbb JW |
10474 | } |
10475 | ||
88dad228 | 10476 | /* If the compiled language is ANSI C, then add a 'prototyped' |
a3f97cbb | 10477 | attribute, if arg types are given for the parameters of a function. */ |
71dfc51f RK |
10478 | |
10479 | static inline void | |
7080f735 | 10480 | add_prototyped_attribute (dw_die_ref die, tree func_type) |
a3f97cbb | 10481 | { |
88dad228 JM |
10482 | if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89 |
10483 | && TYPE_ARG_TYPES (func_type) != NULL) | |
10484 | add_AT_flag (die, DW_AT_prototyped, 1); | |
a3f97cbb JW |
10485 | } |
10486 | ||
a3f97cbb JW |
10487 | /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found |
10488 | by looking in either the type declaration or object declaration | |
10489 | equate table. */ | |
71dfc51f RK |
10490 | |
10491 | static inline void | |
7080f735 | 10492 | add_abstract_origin_attribute (dw_die_ref die, tree origin) |
a3f97cbb JW |
10493 | { |
10494 | dw_die_ref origin_die = NULL; | |
bbc6ae08 | 10495 | |
d10b8e05 | 10496 | if (TREE_CODE (origin) != FUNCTION_DECL) |
e40a1c67 JM |
10497 | { |
10498 | /* We may have gotten separated from the block for the inlined | |
10499 | function, if we're in an exception handler or some such; make | |
10500 | sure that the abstract function has been written out. | |
10501 | ||
73c68f61 | 10502 | Doing this for nested functions is wrong, however; functions are |
e40a1c67 | 10503 | distinct units, and our context might not even be inline. */ |
fb13d4d0 | 10504 | tree fn = origin; |
2ad9852d | 10505 | |
fb13d4d0 JM |
10506 | if (TYPE_P (fn)) |
10507 | fn = TYPE_STUB_DECL (fn); | |
2ad9852d | 10508 | |
fb13d4d0 | 10509 | fn = decl_function_context (fn); |
e40a1c67 | 10510 | if (fn) |
1edf43d6 | 10511 | dwarf2out_abstract_function (fn); |
e40a1c67 | 10512 | } |
44db1d9c | 10513 | |
2f939d94 | 10514 | if (DECL_P (origin)) |
71dfc51f | 10515 | origin_die = lookup_decl_die (origin); |
2f939d94 | 10516 | else if (TYPE_P (origin)) |
71dfc51f RK |
10517 | origin_die = lookup_type_die (origin); |
10518 | ||
bbc6ae08 | 10519 | if (origin_die == NULL) |
1ae8994f | 10520 | abort (); |
556273e0 | 10521 | |
a3f97cbb JW |
10522 | add_AT_die_ref (die, DW_AT_abstract_origin, origin_die); |
10523 | } | |
10524 | ||
bdb669cb JM |
10525 | /* We do not currently support the pure_virtual attribute. */ |
10526 | ||
71dfc51f | 10527 | static inline void |
7080f735 | 10528 | add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl) |
a3f97cbb | 10529 | { |
a94dbf2c | 10530 | if (DECL_VINDEX (func_decl)) |
a3f97cbb | 10531 | { |
bdb669cb | 10532 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); |
665f2503 RK |
10533 | |
10534 | if (host_integerp (DECL_VINDEX (func_decl), 0)) | |
10535 | add_AT_loc (die, DW_AT_vtable_elem_location, | |
10536 | new_loc_descr (DW_OP_constu, | |
10537 | tree_low_cst (DECL_VINDEX (func_decl), 0), | |
10538 | 0)); | |
71dfc51f | 10539 | |
a94dbf2c JM |
10540 | /* GNU extension: Record what type this method came from originally. */ |
10541 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
10542 | add_AT_die_ref (die, DW_AT_containing_type, | |
10543 | lookup_type_die (DECL_CONTEXT (func_decl))); | |
a3f97cbb JW |
10544 | } |
10545 | } | |
10546 | \f | |
b2932ae5 | 10547 | /* Add source coordinate attributes for the given decl. */ |
71dfc51f | 10548 | |
b2932ae5 | 10549 | static void |
7080f735 | 10550 | add_src_coords_attributes (dw_die_ref die, tree decl) |
b2932ae5 | 10551 | { |
6773e15f PB |
10552 | expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl)); |
10553 | unsigned file_index = lookup_filename (s.file); | |
71dfc51f | 10554 | |
b2932ae5 | 10555 | add_AT_unsigned (die, DW_AT_decl_file, file_index); |
6773e15f | 10556 | add_AT_unsigned (die, DW_AT_decl_line, s.line); |
b2932ae5 JM |
10557 | } |
10558 | ||
b20b352b | 10559 | /* Add a DW_AT_name attribute and source coordinate attribute for the |
a3f97cbb | 10560 | given decl, but only if it actually has a name. */ |
71dfc51f | 10561 | |
a3f97cbb | 10562 | static void |
7080f735 | 10563 | add_name_and_src_coords_attributes (dw_die_ref die, tree decl) |
a3f97cbb | 10564 | { |
b3694847 | 10565 | tree decl_name; |
71dfc51f | 10566 | |
556273e0 | 10567 | decl_name = DECL_NAME (decl); |
71dfc51f | 10568 | if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL) |
a3f97cbb | 10569 | { |
a1d7ffe3 | 10570 | add_name_attribute (die, dwarf2_name (decl, 0)); |
a96c67ec JM |
10571 | if (! DECL_ARTIFICIAL (decl)) |
10572 | add_src_coords_attributes (die, decl); | |
e689ae67 | 10573 | |
a1d7ffe3 | 10574 | if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) |
bc808e0b | 10575 | && TREE_PUBLIC (decl) |
5daf7c0a JM |
10576 | && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) |
10577 | && !DECL_ABSTRACT (decl)) | |
a1d7ffe3 JM |
10578 | add_AT_string (die, DW_AT_MIPS_linkage_name, |
10579 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
a3f97cbb | 10580 | } |
7a0c8d71 DR |
10581 | |
10582 | #ifdef VMS_DEBUGGING_INFO | |
7a0c8d71 DR |
10583 | /* Get the function's name, as described by its RTL. This may be different |
10584 | from the DECL_NAME name used in the source file. */ | |
10585 | if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl)) | |
c470afad RK |
10586 | { |
10587 | add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address, | |
10588 | XEXP (DECL_RTL (decl), 0)); | |
10589 | VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0)); | |
10590 | } | |
7a0c8d71 | 10591 | #endif |
a3f97cbb JW |
10592 | } |
10593 | ||
556273e0 | 10594 | /* Push a new declaration scope. */ |
71dfc51f | 10595 | |
a3f97cbb | 10596 | static void |
7080f735 | 10597 | push_decl_scope (tree scope) |
a3f97cbb | 10598 | { |
244a4af0 | 10599 | VARRAY_PUSH_TREE (decl_scope_table, scope); |
a3f97cbb JW |
10600 | } |
10601 | ||
777ad4c2 | 10602 | /* Pop a declaration scope. */ |
2ad9852d | 10603 | |
777ad4c2 | 10604 | static inline void |
7080f735 | 10605 | pop_decl_scope (void) |
777ad4c2 | 10606 | { |
244a4af0 | 10607 | if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0) |
777ad4c2 | 10608 | abort (); |
2ad9852d | 10609 | |
244a4af0 | 10610 | VARRAY_POP (decl_scope_table); |
777ad4c2 JM |
10611 | } |
10612 | ||
10613 | /* Return the DIE for the scope that immediately contains this type. | |
10614 | Non-named types get global scope. Named types nested in other | |
10615 | types get their containing scope if it's open, or global scope | |
10616 | otherwise. All other types (i.e. function-local named types) get | |
10617 | the current active scope. */ | |
71dfc51f | 10618 | |
a3f97cbb | 10619 | static dw_die_ref |
7080f735 | 10620 | scope_die_for (tree t, dw_die_ref context_die) |
a3f97cbb | 10621 | { |
b3694847 SS |
10622 | dw_die_ref scope_die = NULL; |
10623 | tree containing_scope; | |
10624 | int i; | |
a3f97cbb | 10625 | |
777ad4c2 JM |
10626 | /* Non-types always go in the current scope. */ |
10627 | if (! TYPE_P (t)) | |
10628 | abort (); | |
10629 | ||
10630 | containing_scope = TYPE_CONTEXT (t); | |
ab72d377 | 10631 | |
66c78aa9 | 10632 | /* Use the containing namespace if it was passed in (for a declaration). */ |
2addbe1d | 10633 | if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL) |
66c78aa9 JM |
10634 | { |
10635 | if (context_die == lookup_decl_die (containing_scope)) | |
10636 | /* OK */; | |
10637 | else | |
10638 | containing_scope = NULL_TREE; | |
10639 | } | |
2addbe1d | 10640 | |
5f2f160c JM |
10641 | /* Ignore function type "scopes" from the C frontend. They mean that |
10642 | a tagged type is local to a parmlist of a function declarator, but | |
10643 | that isn't useful to DWARF. */ | |
10644 | if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE) | |
10645 | containing_scope = NULL_TREE; | |
10646 | ||
71dfc51f RK |
10647 | if (containing_scope == NULL_TREE) |
10648 | scope_die = comp_unit_die; | |
777ad4c2 | 10649 | else if (TYPE_P (containing_scope)) |
348bb3c7 | 10650 | { |
777ad4c2 JM |
10651 | /* For types, we can just look up the appropriate DIE. But |
10652 | first we check to see if we're in the middle of emitting it | |
10653 | so we know where the new DIE should go. */ | |
244a4af0 TF |
10654 | for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i) |
10655 | if (VARRAY_TREE (decl_scope_table, i) == containing_scope) | |
348bb3c7 JM |
10656 | break; |
10657 | ||
10658 | if (i < 0) | |
10659 | { | |
348bb3c7 JM |
10660 | if (debug_info_level > DINFO_LEVEL_TERSE |
10661 | && !TREE_ASM_WRITTEN (containing_scope)) | |
10662 | abort (); | |
10663 | ||
10664 | /* If none of the current dies are suitable, we get file scope. */ | |
10665 | scope_die = comp_unit_die; | |
10666 | } | |
10667 | else | |
777ad4c2 | 10668 | scope_die = lookup_type_die (containing_scope); |
348bb3c7 | 10669 | } |
a3f97cbb | 10670 | else |
777ad4c2 | 10671 | scope_die = context_die; |
71dfc51f | 10672 | |
a3f97cbb JW |
10673 | return scope_die; |
10674 | } | |
10675 | ||
2ad9852d | 10676 | /* Returns nonzero if CONTEXT_DIE is internal to a function. */ |
777ad4c2 JM |
10677 | |
10678 | static inline int | |
7080f735 | 10679 | local_scope_p (dw_die_ref context_die) |
a3f97cbb | 10680 | { |
777ad4c2 JM |
10681 | for (; context_die; context_die = context_die->die_parent) |
10682 | if (context_die->die_tag == DW_TAG_inlined_subroutine | |
10683 | || context_die->die_tag == DW_TAG_subprogram) | |
10684 | return 1; | |
2ad9852d | 10685 | |
777ad4c2 | 10686 | return 0; |
a3f97cbb JW |
10687 | } |
10688 | ||
66c78aa9 JM |
10689 | /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding |
10690 | whether or not to treat a DIE in this context as a declaration. */ | |
9765e357 JM |
10691 | |
10692 | static inline int | |
66c78aa9 | 10693 | class_or_namespace_scope_p (dw_die_ref context_die) |
9765e357 JM |
10694 | { |
10695 | return (context_die | |
10696 | && (context_die->die_tag == DW_TAG_structure_type | |
66c78aa9 JM |
10697 | || context_die->die_tag == DW_TAG_union_type |
10698 | || context_die->die_tag == DW_TAG_namespace)); | |
9765e357 JM |
10699 | } |
10700 | ||
a3f97cbb JW |
10701 | /* Many forms of DIEs require a "type description" attribute. This |
10702 | routine locates the proper "type descriptor" die for the type given | |
b20b352b | 10703 | by 'type', and adds a DW_AT_type attribute below the given die. */ |
71dfc51f | 10704 | |
a3f97cbb | 10705 | static void |
7080f735 AJ |
10706 | add_type_attribute (dw_die_ref object_die, tree type, int decl_const, |
10707 | int decl_volatile, dw_die_ref context_die) | |
a3f97cbb | 10708 | { |
b3694847 SS |
10709 | enum tree_code code = TREE_CODE (type); |
10710 | dw_die_ref type_die = NULL; | |
a3f97cbb | 10711 | |
ef76d03b JW |
10712 | /* ??? If this type is an unnamed subrange type of an integral or |
10713 | floating-point type, use the inner type. This is because we have no | |
10714 | support for unnamed types in base_type_die. This can happen if this is | |
10715 | an Ada subrange type. Correct solution is emit a subrange type die. */ | |
b1ccbc24 RK |
10716 | if ((code == INTEGER_TYPE || code == REAL_TYPE) |
10717 | && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0) | |
10718 | type = TREE_TYPE (type), code = TREE_CODE (type); | |
10719 | ||
2ad9852d RK |
10720 | if (code == ERROR_MARK |
10721 | /* Handle a special case. For functions whose return type is void, we | |
10722 | generate *no* type attribute. (Note that no object may have type | |
10723 | `void', so this only applies to function return types). */ | |
10724 | || code == VOID_TYPE) | |
b1ccbc24 | 10725 | return; |
a3f97cbb | 10726 | |
a3f97cbb JW |
10727 | type_die = modified_type_die (type, |
10728 | decl_const || TYPE_READONLY (type), | |
10729 | decl_volatile || TYPE_VOLATILE (type), | |
ab72d377 | 10730 | context_die); |
2ad9852d | 10731 | |
a3f97cbb | 10732 | if (type_die != NULL) |
71dfc51f | 10733 | add_AT_die_ref (object_die, DW_AT_type, type_die); |
a3f97cbb JW |
10734 | } |
10735 | ||
10736 | /* Given a tree pointer to a struct, class, union, or enum type node, return | |
10737 | a pointer to the (string) tag name for the given type, or zero if the type | |
10738 | was declared without a tag. */ | |
71dfc51f | 10739 | |
d3e3972c | 10740 | static const char * |
7080f735 | 10741 | type_tag (tree type) |
a3f97cbb | 10742 | { |
b3694847 | 10743 | const char *name = 0; |
a3f97cbb JW |
10744 | |
10745 | if (TYPE_NAME (type) != 0) | |
10746 | { | |
b3694847 | 10747 | tree t = 0; |
a3f97cbb JW |
10748 | |
10749 | /* Find the IDENTIFIER_NODE for the type name. */ | |
10750 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
10751 | t = TYPE_NAME (type); | |
bdb669cb | 10752 | |
556273e0 | 10753 | /* The g++ front end makes the TYPE_NAME of *each* tagged type point to |
73c68f61 SS |
10754 | a TYPE_DECL node, regardless of whether or not a `typedef' was |
10755 | involved. */ | |
a94dbf2c JM |
10756 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
10757 | && ! DECL_IGNORED_P (TYPE_NAME (type))) | |
a3f97cbb | 10758 | t = DECL_NAME (TYPE_NAME (type)); |
bdb669cb | 10759 | |
a3f97cbb JW |
10760 | /* Now get the name as a string, or invent one. */ |
10761 | if (t != 0) | |
a94dbf2c | 10762 | name = IDENTIFIER_POINTER (t); |
a3f97cbb | 10763 | } |
71dfc51f | 10764 | |
a3f97cbb JW |
10765 | return (name == 0 || *name == '\0') ? 0 : name; |
10766 | } | |
10767 | ||
10768 | /* Return the type associated with a data member, make a special check | |
10769 | for bit field types. */ | |
71dfc51f RK |
10770 | |
10771 | static inline tree | |
7080f735 | 10772 | member_declared_type (tree member) |
a3f97cbb | 10773 | { |
71dfc51f | 10774 | return (DECL_BIT_FIELD_TYPE (member) |
2ad9852d | 10775 | ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member)); |
a3f97cbb JW |
10776 | } |
10777 | ||
d291dd49 | 10778 | /* Get the decl's label, as described by its RTL. This may be different |
a3f97cbb | 10779 | from the DECL_NAME name used in the source file. */ |
71dfc51f | 10780 | |
487a6e06 | 10781 | #if 0 |
d3e3972c | 10782 | static const char * |
7080f735 | 10783 | decl_start_label (tree decl) |
a3f97cbb JW |
10784 | { |
10785 | rtx x; | |
d3e3972c | 10786 | const char *fnname; |
2ad9852d | 10787 | |
a3f97cbb | 10788 | x = DECL_RTL (decl); |
3c0cb5de | 10789 | if (!MEM_P (x)) |
71dfc51f RK |
10790 | abort (); |
10791 | ||
a3f97cbb JW |
10792 | x = XEXP (x, 0); |
10793 | if (GET_CODE (x) != SYMBOL_REF) | |
71dfc51f RK |
10794 | abort (); |
10795 | ||
a3f97cbb JW |
10796 | fnname = XSTR (x, 0); |
10797 | return fnname; | |
10798 | } | |
487a6e06 | 10799 | #endif |
a3f97cbb | 10800 | \f |
956d6950 | 10801 | /* These routines generate the internal representation of the DIE's for |
a3f97cbb | 10802 | the compilation unit. Debugging information is collected by walking |
88dad228 | 10803 | the declaration trees passed in from dwarf2out_decl(). */ |
a3f97cbb JW |
10804 | |
10805 | static void | |
7080f735 | 10806 | gen_array_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 10807 | { |
b3694847 SS |
10808 | dw_die_ref scope_die = scope_die_for (type, context_die); |
10809 | dw_die_ref array_die; | |
10810 | tree element_type; | |
bdb669cb | 10811 | |
a9d38797 JM |
10812 | /* ??? The SGI dwarf reader fails for array of array of enum types unless |
10813 | the inner array type comes before the outer array type. Thus we must | |
10814 | call gen_type_die before we call new_die. See below also. */ | |
10815 | #ifdef MIPS_DEBUGGING_INFO | |
10816 | gen_type_die (TREE_TYPE (type), context_die); | |
10817 | #endif | |
10818 | ||
54ba1f0d | 10819 | array_die = new_die (DW_TAG_array_type, scope_die, type); |
84f0ace0 JM |
10820 | add_name_attribute (array_die, type_tag (type)); |
10821 | equate_type_number_to_die (type, array_die); | |
10822 | ||
10823 | if (TREE_CODE (type) == VECTOR_TYPE) | |
10824 | { | |
10825 | /* The frontend feeds us a representation for the vector as a struct | |
10826 | containing an array. Pull out the array type. */ | |
10827 | type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type))); | |
10828 | add_AT_flag (array_die, DW_AT_GNU_vector, 1); | |
10829 | } | |
a9d38797 | 10830 | |
a3f97cbb JW |
10831 | #if 0 |
10832 | /* We default the array ordering. SDB will probably do | |
10833 | the right things even if DW_AT_ordering is not present. It's not even | |
10834 | an issue until we start to get into multidimensional arrays anyway. If | |
10835 | SDB is ever caught doing the Wrong Thing for multi-dimensional arrays, | |
10836 | then we'll have to put the DW_AT_ordering attribute back in. (But if | |
10837 | and when we find out that we need to put these in, we will only do so | |
10838 | for multidimensional arrays. */ | |
10839 | add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major); | |
10840 | #endif | |
10841 | ||
a9d38797 | 10842 | #ifdef MIPS_DEBUGGING_INFO |
4edb7b60 JM |
10843 | /* The SGI compilers handle arrays of unknown bound by setting |
10844 | AT_declaration and not emitting any subrange DIEs. */ | |
a9d38797 | 10845 | if (! TYPE_DOMAIN (type)) |
371e8c4f | 10846 | add_AT_flag (array_die, DW_AT_declaration, 1); |
a9d38797 JM |
10847 | else |
10848 | #endif | |
10849 | add_subscript_info (array_die, type); | |
a3f97cbb | 10850 | |
a3f97cbb JW |
10851 | /* Add representation of the type of the elements of this array type. */ |
10852 | element_type = TREE_TYPE (type); | |
71dfc51f | 10853 | |
a3f97cbb JW |
10854 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
10855 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
10856 | We work around this by disabling this feature. See also | |
10857 | add_subscript_info. */ | |
10858 | #ifndef MIPS_DEBUGGING_INFO | |
71dfc51f RK |
10859 | while (TREE_CODE (element_type) == ARRAY_TYPE) |
10860 | element_type = TREE_TYPE (element_type); | |
10861 | ||
a3f97cbb | 10862 | gen_type_die (element_type, context_die); |
a9d38797 | 10863 | #endif |
a3f97cbb JW |
10864 | |
10865 | add_type_attribute (array_die, element_type, 0, 0, context_die); | |
10866 | } | |
10867 | ||
10868 | static void | |
7080f735 | 10869 | gen_set_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 10870 | { |
b3694847 | 10871 | dw_die_ref type_die |
54ba1f0d | 10872 | = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type); |
71dfc51f | 10873 | |
a3f97cbb | 10874 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
10875 | add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die); |
10876 | } | |
10877 | ||
d6f4ec51 | 10878 | #if 0 |
a3f97cbb | 10879 | static void |
7080f735 | 10880 | gen_entry_point_die (tree decl, dw_die_ref context_die) |
a3f97cbb | 10881 | { |
b3694847 | 10882 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 10883 | dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl); |
2ad9852d | 10884 | |
a3f97cbb | 10885 | if (origin != NULL) |
71dfc51f | 10886 | add_abstract_origin_attribute (decl_die, origin); |
a3f97cbb JW |
10887 | else |
10888 | { | |
10889 | add_name_and_src_coords_attributes (decl_die, decl); | |
a3f97cbb JW |
10890 | add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)), |
10891 | 0, 0, context_die); | |
10892 | } | |
71dfc51f | 10893 | |
a3f97cbb | 10894 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 10895 | equate_decl_number_to_die (decl, decl_die); |
a3f97cbb | 10896 | else |
71dfc51f | 10897 | add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl)); |
a3f97cbb | 10898 | } |
d6f4ec51 | 10899 | #endif |
a3f97cbb | 10900 | |
8a8c3656 JM |
10901 | /* Walk through the list of incomplete types again, trying once more to |
10902 | emit full debugging info for them. */ | |
10903 | ||
10904 | static void | |
7080f735 | 10905 | retry_incomplete_types (void) |
8a8c3656 | 10906 | { |
244a4af0 | 10907 | int i; |
2ad9852d | 10908 | |
244a4af0 | 10909 | for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--) |
2ad9852d | 10910 | gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die); |
8a8c3656 JM |
10911 | } |
10912 | ||
a3f97cbb | 10913 | /* Generate a DIE to represent an inlined instance of an enumeration type. */ |
71dfc51f | 10914 | |
a3f97cbb | 10915 | static void |
7080f735 | 10916 | gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 10917 | { |
54ba1f0d | 10918 | dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type); |
2ad9852d | 10919 | |
bbc6ae08 NC |
10920 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
10921 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
10922 | add_abstract_origin_attribute (type_die, type); |
10923 | } | |
10924 | ||
10925 | /* Generate a DIE to represent an inlined instance of a structure type. */ | |
71dfc51f | 10926 | |
a3f97cbb | 10927 | static void |
7080f735 | 10928 | gen_inlined_structure_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 10929 | { |
54ba1f0d | 10930 | dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type); |
777ad4c2 | 10931 | |
bbc6ae08 NC |
10932 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
10933 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
10934 | add_abstract_origin_attribute (type_die, type); |
10935 | } | |
10936 | ||
10937 | /* Generate a DIE to represent an inlined instance of a union type. */ | |
71dfc51f | 10938 | |
a3f97cbb | 10939 | static void |
7080f735 | 10940 | gen_inlined_union_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 10941 | { |
54ba1f0d | 10942 | dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type); |
777ad4c2 | 10943 | |
bbc6ae08 NC |
10944 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
10945 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
10946 | add_abstract_origin_attribute (type_die, type); |
10947 | } | |
10948 | ||
10949 | /* Generate a DIE to represent an enumeration type. Note that these DIEs | |
10950 | include all of the information about the enumeration values also. Each | |
273dbe67 JM |
10951 | enumerated type name/value is listed as a child of the enumerated type |
10952 | DIE. */ | |
71dfc51f | 10953 | |
de99511b | 10954 | static dw_die_ref |
7080f735 | 10955 | gen_enumeration_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 10956 | { |
b3694847 | 10957 | dw_die_ref type_die = lookup_type_die (type); |
273dbe67 | 10958 | |
a3f97cbb JW |
10959 | if (type_die == NULL) |
10960 | { | |
10961 | type_die = new_die (DW_TAG_enumeration_type, | |
54ba1f0d | 10962 | scope_die_for (type, context_die), type); |
a3f97cbb JW |
10963 | equate_type_number_to_die (type, type_die); |
10964 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 10965 | } |
273dbe67 | 10966 | else if (! TYPE_SIZE (type)) |
de99511b | 10967 | return type_die; |
273dbe67 JM |
10968 | else |
10969 | remove_AT (type_die, DW_AT_declaration); | |
10970 | ||
10971 | /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the | |
10972 | given enum type is incomplete, do not generate the DW_AT_byte_size | |
10973 | attribute or the DW_AT_element_list attribute. */ | |
10974 | if (TYPE_SIZE (type)) | |
a3f97cbb | 10975 | { |
b3694847 | 10976 | tree link; |
71dfc51f | 10977 | |
a082c85a | 10978 | TREE_ASM_WRITTEN (type) = 1; |
273dbe67 | 10979 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 10980 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 10981 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 10982 | |
ef76d03b JW |
10983 | /* If the first reference to this type was as the return type of an |
10984 | inline function, then it may not have a parent. Fix this now. */ | |
10985 | if (type_die->die_parent == NULL) | |
10986 | add_child_die (scope_die_for (type, context_die), type_die); | |
10987 | ||
eb34af89 | 10988 | for (link = TYPE_VALUES (type); |
273dbe67 | 10989 | link != NULL; link = TREE_CHAIN (link)) |
a3f97cbb | 10990 | { |
54ba1f0d | 10991 | dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link); |
5bb2ed2c | 10992 | tree value = TREE_VALUE (link); |
71dfc51f | 10993 | |
273dbe67 JM |
10994 | add_name_attribute (enum_die, |
10995 | IDENTIFIER_POINTER (TREE_PURPOSE (link))); | |
665f2503 | 10996 | |
8df83eae | 10997 | if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value)))) |
5bb2ed2c MM |
10998 | /* DWARF2 does not provide a way of indicating whether or |
10999 | not enumeration constants are signed or unsigned. GDB | |
11000 | always assumes the values are signed, so we output all | |
11001 | values as if they were signed. That means that | |
11002 | enumeration constants with very large unsigned values | |
11003 | will appear to have negative values in the debugger. */ | |
11004 | add_AT_int (enum_die, DW_AT_const_value, | |
11005 | tree_low_cst (value, tree_int_cst_sgn (value) > 0)); | |
a3f97cbb JW |
11006 | } |
11007 | } | |
273dbe67 JM |
11008 | else |
11009 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
de99511b B |
11010 | |
11011 | return type_die; | |
a3f97cbb JW |
11012 | } |
11013 | ||
a3f97cbb JW |
11014 | /* Generate a DIE to represent either a real live formal parameter decl or to |
11015 | represent just the type of some formal parameter position in some function | |
11016 | type. | |
71dfc51f | 11017 | |
a3f97cbb JW |
11018 | Note that this routine is a bit unusual because its argument may be a |
11019 | ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which | |
11020 | represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE | |
11021 | node. If it's the former then this function is being called to output a | |
11022 | DIE to represent a formal parameter object (or some inlining thereof). If | |
11023 | it's the latter, then this function is only being called to output a | |
11024 | DW_TAG_formal_parameter DIE to stand as a placeholder for some formal | |
11025 | argument type of some subprogram type. */ | |
71dfc51f | 11026 | |
a94dbf2c | 11027 | static dw_die_ref |
7080f735 | 11028 | gen_formal_parameter_die (tree node, dw_die_ref context_die) |
a3f97cbb | 11029 | { |
b3694847 | 11030 | dw_die_ref parm_die |
54ba1f0d | 11031 | = new_die (DW_TAG_formal_parameter, context_die, node); |
b3694847 | 11032 | tree origin; |
71dfc51f | 11033 | |
a3f97cbb JW |
11034 | switch (TREE_CODE_CLASS (TREE_CODE (node))) |
11035 | { | |
a3f97cbb JW |
11036 | case 'd': |
11037 | origin = decl_ultimate_origin (node); | |
11038 | if (origin != NULL) | |
a94dbf2c | 11039 | add_abstract_origin_attribute (parm_die, origin); |
a3f97cbb JW |
11040 | else |
11041 | { | |
11042 | add_name_and_src_coords_attributes (parm_die, node); | |
11043 | add_type_attribute (parm_die, TREE_TYPE (node), | |
11044 | TREE_READONLY (node), | |
11045 | TREE_THIS_VOLATILE (node), | |
11046 | context_die); | |
bdb669cb JM |
11047 | if (DECL_ARTIFICIAL (node)) |
11048 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb | 11049 | } |
71dfc51f | 11050 | |
141719a8 JM |
11051 | equate_decl_number_to_die (node, parm_die); |
11052 | if (! DECL_ABSTRACT (node)) | |
0a2d3d69 | 11053 | add_location_or_const_value_attribute (parm_die, node, DW_AT_location); |
71dfc51f | 11054 | |
a3f97cbb JW |
11055 | break; |
11056 | ||
a3f97cbb | 11057 | case 't': |
71dfc51f | 11058 | /* We were called with some kind of a ..._TYPE node. */ |
a3f97cbb JW |
11059 | add_type_attribute (parm_die, node, 0, 0, context_die); |
11060 | break; | |
11061 | ||
a3f97cbb JW |
11062 | default: |
11063 | abort (); | |
11064 | } | |
71dfc51f | 11065 | |
a94dbf2c | 11066 | return parm_die; |
a3f97cbb JW |
11067 | } |
11068 | ||
11069 | /* Generate a special type of DIE used as a stand-in for a trailing ellipsis | |
11070 | at the end of an (ANSI prototyped) formal parameters list. */ | |
71dfc51f | 11071 | |
a3f97cbb | 11072 | static void |
7080f735 | 11073 | gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die) |
a3f97cbb | 11074 | { |
54ba1f0d | 11075 | new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type); |
a3f97cbb JW |
11076 | } |
11077 | ||
11078 | /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a | |
11079 | DW_TAG_unspecified_parameters DIE) to represent the types of the formal | |
11080 | parameters as specified in some function type specification (except for | |
1cfdcc15 | 11081 | those which appear as part of a function *definition*). */ |
71dfc51f | 11082 | |
a3f97cbb | 11083 | static void |
7080f735 | 11084 | gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die) |
a3f97cbb | 11085 | { |
b3694847 SS |
11086 | tree link; |
11087 | tree formal_type = NULL; | |
11088 | tree first_parm_type; | |
5daf7c0a | 11089 | tree arg; |
a3f97cbb | 11090 | |
5daf7c0a JM |
11091 | if (TREE_CODE (function_or_method_type) == FUNCTION_DECL) |
11092 | { | |
11093 | arg = DECL_ARGUMENTS (function_or_method_type); | |
11094 | function_or_method_type = TREE_TYPE (function_or_method_type); | |
11095 | } | |
11096 | else | |
11097 | arg = NULL_TREE; | |
c26fbbca | 11098 | |
5daf7c0a | 11099 | first_parm_type = TYPE_ARG_TYPES (function_or_method_type); |
a3f97cbb | 11100 | |
556273e0 | 11101 | /* Make our first pass over the list of formal parameter types and output a |
a3f97cbb | 11102 | DW_TAG_formal_parameter DIE for each one. */ |
5daf7c0a | 11103 | for (link = first_parm_type; link; ) |
a3f97cbb | 11104 | { |
b3694847 | 11105 | dw_die_ref parm_die; |
556273e0 | 11106 | |
a3f97cbb JW |
11107 | formal_type = TREE_VALUE (link); |
11108 | if (formal_type == void_type_node) | |
11109 | break; | |
11110 | ||
11111 | /* Output a (nameless) DIE to represent the formal parameter itself. */ | |
a94dbf2c | 11112 | parm_die = gen_formal_parameter_die (formal_type, context_die); |
5daf7c0a JM |
11113 | if ((TREE_CODE (function_or_method_type) == METHOD_TYPE |
11114 | && link == first_parm_type) | |
11115 | || (arg && DECL_ARTIFICIAL (arg))) | |
a94dbf2c | 11116 | add_AT_flag (parm_die, DW_AT_artificial, 1); |
5daf7c0a JM |
11117 | |
11118 | link = TREE_CHAIN (link); | |
11119 | if (arg) | |
11120 | arg = TREE_CHAIN (arg); | |
a3f97cbb JW |
11121 | } |
11122 | ||
11123 | /* If this function type has an ellipsis, add a | |
11124 | DW_TAG_unspecified_parameters DIE to the end of the parameter list. */ | |
11125 | if (formal_type != void_type_node) | |
11126 | gen_unspecified_parameters_die (function_or_method_type, context_die); | |
11127 | ||
556273e0 | 11128 | /* Make our second (and final) pass over the list of formal parameter types |
a3f97cbb JW |
11129 | and output DIEs to represent those types (as necessary). */ |
11130 | for (link = TYPE_ARG_TYPES (function_or_method_type); | |
2ad9852d | 11131 | link && TREE_VALUE (link); |
a3f97cbb | 11132 | link = TREE_CHAIN (link)) |
2ad9852d | 11133 | gen_type_die (TREE_VALUE (link), context_die); |
a3f97cbb JW |
11134 | } |
11135 | ||
10a11b75 JM |
11136 | /* We want to generate the DIE for TYPE so that we can generate the |
11137 | die for MEMBER, which has been defined; we will need to refer back | |
11138 | to the member declaration nested within TYPE. If we're trying to | |
11139 | generate minimal debug info for TYPE, processing TYPE won't do the | |
11140 | trick; we need to attach the member declaration by hand. */ | |
11141 | ||
11142 | static void | |
7080f735 | 11143 | gen_type_die_for_member (tree type, tree member, dw_die_ref context_die) |
10a11b75 JM |
11144 | { |
11145 | gen_type_die (type, context_die); | |
11146 | ||
11147 | /* If we're trying to avoid duplicate debug info, we may not have | |
11148 | emitted the member decl for this function. Emit it now. */ | |
11149 | if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)) | |
11150 | && ! lookup_decl_die (member)) | |
11151 | { | |
11152 | if (decl_ultimate_origin (member)) | |
11153 | abort (); | |
11154 | ||
11155 | push_decl_scope (type); | |
11156 | if (TREE_CODE (member) == FUNCTION_DECL) | |
11157 | gen_subprogram_die (member, lookup_type_die (type)); | |
11158 | else | |
11159 | gen_variable_die (member, lookup_type_die (type)); | |
2ad9852d | 11160 | |
10a11b75 JM |
11161 | pop_decl_scope (); |
11162 | } | |
11163 | } | |
11164 | ||
2ad9852d RK |
11165 | /* Generate the DWARF2 info for the "abstract" instance of a function which we |
11166 | may later generate inlined and/or out-of-line instances of. */ | |
10a11b75 | 11167 | |
e1772ac0 | 11168 | static void |
7080f735 | 11169 | dwarf2out_abstract_function (tree decl) |
10a11b75 | 11170 | { |
b3694847 | 11171 | dw_die_ref old_die; |
777ad4c2 | 11172 | tree save_fn; |
5daf7c0a JM |
11173 | tree context; |
11174 | int was_abstract = DECL_ABSTRACT (decl); | |
11175 | ||
11176 | /* Make sure we have the actual abstract inline, not a clone. */ | |
11177 | decl = DECL_ORIGIN (decl); | |
10a11b75 | 11178 | |
c26fbbca | 11179 | old_die = lookup_decl_die (decl); |
ae0f3477 | 11180 | if (old_die && get_AT (old_die, DW_AT_inline)) |
10a11b75 JM |
11181 | /* We've already generated the abstract instance. */ |
11182 | return; | |
11183 | ||
5daf7c0a JM |
11184 | /* Be sure we've emitted the in-class declaration DIE (if any) first, so |
11185 | we don't get confused by DECL_ABSTRACT. */ | |
8458e954 JS |
11186 | if (debug_info_level > DINFO_LEVEL_TERSE) |
11187 | { | |
11188 | context = decl_class_context (decl); | |
11189 | if (context) | |
11190 | gen_type_die_for_member | |
11191 | (context, decl, decl_function_context (decl) ? NULL : comp_unit_die); | |
11192 | } | |
c26fbbca | 11193 | |
5daf7c0a | 11194 | /* Pretend we've just finished compiling this function. */ |
777ad4c2 JM |
11195 | save_fn = current_function_decl; |
11196 | current_function_decl = decl; | |
11197 | ||
10a11b75 JM |
11198 | set_decl_abstract_flags (decl, 1); |
11199 | dwarf2out_decl (decl); | |
5daf7c0a JM |
11200 | if (! was_abstract) |
11201 | set_decl_abstract_flags (decl, 0); | |
777ad4c2 JM |
11202 | |
11203 | current_function_decl = save_fn; | |
10a11b75 JM |
11204 | } |
11205 | ||
a3f97cbb JW |
11206 | /* Generate a DIE to represent a declared function (either file-scope or |
11207 | block-local). */ | |
71dfc51f | 11208 | |
a3f97cbb | 11209 | static void |
7080f735 | 11210 | gen_subprogram_die (tree decl, dw_die_ref context_die) |
a3f97cbb JW |
11211 | { |
11212 | char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 SS |
11213 | tree origin = decl_ultimate_origin (decl); |
11214 | dw_die_ref subr_die; | |
11215 | rtx fp_reg; | |
11216 | tree fn_arg_types; | |
11217 | tree outer_scope; | |
11218 | dw_die_ref old_die = lookup_decl_die (decl); | |
11219 | int declaration = (current_function_decl != decl | |
66c78aa9 | 11220 | || class_or_namespace_scope_p (context_die)); |
a3f97cbb | 11221 | |
2ad9852d RK |
11222 | /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we |
11223 | started to generate the abstract instance of an inline, decided to output | |
11224 | its containing class, and proceeded to emit the declaration of the inline | |
11225 | from the member list for the class. If so, DECLARATION takes priority; | |
11226 | we'll get back to the abstract instance when done with the class. */ | |
10a11b75 | 11227 | |
1cfdcc15 | 11228 | /* The class-scope declaration DIE must be the primary DIE. */ |
66c78aa9 | 11229 | if (origin && declaration && class_or_namespace_scope_p (context_die)) |
1cfdcc15 JM |
11230 | { |
11231 | origin = NULL; | |
11232 | if (old_die) | |
11233 | abort (); | |
11234 | } | |
11235 | ||
a3f97cbb JW |
11236 | if (origin != NULL) |
11237 | { | |
777ad4c2 | 11238 | if (declaration && ! local_scope_p (context_die)) |
10a11b75 JM |
11239 | abort (); |
11240 | ||
8d8238b6 JM |
11241 | /* Fixup die_parent for the abstract instance of a nested |
11242 | inline function. */ | |
11243 | if (old_die && old_die->die_parent == NULL) | |
11244 | add_child_die (context_die, old_die); | |
11245 | ||
54ba1f0d | 11246 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
a3f97cbb JW |
11247 | add_abstract_origin_attribute (subr_die, origin); |
11248 | } | |
bdb669cb JM |
11249 | else if (old_die) |
11250 | { | |
6773e15f PB |
11251 | expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl)); |
11252 | unsigned file_index = lookup_filename (s.file); | |
a94dbf2c | 11253 | |
1edf43d6 JM |
11254 | if (!get_AT_flag (old_die, DW_AT_declaration) |
11255 | /* We can have a normal definition following an inline one in the | |
11256 | case of redefinition of GNU C extern inlines. | |
11257 | It seems reasonable to use AT_specification in this case. */ | |
ae0f3477 | 11258 | && !get_AT (old_die, DW_AT_inline)) |
b75ab88b NC |
11259 | { |
11260 | /* ??? This can happen if there is a bug in the program, for | |
11261 | instance, if it has duplicate function definitions. Ideally, | |
11262 | we should detect this case and ignore it. For now, if we have | |
11263 | already reported an error, any error at all, then assume that | |
4fe9b91c | 11264 | we got here because of an input error, not a dwarf2 bug. */ |
b75ab88b NC |
11265 | if (errorcount) |
11266 | return; | |
11267 | abort (); | |
11268 | } | |
4b674448 JM |
11269 | |
11270 | /* If the definition comes from the same place as the declaration, | |
a94dbf2c JM |
11271 | maybe use the old DIE. We always want the DIE for this function |
11272 | that has the *_pc attributes to be under comp_unit_die so the | |
cb9e9d8d JM |
11273 | debugger can find it. We also need to do this for abstract |
11274 | instances of inlines, since the spec requires the out-of-line copy | |
11275 | to have the same parent. For local class methods, this doesn't | |
11276 | apply; we just use the old DIE. */ | |
11277 | if ((old_die->die_parent == comp_unit_die || context_die == NULL) | |
a96c67ec JM |
11278 | && (DECL_ARTIFICIAL (decl) |
11279 | || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index | |
11280 | && (get_AT_unsigned (old_die, DW_AT_decl_line) | |
6773e15f | 11281 | == (unsigned) s.line)))) |
bdb669cb | 11282 | { |
4b674448 JM |
11283 | subr_die = old_die; |
11284 | ||
6097b0c3 DP |
11285 | /* Clear out the declaration attribute and the formal parameters. |
11286 | Do not remove all children, because it is possible that this | |
11287 | declaration die was forced using force_decl_die(). In such | |
11288 | cases die that forced declaration die (e.g. TAG_imported_module) | |
11289 | is one of the children that we do not want to remove. */ | |
4b674448 | 11290 | remove_AT (subr_die, DW_AT_declaration); |
6097b0c3 | 11291 | remove_child_TAG (subr_die, DW_TAG_formal_parameter); |
4b674448 JM |
11292 | } |
11293 | else | |
11294 | { | |
54ba1f0d | 11295 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
47fcfa7b | 11296 | add_AT_specification (subr_die, old_die); |
bdb669cb JM |
11297 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
11298 | add_AT_unsigned (subr_die, DW_AT_decl_file, file_index); | |
11299 | if (get_AT_unsigned (old_die, DW_AT_decl_line) | |
6773e15f | 11300 | != (unsigned) s.line) |
bdb669cb | 11301 | add_AT_unsigned |
6773e15f | 11302 | (subr_die, DW_AT_decl_line, s.line); |
bdb669cb JM |
11303 | } |
11304 | } | |
a3f97cbb JW |
11305 | else |
11306 | { | |
54ba1f0d | 11307 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
556273e0 | 11308 | |
273dbe67 JM |
11309 | if (TREE_PUBLIC (decl)) |
11310 | add_AT_flag (subr_die, DW_AT_external, 1); | |
71dfc51f | 11311 | |
a3f97cbb | 11312 | add_name_and_src_coords_attributes (subr_die, decl); |
4927276d JM |
11313 | if (debug_info_level > DINFO_LEVEL_TERSE) |
11314 | { | |
2ad9852d RK |
11315 | add_prototyped_attribute (subr_die, TREE_TYPE (decl)); |
11316 | add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)), | |
11317 | 0, 0, context_die); | |
4927276d | 11318 | } |
71dfc51f | 11319 | |
a3f97cbb | 11320 | add_pure_or_virtual_attribute (subr_die, decl); |
273dbe67 JM |
11321 | if (DECL_ARTIFICIAL (decl)) |
11322 | add_AT_flag (subr_die, DW_AT_artificial, 1); | |
2ad9852d | 11323 | |
a94dbf2c JM |
11324 | if (TREE_PROTECTED (decl)) |
11325 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected); | |
11326 | else if (TREE_PRIVATE (decl)) | |
11327 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 11328 | } |
4edb7b60 | 11329 | |
a94dbf2c JM |
11330 | if (declaration) |
11331 | { | |
ae0f3477 | 11332 | if (!old_die || !get_AT (old_die, DW_AT_inline)) |
1edf43d6 JM |
11333 | { |
11334 | add_AT_flag (subr_die, DW_AT_declaration, 1); | |
11335 | ||
11336 | /* The first time we see a member function, it is in the context of | |
11337 | the class to which it belongs. We make sure of this by emitting | |
11338 | the class first. The next time is the definition, which is | |
6097b0c3 DP |
11339 | handled above. The two may come from the same source text. |
11340 | ||
11341 | Note that force_decl_die() forces function declaration die. It is | |
11342 | later reused to represent definition. */ | |
1edf43d6 JM |
11343 | equate_decl_number_to_die (decl, subr_die); |
11344 | } | |
a94dbf2c JM |
11345 | } |
11346 | else if (DECL_ABSTRACT (decl)) | |
a3f97cbb | 11347 | { |
1bb17c21 | 11348 | if (DECL_DECLARED_INLINE_P (decl)) |
61b32c02 | 11349 | { |
1bb17c21 | 11350 | if (cgraph_function_possibly_inlined_p (decl)) |
61b32c02 JM |
11351 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined); |
11352 | else | |
1bb17c21 | 11353 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined); |
61b32c02 | 11354 | } |
61b32c02 | 11355 | else |
1bb17c21 JH |
11356 | { |
11357 | if (cgraph_function_possibly_inlined_p (decl)) | |
11358 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined); | |
11359 | else | |
ae0f3477 | 11360 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined); |
1bb17c21 | 11361 | } |
61b32c02 | 11362 | |
a3f97cbb JW |
11363 | equate_decl_number_to_die (decl, subr_die); |
11364 | } | |
11365 | else if (!DECL_EXTERNAL (decl)) | |
11366 | { | |
ae0f3477 | 11367 | if (!old_die || !get_AT (old_die, DW_AT_inline)) |
ba7b35df | 11368 | equate_decl_number_to_die (decl, subr_die); |
71dfc51f | 11369 | |
5c90448c | 11370 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL, |
df696a75 | 11371 | current_function_funcdef_no); |
7d4440be | 11372 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id); |
5c90448c | 11373 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, |
df696a75 | 11374 | current_function_funcdef_no); |
a3f97cbb JW |
11375 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id); |
11376 | ||
d291dd49 JM |
11377 | add_pubname (decl, subr_die); |
11378 | add_arange (decl, subr_die); | |
11379 | ||
a3f97cbb | 11380 | #ifdef MIPS_DEBUGGING_INFO |
a3f97cbb JW |
11381 | /* Add a reference to the FDE for this routine. */ |
11382 | add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde); | |
11383 | #endif | |
11384 | ||
810429b7 | 11385 | /* Define the "frame base" location for this routine. We use the |
73c68f61 SS |
11386 | frame pointer or stack pointer registers, since the RTL for local |
11387 | variables is relative to one of them. */ | |
0a2d3d69 DB |
11388 | if (frame_base_decl && lookup_decl_loc (frame_base_decl) != NULL) |
11389 | { | |
11390 | add_location_or_const_value_attribute (subr_die, frame_base_decl, | |
11391 | DW_AT_frame_base); | |
11392 | } | |
11393 | else | |
11394 | { | |
11395 | fp_reg | |
11396 | = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx; | |
11397 | add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg)); | |
11398 | } | |
a3f97cbb | 11399 | |
6de9cd9a | 11400 | if (cfun->static_chain_decl) |
ef76d03b | 11401 | add_AT_location_description (subr_die, DW_AT_static_link, |
6de9cd9a | 11402 | loc_descriptor_from_tree (cfun->static_chain_decl, 0)); |
a3f97cbb JW |
11403 | } |
11404 | ||
11405 | /* Now output descriptions of the arguments for this function. This gets | |
556273e0 | 11406 | (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list |
a3f97cbb JW |
11407 | for a FUNCTION_DECL doesn't indicate cases where there was a trailing |
11408 | `...' at the end of the formal parameter list. In order to find out if | |
11409 | there was a trailing ellipsis or not, we must instead look at the type | |
11410 | associated with the FUNCTION_DECL. This will be a node of type | |
11411 | FUNCTION_TYPE. If the chain of type nodes hanging off of this | |
556273e0 | 11412 | FUNCTION_TYPE node ends with a void_type_node then there should *not* be |
a3f97cbb | 11413 | an ellipsis at the end. */ |
71dfc51f | 11414 | |
a3f97cbb | 11415 | /* In the case where we are describing a mere function declaration, all we |
556273e0 | 11416 | need to do here (and all we *can* do here) is to describe the *types* of |
a3f97cbb | 11417 | its formal parameters. */ |
4927276d | 11418 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 11419 | ; |
4edb7b60 | 11420 | else if (declaration) |
5daf7c0a | 11421 | gen_formal_types_die (decl, subr_die); |
a3f97cbb JW |
11422 | else |
11423 | { | |
f9da5064 | 11424 | /* Generate DIEs to represent all known formal parameters. */ |
b3694847 SS |
11425 | tree arg_decls = DECL_ARGUMENTS (decl); |
11426 | tree parm; | |
a3f97cbb JW |
11427 | |
11428 | /* When generating DIEs, generate the unspecified_parameters DIE | |
73c68f61 | 11429 | instead if we come across the arg "__builtin_va_alist" */ |
a3f97cbb | 11430 | for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) |
71dfc51f RK |
11431 | if (TREE_CODE (parm) == PARM_DECL) |
11432 | { | |
db3cf6fb MS |
11433 | if (DECL_NAME (parm) |
11434 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), | |
11435 | "__builtin_va_alist")) | |
71dfc51f RK |
11436 | gen_unspecified_parameters_die (parm, subr_die); |
11437 | else | |
11438 | gen_decl_die (parm, subr_die); | |
11439 | } | |
a3f97cbb | 11440 | |
4fe9b91c | 11441 | /* Decide whether we need an unspecified_parameters DIE at the end. |
73c68f61 SS |
11442 | There are 2 more cases to do this for: 1) the ansi ... declaration - |
11443 | this is detectable when the end of the arg list is not a | |
11444 | void_type_node 2) an unprototyped function declaration (not a | |
11445 | definition). This just means that we have no info about the | |
11446 | parameters at all. */ | |
a3f97cbb | 11447 | fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); |
71dfc51f | 11448 | if (fn_arg_types != NULL) |
a3f97cbb | 11449 | { |
beb235f8 | 11450 | /* This is the prototyped case, check for.... */ |
a3f97cbb | 11451 | if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) |
71dfc51f | 11452 | gen_unspecified_parameters_die (decl, subr_die); |
a3f97cbb | 11453 | } |
71dfc51f RK |
11454 | else if (DECL_INITIAL (decl) == NULL_TREE) |
11455 | gen_unspecified_parameters_die (decl, subr_die); | |
a3f97cbb JW |
11456 | } |
11457 | ||
11458 | /* Output Dwarf info for all of the stuff within the body of the function | |
11459 | (if it has one - it may be just a declaration). */ | |
11460 | outer_scope = DECL_INITIAL (decl); | |
11461 | ||
2ad9852d RK |
11462 | /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent |
11463 | a function. This BLOCK actually represents the outermost binding contour | |
11464 | for the function, i.e. the contour in which the function's formal | |
11465 | parameters and labels get declared. Curiously, it appears that the front | |
11466 | end doesn't actually put the PARM_DECL nodes for the current function onto | |
11467 | the BLOCK_VARS list for this outer scope, but are strung off of the | |
11468 | DECL_ARGUMENTS list for the function instead. | |
11469 | ||
11470 | The BLOCK_VARS list for the `outer_scope' does provide us with a list of | |
11471 | the LABEL_DECL nodes for the function however, and we output DWARF info | |
11472 | for those in decls_for_scope. Just within the `outer_scope' there will be | |
11473 | a BLOCK node representing the function's outermost pair of curly braces, | |
11474 | and any blocks used for the base and member initializers of a C++ | |
d7248bff | 11475 | constructor function. */ |
4edb7b60 | 11476 | if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK) |
7e23cb16 | 11477 | { |
6de9cd9a DN |
11478 | /* Emit a DW_TAG_variable DIE for a named return value. */ |
11479 | if (DECL_NAME (DECL_RESULT (decl))) | |
11480 | gen_decl_die (DECL_RESULT (decl), subr_die); | |
11481 | ||
7e23cb16 JM |
11482 | current_function_has_inlines = 0; |
11483 | decls_for_scope (outer_scope, subr_die, 0); | |
71dfc51f | 11484 | |
ce61cc73 | 11485 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
7e23cb16 JM |
11486 | if (current_function_has_inlines) |
11487 | { | |
11488 | add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1); | |
11489 | if (! comp_unit_has_inlines) | |
11490 | { | |
11491 | add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1); | |
11492 | comp_unit_has_inlines = 1; | |
11493 | } | |
11494 | } | |
11495 | #endif | |
11496 | } | |
a3f97cbb JW |
11497 | } |
11498 | ||
11499 | /* Generate a DIE to represent a declared data object. */ | |
71dfc51f | 11500 | |
a3f97cbb | 11501 | static void |
7080f735 | 11502 | gen_variable_die (tree decl, dw_die_ref context_die) |
a3f97cbb | 11503 | { |
b3694847 | 11504 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 11505 | dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl); |
71dfc51f | 11506 | |
bdb669cb | 11507 | dw_die_ref old_die = lookup_decl_die (decl); |
9765e357 | 11508 | int declaration = (DECL_EXTERNAL (decl) |
66c78aa9 | 11509 | || class_or_namespace_scope_p (context_die)); |
4edb7b60 | 11510 | |
a3f97cbb | 11511 | if (origin != NULL) |
71dfc51f | 11512 | add_abstract_origin_attribute (var_die, origin); |
2ad9852d | 11513 | |
f76b8156 | 11514 | /* Loop unrolling can create multiple blocks that refer to the same |
2ad9852d RK |
11515 | static variable, so we must test for the DW_AT_declaration flag. |
11516 | ||
11517 | ??? Loop unrolling/reorder_blocks should perhaps be rewritten to | |
f76b8156 | 11518 | copy decls and set the DECL_ABSTRACT flag on them instead of |
2ad9852d RK |
11519 | sharing them. |
11520 | ||
11521 | ??? Duplicated blocks have been rewritten to use .debug_ranges. */ | |
f76b8156 | 11522 | else if (old_die && TREE_STATIC (decl) |
c26fbbca | 11523 | && get_AT_flag (old_die, DW_AT_declaration) == 1) |
bdb669cb | 11524 | { |
e689ae67 | 11525 | /* This is a definition of a C++ class level static. */ |
47fcfa7b | 11526 | add_AT_specification (var_die, old_die); |
bdb669cb JM |
11527 | if (DECL_NAME (decl)) |
11528 | { | |
6773e15f PB |
11529 | expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl)); |
11530 | unsigned file_index = lookup_filename (s.file); | |
71dfc51f | 11531 | |
bdb669cb JM |
11532 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
11533 | add_AT_unsigned (var_die, DW_AT_decl_file, file_index); | |
71dfc51f | 11534 | |
bdb669cb | 11535 | if (get_AT_unsigned (old_die, DW_AT_decl_line) |
6773e15f | 11536 | != (unsigned) s.line) |
71dfc51f | 11537 | |
6773e15f | 11538 | add_AT_unsigned (var_die, DW_AT_decl_line, s.line); |
bdb669cb JM |
11539 | } |
11540 | } | |
a3f97cbb JW |
11541 | else |
11542 | { | |
11543 | add_name_and_src_coords_attributes (var_die, decl); | |
2ad9852d | 11544 | add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl), |
a3f97cbb | 11545 | TREE_THIS_VOLATILE (decl), context_die); |
71dfc51f | 11546 | |
273dbe67 JM |
11547 | if (TREE_PUBLIC (decl)) |
11548 | add_AT_flag (var_die, DW_AT_external, 1); | |
71dfc51f | 11549 | |
273dbe67 JM |
11550 | if (DECL_ARTIFICIAL (decl)) |
11551 | add_AT_flag (var_die, DW_AT_artificial, 1); | |
71dfc51f | 11552 | |
a94dbf2c JM |
11553 | if (TREE_PROTECTED (decl)) |
11554 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected); | |
11555 | else if (TREE_PRIVATE (decl)) | |
11556 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 11557 | } |
4edb7b60 JM |
11558 | |
11559 | if (declaration) | |
11560 | add_AT_flag (var_die, DW_AT_declaration, 1); | |
556273e0 | 11561 | |
6097b0c3 | 11562 | if (DECL_ABSTRACT (decl) || declaration) |
4edb7b60 JM |
11563 | equate_decl_number_to_die (decl, var_die); |
11564 | ||
11565 | if (! declaration && ! DECL_ABSTRACT (decl)) | |
a3f97cbb | 11566 | { |
0a2d3d69 | 11567 | add_location_or_const_value_attribute (var_die, decl, DW_AT_location); |
d291dd49 | 11568 | add_pubname (decl, var_die); |
a3f97cbb | 11569 | } |
1bfb5f8f JM |
11570 | else |
11571 | tree_add_const_value_attribute (var_die, decl); | |
a3f97cbb JW |
11572 | } |
11573 | ||
11574 | /* Generate a DIE to represent a label identifier. */ | |
71dfc51f | 11575 | |
a3f97cbb | 11576 | static void |
7080f735 | 11577 | gen_label_die (tree decl, dw_die_ref context_die) |
a3f97cbb | 11578 | { |
b3694847 | 11579 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 11580 | dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl); |
b3694847 | 11581 | rtx insn; |
a3f97cbb | 11582 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 11583 | |
a3f97cbb | 11584 | if (origin != NULL) |
71dfc51f | 11585 | add_abstract_origin_attribute (lbl_die, origin); |
a3f97cbb | 11586 | else |
71dfc51f RK |
11587 | add_name_and_src_coords_attributes (lbl_die, decl); |
11588 | ||
a3f97cbb | 11589 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 11590 | equate_decl_number_to_die (decl, lbl_die); |
a3f97cbb JW |
11591 | else |
11592 | { | |
d0585b99 | 11593 | insn = DECL_RTL_IF_SET (decl); |
088e7160 NC |
11594 | |
11595 | /* Deleted labels are programmer specified labels which have been | |
6356f892 | 11596 | eliminated because of various optimizations. We still emit them |
088e7160 | 11597 | here so that it is possible to put breakpoints on them. */ |
d0585b99 | 11598 | if (insn |
4b4bf941 JQ |
11599 | && (LABEL_P (insn) |
11600 | || ((NOTE_P (insn) | |
d0585b99 | 11601 | && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))) |
a3f97cbb | 11602 | { |
556273e0 KH |
11603 | /* When optimization is enabled (via -O) some parts of the compiler |
11604 | (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which | |
a3f97cbb JW |
11605 | represent source-level labels which were explicitly declared by |
11606 | the user. This really shouldn't be happening though, so catch | |
11607 | it if it ever does happen. */ | |
11608 | if (INSN_DELETED_P (insn)) | |
71dfc51f RK |
11609 | abort (); |
11610 | ||
66234570 | 11611 | ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn)); |
a3f97cbb JW |
11612 | add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); |
11613 | } | |
11614 | } | |
11615 | } | |
11616 | ||
11617 | /* Generate a DIE for a lexical block. */ | |
71dfc51f | 11618 | |
a3f97cbb | 11619 | static void |
7080f735 | 11620 | gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth) |
a3f97cbb | 11621 | { |
54ba1f0d | 11622 | dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt); |
a3f97cbb | 11623 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f RK |
11624 | |
11625 | if (! BLOCK_ABSTRACT (stmt)) | |
a3f97cbb | 11626 | { |
a20612aa RH |
11627 | if (BLOCK_FRAGMENT_CHAIN (stmt)) |
11628 | { | |
11629 | tree chain; | |
11630 | ||
2bee6045 | 11631 | add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt)); |
a20612aa RH |
11632 | |
11633 | chain = BLOCK_FRAGMENT_CHAIN (stmt); | |
11634 | do | |
11635 | { | |
11636 | add_ranges (chain); | |
11637 | chain = BLOCK_FRAGMENT_CHAIN (chain); | |
11638 | } | |
11639 | while (chain); | |
11640 | add_ranges (NULL); | |
11641 | } | |
11642 | else | |
11643 | { | |
11644 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, | |
11645 | BLOCK_NUMBER (stmt)); | |
11646 | add_AT_lbl_id (stmt_die, DW_AT_low_pc, label); | |
11647 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, | |
11648 | BLOCK_NUMBER (stmt)); | |
11649 | add_AT_lbl_id (stmt_die, DW_AT_high_pc, label); | |
11650 | } | |
a3f97cbb | 11651 | } |
71dfc51f | 11652 | |
d7248bff | 11653 | decls_for_scope (stmt, stmt_die, depth); |
a3f97cbb JW |
11654 | } |
11655 | ||
11656 | /* Generate a DIE for an inlined subprogram. */ | |
71dfc51f | 11657 | |
a3f97cbb | 11658 | static void |
7080f735 | 11659 | gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth) |
a3f97cbb | 11660 | { |
9bdca184 AO |
11661 | tree decl = block_ultimate_origin (stmt); |
11662 | ||
11663 | /* Emit info for the abstract instance first, if we haven't yet. We | |
11664 | must emit this even if the block is abstract, otherwise when we | |
11665 | emit the block below (or elsewhere), we may end up trying to emit | |
11666 | a die whose origin die hasn't been emitted, and crashing. */ | |
11667 | dwarf2out_abstract_function (decl); | |
11668 | ||
71dfc51f | 11669 | if (! BLOCK_ABSTRACT (stmt)) |
a3f97cbb | 11670 | { |
b3694847 | 11671 | dw_die_ref subr_die |
54ba1f0d | 11672 | = new_die (DW_TAG_inlined_subroutine, context_die, stmt); |
d7248bff | 11673 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 11674 | |
ab72d377 | 11675 | add_abstract_origin_attribute (subr_die, decl); |
5c90448c | 11676 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
18c038b9 | 11677 | BLOCK_NUMBER (stmt)); |
a3f97cbb | 11678 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label); |
18c038b9 MM |
11679 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, |
11680 | BLOCK_NUMBER (stmt)); | |
a3f97cbb | 11681 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label); |
d7248bff | 11682 | decls_for_scope (stmt, subr_die, depth); |
7e23cb16 | 11683 | current_function_has_inlines = 1; |
a3f97cbb | 11684 | } |
06e224f7 AO |
11685 | else |
11686 | /* We may get here if we're the outer block of function A that was | |
11687 | inlined into function B that was inlined into function C. When | |
11688 | generating debugging info for C, dwarf2out_abstract_function(B) | |
11689 | would mark all inlined blocks as abstract, including this one. | |
11690 | So, we wouldn't (and shouldn't) expect labels to be generated | |
11691 | for this one. Instead, just emit debugging info for | |
11692 | declarations within the block. This is particularly important | |
11693 | in the case of initializers of arguments passed from B to us: | |
11694 | if they're statement expressions containing declarations, we | |
11695 | wouldn't generate dies for their abstract variables, and then, | |
11696 | when generating dies for the real variables, we'd die (pun | |
11697 | intended :-) */ | |
11698 | gen_lexical_block_die (stmt, context_die, depth); | |
a3f97cbb JW |
11699 | } |
11700 | ||
11701 | /* Generate a DIE for a field in a record, or structure. */ | |
71dfc51f | 11702 | |
a3f97cbb | 11703 | static void |
7080f735 | 11704 | gen_field_die (tree decl, dw_die_ref context_die) |
a3f97cbb | 11705 | { |
a53efda2 | 11706 | dw_die_ref decl_die; |
71dfc51f | 11707 | |
a53efda2 JZ |
11708 | if (TREE_TYPE (decl) == error_mark_node) |
11709 | return; | |
7080f735 | 11710 | |
a53efda2 | 11711 | decl_die = new_die (DW_TAG_member, context_die, decl); |
a3f97cbb | 11712 | add_name_and_src_coords_attributes (decl_die, decl); |
a3f97cbb JW |
11713 | add_type_attribute (decl_die, member_declared_type (decl), |
11714 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl), | |
11715 | context_die); | |
71dfc51f | 11716 | |
a3f97cbb JW |
11717 | if (DECL_BIT_FIELD_TYPE (decl)) |
11718 | { | |
11719 | add_byte_size_attribute (decl_die, decl); | |
11720 | add_bit_size_attribute (decl_die, decl); | |
11721 | add_bit_offset_attribute (decl_die, decl); | |
11722 | } | |
71dfc51f | 11723 | |
a94dbf2c JM |
11724 | if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE) |
11725 | add_data_member_location_attribute (decl_die, decl); | |
71dfc51f | 11726 | |
273dbe67 JM |
11727 | if (DECL_ARTIFICIAL (decl)) |
11728 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
71dfc51f | 11729 | |
a94dbf2c JM |
11730 | if (TREE_PROTECTED (decl)) |
11731 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected); | |
11732 | else if (TREE_PRIVATE (decl)) | |
11733 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb JW |
11734 | } |
11735 | ||
ab72d377 JM |
11736 | #if 0 |
11737 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. | |
11738 | Use modified_type_die instead. | |
a3f97cbb JW |
11739 | We keep this code here just in case these types of DIEs may be needed to |
11740 | represent certain things in other languages (e.g. Pascal) someday. */ | |
2ad9852d | 11741 | |
a3f97cbb | 11742 | static void |
7080f735 | 11743 | gen_pointer_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 11744 | { |
b3694847 | 11745 | dw_die_ref ptr_die |
54ba1f0d | 11746 | = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type); |
71dfc51f | 11747 | |
a3f97cbb | 11748 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 11749 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 11750 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb JW |
11751 | } |
11752 | ||
ab72d377 JM |
11753 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. |
11754 | Use modified_type_die instead. | |
a3f97cbb JW |
11755 | We keep this code here just in case these types of DIEs may be needed to |
11756 | represent certain things in other languages (e.g. Pascal) someday. */ | |
2ad9852d | 11757 | |
a3f97cbb | 11758 | static void |
7080f735 | 11759 | gen_reference_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 11760 | { |
b3694847 | 11761 | dw_die_ref ref_die |
54ba1f0d | 11762 | = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type); |
71dfc51f | 11763 | |
a3f97cbb | 11764 | equate_type_number_to_die (type, ref_die); |
a3f97cbb | 11765 | add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 11766 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb | 11767 | } |
ab72d377 | 11768 | #endif |
a3f97cbb JW |
11769 | |
11770 | /* Generate a DIE for a pointer to a member type. */ | |
2ad9852d | 11771 | |
a3f97cbb | 11772 | static void |
7080f735 | 11773 | gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 11774 | { |
b3694847 | 11775 | dw_die_ref ptr_die |
54ba1f0d RH |
11776 | = new_die (DW_TAG_ptr_to_member_type, |
11777 | scope_die_for (type, context_die), type); | |
71dfc51f | 11778 | |
a3f97cbb | 11779 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 11780 | add_AT_die_ref (ptr_die, DW_AT_containing_type, |
bdb669cb | 11781 | lookup_type_die (TYPE_OFFSET_BASETYPE (type))); |
a3f97cbb JW |
11782 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
11783 | } | |
11784 | ||
11785 | /* Generate the DIE for the compilation unit. */ | |
71dfc51f | 11786 | |
a96c67ec | 11787 | static dw_die_ref |
7080f735 | 11788 | gen_compile_unit_die (const char *filename) |
a3f97cbb | 11789 | { |
b3694847 | 11790 | dw_die_ref die; |
a3f97cbb | 11791 | char producer[250]; |
3ac88239 | 11792 | const char *language_string = lang_hooks.name; |
a96c67ec | 11793 | int language; |
a3f97cbb | 11794 | |
54ba1f0d | 11795 | die = new_die (DW_TAG_compile_unit, NULL, NULL); |
bdb669cb | 11796 | |
c4274b22 RH |
11797 | if (filename) |
11798 | { | |
11799 | add_name_attribute (die, filename); | |
e3091a5f R |
11800 | /* Don't add cwd for <built-in>. */ |
11801 | if (filename[0] != DIR_SEPARATOR && filename[0] != '<') | |
c4274b22 RH |
11802 | add_comp_dir_attribute (die); |
11803 | } | |
a3f97cbb JW |
11804 | |
11805 | sprintf (producer, "%s %s", language_string, version_string); | |
11806 | ||
11807 | #ifdef MIPS_DEBUGGING_INFO | |
11808 | /* The MIPS/SGI compilers place the 'cc' command line options in the producer | |
11809 | string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do | |
11810 | not appear in the producer string, the debugger reaches the conclusion | |
11811 | that the object file is stripped and has no debugging information. | |
11812 | To get the MIPS/SGI debugger to believe that there is debugging | |
11813 | information in the object file, we add a -g to the producer string. */ | |
4927276d JM |
11814 | if (debug_info_level > DINFO_LEVEL_TERSE) |
11815 | strcat (producer, " -g"); | |
a3f97cbb JW |
11816 | #endif |
11817 | ||
a96c67ec | 11818 | add_AT_string (die, DW_AT_producer, producer); |
a9d38797 | 11819 | |
a3f97cbb | 11820 | if (strcmp (language_string, "GNU C++") == 0) |
a96c67ec | 11821 | language = DW_LANG_C_plus_plus; |
a3f97cbb | 11822 | else if (strcmp (language_string, "GNU Ada") == 0) |
8cb5fbbf | 11823 | language = DW_LANG_Ada95; |
a9d38797 | 11824 | else if (strcmp (language_string, "GNU F77") == 0) |
a96c67ec | 11825 | language = DW_LANG_Fortran77; |
6de9cd9a DN |
11826 | else if (strcmp (language_string, "GNU F95") == 0) |
11827 | language = DW_LANG_Fortran95; | |
bc28c45b | 11828 | else if (strcmp (language_string, "GNU Pascal") == 0) |
a96c67ec | 11829 | language = DW_LANG_Pascal83; |
28985b81 AG |
11830 | else if (strcmp (language_string, "GNU Java") == 0) |
11831 | language = DW_LANG_Java; | |
a3f97cbb | 11832 | else |
a96c67ec | 11833 | language = DW_LANG_C89; |
a9d38797 | 11834 | |
a96c67ec | 11835 | add_AT_unsigned (die, DW_AT_language, language); |
a96c67ec | 11836 | return die; |
a3f97cbb JW |
11837 | } |
11838 | ||
11839 | /* Generate a DIE for a string type. */ | |
71dfc51f | 11840 | |
a3f97cbb | 11841 | static void |
7080f735 | 11842 | gen_string_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 11843 | { |
b3694847 | 11844 | dw_die_ref type_die |
54ba1f0d | 11845 | = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type); |
71dfc51f | 11846 | |
bdb669cb | 11847 | equate_type_number_to_die (type, type_die); |
a3f97cbb | 11848 | |
2ad9852d RK |
11849 | /* ??? Fudge the string length attribute for now. |
11850 | TODO: add string length info. */ | |
11851 | #if 0 | |
11852 | string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type))); | |
11853 | bound_representation (upper_bound, 0, 'u'); | |
11854 | #endif | |
a3f97cbb JW |
11855 | } |
11856 | ||
61b32c02 | 11857 | /* Generate the DIE for a base class. */ |
71dfc51f | 11858 | |
61b32c02 | 11859 | static void |
7080f735 | 11860 | gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die) |
61b32c02 | 11861 | { |
54ba1f0d | 11862 | dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo); |
71dfc51f | 11863 | |
61b32c02 JM |
11864 | add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die); |
11865 | add_data_member_location_attribute (die, binfo); | |
71dfc51f | 11866 | |
809e3e7f | 11867 | if (BINFO_VIRTUAL_P (binfo)) |
61b32c02 | 11868 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); |
2ad9852d | 11869 | |
dbbf88d1 | 11870 | if (access == access_public_node) |
61b32c02 | 11871 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public); |
dbbf88d1 | 11872 | else if (access == access_protected_node) |
61b32c02 JM |
11873 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected); |
11874 | } | |
11875 | ||
956d6950 | 11876 | /* Generate a DIE for a class member. */ |
71dfc51f | 11877 | |
a3f97cbb | 11878 | static void |
7080f735 | 11879 | gen_member_die (tree type, dw_die_ref context_die) |
a3f97cbb | 11880 | { |
b3694847 | 11881 | tree member; |
dbbf88d1 | 11882 | tree binfo = TYPE_BINFO (type); |
10a11b75 | 11883 | dw_die_ref child; |
71dfc51f | 11884 | |
a3f97cbb JW |
11885 | /* If this is not an incomplete type, output descriptions of each of its |
11886 | members. Note that as we output the DIEs necessary to represent the | |
11887 | members of this record or union type, we will also be trying to output | |
11888 | DIEs to represent the *types* of those members. However the `type' | |
556273e0 | 11889 | function (above) will specifically avoid generating type DIEs for member |
eaec9b3d | 11890 | types *within* the list of member DIEs for this (containing) type except |
a3f97cbb JW |
11891 | for those types (of members) which are explicitly marked as also being |
11892 | members of this (containing) type themselves. The g++ front- end can | |
2ad9852d RK |
11893 | force any given type to be treated as a member of some other (containing) |
11894 | type by setting the TYPE_CONTEXT of the given (member) type to point to | |
11895 | the TREE node representing the appropriate (containing) type. */ | |
a3f97cbb | 11896 | |
61b32c02 | 11897 | /* First output info about the base classes. */ |
fa743e8c | 11898 | if (binfo) |
a3f97cbb | 11899 | { |
604a3205 | 11900 | tree accesses = BINFO_BASE_ACCESSES (binfo); |
b3694847 | 11901 | int i; |
fa743e8c | 11902 | tree base; |
61b32c02 | 11903 | |
fa743e8c NS |
11904 | for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++) |
11905 | gen_inheritance_die (base, | |
dbbf88d1 NS |
11906 | (accesses ? TREE_VEC_ELT (accesses, i) |
11907 | : access_public_node), context_die); | |
a3f97cbb JW |
11908 | } |
11909 | ||
61b32c02 JM |
11910 | /* Now output info about the data members and type members. */ |
11911 | for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member)) | |
10a11b75 JM |
11912 | { |
11913 | /* If we thought we were generating minimal debug info for TYPE | |
11914 | and then changed our minds, some of the member declarations | |
11915 | may have already been defined. Don't define them again, but | |
11916 | do put them in the right order. */ | |
11917 | ||
11918 | child = lookup_decl_die (member); | |
11919 | if (child) | |
11920 | splice_child_die (context_die, child); | |
11921 | else | |
11922 | gen_decl_die (member, context_die); | |
11923 | } | |
61b32c02 | 11924 | |
a3f97cbb | 11925 | /* Now output info about the function members (if any). */ |
61b32c02 | 11926 | for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member)) |
10a11b75 | 11927 | { |
5daf7c0a JM |
11928 | /* Don't include clones in the member list. */ |
11929 | if (DECL_ABSTRACT_ORIGIN (member)) | |
11930 | continue; | |
11931 | ||
10a11b75 JM |
11932 | child = lookup_decl_die (member); |
11933 | if (child) | |
11934 | splice_child_die (context_die, child); | |
11935 | else | |
11936 | gen_decl_die (member, context_die); | |
11937 | } | |
a3f97cbb JW |
11938 | } |
11939 | ||
10a11b75 JM |
11940 | /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG |
11941 | is set, we pretend that the type was never defined, so we only get the | |
11942 | member DIEs needed by later specification DIEs. */ | |
71dfc51f | 11943 | |
a3f97cbb | 11944 | static void |
7080f735 | 11945 | gen_struct_or_union_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 11946 | { |
b3694847 SS |
11947 | dw_die_ref type_die = lookup_type_die (type); |
11948 | dw_die_ref scope_die = 0; | |
11949 | int nested = 0; | |
10a11b75 | 11950 | int complete = (TYPE_SIZE (type) |
65e1263a JW |
11951 | && (! TYPE_STUB_DECL (type) |
11952 | || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)))); | |
66c78aa9 | 11953 | int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace); |
273dbe67 | 11954 | |
10a11b75 | 11955 | if (type_die && ! complete) |
273dbe67 | 11956 | return; |
a082c85a | 11957 | |
71dfc51f | 11958 | if (TYPE_CONTEXT (type) != NULL_TREE |
66c78aa9 JM |
11959 | && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) |
11960 | || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL)) | |
a082c85a JM |
11961 | nested = 1; |
11962 | ||
a94dbf2c | 11963 | scope_die = scope_die_for (type, context_die); |
a082c85a JM |
11964 | |
11965 | if (! type_die || (nested && scope_die == comp_unit_die)) | |
273dbe67 | 11966 | /* First occurrence of type or toplevel definition of nested class. */ |
a3f97cbb | 11967 | { |
b3694847 | 11968 | dw_die_ref old_die = type_die; |
71dfc51f | 11969 | |
a3f97cbb JW |
11970 | type_die = new_die (TREE_CODE (type) == RECORD_TYPE |
11971 | ? DW_TAG_structure_type : DW_TAG_union_type, | |
54ba1f0d | 11972 | scope_die, type); |
a3f97cbb | 11973 | equate_type_number_to_die (type, type_die); |
273dbe67 | 11974 | if (old_die) |
47fcfa7b | 11975 | add_AT_specification (type_die, old_die); |
5de0e8d4 JM |
11976 | else |
11977 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 11978 | } |
4b674448 | 11979 | else |
273dbe67 | 11980 | remove_AT (type_die, DW_AT_declaration); |
a3f97cbb JW |
11981 | |
11982 | /* If this type has been completed, then give it a byte_size attribute and | |
11983 | then give a list of members. */ | |
66c78aa9 | 11984 | if (complete && !ns_decl) |
a3f97cbb | 11985 | { |
556273e0 | 11986 | /* Prevent infinite recursion in cases where the type of some member of |
73c68f61 | 11987 | this type is expressed in terms of this type itself. */ |
a3f97cbb | 11988 | TREE_ASM_WRITTEN (type) = 1; |
273dbe67 | 11989 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 11990 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 11991 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 11992 | |
ef76d03b JW |
11993 | /* If the first reference to this type was as the return type of an |
11994 | inline function, then it may not have a parent. Fix this now. */ | |
11995 | if (type_die->die_parent == NULL) | |
11996 | add_child_die (scope_die, type_die); | |
11997 | ||
273dbe67 JM |
11998 | push_decl_scope (type); |
11999 | gen_member_die (type, type_die); | |
12000 | pop_decl_scope (); | |
71dfc51f | 12001 | |
a94dbf2c JM |
12002 | /* GNU extension: Record what type our vtable lives in. */ |
12003 | if (TYPE_VFIELD (type)) | |
12004 | { | |
12005 | tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type)); | |
71dfc51f | 12006 | |
de6e505e JM |
12007 | gen_type_die (vtype, context_die); |
12008 | add_AT_die_ref (type_die, DW_AT_containing_type, | |
12009 | lookup_type_die (vtype)); | |
a94dbf2c | 12010 | } |
a3f97cbb | 12011 | } |
4b674448 | 12012 | else |
8a8c3656 JM |
12013 | { |
12014 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a30d4514 | 12015 | |
9765e357 | 12016 | /* We don't need to do this for function-local types. */ |
9702143f RK |
12017 | if (TYPE_STUB_DECL (type) |
12018 | && ! decl_function_context (TYPE_STUB_DECL (type))) | |
2ad9852d | 12019 | VARRAY_PUSH_TREE (incomplete_types, type); |
8a8c3656 | 12020 | } |
a3f97cbb JW |
12021 | } |
12022 | ||
12023 | /* Generate a DIE for a subroutine _type_. */ | |
71dfc51f | 12024 | |
a3f97cbb | 12025 | static void |
7080f735 | 12026 | gen_subroutine_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 12027 | { |
b3694847 SS |
12028 | tree return_type = TREE_TYPE (type); |
12029 | dw_die_ref subr_die | |
54ba1f0d RH |
12030 | = new_die (DW_TAG_subroutine_type, |
12031 | scope_die_for (type, context_die), type); | |
71dfc51f | 12032 | |
a3f97cbb JW |
12033 | equate_type_number_to_die (type, subr_die); |
12034 | add_prototyped_attribute (subr_die, type); | |
a3f97cbb | 12035 | add_type_attribute (subr_die, return_type, 0, 0, context_die); |
a94dbf2c | 12036 | gen_formal_types_die (type, subr_die); |
a3f97cbb JW |
12037 | } |
12038 | ||
f9da5064 | 12039 | /* Generate a DIE for a type definition. */ |
71dfc51f | 12040 | |
a3f97cbb | 12041 | static void |
7080f735 | 12042 | gen_typedef_die (tree decl, dw_die_ref context_die) |
a3f97cbb | 12043 | { |
b3694847 SS |
12044 | dw_die_ref type_die; |
12045 | tree origin; | |
a94dbf2c JM |
12046 | |
12047 | if (TREE_ASM_WRITTEN (decl)) | |
12048 | return; | |
a94dbf2c | 12049 | |
2ad9852d | 12050 | TREE_ASM_WRITTEN (decl) = 1; |
54ba1f0d | 12051 | type_die = new_die (DW_TAG_typedef, context_die, decl); |
a94dbf2c | 12052 | origin = decl_ultimate_origin (decl); |
a3f97cbb | 12053 | if (origin != NULL) |
a94dbf2c | 12054 | add_abstract_origin_attribute (type_die, origin); |
a3f97cbb JW |
12055 | else |
12056 | { | |
b3694847 | 12057 | tree type; |
2ad9852d | 12058 | |
a3f97cbb | 12059 | add_name_and_src_coords_attributes (type_die, decl); |
a94dbf2c JM |
12060 | if (DECL_ORIGINAL_TYPE (decl)) |
12061 | { | |
12062 | type = DECL_ORIGINAL_TYPE (decl); | |
62e3bf54 JM |
12063 | |
12064 | if (type == TREE_TYPE (decl)) | |
12065 | abort (); | |
12066 | else | |
12067 | equate_type_number_to_die (TREE_TYPE (decl), type_die); | |
a94dbf2c JM |
12068 | } |
12069 | else | |
12070 | type = TREE_TYPE (decl); | |
2ad9852d | 12071 | |
a94dbf2c JM |
12072 | add_type_attribute (type_die, type, TREE_READONLY (decl), |
12073 | TREE_THIS_VOLATILE (decl), context_die); | |
a3f97cbb | 12074 | } |
71dfc51f | 12075 | |
a3f97cbb | 12076 | if (DECL_ABSTRACT (decl)) |
a94dbf2c | 12077 | equate_decl_number_to_die (decl, type_die); |
a3f97cbb JW |
12078 | } |
12079 | ||
12080 | /* Generate a type description DIE. */ | |
71dfc51f | 12081 | |
a3f97cbb | 12082 | static void |
7080f735 | 12083 | gen_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 12084 | { |
348bb3c7 JM |
12085 | int need_pop; |
12086 | ||
71dfc51f RK |
12087 | if (type == NULL_TREE || type == error_mark_node) |
12088 | return; | |
a3f97cbb | 12089 | |
a94dbf2c JM |
12090 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
12091 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
556273e0 | 12092 | { |
5d7bed9d DJ |
12093 | if (TREE_ASM_WRITTEN (type)) |
12094 | return; | |
12095 | ||
29b91443 JM |
12096 | /* Prevent broken recursion; we can't hand off to the same type. */ |
12097 | if (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) == type) | |
12098 | abort (); | |
12099 | ||
a94dbf2c JM |
12100 | TREE_ASM_WRITTEN (type) = 1; |
12101 | gen_decl_die (TYPE_NAME (type), context_die); | |
12102 | return; | |
12103 | } | |
12104 | ||
5d7bed9d DJ |
12105 | /* We are going to output a DIE to represent the unqualified version |
12106 | of this type (i.e. without any const or volatile qualifiers) so | |
12107 | get the main variant (i.e. the unqualified version) of this type | |
12108 | now. (Vectors are special because the debugging info is in the | |
12109 | cloned type itself). */ | |
12110 | if (TREE_CODE (type) != VECTOR_TYPE) | |
12111 | type = type_main_variant (type); | |
12112 | ||
12113 | if (TREE_ASM_WRITTEN (type)) | |
12114 | return; | |
12115 | ||
a3f97cbb JW |
12116 | switch (TREE_CODE (type)) |
12117 | { | |
12118 | case ERROR_MARK: | |
12119 | break; | |
12120 | ||
12121 | case POINTER_TYPE: | |
12122 | case REFERENCE_TYPE: | |
956d6950 JL |
12123 | /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This |
12124 | ensures that the gen_type_die recursion will terminate even if the | |
12125 | type is recursive. Recursive types are possible in Ada. */ | |
12126 | /* ??? We could perhaps do this for all types before the switch | |
12127 | statement. */ | |
12128 | TREE_ASM_WRITTEN (type) = 1; | |
12129 | ||
a3f97cbb | 12130 | /* For these types, all that is required is that we output a DIE (or a |
73c68f61 | 12131 | set of DIEs) to represent the "basis" type. */ |
a3f97cbb JW |
12132 | gen_type_die (TREE_TYPE (type), context_die); |
12133 | break; | |
12134 | ||
12135 | case OFFSET_TYPE: | |
556273e0 | 12136 | /* This code is used for C++ pointer-to-data-member types. |
71dfc51f | 12137 | Output a description of the relevant class type. */ |
a3f97cbb | 12138 | gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die); |
71dfc51f | 12139 | |
a3f97cbb JW |
12140 | /* Output a description of the type of the object pointed to. */ |
12141 | gen_type_die (TREE_TYPE (type), context_die); | |
71dfc51f | 12142 | |
a3f97cbb | 12143 | /* Now output a DIE to represent this pointer-to-data-member type |
73c68f61 | 12144 | itself. */ |
a3f97cbb JW |
12145 | gen_ptr_to_mbr_type_die (type, context_die); |
12146 | break; | |
12147 | ||
12148 | case SET_TYPE: | |
12149 | gen_type_die (TYPE_DOMAIN (type), context_die); | |
12150 | gen_set_type_die (type, context_die); | |
12151 | break; | |
12152 | ||
12153 | case FILE_TYPE: | |
12154 | gen_type_die (TREE_TYPE (type), context_die); | |
12155 | abort (); /* No way to represent these in Dwarf yet! */ | |
12156 | break; | |
12157 | ||
12158 | case FUNCTION_TYPE: | |
12159 | /* Force out return type (in case it wasn't forced out already). */ | |
12160 | gen_type_die (TREE_TYPE (type), context_die); | |
12161 | gen_subroutine_type_die (type, context_die); | |
12162 | break; | |
12163 | ||
12164 | case METHOD_TYPE: | |
12165 | /* Force out return type (in case it wasn't forced out already). */ | |
12166 | gen_type_die (TREE_TYPE (type), context_die); | |
12167 | gen_subroutine_type_die (type, context_die); | |
12168 | break; | |
12169 | ||
12170 | case ARRAY_TYPE: | |
12171 | if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE) | |
12172 | { | |
12173 | gen_type_die (TREE_TYPE (type), context_die); | |
12174 | gen_string_type_die (type, context_die); | |
12175 | } | |
12176 | else | |
71dfc51f | 12177 | gen_array_type_die (type, context_die); |
a3f97cbb JW |
12178 | break; |
12179 | ||
4061f623 | 12180 | case VECTOR_TYPE: |
84f0ace0 | 12181 | gen_array_type_die (type, context_die); |
4061f623 BS |
12182 | break; |
12183 | ||
a3f97cbb JW |
12184 | case ENUMERAL_TYPE: |
12185 | case RECORD_TYPE: | |
12186 | case UNION_TYPE: | |
12187 | case QUAL_UNION_TYPE: | |
2ad9852d | 12188 | /* If this is a nested type whose containing class hasn't been written |
73c68f61 SS |
12189 | out yet, writing it out will cover this one, too. This does not apply |
12190 | to instantiations of member class templates; they need to be added to | |
12191 | the containing class as they are generated. FIXME: This hurts the | |
12192 | idea of combining type decls from multiple TUs, since we can't predict | |
12193 | what set of template instantiations we'll get. */ | |
a082c85a | 12194 | if (TYPE_CONTEXT (type) |
5f2f160c | 12195 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) |
a082c85a | 12196 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) |
a94dbf2c JM |
12197 | { |
12198 | gen_type_die (TYPE_CONTEXT (type), context_die); | |
12199 | ||
348bb3c7 | 12200 | if (TREE_ASM_WRITTEN (type)) |
a94dbf2c JM |
12201 | return; |
12202 | ||
12203 | /* If that failed, attach ourselves to the stub. */ | |
12204 | push_decl_scope (TYPE_CONTEXT (type)); | |
12205 | context_die = lookup_type_die (TYPE_CONTEXT (type)); | |
348bb3c7 | 12206 | need_pop = 1; |
a94dbf2c | 12207 | } |
348bb3c7 | 12208 | else |
66c78aa9 JM |
12209 | { |
12210 | declare_in_namespace (type, context_die); | |
12211 | need_pop = 0; | |
12212 | } | |
a94dbf2c JM |
12213 | |
12214 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
273dbe67 | 12215 | gen_enumeration_type_die (type, context_die); |
a3f97cbb | 12216 | else |
273dbe67 | 12217 | gen_struct_or_union_type_die (type, context_die); |
4b674448 | 12218 | |
348bb3c7 | 12219 | if (need_pop) |
a94dbf2c JM |
12220 | pop_decl_scope (); |
12221 | ||
4b674448 | 12222 | /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix |
a082c85a JM |
12223 | it up if it is ever completed. gen_*_type_die will set it for us |
12224 | when appropriate. */ | |
12225 | return; | |
a3f97cbb JW |
12226 | |
12227 | case VOID_TYPE: | |
12228 | case INTEGER_TYPE: | |
12229 | case REAL_TYPE: | |
12230 | case COMPLEX_TYPE: | |
12231 | case BOOLEAN_TYPE: | |
12232 | case CHAR_TYPE: | |
12233 | /* No DIEs needed for fundamental types. */ | |
12234 | break; | |
12235 | ||
12236 | case LANG_TYPE: | |
12237 | /* No Dwarf representation currently defined. */ | |
12238 | break; | |
12239 | ||
12240 | default: | |
12241 | abort (); | |
12242 | } | |
12243 | ||
12244 | TREE_ASM_WRITTEN (type) = 1; | |
12245 | } | |
12246 | ||
12247 | /* Generate a DIE for a tagged type instantiation. */ | |
71dfc51f | 12248 | |
a3f97cbb | 12249 | static void |
7080f735 | 12250 | gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die) |
a3f97cbb | 12251 | { |
71dfc51f RK |
12252 | if (type == NULL_TREE || type == error_mark_node) |
12253 | return; | |
a3f97cbb | 12254 | |
38e01259 | 12255 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
12256 | this type (i.e. without any const or volatile qualifiers) so make sure |
12257 | that we have the main variant (i.e. the unqualified version) of this | |
12258 | type now. */ | |
bbc6ae08 | 12259 | if (type != type_main_variant (type)) |
3a88cbd1 | 12260 | abort (); |
a3f97cbb | 12261 | |
203588e7 | 12262 | /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is |
bbc6ae08 | 12263 | an instance of an unresolved type. */ |
556273e0 | 12264 | |
a3f97cbb JW |
12265 | switch (TREE_CODE (type)) |
12266 | { | |
12267 | case ERROR_MARK: | |
12268 | break; | |
12269 | ||
12270 | case ENUMERAL_TYPE: | |
12271 | gen_inlined_enumeration_type_die (type, context_die); | |
12272 | break; | |
12273 | ||
12274 | case RECORD_TYPE: | |
12275 | gen_inlined_structure_type_die (type, context_die); | |
12276 | break; | |
12277 | ||
12278 | case UNION_TYPE: | |
12279 | case QUAL_UNION_TYPE: | |
12280 | gen_inlined_union_type_die (type, context_die); | |
12281 | break; | |
12282 | ||
12283 | default: | |
71dfc51f | 12284 | abort (); |
a3f97cbb JW |
12285 | } |
12286 | } | |
12287 | ||
12288 | /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the | |
12289 | things which are local to the given block. */ | |
71dfc51f | 12290 | |
a3f97cbb | 12291 | static void |
7080f735 | 12292 | gen_block_die (tree stmt, dw_die_ref context_die, int depth) |
a3f97cbb | 12293 | { |
b3694847 SS |
12294 | int must_output_die = 0; |
12295 | tree origin; | |
12296 | tree decl; | |
12297 | enum tree_code origin_code; | |
a3f97cbb JW |
12298 | |
12299 | /* Ignore blocks never really used to make RTL. */ | |
1e7f092a JM |
12300 | if (stmt == NULL_TREE || !TREE_USED (stmt) |
12301 | || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt))) | |
71dfc51f | 12302 | return; |
a3f97cbb | 12303 | |
a20612aa RH |
12304 | /* If the block is one fragment of a non-contiguous block, do not |
12305 | process the variables, since they will have been done by the | |
12306 | origin block. Do process subblocks. */ | |
12307 | if (BLOCK_FRAGMENT_ORIGIN (stmt)) | |
12308 | { | |
12309 | tree sub; | |
12310 | ||
2ad9852d | 12311 | for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub)) |
a20612aa | 12312 | gen_block_die (sub, context_die, depth + 1); |
2ad9852d | 12313 | |
a20612aa RH |
12314 | return; |
12315 | } | |
12316 | ||
a3f97cbb JW |
12317 | /* Determine the "ultimate origin" of this block. This block may be an |
12318 | inlined instance of an inlined instance of inline function, so we have | |
12319 | to trace all of the way back through the origin chain to find out what | |
12320 | sort of node actually served as the original seed for the creation of | |
12321 | the current block. */ | |
12322 | origin = block_ultimate_origin (stmt); | |
12323 | origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; | |
12324 | ||
12325 | /* Determine if we need to output any Dwarf DIEs at all to represent this | |
12326 | block. */ | |
12327 | if (origin_code == FUNCTION_DECL) | |
71dfc51f RK |
12328 | /* The outer scopes for inlinings *must* always be represented. We |
12329 | generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */ | |
12330 | must_output_die = 1; | |
a3f97cbb JW |
12331 | else |
12332 | { | |
12333 | /* In the case where the current block represents an inlining of the | |
73c68f61 SS |
12334 | "body block" of an inline function, we must *NOT* output any DIE for |
12335 | this block because we have already output a DIE to represent the whole | |
12336 | inlined function scope and the "body block" of any function doesn't | |
12337 | really represent a different scope according to ANSI C rules. So we | |
12338 | check here to make sure that this block does not represent a "body | |
12339 | block inlining" before trying to set the MUST_OUTPUT_DIE flag. */ | |
d7248bff | 12340 | if (! is_body_block (origin ? origin : stmt)) |
a3f97cbb JW |
12341 | { |
12342 | /* Determine if this block directly contains any "significant" | |
12343 | local declarations which we will need to output DIEs for. */ | |
12344 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
71dfc51f RK |
12345 | /* We are not in terse mode so *any* local declaration counts |
12346 | as being a "significant" one. */ | |
12347 | must_output_die = (BLOCK_VARS (stmt) != NULL); | |
a3f97cbb | 12348 | else |
71dfc51f RK |
12349 | /* We are in terse mode, so only local (nested) function |
12350 | definitions count as "significant" local declarations. */ | |
12351 | for (decl = BLOCK_VARS (stmt); | |
12352 | decl != NULL; decl = TREE_CHAIN (decl)) | |
12353 | if (TREE_CODE (decl) == FUNCTION_DECL | |
12354 | && DECL_INITIAL (decl)) | |
a3f97cbb | 12355 | { |
71dfc51f RK |
12356 | must_output_die = 1; |
12357 | break; | |
a3f97cbb | 12358 | } |
a3f97cbb JW |
12359 | } |
12360 | } | |
12361 | ||
12362 | /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block | |
12363 | DIE for any block which contains no significant local declarations at | |
12364 | all. Rather, in such cases we just call `decls_for_scope' so that any | |
12365 | needed Dwarf info for any sub-blocks will get properly generated. Note | |
12366 | that in terse mode, our definition of what constitutes a "significant" | |
12367 | local declaration gets restricted to include only inlined function | |
12368 | instances and local (nested) function definitions. */ | |
12369 | if (must_output_die) | |
12370 | { | |
12371 | if (origin_code == FUNCTION_DECL) | |
71dfc51f | 12372 | gen_inlined_subroutine_die (stmt, context_die, depth); |
a3f97cbb | 12373 | else |
71dfc51f | 12374 | gen_lexical_block_die (stmt, context_die, depth); |
a3f97cbb JW |
12375 | } |
12376 | else | |
d7248bff | 12377 | decls_for_scope (stmt, context_die, depth); |
a3f97cbb JW |
12378 | } |
12379 | ||
12380 | /* Generate all of the decls declared within a given scope and (recursively) | |
9ec36da5 | 12381 | all of its sub-blocks. */ |
71dfc51f | 12382 | |
a3f97cbb | 12383 | static void |
7080f735 | 12384 | decls_for_scope (tree stmt, dw_die_ref context_die, int depth) |
a3f97cbb | 12385 | { |
b3694847 SS |
12386 | tree decl; |
12387 | tree subblocks; | |
71dfc51f | 12388 | |
a3f97cbb | 12389 | /* Ignore blocks never really used to make RTL. */ |
71dfc51f RK |
12390 | if (stmt == NULL_TREE || ! TREE_USED (stmt)) |
12391 | return; | |
12392 | ||
88dad228 JM |
12393 | /* Output the DIEs to represent all of the data objects and typedefs |
12394 | declared directly within this block but not within any nested | |
12395 | sub-blocks. Also, nested function and tag DIEs have been | |
12396 | generated with a parent of NULL; fix that up now. */ | |
2ad9852d | 12397 | for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl)) |
a3f97cbb | 12398 | { |
b3694847 | 12399 | dw_die_ref die; |
a94dbf2c | 12400 | |
88dad228 | 12401 | if (TREE_CODE (decl) == FUNCTION_DECL) |
a94dbf2c | 12402 | die = lookup_decl_die (decl); |
88dad228 | 12403 | else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)) |
a94dbf2c JM |
12404 | die = lookup_type_die (TREE_TYPE (decl)); |
12405 | else | |
12406 | die = NULL; | |
12407 | ||
71dfc51f | 12408 | if (die != NULL && die->die_parent == NULL) |
ef76d03b | 12409 | add_child_die (context_die, die); |
88dad228 JM |
12410 | else |
12411 | gen_decl_die (decl, context_die); | |
a3f97cbb JW |
12412 | } |
12413 | ||
8cadae7e JM |
12414 | /* If we're at -g1, we're not interested in subblocks. */ |
12415 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
12416 | return; | |
12417 | ||
a3f97cbb JW |
12418 | /* Output the DIEs to represent all sub-blocks (and the items declared |
12419 | therein) of this block. */ | |
12420 | for (subblocks = BLOCK_SUBBLOCKS (stmt); | |
12421 | subblocks != NULL; | |
12422 | subblocks = BLOCK_CHAIN (subblocks)) | |
71dfc51f | 12423 | gen_block_die (subblocks, context_die, depth + 1); |
a3f97cbb JW |
12424 | } |
12425 | ||
a94dbf2c | 12426 | /* Is this a typedef we can avoid emitting? */ |
71dfc51f RK |
12427 | |
12428 | static inline int | |
7080f735 | 12429 | is_redundant_typedef (tree decl) |
a94dbf2c JM |
12430 | { |
12431 | if (TYPE_DECL_IS_STUB (decl)) | |
12432 | return 1; | |
71dfc51f | 12433 | |
a94dbf2c JM |
12434 | if (DECL_ARTIFICIAL (decl) |
12435 | && DECL_CONTEXT (decl) | |
12436 | && is_tagged_type (DECL_CONTEXT (decl)) | |
12437 | && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL | |
12438 | && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) | |
12439 | /* Also ignore the artificial member typedef for the class name. */ | |
12440 | return 1; | |
71dfc51f | 12441 | |
a94dbf2c JM |
12442 | return 0; |
12443 | } | |
12444 | ||
6097b0c3 DP |
12445 | /* Returns the DIE for decl or aborts. */ |
12446 | ||
12447 | static dw_die_ref | |
12448 | force_decl_die (tree decl) | |
12449 | { | |
12450 | dw_die_ref decl_die; | |
12451 | unsigned saved_external_flag; | |
12452 | tree save_fn = NULL_TREE; | |
12453 | decl_die = lookup_decl_die (decl); | |
12454 | if (!decl_die) | |
12455 | { | |
12456 | dw_die_ref context_die; | |
12457 | tree decl_context = DECL_CONTEXT (decl); | |
12458 | if (decl_context) | |
12459 | { | |
12460 | /* Find die that represents this context. */ | |
12461 | if (TYPE_P (decl_context)) | |
12462 | context_die = force_type_die (decl_context); | |
12463 | else | |
12464 | context_die = force_decl_die (decl_context); | |
12465 | } | |
12466 | else | |
12467 | context_die = comp_unit_die; | |
12468 | ||
12469 | switch (TREE_CODE (decl)) | |
12470 | { | |
12471 | case FUNCTION_DECL: | |
12472 | /* Clear current_function_decl, so that gen_subprogram_die thinks | |
12473 | that this is a declaration. At this point, we just want to force | |
12474 | declaration die. */ | |
12475 | save_fn = current_function_decl; | |
12476 | current_function_decl = NULL_TREE; | |
12477 | gen_subprogram_die (decl, context_die); | |
12478 | current_function_decl = save_fn; | |
12479 | break; | |
12480 | ||
12481 | case VAR_DECL: | |
12482 | /* Set external flag to force declaration die. Restore it after | |
12483 | gen_decl_die() call. */ | |
12484 | saved_external_flag = DECL_EXTERNAL (decl); | |
12485 | DECL_EXTERNAL (decl) = 1; | |
12486 | gen_decl_die (decl, context_die); | |
12487 | DECL_EXTERNAL (decl) = saved_external_flag; | |
12488 | break; | |
12489 | ||
12490 | case NAMESPACE_DECL: | |
12491 | dwarf2out_decl (decl); | |
12492 | break; | |
12493 | ||
12494 | default: | |
12495 | abort (); | |
12496 | } | |
12497 | ||
12498 | /* See if we can find the die for this deci now. | |
12499 | If not then abort. */ | |
12500 | if (!decl_die) | |
12501 | decl_die = lookup_decl_die (decl); | |
12502 | if (!decl_die) | |
12503 | abort (); | |
12504 | } | |
12505 | ||
12506 | return decl_die; | |
12507 | } | |
66c78aa9 | 12508 | |
6097b0c3 | 12509 | /* Returns the DIE for decl or aborts. */ |
66c78aa9 JM |
12510 | |
12511 | static dw_die_ref | |
6097b0c3 | 12512 | force_type_die (tree type) |
66c78aa9 | 12513 | { |
6097b0c3 | 12514 | dw_die_ref type_die; |
66c78aa9 | 12515 | |
9733d507 | 12516 | type_die = lookup_type_die (type); |
6097b0c3 DP |
12517 | if (!type_die) |
12518 | { | |
12519 | dw_die_ref context_die; | |
12520 | if (TYPE_CONTEXT (type)) | |
12521 | if (TYPE_P (TYPE_CONTEXT (type))) | |
12522 | context_die = force_type_die (TYPE_CONTEXT (type)); | |
12523 | else | |
12524 | context_die = force_decl_die (TYPE_CONTEXT (type)); | |
12525 | else | |
12526 | context_die = comp_unit_die; | |
66c78aa9 | 12527 | |
6097b0c3 | 12528 | gen_type_die (type, context_die); |
9733d507 | 12529 | type_die = lookup_type_die (type); |
6097b0c3 DP |
12530 | if (!type_die) |
12531 | abort(); | |
12532 | } | |
12533 | return type_die; | |
66c78aa9 JM |
12534 | } |
12535 | ||
12536 | /* Force out any required namespaces to be able to output DECL, | |
12537 | and return the new context_die for it, if it's changed. */ | |
12538 | ||
12539 | static dw_die_ref | |
12540 | setup_namespace_context (tree thing, dw_die_ref context_die) | |
12541 | { | |
12542 | tree context = DECL_P (thing) ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing); | |
12543 | if (context && TREE_CODE (context) == NAMESPACE_DECL) | |
6614fd40 | 12544 | /* Force out the namespace. */ |
6097b0c3 | 12545 | context_die = force_decl_die (context); |
66c78aa9 JM |
12546 | |
12547 | return context_die; | |
12548 | } | |
12549 | ||
12550 | /* Emit a declaration DIE for THING (which is either a DECL or a tagged | |
12551 | type) within its namespace, if appropriate. | |
12552 | ||
12553 | For compatibility with older debuggers, namespace DIEs only contain | |
12554 | declarations; all definitions are emitted at CU scope. */ | |
12555 | ||
12556 | static void | |
12557 | declare_in_namespace (tree thing, dw_die_ref context_die) | |
12558 | { | |
12559 | dw_die_ref ns_context; | |
12560 | ||
12561 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
12562 | return; | |
12563 | ||
12564 | ns_context = setup_namespace_context (thing, context_die); | |
12565 | ||
12566 | if (ns_context != context_die) | |
12567 | { | |
12568 | if (DECL_P (thing)) | |
12569 | gen_decl_die (thing, ns_context); | |
12570 | else | |
12571 | gen_type_die (thing, ns_context); | |
12572 | } | |
12573 | } | |
12574 | ||
6614fd40 | 12575 | /* Generate a DIE for a namespace or namespace alias. */ |
66c78aa9 JM |
12576 | |
12577 | static void | |
12578 | gen_namespace_die (tree decl) | |
12579 | { | |
12580 | dw_die_ref context_die = setup_namespace_context (decl, comp_unit_die); | |
12581 | ||
12582 | /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace | |
e0a21ab9 | 12583 | they are an alias of. */ |
66c78aa9 JM |
12584 | if (DECL_ABSTRACT_ORIGIN (decl) == NULL) |
12585 | { | |
6614fd40 | 12586 | /* Output a real namespace. */ |
66c78aa9 JM |
12587 | dw_die_ref namespace_die |
12588 | = new_die (DW_TAG_namespace, context_die, decl); | |
12589 | add_name_and_src_coords_attributes (namespace_die, decl); | |
12590 | equate_decl_number_to_die (decl, namespace_die); | |
12591 | } | |
12592 | else | |
12593 | { | |
6614fd40 | 12594 | /* Output a namespace alias. */ |
66c78aa9 | 12595 | |
6614fd40 | 12596 | /* Force out the namespace we are an alias of, if necessary. */ |
66c78aa9 | 12597 | dw_die_ref origin_die |
6097b0c3 | 12598 | = force_decl_die (DECL_ABSTRACT_ORIGIN (decl)); |
66c78aa9 | 12599 | |
6614fd40 | 12600 | /* Now create the namespace alias DIE. */ |
66c78aa9 JM |
12601 | dw_die_ref namespace_die |
12602 | = new_die (DW_TAG_imported_declaration, context_die, decl); | |
12603 | add_name_and_src_coords_attributes (namespace_die, decl); | |
12604 | add_AT_die_ref (namespace_die, DW_AT_import, origin_die); | |
12605 | equate_decl_number_to_die (decl, namespace_die); | |
12606 | } | |
12607 | } | |
12608 | ||
a3f97cbb | 12609 | /* Generate Dwarf debug information for a decl described by DECL. */ |
71dfc51f | 12610 | |
a3f97cbb | 12611 | static void |
7080f735 | 12612 | gen_decl_die (tree decl, dw_die_ref context_die) |
a3f97cbb | 12613 | { |
b3694847 | 12614 | tree origin; |
71dfc51f | 12615 | |
f11c3043 | 12616 | if (DECL_P (decl) && DECL_IGNORED_P (decl)) |
71dfc51f | 12617 | return; |
a3f97cbb | 12618 | |
a3f97cbb JW |
12619 | switch (TREE_CODE (decl)) |
12620 | { | |
2ad9852d RK |
12621 | case ERROR_MARK: |
12622 | break; | |
12623 | ||
a3f97cbb | 12624 | case CONST_DECL: |
556273e0 | 12625 | /* The individual enumerators of an enum type get output when we output |
73c68f61 | 12626 | the Dwarf representation of the relevant enum type itself. */ |
a3f97cbb JW |
12627 | break; |
12628 | ||
12629 | case FUNCTION_DECL: | |
4edb7b60 JM |
12630 | /* Don't output any DIEs to represent mere function declarations, |
12631 | unless they are class members or explicit block externs. */ | |
12632 | if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE | |
777ad4c2 | 12633 | && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl))) |
71dfc51f | 12634 | break; |
bdb669cb | 12635 | |
6de9cd9a DN |
12636 | #if 0 |
12637 | /* FIXME */ | |
12638 | /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN | |
12639 | on local redeclarations of global functions. That seems broken. */ | |
12640 | if (current_function_decl != decl) | |
12641 | /* This is only a declaration. */; | |
12642 | #endif | |
12643 | ||
5daf7c0a JM |
12644 | /* If we're emitting a clone, emit info for the abstract instance. */ |
12645 | if (DECL_ORIGIN (decl) != decl) | |
12646 | dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl)); | |
2ad9852d | 12647 | |
1cfdcc15 JM |
12648 | /* If we're emitting an out-of-line copy of an inline function, |
12649 | emit info for the abstract instance and set up to refer to it. */ | |
1bb17c21 JH |
12650 | else if (cgraph_function_possibly_inlined_p (decl) |
12651 | && ! DECL_ABSTRACT (decl) | |
66c78aa9 | 12652 | && ! class_or_namespace_scope_p (context_die) |
5daf7c0a JM |
12653 | /* dwarf2out_abstract_function won't emit a die if this is just |
12654 | a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in | |
12655 | that case, because that works only if we have a die. */ | |
12656 | && DECL_INITIAL (decl) != NULL_TREE) | |
1cfdcc15 | 12657 | { |
1edf43d6 | 12658 | dwarf2out_abstract_function (decl); |
1cfdcc15 JM |
12659 | set_decl_origin_self (decl); |
12660 | } | |
2ad9852d | 12661 | |
5daf7c0a JM |
12662 | /* Otherwise we're emitting the primary DIE for this decl. */ |
12663 | else if (debug_info_level > DINFO_LEVEL_TERSE) | |
a94dbf2c JM |
12664 | { |
12665 | /* Before we describe the FUNCTION_DECL itself, make sure that we | |
12666 | have described its return type. */ | |
12667 | gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); | |
12668 | ||
2081603c JM |
12669 | /* And its virtual context. */ |
12670 | if (DECL_VINDEX (decl) != NULL_TREE) | |
12671 | gen_type_die (DECL_CONTEXT (decl), context_die); | |
12672 | ||
a94dbf2c JM |
12673 | /* And its containing type. */ |
12674 | origin = decl_class_context (decl); | |
71dfc51f | 12675 | if (origin != NULL_TREE) |
10a11b75 | 12676 | gen_type_die_for_member (origin, decl, context_die); |
66c78aa9 JM |
12677 | |
12678 | /* And its containing namespace. */ | |
12679 | declare_in_namespace (decl, context_die); | |
a94dbf2c | 12680 | } |
a3f97cbb JW |
12681 | |
12682 | /* Now output a DIE to represent the function itself. */ | |
12683 | gen_subprogram_die (decl, context_die); | |
12684 | break; | |
12685 | ||
12686 | case TYPE_DECL: | |
12687 | /* If we are in terse mode, don't generate any DIEs to represent any | |
73c68f61 | 12688 | actual typedefs. */ |
a3f97cbb | 12689 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 12690 | break; |
a3f97cbb | 12691 | |
2ad9852d | 12692 | /* In the special case of a TYPE_DECL node representing the declaration |
73c68f61 SS |
12693 | of some type tag, if the given TYPE_DECL is marked as having been |
12694 | instantiated from some other (original) TYPE_DECL node (e.g. one which | |
12695 | was generated within the original definition of an inline function) we | |
12696 | have to generate a special (abbreviated) DW_TAG_structure_type, | |
12697 | DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */ | |
2081603c | 12698 | if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE) |
a3f97cbb JW |
12699 | { |
12700 | gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die); | |
12701 | break; | |
12702 | } | |
a3f97cbb | 12703 | |
a94dbf2c JM |
12704 | if (is_redundant_typedef (decl)) |
12705 | gen_type_die (TREE_TYPE (decl), context_die); | |
12706 | else | |
71dfc51f RK |
12707 | /* Output a DIE to represent the typedef itself. */ |
12708 | gen_typedef_die (decl, context_die); | |
a3f97cbb JW |
12709 | break; |
12710 | ||
12711 | case LABEL_DECL: | |
12712 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
71dfc51f | 12713 | gen_label_die (decl, context_die); |
a3f97cbb JW |
12714 | break; |
12715 | ||
12716 | case VAR_DECL: | |
6de9cd9a | 12717 | case RESULT_DECL: |
a3f97cbb | 12718 | /* If we are in terse mode, don't generate any DIEs to represent any |
73c68f61 | 12719 | variable declarations or definitions. */ |
a3f97cbb | 12720 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 12721 | break; |
a3f97cbb JW |
12722 | |
12723 | /* Output any DIEs that are needed to specify the type of this data | |
73c68f61 | 12724 | object. */ |
a3f97cbb JW |
12725 | gen_type_die (TREE_TYPE (decl), context_die); |
12726 | ||
a94dbf2c JM |
12727 | /* And its containing type. */ |
12728 | origin = decl_class_context (decl); | |
71dfc51f | 12729 | if (origin != NULL_TREE) |
10a11b75 | 12730 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 12731 | |
66c78aa9 JM |
12732 | /* And its containing namespace. */ |
12733 | declare_in_namespace (decl, context_die); | |
12734 | ||
a3f97cbb | 12735 | /* Now output the DIE to represent the data object itself. This gets |
73c68f61 SS |
12736 | complicated because of the possibility that the VAR_DECL really |
12737 | represents an inlined instance of a formal parameter for an inline | |
12738 | function. */ | |
a3f97cbb | 12739 | origin = decl_ultimate_origin (decl); |
71dfc51f RK |
12740 | if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL) |
12741 | gen_formal_parameter_die (decl, context_die); | |
a3f97cbb | 12742 | else |
71dfc51f | 12743 | gen_variable_die (decl, context_die); |
a3f97cbb JW |
12744 | break; |
12745 | ||
12746 | case FIELD_DECL: | |
2ad9852d | 12747 | /* Ignore the nameless fields that are used to skip bits but handle C++ |
3199cb41 | 12748 | anonymous unions and structs. */ |
71dfc51f | 12749 | if (DECL_NAME (decl) != NULL_TREE |
3199cb41 UW |
12750 | || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE |
12751 | || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE) | |
a3f97cbb JW |
12752 | { |
12753 | gen_type_die (member_declared_type (decl), context_die); | |
12754 | gen_field_die (decl, context_die); | |
12755 | } | |
12756 | break; | |
12757 | ||
12758 | case PARM_DECL: | |
12759 | gen_type_die (TREE_TYPE (decl), context_die); | |
12760 | gen_formal_parameter_die (decl, context_die); | |
12761 | break; | |
12762 | ||
348bb3c7 | 12763 | case NAMESPACE_DECL: |
66c78aa9 | 12764 | gen_namespace_die (decl); |
348bb3c7 JM |
12765 | break; |
12766 | ||
a3f97cbb | 12767 | default: |
ae0e5982 JM |
12768 | if ((int)TREE_CODE (decl) > NUM_TREE_CODES) |
12769 | /* Probably some frontend-internal decl. Assume we don't care. */ | |
12770 | break; | |
a3f97cbb JW |
12771 | abort (); |
12772 | } | |
a3f97cbb JW |
12773 | } |
12774 | \f | |
14a774a9 RK |
12775 | /* Add Ada "use" clause information for SGI Workshop debugger. */ |
12776 | ||
12777 | void | |
7080f735 | 12778 | dwarf2out_add_library_unit_info (const char *filename, const char *context_list) |
14a774a9 RK |
12779 | { |
12780 | unsigned int file_index; | |
12781 | ||
12782 | if (filename != NULL) | |
12783 | { | |
54ba1f0d | 12784 | dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL); |
556273e0 | 12785 | tree context_list_decl |
14a774a9 RK |
12786 | = build_decl (LABEL_DECL, get_identifier (context_list), |
12787 | void_type_node); | |
12788 | ||
12789 | TREE_PUBLIC (context_list_decl) = TRUE; | |
12790 | add_name_attribute (unit_die, context_list); | |
981975b6 | 12791 | file_index = lookup_filename (filename); |
14a774a9 RK |
12792 | add_AT_unsigned (unit_die, DW_AT_decl_file, file_index); |
12793 | add_pubname (context_list_decl, unit_die); | |
12794 | } | |
12795 | } | |
12796 | ||
2ad9852d | 12797 | /* Output debug information for global decl DECL. Called from toplev.c after |
2b85879e | 12798 | compilation proper has finished. */ |
2ad9852d | 12799 | |
2b85879e | 12800 | static void |
7080f735 | 12801 | dwarf2out_global_decl (tree decl) |
2b85879e NB |
12802 | { |
12803 | /* Output DWARF2 information for file-scope tentative data object | |
2ad9852d RK |
12804 | declarations, file-scope (extern) function declarations (which had no |
12805 | corresponding body) and file-scope tagged type declarations and | |
12806 | definitions which have not yet been forced out. */ | |
2b85879e NB |
12807 | if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)) |
12808 | dwarf2out_decl (decl); | |
12809 | } | |
12810 | ||
21d13d83 ZW |
12811 | /* Output debug information for type decl DECL. Called from toplev.c |
12812 | and from language front ends (to record built-in types). */ | |
12813 | static void | |
12814 | dwarf2out_type_decl (tree decl, int local) | |
12815 | { | |
12816 | if (!local) | |
12817 | dwarf2out_decl (decl); | |
12818 | } | |
12819 | ||
6097b0c3 DP |
12820 | /* Output debug information for imported module or decl. */ |
12821 | ||
12822 | static void | |
12823 | dwarf2out_imported_module_or_decl (tree decl, tree context) | |
12824 | { | |
12825 | dw_die_ref imported_die, at_import_die; | |
12826 | dw_die_ref scope_die; | |
12827 | unsigned file_index; | |
6773e15f | 12828 | expanded_location xloc; |
6097b0c3 DP |
12829 | |
12830 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
12831 | return; | |
12832 | ||
12833 | if (!decl) | |
12834 | abort (); | |
12835 | ||
12836 | /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs. | |
12837 | We need decl DIE for reference and scope die. First, get DIE for the decl | |
12838 | itself. */ | |
12839 | ||
12840 | /* Get the scope die for decl context. Use comp_unit_die for global module | |
12841 | or decl. If die is not found for non globals, force new die. */ | |
12842 | if (!context) | |
12843 | scope_die = comp_unit_die; | |
12844 | else if (TYPE_P (context)) | |
12845 | scope_die = force_type_die (context); | |
12846 | else | |
12847 | scope_die = force_decl_die (context); | |
12848 | ||
834eb1f0 GS |
12849 | /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */ |
12850 | if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL) | |
6097b0c3 DP |
12851 | at_import_die = force_type_die (TREE_TYPE (decl)); |
12852 | else | |
12853 | at_import_die = force_decl_die (decl); | |
12854 | ||
12855 | /* OK, now we have DIEs for decl as well as scope. Emit imported die. */ | |
12856 | if (TREE_CODE (decl) == NAMESPACE_DECL) | |
12857 | imported_die = new_die (DW_TAG_imported_module, scope_die, context); | |
12858 | else | |
12859 | imported_die = new_die (DW_TAG_imported_declaration, scope_die, context); | |
6773e15f PB |
12860 | |
12861 | xloc = expand_location (input_location); | |
12862 | file_index = lookup_filename (xloc.file); | |
6097b0c3 | 12863 | add_AT_unsigned (imported_die, DW_AT_decl_file, file_index); |
6773e15f | 12864 | add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line); |
6097b0c3 DP |
12865 | add_AT_die_ref (imported_die, DW_AT_import, at_import_die); |
12866 | } | |
12867 | ||
71dfc51f RK |
12868 | /* Write the debugging output for DECL. */ |
12869 | ||
a3f97cbb | 12870 | void |
7080f735 | 12871 | dwarf2out_decl (tree decl) |
a3f97cbb | 12872 | { |
b3694847 | 12873 | dw_die_ref context_die = comp_unit_die; |
88dad228 | 12874 | |
a3f97cbb JW |
12875 | switch (TREE_CODE (decl)) |
12876 | { | |
2ad9852d RK |
12877 | case ERROR_MARK: |
12878 | return; | |
12879 | ||
a3f97cbb | 12880 | case FUNCTION_DECL: |
a3f97cbb | 12881 | /* What we would really like to do here is to filter out all mere |
73c68f61 SS |
12882 | file-scope declarations of file-scope functions which are never |
12883 | referenced later within this translation unit (and keep all of ones | |
12884 | that *are* referenced later on) but we aren't clairvoyant, so we have | |
12885 | no idea which functions will be referenced in the future (i.e. later | |
12886 | on within the current translation unit). So here we just ignore all | |
12887 | file-scope function declarations which are not also definitions. If | |
12888 | and when the debugger needs to know something about these functions, | |
12889 | it will have to hunt around and find the DWARF information associated | |
12890 | with the definition of the function. | |
2ad9852d RK |
12891 | |
12892 | We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL | |
73c68f61 SS |
12893 | nodes represent definitions and which ones represent mere |
12894 | declarations. We have to check DECL_INITIAL instead. That's because | |
12895 | the C front-end supports some weird semantics for "extern inline" | |
12896 | function definitions. These can get inlined within the current | |
12897 | translation unit (an thus, we need to generate Dwarf info for their | |
12898 | abstract instances so that the Dwarf info for the concrete inlined | |
12899 | instances can have something to refer to) but the compiler never | |
12900 | generates any out-of-lines instances of such things (despite the fact | |
12901 | that they *are* definitions). | |
2ad9852d RK |
12902 | |
12903 | The important point is that the C front-end marks these "extern | |
12904 | inline" functions as DECL_EXTERNAL, but we need to generate DWARF for | |
12905 | them anyway. Note that the C++ front-end also plays some similar games | |
12906 | for inline function definitions appearing within include files which | |
12907 | also contain `#pragma interface' pragmas. */ | |
a3f97cbb | 12908 | if (DECL_INITIAL (decl) == NULL_TREE) |
b1ccbc24 | 12909 | return; |
88dad228 | 12910 | |
9c6cd30e JM |
12911 | /* If we're a nested function, initially use a parent of NULL; if we're |
12912 | a plain function, this will be fixed up in decls_for_scope. If | |
12913 | we're a method, it will be ignored, since we already have a DIE. */ | |
8cadae7e JM |
12914 | if (decl_function_context (decl) |
12915 | /* But if we're in terse mode, we don't care about scope. */ | |
12916 | && debug_info_level > DINFO_LEVEL_TERSE) | |
9c6cd30e | 12917 | context_die = NULL; |
a3f97cbb JW |
12918 | break; |
12919 | ||
12920 | case VAR_DECL: | |
556273e0 | 12921 | /* Ignore this VAR_DECL if it refers to a file-scope extern data object |
73c68f61 SS |
12922 | declaration and if the declaration was never even referenced from |
12923 | within this entire compilation unit. We suppress these DIEs in | |
12924 | order to save space in the .debug section (by eliminating entries | |
12925 | which are probably useless). Note that we must not suppress | |
12926 | block-local extern declarations (whether used or not) because that | |
12927 | would screw-up the debugger's name lookup mechanism and cause it to | |
12928 | miss things which really ought to be in scope at a given point. */ | |
a3f97cbb | 12929 | if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) |
71dfc51f | 12930 | return; |
a3f97cbb JW |
12931 | |
12932 | /* If we are in terse mode, don't generate any DIEs to represent any | |
73c68f61 | 12933 | variable declarations or definitions. */ |
a3f97cbb | 12934 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 12935 | return; |
a3f97cbb JW |
12936 | break; |
12937 | ||
66c78aa9 JM |
12938 | case NAMESPACE_DECL: |
12939 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
12940 | return; | |
12941 | if (lookup_decl_die (decl) != NULL) | |
12942 | return; | |
12943 | break; | |
12944 | ||
a3f97cbb | 12945 | case TYPE_DECL: |
57fb7689 JM |
12946 | /* Don't emit stubs for types unless they are needed by other DIEs. */ |
12947 | if (TYPE_DECL_SUPPRESS_DEBUG (decl)) | |
12948 | return; | |
12949 | ||
a3f97cbb | 12950 | /* Don't bother trying to generate any DIEs to represent any of the |
73c68f61 | 12951 | normal built-in types for the language we are compiling. */ |
6773e15f | 12952 | if (DECL_IS_BUILTIN (decl)) |
a94dbf2c JM |
12953 | { |
12954 | /* OK, we need to generate one for `bool' so GDB knows what type | |
73c68f61 | 12955 | comparisons have. */ |
a94dbf2c JM |
12956 | if ((get_AT_unsigned (comp_unit_die, DW_AT_language) |
12957 | == DW_LANG_C_plus_plus) | |
f11c3043 RK |
12958 | && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE |
12959 | && ! DECL_IGNORED_P (decl)) | |
a94dbf2c | 12960 | modified_type_die (TREE_TYPE (decl), 0, 0, NULL); |
71dfc51f | 12961 | |
a94dbf2c JM |
12962 | return; |
12963 | } | |
a3f97cbb | 12964 | |
88dad228 | 12965 | /* If we are in terse mode, don't generate any DIEs for types. */ |
a3f97cbb | 12966 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 12967 | return; |
88dad228 JM |
12968 | |
12969 | /* If we're a function-scope tag, initially use a parent of NULL; | |
12970 | this will be fixed up in decls_for_scope. */ | |
12971 | if (decl_function_context (decl)) | |
3f76745e | 12972 | context_die = NULL; |
88dad228 | 12973 | |
a3f97cbb JW |
12974 | break; |
12975 | ||
12976 | default: | |
12977 | return; | |
12978 | } | |
12979 | ||
88dad228 | 12980 | gen_decl_die (decl, context_die); |
a3f97cbb JW |
12981 | } |
12982 | ||
12983 | /* Output a marker (i.e. a label) for the beginning of the generated code for | |
12984 | a lexical block. */ | |
71dfc51f | 12985 | |
a5a42b92 | 12986 | static void |
7080f735 AJ |
12987 | dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED, |
12988 | unsigned int blocknum) | |
a3f97cbb | 12989 | { |
a3f97cbb | 12990 | function_section (current_function_decl); |
8215347e | 12991 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum); |
a3f97cbb JW |
12992 | } |
12993 | ||
12994 | /* Output a marker (i.e. a label) for the end of the generated code for a | |
12995 | lexical block. */ | |
71dfc51f | 12996 | |
a5a42b92 | 12997 | static void |
7080f735 | 12998 | dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum) |
a3f97cbb | 12999 | { |
a3f97cbb | 13000 | function_section (current_function_decl); |
8215347e | 13001 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum); |
a3f97cbb JW |
13002 | } |
13003 | ||
64b59a80 JM |
13004 | /* Returns nonzero if it is appropriate not to emit any debugging |
13005 | information for BLOCK, because it doesn't contain any instructions. | |
fcd7f76b | 13006 | |
64b59a80 JM |
13007 | Don't allow this for blocks with nested functions or local classes |
13008 | as we would end up with orphans, and in the presence of scheduling | |
13009 | we may end up calling them anyway. */ | |
13010 | ||
e1772ac0 | 13011 | static bool |
7080f735 | 13012 | dwarf2out_ignore_block (tree block) |
fcd7f76b JM |
13013 | { |
13014 | tree decl; | |
2ad9852d | 13015 | |
fcd7f76b | 13016 | for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) |
64b59a80 JM |
13017 | if (TREE_CODE (decl) == FUNCTION_DECL |
13018 | || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))) | |
13019 | return 0; | |
2ad9852d | 13020 | |
64b59a80 | 13021 | return 1; |
fcd7f76b JM |
13022 | } |
13023 | ||
2ad9852d | 13024 | /* Lookup FILE_NAME (in the list of filenames that we know about here in |
9a666dda | 13025 | dwarf2out.c) and return its "index". The index of each (known) filename is |
2ad9852d RK |
13026 | just a unique number which is associated with only that one filename. We |
13027 | need such numbers for the sake of generating labels (in the .debug_sfnames | |
13028 | section) and references to those files numbers (in the .debug_srcinfo | |
13029 | and.debug_macinfo sections). If the filename given as an argument is not | |
13030 | found in our current list, add it to the list and assign it the next | |
13031 | available unique index number. In order to speed up searches, we remember | |
13032 | the index of the filename was looked up last. This handles the majority of | |
13033 | all searches. */ | |
71dfc51f | 13034 | |
a3f97cbb | 13035 | static unsigned |
7080f735 | 13036 | lookup_filename (const char *file_name) |
a3f97cbb | 13037 | { |
c4274b22 RH |
13038 | size_t i, n; |
13039 | char *save_file_name; | |
a3f97cbb | 13040 | |
2e18bbae RH |
13041 | /* Check to see if the file name that was searched on the previous |
13042 | call matches this file name. If so, return the index. */ | |
c4274b22 RH |
13043 | if (file_table_last_lookup_index != 0) |
13044 | { | |
13045 | const char *last | |
13046 | = VARRAY_CHAR_PTR (file_table, file_table_last_lookup_index); | |
13047 | if (strcmp (file_name, last) == 0) | |
73c68f61 | 13048 | return file_table_last_lookup_index; |
c4274b22 | 13049 | } |
a3f97cbb JW |
13050 | |
13051 | /* Didn't match the previous lookup, search the table */ | |
c4274b22 RH |
13052 | n = VARRAY_ACTIVE_SIZE (file_table); |
13053 | for (i = 1; i < n; i++) | |
13054 | if (strcmp (file_name, VARRAY_CHAR_PTR (file_table, i)) == 0) | |
71dfc51f | 13055 | { |
c4274b22 | 13056 | file_table_last_lookup_index = i; |
71dfc51f RK |
13057 | return i; |
13058 | } | |
a3f97cbb | 13059 | |
71dfc51f | 13060 | /* Add the new entry to the end of the filename table. */ |
c4274b22 RH |
13061 | file_table_last_lookup_index = n; |
13062 | save_file_name = (char *) ggc_strdup (file_name); | |
13063 | VARRAY_PUSH_CHAR_PTR (file_table, save_file_name); | |
73c68f61 | 13064 | VARRAY_PUSH_UINT (file_table_emitted, 0); |
2e18bbae | 13065 | |
73c68f61 SS |
13066 | return i; |
13067 | } | |
13068 | ||
13069 | static int | |
7080f735 | 13070 | maybe_emit_file (int fileno) |
73c68f61 | 13071 | { |
73c68f61 | 13072 | if (DWARF2_ASM_LINE_DEBUG_INFO && fileno > 0) |
211a0cbe | 13073 | { |
73c68f61 SS |
13074 | if (!VARRAY_UINT (file_table_emitted, fileno)) |
13075 | { | |
13076 | VARRAY_UINT (file_table_emitted, fileno) = ++emitcount; | |
13077 | fprintf (asm_out_file, "\t.file %u ", | |
13078 | VARRAY_UINT (file_table_emitted, fileno)); | |
13079 | output_quoted_string (asm_out_file, | |
13080 | VARRAY_CHAR_PTR (file_table, fileno)); | |
13081 | fputc ('\n', asm_out_file); | |
13082 | } | |
13083 | return VARRAY_UINT (file_table_emitted, fileno); | |
211a0cbe | 13084 | } |
73c68f61 SS |
13085 | else |
13086 | return fileno; | |
2e18bbae RH |
13087 | } |
13088 | ||
13089 | static void | |
7080f735 | 13090 | init_file_table (void) |
2e18bbae RH |
13091 | { |
13092 | /* Allocate the initial hunk of the file_table. */ | |
c4274b22 | 13093 | VARRAY_CHAR_PTR_INIT (file_table, 64, "file_table"); |
73c68f61 | 13094 | VARRAY_UINT_INIT (file_table_emitted, 64, "file_table_emitted"); |
71dfc51f | 13095 | |
2e18bbae | 13096 | /* Skip the first entry - file numbers begin at 1. */ |
c4274b22 | 13097 | VARRAY_PUSH_CHAR_PTR (file_table, NULL); |
73c68f61 | 13098 | VARRAY_PUSH_UINT (file_table_emitted, 0); |
c4274b22 | 13099 | file_table_last_lookup_index = 0; |
a3f97cbb JW |
13100 | } |
13101 | ||
0a2d3d69 DB |
13102 | /* Called by the final INSN scan whenever we see a var location. We |
13103 | use it to drop labels in the right places, and throw the location in | |
13104 | our lookup table. */ | |
13105 | ||
13106 | static void | |
13107 | dwarf2out_var_location (rtx loc_note) | |
13108 | { | |
13109 | char loclabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
13110 | struct var_loc_node *newloc; | |
13111 | rtx prev_insn; | |
13112 | static rtx last_insn; | |
13113 | static const char *last_label; | |
13114 | ||
13115 | if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note))) | |
13116 | return; | |
13117 | prev_insn = PREV_INSN (loc_note); | |
13118 | ||
13119 | newloc = ggc_alloc_cleared (sizeof (struct var_loc_node)); | |
13120 | /* If the insn we processed last time is the previous insn | |
13121 | and it is also a var location note, use the label we emitted | |
13122 | last time. */ | |
13123 | if (last_insn != NULL_RTX | |
13124 | && last_insn == prev_insn | |
4b4bf941 | 13125 | && NOTE_P (prev_insn) |
0a2d3d69 DB |
13126 | && NOTE_LINE_NUMBER (prev_insn) == NOTE_INSN_VAR_LOCATION) |
13127 | { | |
13128 | newloc->label = last_label; | |
13129 | } | |
13130 | else | |
13131 | { | |
13132 | ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num); | |
13133 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num); | |
13134 | loclabel_num++; | |
13135 | newloc->label = ggc_strdup (loclabel); | |
13136 | } | |
13137 | newloc->var_loc_note = loc_note; | |
13138 | newloc->next = NULL; | |
13139 | ||
13140 | last_insn = loc_note; | |
13141 | last_label = newloc->label; | |
13142 | ||
13143 | add_var_loc_to_decl (NOTE_VAR_LOCATION_DECL (loc_note), newloc); | |
13144 | } | |
13145 | ||
13146 | /* We need to reset the locations at the beginning of each | |
13147 | function. We can't do this in the end_function hook, because the | |
13148 | declarations that use the locations won't have been outputted when | |
13149 | that hook is called. */ | |
13150 | ||
13151 | static void | |
13152 | dwarf2out_begin_function (tree unused ATTRIBUTE_UNUSED) | |
13153 | { | |
13154 | htab_empty (decl_loc_table); | |
13155 | } | |
13156 | ||
a3f97cbb JW |
13157 | /* Output a label to mark the beginning of a source code line entry |
13158 | and record information relating to this source line, in | |
13159 | 'line_info_table' for later output of the .debug_line section. */ | |
71dfc51f | 13160 | |
e2a12aca | 13161 | static void |
7080f735 | 13162 | dwarf2out_source_line (unsigned int line, const char *filename) |
a3f97cbb | 13163 | { |
7bf6b23d JM |
13164 | if (debug_info_level >= DINFO_LEVEL_NORMAL |
13165 | && line != 0) | |
a3f97cbb JW |
13166 | { |
13167 | function_section (current_function_decl); | |
a3f97cbb | 13168 | |
8aaf55ac JM |
13169 | /* If requested, emit something human-readable. */ |
13170 | if (flag_debug_asm) | |
13171 | fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, | |
13172 | filename, line); | |
13173 | ||
b2244e22 JW |
13174 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
13175 | { | |
981975b6 | 13176 | unsigned file_num = lookup_filename (filename); |
b2244e22 | 13177 | |
73c68f61 SS |
13178 | file_num = maybe_emit_file (file_num); |
13179 | ||
981975b6 | 13180 | /* Emit the .loc directive understood by GNU as. */ |
2e18bbae | 13181 | fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line); |
b2244e22 JW |
13182 | |
13183 | /* Indicate that line number info exists. */ | |
2ad9852d | 13184 | line_info_table_in_use++; |
b2244e22 JW |
13185 | |
13186 | /* Indicate that multiple line number tables exist. */ | |
13187 | if (DECL_SECTION_NAME (current_function_decl)) | |
2ad9852d | 13188 | separate_line_info_table_in_use++; |
b2244e22 JW |
13189 | } |
13190 | else if (DECL_SECTION_NAME (current_function_decl)) | |
a3f97cbb | 13191 | { |
b3694847 | 13192 | dw_separate_line_info_ref line_info; |
5fd9b178 | 13193 | targetm.asm_out.internal_label (asm_out_file, SEPARATE_LINE_CODE_LABEL, |
5c90448c | 13194 | separate_line_info_table_in_use); |
e90b62db | 13195 | |
a1105617 | 13196 | /* Expand the line info table if necessary. */ |
e90b62db JM |
13197 | if (separate_line_info_table_in_use |
13198 | == separate_line_info_table_allocated) | |
13199 | { | |
13200 | separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
13201 | separate_line_info_table | |
703ad42b | 13202 | = ggc_realloc (separate_line_info_table, |
17211ab5 GK |
13203 | separate_line_info_table_allocated |
13204 | * sizeof (dw_separate_line_info_entry)); | |
703ad42b KG |
13205 | memset (separate_line_info_table |
13206 | + separate_line_info_table_in_use, | |
17211ab5 | 13207 | 0, |
7080f735 | 13208 | (LINE_INFO_TABLE_INCREMENT |
17211ab5 | 13209 | * sizeof (dw_separate_line_info_entry))); |
e90b62db | 13210 | } |
71dfc51f RK |
13211 | |
13212 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
13213 | line_info |
13214 | = &separate_line_info_table[separate_line_info_table_in_use++]; | |
981975b6 | 13215 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db | 13216 | line_info->dw_line_num = line; |
df696a75 | 13217 | line_info->function = current_function_funcdef_no; |
e90b62db JM |
13218 | } |
13219 | else | |
13220 | { | |
b3694847 | 13221 | dw_line_info_ref line_info; |
71dfc51f | 13222 | |
5fd9b178 | 13223 | targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, |
5c90448c | 13224 | line_info_table_in_use); |
e90b62db | 13225 | |
71dfc51f | 13226 | /* Expand the line info table if necessary. */ |
e90b62db JM |
13227 | if (line_info_table_in_use == line_info_table_allocated) |
13228 | { | |
13229 | line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
13230 | line_info_table | |
17211ab5 GK |
13231 | = ggc_realloc (line_info_table, |
13232 | (line_info_table_allocated | |
13233 | * sizeof (dw_line_info_entry))); | |
13234 | memset (line_info_table + line_info_table_in_use, 0, | |
13235 | LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry)); | |
e90b62db | 13236 | } |
71dfc51f RK |
13237 | |
13238 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db | 13239 | line_info = &line_info_table[line_info_table_in_use++]; |
981975b6 | 13240 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db | 13241 | line_info->dw_line_num = line; |
a3f97cbb | 13242 | } |
a3f97cbb JW |
13243 | } |
13244 | } | |
13245 | ||
30f7a378 | 13246 | /* Record the beginning of a new source file. */ |
71dfc51f | 13247 | |
7f905405 | 13248 | static void |
7080f735 | 13249 | dwarf2out_start_source_file (unsigned int lineno, const char *filename) |
a3f97cbb | 13250 | { |
8a7a6f4d | 13251 | if (flag_eliminate_dwarf2_dups) |
881c6935 JM |
13252 | { |
13253 | /* Record the beginning of the file for break_out_includes. */ | |
cc0017a9 ZD |
13254 | dw_die_ref bincl_die; |
13255 | ||
13256 | bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL); | |
881c6935 JM |
13257 | add_AT_string (bincl_die, DW_AT_name, filename); |
13258 | } | |
2ad9852d | 13259 | |
84a5b4f8 DB |
13260 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
13261 | { | |
715bdd29 | 13262 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 | 13263 | dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file"); |
7c262518 RH |
13264 | dw2_asm_output_data_uleb128 (lineno, "Included from line number %d", |
13265 | lineno); | |
73c68f61 | 13266 | maybe_emit_file (lookup_filename (filename)); |
7c262518 RH |
13267 | dw2_asm_output_data_uleb128 (lookup_filename (filename), |
13268 | "Filename we just started"); | |
84a5b4f8 | 13269 | } |
a3f97cbb JW |
13270 | } |
13271 | ||
cc260610 | 13272 | /* Record the end of a source file. */ |
71dfc51f | 13273 | |
7f905405 | 13274 | static void |
7080f735 | 13275 | dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED) |
a3f97cbb | 13276 | { |
881c6935 | 13277 | if (flag_eliminate_dwarf2_dups) |
2ad9852d | 13278 | /* Record the end of the file for break_out_includes. */ |
54ba1f0d | 13279 | new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL); |
2ad9852d | 13280 | |
84a5b4f8 DB |
13281 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
13282 | { | |
715bdd29 | 13283 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
13284 | dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); |
13285 | } | |
a3f97cbb JW |
13286 | } |
13287 | ||
cc260610 | 13288 | /* Called from debug_define in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
13289 | the tail part of the directive line, i.e. the part which is past the |
13290 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 13291 | |
7f905405 | 13292 | static void |
7080f735 AJ |
13293 | dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED, |
13294 | const char *buffer ATTRIBUTE_UNUSED) | |
a3f97cbb | 13295 | { |
84a5b4f8 DB |
13296 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
13297 | { | |
715bdd29 | 13298 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
13299 | dw2_asm_output_data (1, DW_MACINFO_define, "Define macro"); |
13300 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
13301 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
13302 | } | |
a3f97cbb JW |
13303 | } |
13304 | ||
cc260610 | 13305 | /* Called from debug_undef in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
13306 | the tail part of the directive line, i.e. the part which is past the |
13307 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 13308 | |
7f905405 | 13309 | static void |
7080f735 AJ |
13310 | dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED, |
13311 | const char *buffer ATTRIBUTE_UNUSED) | |
a3f97cbb | 13312 | { |
84a5b4f8 DB |
13313 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
13314 | { | |
715bdd29 | 13315 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
13316 | dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro"); |
13317 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
13318 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
13319 | } | |
a3f97cbb JW |
13320 | } |
13321 | ||
13322 | /* Set up for Dwarf output at the start of compilation. */ | |
71dfc51f | 13323 | |
a51d908e | 13324 | static void |
7080f735 | 13325 | dwarf2out_init (const char *filename ATTRIBUTE_UNUSED) |
a3f97cbb | 13326 | { |
acc187f5 RH |
13327 | init_file_table (); |
13328 | ||
0a2d3d69 | 13329 | /* Allocate the decl_die_table. */ |
636c7bc4 JZ |
13330 | decl_die_table = htab_create_ggc (10, decl_die_table_hash, |
13331 | decl_die_table_eq, NULL); | |
0a2d3d69 DB |
13332 | |
13333 | /* Allocate the decl_loc_table. */ | |
13334 | decl_loc_table = htab_create_ggc (10, decl_loc_table_hash, | |
13335 | decl_loc_table_eq, NULL); | |
a3f97cbb JW |
13336 | |
13337 | /* Allocate the initial hunk of the decl_scope_table. */ | |
244a4af0 | 13338 | VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table"); |
a3f97cbb JW |
13339 | |
13340 | /* Allocate the initial hunk of the abbrev_die_table. */ | |
17211ab5 GK |
13341 | abbrev_die_table = ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT |
13342 | * sizeof (dw_die_ref)); | |
a3f97cbb | 13343 | abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT; |
71dfc51f | 13344 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
13345 | abbrev_die_table_in_use = 1; |
13346 | ||
13347 | /* Allocate the initial hunk of the line_info_table. */ | |
17211ab5 GK |
13348 | line_info_table = ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT |
13349 | * sizeof (dw_line_info_entry)); | |
a3f97cbb | 13350 | line_info_table_allocated = LINE_INFO_TABLE_INCREMENT; |
2ad9852d | 13351 | |
71dfc51f | 13352 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
13353 | line_info_table_in_use = 1; |
13354 | ||
556273e0 | 13355 | /* Generate the initial DIE for the .debug section. Note that the (string) |
a3f97cbb | 13356 | value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE |
556273e0 | 13357 | will (typically) be a relative pathname and that this pathname should be |
a3f97cbb | 13358 | taken as being relative to the directory from which the compiler was |
c4274b22 RH |
13359 | invoked when the given (base) source file was compiled. We will fill |
13360 | in this value in dwarf2out_finish. */ | |
13361 | comp_unit_die = gen_compile_unit_die (NULL); | |
a3f97cbb | 13362 | |
244a4af0 | 13363 | VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types"); |
244a4af0 | 13364 | |
1f8f4a0b | 13365 | VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray"); |
1865dbb5 | 13366 | |
5c90448c | 13367 | ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0); |
9d2f2c45 RH |
13368 | ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, |
13369 | DEBUG_ABBREV_SECTION_LABEL, 0); | |
b366352b MM |
13370 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) |
13371 | ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0); | |
13372 | else | |
f99ffb60 | 13373 | strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME)); |
2ad9852d | 13374 | |
556273e0 | 13375 | ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label, |
8b790721 | 13376 | DEBUG_INFO_SECTION_LABEL, 0); |
556273e0 | 13377 | ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label, |
8b790721 | 13378 | DEBUG_LINE_SECTION_LABEL, 0); |
2bee6045 JJ |
13379 | ASM_GENERATE_INTERNAL_LABEL (ranges_section_label, |
13380 | DEBUG_RANGES_SECTION_LABEL, 0); | |
715bdd29 | 13381 | named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG); |
8b790721 | 13382 | ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label); |
715bdd29 | 13383 | named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG); |
8b790721 | 13384 | ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label); |
715bdd29 | 13385 | named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG); |
8b790721 | 13386 | ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label); |
2ad9852d | 13387 | |
84a5b4f8 DB |
13388 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
13389 | { | |
715bdd29 | 13390 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
13391 | ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label, |
13392 | DEBUG_MACINFO_SECTION_LABEL, 0); | |
13393 | ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label); | |
13394 | } | |
7c262518 RH |
13395 | |
13396 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) | |
13397 | { | |
13398 | text_section (); | |
13399 | ASM_OUTPUT_LABEL (asm_out_file, text_section_label); | |
13400 | } | |
a3f97cbb JW |
13401 | } |
13402 | ||
9eb4015a JJ |
13403 | /* A helper function for dwarf2out_finish called through |
13404 | ht_forall. Emit one queued .debug_str string. */ | |
13405 | ||
13406 | static int | |
7080f735 | 13407 | output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED) |
9eb4015a | 13408 | { |
17211ab5 | 13409 | struct indirect_string_node *node = (struct indirect_string_node *) *h; |
9eb4015a | 13410 | |
9eb4015a JJ |
13411 | if (node->form == DW_FORM_strp) |
13412 | { | |
13413 | named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS); | |
13414 | ASM_OUTPUT_LABEL (asm_out_file, node->label); | |
17211ab5 | 13415 | assemble_string (node->str, strlen (node->str) + 1); |
9eb4015a | 13416 | } |
2ad9852d | 13417 | |
9eb4015a JJ |
13418 | return 1; |
13419 | } | |
13420 | ||
73c68f61 SS |
13421 | |
13422 | ||
13423 | /* Clear the marks for a die and its children. | |
3dc575ff | 13424 | Be cool if the mark isn't set. */ |
73c68f61 SS |
13425 | |
13426 | static void | |
7080f735 | 13427 | prune_unmark_dies (dw_die_ref die) |
73c68f61 SS |
13428 | { |
13429 | dw_die_ref c; | |
13430 | die->die_mark = 0; | |
13431 | for (c = die->die_child; c; c = c->die_sib) | |
13432 | prune_unmark_dies (c); | |
13433 | } | |
13434 | ||
13435 | ||
13436 | /* Given DIE that we're marking as used, find any other dies | |
13437 | it references as attributes and mark them as used. */ | |
13438 | ||
13439 | static void | |
7080f735 | 13440 | prune_unused_types_walk_attribs (dw_die_ref die) |
73c68f61 SS |
13441 | { |
13442 | dw_attr_ref a; | |
13443 | ||
13444 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
13445 | { | |
13446 | if (a->dw_attr_val.val_class == dw_val_class_die_ref) | |
13447 | { | |
13448 | /* A reference to another DIE. | |
13449 | Make sure that it will get emitted. */ | |
13450 | prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1); | |
13451 | } | |
13452 | else if (a->dw_attr == DW_AT_decl_file) | |
13453 | { | |
13454 | /* A reference to a file. Make sure the file name is emitted. */ | |
13455 | a->dw_attr_val.v.val_unsigned = | |
13456 | maybe_emit_file (a->dw_attr_val.v.val_unsigned); | |
13457 | } | |
13458 | } | |
13459 | } | |
13460 | ||
13461 | ||
13462 | /* Mark DIE as being used. If DOKIDS is true, then walk down | |
13463 | to DIE's children. */ | |
13464 | ||
13465 | static void | |
7080f735 | 13466 | prune_unused_types_mark (dw_die_ref die, int dokids) |
73c68f61 SS |
13467 | { |
13468 | dw_die_ref c; | |
13469 | ||
13470 | if (die->die_mark == 0) | |
13471 | { | |
13472 | /* We haven't done this node yet. Mark it as used. */ | |
13473 | die->die_mark = 1; | |
13474 | ||
13475 | /* We also have to mark its parents as used. | |
13476 | (But we don't want to mark our parents' kids due to this.) */ | |
13477 | if (die->die_parent) | |
13478 | prune_unused_types_mark (die->die_parent, 0); | |
13479 | ||
13480 | /* Mark any referenced nodes. */ | |
13481 | prune_unused_types_walk_attribs (die); | |
47fcfa7b SS |
13482 | |
13483 | /* If this node is a specification, | |
6614fd40 | 13484 | also mark the definition, if it exists. */ |
47fcfa7b SS |
13485 | if (get_AT_flag (die, DW_AT_declaration) && die->die_definition) |
13486 | prune_unused_types_mark (die->die_definition, 1); | |
73c68f61 SS |
13487 | } |
13488 | ||
13489 | if (dokids && die->die_mark != 2) | |
13490 | { | |
13491 | /* We need to walk the children, but haven't done so yet. | |
13492 | Remember that we've walked the kids. */ | |
13493 | die->die_mark = 2; | |
13494 | ||
13495 | /* Walk them. */ | |
13496 | for (c = die->die_child; c; c = c->die_sib) | |
13497 | { | |
13498 | /* If this is an array type, we need to make sure our | |
3dc575ff | 13499 | kids get marked, even if they're types. */ |
73c68f61 SS |
13500 | if (die->die_tag == DW_TAG_array_type) |
13501 | prune_unused_types_mark (c, 1); | |
13502 | else | |
13503 | prune_unused_types_walk (c); | |
13504 | } | |
13505 | } | |
13506 | } | |
13507 | ||
13508 | ||
13509 | /* Walk the tree DIE and mark types that we actually use. */ | |
13510 | ||
13511 | static void | |
7080f735 | 13512 | prune_unused_types_walk (dw_die_ref die) |
73c68f61 SS |
13513 | { |
13514 | dw_die_ref c; | |
13515 | ||
13516 | /* Don't do anything if this node is already marked. */ | |
13517 | if (die->die_mark) | |
13518 | return; | |
13519 | ||
13520 | switch (die->die_tag) { | |
13521 | case DW_TAG_const_type: | |
13522 | case DW_TAG_packed_type: | |
13523 | case DW_TAG_pointer_type: | |
13524 | case DW_TAG_reference_type: | |
13525 | case DW_TAG_volatile_type: | |
13526 | case DW_TAG_typedef: | |
13527 | case DW_TAG_array_type: | |
13528 | case DW_TAG_structure_type: | |
13529 | case DW_TAG_union_type: | |
13530 | case DW_TAG_class_type: | |
13531 | case DW_TAG_friend: | |
13532 | case DW_TAG_variant_part: | |
13533 | case DW_TAG_enumeration_type: | |
13534 | case DW_TAG_subroutine_type: | |
13535 | case DW_TAG_string_type: | |
13536 | case DW_TAG_set_type: | |
13537 | case DW_TAG_subrange_type: | |
13538 | case DW_TAG_ptr_to_member_type: | |
13539 | case DW_TAG_file_type: | |
13540 | /* It's a type node --- don't mark it. */ | |
13541 | return; | |
13542 | ||
13543 | default: | |
13544 | /* Mark everything else. */ | |
13545 | break; | |
13546 | } | |
13547 | ||
13548 | die->die_mark = 1; | |
13549 | ||
13550 | /* Now, mark any dies referenced from here. */ | |
13551 | prune_unused_types_walk_attribs (die); | |
13552 | ||
13553 | /* Mark children. */ | |
13554 | for (c = die->die_child; c; c = c->die_sib) | |
13555 | prune_unused_types_walk (c); | |
13556 | } | |
13557 | ||
13558 | ||
13559 | /* Remove from the tree DIE any dies that aren't marked. */ | |
13560 | ||
13561 | static void | |
7080f735 | 13562 | prune_unused_types_prune (dw_die_ref die) |
73c68f61 SS |
13563 | { |
13564 | dw_die_ref c, p, n; | |
13565 | if (!die->die_mark) | |
13566 | abort(); | |
13567 | ||
13568 | p = NULL; | |
13569 | for (c = die->die_child; c; c = n) | |
13570 | { | |
13571 | n = c->die_sib; | |
13572 | if (c->die_mark) | |
13573 | { | |
13574 | prune_unused_types_prune (c); | |
13575 | p = c; | |
13576 | } | |
13577 | else | |
13578 | { | |
13579 | if (p) | |
13580 | p->die_sib = n; | |
13581 | else | |
13582 | die->die_child = n; | |
13583 | free_die (c); | |
13584 | } | |
13585 | } | |
13586 | } | |
13587 | ||
13588 | ||
13589 | /* Remove dies representing declarations that we never use. */ | |
13590 | ||
13591 | static void | |
7080f735 | 13592 | prune_unused_types (void) |
73c68f61 SS |
13593 | { |
13594 | unsigned int i; | |
13595 | limbo_die_node *node; | |
13596 | ||
13597 | /* Clear all the marks. */ | |
13598 | prune_unmark_dies (comp_unit_die); | |
13599 | for (node = limbo_die_list; node; node = node->next) | |
13600 | prune_unmark_dies (node->die); | |
13601 | ||
13602 | /* Set the mark on nodes that are actually used. */ | |
13603 | prune_unused_types_walk (comp_unit_die); | |
13604 | for (node = limbo_die_list; node; node = node->next) | |
13605 | prune_unused_types_walk (node->die); | |
13606 | ||
13607 | /* Also set the mark on nodes referenced from the | |
13608 | pubname_table or arange_table. */ | |
6a87d634 RS |
13609 | for (i = 0; i < pubname_table_in_use; i++) |
13610 | prune_unused_types_mark (pubname_table[i].die, 1); | |
13611 | for (i = 0; i < arange_table_in_use; i++) | |
13612 | prune_unused_types_mark (arange_table[i], 1); | |
73c68f61 SS |
13613 | |
13614 | /* Get rid of nodes that aren't marked. */ | |
13615 | prune_unused_types_prune (comp_unit_die); | |
13616 | for (node = limbo_die_list; node; node = node->next) | |
13617 | prune_unused_types_prune (node->die); | |
13618 | ||
13619 | /* Leave the marks clear. */ | |
13620 | prune_unmark_dies (comp_unit_die); | |
13621 | for (node = limbo_die_list; node; node = node->next) | |
13622 | prune_unmark_dies (node->die); | |
13623 | } | |
13624 | ||
a3f97cbb JW |
13625 | /* Output stuff that dwarf requires at the end of every file, |
13626 | and generate the DWARF-2 debugging info. */ | |
71dfc51f | 13627 | |
a51d908e | 13628 | static void |
7080f735 | 13629 | dwarf2out_finish (const char *filename) |
a3f97cbb | 13630 | { |
ef76d03b | 13631 | limbo_die_node *node, *next_node; |
ae0ed63a | 13632 | dw_die_ref die = 0; |
ef76d03b | 13633 | |
c4274b22 RH |
13634 | /* Add the name for the main input file now. We delayed this from |
13635 | dwarf2out_init to avoid complications with PCH. */ | |
3b895f8e NS |
13636 | add_name_attribute (comp_unit_die, filename); |
13637 | if (filename[0] != DIR_SEPARATOR) | |
c4274b22 | 13638 | add_comp_dir_attribute (comp_unit_die); |
79c758fb JJ |
13639 | else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL) |
13640 | { | |
13641 | size_t i; | |
13642 | for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++) | |
e3091a5f R |
13643 | if (VARRAY_CHAR_PTR (file_table, i)[0] != DIR_SEPARATOR |
13644 | /* Don't add cwd for <built-in>. */ | |
13645 | && VARRAY_CHAR_PTR (file_table, i)[0] != '<') | |
79c758fb JJ |
13646 | { |
13647 | add_comp_dir_attribute (comp_unit_die); | |
13648 | break; | |
13649 | } | |
13650 | } | |
c4274b22 | 13651 | |
ef76d03b JW |
13652 | /* Traverse the limbo die list, and add parent/child links. The only |
13653 | dies without parents that should be here are concrete instances of | |
13654 | inline functions, and the comp_unit_die. We can ignore the comp_unit_die. | |
13655 | For concrete instances, we can get the parent die from the abstract | |
13656 | instance. */ | |
13657 | for (node = limbo_die_list; node; node = next_node) | |
13658 | { | |
13659 | next_node = node->next; | |
13660 | die = node->die; | |
13661 | ||
13662 | if (die->die_parent == NULL) | |
13663 | { | |
a96c67ec | 13664 | dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin); |
54ba1f0d | 13665 | tree context; |
2ad9852d | 13666 | |
a96c67ec JM |
13667 | if (origin) |
13668 | add_child_die (origin->die_parent, die); | |
ef76d03b | 13669 | else if (die == comp_unit_die) |
a96c67ec | 13670 | ; |
6bb28965 JM |
13671 | else if (errorcount > 0 || sorrycount > 0) |
13672 | /* It's OK to be confused by errors in the input. */ | |
13673 | add_child_die (comp_unit_die, die); | |
54ba1f0d RH |
13674 | else if (node->created_for |
13675 | && ((DECL_P (node->created_for) | |
c26fbbca | 13676 | && (context = DECL_CONTEXT (node->created_for))) |
54ba1f0d RH |
13677 | || (TYPE_P (node->created_for) |
13678 | && (context = TYPE_CONTEXT (node->created_for)))) | |
13679 | && TREE_CODE (context) == FUNCTION_DECL) | |
13680 | { | |
13681 | /* In certain situations, the lexical block containing a | |
13682 | nested function can be optimized away, which results | |
13683 | in the nested function die being orphaned. Likewise | |
13684 | with the return type of that nested function. Force | |
13685 | this to be a child of the containing function. */ | |
13686 | origin = lookup_decl_die (context); | |
13687 | if (! origin) | |
13688 | abort (); | |
13689 | add_child_die (origin, die); | |
13690 | } | |
ef76d03b JW |
13691 | else |
13692 | abort (); | |
13693 | } | |
ef76d03b | 13694 | } |
2ad9852d | 13695 | |
a96c67ec | 13696 | limbo_die_list = NULL; |
ef76d03b | 13697 | |
8a8c3656 JM |
13698 | /* Walk through the list of incomplete types again, trying once more to |
13699 | emit full debugging info for them. */ | |
13700 | retry_incomplete_types (); | |
13701 | ||
881c6935 JM |
13702 | /* We need to reverse all the dies before break_out_includes, or |
13703 | we'll see the end of an include file before the beginning. */ | |
13704 | reverse_all_dies (comp_unit_die); | |
13705 | ||
03275f81 ZD |
13706 | if (flag_eliminate_unused_debug_types) |
13707 | prune_unused_types (); | |
13708 | ||
881c6935 JM |
13709 | /* Generate separate CUs for each of the include files we've seen. |
13710 | They will go into limbo_die_list. */ | |
5f632b5e JM |
13711 | if (flag_eliminate_dwarf2_dups) |
13712 | break_out_includes (comp_unit_die); | |
881c6935 JM |
13713 | |
13714 | /* Traverse the DIE's and add add sibling attributes to those DIE's | |
13715 | that have children. */ | |
a3f97cbb | 13716 | add_sibling_attributes (comp_unit_die); |
881c6935 JM |
13717 | for (node = limbo_die_list; node; node = node->next) |
13718 | add_sibling_attributes (node->die); | |
a3f97cbb JW |
13719 | |
13720 | /* Output a terminator label for the .text section. */ | |
7c262518 | 13721 | text_section (); |
5fd9b178 | 13722 | targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0); |
a3f97cbb | 13723 | |
db3c0315 MM |
13724 | /* Output the source line correspondence table. We must do this |
13725 | even if there is no line information. Otherwise, on an empty | |
13726 | translation unit, we will generate a present, but empty, | |
13727 | .debug_info section. IRIX 6.5 `nm' will then complain when | |
13728 | examining the file. */ | |
13729 | if (! DWARF2_ASM_LINE_DEBUG_INFO) | |
e90b62db | 13730 | { |
715bdd29 | 13731 | named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG); |
db3c0315 MM |
13732 | output_line_info (); |
13733 | } | |
71dfc51f | 13734 | |
b38a75e5 RH |
13735 | /* Output location list section if necessary. */ |
13736 | if (have_location_lists) | |
13737 | { | |
13738 | /* Output the location lists info. */ | |
13739 | named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG); | |
13740 | ASM_GENERATE_INTERNAL_LABEL (loc_section_label, | |
13741 | DEBUG_LOC_SECTION_LABEL, 0); | |
13742 | ASM_OUTPUT_LABEL (asm_out_file, loc_section_label); | |
13743 | output_location_lists (die); | |
13744 | have_location_lists = 0; | |
13745 | } | |
13746 | ||
db3c0315 MM |
13747 | /* We can only use the low/high_pc attributes if all of the code was |
13748 | in .text. */ | |
13749 | if (separate_line_info_table_in_use == 0) | |
13750 | { | |
13751 | add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label); | |
13752 | add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label); | |
e90b62db | 13753 | } |
2ad9852d RK |
13754 | |
13755 | /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate | |
13756 | "base address". Use zero so that these addresses become absolute. */ | |
a20612aa RH |
13757 | else if (have_location_lists || ranges_table_in_use) |
13758 | add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx); | |
e90b62db | 13759 | |
fe7cd37f RH |
13760 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
13761 | add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list, | |
13762 | debug_line_section_label); | |
db3c0315 | 13763 | |
84a5b4f8 DB |
13764 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
13765 | add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label); | |
a96c67ec | 13766 | |
881c6935 JM |
13767 | /* Output all of the compilation units. We put the main one last so that |
13768 | the offsets are available to output_pubnames. */ | |
13769 | for (node = limbo_die_list; node; node = node->next) | |
cc0017a9 | 13770 | output_comp_unit (node->die, 0); |
2ad9852d | 13771 | |
cc0017a9 | 13772 | output_comp_unit (comp_unit_die, 0); |
881c6935 | 13773 | |
a3f97cbb | 13774 | /* Output the abbreviation table. */ |
715bdd29 | 13775 | named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG); |
a3f97cbb JW |
13776 | output_abbrev_section (); |
13777 | ||
2ad9852d | 13778 | /* Output public names table if necessary. */ |
d291dd49 JM |
13779 | if (pubname_table_in_use) |
13780 | { | |
715bdd29 | 13781 | named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG); |
d291dd49 JM |
13782 | output_pubnames (); |
13783 | } | |
13784 | ||
2ad9852d RK |
13785 | /* Output the address range information. We only put functions in the arange |
13786 | table, so don't write it out if we don't have any. */ | |
a3f97cbb JW |
13787 | if (fde_table_in_use) |
13788 | { | |
715bdd29 | 13789 | named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG); |
a3f97cbb JW |
13790 | output_aranges (); |
13791 | } | |
a20612aa | 13792 | |
a20612aa RH |
13793 | /* Output ranges section if necessary. */ |
13794 | if (ranges_table_in_use) | |
13795 | { | |
715bdd29 | 13796 | named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG); |
2bee6045 | 13797 | ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label); |
a20612aa RH |
13798 | output_ranges (); |
13799 | } | |
13800 | ||
30f7a378 | 13801 | /* Have to end the primary source file. */ |
cc260610 | 13802 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
c26fbbca | 13803 | { |
715bdd29 | 13804 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
cc260610 | 13805 | dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); |
2f8d482e | 13806 | dw2_asm_output_data (1, 0, "End compilation unit"); |
cc260610 | 13807 | } |
9eb4015a | 13808 | |
2ad9852d | 13809 | /* If we emitted any DW_FORM_strp form attribute, output the string |
9eb4015a JJ |
13810 | table too. */ |
13811 | if (debug_str_hash) | |
17211ab5 | 13812 | htab_traverse (debug_str_hash, output_indirect_string, NULL); |
a3f97cbb | 13813 | } |
e2500fed GK |
13814 | #else |
13815 | ||
13816 | /* This should never be used, but its address is needed for comparisons. */ | |
13817 | const struct gcc_debug_hooks dwarf2_debug_hooks; | |
13818 | ||
13819 | #endif /* DWARF2_DEBUGGING_INFO */ | |
13820 | ||
13821 | #include "gt-dwarf2out.h" |