]>
Commit | Line | Data |
---|---|---|
5e6908ea | 1 | /* Output Dwarf2 format symbol table information from GCC. |
69bd9368 RS |
2 | Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, |
3 | 2003 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 JW |
41 | #include "tree.h" |
42 | #include "flags.h" | |
11ad4784 | 43 | #include "real.h" |
a3f97cbb JW |
44 | #include "rtl.h" |
45 | #include "hard-reg-set.h" | |
46 | #include "regs.h" | |
47 | #include "insn-config.h" | |
48 | #include "reload.h" | |
52a11cbf | 49 | #include "function.h" |
a3f97cbb | 50 | #include "output.h" |
71dfc51f | 51 | #include "expr.h" |
e78d8e51 | 52 | #include "libfuncs.h" |
3f76745e | 53 | #include "except.h" |
a7cc7f29 | 54 | #include "dwarf2.h" |
76ead72b | 55 | #include "dwarf2out.h" |
2e4b9b8c | 56 | #include "dwarf2asm.h" |
10f0ad3d | 57 | #include "toplev.h" |
1865dbb5 | 58 | #include "varray.h" |
951a525f | 59 | #include "ggc.h" |
881c6935 | 60 | #include "md5.h" |
57bed152 | 61 | #include "tm_p.h" |
2a2b2d43 | 62 | #include "diagnostic.h" |
a51d908e | 63 | #include "debug.h" |
07c9d2eb | 64 | #include "target.h" |
3ac88239 | 65 | #include "langhooks.h" |
cc0017a9 | 66 | #include "hashtab.h" |
a3f97cbb | 67 | |
653e276c | 68 | #ifdef DWARF2_DEBUGGING_INFO |
7080f735 | 69 | static void dwarf2out_source_line (unsigned int, const char *); |
653e276c NB |
70 | #endif |
71 | ||
770ca8c6 JO |
72 | /* DWARF2 Abbreviation Glossary: |
73 | CFA = Canonical Frame Address | |
00a42e21 JM |
74 | a fixed address on the stack which identifies a call frame. |
75 | We define it to be the value of SP just before the call insn. | |
76 | The CFA register and offset, which may change during the course | |
77 | of the function, are used to calculate its value at runtime. | |
a401107d JO |
78 | CFI = Call Frame Instruction |
79 | an instruction for the DWARF2 abstract machine | |
770ca8c6 JO |
80 | CIE = Common Information Entry |
81 | information describing information common to one or more FDEs | |
82 | DIE = Debugging Information Entry | |
83 | FDE = Frame Description Entry | |
84 | information describing the stack call frame, in particular, | |
85 | how to restore registers | |
86 | ||
87 | DW_CFA_... = DWARF2 CFA call frame instruction | |
88 | DW_TAG_... = DWARF2 DIE tag */ | |
89 | ||
0021b564 JM |
90 | /* Decide whether we want to emit frame unwind information for the current |
91 | translation unit. */ | |
92 | ||
93 | int | |
7080f735 | 94 | dwarf2out_do_frame (void) |
0021b564 JM |
95 | { |
96 | return (write_symbols == DWARF2_DEBUG | |
7a0c8d71 | 97 | || write_symbols == VMS_AND_DWARF2_DEBUG |
9ec36da5 | 98 | #ifdef DWARF2_FRAME_INFO |
556273e0 | 99 | || DWARF2_FRAME_INFO |
9ec36da5 | 100 | #endif |
0021b564 | 101 | #ifdef DWARF2_UNWIND_INFO |
14a774a9 | 102 | || flag_unwind_tables |
531073e7 | 103 | || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS) |
0021b564 JM |
104 | #endif |
105 | ); | |
106 | } | |
107 | ||
f3a8e4f5 KG |
108 | /* The size of the target's pointer type. */ |
109 | #ifndef PTR_SIZE | |
110 | #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT) | |
111 | #endif | |
112 | ||
113 | /* Default version of targetm.eh_frame_section. Note this must appear | |
114 | outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro | |
115 | guards. */ | |
116 | ||
117 | void | |
7080f735 | 118 | default_eh_frame_section (void) |
f3a8e4f5 KG |
119 | { |
120 | #ifdef EH_FRAME_SECTION_NAME | |
96d0f4dc JJ |
121 | #ifdef HAVE_LD_RO_RW_SECTION_MIXING |
122 | int fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0); | |
123 | int per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1); | |
124 | int lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0); | |
125 | int flags; | |
126 | ||
127 | flags = (! flag_pic | |
128 | || ((fde_encoding & 0x70) != DW_EH_PE_absptr | |
129 | && (fde_encoding & 0x70) != DW_EH_PE_aligned | |
130 | && (per_encoding & 0x70) != DW_EH_PE_absptr | |
131 | && (per_encoding & 0x70) != DW_EH_PE_aligned | |
132 | && (lsda_encoding & 0x70) != DW_EH_PE_absptr | |
133 | && (lsda_encoding & 0x70) != DW_EH_PE_aligned)) | |
134 | ? 0 : SECTION_WRITE; | |
135 | named_section_flags (EH_FRAME_SECTION_NAME, flags); | |
136 | #else | |
f3a8e4f5 | 137 | named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE); |
96d0f4dc | 138 | #endif |
f3a8e4f5 KG |
139 | #else |
140 | tree label = get_file_function_name ('F'); | |
141 | ||
142 | data_section (); | |
143 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); | |
5eb99654 | 144 | (*targetm.asm_out.globalize_label) (asm_out_file, IDENTIFIER_POINTER (label)); |
f3a8e4f5 KG |
145 | ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); |
146 | #endif | |
147 | } | |
148 | ||
e2500fed GK |
149 | /* Array of RTXes referenced by the debugging information, which therefore |
150 | must be kept around forever. */ | |
151 | static GTY(()) varray_type used_rtx_varray; | |
152 | ||
153 | /* A pointer to the base of a list of incomplete types which might be | |
154 | completed at some later time. incomplete_types_list needs to be a VARRAY | |
155 | because we want to tell the garbage collector about it. */ | |
156 | static GTY(()) varray_type incomplete_types; | |
157 | ||
158 | /* A pointer to the base of a table of references to declaration | |
159 | scopes. This table is a display which tracks the nesting | |
160 | of declaration scopes at the current scope and containing | |
161 | scopes. This table is used to find the proper place to | |
162 | define type declaration DIE's. */ | |
163 | static GTY(()) varray_type decl_scope_table; | |
164 | ||
eaf95893 RK |
165 | /* How to start an assembler comment. */ |
166 | #ifndef ASM_COMMENT_START | |
167 | #define ASM_COMMENT_START ";#" | |
168 | #endif | |
169 | ||
a3f97cbb JW |
170 | typedef struct dw_cfi_struct *dw_cfi_ref; |
171 | typedef struct dw_fde_struct *dw_fde_ref; | |
172 | typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref; | |
a3f97cbb JW |
173 | |
174 | /* Call frames are described using a sequence of Call Frame | |
175 | Information instructions. The register number, offset | |
176 | and address fields are provided as possible operands; | |
177 | their use is selected by the opcode field. */ | |
71dfc51f | 178 | |
17211ab5 GK |
179 | enum dw_cfi_oprnd_type { |
180 | dw_cfi_oprnd_unused, | |
181 | dw_cfi_oprnd_reg_num, | |
182 | dw_cfi_oprnd_offset, | |
183 | dw_cfi_oprnd_addr, | |
184 | dw_cfi_oprnd_loc | |
185 | }; | |
186 | ||
187 | typedef union dw_cfi_oprnd_struct GTY(()) | |
71dfc51f | 188 | { |
17211ab5 GK |
189 | unsigned long GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num; |
190 | long int GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset; | |
191 | const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr; | |
192 | struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc; | |
71dfc51f | 193 | } |
a3f97cbb JW |
194 | dw_cfi_oprnd; |
195 | ||
17211ab5 | 196 | typedef struct dw_cfi_struct GTY(()) |
71dfc51f RK |
197 | { |
198 | dw_cfi_ref dw_cfi_next; | |
199 | enum dwarf_call_frame_info dw_cfi_opc; | |
7080f735 | 200 | dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)"))) |
17211ab5 | 201 | dw_cfi_oprnd1; |
7080f735 | 202 | dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)"))) |
17211ab5 | 203 | dw_cfi_oprnd2; |
71dfc51f | 204 | } |
a3f97cbb JW |
205 | dw_cfi_node; |
206 | ||
7d9d8943 AM |
207 | /* This is how we define the location of the CFA. We use to handle it |
208 | as REG + OFFSET all the time, but now it can be more complex. | |
209 | It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET. | |
556273e0 | 210 | Instead of passing around REG and OFFSET, we pass a copy |
7d9d8943 | 211 | of this structure. */ |
17211ab5 | 212 | typedef struct cfa_loc GTY(()) |
7d9d8943 | 213 | { |
556273e0 | 214 | unsigned long reg; |
7d9d8943 AM |
215 | long offset; |
216 | long base_offset; | |
217 | int indirect; /* 1 if CFA is accessed via a dereference. */ | |
218 | } dw_cfa_location; | |
219 | ||
a3f97cbb | 220 | /* All call frame descriptions (FDE's) in the GCC generated DWARF |
4b674448 | 221 | refer to a single Common Information Entry (CIE), defined at |
fb530c07 | 222 | the beginning of the .debug_frame section. This use of a single |
a3f97cbb JW |
223 | CIE obviates the need to keep track of multiple CIE's |
224 | in the DWARF generation routines below. */ | |
71dfc51f | 225 | |
17211ab5 | 226 | typedef struct dw_fde_struct GTY(()) |
71dfc51f | 227 | { |
d3e3972c KG |
228 | const char *dw_fde_begin; |
229 | const char *dw_fde_current_label; | |
230 | const char *dw_fde_end; | |
71dfc51f | 231 | dw_cfi_ref dw_fde_cfi; |
52a11cbf | 232 | unsigned funcdef_number; |
b6128b8c | 233 | unsigned all_throwers_are_sibcalls : 1; |
52a11cbf RH |
234 | unsigned nothrow : 1; |
235 | unsigned uses_eh_lsda : 1; | |
71dfc51f | 236 | } |
a3f97cbb JW |
237 | dw_fde_node; |
238 | ||
6d2f8887 | 239 | /* Maximum size (in bytes) of an artificially generated label. */ |
a3f97cbb JW |
240 | #define MAX_ARTIFICIAL_LABEL_BYTES 30 |
241 | ||
a1a4189d JB |
242 | /* The size of addresses as they appear in the Dwarf 2 data. |
243 | Some architectures use word addresses to refer to code locations, | |
244 | but Dwarf 2 info always uses byte addresses. On such machines, | |
245 | Dwarf 2 addresses need to be larger than the architecture's | |
246 | pointers. */ | |
247 | #ifndef DWARF2_ADDR_SIZE | |
248 | #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT) | |
249 | #endif | |
250 | ||
7e23cb16 | 251 | /* The size in bytes of a DWARF field indicating an offset or length |
a1a4189d JB |
252 | relative to a debug info section, specified to be 4 bytes in the |
253 | DWARF-2 specification. The SGI/MIPS ABI defines it to be the same | |
b13fe8bf | 254 | as PTR_SIZE. */ |
71dfc51f | 255 | |
7e23cb16 JM |
256 | #ifndef DWARF_OFFSET_SIZE |
257 | #define DWARF_OFFSET_SIZE 4 | |
258 | #endif | |
259 | ||
9eb0ef7a KB |
260 | /* According to the (draft) DWARF 3 specification, the initial length |
261 | should either be 4 or 12 bytes. When it's 12 bytes, the first 4 | |
262 | bytes are 0xffffffff, followed by the length stored in the next 8 | |
263 | bytes. | |
264 | ||
265 | However, the SGI/MIPS ABI uses an initial length which is equal to | |
266 | DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */ | |
267 | ||
268 | #ifndef DWARF_INITIAL_LENGTH_SIZE | |
269 | #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12) | |
270 | #endif | |
271 | ||
9a666dda JM |
272 | #define DWARF_VERSION 2 |
273 | ||
7e23cb16 JM |
274 | /* Round SIZE up to the nearest BOUNDARY. */ |
275 | #define DWARF_ROUND(SIZE,BOUNDARY) \ | |
262b6384 | 276 | ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY)) |
a3f97cbb | 277 | |
a3f97cbb | 278 | /* Offsets recorded in opcodes are a multiple of this alignment factor. */ |
27c35f4b | 279 | #ifndef DWARF_CIE_DATA_ALIGNMENT |
469ac993 | 280 | #ifdef STACK_GROWS_DOWNWARD |
08cb3d38 | 281 | #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD)) |
469ac993 | 282 | #else |
08cb3d38 | 283 | #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD) |
469ac993 | 284 | #endif |
2ad9852d | 285 | #endif |
a3f97cbb | 286 | |
3f76745e JM |
287 | /* A pointer to the base of a table that contains frame description |
288 | information for each routine. */ | |
17211ab5 | 289 | static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table; |
a3f97cbb | 290 | |
3f76745e | 291 | /* Number of elements currently allocated for fde_table. */ |
c2e9147c | 292 | static GTY(()) unsigned fde_table_allocated; |
a94dbf2c | 293 | |
3f76745e | 294 | /* Number of elements in fde_table currently in use. */ |
044b4de3 | 295 | static GTY(()) unsigned fde_table_in_use; |
a3f97cbb | 296 | |
3f76745e JM |
297 | /* Size (in elements) of increments by which we may expand the |
298 | fde_table. */ | |
299 | #define FDE_TABLE_INCREMENT 256 | |
a3f97cbb | 300 | |
a94dbf2c | 301 | /* A list of call frame insns for the CIE. */ |
17211ab5 | 302 | static GTY(()) dw_cfi_ref cie_cfi_head; |
a94dbf2c | 303 | |
c1b50e49 | 304 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) |
a3f97cbb JW |
305 | /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram |
306 | attribute that accelerates the lookup of the FDE associated | |
556273e0 | 307 | with the subprogram. This variable holds the table index of the FDE |
a3f97cbb JW |
308 | associated with the current function (body) definition. */ |
309 | static unsigned current_funcdef_fde; | |
c1b50e49 | 310 | #endif |
a3f97cbb | 311 | |
17211ab5 | 312 | struct indirect_string_node GTY(()) |
9eb4015a | 313 | { |
17211ab5 | 314 | const char *str; |
9eb4015a JJ |
315 | unsigned int refcount; |
316 | unsigned int form; | |
317 | char *label; | |
318 | }; | |
319 | ||
17211ab5 GK |
320 | static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash; |
321 | ||
322 | static GTY(()) int dw2_string_counter; | |
044b4de3 | 323 | static GTY(()) unsigned long dwarf2out_cfi_label_num; |
17211ab5 GK |
324 | |
325 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) | |
326 | ||
a3f97cbb | 327 | /* Forward declarations for functions defined in this file. */ |
71dfc51f | 328 | |
7080f735 AJ |
329 | static char *stripattributes (const char *); |
330 | static const char *dwarf_cfi_name (unsigned); | |
331 | static dw_cfi_ref new_cfi (void); | |
332 | static void add_cfi (dw_cfi_ref *, dw_cfi_ref); | |
333 | static void add_fde_cfi (const char *, dw_cfi_ref); | |
334 | static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *); | |
335 | static void lookup_cfa (dw_cfa_location *); | |
336 | static void reg_save (const char *, unsigned, unsigned, long); | |
337 | static void initial_return_save (rtx); | |
338 | static long stack_adjust_offset (rtx); | |
339 | static void output_cfi (dw_cfi_ref, dw_fde_ref, int); | |
340 | static void output_call_frame_info (int); | |
341 | static void dwarf2out_stack_adjust (rtx); | |
342 | static void queue_reg_save (const char *, rtx, long); | |
343 | static void flush_queued_reg_saves (void); | |
344 | static bool clobbers_queued_reg_save (rtx); | |
345 | static void dwarf2out_frame_debug_expr (rtx, const char *); | |
a3f97cbb | 346 | |
7d9d8943 | 347 | /* Support for complex CFA locations. */ |
7080f735 AJ |
348 | static void output_cfa_loc (dw_cfi_ref); |
349 | static void get_cfa_from_loc_descr (dw_cfa_location *, | |
350 | struct dw_loc_descr_struct *); | |
7d9d8943 | 351 | static struct dw_loc_descr_struct *build_cfa_loc |
7080f735 AJ |
352 | (dw_cfa_location *); |
353 | static void def_cfa_1 (const char *, dw_cfa_location *); | |
7d9d8943 | 354 | |
2e4b9b8c RH |
355 | /* How to start an assembler comment. */ |
356 | #ifndef ASM_COMMENT_START | |
357 | #define ASM_COMMENT_START ";#" | |
a3f97cbb JW |
358 | #endif |
359 | ||
7e23cb16 JM |
360 | /* Data and reference forms for relocatable data. */ |
361 | #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4) | |
362 | #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4) | |
363 | ||
cf2fe500 RH |
364 | #ifndef DEBUG_FRAME_SECTION |
365 | #define DEBUG_FRAME_SECTION ".debug_frame" | |
a3f97cbb | 366 | #endif |
a3f97cbb | 367 | |
5c90448c JM |
368 | #ifndef FUNC_BEGIN_LABEL |
369 | #define FUNC_BEGIN_LABEL "LFB" | |
a3f97cbb | 370 | #endif |
2ad9852d | 371 | |
5c90448c JM |
372 | #ifndef FUNC_END_LABEL |
373 | #define FUNC_END_LABEL "LFE" | |
a3f97cbb | 374 | #endif |
2ad9852d | 375 | |
27d95cbe | 376 | #define FRAME_BEGIN_LABEL "Lframe" |
a6ab3aad JM |
377 | #define CIE_AFTER_SIZE_LABEL "LSCIE" |
378 | #define CIE_END_LABEL "LECIE" | |
2e4b9b8c RH |
379 | #define FDE_LABEL "LSFDE" |
380 | #define FDE_AFTER_SIZE_LABEL "LASFDE" | |
a6ab3aad | 381 | #define FDE_END_LABEL "LEFDE" |
981975b6 RH |
382 | #define LINE_NUMBER_BEGIN_LABEL "LSLT" |
383 | #define LINE_NUMBER_END_LABEL "LELT" | |
384 | #define LN_PROLOG_AS_LABEL "LASLTP" | |
385 | #define LN_PROLOG_END_LABEL "LELTP" | |
881c6935 | 386 | #define DIE_LABEL_PREFIX "DW" |
a3f97cbb | 387 | |
c8cc5c4a | 388 | /* The DWARF 2 CFA column which tracks the return address. Normally this |
a94dbf2c JM |
389 | is the column for PC, or the first column after all of the hard |
390 | registers. */ | |
c8cc5c4a | 391 | #ifndef DWARF_FRAME_RETURN_COLUMN |
a94dbf2c | 392 | #ifdef PC_REGNUM |
7080f735 | 393 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM) |
a94dbf2c | 394 | #else |
7080f735 | 395 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS |
a94dbf2c | 396 | #endif |
c8cc5c4a JM |
397 | #endif |
398 | ||
399 | /* The mapping from gcc register number to DWARF 2 CFA column number. By | |
469ac993 | 400 | default, we just provide columns for all registers. */ |
c8cc5c4a | 401 | #ifndef DWARF_FRAME_REGNUM |
469ac993 | 402 | #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG) |
c8cc5c4a | 403 | #endif |
3f76745e | 404 | |
2ad9852d RK |
405 | /* The offset from the incoming value of %sp to the top of the stack frame |
406 | for the current function. */ | |
407 | #ifndef INCOMING_FRAME_SP_OFFSET | |
408 | #define INCOMING_FRAME_SP_OFFSET 0 | |
409 | #endif | |
410 | \f | |
0021b564 JM |
411 | /* Hook used by __throw. */ |
412 | ||
413 | rtx | |
7080f735 | 414 | expand_builtin_dwarf_sp_column (void) |
0021b564 | 415 | { |
9c80ff25 | 416 | return GEN_INT (DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)); |
0021b564 JM |
417 | } |
418 | ||
71dfc51f | 419 | /* Return a pointer to a copy of the section string name S with all |
bf20f341 | 420 | attributes stripped off, and an asterisk prepended (for assemble_name). */ |
71dfc51f RK |
421 | |
422 | static inline char * | |
7080f735 | 423 | stripattributes (const char *s) |
a3f97cbb | 424 | { |
bf20f341 | 425 | char *stripped = xmalloc (strlen (s) + 2); |
71dfc51f RK |
426 | char *p = stripped; |
427 | ||
bf20f341 JW |
428 | *p++ = '*'; |
429 | ||
430 | while (*s && *s != ',') | |
431 | *p++ = *s++; | |
71dfc51f | 432 | |
a3f97cbb JW |
433 | *p = '\0'; |
434 | return stripped; | |
435 | } | |
436 | ||
d9d5c9de | 437 | /* Generate code to initialize the register size table. */ |
2f3ca9e7 | 438 | |
d9d5c9de | 439 | void |
7080f735 | 440 | expand_builtin_init_dwarf_reg_sizes (tree address) |
2f3ca9e7 | 441 | { |
d9d5c9de BS |
442 | int i; |
443 | enum machine_mode mode = TYPE_MODE (char_type_node); | |
444 | rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0); | |
2ad9852d | 445 | rtx mem = gen_rtx_MEM (BLKmode, addr); |
71628aa0 | 446 | bool wrote_return_column = false; |
2f3ca9e7 | 447 | |
91ea38f9 JH |
448 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) |
449 | if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS) | |
450 | { | |
451 | HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode); | |
fee226d2 R |
452 | enum machine_mode save_mode = reg_raw_mode[i]; |
453 | HOST_WIDE_INT size; | |
2f3ca9e7 | 454 | |
fee226d2 R |
455 | if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode)) |
456 | save_mode = choose_hard_reg_mode (i, 1, true); | |
71628aa0 R |
457 | if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN) |
458 | { | |
459 | if (save_mode == VOIDmode) | |
460 | continue; | |
461 | wrote_return_column = true; | |
462 | } | |
fee226d2 | 463 | size = GET_MODE_SIZE (save_mode); |
91ea38f9 JH |
464 | if (offset < 0) |
465 | continue; | |
c699cee9 | 466 | |
91ea38f9 JH |
467 | emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size)); |
468 | } | |
71628aa0 R |
469 | if (! wrote_return_column) |
470 | { | |
471 | enum machine_mode save_mode = Pmode; | |
472 | HOST_WIDE_INT offset = DWARF_FRAME_RETURN_COLUMN * GET_MODE_SIZE (mode); | |
473 | HOST_WIDE_INT size = GET_MODE_SIZE (save_mode); | |
474 | emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size)); | |
475 | } | |
2f3ca9e7 JM |
476 | } |
477 | ||
3f76745e | 478 | /* Convert a DWARF call frame info. operation to its string name */ |
a3f97cbb | 479 | |
d560ee52 | 480 | static const char * |
7080f735 | 481 | dwarf_cfi_name (unsigned int cfi_opc) |
3f76745e JM |
482 | { |
483 | switch (cfi_opc) | |
484 | { | |
485 | case DW_CFA_advance_loc: | |
486 | return "DW_CFA_advance_loc"; | |
487 | case DW_CFA_offset: | |
488 | return "DW_CFA_offset"; | |
489 | case DW_CFA_restore: | |
490 | return "DW_CFA_restore"; | |
491 | case DW_CFA_nop: | |
492 | return "DW_CFA_nop"; | |
493 | case DW_CFA_set_loc: | |
494 | return "DW_CFA_set_loc"; | |
495 | case DW_CFA_advance_loc1: | |
496 | return "DW_CFA_advance_loc1"; | |
497 | case DW_CFA_advance_loc2: | |
498 | return "DW_CFA_advance_loc2"; | |
499 | case DW_CFA_advance_loc4: | |
500 | return "DW_CFA_advance_loc4"; | |
501 | case DW_CFA_offset_extended: | |
502 | return "DW_CFA_offset_extended"; | |
503 | case DW_CFA_restore_extended: | |
504 | return "DW_CFA_restore_extended"; | |
505 | case DW_CFA_undefined: | |
506 | return "DW_CFA_undefined"; | |
507 | case DW_CFA_same_value: | |
508 | return "DW_CFA_same_value"; | |
509 | case DW_CFA_register: | |
510 | return "DW_CFA_register"; | |
511 | case DW_CFA_remember_state: | |
512 | return "DW_CFA_remember_state"; | |
513 | case DW_CFA_restore_state: | |
514 | return "DW_CFA_restore_state"; | |
515 | case DW_CFA_def_cfa: | |
516 | return "DW_CFA_def_cfa"; | |
517 | case DW_CFA_def_cfa_register: | |
518 | return "DW_CFA_def_cfa_register"; | |
519 | case DW_CFA_def_cfa_offset: | |
520 | return "DW_CFA_def_cfa_offset"; | |
6bb28965 JM |
521 | |
522 | /* DWARF 3 */ | |
7d9d8943 AM |
523 | case DW_CFA_def_cfa_expression: |
524 | return "DW_CFA_def_cfa_expression"; | |
6bb28965 JM |
525 | case DW_CFA_expression: |
526 | return "DW_CFA_expression"; | |
527 | case DW_CFA_offset_extended_sf: | |
528 | return "DW_CFA_offset_extended_sf"; | |
529 | case DW_CFA_def_cfa_sf: | |
530 | return "DW_CFA_def_cfa_sf"; | |
531 | case DW_CFA_def_cfa_offset_sf: | |
532 | return "DW_CFA_def_cfa_offset_sf"; | |
c53aa195 | 533 | |
3f76745e JM |
534 | /* SGI/MIPS specific */ |
535 | case DW_CFA_MIPS_advance_loc8: | |
536 | return "DW_CFA_MIPS_advance_loc8"; | |
c53aa195 JM |
537 | |
538 | /* GNU extensions */ | |
539 | case DW_CFA_GNU_window_save: | |
540 | return "DW_CFA_GNU_window_save"; | |
0021b564 JM |
541 | case DW_CFA_GNU_args_size: |
542 | return "DW_CFA_GNU_args_size"; | |
3f388b42 GK |
543 | case DW_CFA_GNU_negative_offset_extended: |
544 | return "DW_CFA_GNU_negative_offset_extended"; | |
c53aa195 | 545 | |
3f76745e JM |
546 | default: |
547 | return "DW_CFA_<unknown>"; | |
548 | } | |
549 | } | |
a3f97cbb | 550 | |
3f76745e | 551 | /* Return a pointer to a newly allocated Call Frame Instruction. */ |
71dfc51f | 552 | |
3f76745e | 553 | static inline dw_cfi_ref |
7080f735 | 554 | new_cfi (void) |
3f76745e | 555 | { |
703ad42b | 556 | dw_cfi_ref cfi = ggc_alloc (sizeof (dw_cfi_node)); |
71dfc51f | 557 | |
3f76745e JM |
558 | cfi->dw_cfi_next = NULL; |
559 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0; | |
560 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0; | |
a3f97cbb | 561 | |
3f76745e JM |
562 | return cfi; |
563 | } | |
a3f97cbb | 564 | |
3f76745e | 565 | /* Add a Call Frame Instruction to list of instructions. */ |
a3f97cbb | 566 | |
3f76745e | 567 | static inline void |
7080f735 | 568 | add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi) |
3f76745e | 569 | { |
b3694847 | 570 | dw_cfi_ref *p; |
a3f97cbb | 571 | |
3f76745e JM |
572 | /* Find the end of the chain. */ |
573 | for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next) | |
574 | ; | |
575 | ||
576 | *p = cfi; | |
a3f97cbb JW |
577 | } |
578 | ||
3f76745e | 579 | /* Generate a new label for the CFI info to refer to. */ |
71dfc51f | 580 | |
c53aa195 | 581 | char * |
7080f735 | 582 | dwarf2out_cfi_label (void) |
a3f97cbb | 583 | { |
3f76745e | 584 | static char label[20]; |
556273e0 | 585 | |
044b4de3 | 586 | ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++); |
3f76745e | 587 | ASM_OUTPUT_LABEL (asm_out_file, label); |
3f76745e | 588 | return label; |
a3f97cbb JW |
589 | } |
590 | ||
3f76745e JM |
591 | /* Add CFI to the current fde at the PC value indicated by LABEL if specified, |
592 | or to the CIE if LABEL is NULL. */ | |
71dfc51f | 593 | |
3f76745e | 594 | static void |
7080f735 | 595 | add_fde_cfi (const char *label, dw_cfi_ref cfi) |
a3f97cbb | 596 | { |
3f76745e JM |
597 | if (label) |
598 | { | |
b3694847 | 599 | dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
a3f97cbb | 600 | |
3f76745e JM |
601 | if (*label == 0) |
602 | label = dwarf2out_cfi_label (); | |
71dfc51f | 603 | |
3f76745e JM |
604 | if (fde->dw_fde_current_label == NULL |
605 | || strcmp (label, fde->dw_fde_current_label) != 0) | |
606 | { | |
b3694847 | 607 | dw_cfi_ref xcfi; |
a3f97cbb | 608 | |
3f76745e | 609 | fde->dw_fde_current_label = label = xstrdup (label); |
71dfc51f | 610 | |
3f76745e JM |
611 | /* Set the location counter to the new label. */ |
612 | xcfi = new_cfi (); | |
613 | xcfi->dw_cfi_opc = DW_CFA_advance_loc4; | |
614 | xcfi->dw_cfi_oprnd1.dw_cfi_addr = label; | |
615 | add_cfi (&fde->dw_fde_cfi, xcfi); | |
616 | } | |
71dfc51f | 617 | |
3f76745e JM |
618 | add_cfi (&fde->dw_fde_cfi, cfi); |
619 | } | |
620 | ||
621 | else | |
622 | add_cfi (&cie_cfi_head, cfi); | |
a3f97cbb JW |
623 | } |
624 | ||
3f76745e | 625 | /* Subroutine of lookup_cfa. */ |
71dfc51f | 626 | |
3f76745e | 627 | static inline void |
7080f735 | 628 | lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc) |
a3f97cbb | 629 | { |
3f76745e JM |
630 | switch (cfi->dw_cfi_opc) |
631 | { | |
632 | case DW_CFA_def_cfa_offset: | |
7d9d8943 | 633 | loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset; |
3f76745e JM |
634 | break; |
635 | case DW_CFA_def_cfa_register: | |
7d9d8943 | 636 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
3f76745e JM |
637 | break; |
638 | case DW_CFA_def_cfa: | |
7d9d8943 AM |
639 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
640 | loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset; | |
641 | break; | |
642 | case DW_CFA_def_cfa_expression: | |
643 | get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc); | |
3f76745e | 644 | break; |
e9a25f70 JL |
645 | default: |
646 | break; | |
3f76745e | 647 | } |
a3f97cbb JW |
648 | } |
649 | ||
3f76745e | 650 | /* Find the previous value for the CFA. */ |
71dfc51f | 651 | |
3f76745e | 652 | static void |
7080f735 | 653 | lookup_cfa (dw_cfa_location *loc) |
a3f97cbb | 654 | { |
b3694847 | 655 | dw_cfi_ref cfi; |
3f76745e | 656 | |
7d9d8943 AM |
657 | loc->reg = (unsigned long) -1; |
658 | loc->offset = 0; | |
659 | loc->indirect = 0; | |
660 | loc->base_offset = 0; | |
3f76745e JM |
661 | |
662 | for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next) | |
7d9d8943 | 663 | lookup_cfa_1 (cfi, loc); |
3f76745e JM |
664 | |
665 | if (fde_table_in_use) | |
a3f97cbb | 666 | { |
b3694847 | 667 | dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
3f76745e | 668 | for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next) |
7d9d8943 | 669 | lookup_cfa_1 (cfi, loc); |
a3f97cbb JW |
670 | } |
671 | } | |
672 | ||
3f76745e | 673 | /* The current rule for calculating the DWARF2 canonical frame address. */ |
fbfa55b0 | 674 | static dw_cfa_location cfa; |
71dfc51f | 675 | |
3f76745e JM |
676 | /* The register used for saving registers to the stack, and its offset |
677 | from the CFA. */ | |
fbfa55b0 | 678 | static dw_cfa_location cfa_store; |
3f76745e | 679 | |
0021b564 JM |
680 | /* The running total of the size of arguments pushed onto the stack. */ |
681 | static long args_size; | |
682 | ||
b57d9225 JM |
683 | /* The last args_size we actually output. */ |
684 | static long old_args_size; | |
685 | ||
3f76745e JM |
686 | /* Entry point to update the canonical frame address (CFA). |
687 | LABEL is passed to add_fde_cfi. The value of CFA is now to be | |
688 | calculated from REG+OFFSET. */ | |
689 | ||
690 | void | |
7080f735 | 691 | dwarf2out_def_cfa (const char *label, unsigned int reg, long int offset) |
7d9d8943 AM |
692 | { |
693 | dw_cfa_location loc; | |
694 | loc.indirect = 0; | |
695 | loc.base_offset = 0; | |
696 | loc.reg = reg; | |
697 | loc.offset = offset; | |
698 | def_cfa_1 (label, &loc); | |
699 | } | |
700 | ||
770ca8c6 | 701 | /* This routine does the actual work. The CFA is now calculated from |
7d9d8943 | 702 | the dw_cfa_location structure. */ |
2ad9852d | 703 | |
7d9d8943 | 704 | static void |
7080f735 | 705 | def_cfa_1 (const char *label, dw_cfa_location *loc_p) |
a3f97cbb | 706 | { |
b3694847 | 707 | dw_cfi_ref cfi; |
7d9d8943 | 708 | dw_cfa_location old_cfa, loc; |
3f76745e | 709 | |
7d9d8943 AM |
710 | cfa = *loc_p; |
711 | loc = *loc_p; | |
5bef9b1f | 712 | |
7d9d8943 AM |
713 | if (cfa_store.reg == loc.reg && loc.indirect == 0) |
714 | cfa_store.offset = loc.offset; | |
3f76745e | 715 | |
7d9d8943 AM |
716 | loc.reg = DWARF_FRAME_REGNUM (loc.reg); |
717 | lookup_cfa (&old_cfa); | |
718 | ||
2ad9852d RK |
719 | /* If nothing changed, no need to issue any call frame instructions. */ |
720 | if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset | |
721 | && loc.indirect == old_cfa.indirect | |
722 | && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset)) | |
723 | return; | |
3f76745e JM |
724 | |
725 | cfi = new_cfi (); | |
726 | ||
e09bbb25 | 727 | if (loc.reg == old_cfa.reg && !loc.indirect) |
a3f97cbb | 728 | { |
770ca8c6 JO |
729 | /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, |
730 | indicating the CFA register did not change but the offset | |
731 | did. */ | |
3f76745e | 732 | cfi->dw_cfi_opc = DW_CFA_def_cfa_offset; |
7d9d8943 | 733 | cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset; |
3f76745e | 734 | } |
a3f97cbb | 735 | |
3f76745e | 736 | #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */ |
7d9d8943 | 737 | else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1 |
e09bbb25 | 738 | && !loc.indirect) |
3f76745e | 739 | { |
770ca8c6 JO |
740 | /* Construct a "DW_CFA_def_cfa_register <register>" instruction, |
741 | indicating the CFA register has changed to <register> but the | |
742 | offset has not changed. */ | |
3f76745e | 743 | cfi->dw_cfi_opc = DW_CFA_def_cfa_register; |
7d9d8943 | 744 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
3f76745e JM |
745 | } |
746 | #endif | |
a3f97cbb | 747 | |
7d9d8943 | 748 | else if (loc.indirect == 0) |
3f76745e | 749 | { |
770ca8c6 JO |
750 | /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction, |
751 | indicating the CFA register has changed to <register> with | |
752 | the specified offset. */ | |
3f76745e | 753 | cfi->dw_cfi_opc = DW_CFA_def_cfa; |
7d9d8943 AM |
754 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
755 | cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset; | |
756 | } | |
757 | else | |
758 | { | |
770ca8c6 JO |
759 | /* Construct a DW_CFA_def_cfa_expression instruction to |
760 | calculate the CFA using a full location expression since no | |
761 | register-offset pair is available. */ | |
556273e0 | 762 | struct dw_loc_descr_struct *loc_list; |
2ad9852d | 763 | |
7d9d8943 AM |
764 | cfi->dw_cfi_opc = DW_CFA_def_cfa_expression; |
765 | loc_list = build_cfa_loc (&loc); | |
766 | cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list; | |
a3f97cbb | 767 | } |
3f76745e JM |
768 | |
769 | add_fde_cfi (label, cfi); | |
a3f97cbb JW |
770 | } |
771 | ||
3f76745e JM |
772 | /* Add the CFI for saving a register. REG is the CFA column number. |
773 | LABEL is passed to add_fde_cfi. | |
774 | If SREG is -1, the register is saved at OFFSET from the CFA; | |
775 | otherwise it is saved in SREG. */ | |
71dfc51f | 776 | |
3f76745e | 777 | static void |
7080f735 | 778 | reg_save (const char *label, unsigned int reg, unsigned int sreg, long int offset) |
a3f97cbb | 779 | { |
b3694847 | 780 | dw_cfi_ref cfi = new_cfi (); |
3f76745e JM |
781 | |
782 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
783 | ||
85066503 MH |
784 | /* The following comparison is correct. -1 is used to indicate that |
785 | the value isn't a register number. */ | |
786 | if (sreg == (unsigned int) -1) | |
a3f97cbb | 787 | { |
3f76745e JM |
788 | if (reg & ~0x3f) |
789 | /* The register number won't fit in 6 bits, so we have to use | |
790 | the long form. */ | |
791 | cfi->dw_cfi_opc = DW_CFA_offset_extended; | |
792 | else | |
793 | cfi->dw_cfi_opc = DW_CFA_offset; | |
794 | ||
27c35f4b HPN |
795 | #ifdef ENABLE_CHECKING |
796 | { | |
797 | /* If we get an offset that is not a multiple of | |
798 | DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the | |
799 | definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine | |
800 | description. */ | |
801 | long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT; | |
802 | ||
803 | if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset) | |
804 | abort (); | |
805 | } | |
806 | #endif | |
3f76745e | 807 | offset /= DWARF_CIE_DATA_ALIGNMENT; |
3a88cbd1 | 808 | if (offset < 0) |
6bb28965 | 809 | cfi->dw_cfi_opc = DW_CFA_offset_extended_sf; |
2ad9852d | 810 | |
3f76745e JM |
811 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; |
812 | } | |
2c849145 JM |
813 | else if (sreg == reg) |
814 | /* We could emit a DW_CFA_same_value in this case, but don't bother. */ | |
815 | return; | |
3f76745e JM |
816 | else |
817 | { | |
818 | cfi->dw_cfi_opc = DW_CFA_register; | |
819 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg; | |
820 | } | |
821 | ||
822 | add_fde_cfi (label, cfi); | |
823 | } | |
824 | ||
c53aa195 JM |
825 | /* Add the CFI for saving a register window. LABEL is passed to reg_save. |
826 | This CFI tells the unwinder that it needs to restore the window registers | |
827 | from the previous frame's window save area. | |
556273e0 | 828 | |
c53aa195 JM |
829 | ??? Perhaps we should note in the CIE where windows are saved (instead of |
830 | assuming 0(cfa)) and what registers are in the window. */ | |
831 | ||
832 | void | |
7080f735 | 833 | dwarf2out_window_save (const char *label) |
c53aa195 | 834 | { |
b3694847 | 835 | dw_cfi_ref cfi = new_cfi (); |
2ad9852d | 836 | |
c53aa195 JM |
837 | cfi->dw_cfi_opc = DW_CFA_GNU_window_save; |
838 | add_fde_cfi (label, cfi); | |
839 | } | |
840 | ||
0021b564 JM |
841 | /* Add a CFI to update the running total of the size of arguments |
842 | pushed onto the stack. */ | |
843 | ||
844 | void | |
7080f735 | 845 | dwarf2out_args_size (const char *label, long int size) |
0021b564 | 846 | { |
b3694847 | 847 | dw_cfi_ref cfi; |
b57d9225 JM |
848 | |
849 | if (size == old_args_size) | |
850 | return; | |
2ad9852d | 851 | |
b57d9225 JM |
852 | old_args_size = size; |
853 | ||
854 | cfi = new_cfi (); | |
0021b564 JM |
855 | cfi->dw_cfi_opc = DW_CFA_GNU_args_size; |
856 | cfi->dw_cfi_oprnd1.dw_cfi_offset = size; | |
857 | add_fde_cfi (label, cfi); | |
858 | } | |
859 | ||
c53aa195 JM |
860 | /* Entry point for saving a register to the stack. REG is the GCC register |
861 | number. LABEL and OFFSET are passed to reg_save. */ | |
3f76745e JM |
862 | |
863 | void | |
7080f735 | 864 | dwarf2out_reg_save (const char *label, unsigned int reg, long int offset) |
3f76745e JM |
865 | { |
866 | reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset); | |
867 | } | |
868 | ||
c53aa195 JM |
869 | /* Entry point for saving the return address in the stack. |
870 | LABEL and OFFSET are passed to reg_save. */ | |
871 | ||
872 | void | |
7080f735 | 873 | dwarf2out_return_save (const char *label, long int offset) |
c53aa195 JM |
874 | { |
875 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset); | |
876 | } | |
877 | ||
878 | /* Entry point for saving the return address in a register. | |
879 | LABEL and SREG are passed to reg_save. */ | |
880 | ||
881 | void | |
7080f735 | 882 | dwarf2out_return_reg (const char *label, unsigned int sreg) |
c53aa195 JM |
883 | { |
884 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0); | |
885 | } | |
886 | ||
3f76745e JM |
887 | /* Record the initial position of the return address. RTL is |
888 | INCOMING_RETURN_ADDR_RTX. */ | |
889 | ||
890 | static void | |
7080f735 | 891 | initial_return_save (rtx rtl) |
3f76745e | 892 | { |
973838fd | 893 | unsigned int reg = (unsigned int) -1; |
2ad9852d | 894 | HOST_WIDE_INT offset = 0; |
3f76745e JM |
895 | |
896 | switch (GET_CODE (rtl)) | |
897 | { | |
898 | case REG: | |
899 | /* RA is in a register. */ | |
2c849145 | 900 | reg = DWARF_FRAME_REGNUM (REGNO (rtl)); |
3f76745e | 901 | break; |
2ad9852d | 902 | |
3f76745e JM |
903 | case MEM: |
904 | /* RA is on the stack. */ | |
905 | rtl = XEXP (rtl, 0); | |
906 | switch (GET_CODE (rtl)) | |
907 | { | |
908 | case REG: | |
3a88cbd1 JL |
909 | if (REGNO (rtl) != STACK_POINTER_REGNUM) |
910 | abort (); | |
3f76745e JM |
911 | offset = 0; |
912 | break; | |
2ad9852d | 913 | |
3f76745e | 914 | case PLUS: |
3a88cbd1 JL |
915 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
916 | abort (); | |
3f76745e JM |
917 | offset = INTVAL (XEXP (rtl, 1)); |
918 | break; | |
2ad9852d | 919 | |
3f76745e | 920 | case MINUS: |
3a88cbd1 JL |
921 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
922 | abort (); | |
3f76745e JM |
923 | offset = -INTVAL (XEXP (rtl, 1)); |
924 | break; | |
2ad9852d | 925 | |
3f76745e JM |
926 | default: |
927 | abort (); | |
928 | } | |
2ad9852d | 929 | |
3f76745e | 930 | break; |
2ad9852d | 931 | |
c53aa195 JM |
932 | case PLUS: |
933 | /* The return address is at some offset from any value we can | |
934 | actually load. For instance, on the SPARC it is in %i7+8. Just | |
935 | ignore the offset for now; it doesn't matter for unwinding frames. */ | |
3a88cbd1 JL |
936 | if (GET_CODE (XEXP (rtl, 1)) != CONST_INT) |
937 | abort (); | |
c53aa195 JM |
938 | initial_return_save (XEXP (rtl, 0)); |
939 | return; | |
2ad9852d | 940 | |
a3f97cbb | 941 | default: |
3f76745e | 942 | abort (); |
a3f97cbb | 943 | } |
3f76745e | 944 | |
7d9d8943 | 945 | reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset); |
a3f97cbb JW |
946 | } |
947 | ||
1ba5ae8f | 948 | /* Given a SET, calculate the amount of stack adjustment it |
30f7a378 | 949 | contains. */ |
1ba5ae8f | 950 | |
5e640c56 | 951 | static long |
7080f735 | 952 | stack_adjust_offset (rtx pattern) |
1ba5ae8f AH |
953 | { |
954 | rtx src = SET_SRC (pattern); | |
955 | rtx dest = SET_DEST (pattern); | |
2ad9852d | 956 | HOST_WIDE_INT offset = 0; |
1ba5ae8f AH |
957 | enum rtx_code code; |
958 | ||
959 | if (dest == stack_pointer_rtx) | |
960 | { | |
961 | /* (set (reg sp) (plus (reg sp) (const_int))) */ | |
962 | code = GET_CODE (src); | |
963 | if (! (code == PLUS || code == MINUS) | |
964 | || XEXP (src, 0) != stack_pointer_rtx | |
965 | || GET_CODE (XEXP (src, 1)) != CONST_INT) | |
966 | return 0; | |
967 | ||
968 | offset = INTVAL (XEXP (src, 1)); | |
f472fa29 AM |
969 | if (code == PLUS) |
970 | offset = -offset; | |
1ba5ae8f AH |
971 | } |
972 | else if (GET_CODE (dest) == MEM) | |
973 | { | |
974 | /* (set (mem (pre_dec (reg sp))) (foo)) */ | |
975 | src = XEXP (dest, 0); | |
976 | code = GET_CODE (src); | |
977 | ||
c26fbbca KH |
978 | switch (code) |
979 | { | |
f472fa29 AM |
980 | case PRE_MODIFY: |
981 | case POST_MODIFY: | |
982 | if (XEXP (src, 0) == stack_pointer_rtx) | |
983 | { | |
984 | rtx val = XEXP (XEXP (src, 1), 1); | |
985 | /* We handle only adjustments by constant amount. */ | |
986 | if (GET_CODE (XEXP (src, 1)) != PLUS || | |
987 | GET_CODE (val) != CONST_INT) | |
c26fbbca | 988 | abort (); |
f472fa29 AM |
989 | offset = -INTVAL (val); |
990 | break; | |
991 | } | |
992 | return 0; | |
993 | ||
994 | case PRE_DEC: | |
995 | case POST_DEC: | |
996 | if (XEXP (src, 0) == stack_pointer_rtx) | |
997 | { | |
998 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
999 | break; | |
1000 | } | |
1001 | return 0; | |
1002 | ||
1003 | case PRE_INC: | |
1004 | case POST_INC: | |
1005 | if (XEXP (src, 0) == stack_pointer_rtx) | |
1006 | { | |
1007 | offset = -GET_MODE_SIZE (GET_MODE (dest)); | |
1008 | break; | |
1009 | } | |
1010 | return 0; | |
2ad9852d | 1011 | |
f472fa29 AM |
1012 | default: |
1013 | return 0; | |
e2134eea | 1014 | } |
1ba5ae8f AH |
1015 | } |
1016 | else | |
1017 | return 0; | |
1018 | ||
1ba5ae8f AH |
1019 | return offset; |
1020 | } | |
1021 | ||
0021b564 JM |
1022 | /* Check INSN to see if it looks like a push or a stack adjustment, and |
1023 | make a note of it if it does. EH uses this information to find out how | |
1024 | much extra space it needs to pop off the stack. */ | |
1025 | ||
1026 | static void | |
7080f735 | 1027 | dwarf2out_stack_adjust (rtx insn) |
0021b564 | 1028 | { |
2ad9852d | 1029 | HOST_WIDE_INT offset; |
d3e3972c | 1030 | const char *label; |
2ad9852d | 1031 | int i; |
0021b564 | 1032 | |
2ad9852d | 1033 | if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN) |
b57d9225 JM |
1034 | { |
1035 | /* Extract the size of the args from the CALL rtx itself. */ | |
b57d9225 JM |
1036 | insn = PATTERN (insn); |
1037 | if (GET_CODE (insn) == PARALLEL) | |
1038 | insn = XVECEXP (insn, 0, 0); | |
1039 | if (GET_CODE (insn) == SET) | |
1040 | insn = SET_SRC (insn); | |
3db35af4 MM |
1041 | if (GET_CODE (insn) != CALL) |
1042 | abort (); | |
2ad9852d | 1043 | |
b57d9225 JM |
1044 | dwarf2out_args_size ("", INTVAL (XEXP (insn, 1))); |
1045 | return; | |
1046 | } | |
1047 | ||
1048 | /* If only calls can throw, and we have a frame pointer, | |
1049 | save up adjustments until we see the CALL_INSN. */ | |
2ad9852d | 1050 | else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM) |
b57d9225 JM |
1051 | return; |
1052 | ||
6020d360 | 1053 | if (GET_CODE (insn) == BARRIER) |
0021b564 | 1054 | { |
6020d360 JM |
1055 | /* When we see a BARRIER, we know to reset args_size to 0. Usually |
1056 | the compiler will have already emitted a stack adjustment, but | |
1057 | doesn't bother for calls to noreturn functions. */ | |
1058 | #ifdef STACK_GROWS_DOWNWARD | |
1059 | offset = -args_size; | |
1060 | #else | |
1061 | offset = args_size; | |
1062 | #endif | |
0021b564 | 1063 | } |
6020d360 | 1064 | else if (GET_CODE (PATTERN (insn)) == SET) |
2ad9852d | 1065 | offset = stack_adjust_offset (PATTERN (insn)); |
1ba5ae8f AH |
1066 | else if (GET_CODE (PATTERN (insn)) == PARALLEL |
1067 | || GET_CODE (PATTERN (insn)) == SEQUENCE) | |
1068 | { | |
1069 | /* There may be stack adjustments inside compound insns. Search | |
2ad9852d RK |
1070 | for them. */ |
1071 | for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--) | |
1072 | if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET) | |
1073 | offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i)); | |
0021b564 JM |
1074 | } |
1075 | else | |
1076 | return; | |
0b34cf1e | 1077 | |
6020d360 JM |
1078 | if (offset == 0) |
1079 | return; | |
1080 | ||
7d9d8943 AM |
1081 | if (cfa.reg == STACK_POINTER_REGNUM) |
1082 | cfa.offset += offset; | |
0021b564 JM |
1083 | |
1084 | #ifndef STACK_GROWS_DOWNWARD | |
1085 | offset = -offset; | |
1086 | #endif | |
2ad9852d | 1087 | |
0021b564 JM |
1088 | args_size += offset; |
1089 | if (args_size < 0) | |
1090 | args_size = 0; | |
1091 | ||
1092 | label = dwarf2out_cfi_label (); | |
7d9d8943 | 1093 | def_cfa_1 (label, &cfa); |
0021b564 JM |
1094 | dwarf2out_args_size (label, args_size); |
1095 | } | |
1096 | ||
17211ab5 GK |
1097 | #endif |
1098 | ||
fbfa55b0 RH |
1099 | /* We delay emitting a register save until either (a) we reach the end |
1100 | of the prologue or (b) the register is clobbered. This clusters | |
1101 | register saves so that there are fewer pc advances. */ | |
1102 | ||
17211ab5 | 1103 | struct queued_reg_save GTY(()) |
fbfa55b0 RH |
1104 | { |
1105 | struct queued_reg_save *next; | |
1106 | rtx reg; | |
1107 | long cfa_offset; | |
1108 | }; | |
1109 | ||
17211ab5 GK |
1110 | static GTY(()) struct queued_reg_save *queued_reg_saves; |
1111 | ||
1112 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) | |
fbfa55b0 RH |
1113 | static const char *last_reg_save_label; |
1114 | ||
1115 | static void | |
7080f735 | 1116 | queue_reg_save (const char *label, rtx reg, long int offset) |
fbfa55b0 | 1117 | { |
17211ab5 | 1118 | struct queued_reg_save *q = ggc_alloc (sizeof (*q)); |
fbfa55b0 RH |
1119 | |
1120 | q->next = queued_reg_saves; | |
1121 | q->reg = reg; | |
1122 | q->cfa_offset = offset; | |
1123 | queued_reg_saves = q; | |
1124 | ||
1125 | last_reg_save_label = label; | |
1126 | } | |
1127 | ||
1128 | static void | |
7080f735 | 1129 | flush_queued_reg_saves (void) |
fbfa55b0 RH |
1130 | { |
1131 | struct queued_reg_save *q, *next; | |
1132 | ||
c26fbbca | 1133 | for (q = queued_reg_saves; q; q = next) |
fbfa55b0 RH |
1134 | { |
1135 | dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset); | |
1136 | next = q->next; | |
fbfa55b0 RH |
1137 | } |
1138 | ||
1139 | queued_reg_saves = NULL; | |
1140 | last_reg_save_label = NULL; | |
1141 | } | |
1142 | ||
1143 | static bool | |
7080f735 | 1144 | clobbers_queued_reg_save (rtx insn) |
fbfa55b0 RH |
1145 | { |
1146 | struct queued_reg_save *q; | |
1147 | ||
c26fbbca | 1148 | for (q = queued_reg_saves; q; q = q->next) |
fbfa55b0 RH |
1149 | if (modified_in_p (q->reg, insn)) |
1150 | return true; | |
1151 | ||
1152 | return false; | |
1153 | } | |
c26fbbca | 1154 | |
fbfa55b0 | 1155 | |
770ca8c6 JO |
1156 | /* A temporary register holding an integral value used in adjusting SP |
1157 | or setting up the store_reg. The "offset" field holds the integer | |
1158 | value, not an offset. */ | |
fbfa55b0 | 1159 | static dw_cfa_location cfa_temp; |
770ca8c6 JO |
1160 | |
1161 | /* Record call frame debugging information for an expression EXPR, | |
1162 | which either sets SP or FP (adjusting how we calculate the frame | |
1163 | address) or saves a register to the stack. LABEL indicates the | |
1164 | address of EXPR. | |
1165 | ||
1166 | This function encodes a state machine mapping rtxes to actions on | |
1167 | cfa, cfa_store, and cfa_temp.reg. We describe these rules so | |
1168 | users need not read the source code. | |
1169 | ||
a401107d JO |
1170 | The High-Level Picture |
1171 | ||
1172 | Changes in the register we use to calculate the CFA: Currently we | |
1173 | assume that if you copy the CFA register into another register, we | |
1174 | should take the other one as the new CFA register; this seems to | |
1175 | work pretty well. If it's wrong for some target, it's simple | |
1176 | enough not to set RTX_FRAME_RELATED_P on the insn in question. | |
1177 | ||
1178 | Changes in the register we use for saving registers to the stack: | |
1179 | This is usually SP, but not always. Again, we deduce that if you | |
1180 | copy SP into another register (and SP is not the CFA register), | |
1181 | then the new register is the one we will be using for register | |
1182 | saves. This also seems to work. | |
1183 | ||
1184 | Register saves: There's not much guesswork about this one; if | |
1185 | RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a | |
1186 | register save, and the register used to calculate the destination | |
1187 | had better be the one we think we're using for this purpose. | |
1188 | ||
1189 | Except: If the register being saved is the CFA register, and the | |
cc2902df | 1190 | offset is nonzero, we are saving the CFA, so we assume we have to |
a401107d JO |
1191 | use DW_CFA_def_cfa_expression. If the offset is 0, we assume that |
1192 | the intent is to save the value of SP from the previous frame. | |
1193 | ||
770ca8c6 JO |
1194 | Invariants / Summaries of Rules |
1195 | ||
a401107d JO |
1196 | cfa current rule for calculating the CFA. It usually |
1197 | consists of a register and an offset. | |
770ca8c6 JO |
1198 | cfa_store register used by prologue code to save things to the stack |
1199 | cfa_store.offset is the offset from the value of | |
1200 | cfa_store.reg to the actual CFA | |
1201 | cfa_temp register holding an integral value. cfa_temp.offset | |
1202 | stores the value, which will be used to adjust the | |
19ec6a36 AM |
1203 | stack pointer. cfa_temp is also used like cfa_store, |
1204 | to track stores to the stack via fp or a temp reg. | |
c26fbbca | 1205 | |
770ca8c6 | 1206 | Rules 1- 4: Setting a register's value to cfa.reg or an expression |
7080f735 | 1207 | with cfa.reg as the first operand changes the cfa.reg and its |
19ec6a36 AM |
1208 | cfa.offset. Rule 1 and 4 also set cfa_temp.reg and |
1209 | cfa_temp.offset. | |
770ca8c6 JO |
1210 | |
1211 | Rules 6- 9: Set a non-cfa.reg register value to a constant or an | |
1212 | expression yielding a constant. This sets cfa_temp.reg | |
1213 | and cfa_temp.offset. | |
1214 | ||
1215 | Rule 5: Create a new register cfa_store used to save items to the | |
1216 | stack. | |
1217 | ||
19ec6a36 | 1218 | Rules 10-14: Save a register to the stack. Define offset as the |
a401107d | 1219 | difference of the original location and cfa_store's |
19ec6a36 | 1220 | location (or cfa_temp's location if cfa_temp is used). |
770ca8c6 JO |
1221 | |
1222 | The Rules | |
1223 | ||
1224 | "{a,b}" indicates a choice of a xor b. | |
1225 | "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg. | |
1226 | ||
1227 | Rule 1: | |
1228 | (set <reg1> <reg2>:cfa.reg) | |
19ec6a36 | 1229 | effects: cfa.reg = <reg1> |
73c68f61 | 1230 | cfa.offset unchanged |
19ec6a36 AM |
1231 | cfa_temp.reg = <reg1> |
1232 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1233 | |
1234 | Rule 2: | |
2ad9852d RK |
1235 | (set sp ({minus,plus,losum} {sp,fp}:cfa.reg |
1236 | {<const_int>,<reg>:cfa_temp.reg})) | |
770ca8c6 | 1237 | effects: cfa.reg = sp if fp used |
7080f735 | 1238 | cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp |
770ca8c6 JO |
1239 | cfa_store.offset += {+/- <const_int>, cfa_temp.offset} |
1240 | if cfa_store.reg==sp | |
1241 | ||
1242 | Rule 3: | |
19ec6a36 | 1243 | (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>)) |
770ca8c6 | 1244 | effects: cfa.reg = fp |
7080f735 | 1245 | cfa_offset += +/- <const_int> |
770ca8c6 JO |
1246 | |
1247 | Rule 4: | |
19ec6a36 | 1248 | (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>)) |
770ca8c6 | 1249 | constraints: <reg1> != fp |
7080f735 | 1250 | <reg1> != sp |
770ca8c6 | 1251 | effects: cfa.reg = <reg1> |
19ec6a36 AM |
1252 | cfa_temp.reg = <reg1> |
1253 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1254 | |
1255 | Rule 5: | |
1256 | (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg)) | |
1257 | constraints: <reg1> != fp | |
7080f735 | 1258 | <reg1> != sp |
770ca8c6 | 1259 | effects: cfa_store.reg = <reg1> |
7080f735 | 1260 | cfa_store.offset = cfa.offset - cfa_temp.offset |
770ca8c6 JO |
1261 | |
1262 | Rule 6: | |
1263 | (set <reg> <const_int>) | |
1264 | effects: cfa_temp.reg = <reg> | |
7080f735 | 1265 | cfa_temp.offset = <const_int> |
770ca8c6 JO |
1266 | |
1267 | Rule 7: | |
1268 | (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>)) | |
1269 | effects: cfa_temp.reg = <reg1> | |
1270 | cfa_temp.offset |= <const_int> | |
1271 | ||
1272 | Rule 8: | |
1273 | (set <reg> (high <exp>)) | |
1274 | effects: none | |
1275 | ||
1276 | Rule 9: | |
1277 | (set <reg> (lo_sum <exp> <const_int>)) | |
1278 | effects: cfa_temp.reg = <reg> | |
7080f735 | 1279 | cfa_temp.offset = <const_int> |
770ca8c6 JO |
1280 | |
1281 | Rule 10: | |
1282 | (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>) | |
1283 | effects: cfa_store.offset -= <const_int> | |
1284 | cfa.offset = cfa_store.offset if cfa.reg == sp | |
770ca8c6 | 1285 | cfa.reg = sp |
19ec6a36 | 1286 | cfa.base_offset = -cfa_store.offset |
770ca8c6 JO |
1287 | |
1288 | Rule 11: | |
1289 | (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>) | |
1290 | effects: cfa_store.offset += -/+ mode_size(mem) | |
1291 | cfa.offset = cfa_store.offset if cfa.reg == sp | |
770ca8c6 | 1292 | cfa.reg = sp |
19ec6a36 | 1293 | cfa.base_offset = -cfa_store.offset |
770ca8c6 JO |
1294 | |
1295 | Rule 12: | |
2ad9852d RK |
1296 | (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) |
1297 | ||
1298 | <reg2>) | |
19ec6a36 AM |
1299 | effects: cfa.reg = <reg1> |
1300 | cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset | |
770ca8c6 JO |
1301 | |
1302 | Rule 13: | |
19ec6a36 AM |
1303 | (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>) |
1304 | effects: cfa.reg = <reg1> | |
1305 | cfa.base_offset = -{cfa_store,cfa_temp}.offset | |
1306 | ||
1307 | Rule 14: | |
1308 | (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>) | |
1309 | effects: cfa.reg = <reg1> | |
1310 | cfa.base_offset = -cfa_temp.offset | |
1311 | cfa_temp.offset -= mode_size(mem) */ | |
b664de3a AM |
1312 | |
1313 | static void | |
7080f735 | 1314 | dwarf2out_frame_debug_expr (rtx expr, const char *label) |
b664de3a AM |
1315 | { |
1316 | rtx src, dest; | |
2ad9852d | 1317 | HOST_WIDE_INT offset; |
556273e0 KH |
1318 | |
1319 | /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of | |
1320 | the PARALLEL independently. The first element is always processed if | |
770ca8c6 | 1321 | it is a SET. This is for backward compatibility. Other elements |
556273e0 KH |
1322 | are processed only if they are SETs and the RTX_FRAME_RELATED_P |
1323 | flag is set in them. */ | |
2ad9852d | 1324 | if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE) |
556273e0 | 1325 | { |
b664de3a AM |
1326 | int par_index; |
1327 | int limit = XVECLEN (expr, 0); | |
1328 | ||
1329 | for (par_index = 0; par_index < limit; par_index++) | |
2ad9852d RK |
1330 | if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET |
1331 | && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index)) | |
1332 | || par_index == 0)) | |
1333 | dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label); | |
556273e0 | 1334 | |
b664de3a AM |
1335 | return; |
1336 | } | |
556273e0 | 1337 | |
b664de3a AM |
1338 | if (GET_CODE (expr) != SET) |
1339 | abort (); | |
1340 | ||
1341 | src = SET_SRC (expr); | |
1342 | dest = SET_DEST (expr); | |
1343 | ||
1344 | switch (GET_CODE (dest)) | |
1345 | { | |
1346 | case REG: | |
770ca8c6 | 1347 | /* Rule 1 */ |
b664de3a | 1348 | /* Update the CFA rule wrt SP or FP. Make sure src is |
73c68f61 | 1349 | relative to the current CFA register. */ |
b664de3a | 1350 | switch (GET_CODE (src)) |
556273e0 KH |
1351 | { |
1352 | /* Setting FP from SP. */ | |
1353 | case REG: | |
1354 | if (cfa.reg == (unsigned) REGNO (src)) | |
1355 | /* OK. */ | |
1356 | ; | |
626d1efd | 1357 | else |
556273e0 | 1358 | abort (); |
2c849145 JM |
1359 | |
1360 | /* We used to require that dest be either SP or FP, but the | |
1361 | ARM copies SP to a temporary register, and from there to | |
1362 | FP. So we just rely on the backends to only set | |
1363 | RTX_FRAME_RELATED_P on appropriate insns. */ | |
556273e0 | 1364 | cfa.reg = REGNO (dest); |
19ec6a36 AM |
1365 | cfa_temp.reg = cfa.reg; |
1366 | cfa_temp.offset = cfa.offset; | |
556273e0 | 1367 | break; |
b664de3a | 1368 | |
556273e0 KH |
1369 | case PLUS: |
1370 | case MINUS: | |
19ec6a36 | 1371 | case LO_SUM: |
556273e0 KH |
1372 | if (dest == stack_pointer_rtx) |
1373 | { | |
770ca8c6 | 1374 | /* Rule 2 */ |
2618f955 MM |
1375 | /* Adjusting SP. */ |
1376 | switch (GET_CODE (XEXP (src, 1))) | |
1377 | { | |
1378 | case CONST_INT: | |
1379 | offset = INTVAL (XEXP (src, 1)); | |
1380 | break; | |
1381 | case REG: | |
770ca8c6 | 1382 | if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg) |
2618f955 | 1383 | abort (); |
770ca8c6 | 1384 | offset = cfa_temp.offset; |
2618f955 MM |
1385 | break; |
1386 | default: | |
1387 | abort (); | |
1388 | } | |
1389 | ||
1390 | if (XEXP (src, 0) == hard_frame_pointer_rtx) | |
1391 | { | |
1392 | /* Restoring SP from FP in the epilogue. */ | |
7d9d8943 | 1393 | if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM) |
2618f955 | 1394 | abort (); |
7d9d8943 | 1395 | cfa.reg = STACK_POINTER_REGNUM; |
2618f955 | 1396 | } |
19ec6a36 AM |
1397 | else if (GET_CODE (src) == LO_SUM) |
1398 | /* Assume we've set the source reg of the LO_SUM from sp. */ | |
1399 | ; | |
2618f955 MM |
1400 | else if (XEXP (src, 0) != stack_pointer_rtx) |
1401 | abort (); | |
1402 | ||
19ec6a36 | 1403 | if (GET_CODE (src) != MINUS) |
2618f955 | 1404 | offset = -offset; |
7d9d8943 AM |
1405 | if (cfa.reg == STACK_POINTER_REGNUM) |
1406 | cfa.offset += offset; | |
1407 | if (cfa_store.reg == STACK_POINTER_REGNUM) | |
1408 | cfa_store.offset += offset; | |
556273e0 KH |
1409 | } |
1410 | else if (dest == hard_frame_pointer_rtx) | |
1411 | { | |
770ca8c6 | 1412 | /* Rule 3 */ |
2618f955 MM |
1413 | /* Either setting the FP from an offset of the SP, |
1414 | or adjusting the FP */ | |
2c849145 | 1415 | if (! frame_pointer_needed) |
2618f955 MM |
1416 | abort (); |
1417 | ||
2c849145 | 1418 | if (GET_CODE (XEXP (src, 0)) == REG |
7d9d8943 | 1419 | && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg |
2618f955 MM |
1420 | && GET_CODE (XEXP (src, 1)) == CONST_INT) |
1421 | { | |
2618f955 | 1422 | offset = INTVAL (XEXP (src, 1)); |
19ec6a36 | 1423 | if (GET_CODE (src) != MINUS) |
2618f955 | 1424 | offset = -offset; |
7d9d8943 AM |
1425 | cfa.offset += offset; |
1426 | cfa.reg = HARD_FRAME_POINTER_REGNUM; | |
2618f955 | 1427 | } |
556273e0 KH |
1428 | else |
1429 | abort (); | |
1430 | } | |
1431 | else | |
1432 | { | |
19ec6a36 | 1433 | if (GET_CODE (src) == MINUS) |
2618f955 | 1434 | abort (); |
b53ef1a2 | 1435 | |
770ca8c6 | 1436 | /* Rule 4 */ |
b53ef1a2 NC |
1437 | if (GET_CODE (XEXP (src, 0)) == REG |
1438 | && REGNO (XEXP (src, 0)) == cfa.reg | |
1439 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
34ce3d7b JM |
1440 | { |
1441 | /* Setting a temporary CFA register that will be copied | |
1442 | into the FP later on. */ | |
19ec6a36 | 1443 | offset = - INTVAL (XEXP (src, 1)); |
34ce3d7b JM |
1444 | cfa.offset += offset; |
1445 | cfa.reg = REGNO (dest); | |
19ec6a36 AM |
1446 | /* Or used to save regs to the stack. */ |
1447 | cfa_temp.reg = cfa.reg; | |
1448 | cfa_temp.offset = cfa.offset; | |
34ce3d7b | 1449 | } |
2ad9852d | 1450 | |
770ca8c6 | 1451 | /* Rule 5 */ |
19ec6a36 AM |
1452 | else if (GET_CODE (XEXP (src, 0)) == REG |
1453 | && REGNO (XEXP (src, 0)) == cfa_temp.reg | |
1454 | && XEXP (src, 1) == stack_pointer_rtx) | |
b53ef1a2 | 1455 | { |
00a42e21 JM |
1456 | /* Setting a scratch register that we will use instead |
1457 | of SP for saving registers to the stack. */ | |
b53ef1a2 NC |
1458 | if (cfa.reg != STACK_POINTER_REGNUM) |
1459 | abort (); | |
1460 | cfa_store.reg = REGNO (dest); | |
770ca8c6 | 1461 | cfa_store.offset = cfa.offset - cfa_temp.offset; |
b53ef1a2 | 1462 | } |
2ad9852d | 1463 | |
19ec6a36 AM |
1464 | /* Rule 9 */ |
1465 | else if (GET_CODE (src) == LO_SUM | |
1466 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
1467 | { | |
1468 | cfa_temp.reg = REGNO (dest); | |
1469 | cfa_temp.offset = INTVAL (XEXP (src, 1)); | |
1470 | } | |
1471 | else | |
1472 | abort (); | |
556273e0 KH |
1473 | } |
1474 | break; | |
b664de3a | 1475 | |
770ca8c6 | 1476 | /* Rule 6 */ |
556273e0 | 1477 | case CONST_INT: |
770ca8c6 JO |
1478 | cfa_temp.reg = REGNO (dest); |
1479 | cfa_temp.offset = INTVAL (src); | |
556273e0 | 1480 | break; |
b664de3a | 1481 | |
770ca8c6 | 1482 | /* Rule 7 */ |
556273e0 KH |
1483 | case IOR: |
1484 | if (GET_CODE (XEXP (src, 0)) != REG | |
770ca8c6 | 1485 | || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg |
2618f955 | 1486 | || GET_CODE (XEXP (src, 1)) != CONST_INT) |
556273e0 | 1487 | abort (); |
2ad9852d | 1488 | |
770ca8c6 JO |
1489 | if ((unsigned) REGNO (dest) != cfa_temp.reg) |
1490 | cfa_temp.reg = REGNO (dest); | |
1491 | cfa_temp.offset |= INTVAL (XEXP (src, 1)); | |
556273e0 | 1492 | break; |
b664de3a | 1493 | |
9ae21d2a AM |
1494 | /* Skip over HIGH, assuming it will be followed by a LO_SUM, |
1495 | which will fill in all of the bits. */ | |
1496 | /* Rule 8 */ | |
1497 | case HIGH: | |
1498 | break; | |
1499 | ||
556273e0 KH |
1500 | default: |
1501 | abort (); | |
1502 | } | |
2ad9852d | 1503 | |
7d9d8943 | 1504 | def_cfa_1 (label, &cfa); |
2618f955 | 1505 | break; |
b664de3a | 1506 | |
2618f955 | 1507 | case MEM: |
2618f955 MM |
1508 | if (GET_CODE (src) != REG) |
1509 | abort (); | |
7d9d8943 | 1510 | |
7d9d8943 AM |
1511 | /* Saving a register to the stack. Make sure dest is relative to the |
1512 | CFA register. */ | |
2618f955 MM |
1513 | switch (GET_CODE (XEXP (dest, 0))) |
1514 | { | |
770ca8c6 | 1515 | /* Rule 10 */ |
2618f955 | 1516 | /* With a push. */ |
e2134eea JH |
1517 | case PRE_MODIFY: |
1518 | /* We can't handle variable size modifications. */ | |
1519 | if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT) | |
173bf5be | 1520 | abort (); |
e2134eea JH |
1521 | offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1)); |
1522 | ||
1523 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM | |
1524 | || cfa_store.reg != STACK_POINTER_REGNUM) | |
1525 | abort (); | |
2ad9852d | 1526 | |
e2134eea JH |
1527 | cfa_store.offset += offset; |
1528 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1529 | cfa.offset = cfa_store.offset; | |
1530 | ||
1531 | offset = -cfa_store.offset; | |
1532 | break; | |
2ad9852d | 1533 | |
770ca8c6 | 1534 | /* Rule 11 */ |
2618f955 MM |
1535 | case PRE_INC: |
1536 | case PRE_DEC: | |
1537 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1538 | if (GET_CODE (XEXP (dest, 0)) == PRE_INC) | |
1539 | offset = -offset; | |
b664de3a | 1540 | |
2618f955 | 1541 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM |
7d9d8943 | 1542 | || cfa_store.reg != STACK_POINTER_REGNUM) |
2618f955 | 1543 | abort (); |
2ad9852d | 1544 | |
7d9d8943 AM |
1545 | cfa_store.offset += offset; |
1546 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1547 | cfa.offset = cfa_store.offset; | |
b664de3a | 1548 | |
7d9d8943 | 1549 | offset = -cfa_store.offset; |
2618f955 | 1550 | break; |
b664de3a | 1551 | |
770ca8c6 | 1552 | /* Rule 12 */ |
2618f955 MM |
1553 | /* With an offset. */ |
1554 | case PLUS: | |
1555 | case MINUS: | |
19ec6a36 | 1556 | case LO_SUM: |
770ca8c6 JO |
1557 | if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT) |
1558 | abort (); | |
2618f955 MM |
1559 | offset = INTVAL (XEXP (XEXP (dest, 0), 1)); |
1560 | if (GET_CODE (XEXP (dest, 0)) == MINUS) | |
1561 | offset = -offset; | |
b664de3a | 1562 | |
19ec6a36 AM |
1563 | if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) |
1564 | offset -= cfa_store.offset; | |
1565 | else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) | |
1566 | offset -= cfa_temp.offset; | |
1567 | else | |
2618f955 | 1568 | abort (); |
2618f955 MM |
1569 | break; |
1570 | ||
770ca8c6 | 1571 | /* Rule 13 */ |
2618f955 MM |
1572 | /* Without an offset. */ |
1573 | case REG: | |
19ec6a36 AM |
1574 | if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0))) |
1575 | offset = -cfa_store.offset; | |
1576 | else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0))) | |
1577 | offset = -cfa_temp.offset; | |
1578 | else | |
556273e0 | 1579 | abort (); |
19ec6a36 AM |
1580 | break; |
1581 | ||
1582 | /* Rule 14 */ | |
1583 | case POST_INC: | |
1584 | if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) | |
1585 | abort (); | |
1586 | offset = -cfa_temp.offset; | |
1587 | cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest)); | |
2618f955 MM |
1588 | break; |
1589 | ||
1590 | default: | |
1591 | abort (); | |
1592 | } | |
e09bbb25 | 1593 | |
556273e0 | 1594 | if (REGNO (src) != STACK_POINTER_REGNUM |
e09bbb25 JM |
1595 | && REGNO (src) != HARD_FRAME_POINTER_REGNUM |
1596 | && (unsigned) REGNO (src) == cfa.reg) | |
1597 | { | |
1598 | /* We're storing the current CFA reg into the stack. */ | |
1599 | ||
1600 | if (cfa.offset == 0) | |
1601 | { | |
1602 | /* If the source register is exactly the CFA, assume | |
1603 | we're saving SP like any other register; this happens | |
1604 | on the ARM. */ | |
e09bbb25 | 1605 | def_cfa_1 (label, &cfa); |
fbfa55b0 | 1606 | queue_reg_save (label, stack_pointer_rtx, offset); |
e09bbb25 JM |
1607 | break; |
1608 | } | |
1609 | else | |
1610 | { | |
1611 | /* Otherwise, we'll need to look in the stack to | |
73c68f61 | 1612 | calculate the CFA. */ |
e09bbb25 | 1613 | rtx x = XEXP (dest, 0); |
2ad9852d | 1614 | |
e09bbb25 JM |
1615 | if (GET_CODE (x) != REG) |
1616 | x = XEXP (x, 0); | |
1617 | if (GET_CODE (x) != REG) | |
1618 | abort (); | |
2ad9852d RK |
1619 | |
1620 | cfa.reg = REGNO (x); | |
e09bbb25 JM |
1621 | cfa.base_offset = offset; |
1622 | cfa.indirect = 1; | |
1623 | def_cfa_1 (label, &cfa); | |
1624 | break; | |
1625 | } | |
1626 | } | |
1627 | ||
7d9d8943 | 1628 | def_cfa_1 (label, &cfa); |
fbfa55b0 | 1629 | queue_reg_save (label, src, offset); |
2618f955 MM |
1630 | break; |
1631 | ||
1632 | default: | |
1633 | abort (); | |
1634 | } | |
b664de3a AM |
1635 | } |
1636 | ||
3f76745e JM |
1637 | /* Record call frame debugging information for INSN, which either |
1638 | sets SP or FP (adjusting how we calculate the frame address) or saves a | |
1639 | register to the stack. If INSN is NULL_RTX, initialize our state. */ | |
71dfc51f | 1640 | |
3f76745e | 1641 | void |
7080f735 | 1642 | dwarf2out_frame_debug (rtx insn) |
a3f97cbb | 1643 | { |
d3e3972c | 1644 | const char *label; |
b664de3a | 1645 | rtx src; |
3f76745e JM |
1646 | |
1647 | if (insn == NULL_RTX) | |
a3f97cbb | 1648 | { |
fbfa55b0 RH |
1649 | /* Flush any queued register saves. */ |
1650 | flush_queued_reg_saves (); | |
1651 | ||
3f76745e | 1652 | /* Set up state for generating call frame debug info. */ |
7d9d8943 AM |
1653 | lookup_cfa (&cfa); |
1654 | if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)) | |
3a88cbd1 | 1655 | abort (); |
2ad9852d | 1656 | |
7d9d8943 AM |
1657 | cfa.reg = STACK_POINTER_REGNUM; |
1658 | cfa_store = cfa; | |
770ca8c6 JO |
1659 | cfa_temp.reg = -1; |
1660 | cfa_temp.offset = 0; | |
3f76745e JM |
1661 | return; |
1662 | } | |
1663 | ||
fbfa55b0 RH |
1664 | if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn)) |
1665 | flush_queued_reg_saves (); | |
1666 | ||
0021b564 JM |
1667 | if (! RTX_FRAME_RELATED_P (insn)) |
1668 | { | |
fbfa55b0 | 1669 | if (!ACCUMULATE_OUTGOING_ARGS) |
c26fbbca | 1670 | dwarf2out_stack_adjust (insn); |
2ad9852d | 1671 | |
0021b564 JM |
1672 | return; |
1673 | } | |
1674 | ||
3f76745e | 1675 | label = dwarf2out_cfi_label (); |
07ebc930 RH |
1676 | src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX); |
1677 | if (src) | |
1678 | insn = XEXP (src, 0); | |
556273e0 | 1679 | else |
07ebc930 RH |
1680 | insn = PATTERN (insn); |
1681 | ||
b664de3a | 1682 | dwarf2out_frame_debug_expr (insn, label); |
3f76745e JM |
1683 | } |
1684 | ||
17211ab5 GK |
1685 | #endif |
1686 | ||
1687 | /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */ | |
7080f735 AJ |
1688 | static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc |
1689 | (enum dwarf_call_frame_info cfi); | |
17211ab5 GK |
1690 | |
1691 | static enum dw_cfi_oprnd_type | |
7080f735 | 1692 | dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi) |
17211ab5 GK |
1693 | { |
1694 | switch (cfi) | |
1695 | { | |
1696 | case DW_CFA_nop: | |
1697 | case DW_CFA_GNU_window_save: | |
1698 | return dw_cfi_oprnd_unused; | |
1699 | ||
1700 | case DW_CFA_set_loc: | |
1701 | case DW_CFA_advance_loc1: | |
1702 | case DW_CFA_advance_loc2: | |
1703 | case DW_CFA_advance_loc4: | |
1704 | case DW_CFA_MIPS_advance_loc8: | |
1705 | return dw_cfi_oprnd_addr; | |
1706 | ||
1707 | case DW_CFA_offset: | |
1708 | case DW_CFA_offset_extended: | |
1709 | case DW_CFA_def_cfa: | |
1710 | case DW_CFA_offset_extended_sf: | |
1711 | case DW_CFA_def_cfa_sf: | |
1712 | case DW_CFA_restore_extended: | |
1713 | case DW_CFA_undefined: | |
1714 | case DW_CFA_same_value: | |
1715 | case DW_CFA_def_cfa_register: | |
1716 | case DW_CFA_register: | |
1717 | return dw_cfi_oprnd_reg_num; | |
1718 | ||
1719 | case DW_CFA_def_cfa_offset: | |
1720 | case DW_CFA_GNU_args_size: | |
1721 | case DW_CFA_def_cfa_offset_sf: | |
1722 | return dw_cfi_oprnd_offset; | |
7080f735 | 1723 | |
17211ab5 GK |
1724 | case DW_CFA_def_cfa_expression: |
1725 | case DW_CFA_expression: | |
1726 | return dw_cfi_oprnd_loc; | |
1727 | ||
1728 | default: | |
1729 | abort (); | |
1730 | } | |
1731 | } | |
1732 | ||
1733 | /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */ | |
7080f735 AJ |
1734 | static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc |
1735 | (enum dwarf_call_frame_info cfi); | |
17211ab5 GK |
1736 | |
1737 | static enum dw_cfi_oprnd_type | |
7080f735 | 1738 | dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi) |
17211ab5 GK |
1739 | { |
1740 | switch (cfi) | |
1741 | { | |
1742 | case DW_CFA_def_cfa: | |
1743 | case DW_CFA_def_cfa_sf: | |
1744 | case DW_CFA_offset: | |
1745 | case DW_CFA_offset_extended_sf: | |
1746 | case DW_CFA_offset_extended: | |
1747 | return dw_cfi_oprnd_offset; | |
1748 | ||
1749 | case DW_CFA_register: | |
1750 | return dw_cfi_oprnd_reg_num; | |
1751 | ||
1752 | default: | |
1753 | return dw_cfi_oprnd_unused; | |
1754 | } | |
1755 | } | |
1756 | ||
1757 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) | |
1758 | ||
3f76745e JM |
1759 | /* Output a Call Frame Information opcode and its operand(s). */ |
1760 | ||
1761 | static void | |
7080f735 | 1762 | output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh) |
3f76745e JM |
1763 | { |
1764 | if (cfi->dw_cfi_opc == DW_CFA_advance_loc) | |
2ad9852d RK |
1765 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1766 | | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)), | |
1767 | "DW_CFA_advance_loc 0x%lx", | |
1768 | cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
3f76745e JM |
1769 | else if (cfi->dw_cfi_opc == DW_CFA_offset) |
1770 | { | |
2e4b9b8c RH |
1771 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1772 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)), | |
1773 | "DW_CFA_offset, column 0x%lx", | |
1774 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1775 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); | |
3f76745e JM |
1776 | } |
1777 | else if (cfi->dw_cfi_opc == DW_CFA_restore) | |
2ad9852d RK |
1778 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1779 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)), | |
1780 | "DW_CFA_restore, column 0x%lx", | |
1781 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
3f76745e JM |
1782 | else |
1783 | { | |
2e4b9b8c RH |
1784 | dw2_asm_output_data (1, cfi->dw_cfi_opc, |
1785 | "%s", dwarf_cfi_name (cfi->dw_cfi_opc)); | |
3f76745e | 1786 | |
3f76745e JM |
1787 | switch (cfi->dw_cfi_opc) |
1788 | { | |
1789 | case DW_CFA_set_loc: | |
e1f9550a RH |
1790 | if (for_eh) |
1791 | dw2_asm_output_encoded_addr_rtx ( | |
1792 | ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0), | |
1793 | gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr), | |
1794 | NULL); | |
1795 | else | |
1796 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, | |
1797 | cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL); | |
3f76745e | 1798 | break; |
2ad9852d | 1799 | |
3f76745e | 1800 | case DW_CFA_advance_loc1: |
2e4b9b8c RH |
1801 | dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1802 | fde->dw_fde_current_label, NULL); | |
bb727b5a | 1803 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
3f76745e | 1804 | break; |
2ad9852d | 1805 | |
3f76745e | 1806 | case DW_CFA_advance_loc2: |
2e4b9b8c RH |
1807 | dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1808 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
1809 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
1810 | break; | |
2ad9852d | 1811 | |
3f76745e | 1812 | case DW_CFA_advance_loc4: |
2e4b9b8c RH |
1813 | dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1814 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
1815 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
1816 | break; | |
2ad9852d | 1817 | |
3f76745e | 1818 | case DW_CFA_MIPS_advance_loc8: |
2e4b9b8c RH |
1819 | dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1820 | fde->dw_fde_current_label, NULL); | |
1821 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
3f76745e | 1822 | break; |
2ad9852d | 1823 | |
3f76745e JM |
1824 | case DW_CFA_offset_extended: |
1825 | case DW_CFA_def_cfa: | |
2ad9852d RK |
1826 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, |
1827 | NULL); | |
2e4b9b8c | 1828 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); |
3f76745e | 1829 | break; |
2ad9852d | 1830 | |
6bb28965 JM |
1831 | case DW_CFA_offset_extended_sf: |
1832 | case DW_CFA_def_cfa_sf: | |
1833 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, | |
1834 | NULL); | |
1835 | dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); | |
1836 | break; | |
1837 | ||
3f76745e JM |
1838 | case DW_CFA_restore_extended: |
1839 | case DW_CFA_undefined: | |
3f76745e JM |
1840 | case DW_CFA_same_value: |
1841 | case DW_CFA_def_cfa_register: | |
2ad9852d RK |
1842 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, |
1843 | NULL); | |
3f76745e | 1844 | break; |
2ad9852d | 1845 | |
3f76745e | 1846 | case DW_CFA_register: |
2ad9852d RK |
1847 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, |
1848 | NULL); | |
1849 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, | |
1850 | NULL); | |
3f76745e | 1851 | break; |
2ad9852d | 1852 | |
3f76745e | 1853 | case DW_CFA_def_cfa_offset: |
2e4b9b8c RH |
1854 | case DW_CFA_GNU_args_size: |
1855 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL); | |
3f76745e | 1856 | break; |
2ad9852d | 1857 | |
6bb28965 JM |
1858 | case DW_CFA_def_cfa_offset_sf: |
1859 | dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL); | |
1860 | break; | |
1861 | ||
c53aa195 JM |
1862 | case DW_CFA_GNU_window_save: |
1863 | break; | |
2ad9852d | 1864 | |
7d9d8943 | 1865 | case DW_CFA_def_cfa_expression: |
6bb28965 | 1866 | case DW_CFA_expression: |
7d9d8943 AM |
1867 | output_cfa_loc (cfi); |
1868 | break; | |
2ad9852d | 1869 | |
6bb28965 JM |
1870 | case DW_CFA_GNU_negative_offset_extended: |
1871 | /* Obsoleted by DW_CFA_offset_extended_sf. */ | |
1872 | abort (); | |
1873 | ||
3f76745e JM |
1874 | default: |
1875 | break; | |
1876 | } | |
556273e0 | 1877 | } |
3f76745e JM |
1878 | } |
1879 | ||
1880 | /* Output the call frame information used to used to record information | |
1881 | that relates to calculating the frame pointer, and records the | |
1882 | location of saved registers. */ | |
1883 | ||
1884 | static void | |
7080f735 | 1885 | output_call_frame_info (int for_eh) |
3f76745e | 1886 | { |
b3694847 SS |
1887 | unsigned int i; |
1888 | dw_fde_ref fde; | |
1889 | dw_cfi_ref cfi; | |
27d95cbe | 1890 | char l1[20], l2[20], section_start_label[20]; |
ad5eeaa9 | 1891 | bool any_lsda_needed = false; |
52a11cbf | 1892 | char augmentation[6]; |
e1f9550a RH |
1893 | int augmentation_size; |
1894 | int fde_encoding = DW_EH_PE_absptr; | |
1895 | int per_encoding = DW_EH_PE_absptr; | |
1896 | int lsda_encoding = DW_EH_PE_absptr; | |
3f76745e | 1897 | |
29b91443 JM |
1898 | /* Don't emit a CIE if there won't be any FDEs. */ |
1899 | if (fde_table_in_use == 0) | |
1900 | return; | |
1901 | ||
ad5eeaa9 RH |
1902 | /* If we don't have any functions we'll want to unwind out of, don't |
1903 | emit any EH unwind information. Note that if exceptions aren't | |
1904 | enabled, we won't have collected nothrow information, and if we | |
1905 | asked for asynchronous tables, we always want this info. */ | |
737faf14 JM |
1906 | if (for_eh) |
1907 | { | |
ad5eeaa9 | 1908 | bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables; |
2ad9852d RK |
1909 | |
1910 | for (i = 0; i < fde_table_in_use; i++) | |
52a11cbf | 1911 | if (fde_table[i].uses_eh_lsda) |
ad5eeaa9 | 1912 | any_eh_needed = any_lsda_needed = true; |
0366359a GK |
1913 | else if (! fde_table[i].nothrow |
1914 | && ! fde_table[i].all_throwers_are_sibcalls) | |
ad5eeaa9 | 1915 | any_eh_needed = true; |
52a11cbf RH |
1916 | |
1917 | if (! any_eh_needed) | |
1918 | return; | |
737faf14 JM |
1919 | } |
1920 | ||
aa0c1401 JL |
1921 | /* We're going to be generating comments, so turn on app. */ |
1922 | if (flag_debug_asm) | |
1923 | app_enable (); | |
956d6950 | 1924 | |
3f76745e | 1925 | if (for_eh) |
07c9d2eb | 1926 | (*targetm.asm_out.eh_frame_section) (); |
3f76745e | 1927 | else |
715bdd29 | 1928 | named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG); |
3f76745e | 1929 | |
27d95cbe RH |
1930 | ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh); |
1931 | ASM_OUTPUT_LABEL (asm_out_file, section_start_label); | |
1932 | ||
556273e0 | 1933 | /* Output the CIE. */ |
a6ab3aad JM |
1934 | ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh); |
1935 | ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh); | |
2e4b9b8c RH |
1936 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
1937 | "Length of Common Information Entry"); | |
a6ab3aad JM |
1938 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1939 | ||
2e4b9b8c RH |
1940 | /* Now that the CIE pointer is PC-relative for EH, |
1941 | use 0 to identify the CIE. */ | |
1942 | dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE), | |
1943 | (for_eh ? 0 : DW_CIE_ID), | |
1944 | "CIE Identifier Tag"); | |
3f76745e | 1945 | |
2e4b9b8c | 1946 | dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version"); |
3f76745e | 1947 | |
52a11cbf | 1948 | augmentation[0] = 0; |
e1f9550a | 1949 | augmentation_size = 0; |
52a11cbf | 1950 | if (for_eh) |
a6ab3aad | 1951 | { |
e1f9550a RH |
1952 | char *p; |
1953 | ||
52a11cbf RH |
1954 | /* Augmentation: |
1955 | z Indicates that a uleb128 is present to size the | |
7080f735 | 1956 | augmentation section. |
e1f9550a RH |
1957 | L Indicates the encoding (and thus presence) of |
1958 | an LSDA pointer in the FDE augmentation. | |
1959 | R Indicates a non-default pointer encoding for | |
1960 | FDE code pointers. | |
1961 | P Indicates the presence of an encoding + language | |
1962 | personality routine in the CIE augmentation. */ | |
1963 | ||
1964 | fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0); | |
1965 | per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1); | |
1966 | lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0); | |
1967 | ||
1968 | p = augmentation + 1; | |
1969 | if (eh_personality_libfunc) | |
1970 | { | |
1971 | *p++ = 'P'; | |
1972 | augmentation_size += 1 + size_of_encoded_value (per_encoding); | |
1973 | } | |
52a11cbf | 1974 | if (any_lsda_needed) |
e1f9550a RH |
1975 | { |
1976 | *p++ = 'L'; | |
1977 | augmentation_size += 1; | |
1978 | } | |
1979 | if (fde_encoding != DW_EH_PE_absptr) | |
1980 | { | |
1981 | *p++ = 'R'; | |
1982 | augmentation_size += 1; | |
1983 | } | |
1984 | if (p > augmentation + 1) | |
1985 | { | |
1986 | augmentation[0] = 'z'; | |
c26fbbca | 1987 | *p = '\0'; |
e1f9550a | 1988 | } |
099c8b17 RH |
1989 | |
1990 | /* Ug. Some platforms can't do unaligned dynamic relocations at all. */ | |
1991 | if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned) | |
1992 | { | |
1993 | int offset = ( 4 /* Length */ | |
1994 | + 4 /* CIE Id */ | |
1995 | + 1 /* CIE version */ | |
1996 | + strlen (augmentation) + 1 /* Augmentation */ | |
1997 | + size_of_uleb128 (1) /* Code alignment */ | |
1998 | + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT) | |
1999 | + 1 /* RA column */ | |
2000 | + 1 /* Augmentation size */ | |
2001 | + 1 /* Personality encoding */ ); | |
2002 | int pad = -offset & (PTR_SIZE - 1); | |
2003 | ||
2004 | augmentation_size += pad; | |
2005 | ||
2006 | /* Augmentations should be small, so there's scarce need to | |
2007 | iterate for a solution. Die if we exceed one uleb128 byte. */ | |
2008 | if (size_of_uleb128 (augmentation_size) != 1) | |
2009 | abort (); | |
2010 | } | |
a6ab3aad | 2011 | } |
3f76745e | 2012 | |
2ad9852d | 2013 | dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation"); |
2e4b9b8c | 2014 | dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor"); |
2e4b9b8c RH |
2015 | dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT, |
2016 | "CIE Data Alignment Factor"); | |
2e4b9b8c | 2017 | dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column"); |
3f76745e | 2018 | |
52a11cbf RH |
2019 | if (augmentation[0]) |
2020 | { | |
e1f9550a | 2021 | dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size"); |
52a11cbf | 2022 | if (eh_personality_libfunc) |
e1f9550a RH |
2023 | { |
2024 | dw2_asm_output_data (1, per_encoding, "Personality (%s)", | |
2025 | eh_data_format_name (per_encoding)); | |
2026 | dw2_asm_output_encoded_addr_rtx (per_encoding, | |
2027 | eh_personality_libfunc, NULL); | |
2028 | } | |
2ad9852d | 2029 | |
e1f9550a RH |
2030 | if (any_lsda_needed) |
2031 | dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)", | |
2032 | eh_data_format_name (lsda_encoding)); | |
2ad9852d | 2033 | |
e1f9550a RH |
2034 | if (fde_encoding != DW_EH_PE_absptr) |
2035 | dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)", | |
2036 | eh_data_format_name (fde_encoding)); | |
52a11cbf RH |
2037 | } |
2038 | ||
3f76745e | 2039 | for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next) |
12f0b96b | 2040 | output_cfi (cfi, NULL, for_eh); |
3f76745e JM |
2041 | |
2042 | /* Pad the CIE out to an address sized boundary. */ | |
c26fbbca | 2043 | ASM_OUTPUT_ALIGN (asm_out_file, |
12f0b96b | 2044 | floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)); |
a6ab3aad | 2045 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e JM |
2046 | |
2047 | /* Loop through all of the FDE's. */ | |
2ad9852d | 2048 | for (i = 0; i < fde_table_in_use; i++) |
3f76745e JM |
2049 | { |
2050 | fde = &fde_table[i]; | |
3f76745e | 2051 | |
52a11cbf | 2052 | /* Don't emit EH unwind info for leaf functions that don't need it. */ |
ad5eeaa9 | 2053 | if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions |
b6128b8c SH |
2054 | && (fde->nothrow || fde->all_throwers_are_sibcalls) |
2055 | && !fde->uses_eh_lsda) | |
737faf14 JM |
2056 | continue; |
2057 | ||
4977bab6 | 2058 | (*targetm.asm_out.internal_label) (asm_out_file, FDE_LABEL, for_eh + i * 2); |
556273e0 KH |
2059 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2); |
2060 | ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2); | |
2e4b9b8c RH |
2061 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
2062 | "FDE Length"); | |
a6ab3aad JM |
2063 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
2064 | ||
3f76745e | 2065 | if (for_eh) |
27d95cbe | 2066 | dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset"); |
3f76745e | 2067 | else |
27d95cbe | 2068 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label, |
2e4b9b8c | 2069 | "FDE CIE offset"); |
3f76745e | 2070 | |
e1f9550a RH |
2071 | if (for_eh) |
2072 | { | |
2073 | dw2_asm_output_encoded_addr_rtx (fde_encoding, | |
2074 | gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin), | |
2075 | "FDE initial location"); | |
2076 | dw2_asm_output_delta (size_of_encoded_value (fde_encoding), | |
c26fbbca | 2077 | fde->dw_fde_end, fde->dw_fde_begin, |
e1f9550a RH |
2078 | "FDE address range"); |
2079 | } | |
2080 | else | |
2081 | { | |
2082 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin, | |
2083 | "FDE initial location"); | |
c26fbbca KH |
2084 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, |
2085 | fde->dw_fde_end, fde->dw_fde_begin, | |
e1f9550a RH |
2086 | "FDE address range"); |
2087 | } | |
3f76745e | 2088 | |
52a11cbf RH |
2089 | if (augmentation[0]) |
2090 | { | |
e1f9550a | 2091 | if (any_lsda_needed) |
52a11cbf | 2092 | { |
099c8b17 RH |
2093 | int size = size_of_encoded_value (lsda_encoding); |
2094 | ||
2095 | if (lsda_encoding == DW_EH_PE_aligned) | |
2096 | { | |
2097 | int offset = ( 4 /* Length */ | |
2098 | + 4 /* CIE offset */ | |
2099 | + 2 * size_of_encoded_value (fde_encoding) | |
2100 | + 1 /* Augmentation size */ ); | |
2101 | int pad = -offset & (PTR_SIZE - 1); | |
2102 | ||
2103 | size += pad; | |
2104 | if (size_of_uleb128 (size) != 1) | |
2105 | abort (); | |
2106 | } | |
2107 | ||
2108 | dw2_asm_output_data_uleb128 (size, "Augmentation size"); | |
e1f9550a RH |
2109 | |
2110 | if (fde->uses_eh_lsda) | |
73c68f61 SS |
2111 | { |
2112 | ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA", | |
e1f9550a | 2113 | fde->funcdef_number); |
73c68f61 | 2114 | dw2_asm_output_encoded_addr_rtx ( |
e1f9550a | 2115 | lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1), |
7080f735 | 2116 | "Language Specific Data Area"); |
73c68f61 | 2117 | } |
e1f9550a | 2118 | else |
099c8b17 RH |
2119 | { |
2120 | if (lsda_encoding == DW_EH_PE_aligned) | |
2121 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); | |
2ad9852d RK |
2122 | dw2_asm_output_data |
2123 | (size_of_encoded_value (lsda_encoding), 0, | |
2124 | "Language Specific Data Area (none)"); | |
099c8b17 | 2125 | } |
52a11cbf RH |
2126 | } |
2127 | else | |
e1f9550a | 2128 | dw2_asm_output_data_uleb128 (0, "Augmentation size"); |
52a11cbf RH |
2129 | } |
2130 | ||
3f76745e JM |
2131 | /* Loop through the Call Frame Instructions associated with |
2132 | this FDE. */ | |
2133 | fde->dw_fde_current_label = fde->dw_fde_begin; | |
2134 | for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next) | |
12f0b96b | 2135 | output_cfi (cfi, fde, for_eh); |
3f76745e | 2136 | |
a6ab3aad | 2137 | /* Pad the FDE out to an address sized boundary. */ |
c26fbbca | 2138 | ASM_OUTPUT_ALIGN (asm_out_file, |
73c68f61 | 2139 | floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE))); |
a6ab3aad | 2140 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e | 2141 | } |
2e4b9b8c | 2142 | |
7606e68f | 2143 | if (for_eh && targetm.terminate_dw2_eh_frame_info) |
2e4b9b8c | 2144 | dw2_asm_output_data (4, 0, "End of Table"); |
a6ab3aad JM |
2145 | #ifdef MIPS_DEBUGGING_INFO |
2146 | /* Work around Irix 6 assembler bug whereby labels at the end of a section | |
2147 | get a value of 0. Putting .align 0 after the label fixes it. */ | |
2148 | ASM_OUTPUT_ALIGN (asm_out_file, 0); | |
2149 | #endif | |
aa0c1401 JL |
2150 | |
2151 | /* Turn off app to make assembly quicker. */ | |
2152 | if (flag_debug_asm) | |
2153 | app_disable (); | |
a6ab3aad JM |
2154 | } |
2155 | ||
3f76745e JM |
2156 | /* Output a marker (i.e. a label) for the beginning of a function, before |
2157 | the prologue. */ | |
2158 | ||
2159 | void | |
7080f735 AJ |
2160 | dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED, |
2161 | const char *file ATTRIBUTE_UNUSED) | |
3f76745e JM |
2162 | { |
2163 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 | 2164 | dw_fde_ref fde; |
3f76745e | 2165 | |
2a1ee410 RH |
2166 | current_function_func_begin_label = 0; |
2167 | ||
2168 | #ifdef IA64_UNWIND_INFO | |
2169 | /* ??? current_function_func_begin_label is also used by except.c | |
2170 | for call-site information. We must emit this label if it might | |
2171 | be used. */ | |
2172 | if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS) | |
2173 | && ! dwarf2out_do_frame ()) | |
2174 | return; | |
2175 | #else | |
2176 | if (! dwarf2out_do_frame ()) | |
2177 | return; | |
2178 | #endif | |
2179 | ||
3f76745e JM |
2180 | function_section (current_function_decl); |
2181 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL, | |
df696a75 | 2182 | current_function_funcdef_no); |
2a1ee410 | 2183 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL, |
df696a75 | 2184 | current_function_funcdef_no); |
00262c8a | 2185 | current_function_func_begin_label = get_identifier (label); |
3f76745e | 2186 | |
2a1ee410 RH |
2187 | #ifdef IA64_UNWIND_INFO |
2188 | /* We can elide the fde allocation if we're not emitting debug info. */ | |
2189 | if (! dwarf2out_do_frame ()) | |
2190 | return; | |
2191 | #endif | |
2192 | ||
3f76745e JM |
2193 | /* Expand the fde table if necessary. */ |
2194 | if (fde_table_in_use == fde_table_allocated) | |
2195 | { | |
2196 | fde_table_allocated += FDE_TABLE_INCREMENT; | |
17211ab5 GK |
2197 | fde_table = ggc_realloc (fde_table, |
2198 | fde_table_allocated * sizeof (dw_fde_node)); | |
2199 | memset (fde_table + fde_table_in_use, 0, | |
2200 | FDE_TABLE_INCREMENT * sizeof (dw_fde_node)); | |
a3f97cbb | 2201 | } |
3f76745e JM |
2202 | |
2203 | /* Record the FDE associated with this function. */ | |
2204 | current_funcdef_fde = fde_table_in_use; | |
2205 | ||
2206 | /* Add the new FDE at the end of the fde_table. */ | |
2207 | fde = &fde_table[fde_table_in_use++]; | |
2208 | fde->dw_fde_begin = xstrdup (label); | |
2209 | fde->dw_fde_current_label = NULL; | |
2210 | fde->dw_fde_end = NULL; | |
2211 | fde->dw_fde_cfi = NULL; | |
df696a75 | 2212 | fde->funcdef_number = current_function_funcdef_no; |
fb13d4d0 | 2213 | fde->nothrow = current_function_nothrow; |
52a11cbf | 2214 | fde->uses_eh_lsda = cfun->uses_eh_lsda; |
b6128b8c | 2215 | fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls; |
737faf14 | 2216 | |
b57d9225 | 2217 | args_size = old_args_size = 0; |
653e276c | 2218 | |
2ad9852d RK |
2219 | /* We only want to output line number information for the genuine dwarf2 |
2220 | prologue case, not the eh frame case. */ | |
653e276c NB |
2221 | #ifdef DWARF2_DEBUGGING_INFO |
2222 | if (file) | |
2223 | dwarf2out_source_line (line, file); | |
2224 | #endif | |
3f76745e JM |
2225 | } |
2226 | ||
2227 | /* Output a marker (i.e. a label) for the absolute end of the generated code | |
2228 | for a function definition. This gets called *after* the epilogue code has | |
2229 | been generated. */ | |
2230 | ||
2231 | void | |
7080f735 AJ |
2232 | dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED, |
2233 | const char *file ATTRIBUTE_UNUSED) | |
3f76745e JM |
2234 | { |
2235 | dw_fde_ref fde; | |
2236 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2237 | ||
2238 | /* Output a label to mark the endpoint of the code generated for this | |
3ef42a0c | 2239 | function. */ |
df696a75 RH |
2240 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, |
2241 | current_function_funcdef_no); | |
3f76745e JM |
2242 | ASM_OUTPUT_LABEL (asm_out_file, label); |
2243 | fde = &fde_table[fde_table_in_use - 1]; | |
2244 | fde->dw_fde_end = xstrdup (label); | |
3f76745e JM |
2245 | } |
2246 | ||
2247 | void | |
7080f735 | 2248 | dwarf2out_frame_init (void) |
3f76745e JM |
2249 | { |
2250 | /* Allocate the initial hunk of the fde_table. */ | |
703ad42b | 2251 | fde_table = ggc_alloc_cleared (FDE_TABLE_INCREMENT * sizeof (dw_fde_node)); |
3f76745e JM |
2252 | fde_table_allocated = FDE_TABLE_INCREMENT; |
2253 | fde_table_in_use = 0; | |
2254 | ||
2255 | /* Generate the CFA instructions common to all FDE's. Do it now for the | |
2256 | sake of lookup_cfa. */ | |
2257 | ||
a6ab3aad | 2258 | #ifdef DWARF2_UNWIND_INFO |
91193900 AS |
2259 | /* On entry, the Canonical Frame Address is at SP. */ |
2260 | dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET); | |
2261 | initial_return_save (INCOMING_RETURN_ADDR_RTX); | |
3f76745e JM |
2262 | #endif |
2263 | } | |
2264 | ||
2265 | void | |
7080f735 | 2266 | dwarf2out_frame_finish (void) |
3f76745e | 2267 | { |
3f76745e | 2268 | /* Output call frame information. */ |
7a0c8d71 | 2269 | if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG) |
3f76745e | 2270 | output_call_frame_info (0); |
2ad9852d | 2271 | |
ddee9e8d | 2272 | if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions)) |
3f76745e | 2273 | output_call_frame_info (1); |
556273e0 | 2274 | } |
17211ab5 | 2275 | #endif |
7d9d8943 AM |
2276 | \f |
2277 | /* And now, the subset of the debugging information support code necessary | |
2278 | for emitting location expressions. */ | |
3f76745e | 2279 | |
b9203463 RH |
2280 | /* We need some way to distinguish DW_OP_addr with a direct symbol |
2281 | relocation from DW_OP_addr with a dtp-relative symbol relocation. */ | |
2282 | #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr) | |
2283 | ||
2284 | ||
7d9d8943 AM |
2285 | typedef struct dw_val_struct *dw_val_ref; |
2286 | typedef struct die_struct *dw_die_ref; | |
2287 | typedef struct dw_loc_descr_struct *dw_loc_descr_ref; | |
63e46568 | 2288 | typedef struct dw_loc_list_struct *dw_loc_list_ref; |
3f76745e JM |
2289 | |
2290 | /* Each DIE may have a series of attribute/value pairs. Values | |
2291 | can take on several forms. The forms that are used in this | |
2292 | implementation are listed below. */ | |
2293 | ||
17211ab5 | 2294 | enum dw_val_class |
3f76745e JM |
2295 | { |
2296 | dw_val_class_addr, | |
a20612aa | 2297 | dw_val_class_offset, |
3f76745e | 2298 | dw_val_class_loc, |
63e46568 | 2299 | dw_val_class_loc_list, |
2bee6045 | 2300 | dw_val_class_range_list, |
3f76745e JM |
2301 | dw_val_class_const, |
2302 | dw_val_class_unsigned_const, | |
2303 | dw_val_class_long_long, | |
2304 | dw_val_class_float, | |
2305 | dw_val_class_flag, | |
2306 | dw_val_class_die_ref, | |
2307 | dw_val_class_fde_ref, | |
2308 | dw_val_class_lbl_id, | |
8b790721 | 2309 | dw_val_class_lbl_offset, |
3f76745e | 2310 | dw_val_class_str |
17211ab5 | 2311 | }; |
a3f97cbb | 2312 | |
3f76745e | 2313 | /* Describe a double word constant value. */ |
21217bd0 | 2314 | /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */ |
3f76745e | 2315 | |
17211ab5 | 2316 | typedef struct dw_long_long_struct GTY(()) |
a3f97cbb | 2317 | { |
3f76745e JM |
2318 | unsigned long hi; |
2319 | unsigned long low; | |
2320 | } | |
2321 | dw_long_long_const; | |
2322 | ||
2323 | /* Describe a floating point constant value. */ | |
2324 | ||
17211ab5 | 2325 | typedef struct dw_fp_struct GTY(()) |
3f76745e | 2326 | { |
17211ab5 | 2327 | long * GTY((length ("%h.length"))) array; |
3f76745e JM |
2328 | unsigned length; |
2329 | } | |
2330 | dw_float_const; | |
2331 | ||
956d6950 | 2332 | /* The dw_val_node describes an attribute's value, as it is |
3f76745e JM |
2333 | represented internally. */ |
2334 | ||
17211ab5 | 2335 | typedef struct dw_val_struct GTY(()) |
3f76745e | 2336 | { |
17211ab5 GK |
2337 | enum dw_val_class val_class; |
2338 | union dw_val_struct_union | |
a3f97cbb | 2339 | { |
17211ab5 GK |
2340 | rtx GTY ((tag ("dw_val_class_addr"))) val_addr; |
2341 | long unsigned GTY ((tag ("dw_val_class_offset"))) val_offset; | |
2342 | dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list; | |
2343 | dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc; | |
2344 | long int GTY ((default (""))) val_int; | |
2345 | long unsigned GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned; | |
2346 | dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long; | |
2347 | dw_float_const GTY ((tag ("dw_val_class_float"))) val_float; | |
2348 | struct dw_val_die_union | |
2ad9852d RK |
2349 | { |
2350 | dw_die_ref die; | |
2351 | int external; | |
17211ab5 GK |
2352 | } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref; |
2353 | unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index; | |
2354 | struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str; | |
2355 | char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id; | |
2356 | unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag; | |
a3f97cbb | 2357 | } |
17211ab5 | 2358 | GTY ((desc ("%1.val_class"))) v; |
3f76745e JM |
2359 | } |
2360 | dw_val_node; | |
2361 | ||
2362 | /* Locations in memory are described using a sequence of stack machine | |
2363 | operations. */ | |
2364 | ||
17211ab5 | 2365 | typedef struct dw_loc_descr_struct GTY(()) |
3f76745e JM |
2366 | { |
2367 | dw_loc_descr_ref dw_loc_next; | |
2368 | enum dwarf_location_atom dw_loc_opc; | |
2369 | dw_val_node dw_loc_oprnd1; | |
2370 | dw_val_node dw_loc_oprnd2; | |
d8041cc8 | 2371 | int dw_loc_addr; |
3f76745e JM |
2372 | } |
2373 | dw_loc_descr_node; | |
2374 | ||
63e46568 DB |
2375 | /* Location lists are ranges + location descriptions for that range, |
2376 | so you can track variables that are in different places over | |
30f7a378 | 2377 | their entire life. */ |
17211ab5 | 2378 | typedef struct dw_loc_list_struct GTY(()) |
63e46568 DB |
2379 | { |
2380 | dw_loc_list_ref dw_loc_next; | |
2381 | const char *begin; /* Label for begin address of range */ | |
2382 | const char *end; /* Label for end address of range */ | |
2ad9852d RK |
2383 | char *ll_symbol; /* Label for beginning of location list. |
2384 | Only on head of list */ | |
63e46568 DB |
2385 | const char *section; /* Section this loclist is relative to */ |
2386 | dw_loc_descr_ref expr; | |
2387 | } dw_loc_list_node; | |
2388 | ||
17211ab5 GK |
2389 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) |
2390 | ||
7080f735 AJ |
2391 | static const char *dwarf_stack_op_name (unsigned); |
2392 | static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom, | |
2393 | unsigned long, unsigned long); | |
2394 | static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref); | |
2395 | static unsigned long size_of_loc_descr (dw_loc_descr_ref); | |
2396 | static unsigned long size_of_locs (dw_loc_descr_ref); | |
2397 | static void output_loc_operands (dw_loc_descr_ref); | |
2398 | static void output_loc_sequence (dw_loc_descr_ref); | |
3f76745e | 2399 | |
7d9d8943 | 2400 | /* Convert a DWARF stack opcode into its string name. */ |
3f76745e | 2401 | |
7d9d8943 | 2402 | static const char * |
7080f735 | 2403 | dwarf_stack_op_name (unsigned int op) |
ef76d03b | 2404 | { |
7d9d8943 AM |
2405 | switch (op) |
2406 | { | |
2407 | case DW_OP_addr: | |
b9203463 | 2408 | case INTERNAL_DW_OP_tls_addr: |
7d9d8943 AM |
2409 | return "DW_OP_addr"; |
2410 | case DW_OP_deref: | |
2411 | return "DW_OP_deref"; | |
2412 | case DW_OP_const1u: | |
2413 | return "DW_OP_const1u"; | |
2414 | case DW_OP_const1s: | |
2415 | return "DW_OP_const1s"; | |
2416 | case DW_OP_const2u: | |
2417 | return "DW_OP_const2u"; | |
2418 | case DW_OP_const2s: | |
2419 | return "DW_OP_const2s"; | |
2420 | case DW_OP_const4u: | |
2421 | return "DW_OP_const4u"; | |
2422 | case DW_OP_const4s: | |
2423 | return "DW_OP_const4s"; | |
2424 | case DW_OP_const8u: | |
2425 | return "DW_OP_const8u"; | |
2426 | case DW_OP_const8s: | |
2427 | return "DW_OP_const8s"; | |
2428 | case DW_OP_constu: | |
2429 | return "DW_OP_constu"; | |
2430 | case DW_OP_consts: | |
2431 | return "DW_OP_consts"; | |
2432 | case DW_OP_dup: | |
2433 | return "DW_OP_dup"; | |
2434 | case DW_OP_drop: | |
2435 | return "DW_OP_drop"; | |
2436 | case DW_OP_over: | |
2437 | return "DW_OP_over"; | |
2438 | case DW_OP_pick: | |
2439 | return "DW_OP_pick"; | |
2440 | case DW_OP_swap: | |
2441 | return "DW_OP_swap"; | |
2442 | case DW_OP_rot: | |
2443 | return "DW_OP_rot"; | |
2444 | case DW_OP_xderef: | |
2445 | return "DW_OP_xderef"; | |
2446 | case DW_OP_abs: | |
2447 | return "DW_OP_abs"; | |
2448 | case DW_OP_and: | |
2449 | return "DW_OP_and"; | |
2450 | case DW_OP_div: | |
2451 | return "DW_OP_div"; | |
2452 | case DW_OP_minus: | |
2453 | return "DW_OP_minus"; | |
2454 | case DW_OP_mod: | |
2455 | return "DW_OP_mod"; | |
2456 | case DW_OP_mul: | |
2457 | return "DW_OP_mul"; | |
2458 | case DW_OP_neg: | |
2459 | return "DW_OP_neg"; | |
2460 | case DW_OP_not: | |
2461 | return "DW_OP_not"; | |
2462 | case DW_OP_or: | |
2463 | return "DW_OP_or"; | |
2464 | case DW_OP_plus: | |
2465 | return "DW_OP_plus"; | |
2466 | case DW_OP_plus_uconst: | |
2467 | return "DW_OP_plus_uconst"; | |
2468 | case DW_OP_shl: | |
2469 | return "DW_OP_shl"; | |
2470 | case DW_OP_shr: | |
2471 | return "DW_OP_shr"; | |
2472 | case DW_OP_shra: | |
2473 | return "DW_OP_shra"; | |
2474 | case DW_OP_xor: | |
2475 | return "DW_OP_xor"; | |
2476 | case DW_OP_bra: | |
2477 | return "DW_OP_bra"; | |
2478 | case DW_OP_eq: | |
2479 | return "DW_OP_eq"; | |
2480 | case DW_OP_ge: | |
2481 | return "DW_OP_ge"; | |
2482 | case DW_OP_gt: | |
2483 | return "DW_OP_gt"; | |
2484 | case DW_OP_le: | |
2485 | return "DW_OP_le"; | |
2486 | case DW_OP_lt: | |
2487 | return "DW_OP_lt"; | |
2488 | case DW_OP_ne: | |
2489 | return "DW_OP_ne"; | |
2490 | case DW_OP_skip: | |
2491 | return "DW_OP_skip"; | |
2492 | case DW_OP_lit0: | |
2493 | return "DW_OP_lit0"; | |
2494 | case DW_OP_lit1: | |
2495 | return "DW_OP_lit1"; | |
2496 | case DW_OP_lit2: | |
2497 | return "DW_OP_lit2"; | |
2498 | case DW_OP_lit3: | |
2499 | return "DW_OP_lit3"; | |
2500 | case DW_OP_lit4: | |
2501 | return "DW_OP_lit4"; | |
2502 | case DW_OP_lit5: | |
2503 | return "DW_OP_lit5"; | |
2504 | case DW_OP_lit6: | |
2505 | return "DW_OP_lit6"; | |
2506 | case DW_OP_lit7: | |
2507 | return "DW_OP_lit7"; | |
2508 | case DW_OP_lit8: | |
2509 | return "DW_OP_lit8"; | |
2510 | case DW_OP_lit9: | |
2511 | return "DW_OP_lit9"; | |
2512 | case DW_OP_lit10: | |
2513 | return "DW_OP_lit10"; | |
2514 | case DW_OP_lit11: | |
2515 | return "DW_OP_lit11"; | |
2516 | case DW_OP_lit12: | |
2517 | return "DW_OP_lit12"; | |
2518 | case DW_OP_lit13: | |
2519 | return "DW_OP_lit13"; | |
2520 | case DW_OP_lit14: | |
2521 | return "DW_OP_lit14"; | |
2522 | case DW_OP_lit15: | |
2523 | return "DW_OP_lit15"; | |
2524 | case DW_OP_lit16: | |
2525 | return "DW_OP_lit16"; | |
2526 | case DW_OP_lit17: | |
2527 | return "DW_OP_lit17"; | |
2528 | case DW_OP_lit18: | |
2529 | return "DW_OP_lit18"; | |
2530 | case DW_OP_lit19: | |
2531 | return "DW_OP_lit19"; | |
2532 | case DW_OP_lit20: | |
2533 | return "DW_OP_lit20"; | |
2534 | case DW_OP_lit21: | |
2535 | return "DW_OP_lit21"; | |
2536 | case DW_OP_lit22: | |
2537 | return "DW_OP_lit22"; | |
2538 | case DW_OP_lit23: | |
2539 | return "DW_OP_lit23"; | |
2540 | case DW_OP_lit24: | |
2541 | return "DW_OP_lit24"; | |
2542 | case DW_OP_lit25: | |
2543 | return "DW_OP_lit25"; | |
2544 | case DW_OP_lit26: | |
2545 | return "DW_OP_lit26"; | |
2546 | case DW_OP_lit27: | |
2547 | return "DW_OP_lit27"; | |
2548 | case DW_OP_lit28: | |
2549 | return "DW_OP_lit28"; | |
2550 | case DW_OP_lit29: | |
2551 | return "DW_OP_lit29"; | |
2552 | case DW_OP_lit30: | |
2553 | return "DW_OP_lit30"; | |
2554 | case DW_OP_lit31: | |
2555 | return "DW_OP_lit31"; | |
2556 | case DW_OP_reg0: | |
2557 | return "DW_OP_reg0"; | |
2558 | case DW_OP_reg1: | |
2559 | return "DW_OP_reg1"; | |
2560 | case DW_OP_reg2: | |
2561 | return "DW_OP_reg2"; | |
2562 | case DW_OP_reg3: | |
2563 | return "DW_OP_reg3"; | |
2564 | case DW_OP_reg4: | |
2565 | return "DW_OP_reg4"; | |
2566 | case DW_OP_reg5: | |
2567 | return "DW_OP_reg5"; | |
2568 | case DW_OP_reg6: | |
2569 | return "DW_OP_reg6"; | |
2570 | case DW_OP_reg7: | |
2571 | return "DW_OP_reg7"; | |
2572 | case DW_OP_reg8: | |
2573 | return "DW_OP_reg8"; | |
2574 | case DW_OP_reg9: | |
2575 | return "DW_OP_reg9"; | |
2576 | case DW_OP_reg10: | |
2577 | return "DW_OP_reg10"; | |
2578 | case DW_OP_reg11: | |
2579 | return "DW_OP_reg11"; | |
2580 | case DW_OP_reg12: | |
2581 | return "DW_OP_reg12"; | |
2582 | case DW_OP_reg13: | |
2583 | return "DW_OP_reg13"; | |
2584 | case DW_OP_reg14: | |
2585 | return "DW_OP_reg14"; | |
2586 | case DW_OP_reg15: | |
2587 | return "DW_OP_reg15"; | |
2588 | case DW_OP_reg16: | |
2589 | return "DW_OP_reg16"; | |
2590 | case DW_OP_reg17: | |
2591 | return "DW_OP_reg17"; | |
2592 | case DW_OP_reg18: | |
2593 | return "DW_OP_reg18"; | |
2594 | case DW_OP_reg19: | |
2595 | return "DW_OP_reg19"; | |
2596 | case DW_OP_reg20: | |
2597 | return "DW_OP_reg20"; | |
2598 | case DW_OP_reg21: | |
2599 | return "DW_OP_reg21"; | |
2600 | case DW_OP_reg22: | |
2601 | return "DW_OP_reg22"; | |
2602 | case DW_OP_reg23: | |
2603 | return "DW_OP_reg23"; | |
2604 | case DW_OP_reg24: | |
2605 | return "DW_OP_reg24"; | |
2606 | case DW_OP_reg25: | |
2607 | return "DW_OP_reg25"; | |
2608 | case DW_OP_reg26: | |
2609 | return "DW_OP_reg26"; | |
2610 | case DW_OP_reg27: | |
2611 | return "DW_OP_reg27"; | |
2612 | case DW_OP_reg28: | |
2613 | return "DW_OP_reg28"; | |
2614 | case DW_OP_reg29: | |
2615 | return "DW_OP_reg29"; | |
2616 | case DW_OP_reg30: | |
2617 | return "DW_OP_reg30"; | |
2618 | case DW_OP_reg31: | |
2619 | return "DW_OP_reg31"; | |
2620 | case DW_OP_breg0: | |
2621 | return "DW_OP_breg0"; | |
2622 | case DW_OP_breg1: | |
2623 | return "DW_OP_breg1"; | |
2624 | case DW_OP_breg2: | |
2625 | return "DW_OP_breg2"; | |
2626 | case DW_OP_breg3: | |
2627 | return "DW_OP_breg3"; | |
2628 | case DW_OP_breg4: | |
2629 | return "DW_OP_breg4"; | |
2630 | case DW_OP_breg5: | |
2631 | return "DW_OP_breg5"; | |
2632 | case DW_OP_breg6: | |
2633 | return "DW_OP_breg6"; | |
2634 | case DW_OP_breg7: | |
2635 | return "DW_OP_breg7"; | |
2636 | case DW_OP_breg8: | |
2637 | return "DW_OP_breg8"; | |
2638 | case DW_OP_breg9: | |
2639 | return "DW_OP_breg9"; | |
2640 | case DW_OP_breg10: | |
2641 | return "DW_OP_breg10"; | |
2642 | case DW_OP_breg11: | |
2643 | return "DW_OP_breg11"; | |
2644 | case DW_OP_breg12: | |
2645 | return "DW_OP_breg12"; | |
2646 | case DW_OP_breg13: | |
2647 | return "DW_OP_breg13"; | |
2648 | case DW_OP_breg14: | |
2649 | return "DW_OP_breg14"; | |
2650 | case DW_OP_breg15: | |
2651 | return "DW_OP_breg15"; | |
2652 | case DW_OP_breg16: | |
2653 | return "DW_OP_breg16"; | |
2654 | case DW_OP_breg17: | |
2655 | return "DW_OP_breg17"; | |
2656 | case DW_OP_breg18: | |
2657 | return "DW_OP_breg18"; | |
2658 | case DW_OP_breg19: | |
2659 | return "DW_OP_breg19"; | |
2660 | case DW_OP_breg20: | |
2661 | return "DW_OP_breg20"; | |
2662 | case DW_OP_breg21: | |
2663 | return "DW_OP_breg21"; | |
2664 | case DW_OP_breg22: | |
2665 | return "DW_OP_breg22"; | |
2666 | case DW_OP_breg23: | |
2667 | return "DW_OP_breg23"; | |
2668 | case DW_OP_breg24: | |
2669 | return "DW_OP_breg24"; | |
2670 | case DW_OP_breg25: | |
2671 | return "DW_OP_breg25"; | |
2672 | case DW_OP_breg26: | |
2673 | return "DW_OP_breg26"; | |
2674 | case DW_OP_breg27: | |
2675 | return "DW_OP_breg27"; | |
2676 | case DW_OP_breg28: | |
2677 | return "DW_OP_breg28"; | |
2678 | case DW_OP_breg29: | |
2679 | return "DW_OP_breg29"; | |
2680 | case DW_OP_breg30: | |
2681 | return "DW_OP_breg30"; | |
2682 | case DW_OP_breg31: | |
2683 | return "DW_OP_breg31"; | |
2684 | case DW_OP_regx: | |
2685 | return "DW_OP_regx"; | |
2686 | case DW_OP_fbreg: | |
2687 | return "DW_OP_fbreg"; | |
2688 | case DW_OP_bregx: | |
2689 | return "DW_OP_bregx"; | |
2690 | case DW_OP_piece: | |
2691 | return "DW_OP_piece"; | |
2692 | case DW_OP_deref_size: | |
2693 | return "DW_OP_deref_size"; | |
2694 | case DW_OP_xderef_size: | |
2695 | return "DW_OP_xderef_size"; | |
2696 | case DW_OP_nop: | |
2697 | return "DW_OP_nop"; | |
b9203463 RH |
2698 | case DW_OP_push_object_address: |
2699 | return "DW_OP_push_object_address"; | |
2700 | case DW_OP_call2: | |
2701 | return "DW_OP_call2"; | |
2702 | case DW_OP_call4: | |
2703 | return "DW_OP_call4"; | |
2704 | case DW_OP_call_ref: | |
2705 | return "DW_OP_call_ref"; | |
2706 | case DW_OP_GNU_push_tls_address: | |
2707 | return "DW_OP_GNU_push_tls_address"; | |
3f76745e | 2708 | default: |
7d9d8943 | 2709 | return "OP_<unknown>"; |
3f76745e | 2710 | } |
bdb669cb | 2711 | } |
a3f97cbb | 2712 | |
7d9d8943 AM |
2713 | /* Return a pointer to a newly allocated location description. Location |
2714 | descriptions are simple expression terms that can be strung | |
2715 | together to form more complicated location (address) descriptions. */ | |
2716 | ||
2717 | static inline dw_loc_descr_ref | |
7080f735 AJ |
2718 | new_loc_descr (enum dwarf_location_atom op, long unsigned int oprnd1, |
2719 | long unsigned int oprnd2) | |
4b674448 | 2720 | { |
703ad42b | 2721 | dw_loc_descr_ref descr = ggc_alloc_cleared (sizeof (dw_loc_descr_node)); |
71dfc51f | 2722 | |
7d9d8943 AM |
2723 | descr->dw_loc_opc = op; |
2724 | descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const; | |
2725 | descr->dw_loc_oprnd1.v.val_unsigned = oprnd1; | |
2726 | descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const; | |
2727 | descr->dw_loc_oprnd2.v.val_unsigned = oprnd2; | |
71dfc51f | 2728 | |
7d9d8943 AM |
2729 | return descr; |
2730 | } | |
2731 | ||
63e46568 | 2732 | |
7d9d8943 AM |
2733 | /* Add a location description term to a location description expression. */ |
2734 | ||
2735 | static inline void | |
7080f735 | 2736 | add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr) |
7d9d8943 | 2737 | { |
b3694847 | 2738 | dw_loc_descr_ref *d; |
7d9d8943 AM |
2739 | |
2740 | /* Find the end of the chain. */ | |
2741 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
2742 | ; | |
2743 | ||
2744 | *d = descr; | |
2745 | } | |
2746 | ||
2747 | /* Return the size of a location descriptor. */ | |
2748 | ||
2749 | static unsigned long | |
7080f735 | 2750 | size_of_loc_descr (dw_loc_descr_ref loc) |
7d9d8943 | 2751 | { |
b3694847 | 2752 | unsigned long size = 1; |
7d9d8943 AM |
2753 | |
2754 | switch (loc->dw_loc_opc) | |
2755 | { | |
2756 | case DW_OP_addr: | |
b9203463 | 2757 | case INTERNAL_DW_OP_tls_addr: |
7d9d8943 AM |
2758 | size += DWARF2_ADDR_SIZE; |
2759 | break; | |
2760 | case DW_OP_const1u: | |
2761 | case DW_OP_const1s: | |
2762 | size += 1; | |
2763 | break; | |
2764 | case DW_OP_const2u: | |
2765 | case DW_OP_const2s: | |
2766 | size += 2; | |
2767 | break; | |
2768 | case DW_OP_const4u: | |
2769 | case DW_OP_const4s: | |
2770 | size += 4; | |
2771 | break; | |
2772 | case DW_OP_const8u: | |
2773 | case DW_OP_const8s: | |
2774 | size += 8; | |
2775 | break; | |
2776 | case DW_OP_constu: | |
2777 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2778 | break; | |
2779 | case DW_OP_consts: | |
2780 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2781 | break; | |
2782 | case DW_OP_pick: | |
2783 | size += 1; | |
2784 | break; | |
2785 | case DW_OP_plus_uconst: | |
2786 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2787 | break; | |
2788 | case DW_OP_skip: | |
2789 | case DW_OP_bra: | |
2790 | size += 2; | |
2791 | break; | |
2792 | case DW_OP_breg0: | |
2793 | case DW_OP_breg1: | |
2794 | case DW_OP_breg2: | |
2795 | case DW_OP_breg3: | |
2796 | case DW_OP_breg4: | |
2797 | case DW_OP_breg5: | |
2798 | case DW_OP_breg6: | |
2799 | case DW_OP_breg7: | |
2800 | case DW_OP_breg8: | |
2801 | case DW_OP_breg9: | |
2802 | case DW_OP_breg10: | |
2803 | case DW_OP_breg11: | |
2804 | case DW_OP_breg12: | |
2805 | case DW_OP_breg13: | |
2806 | case DW_OP_breg14: | |
2807 | case DW_OP_breg15: | |
2808 | case DW_OP_breg16: | |
2809 | case DW_OP_breg17: | |
2810 | case DW_OP_breg18: | |
2811 | case DW_OP_breg19: | |
2812 | case DW_OP_breg20: | |
2813 | case DW_OP_breg21: | |
2814 | case DW_OP_breg22: | |
2815 | case DW_OP_breg23: | |
2816 | case DW_OP_breg24: | |
2817 | case DW_OP_breg25: | |
2818 | case DW_OP_breg26: | |
2819 | case DW_OP_breg27: | |
2820 | case DW_OP_breg28: | |
2821 | case DW_OP_breg29: | |
2822 | case DW_OP_breg30: | |
2823 | case DW_OP_breg31: | |
2824 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2825 | break; | |
2826 | case DW_OP_regx: | |
2827 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2828 | break; | |
2829 | case DW_OP_fbreg: | |
2830 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2831 | break; | |
2832 | case DW_OP_bregx: | |
2833 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2834 | size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int); | |
2835 | break; | |
2836 | case DW_OP_piece: | |
2837 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2838 | break; | |
2839 | case DW_OP_deref_size: | |
2840 | case DW_OP_xderef_size: | |
2841 | size += 1; | |
2842 | break; | |
b9203463 RH |
2843 | case DW_OP_call2: |
2844 | size += 2; | |
2845 | break; | |
2846 | case DW_OP_call4: | |
2847 | size += 4; | |
2848 | break; | |
2849 | case DW_OP_call_ref: | |
2850 | size += DWARF2_ADDR_SIZE; | |
2851 | break; | |
3f76745e | 2852 | default: |
7d9d8943 | 2853 | break; |
4b674448 | 2854 | } |
7d9d8943 AM |
2855 | |
2856 | return size; | |
4b674448 JM |
2857 | } |
2858 | ||
7d9d8943 | 2859 | /* Return the size of a series of location descriptors. */ |
71dfc51f | 2860 | |
7d9d8943 | 2861 | static unsigned long |
7080f735 | 2862 | size_of_locs (dw_loc_descr_ref loc) |
4b674448 | 2863 | { |
2ad9852d | 2864 | unsigned long size; |
7d9d8943 | 2865 | |
2ad9852d | 2866 | for (size = 0; loc != NULL; loc = loc->dw_loc_next) |
d8041cc8 RH |
2867 | { |
2868 | loc->dw_loc_addr = size; | |
2869 | size += size_of_loc_descr (loc); | |
2870 | } | |
7d9d8943 AM |
2871 | |
2872 | return size; | |
4b674448 JM |
2873 | } |
2874 | ||
7d9d8943 | 2875 | /* Output location description stack opcode's operands (if any). */ |
71dfc51f | 2876 | |
7d9d8943 | 2877 | static void |
7080f735 | 2878 | output_loc_operands (dw_loc_descr_ref loc) |
a3f97cbb | 2879 | { |
b3694847 SS |
2880 | dw_val_ref val1 = &loc->dw_loc_oprnd1; |
2881 | dw_val_ref val2 = &loc->dw_loc_oprnd2; | |
7d9d8943 AM |
2882 | |
2883 | switch (loc->dw_loc_opc) | |
a3f97cbb | 2884 | { |
0517872a | 2885 | #ifdef DWARF2_DEBUGGING_INFO |
3f76745e | 2886 | case DW_OP_addr: |
2e4b9b8c | 2887 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL); |
7d9d8943 | 2888 | break; |
3f76745e | 2889 | case DW_OP_const2u: |
3f76745e | 2890 | case DW_OP_const2s: |
2e4b9b8c | 2891 | dw2_asm_output_data (2, val1->v.val_int, NULL); |
7d9d8943 | 2892 | break; |
3f76745e | 2893 | case DW_OP_const4u: |
3f76745e | 2894 | case DW_OP_const4s: |
2e4b9b8c | 2895 | dw2_asm_output_data (4, val1->v.val_int, NULL); |
7d9d8943 | 2896 | break; |
3f76745e | 2897 | case DW_OP_const8u: |
3f76745e | 2898 | case DW_OP_const8s: |
2e4b9b8c RH |
2899 | if (HOST_BITS_PER_LONG < 64) |
2900 | abort (); | |
2901 | dw2_asm_output_data (8, val1->v.val_int, NULL); | |
7d9d8943 | 2902 | break; |
0517872a JM |
2903 | case DW_OP_skip: |
2904 | case DW_OP_bra: | |
d8041cc8 RH |
2905 | { |
2906 | int offset; | |
2907 | ||
2908 | if (val1->val_class == dw_val_class_loc) | |
2909 | offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3); | |
2910 | else | |
2911 | abort (); | |
2912 | ||
2e4b9b8c | 2913 | dw2_asm_output_data (2, offset, NULL); |
d8041cc8 | 2914 | } |
0517872a | 2915 | break; |
3139472f JM |
2916 | #else |
2917 | case DW_OP_addr: | |
2918 | case DW_OP_const2u: | |
2919 | case DW_OP_const2s: | |
2920 | case DW_OP_const4u: | |
2921 | case DW_OP_const4s: | |
2922 | case DW_OP_const8u: | |
2923 | case DW_OP_const8s: | |
2924 | case DW_OP_skip: | |
2925 | case DW_OP_bra: | |
2926 | /* We currently don't make any attempt to make sure these are | |
73c68f61 SS |
2927 | aligned properly like we do for the main unwind info, so |
2928 | don't support emitting things larger than a byte if we're | |
2929 | only doing unwinding. */ | |
3139472f | 2930 | abort (); |
0517872a JM |
2931 | #endif |
2932 | case DW_OP_const1u: | |
2933 | case DW_OP_const1s: | |
2e4b9b8c | 2934 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
0517872a | 2935 | break; |
3f76745e | 2936 | case DW_OP_constu: |
2e4b9b8c | 2937 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2938 | break; |
3f76745e | 2939 | case DW_OP_consts: |
2e4b9b8c | 2940 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 AM |
2941 | break; |
2942 | case DW_OP_pick: | |
2e4b9b8c | 2943 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 AM |
2944 | break; |
2945 | case DW_OP_plus_uconst: | |
2e4b9b8c | 2946 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2947 | break; |
3f76745e | 2948 | case DW_OP_breg0: |
3f76745e | 2949 | case DW_OP_breg1: |
3f76745e | 2950 | case DW_OP_breg2: |
3f76745e | 2951 | case DW_OP_breg3: |
3f76745e | 2952 | case DW_OP_breg4: |
3f76745e | 2953 | case DW_OP_breg5: |
3f76745e | 2954 | case DW_OP_breg6: |
3f76745e | 2955 | case DW_OP_breg7: |
3f76745e | 2956 | case DW_OP_breg8: |
3f76745e | 2957 | case DW_OP_breg9: |
3f76745e | 2958 | case DW_OP_breg10: |
3f76745e | 2959 | case DW_OP_breg11: |
3f76745e | 2960 | case DW_OP_breg12: |
3f76745e | 2961 | case DW_OP_breg13: |
3f76745e | 2962 | case DW_OP_breg14: |
3f76745e | 2963 | case DW_OP_breg15: |
3f76745e | 2964 | case DW_OP_breg16: |
3f76745e | 2965 | case DW_OP_breg17: |
3f76745e | 2966 | case DW_OP_breg18: |
3f76745e | 2967 | case DW_OP_breg19: |
3f76745e | 2968 | case DW_OP_breg20: |
3f76745e | 2969 | case DW_OP_breg21: |
3f76745e | 2970 | case DW_OP_breg22: |
3f76745e | 2971 | case DW_OP_breg23: |
3f76745e | 2972 | case DW_OP_breg24: |
3f76745e | 2973 | case DW_OP_breg25: |
3f76745e | 2974 | case DW_OP_breg26: |
3f76745e | 2975 | case DW_OP_breg27: |
3f76745e | 2976 | case DW_OP_breg28: |
3f76745e | 2977 | case DW_OP_breg29: |
3f76745e | 2978 | case DW_OP_breg30: |
3f76745e | 2979 | case DW_OP_breg31: |
2e4b9b8c | 2980 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 2981 | break; |
3f76745e | 2982 | case DW_OP_regx: |
2e4b9b8c | 2983 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2984 | break; |
3f76745e | 2985 | case DW_OP_fbreg: |
2e4b9b8c | 2986 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 2987 | break; |
3f76745e | 2988 | case DW_OP_bregx: |
2e4b9b8c RH |
2989 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
2990 | dw2_asm_output_data_sleb128 (val2->v.val_int, NULL); | |
7d9d8943 | 2991 | break; |
3f76745e | 2992 | case DW_OP_piece: |
2e4b9b8c | 2993 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2994 | break; |
3f76745e | 2995 | case DW_OP_deref_size: |
3f76745e | 2996 | case DW_OP_xderef_size: |
2e4b9b8c | 2997 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 | 2998 | break; |
b9203463 RH |
2999 | |
3000 | case INTERNAL_DW_OP_tls_addr: | |
3001 | #ifdef ASM_OUTPUT_DWARF_DTPREL | |
3002 | ASM_OUTPUT_DWARF_DTPREL (asm_out_file, DWARF2_ADDR_SIZE, | |
3003 | val1->v.val_addr); | |
3004 | fputc ('\n', asm_out_file); | |
3005 | #else | |
3006 | abort (); | |
3007 | #endif | |
3008 | break; | |
3009 | ||
7d9d8943 | 3010 | default: |
3139472f JM |
3011 | /* Other codes have no operands. */ |
3012 | break; | |
7d9d8943 AM |
3013 | } |
3014 | } | |
3015 | ||
3016 | /* Output a sequence of location operations. */ | |
3017 | ||
3018 | static void | |
7080f735 | 3019 | output_loc_sequence (dw_loc_descr_ref loc) |
7d9d8943 AM |
3020 | { |
3021 | for (; loc != NULL; loc = loc->dw_loc_next) | |
3022 | { | |
3023 | /* Output the opcode. */ | |
2e4b9b8c RH |
3024 | dw2_asm_output_data (1, loc->dw_loc_opc, |
3025 | "%s", dwarf_stack_op_name (loc->dw_loc_opc)); | |
7d9d8943 AM |
3026 | |
3027 | /* Output the operand(s) (if any). */ | |
3028 | output_loc_operands (loc); | |
3029 | } | |
3030 | } | |
3031 | ||
3032 | /* This routine will generate the correct assembly data for a location | |
3033 | description based on a cfi entry with a complex address. */ | |
3034 | ||
3035 | static void | |
7080f735 | 3036 | output_cfa_loc (dw_cfi_ref cfi) |
7d9d8943 AM |
3037 | { |
3038 | dw_loc_descr_ref loc; | |
3039 | unsigned long size; | |
3040 | ||
3041 | /* Output the size of the block. */ | |
3042 | loc = cfi->dw_cfi_oprnd1.dw_cfi_loc; | |
3043 | size = size_of_locs (loc); | |
2e4b9b8c | 3044 | dw2_asm_output_data_uleb128 (size, NULL); |
7d9d8943 AM |
3045 | |
3046 | /* Now output the operations themselves. */ | |
3047 | output_loc_sequence (loc); | |
3048 | } | |
3049 | ||
dd49a9ec | 3050 | /* This function builds a dwarf location descriptor sequence from |
556273e0 | 3051 | a dw_cfa_location. */ |
7d9d8943 AM |
3052 | |
3053 | static struct dw_loc_descr_struct * | |
7080f735 | 3054 | build_cfa_loc (dw_cfa_location *cfa) |
7d9d8943 AM |
3055 | { |
3056 | struct dw_loc_descr_struct *head, *tmp; | |
3057 | ||
3058 | if (cfa->indirect == 0) | |
3059 | abort (); | |
3060 | ||
3061 | if (cfa->base_offset) | |
f299afab HPN |
3062 | { |
3063 | if (cfa->reg <= 31) | |
3064 | head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0); | |
3065 | else | |
3066 | head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset); | |
3067 | } | |
3068 | else if (cfa->reg <= 31) | |
7d9d8943 | 3069 | head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0); |
f299afab HPN |
3070 | else |
3071 | head = new_loc_descr (DW_OP_regx, cfa->reg, 0); | |
2ad9852d | 3072 | |
7d9d8943 AM |
3073 | head->dw_loc_oprnd1.val_class = dw_val_class_const; |
3074 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
3075 | add_loc_descr (&head, tmp); | |
3076 | if (cfa->offset != 0) | |
3077 | { | |
3078 | tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0); | |
3079 | add_loc_descr (&head, tmp); | |
3080 | } | |
2ad9852d | 3081 | |
7d9d8943 AM |
3082 | return head; |
3083 | } | |
3084 | ||
2ad9852d RK |
3085 | /* This function fills in aa dw_cfa_location structure from a dwarf location |
3086 | descriptor sequence. */ | |
7d9d8943 AM |
3087 | |
3088 | static void | |
7080f735 | 3089 | get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc) |
7d9d8943 | 3090 | { |
556273e0 | 3091 | struct dw_loc_descr_struct *ptr; |
7d9d8943 AM |
3092 | cfa->offset = 0; |
3093 | cfa->base_offset = 0; | |
3094 | cfa->indirect = 0; | |
3095 | cfa->reg = -1; | |
3096 | ||
3097 | for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next) | |
3098 | { | |
3099 | enum dwarf_location_atom op = ptr->dw_loc_opc; | |
2ad9852d | 3100 | |
7d9d8943 | 3101 | switch (op) |
556273e0 | 3102 | { |
7d9d8943 AM |
3103 | case DW_OP_reg0: |
3104 | case DW_OP_reg1: | |
3105 | case DW_OP_reg2: | |
3106 | case DW_OP_reg3: | |
3107 | case DW_OP_reg4: | |
3108 | case DW_OP_reg5: | |
3109 | case DW_OP_reg6: | |
3110 | case DW_OP_reg7: | |
3111 | case DW_OP_reg8: | |
3112 | case DW_OP_reg9: | |
3113 | case DW_OP_reg10: | |
3114 | case DW_OP_reg11: | |
3115 | case DW_OP_reg12: | |
3116 | case DW_OP_reg13: | |
3117 | case DW_OP_reg14: | |
3118 | case DW_OP_reg15: | |
3119 | case DW_OP_reg16: | |
3120 | case DW_OP_reg17: | |
3121 | case DW_OP_reg18: | |
3122 | case DW_OP_reg19: | |
3123 | case DW_OP_reg20: | |
3124 | case DW_OP_reg21: | |
3125 | case DW_OP_reg22: | |
3126 | case DW_OP_reg23: | |
3127 | case DW_OP_reg24: | |
3128 | case DW_OP_reg25: | |
3129 | case DW_OP_reg26: | |
3130 | case DW_OP_reg27: | |
3131 | case DW_OP_reg28: | |
3132 | case DW_OP_reg29: | |
3133 | case DW_OP_reg30: | |
3134 | case DW_OP_reg31: | |
3135 | cfa->reg = op - DW_OP_reg0; | |
3136 | break; | |
3137 | case DW_OP_regx: | |
3138 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
3139 | break; | |
3140 | case DW_OP_breg0: | |
3141 | case DW_OP_breg1: | |
3142 | case DW_OP_breg2: | |
3143 | case DW_OP_breg3: | |
3144 | case DW_OP_breg4: | |
3145 | case DW_OP_breg5: | |
3146 | case DW_OP_breg6: | |
3147 | case DW_OP_breg7: | |
3148 | case DW_OP_breg8: | |
3149 | case DW_OP_breg9: | |
3150 | case DW_OP_breg10: | |
3151 | case DW_OP_breg11: | |
3152 | case DW_OP_breg12: | |
3153 | case DW_OP_breg13: | |
3154 | case DW_OP_breg14: | |
3155 | case DW_OP_breg15: | |
3156 | case DW_OP_breg16: | |
3157 | case DW_OP_breg17: | |
3158 | case DW_OP_breg18: | |
3159 | case DW_OP_breg19: | |
3160 | case DW_OP_breg20: | |
3161 | case DW_OP_breg21: | |
3162 | case DW_OP_breg22: | |
3163 | case DW_OP_breg23: | |
3164 | case DW_OP_breg24: | |
3165 | case DW_OP_breg25: | |
3166 | case DW_OP_breg26: | |
3167 | case DW_OP_breg27: | |
3168 | case DW_OP_breg28: | |
3169 | case DW_OP_breg29: | |
3170 | case DW_OP_breg30: | |
3171 | case DW_OP_breg31: | |
3172 | cfa->reg = op - DW_OP_breg0; | |
3173 | cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int; | |
3174 | break; | |
3175 | case DW_OP_bregx: | |
3176 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
3177 | cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int; | |
3178 | break; | |
3179 | case DW_OP_deref: | |
3180 | cfa->indirect = 1; | |
3181 | break; | |
3182 | case DW_OP_plus_uconst: | |
556273e0 | 3183 | cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned; |
7d9d8943 AM |
3184 | break; |
3185 | default: | |
a1f300c0 | 3186 | internal_error ("DW_LOC_OP %s not implemented\n", |
400500c4 | 3187 | dwarf_stack_op_name (ptr->dw_loc_opc)); |
7d9d8943 AM |
3188 | } |
3189 | } | |
3190 | } | |
3191 | #endif /* .debug_frame support */ | |
3192 | \f | |
3193 | /* And now, the support for symbolic debugging information. */ | |
3194 | #ifdef DWARF2_DEBUGGING_INFO | |
3195 | ||
117f9d28 | 3196 | /* .debug_str support. */ |
7080f735 AJ |
3197 | static int output_indirect_string (void **, void *); |
3198 | ||
3199 | static void dwarf2out_init (const char *); | |
3200 | static void dwarf2out_finish (const char *); | |
3201 | static void dwarf2out_define (unsigned int, const char *); | |
3202 | static void dwarf2out_undef (unsigned int, const char *); | |
3203 | static void dwarf2out_start_source_file (unsigned, const char *); | |
3204 | static void dwarf2out_end_source_file (unsigned); | |
3205 | static void dwarf2out_begin_block (unsigned, unsigned); | |
3206 | static void dwarf2out_end_block (unsigned, unsigned); | |
3207 | static bool dwarf2out_ignore_block (tree); | |
3208 | static void dwarf2out_global_decl (tree); | |
3209 | static void dwarf2out_abstract_function (tree); | |
7f905405 NB |
3210 | |
3211 | /* The debug hooks structure. */ | |
3212 | ||
54b6670a | 3213 | const struct gcc_debug_hooks dwarf2_debug_hooks = |
7f905405 NB |
3214 | { |
3215 | dwarf2out_init, | |
3216 | dwarf2out_finish, | |
3217 | dwarf2out_define, | |
3218 | dwarf2out_undef, | |
3219 | dwarf2out_start_source_file, | |
a5a42b92 NB |
3220 | dwarf2out_end_source_file, |
3221 | dwarf2out_begin_block, | |
e2a12aca | 3222 | dwarf2out_end_block, |
e1772ac0 | 3223 | dwarf2out_ignore_block, |
e2a12aca | 3224 | dwarf2out_source_line, |
653e276c | 3225 | dwarf2out_begin_prologue, |
702ada3d | 3226 | debug_nothing_int_charstar, /* end_prologue */ |
e2a12aca | 3227 | dwarf2out_end_epilogue, |
653e276c | 3228 | debug_nothing_tree, /* begin_function */ |
2b85879e NB |
3229 | debug_nothing_int, /* end_function */ |
3230 | dwarf2out_decl, /* function_decl */ | |
3231 | dwarf2out_global_decl, | |
e1772ac0 NB |
3232 | debug_nothing_tree, /* deferred_inline_function */ |
3233 | /* The DWARF 2 backend tries to reduce debugging bloat by not | |
3234 | emitting the abstract description of inline functions until | |
3235 | something tries to reference them. */ | |
3236 | dwarf2out_abstract_function, /* outlining_inline_function */ | |
33b49800 GK |
3237 | debug_nothing_rtx, /* label */ |
3238 | debug_nothing_int /* handle_pch */ | |
7f905405 | 3239 | }; |
17211ab5 | 3240 | #endif |
7f905405 | 3241 | \f |
7d9d8943 AM |
3242 | /* NOTE: In the comments in this file, many references are made to |
3243 | "Debugging Information Entries". This term is abbreviated as `DIE' | |
3244 | throughout the remainder of this file. */ | |
3245 | ||
3246 | /* An internal representation of the DWARF output is built, and then | |
3247 | walked to generate the DWARF debugging info. The walk of the internal | |
3248 | representation is done after the entire program has been compiled. | |
3249 | The types below are used to describe the internal representation. */ | |
3250 | ||
3251 | /* Various DIE's use offsets relative to the beginning of the | |
3252 | .debug_info section to refer to each other. */ | |
3253 | ||
3254 | typedef long int dw_offset; | |
3255 | ||
3256 | /* Define typedefs here to avoid circular dependencies. */ | |
3257 | ||
3258 | typedef struct dw_attr_struct *dw_attr_ref; | |
3259 | typedef struct dw_line_info_struct *dw_line_info_ref; | |
3260 | typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref; | |
3261 | typedef struct pubname_struct *pubname_ref; | |
a20612aa | 3262 | typedef struct dw_ranges_struct *dw_ranges_ref; |
7d9d8943 AM |
3263 | |
3264 | /* Each entry in the line_info_table maintains the file and | |
3265 | line number associated with the label generated for that | |
3266 | entry. The label gives the PC value associated with | |
3267 | the line number entry. */ | |
3268 | ||
17211ab5 | 3269 | typedef struct dw_line_info_struct GTY(()) |
7d9d8943 AM |
3270 | { |
3271 | unsigned long dw_file_num; | |
3272 | unsigned long dw_line_num; | |
3273 | } | |
3274 | dw_line_info_entry; | |
3275 | ||
3276 | /* Line information for functions in separate sections; each one gets its | |
3277 | own sequence. */ | |
17211ab5 | 3278 | typedef struct dw_separate_line_info_struct GTY(()) |
7d9d8943 AM |
3279 | { |
3280 | unsigned long dw_file_num; | |
3281 | unsigned long dw_line_num; | |
3282 | unsigned long function; | |
3283 | } | |
3284 | dw_separate_line_info_entry; | |
3285 | ||
3286 | /* Each DIE attribute has a field specifying the attribute kind, | |
3287 | a link to the next attribute in the chain, and an attribute value. | |
3288 | Attributes are typically linked below the DIE they modify. */ | |
3289 | ||
17211ab5 | 3290 | typedef struct dw_attr_struct GTY(()) |
7d9d8943 AM |
3291 | { |
3292 | enum dwarf_attribute dw_attr; | |
3293 | dw_attr_ref dw_attr_next; | |
3294 | dw_val_node dw_attr_val; | |
3295 | } | |
3296 | dw_attr_node; | |
3297 | ||
3298 | /* The Debugging Information Entry (DIE) structure */ | |
3299 | ||
17211ab5 | 3300 | typedef struct die_struct GTY(()) |
7d9d8943 AM |
3301 | { |
3302 | enum dwarf_tag die_tag; | |
881c6935 | 3303 | char *die_symbol; |
7d9d8943 AM |
3304 | dw_attr_ref die_attr; |
3305 | dw_die_ref die_parent; | |
3306 | dw_die_ref die_child; | |
3307 | dw_die_ref die_sib; | |
3308 | dw_offset die_offset; | |
3309 | unsigned long die_abbrev; | |
1bfb5f8f | 3310 | int die_mark; |
7d9d8943 AM |
3311 | } |
3312 | die_node; | |
3313 | ||
3314 | /* The pubname structure */ | |
3315 | ||
17211ab5 | 3316 | typedef struct pubname_struct GTY(()) |
7d9d8943 AM |
3317 | { |
3318 | dw_die_ref die; | |
556273e0 | 3319 | char *name; |
7d9d8943 AM |
3320 | } |
3321 | pubname_entry; | |
3322 | ||
17211ab5 | 3323 | struct dw_ranges_struct GTY(()) |
a20612aa RH |
3324 | { |
3325 | int block_num; | |
3326 | }; | |
3327 | ||
7d9d8943 | 3328 | /* The limbo die list structure. */ |
17211ab5 | 3329 | typedef struct limbo_die_struct GTY(()) |
7d9d8943 AM |
3330 | { |
3331 | dw_die_ref die; | |
54ba1f0d | 3332 | tree created_for; |
7d9d8943 AM |
3333 | struct limbo_die_struct *next; |
3334 | } | |
3335 | limbo_die_node; | |
3336 | ||
3337 | /* How to start an assembler comment. */ | |
3338 | #ifndef ASM_COMMENT_START | |
3339 | #define ASM_COMMENT_START ";#" | |
3340 | #endif | |
3341 | ||
cc2902df | 3342 | /* Define a macro which returns nonzero for a TYPE_DECL which was |
7d9d8943 AM |
3343 | implicitly generated for a tagged type. |
3344 | ||
3345 | Note that unlike the gcc front end (which generates a NULL named | |
3346 | TYPE_DECL node for each complete tagged type, each array type, and | |
3347 | each function type node created) the g++ front end generates a | |
3348 | _named_ TYPE_DECL node for each tagged type node created. | |
3349 | These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to | |
3350 | generate a DW_TAG_typedef DIE for them. */ | |
3351 | ||
3352 | #define TYPE_DECL_IS_STUB(decl) \ | |
3353 | (DECL_NAME (decl) == NULL_TREE \ | |
3354 | || (DECL_ARTIFICIAL (decl) \ | |
3355 | && is_tagged_type (TREE_TYPE (decl)) \ | |
3356 | && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \ | |
3357 | /* This is necessary for stub decls that \ | |
3358 | appear in nested inline functions. */ \ | |
3359 | || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \ | |
3360 | && (decl_ultimate_origin (decl) \ | |
3361 | == TYPE_STUB_DECL (TREE_TYPE (decl))))))) | |
3362 | ||
3363 | /* Information concerning the compilation unit's programming | |
3364 | language, and compiler version. */ | |
3365 | ||
7d9d8943 | 3366 | /* Fixed size portion of the DWARF compilation unit header. */ |
9eb0ef7a KB |
3367 | #define DWARF_COMPILE_UNIT_HEADER_SIZE \ |
3368 | (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3) | |
7d9d8943 | 3369 | |
7d9d8943 AM |
3370 | /* Fixed size portion of public names info. */ |
3371 | #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2) | |
3372 | ||
3373 | /* Fixed size portion of the address range info. */ | |
3374 | #define DWARF_ARANGES_HEADER_SIZE \ | |
c583e7c3 KB |
3375 | (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \ |
3376 | DWARF2_ADDR_SIZE * 2) \ | |
3377 | - DWARF_INITIAL_LENGTH_SIZE) | |
7d9d8943 AM |
3378 | |
3379 | /* Size of padding portion in the address range info. It must be | |
3380 | aligned to twice the pointer size. */ | |
3381 | #define DWARF_ARANGES_PAD_SIZE \ | |
c583e7c3 KB |
3382 | (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \ |
3383 | DWARF2_ADDR_SIZE * 2) \ | |
3384 | - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4)) | |
7d9d8943 | 3385 | |
9d147085 | 3386 | /* Use assembler line directives if available. */ |
7d9d8943 | 3387 | #ifndef DWARF2_ASM_LINE_DEBUG_INFO |
9d147085 RH |
3388 | #ifdef HAVE_AS_DWARF2_DEBUG_LINE |
3389 | #define DWARF2_ASM_LINE_DEBUG_INFO 1 | |
3390 | #else | |
7d9d8943 AM |
3391 | #define DWARF2_ASM_LINE_DEBUG_INFO 0 |
3392 | #endif | |
9d147085 | 3393 | #endif |
7d9d8943 | 3394 | |
7d9d8943 AM |
3395 | /* Minimum line offset in a special line info. opcode. |
3396 | This value was chosen to give a reasonable range of values. */ | |
3397 | #define DWARF_LINE_BASE -10 | |
3398 | ||
a1f300c0 | 3399 | /* First special line opcode - leave room for the standard opcodes. */ |
7d9d8943 AM |
3400 | #define DWARF_LINE_OPCODE_BASE 10 |
3401 | ||
3402 | /* Range of line offsets in a special line info. opcode. */ | |
3403 | #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1) | |
3404 | ||
3405 | /* Flag that indicates the initial value of the is_stmt_start flag. | |
3406 | In the present implementation, we do not mark any lines as | |
3407 | the beginning of a source statement, because that information | |
3408 | is not made available by the GCC front-end. */ | |
3409 | #define DWARF_LINE_DEFAULT_IS_STMT_START 1 | |
3410 | ||
c1b50e49 | 3411 | #ifdef DWARF2_DEBUGGING_INFO |
7d9d8943 AM |
3412 | /* This location is used by calc_die_sizes() to keep track |
3413 | the offset of each DIE within the .debug_info section. */ | |
3414 | static unsigned long next_die_offset; | |
c1b50e49 | 3415 | #endif |
7d9d8943 AM |
3416 | |
3417 | /* Record the root of the DIE's built for the current compilation unit. */ | |
17211ab5 | 3418 | static GTY(()) dw_die_ref comp_unit_die; |
7d9d8943 | 3419 | |
c1b50e49 | 3420 | #ifdef DWARF2_DEBUGGING_INFO |
cc0017a9 ZD |
3421 | /* We need special handling in dwarf2out_start_source_file if it is |
3422 | first one. */ | |
3423 | static int is_main_source; | |
c1b50e49 | 3424 | #endif |
cc0017a9 | 3425 | |
7d9d8943 | 3426 | /* A list of DIEs with a NULL parent waiting to be relocated. */ |
17211ab5 | 3427 | static GTY(()) limbo_die_node *limbo_die_list; |
7d9d8943 | 3428 | |
981975b6 | 3429 | /* Filenames referenced by this compilation unit. */ |
c4274b22 | 3430 | static GTY(()) varray_type file_table; |
73c68f61 | 3431 | static GTY(()) varray_type file_table_emitted; |
c4274b22 | 3432 | static GTY(()) size_t file_table_last_lookup_index; |
2e18bbae | 3433 | |
7d9d8943 AM |
3434 | /* A pointer to the base of a table of references to DIE's that describe |
3435 | declarations. The table is indexed by DECL_UID() which is a unique | |
3436 | number identifying each decl. */ | |
17211ab5 | 3437 | static GTY((length ("decl_die_table_allocated"))) dw_die_ref *decl_die_table; |
7d9d8943 AM |
3438 | |
3439 | /* Number of elements currently allocated for the decl_die_table. */ | |
c2e9147c | 3440 | static GTY(()) unsigned decl_die_table_allocated; |
7d9d8943 AM |
3441 | |
3442 | /* Number of elements in decl_die_table currently in use. */ | |
c2e9147c | 3443 | static GTY(()) unsigned decl_die_table_in_use; |
7d9d8943 AM |
3444 | |
3445 | /* Size (in elements) of increments by which we may expand the | |
3446 | decl_die_table. */ | |
3447 | #define DECL_DIE_TABLE_INCREMENT 256 | |
3448 | ||
7d9d8943 AM |
3449 | /* A pointer to the base of a list of references to DIE's that |
3450 | are uniquely identified by their tag, presence/absence of | |
3451 | children DIE's, and list of attribute/value pairs. */ | |
7080f735 | 3452 | static GTY((length ("abbrev_die_table_allocated"))) |
17211ab5 | 3453 | dw_die_ref *abbrev_die_table; |
7d9d8943 AM |
3454 | |
3455 | /* Number of elements currently allocated for abbrev_die_table. */ | |
c2e9147c | 3456 | static GTY(()) unsigned abbrev_die_table_allocated; |
7d9d8943 AM |
3457 | |
3458 | /* Number of elements in type_die_table currently in use. */ | |
c2e9147c | 3459 | static GTY(()) unsigned abbrev_die_table_in_use; |
7d9d8943 AM |
3460 | |
3461 | /* Size (in elements) of increments by which we may expand the | |
3462 | abbrev_die_table. */ | |
3463 | #define ABBREV_DIE_TABLE_INCREMENT 256 | |
3464 | ||
3465 | /* A pointer to the base of a table that contains line information | |
3466 | for each source code line in .text in the compilation unit. */ | |
7080f735 | 3467 | static GTY((length ("line_info_table_allocated"))) |
17211ab5 | 3468 | dw_line_info_ref line_info_table; |
7d9d8943 AM |
3469 | |
3470 | /* Number of elements currently allocated for line_info_table. */ | |
c2e9147c | 3471 | static GTY(()) unsigned line_info_table_allocated; |
7d9d8943 | 3472 | |
17211ab5 | 3473 | /* Number of elements in line_info_table currently in use. */ |
c2e9147c | 3474 | static GTY(()) unsigned line_info_table_in_use; |
7d9d8943 AM |
3475 | |
3476 | /* A pointer to the base of a table that contains line information | |
3477 | for each source code line outside of .text in the compilation unit. */ | |
17211ab5 GK |
3478 | static GTY ((length ("separate_line_info_table_allocated"))) |
3479 | dw_separate_line_info_ref separate_line_info_table; | |
7d9d8943 AM |
3480 | |
3481 | /* Number of elements currently allocated for separate_line_info_table. */ | |
c2e9147c | 3482 | static GTY(()) unsigned separate_line_info_table_allocated; |
7d9d8943 | 3483 | |
17211ab5 | 3484 | /* Number of elements in separate_line_info_table currently in use. */ |
c2e9147c | 3485 | static GTY(()) unsigned separate_line_info_table_in_use; |
7d9d8943 AM |
3486 | |
3487 | /* Size (in elements) of increments by which we may expand the | |
3488 | line_info_table. */ | |
3489 | #define LINE_INFO_TABLE_INCREMENT 1024 | |
3490 | ||
3491 | /* A pointer to the base of a table that contains a list of publicly | |
3492 | accessible names. */ | |
17211ab5 | 3493 | static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table; |
7d9d8943 AM |
3494 | |
3495 | /* Number of elements currently allocated for pubname_table. */ | |
c2e9147c | 3496 | static GTY(()) unsigned pubname_table_allocated; |
7d9d8943 AM |
3497 | |
3498 | /* Number of elements in pubname_table currently in use. */ | |
c2e9147c | 3499 | static GTY(()) unsigned pubname_table_in_use; |
7d9d8943 AM |
3500 | |
3501 | /* Size (in elements) of increments by which we may expand the | |
3502 | pubname_table. */ | |
3503 | #define PUBNAME_TABLE_INCREMENT 64 | |
3504 | ||
a20612aa | 3505 | /* Array of dies for which we should generate .debug_arange info. */ |
17211ab5 | 3506 | static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table; |
7d9d8943 AM |
3507 | |
3508 | /* Number of elements currently allocated for arange_table. */ | |
c2e9147c | 3509 | static GTY(()) unsigned arange_table_allocated; |
7d9d8943 AM |
3510 | |
3511 | /* Number of elements in arange_table currently in use. */ | |
c2e9147c | 3512 | static GTY(()) unsigned arange_table_in_use; |
7d9d8943 AM |
3513 | |
3514 | /* Size (in elements) of increments by which we may expand the | |
3515 | arange_table. */ | |
3516 | #define ARANGE_TABLE_INCREMENT 64 | |
3517 | ||
a20612aa | 3518 | /* Array of dies for which we should generate .debug_ranges info. */ |
17211ab5 | 3519 | static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table; |
a20612aa RH |
3520 | |
3521 | /* Number of elements currently allocated for ranges_table. */ | |
c2e9147c | 3522 | static GTY(()) unsigned ranges_table_allocated; |
a20612aa RH |
3523 | |
3524 | /* Number of elements in ranges_table currently in use. */ | |
c2e9147c | 3525 | static GTY(()) unsigned ranges_table_in_use; |
a20612aa RH |
3526 | |
3527 | /* Size (in elements) of increments by which we may expand the | |
3528 | ranges_table. */ | |
3529 | #define RANGES_TABLE_INCREMENT 64 | |
3530 | ||
63e46568 | 3531 | /* Whether we have location lists that need outputting */ |
c2e9147c | 3532 | static GTY(()) unsigned have_location_lists; |
63e46568 | 3533 | |
c2e9147c | 3534 | #ifdef DWARF2_DEBUGGING_INFO |
7d9d8943 AM |
3535 | /* Record whether the function being analyzed contains inlined functions. */ |
3536 | static int current_function_has_inlines; | |
c1b50e49 | 3537 | #endif |
7d9d8943 AM |
3538 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
3539 | static int comp_unit_has_inlines; | |
3540 | #endif | |
3541 | ||
e0bb17a8 | 3542 | /* Number of file tables emitted in maybe_emit_file(). */ |
c2e9147c GK |
3543 | static GTY(()) int emitcount = 0; |
3544 | ||
71c0e7fc | 3545 | /* Number of internal labels generated by gen_internal_sym(). */ |
c2e9147c GK |
3546 | static GTY(()) int label_num; |
3547 | ||
17211ab5 GK |
3548 | #ifdef DWARF2_DEBUGGING_INFO |
3549 | ||
7d9d8943 AM |
3550 | /* Forward declarations for functions defined in this file. */ |
3551 | ||
7080f735 AJ |
3552 | static int is_pseudo_reg (rtx); |
3553 | static tree type_main_variant (tree); | |
3554 | static int is_tagged_type (tree); | |
3555 | static const char *dwarf_tag_name (unsigned); | |
3556 | static const char *dwarf_attr_name (unsigned); | |
3557 | static const char *dwarf_form_name (unsigned); | |
7d9d8943 | 3558 | #if 0 |
7080f735 | 3559 | static const char *dwarf_type_encoding_name (unsigned); |
7d9d8943 | 3560 | #endif |
7080f735 AJ |
3561 | static tree decl_ultimate_origin (tree); |
3562 | static tree block_ultimate_origin (tree); | |
3563 | static tree decl_class_context (tree); | |
3564 | static void add_dwarf_attr (dw_die_ref, dw_attr_ref); | |
3565 | static inline enum dw_val_class AT_class (dw_attr_ref); | |
3566 | static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned); | |
3567 | static inline unsigned AT_flag (dw_attr_ref); | |
3568 | static void add_AT_int (dw_die_ref, enum dwarf_attribute, long); | |
3569 | static inline long int AT_int (dw_attr_ref); | |
3570 | static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned long); | |
3571 | static inline unsigned long AT_unsigned (dw_attr_ref); | |
3572 | static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long, | |
3573 | unsigned long); | |
3574 | static void add_AT_float (dw_die_ref, enum dwarf_attribute, unsigned, long *); | |
3575 | static hashval_t debug_str_do_hash (const void *); | |
3576 | static int debug_str_eq (const void *, const void *); | |
3577 | static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *); | |
3578 | static inline const char *AT_string (dw_attr_ref); | |
3579 | static int AT_string_form (dw_attr_ref); | |
3580 | static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref); | |
3581 | static inline dw_die_ref AT_ref (dw_attr_ref); | |
3582 | static inline int AT_ref_external (dw_attr_ref); | |
3583 | static inline void set_AT_ref_external (dw_attr_ref, int); | |
3584 | static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned); | |
3585 | static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref); | |
3586 | static inline dw_loc_descr_ref AT_loc (dw_attr_ref); | |
3587 | static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute, | |
3588 | dw_loc_list_ref); | |
3589 | static inline dw_loc_list_ref AT_loc_list (dw_attr_ref); | |
3590 | static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx); | |
3591 | static inline rtx AT_addr (dw_attr_ref); | |
3592 | static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *); | |
3593 | static void add_AT_lbl_offset (dw_die_ref, enum dwarf_attribute, const char *); | |
3594 | static void add_AT_offset (dw_die_ref, enum dwarf_attribute, unsigned long); | |
3595 | static void add_AT_range_list (dw_die_ref, enum dwarf_attribute, | |
3596 | unsigned long); | |
3597 | static inline const char *AT_lbl (dw_attr_ref); | |
3598 | static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute); | |
3599 | static const char *get_AT_low_pc (dw_die_ref); | |
3600 | static const char *get_AT_hi_pc (dw_die_ref); | |
3601 | static const char *get_AT_string (dw_die_ref, enum dwarf_attribute); | |
3602 | static int get_AT_flag (dw_die_ref, enum dwarf_attribute); | |
3603 | static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute); | |
3604 | static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute); | |
3605 | static bool is_c_family (void); | |
3606 | static bool is_cxx (void); | |
3607 | static bool is_java (void); | |
3608 | static bool is_fortran (void); | |
3609 | static bool is_ada (void); | |
3610 | static void remove_AT (dw_die_ref, enum dwarf_attribute); | |
3611 | static inline void free_die (dw_die_ref); | |
3612 | static void remove_children (dw_die_ref); | |
3613 | static void add_child_die (dw_die_ref, dw_die_ref); | |
3614 | static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree); | |
3615 | static dw_die_ref lookup_type_die (tree); | |
3616 | static void equate_type_number_to_die (tree, dw_die_ref); | |
3617 | static dw_die_ref lookup_decl_die (tree); | |
3618 | static void equate_decl_number_to_die (tree, dw_die_ref); | |
3619 | static void print_spaces (FILE *); | |
3620 | static void print_die (dw_die_ref, FILE *); | |
3621 | static void print_dwarf_line_table (FILE *); | |
3622 | static void reverse_die_lists (dw_die_ref); | |
3623 | static void reverse_all_dies (dw_die_ref); | |
3624 | static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref); | |
3625 | static dw_die_ref pop_compile_unit (dw_die_ref); | |
3626 | static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *); | |
3627 | static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *); | |
3628 | static void die_checksum (dw_die_ref, struct md5_ctx *, int *); | |
3629 | static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *); | |
3630 | static int same_dw_val_p (dw_val_node *, dw_val_node *, int *); | |
3631 | static int same_attr_p (dw_attr_ref, dw_attr_ref, int *); | |
3632 | static int same_die_p (dw_die_ref, dw_die_ref, int *); | |
3633 | static int same_die_p_wrap (dw_die_ref, dw_die_ref); | |
3634 | static void compute_section_prefix (dw_die_ref); | |
3635 | static int is_type_die (dw_die_ref); | |
3636 | static int is_comdat_die (dw_die_ref); | |
3637 | static int is_symbol_die (dw_die_ref); | |
3638 | static void assign_symbol_names (dw_die_ref); | |
3639 | static void break_out_includes (dw_die_ref); | |
3640 | static hashval_t htab_cu_hash (const void *); | |
3641 | static int htab_cu_eq (const void *, const void *); | |
3642 | static void htab_cu_del (void *); | |
3643 | static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *); | |
3644 | static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned); | |
3645 | static void add_sibling_attributes (dw_die_ref); | |
3646 | static void build_abbrev_table (dw_die_ref); | |
3647 | static void output_location_lists (dw_die_ref); | |
3648 | static int constant_size (long unsigned); | |
3649 | static unsigned long size_of_die (dw_die_ref); | |
3650 | static void calc_die_sizes (dw_die_ref); | |
3651 | static void mark_dies (dw_die_ref); | |
3652 | static void unmark_dies (dw_die_ref); | |
3653 | static void unmark_all_dies (dw_die_ref); | |
3654 | static unsigned long size_of_pubnames (void); | |
3655 | static unsigned long size_of_aranges (void); | |
3656 | static enum dwarf_form value_format (dw_attr_ref); | |
3657 | static void output_value_format (dw_attr_ref); | |
3658 | static void output_abbrev_section (void); | |
3659 | static void output_die_symbol (dw_die_ref); | |
3660 | static void output_die (dw_die_ref); | |
3661 | static void output_compilation_unit_header (void); | |
3662 | static void output_comp_unit (dw_die_ref, int); | |
3663 | static const char *dwarf2_name (tree, int); | |
3664 | static void add_pubname (tree, dw_die_ref); | |
3665 | static void output_pubnames (void); | |
3666 | static void add_arange (tree, dw_die_ref); | |
3667 | static void output_aranges (void); | |
3668 | static unsigned int add_ranges (tree); | |
3669 | static void output_ranges (void); | |
3670 | static void output_line_info (void); | |
3671 | static void output_file_names (void); | |
3672 | static dw_die_ref base_type_die (tree); | |
3673 | static tree root_type (tree); | |
3674 | static int is_base_type (tree); | |
3675 | static bool is_ada_subrange_type (tree); | |
3676 | static dw_die_ref subrange_type_die (tree); | |
3677 | static dw_die_ref modified_type_die (tree, int, int, dw_die_ref); | |
3678 | static int type_is_enum (tree); | |
3679 | static unsigned int reg_number (rtx); | |
3680 | static dw_loc_descr_ref reg_loc_descriptor (rtx); | |
3681 | static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int); | |
3682 | static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx); | |
3683 | static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT); | |
3684 | static dw_loc_descr_ref based_loc_descr (unsigned, long); | |
3685 | static int is_based_loc (rtx); | |
3686 | static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode); | |
3687 | static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx); | |
3688 | static dw_loc_descr_ref loc_descriptor (rtx); | |
3689 | static dw_loc_descr_ref loc_descriptor_from_tree (tree, int); | |
3690 | static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int); | |
3691 | static tree field_type (tree); | |
3692 | static unsigned int simple_type_align_in_bits (tree); | |
3693 | static unsigned int simple_decl_align_in_bits (tree); | |
3694 | static unsigned HOST_WIDE_INT simple_type_size_in_bits (tree); | |
3695 | static HOST_WIDE_INT field_byte_offset (tree); | |
3696 | static void add_AT_location_description (dw_die_ref, enum dwarf_attribute, | |
3697 | dw_loc_descr_ref); | |
3698 | static void add_data_member_location_attribute (dw_die_ref, tree); | |
3699 | static void add_const_value_attribute (dw_die_ref, rtx); | |
3700 | static rtx rtl_for_decl_location (tree); | |
3701 | static void add_location_or_const_value_attribute (dw_die_ref, tree); | |
3702 | static void tree_add_const_value_attribute (dw_die_ref, tree); | |
3703 | static void add_name_attribute (dw_die_ref, const char *); | |
3704 | static void add_comp_dir_attribute (dw_die_ref); | |
3705 | static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree); | |
3706 | static void add_subscript_info (dw_die_ref, tree); | |
3707 | static void add_byte_size_attribute (dw_die_ref, tree); | |
3708 | static void add_bit_offset_attribute (dw_die_ref, tree); | |
3709 | static void add_bit_size_attribute (dw_die_ref, tree); | |
3710 | static void add_prototyped_attribute (dw_die_ref, tree); | |
3711 | static void add_abstract_origin_attribute (dw_die_ref, tree); | |
3712 | static void add_pure_or_virtual_attribute (dw_die_ref, tree); | |
3713 | static void add_src_coords_attributes (dw_die_ref, tree); | |
3714 | static void add_name_and_src_coords_attributes (dw_die_ref, tree); | |
3715 | static void push_decl_scope (tree); | |
3716 | static void pop_decl_scope (void); | |
3717 | static dw_die_ref scope_die_for (tree, dw_die_ref); | |
3718 | static inline int local_scope_p (dw_die_ref); | |
3719 | static inline int class_scope_p (dw_die_ref); | |
3720 | static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref); | |
3721 | static const char *type_tag (tree); | |
3722 | static tree member_declared_type (tree); | |
7d9d8943 | 3723 | #if 0 |
7080f735 | 3724 | static const char *decl_start_label (tree); |
7d9d8943 | 3725 | #endif |
7080f735 AJ |
3726 | static void gen_array_type_die (tree, dw_die_ref); |
3727 | static void gen_set_type_die (tree, dw_die_ref); | |
7d9d8943 | 3728 | #if 0 |
7080f735 | 3729 | static void gen_entry_point_die (tree, dw_die_ref); |
7d9d8943 | 3730 | #endif |
7080f735 AJ |
3731 | static void gen_inlined_enumeration_type_die (tree, dw_die_ref); |
3732 | static void gen_inlined_structure_type_die (tree, dw_die_ref); | |
3733 | static void gen_inlined_union_type_die (tree, dw_die_ref); | |
3734 | static void gen_enumeration_type_die (tree, dw_die_ref); | |
3735 | static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref); | |
3736 | static void gen_unspecified_parameters_die (tree, dw_die_ref); | |
3737 | static void gen_formal_types_die (tree, dw_die_ref); | |
3738 | static void gen_subprogram_die (tree, dw_die_ref); | |
3739 | static void gen_variable_die (tree, dw_die_ref); | |
3740 | static void gen_label_die (tree, dw_die_ref); | |
3741 | static void gen_lexical_block_die (tree, dw_die_ref, int); | |
3742 | static void gen_inlined_subroutine_die (tree, dw_die_ref, int); | |
3743 | static void gen_field_die (tree, dw_die_ref); | |
3744 | static void gen_ptr_to_mbr_type_die (tree, dw_die_ref); | |
3745 | static dw_die_ref gen_compile_unit_die (const char *); | |
3746 | static void gen_string_type_die (tree, dw_die_ref); | |
3747 | static void gen_inheritance_die (tree, tree, dw_die_ref); | |
3748 | static void gen_member_die (tree, dw_die_ref); | |
3749 | static void gen_struct_or_union_type_die (tree, dw_die_ref); | |
3750 | static void gen_subroutine_type_die (tree, dw_die_ref); | |
3751 | static void gen_typedef_die (tree, dw_die_ref); | |
3752 | static void gen_type_die (tree, dw_die_ref); | |
3753 | static void gen_tagged_type_instantiation_die (tree, dw_die_ref); | |
3754 | static void gen_block_die (tree, dw_die_ref, int); | |
3755 | static void decls_for_scope (tree, dw_die_ref, int); | |
3756 | static int is_redundant_typedef (tree); | |
3757 | static void gen_decl_die (tree, dw_die_ref); | |
3758 | static unsigned lookup_filename (const char *); | |
3759 | static void init_file_table (void); | |
3760 | static void retry_incomplete_types (void); | |
3761 | static void gen_type_die_for_member (tree, tree, dw_die_ref); | |
3762 | static void splice_child_die (dw_die_ref, dw_die_ref); | |
3763 | static int file_info_cmp (const void *, const void *); | |
3764 | static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *, | |
3765 | const char *, const char *, unsigned); | |
3766 | static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref, | |
3767 | const char *, const char *, | |
3768 | const char *); | |
3769 | static void output_loc_list (dw_loc_list_ref); | |
3770 | static char *gen_internal_sym (const char *); | |
3771 | ||
3772 | static void prune_unmark_dies (dw_die_ref); | |
3773 | static void prune_unused_types_mark (dw_die_ref, int); | |
3774 | static void prune_unused_types_walk (dw_die_ref); | |
3775 | static void prune_unused_types_walk_attribs (dw_die_ref); | |
3776 | static void prune_unused_types_prune (dw_die_ref); | |
3777 | static void prune_unused_types (void); | |
3778 | static int maybe_emit_file (int); | |
73c68f61 | 3779 | |
7d9d8943 AM |
3780 | /* Section names used to hold DWARF debugging information. */ |
3781 | #ifndef DEBUG_INFO_SECTION | |
3782 | #define DEBUG_INFO_SECTION ".debug_info" | |
3783 | #endif | |
9d2f2c45 RH |
3784 | #ifndef DEBUG_ABBREV_SECTION |
3785 | #define DEBUG_ABBREV_SECTION ".debug_abbrev" | |
7d9d8943 | 3786 | #endif |
9d2f2c45 RH |
3787 | #ifndef DEBUG_ARANGES_SECTION |
3788 | #define DEBUG_ARANGES_SECTION ".debug_aranges" | |
7d9d8943 | 3789 | #endif |
9d2f2c45 RH |
3790 | #ifndef DEBUG_MACINFO_SECTION |
3791 | #define DEBUG_MACINFO_SECTION ".debug_macinfo" | |
7d9d8943 AM |
3792 | #endif |
3793 | #ifndef DEBUG_LINE_SECTION | |
3794 | #define DEBUG_LINE_SECTION ".debug_line" | |
3795 | #endif | |
9d2f2c45 RH |
3796 | #ifndef DEBUG_LOC_SECTION |
3797 | #define DEBUG_LOC_SECTION ".debug_loc" | |
7d9d8943 | 3798 | #endif |
9d2f2c45 RH |
3799 | #ifndef DEBUG_PUBNAMES_SECTION |
3800 | #define DEBUG_PUBNAMES_SECTION ".debug_pubnames" | |
7d9d8943 | 3801 | #endif |
9d2f2c45 RH |
3802 | #ifndef DEBUG_STR_SECTION |
3803 | #define DEBUG_STR_SECTION ".debug_str" | |
7d9d8943 | 3804 | #endif |
a20612aa RH |
3805 | #ifndef DEBUG_RANGES_SECTION |
3806 | #define DEBUG_RANGES_SECTION ".debug_ranges" | |
3807 | #endif | |
7d9d8943 AM |
3808 | |
3809 | /* Standard ELF section names for compiled code and data. */ | |
f99ffb60 RH |
3810 | #ifndef TEXT_SECTION_NAME |
3811 | #define TEXT_SECTION_NAME ".text" | |
7d9d8943 AM |
3812 | #endif |
3813 | ||
9eb4015a JJ |
3814 | /* Section flags for .debug_str section. */ |
3815 | #ifdef HAVE_GAS_SHF_MERGE | |
3816 | #define DEBUG_STR_SECTION_FLAGS \ | |
b0c242c0 AM |
3817 | (flag_merge_constants \ |
3818 | ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \ | |
3819 | : SECTION_DEBUG) | |
9eb4015a JJ |
3820 | #else |
3821 | #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG | |
3822 | #endif | |
3823 | ||
7d9d8943 | 3824 | /* Labels we insert at beginning sections we can reference instead of |
556273e0 | 3825 | the section names themselves. */ |
7d9d8943 AM |
3826 | |
3827 | #ifndef TEXT_SECTION_LABEL | |
9d2f2c45 | 3828 | #define TEXT_SECTION_LABEL "Ltext" |
7d9d8943 AM |
3829 | #endif |
3830 | #ifndef DEBUG_LINE_SECTION_LABEL | |
9d2f2c45 | 3831 | #define DEBUG_LINE_SECTION_LABEL "Ldebug_line" |
7d9d8943 AM |
3832 | #endif |
3833 | #ifndef DEBUG_INFO_SECTION_LABEL | |
9d2f2c45 | 3834 | #define DEBUG_INFO_SECTION_LABEL "Ldebug_info" |
7d9d8943 | 3835 | #endif |
9d2f2c45 RH |
3836 | #ifndef DEBUG_ABBREV_SECTION_LABEL |
3837 | #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev" | |
7d9d8943 | 3838 | #endif |
9d2f2c45 RH |
3839 | #ifndef DEBUG_LOC_SECTION_LABEL |
3840 | #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc" | |
63e46568 | 3841 | #endif |
2bee6045 JJ |
3842 | #ifndef DEBUG_RANGES_SECTION_LABEL |
3843 | #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges" | |
3844 | #endif | |
84a5b4f8 DB |
3845 | #ifndef DEBUG_MACINFO_SECTION_LABEL |
3846 | #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo" | |
3847 | #endif | |
a20612aa | 3848 | |
7d9d8943 AM |
3849 | /* Definitions of defaults for formats and names of various special |
3850 | (artificial) labels which may be generated within this file (when the -g | |
3851 | options is used and DWARF_DEBUGGING_INFO is in effect. | |
3852 | If necessary, these may be overridden from within the tm.h file, but | |
3853 | typically, overriding these defaults is unnecessary. */ | |
3854 | ||
3855 | static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3856 | static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3857 | static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3858 | static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3859 | static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
84a5b4f8 | 3860 | static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
63e46568 | 3861 | static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
2bee6045 | 3862 | static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES]; |
2ad9852d | 3863 | |
7d9d8943 AM |
3864 | #ifndef TEXT_END_LABEL |
3865 | #define TEXT_END_LABEL "Letext" | |
3866 | #endif | |
7d9d8943 AM |
3867 | #ifndef BLOCK_BEGIN_LABEL |
3868 | #define BLOCK_BEGIN_LABEL "LBB" | |
3869 | #endif | |
3870 | #ifndef BLOCK_END_LABEL | |
3871 | #define BLOCK_END_LABEL "LBE" | |
3872 | #endif | |
7d9d8943 AM |
3873 | #ifndef LINE_CODE_LABEL |
3874 | #define LINE_CODE_LABEL "LM" | |
3875 | #endif | |
3876 | #ifndef SEPARATE_LINE_CODE_LABEL | |
3877 | #define SEPARATE_LINE_CODE_LABEL "LSM" | |
3878 | #endif | |
3879 | \f | |
3880 | /* We allow a language front-end to designate a function that is to be | |
3881 | called to "demangle" any name before it it put into a DIE. */ | |
3882 | ||
7080f735 | 3883 | static const char *(*demangle_name_func) (const char *); |
7d9d8943 AM |
3884 | |
3885 | void | |
7080f735 | 3886 | dwarf2out_set_demangle_name_func (const char *(*func) (const char *)) |
7d9d8943 AM |
3887 | { |
3888 | demangle_name_func = func; | |
3889 | } | |
7d9d8943 AM |
3890 | |
3891 | /* Test if rtl node points to a pseudo register. */ | |
3892 | ||
3893 | static inline int | |
7080f735 | 3894 | is_pseudo_reg (rtx rtl) |
7d9d8943 AM |
3895 | { |
3896 | return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER) | |
3897 | || (GET_CODE (rtl) == SUBREG | |
ddef6bc7 | 3898 | && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)); |
7d9d8943 AM |
3899 | } |
3900 | ||
3901 | /* Return a reference to a type, with its const and volatile qualifiers | |
3902 | removed. */ | |
3903 | ||
3904 | static inline tree | |
7080f735 | 3905 | type_main_variant (tree type) |
7d9d8943 AM |
3906 | { |
3907 | type = TYPE_MAIN_VARIANT (type); | |
3908 | ||
2ad9852d RK |
3909 | /* ??? There really should be only one main variant among any group of |
3910 | variants of a given type (and all of the MAIN_VARIANT values for all | |
3911 | members of the group should point to that one type) but sometimes the C | |
3912 | front-end messes this up for array types, so we work around that bug | |
3913 | here. */ | |
7d9d8943 AM |
3914 | if (TREE_CODE (type) == ARRAY_TYPE) |
3915 | while (type != TYPE_MAIN_VARIANT (type)) | |
3916 | type = TYPE_MAIN_VARIANT (type); | |
3917 | ||
3918 | return type; | |
3919 | } | |
3920 | ||
cc2902df | 3921 | /* Return nonzero if the given type node represents a tagged type. */ |
7d9d8943 AM |
3922 | |
3923 | static inline int | |
7080f735 | 3924 | is_tagged_type (tree type) |
7d9d8943 | 3925 | { |
b3694847 | 3926 | enum tree_code code = TREE_CODE (type); |
7d9d8943 AM |
3927 | |
3928 | return (code == RECORD_TYPE || code == UNION_TYPE | |
3929 | || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); | |
3930 | } | |
3931 | ||
3932 | /* Convert a DIE tag into its string name. */ | |
3933 | ||
3934 | static const char * | |
7080f735 | 3935 | dwarf_tag_name (unsigned int tag) |
7d9d8943 AM |
3936 | { |
3937 | switch (tag) | |
3938 | { | |
3939 | case DW_TAG_padding: | |
3940 | return "DW_TAG_padding"; | |
3941 | case DW_TAG_array_type: | |
3942 | return "DW_TAG_array_type"; | |
3943 | case DW_TAG_class_type: | |
3944 | return "DW_TAG_class_type"; | |
3945 | case DW_TAG_entry_point: | |
3946 | return "DW_TAG_entry_point"; | |
3947 | case DW_TAG_enumeration_type: | |
3948 | return "DW_TAG_enumeration_type"; | |
3949 | case DW_TAG_formal_parameter: | |
3950 | return "DW_TAG_formal_parameter"; | |
3951 | case DW_TAG_imported_declaration: | |
3952 | return "DW_TAG_imported_declaration"; | |
3953 | case DW_TAG_label: | |
3954 | return "DW_TAG_label"; | |
3955 | case DW_TAG_lexical_block: | |
3956 | return "DW_TAG_lexical_block"; | |
3957 | case DW_TAG_member: | |
3958 | return "DW_TAG_member"; | |
3959 | case DW_TAG_pointer_type: | |
3960 | return "DW_TAG_pointer_type"; | |
3961 | case DW_TAG_reference_type: | |
3962 | return "DW_TAG_reference_type"; | |
3963 | case DW_TAG_compile_unit: | |
3964 | return "DW_TAG_compile_unit"; | |
3965 | case DW_TAG_string_type: | |
3966 | return "DW_TAG_string_type"; | |
3967 | case DW_TAG_structure_type: | |
3968 | return "DW_TAG_structure_type"; | |
3969 | case DW_TAG_subroutine_type: | |
3970 | return "DW_TAG_subroutine_type"; | |
3971 | case DW_TAG_typedef: | |
3972 | return "DW_TAG_typedef"; | |
3973 | case DW_TAG_union_type: | |
3974 | return "DW_TAG_union_type"; | |
3975 | case DW_TAG_unspecified_parameters: | |
3976 | return "DW_TAG_unspecified_parameters"; | |
3977 | case DW_TAG_variant: | |
3978 | return "DW_TAG_variant"; | |
3979 | case DW_TAG_common_block: | |
3980 | return "DW_TAG_common_block"; | |
3981 | case DW_TAG_common_inclusion: | |
3982 | return "DW_TAG_common_inclusion"; | |
3983 | case DW_TAG_inheritance: | |
3984 | return "DW_TAG_inheritance"; | |
3985 | case DW_TAG_inlined_subroutine: | |
3986 | return "DW_TAG_inlined_subroutine"; | |
3987 | case DW_TAG_module: | |
3988 | return "DW_TAG_module"; | |
3989 | case DW_TAG_ptr_to_member_type: | |
3990 | return "DW_TAG_ptr_to_member_type"; | |
3991 | case DW_TAG_set_type: | |
3992 | return "DW_TAG_set_type"; | |
3993 | case DW_TAG_subrange_type: | |
3994 | return "DW_TAG_subrange_type"; | |
3995 | case DW_TAG_with_stmt: | |
3996 | return "DW_TAG_with_stmt"; | |
3997 | case DW_TAG_access_declaration: | |
3998 | return "DW_TAG_access_declaration"; | |
3999 | case DW_TAG_base_type: | |
4000 | return "DW_TAG_base_type"; | |
4001 | case DW_TAG_catch_block: | |
4002 | return "DW_TAG_catch_block"; | |
4003 | case DW_TAG_const_type: | |
4004 | return "DW_TAG_const_type"; | |
4005 | case DW_TAG_constant: | |
4006 | return "DW_TAG_constant"; | |
4007 | case DW_TAG_enumerator: | |
4008 | return "DW_TAG_enumerator"; | |
4009 | case DW_TAG_file_type: | |
4010 | return "DW_TAG_file_type"; | |
4011 | case DW_TAG_friend: | |
4012 | return "DW_TAG_friend"; | |
4013 | case DW_TAG_namelist: | |
4014 | return "DW_TAG_namelist"; | |
4015 | case DW_TAG_namelist_item: | |
4016 | return "DW_TAG_namelist_item"; | |
4017 | case DW_TAG_packed_type: | |
4018 | return "DW_TAG_packed_type"; | |
4019 | case DW_TAG_subprogram: | |
4020 | return "DW_TAG_subprogram"; | |
4021 | case DW_TAG_template_type_param: | |
4022 | return "DW_TAG_template_type_param"; | |
4023 | case DW_TAG_template_value_param: | |
4024 | return "DW_TAG_template_value_param"; | |
4025 | case DW_TAG_thrown_type: | |
4026 | return "DW_TAG_thrown_type"; | |
4027 | case DW_TAG_try_block: | |
4028 | return "DW_TAG_try_block"; | |
4029 | case DW_TAG_variant_part: | |
4030 | return "DW_TAG_variant_part"; | |
4031 | case DW_TAG_variable: | |
4032 | return "DW_TAG_variable"; | |
4033 | case DW_TAG_volatile_type: | |
4034 | return "DW_TAG_volatile_type"; | |
4035 | case DW_TAG_MIPS_loop: | |
4036 | return "DW_TAG_MIPS_loop"; | |
4037 | case DW_TAG_format_label: | |
4038 | return "DW_TAG_format_label"; | |
4039 | case DW_TAG_function_template: | |
4040 | return "DW_TAG_function_template"; | |
4041 | case DW_TAG_class_template: | |
4042 | return "DW_TAG_class_template"; | |
881c6935 JM |
4043 | case DW_TAG_GNU_BINCL: |
4044 | return "DW_TAG_GNU_BINCL"; | |
4045 | case DW_TAG_GNU_EINCL: | |
4046 | return "DW_TAG_GNU_EINCL"; | |
7d9d8943 AM |
4047 | default: |
4048 | return "DW_TAG_<unknown>"; | |
4049 | } | |
4050 | } | |
4051 | ||
4052 | /* Convert a DWARF attribute code into its string name. */ | |
4053 | ||
4054 | static const char * | |
7080f735 | 4055 | dwarf_attr_name (unsigned int attr) |
7d9d8943 AM |
4056 | { |
4057 | switch (attr) | |
4058 | { | |
4059 | case DW_AT_sibling: | |
4060 | return "DW_AT_sibling"; | |
4061 | case DW_AT_location: | |
4062 | return "DW_AT_location"; | |
4063 | case DW_AT_name: | |
4064 | return "DW_AT_name"; | |
4065 | case DW_AT_ordering: | |
4066 | return "DW_AT_ordering"; | |
4067 | case DW_AT_subscr_data: | |
4068 | return "DW_AT_subscr_data"; | |
4069 | case DW_AT_byte_size: | |
4070 | return "DW_AT_byte_size"; | |
4071 | case DW_AT_bit_offset: | |
4072 | return "DW_AT_bit_offset"; | |
4073 | case DW_AT_bit_size: | |
4074 | return "DW_AT_bit_size"; | |
4075 | case DW_AT_element_list: | |
4076 | return "DW_AT_element_list"; | |
4077 | case DW_AT_stmt_list: | |
4078 | return "DW_AT_stmt_list"; | |
4079 | case DW_AT_low_pc: | |
4080 | return "DW_AT_low_pc"; | |
4081 | case DW_AT_high_pc: | |
4082 | return "DW_AT_high_pc"; | |
4083 | case DW_AT_language: | |
4084 | return "DW_AT_language"; | |
4085 | case DW_AT_member: | |
4086 | return "DW_AT_member"; | |
4087 | case DW_AT_discr: | |
4088 | return "DW_AT_discr"; | |
4089 | case DW_AT_discr_value: | |
4090 | return "DW_AT_discr_value"; | |
4091 | case DW_AT_visibility: | |
4092 | return "DW_AT_visibility"; | |
4093 | case DW_AT_import: | |
4094 | return "DW_AT_import"; | |
4095 | case DW_AT_string_length: | |
4096 | return "DW_AT_string_length"; | |
4097 | case DW_AT_common_reference: | |
4098 | return "DW_AT_common_reference"; | |
4099 | case DW_AT_comp_dir: | |
4100 | return "DW_AT_comp_dir"; | |
4101 | case DW_AT_const_value: | |
4102 | return "DW_AT_const_value"; | |
4103 | case DW_AT_containing_type: | |
4104 | return "DW_AT_containing_type"; | |
4105 | case DW_AT_default_value: | |
4106 | return "DW_AT_default_value"; | |
4107 | case DW_AT_inline: | |
4108 | return "DW_AT_inline"; | |
4109 | case DW_AT_is_optional: | |
4110 | return "DW_AT_is_optional"; | |
4111 | case DW_AT_lower_bound: | |
4112 | return "DW_AT_lower_bound"; | |
4113 | case DW_AT_producer: | |
4114 | return "DW_AT_producer"; | |
4115 | case DW_AT_prototyped: | |
4116 | return "DW_AT_prototyped"; | |
4117 | case DW_AT_return_addr: | |
4118 | return "DW_AT_return_addr"; | |
4119 | case DW_AT_start_scope: | |
4120 | return "DW_AT_start_scope"; | |
4121 | case DW_AT_stride_size: | |
4122 | return "DW_AT_stride_size"; | |
4123 | case DW_AT_upper_bound: | |
4124 | return "DW_AT_upper_bound"; | |
4125 | case DW_AT_abstract_origin: | |
4126 | return "DW_AT_abstract_origin"; | |
4127 | case DW_AT_accessibility: | |
4128 | return "DW_AT_accessibility"; | |
4129 | case DW_AT_address_class: | |
4130 | return "DW_AT_address_class"; | |
4131 | case DW_AT_artificial: | |
4132 | return "DW_AT_artificial"; | |
4133 | case DW_AT_base_types: | |
4134 | return "DW_AT_base_types"; | |
4135 | case DW_AT_calling_convention: | |
4136 | return "DW_AT_calling_convention"; | |
4137 | case DW_AT_count: | |
4138 | return "DW_AT_count"; | |
4139 | case DW_AT_data_member_location: | |
4140 | return "DW_AT_data_member_location"; | |
4141 | case DW_AT_decl_column: | |
4142 | return "DW_AT_decl_column"; | |
4143 | case DW_AT_decl_file: | |
4144 | return "DW_AT_decl_file"; | |
4145 | case DW_AT_decl_line: | |
4146 | return "DW_AT_decl_line"; | |
4147 | case DW_AT_declaration: | |
4148 | return "DW_AT_declaration"; | |
4149 | case DW_AT_discr_list: | |
4150 | return "DW_AT_discr_list"; | |
4151 | case DW_AT_encoding: | |
4152 | return "DW_AT_encoding"; | |
4153 | case DW_AT_external: | |
4154 | return "DW_AT_external"; | |
4155 | case DW_AT_frame_base: | |
4156 | return "DW_AT_frame_base"; | |
4157 | case DW_AT_friend: | |
4158 | return "DW_AT_friend"; | |
4159 | case DW_AT_identifier_case: | |
4160 | return "DW_AT_identifier_case"; | |
4161 | case DW_AT_macro_info: | |
4162 | return "DW_AT_macro_info"; | |
4163 | case DW_AT_namelist_items: | |
4164 | return "DW_AT_namelist_items"; | |
4165 | case DW_AT_priority: | |
4166 | return "DW_AT_priority"; | |
4167 | case DW_AT_segment: | |
4168 | return "DW_AT_segment"; | |
4169 | case DW_AT_specification: | |
4170 | return "DW_AT_specification"; | |
4171 | case DW_AT_static_link: | |
4172 | return "DW_AT_static_link"; | |
4173 | case DW_AT_type: | |
4174 | return "DW_AT_type"; | |
4175 | case DW_AT_use_location: | |
4176 | return "DW_AT_use_location"; | |
4177 | case DW_AT_variable_parameter: | |
4178 | return "DW_AT_variable_parameter"; | |
4179 | case DW_AT_virtuality: | |
4180 | return "DW_AT_virtuality"; | |
4181 | case DW_AT_vtable_elem_location: | |
4182 | return "DW_AT_vtable_elem_location"; | |
4183 | ||
a20612aa RH |
4184 | case DW_AT_allocated: |
4185 | return "DW_AT_allocated"; | |
4186 | case DW_AT_associated: | |
4187 | return "DW_AT_associated"; | |
4188 | case DW_AT_data_location: | |
4189 | return "DW_AT_data_location"; | |
4190 | case DW_AT_stride: | |
4191 | return "DW_AT_stride"; | |
4192 | case DW_AT_entry_pc: | |
4193 | return "DW_AT_entry_pc"; | |
4194 | case DW_AT_use_UTF8: | |
4195 | return "DW_AT_use_UTF8"; | |
4196 | case DW_AT_extension: | |
4197 | return "DW_AT_extension"; | |
4198 | case DW_AT_ranges: | |
4199 | return "DW_AT_ranges"; | |
4200 | case DW_AT_trampoline: | |
4201 | return "DW_AT_trampoline"; | |
4202 | case DW_AT_call_column: | |
4203 | return "DW_AT_call_column"; | |
4204 | case DW_AT_call_file: | |
4205 | return "DW_AT_call_file"; | |
4206 | case DW_AT_call_line: | |
4207 | return "DW_AT_call_line"; | |
4208 | ||
7d9d8943 AM |
4209 | case DW_AT_MIPS_fde: |
4210 | return "DW_AT_MIPS_fde"; | |
4211 | case DW_AT_MIPS_loop_begin: | |
4212 | return "DW_AT_MIPS_loop_begin"; | |
4213 | case DW_AT_MIPS_tail_loop_begin: | |
4214 | return "DW_AT_MIPS_tail_loop_begin"; | |
4215 | case DW_AT_MIPS_epilog_begin: | |
4216 | return "DW_AT_MIPS_epilog_begin"; | |
4217 | case DW_AT_MIPS_loop_unroll_factor: | |
4218 | return "DW_AT_MIPS_loop_unroll_factor"; | |
4219 | case DW_AT_MIPS_software_pipeline_depth: | |
4220 | return "DW_AT_MIPS_software_pipeline_depth"; | |
4221 | case DW_AT_MIPS_linkage_name: | |
4222 | return "DW_AT_MIPS_linkage_name"; | |
4223 | case DW_AT_MIPS_stride: | |
4224 | return "DW_AT_MIPS_stride"; | |
4225 | case DW_AT_MIPS_abstract_name: | |
4226 | return "DW_AT_MIPS_abstract_name"; | |
4227 | case DW_AT_MIPS_clone_origin: | |
4228 | return "DW_AT_MIPS_clone_origin"; | |
4229 | case DW_AT_MIPS_has_inlines: | |
4230 | return "DW_AT_MIPS_has_inlines"; | |
4231 | ||
4232 | case DW_AT_sf_names: | |
4233 | return "DW_AT_sf_names"; | |
4234 | case DW_AT_src_info: | |
4235 | return "DW_AT_src_info"; | |
4236 | case DW_AT_mac_info: | |
4237 | return "DW_AT_mac_info"; | |
4238 | case DW_AT_src_coords: | |
4239 | return "DW_AT_src_coords"; | |
4240 | case DW_AT_body_begin: | |
4241 | return "DW_AT_body_begin"; | |
4242 | case DW_AT_body_end: | |
4243 | return "DW_AT_body_end"; | |
84f0ace0 JM |
4244 | case DW_AT_GNU_vector: |
4245 | return "DW_AT_GNU_vector"; | |
4246 | ||
7a0c8d71 DR |
4247 | case DW_AT_VMS_rtnbeg_pd_address: |
4248 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
4249 | ||
7d9d8943 AM |
4250 | default: |
4251 | return "DW_AT_<unknown>"; | |
4252 | } | |
4253 | } | |
4254 | ||
4255 | /* Convert a DWARF value form code into its string name. */ | |
4256 | ||
4257 | static const char * | |
7080f735 | 4258 | dwarf_form_name (unsigned int form) |
7d9d8943 AM |
4259 | { |
4260 | switch (form) | |
4261 | { | |
4262 | case DW_FORM_addr: | |
4263 | return "DW_FORM_addr"; | |
4264 | case DW_FORM_block2: | |
4265 | return "DW_FORM_block2"; | |
4266 | case DW_FORM_block4: | |
4267 | return "DW_FORM_block4"; | |
4268 | case DW_FORM_data2: | |
4269 | return "DW_FORM_data2"; | |
4270 | case DW_FORM_data4: | |
4271 | return "DW_FORM_data4"; | |
4272 | case DW_FORM_data8: | |
4273 | return "DW_FORM_data8"; | |
4274 | case DW_FORM_string: | |
4275 | return "DW_FORM_string"; | |
4276 | case DW_FORM_block: | |
4277 | return "DW_FORM_block"; | |
4278 | case DW_FORM_block1: | |
4279 | return "DW_FORM_block1"; | |
4280 | case DW_FORM_data1: | |
4281 | return "DW_FORM_data1"; | |
4282 | case DW_FORM_flag: | |
4283 | return "DW_FORM_flag"; | |
4284 | case DW_FORM_sdata: | |
4285 | return "DW_FORM_sdata"; | |
4286 | case DW_FORM_strp: | |
4287 | return "DW_FORM_strp"; | |
4288 | case DW_FORM_udata: | |
4289 | return "DW_FORM_udata"; | |
4290 | case DW_FORM_ref_addr: | |
4291 | return "DW_FORM_ref_addr"; | |
4292 | case DW_FORM_ref1: | |
4293 | return "DW_FORM_ref1"; | |
4294 | case DW_FORM_ref2: | |
4295 | return "DW_FORM_ref2"; | |
4296 | case DW_FORM_ref4: | |
4297 | return "DW_FORM_ref4"; | |
4298 | case DW_FORM_ref8: | |
4299 | return "DW_FORM_ref8"; | |
4300 | case DW_FORM_ref_udata: | |
4301 | return "DW_FORM_ref_udata"; | |
4302 | case DW_FORM_indirect: | |
4303 | return "DW_FORM_indirect"; | |
3f76745e | 4304 | default: |
7d9d8943 | 4305 | return "DW_FORM_<unknown>"; |
a3f97cbb JW |
4306 | } |
4307 | } | |
4308 | ||
3f76745e | 4309 | /* Convert a DWARF type code into its string name. */ |
71dfc51f | 4310 | |
487a6e06 | 4311 | #if 0 |
d560ee52 | 4312 | static const char * |
7080f735 | 4313 | dwarf_type_encoding_name (unsigned enc) |
a3f97cbb | 4314 | { |
3f76745e | 4315 | switch (enc) |
a3f97cbb | 4316 | { |
3f76745e JM |
4317 | case DW_ATE_address: |
4318 | return "DW_ATE_address"; | |
4319 | case DW_ATE_boolean: | |
4320 | return "DW_ATE_boolean"; | |
4321 | case DW_ATE_complex_float: | |
4322 | return "DW_ATE_complex_float"; | |
4323 | case DW_ATE_float: | |
4324 | return "DW_ATE_float"; | |
4325 | case DW_ATE_signed: | |
4326 | return "DW_ATE_signed"; | |
4327 | case DW_ATE_signed_char: | |
4328 | return "DW_ATE_signed_char"; | |
4329 | case DW_ATE_unsigned: | |
4330 | return "DW_ATE_unsigned"; | |
4331 | case DW_ATE_unsigned_char: | |
4332 | return "DW_ATE_unsigned_char"; | |
4333 | default: | |
4334 | return "DW_ATE_<unknown>"; | |
4335 | } | |
a3f97cbb | 4336 | } |
487a6e06 | 4337 | #endif |
3f76745e JM |
4338 | \f |
4339 | /* Determine the "ultimate origin" of a decl. The decl may be an inlined | |
4340 | instance of an inlined instance of a decl which is local to an inline | |
4341 | function, so we have to trace all of the way back through the origin chain | |
4342 | to find out what sort of node actually served as the original seed for the | |
4343 | given block. */ | |
a3f97cbb | 4344 | |
3f76745e | 4345 | static tree |
7080f735 | 4346 | decl_ultimate_origin (tree decl) |
a3f97cbb | 4347 | { |
10a11b75 JM |
4348 | /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the |
4349 | nodes in the function to point to themselves; ignore that if | |
4350 | we're trying to output the abstract instance of this function. */ | |
4351 | if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl) | |
4352 | return NULL_TREE; | |
4353 | ||
556273e0 | 4354 | #ifdef ENABLE_CHECKING |
02e24c7a MM |
4355 | if (DECL_FROM_INLINE (DECL_ORIGIN (decl))) |
4356 | /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the | |
4357 | most distant ancestor, this should never happen. */ | |
4358 | abort (); | |
4359 | #endif | |
3f76745e | 4360 | |
02e24c7a | 4361 | return DECL_ABSTRACT_ORIGIN (decl); |
a3f97cbb JW |
4362 | } |
4363 | ||
3f76745e JM |
4364 | /* Determine the "ultimate origin" of a block. The block may be an inlined |
4365 | instance of an inlined instance of a block which is local to an inline | |
4366 | function, so we have to trace all of the way back through the origin chain | |
4367 | to find out what sort of node actually served as the original seed for the | |
4368 | given block. */ | |
71dfc51f | 4369 | |
3f76745e | 4370 | static tree |
7080f735 | 4371 | block_ultimate_origin (tree block) |
a3f97cbb | 4372 | { |
b3694847 | 4373 | tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); |
71dfc51f | 4374 | |
10a11b75 JM |
4375 | /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the |
4376 | nodes in the function to point to themselves; ignore that if | |
4377 | we're trying to output the abstract instance of this function. */ | |
4378 | if (BLOCK_ABSTRACT (block) && immediate_origin == block) | |
4379 | return NULL_TREE; | |
4380 | ||
3f76745e JM |
4381 | if (immediate_origin == NULL_TREE) |
4382 | return NULL_TREE; | |
4383 | else | |
4384 | { | |
b3694847 SS |
4385 | tree ret_val; |
4386 | tree lookahead = immediate_origin; | |
71dfc51f | 4387 | |
3f76745e JM |
4388 | do |
4389 | { | |
4390 | ret_val = lookahead; | |
2ad9852d RK |
4391 | lookahead = (TREE_CODE (ret_val) == BLOCK |
4392 | ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL); | |
3f76745e JM |
4393 | } |
4394 | while (lookahead != NULL && lookahead != ret_val); | |
4395 | ||
4396 | return ret_val; | |
4397 | } | |
a3f97cbb JW |
4398 | } |
4399 | ||
3f76745e JM |
4400 | /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT |
4401 | of a virtual function may refer to a base class, so we check the 'this' | |
4402 | parameter. */ | |
71dfc51f | 4403 | |
3f76745e | 4404 | static tree |
7080f735 | 4405 | decl_class_context (tree decl) |
a3f97cbb | 4406 | { |
3f76745e | 4407 | tree context = NULL_TREE; |
71dfc51f | 4408 | |
3f76745e JM |
4409 | if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl)) |
4410 | context = DECL_CONTEXT (decl); | |
4411 | else | |
4412 | context = TYPE_MAIN_VARIANT | |
4413 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
71dfc51f | 4414 | |
2f939d94 | 4415 | if (context && !TYPE_P (context)) |
3f76745e JM |
4416 | context = NULL_TREE; |
4417 | ||
4418 | return context; | |
a3f97cbb JW |
4419 | } |
4420 | \f | |
a96c67ec | 4421 | /* Add an attribute/value pair to a DIE. We build the lists up in reverse |
881c6935 | 4422 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f RK |
4423 | |
4424 | static inline void | |
7080f735 | 4425 | add_dwarf_attr (dw_die_ref die, dw_attr_ref attr) |
a3f97cbb | 4426 | { |
3f76745e | 4427 | if (die != NULL && attr != NULL) |
a3f97cbb | 4428 | { |
a96c67ec JM |
4429 | attr->dw_attr_next = die->die_attr; |
4430 | die->die_attr = attr; | |
a3f97cbb JW |
4431 | } |
4432 | } | |
4433 | ||
17211ab5 | 4434 | static inline enum dw_val_class |
7080f735 | 4435 | AT_class (dw_attr_ref a) |
a96c67ec JM |
4436 | { |
4437 | return a->dw_attr_val.val_class; | |
4438 | } | |
4439 | ||
3f76745e | 4440 | /* Add a flag value attribute to a DIE. */ |
71dfc51f | 4441 | |
3f76745e | 4442 | static inline void |
7080f735 | 4443 | add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag) |
a3f97cbb | 4444 | { |
703ad42b | 4445 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
71dfc51f | 4446 | |
3f76745e JM |
4447 | attr->dw_attr_next = NULL; |
4448 | attr->dw_attr = attr_kind; | |
4449 | attr->dw_attr_val.val_class = dw_val_class_flag; | |
4450 | attr->dw_attr_val.v.val_flag = flag; | |
4451 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4452 | } |
4453 | ||
a96c67ec | 4454 | static inline unsigned |
7080f735 | 4455 | AT_flag (dw_attr_ref a) |
a96c67ec JM |
4456 | { |
4457 | if (a && AT_class (a) == dw_val_class_flag) | |
4458 | return a->dw_attr_val.v.val_flag; | |
4459 | ||
40e8cc95 | 4460 | abort (); |
a96c67ec JM |
4461 | } |
4462 | ||
3f76745e | 4463 | /* Add a signed integer attribute value to a DIE. */ |
71dfc51f | 4464 | |
3f76745e | 4465 | static inline void |
7080f735 | 4466 | add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, long int int_val) |
a3f97cbb | 4467 | { |
703ad42b | 4468 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
3f76745e JM |
4469 | |
4470 | attr->dw_attr_next = NULL; | |
4471 | attr->dw_attr = attr_kind; | |
4472 | attr->dw_attr_val.val_class = dw_val_class_const; | |
4473 | attr->dw_attr_val.v.val_int = int_val; | |
4474 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4475 | } |
4476 | ||
a96c67ec | 4477 | static inline long int |
7080f735 | 4478 | AT_int (dw_attr_ref a) |
a96c67ec JM |
4479 | { |
4480 | if (a && AT_class (a) == dw_val_class_const) | |
4481 | return a->dw_attr_val.v.val_int; | |
4482 | ||
40e8cc95 | 4483 | abort (); |
a96c67ec JM |
4484 | } |
4485 | ||
3f76745e | 4486 | /* Add an unsigned integer attribute value to a DIE. */ |
71dfc51f | 4487 | |
3f76745e | 4488 | static inline void |
7080f735 AJ |
4489 | add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind, |
4490 | long unsigned int unsigned_val) | |
a3f97cbb | 4491 | { |
703ad42b | 4492 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
3f76745e JM |
4493 | |
4494 | attr->dw_attr_next = NULL; | |
4495 | attr->dw_attr = attr_kind; | |
4496 | attr->dw_attr_val.val_class = dw_val_class_unsigned_const; | |
4497 | attr->dw_attr_val.v.val_unsigned = unsigned_val; | |
4498 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4499 | } |
71dfc51f | 4500 | |
a96c67ec | 4501 | static inline unsigned long |
7080f735 | 4502 | AT_unsigned (dw_attr_ref a) |
a96c67ec JM |
4503 | { |
4504 | if (a && AT_class (a) == dw_val_class_unsigned_const) | |
4505 | return a->dw_attr_val.v.val_unsigned; | |
4506 | ||
40e8cc95 | 4507 | abort (); |
a96c67ec JM |
4508 | } |
4509 | ||
3f76745e JM |
4510 | /* Add an unsigned double integer attribute value to a DIE. */ |
4511 | ||
4512 | static inline void | |
7080f735 AJ |
4513 | add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind, |
4514 | long unsigned int val_hi, long unsigned int val_low) | |
a3f97cbb | 4515 | { |
703ad42b | 4516 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
71dfc51f | 4517 | |
3f76745e JM |
4518 | attr->dw_attr_next = NULL; |
4519 | attr->dw_attr = attr_kind; | |
4520 | attr->dw_attr_val.val_class = dw_val_class_long_long; | |
4521 | attr->dw_attr_val.v.val_long_long.hi = val_hi; | |
4522 | attr->dw_attr_val.v.val_long_long.low = val_low; | |
4523 | add_dwarf_attr (die, attr); | |
4524 | } | |
71dfc51f | 4525 | |
3f76745e | 4526 | /* Add a floating point attribute value to a DIE and return it. */ |
71dfc51f | 4527 | |
3f76745e | 4528 | static inline void |
7080f735 AJ |
4529 | add_AT_float (dw_die_ref die, enum dwarf_attribute attr_kind, |
4530 | unsigned int length, long int *array) | |
3f76745e | 4531 | { |
703ad42b | 4532 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
3f76745e JM |
4533 | |
4534 | attr->dw_attr_next = NULL; | |
4535 | attr->dw_attr = attr_kind; | |
4536 | attr->dw_attr_val.val_class = dw_val_class_float; | |
4537 | attr->dw_attr_val.v.val_float.length = length; | |
4538 | attr->dw_attr_val.v.val_float.array = array; | |
4539 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4540 | } |
4541 | ||
17211ab5 GK |
4542 | /* Hash and equality functions for debug_str_hash. */ |
4543 | ||
4544 | static hashval_t | |
7080f735 | 4545 | debug_str_do_hash (const void *x) |
17211ab5 GK |
4546 | { |
4547 | return htab_hash_string (((const struct indirect_string_node *)x)->str); | |
4548 | } | |
4549 | ||
4550 | static int | |
7080f735 | 4551 | debug_str_eq (const void *x1, const void *x2) |
17211ab5 GK |
4552 | { |
4553 | return strcmp ((((const struct indirect_string_node *)x1)->str), | |
4554 | (const char *)x2) == 0; | |
4555 | } | |
4556 | ||
3f76745e | 4557 | /* Add a string attribute value to a DIE. */ |
71dfc51f | 4558 | |
3f76745e | 4559 | static inline void |
7080f735 | 4560 | add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str) |
a3f97cbb | 4561 | { |
703ad42b | 4562 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
9eb4015a | 4563 | struct indirect_string_node *node; |
fad205ff | 4564 | void **slot; |
c26fbbca | 4565 | |
9eb4015a | 4566 | if (! debug_str_hash) |
7080f735 | 4567 | debug_str_hash = htab_create_ggc (10, debug_str_do_hash, |
17211ab5 GK |
4568 | debug_str_eq, NULL); |
4569 | ||
4570 | slot = htab_find_slot_with_hash (debug_str_hash, str, | |
4571 | htab_hash_string (str), INSERT); | |
4572 | if (*slot == NULL) | |
4573 | *slot = ggc_alloc_cleared (sizeof (struct indirect_string_node)); | |
4574 | node = (struct indirect_string_node *) *slot; | |
485bad26 | 4575 | node->str = ggc_strdup (str); |
9eb4015a | 4576 | node->refcount++; |
71dfc51f | 4577 | |
3f76745e JM |
4578 | attr->dw_attr_next = NULL; |
4579 | attr->dw_attr = attr_kind; | |
4580 | attr->dw_attr_val.val_class = dw_val_class_str; | |
9eb4015a | 4581 | attr->dw_attr_val.v.val_str = node; |
3f76745e JM |
4582 | add_dwarf_attr (die, attr); |
4583 | } | |
71dfc51f | 4584 | |
a96c67ec | 4585 | static inline const char * |
7080f735 | 4586 | AT_string (dw_attr_ref a) |
a96c67ec JM |
4587 | { |
4588 | if (a && AT_class (a) == dw_val_class_str) | |
17211ab5 | 4589 | return a->dw_attr_val.v.val_str->str; |
9eb4015a JJ |
4590 | |
4591 | abort (); | |
4592 | } | |
4593 | ||
4594 | /* Find out whether a string should be output inline in DIE | |
4595 | or out-of-line in .debug_str section. */ | |
4596 | ||
9eb4015a | 4597 | static int |
7080f735 | 4598 | AT_string_form (dw_attr_ref a) |
9eb4015a JJ |
4599 | { |
4600 | if (a && AT_class (a) == dw_val_class_str) | |
4601 | { | |
4602 | struct indirect_string_node *node; | |
4603 | unsigned int len; | |
9eb4015a JJ |
4604 | char label[32]; |
4605 | ||
4606 | node = a->dw_attr_val.v.val_str; | |
4607 | if (node->form) | |
4608 | return node->form; | |
4609 | ||
17211ab5 | 4610 | len = strlen (node->str) + 1; |
9eb4015a | 4611 | |
2ad9852d RK |
4612 | /* If the string is shorter or equal to the size of the reference, it is |
4613 | always better to put it inline. */ | |
9eb4015a JJ |
4614 | if (len <= DWARF_OFFSET_SIZE || node->refcount == 0) |
4615 | return node->form = DW_FORM_string; | |
4616 | ||
2ad9852d RK |
4617 | /* If we cannot expect the linker to merge strings in .debug_str |
4618 | section, only put it into .debug_str if it is worth even in this | |
4619 | single module. */ | |
4620 | if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0 | |
4621 | && (len - DWARF_OFFSET_SIZE) * node->refcount <= len) | |
4622 | return node->form = DW_FORM_string; | |
9eb4015a | 4623 | |
17211ab5 GK |
4624 | ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter); |
4625 | ++dw2_string_counter; | |
9eb4015a | 4626 | node->label = xstrdup (label); |
2ad9852d | 4627 | |
9eb4015a JJ |
4628 | return node->form = DW_FORM_strp; |
4629 | } | |
a96c67ec | 4630 | |
40e8cc95 | 4631 | abort (); |
a96c67ec JM |
4632 | } |
4633 | ||
3f76745e | 4634 | /* Add a DIE reference attribute value to a DIE. */ |
71dfc51f | 4635 | |
3f76745e | 4636 | static inline void |
7080f735 | 4637 | add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die) |
3f76745e | 4638 | { |
703ad42b | 4639 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
71dfc51f | 4640 | |
3f76745e JM |
4641 | attr->dw_attr_next = NULL; |
4642 | attr->dw_attr = attr_kind; | |
4643 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
881c6935 JM |
4644 | attr->dw_attr_val.v.val_die_ref.die = targ_die; |
4645 | attr->dw_attr_val.v.val_die_ref.external = 0; | |
3f76745e JM |
4646 | add_dwarf_attr (die, attr); |
4647 | } | |
b1ccbc24 | 4648 | |
a96c67ec | 4649 | static inline dw_die_ref |
7080f735 | 4650 | AT_ref (dw_attr_ref a) |
a96c67ec JM |
4651 | { |
4652 | if (a && AT_class (a) == dw_val_class_die_ref) | |
881c6935 | 4653 | return a->dw_attr_val.v.val_die_ref.die; |
a96c67ec | 4654 | |
40e8cc95 | 4655 | abort (); |
a96c67ec JM |
4656 | } |
4657 | ||
881c6935 | 4658 | static inline int |
7080f735 | 4659 | AT_ref_external (dw_attr_ref a) |
881c6935 JM |
4660 | { |
4661 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4662 | return a->dw_attr_val.v.val_die_ref.external; | |
4663 | ||
4664 | return 0; | |
4665 | } | |
4666 | ||
881c6935 | 4667 | static inline void |
7080f735 | 4668 | set_AT_ref_external (dw_attr_ref a, int i) |
881c6935 JM |
4669 | { |
4670 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4671 | a->dw_attr_val.v.val_die_ref.external = i; | |
4672 | else | |
4673 | abort (); | |
4674 | } | |
4675 | ||
3f76745e | 4676 | /* Add an FDE reference attribute value to a DIE. */ |
b1ccbc24 | 4677 | |
3f76745e | 4678 | static inline void |
7080f735 | 4679 | add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde) |
3f76745e | 4680 | { |
703ad42b | 4681 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
b1ccbc24 | 4682 | |
3f76745e JM |
4683 | attr->dw_attr_next = NULL; |
4684 | attr->dw_attr = attr_kind; | |
4685 | attr->dw_attr_val.val_class = dw_val_class_fde_ref; | |
4686 | attr->dw_attr_val.v.val_fde_index = targ_fde; | |
4687 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4688 | } |
71dfc51f | 4689 | |
3f76745e | 4690 | /* Add a location description attribute value to a DIE. */ |
71dfc51f | 4691 | |
3f76745e | 4692 | static inline void |
7080f735 | 4693 | add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc) |
3f76745e | 4694 | { |
703ad42b | 4695 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
71dfc51f | 4696 | |
3f76745e JM |
4697 | attr->dw_attr_next = NULL; |
4698 | attr->dw_attr = attr_kind; | |
4699 | attr->dw_attr_val.val_class = dw_val_class_loc; | |
4700 | attr->dw_attr_val.v.val_loc = loc; | |
4701 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4702 | } |
4703 | ||
a96c67ec | 4704 | static inline dw_loc_descr_ref |
7080f735 | 4705 | AT_loc (dw_attr_ref a) |
a96c67ec JM |
4706 | { |
4707 | if (a && AT_class (a) == dw_val_class_loc) | |
4708 | return a->dw_attr_val.v.val_loc; | |
4709 | ||
40e8cc95 | 4710 | abort (); |
a96c67ec JM |
4711 | } |
4712 | ||
63e46568 | 4713 | static inline void |
7080f735 | 4714 | add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list) |
63e46568 | 4715 | { |
703ad42b | 4716 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
63e46568 DB |
4717 | |
4718 | attr->dw_attr_next = NULL; | |
4719 | attr->dw_attr = attr_kind; | |
4720 | attr->dw_attr_val.val_class = dw_val_class_loc_list; | |
4721 | attr->dw_attr_val.v.val_loc_list = loc_list; | |
4722 | add_dwarf_attr (die, attr); | |
4723 | have_location_lists = 1; | |
4724 | } | |
4725 | ||
63e46568 | 4726 | static inline dw_loc_list_ref |
7080f735 | 4727 | AT_loc_list (dw_attr_ref a) |
63e46568 DB |
4728 | { |
4729 | if (a && AT_class (a) == dw_val_class_loc_list) | |
4730 | return a->dw_attr_val.v.val_loc_list; | |
4731 | ||
4732 | abort (); | |
4733 | } | |
4734 | ||
3f76745e | 4735 | /* Add an address constant attribute value to a DIE. */ |
71dfc51f | 4736 | |
3f76745e | 4737 | static inline void |
7080f735 | 4738 | add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr) |
a3f97cbb | 4739 | { |
703ad42b | 4740 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
71dfc51f | 4741 | |
3f76745e JM |
4742 | attr->dw_attr_next = NULL; |
4743 | attr->dw_attr = attr_kind; | |
4744 | attr->dw_attr_val.val_class = dw_val_class_addr; | |
4745 | attr->dw_attr_val.v.val_addr = addr; | |
4746 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4747 | } |
4748 | ||
1865dbb5 | 4749 | static inline rtx |
7080f735 | 4750 | AT_addr (dw_attr_ref a) |
a96c67ec JM |
4751 | { |
4752 | if (a && AT_class (a) == dw_val_class_addr) | |
4753 | return a->dw_attr_val.v.val_addr; | |
4754 | ||
40e8cc95 | 4755 | abort (); |
a96c67ec JM |
4756 | } |
4757 | ||
3f76745e | 4758 | /* Add a label identifier attribute value to a DIE. */ |
71dfc51f | 4759 | |
3f76745e | 4760 | static inline void |
7080f735 | 4761 | add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id) |
a3f97cbb | 4762 | { |
703ad42b | 4763 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
71dfc51f | 4764 | |
3f76745e JM |
4765 | attr->dw_attr_next = NULL; |
4766 | attr->dw_attr = attr_kind; | |
4767 | attr->dw_attr_val.val_class = dw_val_class_lbl_id; | |
4768 | attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); | |
4769 | add_dwarf_attr (die, attr); | |
4770 | } | |
71dfc51f | 4771 | |
3f76745e JM |
4772 | /* Add a section offset attribute value to a DIE. */ |
4773 | ||
4774 | static inline void | |
7080f735 | 4775 | add_AT_lbl_offset (dw_die_ref die, enum dwarf_attribute attr_kind, const char *label) |
3f76745e | 4776 | { |
703ad42b | 4777 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
71dfc51f | 4778 | |
3f76745e JM |
4779 | attr->dw_attr_next = NULL; |
4780 | attr->dw_attr = attr_kind; | |
8b790721 | 4781 | attr->dw_attr_val.val_class = dw_val_class_lbl_offset; |
a96c67ec | 4782 | attr->dw_attr_val.v.val_lbl_id = xstrdup (label); |
3f76745e | 4783 | add_dwarf_attr (die, attr); |
a3f97cbb JW |
4784 | } |
4785 | ||
a20612aa RH |
4786 | /* Add an offset attribute value to a DIE. */ |
4787 | ||
2bee6045 | 4788 | static inline void |
7080f735 | 4789 | add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind, long unsigned int offset) |
a20612aa | 4790 | { |
703ad42b | 4791 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
a20612aa RH |
4792 | |
4793 | attr->dw_attr_next = NULL; | |
4794 | attr->dw_attr = attr_kind; | |
4795 | attr->dw_attr_val.val_class = dw_val_class_offset; | |
4796 | attr->dw_attr_val.v.val_offset = offset; | |
4797 | add_dwarf_attr (die, attr); | |
4798 | } | |
4799 | ||
2bee6045 JJ |
4800 | /* Add an range_list attribute value to a DIE. */ |
4801 | ||
4802 | static void | |
7080f735 AJ |
4803 | add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind, |
4804 | long unsigned int offset) | |
2bee6045 | 4805 | { |
703ad42b | 4806 | dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node)); |
2bee6045 JJ |
4807 | |
4808 | attr->dw_attr_next = NULL; | |
4809 | attr->dw_attr = attr_kind; | |
4810 | attr->dw_attr_val.val_class = dw_val_class_range_list; | |
4811 | attr->dw_attr_val.v.val_offset = offset; | |
4812 | add_dwarf_attr (die, attr); | |
4813 | } | |
4814 | ||
a96c67ec | 4815 | static inline const char * |
7080f735 | 4816 | AT_lbl (dw_attr_ref a) |
a3f97cbb | 4817 | { |
a96c67ec JM |
4818 | if (a && (AT_class (a) == dw_val_class_lbl_id |
4819 | || AT_class (a) == dw_val_class_lbl_offset)) | |
4820 | return a->dw_attr_val.v.val_lbl_id; | |
71dfc51f | 4821 | |
40e8cc95 | 4822 | abort (); |
a3f97cbb JW |
4823 | } |
4824 | ||
3f76745e | 4825 | /* Get the attribute of type attr_kind. */ |
71dfc51f | 4826 | |
3f76745e | 4827 | static inline dw_attr_ref |
7080f735 | 4828 | get_AT (dw_die_ref die, enum dwarf_attribute attr_kind) |
f37230f0 | 4829 | { |
b3694847 SS |
4830 | dw_attr_ref a; |
4831 | dw_die_ref spec = NULL; | |
556273e0 | 4832 | |
3f76745e JM |
4833 | if (die != NULL) |
4834 | { | |
4835 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
2ad9852d RK |
4836 | if (a->dw_attr == attr_kind) |
4837 | return a; | |
4838 | else if (a->dw_attr == DW_AT_specification | |
4839 | || a->dw_attr == DW_AT_abstract_origin) | |
4840 | spec = AT_ref (a); | |
71dfc51f | 4841 | |
3f76745e JM |
4842 | if (spec) |
4843 | return get_AT (spec, attr_kind); | |
4844 | } | |
4845 | ||
4846 | return NULL; | |
f37230f0 JM |
4847 | } |
4848 | ||
2ad9852d RK |
4849 | /* Return the "low pc" attribute value, typically associated with a subprogram |
4850 | DIE. Return null if the "low pc" attribute is either not present, or if it | |
4851 | cannot be represented as an assembler label identifier. */ | |
71dfc51f | 4852 | |
a96c67ec | 4853 | static inline const char * |
7080f735 | 4854 | get_AT_low_pc (dw_die_ref die) |
7e23cb16 | 4855 | { |
b3694847 | 4856 | dw_attr_ref a = get_AT (die, DW_AT_low_pc); |
2ad9852d | 4857 | |
40e8cc95 | 4858 | return a ? AT_lbl (a) : NULL; |
7e23cb16 JM |
4859 | } |
4860 | ||
2ad9852d RK |
4861 | /* Return the "high pc" attribute value, typically associated with a subprogram |
4862 | DIE. Return null if the "high pc" attribute is either not present, or if it | |
4863 | cannot be represented as an assembler label identifier. */ | |
71dfc51f | 4864 | |
a96c67ec | 4865 | static inline const char * |
7080f735 | 4866 | get_AT_hi_pc (dw_die_ref die) |
a3f97cbb | 4867 | { |
b3694847 | 4868 | dw_attr_ref a = get_AT (die, DW_AT_high_pc); |
2ad9852d | 4869 | |
40e8cc95 | 4870 | return a ? AT_lbl (a) : NULL; |
3f76745e JM |
4871 | } |
4872 | ||
4873 | /* Return the value of the string attribute designated by ATTR_KIND, or | |
4874 | NULL if it is not present. */ | |
71dfc51f | 4875 | |
a96c67ec | 4876 | static inline const char * |
7080f735 | 4877 | get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind) |
3f76745e | 4878 | { |
b3694847 | 4879 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4880 | |
40e8cc95 | 4881 | return a ? AT_string (a) : NULL; |
a3f97cbb JW |
4882 | } |
4883 | ||
3f76745e JM |
4884 | /* Return the value of the flag attribute designated by ATTR_KIND, or -1 |
4885 | if it is not present. */ | |
71dfc51f | 4886 | |
3f76745e | 4887 | static inline int |
7080f735 | 4888 | get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind) |
a3f97cbb | 4889 | { |
b3694847 | 4890 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4891 | |
40e8cc95 | 4892 | return a ? AT_flag (a) : 0; |
a3f97cbb JW |
4893 | } |
4894 | ||
3f76745e JM |
4895 | /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0 |
4896 | if it is not present. */ | |
71dfc51f | 4897 | |
3f76745e | 4898 | static inline unsigned |
7080f735 | 4899 | get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind) |
a3f97cbb | 4900 | { |
b3694847 | 4901 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4902 | |
40e8cc95 | 4903 | return a ? AT_unsigned (a) : 0; |
a96c67ec | 4904 | } |
71dfc51f | 4905 | |
a96c67ec | 4906 | static inline dw_die_ref |
7080f735 | 4907 | get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind) |
a96c67ec | 4908 | { |
b3694847 | 4909 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4910 | |
40e8cc95 | 4911 | return a ? AT_ref (a) : NULL; |
3f76745e | 4912 | } |
71dfc51f | 4913 | |
c3cdeef4 JB |
4914 | /* Return TRUE if the language is C or C++. */ |
4915 | ||
4916 | static inline bool | |
7080f735 | 4917 | is_c_family (void) |
3f76745e | 4918 | { |
c3cdeef4 | 4919 | unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
71dfc51f | 4920 | |
3f76745e JM |
4921 | return (lang == DW_LANG_C || lang == DW_LANG_C89 |
4922 | || lang == DW_LANG_C_plus_plus); | |
556273e0 | 4923 | } |
71dfc51f | 4924 | |
c3cdeef4 JB |
4925 | /* Return TRUE if the language is C++. */ |
4926 | ||
4927 | static inline bool | |
7080f735 | 4928 | is_cxx (void) |
1d3d6b1e JM |
4929 | { |
4930 | return (get_AT_unsigned (comp_unit_die, DW_AT_language) | |
4931 | == DW_LANG_C_plus_plus); | |
c26fbbca | 4932 | } |
1d3d6b1e | 4933 | |
c3cdeef4 JB |
4934 | /* Return TRUE if the language is Fortran. */ |
4935 | ||
4936 | static inline bool | |
7080f735 | 4937 | is_fortran (void) |
3f76745e | 4938 | { |
c3cdeef4 | 4939 | unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
71dfc51f | 4940 | |
c3cdeef4 | 4941 | return lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90; |
556273e0 | 4942 | } |
71dfc51f | 4943 | |
c3cdeef4 JB |
4944 | /* Return TRUE if the language is Java. */ |
4945 | ||
4946 | static inline bool | |
7080f735 | 4947 | is_java (void) |
28985b81 | 4948 | { |
c3cdeef4 | 4949 | unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
28985b81 | 4950 | |
c3cdeef4 JB |
4951 | return lang == DW_LANG_Java; |
4952 | } | |
4953 | ||
4954 | /* Return TRUE if the language is Ada. */ | |
4955 | ||
4956 | static inline bool | |
7080f735 | 4957 | is_ada (void) |
c3cdeef4 JB |
4958 | { |
4959 | unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
7080f735 | 4960 | |
c3cdeef4 | 4961 | return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83; |
28985b81 AG |
4962 | } |
4963 | ||
10a11b75 | 4964 | /* Free up the memory used by A. */ |
71dfc51f | 4965 | |
7080f735 | 4966 | static inline void free_AT (dw_attr_ref); |
3f76745e | 4967 | static inline void |
7080f735 | 4968 | free_AT (dw_attr_ref a) |
10a11b75 | 4969 | { |
17211ab5 GK |
4970 | if (AT_class (a) == dw_val_class_str) |
4971 | if (a->dw_attr_val.v.val_str->refcount) | |
4972 | a->dw_attr_val.v.val_str->refcount--; | |
556273e0 | 4973 | } |
10a11b75 JM |
4974 | |
4975 | /* Remove the specified attribute if present. */ | |
4976 | ||
4977 | static void | |
7080f735 | 4978 | remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind) |
3f76745e | 4979 | { |
b3694847 SS |
4980 | dw_attr_ref *p; |
4981 | dw_attr_ref removed = NULL; | |
a3f97cbb | 4982 | |
3f76745e JM |
4983 | if (die != NULL) |
4984 | { | |
a96c67ec JM |
4985 | for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next)) |
4986 | if ((*p)->dw_attr == attr_kind) | |
4987 | { | |
4988 | removed = *p; | |
4989 | *p = (*p)->dw_attr_next; | |
4990 | break; | |
4991 | } | |
71dfc51f | 4992 | |
a96c67ec | 4993 | if (removed != 0) |
10a11b75 JM |
4994 | free_AT (removed); |
4995 | } | |
4996 | } | |
71dfc51f | 4997 | |
10a11b75 | 4998 | /* Free up the memory used by DIE. */ |
71dfc51f | 4999 | |
10a11b75 | 5000 | static inline void |
7080f735 | 5001 | free_die (dw_die_ref die) |
10a11b75 JM |
5002 | { |
5003 | remove_children (die); | |
3f76745e | 5004 | } |
71dfc51f | 5005 | |
3f76745e | 5006 | /* Discard the children of this DIE. */ |
71dfc51f | 5007 | |
10a11b75 | 5008 | static void |
7080f735 | 5009 | remove_children (dw_die_ref die) |
3f76745e | 5010 | { |
b3694847 | 5011 | dw_die_ref child_die = die->die_child; |
3f76745e JM |
5012 | |
5013 | die->die_child = NULL; | |
3f76745e JM |
5014 | |
5015 | while (child_die != NULL) | |
a3f97cbb | 5016 | { |
b3694847 SS |
5017 | dw_die_ref tmp_die = child_die; |
5018 | dw_attr_ref a; | |
71dfc51f | 5019 | |
3f76745e | 5020 | child_die = child_die->die_sib; |
556273e0 KH |
5021 | |
5022 | for (a = tmp_die->die_attr; a != NULL;) | |
a3f97cbb | 5023 | { |
b3694847 | 5024 | dw_attr_ref tmp_a = a; |
71dfc51f | 5025 | |
3f76745e | 5026 | a = a->dw_attr_next; |
10a11b75 | 5027 | free_AT (tmp_a); |
a3f97cbb | 5028 | } |
71dfc51f | 5029 | |
10a11b75 | 5030 | free_die (tmp_die); |
3f76745e JM |
5031 | } |
5032 | } | |
71dfc51f | 5033 | |
a96c67ec | 5034 | /* Add a child DIE below its parent. We build the lists up in reverse |
881c6935 | 5035 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f | 5036 | |
3f76745e | 5037 | static inline void |
7080f735 | 5038 | add_child_die (dw_die_ref die, dw_die_ref child_die) |
3f76745e JM |
5039 | { |
5040 | if (die != NULL && child_die != NULL) | |
e90b62db | 5041 | { |
3a88cbd1 JL |
5042 | if (die == child_die) |
5043 | abort (); | |
2ad9852d | 5044 | |
3f76745e | 5045 | child_die->die_parent = die; |
a96c67ec JM |
5046 | child_die->die_sib = die->die_child; |
5047 | die->die_child = child_die; | |
3f76745e JM |
5048 | } |
5049 | } | |
5050 | ||
2081603c JM |
5051 | /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT |
5052 | is the specification, to the front of PARENT's list of children. */ | |
10a11b75 JM |
5053 | |
5054 | static void | |
7080f735 | 5055 | splice_child_die (dw_die_ref parent, dw_die_ref child) |
10a11b75 JM |
5056 | { |
5057 | dw_die_ref *p; | |
5058 | ||
5059 | /* We want the declaration DIE from inside the class, not the | |
5060 | specification DIE at toplevel. */ | |
5061 | if (child->die_parent != parent) | |
2081603c JM |
5062 | { |
5063 | dw_die_ref tmp = get_AT_ref (child, DW_AT_specification); | |
2ad9852d | 5064 | |
2081603c JM |
5065 | if (tmp) |
5066 | child = tmp; | |
5067 | } | |
10a11b75 | 5068 | |
2081603c JM |
5069 | if (child->die_parent != parent |
5070 | && child->die_parent != get_AT_ref (parent, DW_AT_specification)) | |
10a11b75 JM |
5071 | abort (); |
5072 | ||
5de0e8d4 | 5073 | for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib)) |
10a11b75 JM |
5074 | if (*p == child) |
5075 | { | |
5076 | *p = child->die_sib; | |
5077 | break; | |
5078 | } | |
5079 | ||
73c68f61 | 5080 | child->die_parent = parent; |
10a11b75 JM |
5081 | child->die_sib = parent->die_child; |
5082 | parent->die_child = child; | |
5083 | } | |
5084 | ||
3f76745e JM |
5085 | /* Return a pointer to a newly created DIE node. */ |
5086 | ||
5087 | static inline dw_die_ref | |
7080f735 | 5088 | new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t) |
3f76745e | 5089 | { |
703ad42b | 5090 | dw_die_ref die = ggc_alloc_cleared (sizeof (die_node)); |
3f76745e JM |
5091 | |
5092 | die->die_tag = tag_value; | |
3f76745e JM |
5093 | |
5094 | if (parent_die != NULL) | |
5095 | add_child_die (parent_die, die); | |
5096 | else | |
ef76d03b JW |
5097 | { |
5098 | limbo_die_node *limbo_node; | |
5099 | ||
17211ab5 | 5100 | limbo_node = ggc_alloc_cleared (sizeof (limbo_die_node)); |
ef76d03b | 5101 | limbo_node->die = die; |
54ba1f0d | 5102 | limbo_node->created_for = t; |
ef76d03b JW |
5103 | limbo_node->next = limbo_die_list; |
5104 | limbo_die_list = limbo_node; | |
5105 | } | |
71dfc51f | 5106 | |
3f76745e JM |
5107 | return die; |
5108 | } | |
71dfc51f | 5109 | |
3f76745e | 5110 | /* Return the DIE associated with the given type specifier. */ |
71dfc51f | 5111 | |
3f76745e | 5112 | static inline dw_die_ref |
7080f735 | 5113 | lookup_type_die (tree type) |
3f76745e | 5114 | { |
e2500fed | 5115 | return TYPE_SYMTAB_DIE (type); |
3f76745e | 5116 | } |
e90b62db | 5117 | |
3f76745e | 5118 | /* Equate a DIE to a given type specifier. */ |
71dfc51f | 5119 | |
10a11b75 | 5120 | static inline void |
7080f735 | 5121 | equate_type_number_to_die (tree type, dw_die_ref type_die) |
3f76745e | 5122 | { |
e2500fed | 5123 | TYPE_SYMTAB_DIE (type) = type_die; |
3f76745e | 5124 | } |
71dfc51f | 5125 | |
3f76745e | 5126 | /* Return the DIE associated with a given declaration. */ |
71dfc51f | 5127 | |
3f76745e | 5128 | static inline dw_die_ref |
7080f735 | 5129 | lookup_decl_die (tree decl) |
3f76745e | 5130 | { |
b3694847 | 5131 | unsigned decl_id = DECL_UID (decl); |
3f76745e | 5132 | |
2ad9852d | 5133 | return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL); |
a3f97cbb JW |
5134 | } |
5135 | ||
3f76745e | 5136 | /* Equate a DIE to a particular declaration. */ |
71dfc51f | 5137 | |
3f76745e | 5138 | static void |
7080f735 | 5139 | equate_decl_number_to_die (tree decl, dw_die_ref decl_die) |
a3f97cbb | 5140 | { |
aea9695c RK |
5141 | unsigned int decl_id = DECL_UID (decl); |
5142 | unsigned int num_allocated; | |
d291dd49 | 5143 | |
3f76745e | 5144 | if (decl_id >= decl_die_table_allocated) |
a3f97cbb | 5145 | { |
3f76745e JM |
5146 | num_allocated |
5147 | = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1) | |
5148 | / DECL_DIE_TABLE_INCREMENT) | |
5149 | * DECL_DIE_TABLE_INCREMENT; | |
5150 | ||
17211ab5 GK |
5151 | decl_die_table = ggc_realloc (decl_die_table, |
5152 | sizeof (dw_die_ref) * num_allocated); | |
3f76745e | 5153 | |
703ad42b | 5154 | memset (&decl_die_table[decl_die_table_allocated], 0, |
3f76745e JM |
5155 | (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref)); |
5156 | decl_die_table_allocated = num_allocated; | |
a3f97cbb | 5157 | } |
71dfc51f | 5158 | |
3f76745e JM |
5159 | if (decl_id >= decl_die_table_in_use) |
5160 | decl_die_table_in_use = (decl_id + 1); | |
5161 | ||
5162 | decl_die_table[decl_id] = decl_die; | |
a3f97cbb | 5163 | } |
3f76745e JM |
5164 | \f |
5165 | /* Keep track of the number of spaces used to indent the | |
5166 | output of the debugging routines that print the structure of | |
5167 | the DIE internal representation. */ | |
5168 | static int print_indent; | |
71dfc51f | 5169 | |
3f76745e JM |
5170 | /* Indent the line the number of spaces given by print_indent. */ |
5171 | ||
5172 | static inline void | |
7080f735 | 5173 | print_spaces (FILE *outfile) |
3f76745e JM |
5174 | { |
5175 | fprintf (outfile, "%*s", print_indent, ""); | |
a3f97cbb JW |
5176 | } |
5177 | ||
956d6950 | 5178 | /* Print the information associated with a given DIE, and its children. |
3f76745e | 5179 | This routine is a debugging aid only. */ |
71dfc51f | 5180 | |
a3f97cbb | 5181 | static void |
7080f735 | 5182 | print_die (dw_die_ref die, FILE *outfile) |
a3f97cbb | 5183 | { |
b3694847 SS |
5184 | dw_attr_ref a; |
5185 | dw_die_ref c; | |
71dfc51f | 5186 | |
3f76745e | 5187 | print_spaces (outfile); |
2d8b0f3a | 5188 | fprintf (outfile, "DIE %4lu: %s\n", |
3f76745e JM |
5189 | die->die_offset, dwarf_tag_name (die->die_tag)); |
5190 | print_spaces (outfile); | |
2d8b0f3a JL |
5191 | fprintf (outfile, " abbrev id: %lu", die->die_abbrev); |
5192 | fprintf (outfile, " offset: %lu\n", die->die_offset); | |
3f76745e JM |
5193 | |
5194 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
a3f97cbb | 5195 | { |
3f76745e JM |
5196 | print_spaces (outfile); |
5197 | fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr)); | |
5198 | ||
a96c67ec | 5199 | switch (AT_class (a)) |
3f76745e JM |
5200 | { |
5201 | case dw_val_class_addr: | |
5202 | fprintf (outfile, "address"); | |
5203 | break; | |
a20612aa RH |
5204 | case dw_val_class_offset: |
5205 | fprintf (outfile, "offset"); | |
5206 | break; | |
3f76745e JM |
5207 | case dw_val_class_loc: |
5208 | fprintf (outfile, "location descriptor"); | |
5209 | break; | |
63e46568 | 5210 | case dw_val_class_loc_list: |
a20612aa RH |
5211 | fprintf (outfile, "location list -> label:%s", |
5212 | AT_loc_list (a)->ll_symbol); | |
63e46568 | 5213 | break; |
2bee6045 JJ |
5214 | case dw_val_class_range_list: |
5215 | fprintf (outfile, "range list"); | |
5216 | break; | |
3f76745e | 5217 | case dw_val_class_const: |
a96c67ec | 5218 | fprintf (outfile, "%ld", AT_int (a)); |
3f76745e JM |
5219 | break; |
5220 | case dw_val_class_unsigned_const: | |
a96c67ec | 5221 | fprintf (outfile, "%lu", AT_unsigned (a)); |
3f76745e JM |
5222 | break; |
5223 | case dw_val_class_long_long: | |
2d8b0f3a | 5224 | fprintf (outfile, "constant (%lu,%lu)", |
556273e0 KH |
5225 | a->dw_attr_val.v.val_long_long.hi, |
5226 | a->dw_attr_val.v.val_long_long.low); | |
3f76745e JM |
5227 | break; |
5228 | case dw_val_class_float: | |
5229 | fprintf (outfile, "floating-point constant"); | |
5230 | break; | |
5231 | case dw_val_class_flag: | |
a96c67ec | 5232 | fprintf (outfile, "%u", AT_flag (a)); |
3f76745e JM |
5233 | break; |
5234 | case dw_val_class_die_ref: | |
a96c67ec | 5235 | if (AT_ref (a) != NULL) |
881c6935 | 5236 | { |
1bfb5f8f | 5237 | if (AT_ref (a)->die_symbol) |
881c6935 JM |
5238 | fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol); |
5239 | else | |
5240 | fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset); | |
5241 | } | |
3f76745e JM |
5242 | else |
5243 | fprintf (outfile, "die -> <null>"); | |
5244 | break; | |
5245 | case dw_val_class_lbl_id: | |
8b790721 | 5246 | case dw_val_class_lbl_offset: |
a96c67ec | 5247 | fprintf (outfile, "label: %s", AT_lbl (a)); |
3f76745e | 5248 | break; |
3f76745e | 5249 | case dw_val_class_str: |
a96c67ec JM |
5250 | if (AT_string (a) != NULL) |
5251 | fprintf (outfile, "\"%s\"", AT_string (a)); | |
3f76745e JM |
5252 | else |
5253 | fprintf (outfile, "<null>"); | |
5254 | break; | |
e9a25f70 JL |
5255 | default: |
5256 | break; | |
3f76745e JM |
5257 | } |
5258 | ||
5259 | fprintf (outfile, "\n"); | |
5260 | } | |
5261 | ||
5262 | if (die->die_child != NULL) | |
5263 | { | |
5264 | print_indent += 4; | |
5265 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5266 | print_die (c, outfile); | |
71dfc51f | 5267 | |
3f76745e | 5268 | print_indent -= 4; |
a3f97cbb | 5269 | } |
881c6935 JM |
5270 | if (print_indent == 0) |
5271 | fprintf (outfile, "\n"); | |
a3f97cbb JW |
5272 | } |
5273 | ||
3f76745e JM |
5274 | /* Print the contents of the source code line number correspondence table. |
5275 | This routine is a debugging aid only. */ | |
71dfc51f | 5276 | |
3f76745e | 5277 | static void |
7080f735 | 5278 | print_dwarf_line_table (FILE *outfile) |
a3f97cbb | 5279 | { |
b3694847 SS |
5280 | unsigned i; |
5281 | dw_line_info_ref line_info; | |
3f76745e JM |
5282 | |
5283 | fprintf (outfile, "\n\nDWARF source line information\n"); | |
2ad9852d | 5284 | for (i = 1; i < line_info_table_in_use; i++) |
a3f97cbb | 5285 | { |
3f76745e JM |
5286 | line_info = &line_info_table[i]; |
5287 | fprintf (outfile, "%5d: ", i); | |
c4274b22 RH |
5288 | fprintf (outfile, "%-20s", |
5289 | VARRAY_CHAR_PTR (file_table, line_info->dw_file_num)); | |
2d8b0f3a | 5290 | fprintf (outfile, "%6ld", line_info->dw_line_num); |
3f76745e | 5291 | fprintf (outfile, "\n"); |
a3f97cbb | 5292 | } |
3f76745e JM |
5293 | |
5294 | fprintf (outfile, "\n\n"); | |
f37230f0 JM |
5295 | } |
5296 | ||
3f76745e JM |
5297 | /* Print the information collected for a given DIE. */ |
5298 | ||
5299 | void | |
7080f735 | 5300 | debug_dwarf_die (dw_die_ref die) |
3f76745e JM |
5301 | { |
5302 | print_die (die, stderr); | |
5303 | } | |
5304 | ||
5305 | /* Print all DWARF information collected for the compilation unit. | |
5306 | This routine is a debugging aid only. */ | |
5307 | ||
5308 | void | |
7080f735 | 5309 | debug_dwarf (void) |
3f76745e JM |
5310 | { |
5311 | print_indent = 0; | |
5312 | print_die (comp_unit_die, stderr); | |
b2244e22 JW |
5313 | if (! DWARF2_ASM_LINE_DEBUG_INFO) |
5314 | print_dwarf_line_table (stderr); | |
3f76745e JM |
5315 | } |
5316 | \f | |
a96c67ec JM |
5317 | /* We build up the lists of children and attributes by pushing new ones |
5318 | onto the beginning of the list. Reverse the lists for DIE so that | |
5319 | they are in order of addition. */ | |
71dfc51f | 5320 | |
f37230f0 | 5321 | static void |
7080f735 | 5322 | reverse_die_lists (dw_die_ref die) |
f37230f0 | 5323 | { |
b3694847 SS |
5324 | dw_die_ref c, cp, cn; |
5325 | dw_attr_ref a, ap, an; | |
71dfc51f | 5326 | |
a96c67ec | 5327 | for (a = die->die_attr, ap = 0; a; a = an) |
7d9d8943 AM |
5328 | { |
5329 | an = a->dw_attr_next; | |
5330 | a->dw_attr_next = ap; | |
5331 | ap = a; | |
a3f97cbb | 5332 | } |
2ad9852d | 5333 | |
7d9d8943 | 5334 | die->die_attr = ap; |
3f76745e | 5335 | |
7d9d8943 AM |
5336 | for (c = die->die_child, cp = 0; c; c = cn) |
5337 | { | |
5338 | cn = c->die_sib; | |
5339 | c->die_sib = cp; | |
5340 | cp = c; | |
5341 | } | |
2ad9852d | 5342 | |
7d9d8943 | 5343 | die->die_child = cp; |
a3f97cbb JW |
5344 | } |
5345 | ||
2ad9852d RK |
5346 | /* reverse_die_lists only reverses the single die you pass it. Since we used to |
5347 | reverse all dies in add_sibling_attributes, which runs through all the dies, | |
5348 | it would reverse all the dies. Now, however, since we don't call | |
5349 | reverse_die_lists in add_sibling_attributes, we need a routine to | |
5350 | recursively reverse all the dies. This is that routine. */ | |
71dfc51f | 5351 | |
7d9d8943 | 5352 | static void |
7080f735 | 5353 | reverse_all_dies (dw_die_ref die) |
a3f97cbb | 5354 | { |
b3694847 | 5355 | dw_die_ref c; |
71dfc51f | 5356 | |
7d9d8943 | 5357 | reverse_die_lists (die); |
3f76745e | 5358 | |
881c6935 JM |
5359 | for (c = die->die_child; c; c = c->die_sib) |
5360 | reverse_all_dies (c); | |
5361 | } | |
5362 | ||
2ad9852d RK |
5363 | /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU |
5364 | for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL | |
5365 | DIE that marks the start of the DIEs for this include file. */ | |
881c6935 JM |
5366 | |
5367 | static dw_die_ref | |
7080f735 | 5368 | push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die) |
881c6935 JM |
5369 | { |
5370 | const char *filename = get_AT_string (bincl_die, DW_AT_name); | |
5371 | dw_die_ref new_unit = gen_compile_unit_die (filename); | |
2ad9852d | 5372 | |
881c6935 JM |
5373 | new_unit->die_sib = old_unit; |
5374 | return new_unit; | |
5375 | } | |
5376 | ||
5377 | /* Close an include-file CU and reopen the enclosing one. */ | |
5378 | ||
5379 | static dw_die_ref | |
7080f735 | 5380 | pop_compile_unit (dw_die_ref old_unit) |
881c6935 JM |
5381 | { |
5382 | dw_die_ref new_unit = old_unit->die_sib; | |
2ad9852d | 5383 | |
881c6935 JM |
5384 | old_unit->die_sib = NULL; |
5385 | return new_unit; | |
5386 | } | |
5387 | ||
2ad9852d RK |
5388 | #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx) |
5389 | #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx) | |
881c6935 JM |
5390 | |
5391 | /* Calculate the checksum of a location expression. */ | |
5392 | ||
5393 | static inline void | |
7080f735 | 5394 | loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx) |
881c6935 | 5395 | { |
2ad9852d RK |
5396 | CHECKSUM (loc->dw_loc_opc); |
5397 | CHECKSUM (loc->dw_loc_oprnd1); | |
5398 | CHECKSUM (loc->dw_loc_oprnd2); | |
881c6935 JM |
5399 | } |
5400 | ||
5401 | /* Calculate the checksum of an attribute. */ | |
5402 | ||
5403 | static void | |
7080f735 | 5404 | attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark) |
881c6935 JM |
5405 | { |
5406 | dw_loc_descr_ref loc; | |
5407 | rtx r; | |
5408 | ||
2ad9852d | 5409 | CHECKSUM (at->dw_attr); |
881c6935 JM |
5410 | |
5411 | /* We don't care about differences in file numbering. */ | |
5f632b5e JM |
5412 | if (at->dw_attr == DW_AT_decl_file |
5413 | /* Or that this was compiled with a different compiler snapshot; if | |
5414 | the output is the same, that's what matters. */ | |
5415 | || at->dw_attr == DW_AT_producer) | |
881c6935 JM |
5416 | return; |
5417 | ||
5418 | switch (AT_class (at)) | |
5419 | { | |
5420 | case dw_val_class_const: | |
2ad9852d | 5421 | CHECKSUM (at->dw_attr_val.v.val_int); |
881c6935 JM |
5422 | break; |
5423 | case dw_val_class_unsigned_const: | |
2ad9852d | 5424 | CHECKSUM (at->dw_attr_val.v.val_unsigned); |
881c6935 JM |
5425 | break; |
5426 | case dw_val_class_long_long: | |
2ad9852d | 5427 | CHECKSUM (at->dw_attr_val.v.val_long_long); |
881c6935 JM |
5428 | break; |
5429 | case dw_val_class_float: | |
2ad9852d | 5430 | CHECKSUM (at->dw_attr_val.v.val_float); |
881c6935 JM |
5431 | break; |
5432 | case dw_val_class_flag: | |
2ad9852d | 5433 | CHECKSUM (at->dw_attr_val.v.val_flag); |
881c6935 | 5434 | break; |
881c6935 | 5435 | case dw_val_class_str: |
2ad9852d | 5436 | CHECKSUM_STRING (AT_string (at)); |
881c6935 | 5437 | break; |
a20612aa | 5438 | |
881c6935 JM |
5439 | case dw_val_class_addr: |
5440 | r = AT_addr (at); | |
5441 | switch (GET_CODE (r)) | |
5442 | { | |
5443 | case SYMBOL_REF: | |
2ad9852d | 5444 | CHECKSUM_STRING (XSTR (r, 0)); |
881c6935 JM |
5445 | break; |
5446 | ||
5447 | default: | |
5448 | abort (); | |
5449 | } | |
5450 | break; | |
5451 | ||
a20612aa | 5452 | case dw_val_class_offset: |
2ad9852d | 5453 | CHECKSUM (at->dw_attr_val.v.val_offset); |
a20612aa RH |
5454 | break; |
5455 | ||
881c6935 JM |
5456 | case dw_val_class_loc: |
5457 | for (loc = AT_loc (at); loc; loc = loc->dw_loc_next) | |
5458 | loc_checksum (loc, ctx); | |
5459 | break; | |
5460 | ||
5461 | case dw_val_class_die_ref: | |
cc0017a9 ZD |
5462 | die_checksum (AT_ref (at), ctx, mark); |
5463 | break; | |
881c6935 JM |
5464 | |
5465 | case dw_val_class_fde_ref: | |
5466 | case dw_val_class_lbl_id: | |
5467 | case dw_val_class_lbl_offset: | |
a20612aa | 5468 | break; |
881c6935 JM |
5469 | |
5470 | default: | |
5471 | break; | |
5472 | } | |
5473 | } | |
5474 | ||
5475 | /* Calculate the checksum of a DIE. */ | |
5476 | ||
5477 | static void | |
7080f735 | 5478 | die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark) |
881c6935 JM |
5479 | { |
5480 | dw_die_ref c; | |
5481 | dw_attr_ref a; | |
5482 | ||
cc0017a9 ZD |
5483 | /* To avoid infinite recursion. */ |
5484 | if (die->die_mark) | |
5485 | { | |
5486 | CHECKSUM (die->die_mark); | |
5487 | return; | |
5488 | } | |
5489 | die->die_mark = ++(*mark); | |
5490 | ||
2ad9852d | 5491 | CHECKSUM (die->die_tag); |
881c6935 JM |
5492 | |
5493 | for (a = die->die_attr; a; a = a->dw_attr_next) | |
cc0017a9 | 5494 | attr_checksum (a, ctx, mark); |
881c6935 JM |
5495 | |
5496 | for (c = die->die_child; c; c = c->die_sib) | |
cc0017a9 | 5497 | die_checksum (c, ctx, mark); |
881c6935 JM |
5498 | } |
5499 | ||
2ad9852d RK |
5500 | #undef CHECKSUM |
5501 | #undef CHECKSUM_STRING | |
881c6935 | 5502 | |
cc0017a9 ZD |
5503 | /* Do the location expressions look same? */ |
5504 | static inline int | |
7080f735 | 5505 | same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark) |
cc0017a9 ZD |
5506 | { |
5507 | return loc1->dw_loc_opc == loc2->dw_loc_opc | |
5508 | && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark) | |
5509 | && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark); | |
5510 | } | |
5511 | ||
5512 | /* Do the values look the same? */ | |
5513 | static int | |
7080f735 | 5514 | same_dw_val_p (dw_val_node *v1, dw_val_node *v2, int *mark) |
cc0017a9 ZD |
5515 | { |
5516 | dw_loc_descr_ref loc1, loc2; | |
5517 | rtx r1, r2; | |
5518 | unsigned i; | |
5519 | ||
5520 | if (v1->val_class != v2->val_class) | |
5521 | return 0; | |
5522 | ||
5523 | switch (v1->val_class) | |
5524 | { | |
5525 | case dw_val_class_const: | |
5526 | return v1->v.val_int == v2->v.val_int; | |
5527 | case dw_val_class_unsigned_const: | |
5528 | return v1->v.val_unsigned == v2->v.val_unsigned; | |
5529 | case dw_val_class_long_long: | |
5530 | return v1->v.val_long_long.hi == v2->v.val_long_long.hi | |
73c68f61 | 5531 | && v1->v.val_long_long.low == v2->v.val_long_long.low; |
cc0017a9 ZD |
5532 | case dw_val_class_float: |
5533 | if (v1->v.val_float.length != v2->v.val_float.length) | |
5534 | return 0; | |
5535 | for (i = 0; i < v1->v.val_float.length; i++) | |
73c68f61 | 5536 | if (v1->v.val_float.array[i] != v2->v.val_float.array[i]) |
cc0017a9 ZD |
5537 | return 0; |
5538 | return 1; | |
5539 | case dw_val_class_flag: | |
5540 | return v1->v.val_flag == v2->v.val_flag; | |
5541 | case dw_val_class_str: | |
17211ab5 | 5542 | return !strcmp(v1->v.val_str->str, v2->v.val_str->str); |
cc0017a9 ZD |
5543 | |
5544 | case dw_val_class_addr: | |
5545 | r1 = v1->v.val_addr; | |
5546 | r2 = v2->v.val_addr; | |
5547 | if (GET_CODE (r1) != GET_CODE (r2)) | |
5548 | return 0; | |
5549 | switch (GET_CODE (r1)) | |
5550 | { | |
5551 | case SYMBOL_REF: | |
5552 | return !strcmp (XSTR (r1, 0), XSTR (r2, 0)); | |
5553 | ||
5554 | default: | |
5555 | abort (); | |
5556 | } | |
5557 | ||
5558 | case dw_val_class_offset: | |
5559 | return v1->v.val_offset == v2->v.val_offset; | |
5560 | ||
5561 | case dw_val_class_loc: | |
5562 | for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc; | |
5563 | loc1 && loc2; | |
5564 | loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next) | |
5565 | if (!same_loc_p (loc1, loc2, mark)) | |
5566 | return 0; | |
5567 | return !loc1 && !loc2; | |
5568 | ||
5569 | case dw_val_class_die_ref: | |
5570 | return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark); | |
5571 | ||
5572 | case dw_val_class_fde_ref: | |
5573 | case dw_val_class_lbl_id: | |
5574 | case dw_val_class_lbl_offset: | |
5575 | return 1; | |
5576 | ||
5577 | default: | |
5578 | return 1; | |
5579 | } | |
5580 | } | |
5581 | ||
5582 | /* Do the attributes look the same? */ | |
5583 | ||
5584 | static int | |
7080f735 | 5585 | same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark) |
cc0017a9 ZD |
5586 | { |
5587 | if (at1->dw_attr != at2->dw_attr) | |
5588 | return 0; | |
5589 | ||
5590 | /* We don't care about differences in file numbering. */ | |
5591 | if (at1->dw_attr == DW_AT_decl_file | |
5592 | /* Or that this was compiled with a different compiler snapshot; if | |
5593 | the output is the same, that's what matters. */ | |
5594 | || at1->dw_attr == DW_AT_producer) | |
5595 | return 1; | |
5596 | ||
5597 | return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark); | |
5598 | } | |
5599 | ||
5600 | /* Do the dies look the same? */ | |
5601 | ||
5602 | static int | |
7080f735 | 5603 | same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark) |
cc0017a9 ZD |
5604 | { |
5605 | dw_die_ref c1, c2; | |
5606 | dw_attr_ref a1, a2; | |
5607 | ||
5608 | /* To avoid infinite recursion. */ | |
5609 | if (die1->die_mark) | |
5610 | return die1->die_mark == die2->die_mark; | |
5611 | die1->die_mark = die2->die_mark = ++(*mark); | |
5612 | ||
5613 | if (die1->die_tag != die2->die_tag) | |
5614 | return 0; | |
5615 | ||
5616 | for (a1 = die1->die_attr, a2 = die2->die_attr; | |
5617 | a1 && a2; | |
5618 | a1 = a1->dw_attr_next, a2 = a2->dw_attr_next) | |
5619 | if (!same_attr_p (a1, a2, mark)) | |
5620 | return 0; | |
5621 | if (a1 || a2) | |
5622 | return 0; | |
5623 | ||
5624 | for (c1 = die1->die_child, c2 = die2->die_child; | |
5625 | c1 && c2; | |
5626 | c1 = c1->die_sib, c2 = c2->die_sib) | |
5627 | if (!same_die_p (c1, c2, mark)) | |
5628 | return 0; | |
5629 | if (c1 || c2) | |
5630 | return 0; | |
5631 | ||
5632 | return 1; | |
5633 | } | |
5634 | ||
5635 | /* Do the dies look the same? Wrapper around same_die_p. */ | |
5636 | ||
5637 | static int | |
7080f735 | 5638 | same_die_p_wrap (dw_die_ref die1, dw_die_ref die2) |
cc0017a9 ZD |
5639 | { |
5640 | int mark = 0; | |
5641 | int ret = same_die_p (die1, die2, &mark); | |
5642 | ||
5643 | unmark_all_dies (die1); | |
5644 | unmark_all_dies (die2); | |
5645 | ||
5646 | return ret; | |
5647 | } | |
5648 | ||
881c6935 JM |
5649 | /* The prefix to attach to symbols on DIEs in the current comdat debug |
5650 | info section. */ | |
5651 | static char *comdat_symbol_id; | |
5652 | ||
5653 | /* The index of the current symbol within the current comdat CU. */ | |
5654 | static unsigned int comdat_symbol_number; | |
5655 | ||
5656 | /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its | |
5657 | children, and set comdat_symbol_id accordingly. */ | |
5658 | ||
5659 | static void | |
7080f735 | 5660 | compute_section_prefix (dw_die_ref unit_die) |
881c6935 | 5661 | { |
cc0017a9 ZD |
5662 | const char *die_name = get_AT_string (unit_die, DW_AT_name); |
5663 | const char *base = die_name ? lbasename (die_name) : "anonymous"; | |
703ad42b | 5664 | char *name = alloca (strlen (base) + 64); |
f11c3043 | 5665 | char *p; |
cc0017a9 | 5666 | int i, mark; |
881c6935 JM |
5667 | unsigned char checksum[16]; |
5668 | struct md5_ctx ctx; | |
5669 | ||
f11c3043 RK |
5670 | /* Compute the checksum of the DIE, then append part of it as hex digits to |
5671 | the name filename of the unit. */ | |
5672 | ||
881c6935 | 5673 | md5_init_ctx (&ctx); |
cc0017a9 ZD |
5674 | mark = 0; |
5675 | die_checksum (unit_die, &ctx, &mark); | |
5676 | unmark_all_dies (unit_die); | |
881c6935 JM |
5677 | md5_finish_ctx (&ctx, checksum); |
5678 | ||
0023400b | 5679 | sprintf (name, "%s.", base); |
881c6935 JM |
5680 | clean_symbol_name (name); |
5681 | ||
2ad9852d RK |
5682 | p = name + strlen (name); |
5683 | for (i = 0; i < 4; i++) | |
5684 | { | |
5685 | sprintf (p, "%.2x", checksum[i]); | |
5686 | p += 2; | |
5687 | } | |
881c6935 JM |
5688 | |
5689 | comdat_symbol_id = unit_die->die_symbol = xstrdup (name); | |
5690 | comdat_symbol_number = 0; | |
5691 | } | |
5692 | ||
f11c3043 | 5693 | /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */ |
881c6935 JM |
5694 | |
5695 | static int | |
7080f735 | 5696 | is_type_die (dw_die_ref die) |
881c6935 JM |
5697 | { |
5698 | switch (die->die_tag) | |
5699 | { | |
5700 | case DW_TAG_array_type: | |
5701 | case DW_TAG_class_type: | |
5702 | case DW_TAG_enumeration_type: | |
5703 | case DW_TAG_pointer_type: | |
5704 | case DW_TAG_reference_type: | |
5705 | case DW_TAG_string_type: | |
5706 | case DW_TAG_structure_type: | |
5707 | case DW_TAG_subroutine_type: | |
5708 | case DW_TAG_union_type: | |
5709 | case DW_TAG_ptr_to_member_type: | |
5710 | case DW_TAG_set_type: | |
5711 | case DW_TAG_subrange_type: | |
5712 | case DW_TAG_base_type: | |
5713 | case DW_TAG_const_type: | |
5714 | case DW_TAG_file_type: | |
5715 | case DW_TAG_packed_type: | |
5716 | case DW_TAG_volatile_type: | |
cc0017a9 | 5717 | case DW_TAG_typedef: |
881c6935 JM |
5718 | return 1; |
5719 | default: | |
5720 | return 0; | |
5721 | } | |
5722 | } | |
5723 | ||
5724 | /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU. | |
5725 | Basically, we want to choose the bits that are likely to be shared between | |
5726 | compilations (types) and leave out the bits that are specific to individual | |
5727 | compilations (functions). */ | |
5728 | ||
5729 | static int | |
7080f735 | 5730 | is_comdat_die (dw_die_ref c) |
881c6935 | 5731 | { |
2ad9852d RK |
5732 | /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as |
5733 | we do for stabs. The advantage is a greater likelihood of sharing between | |
5734 | objects that don't include headers in the same order (and therefore would | |
5735 | put the base types in a different comdat). jason 8/28/00 */ | |
5736 | ||
881c6935 JM |
5737 | if (c->die_tag == DW_TAG_base_type) |
5738 | return 0; | |
5739 | ||
5740 | if (c->die_tag == DW_TAG_pointer_type | |
5741 | || c->die_tag == DW_TAG_reference_type | |
5742 | || c->die_tag == DW_TAG_const_type | |
5743 | || c->die_tag == DW_TAG_volatile_type) | |
5744 | { | |
5745 | dw_die_ref t = get_AT_ref (c, DW_AT_type); | |
2ad9852d | 5746 | |
881c6935 JM |
5747 | return t ? is_comdat_die (t) : 0; |
5748 | } | |
881c6935 JM |
5749 | |
5750 | return is_type_die (c); | |
5751 | } | |
5752 | ||
5753 | /* Returns 1 iff C is the sort of DIE that might be referred to from another | |
5754 | compilation unit. */ | |
5755 | ||
5756 | static int | |
7080f735 | 5757 | is_symbol_die (dw_die_ref c) |
881c6935 | 5758 | { |
2ad9852d | 5759 | return (is_type_die (c) |
c26fbbca | 5760 | || (get_AT (c, DW_AT_declaration) |
2ad9852d | 5761 | && !get_AT (c, DW_AT_specification))); |
881c6935 JM |
5762 | } |
5763 | ||
5764 | static char * | |
7080f735 | 5765 | gen_internal_sym (const char *prefix) |
881c6935 JM |
5766 | { |
5767 | char buf[256]; | |
2ad9852d | 5768 | |
63e46568 | 5769 | ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++); |
881c6935 JM |
5770 | return xstrdup (buf); |
5771 | } | |
5772 | ||
5773 | /* Assign symbols to all worthy DIEs under DIE. */ | |
5774 | ||
5775 | static void | |
7080f735 | 5776 | assign_symbol_names (dw_die_ref die) |
881c6935 | 5777 | { |
b3694847 | 5778 | dw_die_ref c; |
881c6935 JM |
5779 | |
5780 | if (is_symbol_die (die)) | |
5781 | { | |
5782 | if (comdat_symbol_id) | |
5783 | { | |
5784 | char *p = alloca (strlen (comdat_symbol_id) + 64); | |
2ad9852d | 5785 | |
881c6935 JM |
5786 | sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX, |
5787 | comdat_symbol_id, comdat_symbol_number++); | |
5788 | die->die_symbol = xstrdup (p); | |
5789 | } | |
5790 | else | |
63e46568 | 5791 | die->die_symbol = gen_internal_sym ("LDIE"); |
881c6935 JM |
5792 | } |
5793 | ||
5794 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5795 | assign_symbol_names (c); | |
5796 | } | |
5797 | ||
cc0017a9 ZD |
5798 | struct cu_hash_table_entry |
5799 | { | |
5800 | dw_die_ref cu; | |
5801 | unsigned min_comdat_num, max_comdat_num; | |
5802 | struct cu_hash_table_entry *next; | |
5803 | }; | |
5804 | ||
5805 | /* Routines to manipulate hash table of CUs. */ | |
5806 | static hashval_t | |
7080f735 | 5807 | htab_cu_hash (const void *of) |
cc0017a9 ZD |
5808 | { |
5809 | const struct cu_hash_table_entry *entry = of; | |
5810 | ||
5811 | return htab_hash_string (entry->cu->die_symbol); | |
5812 | } | |
5813 | ||
5814 | static int | |
7080f735 | 5815 | htab_cu_eq (const void *of1, const void *of2) |
cc0017a9 ZD |
5816 | { |
5817 | const struct cu_hash_table_entry *entry1 = of1; | |
5818 | const struct die_struct *entry2 = of2; | |
5819 | ||
5820 | return !strcmp (entry1->cu->die_symbol, entry2->die_symbol); | |
5821 | } | |
5822 | ||
5823 | static void | |
7080f735 | 5824 | htab_cu_del (void *what) |
cc0017a9 ZD |
5825 | { |
5826 | struct cu_hash_table_entry *next, *entry = what; | |
5827 | ||
5828 | while (entry) | |
5829 | { | |
5830 | next = entry->next; | |
5831 | free (entry); | |
5832 | entry = next; | |
5833 | } | |
5834 | } | |
5835 | ||
5836 | /* Check whether we have already seen this CU and set up SYM_NUM | |
5837 | accordingly. */ | |
5838 | static int | |
7080f735 | 5839 | check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num) |
cc0017a9 ZD |
5840 | { |
5841 | struct cu_hash_table_entry dummy; | |
5842 | struct cu_hash_table_entry **slot, *entry, *last = &dummy; | |
5843 | ||
5844 | dummy.max_comdat_num = 0; | |
5845 | ||
5846 | slot = (struct cu_hash_table_entry **) | |
5847 | htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol), | |
5848 | INSERT); | |
5849 | entry = *slot; | |
5850 | ||
5851 | for (; entry; last = entry, entry = entry->next) | |
5852 | { | |
5853 | if (same_die_p_wrap (cu, entry->cu)) | |
5854 | break; | |
5855 | } | |
5856 | ||
5857 | if (entry) | |
5858 | { | |
5859 | *sym_num = entry->min_comdat_num; | |
5860 | return 1; | |
5861 | } | |
5862 | ||
5863 | entry = xcalloc (1, sizeof (struct cu_hash_table_entry)); | |
5864 | entry->cu = cu; | |
5865 | entry->min_comdat_num = *sym_num = last->max_comdat_num; | |
5866 | entry->next = *slot; | |
5867 | *slot = entry; | |
5868 | ||
5869 | return 0; | |
5870 | } | |
5871 | ||
5872 | /* Record SYM_NUM to record of CU in HTABLE. */ | |
5873 | static void | |
7080f735 | 5874 | record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num) |
cc0017a9 ZD |
5875 | { |
5876 | struct cu_hash_table_entry **slot, *entry; | |
5877 | ||
5878 | slot = (struct cu_hash_table_entry **) | |
5879 | htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol), | |
5880 | NO_INSERT); | |
5881 | entry = *slot; | |
5882 | ||
5883 | entry->max_comdat_num = sym_num; | |
5884 | } | |
5885 | ||
881c6935 JM |
5886 | /* Traverse the DIE (which is always comp_unit_die), and set up |
5887 | additional compilation units for each of the include files we see | |
5888 | bracketed by BINCL/EINCL. */ | |
5889 | ||
5890 | static void | |
7080f735 | 5891 | break_out_includes (dw_die_ref die) |
881c6935 JM |
5892 | { |
5893 | dw_die_ref *ptr; | |
b3694847 | 5894 | dw_die_ref unit = NULL; |
cc0017a9 ZD |
5895 | limbo_die_node *node, **pnode; |
5896 | htab_t cu_hash_table; | |
881c6935 | 5897 | |
c26fbbca | 5898 | for (ptr = &(die->die_child); *ptr;) |
881c6935 | 5899 | { |
b3694847 | 5900 | dw_die_ref c = *ptr; |
881c6935 | 5901 | |
2ad9852d | 5902 | if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL |
881c6935 JM |
5903 | || (unit && is_comdat_die (c))) |
5904 | { | |
5905 | /* This DIE is for a secondary CU; remove it from the main one. */ | |
5906 | *ptr = c->die_sib; | |
5907 | ||
5908 | if (c->die_tag == DW_TAG_GNU_BINCL) | |
5909 | { | |
5910 | unit = push_new_compile_unit (unit, c); | |
5911 | free_die (c); | |
5912 | } | |
5913 | else if (c->die_tag == DW_TAG_GNU_EINCL) | |
5914 | { | |
5915 | unit = pop_compile_unit (unit); | |
5916 | free_die (c); | |
5917 | } | |
5918 | else | |
5919 | add_child_die (unit, c); | |
5920 | } | |
5921 | else | |
5922 | { | |
5923 | /* Leave this DIE in the main CU. */ | |
5924 | ptr = &(c->die_sib); | |
5925 | continue; | |
5926 | } | |
5927 | } | |
5928 | ||
5929 | #if 0 | |
5930 | /* We can only use this in debugging, since the frontend doesn't check | |
0b34cf1e | 5931 | to make sure that we leave every include file we enter. */ |
881c6935 JM |
5932 | if (unit != NULL) |
5933 | abort (); | |
5934 | #endif | |
5935 | ||
5936 | assign_symbol_names (die); | |
cc0017a9 ZD |
5937 | cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del); |
5938 | for (node = limbo_die_list, pnode = &limbo_die_list; | |
5939 | node; | |
5940 | node = node->next) | |
881c6935 | 5941 | { |
cc0017a9 ZD |
5942 | int is_dupl; |
5943 | ||
881c6935 | 5944 | compute_section_prefix (node->die); |
cc0017a9 ZD |
5945 | is_dupl = check_duplicate_cu (node->die, cu_hash_table, |
5946 | &comdat_symbol_number); | |
881c6935 | 5947 | assign_symbol_names (node->die); |
cc0017a9 ZD |
5948 | if (is_dupl) |
5949 | *pnode = node->next; | |
5950 | else | |
73c68f61 | 5951 | { |
cc0017a9 ZD |
5952 | pnode = &node->next; |
5953 | record_comdat_symbol_number (node->die, cu_hash_table, | |
5954 | comdat_symbol_number); | |
5955 | } | |
881c6935 | 5956 | } |
cc0017a9 | 5957 | htab_delete (cu_hash_table); |
881c6935 JM |
5958 | } |
5959 | ||
5960 | /* Traverse the DIE and add a sibling attribute if it may have the | |
5961 | effect of speeding up access to siblings. To save some space, | |
5962 | avoid generating sibling attributes for DIE's without children. */ | |
5963 | ||
5964 | static void | |
7080f735 | 5965 | add_sibling_attributes (dw_die_ref die) |
881c6935 | 5966 | { |
b3694847 | 5967 | dw_die_ref c; |
881c6935 JM |
5968 | |
5969 | if (die->die_tag != DW_TAG_compile_unit | |
5970 | && die->die_sib && die->die_child != NULL) | |
7d9d8943 AM |
5971 | /* Add the sibling link to the front of the attribute list. */ |
5972 | add_AT_die_ref (die, DW_AT_sibling, die->die_sib); | |
5973 | ||
5974 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5975 | add_sibling_attributes (c); | |
5976 | } | |
5977 | ||
2ad9852d RK |
5978 | /* Output all location lists for the DIE and its children. */ |
5979 | ||
63e46568 | 5980 | static void |
7080f735 | 5981 | output_location_lists (dw_die_ref die) |
63e46568 DB |
5982 | { |
5983 | dw_die_ref c; | |
5984 | dw_attr_ref d_attr; | |
2ad9852d | 5985 | |
63e46568 | 5986 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) |
2ad9852d RK |
5987 | if (AT_class (d_attr) == dw_val_class_loc_list) |
5988 | output_loc_list (AT_loc_list (d_attr)); | |
5989 | ||
63e46568 DB |
5990 | for (c = die->die_child; c != NULL; c = c->die_sib) |
5991 | output_location_lists (c); | |
5992 | ||
5993 | } | |
c26fbbca | 5994 | |
2ad9852d RK |
5995 | /* The format of each DIE (and its attribute value pairs) is encoded in an |
5996 | abbreviation table. This routine builds the abbreviation table and assigns | |
5997 | a unique abbreviation id for each abbreviation entry. The children of each | |
5998 | die are visited recursively. */ | |
7d9d8943 AM |
5999 | |
6000 | static void | |
7080f735 | 6001 | build_abbrev_table (dw_die_ref die) |
7d9d8943 | 6002 | { |
b3694847 SS |
6003 | unsigned long abbrev_id; |
6004 | unsigned int n_alloc; | |
6005 | dw_die_ref c; | |
6006 | dw_attr_ref d_attr, a_attr; | |
881c6935 JM |
6007 | |
6008 | /* Scan the DIE references, and mark as external any that refer to | |
1bfb5f8f | 6009 | DIEs from other CUs (i.e. those which are not marked). */ |
881c6935 | 6010 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) |
2ad9852d RK |
6011 | if (AT_class (d_attr) == dw_val_class_die_ref |
6012 | && AT_ref (d_attr)->die_mark == 0) | |
6013 | { | |
6014 | if (AT_ref (d_attr)->die_symbol == 0) | |
6015 | abort (); | |
6016 | ||
6017 | set_AT_ref_external (d_attr, 1); | |
6018 | } | |
881c6935 | 6019 | |
7d9d8943 AM |
6020 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
6021 | { | |
b3694847 | 6022 | dw_die_ref abbrev = abbrev_die_table[abbrev_id]; |
7d9d8943 AM |
6023 | |
6024 | if (abbrev->die_tag == die->die_tag) | |
6025 | { | |
6026 | if ((abbrev->die_child != NULL) == (die->die_child != NULL)) | |
6027 | { | |
6028 | a_attr = abbrev->die_attr; | |
6029 | d_attr = die->die_attr; | |
6030 | ||
6031 | while (a_attr != NULL && d_attr != NULL) | |
6032 | { | |
6033 | if ((a_attr->dw_attr != d_attr->dw_attr) | |
6034 | || (value_format (a_attr) != value_format (d_attr))) | |
6035 | break; | |
6036 | ||
6037 | a_attr = a_attr->dw_attr_next; | |
6038 | d_attr = d_attr->dw_attr_next; | |
6039 | } | |
6040 | ||
6041 | if (a_attr == NULL && d_attr == NULL) | |
6042 | break; | |
6043 | } | |
6044 | } | |
6045 | } | |
6046 | ||
6047 | if (abbrev_id >= abbrev_die_table_in_use) | |
6048 | { | |
6049 | if (abbrev_die_table_in_use >= abbrev_die_table_allocated) | |
6050 | { | |
6051 | n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT; | |
17211ab5 GK |
6052 | abbrev_die_table = ggc_realloc (abbrev_die_table, |
6053 | sizeof (dw_die_ref) * n_alloc); | |
7d9d8943 | 6054 | |
703ad42b | 6055 | memset (&abbrev_die_table[abbrev_die_table_allocated], 0, |
7d9d8943 AM |
6056 | (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref)); |
6057 | abbrev_die_table_allocated = n_alloc; | |
6058 | } | |
6059 | ||
6060 | ++abbrev_die_table_in_use; | |
6061 | abbrev_die_table[abbrev_id] = die; | |
6062 | } | |
6063 | ||
6064 | die->die_abbrev = abbrev_id; | |
6065 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
6066 | build_abbrev_table (c); | |
6067 | } | |
6068 | \f | |
3f76745e JM |
6069 | /* Return the power-of-two number of bytes necessary to represent VALUE. */ |
6070 | ||
6071 | static int | |
7080f735 | 6072 | constant_size (long unsigned int value) |
3f76745e JM |
6073 | { |
6074 | int log; | |
6075 | ||
6076 | if (value == 0) | |
6077 | log = 0; | |
a3f97cbb | 6078 | else |
3f76745e | 6079 | log = floor_log2 (value); |
71dfc51f | 6080 | |
3f76745e JM |
6081 | log = log / 8; |
6082 | log = 1 << (floor_log2 (log) + 1); | |
6083 | ||
6084 | return log; | |
a3f97cbb JW |
6085 | } |
6086 | ||
2ad9852d | 6087 | /* Return the size of a DIE as it is represented in the |
3f76745e | 6088 | .debug_info section. */ |
71dfc51f | 6089 | |
3f76745e | 6090 | static unsigned long |
7080f735 | 6091 | size_of_die (dw_die_ref die) |
a3f97cbb | 6092 | { |
b3694847 SS |
6093 | unsigned long size = 0; |
6094 | dw_attr_ref a; | |
71dfc51f | 6095 | |
3f76745e | 6096 | size += size_of_uleb128 (die->die_abbrev); |
a3f97cbb JW |
6097 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
6098 | { | |
a96c67ec | 6099 | switch (AT_class (a)) |
a3f97cbb JW |
6100 | { |
6101 | case dw_val_class_addr: | |
a1a4189d | 6102 | size += DWARF2_ADDR_SIZE; |
a3f97cbb | 6103 | break; |
a20612aa RH |
6104 | case dw_val_class_offset: |
6105 | size += DWARF_OFFSET_SIZE; | |
6106 | break; | |
a3f97cbb | 6107 | case dw_val_class_loc: |
3f76745e | 6108 | { |
b3694847 | 6109 | unsigned long lsize = size_of_locs (AT_loc (a)); |
71dfc51f | 6110 | |
3f76745e JM |
6111 | /* Block length. */ |
6112 | size += constant_size (lsize); | |
6113 | size += lsize; | |
6114 | } | |
a3f97cbb | 6115 | break; |
63e46568 DB |
6116 | case dw_val_class_loc_list: |
6117 | size += DWARF_OFFSET_SIZE; | |
6118 | break; | |
2bee6045 JJ |
6119 | case dw_val_class_range_list: |
6120 | size += DWARF_OFFSET_SIZE; | |
6121 | break; | |
a3f97cbb | 6122 | case dw_val_class_const: |
25dd13ec | 6123 | size += size_of_sleb128 (AT_int (a)); |
a3f97cbb JW |
6124 | break; |
6125 | case dw_val_class_unsigned_const: | |
a96c67ec | 6126 | size += constant_size (AT_unsigned (a)); |
a3f97cbb | 6127 | break; |
469ac993 | 6128 | case dw_val_class_long_long: |
2e4b9b8c | 6129 | size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */ |
469ac993 JM |
6130 | break; |
6131 | case dw_val_class_float: | |
3f76745e | 6132 | size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */ |
a3f97cbb JW |
6133 | break; |
6134 | case dw_val_class_flag: | |
3f76745e | 6135 | size += 1; |
a3f97cbb JW |
6136 | break; |
6137 | case dw_val_class_die_ref: | |
323658ea ZD |
6138 | if (AT_ref_external (a)) |
6139 | size += DWARF2_ADDR_SIZE; | |
6140 | else | |
6141 | size += DWARF_OFFSET_SIZE; | |
a3f97cbb JW |
6142 | break; |
6143 | case dw_val_class_fde_ref: | |
3f76745e | 6144 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
6145 | break; |
6146 | case dw_val_class_lbl_id: | |
a1a4189d | 6147 | size += DWARF2_ADDR_SIZE; |
3f76745e | 6148 | break; |
8b790721 | 6149 | case dw_val_class_lbl_offset: |
3f76745e JM |
6150 | size += DWARF_OFFSET_SIZE; |
6151 | break; | |
6152 | case dw_val_class_str: | |
9eb4015a JJ |
6153 | if (AT_string_form (a) == DW_FORM_strp) |
6154 | size += DWARF_OFFSET_SIZE; | |
6155 | else | |
17211ab5 | 6156 | size += strlen (a->dw_attr_val.v.val_str->str) + 1; |
3f76745e JM |
6157 | break; |
6158 | default: | |
6159 | abort (); | |
6160 | } | |
a3f97cbb | 6161 | } |
3f76745e JM |
6162 | |
6163 | return size; | |
a3f97cbb JW |
6164 | } |
6165 | ||
2ad9852d RK |
6166 | /* Size the debugging information associated with a given DIE. Visits the |
6167 | DIE's children recursively. Updates the global variable next_die_offset, on | |
6168 | each time through. Uses the current value of next_die_offset to update the | |
6169 | die_offset field in each DIE. */ | |
71dfc51f | 6170 | |
a3f97cbb | 6171 | static void |
7080f735 | 6172 | calc_die_sizes (dw_die_ref die) |
a3f97cbb | 6173 | { |
b3694847 | 6174 | dw_die_ref c; |
2ad9852d | 6175 | |
3f76745e JM |
6176 | die->die_offset = next_die_offset; |
6177 | next_die_offset += size_of_die (die); | |
71dfc51f | 6178 | |
3f76745e JM |
6179 | for (c = die->die_child; c != NULL; c = c->die_sib) |
6180 | calc_die_sizes (c); | |
71dfc51f | 6181 | |
3f76745e JM |
6182 | if (die->die_child != NULL) |
6183 | /* Count the null byte used to terminate sibling lists. */ | |
6184 | next_die_offset += 1; | |
a3f97cbb JW |
6185 | } |
6186 | ||
1bfb5f8f | 6187 | /* Set the marks for a die and its children. We do this so |
881c6935 | 6188 | that we know whether or not a reference needs to use FORM_ref_addr; only |
1bfb5f8f JM |
6189 | DIEs in the same CU will be marked. We used to clear out the offset |
6190 | and use that as the flag, but ran into ordering problems. */ | |
881c6935 JM |
6191 | |
6192 | static void | |
7080f735 | 6193 | mark_dies (dw_die_ref die) |
881c6935 | 6194 | { |
b3694847 | 6195 | dw_die_ref c; |
2ad9852d | 6196 | |
cc0017a9 ZD |
6197 | if (die->die_mark) |
6198 | abort (); | |
7080f735 | 6199 | |
1bfb5f8f JM |
6200 | die->die_mark = 1; |
6201 | for (c = die->die_child; c; c = c->die_sib) | |
6202 | mark_dies (c); | |
6203 | } | |
6204 | ||
6205 | /* Clear the marks for a die and its children. */ | |
6206 | ||
6207 | static void | |
7080f735 | 6208 | unmark_dies (dw_die_ref die) |
1bfb5f8f | 6209 | { |
b3694847 | 6210 | dw_die_ref c; |
2ad9852d | 6211 | |
cc0017a9 ZD |
6212 | if (!die->die_mark) |
6213 | abort (); | |
7080f735 | 6214 | |
1bfb5f8f | 6215 | die->die_mark = 0; |
881c6935 | 6216 | for (c = die->die_child; c; c = c->die_sib) |
1bfb5f8f | 6217 | unmark_dies (c); |
881c6935 JM |
6218 | } |
6219 | ||
cc0017a9 ZD |
6220 | /* Clear the marks for a die, its children and referred dies. */ |
6221 | ||
6222 | static void | |
7080f735 | 6223 | unmark_all_dies (dw_die_ref die) |
cc0017a9 ZD |
6224 | { |
6225 | dw_die_ref c; | |
6226 | dw_attr_ref a; | |
6227 | ||
6228 | if (!die->die_mark) | |
6229 | return; | |
6230 | die->die_mark = 0; | |
6231 | ||
6232 | for (c = die->die_child; c; c = c->die_sib) | |
6233 | unmark_all_dies (c); | |
6234 | ||
6235 | for (a = die->die_attr; a; a = a->dw_attr_next) | |
6236 | if (AT_class (a) == dw_val_class_die_ref) | |
6237 | unmark_all_dies (AT_ref (a)); | |
6238 | } | |
6239 | ||
3f76745e JM |
6240 | /* Return the size of the .debug_pubnames table generated for the |
6241 | compilation unit. */ | |
a94dbf2c | 6242 | |
3f76745e | 6243 | static unsigned long |
7080f735 | 6244 | size_of_pubnames (void) |
a94dbf2c | 6245 | { |
b3694847 SS |
6246 | unsigned long size; |
6247 | unsigned i; | |
469ac993 | 6248 | |
3f76745e | 6249 | size = DWARF_PUBNAMES_HEADER_SIZE; |
2ad9852d | 6250 | for (i = 0; i < pubname_table_in_use; i++) |
a94dbf2c | 6251 | { |
b3694847 | 6252 | pubname_ref p = &pubname_table[i]; |
9eb4015a | 6253 | size += DWARF_OFFSET_SIZE + strlen (p->name) + 1; |
a94dbf2c JM |
6254 | } |
6255 | ||
3f76745e JM |
6256 | size += DWARF_OFFSET_SIZE; |
6257 | return size; | |
a94dbf2c JM |
6258 | } |
6259 | ||
956d6950 | 6260 | /* Return the size of the information in the .debug_aranges section. */ |
469ac993 | 6261 | |
3f76745e | 6262 | static unsigned long |
7080f735 | 6263 | size_of_aranges (void) |
469ac993 | 6264 | { |
b3694847 | 6265 | unsigned long size; |
469ac993 | 6266 | |
3f76745e | 6267 | size = DWARF_ARANGES_HEADER_SIZE; |
469ac993 | 6268 | |
3f76745e | 6269 | /* Count the address/length pair for this compilation unit. */ |
a1a4189d JB |
6270 | size += 2 * DWARF2_ADDR_SIZE; |
6271 | size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use; | |
469ac993 | 6272 | |
3f76745e | 6273 | /* Count the two zero words used to terminated the address range table. */ |
a1a4189d | 6274 | size += 2 * DWARF2_ADDR_SIZE; |
3f76745e JM |
6275 | return size; |
6276 | } | |
6277 | \f | |
6278 | /* Select the encoding of an attribute value. */ | |
6279 | ||
6280 | static enum dwarf_form | |
7080f735 | 6281 | value_format (dw_attr_ref a) |
3f76745e | 6282 | { |
a96c67ec | 6283 | switch (a->dw_attr_val.val_class) |
469ac993 | 6284 | { |
3f76745e JM |
6285 | case dw_val_class_addr: |
6286 | return DW_FORM_addr; | |
2bee6045 | 6287 | case dw_val_class_range_list: |
a20612aa RH |
6288 | case dw_val_class_offset: |
6289 | if (DWARF_OFFSET_SIZE == 4) | |
6290 | return DW_FORM_data4; | |
6291 | if (DWARF_OFFSET_SIZE == 8) | |
6292 | return DW_FORM_data8; | |
6293 | abort (); | |
63e46568 | 6294 | case dw_val_class_loc_list: |
9d2f2c45 RH |
6295 | /* FIXME: Could be DW_FORM_data8, with a > 32 bit size |
6296 | .debug_loc section */ | |
6297 | return DW_FORM_data4; | |
3f76745e | 6298 | case dw_val_class_loc: |
a96c67ec | 6299 | switch (constant_size (size_of_locs (AT_loc (a)))) |
469ac993 | 6300 | { |
3f76745e JM |
6301 | case 1: |
6302 | return DW_FORM_block1; | |
6303 | case 2: | |
6304 | return DW_FORM_block2; | |
469ac993 JM |
6305 | default: |
6306 | abort (); | |
6307 | } | |
3f76745e | 6308 | case dw_val_class_const: |
25dd13ec | 6309 | return DW_FORM_sdata; |
3f76745e | 6310 | case dw_val_class_unsigned_const: |
a96c67ec | 6311 | switch (constant_size (AT_unsigned (a))) |
3f76745e JM |
6312 | { |
6313 | case 1: | |
6314 | return DW_FORM_data1; | |
6315 | case 2: | |
6316 | return DW_FORM_data2; | |
6317 | case 4: | |
6318 | return DW_FORM_data4; | |
6319 | case 8: | |
6320 | return DW_FORM_data8; | |
6321 | default: | |
6322 | abort (); | |
6323 | } | |
6324 | case dw_val_class_long_long: | |
6325 | return DW_FORM_block1; | |
6326 | case dw_val_class_float: | |
6327 | return DW_FORM_block1; | |
6328 | case dw_val_class_flag: | |
6329 | return DW_FORM_flag; | |
6330 | case dw_val_class_die_ref: | |
881c6935 JM |
6331 | if (AT_ref_external (a)) |
6332 | return DW_FORM_ref_addr; | |
6333 | else | |
6334 | return DW_FORM_ref; | |
3f76745e JM |
6335 | case dw_val_class_fde_ref: |
6336 | return DW_FORM_data; | |
6337 | case dw_val_class_lbl_id: | |
6338 | return DW_FORM_addr; | |
8b790721 | 6339 | case dw_val_class_lbl_offset: |
3f76745e JM |
6340 | return DW_FORM_data; |
6341 | case dw_val_class_str: | |
9eb4015a | 6342 | return AT_string_form (a); |
a20612aa | 6343 | |
469ac993 JM |
6344 | default: |
6345 | abort (); | |
6346 | } | |
a94dbf2c JM |
6347 | } |
6348 | ||
3f76745e | 6349 | /* Output the encoding of an attribute value. */ |
469ac993 | 6350 | |
3f76745e | 6351 | static void |
7080f735 | 6352 | output_value_format (dw_attr_ref a) |
a94dbf2c | 6353 | { |
a96c67ec | 6354 | enum dwarf_form form = value_format (a); |
2ad9852d | 6355 | |
2e4b9b8c | 6356 | dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form)); |
3f76745e | 6357 | } |
469ac993 | 6358 | |
3f76745e JM |
6359 | /* Output the .debug_abbrev section which defines the DIE abbreviation |
6360 | table. */ | |
469ac993 | 6361 | |
3f76745e | 6362 | static void |
7080f735 | 6363 | output_abbrev_section (void) |
3f76745e JM |
6364 | { |
6365 | unsigned long abbrev_id; | |
71dfc51f | 6366 | |
3f76745e | 6367 | dw_attr_ref a_attr; |
2ad9852d | 6368 | |
3f76745e JM |
6369 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
6370 | { | |
b3694847 | 6371 | dw_die_ref abbrev = abbrev_die_table[abbrev_id]; |
71dfc51f | 6372 | |
2e4b9b8c | 6373 | dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)"); |
2e4b9b8c RH |
6374 | dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)", |
6375 | dwarf_tag_name (abbrev->die_tag)); | |
71dfc51f | 6376 | |
2e4b9b8c RH |
6377 | if (abbrev->die_child != NULL) |
6378 | dw2_asm_output_data (1, DW_children_yes, "DW_children_yes"); | |
6379 | else | |
6380 | dw2_asm_output_data (1, DW_children_no, "DW_children_no"); | |
3f76745e JM |
6381 | |
6382 | for (a_attr = abbrev->die_attr; a_attr != NULL; | |
6383 | a_attr = a_attr->dw_attr_next) | |
6384 | { | |
2e4b9b8c RH |
6385 | dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)", |
6386 | dwarf_attr_name (a_attr->dw_attr)); | |
a96c67ec | 6387 | output_value_format (a_attr); |
469ac993 | 6388 | } |
469ac993 | 6389 | |
2e4b9b8c RH |
6390 | dw2_asm_output_data (1, 0, NULL); |
6391 | dw2_asm_output_data (1, 0, NULL); | |
469ac993 | 6392 | } |
81f374eb HPN |
6393 | |
6394 | /* Terminate the table. */ | |
2e4b9b8c | 6395 | dw2_asm_output_data (1, 0, NULL); |
a94dbf2c JM |
6396 | } |
6397 | ||
881c6935 JM |
6398 | /* Output a symbol we can use to refer to this DIE from another CU. */ |
6399 | ||
6400 | static inline void | |
7080f735 | 6401 | output_die_symbol (dw_die_ref die) |
881c6935 JM |
6402 | { |
6403 | char *sym = die->die_symbol; | |
6404 | ||
6405 | if (sym == 0) | |
6406 | return; | |
6407 | ||
6408 | if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0) | |
6409 | /* We make these global, not weak; if the target doesn't support | |
6410 | .linkonce, it doesn't support combining the sections, so debugging | |
6411 | will break. */ | |
5eb99654 | 6412 | (*targetm.asm_out.globalize_label) (asm_out_file, sym); |
2ad9852d | 6413 | |
881c6935 JM |
6414 | ASM_OUTPUT_LABEL (asm_out_file, sym); |
6415 | } | |
6416 | ||
84a5b4f8 | 6417 | /* Return a new location list, given the begin and end range, and the |
2ad9852d RK |
6418 | expression. gensym tells us whether to generate a new internal symbol for |
6419 | this location list node, which is done for the head of the list only. */ | |
6420 | ||
84a5b4f8 | 6421 | static inline dw_loc_list_ref |
7080f735 AJ |
6422 | new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end, |
6423 | const char *section, unsigned int gensym) | |
84a5b4f8 | 6424 | { |
17211ab5 | 6425 | dw_loc_list_ref retlist = ggc_alloc_cleared (sizeof (dw_loc_list_node)); |
2ad9852d | 6426 | |
84a5b4f8 DB |
6427 | retlist->begin = begin; |
6428 | retlist->end = end; | |
6429 | retlist->expr = expr; | |
6430 | retlist->section = section; | |
c26fbbca | 6431 | if (gensym) |
84a5b4f8 | 6432 | retlist->ll_symbol = gen_internal_sym ("LLST"); |
2ad9852d | 6433 | |
84a5b4f8 DB |
6434 | return retlist; |
6435 | } | |
6436 | ||
f9da5064 | 6437 | /* Add a location description expression to a location list. */ |
2ad9852d | 6438 | |
84a5b4f8 | 6439 | static inline void |
7080f735 AJ |
6440 | add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr, |
6441 | const char *begin, const char *end, | |
6442 | const char *section) | |
84a5b4f8 | 6443 | { |
b3694847 | 6444 | dw_loc_list_ref *d; |
c26fbbca | 6445 | |
30f7a378 | 6446 | /* Find the end of the chain. */ |
84a5b4f8 DB |
6447 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) |
6448 | ; | |
2ad9852d | 6449 | |
f9da5064 | 6450 | /* Add a new location list node to the list. */ |
84a5b4f8 DB |
6451 | *d = new_loc_list (descr, begin, end, section, 0); |
6452 | } | |
6453 | ||
f9da5064 | 6454 | /* Output the location list given to us. */ |
2ad9852d | 6455 | |
63e46568 | 6456 | static void |
7080f735 | 6457 | output_loc_list (dw_loc_list_ref list_head) |
63e46568 | 6458 | { |
2ad9852d RK |
6459 | dw_loc_list_ref curr = list_head; |
6460 | ||
63e46568 | 6461 | ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol); |
a20612aa RH |
6462 | |
6463 | /* ??? This shouldn't be needed now that we've forced the | |
6464 | compilation unit base address to zero when there is code | |
6465 | in more than one section. */ | |
63e46568 DB |
6466 | if (strcmp (curr->section, ".text") == 0) |
6467 | { | |
aafdcfcd | 6468 | /* dw2_asm_output_data will mask off any extra bits in the ~0. */ |
c4f2c499 | 6469 | dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0, |
aafdcfcd NS |
6470 | "Location list base address specifier fake entry"); |
6471 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section, | |
6472 | "Location list base address specifier base"); | |
63e46568 | 6473 | } |
2ad9852d | 6474 | |
c26fbbca | 6475 | for (curr = list_head; curr != NULL; curr = curr->dw_loc_next) |
63e46568 | 6476 | { |
2bee6045 | 6477 | unsigned long size; |
2ad9852d | 6478 | |
aafdcfcd NS |
6479 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section, |
6480 | "Location list begin address (%s)", | |
6481 | list_head->ll_symbol); | |
6482 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section, | |
6483 | "Location list end address (%s)", | |
6484 | list_head->ll_symbol); | |
63e46568 | 6485 | size = size_of_locs (curr->expr); |
c26fbbca | 6486 | |
63e46568 | 6487 | /* Output the block length for this list of location operations. */ |
2bee6045 JJ |
6488 | if (size > 0xffff) |
6489 | abort (); | |
6490 | dw2_asm_output_data (2, size, "%s", "Location expression size"); | |
6491 | ||
63e46568 DB |
6492 | output_loc_sequence (curr->expr); |
6493 | } | |
2ad9852d | 6494 | |
aafdcfcd NS |
6495 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, |
6496 | "Location list terminator begin (%s)", | |
6497 | list_head->ll_symbol); | |
6498 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, | |
6499 | "Location list terminator end (%s)", | |
6500 | list_head->ll_symbol); | |
63e46568 | 6501 | } |
9eb4015a | 6502 | |
3f76745e JM |
6503 | /* Output the DIE and its attributes. Called recursively to generate |
6504 | the definitions of each child DIE. */ | |
71dfc51f | 6505 | |
a3f97cbb | 6506 | static void |
7080f735 | 6507 | output_die (dw_die_ref die) |
a3f97cbb | 6508 | { |
b3694847 SS |
6509 | dw_attr_ref a; |
6510 | dw_die_ref c; | |
6511 | unsigned long size; | |
a94dbf2c | 6512 | |
881c6935 JM |
6513 | /* If someone in another CU might refer to us, set up a symbol for |
6514 | them to point to. */ | |
6515 | if (die->die_symbol) | |
6516 | output_die_symbol (die); | |
6517 | ||
2e4b9b8c RH |
6518 | dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)", |
6519 | die->die_offset, dwarf_tag_name (die->die_tag)); | |
a94dbf2c | 6520 | |
3f76745e | 6521 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
a3f97cbb | 6522 | { |
2e4b9b8c RH |
6523 | const char *name = dwarf_attr_name (a->dw_attr); |
6524 | ||
a96c67ec | 6525 | switch (AT_class (a)) |
3f76745e JM |
6526 | { |
6527 | case dw_val_class_addr: | |
2e4b9b8c | 6528 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name); |
3f76745e | 6529 | break; |
a3f97cbb | 6530 | |
a20612aa RH |
6531 | case dw_val_class_offset: |
6532 | dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset, | |
6533 | "%s", name); | |
6534 | break; | |
6535 | ||
2bee6045 JJ |
6536 | case dw_val_class_range_list: |
6537 | { | |
6538 | char *p = strchr (ranges_section_label, '\0'); | |
6539 | ||
6540 | sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset); | |
6541 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label, | |
6542 | "%s", name); | |
6543 | *p = '\0'; | |
6544 | } | |
6545 | break; | |
6546 | ||
3f76745e | 6547 | case dw_val_class_loc: |
a96c67ec | 6548 | size = size_of_locs (AT_loc (a)); |
71dfc51f | 6549 | |
3f76745e | 6550 | /* Output the block length for this list of location operations. */ |
2e4b9b8c | 6551 | dw2_asm_output_data (constant_size (size), size, "%s", name); |
71dfc51f | 6552 | |
7d9d8943 | 6553 | output_loc_sequence (AT_loc (a)); |
a3f97cbb | 6554 | break; |
3f76745e JM |
6555 | |
6556 | case dw_val_class_const: | |
25dd13ec JW |
6557 | /* ??? It would be slightly more efficient to use a scheme like is |
6558 | used for unsigned constants below, but gdb 4.x does not sign | |
6559 | extend. Gdb 5.x does sign extend. */ | |
2e4b9b8c | 6560 | dw2_asm_output_data_sleb128 (AT_int (a), "%s", name); |
a3f97cbb | 6561 | break; |
3f76745e JM |
6562 | |
6563 | case dw_val_class_unsigned_const: | |
2e4b9b8c RH |
6564 | dw2_asm_output_data (constant_size (AT_unsigned (a)), |
6565 | AT_unsigned (a), "%s", name); | |
a3f97cbb | 6566 | break; |
3f76745e JM |
6567 | |
6568 | case dw_val_class_long_long: | |
2e4b9b8c RH |
6569 | { |
6570 | unsigned HOST_WIDE_INT first, second; | |
3f76745e | 6571 | |
2ad9852d RK |
6572 | dw2_asm_output_data (1, |
6573 | 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, | |
c26fbbca | 6574 | "%s", name); |
556273e0 | 6575 | |
2e4b9b8c RH |
6576 | if (WORDS_BIG_ENDIAN) |
6577 | { | |
6578 | first = a->dw_attr_val.v.val_long_long.hi; | |
6579 | second = a->dw_attr_val.v.val_long_long.low; | |
6580 | } | |
6581 | else | |
6582 | { | |
6583 | first = a->dw_attr_val.v.val_long_long.low; | |
6584 | second = a->dw_attr_val.v.val_long_long.hi; | |
6585 | } | |
2ad9852d RK |
6586 | |
6587 | dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, | |
2e4b9b8c | 6588 | first, "long long constant"); |
2ad9852d | 6589 | dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, |
2e4b9b8c RH |
6590 | second, NULL); |
6591 | } | |
a3f97cbb | 6592 | break; |
3f76745e JM |
6593 | |
6594 | case dw_val_class_float: | |
c84e2712 | 6595 | { |
b3694847 | 6596 | unsigned int i; |
c84e2712 | 6597 | |
2e4b9b8c | 6598 | dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4, |
c26fbbca | 6599 | "%s", name); |
c84e2712 | 6600 | |
2ad9852d | 6601 | for (i = 0; i < a->dw_attr_val.v.val_float.length; i++) |
2e4b9b8c RH |
6602 | dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i], |
6603 | "fp constant word %u", i); | |
556273e0 | 6604 | break; |
c84e2712 | 6605 | } |
3f76745e JM |
6606 | |
6607 | case dw_val_class_flag: | |
2e4b9b8c | 6608 | dw2_asm_output_data (1, AT_flag (a), "%s", name); |
a3f97cbb | 6609 | break; |
a20612aa | 6610 | |
c26fbbca | 6611 | case dw_val_class_loc_list: |
63e46568 DB |
6612 | { |
6613 | char *sym = AT_loc_list (a)->ll_symbol; | |
2ad9852d | 6614 | |
63e46568 | 6615 | if (sym == 0) |
173bf5be | 6616 | abort (); |
a20612aa RH |
6617 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, |
6618 | loc_section_label, "%s", name); | |
63e46568 DB |
6619 | } |
6620 | break; | |
a20612aa | 6621 | |
3f76745e | 6622 | case dw_val_class_die_ref: |
881c6935 | 6623 | if (AT_ref_external (a)) |
2e4b9b8c RH |
6624 | { |
6625 | char *sym = AT_ref (a)->die_symbol; | |
2ad9852d | 6626 | |
2e4b9b8c RH |
6627 | if (sym == 0) |
6628 | abort (); | |
6629 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name); | |
6630 | } | |
3f4907a6 JM |
6631 | else if (AT_ref (a)->die_offset == 0) |
6632 | abort (); | |
881c6935 | 6633 | else |
2e4b9b8c RH |
6634 | dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset, |
6635 | "%s", name); | |
a3f97cbb | 6636 | break; |
3f76745e JM |
6637 | |
6638 | case dw_val_class_fde_ref: | |
a6ab3aad JM |
6639 | { |
6640 | char l1[20]; | |
2ad9852d | 6641 | |
2e4b9b8c RH |
6642 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL, |
6643 | a->dw_attr_val.v.val_fde_index * 2); | |
6644 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name); | |
a6ab3aad | 6645 | } |
a3f97cbb | 6646 | break; |
a3f97cbb | 6647 | |
3f76745e | 6648 | case dw_val_class_lbl_id: |
8e7fa2c8 | 6649 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 6650 | break; |
71dfc51f | 6651 | |
8b790721 | 6652 | case dw_val_class_lbl_offset: |
2e4b9b8c | 6653 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 6654 | break; |
a3f97cbb | 6655 | |
3f76745e | 6656 | case dw_val_class_str: |
9eb4015a JJ |
6657 | if (AT_string_form (a) == DW_FORM_strp) |
6658 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, | |
6659 | a->dw_attr_val.v.val_str->label, | |
a4cf1d85 | 6660 | "%s: \"%s\"", name, AT_string (a)); |
9eb4015a JJ |
6661 | else |
6662 | dw2_asm_output_nstring (AT_string (a), -1, "%s", name); | |
3f76745e | 6663 | break; |
b2932ae5 | 6664 | |
3f76745e JM |
6665 | default: |
6666 | abort (); | |
6667 | } | |
3f76745e | 6668 | } |
71dfc51f | 6669 | |
3f76745e JM |
6670 | for (c = die->die_child; c != NULL; c = c->die_sib) |
6671 | output_die (c); | |
71dfc51f | 6672 | |
2ad9852d | 6673 | /* Add null byte to terminate sibling list. */ |
3f76745e | 6674 | if (die->die_child != NULL) |
2ad9852d RK |
6675 | dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx", |
6676 | die->die_offset); | |
3f76745e | 6677 | } |
71dfc51f | 6678 | |
3f76745e JM |
6679 | /* Output the compilation unit that appears at the beginning of the |
6680 | .debug_info section, and precedes the DIE descriptions. */ | |
71dfc51f | 6681 | |
3f76745e | 6682 | static void |
7080f735 | 6683 | output_compilation_unit_header (void) |
3f76745e | 6684 | { |
9eb0ef7a KB |
6685 | if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4) |
6686 | dw2_asm_output_data (4, 0xffffffff, | |
6687 | "Initial length escape value indicating 64-bit DWARF extension"); | |
6688 | dw2_asm_output_data (DWARF_OFFSET_SIZE, | |
6689 | next_die_offset - DWARF_INITIAL_LENGTH_SIZE, | |
2e4b9b8c | 6690 | "Length of Compilation Unit Info"); |
2e4b9b8c | 6691 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number"); |
2e4b9b8c RH |
6692 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label, |
6693 | "Offset Into Abbrev. Section"); | |
2e4b9b8c | 6694 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)"); |
a3f97cbb JW |
6695 | } |
6696 | ||
881c6935 JM |
6697 | /* Output the compilation unit DIE and its children. */ |
6698 | ||
6699 | static void | |
7080f735 | 6700 | output_comp_unit (dw_die_ref die, int output_if_empty) |
881c6935 | 6701 | { |
ce1cc601 | 6702 | const char *secname; |
cc0017a9 ZD |
6703 | char *oldsym, *tmp; |
6704 | ||
6705 | /* Unless we are outputting main CU, we may throw away empty ones. */ | |
6706 | if (!output_if_empty && die->die_child == NULL) | |
6707 | return; | |
881c6935 | 6708 | |
2ad9852d RK |
6709 | /* Even if there are no children of this DIE, we must output the information |
6710 | about the compilation unit. Otherwise, on an empty translation unit, we | |
6711 | will generate a present, but empty, .debug_info section. IRIX 6.5 `nm' | |
6712 | will then complain when examining the file. First mark all the DIEs in | |
6713 | this CU so we know which get local refs. */ | |
1bfb5f8f JM |
6714 | mark_dies (die); |
6715 | ||
6716 | build_abbrev_table (die); | |
6717 | ||
6d2f8887 | 6718 | /* Initialize the beginning DIE offset - and calculate sizes/offsets. */ |
881c6935 JM |
6719 | next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE; |
6720 | calc_die_sizes (die); | |
6721 | ||
cc0017a9 ZD |
6722 | oldsym = die->die_symbol; |
6723 | if (oldsym) | |
881c6935 | 6724 | { |
703ad42b | 6725 | tmp = alloca (strlen (oldsym) + 24); |
2ad9852d | 6726 | |
cc0017a9 | 6727 | sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym); |
ce1cc601 | 6728 | secname = tmp; |
881c6935 JM |
6729 | die->die_symbol = NULL; |
6730 | } | |
6731 | else | |
ce1cc601 | 6732 | secname = (const char *) DEBUG_INFO_SECTION; |
881c6935 JM |
6733 | |
6734 | /* Output debugging information. */ | |
715bdd29 | 6735 | named_section_flags (secname, SECTION_DEBUG); |
881c6935 JM |
6736 | output_compilation_unit_header (); |
6737 | output_die (die); | |
6738 | ||
1bfb5f8f JM |
6739 | /* Leave the marks on the main CU, so we can check them in |
6740 | output_pubnames. */ | |
cc0017a9 ZD |
6741 | if (oldsym) |
6742 | { | |
6743 | unmark_dies (die); | |
6744 | die->die_symbol = oldsym; | |
6745 | } | |
881c6935 JM |
6746 | } |
6747 | ||
7afff7cf NB |
6748 | /* The DWARF2 pubname for a nested thingy looks like "A::f". The |
6749 | output of lang_hooks.decl_printable_name for C++ looks like | |
6750 | "A::f(int)". Let's drop the argument list, and maybe the scope. */ | |
a1d7ffe3 | 6751 | |
d560ee52 | 6752 | static const char * |
7080f735 | 6753 | dwarf2_name (tree decl, int scope) |
a1d7ffe3 | 6754 | { |
7afff7cf | 6755 | return (*lang_hooks.decl_printable_name) (decl, scope ? 1 : 0); |
a1d7ffe3 JM |
6756 | } |
6757 | ||
d291dd49 | 6758 | /* Add a new entry to .debug_pubnames if appropriate. */ |
71dfc51f | 6759 | |
d291dd49 | 6760 | static void |
7080f735 | 6761 | add_pubname (tree decl, dw_die_ref die) |
d291dd49 JM |
6762 | { |
6763 | pubname_ref p; | |
6764 | ||
6765 | if (! TREE_PUBLIC (decl)) | |
6766 | return; | |
6767 | ||
6768 | if (pubname_table_in_use == pubname_table_allocated) | |
6769 | { | |
6770 | pubname_table_allocated += PUBNAME_TABLE_INCREMENT; | |
2ad9852d | 6771 | pubname_table |
703ad42b KG |
6772 | = ggc_realloc (pubname_table, |
6773 | (pubname_table_allocated * sizeof (pubname_entry))); | |
17211ab5 GK |
6774 | memset (pubname_table + pubname_table_in_use, 0, |
6775 | PUBNAME_TABLE_INCREMENT * sizeof (pubname_entry)); | |
d291dd49 | 6776 | } |
71dfc51f | 6777 | |
d291dd49 JM |
6778 | p = &pubname_table[pubname_table_in_use++]; |
6779 | p->die = die; | |
a1d7ffe3 | 6780 | p->name = xstrdup (dwarf2_name (decl, 1)); |
d291dd49 JM |
6781 | } |
6782 | ||
a3f97cbb JW |
6783 | /* Output the public names table used to speed up access to externally |
6784 | visible names. For now, only generate entries for externally | |
6785 | visible procedures. */ | |
71dfc51f | 6786 | |
a3f97cbb | 6787 | static void |
7080f735 | 6788 | output_pubnames (void) |
a3f97cbb | 6789 | { |
b3694847 SS |
6790 | unsigned i; |
6791 | unsigned long pubnames_length = size_of_pubnames (); | |
71dfc51f | 6792 | |
9eb0ef7a KB |
6793 | if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4) |
6794 | dw2_asm_output_data (4, 0xffffffff, | |
6795 | "Initial length escape value indicating 64-bit DWARF extension"); | |
2e4b9b8c RH |
6796 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, |
6797 | "Length of Public Names Info"); | |
2e4b9b8c | 6798 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
2e4b9b8c RH |
6799 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
6800 | "Offset of Compilation Unit Info"); | |
2e4b9b8c RH |
6801 | dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset, |
6802 | "Compilation Unit Length"); | |
71dfc51f | 6803 | |
2ad9852d | 6804 | for (i = 0; i < pubname_table_in_use; i++) |
a3f97cbb | 6805 | { |
b3694847 | 6806 | pubname_ref pub = &pubname_table[i]; |
71dfc51f | 6807 | |
881c6935 | 6808 | /* We shouldn't see pubnames for DIEs outside of the main CU. */ |
1bfb5f8f | 6809 | if (pub->die->die_mark == 0) |
881c6935 JM |
6810 | abort (); |
6811 | ||
2e4b9b8c RH |
6812 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset, |
6813 | "DIE offset"); | |
71dfc51f | 6814 | |
2e4b9b8c | 6815 | dw2_asm_output_nstring (pub->name, -1, "external name"); |
a3f97cbb | 6816 | } |
71dfc51f | 6817 | |
2e4b9b8c | 6818 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL); |
a3f97cbb JW |
6819 | } |
6820 | ||
d291dd49 | 6821 | /* Add a new entry to .debug_aranges if appropriate. */ |
71dfc51f | 6822 | |
d291dd49 | 6823 | static void |
7080f735 | 6824 | add_arange (tree decl, dw_die_ref die) |
d291dd49 JM |
6825 | { |
6826 | if (! DECL_SECTION_NAME (decl)) | |
6827 | return; | |
6828 | ||
6829 | if (arange_table_in_use == arange_table_allocated) | |
6830 | { | |
6831 | arange_table_allocated += ARANGE_TABLE_INCREMENT; | |
7080f735 AJ |
6832 | arange_table = ggc_realloc (arange_table, |
6833 | (arange_table_allocated | |
17211ab5 GK |
6834 | * sizeof (dw_die_ref))); |
6835 | memset (arange_table + arange_table_in_use, 0, | |
6836 | ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref)); | |
d291dd49 | 6837 | } |
71dfc51f | 6838 | |
d291dd49 JM |
6839 | arange_table[arange_table_in_use++] = die; |
6840 | } | |
6841 | ||
a3f97cbb JW |
6842 | /* Output the information that goes into the .debug_aranges table. |
6843 | Namely, define the beginning and ending address range of the | |
6844 | text section generated for this compilation unit. */ | |
71dfc51f | 6845 | |
a3f97cbb | 6846 | static void |
7080f735 | 6847 | output_aranges (void) |
a3f97cbb | 6848 | { |
b3694847 SS |
6849 | unsigned i; |
6850 | unsigned long aranges_length = size_of_aranges (); | |
71dfc51f | 6851 | |
9eb0ef7a KB |
6852 | if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4) |
6853 | dw2_asm_output_data (4, 0xffffffff, | |
6854 | "Initial length escape value indicating 64-bit DWARF extension"); | |
2e4b9b8c RH |
6855 | dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length, |
6856 | "Length of Address Ranges Info"); | |
2e4b9b8c | 6857 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
2e4b9b8c RH |
6858 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
6859 | "Offset of Compilation Unit Info"); | |
2e4b9b8c | 6860 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address"); |
2e4b9b8c | 6861 | dw2_asm_output_data (1, 0, "Size of Segment Descriptor"); |
71dfc51f | 6862 | |
262b6384 SC |
6863 | /* We need to align to twice the pointer size here. */ |
6864 | if (DWARF_ARANGES_PAD_SIZE) | |
6865 | { | |
2e4b9b8c | 6866 | /* Pad using a 2 byte words so that padding is correct for any |
73c68f61 | 6867 | pointer size. */ |
2e4b9b8c RH |
6868 | dw2_asm_output_data (2, 0, "Pad to %d byte boundary", |
6869 | 2 * DWARF2_ADDR_SIZE); | |
770ca8c6 | 6870 | for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2) |
2e4b9b8c | 6871 | dw2_asm_output_data (2, 0, NULL); |
262b6384 | 6872 | } |
71dfc51f | 6873 | |
8e7fa2c8 | 6874 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address"); |
2e4b9b8c RH |
6875 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label, |
6876 | text_section_label, "Length"); | |
71dfc51f | 6877 | |
2ad9852d | 6878 | for (i = 0; i < arange_table_in_use; i++) |
d291dd49 | 6879 | { |
e689ae67 | 6880 | dw_die_ref die = arange_table[i]; |
71dfc51f | 6881 | |
881c6935 | 6882 | /* We shouldn't see aranges for DIEs outside of the main CU. */ |
1bfb5f8f | 6883 | if (die->die_mark == 0) |
881c6935 JM |
6884 | abort (); |
6885 | ||
e689ae67 | 6886 | if (die->die_tag == DW_TAG_subprogram) |
2e4b9b8c | 6887 | { |
8e7fa2c8 | 6888 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die), |
173bf5be | 6889 | "Address"); |
2e4b9b8c RH |
6890 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die), |
6891 | get_AT_low_pc (die), "Length"); | |
6892 | } | |
d291dd49 | 6893 | else |
a1d7ffe3 | 6894 | { |
e689ae67 JM |
6895 | /* A static variable; extract the symbol from DW_AT_location. |
6896 | Note that this code isn't currently hit, as we only emit | |
6897 | aranges for functions (jason 9/23/99). */ | |
e689ae67 JM |
6898 | dw_attr_ref a = get_AT (die, DW_AT_location); |
6899 | dw_loc_descr_ref loc; | |
2ad9852d | 6900 | |
a96c67ec | 6901 | if (! a || AT_class (a) != dw_val_class_loc) |
e689ae67 JM |
6902 | abort (); |
6903 | ||
a96c67ec | 6904 | loc = AT_loc (a); |
e689ae67 JM |
6905 | if (loc->dw_loc_opc != DW_OP_addr) |
6906 | abort (); | |
6907 | ||
2e4b9b8c RH |
6908 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, |
6909 | loc->dw_loc_oprnd1.v.val_addr, "Address"); | |
6910 | dw2_asm_output_data (DWARF2_ADDR_SIZE, | |
6911 | get_AT_unsigned (die, DW_AT_byte_size), | |
6912 | "Length"); | |
a1d7ffe3 | 6913 | } |
d291dd49 | 6914 | } |
71dfc51f | 6915 | |
a3f97cbb | 6916 | /* Output the terminator words. */ |
2e4b9b8c RH |
6917 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); |
6918 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
a3f97cbb JW |
6919 | } |
6920 | ||
a20612aa RH |
6921 | /* Add a new entry to .debug_ranges. Return the offset at which it |
6922 | was placed. */ | |
6923 | ||
6924 | static unsigned int | |
7080f735 | 6925 | add_ranges (tree block) |
a20612aa RH |
6926 | { |
6927 | unsigned int in_use = ranges_table_in_use; | |
6928 | ||
6929 | if (in_use == ranges_table_allocated) | |
6930 | { | |
6931 | ranges_table_allocated += RANGES_TABLE_INCREMENT; | |
703ad42b KG |
6932 | ranges_table |
6933 | = ggc_realloc (ranges_table, (ranges_table_allocated | |
6934 | * sizeof (struct dw_ranges_struct))); | |
17211ab5 GK |
6935 | memset (ranges_table + ranges_table_in_use, 0, |
6936 | RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct)); | |
a20612aa RH |
6937 | } |
6938 | ||
6939 | ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0); | |
6940 | ranges_table_in_use = in_use + 1; | |
6941 | ||
6942 | return in_use * 2 * DWARF2_ADDR_SIZE; | |
6943 | } | |
6944 | ||
6945 | static void | |
7080f735 | 6946 | output_ranges (void) |
a20612aa | 6947 | { |
b3694847 | 6948 | unsigned i; |
83182544 | 6949 | static const char *const start_fmt = "Offset 0x%x"; |
a20612aa RH |
6950 | const char *fmt = start_fmt; |
6951 | ||
2ad9852d | 6952 | for (i = 0; i < ranges_table_in_use; i++) |
a20612aa RH |
6953 | { |
6954 | int block_num = ranges_table[i].block_num; | |
6955 | ||
6956 | if (block_num) | |
6957 | { | |
6958 | char blabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6959 | char elabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6960 | ||
6961 | ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num); | |
6962 | ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num); | |
6963 | ||
6964 | /* If all code is in the text section, then the compilation | |
6965 | unit base address defaults to DW_AT_low_pc, which is the | |
6966 | base of the text section. */ | |
6967 | if (separate_line_info_table_in_use == 0) | |
6968 | { | |
6969 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel, | |
6970 | text_section_label, | |
6971 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
6972 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel, | |
6973 | text_section_label, NULL); | |
6974 | } | |
2ad9852d | 6975 | |
a20612aa RH |
6976 | /* Otherwise, we add a DW_AT_entry_pc attribute to force the |
6977 | compilation unit base address to zero, which allows us to | |
6978 | use absolute addresses, and not worry about whether the | |
6979 | target supports cross-section arithmetic. */ | |
6980 | else | |
6981 | { | |
6982 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel, | |
6983 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
6984 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL); | |
6985 | } | |
6986 | ||
6987 | fmt = NULL; | |
6988 | } | |
6989 | else | |
6990 | { | |
6991 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
6992 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
6993 | fmt = start_fmt; | |
6994 | } | |
6995 | } | |
6996 | } | |
0b34cf1e UD |
6997 | |
6998 | /* Data structure containing information about input files. */ | |
6999 | struct file_info | |
7000 | { | |
7001 | char *path; /* Complete file name. */ | |
7002 | char *fname; /* File name part. */ | |
7003 | int length; /* Length of entire string. */ | |
7004 | int file_idx; /* Index in input file table. */ | |
7005 | int dir_idx; /* Index in directory table. */ | |
7006 | }; | |
7007 | ||
7008 | /* Data structure containing information about directories with source | |
7009 | files. */ | |
7010 | struct dir_info | |
7011 | { | |
7012 | char *path; /* Path including directory name. */ | |
7013 | int length; /* Path length. */ | |
7014 | int prefix; /* Index of directory entry which is a prefix. */ | |
0b34cf1e UD |
7015 | int count; /* Number of files in this directory. */ |
7016 | int dir_idx; /* Index of directory used as base. */ | |
7017 | int used; /* Used in the end? */ | |
7018 | }; | |
7019 | ||
7020 | /* Callback function for file_info comparison. We sort by looking at | |
7021 | the directories in the path. */ | |
356b0698 | 7022 | |
0b34cf1e | 7023 | static int |
7080f735 | 7024 | file_info_cmp (const void *p1, const void *p2) |
0b34cf1e UD |
7025 | { |
7026 | const struct file_info *s1 = p1; | |
7027 | const struct file_info *s2 = p2; | |
7028 | unsigned char *cp1; | |
7029 | unsigned char *cp2; | |
7030 | ||
356b0698 RK |
7031 | /* Take care of file names without directories. We need to make sure that |
7032 | we return consistent values to qsort since some will get confused if | |
7033 | we return the same value when identical operands are passed in opposite | |
7034 | orders. So if neither has a directory, return 0 and otherwise return | |
7035 | 1 or -1 depending on which one has the directory. */ | |
7036 | if ((s1->path == s1->fname || s2->path == s2->fname)) | |
7037 | return (s2->path == s2->fname) - (s1->path == s1->fname); | |
0b34cf1e UD |
7038 | |
7039 | cp1 = (unsigned char *) s1->path; | |
7040 | cp2 = (unsigned char *) s2->path; | |
7041 | ||
7042 | while (1) | |
7043 | { | |
7044 | ++cp1; | |
7045 | ++cp2; | |
356b0698 RK |
7046 | /* Reached the end of the first path? If so, handle like above. */ |
7047 | if ((cp1 == (unsigned char *) s1->fname) | |
7048 | || (cp2 == (unsigned char *) s2->fname)) | |
7049 | return ((cp2 == (unsigned char *) s2->fname) | |
7050 | - (cp1 == (unsigned char *) s1->fname)); | |
0b34cf1e UD |
7051 | |
7052 | /* Character of current path component the same? */ | |
356b0698 | 7053 | else if (*cp1 != *cp2) |
0b34cf1e UD |
7054 | return *cp1 - *cp2; |
7055 | } | |
7056 | } | |
7057 | ||
7058 | /* Output the directory table and the file name table. We try to minimize | |
7059 | the total amount of memory needed. A heuristic is used to avoid large | |
7060 | slowdowns with many input files. */ | |
2ad9852d | 7061 | |
0b34cf1e | 7062 | static void |
7080f735 | 7063 | output_file_names (void) |
0b34cf1e UD |
7064 | { |
7065 | struct file_info *files; | |
7066 | struct dir_info *dirs; | |
7067 | int *saved; | |
7068 | int *savehere; | |
7069 | int *backmap; | |
c4274b22 | 7070 | size_t ndirs; |
0b34cf1e | 7071 | int idx_offset; |
c4274b22 | 7072 | size_t i; |
0b34cf1e UD |
7073 | int idx; |
7074 | ||
f0b886ab UW |
7075 | /* Handle the case where file_table is empty. */ |
7076 | if (VARRAY_ACTIVE_SIZE (file_table) <= 1) | |
7077 | { | |
7078 | dw2_asm_output_data (1, 0, "End directory table"); | |
7079 | dw2_asm_output_data (1, 0, "End file name table"); | |
7080 | return; | |
7081 | } | |
7082 | ||
0b34cf1e | 7083 | /* Allocate the various arrays we need. */ |
703ad42b KG |
7084 | files = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (struct file_info)); |
7085 | dirs = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (struct dir_info)); | |
0b34cf1e UD |
7086 | |
7087 | /* Sort the file names. */ | |
c4274b22 | 7088 | for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++) |
0b34cf1e UD |
7089 | { |
7090 | char *f; | |
7091 | ||
7092 | /* Skip all leading "./". */ | |
c4274b22 | 7093 | f = VARRAY_CHAR_PTR (file_table, i); |
0b34cf1e UD |
7094 | while (f[0] == '.' && f[1] == '/') |
7095 | f += 2; | |
7096 | ||
7097 | /* Create a new array entry. */ | |
7098 | files[i].path = f; | |
7099 | files[i].length = strlen (f); | |
7100 | files[i].file_idx = i; | |
7101 | ||
7102 | /* Search for the file name part. */ | |
7103 | f = strrchr (f, '/'); | |
7104 | files[i].fname = f == NULL ? files[i].path : f + 1; | |
7105 | } | |
2ad9852d | 7106 | |
c4274b22 RH |
7107 | qsort (files + 1, VARRAY_ACTIVE_SIZE (file_table) - 1, |
7108 | sizeof (files[0]), file_info_cmp); | |
0b34cf1e UD |
7109 | |
7110 | /* Find all the different directories used. */ | |
7111 | dirs[0].path = files[1].path; | |
7112 | dirs[0].length = files[1].fname - files[1].path; | |
7113 | dirs[0].prefix = -1; | |
0b34cf1e UD |
7114 | dirs[0].count = 1; |
7115 | dirs[0].dir_idx = 0; | |
7116 | dirs[0].used = 0; | |
7117 | files[1].dir_idx = 0; | |
7118 | ndirs = 1; | |
7119 | ||
c4274b22 | 7120 | for (i = 2; i < VARRAY_ACTIVE_SIZE (file_table); i++) |
0b34cf1e UD |
7121 | if (files[i].fname - files[i].path == dirs[ndirs - 1].length |
7122 | && memcmp (dirs[ndirs - 1].path, files[i].path, | |
7123 | dirs[ndirs - 1].length) == 0) | |
7124 | { | |
7125 | /* Same directory as last entry. */ | |
7126 | files[i].dir_idx = ndirs - 1; | |
0b34cf1e UD |
7127 | ++dirs[ndirs - 1].count; |
7128 | } | |
7129 | else | |
7130 | { | |
c4274b22 | 7131 | size_t j; |
0b34cf1e UD |
7132 | |
7133 | /* This is a new directory. */ | |
7134 | dirs[ndirs].path = files[i].path; | |
7135 | dirs[ndirs].length = files[i].fname - files[i].path; | |
0b34cf1e UD |
7136 | dirs[ndirs].count = 1; |
7137 | dirs[ndirs].dir_idx = ndirs; | |
7138 | dirs[ndirs].used = 0; | |
7139 | files[i].dir_idx = ndirs; | |
7140 | ||
7141 | /* Search for a prefix. */ | |
981975b6 | 7142 | dirs[ndirs].prefix = -1; |
2ad9852d | 7143 | for (j = 0; j < ndirs; j++) |
981975b6 RH |
7144 | if (dirs[j].length < dirs[ndirs].length |
7145 | && dirs[j].length > 1 | |
7146 | && (dirs[ndirs].prefix == -1 | |
7147 | || dirs[j].length > dirs[dirs[ndirs].prefix].length) | |
7148 | && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0) | |
7149 | dirs[ndirs].prefix = j; | |
0b34cf1e UD |
7150 | |
7151 | ++ndirs; | |
7152 | } | |
7153 | ||
2ad9852d RK |
7154 | /* Now to the actual work. We have to find a subset of the directories which |
7155 | allow expressing the file name using references to the directory table | |
7156 | with the least amount of characters. We do not do an exhaustive search | |
7157 | where we would have to check out every combination of every single | |
7158 | possible prefix. Instead we use a heuristic which provides nearly optimal | |
7159 | results in most cases and never is much off. */ | |
703ad42b KG |
7160 | saved = alloca (ndirs * sizeof (int)); |
7161 | savehere = alloca (ndirs * sizeof (int)); | |
0b34cf1e UD |
7162 | |
7163 | memset (saved, '\0', ndirs * sizeof (saved[0])); | |
2ad9852d | 7164 | for (i = 0; i < ndirs; i++) |
0b34cf1e | 7165 | { |
c4274b22 | 7166 | size_t j; |
0b34cf1e UD |
7167 | int total; |
7168 | ||
2ad9852d RK |
7169 | /* We can always save some space for the current directory. But this |
7170 | does not mean it will be enough to justify adding the directory. */ | |
0b34cf1e UD |
7171 | savehere[i] = dirs[i].length; |
7172 | total = (savehere[i] - saved[i]) * dirs[i].count; | |
7173 | ||
2ad9852d | 7174 | for (j = i + 1; j < ndirs; j++) |
0b34cf1e UD |
7175 | { |
7176 | savehere[j] = 0; | |
0b34cf1e UD |
7177 | if (saved[j] < dirs[i].length) |
7178 | { | |
7179 | /* Determine whether the dirs[i] path is a prefix of the | |
7180 | dirs[j] path. */ | |
7181 | int k; | |
7182 | ||
981975b6 | 7183 | k = dirs[j].prefix; |
c4274b22 | 7184 | while (k != -1 && k != (int) i) |
981975b6 RH |
7185 | k = dirs[k].prefix; |
7186 | ||
c4274b22 | 7187 | if (k == (int) i) |
981975b6 RH |
7188 | { |
7189 | /* Yes it is. We can possibly safe some memory but | |
7190 | writing the filenames in dirs[j] relative to | |
7191 | dirs[i]. */ | |
7192 | savehere[j] = dirs[i].length; | |
7193 | total += (savehere[j] - saved[j]) * dirs[j].count; | |
7194 | } | |
0b34cf1e UD |
7195 | } |
7196 | } | |
7197 | ||
7198 | /* Check whether we can safe enough to justify adding the dirs[i] | |
7199 | directory. */ | |
7200 | if (total > dirs[i].length + 1) | |
7201 | { | |
981975b6 | 7202 | /* It's worthwhile adding. */ |
c26fbbca | 7203 | for (j = i; j < ndirs; j++) |
0b34cf1e UD |
7204 | if (savehere[j] > 0) |
7205 | { | |
7206 | /* Remember how much we saved for this directory so far. */ | |
7207 | saved[j] = savehere[j]; | |
7208 | ||
7209 | /* Remember the prefix directory. */ | |
7210 | dirs[j].dir_idx = i; | |
7211 | } | |
7212 | } | |
7213 | } | |
7214 | ||
2ad9852d RK |
7215 | /* We have to emit them in the order they appear in the file_table array |
7216 | since the index is used in the debug info generation. To do this | |
7217 | efficiently we generate a back-mapping of the indices first. */ | |
703ad42b | 7218 | backmap = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (int)); |
c4274b22 | 7219 | for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++) |
0b34cf1e UD |
7220 | { |
7221 | backmap[files[i].file_idx] = i; | |
2ad9852d | 7222 | |
0b34cf1e UD |
7223 | /* Mark this directory as used. */ |
7224 | dirs[dirs[files[i].dir_idx].dir_idx].used = 1; | |
7225 | } | |
7226 | ||
2ad9852d RK |
7227 | /* That was it. We are ready to emit the information. First emit the |
7228 | directory name table. We have to make sure the first actually emitted | |
7229 | directory name has index one; zero is reserved for the current working | |
7230 | directory. Make sure we do not confuse these indices with the one for the | |
7231 | constructed table (even though most of the time they are identical). */ | |
0b34cf1e | 7232 | idx = 1; |
e57cabac | 7233 | idx_offset = dirs[0].length > 0 ? 1 : 0; |
2ad9852d | 7234 | for (i = 1 - idx_offset; i < ndirs; i++) |
0b34cf1e UD |
7235 | if (dirs[i].used != 0) |
7236 | { | |
7237 | dirs[i].used = idx++; | |
2e4b9b8c RH |
7238 | dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1, |
7239 | "Directory Entry: 0x%x", dirs[i].used); | |
0b34cf1e | 7240 | } |
2ad9852d | 7241 | |
2e4b9b8c RH |
7242 | dw2_asm_output_data (1, 0, "End directory table"); |
7243 | ||
0b34cf1e UD |
7244 | /* Correct the index for the current working directory entry if it |
7245 | exists. */ | |
7246 | if (idx_offset == 0) | |
7247 | dirs[0].used = 0; | |
0b34cf1e UD |
7248 | |
7249 | /* Now write all the file names. */ | |
c4274b22 | 7250 | for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++) |
0b34cf1e UD |
7251 | { |
7252 | int file_idx = backmap[i]; | |
7253 | int dir_idx = dirs[files[file_idx].dir_idx].dir_idx; | |
7254 | ||
2e4b9b8c | 7255 | dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1, |
94e001a9 | 7256 | "File Entry: 0x%lx", (unsigned long) i); |
0b34cf1e UD |
7257 | |
7258 | /* Include directory index. */ | |
2e4b9b8c | 7259 | dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL); |
0b34cf1e UD |
7260 | |
7261 | /* Modification time. */ | |
2e4b9b8c | 7262 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e UD |
7263 | |
7264 | /* File length in bytes. */ | |
2e4b9b8c | 7265 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e | 7266 | } |
2ad9852d | 7267 | |
2e4b9b8c | 7268 | dw2_asm_output_data (1, 0, "End file name table"); |
0b34cf1e UD |
7269 | } |
7270 | ||
7271 | ||
a3f97cbb | 7272 | /* Output the source line number correspondence information. This |
14a774a9 | 7273 | information goes into the .debug_line section. */ |
71dfc51f | 7274 | |
a3f97cbb | 7275 | static void |
7080f735 | 7276 | output_line_info (void) |
a3f97cbb | 7277 | { |
981975b6 | 7278 | char l1[20], l2[20], p1[20], p2[20]; |
a3f97cbb JW |
7279 | char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
7280 | char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 SS |
7281 | unsigned opc; |
7282 | unsigned n_op_args; | |
7283 | unsigned long lt_index; | |
7284 | unsigned long current_line; | |
7285 | long line_offset; | |
7286 | long line_delta; | |
7287 | unsigned long current_file; | |
7288 | unsigned long function; | |
71dfc51f | 7289 | |
2e4b9b8c RH |
7290 | ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0); |
7291 | ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0); | |
981975b6 RH |
7292 | ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0); |
7293 | ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0); | |
71dfc51f | 7294 | |
9eb0ef7a KB |
7295 | if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4) |
7296 | dw2_asm_output_data (4, 0xffffffff, | |
7297 | "Initial length escape value indicating 64-bit DWARF extension"); | |
2e4b9b8c RH |
7298 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1, |
7299 | "Length of Source Line Info"); | |
7300 | ASM_OUTPUT_LABEL (asm_out_file, l1); | |
71dfc51f | 7301 | |
2e4b9b8c | 7302 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
981975b6 RH |
7303 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length"); |
7304 | ASM_OUTPUT_LABEL (asm_out_file, p1); | |
71dfc51f | 7305 | |
c1a046e5 TT |
7306 | /* Define the architecture-dependent minimum instruction length (in |
7307 | bytes). In this implementation of DWARF, this field is used for | |
7308 | information purposes only. Since GCC generates assembly language, | |
7309 | we have no a priori knowledge of how many instruction bytes are | |
7310 | generated for each source line, and therefore can use only the | |
7311 | DW_LNE_set_address and DW_LNS_fixed_advance_pc line information | |
7312 | commands. Accordingly, we fix this as `1', which is "correct | |
7313 | enough" for all architectures, and don't let the target override. */ | |
7314 | dw2_asm_output_data (1, 1, | |
2e4b9b8c | 7315 | "Minimum Instruction Length"); |
c1a046e5 | 7316 | |
2e4b9b8c RH |
7317 | dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START, |
7318 | "Default is_stmt_start flag"); | |
2e4b9b8c RH |
7319 | dw2_asm_output_data (1, DWARF_LINE_BASE, |
7320 | "Line Base Value (Special Opcodes)"); | |
2e4b9b8c RH |
7321 | dw2_asm_output_data (1, DWARF_LINE_RANGE, |
7322 | "Line Range Value (Special Opcodes)"); | |
2e4b9b8c RH |
7323 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE, |
7324 | "Special Opcode Base"); | |
71dfc51f | 7325 | |
2ad9852d | 7326 | for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++) |
a3f97cbb JW |
7327 | { |
7328 | switch (opc) | |
7329 | { | |
7330 | case DW_LNS_advance_pc: | |
7331 | case DW_LNS_advance_line: | |
7332 | case DW_LNS_set_file: | |
7333 | case DW_LNS_set_column: | |
7334 | case DW_LNS_fixed_advance_pc: | |
7335 | n_op_args = 1; | |
7336 | break; | |
7337 | default: | |
7338 | n_op_args = 0; | |
7339 | break; | |
7340 | } | |
2e4b9b8c RH |
7341 | |
7342 | dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args", | |
7343 | opc, n_op_args); | |
a3f97cbb | 7344 | } |
71dfc51f | 7345 | |
0b34cf1e UD |
7346 | /* Write out the information about the files we use. */ |
7347 | output_file_names (); | |
981975b6 | 7348 | ASM_OUTPUT_LABEL (asm_out_file, p2); |
a3f97cbb | 7349 | |
2f22d404 JM |
7350 | /* We used to set the address register to the first location in the text |
7351 | section here, but that didn't accomplish anything since we already | |
7352 | have a line note for the opening brace of the first function. */ | |
a3f97cbb JW |
7353 | |
7354 | /* Generate the line number to PC correspondence table, encoded as | |
7355 | a series of state machine operations. */ | |
7356 | current_file = 1; | |
7357 | current_line = 1; | |
8b790721 | 7358 | strcpy (prev_line_label, text_section_label); |
a3f97cbb JW |
7359 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) |
7360 | { | |
b3694847 | 7361 | dw_line_info_ref line_info = &line_info_table[lt_index]; |
2f22d404 | 7362 | |
10a11b75 JM |
7363 | #if 0 |
7364 | /* Disable this optimization for now; GDB wants to see two line notes | |
7365 | at the beginning of a function so it can find the end of the | |
7366 | prologue. */ | |
7367 | ||
2f22d404 | 7368 | /* Don't emit anything for redundant notes. Just updating the |
73c68f61 SS |
7369 | address doesn't accomplish anything, because we already assume |
7370 | that anything after the last address is this line. */ | |
2f22d404 JM |
7371 | if (line_info->dw_line_num == current_line |
7372 | && line_info->dw_file_num == current_file) | |
7373 | continue; | |
10a11b75 | 7374 | #endif |
71dfc51f | 7375 | |
2e4b9b8c RH |
7376 | /* Emit debug info for the address of the current line. |
7377 | ||
7378 | Unfortunately, we have little choice here currently, and must always | |
2ad9852d | 7379 | use the most general form. GCC does not know the address delta |
2e4b9b8c RH |
7380 | itself, so we can't use DW_LNS_advance_pc. Many ports do have length |
7381 | attributes which will give an upper bound on the address range. We | |
7382 | could perhaps use length attributes to determine when it is safe to | |
7383 | use DW_LNS_fixed_advance_pc. */ | |
7384 | ||
5c90448c | 7385 | ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index); |
f19a6894 JW |
7386 | if (0) |
7387 | { | |
7388 | /* This can handle deltas up to 0xffff. This takes 3 bytes. */ | |
2e4b9b8c RH |
7389 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7390 | "DW_LNS_fixed_advance_pc"); | |
7391 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7392 | } |
7393 | else | |
7394 | { | |
a1a4189d | 7395 | /* This can handle any delta. This takes |
73c68f61 | 7396 | 4+DWARF2_ADDR_SIZE bytes. */ |
2e4b9b8c RH |
7397 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7398 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7399 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7400 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7401 | } |
2ad9852d | 7402 | |
f19a6894 JW |
7403 | strcpy (prev_line_label, line_label); |
7404 | ||
7405 | /* Emit debug info for the source file of the current line, if | |
7406 | different from the previous line. */ | |
a3f97cbb JW |
7407 | if (line_info->dw_file_num != current_file) |
7408 | { | |
7409 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
7410 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
7411 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
c4274b22 RH |
7412 | VARRAY_CHAR_PTR (file_table, |
7413 | current_file)); | |
a3f97cbb | 7414 | } |
71dfc51f | 7415 | |
f19a6894 JW |
7416 | /* Emit debug info for the current line number, choosing the encoding |
7417 | that uses the least amount of space. */ | |
2f22d404 | 7418 | if (line_info->dw_line_num != current_line) |
a3f97cbb | 7419 | { |
2f22d404 JM |
7420 | line_offset = line_info->dw_line_num - current_line; |
7421 | line_delta = line_offset - DWARF_LINE_BASE; | |
7422 | current_line = line_info->dw_line_num; | |
7423 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
2ad9852d RK |
7424 | /* This can handle deltas from -10 to 234, using the current |
7425 | definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This | |
7426 | takes 1 byte. */ | |
7427 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, | |
7428 | "line %lu", current_line); | |
2f22d404 JM |
7429 | else |
7430 | { | |
7431 | /* This can handle any delta. This takes at least 4 bytes, | |
7432 | depending on the value being encoded. */ | |
2e4b9b8c RH |
7433 | dw2_asm_output_data (1, DW_LNS_advance_line, |
7434 | "advance to line %lu", current_line); | |
7435 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
7436 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
2f22d404 | 7437 | } |
a94dbf2c JM |
7438 | } |
7439 | else | |
2ad9852d RK |
7440 | /* We still need to start a new row, so output a copy insn. */ |
7441 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
a3f97cbb JW |
7442 | } |
7443 | ||
f19a6894 JW |
7444 | /* Emit debug info for the address of the end of the function. */ |
7445 | if (0) | |
7446 | { | |
2e4b9b8c RH |
7447 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7448 | "DW_LNS_fixed_advance_pc"); | |
7449 | dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL); | |
f19a6894 JW |
7450 | } |
7451 | else | |
7452 | { | |
2e4b9b8c RH |
7453 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7454 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7455 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7456 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL); |
f19a6894 | 7457 | } |
bdb669cb | 7458 | |
2e4b9b8c RH |
7459 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
7460 | dw2_asm_output_data_uleb128 (1, NULL); | |
7461 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
7462 | |
7463 | function = 0; | |
7464 | current_file = 1; | |
7465 | current_line = 1; | |
556273e0 | 7466 | for (lt_index = 0; lt_index < separate_line_info_table_in_use;) |
e90b62db | 7467 | { |
b3694847 | 7468 | dw_separate_line_info_ref line_info |
e90b62db | 7469 | = &separate_line_info_table[lt_index]; |
71dfc51f | 7470 | |
10a11b75 | 7471 | #if 0 |
2f22d404 JM |
7472 | /* Don't emit anything for redundant notes. */ |
7473 | if (line_info->dw_line_num == current_line | |
7474 | && line_info->dw_file_num == current_file | |
7475 | && line_info->function == function) | |
7476 | goto cont; | |
10a11b75 | 7477 | #endif |
2f22d404 | 7478 | |
f19a6894 JW |
7479 | /* Emit debug info for the address of the current line. If this is |
7480 | a new function, or the first line of a function, then we need | |
7481 | to handle it differently. */ | |
5c90448c JM |
7482 | ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL, |
7483 | lt_index); | |
e90b62db JM |
7484 | if (function != line_info->function) |
7485 | { | |
7486 | function = line_info->function; | |
71dfc51f | 7487 | |
f9da5064 | 7488 | /* Set the address register to the first line in the function. */ |
2e4b9b8c RH |
7489 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7490 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7491 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7492 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
e90b62db JM |
7493 | } |
7494 | else | |
7495 | { | |
f19a6894 JW |
7496 | /* ??? See the DW_LNS_advance_pc comment above. */ |
7497 | if (0) | |
7498 | { | |
2e4b9b8c RH |
7499 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7500 | "DW_LNS_fixed_advance_pc"); | |
7501 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7502 | } |
7503 | else | |
7504 | { | |
2e4b9b8c RH |
7505 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7506 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7507 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7508 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7509 | } |
e90b62db | 7510 | } |
2ad9852d | 7511 | |
f19a6894 | 7512 | strcpy (prev_line_label, line_label); |
71dfc51f | 7513 | |
f19a6894 JW |
7514 | /* Emit debug info for the source file of the current line, if |
7515 | different from the previous line. */ | |
e90b62db JM |
7516 | if (line_info->dw_file_num != current_file) |
7517 | { | |
7518 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
7519 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
7520 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
c4274b22 RH |
7521 | VARRAY_CHAR_PTR (file_table, |
7522 | current_file)); | |
e90b62db | 7523 | } |
71dfc51f | 7524 | |
f19a6894 JW |
7525 | /* Emit debug info for the current line number, choosing the encoding |
7526 | that uses the least amount of space. */ | |
e90b62db JM |
7527 | if (line_info->dw_line_num != current_line) |
7528 | { | |
7529 | line_offset = line_info->dw_line_num - current_line; | |
7530 | line_delta = line_offset - DWARF_LINE_BASE; | |
7531 | current_line = line_info->dw_line_num; | |
7532 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
2e4b9b8c RH |
7533 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, |
7534 | "line %lu", current_line); | |
e90b62db JM |
7535 | else |
7536 | { | |
2e4b9b8c RH |
7537 | dw2_asm_output_data (1, DW_LNS_advance_line, |
7538 | "advance to line %lu", current_line); | |
7539 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
7540 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
e90b62db JM |
7541 | } |
7542 | } | |
2f22d404 | 7543 | else |
2e4b9b8c | 7544 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); |
71dfc51f | 7545 | |
10a11b75 | 7546 | #if 0 |
2f22d404 | 7547 | cont: |
10a11b75 | 7548 | #endif |
2ad9852d RK |
7549 | |
7550 | lt_index++; | |
e90b62db JM |
7551 | |
7552 | /* If we're done with a function, end its sequence. */ | |
7553 | if (lt_index == separate_line_info_table_in_use | |
7554 | || separate_line_info_table[lt_index].function != function) | |
7555 | { | |
7556 | current_file = 1; | |
7557 | current_line = 1; | |
71dfc51f | 7558 | |
f19a6894 | 7559 | /* Emit debug info for the address of the end of the function. */ |
5c90448c | 7560 | ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function); |
f19a6894 JW |
7561 | if (0) |
7562 | { | |
2e4b9b8c RH |
7563 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7564 | "DW_LNS_fixed_advance_pc"); | |
7565 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7566 | } |
7567 | else | |
7568 | { | |
2e4b9b8c RH |
7569 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7570 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7571 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7572 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7573 | } |
e90b62db JM |
7574 | |
7575 | /* Output the marker for the end of this sequence. */ | |
2e4b9b8c RH |
7576 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
7577 | dw2_asm_output_data_uleb128 (1, NULL); | |
7578 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
7579 | } |
7580 | } | |
f19f17e0 JM |
7581 | |
7582 | /* Output the marker for the end of the line number info. */ | |
2e4b9b8c | 7583 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
a3f97cbb JW |
7584 | } |
7585 | \f | |
a3f97cbb JW |
7586 | /* Given a pointer to a tree node for some base type, return a pointer to |
7587 | a DIE that describes the given type. | |
7588 | ||
7589 | This routine must only be called for GCC type nodes that correspond to | |
7590 | Dwarf base (fundamental) types. */ | |
71dfc51f | 7591 | |
a3f97cbb | 7592 | static dw_die_ref |
7080f735 | 7593 | base_type_die (tree type) |
a3f97cbb | 7594 | { |
b3694847 SS |
7595 | dw_die_ref base_type_result; |
7596 | const char *type_name; | |
7597 | enum dwarf_type encoding; | |
7598 | tree name = TYPE_NAME (type); | |
a3f97cbb | 7599 | |
2ad9852d | 7600 | if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE) |
a3f97cbb JW |
7601 | return 0; |
7602 | ||
405f63da MM |
7603 | if (name) |
7604 | { | |
7605 | if (TREE_CODE (name) == TYPE_DECL) | |
7606 | name = DECL_NAME (name); | |
7607 | ||
7608 | type_name = IDENTIFIER_POINTER (name); | |
7609 | } | |
7610 | else | |
7611 | type_name = "__unknown__"; | |
a9d38797 | 7612 | |
a3f97cbb JW |
7613 | switch (TREE_CODE (type)) |
7614 | { | |
a3f97cbb | 7615 | case INTEGER_TYPE: |
a9d38797 | 7616 | /* Carefully distinguish the C character types, without messing |
73c68f61 SS |
7617 | up if the language is not C. Note that we check only for the names |
7618 | that contain spaces; other names might occur by coincidence in other | |
7619 | languages. */ | |
a9d38797 JM |
7620 | if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE |
7621 | && (type == char_type_node | |
7622 | || ! strcmp (type_name, "signed char") | |
7623 | || ! strcmp (type_name, "unsigned char")))) | |
a3f97cbb | 7624 | { |
a9d38797 JM |
7625 | if (TREE_UNSIGNED (type)) |
7626 | encoding = DW_ATE_unsigned; | |
7627 | else | |
7628 | encoding = DW_ATE_signed; | |
7629 | break; | |
a3f97cbb | 7630 | } |
556273e0 | 7631 | /* else fall through. */ |
a3f97cbb | 7632 | |
a9d38797 JM |
7633 | case CHAR_TYPE: |
7634 | /* GNU Pascal/Ada CHAR type. Not used in C. */ | |
7635 | if (TREE_UNSIGNED (type)) | |
7636 | encoding = DW_ATE_unsigned_char; | |
7637 | else | |
7638 | encoding = DW_ATE_signed_char; | |
a3f97cbb JW |
7639 | break; |
7640 | ||
7641 | case REAL_TYPE: | |
a9d38797 | 7642 | encoding = DW_ATE_float; |
a3f97cbb JW |
7643 | break; |
7644 | ||
405f63da MM |
7645 | /* Dwarf2 doesn't know anything about complex ints, so use |
7646 | a user defined type for it. */ | |
a3f97cbb | 7647 | case COMPLEX_TYPE: |
405f63da MM |
7648 | if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE) |
7649 | encoding = DW_ATE_complex_float; | |
7650 | else | |
7651 | encoding = DW_ATE_lo_user; | |
a3f97cbb JW |
7652 | break; |
7653 | ||
7654 | case BOOLEAN_TYPE: | |
a9d38797 JM |
7655 | /* GNU FORTRAN/Ada/C++ BOOLEAN type. */ |
7656 | encoding = DW_ATE_boolean; | |
a3f97cbb JW |
7657 | break; |
7658 | ||
7659 | default: | |
2ad9852d RK |
7660 | /* No other TREE_CODEs are Dwarf fundamental types. */ |
7661 | abort (); | |
a3f97cbb JW |
7662 | } |
7663 | ||
54ba1f0d | 7664 | base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type); |
14a774a9 RK |
7665 | if (demangle_name_func) |
7666 | type_name = (*demangle_name_func) (type_name); | |
7667 | ||
a9d38797 JM |
7668 | add_AT_string (base_type_result, DW_AT_name, type_name); |
7669 | add_AT_unsigned (base_type_result, DW_AT_byte_size, | |
4e5a8d7b | 7670 | int_size_in_bytes (type)); |
a9d38797 | 7671 | add_AT_unsigned (base_type_result, DW_AT_encoding, encoding); |
a3f97cbb JW |
7672 | |
7673 | return base_type_result; | |
7674 | } | |
7675 | ||
7676 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to | |
7677 | the Dwarf "root" type for the given input type. The Dwarf "root" type of | |
7678 | a given type is generally the same as the given type, except that if the | |
7679 | given type is a pointer or reference type, then the root type of the given | |
7680 | type is the root type of the "basis" type for the pointer or reference | |
7681 | type. (This definition of the "root" type is recursive.) Also, the root | |
7682 | type of a `const' qualified type or a `volatile' qualified type is the | |
7683 | root type of the given type without the qualifiers. */ | |
71dfc51f | 7684 | |
a3f97cbb | 7685 | static tree |
7080f735 | 7686 | root_type (tree type) |
a3f97cbb JW |
7687 | { |
7688 | if (TREE_CODE (type) == ERROR_MARK) | |
7689 | return error_mark_node; | |
7690 | ||
7691 | switch (TREE_CODE (type)) | |
7692 | { | |
7693 | case ERROR_MARK: | |
7694 | return error_mark_node; | |
7695 | ||
7696 | case POINTER_TYPE: | |
7697 | case REFERENCE_TYPE: | |
7698 | return type_main_variant (root_type (TREE_TYPE (type))); | |
7699 | ||
7700 | default: | |
7701 | return type_main_variant (type); | |
7702 | } | |
7703 | } | |
7704 | ||
cc2902df | 7705 | /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the |
a3f97cbb | 7706 | given input type is a Dwarf "fundamental" type. Otherwise return null. */ |
71dfc51f RK |
7707 | |
7708 | static inline int | |
7080f735 | 7709 | is_base_type (tree type) |
a3f97cbb JW |
7710 | { |
7711 | switch (TREE_CODE (type)) | |
7712 | { | |
7713 | case ERROR_MARK: | |
7714 | case VOID_TYPE: | |
7715 | case INTEGER_TYPE: | |
7716 | case REAL_TYPE: | |
7717 | case COMPLEX_TYPE: | |
7718 | case BOOLEAN_TYPE: | |
7719 | case CHAR_TYPE: | |
7720 | return 1; | |
7721 | ||
7722 | case SET_TYPE: | |
7723 | case ARRAY_TYPE: | |
7724 | case RECORD_TYPE: | |
7725 | case UNION_TYPE: | |
7726 | case QUAL_UNION_TYPE: | |
7727 | case ENUMERAL_TYPE: | |
7728 | case FUNCTION_TYPE: | |
7729 | case METHOD_TYPE: | |
7730 | case POINTER_TYPE: | |
7731 | case REFERENCE_TYPE: | |
7732 | case FILE_TYPE: | |
7733 | case OFFSET_TYPE: | |
7734 | case LANG_TYPE: | |
604bb87d | 7735 | case VECTOR_TYPE: |
a3f97cbb JW |
7736 | return 0; |
7737 | ||
7738 | default: | |
7739 | abort (); | |
7740 | } | |
71dfc51f | 7741 | |
a3f97cbb JW |
7742 | return 0; |
7743 | } | |
7744 | ||
4977bab6 ZW |
7745 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE |
7746 | node, return the size in bits for the type if it is a constant, or else | |
7747 | return the alignment for the type if the type's size is not constant, or | |
7748 | else return BITS_PER_WORD if the type actually turns out to be an | |
7749 | ERROR_MARK node. */ | |
7750 | ||
7751 | static inline unsigned HOST_WIDE_INT | |
7080f735 | 7752 | simple_type_size_in_bits (tree type) |
4977bab6 | 7753 | { |
4977bab6 ZW |
7754 | if (TREE_CODE (type) == ERROR_MARK) |
7755 | return BITS_PER_WORD; | |
7756 | else if (TYPE_SIZE (type) == NULL_TREE) | |
7757 | return 0; | |
7758 | else if (host_integerp (TYPE_SIZE (type), 1)) | |
7759 | return tree_low_cst (TYPE_SIZE (type), 1); | |
7760 | else | |
7761 | return TYPE_ALIGN (type); | |
7762 | } | |
7763 | ||
c3cdeef4 JB |
7764 | /* Return true if the debug information for the given type should be |
7765 | emitted as a subrange type. */ | |
7766 | ||
7767 | static inline bool | |
7080f735 | 7768 | is_ada_subrange_type (tree type) |
c3cdeef4 JB |
7769 | { |
7770 | /* We do this for INTEGER_TYPEs that have names, parent types, and when | |
7771 | we are compiling Ada code. */ | |
7772 | return (TREE_CODE (type) == INTEGER_TYPE | |
7773 | && TYPE_NAME (type) != 0 && TREE_TYPE (type) != 0 | |
7774 | && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE | |
7775 | && TREE_UNSIGNED (TREE_TYPE (type)) && is_ada ()); | |
7776 | } | |
7777 | ||
7778 | /* Given a pointer to a tree node for a subrange type, return a pointer | |
7779 | to a DIE that describes the given type. */ | |
7780 | ||
7781 | static dw_die_ref | |
7080f735 | 7782 | subrange_type_die (tree type) |
c3cdeef4 JB |
7783 | { |
7784 | dw_die_ref subtype_die; | |
7785 | dw_die_ref subrange_die; | |
7786 | tree name = TYPE_NAME (type); | |
7080f735 | 7787 | |
c3cdeef4 JB |
7788 | subtype_die = base_type_die (TREE_TYPE (type)); |
7789 | ||
7790 | if (TREE_CODE (name) == TYPE_DECL) | |
7791 | name = DECL_NAME (name); | |
7792 | ||
7793 | subrange_die = new_die (DW_TAG_subrange_type, comp_unit_die, type); | |
7794 | add_name_attribute (subrange_die, IDENTIFIER_POINTER (name)); | |
7795 | if (TYPE_MIN_VALUE (type) != NULL) | |
7796 | add_bound_info (subrange_die, DW_AT_lower_bound, | |
7797 | TYPE_MIN_VALUE (type)); | |
7798 | if (TYPE_MAX_VALUE (type) != NULL) | |
7799 | add_bound_info (subrange_die, DW_AT_upper_bound, | |
7800 | TYPE_MAX_VALUE (type)); | |
7801 | add_AT_die_ref (subrange_die, DW_AT_type, subtype_die); | |
7802 | ||
7803 | return subrange_die; | |
7804 | } | |
7805 | ||
a3f97cbb JW |
7806 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging |
7807 | entry that chains various modifiers in front of the given type. */ | |
71dfc51f | 7808 | |
a3f97cbb | 7809 | static dw_die_ref |
7080f735 AJ |
7810 | modified_type_die (tree type, int is_const_type, int is_volatile_type, |
7811 | dw_die_ref context_die) | |
a3f97cbb | 7812 | { |
b3694847 SS |
7813 | enum tree_code code = TREE_CODE (type); |
7814 | dw_die_ref mod_type_die = NULL; | |
7815 | dw_die_ref sub_die = NULL; | |
7816 | tree item_type = NULL; | |
a3f97cbb JW |
7817 | |
7818 | if (code != ERROR_MARK) | |
7819 | { | |
5101b304 MM |
7820 | tree qualified_type; |
7821 | ||
7822 | /* See if we already have the appropriately qualified variant of | |
7823 | this type. */ | |
c26fbbca | 7824 | qualified_type |
5101b304 MM |
7825 | = get_qualified_type (type, |
7826 | ((is_const_type ? TYPE_QUAL_CONST : 0) | |
c26fbbca | 7827 | | (is_volatile_type |
5101b304 | 7828 | ? TYPE_QUAL_VOLATILE : 0))); |
2ad9852d | 7829 | |
5101b304 MM |
7830 | /* If we do, then we can just use its DIE, if it exists. */ |
7831 | if (qualified_type) | |
7832 | { | |
7833 | mod_type_die = lookup_type_die (qualified_type); | |
7834 | if (mod_type_die) | |
7835 | return mod_type_die; | |
7836 | } | |
bdb669cb | 7837 | |
556273e0 | 7838 | /* Handle C typedef types. */ |
c26fbbca | 7839 | if (qualified_type && TYPE_NAME (qualified_type) |
5101b304 MM |
7840 | && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL |
7841 | && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type))) | |
a94dbf2c | 7842 | { |
5101b304 MM |
7843 | tree type_name = TYPE_NAME (qualified_type); |
7844 | tree dtype = TREE_TYPE (type_name); | |
2ad9852d | 7845 | |
5101b304 | 7846 | if (qualified_type == dtype) |
a94dbf2c JM |
7847 | { |
7848 | /* For a named type, use the typedef. */ | |
5101b304 MM |
7849 | gen_type_die (qualified_type, context_die); |
7850 | mod_type_die = lookup_type_die (qualified_type); | |
a94dbf2c JM |
7851 | } |
7852 | else if (is_const_type < TYPE_READONLY (dtype) | |
7853 | || is_volatile_type < TYPE_VOLATILE (dtype)) | |
7854 | /* cv-unqualified version of named type. Just use the unnamed | |
7855 | type to which it refers. */ | |
71dfc51f | 7856 | mod_type_die |
5101b304 | 7857 | = modified_type_die (DECL_ORIGINAL_TYPE (type_name), |
71dfc51f RK |
7858 | is_const_type, is_volatile_type, |
7859 | context_die); | |
2ad9852d | 7860 | |
71dfc51f | 7861 | /* Else cv-qualified version of named type; fall through. */ |
a94dbf2c JM |
7862 | } |
7863 | ||
7864 | if (mod_type_die) | |
556273e0 KH |
7865 | /* OK. */ |
7866 | ; | |
a94dbf2c | 7867 | else if (is_const_type) |
a3f97cbb | 7868 | { |
54ba1f0d | 7869 | mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type); |
a9d38797 | 7870 | sub_die = modified_type_die (type, 0, is_volatile_type, context_die); |
a3f97cbb JW |
7871 | } |
7872 | else if (is_volatile_type) | |
7873 | { | |
54ba1f0d | 7874 | mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type); |
a9d38797 | 7875 | sub_die = modified_type_die (type, 0, 0, context_die); |
a3f97cbb JW |
7876 | } |
7877 | else if (code == POINTER_TYPE) | |
7878 | { | |
54ba1f0d | 7879 | mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type); |
4977bab6 ZW |
7880 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, |
7881 | simple_type_size_in_bits (type) / BITS_PER_UNIT); | |
61b32c02 | 7882 | #if 0 |
a3f97cbb | 7883 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
61b32c02 | 7884 | #endif |
a3f97cbb | 7885 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
7886 | } |
7887 | else if (code == REFERENCE_TYPE) | |
7888 | { | |
54ba1f0d | 7889 | mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type); |
4977bab6 ZW |
7890 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, |
7891 | simple_type_size_in_bits (type) / BITS_PER_UNIT); | |
61b32c02 | 7892 | #if 0 |
a3f97cbb | 7893 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
556273e0 | 7894 | #endif |
a3f97cbb | 7895 | item_type = TREE_TYPE (type); |
a3f97cbb | 7896 | } |
c3cdeef4 JB |
7897 | else if (is_ada_subrange_type (type)) |
7898 | mod_type_die = subrange_type_die (type); | |
a3f97cbb | 7899 | else if (is_base_type (type)) |
71dfc51f | 7900 | mod_type_die = base_type_die (type); |
a3f97cbb JW |
7901 | else |
7902 | { | |
4b674448 JM |
7903 | gen_type_die (type, context_die); |
7904 | ||
a3f97cbb JW |
7905 | /* We have to get the type_main_variant here (and pass that to the |
7906 | `lookup_type_die' routine) because the ..._TYPE node we have | |
7907 | might simply be a *copy* of some original type node (where the | |
7908 | copy was created to help us keep track of typedef names) and | |
7909 | that copy might have a different TYPE_UID from the original | |
a94dbf2c | 7910 | ..._TYPE node. */ |
0e98f924 AH |
7911 | if (TREE_CODE (type) != VECTOR_TYPE) |
7912 | mod_type_die = lookup_type_die (type_main_variant (type)); | |
7913 | else | |
7914 | /* Vectors have the debugging information in the type, | |
7915 | not the main variant. */ | |
7916 | mod_type_die = lookup_type_die (type); | |
3a88cbd1 JL |
7917 | if (mod_type_die == NULL) |
7918 | abort (); | |
a3f97cbb | 7919 | } |
3d2999ba MK |
7920 | |
7921 | /* We want to equate the qualified type to the die below. */ | |
8370aa3a | 7922 | type = qualified_type; |
a3f97cbb | 7923 | } |
71dfc51f | 7924 | |
8370aa3a RH |
7925 | if (type) |
7926 | equate_type_number_to_die (type, mod_type_die); | |
dfcf9891 | 7927 | if (item_type) |
71dfc51f RK |
7928 | /* We must do this after the equate_type_number_to_die call, in case |
7929 | this is a recursive type. This ensures that the modified_type_die | |
7930 | recursion will terminate even if the type is recursive. Recursive | |
7931 | types are possible in Ada. */ | |
7932 | sub_die = modified_type_die (item_type, | |
7933 | TYPE_READONLY (item_type), | |
7934 | TYPE_VOLATILE (item_type), | |
7935 | context_die); | |
7936 | ||
a3f97cbb | 7937 | if (sub_die != NULL) |
71dfc51f RK |
7938 | add_AT_die_ref (mod_type_die, DW_AT_type, sub_die); |
7939 | ||
a3f97cbb JW |
7940 | return mod_type_die; |
7941 | } | |
7942 | ||
a3f97cbb | 7943 | /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is |
6d2f8887 | 7944 | an enumerated type. */ |
71dfc51f RK |
7945 | |
7946 | static inline int | |
7080f735 | 7947 | type_is_enum (tree type) |
a3f97cbb JW |
7948 | { |
7949 | return TREE_CODE (type) == ENUMERAL_TYPE; | |
7950 | } | |
7951 | ||
7d9d8943 AM |
7952 | /* Return the register number described by a given RTL node. */ |
7953 | ||
7954 | static unsigned int | |
7080f735 | 7955 | reg_number (rtx rtl) |
7d9d8943 | 7956 | { |
b3694847 | 7957 | unsigned regno = REGNO (rtl); |
7d9d8943 AM |
7958 | |
7959 | if (regno >= FIRST_PSEUDO_REGISTER) | |
e7af1d45 | 7960 | abort (); |
7d9d8943 | 7961 | |
e7af1d45 | 7962 | return DBX_REGISTER_NUMBER (regno); |
7d9d8943 AM |
7963 | } |
7964 | ||
e7af1d45 | 7965 | /* Return a location descriptor that designates a machine register or |
96714395 | 7966 | zero if there is none. */ |
71dfc51f | 7967 | |
a3f97cbb | 7968 | static dw_loc_descr_ref |
7080f735 | 7969 | reg_loc_descriptor (rtx rtl) |
a3f97cbb | 7970 | { |
d22c2324 | 7971 | unsigned reg; |
96714395 | 7972 | rtx regs; |
71dfc51f | 7973 | |
e7af1d45 RK |
7974 | if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER) |
7975 | return 0; | |
7976 | ||
7977 | reg = reg_number (rtl); | |
96714395 AH |
7978 | regs = (*targetm.dwarf_register_span) (rtl); |
7979 | ||
7980 | if (HARD_REGNO_NREGS (reg, GET_MODE (rtl)) > 1 | |
7981 | || regs) | |
7982 | return multiple_reg_loc_descriptor (rtl, regs); | |
7983 | else | |
7984 | return one_reg_loc_descriptor (reg); | |
7985 | } | |
7986 | ||
7987 | /* Return a location descriptor that designates a machine register for | |
7988 | a given hard register number. */ | |
7989 | ||
7990 | static dw_loc_descr_ref | |
7080f735 | 7991 | one_reg_loc_descriptor (unsigned int regno) |
96714395 AH |
7992 | { |
7993 | if (regno <= 31) | |
7994 | return new_loc_descr (DW_OP_reg0 + regno, 0, 0); | |
d22c2324 | 7995 | else |
96714395 AH |
7996 | return new_loc_descr (DW_OP_regx, regno, 0); |
7997 | } | |
7998 | ||
7999 | /* Given an RTL of a register, return a location descriptor that | |
8000 | designates a value that spans more than one register. */ | |
8001 | ||
8002 | static dw_loc_descr_ref | |
7080f735 | 8003 | multiple_reg_loc_descriptor (rtx rtl, rtx regs) |
96714395 AH |
8004 | { |
8005 | int nregs, size, i; | |
8006 | unsigned reg; | |
8007 | dw_loc_descr_ref loc_result = NULL; | |
71dfc51f | 8008 | |
96714395 AH |
8009 | reg = reg_number (rtl); |
8010 | nregs = HARD_REGNO_NREGS (reg, GET_MODE (rtl)); | |
8011 | ||
8012 | /* Simple, contiguous registers. */ | |
8013 | if (regs == NULL_RTX) | |
8014 | { | |
8015 | size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs; | |
8016 | ||
8017 | loc_result = NULL; | |
8018 | while (nregs--) | |
8019 | { | |
8020 | dw_loc_descr_ref t; | |
8021 | ||
96714395 AH |
8022 | t = one_reg_loc_descriptor (reg); |
8023 | add_loc_descr (&loc_result, t); | |
8024 | add_loc_descr (&loc_result, new_loc_descr (DW_OP_piece, size, 0)); | |
31ca3635 | 8025 | ++reg; |
96714395 AH |
8026 | } |
8027 | return loc_result; | |
8028 | } | |
8029 | ||
8030 | /* Now onto stupid register sets in non contiguous locations. */ | |
8031 | ||
8032 | if (GET_CODE (regs) != PARALLEL) | |
8033 | abort (); | |
8034 | ||
8035 | size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0))); | |
8036 | loc_result = NULL; | |
8037 | ||
8038 | for (i = 0; i < XVECLEN (regs, 0); ++i) | |
8039 | { | |
8040 | dw_loc_descr_ref t; | |
8041 | ||
8042 | t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i))); | |
8043 | add_loc_descr (&loc_result, t); | |
8044 | size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0))); | |
8045 | add_loc_descr (&loc_result, new_loc_descr (DW_OP_piece, size, 0)); | |
8046 | } | |
a3f97cbb JW |
8047 | return loc_result; |
8048 | } | |
8049 | ||
d8041cc8 RH |
8050 | /* Return a location descriptor that designates a constant. */ |
8051 | ||
8052 | static dw_loc_descr_ref | |
7080f735 | 8053 | int_loc_descriptor (HOST_WIDE_INT i) |
d8041cc8 RH |
8054 | { |
8055 | enum dwarf_location_atom op; | |
8056 | ||
8057 | /* Pick the smallest representation of a constant, rather than just | |
8058 | defaulting to the LEB encoding. */ | |
8059 | if (i >= 0) | |
8060 | { | |
8061 | if (i <= 31) | |
8062 | op = DW_OP_lit0 + i; | |
8063 | else if (i <= 0xff) | |
8064 | op = DW_OP_const1u; | |
8065 | else if (i <= 0xffff) | |
8066 | op = DW_OP_const2u; | |
8067 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
8068 | || i <= 0xffffffff) | |
8069 | op = DW_OP_const4u; | |
8070 | else | |
8071 | op = DW_OP_constu; | |
8072 | } | |
8073 | else | |
8074 | { | |
8075 | if (i >= -0x80) | |
8076 | op = DW_OP_const1s; | |
8077 | else if (i >= -0x8000) | |
8078 | op = DW_OP_const2s; | |
8079 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
8080 | || i >= -0x80000000) | |
8081 | op = DW_OP_const4s; | |
8082 | else | |
8083 | op = DW_OP_consts; | |
8084 | } | |
8085 | ||
8086 | return new_loc_descr (op, i, 0); | |
8087 | } | |
8088 | ||
a3f97cbb | 8089 | /* Return a location descriptor that designates a base+offset location. */ |
71dfc51f | 8090 | |
a3f97cbb | 8091 | static dw_loc_descr_ref |
7080f735 | 8092 | based_loc_descr (unsigned int reg, long int offset) |
a3f97cbb | 8093 | { |
b3694847 | 8094 | dw_loc_descr_ref loc_result; |
810429b7 JM |
8095 | /* For the "frame base", we use the frame pointer or stack pointer |
8096 | registers, since the RTL for local variables is relative to one of | |
8097 | them. */ | |
b3694847 SS |
8098 | unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed |
8099 | ? HARD_FRAME_POINTER_REGNUM | |
8100 | : STACK_POINTER_REGNUM); | |
71dfc51f | 8101 | |
a3f97cbb | 8102 | if (reg == fp_reg) |
71dfc51f | 8103 | loc_result = new_loc_descr (DW_OP_fbreg, offset, 0); |
85066503 | 8104 | else if (reg <= 31) |
71dfc51f | 8105 | loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0); |
a3f97cbb | 8106 | else |
71dfc51f RK |
8107 | loc_result = new_loc_descr (DW_OP_bregx, reg, offset); |
8108 | ||
a3f97cbb JW |
8109 | return loc_result; |
8110 | } | |
8111 | ||
8112 | /* Return true if this RTL expression describes a base+offset calculation. */ | |
71dfc51f RK |
8113 | |
8114 | static inline int | |
7080f735 | 8115 | is_based_loc (rtx rtl) |
a3f97cbb | 8116 | { |
173bf5be KH |
8117 | return (GET_CODE (rtl) == PLUS |
8118 | && ((GET_CODE (XEXP (rtl, 0)) == REG | |
8119 | && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER | |
8120 | && GET_CODE (XEXP (rtl, 1)) == CONST_INT))); | |
a3f97cbb JW |
8121 | } |
8122 | ||
8123 | /* The following routine converts the RTL for a variable or parameter | |
8124 | (resident in memory) into an equivalent Dwarf representation of a | |
8125 | mechanism for getting the address of that same variable onto the top of a | |
8126 | hypothetical "address evaluation" stack. | |
71dfc51f | 8127 | |
a3f97cbb JW |
8128 | When creating memory location descriptors, we are effectively transforming |
8129 | the RTL for a memory-resident object into its Dwarf postfix expression | |
8130 | equivalent. This routine recursively descends an RTL tree, turning | |
e60d4d7b JL |
8131 | it into Dwarf postfix code as it goes. |
8132 | ||
8133 | MODE is the mode of the memory reference, needed to handle some | |
e7af1d45 RK |
8134 | autoincrement addressing modes. |
8135 | ||
8136 | Return 0 if we can't represent the location. */ | |
71dfc51f | 8137 | |
a3f97cbb | 8138 | static dw_loc_descr_ref |
7080f735 | 8139 | mem_loc_descriptor (rtx rtl, enum machine_mode mode) |
a3f97cbb JW |
8140 | { |
8141 | dw_loc_descr_ref mem_loc_result = NULL; | |
e7af1d45 | 8142 | |
556273e0 | 8143 | /* Note that for a dynamically sized array, the location we will generate a |
a3f97cbb JW |
8144 | description of here will be the lowest numbered location which is |
8145 | actually within the array. That's *not* necessarily the same as the | |
8146 | zeroth element of the array. */ | |
71dfc51f | 8147 | |
69bd9368 | 8148 | rtl = (*targetm.delegitimize_address) (rtl); |
1865dbb5 | 8149 | |
a3f97cbb JW |
8150 | switch (GET_CODE (rtl)) |
8151 | { | |
e60d4d7b JL |
8152 | case POST_INC: |
8153 | case POST_DEC: | |
e2134eea | 8154 | case POST_MODIFY: |
e60d4d7b JL |
8155 | /* POST_INC and POST_DEC can be handled just like a SUBREG. So we |
8156 | just fall into the SUBREG code. */ | |
8157 | ||
2ad9852d | 8158 | /* ... fall through ... */ |
e60d4d7b | 8159 | |
a3f97cbb JW |
8160 | case SUBREG: |
8161 | /* The case of a subreg may arise when we have a local (register) | |
73c68f61 SS |
8162 | variable or a formal (register) parameter which doesn't quite fill |
8163 | up an entire register. For now, just assume that it is | |
8164 | legitimate to make the Dwarf info refer to the whole register which | |
8165 | contains the given subreg. */ | |
ddef6bc7 | 8166 | rtl = SUBREG_REG (rtl); |
71dfc51f | 8167 | |
2ad9852d | 8168 | /* ... fall through ... */ |
a3f97cbb JW |
8169 | |
8170 | case REG: | |
8171 | /* Whenever a register number forms a part of the description of the | |
73c68f61 SS |
8172 | method for calculating the (dynamic) address of a memory resident |
8173 | object, DWARF rules require the register number be referred to as | |
8174 | a "base register". This distinction is not based in any way upon | |
8175 | what category of register the hardware believes the given register | |
8176 | belongs to. This is strictly DWARF terminology we're dealing with | |
8177 | here. Note that in cases where the location of a memory-resident | |
8178 | data object could be expressed as: OP_ADD (OP_BASEREG (basereg), | |
8179 | OP_CONST (0)) the actual DWARF location descriptor that we generate | |
8180 | may just be OP_BASEREG (basereg). This may look deceptively like | |
8181 | the object in question was allocated to a register (rather than in | |
8182 | memory) so DWARF consumers need to be aware of the subtle | |
8183 | distinction between OP_REG and OP_BASEREG. */ | |
e7af1d45 RK |
8184 | if (REGNO (rtl) < FIRST_PSEUDO_REGISTER) |
8185 | mem_loc_result = based_loc_descr (reg_number (rtl), 0); | |
a3f97cbb JW |
8186 | break; |
8187 | ||
8188 | case MEM: | |
f7d2b0ed | 8189 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
e7af1d45 RK |
8190 | if (mem_loc_result != 0) |
8191 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0)); | |
a3f97cbb JW |
8192 | break; |
8193 | ||
1ce324c3 EB |
8194 | case LO_SUM: |
8195 | rtl = XEXP (rtl, 1); | |
8196 | ||
8197 | /* ... fall through ... */ | |
8198 | ||
d8041cc8 RH |
8199 | case LABEL_REF: |
8200 | /* Some ports can transform a symbol ref into a label ref, because | |
7080f735 AJ |
8201 | the symbol ref is too far away and has to be dumped into a constant |
8202 | pool. */ | |
a3f97cbb JW |
8203 | case CONST: |
8204 | case SYMBOL_REF: | |
6331d1c1 | 8205 | /* Alternatively, the symbol in the constant pool might be referenced |
c6f9b9a1 | 8206 | by a different symbol. */ |
2ad9852d | 8207 | if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl)) |
79cdfa4b | 8208 | { |
149d6f9e JJ |
8209 | bool marked; |
8210 | rtx tmp = get_pool_constant_mark (rtl, &marked); | |
2ad9852d | 8211 | |
6331d1c1 | 8212 | if (GET_CODE (tmp) == SYMBOL_REF) |
149d6f9e JJ |
8213 | { |
8214 | rtl = tmp; | |
8215 | if (CONSTANT_POOL_ADDRESS_P (tmp)) | |
8216 | get_pool_constant_mark (tmp, &marked); | |
8217 | else | |
8218 | marked = true; | |
8219 | } | |
8220 | ||
8221 | /* If all references to this pool constant were optimized away, | |
8222 | it was not output and thus we can't represent it. | |
8223 | FIXME: might try to use DW_OP_const_value here, though | |
8224 | DW_OP_piece complicates it. */ | |
8225 | if (!marked) | |
8226 | return 0; | |
79cdfa4b TM |
8227 | } |
8228 | ||
a3f97cbb JW |
8229 | mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0); |
8230 | mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
c470afad RK |
8231 | mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl; |
8232 | VARRAY_PUSH_RTX (used_rtx_varray, rtl); | |
a3f97cbb JW |
8233 | break; |
8234 | ||
e2134eea JH |
8235 | case PRE_MODIFY: |
8236 | /* Extract the PLUS expression nested inside and fall into | |
73c68f61 | 8237 | PLUS code below. */ |
e2134eea JH |
8238 | rtl = XEXP (rtl, 1); |
8239 | goto plus; | |
8240 | ||
e60d4d7b JL |
8241 | case PRE_INC: |
8242 | case PRE_DEC: | |
8243 | /* Turn these into a PLUS expression and fall into the PLUS code | |
8244 | below. */ | |
8245 | rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0), | |
8246 | GEN_INT (GET_CODE (rtl) == PRE_INC | |
556273e0 KH |
8247 | ? GET_MODE_UNIT_SIZE (mode) |
8248 | : -GET_MODE_UNIT_SIZE (mode))); | |
8249 | ||
2ad9852d | 8250 | /* ... fall through ... */ |
e60d4d7b | 8251 | |
a3f97cbb | 8252 | case PLUS: |
e2134eea | 8253 | plus: |
a3f97cbb | 8254 | if (is_based_loc (rtl)) |
71dfc51f RK |
8255 | mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)), |
8256 | INTVAL (XEXP (rtl, 1))); | |
a3f97cbb JW |
8257 | else |
8258 | { | |
d8041cc8 | 8259 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode); |
e7af1d45 RK |
8260 | if (mem_loc_result == 0) |
8261 | break; | |
d8041cc8 RH |
8262 | |
8263 | if (GET_CODE (XEXP (rtl, 1)) == CONST_INT | |
8264 | && INTVAL (XEXP (rtl, 1)) >= 0) | |
e7af1d45 RK |
8265 | add_loc_descr (&mem_loc_result, |
8266 | new_loc_descr (DW_OP_plus_uconst, | |
8267 | INTVAL (XEXP (rtl, 1)), 0)); | |
d8041cc8 RH |
8268 | else |
8269 | { | |
8270 | add_loc_descr (&mem_loc_result, | |
8271 | mem_loc_descriptor (XEXP (rtl, 1), mode)); | |
8272 | add_loc_descr (&mem_loc_result, | |
8273 | new_loc_descr (DW_OP_plus, 0, 0)); | |
8274 | } | |
a3f97cbb JW |
8275 | } |
8276 | break; | |
8277 | ||
dd2478ae | 8278 | case MULT: |
e7af1d45 RK |
8279 | { |
8280 | /* If a pseudo-reg is optimized away, it is possible for it to | |
8281 | be replaced with a MEM containing a multiply. */ | |
8282 | dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode); | |
8283 | dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode); | |
8284 | ||
8285 | if (op0 == 0 || op1 == 0) | |
8286 | break; | |
8287 | ||
8288 | mem_loc_result = op0; | |
8289 | add_loc_descr (&mem_loc_result, op1); | |
8290 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0)); | |
8291 | break; | |
8292 | } | |
dd2478ae | 8293 | |
a3f97cbb | 8294 | case CONST_INT: |
d8041cc8 | 8295 | mem_loc_result = int_loc_descriptor (INTVAL (rtl)); |
a3f97cbb JW |
8296 | break; |
8297 | ||
a9e8a5ee RK |
8298 | case ADDRESSOF: |
8299 | /* If this is a MEM, return its address. Otherwise, we can't | |
8300 | represent this. */ | |
8301 | if (GET_CODE (XEXP (rtl, 0)) == MEM) | |
8302 | return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode); | |
8303 | else | |
8304 | return 0; | |
8305 | ||
a3f97cbb JW |
8306 | default: |
8307 | abort (); | |
8308 | } | |
71dfc51f | 8309 | |
a3f97cbb JW |
8310 | return mem_loc_result; |
8311 | } | |
8312 | ||
956d6950 | 8313 | /* Return a descriptor that describes the concatenation of two locations. |
4401bf24 JL |
8314 | This is typically a complex variable. */ |
8315 | ||
8316 | static dw_loc_descr_ref | |
7080f735 | 8317 | concat_loc_descriptor (rtx x0, rtx x1) |
4401bf24 JL |
8318 | { |
8319 | dw_loc_descr_ref cc_loc_result = NULL; | |
e7af1d45 RK |
8320 | dw_loc_descr_ref x0_ref = loc_descriptor (x0); |
8321 | dw_loc_descr_ref x1_ref = loc_descriptor (x1); | |
4401bf24 | 8322 | |
e7af1d45 RK |
8323 | if (x0_ref == 0 || x1_ref == 0) |
8324 | return 0; | |
8325 | ||
8326 | cc_loc_result = x0_ref; | |
4401bf24 | 8327 | add_loc_descr (&cc_loc_result, |
e7af1d45 RK |
8328 | new_loc_descr (DW_OP_piece, |
8329 | GET_MODE_SIZE (GET_MODE (x0)), 0)); | |
4401bf24 | 8330 | |
e7af1d45 | 8331 | add_loc_descr (&cc_loc_result, x1_ref); |
4401bf24 | 8332 | add_loc_descr (&cc_loc_result, |
e7af1d45 RK |
8333 | new_loc_descr (DW_OP_piece, |
8334 | GET_MODE_SIZE (GET_MODE (x1)), 0)); | |
4401bf24 JL |
8335 | |
8336 | return cc_loc_result; | |
8337 | } | |
8338 | ||
a3f97cbb JW |
8339 | /* Output a proper Dwarf location descriptor for a variable or parameter |
8340 | which is either allocated in a register or in a memory location. For a | |
8341 | register, we just generate an OP_REG and the register number. For a | |
8342 | memory location we provide a Dwarf postfix expression describing how to | |
e7af1d45 RK |
8343 | generate the (dynamic) address of the object onto the address stack. |
8344 | ||
8345 | If we don't know how to describe it, return 0. */ | |
71dfc51f | 8346 | |
a3f97cbb | 8347 | static dw_loc_descr_ref |
7080f735 | 8348 | loc_descriptor (rtx rtl) |
a3f97cbb JW |
8349 | { |
8350 | dw_loc_descr_ref loc_result = NULL; | |
e7af1d45 | 8351 | |
a3f97cbb JW |
8352 | switch (GET_CODE (rtl)) |
8353 | { | |
8354 | case SUBREG: | |
a3f97cbb | 8355 | /* The case of a subreg may arise when we have a local (register) |
73c68f61 SS |
8356 | variable or a formal (register) parameter which doesn't quite fill |
8357 | up an entire register. For now, just assume that it is | |
8358 | legitimate to make the Dwarf info refer to the whole register which | |
8359 | contains the given subreg. */ | |
ddef6bc7 | 8360 | rtl = SUBREG_REG (rtl); |
71dfc51f | 8361 | |
2ad9852d | 8362 | /* ... fall through ... */ |
a3f97cbb JW |
8363 | |
8364 | case REG: | |
5c90448c | 8365 | loc_result = reg_loc_descriptor (rtl); |
a3f97cbb JW |
8366 | break; |
8367 | ||
8368 | case MEM: | |
e60d4d7b | 8369 | loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
a3f97cbb JW |
8370 | break; |
8371 | ||
4401bf24 JL |
8372 | case CONCAT: |
8373 | loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1)); | |
8374 | break; | |
8375 | ||
a3f97cbb | 8376 | default: |
71dfc51f | 8377 | abort (); |
a3f97cbb | 8378 | } |
71dfc51f | 8379 | |
a3f97cbb JW |
8380 | return loc_result; |
8381 | } | |
8382 | ||
2ad9852d RK |
8383 | /* Similar, but generate the descriptor from trees instead of rtl. This comes |
8384 | up particularly with variable length arrays. If ADDRESSP is nonzero, we are | |
8385 | looking for an address. Otherwise, we return a value. If we can't make a | |
8386 | descriptor, return 0. */ | |
d8041cc8 RH |
8387 | |
8388 | static dw_loc_descr_ref | |
7080f735 | 8389 | loc_descriptor_from_tree (tree loc, int addressp) |
d8041cc8 | 8390 | { |
e7af1d45 RK |
8391 | dw_loc_descr_ref ret, ret1; |
8392 | int indirect_p = 0; | |
d8041cc8 RH |
8393 | int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc)); |
8394 | enum dwarf_location_atom op; | |
8395 | ||
8396 | /* ??? Most of the time we do not take proper care for sign/zero | |
8397 | extending the values properly. Hopefully this won't be a real | |
8398 | problem... */ | |
8399 | ||
8400 | switch (TREE_CODE (loc)) | |
8401 | { | |
8402 | case ERROR_MARK: | |
e7af1d45 | 8403 | return 0; |
d8041cc8 | 8404 | |
b4ae5201 | 8405 | case WITH_RECORD_EXPR: |
e7af1d45 | 8406 | case PLACEHOLDER_EXPR: |
b4ae5201 RK |
8407 | /* This case involves extracting fields from an object to determine the |
8408 | position of other fields. We don't try to encode this here. The | |
8409 | only user of this is Ada, which encodes the needed information using | |
8410 | the names of types. */ | |
e7af1d45 | 8411 | return 0; |
b4ae5201 | 8412 | |
aea9695c RK |
8413 | case CALL_EXPR: |
8414 | return 0; | |
8415 | ||
8416 | case ADDR_EXPR: | |
8417 | /* We can support this only if we can look through conversions and | |
8418 | find an INDIRECT_EXPR. */ | |
8419 | for (loc = TREE_OPERAND (loc, 0); | |
8420 | TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR | |
8421 | || TREE_CODE (loc) == NON_LVALUE_EXPR | |
8422 | || TREE_CODE (loc) == VIEW_CONVERT_EXPR | |
8423 | || TREE_CODE (loc) == SAVE_EXPR; | |
8424 | loc = TREE_OPERAND (loc, 0)) | |
8425 | ; | |
8426 | ||
8427 | return (TREE_CODE (loc) == INDIRECT_REF | |
8428 | ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp) | |
8429 | : 0); | |
8430 | ||
d8041cc8 | 8431 | case VAR_DECL: |
b9203463 RH |
8432 | if (DECL_THREAD_LOCAL (loc)) |
8433 | { | |
8434 | rtx rtl; | |
8435 | ||
8436 | #ifndef ASM_OUTPUT_DWARF_DTPREL | |
8437 | /* If this is not defined, we have no way to emit the data. */ | |
8438 | return 0; | |
8439 | #endif | |
8440 | ||
8441 | /* The way DW_OP_GNU_push_tls_address is specified, we can only | |
8442 | look up addresses of objects in the current module. */ | |
3c655f42 | 8443 | if (DECL_EXTERNAL (loc)) |
b9203463 RH |
8444 | return 0; |
8445 | ||
8446 | rtl = rtl_for_decl_location (loc); | |
8447 | if (rtl == NULL_RTX) | |
8448 | return 0; | |
8449 | ||
8450 | if (GET_CODE (rtl) != MEM) | |
8451 | return 0; | |
8452 | rtl = XEXP (rtl, 0); | |
8453 | if (! CONSTANT_P (rtl)) | |
8454 | return 0; | |
8455 | ||
8456 | ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0); | |
8457 | ret->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
8458 | ret->dw_loc_oprnd1.v.val_addr = rtl; | |
8459 | ||
8460 | ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0); | |
8461 | add_loc_descr (&ret, ret1); | |
8462 | ||
8463 | indirect_p = 1; | |
8464 | break; | |
8465 | } | |
8466 | /* FALLTHRU */ | |
8467 | ||
d8041cc8 RH |
8468 | case PARM_DECL: |
8469 | { | |
8470 | rtx rtl = rtl_for_decl_location (loc); | |
d8041cc8 | 8471 | |
a97c9600 | 8472 | if (rtl == NULL_RTX) |
e7af1d45 | 8473 | return 0; |
a97c9600 | 8474 | else if (CONSTANT_P (rtl)) |
d8041cc8 RH |
8475 | { |
8476 | ret = new_loc_descr (DW_OP_addr, 0, 0); | |
8477 | ret->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
8478 | ret->dw_loc_oprnd1.v.val_addr = rtl; | |
e7af1d45 | 8479 | indirect_p = 1; |
d8041cc8 RH |
8480 | } |
8481 | else | |
8482 | { | |
c28abdf0 RH |
8483 | enum machine_mode mode = GET_MODE (rtl); |
8484 | ||
d8041cc8 RH |
8485 | if (GET_CODE (rtl) == MEM) |
8486 | { | |
e7af1d45 | 8487 | indirect_p = 1; |
d8041cc8 RH |
8488 | rtl = XEXP (rtl, 0); |
8489 | } | |
2ad9852d | 8490 | |
d8041cc8 RH |
8491 | ret = mem_loc_descriptor (rtl, mode); |
8492 | } | |
8493 | } | |
8494 | break; | |
8495 | ||
8496 | case INDIRECT_REF: | |
8497 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 | 8498 | indirect_p = 1; |
d8041cc8 RH |
8499 | break; |
8500 | ||
749552c4 RK |
8501 | case COMPOUND_EXPR: |
8502 | return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp); | |
8503 | ||
ed972b14 RK |
8504 | case NOP_EXPR: |
8505 | case CONVERT_EXPR: | |
8506 | case NON_LVALUE_EXPR: | |
ed239f5a | 8507 | case VIEW_CONVERT_EXPR: |
b4ae5201 | 8508 | case SAVE_EXPR: |
032cb602 | 8509 | case MODIFY_EXPR: |
ed972b14 | 8510 | return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp); |
e57cabac | 8511 | |
d8041cc8 RH |
8512 | case COMPONENT_REF: |
8513 | case BIT_FIELD_REF: | |
8514 | case ARRAY_REF: | |
b4e3fabb | 8515 | case ARRAY_RANGE_REF: |
d8041cc8 RH |
8516 | { |
8517 | tree obj, offset; | |
8518 | HOST_WIDE_INT bitsize, bitpos, bytepos; | |
8519 | enum machine_mode mode; | |
8520 | int volatilep; | |
d8041cc8 RH |
8521 | |
8522 | obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode, | |
a06ef755 | 8523 | &unsignedp, &volatilep); |
e7af1d45 RK |
8524 | |
8525 | if (obj == loc) | |
8526 | return 0; | |
8527 | ||
d8041cc8 | 8528 | ret = loc_descriptor_from_tree (obj, 1); |
e7af1d45 | 8529 | if (ret == 0 |
2ad9852d | 8530 | || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0) |
e7af1d45 | 8531 | return 0; |
d8041cc8 RH |
8532 | |
8533 | if (offset != NULL_TREE) | |
8534 | { | |
8535 | /* Variable offset. */ | |
8536 | add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0)); | |
8537 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
8538 | } | |
8539 | ||
e7af1d45 RK |
8540 | if (!addressp) |
8541 | indirect_p = 1; | |
d8041cc8 RH |
8542 | |
8543 | bytepos = bitpos / BITS_PER_UNIT; | |
8544 | if (bytepos > 0) | |
8545 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0)); | |
8546 | else if (bytepos < 0) | |
8547 | { | |
8548 | add_loc_descr (&ret, int_loc_descriptor (bytepos)); | |
8549 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
8550 | } | |
8551 | break; | |
8552 | } | |
8553 | ||
8554 | case INTEGER_CST: | |
8555 | if (host_integerp (loc, 0)) | |
8556 | ret = int_loc_descriptor (tree_low_cst (loc, 0)); | |
e7af1d45 RK |
8557 | else |
8558 | return 0; | |
d8041cc8 | 8559 | break; |
d8041cc8 | 8560 | |
c26fbbca | 8561 | case TRUTH_AND_EXPR: |
9702143f | 8562 | case TRUTH_ANDIF_EXPR: |
d8041cc8 RH |
8563 | case BIT_AND_EXPR: |
8564 | op = DW_OP_and; | |
8565 | goto do_binop; | |
e7af1d45 | 8566 | |
9702143f | 8567 | case TRUTH_XOR_EXPR: |
d8041cc8 RH |
8568 | case BIT_XOR_EXPR: |
8569 | op = DW_OP_xor; | |
8570 | goto do_binop; | |
e7af1d45 | 8571 | |
9702143f RK |
8572 | case TRUTH_OR_EXPR: |
8573 | case TRUTH_ORIF_EXPR: | |
d8041cc8 RH |
8574 | case BIT_IOR_EXPR: |
8575 | op = DW_OP_or; | |
8576 | goto do_binop; | |
e7af1d45 | 8577 | |
8dcea3f3 VC |
8578 | case FLOOR_DIV_EXPR: |
8579 | case CEIL_DIV_EXPR: | |
8580 | case ROUND_DIV_EXPR: | |
d8041cc8 RH |
8581 | case TRUNC_DIV_EXPR: |
8582 | op = DW_OP_div; | |
8583 | goto do_binop; | |
e7af1d45 | 8584 | |
d8041cc8 RH |
8585 | case MINUS_EXPR: |
8586 | op = DW_OP_minus; | |
8587 | goto do_binop; | |
e7af1d45 | 8588 | |
8dcea3f3 VC |
8589 | case FLOOR_MOD_EXPR: |
8590 | case CEIL_MOD_EXPR: | |
8591 | case ROUND_MOD_EXPR: | |
d8041cc8 RH |
8592 | case TRUNC_MOD_EXPR: |
8593 | op = DW_OP_mod; | |
8594 | goto do_binop; | |
e7af1d45 | 8595 | |
d8041cc8 RH |
8596 | case MULT_EXPR: |
8597 | op = DW_OP_mul; | |
8598 | goto do_binop; | |
e7af1d45 | 8599 | |
d8041cc8 RH |
8600 | case LSHIFT_EXPR: |
8601 | op = DW_OP_shl; | |
8602 | goto do_binop; | |
e7af1d45 | 8603 | |
d8041cc8 RH |
8604 | case RSHIFT_EXPR: |
8605 | op = (unsignedp ? DW_OP_shr : DW_OP_shra); | |
8606 | goto do_binop; | |
e7af1d45 | 8607 | |
d8041cc8 RH |
8608 | case PLUS_EXPR: |
8609 | if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST | |
8610 | && host_integerp (TREE_OPERAND (loc, 1), 0)) | |
8611 | { | |
8612 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8613 | if (ret == 0) |
8614 | return 0; | |
8615 | ||
d8041cc8 RH |
8616 | add_loc_descr (&ret, |
8617 | new_loc_descr (DW_OP_plus_uconst, | |
8618 | tree_low_cst (TREE_OPERAND (loc, 1), | |
8619 | 0), | |
8620 | 0)); | |
8621 | break; | |
8622 | } | |
e7af1d45 | 8623 | |
d8041cc8 RH |
8624 | op = DW_OP_plus; |
8625 | goto do_binop; | |
2ad9852d | 8626 | |
d8041cc8 RH |
8627 | case LE_EXPR: |
8628 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8629 | return 0; |
8630 | ||
d8041cc8 RH |
8631 | op = DW_OP_le; |
8632 | goto do_binop; | |
e7af1d45 | 8633 | |
d8041cc8 RH |
8634 | case GE_EXPR: |
8635 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8636 | return 0; |
8637 | ||
d8041cc8 RH |
8638 | op = DW_OP_ge; |
8639 | goto do_binop; | |
e7af1d45 | 8640 | |
d8041cc8 RH |
8641 | case LT_EXPR: |
8642 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8643 | return 0; |
8644 | ||
d8041cc8 RH |
8645 | op = DW_OP_lt; |
8646 | goto do_binop; | |
e7af1d45 | 8647 | |
d8041cc8 RH |
8648 | case GT_EXPR: |
8649 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8650 | return 0; |
8651 | ||
d8041cc8 RH |
8652 | op = DW_OP_gt; |
8653 | goto do_binop; | |
e7af1d45 | 8654 | |
d8041cc8 RH |
8655 | case EQ_EXPR: |
8656 | op = DW_OP_eq; | |
8657 | goto do_binop; | |
e7af1d45 | 8658 | |
d8041cc8 RH |
8659 | case NE_EXPR: |
8660 | op = DW_OP_ne; | |
8661 | goto do_binop; | |
8662 | ||
8663 | do_binop: | |
8664 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8665 | ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); |
8666 | if (ret == 0 || ret1 == 0) | |
8667 | return 0; | |
8668 | ||
8669 | add_loc_descr (&ret, ret1); | |
d8041cc8 RH |
8670 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); |
8671 | break; | |
8672 | ||
9702143f | 8673 | case TRUTH_NOT_EXPR: |
d8041cc8 RH |
8674 | case BIT_NOT_EXPR: |
8675 | op = DW_OP_not; | |
8676 | goto do_unop; | |
e7af1d45 | 8677 | |
d8041cc8 RH |
8678 | case ABS_EXPR: |
8679 | op = DW_OP_abs; | |
8680 | goto do_unop; | |
e7af1d45 | 8681 | |
d8041cc8 RH |
8682 | case NEGATE_EXPR: |
8683 | op = DW_OP_neg; | |
8684 | goto do_unop; | |
8685 | ||
8686 | do_unop: | |
8687 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8688 | if (ret == 0) |
8689 | return 0; | |
8690 | ||
d8041cc8 RH |
8691 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); |
8692 | break; | |
8693 | ||
8694 | case MAX_EXPR: | |
8695 | loc = build (COND_EXPR, TREE_TYPE (loc), | |
8696 | build (LT_EXPR, integer_type_node, | |
8697 | TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)), | |
8698 | TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0)); | |
2ad9852d | 8699 | |
3ef42a0c | 8700 | /* ... fall through ... */ |
d8041cc8 RH |
8701 | |
8702 | case COND_EXPR: | |
8703 | { | |
e7af1d45 RK |
8704 | dw_loc_descr_ref lhs |
8705 | = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); | |
8706 | dw_loc_descr_ref rhs | |
8707 | = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0); | |
d8041cc8 RH |
8708 | dw_loc_descr_ref bra_node, jump_node, tmp; |
8709 | ||
8710 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8711 | if (ret == 0 || lhs == 0 || rhs == 0) |
8712 | return 0; | |
8713 | ||
d8041cc8 RH |
8714 | bra_node = new_loc_descr (DW_OP_bra, 0, 0); |
8715 | add_loc_descr (&ret, bra_node); | |
8716 | ||
e7af1d45 | 8717 | add_loc_descr (&ret, rhs); |
d8041cc8 RH |
8718 | jump_node = new_loc_descr (DW_OP_skip, 0, 0); |
8719 | add_loc_descr (&ret, jump_node); | |
8720 | ||
e7af1d45 | 8721 | add_loc_descr (&ret, lhs); |
d8041cc8 | 8722 | bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc; |
e7af1d45 | 8723 | bra_node->dw_loc_oprnd1.v.val_loc = lhs; |
d8041cc8 RH |
8724 | |
8725 | /* ??? Need a node to point the skip at. Use a nop. */ | |
8726 | tmp = new_loc_descr (DW_OP_nop, 0, 0); | |
8727 | add_loc_descr (&ret, tmp); | |
8728 | jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc; | |
8729 | jump_node->dw_loc_oprnd1.v.val_loc = tmp; | |
8730 | } | |
8731 | break; | |
8732 | ||
8733 | default: | |
7d445f15 RH |
8734 | /* Leave front-end specific codes as simply unknown. This comes |
8735 | up, for instance, with the C STMT_EXPR. */ | |
8736 | if ((unsigned int) TREE_CODE (loc) | |
8737 | >= (unsigned int) LAST_AND_UNUSED_TREE_CODE) | |
8738 | return 0; | |
8739 | ||
8740 | /* Otherwise this is a generic code; we should just lists all of | |
8741 | these explicitly. Aborting means we forgot one. */ | |
d8041cc8 RH |
8742 | abort (); |
8743 | } | |
8744 | ||
e7af1d45 RK |
8745 | /* Show if we can't fill the request for an address. */ |
8746 | if (addressp && indirect_p == 0) | |
8747 | return 0; | |
d8041cc8 RH |
8748 | |
8749 | /* If we've got an address and don't want one, dereference. */ | |
e7af1d45 | 8750 | if (!addressp && indirect_p > 0) |
d8041cc8 | 8751 | { |
e7af1d45 RK |
8752 | HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc)); |
8753 | ||
8754 | if (size > DWARF2_ADDR_SIZE || size == -1) | |
8755 | return 0; | |
2ad9852d | 8756 | else if (size == DWARF2_ADDR_SIZE) |
d8041cc8 RH |
8757 | op = DW_OP_deref; |
8758 | else | |
8759 | op = DW_OP_deref_size; | |
e7af1d45 RK |
8760 | |
8761 | add_loc_descr (&ret, new_loc_descr (op, size, 0)); | |
d8041cc8 RH |
8762 | } |
8763 | ||
8764 | return ret; | |
8765 | } | |
8766 | ||
665f2503 | 8767 | /* Given a value, round it up to the lowest multiple of `boundary' |
a3f97cbb | 8768 | which is not less than the value itself. */ |
71dfc51f | 8769 | |
665f2503 | 8770 | static inline HOST_WIDE_INT |
7080f735 | 8771 | ceiling (HOST_WIDE_INT value, unsigned int boundary) |
a3f97cbb JW |
8772 | { |
8773 | return (((value + boundary - 1) / boundary) * boundary); | |
8774 | } | |
8775 | ||
8776 | /* Given a pointer to what is assumed to be a FIELD_DECL node, return a | |
8777 | pointer to the declared type for the relevant field variable, or return | |
8778 | `integer_type_node' if the given node turns out to be an | |
8779 | ERROR_MARK node. */ | |
71dfc51f RK |
8780 | |
8781 | static inline tree | |
7080f735 | 8782 | field_type (tree decl) |
a3f97cbb | 8783 | { |
b3694847 | 8784 | tree type; |
a3f97cbb JW |
8785 | |
8786 | if (TREE_CODE (decl) == ERROR_MARK) | |
8787 | return integer_type_node; | |
8788 | ||
8789 | type = DECL_BIT_FIELD_TYPE (decl); | |
71dfc51f | 8790 | if (type == NULL_TREE) |
a3f97cbb JW |
8791 | type = TREE_TYPE (decl); |
8792 | ||
8793 | return type; | |
8794 | } | |
8795 | ||
5f446d21 DD |
8796 | /* Given a pointer to a tree node, return the alignment in bits for |
8797 | it, or else return BITS_PER_WORD if the node actually turns out to | |
8798 | be an ERROR_MARK node. */ | |
71dfc51f RK |
8799 | |
8800 | static inline unsigned | |
7080f735 | 8801 | simple_type_align_in_bits (tree type) |
a3f97cbb JW |
8802 | { |
8803 | return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; | |
8804 | } | |
8805 | ||
5f446d21 | 8806 | static inline unsigned |
7080f735 | 8807 | simple_decl_align_in_bits (tree decl) |
5f446d21 DD |
8808 | { |
8809 | return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD; | |
8810 | } | |
8811 | ||
2ad9852d RK |
8812 | /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the |
8813 | lowest addressed byte of the "containing object" for the given FIELD_DECL, | |
8814 | or return 0 if we are unable to determine what that offset is, either | |
8815 | because the argument turns out to be a pointer to an ERROR_MARK node, or | |
8816 | because the offset is actually variable. (We can't handle the latter case | |
8817 | just yet). */ | |
71dfc51f | 8818 | |
665f2503 | 8819 | static HOST_WIDE_INT |
7080f735 | 8820 | field_byte_offset (tree decl) |
a3f97cbb | 8821 | { |
665f2503 | 8822 | unsigned int type_align_in_bits; |
5f446d21 | 8823 | unsigned int decl_align_in_bits; |
665f2503 | 8824 | unsigned HOST_WIDE_INT type_size_in_bits; |
665f2503 | 8825 | HOST_WIDE_INT object_offset_in_bits; |
665f2503 RK |
8826 | tree type; |
8827 | tree field_size_tree; | |
8828 | HOST_WIDE_INT bitpos_int; | |
8829 | HOST_WIDE_INT deepest_bitpos; | |
8830 | unsigned HOST_WIDE_INT field_size_in_bits; | |
a3f97cbb JW |
8831 | |
8832 | if (TREE_CODE (decl) == ERROR_MARK) | |
8833 | return 0; | |
2ad9852d | 8834 | else if (TREE_CODE (decl) != FIELD_DECL) |
a3f97cbb JW |
8835 | abort (); |
8836 | ||
8837 | type = field_type (decl); | |
a3f97cbb JW |
8838 | field_size_tree = DECL_SIZE (decl); |
8839 | ||
3df18884 RH |
8840 | /* The size could be unspecified if there was an error, or for |
8841 | a flexible array member. */ | |
50352c9c | 8842 | if (! field_size_tree) |
3df18884 | 8843 | field_size_tree = bitsize_zero_node; |
50352c9c | 8844 | |
556273e0 | 8845 | /* We cannot yet cope with fields whose positions are variable, so |
a3f97cbb JW |
8846 | for now, when we see such things, we simply return 0. Someday, we may |
8847 | be able to handle such cases, but it will be damn difficult. */ | |
665f2503 | 8848 | if (! host_integerp (bit_position (decl), 0)) |
a3f97cbb | 8849 | return 0; |
14a774a9 | 8850 | |
665f2503 | 8851 | bitpos_int = int_bit_position (decl); |
a3f97cbb | 8852 | |
3df18884 | 8853 | /* If we don't know the size of the field, pretend it's a full word. */ |
665f2503 RK |
8854 | if (host_integerp (field_size_tree, 1)) |
8855 | field_size_in_bits = tree_low_cst (field_size_tree, 1); | |
14a774a9 RK |
8856 | else |
8857 | field_size_in_bits = BITS_PER_WORD; | |
a3f97cbb JW |
8858 | |
8859 | type_size_in_bits = simple_type_size_in_bits (type); | |
a3f97cbb | 8860 | type_align_in_bits = simple_type_align_in_bits (type); |
5f446d21 | 8861 | decl_align_in_bits = simple_decl_align_in_bits (decl); |
a3f97cbb | 8862 | |
2ad9852d RK |
8863 | /* The GCC front-end doesn't make any attempt to keep track of the starting |
8864 | bit offset (relative to the start of the containing structure type) of the | |
8865 | hypothetical "containing object" for a bit-field. Thus, when computing | |
8866 | the byte offset value for the start of the "containing object" of a | |
8867 | bit-field, we must deduce this information on our own. This can be rather | |
8868 | tricky to do in some cases. For example, handling the following structure | |
8869 | type definition when compiling for an i386/i486 target (which only aligns | |
8870 | long long's to 32-bit boundaries) can be very tricky: | |
a3f97cbb JW |
8871 | |
8872 | struct S { int field1; long long field2:31; }; | |
8873 | ||
2ad9852d RK |
8874 | Fortunately, there is a simple rule-of-thumb which can be used in such |
8875 | cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the | |
8876 | structure shown above. It decides to do this based upon one simple rule | |
8877 | for bit-field allocation. GCC allocates each "containing object" for each | |
8878 | bit-field at the first (i.e. lowest addressed) legitimate alignment | |
8879 | boundary (based upon the required minimum alignment for the declared type | |
8880 | of the field) which it can possibly use, subject to the condition that | |
8881 | there is still enough available space remaining in the containing object | |
8882 | (when allocated at the selected point) to fully accommodate all of the | |
8883 | bits of the bit-field itself. | |
8884 | ||
8885 | This simple rule makes it obvious why GCC allocates 8 bytes for each | |
8886 | object of the structure type shown above. When looking for a place to | |
8887 | allocate the "containing object" for `field2', the compiler simply tries | |
8888 | to allocate a 64-bit "containing object" at each successive 32-bit | |
8889 | boundary (starting at zero) until it finds a place to allocate that 64- | |
8890 | bit field such that at least 31 contiguous (and previously unallocated) | |
8891 | bits remain within that selected 64 bit field. (As it turns out, for the | |
8892 | example above, the compiler finds it is OK to allocate the "containing | |
8893 | object" 64-bit field at bit-offset zero within the structure type.) | |
8894 | ||
8895 | Here we attempt to work backwards from the limited set of facts we're | |
8896 | given, and we try to deduce from those facts, where GCC must have believed | |
8897 | that the containing object started (within the structure type). The value | |
8898 | we deduce is then used (by the callers of this routine) to generate | |
8899 | DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields | |
8900 | and, in the case of DW_AT_location, regular fields as well). */ | |
a3f97cbb JW |
8901 | |
8902 | /* Figure out the bit-distance from the start of the structure to the | |
8903 | "deepest" bit of the bit-field. */ | |
8904 | deepest_bitpos = bitpos_int + field_size_in_bits; | |
8905 | ||
8906 | /* This is the tricky part. Use some fancy footwork to deduce where the | |
8907 | lowest addressed bit of the containing object must be. */ | |
5f446d21 DD |
8908 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; |
8909 | ||
8910 | /* Round up to type_align by default. This works best for bitfields. */ | |
8911 | object_offset_in_bits += type_align_in_bits - 1; | |
8912 | object_offset_in_bits /= type_align_in_bits; | |
8913 | object_offset_in_bits *= type_align_in_bits; | |
a3f97cbb | 8914 | |
5f446d21 DD |
8915 | if (object_offset_in_bits > bitpos_int) |
8916 | { | |
8917 | /* Sigh, the decl must be packed. */ | |
8918 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; | |
8919 | ||
8920 | /* Round up to decl_align instead. */ | |
8921 | object_offset_in_bits += decl_align_in_bits - 1; | |
8922 | object_offset_in_bits /= decl_align_in_bits; | |
8923 | object_offset_in_bits *= decl_align_in_bits; | |
8924 | } | |
a3f97cbb | 8925 | |
2ad9852d | 8926 | return object_offset_in_bits / BITS_PER_UNIT; |
a3f97cbb | 8927 | } |
a3f97cbb | 8928 | \f |
71dfc51f RK |
8929 | /* The following routines define various Dwarf attributes and any data |
8930 | associated with them. */ | |
a3f97cbb | 8931 | |
ef76d03b | 8932 | /* Add a location description attribute value to a DIE. |
a3f97cbb | 8933 | |
ef76d03b | 8934 | This emits location attributes suitable for whole variables and |
a3f97cbb JW |
8935 | whole parameters. Note that the location attributes for struct fields are |
8936 | generated by the routine `data_member_location_attribute' below. */ | |
71dfc51f | 8937 | |
b9203463 | 8938 | static inline void |
7080f735 AJ |
8939 | add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind, |
8940 | dw_loc_descr_ref descr) | |
a3f97cbb | 8941 | { |
e7af1d45 RK |
8942 | if (descr != 0) |
8943 | add_AT_loc (die, attr_kind, descr); | |
a3f97cbb JW |
8944 | } |
8945 | ||
2ad9852d RK |
8946 | /* Attach the specialized form of location attribute used for data members of |
8947 | struct and union types. In the special case of a FIELD_DECL node which | |
8948 | represents a bit-field, the "offset" part of this special location | |
8949 | descriptor must indicate the distance in bytes from the lowest-addressed | |
8950 | byte of the containing struct or union type to the lowest-addressed byte of | |
8951 | the "containing object" for the bit-field. (See the `field_byte_offset' | |
8952 | function above). | |
8953 | ||
8954 | For any given bit-field, the "containing object" is a hypothetical object | |
8955 | (of some integral or enum type) within which the given bit-field lives. The | |
8956 | type of this hypothetical "containing object" is always the same as the | |
8957 | declared type of the individual bit-field itself (for GCC anyway... the | |
8958 | DWARF spec doesn't actually mandate this). Note that it is the size (in | |
8959 | bytes) of the hypothetical "containing object" which will be given in the | |
8960 | DW_AT_byte_size attribute for this bit-field. (See the | |
8961 | `byte_size_attribute' function below.) It is also used when calculating the | |
8962 | value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute' | |
8963 | function below.) */ | |
71dfc51f | 8964 | |
a3f97cbb | 8965 | static void |
7080f735 | 8966 | add_data_member_location_attribute (dw_die_ref die, tree decl) |
a3f97cbb | 8967 | { |
649ce3f2 JM |
8968 | long offset; |
8969 | dw_loc_descr_ref loc_descr = 0; | |
a3f97cbb | 8970 | |
61b32c02 | 8971 | if (TREE_CODE (decl) == TREE_VEC) |
649ce3f2 JM |
8972 | { |
8973 | /* We're working on the TAG_inheritance for a base class. */ | |
1d3d6b1e | 8974 | if (TREE_VIA_VIRTUAL (decl) && is_cxx ()) |
649ce3f2 JM |
8975 | { |
8976 | /* For C++ virtual bases we can't just use BINFO_OFFSET, as they | |
8977 | aren't at a fixed offset from all (sub)objects of the same | |
8978 | type. We need to extract the appropriate offset from our | |
8979 | vtable. The following dwarf expression means | |
8980 | ||
8981 | BaseAddr = ObAddr + *((*ObAddr) - Offset) | |
8982 | ||
8983 | This is specific to the V3 ABI, of course. */ | |
8984 | ||
8985 | dw_loc_descr_ref tmp; | |
2ad9852d | 8986 | |
649ce3f2 JM |
8987 | /* Make a copy of the object address. */ |
8988 | tmp = new_loc_descr (DW_OP_dup, 0, 0); | |
8989 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 8990 | |
649ce3f2 JM |
8991 | /* Extract the vtable address. */ |
8992 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
8993 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 8994 | |
649ce3f2 JM |
8995 | /* Calculate the address of the offset. */ |
8996 | offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0); | |
8997 | if (offset >= 0) | |
8998 | abort (); | |
2ad9852d | 8999 | |
649ce3f2 JM |
9000 | tmp = int_loc_descriptor (-offset); |
9001 | add_loc_descr (&loc_descr, tmp); | |
9002 | tmp = new_loc_descr (DW_OP_minus, 0, 0); | |
9003 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 9004 | |
649ce3f2 JM |
9005 | /* Extract the offset. */ |
9006 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
9007 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 9008 | |
649ce3f2 JM |
9009 | /* Add it to the object address. */ |
9010 | tmp = new_loc_descr (DW_OP_plus, 0, 0); | |
9011 | add_loc_descr (&loc_descr, tmp); | |
9012 | } | |
9013 | else | |
9014 | offset = tree_low_cst (BINFO_OFFSET (decl), 0); | |
9015 | } | |
61b32c02 JM |
9016 | else |
9017 | offset = field_byte_offset (decl); | |
9018 | ||
649ce3f2 JM |
9019 | if (! loc_descr) |
9020 | { | |
9021 | enum dwarf_location_atom op; | |
9022 | ||
2ad9852d RK |
9023 | /* The DWARF2 standard says that we should assume that the structure |
9024 | address is already on the stack, so we can specify a structure field | |
9025 | address by using DW_OP_plus_uconst. */ | |
71dfc51f | 9026 | |
a3f97cbb | 9027 | #ifdef MIPS_DEBUGGING_INFO |
2ad9852d RK |
9028 | /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst |
9029 | operator correctly. It works only if we leave the offset on the | |
9030 | stack. */ | |
649ce3f2 | 9031 | op = DW_OP_constu; |
a3f97cbb | 9032 | #else |
649ce3f2 | 9033 | op = DW_OP_plus_uconst; |
a3f97cbb | 9034 | #endif |
71dfc51f | 9035 | |
649ce3f2 JM |
9036 | loc_descr = new_loc_descr (op, offset, 0); |
9037 | } | |
2ad9852d | 9038 | |
a3f97cbb JW |
9039 | add_AT_loc (die, DW_AT_data_member_location, loc_descr); |
9040 | } | |
9041 | ||
b20b352b | 9042 | /* Attach a DW_AT_const_value attribute for a variable or a parameter which |
a3f97cbb JW |
9043 | does not have a "location" either in memory or in a register. These |
9044 | things can arise in GNU C when a constant is passed as an actual parameter | |
9045 | to an inlined function. They can also arise in C++ where declared | |
9046 | constants do not necessarily get memory "homes". */ | |
71dfc51f | 9047 | |
a3f97cbb | 9048 | static void |
7080f735 | 9049 | add_const_value_attribute (dw_die_ref die, rtx rtl) |
a3f97cbb JW |
9050 | { |
9051 | switch (GET_CODE (rtl)) | |
9052 | { | |
9053 | case CONST_INT: | |
2e4b9b8c RH |
9054 | /* Note that a CONST_INT rtx could represent either an integer |
9055 | or a floating-point constant. A CONST_INT is used whenever | |
9056 | the constant will fit into a single word. In all such | |
9057 | cases, the original mode of the constant value is wiped | |
9058 | out, and the CONST_INT rtx is assigned VOIDmode. */ | |
9059 | { | |
9060 | HOST_WIDE_INT val = INTVAL (rtl); | |
c26fbbca | 9061 | |
2e4b9b8c | 9062 | /* ??? We really should be using HOST_WIDE_INT throughout. */ |
5929a2f0 | 9063 | if (val < 0 && (long) val == val) |
3d7a191f | 9064 | add_AT_int (die, DW_AT_const_value, (long) val); |
5929a2f0 RH |
9065 | else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val) |
9066 | add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val); | |
94784fb9 RK |
9067 | else |
9068 | { | |
e7af1d45 | 9069 | #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT |
94784fb9 RK |
9070 | add_AT_long_long (die, DW_AT_const_value, |
9071 | val >> HOST_BITS_PER_LONG, val); | |
e7af1d45 | 9072 | #else |
94784fb9 | 9073 | abort (); |
e7af1d45 | 9074 | #endif |
94784fb9 | 9075 | } |
2e4b9b8c | 9076 | } |
a3f97cbb JW |
9077 | break; |
9078 | ||
9079 | case CONST_DOUBLE: | |
9080 | /* Note that a CONST_DOUBLE rtx could represent either an integer or a | |
73c68f61 SS |
9081 | floating-point constant. A CONST_DOUBLE is used whenever the |
9082 | constant requires more than one word in order to be adequately | |
9083 | represented. We output CONST_DOUBLEs as blocks. */ | |
469ac993 | 9084 | { |
b3694847 | 9085 | enum machine_mode mode = GET_MODE (rtl); |
469ac993 JM |
9086 | |
9087 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
9088 | { | |
b3694847 | 9089 | unsigned length = GET_MODE_SIZE (mode) / 4; |
703ad42b | 9090 | long *array = ggc_alloc (sizeof (long) * length); |
71dfc51f | 9091 | REAL_VALUE_TYPE rv; |
469ac993 | 9092 | |
71dfc51f | 9093 | REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl); |
469ac993 JM |
9094 | switch (mode) |
9095 | { | |
9096 | case SFmode: | |
71dfc51f | 9097 | REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]); |
469ac993 JM |
9098 | break; |
9099 | ||
9100 | case DFmode: | |
71dfc51f | 9101 | REAL_VALUE_TO_TARGET_DOUBLE (rv, array); |
469ac993 JM |
9102 | break; |
9103 | ||
9104 | case XFmode: | |
9105 | case TFmode: | |
71dfc51f | 9106 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array); |
469ac993 JM |
9107 | break; |
9108 | ||
9109 | default: | |
9110 | abort (); | |
9111 | } | |
9112 | ||
469ac993 JM |
9113 | add_AT_float (die, DW_AT_const_value, length, array); |
9114 | } | |
9115 | else | |
2e4b9b8c RH |
9116 | { |
9117 | /* ??? We really should be using HOST_WIDE_INT throughout. */ | |
9118 | if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT) | |
9119 | abort (); | |
2ad9852d | 9120 | |
2e4b9b8c RH |
9121 | add_AT_long_long (die, DW_AT_const_value, |
9122 | CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl)); | |
9123 | } | |
469ac993 | 9124 | } |
a3f97cbb JW |
9125 | break; |
9126 | ||
9127 | case CONST_STRING: | |
9128 | add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0)); | |
9129 | break; | |
9130 | ||
9131 | case SYMBOL_REF: | |
9132 | case LABEL_REF: | |
9133 | case CONST: | |
c470afad RK |
9134 | add_AT_addr (die, DW_AT_const_value, rtl); |
9135 | VARRAY_PUSH_RTX (used_rtx_varray, rtl); | |
a3f97cbb JW |
9136 | break; |
9137 | ||
9138 | case PLUS: | |
9139 | /* In cases where an inlined instance of an inline function is passed | |
73c68f61 SS |
9140 | the address of an `auto' variable (which is local to the caller) we |
9141 | can get a situation where the DECL_RTL of the artificial local | |
9142 | variable (for the inlining) which acts as a stand-in for the | |
9143 | corresponding formal parameter (of the inline function) will look | |
9144 | like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not | |
9145 | exactly a compile-time constant expression, but it isn't the address | |
9146 | of the (artificial) local variable either. Rather, it represents the | |
9147 | *value* which the artificial local variable always has during its | |
9148 | lifetime. We currently have no way to represent such quasi-constant | |
9149 | values in Dwarf, so for now we just punt and generate nothing. */ | |
a3f97cbb JW |
9150 | break; |
9151 | ||
9152 | default: | |
9153 | /* No other kinds of rtx should be possible here. */ | |
9154 | abort (); | |
9155 | } | |
9156 | ||
9157 | } | |
9158 | ||
d8041cc8 | 9159 | static rtx |
7080f735 | 9160 | rtl_for_decl_location (tree decl) |
a3f97cbb | 9161 | { |
b3694847 | 9162 | rtx rtl; |
71dfc51f | 9163 | |
a3f97cbb JW |
9164 | /* Here we have to decide where we are going to say the parameter "lives" |
9165 | (as far as the debugger is concerned). We only have a couple of | |
9166 | choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. | |
71dfc51f | 9167 | |
556273e0 | 9168 | DECL_RTL normally indicates where the parameter lives during most of the |
71dfc51f | 9169 | activation of the function. If optimization is enabled however, this |
556273e0 | 9170 | could be either NULL or else a pseudo-reg. Both of those cases indicate |
a3f97cbb JW |
9171 | that the parameter doesn't really live anywhere (as far as the code |
9172 | generation parts of GCC are concerned) during most of the function's | |
9173 | activation. That will happen (for example) if the parameter is never | |
71dfc51f RK |
9174 | referenced within the function. |
9175 | ||
9176 | We could just generate a location descriptor here for all non-NULL | |
9177 | non-pseudo values of DECL_RTL and ignore all of the rest, but we can be | |
9178 | a little nicer than that if we also consider DECL_INCOMING_RTL in cases | |
9179 | where DECL_RTL is NULL or is a pseudo-reg. | |
9180 | ||
9181 | Note however that we can only get away with using DECL_INCOMING_RTL as | |
9182 | a backup substitute for DECL_RTL in certain limited cases. In cases | |
9183 | where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl), | |
9184 | we can be sure that the parameter was passed using the same type as it is | |
9185 | declared to have within the function, and that its DECL_INCOMING_RTL | |
9186 | points us to a place where a value of that type is passed. | |
9187 | ||
9188 | In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different, | |
9189 | we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL | |
9190 | because in these cases DECL_INCOMING_RTL points us to a value of some | |
9191 | type which is *different* from the type of the parameter itself. Thus, | |
9192 | if we tried to use DECL_INCOMING_RTL to generate a location attribute in | |
9193 | such cases, the debugger would end up (for example) trying to fetch a | |
9194 | `float' from a place which actually contains the first part of a | |
9195 | `double'. That would lead to really incorrect and confusing | |
9196 | output at debug-time. | |
9197 | ||
9198 | So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL | |
9199 | in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There | |
9200 | are a couple of exceptions however. On little-endian machines we can | |
9201 | get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is | |
9202 | not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is | |
9203 | an integral type that is smaller than TREE_TYPE (decl). These cases arise | |
9204 | when (on a little-endian machine) a non-prototyped function has a | |
9205 | parameter declared to be of type `short' or `char'. In such cases, | |
9206 | TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will | |
9207 | be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the | |
9208 | passed `int' value. If the debugger then uses that address to fetch | |
9209 | a `short' or a `char' (on a little-endian machine) the result will be | |
9210 | the correct data, so we allow for such exceptional cases below. | |
9211 | ||
9212 | Note that our goal here is to describe the place where the given formal | |
2ad9852d RK |
9213 | parameter lives during most of the function's activation (i.e. between the |
9214 | end of the prologue and the start of the epilogue). We'll do that as best | |
9215 | as we can. Note however that if the given formal parameter is modified | |
9216 | sometime during the execution of the function, then a stack backtrace (at | |
9217 | debug-time) will show the function as having been called with the *new* | |
9218 | value rather than the value which was originally passed in. This happens | |
9219 | rarely enough that it is not a major problem, but it *is* a problem, and | |
9220 | I'd like to fix it. | |
9221 | ||
9222 | A future version of dwarf2out.c may generate two additional attributes for | |
9223 | any given DW_TAG_formal_parameter DIE which will describe the "passed | |
9224 | type" and the "passed location" for the given formal parameter in addition | |
9225 | to the attributes we now generate to indicate the "declared type" and the | |
9226 | "active location" for each parameter. This additional set of attributes | |
9227 | could be used by debuggers for stack backtraces. Separately, note that | |
9228 | sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also. | |
9229 | This happens (for example) for inlined-instances of inline function formal | |
9230 | parameters which are never referenced. This really shouldn't be | |
9231 | happening. All PARM_DECL nodes should get valid non-NULL | |
9232 | DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these | |
9233 | values for inlined instances of inline function parameters, so when we see | |
9234 | such cases, we are just out-of-luck for the time being (until integrate.c | |
a3f97cbb JW |
9235 | gets fixed). */ |
9236 | ||
9237 | /* Use DECL_RTL as the "location" unless we find something better. */ | |
110c3568 | 9238 | rtl = DECL_RTL_IF_SET (decl); |
a3f97cbb | 9239 | |
c28abdf0 | 9240 | /* When generating abstract instances, ignore everything except |
234c071b KB |
9241 | constants, symbols living in memory, and symbols living in |
9242 | fixed registers. */ | |
c28abdf0 RH |
9243 | if (! reload_completed) |
9244 | { | |
9245 | if (rtl | |
9246 | && (CONSTANT_P (rtl) | |
9247 | || (GET_CODE (rtl) == MEM | |
234c071b KB |
9248 | && CONSTANT_P (XEXP (rtl, 0))) |
9249 | || (GET_CODE (rtl) == REG | |
9250 | && TREE_CODE (decl) == VAR_DECL | |
9251 | && TREE_STATIC (decl)))) | |
4c8c0dec | 9252 | { |
69bd9368 | 9253 | rtl = (*targetm.delegitimize_address) (rtl); |
4c8c0dec JJ |
9254 | return rtl; |
9255 | } | |
c28abdf0 RH |
9256 | rtl = NULL_RTX; |
9257 | } | |
9258 | else if (TREE_CODE (decl) == PARM_DECL) | |
a3f97cbb JW |
9259 | { |
9260 | if (rtl == NULL_RTX || is_pseudo_reg (rtl)) | |
9261 | { | |
d8041cc8 RH |
9262 | tree declared_type = type_main_variant (TREE_TYPE (decl)); |
9263 | tree passed_type = type_main_variant (DECL_ARG_TYPE (decl)); | |
a3f97cbb | 9264 | |
71dfc51f | 9265 | /* This decl represents a formal parameter which was optimized out. |
a3f97cbb | 9266 | Note that DECL_INCOMING_RTL may be NULL in here, but we handle |
2ad9852d | 9267 | all cases where (rtl == NULL_RTX) just below. */ |
a3f97cbb | 9268 | if (declared_type == passed_type) |
71dfc51f RK |
9269 | rtl = DECL_INCOMING_RTL (decl); |
9270 | else if (! BYTES_BIG_ENDIAN | |
9271 | && TREE_CODE (declared_type) == INTEGER_TYPE | |
555b6442 HPN |
9272 | && (GET_MODE_SIZE (TYPE_MODE (declared_type)) |
9273 | <= GET_MODE_SIZE (TYPE_MODE (passed_type)))) | |
556273e0 | 9274 | rtl = DECL_INCOMING_RTL (decl); |
a3f97cbb | 9275 | } |
5a904a61 JW |
9276 | |
9277 | /* If the parm was passed in registers, but lives on the stack, then | |
9278 | make a big endian correction if the mode of the type of the | |
9279 | parameter is not the same as the mode of the rtl. */ | |
9280 | /* ??? This is the same series of checks that are made in dbxout.c before | |
9281 | we reach the big endian correction code there. It isn't clear if all | |
9282 | of these checks are necessary here, but keeping them all is the safe | |
9283 | thing to do. */ | |
9284 | else if (GET_CODE (rtl) == MEM | |
9285 | && XEXP (rtl, 0) != const0_rtx | |
9286 | && ! CONSTANT_P (XEXP (rtl, 0)) | |
9287 | /* Not passed in memory. */ | |
9288 | && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM | |
9289 | /* Not passed by invisible reference. */ | |
9290 | && (GET_CODE (XEXP (rtl, 0)) != REG | |
9291 | || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM | |
9292 | || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM | |
9293 | #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM | |
9294 | || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM | |
9295 | #endif | |
9296 | ) | |
9297 | /* Big endian correction check. */ | |
9298 | && BYTES_BIG_ENDIAN | |
9299 | && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl) | |
9300 | && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))) | |
9301 | < UNITS_PER_WORD)) | |
9302 | { | |
9303 | int offset = (UNITS_PER_WORD | |
9304 | - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))); | |
2ad9852d | 9305 | |
5a904a61 JW |
9306 | rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)), |
9307 | plus_constant (XEXP (rtl, 0), offset)); | |
9308 | } | |
a3f97cbb | 9309 | } |
71dfc51f | 9310 | |
d8041cc8 RH |
9311 | if (rtl != NULL_RTX) |
9312 | { | |
9313 | rtl = eliminate_regs (rtl, 0, NULL_RTX); | |
6a7a9f01 | 9314 | #ifdef LEAF_REG_REMAP |
d8041cc8 RH |
9315 | if (current_function_uses_only_leaf_regs) |
9316 | leaf_renumber_regs_insn (rtl); | |
6a7a9f01 | 9317 | #endif |
d8041cc8 RH |
9318 | } |
9319 | ||
2ad9852d RK |
9320 | /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant, |
9321 | and will have been substituted directly into all expressions that use it. | |
9322 | C does not have such a concept, but C++ and other languages do. */ | |
c28abdf0 | 9323 | else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl)) |
6d73371a JJ |
9324 | { |
9325 | /* If a variable is initialized with a string constant without embedded | |
9326 | zeros, build CONST_STRING. */ | |
9327 | if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST | |
9328 | && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) | |
9329 | { | |
9330 | tree arrtype = TREE_TYPE (decl); | |
9331 | tree enttype = TREE_TYPE (arrtype); | |
9332 | tree domain = TYPE_DOMAIN (arrtype); | |
9333 | tree init = DECL_INITIAL (decl); | |
9334 | enum machine_mode mode = TYPE_MODE (enttype); | |
9335 | ||
9336 | if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1 | |
9337 | && domain | |
9338 | && integer_zerop (TYPE_MIN_VALUE (domain)) | |
9339 | && compare_tree_int (TYPE_MAX_VALUE (domain), | |
9340 | TREE_STRING_LENGTH (init) - 1) == 0 | |
9341 | && ((size_t) TREE_STRING_LENGTH (init) | |
9342 | == strlen (TREE_STRING_POINTER (init)) + 1)) | |
9343 | rtl = gen_rtx_CONST_STRING (VOIDmode, TREE_STRING_POINTER (init)); | |
9344 | } | |
29b91443 JM |
9345 | /* If the initializer is something that we know will expand into an |
9346 | immediate RTL constant, expand it now. Expanding anything else | |
9347 | tends to produce unresolved symbols; see debug/5770 and c++/6381. */ | |
9348 | else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST | |
9349 | || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST) | |
6d73371a JJ |
9350 | { |
9351 | rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode, | |
9352 | EXPAND_INITIALIZER); | |
29b91443 | 9353 | /* If expand_expr returns a MEM, it wasn't immediate. */ |
6d73371a | 9354 | if (rtl && GET_CODE (rtl) == MEM) |
29b91443 | 9355 | abort (); |
6d73371a JJ |
9356 | } |
9357 | } | |
8063ddcf | 9358 | |
4c8c0dec | 9359 | if (rtl) |
69bd9368 | 9360 | rtl = (*targetm.delegitimize_address) (rtl); |
b9203463 RH |
9361 | |
9362 | /* If we don't look past the constant pool, we risk emitting a | |
9363 | reference to a constant pool entry that isn't referenced from | |
9364 | code, and thus is not emitted. */ | |
9365 | if (rtl) | |
9366 | rtl = avoid_constant_pool_reference (rtl); | |
9367 | ||
d8041cc8 RH |
9368 | return rtl; |
9369 | } | |
9370 | ||
b20b352b | 9371 | /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value |
d8041cc8 RH |
9372 | data attribute for a variable or a parameter. We generate the |
9373 | DW_AT_const_value attribute only in those cases where the given variable | |
9374 | or parameter does not have a true "location" either in memory or in a | |
9375 | register. This can happen (for example) when a constant is passed as an | |
9376 | actual argument in a call to an inline function. (It's possible that | |
9377 | these things can crop up in other ways also.) Note that one type of | |
9378 | constant value which can be passed into an inlined function is a constant | |
9379 | pointer. This can happen for example if an actual argument in an inlined | |
9380 | function call evaluates to a compile-time constant address. */ | |
9381 | ||
9382 | static void | |
7080f735 | 9383 | add_location_or_const_value_attribute (dw_die_ref die, tree decl) |
d8041cc8 | 9384 | { |
b3694847 | 9385 | rtx rtl; |
b9203463 | 9386 | dw_loc_descr_ref descr; |
d8041cc8 RH |
9387 | |
9388 | if (TREE_CODE (decl) == ERROR_MARK) | |
9389 | return; | |
2ad9852d | 9390 | else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL) |
d8041cc8 RH |
9391 | abort (); |
9392 | ||
9393 | rtl = rtl_for_decl_location (decl); | |
a97c9600 RH |
9394 | if (rtl == NULL_RTX) |
9395 | return; | |
6a7a9f01 | 9396 | |
a3f97cbb JW |
9397 | switch (GET_CODE (rtl)) |
9398 | { | |
e9a25f70 | 9399 | case ADDRESSOF: |
b9203463 RH |
9400 | /* The address of a variable that was optimized away; |
9401 | don't emit anything. */ | |
e9a25f70 JL |
9402 | break; |
9403 | ||
a3f97cbb JW |
9404 | case CONST_INT: |
9405 | case CONST_DOUBLE: | |
9406 | case CONST_STRING: | |
9407 | case SYMBOL_REF: | |
9408 | case LABEL_REF: | |
9409 | case CONST: | |
9410 | case PLUS: | |
9411 | /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ | |
9412 | add_const_value_attribute (die, rtl); | |
9413 | break; | |
9414 | ||
9415 | case MEM: | |
b9203463 RH |
9416 | if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl)) |
9417 | { | |
9418 | /* Need loc_descriptor_from_tree since that's where we know | |
9419 | how to handle TLS variables. Want the object's address | |
9420 | since the top-level DW_AT_location assumes such. See | |
9421 | the confusion in loc_descriptor for reference. */ | |
9422 | descr = loc_descriptor_from_tree (decl, 1); | |
9423 | } | |
9424 | else | |
9425 | { | |
9426 | case REG: | |
9427 | case SUBREG: | |
9428 | case CONCAT: | |
9429 | descr = loc_descriptor (rtl); | |
9430 | } | |
9431 | add_AT_location_description (die, DW_AT_location, descr); | |
a3f97cbb | 9432 | break; |
7080f735 | 9433 | |
a3f97cbb | 9434 | default: |
71dfc51f | 9435 | abort (); |
a3f97cbb JW |
9436 | } |
9437 | } | |
9438 | ||
1bfb5f8f JM |
9439 | /* If we don't have a copy of this variable in memory for some reason (such |
9440 | as a C++ member constant that doesn't have an out-of-line definition), | |
9441 | we should tell the debugger about the constant value. */ | |
9442 | ||
9443 | static void | |
7080f735 | 9444 | tree_add_const_value_attribute (dw_die_ref var_die, tree decl) |
1bfb5f8f JM |
9445 | { |
9446 | tree init = DECL_INITIAL (decl); | |
9447 | tree type = TREE_TYPE (decl); | |
9448 | ||
9449 | if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init | |
9450 | && initializer_constant_valid_p (init, type) == null_pointer_node) | |
9451 | /* OK */; | |
9452 | else | |
9453 | return; | |
9454 | ||
9455 | switch (TREE_CODE (type)) | |
9456 | { | |
9457 | case INTEGER_TYPE: | |
9458 | if (host_integerp (init, 0)) | |
9459 | add_AT_unsigned (var_die, DW_AT_const_value, | |
2ad9852d | 9460 | tree_low_cst (init, 0)); |
1bfb5f8f JM |
9461 | else |
9462 | add_AT_long_long (var_die, DW_AT_const_value, | |
9463 | TREE_INT_CST_HIGH (init), | |
9464 | TREE_INT_CST_LOW (init)); | |
9465 | break; | |
9466 | ||
9467 | default:; | |
9468 | } | |
9469 | } | |
0b34cf1e | 9470 | |
b20b352b | 9471 | /* Generate a DW_AT_name attribute given some string value to be included as |
a3f97cbb | 9472 | the value of the attribute. */ |
71dfc51f | 9473 | |
c4274b22 | 9474 | static void |
7080f735 | 9475 | add_name_attribute (dw_die_ref die, const char *name_string) |
a3f97cbb | 9476 | { |
71dfc51f | 9477 | if (name_string != NULL && *name_string != 0) |
14a774a9 RK |
9478 | { |
9479 | if (demangle_name_func) | |
9480 | name_string = (*demangle_name_func) (name_string); | |
9481 | ||
9482 | add_AT_string (die, DW_AT_name, name_string); | |
9483 | } | |
a3f97cbb JW |
9484 | } |
9485 | ||
b20b352b | 9486 | /* Generate a DW_AT_comp_dir attribute for DIE. */ |
c4274b22 RH |
9487 | |
9488 | static void | |
7080f735 | 9489 | add_comp_dir_attribute (dw_die_ref die) |
c4274b22 RH |
9490 | { |
9491 | const char *wd = getpwd (); | |
9492 | if (wd != NULL) | |
9493 | add_AT_string (die, DW_AT_comp_dir, wd); | |
9494 | } | |
9495 | ||
a3f97cbb | 9496 | /* Given a tree node describing an array bound (either lower or upper) output |
466446b0 | 9497 | a representation for that bound. */ |
71dfc51f | 9498 | |
a3f97cbb | 9499 | static void |
7080f735 | 9500 | add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound) |
a3f97cbb | 9501 | { |
a3f97cbb JW |
9502 | switch (TREE_CODE (bound)) |
9503 | { | |
9504 | case ERROR_MARK: | |
9505 | return; | |
9506 | ||
3ef42a0c | 9507 | /* All fixed-bounds are represented by INTEGER_CST nodes. */ |
a3f97cbb | 9508 | case INTEGER_CST: |
665f2503 RK |
9509 | if (! host_integerp (bound, 0) |
9510 | || (bound_attr == DW_AT_lower_bound | |
28985b81 | 9511 | && (((is_c_family () || is_java ()) && integer_zerop (bound)) |
665f2503 RK |
9512 | || (is_fortran () && integer_onep (bound))))) |
9513 | /* use the default */ | |
9514 | ; | |
141719a8 | 9515 | else |
665f2503 | 9516 | add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0)); |
a3f97cbb JW |
9517 | break; |
9518 | ||
b1ccbc24 | 9519 | case CONVERT_EXPR: |
a3f97cbb | 9520 | case NOP_EXPR: |
b1ccbc24 | 9521 | case NON_LVALUE_EXPR: |
ed239f5a | 9522 | case VIEW_CONVERT_EXPR: |
b1ccbc24 RK |
9523 | add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0)); |
9524 | break; | |
556273e0 | 9525 | |
a3f97cbb JW |
9526 | case SAVE_EXPR: |
9527 | /* If optimization is turned on, the SAVE_EXPRs that describe how to | |
73c68f61 SS |
9528 | access the upper bound values may be bogus. If they refer to a |
9529 | register, they may only describe how to get at these values at the | |
9530 | points in the generated code right after they have just been | |
9531 | computed. Worse yet, in the typical case, the upper bound values | |
9532 | will not even *be* computed in the optimized code (though the | |
9533 | number of elements will), so these SAVE_EXPRs are entirely | |
9534 | bogus. In order to compensate for this fact, we check here to see | |
9535 | if optimization is enabled, and if so, we don't add an attribute | |
9536 | for the (unknown and unknowable) upper bound. This should not | |
9537 | cause too much trouble for existing (stupid?) debuggers because | |
9538 | they have to deal with empty upper bounds location descriptions | |
9539 | anyway in order to be able to deal with incomplete array types. | |
9540 | Of course an intelligent debugger (GDB?) should be able to | |
9541 | comprehend that a missing upper bound specification in an array | |
9542 | type used for a storage class `auto' local array variable | |
9543 | indicates that the upper bound is both unknown (at compile- time) | |
9544 | and unknowable (at run-time) due to optimization. | |
466446b0 JM |
9545 | |
9546 | We assume that a MEM rtx is safe because gcc wouldn't put the | |
9547 | value there unless it was going to be used repeatedly in the | |
9548 | function, i.e. for cleanups. */ | |
1edf43d6 JM |
9549 | if (SAVE_EXPR_RTL (bound) |
9550 | && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)) | |
a3f97cbb | 9551 | { |
b3694847 | 9552 | dw_die_ref ctx = lookup_decl_die (current_function_decl); |
54ba1f0d | 9553 | dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound); |
b3694847 | 9554 | rtx loc = SAVE_EXPR_RTL (bound); |
f5963e61 JL |
9555 | |
9556 | /* If the RTL for the SAVE_EXPR is memory, handle the case where | |
9557 | it references an outer function's frame. */ | |
f5963e61 JL |
9558 | if (GET_CODE (loc) == MEM) |
9559 | { | |
9560 | rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound); | |
9561 | ||
9562 | if (XEXP (loc, 0) != new_addr) | |
c5c76735 | 9563 | loc = gen_rtx_MEM (GET_MODE (loc), new_addr); |
f5963e61 JL |
9564 | } |
9565 | ||
466446b0 JM |
9566 | add_AT_flag (decl_die, DW_AT_artificial, 1); |
9567 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
b9203463 RH |
9568 | add_AT_location_description (decl_die, DW_AT_location, |
9569 | loc_descriptor (loc)); | |
466446b0 | 9570 | add_AT_die_ref (subrange_die, bound_attr, decl_die); |
a3f97cbb | 9571 | } |
71dfc51f RK |
9572 | |
9573 | /* Else leave out the attribute. */ | |
a3f97cbb | 9574 | break; |
3f76745e | 9575 | |
ef76d03b | 9576 | case VAR_DECL: |
d8041cc8 RH |
9577 | case PARM_DECL: |
9578 | { | |
9579 | dw_die_ref decl_die = lookup_decl_die (bound); | |
9580 | ||
9581 | /* ??? Can this happen, or should the variable have been bound | |
9582 | first? Probably it can, since I imagine that we try to create | |
9583 | the types of parameters in the order in which they exist in | |
0b34cf1e | 9584 | the list, and won't have created a forward reference to a |
d8041cc8 RH |
9585 | later parameter. */ |
9586 | if (decl_die != NULL) | |
9587 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
9588 | break; | |
9589 | } | |
ef76d03b | 9590 | |
3f76745e | 9591 | default: |
d8041cc8 RH |
9592 | { |
9593 | /* Otherwise try to create a stack operation procedure to | |
9594 | evaluate the value of the array bound. */ | |
9595 | ||
9596 | dw_die_ref ctx, decl_die; | |
9597 | dw_loc_descr_ref loc; | |
9598 | ||
9599 | loc = loc_descriptor_from_tree (bound, 0); | |
9600 | if (loc == NULL) | |
9601 | break; | |
9602 | ||
e7af1d45 RK |
9603 | if (current_function_decl == 0) |
9604 | ctx = comp_unit_die; | |
9605 | else | |
9606 | ctx = lookup_decl_die (current_function_decl); | |
d8041cc8 | 9607 | |
aea9695c RK |
9608 | /* If we weren't able to find a context, it's most likely the case |
9609 | that we are processing the return type of the function. So | |
9610 | make a SAVE_EXPR to point to it and have the limbo DIE code | |
9611 | find the proper die. The save_expr function doesn't always | |
9612 | make a SAVE_EXPR, so do it ourselves. */ | |
9613 | if (ctx == 0) | |
9614 | bound = build (SAVE_EXPR, TREE_TYPE (bound), bound, | |
9615 | current_function_decl, NULL_TREE); | |
9616 | ||
54ba1f0d | 9617 | decl_die = new_die (DW_TAG_variable, ctx, bound); |
d8041cc8 RH |
9618 | add_AT_flag (decl_die, DW_AT_artificial, 1); |
9619 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
9620 | add_AT_loc (decl_die, DW_AT_location, loc); | |
9621 | ||
9622 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
9623 | break; | |
9624 | } | |
a3f97cbb JW |
9625 | } |
9626 | } | |
9627 | ||
9628 | /* Note that the block of subscript information for an array type also | |
9629 | includes information about the element type of type given array type. */ | |
71dfc51f | 9630 | |
a3f97cbb | 9631 | static void |
7080f735 | 9632 | add_subscript_info (dw_die_ref type_die, tree type) |
a3f97cbb | 9633 | { |
081f5e7e | 9634 | #ifndef MIPS_DEBUGGING_INFO |
b3694847 | 9635 | unsigned dimension_number; |
081f5e7e | 9636 | #endif |
b3694847 SS |
9637 | tree lower, upper; |
9638 | dw_die_ref subrange_die; | |
a3f97cbb | 9639 | |
556273e0 | 9640 | /* The GNU compilers represent multidimensional array types as sequences of |
a3f97cbb JW |
9641 | one dimensional array types whose element types are themselves array |
9642 | types. Here we squish that down, so that each multidimensional array | |
556273e0 | 9643 | type gets only one array_type DIE in the Dwarf debugging info. The draft |
a3f97cbb JW |
9644 | Dwarf specification say that we are allowed to do this kind of |
9645 | compression in C (because there is no difference between an array or | |
556273e0 | 9646 | arrays and a multidimensional array in C) but for other source languages |
a3f97cbb | 9647 | (e.g. Ada) we probably shouldn't do this. */ |
71dfc51f | 9648 | |
a3f97cbb JW |
9649 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
9650 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
9651 | We work around this by disabling this feature. See also | |
9652 | gen_array_type_die. */ | |
9653 | #ifndef MIPS_DEBUGGING_INFO | |
9654 | for (dimension_number = 0; | |
9655 | TREE_CODE (type) == ARRAY_TYPE; | |
9656 | type = TREE_TYPE (type), dimension_number++) | |
a3f97cbb | 9657 | #endif |
2ad9852d | 9658 | { |
b3694847 | 9659 | tree domain = TYPE_DOMAIN (type); |
a3f97cbb JW |
9660 | |
9661 | /* Arrays come in three flavors: Unspecified bounds, fixed bounds, | |
556273e0 | 9662 | and (in GNU C only) variable bounds. Handle all three forms |
73c68f61 | 9663 | here. */ |
54ba1f0d | 9664 | subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL); |
a3f97cbb JW |
9665 | if (domain) |
9666 | { | |
9667 | /* We have an array type with specified bounds. */ | |
9668 | lower = TYPE_MIN_VALUE (domain); | |
9669 | upper = TYPE_MAX_VALUE (domain); | |
9670 | ||
a9d38797 JM |
9671 | /* define the index type. */ |
9672 | if (TREE_TYPE (domain)) | |
ef76d03b JW |
9673 | { |
9674 | /* ??? This is probably an Ada unnamed subrange type. Ignore the | |
9675 | TREE_TYPE field. We can't emit debug info for this | |
9676 | because it is an unnamed integral type. */ | |
9677 | if (TREE_CODE (domain) == INTEGER_TYPE | |
9678 | && TYPE_NAME (domain) == NULL_TREE | |
9679 | && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE | |
9680 | && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE) | |
556273e0 | 9681 | ; |
ef76d03b JW |
9682 | else |
9683 | add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0, | |
9684 | type_die); | |
9685 | } | |
a9d38797 | 9686 | |
e1ee5cdc RH |
9687 | /* ??? If upper is NULL, the array has unspecified length, |
9688 | but it does have a lower bound. This happens with Fortran | |
9689 | dimension arr(N:*) | |
7080f735 | 9690 | Since the debugger is definitely going to need to know N |
e1ee5cdc RH |
9691 | to produce useful results, go ahead and output the lower |
9692 | bound solo, and hope the debugger can cope. */ | |
9693 | ||
141719a8 | 9694 | add_bound_info (subrange_die, DW_AT_lower_bound, lower); |
e1ee5cdc RH |
9695 | if (upper) |
9696 | add_bound_info (subrange_die, DW_AT_upper_bound, upper); | |
a3f97cbb | 9697 | } |
71dfc51f | 9698 | |
2ad9852d RK |
9699 | /* Otherwise we have an array type with an unspecified length. The |
9700 | DWARF-2 spec does not say how to handle this; let's just leave out the | |
9701 | bounds. */ | |
a3f97cbb | 9702 | } |
a3f97cbb JW |
9703 | } |
9704 | ||
9705 | static void | |
7080f735 | 9706 | add_byte_size_attribute (dw_die_ref die, tree tree_node) |
a3f97cbb | 9707 | { |
b3694847 | 9708 | unsigned size; |
a3f97cbb JW |
9709 | |
9710 | switch (TREE_CODE (tree_node)) | |
9711 | { | |
9712 | case ERROR_MARK: | |
9713 | size = 0; | |
9714 | break; | |
9715 | case ENUMERAL_TYPE: | |
9716 | case RECORD_TYPE: | |
9717 | case UNION_TYPE: | |
9718 | case QUAL_UNION_TYPE: | |
9719 | size = int_size_in_bytes (tree_node); | |
9720 | break; | |
9721 | case FIELD_DECL: | |
9722 | /* For a data member of a struct or union, the DW_AT_byte_size is | |
73c68f61 SS |
9723 | generally given as the number of bytes normally allocated for an |
9724 | object of the *declared* type of the member itself. This is true | |
9725 | even for bit-fields. */ | |
a3f97cbb JW |
9726 | size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT; |
9727 | break; | |
9728 | default: | |
9729 | abort (); | |
9730 | } | |
9731 | ||
9732 | /* Note that `size' might be -1 when we get to this point. If it is, that | |
9733 | indicates that the byte size of the entity in question is variable. We | |
9734 | have no good way of expressing this fact in Dwarf at the present time, | |
9735 | so just let the -1 pass on through. */ | |
a3f97cbb JW |
9736 | add_AT_unsigned (die, DW_AT_byte_size, size); |
9737 | } | |
9738 | ||
9739 | /* For a FIELD_DECL node which represents a bit-field, output an attribute | |
9740 | which specifies the distance in bits from the highest order bit of the | |
9741 | "containing object" for the bit-field to the highest order bit of the | |
9742 | bit-field itself. | |
9743 | ||
2ad9852d RK |
9744 | For any given bit-field, the "containing object" is a hypothetical object |
9745 | (of some integral or enum type) within which the given bit-field lives. The | |
9746 | type of this hypothetical "containing object" is always the same as the | |
9747 | declared type of the individual bit-field itself. The determination of the | |
9748 | exact location of the "containing object" for a bit-field is rather | |
9749 | complicated. It's handled by the `field_byte_offset' function (above). | |
a3f97cbb JW |
9750 | |
9751 | Note that it is the size (in bytes) of the hypothetical "containing object" | |
9752 | which will be given in the DW_AT_byte_size attribute for this bit-field. | |
9753 | (See `byte_size_attribute' above). */ | |
71dfc51f RK |
9754 | |
9755 | static inline void | |
7080f735 | 9756 | add_bit_offset_attribute (dw_die_ref die, tree decl) |
a3f97cbb | 9757 | { |
665f2503 RK |
9758 | HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl); |
9759 | tree type = DECL_BIT_FIELD_TYPE (decl); | |
9760 | HOST_WIDE_INT bitpos_int; | |
9761 | HOST_WIDE_INT highest_order_object_bit_offset; | |
9762 | HOST_WIDE_INT highest_order_field_bit_offset; | |
9763 | HOST_WIDE_INT unsigned bit_offset; | |
a3f97cbb | 9764 | |
3a88cbd1 JL |
9765 | /* Must be a field and a bit field. */ |
9766 | if (!type | |
9767 | || TREE_CODE (decl) != FIELD_DECL) | |
9768 | abort (); | |
a3f97cbb JW |
9769 | |
9770 | /* We can't yet handle bit-fields whose offsets are variable, so if we | |
9771 | encounter such things, just return without generating any attribute | |
665f2503 RK |
9772 | whatsoever. Likewise for variable or too large size. */ |
9773 | if (! host_integerp (bit_position (decl), 0) | |
9774 | || ! host_integerp (DECL_SIZE (decl), 1)) | |
71dfc51f RK |
9775 | return; |
9776 | ||
665f2503 | 9777 | bitpos_int = int_bit_position (decl); |
a3f97cbb JW |
9778 | |
9779 | /* Note that the bit offset is always the distance (in bits) from the | |
556273e0 KH |
9780 | highest-order bit of the "containing object" to the highest-order bit of |
9781 | the bit-field itself. Since the "high-order end" of any object or field | |
a3f97cbb JW |
9782 | is different on big-endian and little-endian machines, the computation |
9783 | below must take account of these differences. */ | |
9784 | highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; | |
9785 | highest_order_field_bit_offset = bitpos_int; | |
9786 | ||
71dfc51f | 9787 | if (! BYTES_BIG_ENDIAN) |
a3f97cbb | 9788 | { |
665f2503 | 9789 | highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0); |
a3f97cbb JW |
9790 | highest_order_object_bit_offset += simple_type_size_in_bits (type); |
9791 | } | |
71dfc51f RK |
9792 | |
9793 | bit_offset | |
9794 | = (! BYTES_BIG_ENDIAN | |
9795 | ? highest_order_object_bit_offset - highest_order_field_bit_offset | |
9796 | : highest_order_field_bit_offset - highest_order_object_bit_offset); | |
a3f97cbb JW |
9797 | |
9798 | add_AT_unsigned (die, DW_AT_bit_offset, bit_offset); | |
9799 | } | |
9800 | ||
9801 | /* For a FIELD_DECL node which represents a bit field, output an attribute | |
9802 | which specifies the length in bits of the given field. */ | |
71dfc51f RK |
9803 | |
9804 | static inline void | |
7080f735 | 9805 | add_bit_size_attribute (dw_die_ref die, tree decl) |
a3f97cbb | 9806 | { |
3a88cbd1 JL |
9807 | /* Must be a field and a bit field. */ |
9808 | if (TREE_CODE (decl) != FIELD_DECL | |
9809 | || ! DECL_BIT_FIELD_TYPE (decl)) | |
9810 | abort (); | |
665f2503 RK |
9811 | |
9812 | if (host_integerp (DECL_SIZE (decl), 1)) | |
9813 | add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1)); | |
a3f97cbb JW |
9814 | } |
9815 | ||
88dad228 | 9816 | /* If the compiled language is ANSI C, then add a 'prototyped' |
a3f97cbb | 9817 | attribute, if arg types are given for the parameters of a function. */ |
71dfc51f RK |
9818 | |
9819 | static inline void | |
7080f735 | 9820 | add_prototyped_attribute (dw_die_ref die, tree func_type) |
a3f97cbb | 9821 | { |
88dad228 JM |
9822 | if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89 |
9823 | && TYPE_ARG_TYPES (func_type) != NULL) | |
9824 | add_AT_flag (die, DW_AT_prototyped, 1); | |
a3f97cbb JW |
9825 | } |
9826 | ||
a3f97cbb JW |
9827 | /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found |
9828 | by looking in either the type declaration or object declaration | |
9829 | equate table. */ | |
71dfc51f RK |
9830 | |
9831 | static inline void | |
7080f735 | 9832 | add_abstract_origin_attribute (dw_die_ref die, tree origin) |
a3f97cbb JW |
9833 | { |
9834 | dw_die_ref origin_die = NULL; | |
bbc6ae08 | 9835 | |
d10b8e05 | 9836 | if (TREE_CODE (origin) != FUNCTION_DECL) |
e40a1c67 JM |
9837 | { |
9838 | /* We may have gotten separated from the block for the inlined | |
9839 | function, if we're in an exception handler or some such; make | |
9840 | sure that the abstract function has been written out. | |
9841 | ||
73c68f61 | 9842 | Doing this for nested functions is wrong, however; functions are |
e40a1c67 | 9843 | distinct units, and our context might not even be inline. */ |
fb13d4d0 | 9844 | tree fn = origin; |
2ad9852d | 9845 | |
fb13d4d0 JM |
9846 | if (TYPE_P (fn)) |
9847 | fn = TYPE_STUB_DECL (fn); | |
2ad9852d | 9848 | |
fb13d4d0 | 9849 | fn = decl_function_context (fn); |
e40a1c67 | 9850 | if (fn) |
1edf43d6 | 9851 | dwarf2out_abstract_function (fn); |
e40a1c67 | 9852 | } |
44db1d9c | 9853 | |
2f939d94 | 9854 | if (DECL_P (origin)) |
71dfc51f | 9855 | origin_die = lookup_decl_die (origin); |
2f939d94 | 9856 | else if (TYPE_P (origin)) |
71dfc51f RK |
9857 | origin_die = lookup_type_die (origin); |
9858 | ||
bbc6ae08 | 9859 | if (origin_die == NULL) |
1ae8994f | 9860 | abort (); |
556273e0 | 9861 | |
a3f97cbb JW |
9862 | add_AT_die_ref (die, DW_AT_abstract_origin, origin_die); |
9863 | } | |
9864 | ||
bdb669cb JM |
9865 | /* We do not currently support the pure_virtual attribute. */ |
9866 | ||
71dfc51f | 9867 | static inline void |
7080f735 | 9868 | add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl) |
a3f97cbb | 9869 | { |
a94dbf2c | 9870 | if (DECL_VINDEX (func_decl)) |
a3f97cbb | 9871 | { |
bdb669cb | 9872 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); |
665f2503 RK |
9873 | |
9874 | if (host_integerp (DECL_VINDEX (func_decl), 0)) | |
9875 | add_AT_loc (die, DW_AT_vtable_elem_location, | |
9876 | new_loc_descr (DW_OP_constu, | |
9877 | tree_low_cst (DECL_VINDEX (func_decl), 0), | |
9878 | 0)); | |
71dfc51f | 9879 | |
a94dbf2c JM |
9880 | /* GNU extension: Record what type this method came from originally. */ |
9881 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
9882 | add_AT_die_ref (die, DW_AT_containing_type, | |
9883 | lookup_type_die (DECL_CONTEXT (func_decl))); | |
a3f97cbb JW |
9884 | } |
9885 | } | |
9886 | \f | |
b2932ae5 | 9887 | /* Add source coordinate attributes for the given decl. */ |
71dfc51f | 9888 | |
b2932ae5 | 9889 | static void |
7080f735 | 9890 | add_src_coords_attributes (dw_die_ref die, tree decl) |
b2932ae5 | 9891 | { |
b3694847 | 9892 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
71dfc51f | 9893 | |
b2932ae5 JM |
9894 | add_AT_unsigned (die, DW_AT_decl_file, file_index); |
9895 | add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
9896 | } | |
9897 | ||
b20b352b | 9898 | /* Add a DW_AT_name attribute and source coordinate attribute for the |
a3f97cbb | 9899 | given decl, but only if it actually has a name. */ |
71dfc51f | 9900 | |
a3f97cbb | 9901 | static void |
7080f735 | 9902 | add_name_and_src_coords_attributes (dw_die_ref die, tree decl) |
a3f97cbb | 9903 | { |
b3694847 | 9904 | tree decl_name; |
71dfc51f | 9905 | |
556273e0 | 9906 | decl_name = DECL_NAME (decl); |
71dfc51f | 9907 | if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL) |
a3f97cbb | 9908 | { |
a1d7ffe3 | 9909 | add_name_attribute (die, dwarf2_name (decl, 0)); |
a96c67ec JM |
9910 | if (! DECL_ARTIFICIAL (decl)) |
9911 | add_src_coords_attributes (die, decl); | |
e689ae67 | 9912 | |
a1d7ffe3 | 9913 | if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) |
bc808e0b | 9914 | && TREE_PUBLIC (decl) |
5daf7c0a JM |
9915 | && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) |
9916 | && !DECL_ABSTRACT (decl)) | |
a1d7ffe3 JM |
9917 | add_AT_string (die, DW_AT_MIPS_linkage_name, |
9918 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
a3f97cbb | 9919 | } |
7a0c8d71 DR |
9920 | |
9921 | #ifdef VMS_DEBUGGING_INFO | |
7a0c8d71 DR |
9922 | /* Get the function's name, as described by its RTL. This may be different |
9923 | from the DECL_NAME name used in the source file. */ | |
9924 | if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl)) | |
c470afad RK |
9925 | { |
9926 | add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address, | |
9927 | XEXP (DECL_RTL (decl), 0)); | |
9928 | VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0)); | |
9929 | } | |
7a0c8d71 | 9930 | #endif |
a3f97cbb JW |
9931 | } |
9932 | ||
556273e0 | 9933 | /* Push a new declaration scope. */ |
71dfc51f | 9934 | |
a3f97cbb | 9935 | static void |
7080f735 | 9936 | push_decl_scope (tree scope) |
a3f97cbb | 9937 | { |
244a4af0 | 9938 | VARRAY_PUSH_TREE (decl_scope_table, scope); |
a3f97cbb JW |
9939 | } |
9940 | ||
777ad4c2 | 9941 | /* Pop a declaration scope. */ |
2ad9852d | 9942 | |
777ad4c2 | 9943 | static inline void |
7080f735 | 9944 | pop_decl_scope (void) |
777ad4c2 | 9945 | { |
244a4af0 | 9946 | if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0) |
777ad4c2 | 9947 | abort (); |
2ad9852d | 9948 | |
244a4af0 | 9949 | VARRAY_POP (decl_scope_table); |
777ad4c2 JM |
9950 | } |
9951 | ||
9952 | /* Return the DIE for the scope that immediately contains this type. | |
9953 | Non-named types get global scope. Named types nested in other | |
9954 | types get their containing scope if it's open, or global scope | |
9955 | otherwise. All other types (i.e. function-local named types) get | |
9956 | the current active scope. */ | |
71dfc51f | 9957 | |
a3f97cbb | 9958 | static dw_die_ref |
7080f735 | 9959 | scope_die_for (tree t, dw_die_ref context_die) |
a3f97cbb | 9960 | { |
b3694847 SS |
9961 | dw_die_ref scope_die = NULL; |
9962 | tree containing_scope; | |
9963 | int i; | |
a3f97cbb | 9964 | |
777ad4c2 JM |
9965 | /* Non-types always go in the current scope. */ |
9966 | if (! TYPE_P (t)) | |
9967 | abort (); | |
9968 | ||
9969 | containing_scope = TYPE_CONTEXT (t); | |
ab72d377 | 9970 | |
2addbe1d JM |
9971 | /* Ignore namespaces for the moment. */ |
9972 | if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL) | |
9973 | containing_scope = NULL_TREE; | |
9974 | ||
5f2f160c JM |
9975 | /* Ignore function type "scopes" from the C frontend. They mean that |
9976 | a tagged type is local to a parmlist of a function declarator, but | |
9977 | that isn't useful to DWARF. */ | |
9978 | if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE) | |
9979 | containing_scope = NULL_TREE; | |
9980 | ||
71dfc51f RK |
9981 | if (containing_scope == NULL_TREE) |
9982 | scope_die = comp_unit_die; | |
777ad4c2 | 9983 | else if (TYPE_P (containing_scope)) |
348bb3c7 | 9984 | { |
777ad4c2 JM |
9985 | /* For types, we can just look up the appropriate DIE. But |
9986 | first we check to see if we're in the middle of emitting it | |
9987 | so we know where the new DIE should go. */ | |
244a4af0 TF |
9988 | for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i) |
9989 | if (VARRAY_TREE (decl_scope_table, i) == containing_scope) | |
348bb3c7 JM |
9990 | break; |
9991 | ||
9992 | if (i < 0) | |
9993 | { | |
348bb3c7 JM |
9994 | if (debug_info_level > DINFO_LEVEL_TERSE |
9995 | && !TREE_ASM_WRITTEN (containing_scope)) | |
9996 | abort (); | |
9997 | ||
9998 | /* If none of the current dies are suitable, we get file scope. */ | |
9999 | scope_die = comp_unit_die; | |
10000 | } | |
10001 | else | |
777ad4c2 | 10002 | scope_die = lookup_type_die (containing_scope); |
348bb3c7 | 10003 | } |
a3f97cbb | 10004 | else |
777ad4c2 | 10005 | scope_die = context_die; |
71dfc51f | 10006 | |
a3f97cbb JW |
10007 | return scope_die; |
10008 | } | |
10009 | ||
2ad9852d | 10010 | /* Returns nonzero if CONTEXT_DIE is internal to a function. */ |
777ad4c2 JM |
10011 | |
10012 | static inline int | |
7080f735 | 10013 | local_scope_p (dw_die_ref context_die) |
a3f97cbb | 10014 | { |
777ad4c2 JM |
10015 | for (; context_die; context_die = context_die->die_parent) |
10016 | if (context_die->die_tag == DW_TAG_inlined_subroutine | |
10017 | || context_die->die_tag == DW_TAG_subprogram) | |
10018 | return 1; | |
2ad9852d | 10019 | |
777ad4c2 | 10020 | return 0; |
a3f97cbb JW |
10021 | } |
10022 | ||
2ad9852d | 10023 | /* Returns nonzero if CONTEXT_DIE is a class. */ |
9765e357 JM |
10024 | |
10025 | static inline int | |
7080f735 | 10026 | class_scope_p (dw_die_ref context_die) |
9765e357 JM |
10027 | { |
10028 | return (context_die | |
10029 | && (context_die->die_tag == DW_TAG_structure_type | |
10030 | || context_die->die_tag == DW_TAG_union_type)); | |
10031 | } | |
10032 | ||
a3f97cbb JW |
10033 | /* Many forms of DIEs require a "type description" attribute. This |
10034 | routine locates the proper "type descriptor" die for the type given | |
b20b352b | 10035 | by 'type', and adds a DW_AT_type attribute below the given die. */ |
71dfc51f | 10036 | |
a3f97cbb | 10037 | static void |
7080f735 AJ |
10038 | add_type_attribute (dw_die_ref object_die, tree type, int decl_const, |
10039 | int decl_volatile, dw_die_ref context_die) | |
a3f97cbb | 10040 | { |
b3694847 SS |
10041 | enum tree_code code = TREE_CODE (type); |
10042 | dw_die_ref type_die = NULL; | |
a3f97cbb | 10043 | |
ef76d03b JW |
10044 | /* ??? If this type is an unnamed subrange type of an integral or |
10045 | floating-point type, use the inner type. This is because we have no | |
10046 | support for unnamed types in base_type_die. This can happen if this is | |
10047 | an Ada subrange type. Correct solution is emit a subrange type die. */ | |
b1ccbc24 RK |
10048 | if ((code == INTEGER_TYPE || code == REAL_TYPE) |
10049 | && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0) | |
10050 | type = TREE_TYPE (type), code = TREE_CODE (type); | |
10051 | ||
2ad9852d RK |
10052 | if (code == ERROR_MARK |
10053 | /* Handle a special case. For functions whose return type is void, we | |
10054 | generate *no* type attribute. (Note that no object may have type | |
10055 | `void', so this only applies to function return types). */ | |
10056 | || code == VOID_TYPE) | |
b1ccbc24 | 10057 | return; |
a3f97cbb | 10058 | |
a3f97cbb JW |
10059 | type_die = modified_type_die (type, |
10060 | decl_const || TYPE_READONLY (type), | |
10061 | decl_volatile || TYPE_VOLATILE (type), | |
ab72d377 | 10062 | context_die); |
2ad9852d | 10063 | |
a3f97cbb | 10064 | if (type_die != NULL) |
71dfc51f | 10065 | add_AT_die_ref (object_die, DW_AT_type, type_die); |
a3f97cbb JW |
10066 | } |
10067 | ||
10068 | /* Given a tree pointer to a struct, class, union, or enum type node, return | |
10069 | a pointer to the (string) tag name for the given type, or zero if the type | |
10070 | was declared without a tag. */ | |
71dfc51f | 10071 | |
d3e3972c | 10072 | static const char * |
7080f735 | 10073 | type_tag (tree type) |
a3f97cbb | 10074 | { |
b3694847 | 10075 | const char *name = 0; |
a3f97cbb JW |
10076 | |
10077 | if (TYPE_NAME (type) != 0) | |
10078 | { | |
b3694847 | 10079 | tree t = 0; |
a3f97cbb JW |
10080 | |
10081 | /* Find the IDENTIFIER_NODE for the type name. */ | |
10082 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
10083 | t = TYPE_NAME (type); | |
bdb669cb | 10084 | |
556273e0 | 10085 | /* The g++ front end makes the TYPE_NAME of *each* tagged type point to |
73c68f61 SS |
10086 | a TYPE_DECL node, regardless of whether or not a `typedef' was |
10087 | involved. */ | |
a94dbf2c JM |
10088 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
10089 | && ! DECL_IGNORED_P (TYPE_NAME (type))) | |
a3f97cbb | 10090 | t = DECL_NAME (TYPE_NAME (type)); |
bdb669cb | 10091 | |
a3f97cbb JW |
10092 | /* Now get the name as a string, or invent one. */ |
10093 | if (t != 0) | |
a94dbf2c | 10094 | name = IDENTIFIER_POINTER (t); |
a3f97cbb | 10095 | } |
71dfc51f | 10096 | |
a3f97cbb JW |
10097 | return (name == 0 || *name == '\0') ? 0 : name; |
10098 | } | |
10099 | ||
10100 | /* Return the type associated with a data member, make a special check | |
10101 | for bit field types. */ | |
71dfc51f RK |
10102 | |
10103 | static inline tree | |
7080f735 | 10104 | member_declared_type (tree member) |
a3f97cbb | 10105 | { |
71dfc51f | 10106 | return (DECL_BIT_FIELD_TYPE (member) |
2ad9852d | 10107 | ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member)); |
a3f97cbb JW |
10108 | } |
10109 | ||
d291dd49 | 10110 | /* Get the decl's label, as described by its RTL. This may be different |
a3f97cbb | 10111 | from the DECL_NAME name used in the source file. */ |
71dfc51f | 10112 | |
487a6e06 | 10113 | #if 0 |
d3e3972c | 10114 | static const char * |
7080f735 | 10115 | decl_start_label (tree decl) |
a3f97cbb JW |
10116 | { |
10117 | rtx x; | |
d3e3972c | 10118 | const char *fnname; |
2ad9852d | 10119 | |
a3f97cbb JW |
10120 | x = DECL_RTL (decl); |
10121 | if (GET_CODE (x) != MEM) | |
71dfc51f RK |
10122 | abort (); |
10123 | ||
a3f97cbb JW |
10124 | x = XEXP (x, 0); |
10125 | if (GET_CODE (x) != SYMBOL_REF) | |
71dfc51f RK |
10126 | abort (); |
10127 | ||
a3f97cbb JW |
10128 | fnname = XSTR (x, 0); |
10129 | return fnname; | |
10130 | } | |
487a6e06 | 10131 | #endif |
a3f97cbb | 10132 | \f |
956d6950 | 10133 | /* These routines generate the internal representation of the DIE's for |
a3f97cbb | 10134 | the compilation unit. Debugging information is collected by walking |
88dad228 | 10135 | the declaration trees passed in from dwarf2out_decl(). */ |
a3f97cbb JW |
10136 | |
10137 | static void | |
7080f735 | 10138 | gen_array_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 10139 | { |
b3694847 SS |
10140 | dw_die_ref scope_die = scope_die_for (type, context_die); |
10141 | dw_die_ref array_die; | |
10142 | tree element_type; | |
bdb669cb | 10143 | |
a9d38797 JM |
10144 | /* ??? The SGI dwarf reader fails for array of array of enum types unless |
10145 | the inner array type comes before the outer array type. Thus we must | |
10146 | call gen_type_die before we call new_die. See below also. */ | |
10147 | #ifdef MIPS_DEBUGGING_INFO | |
10148 | gen_type_die (TREE_TYPE (type), context_die); | |
10149 | #endif | |
10150 | ||
54ba1f0d | 10151 | array_die = new_die (DW_TAG_array_type, scope_die, type); |
84f0ace0 JM |
10152 | add_name_attribute (array_die, type_tag (type)); |
10153 | equate_type_number_to_die (type, array_die); | |
10154 | ||
10155 | if (TREE_CODE (type) == VECTOR_TYPE) | |
10156 | { | |
10157 | /* The frontend feeds us a representation for the vector as a struct | |
10158 | containing an array. Pull out the array type. */ | |
10159 | type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type))); | |
10160 | add_AT_flag (array_die, DW_AT_GNU_vector, 1); | |
10161 | } | |
a9d38797 | 10162 | |
a3f97cbb JW |
10163 | #if 0 |
10164 | /* We default the array ordering. SDB will probably do | |
10165 | the right things even if DW_AT_ordering is not present. It's not even | |
10166 | an issue until we start to get into multidimensional arrays anyway. If | |
10167 | SDB is ever caught doing the Wrong Thing for multi-dimensional arrays, | |
10168 | then we'll have to put the DW_AT_ordering attribute back in. (But if | |
10169 | and when we find out that we need to put these in, we will only do so | |
10170 | for multidimensional arrays. */ | |
10171 | add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major); | |
10172 | #endif | |
10173 | ||
a9d38797 | 10174 | #ifdef MIPS_DEBUGGING_INFO |
4edb7b60 JM |
10175 | /* The SGI compilers handle arrays of unknown bound by setting |
10176 | AT_declaration and not emitting any subrange DIEs. */ | |
a9d38797 JM |
10177 | if (! TYPE_DOMAIN (type)) |
10178 | add_AT_unsigned (array_die, DW_AT_declaration, 1); | |
10179 | else | |
10180 | #endif | |
10181 | add_subscript_info (array_die, type); | |
a3f97cbb | 10182 | |
a3f97cbb JW |
10183 | /* Add representation of the type of the elements of this array type. */ |
10184 | element_type = TREE_TYPE (type); | |
71dfc51f | 10185 | |
a3f97cbb JW |
10186 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
10187 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
10188 | We work around this by disabling this feature. See also | |
10189 | add_subscript_info. */ | |
10190 | #ifndef MIPS_DEBUGGING_INFO | |
71dfc51f RK |
10191 | while (TREE_CODE (element_type) == ARRAY_TYPE) |
10192 | element_type = TREE_TYPE (element_type); | |
10193 | ||
a3f97cbb | 10194 | gen_type_die (element_type, context_die); |
a9d38797 | 10195 | #endif |
a3f97cbb JW |
10196 | |
10197 | add_type_attribute (array_die, element_type, 0, 0, context_die); | |
10198 | } | |
10199 | ||
10200 | static void | |
7080f735 | 10201 | gen_set_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 10202 | { |
b3694847 | 10203 | dw_die_ref type_die |
54ba1f0d | 10204 | = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type); |
71dfc51f | 10205 | |
a3f97cbb | 10206 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
10207 | add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die); |
10208 | } | |
10209 | ||
d6f4ec51 | 10210 | #if 0 |
a3f97cbb | 10211 | static void |
7080f735 | 10212 | gen_entry_point_die (tree decl, dw_die_ref context_die) |
a3f97cbb | 10213 | { |
b3694847 | 10214 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 10215 | dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl); |
2ad9852d | 10216 | |
a3f97cbb | 10217 | if (origin != NULL) |
71dfc51f | 10218 | add_abstract_origin_attribute (decl_die, origin); |
a3f97cbb JW |
10219 | else |
10220 | { | |
10221 | add_name_and_src_coords_attributes (decl_die, decl); | |
a3f97cbb JW |
10222 | add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)), |
10223 | 0, 0, context_die); | |
10224 | } | |
71dfc51f | 10225 | |
a3f97cbb | 10226 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 10227 | equate_decl_number_to_die (decl, decl_die); |
a3f97cbb | 10228 | else |
71dfc51f | 10229 | add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl)); |
a3f97cbb | 10230 | } |
d6f4ec51 | 10231 | #endif |
a3f97cbb | 10232 | |
8a8c3656 JM |
10233 | /* Walk through the list of incomplete types again, trying once more to |
10234 | emit full debugging info for them. */ | |
10235 | ||
10236 | static void | |
7080f735 | 10237 | retry_incomplete_types (void) |
8a8c3656 | 10238 | { |
244a4af0 | 10239 | int i; |
2ad9852d | 10240 | |
244a4af0 | 10241 | for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--) |
2ad9852d | 10242 | gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die); |
8a8c3656 JM |
10243 | } |
10244 | ||
a3f97cbb | 10245 | /* Generate a DIE to represent an inlined instance of an enumeration type. */ |
71dfc51f | 10246 | |
a3f97cbb | 10247 | static void |
7080f735 | 10248 | gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 10249 | { |
54ba1f0d | 10250 | dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type); |
2ad9852d | 10251 | |
bbc6ae08 NC |
10252 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
10253 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
10254 | add_abstract_origin_attribute (type_die, type); |
10255 | } | |
10256 | ||
10257 | /* Generate a DIE to represent an inlined instance of a structure type. */ | |
71dfc51f | 10258 | |
a3f97cbb | 10259 | static void |
7080f735 | 10260 | gen_inlined_structure_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 10261 | { |
54ba1f0d | 10262 | dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type); |
777ad4c2 | 10263 | |
bbc6ae08 NC |
10264 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
10265 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
10266 | add_abstract_origin_attribute (type_die, type); |
10267 | } | |
10268 | ||
10269 | /* Generate a DIE to represent an inlined instance of a union type. */ | |
71dfc51f | 10270 | |
a3f97cbb | 10271 | static void |
7080f735 | 10272 | gen_inlined_union_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 10273 | { |
54ba1f0d | 10274 | dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type); |
777ad4c2 | 10275 | |
bbc6ae08 NC |
10276 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
10277 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
10278 | add_abstract_origin_attribute (type_die, type); |
10279 | } | |
10280 | ||
10281 | /* Generate a DIE to represent an enumeration type. Note that these DIEs | |
10282 | include all of the information about the enumeration values also. Each | |
273dbe67 JM |
10283 | enumerated type name/value is listed as a child of the enumerated type |
10284 | DIE. */ | |
71dfc51f | 10285 | |
a3f97cbb | 10286 | static void |
7080f735 | 10287 | gen_enumeration_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 10288 | { |
b3694847 | 10289 | dw_die_ref type_die = lookup_type_die (type); |
273dbe67 | 10290 | |
a3f97cbb JW |
10291 | if (type_die == NULL) |
10292 | { | |
10293 | type_die = new_die (DW_TAG_enumeration_type, | |
54ba1f0d | 10294 | scope_die_for (type, context_die), type); |
a3f97cbb JW |
10295 | equate_type_number_to_die (type, type_die); |
10296 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 10297 | } |
273dbe67 JM |
10298 | else if (! TYPE_SIZE (type)) |
10299 | return; | |
10300 | else | |
10301 | remove_AT (type_die, DW_AT_declaration); | |
10302 | ||
10303 | /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the | |
10304 | given enum type is incomplete, do not generate the DW_AT_byte_size | |
10305 | attribute or the DW_AT_element_list attribute. */ | |
10306 | if (TYPE_SIZE (type)) | |
a3f97cbb | 10307 | { |
b3694847 | 10308 | tree link; |
71dfc51f | 10309 | |
a082c85a | 10310 | TREE_ASM_WRITTEN (type) = 1; |
273dbe67 | 10311 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 10312 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 10313 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 10314 | |
ef76d03b JW |
10315 | /* If the first reference to this type was as the return type of an |
10316 | inline function, then it may not have a parent. Fix this now. */ | |
10317 | if (type_die->die_parent == NULL) | |
10318 | add_child_die (scope_die_for (type, context_die), type_die); | |
10319 | ||
273dbe67 JM |
10320 | for (link = TYPE_FIELDS (type); |
10321 | link != NULL; link = TREE_CHAIN (link)) | |
a3f97cbb | 10322 | { |
54ba1f0d | 10323 | dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link); |
71dfc51f | 10324 | |
273dbe67 JM |
10325 | add_name_attribute (enum_die, |
10326 | IDENTIFIER_POINTER (TREE_PURPOSE (link))); | |
665f2503 RK |
10327 | |
10328 | if (host_integerp (TREE_VALUE (link), 0)) | |
fc9e8a14 JJ |
10329 | { |
10330 | if (tree_int_cst_sgn (TREE_VALUE (link)) < 0) | |
10331 | add_AT_int (enum_die, DW_AT_const_value, | |
10332 | tree_low_cst (TREE_VALUE (link), 0)); | |
10333 | else | |
10334 | add_AT_unsigned (enum_die, DW_AT_const_value, | |
10335 | tree_low_cst (TREE_VALUE (link), 0)); | |
10336 | } | |
a3f97cbb JW |
10337 | } |
10338 | } | |
273dbe67 JM |
10339 | else |
10340 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a3f97cbb JW |
10341 | } |
10342 | ||
a3f97cbb JW |
10343 | /* Generate a DIE to represent either a real live formal parameter decl or to |
10344 | represent just the type of some formal parameter position in some function | |
10345 | type. | |
71dfc51f | 10346 | |
a3f97cbb JW |
10347 | Note that this routine is a bit unusual because its argument may be a |
10348 | ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which | |
10349 | represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE | |
10350 | node. If it's the former then this function is being called to output a | |
10351 | DIE to represent a formal parameter object (or some inlining thereof). If | |
10352 | it's the latter, then this function is only being called to output a | |
10353 | DW_TAG_formal_parameter DIE to stand as a placeholder for some formal | |
10354 | argument type of some subprogram type. */ | |
71dfc51f | 10355 | |
a94dbf2c | 10356 | static dw_die_ref |
7080f735 | 10357 | gen_formal_parameter_die (tree node, dw_die_ref context_die) |
a3f97cbb | 10358 | { |
b3694847 | 10359 | dw_die_ref parm_die |
54ba1f0d | 10360 | = new_die (DW_TAG_formal_parameter, context_die, node); |
b3694847 | 10361 | tree origin; |
71dfc51f | 10362 | |
a3f97cbb JW |
10363 | switch (TREE_CODE_CLASS (TREE_CODE (node))) |
10364 | { | |
a3f97cbb JW |
10365 | case 'd': |
10366 | origin = decl_ultimate_origin (node); | |
10367 | if (origin != NULL) | |
a94dbf2c | 10368 | add_abstract_origin_attribute (parm_die, origin); |
a3f97cbb JW |
10369 | else |
10370 | { | |
10371 | add_name_and_src_coords_attributes (parm_die, node); | |
10372 | add_type_attribute (parm_die, TREE_TYPE (node), | |
10373 | TREE_READONLY (node), | |
10374 | TREE_THIS_VOLATILE (node), | |
10375 | context_die); | |
bdb669cb JM |
10376 | if (DECL_ARTIFICIAL (node)) |
10377 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb | 10378 | } |
71dfc51f | 10379 | |
141719a8 JM |
10380 | equate_decl_number_to_die (node, parm_die); |
10381 | if (! DECL_ABSTRACT (node)) | |
a94dbf2c | 10382 | add_location_or_const_value_attribute (parm_die, node); |
71dfc51f | 10383 | |
a3f97cbb JW |
10384 | break; |
10385 | ||
a3f97cbb | 10386 | case 't': |
71dfc51f | 10387 | /* We were called with some kind of a ..._TYPE node. */ |
a3f97cbb JW |
10388 | add_type_attribute (parm_die, node, 0, 0, context_die); |
10389 | break; | |
10390 | ||
a3f97cbb JW |
10391 | default: |
10392 | abort (); | |
10393 | } | |
71dfc51f | 10394 | |
a94dbf2c | 10395 | return parm_die; |
a3f97cbb JW |
10396 | } |
10397 | ||
10398 | /* Generate a special type of DIE used as a stand-in for a trailing ellipsis | |
10399 | at the end of an (ANSI prototyped) formal parameters list. */ | |
71dfc51f | 10400 | |
a3f97cbb | 10401 | static void |
7080f735 | 10402 | gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die) |
a3f97cbb | 10403 | { |
54ba1f0d | 10404 | new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type); |
a3f97cbb JW |
10405 | } |
10406 | ||
10407 | /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a | |
10408 | DW_TAG_unspecified_parameters DIE) to represent the types of the formal | |
10409 | parameters as specified in some function type specification (except for | |
1cfdcc15 | 10410 | those which appear as part of a function *definition*). */ |
71dfc51f | 10411 | |
a3f97cbb | 10412 | static void |
7080f735 | 10413 | gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die) |
a3f97cbb | 10414 | { |
b3694847 SS |
10415 | tree link; |
10416 | tree formal_type = NULL; | |
10417 | tree first_parm_type; | |
5daf7c0a | 10418 | tree arg; |
a3f97cbb | 10419 | |
5daf7c0a JM |
10420 | if (TREE_CODE (function_or_method_type) == FUNCTION_DECL) |
10421 | { | |
10422 | arg = DECL_ARGUMENTS (function_or_method_type); | |
10423 | function_or_method_type = TREE_TYPE (function_or_method_type); | |
10424 | } | |
10425 | else | |
10426 | arg = NULL_TREE; | |
c26fbbca | 10427 | |
5daf7c0a | 10428 | first_parm_type = TYPE_ARG_TYPES (function_or_method_type); |
a3f97cbb | 10429 | |
556273e0 | 10430 | /* Make our first pass over the list of formal parameter types and output a |
a3f97cbb | 10431 | DW_TAG_formal_parameter DIE for each one. */ |
5daf7c0a | 10432 | for (link = first_parm_type; link; ) |
a3f97cbb | 10433 | { |
b3694847 | 10434 | dw_die_ref parm_die; |
556273e0 | 10435 | |
a3f97cbb JW |
10436 | formal_type = TREE_VALUE (link); |
10437 | if (formal_type == void_type_node) | |
10438 | break; | |
10439 | ||
10440 | /* Output a (nameless) DIE to represent the formal parameter itself. */ | |
a94dbf2c | 10441 | parm_die = gen_formal_parameter_die (formal_type, context_die); |
5daf7c0a JM |
10442 | if ((TREE_CODE (function_or_method_type) == METHOD_TYPE |
10443 | && link == first_parm_type) | |
10444 | || (arg && DECL_ARTIFICIAL (arg))) | |
a94dbf2c | 10445 | add_AT_flag (parm_die, DW_AT_artificial, 1); |
5daf7c0a JM |
10446 | |
10447 | link = TREE_CHAIN (link); | |
10448 | if (arg) | |
10449 | arg = TREE_CHAIN (arg); | |
a3f97cbb JW |
10450 | } |
10451 | ||
10452 | /* If this function type has an ellipsis, add a | |
10453 | DW_TAG_unspecified_parameters DIE to the end of the parameter list. */ | |
10454 | if (formal_type != void_type_node) | |
10455 | gen_unspecified_parameters_die (function_or_method_type, context_die); | |
10456 | ||
556273e0 | 10457 | /* Make our second (and final) pass over the list of formal parameter types |
a3f97cbb JW |
10458 | and output DIEs to represent those types (as necessary). */ |
10459 | for (link = TYPE_ARG_TYPES (function_or_method_type); | |
2ad9852d | 10460 | link && TREE_VALUE (link); |
a3f97cbb | 10461 | link = TREE_CHAIN (link)) |
2ad9852d | 10462 | gen_type_die (TREE_VALUE (link), context_die); |
a3f97cbb JW |
10463 | } |
10464 | ||
10a11b75 JM |
10465 | /* We want to generate the DIE for TYPE so that we can generate the |
10466 | die for MEMBER, which has been defined; we will need to refer back | |
10467 | to the member declaration nested within TYPE. If we're trying to | |
10468 | generate minimal debug info for TYPE, processing TYPE won't do the | |
10469 | trick; we need to attach the member declaration by hand. */ | |
10470 | ||
10471 | static void | |
7080f735 | 10472 | gen_type_die_for_member (tree type, tree member, dw_die_ref context_die) |
10a11b75 JM |
10473 | { |
10474 | gen_type_die (type, context_die); | |
10475 | ||
10476 | /* If we're trying to avoid duplicate debug info, we may not have | |
10477 | emitted the member decl for this function. Emit it now. */ | |
10478 | if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)) | |
10479 | && ! lookup_decl_die (member)) | |
10480 | { | |
10481 | if (decl_ultimate_origin (member)) | |
10482 | abort (); | |
10483 | ||
10484 | push_decl_scope (type); | |
10485 | if (TREE_CODE (member) == FUNCTION_DECL) | |
10486 | gen_subprogram_die (member, lookup_type_die (type)); | |
10487 | else | |
10488 | gen_variable_die (member, lookup_type_die (type)); | |
2ad9852d | 10489 | |
10a11b75 JM |
10490 | pop_decl_scope (); |
10491 | } | |
10492 | } | |
10493 | ||
2ad9852d RK |
10494 | /* Generate the DWARF2 info for the "abstract" instance of a function which we |
10495 | may later generate inlined and/or out-of-line instances of. */ | |
10a11b75 | 10496 | |
e1772ac0 | 10497 | static void |
7080f735 | 10498 | dwarf2out_abstract_function (tree decl) |
10a11b75 | 10499 | { |
b3694847 | 10500 | dw_die_ref old_die; |
777ad4c2 | 10501 | tree save_fn; |
5daf7c0a JM |
10502 | tree context; |
10503 | int was_abstract = DECL_ABSTRACT (decl); | |
10504 | ||
10505 | /* Make sure we have the actual abstract inline, not a clone. */ | |
10506 | decl = DECL_ORIGIN (decl); | |
10a11b75 | 10507 | |
c26fbbca | 10508 | old_die = lookup_decl_die (decl); |
10a11b75 JM |
10509 | if (old_die && get_AT_unsigned (old_die, DW_AT_inline)) |
10510 | /* We've already generated the abstract instance. */ | |
10511 | return; | |
10512 | ||
5daf7c0a JM |
10513 | /* Be sure we've emitted the in-class declaration DIE (if any) first, so |
10514 | we don't get confused by DECL_ABSTRACT. */ | |
8458e954 JS |
10515 | if (debug_info_level > DINFO_LEVEL_TERSE) |
10516 | { | |
10517 | context = decl_class_context (decl); | |
10518 | if (context) | |
10519 | gen_type_die_for_member | |
10520 | (context, decl, decl_function_context (decl) ? NULL : comp_unit_die); | |
10521 | } | |
c26fbbca | 10522 | |
5daf7c0a | 10523 | /* Pretend we've just finished compiling this function. */ |
777ad4c2 JM |
10524 | save_fn = current_function_decl; |
10525 | current_function_decl = decl; | |
10526 | ||
10a11b75 JM |
10527 | set_decl_abstract_flags (decl, 1); |
10528 | dwarf2out_decl (decl); | |
5daf7c0a JM |
10529 | if (! was_abstract) |
10530 | set_decl_abstract_flags (decl, 0); | |
777ad4c2 JM |
10531 | |
10532 | current_function_decl = save_fn; | |
10a11b75 JM |
10533 | } |
10534 | ||
a3f97cbb JW |
10535 | /* Generate a DIE to represent a declared function (either file-scope or |
10536 | block-local). */ | |
71dfc51f | 10537 | |
a3f97cbb | 10538 | static void |
7080f735 | 10539 | gen_subprogram_die (tree decl, dw_die_ref context_die) |
a3f97cbb JW |
10540 | { |
10541 | char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 SS |
10542 | tree origin = decl_ultimate_origin (decl); |
10543 | dw_die_ref subr_die; | |
10544 | rtx fp_reg; | |
10545 | tree fn_arg_types; | |
10546 | tree outer_scope; | |
10547 | dw_die_ref old_die = lookup_decl_die (decl); | |
10548 | int declaration = (current_function_decl != decl | |
10549 | || class_scope_p (context_die)); | |
a3f97cbb | 10550 | |
2ad9852d RK |
10551 | /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we |
10552 | started to generate the abstract instance of an inline, decided to output | |
10553 | its containing class, and proceeded to emit the declaration of the inline | |
10554 | from the member list for the class. If so, DECLARATION takes priority; | |
10555 | we'll get back to the abstract instance when done with the class. */ | |
10a11b75 | 10556 | |
1cfdcc15 JM |
10557 | /* The class-scope declaration DIE must be the primary DIE. */ |
10558 | if (origin && declaration && class_scope_p (context_die)) | |
10559 | { | |
10560 | origin = NULL; | |
10561 | if (old_die) | |
10562 | abort (); | |
10563 | } | |
10564 | ||
a3f97cbb JW |
10565 | if (origin != NULL) |
10566 | { | |
777ad4c2 | 10567 | if (declaration && ! local_scope_p (context_die)) |
10a11b75 JM |
10568 | abort (); |
10569 | ||
8d8238b6 JM |
10570 | /* Fixup die_parent for the abstract instance of a nested |
10571 | inline function. */ | |
10572 | if (old_die && old_die->die_parent == NULL) | |
10573 | add_child_die (context_die, old_die); | |
10574 | ||
54ba1f0d | 10575 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
a3f97cbb JW |
10576 | add_abstract_origin_attribute (subr_die, origin); |
10577 | } | |
bdb669cb JM |
10578 | else if (old_die) |
10579 | { | |
981975b6 | 10580 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
a94dbf2c | 10581 | |
1edf43d6 JM |
10582 | if (!get_AT_flag (old_die, DW_AT_declaration) |
10583 | /* We can have a normal definition following an inline one in the | |
10584 | case of redefinition of GNU C extern inlines. | |
10585 | It seems reasonable to use AT_specification in this case. */ | |
10586 | && !get_AT_unsigned (old_die, DW_AT_inline)) | |
b75ab88b NC |
10587 | { |
10588 | /* ??? This can happen if there is a bug in the program, for | |
10589 | instance, if it has duplicate function definitions. Ideally, | |
10590 | we should detect this case and ignore it. For now, if we have | |
10591 | already reported an error, any error at all, then assume that | |
4fe9b91c | 10592 | we got here because of an input error, not a dwarf2 bug. */ |
b75ab88b NC |
10593 | if (errorcount) |
10594 | return; | |
10595 | abort (); | |
10596 | } | |
4b674448 JM |
10597 | |
10598 | /* If the definition comes from the same place as the declaration, | |
a94dbf2c JM |
10599 | maybe use the old DIE. We always want the DIE for this function |
10600 | that has the *_pc attributes to be under comp_unit_die so the | |
cb9e9d8d JM |
10601 | debugger can find it. We also need to do this for abstract |
10602 | instances of inlines, since the spec requires the out-of-line copy | |
10603 | to have the same parent. For local class methods, this doesn't | |
10604 | apply; we just use the old DIE. */ | |
10605 | if ((old_die->die_parent == comp_unit_die || context_die == NULL) | |
a96c67ec JM |
10606 | && (DECL_ARTIFICIAL (decl) |
10607 | || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index | |
10608 | && (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 10609 | == (unsigned) DECL_SOURCE_LINE (decl))))) |
bdb669cb | 10610 | { |
4b674448 JM |
10611 | subr_die = old_die; |
10612 | ||
10613 | /* Clear out the declaration attribute and the parm types. */ | |
10614 | remove_AT (subr_die, DW_AT_declaration); | |
10615 | remove_children (subr_die); | |
10616 | } | |
10617 | else | |
10618 | { | |
54ba1f0d | 10619 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
4b674448 | 10620 | add_AT_die_ref (subr_die, DW_AT_specification, old_die); |
bdb669cb JM |
10621 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
10622 | add_AT_unsigned (subr_die, DW_AT_decl_file, file_index); | |
10623 | if (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 10624 | != (unsigned) DECL_SOURCE_LINE (decl)) |
bdb669cb JM |
10625 | add_AT_unsigned |
10626 | (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
10627 | } | |
10628 | } | |
a3f97cbb JW |
10629 | else |
10630 | { | |
54ba1f0d | 10631 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
556273e0 | 10632 | |
273dbe67 JM |
10633 | if (TREE_PUBLIC (decl)) |
10634 | add_AT_flag (subr_die, DW_AT_external, 1); | |
71dfc51f | 10635 | |
a3f97cbb | 10636 | add_name_and_src_coords_attributes (subr_die, decl); |
4927276d JM |
10637 | if (debug_info_level > DINFO_LEVEL_TERSE) |
10638 | { | |
2ad9852d RK |
10639 | add_prototyped_attribute (subr_die, TREE_TYPE (decl)); |
10640 | add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)), | |
10641 | 0, 0, context_die); | |
4927276d | 10642 | } |
71dfc51f | 10643 | |
a3f97cbb | 10644 | add_pure_or_virtual_attribute (subr_die, decl); |
273dbe67 JM |
10645 | if (DECL_ARTIFICIAL (decl)) |
10646 | add_AT_flag (subr_die, DW_AT_artificial, 1); | |
2ad9852d | 10647 | |
a94dbf2c JM |
10648 | if (TREE_PROTECTED (decl)) |
10649 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected); | |
10650 | else if (TREE_PRIVATE (decl)) | |
10651 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 10652 | } |
4edb7b60 | 10653 | |
a94dbf2c JM |
10654 | if (declaration) |
10655 | { | |
2ad9852d | 10656 | if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline)) |
1edf43d6 JM |
10657 | { |
10658 | add_AT_flag (subr_die, DW_AT_declaration, 1); | |
10659 | ||
10660 | /* The first time we see a member function, it is in the context of | |
10661 | the class to which it belongs. We make sure of this by emitting | |
10662 | the class first. The next time is the definition, which is | |
10663 | handled above. The two may come from the same source text. */ | |
10664 | if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl)) | |
10665 | equate_decl_number_to_die (decl, subr_die); | |
10666 | } | |
a94dbf2c JM |
10667 | } |
10668 | else if (DECL_ABSTRACT (decl)) | |
a3f97cbb | 10669 | { |
10a11b75 | 10670 | if (DECL_INLINE (decl) && !flag_no_inline) |
61b32c02 | 10671 | { |
10a11b75 JM |
10672 | /* ??? Checking DECL_DEFER_OUTPUT is correct for static |
10673 | inline functions, but not for extern inline functions. | |
10674 | We can't get this completely correct because information | |
10675 | about whether the function was declared inline is not | |
10676 | saved anywhere. */ | |
10677 | if (DECL_DEFER_OUTPUT (decl)) | |
61b32c02 JM |
10678 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined); |
10679 | else | |
10a11b75 | 10680 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined); |
61b32c02 | 10681 | } |
61b32c02 | 10682 | else |
10a11b75 | 10683 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined); |
61b32c02 | 10684 | |
a3f97cbb JW |
10685 | equate_decl_number_to_die (decl, subr_die); |
10686 | } | |
10687 | else if (!DECL_EXTERNAL (decl)) | |
10688 | { | |
2ad9852d | 10689 | if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline)) |
ba7b35df | 10690 | equate_decl_number_to_die (decl, subr_die); |
71dfc51f | 10691 | |
5c90448c | 10692 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL, |
df696a75 | 10693 | current_function_funcdef_no); |
7d4440be | 10694 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id); |
5c90448c | 10695 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, |
df696a75 | 10696 | current_function_funcdef_no); |
a3f97cbb JW |
10697 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id); |
10698 | ||
d291dd49 JM |
10699 | add_pubname (decl, subr_die); |
10700 | add_arange (decl, subr_die); | |
10701 | ||
a3f97cbb | 10702 | #ifdef MIPS_DEBUGGING_INFO |
a3f97cbb JW |
10703 | /* Add a reference to the FDE for this routine. */ |
10704 | add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde); | |
10705 | #endif | |
10706 | ||
810429b7 | 10707 | /* Define the "frame base" location for this routine. We use the |
73c68f61 SS |
10708 | frame pointer or stack pointer registers, since the RTL for local |
10709 | variables is relative to one of them. */ | |
b1ccbc24 RK |
10710 | fp_reg |
10711 | = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx; | |
10712 | add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg)); | |
a3f97cbb | 10713 | |
ef76d03b JW |
10714 | #if 0 |
10715 | /* ??? This fails for nested inline functions, because context_display | |
10716 | is not part of the state saved/restored for inline functions. */ | |
88dad228 | 10717 | if (current_function_needs_context) |
ef76d03b | 10718 | add_AT_location_description (subr_die, DW_AT_static_link, |
b9203463 | 10719 | loc_descriptor (lookup_static_chain (decl))); |
ef76d03b | 10720 | #endif |
a3f97cbb JW |
10721 | } |
10722 | ||
10723 | /* Now output descriptions of the arguments for this function. This gets | |
556273e0 | 10724 | (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list |
a3f97cbb JW |
10725 | for a FUNCTION_DECL doesn't indicate cases where there was a trailing |
10726 | `...' at the end of the formal parameter list. In order to find out if | |
10727 | there was a trailing ellipsis or not, we must instead look at the type | |
10728 | associated with the FUNCTION_DECL. This will be a node of type | |
10729 | FUNCTION_TYPE. If the chain of type nodes hanging off of this | |
556273e0 | 10730 | FUNCTION_TYPE node ends with a void_type_node then there should *not* be |
a3f97cbb | 10731 | an ellipsis at the end. */ |
71dfc51f | 10732 | |
a3f97cbb | 10733 | /* In the case where we are describing a mere function declaration, all we |
556273e0 | 10734 | need to do here (and all we *can* do here) is to describe the *types* of |
a3f97cbb | 10735 | its formal parameters. */ |
4927276d | 10736 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 10737 | ; |
4edb7b60 | 10738 | else if (declaration) |
5daf7c0a | 10739 | gen_formal_types_die (decl, subr_die); |
a3f97cbb JW |
10740 | else |
10741 | { | |
f9da5064 | 10742 | /* Generate DIEs to represent all known formal parameters. */ |
b3694847 SS |
10743 | tree arg_decls = DECL_ARGUMENTS (decl); |
10744 | tree parm; | |
a3f97cbb JW |
10745 | |
10746 | /* When generating DIEs, generate the unspecified_parameters DIE | |
73c68f61 | 10747 | instead if we come across the arg "__builtin_va_alist" */ |
a3f97cbb | 10748 | for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) |
71dfc51f RK |
10749 | if (TREE_CODE (parm) == PARM_DECL) |
10750 | { | |
db3cf6fb MS |
10751 | if (DECL_NAME (parm) |
10752 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), | |
10753 | "__builtin_va_alist")) | |
71dfc51f RK |
10754 | gen_unspecified_parameters_die (parm, subr_die); |
10755 | else | |
10756 | gen_decl_die (parm, subr_die); | |
10757 | } | |
a3f97cbb | 10758 | |
4fe9b91c | 10759 | /* Decide whether we need an unspecified_parameters DIE at the end. |
73c68f61 SS |
10760 | There are 2 more cases to do this for: 1) the ansi ... declaration - |
10761 | this is detectable when the end of the arg list is not a | |
10762 | void_type_node 2) an unprototyped function declaration (not a | |
10763 | definition). This just means that we have no info about the | |
10764 | parameters at all. */ | |
a3f97cbb | 10765 | fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); |
71dfc51f | 10766 | if (fn_arg_types != NULL) |
a3f97cbb JW |
10767 | { |
10768 | /* this is the prototyped case, check for ... */ | |
10769 | if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) | |
71dfc51f | 10770 | gen_unspecified_parameters_die (decl, subr_die); |
a3f97cbb | 10771 | } |
71dfc51f RK |
10772 | else if (DECL_INITIAL (decl) == NULL_TREE) |
10773 | gen_unspecified_parameters_die (decl, subr_die); | |
a3f97cbb JW |
10774 | } |
10775 | ||
10776 | /* Output Dwarf info for all of the stuff within the body of the function | |
10777 | (if it has one - it may be just a declaration). */ | |
10778 | outer_scope = DECL_INITIAL (decl); | |
10779 | ||
2ad9852d RK |
10780 | /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent |
10781 | a function. This BLOCK actually represents the outermost binding contour | |
10782 | for the function, i.e. the contour in which the function's formal | |
10783 | parameters and labels get declared. Curiously, it appears that the front | |
10784 | end doesn't actually put the PARM_DECL nodes for the current function onto | |
10785 | the BLOCK_VARS list for this outer scope, but are strung off of the | |
10786 | DECL_ARGUMENTS list for the function instead. | |
10787 | ||
10788 | The BLOCK_VARS list for the `outer_scope' does provide us with a list of | |
10789 | the LABEL_DECL nodes for the function however, and we output DWARF info | |
10790 | for those in decls_for_scope. Just within the `outer_scope' there will be | |
10791 | a BLOCK node representing the function's outermost pair of curly braces, | |
10792 | and any blocks used for the base and member initializers of a C++ | |
d7248bff | 10793 | constructor function. */ |
4edb7b60 | 10794 | if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK) |
7e23cb16 JM |
10795 | { |
10796 | current_function_has_inlines = 0; | |
10797 | decls_for_scope (outer_scope, subr_die, 0); | |
71dfc51f | 10798 | |
ce61cc73 | 10799 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
7e23cb16 JM |
10800 | if (current_function_has_inlines) |
10801 | { | |
10802 | add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1); | |
10803 | if (! comp_unit_has_inlines) | |
10804 | { | |
10805 | add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1); | |
10806 | comp_unit_has_inlines = 1; | |
10807 | } | |
10808 | } | |
10809 | #endif | |
10810 | } | |
a3f97cbb JW |
10811 | } |
10812 | ||
10813 | /* Generate a DIE to represent a declared data object. */ | |
71dfc51f | 10814 | |
a3f97cbb | 10815 | static void |
7080f735 | 10816 | gen_variable_die (tree decl, dw_die_ref context_die) |
a3f97cbb | 10817 | { |
b3694847 | 10818 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 10819 | dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl); |
71dfc51f | 10820 | |
bdb669cb | 10821 | dw_die_ref old_die = lookup_decl_die (decl); |
9765e357 JM |
10822 | int declaration = (DECL_EXTERNAL (decl) |
10823 | || class_scope_p (context_die)); | |
4edb7b60 | 10824 | |
a3f97cbb | 10825 | if (origin != NULL) |
71dfc51f | 10826 | add_abstract_origin_attribute (var_die, origin); |
2ad9852d | 10827 | |
f76b8156 | 10828 | /* Loop unrolling can create multiple blocks that refer to the same |
2ad9852d RK |
10829 | static variable, so we must test for the DW_AT_declaration flag. |
10830 | ||
10831 | ??? Loop unrolling/reorder_blocks should perhaps be rewritten to | |
f76b8156 | 10832 | copy decls and set the DECL_ABSTRACT flag on them instead of |
2ad9852d RK |
10833 | sharing them. |
10834 | ||
10835 | ??? Duplicated blocks have been rewritten to use .debug_ranges. */ | |
f76b8156 | 10836 | else if (old_die && TREE_STATIC (decl) |
c26fbbca | 10837 | && get_AT_flag (old_die, DW_AT_declaration) == 1) |
bdb669cb | 10838 | { |
e689ae67 | 10839 | /* This is a definition of a C++ class level static. */ |
bdb669cb JM |
10840 | add_AT_die_ref (var_die, DW_AT_specification, old_die); |
10841 | if (DECL_NAME (decl)) | |
10842 | { | |
981975b6 | 10843 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
71dfc51f | 10844 | |
bdb669cb JM |
10845 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
10846 | add_AT_unsigned (var_die, DW_AT_decl_file, file_index); | |
71dfc51f | 10847 | |
bdb669cb | 10848 | if (get_AT_unsigned (old_die, DW_AT_decl_line) |
556273e0 | 10849 | != (unsigned) DECL_SOURCE_LINE (decl)) |
71dfc51f RK |
10850 | |
10851 | add_AT_unsigned (var_die, DW_AT_decl_line, | |
10852 | DECL_SOURCE_LINE (decl)); | |
bdb669cb JM |
10853 | } |
10854 | } | |
a3f97cbb JW |
10855 | else |
10856 | { | |
10857 | add_name_and_src_coords_attributes (var_die, decl); | |
2ad9852d | 10858 | add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl), |
a3f97cbb | 10859 | TREE_THIS_VOLATILE (decl), context_die); |
71dfc51f | 10860 | |
273dbe67 JM |
10861 | if (TREE_PUBLIC (decl)) |
10862 | add_AT_flag (var_die, DW_AT_external, 1); | |
71dfc51f | 10863 | |
273dbe67 JM |
10864 | if (DECL_ARTIFICIAL (decl)) |
10865 | add_AT_flag (var_die, DW_AT_artificial, 1); | |
71dfc51f | 10866 | |
a94dbf2c JM |
10867 | if (TREE_PROTECTED (decl)) |
10868 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected); | |
10869 | else if (TREE_PRIVATE (decl)) | |
10870 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 10871 | } |
4edb7b60 JM |
10872 | |
10873 | if (declaration) | |
10874 | add_AT_flag (var_die, DW_AT_declaration, 1); | |
556273e0 | 10875 | |
9765e357 | 10876 | if (class_scope_p (context_die) || DECL_ABSTRACT (decl)) |
4edb7b60 JM |
10877 | equate_decl_number_to_die (decl, var_die); |
10878 | ||
10879 | if (! declaration && ! DECL_ABSTRACT (decl)) | |
a3f97cbb JW |
10880 | { |
10881 | add_location_or_const_value_attribute (var_die, decl); | |
d291dd49 | 10882 | add_pubname (decl, var_die); |
a3f97cbb | 10883 | } |
1bfb5f8f JM |
10884 | else |
10885 | tree_add_const_value_attribute (var_die, decl); | |
a3f97cbb JW |
10886 | } |
10887 | ||
10888 | /* Generate a DIE to represent a label identifier. */ | |
71dfc51f | 10889 | |
a3f97cbb | 10890 | static void |
7080f735 | 10891 | gen_label_die (tree decl, dw_die_ref context_die) |
a3f97cbb | 10892 | { |
b3694847 | 10893 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 10894 | dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl); |
b3694847 | 10895 | rtx insn; |
a3f97cbb | 10896 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 10897 | |
a3f97cbb | 10898 | if (origin != NULL) |
71dfc51f | 10899 | add_abstract_origin_attribute (lbl_die, origin); |
a3f97cbb | 10900 | else |
71dfc51f RK |
10901 | add_name_and_src_coords_attributes (lbl_die, decl); |
10902 | ||
a3f97cbb | 10903 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 10904 | equate_decl_number_to_die (decl, lbl_die); |
a3f97cbb JW |
10905 | else |
10906 | { | |
10907 | insn = DECL_RTL (decl); | |
088e7160 NC |
10908 | |
10909 | /* Deleted labels are programmer specified labels which have been | |
6356f892 | 10910 | eliminated because of various optimizations. We still emit them |
088e7160 NC |
10911 | here so that it is possible to put breakpoints on them. */ |
10912 | if (GET_CODE (insn) == CODE_LABEL | |
10913 | || ((GET_CODE (insn) == NOTE | |
10914 | && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))) | |
a3f97cbb | 10915 | { |
556273e0 KH |
10916 | /* When optimization is enabled (via -O) some parts of the compiler |
10917 | (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which | |
a3f97cbb JW |
10918 | represent source-level labels which were explicitly declared by |
10919 | the user. This really shouldn't be happening though, so catch | |
10920 | it if it ever does happen. */ | |
10921 | if (INSN_DELETED_P (insn)) | |
71dfc51f RK |
10922 | abort (); |
10923 | ||
66234570 | 10924 | ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn)); |
a3f97cbb JW |
10925 | add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); |
10926 | } | |
10927 | } | |
10928 | } | |
10929 | ||
10930 | /* Generate a DIE for a lexical block. */ | |
71dfc51f | 10931 | |
a3f97cbb | 10932 | static void |
7080f735 | 10933 | gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth) |
a3f97cbb | 10934 | { |
54ba1f0d | 10935 | dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt); |
a3f97cbb | 10936 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f RK |
10937 | |
10938 | if (! BLOCK_ABSTRACT (stmt)) | |
a3f97cbb | 10939 | { |
a20612aa RH |
10940 | if (BLOCK_FRAGMENT_CHAIN (stmt)) |
10941 | { | |
10942 | tree chain; | |
10943 | ||
2bee6045 | 10944 | add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt)); |
a20612aa RH |
10945 | |
10946 | chain = BLOCK_FRAGMENT_CHAIN (stmt); | |
10947 | do | |
10948 | { | |
10949 | add_ranges (chain); | |
10950 | chain = BLOCK_FRAGMENT_CHAIN (chain); | |
10951 | } | |
10952 | while (chain); | |
10953 | add_ranges (NULL); | |
10954 | } | |
10955 | else | |
10956 | { | |
10957 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, | |
10958 | BLOCK_NUMBER (stmt)); | |
10959 | add_AT_lbl_id (stmt_die, DW_AT_low_pc, label); | |
10960 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, | |
10961 | BLOCK_NUMBER (stmt)); | |
10962 | add_AT_lbl_id (stmt_die, DW_AT_high_pc, label); | |
10963 | } | |
a3f97cbb | 10964 | } |
71dfc51f | 10965 | |
d7248bff | 10966 | decls_for_scope (stmt, stmt_die, depth); |
a3f97cbb JW |
10967 | } |
10968 | ||
10969 | /* Generate a DIE for an inlined subprogram. */ | |
71dfc51f | 10970 | |
a3f97cbb | 10971 | static void |
7080f735 | 10972 | gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth) |
a3f97cbb | 10973 | { |
71dfc51f | 10974 | if (! BLOCK_ABSTRACT (stmt)) |
a3f97cbb | 10975 | { |
b3694847 | 10976 | dw_die_ref subr_die |
54ba1f0d | 10977 | = new_die (DW_TAG_inlined_subroutine, context_die, stmt); |
b3694847 | 10978 | tree decl = block_ultimate_origin (stmt); |
d7248bff | 10979 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 10980 | |
10a11b75 | 10981 | /* Emit info for the abstract instance first, if we haven't yet. */ |
1edf43d6 | 10982 | dwarf2out_abstract_function (decl); |
10a11b75 | 10983 | |
ab72d377 | 10984 | add_abstract_origin_attribute (subr_die, decl); |
5c90448c | 10985 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
18c038b9 | 10986 | BLOCK_NUMBER (stmt)); |
a3f97cbb | 10987 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label); |
18c038b9 MM |
10988 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, |
10989 | BLOCK_NUMBER (stmt)); | |
a3f97cbb | 10990 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label); |
d7248bff | 10991 | decls_for_scope (stmt, subr_die, depth); |
7e23cb16 | 10992 | current_function_has_inlines = 1; |
a3f97cbb | 10993 | } |
06e224f7 AO |
10994 | else |
10995 | /* We may get here if we're the outer block of function A that was | |
10996 | inlined into function B that was inlined into function C. When | |
10997 | generating debugging info for C, dwarf2out_abstract_function(B) | |
10998 | would mark all inlined blocks as abstract, including this one. | |
10999 | So, we wouldn't (and shouldn't) expect labels to be generated | |
11000 | for this one. Instead, just emit debugging info for | |
11001 | declarations within the block. This is particularly important | |
11002 | in the case of initializers of arguments passed from B to us: | |
11003 | if they're statement expressions containing declarations, we | |
11004 | wouldn't generate dies for their abstract variables, and then, | |
11005 | when generating dies for the real variables, we'd die (pun | |
11006 | intended :-) */ | |
11007 | gen_lexical_block_die (stmt, context_die, depth); | |
a3f97cbb JW |
11008 | } |
11009 | ||
11010 | /* Generate a DIE for a field in a record, or structure. */ | |
71dfc51f | 11011 | |
a3f97cbb | 11012 | static void |
7080f735 | 11013 | gen_field_die (tree decl, dw_die_ref context_die) |
a3f97cbb | 11014 | { |
a53efda2 | 11015 | dw_die_ref decl_die; |
71dfc51f | 11016 | |
a53efda2 JZ |
11017 | if (TREE_TYPE (decl) == error_mark_node) |
11018 | return; | |
7080f735 | 11019 | |
a53efda2 | 11020 | decl_die = new_die (DW_TAG_member, context_die, decl); |
a3f97cbb | 11021 | add_name_and_src_coords_attributes (decl_die, decl); |
a3f97cbb JW |
11022 | add_type_attribute (decl_die, member_declared_type (decl), |
11023 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl), | |
11024 | context_die); | |
71dfc51f | 11025 | |
a3f97cbb JW |
11026 | if (DECL_BIT_FIELD_TYPE (decl)) |
11027 | { | |
11028 | add_byte_size_attribute (decl_die, decl); | |
11029 | add_bit_size_attribute (decl_die, decl); | |
11030 | add_bit_offset_attribute (decl_die, decl); | |
11031 | } | |
71dfc51f | 11032 | |
a94dbf2c JM |
11033 | if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE) |
11034 | add_data_member_location_attribute (decl_die, decl); | |
71dfc51f | 11035 | |
273dbe67 JM |
11036 | if (DECL_ARTIFICIAL (decl)) |
11037 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
71dfc51f | 11038 | |
a94dbf2c JM |
11039 | if (TREE_PROTECTED (decl)) |
11040 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected); | |
11041 | else if (TREE_PRIVATE (decl)) | |
11042 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb JW |
11043 | } |
11044 | ||
ab72d377 JM |
11045 | #if 0 |
11046 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. | |
11047 | Use modified_type_die instead. | |
a3f97cbb JW |
11048 | We keep this code here just in case these types of DIEs may be needed to |
11049 | represent certain things in other languages (e.g. Pascal) someday. */ | |
2ad9852d | 11050 | |
a3f97cbb | 11051 | static void |
7080f735 | 11052 | gen_pointer_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 11053 | { |
b3694847 | 11054 | dw_die_ref ptr_die |
54ba1f0d | 11055 | = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type); |
71dfc51f | 11056 | |
a3f97cbb | 11057 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 11058 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 11059 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb JW |
11060 | } |
11061 | ||
ab72d377 JM |
11062 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. |
11063 | Use modified_type_die instead. | |
a3f97cbb JW |
11064 | We keep this code here just in case these types of DIEs may be needed to |
11065 | represent certain things in other languages (e.g. Pascal) someday. */ | |
2ad9852d | 11066 | |
a3f97cbb | 11067 | static void |
7080f735 | 11068 | gen_reference_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 11069 | { |
b3694847 | 11070 | dw_die_ref ref_die |
54ba1f0d | 11071 | = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type); |
71dfc51f | 11072 | |
a3f97cbb | 11073 | equate_type_number_to_die (type, ref_die); |
a3f97cbb | 11074 | add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 11075 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb | 11076 | } |
ab72d377 | 11077 | #endif |
a3f97cbb JW |
11078 | |
11079 | /* Generate a DIE for a pointer to a member type. */ | |
2ad9852d | 11080 | |
a3f97cbb | 11081 | static void |
7080f735 | 11082 | gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 11083 | { |
b3694847 | 11084 | dw_die_ref ptr_die |
54ba1f0d RH |
11085 | = new_die (DW_TAG_ptr_to_member_type, |
11086 | scope_die_for (type, context_die), type); | |
71dfc51f | 11087 | |
a3f97cbb | 11088 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 11089 | add_AT_die_ref (ptr_die, DW_AT_containing_type, |
bdb669cb | 11090 | lookup_type_die (TYPE_OFFSET_BASETYPE (type))); |
a3f97cbb JW |
11091 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
11092 | } | |
11093 | ||
11094 | /* Generate the DIE for the compilation unit. */ | |
71dfc51f | 11095 | |
a96c67ec | 11096 | static dw_die_ref |
7080f735 | 11097 | gen_compile_unit_die (const char *filename) |
a3f97cbb | 11098 | { |
b3694847 | 11099 | dw_die_ref die; |
a3f97cbb | 11100 | char producer[250]; |
3ac88239 | 11101 | const char *language_string = lang_hooks.name; |
a96c67ec | 11102 | int language; |
a3f97cbb | 11103 | |
54ba1f0d | 11104 | die = new_die (DW_TAG_compile_unit, NULL, NULL); |
bdb669cb | 11105 | |
c4274b22 RH |
11106 | if (filename) |
11107 | { | |
11108 | add_name_attribute (die, filename); | |
e3091a5f R |
11109 | /* Don't add cwd for <built-in>. */ |
11110 | if (filename[0] != DIR_SEPARATOR && filename[0] != '<') | |
c4274b22 RH |
11111 | add_comp_dir_attribute (die); |
11112 | } | |
a3f97cbb JW |
11113 | |
11114 | sprintf (producer, "%s %s", language_string, version_string); | |
11115 | ||
11116 | #ifdef MIPS_DEBUGGING_INFO | |
11117 | /* The MIPS/SGI compilers place the 'cc' command line options in the producer | |
11118 | string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do | |
11119 | not appear in the producer string, the debugger reaches the conclusion | |
11120 | that the object file is stripped and has no debugging information. | |
11121 | To get the MIPS/SGI debugger to believe that there is debugging | |
11122 | information in the object file, we add a -g to the producer string. */ | |
4927276d JM |
11123 | if (debug_info_level > DINFO_LEVEL_TERSE) |
11124 | strcat (producer, " -g"); | |
a3f97cbb JW |
11125 | #endif |
11126 | ||
a96c67ec | 11127 | add_AT_string (die, DW_AT_producer, producer); |
a9d38797 | 11128 | |
a3f97cbb | 11129 | if (strcmp (language_string, "GNU C++") == 0) |
a96c67ec | 11130 | language = DW_LANG_C_plus_plus; |
a3f97cbb | 11131 | else if (strcmp (language_string, "GNU Ada") == 0) |
8cb5fbbf | 11132 | language = DW_LANG_Ada95; |
a9d38797 | 11133 | else if (strcmp (language_string, "GNU F77") == 0) |
a96c67ec | 11134 | language = DW_LANG_Fortran77; |
bc28c45b | 11135 | else if (strcmp (language_string, "GNU Pascal") == 0) |
a96c67ec | 11136 | language = DW_LANG_Pascal83; |
28985b81 AG |
11137 | else if (strcmp (language_string, "GNU Java") == 0) |
11138 | language = DW_LANG_Java; | |
a3f97cbb | 11139 | else |
a96c67ec | 11140 | language = DW_LANG_C89; |
a9d38797 | 11141 | |
a96c67ec | 11142 | add_AT_unsigned (die, DW_AT_language, language); |
a96c67ec | 11143 | return die; |
a3f97cbb JW |
11144 | } |
11145 | ||
11146 | /* Generate a DIE for a string type. */ | |
71dfc51f | 11147 | |
a3f97cbb | 11148 | static void |
7080f735 | 11149 | gen_string_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 11150 | { |
b3694847 | 11151 | dw_die_ref type_die |
54ba1f0d | 11152 | = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type); |
71dfc51f | 11153 | |
bdb669cb | 11154 | equate_type_number_to_die (type, type_die); |
a3f97cbb | 11155 | |
2ad9852d RK |
11156 | /* ??? Fudge the string length attribute for now. |
11157 | TODO: add string length info. */ | |
11158 | #if 0 | |
11159 | string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type))); | |
11160 | bound_representation (upper_bound, 0, 'u'); | |
11161 | #endif | |
a3f97cbb JW |
11162 | } |
11163 | ||
61b32c02 | 11164 | /* Generate the DIE for a base class. */ |
71dfc51f | 11165 | |
61b32c02 | 11166 | static void |
7080f735 | 11167 | gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die) |
61b32c02 | 11168 | { |
54ba1f0d | 11169 | dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo); |
71dfc51f | 11170 | |
61b32c02 JM |
11171 | add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die); |
11172 | add_data_member_location_attribute (die, binfo); | |
71dfc51f | 11173 | |
61b32c02 JM |
11174 | if (TREE_VIA_VIRTUAL (binfo)) |
11175 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); | |
2ad9852d | 11176 | |
dbbf88d1 | 11177 | if (access == access_public_node) |
61b32c02 | 11178 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public); |
dbbf88d1 | 11179 | else if (access == access_protected_node) |
61b32c02 JM |
11180 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected); |
11181 | } | |
11182 | ||
956d6950 | 11183 | /* Generate a DIE for a class member. */ |
71dfc51f | 11184 | |
a3f97cbb | 11185 | static void |
7080f735 | 11186 | gen_member_die (tree type, dw_die_ref context_die) |
a3f97cbb | 11187 | { |
b3694847 | 11188 | tree member; |
dbbf88d1 | 11189 | tree binfo = TYPE_BINFO (type); |
10a11b75 | 11190 | dw_die_ref child; |
71dfc51f | 11191 | |
a3f97cbb JW |
11192 | /* If this is not an incomplete type, output descriptions of each of its |
11193 | members. Note that as we output the DIEs necessary to represent the | |
11194 | members of this record or union type, we will also be trying to output | |
11195 | DIEs to represent the *types* of those members. However the `type' | |
556273e0 | 11196 | function (above) will specifically avoid generating type DIEs for member |
eaec9b3d | 11197 | types *within* the list of member DIEs for this (containing) type except |
a3f97cbb JW |
11198 | for those types (of members) which are explicitly marked as also being |
11199 | members of this (containing) type themselves. The g++ front- end can | |
2ad9852d RK |
11200 | force any given type to be treated as a member of some other (containing) |
11201 | type by setting the TYPE_CONTEXT of the given (member) type to point to | |
11202 | the TREE node representing the appropriate (containing) type. */ | |
a3f97cbb | 11203 | |
61b32c02 | 11204 | /* First output info about the base classes. */ |
dbbf88d1 | 11205 | if (binfo && BINFO_BASETYPES (binfo)) |
a3f97cbb | 11206 | { |
dbbf88d1 NS |
11207 | tree bases = BINFO_BASETYPES (binfo); |
11208 | tree accesses = BINFO_BASEACCESSES (binfo); | |
b3694847 SS |
11209 | int n_bases = TREE_VEC_LENGTH (bases); |
11210 | int i; | |
61b32c02 JM |
11211 | |
11212 | for (i = 0; i < n_bases; i++) | |
dbbf88d1 NS |
11213 | gen_inheritance_die (TREE_VEC_ELT (bases, i), |
11214 | (accesses ? TREE_VEC_ELT (accesses, i) | |
11215 | : access_public_node), context_die); | |
a3f97cbb JW |
11216 | } |
11217 | ||
61b32c02 JM |
11218 | /* Now output info about the data members and type members. */ |
11219 | for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member)) | |
10a11b75 JM |
11220 | { |
11221 | /* If we thought we were generating minimal debug info for TYPE | |
11222 | and then changed our minds, some of the member declarations | |
11223 | may have already been defined. Don't define them again, but | |
11224 | do put them in the right order. */ | |
11225 | ||
11226 | child = lookup_decl_die (member); | |
11227 | if (child) | |
11228 | splice_child_die (context_die, child); | |
11229 | else | |
11230 | gen_decl_die (member, context_die); | |
11231 | } | |
61b32c02 | 11232 | |
a3f97cbb | 11233 | /* Now output info about the function members (if any). */ |
61b32c02 | 11234 | for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member)) |
10a11b75 | 11235 | { |
5daf7c0a JM |
11236 | /* Don't include clones in the member list. */ |
11237 | if (DECL_ABSTRACT_ORIGIN (member)) | |
11238 | continue; | |
11239 | ||
10a11b75 JM |
11240 | child = lookup_decl_die (member); |
11241 | if (child) | |
11242 | splice_child_die (context_die, child); | |
11243 | else | |
11244 | gen_decl_die (member, context_die); | |
11245 | } | |
a3f97cbb JW |
11246 | } |
11247 | ||
10a11b75 JM |
11248 | /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG |
11249 | is set, we pretend that the type was never defined, so we only get the | |
11250 | member DIEs needed by later specification DIEs. */ | |
71dfc51f | 11251 | |
a3f97cbb | 11252 | static void |
7080f735 | 11253 | gen_struct_or_union_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 11254 | { |
b3694847 SS |
11255 | dw_die_ref type_die = lookup_type_die (type); |
11256 | dw_die_ref scope_die = 0; | |
11257 | int nested = 0; | |
10a11b75 | 11258 | int complete = (TYPE_SIZE (type) |
65e1263a JW |
11259 | && (! TYPE_STUB_DECL (type) |
11260 | || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)))); | |
273dbe67 | 11261 | |
10a11b75 | 11262 | if (type_die && ! complete) |
273dbe67 | 11263 | return; |
a082c85a | 11264 | |
71dfc51f | 11265 | if (TYPE_CONTEXT (type) != NULL_TREE |
5f2f160c | 11266 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))) |
a082c85a JM |
11267 | nested = 1; |
11268 | ||
a94dbf2c | 11269 | scope_die = scope_die_for (type, context_die); |
a082c85a JM |
11270 | |
11271 | if (! type_die || (nested && scope_die == comp_unit_die)) | |
273dbe67 | 11272 | /* First occurrence of type or toplevel definition of nested class. */ |
a3f97cbb | 11273 | { |
b3694847 | 11274 | dw_die_ref old_die = type_die; |
71dfc51f | 11275 | |
a3f97cbb JW |
11276 | type_die = new_die (TREE_CODE (type) == RECORD_TYPE |
11277 | ? DW_TAG_structure_type : DW_TAG_union_type, | |
54ba1f0d | 11278 | scope_die, type); |
a3f97cbb | 11279 | equate_type_number_to_die (type, type_die); |
273dbe67 JM |
11280 | if (old_die) |
11281 | add_AT_die_ref (type_die, DW_AT_specification, old_die); | |
5de0e8d4 JM |
11282 | else |
11283 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 11284 | } |
4b674448 | 11285 | else |
273dbe67 | 11286 | remove_AT (type_die, DW_AT_declaration); |
a3f97cbb JW |
11287 | |
11288 | /* If this type has been completed, then give it a byte_size attribute and | |
11289 | then give a list of members. */ | |
2081603c | 11290 | if (complete) |
a3f97cbb | 11291 | { |
556273e0 | 11292 | /* Prevent infinite recursion in cases where the type of some member of |
73c68f61 | 11293 | this type is expressed in terms of this type itself. */ |
a3f97cbb | 11294 | TREE_ASM_WRITTEN (type) = 1; |
273dbe67 | 11295 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 11296 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 11297 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 11298 | |
ef76d03b JW |
11299 | /* If the first reference to this type was as the return type of an |
11300 | inline function, then it may not have a parent. Fix this now. */ | |
11301 | if (type_die->die_parent == NULL) | |
11302 | add_child_die (scope_die, type_die); | |
11303 | ||
273dbe67 JM |
11304 | push_decl_scope (type); |
11305 | gen_member_die (type, type_die); | |
11306 | pop_decl_scope (); | |
71dfc51f | 11307 | |
a94dbf2c JM |
11308 | /* GNU extension: Record what type our vtable lives in. */ |
11309 | if (TYPE_VFIELD (type)) | |
11310 | { | |
11311 | tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type)); | |
71dfc51f | 11312 | |
de6e505e JM |
11313 | gen_type_die (vtype, context_die); |
11314 | add_AT_die_ref (type_die, DW_AT_containing_type, | |
11315 | lookup_type_die (vtype)); | |
a94dbf2c | 11316 | } |
a3f97cbb | 11317 | } |
4b674448 | 11318 | else |
8a8c3656 JM |
11319 | { |
11320 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a30d4514 | 11321 | |
9765e357 | 11322 | /* We don't need to do this for function-local types. */ |
9702143f RK |
11323 | if (TYPE_STUB_DECL (type) |
11324 | && ! decl_function_context (TYPE_STUB_DECL (type))) | |
2ad9852d | 11325 | VARRAY_PUSH_TREE (incomplete_types, type); |
8a8c3656 | 11326 | } |
a3f97cbb JW |
11327 | } |
11328 | ||
11329 | /* Generate a DIE for a subroutine _type_. */ | |
71dfc51f | 11330 | |
a3f97cbb | 11331 | static void |
7080f735 | 11332 | gen_subroutine_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 11333 | { |
b3694847 SS |
11334 | tree return_type = TREE_TYPE (type); |
11335 | dw_die_ref subr_die | |
54ba1f0d RH |
11336 | = new_die (DW_TAG_subroutine_type, |
11337 | scope_die_for (type, context_die), type); | |
71dfc51f | 11338 | |
a3f97cbb JW |
11339 | equate_type_number_to_die (type, subr_die); |
11340 | add_prototyped_attribute (subr_die, type); | |
a3f97cbb | 11341 | add_type_attribute (subr_die, return_type, 0, 0, context_die); |
a94dbf2c | 11342 | gen_formal_types_die (type, subr_die); |
a3f97cbb JW |
11343 | } |
11344 | ||
f9da5064 | 11345 | /* Generate a DIE for a type definition. */ |
71dfc51f | 11346 | |
a3f97cbb | 11347 | static void |
7080f735 | 11348 | gen_typedef_die (tree decl, dw_die_ref context_die) |
a3f97cbb | 11349 | { |
b3694847 SS |
11350 | dw_die_ref type_die; |
11351 | tree origin; | |
a94dbf2c JM |
11352 | |
11353 | if (TREE_ASM_WRITTEN (decl)) | |
11354 | return; | |
a94dbf2c | 11355 | |
2ad9852d | 11356 | TREE_ASM_WRITTEN (decl) = 1; |
54ba1f0d | 11357 | type_die = new_die (DW_TAG_typedef, context_die, decl); |
a94dbf2c | 11358 | origin = decl_ultimate_origin (decl); |
a3f97cbb | 11359 | if (origin != NULL) |
a94dbf2c | 11360 | add_abstract_origin_attribute (type_die, origin); |
a3f97cbb JW |
11361 | else |
11362 | { | |
b3694847 | 11363 | tree type; |
2ad9852d | 11364 | |
a3f97cbb | 11365 | add_name_and_src_coords_attributes (type_die, decl); |
a94dbf2c JM |
11366 | if (DECL_ORIGINAL_TYPE (decl)) |
11367 | { | |
11368 | type = DECL_ORIGINAL_TYPE (decl); | |
62e3bf54 JM |
11369 | |
11370 | if (type == TREE_TYPE (decl)) | |
11371 | abort (); | |
11372 | else | |
11373 | equate_type_number_to_die (TREE_TYPE (decl), type_die); | |
a94dbf2c JM |
11374 | } |
11375 | else | |
11376 | type = TREE_TYPE (decl); | |
2ad9852d | 11377 | |
a94dbf2c JM |
11378 | add_type_attribute (type_die, type, TREE_READONLY (decl), |
11379 | TREE_THIS_VOLATILE (decl), context_die); | |
a3f97cbb | 11380 | } |
71dfc51f | 11381 | |
a3f97cbb | 11382 | if (DECL_ABSTRACT (decl)) |
a94dbf2c | 11383 | equate_decl_number_to_die (decl, type_die); |
a3f97cbb JW |
11384 | } |
11385 | ||
11386 | /* Generate a type description DIE. */ | |
71dfc51f | 11387 | |
a3f97cbb | 11388 | static void |
7080f735 | 11389 | gen_type_die (tree type, dw_die_ref context_die) |
a3f97cbb | 11390 | { |
348bb3c7 JM |
11391 | int need_pop; |
11392 | ||
71dfc51f RK |
11393 | if (type == NULL_TREE || type == error_mark_node) |
11394 | return; | |
a3f97cbb | 11395 | |
a94dbf2c JM |
11396 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
11397 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
556273e0 | 11398 | { |
5d7bed9d DJ |
11399 | if (TREE_ASM_WRITTEN (type)) |
11400 | return; | |
11401 | ||
29b91443 JM |
11402 | /* Prevent broken recursion; we can't hand off to the same type. */ |
11403 | if (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) == type) | |
11404 | abort (); | |
11405 | ||
a94dbf2c JM |
11406 | TREE_ASM_WRITTEN (type) = 1; |
11407 | gen_decl_die (TYPE_NAME (type), context_die); | |
11408 | return; | |
11409 | } | |
11410 | ||
5d7bed9d DJ |
11411 | /* We are going to output a DIE to represent the unqualified version |
11412 | of this type (i.e. without any const or volatile qualifiers) so | |
11413 | get the main variant (i.e. the unqualified version) of this type | |
11414 | now. (Vectors are special because the debugging info is in the | |
11415 | cloned type itself). */ | |
11416 | if (TREE_CODE (type) != VECTOR_TYPE) | |
11417 | type = type_main_variant (type); | |
11418 | ||
11419 | if (TREE_ASM_WRITTEN (type)) | |
11420 | return; | |
11421 | ||
a3f97cbb JW |
11422 | switch (TREE_CODE (type)) |
11423 | { | |
11424 | case ERROR_MARK: | |
11425 | break; | |
11426 | ||
11427 | case POINTER_TYPE: | |
11428 | case REFERENCE_TYPE: | |
956d6950 JL |
11429 | /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This |
11430 | ensures that the gen_type_die recursion will terminate even if the | |
11431 | type is recursive. Recursive types are possible in Ada. */ | |
11432 | /* ??? We could perhaps do this for all types before the switch | |
11433 | statement. */ | |
11434 | TREE_ASM_WRITTEN (type) = 1; | |
11435 | ||
a3f97cbb | 11436 | /* For these types, all that is required is that we output a DIE (or a |
73c68f61 | 11437 | set of DIEs) to represent the "basis" type. */ |
a3f97cbb JW |
11438 | gen_type_die (TREE_TYPE (type), context_die); |
11439 | break; | |
11440 | ||
11441 | case OFFSET_TYPE: | |
556273e0 | 11442 | /* This code is used for C++ pointer-to-data-member types. |
71dfc51f | 11443 | Output a description of the relevant class type. */ |
a3f97cbb | 11444 | gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die); |
71dfc51f | 11445 | |
a3f97cbb JW |
11446 | /* Output a description of the type of the object pointed to. */ |
11447 | gen_type_die (TREE_TYPE (type), context_die); | |
71dfc51f | 11448 | |
a3f97cbb | 11449 | /* Now output a DIE to represent this pointer-to-data-member type |
73c68f61 | 11450 | itself. */ |
a3f97cbb JW |
11451 | gen_ptr_to_mbr_type_die (type, context_die); |
11452 | break; | |
11453 | ||
11454 | case SET_TYPE: | |
11455 | gen_type_die (TYPE_DOMAIN (type), context_die); | |
11456 | gen_set_type_die (type, context_die); | |
11457 | break; | |
11458 | ||
11459 | case FILE_TYPE: | |
11460 | gen_type_die (TREE_TYPE (type), context_die); | |
11461 | abort (); /* No way to represent these in Dwarf yet! */ | |
11462 | break; | |
11463 | ||
11464 | case FUNCTION_TYPE: | |
11465 | /* Force out return type (in case it wasn't forced out already). */ | |
11466 | gen_type_die (TREE_TYPE (type), context_die); | |
11467 | gen_subroutine_type_die (type, context_die); | |
11468 | break; | |
11469 | ||
11470 | case METHOD_TYPE: | |
11471 | /* Force out return type (in case it wasn't forced out already). */ | |
11472 | gen_type_die (TREE_TYPE (type), context_die); | |
11473 | gen_subroutine_type_die (type, context_die); | |
11474 | break; | |
11475 | ||
11476 | case ARRAY_TYPE: | |
11477 | if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE) | |
11478 | { | |
11479 | gen_type_die (TREE_TYPE (type), context_die); | |
11480 | gen_string_type_die (type, context_die); | |
11481 | } | |
11482 | else | |
71dfc51f | 11483 | gen_array_type_die (type, context_die); |
a3f97cbb JW |
11484 | break; |
11485 | ||
4061f623 | 11486 | case VECTOR_TYPE: |
84f0ace0 | 11487 | gen_array_type_die (type, context_die); |
4061f623 BS |
11488 | break; |
11489 | ||
a3f97cbb JW |
11490 | case ENUMERAL_TYPE: |
11491 | case RECORD_TYPE: | |
11492 | case UNION_TYPE: | |
11493 | case QUAL_UNION_TYPE: | |
2ad9852d | 11494 | /* If this is a nested type whose containing class hasn't been written |
73c68f61 SS |
11495 | out yet, writing it out will cover this one, too. This does not apply |
11496 | to instantiations of member class templates; they need to be added to | |
11497 | the containing class as they are generated. FIXME: This hurts the | |
11498 | idea of combining type decls from multiple TUs, since we can't predict | |
11499 | what set of template instantiations we'll get. */ | |
a082c85a | 11500 | if (TYPE_CONTEXT (type) |
5f2f160c | 11501 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) |
a082c85a | 11502 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) |
a94dbf2c JM |
11503 | { |
11504 | gen_type_die (TYPE_CONTEXT (type), context_die); | |
11505 | ||
348bb3c7 | 11506 | if (TREE_ASM_WRITTEN (type)) |
a94dbf2c JM |
11507 | return; |
11508 | ||
11509 | /* If that failed, attach ourselves to the stub. */ | |
11510 | push_decl_scope (TYPE_CONTEXT (type)); | |
11511 | context_die = lookup_type_die (TYPE_CONTEXT (type)); | |
348bb3c7 | 11512 | need_pop = 1; |
a94dbf2c | 11513 | } |
348bb3c7 JM |
11514 | else |
11515 | need_pop = 0; | |
a94dbf2c JM |
11516 | |
11517 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
273dbe67 | 11518 | gen_enumeration_type_die (type, context_die); |
a3f97cbb | 11519 | else |
273dbe67 | 11520 | gen_struct_or_union_type_die (type, context_die); |
4b674448 | 11521 | |
348bb3c7 | 11522 | if (need_pop) |
a94dbf2c JM |
11523 | pop_decl_scope (); |
11524 | ||
4b674448 | 11525 | /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix |
a082c85a JM |
11526 | it up if it is ever completed. gen_*_type_die will set it for us |
11527 | when appropriate. */ | |
11528 | return; | |
a3f97cbb JW |
11529 | |
11530 | case VOID_TYPE: | |
11531 | case INTEGER_TYPE: | |
11532 | case REAL_TYPE: | |
11533 | case COMPLEX_TYPE: | |
11534 | case BOOLEAN_TYPE: | |
11535 | case CHAR_TYPE: | |
11536 | /* No DIEs needed for fundamental types. */ | |
11537 | break; | |
11538 | ||
11539 | case LANG_TYPE: | |
11540 | /* No Dwarf representation currently defined. */ | |
11541 | break; | |
11542 | ||
11543 | default: | |
11544 | abort (); | |
11545 | } | |
11546 | ||
11547 | TREE_ASM_WRITTEN (type) = 1; | |
11548 | } | |
11549 | ||
11550 | /* Generate a DIE for a tagged type instantiation. */ | |
71dfc51f | 11551 | |
a3f97cbb | 11552 | static void |
7080f735 | 11553 | gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die) |
a3f97cbb | 11554 | { |
71dfc51f RK |
11555 | if (type == NULL_TREE || type == error_mark_node) |
11556 | return; | |
a3f97cbb | 11557 | |
38e01259 | 11558 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
11559 | this type (i.e. without any const or volatile qualifiers) so make sure |
11560 | that we have the main variant (i.e. the unqualified version) of this | |
11561 | type now. */ | |
bbc6ae08 | 11562 | if (type != type_main_variant (type)) |
3a88cbd1 | 11563 | abort (); |
a3f97cbb | 11564 | |
203588e7 | 11565 | /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is |
bbc6ae08 | 11566 | an instance of an unresolved type. */ |
556273e0 | 11567 | |
a3f97cbb JW |
11568 | switch (TREE_CODE (type)) |
11569 | { | |
11570 | case ERROR_MARK: | |
11571 | break; | |
11572 | ||
11573 | case ENUMERAL_TYPE: | |
11574 | gen_inlined_enumeration_type_die (type, context_die); | |
11575 | break; | |
11576 | ||
11577 | case RECORD_TYPE: | |
11578 | gen_inlined_structure_type_die (type, context_die); | |
11579 | break; | |
11580 | ||
11581 | case UNION_TYPE: | |
11582 | case QUAL_UNION_TYPE: | |
11583 | gen_inlined_union_type_die (type, context_die); | |
11584 | break; | |
11585 | ||
11586 | default: | |
71dfc51f | 11587 | abort (); |
a3f97cbb JW |
11588 | } |
11589 | } | |
11590 | ||
11591 | /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the | |
11592 | things which are local to the given block. */ | |
71dfc51f | 11593 | |
a3f97cbb | 11594 | static void |
7080f735 | 11595 | gen_block_die (tree stmt, dw_die_ref context_die, int depth) |
a3f97cbb | 11596 | { |
b3694847 SS |
11597 | int must_output_die = 0; |
11598 | tree origin; | |
11599 | tree decl; | |
11600 | enum tree_code origin_code; | |
a3f97cbb JW |
11601 | |
11602 | /* Ignore blocks never really used to make RTL. */ | |
1e7f092a JM |
11603 | if (stmt == NULL_TREE || !TREE_USED (stmt) |
11604 | || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt))) | |
71dfc51f | 11605 | return; |
a3f97cbb | 11606 | |
a20612aa RH |
11607 | /* If the block is one fragment of a non-contiguous block, do not |
11608 | process the variables, since they will have been done by the | |
11609 | origin block. Do process subblocks. */ | |
11610 | if (BLOCK_FRAGMENT_ORIGIN (stmt)) | |
11611 | { | |
11612 | tree sub; | |
11613 | ||
2ad9852d | 11614 | for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub)) |
a20612aa | 11615 | gen_block_die (sub, context_die, depth + 1); |
2ad9852d | 11616 | |
a20612aa RH |
11617 | return; |
11618 | } | |
11619 | ||
a3f97cbb JW |
11620 | /* Determine the "ultimate origin" of this block. This block may be an |
11621 | inlined instance of an inlined instance of inline function, so we have | |
11622 | to trace all of the way back through the origin chain to find out what | |
11623 | sort of node actually served as the original seed for the creation of | |
11624 | the current block. */ | |
11625 | origin = block_ultimate_origin (stmt); | |
11626 | origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; | |
11627 | ||
11628 | /* Determine if we need to output any Dwarf DIEs at all to represent this | |
11629 | block. */ | |
11630 | if (origin_code == FUNCTION_DECL) | |
71dfc51f RK |
11631 | /* The outer scopes for inlinings *must* always be represented. We |
11632 | generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */ | |
11633 | must_output_die = 1; | |
a3f97cbb JW |
11634 | else |
11635 | { | |
11636 | /* In the case where the current block represents an inlining of the | |
73c68f61 SS |
11637 | "body block" of an inline function, we must *NOT* output any DIE for |
11638 | this block because we have already output a DIE to represent the whole | |
11639 | inlined function scope and the "body block" of any function doesn't | |
11640 | really represent a different scope according to ANSI C rules. So we | |
11641 | check here to make sure that this block does not represent a "body | |
11642 | block inlining" before trying to set the MUST_OUTPUT_DIE flag. */ | |
d7248bff | 11643 | if (! is_body_block (origin ? origin : stmt)) |
a3f97cbb JW |
11644 | { |
11645 | /* Determine if this block directly contains any "significant" | |
11646 | local declarations which we will need to output DIEs for. */ | |
11647 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
71dfc51f RK |
11648 | /* We are not in terse mode so *any* local declaration counts |
11649 | as being a "significant" one. */ | |
11650 | must_output_die = (BLOCK_VARS (stmt) != NULL); | |
a3f97cbb | 11651 | else |
71dfc51f RK |
11652 | /* We are in terse mode, so only local (nested) function |
11653 | definitions count as "significant" local declarations. */ | |
11654 | for (decl = BLOCK_VARS (stmt); | |
11655 | decl != NULL; decl = TREE_CHAIN (decl)) | |
11656 | if (TREE_CODE (decl) == FUNCTION_DECL | |
11657 | && DECL_INITIAL (decl)) | |
a3f97cbb | 11658 | { |
71dfc51f RK |
11659 | must_output_die = 1; |
11660 | break; | |
a3f97cbb | 11661 | } |
a3f97cbb JW |
11662 | } |
11663 | } | |
11664 | ||
11665 | /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block | |
11666 | DIE for any block which contains no significant local declarations at | |
11667 | all. Rather, in such cases we just call `decls_for_scope' so that any | |
11668 | needed Dwarf info for any sub-blocks will get properly generated. Note | |
11669 | that in terse mode, our definition of what constitutes a "significant" | |
11670 | local declaration gets restricted to include only inlined function | |
11671 | instances and local (nested) function definitions. */ | |
11672 | if (must_output_die) | |
11673 | { | |
11674 | if (origin_code == FUNCTION_DECL) | |
71dfc51f | 11675 | gen_inlined_subroutine_die (stmt, context_die, depth); |
a3f97cbb | 11676 | else |
71dfc51f | 11677 | gen_lexical_block_die (stmt, context_die, depth); |
a3f97cbb JW |
11678 | } |
11679 | else | |
d7248bff | 11680 | decls_for_scope (stmt, context_die, depth); |
a3f97cbb JW |
11681 | } |
11682 | ||
11683 | /* Generate all of the decls declared within a given scope and (recursively) | |
9ec36da5 | 11684 | all of its sub-blocks. */ |
71dfc51f | 11685 | |
a3f97cbb | 11686 | static void |
7080f735 | 11687 | decls_for_scope (tree stmt, dw_die_ref context_die, int depth) |
a3f97cbb | 11688 | { |
b3694847 SS |
11689 | tree decl; |
11690 | tree subblocks; | |
71dfc51f | 11691 | |
a3f97cbb | 11692 | /* Ignore blocks never really used to make RTL. */ |
71dfc51f RK |
11693 | if (stmt == NULL_TREE || ! TREE_USED (stmt)) |
11694 | return; | |
11695 | ||
88dad228 JM |
11696 | /* Output the DIEs to represent all of the data objects and typedefs |
11697 | declared directly within this block but not within any nested | |
11698 | sub-blocks. Also, nested function and tag DIEs have been | |
11699 | generated with a parent of NULL; fix that up now. */ | |
2ad9852d | 11700 | for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl)) |
a3f97cbb | 11701 | { |
b3694847 | 11702 | dw_die_ref die; |
a94dbf2c | 11703 | |
88dad228 | 11704 | if (TREE_CODE (decl) == FUNCTION_DECL) |
a94dbf2c | 11705 | die = lookup_decl_die (decl); |
88dad228 | 11706 | else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)) |
a94dbf2c JM |
11707 | die = lookup_type_die (TREE_TYPE (decl)); |
11708 | else | |
11709 | die = NULL; | |
11710 | ||
71dfc51f | 11711 | if (die != NULL && die->die_parent == NULL) |
ef76d03b | 11712 | add_child_die (context_die, die); |
88dad228 JM |
11713 | else |
11714 | gen_decl_die (decl, context_die); | |
a3f97cbb JW |
11715 | } |
11716 | ||
8cadae7e JM |
11717 | /* If we're at -g1, we're not interested in subblocks. */ |
11718 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
11719 | return; | |
11720 | ||
a3f97cbb JW |
11721 | /* Output the DIEs to represent all sub-blocks (and the items declared |
11722 | therein) of this block. */ | |
11723 | for (subblocks = BLOCK_SUBBLOCKS (stmt); | |
11724 | subblocks != NULL; | |
11725 | subblocks = BLOCK_CHAIN (subblocks)) | |
71dfc51f | 11726 | gen_block_die (subblocks, context_die, depth + 1); |
a3f97cbb JW |
11727 | } |
11728 | ||
a94dbf2c | 11729 | /* Is this a typedef we can avoid emitting? */ |
71dfc51f RK |
11730 | |
11731 | static inline int | |
7080f735 | 11732 | is_redundant_typedef (tree decl) |
a94dbf2c JM |
11733 | { |
11734 | if (TYPE_DECL_IS_STUB (decl)) | |
11735 | return 1; | |
71dfc51f | 11736 | |
a94dbf2c JM |
11737 | if (DECL_ARTIFICIAL (decl) |
11738 | && DECL_CONTEXT (decl) | |
11739 | && is_tagged_type (DECL_CONTEXT (decl)) | |
11740 | && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL | |
11741 | && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) | |
11742 | /* Also ignore the artificial member typedef for the class name. */ | |
11743 | return 1; | |
71dfc51f | 11744 | |
a94dbf2c JM |
11745 | return 0; |
11746 | } | |
11747 | ||
a3f97cbb | 11748 | /* Generate Dwarf debug information for a decl described by DECL. */ |
71dfc51f | 11749 | |
a3f97cbb | 11750 | static void |
7080f735 | 11751 | gen_decl_die (tree decl, dw_die_ref context_die) |
a3f97cbb | 11752 | { |
b3694847 | 11753 | tree origin; |
71dfc51f | 11754 | |
f11c3043 | 11755 | if (DECL_P (decl) && DECL_IGNORED_P (decl)) |
71dfc51f | 11756 | return; |
a3f97cbb | 11757 | |
a3f97cbb JW |
11758 | switch (TREE_CODE (decl)) |
11759 | { | |
2ad9852d RK |
11760 | case ERROR_MARK: |
11761 | break; | |
11762 | ||
a3f97cbb | 11763 | case CONST_DECL: |
556273e0 | 11764 | /* The individual enumerators of an enum type get output when we output |
73c68f61 | 11765 | the Dwarf representation of the relevant enum type itself. */ |
a3f97cbb JW |
11766 | break; |
11767 | ||
11768 | case FUNCTION_DECL: | |
4edb7b60 JM |
11769 | /* Don't output any DIEs to represent mere function declarations, |
11770 | unless they are class members or explicit block externs. */ | |
11771 | if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE | |
777ad4c2 | 11772 | && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl))) |
71dfc51f | 11773 | break; |
bdb669cb | 11774 | |
5daf7c0a JM |
11775 | /* If we're emitting a clone, emit info for the abstract instance. */ |
11776 | if (DECL_ORIGIN (decl) != decl) | |
11777 | dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl)); | |
2ad9852d | 11778 | |
1cfdcc15 JM |
11779 | /* If we're emitting an out-of-line copy of an inline function, |
11780 | emit info for the abstract instance and set up to refer to it. */ | |
5daf7c0a JM |
11781 | else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl) |
11782 | && ! class_scope_p (context_die) | |
11783 | /* dwarf2out_abstract_function won't emit a die if this is just | |
11784 | a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in | |
11785 | that case, because that works only if we have a die. */ | |
11786 | && DECL_INITIAL (decl) != NULL_TREE) | |
1cfdcc15 | 11787 | { |
1edf43d6 | 11788 | dwarf2out_abstract_function (decl); |
1cfdcc15 JM |
11789 | set_decl_origin_self (decl); |
11790 | } | |
2ad9852d | 11791 | |
5daf7c0a JM |
11792 | /* Otherwise we're emitting the primary DIE for this decl. */ |
11793 | else if (debug_info_level > DINFO_LEVEL_TERSE) | |
a94dbf2c JM |
11794 | { |
11795 | /* Before we describe the FUNCTION_DECL itself, make sure that we | |
11796 | have described its return type. */ | |
11797 | gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); | |
11798 | ||
2081603c JM |
11799 | /* And its virtual context. */ |
11800 | if (DECL_VINDEX (decl) != NULL_TREE) | |
11801 | gen_type_die (DECL_CONTEXT (decl), context_die); | |
11802 | ||
a94dbf2c JM |
11803 | /* And its containing type. */ |
11804 | origin = decl_class_context (decl); | |
71dfc51f | 11805 | if (origin != NULL_TREE) |
10a11b75 | 11806 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 11807 | } |
a3f97cbb JW |
11808 | |
11809 | /* Now output a DIE to represent the function itself. */ | |
11810 | gen_subprogram_die (decl, context_die); | |
11811 | break; | |
11812 | ||
11813 | case TYPE_DECL: | |
11814 | /* If we are in terse mode, don't generate any DIEs to represent any | |
73c68f61 | 11815 | actual typedefs. */ |
a3f97cbb | 11816 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 11817 | break; |
a3f97cbb | 11818 | |
2ad9852d | 11819 | /* In the special case of a TYPE_DECL node representing the declaration |
73c68f61 SS |
11820 | of some type tag, if the given TYPE_DECL is marked as having been |
11821 | instantiated from some other (original) TYPE_DECL node (e.g. one which | |
11822 | was generated within the original definition of an inline function) we | |
11823 | have to generate a special (abbreviated) DW_TAG_structure_type, | |
11824 | DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */ | |
2081603c | 11825 | if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE) |
a3f97cbb JW |
11826 | { |
11827 | gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die); | |
11828 | break; | |
11829 | } | |
a3f97cbb | 11830 | |
a94dbf2c JM |
11831 | if (is_redundant_typedef (decl)) |
11832 | gen_type_die (TREE_TYPE (decl), context_die); | |
11833 | else | |
71dfc51f RK |
11834 | /* Output a DIE to represent the typedef itself. */ |
11835 | gen_typedef_die (decl, context_die); | |
a3f97cbb JW |
11836 | break; |
11837 | ||
11838 | case LABEL_DECL: | |
11839 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
71dfc51f | 11840 | gen_label_die (decl, context_die); |
a3f97cbb JW |
11841 | break; |
11842 | ||
11843 | case VAR_DECL: | |
11844 | /* If we are in terse mode, don't generate any DIEs to represent any | |
73c68f61 | 11845 | variable declarations or definitions. */ |
a3f97cbb | 11846 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 11847 | break; |
a3f97cbb JW |
11848 | |
11849 | /* Output any DIEs that are needed to specify the type of this data | |
73c68f61 | 11850 | object. */ |
a3f97cbb JW |
11851 | gen_type_die (TREE_TYPE (decl), context_die); |
11852 | ||
a94dbf2c JM |
11853 | /* And its containing type. */ |
11854 | origin = decl_class_context (decl); | |
71dfc51f | 11855 | if (origin != NULL_TREE) |
10a11b75 | 11856 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 11857 | |
a3f97cbb | 11858 | /* Now output the DIE to represent the data object itself. This gets |
73c68f61 SS |
11859 | complicated because of the possibility that the VAR_DECL really |
11860 | represents an inlined instance of a formal parameter for an inline | |
11861 | function. */ | |
a3f97cbb | 11862 | origin = decl_ultimate_origin (decl); |
71dfc51f RK |
11863 | if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL) |
11864 | gen_formal_parameter_die (decl, context_die); | |
a3f97cbb | 11865 | else |
71dfc51f | 11866 | gen_variable_die (decl, context_die); |
a3f97cbb JW |
11867 | break; |
11868 | ||
11869 | case FIELD_DECL: | |
2ad9852d RK |
11870 | /* Ignore the nameless fields that are used to skip bits but handle C++ |
11871 | anonymous unions. */ | |
71dfc51f RK |
11872 | if (DECL_NAME (decl) != NULL_TREE |
11873 | || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE) | |
a3f97cbb JW |
11874 | { |
11875 | gen_type_die (member_declared_type (decl), context_die); | |
11876 | gen_field_die (decl, context_die); | |
11877 | } | |
11878 | break; | |
11879 | ||
11880 | case PARM_DECL: | |
11881 | gen_type_die (TREE_TYPE (decl), context_die); | |
11882 | gen_formal_parameter_die (decl, context_die); | |
11883 | break; | |
11884 | ||
348bb3c7 JM |
11885 | case NAMESPACE_DECL: |
11886 | /* Ignore for now. */ | |
11887 | break; | |
11888 | ||
a3f97cbb | 11889 | default: |
ae0e5982 JM |
11890 | if ((int)TREE_CODE (decl) > NUM_TREE_CODES) |
11891 | /* Probably some frontend-internal decl. Assume we don't care. */ | |
11892 | break; | |
a3f97cbb JW |
11893 | abort (); |
11894 | } | |
a3f97cbb JW |
11895 | } |
11896 | \f | |
14a774a9 RK |
11897 | /* Add Ada "use" clause information for SGI Workshop debugger. */ |
11898 | ||
11899 | void | |
7080f735 | 11900 | dwarf2out_add_library_unit_info (const char *filename, const char *context_list) |
14a774a9 RK |
11901 | { |
11902 | unsigned int file_index; | |
11903 | ||
11904 | if (filename != NULL) | |
11905 | { | |
54ba1f0d | 11906 | dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL); |
556273e0 | 11907 | tree context_list_decl |
14a774a9 RK |
11908 | = build_decl (LABEL_DECL, get_identifier (context_list), |
11909 | void_type_node); | |
11910 | ||
11911 | TREE_PUBLIC (context_list_decl) = TRUE; | |
11912 | add_name_attribute (unit_die, context_list); | |
981975b6 | 11913 | file_index = lookup_filename (filename); |
14a774a9 RK |
11914 | add_AT_unsigned (unit_die, DW_AT_decl_file, file_index); |
11915 | add_pubname (context_list_decl, unit_die); | |
11916 | } | |
11917 | } | |
11918 | ||
2ad9852d | 11919 | /* Output debug information for global decl DECL. Called from toplev.c after |
2b85879e | 11920 | compilation proper has finished. */ |
2ad9852d | 11921 | |
2b85879e | 11922 | static void |
7080f735 | 11923 | dwarf2out_global_decl (tree decl) |
2b85879e NB |
11924 | { |
11925 | /* Output DWARF2 information for file-scope tentative data object | |
2ad9852d RK |
11926 | declarations, file-scope (extern) function declarations (which had no |
11927 | corresponding body) and file-scope tagged type declarations and | |
11928 | definitions which have not yet been forced out. */ | |
2b85879e NB |
11929 | if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)) |
11930 | dwarf2out_decl (decl); | |
11931 | } | |
11932 | ||
71dfc51f RK |
11933 | /* Write the debugging output for DECL. */ |
11934 | ||
a3f97cbb | 11935 | void |
7080f735 | 11936 | dwarf2out_decl (tree decl) |
a3f97cbb | 11937 | { |
b3694847 | 11938 | dw_die_ref context_die = comp_unit_die; |
88dad228 | 11939 | |
a3f97cbb JW |
11940 | switch (TREE_CODE (decl)) |
11941 | { | |
2ad9852d RK |
11942 | case ERROR_MARK: |
11943 | return; | |
11944 | ||
a3f97cbb | 11945 | case FUNCTION_DECL: |
556273e0 | 11946 | /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a |
73c68f61 SS |
11947 | builtin function. Explicit programmer-supplied declarations of |
11948 | these same functions should NOT be ignored however. */ | |
9765e357 | 11949 | if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl)) |
b1ccbc24 | 11950 | return; |
a3f97cbb JW |
11951 | |
11952 | /* What we would really like to do here is to filter out all mere | |
73c68f61 SS |
11953 | file-scope declarations of file-scope functions which are never |
11954 | referenced later within this translation unit (and keep all of ones | |
11955 | that *are* referenced later on) but we aren't clairvoyant, so we have | |
11956 | no idea which functions will be referenced in the future (i.e. later | |
11957 | on within the current translation unit). So here we just ignore all | |
11958 | file-scope function declarations which are not also definitions. If | |
11959 | and when the debugger needs to know something about these functions, | |
11960 | it will have to hunt around and find the DWARF information associated | |
11961 | with the definition of the function. | |
2ad9852d RK |
11962 | |
11963 | We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL | |
73c68f61 SS |
11964 | nodes represent definitions and which ones represent mere |
11965 | declarations. We have to check DECL_INITIAL instead. That's because | |
11966 | the C front-end supports some weird semantics for "extern inline" | |
11967 | function definitions. These can get inlined within the current | |
11968 | translation unit (an thus, we need to generate Dwarf info for their | |
11969 | abstract instances so that the Dwarf info for the concrete inlined | |
11970 | instances can have something to refer to) but the compiler never | |
11971 | generates any out-of-lines instances of such things (despite the fact | |
11972 | that they *are* definitions). | |
2ad9852d RK |
11973 | |
11974 | The important point is that the C front-end marks these "extern | |
11975 | inline" functions as DECL_EXTERNAL, but we need to generate DWARF for | |
11976 | them anyway. Note that the C++ front-end also plays some similar games | |
11977 | for inline function definitions appearing within include files which | |
11978 | also contain `#pragma interface' pragmas. */ | |
a3f97cbb | 11979 | if (DECL_INITIAL (decl) == NULL_TREE) |
b1ccbc24 | 11980 | return; |
88dad228 | 11981 | |
9c6cd30e JM |
11982 | /* If we're a nested function, initially use a parent of NULL; if we're |
11983 | a plain function, this will be fixed up in decls_for_scope. If | |
11984 | we're a method, it will be ignored, since we already have a DIE. */ | |
8cadae7e JM |
11985 | if (decl_function_context (decl) |
11986 | /* But if we're in terse mode, we don't care about scope. */ | |
11987 | && debug_info_level > DINFO_LEVEL_TERSE) | |
9c6cd30e | 11988 | context_die = NULL; |
a3f97cbb JW |
11989 | break; |
11990 | ||
11991 | case VAR_DECL: | |
556273e0 | 11992 | /* Ignore this VAR_DECL if it refers to a file-scope extern data object |
73c68f61 SS |
11993 | declaration and if the declaration was never even referenced from |
11994 | within this entire compilation unit. We suppress these DIEs in | |
11995 | order to save space in the .debug section (by eliminating entries | |
11996 | which are probably useless). Note that we must not suppress | |
11997 | block-local extern declarations (whether used or not) because that | |
11998 | would screw-up the debugger's name lookup mechanism and cause it to | |
11999 | miss things which really ought to be in scope at a given point. */ | |
a3f97cbb | 12000 | if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) |
71dfc51f | 12001 | return; |
a3f97cbb JW |
12002 | |
12003 | /* If we are in terse mode, don't generate any DIEs to represent any | |
73c68f61 | 12004 | variable declarations or definitions. */ |
a3f97cbb | 12005 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 12006 | return; |
a3f97cbb JW |
12007 | break; |
12008 | ||
12009 | case TYPE_DECL: | |
57fb7689 JM |
12010 | /* Don't emit stubs for types unless they are needed by other DIEs. */ |
12011 | if (TYPE_DECL_SUPPRESS_DEBUG (decl)) | |
12012 | return; | |
12013 | ||
a3f97cbb | 12014 | /* Don't bother trying to generate any DIEs to represent any of the |
73c68f61 | 12015 | normal built-in types for the language we are compiling. */ |
a9d38797 | 12016 | if (DECL_SOURCE_LINE (decl) == 0) |
a94dbf2c JM |
12017 | { |
12018 | /* OK, we need to generate one for `bool' so GDB knows what type | |
73c68f61 | 12019 | comparisons have. */ |
a94dbf2c JM |
12020 | if ((get_AT_unsigned (comp_unit_die, DW_AT_language) |
12021 | == DW_LANG_C_plus_plus) | |
f11c3043 RK |
12022 | && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE |
12023 | && ! DECL_IGNORED_P (decl)) | |
a94dbf2c | 12024 | modified_type_die (TREE_TYPE (decl), 0, 0, NULL); |
71dfc51f | 12025 | |
a94dbf2c JM |
12026 | return; |
12027 | } | |
a3f97cbb | 12028 | |
88dad228 | 12029 | /* If we are in terse mode, don't generate any DIEs for types. */ |
a3f97cbb | 12030 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 12031 | return; |
88dad228 JM |
12032 | |
12033 | /* If we're a function-scope tag, initially use a parent of NULL; | |
12034 | this will be fixed up in decls_for_scope. */ | |
12035 | if (decl_function_context (decl)) | |
3f76745e | 12036 | context_die = NULL; |
88dad228 | 12037 | |
a3f97cbb JW |
12038 | break; |
12039 | ||
12040 | default: | |
12041 | return; | |
12042 | } | |
12043 | ||
88dad228 | 12044 | gen_decl_die (decl, context_die); |
a3f97cbb JW |
12045 | } |
12046 | ||
12047 | /* Output a marker (i.e. a label) for the beginning of the generated code for | |
12048 | a lexical block. */ | |
71dfc51f | 12049 | |
a5a42b92 | 12050 | static void |
7080f735 AJ |
12051 | dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED, |
12052 | unsigned int blocknum) | |
a3f97cbb | 12053 | { |
a3f97cbb | 12054 | function_section (current_function_decl); |
8215347e | 12055 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum); |
a3f97cbb JW |
12056 | } |
12057 | ||
12058 | /* Output a marker (i.e. a label) for the end of the generated code for a | |
12059 | lexical block. */ | |
71dfc51f | 12060 | |
a5a42b92 | 12061 | static void |
7080f735 | 12062 | dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum) |
a3f97cbb | 12063 | { |
a3f97cbb | 12064 | function_section (current_function_decl); |
8215347e | 12065 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum); |
a3f97cbb JW |
12066 | } |
12067 | ||
64b59a80 JM |
12068 | /* Returns nonzero if it is appropriate not to emit any debugging |
12069 | information for BLOCK, because it doesn't contain any instructions. | |
fcd7f76b | 12070 | |
64b59a80 JM |
12071 | Don't allow this for blocks with nested functions or local classes |
12072 | as we would end up with orphans, and in the presence of scheduling | |
12073 | we may end up calling them anyway. */ | |
12074 | ||
e1772ac0 | 12075 | static bool |
7080f735 | 12076 | dwarf2out_ignore_block (tree block) |
fcd7f76b JM |
12077 | { |
12078 | tree decl; | |
2ad9852d | 12079 | |
fcd7f76b | 12080 | for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) |
64b59a80 JM |
12081 | if (TREE_CODE (decl) == FUNCTION_DECL |
12082 | || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))) | |
12083 | return 0; | |
2ad9852d | 12084 | |
64b59a80 | 12085 | return 1; |
fcd7f76b JM |
12086 | } |
12087 | ||
2ad9852d | 12088 | /* Lookup FILE_NAME (in the list of filenames that we know about here in |
9a666dda | 12089 | dwarf2out.c) and return its "index". The index of each (known) filename is |
2ad9852d RK |
12090 | just a unique number which is associated with only that one filename. We |
12091 | need such numbers for the sake of generating labels (in the .debug_sfnames | |
12092 | section) and references to those files numbers (in the .debug_srcinfo | |
12093 | and.debug_macinfo sections). If the filename given as an argument is not | |
12094 | found in our current list, add it to the list and assign it the next | |
12095 | available unique index number. In order to speed up searches, we remember | |
12096 | the index of the filename was looked up last. This handles the majority of | |
12097 | all searches. */ | |
71dfc51f | 12098 | |
a3f97cbb | 12099 | static unsigned |
7080f735 | 12100 | lookup_filename (const char *file_name) |
a3f97cbb | 12101 | { |
c4274b22 RH |
12102 | size_t i, n; |
12103 | char *save_file_name; | |
a3f97cbb | 12104 | |
2e18bbae RH |
12105 | /* Check to see if the file name that was searched on the previous |
12106 | call matches this file name. If so, return the index. */ | |
c4274b22 RH |
12107 | if (file_table_last_lookup_index != 0) |
12108 | { | |
12109 | const char *last | |
12110 | = VARRAY_CHAR_PTR (file_table, file_table_last_lookup_index); | |
12111 | if (strcmp (file_name, last) == 0) | |
73c68f61 | 12112 | return file_table_last_lookup_index; |
c4274b22 | 12113 | } |
a3f97cbb JW |
12114 | |
12115 | /* Didn't match the previous lookup, search the table */ | |
c4274b22 RH |
12116 | n = VARRAY_ACTIVE_SIZE (file_table); |
12117 | for (i = 1; i < n; i++) | |
12118 | if (strcmp (file_name, VARRAY_CHAR_PTR (file_table, i)) == 0) | |
71dfc51f | 12119 | { |
c4274b22 | 12120 | file_table_last_lookup_index = i; |
71dfc51f RK |
12121 | return i; |
12122 | } | |
a3f97cbb | 12123 | |
71dfc51f | 12124 | /* Add the new entry to the end of the filename table. */ |
c4274b22 RH |
12125 | file_table_last_lookup_index = n; |
12126 | save_file_name = (char *) ggc_strdup (file_name); | |
12127 | VARRAY_PUSH_CHAR_PTR (file_table, save_file_name); | |
73c68f61 | 12128 | VARRAY_PUSH_UINT (file_table_emitted, 0); |
2e18bbae | 12129 | |
73c68f61 SS |
12130 | return i; |
12131 | } | |
12132 | ||
12133 | static int | |
7080f735 | 12134 | maybe_emit_file (int fileno) |
73c68f61 | 12135 | { |
73c68f61 | 12136 | if (DWARF2_ASM_LINE_DEBUG_INFO && fileno > 0) |
211a0cbe | 12137 | { |
73c68f61 SS |
12138 | if (!VARRAY_UINT (file_table_emitted, fileno)) |
12139 | { | |
12140 | VARRAY_UINT (file_table_emitted, fileno) = ++emitcount; | |
12141 | fprintf (asm_out_file, "\t.file %u ", | |
12142 | VARRAY_UINT (file_table_emitted, fileno)); | |
12143 | output_quoted_string (asm_out_file, | |
12144 | VARRAY_CHAR_PTR (file_table, fileno)); | |
12145 | fputc ('\n', asm_out_file); | |
12146 | } | |
12147 | return VARRAY_UINT (file_table_emitted, fileno); | |
211a0cbe | 12148 | } |
73c68f61 SS |
12149 | else |
12150 | return fileno; | |
2e18bbae RH |
12151 | } |
12152 | ||
12153 | static void | |
7080f735 | 12154 | init_file_table (void) |
2e18bbae RH |
12155 | { |
12156 | /* Allocate the initial hunk of the file_table. */ | |
c4274b22 | 12157 | VARRAY_CHAR_PTR_INIT (file_table, 64, "file_table"); |
73c68f61 | 12158 | VARRAY_UINT_INIT (file_table_emitted, 64, "file_table_emitted"); |
71dfc51f | 12159 | |
2e18bbae | 12160 | /* Skip the first entry - file numbers begin at 1. */ |
c4274b22 | 12161 | VARRAY_PUSH_CHAR_PTR (file_table, NULL); |
73c68f61 | 12162 | VARRAY_PUSH_UINT (file_table_emitted, 0); |
c4274b22 | 12163 | file_table_last_lookup_index = 0; |
a3f97cbb JW |
12164 | } |
12165 | ||
12166 | /* Output a label to mark the beginning of a source code line entry | |
12167 | and record information relating to this source line, in | |
12168 | 'line_info_table' for later output of the .debug_line section. */ | |
71dfc51f | 12169 | |
e2a12aca | 12170 | static void |
7080f735 | 12171 | dwarf2out_source_line (unsigned int line, const char *filename) |
a3f97cbb | 12172 | { |
7bf6b23d JM |
12173 | if (debug_info_level >= DINFO_LEVEL_NORMAL |
12174 | && line != 0) | |
a3f97cbb JW |
12175 | { |
12176 | function_section (current_function_decl); | |
a3f97cbb | 12177 | |
8aaf55ac JM |
12178 | /* If requested, emit something human-readable. */ |
12179 | if (flag_debug_asm) | |
12180 | fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, | |
12181 | filename, line); | |
12182 | ||
b2244e22 JW |
12183 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
12184 | { | |
981975b6 | 12185 | unsigned file_num = lookup_filename (filename); |
b2244e22 | 12186 | |
73c68f61 SS |
12187 | file_num = maybe_emit_file (file_num); |
12188 | ||
981975b6 | 12189 | /* Emit the .loc directive understood by GNU as. */ |
2e18bbae | 12190 | fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line); |
b2244e22 JW |
12191 | |
12192 | /* Indicate that line number info exists. */ | |
2ad9852d | 12193 | line_info_table_in_use++; |
b2244e22 JW |
12194 | |
12195 | /* Indicate that multiple line number tables exist. */ | |
12196 | if (DECL_SECTION_NAME (current_function_decl)) | |
2ad9852d | 12197 | separate_line_info_table_in_use++; |
b2244e22 JW |
12198 | } |
12199 | else if (DECL_SECTION_NAME (current_function_decl)) | |
a3f97cbb | 12200 | { |
b3694847 | 12201 | dw_separate_line_info_ref line_info; |
4977bab6 | 12202 | (*targetm.asm_out.internal_label) (asm_out_file, SEPARATE_LINE_CODE_LABEL, |
5c90448c | 12203 | separate_line_info_table_in_use); |
e90b62db JM |
12204 | |
12205 | /* expand the line info table if necessary */ | |
12206 | if (separate_line_info_table_in_use | |
12207 | == separate_line_info_table_allocated) | |
12208 | { | |
12209 | separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
12210 | separate_line_info_table | |
703ad42b | 12211 | = ggc_realloc (separate_line_info_table, |
17211ab5 GK |
12212 | separate_line_info_table_allocated |
12213 | * sizeof (dw_separate_line_info_entry)); | |
703ad42b KG |
12214 | memset (separate_line_info_table |
12215 | + separate_line_info_table_in_use, | |
17211ab5 | 12216 | 0, |
7080f735 | 12217 | (LINE_INFO_TABLE_INCREMENT |
17211ab5 | 12218 | * sizeof (dw_separate_line_info_entry))); |
e90b62db | 12219 | } |
71dfc51f RK |
12220 | |
12221 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
12222 | line_info |
12223 | = &separate_line_info_table[separate_line_info_table_in_use++]; | |
981975b6 | 12224 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db | 12225 | line_info->dw_line_num = line; |
df696a75 | 12226 | line_info->function = current_function_funcdef_no; |
e90b62db JM |
12227 | } |
12228 | else | |
12229 | { | |
b3694847 | 12230 | dw_line_info_ref line_info; |
71dfc51f | 12231 | |
4977bab6 | 12232 | (*targetm.asm_out.internal_label) (asm_out_file, LINE_CODE_LABEL, |
5c90448c | 12233 | line_info_table_in_use); |
e90b62db | 12234 | |
71dfc51f | 12235 | /* Expand the line info table if necessary. */ |
e90b62db JM |
12236 | if (line_info_table_in_use == line_info_table_allocated) |
12237 | { | |
12238 | line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
12239 | line_info_table | |
17211ab5 GK |
12240 | = ggc_realloc (line_info_table, |
12241 | (line_info_table_allocated | |
12242 | * sizeof (dw_line_info_entry))); | |
12243 | memset (line_info_table + line_info_table_in_use, 0, | |
12244 | LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry)); | |
e90b62db | 12245 | } |
71dfc51f RK |
12246 | |
12247 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db | 12248 | line_info = &line_info_table[line_info_table_in_use++]; |
981975b6 | 12249 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db | 12250 | line_info->dw_line_num = line; |
a3f97cbb | 12251 | } |
a3f97cbb JW |
12252 | } |
12253 | } | |
12254 | ||
30f7a378 | 12255 | /* Record the beginning of a new source file. */ |
71dfc51f | 12256 | |
7f905405 | 12257 | static void |
7080f735 | 12258 | dwarf2out_start_source_file (unsigned int lineno, const char *filename) |
a3f97cbb | 12259 | { |
cc0017a9 | 12260 | if (flag_eliminate_dwarf2_dups && !is_main_source) |
881c6935 JM |
12261 | { |
12262 | /* Record the beginning of the file for break_out_includes. */ | |
cc0017a9 ZD |
12263 | dw_die_ref bincl_die; |
12264 | ||
12265 | bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL); | |
881c6935 JM |
12266 | add_AT_string (bincl_die, DW_AT_name, filename); |
12267 | } | |
2ad9852d | 12268 | |
cc0017a9 ZD |
12269 | is_main_source = 0; |
12270 | ||
84a5b4f8 DB |
12271 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12272 | { | |
715bdd29 | 12273 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 | 12274 | dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file"); |
7c262518 RH |
12275 | dw2_asm_output_data_uleb128 (lineno, "Included from line number %d", |
12276 | lineno); | |
73c68f61 | 12277 | maybe_emit_file (lookup_filename (filename)); |
7c262518 RH |
12278 | dw2_asm_output_data_uleb128 (lookup_filename (filename), |
12279 | "Filename we just started"); | |
84a5b4f8 | 12280 | } |
a3f97cbb JW |
12281 | } |
12282 | ||
cc260610 | 12283 | /* Record the end of a source file. */ |
71dfc51f | 12284 | |
7f905405 | 12285 | static void |
7080f735 | 12286 | dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED) |
a3f97cbb | 12287 | { |
881c6935 | 12288 | if (flag_eliminate_dwarf2_dups) |
2ad9852d | 12289 | /* Record the end of the file for break_out_includes. */ |
54ba1f0d | 12290 | new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL); |
2ad9852d | 12291 | |
84a5b4f8 DB |
12292 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12293 | { | |
715bdd29 | 12294 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
12295 | dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); |
12296 | } | |
a3f97cbb JW |
12297 | } |
12298 | ||
cc260610 | 12299 | /* Called from debug_define in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
12300 | the tail part of the directive line, i.e. the part which is past the |
12301 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 12302 | |
7f905405 | 12303 | static void |
7080f735 AJ |
12304 | dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED, |
12305 | const char *buffer ATTRIBUTE_UNUSED) | |
a3f97cbb | 12306 | { |
84a5b4f8 DB |
12307 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12308 | { | |
715bdd29 | 12309 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
12310 | dw2_asm_output_data (1, DW_MACINFO_define, "Define macro"); |
12311 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
12312 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
12313 | } | |
a3f97cbb JW |
12314 | } |
12315 | ||
cc260610 | 12316 | /* Called from debug_undef in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
12317 | the tail part of the directive line, i.e. the part which is past the |
12318 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 12319 | |
7f905405 | 12320 | static void |
7080f735 AJ |
12321 | dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED, |
12322 | const char *buffer ATTRIBUTE_UNUSED) | |
a3f97cbb | 12323 | { |
84a5b4f8 DB |
12324 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12325 | { | |
715bdd29 | 12326 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
12327 | dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro"); |
12328 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
12329 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
12330 | } | |
a3f97cbb JW |
12331 | } |
12332 | ||
12333 | /* Set up for Dwarf output at the start of compilation. */ | |
71dfc51f | 12334 | |
a51d908e | 12335 | static void |
7080f735 | 12336 | dwarf2out_init (const char *filename ATTRIBUTE_UNUSED) |
a3f97cbb | 12337 | { |
acc187f5 RH |
12338 | init_file_table (); |
12339 | ||
a3f97cbb | 12340 | /* Allocate the initial hunk of the decl_die_table. */ |
7080f735 | 12341 | decl_die_table = ggc_alloc_cleared (DECL_DIE_TABLE_INCREMENT |
17211ab5 | 12342 | * sizeof (dw_die_ref)); |
a3f97cbb JW |
12343 | decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT; |
12344 | decl_die_table_in_use = 0; | |
12345 | ||
12346 | /* Allocate the initial hunk of the decl_scope_table. */ | |
244a4af0 | 12347 | VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table"); |
a3f97cbb JW |
12348 | |
12349 | /* Allocate the initial hunk of the abbrev_die_table. */ | |
17211ab5 GK |
12350 | abbrev_die_table = ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT |
12351 | * sizeof (dw_die_ref)); | |
a3f97cbb | 12352 | abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT; |
71dfc51f | 12353 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
12354 | abbrev_die_table_in_use = 1; |
12355 | ||
12356 | /* Allocate the initial hunk of the line_info_table. */ | |
17211ab5 GK |
12357 | line_info_table = ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT |
12358 | * sizeof (dw_line_info_entry)); | |
a3f97cbb | 12359 | line_info_table_allocated = LINE_INFO_TABLE_INCREMENT; |
2ad9852d | 12360 | |
71dfc51f | 12361 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
12362 | line_info_table_in_use = 1; |
12363 | ||
556273e0 | 12364 | /* Generate the initial DIE for the .debug section. Note that the (string) |
a3f97cbb | 12365 | value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE |
556273e0 | 12366 | will (typically) be a relative pathname and that this pathname should be |
a3f97cbb | 12367 | taken as being relative to the directory from which the compiler was |
c4274b22 RH |
12368 | invoked when the given (base) source file was compiled. We will fill |
12369 | in this value in dwarf2out_finish. */ | |
12370 | comp_unit_die = gen_compile_unit_die (NULL); | |
cc0017a9 | 12371 | is_main_source = 1; |
a3f97cbb | 12372 | |
244a4af0 | 12373 | VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types"); |
244a4af0 | 12374 | |
1f8f4a0b | 12375 | VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray"); |
1865dbb5 | 12376 | |
5c90448c | 12377 | ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0); |
9d2f2c45 RH |
12378 | ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, |
12379 | DEBUG_ABBREV_SECTION_LABEL, 0); | |
b366352b MM |
12380 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) |
12381 | ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0); | |
12382 | else | |
f99ffb60 | 12383 | strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME)); |
2ad9852d | 12384 | |
556273e0 | 12385 | ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label, |
8b790721 | 12386 | DEBUG_INFO_SECTION_LABEL, 0); |
556273e0 | 12387 | ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label, |
8b790721 | 12388 | DEBUG_LINE_SECTION_LABEL, 0); |
2bee6045 JJ |
12389 | ASM_GENERATE_INTERNAL_LABEL (ranges_section_label, |
12390 | DEBUG_RANGES_SECTION_LABEL, 0); | |
715bdd29 | 12391 | named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG); |
8b790721 | 12392 | ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label); |
715bdd29 | 12393 | named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG); |
8b790721 | 12394 | ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label); |
715bdd29 | 12395 | named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG); |
8b790721 | 12396 | ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label); |
2ad9852d | 12397 | |
84a5b4f8 DB |
12398 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12399 | { | |
715bdd29 | 12400 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
12401 | ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label, |
12402 | DEBUG_MACINFO_SECTION_LABEL, 0); | |
12403 | ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label); | |
12404 | } | |
7c262518 RH |
12405 | |
12406 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) | |
12407 | { | |
12408 | text_section (); | |
12409 | ASM_OUTPUT_LABEL (asm_out_file, text_section_label); | |
12410 | } | |
a3f97cbb JW |
12411 | } |
12412 | ||
9eb4015a JJ |
12413 | /* A helper function for dwarf2out_finish called through |
12414 | ht_forall. Emit one queued .debug_str string. */ | |
12415 | ||
12416 | static int | |
7080f735 | 12417 | output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED) |
9eb4015a | 12418 | { |
17211ab5 | 12419 | struct indirect_string_node *node = (struct indirect_string_node *) *h; |
9eb4015a | 12420 | |
9eb4015a JJ |
12421 | if (node->form == DW_FORM_strp) |
12422 | { | |
12423 | named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS); | |
12424 | ASM_OUTPUT_LABEL (asm_out_file, node->label); | |
17211ab5 | 12425 | assemble_string (node->str, strlen (node->str) + 1); |
9eb4015a | 12426 | } |
2ad9852d | 12427 | |
9eb4015a JJ |
12428 | return 1; |
12429 | } | |
12430 | ||
73c68f61 SS |
12431 | |
12432 | ||
12433 | /* Clear the marks for a die and its children. | |
3dc575ff | 12434 | Be cool if the mark isn't set. */ |
73c68f61 SS |
12435 | |
12436 | static void | |
7080f735 | 12437 | prune_unmark_dies (dw_die_ref die) |
73c68f61 SS |
12438 | { |
12439 | dw_die_ref c; | |
12440 | die->die_mark = 0; | |
12441 | for (c = die->die_child; c; c = c->die_sib) | |
12442 | prune_unmark_dies (c); | |
12443 | } | |
12444 | ||
12445 | ||
12446 | /* Given DIE that we're marking as used, find any other dies | |
12447 | it references as attributes and mark them as used. */ | |
12448 | ||
12449 | static void | |
7080f735 | 12450 | prune_unused_types_walk_attribs (dw_die_ref die) |
73c68f61 SS |
12451 | { |
12452 | dw_attr_ref a; | |
12453 | ||
12454 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
12455 | { | |
12456 | if (a->dw_attr_val.val_class == dw_val_class_die_ref) | |
12457 | { | |
12458 | /* A reference to another DIE. | |
12459 | Make sure that it will get emitted. */ | |
12460 | prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1); | |
12461 | } | |
12462 | else if (a->dw_attr == DW_AT_decl_file) | |
12463 | { | |
12464 | /* A reference to a file. Make sure the file name is emitted. */ | |
12465 | a->dw_attr_val.v.val_unsigned = | |
12466 | maybe_emit_file (a->dw_attr_val.v.val_unsigned); | |
12467 | } | |
12468 | } | |
12469 | } | |
12470 | ||
12471 | ||
12472 | /* Mark DIE as being used. If DOKIDS is true, then walk down | |
12473 | to DIE's children. */ | |
12474 | ||
12475 | static void | |
7080f735 | 12476 | prune_unused_types_mark (dw_die_ref die, int dokids) |
73c68f61 SS |
12477 | { |
12478 | dw_die_ref c; | |
12479 | ||
12480 | if (die->die_mark == 0) | |
12481 | { | |
12482 | /* We haven't done this node yet. Mark it as used. */ | |
12483 | die->die_mark = 1; | |
12484 | ||
12485 | /* We also have to mark its parents as used. | |
12486 | (But we don't want to mark our parents' kids due to this.) */ | |
12487 | if (die->die_parent) | |
12488 | prune_unused_types_mark (die->die_parent, 0); | |
12489 | ||
12490 | /* Mark any referenced nodes. */ | |
12491 | prune_unused_types_walk_attribs (die); | |
12492 | } | |
12493 | ||
12494 | if (dokids && die->die_mark != 2) | |
12495 | { | |
12496 | /* We need to walk the children, but haven't done so yet. | |
12497 | Remember that we've walked the kids. */ | |
12498 | die->die_mark = 2; | |
12499 | ||
12500 | /* Walk them. */ | |
12501 | for (c = die->die_child; c; c = c->die_sib) | |
12502 | { | |
12503 | /* If this is an array type, we need to make sure our | |
3dc575ff | 12504 | kids get marked, even if they're types. */ |
73c68f61 SS |
12505 | if (die->die_tag == DW_TAG_array_type) |
12506 | prune_unused_types_mark (c, 1); | |
12507 | else | |
12508 | prune_unused_types_walk (c); | |
12509 | } | |
12510 | } | |
12511 | } | |
12512 | ||
12513 | ||
12514 | /* Walk the tree DIE and mark types that we actually use. */ | |
12515 | ||
12516 | static void | |
7080f735 | 12517 | prune_unused_types_walk (dw_die_ref die) |
73c68f61 SS |
12518 | { |
12519 | dw_die_ref c; | |
12520 | ||
12521 | /* Don't do anything if this node is already marked. */ | |
12522 | if (die->die_mark) | |
12523 | return; | |
12524 | ||
12525 | switch (die->die_tag) { | |
12526 | case DW_TAG_const_type: | |
12527 | case DW_TAG_packed_type: | |
12528 | case DW_TAG_pointer_type: | |
12529 | case DW_TAG_reference_type: | |
12530 | case DW_TAG_volatile_type: | |
12531 | case DW_TAG_typedef: | |
12532 | case DW_TAG_array_type: | |
12533 | case DW_TAG_structure_type: | |
12534 | case DW_TAG_union_type: | |
12535 | case DW_TAG_class_type: | |
12536 | case DW_TAG_friend: | |
12537 | case DW_TAG_variant_part: | |
12538 | case DW_TAG_enumeration_type: | |
12539 | case DW_TAG_subroutine_type: | |
12540 | case DW_TAG_string_type: | |
12541 | case DW_TAG_set_type: | |
12542 | case DW_TAG_subrange_type: | |
12543 | case DW_TAG_ptr_to_member_type: | |
12544 | case DW_TAG_file_type: | |
12545 | /* It's a type node --- don't mark it. */ | |
12546 | return; | |
12547 | ||
12548 | default: | |
12549 | /* Mark everything else. */ | |
12550 | break; | |
12551 | } | |
12552 | ||
12553 | die->die_mark = 1; | |
12554 | ||
12555 | /* Now, mark any dies referenced from here. */ | |
12556 | prune_unused_types_walk_attribs (die); | |
12557 | ||
12558 | /* Mark children. */ | |
12559 | for (c = die->die_child; c; c = c->die_sib) | |
12560 | prune_unused_types_walk (c); | |
12561 | } | |
12562 | ||
12563 | ||
12564 | /* Remove from the tree DIE any dies that aren't marked. */ | |
12565 | ||
12566 | static void | |
7080f735 | 12567 | prune_unused_types_prune (dw_die_ref die) |
73c68f61 SS |
12568 | { |
12569 | dw_die_ref c, p, n; | |
12570 | if (!die->die_mark) | |
12571 | abort(); | |
12572 | ||
12573 | p = NULL; | |
12574 | for (c = die->die_child; c; c = n) | |
12575 | { | |
12576 | n = c->die_sib; | |
12577 | if (c->die_mark) | |
12578 | { | |
12579 | prune_unused_types_prune (c); | |
12580 | p = c; | |
12581 | } | |
12582 | else | |
12583 | { | |
12584 | if (p) | |
12585 | p->die_sib = n; | |
12586 | else | |
12587 | die->die_child = n; | |
12588 | free_die (c); | |
12589 | } | |
12590 | } | |
12591 | } | |
12592 | ||
12593 | ||
12594 | /* Remove dies representing declarations that we never use. */ | |
12595 | ||
12596 | static void | |
7080f735 | 12597 | prune_unused_types (void) |
73c68f61 SS |
12598 | { |
12599 | unsigned int i; | |
12600 | limbo_die_node *node; | |
12601 | ||
12602 | /* Clear all the marks. */ | |
12603 | prune_unmark_dies (comp_unit_die); | |
12604 | for (node = limbo_die_list; node; node = node->next) | |
12605 | prune_unmark_dies (node->die); | |
12606 | ||
12607 | /* Set the mark on nodes that are actually used. */ | |
12608 | prune_unused_types_walk (comp_unit_die); | |
12609 | for (node = limbo_die_list; node; node = node->next) | |
12610 | prune_unused_types_walk (node->die); | |
12611 | ||
12612 | /* Also set the mark on nodes referenced from the | |
12613 | pubname_table or arange_table. */ | |
6a87d634 RS |
12614 | for (i = 0; i < pubname_table_in_use; i++) |
12615 | prune_unused_types_mark (pubname_table[i].die, 1); | |
12616 | for (i = 0; i < arange_table_in_use; i++) | |
12617 | prune_unused_types_mark (arange_table[i], 1); | |
73c68f61 SS |
12618 | |
12619 | /* Get rid of nodes that aren't marked. */ | |
12620 | prune_unused_types_prune (comp_unit_die); | |
12621 | for (node = limbo_die_list; node; node = node->next) | |
12622 | prune_unused_types_prune (node->die); | |
12623 | ||
12624 | /* Leave the marks clear. */ | |
12625 | prune_unmark_dies (comp_unit_die); | |
12626 | for (node = limbo_die_list; node; node = node->next) | |
12627 | prune_unmark_dies (node->die); | |
12628 | } | |
12629 | ||
a3f97cbb JW |
12630 | /* Output stuff that dwarf requires at the end of every file, |
12631 | and generate the DWARF-2 debugging info. */ | |
71dfc51f | 12632 | |
a51d908e | 12633 | static void |
7080f735 | 12634 | dwarf2out_finish (const char *filename) |
a3f97cbb | 12635 | { |
ef76d03b | 12636 | limbo_die_node *node, *next_node; |
ae0ed63a | 12637 | dw_die_ref die = 0; |
ef76d03b | 12638 | |
c4274b22 RH |
12639 | /* Add the name for the main input file now. We delayed this from |
12640 | dwarf2out_init to avoid complications with PCH. */ | |
3b895f8e NS |
12641 | add_name_attribute (comp_unit_die, filename); |
12642 | if (filename[0] != DIR_SEPARATOR) | |
c4274b22 | 12643 | add_comp_dir_attribute (comp_unit_die); |
79c758fb JJ |
12644 | else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL) |
12645 | { | |
12646 | size_t i; | |
12647 | for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++) | |
e3091a5f R |
12648 | if (VARRAY_CHAR_PTR (file_table, i)[0] != DIR_SEPARATOR |
12649 | /* Don't add cwd for <built-in>. */ | |
12650 | && VARRAY_CHAR_PTR (file_table, i)[0] != '<') | |
79c758fb JJ |
12651 | { |
12652 | add_comp_dir_attribute (comp_unit_die); | |
12653 | break; | |
12654 | } | |
12655 | } | |
c4274b22 | 12656 | |
ef76d03b JW |
12657 | /* Traverse the limbo die list, and add parent/child links. The only |
12658 | dies without parents that should be here are concrete instances of | |
12659 | inline functions, and the comp_unit_die. We can ignore the comp_unit_die. | |
12660 | For concrete instances, we can get the parent die from the abstract | |
12661 | instance. */ | |
12662 | for (node = limbo_die_list; node; node = next_node) | |
12663 | { | |
12664 | next_node = node->next; | |
12665 | die = node->die; | |
12666 | ||
12667 | if (die->die_parent == NULL) | |
12668 | { | |
a96c67ec | 12669 | dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin); |
54ba1f0d | 12670 | tree context; |
2ad9852d | 12671 | |
a96c67ec JM |
12672 | if (origin) |
12673 | add_child_die (origin->die_parent, die); | |
ef76d03b | 12674 | else if (die == comp_unit_die) |
a96c67ec | 12675 | ; |
aea9695c RK |
12676 | /* If this was an expression for a bound involved in a function |
12677 | return type, it may be a SAVE_EXPR for which we weren't able | |
12678 | to find a DIE previously. So try now. */ | |
12679 | else if (node->created_for | |
12680 | && TREE_CODE (node->created_for) == SAVE_EXPR | |
12681 | && 0 != (origin = (lookup_decl_die | |
12682 | (SAVE_EXPR_CONTEXT | |
12683 | (node->created_for))))) | |
12684 | add_child_die (origin, die); | |
6bb28965 JM |
12685 | else if (errorcount > 0 || sorrycount > 0) |
12686 | /* It's OK to be confused by errors in the input. */ | |
12687 | add_child_die (comp_unit_die, die); | |
54ba1f0d RH |
12688 | else if (node->created_for |
12689 | && ((DECL_P (node->created_for) | |
c26fbbca | 12690 | && (context = DECL_CONTEXT (node->created_for))) |
54ba1f0d RH |
12691 | || (TYPE_P (node->created_for) |
12692 | && (context = TYPE_CONTEXT (node->created_for)))) | |
12693 | && TREE_CODE (context) == FUNCTION_DECL) | |
12694 | { | |
12695 | /* In certain situations, the lexical block containing a | |
12696 | nested function can be optimized away, which results | |
12697 | in the nested function die being orphaned. Likewise | |
12698 | with the return type of that nested function. Force | |
12699 | this to be a child of the containing function. */ | |
12700 | origin = lookup_decl_die (context); | |
12701 | if (! origin) | |
12702 | abort (); | |
12703 | add_child_die (origin, die); | |
12704 | } | |
ef76d03b JW |
12705 | else |
12706 | abort (); | |
12707 | } | |
ef76d03b | 12708 | } |
2ad9852d | 12709 | |
a96c67ec | 12710 | limbo_die_list = NULL; |
ef76d03b | 12711 | |
8a8c3656 JM |
12712 | /* Walk through the list of incomplete types again, trying once more to |
12713 | emit full debugging info for them. */ | |
12714 | retry_incomplete_types (); | |
12715 | ||
881c6935 JM |
12716 | /* We need to reverse all the dies before break_out_includes, or |
12717 | we'll see the end of an include file before the beginning. */ | |
12718 | reverse_all_dies (comp_unit_die); | |
12719 | ||
03275f81 ZD |
12720 | if (flag_eliminate_unused_debug_types) |
12721 | prune_unused_types (); | |
12722 | ||
881c6935 JM |
12723 | /* Generate separate CUs for each of the include files we've seen. |
12724 | They will go into limbo_die_list. */ | |
5f632b5e JM |
12725 | if (flag_eliminate_dwarf2_dups) |
12726 | break_out_includes (comp_unit_die); | |
881c6935 JM |
12727 | |
12728 | /* Traverse the DIE's and add add sibling attributes to those DIE's | |
12729 | that have children. */ | |
a3f97cbb | 12730 | add_sibling_attributes (comp_unit_die); |
881c6935 JM |
12731 | for (node = limbo_die_list; node; node = node->next) |
12732 | add_sibling_attributes (node->die); | |
a3f97cbb JW |
12733 | |
12734 | /* Output a terminator label for the .text section. */ | |
7c262518 | 12735 | text_section (); |
4977bab6 | 12736 | (*targetm.asm_out.internal_label) (asm_out_file, TEXT_END_LABEL, 0); |
a3f97cbb | 12737 | |
db3c0315 MM |
12738 | /* Output the source line correspondence table. We must do this |
12739 | even if there is no line information. Otherwise, on an empty | |
12740 | translation unit, we will generate a present, but empty, | |
12741 | .debug_info section. IRIX 6.5 `nm' will then complain when | |
12742 | examining the file. */ | |
12743 | if (! DWARF2_ASM_LINE_DEBUG_INFO) | |
e90b62db | 12744 | { |
715bdd29 | 12745 | named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG); |
db3c0315 MM |
12746 | output_line_info (); |
12747 | } | |
71dfc51f | 12748 | |
b38a75e5 RH |
12749 | /* Output location list section if necessary. */ |
12750 | if (have_location_lists) | |
12751 | { | |
12752 | /* Output the location lists info. */ | |
12753 | named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG); | |
12754 | ASM_GENERATE_INTERNAL_LABEL (loc_section_label, | |
12755 | DEBUG_LOC_SECTION_LABEL, 0); | |
12756 | ASM_OUTPUT_LABEL (asm_out_file, loc_section_label); | |
12757 | output_location_lists (die); | |
12758 | have_location_lists = 0; | |
12759 | } | |
12760 | ||
db3c0315 MM |
12761 | /* We can only use the low/high_pc attributes if all of the code was |
12762 | in .text. */ | |
12763 | if (separate_line_info_table_in_use == 0) | |
12764 | { | |
12765 | add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label); | |
12766 | add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label); | |
e90b62db | 12767 | } |
2ad9852d RK |
12768 | |
12769 | /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate | |
12770 | "base address". Use zero so that these addresses become absolute. */ | |
a20612aa RH |
12771 | else if (have_location_lists || ranges_table_in_use) |
12772 | add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx); | |
e90b62db | 12773 | |
fe7cd37f RH |
12774 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
12775 | add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list, | |
12776 | debug_line_section_label); | |
db3c0315 | 12777 | |
84a5b4f8 DB |
12778 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12779 | add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label); | |
a96c67ec | 12780 | |
881c6935 JM |
12781 | /* Output all of the compilation units. We put the main one last so that |
12782 | the offsets are available to output_pubnames. */ | |
12783 | for (node = limbo_die_list; node; node = node->next) | |
cc0017a9 | 12784 | output_comp_unit (node->die, 0); |
2ad9852d | 12785 | |
cc0017a9 | 12786 | output_comp_unit (comp_unit_die, 0); |
881c6935 | 12787 | |
a3f97cbb | 12788 | /* Output the abbreviation table. */ |
715bdd29 | 12789 | named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG); |
a3f97cbb JW |
12790 | output_abbrev_section (); |
12791 | ||
2ad9852d | 12792 | /* Output public names table if necessary. */ |
d291dd49 JM |
12793 | if (pubname_table_in_use) |
12794 | { | |
715bdd29 | 12795 | named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG); |
d291dd49 JM |
12796 | output_pubnames (); |
12797 | } | |
12798 | ||
2ad9852d RK |
12799 | /* Output the address range information. We only put functions in the arange |
12800 | table, so don't write it out if we don't have any. */ | |
a3f97cbb JW |
12801 | if (fde_table_in_use) |
12802 | { | |
715bdd29 | 12803 | named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG); |
a3f97cbb JW |
12804 | output_aranges (); |
12805 | } | |
a20612aa | 12806 | |
a20612aa RH |
12807 | /* Output ranges section if necessary. */ |
12808 | if (ranges_table_in_use) | |
12809 | { | |
715bdd29 | 12810 | named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG); |
2bee6045 | 12811 | ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label); |
a20612aa RH |
12812 | output_ranges (); |
12813 | } | |
12814 | ||
30f7a378 | 12815 | /* Have to end the primary source file. */ |
cc260610 | 12816 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
c26fbbca | 12817 | { |
715bdd29 | 12818 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
cc260610 | 12819 | dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); |
2f8d482e | 12820 | dw2_asm_output_data (1, 0, "End compilation unit"); |
cc260610 | 12821 | } |
9eb4015a | 12822 | |
2ad9852d | 12823 | /* If we emitted any DW_FORM_strp form attribute, output the string |
9eb4015a JJ |
12824 | table too. */ |
12825 | if (debug_str_hash) | |
17211ab5 | 12826 | htab_traverse (debug_str_hash, output_indirect_string, NULL); |
a3f97cbb | 12827 | } |
e2500fed GK |
12828 | #else |
12829 | ||
12830 | /* This should never be used, but its address is needed for comparisons. */ | |
12831 | const struct gcc_debug_hooks dwarf2_debug_hooks; | |
12832 | ||
12833 | #endif /* DWARF2_DEBUGGING_INFO */ | |
12834 | ||
12835 | #include "gt-dwarf2out.h" |