]>
Commit | Line | Data |
---|---|---|
a3f97cbb | 1 | /* Output Dwarf2 format symbol table information from the GNU C compiler. |
54ba1f0d | 2 | Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 |
06ceef4e | 3 | Free Software Foundation, Inc. |
e9a25f70 JL |
4 | Contributed by Gary Funck (gary@intrepid.com). |
5 | Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com). | |
469ac993 | 6 | Extensively modified by Jason Merrill (jason@cygnus.com). |
a3f97cbb | 7 | |
1322177d | 8 | This file is part of GCC. |
a3f97cbb | 9 | |
1322177d LB |
10 | GCC is free software; you can redistribute it and/or modify it under |
11 | the terms of the GNU General Public License as published by the Free | |
12 | Software Foundation; either version 2, or (at your option) any later | |
13 | version. | |
a3f97cbb | 14 | |
1322177d LB |
15 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
16 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
18 | for more details. | |
a3f97cbb JW |
19 | |
20 | You should have received a copy of the GNU General Public License | |
1322177d LB |
21 | along with GCC; see the file COPYING. If not, write to the Free |
22 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
23 | 02111-1307, USA. */ | |
a3f97cbb | 24 | |
9eb4015a | 25 | /* TODO: Emit .debug_line header even when there are no functions, since |
348bb3c7 JM |
26 | the file numbers are used by .debug_info. Alternately, leave |
27 | out locations for types and decls. | |
28 | Avoid talking about ctors and op= for PODs. | |
29 | Factor out common prologue sequences into multiple CIEs. */ | |
30 | ||
3f76745e JM |
31 | /* The first part of this file deals with the DWARF 2 frame unwind |
32 | information, which is also used by the GCC efficient exception handling | |
33 | mechanism. The second part, controlled only by an #ifdef | |
34 | DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging | |
35 | information. */ | |
36 | ||
0021b564 | 37 | #include "config.h" |
670ee920 | 38 | #include "system.h" |
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" |
9eb4015a | 66 | #include "hashtable.h" |
cc0017a9 | 67 | #include "hashtab.h" |
a3f97cbb | 68 | |
653e276c NB |
69 | #ifdef DWARF2_DEBUGGING_INFO |
70 | static void dwarf2out_source_line PARAMS ((unsigned int, const char *)); | |
71 | #endif | |
72 | ||
770ca8c6 JO |
73 | /* DWARF2 Abbreviation Glossary: |
74 | CFA = Canonical Frame Address | |
00a42e21 JM |
75 | a fixed address on the stack which identifies a call frame. |
76 | We define it to be the value of SP just before the call insn. | |
77 | The CFA register and offset, which may change during the course | |
78 | of the function, are used to calculate its value at runtime. | |
a401107d JO |
79 | CFI = Call Frame Instruction |
80 | an instruction for the DWARF2 abstract machine | |
770ca8c6 JO |
81 | CIE = Common Information Entry |
82 | information describing information common to one or more FDEs | |
83 | DIE = Debugging Information Entry | |
84 | FDE = Frame Description Entry | |
85 | information describing the stack call frame, in particular, | |
86 | how to restore registers | |
87 | ||
88 | DW_CFA_... = DWARF2 CFA call frame instruction | |
89 | DW_TAG_... = DWARF2 DIE tag */ | |
90 | ||
0021b564 JM |
91 | /* Decide whether we want to emit frame unwind information for the current |
92 | translation unit. */ | |
93 | ||
94 | int | |
95 | dwarf2out_do_frame () | |
96 | { | |
97 | return (write_symbols == DWARF2_DEBUG | |
7a0c8d71 | 98 | || write_symbols == VMS_AND_DWARF2_DEBUG |
9ec36da5 | 99 | #ifdef DWARF2_FRAME_INFO |
556273e0 | 100 | || DWARF2_FRAME_INFO |
9ec36da5 | 101 | #endif |
0021b564 | 102 | #ifdef DWARF2_UNWIND_INFO |
14a774a9 | 103 | || flag_unwind_tables |
531073e7 | 104 | || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS) |
0021b564 JM |
105 | #endif |
106 | ); | |
107 | } | |
108 | ||
f3a8e4f5 KG |
109 | /* The size of the target's pointer type. */ |
110 | #ifndef PTR_SIZE | |
111 | #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT) | |
112 | #endif | |
113 | ||
114 | /* Default version of targetm.eh_frame_section. Note this must appear | |
115 | outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro | |
116 | guards. */ | |
117 | ||
118 | void | |
119 | default_eh_frame_section () | |
120 | { | |
121 | #ifdef EH_FRAME_SECTION_NAME | |
96d0f4dc JJ |
122 | #ifdef HAVE_LD_RO_RW_SECTION_MIXING |
123 | int fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0); | |
124 | int per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1); | |
125 | int lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0); | |
126 | int flags; | |
127 | ||
128 | flags = (! flag_pic | |
129 | || ((fde_encoding & 0x70) != DW_EH_PE_absptr | |
130 | && (fde_encoding & 0x70) != DW_EH_PE_aligned | |
131 | && (per_encoding & 0x70) != DW_EH_PE_absptr | |
132 | && (per_encoding & 0x70) != DW_EH_PE_aligned | |
133 | && (lsda_encoding & 0x70) != DW_EH_PE_absptr | |
134 | && (lsda_encoding & 0x70) != DW_EH_PE_aligned)) | |
135 | ? 0 : SECTION_WRITE; | |
136 | named_section_flags (EH_FRAME_SECTION_NAME, flags); | |
137 | #else | |
f3a8e4f5 | 138 | named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE); |
96d0f4dc | 139 | #endif |
f3a8e4f5 KG |
140 | #else |
141 | tree label = get_file_function_name ('F'); | |
142 | ||
143 | data_section (); | |
144 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); | |
5eb99654 | 145 | (*targetm.asm_out.globalize_label) (asm_out_file, IDENTIFIER_POINTER (label)); |
f3a8e4f5 KG |
146 | ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); |
147 | #endif | |
148 | } | |
149 | ||
e2500fed GK |
150 | /* Array of RTXes referenced by the debugging information, which therefore |
151 | must be kept around forever. */ | |
152 | static GTY(()) varray_type used_rtx_varray; | |
153 | ||
154 | /* A pointer to the base of a list of incomplete types which might be | |
155 | completed at some later time. incomplete_types_list needs to be a VARRAY | |
156 | because we want to tell the garbage collector about it. */ | |
157 | static GTY(()) varray_type incomplete_types; | |
158 | ||
159 | /* A pointer to the base of a table of references to declaration | |
160 | scopes. This table is a display which tracks the nesting | |
161 | of declaration scopes at the current scope and containing | |
162 | scopes. This table is used to find the proper place to | |
163 | define type declaration DIE's. */ | |
164 | static GTY(()) varray_type decl_scope_table; | |
165 | ||
0021b564 JM |
166 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) |
167 | ||
eaf95893 RK |
168 | /* How to start an assembler comment. */ |
169 | #ifndef ASM_COMMENT_START | |
170 | #define ASM_COMMENT_START ";#" | |
171 | #endif | |
172 | ||
a3f97cbb JW |
173 | typedef struct dw_cfi_struct *dw_cfi_ref; |
174 | typedef struct dw_fde_struct *dw_fde_ref; | |
175 | typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref; | |
a3f97cbb JW |
176 | |
177 | /* Call frames are described using a sequence of Call Frame | |
178 | Information instructions. The register number, offset | |
179 | and address fields are provided as possible operands; | |
180 | their use is selected by the opcode field. */ | |
71dfc51f | 181 | |
a3f97cbb | 182 | typedef union dw_cfi_oprnd_struct |
71dfc51f RK |
183 | { |
184 | unsigned long dw_cfi_reg_num; | |
185 | long int dw_cfi_offset; | |
d3e3972c | 186 | const char *dw_cfi_addr; |
7d9d8943 | 187 | struct dw_loc_descr_struct *dw_cfi_loc; |
71dfc51f | 188 | } |
a3f97cbb JW |
189 | dw_cfi_oprnd; |
190 | ||
191 | typedef struct dw_cfi_struct | |
71dfc51f RK |
192 | { |
193 | dw_cfi_ref dw_cfi_next; | |
194 | enum dwarf_call_frame_info dw_cfi_opc; | |
195 | dw_cfi_oprnd dw_cfi_oprnd1; | |
196 | dw_cfi_oprnd dw_cfi_oprnd2; | |
197 | } | |
a3f97cbb JW |
198 | dw_cfi_node; |
199 | ||
7d9d8943 AM |
200 | /* This is how we define the location of the CFA. We use to handle it |
201 | as REG + OFFSET all the time, but now it can be more complex. | |
202 | It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET. | |
556273e0 | 203 | Instead of passing around REG and OFFSET, we pass a copy |
7d9d8943 AM |
204 | of this structure. */ |
205 | typedef struct cfa_loc | |
206 | { | |
556273e0 | 207 | unsigned long reg; |
7d9d8943 AM |
208 | long offset; |
209 | long base_offset; | |
210 | int indirect; /* 1 if CFA is accessed via a dereference. */ | |
211 | } dw_cfa_location; | |
212 | ||
a3f97cbb | 213 | /* All call frame descriptions (FDE's) in the GCC generated DWARF |
4b674448 | 214 | refer to a single Common Information Entry (CIE), defined at |
fb530c07 | 215 | the beginning of the .debug_frame section. This use of a single |
a3f97cbb JW |
216 | CIE obviates the need to keep track of multiple CIE's |
217 | in the DWARF generation routines below. */ | |
71dfc51f | 218 | |
a3f97cbb | 219 | typedef struct dw_fde_struct |
71dfc51f | 220 | { |
d3e3972c KG |
221 | const char *dw_fde_begin; |
222 | const char *dw_fde_current_label; | |
223 | const char *dw_fde_end; | |
71dfc51f | 224 | dw_cfi_ref dw_fde_cfi; |
52a11cbf | 225 | unsigned funcdef_number; |
b6128b8c | 226 | unsigned all_throwers_are_sibcalls : 1; |
52a11cbf RH |
227 | unsigned nothrow : 1; |
228 | unsigned uses_eh_lsda : 1; | |
71dfc51f | 229 | } |
a3f97cbb JW |
230 | dw_fde_node; |
231 | ||
6d2f8887 | 232 | /* Maximum size (in bytes) of an artificially generated label. */ |
a3f97cbb JW |
233 | #define MAX_ARTIFICIAL_LABEL_BYTES 30 |
234 | ||
a1a4189d JB |
235 | /* The size of addresses as they appear in the Dwarf 2 data. |
236 | Some architectures use word addresses to refer to code locations, | |
237 | but Dwarf 2 info always uses byte addresses. On such machines, | |
238 | Dwarf 2 addresses need to be larger than the architecture's | |
239 | pointers. */ | |
240 | #ifndef DWARF2_ADDR_SIZE | |
241 | #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT) | |
242 | #endif | |
243 | ||
7e23cb16 | 244 | /* The size in bytes of a DWARF field indicating an offset or length |
a1a4189d JB |
245 | relative to a debug info section, specified to be 4 bytes in the |
246 | DWARF-2 specification. The SGI/MIPS ABI defines it to be the same | |
b13fe8bf | 247 | as PTR_SIZE. */ |
71dfc51f | 248 | |
7e23cb16 JM |
249 | #ifndef DWARF_OFFSET_SIZE |
250 | #define DWARF_OFFSET_SIZE 4 | |
251 | #endif | |
252 | ||
9a666dda JM |
253 | #define DWARF_VERSION 2 |
254 | ||
7e23cb16 JM |
255 | /* Round SIZE up to the nearest BOUNDARY. */ |
256 | #define DWARF_ROUND(SIZE,BOUNDARY) \ | |
262b6384 | 257 | ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY)) |
a3f97cbb | 258 | |
a3f97cbb | 259 | /* Offsets recorded in opcodes are a multiple of this alignment factor. */ |
27c35f4b | 260 | #ifndef DWARF_CIE_DATA_ALIGNMENT |
469ac993 | 261 | #ifdef STACK_GROWS_DOWNWARD |
08cb3d38 | 262 | #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD)) |
469ac993 | 263 | #else |
08cb3d38 | 264 | #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD) |
469ac993 | 265 | #endif |
2ad9852d | 266 | #endif |
a3f97cbb | 267 | |
3f76745e JM |
268 | /* A pointer to the base of a table that contains frame description |
269 | information for each routine. */ | |
270 | static dw_fde_ref fde_table; | |
a3f97cbb | 271 | |
3f76745e JM |
272 | /* Number of elements currently allocated for fde_table. */ |
273 | static unsigned fde_table_allocated; | |
a94dbf2c | 274 | |
3f76745e JM |
275 | /* Number of elements in fde_table currently in use. */ |
276 | static unsigned fde_table_in_use; | |
a3f97cbb | 277 | |
3f76745e JM |
278 | /* Size (in elements) of increments by which we may expand the |
279 | fde_table. */ | |
280 | #define FDE_TABLE_INCREMENT 256 | |
a3f97cbb | 281 | |
a94dbf2c JM |
282 | /* A list of call frame insns for the CIE. */ |
283 | static dw_cfi_ref cie_cfi_head; | |
284 | ||
a3f97cbb JW |
285 | /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram |
286 | attribute that accelerates the lookup of the FDE associated | |
556273e0 | 287 | with the subprogram. This variable holds the table index of the FDE |
a3f97cbb JW |
288 | associated with the current function (body) definition. */ |
289 | static unsigned current_funcdef_fde; | |
290 | ||
9eb4015a JJ |
291 | struct ht *debug_str_hash; |
292 | ||
293 | struct indirect_string_node | |
294 | { | |
295 | struct ht_identifier id; | |
296 | unsigned int refcount; | |
297 | unsigned int form; | |
298 | char *label; | |
299 | }; | |
300 | ||
a3f97cbb | 301 | /* Forward declarations for functions defined in this file. */ |
71dfc51f | 302 | |
83d2b3b9 KG |
303 | static char *stripattributes PARAMS ((const char *)); |
304 | static const char *dwarf_cfi_name PARAMS ((unsigned)); | |
305 | static dw_cfi_ref new_cfi PARAMS ((void)); | |
306 | static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref)); | |
d3e3972c | 307 | static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref)); |
2ad9852d RK |
308 | static void lookup_cfa_1 PARAMS ((dw_cfi_ref, |
309 | dw_cfa_location *)); | |
7d9d8943 | 310 | static void lookup_cfa PARAMS ((dw_cfa_location *)); |
d3e3972c KG |
311 | static void reg_save PARAMS ((const char *, unsigned, |
312 | unsigned, long)); | |
83d2b3b9 | 313 | static void initial_return_save PARAMS ((rtx)); |
5e640c56 | 314 | static long stack_adjust_offset PARAMS ((rtx)); |
12f0b96b | 315 | static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int)); |
83d2b3b9 | 316 | static void output_call_frame_info PARAMS ((int)); |
83d2b3b9 | 317 | static void dwarf2out_stack_adjust PARAMS ((rtx)); |
fbfa55b0 RH |
318 | static void queue_reg_save PARAMS ((const char *, rtx, long)); |
319 | static void flush_queued_reg_saves PARAMS ((void)); | |
320 | static bool clobbers_queued_reg_save PARAMS ((rtx)); | |
d3e3972c | 321 | static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *)); |
a3f97cbb | 322 | |
7d9d8943 AM |
323 | /* Support for complex CFA locations. */ |
324 | static void output_cfa_loc PARAMS ((dw_cfi_ref)); | |
556273e0 | 325 | static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *, |
7d9d8943 AM |
326 | struct dw_loc_descr_struct *)); |
327 | static struct dw_loc_descr_struct *build_cfa_loc | |
328 | PARAMS ((dw_cfa_location *)); | |
2ad9852d RK |
329 | static void def_cfa_1 PARAMS ((const char *, |
330 | dw_cfa_location *)); | |
7d9d8943 | 331 | |
2e4b9b8c RH |
332 | /* How to start an assembler comment. */ |
333 | #ifndef ASM_COMMENT_START | |
334 | #define ASM_COMMENT_START ";#" | |
a3f97cbb JW |
335 | #endif |
336 | ||
7e23cb16 JM |
337 | /* Data and reference forms for relocatable data. */ |
338 | #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4) | |
339 | #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4) | |
340 | ||
cf2fe500 RH |
341 | #ifndef DEBUG_FRAME_SECTION |
342 | #define DEBUG_FRAME_SECTION ".debug_frame" | |
a3f97cbb | 343 | #endif |
a3f97cbb | 344 | |
5c90448c JM |
345 | #ifndef FUNC_BEGIN_LABEL |
346 | #define FUNC_BEGIN_LABEL "LFB" | |
a3f97cbb | 347 | #endif |
2ad9852d | 348 | |
5c90448c JM |
349 | #ifndef FUNC_END_LABEL |
350 | #define FUNC_END_LABEL "LFE" | |
a3f97cbb | 351 | #endif |
2ad9852d | 352 | |
27d95cbe | 353 | #define FRAME_BEGIN_LABEL "Lframe" |
a6ab3aad JM |
354 | #define CIE_AFTER_SIZE_LABEL "LSCIE" |
355 | #define CIE_END_LABEL "LECIE" | |
2e4b9b8c RH |
356 | #define FDE_LABEL "LSFDE" |
357 | #define FDE_AFTER_SIZE_LABEL "LASFDE" | |
a6ab3aad | 358 | #define FDE_END_LABEL "LEFDE" |
981975b6 RH |
359 | #define LINE_NUMBER_BEGIN_LABEL "LSLT" |
360 | #define LINE_NUMBER_END_LABEL "LELT" | |
361 | #define LN_PROLOG_AS_LABEL "LASLTP" | |
362 | #define LN_PROLOG_END_LABEL "LELTP" | |
881c6935 | 363 | #define DIE_LABEL_PREFIX "DW" |
a3f97cbb | 364 | |
c8cc5c4a | 365 | /* The DWARF 2 CFA column which tracks the return address. Normally this |
a94dbf2c JM |
366 | is the column for PC, or the first column after all of the hard |
367 | registers. */ | |
c8cc5c4a | 368 | #ifndef DWARF_FRAME_RETURN_COLUMN |
a94dbf2c JM |
369 | #ifdef PC_REGNUM |
370 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM) | |
371 | #else | |
3073d01c | 372 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS |
a94dbf2c | 373 | #endif |
c8cc5c4a JM |
374 | #endif |
375 | ||
376 | /* The mapping from gcc register number to DWARF 2 CFA column number. By | |
469ac993 | 377 | default, we just provide columns for all registers. */ |
c8cc5c4a | 378 | #ifndef DWARF_FRAME_REGNUM |
469ac993 | 379 | #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG) |
c8cc5c4a | 380 | #endif |
3f76745e | 381 | |
2ad9852d RK |
382 | /* The offset from the incoming value of %sp to the top of the stack frame |
383 | for the current function. */ | |
384 | #ifndef INCOMING_FRAME_SP_OFFSET | |
385 | #define INCOMING_FRAME_SP_OFFSET 0 | |
386 | #endif | |
387 | \f | |
0021b564 JM |
388 | /* Hook used by __throw. */ |
389 | ||
390 | rtx | |
391 | expand_builtin_dwarf_fp_regnum () | |
392 | { | |
393 | return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM)); | |
394 | } | |
395 | ||
71dfc51f | 396 | /* Return a pointer to a copy of the section string name S with all |
bf20f341 | 397 | attributes stripped off, and an asterisk prepended (for assemble_name). */ |
71dfc51f RK |
398 | |
399 | static inline char * | |
a3f97cbb | 400 | stripattributes (s) |
d560ee52 | 401 | const char *s; |
a3f97cbb | 402 | { |
bf20f341 | 403 | char *stripped = xmalloc (strlen (s) + 2); |
71dfc51f RK |
404 | char *p = stripped; |
405 | ||
bf20f341 JW |
406 | *p++ = '*'; |
407 | ||
408 | while (*s && *s != ',') | |
409 | *p++ = *s++; | |
71dfc51f | 410 | |
a3f97cbb JW |
411 | *p = '\0'; |
412 | return stripped; | |
413 | } | |
414 | ||
d9d5c9de | 415 | /* Generate code to initialize the register size table. */ |
2f3ca9e7 | 416 | |
d9d5c9de BS |
417 | void |
418 | expand_builtin_init_dwarf_reg_sizes (address) | |
419 | tree address; | |
2f3ca9e7 | 420 | { |
d9d5c9de BS |
421 | int i; |
422 | enum machine_mode mode = TYPE_MODE (char_type_node); | |
423 | rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0); | |
2ad9852d | 424 | rtx mem = gen_rtx_MEM (BLKmode, addr); |
2f3ca9e7 | 425 | |
91ea38f9 JH |
426 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) |
427 | if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS) | |
428 | { | |
429 | HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode); | |
430 | HOST_WIDE_INT size = GET_MODE_SIZE (reg_raw_mode[i]); | |
2f3ca9e7 | 431 | |
91ea38f9 JH |
432 | if (offset < 0) |
433 | continue; | |
c699cee9 | 434 | |
91ea38f9 JH |
435 | emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size)); |
436 | } | |
2f3ca9e7 JM |
437 | } |
438 | ||
3f76745e | 439 | /* Convert a DWARF call frame info. operation to its string name */ |
a3f97cbb | 440 | |
d560ee52 | 441 | static const char * |
3f76745e | 442 | dwarf_cfi_name (cfi_opc) |
b3694847 | 443 | unsigned cfi_opc; |
3f76745e JM |
444 | { |
445 | switch (cfi_opc) | |
446 | { | |
447 | case DW_CFA_advance_loc: | |
448 | return "DW_CFA_advance_loc"; | |
449 | case DW_CFA_offset: | |
450 | return "DW_CFA_offset"; | |
451 | case DW_CFA_restore: | |
452 | return "DW_CFA_restore"; | |
453 | case DW_CFA_nop: | |
454 | return "DW_CFA_nop"; | |
455 | case DW_CFA_set_loc: | |
456 | return "DW_CFA_set_loc"; | |
457 | case DW_CFA_advance_loc1: | |
458 | return "DW_CFA_advance_loc1"; | |
459 | case DW_CFA_advance_loc2: | |
460 | return "DW_CFA_advance_loc2"; | |
461 | case DW_CFA_advance_loc4: | |
462 | return "DW_CFA_advance_loc4"; | |
463 | case DW_CFA_offset_extended: | |
464 | return "DW_CFA_offset_extended"; | |
465 | case DW_CFA_restore_extended: | |
466 | return "DW_CFA_restore_extended"; | |
467 | case DW_CFA_undefined: | |
468 | return "DW_CFA_undefined"; | |
469 | case DW_CFA_same_value: | |
470 | return "DW_CFA_same_value"; | |
471 | case DW_CFA_register: | |
472 | return "DW_CFA_register"; | |
473 | case DW_CFA_remember_state: | |
474 | return "DW_CFA_remember_state"; | |
475 | case DW_CFA_restore_state: | |
476 | return "DW_CFA_restore_state"; | |
477 | case DW_CFA_def_cfa: | |
478 | return "DW_CFA_def_cfa"; | |
479 | case DW_CFA_def_cfa_register: | |
480 | return "DW_CFA_def_cfa_register"; | |
481 | case DW_CFA_def_cfa_offset: | |
482 | return "DW_CFA_def_cfa_offset"; | |
6bb28965 JM |
483 | |
484 | /* DWARF 3 */ | |
7d9d8943 AM |
485 | case DW_CFA_def_cfa_expression: |
486 | return "DW_CFA_def_cfa_expression"; | |
6bb28965 JM |
487 | case DW_CFA_expression: |
488 | return "DW_CFA_expression"; | |
489 | case DW_CFA_offset_extended_sf: | |
490 | return "DW_CFA_offset_extended_sf"; | |
491 | case DW_CFA_def_cfa_sf: | |
492 | return "DW_CFA_def_cfa_sf"; | |
493 | case DW_CFA_def_cfa_offset_sf: | |
494 | return "DW_CFA_def_cfa_offset_sf"; | |
c53aa195 | 495 | |
3f76745e JM |
496 | /* SGI/MIPS specific */ |
497 | case DW_CFA_MIPS_advance_loc8: | |
498 | return "DW_CFA_MIPS_advance_loc8"; | |
c53aa195 JM |
499 | |
500 | /* GNU extensions */ | |
501 | case DW_CFA_GNU_window_save: | |
502 | return "DW_CFA_GNU_window_save"; | |
0021b564 JM |
503 | case DW_CFA_GNU_args_size: |
504 | return "DW_CFA_GNU_args_size"; | |
3f388b42 GK |
505 | case DW_CFA_GNU_negative_offset_extended: |
506 | return "DW_CFA_GNU_negative_offset_extended"; | |
c53aa195 | 507 | |
3f76745e JM |
508 | default: |
509 | return "DW_CFA_<unknown>"; | |
510 | } | |
511 | } | |
a3f97cbb | 512 | |
3f76745e | 513 | /* Return a pointer to a newly allocated Call Frame Instruction. */ |
71dfc51f | 514 | |
3f76745e JM |
515 | static inline dw_cfi_ref |
516 | new_cfi () | |
517 | { | |
b3694847 | 518 | dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node)); |
71dfc51f | 519 | |
3f76745e JM |
520 | cfi->dw_cfi_next = NULL; |
521 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0; | |
522 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0; | |
a3f97cbb | 523 | |
3f76745e JM |
524 | return cfi; |
525 | } | |
a3f97cbb | 526 | |
3f76745e | 527 | /* Add a Call Frame Instruction to list of instructions. */ |
a3f97cbb | 528 | |
3f76745e JM |
529 | static inline void |
530 | add_cfi (list_head, cfi) | |
b3694847 SS |
531 | dw_cfi_ref *list_head; |
532 | dw_cfi_ref cfi; | |
3f76745e | 533 | { |
b3694847 | 534 | dw_cfi_ref *p; |
a3f97cbb | 535 | |
3f76745e JM |
536 | /* Find the end of the chain. */ |
537 | for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next) | |
538 | ; | |
539 | ||
540 | *p = cfi; | |
a3f97cbb JW |
541 | } |
542 | ||
3f76745e | 543 | /* Generate a new label for the CFI info to refer to. */ |
71dfc51f | 544 | |
c53aa195 | 545 | char * |
3f76745e | 546 | dwarf2out_cfi_label () |
a3f97cbb | 547 | { |
3f76745e JM |
548 | static char label[20]; |
549 | static unsigned long label_num = 0; | |
556273e0 | 550 | |
3f76745e JM |
551 | ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++); |
552 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
3f76745e | 553 | return label; |
a3f97cbb JW |
554 | } |
555 | ||
3f76745e JM |
556 | /* Add CFI to the current fde at the PC value indicated by LABEL if specified, |
557 | or to the CIE if LABEL is NULL. */ | |
71dfc51f | 558 | |
3f76745e JM |
559 | static void |
560 | add_fde_cfi (label, cfi) | |
b3694847 SS |
561 | const char *label; |
562 | dw_cfi_ref cfi; | |
a3f97cbb | 563 | { |
3f76745e JM |
564 | if (label) |
565 | { | |
b3694847 | 566 | dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
a3f97cbb | 567 | |
3f76745e JM |
568 | if (*label == 0) |
569 | label = dwarf2out_cfi_label (); | |
71dfc51f | 570 | |
3f76745e JM |
571 | if (fde->dw_fde_current_label == NULL |
572 | || strcmp (label, fde->dw_fde_current_label) != 0) | |
573 | { | |
b3694847 | 574 | dw_cfi_ref xcfi; |
a3f97cbb | 575 | |
3f76745e | 576 | fde->dw_fde_current_label = label = xstrdup (label); |
71dfc51f | 577 | |
3f76745e JM |
578 | /* Set the location counter to the new label. */ |
579 | xcfi = new_cfi (); | |
580 | xcfi->dw_cfi_opc = DW_CFA_advance_loc4; | |
581 | xcfi->dw_cfi_oprnd1.dw_cfi_addr = label; | |
582 | add_cfi (&fde->dw_fde_cfi, xcfi); | |
583 | } | |
71dfc51f | 584 | |
3f76745e JM |
585 | add_cfi (&fde->dw_fde_cfi, cfi); |
586 | } | |
587 | ||
588 | else | |
589 | add_cfi (&cie_cfi_head, cfi); | |
a3f97cbb JW |
590 | } |
591 | ||
3f76745e | 592 | /* Subroutine of lookup_cfa. */ |
71dfc51f | 593 | |
3f76745e | 594 | static inline void |
7d9d8943 | 595 | lookup_cfa_1 (cfi, loc) |
b3694847 SS |
596 | dw_cfi_ref cfi; |
597 | dw_cfa_location *loc; | |
a3f97cbb | 598 | { |
3f76745e JM |
599 | switch (cfi->dw_cfi_opc) |
600 | { | |
601 | case DW_CFA_def_cfa_offset: | |
7d9d8943 | 602 | loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset; |
3f76745e JM |
603 | break; |
604 | case DW_CFA_def_cfa_register: | |
7d9d8943 | 605 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
3f76745e JM |
606 | break; |
607 | case DW_CFA_def_cfa: | |
7d9d8943 AM |
608 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
609 | loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset; | |
610 | break; | |
611 | case DW_CFA_def_cfa_expression: | |
612 | get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc); | |
3f76745e | 613 | break; |
e9a25f70 JL |
614 | default: |
615 | break; | |
3f76745e | 616 | } |
a3f97cbb JW |
617 | } |
618 | ||
3f76745e | 619 | /* Find the previous value for the CFA. */ |
71dfc51f | 620 | |
3f76745e | 621 | static void |
7d9d8943 | 622 | lookup_cfa (loc) |
b3694847 | 623 | dw_cfa_location *loc; |
a3f97cbb | 624 | { |
b3694847 | 625 | dw_cfi_ref cfi; |
3f76745e | 626 | |
7d9d8943 AM |
627 | loc->reg = (unsigned long) -1; |
628 | loc->offset = 0; | |
629 | loc->indirect = 0; | |
630 | loc->base_offset = 0; | |
3f76745e JM |
631 | |
632 | for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next) | |
7d9d8943 | 633 | lookup_cfa_1 (cfi, loc); |
3f76745e JM |
634 | |
635 | if (fde_table_in_use) | |
a3f97cbb | 636 | { |
b3694847 | 637 | dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
3f76745e | 638 | for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next) |
7d9d8943 | 639 | lookup_cfa_1 (cfi, loc); |
a3f97cbb JW |
640 | } |
641 | } | |
642 | ||
3f76745e | 643 | /* The current rule for calculating the DWARF2 canonical frame address. */ |
fbfa55b0 | 644 | static dw_cfa_location cfa; |
71dfc51f | 645 | |
3f76745e JM |
646 | /* The register used for saving registers to the stack, and its offset |
647 | from the CFA. */ | |
fbfa55b0 | 648 | static dw_cfa_location cfa_store; |
3f76745e | 649 | |
0021b564 JM |
650 | /* The running total of the size of arguments pushed onto the stack. */ |
651 | static long args_size; | |
652 | ||
b57d9225 JM |
653 | /* The last args_size we actually output. */ |
654 | static long old_args_size; | |
655 | ||
3f76745e JM |
656 | /* Entry point to update the canonical frame address (CFA). |
657 | LABEL is passed to add_fde_cfi. The value of CFA is now to be | |
658 | calculated from REG+OFFSET. */ | |
659 | ||
660 | void | |
661 | dwarf2out_def_cfa (label, reg, offset) | |
b3694847 | 662 | const char *label; |
7d9d8943 AM |
663 | unsigned reg; |
664 | long offset; | |
665 | { | |
666 | dw_cfa_location loc; | |
667 | loc.indirect = 0; | |
668 | loc.base_offset = 0; | |
669 | loc.reg = reg; | |
670 | loc.offset = offset; | |
671 | def_cfa_1 (label, &loc); | |
672 | } | |
673 | ||
770ca8c6 | 674 | /* This routine does the actual work. The CFA is now calculated from |
7d9d8943 | 675 | the dw_cfa_location structure. */ |
2ad9852d | 676 | |
7d9d8943 AM |
677 | static void |
678 | def_cfa_1 (label, loc_p) | |
b3694847 | 679 | const char *label; |
7d9d8943 | 680 | dw_cfa_location *loc_p; |
a3f97cbb | 681 | { |
b3694847 | 682 | dw_cfi_ref cfi; |
7d9d8943 | 683 | dw_cfa_location old_cfa, loc; |
3f76745e | 684 | |
7d9d8943 AM |
685 | cfa = *loc_p; |
686 | loc = *loc_p; | |
5bef9b1f | 687 | |
7d9d8943 AM |
688 | if (cfa_store.reg == loc.reg && loc.indirect == 0) |
689 | cfa_store.offset = loc.offset; | |
3f76745e | 690 | |
7d9d8943 AM |
691 | loc.reg = DWARF_FRAME_REGNUM (loc.reg); |
692 | lookup_cfa (&old_cfa); | |
693 | ||
2ad9852d RK |
694 | /* If nothing changed, no need to issue any call frame instructions. */ |
695 | if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset | |
696 | && loc.indirect == old_cfa.indirect | |
697 | && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset)) | |
698 | return; | |
3f76745e JM |
699 | |
700 | cfi = new_cfi (); | |
701 | ||
e09bbb25 | 702 | if (loc.reg == old_cfa.reg && !loc.indirect) |
a3f97cbb | 703 | { |
770ca8c6 JO |
704 | /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, |
705 | indicating the CFA register did not change but the offset | |
706 | did. */ | |
3f76745e | 707 | cfi->dw_cfi_opc = DW_CFA_def_cfa_offset; |
7d9d8943 | 708 | cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset; |
3f76745e | 709 | } |
a3f97cbb | 710 | |
3f76745e | 711 | #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */ |
7d9d8943 | 712 | else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1 |
e09bbb25 | 713 | && !loc.indirect) |
3f76745e | 714 | { |
770ca8c6 JO |
715 | /* Construct a "DW_CFA_def_cfa_register <register>" instruction, |
716 | indicating the CFA register has changed to <register> but the | |
717 | offset has not changed. */ | |
3f76745e | 718 | cfi->dw_cfi_opc = DW_CFA_def_cfa_register; |
7d9d8943 | 719 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
3f76745e JM |
720 | } |
721 | #endif | |
a3f97cbb | 722 | |
7d9d8943 | 723 | else if (loc.indirect == 0) |
3f76745e | 724 | { |
770ca8c6 JO |
725 | /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction, |
726 | indicating the CFA register has changed to <register> with | |
727 | the specified offset. */ | |
3f76745e | 728 | cfi->dw_cfi_opc = DW_CFA_def_cfa; |
7d9d8943 AM |
729 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
730 | cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset; | |
731 | } | |
732 | else | |
733 | { | |
770ca8c6 JO |
734 | /* Construct a DW_CFA_def_cfa_expression instruction to |
735 | calculate the CFA using a full location expression since no | |
736 | register-offset pair is available. */ | |
556273e0 | 737 | struct dw_loc_descr_struct *loc_list; |
2ad9852d | 738 | |
7d9d8943 AM |
739 | cfi->dw_cfi_opc = DW_CFA_def_cfa_expression; |
740 | loc_list = build_cfa_loc (&loc); | |
741 | cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list; | |
a3f97cbb | 742 | } |
3f76745e JM |
743 | |
744 | add_fde_cfi (label, cfi); | |
a3f97cbb JW |
745 | } |
746 | ||
3f76745e JM |
747 | /* Add the CFI for saving a register. REG is the CFA column number. |
748 | LABEL is passed to add_fde_cfi. | |
749 | If SREG is -1, the register is saved at OFFSET from the CFA; | |
750 | otherwise it is saved in SREG. */ | |
71dfc51f | 751 | |
3f76745e JM |
752 | static void |
753 | reg_save (label, reg, sreg, offset) | |
b3694847 SS |
754 | const char *label; |
755 | unsigned reg; | |
756 | unsigned sreg; | |
757 | long offset; | |
a3f97cbb | 758 | { |
b3694847 | 759 | dw_cfi_ref cfi = new_cfi (); |
3f76745e JM |
760 | |
761 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
762 | ||
85066503 MH |
763 | /* The following comparison is correct. -1 is used to indicate that |
764 | the value isn't a register number. */ | |
765 | if (sreg == (unsigned int) -1) | |
a3f97cbb | 766 | { |
3f76745e JM |
767 | if (reg & ~0x3f) |
768 | /* The register number won't fit in 6 bits, so we have to use | |
769 | the long form. */ | |
770 | cfi->dw_cfi_opc = DW_CFA_offset_extended; | |
771 | else | |
772 | cfi->dw_cfi_opc = DW_CFA_offset; | |
773 | ||
27c35f4b HPN |
774 | #ifdef ENABLE_CHECKING |
775 | { | |
776 | /* If we get an offset that is not a multiple of | |
777 | DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the | |
778 | definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine | |
779 | description. */ | |
780 | long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT; | |
781 | ||
782 | if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset) | |
783 | abort (); | |
784 | } | |
785 | #endif | |
3f76745e | 786 | offset /= DWARF_CIE_DATA_ALIGNMENT; |
3a88cbd1 | 787 | if (offset < 0) |
6bb28965 | 788 | cfi->dw_cfi_opc = DW_CFA_offset_extended_sf; |
2ad9852d | 789 | |
3f76745e JM |
790 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; |
791 | } | |
2c849145 JM |
792 | else if (sreg == reg) |
793 | /* We could emit a DW_CFA_same_value in this case, but don't bother. */ | |
794 | return; | |
3f76745e JM |
795 | else |
796 | { | |
797 | cfi->dw_cfi_opc = DW_CFA_register; | |
798 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg; | |
799 | } | |
800 | ||
801 | add_fde_cfi (label, cfi); | |
802 | } | |
803 | ||
c53aa195 JM |
804 | /* Add the CFI for saving a register window. LABEL is passed to reg_save. |
805 | This CFI tells the unwinder that it needs to restore the window registers | |
806 | from the previous frame's window save area. | |
556273e0 | 807 | |
c53aa195 JM |
808 | ??? Perhaps we should note in the CIE where windows are saved (instead of |
809 | assuming 0(cfa)) and what registers are in the window. */ | |
810 | ||
811 | void | |
812 | dwarf2out_window_save (label) | |
b3694847 | 813 | const char *label; |
c53aa195 | 814 | { |
b3694847 | 815 | dw_cfi_ref cfi = new_cfi (); |
2ad9852d | 816 | |
c53aa195 JM |
817 | cfi->dw_cfi_opc = DW_CFA_GNU_window_save; |
818 | add_fde_cfi (label, cfi); | |
819 | } | |
820 | ||
0021b564 JM |
821 | /* Add a CFI to update the running total of the size of arguments |
822 | pushed onto the stack. */ | |
823 | ||
824 | void | |
825 | dwarf2out_args_size (label, size) | |
d3e3972c | 826 | const char *label; |
0021b564 JM |
827 | long size; |
828 | { | |
b3694847 | 829 | dw_cfi_ref cfi; |
b57d9225 JM |
830 | |
831 | if (size == old_args_size) | |
832 | return; | |
2ad9852d | 833 | |
b57d9225 JM |
834 | old_args_size = size; |
835 | ||
836 | cfi = new_cfi (); | |
0021b564 JM |
837 | cfi->dw_cfi_opc = DW_CFA_GNU_args_size; |
838 | cfi->dw_cfi_oprnd1.dw_cfi_offset = size; | |
839 | add_fde_cfi (label, cfi); | |
840 | } | |
841 | ||
c53aa195 JM |
842 | /* Entry point for saving a register to the stack. REG is the GCC register |
843 | number. LABEL and OFFSET are passed to reg_save. */ | |
3f76745e JM |
844 | |
845 | void | |
846 | dwarf2out_reg_save (label, reg, offset) | |
b3694847 SS |
847 | const char *label; |
848 | unsigned reg; | |
849 | long offset; | |
3f76745e JM |
850 | { |
851 | reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset); | |
852 | } | |
853 | ||
c53aa195 JM |
854 | /* Entry point for saving the return address in the stack. |
855 | LABEL and OFFSET are passed to reg_save. */ | |
856 | ||
857 | void | |
858 | dwarf2out_return_save (label, offset) | |
b3694847 SS |
859 | const char *label; |
860 | long offset; | |
c53aa195 JM |
861 | { |
862 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset); | |
863 | } | |
864 | ||
865 | /* Entry point for saving the return address in a register. | |
866 | LABEL and SREG are passed to reg_save. */ | |
867 | ||
868 | void | |
869 | dwarf2out_return_reg (label, sreg) | |
b3694847 SS |
870 | const char *label; |
871 | unsigned sreg; | |
c53aa195 JM |
872 | { |
873 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0); | |
874 | } | |
875 | ||
3f76745e JM |
876 | /* Record the initial position of the return address. RTL is |
877 | INCOMING_RETURN_ADDR_RTX. */ | |
878 | ||
879 | static void | |
880 | initial_return_save (rtl) | |
b3694847 | 881 | rtx rtl; |
3f76745e | 882 | { |
973838fd | 883 | unsigned int reg = (unsigned int) -1; |
2ad9852d | 884 | HOST_WIDE_INT offset = 0; |
3f76745e JM |
885 | |
886 | switch (GET_CODE (rtl)) | |
887 | { | |
888 | case REG: | |
889 | /* RA is in a register. */ | |
2c849145 | 890 | reg = DWARF_FRAME_REGNUM (REGNO (rtl)); |
3f76745e | 891 | break; |
2ad9852d | 892 | |
3f76745e JM |
893 | case MEM: |
894 | /* RA is on the stack. */ | |
895 | rtl = XEXP (rtl, 0); | |
896 | switch (GET_CODE (rtl)) | |
897 | { | |
898 | case REG: | |
3a88cbd1 JL |
899 | if (REGNO (rtl) != STACK_POINTER_REGNUM) |
900 | abort (); | |
3f76745e JM |
901 | offset = 0; |
902 | break; | |
2ad9852d | 903 | |
3f76745e | 904 | case PLUS: |
3a88cbd1 JL |
905 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
906 | abort (); | |
3f76745e JM |
907 | offset = INTVAL (XEXP (rtl, 1)); |
908 | break; | |
2ad9852d | 909 | |
3f76745e | 910 | case MINUS: |
3a88cbd1 JL |
911 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
912 | abort (); | |
3f76745e JM |
913 | offset = -INTVAL (XEXP (rtl, 1)); |
914 | break; | |
2ad9852d | 915 | |
3f76745e JM |
916 | default: |
917 | abort (); | |
918 | } | |
2ad9852d | 919 | |
3f76745e | 920 | break; |
2ad9852d | 921 | |
c53aa195 JM |
922 | case PLUS: |
923 | /* The return address is at some offset from any value we can | |
924 | actually load. For instance, on the SPARC it is in %i7+8. Just | |
925 | ignore the offset for now; it doesn't matter for unwinding frames. */ | |
3a88cbd1 JL |
926 | if (GET_CODE (XEXP (rtl, 1)) != CONST_INT) |
927 | abort (); | |
c53aa195 JM |
928 | initial_return_save (XEXP (rtl, 0)); |
929 | return; | |
2ad9852d | 930 | |
a3f97cbb | 931 | default: |
3f76745e | 932 | abort (); |
a3f97cbb | 933 | } |
3f76745e | 934 | |
7d9d8943 | 935 | reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset); |
a3f97cbb JW |
936 | } |
937 | ||
1ba5ae8f | 938 | /* Given a SET, calculate the amount of stack adjustment it |
30f7a378 | 939 | contains. */ |
1ba5ae8f | 940 | |
5e640c56 AH |
941 | static long |
942 | stack_adjust_offset (pattern) | |
173bf5be | 943 | rtx pattern; |
1ba5ae8f AH |
944 | { |
945 | rtx src = SET_SRC (pattern); | |
946 | rtx dest = SET_DEST (pattern); | |
2ad9852d | 947 | HOST_WIDE_INT offset = 0; |
1ba5ae8f AH |
948 | enum rtx_code code; |
949 | ||
950 | if (dest == stack_pointer_rtx) | |
951 | { | |
952 | /* (set (reg sp) (plus (reg sp) (const_int))) */ | |
953 | code = GET_CODE (src); | |
954 | if (! (code == PLUS || code == MINUS) | |
955 | || XEXP (src, 0) != stack_pointer_rtx | |
956 | || GET_CODE (XEXP (src, 1)) != CONST_INT) | |
957 | return 0; | |
958 | ||
959 | offset = INTVAL (XEXP (src, 1)); | |
f472fa29 AM |
960 | if (code == PLUS) |
961 | offset = -offset; | |
1ba5ae8f AH |
962 | } |
963 | else if (GET_CODE (dest) == MEM) | |
964 | { | |
965 | /* (set (mem (pre_dec (reg sp))) (foo)) */ | |
966 | src = XEXP (dest, 0); | |
967 | code = GET_CODE (src); | |
968 | ||
c26fbbca KH |
969 | switch (code) |
970 | { | |
f472fa29 AM |
971 | case PRE_MODIFY: |
972 | case POST_MODIFY: | |
973 | if (XEXP (src, 0) == stack_pointer_rtx) | |
974 | { | |
975 | rtx val = XEXP (XEXP (src, 1), 1); | |
976 | /* We handle only adjustments by constant amount. */ | |
977 | if (GET_CODE (XEXP (src, 1)) != PLUS || | |
978 | GET_CODE (val) != CONST_INT) | |
c26fbbca | 979 | abort (); |
f472fa29 AM |
980 | offset = -INTVAL (val); |
981 | break; | |
982 | } | |
983 | return 0; | |
984 | ||
985 | case PRE_DEC: | |
986 | case POST_DEC: | |
987 | if (XEXP (src, 0) == stack_pointer_rtx) | |
988 | { | |
989 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
990 | break; | |
991 | } | |
992 | return 0; | |
993 | ||
994 | case PRE_INC: | |
995 | case POST_INC: | |
996 | if (XEXP (src, 0) == stack_pointer_rtx) | |
997 | { | |
998 | offset = -GET_MODE_SIZE (GET_MODE (dest)); | |
999 | break; | |
1000 | } | |
1001 | return 0; | |
2ad9852d | 1002 | |
f472fa29 AM |
1003 | default: |
1004 | return 0; | |
e2134eea | 1005 | } |
1ba5ae8f AH |
1006 | } |
1007 | else | |
1008 | return 0; | |
1009 | ||
1ba5ae8f AH |
1010 | return offset; |
1011 | } | |
1012 | ||
0021b564 JM |
1013 | /* Check INSN to see if it looks like a push or a stack adjustment, and |
1014 | make a note of it if it does. EH uses this information to find out how | |
1015 | much extra space it needs to pop off the stack. */ | |
1016 | ||
1017 | static void | |
1018 | dwarf2out_stack_adjust (insn) | |
1019 | rtx insn; | |
1020 | { | |
2ad9852d | 1021 | HOST_WIDE_INT offset; |
d3e3972c | 1022 | const char *label; |
2ad9852d | 1023 | int i; |
0021b564 | 1024 | |
2ad9852d | 1025 | if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN) |
b57d9225 JM |
1026 | { |
1027 | /* Extract the size of the args from the CALL rtx itself. */ | |
b57d9225 JM |
1028 | insn = PATTERN (insn); |
1029 | if (GET_CODE (insn) == PARALLEL) | |
1030 | insn = XVECEXP (insn, 0, 0); | |
1031 | if (GET_CODE (insn) == SET) | |
1032 | insn = SET_SRC (insn); | |
3db35af4 MM |
1033 | if (GET_CODE (insn) != CALL) |
1034 | abort (); | |
2ad9852d | 1035 | |
b57d9225 JM |
1036 | dwarf2out_args_size ("", INTVAL (XEXP (insn, 1))); |
1037 | return; | |
1038 | } | |
1039 | ||
1040 | /* If only calls can throw, and we have a frame pointer, | |
1041 | save up adjustments until we see the CALL_INSN. */ | |
2ad9852d | 1042 | else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM) |
b57d9225 JM |
1043 | return; |
1044 | ||
6020d360 | 1045 | if (GET_CODE (insn) == BARRIER) |
0021b564 | 1046 | { |
6020d360 JM |
1047 | /* When we see a BARRIER, we know to reset args_size to 0. Usually |
1048 | the compiler will have already emitted a stack adjustment, but | |
1049 | doesn't bother for calls to noreturn functions. */ | |
1050 | #ifdef STACK_GROWS_DOWNWARD | |
1051 | offset = -args_size; | |
1052 | #else | |
1053 | offset = args_size; | |
1054 | #endif | |
0021b564 | 1055 | } |
6020d360 | 1056 | else if (GET_CODE (PATTERN (insn)) == SET) |
2ad9852d | 1057 | offset = stack_adjust_offset (PATTERN (insn)); |
1ba5ae8f AH |
1058 | else if (GET_CODE (PATTERN (insn)) == PARALLEL |
1059 | || GET_CODE (PATTERN (insn)) == SEQUENCE) | |
1060 | { | |
1061 | /* There may be stack adjustments inside compound insns. Search | |
2ad9852d RK |
1062 | for them. */ |
1063 | for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--) | |
1064 | if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET) | |
1065 | offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i)); | |
0021b564 JM |
1066 | } |
1067 | else | |
1068 | return; | |
0b34cf1e | 1069 | |
6020d360 JM |
1070 | if (offset == 0) |
1071 | return; | |
1072 | ||
7d9d8943 AM |
1073 | if (cfa.reg == STACK_POINTER_REGNUM) |
1074 | cfa.offset += offset; | |
0021b564 JM |
1075 | |
1076 | #ifndef STACK_GROWS_DOWNWARD | |
1077 | offset = -offset; | |
1078 | #endif | |
2ad9852d | 1079 | |
0021b564 JM |
1080 | args_size += offset; |
1081 | if (args_size < 0) | |
1082 | args_size = 0; | |
1083 | ||
1084 | label = dwarf2out_cfi_label (); | |
7d9d8943 | 1085 | def_cfa_1 (label, &cfa); |
0021b564 JM |
1086 | dwarf2out_args_size (label, args_size); |
1087 | } | |
1088 | ||
fbfa55b0 RH |
1089 | /* We delay emitting a register save until either (a) we reach the end |
1090 | of the prologue or (b) the register is clobbered. This clusters | |
1091 | register saves so that there are fewer pc advances. */ | |
1092 | ||
1093 | struct queued_reg_save | |
1094 | { | |
1095 | struct queued_reg_save *next; | |
1096 | rtx reg; | |
1097 | long cfa_offset; | |
1098 | }; | |
1099 | ||
1100 | static struct queued_reg_save *queued_reg_saves; | |
1101 | static const char *last_reg_save_label; | |
1102 | ||
1103 | static void | |
1104 | queue_reg_save (label, reg, offset) | |
1105 | const char *label; | |
1106 | rtx reg; | |
1107 | long offset; | |
1108 | { | |
1109 | struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q)); | |
1110 | ||
1111 | q->next = queued_reg_saves; | |
1112 | q->reg = reg; | |
1113 | q->cfa_offset = offset; | |
1114 | queued_reg_saves = q; | |
1115 | ||
1116 | last_reg_save_label = label; | |
1117 | } | |
1118 | ||
1119 | static void | |
1120 | flush_queued_reg_saves () | |
1121 | { | |
1122 | struct queued_reg_save *q, *next; | |
1123 | ||
c26fbbca | 1124 | for (q = queued_reg_saves; q; q = next) |
fbfa55b0 RH |
1125 | { |
1126 | dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset); | |
1127 | next = q->next; | |
1128 | free (q); | |
1129 | } | |
1130 | ||
1131 | queued_reg_saves = NULL; | |
1132 | last_reg_save_label = NULL; | |
1133 | } | |
1134 | ||
1135 | static bool | |
1136 | clobbers_queued_reg_save (insn) | |
1137 | rtx insn; | |
1138 | { | |
1139 | struct queued_reg_save *q; | |
1140 | ||
c26fbbca | 1141 | for (q = queued_reg_saves; q; q = q->next) |
fbfa55b0 RH |
1142 | if (modified_in_p (q->reg, insn)) |
1143 | return true; | |
1144 | ||
1145 | return false; | |
1146 | } | |
c26fbbca | 1147 | |
fbfa55b0 | 1148 | |
770ca8c6 JO |
1149 | /* A temporary register holding an integral value used in adjusting SP |
1150 | or setting up the store_reg. The "offset" field holds the integer | |
1151 | value, not an offset. */ | |
fbfa55b0 | 1152 | static dw_cfa_location cfa_temp; |
770ca8c6 JO |
1153 | |
1154 | /* Record call frame debugging information for an expression EXPR, | |
1155 | which either sets SP or FP (adjusting how we calculate the frame | |
1156 | address) or saves a register to the stack. LABEL indicates the | |
1157 | address of EXPR. | |
1158 | ||
1159 | This function encodes a state machine mapping rtxes to actions on | |
1160 | cfa, cfa_store, and cfa_temp.reg. We describe these rules so | |
1161 | users need not read the source code. | |
1162 | ||
a401107d JO |
1163 | The High-Level Picture |
1164 | ||
1165 | Changes in the register we use to calculate the CFA: Currently we | |
1166 | assume that if you copy the CFA register into another register, we | |
1167 | should take the other one as the new CFA register; this seems to | |
1168 | work pretty well. If it's wrong for some target, it's simple | |
1169 | enough not to set RTX_FRAME_RELATED_P on the insn in question. | |
1170 | ||
1171 | Changes in the register we use for saving registers to the stack: | |
1172 | This is usually SP, but not always. Again, we deduce that if you | |
1173 | copy SP into another register (and SP is not the CFA register), | |
1174 | then the new register is the one we will be using for register | |
1175 | saves. This also seems to work. | |
1176 | ||
1177 | Register saves: There's not much guesswork about this one; if | |
1178 | RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a | |
1179 | register save, and the register used to calculate the destination | |
1180 | had better be the one we think we're using for this purpose. | |
1181 | ||
1182 | Except: If the register being saved is the CFA register, and the | |
cc2902df | 1183 | offset is nonzero, we are saving the CFA, so we assume we have to |
a401107d JO |
1184 | use DW_CFA_def_cfa_expression. If the offset is 0, we assume that |
1185 | the intent is to save the value of SP from the previous frame. | |
1186 | ||
770ca8c6 JO |
1187 | Invariants / Summaries of Rules |
1188 | ||
a401107d JO |
1189 | cfa current rule for calculating the CFA. It usually |
1190 | consists of a register and an offset. | |
770ca8c6 JO |
1191 | cfa_store register used by prologue code to save things to the stack |
1192 | cfa_store.offset is the offset from the value of | |
1193 | cfa_store.reg to the actual CFA | |
1194 | cfa_temp register holding an integral value. cfa_temp.offset | |
1195 | stores the value, which will be used to adjust the | |
19ec6a36 AM |
1196 | stack pointer. cfa_temp is also used like cfa_store, |
1197 | to track stores to the stack via fp or a temp reg. | |
c26fbbca | 1198 | |
770ca8c6 JO |
1199 | Rules 1- 4: Setting a register's value to cfa.reg or an expression |
1200 | with cfa.reg as the first operand changes the cfa.reg and its | |
19ec6a36 AM |
1201 | cfa.offset. Rule 1 and 4 also set cfa_temp.reg and |
1202 | cfa_temp.offset. | |
770ca8c6 JO |
1203 | |
1204 | Rules 6- 9: Set a non-cfa.reg register value to a constant or an | |
1205 | expression yielding a constant. This sets cfa_temp.reg | |
1206 | and cfa_temp.offset. | |
1207 | ||
1208 | Rule 5: Create a new register cfa_store used to save items to the | |
1209 | stack. | |
1210 | ||
19ec6a36 | 1211 | Rules 10-14: Save a register to the stack. Define offset as the |
a401107d | 1212 | difference of the original location and cfa_store's |
19ec6a36 | 1213 | location (or cfa_temp's location if cfa_temp is used). |
770ca8c6 JO |
1214 | |
1215 | The Rules | |
1216 | ||
1217 | "{a,b}" indicates a choice of a xor b. | |
1218 | "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg. | |
1219 | ||
1220 | Rule 1: | |
1221 | (set <reg1> <reg2>:cfa.reg) | |
19ec6a36 | 1222 | effects: cfa.reg = <reg1> |
770ca8c6 | 1223 | cfa.offset unchanged |
19ec6a36 AM |
1224 | cfa_temp.reg = <reg1> |
1225 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1226 | |
1227 | Rule 2: | |
2ad9852d RK |
1228 | (set sp ({minus,plus,losum} {sp,fp}:cfa.reg |
1229 | {<const_int>,<reg>:cfa_temp.reg})) | |
770ca8c6 JO |
1230 | effects: cfa.reg = sp if fp used |
1231 | cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp | |
1232 | cfa_store.offset += {+/- <const_int>, cfa_temp.offset} | |
1233 | if cfa_store.reg==sp | |
1234 | ||
1235 | Rule 3: | |
19ec6a36 | 1236 | (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>)) |
770ca8c6 JO |
1237 | effects: cfa.reg = fp |
1238 | cfa_offset += +/- <const_int> | |
1239 | ||
1240 | Rule 4: | |
19ec6a36 | 1241 | (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>)) |
770ca8c6 JO |
1242 | constraints: <reg1> != fp |
1243 | <reg1> != sp | |
1244 | effects: cfa.reg = <reg1> | |
19ec6a36 AM |
1245 | cfa_temp.reg = <reg1> |
1246 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1247 | |
1248 | Rule 5: | |
1249 | (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg)) | |
1250 | constraints: <reg1> != fp | |
1251 | <reg1> != sp | |
1252 | effects: cfa_store.reg = <reg1> | |
1253 | cfa_store.offset = cfa.offset - cfa_temp.offset | |
1254 | ||
1255 | Rule 6: | |
1256 | (set <reg> <const_int>) | |
1257 | effects: cfa_temp.reg = <reg> | |
1258 | cfa_temp.offset = <const_int> | |
1259 | ||
1260 | Rule 7: | |
1261 | (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>)) | |
1262 | effects: cfa_temp.reg = <reg1> | |
1263 | cfa_temp.offset |= <const_int> | |
1264 | ||
1265 | Rule 8: | |
1266 | (set <reg> (high <exp>)) | |
1267 | effects: none | |
1268 | ||
1269 | Rule 9: | |
1270 | (set <reg> (lo_sum <exp> <const_int>)) | |
1271 | effects: cfa_temp.reg = <reg> | |
1272 | cfa_temp.offset = <const_int> | |
1273 | ||
1274 | Rule 10: | |
1275 | (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>) | |
1276 | effects: cfa_store.offset -= <const_int> | |
1277 | cfa.offset = cfa_store.offset if cfa.reg == sp | |
770ca8c6 | 1278 | cfa.reg = sp |
19ec6a36 | 1279 | cfa.base_offset = -cfa_store.offset |
770ca8c6 JO |
1280 | |
1281 | Rule 11: | |
1282 | (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>) | |
1283 | effects: cfa_store.offset += -/+ mode_size(mem) | |
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 12: | |
2ad9852d RK |
1289 | (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) |
1290 | ||
1291 | <reg2>) | |
19ec6a36 AM |
1292 | effects: cfa.reg = <reg1> |
1293 | cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset | |
770ca8c6 JO |
1294 | |
1295 | Rule 13: | |
19ec6a36 AM |
1296 | (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>) |
1297 | effects: cfa.reg = <reg1> | |
1298 | cfa.base_offset = -{cfa_store,cfa_temp}.offset | |
1299 | ||
1300 | Rule 14: | |
1301 | (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>) | |
1302 | effects: cfa.reg = <reg1> | |
1303 | cfa.base_offset = -cfa_temp.offset | |
1304 | cfa_temp.offset -= mode_size(mem) */ | |
b664de3a AM |
1305 | |
1306 | static void | |
1307 | dwarf2out_frame_debug_expr (expr, label) | |
1308 | rtx expr; | |
d3e3972c | 1309 | const char *label; |
b664de3a AM |
1310 | { |
1311 | rtx src, dest; | |
2ad9852d | 1312 | HOST_WIDE_INT offset; |
556273e0 KH |
1313 | |
1314 | /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of | |
1315 | the PARALLEL independently. The first element is always processed if | |
770ca8c6 | 1316 | it is a SET. This is for backward compatibility. Other elements |
556273e0 KH |
1317 | are processed only if they are SETs and the RTX_FRAME_RELATED_P |
1318 | flag is set in them. */ | |
2ad9852d | 1319 | if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE) |
556273e0 | 1320 | { |
b664de3a AM |
1321 | int par_index; |
1322 | int limit = XVECLEN (expr, 0); | |
1323 | ||
1324 | for (par_index = 0; par_index < limit; par_index++) | |
2ad9852d RK |
1325 | if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET |
1326 | && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index)) | |
1327 | || par_index == 0)) | |
1328 | dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label); | |
556273e0 | 1329 | |
b664de3a AM |
1330 | return; |
1331 | } | |
556273e0 | 1332 | |
b664de3a AM |
1333 | if (GET_CODE (expr) != SET) |
1334 | abort (); | |
1335 | ||
1336 | src = SET_SRC (expr); | |
1337 | dest = SET_DEST (expr); | |
1338 | ||
1339 | switch (GET_CODE (dest)) | |
1340 | { | |
1341 | case REG: | |
770ca8c6 | 1342 | /* Rule 1 */ |
b664de3a AM |
1343 | /* Update the CFA rule wrt SP or FP. Make sure src is |
1344 | relative to the current CFA register. */ | |
1345 | switch (GET_CODE (src)) | |
556273e0 KH |
1346 | { |
1347 | /* Setting FP from SP. */ | |
1348 | case REG: | |
1349 | if (cfa.reg == (unsigned) REGNO (src)) | |
1350 | /* OK. */ | |
1351 | ; | |
626d1efd | 1352 | else |
556273e0 | 1353 | abort (); |
2c849145 JM |
1354 | |
1355 | /* We used to require that dest be either SP or FP, but the | |
1356 | ARM copies SP to a temporary register, and from there to | |
1357 | FP. So we just rely on the backends to only set | |
1358 | RTX_FRAME_RELATED_P on appropriate insns. */ | |
556273e0 | 1359 | cfa.reg = REGNO (dest); |
19ec6a36 AM |
1360 | cfa_temp.reg = cfa.reg; |
1361 | cfa_temp.offset = cfa.offset; | |
556273e0 | 1362 | break; |
b664de3a | 1363 | |
556273e0 KH |
1364 | case PLUS: |
1365 | case MINUS: | |
19ec6a36 | 1366 | case LO_SUM: |
556273e0 KH |
1367 | if (dest == stack_pointer_rtx) |
1368 | { | |
770ca8c6 | 1369 | /* Rule 2 */ |
2618f955 MM |
1370 | /* Adjusting SP. */ |
1371 | switch (GET_CODE (XEXP (src, 1))) | |
1372 | { | |
1373 | case CONST_INT: | |
1374 | offset = INTVAL (XEXP (src, 1)); | |
1375 | break; | |
1376 | case REG: | |
770ca8c6 | 1377 | if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg) |
2618f955 | 1378 | abort (); |
770ca8c6 | 1379 | offset = cfa_temp.offset; |
2618f955 MM |
1380 | break; |
1381 | default: | |
1382 | abort (); | |
1383 | } | |
1384 | ||
1385 | if (XEXP (src, 0) == hard_frame_pointer_rtx) | |
1386 | { | |
1387 | /* Restoring SP from FP in the epilogue. */ | |
7d9d8943 | 1388 | if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM) |
2618f955 | 1389 | abort (); |
7d9d8943 | 1390 | cfa.reg = STACK_POINTER_REGNUM; |
2618f955 | 1391 | } |
19ec6a36 AM |
1392 | else if (GET_CODE (src) == LO_SUM) |
1393 | /* Assume we've set the source reg of the LO_SUM from sp. */ | |
1394 | ; | |
2618f955 MM |
1395 | else if (XEXP (src, 0) != stack_pointer_rtx) |
1396 | abort (); | |
1397 | ||
19ec6a36 | 1398 | if (GET_CODE (src) != MINUS) |
2618f955 | 1399 | offset = -offset; |
7d9d8943 AM |
1400 | if (cfa.reg == STACK_POINTER_REGNUM) |
1401 | cfa.offset += offset; | |
1402 | if (cfa_store.reg == STACK_POINTER_REGNUM) | |
1403 | cfa_store.offset += offset; | |
556273e0 KH |
1404 | } |
1405 | else if (dest == hard_frame_pointer_rtx) | |
1406 | { | |
770ca8c6 | 1407 | /* Rule 3 */ |
2618f955 MM |
1408 | /* Either setting the FP from an offset of the SP, |
1409 | or adjusting the FP */ | |
2c849145 | 1410 | if (! frame_pointer_needed) |
2618f955 MM |
1411 | abort (); |
1412 | ||
2c849145 | 1413 | if (GET_CODE (XEXP (src, 0)) == REG |
7d9d8943 | 1414 | && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg |
2618f955 MM |
1415 | && GET_CODE (XEXP (src, 1)) == CONST_INT) |
1416 | { | |
2618f955 | 1417 | offset = INTVAL (XEXP (src, 1)); |
19ec6a36 | 1418 | if (GET_CODE (src) != MINUS) |
2618f955 | 1419 | offset = -offset; |
7d9d8943 AM |
1420 | cfa.offset += offset; |
1421 | cfa.reg = HARD_FRAME_POINTER_REGNUM; | |
2618f955 | 1422 | } |
556273e0 KH |
1423 | else |
1424 | abort (); | |
1425 | } | |
1426 | else | |
1427 | { | |
19ec6a36 | 1428 | if (GET_CODE (src) == MINUS) |
2618f955 | 1429 | abort (); |
b53ef1a2 | 1430 | |
770ca8c6 | 1431 | /* Rule 4 */ |
b53ef1a2 NC |
1432 | if (GET_CODE (XEXP (src, 0)) == REG |
1433 | && REGNO (XEXP (src, 0)) == cfa.reg | |
1434 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
34ce3d7b JM |
1435 | { |
1436 | /* Setting a temporary CFA register that will be copied | |
1437 | into the FP later on. */ | |
19ec6a36 | 1438 | offset = - INTVAL (XEXP (src, 1)); |
34ce3d7b JM |
1439 | cfa.offset += offset; |
1440 | cfa.reg = REGNO (dest); | |
19ec6a36 AM |
1441 | /* Or used to save regs to the stack. */ |
1442 | cfa_temp.reg = cfa.reg; | |
1443 | cfa_temp.offset = cfa.offset; | |
34ce3d7b | 1444 | } |
2ad9852d | 1445 | |
770ca8c6 | 1446 | /* Rule 5 */ |
19ec6a36 AM |
1447 | else if (GET_CODE (XEXP (src, 0)) == REG |
1448 | && REGNO (XEXP (src, 0)) == cfa_temp.reg | |
1449 | && XEXP (src, 1) == stack_pointer_rtx) | |
b53ef1a2 | 1450 | { |
00a42e21 JM |
1451 | /* Setting a scratch register that we will use instead |
1452 | of SP for saving registers to the stack. */ | |
b53ef1a2 NC |
1453 | if (cfa.reg != STACK_POINTER_REGNUM) |
1454 | abort (); | |
1455 | cfa_store.reg = REGNO (dest); | |
770ca8c6 | 1456 | cfa_store.offset = cfa.offset - cfa_temp.offset; |
b53ef1a2 | 1457 | } |
2ad9852d | 1458 | |
19ec6a36 AM |
1459 | /* Rule 9 */ |
1460 | else if (GET_CODE (src) == LO_SUM | |
1461 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
1462 | { | |
1463 | cfa_temp.reg = REGNO (dest); | |
1464 | cfa_temp.offset = INTVAL (XEXP (src, 1)); | |
1465 | } | |
1466 | else | |
1467 | abort (); | |
556273e0 KH |
1468 | } |
1469 | break; | |
b664de3a | 1470 | |
770ca8c6 | 1471 | /* Rule 6 */ |
556273e0 | 1472 | case CONST_INT: |
770ca8c6 JO |
1473 | cfa_temp.reg = REGNO (dest); |
1474 | cfa_temp.offset = INTVAL (src); | |
556273e0 | 1475 | break; |
b664de3a | 1476 | |
770ca8c6 | 1477 | /* Rule 7 */ |
556273e0 KH |
1478 | case IOR: |
1479 | if (GET_CODE (XEXP (src, 0)) != REG | |
770ca8c6 | 1480 | || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg |
2618f955 | 1481 | || GET_CODE (XEXP (src, 1)) != CONST_INT) |
556273e0 | 1482 | abort (); |
2ad9852d | 1483 | |
770ca8c6 JO |
1484 | if ((unsigned) REGNO (dest) != cfa_temp.reg) |
1485 | cfa_temp.reg = REGNO (dest); | |
1486 | cfa_temp.offset |= INTVAL (XEXP (src, 1)); | |
556273e0 | 1487 | break; |
b664de3a | 1488 | |
9ae21d2a AM |
1489 | /* Skip over HIGH, assuming it will be followed by a LO_SUM, |
1490 | which will fill in all of the bits. */ | |
1491 | /* Rule 8 */ | |
1492 | case HIGH: | |
1493 | break; | |
1494 | ||
556273e0 KH |
1495 | default: |
1496 | abort (); | |
1497 | } | |
2ad9852d | 1498 | |
7d9d8943 | 1499 | def_cfa_1 (label, &cfa); |
2618f955 | 1500 | break; |
b664de3a | 1501 | |
2618f955 | 1502 | case MEM: |
2618f955 MM |
1503 | if (GET_CODE (src) != REG) |
1504 | abort (); | |
7d9d8943 | 1505 | |
7d9d8943 AM |
1506 | /* Saving a register to the stack. Make sure dest is relative to the |
1507 | CFA register. */ | |
2618f955 MM |
1508 | switch (GET_CODE (XEXP (dest, 0))) |
1509 | { | |
770ca8c6 | 1510 | /* Rule 10 */ |
2618f955 | 1511 | /* With a push. */ |
e2134eea JH |
1512 | case PRE_MODIFY: |
1513 | /* We can't handle variable size modifications. */ | |
1514 | if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT) | |
173bf5be | 1515 | abort (); |
e2134eea JH |
1516 | offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1)); |
1517 | ||
1518 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM | |
1519 | || cfa_store.reg != STACK_POINTER_REGNUM) | |
1520 | abort (); | |
2ad9852d | 1521 | |
e2134eea JH |
1522 | cfa_store.offset += offset; |
1523 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1524 | cfa.offset = cfa_store.offset; | |
1525 | ||
1526 | offset = -cfa_store.offset; | |
1527 | break; | |
2ad9852d | 1528 | |
770ca8c6 | 1529 | /* Rule 11 */ |
2618f955 MM |
1530 | case PRE_INC: |
1531 | case PRE_DEC: | |
1532 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1533 | if (GET_CODE (XEXP (dest, 0)) == PRE_INC) | |
1534 | offset = -offset; | |
b664de3a | 1535 | |
2618f955 | 1536 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM |
7d9d8943 | 1537 | || cfa_store.reg != STACK_POINTER_REGNUM) |
2618f955 | 1538 | abort (); |
2ad9852d | 1539 | |
7d9d8943 AM |
1540 | cfa_store.offset += offset; |
1541 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1542 | cfa.offset = cfa_store.offset; | |
b664de3a | 1543 | |
7d9d8943 | 1544 | offset = -cfa_store.offset; |
2618f955 | 1545 | break; |
b664de3a | 1546 | |
770ca8c6 | 1547 | /* Rule 12 */ |
2618f955 MM |
1548 | /* With an offset. */ |
1549 | case PLUS: | |
1550 | case MINUS: | |
19ec6a36 | 1551 | case LO_SUM: |
770ca8c6 JO |
1552 | if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT) |
1553 | abort (); | |
2618f955 MM |
1554 | offset = INTVAL (XEXP (XEXP (dest, 0), 1)); |
1555 | if (GET_CODE (XEXP (dest, 0)) == MINUS) | |
1556 | offset = -offset; | |
b664de3a | 1557 | |
19ec6a36 AM |
1558 | if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) |
1559 | offset -= cfa_store.offset; | |
1560 | else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) | |
1561 | offset -= cfa_temp.offset; | |
1562 | else | |
2618f955 | 1563 | abort (); |
2618f955 MM |
1564 | break; |
1565 | ||
770ca8c6 | 1566 | /* Rule 13 */ |
2618f955 MM |
1567 | /* Without an offset. */ |
1568 | case REG: | |
19ec6a36 AM |
1569 | if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0))) |
1570 | offset = -cfa_store.offset; | |
1571 | else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0))) | |
1572 | offset = -cfa_temp.offset; | |
1573 | else | |
556273e0 | 1574 | abort (); |
19ec6a36 AM |
1575 | break; |
1576 | ||
1577 | /* Rule 14 */ | |
1578 | case POST_INC: | |
1579 | if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) | |
1580 | abort (); | |
1581 | offset = -cfa_temp.offset; | |
1582 | cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest)); | |
2618f955 MM |
1583 | break; |
1584 | ||
1585 | default: | |
1586 | abort (); | |
1587 | } | |
e09bbb25 | 1588 | |
556273e0 | 1589 | if (REGNO (src) != STACK_POINTER_REGNUM |
e09bbb25 JM |
1590 | && REGNO (src) != HARD_FRAME_POINTER_REGNUM |
1591 | && (unsigned) REGNO (src) == cfa.reg) | |
1592 | { | |
1593 | /* We're storing the current CFA reg into the stack. */ | |
1594 | ||
1595 | if (cfa.offset == 0) | |
1596 | { | |
1597 | /* If the source register is exactly the CFA, assume | |
1598 | we're saving SP like any other register; this happens | |
1599 | on the ARM. */ | |
e09bbb25 | 1600 | def_cfa_1 (label, &cfa); |
fbfa55b0 | 1601 | queue_reg_save (label, stack_pointer_rtx, offset); |
e09bbb25 JM |
1602 | break; |
1603 | } | |
1604 | else | |
1605 | { | |
1606 | /* Otherwise, we'll need to look in the stack to | |
1607 | calculate the CFA. */ | |
e09bbb25 | 1608 | rtx x = XEXP (dest, 0); |
2ad9852d | 1609 | |
e09bbb25 JM |
1610 | if (GET_CODE (x) != REG) |
1611 | x = XEXP (x, 0); | |
1612 | if (GET_CODE (x) != REG) | |
1613 | abort (); | |
2ad9852d RK |
1614 | |
1615 | cfa.reg = REGNO (x); | |
e09bbb25 JM |
1616 | cfa.base_offset = offset; |
1617 | cfa.indirect = 1; | |
1618 | def_cfa_1 (label, &cfa); | |
1619 | break; | |
1620 | } | |
1621 | } | |
1622 | ||
7d9d8943 | 1623 | def_cfa_1 (label, &cfa); |
fbfa55b0 | 1624 | queue_reg_save (label, src, offset); |
2618f955 MM |
1625 | break; |
1626 | ||
1627 | default: | |
1628 | abort (); | |
1629 | } | |
b664de3a AM |
1630 | } |
1631 | ||
3f76745e JM |
1632 | /* Record call frame debugging information for INSN, which either |
1633 | sets SP or FP (adjusting how we calculate the frame address) or saves a | |
1634 | register to the stack. If INSN is NULL_RTX, initialize our state. */ | |
71dfc51f | 1635 | |
3f76745e JM |
1636 | void |
1637 | dwarf2out_frame_debug (insn) | |
1638 | rtx insn; | |
a3f97cbb | 1639 | { |
d3e3972c | 1640 | const char *label; |
b664de3a | 1641 | rtx src; |
3f76745e JM |
1642 | |
1643 | if (insn == NULL_RTX) | |
a3f97cbb | 1644 | { |
fbfa55b0 RH |
1645 | /* Flush any queued register saves. */ |
1646 | flush_queued_reg_saves (); | |
1647 | ||
3f76745e | 1648 | /* Set up state for generating call frame debug info. */ |
7d9d8943 AM |
1649 | lookup_cfa (&cfa); |
1650 | if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)) | |
3a88cbd1 | 1651 | abort (); |
2ad9852d | 1652 | |
7d9d8943 AM |
1653 | cfa.reg = STACK_POINTER_REGNUM; |
1654 | cfa_store = cfa; | |
770ca8c6 JO |
1655 | cfa_temp.reg = -1; |
1656 | cfa_temp.offset = 0; | |
3f76745e JM |
1657 | return; |
1658 | } | |
1659 | ||
fbfa55b0 RH |
1660 | if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn)) |
1661 | flush_queued_reg_saves (); | |
1662 | ||
0021b564 JM |
1663 | if (! RTX_FRAME_RELATED_P (insn)) |
1664 | { | |
fbfa55b0 | 1665 | if (!ACCUMULATE_OUTGOING_ARGS) |
c26fbbca | 1666 | dwarf2out_stack_adjust (insn); |
2ad9852d | 1667 | |
0021b564 JM |
1668 | return; |
1669 | } | |
1670 | ||
3f76745e | 1671 | label = dwarf2out_cfi_label (); |
07ebc930 RH |
1672 | src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX); |
1673 | if (src) | |
1674 | insn = XEXP (src, 0); | |
556273e0 | 1675 | else |
07ebc930 RH |
1676 | insn = PATTERN (insn); |
1677 | ||
b664de3a | 1678 | dwarf2out_frame_debug_expr (insn, label); |
3f76745e JM |
1679 | } |
1680 | ||
3f76745e JM |
1681 | /* Output a Call Frame Information opcode and its operand(s). */ |
1682 | ||
1683 | static void | |
12f0b96b | 1684 | output_cfi (cfi, fde, for_eh) |
b3694847 SS |
1685 | dw_cfi_ref cfi; |
1686 | dw_fde_ref fde; | |
12f0b96b | 1687 | int for_eh; |
3f76745e JM |
1688 | { |
1689 | if (cfi->dw_cfi_opc == DW_CFA_advance_loc) | |
2ad9852d RK |
1690 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1691 | | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)), | |
1692 | "DW_CFA_advance_loc 0x%lx", | |
1693 | cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
3f76745e JM |
1694 | else if (cfi->dw_cfi_opc == DW_CFA_offset) |
1695 | { | |
2e4b9b8c RH |
1696 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1697 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)), | |
1698 | "DW_CFA_offset, column 0x%lx", | |
1699 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1700 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); | |
3f76745e JM |
1701 | } |
1702 | else if (cfi->dw_cfi_opc == DW_CFA_restore) | |
2ad9852d RK |
1703 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1704 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)), | |
1705 | "DW_CFA_restore, column 0x%lx", | |
1706 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
3f76745e JM |
1707 | else |
1708 | { | |
2e4b9b8c RH |
1709 | dw2_asm_output_data (1, cfi->dw_cfi_opc, |
1710 | "%s", dwarf_cfi_name (cfi->dw_cfi_opc)); | |
3f76745e | 1711 | |
3f76745e JM |
1712 | switch (cfi->dw_cfi_opc) |
1713 | { | |
1714 | case DW_CFA_set_loc: | |
e1f9550a RH |
1715 | if (for_eh) |
1716 | dw2_asm_output_encoded_addr_rtx ( | |
1717 | ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0), | |
1718 | gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr), | |
1719 | NULL); | |
1720 | else | |
1721 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, | |
1722 | cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL); | |
3f76745e | 1723 | break; |
2ad9852d | 1724 | |
3f76745e | 1725 | case DW_CFA_advance_loc1: |
2e4b9b8c RH |
1726 | dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1727 | fde->dw_fde_current_label, NULL); | |
bb727b5a | 1728 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
3f76745e | 1729 | break; |
2ad9852d | 1730 | |
3f76745e | 1731 | case DW_CFA_advance_loc2: |
2e4b9b8c RH |
1732 | dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1733 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
1734 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
1735 | break; | |
2ad9852d | 1736 | |
3f76745e | 1737 | case DW_CFA_advance_loc4: |
2e4b9b8c RH |
1738 | dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1739 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
1740 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
1741 | break; | |
2ad9852d | 1742 | |
3f76745e | 1743 | case DW_CFA_MIPS_advance_loc8: |
2e4b9b8c RH |
1744 | dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1745 | fde->dw_fde_current_label, NULL); | |
1746 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
3f76745e | 1747 | break; |
2ad9852d | 1748 | |
3f76745e JM |
1749 | case DW_CFA_offset_extended: |
1750 | case DW_CFA_def_cfa: | |
2ad9852d RK |
1751 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, |
1752 | NULL); | |
2e4b9b8c | 1753 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); |
3f76745e | 1754 | break; |
2ad9852d | 1755 | |
6bb28965 JM |
1756 | case DW_CFA_offset_extended_sf: |
1757 | case DW_CFA_def_cfa_sf: | |
1758 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, | |
1759 | NULL); | |
1760 | dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); | |
1761 | break; | |
1762 | ||
3f76745e JM |
1763 | case DW_CFA_restore_extended: |
1764 | case DW_CFA_undefined: | |
3f76745e JM |
1765 | case DW_CFA_same_value: |
1766 | case DW_CFA_def_cfa_register: | |
2ad9852d RK |
1767 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, |
1768 | NULL); | |
3f76745e | 1769 | break; |
2ad9852d | 1770 | |
3f76745e | 1771 | case DW_CFA_register: |
2ad9852d RK |
1772 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, |
1773 | NULL); | |
1774 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, | |
1775 | NULL); | |
3f76745e | 1776 | break; |
2ad9852d | 1777 | |
3f76745e | 1778 | case DW_CFA_def_cfa_offset: |
2e4b9b8c RH |
1779 | case DW_CFA_GNU_args_size: |
1780 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL); | |
3f76745e | 1781 | break; |
2ad9852d | 1782 | |
6bb28965 JM |
1783 | case DW_CFA_def_cfa_offset_sf: |
1784 | dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL); | |
1785 | break; | |
1786 | ||
c53aa195 JM |
1787 | case DW_CFA_GNU_window_save: |
1788 | break; | |
2ad9852d | 1789 | |
7d9d8943 | 1790 | case DW_CFA_def_cfa_expression: |
6bb28965 | 1791 | case DW_CFA_expression: |
7d9d8943 AM |
1792 | output_cfa_loc (cfi); |
1793 | break; | |
2ad9852d | 1794 | |
6bb28965 JM |
1795 | case DW_CFA_GNU_negative_offset_extended: |
1796 | /* Obsoleted by DW_CFA_offset_extended_sf. */ | |
1797 | abort (); | |
1798 | ||
3f76745e JM |
1799 | default: |
1800 | break; | |
1801 | } | |
556273e0 | 1802 | } |
3f76745e JM |
1803 | } |
1804 | ||
1805 | /* Output the call frame information used to used to record information | |
1806 | that relates to calculating the frame pointer, and records the | |
1807 | location of saved registers. */ | |
1808 | ||
1809 | static void | |
1810 | output_call_frame_info (for_eh) | |
1811 | int for_eh; | |
1812 | { | |
b3694847 SS |
1813 | unsigned int i; |
1814 | dw_fde_ref fde; | |
1815 | dw_cfi_ref cfi; | |
27d95cbe | 1816 | char l1[20], l2[20], section_start_label[20]; |
52a11cbf RH |
1817 | int any_lsda_needed = 0; |
1818 | char augmentation[6]; | |
e1f9550a RH |
1819 | int augmentation_size; |
1820 | int fde_encoding = DW_EH_PE_absptr; | |
1821 | int per_encoding = DW_EH_PE_absptr; | |
1822 | int lsda_encoding = DW_EH_PE_absptr; | |
3f76745e | 1823 | |
29b91443 JM |
1824 | /* Don't emit a CIE if there won't be any FDEs. */ |
1825 | if (fde_table_in_use == 0) | |
1826 | return; | |
1827 | ||
2ad9852d RK |
1828 | /* If we don't have any functions we'll want to unwind out of, don't emit any |
1829 | EH unwind information. */ | |
737faf14 JM |
1830 | if (for_eh) |
1831 | { | |
b932f770 | 1832 | int any_eh_needed = flag_asynchronous_unwind_tables; |
2ad9852d RK |
1833 | |
1834 | for (i = 0; i < fde_table_in_use; i++) | |
52a11cbf RH |
1835 | if (fde_table[i].uses_eh_lsda) |
1836 | any_eh_needed = any_lsda_needed = 1; | |
1837 | else if (! fde_table[i].nothrow) | |
1838 | any_eh_needed = 1; | |
1839 | ||
1840 | if (! any_eh_needed) | |
1841 | return; | |
737faf14 JM |
1842 | } |
1843 | ||
aa0c1401 JL |
1844 | /* We're going to be generating comments, so turn on app. */ |
1845 | if (flag_debug_asm) | |
1846 | app_enable (); | |
956d6950 | 1847 | |
3f76745e | 1848 | if (for_eh) |
07c9d2eb | 1849 | (*targetm.asm_out.eh_frame_section) (); |
3f76745e | 1850 | else |
715bdd29 | 1851 | named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG); |
3f76745e | 1852 | |
27d95cbe RH |
1853 | ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh); |
1854 | ASM_OUTPUT_LABEL (asm_out_file, section_start_label); | |
1855 | ||
556273e0 | 1856 | /* Output the CIE. */ |
a6ab3aad JM |
1857 | ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh); |
1858 | ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh); | |
2e4b9b8c RH |
1859 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
1860 | "Length of Common Information Entry"); | |
a6ab3aad JM |
1861 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1862 | ||
2e4b9b8c RH |
1863 | /* Now that the CIE pointer is PC-relative for EH, |
1864 | use 0 to identify the CIE. */ | |
1865 | dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE), | |
1866 | (for_eh ? 0 : DW_CIE_ID), | |
1867 | "CIE Identifier Tag"); | |
3f76745e | 1868 | |
2e4b9b8c | 1869 | dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version"); |
3f76745e | 1870 | |
52a11cbf | 1871 | augmentation[0] = 0; |
e1f9550a | 1872 | augmentation_size = 0; |
52a11cbf | 1873 | if (for_eh) |
a6ab3aad | 1874 | { |
e1f9550a RH |
1875 | char *p; |
1876 | ||
52a11cbf RH |
1877 | /* Augmentation: |
1878 | z Indicates that a uleb128 is present to size the | |
1879 | augmentation section. | |
e1f9550a RH |
1880 | L Indicates the encoding (and thus presence) of |
1881 | an LSDA pointer in the FDE augmentation. | |
1882 | R Indicates a non-default pointer encoding for | |
1883 | FDE code pointers. | |
1884 | P Indicates the presence of an encoding + language | |
1885 | personality routine in the CIE augmentation. */ | |
1886 | ||
1887 | fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0); | |
1888 | per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1); | |
1889 | lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0); | |
1890 | ||
1891 | p = augmentation + 1; | |
1892 | if (eh_personality_libfunc) | |
1893 | { | |
1894 | *p++ = 'P'; | |
1895 | augmentation_size += 1 + size_of_encoded_value (per_encoding); | |
1896 | } | |
52a11cbf | 1897 | if (any_lsda_needed) |
e1f9550a RH |
1898 | { |
1899 | *p++ = 'L'; | |
1900 | augmentation_size += 1; | |
1901 | } | |
1902 | if (fde_encoding != DW_EH_PE_absptr) | |
1903 | { | |
1904 | *p++ = 'R'; | |
1905 | augmentation_size += 1; | |
1906 | } | |
1907 | if (p > augmentation + 1) | |
1908 | { | |
1909 | augmentation[0] = 'z'; | |
c26fbbca | 1910 | *p = '\0'; |
e1f9550a | 1911 | } |
099c8b17 RH |
1912 | |
1913 | /* Ug. Some platforms can't do unaligned dynamic relocations at all. */ | |
1914 | if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned) | |
1915 | { | |
1916 | int offset = ( 4 /* Length */ | |
1917 | + 4 /* CIE Id */ | |
1918 | + 1 /* CIE version */ | |
1919 | + strlen (augmentation) + 1 /* Augmentation */ | |
1920 | + size_of_uleb128 (1) /* Code alignment */ | |
1921 | + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT) | |
1922 | + 1 /* RA column */ | |
1923 | + 1 /* Augmentation size */ | |
1924 | + 1 /* Personality encoding */ ); | |
1925 | int pad = -offset & (PTR_SIZE - 1); | |
1926 | ||
1927 | augmentation_size += pad; | |
1928 | ||
1929 | /* Augmentations should be small, so there's scarce need to | |
1930 | iterate for a solution. Die if we exceed one uleb128 byte. */ | |
1931 | if (size_of_uleb128 (augmentation_size) != 1) | |
1932 | abort (); | |
1933 | } | |
a6ab3aad | 1934 | } |
3f76745e | 1935 | |
2ad9852d | 1936 | dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation"); |
2e4b9b8c | 1937 | dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor"); |
2e4b9b8c RH |
1938 | dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT, |
1939 | "CIE Data Alignment Factor"); | |
2e4b9b8c | 1940 | dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column"); |
3f76745e | 1941 | |
52a11cbf RH |
1942 | if (augmentation[0]) |
1943 | { | |
e1f9550a | 1944 | dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size"); |
52a11cbf | 1945 | if (eh_personality_libfunc) |
e1f9550a RH |
1946 | { |
1947 | dw2_asm_output_data (1, per_encoding, "Personality (%s)", | |
1948 | eh_data_format_name (per_encoding)); | |
1949 | dw2_asm_output_encoded_addr_rtx (per_encoding, | |
1950 | eh_personality_libfunc, NULL); | |
1951 | } | |
2ad9852d | 1952 | |
e1f9550a RH |
1953 | if (any_lsda_needed) |
1954 | dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)", | |
1955 | eh_data_format_name (lsda_encoding)); | |
2ad9852d | 1956 | |
e1f9550a RH |
1957 | if (fde_encoding != DW_EH_PE_absptr) |
1958 | dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)", | |
1959 | eh_data_format_name (fde_encoding)); | |
52a11cbf RH |
1960 | } |
1961 | ||
3f76745e | 1962 | for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next) |
12f0b96b | 1963 | output_cfi (cfi, NULL, for_eh); |
3f76745e JM |
1964 | |
1965 | /* Pad the CIE out to an address sized boundary. */ | |
c26fbbca | 1966 | ASM_OUTPUT_ALIGN (asm_out_file, |
12f0b96b | 1967 | floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)); |
a6ab3aad | 1968 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e JM |
1969 | |
1970 | /* Loop through all of the FDE's. */ | |
2ad9852d | 1971 | for (i = 0; i < fde_table_in_use; i++) |
3f76745e JM |
1972 | { |
1973 | fde = &fde_table[i]; | |
3f76745e | 1974 | |
52a11cbf | 1975 | /* Don't emit EH unwind info for leaf functions that don't need it. */ |
b6128b8c SH |
1976 | if (!flag_asynchronous_unwind_tables && for_eh |
1977 | && (fde->nothrow || fde->all_throwers_are_sibcalls) | |
1978 | && !fde->uses_eh_lsda) | |
737faf14 JM |
1979 | continue; |
1980 | ||
4977bab6 | 1981 | (*targetm.asm_out.internal_label) (asm_out_file, FDE_LABEL, for_eh + i * 2); |
556273e0 KH |
1982 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2); |
1983 | ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2); | |
2e4b9b8c RH |
1984 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
1985 | "FDE Length"); | |
a6ab3aad JM |
1986 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1987 | ||
3f76745e | 1988 | if (for_eh) |
27d95cbe | 1989 | dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset"); |
3f76745e | 1990 | else |
27d95cbe | 1991 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label, |
2e4b9b8c | 1992 | "FDE CIE offset"); |
3f76745e | 1993 | |
e1f9550a RH |
1994 | if (for_eh) |
1995 | { | |
1996 | dw2_asm_output_encoded_addr_rtx (fde_encoding, | |
1997 | gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin), | |
1998 | "FDE initial location"); | |
1999 | dw2_asm_output_delta (size_of_encoded_value (fde_encoding), | |
c26fbbca | 2000 | fde->dw_fde_end, fde->dw_fde_begin, |
e1f9550a RH |
2001 | "FDE address range"); |
2002 | } | |
2003 | else | |
2004 | { | |
2005 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin, | |
2006 | "FDE initial location"); | |
c26fbbca KH |
2007 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, |
2008 | fde->dw_fde_end, fde->dw_fde_begin, | |
e1f9550a RH |
2009 | "FDE address range"); |
2010 | } | |
3f76745e | 2011 | |
52a11cbf RH |
2012 | if (augmentation[0]) |
2013 | { | |
e1f9550a | 2014 | if (any_lsda_needed) |
52a11cbf | 2015 | { |
099c8b17 RH |
2016 | int size = size_of_encoded_value (lsda_encoding); |
2017 | ||
2018 | if (lsda_encoding == DW_EH_PE_aligned) | |
2019 | { | |
2020 | int offset = ( 4 /* Length */ | |
2021 | + 4 /* CIE offset */ | |
2022 | + 2 * size_of_encoded_value (fde_encoding) | |
2023 | + 1 /* Augmentation size */ ); | |
2024 | int pad = -offset & (PTR_SIZE - 1); | |
2025 | ||
2026 | size += pad; | |
2027 | if (size_of_uleb128 (size) != 1) | |
2028 | abort (); | |
2029 | } | |
2030 | ||
2031 | dw2_asm_output_data_uleb128 (size, "Augmentation size"); | |
e1f9550a RH |
2032 | |
2033 | if (fde->uses_eh_lsda) | |
2034 | { | |
2035 | ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA", | |
2036 | fde->funcdef_number); | |
2037 | dw2_asm_output_encoded_addr_rtx ( | |
2038 | lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1), | |
2039 | "Language Specific Data Area"); | |
2040 | } | |
2041 | else | |
099c8b17 RH |
2042 | { |
2043 | if (lsda_encoding == DW_EH_PE_aligned) | |
2044 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); | |
2ad9852d RK |
2045 | dw2_asm_output_data |
2046 | (size_of_encoded_value (lsda_encoding), 0, | |
2047 | "Language Specific Data Area (none)"); | |
099c8b17 | 2048 | } |
52a11cbf RH |
2049 | } |
2050 | else | |
e1f9550a | 2051 | dw2_asm_output_data_uleb128 (0, "Augmentation size"); |
52a11cbf RH |
2052 | } |
2053 | ||
3f76745e JM |
2054 | /* Loop through the Call Frame Instructions associated with |
2055 | this FDE. */ | |
2056 | fde->dw_fde_current_label = fde->dw_fde_begin; | |
2057 | for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next) | |
12f0b96b | 2058 | output_cfi (cfi, fde, for_eh); |
3f76745e | 2059 | |
a6ab3aad | 2060 | /* Pad the FDE out to an address sized boundary. */ |
c26fbbca | 2061 | ASM_OUTPUT_ALIGN (asm_out_file, |
e1f9550a | 2062 | floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE))); |
a6ab3aad | 2063 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e | 2064 | } |
2e4b9b8c | 2065 | |
7606e68f | 2066 | if (for_eh && targetm.terminate_dw2_eh_frame_info) |
2e4b9b8c | 2067 | dw2_asm_output_data (4, 0, "End of Table"); |
a6ab3aad JM |
2068 | #ifdef MIPS_DEBUGGING_INFO |
2069 | /* Work around Irix 6 assembler bug whereby labels at the end of a section | |
2070 | get a value of 0. Putting .align 0 after the label fixes it. */ | |
2071 | ASM_OUTPUT_ALIGN (asm_out_file, 0); | |
2072 | #endif | |
aa0c1401 JL |
2073 | |
2074 | /* Turn off app to make assembly quicker. */ | |
2075 | if (flag_debug_asm) | |
2076 | app_disable (); | |
a6ab3aad JM |
2077 | } |
2078 | ||
3f76745e JM |
2079 | /* Output a marker (i.e. a label) for the beginning of a function, before |
2080 | the prologue. */ | |
2081 | ||
2082 | void | |
653e276c NB |
2083 | dwarf2out_begin_prologue (line, file) |
2084 | unsigned int line ATTRIBUTE_UNUSED; | |
2085 | const char *file ATTRIBUTE_UNUSED; | |
3f76745e JM |
2086 | { |
2087 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 | 2088 | dw_fde_ref fde; |
3f76745e | 2089 | |
2a1ee410 RH |
2090 | current_function_func_begin_label = 0; |
2091 | ||
2092 | #ifdef IA64_UNWIND_INFO | |
2093 | /* ??? current_function_func_begin_label is also used by except.c | |
2094 | for call-site information. We must emit this label if it might | |
2095 | be used. */ | |
2096 | if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS) | |
2097 | && ! dwarf2out_do_frame ()) | |
2098 | return; | |
2099 | #else | |
2100 | if (! dwarf2out_do_frame ()) | |
2101 | return; | |
2102 | #endif | |
2103 | ||
3f76745e JM |
2104 | function_section (current_function_decl); |
2105 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL, | |
df696a75 | 2106 | current_function_funcdef_no); |
2a1ee410 | 2107 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL, |
df696a75 | 2108 | current_function_funcdef_no); |
00262c8a | 2109 | current_function_func_begin_label = get_identifier (label); |
3f76745e | 2110 | |
2a1ee410 RH |
2111 | #ifdef IA64_UNWIND_INFO |
2112 | /* We can elide the fde allocation if we're not emitting debug info. */ | |
2113 | if (! dwarf2out_do_frame ()) | |
2114 | return; | |
2115 | #endif | |
2116 | ||
3f76745e JM |
2117 | /* Expand the fde table if necessary. */ |
2118 | if (fde_table_in_use == fde_table_allocated) | |
2119 | { | |
2120 | fde_table_allocated += FDE_TABLE_INCREMENT; | |
2121 | fde_table | |
2122 | = (dw_fde_ref) xrealloc (fde_table, | |
2123 | fde_table_allocated * sizeof (dw_fde_node)); | |
a3f97cbb | 2124 | } |
3f76745e JM |
2125 | |
2126 | /* Record the FDE associated with this function. */ | |
2127 | current_funcdef_fde = fde_table_in_use; | |
2128 | ||
2129 | /* Add the new FDE at the end of the fde_table. */ | |
2130 | fde = &fde_table[fde_table_in_use++]; | |
2131 | fde->dw_fde_begin = xstrdup (label); | |
2132 | fde->dw_fde_current_label = NULL; | |
2133 | fde->dw_fde_end = NULL; | |
2134 | fde->dw_fde_cfi = NULL; | |
df696a75 | 2135 | fde->funcdef_number = current_function_funcdef_no; |
fb13d4d0 | 2136 | fde->nothrow = current_function_nothrow; |
52a11cbf | 2137 | fde->uses_eh_lsda = cfun->uses_eh_lsda; |
b6128b8c | 2138 | fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls; |
737faf14 | 2139 | |
b57d9225 | 2140 | args_size = old_args_size = 0; |
653e276c | 2141 | |
2ad9852d RK |
2142 | /* We only want to output line number information for the genuine dwarf2 |
2143 | prologue case, not the eh frame case. */ | |
653e276c NB |
2144 | #ifdef DWARF2_DEBUGGING_INFO |
2145 | if (file) | |
2146 | dwarf2out_source_line (line, file); | |
2147 | #endif | |
3f76745e JM |
2148 | } |
2149 | ||
2150 | /* Output a marker (i.e. a label) for the absolute end of the generated code | |
2151 | for a function definition. This gets called *after* the epilogue code has | |
2152 | been generated. */ | |
2153 | ||
2154 | void | |
702ada3d DR |
2155 | dwarf2out_end_epilogue (line, file) |
2156 | unsigned int line ATTRIBUTE_UNUSED; | |
2157 | const char *file ATTRIBUTE_UNUSED; | |
3f76745e JM |
2158 | { |
2159 | dw_fde_ref fde; | |
2160 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2161 | ||
2162 | /* Output a label to mark the endpoint of the code generated for this | |
3ef42a0c | 2163 | function. */ |
df696a75 RH |
2164 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, |
2165 | current_function_funcdef_no); | |
3f76745e JM |
2166 | ASM_OUTPUT_LABEL (asm_out_file, label); |
2167 | fde = &fde_table[fde_table_in_use - 1]; | |
2168 | fde->dw_fde_end = xstrdup (label); | |
3f76745e JM |
2169 | } |
2170 | ||
2171 | void | |
2172 | dwarf2out_frame_init () | |
2173 | { | |
2174 | /* Allocate the initial hunk of the fde_table. */ | |
3de90026 | 2175 | fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node)); |
3f76745e JM |
2176 | fde_table_allocated = FDE_TABLE_INCREMENT; |
2177 | fde_table_in_use = 0; | |
2178 | ||
2179 | /* Generate the CFA instructions common to all FDE's. Do it now for the | |
2180 | sake of lookup_cfa. */ | |
2181 | ||
a6ab3aad | 2182 | #ifdef DWARF2_UNWIND_INFO |
91193900 AS |
2183 | /* On entry, the Canonical Frame Address is at SP. */ |
2184 | dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET); | |
2185 | initial_return_save (INCOMING_RETURN_ADDR_RTX); | |
3f76745e JM |
2186 | #endif |
2187 | } | |
2188 | ||
2189 | void | |
2190 | dwarf2out_frame_finish () | |
2191 | { | |
3f76745e | 2192 | /* Output call frame information. */ |
7a0c8d71 | 2193 | if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG) |
3f76745e | 2194 | output_call_frame_info (0); |
2ad9852d | 2195 | |
ddee9e8d | 2196 | if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions)) |
3f76745e | 2197 | output_call_frame_info (1); |
556273e0 | 2198 | } |
7d9d8943 AM |
2199 | \f |
2200 | /* And now, the subset of the debugging information support code necessary | |
2201 | for emitting location expressions. */ | |
3f76745e | 2202 | |
b9203463 RH |
2203 | /* We need some way to distinguish DW_OP_addr with a direct symbol |
2204 | relocation from DW_OP_addr with a dtp-relative symbol relocation. */ | |
2205 | #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr) | |
2206 | ||
2207 | ||
7d9d8943 AM |
2208 | typedef struct dw_val_struct *dw_val_ref; |
2209 | typedef struct die_struct *dw_die_ref; | |
2210 | typedef struct dw_loc_descr_struct *dw_loc_descr_ref; | |
63e46568 | 2211 | typedef struct dw_loc_list_struct *dw_loc_list_ref; |
3f76745e JM |
2212 | |
2213 | /* Each DIE may have a series of attribute/value pairs. Values | |
2214 | can take on several forms. The forms that are used in this | |
2215 | implementation are listed below. */ | |
2216 | ||
2217 | typedef enum | |
2218 | { | |
2219 | dw_val_class_addr, | |
a20612aa | 2220 | dw_val_class_offset, |
3f76745e | 2221 | dw_val_class_loc, |
63e46568 | 2222 | dw_val_class_loc_list, |
2bee6045 | 2223 | dw_val_class_range_list, |
3f76745e JM |
2224 | dw_val_class_const, |
2225 | dw_val_class_unsigned_const, | |
2226 | dw_val_class_long_long, | |
2227 | dw_val_class_float, | |
2228 | dw_val_class_flag, | |
2229 | dw_val_class_die_ref, | |
2230 | dw_val_class_fde_ref, | |
2231 | dw_val_class_lbl_id, | |
8b790721 | 2232 | dw_val_class_lbl_offset, |
3f76745e | 2233 | dw_val_class_str |
a3f97cbb | 2234 | } |
3f76745e | 2235 | dw_val_class; |
a3f97cbb | 2236 | |
3f76745e | 2237 | /* Describe a double word constant value. */ |
21217bd0 | 2238 | /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */ |
3f76745e JM |
2239 | |
2240 | typedef struct dw_long_long_struct | |
a3f97cbb | 2241 | { |
3f76745e JM |
2242 | unsigned long hi; |
2243 | unsigned long low; | |
2244 | } | |
2245 | dw_long_long_const; | |
2246 | ||
2247 | /* Describe a floating point constant value. */ | |
2248 | ||
2249 | typedef struct dw_fp_struct | |
2250 | { | |
2251 | long *array; | |
2252 | unsigned length; | |
2253 | } | |
2254 | dw_float_const; | |
2255 | ||
956d6950 | 2256 | /* The dw_val_node describes an attribute's value, as it is |
3f76745e JM |
2257 | represented internally. */ |
2258 | ||
2259 | typedef struct dw_val_struct | |
2260 | { | |
2261 | dw_val_class val_class; | |
2262 | union | |
a3f97cbb | 2263 | { |
1865dbb5 | 2264 | rtx val_addr; |
a20612aa | 2265 | long unsigned val_offset; |
63e46568 | 2266 | dw_loc_list_ref val_loc_list; |
3f76745e JM |
2267 | dw_loc_descr_ref val_loc; |
2268 | long int val_int; | |
2269 | long unsigned val_unsigned; | |
2270 | dw_long_long_const val_long_long; | |
2271 | dw_float_const val_float; | |
2ad9852d RK |
2272 | struct |
2273 | { | |
2274 | dw_die_ref die; | |
2275 | int external; | |
2276 | } val_die_ref; | |
3f76745e | 2277 | unsigned val_fde_index; |
9eb4015a | 2278 | struct indirect_string_node *val_str; |
3f76745e | 2279 | char *val_lbl_id; |
3f76745e | 2280 | unsigned char val_flag; |
a3f97cbb | 2281 | } |
3f76745e JM |
2282 | v; |
2283 | } | |
2284 | dw_val_node; | |
2285 | ||
2286 | /* Locations in memory are described using a sequence of stack machine | |
2287 | operations. */ | |
2288 | ||
2289 | typedef struct dw_loc_descr_struct | |
2290 | { | |
2291 | dw_loc_descr_ref dw_loc_next; | |
2292 | enum dwarf_location_atom dw_loc_opc; | |
2293 | dw_val_node dw_loc_oprnd1; | |
2294 | dw_val_node dw_loc_oprnd2; | |
d8041cc8 | 2295 | int dw_loc_addr; |
3f76745e JM |
2296 | } |
2297 | dw_loc_descr_node; | |
2298 | ||
63e46568 DB |
2299 | /* Location lists are ranges + location descriptions for that range, |
2300 | so you can track variables that are in different places over | |
30f7a378 | 2301 | their entire life. */ |
63e46568 DB |
2302 | typedef struct dw_loc_list_struct |
2303 | { | |
2304 | dw_loc_list_ref dw_loc_next; | |
2305 | const char *begin; /* Label for begin address of range */ | |
2306 | const char *end; /* Label for end address of range */ | |
2ad9852d RK |
2307 | char *ll_symbol; /* Label for beginning of location list. |
2308 | Only on head of list */ | |
63e46568 DB |
2309 | const char *section; /* Section this loclist is relative to */ |
2310 | dw_loc_descr_ref expr; | |
2311 | } dw_loc_list_node; | |
2312 | ||
7d9d8943 AM |
2313 | static const char *dwarf_stack_op_name PARAMS ((unsigned)); |
2314 | static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom, | |
2315 | unsigned long, | |
2316 | unsigned long)); | |
2317 | static void add_loc_descr PARAMS ((dw_loc_descr_ref *, | |
2318 | dw_loc_descr_ref)); | |
2319 | static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref)); | |
2320 | static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref)); | |
2321 | static void output_loc_operands PARAMS ((dw_loc_descr_ref)); | |
2322 | static void output_loc_sequence PARAMS ((dw_loc_descr_ref)); | |
3f76745e | 2323 | |
7d9d8943 | 2324 | /* Convert a DWARF stack opcode into its string name. */ |
3f76745e | 2325 | |
7d9d8943 AM |
2326 | static const char * |
2327 | dwarf_stack_op_name (op) | |
b3694847 | 2328 | unsigned op; |
ef76d03b | 2329 | { |
7d9d8943 AM |
2330 | switch (op) |
2331 | { | |
2332 | case DW_OP_addr: | |
b9203463 | 2333 | case INTERNAL_DW_OP_tls_addr: |
7d9d8943 AM |
2334 | return "DW_OP_addr"; |
2335 | case DW_OP_deref: | |
2336 | return "DW_OP_deref"; | |
2337 | case DW_OP_const1u: | |
2338 | return "DW_OP_const1u"; | |
2339 | case DW_OP_const1s: | |
2340 | return "DW_OP_const1s"; | |
2341 | case DW_OP_const2u: | |
2342 | return "DW_OP_const2u"; | |
2343 | case DW_OP_const2s: | |
2344 | return "DW_OP_const2s"; | |
2345 | case DW_OP_const4u: | |
2346 | return "DW_OP_const4u"; | |
2347 | case DW_OP_const4s: | |
2348 | return "DW_OP_const4s"; | |
2349 | case DW_OP_const8u: | |
2350 | return "DW_OP_const8u"; | |
2351 | case DW_OP_const8s: | |
2352 | return "DW_OP_const8s"; | |
2353 | case DW_OP_constu: | |
2354 | return "DW_OP_constu"; | |
2355 | case DW_OP_consts: | |
2356 | return "DW_OP_consts"; | |
2357 | case DW_OP_dup: | |
2358 | return "DW_OP_dup"; | |
2359 | case DW_OP_drop: | |
2360 | return "DW_OP_drop"; | |
2361 | case DW_OP_over: | |
2362 | return "DW_OP_over"; | |
2363 | case DW_OP_pick: | |
2364 | return "DW_OP_pick"; | |
2365 | case DW_OP_swap: | |
2366 | return "DW_OP_swap"; | |
2367 | case DW_OP_rot: | |
2368 | return "DW_OP_rot"; | |
2369 | case DW_OP_xderef: | |
2370 | return "DW_OP_xderef"; | |
2371 | case DW_OP_abs: | |
2372 | return "DW_OP_abs"; | |
2373 | case DW_OP_and: | |
2374 | return "DW_OP_and"; | |
2375 | case DW_OP_div: | |
2376 | return "DW_OP_div"; | |
2377 | case DW_OP_minus: | |
2378 | return "DW_OP_minus"; | |
2379 | case DW_OP_mod: | |
2380 | return "DW_OP_mod"; | |
2381 | case DW_OP_mul: | |
2382 | return "DW_OP_mul"; | |
2383 | case DW_OP_neg: | |
2384 | return "DW_OP_neg"; | |
2385 | case DW_OP_not: | |
2386 | return "DW_OP_not"; | |
2387 | case DW_OP_or: | |
2388 | return "DW_OP_or"; | |
2389 | case DW_OP_plus: | |
2390 | return "DW_OP_plus"; | |
2391 | case DW_OP_plus_uconst: | |
2392 | return "DW_OP_plus_uconst"; | |
2393 | case DW_OP_shl: | |
2394 | return "DW_OP_shl"; | |
2395 | case DW_OP_shr: | |
2396 | return "DW_OP_shr"; | |
2397 | case DW_OP_shra: | |
2398 | return "DW_OP_shra"; | |
2399 | case DW_OP_xor: | |
2400 | return "DW_OP_xor"; | |
2401 | case DW_OP_bra: | |
2402 | return "DW_OP_bra"; | |
2403 | case DW_OP_eq: | |
2404 | return "DW_OP_eq"; | |
2405 | case DW_OP_ge: | |
2406 | return "DW_OP_ge"; | |
2407 | case DW_OP_gt: | |
2408 | return "DW_OP_gt"; | |
2409 | case DW_OP_le: | |
2410 | return "DW_OP_le"; | |
2411 | case DW_OP_lt: | |
2412 | return "DW_OP_lt"; | |
2413 | case DW_OP_ne: | |
2414 | return "DW_OP_ne"; | |
2415 | case DW_OP_skip: | |
2416 | return "DW_OP_skip"; | |
2417 | case DW_OP_lit0: | |
2418 | return "DW_OP_lit0"; | |
2419 | case DW_OP_lit1: | |
2420 | return "DW_OP_lit1"; | |
2421 | case DW_OP_lit2: | |
2422 | return "DW_OP_lit2"; | |
2423 | case DW_OP_lit3: | |
2424 | return "DW_OP_lit3"; | |
2425 | case DW_OP_lit4: | |
2426 | return "DW_OP_lit4"; | |
2427 | case DW_OP_lit5: | |
2428 | return "DW_OP_lit5"; | |
2429 | case DW_OP_lit6: | |
2430 | return "DW_OP_lit6"; | |
2431 | case DW_OP_lit7: | |
2432 | return "DW_OP_lit7"; | |
2433 | case DW_OP_lit8: | |
2434 | return "DW_OP_lit8"; | |
2435 | case DW_OP_lit9: | |
2436 | return "DW_OP_lit9"; | |
2437 | case DW_OP_lit10: | |
2438 | return "DW_OP_lit10"; | |
2439 | case DW_OP_lit11: | |
2440 | return "DW_OP_lit11"; | |
2441 | case DW_OP_lit12: | |
2442 | return "DW_OP_lit12"; | |
2443 | case DW_OP_lit13: | |
2444 | return "DW_OP_lit13"; | |
2445 | case DW_OP_lit14: | |
2446 | return "DW_OP_lit14"; | |
2447 | case DW_OP_lit15: | |
2448 | return "DW_OP_lit15"; | |
2449 | case DW_OP_lit16: | |
2450 | return "DW_OP_lit16"; | |
2451 | case DW_OP_lit17: | |
2452 | return "DW_OP_lit17"; | |
2453 | case DW_OP_lit18: | |
2454 | return "DW_OP_lit18"; | |
2455 | case DW_OP_lit19: | |
2456 | return "DW_OP_lit19"; | |
2457 | case DW_OP_lit20: | |
2458 | return "DW_OP_lit20"; | |
2459 | case DW_OP_lit21: | |
2460 | return "DW_OP_lit21"; | |
2461 | case DW_OP_lit22: | |
2462 | return "DW_OP_lit22"; | |
2463 | case DW_OP_lit23: | |
2464 | return "DW_OP_lit23"; | |
2465 | case DW_OP_lit24: | |
2466 | return "DW_OP_lit24"; | |
2467 | case DW_OP_lit25: | |
2468 | return "DW_OP_lit25"; | |
2469 | case DW_OP_lit26: | |
2470 | return "DW_OP_lit26"; | |
2471 | case DW_OP_lit27: | |
2472 | return "DW_OP_lit27"; | |
2473 | case DW_OP_lit28: | |
2474 | return "DW_OP_lit28"; | |
2475 | case DW_OP_lit29: | |
2476 | return "DW_OP_lit29"; | |
2477 | case DW_OP_lit30: | |
2478 | return "DW_OP_lit30"; | |
2479 | case DW_OP_lit31: | |
2480 | return "DW_OP_lit31"; | |
2481 | case DW_OP_reg0: | |
2482 | return "DW_OP_reg0"; | |
2483 | case DW_OP_reg1: | |
2484 | return "DW_OP_reg1"; | |
2485 | case DW_OP_reg2: | |
2486 | return "DW_OP_reg2"; | |
2487 | case DW_OP_reg3: | |
2488 | return "DW_OP_reg3"; | |
2489 | case DW_OP_reg4: | |
2490 | return "DW_OP_reg4"; | |
2491 | case DW_OP_reg5: | |
2492 | return "DW_OP_reg5"; | |
2493 | case DW_OP_reg6: | |
2494 | return "DW_OP_reg6"; | |
2495 | case DW_OP_reg7: | |
2496 | return "DW_OP_reg7"; | |
2497 | case DW_OP_reg8: | |
2498 | return "DW_OP_reg8"; | |
2499 | case DW_OP_reg9: | |
2500 | return "DW_OP_reg9"; | |
2501 | case DW_OP_reg10: | |
2502 | return "DW_OP_reg10"; | |
2503 | case DW_OP_reg11: | |
2504 | return "DW_OP_reg11"; | |
2505 | case DW_OP_reg12: | |
2506 | return "DW_OP_reg12"; | |
2507 | case DW_OP_reg13: | |
2508 | return "DW_OP_reg13"; | |
2509 | case DW_OP_reg14: | |
2510 | return "DW_OP_reg14"; | |
2511 | case DW_OP_reg15: | |
2512 | return "DW_OP_reg15"; | |
2513 | case DW_OP_reg16: | |
2514 | return "DW_OP_reg16"; | |
2515 | case DW_OP_reg17: | |
2516 | return "DW_OP_reg17"; | |
2517 | case DW_OP_reg18: | |
2518 | return "DW_OP_reg18"; | |
2519 | case DW_OP_reg19: | |
2520 | return "DW_OP_reg19"; | |
2521 | case DW_OP_reg20: | |
2522 | return "DW_OP_reg20"; | |
2523 | case DW_OP_reg21: | |
2524 | return "DW_OP_reg21"; | |
2525 | case DW_OP_reg22: | |
2526 | return "DW_OP_reg22"; | |
2527 | case DW_OP_reg23: | |
2528 | return "DW_OP_reg23"; | |
2529 | case DW_OP_reg24: | |
2530 | return "DW_OP_reg24"; | |
2531 | case DW_OP_reg25: | |
2532 | return "DW_OP_reg25"; | |
2533 | case DW_OP_reg26: | |
2534 | return "DW_OP_reg26"; | |
2535 | case DW_OP_reg27: | |
2536 | return "DW_OP_reg27"; | |
2537 | case DW_OP_reg28: | |
2538 | return "DW_OP_reg28"; | |
2539 | case DW_OP_reg29: | |
2540 | return "DW_OP_reg29"; | |
2541 | case DW_OP_reg30: | |
2542 | return "DW_OP_reg30"; | |
2543 | case DW_OP_reg31: | |
2544 | return "DW_OP_reg31"; | |
2545 | case DW_OP_breg0: | |
2546 | return "DW_OP_breg0"; | |
2547 | case DW_OP_breg1: | |
2548 | return "DW_OP_breg1"; | |
2549 | case DW_OP_breg2: | |
2550 | return "DW_OP_breg2"; | |
2551 | case DW_OP_breg3: | |
2552 | return "DW_OP_breg3"; | |
2553 | case DW_OP_breg4: | |
2554 | return "DW_OP_breg4"; | |
2555 | case DW_OP_breg5: | |
2556 | return "DW_OP_breg5"; | |
2557 | case DW_OP_breg6: | |
2558 | return "DW_OP_breg6"; | |
2559 | case DW_OP_breg7: | |
2560 | return "DW_OP_breg7"; | |
2561 | case DW_OP_breg8: | |
2562 | return "DW_OP_breg8"; | |
2563 | case DW_OP_breg9: | |
2564 | return "DW_OP_breg9"; | |
2565 | case DW_OP_breg10: | |
2566 | return "DW_OP_breg10"; | |
2567 | case DW_OP_breg11: | |
2568 | return "DW_OP_breg11"; | |
2569 | case DW_OP_breg12: | |
2570 | return "DW_OP_breg12"; | |
2571 | case DW_OP_breg13: | |
2572 | return "DW_OP_breg13"; | |
2573 | case DW_OP_breg14: | |
2574 | return "DW_OP_breg14"; | |
2575 | case DW_OP_breg15: | |
2576 | return "DW_OP_breg15"; | |
2577 | case DW_OP_breg16: | |
2578 | return "DW_OP_breg16"; | |
2579 | case DW_OP_breg17: | |
2580 | return "DW_OP_breg17"; | |
2581 | case DW_OP_breg18: | |
2582 | return "DW_OP_breg18"; | |
2583 | case DW_OP_breg19: | |
2584 | return "DW_OP_breg19"; | |
2585 | case DW_OP_breg20: | |
2586 | return "DW_OP_breg20"; | |
2587 | case DW_OP_breg21: | |
2588 | return "DW_OP_breg21"; | |
2589 | case DW_OP_breg22: | |
2590 | return "DW_OP_breg22"; | |
2591 | case DW_OP_breg23: | |
2592 | return "DW_OP_breg23"; | |
2593 | case DW_OP_breg24: | |
2594 | return "DW_OP_breg24"; | |
2595 | case DW_OP_breg25: | |
2596 | return "DW_OP_breg25"; | |
2597 | case DW_OP_breg26: | |
2598 | return "DW_OP_breg26"; | |
2599 | case DW_OP_breg27: | |
2600 | return "DW_OP_breg27"; | |
2601 | case DW_OP_breg28: | |
2602 | return "DW_OP_breg28"; | |
2603 | case DW_OP_breg29: | |
2604 | return "DW_OP_breg29"; | |
2605 | case DW_OP_breg30: | |
2606 | return "DW_OP_breg30"; | |
2607 | case DW_OP_breg31: | |
2608 | return "DW_OP_breg31"; | |
2609 | case DW_OP_regx: | |
2610 | return "DW_OP_regx"; | |
2611 | case DW_OP_fbreg: | |
2612 | return "DW_OP_fbreg"; | |
2613 | case DW_OP_bregx: | |
2614 | return "DW_OP_bregx"; | |
2615 | case DW_OP_piece: | |
2616 | return "DW_OP_piece"; | |
2617 | case DW_OP_deref_size: | |
2618 | return "DW_OP_deref_size"; | |
2619 | case DW_OP_xderef_size: | |
2620 | return "DW_OP_xderef_size"; | |
2621 | case DW_OP_nop: | |
2622 | return "DW_OP_nop"; | |
b9203463 RH |
2623 | case DW_OP_push_object_address: |
2624 | return "DW_OP_push_object_address"; | |
2625 | case DW_OP_call2: | |
2626 | return "DW_OP_call2"; | |
2627 | case DW_OP_call4: | |
2628 | return "DW_OP_call4"; | |
2629 | case DW_OP_call_ref: | |
2630 | return "DW_OP_call_ref"; | |
2631 | case DW_OP_GNU_push_tls_address: | |
2632 | return "DW_OP_GNU_push_tls_address"; | |
3f76745e | 2633 | default: |
7d9d8943 | 2634 | return "OP_<unknown>"; |
3f76745e | 2635 | } |
bdb669cb | 2636 | } |
a3f97cbb | 2637 | |
7d9d8943 AM |
2638 | /* Return a pointer to a newly allocated location description. Location |
2639 | descriptions are simple expression terms that can be strung | |
2640 | together to form more complicated location (address) descriptions. */ | |
2641 | ||
2642 | static inline dw_loc_descr_ref | |
2643 | new_loc_descr (op, oprnd1, oprnd2) | |
b3694847 SS |
2644 | enum dwarf_location_atom op; |
2645 | unsigned long oprnd1; | |
2646 | unsigned long oprnd2; | |
4b674448 | 2647 | { |
5de0e8d4 JM |
2648 | /* Use xcalloc here so we clear out all of the long_long constant in |
2649 | the union. */ | |
b3694847 | 2650 | dw_loc_descr_ref descr |
5de0e8d4 | 2651 | = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node)); |
71dfc51f | 2652 | |
7d9d8943 AM |
2653 | descr->dw_loc_opc = op; |
2654 | descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const; | |
2655 | descr->dw_loc_oprnd1.v.val_unsigned = oprnd1; | |
2656 | descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const; | |
2657 | descr->dw_loc_oprnd2.v.val_unsigned = oprnd2; | |
71dfc51f | 2658 | |
7d9d8943 AM |
2659 | return descr; |
2660 | } | |
2661 | ||
63e46568 | 2662 | |
7d9d8943 AM |
2663 | /* Add a location description term to a location description expression. */ |
2664 | ||
2665 | static inline void | |
2666 | add_loc_descr (list_head, descr) | |
b3694847 SS |
2667 | dw_loc_descr_ref *list_head; |
2668 | dw_loc_descr_ref descr; | |
7d9d8943 | 2669 | { |
b3694847 | 2670 | dw_loc_descr_ref *d; |
7d9d8943 AM |
2671 | |
2672 | /* Find the end of the chain. */ | |
2673 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
2674 | ; | |
2675 | ||
2676 | *d = descr; | |
2677 | } | |
2678 | ||
2679 | /* Return the size of a location descriptor. */ | |
2680 | ||
2681 | static unsigned long | |
2682 | size_of_loc_descr (loc) | |
b3694847 | 2683 | dw_loc_descr_ref loc; |
7d9d8943 | 2684 | { |
b3694847 | 2685 | unsigned long size = 1; |
7d9d8943 AM |
2686 | |
2687 | switch (loc->dw_loc_opc) | |
2688 | { | |
2689 | case DW_OP_addr: | |
b9203463 | 2690 | case INTERNAL_DW_OP_tls_addr: |
7d9d8943 AM |
2691 | size += DWARF2_ADDR_SIZE; |
2692 | break; | |
2693 | case DW_OP_const1u: | |
2694 | case DW_OP_const1s: | |
2695 | size += 1; | |
2696 | break; | |
2697 | case DW_OP_const2u: | |
2698 | case DW_OP_const2s: | |
2699 | size += 2; | |
2700 | break; | |
2701 | case DW_OP_const4u: | |
2702 | case DW_OP_const4s: | |
2703 | size += 4; | |
2704 | break; | |
2705 | case DW_OP_const8u: | |
2706 | case DW_OP_const8s: | |
2707 | size += 8; | |
2708 | break; | |
2709 | case DW_OP_constu: | |
2710 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2711 | break; | |
2712 | case DW_OP_consts: | |
2713 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2714 | break; | |
2715 | case DW_OP_pick: | |
2716 | size += 1; | |
2717 | break; | |
2718 | case DW_OP_plus_uconst: | |
2719 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2720 | break; | |
2721 | case DW_OP_skip: | |
2722 | case DW_OP_bra: | |
2723 | size += 2; | |
2724 | break; | |
2725 | case DW_OP_breg0: | |
2726 | case DW_OP_breg1: | |
2727 | case DW_OP_breg2: | |
2728 | case DW_OP_breg3: | |
2729 | case DW_OP_breg4: | |
2730 | case DW_OP_breg5: | |
2731 | case DW_OP_breg6: | |
2732 | case DW_OP_breg7: | |
2733 | case DW_OP_breg8: | |
2734 | case DW_OP_breg9: | |
2735 | case DW_OP_breg10: | |
2736 | case DW_OP_breg11: | |
2737 | case DW_OP_breg12: | |
2738 | case DW_OP_breg13: | |
2739 | case DW_OP_breg14: | |
2740 | case DW_OP_breg15: | |
2741 | case DW_OP_breg16: | |
2742 | case DW_OP_breg17: | |
2743 | case DW_OP_breg18: | |
2744 | case DW_OP_breg19: | |
2745 | case DW_OP_breg20: | |
2746 | case DW_OP_breg21: | |
2747 | case DW_OP_breg22: | |
2748 | case DW_OP_breg23: | |
2749 | case DW_OP_breg24: | |
2750 | case DW_OP_breg25: | |
2751 | case DW_OP_breg26: | |
2752 | case DW_OP_breg27: | |
2753 | case DW_OP_breg28: | |
2754 | case DW_OP_breg29: | |
2755 | case DW_OP_breg30: | |
2756 | case DW_OP_breg31: | |
2757 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2758 | break; | |
2759 | case DW_OP_regx: | |
2760 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2761 | break; | |
2762 | case DW_OP_fbreg: | |
2763 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2764 | break; | |
2765 | case DW_OP_bregx: | |
2766 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2767 | size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int); | |
2768 | break; | |
2769 | case DW_OP_piece: | |
2770 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2771 | break; | |
2772 | case DW_OP_deref_size: | |
2773 | case DW_OP_xderef_size: | |
2774 | size += 1; | |
2775 | break; | |
b9203463 RH |
2776 | case DW_OP_call2: |
2777 | size += 2; | |
2778 | break; | |
2779 | case DW_OP_call4: | |
2780 | size += 4; | |
2781 | break; | |
2782 | case DW_OP_call_ref: | |
2783 | size += DWARF2_ADDR_SIZE; | |
2784 | break; | |
3f76745e | 2785 | default: |
7d9d8943 | 2786 | break; |
4b674448 | 2787 | } |
7d9d8943 AM |
2788 | |
2789 | return size; | |
4b674448 JM |
2790 | } |
2791 | ||
7d9d8943 | 2792 | /* Return the size of a series of location descriptors. */ |
71dfc51f | 2793 | |
7d9d8943 AM |
2794 | static unsigned long |
2795 | size_of_locs (loc) | |
b3694847 | 2796 | dw_loc_descr_ref loc; |
4b674448 | 2797 | { |
2ad9852d | 2798 | unsigned long size; |
7d9d8943 | 2799 | |
2ad9852d | 2800 | for (size = 0; loc != NULL; loc = loc->dw_loc_next) |
d8041cc8 RH |
2801 | { |
2802 | loc->dw_loc_addr = size; | |
2803 | size += size_of_loc_descr (loc); | |
2804 | } | |
7d9d8943 AM |
2805 | |
2806 | return size; | |
4b674448 JM |
2807 | } |
2808 | ||
7d9d8943 | 2809 | /* Output location description stack opcode's operands (if any). */ |
71dfc51f | 2810 | |
7d9d8943 AM |
2811 | static void |
2812 | output_loc_operands (loc) | |
b3694847 | 2813 | dw_loc_descr_ref loc; |
a3f97cbb | 2814 | { |
b3694847 SS |
2815 | dw_val_ref val1 = &loc->dw_loc_oprnd1; |
2816 | dw_val_ref val2 = &loc->dw_loc_oprnd2; | |
7d9d8943 AM |
2817 | |
2818 | switch (loc->dw_loc_opc) | |
a3f97cbb | 2819 | { |
0517872a | 2820 | #ifdef DWARF2_DEBUGGING_INFO |
3f76745e | 2821 | case DW_OP_addr: |
2e4b9b8c | 2822 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL); |
7d9d8943 | 2823 | break; |
3f76745e | 2824 | case DW_OP_const2u: |
3f76745e | 2825 | case DW_OP_const2s: |
2e4b9b8c | 2826 | dw2_asm_output_data (2, val1->v.val_int, NULL); |
7d9d8943 | 2827 | break; |
3f76745e | 2828 | case DW_OP_const4u: |
3f76745e | 2829 | case DW_OP_const4s: |
2e4b9b8c | 2830 | dw2_asm_output_data (4, val1->v.val_int, NULL); |
7d9d8943 | 2831 | break; |
3f76745e | 2832 | case DW_OP_const8u: |
3f76745e | 2833 | case DW_OP_const8s: |
2e4b9b8c RH |
2834 | if (HOST_BITS_PER_LONG < 64) |
2835 | abort (); | |
2836 | dw2_asm_output_data (8, val1->v.val_int, NULL); | |
7d9d8943 | 2837 | break; |
0517872a JM |
2838 | case DW_OP_skip: |
2839 | case DW_OP_bra: | |
d8041cc8 RH |
2840 | { |
2841 | int offset; | |
2842 | ||
2843 | if (val1->val_class == dw_val_class_loc) | |
2844 | offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3); | |
2845 | else | |
2846 | abort (); | |
2847 | ||
2e4b9b8c | 2848 | dw2_asm_output_data (2, offset, NULL); |
d8041cc8 | 2849 | } |
0517872a | 2850 | break; |
3139472f JM |
2851 | #else |
2852 | case DW_OP_addr: | |
2853 | case DW_OP_const2u: | |
2854 | case DW_OP_const2s: | |
2855 | case DW_OP_const4u: | |
2856 | case DW_OP_const4s: | |
2857 | case DW_OP_const8u: | |
2858 | case DW_OP_const8s: | |
2859 | case DW_OP_skip: | |
2860 | case DW_OP_bra: | |
2861 | /* We currently don't make any attempt to make sure these are | |
2862 | aligned properly like we do for the main unwind info, so | |
2863 | don't support emitting things larger than a byte if we're | |
2864 | only doing unwinding. */ | |
2865 | abort (); | |
0517872a JM |
2866 | #endif |
2867 | case DW_OP_const1u: | |
2868 | case DW_OP_const1s: | |
2e4b9b8c | 2869 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
0517872a | 2870 | break; |
3f76745e | 2871 | case DW_OP_constu: |
2e4b9b8c | 2872 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2873 | break; |
3f76745e | 2874 | case DW_OP_consts: |
2e4b9b8c | 2875 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 AM |
2876 | break; |
2877 | case DW_OP_pick: | |
2e4b9b8c | 2878 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 AM |
2879 | break; |
2880 | case DW_OP_plus_uconst: | |
2e4b9b8c | 2881 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2882 | break; |
3f76745e | 2883 | case DW_OP_breg0: |
3f76745e | 2884 | case DW_OP_breg1: |
3f76745e | 2885 | case DW_OP_breg2: |
3f76745e | 2886 | case DW_OP_breg3: |
3f76745e | 2887 | case DW_OP_breg4: |
3f76745e | 2888 | case DW_OP_breg5: |
3f76745e | 2889 | case DW_OP_breg6: |
3f76745e | 2890 | case DW_OP_breg7: |
3f76745e | 2891 | case DW_OP_breg8: |
3f76745e | 2892 | case DW_OP_breg9: |
3f76745e | 2893 | case DW_OP_breg10: |
3f76745e | 2894 | case DW_OP_breg11: |
3f76745e | 2895 | case DW_OP_breg12: |
3f76745e | 2896 | case DW_OP_breg13: |
3f76745e | 2897 | case DW_OP_breg14: |
3f76745e | 2898 | case DW_OP_breg15: |
3f76745e | 2899 | case DW_OP_breg16: |
3f76745e | 2900 | case DW_OP_breg17: |
3f76745e | 2901 | case DW_OP_breg18: |
3f76745e | 2902 | case DW_OP_breg19: |
3f76745e | 2903 | case DW_OP_breg20: |
3f76745e | 2904 | case DW_OP_breg21: |
3f76745e | 2905 | case DW_OP_breg22: |
3f76745e | 2906 | case DW_OP_breg23: |
3f76745e | 2907 | case DW_OP_breg24: |
3f76745e | 2908 | case DW_OP_breg25: |
3f76745e | 2909 | case DW_OP_breg26: |
3f76745e | 2910 | case DW_OP_breg27: |
3f76745e | 2911 | case DW_OP_breg28: |
3f76745e | 2912 | case DW_OP_breg29: |
3f76745e | 2913 | case DW_OP_breg30: |
3f76745e | 2914 | case DW_OP_breg31: |
2e4b9b8c | 2915 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 2916 | break; |
3f76745e | 2917 | case DW_OP_regx: |
2e4b9b8c | 2918 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2919 | break; |
3f76745e | 2920 | case DW_OP_fbreg: |
2e4b9b8c | 2921 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 2922 | break; |
3f76745e | 2923 | case DW_OP_bregx: |
2e4b9b8c RH |
2924 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
2925 | dw2_asm_output_data_sleb128 (val2->v.val_int, NULL); | |
7d9d8943 | 2926 | break; |
3f76745e | 2927 | case DW_OP_piece: |
2e4b9b8c | 2928 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2929 | break; |
3f76745e | 2930 | case DW_OP_deref_size: |
3f76745e | 2931 | case DW_OP_xderef_size: |
2e4b9b8c | 2932 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 | 2933 | break; |
b9203463 RH |
2934 | |
2935 | case INTERNAL_DW_OP_tls_addr: | |
2936 | #ifdef ASM_OUTPUT_DWARF_DTPREL | |
2937 | ASM_OUTPUT_DWARF_DTPREL (asm_out_file, DWARF2_ADDR_SIZE, | |
2938 | val1->v.val_addr); | |
2939 | fputc ('\n', asm_out_file); | |
2940 | #else | |
2941 | abort (); | |
2942 | #endif | |
2943 | break; | |
2944 | ||
7d9d8943 | 2945 | default: |
3139472f JM |
2946 | /* Other codes have no operands. */ |
2947 | break; | |
7d9d8943 AM |
2948 | } |
2949 | } | |
2950 | ||
2951 | /* Output a sequence of location operations. */ | |
2952 | ||
2953 | static void | |
2954 | output_loc_sequence (loc) | |
2955 | dw_loc_descr_ref loc; | |
2956 | { | |
2957 | for (; loc != NULL; loc = loc->dw_loc_next) | |
2958 | { | |
2959 | /* Output the opcode. */ | |
2e4b9b8c RH |
2960 | dw2_asm_output_data (1, loc->dw_loc_opc, |
2961 | "%s", dwarf_stack_op_name (loc->dw_loc_opc)); | |
7d9d8943 AM |
2962 | |
2963 | /* Output the operand(s) (if any). */ | |
2964 | output_loc_operands (loc); | |
2965 | } | |
2966 | } | |
2967 | ||
2968 | /* This routine will generate the correct assembly data for a location | |
2969 | description based on a cfi entry with a complex address. */ | |
2970 | ||
2971 | static void | |
2972 | output_cfa_loc (cfi) | |
2973 | dw_cfi_ref cfi; | |
2974 | { | |
2975 | dw_loc_descr_ref loc; | |
2976 | unsigned long size; | |
2977 | ||
2978 | /* Output the size of the block. */ | |
2979 | loc = cfi->dw_cfi_oprnd1.dw_cfi_loc; | |
2980 | size = size_of_locs (loc); | |
2e4b9b8c | 2981 | dw2_asm_output_data_uleb128 (size, NULL); |
7d9d8943 AM |
2982 | |
2983 | /* Now output the operations themselves. */ | |
2984 | output_loc_sequence (loc); | |
2985 | } | |
2986 | ||
dd49a9ec | 2987 | /* This function builds a dwarf location descriptor sequence from |
556273e0 | 2988 | a dw_cfa_location. */ |
7d9d8943 AM |
2989 | |
2990 | static struct dw_loc_descr_struct * | |
2991 | build_cfa_loc (cfa) | |
2992 | dw_cfa_location *cfa; | |
2993 | { | |
2994 | struct dw_loc_descr_struct *head, *tmp; | |
2995 | ||
2996 | if (cfa->indirect == 0) | |
2997 | abort (); | |
2998 | ||
2999 | if (cfa->base_offset) | |
f299afab HPN |
3000 | { |
3001 | if (cfa->reg <= 31) | |
3002 | head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0); | |
3003 | else | |
3004 | head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset); | |
3005 | } | |
3006 | else if (cfa->reg <= 31) | |
7d9d8943 | 3007 | head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0); |
f299afab HPN |
3008 | else |
3009 | head = new_loc_descr (DW_OP_regx, cfa->reg, 0); | |
2ad9852d | 3010 | |
7d9d8943 AM |
3011 | head->dw_loc_oprnd1.val_class = dw_val_class_const; |
3012 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
3013 | add_loc_descr (&head, tmp); | |
3014 | if (cfa->offset != 0) | |
3015 | { | |
3016 | tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0); | |
3017 | add_loc_descr (&head, tmp); | |
3018 | } | |
2ad9852d | 3019 | |
7d9d8943 AM |
3020 | return head; |
3021 | } | |
3022 | ||
2ad9852d RK |
3023 | /* This function fills in aa dw_cfa_location structure from a dwarf location |
3024 | descriptor sequence. */ | |
7d9d8943 AM |
3025 | |
3026 | static void | |
3027 | get_cfa_from_loc_descr (cfa, loc) | |
3028 | dw_cfa_location *cfa; | |
556273e0 | 3029 | struct dw_loc_descr_struct *loc; |
7d9d8943 | 3030 | { |
556273e0 | 3031 | struct dw_loc_descr_struct *ptr; |
7d9d8943 AM |
3032 | cfa->offset = 0; |
3033 | cfa->base_offset = 0; | |
3034 | cfa->indirect = 0; | |
3035 | cfa->reg = -1; | |
3036 | ||
3037 | for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next) | |
3038 | { | |
3039 | enum dwarf_location_atom op = ptr->dw_loc_opc; | |
2ad9852d | 3040 | |
7d9d8943 | 3041 | switch (op) |
556273e0 | 3042 | { |
7d9d8943 AM |
3043 | case DW_OP_reg0: |
3044 | case DW_OP_reg1: | |
3045 | case DW_OP_reg2: | |
3046 | case DW_OP_reg3: | |
3047 | case DW_OP_reg4: | |
3048 | case DW_OP_reg5: | |
3049 | case DW_OP_reg6: | |
3050 | case DW_OP_reg7: | |
3051 | case DW_OP_reg8: | |
3052 | case DW_OP_reg9: | |
3053 | case DW_OP_reg10: | |
3054 | case DW_OP_reg11: | |
3055 | case DW_OP_reg12: | |
3056 | case DW_OP_reg13: | |
3057 | case DW_OP_reg14: | |
3058 | case DW_OP_reg15: | |
3059 | case DW_OP_reg16: | |
3060 | case DW_OP_reg17: | |
3061 | case DW_OP_reg18: | |
3062 | case DW_OP_reg19: | |
3063 | case DW_OP_reg20: | |
3064 | case DW_OP_reg21: | |
3065 | case DW_OP_reg22: | |
3066 | case DW_OP_reg23: | |
3067 | case DW_OP_reg24: | |
3068 | case DW_OP_reg25: | |
3069 | case DW_OP_reg26: | |
3070 | case DW_OP_reg27: | |
3071 | case DW_OP_reg28: | |
3072 | case DW_OP_reg29: | |
3073 | case DW_OP_reg30: | |
3074 | case DW_OP_reg31: | |
3075 | cfa->reg = op - DW_OP_reg0; | |
3076 | break; | |
3077 | case DW_OP_regx: | |
3078 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
3079 | break; | |
3080 | case DW_OP_breg0: | |
3081 | case DW_OP_breg1: | |
3082 | case DW_OP_breg2: | |
3083 | case DW_OP_breg3: | |
3084 | case DW_OP_breg4: | |
3085 | case DW_OP_breg5: | |
3086 | case DW_OP_breg6: | |
3087 | case DW_OP_breg7: | |
3088 | case DW_OP_breg8: | |
3089 | case DW_OP_breg9: | |
3090 | case DW_OP_breg10: | |
3091 | case DW_OP_breg11: | |
3092 | case DW_OP_breg12: | |
3093 | case DW_OP_breg13: | |
3094 | case DW_OP_breg14: | |
3095 | case DW_OP_breg15: | |
3096 | case DW_OP_breg16: | |
3097 | case DW_OP_breg17: | |
3098 | case DW_OP_breg18: | |
3099 | case DW_OP_breg19: | |
3100 | case DW_OP_breg20: | |
3101 | case DW_OP_breg21: | |
3102 | case DW_OP_breg22: | |
3103 | case DW_OP_breg23: | |
3104 | case DW_OP_breg24: | |
3105 | case DW_OP_breg25: | |
3106 | case DW_OP_breg26: | |
3107 | case DW_OP_breg27: | |
3108 | case DW_OP_breg28: | |
3109 | case DW_OP_breg29: | |
3110 | case DW_OP_breg30: | |
3111 | case DW_OP_breg31: | |
3112 | cfa->reg = op - DW_OP_breg0; | |
3113 | cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int; | |
3114 | break; | |
3115 | case DW_OP_bregx: | |
3116 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
3117 | cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int; | |
3118 | break; | |
3119 | case DW_OP_deref: | |
3120 | cfa->indirect = 1; | |
3121 | break; | |
3122 | case DW_OP_plus_uconst: | |
556273e0 | 3123 | cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned; |
7d9d8943 AM |
3124 | break; |
3125 | default: | |
a1f300c0 | 3126 | internal_error ("DW_LOC_OP %s not implemented\n", |
400500c4 | 3127 | dwarf_stack_op_name (ptr->dw_loc_opc)); |
7d9d8943 AM |
3128 | } |
3129 | } | |
3130 | } | |
3131 | #endif /* .debug_frame support */ | |
3132 | \f | |
3133 | /* And now, the support for symbolic debugging information. */ | |
3134 | #ifdef DWARF2_DEBUGGING_INFO | |
3135 | ||
117f9d28 GS |
3136 | /* .debug_str support. */ |
3137 | static hashnode indirect_string_alloc PARAMS ((hash_table *)); | |
3138 | static int output_indirect_string PARAMS ((struct cpp_reader *, | |
3139 | hashnode, const PTR)); | |
3140 | ||
3141 | ||
e2a12aca NB |
3142 | static void dwarf2out_init PARAMS ((const char *)); |
3143 | static void dwarf2out_finish PARAMS ((const char *)); | |
7f905405 NB |
3144 | static void dwarf2out_define PARAMS ((unsigned int, const char *)); |
3145 | static void dwarf2out_undef PARAMS ((unsigned int, const char *)); | |
3146 | static void dwarf2out_start_source_file PARAMS ((unsigned, const char *)); | |
3147 | static void dwarf2out_end_source_file PARAMS ((unsigned)); | |
e2a12aca NB |
3148 | static void dwarf2out_begin_block PARAMS ((unsigned, unsigned)); |
3149 | static void dwarf2out_end_block PARAMS ((unsigned, unsigned)); | |
e1772ac0 | 3150 | static bool dwarf2out_ignore_block PARAMS ((tree)); |
2b85879e | 3151 | static void dwarf2out_global_decl PARAMS ((tree)); |
e1772ac0 | 3152 | static void dwarf2out_abstract_function PARAMS ((tree)); |
7f905405 NB |
3153 | |
3154 | /* The debug hooks structure. */ | |
3155 | ||
54b6670a | 3156 | const struct gcc_debug_hooks dwarf2_debug_hooks = |
7f905405 NB |
3157 | { |
3158 | dwarf2out_init, | |
3159 | dwarf2out_finish, | |
3160 | dwarf2out_define, | |
3161 | dwarf2out_undef, | |
3162 | dwarf2out_start_source_file, | |
a5a42b92 NB |
3163 | dwarf2out_end_source_file, |
3164 | dwarf2out_begin_block, | |
e2a12aca | 3165 | dwarf2out_end_block, |
e1772ac0 | 3166 | dwarf2out_ignore_block, |
e2a12aca | 3167 | dwarf2out_source_line, |
653e276c | 3168 | dwarf2out_begin_prologue, |
702ada3d | 3169 | debug_nothing_int_charstar, /* end_prologue */ |
e2a12aca | 3170 | dwarf2out_end_epilogue, |
653e276c | 3171 | debug_nothing_tree, /* begin_function */ |
2b85879e NB |
3172 | debug_nothing_int, /* end_function */ |
3173 | dwarf2out_decl, /* function_decl */ | |
3174 | dwarf2out_global_decl, | |
e1772ac0 NB |
3175 | debug_nothing_tree, /* deferred_inline_function */ |
3176 | /* The DWARF 2 backend tries to reduce debugging bloat by not | |
3177 | emitting the abstract description of inline functions until | |
3178 | something tries to reference them. */ | |
3179 | dwarf2out_abstract_function, /* outlining_inline_function */ | |
3180 | debug_nothing_rtx /* label */ | |
7f905405 NB |
3181 | }; |
3182 | \f | |
7d9d8943 AM |
3183 | /* NOTE: In the comments in this file, many references are made to |
3184 | "Debugging Information Entries". This term is abbreviated as `DIE' | |
3185 | throughout the remainder of this file. */ | |
3186 | ||
3187 | /* An internal representation of the DWARF output is built, and then | |
3188 | walked to generate the DWARF debugging info. The walk of the internal | |
3189 | representation is done after the entire program has been compiled. | |
3190 | The types below are used to describe the internal representation. */ | |
3191 | ||
3192 | /* Various DIE's use offsets relative to the beginning of the | |
3193 | .debug_info section to refer to each other. */ | |
3194 | ||
3195 | typedef long int dw_offset; | |
3196 | ||
3197 | /* Define typedefs here to avoid circular dependencies. */ | |
3198 | ||
3199 | typedef struct dw_attr_struct *dw_attr_ref; | |
3200 | typedef struct dw_line_info_struct *dw_line_info_ref; | |
3201 | typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref; | |
3202 | typedef struct pubname_struct *pubname_ref; | |
a20612aa | 3203 | typedef struct dw_ranges_struct *dw_ranges_ref; |
7d9d8943 AM |
3204 | |
3205 | /* Each entry in the line_info_table maintains the file and | |
3206 | line number associated with the label generated for that | |
3207 | entry. The label gives the PC value associated with | |
3208 | the line number entry. */ | |
3209 | ||
3210 | typedef struct dw_line_info_struct | |
3211 | { | |
3212 | unsigned long dw_file_num; | |
3213 | unsigned long dw_line_num; | |
3214 | } | |
3215 | dw_line_info_entry; | |
3216 | ||
3217 | /* Line information for functions in separate sections; each one gets its | |
3218 | own sequence. */ | |
3219 | typedef struct dw_separate_line_info_struct | |
3220 | { | |
3221 | unsigned long dw_file_num; | |
3222 | unsigned long dw_line_num; | |
3223 | unsigned long function; | |
3224 | } | |
3225 | dw_separate_line_info_entry; | |
3226 | ||
3227 | /* Each DIE attribute has a field specifying the attribute kind, | |
3228 | a link to the next attribute in the chain, and an attribute value. | |
3229 | Attributes are typically linked below the DIE they modify. */ | |
3230 | ||
3231 | typedef struct dw_attr_struct | |
3232 | { | |
3233 | enum dwarf_attribute dw_attr; | |
3234 | dw_attr_ref dw_attr_next; | |
3235 | dw_val_node dw_attr_val; | |
3236 | } | |
3237 | dw_attr_node; | |
3238 | ||
3239 | /* The Debugging Information Entry (DIE) structure */ | |
3240 | ||
3241 | typedef struct die_struct | |
3242 | { | |
3243 | enum dwarf_tag die_tag; | |
881c6935 | 3244 | char *die_symbol; |
7d9d8943 AM |
3245 | dw_attr_ref die_attr; |
3246 | dw_die_ref die_parent; | |
3247 | dw_die_ref die_child; | |
3248 | dw_die_ref die_sib; | |
3249 | dw_offset die_offset; | |
3250 | unsigned long die_abbrev; | |
1bfb5f8f | 3251 | int die_mark; |
7d9d8943 AM |
3252 | } |
3253 | die_node; | |
3254 | ||
3255 | /* The pubname structure */ | |
3256 | ||
3257 | typedef struct pubname_struct | |
3258 | { | |
3259 | dw_die_ref die; | |
556273e0 | 3260 | char *name; |
7d9d8943 AM |
3261 | } |
3262 | pubname_entry; | |
3263 | ||
a20612aa RH |
3264 | struct dw_ranges_struct |
3265 | { | |
3266 | int block_num; | |
3267 | }; | |
3268 | ||
7d9d8943 AM |
3269 | /* The limbo die list structure. */ |
3270 | typedef struct limbo_die_struct | |
3271 | { | |
3272 | dw_die_ref die; | |
54ba1f0d | 3273 | tree created_for; |
7d9d8943 AM |
3274 | struct limbo_die_struct *next; |
3275 | } | |
3276 | limbo_die_node; | |
3277 | ||
3278 | /* How to start an assembler comment. */ | |
3279 | #ifndef ASM_COMMENT_START | |
3280 | #define ASM_COMMENT_START ";#" | |
3281 | #endif | |
3282 | ||
cc2902df | 3283 | /* Define a macro which returns nonzero for a TYPE_DECL which was |
7d9d8943 AM |
3284 | implicitly generated for a tagged type. |
3285 | ||
3286 | Note that unlike the gcc front end (which generates a NULL named | |
3287 | TYPE_DECL node for each complete tagged type, each array type, and | |
3288 | each function type node created) the g++ front end generates a | |
3289 | _named_ TYPE_DECL node for each tagged type node created. | |
3290 | These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to | |
3291 | generate a DW_TAG_typedef DIE for them. */ | |
3292 | ||
3293 | #define TYPE_DECL_IS_STUB(decl) \ | |
3294 | (DECL_NAME (decl) == NULL_TREE \ | |
3295 | || (DECL_ARTIFICIAL (decl) \ | |
3296 | && is_tagged_type (TREE_TYPE (decl)) \ | |
3297 | && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \ | |
3298 | /* This is necessary for stub decls that \ | |
3299 | appear in nested inline functions. */ \ | |
3300 | || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \ | |
3301 | && (decl_ultimate_origin (decl) \ | |
3302 | == TYPE_STUB_DECL (TREE_TYPE (decl))))))) | |
3303 | ||
3304 | /* Information concerning the compilation unit's programming | |
3305 | language, and compiler version. */ | |
3306 | ||
7d9d8943 AM |
3307 | /* Fixed size portion of the DWARF compilation unit header. */ |
3308 | #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3) | |
3309 | ||
7d9d8943 AM |
3310 | /* Fixed size portion of public names info. */ |
3311 | #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2) | |
3312 | ||
3313 | /* Fixed size portion of the address range info. */ | |
3314 | #define DWARF_ARANGES_HEADER_SIZE \ | |
3315 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ | |
3316 | - DWARF_OFFSET_SIZE) | |
3317 | ||
3318 | /* Size of padding portion in the address range info. It must be | |
3319 | aligned to twice the pointer size. */ | |
3320 | #define DWARF_ARANGES_PAD_SIZE \ | |
3321 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ | |
3322 | - (2 * DWARF_OFFSET_SIZE + 4)) | |
3323 | ||
9d147085 | 3324 | /* Use assembler line directives if available. */ |
7d9d8943 | 3325 | #ifndef DWARF2_ASM_LINE_DEBUG_INFO |
9d147085 RH |
3326 | #ifdef HAVE_AS_DWARF2_DEBUG_LINE |
3327 | #define DWARF2_ASM_LINE_DEBUG_INFO 1 | |
3328 | #else | |
7d9d8943 AM |
3329 | #define DWARF2_ASM_LINE_DEBUG_INFO 0 |
3330 | #endif | |
9d147085 | 3331 | #endif |
7d9d8943 | 3332 | |
7d9d8943 AM |
3333 | /* Minimum line offset in a special line info. opcode. |
3334 | This value was chosen to give a reasonable range of values. */ | |
3335 | #define DWARF_LINE_BASE -10 | |
3336 | ||
a1f300c0 | 3337 | /* First special line opcode - leave room for the standard opcodes. */ |
7d9d8943 AM |
3338 | #define DWARF_LINE_OPCODE_BASE 10 |
3339 | ||
3340 | /* Range of line offsets in a special line info. opcode. */ | |
3341 | #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1) | |
3342 | ||
3343 | /* Flag that indicates the initial value of the is_stmt_start flag. | |
3344 | In the present implementation, we do not mark any lines as | |
3345 | the beginning of a source statement, because that information | |
3346 | is not made available by the GCC front-end. */ | |
3347 | #define DWARF_LINE_DEFAULT_IS_STMT_START 1 | |
3348 | ||
3349 | /* This location is used by calc_die_sizes() to keep track | |
3350 | the offset of each DIE within the .debug_info section. */ | |
3351 | static unsigned long next_die_offset; | |
3352 | ||
3353 | /* Record the root of the DIE's built for the current compilation unit. */ | |
3354 | static dw_die_ref comp_unit_die; | |
3355 | ||
cc0017a9 ZD |
3356 | /* We need special handling in dwarf2out_start_source_file if it is |
3357 | first one. */ | |
3358 | static int is_main_source; | |
3359 | ||
7d9d8943 AM |
3360 | /* A list of DIEs with a NULL parent waiting to be relocated. */ |
3361 | static limbo_die_node *limbo_die_list = 0; | |
3362 | ||
2e18bbae RH |
3363 | /* Structure used by lookup_filename to manage sets of filenames. */ |
3364 | struct file_table | |
3365 | { | |
3366 | char **table; | |
3367 | unsigned allocated; | |
3368 | unsigned in_use; | |
3369 | unsigned last_lookup_index; | |
3370 | }; | |
7d9d8943 AM |
3371 | |
3372 | /* Size (in elements) of increments by which we may expand the filename | |
3373 | table. */ | |
3374 | #define FILE_TABLE_INCREMENT 64 | |
3375 | ||
981975b6 RH |
3376 | /* Filenames referenced by this compilation unit. */ |
3377 | static struct file_table file_table; | |
2e18bbae | 3378 | |
7d9d8943 AM |
3379 | /* A pointer to the base of a table of references to DIE's that describe |
3380 | declarations. The table is indexed by DECL_UID() which is a unique | |
3381 | number identifying each decl. */ | |
3382 | static dw_die_ref *decl_die_table; | |
3383 | ||
3384 | /* Number of elements currently allocated for the decl_die_table. */ | |
3385 | static unsigned decl_die_table_allocated; | |
3386 | ||
3387 | /* Number of elements in decl_die_table currently in use. */ | |
3388 | static unsigned decl_die_table_in_use; | |
3389 | ||
3390 | /* Size (in elements) of increments by which we may expand the | |
3391 | decl_die_table. */ | |
3392 | #define DECL_DIE_TABLE_INCREMENT 256 | |
3393 | ||
7d9d8943 AM |
3394 | /* A pointer to the base of a list of references to DIE's that |
3395 | are uniquely identified by their tag, presence/absence of | |
3396 | children DIE's, and list of attribute/value pairs. */ | |
3397 | static dw_die_ref *abbrev_die_table; | |
3398 | ||
3399 | /* Number of elements currently allocated for abbrev_die_table. */ | |
3400 | static unsigned abbrev_die_table_allocated; | |
3401 | ||
3402 | /* Number of elements in type_die_table currently in use. */ | |
3403 | static unsigned abbrev_die_table_in_use; | |
3404 | ||
3405 | /* Size (in elements) of increments by which we may expand the | |
3406 | abbrev_die_table. */ | |
3407 | #define ABBREV_DIE_TABLE_INCREMENT 256 | |
3408 | ||
3409 | /* A pointer to the base of a table that contains line information | |
3410 | for each source code line in .text in the compilation unit. */ | |
3411 | static dw_line_info_ref line_info_table; | |
3412 | ||
3413 | /* Number of elements currently allocated for line_info_table. */ | |
3414 | static unsigned line_info_table_allocated; | |
3415 | ||
3416 | /* Number of elements in separate_line_info_table currently in use. */ | |
3417 | static unsigned separate_line_info_table_in_use; | |
3418 | ||
3419 | /* A pointer to the base of a table that contains line information | |
3420 | for each source code line outside of .text in the compilation unit. */ | |
3421 | static dw_separate_line_info_ref separate_line_info_table; | |
3422 | ||
3423 | /* Number of elements currently allocated for separate_line_info_table. */ | |
3424 | static unsigned separate_line_info_table_allocated; | |
3425 | ||
3426 | /* Number of elements in line_info_table currently in use. */ | |
3427 | static unsigned line_info_table_in_use; | |
3428 | ||
3429 | /* Size (in elements) of increments by which we may expand the | |
3430 | line_info_table. */ | |
3431 | #define LINE_INFO_TABLE_INCREMENT 1024 | |
3432 | ||
3433 | /* A pointer to the base of a table that contains a list of publicly | |
3434 | accessible names. */ | |
3435 | static pubname_ref pubname_table; | |
3436 | ||
3437 | /* Number of elements currently allocated for pubname_table. */ | |
3438 | static unsigned pubname_table_allocated; | |
3439 | ||
3440 | /* Number of elements in pubname_table currently in use. */ | |
3441 | static unsigned pubname_table_in_use; | |
3442 | ||
3443 | /* Size (in elements) of increments by which we may expand the | |
3444 | pubname_table. */ | |
3445 | #define PUBNAME_TABLE_INCREMENT 64 | |
3446 | ||
a20612aa RH |
3447 | /* Array of dies for which we should generate .debug_arange info. */ |
3448 | static dw_die_ref *arange_table; | |
7d9d8943 AM |
3449 | |
3450 | /* Number of elements currently allocated for arange_table. */ | |
3451 | static unsigned arange_table_allocated; | |
3452 | ||
3453 | /* Number of elements in arange_table currently in use. */ | |
3454 | static unsigned arange_table_in_use; | |
3455 | ||
3456 | /* Size (in elements) of increments by which we may expand the | |
3457 | arange_table. */ | |
3458 | #define ARANGE_TABLE_INCREMENT 64 | |
3459 | ||
a20612aa RH |
3460 | /* Array of dies for which we should generate .debug_ranges info. */ |
3461 | static dw_ranges_ref ranges_table; | |
3462 | ||
3463 | /* Number of elements currently allocated for ranges_table. */ | |
3464 | static unsigned ranges_table_allocated; | |
3465 | ||
3466 | /* Number of elements in ranges_table currently in use. */ | |
3467 | static unsigned ranges_table_in_use; | |
3468 | ||
3469 | /* Size (in elements) of increments by which we may expand the | |
3470 | ranges_table. */ | |
3471 | #define RANGES_TABLE_INCREMENT 64 | |
3472 | ||
63e46568 DB |
3473 | /* Whether we have location lists that need outputting */ |
3474 | static unsigned have_location_lists; | |
3475 | ||
7d9d8943 AM |
3476 | /* Record whether the function being analyzed contains inlined functions. */ |
3477 | static int current_function_has_inlines; | |
3478 | #if 0 && defined (MIPS_DEBUGGING_INFO) | |
3479 | static int comp_unit_has_inlines; | |
3480 | #endif | |
3481 | ||
7d9d8943 AM |
3482 | /* Forward declarations for functions defined in this file. */ |
3483 | ||
3484 | static int is_pseudo_reg PARAMS ((rtx)); | |
3485 | static tree type_main_variant PARAMS ((tree)); | |
3486 | static int is_tagged_type PARAMS ((tree)); | |
3487 | static const char *dwarf_tag_name PARAMS ((unsigned)); | |
3488 | static const char *dwarf_attr_name PARAMS ((unsigned)); | |
3489 | static const char *dwarf_form_name PARAMS ((unsigned)); | |
3490 | #if 0 | |
3491 | static const char *dwarf_type_encoding_name PARAMS ((unsigned)); | |
3492 | #endif | |
3493 | static tree decl_ultimate_origin PARAMS ((tree)); | |
3494 | static tree block_ultimate_origin PARAMS ((tree)); | |
3495 | static tree decl_class_context PARAMS ((tree)); | |
3496 | static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref)); | |
2ad9852d | 3497 | static inline dw_val_class AT_class PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3498 | static void add_AT_flag PARAMS ((dw_die_ref, |
3499 | enum dwarf_attribute, | |
3500 | unsigned)); | |
2ad9852d | 3501 | static inline unsigned AT_flag PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3502 | static void add_AT_int PARAMS ((dw_die_ref, |
3503 | enum dwarf_attribute, long)); | |
2ad9852d | 3504 | static inline long int AT_int PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3505 | static void add_AT_unsigned PARAMS ((dw_die_ref, |
3506 | enum dwarf_attribute, | |
3507 | unsigned long)); | |
2ad9852d | 3508 | static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3509 | static void add_AT_long_long PARAMS ((dw_die_ref, |
3510 | enum dwarf_attribute, | |
3511 | unsigned long, | |
3512 | unsigned long)); | |
3513 | static void add_AT_float PARAMS ((dw_die_ref, | |
3514 | enum dwarf_attribute, | |
3515 | unsigned, long *)); | |
3516 | static void add_AT_string PARAMS ((dw_die_ref, | |
3517 | enum dwarf_attribute, | |
3518 | const char *)); | |
2ad9852d RK |
3519 | static inline const char *AT_string PARAMS ((dw_attr_ref)); |
3520 | static int AT_string_form PARAMS ((dw_attr_ref)); | |
7d9d8943 AM |
3521 | static void add_AT_die_ref PARAMS ((dw_die_ref, |
3522 | enum dwarf_attribute, | |
3523 | dw_die_ref)); | |
2ad9852d RK |
3524 | static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref)); |
3525 | static inline int AT_ref_external PARAMS ((dw_attr_ref)); | |
3526 | static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int)); | |
7d9d8943 AM |
3527 | static void add_AT_fde_ref PARAMS ((dw_die_ref, |
3528 | enum dwarf_attribute, | |
3529 | unsigned)); | |
3530 | static void add_AT_loc PARAMS ((dw_die_ref, | |
3531 | enum dwarf_attribute, | |
3532 | dw_loc_descr_ref)); | |
2ad9852d | 3533 | static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref)); |
63e46568 DB |
3534 | static void add_AT_loc_list PARAMS ((dw_die_ref, |
3535 | enum dwarf_attribute, | |
3536 | dw_loc_list_ref)); | |
2ad9852d | 3537 | static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3538 | static void add_AT_addr PARAMS ((dw_die_ref, |
3539 | enum dwarf_attribute, | |
3540 | rtx)); | |
2ad9852d | 3541 | static inline rtx AT_addr PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3542 | static void add_AT_lbl_id PARAMS ((dw_die_ref, |
3543 | enum dwarf_attribute, | |
3544 | const char *)); | |
3545 | static void add_AT_lbl_offset PARAMS ((dw_die_ref, | |
3546 | enum dwarf_attribute, | |
3547 | const char *)); | |
a20612aa RH |
3548 | static void add_AT_offset PARAMS ((dw_die_ref, |
3549 | enum dwarf_attribute, | |
3550 | unsigned long)); | |
2bee6045 JJ |
3551 | static void add_AT_range_list PARAMS ((dw_die_ref, |
3552 | enum dwarf_attribute, | |
3553 | unsigned long)); | |
2ad9852d | 3554 | static inline const char *AT_lbl PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3555 | static dw_attr_ref get_AT PARAMS ((dw_die_ref, |
3556 | enum dwarf_attribute)); | |
3557 | static const char *get_AT_low_pc PARAMS ((dw_die_ref)); | |
3558 | static const char *get_AT_hi_pc PARAMS ((dw_die_ref)); | |
3559 | static const char *get_AT_string PARAMS ((dw_die_ref, | |
3560 | enum dwarf_attribute)); | |
3561 | static int get_AT_flag PARAMS ((dw_die_ref, | |
3562 | enum dwarf_attribute)); | |
3563 | static unsigned get_AT_unsigned PARAMS ((dw_die_ref, | |
3564 | enum dwarf_attribute)); | |
3565 | static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref, | |
3566 | enum dwarf_attribute)); | |
3567 | static int is_c_family PARAMS ((void)); | |
710af899 | 3568 | static int is_cxx PARAMS ((void)); |
28985b81 | 3569 | static int is_java PARAMS ((void)); |
7d9d8943 AM |
3570 | static int is_fortran PARAMS ((void)); |
3571 | static void remove_AT PARAMS ((dw_die_ref, | |
3572 | enum dwarf_attribute)); | |
2ad9852d | 3573 | static inline void free_die PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3574 | static void remove_children PARAMS ((dw_die_ref)); |
3575 | static void add_child_die PARAMS ((dw_die_ref, dw_die_ref)); | |
54ba1f0d RH |
3576 | static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref, |
3577 | tree)); | |
7d9d8943 AM |
3578 | static dw_die_ref lookup_type_die PARAMS ((tree)); |
3579 | static void equate_type_number_to_die PARAMS ((tree, dw_die_ref)); | |
3580 | static dw_die_ref lookup_decl_die PARAMS ((tree)); | |
3581 | static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref)); | |
3582 | static void print_spaces PARAMS ((FILE *)); | |
3583 | static void print_die PARAMS ((dw_die_ref, FILE *)); | |
3584 | static void print_dwarf_line_table PARAMS ((FILE *)); | |
881c6935 JM |
3585 | static void reverse_die_lists PARAMS ((dw_die_ref)); |
3586 | static void reverse_all_dies PARAMS ((dw_die_ref)); | |
3587 | static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref)); | |
3588 | static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref)); | |
2ad9852d RK |
3589 | static void loc_checksum PARAMS ((dw_loc_descr_ref, |
3590 | struct md5_ctx *)); | |
3591 | static void attr_checksum PARAMS ((dw_attr_ref, | |
cc0017a9 ZD |
3592 | struct md5_ctx *, |
3593 | int *)); | |
2ad9852d | 3594 | static void die_checksum PARAMS ((dw_die_ref, |
cc0017a9 ZD |
3595 | struct md5_ctx *, |
3596 | int *)); | |
3597 | static int same_loc_p PARAMS ((dw_loc_descr_ref, | |
3598 | dw_loc_descr_ref, int *)); | |
3599 | static int same_dw_val_p PARAMS ((dw_val_node *, dw_val_node *, | |
3600 | int *)); | |
3601 | static int same_attr_p PARAMS ((dw_attr_ref, dw_attr_ref, int *)); | |
3602 | static int same_die_p PARAMS ((dw_die_ref, dw_die_ref, int *)); | |
3603 | static int same_die_p_wrap PARAMS ((dw_die_ref, dw_die_ref)); | |
881c6935 JM |
3604 | static void compute_section_prefix PARAMS ((dw_die_ref)); |
3605 | static int is_type_die PARAMS ((dw_die_ref)); | |
3606 | static int is_comdat_die PARAMS ((dw_die_ref)); | |
3607 | static int is_symbol_die PARAMS ((dw_die_ref)); | |
881c6935 JM |
3608 | static void assign_symbol_names PARAMS ((dw_die_ref)); |
3609 | static void break_out_includes PARAMS ((dw_die_ref)); | |
cc0017a9 ZD |
3610 | static hashval_t htab_cu_hash PARAMS ((const void *)); |
3611 | static int htab_cu_eq PARAMS ((const void *, const void *)); | |
3612 | static void htab_cu_del PARAMS ((void *)); | |
3613 | static int check_duplicate_cu PARAMS ((dw_die_ref, htab_t, unsigned *)); | |
3614 | static void record_comdat_symbol_number PARAMS ((dw_die_ref, htab_t, unsigned)); | |
7d9d8943 AM |
3615 | static void add_sibling_attributes PARAMS ((dw_die_ref)); |
3616 | static void build_abbrev_table PARAMS ((dw_die_ref)); | |
63e46568 | 3617 | static void output_location_lists PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3618 | static int constant_size PARAMS ((long unsigned)); |
3619 | static unsigned long size_of_die PARAMS ((dw_die_ref)); | |
3620 | static void calc_die_sizes PARAMS ((dw_die_ref)); | |
1bfb5f8f JM |
3621 | static void mark_dies PARAMS ((dw_die_ref)); |
3622 | static void unmark_dies PARAMS ((dw_die_ref)); | |
cc0017a9 | 3623 | static void unmark_all_dies PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3624 | static unsigned long size_of_pubnames PARAMS ((void)); |
3625 | static unsigned long size_of_aranges PARAMS ((void)); | |
3626 | static enum dwarf_form value_format PARAMS ((dw_attr_ref)); | |
3627 | static void output_value_format PARAMS ((dw_attr_ref)); | |
3628 | static void output_abbrev_section PARAMS ((void)); | |
881c6935 | 3629 | static void output_die_symbol PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3630 | static void output_die PARAMS ((dw_die_ref)); |
3631 | static void output_compilation_unit_header PARAMS ((void)); | |
cc0017a9 | 3632 | static void output_comp_unit PARAMS ((dw_die_ref, int)); |
7d9d8943 AM |
3633 | static const char *dwarf2_name PARAMS ((tree, int)); |
3634 | static void add_pubname PARAMS ((tree, dw_die_ref)); | |
3635 | static void output_pubnames PARAMS ((void)); | |
3636 | static void add_arange PARAMS ((tree, dw_die_ref)); | |
3637 | static void output_aranges PARAMS ((void)); | |
a20612aa RH |
3638 | static unsigned int add_ranges PARAMS ((tree)); |
3639 | static void output_ranges PARAMS ((void)); | |
7d9d8943 | 3640 | static void output_line_info PARAMS ((void)); |
0b34cf1e | 3641 | static void output_file_names PARAMS ((void)); |
7d9d8943 AM |
3642 | static dw_die_ref base_type_die PARAMS ((tree)); |
3643 | static tree root_type PARAMS ((tree)); | |
3644 | static int is_base_type PARAMS ((tree)); | |
3645 | static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref)); | |
3646 | static int type_is_enum PARAMS ((tree)); | |
3647 | static unsigned int reg_number PARAMS ((rtx)); | |
3648 | static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx)); | |
d8041cc8 | 3649 | static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT)); |
7d9d8943 AM |
3650 | static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long)); |
3651 | static int is_based_loc PARAMS ((rtx)); | |
3652 | static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode)); | |
3653 | static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx)); | |
3654 | static dw_loc_descr_ref loc_descriptor PARAMS ((rtx)); | |
d8041cc8 | 3655 | static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int)); |
7d9d8943 AM |
3656 | static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int)); |
3657 | static tree field_type PARAMS ((tree)); | |
3658 | static unsigned int simple_type_align_in_bits PARAMS ((tree)); | |
5f446d21 | 3659 | static unsigned int simple_decl_align_in_bits PARAMS ((tree)); |
7d9d8943 AM |
3660 | static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree)); |
3661 | static HOST_WIDE_INT field_byte_offset PARAMS ((tree)); | |
3662 | static void add_AT_location_description PARAMS ((dw_die_ref, | |
b9203463 RH |
3663 | enum dwarf_attribute, |
3664 | dw_loc_descr_ref)); | |
7d9d8943 AM |
3665 | static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree)); |
3666 | static void add_const_value_attribute PARAMS ((dw_die_ref, rtx)); | |
d8041cc8 | 3667 | static rtx rtl_for_decl_location PARAMS ((tree)); |
7d9d8943 | 3668 | static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree)); |
1bfb5f8f | 3669 | static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree)); |
7d9d8943 AM |
3670 | static void add_name_attribute PARAMS ((dw_die_ref, const char *)); |
3671 | static void add_bound_info PARAMS ((dw_die_ref, | |
3672 | enum dwarf_attribute, tree)); | |
3673 | static void add_subscript_info PARAMS ((dw_die_ref, tree)); | |
3674 | static void add_byte_size_attribute PARAMS ((dw_die_ref, tree)); | |
3675 | static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree)); | |
3676 | static void add_bit_size_attribute PARAMS ((dw_die_ref, tree)); | |
3677 | static void add_prototyped_attribute PARAMS ((dw_die_ref, tree)); | |
3678 | static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree)); | |
3679 | static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree)); | |
3680 | static void add_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
3681 | static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
3682 | static void push_decl_scope PARAMS ((tree)); | |
7d9d8943 | 3683 | static void pop_decl_scope PARAMS ((void)); |
2ad9852d RK |
3684 | static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref)); |
3685 | static inline int local_scope_p PARAMS ((dw_die_ref)); | |
3686 | static inline int class_scope_p PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3687 | static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int, |
3688 | dw_die_ref)); | |
3689 | static const char *type_tag PARAMS ((tree)); | |
3690 | static tree member_declared_type PARAMS ((tree)); | |
3691 | #if 0 | |
3692 | static const char *decl_start_label PARAMS ((tree)); | |
3693 | #endif | |
3694 | static void gen_array_type_die PARAMS ((tree, dw_die_ref)); | |
3695 | static void gen_set_type_die PARAMS ((tree, dw_die_ref)); | |
3696 | #if 0 | |
3697 | static void gen_entry_point_die PARAMS ((tree, dw_die_ref)); | |
3698 | #endif | |
3699 | static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
3700 | static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref)); | |
3701 | static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref)); | |
3702 | static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
3703 | static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref)); | |
3704 | static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref)); | |
3705 | static void gen_formal_types_die PARAMS ((tree, dw_die_ref)); | |
3706 | static void gen_subprogram_die PARAMS ((tree, dw_die_ref)); | |
3707 | static void gen_variable_die PARAMS ((tree, dw_die_ref)); | |
3708 | static void gen_label_die PARAMS ((tree, dw_die_ref)); | |
3709 | static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int)); | |
3710 | static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int)); | |
3711 | static void gen_field_die PARAMS ((tree, dw_die_ref)); | |
3712 | static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref)); | |
3713 | static dw_die_ref gen_compile_unit_die PARAMS ((const char *)); | |
3714 | static void gen_string_type_die PARAMS ((tree, dw_die_ref)); | |
3715 | static void gen_inheritance_die PARAMS ((tree, dw_die_ref)); | |
3716 | static void gen_member_die PARAMS ((tree, dw_die_ref)); | |
3717 | static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref)); | |
3718 | static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref)); | |
3719 | static void gen_typedef_die PARAMS ((tree, dw_die_ref)); | |
3720 | static void gen_type_die PARAMS ((tree, dw_die_ref)); | |
3721 | static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref)); | |
3722 | static void gen_block_die PARAMS ((tree, dw_die_ref, int)); | |
3723 | static void decls_for_scope PARAMS ((tree, dw_die_ref, int)); | |
3724 | static int is_redundant_typedef PARAMS ((tree)); | |
3725 | static void gen_decl_die PARAMS ((tree, dw_die_ref)); | |
981975b6 RH |
3726 | static unsigned lookup_filename PARAMS ((const char *)); |
3727 | static void init_file_table PARAMS ((void)); | |
7d9d8943 AM |
3728 | static void retry_incomplete_types PARAMS ((void)); |
3729 | static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref)); | |
7d9d8943 | 3730 | static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref)); |
fc608b03 | 3731 | static int file_info_cmp PARAMS ((const void *, const void *)); |
c26fbbca | 3732 | static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref, |
84a5b4f8 DB |
3733 | const char *, const char *, |
3734 | const char *, unsigned)); | |
3735 | static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *, | |
3736 | dw_loc_descr_ref, | |
3737 | const char *, const char *, const char *)); | |
3738 | static void output_loc_list PARAMS ((dw_loc_list_ref)); | |
3739 | static char *gen_internal_sym PARAMS ((const char *)); | |
54ba1f0d | 3740 | static void mark_limbo_die_list PARAMS ((void *)); |
7d9d8943 AM |
3741 | |
3742 | /* Section names used to hold DWARF debugging information. */ | |
3743 | #ifndef DEBUG_INFO_SECTION | |
3744 | #define DEBUG_INFO_SECTION ".debug_info" | |
3745 | #endif | |
9d2f2c45 RH |
3746 | #ifndef DEBUG_ABBREV_SECTION |
3747 | #define DEBUG_ABBREV_SECTION ".debug_abbrev" | |
7d9d8943 | 3748 | #endif |
9d2f2c45 RH |
3749 | #ifndef DEBUG_ARANGES_SECTION |
3750 | #define DEBUG_ARANGES_SECTION ".debug_aranges" | |
7d9d8943 | 3751 | #endif |
9d2f2c45 RH |
3752 | #ifndef DEBUG_MACINFO_SECTION |
3753 | #define DEBUG_MACINFO_SECTION ".debug_macinfo" | |
7d9d8943 AM |
3754 | #endif |
3755 | #ifndef DEBUG_LINE_SECTION | |
3756 | #define DEBUG_LINE_SECTION ".debug_line" | |
3757 | #endif | |
9d2f2c45 RH |
3758 | #ifndef DEBUG_LOC_SECTION |
3759 | #define DEBUG_LOC_SECTION ".debug_loc" | |
7d9d8943 | 3760 | #endif |
9d2f2c45 RH |
3761 | #ifndef DEBUG_PUBNAMES_SECTION |
3762 | #define DEBUG_PUBNAMES_SECTION ".debug_pubnames" | |
7d9d8943 | 3763 | #endif |
9d2f2c45 RH |
3764 | #ifndef DEBUG_STR_SECTION |
3765 | #define DEBUG_STR_SECTION ".debug_str" | |
7d9d8943 | 3766 | #endif |
a20612aa RH |
3767 | #ifndef DEBUG_RANGES_SECTION |
3768 | #define DEBUG_RANGES_SECTION ".debug_ranges" | |
3769 | #endif | |
7d9d8943 AM |
3770 | |
3771 | /* Standard ELF section names for compiled code and data. */ | |
f99ffb60 RH |
3772 | #ifndef TEXT_SECTION_NAME |
3773 | #define TEXT_SECTION_NAME ".text" | |
7d9d8943 AM |
3774 | #endif |
3775 | ||
9eb4015a JJ |
3776 | /* Section flags for .debug_str section. */ |
3777 | #ifdef HAVE_GAS_SHF_MERGE | |
3778 | #define DEBUG_STR_SECTION_FLAGS \ | |
3779 | (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1) | |
3780 | #else | |
3781 | #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG | |
3782 | #endif | |
3783 | ||
7d9d8943 | 3784 | /* Labels we insert at beginning sections we can reference instead of |
556273e0 | 3785 | the section names themselves. */ |
7d9d8943 AM |
3786 | |
3787 | #ifndef TEXT_SECTION_LABEL | |
9d2f2c45 | 3788 | #define TEXT_SECTION_LABEL "Ltext" |
7d9d8943 AM |
3789 | #endif |
3790 | #ifndef DEBUG_LINE_SECTION_LABEL | |
9d2f2c45 | 3791 | #define DEBUG_LINE_SECTION_LABEL "Ldebug_line" |
7d9d8943 AM |
3792 | #endif |
3793 | #ifndef DEBUG_INFO_SECTION_LABEL | |
9d2f2c45 | 3794 | #define DEBUG_INFO_SECTION_LABEL "Ldebug_info" |
7d9d8943 | 3795 | #endif |
9d2f2c45 RH |
3796 | #ifndef DEBUG_ABBREV_SECTION_LABEL |
3797 | #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev" | |
7d9d8943 | 3798 | #endif |
9d2f2c45 RH |
3799 | #ifndef DEBUG_LOC_SECTION_LABEL |
3800 | #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc" | |
63e46568 | 3801 | #endif |
2bee6045 JJ |
3802 | #ifndef DEBUG_RANGES_SECTION_LABEL |
3803 | #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges" | |
3804 | #endif | |
84a5b4f8 DB |
3805 | #ifndef DEBUG_MACINFO_SECTION_LABEL |
3806 | #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo" | |
3807 | #endif | |
a20612aa | 3808 | |
7d9d8943 AM |
3809 | /* Definitions of defaults for formats and names of various special |
3810 | (artificial) labels which may be generated within this file (when the -g | |
3811 | options is used and DWARF_DEBUGGING_INFO is in effect. | |
3812 | If necessary, these may be overridden from within the tm.h file, but | |
3813 | typically, overriding these defaults is unnecessary. */ | |
3814 | ||
3815 | static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3816 | static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3817 | static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3818 | static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3819 | static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
84a5b4f8 | 3820 | static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
63e46568 | 3821 | static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
2bee6045 | 3822 | static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES]; |
2ad9852d | 3823 | |
7d9d8943 AM |
3824 | #ifndef TEXT_END_LABEL |
3825 | #define TEXT_END_LABEL "Letext" | |
3826 | #endif | |
7d9d8943 AM |
3827 | #ifndef BLOCK_BEGIN_LABEL |
3828 | #define BLOCK_BEGIN_LABEL "LBB" | |
3829 | #endif | |
3830 | #ifndef BLOCK_END_LABEL | |
3831 | #define BLOCK_END_LABEL "LBE" | |
3832 | #endif | |
7d9d8943 AM |
3833 | #ifndef LINE_CODE_LABEL |
3834 | #define LINE_CODE_LABEL "LM" | |
3835 | #endif | |
3836 | #ifndef SEPARATE_LINE_CODE_LABEL | |
3837 | #define SEPARATE_LINE_CODE_LABEL "LSM" | |
3838 | #endif | |
3839 | \f | |
3840 | /* We allow a language front-end to designate a function that is to be | |
3841 | called to "demangle" any name before it it put into a DIE. */ | |
3842 | ||
3843 | static const char *(*demangle_name_func) PARAMS ((const char *)); | |
3844 | ||
3845 | void | |
3846 | dwarf2out_set_demangle_name_func (func) | |
3847 | const char *(*func) PARAMS ((const char *)); | |
3848 | { | |
3849 | demangle_name_func = func; | |
3850 | } | |
7d9d8943 AM |
3851 | |
3852 | /* Test if rtl node points to a pseudo register. */ | |
3853 | ||
3854 | static inline int | |
3855 | is_pseudo_reg (rtl) | |
b3694847 | 3856 | rtx rtl; |
7d9d8943 AM |
3857 | { |
3858 | return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER) | |
3859 | || (GET_CODE (rtl) == SUBREG | |
ddef6bc7 | 3860 | && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)); |
7d9d8943 AM |
3861 | } |
3862 | ||
3863 | /* Return a reference to a type, with its const and volatile qualifiers | |
3864 | removed. */ | |
3865 | ||
3866 | static inline tree | |
3867 | type_main_variant (type) | |
b3694847 | 3868 | tree type; |
7d9d8943 AM |
3869 | { |
3870 | type = TYPE_MAIN_VARIANT (type); | |
3871 | ||
2ad9852d RK |
3872 | /* ??? There really should be only one main variant among any group of |
3873 | variants of a given type (and all of the MAIN_VARIANT values for all | |
3874 | members of the group should point to that one type) but sometimes the C | |
3875 | front-end messes this up for array types, so we work around that bug | |
3876 | here. */ | |
7d9d8943 AM |
3877 | if (TREE_CODE (type) == ARRAY_TYPE) |
3878 | while (type != TYPE_MAIN_VARIANT (type)) | |
3879 | type = TYPE_MAIN_VARIANT (type); | |
3880 | ||
3881 | return type; | |
3882 | } | |
3883 | ||
cc2902df | 3884 | /* Return nonzero if the given type node represents a tagged type. */ |
7d9d8943 AM |
3885 | |
3886 | static inline int | |
3887 | is_tagged_type (type) | |
b3694847 | 3888 | tree type; |
7d9d8943 | 3889 | { |
b3694847 | 3890 | enum tree_code code = TREE_CODE (type); |
7d9d8943 AM |
3891 | |
3892 | return (code == RECORD_TYPE || code == UNION_TYPE | |
3893 | || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); | |
3894 | } | |
3895 | ||
3896 | /* Convert a DIE tag into its string name. */ | |
3897 | ||
3898 | static const char * | |
3899 | dwarf_tag_name (tag) | |
b3694847 | 3900 | unsigned tag; |
7d9d8943 AM |
3901 | { |
3902 | switch (tag) | |
3903 | { | |
3904 | case DW_TAG_padding: | |
3905 | return "DW_TAG_padding"; | |
3906 | case DW_TAG_array_type: | |
3907 | return "DW_TAG_array_type"; | |
3908 | case DW_TAG_class_type: | |
3909 | return "DW_TAG_class_type"; | |
3910 | case DW_TAG_entry_point: | |
3911 | return "DW_TAG_entry_point"; | |
3912 | case DW_TAG_enumeration_type: | |
3913 | return "DW_TAG_enumeration_type"; | |
3914 | case DW_TAG_formal_parameter: | |
3915 | return "DW_TAG_formal_parameter"; | |
3916 | case DW_TAG_imported_declaration: | |
3917 | return "DW_TAG_imported_declaration"; | |
3918 | case DW_TAG_label: | |
3919 | return "DW_TAG_label"; | |
3920 | case DW_TAG_lexical_block: | |
3921 | return "DW_TAG_lexical_block"; | |
3922 | case DW_TAG_member: | |
3923 | return "DW_TAG_member"; | |
3924 | case DW_TAG_pointer_type: | |
3925 | return "DW_TAG_pointer_type"; | |
3926 | case DW_TAG_reference_type: | |
3927 | return "DW_TAG_reference_type"; | |
3928 | case DW_TAG_compile_unit: | |
3929 | return "DW_TAG_compile_unit"; | |
3930 | case DW_TAG_string_type: | |
3931 | return "DW_TAG_string_type"; | |
3932 | case DW_TAG_structure_type: | |
3933 | return "DW_TAG_structure_type"; | |
3934 | case DW_TAG_subroutine_type: | |
3935 | return "DW_TAG_subroutine_type"; | |
3936 | case DW_TAG_typedef: | |
3937 | return "DW_TAG_typedef"; | |
3938 | case DW_TAG_union_type: | |
3939 | return "DW_TAG_union_type"; | |
3940 | case DW_TAG_unspecified_parameters: | |
3941 | return "DW_TAG_unspecified_parameters"; | |
3942 | case DW_TAG_variant: | |
3943 | return "DW_TAG_variant"; | |
3944 | case DW_TAG_common_block: | |
3945 | return "DW_TAG_common_block"; | |
3946 | case DW_TAG_common_inclusion: | |
3947 | return "DW_TAG_common_inclusion"; | |
3948 | case DW_TAG_inheritance: | |
3949 | return "DW_TAG_inheritance"; | |
3950 | case DW_TAG_inlined_subroutine: | |
3951 | return "DW_TAG_inlined_subroutine"; | |
3952 | case DW_TAG_module: | |
3953 | return "DW_TAG_module"; | |
3954 | case DW_TAG_ptr_to_member_type: | |
3955 | return "DW_TAG_ptr_to_member_type"; | |
3956 | case DW_TAG_set_type: | |
3957 | return "DW_TAG_set_type"; | |
3958 | case DW_TAG_subrange_type: | |
3959 | return "DW_TAG_subrange_type"; | |
3960 | case DW_TAG_with_stmt: | |
3961 | return "DW_TAG_with_stmt"; | |
3962 | case DW_TAG_access_declaration: | |
3963 | return "DW_TAG_access_declaration"; | |
3964 | case DW_TAG_base_type: | |
3965 | return "DW_TAG_base_type"; | |
3966 | case DW_TAG_catch_block: | |
3967 | return "DW_TAG_catch_block"; | |
3968 | case DW_TAG_const_type: | |
3969 | return "DW_TAG_const_type"; | |
3970 | case DW_TAG_constant: | |
3971 | return "DW_TAG_constant"; | |
3972 | case DW_TAG_enumerator: | |
3973 | return "DW_TAG_enumerator"; | |
3974 | case DW_TAG_file_type: | |
3975 | return "DW_TAG_file_type"; | |
3976 | case DW_TAG_friend: | |
3977 | return "DW_TAG_friend"; | |
3978 | case DW_TAG_namelist: | |
3979 | return "DW_TAG_namelist"; | |
3980 | case DW_TAG_namelist_item: | |
3981 | return "DW_TAG_namelist_item"; | |
3982 | case DW_TAG_packed_type: | |
3983 | return "DW_TAG_packed_type"; | |
3984 | case DW_TAG_subprogram: | |
3985 | return "DW_TAG_subprogram"; | |
3986 | case DW_TAG_template_type_param: | |
3987 | return "DW_TAG_template_type_param"; | |
3988 | case DW_TAG_template_value_param: | |
3989 | return "DW_TAG_template_value_param"; | |
3990 | case DW_TAG_thrown_type: | |
3991 | return "DW_TAG_thrown_type"; | |
3992 | case DW_TAG_try_block: | |
3993 | return "DW_TAG_try_block"; | |
3994 | case DW_TAG_variant_part: | |
3995 | return "DW_TAG_variant_part"; | |
3996 | case DW_TAG_variable: | |
3997 | return "DW_TAG_variable"; | |
3998 | case DW_TAG_volatile_type: | |
3999 | return "DW_TAG_volatile_type"; | |
4000 | case DW_TAG_MIPS_loop: | |
4001 | return "DW_TAG_MIPS_loop"; | |
4002 | case DW_TAG_format_label: | |
4003 | return "DW_TAG_format_label"; | |
4004 | case DW_TAG_function_template: | |
4005 | return "DW_TAG_function_template"; | |
4006 | case DW_TAG_class_template: | |
4007 | return "DW_TAG_class_template"; | |
881c6935 JM |
4008 | case DW_TAG_GNU_BINCL: |
4009 | return "DW_TAG_GNU_BINCL"; | |
4010 | case DW_TAG_GNU_EINCL: | |
4011 | return "DW_TAG_GNU_EINCL"; | |
7d9d8943 AM |
4012 | default: |
4013 | return "DW_TAG_<unknown>"; | |
4014 | } | |
4015 | } | |
4016 | ||
4017 | /* Convert a DWARF attribute code into its string name. */ | |
4018 | ||
4019 | static const char * | |
4020 | dwarf_attr_name (attr) | |
b3694847 | 4021 | unsigned attr; |
7d9d8943 AM |
4022 | { |
4023 | switch (attr) | |
4024 | { | |
4025 | case DW_AT_sibling: | |
4026 | return "DW_AT_sibling"; | |
4027 | case DW_AT_location: | |
4028 | return "DW_AT_location"; | |
4029 | case DW_AT_name: | |
4030 | return "DW_AT_name"; | |
4031 | case DW_AT_ordering: | |
4032 | return "DW_AT_ordering"; | |
4033 | case DW_AT_subscr_data: | |
4034 | return "DW_AT_subscr_data"; | |
4035 | case DW_AT_byte_size: | |
4036 | return "DW_AT_byte_size"; | |
4037 | case DW_AT_bit_offset: | |
4038 | return "DW_AT_bit_offset"; | |
4039 | case DW_AT_bit_size: | |
4040 | return "DW_AT_bit_size"; | |
4041 | case DW_AT_element_list: | |
4042 | return "DW_AT_element_list"; | |
4043 | case DW_AT_stmt_list: | |
4044 | return "DW_AT_stmt_list"; | |
4045 | case DW_AT_low_pc: | |
4046 | return "DW_AT_low_pc"; | |
4047 | case DW_AT_high_pc: | |
4048 | return "DW_AT_high_pc"; | |
4049 | case DW_AT_language: | |
4050 | return "DW_AT_language"; | |
4051 | case DW_AT_member: | |
4052 | return "DW_AT_member"; | |
4053 | case DW_AT_discr: | |
4054 | return "DW_AT_discr"; | |
4055 | case DW_AT_discr_value: | |
4056 | return "DW_AT_discr_value"; | |
4057 | case DW_AT_visibility: | |
4058 | return "DW_AT_visibility"; | |
4059 | case DW_AT_import: | |
4060 | return "DW_AT_import"; | |
4061 | case DW_AT_string_length: | |
4062 | return "DW_AT_string_length"; | |
4063 | case DW_AT_common_reference: | |
4064 | return "DW_AT_common_reference"; | |
4065 | case DW_AT_comp_dir: | |
4066 | return "DW_AT_comp_dir"; | |
4067 | case DW_AT_const_value: | |
4068 | return "DW_AT_const_value"; | |
4069 | case DW_AT_containing_type: | |
4070 | return "DW_AT_containing_type"; | |
4071 | case DW_AT_default_value: | |
4072 | return "DW_AT_default_value"; | |
4073 | case DW_AT_inline: | |
4074 | return "DW_AT_inline"; | |
4075 | case DW_AT_is_optional: | |
4076 | return "DW_AT_is_optional"; | |
4077 | case DW_AT_lower_bound: | |
4078 | return "DW_AT_lower_bound"; | |
4079 | case DW_AT_producer: | |
4080 | return "DW_AT_producer"; | |
4081 | case DW_AT_prototyped: | |
4082 | return "DW_AT_prototyped"; | |
4083 | case DW_AT_return_addr: | |
4084 | return "DW_AT_return_addr"; | |
4085 | case DW_AT_start_scope: | |
4086 | return "DW_AT_start_scope"; | |
4087 | case DW_AT_stride_size: | |
4088 | return "DW_AT_stride_size"; | |
4089 | case DW_AT_upper_bound: | |
4090 | return "DW_AT_upper_bound"; | |
4091 | case DW_AT_abstract_origin: | |
4092 | return "DW_AT_abstract_origin"; | |
4093 | case DW_AT_accessibility: | |
4094 | return "DW_AT_accessibility"; | |
4095 | case DW_AT_address_class: | |
4096 | return "DW_AT_address_class"; | |
4097 | case DW_AT_artificial: | |
4098 | return "DW_AT_artificial"; | |
4099 | case DW_AT_base_types: | |
4100 | return "DW_AT_base_types"; | |
4101 | case DW_AT_calling_convention: | |
4102 | return "DW_AT_calling_convention"; | |
4103 | case DW_AT_count: | |
4104 | return "DW_AT_count"; | |
4105 | case DW_AT_data_member_location: | |
4106 | return "DW_AT_data_member_location"; | |
4107 | case DW_AT_decl_column: | |
4108 | return "DW_AT_decl_column"; | |
4109 | case DW_AT_decl_file: | |
4110 | return "DW_AT_decl_file"; | |
4111 | case DW_AT_decl_line: | |
4112 | return "DW_AT_decl_line"; | |
4113 | case DW_AT_declaration: | |
4114 | return "DW_AT_declaration"; | |
4115 | case DW_AT_discr_list: | |
4116 | return "DW_AT_discr_list"; | |
4117 | case DW_AT_encoding: | |
4118 | return "DW_AT_encoding"; | |
4119 | case DW_AT_external: | |
4120 | return "DW_AT_external"; | |
4121 | case DW_AT_frame_base: | |
4122 | return "DW_AT_frame_base"; | |
4123 | case DW_AT_friend: | |
4124 | return "DW_AT_friend"; | |
4125 | case DW_AT_identifier_case: | |
4126 | return "DW_AT_identifier_case"; | |
4127 | case DW_AT_macro_info: | |
4128 | return "DW_AT_macro_info"; | |
4129 | case DW_AT_namelist_items: | |
4130 | return "DW_AT_namelist_items"; | |
4131 | case DW_AT_priority: | |
4132 | return "DW_AT_priority"; | |
4133 | case DW_AT_segment: | |
4134 | return "DW_AT_segment"; | |
4135 | case DW_AT_specification: | |
4136 | return "DW_AT_specification"; | |
4137 | case DW_AT_static_link: | |
4138 | return "DW_AT_static_link"; | |
4139 | case DW_AT_type: | |
4140 | return "DW_AT_type"; | |
4141 | case DW_AT_use_location: | |
4142 | return "DW_AT_use_location"; | |
4143 | case DW_AT_variable_parameter: | |
4144 | return "DW_AT_variable_parameter"; | |
4145 | case DW_AT_virtuality: | |
4146 | return "DW_AT_virtuality"; | |
4147 | case DW_AT_vtable_elem_location: | |
4148 | return "DW_AT_vtable_elem_location"; | |
4149 | ||
a20612aa RH |
4150 | case DW_AT_allocated: |
4151 | return "DW_AT_allocated"; | |
4152 | case DW_AT_associated: | |
4153 | return "DW_AT_associated"; | |
4154 | case DW_AT_data_location: | |
4155 | return "DW_AT_data_location"; | |
4156 | case DW_AT_stride: | |
4157 | return "DW_AT_stride"; | |
4158 | case DW_AT_entry_pc: | |
4159 | return "DW_AT_entry_pc"; | |
4160 | case DW_AT_use_UTF8: | |
4161 | return "DW_AT_use_UTF8"; | |
4162 | case DW_AT_extension: | |
4163 | return "DW_AT_extension"; | |
4164 | case DW_AT_ranges: | |
4165 | return "DW_AT_ranges"; | |
4166 | case DW_AT_trampoline: | |
4167 | return "DW_AT_trampoline"; | |
4168 | case DW_AT_call_column: | |
4169 | return "DW_AT_call_column"; | |
4170 | case DW_AT_call_file: | |
4171 | return "DW_AT_call_file"; | |
4172 | case DW_AT_call_line: | |
4173 | return "DW_AT_call_line"; | |
4174 | ||
7d9d8943 AM |
4175 | case DW_AT_MIPS_fde: |
4176 | return "DW_AT_MIPS_fde"; | |
4177 | case DW_AT_MIPS_loop_begin: | |
4178 | return "DW_AT_MIPS_loop_begin"; | |
4179 | case DW_AT_MIPS_tail_loop_begin: | |
4180 | return "DW_AT_MIPS_tail_loop_begin"; | |
4181 | case DW_AT_MIPS_epilog_begin: | |
4182 | return "DW_AT_MIPS_epilog_begin"; | |
4183 | case DW_AT_MIPS_loop_unroll_factor: | |
4184 | return "DW_AT_MIPS_loop_unroll_factor"; | |
4185 | case DW_AT_MIPS_software_pipeline_depth: | |
4186 | return "DW_AT_MIPS_software_pipeline_depth"; | |
4187 | case DW_AT_MIPS_linkage_name: | |
4188 | return "DW_AT_MIPS_linkage_name"; | |
4189 | case DW_AT_MIPS_stride: | |
4190 | return "DW_AT_MIPS_stride"; | |
4191 | case DW_AT_MIPS_abstract_name: | |
4192 | return "DW_AT_MIPS_abstract_name"; | |
4193 | case DW_AT_MIPS_clone_origin: | |
4194 | return "DW_AT_MIPS_clone_origin"; | |
4195 | case DW_AT_MIPS_has_inlines: | |
4196 | return "DW_AT_MIPS_has_inlines"; | |
4197 | ||
4198 | case DW_AT_sf_names: | |
4199 | return "DW_AT_sf_names"; | |
4200 | case DW_AT_src_info: | |
4201 | return "DW_AT_src_info"; | |
4202 | case DW_AT_mac_info: | |
4203 | return "DW_AT_mac_info"; | |
4204 | case DW_AT_src_coords: | |
4205 | return "DW_AT_src_coords"; | |
4206 | case DW_AT_body_begin: | |
4207 | return "DW_AT_body_begin"; | |
4208 | case DW_AT_body_end: | |
4209 | return "DW_AT_body_end"; | |
84f0ace0 JM |
4210 | case DW_AT_GNU_vector: |
4211 | return "DW_AT_GNU_vector"; | |
4212 | ||
7a0c8d71 DR |
4213 | case DW_AT_VMS_rtnbeg_pd_address: |
4214 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
4215 | ||
7d9d8943 AM |
4216 | default: |
4217 | return "DW_AT_<unknown>"; | |
4218 | } | |
4219 | } | |
4220 | ||
4221 | /* Convert a DWARF value form code into its string name. */ | |
4222 | ||
4223 | static const char * | |
4224 | dwarf_form_name (form) | |
b3694847 | 4225 | unsigned form; |
7d9d8943 AM |
4226 | { |
4227 | switch (form) | |
4228 | { | |
4229 | case DW_FORM_addr: | |
4230 | return "DW_FORM_addr"; | |
4231 | case DW_FORM_block2: | |
4232 | return "DW_FORM_block2"; | |
4233 | case DW_FORM_block4: | |
4234 | return "DW_FORM_block4"; | |
4235 | case DW_FORM_data2: | |
4236 | return "DW_FORM_data2"; | |
4237 | case DW_FORM_data4: | |
4238 | return "DW_FORM_data4"; | |
4239 | case DW_FORM_data8: | |
4240 | return "DW_FORM_data8"; | |
4241 | case DW_FORM_string: | |
4242 | return "DW_FORM_string"; | |
4243 | case DW_FORM_block: | |
4244 | return "DW_FORM_block"; | |
4245 | case DW_FORM_block1: | |
4246 | return "DW_FORM_block1"; | |
4247 | case DW_FORM_data1: | |
4248 | return "DW_FORM_data1"; | |
4249 | case DW_FORM_flag: | |
4250 | return "DW_FORM_flag"; | |
4251 | case DW_FORM_sdata: | |
4252 | return "DW_FORM_sdata"; | |
4253 | case DW_FORM_strp: | |
4254 | return "DW_FORM_strp"; | |
4255 | case DW_FORM_udata: | |
4256 | return "DW_FORM_udata"; | |
4257 | case DW_FORM_ref_addr: | |
4258 | return "DW_FORM_ref_addr"; | |
4259 | case DW_FORM_ref1: | |
4260 | return "DW_FORM_ref1"; | |
4261 | case DW_FORM_ref2: | |
4262 | return "DW_FORM_ref2"; | |
4263 | case DW_FORM_ref4: | |
4264 | return "DW_FORM_ref4"; | |
4265 | case DW_FORM_ref8: | |
4266 | return "DW_FORM_ref8"; | |
4267 | case DW_FORM_ref_udata: | |
4268 | return "DW_FORM_ref_udata"; | |
4269 | case DW_FORM_indirect: | |
4270 | return "DW_FORM_indirect"; | |
3f76745e | 4271 | default: |
7d9d8943 | 4272 | return "DW_FORM_<unknown>"; |
a3f97cbb JW |
4273 | } |
4274 | } | |
4275 | ||
3f76745e | 4276 | /* Convert a DWARF type code into its string name. */ |
71dfc51f | 4277 | |
487a6e06 | 4278 | #if 0 |
d560ee52 | 4279 | static const char * |
3f76745e | 4280 | dwarf_type_encoding_name (enc) |
b3694847 | 4281 | unsigned enc; |
a3f97cbb | 4282 | { |
3f76745e | 4283 | switch (enc) |
a3f97cbb | 4284 | { |
3f76745e JM |
4285 | case DW_ATE_address: |
4286 | return "DW_ATE_address"; | |
4287 | case DW_ATE_boolean: | |
4288 | return "DW_ATE_boolean"; | |
4289 | case DW_ATE_complex_float: | |
4290 | return "DW_ATE_complex_float"; | |
4291 | case DW_ATE_float: | |
4292 | return "DW_ATE_float"; | |
4293 | case DW_ATE_signed: | |
4294 | return "DW_ATE_signed"; | |
4295 | case DW_ATE_signed_char: | |
4296 | return "DW_ATE_signed_char"; | |
4297 | case DW_ATE_unsigned: | |
4298 | return "DW_ATE_unsigned"; | |
4299 | case DW_ATE_unsigned_char: | |
4300 | return "DW_ATE_unsigned_char"; | |
4301 | default: | |
4302 | return "DW_ATE_<unknown>"; | |
4303 | } | |
a3f97cbb | 4304 | } |
487a6e06 | 4305 | #endif |
3f76745e JM |
4306 | \f |
4307 | /* Determine the "ultimate origin" of a decl. The decl may be an inlined | |
4308 | instance of an inlined instance of a decl which is local to an inline | |
4309 | function, so we have to trace all of the way back through the origin chain | |
4310 | to find out what sort of node actually served as the original seed for the | |
4311 | given block. */ | |
a3f97cbb | 4312 | |
3f76745e JM |
4313 | static tree |
4314 | decl_ultimate_origin (decl) | |
b3694847 | 4315 | tree decl; |
a3f97cbb | 4316 | { |
10a11b75 JM |
4317 | /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the |
4318 | nodes in the function to point to themselves; ignore that if | |
4319 | we're trying to output the abstract instance of this function. */ | |
4320 | if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl) | |
4321 | return NULL_TREE; | |
4322 | ||
556273e0 | 4323 | #ifdef ENABLE_CHECKING |
02e24c7a MM |
4324 | if (DECL_FROM_INLINE (DECL_ORIGIN (decl))) |
4325 | /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the | |
4326 | most distant ancestor, this should never happen. */ | |
4327 | abort (); | |
4328 | #endif | |
3f76745e | 4329 | |
02e24c7a | 4330 | return DECL_ABSTRACT_ORIGIN (decl); |
a3f97cbb JW |
4331 | } |
4332 | ||
3f76745e JM |
4333 | /* Determine the "ultimate origin" of a block. The block may be an inlined |
4334 | instance of an inlined instance of a block which is local to an inline | |
4335 | function, so we have to trace all of the way back through the origin chain | |
4336 | to find out what sort of node actually served as the original seed for the | |
4337 | given block. */ | |
71dfc51f | 4338 | |
3f76745e JM |
4339 | static tree |
4340 | block_ultimate_origin (block) | |
b3694847 | 4341 | tree block; |
a3f97cbb | 4342 | { |
b3694847 | 4343 | tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); |
71dfc51f | 4344 | |
10a11b75 JM |
4345 | /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the |
4346 | nodes in the function to point to themselves; ignore that if | |
4347 | we're trying to output the abstract instance of this function. */ | |
4348 | if (BLOCK_ABSTRACT (block) && immediate_origin == block) | |
4349 | return NULL_TREE; | |
4350 | ||
3f76745e JM |
4351 | if (immediate_origin == NULL_TREE) |
4352 | return NULL_TREE; | |
4353 | else | |
4354 | { | |
b3694847 SS |
4355 | tree ret_val; |
4356 | tree lookahead = immediate_origin; | |
71dfc51f | 4357 | |
3f76745e JM |
4358 | do |
4359 | { | |
4360 | ret_val = lookahead; | |
2ad9852d RK |
4361 | lookahead = (TREE_CODE (ret_val) == BLOCK |
4362 | ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL); | |
3f76745e JM |
4363 | } |
4364 | while (lookahead != NULL && lookahead != ret_val); | |
4365 | ||
4366 | return ret_val; | |
4367 | } | |
a3f97cbb JW |
4368 | } |
4369 | ||
3f76745e JM |
4370 | /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT |
4371 | of a virtual function may refer to a base class, so we check the 'this' | |
4372 | parameter. */ | |
71dfc51f | 4373 | |
3f76745e JM |
4374 | static tree |
4375 | decl_class_context (decl) | |
4376 | tree decl; | |
a3f97cbb | 4377 | { |
3f76745e | 4378 | tree context = NULL_TREE; |
71dfc51f | 4379 | |
3f76745e JM |
4380 | if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl)) |
4381 | context = DECL_CONTEXT (decl); | |
4382 | else | |
4383 | context = TYPE_MAIN_VARIANT | |
4384 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
71dfc51f | 4385 | |
2f939d94 | 4386 | if (context && !TYPE_P (context)) |
3f76745e JM |
4387 | context = NULL_TREE; |
4388 | ||
4389 | return context; | |
a3f97cbb JW |
4390 | } |
4391 | \f | |
a96c67ec | 4392 | /* Add an attribute/value pair to a DIE. We build the lists up in reverse |
881c6935 | 4393 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f RK |
4394 | |
4395 | static inline void | |
3f76745e | 4396 | add_dwarf_attr (die, attr) |
b3694847 SS |
4397 | dw_die_ref die; |
4398 | dw_attr_ref attr; | |
a3f97cbb | 4399 | { |
3f76745e | 4400 | if (die != NULL && attr != NULL) |
a3f97cbb | 4401 | { |
a96c67ec JM |
4402 | attr->dw_attr_next = die->die_attr; |
4403 | die->die_attr = attr; | |
a3f97cbb JW |
4404 | } |
4405 | } | |
4406 | ||
a96c67ec JM |
4407 | static inline dw_val_class |
4408 | AT_class (a) | |
4409 | dw_attr_ref a; | |
4410 | { | |
4411 | return a->dw_attr_val.val_class; | |
4412 | } | |
4413 | ||
3f76745e | 4414 | /* Add a flag value attribute to a DIE. */ |
71dfc51f | 4415 | |
3f76745e JM |
4416 | static inline void |
4417 | add_AT_flag (die, attr_kind, flag) | |
b3694847 SS |
4418 | dw_die_ref die; |
4419 | enum dwarf_attribute attr_kind; | |
4420 | unsigned flag; | |
a3f97cbb | 4421 | { |
b3694847 | 4422 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4423 | |
3f76745e JM |
4424 | attr->dw_attr_next = NULL; |
4425 | attr->dw_attr = attr_kind; | |
4426 | attr->dw_attr_val.val_class = dw_val_class_flag; | |
4427 | attr->dw_attr_val.v.val_flag = flag; | |
4428 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4429 | } |
4430 | ||
a96c67ec JM |
4431 | static inline unsigned |
4432 | AT_flag (a) | |
b3694847 | 4433 | dw_attr_ref a; |
a96c67ec JM |
4434 | { |
4435 | if (a && AT_class (a) == dw_val_class_flag) | |
4436 | return a->dw_attr_val.v.val_flag; | |
4437 | ||
40e8cc95 | 4438 | abort (); |
a96c67ec JM |
4439 | } |
4440 | ||
3f76745e | 4441 | /* Add a signed integer attribute value to a DIE. */ |
71dfc51f | 4442 | |
3f76745e JM |
4443 | static inline void |
4444 | add_AT_int (die, attr_kind, int_val) | |
b3694847 SS |
4445 | dw_die_ref die; |
4446 | enum dwarf_attribute attr_kind; | |
4447 | long int int_val; | |
a3f97cbb | 4448 | { |
b3694847 | 4449 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3f76745e JM |
4450 | |
4451 | attr->dw_attr_next = NULL; | |
4452 | attr->dw_attr = attr_kind; | |
4453 | attr->dw_attr_val.val_class = dw_val_class_const; | |
4454 | attr->dw_attr_val.v.val_int = int_val; | |
4455 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4456 | } |
4457 | ||
a96c67ec JM |
4458 | static inline long int |
4459 | AT_int (a) | |
b3694847 | 4460 | dw_attr_ref a; |
a96c67ec JM |
4461 | { |
4462 | if (a && AT_class (a) == dw_val_class_const) | |
4463 | return a->dw_attr_val.v.val_int; | |
4464 | ||
40e8cc95 | 4465 | abort (); |
a96c67ec JM |
4466 | } |
4467 | ||
3f76745e | 4468 | /* Add an unsigned integer attribute value to a DIE. */ |
71dfc51f | 4469 | |
3f76745e JM |
4470 | static inline void |
4471 | add_AT_unsigned (die, attr_kind, unsigned_val) | |
b3694847 SS |
4472 | dw_die_ref die; |
4473 | enum dwarf_attribute attr_kind; | |
4474 | unsigned long unsigned_val; | |
a3f97cbb | 4475 | { |
b3694847 | 4476 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3f76745e JM |
4477 | |
4478 | attr->dw_attr_next = NULL; | |
4479 | attr->dw_attr = attr_kind; | |
4480 | attr->dw_attr_val.val_class = dw_val_class_unsigned_const; | |
4481 | attr->dw_attr_val.v.val_unsigned = unsigned_val; | |
4482 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4483 | } |
71dfc51f | 4484 | |
a96c67ec JM |
4485 | static inline unsigned long |
4486 | AT_unsigned (a) | |
b3694847 | 4487 | dw_attr_ref a; |
a96c67ec JM |
4488 | { |
4489 | if (a && AT_class (a) == dw_val_class_unsigned_const) | |
4490 | return a->dw_attr_val.v.val_unsigned; | |
4491 | ||
40e8cc95 | 4492 | abort (); |
a96c67ec JM |
4493 | } |
4494 | ||
3f76745e JM |
4495 | /* Add an unsigned double integer attribute value to a DIE. */ |
4496 | ||
4497 | static inline void | |
4498 | add_AT_long_long (die, attr_kind, val_hi, val_low) | |
b3694847 SS |
4499 | dw_die_ref die; |
4500 | enum dwarf_attribute attr_kind; | |
4501 | unsigned long val_hi; | |
4502 | unsigned long val_low; | |
a3f97cbb | 4503 | { |
b3694847 | 4504 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4505 | |
3f76745e JM |
4506 | attr->dw_attr_next = NULL; |
4507 | attr->dw_attr = attr_kind; | |
4508 | attr->dw_attr_val.val_class = dw_val_class_long_long; | |
4509 | attr->dw_attr_val.v.val_long_long.hi = val_hi; | |
4510 | attr->dw_attr_val.v.val_long_long.low = val_low; | |
4511 | add_dwarf_attr (die, attr); | |
4512 | } | |
71dfc51f | 4513 | |
3f76745e | 4514 | /* Add a floating point attribute value to a DIE and return it. */ |
71dfc51f | 4515 | |
3f76745e JM |
4516 | static inline void |
4517 | add_AT_float (die, attr_kind, length, array) | |
b3694847 SS |
4518 | dw_die_ref die; |
4519 | enum dwarf_attribute attr_kind; | |
4520 | unsigned length; | |
4521 | long *array; | |
3f76745e | 4522 | { |
b3694847 | 4523 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3f76745e JM |
4524 | |
4525 | attr->dw_attr_next = NULL; | |
4526 | attr->dw_attr = attr_kind; | |
4527 | attr->dw_attr_val.val_class = dw_val_class_float; | |
4528 | attr->dw_attr_val.v.val_float.length = length; | |
4529 | attr->dw_attr_val.v.val_float.array = array; | |
4530 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4531 | } |
4532 | ||
3f76745e | 4533 | /* Add a string attribute value to a DIE. */ |
71dfc51f | 4534 | |
3f76745e JM |
4535 | static inline void |
4536 | add_AT_string (die, attr_kind, str) | |
b3694847 SS |
4537 | dw_die_ref die; |
4538 | enum dwarf_attribute attr_kind; | |
4539 | const char *str; | |
a3f97cbb | 4540 | { |
b3694847 | 4541 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
9eb4015a | 4542 | struct indirect_string_node *node; |
c26fbbca | 4543 | |
9eb4015a JJ |
4544 | if (! debug_str_hash) |
4545 | { | |
4546 | debug_str_hash = ht_create (10); | |
4547 | debug_str_hash->alloc_node = indirect_string_alloc; | |
4548 | } | |
4549 | ||
4550 | node = (struct indirect_string_node *) | |
4551 | ht_lookup (debug_str_hash, (const unsigned char *) str, | |
4552 | strlen (str), HT_ALLOC); | |
4553 | node->refcount++; | |
71dfc51f | 4554 | |
3f76745e JM |
4555 | attr->dw_attr_next = NULL; |
4556 | attr->dw_attr = attr_kind; | |
4557 | attr->dw_attr_val.val_class = dw_val_class_str; | |
9eb4015a | 4558 | attr->dw_attr_val.v.val_str = node; |
3f76745e JM |
4559 | add_dwarf_attr (die, attr); |
4560 | } | |
71dfc51f | 4561 | |
a96c67ec JM |
4562 | static inline const char * |
4563 | AT_string (a) | |
b3694847 | 4564 | dw_attr_ref a; |
a96c67ec JM |
4565 | { |
4566 | if (a && AT_class (a) == dw_val_class_str) | |
9eb4015a JJ |
4567 | return (const char *) HT_STR (&a->dw_attr_val.v.val_str->id); |
4568 | ||
4569 | abort (); | |
4570 | } | |
4571 | ||
4572 | /* Find out whether a string should be output inline in DIE | |
4573 | or out-of-line in .debug_str section. */ | |
4574 | ||
9eb4015a JJ |
4575 | static int |
4576 | AT_string_form (a) | |
4577 | dw_attr_ref a; | |
4578 | { | |
4579 | if (a && AT_class (a) == dw_val_class_str) | |
4580 | { | |
4581 | struct indirect_string_node *node; | |
4582 | unsigned int len; | |
4583 | extern int const_labelno; | |
4584 | char label[32]; | |
4585 | ||
4586 | node = a->dw_attr_val.v.val_str; | |
4587 | if (node->form) | |
4588 | return node->form; | |
4589 | ||
4590 | len = HT_LEN (&node->id) + 1; | |
4591 | ||
2ad9852d RK |
4592 | /* If the string is shorter or equal to the size of the reference, it is |
4593 | always better to put it inline. */ | |
9eb4015a JJ |
4594 | if (len <= DWARF_OFFSET_SIZE || node->refcount == 0) |
4595 | return node->form = DW_FORM_string; | |
4596 | ||
2ad9852d RK |
4597 | /* If we cannot expect the linker to merge strings in .debug_str |
4598 | section, only put it into .debug_str if it is worth even in this | |
4599 | single module. */ | |
4600 | if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0 | |
4601 | && (len - DWARF_OFFSET_SIZE) * node->refcount <= len) | |
4602 | return node->form = DW_FORM_string; | |
9eb4015a JJ |
4603 | |
4604 | ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno); | |
4605 | ++const_labelno; | |
4606 | node->label = xstrdup (label); | |
2ad9852d | 4607 | |
9eb4015a JJ |
4608 | return node->form = DW_FORM_strp; |
4609 | } | |
a96c67ec | 4610 | |
40e8cc95 | 4611 | abort (); |
a96c67ec JM |
4612 | } |
4613 | ||
3f76745e | 4614 | /* Add a DIE reference attribute value to a DIE. */ |
71dfc51f | 4615 | |
3f76745e JM |
4616 | static inline void |
4617 | add_AT_die_ref (die, attr_kind, targ_die) | |
b3694847 SS |
4618 | dw_die_ref die; |
4619 | enum dwarf_attribute attr_kind; | |
4620 | dw_die_ref targ_die; | |
3f76745e | 4621 | { |
b3694847 | 4622 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4623 | |
3f76745e JM |
4624 | attr->dw_attr_next = NULL; |
4625 | attr->dw_attr = attr_kind; | |
4626 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
881c6935 JM |
4627 | attr->dw_attr_val.v.val_die_ref.die = targ_die; |
4628 | attr->dw_attr_val.v.val_die_ref.external = 0; | |
3f76745e JM |
4629 | add_dwarf_attr (die, attr); |
4630 | } | |
b1ccbc24 | 4631 | |
a96c67ec JM |
4632 | static inline dw_die_ref |
4633 | AT_ref (a) | |
b3694847 | 4634 | dw_attr_ref a; |
a96c67ec JM |
4635 | { |
4636 | if (a && AT_class (a) == dw_val_class_die_ref) | |
881c6935 | 4637 | return a->dw_attr_val.v.val_die_ref.die; |
a96c67ec | 4638 | |
40e8cc95 | 4639 | abort (); |
a96c67ec JM |
4640 | } |
4641 | ||
881c6935 JM |
4642 | static inline int |
4643 | AT_ref_external (a) | |
b3694847 | 4644 | dw_attr_ref a; |
881c6935 JM |
4645 | { |
4646 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4647 | return a->dw_attr_val.v.val_die_ref.external; | |
4648 | ||
4649 | return 0; | |
4650 | } | |
4651 | ||
881c6935 JM |
4652 | static inline void |
4653 | set_AT_ref_external (a, i) | |
b3694847 | 4654 | dw_attr_ref a; |
881c6935 JM |
4655 | int i; |
4656 | { | |
4657 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4658 | a->dw_attr_val.v.val_die_ref.external = i; | |
4659 | else | |
4660 | abort (); | |
4661 | } | |
4662 | ||
3f76745e | 4663 | /* Add an FDE reference attribute value to a DIE. */ |
b1ccbc24 | 4664 | |
3f76745e JM |
4665 | static inline void |
4666 | add_AT_fde_ref (die, attr_kind, targ_fde) | |
b3694847 SS |
4667 | dw_die_ref die; |
4668 | enum dwarf_attribute attr_kind; | |
4669 | unsigned targ_fde; | |
3f76745e | 4670 | { |
b3694847 | 4671 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
b1ccbc24 | 4672 | |
3f76745e JM |
4673 | attr->dw_attr_next = NULL; |
4674 | attr->dw_attr = attr_kind; | |
4675 | attr->dw_attr_val.val_class = dw_val_class_fde_ref; | |
4676 | attr->dw_attr_val.v.val_fde_index = targ_fde; | |
4677 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4678 | } |
71dfc51f | 4679 | |
3f76745e | 4680 | /* Add a location description attribute value to a DIE. */ |
71dfc51f | 4681 | |
3f76745e JM |
4682 | static inline void |
4683 | add_AT_loc (die, attr_kind, loc) | |
b3694847 SS |
4684 | dw_die_ref die; |
4685 | enum dwarf_attribute attr_kind; | |
4686 | dw_loc_descr_ref loc; | |
3f76745e | 4687 | { |
b3694847 | 4688 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4689 | |
3f76745e JM |
4690 | attr->dw_attr_next = NULL; |
4691 | attr->dw_attr = attr_kind; | |
4692 | attr->dw_attr_val.val_class = dw_val_class_loc; | |
4693 | attr->dw_attr_val.v.val_loc = loc; | |
4694 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4695 | } |
4696 | ||
a96c67ec JM |
4697 | static inline dw_loc_descr_ref |
4698 | AT_loc (a) | |
b3694847 | 4699 | dw_attr_ref a; |
a96c67ec JM |
4700 | { |
4701 | if (a && AT_class (a) == dw_val_class_loc) | |
4702 | return a->dw_attr_val.v.val_loc; | |
4703 | ||
40e8cc95 | 4704 | abort (); |
a96c67ec JM |
4705 | } |
4706 | ||
63e46568 DB |
4707 | static inline void |
4708 | add_AT_loc_list (die, attr_kind, loc_list) | |
b3694847 SS |
4709 | dw_die_ref die; |
4710 | enum dwarf_attribute attr_kind; | |
4711 | dw_loc_list_ref loc_list; | |
63e46568 | 4712 | { |
b3694847 | 4713 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
63e46568 DB |
4714 | |
4715 | attr->dw_attr_next = NULL; | |
4716 | attr->dw_attr = attr_kind; | |
4717 | attr->dw_attr_val.val_class = dw_val_class_loc_list; | |
4718 | attr->dw_attr_val.v.val_loc_list = loc_list; | |
4719 | add_dwarf_attr (die, attr); | |
4720 | have_location_lists = 1; | |
4721 | } | |
4722 | ||
63e46568 DB |
4723 | static inline dw_loc_list_ref |
4724 | AT_loc_list (a) | |
b3694847 | 4725 | dw_attr_ref a; |
63e46568 DB |
4726 | { |
4727 | if (a && AT_class (a) == dw_val_class_loc_list) | |
4728 | return a->dw_attr_val.v.val_loc_list; | |
4729 | ||
4730 | abort (); | |
4731 | } | |
4732 | ||
3f76745e | 4733 | /* Add an address constant attribute value to a DIE. */ |
71dfc51f | 4734 | |
3f76745e JM |
4735 | static inline void |
4736 | add_AT_addr (die, attr_kind, addr) | |
b3694847 SS |
4737 | dw_die_ref die; |
4738 | enum dwarf_attribute attr_kind; | |
1865dbb5 | 4739 | rtx addr; |
a3f97cbb | 4740 | { |
b3694847 | 4741 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4742 | |
3f76745e JM |
4743 | attr->dw_attr_next = NULL; |
4744 | attr->dw_attr = attr_kind; | |
4745 | attr->dw_attr_val.val_class = dw_val_class_addr; | |
4746 | attr->dw_attr_val.v.val_addr = addr; | |
4747 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4748 | } |
4749 | ||
1865dbb5 | 4750 | static inline rtx |
a96c67ec | 4751 | AT_addr (a) |
b3694847 | 4752 | dw_attr_ref a; |
a96c67ec JM |
4753 | { |
4754 | if (a && AT_class (a) == dw_val_class_addr) | |
4755 | return a->dw_attr_val.v.val_addr; | |
4756 | ||
40e8cc95 | 4757 | abort (); |
a96c67ec JM |
4758 | } |
4759 | ||
3f76745e | 4760 | /* Add a label identifier attribute value to a DIE. */ |
71dfc51f | 4761 | |
3f76745e JM |
4762 | static inline void |
4763 | add_AT_lbl_id (die, attr_kind, lbl_id) | |
b3694847 SS |
4764 | dw_die_ref die; |
4765 | enum dwarf_attribute attr_kind; | |
4766 | const char *lbl_id; | |
a3f97cbb | 4767 | { |
b3694847 | 4768 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4769 | |
3f76745e JM |
4770 | attr->dw_attr_next = NULL; |
4771 | attr->dw_attr = attr_kind; | |
4772 | attr->dw_attr_val.val_class = dw_val_class_lbl_id; | |
4773 | attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); | |
4774 | add_dwarf_attr (die, attr); | |
4775 | } | |
71dfc51f | 4776 | |
3f76745e JM |
4777 | /* Add a section offset attribute value to a DIE. */ |
4778 | ||
4779 | static inline void | |
8b790721 | 4780 | add_AT_lbl_offset (die, attr_kind, label) |
b3694847 SS |
4781 | dw_die_ref die; |
4782 | enum dwarf_attribute attr_kind; | |
4783 | const char *label; | |
3f76745e | 4784 | { |
b3694847 | 4785 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4786 | |
3f76745e JM |
4787 | attr->dw_attr_next = NULL; |
4788 | attr->dw_attr = attr_kind; | |
8b790721 | 4789 | attr->dw_attr_val.val_class = dw_val_class_lbl_offset; |
a96c67ec | 4790 | attr->dw_attr_val.v.val_lbl_id = xstrdup (label); |
3f76745e | 4791 | add_dwarf_attr (die, attr); |
a3f97cbb JW |
4792 | } |
4793 | ||
a20612aa RH |
4794 | /* Add an offset attribute value to a DIE. */ |
4795 | ||
2bee6045 | 4796 | static inline void |
a20612aa | 4797 | add_AT_offset (die, attr_kind, offset) |
b3694847 SS |
4798 | dw_die_ref die; |
4799 | enum dwarf_attribute attr_kind; | |
4800 | unsigned long offset; | |
a20612aa | 4801 | { |
b3694847 | 4802 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
a20612aa RH |
4803 | |
4804 | attr->dw_attr_next = NULL; | |
4805 | attr->dw_attr = attr_kind; | |
4806 | attr->dw_attr_val.val_class = dw_val_class_offset; | |
4807 | attr->dw_attr_val.v.val_offset = offset; | |
4808 | add_dwarf_attr (die, attr); | |
4809 | } | |
4810 | ||
2bee6045 JJ |
4811 | /* Add an range_list attribute value to a DIE. */ |
4812 | ||
4813 | static void | |
4814 | add_AT_range_list (die, attr_kind, offset) | |
4815 | dw_die_ref die; | |
4816 | enum dwarf_attribute attr_kind; | |
4817 | unsigned long offset; | |
4818 | { | |
4819 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
4820 | ||
4821 | attr->dw_attr_next = NULL; | |
4822 | attr->dw_attr = attr_kind; | |
4823 | attr->dw_attr_val.val_class = dw_val_class_range_list; | |
4824 | attr->dw_attr_val.v.val_offset = offset; | |
4825 | add_dwarf_attr (die, attr); | |
4826 | } | |
4827 | ||
a96c67ec JM |
4828 | static inline const char * |
4829 | AT_lbl (a) | |
b3694847 | 4830 | dw_attr_ref a; |
a3f97cbb | 4831 | { |
a96c67ec JM |
4832 | if (a && (AT_class (a) == dw_val_class_lbl_id |
4833 | || AT_class (a) == dw_val_class_lbl_offset)) | |
4834 | return a->dw_attr_val.v.val_lbl_id; | |
71dfc51f | 4835 | |
40e8cc95 | 4836 | abort (); |
a3f97cbb JW |
4837 | } |
4838 | ||
3f76745e | 4839 | /* Get the attribute of type attr_kind. */ |
71dfc51f | 4840 | |
3f76745e JM |
4841 | static inline dw_attr_ref |
4842 | get_AT (die, attr_kind) | |
b3694847 SS |
4843 | dw_die_ref die; |
4844 | enum dwarf_attribute attr_kind; | |
f37230f0 | 4845 | { |
b3694847 SS |
4846 | dw_attr_ref a; |
4847 | dw_die_ref spec = NULL; | |
556273e0 | 4848 | |
3f76745e JM |
4849 | if (die != NULL) |
4850 | { | |
4851 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
2ad9852d RK |
4852 | if (a->dw_attr == attr_kind) |
4853 | return a; | |
4854 | else if (a->dw_attr == DW_AT_specification | |
4855 | || a->dw_attr == DW_AT_abstract_origin) | |
4856 | spec = AT_ref (a); | |
71dfc51f | 4857 | |
3f76745e JM |
4858 | if (spec) |
4859 | return get_AT (spec, attr_kind); | |
4860 | } | |
4861 | ||
4862 | return NULL; | |
f37230f0 JM |
4863 | } |
4864 | ||
2ad9852d RK |
4865 | /* Return the "low pc" attribute value, typically associated with a subprogram |
4866 | DIE. Return null if the "low pc" attribute is either not present, or if it | |
4867 | cannot be represented as an assembler label identifier. */ | |
71dfc51f | 4868 | |
a96c67ec | 4869 | static inline const char * |
3f76745e | 4870 | get_AT_low_pc (die) |
b3694847 | 4871 | dw_die_ref die; |
7e23cb16 | 4872 | { |
b3694847 | 4873 | dw_attr_ref a = get_AT (die, DW_AT_low_pc); |
2ad9852d | 4874 | |
40e8cc95 | 4875 | return a ? AT_lbl (a) : NULL; |
7e23cb16 JM |
4876 | } |
4877 | ||
2ad9852d RK |
4878 | /* Return the "high pc" attribute value, typically associated with a subprogram |
4879 | DIE. Return null if the "high pc" attribute is either not present, or if it | |
4880 | cannot be represented as an assembler label identifier. */ | |
71dfc51f | 4881 | |
a96c67ec | 4882 | static inline const char * |
3f76745e | 4883 | get_AT_hi_pc (die) |
b3694847 | 4884 | dw_die_ref die; |
a3f97cbb | 4885 | { |
b3694847 | 4886 | dw_attr_ref a = get_AT (die, DW_AT_high_pc); |
2ad9852d | 4887 | |
40e8cc95 | 4888 | return a ? AT_lbl (a) : NULL; |
3f76745e JM |
4889 | } |
4890 | ||
4891 | /* Return the value of the string attribute designated by ATTR_KIND, or | |
4892 | NULL if it is not present. */ | |
71dfc51f | 4893 | |
a96c67ec | 4894 | static inline const char * |
3f76745e | 4895 | get_AT_string (die, attr_kind) |
b3694847 SS |
4896 | dw_die_ref die; |
4897 | enum dwarf_attribute attr_kind; | |
3f76745e | 4898 | { |
b3694847 | 4899 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4900 | |
40e8cc95 | 4901 | return a ? AT_string (a) : NULL; |
a3f97cbb JW |
4902 | } |
4903 | ||
3f76745e JM |
4904 | /* Return the value of the flag attribute designated by ATTR_KIND, or -1 |
4905 | if it is not present. */ | |
71dfc51f | 4906 | |
3f76745e JM |
4907 | static inline int |
4908 | get_AT_flag (die, attr_kind) | |
b3694847 SS |
4909 | dw_die_ref die; |
4910 | enum dwarf_attribute attr_kind; | |
a3f97cbb | 4911 | { |
b3694847 | 4912 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4913 | |
40e8cc95 | 4914 | return a ? AT_flag (a) : 0; |
a3f97cbb JW |
4915 | } |
4916 | ||
3f76745e JM |
4917 | /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0 |
4918 | if it is not present. */ | |
71dfc51f | 4919 | |
3f76745e JM |
4920 | static inline unsigned |
4921 | get_AT_unsigned (die, attr_kind) | |
b3694847 SS |
4922 | dw_die_ref die; |
4923 | enum dwarf_attribute attr_kind; | |
a3f97cbb | 4924 | { |
b3694847 | 4925 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4926 | |
40e8cc95 | 4927 | return a ? AT_unsigned (a) : 0; |
a96c67ec | 4928 | } |
71dfc51f | 4929 | |
a96c67ec JM |
4930 | static inline dw_die_ref |
4931 | get_AT_ref (die, attr_kind) | |
4932 | dw_die_ref die; | |
b3694847 | 4933 | enum dwarf_attribute attr_kind; |
a96c67ec | 4934 | { |
b3694847 | 4935 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4936 | |
40e8cc95 | 4937 | return a ? AT_ref (a) : NULL; |
3f76745e | 4938 | } |
71dfc51f | 4939 | |
3f76745e JM |
4940 | static inline int |
4941 | is_c_family () | |
4942 | { | |
b3694847 | 4943 | unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
71dfc51f | 4944 | |
3f76745e JM |
4945 | return (lang == DW_LANG_C || lang == DW_LANG_C89 |
4946 | || lang == DW_LANG_C_plus_plus); | |
556273e0 | 4947 | } |
71dfc51f | 4948 | |
1d3d6b1e JM |
4949 | static inline int |
4950 | is_cxx () | |
4951 | { | |
4952 | return (get_AT_unsigned (comp_unit_die, DW_AT_language) | |
4953 | == DW_LANG_C_plus_plus); | |
c26fbbca | 4954 | } |
1d3d6b1e | 4955 | |
3f76745e JM |
4956 | static inline int |
4957 | is_fortran () | |
4958 | { | |
b3694847 | 4959 | unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
71dfc51f | 4960 | |
3f76745e | 4961 | return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90); |
556273e0 | 4962 | } |
71dfc51f | 4963 | |
28985b81 AG |
4964 | static inline int |
4965 | is_java () | |
4966 | { | |
b3694847 | 4967 | unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
28985b81 AG |
4968 | |
4969 | return (lang == DW_LANG_Java); | |
4970 | } | |
4971 | ||
10a11b75 | 4972 | /* Free up the memory used by A. */ |
71dfc51f | 4973 | |
c6991660 | 4974 | static inline void free_AT PARAMS ((dw_attr_ref)); |
3f76745e | 4975 | static inline void |
10a11b75 JM |
4976 | free_AT (a) |
4977 | dw_attr_ref a; | |
4978 | { | |
4979 | switch (AT_class (a)) | |
4980 | { | |
10a11b75 | 4981 | case dw_val_class_str: |
9eb4015a JJ |
4982 | if (a->dw_attr_val.v.val_str->refcount) |
4983 | a->dw_attr_val.v.val_str->refcount--; | |
4984 | break; | |
4985 | ||
10a11b75 JM |
4986 | case dw_val_class_lbl_id: |
4987 | case dw_val_class_lbl_offset: | |
9eb4015a | 4988 | free (a->dw_attr_val.v.val_lbl_id); |
10a11b75 JM |
4989 | break; |
4990 | ||
3724ec07 WC |
4991 | case dw_val_class_float: |
4992 | free (a->dw_attr_val.v.val_float.array); | |
4993 | break; | |
0b34cf1e | 4994 | |
10a11b75 JM |
4995 | default: |
4996 | break; | |
4997 | } | |
4998 | ||
4999 | free (a); | |
556273e0 | 5000 | } |
10a11b75 JM |
5001 | |
5002 | /* Remove the specified attribute if present. */ | |
5003 | ||
5004 | static void | |
3f76745e | 5005 | remove_AT (die, attr_kind) |
b3694847 SS |
5006 | dw_die_ref die; |
5007 | enum dwarf_attribute attr_kind; | |
3f76745e | 5008 | { |
b3694847 SS |
5009 | dw_attr_ref *p; |
5010 | dw_attr_ref removed = NULL; | |
a3f97cbb | 5011 | |
3f76745e JM |
5012 | if (die != NULL) |
5013 | { | |
a96c67ec JM |
5014 | for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next)) |
5015 | if ((*p)->dw_attr == attr_kind) | |
5016 | { | |
5017 | removed = *p; | |
5018 | *p = (*p)->dw_attr_next; | |
5019 | break; | |
5020 | } | |
71dfc51f | 5021 | |
a96c67ec | 5022 | if (removed != 0) |
10a11b75 JM |
5023 | free_AT (removed); |
5024 | } | |
5025 | } | |
71dfc51f | 5026 | |
10a11b75 | 5027 | /* Free up the memory used by DIE. */ |
71dfc51f | 5028 | |
10a11b75 JM |
5029 | static inline void |
5030 | free_die (die) | |
5031 | dw_die_ref die; | |
5032 | { | |
5033 | remove_children (die); | |
5034 | free (die); | |
3f76745e | 5035 | } |
71dfc51f | 5036 | |
3f76745e | 5037 | /* Discard the children of this DIE. */ |
71dfc51f | 5038 | |
10a11b75 | 5039 | static void |
3f76745e | 5040 | remove_children (die) |
b3694847 | 5041 | dw_die_ref die; |
3f76745e | 5042 | { |
b3694847 | 5043 | dw_die_ref child_die = die->die_child; |
3f76745e JM |
5044 | |
5045 | die->die_child = NULL; | |
3f76745e JM |
5046 | |
5047 | while (child_die != NULL) | |
a3f97cbb | 5048 | { |
b3694847 SS |
5049 | dw_die_ref tmp_die = child_die; |
5050 | dw_attr_ref a; | |
71dfc51f | 5051 | |
3f76745e | 5052 | child_die = child_die->die_sib; |
556273e0 KH |
5053 | |
5054 | for (a = tmp_die->die_attr; a != NULL;) | |
a3f97cbb | 5055 | { |
b3694847 | 5056 | dw_attr_ref tmp_a = a; |
71dfc51f | 5057 | |
3f76745e | 5058 | a = a->dw_attr_next; |
10a11b75 | 5059 | free_AT (tmp_a); |
a3f97cbb | 5060 | } |
71dfc51f | 5061 | |
10a11b75 | 5062 | free_die (tmp_die); |
3f76745e JM |
5063 | } |
5064 | } | |
71dfc51f | 5065 | |
a96c67ec | 5066 | /* Add a child DIE below its parent. We build the lists up in reverse |
881c6935 | 5067 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f | 5068 | |
3f76745e JM |
5069 | static inline void |
5070 | add_child_die (die, child_die) | |
b3694847 SS |
5071 | dw_die_ref die; |
5072 | dw_die_ref child_die; | |
3f76745e JM |
5073 | { |
5074 | if (die != NULL && child_die != NULL) | |
e90b62db | 5075 | { |
3a88cbd1 JL |
5076 | if (die == child_die) |
5077 | abort (); | |
2ad9852d | 5078 | |
3f76745e | 5079 | child_die->die_parent = die; |
a96c67ec JM |
5080 | child_die->die_sib = die->die_child; |
5081 | die->die_child = child_die; | |
3f76745e JM |
5082 | } |
5083 | } | |
5084 | ||
2081603c JM |
5085 | /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT |
5086 | is the specification, to the front of PARENT's list of children. */ | |
10a11b75 JM |
5087 | |
5088 | static void | |
5089 | splice_child_die (parent, child) | |
5090 | dw_die_ref parent, child; | |
5091 | { | |
5092 | dw_die_ref *p; | |
5093 | ||
5094 | /* We want the declaration DIE from inside the class, not the | |
5095 | specification DIE at toplevel. */ | |
5096 | if (child->die_parent != parent) | |
2081603c JM |
5097 | { |
5098 | dw_die_ref tmp = get_AT_ref (child, DW_AT_specification); | |
2ad9852d | 5099 | |
2081603c JM |
5100 | if (tmp) |
5101 | child = tmp; | |
5102 | } | |
10a11b75 | 5103 | |
2081603c JM |
5104 | if (child->die_parent != parent |
5105 | && child->die_parent != get_AT_ref (parent, DW_AT_specification)) | |
10a11b75 JM |
5106 | abort (); |
5107 | ||
5de0e8d4 | 5108 | for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib)) |
10a11b75 JM |
5109 | if (*p == child) |
5110 | { | |
5111 | *p = child->die_sib; | |
5112 | break; | |
5113 | } | |
5114 | ||
5115 | child->die_sib = parent->die_child; | |
5116 | parent->die_child = child; | |
5117 | } | |
5118 | ||
3f76745e JM |
5119 | /* Return a pointer to a newly created DIE node. */ |
5120 | ||
5121 | static inline dw_die_ref | |
54ba1f0d | 5122 | new_die (tag_value, parent_die, t) |
b3694847 SS |
5123 | enum dwarf_tag tag_value; |
5124 | dw_die_ref parent_die; | |
54ba1f0d | 5125 | tree t; |
3f76745e | 5126 | { |
b3694847 | 5127 | dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node)); |
3f76745e JM |
5128 | |
5129 | die->die_tag = tag_value; | |
3f76745e JM |
5130 | |
5131 | if (parent_die != NULL) | |
5132 | add_child_die (parent_die, die); | |
5133 | else | |
ef76d03b JW |
5134 | { |
5135 | limbo_die_node *limbo_node; | |
5136 | ||
5137 | limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node)); | |
5138 | limbo_node->die = die; | |
54ba1f0d | 5139 | limbo_node->created_for = t; |
ef76d03b JW |
5140 | limbo_node->next = limbo_die_list; |
5141 | limbo_die_list = limbo_node; | |
5142 | } | |
71dfc51f | 5143 | |
3f76745e JM |
5144 | return die; |
5145 | } | |
71dfc51f | 5146 | |
3f76745e | 5147 | /* Return the DIE associated with the given type specifier. */ |
71dfc51f | 5148 | |
3f76745e JM |
5149 | static inline dw_die_ref |
5150 | lookup_type_die (type) | |
b3694847 | 5151 | tree type; |
3f76745e | 5152 | { |
e2500fed | 5153 | return TYPE_SYMTAB_DIE (type); |
3f76745e | 5154 | } |
e90b62db | 5155 | |
3f76745e | 5156 | /* Equate a DIE to a given type specifier. */ |
71dfc51f | 5157 | |
10a11b75 | 5158 | static inline void |
3f76745e | 5159 | equate_type_number_to_die (type, type_die) |
b3694847 SS |
5160 | tree type; |
5161 | dw_die_ref type_die; | |
3f76745e | 5162 | { |
e2500fed | 5163 | TYPE_SYMTAB_DIE (type) = type_die; |
3f76745e | 5164 | } |
71dfc51f | 5165 | |
3f76745e | 5166 | /* Return the DIE associated with a given declaration. */ |
71dfc51f | 5167 | |
3f76745e JM |
5168 | static inline dw_die_ref |
5169 | lookup_decl_die (decl) | |
b3694847 | 5170 | tree decl; |
3f76745e | 5171 | { |
b3694847 | 5172 | unsigned decl_id = DECL_UID (decl); |
3f76745e | 5173 | |
2ad9852d | 5174 | return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL); |
a3f97cbb JW |
5175 | } |
5176 | ||
3f76745e | 5177 | /* Equate a DIE to a particular declaration. */ |
71dfc51f | 5178 | |
3f76745e JM |
5179 | static void |
5180 | equate_decl_number_to_die (decl, decl_die) | |
b3694847 SS |
5181 | tree decl; |
5182 | dw_die_ref decl_die; | |
a3f97cbb | 5183 | { |
aea9695c RK |
5184 | unsigned int decl_id = DECL_UID (decl); |
5185 | unsigned int num_allocated; | |
d291dd49 | 5186 | |
3f76745e | 5187 | if (decl_id >= decl_die_table_allocated) |
a3f97cbb | 5188 | { |
3f76745e JM |
5189 | num_allocated |
5190 | = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1) | |
5191 | / DECL_DIE_TABLE_INCREMENT) | |
5192 | * DECL_DIE_TABLE_INCREMENT; | |
5193 | ||
5194 | decl_die_table | |
5195 | = (dw_die_ref *) xrealloc (decl_die_table, | |
5196 | sizeof (dw_die_ref) * num_allocated); | |
5197 | ||
961192e1 | 5198 | memset ((char *) &decl_die_table[decl_die_table_allocated], 0, |
3f76745e JM |
5199 | (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref)); |
5200 | decl_die_table_allocated = num_allocated; | |
a3f97cbb | 5201 | } |
71dfc51f | 5202 | |
3f76745e JM |
5203 | if (decl_id >= decl_die_table_in_use) |
5204 | decl_die_table_in_use = (decl_id + 1); | |
5205 | ||
5206 | decl_die_table[decl_id] = decl_die; | |
a3f97cbb | 5207 | } |
3f76745e JM |
5208 | \f |
5209 | /* Keep track of the number of spaces used to indent the | |
5210 | output of the debugging routines that print the structure of | |
5211 | the DIE internal representation. */ | |
5212 | static int print_indent; | |
71dfc51f | 5213 | |
3f76745e JM |
5214 | /* Indent the line the number of spaces given by print_indent. */ |
5215 | ||
5216 | static inline void | |
5217 | print_spaces (outfile) | |
5218 | FILE *outfile; | |
5219 | { | |
5220 | fprintf (outfile, "%*s", print_indent, ""); | |
a3f97cbb JW |
5221 | } |
5222 | ||
956d6950 | 5223 | /* Print the information associated with a given DIE, and its children. |
3f76745e | 5224 | This routine is a debugging aid only. */ |
71dfc51f | 5225 | |
a3f97cbb | 5226 | static void |
3f76745e JM |
5227 | print_die (die, outfile) |
5228 | dw_die_ref die; | |
5229 | FILE *outfile; | |
a3f97cbb | 5230 | { |
b3694847 SS |
5231 | dw_attr_ref a; |
5232 | dw_die_ref c; | |
71dfc51f | 5233 | |
3f76745e | 5234 | print_spaces (outfile); |
2d8b0f3a | 5235 | fprintf (outfile, "DIE %4lu: %s\n", |
3f76745e JM |
5236 | die->die_offset, dwarf_tag_name (die->die_tag)); |
5237 | print_spaces (outfile); | |
2d8b0f3a JL |
5238 | fprintf (outfile, " abbrev id: %lu", die->die_abbrev); |
5239 | fprintf (outfile, " offset: %lu\n", die->die_offset); | |
3f76745e JM |
5240 | |
5241 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
a3f97cbb | 5242 | { |
3f76745e JM |
5243 | print_spaces (outfile); |
5244 | fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr)); | |
5245 | ||
a96c67ec | 5246 | switch (AT_class (a)) |
3f76745e JM |
5247 | { |
5248 | case dw_val_class_addr: | |
5249 | fprintf (outfile, "address"); | |
5250 | break; | |
a20612aa RH |
5251 | case dw_val_class_offset: |
5252 | fprintf (outfile, "offset"); | |
5253 | break; | |
3f76745e JM |
5254 | case dw_val_class_loc: |
5255 | fprintf (outfile, "location descriptor"); | |
5256 | break; | |
63e46568 | 5257 | case dw_val_class_loc_list: |
a20612aa RH |
5258 | fprintf (outfile, "location list -> label:%s", |
5259 | AT_loc_list (a)->ll_symbol); | |
63e46568 | 5260 | break; |
2bee6045 JJ |
5261 | case dw_val_class_range_list: |
5262 | fprintf (outfile, "range list"); | |
5263 | break; | |
3f76745e | 5264 | case dw_val_class_const: |
a96c67ec | 5265 | fprintf (outfile, "%ld", AT_int (a)); |
3f76745e JM |
5266 | break; |
5267 | case dw_val_class_unsigned_const: | |
a96c67ec | 5268 | fprintf (outfile, "%lu", AT_unsigned (a)); |
3f76745e JM |
5269 | break; |
5270 | case dw_val_class_long_long: | |
2d8b0f3a | 5271 | fprintf (outfile, "constant (%lu,%lu)", |
556273e0 KH |
5272 | a->dw_attr_val.v.val_long_long.hi, |
5273 | a->dw_attr_val.v.val_long_long.low); | |
3f76745e JM |
5274 | break; |
5275 | case dw_val_class_float: | |
5276 | fprintf (outfile, "floating-point constant"); | |
5277 | break; | |
5278 | case dw_val_class_flag: | |
a96c67ec | 5279 | fprintf (outfile, "%u", AT_flag (a)); |
3f76745e JM |
5280 | break; |
5281 | case dw_val_class_die_ref: | |
a96c67ec | 5282 | if (AT_ref (a) != NULL) |
881c6935 | 5283 | { |
1bfb5f8f | 5284 | if (AT_ref (a)->die_symbol) |
881c6935 JM |
5285 | fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol); |
5286 | else | |
5287 | fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset); | |
5288 | } | |
3f76745e JM |
5289 | else |
5290 | fprintf (outfile, "die -> <null>"); | |
5291 | break; | |
5292 | case dw_val_class_lbl_id: | |
8b790721 | 5293 | case dw_val_class_lbl_offset: |
a96c67ec | 5294 | fprintf (outfile, "label: %s", AT_lbl (a)); |
3f76745e | 5295 | break; |
3f76745e | 5296 | case dw_val_class_str: |
a96c67ec JM |
5297 | if (AT_string (a) != NULL) |
5298 | fprintf (outfile, "\"%s\"", AT_string (a)); | |
3f76745e JM |
5299 | else |
5300 | fprintf (outfile, "<null>"); | |
5301 | break; | |
e9a25f70 JL |
5302 | default: |
5303 | break; | |
3f76745e JM |
5304 | } |
5305 | ||
5306 | fprintf (outfile, "\n"); | |
5307 | } | |
5308 | ||
5309 | if (die->die_child != NULL) | |
5310 | { | |
5311 | print_indent += 4; | |
5312 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5313 | print_die (c, outfile); | |
71dfc51f | 5314 | |
3f76745e | 5315 | print_indent -= 4; |
a3f97cbb | 5316 | } |
881c6935 JM |
5317 | if (print_indent == 0) |
5318 | fprintf (outfile, "\n"); | |
a3f97cbb JW |
5319 | } |
5320 | ||
3f76745e JM |
5321 | /* Print the contents of the source code line number correspondence table. |
5322 | This routine is a debugging aid only. */ | |
71dfc51f | 5323 | |
3f76745e JM |
5324 | static void |
5325 | print_dwarf_line_table (outfile) | |
5326 | FILE *outfile; | |
a3f97cbb | 5327 | { |
b3694847 SS |
5328 | unsigned i; |
5329 | dw_line_info_ref line_info; | |
3f76745e JM |
5330 | |
5331 | fprintf (outfile, "\n\nDWARF source line information\n"); | |
2ad9852d | 5332 | for (i = 1; i < line_info_table_in_use; i++) |
a3f97cbb | 5333 | { |
3f76745e JM |
5334 | line_info = &line_info_table[i]; |
5335 | fprintf (outfile, "%5d: ", i); | |
981975b6 | 5336 | fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]); |
2d8b0f3a | 5337 | fprintf (outfile, "%6ld", line_info->dw_line_num); |
3f76745e | 5338 | fprintf (outfile, "\n"); |
a3f97cbb | 5339 | } |
3f76745e JM |
5340 | |
5341 | fprintf (outfile, "\n\n"); | |
f37230f0 JM |
5342 | } |
5343 | ||
3f76745e JM |
5344 | /* Print the information collected for a given DIE. */ |
5345 | ||
5346 | void | |
5347 | debug_dwarf_die (die) | |
5348 | dw_die_ref die; | |
5349 | { | |
5350 | print_die (die, stderr); | |
5351 | } | |
5352 | ||
5353 | /* Print all DWARF information collected for the compilation unit. | |
5354 | This routine is a debugging aid only. */ | |
5355 | ||
5356 | void | |
5357 | debug_dwarf () | |
5358 | { | |
5359 | print_indent = 0; | |
5360 | print_die (comp_unit_die, stderr); | |
b2244e22 JW |
5361 | if (! DWARF2_ASM_LINE_DEBUG_INFO) |
5362 | print_dwarf_line_table (stderr); | |
3f76745e JM |
5363 | } |
5364 | \f | |
a96c67ec JM |
5365 | /* We build up the lists of children and attributes by pushing new ones |
5366 | onto the beginning of the list. Reverse the lists for DIE so that | |
5367 | they are in order of addition. */ | |
71dfc51f | 5368 | |
f37230f0 | 5369 | static void |
a96c67ec | 5370 | reverse_die_lists (die) |
b3694847 | 5371 | dw_die_ref die; |
f37230f0 | 5372 | { |
b3694847 SS |
5373 | dw_die_ref c, cp, cn; |
5374 | dw_attr_ref a, ap, an; | |
71dfc51f | 5375 | |
a96c67ec | 5376 | for (a = die->die_attr, ap = 0; a; a = an) |
7d9d8943 AM |
5377 | { |
5378 | an = a->dw_attr_next; | |
5379 | a->dw_attr_next = ap; | |
5380 | ap = a; | |
a3f97cbb | 5381 | } |
2ad9852d | 5382 | |
7d9d8943 | 5383 | die->die_attr = ap; |
3f76745e | 5384 | |
7d9d8943 AM |
5385 | for (c = die->die_child, cp = 0; c; c = cn) |
5386 | { | |
5387 | cn = c->die_sib; | |
5388 | c->die_sib = cp; | |
5389 | cp = c; | |
5390 | } | |
2ad9852d | 5391 | |
7d9d8943 | 5392 | die->die_child = cp; |
a3f97cbb JW |
5393 | } |
5394 | ||
2ad9852d RK |
5395 | /* reverse_die_lists only reverses the single die you pass it. Since we used to |
5396 | reverse all dies in add_sibling_attributes, which runs through all the dies, | |
5397 | it would reverse all the dies. Now, however, since we don't call | |
5398 | reverse_die_lists in add_sibling_attributes, we need a routine to | |
5399 | recursively reverse all the dies. This is that routine. */ | |
71dfc51f | 5400 | |
7d9d8943 | 5401 | static void |
881c6935 | 5402 | reverse_all_dies (die) |
b3694847 | 5403 | dw_die_ref die; |
a3f97cbb | 5404 | { |
b3694847 | 5405 | dw_die_ref c; |
71dfc51f | 5406 | |
7d9d8943 | 5407 | reverse_die_lists (die); |
3f76745e | 5408 | |
881c6935 JM |
5409 | for (c = die->die_child; c; c = c->die_sib) |
5410 | reverse_all_dies (c); | |
5411 | } | |
5412 | ||
2ad9852d RK |
5413 | /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU |
5414 | for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL | |
5415 | DIE that marks the start of the DIEs for this include file. */ | |
881c6935 JM |
5416 | |
5417 | static dw_die_ref | |
5418 | push_new_compile_unit (old_unit, bincl_die) | |
5419 | dw_die_ref old_unit, bincl_die; | |
5420 | { | |
5421 | const char *filename = get_AT_string (bincl_die, DW_AT_name); | |
5422 | dw_die_ref new_unit = gen_compile_unit_die (filename); | |
2ad9852d | 5423 | |
881c6935 JM |
5424 | new_unit->die_sib = old_unit; |
5425 | return new_unit; | |
5426 | } | |
5427 | ||
5428 | /* Close an include-file CU and reopen the enclosing one. */ | |
5429 | ||
5430 | static dw_die_ref | |
5431 | pop_compile_unit (old_unit) | |
5432 | dw_die_ref old_unit; | |
5433 | { | |
5434 | dw_die_ref new_unit = old_unit->die_sib; | |
2ad9852d | 5435 | |
881c6935 JM |
5436 | old_unit->die_sib = NULL; |
5437 | return new_unit; | |
5438 | } | |
5439 | ||
2ad9852d RK |
5440 | #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx) |
5441 | #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx) | |
881c6935 JM |
5442 | |
5443 | /* Calculate the checksum of a location expression. */ | |
5444 | ||
5445 | static inline void | |
5446 | loc_checksum (loc, ctx) | |
5447 | dw_loc_descr_ref loc; | |
5448 | struct md5_ctx *ctx; | |
5449 | { | |
2ad9852d RK |
5450 | CHECKSUM (loc->dw_loc_opc); |
5451 | CHECKSUM (loc->dw_loc_oprnd1); | |
5452 | CHECKSUM (loc->dw_loc_oprnd2); | |
881c6935 JM |
5453 | } |
5454 | ||
5455 | /* Calculate the checksum of an attribute. */ | |
5456 | ||
5457 | static void | |
cc0017a9 | 5458 | attr_checksum (at, ctx, mark) |
881c6935 JM |
5459 | dw_attr_ref at; |
5460 | struct md5_ctx *ctx; | |
cc0017a9 | 5461 | int *mark; |
881c6935 JM |
5462 | { |
5463 | dw_loc_descr_ref loc; | |
5464 | rtx r; | |
5465 | ||
2ad9852d | 5466 | CHECKSUM (at->dw_attr); |
881c6935 JM |
5467 | |
5468 | /* We don't care about differences in file numbering. */ | |
5f632b5e JM |
5469 | if (at->dw_attr == DW_AT_decl_file |
5470 | /* Or that this was compiled with a different compiler snapshot; if | |
5471 | the output is the same, that's what matters. */ | |
5472 | || at->dw_attr == DW_AT_producer) | |
881c6935 JM |
5473 | return; |
5474 | ||
5475 | switch (AT_class (at)) | |
5476 | { | |
5477 | case dw_val_class_const: | |
2ad9852d | 5478 | CHECKSUM (at->dw_attr_val.v.val_int); |
881c6935 JM |
5479 | break; |
5480 | case dw_val_class_unsigned_const: | |
2ad9852d | 5481 | CHECKSUM (at->dw_attr_val.v.val_unsigned); |
881c6935 JM |
5482 | break; |
5483 | case dw_val_class_long_long: | |
2ad9852d | 5484 | CHECKSUM (at->dw_attr_val.v.val_long_long); |
881c6935 JM |
5485 | break; |
5486 | case dw_val_class_float: | |
2ad9852d | 5487 | CHECKSUM (at->dw_attr_val.v.val_float); |
881c6935 JM |
5488 | break; |
5489 | case dw_val_class_flag: | |
2ad9852d | 5490 | CHECKSUM (at->dw_attr_val.v.val_flag); |
881c6935 | 5491 | break; |
881c6935 | 5492 | case dw_val_class_str: |
2ad9852d | 5493 | CHECKSUM_STRING (AT_string (at)); |
881c6935 | 5494 | break; |
a20612aa | 5495 | |
881c6935 JM |
5496 | case dw_val_class_addr: |
5497 | r = AT_addr (at); | |
5498 | switch (GET_CODE (r)) | |
5499 | { | |
5500 | case SYMBOL_REF: | |
2ad9852d | 5501 | CHECKSUM_STRING (XSTR (r, 0)); |
881c6935 JM |
5502 | break; |
5503 | ||
5504 | default: | |
5505 | abort (); | |
5506 | } | |
5507 | break; | |
5508 | ||
a20612aa | 5509 | case dw_val_class_offset: |
2ad9852d | 5510 | CHECKSUM (at->dw_attr_val.v.val_offset); |
a20612aa RH |
5511 | break; |
5512 | ||
881c6935 JM |
5513 | case dw_val_class_loc: |
5514 | for (loc = AT_loc (at); loc; loc = loc->dw_loc_next) | |
5515 | loc_checksum (loc, ctx); | |
5516 | break; | |
5517 | ||
5518 | case dw_val_class_die_ref: | |
cc0017a9 ZD |
5519 | die_checksum (AT_ref (at), ctx, mark); |
5520 | break; | |
881c6935 JM |
5521 | |
5522 | case dw_val_class_fde_ref: | |
5523 | case dw_val_class_lbl_id: | |
5524 | case dw_val_class_lbl_offset: | |
a20612aa | 5525 | break; |
881c6935 JM |
5526 | |
5527 | default: | |
5528 | break; | |
5529 | } | |
5530 | } | |
5531 | ||
5532 | /* Calculate the checksum of a DIE. */ | |
5533 | ||
5534 | static void | |
cc0017a9 | 5535 | die_checksum (die, ctx, mark) |
881c6935 JM |
5536 | dw_die_ref die; |
5537 | struct md5_ctx *ctx; | |
cc0017a9 | 5538 | int *mark; |
881c6935 JM |
5539 | { |
5540 | dw_die_ref c; | |
5541 | dw_attr_ref a; | |
5542 | ||
cc0017a9 ZD |
5543 | /* To avoid infinite recursion. */ |
5544 | if (die->die_mark) | |
5545 | { | |
5546 | CHECKSUM (die->die_mark); | |
5547 | return; | |
5548 | } | |
5549 | die->die_mark = ++(*mark); | |
5550 | ||
2ad9852d | 5551 | CHECKSUM (die->die_tag); |
881c6935 JM |
5552 | |
5553 | for (a = die->die_attr; a; a = a->dw_attr_next) | |
cc0017a9 | 5554 | attr_checksum (a, ctx, mark); |
881c6935 JM |
5555 | |
5556 | for (c = die->die_child; c; c = c->die_sib) | |
cc0017a9 | 5557 | die_checksum (c, ctx, mark); |
881c6935 JM |
5558 | } |
5559 | ||
2ad9852d RK |
5560 | #undef CHECKSUM |
5561 | #undef CHECKSUM_STRING | |
881c6935 | 5562 | |
cc0017a9 ZD |
5563 | /* Do the location expressions look same? */ |
5564 | static inline int | |
5565 | same_loc_p (loc1, loc2, mark) | |
5566 | dw_loc_descr_ref loc1; | |
5567 | dw_loc_descr_ref loc2; | |
5568 | int *mark; | |
5569 | { | |
5570 | return loc1->dw_loc_opc == loc2->dw_loc_opc | |
5571 | && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark) | |
5572 | && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark); | |
5573 | } | |
5574 | ||
5575 | /* Do the values look the same? */ | |
5576 | static int | |
5577 | same_dw_val_p (v1, v2, mark) | |
5578 | dw_val_node *v1; | |
5579 | dw_val_node *v2; | |
5580 | int *mark; | |
5581 | { | |
5582 | dw_loc_descr_ref loc1, loc2; | |
5583 | rtx r1, r2; | |
5584 | unsigned i; | |
5585 | ||
5586 | if (v1->val_class != v2->val_class) | |
5587 | return 0; | |
5588 | ||
5589 | switch (v1->val_class) | |
5590 | { | |
5591 | case dw_val_class_const: | |
5592 | return v1->v.val_int == v2->v.val_int; | |
5593 | case dw_val_class_unsigned_const: | |
5594 | return v1->v.val_unsigned == v2->v.val_unsigned; | |
5595 | case dw_val_class_long_long: | |
5596 | return v1->v.val_long_long.hi == v2->v.val_long_long.hi | |
5597 | && v1->v.val_long_long.low == v2->v.val_long_long.low; | |
5598 | case dw_val_class_float: | |
5599 | if (v1->v.val_float.length != v2->v.val_float.length) | |
5600 | return 0; | |
5601 | for (i = 0; i < v1->v.val_float.length; i++) | |
5602 | if (v1->v.val_float.array[i] != v2->v.val_float.array[i]) | |
5603 | return 0; | |
5604 | return 1; | |
5605 | case dw_val_class_flag: | |
5606 | return v1->v.val_flag == v2->v.val_flag; | |
5607 | case dw_val_class_str: | |
5608 | return !strcmp((const char *) HT_STR (&v1->v.val_str->id), | |
5609 | (const char *) HT_STR (&v2->v.val_str->id)); | |
5610 | ||
5611 | case dw_val_class_addr: | |
5612 | r1 = v1->v.val_addr; | |
5613 | r2 = v2->v.val_addr; | |
5614 | if (GET_CODE (r1) != GET_CODE (r2)) | |
5615 | return 0; | |
5616 | switch (GET_CODE (r1)) | |
5617 | { | |
5618 | case SYMBOL_REF: | |
5619 | return !strcmp (XSTR (r1, 0), XSTR (r2, 0)); | |
5620 | ||
5621 | default: | |
5622 | abort (); | |
5623 | } | |
5624 | ||
5625 | case dw_val_class_offset: | |
5626 | return v1->v.val_offset == v2->v.val_offset; | |
5627 | ||
5628 | case dw_val_class_loc: | |
5629 | for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc; | |
5630 | loc1 && loc2; | |
5631 | loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next) | |
5632 | if (!same_loc_p (loc1, loc2, mark)) | |
5633 | return 0; | |
5634 | return !loc1 && !loc2; | |
5635 | ||
5636 | case dw_val_class_die_ref: | |
5637 | return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark); | |
5638 | ||
5639 | case dw_val_class_fde_ref: | |
5640 | case dw_val_class_lbl_id: | |
5641 | case dw_val_class_lbl_offset: | |
5642 | return 1; | |
5643 | ||
5644 | default: | |
5645 | return 1; | |
5646 | } | |
5647 | } | |
5648 | ||
5649 | /* Do the attributes look the same? */ | |
5650 | ||
5651 | static int | |
5652 | same_attr_p (at1, at2, mark) | |
5653 | dw_attr_ref at1; | |
5654 | dw_attr_ref at2; | |
5655 | int *mark; | |
5656 | { | |
5657 | if (at1->dw_attr != at2->dw_attr) | |
5658 | return 0; | |
5659 | ||
5660 | /* We don't care about differences in file numbering. */ | |
5661 | if (at1->dw_attr == DW_AT_decl_file | |
5662 | /* Or that this was compiled with a different compiler snapshot; if | |
5663 | the output is the same, that's what matters. */ | |
5664 | || at1->dw_attr == DW_AT_producer) | |
5665 | return 1; | |
5666 | ||
5667 | return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark); | |
5668 | } | |
5669 | ||
5670 | /* Do the dies look the same? */ | |
5671 | ||
5672 | static int | |
5673 | same_die_p (die1, die2, mark) | |
5674 | dw_die_ref die1; | |
5675 | dw_die_ref die2; | |
5676 | int *mark; | |
5677 | { | |
5678 | dw_die_ref c1, c2; | |
5679 | dw_attr_ref a1, a2; | |
5680 | ||
5681 | /* To avoid infinite recursion. */ | |
5682 | if (die1->die_mark) | |
5683 | return die1->die_mark == die2->die_mark; | |
5684 | die1->die_mark = die2->die_mark = ++(*mark); | |
5685 | ||
5686 | if (die1->die_tag != die2->die_tag) | |
5687 | return 0; | |
5688 | ||
5689 | for (a1 = die1->die_attr, a2 = die2->die_attr; | |
5690 | a1 && a2; | |
5691 | a1 = a1->dw_attr_next, a2 = a2->dw_attr_next) | |
5692 | if (!same_attr_p (a1, a2, mark)) | |
5693 | return 0; | |
5694 | if (a1 || a2) | |
5695 | return 0; | |
5696 | ||
5697 | for (c1 = die1->die_child, c2 = die2->die_child; | |
5698 | c1 && c2; | |
5699 | c1 = c1->die_sib, c2 = c2->die_sib) | |
5700 | if (!same_die_p (c1, c2, mark)) | |
5701 | return 0; | |
5702 | if (c1 || c2) | |
5703 | return 0; | |
5704 | ||
5705 | return 1; | |
5706 | } | |
5707 | ||
5708 | /* Do the dies look the same? Wrapper around same_die_p. */ | |
5709 | ||
5710 | static int | |
5711 | same_die_p_wrap (die1, die2) | |
5712 | dw_die_ref die1; | |
5713 | dw_die_ref die2; | |
5714 | { | |
5715 | int mark = 0; | |
5716 | int ret = same_die_p (die1, die2, &mark); | |
5717 | ||
5718 | unmark_all_dies (die1); | |
5719 | unmark_all_dies (die2); | |
5720 | ||
5721 | return ret; | |
5722 | } | |
5723 | ||
881c6935 JM |
5724 | /* The prefix to attach to symbols on DIEs in the current comdat debug |
5725 | info section. */ | |
5726 | static char *comdat_symbol_id; | |
5727 | ||
5728 | /* The index of the current symbol within the current comdat CU. */ | |
5729 | static unsigned int comdat_symbol_number; | |
5730 | ||
5731 | /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its | |
5732 | children, and set comdat_symbol_id accordingly. */ | |
5733 | ||
5734 | static void | |
5735 | compute_section_prefix (unit_die) | |
5736 | dw_die_ref unit_die; | |
5737 | { | |
cc0017a9 ZD |
5738 | const char *die_name = get_AT_string (unit_die, DW_AT_name); |
5739 | const char *base = die_name ? lbasename (die_name) : "anonymous"; | |
f11c3043 RK |
5740 | char *name = (char *) alloca (strlen (base) + 64); |
5741 | char *p; | |
cc0017a9 | 5742 | int i, mark; |
881c6935 JM |
5743 | unsigned char checksum[16]; |
5744 | struct md5_ctx ctx; | |
5745 | ||
f11c3043 RK |
5746 | /* Compute the checksum of the DIE, then append part of it as hex digits to |
5747 | the name filename of the unit. */ | |
5748 | ||
881c6935 | 5749 | md5_init_ctx (&ctx); |
cc0017a9 ZD |
5750 | mark = 0; |
5751 | die_checksum (unit_die, &ctx, &mark); | |
5752 | unmark_all_dies (unit_die); | |
881c6935 JM |
5753 | md5_finish_ctx (&ctx, checksum); |
5754 | ||
0023400b | 5755 | sprintf (name, "%s.", base); |
881c6935 JM |
5756 | clean_symbol_name (name); |
5757 | ||
2ad9852d RK |
5758 | p = name + strlen (name); |
5759 | for (i = 0; i < 4; i++) | |
5760 | { | |
5761 | sprintf (p, "%.2x", checksum[i]); | |
5762 | p += 2; | |
5763 | } | |
881c6935 JM |
5764 | |
5765 | comdat_symbol_id = unit_die->die_symbol = xstrdup (name); | |
5766 | comdat_symbol_number = 0; | |
5767 | } | |
5768 | ||
f11c3043 | 5769 | /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */ |
881c6935 JM |
5770 | |
5771 | static int | |
5772 | is_type_die (die) | |
5773 | dw_die_ref die; | |
5774 | { | |
5775 | switch (die->die_tag) | |
5776 | { | |
5777 | case DW_TAG_array_type: | |
5778 | case DW_TAG_class_type: | |
5779 | case DW_TAG_enumeration_type: | |
5780 | case DW_TAG_pointer_type: | |
5781 | case DW_TAG_reference_type: | |
5782 | case DW_TAG_string_type: | |
5783 | case DW_TAG_structure_type: | |
5784 | case DW_TAG_subroutine_type: | |
5785 | case DW_TAG_union_type: | |
5786 | case DW_TAG_ptr_to_member_type: | |
5787 | case DW_TAG_set_type: | |
5788 | case DW_TAG_subrange_type: | |
5789 | case DW_TAG_base_type: | |
5790 | case DW_TAG_const_type: | |
5791 | case DW_TAG_file_type: | |
5792 | case DW_TAG_packed_type: | |
5793 | case DW_TAG_volatile_type: | |
cc0017a9 | 5794 | case DW_TAG_typedef: |
881c6935 JM |
5795 | return 1; |
5796 | default: | |
5797 | return 0; | |
5798 | } | |
5799 | } | |
5800 | ||
5801 | /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU. | |
5802 | Basically, we want to choose the bits that are likely to be shared between | |
5803 | compilations (types) and leave out the bits that are specific to individual | |
5804 | compilations (functions). */ | |
5805 | ||
5806 | static int | |
5807 | is_comdat_die (c) | |
5808 | dw_die_ref c; | |
5809 | { | |
2ad9852d RK |
5810 | /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as |
5811 | we do for stabs. The advantage is a greater likelihood of sharing between | |
5812 | objects that don't include headers in the same order (and therefore would | |
5813 | put the base types in a different comdat). jason 8/28/00 */ | |
5814 | ||
881c6935 JM |
5815 | if (c->die_tag == DW_TAG_base_type) |
5816 | return 0; | |
5817 | ||
5818 | if (c->die_tag == DW_TAG_pointer_type | |
5819 | || c->die_tag == DW_TAG_reference_type | |
5820 | || c->die_tag == DW_TAG_const_type | |
5821 | || c->die_tag == DW_TAG_volatile_type) | |
5822 | { | |
5823 | dw_die_ref t = get_AT_ref (c, DW_AT_type); | |
2ad9852d | 5824 | |
881c6935 JM |
5825 | return t ? is_comdat_die (t) : 0; |
5826 | } | |
881c6935 JM |
5827 | |
5828 | return is_type_die (c); | |
5829 | } | |
5830 | ||
5831 | /* Returns 1 iff C is the sort of DIE that might be referred to from another | |
5832 | compilation unit. */ | |
5833 | ||
5834 | static int | |
5835 | is_symbol_die (c) | |
5836 | dw_die_ref c; | |
5837 | { | |
2ad9852d | 5838 | return (is_type_die (c) |
c26fbbca | 5839 | || (get_AT (c, DW_AT_declaration) |
2ad9852d | 5840 | && !get_AT (c, DW_AT_specification))); |
881c6935 JM |
5841 | } |
5842 | ||
5843 | static char * | |
63e46568 | 5844 | gen_internal_sym (prefix) |
173bf5be | 5845 | const char *prefix; |
881c6935 JM |
5846 | { |
5847 | char buf[256]; | |
5848 | static int label_num; | |
2ad9852d | 5849 | |
63e46568 | 5850 | ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++); |
881c6935 JM |
5851 | return xstrdup (buf); |
5852 | } | |
5853 | ||
5854 | /* Assign symbols to all worthy DIEs under DIE. */ | |
5855 | ||
5856 | static void | |
5857 | assign_symbol_names (die) | |
b3694847 | 5858 | dw_die_ref die; |
881c6935 | 5859 | { |
b3694847 | 5860 | dw_die_ref c; |
881c6935 JM |
5861 | |
5862 | if (is_symbol_die (die)) | |
5863 | { | |
5864 | if (comdat_symbol_id) | |
5865 | { | |
5866 | char *p = alloca (strlen (comdat_symbol_id) + 64); | |
2ad9852d | 5867 | |
881c6935 JM |
5868 | sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX, |
5869 | comdat_symbol_id, comdat_symbol_number++); | |
5870 | die->die_symbol = xstrdup (p); | |
5871 | } | |
5872 | else | |
63e46568 | 5873 | die->die_symbol = gen_internal_sym ("LDIE"); |
881c6935 JM |
5874 | } |
5875 | ||
5876 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5877 | assign_symbol_names (c); | |
5878 | } | |
5879 | ||
cc0017a9 ZD |
5880 | struct cu_hash_table_entry |
5881 | { | |
5882 | dw_die_ref cu; | |
5883 | unsigned min_comdat_num, max_comdat_num; | |
5884 | struct cu_hash_table_entry *next; | |
5885 | }; | |
5886 | ||
5887 | /* Routines to manipulate hash table of CUs. */ | |
5888 | static hashval_t | |
5889 | htab_cu_hash (of) | |
5890 | const void *of; | |
5891 | { | |
5892 | const struct cu_hash_table_entry *entry = of; | |
5893 | ||
5894 | return htab_hash_string (entry->cu->die_symbol); | |
5895 | } | |
5896 | ||
5897 | static int | |
5898 | htab_cu_eq (of1, of2) | |
5899 | const void *of1; | |
5900 | const void *of2; | |
5901 | { | |
5902 | const struct cu_hash_table_entry *entry1 = of1; | |
5903 | const struct die_struct *entry2 = of2; | |
5904 | ||
5905 | return !strcmp (entry1->cu->die_symbol, entry2->die_symbol); | |
5906 | } | |
5907 | ||
5908 | static void | |
5909 | htab_cu_del (what) | |
5910 | void *what; | |
5911 | { | |
5912 | struct cu_hash_table_entry *next, *entry = what; | |
5913 | ||
5914 | while (entry) | |
5915 | { | |
5916 | next = entry->next; | |
5917 | free (entry); | |
5918 | entry = next; | |
5919 | } | |
5920 | } | |
5921 | ||
5922 | /* Check whether we have already seen this CU and set up SYM_NUM | |
5923 | accordingly. */ | |
5924 | static int | |
5925 | check_duplicate_cu (cu, htable, sym_num) | |
5926 | dw_die_ref cu; | |
5927 | htab_t htable; | |
5928 | unsigned *sym_num; | |
5929 | { | |
5930 | struct cu_hash_table_entry dummy; | |
5931 | struct cu_hash_table_entry **slot, *entry, *last = &dummy; | |
5932 | ||
5933 | dummy.max_comdat_num = 0; | |
5934 | ||
5935 | slot = (struct cu_hash_table_entry **) | |
5936 | htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol), | |
5937 | INSERT); | |
5938 | entry = *slot; | |
5939 | ||
5940 | for (; entry; last = entry, entry = entry->next) | |
5941 | { | |
5942 | if (same_die_p_wrap (cu, entry->cu)) | |
5943 | break; | |
5944 | } | |
5945 | ||
5946 | if (entry) | |
5947 | { | |
5948 | *sym_num = entry->min_comdat_num; | |
5949 | return 1; | |
5950 | } | |
5951 | ||
5952 | entry = xcalloc (1, sizeof (struct cu_hash_table_entry)); | |
5953 | entry->cu = cu; | |
5954 | entry->min_comdat_num = *sym_num = last->max_comdat_num; | |
5955 | entry->next = *slot; | |
5956 | *slot = entry; | |
5957 | ||
5958 | return 0; | |
5959 | } | |
5960 | ||
5961 | /* Record SYM_NUM to record of CU in HTABLE. */ | |
5962 | static void | |
5963 | record_comdat_symbol_number (cu, htable, sym_num) | |
5964 | dw_die_ref cu; | |
5965 | htab_t htable; | |
5966 | unsigned sym_num; | |
5967 | { | |
5968 | struct cu_hash_table_entry **slot, *entry; | |
5969 | ||
5970 | slot = (struct cu_hash_table_entry **) | |
5971 | htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol), | |
5972 | NO_INSERT); | |
5973 | entry = *slot; | |
5974 | ||
5975 | entry->max_comdat_num = sym_num; | |
5976 | } | |
5977 | ||
881c6935 JM |
5978 | /* Traverse the DIE (which is always comp_unit_die), and set up |
5979 | additional compilation units for each of the include files we see | |
5980 | bracketed by BINCL/EINCL. */ | |
5981 | ||
5982 | static void | |
5983 | break_out_includes (die) | |
b3694847 | 5984 | dw_die_ref die; |
881c6935 JM |
5985 | { |
5986 | dw_die_ref *ptr; | |
b3694847 | 5987 | dw_die_ref unit = NULL; |
cc0017a9 ZD |
5988 | limbo_die_node *node, **pnode; |
5989 | htab_t cu_hash_table; | |
881c6935 | 5990 | |
c26fbbca | 5991 | for (ptr = &(die->die_child); *ptr;) |
881c6935 | 5992 | { |
b3694847 | 5993 | dw_die_ref c = *ptr; |
881c6935 | 5994 | |
2ad9852d | 5995 | if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL |
881c6935 JM |
5996 | || (unit && is_comdat_die (c))) |
5997 | { | |
5998 | /* This DIE is for a secondary CU; remove it from the main one. */ | |
5999 | *ptr = c->die_sib; | |
6000 | ||
6001 | if (c->die_tag == DW_TAG_GNU_BINCL) | |
6002 | { | |
6003 | unit = push_new_compile_unit (unit, c); | |
6004 | free_die (c); | |
6005 | } | |
6006 | else if (c->die_tag == DW_TAG_GNU_EINCL) | |
6007 | { | |
6008 | unit = pop_compile_unit (unit); | |
6009 | free_die (c); | |
6010 | } | |
6011 | else | |
6012 | add_child_die (unit, c); | |
6013 | } | |
6014 | else | |
6015 | { | |
6016 | /* Leave this DIE in the main CU. */ | |
6017 | ptr = &(c->die_sib); | |
6018 | continue; | |
6019 | } | |
6020 | } | |
6021 | ||
6022 | #if 0 | |
6023 | /* We can only use this in debugging, since the frontend doesn't check | |
0b34cf1e | 6024 | to make sure that we leave every include file we enter. */ |
881c6935 JM |
6025 | if (unit != NULL) |
6026 | abort (); | |
6027 | #endif | |
6028 | ||
6029 | assign_symbol_names (die); | |
cc0017a9 ZD |
6030 | cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del); |
6031 | for (node = limbo_die_list, pnode = &limbo_die_list; | |
6032 | node; | |
6033 | node = node->next) | |
881c6935 | 6034 | { |
cc0017a9 ZD |
6035 | int is_dupl; |
6036 | ||
881c6935 | 6037 | compute_section_prefix (node->die); |
cc0017a9 ZD |
6038 | is_dupl = check_duplicate_cu (node->die, cu_hash_table, |
6039 | &comdat_symbol_number); | |
881c6935 | 6040 | assign_symbol_names (node->die); |
cc0017a9 ZD |
6041 | if (is_dupl) |
6042 | *pnode = node->next; | |
6043 | else | |
6044 | { | |
6045 | pnode = &node->next; | |
6046 | record_comdat_symbol_number (node->die, cu_hash_table, | |
6047 | comdat_symbol_number); | |
6048 | } | |
881c6935 | 6049 | } |
cc0017a9 | 6050 | htab_delete (cu_hash_table); |
881c6935 JM |
6051 | } |
6052 | ||
6053 | /* Traverse the DIE and add a sibling attribute if it may have the | |
6054 | effect of speeding up access to siblings. To save some space, | |
6055 | avoid generating sibling attributes for DIE's without children. */ | |
6056 | ||
6057 | static void | |
6058 | add_sibling_attributes (die) | |
b3694847 | 6059 | dw_die_ref die; |
881c6935 | 6060 | { |
b3694847 | 6061 | dw_die_ref c; |
881c6935 JM |
6062 | |
6063 | if (die->die_tag != DW_TAG_compile_unit | |
6064 | && die->die_sib && die->die_child != NULL) | |
7d9d8943 AM |
6065 | /* Add the sibling link to the front of the attribute list. */ |
6066 | add_AT_die_ref (die, DW_AT_sibling, die->die_sib); | |
6067 | ||
6068 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
6069 | add_sibling_attributes (c); | |
6070 | } | |
6071 | ||
2ad9852d RK |
6072 | /* Output all location lists for the DIE and its children. */ |
6073 | ||
63e46568 DB |
6074 | static void |
6075 | output_location_lists (die) | |
b3694847 | 6076 | dw_die_ref die; |
63e46568 DB |
6077 | { |
6078 | dw_die_ref c; | |
6079 | dw_attr_ref d_attr; | |
2ad9852d | 6080 | |
63e46568 | 6081 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) |
2ad9852d RK |
6082 | if (AT_class (d_attr) == dw_val_class_loc_list) |
6083 | output_loc_list (AT_loc_list (d_attr)); | |
6084 | ||
63e46568 DB |
6085 | for (c = die->die_child; c != NULL; c = c->die_sib) |
6086 | output_location_lists (c); | |
6087 | ||
6088 | } | |
c26fbbca | 6089 | |
2ad9852d RK |
6090 | /* The format of each DIE (and its attribute value pairs) is encoded in an |
6091 | abbreviation table. This routine builds the abbreviation table and assigns | |
6092 | a unique abbreviation id for each abbreviation entry. The children of each | |
6093 | die are visited recursively. */ | |
7d9d8943 AM |
6094 | |
6095 | static void | |
6096 | build_abbrev_table (die) | |
b3694847 | 6097 | dw_die_ref die; |
7d9d8943 | 6098 | { |
b3694847 SS |
6099 | unsigned long abbrev_id; |
6100 | unsigned int n_alloc; | |
6101 | dw_die_ref c; | |
6102 | dw_attr_ref d_attr, a_attr; | |
881c6935 JM |
6103 | |
6104 | /* Scan the DIE references, and mark as external any that refer to | |
1bfb5f8f | 6105 | DIEs from other CUs (i.e. those which are not marked). */ |
881c6935 | 6106 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) |
2ad9852d RK |
6107 | if (AT_class (d_attr) == dw_val_class_die_ref |
6108 | && AT_ref (d_attr)->die_mark == 0) | |
6109 | { | |
6110 | if (AT_ref (d_attr)->die_symbol == 0) | |
6111 | abort (); | |
6112 | ||
6113 | set_AT_ref_external (d_attr, 1); | |
6114 | } | |
881c6935 | 6115 | |
7d9d8943 AM |
6116 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
6117 | { | |
b3694847 | 6118 | dw_die_ref abbrev = abbrev_die_table[abbrev_id]; |
7d9d8943 AM |
6119 | |
6120 | if (abbrev->die_tag == die->die_tag) | |
6121 | { | |
6122 | if ((abbrev->die_child != NULL) == (die->die_child != NULL)) | |
6123 | { | |
6124 | a_attr = abbrev->die_attr; | |
6125 | d_attr = die->die_attr; | |
6126 | ||
6127 | while (a_attr != NULL && d_attr != NULL) | |
6128 | { | |
6129 | if ((a_attr->dw_attr != d_attr->dw_attr) | |
6130 | || (value_format (a_attr) != value_format (d_attr))) | |
6131 | break; | |
6132 | ||
6133 | a_attr = a_attr->dw_attr_next; | |
6134 | d_attr = d_attr->dw_attr_next; | |
6135 | } | |
6136 | ||
6137 | if (a_attr == NULL && d_attr == NULL) | |
6138 | break; | |
6139 | } | |
6140 | } | |
6141 | } | |
6142 | ||
6143 | if (abbrev_id >= abbrev_die_table_in_use) | |
6144 | { | |
6145 | if (abbrev_die_table_in_use >= abbrev_die_table_allocated) | |
6146 | { | |
6147 | n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT; | |
556273e0 | 6148 | abbrev_die_table |
7d9d8943 AM |
6149 | = (dw_die_ref *) xrealloc (abbrev_die_table, |
6150 | sizeof (dw_die_ref) * n_alloc); | |
6151 | ||
961192e1 | 6152 | memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0, |
7d9d8943 AM |
6153 | (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref)); |
6154 | abbrev_die_table_allocated = n_alloc; | |
6155 | } | |
6156 | ||
6157 | ++abbrev_die_table_in_use; | |
6158 | abbrev_die_table[abbrev_id] = die; | |
6159 | } | |
6160 | ||
6161 | die->die_abbrev = abbrev_id; | |
6162 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
6163 | build_abbrev_table (c); | |
6164 | } | |
6165 | \f | |
3f76745e JM |
6166 | /* Return the power-of-two number of bytes necessary to represent VALUE. */ |
6167 | ||
6168 | static int | |
6169 | constant_size (value) | |
6170 | long unsigned value; | |
6171 | { | |
6172 | int log; | |
6173 | ||
6174 | if (value == 0) | |
6175 | log = 0; | |
a3f97cbb | 6176 | else |
3f76745e | 6177 | log = floor_log2 (value); |
71dfc51f | 6178 | |
3f76745e JM |
6179 | log = log / 8; |
6180 | log = 1 << (floor_log2 (log) + 1); | |
6181 | ||
6182 | return log; | |
a3f97cbb JW |
6183 | } |
6184 | ||
2ad9852d | 6185 | /* Return the size of a DIE as it is represented in the |
3f76745e | 6186 | .debug_info section. */ |
71dfc51f | 6187 | |
3f76745e JM |
6188 | static unsigned long |
6189 | size_of_die (die) | |
b3694847 | 6190 | dw_die_ref die; |
a3f97cbb | 6191 | { |
b3694847 SS |
6192 | unsigned long size = 0; |
6193 | dw_attr_ref a; | |
71dfc51f | 6194 | |
3f76745e | 6195 | size += size_of_uleb128 (die->die_abbrev); |
a3f97cbb JW |
6196 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
6197 | { | |
a96c67ec | 6198 | switch (AT_class (a)) |
a3f97cbb JW |
6199 | { |
6200 | case dw_val_class_addr: | |
a1a4189d | 6201 | size += DWARF2_ADDR_SIZE; |
a3f97cbb | 6202 | break; |
a20612aa RH |
6203 | case dw_val_class_offset: |
6204 | size += DWARF_OFFSET_SIZE; | |
6205 | break; | |
a3f97cbb | 6206 | case dw_val_class_loc: |
3f76745e | 6207 | { |
b3694847 | 6208 | unsigned long lsize = size_of_locs (AT_loc (a)); |
71dfc51f | 6209 | |
3f76745e JM |
6210 | /* Block length. */ |
6211 | size += constant_size (lsize); | |
6212 | size += lsize; | |
6213 | } | |
a3f97cbb | 6214 | break; |
63e46568 DB |
6215 | case dw_val_class_loc_list: |
6216 | size += DWARF_OFFSET_SIZE; | |
6217 | break; | |
2bee6045 JJ |
6218 | case dw_val_class_range_list: |
6219 | size += DWARF_OFFSET_SIZE; | |
6220 | break; | |
a3f97cbb | 6221 | case dw_val_class_const: |
25dd13ec | 6222 | size += size_of_sleb128 (AT_int (a)); |
a3f97cbb JW |
6223 | break; |
6224 | case dw_val_class_unsigned_const: | |
a96c67ec | 6225 | size += constant_size (AT_unsigned (a)); |
a3f97cbb | 6226 | break; |
469ac993 | 6227 | case dw_val_class_long_long: |
2e4b9b8c | 6228 | size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */ |
469ac993 JM |
6229 | break; |
6230 | case dw_val_class_float: | |
3f76745e | 6231 | size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */ |
a3f97cbb JW |
6232 | break; |
6233 | case dw_val_class_flag: | |
3f76745e | 6234 | size += 1; |
a3f97cbb JW |
6235 | break; |
6236 | case dw_val_class_die_ref: | |
3f76745e | 6237 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
6238 | break; |
6239 | case dw_val_class_fde_ref: | |
3f76745e | 6240 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
6241 | break; |
6242 | case dw_val_class_lbl_id: | |
a1a4189d | 6243 | size += DWARF2_ADDR_SIZE; |
3f76745e | 6244 | break; |
8b790721 | 6245 | case dw_val_class_lbl_offset: |
3f76745e JM |
6246 | size += DWARF_OFFSET_SIZE; |
6247 | break; | |
6248 | case dw_val_class_str: | |
9eb4015a JJ |
6249 | if (AT_string_form (a) == DW_FORM_strp) |
6250 | size += DWARF_OFFSET_SIZE; | |
6251 | else | |
6252 | size += HT_LEN (&a->dw_attr_val.v.val_str->id) + 1; | |
3f76745e JM |
6253 | break; |
6254 | default: | |
6255 | abort (); | |
6256 | } | |
a3f97cbb | 6257 | } |
3f76745e JM |
6258 | |
6259 | return size; | |
a3f97cbb JW |
6260 | } |
6261 | ||
2ad9852d RK |
6262 | /* Size the debugging information associated with a given DIE. Visits the |
6263 | DIE's children recursively. Updates the global variable next_die_offset, on | |
6264 | each time through. Uses the current value of next_die_offset to update the | |
6265 | die_offset field in each DIE. */ | |
71dfc51f | 6266 | |
a3f97cbb | 6267 | static void |
3f76745e JM |
6268 | calc_die_sizes (die) |
6269 | dw_die_ref die; | |
a3f97cbb | 6270 | { |
b3694847 | 6271 | dw_die_ref c; |
2ad9852d | 6272 | |
3f76745e JM |
6273 | die->die_offset = next_die_offset; |
6274 | next_die_offset += size_of_die (die); | |
71dfc51f | 6275 | |
3f76745e JM |
6276 | for (c = die->die_child; c != NULL; c = c->die_sib) |
6277 | calc_die_sizes (c); | |
71dfc51f | 6278 | |
3f76745e JM |
6279 | if (die->die_child != NULL) |
6280 | /* Count the null byte used to terminate sibling lists. */ | |
6281 | next_die_offset += 1; | |
a3f97cbb JW |
6282 | } |
6283 | ||
1bfb5f8f | 6284 | /* Set the marks for a die and its children. We do this so |
881c6935 | 6285 | that we know whether or not a reference needs to use FORM_ref_addr; only |
1bfb5f8f JM |
6286 | DIEs in the same CU will be marked. We used to clear out the offset |
6287 | and use that as the flag, but ran into ordering problems. */ | |
881c6935 JM |
6288 | |
6289 | static void | |
1bfb5f8f | 6290 | mark_dies (die) |
881c6935 JM |
6291 | dw_die_ref die; |
6292 | { | |
b3694847 | 6293 | dw_die_ref c; |
2ad9852d | 6294 | |
cc0017a9 ZD |
6295 | if (die->die_mark) |
6296 | abort (); | |
6297 | ||
1bfb5f8f JM |
6298 | die->die_mark = 1; |
6299 | for (c = die->die_child; c; c = c->die_sib) | |
6300 | mark_dies (c); | |
6301 | } | |
6302 | ||
6303 | /* Clear the marks for a die and its children. */ | |
6304 | ||
6305 | static void | |
6306 | unmark_dies (die) | |
6307 | dw_die_ref die; | |
6308 | { | |
b3694847 | 6309 | dw_die_ref c; |
2ad9852d | 6310 | |
cc0017a9 ZD |
6311 | if (!die->die_mark) |
6312 | abort (); | |
6313 | ||
1bfb5f8f | 6314 | die->die_mark = 0; |
881c6935 | 6315 | for (c = die->die_child; c; c = c->die_sib) |
1bfb5f8f | 6316 | unmark_dies (c); |
881c6935 JM |
6317 | } |
6318 | ||
cc0017a9 ZD |
6319 | /* Clear the marks for a die, its children and referred dies. */ |
6320 | ||
6321 | static void | |
6322 | unmark_all_dies (die) | |
6323 | dw_die_ref die; | |
6324 | { | |
6325 | dw_die_ref c; | |
6326 | dw_attr_ref a; | |
6327 | ||
6328 | if (!die->die_mark) | |
6329 | return; | |
6330 | die->die_mark = 0; | |
6331 | ||
6332 | for (c = die->die_child; c; c = c->die_sib) | |
6333 | unmark_all_dies (c); | |
6334 | ||
6335 | for (a = die->die_attr; a; a = a->dw_attr_next) | |
6336 | if (AT_class (a) == dw_val_class_die_ref) | |
6337 | unmark_all_dies (AT_ref (a)); | |
6338 | } | |
6339 | ||
3f76745e JM |
6340 | /* Return the size of the .debug_pubnames table generated for the |
6341 | compilation unit. */ | |
a94dbf2c | 6342 | |
3f76745e JM |
6343 | static unsigned long |
6344 | size_of_pubnames () | |
a94dbf2c | 6345 | { |
b3694847 SS |
6346 | unsigned long size; |
6347 | unsigned i; | |
469ac993 | 6348 | |
3f76745e | 6349 | size = DWARF_PUBNAMES_HEADER_SIZE; |
2ad9852d | 6350 | for (i = 0; i < pubname_table_in_use; i++) |
a94dbf2c | 6351 | { |
b3694847 | 6352 | pubname_ref p = &pubname_table[i]; |
9eb4015a | 6353 | size += DWARF_OFFSET_SIZE + strlen (p->name) + 1; |
a94dbf2c JM |
6354 | } |
6355 | ||
3f76745e JM |
6356 | size += DWARF_OFFSET_SIZE; |
6357 | return size; | |
a94dbf2c JM |
6358 | } |
6359 | ||
956d6950 | 6360 | /* Return the size of the information in the .debug_aranges section. */ |
469ac993 | 6361 | |
3f76745e JM |
6362 | static unsigned long |
6363 | size_of_aranges () | |
469ac993 | 6364 | { |
b3694847 | 6365 | unsigned long size; |
469ac993 | 6366 | |
3f76745e | 6367 | size = DWARF_ARANGES_HEADER_SIZE; |
469ac993 | 6368 | |
3f76745e | 6369 | /* Count the address/length pair for this compilation unit. */ |
a1a4189d JB |
6370 | size += 2 * DWARF2_ADDR_SIZE; |
6371 | size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use; | |
469ac993 | 6372 | |
3f76745e | 6373 | /* Count the two zero words used to terminated the address range table. */ |
a1a4189d | 6374 | size += 2 * DWARF2_ADDR_SIZE; |
3f76745e JM |
6375 | return size; |
6376 | } | |
6377 | \f | |
6378 | /* Select the encoding of an attribute value. */ | |
6379 | ||
6380 | static enum dwarf_form | |
a96c67ec JM |
6381 | value_format (a) |
6382 | dw_attr_ref a; | |
3f76745e | 6383 | { |
a96c67ec | 6384 | switch (a->dw_attr_val.val_class) |
469ac993 | 6385 | { |
3f76745e JM |
6386 | case dw_val_class_addr: |
6387 | return DW_FORM_addr; | |
2bee6045 | 6388 | case dw_val_class_range_list: |
a20612aa RH |
6389 | case dw_val_class_offset: |
6390 | if (DWARF_OFFSET_SIZE == 4) | |
6391 | return DW_FORM_data4; | |
6392 | if (DWARF_OFFSET_SIZE == 8) | |
6393 | return DW_FORM_data8; | |
6394 | abort (); | |
63e46568 | 6395 | case dw_val_class_loc_list: |
9d2f2c45 RH |
6396 | /* FIXME: Could be DW_FORM_data8, with a > 32 bit size |
6397 | .debug_loc section */ | |
6398 | return DW_FORM_data4; | |
3f76745e | 6399 | case dw_val_class_loc: |
a96c67ec | 6400 | switch (constant_size (size_of_locs (AT_loc (a)))) |
469ac993 | 6401 | { |
3f76745e JM |
6402 | case 1: |
6403 | return DW_FORM_block1; | |
6404 | case 2: | |
6405 | return DW_FORM_block2; | |
469ac993 JM |
6406 | default: |
6407 | abort (); | |
6408 | } | |
3f76745e | 6409 | case dw_val_class_const: |
25dd13ec | 6410 | return DW_FORM_sdata; |
3f76745e | 6411 | case dw_val_class_unsigned_const: |
a96c67ec | 6412 | switch (constant_size (AT_unsigned (a))) |
3f76745e JM |
6413 | { |
6414 | case 1: | |
6415 | return DW_FORM_data1; | |
6416 | case 2: | |
6417 | return DW_FORM_data2; | |
6418 | case 4: | |
6419 | return DW_FORM_data4; | |
6420 | case 8: | |
6421 | return DW_FORM_data8; | |
6422 | default: | |
6423 | abort (); | |
6424 | } | |
6425 | case dw_val_class_long_long: | |
6426 | return DW_FORM_block1; | |
6427 | case dw_val_class_float: | |
6428 | return DW_FORM_block1; | |
6429 | case dw_val_class_flag: | |
6430 | return DW_FORM_flag; | |
6431 | case dw_val_class_die_ref: | |
881c6935 JM |
6432 | if (AT_ref_external (a)) |
6433 | return DW_FORM_ref_addr; | |
6434 | else | |
6435 | return DW_FORM_ref; | |
3f76745e JM |
6436 | case dw_val_class_fde_ref: |
6437 | return DW_FORM_data; | |
6438 | case dw_val_class_lbl_id: | |
6439 | return DW_FORM_addr; | |
8b790721 | 6440 | case dw_val_class_lbl_offset: |
3f76745e JM |
6441 | return DW_FORM_data; |
6442 | case dw_val_class_str: | |
9eb4015a | 6443 | return AT_string_form (a); |
a20612aa | 6444 | |
469ac993 JM |
6445 | default: |
6446 | abort (); | |
6447 | } | |
a94dbf2c JM |
6448 | } |
6449 | ||
3f76745e | 6450 | /* Output the encoding of an attribute value. */ |
469ac993 | 6451 | |
3f76745e | 6452 | static void |
a96c67ec JM |
6453 | output_value_format (a) |
6454 | dw_attr_ref a; | |
a94dbf2c | 6455 | { |
a96c67ec | 6456 | enum dwarf_form form = value_format (a); |
2ad9852d | 6457 | |
2e4b9b8c | 6458 | dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form)); |
3f76745e | 6459 | } |
469ac993 | 6460 | |
3f76745e JM |
6461 | /* Output the .debug_abbrev section which defines the DIE abbreviation |
6462 | table. */ | |
469ac993 | 6463 | |
3f76745e JM |
6464 | static void |
6465 | output_abbrev_section () | |
6466 | { | |
6467 | unsigned long abbrev_id; | |
71dfc51f | 6468 | |
3f76745e | 6469 | dw_attr_ref a_attr; |
2ad9852d | 6470 | |
3f76745e JM |
6471 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
6472 | { | |
b3694847 | 6473 | dw_die_ref abbrev = abbrev_die_table[abbrev_id]; |
71dfc51f | 6474 | |
2e4b9b8c | 6475 | dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)"); |
2e4b9b8c RH |
6476 | dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)", |
6477 | dwarf_tag_name (abbrev->die_tag)); | |
71dfc51f | 6478 | |
2e4b9b8c RH |
6479 | if (abbrev->die_child != NULL) |
6480 | dw2_asm_output_data (1, DW_children_yes, "DW_children_yes"); | |
6481 | else | |
6482 | dw2_asm_output_data (1, DW_children_no, "DW_children_no"); | |
3f76745e JM |
6483 | |
6484 | for (a_attr = abbrev->die_attr; a_attr != NULL; | |
6485 | a_attr = a_attr->dw_attr_next) | |
6486 | { | |
2e4b9b8c RH |
6487 | dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)", |
6488 | dwarf_attr_name (a_attr->dw_attr)); | |
a96c67ec | 6489 | output_value_format (a_attr); |
469ac993 | 6490 | } |
469ac993 | 6491 | |
2e4b9b8c RH |
6492 | dw2_asm_output_data (1, 0, NULL); |
6493 | dw2_asm_output_data (1, 0, NULL); | |
469ac993 | 6494 | } |
81f374eb HPN |
6495 | |
6496 | /* Terminate the table. */ | |
2e4b9b8c | 6497 | dw2_asm_output_data (1, 0, NULL); |
a94dbf2c JM |
6498 | } |
6499 | ||
881c6935 JM |
6500 | /* Output a symbol we can use to refer to this DIE from another CU. */ |
6501 | ||
6502 | static inline void | |
6503 | output_die_symbol (die) | |
b3694847 | 6504 | dw_die_ref die; |
881c6935 JM |
6505 | { |
6506 | char *sym = die->die_symbol; | |
6507 | ||
6508 | if (sym == 0) | |
6509 | return; | |
6510 | ||
6511 | if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0) | |
6512 | /* We make these global, not weak; if the target doesn't support | |
6513 | .linkonce, it doesn't support combining the sections, so debugging | |
6514 | will break. */ | |
5eb99654 | 6515 | (*targetm.asm_out.globalize_label) (asm_out_file, sym); |
2ad9852d | 6516 | |
881c6935 JM |
6517 | ASM_OUTPUT_LABEL (asm_out_file, sym); |
6518 | } | |
6519 | ||
84a5b4f8 | 6520 | /* Return a new location list, given the begin and end range, and the |
2ad9852d RK |
6521 | expression. gensym tells us whether to generate a new internal symbol for |
6522 | this location list node, which is done for the head of the list only. */ | |
6523 | ||
84a5b4f8 DB |
6524 | static inline dw_loc_list_ref |
6525 | new_loc_list (expr, begin, end, section, gensym) | |
b3694847 SS |
6526 | dw_loc_descr_ref expr; |
6527 | const char *begin; | |
6528 | const char *end; | |
6529 | const char *section; | |
6530 | unsigned gensym; | |
84a5b4f8 | 6531 | { |
b3694847 | 6532 | dw_loc_list_ref retlist |
84a5b4f8 | 6533 | = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node)); |
2ad9852d | 6534 | |
84a5b4f8 DB |
6535 | retlist->begin = begin; |
6536 | retlist->end = end; | |
6537 | retlist->expr = expr; | |
6538 | retlist->section = section; | |
c26fbbca | 6539 | if (gensym) |
84a5b4f8 | 6540 | retlist->ll_symbol = gen_internal_sym ("LLST"); |
2ad9852d | 6541 | |
84a5b4f8 DB |
6542 | return retlist; |
6543 | } | |
6544 | ||
6545 | /* Add a location description expression to a location list */ | |
2ad9852d | 6546 | |
84a5b4f8 DB |
6547 | static inline void |
6548 | add_loc_descr_to_loc_list (list_head, descr, begin, end, section) | |
b3694847 SS |
6549 | dw_loc_list_ref *list_head; |
6550 | dw_loc_descr_ref descr; | |
6551 | const char *begin; | |
6552 | const char *end; | |
6553 | const char *section; | |
84a5b4f8 | 6554 | { |
b3694847 | 6555 | dw_loc_list_ref *d; |
c26fbbca | 6556 | |
30f7a378 | 6557 | /* Find the end of the chain. */ |
84a5b4f8 DB |
6558 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) |
6559 | ; | |
2ad9852d | 6560 | |
84a5b4f8 DB |
6561 | /* Add a new location list node to the list */ |
6562 | *d = new_loc_list (descr, begin, end, section, 0); | |
6563 | } | |
6564 | ||
63e46568 | 6565 | /* Output the location list given to us */ |
2ad9852d | 6566 | |
63e46568 DB |
6567 | static void |
6568 | output_loc_list (list_head) | |
b3694847 | 6569 | dw_loc_list_ref list_head; |
63e46568 | 6570 | { |
2ad9852d RK |
6571 | dw_loc_list_ref curr = list_head; |
6572 | ||
63e46568 | 6573 | ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol); |
a20612aa RH |
6574 | |
6575 | /* ??? This shouldn't be needed now that we've forced the | |
6576 | compilation unit base address to zero when there is code | |
6577 | in more than one section. */ | |
63e46568 DB |
6578 | if (strcmp (curr->section, ".text") == 0) |
6579 | { | |
aafdcfcd | 6580 | /* dw2_asm_output_data will mask off any extra bits in the ~0. */ |
c4f2c499 | 6581 | dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0, |
aafdcfcd NS |
6582 | "Location list base address specifier fake entry"); |
6583 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section, | |
6584 | "Location list base address specifier base"); | |
63e46568 | 6585 | } |
2ad9852d | 6586 | |
c26fbbca | 6587 | for (curr = list_head; curr != NULL; curr = curr->dw_loc_next) |
63e46568 | 6588 | { |
2bee6045 | 6589 | unsigned long size; |
2ad9852d | 6590 | |
aafdcfcd NS |
6591 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section, |
6592 | "Location list begin address (%s)", | |
6593 | list_head->ll_symbol); | |
6594 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section, | |
6595 | "Location list end address (%s)", | |
6596 | list_head->ll_symbol); | |
63e46568 | 6597 | size = size_of_locs (curr->expr); |
c26fbbca | 6598 | |
63e46568 | 6599 | /* Output the block length for this list of location operations. */ |
2bee6045 JJ |
6600 | if (size > 0xffff) |
6601 | abort (); | |
6602 | dw2_asm_output_data (2, size, "%s", "Location expression size"); | |
6603 | ||
63e46568 DB |
6604 | output_loc_sequence (curr->expr); |
6605 | } | |
2ad9852d | 6606 | |
aafdcfcd NS |
6607 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, |
6608 | "Location list terminator begin (%s)", | |
6609 | list_head->ll_symbol); | |
6610 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, | |
6611 | "Location list terminator end (%s)", | |
6612 | list_head->ll_symbol); | |
63e46568 | 6613 | } |
9eb4015a | 6614 | |
3f76745e JM |
6615 | /* Output the DIE and its attributes. Called recursively to generate |
6616 | the definitions of each child DIE. */ | |
71dfc51f | 6617 | |
a3f97cbb | 6618 | static void |
3f76745e | 6619 | output_die (die) |
b3694847 | 6620 | dw_die_ref die; |
a3f97cbb | 6621 | { |
b3694847 SS |
6622 | dw_attr_ref a; |
6623 | dw_die_ref c; | |
6624 | unsigned long size; | |
a94dbf2c | 6625 | |
881c6935 JM |
6626 | /* If someone in another CU might refer to us, set up a symbol for |
6627 | them to point to. */ | |
6628 | if (die->die_symbol) | |
6629 | output_die_symbol (die); | |
6630 | ||
2e4b9b8c RH |
6631 | dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)", |
6632 | die->die_offset, dwarf_tag_name (die->die_tag)); | |
a94dbf2c | 6633 | |
3f76745e | 6634 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
a3f97cbb | 6635 | { |
2e4b9b8c RH |
6636 | const char *name = dwarf_attr_name (a->dw_attr); |
6637 | ||
a96c67ec | 6638 | switch (AT_class (a)) |
3f76745e JM |
6639 | { |
6640 | case dw_val_class_addr: | |
2e4b9b8c | 6641 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name); |
3f76745e | 6642 | break; |
a3f97cbb | 6643 | |
a20612aa RH |
6644 | case dw_val_class_offset: |
6645 | dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset, | |
6646 | "%s", name); | |
6647 | break; | |
6648 | ||
2bee6045 JJ |
6649 | case dw_val_class_range_list: |
6650 | { | |
6651 | char *p = strchr (ranges_section_label, '\0'); | |
6652 | ||
6653 | sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset); | |
6654 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label, | |
6655 | "%s", name); | |
6656 | *p = '\0'; | |
6657 | } | |
6658 | break; | |
6659 | ||
3f76745e | 6660 | case dw_val_class_loc: |
a96c67ec | 6661 | size = size_of_locs (AT_loc (a)); |
71dfc51f | 6662 | |
3f76745e | 6663 | /* Output the block length for this list of location operations. */ |
2e4b9b8c | 6664 | dw2_asm_output_data (constant_size (size), size, "%s", name); |
71dfc51f | 6665 | |
7d9d8943 | 6666 | output_loc_sequence (AT_loc (a)); |
a3f97cbb | 6667 | break; |
3f76745e JM |
6668 | |
6669 | case dw_val_class_const: | |
25dd13ec JW |
6670 | /* ??? It would be slightly more efficient to use a scheme like is |
6671 | used for unsigned constants below, but gdb 4.x does not sign | |
6672 | extend. Gdb 5.x does sign extend. */ | |
2e4b9b8c | 6673 | dw2_asm_output_data_sleb128 (AT_int (a), "%s", name); |
a3f97cbb | 6674 | break; |
3f76745e JM |
6675 | |
6676 | case dw_val_class_unsigned_const: | |
2e4b9b8c RH |
6677 | dw2_asm_output_data (constant_size (AT_unsigned (a)), |
6678 | AT_unsigned (a), "%s", name); | |
a3f97cbb | 6679 | break; |
3f76745e JM |
6680 | |
6681 | case dw_val_class_long_long: | |
2e4b9b8c RH |
6682 | { |
6683 | unsigned HOST_WIDE_INT first, second; | |
3f76745e | 6684 | |
2ad9852d RK |
6685 | dw2_asm_output_data (1, |
6686 | 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, | |
c26fbbca | 6687 | "%s", name); |
556273e0 | 6688 | |
2e4b9b8c RH |
6689 | if (WORDS_BIG_ENDIAN) |
6690 | { | |
6691 | first = a->dw_attr_val.v.val_long_long.hi; | |
6692 | second = a->dw_attr_val.v.val_long_long.low; | |
6693 | } | |
6694 | else | |
6695 | { | |
6696 | first = a->dw_attr_val.v.val_long_long.low; | |
6697 | second = a->dw_attr_val.v.val_long_long.hi; | |
6698 | } | |
2ad9852d RK |
6699 | |
6700 | dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, | |
2e4b9b8c | 6701 | first, "long long constant"); |
2ad9852d | 6702 | dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, |
2e4b9b8c RH |
6703 | second, NULL); |
6704 | } | |
a3f97cbb | 6705 | break; |
3f76745e JM |
6706 | |
6707 | case dw_val_class_float: | |
c84e2712 | 6708 | { |
b3694847 | 6709 | unsigned int i; |
c84e2712 | 6710 | |
2e4b9b8c | 6711 | dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4, |
c26fbbca | 6712 | "%s", name); |
c84e2712 | 6713 | |
2ad9852d | 6714 | for (i = 0; i < a->dw_attr_val.v.val_float.length; i++) |
2e4b9b8c RH |
6715 | dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i], |
6716 | "fp constant word %u", i); | |
556273e0 | 6717 | break; |
c84e2712 | 6718 | } |
3f76745e JM |
6719 | |
6720 | case dw_val_class_flag: | |
2e4b9b8c | 6721 | dw2_asm_output_data (1, AT_flag (a), "%s", name); |
a3f97cbb | 6722 | break; |
a20612aa | 6723 | |
c26fbbca | 6724 | case dw_val_class_loc_list: |
63e46568 DB |
6725 | { |
6726 | char *sym = AT_loc_list (a)->ll_symbol; | |
2ad9852d | 6727 | |
63e46568 | 6728 | if (sym == 0) |
173bf5be | 6729 | abort (); |
a20612aa RH |
6730 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, |
6731 | loc_section_label, "%s", name); | |
63e46568 DB |
6732 | } |
6733 | break; | |
a20612aa | 6734 | |
3f76745e | 6735 | case dw_val_class_die_ref: |
881c6935 | 6736 | if (AT_ref_external (a)) |
2e4b9b8c RH |
6737 | { |
6738 | char *sym = AT_ref (a)->die_symbol; | |
2ad9852d | 6739 | |
2e4b9b8c RH |
6740 | if (sym == 0) |
6741 | abort (); | |
6742 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name); | |
6743 | } | |
3f4907a6 JM |
6744 | else if (AT_ref (a)->die_offset == 0) |
6745 | abort (); | |
881c6935 | 6746 | else |
2e4b9b8c RH |
6747 | dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset, |
6748 | "%s", name); | |
a3f97cbb | 6749 | break; |
3f76745e JM |
6750 | |
6751 | case dw_val_class_fde_ref: | |
a6ab3aad JM |
6752 | { |
6753 | char l1[20]; | |
2ad9852d | 6754 | |
2e4b9b8c RH |
6755 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL, |
6756 | a->dw_attr_val.v.val_fde_index * 2); | |
6757 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name); | |
a6ab3aad | 6758 | } |
a3f97cbb | 6759 | break; |
a3f97cbb | 6760 | |
3f76745e | 6761 | case dw_val_class_lbl_id: |
8e7fa2c8 | 6762 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 6763 | break; |
71dfc51f | 6764 | |
8b790721 | 6765 | case dw_val_class_lbl_offset: |
2e4b9b8c | 6766 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 6767 | break; |
a3f97cbb | 6768 | |
3f76745e | 6769 | case dw_val_class_str: |
9eb4015a JJ |
6770 | if (AT_string_form (a) == DW_FORM_strp) |
6771 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, | |
6772 | a->dw_attr_val.v.val_str->label, | |
a4cf1d85 | 6773 | "%s: \"%s\"", name, AT_string (a)); |
9eb4015a JJ |
6774 | else |
6775 | dw2_asm_output_nstring (AT_string (a), -1, "%s", name); | |
3f76745e | 6776 | break; |
b2932ae5 | 6777 | |
3f76745e JM |
6778 | default: |
6779 | abort (); | |
6780 | } | |
3f76745e | 6781 | } |
71dfc51f | 6782 | |
3f76745e JM |
6783 | for (c = die->die_child; c != NULL; c = c->die_sib) |
6784 | output_die (c); | |
71dfc51f | 6785 | |
2ad9852d | 6786 | /* Add null byte to terminate sibling list. */ |
3f76745e | 6787 | if (die->die_child != NULL) |
2ad9852d RK |
6788 | dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx", |
6789 | die->die_offset); | |
3f76745e | 6790 | } |
71dfc51f | 6791 | |
3f76745e JM |
6792 | /* Output the compilation unit that appears at the beginning of the |
6793 | .debug_info section, and precedes the DIE descriptions. */ | |
71dfc51f | 6794 | |
3f76745e JM |
6795 | static void |
6796 | output_compilation_unit_header () | |
6797 | { | |
2e4b9b8c RH |
6798 | dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE, |
6799 | "Length of Compilation Unit Info"); | |
2e4b9b8c | 6800 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number"); |
2e4b9b8c RH |
6801 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label, |
6802 | "Offset Into Abbrev. Section"); | |
2e4b9b8c | 6803 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)"); |
a3f97cbb JW |
6804 | } |
6805 | ||
881c6935 JM |
6806 | /* Output the compilation unit DIE and its children. */ |
6807 | ||
6808 | static void | |
cc0017a9 | 6809 | output_comp_unit (die, output_if_empty) |
881c6935 | 6810 | dw_die_ref die; |
cc0017a9 | 6811 | int output_if_empty; |
881c6935 | 6812 | { |
ce1cc601 | 6813 | const char *secname; |
cc0017a9 ZD |
6814 | char *oldsym, *tmp; |
6815 | ||
6816 | /* Unless we are outputting main CU, we may throw away empty ones. */ | |
6817 | if (!output_if_empty && die->die_child == NULL) | |
6818 | return; | |
881c6935 | 6819 | |
2ad9852d RK |
6820 | /* Even if there are no children of this DIE, we must output the information |
6821 | about the compilation unit. Otherwise, on an empty translation unit, we | |
6822 | will generate a present, but empty, .debug_info section. IRIX 6.5 `nm' | |
6823 | will then complain when examining the file. First mark all the DIEs in | |
6824 | this CU so we know which get local refs. */ | |
1bfb5f8f JM |
6825 | mark_dies (die); |
6826 | ||
6827 | build_abbrev_table (die); | |
6828 | ||
6d2f8887 | 6829 | /* Initialize the beginning DIE offset - and calculate sizes/offsets. */ |
881c6935 JM |
6830 | next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE; |
6831 | calc_die_sizes (die); | |
6832 | ||
cc0017a9 ZD |
6833 | oldsym = die->die_symbol; |
6834 | if (oldsym) | |
881c6935 | 6835 | { |
cc0017a9 | 6836 | tmp = (char *) alloca (strlen (oldsym) + 24); |
2ad9852d | 6837 | |
cc0017a9 | 6838 | sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym); |
ce1cc601 | 6839 | secname = tmp; |
881c6935 JM |
6840 | die->die_symbol = NULL; |
6841 | } | |
6842 | else | |
ce1cc601 | 6843 | secname = (const char *) DEBUG_INFO_SECTION; |
881c6935 JM |
6844 | |
6845 | /* Output debugging information. */ | |
715bdd29 | 6846 | named_section_flags (secname, SECTION_DEBUG); |
881c6935 JM |
6847 | output_compilation_unit_header (); |
6848 | output_die (die); | |
6849 | ||
1bfb5f8f JM |
6850 | /* Leave the marks on the main CU, so we can check them in |
6851 | output_pubnames. */ | |
cc0017a9 ZD |
6852 | if (oldsym) |
6853 | { | |
6854 | unmark_dies (die); | |
6855 | die->die_symbol = oldsym; | |
6856 | } | |
881c6935 JM |
6857 | } |
6858 | ||
7afff7cf NB |
6859 | /* The DWARF2 pubname for a nested thingy looks like "A::f". The |
6860 | output of lang_hooks.decl_printable_name for C++ looks like | |
6861 | "A::f(int)". Let's drop the argument list, and maybe the scope. */ | |
a1d7ffe3 | 6862 | |
d560ee52 | 6863 | static const char * |
a1d7ffe3 JM |
6864 | dwarf2_name (decl, scope) |
6865 | tree decl; | |
6866 | int scope; | |
6867 | { | |
7afff7cf | 6868 | return (*lang_hooks.decl_printable_name) (decl, scope ? 1 : 0); |
a1d7ffe3 JM |
6869 | } |
6870 | ||
d291dd49 | 6871 | /* Add a new entry to .debug_pubnames if appropriate. */ |
71dfc51f | 6872 | |
d291dd49 JM |
6873 | static void |
6874 | add_pubname (decl, die) | |
6875 | tree decl; | |
6876 | dw_die_ref die; | |
6877 | { | |
6878 | pubname_ref p; | |
6879 | ||
6880 | if (! TREE_PUBLIC (decl)) | |
6881 | return; | |
6882 | ||
6883 | if (pubname_table_in_use == pubname_table_allocated) | |
6884 | { | |
6885 | pubname_table_allocated += PUBNAME_TABLE_INCREMENT; | |
2ad9852d RK |
6886 | pubname_table |
6887 | = (pubname_ref) xrealloc (pubname_table, | |
6888 | (pubname_table_allocated | |
6889 | * sizeof (pubname_entry))); | |
d291dd49 | 6890 | } |
71dfc51f | 6891 | |
d291dd49 JM |
6892 | p = &pubname_table[pubname_table_in_use++]; |
6893 | p->die = die; | |
a1d7ffe3 | 6894 | p->name = xstrdup (dwarf2_name (decl, 1)); |
d291dd49 JM |
6895 | } |
6896 | ||
a3f97cbb JW |
6897 | /* Output the public names table used to speed up access to externally |
6898 | visible names. For now, only generate entries for externally | |
6899 | visible procedures. */ | |
71dfc51f | 6900 | |
a3f97cbb JW |
6901 | static void |
6902 | output_pubnames () | |
6903 | { | |
b3694847 SS |
6904 | unsigned i; |
6905 | unsigned long pubnames_length = size_of_pubnames (); | |
71dfc51f | 6906 | |
2e4b9b8c RH |
6907 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, |
6908 | "Length of Public Names Info"); | |
2e4b9b8c | 6909 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
2e4b9b8c RH |
6910 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
6911 | "Offset of Compilation Unit Info"); | |
2e4b9b8c RH |
6912 | dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset, |
6913 | "Compilation Unit Length"); | |
71dfc51f | 6914 | |
2ad9852d | 6915 | for (i = 0; i < pubname_table_in_use; i++) |
a3f97cbb | 6916 | { |
b3694847 | 6917 | pubname_ref pub = &pubname_table[i]; |
71dfc51f | 6918 | |
881c6935 | 6919 | /* We shouldn't see pubnames for DIEs outside of the main CU. */ |
1bfb5f8f | 6920 | if (pub->die->die_mark == 0) |
881c6935 JM |
6921 | abort (); |
6922 | ||
2e4b9b8c RH |
6923 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset, |
6924 | "DIE offset"); | |
71dfc51f | 6925 | |
2e4b9b8c | 6926 | dw2_asm_output_nstring (pub->name, -1, "external name"); |
a3f97cbb | 6927 | } |
71dfc51f | 6928 | |
2e4b9b8c | 6929 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL); |
a3f97cbb JW |
6930 | } |
6931 | ||
d291dd49 | 6932 | /* Add a new entry to .debug_aranges if appropriate. */ |
71dfc51f | 6933 | |
d291dd49 JM |
6934 | static void |
6935 | add_arange (decl, die) | |
6936 | tree decl; | |
6937 | dw_die_ref die; | |
6938 | { | |
6939 | if (! DECL_SECTION_NAME (decl)) | |
6940 | return; | |
6941 | ||
6942 | if (arange_table_in_use == arange_table_allocated) | |
6943 | { | |
6944 | arange_table_allocated += ARANGE_TABLE_INCREMENT; | |
a20612aa RH |
6945 | arange_table = (dw_die_ref *) |
6946 | xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref)); | |
d291dd49 | 6947 | } |
71dfc51f | 6948 | |
d291dd49 JM |
6949 | arange_table[arange_table_in_use++] = die; |
6950 | } | |
6951 | ||
a3f97cbb JW |
6952 | /* Output the information that goes into the .debug_aranges table. |
6953 | Namely, define the beginning and ending address range of the | |
6954 | text section generated for this compilation unit. */ | |
71dfc51f | 6955 | |
a3f97cbb JW |
6956 | static void |
6957 | output_aranges () | |
6958 | { | |
b3694847 SS |
6959 | unsigned i; |
6960 | unsigned long aranges_length = size_of_aranges (); | |
71dfc51f | 6961 | |
2e4b9b8c RH |
6962 | dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length, |
6963 | "Length of Address Ranges Info"); | |
2e4b9b8c | 6964 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
2e4b9b8c RH |
6965 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
6966 | "Offset of Compilation Unit Info"); | |
2e4b9b8c | 6967 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address"); |
2e4b9b8c | 6968 | dw2_asm_output_data (1, 0, "Size of Segment Descriptor"); |
71dfc51f | 6969 | |
262b6384 SC |
6970 | /* We need to align to twice the pointer size here. */ |
6971 | if (DWARF_ARANGES_PAD_SIZE) | |
6972 | { | |
2e4b9b8c RH |
6973 | /* Pad using a 2 byte words so that padding is correct for any |
6974 | pointer size. */ | |
6975 | dw2_asm_output_data (2, 0, "Pad to %d byte boundary", | |
6976 | 2 * DWARF2_ADDR_SIZE); | |
770ca8c6 | 6977 | for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2) |
2e4b9b8c | 6978 | dw2_asm_output_data (2, 0, NULL); |
262b6384 | 6979 | } |
71dfc51f | 6980 | |
8e7fa2c8 | 6981 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address"); |
2e4b9b8c RH |
6982 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label, |
6983 | text_section_label, "Length"); | |
71dfc51f | 6984 | |
2ad9852d | 6985 | for (i = 0; i < arange_table_in_use; i++) |
d291dd49 | 6986 | { |
e689ae67 | 6987 | dw_die_ref die = arange_table[i]; |
71dfc51f | 6988 | |
881c6935 | 6989 | /* We shouldn't see aranges for DIEs outside of the main CU. */ |
1bfb5f8f | 6990 | if (die->die_mark == 0) |
881c6935 JM |
6991 | abort (); |
6992 | ||
e689ae67 | 6993 | if (die->die_tag == DW_TAG_subprogram) |
2e4b9b8c | 6994 | { |
8e7fa2c8 | 6995 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die), |
173bf5be | 6996 | "Address"); |
2e4b9b8c RH |
6997 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die), |
6998 | get_AT_low_pc (die), "Length"); | |
6999 | } | |
d291dd49 | 7000 | else |
a1d7ffe3 | 7001 | { |
e689ae67 JM |
7002 | /* A static variable; extract the symbol from DW_AT_location. |
7003 | Note that this code isn't currently hit, as we only emit | |
7004 | aranges for functions (jason 9/23/99). */ | |
e689ae67 JM |
7005 | dw_attr_ref a = get_AT (die, DW_AT_location); |
7006 | dw_loc_descr_ref loc; | |
2ad9852d | 7007 | |
a96c67ec | 7008 | if (! a || AT_class (a) != dw_val_class_loc) |
e689ae67 JM |
7009 | abort (); |
7010 | ||
a96c67ec | 7011 | loc = AT_loc (a); |
e689ae67 JM |
7012 | if (loc->dw_loc_opc != DW_OP_addr) |
7013 | abort (); | |
7014 | ||
2e4b9b8c RH |
7015 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, |
7016 | loc->dw_loc_oprnd1.v.val_addr, "Address"); | |
7017 | dw2_asm_output_data (DWARF2_ADDR_SIZE, | |
7018 | get_AT_unsigned (die, DW_AT_byte_size), | |
7019 | "Length"); | |
a1d7ffe3 | 7020 | } |
d291dd49 | 7021 | } |
71dfc51f | 7022 | |
a3f97cbb | 7023 | /* Output the terminator words. */ |
2e4b9b8c RH |
7024 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); |
7025 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
a3f97cbb JW |
7026 | } |
7027 | ||
a20612aa RH |
7028 | /* Add a new entry to .debug_ranges. Return the offset at which it |
7029 | was placed. */ | |
7030 | ||
7031 | static unsigned int | |
7032 | add_ranges (block) | |
7033 | tree block; | |
7034 | { | |
7035 | unsigned int in_use = ranges_table_in_use; | |
7036 | ||
7037 | if (in_use == ranges_table_allocated) | |
7038 | { | |
7039 | ranges_table_allocated += RANGES_TABLE_INCREMENT; | |
7040 | ranges_table = (dw_ranges_ref) | |
7041 | xrealloc (ranges_table, (ranges_table_allocated | |
7042 | * sizeof (struct dw_ranges_struct))); | |
7043 | } | |
7044 | ||
7045 | ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0); | |
7046 | ranges_table_in_use = in_use + 1; | |
7047 | ||
7048 | return in_use * 2 * DWARF2_ADDR_SIZE; | |
7049 | } | |
7050 | ||
7051 | static void | |
7052 | output_ranges () | |
7053 | { | |
b3694847 | 7054 | unsigned i; |
83182544 | 7055 | static const char *const start_fmt = "Offset 0x%x"; |
a20612aa RH |
7056 | const char *fmt = start_fmt; |
7057 | ||
2ad9852d | 7058 | for (i = 0; i < ranges_table_in_use; i++) |
a20612aa RH |
7059 | { |
7060 | int block_num = ranges_table[i].block_num; | |
7061 | ||
7062 | if (block_num) | |
7063 | { | |
7064 | char blabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
7065 | char elabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
7066 | ||
7067 | ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num); | |
7068 | ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num); | |
7069 | ||
7070 | /* If all code is in the text section, then the compilation | |
7071 | unit base address defaults to DW_AT_low_pc, which is the | |
7072 | base of the text section. */ | |
7073 | if (separate_line_info_table_in_use == 0) | |
7074 | { | |
7075 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel, | |
7076 | text_section_label, | |
7077 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
7078 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel, | |
7079 | text_section_label, NULL); | |
7080 | } | |
2ad9852d | 7081 | |
a20612aa RH |
7082 | /* Otherwise, we add a DW_AT_entry_pc attribute to force the |
7083 | compilation unit base address to zero, which allows us to | |
7084 | use absolute addresses, and not worry about whether the | |
7085 | target supports cross-section arithmetic. */ | |
7086 | else | |
7087 | { | |
7088 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel, | |
7089 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
7090 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL); | |
7091 | } | |
7092 | ||
7093 | fmt = NULL; | |
7094 | } | |
7095 | else | |
7096 | { | |
7097 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
7098 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
7099 | fmt = start_fmt; | |
7100 | } | |
7101 | } | |
7102 | } | |
0b34cf1e UD |
7103 | |
7104 | /* Data structure containing information about input files. */ | |
7105 | struct file_info | |
7106 | { | |
7107 | char *path; /* Complete file name. */ | |
7108 | char *fname; /* File name part. */ | |
7109 | int length; /* Length of entire string. */ | |
7110 | int file_idx; /* Index in input file table. */ | |
7111 | int dir_idx; /* Index in directory table. */ | |
7112 | }; | |
7113 | ||
7114 | /* Data structure containing information about directories with source | |
7115 | files. */ | |
7116 | struct dir_info | |
7117 | { | |
7118 | char *path; /* Path including directory name. */ | |
7119 | int length; /* Path length. */ | |
7120 | int prefix; /* Index of directory entry which is a prefix. */ | |
0b34cf1e UD |
7121 | int count; /* Number of files in this directory. */ |
7122 | int dir_idx; /* Index of directory used as base. */ | |
7123 | int used; /* Used in the end? */ | |
7124 | }; | |
7125 | ||
7126 | /* Callback function for file_info comparison. We sort by looking at | |
7127 | the directories in the path. */ | |
356b0698 | 7128 | |
0b34cf1e UD |
7129 | static int |
7130 | file_info_cmp (p1, p2) | |
7131 | const void *p1; | |
7132 | const void *p2; | |
7133 | { | |
7134 | const struct file_info *s1 = p1; | |
7135 | const struct file_info *s2 = p2; | |
7136 | unsigned char *cp1; | |
7137 | unsigned char *cp2; | |
7138 | ||
356b0698 RK |
7139 | /* Take care of file names without directories. We need to make sure that |
7140 | we return consistent values to qsort since some will get confused if | |
7141 | we return the same value when identical operands are passed in opposite | |
7142 | orders. So if neither has a directory, return 0 and otherwise return | |
7143 | 1 or -1 depending on which one has the directory. */ | |
7144 | if ((s1->path == s1->fname || s2->path == s2->fname)) | |
7145 | return (s2->path == s2->fname) - (s1->path == s1->fname); | |
0b34cf1e UD |
7146 | |
7147 | cp1 = (unsigned char *) s1->path; | |
7148 | cp2 = (unsigned char *) s2->path; | |
7149 | ||
7150 | while (1) | |
7151 | { | |
7152 | ++cp1; | |
7153 | ++cp2; | |
356b0698 RK |
7154 | /* Reached the end of the first path? If so, handle like above. */ |
7155 | if ((cp1 == (unsigned char *) s1->fname) | |
7156 | || (cp2 == (unsigned char *) s2->fname)) | |
7157 | return ((cp2 == (unsigned char *) s2->fname) | |
7158 | - (cp1 == (unsigned char *) s1->fname)); | |
0b34cf1e UD |
7159 | |
7160 | /* Character of current path component the same? */ | |
356b0698 | 7161 | else if (*cp1 != *cp2) |
0b34cf1e UD |
7162 | return *cp1 - *cp2; |
7163 | } | |
7164 | } | |
7165 | ||
7166 | /* Output the directory table and the file name table. We try to minimize | |
7167 | the total amount of memory needed. A heuristic is used to avoid large | |
7168 | slowdowns with many input files. */ | |
2ad9852d | 7169 | |
0b34cf1e UD |
7170 | static void |
7171 | output_file_names () | |
7172 | { | |
7173 | struct file_info *files; | |
7174 | struct dir_info *dirs; | |
7175 | int *saved; | |
7176 | int *savehere; | |
7177 | int *backmap; | |
7178 | int ndirs; | |
7179 | int idx_offset; | |
7180 | int i; | |
7181 | int idx; | |
7182 | ||
7183 | /* Allocate the various arrays we need. */ | |
981975b6 | 7184 | files = (struct file_info *) alloca (file_table.in_use |
0b34cf1e | 7185 | * sizeof (struct file_info)); |
981975b6 | 7186 | dirs = (struct dir_info *) alloca (file_table.in_use |
0b34cf1e UD |
7187 | * sizeof (struct dir_info)); |
7188 | ||
7189 | /* Sort the file names. */ | |
2ad9852d | 7190 | for (i = 1; i < (int) file_table.in_use; i++) |
0b34cf1e UD |
7191 | { |
7192 | char *f; | |
7193 | ||
7194 | /* Skip all leading "./". */ | |
981975b6 | 7195 | f = file_table.table[i]; |
0b34cf1e UD |
7196 | while (f[0] == '.' && f[1] == '/') |
7197 | f += 2; | |
7198 | ||
7199 | /* Create a new array entry. */ | |
7200 | files[i].path = f; | |
7201 | files[i].length = strlen (f); | |
7202 | files[i].file_idx = i; | |
7203 | ||
7204 | /* Search for the file name part. */ | |
7205 | f = strrchr (f, '/'); | |
7206 | files[i].fname = f == NULL ? files[i].path : f + 1; | |
7207 | } | |
2ad9852d | 7208 | |
981975b6 | 7209 | qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp); |
0b34cf1e UD |
7210 | |
7211 | /* Find all the different directories used. */ | |
7212 | dirs[0].path = files[1].path; | |
7213 | dirs[0].length = files[1].fname - files[1].path; | |
7214 | dirs[0].prefix = -1; | |
0b34cf1e UD |
7215 | dirs[0].count = 1; |
7216 | dirs[0].dir_idx = 0; | |
7217 | dirs[0].used = 0; | |
7218 | files[1].dir_idx = 0; | |
7219 | ndirs = 1; | |
7220 | ||
2ad9852d | 7221 | for (i = 2; i < (int) file_table.in_use; i++) |
0b34cf1e UD |
7222 | if (files[i].fname - files[i].path == dirs[ndirs - 1].length |
7223 | && memcmp (dirs[ndirs - 1].path, files[i].path, | |
7224 | dirs[ndirs - 1].length) == 0) | |
7225 | { | |
7226 | /* Same directory as last entry. */ | |
7227 | files[i].dir_idx = ndirs - 1; | |
0b34cf1e UD |
7228 | ++dirs[ndirs - 1].count; |
7229 | } | |
7230 | else | |
7231 | { | |
7232 | int j; | |
7233 | ||
7234 | /* This is a new directory. */ | |
7235 | dirs[ndirs].path = files[i].path; | |
7236 | dirs[ndirs].length = files[i].fname - files[i].path; | |
0b34cf1e UD |
7237 | dirs[ndirs].count = 1; |
7238 | dirs[ndirs].dir_idx = ndirs; | |
7239 | dirs[ndirs].used = 0; | |
7240 | files[i].dir_idx = ndirs; | |
7241 | ||
7242 | /* Search for a prefix. */ | |
981975b6 | 7243 | dirs[ndirs].prefix = -1; |
2ad9852d | 7244 | for (j = 0; j < ndirs; j++) |
981975b6 RH |
7245 | if (dirs[j].length < dirs[ndirs].length |
7246 | && dirs[j].length > 1 | |
7247 | && (dirs[ndirs].prefix == -1 | |
7248 | || dirs[j].length > dirs[dirs[ndirs].prefix].length) | |
7249 | && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0) | |
7250 | dirs[ndirs].prefix = j; | |
0b34cf1e UD |
7251 | |
7252 | ++ndirs; | |
7253 | } | |
7254 | ||
2ad9852d RK |
7255 | /* Now to the actual work. We have to find a subset of the directories which |
7256 | allow expressing the file name using references to the directory table | |
7257 | with the least amount of characters. We do not do an exhaustive search | |
7258 | where we would have to check out every combination of every single | |
7259 | possible prefix. Instead we use a heuristic which provides nearly optimal | |
7260 | results in most cases and never is much off. */ | |
0b34cf1e UD |
7261 | saved = (int *) alloca (ndirs * sizeof (int)); |
7262 | savehere = (int *) alloca (ndirs * sizeof (int)); | |
7263 | ||
7264 | memset (saved, '\0', ndirs * sizeof (saved[0])); | |
2ad9852d | 7265 | for (i = 0; i < ndirs; i++) |
0b34cf1e UD |
7266 | { |
7267 | int j; | |
7268 | int total; | |
7269 | ||
2ad9852d RK |
7270 | /* We can always save some space for the current directory. But this |
7271 | does not mean it will be enough to justify adding the directory. */ | |
0b34cf1e UD |
7272 | savehere[i] = dirs[i].length; |
7273 | total = (savehere[i] - saved[i]) * dirs[i].count; | |
7274 | ||
2ad9852d | 7275 | for (j = i + 1; j < ndirs; j++) |
0b34cf1e UD |
7276 | { |
7277 | savehere[j] = 0; | |
0b34cf1e UD |
7278 | if (saved[j] < dirs[i].length) |
7279 | { | |
7280 | /* Determine whether the dirs[i] path is a prefix of the | |
7281 | dirs[j] path. */ | |
7282 | int k; | |
7283 | ||
981975b6 RH |
7284 | k = dirs[j].prefix; |
7285 | while (k != -1 && k != i) | |
7286 | k = dirs[k].prefix; | |
7287 | ||
7288 | if (k == i) | |
7289 | { | |
7290 | /* Yes it is. We can possibly safe some memory but | |
7291 | writing the filenames in dirs[j] relative to | |
7292 | dirs[i]. */ | |
7293 | savehere[j] = dirs[i].length; | |
7294 | total += (savehere[j] - saved[j]) * dirs[j].count; | |
7295 | } | |
0b34cf1e UD |
7296 | } |
7297 | } | |
7298 | ||
7299 | /* Check whether we can safe enough to justify adding the dirs[i] | |
7300 | directory. */ | |
7301 | if (total > dirs[i].length + 1) | |
7302 | { | |
981975b6 | 7303 | /* It's worthwhile adding. */ |
c26fbbca | 7304 | for (j = i; j < ndirs; j++) |
0b34cf1e UD |
7305 | if (savehere[j] > 0) |
7306 | { | |
7307 | /* Remember how much we saved for this directory so far. */ | |
7308 | saved[j] = savehere[j]; | |
7309 | ||
7310 | /* Remember the prefix directory. */ | |
7311 | dirs[j].dir_idx = i; | |
7312 | } | |
7313 | } | |
7314 | } | |
7315 | ||
2ad9852d RK |
7316 | /* We have to emit them in the order they appear in the file_table array |
7317 | since the index is used in the debug info generation. To do this | |
7318 | efficiently we generate a back-mapping of the indices first. */ | |
981975b6 | 7319 | backmap = (int *) alloca (file_table.in_use * sizeof (int)); |
2ad9852d | 7320 | for (i = 1; i < (int) file_table.in_use; i++) |
0b34cf1e UD |
7321 | { |
7322 | backmap[files[i].file_idx] = i; | |
2ad9852d | 7323 | |
0b34cf1e UD |
7324 | /* Mark this directory as used. */ |
7325 | dirs[dirs[files[i].dir_idx].dir_idx].used = 1; | |
7326 | } | |
7327 | ||
2ad9852d RK |
7328 | /* That was it. We are ready to emit the information. First emit the |
7329 | directory name table. We have to make sure the first actually emitted | |
7330 | directory name has index one; zero is reserved for the current working | |
7331 | directory. Make sure we do not confuse these indices with the one for the | |
7332 | constructed table (even though most of the time they are identical). */ | |
0b34cf1e | 7333 | idx = 1; |
e57cabac | 7334 | idx_offset = dirs[0].length > 0 ? 1 : 0; |
2ad9852d | 7335 | for (i = 1 - idx_offset; i < ndirs; i++) |
0b34cf1e UD |
7336 | if (dirs[i].used != 0) |
7337 | { | |
7338 | dirs[i].used = idx++; | |
2e4b9b8c RH |
7339 | dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1, |
7340 | "Directory Entry: 0x%x", dirs[i].used); | |
0b34cf1e | 7341 | } |
2ad9852d | 7342 | |
2e4b9b8c RH |
7343 | dw2_asm_output_data (1, 0, "End directory table"); |
7344 | ||
0b34cf1e UD |
7345 | /* Correct the index for the current working directory entry if it |
7346 | exists. */ | |
7347 | if (idx_offset == 0) | |
7348 | dirs[0].used = 0; | |
0b34cf1e UD |
7349 | |
7350 | /* Now write all the file names. */ | |
2ad9852d | 7351 | for (i = 1; i < (int) file_table.in_use; i++) |
0b34cf1e UD |
7352 | { |
7353 | int file_idx = backmap[i]; | |
7354 | int dir_idx = dirs[files[file_idx].dir_idx].dir_idx; | |
7355 | ||
2e4b9b8c RH |
7356 | dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1, |
7357 | "File Entry: 0x%x", i); | |
0b34cf1e UD |
7358 | |
7359 | /* Include directory index. */ | |
2e4b9b8c | 7360 | dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL); |
0b34cf1e UD |
7361 | |
7362 | /* Modification time. */ | |
2e4b9b8c | 7363 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e UD |
7364 | |
7365 | /* File length in bytes. */ | |
2e4b9b8c | 7366 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e | 7367 | } |
2ad9852d | 7368 | |
2e4b9b8c | 7369 | dw2_asm_output_data (1, 0, "End file name table"); |
0b34cf1e UD |
7370 | } |
7371 | ||
7372 | ||
a3f97cbb | 7373 | /* Output the source line number correspondence information. This |
14a774a9 | 7374 | information goes into the .debug_line section. */ |
71dfc51f | 7375 | |
a3f97cbb JW |
7376 | static void |
7377 | output_line_info () | |
7378 | { | |
981975b6 | 7379 | char l1[20], l2[20], p1[20], p2[20]; |
a3f97cbb JW |
7380 | char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
7381 | char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 SS |
7382 | unsigned opc; |
7383 | unsigned n_op_args; | |
7384 | unsigned long lt_index; | |
7385 | unsigned long current_line; | |
7386 | long line_offset; | |
7387 | long line_delta; | |
7388 | unsigned long current_file; | |
7389 | unsigned long function; | |
71dfc51f | 7390 | |
2e4b9b8c RH |
7391 | ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0); |
7392 | ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0); | |
981975b6 RH |
7393 | ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0); |
7394 | ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0); | |
71dfc51f | 7395 | |
2e4b9b8c RH |
7396 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1, |
7397 | "Length of Source Line Info"); | |
7398 | ASM_OUTPUT_LABEL (asm_out_file, l1); | |
71dfc51f | 7399 | |
2e4b9b8c | 7400 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
981975b6 RH |
7401 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length"); |
7402 | ASM_OUTPUT_LABEL (asm_out_file, p1); | |
71dfc51f | 7403 | |
c1a046e5 TT |
7404 | /* Define the architecture-dependent minimum instruction length (in |
7405 | bytes). In this implementation of DWARF, this field is used for | |
7406 | information purposes only. Since GCC generates assembly language, | |
7407 | we have no a priori knowledge of how many instruction bytes are | |
7408 | generated for each source line, and therefore can use only the | |
7409 | DW_LNE_set_address and DW_LNS_fixed_advance_pc line information | |
7410 | commands. Accordingly, we fix this as `1', which is "correct | |
7411 | enough" for all architectures, and don't let the target override. */ | |
7412 | dw2_asm_output_data (1, 1, | |
2e4b9b8c | 7413 | "Minimum Instruction Length"); |
c1a046e5 | 7414 | |
2e4b9b8c RH |
7415 | dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START, |
7416 | "Default is_stmt_start flag"); | |
2e4b9b8c RH |
7417 | dw2_asm_output_data (1, DWARF_LINE_BASE, |
7418 | "Line Base Value (Special Opcodes)"); | |
2e4b9b8c RH |
7419 | dw2_asm_output_data (1, DWARF_LINE_RANGE, |
7420 | "Line Range Value (Special Opcodes)"); | |
2e4b9b8c RH |
7421 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE, |
7422 | "Special Opcode Base"); | |
71dfc51f | 7423 | |
2ad9852d | 7424 | for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++) |
a3f97cbb JW |
7425 | { |
7426 | switch (opc) | |
7427 | { | |
7428 | case DW_LNS_advance_pc: | |
7429 | case DW_LNS_advance_line: | |
7430 | case DW_LNS_set_file: | |
7431 | case DW_LNS_set_column: | |
7432 | case DW_LNS_fixed_advance_pc: | |
7433 | n_op_args = 1; | |
7434 | break; | |
7435 | default: | |
7436 | n_op_args = 0; | |
7437 | break; | |
7438 | } | |
2e4b9b8c RH |
7439 | |
7440 | dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args", | |
7441 | opc, n_op_args); | |
a3f97cbb | 7442 | } |
71dfc51f | 7443 | |
0b34cf1e UD |
7444 | /* Write out the information about the files we use. */ |
7445 | output_file_names (); | |
981975b6 | 7446 | ASM_OUTPUT_LABEL (asm_out_file, p2); |
a3f97cbb | 7447 | |
2f22d404 JM |
7448 | /* We used to set the address register to the first location in the text |
7449 | section here, but that didn't accomplish anything since we already | |
7450 | have a line note for the opening brace of the first function. */ | |
a3f97cbb JW |
7451 | |
7452 | /* Generate the line number to PC correspondence table, encoded as | |
7453 | a series of state machine operations. */ | |
7454 | current_file = 1; | |
7455 | current_line = 1; | |
8b790721 | 7456 | strcpy (prev_line_label, text_section_label); |
a3f97cbb JW |
7457 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) |
7458 | { | |
b3694847 | 7459 | dw_line_info_ref line_info = &line_info_table[lt_index]; |
2f22d404 | 7460 | |
10a11b75 JM |
7461 | #if 0 |
7462 | /* Disable this optimization for now; GDB wants to see two line notes | |
7463 | at the beginning of a function so it can find the end of the | |
7464 | prologue. */ | |
7465 | ||
2f22d404 JM |
7466 | /* Don't emit anything for redundant notes. Just updating the |
7467 | address doesn't accomplish anything, because we already assume | |
7468 | that anything after the last address is this line. */ | |
7469 | if (line_info->dw_line_num == current_line | |
7470 | && line_info->dw_file_num == current_file) | |
7471 | continue; | |
10a11b75 | 7472 | #endif |
71dfc51f | 7473 | |
2e4b9b8c RH |
7474 | /* Emit debug info for the address of the current line. |
7475 | ||
7476 | Unfortunately, we have little choice here currently, and must always | |
2ad9852d | 7477 | use the most general form. GCC does not know the address delta |
2e4b9b8c RH |
7478 | itself, so we can't use DW_LNS_advance_pc. Many ports do have length |
7479 | attributes which will give an upper bound on the address range. We | |
7480 | could perhaps use length attributes to determine when it is safe to | |
7481 | use DW_LNS_fixed_advance_pc. */ | |
7482 | ||
5c90448c | 7483 | ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index); |
f19a6894 JW |
7484 | if (0) |
7485 | { | |
7486 | /* This can handle deltas up to 0xffff. This takes 3 bytes. */ | |
2e4b9b8c RH |
7487 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7488 | "DW_LNS_fixed_advance_pc"); | |
7489 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7490 | } |
7491 | else | |
7492 | { | |
a1a4189d JB |
7493 | /* This can handle any delta. This takes |
7494 | 4+DWARF2_ADDR_SIZE bytes. */ | |
2e4b9b8c RH |
7495 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7496 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7497 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7498 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7499 | } |
2ad9852d | 7500 | |
f19a6894 JW |
7501 | strcpy (prev_line_label, line_label); |
7502 | ||
7503 | /* Emit debug info for the source file of the current line, if | |
7504 | different from the previous line. */ | |
a3f97cbb JW |
7505 | if (line_info->dw_file_num != current_file) |
7506 | { | |
7507 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
7508 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
7509 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
981975b6 | 7510 | file_table.table[current_file]); |
a3f97cbb | 7511 | } |
71dfc51f | 7512 | |
f19a6894 JW |
7513 | /* Emit debug info for the current line number, choosing the encoding |
7514 | that uses the least amount of space. */ | |
2f22d404 | 7515 | if (line_info->dw_line_num != current_line) |
a3f97cbb | 7516 | { |
2f22d404 JM |
7517 | line_offset = line_info->dw_line_num - current_line; |
7518 | line_delta = line_offset - DWARF_LINE_BASE; | |
7519 | current_line = line_info->dw_line_num; | |
7520 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
2ad9852d RK |
7521 | /* This can handle deltas from -10 to 234, using the current |
7522 | definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This | |
7523 | takes 1 byte. */ | |
7524 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, | |
7525 | "line %lu", current_line); | |
2f22d404 JM |
7526 | else |
7527 | { | |
7528 | /* This can handle any delta. This takes at least 4 bytes, | |
7529 | depending on the value being encoded. */ | |
2e4b9b8c RH |
7530 | dw2_asm_output_data (1, DW_LNS_advance_line, |
7531 | "advance to line %lu", current_line); | |
7532 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
7533 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
2f22d404 | 7534 | } |
a94dbf2c JM |
7535 | } |
7536 | else | |
2ad9852d RK |
7537 | /* We still need to start a new row, so output a copy insn. */ |
7538 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
a3f97cbb JW |
7539 | } |
7540 | ||
f19a6894 JW |
7541 | /* Emit debug info for the address of the end of the function. */ |
7542 | if (0) | |
7543 | { | |
2e4b9b8c RH |
7544 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7545 | "DW_LNS_fixed_advance_pc"); | |
7546 | dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL); | |
f19a6894 JW |
7547 | } |
7548 | else | |
7549 | { | |
2e4b9b8c RH |
7550 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7551 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7552 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7553 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL); |
f19a6894 | 7554 | } |
bdb669cb | 7555 | |
2e4b9b8c RH |
7556 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
7557 | dw2_asm_output_data_uleb128 (1, NULL); | |
7558 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
7559 | |
7560 | function = 0; | |
7561 | current_file = 1; | |
7562 | current_line = 1; | |
556273e0 | 7563 | for (lt_index = 0; lt_index < separate_line_info_table_in_use;) |
e90b62db | 7564 | { |
b3694847 | 7565 | dw_separate_line_info_ref line_info |
e90b62db | 7566 | = &separate_line_info_table[lt_index]; |
71dfc51f | 7567 | |
10a11b75 | 7568 | #if 0 |
2f22d404 JM |
7569 | /* Don't emit anything for redundant notes. */ |
7570 | if (line_info->dw_line_num == current_line | |
7571 | && line_info->dw_file_num == current_file | |
7572 | && line_info->function == function) | |
7573 | goto cont; | |
10a11b75 | 7574 | #endif |
2f22d404 | 7575 | |
f19a6894 JW |
7576 | /* Emit debug info for the address of the current line. If this is |
7577 | a new function, or the first line of a function, then we need | |
7578 | to handle it differently. */ | |
5c90448c JM |
7579 | ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL, |
7580 | lt_index); | |
e90b62db JM |
7581 | if (function != line_info->function) |
7582 | { | |
7583 | function = line_info->function; | |
71dfc51f | 7584 | |
e90b62db | 7585 | /* Set the address register to the first line in the function */ |
2e4b9b8c RH |
7586 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7587 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7588 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7589 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
e90b62db JM |
7590 | } |
7591 | else | |
7592 | { | |
f19a6894 JW |
7593 | /* ??? See the DW_LNS_advance_pc comment above. */ |
7594 | if (0) | |
7595 | { | |
2e4b9b8c RH |
7596 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7597 | "DW_LNS_fixed_advance_pc"); | |
7598 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7599 | } |
7600 | else | |
7601 | { | |
2e4b9b8c RH |
7602 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7603 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7604 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7605 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7606 | } |
e90b62db | 7607 | } |
2ad9852d | 7608 | |
f19a6894 | 7609 | strcpy (prev_line_label, line_label); |
71dfc51f | 7610 | |
f19a6894 JW |
7611 | /* Emit debug info for the source file of the current line, if |
7612 | different from the previous line. */ | |
e90b62db JM |
7613 | if (line_info->dw_file_num != current_file) |
7614 | { | |
7615 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
7616 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
7617 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
981975b6 | 7618 | file_table.table[current_file]); |
e90b62db | 7619 | } |
71dfc51f | 7620 | |
f19a6894 JW |
7621 | /* Emit debug info for the current line number, choosing the encoding |
7622 | that uses the least amount of space. */ | |
e90b62db JM |
7623 | if (line_info->dw_line_num != current_line) |
7624 | { | |
7625 | line_offset = line_info->dw_line_num - current_line; | |
7626 | line_delta = line_offset - DWARF_LINE_BASE; | |
7627 | current_line = line_info->dw_line_num; | |
7628 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
2e4b9b8c RH |
7629 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, |
7630 | "line %lu", current_line); | |
e90b62db JM |
7631 | else |
7632 | { | |
2e4b9b8c RH |
7633 | dw2_asm_output_data (1, DW_LNS_advance_line, |
7634 | "advance to line %lu", current_line); | |
7635 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
7636 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
e90b62db JM |
7637 | } |
7638 | } | |
2f22d404 | 7639 | else |
2e4b9b8c | 7640 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); |
71dfc51f | 7641 | |
10a11b75 | 7642 | #if 0 |
2f22d404 | 7643 | cont: |
10a11b75 | 7644 | #endif |
2ad9852d RK |
7645 | |
7646 | lt_index++; | |
e90b62db JM |
7647 | |
7648 | /* If we're done with a function, end its sequence. */ | |
7649 | if (lt_index == separate_line_info_table_in_use | |
7650 | || separate_line_info_table[lt_index].function != function) | |
7651 | { | |
7652 | current_file = 1; | |
7653 | current_line = 1; | |
71dfc51f | 7654 | |
f19a6894 | 7655 | /* Emit debug info for the address of the end of the function. */ |
5c90448c | 7656 | ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function); |
f19a6894 JW |
7657 | if (0) |
7658 | { | |
2e4b9b8c RH |
7659 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7660 | "DW_LNS_fixed_advance_pc"); | |
7661 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7662 | } |
7663 | else | |
7664 | { | |
2e4b9b8c RH |
7665 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7666 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7667 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7668 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7669 | } |
e90b62db JM |
7670 | |
7671 | /* Output the marker for the end of this sequence. */ | |
2e4b9b8c RH |
7672 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
7673 | dw2_asm_output_data_uleb128 (1, NULL); | |
7674 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
7675 | } |
7676 | } | |
f19f17e0 JM |
7677 | |
7678 | /* Output the marker for the end of the line number info. */ | |
2e4b9b8c | 7679 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
a3f97cbb JW |
7680 | } |
7681 | \f | |
a3f97cbb JW |
7682 | /* Given a pointer to a tree node for some base type, return a pointer to |
7683 | a DIE that describes the given type. | |
7684 | ||
7685 | This routine must only be called for GCC type nodes that correspond to | |
7686 | Dwarf base (fundamental) types. */ | |
71dfc51f | 7687 | |
a3f97cbb JW |
7688 | static dw_die_ref |
7689 | base_type_die (type) | |
b3694847 | 7690 | tree type; |
a3f97cbb | 7691 | { |
b3694847 SS |
7692 | dw_die_ref base_type_result; |
7693 | const char *type_name; | |
7694 | enum dwarf_type encoding; | |
7695 | tree name = TYPE_NAME (type); | |
a3f97cbb | 7696 | |
2ad9852d | 7697 | if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE) |
a3f97cbb JW |
7698 | return 0; |
7699 | ||
405f63da MM |
7700 | if (name) |
7701 | { | |
7702 | if (TREE_CODE (name) == TYPE_DECL) | |
7703 | name = DECL_NAME (name); | |
7704 | ||
7705 | type_name = IDENTIFIER_POINTER (name); | |
7706 | } | |
7707 | else | |
7708 | type_name = "__unknown__"; | |
a9d38797 | 7709 | |
a3f97cbb JW |
7710 | switch (TREE_CODE (type)) |
7711 | { | |
a3f97cbb | 7712 | case INTEGER_TYPE: |
a9d38797 | 7713 | /* Carefully distinguish the C character types, without messing |
a3f97cbb | 7714 | up if the language is not C. Note that we check only for the names |
556273e0 | 7715 | that contain spaces; other names might occur by coincidence in other |
a3f97cbb | 7716 | languages. */ |
a9d38797 JM |
7717 | if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE |
7718 | && (type == char_type_node | |
7719 | || ! strcmp (type_name, "signed char") | |
7720 | || ! strcmp (type_name, "unsigned char")))) | |
a3f97cbb | 7721 | { |
a9d38797 JM |
7722 | if (TREE_UNSIGNED (type)) |
7723 | encoding = DW_ATE_unsigned; | |
7724 | else | |
7725 | encoding = DW_ATE_signed; | |
7726 | break; | |
a3f97cbb | 7727 | } |
556273e0 | 7728 | /* else fall through. */ |
a3f97cbb | 7729 | |
a9d38797 JM |
7730 | case CHAR_TYPE: |
7731 | /* GNU Pascal/Ada CHAR type. Not used in C. */ | |
7732 | if (TREE_UNSIGNED (type)) | |
7733 | encoding = DW_ATE_unsigned_char; | |
7734 | else | |
7735 | encoding = DW_ATE_signed_char; | |
a3f97cbb JW |
7736 | break; |
7737 | ||
7738 | case REAL_TYPE: | |
a9d38797 | 7739 | encoding = DW_ATE_float; |
a3f97cbb JW |
7740 | break; |
7741 | ||
405f63da MM |
7742 | /* Dwarf2 doesn't know anything about complex ints, so use |
7743 | a user defined type for it. */ | |
a3f97cbb | 7744 | case COMPLEX_TYPE: |
405f63da MM |
7745 | if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE) |
7746 | encoding = DW_ATE_complex_float; | |
7747 | else | |
7748 | encoding = DW_ATE_lo_user; | |
a3f97cbb JW |
7749 | break; |
7750 | ||
7751 | case BOOLEAN_TYPE: | |
a9d38797 JM |
7752 | /* GNU FORTRAN/Ada/C++ BOOLEAN type. */ |
7753 | encoding = DW_ATE_boolean; | |
a3f97cbb JW |
7754 | break; |
7755 | ||
7756 | default: | |
2ad9852d RK |
7757 | /* No other TREE_CODEs are Dwarf fundamental types. */ |
7758 | abort (); | |
a3f97cbb JW |
7759 | } |
7760 | ||
54ba1f0d | 7761 | base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type); |
14a774a9 RK |
7762 | if (demangle_name_func) |
7763 | type_name = (*demangle_name_func) (type_name); | |
7764 | ||
a9d38797 JM |
7765 | add_AT_string (base_type_result, DW_AT_name, type_name); |
7766 | add_AT_unsigned (base_type_result, DW_AT_byte_size, | |
4e5a8d7b | 7767 | int_size_in_bytes (type)); |
a9d38797 | 7768 | add_AT_unsigned (base_type_result, DW_AT_encoding, encoding); |
a3f97cbb JW |
7769 | |
7770 | return base_type_result; | |
7771 | } | |
7772 | ||
7773 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to | |
7774 | the Dwarf "root" type for the given input type. The Dwarf "root" type of | |
7775 | a given type is generally the same as the given type, except that if the | |
7776 | given type is a pointer or reference type, then the root type of the given | |
7777 | type is the root type of the "basis" type for the pointer or reference | |
7778 | type. (This definition of the "root" type is recursive.) Also, the root | |
7779 | type of a `const' qualified type or a `volatile' qualified type is the | |
7780 | root type of the given type without the qualifiers. */ | |
71dfc51f | 7781 | |
a3f97cbb JW |
7782 | static tree |
7783 | root_type (type) | |
b3694847 | 7784 | tree type; |
a3f97cbb JW |
7785 | { |
7786 | if (TREE_CODE (type) == ERROR_MARK) | |
7787 | return error_mark_node; | |
7788 | ||
7789 | switch (TREE_CODE (type)) | |
7790 | { | |
7791 | case ERROR_MARK: | |
7792 | return error_mark_node; | |
7793 | ||
7794 | case POINTER_TYPE: | |
7795 | case REFERENCE_TYPE: | |
7796 | return type_main_variant (root_type (TREE_TYPE (type))); | |
7797 | ||
7798 | default: | |
7799 | return type_main_variant (type); | |
7800 | } | |
7801 | } | |
7802 | ||
cc2902df | 7803 | /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the |
a3f97cbb | 7804 | given input type is a Dwarf "fundamental" type. Otherwise return null. */ |
71dfc51f RK |
7805 | |
7806 | static inline int | |
a3f97cbb | 7807 | is_base_type (type) |
b3694847 | 7808 | tree type; |
a3f97cbb JW |
7809 | { |
7810 | switch (TREE_CODE (type)) | |
7811 | { | |
7812 | case ERROR_MARK: | |
7813 | case VOID_TYPE: | |
7814 | case INTEGER_TYPE: | |
7815 | case REAL_TYPE: | |
7816 | case COMPLEX_TYPE: | |
7817 | case BOOLEAN_TYPE: | |
7818 | case CHAR_TYPE: | |
7819 | return 1; | |
7820 | ||
7821 | case SET_TYPE: | |
7822 | case ARRAY_TYPE: | |
7823 | case RECORD_TYPE: | |
7824 | case UNION_TYPE: | |
7825 | case QUAL_UNION_TYPE: | |
7826 | case ENUMERAL_TYPE: | |
7827 | case FUNCTION_TYPE: | |
7828 | case METHOD_TYPE: | |
7829 | case POINTER_TYPE: | |
7830 | case REFERENCE_TYPE: | |
7831 | case FILE_TYPE: | |
7832 | case OFFSET_TYPE: | |
7833 | case LANG_TYPE: | |
604bb87d | 7834 | case VECTOR_TYPE: |
a3f97cbb JW |
7835 | return 0; |
7836 | ||
7837 | default: | |
7838 | abort (); | |
7839 | } | |
71dfc51f | 7840 | |
a3f97cbb JW |
7841 | return 0; |
7842 | } | |
7843 | ||
4977bab6 ZW |
7844 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE |
7845 | node, return the size in bits for the type if it is a constant, or else | |
7846 | return the alignment for the type if the type's size is not constant, or | |
7847 | else return BITS_PER_WORD if the type actually turns out to be an | |
7848 | ERROR_MARK node. */ | |
7849 | ||
7850 | static inline unsigned HOST_WIDE_INT | |
7851 | simple_type_size_in_bits (type) | |
7852 | tree type; | |
7853 | { | |
7854 | ||
7855 | if (TREE_CODE (type) == ERROR_MARK) | |
7856 | return BITS_PER_WORD; | |
7857 | else if (TYPE_SIZE (type) == NULL_TREE) | |
7858 | return 0; | |
7859 | else if (host_integerp (TYPE_SIZE (type), 1)) | |
7860 | return tree_low_cst (TYPE_SIZE (type), 1); | |
7861 | else | |
7862 | return TYPE_ALIGN (type); | |
7863 | } | |
7864 | ||
a3f97cbb JW |
7865 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging |
7866 | entry that chains various modifiers in front of the given type. */ | |
71dfc51f | 7867 | |
a3f97cbb JW |
7868 | static dw_die_ref |
7869 | modified_type_die (type, is_const_type, is_volatile_type, context_die) | |
b3694847 SS |
7870 | tree type; |
7871 | int is_const_type; | |
7872 | int is_volatile_type; | |
7873 | dw_die_ref context_die; | |
a3f97cbb | 7874 | { |
b3694847 SS |
7875 | enum tree_code code = TREE_CODE (type); |
7876 | dw_die_ref mod_type_die = NULL; | |
7877 | dw_die_ref sub_die = NULL; | |
7878 | tree item_type = NULL; | |
a3f97cbb JW |
7879 | |
7880 | if (code != ERROR_MARK) | |
7881 | { | |
5101b304 MM |
7882 | tree qualified_type; |
7883 | ||
7884 | /* See if we already have the appropriately qualified variant of | |
7885 | this type. */ | |
c26fbbca | 7886 | qualified_type |
5101b304 MM |
7887 | = get_qualified_type (type, |
7888 | ((is_const_type ? TYPE_QUAL_CONST : 0) | |
c26fbbca | 7889 | | (is_volatile_type |
5101b304 | 7890 | ? TYPE_QUAL_VOLATILE : 0))); |
2ad9852d | 7891 | |
5101b304 MM |
7892 | /* If we do, then we can just use its DIE, if it exists. */ |
7893 | if (qualified_type) | |
7894 | { | |
7895 | mod_type_die = lookup_type_die (qualified_type); | |
7896 | if (mod_type_die) | |
7897 | return mod_type_die; | |
7898 | } | |
bdb669cb | 7899 | |
556273e0 | 7900 | /* Handle C typedef types. */ |
c26fbbca | 7901 | if (qualified_type && TYPE_NAME (qualified_type) |
5101b304 MM |
7902 | && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL |
7903 | && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type))) | |
a94dbf2c | 7904 | { |
5101b304 MM |
7905 | tree type_name = TYPE_NAME (qualified_type); |
7906 | tree dtype = TREE_TYPE (type_name); | |
2ad9852d | 7907 | |
5101b304 | 7908 | if (qualified_type == dtype) |
a94dbf2c JM |
7909 | { |
7910 | /* For a named type, use the typedef. */ | |
5101b304 MM |
7911 | gen_type_die (qualified_type, context_die); |
7912 | mod_type_die = lookup_type_die (qualified_type); | |
a94dbf2c JM |
7913 | } |
7914 | else if (is_const_type < TYPE_READONLY (dtype) | |
7915 | || is_volatile_type < TYPE_VOLATILE (dtype)) | |
7916 | /* cv-unqualified version of named type. Just use the unnamed | |
7917 | type to which it refers. */ | |
71dfc51f | 7918 | mod_type_die |
5101b304 | 7919 | = modified_type_die (DECL_ORIGINAL_TYPE (type_name), |
71dfc51f RK |
7920 | is_const_type, is_volatile_type, |
7921 | context_die); | |
2ad9852d | 7922 | |
71dfc51f | 7923 | /* Else cv-qualified version of named type; fall through. */ |
a94dbf2c JM |
7924 | } |
7925 | ||
7926 | if (mod_type_die) | |
556273e0 KH |
7927 | /* OK. */ |
7928 | ; | |
a94dbf2c | 7929 | else if (is_const_type) |
a3f97cbb | 7930 | { |
54ba1f0d | 7931 | mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type); |
a9d38797 | 7932 | sub_die = modified_type_die (type, 0, is_volatile_type, context_die); |
a3f97cbb JW |
7933 | } |
7934 | else if (is_volatile_type) | |
7935 | { | |
54ba1f0d | 7936 | mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type); |
a9d38797 | 7937 | sub_die = modified_type_die (type, 0, 0, context_die); |
a3f97cbb JW |
7938 | } |
7939 | else if (code == POINTER_TYPE) | |
7940 | { | |
54ba1f0d | 7941 | mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type); |
4977bab6 ZW |
7942 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, |
7943 | simple_type_size_in_bits (type) / BITS_PER_UNIT); | |
61b32c02 | 7944 | #if 0 |
a3f97cbb | 7945 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
61b32c02 | 7946 | #endif |
a3f97cbb | 7947 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
7948 | } |
7949 | else if (code == REFERENCE_TYPE) | |
7950 | { | |
54ba1f0d | 7951 | mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type); |
4977bab6 ZW |
7952 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, |
7953 | simple_type_size_in_bits (type) / BITS_PER_UNIT); | |
61b32c02 | 7954 | #if 0 |
a3f97cbb | 7955 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
556273e0 | 7956 | #endif |
a3f97cbb | 7957 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
7958 | } |
7959 | else if (is_base_type (type)) | |
71dfc51f | 7960 | mod_type_die = base_type_die (type); |
a3f97cbb JW |
7961 | else |
7962 | { | |
4b674448 JM |
7963 | gen_type_die (type, context_die); |
7964 | ||
a3f97cbb JW |
7965 | /* We have to get the type_main_variant here (and pass that to the |
7966 | `lookup_type_die' routine) because the ..._TYPE node we have | |
7967 | might simply be a *copy* of some original type node (where the | |
7968 | copy was created to help us keep track of typedef names) and | |
7969 | that copy might have a different TYPE_UID from the original | |
a94dbf2c | 7970 | ..._TYPE node. */ |
0e98f924 AH |
7971 | if (TREE_CODE (type) != VECTOR_TYPE) |
7972 | mod_type_die = lookup_type_die (type_main_variant (type)); | |
7973 | else | |
7974 | /* Vectors have the debugging information in the type, | |
7975 | not the main variant. */ | |
7976 | mod_type_die = lookup_type_die (type); | |
3a88cbd1 JL |
7977 | if (mod_type_die == NULL) |
7978 | abort (); | |
a3f97cbb | 7979 | } |
3d2999ba MK |
7980 | |
7981 | /* We want to equate the qualified type to the die below. */ | |
8370aa3a | 7982 | type = qualified_type; |
a3f97cbb | 7983 | } |
71dfc51f | 7984 | |
8370aa3a RH |
7985 | if (type) |
7986 | equate_type_number_to_die (type, mod_type_die); | |
dfcf9891 | 7987 | if (item_type) |
71dfc51f RK |
7988 | /* We must do this after the equate_type_number_to_die call, in case |
7989 | this is a recursive type. This ensures that the modified_type_die | |
7990 | recursion will terminate even if the type is recursive. Recursive | |
7991 | types are possible in Ada. */ | |
7992 | sub_die = modified_type_die (item_type, | |
7993 | TYPE_READONLY (item_type), | |
7994 | TYPE_VOLATILE (item_type), | |
7995 | context_die); | |
7996 | ||
a3f97cbb | 7997 | if (sub_die != NULL) |
71dfc51f RK |
7998 | add_AT_die_ref (mod_type_die, DW_AT_type, sub_die); |
7999 | ||
a3f97cbb JW |
8000 | return mod_type_die; |
8001 | } | |
8002 | ||
a3f97cbb | 8003 | /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is |
6d2f8887 | 8004 | an enumerated type. */ |
71dfc51f RK |
8005 | |
8006 | static inline int | |
a3f97cbb | 8007 | type_is_enum (type) |
b3694847 | 8008 | tree type; |
a3f97cbb JW |
8009 | { |
8010 | return TREE_CODE (type) == ENUMERAL_TYPE; | |
8011 | } | |
8012 | ||
7d9d8943 AM |
8013 | /* Return the register number described by a given RTL node. */ |
8014 | ||
8015 | static unsigned int | |
8016 | reg_number (rtl) | |
b3694847 | 8017 | rtx rtl; |
7d9d8943 | 8018 | { |
b3694847 | 8019 | unsigned regno = REGNO (rtl); |
7d9d8943 AM |
8020 | |
8021 | if (regno >= FIRST_PSEUDO_REGISTER) | |
e7af1d45 | 8022 | abort (); |
7d9d8943 | 8023 | |
e7af1d45 | 8024 | return DBX_REGISTER_NUMBER (regno); |
7d9d8943 AM |
8025 | } |
8026 | ||
e7af1d45 RK |
8027 | /* Return a location descriptor that designates a machine register or |
8028 | zero if there is no such. */ | |
71dfc51f | 8029 | |
a3f97cbb JW |
8030 | static dw_loc_descr_ref |
8031 | reg_loc_descriptor (rtl) | |
b3694847 | 8032 | rtx rtl; |
a3f97cbb | 8033 | { |
b3694847 | 8034 | dw_loc_descr_ref loc_result = NULL; |
d22c2324 | 8035 | unsigned reg; |
71dfc51f | 8036 | |
e7af1d45 RK |
8037 | if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER) |
8038 | return 0; | |
8039 | ||
8040 | reg = reg_number (rtl); | |
d22c2324 TT |
8041 | if (reg <= 31) |
8042 | loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0); | |
8043 | else | |
8044 | loc_result = new_loc_descr (DW_OP_regx, reg, 0); | |
71dfc51f | 8045 | |
a3f97cbb JW |
8046 | return loc_result; |
8047 | } | |
8048 | ||
d8041cc8 RH |
8049 | /* Return a location descriptor that designates a constant. */ |
8050 | ||
8051 | static dw_loc_descr_ref | |
8052 | int_loc_descriptor (i) | |
8053 | HOST_WIDE_INT i; | |
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 JW |
8091 | static dw_loc_descr_ref |
8092 | based_loc_descr (reg, offset) | |
8093 | unsigned reg; | |
8094 | long int offset; | |
8095 | { | |
b3694847 | 8096 | dw_loc_descr_ref loc_result; |
810429b7 JM |
8097 | /* For the "frame base", we use the frame pointer or stack pointer |
8098 | registers, since the RTL for local variables is relative to one of | |
8099 | them. */ | |
b3694847 SS |
8100 | unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed |
8101 | ? HARD_FRAME_POINTER_REGNUM | |
8102 | : STACK_POINTER_REGNUM); | |
71dfc51f | 8103 | |
a3f97cbb | 8104 | if (reg == fp_reg) |
71dfc51f | 8105 | loc_result = new_loc_descr (DW_OP_fbreg, offset, 0); |
85066503 | 8106 | else if (reg <= 31) |
71dfc51f | 8107 | loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0); |
a3f97cbb | 8108 | else |
71dfc51f RK |
8109 | loc_result = new_loc_descr (DW_OP_bregx, reg, offset); |
8110 | ||
a3f97cbb JW |
8111 | return loc_result; |
8112 | } | |
8113 | ||
8114 | /* Return true if this RTL expression describes a base+offset calculation. */ | |
71dfc51f RK |
8115 | |
8116 | static inline int | |
a3f97cbb | 8117 | is_based_loc (rtl) |
b3694847 | 8118 | rtx rtl; |
a3f97cbb | 8119 | { |
173bf5be KH |
8120 | return (GET_CODE (rtl) == PLUS |
8121 | && ((GET_CODE (XEXP (rtl, 0)) == REG | |
8122 | && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER | |
8123 | && GET_CODE (XEXP (rtl, 1)) == CONST_INT))); | |
a3f97cbb JW |
8124 | } |
8125 | ||
8126 | /* The following routine converts the RTL for a variable or parameter | |
8127 | (resident in memory) into an equivalent Dwarf representation of a | |
8128 | mechanism for getting the address of that same variable onto the top of a | |
8129 | hypothetical "address evaluation" stack. | |
71dfc51f | 8130 | |
a3f97cbb JW |
8131 | When creating memory location descriptors, we are effectively transforming |
8132 | the RTL for a memory-resident object into its Dwarf postfix expression | |
8133 | equivalent. This routine recursively descends an RTL tree, turning | |
e60d4d7b JL |
8134 | it into Dwarf postfix code as it goes. |
8135 | ||
8136 | MODE is the mode of the memory reference, needed to handle some | |
e7af1d45 RK |
8137 | autoincrement addressing modes. |
8138 | ||
8139 | Return 0 if we can't represent the location. */ | |
71dfc51f | 8140 | |
a3f97cbb | 8141 | static dw_loc_descr_ref |
e60d4d7b | 8142 | mem_loc_descriptor (rtl, mode) |
b3694847 | 8143 | rtx rtl; |
e60d4d7b | 8144 | enum machine_mode mode; |
a3f97cbb JW |
8145 | { |
8146 | dw_loc_descr_ref mem_loc_result = NULL; | |
e7af1d45 | 8147 | |
556273e0 | 8148 | /* Note that for a dynamically sized array, the location we will generate a |
a3f97cbb JW |
8149 | description of here will be the lowest numbered location which is |
8150 | actually within the array. That's *not* necessarily the same as the | |
8151 | zeroth element of the array. */ | |
71dfc51f | 8152 | |
1865dbb5 JM |
8153 | #ifdef ASM_SIMPLIFY_DWARF_ADDR |
8154 | rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); | |
8155 | #endif | |
8156 | ||
a3f97cbb JW |
8157 | switch (GET_CODE (rtl)) |
8158 | { | |
e60d4d7b JL |
8159 | case POST_INC: |
8160 | case POST_DEC: | |
e2134eea | 8161 | case POST_MODIFY: |
e60d4d7b JL |
8162 | /* POST_INC and POST_DEC can be handled just like a SUBREG. So we |
8163 | just fall into the SUBREG code. */ | |
8164 | ||
2ad9852d | 8165 | /* ... fall through ... */ |
e60d4d7b | 8166 | |
a3f97cbb JW |
8167 | case SUBREG: |
8168 | /* The case of a subreg may arise when we have a local (register) | |
8169 | variable or a formal (register) parameter which doesn't quite fill | |
8170 | up an entire register. For now, just assume that it is | |
8171 | legitimate to make the Dwarf info refer to the whole register which | |
8172 | contains the given subreg. */ | |
ddef6bc7 | 8173 | rtl = SUBREG_REG (rtl); |
71dfc51f | 8174 | |
2ad9852d | 8175 | /* ... fall through ... */ |
a3f97cbb JW |
8176 | |
8177 | case REG: | |
8178 | /* Whenever a register number forms a part of the description of the | |
8179 | method for calculating the (dynamic) address of a memory resident | |
556273e0 | 8180 | object, DWARF rules require the register number be referred to as |
a3f97cbb JW |
8181 | a "base register". This distinction is not based in any way upon |
8182 | what category of register the hardware believes the given register | |
8183 | belongs to. This is strictly DWARF terminology we're dealing with | |
8184 | here. Note that in cases where the location of a memory-resident | |
8185 | data object could be expressed as: OP_ADD (OP_BASEREG (basereg), | |
8186 | OP_CONST (0)) the actual DWARF location descriptor that we generate | |
8187 | may just be OP_BASEREG (basereg). This may look deceptively like | |
8188 | the object in question was allocated to a register (rather than in | |
8189 | memory) so DWARF consumers need to be aware of the subtle | |
8190 | distinction between OP_REG and OP_BASEREG. */ | |
e7af1d45 RK |
8191 | if (REGNO (rtl) < FIRST_PSEUDO_REGISTER) |
8192 | mem_loc_result = based_loc_descr (reg_number (rtl), 0); | |
a3f97cbb JW |
8193 | break; |
8194 | ||
8195 | case MEM: | |
f7d2b0ed | 8196 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
e7af1d45 RK |
8197 | if (mem_loc_result != 0) |
8198 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0)); | |
a3f97cbb JW |
8199 | break; |
8200 | ||
d8041cc8 RH |
8201 | case LABEL_REF: |
8202 | /* Some ports can transform a symbol ref into a label ref, because | |
368f4cd6 NC |
8203 | the symbol ref is too far away and has to be dumped into a constant |
8204 | pool. */ | |
a3f97cbb JW |
8205 | case CONST: |
8206 | case SYMBOL_REF: | |
6331d1c1 | 8207 | /* Alternatively, the symbol in the constant pool might be referenced |
c6f9b9a1 | 8208 | by a different symbol. */ |
2ad9852d | 8209 | if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl)) |
79cdfa4b | 8210 | { |
149d6f9e JJ |
8211 | bool marked; |
8212 | rtx tmp = get_pool_constant_mark (rtl, &marked); | |
2ad9852d | 8213 | |
6331d1c1 | 8214 | if (GET_CODE (tmp) == SYMBOL_REF) |
149d6f9e JJ |
8215 | { |
8216 | rtl = tmp; | |
8217 | if (CONSTANT_POOL_ADDRESS_P (tmp)) | |
8218 | get_pool_constant_mark (tmp, &marked); | |
8219 | else | |
8220 | marked = true; | |
8221 | } | |
8222 | ||
8223 | /* If all references to this pool constant were optimized away, | |
8224 | it was not output and thus we can't represent it. | |
8225 | FIXME: might try to use DW_OP_const_value here, though | |
8226 | DW_OP_piece complicates it. */ | |
8227 | if (!marked) | |
8228 | return 0; | |
79cdfa4b TM |
8229 | } |
8230 | ||
a3f97cbb JW |
8231 | mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0); |
8232 | mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
c470afad RK |
8233 | mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl; |
8234 | VARRAY_PUSH_RTX (used_rtx_varray, rtl); | |
a3f97cbb JW |
8235 | break; |
8236 | ||
e2134eea JH |
8237 | case PRE_MODIFY: |
8238 | /* Extract the PLUS expression nested inside and fall into | |
0407c02b | 8239 | PLUS code below. */ |
e2134eea JH |
8240 | rtl = XEXP (rtl, 1); |
8241 | goto plus; | |
8242 | ||
e60d4d7b JL |
8243 | case PRE_INC: |
8244 | case PRE_DEC: | |
8245 | /* Turn these into a PLUS expression and fall into the PLUS code | |
8246 | below. */ | |
8247 | rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0), | |
8248 | GEN_INT (GET_CODE (rtl) == PRE_INC | |
556273e0 KH |
8249 | ? GET_MODE_UNIT_SIZE (mode) |
8250 | : -GET_MODE_UNIT_SIZE (mode))); | |
8251 | ||
2ad9852d | 8252 | /* ... fall through ... */ |
e60d4d7b | 8253 | |
a3f97cbb | 8254 | case PLUS: |
e2134eea | 8255 | plus: |
a3f97cbb | 8256 | if (is_based_loc (rtl)) |
71dfc51f RK |
8257 | mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)), |
8258 | INTVAL (XEXP (rtl, 1))); | |
a3f97cbb JW |
8259 | else |
8260 | { | |
d8041cc8 | 8261 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode); |
e7af1d45 RK |
8262 | if (mem_loc_result == 0) |
8263 | break; | |
d8041cc8 RH |
8264 | |
8265 | if (GET_CODE (XEXP (rtl, 1)) == CONST_INT | |
8266 | && INTVAL (XEXP (rtl, 1)) >= 0) | |
e7af1d45 RK |
8267 | add_loc_descr (&mem_loc_result, |
8268 | new_loc_descr (DW_OP_plus_uconst, | |
8269 | INTVAL (XEXP (rtl, 1)), 0)); | |
d8041cc8 RH |
8270 | else |
8271 | { | |
8272 | add_loc_descr (&mem_loc_result, | |
8273 | mem_loc_descriptor (XEXP (rtl, 1), mode)); | |
8274 | add_loc_descr (&mem_loc_result, | |
8275 | new_loc_descr (DW_OP_plus, 0, 0)); | |
8276 | } | |
a3f97cbb JW |
8277 | } |
8278 | break; | |
8279 | ||
dd2478ae | 8280 | case MULT: |
e7af1d45 RK |
8281 | { |
8282 | /* If a pseudo-reg is optimized away, it is possible for it to | |
8283 | be replaced with a MEM containing a multiply. */ | |
8284 | dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode); | |
8285 | dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode); | |
8286 | ||
8287 | if (op0 == 0 || op1 == 0) | |
8288 | break; | |
8289 | ||
8290 | mem_loc_result = op0; | |
8291 | add_loc_descr (&mem_loc_result, op1); | |
8292 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0)); | |
8293 | break; | |
8294 | } | |
dd2478ae | 8295 | |
a3f97cbb | 8296 | case CONST_INT: |
d8041cc8 | 8297 | mem_loc_result = int_loc_descriptor (INTVAL (rtl)); |
a3f97cbb JW |
8298 | break; |
8299 | ||
a9e8a5ee RK |
8300 | case ADDRESSOF: |
8301 | /* If this is a MEM, return its address. Otherwise, we can't | |
8302 | represent this. */ | |
8303 | if (GET_CODE (XEXP (rtl, 0)) == MEM) | |
8304 | return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode); | |
8305 | else | |
8306 | return 0; | |
8307 | ||
a3f97cbb JW |
8308 | default: |
8309 | abort (); | |
8310 | } | |
71dfc51f | 8311 | |
a3f97cbb JW |
8312 | return mem_loc_result; |
8313 | } | |
8314 | ||
956d6950 | 8315 | /* Return a descriptor that describes the concatenation of two locations. |
4401bf24 JL |
8316 | This is typically a complex variable. */ |
8317 | ||
8318 | static dw_loc_descr_ref | |
8319 | concat_loc_descriptor (x0, x1) | |
b3694847 | 8320 | rtx x0, x1; |
4401bf24 JL |
8321 | { |
8322 | dw_loc_descr_ref cc_loc_result = NULL; | |
e7af1d45 RK |
8323 | dw_loc_descr_ref x0_ref = loc_descriptor (x0); |
8324 | dw_loc_descr_ref x1_ref = loc_descriptor (x1); | |
4401bf24 | 8325 | |
e7af1d45 RK |
8326 | if (x0_ref == 0 || x1_ref == 0) |
8327 | return 0; | |
8328 | ||
8329 | cc_loc_result = x0_ref; | |
4401bf24 | 8330 | add_loc_descr (&cc_loc_result, |
e7af1d45 RK |
8331 | new_loc_descr (DW_OP_piece, |
8332 | GET_MODE_SIZE (GET_MODE (x0)), 0)); | |
4401bf24 | 8333 | |
e7af1d45 | 8334 | add_loc_descr (&cc_loc_result, x1_ref); |
4401bf24 | 8335 | add_loc_descr (&cc_loc_result, |
e7af1d45 RK |
8336 | new_loc_descr (DW_OP_piece, |
8337 | GET_MODE_SIZE (GET_MODE (x1)), 0)); | |
4401bf24 JL |
8338 | |
8339 | return cc_loc_result; | |
8340 | } | |
8341 | ||
a3f97cbb JW |
8342 | /* Output a proper Dwarf location descriptor for a variable or parameter |
8343 | which is either allocated in a register or in a memory location. For a | |
8344 | register, we just generate an OP_REG and the register number. For a | |
8345 | memory location we provide a Dwarf postfix expression describing how to | |
e7af1d45 RK |
8346 | generate the (dynamic) address of the object onto the address stack. |
8347 | ||
8348 | If we don't know how to describe it, return 0. */ | |
71dfc51f | 8349 | |
a3f97cbb JW |
8350 | static dw_loc_descr_ref |
8351 | loc_descriptor (rtl) | |
b3694847 | 8352 | rtx rtl; |
a3f97cbb JW |
8353 | { |
8354 | dw_loc_descr_ref loc_result = NULL; | |
e7af1d45 | 8355 | |
a3f97cbb JW |
8356 | switch (GET_CODE (rtl)) |
8357 | { | |
8358 | case SUBREG: | |
a3f97cbb JW |
8359 | /* The case of a subreg may arise when we have a local (register) |
8360 | variable or a formal (register) parameter which doesn't quite fill | |
71dfc51f | 8361 | up an entire register. For now, just assume that it is |
a3f97cbb JW |
8362 | legitimate to make the Dwarf info refer to the whole register which |
8363 | contains the given subreg. */ | |
ddef6bc7 | 8364 | rtl = SUBREG_REG (rtl); |
71dfc51f | 8365 | |
2ad9852d | 8366 | /* ... fall through ... */ |
a3f97cbb JW |
8367 | |
8368 | case REG: | |
5c90448c | 8369 | loc_result = reg_loc_descriptor (rtl); |
a3f97cbb JW |
8370 | break; |
8371 | ||
8372 | case MEM: | |
e60d4d7b | 8373 | loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
a3f97cbb JW |
8374 | break; |
8375 | ||
4401bf24 JL |
8376 | case CONCAT: |
8377 | loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1)); | |
8378 | break; | |
8379 | ||
a3f97cbb | 8380 | default: |
71dfc51f | 8381 | abort (); |
a3f97cbb | 8382 | } |
71dfc51f | 8383 | |
a3f97cbb JW |
8384 | return loc_result; |
8385 | } | |
8386 | ||
2ad9852d RK |
8387 | /* Similar, but generate the descriptor from trees instead of rtl. This comes |
8388 | up particularly with variable length arrays. If ADDRESSP is nonzero, we are | |
8389 | looking for an address. Otherwise, we return a value. If we can't make a | |
8390 | descriptor, return 0. */ | |
d8041cc8 RH |
8391 | |
8392 | static dw_loc_descr_ref | |
8393 | loc_descriptor_from_tree (loc, addressp) | |
8394 | tree loc; | |
8395 | int addressp; | |
8396 | { | |
e7af1d45 RK |
8397 | dw_loc_descr_ref ret, ret1; |
8398 | int indirect_p = 0; | |
d8041cc8 RH |
8399 | int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc)); |
8400 | enum dwarf_location_atom op; | |
8401 | ||
8402 | /* ??? Most of the time we do not take proper care for sign/zero | |
8403 | extending the values properly. Hopefully this won't be a real | |
8404 | problem... */ | |
8405 | ||
8406 | switch (TREE_CODE (loc)) | |
8407 | { | |
8408 | case ERROR_MARK: | |
e7af1d45 | 8409 | return 0; |
d8041cc8 | 8410 | |
b4ae5201 | 8411 | case WITH_RECORD_EXPR: |
e7af1d45 | 8412 | case PLACEHOLDER_EXPR: |
b4ae5201 RK |
8413 | /* This case involves extracting fields from an object to determine the |
8414 | position of other fields. We don't try to encode this here. The | |
8415 | only user of this is Ada, which encodes the needed information using | |
8416 | the names of types. */ | |
e7af1d45 | 8417 | return 0; |
b4ae5201 | 8418 | |
aea9695c RK |
8419 | case CALL_EXPR: |
8420 | return 0; | |
8421 | ||
8422 | case ADDR_EXPR: | |
8423 | /* We can support this only if we can look through conversions and | |
8424 | find an INDIRECT_EXPR. */ | |
8425 | for (loc = TREE_OPERAND (loc, 0); | |
8426 | TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR | |
8427 | || TREE_CODE (loc) == NON_LVALUE_EXPR | |
8428 | || TREE_CODE (loc) == VIEW_CONVERT_EXPR | |
8429 | || TREE_CODE (loc) == SAVE_EXPR; | |
8430 | loc = TREE_OPERAND (loc, 0)) | |
8431 | ; | |
8432 | ||
8433 | return (TREE_CODE (loc) == INDIRECT_REF | |
8434 | ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp) | |
8435 | : 0); | |
8436 | ||
d8041cc8 | 8437 | case VAR_DECL: |
b9203463 RH |
8438 | if (DECL_THREAD_LOCAL (loc)) |
8439 | { | |
8440 | rtx rtl; | |
8441 | ||
8442 | #ifndef ASM_OUTPUT_DWARF_DTPREL | |
8443 | /* If this is not defined, we have no way to emit the data. */ | |
8444 | return 0; | |
8445 | #endif | |
8446 | ||
8447 | /* The way DW_OP_GNU_push_tls_address is specified, we can only | |
8448 | look up addresses of objects in the current module. */ | |
3c655f42 | 8449 | if (DECL_EXTERNAL (loc)) |
b9203463 RH |
8450 | return 0; |
8451 | ||
8452 | rtl = rtl_for_decl_location (loc); | |
8453 | if (rtl == NULL_RTX) | |
8454 | return 0; | |
8455 | ||
8456 | if (GET_CODE (rtl) != MEM) | |
8457 | return 0; | |
8458 | rtl = XEXP (rtl, 0); | |
8459 | if (! CONSTANT_P (rtl)) | |
8460 | return 0; | |
8461 | ||
8462 | ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0); | |
8463 | ret->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
8464 | ret->dw_loc_oprnd1.v.val_addr = rtl; | |
8465 | ||
8466 | ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0); | |
8467 | add_loc_descr (&ret, ret1); | |
8468 | ||
8469 | indirect_p = 1; | |
8470 | break; | |
8471 | } | |
8472 | /* FALLTHRU */ | |
8473 | ||
d8041cc8 RH |
8474 | case PARM_DECL: |
8475 | { | |
8476 | rtx rtl = rtl_for_decl_location (loc); | |
d8041cc8 | 8477 | |
a97c9600 | 8478 | if (rtl == NULL_RTX) |
e7af1d45 | 8479 | return 0; |
a97c9600 | 8480 | else if (CONSTANT_P (rtl)) |
d8041cc8 RH |
8481 | { |
8482 | ret = new_loc_descr (DW_OP_addr, 0, 0); | |
8483 | ret->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
8484 | ret->dw_loc_oprnd1.v.val_addr = rtl; | |
e7af1d45 | 8485 | indirect_p = 1; |
d8041cc8 RH |
8486 | } |
8487 | else | |
8488 | { | |
c28abdf0 RH |
8489 | enum machine_mode mode = GET_MODE (rtl); |
8490 | ||
d8041cc8 RH |
8491 | if (GET_CODE (rtl) == MEM) |
8492 | { | |
e7af1d45 | 8493 | indirect_p = 1; |
d8041cc8 RH |
8494 | rtl = XEXP (rtl, 0); |
8495 | } | |
2ad9852d | 8496 | |
d8041cc8 RH |
8497 | ret = mem_loc_descriptor (rtl, mode); |
8498 | } | |
8499 | } | |
8500 | break; | |
8501 | ||
8502 | case INDIRECT_REF: | |
8503 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 | 8504 | indirect_p = 1; |
d8041cc8 RH |
8505 | break; |
8506 | ||
749552c4 RK |
8507 | case COMPOUND_EXPR: |
8508 | return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp); | |
8509 | ||
ed972b14 RK |
8510 | case NOP_EXPR: |
8511 | case CONVERT_EXPR: | |
8512 | case NON_LVALUE_EXPR: | |
ed239f5a | 8513 | case VIEW_CONVERT_EXPR: |
b4ae5201 | 8514 | case SAVE_EXPR: |
ed972b14 | 8515 | return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp); |
e57cabac | 8516 | |
d8041cc8 RH |
8517 | case COMPONENT_REF: |
8518 | case BIT_FIELD_REF: | |
8519 | case ARRAY_REF: | |
b4e3fabb | 8520 | case ARRAY_RANGE_REF: |
d8041cc8 RH |
8521 | { |
8522 | tree obj, offset; | |
8523 | HOST_WIDE_INT bitsize, bitpos, bytepos; | |
8524 | enum machine_mode mode; | |
8525 | int volatilep; | |
d8041cc8 RH |
8526 | |
8527 | obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode, | |
a06ef755 | 8528 | &unsignedp, &volatilep); |
e7af1d45 RK |
8529 | |
8530 | if (obj == loc) | |
8531 | return 0; | |
8532 | ||
d8041cc8 | 8533 | ret = loc_descriptor_from_tree (obj, 1); |
e7af1d45 | 8534 | if (ret == 0 |
2ad9852d | 8535 | || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0) |
e7af1d45 | 8536 | return 0; |
d8041cc8 RH |
8537 | |
8538 | if (offset != NULL_TREE) | |
8539 | { | |
8540 | /* Variable offset. */ | |
8541 | add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0)); | |
8542 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
8543 | } | |
8544 | ||
e7af1d45 RK |
8545 | if (!addressp) |
8546 | indirect_p = 1; | |
d8041cc8 RH |
8547 | |
8548 | bytepos = bitpos / BITS_PER_UNIT; | |
8549 | if (bytepos > 0) | |
8550 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0)); | |
8551 | else if (bytepos < 0) | |
8552 | { | |
8553 | add_loc_descr (&ret, int_loc_descriptor (bytepos)); | |
8554 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
8555 | } | |
8556 | break; | |
8557 | } | |
8558 | ||
8559 | case INTEGER_CST: | |
8560 | if (host_integerp (loc, 0)) | |
8561 | ret = int_loc_descriptor (tree_low_cst (loc, 0)); | |
e7af1d45 RK |
8562 | else |
8563 | return 0; | |
d8041cc8 | 8564 | break; |
d8041cc8 | 8565 | |
c26fbbca | 8566 | case TRUTH_AND_EXPR: |
9702143f | 8567 | case TRUTH_ANDIF_EXPR: |
d8041cc8 RH |
8568 | case BIT_AND_EXPR: |
8569 | op = DW_OP_and; | |
8570 | goto do_binop; | |
e7af1d45 | 8571 | |
9702143f | 8572 | case TRUTH_XOR_EXPR: |
d8041cc8 RH |
8573 | case BIT_XOR_EXPR: |
8574 | op = DW_OP_xor; | |
8575 | goto do_binop; | |
e7af1d45 | 8576 | |
9702143f RK |
8577 | case TRUTH_OR_EXPR: |
8578 | case TRUTH_ORIF_EXPR: | |
d8041cc8 RH |
8579 | case BIT_IOR_EXPR: |
8580 | op = DW_OP_or; | |
8581 | goto do_binop; | |
e7af1d45 | 8582 | |
d8041cc8 RH |
8583 | case TRUNC_DIV_EXPR: |
8584 | op = DW_OP_div; | |
8585 | goto do_binop; | |
e7af1d45 | 8586 | |
d8041cc8 RH |
8587 | case MINUS_EXPR: |
8588 | op = DW_OP_minus; | |
8589 | goto do_binop; | |
e7af1d45 | 8590 | |
d8041cc8 RH |
8591 | case TRUNC_MOD_EXPR: |
8592 | op = DW_OP_mod; | |
8593 | goto do_binop; | |
e7af1d45 | 8594 | |
d8041cc8 RH |
8595 | case MULT_EXPR: |
8596 | op = DW_OP_mul; | |
8597 | goto do_binop; | |
e7af1d45 | 8598 | |
d8041cc8 RH |
8599 | case LSHIFT_EXPR: |
8600 | op = DW_OP_shl; | |
8601 | goto do_binop; | |
e7af1d45 | 8602 | |
d8041cc8 RH |
8603 | case RSHIFT_EXPR: |
8604 | op = (unsignedp ? DW_OP_shr : DW_OP_shra); | |
8605 | goto do_binop; | |
e7af1d45 | 8606 | |
d8041cc8 RH |
8607 | case PLUS_EXPR: |
8608 | if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST | |
8609 | && host_integerp (TREE_OPERAND (loc, 1), 0)) | |
8610 | { | |
8611 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8612 | if (ret == 0) |
8613 | return 0; | |
8614 | ||
d8041cc8 RH |
8615 | add_loc_descr (&ret, |
8616 | new_loc_descr (DW_OP_plus_uconst, | |
8617 | tree_low_cst (TREE_OPERAND (loc, 1), | |
8618 | 0), | |
8619 | 0)); | |
8620 | break; | |
8621 | } | |
e7af1d45 | 8622 | |
d8041cc8 RH |
8623 | op = DW_OP_plus; |
8624 | goto do_binop; | |
2ad9852d | 8625 | |
d8041cc8 RH |
8626 | case LE_EXPR: |
8627 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8628 | return 0; |
8629 | ||
d8041cc8 RH |
8630 | op = DW_OP_le; |
8631 | goto do_binop; | |
e7af1d45 | 8632 | |
d8041cc8 RH |
8633 | case GE_EXPR: |
8634 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8635 | return 0; |
8636 | ||
d8041cc8 RH |
8637 | op = DW_OP_ge; |
8638 | goto do_binop; | |
e7af1d45 | 8639 | |
d8041cc8 RH |
8640 | case LT_EXPR: |
8641 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8642 | return 0; |
8643 | ||
d8041cc8 RH |
8644 | op = DW_OP_lt; |
8645 | goto do_binop; | |
e7af1d45 | 8646 | |
d8041cc8 RH |
8647 | case GT_EXPR: |
8648 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8649 | return 0; |
8650 | ||
d8041cc8 RH |
8651 | op = DW_OP_gt; |
8652 | goto do_binop; | |
e7af1d45 | 8653 | |
d8041cc8 RH |
8654 | case EQ_EXPR: |
8655 | op = DW_OP_eq; | |
8656 | goto do_binop; | |
e7af1d45 | 8657 | |
d8041cc8 RH |
8658 | case NE_EXPR: |
8659 | op = DW_OP_ne; | |
8660 | goto do_binop; | |
8661 | ||
8662 | do_binop: | |
8663 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8664 | ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); |
8665 | if (ret == 0 || ret1 == 0) | |
8666 | return 0; | |
8667 | ||
8668 | add_loc_descr (&ret, ret1); | |
d8041cc8 RH |
8669 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); |
8670 | break; | |
8671 | ||
9702143f | 8672 | case TRUTH_NOT_EXPR: |
d8041cc8 RH |
8673 | case BIT_NOT_EXPR: |
8674 | op = DW_OP_not; | |
8675 | goto do_unop; | |
e7af1d45 | 8676 | |
d8041cc8 RH |
8677 | case ABS_EXPR: |
8678 | op = DW_OP_abs; | |
8679 | goto do_unop; | |
e7af1d45 | 8680 | |
d8041cc8 RH |
8681 | case NEGATE_EXPR: |
8682 | op = DW_OP_neg; | |
8683 | goto do_unop; | |
8684 | ||
8685 | do_unop: | |
8686 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8687 | if (ret == 0) |
8688 | return 0; | |
8689 | ||
d8041cc8 RH |
8690 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); |
8691 | break; | |
8692 | ||
8693 | case MAX_EXPR: | |
8694 | loc = build (COND_EXPR, TREE_TYPE (loc), | |
8695 | build (LT_EXPR, integer_type_node, | |
8696 | TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)), | |
8697 | TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0)); | |
2ad9852d | 8698 | |
3ef42a0c | 8699 | /* ... fall through ... */ |
d8041cc8 RH |
8700 | |
8701 | case COND_EXPR: | |
8702 | { | |
e7af1d45 RK |
8703 | dw_loc_descr_ref lhs |
8704 | = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); | |
8705 | dw_loc_descr_ref rhs | |
8706 | = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0); | |
d8041cc8 RH |
8707 | dw_loc_descr_ref bra_node, jump_node, tmp; |
8708 | ||
8709 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8710 | if (ret == 0 || lhs == 0 || rhs == 0) |
8711 | return 0; | |
8712 | ||
d8041cc8 RH |
8713 | bra_node = new_loc_descr (DW_OP_bra, 0, 0); |
8714 | add_loc_descr (&ret, bra_node); | |
8715 | ||
e7af1d45 | 8716 | add_loc_descr (&ret, rhs); |
d8041cc8 RH |
8717 | jump_node = new_loc_descr (DW_OP_skip, 0, 0); |
8718 | add_loc_descr (&ret, jump_node); | |
8719 | ||
e7af1d45 | 8720 | add_loc_descr (&ret, lhs); |
d8041cc8 | 8721 | bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc; |
e7af1d45 | 8722 | bra_node->dw_loc_oprnd1.v.val_loc = lhs; |
d8041cc8 RH |
8723 | |
8724 | /* ??? Need a node to point the skip at. Use a nop. */ | |
8725 | tmp = new_loc_descr (DW_OP_nop, 0, 0); | |
8726 | add_loc_descr (&ret, tmp); | |
8727 | jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc; | |
8728 | jump_node->dw_loc_oprnd1.v.val_loc = tmp; | |
8729 | } | |
8730 | break; | |
8731 | ||
8732 | default: | |
8733 | abort (); | |
8734 | } | |
8735 | ||
e7af1d45 RK |
8736 | /* Show if we can't fill the request for an address. */ |
8737 | if (addressp && indirect_p == 0) | |
8738 | return 0; | |
d8041cc8 RH |
8739 | |
8740 | /* If we've got an address and don't want one, dereference. */ | |
e7af1d45 | 8741 | if (!addressp && indirect_p > 0) |
d8041cc8 | 8742 | { |
e7af1d45 RK |
8743 | HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc)); |
8744 | ||
8745 | if (size > DWARF2_ADDR_SIZE || size == -1) | |
8746 | return 0; | |
2ad9852d | 8747 | else if (size == DWARF2_ADDR_SIZE) |
d8041cc8 RH |
8748 | op = DW_OP_deref; |
8749 | else | |
8750 | op = DW_OP_deref_size; | |
e7af1d45 RK |
8751 | |
8752 | add_loc_descr (&ret, new_loc_descr (op, size, 0)); | |
d8041cc8 RH |
8753 | } |
8754 | ||
8755 | return ret; | |
8756 | } | |
8757 | ||
665f2503 | 8758 | /* Given a value, round it up to the lowest multiple of `boundary' |
a3f97cbb | 8759 | which is not less than the value itself. */ |
71dfc51f | 8760 | |
665f2503 | 8761 | static inline HOST_WIDE_INT |
a3f97cbb | 8762 | ceiling (value, boundary) |
665f2503 RK |
8763 | HOST_WIDE_INT value; |
8764 | unsigned int boundary; | |
a3f97cbb JW |
8765 | { |
8766 | return (((value + boundary - 1) / boundary) * boundary); | |
8767 | } | |
8768 | ||
8769 | /* Given a pointer to what is assumed to be a FIELD_DECL node, return a | |
8770 | pointer to the declared type for the relevant field variable, or return | |
8771 | `integer_type_node' if the given node turns out to be an | |
8772 | ERROR_MARK node. */ | |
71dfc51f RK |
8773 | |
8774 | static inline tree | |
a3f97cbb | 8775 | field_type (decl) |
b3694847 | 8776 | tree decl; |
a3f97cbb | 8777 | { |
b3694847 | 8778 | tree type; |
a3f97cbb JW |
8779 | |
8780 | if (TREE_CODE (decl) == ERROR_MARK) | |
8781 | return integer_type_node; | |
8782 | ||
8783 | type = DECL_BIT_FIELD_TYPE (decl); | |
71dfc51f | 8784 | if (type == NULL_TREE) |
a3f97cbb JW |
8785 | type = TREE_TYPE (decl); |
8786 | ||
8787 | return type; | |
8788 | } | |
8789 | ||
5f446d21 DD |
8790 | /* Given a pointer to a tree node, return the alignment in bits for |
8791 | it, or else return BITS_PER_WORD if the node actually turns out to | |
8792 | be an ERROR_MARK node. */ | |
71dfc51f RK |
8793 | |
8794 | static inline unsigned | |
a3f97cbb | 8795 | simple_type_align_in_bits (type) |
b3694847 | 8796 | tree type; |
a3f97cbb JW |
8797 | { |
8798 | return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; | |
8799 | } | |
8800 | ||
5f446d21 DD |
8801 | static inline unsigned |
8802 | simple_decl_align_in_bits (decl) | |
b3694847 | 8803 | tree decl; |
5f446d21 DD |
8804 | { |
8805 | return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD; | |
8806 | } | |
8807 | ||
2ad9852d RK |
8808 | /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the |
8809 | lowest addressed byte of the "containing object" for the given FIELD_DECL, | |
8810 | or return 0 if we are unable to determine what that offset is, either | |
8811 | because the argument turns out to be a pointer to an ERROR_MARK node, or | |
8812 | because the offset is actually variable. (We can't handle the latter case | |
8813 | just yet). */ | |
71dfc51f | 8814 | |
665f2503 | 8815 | static HOST_WIDE_INT |
a3f97cbb | 8816 | field_byte_offset (decl) |
b3694847 | 8817 | tree decl; |
a3f97cbb | 8818 | { |
665f2503 | 8819 | unsigned int type_align_in_bits; |
5f446d21 | 8820 | unsigned int decl_align_in_bits; |
665f2503 | 8821 | unsigned HOST_WIDE_INT type_size_in_bits; |
665f2503 | 8822 | HOST_WIDE_INT object_offset_in_bits; |
665f2503 RK |
8823 | tree type; |
8824 | tree field_size_tree; | |
8825 | HOST_WIDE_INT bitpos_int; | |
8826 | HOST_WIDE_INT deepest_bitpos; | |
8827 | unsigned HOST_WIDE_INT field_size_in_bits; | |
a3f97cbb JW |
8828 | |
8829 | if (TREE_CODE (decl) == ERROR_MARK) | |
8830 | return 0; | |
2ad9852d | 8831 | else if (TREE_CODE (decl) != FIELD_DECL) |
a3f97cbb JW |
8832 | abort (); |
8833 | ||
8834 | type = field_type (decl); | |
a3f97cbb JW |
8835 | field_size_tree = DECL_SIZE (decl); |
8836 | ||
3df18884 RH |
8837 | /* The size could be unspecified if there was an error, or for |
8838 | a flexible array member. */ | |
50352c9c | 8839 | if (! field_size_tree) |
3df18884 | 8840 | field_size_tree = bitsize_zero_node; |
50352c9c | 8841 | |
556273e0 | 8842 | /* We cannot yet cope with fields whose positions are variable, so |
a3f97cbb JW |
8843 | for now, when we see such things, we simply return 0. Someday, we may |
8844 | be able to handle such cases, but it will be damn difficult. */ | |
665f2503 | 8845 | if (! host_integerp (bit_position (decl), 0)) |
a3f97cbb | 8846 | return 0; |
14a774a9 | 8847 | |
665f2503 | 8848 | bitpos_int = int_bit_position (decl); |
a3f97cbb | 8849 | |
3df18884 | 8850 | /* If we don't know the size of the field, pretend it's a full word. */ |
665f2503 RK |
8851 | if (host_integerp (field_size_tree, 1)) |
8852 | field_size_in_bits = tree_low_cst (field_size_tree, 1); | |
14a774a9 RK |
8853 | else |
8854 | field_size_in_bits = BITS_PER_WORD; | |
a3f97cbb JW |
8855 | |
8856 | type_size_in_bits = simple_type_size_in_bits (type); | |
a3f97cbb | 8857 | type_align_in_bits = simple_type_align_in_bits (type); |
5f446d21 | 8858 | decl_align_in_bits = simple_decl_align_in_bits (decl); |
a3f97cbb | 8859 | |
2ad9852d RK |
8860 | /* The GCC front-end doesn't make any attempt to keep track of the starting |
8861 | bit offset (relative to the start of the containing structure type) of the | |
8862 | hypothetical "containing object" for a bit-field. Thus, when computing | |
8863 | the byte offset value for the start of the "containing object" of a | |
8864 | bit-field, we must deduce this information on our own. This can be rather | |
8865 | tricky to do in some cases. For example, handling the following structure | |
8866 | type definition when compiling for an i386/i486 target (which only aligns | |
8867 | long long's to 32-bit boundaries) can be very tricky: | |
a3f97cbb JW |
8868 | |
8869 | struct S { int field1; long long field2:31; }; | |
8870 | ||
2ad9852d RK |
8871 | Fortunately, there is a simple rule-of-thumb which can be used in such |
8872 | cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the | |
8873 | structure shown above. It decides to do this based upon one simple rule | |
8874 | for bit-field allocation. GCC allocates each "containing object" for each | |
8875 | bit-field at the first (i.e. lowest addressed) legitimate alignment | |
8876 | boundary (based upon the required minimum alignment for the declared type | |
8877 | of the field) which it can possibly use, subject to the condition that | |
8878 | there is still enough available space remaining in the containing object | |
8879 | (when allocated at the selected point) to fully accommodate all of the | |
8880 | bits of the bit-field itself. | |
8881 | ||
8882 | This simple rule makes it obvious why GCC allocates 8 bytes for each | |
8883 | object of the structure type shown above. When looking for a place to | |
8884 | allocate the "containing object" for `field2', the compiler simply tries | |
8885 | to allocate a 64-bit "containing object" at each successive 32-bit | |
8886 | boundary (starting at zero) until it finds a place to allocate that 64- | |
8887 | bit field such that at least 31 contiguous (and previously unallocated) | |
8888 | bits remain within that selected 64 bit field. (As it turns out, for the | |
8889 | example above, the compiler finds it is OK to allocate the "containing | |
8890 | object" 64-bit field at bit-offset zero within the structure type.) | |
8891 | ||
8892 | Here we attempt to work backwards from the limited set of facts we're | |
8893 | given, and we try to deduce from those facts, where GCC must have believed | |
8894 | that the containing object started (within the structure type). The value | |
8895 | we deduce is then used (by the callers of this routine) to generate | |
8896 | DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields | |
8897 | and, in the case of DW_AT_location, regular fields as well). */ | |
a3f97cbb JW |
8898 | |
8899 | /* Figure out the bit-distance from the start of the structure to the | |
8900 | "deepest" bit of the bit-field. */ | |
8901 | deepest_bitpos = bitpos_int + field_size_in_bits; | |
8902 | ||
8903 | /* This is the tricky part. Use some fancy footwork to deduce where the | |
8904 | lowest addressed bit of the containing object must be. */ | |
5f446d21 DD |
8905 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; |
8906 | ||
8907 | /* Round up to type_align by default. This works best for bitfields. */ | |
8908 | object_offset_in_bits += type_align_in_bits - 1; | |
8909 | object_offset_in_bits /= type_align_in_bits; | |
8910 | object_offset_in_bits *= type_align_in_bits; | |
a3f97cbb | 8911 | |
5f446d21 DD |
8912 | if (object_offset_in_bits > bitpos_int) |
8913 | { | |
8914 | /* Sigh, the decl must be packed. */ | |
8915 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; | |
8916 | ||
8917 | /* Round up to decl_align instead. */ | |
8918 | object_offset_in_bits += decl_align_in_bits - 1; | |
8919 | object_offset_in_bits /= decl_align_in_bits; | |
8920 | object_offset_in_bits *= decl_align_in_bits; | |
8921 | } | |
a3f97cbb | 8922 | |
2ad9852d | 8923 | return object_offset_in_bits / BITS_PER_UNIT; |
a3f97cbb | 8924 | } |
a3f97cbb | 8925 | \f |
71dfc51f RK |
8926 | /* The following routines define various Dwarf attributes and any data |
8927 | associated with them. */ | |
a3f97cbb | 8928 | |
ef76d03b | 8929 | /* Add a location description attribute value to a DIE. |
a3f97cbb | 8930 | |
ef76d03b | 8931 | This emits location attributes suitable for whole variables and |
a3f97cbb JW |
8932 | whole parameters. Note that the location attributes for struct fields are |
8933 | generated by the routine `data_member_location_attribute' below. */ | |
71dfc51f | 8934 | |
b9203463 RH |
8935 | static inline void |
8936 | add_AT_location_description (die, attr_kind, descr) | |
a3f97cbb | 8937 | dw_die_ref die; |
ef76d03b | 8938 | enum dwarf_attribute attr_kind; |
b9203463 | 8939 | dw_loc_descr_ref descr; |
a3f97cbb | 8940 | { |
e7af1d45 RK |
8941 | if (descr != 0) |
8942 | add_AT_loc (die, attr_kind, descr); | |
a3f97cbb JW |
8943 | } |
8944 | ||
2ad9852d RK |
8945 | /* Attach the specialized form of location attribute used for data members of |
8946 | struct and union types. In the special case of a FIELD_DECL node which | |
8947 | represents a bit-field, the "offset" part of this special location | |
8948 | descriptor must indicate the distance in bytes from the lowest-addressed | |
8949 | byte of the containing struct or union type to the lowest-addressed byte of | |
8950 | the "containing object" for the bit-field. (See the `field_byte_offset' | |
8951 | function above). | |
8952 | ||
8953 | For any given bit-field, the "containing object" is a hypothetical object | |
8954 | (of some integral or enum type) within which the given bit-field lives. The | |
8955 | type of this hypothetical "containing object" is always the same as the | |
8956 | declared type of the individual bit-field itself (for GCC anyway... the | |
8957 | DWARF spec doesn't actually mandate this). Note that it is the size (in | |
8958 | bytes) of the hypothetical "containing object" which will be given in the | |
8959 | DW_AT_byte_size attribute for this bit-field. (See the | |
8960 | `byte_size_attribute' function below.) It is also used when calculating the | |
8961 | value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute' | |
8962 | function below.) */ | |
71dfc51f | 8963 | |
a3f97cbb JW |
8964 | static void |
8965 | add_data_member_location_attribute (die, decl) | |
b3694847 SS |
8966 | dw_die_ref die; |
8967 | tree decl; | |
a3f97cbb | 8968 | { |
649ce3f2 JM |
8969 | long offset; |
8970 | dw_loc_descr_ref loc_descr = 0; | |
a3f97cbb | 8971 | |
61b32c02 | 8972 | if (TREE_CODE (decl) == TREE_VEC) |
649ce3f2 JM |
8973 | { |
8974 | /* We're working on the TAG_inheritance for a base class. */ | |
1d3d6b1e | 8975 | if (TREE_VIA_VIRTUAL (decl) && is_cxx ()) |
649ce3f2 JM |
8976 | { |
8977 | /* For C++ virtual bases we can't just use BINFO_OFFSET, as they | |
8978 | aren't at a fixed offset from all (sub)objects of the same | |
8979 | type. We need to extract the appropriate offset from our | |
8980 | vtable. The following dwarf expression means | |
8981 | ||
8982 | BaseAddr = ObAddr + *((*ObAddr) - Offset) | |
8983 | ||
8984 | This is specific to the V3 ABI, of course. */ | |
8985 | ||
8986 | dw_loc_descr_ref tmp; | |
2ad9852d | 8987 | |
649ce3f2 JM |
8988 | /* Make a copy of the object address. */ |
8989 | tmp = new_loc_descr (DW_OP_dup, 0, 0); | |
8990 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 8991 | |
649ce3f2 JM |
8992 | /* Extract the vtable address. */ |
8993 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
8994 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 8995 | |
649ce3f2 JM |
8996 | /* Calculate the address of the offset. */ |
8997 | offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0); | |
8998 | if (offset >= 0) | |
8999 | abort (); | |
2ad9852d | 9000 | |
649ce3f2 JM |
9001 | tmp = int_loc_descriptor (-offset); |
9002 | add_loc_descr (&loc_descr, tmp); | |
9003 | tmp = new_loc_descr (DW_OP_minus, 0, 0); | |
9004 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 9005 | |
649ce3f2 JM |
9006 | /* Extract the offset. */ |
9007 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
9008 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 9009 | |
649ce3f2 JM |
9010 | /* Add it to the object address. */ |
9011 | tmp = new_loc_descr (DW_OP_plus, 0, 0); | |
9012 | add_loc_descr (&loc_descr, tmp); | |
9013 | } | |
9014 | else | |
9015 | offset = tree_low_cst (BINFO_OFFSET (decl), 0); | |
9016 | } | |
61b32c02 JM |
9017 | else |
9018 | offset = field_byte_offset (decl); | |
9019 | ||
649ce3f2 JM |
9020 | if (! loc_descr) |
9021 | { | |
9022 | enum dwarf_location_atom op; | |
9023 | ||
2ad9852d RK |
9024 | /* The DWARF2 standard says that we should assume that the structure |
9025 | address is already on the stack, so we can specify a structure field | |
9026 | address by using DW_OP_plus_uconst. */ | |
71dfc51f | 9027 | |
a3f97cbb | 9028 | #ifdef MIPS_DEBUGGING_INFO |
2ad9852d RK |
9029 | /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst |
9030 | operator correctly. It works only if we leave the offset on the | |
9031 | stack. */ | |
649ce3f2 | 9032 | op = DW_OP_constu; |
a3f97cbb | 9033 | #else |
649ce3f2 | 9034 | op = DW_OP_plus_uconst; |
a3f97cbb | 9035 | #endif |
71dfc51f | 9036 | |
649ce3f2 JM |
9037 | loc_descr = new_loc_descr (op, offset, 0); |
9038 | } | |
2ad9852d | 9039 | |
a3f97cbb JW |
9040 | add_AT_loc (die, DW_AT_data_member_location, loc_descr); |
9041 | } | |
9042 | ||
9043 | /* Attach an DW_AT_const_value attribute for a variable or a parameter which | |
9044 | does not have a "location" either in memory or in a register. These | |
9045 | things can arise in GNU C when a constant is passed as an actual parameter | |
9046 | to an inlined function. They can also arise in C++ where declared | |
9047 | constants do not necessarily get memory "homes". */ | |
71dfc51f | 9048 | |
a3f97cbb JW |
9049 | static void |
9050 | add_const_value_attribute (die, rtl) | |
b3694847 SS |
9051 | dw_die_ref die; |
9052 | rtx rtl; | |
a3f97cbb JW |
9053 | { |
9054 | switch (GET_CODE (rtl)) | |
9055 | { | |
9056 | case CONST_INT: | |
2e4b9b8c RH |
9057 | /* Note that a CONST_INT rtx could represent either an integer |
9058 | or a floating-point constant. A CONST_INT is used whenever | |
9059 | the constant will fit into a single word. In all such | |
9060 | cases, the original mode of the constant value is wiped | |
9061 | out, and the CONST_INT rtx is assigned VOIDmode. */ | |
9062 | { | |
9063 | HOST_WIDE_INT val = INTVAL (rtl); | |
c26fbbca | 9064 | |
2e4b9b8c | 9065 | /* ??? We really should be using HOST_WIDE_INT throughout. */ |
5929a2f0 | 9066 | if (val < 0 && (long) val == val) |
3d7a191f | 9067 | add_AT_int (die, DW_AT_const_value, (long) val); |
5929a2f0 RH |
9068 | else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val) |
9069 | add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val); | |
94784fb9 RK |
9070 | else |
9071 | { | |
e7af1d45 | 9072 | #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT |
94784fb9 RK |
9073 | add_AT_long_long (die, DW_AT_const_value, |
9074 | val >> HOST_BITS_PER_LONG, val); | |
e7af1d45 | 9075 | #else |
94784fb9 | 9076 | abort (); |
e7af1d45 | 9077 | #endif |
94784fb9 | 9078 | } |
2e4b9b8c | 9079 | } |
a3f97cbb JW |
9080 | break; |
9081 | ||
9082 | case CONST_DOUBLE: | |
9083 | /* Note that a CONST_DOUBLE rtx could represent either an integer or a | |
9084 | floating-point constant. A CONST_DOUBLE is used whenever the | |
9085 | constant requires more than one word in order to be adequately | |
469ac993 JM |
9086 | represented. We output CONST_DOUBLEs as blocks. */ |
9087 | { | |
b3694847 | 9088 | enum machine_mode mode = GET_MODE (rtl); |
469ac993 JM |
9089 | |
9090 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
9091 | { | |
b3694847 | 9092 | unsigned length = GET_MODE_SIZE (mode) / 4; |
c26fbbca | 9093 | long *array = (long *) xmalloc (sizeof (long) * length); |
71dfc51f | 9094 | REAL_VALUE_TYPE rv; |
469ac993 | 9095 | |
71dfc51f | 9096 | REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl); |
469ac993 JM |
9097 | switch (mode) |
9098 | { | |
9099 | case SFmode: | |
71dfc51f | 9100 | REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]); |
469ac993 JM |
9101 | break; |
9102 | ||
9103 | case DFmode: | |
71dfc51f | 9104 | REAL_VALUE_TO_TARGET_DOUBLE (rv, array); |
469ac993 JM |
9105 | break; |
9106 | ||
9107 | case XFmode: | |
9108 | case TFmode: | |
71dfc51f | 9109 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array); |
469ac993 JM |
9110 | break; |
9111 | ||
9112 | default: | |
9113 | abort (); | |
9114 | } | |
9115 | ||
469ac993 JM |
9116 | add_AT_float (die, DW_AT_const_value, length, array); |
9117 | } | |
9118 | else | |
2e4b9b8c RH |
9119 | { |
9120 | /* ??? We really should be using HOST_WIDE_INT throughout. */ | |
9121 | if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT) | |
9122 | abort (); | |
2ad9852d | 9123 | |
2e4b9b8c RH |
9124 | add_AT_long_long (die, DW_AT_const_value, |
9125 | CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl)); | |
9126 | } | |
469ac993 | 9127 | } |
a3f97cbb JW |
9128 | break; |
9129 | ||
9130 | case CONST_STRING: | |
9131 | add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0)); | |
9132 | break; | |
9133 | ||
9134 | case SYMBOL_REF: | |
9135 | case LABEL_REF: | |
9136 | case CONST: | |
c470afad RK |
9137 | add_AT_addr (die, DW_AT_const_value, rtl); |
9138 | VARRAY_PUSH_RTX (used_rtx_varray, rtl); | |
a3f97cbb JW |
9139 | break; |
9140 | ||
9141 | case PLUS: | |
9142 | /* In cases where an inlined instance of an inline function is passed | |
9143 | the address of an `auto' variable (which is local to the caller) we | |
9144 | can get a situation where the DECL_RTL of the artificial local | |
9145 | variable (for the inlining) which acts as a stand-in for the | |
9146 | corresponding formal parameter (of the inline function) will look | |
9147 | like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not | |
556273e0 KH |
9148 | exactly a compile-time constant expression, but it isn't the address |
9149 | of the (artificial) local variable either. Rather, it represents the | |
a3f97cbb | 9150 | *value* which the artificial local variable always has during its |
556273e0 | 9151 | lifetime. We currently have no way to represent such quasi-constant |
6a7a9f01 | 9152 | values in Dwarf, so for now we just punt and generate nothing. */ |
a3f97cbb JW |
9153 | break; |
9154 | ||
9155 | default: | |
9156 | /* No other kinds of rtx should be possible here. */ | |
9157 | abort (); | |
9158 | } | |
9159 | ||
9160 | } | |
9161 | ||
d8041cc8 RH |
9162 | static rtx |
9163 | rtl_for_decl_location (decl) | |
9164 | tree decl; | |
a3f97cbb | 9165 | { |
b3694847 | 9166 | rtx rtl; |
71dfc51f | 9167 | |
a3f97cbb JW |
9168 | /* Here we have to decide where we are going to say the parameter "lives" |
9169 | (as far as the debugger is concerned). We only have a couple of | |
9170 | choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. | |
71dfc51f | 9171 | |
556273e0 | 9172 | DECL_RTL normally indicates where the parameter lives during most of the |
71dfc51f | 9173 | activation of the function. If optimization is enabled however, this |
556273e0 | 9174 | could be either NULL or else a pseudo-reg. Both of those cases indicate |
a3f97cbb JW |
9175 | that the parameter doesn't really live anywhere (as far as the code |
9176 | generation parts of GCC are concerned) during most of the function's | |
9177 | activation. That will happen (for example) if the parameter is never | |
71dfc51f RK |
9178 | referenced within the function. |
9179 | ||
9180 | We could just generate a location descriptor here for all non-NULL | |
9181 | non-pseudo values of DECL_RTL and ignore all of the rest, but we can be | |
9182 | a little nicer than that if we also consider DECL_INCOMING_RTL in cases | |
9183 | where DECL_RTL is NULL or is a pseudo-reg. | |
9184 | ||
9185 | Note however that we can only get away with using DECL_INCOMING_RTL as | |
9186 | a backup substitute for DECL_RTL in certain limited cases. In cases | |
9187 | where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl), | |
9188 | we can be sure that the parameter was passed using the same type as it is | |
9189 | declared to have within the function, and that its DECL_INCOMING_RTL | |
9190 | points us to a place where a value of that type is passed. | |
9191 | ||
9192 | In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different, | |
9193 | we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL | |
9194 | because in these cases DECL_INCOMING_RTL points us to a value of some | |
9195 | type which is *different* from the type of the parameter itself. Thus, | |
9196 | if we tried to use DECL_INCOMING_RTL to generate a location attribute in | |
9197 | such cases, the debugger would end up (for example) trying to fetch a | |
9198 | `float' from a place which actually contains the first part of a | |
9199 | `double'. That would lead to really incorrect and confusing | |
9200 | output at debug-time. | |
9201 | ||
9202 | So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL | |
9203 | in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There | |
9204 | are a couple of exceptions however. On little-endian machines we can | |
9205 | get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is | |
9206 | not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is | |
9207 | an integral type that is smaller than TREE_TYPE (decl). These cases arise | |
9208 | when (on a little-endian machine) a non-prototyped function has a | |
9209 | parameter declared to be of type `short' or `char'. In such cases, | |
9210 | TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will | |
9211 | be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the | |
9212 | passed `int' value. If the debugger then uses that address to fetch | |
9213 | a `short' or a `char' (on a little-endian machine) the result will be | |
9214 | the correct data, so we allow for such exceptional cases below. | |
9215 | ||
9216 | Note that our goal here is to describe the place where the given formal | |
2ad9852d RK |
9217 | parameter lives during most of the function's activation (i.e. between the |
9218 | end of the prologue and the start of the epilogue). We'll do that as best | |
9219 | as we can. Note however that if the given formal parameter is modified | |
9220 | sometime during the execution of the function, then a stack backtrace (at | |
9221 | debug-time) will show the function as having been called with the *new* | |
9222 | value rather than the value which was originally passed in. This happens | |
9223 | rarely enough that it is not a major problem, but it *is* a problem, and | |
9224 | I'd like to fix it. | |
9225 | ||
9226 | A future version of dwarf2out.c may generate two additional attributes for | |
9227 | any given DW_TAG_formal_parameter DIE which will describe the "passed | |
9228 | type" and the "passed location" for the given formal parameter in addition | |
9229 | to the attributes we now generate to indicate the "declared type" and the | |
9230 | "active location" for each parameter. This additional set of attributes | |
9231 | could be used by debuggers for stack backtraces. Separately, note that | |
9232 | sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also. | |
9233 | This happens (for example) for inlined-instances of inline function formal | |
9234 | parameters which are never referenced. This really shouldn't be | |
9235 | happening. All PARM_DECL nodes should get valid non-NULL | |
9236 | DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these | |
9237 | values for inlined instances of inline function parameters, so when we see | |
9238 | such cases, we are just out-of-luck for the time being (until integrate.c | |
a3f97cbb JW |
9239 | gets fixed). */ |
9240 | ||
9241 | /* Use DECL_RTL as the "location" unless we find something better. */ | |
110c3568 | 9242 | rtl = DECL_RTL_IF_SET (decl); |
a3f97cbb | 9243 | |
c28abdf0 RH |
9244 | /* When generating abstract instances, ignore everything except |
9245 | constants and symbols living in memory. */ | |
9246 | if (! reload_completed) | |
9247 | { | |
9248 | if (rtl | |
9249 | && (CONSTANT_P (rtl) | |
9250 | || (GET_CODE (rtl) == MEM | |
9251 | && CONSTANT_P (XEXP (rtl, 0))))) | |
4c8c0dec JJ |
9252 | { |
9253 | #ifdef ASM_SIMPLIFY_DWARF_ADDR | |
9254 | rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); | |
9255 | #endif | |
9256 | return rtl; | |
9257 | } | |
c28abdf0 RH |
9258 | rtl = NULL_RTX; |
9259 | } | |
9260 | else if (TREE_CODE (decl) == PARM_DECL) | |
a3f97cbb JW |
9261 | { |
9262 | if (rtl == NULL_RTX || is_pseudo_reg (rtl)) | |
9263 | { | |
d8041cc8 RH |
9264 | tree declared_type = type_main_variant (TREE_TYPE (decl)); |
9265 | tree passed_type = type_main_variant (DECL_ARG_TYPE (decl)); | |
a3f97cbb | 9266 | |
71dfc51f | 9267 | /* This decl represents a formal parameter which was optimized out. |
a3f97cbb | 9268 | Note that DECL_INCOMING_RTL may be NULL in here, but we handle |
2ad9852d | 9269 | all cases where (rtl == NULL_RTX) just below. */ |
a3f97cbb | 9270 | if (declared_type == passed_type) |
71dfc51f RK |
9271 | rtl = DECL_INCOMING_RTL (decl); |
9272 | else if (! BYTES_BIG_ENDIAN | |
9273 | && TREE_CODE (declared_type) == INTEGER_TYPE | |
555b6442 HPN |
9274 | && (GET_MODE_SIZE (TYPE_MODE (declared_type)) |
9275 | <= GET_MODE_SIZE (TYPE_MODE (passed_type)))) | |
556273e0 | 9276 | rtl = DECL_INCOMING_RTL (decl); |
a3f97cbb | 9277 | } |
5a904a61 JW |
9278 | |
9279 | /* If the parm was passed in registers, but lives on the stack, then | |
9280 | make a big endian correction if the mode of the type of the | |
9281 | parameter is not the same as the mode of the rtl. */ | |
9282 | /* ??? This is the same series of checks that are made in dbxout.c before | |
9283 | we reach the big endian correction code there. It isn't clear if all | |
9284 | of these checks are necessary here, but keeping them all is the safe | |
9285 | thing to do. */ | |
9286 | else if (GET_CODE (rtl) == MEM | |
9287 | && XEXP (rtl, 0) != const0_rtx | |
9288 | && ! CONSTANT_P (XEXP (rtl, 0)) | |
9289 | /* Not passed in memory. */ | |
9290 | && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM | |
9291 | /* Not passed by invisible reference. */ | |
9292 | && (GET_CODE (XEXP (rtl, 0)) != REG | |
9293 | || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM | |
9294 | || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM | |
9295 | #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM | |
9296 | || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM | |
9297 | #endif | |
9298 | ) | |
9299 | /* Big endian correction check. */ | |
9300 | && BYTES_BIG_ENDIAN | |
9301 | && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl) | |
9302 | && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))) | |
9303 | < UNITS_PER_WORD)) | |
9304 | { | |
9305 | int offset = (UNITS_PER_WORD | |
9306 | - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))); | |
2ad9852d | 9307 | |
5a904a61 JW |
9308 | rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)), |
9309 | plus_constant (XEXP (rtl, 0), offset)); | |
9310 | } | |
a3f97cbb | 9311 | } |
71dfc51f | 9312 | |
d8041cc8 RH |
9313 | if (rtl != NULL_RTX) |
9314 | { | |
9315 | rtl = eliminate_regs (rtl, 0, NULL_RTX); | |
6a7a9f01 | 9316 | #ifdef LEAF_REG_REMAP |
d8041cc8 RH |
9317 | if (current_function_uses_only_leaf_regs) |
9318 | leaf_renumber_regs_insn (rtl); | |
6a7a9f01 | 9319 | #endif |
d8041cc8 RH |
9320 | } |
9321 | ||
2ad9852d RK |
9322 | /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant, |
9323 | and will have been substituted directly into all expressions that use it. | |
9324 | C does not have such a concept, but C++ and other languages do. */ | |
c28abdf0 | 9325 | else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl)) |
6d73371a JJ |
9326 | { |
9327 | /* If a variable is initialized with a string constant without embedded | |
9328 | zeros, build CONST_STRING. */ | |
9329 | if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST | |
9330 | && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) | |
9331 | { | |
9332 | tree arrtype = TREE_TYPE (decl); | |
9333 | tree enttype = TREE_TYPE (arrtype); | |
9334 | tree domain = TYPE_DOMAIN (arrtype); | |
9335 | tree init = DECL_INITIAL (decl); | |
9336 | enum machine_mode mode = TYPE_MODE (enttype); | |
9337 | ||
9338 | if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1 | |
9339 | && domain | |
9340 | && integer_zerop (TYPE_MIN_VALUE (domain)) | |
9341 | && compare_tree_int (TYPE_MAX_VALUE (domain), | |
9342 | TREE_STRING_LENGTH (init) - 1) == 0 | |
9343 | && ((size_t) TREE_STRING_LENGTH (init) | |
9344 | == strlen (TREE_STRING_POINTER (init)) + 1)) | |
9345 | rtl = gen_rtx_CONST_STRING (VOIDmode, TREE_STRING_POINTER (init)); | |
9346 | } | |
29b91443 JM |
9347 | /* If the initializer is something that we know will expand into an |
9348 | immediate RTL constant, expand it now. Expanding anything else | |
9349 | tends to produce unresolved symbols; see debug/5770 and c++/6381. */ | |
9350 | else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST | |
9351 | || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST) | |
6d73371a JJ |
9352 | { |
9353 | rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode, | |
9354 | EXPAND_INITIALIZER); | |
29b91443 | 9355 | /* If expand_expr returns a MEM, it wasn't immediate. */ |
6d73371a | 9356 | if (rtl && GET_CODE (rtl) == MEM) |
29b91443 | 9357 | abort (); |
6d73371a JJ |
9358 | } |
9359 | } | |
8063ddcf | 9360 | |
4c8c0dec JJ |
9361 | #ifdef ASM_SIMPLIFY_DWARF_ADDR |
9362 | if (rtl) | |
9363 | rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); | |
9364 | #endif | |
b9203463 RH |
9365 | |
9366 | /* If we don't look past the constant pool, we risk emitting a | |
9367 | reference to a constant pool entry that isn't referenced from | |
9368 | code, and thus is not emitted. */ | |
9369 | if (rtl) | |
9370 | rtl = avoid_constant_pool_reference (rtl); | |
9371 | ||
d8041cc8 RH |
9372 | return rtl; |
9373 | } | |
9374 | ||
9375 | /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value | |
9376 | data attribute for a variable or a parameter. We generate the | |
9377 | DW_AT_const_value attribute only in those cases where the given variable | |
9378 | or parameter does not have a true "location" either in memory or in a | |
9379 | register. This can happen (for example) when a constant is passed as an | |
9380 | actual argument in a call to an inline function. (It's possible that | |
9381 | these things can crop up in other ways also.) Note that one type of | |
9382 | constant value which can be passed into an inlined function is a constant | |
9383 | pointer. This can happen for example if an actual argument in an inlined | |
9384 | function call evaluates to a compile-time constant address. */ | |
9385 | ||
9386 | static void | |
9387 | add_location_or_const_value_attribute (die, decl) | |
b3694847 SS |
9388 | dw_die_ref die; |
9389 | tree decl; | |
d8041cc8 | 9390 | { |
b3694847 | 9391 | rtx rtl; |
b9203463 | 9392 | dw_loc_descr_ref descr; |
d8041cc8 RH |
9393 | |
9394 | if (TREE_CODE (decl) == ERROR_MARK) | |
9395 | return; | |
2ad9852d | 9396 | else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL) |
d8041cc8 RH |
9397 | abort (); |
9398 | ||
9399 | rtl = rtl_for_decl_location (decl); | |
a97c9600 RH |
9400 | if (rtl == NULL_RTX) |
9401 | return; | |
6a7a9f01 | 9402 | |
a3f97cbb JW |
9403 | switch (GET_CODE (rtl)) |
9404 | { | |
e9a25f70 | 9405 | case ADDRESSOF: |
b9203463 RH |
9406 | /* The address of a variable that was optimized away; |
9407 | don't emit anything. */ | |
e9a25f70 JL |
9408 | break; |
9409 | ||
a3f97cbb JW |
9410 | case CONST_INT: |
9411 | case CONST_DOUBLE: | |
9412 | case CONST_STRING: | |
9413 | case SYMBOL_REF: | |
9414 | case LABEL_REF: | |
9415 | case CONST: | |
9416 | case PLUS: | |
9417 | /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ | |
9418 | add_const_value_attribute (die, rtl); | |
9419 | break; | |
9420 | ||
9421 | case MEM: | |
b9203463 RH |
9422 | if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl)) |
9423 | { | |
9424 | /* Need loc_descriptor_from_tree since that's where we know | |
9425 | how to handle TLS variables. Want the object's address | |
9426 | since the top-level DW_AT_location assumes such. See | |
9427 | the confusion in loc_descriptor for reference. */ | |
9428 | descr = loc_descriptor_from_tree (decl, 1); | |
9429 | } | |
9430 | else | |
9431 | { | |
9432 | case REG: | |
9433 | case SUBREG: | |
9434 | case CONCAT: | |
9435 | descr = loc_descriptor (rtl); | |
9436 | } | |
9437 | add_AT_location_description (die, DW_AT_location, descr); | |
a3f97cbb | 9438 | break; |
b9203463 | 9439 | |
a3f97cbb | 9440 | default: |
71dfc51f | 9441 | abort (); |
a3f97cbb JW |
9442 | } |
9443 | } | |
9444 | ||
1bfb5f8f JM |
9445 | /* If we don't have a copy of this variable in memory for some reason (such |
9446 | as a C++ member constant that doesn't have an out-of-line definition), | |
9447 | we should tell the debugger about the constant value. */ | |
9448 | ||
9449 | static void | |
9450 | tree_add_const_value_attribute (var_die, decl) | |
9451 | dw_die_ref var_die; | |
9452 | tree decl; | |
9453 | { | |
9454 | tree init = DECL_INITIAL (decl); | |
9455 | tree type = TREE_TYPE (decl); | |
9456 | ||
9457 | if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init | |
9458 | && initializer_constant_valid_p (init, type) == null_pointer_node) | |
9459 | /* OK */; | |
9460 | else | |
9461 | return; | |
9462 | ||
9463 | switch (TREE_CODE (type)) | |
9464 | { | |
9465 | case INTEGER_TYPE: | |
9466 | if (host_integerp (init, 0)) | |
9467 | add_AT_unsigned (var_die, DW_AT_const_value, | |
2ad9852d | 9468 | tree_low_cst (init, 0)); |
1bfb5f8f JM |
9469 | else |
9470 | add_AT_long_long (var_die, DW_AT_const_value, | |
9471 | TREE_INT_CST_HIGH (init), | |
9472 | TREE_INT_CST_LOW (init)); | |
9473 | break; | |
9474 | ||
9475 | default:; | |
9476 | } | |
9477 | } | |
0b34cf1e | 9478 | |
a3f97cbb JW |
9479 | /* Generate an DW_AT_name attribute given some string value to be included as |
9480 | the value of the attribute. */ | |
71dfc51f RK |
9481 | |
9482 | static inline void | |
a3f97cbb | 9483 | add_name_attribute (die, name_string) |
b3694847 SS |
9484 | dw_die_ref die; |
9485 | const char *name_string; | |
a3f97cbb | 9486 | { |
71dfc51f | 9487 | if (name_string != NULL && *name_string != 0) |
14a774a9 RK |
9488 | { |
9489 | if (demangle_name_func) | |
9490 | name_string = (*demangle_name_func) (name_string); | |
9491 | ||
9492 | add_AT_string (die, DW_AT_name, name_string); | |
9493 | } | |
a3f97cbb JW |
9494 | } |
9495 | ||
9496 | /* Given a tree node describing an array bound (either lower or upper) output | |
466446b0 | 9497 | a representation for that bound. */ |
71dfc51f | 9498 | |
a3f97cbb JW |
9499 | static void |
9500 | add_bound_info (subrange_die, bound_attr, bound) | |
b3694847 SS |
9501 | dw_die_ref subrange_die; |
9502 | enum dwarf_attribute bound_attr; | |
9503 | tree bound; | |
a3f97cbb | 9504 | { |
a3f97cbb JW |
9505 | switch (TREE_CODE (bound)) |
9506 | { | |
9507 | case ERROR_MARK: | |
9508 | return; | |
9509 | ||
3ef42a0c | 9510 | /* All fixed-bounds are represented by INTEGER_CST nodes. */ |
a3f97cbb | 9511 | case INTEGER_CST: |
665f2503 RK |
9512 | if (! host_integerp (bound, 0) |
9513 | || (bound_attr == DW_AT_lower_bound | |
28985b81 | 9514 | && (((is_c_family () || is_java ()) && integer_zerop (bound)) |
665f2503 RK |
9515 | || (is_fortran () && integer_onep (bound))))) |
9516 | /* use the default */ | |
9517 | ; | |
141719a8 | 9518 | else |
665f2503 | 9519 | add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0)); |
a3f97cbb JW |
9520 | break; |
9521 | ||
b1ccbc24 | 9522 | case CONVERT_EXPR: |
a3f97cbb | 9523 | case NOP_EXPR: |
b1ccbc24 | 9524 | case NON_LVALUE_EXPR: |
ed239f5a | 9525 | case VIEW_CONVERT_EXPR: |
b1ccbc24 RK |
9526 | add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0)); |
9527 | break; | |
556273e0 | 9528 | |
a3f97cbb JW |
9529 | case SAVE_EXPR: |
9530 | /* If optimization is turned on, the SAVE_EXPRs that describe how to | |
466446b0 JM |
9531 | access the upper bound values may be bogus. If they refer to a |
9532 | register, they may only describe how to get at these values at the | |
9533 | points in the generated code right after they have just been | |
9534 | computed. Worse yet, in the typical case, the upper bound values | |
9535 | will not even *be* computed in the optimized code (though the | |
9536 | number of elements will), so these SAVE_EXPRs are entirely | |
9537 | bogus. In order to compensate for this fact, we check here to see | |
9538 | if optimization is enabled, and if so, we don't add an attribute | |
9539 | for the (unknown and unknowable) upper bound. This should not | |
9540 | cause too much trouble for existing (stupid?) debuggers because | |
9541 | they have to deal with empty upper bounds location descriptions | |
9542 | anyway in order to be able to deal with incomplete array types. | |
9543 | Of course an intelligent debugger (GDB?) should be able to | |
4fe9b91c | 9544 | comprehend that a missing upper bound specification in an array |
466446b0 JM |
9545 | type used for a storage class `auto' local array variable |
9546 | indicates that the upper bound is both unknown (at compile- time) | |
9547 | and unknowable (at run-time) due to optimization. | |
9548 | ||
9549 | We assume that a MEM rtx is safe because gcc wouldn't put the | |
9550 | value there unless it was going to be used repeatedly in the | |
9551 | function, i.e. for cleanups. */ | |
1edf43d6 JM |
9552 | if (SAVE_EXPR_RTL (bound) |
9553 | && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)) | |
a3f97cbb | 9554 | { |
b3694847 | 9555 | dw_die_ref ctx = lookup_decl_die (current_function_decl); |
54ba1f0d | 9556 | dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound); |
b3694847 | 9557 | rtx loc = SAVE_EXPR_RTL (bound); |
f5963e61 JL |
9558 | |
9559 | /* If the RTL for the SAVE_EXPR is memory, handle the case where | |
9560 | it references an outer function's frame. */ | |
f5963e61 JL |
9561 | if (GET_CODE (loc) == MEM) |
9562 | { | |
9563 | rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound); | |
9564 | ||
9565 | if (XEXP (loc, 0) != new_addr) | |
c5c76735 | 9566 | loc = gen_rtx_MEM (GET_MODE (loc), new_addr); |
f5963e61 JL |
9567 | } |
9568 | ||
466446b0 JM |
9569 | add_AT_flag (decl_die, DW_AT_artificial, 1); |
9570 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
b9203463 RH |
9571 | add_AT_location_description (decl_die, DW_AT_location, |
9572 | loc_descriptor (loc)); | |
466446b0 | 9573 | add_AT_die_ref (subrange_die, bound_attr, decl_die); |
a3f97cbb | 9574 | } |
71dfc51f RK |
9575 | |
9576 | /* Else leave out the attribute. */ | |
a3f97cbb | 9577 | break; |
3f76745e | 9578 | |
ef76d03b | 9579 | case VAR_DECL: |
d8041cc8 RH |
9580 | case PARM_DECL: |
9581 | { | |
9582 | dw_die_ref decl_die = lookup_decl_die (bound); | |
9583 | ||
9584 | /* ??? Can this happen, or should the variable have been bound | |
9585 | first? Probably it can, since I imagine that we try to create | |
9586 | the types of parameters in the order in which they exist in | |
0b34cf1e | 9587 | the list, and won't have created a forward reference to a |
d8041cc8 RH |
9588 | later parameter. */ |
9589 | if (decl_die != NULL) | |
9590 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
9591 | break; | |
9592 | } | |
ef76d03b | 9593 | |
3f76745e | 9594 | default: |
d8041cc8 RH |
9595 | { |
9596 | /* Otherwise try to create a stack operation procedure to | |
9597 | evaluate the value of the array bound. */ | |
9598 | ||
9599 | dw_die_ref ctx, decl_die; | |
9600 | dw_loc_descr_ref loc; | |
9601 | ||
9602 | loc = loc_descriptor_from_tree (bound, 0); | |
9603 | if (loc == NULL) | |
9604 | break; | |
9605 | ||
e7af1d45 RK |
9606 | if (current_function_decl == 0) |
9607 | ctx = comp_unit_die; | |
9608 | else | |
9609 | ctx = lookup_decl_die (current_function_decl); | |
d8041cc8 | 9610 | |
aea9695c RK |
9611 | /* If we weren't able to find a context, it's most likely the case |
9612 | that we are processing the return type of the function. So | |
9613 | make a SAVE_EXPR to point to it and have the limbo DIE code | |
9614 | find the proper die. The save_expr function doesn't always | |
9615 | make a SAVE_EXPR, so do it ourselves. */ | |
9616 | if (ctx == 0) | |
9617 | bound = build (SAVE_EXPR, TREE_TYPE (bound), bound, | |
9618 | current_function_decl, NULL_TREE); | |
9619 | ||
54ba1f0d | 9620 | decl_die = new_die (DW_TAG_variable, ctx, bound); |
d8041cc8 RH |
9621 | add_AT_flag (decl_die, DW_AT_artificial, 1); |
9622 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
9623 | add_AT_loc (decl_die, DW_AT_location, loc); | |
9624 | ||
9625 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
9626 | break; | |
9627 | } | |
a3f97cbb JW |
9628 | } |
9629 | } | |
9630 | ||
9631 | /* Note that the block of subscript information for an array type also | |
9632 | includes information about the element type of type given array type. */ | |
71dfc51f | 9633 | |
a3f97cbb JW |
9634 | static void |
9635 | add_subscript_info (type_die, type) | |
b3694847 SS |
9636 | dw_die_ref type_die; |
9637 | tree type; | |
a3f97cbb | 9638 | { |
081f5e7e | 9639 | #ifndef MIPS_DEBUGGING_INFO |
b3694847 | 9640 | unsigned dimension_number; |
081f5e7e | 9641 | #endif |
b3694847 SS |
9642 | tree lower, upper; |
9643 | dw_die_ref subrange_die; | |
a3f97cbb | 9644 | |
556273e0 | 9645 | /* The GNU compilers represent multidimensional array types as sequences of |
a3f97cbb JW |
9646 | one dimensional array types whose element types are themselves array |
9647 | types. Here we squish that down, so that each multidimensional array | |
556273e0 | 9648 | type gets only one array_type DIE in the Dwarf debugging info. The draft |
a3f97cbb JW |
9649 | Dwarf specification say that we are allowed to do this kind of |
9650 | compression in C (because there is no difference between an array or | |
556273e0 | 9651 | arrays and a multidimensional array in C) but for other source languages |
a3f97cbb | 9652 | (e.g. Ada) we probably shouldn't do this. */ |
71dfc51f | 9653 | |
a3f97cbb JW |
9654 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
9655 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
9656 | We work around this by disabling this feature. See also | |
9657 | gen_array_type_die. */ | |
9658 | #ifndef MIPS_DEBUGGING_INFO | |
9659 | for (dimension_number = 0; | |
9660 | TREE_CODE (type) == ARRAY_TYPE; | |
9661 | type = TREE_TYPE (type), dimension_number++) | |
a3f97cbb | 9662 | #endif |
2ad9852d | 9663 | { |
b3694847 | 9664 | tree domain = TYPE_DOMAIN (type); |
a3f97cbb JW |
9665 | |
9666 | /* Arrays come in three flavors: Unspecified bounds, fixed bounds, | |
556273e0 | 9667 | and (in GNU C only) variable bounds. Handle all three forms |
a3f97cbb | 9668 | here. */ |
54ba1f0d | 9669 | subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL); |
a3f97cbb JW |
9670 | if (domain) |
9671 | { | |
9672 | /* We have an array type with specified bounds. */ | |
9673 | lower = TYPE_MIN_VALUE (domain); | |
9674 | upper = TYPE_MAX_VALUE (domain); | |
9675 | ||
a9d38797 JM |
9676 | /* define the index type. */ |
9677 | if (TREE_TYPE (domain)) | |
ef76d03b JW |
9678 | { |
9679 | /* ??? This is probably an Ada unnamed subrange type. Ignore the | |
9680 | TREE_TYPE field. We can't emit debug info for this | |
9681 | because it is an unnamed integral type. */ | |
9682 | if (TREE_CODE (domain) == INTEGER_TYPE | |
9683 | && TYPE_NAME (domain) == NULL_TREE | |
9684 | && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE | |
9685 | && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE) | |
556273e0 | 9686 | ; |
ef76d03b JW |
9687 | else |
9688 | add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0, | |
9689 | type_die); | |
9690 | } | |
a9d38797 | 9691 | |
e1ee5cdc RH |
9692 | /* ??? If upper is NULL, the array has unspecified length, |
9693 | but it does have a lower bound. This happens with Fortran | |
9694 | dimension arr(N:*) | |
9695 | Since the debugger is definitely going to need to know N | |
9696 | to produce useful results, go ahead and output the lower | |
9697 | bound solo, and hope the debugger can cope. */ | |
9698 | ||
141719a8 | 9699 | add_bound_info (subrange_die, DW_AT_lower_bound, lower); |
e1ee5cdc RH |
9700 | if (upper) |
9701 | add_bound_info (subrange_die, DW_AT_upper_bound, upper); | |
a3f97cbb | 9702 | } |
71dfc51f | 9703 | |
2ad9852d RK |
9704 | /* Otherwise we have an array type with an unspecified length. The |
9705 | DWARF-2 spec does not say how to handle this; let's just leave out the | |
9706 | bounds. */ | |
a3f97cbb | 9707 | } |
a3f97cbb JW |
9708 | } |
9709 | ||
9710 | static void | |
9711 | add_byte_size_attribute (die, tree_node) | |
9712 | dw_die_ref die; | |
b3694847 | 9713 | tree tree_node; |
a3f97cbb | 9714 | { |
b3694847 | 9715 | unsigned size; |
a3f97cbb JW |
9716 | |
9717 | switch (TREE_CODE (tree_node)) | |
9718 | { | |
9719 | case ERROR_MARK: | |
9720 | size = 0; | |
9721 | break; | |
9722 | case ENUMERAL_TYPE: | |
9723 | case RECORD_TYPE: | |
9724 | case UNION_TYPE: | |
9725 | case QUAL_UNION_TYPE: | |
9726 | size = int_size_in_bytes (tree_node); | |
9727 | break; | |
9728 | case FIELD_DECL: | |
9729 | /* For a data member of a struct or union, the DW_AT_byte_size is | |
9730 | generally given as the number of bytes normally allocated for an | |
9731 | object of the *declared* type of the member itself. This is true | |
9732 | even for bit-fields. */ | |
9733 | size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT; | |
9734 | break; | |
9735 | default: | |
9736 | abort (); | |
9737 | } | |
9738 | ||
9739 | /* Note that `size' might be -1 when we get to this point. If it is, that | |
9740 | indicates that the byte size of the entity in question is variable. We | |
9741 | have no good way of expressing this fact in Dwarf at the present time, | |
9742 | so just let the -1 pass on through. */ | |
a3f97cbb JW |
9743 | add_AT_unsigned (die, DW_AT_byte_size, size); |
9744 | } | |
9745 | ||
9746 | /* For a FIELD_DECL node which represents a bit-field, output an attribute | |
9747 | which specifies the distance in bits from the highest order bit of the | |
9748 | "containing object" for the bit-field to the highest order bit of the | |
9749 | bit-field itself. | |
9750 | ||
2ad9852d RK |
9751 | For any given bit-field, the "containing object" is a hypothetical object |
9752 | (of some integral or enum type) within which the given bit-field lives. The | |
9753 | type of this hypothetical "containing object" is always the same as the | |
9754 | declared type of the individual bit-field itself. The determination of the | |
9755 | exact location of the "containing object" for a bit-field is rather | |
9756 | complicated. It's handled by the `field_byte_offset' function (above). | |
a3f97cbb JW |
9757 | |
9758 | Note that it is the size (in bytes) of the hypothetical "containing object" | |
9759 | which will be given in the DW_AT_byte_size attribute for this bit-field. | |
9760 | (See `byte_size_attribute' above). */ | |
71dfc51f RK |
9761 | |
9762 | static inline void | |
a3f97cbb | 9763 | add_bit_offset_attribute (die, decl) |
b3694847 SS |
9764 | dw_die_ref die; |
9765 | tree decl; | |
a3f97cbb | 9766 | { |
665f2503 RK |
9767 | HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl); |
9768 | tree type = DECL_BIT_FIELD_TYPE (decl); | |
9769 | HOST_WIDE_INT bitpos_int; | |
9770 | HOST_WIDE_INT highest_order_object_bit_offset; | |
9771 | HOST_WIDE_INT highest_order_field_bit_offset; | |
9772 | HOST_WIDE_INT unsigned bit_offset; | |
a3f97cbb | 9773 | |
3a88cbd1 JL |
9774 | /* Must be a field and a bit field. */ |
9775 | if (!type | |
9776 | || TREE_CODE (decl) != FIELD_DECL) | |
9777 | abort (); | |
a3f97cbb JW |
9778 | |
9779 | /* We can't yet handle bit-fields whose offsets are variable, so if we | |
9780 | encounter such things, just return without generating any attribute | |
665f2503 RK |
9781 | whatsoever. Likewise for variable or too large size. */ |
9782 | if (! host_integerp (bit_position (decl), 0) | |
9783 | || ! host_integerp (DECL_SIZE (decl), 1)) | |
71dfc51f RK |
9784 | return; |
9785 | ||
665f2503 | 9786 | bitpos_int = int_bit_position (decl); |
a3f97cbb JW |
9787 | |
9788 | /* Note that the bit offset is always the distance (in bits) from the | |
556273e0 KH |
9789 | highest-order bit of the "containing object" to the highest-order bit of |
9790 | the bit-field itself. Since the "high-order end" of any object or field | |
a3f97cbb JW |
9791 | is different on big-endian and little-endian machines, the computation |
9792 | below must take account of these differences. */ | |
9793 | highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; | |
9794 | highest_order_field_bit_offset = bitpos_int; | |
9795 | ||
71dfc51f | 9796 | if (! BYTES_BIG_ENDIAN) |
a3f97cbb | 9797 | { |
665f2503 | 9798 | highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0); |
a3f97cbb JW |
9799 | highest_order_object_bit_offset += simple_type_size_in_bits (type); |
9800 | } | |
71dfc51f RK |
9801 | |
9802 | bit_offset | |
9803 | = (! BYTES_BIG_ENDIAN | |
9804 | ? highest_order_object_bit_offset - highest_order_field_bit_offset | |
9805 | : highest_order_field_bit_offset - highest_order_object_bit_offset); | |
a3f97cbb JW |
9806 | |
9807 | add_AT_unsigned (die, DW_AT_bit_offset, bit_offset); | |
9808 | } | |
9809 | ||
9810 | /* For a FIELD_DECL node which represents a bit field, output an attribute | |
9811 | which specifies the length in bits of the given field. */ | |
71dfc51f RK |
9812 | |
9813 | static inline void | |
a3f97cbb | 9814 | add_bit_size_attribute (die, decl) |
b3694847 SS |
9815 | dw_die_ref die; |
9816 | tree decl; | |
a3f97cbb | 9817 | { |
3a88cbd1 JL |
9818 | /* Must be a field and a bit field. */ |
9819 | if (TREE_CODE (decl) != FIELD_DECL | |
9820 | || ! DECL_BIT_FIELD_TYPE (decl)) | |
9821 | abort (); | |
665f2503 RK |
9822 | |
9823 | if (host_integerp (DECL_SIZE (decl), 1)) | |
9824 | add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1)); | |
a3f97cbb JW |
9825 | } |
9826 | ||
88dad228 | 9827 | /* If the compiled language is ANSI C, then add a 'prototyped' |
a3f97cbb | 9828 | attribute, if arg types are given for the parameters of a function. */ |
71dfc51f RK |
9829 | |
9830 | static inline void | |
a3f97cbb | 9831 | add_prototyped_attribute (die, func_type) |
b3694847 SS |
9832 | dw_die_ref die; |
9833 | tree func_type; | |
a3f97cbb | 9834 | { |
88dad228 JM |
9835 | if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89 |
9836 | && TYPE_ARG_TYPES (func_type) != NULL) | |
9837 | add_AT_flag (die, DW_AT_prototyped, 1); | |
a3f97cbb JW |
9838 | } |
9839 | ||
a3f97cbb JW |
9840 | /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found |
9841 | by looking in either the type declaration or object declaration | |
9842 | equate table. */ | |
71dfc51f RK |
9843 | |
9844 | static inline void | |
a3f97cbb | 9845 | add_abstract_origin_attribute (die, origin) |
b3694847 SS |
9846 | dw_die_ref die; |
9847 | tree origin; | |
a3f97cbb JW |
9848 | { |
9849 | dw_die_ref origin_die = NULL; | |
bbc6ae08 | 9850 | |
d10b8e05 | 9851 | if (TREE_CODE (origin) != FUNCTION_DECL) |
e40a1c67 JM |
9852 | { |
9853 | /* We may have gotten separated from the block for the inlined | |
9854 | function, if we're in an exception handler or some such; make | |
9855 | sure that the abstract function has been written out. | |
9856 | ||
9857 | Doing this for nested functions is wrong, however; functions are | |
9858 | distinct units, and our context might not even be inline. */ | |
fb13d4d0 | 9859 | tree fn = origin; |
2ad9852d | 9860 | |
fb13d4d0 JM |
9861 | if (TYPE_P (fn)) |
9862 | fn = TYPE_STUB_DECL (fn); | |
2ad9852d | 9863 | |
fb13d4d0 | 9864 | fn = decl_function_context (fn); |
e40a1c67 | 9865 | if (fn) |
1edf43d6 | 9866 | dwarf2out_abstract_function (fn); |
e40a1c67 | 9867 | } |
44db1d9c | 9868 | |
2f939d94 | 9869 | if (DECL_P (origin)) |
71dfc51f | 9870 | origin_die = lookup_decl_die (origin); |
2f939d94 | 9871 | else if (TYPE_P (origin)) |
71dfc51f RK |
9872 | origin_die = lookup_type_die (origin); |
9873 | ||
bbc6ae08 | 9874 | if (origin_die == NULL) |
1ae8994f | 9875 | abort (); |
556273e0 | 9876 | |
a3f97cbb JW |
9877 | add_AT_die_ref (die, DW_AT_abstract_origin, origin_die); |
9878 | } | |
9879 | ||
bdb669cb JM |
9880 | /* We do not currently support the pure_virtual attribute. */ |
9881 | ||
71dfc51f | 9882 | static inline void |
a3f97cbb | 9883 | add_pure_or_virtual_attribute (die, func_decl) |
b3694847 SS |
9884 | dw_die_ref die; |
9885 | tree func_decl; | |
a3f97cbb | 9886 | { |
a94dbf2c | 9887 | if (DECL_VINDEX (func_decl)) |
a3f97cbb | 9888 | { |
bdb669cb | 9889 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); |
665f2503 RK |
9890 | |
9891 | if (host_integerp (DECL_VINDEX (func_decl), 0)) | |
9892 | add_AT_loc (die, DW_AT_vtable_elem_location, | |
9893 | new_loc_descr (DW_OP_constu, | |
9894 | tree_low_cst (DECL_VINDEX (func_decl), 0), | |
9895 | 0)); | |
71dfc51f | 9896 | |
a94dbf2c JM |
9897 | /* GNU extension: Record what type this method came from originally. */ |
9898 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
9899 | add_AT_die_ref (die, DW_AT_containing_type, | |
9900 | lookup_type_die (DECL_CONTEXT (func_decl))); | |
a3f97cbb JW |
9901 | } |
9902 | } | |
9903 | \f | |
b2932ae5 | 9904 | /* Add source coordinate attributes for the given decl. */ |
71dfc51f | 9905 | |
b2932ae5 JM |
9906 | static void |
9907 | add_src_coords_attributes (die, decl) | |
b3694847 SS |
9908 | dw_die_ref die; |
9909 | tree decl; | |
b2932ae5 | 9910 | { |
b3694847 | 9911 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
71dfc51f | 9912 | |
b2932ae5 JM |
9913 | add_AT_unsigned (die, DW_AT_decl_file, file_index); |
9914 | add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
9915 | } | |
9916 | ||
a3f97cbb JW |
9917 | /* Add an DW_AT_name attribute and source coordinate attribute for the |
9918 | given decl, but only if it actually has a name. */ | |
71dfc51f | 9919 | |
a3f97cbb JW |
9920 | static void |
9921 | add_name_and_src_coords_attributes (die, decl) | |
b3694847 SS |
9922 | dw_die_ref die; |
9923 | tree decl; | |
a3f97cbb | 9924 | { |
b3694847 | 9925 | tree decl_name; |
71dfc51f | 9926 | |
556273e0 | 9927 | decl_name = DECL_NAME (decl); |
71dfc51f | 9928 | if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL) |
a3f97cbb | 9929 | { |
a1d7ffe3 | 9930 | add_name_attribute (die, dwarf2_name (decl, 0)); |
a96c67ec JM |
9931 | if (! DECL_ARTIFICIAL (decl)) |
9932 | add_src_coords_attributes (die, decl); | |
e689ae67 | 9933 | |
a1d7ffe3 | 9934 | if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) |
bc808e0b | 9935 | && TREE_PUBLIC (decl) |
5daf7c0a JM |
9936 | && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) |
9937 | && !DECL_ABSTRACT (decl)) | |
a1d7ffe3 JM |
9938 | add_AT_string (die, DW_AT_MIPS_linkage_name, |
9939 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
a3f97cbb | 9940 | } |
7a0c8d71 DR |
9941 | |
9942 | #ifdef VMS_DEBUGGING_INFO | |
7a0c8d71 DR |
9943 | /* Get the function's name, as described by its RTL. This may be different |
9944 | from the DECL_NAME name used in the source file. */ | |
9945 | if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl)) | |
c470afad RK |
9946 | { |
9947 | add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address, | |
9948 | XEXP (DECL_RTL (decl), 0)); | |
9949 | VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0)); | |
9950 | } | |
7a0c8d71 | 9951 | #endif |
a3f97cbb JW |
9952 | } |
9953 | ||
556273e0 | 9954 | /* Push a new declaration scope. */ |
71dfc51f | 9955 | |
a3f97cbb JW |
9956 | static void |
9957 | push_decl_scope (scope) | |
9958 | tree scope; | |
9959 | { | |
244a4af0 | 9960 | VARRAY_PUSH_TREE (decl_scope_table, scope); |
a3f97cbb JW |
9961 | } |
9962 | ||
777ad4c2 | 9963 | /* Pop a declaration scope. */ |
2ad9852d | 9964 | |
777ad4c2 JM |
9965 | static inline void |
9966 | pop_decl_scope () | |
9967 | { | |
244a4af0 | 9968 | if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0) |
777ad4c2 | 9969 | abort (); |
2ad9852d | 9970 | |
244a4af0 | 9971 | VARRAY_POP (decl_scope_table); |
777ad4c2 JM |
9972 | } |
9973 | ||
9974 | /* Return the DIE for the scope that immediately contains this type. | |
9975 | Non-named types get global scope. Named types nested in other | |
9976 | types get their containing scope if it's open, or global scope | |
9977 | otherwise. All other types (i.e. function-local named types) get | |
9978 | the current active scope. */ | |
71dfc51f | 9979 | |
a3f97cbb | 9980 | static dw_die_ref |
ab72d377 | 9981 | scope_die_for (t, context_die) |
b3694847 SS |
9982 | tree t; |
9983 | dw_die_ref context_die; | |
a3f97cbb | 9984 | { |
b3694847 SS |
9985 | dw_die_ref scope_die = NULL; |
9986 | tree containing_scope; | |
9987 | int i; | |
a3f97cbb | 9988 | |
777ad4c2 JM |
9989 | /* Non-types always go in the current scope. */ |
9990 | if (! TYPE_P (t)) | |
9991 | abort (); | |
9992 | ||
9993 | containing_scope = TYPE_CONTEXT (t); | |
ab72d377 | 9994 | |
2addbe1d JM |
9995 | /* Ignore namespaces for the moment. */ |
9996 | if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL) | |
9997 | containing_scope = NULL_TREE; | |
9998 | ||
5f2f160c JM |
9999 | /* Ignore function type "scopes" from the C frontend. They mean that |
10000 | a tagged type is local to a parmlist of a function declarator, but | |
10001 | that isn't useful to DWARF. */ | |
10002 | if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE) | |
10003 | containing_scope = NULL_TREE; | |
10004 | ||
71dfc51f RK |
10005 | if (containing_scope == NULL_TREE) |
10006 | scope_die = comp_unit_die; | |
777ad4c2 | 10007 | else if (TYPE_P (containing_scope)) |
348bb3c7 | 10008 | { |
777ad4c2 JM |
10009 | /* For types, we can just look up the appropriate DIE. But |
10010 | first we check to see if we're in the middle of emitting it | |
10011 | so we know where the new DIE should go. */ | |
244a4af0 TF |
10012 | for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i) |
10013 | if (VARRAY_TREE (decl_scope_table, i) == containing_scope) | |
348bb3c7 JM |
10014 | break; |
10015 | ||
10016 | if (i < 0) | |
10017 | { | |
348bb3c7 JM |
10018 | if (debug_info_level > DINFO_LEVEL_TERSE |
10019 | && !TREE_ASM_WRITTEN (containing_scope)) | |
10020 | abort (); | |
10021 | ||
10022 | /* If none of the current dies are suitable, we get file scope. */ | |
10023 | scope_die = comp_unit_die; | |
10024 | } | |
10025 | else | |
777ad4c2 | 10026 | scope_die = lookup_type_die (containing_scope); |
348bb3c7 | 10027 | } |
a3f97cbb | 10028 | else |
777ad4c2 | 10029 | scope_die = context_die; |
71dfc51f | 10030 | |
a3f97cbb JW |
10031 | return scope_die; |
10032 | } | |
10033 | ||
2ad9852d | 10034 | /* Returns nonzero if CONTEXT_DIE is internal to a function. */ |
777ad4c2 JM |
10035 | |
10036 | static inline int | |
10037 | local_scope_p (context_die) | |
10038 | dw_die_ref context_die; | |
a3f97cbb | 10039 | { |
777ad4c2 JM |
10040 | for (; context_die; context_die = context_die->die_parent) |
10041 | if (context_die->die_tag == DW_TAG_inlined_subroutine | |
10042 | || context_die->die_tag == DW_TAG_subprogram) | |
10043 | return 1; | |
2ad9852d | 10044 | |
777ad4c2 | 10045 | return 0; |
a3f97cbb JW |
10046 | } |
10047 | ||
2ad9852d | 10048 | /* Returns nonzero if CONTEXT_DIE is a class. */ |
9765e357 JM |
10049 | |
10050 | static inline int | |
10051 | class_scope_p (context_die) | |
10052 | dw_die_ref context_die; | |
10053 | { | |
10054 | return (context_die | |
10055 | && (context_die->die_tag == DW_TAG_structure_type | |
10056 | || context_die->die_tag == DW_TAG_union_type)); | |
10057 | } | |
10058 | ||
a3f97cbb JW |
10059 | /* Many forms of DIEs require a "type description" attribute. This |
10060 | routine locates the proper "type descriptor" die for the type given | |
10061 | by 'type', and adds an DW_AT_type attribute below the given die. */ | |
71dfc51f | 10062 | |
a3f97cbb JW |
10063 | static void |
10064 | add_type_attribute (object_die, type, decl_const, decl_volatile, context_die) | |
b3694847 SS |
10065 | dw_die_ref object_die; |
10066 | tree type; | |
10067 | int decl_const; | |
10068 | int decl_volatile; | |
10069 | dw_die_ref context_die; | |
a3f97cbb | 10070 | { |
b3694847 SS |
10071 | enum tree_code code = TREE_CODE (type); |
10072 | dw_die_ref type_die = NULL; | |
a3f97cbb | 10073 | |
ef76d03b JW |
10074 | /* ??? If this type is an unnamed subrange type of an integral or |
10075 | floating-point type, use the inner type. This is because we have no | |
10076 | support for unnamed types in base_type_die. This can happen if this is | |
10077 | an Ada subrange type. Correct solution is emit a subrange type die. */ | |
b1ccbc24 RK |
10078 | if ((code == INTEGER_TYPE || code == REAL_TYPE) |
10079 | && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0) | |
10080 | type = TREE_TYPE (type), code = TREE_CODE (type); | |
10081 | ||
2ad9852d RK |
10082 | if (code == ERROR_MARK |
10083 | /* Handle a special case. For functions whose return type is void, we | |
10084 | generate *no* type attribute. (Note that no object may have type | |
10085 | `void', so this only applies to function return types). */ | |
10086 | || code == VOID_TYPE) | |
b1ccbc24 | 10087 | return; |
a3f97cbb | 10088 | |
a3f97cbb JW |
10089 | type_die = modified_type_die (type, |
10090 | decl_const || TYPE_READONLY (type), | |
10091 | decl_volatile || TYPE_VOLATILE (type), | |
ab72d377 | 10092 | context_die); |
2ad9852d | 10093 | |
a3f97cbb | 10094 | if (type_die != NULL) |
71dfc51f | 10095 | add_AT_die_ref (object_die, DW_AT_type, type_die); |
a3f97cbb JW |
10096 | } |
10097 | ||
10098 | /* Given a tree pointer to a struct, class, union, or enum type node, return | |
10099 | a pointer to the (string) tag name for the given type, or zero if the type | |
10100 | was declared without a tag. */ | |
71dfc51f | 10101 | |
d3e3972c | 10102 | static const char * |
a3f97cbb | 10103 | type_tag (type) |
b3694847 | 10104 | tree type; |
a3f97cbb | 10105 | { |
b3694847 | 10106 | const char *name = 0; |
a3f97cbb JW |
10107 | |
10108 | if (TYPE_NAME (type) != 0) | |
10109 | { | |
b3694847 | 10110 | tree t = 0; |
a3f97cbb JW |
10111 | |
10112 | /* Find the IDENTIFIER_NODE for the type name. */ | |
10113 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
10114 | t = TYPE_NAME (type); | |
bdb669cb | 10115 | |
556273e0 | 10116 | /* The g++ front end makes the TYPE_NAME of *each* tagged type point to |
a3f97cbb | 10117 | a TYPE_DECL node, regardless of whether or not a `typedef' was |
bdb669cb | 10118 | involved. */ |
a94dbf2c JM |
10119 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
10120 | && ! DECL_IGNORED_P (TYPE_NAME (type))) | |
a3f97cbb | 10121 | t = DECL_NAME (TYPE_NAME (type)); |
bdb669cb | 10122 | |
a3f97cbb JW |
10123 | /* Now get the name as a string, or invent one. */ |
10124 | if (t != 0) | |
a94dbf2c | 10125 | name = IDENTIFIER_POINTER (t); |
a3f97cbb | 10126 | } |
71dfc51f | 10127 | |
a3f97cbb JW |
10128 | return (name == 0 || *name == '\0') ? 0 : name; |
10129 | } | |
10130 | ||
10131 | /* Return the type associated with a data member, make a special check | |
10132 | for bit field types. */ | |
71dfc51f RK |
10133 | |
10134 | static inline tree | |
a3f97cbb | 10135 | member_declared_type (member) |
b3694847 | 10136 | tree member; |
a3f97cbb | 10137 | { |
71dfc51f | 10138 | return (DECL_BIT_FIELD_TYPE (member) |
2ad9852d | 10139 | ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member)); |
a3f97cbb JW |
10140 | } |
10141 | ||
d291dd49 | 10142 | /* Get the decl's label, as described by its RTL. This may be different |
a3f97cbb | 10143 | from the DECL_NAME name used in the source file. */ |
71dfc51f | 10144 | |
487a6e06 | 10145 | #if 0 |
d3e3972c | 10146 | static const char * |
d291dd49 | 10147 | decl_start_label (decl) |
b3694847 | 10148 | tree decl; |
a3f97cbb JW |
10149 | { |
10150 | rtx x; | |
d3e3972c | 10151 | const char *fnname; |
2ad9852d | 10152 | |
a3f97cbb JW |
10153 | x = DECL_RTL (decl); |
10154 | if (GET_CODE (x) != MEM) | |
71dfc51f RK |
10155 | abort (); |
10156 | ||
a3f97cbb JW |
10157 | x = XEXP (x, 0); |
10158 | if (GET_CODE (x) != SYMBOL_REF) | |
71dfc51f RK |
10159 | abort (); |
10160 | ||
a3f97cbb JW |
10161 | fnname = XSTR (x, 0); |
10162 | return fnname; | |
10163 | } | |
487a6e06 | 10164 | #endif |
a3f97cbb | 10165 | \f |
956d6950 | 10166 | /* These routines generate the internal representation of the DIE's for |
a3f97cbb | 10167 | the compilation unit. Debugging information is collected by walking |
88dad228 | 10168 | the declaration trees passed in from dwarf2out_decl(). */ |
a3f97cbb JW |
10169 | |
10170 | static void | |
10171 | gen_array_type_die (type, context_die) | |
b3694847 SS |
10172 | tree type; |
10173 | dw_die_ref context_die; | |
a3f97cbb | 10174 | { |
b3694847 SS |
10175 | dw_die_ref scope_die = scope_die_for (type, context_die); |
10176 | dw_die_ref array_die; | |
10177 | tree element_type; | |
bdb669cb | 10178 | |
a9d38797 JM |
10179 | /* ??? The SGI dwarf reader fails for array of array of enum types unless |
10180 | the inner array type comes before the outer array type. Thus we must | |
10181 | call gen_type_die before we call new_die. See below also. */ | |
10182 | #ifdef MIPS_DEBUGGING_INFO | |
10183 | gen_type_die (TREE_TYPE (type), context_die); | |
10184 | #endif | |
10185 | ||
54ba1f0d | 10186 | array_die = new_die (DW_TAG_array_type, scope_die, type); |
84f0ace0 JM |
10187 | add_name_attribute (array_die, type_tag (type)); |
10188 | equate_type_number_to_die (type, array_die); | |
10189 | ||
10190 | if (TREE_CODE (type) == VECTOR_TYPE) | |
10191 | { | |
10192 | /* The frontend feeds us a representation for the vector as a struct | |
10193 | containing an array. Pull out the array type. */ | |
10194 | type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type))); | |
10195 | add_AT_flag (array_die, DW_AT_GNU_vector, 1); | |
10196 | } | |
a9d38797 | 10197 | |
a3f97cbb JW |
10198 | #if 0 |
10199 | /* We default the array ordering. SDB will probably do | |
10200 | the right things even if DW_AT_ordering is not present. It's not even | |
10201 | an issue until we start to get into multidimensional arrays anyway. If | |
10202 | SDB is ever caught doing the Wrong Thing for multi-dimensional arrays, | |
10203 | then we'll have to put the DW_AT_ordering attribute back in. (But if | |
10204 | and when we find out that we need to put these in, we will only do so | |
10205 | for multidimensional arrays. */ | |
10206 | add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major); | |
10207 | #endif | |
10208 | ||
a9d38797 | 10209 | #ifdef MIPS_DEBUGGING_INFO |
4edb7b60 JM |
10210 | /* The SGI compilers handle arrays of unknown bound by setting |
10211 | AT_declaration and not emitting any subrange DIEs. */ | |
a9d38797 JM |
10212 | if (! TYPE_DOMAIN (type)) |
10213 | add_AT_unsigned (array_die, DW_AT_declaration, 1); | |
10214 | else | |
10215 | #endif | |
10216 | add_subscript_info (array_die, type); | |
a3f97cbb | 10217 | |
a3f97cbb JW |
10218 | /* Add representation of the type of the elements of this array type. */ |
10219 | element_type = TREE_TYPE (type); | |
71dfc51f | 10220 | |
a3f97cbb JW |
10221 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
10222 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
10223 | We work around this by disabling this feature. See also | |
10224 | add_subscript_info. */ | |
10225 | #ifndef MIPS_DEBUGGING_INFO | |
71dfc51f RK |
10226 | while (TREE_CODE (element_type) == ARRAY_TYPE) |
10227 | element_type = TREE_TYPE (element_type); | |
10228 | ||
a3f97cbb | 10229 | gen_type_die (element_type, context_die); |
a9d38797 | 10230 | #endif |
a3f97cbb JW |
10231 | |
10232 | add_type_attribute (array_die, element_type, 0, 0, context_die); | |
10233 | } | |
10234 | ||
10235 | static void | |
10236 | gen_set_type_die (type, context_die) | |
b3694847 SS |
10237 | tree type; |
10238 | dw_die_ref context_die; | |
a3f97cbb | 10239 | { |
b3694847 | 10240 | dw_die_ref type_die |
54ba1f0d | 10241 | = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type); |
71dfc51f | 10242 | |
a3f97cbb | 10243 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
10244 | add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die); |
10245 | } | |
10246 | ||
d6f4ec51 | 10247 | #if 0 |
a3f97cbb JW |
10248 | static void |
10249 | gen_entry_point_die (decl, context_die) | |
b3694847 SS |
10250 | tree decl; |
10251 | dw_die_ref context_die; | |
a3f97cbb | 10252 | { |
b3694847 | 10253 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 10254 | dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl); |
2ad9852d | 10255 | |
a3f97cbb | 10256 | if (origin != NULL) |
71dfc51f | 10257 | add_abstract_origin_attribute (decl_die, origin); |
a3f97cbb JW |
10258 | else |
10259 | { | |
10260 | add_name_and_src_coords_attributes (decl_die, decl); | |
a3f97cbb JW |
10261 | add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)), |
10262 | 0, 0, context_die); | |
10263 | } | |
71dfc51f | 10264 | |
a3f97cbb | 10265 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 10266 | equate_decl_number_to_die (decl, decl_die); |
a3f97cbb | 10267 | else |
71dfc51f | 10268 | add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl)); |
a3f97cbb | 10269 | } |
d6f4ec51 | 10270 | #endif |
a3f97cbb | 10271 | |
8a8c3656 JM |
10272 | /* Walk through the list of incomplete types again, trying once more to |
10273 | emit full debugging info for them. */ | |
10274 | ||
10275 | static void | |
10276 | retry_incomplete_types () | |
10277 | { | |
244a4af0 | 10278 | int i; |
2ad9852d | 10279 | |
244a4af0 | 10280 | for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--) |
2ad9852d | 10281 | gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die); |
8a8c3656 JM |
10282 | } |
10283 | ||
a3f97cbb | 10284 | /* Generate a DIE to represent an inlined instance of an enumeration type. */ |
71dfc51f | 10285 | |
a3f97cbb JW |
10286 | static void |
10287 | gen_inlined_enumeration_type_die (type, context_die) | |
b3694847 SS |
10288 | tree type; |
10289 | dw_die_ref context_die; | |
a3f97cbb | 10290 | { |
54ba1f0d | 10291 | dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type); |
2ad9852d | 10292 | |
bbc6ae08 NC |
10293 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
10294 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
10295 | add_abstract_origin_attribute (type_die, type); |
10296 | } | |
10297 | ||
10298 | /* Generate a DIE to represent an inlined instance of a structure type. */ | |
71dfc51f | 10299 | |
a3f97cbb JW |
10300 | static void |
10301 | gen_inlined_structure_type_die (type, context_die) | |
b3694847 SS |
10302 | tree type; |
10303 | dw_die_ref context_die; | |
a3f97cbb | 10304 | { |
54ba1f0d | 10305 | dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type); |
777ad4c2 | 10306 | |
bbc6ae08 NC |
10307 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
10308 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
10309 | add_abstract_origin_attribute (type_die, type); |
10310 | } | |
10311 | ||
10312 | /* Generate a DIE to represent an inlined instance of a union type. */ | |
71dfc51f | 10313 | |
a3f97cbb JW |
10314 | static void |
10315 | gen_inlined_union_type_die (type, context_die) | |
b3694847 SS |
10316 | tree type; |
10317 | dw_die_ref context_die; | |
a3f97cbb | 10318 | { |
54ba1f0d | 10319 | dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type); |
777ad4c2 | 10320 | |
bbc6ae08 NC |
10321 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
10322 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
10323 | add_abstract_origin_attribute (type_die, type); |
10324 | } | |
10325 | ||
10326 | /* Generate a DIE to represent an enumeration type. Note that these DIEs | |
10327 | include all of the information about the enumeration values also. Each | |
273dbe67 JM |
10328 | enumerated type name/value is listed as a child of the enumerated type |
10329 | DIE. */ | |
71dfc51f | 10330 | |
a3f97cbb | 10331 | static void |
273dbe67 | 10332 | gen_enumeration_type_die (type, context_die) |
b3694847 SS |
10333 | tree type; |
10334 | dw_die_ref context_die; | |
a3f97cbb | 10335 | { |
b3694847 | 10336 | dw_die_ref type_die = lookup_type_die (type); |
273dbe67 | 10337 | |
a3f97cbb JW |
10338 | if (type_die == NULL) |
10339 | { | |
10340 | type_die = new_die (DW_TAG_enumeration_type, | |
54ba1f0d | 10341 | scope_die_for (type, context_die), type); |
a3f97cbb JW |
10342 | equate_type_number_to_die (type, type_die); |
10343 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 10344 | } |
273dbe67 JM |
10345 | else if (! TYPE_SIZE (type)) |
10346 | return; | |
10347 | else | |
10348 | remove_AT (type_die, DW_AT_declaration); | |
10349 | ||
10350 | /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the | |
10351 | given enum type is incomplete, do not generate the DW_AT_byte_size | |
10352 | attribute or the DW_AT_element_list attribute. */ | |
10353 | if (TYPE_SIZE (type)) | |
a3f97cbb | 10354 | { |
b3694847 | 10355 | tree link; |
71dfc51f | 10356 | |
a082c85a | 10357 | TREE_ASM_WRITTEN (type) = 1; |
273dbe67 | 10358 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 10359 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 10360 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 10361 | |
ef76d03b JW |
10362 | /* If the first reference to this type was as the return type of an |
10363 | inline function, then it may not have a parent. Fix this now. */ | |
10364 | if (type_die->die_parent == NULL) | |
10365 | add_child_die (scope_die_for (type, context_die), type_die); | |
10366 | ||
273dbe67 JM |
10367 | for (link = TYPE_FIELDS (type); |
10368 | link != NULL; link = TREE_CHAIN (link)) | |
a3f97cbb | 10369 | { |
54ba1f0d | 10370 | dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link); |
71dfc51f | 10371 | |
273dbe67 JM |
10372 | add_name_attribute (enum_die, |
10373 | IDENTIFIER_POINTER (TREE_PURPOSE (link))); | |
665f2503 RK |
10374 | |
10375 | if (host_integerp (TREE_VALUE (link), 0)) | |
fc9e8a14 JJ |
10376 | { |
10377 | if (tree_int_cst_sgn (TREE_VALUE (link)) < 0) | |
10378 | add_AT_int (enum_die, DW_AT_const_value, | |
10379 | tree_low_cst (TREE_VALUE (link), 0)); | |
10380 | else | |
10381 | add_AT_unsigned (enum_die, DW_AT_const_value, | |
10382 | tree_low_cst (TREE_VALUE (link), 0)); | |
10383 | } | |
a3f97cbb JW |
10384 | } |
10385 | } | |
273dbe67 JM |
10386 | else |
10387 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a3f97cbb JW |
10388 | } |
10389 | ||
a3f97cbb JW |
10390 | /* Generate a DIE to represent either a real live formal parameter decl or to |
10391 | represent just the type of some formal parameter position in some function | |
10392 | type. | |
71dfc51f | 10393 | |
a3f97cbb JW |
10394 | Note that this routine is a bit unusual because its argument may be a |
10395 | ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which | |
10396 | represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE | |
10397 | node. If it's the former then this function is being called to output a | |
10398 | DIE to represent a formal parameter object (or some inlining thereof). If | |
10399 | it's the latter, then this function is only being called to output a | |
10400 | DW_TAG_formal_parameter DIE to stand as a placeholder for some formal | |
10401 | argument type of some subprogram type. */ | |
71dfc51f | 10402 | |
a94dbf2c | 10403 | static dw_die_ref |
a3f97cbb | 10404 | gen_formal_parameter_die (node, context_die) |
b3694847 SS |
10405 | tree node; |
10406 | dw_die_ref context_die; | |
a3f97cbb | 10407 | { |
b3694847 | 10408 | dw_die_ref parm_die |
54ba1f0d | 10409 | = new_die (DW_TAG_formal_parameter, context_die, node); |
b3694847 | 10410 | tree origin; |
71dfc51f | 10411 | |
a3f97cbb JW |
10412 | switch (TREE_CODE_CLASS (TREE_CODE (node))) |
10413 | { | |
a3f97cbb JW |
10414 | case 'd': |
10415 | origin = decl_ultimate_origin (node); | |
10416 | if (origin != NULL) | |
a94dbf2c | 10417 | add_abstract_origin_attribute (parm_die, origin); |
a3f97cbb JW |
10418 | else |
10419 | { | |
10420 | add_name_and_src_coords_attributes (parm_die, node); | |
10421 | add_type_attribute (parm_die, TREE_TYPE (node), | |
10422 | TREE_READONLY (node), | |
10423 | TREE_THIS_VOLATILE (node), | |
10424 | context_die); | |
bdb669cb JM |
10425 | if (DECL_ARTIFICIAL (node)) |
10426 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb | 10427 | } |
71dfc51f | 10428 | |
141719a8 JM |
10429 | equate_decl_number_to_die (node, parm_die); |
10430 | if (! DECL_ABSTRACT (node)) | |
a94dbf2c | 10431 | add_location_or_const_value_attribute (parm_die, node); |
71dfc51f | 10432 | |
a3f97cbb JW |
10433 | break; |
10434 | ||
a3f97cbb | 10435 | case 't': |
71dfc51f | 10436 | /* We were called with some kind of a ..._TYPE node. */ |
a3f97cbb JW |
10437 | add_type_attribute (parm_die, node, 0, 0, context_die); |
10438 | break; | |
10439 | ||
a3f97cbb JW |
10440 | default: |
10441 | abort (); | |
10442 | } | |
71dfc51f | 10443 | |
a94dbf2c | 10444 | return parm_die; |
a3f97cbb JW |
10445 | } |
10446 | ||
10447 | /* Generate a special type of DIE used as a stand-in for a trailing ellipsis | |
10448 | at the end of an (ANSI prototyped) formal parameters list. */ | |
71dfc51f | 10449 | |
a3f97cbb JW |
10450 | static void |
10451 | gen_unspecified_parameters_die (decl_or_type, context_die) | |
54ba1f0d | 10452 | tree decl_or_type; |
b3694847 | 10453 | dw_die_ref context_die; |
a3f97cbb | 10454 | { |
54ba1f0d | 10455 | new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type); |
a3f97cbb JW |
10456 | } |
10457 | ||
10458 | /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a | |
10459 | DW_TAG_unspecified_parameters DIE) to represent the types of the formal | |
10460 | parameters as specified in some function type specification (except for | |
1cfdcc15 | 10461 | those which appear as part of a function *definition*). */ |
71dfc51f | 10462 | |
a3f97cbb JW |
10463 | static void |
10464 | gen_formal_types_die (function_or_method_type, context_die) | |
b3694847 SS |
10465 | tree function_or_method_type; |
10466 | dw_die_ref context_die; | |
a3f97cbb | 10467 | { |
b3694847 SS |
10468 | tree link; |
10469 | tree formal_type = NULL; | |
10470 | tree first_parm_type; | |
5daf7c0a | 10471 | tree arg; |
a3f97cbb | 10472 | |
5daf7c0a JM |
10473 | if (TREE_CODE (function_or_method_type) == FUNCTION_DECL) |
10474 | { | |
10475 | arg = DECL_ARGUMENTS (function_or_method_type); | |
10476 | function_or_method_type = TREE_TYPE (function_or_method_type); | |
10477 | } | |
10478 | else | |
10479 | arg = NULL_TREE; | |
c26fbbca | 10480 | |
5daf7c0a | 10481 | first_parm_type = TYPE_ARG_TYPES (function_or_method_type); |
a3f97cbb | 10482 | |
556273e0 | 10483 | /* Make our first pass over the list of formal parameter types and output a |
a3f97cbb | 10484 | DW_TAG_formal_parameter DIE for each one. */ |
5daf7c0a | 10485 | for (link = first_parm_type; link; ) |
a3f97cbb | 10486 | { |
b3694847 | 10487 | dw_die_ref parm_die; |
556273e0 | 10488 | |
a3f97cbb JW |
10489 | formal_type = TREE_VALUE (link); |
10490 | if (formal_type == void_type_node) | |
10491 | break; | |
10492 | ||
10493 | /* Output a (nameless) DIE to represent the formal parameter itself. */ | |
a94dbf2c | 10494 | parm_die = gen_formal_parameter_die (formal_type, context_die); |
5daf7c0a JM |
10495 | if ((TREE_CODE (function_or_method_type) == METHOD_TYPE |
10496 | && link == first_parm_type) | |
10497 | || (arg && DECL_ARTIFICIAL (arg))) | |
a94dbf2c | 10498 | add_AT_flag (parm_die, DW_AT_artificial, 1); |
5daf7c0a JM |
10499 | |
10500 | link = TREE_CHAIN (link); | |
10501 | if (arg) | |
10502 | arg = TREE_CHAIN (arg); | |
a3f97cbb JW |
10503 | } |
10504 | ||
10505 | /* If this function type has an ellipsis, add a | |
10506 | DW_TAG_unspecified_parameters DIE to the end of the parameter list. */ | |
10507 | if (formal_type != void_type_node) | |
10508 | gen_unspecified_parameters_die (function_or_method_type, context_die); | |
10509 | ||
556273e0 | 10510 | /* Make our second (and final) pass over the list of formal parameter types |
a3f97cbb JW |
10511 | and output DIEs to represent those types (as necessary). */ |
10512 | for (link = TYPE_ARG_TYPES (function_or_method_type); | |
2ad9852d | 10513 | link && TREE_VALUE (link); |
a3f97cbb | 10514 | link = TREE_CHAIN (link)) |
2ad9852d | 10515 | gen_type_die (TREE_VALUE (link), context_die); |
a3f97cbb JW |
10516 | } |
10517 | ||
10a11b75 JM |
10518 | /* We want to generate the DIE for TYPE so that we can generate the |
10519 | die for MEMBER, which has been defined; we will need to refer back | |
10520 | to the member declaration nested within TYPE. If we're trying to | |
10521 | generate minimal debug info for TYPE, processing TYPE won't do the | |
10522 | trick; we need to attach the member declaration by hand. */ | |
10523 | ||
10524 | static void | |
10525 | gen_type_die_for_member (type, member, context_die) | |
10526 | tree type, member; | |
10527 | dw_die_ref context_die; | |
10528 | { | |
10529 | gen_type_die (type, context_die); | |
10530 | ||
10531 | /* If we're trying to avoid duplicate debug info, we may not have | |
10532 | emitted the member decl for this function. Emit it now. */ | |
10533 | if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)) | |
10534 | && ! lookup_decl_die (member)) | |
10535 | { | |
10536 | if (decl_ultimate_origin (member)) | |
10537 | abort (); | |
10538 | ||
10539 | push_decl_scope (type); | |
10540 | if (TREE_CODE (member) == FUNCTION_DECL) | |
10541 | gen_subprogram_die (member, lookup_type_die (type)); | |
10542 | else | |
10543 | gen_variable_die (member, lookup_type_die (type)); | |
2ad9852d | 10544 | |
10a11b75 JM |
10545 | pop_decl_scope (); |
10546 | } | |
10547 | } | |
10548 | ||
2ad9852d RK |
10549 | /* Generate the DWARF2 info for the "abstract" instance of a function which we |
10550 | may later generate inlined and/or out-of-line instances of. */ | |
10a11b75 | 10551 | |
e1772ac0 | 10552 | static void |
1edf43d6 | 10553 | dwarf2out_abstract_function (decl) |
10a11b75 JM |
10554 | tree decl; |
10555 | { | |
b3694847 | 10556 | dw_die_ref old_die; |
777ad4c2 | 10557 | tree save_fn; |
5daf7c0a JM |
10558 | tree context; |
10559 | int was_abstract = DECL_ABSTRACT (decl); | |
10560 | ||
10561 | /* Make sure we have the actual abstract inline, not a clone. */ | |
10562 | decl = DECL_ORIGIN (decl); | |
10a11b75 | 10563 | |
c26fbbca | 10564 | old_die = lookup_decl_die (decl); |
10a11b75 JM |
10565 | if (old_die && get_AT_unsigned (old_die, DW_AT_inline)) |
10566 | /* We've already generated the abstract instance. */ | |
10567 | return; | |
10568 | ||
5daf7c0a JM |
10569 | /* Be sure we've emitted the in-class declaration DIE (if any) first, so |
10570 | we don't get confused by DECL_ABSTRACT. */ | |
8458e954 JS |
10571 | if (debug_info_level > DINFO_LEVEL_TERSE) |
10572 | { | |
10573 | context = decl_class_context (decl); | |
10574 | if (context) | |
10575 | gen_type_die_for_member | |
10576 | (context, decl, decl_function_context (decl) ? NULL : comp_unit_die); | |
10577 | } | |
c26fbbca | 10578 | |
5daf7c0a | 10579 | /* Pretend we've just finished compiling this function. */ |
777ad4c2 JM |
10580 | save_fn = current_function_decl; |
10581 | current_function_decl = decl; | |
10582 | ||
10a11b75 JM |
10583 | set_decl_abstract_flags (decl, 1); |
10584 | dwarf2out_decl (decl); | |
5daf7c0a JM |
10585 | if (! was_abstract) |
10586 | set_decl_abstract_flags (decl, 0); | |
777ad4c2 JM |
10587 | |
10588 | current_function_decl = save_fn; | |
10a11b75 JM |
10589 | } |
10590 | ||
a3f97cbb JW |
10591 | /* Generate a DIE to represent a declared function (either file-scope or |
10592 | block-local). */ | |
71dfc51f | 10593 | |
a3f97cbb JW |
10594 | static void |
10595 | gen_subprogram_die (decl, context_die) | |
b3694847 SS |
10596 | tree decl; |
10597 | dw_die_ref context_die; | |
a3f97cbb JW |
10598 | { |
10599 | char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 SS |
10600 | tree origin = decl_ultimate_origin (decl); |
10601 | dw_die_ref subr_die; | |
10602 | rtx fp_reg; | |
10603 | tree fn_arg_types; | |
10604 | tree outer_scope; | |
10605 | dw_die_ref old_die = lookup_decl_die (decl); | |
10606 | int declaration = (current_function_decl != decl | |
10607 | || class_scope_p (context_die)); | |
a3f97cbb | 10608 | |
2ad9852d RK |
10609 | /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we |
10610 | started to generate the abstract instance of an inline, decided to output | |
10611 | its containing class, and proceeded to emit the declaration of the inline | |
10612 | from the member list for the class. If so, DECLARATION takes priority; | |
10613 | we'll get back to the abstract instance when done with the class. */ | |
10a11b75 | 10614 | |
1cfdcc15 JM |
10615 | /* The class-scope declaration DIE must be the primary DIE. */ |
10616 | if (origin && declaration && class_scope_p (context_die)) | |
10617 | { | |
10618 | origin = NULL; | |
10619 | if (old_die) | |
10620 | abort (); | |
10621 | } | |
10622 | ||
a3f97cbb JW |
10623 | if (origin != NULL) |
10624 | { | |
777ad4c2 | 10625 | if (declaration && ! local_scope_p (context_die)) |
10a11b75 JM |
10626 | abort (); |
10627 | ||
8d8238b6 JM |
10628 | /* Fixup die_parent for the abstract instance of a nested |
10629 | inline function. */ | |
10630 | if (old_die && old_die->die_parent == NULL) | |
10631 | add_child_die (context_die, old_die); | |
10632 | ||
54ba1f0d | 10633 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
a3f97cbb JW |
10634 | add_abstract_origin_attribute (subr_die, origin); |
10635 | } | |
bdb669cb JM |
10636 | else if (old_die) |
10637 | { | |
981975b6 | 10638 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
a94dbf2c | 10639 | |
1edf43d6 JM |
10640 | if (!get_AT_flag (old_die, DW_AT_declaration) |
10641 | /* We can have a normal definition following an inline one in the | |
10642 | case of redefinition of GNU C extern inlines. | |
10643 | It seems reasonable to use AT_specification in this case. */ | |
10644 | && !get_AT_unsigned (old_die, DW_AT_inline)) | |
b75ab88b NC |
10645 | { |
10646 | /* ??? This can happen if there is a bug in the program, for | |
10647 | instance, if it has duplicate function definitions. Ideally, | |
10648 | we should detect this case and ignore it. For now, if we have | |
10649 | already reported an error, any error at all, then assume that | |
4fe9b91c | 10650 | we got here because of an input error, not a dwarf2 bug. */ |
b75ab88b NC |
10651 | if (errorcount) |
10652 | return; | |
10653 | abort (); | |
10654 | } | |
4b674448 JM |
10655 | |
10656 | /* If the definition comes from the same place as the declaration, | |
a94dbf2c JM |
10657 | maybe use the old DIE. We always want the DIE for this function |
10658 | that has the *_pc attributes to be under comp_unit_die so the | |
cb9e9d8d JM |
10659 | debugger can find it. We also need to do this for abstract |
10660 | instances of inlines, since the spec requires the out-of-line copy | |
10661 | to have the same parent. For local class methods, this doesn't | |
10662 | apply; we just use the old DIE. */ | |
10663 | if ((old_die->die_parent == comp_unit_die || context_die == NULL) | |
a96c67ec JM |
10664 | && (DECL_ARTIFICIAL (decl) |
10665 | || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index | |
10666 | && (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 10667 | == (unsigned) DECL_SOURCE_LINE (decl))))) |
bdb669cb | 10668 | { |
4b674448 JM |
10669 | subr_die = old_die; |
10670 | ||
10671 | /* Clear out the declaration attribute and the parm types. */ | |
10672 | remove_AT (subr_die, DW_AT_declaration); | |
10673 | remove_children (subr_die); | |
10674 | } | |
10675 | else | |
10676 | { | |
54ba1f0d | 10677 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
4b674448 | 10678 | add_AT_die_ref (subr_die, DW_AT_specification, old_die); |
bdb669cb JM |
10679 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
10680 | add_AT_unsigned (subr_die, DW_AT_decl_file, file_index); | |
10681 | if (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 10682 | != (unsigned) DECL_SOURCE_LINE (decl)) |
bdb669cb JM |
10683 | add_AT_unsigned |
10684 | (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
10685 | } | |
10686 | } | |
a3f97cbb JW |
10687 | else |
10688 | { | |
54ba1f0d | 10689 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
556273e0 | 10690 | |
273dbe67 JM |
10691 | if (TREE_PUBLIC (decl)) |
10692 | add_AT_flag (subr_die, DW_AT_external, 1); | |
71dfc51f | 10693 | |
a3f97cbb | 10694 | add_name_and_src_coords_attributes (subr_die, decl); |
4927276d JM |
10695 | if (debug_info_level > DINFO_LEVEL_TERSE) |
10696 | { | |
2ad9852d RK |
10697 | add_prototyped_attribute (subr_die, TREE_TYPE (decl)); |
10698 | add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)), | |
10699 | 0, 0, context_die); | |
4927276d | 10700 | } |
71dfc51f | 10701 | |
a3f97cbb | 10702 | add_pure_or_virtual_attribute (subr_die, decl); |
273dbe67 JM |
10703 | if (DECL_ARTIFICIAL (decl)) |
10704 | add_AT_flag (subr_die, DW_AT_artificial, 1); | |
2ad9852d | 10705 | |
a94dbf2c JM |
10706 | if (TREE_PROTECTED (decl)) |
10707 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected); | |
10708 | else if (TREE_PRIVATE (decl)) | |
10709 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 10710 | } |
4edb7b60 | 10711 | |
a94dbf2c JM |
10712 | if (declaration) |
10713 | { | |
2ad9852d | 10714 | if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline)) |
1edf43d6 JM |
10715 | { |
10716 | add_AT_flag (subr_die, DW_AT_declaration, 1); | |
10717 | ||
10718 | /* The first time we see a member function, it is in the context of | |
10719 | the class to which it belongs. We make sure of this by emitting | |
10720 | the class first. The next time is the definition, which is | |
10721 | handled above. The two may come from the same source text. */ | |
10722 | if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl)) | |
10723 | equate_decl_number_to_die (decl, subr_die); | |
10724 | } | |
a94dbf2c JM |
10725 | } |
10726 | else if (DECL_ABSTRACT (decl)) | |
a3f97cbb | 10727 | { |
10a11b75 | 10728 | if (DECL_INLINE (decl) && !flag_no_inline) |
61b32c02 | 10729 | { |
10a11b75 JM |
10730 | /* ??? Checking DECL_DEFER_OUTPUT is correct for static |
10731 | inline functions, but not for extern inline functions. | |
10732 | We can't get this completely correct because information | |
10733 | about whether the function was declared inline is not | |
10734 | saved anywhere. */ | |
10735 | if (DECL_DEFER_OUTPUT (decl)) | |
61b32c02 JM |
10736 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined); |
10737 | else | |
10a11b75 | 10738 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined); |
61b32c02 | 10739 | } |
61b32c02 | 10740 | else |
10a11b75 | 10741 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined); |
61b32c02 | 10742 | |
a3f97cbb JW |
10743 | equate_decl_number_to_die (decl, subr_die); |
10744 | } | |
10745 | else if (!DECL_EXTERNAL (decl)) | |
10746 | { | |
2ad9852d | 10747 | if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline)) |
ba7b35df | 10748 | equate_decl_number_to_die (decl, subr_die); |
71dfc51f | 10749 | |
5c90448c | 10750 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL, |
df696a75 | 10751 | current_function_funcdef_no); |
7d4440be | 10752 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id); |
5c90448c | 10753 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, |
df696a75 | 10754 | current_function_funcdef_no); |
a3f97cbb JW |
10755 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id); |
10756 | ||
d291dd49 JM |
10757 | add_pubname (decl, subr_die); |
10758 | add_arange (decl, subr_die); | |
10759 | ||
a3f97cbb | 10760 | #ifdef MIPS_DEBUGGING_INFO |
a3f97cbb JW |
10761 | /* Add a reference to the FDE for this routine. */ |
10762 | add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde); | |
10763 | #endif | |
10764 | ||
810429b7 JM |
10765 | /* Define the "frame base" location for this routine. We use the |
10766 | frame pointer or stack pointer registers, since the RTL for local | |
10767 | variables is relative to one of them. */ | |
b1ccbc24 RK |
10768 | fp_reg |
10769 | = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx; | |
10770 | add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg)); | |
a3f97cbb | 10771 | |
ef76d03b JW |
10772 | #if 0 |
10773 | /* ??? This fails for nested inline functions, because context_display | |
10774 | is not part of the state saved/restored for inline functions. */ | |
88dad228 | 10775 | if (current_function_needs_context) |
ef76d03b | 10776 | add_AT_location_description (subr_die, DW_AT_static_link, |
b9203463 | 10777 | loc_descriptor (lookup_static_chain (decl))); |
ef76d03b | 10778 | #endif |
a3f97cbb JW |
10779 | } |
10780 | ||
10781 | /* Now output descriptions of the arguments for this function. This gets | |
556273e0 | 10782 | (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list |
a3f97cbb JW |
10783 | for a FUNCTION_DECL doesn't indicate cases where there was a trailing |
10784 | `...' at the end of the formal parameter list. In order to find out if | |
10785 | there was a trailing ellipsis or not, we must instead look at the type | |
10786 | associated with the FUNCTION_DECL. This will be a node of type | |
10787 | FUNCTION_TYPE. If the chain of type nodes hanging off of this | |
556273e0 | 10788 | FUNCTION_TYPE node ends with a void_type_node then there should *not* be |
a3f97cbb | 10789 | an ellipsis at the end. */ |
71dfc51f | 10790 | |
a3f97cbb | 10791 | /* In the case where we are describing a mere function declaration, all we |
556273e0 | 10792 | need to do here (and all we *can* do here) is to describe the *types* of |
a3f97cbb | 10793 | its formal parameters. */ |
4927276d | 10794 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 10795 | ; |
4edb7b60 | 10796 | else if (declaration) |
5daf7c0a | 10797 | gen_formal_types_die (decl, subr_die); |
a3f97cbb JW |
10798 | else |
10799 | { | |
10800 | /* Generate DIEs to represent all known formal parameters */ | |
b3694847 SS |
10801 | tree arg_decls = DECL_ARGUMENTS (decl); |
10802 | tree parm; | |
a3f97cbb JW |
10803 | |
10804 | /* When generating DIEs, generate the unspecified_parameters DIE | |
10805 | instead if we come across the arg "__builtin_va_alist" */ | |
10806 | for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) | |
71dfc51f RK |
10807 | if (TREE_CODE (parm) == PARM_DECL) |
10808 | { | |
db3cf6fb MS |
10809 | if (DECL_NAME (parm) |
10810 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), | |
10811 | "__builtin_va_alist")) | |
71dfc51f RK |
10812 | gen_unspecified_parameters_die (parm, subr_die); |
10813 | else | |
10814 | gen_decl_die (parm, subr_die); | |
10815 | } | |
a3f97cbb | 10816 | |
4fe9b91c | 10817 | /* Decide whether we need an unspecified_parameters DIE at the end. |
556273e0 | 10818 | There are 2 more cases to do this for: 1) the ansi ... declaration - |
a3f97cbb JW |
10819 | this is detectable when the end of the arg list is not a |
10820 | void_type_node 2) an unprototyped function declaration (not a | |
10821 | definition). This just means that we have no info about the | |
10822 | parameters at all. */ | |
10823 | fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
71dfc51f | 10824 | if (fn_arg_types != NULL) |
a3f97cbb JW |
10825 | { |
10826 | /* this is the prototyped case, check for ... */ | |
10827 | if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) | |
71dfc51f | 10828 | gen_unspecified_parameters_die (decl, subr_die); |
a3f97cbb | 10829 | } |
71dfc51f RK |
10830 | else if (DECL_INITIAL (decl) == NULL_TREE) |
10831 | gen_unspecified_parameters_die (decl, subr_die); | |
a3f97cbb JW |
10832 | } |
10833 | ||
10834 | /* Output Dwarf info for all of the stuff within the body of the function | |
10835 | (if it has one - it may be just a declaration). */ | |
10836 | outer_scope = DECL_INITIAL (decl); | |
10837 | ||
2ad9852d RK |
10838 | /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent |
10839 | a function. This BLOCK actually represents the outermost binding contour | |
10840 | for the function, i.e. the contour in which the function's formal | |
10841 | parameters and labels get declared. Curiously, it appears that the front | |
10842 | end doesn't actually put the PARM_DECL nodes for the current function onto | |
10843 | the BLOCK_VARS list for this outer scope, but are strung off of the | |
10844 | DECL_ARGUMENTS list for the function instead. | |
10845 | ||
10846 | The BLOCK_VARS list for the `outer_scope' does provide us with a list of | |
10847 | the LABEL_DECL nodes for the function however, and we output DWARF info | |
10848 | for those in decls_for_scope. Just within the `outer_scope' there will be | |
10849 | a BLOCK node representing the function's outermost pair of curly braces, | |
10850 | and any blocks used for the base and member initializers of a C++ | |
d7248bff | 10851 | constructor function. */ |
4edb7b60 | 10852 | if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK) |
7e23cb16 JM |
10853 | { |
10854 | current_function_has_inlines = 0; | |
10855 | decls_for_scope (outer_scope, subr_die, 0); | |
71dfc51f | 10856 | |
ce61cc73 | 10857 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
7e23cb16 JM |
10858 | if (current_function_has_inlines) |
10859 | { | |
10860 | add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1); | |
10861 | if (! comp_unit_has_inlines) | |
10862 | { | |
10863 | add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1); | |
10864 | comp_unit_has_inlines = 1; | |
10865 | } | |
10866 | } | |
10867 | #endif | |
10868 | } | |
a3f97cbb JW |
10869 | } |
10870 | ||
10871 | /* Generate a DIE to represent a declared data object. */ | |
71dfc51f | 10872 | |
a3f97cbb JW |
10873 | static void |
10874 | gen_variable_die (decl, context_die) | |
b3694847 SS |
10875 | tree decl; |
10876 | dw_die_ref context_die; | |
a3f97cbb | 10877 | { |
b3694847 | 10878 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 10879 | dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl); |
71dfc51f | 10880 | |
bdb669cb | 10881 | dw_die_ref old_die = lookup_decl_die (decl); |
9765e357 JM |
10882 | int declaration = (DECL_EXTERNAL (decl) |
10883 | || class_scope_p (context_die)); | |
4edb7b60 | 10884 | |
a3f97cbb | 10885 | if (origin != NULL) |
71dfc51f | 10886 | add_abstract_origin_attribute (var_die, origin); |
2ad9852d | 10887 | |
f76b8156 | 10888 | /* Loop unrolling can create multiple blocks that refer to the same |
2ad9852d RK |
10889 | static variable, so we must test for the DW_AT_declaration flag. |
10890 | ||
10891 | ??? Loop unrolling/reorder_blocks should perhaps be rewritten to | |
f76b8156 | 10892 | copy decls and set the DECL_ABSTRACT flag on them instead of |
2ad9852d RK |
10893 | sharing them. |
10894 | ||
10895 | ??? Duplicated blocks have been rewritten to use .debug_ranges. */ | |
f76b8156 | 10896 | else if (old_die && TREE_STATIC (decl) |
c26fbbca | 10897 | && get_AT_flag (old_die, DW_AT_declaration) == 1) |
bdb669cb | 10898 | { |
e689ae67 | 10899 | /* This is a definition of a C++ class level static. */ |
bdb669cb JM |
10900 | add_AT_die_ref (var_die, DW_AT_specification, old_die); |
10901 | if (DECL_NAME (decl)) | |
10902 | { | |
981975b6 | 10903 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
71dfc51f | 10904 | |
bdb669cb JM |
10905 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
10906 | add_AT_unsigned (var_die, DW_AT_decl_file, file_index); | |
71dfc51f | 10907 | |
bdb669cb | 10908 | if (get_AT_unsigned (old_die, DW_AT_decl_line) |
556273e0 | 10909 | != (unsigned) DECL_SOURCE_LINE (decl)) |
71dfc51f RK |
10910 | |
10911 | add_AT_unsigned (var_die, DW_AT_decl_line, | |
10912 | DECL_SOURCE_LINE (decl)); | |
bdb669cb JM |
10913 | } |
10914 | } | |
a3f97cbb JW |
10915 | else |
10916 | { | |
10917 | add_name_and_src_coords_attributes (var_die, decl); | |
2ad9852d | 10918 | add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl), |
a3f97cbb | 10919 | TREE_THIS_VOLATILE (decl), context_die); |
71dfc51f | 10920 | |
273dbe67 JM |
10921 | if (TREE_PUBLIC (decl)) |
10922 | add_AT_flag (var_die, DW_AT_external, 1); | |
71dfc51f | 10923 | |
273dbe67 JM |
10924 | if (DECL_ARTIFICIAL (decl)) |
10925 | add_AT_flag (var_die, DW_AT_artificial, 1); | |
71dfc51f | 10926 | |
a94dbf2c JM |
10927 | if (TREE_PROTECTED (decl)) |
10928 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected); | |
10929 | else if (TREE_PRIVATE (decl)) | |
10930 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 10931 | } |
4edb7b60 JM |
10932 | |
10933 | if (declaration) | |
10934 | add_AT_flag (var_die, DW_AT_declaration, 1); | |
556273e0 | 10935 | |
9765e357 | 10936 | if (class_scope_p (context_die) || DECL_ABSTRACT (decl)) |
4edb7b60 JM |
10937 | equate_decl_number_to_die (decl, var_die); |
10938 | ||
10939 | if (! declaration && ! DECL_ABSTRACT (decl)) | |
a3f97cbb JW |
10940 | { |
10941 | add_location_or_const_value_attribute (var_die, decl); | |
d291dd49 | 10942 | add_pubname (decl, var_die); |
a3f97cbb | 10943 | } |
1bfb5f8f JM |
10944 | else |
10945 | tree_add_const_value_attribute (var_die, decl); | |
a3f97cbb JW |
10946 | } |
10947 | ||
10948 | /* Generate a DIE to represent a label identifier. */ | |
71dfc51f | 10949 | |
a3f97cbb JW |
10950 | static void |
10951 | gen_label_die (decl, context_die) | |
b3694847 SS |
10952 | tree decl; |
10953 | dw_die_ref context_die; | |
a3f97cbb | 10954 | { |
b3694847 | 10955 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 10956 | dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl); |
b3694847 | 10957 | rtx insn; |
a3f97cbb | 10958 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 10959 | |
a3f97cbb | 10960 | if (origin != NULL) |
71dfc51f | 10961 | add_abstract_origin_attribute (lbl_die, origin); |
a3f97cbb | 10962 | else |
71dfc51f RK |
10963 | add_name_and_src_coords_attributes (lbl_die, decl); |
10964 | ||
a3f97cbb | 10965 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 10966 | equate_decl_number_to_die (decl, lbl_die); |
a3f97cbb JW |
10967 | else |
10968 | { | |
10969 | insn = DECL_RTL (decl); | |
088e7160 NC |
10970 | |
10971 | /* Deleted labels are programmer specified labels which have been | |
10972 | eliminated because of various optimisations. We still emit them | |
10973 | here so that it is possible to put breakpoints on them. */ | |
10974 | if (GET_CODE (insn) == CODE_LABEL | |
10975 | || ((GET_CODE (insn) == NOTE | |
10976 | && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))) | |
a3f97cbb | 10977 | { |
556273e0 KH |
10978 | /* When optimization is enabled (via -O) some parts of the compiler |
10979 | (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which | |
a3f97cbb JW |
10980 | represent source-level labels which were explicitly declared by |
10981 | the user. This really shouldn't be happening though, so catch | |
10982 | it if it ever does happen. */ | |
10983 | if (INSN_DELETED_P (insn)) | |
71dfc51f RK |
10984 | abort (); |
10985 | ||
66234570 | 10986 | ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn)); |
a3f97cbb JW |
10987 | add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); |
10988 | } | |
10989 | } | |
10990 | } | |
10991 | ||
10992 | /* Generate a DIE for a lexical block. */ | |
71dfc51f | 10993 | |
a3f97cbb | 10994 | static void |
d7248bff | 10995 | gen_lexical_block_die (stmt, context_die, depth) |
b3694847 SS |
10996 | tree stmt; |
10997 | dw_die_ref context_die; | |
d7248bff | 10998 | int depth; |
a3f97cbb | 10999 | { |
54ba1f0d | 11000 | dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt); |
a3f97cbb | 11001 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f RK |
11002 | |
11003 | if (! BLOCK_ABSTRACT (stmt)) | |
a3f97cbb | 11004 | { |
a20612aa RH |
11005 | if (BLOCK_FRAGMENT_CHAIN (stmt)) |
11006 | { | |
11007 | tree chain; | |
11008 | ||
2bee6045 | 11009 | add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt)); |
a20612aa RH |
11010 | |
11011 | chain = BLOCK_FRAGMENT_CHAIN (stmt); | |
11012 | do | |
11013 | { | |
11014 | add_ranges (chain); | |
11015 | chain = BLOCK_FRAGMENT_CHAIN (chain); | |
11016 | } | |
11017 | while (chain); | |
11018 | add_ranges (NULL); | |
11019 | } | |
11020 | else | |
11021 | { | |
11022 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, | |
11023 | BLOCK_NUMBER (stmt)); | |
11024 | add_AT_lbl_id (stmt_die, DW_AT_low_pc, label); | |
11025 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, | |
11026 | BLOCK_NUMBER (stmt)); | |
11027 | add_AT_lbl_id (stmt_die, DW_AT_high_pc, label); | |
11028 | } | |
a3f97cbb | 11029 | } |
71dfc51f | 11030 | |
d7248bff | 11031 | decls_for_scope (stmt, stmt_die, depth); |
a3f97cbb JW |
11032 | } |
11033 | ||
11034 | /* Generate a DIE for an inlined subprogram. */ | |
71dfc51f | 11035 | |
a3f97cbb | 11036 | static void |
d7248bff | 11037 | gen_inlined_subroutine_die (stmt, context_die, depth) |
b3694847 SS |
11038 | tree stmt; |
11039 | dw_die_ref context_die; | |
d7248bff | 11040 | int depth; |
a3f97cbb | 11041 | { |
71dfc51f | 11042 | if (! BLOCK_ABSTRACT (stmt)) |
a3f97cbb | 11043 | { |
b3694847 | 11044 | dw_die_ref subr_die |
54ba1f0d | 11045 | = new_die (DW_TAG_inlined_subroutine, context_die, stmt); |
b3694847 | 11046 | tree decl = block_ultimate_origin (stmt); |
d7248bff | 11047 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 11048 | |
10a11b75 | 11049 | /* Emit info for the abstract instance first, if we haven't yet. */ |
1edf43d6 | 11050 | dwarf2out_abstract_function (decl); |
10a11b75 | 11051 | |
ab72d377 | 11052 | add_abstract_origin_attribute (subr_die, decl); |
5c90448c | 11053 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
18c038b9 | 11054 | BLOCK_NUMBER (stmt)); |
a3f97cbb | 11055 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label); |
18c038b9 MM |
11056 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, |
11057 | BLOCK_NUMBER (stmt)); | |
a3f97cbb | 11058 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label); |
d7248bff | 11059 | decls_for_scope (stmt, subr_die, depth); |
7e23cb16 | 11060 | current_function_has_inlines = 1; |
a3f97cbb | 11061 | } |
06e224f7 AO |
11062 | else |
11063 | /* We may get here if we're the outer block of function A that was | |
11064 | inlined into function B that was inlined into function C. When | |
11065 | generating debugging info for C, dwarf2out_abstract_function(B) | |
11066 | would mark all inlined blocks as abstract, including this one. | |
11067 | So, we wouldn't (and shouldn't) expect labels to be generated | |
11068 | for this one. Instead, just emit debugging info for | |
11069 | declarations within the block. This is particularly important | |
11070 | in the case of initializers of arguments passed from B to us: | |
11071 | if they're statement expressions containing declarations, we | |
11072 | wouldn't generate dies for their abstract variables, and then, | |
11073 | when generating dies for the real variables, we'd die (pun | |
11074 | intended :-) */ | |
11075 | gen_lexical_block_die (stmt, context_die, depth); | |
a3f97cbb JW |
11076 | } |
11077 | ||
11078 | /* Generate a DIE for a field in a record, or structure. */ | |
71dfc51f | 11079 | |
a3f97cbb JW |
11080 | static void |
11081 | gen_field_die (decl, context_die) | |
b3694847 SS |
11082 | tree decl; |
11083 | dw_die_ref context_die; | |
a3f97cbb | 11084 | { |
54ba1f0d | 11085 | dw_die_ref decl_die = new_die (DW_TAG_member, context_die, decl); |
71dfc51f | 11086 | |
a3f97cbb | 11087 | add_name_and_src_coords_attributes (decl_die, decl); |
a3f97cbb JW |
11088 | add_type_attribute (decl_die, member_declared_type (decl), |
11089 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl), | |
11090 | context_die); | |
71dfc51f | 11091 | |
a3f97cbb JW |
11092 | if (DECL_BIT_FIELD_TYPE (decl)) |
11093 | { | |
11094 | add_byte_size_attribute (decl_die, decl); | |
11095 | add_bit_size_attribute (decl_die, decl); | |
11096 | add_bit_offset_attribute (decl_die, decl); | |
11097 | } | |
71dfc51f | 11098 | |
a94dbf2c JM |
11099 | if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE) |
11100 | add_data_member_location_attribute (decl_die, decl); | |
71dfc51f | 11101 | |
273dbe67 JM |
11102 | if (DECL_ARTIFICIAL (decl)) |
11103 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
71dfc51f | 11104 | |
a94dbf2c JM |
11105 | if (TREE_PROTECTED (decl)) |
11106 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected); | |
11107 | else if (TREE_PRIVATE (decl)) | |
11108 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb JW |
11109 | } |
11110 | ||
ab72d377 JM |
11111 | #if 0 |
11112 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. | |
11113 | Use modified_type_die instead. | |
a3f97cbb JW |
11114 | We keep this code here just in case these types of DIEs may be needed to |
11115 | represent certain things in other languages (e.g. Pascal) someday. */ | |
2ad9852d | 11116 | |
a3f97cbb JW |
11117 | static void |
11118 | gen_pointer_type_die (type, context_die) | |
b3694847 SS |
11119 | tree type; |
11120 | dw_die_ref context_die; | |
a3f97cbb | 11121 | { |
b3694847 | 11122 | dw_die_ref ptr_die |
54ba1f0d | 11123 | = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type); |
71dfc51f | 11124 | |
a3f97cbb | 11125 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 11126 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 11127 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb JW |
11128 | } |
11129 | ||
ab72d377 JM |
11130 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. |
11131 | Use modified_type_die instead. | |
a3f97cbb JW |
11132 | We keep this code here just in case these types of DIEs may be needed to |
11133 | represent certain things in other languages (e.g. Pascal) someday. */ | |
2ad9852d | 11134 | |
a3f97cbb JW |
11135 | static void |
11136 | gen_reference_type_die (type, context_die) | |
b3694847 SS |
11137 | tree type; |
11138 | dw_die_ref context_die; | |
a3f97cbb | 11139 | { |
b3694847 | 11140 | dw_die_ref ref_die |
54ba1f0d | 11141 | = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type); |
71dfc51f | 11142 | |
a3f97cbb | 11143 | equate_type_number_to_die (type, ref_die); |
a3f97cbb | 11144 | add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 11145 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb | 11146 | } |
ab72d377 | 11147 | #endif |
a3f97cbb JW |
11148 | |
11149 | /* Generate a DIE for a pointer to a member type. */ | |
2ad9852d | 11150 | |
a3f97cbb JW |
11151 | static void |
11152 | gen_ptr_to_mbr_type_die (type, context_die) | |
b3694847 SS |
11153 | tree type; |
11154 | dw_die_ref context_die; | |
a3f97cbb | 11155 | { |
b3694847 | 11156 | dw_die_ref ptr_die |
54ba1f0d RH |
11157 | = new_die (DW_TAG_ptr_to_member_type, |
11158 | scope_die_for (type, context_die), type); | |
71dfc51f | 11159 | |
a3f97cbb | 11160 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 11161 | add_AT_die_ref (ptr_die, DW_AT_containing_type, |
bdb669cb | 11162 | lookup_type_die (TYPE_OFFSET_BASETYPE (type))); |
a3f97cbb JW |
11163 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
11164 | } | |
11165 | ||
11166 | /* Generate the DIE for the compilation unit. */ | |
71dfc51f | 11167 | |
a96c67ec JM |
11168 | static dw_die_ref |
11169 | gen_compile_unit_die (filename) | |
b3694847 | 11170 | const char *filename; |
a3f97cbb | 11171 | { |
b3694847 | 11172 | dw_die_ref die; |
a3f97cbb | 11173 | char producer[250]; |
d3e3972c | 11174 | const char *wd = getpwd (); |
3ac88239 | 11175 | const char *language_string = lang_hooks.name; |
a96c67ec | 11176 | int language; |
a3f97cbb | 11177 | |
54ba1f0d | 11178 | die = new_die (DW_TAG_compile_unit, NULL, NULL); |
a96c67ec | 11179 | add_name_attribute (die, filename); |
bdb669cb | 11180 | |
a96c67ec JM |
11181 | if (wd != NULL && filename[0] != DIR_SEPARATOR) |
11182 | add_AT_string (die, DW_AT_comp_dir, wd); | |
a3f97cbb JW |
11183 | |
11184 | sprintf (producer, "%s %s", language_string, version_string); | |
11185 | ||
11186 | #ifdef MIPS_DEBUGGING_INFO | |
11187 | /* The MIPS/SGI compilers place the 'cc' command line options in the producer | |
11188 | string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do | |
11189 | not appear in the producer string, the debugger reaches the conclusion | |
11190 | that the object file is stripped and has no debugging information. | |
11191 | To get the MIPS/SGI debugger to believe that there is debugging | |
11192 | information in the object file, we add a -g to the producer string. */ | |
4927276d JM |
11193 | if (debug_info_level > DINFO_LEVEL_TERSE) |
11194 | strcat (producer, " -g"); | |
a3f97cbb JW |
11195 | #endif |
11196 | ||
a96c67ec | 11197 | add_AT_string (die, DW_AT_producer, producer); |
a9d38797 | 11198 | |
a3f97cbb | 11199 | if (strcmp (language_string, "GNU C++") == 0) |
a96c67ec | 11200 | language = DW_LANG_C_plus_plus; |
a3f97cbb | 11201 | else if (strcmp (language_string, "GNU Ada") == 0) |
a96c67ec | 11202 | language = DW_LANG_Ada83; |
a9d38797 | 11203 | else if (strcmp (language_string, "GNU F77") == 0) |
a96c67ec | 11204 | language = DW_LANG_Fortran77; |
bc28c45b | 11205 | else if (strcmp (language_string, "GNU Pascal") == 0) |
a96c67ec | 11206 | language = DW_LANG_Pascal83; |
28985b81 AG |
11207 | else if (strcmp (language_string, "GNU Java") == 0) |
11208 | language = DW_LANG_Java; | |
a3f97cbb | 11209 | else |
a96c67ec | 11210 | language = DW_LANG_C89; |
a9d38797 | 11211 | |
a96c67ec | 11212 | add_AT_unsigned (die, DW_AT_language, language); |
a96c67ec | 11213 | return die; |
a3f97cbb JW |
11214 | } |
11215 | ||
11216 | /* Generate a DIE for a string type. */ | |
71dfc51f | 11217 | |
a3f97cbb JW |
11218 | static void |
11219 | gen_string_type_die (type, context_die) | |
b3694847 SS |
11220 | tree type; |
11221 | dw_die_ref context_die; | |
a3f97cbb | 11222 | { |
b3694847 | 11223 | dw_die_ref type_die |
54ba1f0d | 11224 | = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type); |
71dfc51f | 11225 | |
bdb669cb | 11226 | equate_type_number_to_die (type, type_die); |
a3f97cbb | 11227 | |
2ad9852d RK |
11228 | /* ??? Fudge the string length attribute for now. |
11229 | TODO: add string length info. */ | |
11230 | #if 0 | |
11231 | string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type))); | |
11232 | bound_representation (upper_bound, 0, 'u'); | |
11233 | #endif | |
a3f97cbb JW |
11234 | } |
11235 | ||
61b32c02 | 11236 | /* Generate the DIE for a base class. */ |
71dfc51f | 11237 | |
61b32c02 JM |
11238 | static void |
11239 | gen_inheritance_die (binfo, context_die) | |
b3694847 SS |
11240 | tree binfo; |
11241 | dw_die_ref context_die; | |
61b32c02 | 11242 | { |
54ba1f0d | 11243 | dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo); |
71dfc51f | 11244 | |
61b32c02 JM |
11245 | add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die); |
11246 | add_data_member_location_attribute (die, binfo); | |
71dfc51f | 11247 | |
61b32c02 JM |
11248 | if (TREE_VIA_VIRTUAL (binfo)) |
11249 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); | |
2ad9852d | 11250 | |
61b32c02 JM |
11251 | if (TREE_VIA_PUBLIC (binfo)) |
11252 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public); | |
11253 | else if (TREE_VIA_PROTECTED (binfo)) | |
11254 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected); | |
11255 | } | |
11256 | ||
956d6950 | 11257 | /* Generate a DIE for a class member. */ |
71dfc51f | 11258 | |
a3f97cbb JW |
11259 | static void |
11260 | gen_member_die (type, context_die) | |
b3694847 SS |
11261 | tree type; |
11262 | dw_die_ref context_die; | |
a3f97cbb | 11263 | { |
b3694847 | 11264 | tree member; |
10a11b75 | 11265 | dw_die_ref child; |
71dfc51f | 11266 | |
a3f97cbb JW |
11267 | /* If this is not an incomplete type, output descriptions of each of its |
11268 | members. Note that as we output the DIEs necessary to represent the | |
11269 | members of this record or union type, we will also be trying to output | |
11270 | DIEs to represent the *types* of those members. However the `type' | |
556273e0 | 11271 | function (above) will specifically avoid generating type DIEs for member |
eaec9b3d | 11272 | types *within* the list of member DIEs for this (containing) type except |
a3f97cbb JW |
11273 | for those types (of members) which are explicitly marked as also being |
11274 | members of this (containing) type themselves. The g++ front- end can | |
2ad9852d RK |
11275 | force any given type to be treated as a member of some other (containing) |
11276 | type by setting the TYPE_CONTEXT of the given (member) type to point to | |
11277 | the TREE node representing the appropriate (containing) type. */ | |
a3f97cbb | 11278 | |
61b32c02 JM |
11279 | /* First output info about the base classes. */ |
11280 | if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type)) | |
a3f97cbb | 11281 | { |
b3694847 SS |
11282 | tree bases = TYPE_BINFO_BASETYPES (type); |
11283 | int n_bases = TREE_VEC_LENGTH (bases); | |
11284 | int i; | |
61b32c02 JM |
11285 | |
11286 | for (i = 0; i < n_bases; i++) | |
11287 | gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die); | |
a3f97cbb JW |
11288 | } |
11289 | ||
61b32c02 JM |
11290 | /* Now output info about the data members and type members. */ |
11291 | for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member)) | |
10a11b75 JM |
11292 | { |
11293 | /* If we thought we were generating minimal debug info for TYPE | |
11294 | and then changed our minds, some of the member declarations | |
11295 | may have already been defined. Don't define them again, but | |
11296 | do put them in the right order. */ | |
11297 | ||
11298 | child = lookup_decl_die (member); | |
11299 | if (child) | |
11300 | splice_child_die (context_die, child); | |
11301 | else | |
11302 | gen_decl_die (member, context_die); | |
11303 | } | |
61b32c02 | 11304 | |
a3f97cbb | 11305 | /* Now output info about the function members (if any). */ |
61b32c02 | 11306 | for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member)) |
10a11b75 | 11307 | { |
5daf7c0a JM |
11308 | /* Don't include clones in the member list. */ |
11309 | if (DECL_ABSTRACT_ORIGIN (member)) | |
11310 | continue; | |
11311 | ||
10a11b75 JM |
11312 | child = lookup_decl_die (member); |
11313 | if (child) | |
11314 | splice_child_die (context_die, child); | |
11315 | else | |
11316 | gen_decl_die (member, context_die); | |
11317 | } | |
a3f97cbb JW |
11318 | } |
11319 | ||
10a11b75 JM |
11320 | /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG |
11321 | is set, we pretend that the type was never defined, so we only get the | |
11322 | member DIEs needed by later specification DIEs. */ | |
71dfc51f | 11323 | |
a3f97cbb | 11324 | static void |
273dbe67 | 11325 | gen_struct_or_union_type_die (type, context_die) |
b3694847 SS |
11326 | tree type; |
11327 | dw_die_ref context_die; | |
a3f97cbb | 11328 | { |
b3694847 SS |
11329 | dw_die_ref type_die = lookup_type_die (type); |
11330 | dw_die_ref scope_die = 0; | |
11331 | int nested = 0; | |
10a11b75 | 11332 | int complete = (TYPE_SIZE (type) |
65e1263a JW |
11333 | && (! TYPE_STUB_DECL (type) |
11334 | || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)))); | |
273dbe67 | 11335 | |
10a11b75 | 11336 | if (type_die && ! complete) |
273dbe67 | 11337 | return; |
a082c85a | 11338 | |
71dfc51f | 11339 | if (TYPE_CONTEXT (type) != NULL_TREE |
5f2f160c | 11340 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))) |
a082c85a JM |
11341 | nested = 1; |
11342 | ||
a94dbf2c | 11343 | scope_die = scope_die_for (type, context_die); |
a082c85a JM |
11344 | |
11345 | if (! type_die || (nested && scope_die == comp_unit_die)) | |
273dbe67 | 11346 | /* First occurrence of type or toplevel definition of nested class. */ |
a3f97cbb | 11347 | { |
b3694847 | 11348 | dw_die_ref old_die = type_die; |
71dfc51f | 11349 | |
a3f97cbb JW |
11350 | type_die = new_die (TREE_CODE (type) == RECORD_TYPE |
11351 | ? DW_TAG_structure_type : DW_TAG_union_type, | |
54ba1f0d | 11352 | scope_die, type); |
a3f97cbb | 11353 | equate_type_number_to_die (type, type_die); |
273dbe67 JM |
11354 | if (old_die) |
11355 | add_AT_die_ref (type_die, DW_AT_specification, old_die); | |
5de0e8d4 JM |
11356 | else |
11357 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 11358 | } |
4b674448 | 11359 | else |
273dbe67 | 11360 | remove_AT (type_die, DW_AT_declaration); |
a3f97cbb JW |
11361 | |
11362 | /* If this type has been completed, then give it a byte_size attribute and | |
11363 | then give a list of members. */ | |
2081603c | 11364 | if (complete) |
a3f97cbb | 11365 | { |
556273e0 | 11366 | /* Prevent infinite recursion in cases where the type of some member of |
a3f97cbb JW |
11367 | this type is expressed in terms of this type itself. */ |
11368 | TREE_ASM_WRITTEN (type) = 1; | |
273dbe67 | 11369 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 11370 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 11371 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 11372 | |
ef76d03b JW |
11373 | /* If the first reference to this type was as the return type of an |
11374 | inline function, then it may not have a parent. Fix this now. */ | |
11375 | if (type_die->die_parent == NULL) | |
11376 | add_child_die (scope_die, type_die); | |
11377 | ||
273dbe67 JM |
11378 | push_decl_scope (type); |
11379 | gen_member_die (type, type_die); | |
11380 | pop_decl_scope (); | |
71dfc51f | 11381 | |
a94dbf2c JM |
11382 | /* GNU extension: Record what type our vtable lives in. */ |
11383 | if (TYPE_VFIELD (type)) | |
11384 | { | |
11385 | tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type)); | |
71dfc51f | 11386 | |
de6e505e JM |
11387 | gen_type_die (vtype, context_die); |
11388 | add_AT_die_ref (type_die, DW_AT_containing_type, | |
11389 | lookup_type_die (vtype)); | |
a94dbf2c | 11390 | } |
a3f97cbb | 11391 | } |
4b674448 | 11392 | else |
8a8c3656 JM |
11393 | { |
11394 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a30d4514 | 11395 | |
9765e357 | 11396 | /* We don't need to do this for function-local types. */ |
9702143f RK |
11397 | if (TYPE_STUB_DECL (type) |
11398 | && ! decl_function_context (TYPE_STUB_DECL (type))) | |
2ad9852d | 11399 | VARRAY_PUSH_TREE (incomplete_types, type); |
8a8c3656 | 11400 | } |
a3f97cbb JW |
11401 | } |
11402 | ||
11403 | /* Generate a DIE for a subroutine _type_. */ | |
71dfc51f | 11404 | |
a3f97cbb JW |
11405 | static void |
11406 | gen_subroutine_type_die (type, context_die) | |
b3694847 SS |
11407 | tree type; |
11408 | dw_die_ref context_die; | |
a3f97cbb | 11409 | { |
b3694847 SS |
11410 | tree return_type = TREE_TYPE (type); |
11411 | dw_die_ref subr_die | |
54ba1f0d RH |
11412 | = new_die (DW_TAG_subroutine_type, |
11413 | scope_die_for (type, context_die), type); | |
71dfc51f | 11414 | |
a3f97cbb JW |
11415 | equate_type_number_to_die (type, subr_die); |
11416 | add_prototyped_attribute (subr_die, type); | |
a3f97cbb | 11417 | add_type_attribute (subr_die, return_type, 0, 0, context_die); |
a94dbf2c | 11418 | gen_formal_types_die (type, subr_die); |
a3f97cbb JW |
11419 | } |
11420 | ||
11421 | /* Generate a DIE for a type definition */ | |
71dfc51f | 11422 | |
a3f97cbb JW |
11423 | static void |
11424 | gen_typedef_die (decl, context_die) | |
b3694847 SS |
11425 | tree decl; |
11426 | dw_die_ref context_die; | |
a3f97cbb | 11427 | { |
b3694847 SS |
11428 | dw_die_ref type_die; |
11429 | tree origin; | |
a94dbf2c JM |
11430 | |
11431 | if (TREE_ASM_WRITTEN (decl)) | |
11432 | return; | |
a94dbf2c | 11433 | |
2ad9852d | 11434 | TREE_ASM_WRITTEN (decl) = 1; |
54ba1f0d | 11435 | type_die = new_die (DW_TAG_typedef, context_die, decl); |
a94dbf2c | 11436 | origin = decl_ultimate_origin (decl); |
a3f97cbb | 11437 | if (origin != NULL) |
a94dbf2c | 11438 | add_abstract_origin_attribute (type_die, origin); |
a3f97cbb JW |
11439 | else |
11440 | { | |
b3694847 | 11441 | tree type; |
2ad9852d | 11442 | |
a3f97cbb | 11443 | add_name_and_src_coords_attributes (type_die, decl); |
a94dbf2c JM |
11444 | if (DECL_ORIGINAL_TYPE (decl)) |
11445 | { | |
11446 | type = DECL_ORIGINAL_TYPE (decl); | |
62e3bf54 JM |
11447 | |
11448 | if (type == TREE_TYPE (decl)) | |
11449 | abort (); | |
11450 | else | |
11451 | equate_type_number_to_die (TREE_TYPE (decl), type_die); | |
a94dbf2c JM |
11452 | } |
11453 | else | |
11454 | type = TREE_TYPE (decl); | |
2ad9852d | 11455 | |
a94dbf2c JM |
11456 | add_type_attribute (type_die, type, TREE_READONLY (decl), |
11457 | TREE_THIS_VOLATILE (decl), context_die); | |
a3f97cbb | 11458 | } |
71dfc51f | 11459 | |
a3f97cbb | 11460 | if (DECL_ABSTRACT (decl)) |
a94dbf2c | 11461 | equate_decl_number_to_die (decl, type_die); |
a3f97cbb JW |
11462 | } |
11463 | ||
11464 | /* Generate a type description DIE. */ | |
71dfc51f | 11465 | |
a3f97cbb JW |
11466 | static void |
11467 | gen_type_die (type, context_die) | |
b3694847 SS |
11468 | tree type; |
11469 | dw_die_ref context_die; | |
a3f97cbb | 11470 | { |
348bb3c7 JM |
11471 | int need_pop; |
11472 | ||
71dfc51f RK |
11473 | if (type == NULL_TREE || type == error_mark_node) |
11474 | return; | |
a3f97cbb | 11475 | |
0e98f924 AH |
11476 | /* We are going to output a DIE to represent the unqualified version |
11477 | of this type (i.e. without any const or volatile qualifiers) so | |
11478 | get the main variant (i.e. the unqualified version) of this type | |
11479 | now. (Vectors are special because the debugging info is in the | |
11480 | cloned type itself). */ | |
11481 | if (TREE_CODE (type) != VECTOR_TYPE) | |
11482 | type = type_main_variant (type); | |
a3f97cbb JW |
11483 | |
11484 | if (TREE_ASM_WRITTEN (type)) | |
71dfc51f | 11485 | return; |
a3f97cbb | 11486 | |
a94dbf2c JM |
11487 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
11488 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
556273e0 | 11489 | { |
29b91443 JM |
11490 | /* Prevent broken recursion; we can't hand off to the same type. */ |
11491 | if (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) == type) | |
11492 | abort (); | |
11493 | ||
a94dbf2c JM |
11494 | TREE_ASM_WRITTEN (type) = 1; |
11495 | gen_decl_die (TYPE_NAME (type), context_die); | |
11496 | return; | |
11497 | } | |
11498 | ||
a3f97cbb JW |
11499 | switch (TREE_CODE (type)) |
11500 | { | |
11501 | case ERROR_MARK: | |
11502 | break; | |
11503 | ||
11504 | case POINTER_TYPE: | |
11505 | case REFERENCE_TYPE: | |
956d6950 JL |
11506 | /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This |
11507 | ensures that the gen_type_die recursion will terminate even if the | |
11508 | type is recursive. Recursive types are possible in Ada. */ | |
11509 | /* ??? We could perhaps do this for all types before the switch | |
11510 | statement. */ | |
11511 | TREE_ASM_WRITTEN (type) = 1; | |
11512 | ||
a3f97cbb JW |
11513 | /* For these types, all that is required is that we output a DIE (or a |
11514 | set of DIEs) to represent the "basis" type. */ | |
11515 | gen_type_die (TREE_TYPE (type), context_die); | |
11516 | break; | |
11517 | ||
11518 | case OFFSET_TYPE: | |
556273e0 | 11519 | /* This code is used for C++ pointer-to-data-member types. |
71dfc51f | 11520 | Output a description of the relevant class type. */ |
a3f97cbb | 11521 | gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die); |
71dfc51f | 11522 | |
a3f97cbb JW |
11523 | /* Output a description of the type of the object pointed to. */ |
11524 | gen_type_die (TREE_TYPE (type), context_die); | |
71dfc51f | 11525 | |
a3f97cbb JW |
11526 | /* Now output a DIE to represent this pointer-to-data-member type |
11527 | itself. */ | |
11528 | gen_ptr_to_mbr_type_die (type, context_die); | |
11529 | break; | |
11530 | ||
11531 | case SET_TYPE: | |
11532 | gen_type_die (TYPE_DOMAIN (type), context_die); | |
11533 | gen_set_type_die (type, context_die); | |
11534 | break; | |
11535 | ||
11536 | case FILE_TYPE: | |
11537 | gen_type_die (TREE_TYPE (type), context_die); | |
11538 | abort (); /* No way to represent these in Dwarf yet! */ | |
11539 | break; | |
11540 | ||
11541 | case FUNCTION_TYPE: | |
11542 | /* Force out return type (in case it wasn't forced out already). */ | |
11543 | gen_type_die (TREE_TYPE (type), context_die); | |
11544 | gen_subroutine_type_die (type, context_die); | |
11545 | break; | |
11546 | ||
11547 | case METHOD_TYPE: | |
11548 | /* Force out return type (in case it wasn't forced out already). */ | |
11549 | gen_type_die (TREE_TYPE (type), context_die); | |
11550 | gen_subroutine_type_die (type, context_die); | |
11551 | break; | |
11552 | ||
11553 | case ARRAY_TYPE: | |
11554 | if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE) | |
11555 | { | |
11556 | gen_type_die (TREE_TYPE (type), context_die); | |
11557 | gen_string_type_die (type, context_die); | |
11558 | } | |
11559 | else | |
71dfc51f | 11560 | gen_array_type_die (type, context_die); |
a3f97cbb JW |
11561 | break; |
11562 | ||
4061f623 | 11563 | case VECTOR_TYPE: |
84f0ace0 | 11564 | gen_array_type_die (type, context_die); |
4061f623 BS |
11565 | break; |
11566 | ||
a3f97cbb JW |
11567 | case ENUMERAL_TYPE: |
11568 | case RECORD_TYPE: | |
11569 | case UNION_TYPE: | |
11570 | case QUAL_UNION_TYPE: | |
2ad9852d RK |
11571 | /* If this is a nested type whose containing class hasn't been written |
11572 | out yet, writing it out will cover this one, too. This does not apply | |
11573 | to instantiations of member class templates; they need to be added to | |
11574 | the containing class as they are generated. FIXME: This hurts the | |
11575 | idea of combining type decls from multiple TUs, since we can't predict | |
11576 | what set of template instantiations we'll get. */ | |
a082c85a | 11577 | if (TYPE_CONTEXT (type) |
5f2f160c | 11578 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) |
a082c85a | 11579 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) |
a94dbf2c JM |
11580 | { |
11581 | gen_type_die (TYPE_CONTEXT (type), context_die); | |
11582 | ||
348bb3c7 | 11583 | if (TREE_ASM_WRITTEN (type)) |
a94dbf2c JM |
11584 | return; |
11585 | ||
11586 | /* If that failed, attach ourselves to the stub. */ | |
11587 | push_decl_scope (TYPE_CONTEXT (type)); | |
11588 | context_die = lookup_type_die (TYPE_CONTEXT (type)); | |
348bb3c7 | 11589 | need_pop = 1; |
a94dbf2c | 11590 | } |
348bb3c7 JM |
11591 | else |
11592 | need_pop = 0; | |
a94dbf2c JM |
11593 | |
11594 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
273dbe67 | 11595 | gen_enumeration_type_die (type, context_die); |
a3f97cbb | 11596 | else |
273dbe67 | 11597 | gen_struct_or_union_type_die (type, context_die); |
4b674448 | 11598 | |
348bb3c7 | 11599 | if (need_pop) |
a94dbf2c JM |
11600 | pop_decl_scope (); |
11601 | ||
4b674448 | 11602 | /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix |
a082c85a JM |
11603 | it up if it is ever completed. gen_*_type_die will set it for us |
11604 | when appropriate. */ | |
11605 | return; | |
a3f97cbb JW |
11606 | |
11607 | case VOID_TYPE: | |
11608 | case INTEGER_TYPE: | |
11609 | case REAL_TYPE: | |
11610 | case COMPLEX_TYPE: | |
11611 | case BOOLEAN_TYPE: | |
11612 | case CHAR_TYPE: | |
11613 | /* No DIEs needed for fundamental types. */ | |
11614 | break; | |
11615 | ||
11616 | case LANG_TYPE: | |
11617 | /* No Dwarf representation currently defined. */ | |
11618 | break; | |
11619 | ||
11620 | default: | |
11621 | abort (); | |
11622 | } | |
11623 | ||
11624 | TREE_ASM_WRITTEN (type) = 1; | |
11625 | } | |
11626 | ||
11627 | /* Generate a DIE for a tagged type instantiation. */ | |
71dfc51f | 11628 | |
a3f97cbb JW |
11629 | static void |
11630 | gen_tagged_type_instantiation_die (type, context_die) | |
b3694847 SS |
11631 | tree type; |
11632 | dw_die_ref context_die; | |
a3f97cbb | 11633 | { |
71dfc51f RK |
11634 | if (type == NULL_TREE || type == error_mark_node) |
11635 | return; | |
a3f97cbb | 11636 | |
38e01259 | 11637 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
11638 | this type (i.e. without any const or volatile qualifiers) so make sure |
11639 | that we have the main variant (i.e. the unqualified version) of this | |
11640 | type now. */ | |
bbc6ae08 | 11641 | if (type != type_main_variant (type)) |
3a88cbd1 | 11642 | abort (); |
a3f97cbb | 11643 | |
203588e7 | 11644 | /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is |
bbc6ae08 | 11645 | an instance of an unresolved type. */ |
556273e0 | 11646 | |
a3f97cbb JW |
11647 | switch (TREE_CODE (type)) |
11648 | { | |
11649 | case ERROR_MARK: | |
11650 | break; | |
11651 | ||
11652 | case ENUMERAL_TYPE: | |
11653 | gen_inlined_enumeration_type_die (type, context_die); | |
11654 | break; | |
11655 | ||
11656 | case RECORD_TYPE: | |
11657 | gen_inlined_structure_type_die (type, context_die); | |
11658 | break; | |
11659 | ||
11660 | case UNION_TYPE: | |
11661 | case QUAL_UNION_TYPE: | |
11662 | gen_inlined_union_type_die (type, context_die); | |
11663 | break; | |
11664 | ||
11665 | default: | |
71dfc51f | 11666 | abort (); |
a3f97cbb JW |
11667 | } |
11668 | } | |
11669 | ||
11670 | /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the | |
11671 | things which are local to the given block. */ | |
71dfc51f | 11672 | |
a3f97cbb | 11673 | static void |
d7248bff | 11674 | gen_block_die (stmt, context_die, depth) |
b3694847 SS |
11675 | tree stmt; |
11676 | dw_die_ref context_die; | |
d7248bff | 11677 | int depth; |
a3f97cbb | 11678 | { |
b3694847 SS |
11679 | int must_output_die = 0; |
11680 | tree origin; | |
11681 | tree decl; | |
11682 | enum tree_code origin_code; | |
a3f97cbb JW |
11683 | |
11684 | /* Ignore blocks never really used to make RTL. */ | |
1e7f092a JM |
11685 | if (stmt == NULL_TREE || !TREE_USED (stmt) |
11686 | || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt))) | |
71dfc51f | 11687 | return; |
a3f97cbb | 11688 | |
a20612aa RH |
11689 | /* If the block is one fragment of a non-contiguous block, do not |
11690 | process the variables, since they will have been done by the | |
11691 | origin block. Do process subblocks. */ | |
11692 | if (BLOCK_FRAGMENT_ORIGIN (stmt)) | |
11693 | { | |
11694 | tree sub; | |
11695 | ||
2ad9852d | 11696 | for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub)) |
a20612aa | 11697 | gen_block_die (sub, context_die, depth + 1); |
2ad9852d | 11698 | |
a20612aa RH |
11699 | return; |
11700 | } | |
11701 | ||
a3f97cbb JW |
11702 | /* Determine the "ultimate origin" of this block. This block may be an |
11703 | inlined instance of an inlined instance of inline function, so we have | |
11704 | to trace all of the way back through the origin chain to find out what | |
11705 | sort of node actually served as the original seed for the creation of | |
11706 | the current block. */ | |
11707 | origin = block_ultimate_origin (stmt); | |
11708 | origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; | |
11709 | ||
11710 | /* Determine if we need to output any Dwarf DIEs at all to represent this | |
11711 | block. */ | |
11712 | if (origin_code == FUNCTION_DECL) | |
71dfc51f RK |
11713 | /* The outer scopes for inlinings *must* always be represented. We |
11714 | generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */ | |
11715 | must_output_die = 1; | |
a3f97cbb JW |
11716 | else |
11717 | { | |
11718 | /* In the case where the current block represents an inlining of the | |
556273e0 | 11719 | "body block" of an inline function, we must *NOT* output any DIE for |
2ad9852d RK |
11720 | this block because we have already output a DIE to represent the whole |
11721 | inlined function scope and the "body block" of any function doesn't | |
11722 | really represent a different scope according to ANSI C rules. So we | |
11723 | check here to make sure that this block does not represent a "body | |
11724 | block inlining" before trying to set the MUST_OUTPUT_DIE flag. */ | |
d7248bff | 11725 | if (! is_body_block (origin ? origin : stmt)) |
a3f97cbb JW |
11726 | { |
11727 | /* Determine if this block directly contains any "significant" | |
11728 | local declarations which we will need to output DIEs for. */ | |
11729 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
71dfc51f RK |
11730 | /* We are not in terse mode so *any* local declaration counts |
11731 | as being a "significant" one. */ | |
11732 | must_output_die = (BLOCK_VARS (stmt) != NULL); | |
a3f97cbb | 11733 | else |
71dfc51f RK |
11734 | /* We are in terse mode, so only local (nested) function |
11735 | definitions count as "significant" local declarations. */ | |
11736 | for (decl = BLOCK_VARS (stmt); | |
11737 | decl != NULL; decl = TREE_CHAIN (decl)) | |
11738 | if (TREE_CODE (decl) == FUNCTION_DECL | |
11739 | && DECL_INITIAL (decl)) | |
a3f97cbb | 11740 | { |
71dfc51f RK |
11741 | must_output_die = 1; |
11742 | break; | |
a3f97cbb | 11743 | } |
a3f97cbb JW |
11744 | } |
11745 | } | |
11746 | ||
11747 | /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block | |
11748 | DIE for any block which contains no significant local declarations at | |
11749 | all. Rather, in such cases we just call `decls_for_scope' so that any | |
11750 | needed Dwarf info for any sub-blocks will get properly generated. Note | |
11751 | that in terse mode, our definition of what constitutes a "significant" | |
11752 | local declaration gets restricted to include only inlined function | |
11753 | instances and local (nested) function definitions. */ | |
11754 | if (must_output_die) | |
11755 | { | |
11756 | if (origin_code == FUNCTION_DECL) | |
71dfc51f | 11757 | gen_inlined_subroutine_die (stmt, context_die, depth); |
a3f97cbb | 11758 | else |
71dfc51f | 11759 | gen_lexical_block_die (stmt, context_die, depth); |
a3f97cbb JW |
11760 | } |
11761 | else | |
d7248bff | 11762 | decls_for_scope (stmt, context_die, depth); |
a3f97cbb JW |
11763 | } |
11764 | ||
11765 | /* Generate all of the decls declared within a given scope and (recursively) | |
9ec36da5 | 11766 | all of its sub-blocks. */ |
71dfc51f | 11767 | |
a3f97cbb | 11768 | static void |
d7248bff | 11769 | decls_for_scope (stmt, context_die, depth) |
b3694847 SS |
11770 | tree stmt; |
11771 | dw_die_ref context_die; | |
d7248bff | 11772 | int depth; |
a3f97cbb | 11773 | { |
b3694847 SS |
11774 | tree decl; |
11775 | tree subblocks; | |
71dfc51f | 11776 | |
a3f97cbb | 11777 | /* Ignore blocks never really used to make RTL. */ |
71dfc51f RK |
11778 | if (stmt == NULL_TREE || ! TREE_USED (stmt)) |
11779 | return; | |
11780 | ||
88dad228 JM |
11781 | /* Output the DIEs to represent all of the data objects and typedefs |
11782 | declared directly within this block but not within any nested | |
11783 | sub-blocks. Also, nested function and tag DIEs have been | |
11784 | generated with a parent of NULL; fix that up now. */ | |
2ad9852d | 11785 | for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl)) |
a3f97cbb | 11786 | { |
b3694847 | 11787 | dw_die_ref die; |
a94dbf2c | 11788 | |
88dad228 | 11789 | if (TREE_CODE (decl) == FUNCTION_DECL) |
a94dbf2c | 11790 | die = lookup_decl_die (decl); |
88dad228 | 11791 | else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)) |
a94dbf2c JM |
11792 | die = lookup_type_die (TREE_TYPE (decl)); |
11793 | else | |
11794 | die = NULL; | |
11795 | ||
71dfc51f | 11796 | if (die != NULL && die->die_parent == NULL) |
ef76d03b | 11797 | add_child_die (context_die, die); |
88dad228 JM |
11798 | else |
11799 | gen_decl_die (decl, context_die); | |
a3f97cbb JW |
11800 | } |
11801 | ||
11802 | /* Output the DIEs to represent all sub-blocks (and the items declared | |
11803 | therein) of this block. */ | |
11804 | for (subblocks = BLOCK_SUBBLOCKS (stmt); | |
11805 | subblocks != NULL; | |
11806 | subblocks = BLOCK_CHAIN (subblocks)) | |
71dfc51f | 11807 | gen_block_die (subblocks, context_die, depth + 1); |
a3f97cbb JW |
11808 | } |
11809 | ||
a94dbf2c | 11810 | /* Is this a typedef we can avoid emitting? */ |
71dfc51f RK |
11811 | |
11812 | static inline int | |
a94dbf2c | 11813 | is_redundant_typedef (decl) |
b3694847 | 11814 | tree decl; |
a94dbf2c JM |
11815 | { |
11816 | if (TYPE_DECL_IS_STUB (decl)) | |
11817 | return 1; | |
71dfc51f | 11818 | |
a94dbf2c JM |
11819 | if (DECL_ARTIFICIAL (decl) |
11820 | && DECL_CONTEXT (decl) | |
11821 | && is_tagged_type (DECL_CONTEXT (decl)) | |
11822 | && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL | |
11823 | && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) | |
11824 | /* Also ignore the artificial member typedef for the class name. */ | |
11825 | return 1; | |
71dfc51f | 11826 | |
a94dbf2c JM |
11827 | return 0; |
11828 | } | |
11829 | ||
a3f97cbb | 11830 | /* Generate Dwarf debug information for a decl described by DECL. */ |
71dfc51f | 11831 | |
a3f97cbb JW |
11832 | static void |
11833 | gen_decl_die (decl, context_die) | |
b3694847 SS |
11834 | tree decl; |
11835 | dw_die_ref context_die; | |
a3f97cbb | 11836 | { |
b3694847 | 11837 | tree origin; |
71dfc51f | 11838 | |
f11c3043 | 11839 | if (DECL_P (decl) && DECL_IGNORED_P (decl)) |
71dfc51f | 11840 | return; |
a3f97cbb | 11841 | |
a3f97cbb JW |
11842 | switch (TREE_CODE (decl)) |
11843 | { | |
2ad9852d RK |
11844 | case ERROR_MARK: |
11845 | break; | |
11846 | ||
a3f97cbb | 11847 | case CONST_DECL: |
556273e0 | 11848 | /* The individual enumerators of an enum type get output when we output |
a3f97cbb JW |
11849 | the Dwarf representation of the relevant enum type itself. */ |
11850 | break; | |
11851 | ||
11852 | case FUNCTION_DECL: | |
4edb7b60 JM |
11853 | /* Don't output any DIEs to represent mere function declarations, |
11854 | unless they are class members or explicit block externs. */ | |
11855 | if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE | |
777ad4c2 | 11856 | && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl))) |
71dfc51f | 11857 | break; |
bdb669cb | 11858 | |
5daf7c0a JM |
11859 | /* If we're emitting a clone, emit info for the abstract instance. */ |
11860 | if (DECL_ORIGIN (decl) != decl) | |
11861 | dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl)); | |
2ad9852d | 11862 | |
1cfdcc15 JM |
11863 | /* If we're emitting an out-of-line copy of an inline function, |
11864 | emit info for the abstract instance and set up to refer to it. */ | |
5daf7c0a JM |
11865 | else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl) |
11866 | && ! class_scope_p (context_die) | |
11867 | /* dwarf2out_abstract_function won't emit a die if this is just | |
11868 | a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in | |
11869 | that case, because that works only if we have a die. */ | |
11870 | && DECL_INITIAL (decl) != NULL_TREE) | |
1cfdcc15 | 11871 | { |
1edf43d6 | 11872 | dwarf2out_abstract_function (decl); |
1cfdcc15 JM |
11873 | set_decl_origin_self (decl); |
11874 | } | |
2ad9852d | 11875 | |
5daf7c0a JM |
11876 | /* Otherwise we're emitting the primary DIE for this decl. */ |
11877 | else if (debug_info_level > DINFO_LEVEL_TERSE) | |
a94dbf2c JM |
11878 | { |
11879 | /* Before we describe the FUNCTION_DECL itself, make sure that we | |
11880 | have described its return type. */ | |
11881 | gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); | |
11882 | ||
2081603c JM |
11883 | /* And its virtual context. */ |
11884 | if (DECL_VINDEX (decl) != NULL_TREE) | |
11885 | gen_type_die (DECL_CONTEXT (decl), context_die); | |
11886 | ||
a94dbf2c JM |
11887 | /* And its containing type. */ |
11888 | origin = decl_class_context (decl); | |
71dfc51f | 11889 | if (origin != NULL_TREE) |
10a11b75 | 11890 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 11891 | } |
a3f97cbb JW |
11892 | |
11893 | /* Now output a DIE to represent the function itself. */ | |
11894 | gen_subprogram_die (decl, context_die); | |
11895 | break; | |
11896 | ||
11897 | case TYPE_DECL: | |
11898 | /* If we are in terse mode, don't generate any DIEs to represent any | |
4927276d | 11899 | actual typedefs. */ |
a3f97cbb | 11900 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 11901 | break; |
a3f97cbb | 11902 | |
2ad9852d RK |
11903 | /* In the special case of a TYPE_DECL node representing the declaration |
11904 | of some type tag, if the given TYPE_DECL is marked as having been | |
11905 | instantiated from some other (original) TYPE_DECL node (e.g. one which | |
11906 | was generated within the original definition of an inline function) we | |
11907 | have to generate a special (abbreviated) DW_TAG_structure_type, | |
11908 | DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */ | |
2081603c | 11909 | if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE) |
a3f97cbb JW |
11910 | { |
11911 | gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die); | |
11912 | break; | |
11913 | } | |
a3f97cbb | 11914 | |
a94dbf2c JM |
11915 | if (is_redundant_typedef (decl)) |
11916 | gen_type_die (TREE_TYPE (decl), context_die); | |
11917 | else | |
71dfc51f RK |
11918 | /* Output a DIE to represent the typedef itself. */ |
11919 | gen_typedef_die (decl, context_die); | |
a3f97cbb JW |
11920 | break; |
11921 | ||
11922 | case LABEL_DECL: | |
11923 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
71dfc51f | 11924 | gen_label_die (decl, context_die); |
a3f97cbb JW |
11925 | break; |
11926 | ||
11927 | case VAR_DECL: | |
11928 | /* If we are in terse mode, don't generate any DIEs to represent any | |
11929 | variable declarations or definitions. */ | |
11930 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 11931 | break; |
a3f97cbb JW |
11932 | |
11933 | /* Output any DIEs that are needed to specify the type of this data | |
11934 | object. */ | |
11935 | gen_type_die (TREE_TYPE (decl), context_die); | |
11936 | ||
a94dbf2c JM |
11937 | /* And its containing type. */ |
11938 | origin = decl_class_context (decl); | |
71dfc51f | 11939 | if (origin != NULL_TREE) |
10a11b75 | 11940 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 11941 | |
a3f97cbb JW |
11942 | /* Now output the DIE to represent the data object itself. This gets |
11943 | complicated because of the possibility that the VAR_DECL really | |
11944 | represents an inlined instance of a formal parameter for an inline | |
11945 | function. */ | |
11946 | origin = decl_ultimate_origin (decl); | |
71dfc51f RK |
11947 | if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL) |
11948 | gen_formal_parameter_die (decl, context_die); | |
a3f97cbb | 11949 | else |
71dfc51f | 11950 | gen_variable_die (decl, context_die); |
a3f97cbb JW |
11951 | break; |
11952 | ||
11953 | case FIELD_DECL: | |
2ad9852d RK |
11954 | /* Ignore the nameless fields that are used to skip bits but handle C++ |
11955 | anonymous unions. */ | |
71dfc51f RK |
11956 | if (DECL_NAME (decl) != NULL_TREE |
11957 | || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE) | |
a3f97cbb JW |
11958 | { |
11959 | gen_type_die (member_declared_type (decl), context_die); | |
11960 | gen_field_die (decl, context_die); | |
11961 | } | |
11962 | break; | |
11963 | ||
11964 | case PARM_DECL: | |
11965 | gen_type_die (TREE_TYPE (decl), context_die); | |
11966 | gen_formal_parameter_die (decl, context_die); | |
11967 | break; | |
11968 | ||
348bb3c7 JM |
11969 | case NAMESPACE_DECL: |
11970 | /* Ignore for now. */ | |
11971 | break; | |
11972 | ||
a3f97cbb JW |
11973 | default: |
11974 | abort (); | |
11975 | } | |
a3f97cbb | 11976 | } |
54ba1f0d RH |
11977 | |
11978 | static void | |
11979 | mark_limbo_die_list (ptr) | |
11980 | void *ptr ATTRIBUTE_UNUSED; | |
11981 | { | |
11982 | limbo_die_node *node; | |
c26fbbca | 11983 | for (node = limbo_die_list; node; node = node->next) |
54ba1f0d RH |
11984 | ggc_mark_tree (node->created_for); |
11985 | } | |
a3f97cbb | 11986 | \f |
14a774a9 RK |
11987 | /* Add Ada "use" clause information for SGI Workshop debugger. */ |
11988 | ||
11989 | void | |
11990 | dwarf2out_add_library_unit_info (filename, context_list) | |
c6991660 KG |
11991 | const char *filename; |
11992 | const char *context_list; | |
14a774a9 RK |
11993 | { |
11994 | unsigned int file_index; | |
11995 | ||
11996 | if (filename != NULL) | |
11997 | { | |
54ba1f0d | 11998 | dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL); |
556273e0 | 11999 | tree context_list_decl |
14a774a9 RK |
12000 | = build_decl (LABEL_DECL, get_identifier (context_list), |
12001 | void_type_node); | |
12002 | ||
12003 | TREE_PUBLIC (context_list_decl) = TRUE; | |
12004 | add_name_attribute (unit_die, context_list); | |
981975b6 | 12005 | file_index = lookup_filename (filename); |
14a774a9 RK |
12006 | add_AT_unsigned (unit_die, DW_AT_decl_file, file_index); |
12007 | add_pubname (context_list_decl, unit_die); | |
12008 | } | |
12009 | } | |
12010 | ||
2ad9852d | 12011 | /* Output debug information for global decl DECL. Called from toplev.c after |
2b85879e | 12012 | compilation proper has finished. */ |
2ad9852d | 12013 | |
2b85879e NB |
12014 | static void |
12015 | dwarf2out_global_decl (decl) | |
12016 | tree decl; | |
12017 | { | |
12018 | /* Output DWARF2 information for file-scope tentative data object | |
2ad9852d RK |
12019 | declarations, file-scope (extern) function declarations (which had no |
12020 | corresponding body) and file-scope tagged type declarations and | |
12021 | definitions which have not yet been forced out. */ | |
2b85879e NB |
12022 | if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)) |
12023 | dwarf2out_decl (decl); | |
12024 | } | |
12025 | ||
71dfc51f RK |
12026 | /* Write the debugging output for DECL. */ |
12027 | ||
a3f97cbb | 12028 | void |
88dad228 | 12029 | dwarf2out_decl (decl) |
b3694847 | 12030 | tree decl; |
a3f97cbb | 12031 | { |
b3694847 | 12032 | dw_die_ref context_die = comp_unit_die; |
88dad228 | 12033 | |
a3f97cbb JW |
12034 | switch (TREE_CODE (decl)) |
12035 | { | |
2ad9852d RK |
12036 | case ERROR_MARK: |
12037 | return; | |
12038 | ||
a3f97cbb | 12039 | case FUNCTION_DECL: |
556273e0 | 12040 | /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a |
a3f97cbb JW |
12041 | builtin function. Explicit programmer-supplied declarations of |
12042 | these same functions should NOT be ignored however. */ | |
9765e357 | 12043 | if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl)) |
b1ccbc24 | 12044 | return; |
a3f97cbb JW |
12045 | |
12046 | /* What we would really like to do here is to filter out all mere | |
12047 | file-scope declarations of file-scope functions which are never | |
12048 | referenced later within this translation unit (and keep all of ones | |
556273e0 KH |
12049 | that *are* referenced later on) but we aren't clairvoyant, so we have |
12050 | no idea which functions will be referenced in the future (i.e. later | |
a3f97cbb | 12051 | on within the current translation unit). So here we just ignore all |
556273e0 | 12052 | file-scope function declarations which are not also definitions. If |
956d6950 | 12053 | and when the debugger needs to know something about these functions, |
556273e0 | 12054 | it will have to hunt around and find the DWARF information associated |
2ad9852d RK |
12055 | with the definition of the function. |
12056 | ||
12057 | We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL | |
12058 | nodes represent definitions and which ones represent mere | |
12059 | declarations. We have to check DECL_INITIAL instead. That's because | |
12060 | the C front-end supports some weird semantics for "extern inline" | |
12061 | function definitions. These can get inlined within the current | |
12062 | translation unit (an thus, we need to generate Dwarf info for their | |
12063 | abstract instances so that the Dwarf info for the concrete inlined | |
12064 | instances can have something to refer to) but the compiler never | |
12065 | generates any out-of-lines instances of such things (despite the fact | |
12066 | that they *are* definitions). | |
12067 | ||
12068 | The important point is that the C front-end marks these "extern | |
12069 | inline" functions as DECL_EXTERNAL, but we need to generate DWARF for | |
12070 | them anyway. Note that the C++ front-end also plays some similar games | |
12071 | for inline function definitions appearing within include files which | |
12072 | also contain `#pragma interface' pragmas. */ | |
a3f97cbb | 12073 | if (DECL_INITIAL (decl) == NULL_TREE) |
b1ccbc24 | 12074 | return; |
88dad228 | 12075 | |
9c6cd30e JM |
12076 | /* If we're a nested function, initially use a parent of NULL; if we're |
12077 | a plain function, this will be fixed up in decls_for_scope. If | |
12078 | we're a method, it will be ignored, since we already have a DIE. */ | |
88dad228 | 12079 | if (decl_function_context (decl)) |
9c6cd30e | 12080 | context_die = NULL; |
a3f97cbb JW |
12081 | break; |
12082 | ||
12083 | case VAR_DECL: | |
556273e0 | 12084 | /* Ignore this VAR_DECL if it refers to a file-scope extern data object |
a3f97cbb JW |
12085 | declaration and if the declaration was never even referenced from |
12086 | within this entire compilation unit. We suppress these DIEs in | |
12087 | order to save space in the .debug section (by eliminating entries | |
12088 | which are probably useless). Note that we must not suppress | |
12089 | block-local extern declarations (whether used or not) because that | |
12090 | would screw-up the debugger's name lookup mechanism and cause it to | |
12091 | miss things which really ought to be in scope at a given point. */ | |
12092 | if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) | |
71dfc51f | 12093 | return; |
a3f97cbb JW |
12094 | |
12095 | /* If we are in terse mode, don't generate any DIEs to represent any | |
12096 | variable declarations or definitions. */ | |
12097 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 12098 | return; |
a3f97cbb JW |
12099 | break; |
12100 | ||
12101 | case TYPE_DECL: | |
57fb7689 JM |
12102 | /* Don't emit stubs for types unless they are needed by other DIEs. */ |
12103 | if (TYPE_DECL_SUPPRESS_DEBUG (decl)) | |
12104 | return; | |
12105 | ||
a3f97cbb | 12106 | /* Don't bother trying to generate any DIEs to represent any of the |
a9d38797 JM |
12107 | normal built-in types for the language we are compiling. */ |
12108 | if (DECL_SOURCE_LINE (decl) == 0) | |
a94dbf2c JM |
12109 | { |
12110 | /* OK, we need to generate one for `bool' so GDB knows what type | |
12111 | comparisons have. */ | |
12112 | if ((get_AT_unsigned (comp_unit_die, DW_AT_language) | |
12113 | == DW_LANG_C_plus_plus) | |
f11c3043 RK |
12114 | && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE |
12115 | && ! DECL_IGNORED_P (decl)) | |
a94dbf2c | 12116 | modified_type_die (TREE_TYPE (decl), 0, 0, NULL); |
71dfc51f | 12117 | |
a94dbf2c JM |
12118 | return; |
12119 | } | |
a3f97cbb | 12120 | |
88dad228 | 12121 | /* If we are in terse mode, don't generate any DIEs for types. */ |
a3f97cbb | 12122 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 12123 | return; |
88dad228 JM |
12124 | |
12125 | /* If we're a function-scope tag, initially use a parent of NULL; | |
12126 | this will be fixed up in decls_for_scope. */ | |
12127 | if (decl_function_context (decl)) | |
3f76745e | 12128 | context_die = NULL; |
88dad228 | 12129 | |
a3f97cbb JW |
12130 | break; |
12131 | ||
12132 | default: | |
12133 | return; | |
12134 | } | |
12135 | ||
88dad228 | 12136 | gen_decl_die (decl, context_die); |
a3f97cbb JW |
12137 | } |
12138 | ||
12139 | /* Output a marker (i.e. a label) for the beginning of the generated code for | |
12140 | a lexical block. */ | |
71dfc51f | 12141 | |
a5a42b92 | 12142 | static void |
e2a12aca | 12143 | dwarf2out_begin_block (line, blocknum) |
a5a42b92 NB |
12144 | unsigned int line ATTRIBUTE_UNUSED; |
12145 | unsigned int blocknum; | |
a3f97cbb | 12146 | { |
a3f97cbb | 12147 | function_section (current_function_decl); |
8215347e | 12148 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum); |
a3f97cbb JW |
12149 | } |
12150 | ||
12151 | /* Output a marker (i.e. a label) for the end of the generated code for a | |
12152 | lexical block. */ | |
71dfc51f | 12153 | |
a5a42b92 | 12154 | static void |
e2a12aca | 12155 | dwarf2out_end_block (line, blocknum) |
a5a42b92 NB |
12156 | unsigned int line ATTRIBUTE_UNUSED; |
12157 | unsigned int blocknum; | |
a3f97cbb | 12158 | { |
a3f97cbb | 12159 | function_section (current_function_decl); |
8215347e | 12160 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum); |
a3f97cbb JW |
12161 | } |
12162 | ||
64b59a80 JM |
12163 | /* Returns nonzero if it is appropriate not to emit any debugging |
12164 | information for BLOCK, because it doesn't contain any instructions. | |
fcd7f76b | 12165 | |
64b59a80 JM |
12166 | Don't allow this for blocks with nested functions or local classes |
12167 | as we would end up with orphans, and in the presence of scheduling | |
12168 | we may end up calling them anyway. */ | |
12169 | ||
e1772ac0 | 12170 | static bool |
fcd7f76b JM |
12171 | dwarf2out_ignore_block (block) |
12172 | tree block; | |
12173 | { | |
12174 | tree decl; | |
2ad9852d | 12175 | |
fcd7f76b | 12176 | for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) |
64b59a80 JM |
12177 | if (TREE_CODE (decl) == FUNCTION_DECL |
12178 | || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))) | |
12179 | return 0; | |
2ad9852d | 12180 | |
64b59a80 | 12181 | return 1; |
fcd7f76b JM |
12182 | } |
12183 | ||
2ad9852d | 12184 | /* Lookup FILE_NAME (in the list of filenames that we know about here in |
9a666dda | 12185 | dwarf2out.c) and return its "index". The index of each (known) filename is |
2ad9852d RK |
12186 | just a unique number which is associated with only that one filename. We |
12187 | need such numbers for the sake of generating labels (in the .debug_sfnames | |
12188 | section) and references to those files numbers (in the .debug_srcinfo | |
12189 | and.debug_macinfo sections). If the filename given as an argument is not | |
12190 | found in our current list, add it to the list and assign it the next | |
12191 | available unique index number. In order to speed up searches, we remember | |
12192 | the index of the filename was looked up last. This handles the majority of | |
12193 | all searches. */ | |
71dfc51f | 12194 | |
a3f97cbb | 12195 | static unsigned |
981975b6 | 12196 | lookup_filename (file_name) |
d560ee52 | 12197 | const char *file_name; |
a3f97cbb | 12198 | { |
b3694847 | 12199 | unsigned i; |
a3f97cbb | 12200 | |
981975b6 RH |
12201 | /* ??? Why isn't DECL_SOURCE_FILE left null instead. */ |
12202 | if (strcmp (file_name, "<internal>") == 0 | |
12203 | || strcmp (file_name, "<built-in>") == 0) | |
12204 | return 0; | |
12205 | ||
2e18bbae RH |
12206 | /* Check to see if the file name that was searched on the previous |
12207 | call matches this file name. If so, return the index. */ | |
981975b6 | 12208 | if (file_table.last_lookup_index != 0) |
2ad9852d RK |
12209 | if (0 == strcmp (file_name, |
12210 | file_table.table[file_table.last_lookup_index])) | |
981975b6 | 12211 | return file_table.last_lookup_index; |
a3f97cbb JW |
12212 | |
12213 | /* Didn't match the previous lookup, search the table */ | |
2ad9852d | 12214 | for (i = 1; i < file_table.in_use; i++) |
981975b6 | 12215 | if (strcmp (file_name, file_table.table[i]) == 0) |
71dfc51f | 12216 | { |
981975b6 | 12217 | file_table.last_lookup_index = i; |
71dfc51f RK |
12218 | return i; |
12219 | } | |
a3f97cbb | 12220 | |
556273e0 | 12221 | /* Prepare to add a new table entry by making sure there is enough space in |
a3f97cbb | 12222 | the table to do so. If not, expand the current table. */ |
981975b6 | 12223 | if (i == file_table.allocated) |
a3f97cbb | 12224 | { |
981975b6 RH |
12225 | file_table.allocated = i + FILE_TABLE_INCREMENT; |
12226 | file_table.table = (char **) | |
12227 | xrealloc (file_table.table, file_table.allocated * sizeof (char *)); | |
a3f97cbb JW |
12228 | } |
12229 | ||
71dfc51f | 12230 | /* Add the new entry to the end of the filename table. */ |
981975b6 RH |
12231 | file_table.table[i] = xstrdup (file_name); |
12232 | file_table.in_use = i + 1; | |
12233 | file_table.last_lookup_index = i; | |
2e18bbae | 12234 | |
acc187f5 | 12235 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
211a0cbe GDR |
12236 | { |
12237 | fprintf (asm_out_file, "\t.file %u ", i); | |
12238 | output_quoted_string (asm_out_file, file_name); | |
12239 | fputc ('\n', asm_out_file); | |
12240 | } | |
acc187f5 | 12241 | |
2e18bbae RH |
12242 | return i; |
12243 | } | |
12244 | ||
12245 | static void | |
981975b6 | 12246 | init_file_table () |
2e18bbae RH |
12247 | { |
12248 | /* Allocate the initial hunk of the file_table. */ | |
981975b6 RH |
12249 | file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *)); |
12250 | file_table.allocated = FILE_TABLE_INCREMENT; | |
71dfc51f | 12251 | |
2e18bbae | 12252 | /* Skip the first entry - file numbers begin at 1. */ |
981975b6 RH |
12253 | file_table.in_use = 1; |
12254 | file_table.last_lookup_index = 0; | |
a3f97cbb JW |
12255 | } |
12256 | ||
12257 | /* Output a label to mark the beginning of a source code line entry | |
12258 | and record information relating to this source line, in | |
12259 | 'line_info_table' for later output of the .debug_line section. */ | |
71dfc51f | 12260 | |
e2a12aca | 12261 | static void |
653e276c NB |
12262 | dwarf2out_source_line (line, filename) |
12263 | unsigned int line; | |
b3694847 | 12264 | const char *filename; |
a3f97cbb | 12265 | { |
a3f97cbb JW |
12266 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
12267 | { | |
12268 | function_section (current_function_decl); | |
a3f97cbb | 12269 | |
8aaf55ac JM |
12270 | /* If requested, emit something human-readable. */ |
12271 | if (flag_debug_asm) | |
12272 | fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, | |
12273 | filename, line); | |
12274 | ||
b2244e22 JW |
12275 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
12276 | { | |
981975b6 | 12277 | unsigned file_num = lookup_filename (filename); |
b2244e22 | 12278 | |
981975b6 | 12279 | /* Emit the .loc directive understood by GNU as. */ |
2e18bbae | 12280 | fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line); |
b2244e22 JW |
12281 | |
12282 | /* Indicate that line number info exists. */ | |
2ad9852d | 12283 | line_info_table_in_use++; |
b2244e22 JW |
12284 | |
12285 | /* Indicate that multiple line number tables exist. */ | |
12286 | if (DECL_SECTION_NAME (current_function_decl)) | |
2ad9852d | 12287 | separate_line_info_table_in_use++; |
b2244e22 JW |
12288 | } |
12289 | else if (DECL_SECTION_NAME (current_function_decl)) | |
a3f97cbb | 12290 | { |
b3694847 | 12291 | dw_separate_line_info_ref line_info; |
4977bab6 | 12292 | (*targetm.asm_out.internal_label) (asm_out_file, SEPARATE_LINE_CODE_LABEL, |
5c90448c | 12293 | separate_line_info_table_in_use); |
e90b62db JM |
12294 | |
12295 | /* expand the line info table if necessary */ | |
12296 | if (separate_line_info_table_in_use | |
12297 | == separate_line_info_table_allocated) | |
12298 | { | |
12299 | separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
12300 | separate_line_info_table | |
71dfc51f RK |
12301 | = (dw_separate_line_info_ref) |
12302 | xrealloc (separate_line_info_table, | |
12303 | separate_line_info_table_allocated | |
12304 | * sizeof (dw_separate_line_info_entry)); | |
e90b62db | 12305 | } |
71dfc51f RK |
12306 | |
12307 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
12308 | line_info |
12309 | = &separate_line_info_table[separate_line_info_table_in_use++]; | |
981975b6 | 12310 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db | 12311 | line_info->dw_line_num = line; |
df696a75 | 12312 | line_info->function = current_function_funcdef_no; |
e90b62db JM |
12313 | } |
12314 | else | |
12315 | { | |
b3694847 | 12316 | dw_line_info_ref line_info; |
71dfc51f | 12317 | |
4977bab6 | 12318 | (*targetm.asm_out.internal_label) (asm_out_file, LINE_CODE_LABEL, |
5c90448c | 12319 | line_info_table_in_use); |
e90b62db | 12320 | |
71dfc51f | 12321 | /* Expand the line info table if necessary. */ |
e90b62db JM |
12322 | if (line_info_table_in_use == line_info_table_allocated) |
12323 | { | |
12324 | line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
12325 | line_info_table | |
71dfc51f RK |
12326 | = (dw_line_info_ref) |
12327 | xrealloc (line_info_table, | |
12328 | (line_info_table_allocated | |
12329 | * sizeof (dw_line_info_entry))); | |
e90b62db | 12330 | } |
71dfc51f RK |
12331 | |
12332 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db | 12333 | line_info = &line_info_table[line_info_table_in_use++]; |
981975b6 | 12334 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db | 12335 | line_info->dw_line_num = line; |
a3f97cbb | 12336 | } |
a3f97cbb JW |
12337 | } |
12338 | } | |
12339 | ||
30f7a378 | 12340 | /* Record the beginning of a new source file. */ |
71dfc51f | 12341 | |
7f905405 | 12342 | static void |
84a5b4f8 | 12343 | dwarf2out_start_source_file (lineno, filename) |
b3694847 SS |
12344 | unsigned int lineno; |
12345 | const char *filename; | |
a3f97cbb | 12346 | { |
cc0017a9 | 12347 | if (flag_eliminate_dwarf2_dups && !is_main_source) |
881c6935 JM |
12348 | { |
12349 | /* Record the beginning of the file for break_out_includes. */ | |
cc0017a9 ZD |
12350 | dw_die_ref bincl_die; |
12351 | ||
12352 | bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL); | |
881c6935 JM |
12353 | add_AT_string (bincl_die, DW_AT_name, filename); |
12354 | } | |
2ad9852d | 12355 | |
cc0017a9 ZD |
12356 | is_main_source = 0; |
12357 | ||
84a5b4f8 DB |
12358 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12359 | { | |
715bdd29 | 12360 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 | 12361 | dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file"); |
7c262518 RH |
12362 | dw2_asm_output_data_uleb128 (lineno, "Included from line number %d", |
12363 | lineno); | |
12364 | dw2_asm_output_data_uleb128 (lookup_filename (filename), | |
12365 | "Filename we just started"); | |
84a5b4f8 | 12366 | } |
a3f97cbb JW |
12367 | } |
12368 | ||
cc260610 | 12369 | /* Record the end of a source file. */ |
71dfc51f | 12370 | |
7f905405 NB |
12371 | static void |
12372 | dwarf2out_end_source_file (lineno) | |
12373 | unsigned int lineno ATTRIBUTE_UNUSED; | |
a3f97cbb | 12374 | { |
881c6935 | 12375 | if (flag_eliminate_dwarf2_dups) |
2ad9852d | 12376 | /* Record the end of the file for break_out_includes. */ |
54ba1f0d | 12377 | new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL); |
2ad9852d | 12378 | |
84a5b4f8 DB |
12379 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12380 | { | |
715bdd29 | 12381 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
12382 | dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); |
12383 | } | |
a3f97cbb JW |
12384 | } |
12385 | ||
cc260610 | 12386 | /* Called from debug_define in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
12387 | the tail part of the directive line, i.e. the part which is past the |
12388 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 12389 | |
7f905405 | 12390 | static void |
9a666dda | 12391 | dwarf2out_define (lineno, buffer) |
b3694847 SS |
12392 | unsigned lineno ATTRIBUTE_UNUSED; |
12393 | const char *buffer ATTRIBUTE_UNUSED; | |
a3f97cbb | 12394 | { |
84a5b4f8 DB |
12395 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12396 | { | |
715bdd29 | 12397 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
12398 | dw2_asm_output_data (1, DW_MACINFO_define, "Define macro"); |
12399 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
12400 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
12401 | } | |
a3f97cbb JW |
12402 | } |
12403 | ||
cc260610 | 12404 | /* Called from debug_undef in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
12405 | the tail part of the directive line, i.e. the part which is past the |
12406 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 12407 | |
7f905405 | 12408 | static void |
9a666dda | 12409 | dwarf2out_undef (lineno, buffer) |
b3694847 SS |
12410 | unsigned lineno ATTRIBUTE_UNUSED; |
12411 | const char *buffer ATTRIBUTE_UNUSED; | |
a3f97cbb | 12412 | { |
84a5b4f8 DB |
12413 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12414 | { | |
715bdd29 | 12415 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
12416 | dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro"); |
12417 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
12418 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
12419 | } | |
a3f97cbb JW |
12420 | } |
12421 | ||
12422 | /* Set up for Dwarf output at the start of compilation. */ | |
71dfc51f | 12423 | |
a51d908e | 12424 | static void |
e2a12aca | 12425 | dwarf2out_init (main_input_filename) |
b3694847 | 12426 | const char *main_input_filename; |
a3f97cbb | 12427 | { |
acc187f5 RH |
12428 | init_file_table (); |
12429 | ||
4977bab6 ZW |
12430 | /* Add the name of the primary input file to the file table first, |
12431 | under the assumption that we'll be emitting line number data for | |
12432 | it first, which avoids having to add an initial DW_LNS_set_file. */ | |
acc187f5 | 12433 | lookup_filename (main_input_filename); |
a3f97cbb | 12434 | |
a3f97cbb JW |
12435 | /* Allocate the initial hunk of the decl_die_table. */ |
12436 | decl_die_table | |
3de90026 | 12437 | = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref)); |
a3f97cbb JW |
12438 | decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT; |
12439 | decl_die_table_in_use = 0; | |
12440 | ||
12441 | /* Allocate the initial hunk of the decl_scope_table. */ | |
244a4af0 | 12442 | VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table"); |
a3f97cbb JW |
12443 | |
12444 | /* Allocate the initial hunk of the abbrev_die_table. */ | |
12445 | abbrev_die_table | |
3de90026 RH |
12446 | = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT, |
12447 | sizeof (dw_die_ref)); | |
a3f97cbb | 12448 | abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT; |
71dfc51f | 12449 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
12450 | abbrev_die_table_in_use = 1; |
12451 | ||
12452 | /* Allocate the initial hunk of the line_info_table. */ | |
12453 | line_info_table | |
3de90026 RH |
12454 | = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT, |
12455 | sizeof (dw_line_info_entry)); | |
a3f97cbb | 12456 | line_info_table_allocated = LINE_INFO_TABLE_INCREMENT; |
2ad9852d | 12457 | |
71dfc51f | 12458 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
12459 | line_info_table_in_use = 1; |
12460 | ||
556273e0 | 12461 | /* Generate the initial DIE for the .debug section. Note that the (string) |
a3f97cbb | 12462 | value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE |
556273e0 | 12463 | will (typically) be a relative pathname and that this pathname should be |
a3f97cbb JW |
12464 | taken as being relative to the directory from which the compiler was |
12465 | invoked when the given (base) source file was compiled. */ | |
a96c67ec | 12466 | comp_unit_die = gen_compile_unit_die (main_input_filename); |
cc0017a9 | 12467 | is_main_source = 1; |
a3f97cbb | 12468 | |
244a4af0 | 12469 | VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types"); |
244a4af0 | 12470 | |
1f8f4a0b | 12471 | VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray"); |
1865dbb5 | 12472 | |
54ba1f0d RH |
12473 | ggc_add_root (&limbo_die_list, 1, 1, mark_limbo_die_list); |
12474 | ||
5c90448c | 12475 | ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0); |
9d2f2c45 RH |
12476 | ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, |
12477 | DEBUG_ABBREV_SECTION_LABEL, 0); | |
b366352b MM |
12478 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) |
12479 | ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0); | |
12480 | else | |
f99ffb60 | 12481 | strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME)); |
2ad9852d | 12482 | |
556273e0 | 12483 | ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label, |
8b790721 | 12484 | DEBUG_INFO_SECTION_LABEL, 0); |
556273e0 | 12485 | ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label, |
8b790721 | 12486 | DEBUG_LINE_SECTION_LABEL, 0); |
2bee6045 JJ |
12487 | ASM_GENERATE_INTERNAL_LABEL (ranges_section_label, |
12488 | DEBUG_RANGES_SECTION_LABEL, 0); | |
715bdd29 | 12489 | named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG); |
8b790721 | 12490 | ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label); |
715bdd29 | 12491 | named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG); |
8b790721 | 12492 | ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label); |
715bdd29 | 12493 | named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG); |
8b790721 | 12494 | ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label); |
2ad9852d | 12495 | |
84a5b4f8 DB |
12496 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12497 | { | |
715bdd29 | 12498 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
12499 | ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label, |
12500 | DEBUG_MACINFO_SECTION_LABEL, 0); | |
12501 | ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label); | |
12502 | } | |
7c262518 RH |
12503 | |
12504 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) | |
12505 | { | |
12506 | text_section (); | |
12507 | ASM_OUTPUT_LABEL (asm_out_file, text_section_label); | |
12508 | } | |
a3f97cbb JW |
12509 | } |
12510 | ||
9eb4015a JJ |
12511 | /* Allocate a string in .debug_str hash table. */ |
12512 | ||
12513 | static hashnode | |
12514 | indirect_string_alloc (tab) | |
12515 | hash_table *tab ATTRIBUTE_UNUSED; | |
12516 | { | |
12517 | struct indirect_string_node *node; | |
12518 | ||
12519 | node = xmalloc (sizeof (struct indirect_string_node)); | |
12520 | node->refcount = 0; | |
12521 | node->form = 0; | |
12522 | node->label = NULL; | |
2ad9852d | 12523 | |
9eb4015a JJ |
12524 | return (hashnode) node; |
12525 | } | |
12526 | ||
12527 | /* A helper function for dwarf2out_finish called through | |
12528 | ht_forall. Emit one queued .debug_str string. */ | |
12529 | ||
12530 | static int | |
12531 | output_indirect_string (pfile, h, v) | |
12532 | struct cpp_reader *pfile ATTRIBUTE_UNUSED; | |
12533 | hashnode h; | |
12534 | const PTR v ATTRIBUTE_UNUSED; | |
12535 | { | |
2ad9852d | 12536 | struct indirect_string_node *node = (struct indirect_string_node *) h; |
9eb4015a | 12537 | |
9eb4015a JJ |
12538 | if (node->form == DW_FORM_strp) |
12539 | { | |
12540 | named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS); | |
12541 | ASM_OUTPUT_LABEL (asm_out_file, node->label); | |
12542 | assemble_string ((const char *) HT_STR (&node->id), | |
12543 | HT_LEN (&node->id) + 1); | |
12544 | } | |
2ad9852d | 12545 | |
9eb4015a JJ |
12546 | return 1; |
12547 | } | |
12548 | ||
a3f97cbb JW |
12549 | /* Output stuff that dwarf requires at the end of every file, |
12550 | and generate the DWARF-2 debugging info. */ | |
71dfc51f | 12551 | |
a51d908e | 12552 | static void |
e2a12aca | 12553 | dwarf2out_finish (input_filename) |
b3694847 | 12554 | const char *input_filename ATTRIBUTE_UNUSED; |
a3f97cbb | 12555 | { |
ef76d03b | 12556 | limbo_die_node *node, *next_node; |
ae0ed63a | 12557 | dw_die_ref die = 0; |
ef76d03b JW |
12558 | |
12559 | /* Traverse the limbo die list, and add parent/child links. The only | |
12560 | dies without parents that should be here are concrete instances of | |
12561 | inline functions, and the comp_unit_die. We can ignore the comp_unit_die. | |
12562 | For concrete instances, we can get the parent die from the abstract | |
12563 | instance. */ | |
12564 | for (node = limbo_die_list; node; node = next_node) | |
12565 | { | |
12566 | next_node = node->next; | |
12567 | die = node->die; | |
12568 | ||
12569 | if (die->die_parent == NULL) | |
12570 | { | |
a96c67ec | 12571 | dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin); |
54ba1f0d | 12572 | tree context; |
2ad9852d | 12573 | |
a96c67ec JM |
12574 | if (origin) |
12575 | add_child_die (origin->die_parent, die); | |
ef76d03b | 12576 | else if (die == comp_unit_die) |
a96c67ec | 12577 | ; |
aea9695c RK |
12578 | /* If this was an expression for a bound involved in a function |
12579 | return type, it may be a SAVE_EXPR for which we weren't able | |
12580 | to find a DIE previously. So try now. */ | |
12581 | else if (node->created_for | |
12582 | && TREE_CODE (node->created_for) == SAVE_EXPR | |
12583 | && 0 != (origin = (lookup_decl_die | |
12584 | (SAVE_EXPR_CONTEXT | |
12585 | (node->created_for))))) | |
12586 | add_child_die (origin, die); | |
6bb28965 JM |
12587 | else if (errorcount > 0 || sorrycount > 0) |
12588 | /* It's OK to be confused by errors in the input. */ | |
12589 | add_child_die (comp_unit_die, die); | |
54ba1f0d RH |
12590 | else if (node->created_for |
12591 | && ((DECL_P (node->created_for) | |
c26fbbca | 12592 | && (context = DECL_CONTEXT (node->created_for))) |
54ba1f0d RH |
12593 | || (TYPE_P (node->created_for) |
12594 | && (context = TYPE_CONTEXT (node->created_for)))) | |
12595 | && TREE_CODE (context) == FUNCTION_DECL) | |
12596 | { | |
12597 | /* In certain situations, the lexical block containing a | |
12598 | nested function can be optimized away, which results | |
12599 | in the nested function die being orphaned. Likewise | |
12600 | with the return type of that nested function. Force | |
12601 | this to be a child of the containing function. */ | |
12602 | origin = lookup_decl_die (context); | |
12603 | if (! origin) | |
12604 | abort (); | |
12605 | add_child_die (origin, die); | |
12606 | } | |
ef76d03b JW |
12607 | else |
12608 | abort (); | |
12609 | } | |
2ad9852d | 12610 | |
ef76d03b JW |
12611 | free (node); |
12612 | } | |
2ad9852d | 12613 | |
a96c67ec | 12614 | limbo_die_list = NULL; |
ef76d03b | 12615 | |
8a8c3656 JM |
12616 | /* Walk through the list of incomplete types again, trying once more to |
12617 | emit full debugging info for them. */ | |
12618 | retry_incomplete_types (); | |
12619 | ||
881c6935 JM |
12620 | /* We need to reverse all the dies before break_out_includes, or |
12621 | we'll see the end of an include file before the beginning. */ | |
12622 | reverse_all_dies (comp_unit_die); | |
12623 | ||
12624 | /* Generate separate CUs for each of the include files we've seen. | |
12625 | They will go into limbo_die_list. */ | |
5f632b5e JM |
12626 | if (flag_eliminate_dwarf2_dups) |
12627 | break_out_includes (comp_unit_die); | |
881c6935 JM |
12628 | |
12629 | /* Traverse the DIE's and add add sibling attributes to those DIE's | |
12630 | that have children. */ | |
a3f97cbb | 12631 | add_sibling_attributes (comp_unit_die); |
881c6935 JM |
12632 | for (node = limbo_die_list; node; node = node->next) |
12633 | add_sibling_attributes (node->die); | |
a3f97cbb JW |
12634 | |
12635 | /* Output a terminator label for the .text section. */ | |
7c262518 | 12636 | text_section (); |
4977bab6 | 12637 | (*targetm.asm_out.internal_label) (asm_out_file, TEXT_END_LABEL, 0); |
a3f97cbb | 12638 | |
db3c0315 MM |
12639 | /* Output the source line correspondence table. We must do this |
12640 | even if there is no line information. Otherwise, on an empty | |
12641 | translation unit, we will generate a present, but empty, | |
12642 | .debug_info section. IRIX 6.5 `nm' will then complain when | |
12643 | examining the file. */ | |
12644 | if (! DWARF2_ASM_LINE_DEBUG_INFO) | |
e90b62db | 12645 | { |
715bdd29 | 12646 | named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG); |
db3c0315 MM |
12647 | output_line_info (); |
12648 | } | |
71dfc51f | 12649 | |
b38a75e5 RH |
12650 | /* Output location list section if necessary. */ |
12651 | if (have_location_lists) | |
12652 | { | |
12653 | /* Output the location lists info. */ | |
12654 | named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG); | |
12655 | ASM_GENERATE_INTERNAL_LABEL (loc_section_label, | |
12656 | DEBUG_LOC_SECTION_LABEL, 0); | |
12657 | ASM_OUTPUT_LABEL (asm_out_file, loc_section_label); | |
12658 | output_location_lists (die); | |
12659 | have_location_lists = 0; | |
12660 | } | |
12661 | ||
db3c0315 MM |
12662 | /* We can only use the low/high_pc attributes if all of the code was |
12663 | in .text. */ | |
12664 | if (separate_line_info_table_in_use == 0) | |
12665 | { | |
12666 | add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label); | |
12667 | add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label); | |
e90b62db | 12668 | } |
2ad9852d RK |
12669 | |
12670 | /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate | |
12671 | "base address". Use zero so that these addresses become absolute. */ | |
a20612aa RH |
12672 | else if (have_location_lists || ranges_table_in_use) |
12673 | add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx); | |
e90b62db | 12674 | |
fe7cd37f RH |
12675 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
12676 | add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list, | |
12677 | debug_line_section_label); | |
db3c0315 | 12678 | |
84a5b4f8 DB |
12679 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12680 | add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label); | |
a96c67ec | 12681 | |
881c6935 JM |
12682 | /* Output all of the compilation units. We put the main one last so that |
12683 | the offsets are available to output_pubnames. */ | |
12684 | for (node = limbo_die_list; node; node = node->next) | |
cc0017a9 | 12685 | output_comp_unit (node->die, 0); |
2ad9852d | 12686 | |
cc0017a9 | 12687 | output_comp_unit (comp_unit_die, 0); |
881c6935 | 12688 | |
a3f97cbb | 12689 | /* Output the abbreviation table. */ |
715bdd29 | 12690 | named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG); |
a3f97cbb JW |
12691 | output_abbrev_section (); |
12692 | ||
2ad9852d | 12693 | /* Output public names table if necessary. */ |
d291dd49 JM |
12694 | if (pubname_table_in_use) |
12695 | { | |
715bdd29 | 12696 | named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG); |
d291dd49 JM |
12697 | output_pubnames (); |
12698 | } | |
12699 | ||
2ad9852d RK |
12700 | /* Output the address range information. We only put functions in the arange |
12701 | table, so don't write it out if we don't have any. */ | |
a3f97cbb JW |
12702 | if (fde_table_in_use) |
12703 | { | |
715bdd29 | 12704 | named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG); |
a3f97cbb JW |
12705 | output_aranges (); |
12706 | } | |
a20612aa | 12707 | |
a20612aa RH |
12708 | /* Output ranges section if necessary. */ |
12709 | if (ranges_table_in_use) | |
12710 | { | |
715bdd29 | 12711 | named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG); |
2bee6045 | 12712 | ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label); |
a20612aa RH |
12713 | output_ranges (); |
12714 | } | |
12715 | ||
30f7a378 | 12716 | /* Have to end the primary source file. */ |
cc260610 | 12717 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
c26fbbca | 12718 | { |
715bdd29 | 12719 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
cc260610 | 12720 | dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); |
2f8d482e | 12721 | dw2_asm_output_data (1, 0, "End compilation unit"); |
cc260610 | 12722 | } |
9eb4015a | 12723 | |
2ad9852d | 12724 | /* If we emitted any DW_FORM_strp form attribute, output the string |
9eb4015a JJ |
12725 | table too. */ |
12726 | if (debug_str_hash) | |
12727 | ht_forall (debug_str_hash, output_indirect_string, NULL); | |
a3f97cbb | 12728 | } |
e2500fed GK |
12729 | #else |
12730 | ||
12731 | /* This should never be used, but its address is needed for comparisons. */ | |
12732 | const struct gcc_debug_hooks dwarf2_debug_hooks; | |
12733 | ||
12734 | #endif /* DWARF2_DEBUGGING_INFO */ | |
12735 | ||
12736 | #include "gt-dwarf2out.h" |