]>
Commit | Line | Data |
---|---|---|
a3f97cbb | 1 | /* Output Dwarf2 format symbol table information from the GNU C compiler. |
54ba1f0d | 2 | Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 |
06ceef4e | 3 | Free Software Foundation, Inc. |
e9a25f70 JL |
4 | Contributed by Gary Funck (gary@intrepid.com). |
5 | Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com). | |
469ac993 | 6 | Extensively modified by Jason Merrill (jason@cygnus.com). |
a3f97cbb | 7 | |
1322177d | 8 | This file is part of GCC. |
a3f97cbb | 9 | |
1322177d LB |
10 | GCC is free software; you can redistribute it and/or modify it under |
11 | the terms of the GNU General Public License as published by the Free | |
12 | Software Foundation; either version 2, or (at your option) any later | |
13 | version. | |
a3f97cbb | 14 | |
1322177d LB |
15 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
16 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
17 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
18 | for more details. | |
a3f97cbb JW |
19 | |
20 | You should have received a copy of the GNU General Public License | |
1322177d LB |
21 | along with GCC; see the file COPYING. If not, write to the Free |
22 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
23 | 02111-1307, USA. */ | |
a3f97cbb | 24 | |
9eb4015a | 25 | /* TODO: Emit .debug_line header even when there are no functions, since |
348bb3c7 JM |
26 | the file numbers are used by .debug_info. Alternately, leave |
27 | out locations for types and decls. | |
28 | Avoid talking about ctors and op= for PODs. | |
29 | Factor out common prologue sequences into multiple CIEs. */ | |
30 | ||
3f76745e JM |
31 | /* The first part of this file deals with the DWARF 2 frame unwind |
32 | information, which is also used by the GCC efficient exception handling | |
33 | mechanism. The second part, controlled only by an #ifdef | |
34 | DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging | |
35 | information. */ | |
36 | ||
0021b564 | 37 | #include "config.h" |
670ee920 | 38 | #include "system.h" |
a3f97cbb JW |
39 | #include "tree.h" |
40 | #include "flags.h" | |
11ad4784 | 41 | #include "real.h" |
a3f97cbb JW |
42 | #include "rtl.h" |
43 | #include "hard-reg-set.h" | |
44 | #include "regs.h" | |
45 | #include "insn-config.h" | |
46 | #include "reload.h" | |
52a11cbf | 47 | #include "function.h" |
a3f97cbb | 48 | #include "output.h" |
71dfc51f | 49 | #include "expr.h" |
e78d8e51 | 50 | #include "libfuncs.h" |
3f76745e | 51 | #include "except.h" |
a7cc7f29 | 52 | #include "dwarf2.h" |
76ead72b | 53 | #include "dwarf2out.h" |
2e4b9b8c | 54 | #include "dwarf2asm.h" |
10f0ad3d | 55 | #include "toplev.h" |
1865dbb5 | 56 | #include "varray.h" |
951a525f | 57 | #include "ggc.h" |
881c6935 | 58 | #include "md5.h" |
57bed152 | 59 | #include "tm_p.h" |
2a2b2d43 | 60 | #include "diagnostic.h" |
a51d908e | 61 | #include "debug.h" |
07c9d2eb | 62 | #include "target.h" |
3ac88239 | 63 | #include "langhooks.h" |
9eb4015a | 64 | #include "hashtable.h" |
a3f97cbb | 65 | |
653e276c NB |
66 | #ifdef DWARF2_DEBUGGING_INFO |
67 | static void dwarf2out_source_line PARAMS ((unsigned int, const char *)); | |
68 | #endif | |
69 | ||
770ca8c6 JO |
70 | /* DWARF2 Abbreviation Glossary: |
71 | CFA = Canonical Frame Address | |
00a42e21 JM |
72 | a fixed address on the stack which identifies a call frame. |
73 | We define it to be the value of SP just before the call insn. | |
74 | The CFA register and offset, which may change during the course | |
75 | of the function, are used to calculate its value at runtime. | |
a401107d JO |
76 | CFI = Call Frame Instruction |
77 | an instruction for the DWARF2 abstract machine | |
770ca8c6 JO |
78 | CIE = Common Information Entry |
79 | information describing information common to one or more FDEs | |
80 | DIE = Debugging Information Entry | |
81 | FDE = Frame Description Entry | |
82 | information describing the stack call frame, in particular, | |
83 | how to restore registers | |
84 | ||
85 | DW_CFA_... = DWARF2 CFA call frame instruction | |
86 | DW_TAG_... = DWARF2 DIE tag */ | |
87 | ||
0021b564 JM |
88 | /* Decide whether we want to emit frame unwind information for the current |
89 | translation unit. */ | |
90 | ||
91 | int | |
92 | dwarf2out_do_frame () | |
93 | { | |
94 | return (write_symbols == DWARF2_DEBUG | |
7a0c8d71 | 95 | || write_symbols == VMS_AND_DWARF2_DEBUG |
9ec36da5 | 96 | #ifdef DWARF2_FRAME_INFO |
556273e0 | 97 | || DWARF2_FRAME_INFO |
9ec36da5 | 98 | #endif |
0021b564 | 99 | #ifdef DWARF2_UNWIND_INFO |
14a774a9 | 100 | || flag_unwind_tables |
531073e7 | 101 | || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS) |
0021b564 JM |
102 | #endif |
103 | ); | |
104 | } | |
105 | ||
b1e6ab03 RH |
106 | /* The number of the current function definition for which debugging |
107 | information is being generated. These numbers range from 1 up to the | |
108 | maximum number of function definitions contained within the current | |
109 | compilation unit. These numbers are used to create unique label id's | |
110 | unique to each function definition. */ | |
111 | unsigned current_funcdef_number = 0; | |
112 | ||
f3a8e4f5 KG |
113 | /* The size of the target's pointer type. */ |
114 | #ifndef PTR_SIZE | |
115 | #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT) | |
116 | #endif | |
117 | ||
118 | /* Default version of targetm.eh_frame_section. Note this must appear | |
119 | outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro | |
120 | guards. */ | |
121 | ||
122 | void | |
123 | default_eh_frame_section () | |
124 | { | |
125 | #ifdef EH_FRAME_SECTION_NAME | |
126 | named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE); | |
127 | #else | |
128 | tree label = get_file_function_name ('F'); | |
129 | ||
130 | data_section (); | |
131 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); | |
132 | ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); | |
133 | ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); | |
134 | #endif | |
135 | } | |
136 | ||
0021b564 JM |
137 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) |
138 | ||
eaf95893 RK |
139 | /* How to start an assembler comment. */ |
140 | #ifndef ASM_COMMENT_START | |
141 | #define ASM_COMMENT_START ";#" | |
142 | #endif | |
143 | ||
a3f97cbb JW |
144 | typedef struct dw_cfi_struct *dw_cfi_ref; |
145 | typedef struct dw_fde_struct *dw_fde_ref; | |
146 | typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref; | |
a3f97cbb JW |
147 | |
148 | /* Call frames are described using a sequence of Call Frame | |
149 | Information instructions. The register number, offset | |
150 | and address fields are provided as possible operands; | |
151 | their use is selected by the opcode field. */ | |
71dfc51f | 152 | |
a3f97cbb | 153 | typedef union dw_cfi_oprnd_struct |
71dfc51f RK |
154 | { |
155 | unsigned long dw_cfi_reg_num; | |
156 | long int dw_cfi_offset; | |
d3e3972c | 157 | const char *dw_cfi_addr; |
7d9d8943 | 158 | struct dw_loc_descr_struct *dw_cfi_loc; |
71dfc51f | 159 | } |
a3f97cbb JW |
160 | dw_cfi_oprnd; |
161 | ||
162 | typedef struct dw_cfi_struct | |
71dfc51f RK |
163 | { |
164 | dw_cfi_ref dw_cfi_next; | |
165 | enum dwarf_call_frame_info dw_cfi_opc; | |
166 | dw_cfi_oprnd dw_cfi_oprnd1; | |
167 | dw_cfi_oprnd dw_cfi_oprnd2; | |
168 | } | |
a3f97cbb JW |
169 | dw_cfi_node; |
170 | ||
7d9d8943 AM |
171 | /* This is how we define the location of the CFA. We use to handle it |
172 | as REG + OFFSET all the time, but now it can be more complex. | |
173 | It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET. | |
556273e0 | 174 | Instead of passing around REG and OFFSET, we pass a copy |
7d9d8943 AM |
175 | of this structure. */ |
176 | typedef struct cfa_loc | |
177 | { | |
556273e0 | 178 | unsigned long reg; |
7d9d8943 AM |
179 | long offset; |
180 | long base_offset; | |
181 | int indirect; /* 1 if CFA is accessed via a dereference. */ | |
182 | } dw_cfa_location; | |
183 | ||
a3f97cbb | 184 | /* All call frame descriptions (FDE's) in the GCC generated DWARF |
4b674448 | 185 | refer to a single Common Information Entry (CIE), defined at |
fb530c07 | 186 | the beginning of the .debug_frame section. This use of a single |
a3f97cbb JW |
187 | CIE obviates the need to keep track of multiple CIE's |
188 | in the DWARF generation routines below. */ | |
71dfc51f | 189 | |
a3f97cbb | 190 | typedef struct dw_fde_struct |
71dfc51f | 191 | { |
d3e3972c KG |
192 | const char *dw_fde_begin; |
193 | const char *dw_fde_current_label; | |
194 | const char *dw_fde_end; | |
71dfc51f | 195 | dw_cfi_ref dw_fde_cfi; |
52a11cbf RH |
196 | unsigned funcdef_number; |
197 | unsigned nothrow : 1; | |
198 | unsigned uses_eh_lsda : 1; | |
71dfc51f | 199 | } |
a3f97cbb JW |
200 | dw_fde_node; |
201 | ||
6d2f8887 | 202 | /* Maximum size (in bytes) of an artificially generated label. */ |
a3f97cbb JW |
203 | #define MAX_ARTIFICIAL_LABEL_BYTES 30 |
204 | ||
a1a4189d JB |
205 | /* The size of addresses as they appear in the Dwarf 2 data. |
206 | Some architectures use word addresses to refer to code locations, | |
207 | but Dwarf 2 info always uses byte addresses. On such machines, | |
208 | Dwarf 2 addresses need to be larger than the architecture's | |
209 | pointers. */ | |
210 | #ifndef DWARF2_ADDR_SIZE | |
211 | #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT) | |
212 | #endif | |
213 | ||
7e23cb16 | 214 | /* The size in bytes of a DWARF field indicating an offset or length |
a1a4189d JB |
215 | relative to a debug info section, specified to be 4 bytes in the |
216 | DWARF-2 specification. The SGI/MIPS ABI defines it to be the same | |
b13fe8bf | 217 | as PTR_SIZE. */ |
71dfc51f | 218 | |
7e23cb16 JM |
219 | #ifndef DWARF_OFFSET_SIZE |
220 | #define DWARF_OFFSET_SIZE 4 | |
221 | #endif | |
222 | ||
9a666dda JM |
223 | #define DWARF_VERSION 2 |
224 | ||
7e23cb16 JM |
225 | /* Round SIZE up to the nearest BOUNDARY. */ |
226 | #define DWARF_ROUND(SIZE,BOUNDARY) \ | |
262b6384 | 227 | ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY)) |
a3f97cbb | 228 | |
a3f97cbb | 229 | /* Offsets recorded in opcodes are a multiple of this alignment factor. */ |
27c35f4b | 230 | #ifndef DWARF_CIE_DATA_ALIGNMENT |
469ac993 | 231 | #ifdef STACK_GROWS_DOWNWARD |
08cb3d38 | 232 | #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD)) |
469ac993 | 233 | #else |
08cb3d38 | 234 | #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD) |
469ac993 | 235 | #endif |
2ad9852d | 236 | #endif |
a3f97cbb | 237 | |
3f76745e JM |
238 | /* A pointer to the base of a table that contains frame description |
239 | information for each routine. */ | |
240 | static dw_fde_ref fde_table; | |
a3f97cbb | 241 | |
3f76745e JM |
242 | /* Number of elements currently allocated for fde_table. */ |
243 | static unsigned fde_table_allocated; | |
a94dbf2c | 244 | |
3f76745e JM |
245 | /* Number of elements in fde_table currently in use. */ |
246 | static unsigned fde_table_in_use; | |
a3f97cbb | 247 | |
3f76745e JM |
248 | /* Size (in elements) of increments by which we may expand the |
249 | fde_table. */ | |
250 | #define FDE_TABLE_INCREMENT 256 | |
a3f97cbb | 251 | |
a94dbf2c JM |
252 | /* A list of call frame insns for the CIE. */ |
253 | static dw_cfi_ref cie_cfi_head; | |
254 | ||
a3f97cbb JW |
255 | /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram |
256 | attribute that accelerates the lookup of the FDE associated | |
556273e0 | 257 | with the subprogram. This variable holds the table index of the FDE |
a3f97cbb JW |
258 | associated with the current function (body) definition. */ |
259 | static unsigned current_funcdef_fde; | |
260 | ||
9eb4015a JJ |
261 | struct ht *debug_str_hash; |
262 | ||
263 | struct indirect_string_node | |
264 | { | |
265 | struct ht_identifier id; | |
266 | unsigned int refcount; | |
267 | unsigned int form; | |
268 | char *label; | |
269 | }; | |
270 | ||
a3f97cbb | 271 | /* Forward declarations for functions defined in this file. */ |
71dfc51f | 272 | |
83d2b3b9 KG |
273 | static char *stripattributes PARAMS ((const char *)); |
274 | static const char *dwarf_cfi_name PARAMS ((unsigned)); | |
275 | static dw_cfi_ref new_cfi PARAMS ((void)); | |
276 | static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref)); | |
d3e3972c | 277 | static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref)); |
2ad9852d RK |
278 | static void lookup_cfa_1 PARAMS ((dw_cfi_ref, |
279 | dw_cfa_location *)); | |
7d9d8943 | 280 | static void lookup_cfa PARAMS ((dw_cfa_location *)); |
d3e3972c KG |
281 | static void reg_save PARAMS ((const char *, unsigned, |
282 | unsigned, long)); | |
83d2b3b9 | 283 | static void initial_return_save PARAMS ((rtx)); |
5e640c56 | 284 | static long stack_adjust_offset PARAMS ((rtx)); |
12f0b96b | 285 | static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int)); |
83d2b3b9 | 286 | static void output_call_frame_info PARAMS ((int)); |
83d2b3b9 | 287 | static void dwarf2out_stack_adjust PARAMS ((rtx)); |
fbfa55b0 RH |
288 | static void queue_reg_save PARAMS ((const char *, rtx, long)); |
289 | static void flush_queued_reg_saves PARAMS ((void)); | |
290 | static bool clobbers_queued_reg_save PARAMS ((rtx)); | |
d3e3972c | 291 | static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *)); |
a3f97cbb | 292 | |
7d9d8943 AM |
293 | /* Support for complex CFA locations. */ |
294 | static void output_cfa_loc PARAMS ((dw_cfi_ref)); | |
556273e0 | 295 | static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *, |
7d9d8943 AM |
296 | struct dw_loc_descr_struct *)); |
297 | static struct dw_loc_descr_struct *build_cfa_loc | |
298 | PARAMS ((dw_cfa_location *)); | |
2ad9852d RK |
299 | static void def_cfa_1 PARAMS ((const char *, |
300 | dw_cfa_location *)); | |
7d9d8943 | 301 | |
2e4b9b8c RH |
302 | /* How to start an assembler comment. */ |
303 | #ifndef ASM_COMMENT_START | |
304 | #define ASM_COMMENT_START ";#" | |
a3f97cbb JW |
305 | #endif |
306 | ||
7e23cb16 JM |
307 | /* Data and reference forms for relocatable data. */ |
308 | #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4) | |
309 | #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4) | |
310 | ||
a3f97cbb JW |
311 | /* Pseudo-op for defining a new section. */ |
312 | #ifndef SECTION_ASM_OP | |
0a3e1f45 | 313 | #define SECTION_ASM_OP "\t.section\t" |
a3f97cbb JW |
314 | #endif |
315 | ||
cf2fe500 RH |
316 | #ifndef DEBUG_FRAME_SECTION |
317 | #define DEBUG_FRAME_SECTION ".debug_frame" | |
a3f97cbb | 318 | #endif |
a3f97cbb | 319 | |
5c90448c JM |
320 | #ifndef FUNC_BEGIN_LABEL |
321 | #define FUNC_BEGIN_LABEL "LFB" | |
a3f97cbb | 322 | #endif |
2ad9852d | 323 | |
5c90448c JM |
324 | #ifndef FUNC_END_LABEL |
325 | #define FUNC_END_LABEL "LFE" | |
a3f97cbb | 326 | #endif |
2ad9852d | 327 | |
27d95cbe | 328 | #define FRAME_BEGIN_LABEL "Lframe" |
a6ab3aad JM |
329 | #define CIE_AFTER_SIZE_LABEL "LSCIE" |
330 | #define CIE_END_LABEL "LECIE" | |
2ed2af28 | 331 | #define CIE_LENGTH_LABEL "LLCIE" |
2e4b9b8c RH |
332 | #define FDE_LABEL "LSFDE" |
333 | #define FDE_AFTER_SIZE_LABEL "LASFDE" | |
a6ab3aad | 334 | #define FDE_END_LABEL "LEFDE" |
2ed2af28 | 335 | #define FDE_LENGTH_LABEL "LLFDE" |
981975b6 RH |
336 | #define LINE_NUMBER_BEGIN_LABEL "LSLT" |
337 | #define LINE_NUMBER_END_LABEL "LELT" | |
338 | #define LN_PROLOG_AS_LABEL "LASLTP" | |
339 | #define LN_PROLOG_END_LABEL "LELTP" | |
881c6935 | 340 | #define DIE_LABEL_PREFIX "DW" |
a3f97cbb | 341 | |
a3f97cbb JW |
342 | /* Definitions of defaults for various types of primitive assembly language |
343 | output operations. These may be overridden from within the tm.h file, | |
956d6950 | 344 | but typically, that is unnecessary. */ |
71dfc51f | 345 | |
2ed2af28 PDM |
346 | #ifdef SET_ASM_OP |
347 | #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL | |
3a538a66 KH |
348 | #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \ |
349 | do \ | |
350 | { \ | |
351 | fprintf (FILE, "%s", SET_ASM_OP); \ | |
352 | assemble_name (FILE, SY); \ | |
353 | fputc (',', FILE); \ | |
354 | assemble_name (FILE, HI); \ | |
355 | fputc ('-', FILE); \ | |
356 | assemble_name (FILE, LO); \ | |
357 | } \ | |
358 | while (0) | |
2ed2af28 | 359 | #endif |
2ad9852d | 360 | #endif |
2ed2af28 | 361 | |
c8cc5c4a | 362 | /* The DWARF 2 CFA column which tracks the return address. Normally this |
a94dbf2c JM |
363 | is the column for PC, or the first column after all of the hard |
364 | registers. */ | |
c8cc5c4a | 365 | #ifndef DWARF_FRAME_RETURN_COLUMN |
a94dbf2c JM |
366 | #ifdef PC_REGNUM |
367 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM) | |
368 | #else | |
3073d01c | 369 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS |
a94dbf2c | 370 | #endif |
c8cc5c4a JM |
371 | #endif |
372 | ||
373 | /* The mapping from gcc register number to DWARF 2 CFA column number. By | |
469ac993 | 374 | default, we just provide columns for all registers. */ |
c8cc5c4a | 375 | #ifndef DWARF_FRAME_REGNUM |
469ac993 | 376 | #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG) |
c8cc5c4a | 377 | #endif |
3f76745e | 378 | |
2ad9852d RK |
379 | /* The offset from the incoming value of %sp to the top of the stack frame |
380 | for the current function. */ | |
381 | #ifndef INCOMING_FRAME_SP_OFFSET | |
382 | #define INCOMING_FRAME_SP_OFFSET 0 | |
383 | #endif | |
384 | \f | |
0021b564 JM |
385 | /* Hook used by __throw. */ |
386 | ||
387 | rtx | |
388 | expand_builtin_dwarf_fp_regnum () | |
389 | { | |
390 | return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM)); | |
391 | } | |
392 | ||
71dfc51f | 393 | /* Return a pointer to a copy of the section string name S with all |
bf20f341 | 394 | attributes stripped off, and an asterisk prepended (for assemble_name). */ |
71dfc51f RK |
395 | |
396 | static inline char * | |
a3f97cbb | 397 | stripattributes (s) |
d560ee52 | 398 | const char *s; |
a3f97cbb | 399 | { |
bf20f341 | 400 | char *stripped = xmalloc (strlen (s) + 2); |
71dfc51f RK |
401 | char *p = stripped; |
402 | ||
bf20f341 JW |
403 | *p++ = '*'; |
404 | ||
405 | while (*s && *s != ',') | |
406 | *p++ = *s++; | |
71dfc51f | 407 | |
a3f97cbb JW |
408 | *p = '\0'; |
409 | return stripped; | |
410 | } | |
411 | ||
d9d5c9de | 412 | /* Generate code to initialize the register size table. */ |
2f3ca9e7 | 413 | |
d9d5c9de BS |
414 | void |
415 | expand_builtin_init_dwarf_reg_sizes (address) | |
416 | tree address; | |
2f3ca9e7 | 417 | { |
d9d5c9de BS |
418 | int i; |
419 | enum machine_mode mode = TYPE_MODE (char_type_node); | |
420 | rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0); | |
2ad9852d | 421 | rtx mem = gen_rtx_MEM (BLKmode, addr); |
2f3ca9e7 | 422 | |
2ad9852d | 423 | for (i = 0; i < DWARF_FRAME_REGISTERS; i++) |
2f3ca9e7 | 424 | { |
2ad9852d RK |
425 | HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode); |
426 | HOST_WIDE_INT size = GET_MODE_SIZE (reg_raw_mode[i]); | |
2f3ca9e7 | 427 | |
c699cee9 JM |
428 | if (offset < 0) |
429 | continue; | |
430 | ||
f4ef873c | 431 | emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size)); |
2f3ca9e7 | 432 | } |
2f3ca9e7 JM |
433 | } |
434 | ||
3f76745e | 435 | /* Convert a DWARF call frame info. operation to its string name */ |
a3f97cbb | 436 | |
d560ee52 | 437 | static const char * |
3f76745e | 438 | dwarf_cfi_name (cfi_opc) |
b3694847 | 439 | unsigned cfi_opc; |
3f76745e JM |
440 | { |
441 | switch (cfi_opc) | |
442 | { | |
443 | case DW_CFA_advance_loc: | |
444 | return "DW_CFA_advance_loc"; | |
445 | case DW_CFA_offset: | |
446 | return "DW_CFA_offset"; | |
447 | case DW_CFA_restore: | |
448 | return "DW_CFA_restore"; | |
449 | case DW_CFA_nop: | |
450 | return "DW_CFA_nop"; | |
451 | case DW_CFA_set_loc: | |
452 | return "DW_CFA_set_loc"; | |
453 | case DW_CFA_advance_loc1: | |
454 | return "DW_CFA_advance_loc1"; | |
455 | case DW_CFA_advance_loc2: | |
456 | return "DW_CFA_advance_loc2"; | |
457 | case DW_CFA_advance_loc4: | |
458 | return "DW_CFA_advance_loc4"; | |
459 | case DW_CFA_offset_extended: | |
460 | return "DW_CFA_offset_extended"; | |
461 | case DW_CFA_restore_extended: | |
462 | return "DW_CFA_restore_extended"; | |
463 | case DW_CFA_undefined: | |
464 | return "DW_CFA_undefined"; | |
465 | case DW_CFA_same_value: | |
466 | return "DW_CFA_same_value"; | |
467 | case DW_CFA_register: | |
468 | return "DW_CFA_register"; | |
469 | case DW_CFA_remember_state: | |
470 | return "DW_CFA_remember_state"; | |
471 | case DW_CFA_restore_state: | |
472 | return "DW_CFA_restore_state"; | |
473 | case DW_CFA_def_cfa: | |
474 | return "DW_CFA_def_cfa"; | |
475 | case DW_CFA_def_cfa_register: | |
476 | return "DW_CFA_def_cfa_register"; | |
477 | case DW_CFA_def_cfa_offset: | |
478 | return "DW_CFA_def_cfa_offset"; | |
6bb28965 JM |
479 | |
480 | /* DWARF 3 */ | |
7d9d8943 AM |
481 | case DW_CFA_def_cfa_expression: |
482 | return "DW_CFA_def_cfa_expression"; | |
6bb28965 JM |
483 | case DW_CFA_expression: |
484 | return "DW_CFA_expression"; | |
485 | case DW_CFA_offset_extended_sf: | |
486 | return "DW_CFA_offset_extended_sf"; | |
487 | case DW_CFA_def_cfa_sf: | |
488 | return "DW_CFA_def_cfa_sf"; | |
489 | case DW_CFA_def_cfa_offset_sf: | |
490 | return "DW_CFA_def_cfa_offset_sf"; | |
c53aa195 | 491 | |
3f76745e JM |
492 | /* SGI/MIPS specific */ |
493 | case DW_CFA_MIPS_advance_loc8: | |
494 | return "DW_CFA_MIPS_advance_loc8"; | |
c53aa195 JM |
495 | |
496 | /* GNU extensions */ | |
497 | case DW_CFA_GNU_window_save: | |
498 | return "DW_CFA_GNU_window_save"; | |
0021b564 JM |
499 | case DW_CFA_GNU_args_size: |
500 | return "DW_CFA_GNU_args_size"; | |
3f388b42 GK |
501 | case DW_CFA_GNU_negative_offset_extended: |
502 | return "DW_CFA_GNU_negative_offset_extended"; | |
c53aa195 | 503 | |
3f76745e JM |
504 | default: |
505 | return "DW_CFA_<unknown>"; | |
506 | } | |
507 | } | |
a3f97cbb | 508 | |
3f76745e | 509 | /* Return a pointer to a newly allocated Call Frame Instruction. */ |
71dfc51f | 510 | |
3f76745e JM |
511 | static inline dw_cfi_ref |
512 | new_cfi () | |
513 | { | |
b3694847 | 514 | dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node)); |
71dfc51f | 515 | |
3f76745e JM |
516 | cfi->dw_cfi_next = NULL; |
517 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0; | |
518 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0; | |
a3f97cbb | 519 | |
3f76745e JM |
520 | return cfi; |
521 | } | |
a3f97cbb | 522 | |
3f76745e | 523 | /* Add a Call Frame Instruction to list of instructions. */ |
a3f97cbb | 524 | |
3f76745e JM |
525 | static inline void |
526 | add_cfi (list_head, cfi) | |
b3694847 SS |
527 | dw_cfi_ref *list_head; |
528 | dw_cfi_ref cfi; | |
3f76745e | 529 | { |
b3694847 | 530 | dw_cfi_ref *p; |
a3f97cbb | 531 | |
3f76745e JM |
532 | /* Find the end of the chain. */ |
533 | for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next) | |
534 | ; | |
535 | ||
536 | *p = cfi; | |
a3f97cbb JW |
537 | } |
538 | ||
3f76745e | 539 | /* Generate a new label for the CFI info to refer to. */ |
71dfc51f | 540 | |
c53aa195 | 541 | char * |
3f76745e | 542 | dwarf2out_cfi_label () |
a3f97cbb | 543 | { |
3f76745e JM |
544 | static char label[20]; |
545 | static unsigned long label_num = 0; | |
556273e0 | 546 | |
3f76745e JM |
547 | ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++); |
548 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
3f76745e | 549 | return label; |
a3f97cbb JW |
550 | } |
551 | ||
3f76745e JM |
552 | /* Add CFI to the current fde at the PC value indicated by LABEL if specified, |
553 | or to the CIE if LABEL is NULL. */ | |
71dfc51f | 554 | |
3f76745e JM |
555 | static void |
556 | add_fde_cfi (label, cfi) | |
b3694847 SS |
557 | const char *label; |
558 | dw_cfi_ref cfi; | |
a3f97cbb | 559 | { |
3f76745e JM |
560 | if (label) |
561 | { | |
b3694847 | 562 | dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
a3f97cbb | 563 | |
3f76745e JM |
564 | if (*label == 0) |
565 | label = dwarf2out_cfi_label (); | |
71dfc51f | 566 | |
3f76745e JM |
567 | if (fde->dw_fde_current_label == NULL |
568 | || strcmp (label, fde->dw_fde_current_label) != 0) | |
569 | { | |
b3694847 | 570 | dw_cfi_ref xcfi; |
a3f97cbb | 571 | |
3f76745e | 572 | fde->dw_fde_current_label = label = xstrdup (label); |
71dfc51f | 573 | |
3f76745e JM |
574 | /* Set the location counter to the new label. */ |
575 | xcfi = new_cfi (); | |
576 | xcfi->dw_cfi_opc = DW_CFA_advance_loc4; | |
577 | xcfi->dw_cfi_oprnd1.dw_cfi_addr = label; | |
578 | add_cfi (&fde->dw_fde_cfi, xcfi); | |
579 | } | |
71dfc51f | 580 | |
3f76745e JM |
581 | add_cfi (&fde->dw_fde_cfi, cfi); |
582 | } | |
583 | ||
584 | else | |
585 | add_cfi (&cie_cfi_head, cfi); | |
a3f97cbb JW |
586 | } |
587 | ||
3f76745e | 588 | /* Subroutine of lookup_cfa. */ |
71dfc51f | 589 | |
3f76745e | 590 | static inline void |
7d9d8943 | 591 | lookup_cfa_1 (cfi, loc) |
b3694847 SS |
592 | dw_cfi_ref cfi; |
593 | dw_cfa_location *loc; | |
a3f97cbb | 594 | { |
3f76745e JM |
595 | switch (cfi->dw_cfi_opc) |
596 | { | |
597 | case DW_CFA_def_cfa_offset: | |
7d9d8943 | 598 | loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset; |
3f76745e JM |
599 | break; |
600 | case DW_CFA_def_cfa_register: | |
7d9d8943 | 601 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
3f76745e JM |
602 | break; |
603 | case DW_CFA_def_cfa: | |
7d9d8943 AM |
604 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
605 | loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset; | |
606 | break; | |
607 | case DW_CFA_def_cfa_expression: | |
608 | get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc); | |
3f76745e | 609 | break; |
e9a25f70 JL |
610 | default: |
611 | break; | |
3f76745e | 612 | } |
a3f97cbb JW |
613 | } |
614 | ||
3f76745e | 615 | /* Find the previous value for the CFA. */ |
71dfc51f | 616 | |
3f76745e | 617 | static void |
7d9d8943 | 618 | lookup_cfa (loc) |
b3694847 | 619 | dw_cfa_location *loc; |
a3f97cbb | 620 | { |
b3694847 | 621 | dw_cfi_ref cfi; |
3f76745e | 622 | |
7d9d8943 AM |
623 | loc->reg = (unsigned long) -1; |
624 | loc->offset = 0; | |
625 | loc->indirect = 0; | |
626 | loc->base_offset = 0; | |
3f76745e JM |
627 | |
628 | for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next) | |
7d9d8943 | 629 | lookup_cfa_1 (cfi, loc); |
3f76745e JM |
630 | |
631 | if (fde_table_in_use) | |
a3f97cbb | 632 | { |
b3694847 | 633 | dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
3f76745e | 634 | for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next) |
7d9d8943 | 635 | lookup_cfa_1 (cfi, loc); |
a3f97cbb JW |
636 | } |
637 | } | |
638 | ||
3f76745e | 639 | /* The current rule for calculating the DWARF2 canonical frame address. */ |
fbfa55b0 | 640 | static dw_cfa_location cfa; |
71dfc51f | 641 | |
3f76745e JM |
642 | /* The register used for saving registers to the stack, and its offset |
643 | from the CFA. */ | |
fbfa55b0 | 644 | static dw_cfa_location cfa_store; |
3f76745e | 645 | |
0021b564 JM |
646 | /* The running total of the size of arguments pushed onto the stack. */ |
647 | static long args_size; | |
648 | ||
b57d9225 JM |
649 | /* The last args_size we actually output. */ |
650 | static long old_args_size; | |
651 | ||
3f76745e JM |
652 | /* Entry point to update the canonical frame address (CFA). |
653 | LABEL is passed to add_fde_cfi. The value of CFA is now to be | |
654 | calculated from REG+OFFSET. */ | |
655 | ||
656 | void | |
657 | dwarf2out_def_cfa (label, reg, offset) | |
b3694847 | 658 | const char *label; |
7d9d8943 AM |
659 | unsigned reg; |
660 | long offset; | |
661 | { | |
662 | dw_cfa_location loc; | |
663 | loc.indirect = 0; | |
664 | loc.base_offset = 0; | |
665 | loc.reg = reg; | |
666 | loc.offset = offset; | |
667 | def_cfa_1 (label, &loc); | |
668 | } | |
669 | ||
770ca8c6 | 670 | /* This routine does the actual work. The CFA is now calculated from |
7d9d8943 | 671 | the dw_cfa_location structure. */ |
2ad9852d | 672 | |
7d9d8943 AM |
673 | static void |
674 | def_cfa_1 (label, loc_p) | |
b3694847 | 675 | const char *label; |
7d9d8943 | 676 | dw_cfa_location *loc_p; |
a3f97cbb | 677 | { |
b3694847 | 678 | dw_cfi_ref cfi; |
7d9d8943 | 679 | dw_cfa_location old_cfa, loc; |
3f76745e | 680 | |
7d9d8943 AM |
681 | cfa = *loc_p; |
682 | loc = *loc_p; | |
5bef9b1f | 683 | |
7d9d8943 AM |
684 | if (cfa_store.reg == loc.reg && loc.indirect == 0) |
685 | cfa_store.offset = loc.offset; | |
3f76745e | 686 | |
7d9d8943 AM |
687 | loc.reg = DWARF_FRAME_REGNUM (loc.reg); |
688 | lookup_cfa (&old_cfa); | |
689 | ||
2ad9852d RK |
690 | /* If nothing changed, no need to issue any call frame instructions. */ |
691 | if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset | |
692 | && loc.indirect == old_cfa.indirect | |
693 | && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset)) | |
694 | return; | |
3f76745e JM |
695 | |
696 | cfi = new_cfi (); | |
697 | ||
e09bbb25 | 698 | if (loc.reg == old_cfa.reg && !loc.indirect) |
a3f97cbb | 699 | { |
770ca8c6 JO |
700 | /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, |
701 | indicating the CFA register did not change but the offset | |
702 | did. */ | |
3f76745e | 703 | cfi->dw_cfi_opc = DW_CFA_def_cfa_offset; |
7d9d8943 | 704 | cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset; |
3f76745e | 705 | } |
a3f97cbb | 706 | |
3f76745e | 707 | #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */ |
7d9d8943 | 708 | else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1 |
e09bbb25 | 709 | && !loc.indirect) |
3f76745e | 710 | { |
770ca8c6 JO |
711 | /* Construct a "DW_CFA_def_cfa_register <register>" instruction, |
712 | indicating the CFA register has changed to <register> but the | |
713 | offset has not changed. */ | |
3f76745e | 714 | cfi->dw_cfi_opc = DW_CFA_def_cfa_register; |
7d9d8943 | 715 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
3f76745e JM |
716 | } |
717 | #endif | |
a3f97cbb | 718 | |
7d9d8943 | 719 | else if (loc.indirect == 0) |
3f76745e | 720 | { |
770ca8c6 JO |
721 | /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction, |
722 | indicating the CFA register has changed to <register> with | |
723 | the specified offset. */ | |
3f76745e | 724 | cfi->dw_cfi_opc = DW_CFA_def_cfa; |
7d9d8943 AM |
725 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
726 | cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset; | |
727 | } | |
728 | else | |
729 | { | |
770ca8c6 JO |
730 | /* Construct a DW_CFA_def_cfa_expression instruction to |
731 | calculate the CFA using a full location expression since no | |
732 | register-offset pair is available. */ | |
556273e0 | 733 | struct dw_loc_descr_struct *loc_list; |
2ad9852d | 734 | |
7d9d8943 AM |
735 | cfi->dw_cfi_opc = DW_CFA_def_cfa_expression; |
736 | loc_list = build_cfa_loc (&loc); | |
737 | cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list; | |
a3f97cbb | 738 | } |
3f76745e JM |
739 | |
740 | add_fde_cfi (label, cfi); | |
a3f97cbb JW |
741 | } |
742 | ||
3f76745e JM |
743 | /* Add the CFI for saving a register. REG is the CFA column number. |
744 | LABEL is passed to add_fde_cfi. | |
745 | If SREG is -1, the register is saved at OFFSET from the CFA; | |
746 | otherwise it is saved in SREG. */ | |
71dfc51f | 747 | |
3f76745e JM |
748 | static void |
749 | reg_save (label, reg, sreg, offset) | |
b3694847 SS |
750 | const char *label; |
751 | unsigned reg; | |
752 | unsigned sreg; | |
753 | long offset; | |
a3f97cbb | 754 | { |
b3694847 | 755 | dw_cfi_ref cfi = new_cfi (); |
3f76745e JM |
756 | |
757 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
758 | ||
85066503 MH |
759 | /* The following comparison is correct. -1 is used to indicate that |
760 | the value isn't a register number. */ | |
761 | if (sreg == (unsigned int) -1) | |
a3f97cbb | 762 | { |
3f76745e JM |
763 | if (reg & ~0x3f) |
764 | /* The register number won't fit in 6 bits, so we have to use | |
765 | the long form. */ | |
766 | cfi->dw_cfi_opc = DW_CFA_offset_extended; | |
767 | else | |
768 | cfi->dw_cfi_opc = DW_CFA_offset; | |
769 | ||
27c35f4b HPN |
770 | #ifdef ENABLE_CHECKING |
771 | { | |
772 | /* If we get an offset that is not a multiple of | |
773 | DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the | |
774 | definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine | |
775 | description. */ | |
776 | long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT; | |
777 | ||
778 | if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset) | |
779 | abort (); | |
780 | } | |
781 | #endif | |
3f76745e | 782 | offset /= DWARF_CIE_DATA_ALIGNMENT; |
3a88cbd1 | 783 | if (offset < 0) |
6bb28965 | 784 | cfi->dw_cfi_opc = DW_CFA_offset_extended_sf; |
2ad9852d | 785 | |
3f76745e JM |
786 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; |
787 | } | |
2c849145 JM |
788 | else if (sreg == reg) |
789 | /* We could emit a DW_CFA_same_value in this case, but don't bother. */ | |
790 | return; | |
3f76745e JM |
791 | else |
792 | { | |
793 | cfi->dw_cfi_opc = DW_CFA_register; | |
794 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg; | |
795 | } | |
796 | ||
797 | add_fde_cfi (label, cfi); | |
798 | } | |
799 | ||
c53aa195 JM |
800 | /* Add the CFI for saving a register window. LABEL is passed to reg_save. |
801 | This CFI tells the unwinder that it needs to restore the window registers | |
802 | from the previous frame's window save area. | |
556273e0 | 803 | |
c53aa195 JM |
804 | ??? Perhaps we should note in the CIE where windows are saved (instead of |
805 | assuming 0(cfa)) and what registers are in the window. */ | |
806 | ||
807 | void | |
808 | dwarf2out_window_save (label) | |
b3694847 | 809 | const char *label; |
c53aa195 | 810 | { |
b3694847 | 811 | dw_cfi_ref cfi = new_cfi (); |
2ad9852d | 812 | |
c53aa195 JM |
813 | cfi->dw_cfi_opc = DW_CFA_GNU_window_save; |
814 | add_fde_cfi (label, cfi); | |
815 | } | |
816 | ||
0021b564 JM |
817 | /* Add a CFI to update the running total of the size of arguments |
818 | pushed onto the stack. */ | |
819 | ||
820 | void | |
821 | dwarf2out_args_size (label, size) | |
d3e3972c | 822 | const char *label; |
0021b564 JM |
823 | long size; |
824 | { | |
b3694847 | 825 | dw_cfi_ref cfi; |
b57d9225 JM |
826 | |
827 | if (size == old_args_size) | |
828 | return; | |
2ad9852d | 829 | |
b57d9225 JM |
830 | old_args_size = size; |
831 | ||
832 | cfi = new_cfi (); | |
0021b564 JM |
833 | cfi->dw_cfi_opc = DW_CFA_GNU_args_size; |
834 | cfi->dw_cfi_oprnd1.dw_cfi_offset = size; | |
835 | add_fde_cfi (label, cfi); | |
836 | } | |
837 | ||
c53aa195 JM |
838 | /* Entry point for saving a register to the stack. REG is the GCC register |
839 | number. LABEL and OFFSET are passed to reg_save. */ | |
3f76745e JM |
840 | |
841 | void | |
842 | dwarf2out_reg_save (label, reg, offset) | |
b3694847 SS |
843 | const char *label; |
844 | unsigned reg; | |
845 | long offset; | |
3f76745e JM |
846 | { |
847 | reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset); | |
848 | } | |
849 | ||
c53aa195 JM |
850 | /* Entry point for saving the return address in the stack. |
851 | LABEL and OFFSET are passed to reg_save. */ | |
852 | ||
853 | void | |
854 | dwarf2out_return_save (label, offset) | |
b3694847 SS |
855 | const char *label; |
856 | long offset; | |
c53aa195 JM |
857 | { |
858 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset); | |
859 | } | |
860 | ||
861 | /* Entry point for saving the return address in a register. | |
862 | LABEL and SREG are passed to reg_save. */ | |
863 | ||
864 | void | |
865 | dwarf2out_return_reg (label, sreg) | |
b3694847 SS |
866 | const char *label; |
867 | unsigned sreg; | |
c53aa195 JM |
868 | { |
869 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0); | |
870 | } | |
871 | ||
3f76745e JM |
872 | /* Record the initial position of the return address. RTL is |
873 | INCOMING_RETURN_ADDR_RTX. */ | |
874 | ||
875 | static void | |
876 | initial_return_save (rtl) | |
b3694847 | 877 | rtx rtl; |
3f76745e | 878 | { |
973838fd | 879 | unsigned int reg = (unsigned int) -1; |
2ad9852d | 880 | HOST_WIDE_INT offset = 0; |
3f76745e JM |
881 | |
882 | switch (GET_CODE (rtl)) | |
883 | { | |
884 | case REG: | |
885 | /* RA is in a register. */ | |
2c849145 | 886 | reg = DWARF_FRAME_REGNUM (REGNO (rtl)); |
3f76745e | 887 | break; |
2ad9852d | 888 | |
3f76745e JM |
889 | case MEM: |
890 | /* RA is on the stack. */ | |
891 | rtl = XEXP (rtl, 0); | |
892 | switch (GET_CODE (rtl)) | |
893 | { | |
894 | case REG: | |
3a88cbd1 JL |
895 | if (REGNO (rtl) != STACK_POINTER_REGNUM) |
896 | abort (); | |
3f76745e JM |
897 | offset = 0; |
898 | break; | |
2ad9852d | 899 | |
3f76745e | 900 | case PLUS: |
3a88cbd1 JL |
901 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
902 | abort (); | |
3f76745e JM |
903 | offset = INTVAL (XEXP (rtl, 1)); |
904 | break; | |
2ad9852d | 905 | |
3f76745e | 906 | case MINUS: |
3a88cbd1 JL |
907 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
908 | abort (); | |
3f76745e JM |
909 | offset = -INTVAL (XEXP (rtl, 1)); |
910 | break; | |
2ad9852d | 911 | |
3f76745e JM |
912 | default: |
913 | abort (); | |
914 | } | |
2ad9852d | 915 | |
3f76745e | 916 | break; |
2ad9852d | 917 | |
c53aa195 JM |
918 | case PLUS: |
919 | /* The return address is at some offset from any value we can | |
920 | actually load. For instance, on the SPARC it is in %i7+8. Just | |
921 | ignore the offset for now; it doesn't matter for unwinding frames. */ | |
3a88cbd1 JL |
922 | if (GET_CODE (XEXP (rtl, 1)) != CONST_INT) |
923 | abort (); | |
c53aa195 JM |
924 | initial_return_save (XEXP (rtl, 0)); |
925 | return; | |
2ad9852d | 926 | |
a3f97cbb | 927 | default: |
3f76745e | 928 | abort (); |
a3f97cbb | 929 | } |
3f76745e | 930 | |
7d9d8943 | 931 | reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset); |
a3f97cbb JW |
932 | } |
933 | ||
1ba5ae8f | 934 | /* Given a SET, calculate the amount of stack adjustment it |
30f7a378 | 935 | contains. */ |
1ba5ae8f | 936 | |
5e640c56 AH |
937 | static long |
938 | stack_adjust_offset (pattern) | |
173bf5be | 939 | rtx pattern; |
1ba5ae8f AH |
940 | { |
941 | rtx src = SET_SRC (pattern); | |
942 | rtx dest = SET_DEST (pattern); | |
2ad9852d | 943 | HOST_WIDE_INT offset = 0; |
1ba5ae8f AH |
944 | enum rtx_code code; |
945 | ||
946 | if (dest == stack_pointer_rtx) | |
947 | { | |
948 | /* (set (reg sp) (plus (reg sp) (const_int))) */ | |
949 | code = GET_CODE (src); | |
950 | if (! (code == PLUS || code == MINUS) | |
951 | || XEXP (src, 0) != stack_pointer_rtx | |
952 | || GET_CODE (XEXP (src, 1)) != CONST_INT) | |
953 | return 0; | |
954 | ||
955 | offset = INTVAL (XEXP (src, 1)); | |
f472fa29 AM |
956 | if (code == PLUS) |
957 | offset = -offset; | |
1ba5ae8f AH |
958 | } |
959 | else if (GET_CODE (dest) == MEM) | |
960 | { | |
961 | /* (set (mem (pre_dec (reg sp))) (foo)) */ | |
962 | src = XEXP (dest, 0); | |
963 | code = GET_CODE (src); | |
964 | ||
c26fbbca KH |
965 | switch (code) |
966 | { | |
f472fa29 AM |
967 | case PRE_MODIFY: |
968 | case POST_MODIFY: | |
969 | if (XEXP (src, 0) == stack_pointer_rtx) | |
970 | { | |
971 | rtx val = XEXP (XEXP (src, 1), 1); | |
972 | /* We handle only adjustments by constant amount. */ | |
973 | if (GET_CODE (XEXP (src, 1)) != PLUS || | |
974 | GET_CODE (val) != CONST_INT) | |
c26fbbca | 975 | abort (); |
f472fa29 AM |
976 | offset = -INTVAL (val); |
977 | break; | |
978 | } | |
979 | return 0; | |
980 | ||
981 | case PRE_DEC: | |
982 | case POST_DEC: | |
983 | if (XEXP (src, 0) == stack_pointer_rtx) | |
984 | { | |
985 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
986 | break; | |
987 | } | |
988 | return 0; | |
989 | ||
990 | case PRE_INC: | |
991 | case POST_INC: | |
992 | if (XEXP (src, 0) == stack_pointer_rtx) | |
993 | { | |
994 | offset = -GET_MODE_SIZE (GET_MODE (dest)); | |
995 | break; | |
996 | } | |
997 | return 0; | |
2ad9852d | 998 | |
f472fa29 AM |
999 | default: |
1000 | return 0; | |
e2134eea | 1001 | } |
1ba5ae8f AH |
1002 | } |
1003 | else | |
1004 | return 0; | |
1005 | ||
1ba5ae8f AH |
1006 | return offset; |
1007 | } | |
1008 | ||
0021b564 JM |
1009 | /* Check INSN to see if it looks like a push or a stack adjustment, and |
1010 | make a note of it if it does. EH uses this information to find out how | |
1011 | much extra space it needs to pop off the stack. */ | |
1012 | ||
1013 | static void | |
1014 | dwarf2out_stack_adjust (insn) | |
1015 | rtx insn; | |
1016 | { | |
2ad9852d | 1017 | HOST_WIDE_INT offset; |
d3e3972c | 1018 | const char *label; |
2ad9852d | 1019 | int i; |
0021b564 | 1020 | |
2ad9852d | 1021 | if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN) |
b57d9225 JM |
1022 | { |
1023 | /* Extract the size of the args from the CALL rtx itself. */ | |
b57d9225 JM |
1024 | insn = PATTERN (insn); |
1025 | if (GET_CODE (insn) == PARALLEL) | |
1026 | insn = XVECEXP (insn, 0, 0); | |
1027 | if (GET_CODE (insn) == SET) | |
1028 | insn = SET_SRC (insn); | |
3db35af4 MM |
1029 | if (GET_CODE (insn) != CALL) |
1030 | abort (); | |
2ad9852d | 1031 | |
b57d9225 JM |
1032 | dwarf2out_args_size ("", INTVAL (XEXP (insn, 1))); |
1033 | return; | |
1034 | } | |
1035 | ||
1036 | /* If only calls can throw, and we have a frame pointer, | |
1037 | save up adjustments until we see the CALL_INSN. */ | |
2ad9852d | 1038 | else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM) |
b57d9225 JM |
1039 | return; |
1040 | ||
6020d360 | 1041 | if (GET_CODE (insn) == BARRIER) |
0021b564 | 1042 | { |
6020d360 JM |
1043 | /* When we see a BARRIER, we know to reset args_size to 0. Usually |
1044 | the compiler will have already emitted a stack adjustment, but | |
1045 | doesn't bother for calls to noreturn functions. */ | |
1046 | #ifdef STACK_GROWS_DOWNWARD | |
1047 | offset = -args_size; | |
1048 | #else | |
1049 | offset = args_size; | |
1050 | #endif | |
0021b564 | 1051 | } |
6020d360 | 1052 | else if (GET_CODE (PATTERN (insn)) == SET) |
2ad9852d | 1053 | offset = stack_adjust_offset (PATTERN (insn)); |
1ba5ae8f AH |
1054 | else if (GET_CODE (PATTERN (insn)) == PARALLEL |
1055 | || GET_CODE (PATTERN (insn)) == SEQUENCE) | |
1056 | { | |
1057 | /* There may be stack adjustments inside compound insns. Search | |
2ad9852d RK |
1058 | for them. */ |
1059 | for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--) | |
1060 | if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET) | |
1061 | offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i)); | |
0021b564 JM |
1062 | } |
1063 | else | |
1064 | return; | |
0b34cf1e | 1065 | |
6020d360 JM |
1066 | if (offset == 0) |
1067 | return; | |
1068 | ||
7d9d8943 AM |
1069 | if (cfa.reg == STACK_POINTER_REGNUM) |
1070 | cfa.offset += offset; | |
0021b564 JM |
1071 | |
1072 | #ifndef STACK_GROWS_DOWNWARD | |
1073 | offset = -offset; | |
1074 | #endif | |
2ad9852d | 1075 | |
0021b564 JM |
1076 | args_size += offset; |
1077 | if (args_size < 0) | |
1078 | args_size = 0; | |
1079 | ||
1080 | label = dwarf2out_cfi_label (); | |
7d9d8943 | 1081 | def_cfa_1 (label, &cfa); |
0021b564 JM |
1082 | dwarf2out_args_size (label, args_size); |
1083 | } | |
1084 | ||
fbfa55b0 RH |
1085 | /* We delay emitting a register save until either (a) we reach the end |
1086 | of the prologue or (b) the register is clobbered. This clusters | |
1087 | register saves so that there are fewer pc advances. */ | |
1088 | ||
1089 | struct queued_reg_save | |
1090 | { | |
1091 | struct queued_reg_save *next; | |
1092 | rtx reg; | |
1093 | long cfa_offset; | |
1094 | }; | |
1095 | ||
1096 | static struct queued_reg_save *queued_reg_saves; | |
1097 | static const char *last_reg_save_label; | |
1098 | ||
1099 | static void | |
1100 | queue_reg_save (label, reg, offset) | |
1101 | const char *label; | |
1102 | rtx reg; | |
1103 | long offset; | |
1104 | { | |
1105 | struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q)); | |
1106 | ||
1107 | q->next = queued_reg_saves; | |
1108 | q->reg = reg; | |
1109 | q->cfa_offset = offset; | |
1110 | queued_reg_saves = q; | |
1111 | ||
1112 | last_reg_save_label = label; | |
1113 | } | |
1114 | ||
1115 | static void | |
1116 | flush_queued_reg_saves () | |
1117 | { | |
1118 | struct queued_reg_save *q, *next; | |
1119 | ||
c26fbbca | 1120 | for (q = queued_reg_saves; q; q = next) |
fbfa55b0 RH |
1121 | { |
1122 | dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset); | |
1123 | next = q->next; | |
1124 | free (q); | |
1125 | } | |
1126 | ||
1127 | queued_reg_saves = NULL; | |
1128 | last_reg_save_label = NULL; | |
1129 | } | |
1130 | ||
1131 | static bool | |
1132 | clobbers_queued_reg_save (insn) | |
1133 | rtx insn; | |
1134 | { | |
1135 | struct queued_reg_save *q; | |
1136 | ||
c26fbbca | 1137 | for (q = queued_reg_saves; q; q = q->next) |
fbfa55b0 RH |
1138 | if (modified_in_p (q->reg, insn)) |
1139 | return true; | |
1140 | ||
1141 | return false; | |
1142 | } | |
c26fbbca | 1143 | |
fbfa55b0 | 1144 | |
770ca8c6 JO |
1145 | /* A temporary register holding an integral value used in adjusting SP |
1146 | or setting up the store_reg. The "offset" field holds the integer | |
1147 | value, not an offset. */ | |
fbfa55b0 | 1148 | static dw_cfa_location cfa_temp; |
770ca8c6 JO |
1149 | |
1150 | /* Record call frame debugging information for an expression EXPR, | |
1151 | which either sets SP or FP (adjusting how we calculate the frame | |
1152 | address) or saves a register to the stack. LABEL indicates the | |
1153 | address of EXPR. | |
1154 | ||
1155 | This function encodes a state machine mapping rtxes to actions on | |
1156 | cfa, cfa_store, and cfa_temp.reg. We describe these rules so | |
1157 | users need not read the source code. | |
1158 | ||
a401107d JO |
1159 | The High-Level Picture |
1160 | ||
1161 | Changes in the register we use to calculate the CFA: Currently we | |
1162 | assume that if you copy the CFA register into another register, we | |
1163 | should take the other one as the new CFA register; this seems to | |
1164 | work pretty well. If it's wrong for some target, it's simple | |
1165 | enough not to set RTX_FRAME_RELATED_P on the insn in question. | |
1166 | ||
1167 | Changes in the register we use for saving registers to the stack: | |
1168 | This is usually SP, but not always. Again, we deduce that if you | |
1169 | copy SP into another register (and SP is not the CFA register), | |
1170 | then the new register is the one we will be using for register | |
1171 | saves. This also seems to work. | |
1172 | ||
1173 | Register saves: There's not much guesswork about this one; if | |
1174 | RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a | |
1175 | register save, and the register used to calculate the destination | |
1176 | had better be the one we think we're using for this purpose. | |
1177 | ||
1178 | Except: If the register being saved is the CFA register, and the | |
1179 | offset is non-zero, we are saving the CFA, so we assume we have to | |
1180 | use DW_CFA_def_cfa_expression. If the offset is 0, we assume that | |
1181 | the intent is to save the value of SP from the previous frame. | |
1182 | ||
770ca8c6 JO |
1183 | Invariants / Summaries of Rules |
1184 | ||
a401107d JO |
1185 | cfa current rule for calculating the CFA. It usually |
1186 | consists of a register and an offset. | |
770ca8c6 JO |
1187 | cfa_store register used by prologue code to save things to the stack |
1188 | cfa_store.offset is the offset from the value of | |
1189 | cfa_store.reg to the actual CFA | |
1190 | cfa_temp register holding an integral value. cfa_temp.offset | |
1191 | stores the value, which will be used to adjust the | |
19ec6a36 AM |
1192 | stack pointer. cfa_temp is also used like cfa_store, |
1193 | to track stores to the stack via fp or a temp reg. | |
c26fbbca | 1194 | |
770ca8c6 JO |
1195 | Rules 1- 4: Setting a register's value to cfa.reg or an expression |
1196 | with cfa.reg as the first operand changes the cfa.reg and its | |
19ec6a36 AM |
1197 | cfa.offset. Rule 1 and 4 also set cfa_temp.reg and |
1198 | cfa_temp.offset. | |
770ca8c6 JO |
1199 | |
1200 | Rules 6- 9: Set a non-cfa.reg register value to a constant or an | |
1201 | expression yielding a constant. This sets cfa_temp.reg | |
1202 | and cfa_temp.offset. | |
1203 | ||
1204 | Rule 5: Create a new register cfa_store used to save items to the | |
1205 | stack. | |
1206 | ||
19ec6a36 | 1207 | Rules 10-14: Save a register to the stack. Define offset as the |
a401107d | 1208 | difference of the original location and cfa_store's |
19ec6a36 | 1209 | location (or cfa_temp's location if cfa_temp is used). |
770ca8c6 JO |
1210 | |
1211 | The Rules | |
1212 | ||
1213 | "{a,b}" indicates a choice of a xor b. | |
1214 | "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg. | |
1215 | ||
1216 | Rule 1: | |
1217 | (set <reg1> <reg2>:cfa.reg) | |
19ec6a36 | 1218 | effects: cfa.reg = <reg1> |
770ca8c6 | 1219 | cfa.offset unchanged |
19ec6a36 AM |
1220 | cfa_temp.reg = <reg1> |
1221 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1222 | |
1223 | Rule 2: | |
2ad9852d RK |
1224 | (set sp ({minus,plus,losum} {sp,fp}:cfa.reg |
1225 | {<const_int>,<reg>:cfa_temp.reg})) | |
770ca8c6 JO |
1226 | effects: cfa.reg = sp if fp used |
1227 | cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp | |
1228 | cfa_store.offset += {+/- <const_int>, cfa_temp.offset} | |
1229 | if cfa_store.reg==sp | |
1230 | ||
1231 | Rule 3: | |
19ec6a36 | 1232 | (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>)) |
770ca8c6 JO |
1233 | effects: cfa.reg = fp |
1234 | cfa_offset += +/- <const_int> | |
1235 | ||
1236 | Rule 4: | |
19ec6a36 | 1237 | (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>)) |
770ca8c6 JO |
1238 | constraints: <reg1> != fp |
1239 | <reg1> != sp | |
1240 | effects: cfa.reg = <reg1> | |
19ec6a36 AM |
1241 | cfa_temp.reg = <reg1> |
1242 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1243 | |
1244 | Rule 5: | |
1245 | (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg)) | |
1246 | constraints: <reg1> != fp | |
1247 | <reg1> != sp | |
1248 | effects: cfa_store.reg = <reg1> | |
1249 | cfa_store.offset = cfa.offset - cfa_temp.offset | |
1250 | ||
1251 | Rule 6: | |
1252 | (set <reg> <const_int>) | |
1253 | effects: cfa_temp.reg = <reg> | |
1254 | cfa_temp.offset = <const_int> | |
1255 | ||
1256 | Rule 7: | |
1257 | (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>)) | |
1258 | effects: cfa_temp.reg = <reg1> | |
1259 | cfa_temp.offset |= <const_int> | |
1260 | ||
1261 | Rule 8: | |
1262 | (set <reg> (high <exp>)) | |
1263 | effects: none | |
1264 | ||
1265 | Rule 9: | |
1266 | (set <reg> (lo_sum <exp> <const_int>)) | |
1267 | effects: cfa_temp.reg = <reg> | |
1268 | cfa_temp.offset = <const_int> | |
1269 | ||
1270 | Rule 10: | |
1271 | (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>) | |
1272 | effects: cfa_store.offset -= <const_int> | |
1273 | cfa.offset = cfa_store.offset if cfa.reg == sp | |
770ca8c6 | 1274 | cfa.reg = sp |
19ec6a36 | 1275 | cfa.base_offset = -cfa_store.offset |
770ca8c6 JO |
1276 | |
1277 | Rule 11: | |
1278 | (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>) | |
1279 | effects: cfa_store.offset += -/+ mode_size(mem) | |
1280 | cfa.offset = cfa_store.offset if cfa.reg == sp | |
770ca8c6 | 1281 | cfa.reg = sp |
19ec6a36 | 1282 | cfa.base_offset = -cfa_store.offset |
770ca8c6 JO |
1283 | |
1284 | Rule 12: | |
2ad9852d RK |
1285 | (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) |
1286 | ||
1287 | <reg2>) | |
19ec6a36 AM |
1288 | effects: cfa.reg = <reg1> |
1289 | cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset | |
770ca8c6 JO |
1290 | |
1291 | Rule 13: | |
19ec6a36 AM |
1292 | (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>) |
1293 | effects: cfa.reg = <reg1> | |
1294 | cfa.base_offset = -{cfa_store,cfa_temp}.offset | |
1295 | ||
1296 | Rule 14: | |
1297 | (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>) | |
1298 | effects: cfa.reg = <reg1> | |
1299 | cfa.base_offset = -cfa_temp.offset | |
1300 | cfa_temp.offset -= mode_size(mem) */ | |
b664de3a AM |
1301 | |
1302 | static void | |
1303 | dwarf2out_frame_debug_expr (expr, label) | |
1304 | rtx expr; | |
d3e3972c | 1305 | const char *label; |
b664de3a AM |
1306 | { |
1307 | rtx src, dest; | |
2ad9852d | 1308 | HOST_WIDE_INT offset; |
556273e0 KH |
1309 | |
1310 | /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of | |
1311 | the PARALLEL independently. The first element is always processed if | |
770ca8c6 | 1312 | it is a SET. This is for backward compatibility. Other elements |
556273e0 KH |
1313 | are processed only if they are SETs and the RTX_FRAME_RELATED_P |
1314 | flag is set in them. */ | |
2ad9852d | 1315 | if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE) |
556273e0 | 1316 | { |
b664de3a AM |
1317 | int par_index; |
1318 | int limit = XVECLEN (expr, 0); | |
1319 | ||
1320 | for (par_index = 0; par_index < limit; par_index++) | |
2ad9852d RK |
1321 | if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET |
1322 | && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index)) | |
1323 | || par_index == 0)) | |
1324 | dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label); | |
556273e0 | 1325 | |
b664de3a AM |
1326 | return; |
1327 | } | |
556273e0 | 1328 | |
b664de3a AM |
1329 | if (GET_CODE (expr) != SET) |
1330 | abort (); | |
1331 | ||
1332 | src = SET_SRC (expr); | |
1333 | dest = SET_DEST (expr); | |
1334 | ||
1335 | switch (GET_CODE (dest)) | |
1336 | { | |
1337 | case REG: | |
770ca8c6 | 1338 | /* Rule 1 */ |
b664de3a AM |
1339 | /* Update the CFA rule wrt SP or FP. Make sure src is |
1340 | relative to the current CFA register. */ | |
1341 | switch (GET_CODE (src)) | |
556273e0 KH |
1342 | { |
1343 | /* Setting FP from SP. */ | |
1344 | case REG: | |
1345 | if (cfa.reg == (unsigned) REGNO (src)) | |
1346 | /* OK. */ | |
1347 | ; | |
626d1efd | 1348 | else |
556273e0 | 1349 | abort (); |
2c849145 JM |
1350 | |
1351 | /* We used to require that dest be either SP or FP, but the | |
1352 | ARM copies SP to a temporary register, and from there to | |
1353 | FP. So we just rely on the backends to only set | |
1354 | RTX_FRAME_RELATED_P on appropriate insns. */ | |
556273e0 | 1355 | cfa.reg = REGNO (dest); |
19ec6a36 AM |
1356 | cfa_temp.reg = cfa.reg; |
1357 | cfa_temp.offset = cfa.offset; | |
556273e0 | 1358 | break; |
b664de3a | 1359 | |
556273e0 KH |
1360 | case PLUS: |
1361 | case MINUS: | |
19ec6a36 | 1362 | case LO_SUM: |
556273e0 KH |
1363 | if (dest == stack_pointer_rtx) |
1364 | { | |
770ca8c6 | 1365 | /* Rule 2 */ |
2618f955 MM |
1366 | /* Adjusting SP. */ |
1367 | switch (GET_CODE (XEXP (src, 1))) | |
1368 | { | |
1369 | case CONST_INT: | |
1370 | offset = INTVAL (XEXP (src, 1)); | |
1371 | break; | |
1372 | case REG: | |
770ca8c6 | 1373 | if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg) |
2618f955 | 1374 | abort (); |
770ca8c6 | 1375 | offset = cfa_temp.offset; |
2618f955 MM |
1376 | break; |
1377 | default: | |
1378 | abort (); | |
1379 | } | |
1380 | ||
1381 | if (XEXP (src, 0) == hard_frame_pointer_rtx) | |
1382 | { | |
1383 | /* Restoring SP from FP in the epilogue. */ | |
7d9d8943 | 1384 | if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM) |
2618f955 | 1385 | abort (); |
7d9d8943 | 1386 | cfa.reg = STACK_POINTER_REGNUM; |
2618f955 | 1387 | } |
19ec6a36 AM |
1388 | else if (GET_CODE (src) == LO_SUM) |
1389 | /* Assume we've set the source reg of the LO_SUM from sp. */ | |
1390 | ; | |
2618f955 MM |
1391 | else if (XEXP (src, 0) != stack_pointer_rtx) |
1392 | abort (); | |
1393 | ||
19ec6a36 | 1394 | if (GET_CODE (src) != MINUS) |
2618f955 | 1395 | offset = -offset; |
7d9d8943 AM |
1396 | if (cfa.reg == STACK_POINTER_REGNUM) |
1397 | cfa.offset += offset; | |
1398 | if (cfa_store.reg == STACK_POINTER_REGNUM) | |
1399 | cfa_store.offset += offset; | |
556273e0 KH |
1400 | } |
1401 | else if (dest == hard_frame_pointer_rtx) | |
1402 | { | |
770ca8c6 | 1403 | /* Rule 3 */ |
2618f955 MM |
1404 | /* Either setting the FP from an offset of the SP, |
1405 | or adjusting the FP */ | |
2c849145 | 1406 | if (! frame_pointer_needed) |
2618f955 MM |
1407 | abort (); |
1408 | ||
2c849145 | 1409 | if (GET_CODE (XEXP (src, 0)) == REG |
7d9d8943 | 1410 | && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg |
2618f955 MM |
1411 | && GET_CODE (XEXP (src, 1)) == CONST_INT) |
1412 | { | |
2618f955 | 1413 | offset = INTVAL (XEXP (src, 1)); |
19ec6a36 | 1414 | if (GET_CODE (src) != MINUS) |
2618f955 | 1415 | offset = -offset; |
7d9d8943 AM |
1416 | cfa.offset += offset; |
1417 | cfa.reg = HARD_FRAME_POINTER_REGNUM; | |
2618f955 | 1418 | } |
556273e0 KH |
1419 | else |
1420 | abort (); | |
1421 | } | |
1422 | else | |
1423 | { | |
19ec6a36 | 1424 | if (GET_CODE (src) == MINUS) |
2618f955 | 1425 | abort (); |
b53ef1a2 | 1426 | |
770ca8c6 | 1427 | /* Rule 4 */ |
b53ef1a2 NC |
1428 | if (GET_CODE (XEXP (src, 0)) == REG |
1429 | && REGNO (XEXP (src, 0)) == cfa.reg | |
1430 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
34ce3d7b JM |
1431 | { |
1432 | /* Setting a temporary CFA register that will be copied | |
1433 | into the FP later on. */ | |
19ec6a36 | 1434 | offset = - INTVAL (XEXP (src, 1)); |
34ce3d7b JM |
1435 | cfa.offset += offset; |
1436 | cfa.reg = REGNO (dest); | |
19ec6a36 AM |
1437 | /* Or used to save regs to the stack. */ |
1438 | cfa_temp.reg = cfa.reg; | |
1439 | cfa_temp.offset = cfa.offset; | |
34ce3d7b | 1440 | } |
2ad9852d | 1441 | |
770ca8c6 | 1442 | /* Rule 5 */ |
19ec6a36 AM |
1443 | else if (GET_CODE (XEXP (src, 0)) == REG |
1444 | && REGNO (XEXP (src, 0)) == cfa_temp.reg | |
1445 | && XEXP (src, 1) == stack_pointer_rtx) | |
b53ef1a2 | 1446 | { |
00a42e21 JM |
1447 | /* Setting a scratch register that we will use instead |
1448 | of SP for saving registers to the stack. */ | |
b53ef1a2 NC |
1449 | if (cfa.reg != STACK_POINTER_REGNUM) |
1450 | abort (); | |
1451 | cfa_store.reg = REGNO (dest); | |
770ca8c6 | 1452 | cfa_store.offset = cfa.offset - cfa_temp.offset; |
b53ef1a2 | 1453 | } |
2ad9852d | 1454 | |
19ec6a36 AM |
1455 | /* Rule 9 */ |
1456 | else if (GET_CODE (src) == LO_SUM | |
1457 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
1458 | { | |
1459 | cfa_temp.reg = REGNO (dest); | |
1460 | cfa_temp.offset = INTVAL (XEXP (src, 1)); | |
1461 | } | |
1462 | else | |
1463 | abort (); | |
556273e0 KH |
1464 | } |
1465 | break; | |
b664de3a | 1466 | |
770ca8c6 | 1467 | /* Rule 6 */ |
556273e0 | 1468 | case CONST_INT: |
770ca8c6 JO |
1469 | cfa_temp.reg = REGNO (dest); |
1470 | cfa_temp.offset = INTVAL (src); | |
556273e0 | 1471 | break; |
b664de3a | 1472 | |
770ca8c6 | 1473 | /* Rule 7 */ |
556273e0 KH |
1474 | case IOR: |
1475 | if (GET_CODE (XEXP (src, 0)) != REG | |
770ca8c6 | 1476 | || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg |
2618f955 | 1477 | || GET_CODE (XEXP (src, 1)) != CONST_INT) |
556273e0 | 1478 | abort (); |
2ad9852d | 1479 | |
770ca8c6 JO |
1480 | if ((unsigned) REGNO (dest) != cfa_temp.reg) |
1481 | cfa_temp.reg = REGNO (dest); | |
1482 | cfa_temp.offset |= INTVAL (XEXP (src, 1)); | |
556273e0 | 1483 | break; |
b664de3a | 1484 | |
9ae21d2a AM |
1485 | /* Skip over HIGH, assuming it will be followed by a LO_SUM, |
1486 | which will fill in all of the bits. */ | |
1487 | /* Rule 8 */ | |
1488 | case HIGH: | |
1489 | break; | |
1490 | ||
556273e0 KH |
1491 | default: |
1492 | abort (); | |
1493 | } | |
2ad9852d | 1494 | |
7d9d8943 | 1495 | def_cfa_1 (label, &cfa); |
2618f955 | 1496 | break; |
b664de3a | 1497 | |
2618f955 | 1498 | case MEM: |
2618f955 MM |
1499 | if (GET_CODE (src) != REG) |
1500 | abort (); | |
7d9d8943 | 1501 | |
7d9d8943 AM |
1502 | /* Saving a register to the stack. Make sure dest is relative to the |
1503 | CFA register. */ | |
2618f955 MM |
1504 | switch (GET_CODE (XEXP (dest, 0))) |
1505 | { | |
770ca8c6 | 1506 | /* Rule 10 */ |
2618f955 | 1507 | /* With a push. */ |
e2134eea JH |
1508 | case PRE_MODIFY: |
1509 | /* We can't handle variable size modifications. */ | |
1510 | if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT) | |
173bf5be | 1511 | abort (); |
e2134eea JH |
1512 | offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1)); |
1513 | ||
1514 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM | |
1515 | || cfa_store.reg != STACK_POINTER_REGNUM) | |
1516 | abort (); | |
2ad9852d | 1517 | |
e2134eea JH |
1518 | cfa_store.offset += offset; |
1519 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1520 | cfa.offset = cfa_store.offset; | |
1521 | ||
1522 | offset = -cfa_store.offset; | |
1523 | break; | |
2ad9852d | 1524 | |
770ca8c6 | 1525 | /* Rule 11 */ |
2618f955 MM |
1526 | case PRE_INC: |
1527 | case PRE_DEC: | |
1528 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1529 | if (GET_CODE (XEXP (dest, 0)) == PRE_INC) | |
1530 | offset = -offset; | |
b664de3a | 1531 | |
2618f955 | 1532 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM |
7d9d8943 | 1533 | || cfa_store.reg != STACK_POINTER_REGNUM) |
2618f955 | 1534 | abort (); |
2ad9852d | 1535 | |
7d9d8943 AM |
1536 | cfa_store.offset += offset; |
1537 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1538 | cfa.offset = cfa_store.offset; | |
b664de3a | 1539 | |
7d9d8943 | 1540 | offset = -cfa_store.offset; |
2618f955 | 1541 | break; |
b664de3a | 1542 | |
770ca8c6 | 1543 | /* Rule 12 */ |
2618f955 MM |
1544 | /* With an offset. */ |
1545 | case PLUS: | |
1546 | case MINUS: | |
19ec6a36 | 1547 | case LO_SUM: |
770ca8c6 JO |
1548 | if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT) |
1549 | abort (); | |
2618f955 MM |
1550 | offset = INTVAL (XEXP (XEXP (dest, 0), 1)); |
1551 | if (GET_CODE (XEXP (dest, 0)) == MINUS) | |
1552 | offset = -offset; | |
b664de3a | 1553 | |
19ec6a36 AM |
1554 | if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) |
1555 | offset -= cfa_store.offset; | |
1556 | else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) | |
1557 | offset -= cfa_temp.offset; | |
1558 | else | |
2618f955 | 1559 | abort (); |
2618f955 MM |
1560 | break; |
1561 | ||
770ca8c6 | 1562 | /* Rule 13 */ |
2618f955 MM |
1563 | /* Without an offset. */ |
1564 | case REG: | |
19ec6a36 AM |
1565 | if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0))) |
1566 | offset = -cfa_store.offset; | |
1567 | else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0))) | |
1568 | offset = -cfa_temp.offset; | |
1569 | else | |
556273e0 | 1570 | abort (); |
19ec6a36 AM |
1571 | break; |
1572 | ||
1573 | /* Rule 14 */ | |
1574 | case POST_INC: | |
1575 | if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) | |
1576 | abort (); | |
1577 | offset = -cfa_temp.offset; | |
1578 | cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest)); | |
2618f955 MM |
1579 | break; |
1580 | ||
1581 | default: | |
1582 | abort (); | |
1583 | } | |
e09bbb25 | 1584 | |
556273e0 | 1585 | if (REGNO (src) != STACK_POINTER_REGNUM |
e09bbb25 JM |
1586 | && REGNO (src) != HARD_FRAME_POINTER_REGNUM |
1587 | && (unsigned) REGNO (src) == cfa.reg) | |
1588 | { | |
1589 | /* We're storing the current CFA reg into the stack. */ | |
1590 | ||
1591 | if (cfa.offset == 0) | |
1592 | { | |
1593 | /* If the source register is exactly the CFA, assume | |
1594 | we're saving SP like any other register; this happens | |
1595 | on the ARM. */ | |
e09bbb25 | 1596 | def_cfa_1 (label, &cfa); |
fbfa55b0 | 1597 | queue_reg_save (label, stack_pointer_rtx, offset); |
e09bbb25 JM |
1598 | break; |
1599 | } | |
1600 | else | |
1601 | { | |
1602 | /* Otherwise, we'll need to look in the stack to | |
1603 | calculate the CFA. */ | |
e09bbb25 | 1604 | rtx x = XEXP (dest, 0); |
2ad9852d | 1605 | |
e09bbb25 JM |
1606 | if (GET_CODE (x) != REG) |
1607 | x = XEXP (x, 0); | |
1608 | if (GET_CODE (x) != REG) | |
1609 | abort (); | |
2ad9852d RK |
1610 | |
1611 | cfa.reg = REGNO (x); | |
e09bbb25 JM |
1612 | cfa.base_offset = offset; |
1613 | cfa.indirect = 1; | |
1614 | def_cfa_1 (label, &cfa); | |
1615 | break; | |
1616 | } | |
1617 | } | |
1618 | ||
7d9d8943 | 1619 | def_cfa_1 (label, &cfa); |
fbfa55b0 | 1620 | queue_reg_save (label, src, offset); |
2618f955 MM |
1621 | break; |
1622 | ||
1623 | default: | |
1624 | abort (); | |
1625 | } | |
b664de3a AM |
1626 | } |
1627 | ||
3f76745e JM |
1628 | /* Record call frame debugging information for INSN, which either |
1629 | sets SP or FP (adjusting how we calculate the frame address) or saves a | |
1630 | register to the stack. If INSN is NULL_RTX, initialize our state. */ | |
71dfc51f | 1631 | |
3f76745e JM |
1632 | void |
1633 | dwarf2out_frame_debug (insn) | |
1634 | rtx insn; | |
a3f97cbb | 1635 | { |
d3e3972c | 1636 | const char *label; |
b664de3a | 1637 | rtx src; |
3f76745e JM |
1638 | |
1639 | if (insn == NULL_RTX) | |
a3f97cbb | 1640 | { |
fbfa55b0 RH |
1641 | /* Flush any queued register saves. */ |
1642 | flush_queued_reg_saves (); | |
1643 | ||
3f76745e | 1644 | /* Set up state for generating call frame debug info. */ |
7d9d8943 AM |
1645 | lookup_cfa (&cfa); |
1646 | if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)) | |
3a88cbd1 | 1647 | abort (); |
2ad9852d | 1648 | |
7d9d8943 AM |
1649 | cfa.reg = STACK_POINTER_REGNUM; |
1650 | cfa_store = cfa; | |
770ca8c6 JO |
1651 | cfa_temp.reg = -1; |
1652 | cfa_temp.offset = 0; | |
3f76745e JM |
1653 | return; |
1654 | } | |
1655 | ||
fbfa55b0 RH |
1656 | if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn)) |
1657 | flush_queued_reg_saves (); | |
1658 | ||
0021b564 JM |
1659 | if (! RTX_FRAME_RELATED_P (insn)) |
1660 | { | |
fbfa55b0 | 1661 | if (!ACCUMULATE_OUTGOING_ARGS) |
c26fbbca | 1662 | dwarf2out_stack_adjust (insn); |
2ad9852d | 1663 | |
0021b564 JM |
1664 | return; |
1665 | } | |
1666 | ||
3f76745e | 1667 | label = dwarf2out_cfi_label (); |
07ebc930 RH |
1668 | src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX); |
1669 | if (src) | |
1670 | insn = XEXP (src, 0); | |
556273e0 | 1671 | else |
07ebc930 RH |
1672 | insn = PATTERN (insn); |
1673 | ||
b664de3a | 1674 | dwarf2out_frame_debug_expr (insn, label); |
3f76745e JM |
1675 | } |
1676 | ||
3f76745e JM |
1677 | /* Output a Call Frame Information opcode and its operand(s). */ |
1678 | ||
1679 | static void | |
12f0b96b | 1680 | output_cfi (cfi, fde, for_eh) |
b3694847 SS |
1681 | dw_cfi_ref cfi; |
1682 | dw_fde_ref fde; | |
12f0b96b | 1683 | int for_eh; |
3f76745e JM |
1684 | { |
1685 | if (cfi->dw_cfi_opc == DW_CFA_advance_loc) | |
2ad9852d RK |
1686 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1687 | | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)), | |
1688 | "DW_CFA_advance_loc 0x%lx", | |
1689 | cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
3f76745e JM |
1690 | else if (cfi->dw_cfi_opc == DW_CFA_offset) |
1691 | { | |
2e4b9b8c RH |
1692 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1693 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)), | |
1694 | "DW_CFA_offset, column 0x%lx", | |
1695 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1696 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); | |
3f76745e JM |
1697 | } |
1698 | else if (cfi->dw_cfi_opc == DW_CFA_restore) | |
2ad9852d RK |
1699 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1700 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)), | |
1701 | "DW_CFA_restore, column 0x%lx", | |
1702 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
3f76745e JM |
1703 | else |
1704 | { | |
2e4b9b8c RH |
1705 | dw2_asm_output_data (1, cfi->dw_cfi_opc, |
1706 | "%s", dwarf_cfi_name (cfi->dw_cfi_opc)); | |
3f76745e | 1707 | |
3f76745e JM |
1708 | switch (cfi->dw_cfi_opc) |
1709 | { | |
1710 | case DW_CFA_set_loc: | |
e1f9550a RH |
1711 | if (for_eh) |
1712 | dw2_asm_output_encoded_addr_rtx ( | |
1713 | ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0), | |
1714 | gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr), | |
1715 | NULL); | |
1716 | else | |
1717 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, | |
1718 | cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL); | |
3f76745e | 1719 | break; |
2ad9852d | 1720 | |
3f76745e | 1721 | case DW_CFA_advance_loc1: |
2e4b9b8c RH |
1722 | dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1723 | fde->dw_fde_current_label, NULL); | |
bb727b5a | 1724 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
3f76745e | 1725 | break; |
2ad9852d | 1726 | |
3f76745e | 1727 | case DW_CFA_advance_loc2: |
2e4b9b8c RH |
1728 | dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1729 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
1730 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
1731 | break; | |
2ad9852d | 1732 | |
3f76745e | 1733 | case DW_CFA_advance_loc4: |
2e4b9b8c RH |
1734 | dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1735 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
1736 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
1737 | break; | |
2ad9852d | 1738 | |
3f76745e | 1739 | case DW_CFA_MIPS_advance_loc8: |
2e4b9b8c RH |
1740 | dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1741 | fde->dw_fde_current_label, NULL); | |
1742 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
3f76745e | 1743 | break; |
2ad9852d | 1744 | |
3f76745e JM |
1745 | case DW_CFA_offset_extended: |
1746 | case DW_CFA_def_cfa: | |
2ad9852d RK |
1747 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, |
1748 | NULL); | |
2e4b9b8c | 1749 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); |
3f76745e | 1750 | break; |
2ad9852d | 1751 | |
6bb28965 JM |
1752 | case DW_CFA_offset_extended_sf: |
1753 | case DW_CFA_def_cfa_sf: | |
1754 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, | |
1755 | NULL); | |
1756 | dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); | |
1757 | break; | |
1758 | ||
3f76745e JM |
1759 | case DW_CFA_restore_extended: |
1760 | case DW_CFA_undefined: | |
3f76745e JM |
1761 | case DW_CFA_same_value: |
1762 | case DW_CFA_def_cfa_register: | |
2ad9852d RK |
1763 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, |
1764 | NULL); | |
3f76745e | 1765 | break; |
2ad9852d | 1766 | |
3f76745e | 1767 | case DW_CFA_register: |
2ad9852d RK |
1768 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, |
1769 | NULL); | |
1770 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, | |
1771 | NULL); | |
3f76745e | 1772 | break; |
2ad9852d | 1773 | |
3f76745e | 1774 | case DW_CFA_def_cfa_offset: |
2e4b9b8c RH |
1775 | case DW_CFA_GNU_args_size: |
1776 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL); | |
3f76745e | 1777 | break; |
2ad9852d | 1778 | |
6bb28965 JM |
1779 | case DW_CFA_def_cfa_offset_sf: |
1780 | dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL); | |
1781 | break; | |
1782 | ||
c53aa195 JM |
1783 | case DW_CFA_GNU_window_save: |
1784 | break; | |
2ad9852d | 1785 | |
7d9d8943 | 1786 | case DW_CFA_def_cfa_expression: |
6bb28965 | 1787 | case DW_CFA_expression: |
7d9d8943 AM |
1788 | output_cfa_loc (cfi); |
1789 | break; | |
2ad9852d | 1790 | |
6bb28965 JM |
1791 | case DW_CFA_GNU_negative_offset_extended: |
1792 | /* Obsoleted by DW_CFA_offset_extended_sf. */ | |
1793 | abort (); | |
1794 | ||
3f76745e JM |
1795 | default: |
1796 | break; | |
1797 | } | |
556273e0 | 1798 | } |
3f76745e JM |
1799 | } |
1800 | ||
1801 | /* Output the call frame information used to used to record information | |
1802 | that relates to calculating the frame pointer, and records the | |
1803 | location of saved registers. */ | |
1804 | ||
1805 | static void | |
1806 | output_call_frame_info (for_eh) | |
1807 | int for_eh; | |
1808 | { | |
b3694847 SS |
1809 | unsigned int i; |
1810 | dw_fde_ref fde; | |
1811 | dw_cfi_ref cfi; | |
27d95cbe | 1812 | char l1[20], l2[20], section_start_label[20]; |
52a11cbf RH |
1813 | int any_lsda_needed = 0; |
1814 | char augmentation[6]; | |
e1f9550a RH |
1815 | int augmentation_size; |
1816 | int fde_encoding = DW_EH_PE_absptr; | |
1817 | int per_encoding = DW_EH_PE_absptr; | |
1818 | int lsda_encoding = DW_EH_PE_absptr; | |
3f76745e | 1819 | |
29b91443 JM |
1820 | /* Don't emit a CIE if there won't be any FDEs. */ |
1821 | if (fde_table_in_use == 0) | |
1822 | return; | |
1823 | ||
2ad9852d RK |
1824 | /* If we don't have any functions we'll want to unwind out of, don't emit any |
1825 | EH unwind information. */ | |
737faf14 JM |
1826 | if (for_eh) |
1827 | { | |
b932f770 | 1828 | int any_eh_needed = flag_asynchronous_unwind_tables; |
2ad9852d RK |
1829 | |
1830 | for (i = 0; i < fde_table_in_use; i++) | |
52a11cbf RH |
1831 | if (fde_table[i].uses_eh_lsda) |
1832 | any_eh_needed = any_lsda_needed = 1; | |
1833 | else if (! fde_table[i].nothrow) | |
1834 | any_eh_needed = 1; | |
1835 | ||
1836 | if (! any_eh_needed) | |
1837 | return; | |
737faf14 JM |
1838 | } |
1839 | ||
aa0c1401 JL |
1840 | /* We're going to be generating comments, so turn on app. */ |
1841 | if (flag_debug_asm) | |
1842 | app_enable (); | |
956d6950 | 1843 | |
3f76745e | 1844 | if (for_eh) |
07c9d2eb | 1845 | (*targetm.asm_out.eh_frame_section) (); |
3f76745e | 1846 | else |
715bdd29 | 1847 | named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG); |
3f76745e | 1848 | |
27d95cbe RH |
1849 | ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh); |
1850 | ASM_OUTPUT_LABEL (asm_out_file, section_start_label); | |
1851 | ||
556273e0 | 1852 | /* Output the CIE. */ |
a6ab3aad JM |
1853 | ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh); |
1854 | ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh); | |
2e4b9b8c RH |
1855 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
1856 | "Length of Common Information Entry"); | |
a6ab3aad JM |
1857 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1858 | ||
2e4b9b8c RH |
1859 | /* Now that the CIE pointer is PC-relative for EH, |
1860 | use 0 to identify the CIE. */ | |
1861 | dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE), | |
1862 | (for_eh ? 0 : DW_CIE_ID), | |
1863 | "CIE Identifier Tag"); | |
3f76745e | 1864 | |
2e4b9b8c | 1865 | dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version"); |
3f76745e | 1866 | |
52a11cbf | 1867 | augmentation[0] = 0; |
e1f9550a | 1868 | augmentation_size = 0; |
52a11cbf | 1869 | if (for_eh) |
a6ab3aad | 1870 | { |
e1f9550a RH |
1871 | char *p; |
1872 | ||
52a11cbf RH |
1873 | /* Augmentation: |
1874 | z Indicates that a uleb128 is present to size the | |
1875 | augmentation section. | |
e1f9550a RH |
1876 | L Indicates the encoding (and thus presence) of |
1877 | an LSDA pointer in the FDE augmentation. | |
1878 | R Indicates a non-default pointer encoding for | |
1879 | FDE code pointers. | |
1880 | P Indicates the presence of an encoding + language | |
1881 | personality routine in the CIE augmentation. */ | |
1882 | ||
1883 | fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0); | |
1884 | per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1); | |
1885 | lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0); | |
1886 | ||
1887 | p = augmentation + 1; | |
1888 | if (eh_personality_libfunc) | |
1889 | { | |
1890 | *p++ = 'P'; | |
1891 | augmentation_size += 1 + size_of_encoded_value (per_encoding); | |
1892 | } | |
52a11cbf | 1893 | if (any_lsda_needed) |
e1f9550a RH |
1894 | { |
1895 | *p++ = 'L'; | |
1896 | augmentation_size += 1; | |
1897 | } | |
1898 | if (fde_encoding != DW_EH_PE_absptr) | |
1899 | { | |
1900 | *p++ = 'R'; | |
1901 | augmentation_size += 1; | |
1902 | } | |
1903 | if (p > augmentation + 1) | |
1904 | { | |
1905 | augmentation[0] = 'z'; | |
c26fbbca | 1906 | *p = '\0'; |
e1f9550a | 1907 | } |
099c8b17 RH |
1908 | |
1909 | /* Ug. Some platforms can't do unaligned dynamic relocations at all. */ | |
1910 | if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned) | |
1911 | { | |
1912 | int offset = ( 4 /* Length */ | |
1913 | + 4 /* CIE Id */ | |
1914 | + 1 /* CIE version */ | |
1915 | + strlen (augmentation) + 1 /* Augmentation */ | |
1916 | + size_of_uleb128 (1) /* Code alignment */ | |
1917 | + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT) | |
1918 | + 1 /* RA column */ | |
1919 | + 1 /* Augmentation size */ | |
1920 | + 1 /* Personality encoding */ ); | |
1921 | int pad = -offset & (PTR_SIZE - 1); | |
1922 | ||
1923 | augmentation_size += pad; | |
1924 | ||
1925 | /* Augmentations should be small, so there's scarce need to | |
1926 | iterate for a solution. Die if we exceed one uleb128 byte. */ | |
1927 | if (size_of_uleb128 (augmentation_size) != 1) | |
1928 | abort (); | |
1929 | } | |
a6ab3aad | 1930 | } |
3f76745e | 1931 | |
2ad9852d | 1932 | dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation"); |
2e4b9b8c | 1933 | dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor"); |
2e4b9b8c RH |
1934 | dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT, |
1935 | "CIE Data Alignment Factor"); | |
2e4b9b8c | 1936 | dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column"); |
3f76745e | 1937 | |
52a11cbf RH |
1938 | if (augmentation[0]) |
1939 | { | |
e1f9550a | 1940 | dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size"); |
52a11cbf | 1941 | if (eh_personality_libfunc) |
e1f9550a RH |
1942 | { |
1943 | dw2_asm_output_data (1, per_encoding, "Personality (%s)", | |
1944 | eh_data_format_name (per_encoding)); | |
1945 | dw2_asm_output_encoded_addr_rtx (per_encoding, | |
1946 | eh_personality_libfunc, NULL); | |
1947 | } | |
2ad9852d | 1948 | |
e1f9550a RH |
1949 | if (any_lsda_needed) |
1950 | dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)", | |
1951 | eh_data_format_name (lsda_encoding)); | |
2ad9852d | 1952 | |
e1f9550a RH |
1953 | if (fde_encoding != DW_EH_PE_absptr) |
1954 | dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)", | |
1955 | eh_data_format_name (fde_encoding)); | |
52a11cbf RH |
1956 | } |
1957 | ||
3f76745e | 1958 | for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next) |
12f0b96b | 1959 | output_cfi (cfi, NULL, for_eh); |
3f76745e JM |
1960 | |
1961 | /* Pad the CIE out to an address sized boundary. */ | |
c26fbbca | 1962 | ASM_OUTPUT_ALIGN (asm_out_file, |
12f0b96b | 1963 | floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)); |
a6ab3aad | 1964 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e JM |
1965 | |
1966 | /* Loop through all of the FDE's. */ | |
2ad9852d | 1967 | for (i = 0; i < fde_table_in_use; i++) |
3f76745e JM |
1968 | { |
1969 | fde = &fde_table[i]; | |
3f76745e | 1970 | |
52a11cbf | 1971 | /* Don't emit EH unwind info for leaf functions that don't need it. */ |
194734e9 JH |
1972 | if (!flag_asynchronous_unwind_tables && for_eh && fde->nothrow |
1973 | && ! fde->uses_eh_lsda) | |
737faf14 JM |
1974 | continue; |
1975 | ||
2e4b9b8c | 1976 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2); |
556273e0 KH |
1977 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2); |
1978 | ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2); | |
2e4b9b8c RH |
1979 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
1980 | "FDE Length"); | |
a6ab3aad JM |
1981 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1982 | ||
3f76745e | 1983 | if (for_eh) |
27d95cbe | 1984 | dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset"); |
3f76745e | 1985 | else |
27d95cbe | 1986 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label, |
2e4b9b8c | 1987 | "FDE CIE offset"); |
3f76745e | 1988 | |
e1f9550a RH |
1989 | if (for_eh) |
1990 | { | |
1991 | dw2_asm_output_encoded_addr_rtx (fde_encoding, | |
1992 | gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin), | |
1993 | "FDE initial location"); | |
1994 | dw2_asm_output_delta (size_of_encoded_value (fde_encoding), | |
c26fbbca | 1995 | fde->dw_fde_end, fde->dw_fde_begin, |
e1f9550a RH |
1996 | "FDE address range"); |
1997 | } | |
1998 | else | |
1999 | { | |
2000 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin, | |
2001 | "FDE initial location"); | |
c26fbbca KH |
2002 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, |
2003 | fde->dw_fde_end, fde->dw_fde_begin, | |
e1f9550a RH |
2004 | "FDE address range"); |
2005 | } | |
3f76745e | 2006 | |
52a11cbf RH |
2007 | if (augmentation[0]) |
2008 | { | |
e1f9550a | 2009 | if (any_lsda_needed) |
52a11cbf | 2010 | { |
099c8b17 RH |
2011 | int size = size_of_encoded_value (lsda_encoding); |
2012 | ||
2013 | if (lsda_encoding == DW_EH_PE_aligned) | |
2014 | { | |
2015 | int offset = ( 4 /* Length */ | |
2016 | + 4 /* CIE offset */ | |
2017 | + 2 * size_of_encoded_value (fde_encoding) | |
2018 | + 1 /* Augmentation size */ ); | |
2019 | int pad = -offset & (PTR_SIZE - 1); | |
2020 | ||
2021 | size += pad; | |
2022 | if (size_of_uleb128 (size) != 1) | |
2023 | abort (); | |
2024 | } | |
2025 | ||
2026 | dw2_asm_output_data_uleb128 (size, "Augmentation size"); | |
e1f9550a RH |
2027 | |
2028 | if (fde->uses_eh_lsda) | |
2029 | { | |
2030 | ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA", | |
2031 | fde->funcdef_number); | |
2032 | dw2_asm_output_encoded_addr_rtx ( | |
2033 | lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1), | |
2034 | "Language Specific Data Area"); | |
2035 | } | |
2036 | else | |
099c8b17 RH |
2037 | { |
2038 | if (lsda_encoding == DW_EH_PE_aligned) | |
2039 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); | |
2ad9852d RK |
2040 | dw2_asm_output_data |
2041 | (size_of_encoded_value (lsda_encoding), 0, | |
2042 | "Language Specific Data Area (none)"); | |
099c8b17 | 2043 | } |
52a11cbf RH |
2044 | } |
2045 | else | |
e1f9550a | 2046 | dw2_asm_output_data_uleb128 (0, "Augmentation size"); |
52a11cbf RH |
2047 | } |
2048 | ||
3f76745e JM |
2049 | /* Loop through the Call Frame Instructions associated with |
2050 | this FDE. */ | |
2051 | fde->dw_fde_current_label = fde->dw_fde_begin; | |
2052 | for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next) | |
12f0b96b | 2053 | output_cfi (cfi, fde, for_eh); |
3f76745e | 2054 | |
a6ab3aad | 2055 | /* Pad the FDE out to an address sized boundary. */ |
c26fbbca | 2056 | ASM_OUTPUT_ALIGN (asm_out_file, |
e1f9550a | 2057 | floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE))); |
a6ab3aad | 2058 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e | 2059 | } |
2e4b9b8c | 2060 | |
7c262518 | 2061 | #ifndef EH_FRAME_SECTION_NAME |
3f76745e | 2062 | if (for_eh) |
2e4b9b8c | 2063 | dw2_asm_output_data (4, 0, "End of Table"); |
3f76745e | 2064 | #endif |
a6ab3aad JM |
2065 | #ifdef MIPS_DEBUGGING_INFO |
2066 | /* Work around Irix 6 assembler bug whereby labels at the end of a section | |
2067 | get a value of 0. Putting .align 0 after the label fixes it. */ | |
2068 | ASM_OUTPUT_ALIGN (asm_out_file, 0); | |
2069 | #endif | |
aa0c1401 JL |
2070 | |
2071 | /* Turn off app to make assembly quicker. */ | |
2072 | if (flag_debug_asm) | |
2073 | app_disable (); | |
a6ab3aad JM |
2074 | } |
2075 | ||
3f76745e JM |
2076 | /* Output a marker (i.e. a label) for the beginning of a function, before |
2077 | the prologue. */ | |
2078 | ||
2079 | void | |
653e276c NB |
2080 | dwarf2out_begin_prologue (line, file) |
2081 | unsigned int line ATTRIBUTE_UNUSED; | |
2082 | const char *file ATTRIBUTE_UNUSED; | |
3f76745e JM |
2083 | { |
2084 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 | 2085 | dw_fde_ref fde; |
3f76745e | 2086 | |
2a1ee410 RH |
2087 | current_function_func_begin_label = 0; |
2088 | ||
2089 | #ifdef IA64_UNWIND_INFO | |
2090 | /* ??? current_function_func_begin_label is also used by except.c | |
2091 | for call-site information. We must emit this label if it might | |
2092 | be used. */ | |
2093 | if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS) | |
2094 | && ! dwarf2out_do_frame ()) | |
2095 | return; | |
2096 | #else | |
2097 | if (! dwarf2out_do_frame ()) | |
2098 | return; | |
2099 | #endif | |
2100 | ||
2ad9852d | 2101 | current_funcdef_number++; |
3f76745e JM |
2102 | function_section (current_function_decl); |
2103 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL, | |
2104 | current_funcdef_number); | |
2a1ee410 RH |
2105 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL, |
2106 | current_funcdef_number); | |
00262c8a | 2107 | current_function_func_begin_label = get_identifier (label); |
3f76745e | 2108 | |
2a1ee410 RH |
2109 | #ifdef IA64_UNWIND_INFO |
2110 | /* We can elide the fde allocation if we're not emitting debug info. */ | |
2111 | if (! dwarf2out_do_frame ()) | |
2112 | return; | |
2113 | #endif | |
2114 | ||
3f76745e JM |
2115 | /* Expand the fde table if necessary. */ |
2116 | if (fde_table_in_use == fde_table_allocated) | |
2117 | { | |
2118 | fde_table_allocated += FDE_TABLE_INCREMENT; | |
2119 | fde_table | |
2120 | = (dw_fde_ref) xrealloc (fde_table, | |
2121 | fde_table_allocated * sizeof (dw_fde_node)); | |
a3f97cbb | 2122 | } |
3f76745e JM |
2123 | |
2124 | /* Record the FDE associated with this function. */ | |
2125 | current_funcdef_fde = fde_table_in_use; | |
2126 | ||
2127 | /* Add the new FDE at the end of the fde_table. */ | |
2128 | fde = &fde_table[fde_table_in_use++]; | |
2129 | fde->dw_fde_begin = xstrdup (label); | |
2130 | fde->dw_fde_current_label = NULL; | |
2131 | fde->dw_fde_end = NULL; | |
2132 | fde->dw_fde_cfi = NULL; | |
52a11cbf | 2133 | fde->funcdef_number = current_funcdef_number; |
fb13d4d0 | 2134 | fde->nothrow = current_function_nothrow; |
52a11cbf | 2135 | fde->uses_eh_lsda = cfun->uses_eh_lsda; |
737faf14 | 2136 | |
b57d9225 | 2137 | args_size = old_args_size = 0; |
653e276c | 2138 | |
2ad9852d RK |
2139 | /* We only want to output line number information for the genuine dwarf2 |
2140 | prologue case, not the eh frame case. */ | |
653e276c NB |
2141 | #ifdef DWARF2_DEBUGGING_INFO |
2142 | if (file) | |
2143 | dwarf2out_source_line (line, file); | |
2144 | #endif | |
3f76745e JM |
2145 | } |
2146 | ||
2147 | /* Output a marker (i.e. a label) for the absolute end of the generated code | |
2148 | for a function definition. This gets called *after* the epilogue code has | |
2149 | been generated. */ | |
2150 | ||
2151 | void | |
2152 | dwarf2out_end_epilogue () | |
2153 | { | |
2154 | dw_fde_ref fde; | |
2155 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2156 | ||
2157 | /* Output a label to mark the endpoint of the code generated for this | |
3ef42a0c | 2158 | function. */ |
3f76745e JM |
2159 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number); |
2160 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
2161 | fde = &fde_table[fde_table_in_use - 1]; | |
2162 | fde->dw_fde_end = xstrdup (label); | |
3f76745e JM |
2163 | } |
2164 | ||
2165 | void | |
2166 | dwarf2out_frame_init () | |
2167 | { | |
2168 | /* Allocate the initial hunk of the fde_table. */ | |
3de90026 | 2169 | fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node)); |
3f76745e JM |
2170 | fde_table_allocated = FDE_TABLE_INCREMENT; |
2171 | fde_table_in_use = 0; | |
2172 | ||
2173 | /* Generate the CFA instructions common to all FDE's. Do it now for the | |
2174 | sake of lookup_cfa. */ | |
2175 | ||
a6ab3aad | 2176 | #ifdef DWARF2_UNWIND_INFO |
91193900 AS |
2177 | /* On entry, the Canonical Frame Address is at SP. */ |
2178 | dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET); | |
2179 | initial_return_save (INCOMING_RETURN_ADDR_RTX); | |
3f76745e JM |
2180 | #endif |
2181 | } | |
2182 | ||
2183 | void | |
2184 | dwarf2out_frame_finish () | |
2185 | { | |
3f76745e | 2186 | /* Output call frame information. */ |
7a0c8d71 | 2187 | if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG) |
3f76745e | 2188 | output_call_frame_info (0); |
2ad9852d | 2189 | |
ddee9e8d | 2190 | if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions)) |
3f76745e | 2191 | output_call_frame_info (1); |
556273e0 | 2192 | } |
7d9d8943 AM |
2193 | \f |
2194 | /* And now, the subset of the debugging information support code necessary | |
2195 | for emitting location expressions. */ | |
3f76745e | 2196 | |
7d9d8943 AM |
2197 | typedef struct dw_val_struct *dw_val_ref; |
2198 | typedef struct die_struct *dw_die_ref; | |
2199 | typedef struct dw_loc_descr_struct *dw_loc_descr_ref; | |
63e46568 | 2200 | typedef struct dw_loc_list_struct *dw_loc_list_ref; |
3f76745e JM |
2201 | |
2202 | /* Each DIE may have a series of attribute/value pairs. Values | |
2203 | can take on several forms. The forms that are used in this | |
2204 | implementation are listed below. */ | |
2205 | ||
2206 | typedef enum | |
2207 | { | |
2208 | dw_val_class_addr, | |
a20612aa | 2209 | dw_val_class_offset, |
3f76745e | 2210 | dw_val_class_loc, |
63e46568 | 2211 | dw_val_class_loc_list, |
2bee6045 | 2212 | dw_val_class_range_list, |
3f76745e JM |
2213 | dw_val_class_const, |
2214 | dw_val_class_unsigned_const, | |
2215 | dw_val_class_long_long, | |
2216 | dw_val_class_float, | |
2217 | dw_val_class_flag, | |
2218 | dw_val_class_die_ref, | |
2219 | dw_val_class_fde_ref, | |
2220 | dw_val_class_lbl_id, | |
8b790721 | 2221 | dw_val_class_lbl_offset, |
3f76745e | 2222 | dw_val_class_str |
a3f97cbb | 2223 | } |
3f76745e | 2224 | dw_val_class; |
a3f97cbb | 2225 | |
3f76745e | 2226 | /* Describe a double word constant value. */ |
21217bd0 | 2227 | /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */ |
3f76745e JM |
2228 | |
2229 | typedef struct dw_long_long_struct | |
a3f97cbb | 2230 | { |
3f76745e JM |
2231 | unsigned long hi; |
2232 | unsigned long low; | |
2233 | } | |
2234 | dw_long_long_const; | |
2235 | ||
2236 | /* Describe a floating point constant value. */ | |
2237 | ||
2238 | typedef struct dw_fp_struct | |
2239 | { | |
2240 | long *array; | |
2241 | unsigned length; | |
2242 | } | |
2243 | dw_float_const; | |
2244 | ||
956d6950 | 2245 | /* The dw_val_node describes an attribute's value, as it is |
3f76745e JM |
2246 | represented internally. */ |
2247 | ||
2248 | typedef struct dw_val_struct | |
2249 | { | |
2250 | dw_val_class val_class; | |
2251 | union | |
a3f97cbb | 2252 | { |
1865dbb5 | 2253 | rtx val_addr; |
a20612aa | 2254 | long unsigned val_offset; |
63e46568 | 2255 | dw_loc_list_ref val_loc_list; |
3f76745e JM |
2256 | dw_loc_descr_ref val_loc; |
2257 | long int val_int; | |
2258 | long unsigned val_unsigned; | |
2259 | dw_long_long_const val_long_long; | |
2260 | dw_float_const val_float; | |
2ad9852d RK |
2261 | struct |
2262 | { | |
2263 | dw_die_ref die; | |
2264 | int external; | |
2265 | } val_die_ref; | |
3f76745e | 2266 | unsigned val_fde_index; |
9eb4015a | 2267 | struct indirect_string_node *val_str; |
3f76745e | 2268 | char *val_lbl_id; |
3f76745e | 2269 | unsigned char val_flag; |
a3f97cbb | 2270 | } |
3f76745e JM |
2271 | v; |
2272 | } | |
2273 | dw_val_node; | |
2274 | ||
2275 | /* Locations in memory are described using a sequence of stack machine | |
2276 | operations. */ | |
2277 | ||
2278 | typedef struct dw_loc_descr_struct | |
2279 | { | |
2280 | dw_loc_descr_ref dw_loc_next; | |
2281 | enum dwarf_location_atom dw_loc_opc; | |
2282 | dw_val_node dw_loc_oprnd1; | |
2283 | dw_val_node dw_loc_oprnd2; | |
d8041cc8 | 2284 | int dw_loc_addr; |
3f76745e JM |
2285 | } |
2286 | dw_loc_descr_node; | |
2287 | ||
63e46568 DB |
2288 | /* Location lists are ranges + location descriptions for that range, |
2289 | so you can track variables that are in different places over | |
30f7a378 | 2290 | their entire life. */ |
63e46568 DB |
2291 | typedef struct dw_loc_list_struct |
2292 | { | |
2293 | dw_loc_list_ref dw_loc_next; | |
2294 | const char *begin; /* Label for begin address of range */ | |
2295 | const char *end; /* Label for end address of range */ | |
2ad9852d RK |
2296 | char *ll_symbol; /* Label for beginning of location list. |
2297 | Only on head of list */ | |
63e46568 DB |
2298 | const char *section; /* Section this loclist is relative to */ |
2299 | dw_loc_descr_ref expr; | |
2300 | } dw_loc_list_node; | |
2301 | ||
7d9d8943 AM |
2302 | static const char *dwarf_stack_op_name PARAMS ((unsigned)); |
2303 | static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom, | |
2304 | unsigned long, | |
2305 | unsigned long)); | |
2306 | static void add_loc_descr PARAMS ((dw_loc_descr_ref *, | |
2307 | dw_loc_descr_ref)); | |
2308 | static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref)); | |
2309 | static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref)); | |
2310 | static void output_loc_operands PARAMS ((dw_loc_descr_ref)); | |
2311 | static void output_loc_sequence PARAMS ((dw_loc_descr_ref)); | |
3f76745e | 2312 | |
7d9d8943 | 2313 | /* Convert a DWARF stack opcode into its string name. */ |
3f76745e | 2314 | |
7d9d8943 AM |
2315 | static const char * |
2316 | dwarf_stack_op_name (op) | |
b3694847 | 2317 | unsigned op; |
ef76d03b | 2318 | { |
7d9d8943 AM |
2319 | switch (op) |
2320 | { | |
2321 | case DW_OP_addr: | |
2322 | return "DW_OP_addr"; | |
2323 | case DW_OP_deref: | |
2324 | return "DW_OP_deref"; | |
2325 | case DW_OP_const1u: | |
2326 | return "DW_OP_const1u"; | |
2327 | case DW_OP_const1s: | |
2328 | return "DW_OP_const1s"; | |
2329 | case DW_OP_const2u: | |
2330 | return "DW_OP_const2u"; | |
2331 | case DW_OP_const2s: | |
2332 | return "DW_OP_const2s"; | |
2333 | case DW_OP_const4u: | |
2334 | return "DW_OP_const4u"; | |
2335 | case DW_OP_const4s: | |
2336 | return "DW_OP_const4s"; | |
2337 | case DW_OP_const8u: | |
2338 | return "DW_OP_const8u"; | |
2339 | case DW_OP_const8s: | |
2340 | return "DW_OP_const8s"; | |
2341 | case DW_OP_constu: | |
2342 | return "DW_OP_constu"; | |
2343 | case DW_OP_consts: | |
2344 | return "DW_OP_consts"; | |
2345 | case DW_OP_dup: | |
2346 | return "DW_OP_dup"; | |
2347 | case DW_OP_drop: | |
2348 | return "DW_OP_drop"; | |
2349 | case DW_OP_over: | |
2350 | return "DW_OP_over"; | |
2351 | case DW_OP_pick: | |
2352 | return "DW_OP_pick"; | |
2353 | case DW_OP_swap: | |
2354 | return "DW_OP_swap"; | |
2355 | case DW_OP_rot: | |
2356 | return "DW_OP_rot"; | |
2357 | case DW_OP_xderef: | |
2358 | return "DW_OP_xderef"; | |
2359 | case DW_OP_abs: | |
2360 | return "DW_OP_abs"; | |
2361 | case DW_OP_and: | |
2362 | return "DW_OP_and"; | |
2363 | case DW_OP_div: | |
2364 | return "DW_OP_div"; | |
2365 | case DW_OP_minus: | |
2366 | return "DW_OP_minus"; | |
2367 | case DW_OP_mod: | |
2368 | return "DW_OP_mod"; | |
2369 | case DW_OP_mul: | |
2370 | return "DW_OP_mul"; | |
2371 | case DW_OP_neg: | |
2372 | return "DW_OP_neg"; | |
2373 | case DW_OP_not: | |
2374 | return "DW_OP_not"; | |
2375 | case DW_OP_or: | |
2376 | return "DW_OP_or"; | |
2377 | case DW_OP_plus: | |
2378 | return "DW_OP_plus"; | |
2379 | case DW_OP_plus_uconst: | |
2380 | return "DW_OP_plus_uconst"; | |
2381 | case DW_OP_shl: | |
2382 | return "DW_OP_shl"; | |
2383 | case DW_OP_shr: | |
2384 | return "DW_OP_shr"; | |
2385 | case DW_OP_shra: | |
2386 | return "DW_OP_shra"; | |
2387 | case DW_OP_xor: | |
2388 | return "DW_OP_xor"; | |
2389 | case DW_OP_bra: | |
2390 | return "DW_OP_bra"; | |
2391 | case DW_OP_eq: | |
2392 | return "DW_OP_eq"; | |
2393 | case DW_OP_ge: | |
2394 | return "DW_OP_ge"; | |
2395 | case DW_OP_gt: | |
2396 | return "DW_OP_gt"; | |
2397 | case DW_OP_le: | |
2398 | return "DW_OP_le"; | |
2399 | case DW_OP_lt: | |
2400 | return "DW_OP_lt"; | |
2401 | case DW_OP_ne: | |
2402 | return "DW_OP_ne"; | |
2403 | case DW_OP_skip: | |
2404 | return "DW_OP_skip"; | |
2405 | case DW_OP_lit0: | |
2406 | return "DW_OP_lit0"; | |
2407 | case DW_OP_lit1: | |
2408 | return "DW_OP_lit1"; | |
2409 | case DW_OP_lit2: | |
2410 | return "DW_OP_lit2"; | |
2411 | case DW_OP_lit3: | |
2412 | return "DW_OP_lit3"; | |
2413 | case DW_OP_lit4: | |
2414 | return "DW_OP_lit4"; | |
2415 | case DW_OP_lit5: | |
2416 | return "DW_OP_lit5"; | |
2417 | case DW_OP_lit6: | |
2418 | return "DW_OP_lit6"; | |
2419 | case DW_OP_lit7: | |
2420 | return "DW_OP_lit7"; | |
2421 | case DW_OP_lit8: | |
2422 | return "DW_OP_lit8"; | |
2423 | case DW_OP_lit9: | |
2424 | return "DW_OP_lit9"; | |
2425 | case DW_OP_lit10: | |
2426 | return "DW_OP_lit10"; | |
2427 | case DW_OP_lit11: | |
2428 | return "DW_OP_lit11"; | |
2429 | case DW_OP_lit12: | |
2430 | return "DW_OP_lit12"; | |
2431 | case DW_OP_lit13: | |
2432 | return "DW_OP_lit13"; | |
2433 | case DW_OP_lit14: | |
2434 | return "DW_OP_lit14"; | |
2435 | case DW_OP_lit15: | |
2436 | return "DW_OP_lit15"; | |
2437 | case DW_OP_lit16: | |
2438 | return "DW_OP_lit16"; | |
2439 | case DW_OP_lit17: | |
2440 | return "DW_OP_lit17"; | |
2441 | case DW_OP_lit18: | |
2442 | return "DW_OP_lit18"; | |
2443 | case DW_OP_lit19: | |
2444 | return "DW_OP_lit19"; | |
2445 | case DW_OP_lit20: | |
2446 | return "DW_OP_lit20"; | |
2447 | case DW_OP_lit21: | |
2448 | return "DW_OP_lit21"; | |
2449 | case DW_OP_lit22: | |
2450 | return "DW_OP_lit22"; | |
2451 | case DW_OP_lit23: | |
2452 | return "DW_OP_lit23"; | |
2453 | case DW_OP_lit24: | |
2454 | return "DW_OP_lit24"; | |
2455 | case DW_OP_lit25: | |
2456 | return "DW_OP_lit25"; | |
2457 | case DW_OP_lit26: | |
2458 | return "DW_OP_lit26"; | |
2459 | case DW_OP_lit27: | |
2460 | return "DW_OP_lit27"; | |
2461 | case DW_OP_lit28: | |
2462 | return "DW_OP_lit28"; | |
2463 | case DW_OP_lit29: | |
2464 | return "DW_OP_lit29"; | |
2465 | case DW_OP_lit30: | |
2466 | return "DW_OP_lit30"; | |
2467 | case DW_OP_lit31: | |
2468 | return "DW_OP_lit31"; | |
2469 | case DW_OP_reg0: | |
2470 | return "DW_OP_reg0"; | |
2471 | case DW_OP_reg1: | |
2472 | return "DW_OP_reg1"; | |
2473 | case DW_OP_reg2: | |
2474 | return "DW_OP_reg2"; | |
2475 | case DW_OP_reg3: | |
2476 | return "DW_OP_reg3"; | |
2477 | case DW_OP_reg4: | |
2478 | return "DW_OP_reg4"; | |
2479 | case DW_OP_reg5: | |
2480 | return "DW_OP_reg5"; | |
2481 | case DW_OP_reg6: | |
2482 | return "DW_OP_reg6"; | |
2483 | case DW_OP_reg7: | |
2484 | return "DW_OP_reg7"; | |
2485 | case DW_OP_reg8: | |
2486 | return "DW_OP_reg8"; | |
2487 | case DW_OP_reg9: | |
2488 | return "DW_OP_reg9"; | |
2489 | case DW_OP_reg10: | |
2490 | return "DW_OP_reg10"; | |
2491 | case DW_OP_reg11: | |
2492 | return "DW_OP_reg11"; | |
2493 | case DW_OP_reg12: | |
2494 | return "DW_OP_reg12"; | |
2495 | case DW_OP_reg13: | |
2496 | return "DW_OP_reg13"; | |
2497 | case DW_OP_reg14: | |
2498 | return "DW_OP_reg14"; | |
2499 | case DW_OP_reg15: | |
2500 | return "DW_OP_reg15"; | |
2501 | case DW_OP_reg16: | |
2502 | return "DW_OP_reg16"; | |
2503 | case DW_OP_reg17: | |
2504 | return "DW_OP_reg17"; | |
2505 | case DW_OP_reg18: | |
2506 | return "DW_OP_reg18"; | |
2507 | case DW_OP_reg19: | |
2508 | return "DW_OP_reg19"; | |
2509 | case DW_OP_reg20: | |
2510 | return "DW_OP_reg20"; | |
2511 | case DW_OP_reg21: | |
2512 | return "DW_OP_reg21"; | |
2513 | case DW_OP_reg22: | |
2514 | return "DW_OP_reg22"; | |
2515 | case DW_OP_reg23: | |
2516 | return "DW_OP_reg23"; | |
2517 | case DW_OP_reg24: | |
2518 | return "DW_OP_reg24"; | |
2519 | case DW_OP_reg25: | |
2520 | return "DW_OP_reg25"; | |
2521 | case DW_OP_reg26: | |
2522 | return "DW_OP_reg26"; | |
2523 | case DW_OP_reg27: | |
2524 | return "DW_OP_reg27"; | |
2525 | case DW_OP_reg28: | |
2526 | return "DW_OP_reg28"; | |
2527 | case DW_OP_reg29: | |
2528 | return "DW_OP_reg29"; | |
2529 | case DW_OP_reg30: | |
2530 | return "DW_OP_reg30"; | |
2531 | case DW_OP_reg31: | |
2532 | return "DW_OP_reg31"; | |
2533 | case DW_OP_breg0: | |
2534 | return "DW_OP_breg0"; | |
2535 | case DW_OP_breg1: | |
2536 | return "DW_OP_breg1"; | |
2537 | case DW_OP_breg2: | |
2538 | return "DW_OP_breg2"; | |
2539 | case DW_OP_breg3: | |
2540 | return "DW_OP_breg3"; | |
2541 | case DW_OP_breg4: | |
2542 | return "DW_OP_breg4"; | |
2543 | case DW_OP_breg5: | |
2544 | return "DW_OP_breg5"; | |
2545 | case DW_OP_breg6: | |
2546 | return "DW_OP_breg6"; | |
2547 | case DW_OP_breg7: | |
2548 | return "DW_OP_breg7"; | |
2549 | case DW_OP_breg8: | |
2550 | return "DW_OP_breg8"; | |
2551 | case DW_OP_breg9: | |
2552 | return "DW_OP_breg9"; | |
2553 | case DW_OP_breg10: | |
2554 | return "DW_OP_breg10"; | |
2555 | case DW_OP_breg11: | |
2556 | return "DW_OP_breg11"; | |
2557 | case DW_OP_breg12: | |
2558 | return "DW_OP_breg12"; | |
2559 | case DW_OP_breg13: | |
2560 | return "DW_OP_breg13"; | |
2561 | case DW_OP_breg14: | |
2562 | return "DW_OP_breg14"; | |
2563 | case DW_OP_breg15: | |
2564 | return "DW_OP_breg15"; | |
2565 | case DW_OP_breg16: | |
2566 | return "DW_OP_breg16"; | |
2567 | case DW_OP_breg17: | |
2568 | return "DW_OP_breg17"; | |
2569 | case DW_OP_breg18: | |
2570 | return "DW_OP_breg18"; | |
2571 | case DW_OP_breg19: | |
2572 | return "DW_OP_breg19"; | |
2573 | case DW_OP_breg20: | |
2574 | return "DW_OP_breg20"; | |
2575 | case DW_OP_breg21: | |
2576 | return "DW_OP_breg21"; | |
2577 | case DW_OP_breg22: | |
2578 | return "DW_OP_breg22"; | |
2579 | case DW_OP_breg23: | |
2580 | return "DW_OP_breg23"; | |
2581 | case DW_OP_breg24: | |
2582 | return "DW_OP_breg24"; | |
2583 | case DW_OP_breg25: | |
2584 | return "DW_OP_breg25"; | |
2585 | case DW_OP_breg26: | |
2586 | return "DW_OP_breg26"; | |
2587 | case DW_OP_breg27: | |
2588 | return "DW_OP_breg27"; | |
2589 | case DW_OP_breg28: | |
2590 | return "DW_OP_breg28"; | |
2591 | case DW_OP_breg29: | |
2592 | return "DW_OP_breg29"; | |
2593 | case DW_OP_breg30: | |
2594 | return "DW_OP_breg30"; | |
2595 | case DW_OP_breg31: | |
2596 | return "DW_OP_breg31"; | |
2597 | case DW_OP_regx: | |
2598 | return "DW_OP_regx"; | |
2599 | case DW_OP_fbreg: | |
2600 | return "DW_OP_fbreg"; | |
2601 | case DW_OP_bregx: | |
2602 | return "DW_OP_bregx"; | |
2603 | case DW_OP_piece: | |
2604 | return "DW_OP_piece"; | |
2605 | case DW_OP_deref_size: | |
2606 | return "DW_OP_deref_size"; | |
2607 | case DW_OP_xderef_size: | |
2608 | return "DW_OP_xderef_size"; | |
2609 | case DW_OP_nop: | |
2610 | return "DW_OP_nop"; | |
3f76745e | 2611 | default: |
7d9d8943 | 2612 | return "OP_<unknown>"; |
3f76745e | 2613 | } |
bdb669cb | 2614 | } |
a3f97cbb | 2615 | |
7d9d8943 AM |
2616 | /* Return a pointer to a newly allocated location description. Location |
2617 | descriptions are simple expression terms that can be strung | |
2618 | together to form more complicated location (address) descriptions. */ | |
2619 | ||
2620 | static inline dw_loc_descr_ref | |
2621 | new_loc_descr (op, oprnd1, oprnd2) | |
b3694847 SS |
2622 | enum dwarf_location_atom op; |
2623 | unsigned long oprnd1; | |
2624 | unsigned long oprnd2; | |
4b674448 | 2625 | { |
5de0e8d4 JM |
2626 | /* Use xcalloc here so we clear out all of the long_long constant in |
2627 | the union. */ | |
b3694847 | 2628 | dw_loc_descr_ref descr |
5de0e8d4 | 2629 | = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node)); |
71dfc51f | 2630 | |
7d9d8943 AM |
2631 | descr->dw_loc_opc = op; |
2632 | descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const; | |
2633 | descr->dw_loc_oprnd1.v.val_unsigned = oprnd1; | |
2634 | descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const; | |
2635 | descr->dw_loc_oprnd2.v.val_unsigned = oprnd2; | |
71dfc51f | 2636 | |
7d9d8943 AM |
2637 | return descr; |
2638 | } | |
2639 | ||
63e46568 | 2640 | |
7d9d8943 AM |
2641 | /* Add a location description term to a location description expression. */ |
2642 | ||
2643 | static inline void | |
2644 | add_loc_descr (list_head, descr) | |
b3694847 SS |
2645 | dw_loc_descr_ref *list_head; |
2646 | dw_loc_descr_ref descr; | |
7d9d8943 | 2647 | { |
b3694847 | 2648 | dw_loc_descr_ref *d; |
7d9d8943 AM |
2649 | |
2650 | /* Find the end of the chain. */ | |
2651 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
2652 | ; | |
2653 | ||
2654 | *d = descr; | |
2655 | } | |
2656 | ||
2657 | /* Return the size of a location descriptor. */ | |
2658 | ||
2659 | static unsigned long | |
2660 | size_of_loc_descr (loc) | |
b3694847 | 2661 | dw_loc_descr_ref loc; |
7d9d8943 | 2662 | { |
b3694847 | 2663 | unsigned long size = 1; |
7d9d8943 AM |
2664 | |
2665 | switch (loc->dw_loc_opc) | |
2666 | { | |
2667 | case DW_OP_addr: | |
2668 | size += DWARF2_ADDR_SIZE; | |
2669 | break; | |
2670 | case DW_OP_const1u: | |
2671 | case DW_OP_const1s: | |
2672 | size += 1; | |
2673 | break; | |
2674 | case DW_OP_const2u: | |
2675 | case DW_OP_const2s: | |
2676 | size += 2; | |
2677 | break; | |
2678 | case DW_OP_const4u: | |
2679 | case DW_OP_const4s: | |
2680 | size += 4; | |
2681 | break; | |
2682 | case DW_OP_const8u: | |
2683 | case DW_OP_const8s: | |
2684 | size += 8; | |
2685 | break; | |
2686 | case DW_OP_constu: | |
2687 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2688 | break; | |
2689 | case DW_OP_consts: | |
2690 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2691 | break; | |
2692 | case DW_OP_pick: | |
2693 | size += 1; | |
2694 | break; | |
2695 | case DW_OP_plus_uconst: | |
2696 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2697 | break; | |
2698 | case DW_OP_skip: | |
2699 | case DW_OP_bra: | |
2700 | size += 2; | |
2701 | break; | |
2702 | case DW_OP_breg0: | |
2703 | case DW_OP_breg1: | |
2704 | case DW_OP_breg2: | |
2705 | case DW_OP_breg3: | |
2706 | case DW_OP_breg4: | |
2707 | case DW_OP_breg5: | |
2708 | case DW_OP_breg6: | |
2709 | case DW_OP_breg7: | |
2710 | case DW_OP_breg8: | |
2711 | case DW_OP_breg9: | |
2712 | case DW_OP_breg10: | |
2713 | case DW_OP_breg11: | |
2714 | case DW_OP_breg12: | |
2715 | case DW_OP_breg13: | |
2716 | case DW_OP_breg14: | |
2717 | case DW_OP_breg15: | |
2718 | case DW_OP_breg16: | |
2719 | case DW_OP_breg17: | |
2720 | case DW_OP_breg18: | |
2721 | case DW_OP_breg19: | |
2722 | case DW_OP_breg20: | |
2723 | case DW_OP_breg21: | |
2724 | case DW_OP_breg22: | |
2725 | case DW_OP_breg23: | |
2726 | case DW_OP_breg24: | |
2727 | case DW_OP_breg25: | |
2728 | case DW_OP_breg26: | |
2729 | case DW_OP_breg27: | |
2730 | case DW_OP_breg28: | |
2731 | case DW_OP_breg29: | |
2732 | case DW_OP_breg30: | |
2733 | case DW_OP_breg31: | |
2734 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2735 | break; | |
2736 | case DW_OP_regx: | |
2737 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2738 | break; | |
2739 | case DW_OP_fbreg: | |
2740 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2741 | break; | |
2742 | case DW_OP_bregx: | |
2743 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2744 | size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int); | |
2745 | break; | |
2746 | case DW_OP_piece: | |
2747 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2748 | break; | |
2749 | case DW_OP_deref_size: | |
2750 | case DW_OP_xderef_size: | |
2751 | size += 1; | |
2752 | break; | |
3f76745e | 2753 | default: |
7d9d8943 | 2754 | break; |
4b674448 | 2755 | } |
7d9d8943 AM |
2756 | |
2757 | return size; | |
4b674448 JM |
2758 | } |
2759 | ||
7d9d8943 | 2760 | /* Return the size of a series of location descriptors. */ |
71dfc51f | 2761 | |
7d9d8943 AM |
2762 | static unsigned long |
2763 | size_of_locs (loc) | |
b3694847 | 2764 | dw_loc_descr_ref loc; |
4b674448 | 2765 | { |
2ad9852d | 2766 | unsigned long size; |
7d9d8943 | 2767 | |
2ad9852d | 2768 | for (size = 0; loc != NULL; loc = loc->dw_loc_next) |
d8041cc8 RH |
2769 | { |
2770 | loc->dw_loc_addr = size; | |
2771 | size += size_of_loc_descr (loc); | |
2772 | } | |
7d9d8943 AM |
2773 | |
2774 | return size; | |
4b674448 JM |
2775 | } |
2776 | ||
7d9d8943 | 2777 | /* Output location description stack opcode's operands (if any). */ |
71dfc51f | 2778 | |
7d9d8943 AM |
2779 | static void |
2780 | output_loc_operands (loc) | |
b3694847 | 2781 | dw_loc_descr_ref loc; |
a3f97cbb | 2782 | { |
b3694847 SS |
2783 | dw_val_ref val1 = &loc->dw_loc_oprnd1; |
2784 | dw_val_ref val2 = &loc->dw_loc_oprnd2; | |
7d9d8943 AM |
2785 | |
2786 | switch (loc->dw_loc_opc) | |
a3f97cbb | 2787 | { |
0517872a | 2788 | #ifdef DWARF2_DEBUGGING_INFO |
3f76745e | 2789 | case DW_OP_addr: |
2e4b9b8c | 2790 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL); |
7d9d8943 | 2791 | break; |
3f76745e | 2792 | case DW_OP_const2u: |
3f76745e | 2793 | case DW_OP_const2s: |
2e4b9b8c | 2794 | dw2_asm_output_data (2, val1->v.val_int, NULL); |
7d9d8943 | 2795 | break; |
3f76745e | 2796 | case DW_OP_const4u: |
3f76745e | 2797 | case DW_OP_const4s: |
2e4b9b8c | 2798 | dw2_asm_output_data (4, val1->v.val_int, NULL); |
7d9d8943 | 2799 | break; |
3f76745e | 2800 | case DW_OP_const8u: |
3f76745e | 2801 | case DW_OP_const8s: |
2e4b9b8c RH |
2802 | if (HOST_BITS_PER_LONG < 64) |
2803 | abort (); | |
2804 | dw2_asm_output_data (8, val1->v.val_int, NULL); | |
7d9d8943 | 2805 | break; |
0517872a JM |
2806 | case DW_OP_skip: |
2807 | case DW_OP_bra: | |
d8041cc8 RH |
2808 | { |
2809 | int offset; | |
2810 | ||
2811 | if (val1->val_class == dw_val_class_loc) | |
2812 | offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3); | |
2813 | else | |
2814 | abort (); | |
2815 | ||
2e4b9b8c | 2816 | dw2_asm_output_data (2, offset, NULL); |
d8041cc8 | 2817 | } |
0517872a | 2818 | break; |
3139472f JM |
2819 | #else |
2820 | case DW_OP_addr: | |
2821 | case DW_OP_const2u: | |
2822 | case DW_OP_const2s: | |
2823 | case DW_OP_const4u: | |
2824 | case DW_OP_const4s: | |
2825 | case DW_OP_const8u: | |
2826 | case DW_OP_const8s: | |
2827 | case DW_OP_skip: | |
2828 | case DW_OP_bra: | |
2829 | /* We currently don't make any attempt to make sure these are | |
2830 | aligned properly like we do for the main unwind info, so | |
2831 | don't support emitting things larger than a byte if we're | |
2832 | only doing unwinding. */ | |
2833 | abort (); | |
0517872a JM |
2834 | #endif |
2835 | case DW_OP_const1u: | |
2836 | case DW_OP_const1s: | |
2e4b9b8c | 2837 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
0517872a | 2838 | break; |
3f76745e | 2839 | case DW_OP_constu: |
2e4b9b8c | 2840 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2841 | break; |
3f76745e | 2842 | case DW_OP_consts: |
2e4b9b8c | 2843 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 AM |
2844 | break; |
2845 | case DW_OP_pick: | |
2e4b9b8c | 2846 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 AM |
2847 | break; |
2848 | case DW_OP_plus_uconst: | |
2e4b9b8c | 2849 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2850 | break; |
3f76745e | 2851 | case DW_OP_breg0: |
3f76745e | 2852 | case DW_OP_breg1: |
3f76745e | 2853 | case DW_OP_breg2: |
3f76745e | 2854 | case DW_OP_breg3: |
3f76745e | 2855 | case DW_OP_breg4: |
3f76745e | 2856 | case DW_OP_breg5: |
3f76745e | 2857 | case DW_OP_breg6: |
3f76745e | 2858 | case DW_OP_breg7: |
3f76745e | 2859 | case DW_OP_breg8: |
3f76745e | 2860 | case DW_OP_breg9: |
3f76745e | 2861 | case DW_OP_breg10: |
3f76745e | 2862 | case DW_OP_breg11: |
3f76745e | 2863 | case DW_OP_breg12: |
3f76745e | 2864 | case DW_OP_breg13: |
3f76745e | 2865 | case DW_OP_breg14: |
3f76745e | 2866 | case DW_OP_breg15: |
3f76745e | 2867 | case DW_OP_breg16: |
3f76745e | 2868 | case DW_OP_breg17: |
3f76745e | 2869 | case DW_OP_breg18: |
3f76745e | 2870 | case DW_OP_breg19: |
3f76745e | 2871 | case DW_OP_breg20: |
3f76745e | 2872 | case DW_OP_breg21: |
3f76745e | 2873 | case DW_OP_breg22: |
3f76745e | 2874 | case DW_OP_breg23: |
3f76745e | 2875 | case DW_OP_breg24: |
3f76745e | 2876 | case DW_OP_breg25: |
3f76745e | 2877 | case DW_OP_breg26: |
3f76745e | 2878 | case DW_OP_breg27: |
3f76745e | 2879 | case DW_OP_breg28: |
3f76745e | 2880 | case DW_OP_breg29: |
3f76745e | 2881 | case DW_OP_breg30: |
3f76745e | 2882 | case DW_OP_breg31: |
2e4b9b8c | 2883 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 2884 | break; |
3f76745e | 2885 | case DW_OP_regx: |
2e4b9b8c | 2886 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2887 | break; |
3f76745e | 2888 | case DW_OP_fbreg: |
2e4b9b8c | 2889 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 2890 | break; |
3f76745e | 2891 | case DW_OP_bregx: |
2e4b9b8c RH |
2892 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
2893 | dw2_asm_output_data_sleb128 (val2->v.val_int, NULL); | |
7d9d8943 | 2894 | break; |
3f76745e | 2895 | case DW_OP_piece: |
2e4b9b8c | 2896 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2897 | break; |
3f76745e | 2898 | case DW_OP_deref_size: |
3f76745e | 2899 | case DW_OP_xderef_size: |
2e4b9b8c | 2900 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 AM |
2901 | break; |
2902 | default: | |
3139472f JM |
2903 | /* Other codes have no operands. */ |
2904 | break; | |
7d9d8943 AM |
2905 | } |
2906 | } | |
2907 | ||
2908 | /* Output a sequence of location operations. */ | |
2909 | ||
2910 | static void | |
2911 | output_loc_sequence (loc) | |
2912 | dw_loc_descr_ref loc; | |
2913 | { | |
2914 | for (; loc != NULL; loc = loc->dw_loc_next) | |
2915 | { | |
2916 | /* Output the opcode. */ | |
2e4b9b8c RH |
2917 | dw2_asm_output_data (1, loc->dw_loc_opc, |
2918 | "%s", dwarf_stack_op_name (loc->dw_loc_opc)); | |
7d9d8943 AM |
2919 | |
2920 | /* Output the operand(s) (if any). */ | |
2921 | output_loc_operands (loc); | |
2922 | } | |
2923 | } | |
2924 | ||
2925 | /* This routine will generate the correct assembly data for a location | |
2926 | description based on a cfi entry with a complex address. */ | |
2927 | ||
2928 | static void | |
2929 | output_cfa_loc (cfi) | |
2930 | dw_cfi_ref cfi; | |
2931 | { | |
2932 | dw_loc_descr_ref loc; | |
2933 | unsigned long size; | |
2934 | ||
2935 | /* Output the size of the block. */ | |
2936 | loc = cfi->dw_cfi_oprnd1.dw_cfi_loc; | |
2937 | size = size_of_locs (loc); | |
2e4b9b8c | 2938 | dw2_asm_output_data_uleb128 (size, NULL); |
7d9d8943 AM |
2939 | |
2940 | /* Now output the operations themselves. */ | |
2941 | output_loc_sequence (loc); | |
2942 | } | |
2943 | ||
dd49a9ec | 2944 | /* This function builds a dwarf location descriptor sequence from |
556273e0 | 2945 | a dw_cfa_location. */ |
7d9d8943 AM |
2946 | |
2947 | static struct dw_loc_descr_struct * | |
2948 | build_cfa_loc (cfa) | |
2949 | dw_cfa_location *cfa; | |
2950 | { | |
2951 | struct dw_loc_descr_struct *head, *tmp; | |
2952 | ||
2953 | if (cfa->indirect == 0) | |
2954 | abort (); | |
2955 | ||
2956 | if (cfa->base_offset) | |
f299afab HPN |
2957 | { |
2958 | if (cfa->reg <= 31) | |
2959 | head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0); | |
2960 | else | |
2961 | head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset); | |
2962 | } | |
2963 | else if (cfa->reg <= 31) | |
7d9d8943 | 2964 | head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0); |
f299afab HPN |
2965 | else |
2966 | head = new_loc_descr (DW_OP_regx, cfa->reg, 0); | |
2ad9852d | 2967 | |
7d9d8943 AM |
2968 | head->dw_loc_oprnd1.val_class = dw_val_class_const; |
2969 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
2970 | add_loc_descr (&head, tmp); | |
2971 | if (cfa->offset != 0) | |
2972 | { | |
2973 | tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0); | |
2974 | add_loc_descr (&head, tmp); | |
2975 | } | |
2ad9852d | 2976 | |
7d9d8943 AM |
2977 | return head; |
2978 | } | |
2979 | ||
2ad9852d RK |
2980 | /* This function fills in aa dw_cfa_location structure from a dwarf location |
2981 | descriptor sequence. */ | |
7d9d8943 AM |
2982 | |
2983 | static void | |
2984 | get_cfa_from_loc_descr (cfa, loc) | |
2985 | dw_cfa_location *cfa; | |
556273e0 | 2986 | struct dw_loc_descr_struct *loc; |
7d9d8943 | 2987 | { |
556273e0 | 2988 | struct dw_loc_descr_struct *ptr; |
7d9d8943 AM |
2989 | cfa->offset = 0; |
2990 | cfa->base_offset = 0; | |
2991 | cfa->indirect = 0; | |
2992 | cfa->reg = -1; | |
2993 | ||
2994 | for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next) | |
2995 | { | |
2996 | enum dwarf_location_atom op = ptr->dw_loc_opc; | |
2ad9852d | 2997 | |
7d9d8943 | 2998 | switch (op) |
556273e0 | 2999 | { |
7d9d8943 AM |
3000 | case DW_OP_reg0: |
3001 | case DW_OP_reg1: | |
3002 | case DW_OP_reg2: | |
3003 | case DW_OP_reg3: | |
3004 | case DW_OP_reg4: | |
3005 | case DW_OP_reg5: | |
3006 | case DW_OP_reg6: | |
3007 | case DW_OP_reg7: | |
3008 | case DW_OP_reg8: | |
3009 | case DW_OP_reg9: | |
3010 | case DW_OP_reg10: | |
3011 | case DW_OP_reg11: | |
3012 | case DW_OP_reg12: | |
3013 | case DW_OP_reg13: | |
3014 | case DW_OP_reg14: | |
3015 | case DW_OP_reg15: | |
3016 | case DW_OP_reg16: | |
3017 | case DW_OP_reg17: | |
3018 | case DW_OP_reg18: | |
3019 | case DW_OP_reg19: | |
3020 | case DW_OP_reg20: | |
3021 | case DW_OP_reg21: | |
3022 | case DW_OP_reg22: | |
3023 | case DW_OP_reg23: | |
3024 | case DW_OP_reg24: | |
3025 | case DW_OP_reg25: | |
3026 | case DW_OP_reg26: | |
3027 | case DW_OP_reg27: | |
3028 | case DW_OP_reg28: | |
3029 | case DW_OP_reg29: | |
3030 | case DW_OP_reg30: | |
3031 | case DW_OP_reg31: | |
3032 | cfa->reg = op - DW_OP_reg0; | |
3033 | break; | |
3034 | case DW_OP_regx: | |
3035 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
3036 | break; | |
3037 | case DW_OP_breg0: | |
3038 | case DW_OP_breg1: | |
3039 | case DW_OP_breg2: | |
3040 | case DW_OP_breg3: | |
3041 | case DW_OP_breg4: | |
3042 | case DW_OP_breg5: | |
3043 | case DW_OP_breg6: | |
3044 | case DW_OP_breg7: | |
3045 | case DW_OP_breg8: | |
3046 | case DW_OP_breg9: | |
3047 | case DW_OP_breg10: | |
3048 | case DW_OP_breg11: | |
3049 | case DW_OP_breg12: | |
3050 | case DW_OP_breg13: | |
3051 | case DW_OP_breg14: | |
3052 | case DW_OP_breg15: | |
3053 | case DW_OP_breg16: | |
3054 | case DW_OP_breg17: | |
3055 | case DW_OP_breg18: | |
3056 | case DW_OP_breg19: | |
3057 | case DW_OP_breg20: | |
3058 | case DW_OP_breg21: | |
3059 | case DW_OP_breg22: | |
3060 | case DW_OP_breg23: | |
3061 | case DW_OP_breg24: | |
3062 | case DW_OP_breg25: | |
3063 | case DW_OP_breg26: | |
3064 | case DW_OP_breg27: | |
3065 | case DW_OP_breg28: | |
3066 | case DW_OP_breg29: | |
3067 | case DW_OP_breg30: | |
3068 | case DW_OP_breg31: | |
3069 | cfa->reg = op - DW_OP_breg0; | |
3070 | cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int; | |
3071 | break; | |
3072 | case DW_OP_bregx: | |
3073 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
3074 | cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int; | |
3075 | break; | |
3076 | case DW_OP_deref: | |
3077 | cfa->indirect = 1; | |
3078 | break; | |
3079 | case DW_OP_plus_uconst: | |
556273e0 | 3080 | cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned; |
7d9d8943 AM |
3081 | break; |
3082 | default: | |
a1f300c0 | 3083 | internal_error ("DW_LOC_OP %s not implemented\n", |
400500c4 | 3084 | dwarf_stack_op_name (ptr->dw_loc_opc)); |
7d9d8943 AM |
3085 | } |
3086 | } | |
3087 | } | |
3088 | #endif /* .debug_frame support */ | |
3089 | \f | |
3090 | /* And now, the support for symbolic debugging information. */ | |
3091 | #ifdef DWARF2_DEBUGGING_INFO | |
3092 | ||
117f9d28 GS |
3093 | /* .debug_str support. */ |
3094 | static hashnode indirect_string_alloc PARAMS ((hash_table *)); | |
3095 | static int output_indirect_string PARAMS ((struct cpp_reader *, | |
3096 | hashnode, const PTR)); | |
3097 | ||
3098 | ||
e2a12aca NB |
3099 | static void dwarf2out_init PARAMS ((const char *)); |
3100 | static void dwarf2out_finish PARAMS ((const char *)); | |
7f905405 NB |
3101 | static void dwarf2out_define PARAMS ((unsigned int, const char *)); |
3102 | static void dwarf2out_undef PARAMS ((unsigned int, const char *)); | |
3103 | static void dwarf2out_start_source_file PARAMS ((unsigned, const char *)); | |
3104 | static void dwarf2out_end_source_file PARAMS ((unsigned)); | |
e2a12aca NB |
3105 | static void dwarf2out_begin_block PARAMS ((unsigned, unsigned)); |
3106 | static void dwarf2out_end_block PARAMS ((unsigned, unsigned)); | |
e1772ac0 | 3107 | static bool dwarf2out_ignore_block PARAMS ((tree)); |
2b85879e | 3108 | static void dwarf2out_global_decl PARAMS ((tree)); |
e1772ac0 | 3109 | static void dwarf2out_abstract_function PARAMS ((tree)); |
7f905405 NB |
3110 | |
3111 | /* The debug hooks structure. */ | |
3112 | ||
54b6670a | 3113 | const struct gcc_debug_hooks dwarf2_debug_hooks = |
7f905405 NB |
3114 | { |
3115 | dwarf2out_init, | |
3116 | dwarf2out_finish, | |
3117 | dwarf2out_define, | |
3118 | dwarf2out_undef, | |
3119 | dwarf2out_start_source_file, | |
a5a42b92 NB |
3120 | dwarf2out_end_source_file, |
3121 | dwarf2out_begin_block, | |
e2a12aca | 3122 | dwarf2out_end_block, |
e1772ac0 | 3123 | dwarf2out_ignore_block, |
e2a12aca | 3124 | dwarf2out_source_line, |
653e276c NB |
3125 | dwarf2out_begin_prologue, |
3126 | debug_nothing_int, /* end_prologue */ | |
e2a12aca | 3127 | dwarf2out_end_epilogue, |
653e276c | 3128 | debug_nothing_tree, /* begin_function */ |
2b85879e NB |
3129 | debug_nothing_int, /* end_function */ |
3130 | dwarf2out_decl, /* function_decl */ | |
3131 | dwarf2out_global_decl, | |
e1772ac0 NB |
3132 | debug_nothing_tree, /* deferred_inline_function */ |
3133 | /* The DWARF 2 backend tries to reduce debugging bloat by not | |
3134 | emitting the abstract description of inline functions until | |
3135 | something tries to reference them. */ | |
3136 | dwarf2out_abstract_function, /* outlining_inline_function */ | |
3137 | debug_nothing_rtx /* label */ | |
7f905405 NB |
3138 | }; |
3139 | \f | |
7d9d8943 AM |
3140 | /* NOTE: In the comments in this file, many references are made to |
3141 | "Debugging Information Entries". This term is abbreviated as `DIE' | |
3142 | throughout the remainder of this file. */ | |
3143 | ||
3144 | /* An internal representation of the DWARF output is built, and then | |
3145 | walked to generate the DWARF debugging info. The walk of the internal | |
3146 | representation is done after the entire program has been compiled. | |
3147 | The types below are used to describe the internal representation. */ | |
3148 | ||
3149 | /* Various DIE's use offsets relative to the beginning of the | |
3150 | .debug_info section to refer to each other. */ | |
3151 | ||
3152 | typedef long int dw_offset; | |
3153 | ||
3154 | /* Define typedefs here to avoid circular dependencies. */ | |
3155 | ||
3156 | typedef struct dw_attr_struct *dw_attr_ref; | |
3157 | typedef struct dw_line_info_struct *dw_line_info_ref; | |
3158 | typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref; | |
3159 | typedef struct pubname_struct *pubname_ref; | |
a20612aa | 3160 | typedef struct dw_ranges_struct *dw_ranges_ref; |
7d9d8943 AM |
3161 | |
3162 | /* Each entry in the line_info_table maintains the file and | |
3163 | line number associated with the label generated for that | |
3164 | entry. The label gives the PC value associated with | |
3165 | the line number entry. */ | |
3166 | ||
3167 | typedef struct dw_line_info_struct | |
3168 | { | |
3169 | unsigned long dw_file_num; | |
3170 | unsigned long dw_line_num; | |
3171 | } | |
3172 | dw_line_info_entry; | |
3173 | ||
3174 | /* Line information for functions in separate sections; each one gets its | |
3175 | own sequence. */ | |
3176 | typedef struct dw_separate_line_info_struct | |
3177 | { | |
3178 | unsigned long dw_file_num; | |
3179 | unsigned long dw_line_num; | |
3180 | unsigned long function; | |
3181 | } | |
3182 | dw_separate_line_info_entry; | |
3183 | ||
3184 | /* Each DIE attribute has a field specifying the attribute kind, | |
3185 | a link to the next attribute in the chain, and an attribute value. | |
3186 | Attributes are typically linked below the DIE they modify. */ | |
3187 | ||
3188 | typedef struct dw_attr_struct | |
3189 | { | |
3190 | enum dwarf_attribute dw_attr; | |
3191 | dw_attr_ref dw_attr_next; | |
3192 | dw_val_node dw_attr_val; | |
3193 | } | |
3194 | dw_attr_node; | |
3195 | ||
3196 | /* The Debugging Information Entry (DIE) structure */ | |
3197 | ||
3198 | typedef struct die_struct | |
3199 | { | |
3200 | enum dwarf_tag die_tag; | |
881c6935 | 3201 | char *die_symbol; |
7d9d8943 AM |
3202 | dw_attr_ref die_attr; |
3203 | dw_die_ref die_parent; | |
3204 | dw_die_ref die_child; | |
3205 | dw_die_ref die_sib; | |
3206 | dw_offset die_offset; | |
3207 | unsigned long die_abbrev; | |
1bfb5f8f | 3208 | int die_mark; |
7d9d8943 AM |
3209 | } |
3210 | die_node; | |
3211 | ||
3212 | /* The pubname structure */ | |
3213 | ||
3214 | typedef struct pubname_struct | |
3215 | { | |
3216 | dw_die_ref die; | |
556273e0 | 3217 | char *name; |
7d9d8943 AM |
3218 | } |
3219 | pubname_entry; | |
3220 | ||
a20612aa RH |
3221 | struct dw_ranges_struct |
3222 | { | |
3223 | int block_num; | |
3224 | }; | |
3225 | ||
7d9d8943 AM |
3226 | /* The limbo die list structure. */ |
3227 | typedef struct limbo_die_struct | |
3228 | { | |
3229 | dw_die_ref die; | |
54ba1f0d | 3230 | tree created_for; |
7d9d8943 AM |
3231 | struct limbo_die_struct *next; |
3232 | } | |
3233 | limbo_die_node; | |
3234 | ||
3235 | /* How to start an assembler comment. */ | |
3236 | #ifndef ASM_COMMENT_START | |
3237 | #define ASM_COMMENT_START ";#" | |
3238 | #endif | |
3239 | ||
3240 | /* Define a macro which returns non-zero for a TYPE_DECL which was | |
3241 | implicitly generated for a tagged type. | |
3242 | ||
3243 | Note that unlike the gcc front end (which generates a NULL named | |
3244 | TYPE_DECL node for each complete tagged type, each array type, and | |
3245 | each function type node created) the g++ front end generates a | |
3246 | _named_ TYPE_DECL node for each tagged type node created. | |
3247 | These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to | |
3248 | generate a DW_TAG_typedef DIE for them. */ | |
3249 | ||
3250 | #define TYPE_DECL_IS_STUB(decl) \ | |
3251 | (DECL_NAME (decl) == NULL_TREE \ | |
3252 | || (DECL_ARTIFICIAL (decl) \ | |
3253 | && is_tagged_type (TREE_TYPE (decl)) \ | |
3254 | && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \ | |
3255 | /* This is necessary for stub decls that \ | |
3256 | appear in nested inline functions. */ \ | |
3257 | || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \ | |
3258 | && (decl_ultimate_origin (decl) \ | |
3259 | == TYPE_STUB_DECL (TREE_TYPE (decl))))))) | |
3260 | ||
3261 | /* Information concerning the compilation unit's programming | |
3262 | language, and compiler version. */ | |
3263 | ||
7d9d8943 AM |
3264 | /* Fixed size portion of the DWARF compilation unit header. */ |
3265 | #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3) | |
3266 | ||
3267 | /* Fixed size portion of debugging line information prolog. */ | |
3268 | #define DWARF_LINE_PROLOG_HEADER_SIZE 5 | |
3269 | ||
3270 | /* Fixed size portion of public names info. */ | |
3271 | #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2) | |
3272 | ||
3273 | /* Fixed size portion of the address range info. */ | |
3274 | #define DWARF_ARANGES_HEADER_SIZE \ | |
3275 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ | |
3276 | - DWARF_OFFSET_SIZE) | |
3277 | ||
3278 | /* Size of padding portion in the address range info. It must be | |
3279 | aligned to twice the pointer size. */ | |
3280 | #define DWARF_ARANGES_PAD_SIZE \ | |
3281 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ | |
3282 | - (2 * DWARF_OFFSET_SIZE + 4)) | |
3283 | ||
9d147085 | 3284 | /* Use assembler line directives if available. */ |
7d9d8943 | 3285 | #ifndef DWARF2_ASM_LINE_DEBUG_INFO |
9d147085 RH |
3286 | #ifdef HAVE_AS_DWARF2_DEBUG_LINE |
3287 | #define DWARF2_ASM_LINE_DEBUG_INFO 1 | |
3288 | #else | |
7d9d8943 AM |
3289 | #define DWARF2_ASM_LINE_DEBUG_INFO 0 |
3290 | #endif | |
9d147085 | 3291 | #endif |
7d9d8943 | 3292 | |
7d9d8943 AM |
3293 | /* Minimum line offset in a special line info. opcode. |
3294 | This value was chosen to give a reasonable range of values. */ | |
3295 | #define DWARF_LINE_BASE -10 | |
3296 | ||
a1f300c0 | 3297 | /* First special line opcode - leave room for the standard opcodes. */ |
7d9d8943 AM |
3298 | #define DWARF_LINE_OPCODE_BASE 10 |
3299 | ||
3300 | /* Range of line offsets in a special line info. opcode. */ | |
3301 | #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1) | |
3302 | ||
3303 | /* Flag that indicates the initial value of the is_stmt_start flag. | |
3304 | In the present implementation, we do not mark any lines as | |
3305 | the beginning of a source statement, because that information | |
3306 | is not made available by the GCC front-end. */ | |
3307 | #define DWARF_LINE_DEFAULT_IS_STMT_START 1 | |
3308 | ||
3309 | /* This location is used by calc_die_sizes() to keep track | |
3310 | the offset of each DIE within the .debug_info section. */ | |
3311 | static unsigned long next_die_offset; | |
3312 | ||
3313 | /* Record the root of the DIE's built for the current compilation unit. */ | |
3314 | static dw_die_ref comp_unit_die; | |
3315 | ||
3316 | /* A list of DIEs with a NULL parent waiting to be relocated. */ | |
3317 | static limbo_die_node *limbo_die_list = 0; | |
3318 | ||
2e18bbae RH |
3319 | /* Structure used by lookup_filename to manage sets of filenames. */ |
3320 | struct file_table | |
3321 | { | |
3322 | char **table; | |
3323 | unsigned allocated; | |
3324 | unsigned in_use; | |
3325 | unsigned last_lookup_index; | |
3326 | }; | |
7d9d8943 AM |
3327 | |
3328 | /* Size (in elements) of increments by which we may expand the filename | |
3329 | table. */ | |
3330 | #define FILE_TABLE_INCREMENT 64 | |
3331 | ||
981975b6 RH |
3332 | /* Filenames referenced by this compilation unit. */ |
3333 | static struct file_table file_table; | |
2e18bbae | 3334 | |
7d9d8943 AM |
3335 | /* Local pointer to the name of the main input file. Initialized in |
3336 | dwarf2out_init. */ | |
3337 | static const char *primary_filename; | |
3338 | ||
3339 | /* A pointer to the base of a table of references to DIE's that describe | |
3340 | declarations. The table is indexed by DECL_UID() which is a unique | |
3341 | number identifying each decl. */ | |
3342 | static dw_die_ref *decl_die_table; | |
3343 | ||
3344 | /* Number of elements currently allocated for the decl_die_table. */ | |
3345 | static unsigned decl_die_table_allocated; | |
3346 | ||
3347 | /* Number of elements in decl_die_table currently in use. */ | |
3348 | static unsigned decl_die_table_in_use; | |
3349 | ||
3350 | /* Size (in elements) of increments by which we may expand the | |
3351 | decl_die_table. */ | |
3352 | #define DECL_DIE_TABLE_INCREMENT 256 | |
3353 | ||
3354 | /* A pointer to the base of a table of references to declaration | |
3355 | scopes. This table is a display which tracks the nesting | |
3356 | of declaration scopes at the current scope and containing | |
3357 | scopes. This table is used to find the proper place to | |
3358 | define type declaration DIE's. */ | |
244a4af0 | 3359 | varray_type decl_scope_table; |
7d9d8943 AM |
3360 | |
3361 | /* A pointer to the base of a list of references to DIE's that | |
3362 | are uniquely identified by their tag, presence/absence of | |
3363 | children DIE's, and list of attribute/value pairs. */ | |
3364 | static dw_die_ref *abbrev_die_table; | |
3365 | ||
3366 | /* Number of elements currently allocated for abbrev_die_table. */ | |
3367 | static unsigned abbrev_die_table_allocated; | |
3368 | ||
3369 | /* Number of elements in type_die_table currently in use. */ | |
3370 | static unsigned abbrev_die_table_in_use; | |
3371 | ||
3372 | /* Size (in elements) of increments by which we may expand the | |
3373 | abbrev_die_table. */ | |
3374 | #define ABBREV_DIE_TABLE_INCREMENT 256 | |
3375 | ||
3376 | /* A pointer to the base of a table that contains line information | |
3377 | for each source code line in .text in the compilation unit. */ | |
3378 | static dw_line_info_ref line_info_table; | |
3379 | ||
3380 | /* Number of elements currently allocated for line_info_table. */ | |
3381 | static unsigned line_info_table_allocated; | |
3382 | ||
3383 | /* Number of elements in separate_line_info_table currently in use. */ | |
3384 | static unsigned separate_line_info_table_in_use; | |
3385 | ||
3386 | /* A pointer to the base of a table that contains line information | |
3387 | for each source code line outside of .text in the compilation unit. */ | |
3388 | static dw_separate_line_info_ref separate_line_info_table; | |
3389 | ||
3390 | /* Number of elements currently allocated for separate_line_info_table. */ | |
3391 | static unsigned separate_line_info_table_allocated; | |
3392 | ||
3393 | /* Number of elements in line_info_table currently in use. */ | |
3394 | static unsigned line_info_table_in_use; | |
3395 | ||
3396 | /* Size (in elements) of increments by which we may expand the | |
3397 | line_info_table. */ | |
3398 | #define LINE_INFO_TABLE_INCREMENT 1024 | |
3399 | ||
3400 | /* A pointer to the base of a table that contains a list of publicly | |
3401 | accessible names. */ | |
3402 | static pubname_ref pubname_table; | |
3403 | ||
3404 | /* Number of elements currently allocated for pubname_table. */ | |
3405 | static unsigned pubname_table_allocated; | |
3406 | ||
3407 | /* Number of elements in pubname_table currently in use. */ | |
3408 | static unsigned pubname_table_in_use; | |
3409 | ||
3410 | /* Size (in elements) of increments by which we may expand the | |
3411 | pubname_table. */ | |
3412 | #define PUBNAME_TABLE_INCREMENT 64 | |
3413 | ||
a20612aa RH |
3414 | /* Array of dies for which we should generate .debug_arange info. */ |
3415 | static dw_die_ref *arange_table; | |
7d9d8943 AM |
3416 | |
3417 | /* Number of elements currently allocated for arange_table. */ | |
3418 | static unsigned arange_table_allocated; | |
3419 | ||
3420 | /* Number of elements in arange_table currently in use. */ | |
3421 | static unsigned arange_table_in_use; | |
3422 | ||
3423 | /* Size (in elements) of increments by which we may expand the | |
3424 | arange_table. */ | |
3425 | #define ARANGE_TABLE_INCREMENT 64 | |
3426 | ||
a20612aa RH |
3427 | /* Array of dies for which we should generate .debug_ranges info. */ |
3428 | static dw_ranges_ref ranges_table; | |
3429 | ||
3430 | /* Number of elements currently allocated for ranges_table. */ | |
3431 | static unsigned ranges_table_allocated; | |
3432 | ||
3433 | /* Number of elements in ranges_table currently in use. */ | |
3434 | static unsigned ranges_table_in_use; | |
3435 | ||
3436 | /* Size (in elements) of increments by which we may expand the | |
3437 | ranges_table. */ | |
3438 | #define RANGES_TABLE_INCREMENT 64 | |
3439 | ||
63e46568 DB |
3440 | /* Whether we have location lists that need outputting */ |
3441 | static unsigned have_location_lists; | |
3442 | ||
7d9d8943 | 3443 | /* A pointer to the base of a list of incomplete types which might be |
244a4af0 | 3444 | completed at some later time. incomplete_types_list needs to be a VARRAY |
2ad9852d | 3445 | because we want to tell the garbage collector about it. */ |
244a4af0 | 3446 | varray_type incomplete_types; |
7d9d8943 AM |
3447 | |
3448 | /* Record whether the function being analyzed contains inlined functions. */ | |
3449 | static int current_function_has_inlines; | |
3450 | #if 0 && defined (MIPS_DEBUGGING_INFO) | |
3451 | static int comp_unit_has_inlines; | |
3452 | #endif | |
3453 | ||
3454 | /* Array of RTXes referenced by the debugging information, which therefore | |
c470afad | 3455 | must be kept around forever. This is a GC root. */ |
7d9d8943 AM |
3456 | static varray_type used_rtx_varray; |
3457 | ||
3458 | /* Forward declarations for functions defined in this file. */ | |
3459 | ||
3460 | static int is_pseudo_reg PARAMS ((rtx)); | |
3461 | static tree type_main_variant PARAMS ((tree)); | |
3462 | static int is_tagged_type PARAMS ((tree)); | |
3463 | static const char *dwarf_tag_name PARAMS ((unsigned)); | |
3464 | static const char *dwarf_attr_name PARAMS ((unsigned)); | |
3465 | static const char *dwarf_form_name PARAMS ((unsigned)); | |
3466 | #if 0 | |
3467 | static const char *dwarf_type_encoding_name PARAMS ((unsigned)); | |
3468 | #endif | |
3469 | static tree decl_ultimate_origin PARAMS ((tree)); | |
3470 | static tree block_ultimate_origin PARAMS ((tree)); | |
3471 | static tree decl_class_context PARAMS ((tree)); | |
3472 | static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref)); | |
2ad9852d | 3473 | static inline dw_val_class AT_class PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3474 | static void add_AT_flag PARAMS ((dw_die_ref, |
3475 | enum dwarf_attribute, | |
3476 | unsigned)); | |
2ad9852d | 3477 | static inline unsigned AT_flag PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3478 | static void add_AT_int PARAMS ((dw_die_ref, |
3479 | enum dwarf_attribute, long)); | |
2ad9852d | 3480 | static inline long int AT_int PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3481 | static void add_AT_unsigned PARAMS ((dw_die_ref, |
3482 | enum dwarf_attribute, | |
3483 | unsigned long)); | |
2ad9852d | 3484 | static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3485 | static void add_AT_long_long PARAMS ((dw_die_ref, |
3486 | enum dwarf_attribute, | |
3487 | unsigned long, | |
3488 | unsigned long)); | |
3489 | static void add_AT_float PARAMS ((dw_die_ref, | |
3490 | enum dwarf_attribute, | |
3491 | unsigned, long *)); | |
3492 | static void add_AT_string PARAMS ((dw_die_ref, | |
3493 | enum dwarf_attribute, | |
3494 | const char *)); | |
2ad9852d RK |
3495 | static inline const char *AT_string PARAMS ((dw_attr_ref)); |
3496 | static int AT_string_form PARAMS ((dw_attr_ref)); | |
7d9d8943 AM |
3497 | static void add_AT_die_ref PARAMS ((dw_die_ref, |
3498 | enum dwarf_attribute, | |
3499 | dw_die_ref)); | |
2ad9852d RK |
3500 | static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref)); |
3501 | static inline int AT_ref_external PARAMS ((dw_attr_ref)); | |
3502 | static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int)); | |
7d9d8943 AM |
3503 | static void add_AT_fde_ref PARAMS ((dw_die_ref, |
3504 | enum dwarf_attribute, | |
3505 | unsigned)); | |
3506 | static void add_AT_loc PARAMS ((dw_die_ref, | |
3507 | enum dwarf_attribute, | |
3508 | dw_loc_descr_ref)); | |
2ad9852d | 3509 | static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref)); |
63e46568 DB |
3510 | static void add_AT_loc_list PARAMS ((dw_die_ref, |
3511 | enum dwarf_attribute, | |
3512 | dw_loc_list_ref)); | |
2ad9852d | 3513 | static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3514 | static void add_AT_addr PARAMS ((dw_die_ref, |
3515 | enum dwarf_attribute, | |
3516 | rtx)); | |
2ad9852d | 3517 | static inline rtx AT_addr PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3518 | static void add_AT_lbl_id PARAMS ((dw_die_ref, |
3519 | enum dwarf_attribute, | |
3520 | const char *)); | |
3521 | static void add_AT_lbl_offset PARAMS ((dw_die_ref, | |
3522 | enum dwarf_attribute, | |
3523 | const char *)); | |
a20612aa RH |
3524 | static void add_AT_offset PARAMS ((dw_die_ref, |
3525 | enum dwarf_attribute, | |
3526 | unsigned long)); | |
2bee6045 JJ |
3527 | static void add_AT_range_list PARAMS ((dw_die_ref, |
3528 | enum dwarf_attribute, | |
3529 | unsigned long)); | |
2ad9852d | 3530 | static inline const char *AT_lbl PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3531 | static dw_attr_ref get_AT PARAMS ((dw_die_ref, |
3532 | enum dwarf_attribute)); | |
3533 | static const char *get_AT_low_pc PARAMS ((dw_die_ref)); | |
3534 | static const char *get_AT_hi_pc PARAMS ((dw_die_ref)); | |
3535 | static const char *get_AT_string PARAMS ((dw_die_ref, | |
3536 | enum dwarf_attribute)); | |
3537 | static int get_AT_flag PARAMS ((dw_die_ref, | |
3538 | enum dwarf_attribute)); | |
3539 | static unsigned get_AT_unsigned PARAMS ((dw_die_ref, | |
3540 | enum dwarf_attribute)); | |
3541 | static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref, | |
3542 | enum dwarf_attribute)); | |
3543 | static int is_c_family PARAMS ((void)); | |
710af899 | 3544 | static int is_cxx PARAMS ((void)); |
28985b81 | 3545 | static int is_java PARAMS ((void)); |
7d9d8943 AM |
3546 | static int is_fortran PARAMS ((void)); |
3547 | static void remove_AT PARAMS ((dw_die_ref, | |
3548 | enum dwarf_attribute)); | |
2ad9852d | 3549 | static inline void free_die PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3550 | static void remove_children PARAMS ((dw_die_ref)); |
3551 | static void add_child_die PARAMS ((dw_die_ref, dw_die_ref)); | |
54ba1f0d RH |
3552 | static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref, |
3553 | tree)); | |
7d9d8943 AM |
3554 | static dw_die_ref lookup_type_die PARAMS ((tree)); |
3555 | static void equate_type_number_to_die PARAMS ((tree, dw_die_ref)); | |
3556 | static dw_die_ref lookup_decl_die PARAMS ((tree)); | |
3557 | static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref)); | |
3558 | static void print_spaces PARAMS ((FILE *)); | |
3559 | static void print_die PARAMS ((dw_die_ref, FILE *)); | |
3560 | static void print_dwarf_line_table PARAMS ((FILE *)); | |
881c6935 JM |
3561 | static void reverse_die_lists PARAMS ((dw_die_ref)); |
3562 | static void reverse_all_dies PARAMS ((dw_die_ref)); | |
3563 | static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref)); | |
3564 | static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref)); | |
2ad9852d RK |
3565 | static void loc_checksum PARAMS ((dw_loc_descr_ref, |
3566 | struct md5_ctx *)); | |
3567 | static void attr_checksum PARAMS ((dw_attr_ref, | |
3568 | struct md5_ctx *)); | |
3569 | static void die_checksum PARAMS ((dw_die_ref, | |
3570 | struct md5_ctx *)); | |
881c6935 JM |
3571 | static void compute_section_prefix PARAMS ((dw_die_ref)); |
3572 | static int is_type_die PARAMS ((dw_die_ref)); | |
3573 | static int is_comdat_die PARAMS ((dw_die_ref)); | |
3574 | static int is_symbol_die PARAMS ((dw_die_ref)); | |
881c6935 JM |
3575 | static void assign_symbol_names PARAMS ((dw_die_ref)); |
3576 | static void break_out_includes PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3577 | static void add_sibling_attributes PARAMS ((dw_die_ref)); |
3578 | static void build_abbrev_table PARAMS ((dw_die_ref)); | |
63e46568 | 3579 | static void output_location_lists PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3580 | static int constant_size PARAMS ((long unsigned)); |
3581 | static unsigned long size_of_die PARAMS ((dw_die_ref)); | |
3582 | static void calc_die_sizes PARAMS ((dw_die_ref)); | |
1bfb5f8f JM |
3583 | static void mark_dies PARAMS ((dw_die_ref)); |
3584 | static void unmark_dies PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3585 | static unsigned long size_of_pubnames PARAMS ((void)); |
3586 | static unsigned long size_of_aranges PARAMS ((void)); | |
3587 | static enum dwarf_form value_format PARAMS ((dw_attr_ref)); | |
3588 | static void output_value_format PARAMS ((dw_attr_ref)); | |
3589 | static void output_abbrev_section PARAMS ((void)); | |
881c6935 | 3590 | static void output_die_symbol PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3591 | static void output_die PARAMS ((dw_die_ref)); |
3592 | static void output_compilation_unit_header PARAMS ((void)); | |
881c6935 | 3593 | static void output_comp_unit PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3594 | static const char *dwarf2_name PARAMS ((tree, int)); |
3595 | static void add_pubname PARAMS ((tree, dw_die_ref)); | |
3596 | static void output_pubnames PARAMS ((void)); | |
3597 | static void add_arange PARAMS ((tree, dw_die_ref)); | |
3598 | static void output_aranges PARAMS ((void)); | |
a20612aa RH |
3599 | static unsigned int add_ranges PARAMS ((tree)); |
3600 | static void output_ranges PARAMS ((void)); | |
7d9d8943 | 3601 | static void output_line_info PARAMS ((void)); |
0b34cf1e | 3602 | static void output_file_names PARAMS ((void)); |
7d9d8943 AM |
3603 | static dw_die_ref base_type_die PARAMS ((tree)); |
3604 | static tree root_type PARAMS ((tree)); | |
3605 | static int is_base_type PARAMS ((tree)); | |
3606 | static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref)); | |
3607 | static int type_is_enum PARAMS ((tree)); | |
3608 | static unsigned int reg_number PARAMS ((rtx)); | |
3609 | static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx)); | |
d8041cc8 | 3610 | static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT)); |
7d9d8943 AM |
3611 | static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long)); |
3612 | static int is_based_loc PARAMS ((rtx)); | |
3613 | static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode)); | |
3614 | static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx)); | |
3615 | static dw_loc_descr_ref loc_descriptor PARAMS ((rtx)); | |
d8041cc8 | 3616 | static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int)); |
7d9d8943 AM |
3617 | static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int)); |
3618 | static tree field_type PARAMS ((tree)); | |
3619 | static unsigned int simple_type_align_in_bits PARAMS ((tree)); | |
5f446d21 | 3620 | static unsigned int simple_decl_align_in_bits PARAMS ((tree)); |
7d9d8943 AM |
3621 | static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree)); |
3622 | static HOST_WIDE_INT field_byte_offset PARAMS ((tree)); | |
3623 | static void add_AT_location_description PARAMS ((dw_die_ref, | |
3624 | enum dwarf_attribute, rtx)); | |
3625 | static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree)); | |
3626 | static void add_const_value_attribute PARAMS ((dw_die_ref, rtx)); | |
d8041cc8 | 3627 | static rtx rtl_for_decl_location PARAMS ((tree)); |
7d9d8943 | 3628 | static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree)); |
1bfb5f8f | 3629 | static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree)); |
7d9d8943 AM |
3630 | static void add_name_attribute PARAMS ((dw_die_ref, const char *)); |
3631 | static void add_bound_info PARAMS ((dw_die_ref, | |
3632 | enum dwarf_attribute, tree)); | |
3633 | static void add_subscript_info PARAMS ((dw_die_ref, tree)); | |
3634 | static void add_byte_size_attribute PARAMS ((dw_die_ref, tree)); | |
3635 | static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree)); | |
3636 | static void add_bit_size_attribute PARAMS ((dw_die_ref, tree)); | |
3637 | static void add_prototyped_attribute PARAMS ((dw_die_ref, tree)); | |
3638 | static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree)); | |
3639 | static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree)); | |
3640 | static void add_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
3641 | static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
3642 | static void push_decl_scope PARAMS ((tree)); | |
7d9d8943 | 3643 | static void pop_decl_scope PARAMS ((void)); |
2ad9852d RK |
3644 | static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref)); |
3645 | static inline int local_scope_p PARAMS ((dw_die_ref)); | |
3646 | static inline int class_scope_p PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3647 | static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int, |
3648 | dw_die_ref)); | |
3649 | static const char *type_tag PARAMS ((tree)); | |
3650 | static tree member_declared_type PARAMS ((tree)); | |
3651 | #if 0 | |
3652 | static const char *decl_start_label PARAMS ((tree)); | |
3653 | #endif | |
3654 | static void gen_array_type_die PARAMS ((tree, dw_die_ref)); | |
3655 | static void gen_set_type_die PARAMS ((tree, dw_die_ref)); | |
3656 | #if 0 | |
3657 | static void gen_entry_point_die PARAMS ((tree, dw_die_ref)); | |
3658 | #endif | |
3659 | static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
3660 | static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref)); | |
3661 | static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref)); | |
3662 | static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
3663 | static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref)); | |
3664 | static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref)); | |
3665 | static void gen_formal_types_die PARAMS ((tree, dw_die_ref)); | |
3666 | static void gen_subprogram_die PARAMS ((tree, dw_die_ref)); | |
3667 | static void gen_variable_die PARAMS ((tree, dw_die_ref)); | |
3668 | static void gen_label_die PARAMS ((tree, dw_die_ref)); | |
3669 | static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int)); | |
3670 | static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int)); | |
3671 | static void gen_field_die PARAMS ((tree, dw_die_ref)); | |
3672 | static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref)); | |
3673 | static dw_die_ref gen_compile_unit_die PARAMS ((const char *)); | |
3674 | static void gen_string_type_die PARAMS ((tree, dw_die_ref)); | |
3675 | static void gen_inheritance_die PARAMS ((tree, dw_die_ref)); | |
3676 | static void gen_member_die PARAMS ((tree, dw_die_ref)); | |
3677 | static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref)); | |
3678 | static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref)); | |
3679 | static void gen_typedef_die PARAMS ((tree, dw_die_ref)); | |
3680 | static void gen_type_die PARAMS ((tree, dw_die_ref)); | |
3681 | static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref)); | |
3682 | static void gen_block_die PARAMS ((tree, dw_die_ref, int)); | |
3683 | static void decls_for_scope PARAMS ((tree, dw_die_ref, int)); | |
3684 | static int is_redundant_typedef PARAMS ((tree)); | |
3685 | static void gen_decl_die PARAMS ((tree, dw_die_ref)); | |
981975b6 RH |
3686 | static unsigned lookup_filename PARAMS ((const char *)); |
3687 | static void init_file_table PARAMS ((void)); | |
7d9d8943 AM |
3688 | static void retry_incomplete_types PARAMS ((void)); |
3689 | static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref)); | |
7d9d8943 | 3690 | static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref)); |
fc608b03 | 3691 | static int file_info_cmp PARAMS ((const void *, const void *)); |
c26fbbca | 3692 | static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref, |
84a5b4f8 DB |
3693 | const char *, const char *, |
3694 | const char *, unsigned)); | |
3695 | static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *, | |
3696 | dw_loc_descr_ref, | |
3697 | const char *, const char *, const char *)); | |
3698 | static void output_loc_list PARAMS ((dw_loc_list_ref)); | |
3699 | static char *gen_internal_sym PARAMS ((const char *)); | |
54ba1f0d | 3700 | static void mark_limbo_die_list PARAMS ((void *)); |
7d9d8943 AM |
3701 | |
3702 | /* Section names used to hold DWARF debugging information. */ | |
3703 | #ifndef DEBUG_INFO_SECTION | |
3704 | #define DEBUG_INFO_SECTION ".debug_info" | |
3705 | #endif | |
9d2f2c45 RH |
3706 | #ifndef DEBUG_ABBREV_SECTION |
3707 | #define DEBUG_ABBREV_SECTION ".debug_abbrev" | |
7d9d8943 | 3708 | #endif |
9d2f2c45 RH |
3709 | #ifndef DEBUG_ARANGES_SECTION |
3710 | #define DEBUG_ARANGES_SECTION ".debug_aranges" | |
7d9d8943 | 3711 | #endif |
9d2f2c45 RH |
3712 | #ifndef DEBUG_MACINFO_SECTION |
3713 | #define DEBUG_MACINFO_SECTION ".debug_macinfo" | |
7d9d8943 AM |
3714 | #endif |
3715 | #ifndef DEBUG_LINE_SECTION | |
3716 | #define DEBUG_LINE_SECTION ".debug_line" | |
3717 | #endif | |
9d2f2c45 RH |
3718 | #ifndef DEBUG_LOC_SECTION |
3719 | #define DEBUG_LOC_SECTION ".debug_loc" | |
7d9d8943 | 3720 | #endif |
9d2f2c45 RH |
3721 | #ifndef DEBUG_PUBNAMES_SECTION |
3722 | #define DEBUG_PUBNAMES_SECTION ".debug_pubnames" | |
7d9d8943 | 3723 | #endif |
9d2f2c45 RH |
3724 | #ifndef DEBUG_STR_SECTION |
3725 | #define DEBUG_STR_SECTION ".debug_str" | |
7d9d8943 | 3726 | #endif |
a20612aa RH |
3727 | #ifndef DEBUG_RANGES_SECTION |
3728 | #define DEBUG_RANGES_SECTION ".debug_ranges" | |
3729 | #endif | |
7d9d8943 AM |
3730 | |
3731 | /* Standard ELF section names for compiled code and data. */ | |
f99ffb60 RH |
3732 | #ifndef TEXT_SECTION_NAME |
3733 | #define TEXT_SECTION_NAME ".text" | |
7d9d8943 AM |
3734 | #endif |
3735 | ||
9eb4015a JJ |
3736 | /* Section flags for .debug_str section. */ |
3737 | #ifdef HAVE_GAS_SHF_MERGE | |
3738 | #define DEBUG_STR_SECTION_FLAGS \ | |
3739 | (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1) | |
3740 | #else | |
3741 | #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG | |
3742 | #endif | |
3743 | ||
7d9d8943 | 3744 | /* Labels we insert at beginning sections we can reference instead of |
556273e0 | 3745 | the section names themselves. */ |
7d9d8943 AM |
3746 | |
3747 | #ifndef TEXT_SECTION_LABEL | |
9d2f2c45 | 3748 | #define TEXT_SECTION_LABEL "Ltext" |
7d9d8943 AM |
3749 | #endif |
3750 | #ifndef DEBUG_LINE_SECTION_LABEL | |
9d2f2c45 | 3751 | #define DEBUG_LINE_SECTION_LABEL "Ldebug_line" |
7d9d8943 AM |
3752 | #endif |
3753 | #ifndef DEBUG_INFO_SECTION_LABEL | |
9d2f2c45 | 3754 | #define DEBUG_INFO_SECTION_LABEL "Ldebug_info" |
7d9d8943 | 3755 | #endif |
9d2f2c45 RH |
3756 | #ifndef DEBUG_ABBREV_SECTION_LABEL |
3757 | #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev" | |
7d9d8943 | 3758 | #endif |
9d2f2c45 RH |
3759 | #ifndef DEBUG_LOC_SECTION_LABEL |
3760 | #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc" | |
63e46568 | 3761 | #endif |
2bee6045 JJ |
3762 | #ifndef DEBUG_RANGES_SECTION_LABEL |
3763 | #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges" | |
3764 | #endif | |
84a5b4f8 DB |
3765 | #ifndef DEBUG_MACINFO_SECTION_LABEL |
3766 | #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo" | |
3767 | #endif | |
a20612aa | 3768 | |
7d9d8943 AM |
3769 | /* Definitions of defaults for formats and names of various special |
3770 | (artificial) labels which may be generated within this file (when the -g | |
3771 | options is used and DWARF_DEBUGGING_INFO is in effect. | |
3772 | If necessary, these may be overridden from within the tm.h file, but | |
3773 | typically, overriding these defaults is unnecessary. */ | |
3774 | ||
3775 | static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3776 | static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3777 | static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3778 | static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3779 | static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
84a5b4f8 | 3780 | static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
63e46568 | 3781 | static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
2bee6045 | 3782 | static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES]; |
2ad9852d | 3783 | |
7d9d8943 AM |
3784 | #ifndef TEXT_END_LABEL |
3785 | #define TEXT_END_LABEL "Letext" | |
3786 | #endif | |
3787 | #ifndef DATA_END_LABEL | |
3788 | #define DATA_END_LABEL "Ledata" | |
3789 | #endif | |
3790 | #ifndef BSS_END_LABEL | |
3791 | #define BSS_END_LABEL "Lebss" | |
3792 | #endif | |
7d9d8943 AM |
3793 | #ifndef BLOCK_BEGIN_LABEL |
3794 | #define BLOCK_BEGIN_LABEL "LBB" | |
3795 | #endif | |
3796 | #ifndef BLOCK_END_LABEL | |
3797 | #define BLOCK_END_LABEL "LBE" | |
3798 | #endif | |
3799 | #ifndef BODY_BEGIN_LABEL | |
3800 | #define BODY_BEGIN_LABEL "Lbb" | |
3801 | #endif | |
3802 | #ifndef BODY_END_LABEL | |
3803 | #define BODY_END_LABEL "Lbe" | |
3804 | #endif | |
3805 | #ifndef LINE_CODE_LABEL | |
3806 | #define LINE_CODE_LABEL "LM" | |
3807 | #endif | |
3808 | #ifndef SEPARATE_LINE_CODE_LABEL | |
3809 | #define SEPARATE_LINE_CODE_LABEL "LSM" | |
3810 | #endif | |
3811 | \f | |
3812 | /* We allow a language front-end to designate a function that is to be | |
3813 | called to "demangle" any name before it it put into a DIE. */ | |
3814 | ||
3815 | static const char *(*demangle_name_func) PARAMS ((const char *)); | |
3816 | ||
3817 | void | |
3818 | dwarf2out_set_demangle_name_func (func) | |
3819 | const char *(*func) PARAMS ((const char *)); | |
3820 | { | |
3821 | demangle_name_func = func; | |
3822 | } | |
7d9d8943 AM |
3823 | |
3824 | /* Test if rtl node points to a pseudo register. */ | |
3825 | ||
3826 | static inline int | |
3827 | is_pseudo_reg (rtl) | |
b3694847 | 3828 | rtx rtl; |
7d9d8943 AM |
3829 | { |
3830 | return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER) | |
3831 | || (GET_CODE (rtl) == SUBREG | |
ddef6bc7 | 3832 | && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)); |
7d9d8943 AM |
3833 | } |
3834 | ||
3835 | /* Return a reference to a type, with its const and volatile qualifiers | |
3836 | removed. */ | |
3837 | ||
3838 | static inline tree | |
3839 | type_main_variant (type) | |
b3694847 | 3840 | tree type; |
7d9d8943 AM |
3841 | { |
3842 | type = TYPE_MAIN_VARIANT (type); | |
3843 | ||
2ad9852d RK |
3844 | /* ??? There really should be only one main variant among any group of |
3845 | variants of a given type (and all of the MAIN_VARIANT values for all | |
3846 | members of the group should point to that one type) but sometimes the C | |
3847 | front-end messes this up for array types, so we work around that bug | |
3848 | here. */ | |
7d9d8943 AM |
3849 | if (TREE_CODE (type) == ARRAY_TYPE) |
3850 | while (type != TYPE_MAIN_VARIANT (type)) | |
3851 | type = TYPE_MAIN_VARIANT (type); | |
3852 | ||
3853 | return type; | |
3854 | } | |
3855 | ||
3856 | /* Return non-zero if the given type node represents a tagged type. */ | |
3857 | ||
3858 | static inline int | |
3859 | is_tagged_type (type) | |
b3694847 | 3860 | tree type; |
7d9d8943 | 3861 | { |
b3694847 | 3862 | enum tree_code code = TREE_CODE (type); |
7d9d8943 AM |
3863 | |
3864 | return (code == RECORD_TYPE || code == UNION_TYPE | |
3865 | || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); | |
3866 | } | |
3867 | ||
3868 | /* Convert a DIE tag into its string name. */ | |
3869 | ||
3870 | static const char * | |
3871 | dwarf_tag_name (tag) | |
b3694847 | 3872 | unsigned tag; |
7d9d8943 AM |
3873 | { |
3874 | switch (tag) | |
3875 | { | |
3876 | case DW_TAG_padding: | |
3877 | return "DW_TAG_padding"; | |
3878 | case DW_TAG_array_type: | |
3879 | return "DW_TAG_array_type"; | |
3880 | case DW_TAG_class_type: | |
3881 | return "DW_TAG_class_type"; | |
3882 | case DW_TAG_entry_point: | |
3883 | return "DW_TAG_entry_point"; | |
3884 | case DW_TAG_enumeration_type: | |
3885 | return "DW_TAG_enumeration_type"; | |
3886 | case DW_TAG_formal_parameter: | |
3887 | return "DW_TAG_formal_parameter"; | |
3888 | case DW_TAG_imported_declaration: | |
3889 | return "DW_TAG_imported_declaration"; | |
3890 | case DW_TAG_label: | |
3891 | return "DW_TAG_label"; | |
3892 | case DW_TAG_lexical_block: | |
3893 | return "DW_TAG_lexical_block"; | |
3894 | case DW_TAG_member: | |
3895 | return "DW_TAG_member"; | |
3896 | case DW_TAG_pointer_type: | |
3897 | return "DW_TAG_pointer_type"; | |
3898 | case DW_TAG_reference_type: | |
3899 | return "DW_TAG_reference_type"; | |
3900 | case DW_TAG_compile_unit: | |
3901 | return "DW_TAG_compile_unit"; | |
3902 | case DW_TAG_string_type: | |
3903 | return "DW_TAG_string_type"; | |
3904 | case DW_TAG_structure_type: | |
3905 | return "DW_TAG_structure_type"; | |
3906 | case DW_TAG_subroutine_type: | |
3907 | return "DW_TAG_subroutine_type"; | |
3908 | case DW_TAG_typedef: | |
3909 | return "DW_TAG_typedef"; | |
3910 | case DW_TAG_union_type: | |
3911 | return "DW_TAG_union_type"; | |
3912 | case DW_TAG_unspecified_parameters: | |
3913 | return "DW_TAG_unspecified_parameters"; | |
3914 | case DW_TAG_variant: | |
3915 | return "DW_TAG_variant"; | |
3916 | case DW_TAG_common_block: | |
3917 | return "DW_TAG_common_block"; | |
3918 | case DW_TAG_common_inclusion: | |
3919 | return "DW_TAG_common_inclusion"; | |
3920 | case DW_TAG_inheritance: | |
3921 | return "DW_TAG_inheritance"; | |
3922 | case DW_TAG_inlined_subroutine: | |
3923 | return "DW_TAG_inlined_subroutine"; | |
3924 | case DW_TAG_module: | |
3925 | return "DW_TAG_module"; | |
3926 | case DW_TAG_ptr_to_member_type: | |
3927 | return "DW_TAG_ptr_to_member_type"; | |
3928 | case DW_TAG_set_type: | |
3929 | return "DW_TAG_set_type"; | |
3930 | case DW_TAG_subrange_type: | |
3931 | return "DW_TAG_subrange_type"; | |
3932 | case DW_TAG_with_stmt: | |
3933 | return "DW_TAG_with_stmt"; | |
3934 | case DW_TAG_access_declaration: | |
3935 | return "DW_TAG_access_declaration"; | |
3936 | case DW_TAG_base_type: | |
3937 | return "DW_TAG_base_type"; | |
3938 | case DW_TAG_catch_block: | |
3939 | return "DW_TAG_catch_block"; | |
3940 | case DW_TAG_const_type: | |
3941 | return "DW_TAG_const_type"; | |
3942 | case DW_TAG_constant: | |
3943 | return "DW_TAG_constant"; | |
3944 | case DW_TAG_enumerator: | |
3945 | return "DW_TAG_enumerator"; | |
3946 | case DW_TAG_file_type: | |
3947 | return "DW_TAG_file_type"; | |
3948 | case DW_TAG_friend: | |
3949 | return "DW_TAG_friend"; | |
3950 | case DW_TAG_namelist: | |
3951 | return "DW_TAG_namelist"; | |
3952 | case DW_TAG_namelist_item: | |
3953 | return "DW_TAG_namelist_item"; | |
3954 | case DW_TAG_packed_type: | |
3955 | return "DW_TAG_packed_type"; | |
3956 | case DW_TAG_subprogram: | |
3957 | return "DW_TAG_subprogram"; | |
3958 | case DW_TAG_template_type_param: | |
3959 | return "DW_TAG_template_type_param"; | |
3960 | case DW_TAG_template_value_param: | |
3961 | return "DW_TAG_template_value_param"; | |
3962 | case DW_TAG_thrown_type: | |
3963 | return "DW_TAG_thrown_type"; | |
3964 | case DW_TAG_try_block: | |
3965 | return "DW_TAG_try_block"; | |
3966 | case DW_TAG_variant_part: | |
3967 | return "DW_TAG_variant_part"; | |
3968 | case DW_TAG_variable: | |
3969 | return "DW_TAG_variable"; | |
3970 | case DW_TAG_volatile_type: | |
3971 | return "DW_TAG_volatile_type"; | |
3972 | case DW_TAG_MIPS_loop: | |
3973 | return "DW_TAG_MIPS_loop"; | |
3974 | case DW_TAG_format_label: | |
3975 | return "DW_TAG_format_label"; | |
3976 | case DW_TAG_function_template: | |
3977 | return "DW_TAG_function_template"; | |
3978 | case DW_TAG_class_template: | |
3979 | return "DW_TAG_class_template"; | |
881c6935 JM |
3980 | case DW_TAG_GNU_BINCL: |
3981 | return "DW_TAG_GNU_BINCL"; | |
3982 | case DW_TAG_GNU_EINCL: | |
3983 | return "DW_TAG_GNU_EINCL"; | |
7d9d8943 AM |
3984 | default: |
3985 | return "DW_TAG_<unknown>"; | |
3986 | } | |
3987 | } | |
3988 | ||
3989 | /* Convert a DWARF attribute code into its string name. */ | |
3990 | ||
3991 | static const char * | |
3992 | dwarf_attr_name (attr) | |
b3694847 | 3993 | unsigned attr; |
7d9d8943 AM |
3994 | { |
3995 | switch (attr) | |
3996 | { | |
3997 | case DW_AT_sibling: | |
3998 | return "DW_AT_sibling"; | |
3999 | case DW_AT_location: | |
4000 | return "DW_AT_location"; | |
4001 | case DW_AT_name: | |
4002 | return "DW_AT_name"; | |
4003 | case DW_AT_ordering: | |
4004 | return "DW_AT_ordering"; | |
4005 | case DW_AT_subscr_data: | |
4006 | return "DW_AT_subscr_data"; | |
4007 | case DW_AT_byte_size: | |
4008 | return "DW_AT_byte_size"; | |
4009 | case DW_AT_bit_offset: | |
4010 | return "DW_AT_bit_offset"; | |
4011 | case DW_AT_bit_size: | |
4012 | return "DW_AT_bit_size"; | |
4013 | case DW_AT_element_list: | |
4014 | return "DW_AT_element_list"; | |
4015 | case DW_AT_stmt_list: | |
4016 | return "DW_AT_stmt_list"; | |
4017 | case DW_AT_low_pc: | |
4018 | return "DW_AT_low_pc"; | |
4019 | case DW_AT_high_pc: | |
4020 | return "DW_AT_high_pc"; | |
4021 | case DW_AT_language: | |
4022 | return "DW_AT_language"; | |
4023 | case DW_AT_member: | |
4024 | return "DW_AT_member"; | |
4025 | case DW_AT_discr: | |
4026 | return "DW_AT_discr"; | |
4027 | case DW_AT_discr_value: | |
4028 | return "DW_AT_discr_value"; | |
4029 | case DW_AT_visibility: | |
4030 | return "DW_AT_visibility"; | |
4031 | case DW_AT_import: | |
4032 | return "DW_AT_import"; | |
4033 | case DW_AT_string_length: | |
4034 | return "DW_AT_string_length"; | |
4035 | case DW_AT_common_reference: | |
4036 | return "DW_AT_common_reference"; | |
4037 | case DW_AT_comp_dir: | |
4038 | return "DW_AT_comp_dir"; | |
4039 | case DW_AT_const_value: | |
4040 | return "DW_AT_const_value"; | |
4041 | case DW_AT_containing_type: | |
4042 | return "DW_AT_containing_type"; | |
4043 | case DW_AT_default_value: | |
4044 | return "DW_AT_default_value"; | |
4045 | case DW_AT_inline: | |
4046 | return "DW_AT_inline"; | |
4047 | case DW_AT_is_optional: | |
4048 | return "DW_AT_is_optional"; | |
4049 | case DW_AT_lower_bound: | |
4050 | return "DW_AT_lower_bound"; | |
4051 | case DW_AT_producer: | |
4052 | return "DW_AT_producer"; | |
4053 | case DW_AT_prototyped: | |
4054 | return "DW_AT_prototyped"; | |
4055 | case DW_AT_return_addr: | |
4056 | return "DW_AT_return_addr"; | |
4057 | case DW_AT_start_scope: | |
4058 | return "DW_AT_start_scope"; | |
4059 | case DW_AT_stride_size: | |
4060 | return "DW_AT_stride_size"; | |
4061 | case DW_AT_upper_bound: | |
4062 | return "DW_AT_upper_bound"; | |
4063 | case DW_AT_abstract_origin: | |
4064 | return "DW_AT_abstract_origin"; | |
4065 | case DW_AT_accessibility: | |
4066 | return "DW_AT_accessibility"; | |
4067 | case DW_AT_address_class: | |
4068 | return "DW_AT_address_class"; | |
4069 | case DW_AT_artificial: | |
4070 | return "DW_AT_artificial"; | |
4071 | case DW_AT_base_types: | |
4072 | return "DW_AT_base_types"; | |
4073 | case DW_AT_calling_convention: | |
4074 | return "DW_AT_calling_convention"; | |
4075 | case DW_AT_count: | |
4076 | return "DW_AT_count"; | |
4077 | case DW_AT_data_member_location: | |
4078 | return "DW_AT_data_member_location"; | |
4079 | case DW_AT_decl_column: | |
4080 | return "DW_AT_decl_column"; | |
4081 | case DW_AT_decl_file: | |
4082 | return "DW_AT_decl_file"; | |
4083 | case DW_AT_decl_line: | |
4084 | return "DW_AT_decl_line"; | |
4085 | case DW_AT_declaration: | |
4086 | return "DW_AT_declaration"; | |
4087 | case DW_AT_discr_list: | |
4088 | return "DW_AT_discr_list"; | |
4089 | case DW_AT_encoding: | |
4090 | return "DW_AT_encoding"; | |
4091 | case DW_AT_external: | |
4092 | return "DW_AT_external"; | |
4093 | case DW_AT_frame_base: | |
4094 | return "DW_AT_frame_base"; | |
4095 | case DW_AT_friend: | |
4096 | return "DW_AT_friend"; | |
4097 | case DW_AT_identifier_case: | |
4098 | return "DW_AT_identifier_case"; | |
4099 | case DW_AT_macro_info: | |
4100 | return "DW_AT_macro_info"; | |
4101 | case DW_AT_namelist_items: | |
4102 | return "DW_AT_namelist_items"; | |
4103 | case DW_AT_priority: | |
4104 | return "DW_AT_priority"; | |
4105 | case DW_AT_segment: | |
4106 | return "DW_AT_segment"; | |
4107 | case DW_AT_specification: | |
4108 | return "DW_AT_specification"; | |
4109 | case DW_AT_static_link: | |
4110 | return "DW_AT_static_link"; | |
4111 | case DW_AT_type: | |
4112 | return "DW_AT_type"; | |
4113 | case DW_AT_use_location: | |
4114 | return "DW_AT_use_location"; | |
4115 | case DW_AT_variable_parameter: | |
4116 | return "DW_AT_variable_parameter"; | |
4117 | case DW_AT_virtuality: | |
4118 | return "DW_AT_virtuality"; | |
4119 | case DW_AT_vtable_elem_location: | |
4120 | return "DW_AT_vtable_elem_location"; | |
4121 | ||
a20612aa RH |
4122 | case DW_AT_allocated: |
4123 | return "DW_AT_allocated"; | |
4124 | case DW_AT_associated: | |
4125 | return "DW_AT_associated"; | |
4126 | case DW_AT_data_location: | |
4127 | return "DW_AT_data_location"; | |
4128 | case DW_AT_stride: | |
4129 | return "DW_AT_stride"; | |
4130 | case DW_AT_entry_pc: | |
4131 | return "DW_AT_entry_pc"; | |
4132 | case DW_AT_use_UTF8: | |
4133 | return "DW_AT_use_UTF8"; | |
4134 | case DW_AT_extension: | |
4135 | return "DW_AT_extension"; | |
4136 | case DW_AT_ranges: | |
4137 | return "DW_AT_ranges"; | |
4138 | case DW_AT_trampoline: | |
4139 | return "DW_AT_trampoline"; | |
4140 | case DW_AT_call_column: | |
4141 | return "DW_AT_call_column"; | |
4142 | case DW_AT_call_file: | |
4143 | return "DW_AT_call_file"; | |
4144 | case DW_AT_call_line: | |
4145 | return "DW_AT_call_line"; | |
4146 | ||
7d9d8943 AM |
4147 | case DW_AT_MIPS_fde: |
4148 | return "DW_AT_MIPS_fde"; | |
4149 | case DW_AT_MIPS_loop_begin: | |
4150 | return "DW_AT_MIPS_loop_begin"; | |
4151 | case DW_AT_MIPS_tail_loop_begin: | |
4152 | return "DW_AT_MIPS_tail_loop_begin"; | |
4153 | case DW_AT_MIPS_epilog_begin: | |
4154 | return "DW_AT_MIPS_epilog_begin"; | |
4155 | case DW_AT_MIPS_loop_unroll_factor: | |
4156 | return "DW_AT_MIPS_loop_unroll_factor"; | |
4157 | case DW_AT_MIPS_software_pipeline_depth: | |
4158 | return "DW_AT_MIPS_software_pipeline_depth"; | |
4159 | case DW_AT_MIPS_linkage_name: | |
4160 | return "DW_AT_MIPS_linkage_name"; | |
4161 | case DW_AT_MIPS_stride: | |
4162 | return "DW_AT_MIPS_stride"; | |
4163 | case DW_AT_MIPS_abstract_name: | |
4164 | return "DW_AT_MIPS_abstract_name"; | |
4165 | case DW_AT_MIPS_clone_origin: | |
4166 | return "DW_AT_MIPS_clone_origin"; | |
4167 | case DW_AT_MIPS_has_inlines: | |
4168 | return "DW_AT_MIPS_has_inlines"; | |
4169 | ||
4170 | case DW_AT_sf_names: | |
4171 | return "DW_AT_sf_names"; | |
4172 | case DW_AT_src_info: | |
4173 | return "DW_AT_src_info"; | |
4174 | case DW_AT_mac_info: | |
4175 | return "DW_AT_mac_info"; | |
4176 | case DW_AT_src_coords: | |
4177 | return "DW_AT_src_coords"; | |
4178 | case DW_AT_body_begin: | |
4179 | return "DW_AT_body_begin"; | |
4180 | case DW_AT_body_end: | |
4181 | return "DW_AT_body_end"; | |
84f0ace0 JM |
4182 | case DW_AT_GNU_vector: |
4183 | return "DW_AT_GNU_vector"; | |
4184 | ||
7a0c8d71 DR |
4185 | case DW_AT_VMS_rtnbeg_pd_address: |
4186 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
4187 | ||
7d9d8943 AM |
4188 | default: |
4189 | return "DW_AT_<unknown>"; | |
4190 | } | |
4191 | } | |
4192 | ||
4193 | /* Convert a DWARF value form code into its string name. */ | |
4194 | ||
4195 | static const char * | |
4196 | dwarf_form_name (form) | |
b3694847 | 4197 | unsigned form; |
7d9d8943 AM |
4198 | { |
4199 | switch (form) | |
4200 | { | |
4201 | case DW_FORM_addr: | |
4202 | return "DW_FORM_addr"; | |
4203 | case DW_FORM_block2: | |
4204 | return "DW_FORM_block2"; | |
4205 | case DW_FORM_block4: | |
4206 | return "DW_FORM_block4"; | |
4207 | case DW_FORM_data2: | |
4208 | return "DW_FORM_data2"; | |
4209 | case DW_FORM_data4: | |
4210 | return "DW_FORM_data4"; | |
4211 | case DW_FORM_data8: | |
4212 | return "DW_FORM_data8"; | |
4213 | case DW_FORM_string: | |
4214 | return "DW_FORM_string"; | |
4215 | case DW_FORM_block: | |
4216 | return "DW_FORM_block"; | |
4217 | case DW_FORM_block1: | |
4218 | return "DW_FORM_block1"; | |
4219 | case DW_FORM_data1: | |
4220 | return "DW_FORM_data1"; | |
4221 | case DW_FORM_flag: | |
4222 | return "DW_FORM_flag"; | |
4223 | case DW_FORM_sdata: | |
4224 | return "DW_FORM_sdata"; | |
4225 | case DW_FORM_strp: | |
4226 | return "DW_FORM_strp"; | |
4227 | case DW_FORM_udata: | |
4228 | return "DW_FORM_udata"; | |
4229 | case DW_FORM_ref_addr: | |
4230 | return "DW_FORM_ref_addr"; | |
4231 | case DW_FORM_ref1: | |
4232 | return "DW_FORM_ref1"; | |
4233 | case DW_FORM_ref2: | |
4234 | return "DW_FORM_ref2"; | |
4235 | case DW_FORM_ref4: | |
4236 | return "DW_FORM_ref4"; | |
4237 | case DW_FORM_ref8: | |
4238 | return "DW_FORM_ref8"; | |
4239 | case DW_FORM_ref_udata: | |
4240 | return "DW_FORM_ref_udata"; | |
4241 | case DW_FORM_indirect: | |
4242 | return "DW_FORM_indirect"; | |
3f76745e | 4243 | default: |
7d9d8943 | 4244 | return "DW_FORM_<unknown>"; |
a3f97cbb JW |
4245 | } |
4246 | } | |
4247 | ||
3f76745e | 4248 | /* Convert a DWARF type code into its string name. */ |
71dfc51f | 4249 | |
487a6e06 | 4250 | #if 0 |
d560ee52 | 4251 | static const char * |
3f76745e | 4252 | dwarf_type_encoding_name (enc) |
b3694847 | 4253 | unsigned enc; |
a3f97cbb | 4254 | { |
3f76745e | 4255 | switch (enc) |
a3f97cbb | 4256 | { |
3f76745e JM |
4257 | case DW_ATE_address: |
4258 | return "DW_ATE_address"; | |
4259 | case DW_ATE_boolean: | |
4260 | return "DW_ATE_boolean"; | |
4261 | case DW_ATE_complex_float: | |
4262 | return "DW_ATE_complex_float"; | |
4263 | case DW_ATE_float: | |
4264 | return "DW_ATE_float"; | |
4265 | case DW_ATE_signed: | |
4266 | return "DW_ATE_signed"; | |
4267 | case DW_ATE_signed_char: | |
4268 | return "DW_ATE_signed_char"; | |
4269 | case DW_ATE_unsigned: | |
4270 | return "DW_ATE_unsigned"; | |
4271 | case DW_ATE_unsigned_char: | |
4272 | return "DW_ATE_unsigned_char"; | |
4273 | default: | |
4274 | return "DW_ATE_<unknown>"; | |
4275 | } | |
a3f97cbb | 4276 | } |
487a6e06 | 4277 | #endif |
3f76745e JM |
4278 | \f |
4279 | /* Determine the "ultimate origin" of a decl. The decl may be an inlined | |
4280 | instance of an inlined instance of a decl which is local to an inline | |
4281 | function, so we have to trace all of the way back through the origin chain | |
4282 | to find out what sort of node actually served as the original seed for the | |
4283 | given block. */ | |
a3f97cbb | 4284 | |
3f76745e JM |
4285 | static tree |
4286 | decl_ultimate_origin (decl) | |
b3694847 | 4287 | tree decl; |
a3f97cbb | 4288 | { |
10a11b75 JM |
4289 | /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the |
4290 | nodes in the function to point to themselves; ignore that if | |
4291 | we're trying to output the abstract instance of this function. */ | |
4292 | if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl) | |
4293 | return NULL_TREE; | |
4294 | ||
556273e0 | 4295 | #ifdef ENABLE_CHECKING |
02e24c7a MM |
4296 | if (DECL_FROM_INLINE (DECL_ORIGIN (decl))) |
4297 | /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the | |
4298 | most distant ancestor, this should never happen. */ | |
4299 | abort (); | |
4300 | #endif | |
3f76745e | 4301 | |
02e24c7a | 4302 | return DECL_ABSTRACT_ORIGIN (decl); |
a3f97cbb JW |
4303 | } |
4304 | ||
3f76745e JM |
4305 | /* Determine the "ultimate origin" of a block. The block may be an inlined |
4306 | instance of an inlined instance of a block which is local to an inline | |
4307 | function, so we have to trace all of the way back through the origin chain | |
4308 | to find out what sort of node actually served as the original seed for the | |
4309 | given block. */ | |
71dfc51f | 4310 | |
3f76745e JM |
4311 | static tree |
4312 | block_ultimate_origin (block) | |
b3694847 | 4313 | tree block; |
a3f97cbb | 4314 | { |
b3694847 | 4315 | tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); |
71dfc51f | 4316 | |
10a11b75 JM |
4317 | /* output_inline_function sets BLOCK_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 (BLOCK_ABSTRACT (block) && immediate_origin == block) | |
4321 | return NULL_TREE; | |
4322 | ||
3f76745e JM |
4323 | if (immediate_origin == NULL_TREE) |
4324 | return NULL_TREE; | |
4325 | else | |
4326 | { | |
b3694847 SS |
4327 | tree ret_val; |
4328 | tree lookahead = immediate_origin; | |
71dfc51f | 4329 | |
3f76745e JM |
4330 | do |
4331 | { | |
4332 | ret_val = lookahead; | |
2ad9852d RK |
4333 | lookahead = (TREE_CODE (ret_val) == BLOCK |
4334 | ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL); | |
3f76745e JM |
4335 | } |
4336 | while (lookahead != NULL && lookahead != ret_val); | |
4337 | ||
4338 | return ret_val; | |
4339 | } | |
a3f97cbb JW |
4340 | } |
4341 | ||
3f76745e JM |
4342 | /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT |
4343 | of a virtual function may refer to a base class, so we check the 'this' | |
4344 | parameter. */ | |
71dfc51f | 4345 | |
3f76745e JM |
4346 | static tree |
4347 | decl_class_context (decl) | |
4348 | tree decl; | |
a3f97cbb | 4349 | { |
3f76745e | 4350 | tree context = NULL_TREE; |
71dfc51f | 4351 | |
3f76745e JM |
4352 | if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl)) |
4353 | context = DECL_CONTEXT (decl); | |
4354 | else | |
4355 | context = TYPE_MAIN_VARIANT | |
4356 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
71dfc51f | 4357 | |
2f939d94 | 4358 | if (context && !TYPE_P (context)) |
3f76745e JM |
4359 | context = NULL_TREE; |
4360 | ||
4361 | return context; | |
a3f97cbb JW |
4362 | } |
4363 | \f | |
a96c67ec | 4364 | /* Add an attribute/value pair to a DIE. We build the lists up in reverse |
881c6935 | 4365 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f RK |
4366 | |
4367 | static inline void | |
3f76745e | 4368 | add_dwarf_attr (die, attr) |
b3694847 SS |
4369 | dw_die_ref die; |
4370 | dw_attr_ref attr; | |
a3f97cbb | 4371 | { |
3f76745e | 4372 | if (die != NULL && attr != NULL) |
a3f97cbb | 4373 | { |
a96c67ec JM |
4374 | attr->dw_attr_next = die->die_attr; |
4375 | die->die_attr = attr; | |
a3f97cbb JW |
4376 | } |
4377 | } | |
4378 | ||
a96c67ec JM |
4379 | static inline dw_val_class |
4380 | AT_class (a) | |
4381 | dw_attr_ref a; | |
4382 | { | |
4383 | return a->dw_attr_val.val_class; | |
4384 | } | |
4385 | ||
3f76745e | 4386 | /* Add a flag value attribute to a DIE. */ |
71dfc51f | 4387 | |
3f76745e JM |
4388 | static inline void |
4389 | add_AT_flag (die, attr_kind, flag) | |
b3694847 SS |
4390 | dw_die_ref die; |
4391 | enum dwarf_attribute attr_kind; | |
4392 | unsigned flag; | |
a3f97cbb | 4393 | { |
b3694847 | 4394 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4395 | |
3f76745e JM |
4396 | attr->dw_attr_next = NULL; |
4397 | attr->dw_attr = attr_kind; | |
4398 | attr->dw_attr_val.val_class = dw_val_class_flag; | |
4399 | attr->dw_attr_val.v.val_flag = flag; | |
4400 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4401 | } |
4402 | ||
a96c67ec JM |
4403 | static inline unsigned |
4404 | AT_flag (a) | |
b3694847 | 4405 | dw_attr_ref a; |
a96c67ec JM |
4406 | { |
4407 | if (a && AT_class (a) == dw_val_class_flag) | |
4408 | return a->dw_attr_val.v.val_flag; | |
4409 | ||
40e8cc95 | 4410 | abort (); |
a96c67ec JM |
4411 | } |
4412 | ||
3f76745e | 4413 | /* Add a signed integer attribute value to a DIE. */ |
71dfc51f | 4414 | |
3f76745e JM |
4415 | static inline void |
4416 | add_AT_int (die, attr_kind, int_val) | |
b3694847 SS |
4417 | dw_die_ref die; |
4418 | enum dwarf_attribute attr_kind; | |
4419 | long int int_val; | |
a3f97cbb | 4420 | { |
b3694847 | 4421 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3f76745e JM |
4422 | |
4423 | attr->dw_attr_next = NULL; | |
4424 | attr->dw_attr = attr_kind; | |
4425 | attr->dw_attr_val.val_class = dw_val_class_const; | |
4426 | attr->dw_attr_val.v.val_int = int_val; | |
4427 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4428 | } |
4429 | ||
a96c67ec JM |
4430 | static inline long int |
4431 | AT_int (a) | |
b3694847 | 4432 | dw_attr_ref a; |
a96c67ec JM |
4433 | { |
4434 | if (a && AT_class (a) == dw_val_class_const) | |
4435 | return a->dw_attr_val.v.val_int; | |
4436 | ||
40e8cc95 | 4437 | abort (); |
a96c67ec JM |
4438 | } |
4439 | ||
3f76745e | 4440 | /* Add an unsigned integer attribute value to a DIE. */ |
71dfc51f | 4441 | |
3f76745e JM |
4442 | static inline void |
4443 | add_AT_unsigned (die, attr_kind, unsigned_val) | |
b3694847 SS |
4444 | dw_die_ref die; |
4445 | enum dwarf_attribute attr_kind; | |
4446 | unsigned long unsigned_val; | |
a3f97cbb | 4447 | { |
b3694847 | 4448 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3f76745e JM |
4449 | |
4450 | attr->dw_attr_next = NULL; | |
4451 | attr->dw_attr = attr_kind; | |
4452 | attr->dw_attr_val.val_class = dw_val_class_unsigned_const; | |
4453 | attr->dw_attr_val.v.val_unsigned = unsigned_val; | |
4454 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4455 | } |
71dfc51f | 4456 | |
a96c67ec JM |
4457 | static inline unsigned long |
4458 | AT_unsigned (a) | |
b3694847 | 4459 | dw_attr_ref a; |
a96c67ec JM |
4460 | { |
4461 | if (a && AT_class (a) == dw_val_class_unsigned_const) | |
4462 | return a->dw_attr_val.v.val_unsigned; | |
4463 | ||
40e8cc95 | 4464 | abort (); |
a96c67ec JM |
4465 | } |
4466 | ||
3f76745e JM |
4467 | /* Add an unsigned double integer attribute value to a DIE. */ |
4468 | ||
4469 | static inline void | |
4470 | add_AT_long_long (die, attr_kind, val_hi, val_low) | |
b3694847 SS |
4471 | dw_die_ref die; |
4472 | enum dwarf_attribute attr_kind; | |
4473 | unsigned long val_hi; | |
4474 | unsigned long val_low; | |
a3f97cbb | 4475 | { |
b3694847 | 4476 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4477 | |
3f76745e JM |
4478 | attr->dw_attr_next = NULL; |
4479 | attr->dw_attr = attr_kind; | |
4480 | attr->dw_attr_val.val_class = dw_val_class_long_long; | |
4481 | attr->dw_attr_val.v.val_long_long.hi = val_hi; | |
4482 | attr->dw_attr_val.v.val_long_long.low = val_low; | |
4483 | add_dwarf_attr (die, attr); | |
4484 | } | |
71dfc51f | 4485 | |
3f76745e | 4486 | /* Add a floating point attribute value to a DIE and return it. */ |
71dfc51f | 4487 | |
3f76745e JM |
4488 | static inline void |
4489 | add_AT_float (die, attr_kind, length, array) | |
b3694847 SS |
4490 | dw_die_ref die; |
4491 | enum dwarf_attribute attr_kind; | |
4492 | unsigned length; | |
4493 | long *array; | |
3f76745e | 4494 | { |
b3694847 | 4495 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3f76745e JM |
4496 | |
4497 | attr->dw_attr_next = NULL; | |
4498 | attr->dw_attr = attr_kind; | |
4499 | attr->dw_attr_val.val_class = dw_val_class_float; | |
4500 | attr->dw_attr_val.v.val_float.length = length; | |
4501 | attr->dw_attr_val.v.val_float.array = array; | |
4502 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4503 | } |
4504 | ||
3f76745e | 4505 | /* Add a string attribute value to a DIE. */ |
71dfc51f | 4506 | |
3f76745e JM |
4507 | static inline void |
4508 | add_AT_string (die, attr_kind, str) | |
b3694847 SS |
4509 | dw_die_ref die; |
4510 | enum dwarf_attribute attr_kind; | |
4511 | const char *str; | |
a3f97cbb | 4512 | { |
b3694847 | 4513 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
9eb4015a | 4514 | struct indirect_string_node *node; |
c26fbbca | 4515 | |
9eb4015a JJ |
4516 | if (! debug_str_hash) |
4517 | { | |
4518 | debug_str_hash = ht_create (10); | |
4519 | debug_str_hash->alloc_node = indirect_string_alloc; | |
4520 | } | |
4521 | ||
4522 | node = (struct indirect_string_node *) | |
4523 | ht_lookup (debug_str_hash, (const unsigned char *) str, | |
4524 | strlen (str), HT_ALLOC); | |
4525 | node->refcount++; | |
71dfc51f | 4526 | |
3f76745e JM |
4527 | attr->dw_attr_next = NULL; |
4528 | attr->dw_attr = attr_kind; | |
4529 | attr->dw_attr_val.val_class = dw_val_class_str; | |
9eb4015a | 4530 | attr->dw_attr_val.v.val_str = node; |
3f76745e JM |
4531 | add_dwarf_attr (die, attr); |
4532 | } | |
71dfc51f | 4533 | |
a96c67ec JM |
4534 | static inline const char * |
4535 | AT_string (a) | |
b3694847 | 4536 | dw_attr_ref a; |
a96c67ec JM |
4537 | { |
4538 | if (a && AT_class (a) == dw_val_class_str) | |
9eb4015a JJ |
4539 | return (const char *) HT_STR (&a->dw_attr_val.v.val_str->id); |
4540 | ||
4541 | abort (); | |
4542 | } | |
4543 | ||
4544 | /* Find out whether a string should be output inline in DIE | |
4545 | or out-of-line in .debug_str section. */ | |
4546 | ||
9eb4015a JJ |
4547 | static int |
4548 | AT_string_form (a) | |
4549 | dw_attr_ref a; | |
4550 | { | |
4551 | if (a && AT_class (a) == dw_val_class_str) | |
4552 | { | |
4553 | struct indirect_string_node *node; | |
4554 | unsigned int len; | |
4555 | extern int const_labelno; | |
4556 | char label[32]; | |
4557 | ||
4558 | node = a->dw_attr_val.v.val_str; | |
4559 | if (node->form) | |
4560 | return node->form; | |
4561 | ||
4562 | len = HT_LEN (&node->id) + 1; | |
4563 | ||
2ad9852d RK |
4564 | /* If the string is shorter or equal to the size of the reference, it is |
4565 | always better to put it inline. */ | |
9eb4015a JJ |
4566 | if (len <= DWARF_OFFSET_SIZE || node->refcount == 0) |
4567 | return node->form = DW_FORM_string; | |
4568 | ||
2ad9852d RK |
4569 | /* If we cannot expect the linker to merge strings in .debug_str |
4570 | section, only put it into .debug_str if it is worth even in this | |
4571 | single module. */ | |
4572 | if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0 | |
4573 | && (len - DWARF_OFFSET_SIZE) * node->refcount <= len) | |
4574 | return node->form = DW_FORM_string; | |
9eb4015a JJ |
4575 | |
4576 | ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno); | |
4577 | ++const_labelno; | |
4578 | node->label = xstrdup (label); | |
2ad9852d | 4579 | |
9eb4015a JJ |
4580 | return node->form = DW_FORM_strp; |
4581 | } | |
a96c67ec | 4582 | |
40e8cc95 | 4583 | abort (); |
a96c67ec JM |
4584 | } |
4585 | ||
3f76745e | 4586 | /* Add a DIE reference attribute value to a DIE. */ |
71dfc51f | 4587 | |
3f76745e JM |
4588 | static inline void |
4589 | add_AT_die_ref (die, attr_kind, targ_die) | |
b3694847 SS |
4590 | dw_die_ref die; |
4591 | enum dwarf_attribute attr_kind; | |
4592 | dw_die_ref targ_die; | |
3f76745e | 4593 | { |
b3694847 | 4594 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4595 | |
3f76745e JM |
4596 | attr->dw_attr_next = NULL; |
4597 | attr->dw_attr = attr_kind; | |
4598 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
881c6935 JM |
4599 | attr->dw_attr_val.v.val_die_ref.die = targ_die; |
4600 | attr->dw_attr_val.v.val_die_ref.external = 0; | |
3f76745e JM |
4601 | add_dwarf_attr (die, attr); |
4602 | } | |
b1ccbc24 | 4603 | |
a96c67ec JM |
4604 | static inline dw_die_ref |
4605 | AT_ref (a) | |
b3694847 | 4606 | dw_attr_ref a; |
a96c67ec JM |
4607 | { |
4608 | if (a && AT_class (a) == dw_val_class_die_ref) | |
881c6935 | 4609 | return a->dw_attr_val.v.val_die_ref.die; |
a96c67ec | 4610 | |
40e8cc95 | 4611 | abort (); |
a96c67ec JM |
4612 | } |
4613 | ||
881c6935 JM |
4614 | static inline int |
4615 | AT_ref_external (a) | |
b3694847 | 4616 | dw_attr_ref a; |
881c6935 JM |
4617 | { |
4618 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4619 | return a->dw_attr_val.v.val_die_ref.external; | |
4620 | ||
4621 | return 0; | |
4622 | } | |
4623 | ||
881c6935 JM |
4624 | static inline void |
4625 | set_AT_ref_external (a, i) | |
b3694847 | 4626 | dw_attr_ref a; |
881c6935 JM |
4627 | int i; |
4628 | { | |
4629 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4630 | a->dw_attr_val.v.val_die_ref.external = i; | |
4631 | else | |
4632 | abort (); | |
4633 | } | |
4634 | ||
3f76745e | 4635 | /* Add an FDE reference attribute value to a DIE. */ |
b1ccbc24 | 4636 | |
3f76745e JM |
4637 | static inline void |
4638 | add_AT_fde_ref (die, attr_kind, targ_fde) | |
b3694847 SS |
4639 | dw_die_ref die; |
4640 | enum dwarf_attribute attr_kind; | |
4641 | unsigned targ_fde; | |
3f76745e | 4642 | { |
b3694847 | 4643 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
b1ccbc24 | 4644 | |
3f76745e JM |
4645 | attr->dw_attr_next = NULL; |
4646 | attr->dw_attr = attr_kind; | |
4647 | attr->dw_attr_val.val_class = dw_val_class_fde_ref; | |
4648 | attr->dw_attr_val.v.val_fde_index = targ_fde; | |
4649 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4650 | } |
71dfc51f | 4651 | |
3f76745e | 4652 | /* Add a location description attribute value to a DIE. */ |
71dfc51f | 4653 | |
3f76745e JM |
4654 | static inline void |
4655 | add_AT_loc (die, attr_kind, loc) | |
b3694847 SS |
4656 | dw_die_ref die; |
4657 | enum dwarf_attribute attr_kind; | |
4658 | dw_loc_descr_ref loc; | |
3f76745e | 4659 | { |
b3694847 | 4660 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4661 | |
3f76745e JM |
4662 | attr->dw_attr_next = NULL; |
4663 | attr->dw_attr = attr_kind; | |
4664 | attr->dw_attr_val.val_class = dw_val_class_loc; | |
4665 | attr->dw_attr_val.v.val_loc = loc; | |
4666 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4667 | } |
4668 | ||
a96c67ec JM |
4669 | static inline dw_loc_descr_ref |
4670 | AT_loc (a) | |
b3694847 | 4671 | dw_attr_ref a; |
a96c67ec JM |
4672 | { |
4673 | if (a && AT_class (a) == dw_val_class_loc) | |
4674 | return a->dw_attr_val.v.val_loc; | |
4675 | ||
40e8cc95 | 4676 | abort (); |
a96c67ec JM |
4677 | } |
4678 | ||
63e46568 DB |
4679 | static inline void |
4680 | add_AT_loc_list (die, attr_kind, loc_list) | |
b3694847 SS |
4681 | dw_die_ref die; |
4682 | enum dwarf_attribute attr_kind; | |
4683 | dw_loc_list_ref loc_list; | |
63e46568 | 4684 | { |
b3694847 | 4685 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
63e46568 DB |
4686 | |
4687 | attr->dw_attr_next = NULL; | |
4688 | attr->dw_attr = attr_kind; | |
4689 | attr->dw_attr_val.val_class = dw_val_class_loc_list; | |
4690 | attr->dw_attr_val.v.val_loc_list = loc_list; | |
4691 | add_dwarf_attr (die, attr); | |
4692 | have_location_lists = 1; | |
4693 | } | |
4694 | ||
63e46568 DB |
4695 | static inline dw_loc_list_ref |
4696 | AT_loc_list (a) | |
b3694847 | 4697 | dw_attr_ref a; |
63e46568 DB |
4698 | { |
4699 | if (a && AT_class (a) == dw_val_class_loc_list) | |
4700 | return a->dw_attr_val.v.val_loc_list; | |
4701 | ||
4702 | abort (); | |
4703 | } | |
4704 | ||
3f76745e | 4705 | /* Add an address constant attribute value to a DIE. */ |
71dfc51f | 4706 | |
3f76745e JM |
4707 | static inline void |
4708 | add_AT_addr (die, attr_kind, addr) | |
b3694847 SS |
4709 | dw_die_ref die; |
4710 | enum dwarf_attribute attr_kind; | |
1865dbb5 | 4711 | rtx addr; |
a3f97cbb | 4712 | { |
b3694847 | 4713 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4714 | |
3f76745e JM |
4715 | attr->dw_attr_next = NULL; |
4716 | attr->dw_attr = attr_kind; | |
4717 | attr->dw_attr_val.val_class = dw_val_class_addr; | |
4718 | attr->dw_attr_val.v.val_addr = addr; | |
4719 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4720 | } |
4721 | ||
1865dbb5 | 4722 | static inline rtx |
a96c67ec | 4723 | AT_addr (a) |
b3694847 | 4724 | dw_attr_ref a; |
a96c67ec JM |
4725 | { |
4726 | if (a && AT_class (a) == dw_val_class_addr) | |
4727 | return a->dw_attr_val.v.val_addr; | |
4728 | ||
40e8cc95 | 4729 | abort (); |
a96c67ec JM |
4730 | } |
4731 | ||
3f76745e | 4732 | /* Add a label identifier attribute value to a DIE. */ |
71dfc51f | 4733 | |
3f76745e JM |
4734 | static inline void |
4735 | add_AT_lbl_id (die, attr_kind, lbl_id) | |
b3694847 SS |
4736 | dw_die_ref die; |
4737 | enum dwarf_attribute attr_kind; | |
4738 | const char *lbl_id; | |
a3f97cbb | 4739 | { |
b3694847 | 4740 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4741 | |
3f76745e JM |
4742 | attr->dw_attr_next = NULL; |
4743 | attr->dw_attr = attr_kind; | |
4744 | attr->dw_attr_val.val_class = dw_val_class_lbl_id; | |
4745 | attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); | |
4746 | add_dwarf_attr (die, attr); | |
4747 | } | |
71dfc51f | 4748 | |
3f76745e JM |
4749 | /* Add a section offset attribute value to a DIE. */ |
4750 | ||
4751 | static inline void | |
8b790721 | 4752 | add_AT_lbl_offset (die, attr_kind, label) |
b3694847 SS |
4753 | dw_die_ref die; |
4754 | enum dwarf_attribute attr_kind; | |
4755 | const char *label; | |
3f76745e | 4756 | { |
b3694847 | 4757 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4758 | |
3f76745e JM |
4759 | attr->dw_attr_next = NULL; |
4760 | attr->dw_attr = attr_kind; | |
8b790721 | 4761 | attr->dw_attr_val.val_class = dw_val_class_lbl_offset; |
a96c67ec | 4762 | attr->dw_attr_val.v.val_lbl_id = xstrdup (label); |
3f76745e | 4763 | add_dwarf_attr (die, attr); |
a3f97cbb JW |
4764 | } |
4765 | ||
a20612aa RH |
4766 | /* Add an offset attribute value to a DIE. */ |
4767 | ||
2bee6045 | 4768 | static inline void |
a20612aa | 4769 | add_AT_offset (die, attr_kind, offset) |
b3694847 SS |
4770 | dw_die_ref die; |
4771 | enum dwarf_attribute attr_kind; | |
4772 | unsigned long offset; | |
a20612aa | 4773 | { |
b3694847 | 4774 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
a20612aa RH |
4775 | |
4776 | attr->dw_attr_next = NULL; | |
4777 | attr->dw_attr = attr_kind; | |
4778 | attr->dw_attr_val.val_class = dw_val_class_offset; | |
4779 | attr->dw_attr_val.v.val_offset = offset; | |
4780 | add_dwarf_attr (die, attr); | |
4781 | } | |
4782 | ||
2bee6045 JJ |
4783 | /* Add an range_list attribute value to a DIE. */ |
4784 | ||
4785 | static void | |
4786 | add_AT_range_list (die, attr_kind, offset) | |
4787 | dw_die_ref die; | |
4788 | enum dwarf_attribute attr_kind; | |
4789 | unsigned long offset; | |
4790 | { | |
4791 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
4792 | ||
4793 | attr->dw_attr_next = NULL; | |
4794 | attr->dw_attr = attr_kind; | |
4795 | attr->dw_attr_val.val_class = dw_val_class_range_list; | |
4796 | attr->dw_attr_val.v.val_offset = offset; | |
4797 | add_dwarf_attr (die, attr); | |
4798 | } | |
4799 | ||
a96c67ec JM |
4800 | static inline const char * |
4801 | AT_lbl (a) | |
b3694847 | 4802 | dw_attr_ref a; |
a3f97cbb | 4803 | { |
a96c67ec JM |
4804 | if (a && (AT_class (a) == dw_val_class_lbl_id |
4805 | || AT_class (a) == dw_val_class_lbl_offset)) | |
4806 | return a->dw_attr_val.v.val_lbl_id; | |
71dfc51f | 4807 | |
40e8cc95 | 4808 | abort (); |
a3f97cbb JW |
4809 | } |
4810 | ||
3f76745e | 4811 | /* Get the attribute of type attr_kind. */ |
71dfc51f | 4812 | |
3f76745e JM |
4813 | static inline dw_attr_ref |
4814 | get_AT (die, attr_kind) | |
b3694847 SS |
4815 | dw_die_ref die; |
4816 | enum dwarf_attribute attr_kind; | |
f37230f0 | 4817 | { |
b3694847 SS |
4818 | dw_attr_ref a; |
4819 | dw_die_ref spec = NULL; | |
556273e0 | 4820 | |
3f76745e JM |
4821 | if (die != NULL) |
4822 | { | |
4823 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
2ad9852d RK |
4824 | if (a->dw_attr == attr_kind) |
4825 | return a; | |
4826 | else if (a->dw_attr == DW_AT_specification | |
4827 | || a->dw_attr == DW_AT_abstract_origin) | |
4828 | spec = AT_ref (a); | |
71dfc51f | 4829 | |
3f76745e JM |
4830 | if (spec) |
4831 | return get_AT (spec, attr_kind); | |
4832 | } | |
4833 | ||
4834 | return NULL; | |
f37230f0 JM |
4835 | } |
4836 | ||
2ad9852d RK |
4837 | /* Return the "low pc" attribute value, typically associated with a subprogram |
4838 | DIE. Return null if the "low pc" attribute is either not present, or if it | |
4839 | cannot be represented as an assembler label identifier. */ | |
71dfc51f | 4840 | |
a96c67ec | 4841 | static inline const char * |
3f76745e | 4842 | get_AT_low_pc (die) |
b3694847 | 4843 | dw_die_ref die; |
7e23cb16 | 4844 | { |
b3694847 | 4845 | dw_attr_ref a = get_AT (die, DW_AT_low_pc); |
2ad9852d | 4846 | |
40e8cc95 | 4847 | return a ? AT_lbl (a) : NULL; |
7e23cb16 JM |
4848 | } |
4849 | ||
2ad9852d RK |
4850 | /* Return the "high pc" attribute value, typically associated with a subprogram |
4851 | DIE. Return null if the "high pc" attribute is either not present, or if it | |
4852 | cannot be represented as an assembler label identifier. */ | |
71dfc51f | 4853 | |
a96c67ec | 4854 | static inline const char * |
3f76745e | 4855 | get_AT_hi_pc (die) |
b3694847 | 4856 | dw_die_ref die; |
a3f97cbb | 4857 | { |
b3694847 | 4858 | dw_attr_ref a = get_AT (die, DW_AT_high_pc); |
2ad9852d | 4859 | |
40e8cc95 | 4860 | return a ? AT_lbl (a) : NULL; |
3f76745e JM |
4861 | } |
4862 | ||
4863 | /* Return the value of the string attribute designated by ATTR_KIND, or | |
4864 | NULL if it is not present. */ | |
71dfc51f | 4865 | |
a96c67ec | 4866 | static inline const char * |
3f76745e | 4867 | get_AT_string (die, attr_kind) |
b3694847 SS |
4868 | dw_die_ref die; |
4869 | enum dwarf_attribute attr_kind; | |
3f76745e | 4870 | { |
b3694847 | 4871 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4872 | |
40e8cc95 | 4873 | return a ? AT_string (a) : NULL; |
a3f97cbb JW |
4874 | } |
4875 | ||
3f76745e JM |
4876 | /* Return the value of the flag attribute designated by ATTR_KIND, or -1 |
4877 | if it is not present. */ | |
71dfc51f | 4878 | |
3f76745e JM |
4879 | static inline int |
4880 | get_AT_flag (die, attr_kind) | |
b3694847 SS |
4881 | dw_die_ref die; |
4882 | enum dwarf_attribute attr_kind; | |
a3f97cbb | 4883 | { |
b3694847 | 4884 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4885 | |
40e8cc95 | 4886 | return a ? AT_flag (a) : 0; |
a3f97cbb JW |
4887 | } |
4888 | ||
3f76745e JM |
4889 | /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0 |
4890 | if it is not present. */ | |
71dfc51f | 4891 | |
3f76745e JM |
4892 | static inline unsigned |
4893 | get_AT_unsigned (die, attr_kind) | |
b3694847 SS |
4894 | dw_die_ref die; |
4895 | enum dwarf_attribute attr_kind; | |
a3f97cbb | 4896 | { |
b3694847 | 4897 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4898 | |
40e8cc95 | 4899 | return a ? AT_unsigned (a) : 0; |
a96c67ec | 4900 | } |
71dfc51f | 4901 | |
a96c67ec JM |
4902 | static inline dw_die_ref |
4903 | get_AT_ref (die, attr_kind) | |
4904 | dw_die_ref die; | |
b3694847 | 4905 | enum dwarf_attribute attr_kind; |
a96c67ec | 4906 | { |
b3694847 | 4907 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4908 | |
40e8cc95 | 4909 | return a ? AT_ref (a) : NULL; |
3f76745e | 4910 | } |
71dfc51f | 4911 | |
3f76745e JM |
4912 | static inline int |
4913 | is_c_family () | |
4914 | { | |
b3694847 | 4915 | unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
71dfc51f | 4916 | |
3f76745e JM |
4917 | return (lang == DW_LANG_C || lang == DW_LANG_C89 |
4918 | || lang == DW_LANG_C_plus_plus); | |
556273e0 | 4919 | } |
71dfc51f | 4920 | |
1d3d6b1e JM |
4921 | static inline int |
4922 | is_cxx () | |
4923 | { | |
4924 | return (get_AT_unsigned (comp_unit_die, DW_AT_language) | |
4925 | == DW_LANG_C_plus_plus); | |
c26fbbca | 4926 | } |
1d3d6b1e | 4927 | |
3f76745e JM |
4928 | static inline int |
4929 | is_fortran () | |
4930 | { | |
b3694847 | 4931 | unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
71dfc51f | 4932 | |
3f76745e | 4933 | return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90); |
556273e0 | 4934 | } |
71dfc51f | 4935 | |
28985b81 AG |
4936 | static inline int |
4937 | is_java () | |
4938 | { | |
b3694847 | 4939 | unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
28985b81 AG |
4940 | |
4941 | return (lang == DW_LANG_Java); | |
4942 | } | |
4943 | ||
10a11b75 | 4944 | /* Free up the memory used by A. */ |
71dfc51f | 4945 | |
c6991660 | 4946 | static inline void free_AT PARAMS ((dw_attr_ref)); |
3f76745e | 4947 | static inline void |
10a11b75 JM |
4948 | free_AT (a) |
4949 | dw_attr_ref a; | |
4950 | { | |
4951 | switch (AT_class (a)) | |
4952 | { | |
10a11b75 | 4953 | case dw_val_class_str: |
9eb4015a JJ |
4954 | if (a->dw_attr_val.v.val_str->refcount) |
4955 | a->dw_attr_val.v.val_str->refcount--; | |
4956 | break; | |
4957 | ||
10a11b75 JM |
4958 | case dw_val_class_lbl_id: |
4959 | case dw_val_class_lbl_offset: | |
9eb4015a | 4960 | free (a->dw_attr_val.v.val_lbl_id); |
10a11b75 JM |
4961 | break; |
4962 | ||
3724ec07 WC |
4963 | case dw_val_class_float: |
4964 | free (a->dw_attr_val.v.val_float.array); | |
4965 | break; | |
0b34cf1e | 4966 | |
10a11b75 JM |
4967 | default: |
4968 | break; | |
4969 | } | |
4970 | ||
4971 | free (a); | |
556273e0 | 4972 | } |
10a11b75 JM |
4973 | |
4974 | /* Remove the specified attribute if present. */ | |
4975 | ||
4976 | static void | |
3f76745e | 4977 | remove_AT (die, attr_kind) |
b3694847 SS |
4978 | dw_die_ref die; |
4979 | enum dwarf_attribute attr_kind; | |
3f76745e | 4980 | { |
b3694847 SS |
4981 | dw_attr_ref *p; |
4982 | dw_attr_ref removed = NULL; | |
a3f97cbb | 4983 | |
3f76745e JM |
4984 | if (die != NULL) |
4985 | { | |
a96c67ec JM |
4986 | for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next)) |
4987 | if ((*p)->dw_attr == attr_kind) | |
4988 | { | |
4989 | removed = *p; | |
4990 | *p = (*p)->dw_attr_next; | |
4991 | break; | |
4992 | } | |
71dfc51f | 4993 | |
a96c67ec | 4994 | if (removed != 0) |
10a11b75 JM |
4995 | free_AT (removed); |
4996 | } | |
4997 | } | |
71dfc51f | 4998 | |
10a11b75 | 4999 | /* Free up the memory used by DIE. */ |
71dfc51f | 5000 | |
10a11b75 JM |
5001 | static inline void |
5002 | free_die (die) | |
5003 | dw_die_ref die; | |
5004 | { | |
5005 | remove_children (die); | |
5006 | free (die); | |
3f76745e | 5007 | } |
71dfc51f | 5008 | |
3f76745e | 5009 | /* Discard the children of this DIE. */ |
71dfc51f | 5010 | |
10a11b75 | 5011 | static void |
3f76745e | 5012 | remove_children (die) |
b3694847 | 5013 | dw_die_ref die; |
3f76745e | 5014 | { |
b3694847 | 5015 | dw_die_ref child_die = die->die_child; |
3f76745e JM |
5016 | |
5017 | die->die_child = NULL; | |
3f76745e JM |
5018 | |
5019 | while (child_die != NULL) | |
a3f97cbb | 5020 | { |
b3694847 SS |
5021 | dw_die_ref tmp_die = child_die; |
5022 | dw_attr_ref a; | |
71dfc51f | 5023 | |
3f76745e | 5024 | child_die = child_die->die_sib; |
556273e0 KH |
5025 | |
5026 | for (a = tmp_die->die_attr; a != NULL;) | |
a3f97cbb | 5027 | { |
b3694847 | 5028 | dw_attr_ref tmp_a = a; |
71dfc51f | 5029 | |
3f76745e | 5030 | a = a->dw_attr_next; |
10a11b75 | 5031 | free_AT (tmp_a); |
a3f97cbb | 5032 | } |
71dfc51f | 5033 | |
10a11b75 | 5034 | free_die (tmp_die); |
3f76745e JM |
5035 | } |
5036 | } | |
71dfc51f | 5037 | |
a96c67ec | 5038 | /* Add a child DIE below its parent. We build the lists up in reverse |
881c6935 | 5039 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f | 5040 | |
3f76745e JM |
5041 | static inline void |
5042 | add_child_die (die, child_die) | |
b3694847 SS |
5043 | dw_die_ref die; |
5044 | dw_die_ref child_die; | |
3f76745e JM |
5045 | { |
5046 | if (die != NULL && child_die != NULL) | |
e90b62db | 5047 | { |
3a88cbd1 JL |
5048 | if (die == child_die) |
5049 | abort (); | |
2ad9852d | 5050 | |
3f76745e | 5051 | child_die->die_parent = die; |
a96c67ec JM |
5052 | child_die->die_sib = die->die_child; |
5053 | die->die_child = child_die; | |
3f76745e JM |
5054 | } |
5055 | } | |
5056 | ||
2081603c JM |
5057 | /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT |
5058 | is the specification, to the front of PARENT's list of children. */ | |
10a11b75 JM |
5059 | |
5060 | static void | |
5061 | splice_child_die (parent, child) | |
5062 | dw_die_ref parent, child; | |
5063 | { | |
5064 | dw_die_ref *p; | |
5065 | ||
5066 | /* We want the declaration DIE from inside the class, not the | |
5067 | specification DIE at toplevel. */ | |
5068 | if (child->die_parent != parent) | |
2081603c JM |
5069 | { |
5070 | dw_die_ref tmp = get_AT_ref (child, DW_AT_specification); | |
2ad9852d | 5071 | |
2081603c JM |
5072 | if (tmp) |
5073 | child = tmp; | |
5074 | } | |
10a11b75 | 5075 | |
2081603c JM |
5076 | if (child->die_parent != parent |
5077 | && child->die_parent != get_AT_ref (parent, DW_AT_specification)) | |
10a11b75 JM |
5078 | abort (); |
5079 | ||
5de0e8d4 | 5080 | for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib)) |
10a11b75 JM |
5081 | if (*p == child) |
5082 | { | |
5083 | *p = child->die_sib; | |
5084 | break; | |
5085 | } | |
5086 | ||
5087 | child->die_sib = parent->die_child; | |
5088 | parent->die_child = child; | |
5089 | } | |
5090 | ||
3f76745e JM |
5091 | /* Return a pointer to a newly created DIE node. */ |
5092 | ||
5093 | static inline dw_die_ref | |
54ba1f0d | 5094 | new_die (tag_value, parent_die, t) |
b3694847 SS |
5095 | enum dwarf_tag tag_value; |
5096 | dw_die_ref parent_die; | |
54ba1f0d | 5097 | tree t; |
3f76745e | 5098 | { |
b3694847 | 5099 | dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node)); |
3f76745e JM |
5100 | |
5101 | die->die_tag = tag_value; | |
3f76745e JM |
5102 | |
5103 | if (parent_die != NULL) | |
5104 | add_child_die (parent_die, die); | |
5105 | else | |
ef76d03b JW |
5106 | { |
5107 | limbo_die_node *limbo_node; | |
5108 | ||
5109 | limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node)); | |
5110 | limbo_node->die = die; | |
54ba1f0d | 5111 | limbo_node->created_for = t; |
ef76d03b JW |
5112 | limbo_node->next = limbo_die_list; |
5113 | limbo_die_list = limbo_node; | |
5114 | } | |
71dfc51f | 5115 | |
3f76745e JM |
5116 | return die; |
5117 | } | |
71dfc51f | 5118 | |
3f76745e | 5119 | /* Return the DIE associated with the given type specifier. */ |
71dfc51f | 5120 | |
3f76745e JM |
5121 | static inline dw_die_ref |
5122 | lookup_type_die (type) | |
b3694847 | 5123 | tree type; |
3f76745e JM |
5124 | { |
5125 | return (dw_die_ref) TYPE_SYMTAB_POINTER (type); | |
5126 | } | |
e90b62db | 5127 | |
3f76745e | 5128 | /* Equate a DIE to a given type specifier. */ |
71dfc51f | 5129 | |
10a11b75 | 5130 | static inline void |
3f76745e | 5131 | equate_type_number_to_die (type, type_die) |
b3694847 SS |
5132 | tree type; |
5133 | dw_die_ref type_die; | |
3f76745e JM |
5134 | { |
5135 | TYPE_SYMTAB_POINTER (type) = (char *) type_die; | |
5136 | } | |
71dfc51f | 5137 | |
3f76745e | 5138 | /* Return the DIE associated with a given declaration. */ |
71dfc51f | 5139 | |
3f76745e JM |
5140 | static inline dw_die_ref |
5141 | lookup_decl_die (decl) | |
b3694847 | 5142 | tree decl; |
3f76745e | 5143 | { |
b3694847 | 5144 | unsigned decl_id = DECL_UID (decl); |
3f76745e | 5145 | |
2ad9852d | 5146 | return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL); |
a3f97cbb JW |
5147 | } |
5148 | ||
3f76745e | 5149 | /* Equate a DIE to a particular declaration. */ |
71dfc51f | 5150 | |
3f76745e JM |
5151 | static void |
5152 | equate_decl_number_to_die (decl, decl_die) | |
b3694847 SS |
5153 | tree decl; |
5154 | dw_die_ref decl_die; | |
a3f97cbb | 5155 | { |
aea9695c RK |
5156 | unsigned int decl_id = DECL_UID (decl); |
5157 | unsigned int num_allocated; | |
d291dd49 | 5158 | |
3f76745e | 5159 | if (decl_id >= decl_die_table_allocated) |
a3f97cbb | 5160 | { |
3f76745e JM |
5161 | num_allocated |
5162 | = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1) | |
5163 | / DECL_DIE_TABLE_INCREMENT) | |
5164 | * DECL_DIE_TABLE_INCREMENT; | |
5165 | ||
5166 | decl_die_table | |
5167 | = (dw_die_ref *) xrealloc (decl_die_table, | |
5168 | sizeof (dw_die_ref) * num_allocated); | |
5169 | ||
961192e1 | 5170 | memset ((char *) &decl_die_table[decl_die_table_allocated], 0, |
3f76745e JM |
5171 | (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref)); |
5172 | decl_die_table_allocated = num_allocated; | |
a3f97cbb | 5173 | } |
71dfc51f | 5174 | |
3f76745e JM |
5175 | if (decl_id >= decl_die_table_in_use) |
5176 | decl_die_table_in_use = (decl_id + 1); | |
5177 | ||
5178 | decl_die_table[decl_id] = decl_die; | |
a3f97cbb | 5179 | } |
3f76745e JM |
5180 | \f |
5181 | /* Keep track of the number of spaces used to indent the | |
5182 | output of the debugging routines that print the structure of | |
5183 | the DIE internal representation. */ | |
5184 | static int print_indent; | |
71dfc51f | 5185 | |
3f76745e JM |
5186 | /* Indent the line the number of spaces given by print_indent. */ |
5187 | ||
5188 | static inline void | |
5189 | print_spaces (outfile) | |
5190 | FILE *outfile; | |
5191 | { | |
5192 | fprintf (outfile, "%*s", print_indent, ""); | |
a3f97cbb JW |
5193 | } |
5194 | ||
956d6950 | 5195 | /* Print the information associated with a given DIE, and its children. |
3f76745e | 5196 | This routine is a debugging aid only. */ |
71dfc51f | 5197 | |
a3f97cbb | 5198 | static void |
3f76745e JM |
5199 | print_die (die, outfile) |
5200 | dw_die_ref die; | |
5201 | FILE *outfile; | |
a3f97cbb | 5202 | { |
b3694847 SS |
5203 | dw_attr_ref a; |
5204 | dw_die_ref c; | |
71dfc51f | 5205 | |
3f76745e | 5206 | print_spaces (outfile); |
2d8b0f3a | 5207 | fprintf (outfile, "DIE %4lu: %s\n", |
3f76745e JM |
5208 | die->die_offset, dwarf_tag_name (die->die_tag)); |
5209 | print_spaces (outfile); | |
2d8b0f3a JL |
5210 | fprintf (outfile, " abbrev id: %lu", die->die_abbrev); |
5211 | fprintf (outfile, " offset: %lu\n", die->die_offset); | |
3f76745e JM |
5212 | |
5213 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
a3f97cbb | 5214 | { |
3f76745e JM |
5215 | print_spaces (outfile); |
5216 | fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr)); | |
5217 | ||
a96c67ec | 5218 | switch (AT_class (a)) |
3f76745e JM |
5219 | { |
5220 | case dw_val_class_addr: | |
5221 | fprintf (outfile, "address"); | |
5222 | break; | |
a20612aa RH |
5223 | case dw_val_class_offset: |
5224 | fprintf (outfile, "offset"); | |
5225 | break; | |
3f76745e JM |
5226 | case dw_val_class_loc: |
5227 | fprintf (outfile, "location descriptor"); | |
5228 | break; | |
63e46568 | 5229 | case dw_val_class_loc_list: |
a20612aa RH |
5230 | fprintf (outfile, "location list -> label:%s", |
5231 | AT_loc_list (a)->ll_symbol); | |
63e46568 | 5232 | break; |
2bee6045 JJ |
5233 | case dw_val_class_range_list: |
5234 | fprintf (outfile, "range list"); | |
5235 | break; | |
3f76745e | 5236 | case dw_val_class_const: |
a96c67ec | 5237 | fprintf (outfile, "%ld", AT_int (a)); |
3f76745e JM |
5238 | break; |
5239 | case dw_val_class_unsigned_const: | |
a96c67ec | 5240 | fprintf (outfile, "%lu", AT_unsigned (a)); |
3f76745e JM |
5241 | break; |
5242 | case dw_val_class_long_long: | |
2d8b0f3a | 5243 | fprintf (outfile, "constant (%lu,%lu)", |
556273e0 KH |
5244 | a->dw_attr_val.v.val_long_long.hi, |
5245 | a->dw_attr_val.v.val_long_long.low); | |
3f76745e JM |
5246 | break; |
5247 | case dw_val_class_float: | |
5248 | fprintf (outfile, "floating-point constant"); | |
5249 | break; | |
5250 | case dw_val_class_flag: | |
a96c67ec | 5251 | fprintf (outfile, "%u", AT_flag (a)); |
3f76745e JM |
5252 | break; |
5253 | case dw_val_class_die_ref: | |
a96c67ec | 5254 | if (AT_ref (a) != NULL) |
881c6935 | 5255 | { |
1bfb5f8f | 5256 | if (AT_ref (a)->die_symbol) |
881c6935 JM |
5257 | fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol); |
5258 | else | |
5259 | fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset); | |
5260 | } | |
3f76745e JM |
5261 | else |
5262 | fprintf (outfile, "die -> <null>"); | |
5263 | break; | |
5264 | case dw_val_class_lbl_id: | |
8b790721 | 5265 | case dw_val_class_lbl_offset: |
a96c67ec | 5266 | fprintf (outfile, "label: %s", AT_lbl (a)); |
3f76745e | 5267 | break; |
3f76745e | 5268 | case dw_val_class_str: |
a96c67ec JM |
5269 | if (AT_string (a) != NULL) |
5270 | fprintf (outfile, "\"%s\"", AT_string (a)); | |
3f76745e JM |
5271 | else |
5272 | fprintf (outfile, "<null>"); | |
5273 | break; | |
e9a25f70 JL |
5274 | default: |
5275 | break; | |
3f76745e JM |
5276 | } |
5277 | ||
5278 | fprintf (outfile, "\n"); | |
5279 | } | |
5280 | ||
5281 | if (die->die_child != NULL) | |
5282 | { | |
5283 | print_indent += 4; | |
5284 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5285 | print_die (c, outfile); | |
71dfc51f | 5286 | |
3f76745e | 5287 | print_indent -= 4; |
a3f97cbb | 5288 | } |
881c6935 JM |
5289 | if (print_indent == 0) |
5290 | fprintf (outfile, "\n"); | |
a3f97cbb JW |
5291 | } |
5292 | ||
3f76745e JM |
5293 | /* Print the contents of the source code line number correspondence table. |
5294 | This routine is a debugging aid only. */ | |
71dfc51f | 5295 | |
3f76745e JM |
5296 | static void |
5297 | print_dwarf_line_table (outfile) | |
5298 | FILE *outfile; | |
a3f97cbb | 5299 | { |
b3694847 SS |
5300 | unsigned i; |
5301 | dw_line_info_ref line_info; | |
3f76745e JM |
5302 | |
5303 | fprintf (outfile, "\n\nDWARF source line information\n"); | |
2ad9852d | 5304 | for (i = 1; i < line_info_table_in_use; i++) |
a3f97cbb | 5305 | { |
3f76745e JM |
5306 | line_info = &line_info_table[i]; |
5307 | fprintf (outfile, "%5d: ", i); | |
981975b6 | 5308 | fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]); |
2d8b0f3a | 5309 | fprintf (outfile, "%6ld", line_info->dw_line_num); |
3f76745e | 5310 | fprintf (outfile, "\n"); |
a3f97cbb | 5311 | } |
3f76745e JM |
5312 | |
5313 | fprintf (outfile, "\n\n"); | |
f37230f0 JM |
5314 | } |
5315 | ||
3f76745e JM |
5316 | /* Print the information collected for a given DIE. */ |
5317 | ||
5318 | void | |
5319 | debug_dwarf_die (die) | |
5320 | dw_die_ref die; | |
5321 | { | |
5322 | print_die (die, stderr); | |
5323 | } | |
5324 | ||
5325 | /* Print all DWARF information collected for the compilation unit. | |
5326 | This routine is a debugging aid only. */ | |
5327 | ||
5328 | void | |
5329 | debug_dwarf () | |
5330 | { | |
5331 | print_indent = 0; | |
5332 | print_die (comp_unit_die, stderr); | |
b2244e22 JW |
5333 | if (! DWARF2_ASM_LINE_DEBUG_INFO) |
5334 | print_dwarf_line_table (stderr); | |
3f76745e JM |
5335 | } |
5336 | \f | |
a96c67ec JM |
5337 | /* We build up the lists of children and attributes by pushing new ones |
5338 | onto the beginning of the list. Reverse the lists for DIE so that | |
5339 | they are in order of addition. */ | |
71dfc51f | 5340 | |
f37230f0 | 5341 | static void |
a96c67ec | 5342 | reverse_die_lists (die) |
b3694847 | 5343 | dw_die_ref die; |
f37230f0 | 5344 | { |
b3694847 SS |
5345 | dw_die_ref c, cp, cn; |
5346 | dw_attr_ref a, ap, an; | |
71dfc51f | 5347 | |
a96c67ec | 5348 | for (a = die->die_attr, ap = 0; a; a = an) |
7d9d8943 AM |
5349 | { |
5350 | an = a->dw_attr_next; | |
5351 | a->dw_attr_next = ap; | |
5352 | ap = a; | |
a3f97cbb | 5353 | } |
2ad9852d | 5354 | |
7d9d8943 | 5355 | die->die_attr = ap; |
3f76745e | 5356 | |
7d9d8943 AM |
5357 | for (c = die->die_child, cp = 0; c; c = cn) |
5358 | { | |
5359 | cn = c->die_sib; | |
5360 | c->die_sib = cp; | |
5361 | cp = c; | |
5362 | } | |
2ad9852d | 5363 | |
7d9d8943 | 5364 | die->die_child = cp; |
a3f97cbb JW |
5365 | } |
5366 | ||
2ad9852d RK |
5367 | /* reverse_die_lists only reverses the single die you pass it. Since we used to |
5368 | reverse all dies in add_sibling_attributes, which runs through all the dies, | |
5369 | it would reverse all the dies. Now, however, since we don't call | |
5370 | reverse_die_lists in add_sibling_attributes, we need a routine to | |
5371 | recursively reverse all the dies. This is that routine. */ | |
71dfc51f | 5372 | |
7d9d8943 | 5373 | static void |
881c6935 | 5374 | reverse_all_dies (die) |
b3694847 | 5375 | dw_die_ref die; |
a3f97cbb | 5376 | { |
b3694847 | 5377 | dw_die_ref c; |
71dfc51f | 5378 | |
7d9d8943 | 5379 | reverse_die_lists (die); |
3f76745e | 5380 | |
881c6935 JM |
5381 | for (c = die->die_child; c; c = c->die_sib) |
5382 | reverse_all_dies (c); | |
5383 | } | |
5384 | ||
2ad9852d RK |
5385 | /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU |
5386 | for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL | |
5387 | DIE that marks the start of the DIEs for this include file. */ | |
881c6935 JM |
5388 | |
5389 | static dw_die_ref | |
5390 | push_new_compile_unit (old_unit, bincl_die) | |
5391 | dw_die_ref old_unit, bincl_die; | |
5392 | { | |
5393 | const char *filename = get_AT_string (bincl_die, DW_AT_name); | |
5394 | dw_die_ref new_unit = gen_compile_unit_die (filename); | |
2ad9852d | 5395 | |
881c6935 JM |
5396 | new_unit->die_sib = old_unit; |
5397 | return new_unit; | |
5398 | } | |
5399 | ||
5400 | /* Close an include-file CU and reopen the enclosing one. */ | |
5401 | ||
5402 | static dw_die_ref | |
5403 | pop_compile_unit (old_unit) | |
5404 | dw_die_ref old_unit; | |
5405 | { | |
5406 | dw_die_ref new_unit = old_unit->die_sib; | |
2ad9852d | 5407 | |
881c6935 JM |
5408 | old_unit->die_sib = NULL; |
5409 | return new_unit; | |
5410 | } | |
5411 | ||
2ad9852d RK |
5412 | #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx) |
5413 | #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx) | |
881c6935 JM |
5414 | |
5415 | /* Calculate the checksum of a location expression. */ | |
5416 | ||
5417 | static inline void | |
5418 | loc_checksum (loc, ctx) | |
5419 | dw_loc_descr_ref loc; | |
5420 | struct md5_ctx *ctx; | |
5421 | { | |
2ad9852d RK |
5422 | CHECKSUM (loc->dw_loc_opc); |
5423 | CHECKSUM (loc->dw_loc_oprnd1); | |
5424 | CHECKSUM (loc->dw_loc_oprnd2); | |
881c6935 JM |
5425 | } |
5426 | ||
5427 | /* Calculate the checksum of an attribute. */ | |
5428 | ||
5429 | static void | |
5430 | attr_checksum (at, ctx) | |
5431 | dw_attr_ref at; | |
5432 | struct md5_ctx *ctx; | |
5433 | { | |
5434 | dw_loc_descr_ref loc; | |
5435 | rtx r; | |
5436 | ||
2ad9852d | 5437 | CHECKSUM (at->dw_attr); |
881c6935 JM |
5438 | |
5439 | /* We don't care about differences in file numbering. */ | |
5f632b5e JM |
5440 | if (at->dw_attr == DW_AT_decl_file |
5441 | /* Or that this was compiled with a different compiler snapshot; if | |
5442 | the output is the same, that's what matters. */ | |
5443 | || at->dw_attr == DW_AT_producer) | |
881c6935 JM |
5444 | return; |
5445 | ||
5446 | switch (AT_class (at)) | |
5447 | { | |
5448 | case dw_val_class_const: | |
2ad9852d | 5449 | CHECKSUM (at->dw_attr_val.v.val_int); |
881c6935 JM |
5450 | break; |
5451 | case dw_val_class_unsigned_const: | |
2ad9852d | 5452 | CHECKSUM (at->dw_attr_val.v.val_unsigned); |
881c6935 JM |
5453 | break; |
5454 | case dw_val_class_long_long: | |
2ad9852d | 5455 | CHECKSUM (at->dw_attr_val.v.val_long_long); |
881c6935 JM |
5456 | break; |
5457 | case dw_val_class_float: | |
2ad9852d | 5458 | CHECKSUM (at->dw_attr_val.v.val_float); |
881c6935 JM |
5459 | break; |
5460 | case dw_val_class_flag: | |
2ad9852d | 5461 | CHECKSUM (at->dw_attr_val.v.val_flag); |
881c6935 | 5462 | break; |
881c6935 | 5463 | case dw_val_class_str: |
2ad9852d | 5464 | CHECKSUM_STRING (AT_string (at)); |
881c6935 | 5465 | break; |
a20612aa | 5466 | |
881c6935 JM |
5467 | case dw_val_class_addr: |
5468 | r = AT_addr (at); | |
5469 | switch (GET_CODE (r)) | |
5470 | { | |
5471 | case SYMBOL_REF: | |
2ad9852d | 5472 | CHECKSUM_STRING (XSTR (r, 0)); |
881c6935 JM |
5473 | break; |
5474 | ||
5475 | default: | |
5476 | abort (); | |
5477 | } | |
5478 | break; | |
5479 | ||
a20612aa | 5480 | case dw_val_class_offset: |
2ad9852d | 5481 | CHECKSUM (at->dw_attr_val.v.val_offset); |
a20612aa RH |
5482 | break; |
5483 | ||
881c6935 JM |
5484 | case dw_val_class_loc: |
5485 | for (loc = AT_loc (at); loc; loc = loc->dw_loc_next) | |
5486 | loc_checksum (loc, ctx); | |
5487 | break; | |
5488 | ||
5489 | case dw_val_class_die_ref: | |
5490 | if (AT_ref (at)->die_offset) | |
2ad9852d | 5491 | CHECKSUM (AT_ref (at)->die_offset); |
881c6935 JM |
5492 | /* FIXME else use target die name or something. */ |
5493 | ||
5494 | case dw_val_class_fde_ref: | |
5495 | case dw_val_class_lbl_id: | |
5496 | case dw_val_class_lbl_offset: | |
a20612aa | 5497 | break; |
881c6935 JM |
5498 | |
5499 | default: | |
5500 | break; | |
5501 | } | |
5502 | } | |
5503 | ||
5504 | /* Calculate the checksum of a DIE. */ | |
5505 | ||
5506 | static void | |
5507 | die_checksum (die, ctx) | |
5508 | dw_die_ref die; | |
5509 | struct md5_ctx *ctx; | |
5510 | { | |
5511 | dw_die_ref c; | |
5512 | dw_attr_ref a; | |
5513 | ||
2ad9852d | 5514 | CHECKSUM (die->die_tag); |
881c6935 JM |
5515 | |
5516 | for (a = die->die_attr; a; a = a->dw_attr_next) | |
5517 | attr_checksum (a, ctx); | |
5518 | ||
5519 | for (c = die->die_child; c; c = c->die_sib) | |
5520 | die_checksum (c, ctx); | |
5521 | } | |
5522 | ||
2ad9852d RK |
5523 | #undef CHECKSUM |
5524 | #undef CHECKSUM_STRING | |
881c6935 JM |
5525 | |
5526 | /* The prefix to attach to symbols on DIEs in the current comdat debug | |
5527 | info section. */ | |
5528 | static char *comdat_symbol_id; | |
5529 | ||
5530 | /* The index of the current symbol within the current comdat CU. */ | |
5531 | static unsigned int comdat_symbol_number; | |
5532 | ||
5533 | /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its | |
5534 | children, and set comdat_symbol_id accordingly. */ | |
5535 | ||
5536 | static void | |
5537 | compute_section_prefix (unit_die) | |
5538 | dw_die_ref unit_die; | |
5539 | { | |
f11c3043 RK |
5540 | const char *base = lbasename (get_AT_string (unit_die, DW_AT_name)); |
5541 | char *name = (char *) alloca (strlen (base) + 64); | |
5542 | char *p; | |
881c6935 JM |
5543 | int i; |
5544 | unsigned char checksum[16]; | |
5545 | struct md5_ctx ctx; | |
5546 | ||
f11c3043 RK |
5547 | /* Compute the checksum of the DIE, then append part of it as hex digits to |
5548 | the name filename of the unit. */ | |
5549 | ||
881c6935 JM |
5550 | md5_init_ctx (&ctx); |
5551 | die_checksum (unit_die, &ctx); | |
5552 | md5_finish_ctx (&ctx, checksum); | |
5553 | ||
0023400b | 5554 | sprintf (name, "%s.", base); |
881c6935 JM |
5555 | clean_symbol_name (name); |
5556 | ||
2ad9852d RK |
5557 | p = name + strlen (name); |
5558 | for (i = 0; i < 4; i++) | |
5559 | { | |
5560 | sprintf (p, "%.2x", checksum[i]); | |
5561 | p += 2; | |
5562 | } | |
881c6935 JM |
5563 | |
5564 | comdat_symbol_id = unit_die->die_symbol = xstrdup (name); | |
5565 | comdat_symbol_number = 0; | |
5566 | } | |
5567 | ||
f11c3043 | 5568 | /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */ |
881c6935 JM |
5569 | |
5570 | static int | |
5571 | is_type_die (die) | |
5572 | dw_die_ref die; | |
5573 | { | |
5574 | switch (die->die_tag) | |
5575 | { | |
5576 | case DW_TAG_array_type: | |
5577 | case DW_TAG_class_type: | |
5578 | case DW_TAG_enumeration_type: | |
5579 | case DW_TAG_pointer_type: | |
5580 | case DW_TAG_reference_type: | |
5581 | case DW_TAG_string_type: | |
5582 | case DW_TAG_structure_type: | |
5583 | case DW_TAG_subroutine_type: | |
5584 | case DW_TAG_union_type: | |
5585 | case DW_TAG_ptr_to_member_type: | |
5586 | case DW_TAG_set_type: | |
5587 | case DW_TAG_subrange_type: | |
5588 | case DW_TAG_base_type: | |
5589 | case DW_TAG_const_type: | |
5590 | case DW_TAG_file_type: | |
5591 | case DW_TAG_packed_type: | |
5592 | case DW_TAG_volatile_type: | |
5593 | return 1; | |
5594 | default: | |
5595 | return 0; | |
5596 | } | |
5597 | } | |
5598 | ||
5599 | /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU. | |
5600 | Basically, we want to choose the bits that are likely to be shared between | |
5601 | compilations (types) and leave out the bits that are specific to individual | |
5602 | compilations (functions). */ | |
5603 | ||
5604 | static int | |
5605 | is_comdat_die (c) | |
5606 | dw_die_ref c; | |
5607 | { | |
2ad9852d RK |
5608 | /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as |
5609 | we do for stabs. The advantage is a greater likelihood of sharing between | |
5610 | objects that don't include headers in the same order (and therefore would | |
5611 | put the base types in a different comdat). jason 8/28/00 */ | |
5612 | ||
881c6935 JM |
5613 | if (c->die_tag == DW_TAG_base_type) |
5614 | return 0; | |
5615 | ||
5616 | if (c->die_tag == DW_TAG_pointer_type | |
5617 | || c->die_tag == DW_TAG_reference_type | |
5618 | || c->die_tag == DW_TAG_const_type | |
5619 | || c->die_tag == DW_TAG_volatile_type) | |
5620 | { | |
5621 | dw_die_ref t = get_AT_ref (c, DW_AT_type); | |
2ad9852d | 5622 | |
881c6935 JM |
5623 | return t ? is_comdat_die (t) : 0; |
5624 | } | |
881c6935 JM |
5625 | |
5626 | return is_type_die (c); | |
5627 | } | |
5628 | ||
5629 | /* Returns 1 iff C is the sort of DIE that might be referred to from another | |
5630 | compilation unit. */ | |
5631 | ||
5632 | static int | |
5633 | is_symbol_die (c) | |
5634 | dw_die_ref c; | |
5635 | { | |
2ad9852d | 5636 | return (is_type_die (c) |
c26fbbca | 5637 | || (get_AT (c, DW_AT_declaration) |
2ad9852d | 5638 | && !get_AT (c, DW_AT_specification))); |
881c6935 JM |
5639 | } |
5640 | ||
5641 | static char * | |
63e46568 | 5642 | gen_internal_sym (prefix) |
173bf5be | 5643 | const char *prefix; |
881c6935 JM |
5644 | { |
5645 | char buf[256]; | |
5646 | static int label_num; | |
2ad9852d | 5647 | |
63e46568 | 5648 | ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++); |
881c6935 JM |
5649 | return xstrdup (buf); |
5650 | } | |
5651 | ||
5652 | /* Assign symbols to all worthy DIEs under DIE. */ | |
5653 | ||
5654 | static void | |
5655 | assign_symbol_names (die) | |
b3694847 | 5656 | dw_die_ref die; |
881c6935 | 5657 | { |
b3694847 | 5658 | dw_die_ref c; |
881c6935 JM |
5659 | |
5660 | if (is_symbol_die (die)) | |
5661 | { | |
5662 | if (comdat_symbol_id) | |
5663 | { | |
5664 | char *p = alloca (strlen (comdat_symbol_id) + 64); | |
2ad9852d | 5665 | |
881c6935 JM |
5666 | sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX, |
5667 | comdat_symbol_id, comdat_symbol_number++); | |
5668 | die->die_symbol = xstrdup (p); | |
5669 | } | |
5670 | else | |
63e46568 | 5671 | die->die_symbol = gen_internal_sym ("LDIE"); |
881c6935 JM |
5672 | } |
5673 | ||
5674 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5675 | assign_symbol_names (c); | |
5676 | } | |
5677 | ||
5678 | /* Traverse the DIE (which is always comp_unit_die), and set up | |
5679 | additional compilation units for each of the include files we see | |
5680 | bracketed by BINCL/EINCL. */ | |
5681 | ||
5682 | static void | |
5683 | break_out_includes (die) | |
b3694847 | 5684 | dw_die_ref die; |
881c6935 JM |
5685 | { |
5686 | dw_die_ref *ptr; | |
b3694847 | 5687 | dw_die_ref unit = NULL; |
881c6935 JM |
5688 | limbo_die_node *node; |
5689 | ||
c26fbbca | 5690 | for (ptr = &(die->die_child); *ptr;) |
881c6935 | 5691 | { |
b3694847 | 5692 | dw_die_ref c = *ptr; |
881c6935 | 5693 | |
2ad9852d | 5694 | if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL |
881c6935 JM |
5695 | || (unit && is_comdat_die (c))) |
5696 | { | |
5697 | /* This DIE is for a secondary CU; remove it from the main one. */ | |
5698 | *ptr = c->die_sib; | |
5699 | ||
5700 | if (c->die_tag == DW_TAG_GNU_BINCL) | |
5701 | { | |
5702 | unit = push_new_compile_unit (unit, c); | |
5703 | free_die (c); | |
5704 | } | |
5705 | else if (c->die_tag == DW_TAG_GNU_EINCL) | |
5706 | { | |
5707 | unit = pop_compile_unit (unit); | |
5708 | free_die (c); | |
5709 | } | |
5710 | else | |
5711 | add_child_die (unit, c); | |
5712 | } | |
5713 | else | |
5714 | { | |
5715 | /* Leave this DIE in the main CU. */ | |
5716 | ptr = &(c->die_sib); | |
5717 | continue; | |
5718 | } | |
5719 | } | |
5720 | ||
5721 | #if 0 | |
5722 | /* We can only use this in debugging, since the frontend doesn't check | |
0b34cf1e | 5723 | to make sure that we leave every include file we enter. */ |
881c6935 JM |
5724 | if (unit != NULL) |
5725 | abort (); | |
5726 | #endif | |
5727 | ||
5728 | assign_symbol_names (die); | |
5729 | for (node = limbo_die_list; node; node = node->next) | |
5730 | { | |
5731 | compute_section_prefix (node->die); | |
5732 | assign_symbol_names (node->die); | |
5733 | } | |
5734 | } | |
5735 | ||
5736 | /* Traverse the DIE and add a sibling attribute if it may have the | |
5737 | effect of speeding up access to siblings. To save some space, | |
5738 | avoid generating sibling attributes for DIE's without children. */ | |
5739 | ||
5740 | static void | |
5741 | add_sibling_attributes (die) | |
b3694847 | 5742 | dw_die_ref die; |
881c6935 | 5743 | { |
b3694847 | 5744 | dw_die_ref c; |
881c6935 JM |
5745 | |
5746 | if (die->die_tag != DW_TAG_compile_unit | |
5747 | && die->die_sib && die->die_child != NULL) | |
7d9d8943 AM |
5748 | /* Add the sibling link to the front of the attribute list. */ |
5749 | add_AT_die_ref (die, DW_AT_sibling, die->die_sib); | |
5750 | ||
5751 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5752 | add_sibling_attributes (c); | |
5753 | } | |
5754 | ||
2ad9852d RK |
5755 | /* Output all location lists for the DIE and its children. */ |
5756 | ||
63e46568 DB |
5757 | static void |
5758 | output_location_lists (die) | |
b3694847 | 5759 | dw_die_ref die; |
63e46568 DB |
5760 | { |
5761 | dw_die_ref c; | |
5762 | dw_attr_ref d_attr; | |
2ad9852d | 5763 | |
63e46568 | 5764 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) |
2ad9852d RK |
5765 | if (AT_class (d_attr) == dw_val_class_loc_list) |
5766 | output_loc_list (AT_loc_list (d_attr)); | |
5767 | ||
63e46568 DB |
5768 | for (c = die->die_child; c != NULL; c = c->die_sib) |
5769 | output_location_lists (c); | |
5770 | ||
5771 | } | |
c26fbbca | 5772 | |
2ad9852d RK |
5773 | /* The format of each DIE (and its attribute value pairs) is encoded in an |
5774 | abbreviation table. This routine builds the abbreviation table and assigns | |
5775 | a unique abbreviation id for each abbreviation entry. The children of each | |
5776 | die are visited recursively. */ | |
7d9d8943 AM |
5777 | |
5778 | static void | |
5779 | build_abbrev_table (die) | |
b3694847 | 5780 | dw_die_ref die; |
7d9d8943 | 5781 | { |
b3694847 SS |
5782 | unsigned long abbrev_id; |
5783 | unsigned int n_alloc; | |
5784 | dw_die_ref c; | |
5785 | dw_attr_ref d_attr, a_attr; | |
881c6935 JM |
5786 | |
5787 | /* Scan the DIE references, and mark as external any that refer to | |
1bfb5f8f | 5788 | DIEs from other CUs (i.e. those which are not marked). */ |
881c6935 | 5789 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) |
2ad9852d RK |
5790 | if (AT_class (d_attr) == dw_val_class_die_ref |
5791 | && AT_ref (d_attr)->die_mark == 0) | |
5792 | { | |
5793 | if (AT_ref (d_attr)->die_symbol == 0) | |
5794 | abort (); | |
5795 | ||
5796 | set_AT_ref_external (d_attr, 1); | |
5797 | } | |
881c6935 | 5798 | |
7d9d8943 AM |
5799 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
5800 | { | |
b3694847 | 5801 | dw_die_ref abbrev = abbrev_die_table[abbrev_id]; |
7d9d8943 AM |
5802 | |
5803 | if (abbrev->die_tag == die->die_tag) | |
5804 | { | |
5805 | if ((abbrev->die_child != NULL) == (die->die_child != NULL)) | |
5806 | { | |
5807 | a_attr = abbrev->die_attr; | |
5808 | d_attr = die->die_attr; | |
5809 | ||
5810 | while (a_attr != NULL && d_attr != NULL) | |
5811 | { | |
5812 | if ((a_attr->dw_attr != d_attr->dw_attr) | |
5813 | || (value_format (a_attr) != value_format (d_attr))) | |
5814 | break; | |
5815 | ||
5816 | a_attr = a_attr->dw_attr_next; | |
5817 | d_attr = d_attr->dw_attr_next; | |
5818 | } | |
5819 | ||
5820 | if (a_attr == NULL && d_attr == NULL) | |
5821 | break; | |
5822 | } | |
5823 | } | |
5824 | } | |
5825 | ||
5826 | if (abbrev_id >= abbrev_die_table_in_use) | |
5827 | { | |
5828 | if (abbrev_die_table_in_use >= abbrev_die_table_allocated) | |
5829 | { | |
5830 | n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT; | |
556273e0 | 5831 | abbrev_die_table |
7d9d8943 AM |
5832 | = (dw_die_ref *) xrealloc (abbrev_die_table, |
5833 | sizeof (dw_die_ref) * n_alloc); | |
5834 | ||
961192e1 | 5835 | memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0, |
7d9d8943 AM |
5836 | (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref)); |
5837 | abbrev_die_table_allocated = n_alloc; | |
5838 | } | |
5839 | ||
5840 | ++abbrev_die_table_in_use; | |
5841 | abbrev_die_table[abbrev_id] = die; | |
5842 | } | |
5843 | ||
5844 | die->die_abbrev = abbrev_id; | |
5845 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5846 | build_abbrev_table (c); | |
5847 | } | |
5848 | \f | |
3f76745e JM |
5849 | /* Return the power-of-two number of bytes necessary to represent VALUE. */ |
5850 | ||
5851 | static int | |
5852 | constant_size (value) | |
5853 | long unsigned value; | |
5854 | { | |
5855 | int log; | |
5856 | ||
5857 | if (value == 0) | |
5858 | log = 0; | |
a3f97cbb | 5859 | else |
3f76745e | 5860 | log = floor_log2 (value); |
71dfc51f | 5861 | |
3f76745e JM |
5862 | log = log / 8; |
5863 | log = 1 << (floor_log2 (log) + 1); | |
5864 | ||
5865 | return log; | |
a3f97cbb JW |
5866 | } |
5867 | ||
2ad9852d | 5868 | /* Return the size of a DIE as it is represented in the |
3f76745e | 5869 | .debug_info section. */ |
71dfc51f | 5870 | |
3f76745e JM |
5871 | static unsigned long |
5872 | size_of_die (die) | |
b3694847 | 5873 | dw_die_ref die; |
a3f97cbb | 5874 | { |
b3694847 SS |
5875 | unsigned long size = 0; |
5876 | dw_attr_ref a; | |
71dfc51f | 5877 | |
3f76745e | 5878 | size += size_of_uleb128 (die->die_abbrev); |
a3f97cbb JW |
5879 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
5880 | { | |
a96c67ec | 5881 | switch (AT_class (a)) |
a3f97cbb JW |
5882 | { |
5883 | case dw_val_class_addr: | |
a1a4189d | 5884 | size += DWARF2_ADDR_SIZE; |
a3f97cbb | 5885 | break; |
a20612aa RH |
5886 | case dw_val_class_offset: |
5887 | size += DWARF_OFFSET_SIZE; | |
5888 | break; | |
a3f97cbb | 5889 | case dw_val_class_loc: |
3f76745e | 5890 | { |
b3694847 | 5891 | unsigned long lsize = size_of_locs (AT_loc (a)); |
71dfc51f | 5892 | |
3f76745e JM |
5893 | /* Block length. */ |
5894 | size += constant_size (lsize); | |
5895 | size += lsize; | |
5896 | } | |
a3f97cbb | 5897 | break; |
63e46568 DB |
5898 | case dw_val_class_loc_list: |
5899 | size += DWARF_OFFSET_SIZE; | |
5900 | break; | |
2bee6045 JJ |
5901 | case dw_val_class_range_list: |
5902 | size += DWARF_OFFSET_SIZE; | |
5903 | break; | |
a3f97cbb | 5904 | case dw_val_class_const: |
25dd13ec | 5905 | size += size_of_sleb128 (AT_int (a)); |
a3f97cbb JW |
5906 | break; |
5907 | case dw_val_class_unsigned_const: | |
a96c67ec | 5908 | size += constant_size (AT_unsigned (a)); |
a3f97cbb | 5909 | break; |
469ac993 | 5910 | case dw_val_class_long_long: |
2e4b9b8c | 5911 | size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */ |
469ac993 JM |
5912 | break; |
5913 | case dw_val_class_float: | |
3f76745e | 5914 | size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */ |
a3f97cbb JW |
5915 | break; |
5916 | case dw_val_class_flag: | |
3f76745e | 5917 | size += 1; |
a3f97cbb JW |
5918 | break; |
5919 | case dw_val_class_die_ref: | |
3f76745e | 5920 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
5921 | break; |
5922 | case dw_val_class_fde_ref: | |
3f76745e | 5923 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
5924 | break; |
5925 | case dw_val_class_lbl_id: | |
a1a4189d | 5926 | size += DWARF2_ADDR_SIZE; |
3f76745e | 5927 | break; |
8b790721 | 5928 | case dw_val_class_lbl_offset: |
3f76745e JM |
5929 | size += DWARF_OFFSET_SIZE; |
5930 | break; | |
5931 | case dw_val_class_str: | |
9eb4015a JJ |
5932 | if (AT_string_form (a) == DW_FORM_strp) |
5933 | size += DWARF_OFFSET_SIZE; | |
5934 | else | |
5935 | size += HT_LEN (&a->dw_attr_val.v.val_str->id) + 1; | |
3f76745e JM |
5936 | break; |
5937 | default: | |
5938 | abort (); | |
5939 | } | |
a3f97cbb | 5940 | } |
3f76745e JM |
5941 | |
5942 | return size; | |
a3f97cbb JW |
5943 | } |
5944 | ||
2ad9852d RK |
5945 | /* Size the debugging information associated with a given DIE. Visits the |
5946 | DIE's children recursively. Updates the global variable next_die_offset, on | |
5947 | each time through. Uses the current value of next_die_offset to update the | |
5948 | die_offset field in each DIE. */ | |
71dfc51f | 5949 | |
a3f97cbb | 5950 | static void |
3f76745e JM |
5951 | calc_die_sizes (die) |
5952 | dw_die_ref die; | |
a3f97cbb | 5953 | { |
b3694847 | 5954 | dw_die_ref c; |
2ad9852d | 5955 | |
3f76745e JM |
5956 | die->die_offset = next_die_offset; |
5957 | next_die_offset += size_of_die (die); | |
71dfc51f | 5958 | |
3f76745e JM |
5959 | for (c = die->die_child; c != NULL; c = c->die_sib) |
5960 | calc_die_sizes (c); | |
71dfc51f | 5961 | |
3f76745e JM |
5962 | if (die->die_child != NULL) |
5963 | /* Count the null byte used to terminate sibling lists. */ | |
5964 | next_die_offset += 1; | |
a3f97cbb JW |
5965 | } |
5966 | ||
1bfb5f8f | 5967 | /* Set the marks for a die and its children. We do this so |
881c6935 | 5968 | that we know whether or not a reference needs to use FORM_ref_addr; only |
1bfb5f8f JM |
5969 | DIEs in the same CU will be marked. We used to clear out the offset |
5970 | and use that as the flag, but ran into ordering problems. */ | |
881c6935 JM |
5971 | |
5972 | static void | |
1bfb5f8f | 5973 | mark_dies (die) |
881c6935 JM |
5974 | dw_die_ref die; |
5975 | { | |
b3694847 | 5976 | dw_die_ref c; |
2ad9852d | 5977 | |
1bfb5f8f JM |
5978 | die->die_mark = 1; |
5979 | for (c = die->die_child; c; c = c->die_sib) | |
5980 | mark_dies (c); | |
5981 | } | |
5982 | ||
5983 | /* Clear the marks for a die and its children. */ | |
5984 | ||
5985 | static void | |
5986 | unmark_dies (die) | |
5987 | dw_die_ref die; | |
5988 | { | |
b3694847 | 5989 | dw_die_ref c; |
2ad9852d | 5990 | |
1bfb5f8f | 5991 | die->die_mark = 0; |
881c6935 | 5992 | for (c = die->die_child; c; c = c->die_sib) |
1bfb5f8f | 5993 | unmark_dies (c); |
881c6935 JM |
5994 | } |
5995 | ||
3f76745e JM |
5996 | /* Return the size of the .debug_pubnames table generated for the |
5997 | compilation unit. */ | |
a94dbf2c | 5998 | |
3f76745e JM |
5999 | static unsigned long |
6000 | size_of_pubnames () | |
a94dbf2c | 6001 | { |
b3694847 SS |
6002 | unsigned long size; |
6003 | unsigned i; | |
469ac993 | 6004 | |
3f76745e | 6005 | size = DWARF_PUBNAMES_HEADER_SIZE; |
2ad9852d | 6006 | for (i = 0; i < pubname_table_in_use; i++) |
a94dbf2c | 6007 | { |
b3694847 | 6008 | pubname_ref p = &pubname_table[i]; |
9eb4015a | 6009 | size += DWARF_OFFSET_SIZE + strlen (p->name) + 1; |
a94dbf2c JM |
6010 | } |
6011 | ||
3f76745e JM |
6012 | size += DWARF_OFFSET_SIZE; |
6013 | return size; | |
a94dbf2c JM |
6014 | } |
6015 | ||
956d6950 | 6016 | /* Return the size of the information in the .debug_aranges section. */ |
469ac993 | 6017 | |
3f76745e JM |
6018 | static unsigned long |
6019 | size_of_aranges () | |
469ac993 | 6020 | { |
b3694847 | 6021 | unsigned long size; |
469ac993 | 6022 | |
3f76745e | 6023 | size = DWARF_ARANGES_HEADER_SIZE; |
469ac993 | 6024 | |
3f76745e | 6025 | /* Count the address/length pair for this compilation unit. */ |
a1a4189d JB |
6026 | size += 2 * DWARF2_ADDR_SIZE; |
6027 | size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use; | |
469ac993 | 6028 | |
3f76745e | 6029 | /* Count the two zero words used to terminated the address range table. */ |
a1a4189d | 6030 | size += 2 * DWARF2_ADDR_SIZE; |
3f76745e JM |
6031 | return size; |
6032 | } | |
6033 | \f | |
6034 | /* Select the encoding of an attribute value. */ | |
6035 | ||
6036 | static enum dwarf_form | |
a96c67ec JM |
6037 | value_format (a) |
6038 | dw_attr_ref a; | |
3f76745e | 6039 | { |
a96c67ec | 6040 | switch (a->dw_attr_val.val_class) |
469ac993 | 6041 | { |
3f76745e JM |
6042 | case dw_val_class_addr: |
6043 | return DW_FORM_addr; | |
2bee6045 | 6044 | case dw_val_class_range_list: |
a20612aa RH |
6045 | case dw_val_class_offset: |
6046 | if (DWARF_OFFSET_SIZE == 4) | |
6047 | return DW_FORM_data4; | |
6048 | if (DWARF_OFFSET_SIZE == 8) | |
6049 | return DW_FORM_data8; | |
6050 | abort (); | |
63e46568 | 6051 | case dw_val_class_loc_list: |
9d2f2c45 RH |
6052 | /* FIXME: Could be DW_FORM_data8, with a > 32 bit size |
6053 | .debug_loc section */ | |
6054 | return DW_FORM_data4; | |
3f76745e | 6055 | case dw_val_class_loc: |
a96c67ec | 6056 | switch (constant_size (size_of_locs (AT_loc (a)))) |
469ac993 | 6057 | { |
3f76745e JM |
6058 | case 1: |
6059 | return DW_FORM_block1; | |
6060 | case 2: | |
6061 | return DW_FORM_block2; | |
469ac993 JM |
6062 | default: |
6063 | abort (); | |
6064 | } | |
3f76745e | 6065 | case dw_val_class_const: |
25dd13ec | 6066 | return DW_FORM_sdata; |
3f76745e | 6067 | case dw_val_class_unsigned_const: |
a96c67ec | 6068 | switch (constant_size (AT_unsigned (a))) |
3f76745e JM |
6069 | { |
6070 | case 1: | |
6071 | return DW_FORM_data1; | |
6072 | case 2: | |
6073 | return DW_FORM_data2; | |
6074 | case 4: | |
6075 | return DW_FORM_data4; | |
6076 | case 8: | |
6077 | return DW_FORM_data8; | |
6078 | default: | |
6079 | abort (); | |
6080 | } | |
6081 | case dw_val_class_long_long: | |
6082 | return DW_FORM_block1; | |
6083 | case dw_val_class_float: | |
6084 | return DW_FORM_block1; | |
6085 | case dw_val_class_flag: | |
6086 | return DW_FORM_flag; | |
6087 | case dw_val_class_die_ref: | |
881c6935 JM |
6088 | if (AT_ref_external (a)) |
6089 | return DW_FORM_ref_addr; | |
6090 | else | |
6091 | return DW_FORM_ref; | |
3f76745e JM |
6092 | case dw_val_class_fde_ref: |
6093 | return DW_FORM_data; | |
6094 | case dw_val_class_lbl_id: | |
6095 | return DW_FORM_addr; | |
8b790721 | 6096 | case dw_val_class_lbl_offset: |
3f76745e JM |
6097 | return DW_FORM_data; |
6098 | case dw_val_class_str: | |
9eb4015a | 6099 | return AT_string_form (a); |
a20612aa | 6100 | |
469ac993 JM |
6101 | default: |
6102 | abort (); | |
6103 | } | |
a94dbf2c JM |
6104 | } |
6105 | ||
3f76745e | 6106 | /* Output the encoding of an attribute value. */ |
469ac993 | 6107 | |
3f76745e | 6108 | static void |
a96c67ec JM |
6109 | output_value_format (a) |
6110 | dw_attr_ref a; | |
a94dbf2c | 6111 | { |
a96c67ec | 6112 | enum dwarf_form form = value_format (a); |
2ad9852d | 6113 | |
2e4b9b8c | 6114 | dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form)); |
3f76745e | 6115 | } |
469ac993 | 6116 | |
3f76745e JM |
6117 | /* Output the .debug_abbrev section which defines the DIE abbreviation |
6118 | table. */ | |
469ac993 | 6119 | |
3f76745e JM |
6120 | static void |
6121 | output_abbrev_section () | |
6122 | { | |
6123 | unsigned long abbrev_id; | |
71dfc51f | 6124 | |
3f76745e | 6125 | dw_attr_ref a_attr; |
2ad9852d | 6126 | |
3f76745e JM |
6127 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
6128 | { | |
b3694847 | 6129 | dw_die_ref abbrev = abbrev_die_table[abbrev_id]; |
71dfc51f | 6130 | |
2e4b9b8c | 6131 | dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)"); |
2e4b9b8c RH |
6132 | dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)", |
6133 | dwarf_tag_name (abbrev->die_tag)); | |
71dfc51f | 6134 | |
2e4b9b8c RH |
6135 | if (abbrev->die_child != NULL) |
6136 | dw2_asm_output_data (1, DW_children_yes, "DW_children_yes"); | |
6137 | else | |
6138 | dw2_asm_output_data (1, DW_children_no, "DW_children_no"); | |
3f76745e JM |
6139 | |
6140 | for (a_attr = abbrev->die_attr; a_attr != NULL; | |
6141 | a_attr = a_attr->dw_attr_next) | |
6142 | { | |
2e4b9b8c RH |
6143 | dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)", |
6144 | dwarf_attr_name (a_attr->dw_attr)); | |
a96c67ec | 6145 | output_value_format (a_attr); |
469ac993 | 6146 | } |
469ac993 | 6147 | |
2e4b9b8c RH |
6148 | dw2_asm_output_data (1, 0, NULL); |
6149 | dw2_asm_output_data (1, 0, NULL); | |
469ac993 | 6150 | } |
81f374eb HPN |
6151 | |
6152 | /* Terminate the table. */ | |
2e4b9b8c | 6153 | dw2_asm_output_data (1, 0, NULL); |
a94dbf2c JM |
6154 | } |
6155 | ||
881c6935 JM |
6156 | /* Output a symbol we can use to refer to this DIE from another CU. */ |
6157 | ||
6158 | static inline void | |
6159 | output_die_symbol (die) | |
b3694847 | 6160 | dw_die_ref die; |
881c6935 JM |
6161 | { |
6162 | char *sym = die->die_symbol; | |
6163 | ||
6164 | if (sym == 0) | |
6165 | return; | |
6166 | ||
6167 | if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0) | |
6168 | /* We make these global, not weak; if the target doesn't support | |
6169 | .linkonce, it doesn't support combining the sections, so debugging | |
6170 | will break. */ | |
6171 | ASM_GLOBALIZE_LABEL (asm_out_file, sym); | |
2ad9852d | 6172 | |
881c6935 JM |
6173 | ASM_OUTPUT_LABEL (asm_out_file, sym); |
6174 | } | |
6175 | ||
84a5b4f8 | 6176 | /* Return a new location list, given the begin and end range, and the |
2ad9852d RK |
6177 | expression. gensym tells us whether to generate a new internal symbol for |
6178 | this location list node, which is done for the head of the list only. */ | |
6179 | ||
84a5b4f8 DB |
6180 | static inline dw_loc_list_ref |
6181 | new_loc_list (expr, begin, end, section, gensym) | |
b3694847 SS |
6182 | dw_loc_descr_ref expr; |
6183 | const char *begin; | |
6184 | const char *end; | |
6185 | const char *section; | |
6186 | unsigned gensym; | |
84a5b4f8 | 6187 | { |
b3694847 | 6188 | dw_loc_list_ref retlist |
84a5b4f8 | 6189 | = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node)); |
2ad9852d | 6190 | |
84a5b4f8 DB |
6191 | retlist->begin = begin; |
6192 | retlist->end = end; | |
6193 | retlist->expr = expr; | |
6194 | retlist->section = section; | |
c26fbbca | 6195 | if (gensym) |
84a5b4f8 | 6196 | retlist->ll_symbol = gen_internal_sym ("LLST"); |
2ad9852d | 6197 | |
84a5b4f8 DB |
6198 | return retlist; |
6199 | } | |
6200 | ||
6201 | /* Add a location description expression to a location list */ | |
2ad9852d | 6202 | |
84a5b4f8 DB |
6203 | static inline void |
6204 | add_loc_descr_to_loc_list (list_head, descr, begin, end, section) | |
b3694847 SS |
6205 | dw_loc_list_ref *list_head; |
6206 | dw_loc_descr_ref descr; | |
6207 | const char *begin; | |
6208 | const char *end; | |
6209 | const char *section; | |
84a5b4f8 | 6210 | { |
b3694847 | 6211 | dw_loc_list_ref *d; |
c26fbbca | 6212 | |
30f7a378 | 6213 | /* Find the end of the chain. */ |
84a5b4f8 DB |
6214 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) |
6215 | ; | |
2ad9852d | 6216 | |
84a5b4f8 DB |
6217 | /* Add a new location list node to the list */ |
6218 | *d = new_loc_list (descr, begin, end, section, 0); | |
6219 | } | |
6220 | ||
63e46568 | 6221 | /* Output the location list given to us */ |
2ad9852d | 6222 | |
63e46568 DB |
6223 | static void |
6224 | output_loc_list (list_head) | |
b3694847 | 6225 | dw_loc_list_ref list_head; |
63e46568 | 6226 | { |
2ad9852d RK |
6227 | dw_loc_list_ref curr = list_head; |
6228 | ||
63e46568 | 6229 | ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol); |
a20612aa RH |
6230 | |
6231 | /* ??? This shouldn't be needed now that we've forced the | |
6232 | compilation unit base address to zero when there is code | |
6233 | in more than one section. */ | |
63e46568 DB |
6234 | if (strcmp (curr->section, ".text") == 0) |
6235 | { | |
aafdcfcd | 6236 | /* dw2_asm_output_data will mask off any extra bits in the ~0. */ |
c4f2c499 | 6237 | dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0, |
aafdcfcd NS |
6238 | "Location list base address specifier fake entry"); |
6239 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section, | |
6240 | "Location list base address specifier base"); | |
63e46568 | 6241 | } |
2ad9852d | 6242 | |
c26fbbca | 6243 | for (curr = list_head; curr != NULL; curr = curr->dw_loc_next) |
63e46568 | 6244 | { |
2bee6045 | 6245 | unsigned long size; |
2ad9852d | 6246 | |
aafdcfcd NS |
6247 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section, |
6248 | "Location list begin address (%s)", | |
6249 | list_head->ll_symbol); | |
6250 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section, | |
6251 | "Location list end address (%s)", | |
6252 | list_head->ll_symbol); | |
63e46568 | 6253 | size = size_of_locs (curr->expr); |
c26fbbca | 6254 | |
63e46568 | 6255 | /* Output the block length for this list of location operations. */ |
2bee6045 JJ |
6256 | if (size > 0xffff) |
6257 | abort (); | |
6258 | dw2_asm_output_data (2, size, "%s", "Location expression size"); | |
6259 | ||
63e46568 DB |
6260 | output_loc_sequence (curr->expr); |
6261 | } | |
2ad9852d | 6262 | |
aafdcfcd NS |
6263 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, |
6264 | "Location list terminator begin (%s)", | |
6265 | list_head->ll_symbol); | |
6266 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, | |
6267 | "Location list terminator end (%s)", | |
6268 | list_head->ll_symbol); | |
63e46568 | 6269 | } |
9eb4015a | 6270 | |
3f76745e JM |
6271 | /* Output the DIE and its attributes. Called recursively to generate |
6272 | the definitions of each child DIE. */ | |
71dfc51f | 6273 | |
a3f97cbb | 6274 | static void |
3f76745e | 6275 | output_die (die) |
b3694847 | 6276 | dw_die_ref die; |
a3f97cbb | 6277 | { |
b3694847 SS |
6278 | dw_attr_ref a; |
6279 | dw_die_ref c; | |
6280 | unsigned long size; | |
a94dbf2c | 6281 | |
881c6935 JM |
6282 | /* If someone in another CU might refer to us, set up a symbol for |
6283 | them to point to. */ | |
6284 | if (die->die_symbol) | |
6285 | output_die_symbol (die); | |
6286 | ||
2e4b9b8c RH |
6287 | dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)", |
6288 | die->die_offset, dwarf_tag_name (die->die_tag)); | |
a94dbf2c | 6289 | |
3f76745e | 6290 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
a3f97cbb | 6291 | { |
2e4b9b8c RH |
6292 | const char *name = dwarf_attr_name (a->dw_attr); |
6293 | ||
a96c67ec | 6294 | switch (AT_class (a)) |
3f76745e JM |
6295 | { |
6296 | case dw_val_class_addr: | |
2e4b9b8c | 6297 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name); |
3f76745e | 6298 | break; |
a3f97cbb | 6299 | |
a20612aa RH |
6300 | case dw_val_class_offset: |
6301 | dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset, | |
6302 | "%s", name); | |
6303 | break; | |
6304 | ||
2bee6045 JJ |
6305 | case dw_val_class_range_list: |
6306 | { | |
6307 | char *p = strchr (ranges_section_label, '\0'); | |
6308 | ||
6309 | sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset); | |
6310 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label, | |
6311 | "%s", name); | |
6312 | *p = '\0'; | |
6313 | } | |
6314 | break; | |
6315 | ||
3f76745e | 6316 | case dw_val_class_loc: |
a96c67ec | 6317 | size = size_of_locs (AT_loc (a)); |
71dfc51f | 6318 | |
3f76745e | 6319 | /* Output the block length for this list of location operations. */ |
2e4b9b8c | 6320 | dw2_asm_output_data (constant_size (size), size, "%s", name); |
71dfc51f | 6321 | |
7d9d8943 | 6322 | output_loc_sequence (AT_loc (a)); |
a3f97cbb | 6323 | break; |
3f76745e JM |
6324 | |
6325 | case dw_val_class_const: | |
25dd13ec JW |
6326 | /* ??? It would be slightly more efficient to use a scheme like is |
6327 | used for unsigned constants below, but gdb 4.x does not sign | |
6328 | extend. Gdb 5.x does sign extend. */ | |
2e4b9b8c | 6329 | dw2_asm_output_data_sleb128 (AT_int (a), "%s", name); |
a3f97cbb | 6330 | break; |
3f76745e JM |
6331 | |
6332 | case dw_val_class_unsigned_const: | |
2e4b9b8c RH |
6333 | dw2_asm_output_data (constant_size (AT_unsigned (a)), |
6334 | AT_unsigned (a), "%s", name); | |
a3f97cbb | 6335 | break; |
3f76745e JM |
6336 | |
6337 | case dw_val_class_long_long: | |
2e4b9b8c RH |
6338 | { |
6339 | unsigned HOST_WIDE_INT first, second; | |
3f76745e | 6340 | |
2ad9852d RK |
6341 | dw2_asm_output_data (1, |
6342 | 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, | |
c26fbbca | 6343 | "%s", name); |
556273e0 | 6344 | |
2e4b9b8c RH |
6345 | if (WORDS_BIG_ENDIAN) |
6346 | { | |
6347 | first = a->dw_attr_val.v.val_long_long.hi; | |
6348 | second = a->dw_attr_val.v.val_long_long.low; | |
6349 | } | |
6350 | else | |
6351 | { | |
6352 | first = a->dw_attr_val.v.val_long_long.low; | |
6353 | second = a->dw_attr_val.v.val_long_long.hi; | |
6354 | } | |
2ad9852d RK |
6355 | |
6356 | dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, | |
2e4b9b8c | 6357 | first, "long long constant"); |
2ad9852d | 6358 | dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, |
2e4b9b8c RH |
6359 | second, NULL); |
6360 | } | |
a3f97cbb | 6361 | break; |
3f76745e JM |
6362 | |
6363 | case dw_val_class_float: | |
c84e2712 | 6364 | { |
b3694847 | 6365 | unsigned int i; |
c84e2712 | 6366 | |
2e4b9b8c | 6367 | dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4, |
c26fbbca | 6368 | "%s", name); |
c84e2712 | 6369 | |
2ad9852d | 6370 | for (i = 0; i < a->dw_attr_val.v.val_float.length; i++) |
2e4b9b8c RH |
6371 | dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i], |
6372 | "fp constant word %u", i); | |
556273e0 | 6373 | break; |
c84e2712 | 6374 | } |
3f76745e JM |
6375 | |
6376 | case dw_val_class_flag: | |
2e4b9b8c | 6377 | dw2_asm_output_data (1, AT_flag (a), "%s", name); |
a3f97cbb | 6378 | break; |
a20612aa | 6379 | |
c26fbbca | 6380 | case dw_val_class_loc_list: |
63e46568 DB |
6381 | { |
6382 | char *sym = AT_loc_list (a)->ll_symbol; | |
2ad9852d | 6383 | |
63e46568 | 6384 | if (sym == 0) |
173bf5be | 6385 | abort (); |
a20612aa RH |
6386 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, |
6387 | loc_section_label, "%s", name); | |
63e46568 DB |
6388 | } |
6389 | break; | |
a20612aa | 6390 | |
3f76745e | 6391 | case dw_val_class_die_ref: |
881c6935 | 6392 | if (AT_ref_external (a)) |
2e4b9b8c RH |
6393 | { |
6394 | char *sym = AT_ref (a)->die_symbol; | |
2ad9852d | 6395 | |
2e4b9b8c RH |
6396 | if (sym == 0) |
6397 | abort (); | |
6398 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name); | |
6399 | } | |
3f4907a6 JM |
6400 | else if (AT_ref (a)->die_offset == 0) |
6401 | abort (); | |
881c6935 | 6402 | else |
2e4b9b8c RH |
6403 | dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset, |
6404 | "%s", name); | |
a3f97cbb | 6405 | break; |
3f76745e JM |
6406 | |
6407 | case dw_val_class_fde_ref: | |
a6ab3aad JM |
6408 | { |
6409 | char l1[20]; | |
2ad9852d | 6410 | |
2e4b9b8c RH |
6411 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL, |
6412 | a->dw_attr_val.v.val_fde_index * 2); | |
6413 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name); | |
a6ab3aad | 6414 | } |
a3f97cbb | 6415 | break; |
a3f97cbb | 6416 | |
3f76745e | 6417 | case dw_val_class_lbl_id: |
8e7fa2c8 | 6418 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 6419 | break; |
71dfc51f | 6420 | |
8b790721 | 6421 | case dw_val_class_lbl_offset: |
2e4b9b8c | 6422 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 6423 | break; |
a3f97cbb | 6424 | |
3f76745e | 6425 | case dw_val_class_str: |
9eb4015a JJ |
6426 | if (AT_string_form (a) == DW_FORM_strp) |
6427 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, | |
6428 | a->dw_attr_val.v.val_str->label, | |
a4cf1d85 | 6429 | "%s: \"%s\"", name, AT_string (a)); |
9eb4015a JJ |
6430 | else |
6431 | dw2_asm_output_nstring (AT_string (a), -1, "%s", name); | |
3f76745e | 6432 | break; |
b2932ae5 | 6433 | |
3f76745e JM |
6434 | default: |
6435 | abort (); | |
6436 | } | |
3f76745e | 6437 | } |
71dfc51f | 6438 | |
3f76745e JM |
6439 | for (c = die->die_child; c != NULL; c = c->die_sib) |
6440 | output_die (c); | |
71dfc51f | 6441 | |
2ad9852d | 6442 | /* Add null byte to terminate sibling list. */ |
3f76745e | 6443 | if (die->die_child != NULL) |
2ad9852d RK |
6444 | dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx", |
6445 | die->die_offset); | |
3f76745e | 6446 | } |
71dfc51f | 6447 | |
3f76745e JM |
6448 | /* Output the compilation unit that appears at the beginning of the |
6449 | .debug_info section, and precedes the DIE descriptions. */ | |
71dfc51f | 6450 | |
3f76745e JM |
6451 | static void |
6452 | output_compilation_unit_header () | |
6453 | { | |
2e4b9b8c RH |
6454 | dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE, |
6455 | "Length of Compilation Unit Info"); | |
2e4b9b8c | 6456 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number"); |
2e4b9b8c RH |
6457 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label, |
6458 | "Offset Into Abbrev. Section"); | |
2e4b9b8c | 6459 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)"); |
a3f97cbb JW |
6460 | } |
6461 | ||
881c6935 JM |
6462 | /* Output the compilation unit DIE and its children. */ |
6463 | ||
6464 | static void | |
6465 | output_comp_unit (die) | |
6466 | dw_die_ref die; | |
6467 | { | |
ce1cc601 | 6468 | const char *secname; |
881c6935 | 6469 | |
2ad9852d RK |
6470 | /* Even if there are no children of this DIE, we must output the information |
6471 | about the compilation unit. Otherwise, on an empty translation unit, we | |
6472 | will generate a present, but empty, .debug_info section. IRIX 6.5 `nm' | |
6473 | will then complain when examining the file. First mark all the DIEs in | |
6474 | this CU so we know which get local refs. */ | |
1bfb5f8f JM |
6475 | mark_dies (die); |
6476 | ||
6477 | build_abbrev_table (die); | |
6478 | ||
6d2f8887 | 6479 | /* Initialize the beginning DIE offset - and calculate sizes/offsets. */ |
881c6935 JM |
6480 | next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE; |
6481 | calc_die_sizes (die); | |
6482 | ||
881c6935 JM |
6483 | if (die->die_symbol) |
6484 | { | |
ce1cc601 | 6485 | char *tmp = (char *) alloca (strlen (die->die_symbol) + 24); |
2ad9852d | 6486 | |
ce1cc601 KG |
6487 | sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol); |
6488 | secname = tmp; | |
881c6935 JM |
6489 | die->die_symbol = NULL; |
6490 | } | |
6491 | else | |
ce1cc601 | 6492 | secname = (const char *) DEBUG_INFO_SECTION; |
881c6935 JM |
6493 | |
6494 | /* Output debugging information. */ | |
715bdd29 | 6495 | named_section_flags (secname, SECTION_DEBUG); |
881c6935 JM |
6496 | output_compilation_unit_header (); |
6497 | output_die (die); | |
6498 | ||
1bfb5f8f JM |
6499 | /* Leave the marks on the main CU, so we can check them in |
6500 | output_pubnames. */ | |
881c6935 | 6501 | if (die->die_symbol) |
1bfb5f8f | 6502 | unmark_dies (die); |
881c6935 JM |
6503 | } |
6504 | ||
7afff7cf NB |
6505 | /* The DWARF2 pubname for a nested thingy looks like "A::f". The |
6506 | output of lang_hooks.decl_printable_name for C++ looks like | |
6507 | "A::f(int)". Let's drop the argument list, and maybe the scope. */ | |
a1d7ffe3 | 6508 | |
d560ee52 | 6509 | static const char * |
a1d7ffe3 JM |
6510 | dwarf2_name (decl, scope) |
6511 | tree decl; | |
6512 | int scope; | |
6513 | { | |
7afff7cf | 6514 | return (*lang_hooks.decl_printable_name) (decl, scope ? 1 : 0); |
a1d7ffe3 JM |
6515 | } |
6516 | ||
d291dd49 | 6517 | /* Add a new entry to .debug_pubnames if appropriate. */ |
71dfc51f | 6518 | |
d291dd49 JM |
6519 | static void |
6520 | add_pubname (decl, die) | |
6521 | tree decl; | |
6522 | dw_die_ref die; | |
6523 | { | |
6524 | pubname_ref p; | |
6525 | ||
6526 | if (! TREE_PUBLIC (decl)) | |
6527 | return; | |
6528 | ||
6529 | if (pubname_table_in_use == pubname_table_allocated) | |
6530 | { | |
6531 | pubname_table_allocated += PUBNAME_TABLE_INCREMENT; | |
2ad9852d RK |
6532 | pubname_table |
6533 | = (pubname_ref) xrealloc (pubname_table, | |
6534 | (pubname_table_allocated | |
6535 | * sizeof (pubname_entry))); | |
d291dd49 | 6536 | } |
71dfc51f | 6537 | |
d291dd49 JM |
6538 | p = &pubname_table[pubname_table_in_use++]; |
6539 | p->die = die; | |
a1d7ffe3 | 6540 | p->name = xstrdup (dwarf2_name (decl, 1)); |
d291dd49 JM |
6541 | } |
6542 | ||
a3f97cbb JW |
6543 | /* Output the public names table used to speed up access to externally |
6544 | visible names. For now, only generate entries for externally | |
6545 | visible procedures. */ | |
71dfc51f | 6546 | |
a3f97cbb JW |
6547 | static void |
6548 | output_pubnames () | |
6549 | { | |
b3694847 SS |
6550 | unsigned i; |
6551 | unsigned long pubnames_length = size_of_pubnames (); | |
71dfc51f | 6552 | |
2e4b9b8c RH |
6553 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, |
6554 | "Length of Public Names Info"); | |
2e4b9b8c | 6555 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
2e4b9b8c RH |
6556 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
6557 | "Offset of Compilation Unit Info"); | |
2e4b9b8c RH |
6558 | dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset, |
6559 | "Compilation Unit Length"); | |
71dfc51f | 6560 | |
2ad9852d | 6561 | for (i = 0; i < pubname_table_in_use; i++) |
a3f97cbb | 6562 | { |
b3694847 | 6563 | pubname_ref pub = &pubname_table[i]; |
71dfc51f | 6564 | |
881c6935 | 6565 | /* We shouldn't see pubnames for DIEs outside of the main CU. */ |
1bfb5f8f | 6566 | if (pub->die->die_mark == 0) |
881c6935 JM |
6567 | abort (); |
6568 | ||
2e4b9b8c RH |
6569 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset, |
6570 | "DIE offset"); | |
71dfc51f | 6571 | |
2e4b9b8c | 6572 | dw2_asm_output_nstring (pub->name, -1, "external name"); |
a3f97cbb | 6573 | } |
71dfc51f | 6574 | |
2e4b9b8c | 6575 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL); |
a3f97cbb JW |
6576 | } |
6577 | ||
d291dd49 | 6578 | /* Add a new entry to .debug_aranges if appropriate. */ |
71dfc51f | 6579 | |
d291dd49 JM |
6580 | static void |
6581 | add_arange (decl, die) | |
6582 | tree decl; | |
6583 | dw_die_ref die; | |
6584 | { | |
6585 | if (! DECL_SECTION_NAME (decl)) | |
6586 | return; | |
6587 | ||
6588 | if (arange_table_in_use == arange_table_allocated) | |
6589 | { | |
6590 | arange_table_allocated += ARANGE_TABLE_INCREMENT; | |
a20612aa RH |
6591 | arange_table = (dw_die_ref *) |
6592 | xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref)); | |
d291dd49 | 6593 | } |
71dfc51f | 6594 | |
d291dd49 JM |
6595 | arange_table[arange_table_in_use++] = die; |
6596 | } | |
6597 | ||
a3f97cbb JW |
6598 | /* Output the information that goes into the .debug_aranges table. |
6599 | Namely, define the beginning and ending address range of the | |
6600 | text section generated for this compilation unit. */ | |
71dfc51f | 6601 | |
a3f97cbb JW |
6602 | static void |
6603 | output_aranges () | |
6604 | { | |
b3694847 SS |
6605 | unsigned i; |
6606 | unsigned long aranges_length = size_of_aranges (); | |
71dfc51f | 6607 | |
2e4b9b8c RH |
6608 | dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length, |
6609 | "Length of Address Ranges Info"); | |
2e4b9b8c | 6610 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
2e4b9b8c RH |
6611 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
6612 | "Offset of Compilation Unit Info"); | |
2e4b9b8c | 6613 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address"); |
2e4b9b8c | 6614 | dw2_asm_output_data (1, 0, "Size of Segment Descriptor"); |
71dfc51f | 6615 | |
262b6384 SC |
6616 | /* We need to align to twice the pointer size here. */ |
6617 | if (DWARF_ARANGES_PAD_SIZE) | |
6618 | { | |
2e4b9b8c RH |
6619 | /* Pad using a 2 byte words so that padding is correct for any |
6620 | pointer size. */ | |
6621 | dw2_asm_output_data (2, 0, "Pad to %d byte boundary", | |
6622 | 2 * DWARF2_ADDR_SIZE); | |
770ca8c6 | 6623 | for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2) |
2e4b9b8c | 6624 | dw2_asm_output_data (2, 0, NULL); |
262b6384 | 6625 | } |
71dfc51f | 6626 | |
8e7fa2c8 | 6627 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address"); |
2e4b9b8c RH |
6628 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label, |
6629 | text_section_label, "Length"); | |
71dfc51f | 6630 | |
2ad9852d | 6631 | for (i = 0; i < arange_table_in_use; i++) |
d291dd49 | 6632 | { |
e689ae67 | 6633 | dw_die_ref die = arange_table[i]; |
71dfc51f | 6634 | |
881c6935 | 6635 | /* We shouldn't see aranges for DIEs outside of the main CU. */ |
1bfb5f8f | 6636 | if (die->die_mark == 0) |
881c6935 JM |
6637 | abort (); |
6638 | ||
e689ae67 | 6639 | if (die->die_tag == DW_TAG_subprogram) |
2e4b9b8c | 6640 | { |
8e7fa2c8 | 6641 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die), |
173bf5be | 6642 | "Address"); |
2e4b9b8c RH |
6643 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die), |
6644 | get_AT_low_pc (die), "Length"); | |
6645 | } | |
d291dd49 | 6646 | else |
a1d7ffe3 | 6647 | { |
e689ae67 JM |
6648 | /* A static variable; extract the symbol from DW_AT_location. |
6649 | Note that this code isn't currently hit, as we only emit | |
6650 | aranges for functions (jason 9/23/99). */ | |
e689ae67 JM |
6651 | dw_attr_ref a = get_AT (die, DW_AT_location); |
6652 | dw_loc_descr_ref loc; | |
2ad9852d | 6653 | |
a96c67ec | 6654 | if (! a || AT_class (a) != dw_val_class_loc) |
e689ae67 JM |
6655 | abort (); |
6656 | ||
a96c67ec | 6657 | loc = AT_loc (a); |
e689ae67 JM |
6658 | if (loc->dw_loc_opc != DW_OP_addr) |
6659 | abort (); | |
6660 | ||
2e4b9b8c RH |
6661 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, |
6662 | loc->dw_loc_oprnd1.v.val_addr, "Address"); | |
6663 | dw2_asm_output_data (DWARF2_ADDR_SIZE, | |
6664 | get_AT_unsigned (die, DW_AT_byte_size), | |
6665 | "Length"); | |
a1d7ffe3 | 6666 | } |
d291dd49 | 6667 | } |
71dfc51f | 6668 | |
a3f97cbb | 6669 | /* Output the terminator words. */ |
2e4b9b8c RH |
6670 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); |
6671 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
a3f97cbb JW |
6672 | } |
6673 | ||
a20612aa RH |
6674 | /* Add a new entry to .debug_ranges. Return the offset at which it |
6675 | was placed. */ | |
6676 | ||
6677 | static unsigned int | |
6678 | add_ranges (block) | |
6679 | tree block; | |
6680 | { | |
6681 | unsigned int in_use = ranges_table_in_use; | |
6682 | ||
6683 | if (in_use == ranges_table_allocated) | |
6684 | { | |
6685 | ranges_table_allocated += RANGES_TABLE_INCREMENT; | |
6686 | ranges_table = (dw_ranges_ref) | |
6687 | xrealloc (ranges_table, (ranges_table_allocated | |
6688 | * sizeof (struct dw_ranges_struct))); | |
6689 | } | |
6690 | ||
6691 | ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0); | |
6692 | ranges_table_in_use = in_use + 1; | |
6693 | ||
6694 | return in_use * 2 * DWARF2_ADDR_SIZE; | |
6695 | } | |
6696 | ||
6697 | static void | |
6698 | output_ranges () | |
6699 | { | |
b3694847 | 6700 | unsigned i; |
83182544 | 6701 | static const char *const start_fmt = "Offset 0x%x"; |
a20612aa RH |
6702 | const char *fmt = start_fmt; |
6703 | ||
2ad9852d | 6704 | for (i = 0; i < ranges_table_in_use; i++) |
a20612aa RH |
6705 | { |
6706 | int block_num = ranges_table[i].block_num; | |
6707 | ||
6708 | if (block_num) | |
6709 | { | |
6710 | char blabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6711 | char elabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6712 | ||
6713 | ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num); | |
6714 | ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num); | |
6715 | ||
6716 | /* If all code is in the text section, then the compilation | |
6717 | unit base address defaults to DW_AT_low_pc, which is the | |
6718 | base of the text section. */ | |
6719 | if (separate_line_info_table_in_use == 0) | |
6720 | { | |
6721 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel, | |
6722 | text_section_label, | |
6723 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
6724 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel, | |
6725 | text_section_label, NULL); | |
6726 | } | |
2ad9852d | 6727 | |
a20612aa RH |
6728 | /* Otherwise, we add a DW_AT_entry_pc attribute to force the |
6729 | compilation unit base address to zero, which allows us to | |
6730 | use absolute addresses, and not worry about whether the | |
6731 | target supports cross-section arithmetic. */ | |
6732 | else | |
6733 | { | |
6734 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel, | |
6735 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
6736 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL); | |
6737 | } | |
6738 | ||
6739 | fmt = NULL; | |
6740 | } | |
6741 | else | |
6742 | { | |
6743 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
6744 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
6745 | fmt = start_fmt; | |
6746 | } | |
6747 | } | |
6748 | } | |
0b34cf1e UD |
6749 | |
6750 | /* Data structure containing information about input files. */ | |
6751 | struct file_info | |
6752 | { | |
6753 | char *path; /* Complete file name. */ | |
6754 | char *fname; /* File name part. */ | |
6755 | int length; /* Length of entire string. */ | |
6756 | int file_idx; /* Index in input file table. */ | |
6757 | int dir_idx; /* Index in directory table. */ | |
6758 | }; | |
6759 | ||
6760 | /* Data structure containing information about directories with source | |
6761 | files. */ | |
6762 | struct dir_info | |
6763 | { | |
6764 | char *path; /* Path including directory name. */ | |
6765 | int length; /* Path length. */ | |
6766 | int prefix; /* Index of directory entry which is a prefix. */ | |
0b34cf1e UD |
6767 | int count; /* Number of files in this directory. */ |
6768 | int dir_idx; /* Index of directory used as base. */ | |
6769 | int used; /* Used in the end? */ | |
6770 | }; | |
6771 | ||
6772 | /* Callback function for file_info comparison. We sort by looking at | |
6773 | the directories in the path. */ | |
356b0698 | 6774 | |
0b34cf1e UD |
6775 | static int |
6776 | file_info_cmp (p1, p2) | |
6777 | const void *p1; | |
6778 | const void *p2; | |
6779 | { | |
6780 | const struct file_info *s1 = p1; | |
6781 | const struct file_info *s2 = p2; | |
6782 | unsigned char *cp1; | |
6783 | unsigned char *cp2; | |
6784 | ||
356b0698 RK |
6785 | /* Take care of file names without directories. We need to make sure that |
6786 | we return consistent values to qsort since some will get confused if | |
6787 | we return the same value when identical operands are passed in opposite | |
6788 | orders. So if neither has a directory, return 0 and otherwise return | |
6789 | 1 or -1 depending on which one has the directory. */ | |
6790 | if ((s1->path == s1->fname || s2->path == s2->fname)) | |
6791 | return (s2->path == s2->fname) - (s1->path == s1->fname); | |
0b34cf1e UD |
6792 | |
6793 | cp1 = (unsigned char *) s1->path; | |
6794 | cp2 = (unsigned char *) s2->path; | |
6795 | ||
6796 | while (1) | |
6797 | { | |
6798 | ++cp1; | |
6799 | ++cp2; | |
356b0698 RK |
6800 | /* Reached the end of the first path? If so, handle like above. */ |
6801 | if ((cp1 == (unsigned char *) s1->fname) | |
6802 | || (cp2 == (unsigned char *) s2->fname)) | |
6803 | return ((cp2 == (unsigned char *) s2->fname) | |
6804 | - (cp1 == (unsigned char *) s1->fname)); | |
0b34cf1e UD |
6805 | |
6806 | /* Character of current path component the same? */ | |
356b0698 | 6807 | else if (*cp1 != *cp2) |
0b34cf1e UD |
6808 | return *cp1 - *cp2; |
6809 | } | |
6810 | } | |
6811 | ||
6812 | /* Output the directory table and the file name table. We try to minimize | |
6813 | the total amount of memory needed. A heuristic is used to avoid large | |
6814 | slowdowns with many input files. */ | |
2ad9852d | 6815 | |
0b34cf1e UD |
6816 | static void |
6817 | output_file_names () | |
6818 | { | |
6819 | struct file_info *files; | |
6820 | struct dir_info *dirs; | |
6821 | int *saved; | |
6822 | int *savehere; | |
6823 | int *backmap; | |
6824 | int ndirs; | |
6825 | int idx_offset; | |
6826 | int i; | |
6827 | int idx; | |
6828 | ||
6829 | /* Allocate the various arrays we need. */ | |
981975b6 | 6830 | files = (struct file_info *) alloca (file_table.in_use |
0b34cf1e | 6831 | * sizeof (struct file_info)); |
981975b6 | 6832 | dirs = (struct dir_info *) alloca (file_table.in_use |
0b34cf1e UD |
6833 | * sizeof (struct dir_info)); |
6834 | ||
6835 | /* Sort the file names. */ | |
2ad9852d | 6836 | for (i = 1; i < (int) file_table.in_use; i++) |
0b34cf1e UD |
6837 | { |
6838 | char *f; | |
6839 | ||
6840 | /* Skip all leading "./". */ | |
981975b6 | 6841 | f = file_table.table[i]; |
0b34cf1e UD |
6842 | while (f[0] == '.' && f[1] == '/') |
6843 | f += 2; | |
6844 | ||
6845 | /* Create a new array entry. */ | |
6846 | files[i].path = f; | |
6847 | files[i].length = strlen (f); | |
6848 | files[i].file_idx = i; | |
6849 | ||
6850 | /* Search for the file name part. */ | |
6851 | f = strrchr (f, '/'); | |
6852 | files[i].fname = f == NULL ? files[i].path : f + 1; | |
6853 | } | |
2ad9852d | 6854 | |
981975b6 | 6855 | qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp); |
0b34cf1e UD |
6856 | |
6857 | /* Find all the different directories used. */ | |
6858 | dirs[0].path = files[1].path; | |
6859 | dirs[0].length = files[1].fname - files[1].path; | |
6860 | dirs[0].prefix = -1; | |
0b34cf1e UD |
6861 | dirs[0].count = 1; |
6862 | dirs[0].dir_idx = 0; | |
6863 | dirs[0].used = 0; | |
6864 | files[1].dir_idx = 0; | |
6865 | ndirs = 1; | |
6866 | ||
2ad9852d | 6867 | for (i = 2; i < (int) file_table.in_use; i++) |
0b34cf1e UD |
6868 | if (files[i].fname - files[i].path == dirs[ndirs - 1].length |
6869 | && memcmp (dirs[ndirs - 1].path, files[i].path, | |
6870 | dirs[ndirs - 1].length) == 0) | |
6871 | { | |
6872 | /* Same directory as last entry. */ | |
6873 | files[i].dir_idx = ndirs - 1; | |
0b34cf1e UD |
6874 | ++dirs[ndirs - 1].count; |
6875 | } | |
6876 | else | |
6877 | { | |
6878 | int j; | |
6879 | ||
6880 | /* This is a new directory. */ | |
6881 | dirs[ndirs].path = files[i].path; | |
6882 | dirs[ndirs].length = files[i].fname - files[i].path; | |
0b34cf1e UD |
6883 | dirs[ndirs].count = 1; |
6884 | dirs[ndirs].dir_idx = ndirs; | |
6885 | dirs[ndirs].used = 0; | |
6886 | files[i].dir_idx = ndirs; | |
6887 | ||
6888 | /* Search for a prefix. */ | |
981975b6 | 6889 | dirs[ndirs].prefix = -1; |
2ad9852d | 6890 | for (j = 0; j < ndirs; j++) |
981975b6 RH |
6891 | if (dirs[j].length < dirs[ndirs].length |
6892 | && dirs[j].length > 1 | |
6893 | && (dirs[ndirs].prefix == -1 | |
6894 | || dirs[j].length > dirs[dirs[ndirs].prefix].length) | |
6895 | && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0) | |
6896 | dirs[ndirs].prefix = j; | |
0b34cf1e UD |
6897 | |
6898 | ++ndirs; | |
6899 | } | |
6900 | ||
2ad9852d RK |
6901 | /* Now to the actual work. We have to find a subset of the directories which |
6902 | allow expressing the file name using references to the directory table | |
6903 | with the least amount of characters. We do not do an exhaustive search | |
6904 | where we would have to check out every combination of every single | |
6905 | possible prefix. Instead we use a heuristic which provides nearly optimal | |
6906 | results in most cases and never is much off. */ | |
0b34cf1e UD |
6907 | saved = (int *) alloca (ndirs * sizeof (int)); |
6908 | savehere = (int *) alloca (ndirs * sizeof (int)); | |
6909 | ||
6910 | memset (saved, '\0', ndirs * sizeof (saved[0])); | |
2ad9852d | 6911 | for (i = 0; i < ndirs; i++) |
0b34cf1e UD |
6912 | { |
6913 | int j; | |
6914 | int total; | |
6915 | ||
2ad9852d RK |
6916 | /* We can always save some space for the current directory. But this |
6917 | does not mean it will be enough to justify adding the directory. */ | |
0b34cf1e UD |
6918 | savehere[i] = dirs[i].length; |
6919 | total = (savehere[i] - saved[i]) * dirs[i].count; | |
6920 | ||
2ad9852d | 6921 | for (j = i + 1; j < ndirs; j++) |
0b34cf1e UD |
6922 | { |
6923 | savehere[j] = 0; | |
0b34cf1e UD |
6924 | if (saved[j] < dirs[i].length) |
6925 | { | |
6926 | /* Determine whether the dirs[i] path is a prefix of the | |
6927 | dirs[j] path. */ | |
6928 | int k; | |
6929 | ||
981975b6 RH |
6930 | k = dirs[j].prefix; |
6931 | while (k != -1 && k != i) | |
6932 | k = dirs[k].prefix; | |
6933 | ||
6934 | if (k == i) | |
6935 | { | |
6936 | /* Yes it is. We can possibly safe some memory but | |
6937 | writing the filenames in dirs[j] relative to | |
6938 | dirs[i]. */ | |
6939 | savehere[j] = dirs[i].length; | |
6940 | total += (savehere[j] - saved[j]) * dirs[j].count; | |
6941 | } | |
0b34cf1e UD |
6942 | } |
6943 | } | |
6944 | ||
6945 | /* Check whether we can safe enough to justify adding the dirs[i] | |
6946 | directory. */ | |
6947 | if (total > dirs[i].length + 1) | |
6948 | { | |
981975b6 | 6949 | /* It's worthwhile adding. */ |
c26fbbca | 6950 | for (j = i; j < ndirs; j++) |
0b34cf1e UD |
6951 | if (savehere[j] > 0) |
6952 | { | |
6953 | /* Remember how much we saved for this directory so far. */ | |
6954 | saved[j] = savehere[j]; | |
6955 | ||
6956 | /* Remember the prefix directory. */ | |
6957 | dirs[j].dir_idx = i; | |
6958 | } | |
6959 | } | |
6960 | } | |
6961 | ||
2ad9852d RK |
6962 | /* We have to emit them in the order they appear in the file_table array |
6963 | since the index is used in the debug info generation. To do this | |
6964 | efficiently we generate a back-mapping of the indices first. */ | |
981975b6 | 6965 | backmap = (int *) alloca (file_table.in_use * sizeof (int)); |
2ad9852d | 6966 | for (i = 1; i < (int) file_table.in_use; i++) |
0b34cf1e UD |
6967 | { |
6968 | backmap[files[i].file_idx] = i; | |
2ad9852d | 6969 | |
0b34cf1e UD |
6970 | /* Mark this directory as used. */ |
6971 | dirs[dirs[files[i].dir_idx].dir_idx].used = 1; | |
6972 | } | |
6973 | ||
2ad9852d RK |
6974 | /* That was it. We are ready to emit the information. First emit the |
6975 | directory name table. We have to make sure the first actually emitted | |
6976 | directory name has index one; zero is reserved for the current working | |
6977 | directory. Make sure we do not confuse these indices with the one for the | |
6978 | constructed table (even though most of the time they are identical). */ | |
0b34cf1e | 6979 | idx = 1; |
e57cabac | 6980 | idx_offset = dirs[0].length > 0 ? 1 : 0; |
2ad9852d | 6981 | for (i = 1 - idx_offset; i < ndirs; i++) |
0b34cf1e UD |
6982 | if (dirs[i].used != 0) |
6983 | { | |
6984 | dirs[i].used = idx++; | |
2e4b9b8c RH |
6985 | dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1, |
6986 | "Directory Entry: 0x%x", dirs[i].used); | |
0b34cf1e | 6987 | } |
2ad9852d | 6988 | |
2e4b9b8c RH |
6989 | dw2_asm_output_data (1, 0, "End directory table"); |
6990 | ||
0b34cf1e UD |
6991 | /* Correct the index for the current working directory entry if it |
6992 | exists. */ | |
6993 | if (idx_offset == 0) | |
6994 | dirs[0].used = 0; | |
0b34cf1e UD |
6995 | |
6996 | /* Now write all the file names. */ | |
2ad9852d | 6997 | for (i = 1; i < (int) file_table.in_use; i++) |
0b34cf1e UD |
6998 | { |
6999 | int file_idx = backmap[i]; | |
7000 | int dir_idx = dirs[files[file_idx].dir_idx].dir_idx; | |
7001 | ||
2e4b9b8c RH |
7002 | dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1, |
7003 | "File Entry: 0x%x", i); | |
0b34cf1e UD |
7004 | |
7005 | /* Include directory index. */ | |
2e4b9b8c | 7006 | dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL); |
0b34cf1e UD |
7007 | |
7008 | /* Modification time. */ | |
2e4b9b8c | 7009 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e UD |
7010 | |
7011 | /* File length in bytes. */ | |
2e4b9b8c | 7012 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e | 7013 | } |
2ad9852d | 7014 | |
2e4b9b8c | 7015 | dw2_asm_output_data (1, 0, "End file name table"); |
0b34cf1e UD |
7016 | } |
7017 | ||
7018 | ||
a3f97cbb | 7019 | /* Output the source line number correspondence information. This |
14a774a9 | 7020 | information goes into the .debug_line section. */ |
71dfc51f | 7021 | |
a3f97cbb JW |
7022 | static void |
7023 | output_line_info () | |
7024 | { | |
981975b6 | 7025 | char l1[20], l2[20], p1[20], p2[20]; |
a3f97cbb JW |
7026 | char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
7027 | char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 SS |
7028 | unsigned opc; |
7029 | unsigned n_op_args; | |
7030 | unsigned long lt_index; | |
7031 | unsigned long current_line; | |
7032 | long line_offset; | |
7033 | long line_delta; | |
7034 | unsigned long current_file; | |
7035 | unsigned long function; | |
71dfc51f | 7036 | |
2e4b9b8c RH |
7037 | ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0); |
7038 | ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0); | |
981975b6 RH |
7039 | ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0); |
7040 | ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0); | |
71dfc51f | 7041 | |
2e4b9b8c RH |
7042 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1, |
7043 | "Length of Source Line Info"); | |
7044 | ASM_OUTPUT_LABEL (asm_out_file, l1); | |
71dfc51f | 7045 | |
2e4b9b8c | 7046 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
981975b6 RH |
7047 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length"); |
7048 | ASM_OUTPUT_LABEL (asm_out_file, p1); | |
71dfc51f | 7049 | |
c1a046e5 TT |
7050 | /* Define the architecture-dependent minimum instruction length (in |
7051 | bytes). In this implementation of DWARF, this field is used for | |
7052 | information purposes only. Since GCC generates assembly language, | |
7053 | we have no a priori knowledge of how many instruction bytes are | |
7054 | generated for each source line, and therefore can use only the | |
7055 | DW_LNE_set_address and DW_LNS_fixed_advance_pc line information | |
7056 | commands. Accordingly, we fix this as `1', which is "correct | |
7057 | enough" for all architectures, and don't let the target override. */ | |
7058 | dw2_asm_output_data (1, 1, | |
2e4b9b8c | 7059 | "Minimum Instruction Length"); |
c1a046e5 | 7060 | |
2e4b9b8c RH |
7061 | dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START, |
7062 | "Default is_stmt_start flag"); | |
2e4b9b8c RH |
7063 | dw2_asm_output_data (1, DWARF_LINE_BASE, |
7064 | "Line Base Value (Special Opcodes)"); | |
2e4b9b8c RH |
7065 | dw2_asm_output_data (1, DWARF_LINE_RANGE, |
7066 | "Line Range Value (Special Opcodes)"); | |
2e4b9b8c RH |
7067 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE, |
7068 | "Special Opcode Base"); | |
71dfc51f | 7069 | |
2ad9852d | 7070 | for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++) |
a3f97cbb JW |
7071 | { |
7072 | switch (opc) | |
7073 | { | |
7074 | case DW_LNS_advance_pc: | |
7075 | case DW_LNS_advance_line: | |
7076 | case DW_LNS_set_file: | |
7077 | case DW_LNS_set_column: | |
7078 | case DW_LNS_fixed_advance_pc: | |
7079 | n_op_args = 1; | |
7080 | break; | |
7081 | default: | |
7082 | n_op_args = 0; | |
7083 | break; | |
7084 | } | |
2e4b9b8c RH |
7085 | |
7086 | dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args", | |
7087 | opc, n_op_args); | |
a3f97cbb | 7088 | } |
71dfc51f | 7089 | |
0b34cf1e UD |
7090 | /* Write out the information about the files we use. */ |
7091 | output_file_names (); | |
981975b6 | 7092 | ASM_OUTPUT_LABEL (asm_out_file, p2); |
a3f97cbb | 7093 | |
2f22d404 JM |
7094 | /* We used to set the address register to the first location in the text |
7095 | section here, but that didn't accomplish anything since we already | |
7096 | have a line note for the opening brace of the first function. */ | |
a3f97cbb JW |
7097 | |
7098 | /* Generate the line number to PC correspondence table, encoded as | |
7099 | a series of state machine operations. */ | |
7100 | current_file = 1; | |
7101 | current_line = 1; | |
8b790721 | 7102 | strcpy (prev_line_label, text_section_label); |
a3f97cbb JW |
7103 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) |
7104 | { | |
b3694847 | 7105 | dw_line_info_ref line_info = &line_info_table[lt_index]; |
2f22d404 | 7106 | |
10a11b75 JM |
7107 | #if 0 |
7108 | /* Disable this optimization for now; GDB wants to see two line notes | |
7109 | at the beginning of a function so it can find the end of the | |
7110 | prologue. */ | |
7111 | ||
2f22d404 JM |
7112 | /* Don't emit anything for redundant notes. Just updating the |
7113 | address doesn't accomplish anything, because we already assume | |
7114 | that anything after the last address is this line. */ | |
7115 | if (line_info->dw_line_num == current_line | |
7116 | && line_info->dw_file_num == current_file) | |
7117 | continue; | |
10a11b75 | 7118 | #endif |
71dfc51f | 7119 | |
2e4b9b8c RH |
7120 | /* Emit debug info for the address of the current line. |
7121 | ||
7122 | Unfortunately, we have little choice here currently, and must always | |
2ad9852d | 7123 | use the most general form. GCC does not know the address delta |
2e4b9b8c RH |
7124 | itself, so we can't use DW_LNS_advance_pc. Many ports do have length |
7125 | attributes which will give an upper bound on the address range. We | |
7126 | could perhaps use length attributes to determine when it is safe to | |
7127 | use DW_LNS_fixed_advance_pc. */ | |
7128 | ||
5c90448c | 7129 | ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index); |
f19a6894 JW |
7130 | if (0) |
7131 | { | |
7132 | /* This can handle deltas up to 0xffff. This takes 3 bytes. */ | |
2e4b9b8c RH |
7133 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7134 | "DW_LNS_fixed_advance_pc"); | |
7135 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7136 | } |
7137 | else | |
7138 | { | |
a1a4189d JB |
7139 | /* This can handle any delta. This takes |
7140 | 4+DWARF2_ADDR_SIZE bytes. */ | |
2e4b9b8c RH |
7141 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7142 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7143 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7144 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7145 | } |
2ad9852d | 7146 | |
f19a6894 JW |
7147 | strcpy (prev_line_label, line_label); |
7148 | ||
7149 | /* Emit debug info for the source file of the current line, if | |
7150 | different from the previous line. */ | |
a3f97cbb JW |
7151 | if (line_info->dw_file_num != current_file) |
7152 | { | |
7153 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
7154 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
7155 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
981975b6 | 7156 | file_table.table[current_file]); |
a3f97cbb | 7157 | } |
71dfc51f | 7158 | |
f19a6894 JW |
7159 | /* Emit debug info for the current line number, choosing the encoding |
7160 | that uses the least amount of space. */ | |
2f22d404 | 7161 | if (line_info->dw_line_num != current_line) |
a3f97cbb | 7162 | { |
2f22d404 JM |
7163 | line_offset = line_info->dw_line_num - current_line; |
7164 | line_delta = line_offset - DWARF_LINE_BASE; | |
7165 | current_line = line_info->dw_line_num; | |
7166 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
2ad9852d RK |
7167 | /* This can handle deltas from -10 to 234, using the current |
7168 | definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This | |
7169 | takes 1 byte. */ | |
7170 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, | |
7171 | "line %lu", current_line); | |
2f22d404 JM |
7172 | else |
7173 | { | |
7174 | /* This can handle any delta. This takes at least 4 bytes, | |
7175 | depending on the value being encoded. */ | |
2e4b9b8c RH |
7176 | dw2_asm_output_data (1, DW_LNS_advance_line, |
7177 | "advance to line %lu", current_line); | |
7178 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
7179 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
2f22d404 | 7180 | } |
a94dbf2c JM |
7181 | } |
7182 | else | |
2ad9852d RK |
7183 | /* We still need to start a new row, so output a copy insn. */ |
7184 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
a3f97cbb JW |
7185 | } |
7186 | ||
f19a6894 JW |
7187 | /* Emit debug info for the address of the end of the function. */ |
7188 | if (0) | |
7189 | { | |
2e4b9b8c RH |
7190 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7191 | "DW_LNS_fixed_advance_pc"); | |
7192 | dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL); | |
f19a6894 JW |
7193 | } |
7194 | else | |
7195 | { | |
2e4b9b8c RH |
7196 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7197 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7198 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7199 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL); |
f19a6894 | 7200 | } |
bdb669cb | 7201 | |
2e4b9b8c RH |
7202 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
7203 | dw2_asm_output_data_uleb128 (1, NULL); | |
7204 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
7205 | |
7206 | function = 0; | |
7207 | current_file = 1; | |
7208 | current_line = 1; | |
556273e0 | 7209 | for (lt_index = 0; lt_index < separate_line_info_table_in_use;) |
e90b62db | 7210 | { |
b3694847 | 7211 | dw_separate_line_info_ref line_info |
e90b62db | 7212 | = &separate_line_info_table[lt_index]; |
71dfc51f | 7213 | |
10a11b75 | 7214 | #if 0 |
2f22d404 JM |
7215 | /* Don't emit anything for redundant notes. */ |
7216 | if (line_info->dw_line_num == current_line | |
7217 | && line_info->dw_file_num == current_file | |
7218 | && line_info->function == function) | |
7219 | goto cont; | |
10a11b75 | 7220 | #endif |
2f22d404 | 7221 | |
f19a6894 JW |
7222 | /* Emit debug info for the address of the current line. If this is |
7223 | a new function, or the first line of a function, then we need | |
7224 | to handle it differently. */ | |
5c90448c JM |
7225 | ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL, |
7226 | lt_index); | |
e90b62db JM |
7227 | if (function != line_info->function) |
7228 | { | |
7229 | function = line_info->function; | |
71dfc51f | 7230 | |
e90b62db | 7231 | /* Set the address register to the first line in the function */ |
2e4b9b8c RH |
7232 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7233 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7234 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7235 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
e90b62db JM |
7236 | } |
7237 | else | |
7238 | { | |
f19a6894 JW |
7239 | /* ??? See the DW_LNS_advance_pc comment above. */ |
7240 | if (0) | |
7241 | { | |
2e4b9b8c RH |
7242 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7243 | "DW_LNS_fixed_advance_pc"); | |
7244 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7245 | } |
7246 | else | |
7247 | { | |
2e4b9b8c RH |
7248 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7249 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7250 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7251 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7252 | } |
e90b62db | 7253 | } |
2ad9852d | 7254 | |
f19a6894 | 7255 | strcpy (prev_line_label, line_label); |
71dfc51f | 7256 | |
f19a6894 JW |
7257 | /* Emit debug info for the source file of the current line, if |
7258 | different from the previous line. */ | |
e90b62db JM |
7259 | if (line_info->dw_file_num != current_file) |
7260 | { | |
7261 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
7262 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
7263 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
981975b6 | 7264 | file_table.table[current_file]); |
e90b62db | 7265 | } |
71dfc51f | 7266 | |
f19a6894 JW |
7267 | /* Emit debug info for the current line number, choosing the encoding |
7268 | that uses the least amount of space. */ | |
e90b62db JM |
7269 | if (line_info->dw_line_num != current_line) |
7270 | { | |
7271 | line_offset = line_info->dw_line_num - current_line; | |
7272 | line_delta = line_offset - DWARF_LINE_BASE; | |
7273 | current_line = line_info->dw_line_num; | |
7274 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
2e4b9b8c RH |
7275 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, |
7276 | "line %lu", current_line); | |
e90b62db JM |
7277 | else |
7278 | { | |
2e4b9b8c RH |
7279 | dw2_asm_output_data (1, DW_LNS_advance_line, |
7280 | "advance to line %lu", current_line); | |
7281 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
7282 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
e90b62db JM |
7283 | } |
7284 | } | |
2f22d404 | 7285 | else |
2e4b9b8c | 7286 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); |
71dfc51f | 7287 | |
10a11b75 | 7288 | #if 0 |
2f22d404 | 7289 | cont: |
10a11b75 | 7290 | #endif |
2ad9852d RK |
7291 | |
7292 | lt_index++; | |
e90b62db JM |
7293 | |
7294 | /* If we're done with a function, end its sequence. */ | |
7295 | if (lt_index == separate_line_info_table_in_use | |
7296 | || separate_line_info_table[lt_index].function != function) | |
7297 | { | |
7298 | current_file = 1; | |
7299 | current_line = 1; | |
71dfc51f | 7300 | |
f19a6894 | 7301 | /* Emit debug info for the address of the end of the function. */ |
5c90448c | 7302 | ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function); |
f19a6894 JW |
7303 | if (0) |
7304 | { | |
2e4b9b8c RH |
7305 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7306 | "DW_LNS_fixed_advance_pc"); | |
7307 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7308 | } |
7309 | else | |
7310 | { | |
2e4b9b8c RH |
7311 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7312 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7313 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7314 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7315 | } |
e90b62db JM |
7316 | |
7317 | /* Output the marker for the end of this sequence. */ | |
2e4b9b8c RH |
7318 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
7319 | dw2_asm_output_data_uleb128 (1, NULL); | |
7320 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
7321 | } |
7322 | } | |
f19f17e0 JM |
7323 | |
7324 | /* Output the marker for the end of the line number info. */ | |
2e4b9b8c | 7325 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
a3f97cbb JW |
7326 | } |
7327 | \f | |
a3f97cbb JW |
7328 | /* Given a pointer to a tree node for some base type, return a pointer to |
7329 | a DIE that describes the given type. | |
7330 | ||
7331 | This routine must only be called for GCC type nodes that correspond to | |
7332 | Dwarf base (fundamental) types. */ | |
71dfc51f | 7333 | |
a3f97cbb JW |
7334 | static dw_die_ref |
7335 | base_type_die (type) | |
b3694847 | 7336 | tree type; |
a3f97cbb | 7337 | { |
b3694847 SS |
7338 | dw_die_ref base_type_result; |
7339 | const char *type_name; | |
7340 | enum dwarf_type encoding; | |
7341 | tree name = TYPE_NAME (type); | |
a3f97cbb | 7342 | |
2ad9852d | 7343 | if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE) |
a3f97cbb JW |
7344 | return 0; |
7345 | ||
405f63da MM |
7346 | if (name) |
7347 | { | |
7348 | if (TREE_CODE (name) == TYPE_DECL) | |
7349 | name = DECL_NAME (name); | |
7350 | ||
7351 | type_name = IDENTIFIER_POINTER (name); | |
7352 | } | |
7353 | else | |
7354 | type_name = "__unknown__"; | |
a9d38797 | 7355 | |
a3f97cbb JW |
7356 | switch (TREE_CODE (type)) |
7357 | { | |
a3f97cbb | 7358 | case INTEGER_TYPE: |
a9d38797 | 7359 | /* Carefully distinguish the C character types, without messing |
a3f97cbb | 7360 | up if the language is not C. Note that we check only for the names |
556273e0 | 7361 | that contain spaces; other names might occur by coincidence in other |
a3f97cbb | 7362 | languages. */ |
a9d38797 JM |
7363 | if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE |
7364 | && (type == char_type_node | |
7365 | || ! strcmp (type_name, "signed char") | |
7366 | || ! strcmp (type_name, "unsigned char")))) | |
a3f97cbb | 7367 | { |
a9d38797 JM |
7368 | if (TREE_UNSIGNED (type)) |
7369 | encoding = DW_ATE_unsigned; | |
7370 | else | |
7371 | encoding = DW_ATE_signed; | |
7372 | break; | |
a3f97cbb | 7373 | } |
556273e0 | 7374 | /* else fall through. */ |
a3f97cbb | 7375 | |
a9d38797 JM |
7376 | case CHAR_TYPE: |
7377 | /* GNU Pascal/Ada CHAR type. Not used in C. */ | |
7378 | if (TREE_UNSIGNED (type)) | |
7379 | encoding = DW_ATE_unsigned_char; | |
7380 | else | |
7381 | encoding = DW_ATE_signed_char; | |
a3f97cbb JW |
7382 | break; |
7383 | ||
7384 | case REAL_TYPE: | |
a9d38797 | 7385 | encoding = DW_ATE_float; |
a3f97cbb JW |
7386 | break; |
7387 | ||
405f63da MM |
7388 | /* Dwarf2 doesn't know anything about complex ints, so use |
7389 | a user defined type for it. */ | |
a3f97cbb | 7390 | case COMPLEX_TYPE: |
405f63da MM |
7391 | if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE) |
7392 | encoding = DW_ATE_complex_float; | |
7393 | else | |
7394 | encoding = DW_ATE_lo_user; | |
a3f97cbb JW |
7395 | break; |
7396 | ||
7397 | case BOOLEAN_TYPE: | |
a9d38797 JM |
7398 | /* GNU FORTRAN/Ada/C++ BOOLEAN type. */ |
7399 | encoding = DW_ATE_boolean; | |
a3f97cbb JW |
7400 | break; |
7401 | ||
7402 | default: | |
2ad9852d RK |
7403 | /* No other TREE_CODEs are Dwarf fundamental types. */ |
7404 | abort (); | |
a3f97cbb JW |
7405 | } |
7406 | ||
54ba1f0d | 7407 | base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type); |
14a774a9 RK |
7408 | if (demangle_name_func) |
7409 | type_name = (*demangle_name_func) (type_name); | |
7410 | ||
a9d38797 JM |
7411 | add_AT_string (base_type_result, DW_AT_name, type_name); |
7412 | add_AT_unsigned (base_type_result, DW_AT_byte_size, | |
4e5a8d7b | 7413 | int_size_in_bytes (type)); |
a9d38797 | 7414 | add_AT_unsigned (base_type_result, DW_AT_encoding, encoding); |
a3f97cbb JW |
7415 | |
7416 | return base_type_result; | |
7417 | } | |
7418 | ||
7419 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to | |
7420 | the Dwarf "root" type for the given input type. The Dwarf "root" type of | |
7421 | a given type is generally the same as the given type, except that if the | |
7422 | given type is a pointer or reference type, then the root type of the given | |
7423 | type is the root type of the "basis" type for the pointer or reference | |
7424 | type. (This definition of the "root" type is recursive.) Also, the root | |
7425 | type of a `const' qualified type or a `volatile' qualified type is the | |
7426 | root type of the given type without the qualifiers. */ | |
71dfc51f | 7427 | |
a3f97cbb JW |
7428 | static tree |
7429 | root_type (type) | |
b3694847 | 7430 | tree type; |
a3f97cbb JW |
7431 | { |
7432 | if (TREE_CODE (type) == ERROR_MARK) | |
7433 | return error_mark_node; | |
7434 | ||
7435 | switch (TREE_CODE (type)) | |
7436 | { | |
7437 | case ERROR_MARK: | |
7438 | return error_mark_node; | |
7439 | ||
7440 | case POINTER_TYPE: | |
7441 | case REFERENCE_TYPE: | |
7442 | return type_main_variant (root_type (TREE_TYPE (type))); | |
7443 | ||
7444 | default: | |
7445 | return type_main_variant (type); | |
7446 | } | |
7447 | } | |
7448 | ||
7449 | /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the | |
7450 | given input type is a Dwarf "fundamental" type. Otherwise return null. */ | |
71dfc51f RK |
7451 | |
7452 | static inline int | |
a3f97cbb | 7453 | is_base_type (type) |
b3694847 | 7454 | tree type; |
a3f97cbb JW |
7455 | { |
7456 | switch (TREE_CODE (type)) | |
7457 | { | |
7458 | case ERROR_MARK: | |
7459 | case VOID_TYPE: | |
7460 | case INTEGER_TYPE: | |
7461 | case REAL_TYPE: | |
7462 | case COMPLEX_TYPE: | |
7463 | case BOOLEAN_TYPE: | |
7464 | case CHAR_TYPE: | |
7465 | return 1; | |
7466 | ||
7467 | case SET_TYPE: | |
7468 | case ARRAY_TYPE: | |
7469 | case RECORD_TYPE: | |
7470 | case UNION_TYPE: | |
7471 | case QUAL_UNION_TYPE: | |
7472 | case ENUMERAL_TYPE: | |
7473 | case FUNCTION_TYPE: | |
7474 | case METHOD_TYPE: | |
7475 | case POINTER_TYPE: | |
7476 | case REFERENCE_TYPE: | |
7477 | case FILE_TYPE: | |
7478 | case OFFSET_TYPE: | |
7479 | case LANG_TYPE: | |
604bb87d | 7480 | case VECTOR_TYPE: |
a3f97cbb JW |
7481 | return 0; |
7482 | ||
7483 | default: | |
7484 | abort (); | |
7485 | } | |
71dfc51f | 7486 | |
a3f97cbb JW |
7487 | return 0; |
7488 | } | |
7489 | ||
7490 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging | |
7491 | entry that chains various modifiers in front of the given type. */ | |
71dfc51f | 7492 | |
a3f97cbb JW |
7493 | static dw_die_ref |
7494 | modified_type_die (type, is_const_type, is_volatile_type, context_die) | |
b3694847 SS |
7495 | tree type; |
7496 | int is_const_type; | |
7497 | int is_volatile_type; | |
7498 | dw_die_ref context_die; | |
a3f97cbb | 7499 | { |
b3694847 SS |
7500 | enum tree_code code = TREE_CODE (type); |
7501 | dw_die_ref mod_type_die = NULL; | |
7502 | dw_die_ref sub_die = NULL; | |
7503 | tree item_type = NULL; | |
a3f97cbb JW |
7504 | |
7505 | if (code != ERROR_MARK) | |
7506 | { | |
5101b304 MM |
7507 | tree qualified_type; |
7508 | ||
7509 | /* See if we already have the appropriately qualified variant of | |
7510 | this type. */ | |
c26fbbca | 7511 | qualified_type |
5101b304 MM |
7512 | = get_qualified_type (type, |
7513 | ((is_const_type ? TYPE_QUAL_CONST : 0) | |
c26fbbca | 7514 | | (is_volatile_type |
5101b304 | 7515 | ? TYPE_QUAL_VOLATILE : 0))); |
2ad9852d | 7516 | |
5101b304 MM |
7517 | /* If we do, then we can just use its DIE, if it exists. */ |
7518 | if (qualified_type) | |
7519 | { | |
7520 | mod_type_die = lookup_type_die (qualified_type); | |
7521 | if (mod_type_die) | |
7522 | return mod_type_die; | |
7523 | } | |
bdb669cb | 7524 | |
556273e0 | 7525 | /* Handle C typedef types. */ |
c26fbbca | 7526 | if (qualified_type && TYPE_NAME (qualified_type) |
5101b304 MM |
7527 | && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL |
7528 | && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type))) | |
a94dbf2c | 7529 | { |
5101b304 MM |
7530 | tree type_name = TYPE_NAME (qualified_type); |
7531 | tree dtype = TREE_TYPE (type_name); | |
2ad9852d | 7532 | |
5101b304 | 7533 | if (qualified_type == dtype) |
a94dbf2c JM |
7534 | { |
7535 | /* For a named type, use the typedef. */ | |
5101b304 MM |
7536 | gen_type_die (qualified_type, context_die); |
7537 | mod_type_die = lookup_type_die (qualified_type); | |
a94dbf2c JM |
7538 | } |
7539 | else if (is_const_type < TYPE_READONLY (dtype) | |
7540 | || is_volatile_type < TYPE_VOLATILE (dtype)) | |
7541 | /* cv-unqualified version of named type. Just use the unnamed | |
7542 | type to which it refers. */ | |
71dfc51f | 7543 | mod_type_die |
5101b304 | 7544 | = modified_type_die (DECL_ORIGINAL_TYPE (type_name), |
71dfc51f RK |
7545 | is_const_type, is_volatile_type, |
7546 | context_die); | |
2ad9852d | 7547 | |
71dfc51f | 7548 | /* Else cv-qualified version of named type; fall through. */ |
a94dbf2c JM |
7549 | } |
7550 | ||
7551 | if (mod_type_die) | |
556273e0 KH |
7552 | /* OK. */ |
7553 | ; | |
a94dbf2c | 7554 | else if (is_const_type) |
a3f97cbb | 7555 | { |
54ba1f0d | 7556 | mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type); |
a9d38797 | 7557 | sub_die = modified_type_die (type, 0, is_volatile_type, context_die); |
a3f97cbb JW |
7558 | } |
7559 | else if (is_volatile_type) | |
7560 | { | |
54ba1f0d | 7561 | mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type); |
a9d38797 | 7562 | sub_die = modified_type_die (type, 0, 0, context_die); |
a3f97cbb JW |
7563 | } |
7564 | else if (code == POINTER_TYPE) | |
7565 | { | |
54ba1f0d | 7566 | mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type); |
a3f97cbb | 7567 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 7568 | #if 0 |
a3f97cbb | 7569 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
61b32c02 | 7570 | #endif |
a3f97cbb | 7571 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
7572 | } |
7573 | else if (code == REFERENCE_TYPE) | |
7574 | { | |
54ba1f0d | 7575 | mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type); |
a3f97cbb | 7576 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 7577 | #if 0 |
a3f97cbb | 7578 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
556273e0 | 7579 | #endif |
a3f97cbb | 7580 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
7581 | } |
7582 | else if (is_base_type (type)) | |
71dfc51f | 7583 | mod_type_die = base_type_die (type); |
a3f97cbb JW |
7584 | else |
7585 | { | |
4b674448 JM |
7586 | gen_type_die (type, context_die); |
7587 | ||
a3f97cbb JW |
7588 | /* We have to get the type_main_variant here (and pass that to the |
7589 | `lookup_type_die' routine) because the ..._TYPE node we have | |
7590 | might simply be a *copy* of some original type node (where the | |
7591 | copy was created to help us keep track of typedef names) and | |
7592 | that copy might have a different TYPE_UID from the original | |
a94dbf2c | 7593 | ..._TYPE node. */ |
0e98f924 AH |
7594 | if (TREE_CODE (type) != VECTOR_TYPE) |
7595 | mod_type_die = lookup_type_die (type_main_variant (type)); | |
7596 | else | |
7597 | /* Vectors have the debugging information in the type, | |
7598 | not the main variant. */ | |
7599 | mod_type_die = lookup_type_die (type); | |
3a88cbd1 JL |
7600 | if (mod_type_die == NULL) |
7601 | abort (); | |
a3f97cbb | 7602 | } |
3d2999ba MK |
7603 | |
7604 | /* We want to equate the qualified type to the die below. */ | |
7605 | if (qualified_type) | |
7606 | type = qualified_type; | |
a3f97cbb | 7607 | } |
71dfc51f | 7608 | |
dfcf9891 JW |
7609 | equate_type_number_to_die (type, mod_type_die); |
7610 | if (item_type) | |
71dfc51f RK |
7611 | /* We must do this after the equate_type_number_to_die call, in case |
7612 | this is a recursive type. This ensures that the modified_type_die | |
7613 | recursion will terminate even if the type is recursive. Recursive | |
7614 | types are possible in Ada. */ | |
7615 | sub_die = modified_type_die (item_type, | |
7616 | TYPE_READONLY (item_type), | |
7617 | TYPE_VOLATILE (item_type), | |
7618 | context_die); | |
7619 | ||
a3f97cbb | 7620 | if (sub_die != NULL) |
71dfc51f RK |
7621 | add_AT_die_ref (mod_type_die, DW_AT_type, sub_die); |
7622 | ||
a3f97cbb JW |
7623 | return mod_type_die; |
7624 | } | |
7625 | ||
a3f97cbb | 7626 | /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is |
6d2f8887 | 7627 | an enumerated type. */ |
71dfc51f RK |
7628 | |
7629 | static inline int | |
a3f97cbb | 7630 | type_is_enum (type) |
b3694847 | 7631 | tree type; |
a3f97cbb JW |
7632 | { |
7633 | return TREE_CODE (type) == ENUMERAL_TYPE; | |
7634 | } | |
7635 | ||
7d9d8943 AM |
7636 | /* Return the register number described by a given RTL node. */ |
7637 | ||
7638 | static unsigned int | |
7639 | reg_number (rtl) | |
b3694847 | 7640 | rtx rtl; |
7d9d8943 | 7641 | { |
b3694847 | 7642 | unsigned regno = REGNO (rtl); |
7d9d8943 AM |
7643 | |
7644 | if (regno >= FIRST_PSEUDO_REGISTER) | |
e7af1d45 | 7645 | abort (); |
7d9d8943 | 7646 | |
e7af1d45 | 7647 | return DBX_REGISTER_NUMBER (regno); |
7d9d8943 AM |
7648 | } |
7649 | ||
e7af1d45 RK |
7650 | /* Return a location descriptor that designates a machine register or |
7651 | zero if there is no such. */ | |
71dfc51f | 7652 | |
a3f97cbb JW |
7653 | static dw_loc_descr_ref |
7654 | reg_loc_descriptor (rtl) | |
b3694847 | 7655 | rtx rtl; |
a3f97cbb | 7656 | { |
b3694847 | 7657 | dw_loc_descr_ref loc_result = NULL; |
e7af1d45 | 7658 | unsigned reg; |
71dfc51f | 7659 | |
e7af1d45 RK |
7660 | if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER) |
7661 | return 0; | |
7662 | ||
7663 | reg = reg_number (rtl); | |
85066503 | 7664 | if (reg <= 31) |
71dfc51f | 7665 | loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0); |
a3f97cbb | 7666 | else |
71dfc51f RK |
7667 | loc_result = new_loc_descr (DW_OP_regx, reg, 0); |
7668 | ||
a3f97cbb JW |
7669 | return loc_result; |
7670 | } | |
7671 | ||
d8041cc8 RH |
7672 | /* Return a location descriptor that designates a constant. */ |
7673 | ||
7674 | static dw_loc_descr_ref | |
7675 | int_loc_descriptor (i) | |
7676 | HOST_WIDE_INT i; | |
7677 | { | |
7678 | enum dwarf_location_atom op; | |
7679 | ||
7680 | /* Pick the smallest representation of a constant, rather than just | |
7681 | defaulting to the LEB encoding. */ | |
7682 | if (i >= 0) | |
7683 | { | |
7684 | if (i <= 31) | |
7685 | op = DW_OP_lit0 + i; | |
7686 | else if (i <= 0xff) | |
7687 | op = DW_OP_const1u; | |
7688 | else if (i <= 0xffff) | |
7689 | op = DW_OP_const2u; | |
7690 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
7691 | || i <= 0xffffffff) | |
7692 | op = DW_OP_const4u; | |
7693 | else | |
7694 | op = DW_OP_constu; | |
7695 | } | |
7696 | else | |
7697 | { | |
7698 | if (i >= -0x80) | |
7699 | op = DW_OP_const1s; | |
7700 | else if (i >= -0x8000) | |
7701 | op = DW_OP_const2s; | |
7702 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
7703 | || i >= -0x80000000) | |
7704 | op = DW_OP_const4s; | |
7705 | else | |
7706 | op = DW_OP_consts; | |
7707 | } | |
7708 | ||
7709 | return new_loc_descr (op, i, 0); | |
7710 | } | |
7711 | ||
a3f97cbb | 7712 | /* Return a location descriptor that designates a base+offset location. */ |
71dfc51f | 7713 | |
a3f97cbb JW |
7714 | static dw_loc_descr_ref |
7715 | based_loc_descr (reg, offset) | |
7716 | unsigned reg; | |
7717 | long int offset; | |
7718 | { | |
b3694847 | 7719 | dw_loc_descr_ref loc_result; |
810429b7 JM |
7720 | /* For the "frame base", we use the frame pointer or stack pointer |
7721 | registers, since the RTL for local variables is relative to one of | |
7722 | them. */ | |
b3694847 SS |
7723 | unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed |
7724 | ? HARD_FRAME_POINTER_REGNUM | |
7725 | : STACK_POINTER_REGNUM); | |
71dfc51f | 7726 | |
a3f97cbb | 7727 | if (reg == fp_reg) |
71dfc51f | 7728 | loc_result = new_loc_descr (DW_OP_fbreg, offset, 0); |
85066503 | 7729 | else if (reg <= 31) |
71dfc51f | 7730 | loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0); |
a3f97cbb | 7731 | else |
71dfc51f RK |
7732 | loc_result = new_loc_descr (DW_OP_bregx, reg, offset); |
7733 | ||
a3f97cbb JW |
7734 | return loc_result; |
7735 | } | |
7736 | ||
7737 | /* Return true if this RTL expression describes a base+offset calculation. */ | |
71dfc51f RK |
7738 | |
7739 | static inline int | |
a3f97cbb | 7740 | is_based_loc (rtl) |
b3694847 | 7741 | rtx rtl; |
a3f97cbb | 7742 | { |
173bf5be KH |
7743 | return (GET_CODE (rtl) == PLUS |
7744 | && ((GET_CODE (XEXP (rtl, 0)) == REG | |
7745 | && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER | |
7746 | && GET_CODE (XEXP (rtl, 1)) == CONST_INT))); | |
a3f97cbb JW |
7747 | } |
7748 | ||
7749 | /* The following routine converts the RTL for a variable or parameter | |
7750 | (resident in memory) into an equivalent Dwarf representation of a | |
7751 | mechanism for getting the address of that same variable onto the top of a | |
7752 | hypothetical "address evaluation" stack. | |
71dfc51f | 7753 | |
a3f97cbb JW |
7754 | When creating memory location descriptors, we are effectively transforming |
7755 | the RTL for a memory-resident object into its Dwarf postfix expression | |
7756 | equivalent. This routine recursively descends an RTL tree, turning | |
e60d4d7b JL |
7757 | it into Dwarf postfix code as it goes. |
7758 | ||
7759 | MODE is the mode of the memory reference, needed to handle some | |
e7af1d45 RK |
7760 | autoincrement addressing modes. |
7761 | ||
7762 | Return 0 if we can't represent the location. */ | |
71dfc51f | 7763 | |
a3f97cbb | 7764 | static dw_loc_descr_ref |
e60d4d7b | 7765 | mem_loc_descriptor (rtl, mode) |
b3694847 | 7766 | rtx rtl; |
e60d4d7b | 7767 | enum machine_mode mode; |
a3f97cbb JW |
7768 | { |
7769 | dw_loc_descr_ref mem_loc_result = NULL; | |
e7af1d45 | 7770 | |
556273e0 | 7771 | /* Note that for a dynamically sized array, the location we will generate a |
a3f97cbb JW |
7772 | description of here will be the lowest numbered location which is |
7773 | actually within the array. That's *not* necessarily the same as the | |
7774 | zeroth element of the array. */ | |
71dfc51f | 7775 | |
1865dbb5 JM |
7776 | #ifdef ASM_SIMPLIFY_DWARF_ADDR |
7777 | rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); | |
7778 | #endif | |
7779 | ||
a3f97cbb JW |
7780 | switch (GET_CODE (rtl)) |
7781 | { | |
e60d4d7b JL |
7782 | case POST_INC: |
7783 | case POST_DEC: | |
e2134eea | 7784 | case POST_MODIFY: |
e60d4d7b JL |
7785 | /* POST_INC and POST_DEC can be handled just like a SUBREG. So we |
7786 | just fall into the SUBREG code. */ | |
7787 | ||
2ad9852d | 7788 | /* ... fall through ... */ |
e60d4d7b | 7789 | |
a3f97cbb JW |
7790 | case SUBREG: |
7791 | /* The case of a subreg may arise when we have a local (register) | |
7792 | variable or a formal (register) parameter which doesn't quite fill | |
7793 | up an entire register. For now, just assume that it is | |
7794 | legitimate to make the Dwarf info refer to the whole register which | |
7795 | contains the given subreg. */ | |
ddef6bc7 | 7796 | rtl = SUBREG_REG (rtl); |
71dfc51f | 7797 | |
2ad9852d | 7798 | /* ... fall through ... */ |
a3f97cbb JW |
7799 | |
7800 | case REG: | |
7801 | /* Whenever a register number forms a part of the description of the | |
7802 | method for calculating the (dynamic) address of a memory resident | |
556273e0 | 7803 | object, DWARF rules require the register number be referred to as |
a3f97cbb JW |
7804 | a "base register". This distinction is not based in any way upon |
7805 | what category of register the hardware believes the given register | |
7806 | belongs to. This is strictly DWARF terminology we're dealing with | |
7807 | here. Note that in cases where the location of a memory-resident | |
7808 | data object could be expressed as: OP_ADD (OP_BASEREG (basereg), | |
7809 | OP_CONST (0)) the actual DWARF location descriptor that we generate | |
7810 | may just be OP_BASEREG (basereg). This may look deceptively like | |
7811 | the object in question was allocated to a register (rather than in | |
7812 | memory) so DWARF consumers need to be aware of the subtle | |
7813 | distinction between OP_REG and OP_BASEREG. */ | |
e7af1d45 RK |
7814 | if (REGNO (rtl) < FIRST_PSEUDO_REGISTER) |
7815 | mem_loc_result = based_loc_descr (reg_number (rtl), 0); | |
a3f97cbb JW |
7816 | break; |
7817 | ||
7818 | case MEM: | |
f7d2b0ed | 7819 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
e7af1d45 RK |
7820 | if (mem_loc_result != 0) |
7821 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0)); | |
a3f97cbb JW |
7822 | break; |
7823 | ||
d8041cc8 RH |
7824 | case LABEL_REF: |
7825 | /* Some ports can transform a symbol ref into a label ref, because | |
368f4cd6 NC |
7826 | the symbol ref is too far away and has to be dumped into a constant |
7827 | pool. */ | |
a3f97cbb JW |
7828 | case CONST: |
7829 | case SYMBOL_REF: | |
6331d1c1 | 7830 | /* Alternatively, the symbol in the constant pool might be referenced |
c6f9b9a1 | 7831 | by a different symbol. */ |
2ad9852d | 7832 | if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl)) |
79cdfa4b | 7833 | { |
149d6f9e JJ |
7834 | bool marked; |
7835 | rtx tmp = get_pool_constant_mark (rtl, &marked); | |
2ad9852d | 7836 | |
6331d1c1 | 7837 | if (GET_CODE (tmp) == SYMBOL_REF) |
149d6f9e JJ |
7838 | { |
7839 | rtl = tmp; | |
7840 | if (CONSTANT_POOL_ADDRESS_P (tmp)) | |
7841 | get_pool_constant_mark (tmp, &marked); | |
7842 | else | |
7843 | marked = true; | |
7844 | } | |
7845 | ||
7846 | /* If all references to this pool constant were optimized away, | |
7847 | it was not output and thus we can't represent it. | |
7848 | FIXME: might try to use DW_OP_const_value here, though | |
7849 | DW_OP_piece complicates it. */ | |
7850 | if (!marked) | |
7851 | return 0; | |
79cdfa4b TM |
7852 | } |
7853 | ||
a3f97cbb JW |
7854 | mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0); |
7855 | mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
c470afad RK |
7856 | mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl; |
7857 | VARRAY_PUSH_RTX (used_rtx_varray, rtl); | |
a3f97cbb JW |
7858 | break; |
7859 | ||
e2134eea JH |
7860 | case PRE_MODIFY: |
7861 | /* Extract the PLUS expression nested inside and fall into | |
0407c02b | 7862 | PLUS code below. */ |
e2134eea JH |
7863 | rtl = XEXP (rtl, 1); |
7864 | goto plus; | |
7865 | ||
e60d4d7b JL |
7866 | case PRE_INC: |
7867 | case PRE_DEC: | |
7868 | /* Turn these into a PLUS expression and fall into the PLUS code | |
7869 | below. */ | |
7870 | rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0), | |
7871 | GEN_INT (GET_CODE (rtl) == PRE_INC | |
556273e0 KH |
7872 | ? GET_MODE_UNIT_SIZE (mode) |
7873 | : -GET_MODE_UNIT_SIZE (mode))); | |
7874 | ||
2ad9852d | 7875 | /* ... fall through ... */ |
e60d4d7b | 7876 | |
a3f97cbb | 7877 | case PLUS: |
e2134eea | 7878 | plus: |
a3f97cbb | 7879 | if (is_based_loc (rtl)) |
71dfc51f RK |
7880 | mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)), |
7881 | INTVAL (XEXP (rtl, 1))); | |
a3f97cbb JW |
7882 | else |
7883 | { | |
d8041cc8 | 7884 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode); |
e7af1d45 RK |
7885 | if (mem_loc_result == 0) |
7886 | break; | |
d8041cc8 RH |
7887 | |
7888 | if (GET_CODE (XEXP (rtl, 1)) == CONST_INT | |
7889 | && INTVAL (XEXP (rtl, 1)) >= 0) | |
e7af1d45 RK |
7890 | add_loc_descr (&mem_loc_result, |
7891 | new_loc_descr (DW_OP_plus_uconst, | |
7892 | INTVAL (XEXP (rtl, 1)), 0)); | |
d8041cc8 RH |
7893 | else |
7894 | { | |
7895 | add_loc_descr (&mem_loc_result, | |
7896 | mem_loc_descriptor (XEXP (rtl, 1), mode)); | |
7897 | add_loc_descr (&mem_loc_result, | |
7898 | new_loc_descr (DW_OP_plus, 0, 0)); | |
7899 | } | |
a3f97cbb JW |
7900 | } |
7901 | break; | |
7902 | ||
dd2478ae | 7903 | case MULT: |
e7af1d45 RK |
7904 | { |
7905 | /* If a pseudo-reg is optimized away, it is possible for it to | |
7906 | be replaced with a MEM containing a multiply. */ | |
7907 | dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode); | |
7908 | dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode); | |
7909 | ||
7910 | if (op0 == 0 || op1 == 0) | |
7911 | break; | |
7912 | ||
7913 | mem_loc_result = op0; | |
7914 | add_loc_descr (&mem_loc_result, op1); | |
7915 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0)); | |
7916 | break; | |
7917 | } | |
dd2478ae | 7918 | |
a3f97cbb | 7919 | case CONST_INT: |
d8041cc8 | 7920 | mem_loc_result = int_loc_descriptor (INTVAL (rtl)); |
a3f97cbb JW |
7921 | break; |
7922 | ||
a9e8a5ee RK |
7923 | case ADDRESSOF: |
7924 | /* If this is a MEM, return its address. Otherwise, we can't | |
7925 | represent this. */ | |
7926 | if (GET_CODE (XEXP (rtl, 0)) == MEM) | |
7927 | return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode); | |
7928 | else | |
7929 | return 0; | |
7930 | ||
a3f97cbb JW |
7931 | default: |
7932 | abort (); | |
7933 | } | |
71dfc51f | 7934 | |
a3f97cbb JW |
7935 | return mem_loc_result; |
7936 | } | |
7937 | ||
956d6950 | 7938 | /* Return a descriptor that describes the concatenation of two locations. |
4401bf24 JL |
7939 | This is typically a complex variable. */ |
7940 | ||
7941 | static dw_loc_descr_ref | |
7942 | concat_loc_descriptor (x0, x1) | |
b3694847 | 7943 | rtx x0, x1; |
4401bf24 JL |
7944 | { |
7945 | dw_loc_descr_ref cc_loc_result = NULL; | |
e7af1d45 RK |
7946 | dw_loc_descr_ref x0_ref = loc_descriptor (x0); |
7947 | dw_loc_descr_ref x1_ref = loc_descriptor (x1); | |
4401bf24 | 7948 | |
e7af1d45 RK |
7949 | if (x0_ref == 0 || x1_ref == 0) |
7950 | return 0; | |
7951 | ||
7952 | cc_loc_result = x0_ref; | |
4401bf24 | 7953 | add_loc_descr (&cc_loc_result, |
e7af1d45 RK |
7954 | new_loc_descr (DW_OP_piece, |
7955 | GET_MODE_SIZE (GET_MODE (x0)), 0)); | |
4401bf24 | 7956 | |
e7af1d45 | 7957 | add_loc_descr (&cc_loc_result, x1_ref); |
4401bf24 | 7958 | add_loc_descr (&cc_loc_result, |
e7af1d45 RK |
7959 | new_loc_descr (DW_OP_piece, |
7960 | GET_MODE_SIZE (GET_MODE (x1)), 0)); | |
4401bf24 JL |
7961 | |
7962 | return cc_loc_result; | |
7963 | } | |
7964 | ||
a3f97cbb JW |
7965 | /* Output a proper Dwarf location descriptor for a variable or parameter |
7966 | which is either allocated in a register or in a memory location. For a | |
7967 | register, we just generate an OP_REG and the register number. For a | |
7968 | memory location we provide a Dwarf postfix expression describing how to | |
e7af1d45 RK |
7969 | generate the (dynamic) address of the object onto the address stack. |
7970 | ||
7971 | If we don't know how to describe it, return 0. */ | |
71dfc51f | 7972 | |
a3f97cbb JW |
7973 | static dw_loc_descr_ref |
7974 | loc_descriptor (rtl) | |
b3694847 | 7975 | rtx rtl; |
a3f97cbb JW |
7976 | { |
7977 | dw_loc_descr_ref loc_result = NULL; | |
e7af1d45 | 7978 | |
a3f97cbb JW |
7979 | switch (GET_CODE (rtl)) |
7980 | { | |
7981 | case SUBREG: | |
a3f97cbb JW |
7982 | /* The case of a subreg may arise when we have a local (register) |
7983 | variable or a formal (register) parameter which doesn't quite fill | |
71dfc51f | 7984 | up an entire register. For now, just assume that it is |
a3f97cbb JW |
7985 | legitimate to make the Dwarf info refer to the whole register which |
7986 | contains the given subreg. */ | |
ddef6bc7 | 7987 | rtl = SUBREG_REG (rtl); |
71dfc51f | 7988 | |
2ad9852d | 7989 | /* ... fall through ... */ |
a3f97cbb JW |
7990 | |
7991 | case REG: | |
5c90448c | 7992 | loc_result = reg_loc_descriptor (rtl); |
a3f97cbb JW |
7993 | break; |
7994 | ||
7995 | case MEM: | |
e60d4d7b | 7996 | loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
a3f97cbb JW |
7997 | break; |
7998 | ||
4401bf24 JL |
7999 | case CONCAT: |
8000 | loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1)); | |
8001 | break; | |
8002 | ||
a3f97cbb | 8003 | default: |
71dfc51f | 8004 | abort (); |
a3f97cbb | 8005 | } |
71dfc51f | 8006 | |
a3f97cbb JW |
8007 | return loc_result; |
8008 | } | |
8009 | ||
2ad9852d RK |
8010 | /* Similar, but generate the descriptor from trees instead of rtl. This comes |
8011 | up particularly with variable length arrays. If ADDRESSP is nonzero, we are | |
8012 | looking for an address. Otherwise, we return a value. If we can't make a | |
8013 | descriptor, return 0. */ | |
d8041cc8 RH |
8014 | |
8015 | static dw_loc_descr_ref | |
8016 | loc_descriptor_from_tree (loc, addressp) | |
8017 | tree loc; | |
8018 | int addressp; | |
8019 | { | |
e7af1d45 RK |
8020 | dw_loc_descr_ref ret, ret1; |
8021 | int indirect_p = 0; | |
d8041cc8 RH |
8022 | int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc)); |
8023 | enum dwarf_location_atom op; | |
8024 | ||
8025 | /* ??? Most of the time we do not take proper care for sign/zero | |
8026 | extending the values properly. Hopefully this won't be a real | |
8027 | problem... */ | |
8028 | ||
8029 | switch (TREE_CODE (loc)) | |
8030 | { | |
8031 | case ERROR_MARK: | |
e7af1d45 | 8032 | return 0; |
d8041cc8 | 8033 | |
b4ae5201 | 8034 | case WITH_RECORD_EXPR: |
e7af1d45 | 8035 | case PLACEHOLDER_EXPR: |
b4ae5201 RK |
8036 | /* This case involves extracting fields from an object to determine the |
8037 | position of other fields. We don't try to encode this here. The | |
8038 | only user of this is Ada, which encodes the needed information using | |
8039 | the names of types. */ | |
e7af1d45 | 8040 | return 0; |
b4ae5201 | 8041 | |
aea9695c RK |
8042 | case CALL_EXPR: |
8043 | return 0; | |
8044 | ||
8045 | case ADDR_EXPR: | |
8046 | /* We can support this only if we can look through conversions and | |
8047 | find an INDIRECT_EXPR. */ | |
8048 | for (loc = TREE_OPERAND (loc, 0); | |
8049 | TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR | |
8050 | || TREE_CODE (loc) == NON_LVALUE_EXPR | |
8051 | || TREE_CODE (loc) == VIEW_CONVERT_EXPR | |
8052 | || TREE_CODE (loc) == SAVE_EXPR; | |
8053 | loc = TREE_OPERAND (loc, 0)) | |
8054 | ; | |
8055 | ||
8056 | return (TREE_CODE (loc) == INDIRECT_REF | |
8057 | ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp) | |
8058 | : 0); | |
8059 | ||
d8041cc8 RH |
8060 | case VAR_DECL: |
8061 | case PARM_DECL: | |
8062 | { | |
8063 | rtx rtl = rtl_for_decl_location (loc); | |
d8041cc8 | 8064 | |
a97c9600 | 8065 | if (rtl == NULL_RTX) |
e7af1d45 | 8066 | return 0; |
a97c9600 | 8067 | else if (CONSTANT_P (rtl)) |
d8041cc8 RH |
8068 | { |
8069 | ret = new_loc_descr (DW_OP_addr, 0, 0); | |
8070 | ret->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
8071 | ret->dw_loc_oprnd1.v.val_addr = rtl; | |
e7af1d45 | 8072 | indirect_p = 1; |
d8041cc8 RH |
8073 | } |
8074 | else | |
8075 | { | |
c28abdf0 RH |
8076 | enum machine_mode mode = GET_MODE (rtl); |
8077 | ||
d8041cc8 RH |
8078 | if (GET_CODE (rtl) == MEM) |
8079 | { | |
e7af1d45 | 8080 | indirect_p = 1; |
d8041cc8 RH |
8081 | rtl = XEXP (rtl, 0); |
8082 | } | |
2ad9852d | 8083 | |
d8041cc8 RH |
8084 | ret = mem_loc_descriptor (rtl, mode); |
8085 | } | |
8086 | } | |
8087 | break; | |
8088 | ||
8089 | case INDIRECT_REF: | |
8090 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 | 8091 | indirect_p = 1; |
d8041cc8 RH |
8092 | break; |
8093 | ||
749552c4 RK |
8094 | case COMPOUND_EXPR: |
8095 | return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp); | |
8096 | ||
ed972b14 RK |
8097 | case NOP_EXPR: |
8098 | case CONVERT_EXPR: | |
8099 | case NON_LVALUE_EXPR: | |
ed239f5a | 8100 | case VIEW_CONVERT_EXPR: |
b4ae5201 | 8101 | case SAVE_EXPR: |
ed972b14 | 8102 | return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp); |
e57cabac | 8103 | |
d8041cc8 RH |
8104 | case COMPONENT_REF: |
8105 | case BIT_FIELD_REF: | |
8106 | case ARRAY_REF: | |
b4e3fabb | 8107 | case ARRAY_RANGE_REF: |
d8041cc8 RH |
8108 | { |
8109 | tree obj, offset; | |
8110 | HOST_WIDE_INT bitsize, bitpos, bytepos; | |
8111 | enum machine_mode mode; | |
8112 | int volatilep; | |
d8041cc8 RH |
8113 | |
8114 | obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode, | |
a06ef755 | 8115 | &unsignedp, &volatilep); |
e7af1d45 RK |
8116 | |
8117 | if (obj == loc) | |
8118 | return 0; | |
8119 | ||
d8041cc8 | 8120 | ret = loc_descriptor_from_tree (obj, 1); |
e7af1d45 | 8121 | if (ret == 0 |
2ad9852d | 8122 | || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0) |
e7af1d45 | 8123 | return 0; |
d8041cc8 RH |
8124 | |
8125 | if (offset != NULL_TREE) | |
8126 | { | |
8127 | /* Variable offset. */ | |
8128 | add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0)); | |
8129 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
8130 | } | |
8131 | ||
e7af1d45 RK |
8132 | if (!addressp) |
8133 | indirect_p = 1; | |
d8041cc8 RH |
8134 | |
8135 | bytepos = bitpos / BITS_PER_UNIT; | |
8136 | if (bytepos > 0) | |
8137 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0)); | |
8138 | else if (bytepos < 0) | |
8139 | { | |
8140 | add_loc_descr (&ret, int_loc_descriptor (bytepos)); | |
8141 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
8142 | } | |
8143 | break; | |
8144 | } | |
8145 | ||
8146 | case INTEGER_CST: | |
8147 | if (host_integerp (loc, 0)) | |
8148 | ret = int_loc_descriptor (tree_low_cst (loc, 0)); | |
e7af1d45 RK |
8149 | else |
8150 | return 0; | |
d8041cc8 | 8151 | break; |
d8041cc8 | 8152 | |
c26fbbca | 8153 | case TRUTH_AND_EXPR: |
9702143f | 8154 | case TRUTH_ANDIF_EXPR: |
d8041cc8 RH |
8155 | case BIT_AND_EXPR: |
8156 | op = DW_OP_and; | |
8157 | goto do_binop; | |
e7af1d45 | 8158 | |
9702143f | 8159 | case TRUTH_XOR_EXPR: |
d8041cc8 RH |
8160 | case BIT_XOR_EXPR: |
8161 | op = DW_OP_xor; | |
8162 | goto do_binop; | |
e7af1d45 | 8163 | |
9702143f RK |
8164 | case TRUTH_OR_EXPR: |
8165 | case TRUTH_ORIF_EXPR: | |
d8041cc8 RH |
8166 | case BIT_IOR_EXPR: |
8167 | op = DW_OP_or; | |
8168 | goto do_binop; | |
e7af1d45 | 8169 | |
d8041cc8 RH |
8170 | case TRUNC_DIV_EXPR: |
8171 | op = DW_OP_div; | |
8172 | goto do_binop; | |
e7af1d45 | 8173 | |
d8041cc8 RH |
8174 | case MINUS_EXPR: |
8175 | op = DW_OP_minus; | |
8176 | goto do_binop; | |
e7af1d45 | 8177 | |
d8041cc8 RH |
8178 | case TRUNC_MOD_EXPR: |
8179 | op = DW_OP_mod; | |
8180 | goto do_binop; | |
e7af1d45 | 8181 | |
d8041cc8 RH |
8182 | case MULT_EXPR: |
8183 | op = DW_OP_mul; | |
8184 | goto do_binop; | |
e7af1d45 | 8185 | |
d8041cc8 RH |
8186 | case LSHIFT_EXPR: |
8187 | op = DW_OP_shl; | |
8188 | goto do_binop; | |
e7af1d45 | 8189 | |
d8041cc8 RH |
8190 | case RSHIFT_EXPR: |
8191 | op = (unsignedp ? DW_OP_shr : DW_OP_shra); | |
8192 | goto do_binop; | |
e7af1d45 | 8193 | |
d8041cc8 RH |
8194 | case PLUS_EXPR: |
8195 | if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST | |
8196 | && host_integerp (TREE_OPERAND (loc, 1), 0)) | |
8197 | { | |
8198 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8199 | if (ret == 0) |
8200 | return 0; | |
8201 | ||
d8041cc8 RH |
8202 | add_loc_descr (&ret, |
8203 | new_loc_descr (DW_OP_plus_uconst, | |
8204 | tree_low_cst (TREE_OPERAND (loc, 1), | |
8205 | 0), | |
8206 | 0)); | |
8207 | break; | |
8208 | } | |
e7af1d45 | 8209 | |
d8041cc8 RH |
8210 | op = DW_OP_plus; |
8211 | goto do_binop; | |
2ad9852d | 8212 | |
d8041cc8 RH |
8213 | case LE_EXPR: |
8214 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8215 | return 0; |
8216 | ||
d8041cc8 RH |
8217 | op = DW_OP_le; |
8218 | goto do_binop; | |
e7af1d45 | 8219 | |
d8041cc8 RH |
8220 | case GE_EXPR: |
8221 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8222 | return 0; |
8223 | ||
d8041cc8 RH |
8224 | op = DW_OP_ge; |
8225 | goto do_binop; | |
e7af1d45 | 8226 | |
d8041cc8 RH |
8227 | case LT_EXPR: |
8228 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8229 | return 0; |
8230 | ||
d8041cc8 RH |
8231 | op = DW_OP_lt; |
8232 | goto do_binop; | |
e7af1d45 | 8233 | |
d8041cc8 RH |
8234 | case GT_EXPR: |
8235 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8236 | return 0; |
8237 | ||
d8041cc8 RH |
8238 | op = DW_OP_gt; |
8239 | goto do_binop; | |
e7af1d45 | 8240 | |
d8041cc8 RH |
8241 | case EQ_EXPR: |
8242 | op = DW_OP_eq; | |
8243 | goto do_binop; | |
e7af1d45 | 8244 | |
d8041cc8 RH |
8245 | case NE_EXPR: |
8246 | op = DW_OP_ne; | |
8247 | goto do_binop; | |
8248 | ||
8249 | do_binop: | |
8250 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8251 | ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); |
8252 | if (ret == 0 || ret1 == 0) | |
8253 | return 0; | |
8254 | ||
8255 | add_loc_descr (&ret, ret1); | |
d8041cc8 RH |
8256 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); |
8257 | break; | |
8258 | ||
9702143f | 8259 | case TRUTH_NOT_EXPR: |
d8041cc8 RH |
8260 | case BIT_NOT_EXPR: |
8261 | op = DW_OP_not; | |
8262 | goto do_unop; | |
e7af1d45 | 8263 | |
d8041cc8 RH |
8264 | case ABS_EXPR: |
8265 | op = DW_OP_abs; | |
8266 | goto do_unop; | |
e7af1d45 | 8267 | |
d8041cc8 RH |
8268 | case NEGATE_EXPR: |
8269 | op = DW_OP_neg; | |
8270 | goto do_unop; | |
8271 | ||
8272 | do_unop: | |
8273 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8274 | if (ret == 0) |
8275 | return 0; | |
8276 | ||
d8041cc8 RH |
8277 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); |
8278 | break; | |
8279 | ||
8280 | case MAX_EXPR: | |
8281 | loc = build (COND_EXPR, TREE_TYPE (loc), | |
8282 | build (LT_EXPR, integer_type_node, | |
8283 | TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)), | |
8284 | TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0)); | |
2ad9852d | 8285 | |
3ef42a0c | 8286 | /* ... fall through ... */ |
d8041cc8 RH |
8287 | |
8288 | case COND_EXPR: | |
8289 | { | |
e7af1d45 RK |
8290 | dw_loc_descr_ref lhs |
8291 | = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); | |
8292 | dw_loc_descr_ref rhs | |
8293 | = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0); | |
d8041cc8 RH |
8294 | dw_loc_descr_ref bra_node, jump_node, tmp; |
8295 | ||
8296 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8297 | if (ret == 0 || lhs == 0 || rhs == 0) |
8298 | return 0; | |
8299 | ||
d8041cc8 RH |
8300 | bra_node = new_loc_descr (DW_OP_bra, 0, 0); |
8301 | add_loc_descr (&ret, bra_node); | |
8302 | ||
e7af1d45 | 8303 | add_loc_descr (&ret, rhs); |
d8041cc8 RH |
8304 | jump_node = new_loc_descr (DW_OP_skip, 0, 0); |
8305 | add_loc_descr (&ret, jump_node); | |
8306 | ||
e7af1d45 | 8307 | add_loc_descr (&ret, lhs); |
d8041cc8 | 8308 | bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc; |
e7af1d45 | 8309 | bra_node->dw_loc_oprnd1.v.val_loc = lhs; |
d8041cc8 RH |
8310 | |
8311 | /* ??? Need a node to point the skip at. Use a nop. */ | |
8312 | tmp = new_loc_descr (DW_OP_nop, 0, 0); | |
8313 | add_loc_descr (&ret, tmp); | |
8314 | jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc; | |
8315 | jump_node->dw_loc_oprnd1.v.val_loc = tmp; | |
8316 | } | |
8317 | break; | |
8318 | ||
8319 | default: | |
8320 | abort (); | |
8321 | } | |
8322 | ||
e7af1d45 RK |
8323 | /* Show if we can't fill the request for an address. */ |
8324 | if (addressp && indirect_p == 0) | |
8325 | return 0; | |
d8041cc8 RH |
8326 | |
8327 | /* If we've got an address and don't want one, dereference. */ | |
e7af1d45 | 8328 | if (!addressp && indirect_p > 0) |
d8041cc8 | 8329 | { |
e7af1d45 RK |
8330 | HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc)); |
8331 | ||
8332 | if (size > DWARF2_ADDR_SIZE || size == -1) | |
8333 | return 0; | |
2ad9852d | 8334 | else if (size == DWARF2_ADDR_SIZE) |
d8041cc8 RH |
8335 | op = DW_OP_deref; |
8336 | else | |
8337 | op = DW_OP_deref_size; | |
e7af1d45 RK |
8338 | |
8339 | add_loc_descr (&ret, new_loc_descr (op, size, 0)); | |
d8041cc8 RH |
8340 | } |
8341 | ||
8342 | return ret; | |
8343 | } | |
8344 | ||
665f2503 | 8345 | /* Given a value, round it up to the lowest multiple of `boundary' |
a3f97cbb | 8346 | which is not less than the value itself. */ |
71dfc51f | 8347 | |
665f2503 | 8348 | static inline HOST_WIDE_INT |
a3f97cbb | 8349 | ceiling (value, boundary) |
665f2503 RK |
8350 | HOST_WIDE_INT value; |
8351 | unsigned int boundary; | |
a3f97cbb JW |
8352 | { |
8353 | return (((value + boundary - 1) / boundary) * boundary); | |
8354 | } | |
8355 | ||
8356 | /* Given a pointer to what is assumed to be a FIELD_DECL node, return a | |
8357 | pointer to the declared type for the relevant field variable, or return | |
8358 | `integer_type_node' if the given node turns out to be an | |
8359 | ERROR_MARK node. */ | |
71dfc51f RK |
8360 | |
8361 | static inline tree | |
a3f97cbb | 8362 | field_type (decl) |
b3694847 | 8363 | tree decl; |
a3f97cbb | 8364 | { |
b3694847 | 8365 | tree type; |
a3f97cbb JW |
8366 | |
8367 | if (TREE_CODE (decl) == ERROR_MARK) | |
8368 | return integer_type_node; | |
8369 | ||
8370 | type = DECL_BIT_FIELD_TYPE (decl); | |
71dfc51f | 8371 | if (type == NULL_TREE) |
a3f97cbb JW |
8372 | type = TREE_TYPE (decl); |
8373 | ||
8374 | return type; | |
8375 | } | |
8376 | ||
5f446d21 DD |
8377 | /* Given a pointer to a tree node, return the alignment in bits for |
8378 | it, or else return BITS_PER_WORD if the node actually turns out to | |
8379 | be an ERROR_MARK node. */ | |
71dfc51f RK |
8380 | |
8381 | static inline unsigned | |
a3f97cbb | 8382 | simple_type_align_in_bits (type) |
b3694847 | 8383 | tree type; |
a3f97cbb JW |
8384 | { |
8385 | return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; | |
8386 | } | |
8387 | ||
5f446d21 DD |
8388 | static inline unsigned |
8389 | simple_decl_align_in_bits (decl) | |
b3694847 | 8390 | tree decl; |
5f446d21 DD |
8391 | { |
8392 | return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD; | |
8393 | } | |
8394 | ||
a3f97cbb JW |
8395 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE |
8396 | node, return the size in bits for the type if it is a constant, or else | |
8397 | return the alignment for the type if the type's size is not constant, or | |
8398 | else return BITS_PER_WORD if the type actually turns out to be an | |
8399 | ERROR_MARK node. */ | |
71dfc51f | 8400 | |
665f2503 | 8401 | static inline unsigned HOST_WIDE_INT |
a3f97cbb | 8402 | simple_type_size_in_bits (type) |
b3694847 | 8403 | tree type; |
a3f97cbb | 8404 | { |
3df18884 | 8405 | |
a3f97cbb JW |
8406 | if (TREE_CODE (type) == ERROR_MARK) |
8407 | return BITS_PER_WORD; | |
2ad9852d | 8408 | else if (TYPE_SIZE (type) == NULL_TREE) |
3df18884 | 8409 | return 0; |
2ad9852d RK |
8410 | else if (host_integerp (TYPE_SIZE (type), 1)) |
8411 | return tree_low_cst (TYPE_SIZE (type), 1); | |
8412 | else | |
3df18884 | 8413 | return TYPE_ALIGN (type); |
a3f97cbb JW |
8414 | } |
8415 | ||
2ad9852d RK |
8416 | /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the |
8417 | lowest addressed byte of the "containing object" for the given FIELD_DECL, | |
8418 | or return 0 if we are unable to determine what that offset is, either | |
8419 | because the argument turns out to be a pointer to an ERROR_MARK node, or | |
8420 | because the offset is actually variable. (We can't handle the latter case | |
8421 | just yet). */ | |
71dfc51f | 8422 | |
665f2503 | 8423 | static HOST_WIDE_INT |
a3f97cbb | 8424 | field_byte_offset (decl) |
b3694847 | 8425 | tree decl; |
a3f97cbb | 8426 | { |
665f2503 | 8427 | unsigned int type_align_in_bits; |
5f446d21 | 8428 | unsigned int decl_align_in_bits; |
665f2503 | 8429 | unsigned HOST_WIDE_INT type_size_in_bits; |
665f2503 | 8430 | HOST_WIDE_INT object_offset_in_bits; |
665f2503 RK |
8431 | tree type; |
8432 | tree field_size_tree; | |
8433 | HOST_WIDE_INT bitpos_int; | |
8434 | HOST_WIDE_INT deepest_bitpos; | |
8435 | unsigned HOST_WIDE_INT field_size_in_bits; | |
a3f97cbb JW |
8436 | |
8437 | if (TREE_CODE (decl) == ERROR_MARK) | |
8438 | return 0; | |
2ad9852d | 8439 | else if (TREE_CODE (decl) != FIELD_DECL) |
a3f97cbb JW |
8440 | abort (); |
8441 | ||
8442 | type = field_type (decl); | |
a3f97cbb JW |
8443 | field_size_tree = DECL_SIZE (decl); |
8444 | ||
3df18884 RH |
8445 | /* The size could be unspecified if there was an error, or for |
8446 | a flexible array member. */ | |
50352c9c | 8447 | if (! field_size_tree) |
3df18884 | 8448 | field_size_tree = bitsize_zero_node; |
50352c9c | 8449 | |
556273e0 | 8450 | /* We cannot yet cope with fields whose positions are variable, so |
a3f97cbb JW |
8451 | for now, when we see such things, we simply return 0. Someday, we may |
8452 | be able to handle such cases, but it will be damn difficult. */ | |
665f2503 | 8453 | if (! host_integerp (bit_position (decl), 0)) |
a3f97cbb | 8454 | return 0; |
14a774a9 | 8455 | |
665f2503 | 8456 | bitpos_int = int_bit_position (decl); |
a3f97cbb | 8457 | |
3df18884 | 8458 | /* If we don't know the size of the field, pretend it's a full word. */ |
665f2503 RK |
8459 | if (host_integerp (field_size_tree, 1)) |
8460 | field_size_in_bits = tree_low_cst (field_size_tree, 1); | |
14a774a9 RK |
8461 | else |
8462 | field_size_in_bits = BITS_PER_WORD; | |
a3f97cbb JW |
8463 | |
8464 | type_size_in_bits = simple_type_size_in_bits (type); | |
a3f97cbb | 8465 | type_align_in_bits = simple_type_align_in_bits (type); |
5f446d21 | 8466 | decl_align_in_bits = simple_decl_align_in_bits (decl); |
a3f97cbb | 8467 | |
2ad9852d RK |
8468 | /* The GCC front-end doesn't make any attempt to keep track of the starting |
8469 | bit offset (relative to the start of the containing structure type) of the | |
8470 | hypothetical "containing object" for a bit-field. Thus, when computing | |
8471 | the byte offset value for the start of the "containing object" of a | |
8472 | bit-field, we must deduce this information on our own. This can be rather | |
8473 | tricky to do in some cases. For example, handling the following structure | |
8474 | type definition when compiling for an i386/i486 target (which only aligns | |
8475 | long long's to 32-bit boundaries) can be very tricky: | |
a3f97cbb JW |
8476 | |
8477 | struct S { int field1; long long field2:31; }; | |
8478 | ||
2ad9852d RK |
8479 | Fortunately, there is a simple rule-of-thumb which can be used in such |
8480 | cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the | |
8481 | structure shown above. It decides to do this based upon one simple rule | |
8482 | for bit-field allocation. GCC allocates each "containing object" for each | |
8483 | bit-field at the first (i.e. lowest addressed) legitimate alignment | |
8484 | boundary (based upon the required minimum alignment for the declared type | |
8485 | of the field) which it can possibly use, subject to the condition that | |
8486 | there is still enough available space remaining in the containing object | |
8487 | (when allocated at the selected point) to fully accommodate all of the | |
8488 | bits of the bit-field itself. | |
8489 | ||
8490 | This simple rule makes it obvious why GCC allocates 8 bytes for each | |
8491 | object of the structure type shown above. When looking for a place to | |
8492 | allocate the "containing object" for `field2', the compiler simply tries | |
8493 | to allocate a 64-bit "containing object" at each successive 32-bit | |
8494 | boundary (starting at zero) until it finds a place to allocate that 64- | |
8495 | bit field such that at least 31 contiguous (and previously unallocated) | |
8496 | bits remain within that selected 64 bit field. (As it turns out, for the | |
8497 | example above, the compiler finds it is OK to allocate the "containing | |
8498 | object" 64-bit field at bit-offset zero within the structure type.) | |
8499 | ||
8500 | Here we attempt to work backwards from the limited set of facts we're | |
8501 | given, and we try to deduce from those facts, where GCC must have believed | |
8502 | that the containing object started (within the structure type). The value | |
8503 | we deduce is then used (by the callers of this routine) to generate | |
8504 | DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields | |
8505 | and, in the case of DW_AT_location, regular fields as well). */ | |
a3f97cbb JW |
8506 | |
8507 | /* Figure out the bit-distance from the start of the structure to the | |
8508 | "deepest" bit of the bit-field. */ | |
8509 | deepest_bitpos = bitpos_int + field_size_in_bits; | |
8510 | ||
8511 | /* This is the tricky part. Use some fancy footwork to deduce where the | |
8512 | lowest addressed bit of the containing object must be. */ | |
5f446d21 DD |
8513 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; |
8514 | ||
8515 | /* Round up to type_align by default. This works best for bitfields. */ | |
8516 | object_offset_in_bits += type_align_in_bits - 1; | |
8517 | object_offset_in_bits /= type_align_in_bits; | |
8518 | object_offset_in_bits *= type_align_in_bits; | |
a3f97cbb | 8519 | |
5f446d21 DD |
8520 | if (object_offset_in_bits > bitpos_int) |
8521 | { | |
8522 | /* Sigh, the decl must be packed. */ | |
8523 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; | |
8524 | ||
8525 | /* Round up to decl_align instead. */ | |
8526 | object_offset_in_bits += decl_align_in_bits - 1; | |
8527 | object_offset_in_bits /= decl_align_in_bits; | |
8528 | object_offset_in_bits *= decl_align_in_bits; | |
8529 | } | |
a3f97cbb | 8530 | |
2ad9852d | 8531 | return object_offset_in_bits / BITS_PER_UNIT; |
a3f97cbb | 8532 | } |
a3f97cbb | 8533 | \f |
71dfc51f RK |
8534 | /* The following routines define various Dwarf attributes and any data |
8535 | associated with them. */ | |
a3f97cbb | 8536 | |
ef76d03b | 8537 | /* Add a location description attribute value to a DIE. |
a3f97cbb | 8538 | |
ef76d03b | 8539 | This emits location attributes suitable for whole variables and |
a3f97cbb JW |
8540 | whole parameters. Note that the location attributes for struct fields are |
8541 | generated by the routine `data_member_location_attribute' below. */ | |
71dfc51f | 8542 | |
a3f97cbb | 8543 | static void |
ef76d03b | 8544 | add_AT_location_description (die, attr_kind, rtl) |
a3f97cbb | 8545 | dw_die_ref die; |
ef76d03b | 8546 | enum dwarf_attribute attr_kind; |
b3694847 | 8547 | rtx rtl; |
a3f97cbb | 8548 | { |
e7af1d45 | 8549 | dw_loc_descr_ref descr = loc_descriptor (rtl); |
a3f97cbb | 8550 | |
e7af1d45 RK |
8551 | if (descr != 0) |
8552 | add_AT_loc (die, attr_kind, descr); | |
a3f97cbb JW |
8553 | } |
8554 | ||
2ad9852d RK |
8555 | /* Attach the specialized form of location attribute used for data members of |
8556 | struct and union types. In the special case of a FIELD_DECL node which | |
8557 | represents a bit-field, the "offset" part of this special location | |
8558 | descriptor must indicate the distance in bytes from the lowest-addressed | |
8559 | byte of the containing struct or union type to the lowest-addressed byte of | |
8560 | the "containing object" for the bit-field. (See the `field_byte_offset' | |
8561 | function above). | |
8562 | ||
8563 | For any given bit-field, the "containing object" is a hypothetical object | |
8564 | (of some integral or enum type) within which the given bit-field lives. The | |
8565 | type of this hypothetical "containing object" is always the same as the | |
8566 | declared type of the individual bit-field itself (for GCC anyway... the | |
8567 | DWARF spec doesn't actually mandate this). Note that it is the size (in | |
8568 | bytes) of the hypothetical "containing object" which will be given in the | |
8569 | DW_AT_byte_size attribute for this bit-field. (See the | |
8570 | `byte_size_attribute' function below.) It is also used when calculating the | |
8571 | value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute' | |
8572 | function below.) */ | |
71dfc51f | 8573 | |
a3f97cbb JW |
8574 | static void |
8575 | add_data_member_location_attribute (die, decl) | |
b3694847 SS |
8576 | dw_die_ref die; |
8577 | tree decl; | |
a3f97cbb | 8578 | { |
649ce3f2 JM |
8579 | long offset; |
8580 | dw_loc_descr_ref loc_descr = 0; | |
a3f97cbb | 8581 | |
61b32c02 | 8582 | if (TREE_CODE (decl) == TREE_VEC) |
649ce3f2 JM |
8583 | { |
8584 | /* We're working on the TAG_inheritance for a base class. */ | |
1d3d6b1e | 8585 | if (TREE_VIA_VIRTUAL (decl) && is_cxx ()) |
649ce3f2 JM |
8586 | { |
8587 | /* For C++ virtual bases we can't just use BINFO_OFFSET, as they | |
8588 | aren't at a fixed offset from all (sub)objects of the same | |
8589 | type. We need to extract the appropriate offset from our | |
8590 | vtable. The following dwarf expression means | |
8591 | ||
8592 | BaseAddr = ObAddr + *((*ObAddr) - Offset) | |
8593 | ||
8594 | This is specific to the V3 ABI, of course. */ | |
8595 | ||
8596 | dw_loc_descr_ref tmp; | |
2ad9852d | 8597 | |
649ce3f2 JM |
8598 | /* Make a copy of the object address. */ |
8599 | tmp = new_loc_descr (DW_OP_dup, 0, 0); | |
8600 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 8601 | |
649ce3f2 JM |
8602 | /* Extract the vtable address. */ |
8603 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
8604 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 8605 | |
649ce3f2 JM |
8606 | /* Calculate the address of the offset. */ |
8607 | offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0); | |
8608 | if (offset >= 0) | |
8609 | abort (); | |
2ad9852d | 8610 | |
649ce3f2 JM |
8611 | tmp = int_loc_descriptor (-offset); |
8612 | add_loc_descr (&loc_descr, tmp); | |
8613 | tmp = new_loc_descr (DW_OP_minus, 0, 0); | |
8614 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 8615 | |
649ce3f2 JM |
8616 | /* Extract the offset. */ |
8617 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
8618 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 8619 | |
649ce3f2 JM |
8620 | /* Add it to the object address. */ |
8621 | tmp = new_loc_descr (DW_OP_plus, 0, 0); | |
8622 | add_loc_descr (&loc_descr, tmp); | |
8623 | } | |
8624 | else | |
8625 | offset = tree_low_cst (BINFO_OFFSET (decl), 0); | |
8626 | } | |
61b32c02 JM |
8627 | else |
8628 | offset = field_byte_offset (decl); | |
8629 | ||
649ce3f2 JM |
8630 | if (! loc_descr) |
8631 | { | |
8632 | enum dwarf_location_atom op; | |
8633 | ||
2ad9852d RK |
8634 | /* The DWARF2 standard says that we should assume that the structure |
8635 | address is already on the stack, so we can specify a structure field | |
8636 | address by using DW_OP_plus_uconst. */ | |
71dfc51f | 8637 | |
a3f97cbb | 8638 | #ifdef MIPS_DEBUGGING_INFO |
2ad9852d RK |
8639 | /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst |
8640 | operator correctly. It works only if we leave the offset on the | |
8641 | stack. */ | |
649ce3f2 | 8642 | op = DW_OP_constu; |
a3f97cbb | 8643 | #else |
649ce3f2 | 8644 | op = DW_OP_plus_uconst; |
a3f97cbb | 8645 | #endif |
71dfc51f | 8646 | |
649ce3f2 JM |
8647 | loc_descr = new_loc_descr (op, offset, 0); |
8648 | } | |
2ad9852d | 8649 | |
a3f97cbb JW |
8650 | add_AT_loc (die, DW_AT_data_member_location, loc_descr); |
8651 | } | |
8652 | ||
8653 | /* Attach an DW_AT_const_value attribute for a variable or a parameter which | |
8654 | does not have a "location" either in memory or in a register. These | |
8655 | things can arise in GNU C when a constant is passed as an actual parameter | |
8656 | to an inlined function. They can also arise in C++ where declared | |
8657 | constants do not necessarily get memory "homes". */ | |
71dfc51f | 8658 | |
a3f97cbb JW |
8659 | static void |
8660 | add_const_value_attribute (die, rtl) | |
b3694847 SS |
8661 | dw_die_ref die; |
8662 | rtx rtl; | |
a3f97cbb JW |
8663 | { |
8664 | switch (GET_CODE (rtl)) | |
8665 | { | |
8666 | case CONST_INT: | |
2e4b9b8c RH |
8667 | /* Note that a CONST_INT rtx could represent either an integer |
8668 | or a floating-point constant. A CONST_INT is used whenever | |
8669 | the constant will fit into a single word. In all such | |
8670 | cases, the original mode of the constant value is wiped | |
8671 | out, and the CONST_INT rtx is assigned VOIDmode. */ | |
8672 | { | |
8673 | HOST_WIDE_INT val = INTVAL (rtl); | |
c26fbbca | 8674 | |
2e4b9b8c | 8675 | /* ??? We really should be using HOST_WIDE_INT throughout. */ |
5929a2f0 | 8676 | if (val < 0 && (long) val == val) |
3d7a191f | 8677 | add_AT_int (die, DW_AT_const_value, (long) val); |
5929a2f0 RH |
8678 | else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val) |
8679 | add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val); | |
94784fb9 RK |
8680 | else |
8681 | { | |
e7af1d45 | 8682 | #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT |
94784fb9 RK |
8683 | add_AT_long_long (die, DW_AT_const_value, |
8684 | val >> HOST_BITS_PER_LONG, val); | |
e7af1d45 | 8685 | #else |
94784fb9 | 8686 | abort (); |
e7af1d45 | 8687 | #endif |
94784fb9 | 8688 | } |
2e4b9b8c | 8689 | } |
a3f97cbb JW |
8690 | break; |
8691 | ||
8692 | case CONST_DOUBLE: | |
8693 | /* Note that a CONST_DOUBLE rtx could represent either an integer or a | |
8694 | floating-point constant. A CONST_DOUBLE is used whenever the | |
8695 | constant requires more than one word in order to be adequately | |
469ac993 JM |
8696 | represented. We output CONST_DOUBLEs as blocks. */ |
8697 | { | |
b3694847 | 8698 | enum machine_mode mode = GET_MODE (rtl); |
469ac993 JM |
8699 | |
8700 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
8701 | { | |
b3694847 | 8702 | unsigned length = GET_MODE_SIZE (mode) / 4; |
c26fbbca | 8703 | long *array = (long *) xmalloc (sizeof (long) * length); |
71dfc51f | 8704 | REAL_VALUE_TYPE rv; |
469ac993 | 8705 | |
71dfc51f | 8706 | REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl); |
469ac993 JM |
8707 | switch (mode) |
8708 | { | |
8709 | case SFmode: | |
71dfc51f | 8710 | REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]); |
469ac993 JM |
8711 | break; |
8712 | ||
8713 | case DFmode: | |
71dfc51f | 8714 | REAL_VALUE_TO_TARGET_DOUBLE (rv, array); |
469ac993 JM |
8715 | break; |
8716 | ||
8717 | case XFmode: | |
8718 | case TFmode: | |
71dfc51f | 8719 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array); |
469ac993 JM |
8720 | break; |
8721 | ||
8722 | default: | |
8723 | abort (); | |
8724 | } | |
8725 | ||
469ac993 JM |
8726 | add_AT_float (die, DW_AT_const_value, length, array); |
8727 | } | |
8728 | else | |
2e4b9b8c RH |
8729 | { |
8730 | /* ??? We really should be using HOST_WIDE_INT throughout. */ | |
8731 | if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT) | |
8732 | abort (); | |
2ad9852d | 8733 | |
2e4b9b8c RH |
8734 | add_AT_long_long (die, DW_AT_const_value, |
8735 | CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl)); | |
8736 | } | |
469ac993 | 8737 | } |
a3f97cbb JW |
8738 | break; |
8739 | ||
8740 | case CONST_STRING: | |
8741 | add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0)); | |
8742 | break; | |
8743 | ||
8744 | case SYMBOL_REF: | |
8745 | case LABEL_REF: | |
8746 | case CONST: | |
c470afad RK |
8747 | add_AT_addr (die, DW_AT_const_value, rtl); |
8748 | VARRAY_PUSH_RTX (used_rtx_varray, rtl); | |
a3f97cbb JW |
8749 | break; |
8750 | ||
8751 | case PLUS: | |
8752 | /* In cases where an inlined instance of an inline function is passed | |
8753 | the address of an `auto' variable (which is local to the caller) we | |
8754 | can get a situation where the DECL_RTL of the artificial local | |
8755 | variable (for the inlining) which acts as a stand-in for the | |
8756 | corresponding formal parameter (of the inline function) will look | |
8757 | like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not | |
556273e0 KH |
8758 | exactly a compile-time constant expression, but it isn't the address |
8759 | of the (artificial) local variable either. Rather, it represents the | |
a3f97cbb | 8760 | *value* which the artificial local variable always has during its |
556273e0 | 8761 | lifetime. We currently have no way to represent such quasi-constant |
6a7a9f01 | 8762 | values in Dwarf, so for now we just punt and generate nothing. */ |
a3f97cbb JW |
8763 | break; |
8764 | ||
8765 | default: | |
8766 | /* No other kinds of rtx should be possible here. */ | |
8767 | abort (); | |
8768 | } | |
8769 | ||
8770 | } | |
8771 | ||
d8041cc8 RH |
8772 | static rtx |
8773 | rtl_for_decl_location (decl) | |
8774 | tree decl; | |
a3f97cbb | 8775 | { |
b3694847 | 8776 | rtx rtl; |
71dfc51f | 8777 | |
a3f97cbb JW |
8778 | /* Here we have to decide where we are going to say the parameter "lives" |
8779 | (as far as the debugger is concerned). We only have a couple of | |
8780 | choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. | |
71dfc51f | 8781 | |
556273e0 | 8782 | DECL_RTL normally indicates where the parameter lives during most of the |
71dfc51f | 8783 | activation of the function. If optimization is enabled however, this |
556273e0 | 8784 | could be either NULL or else a pseudo-reg. Both of those cases indicate |
a3f97cbb JW |
8785 | that the parameter doesn't really live anywhere (as far as the code |
8786 | generation parts of GCC are concerned) during most of the function's | |
8787 | activation. That will happen (for example) if the parameter is never | |
71dfc51f RK |
8788 | referenced within the function. |
8789 | ||
8790 | We could just generate a location descriptor here for all non-NULL | |
8791 | non-pseudo values of DECL_RTL and ignore all of the rest, but we can be | |
8792 | a little nicer than that if we also consider DECL_INCOMING_RTL in cases | |
8793 | where DECL_RTL is NULL or is a pseudo-reg. | |
8794 | ||
8795 | Note however that we can only get away with using DECL_INCOMING_RTL as | |
8796 | a backup substitute for DECL_RTL in certain limited cases. In cases | |
8797 | where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl), | |
8798 | we can be sure that the parameter was passed using the same type as it is | |
8799 | declared to have within the function, and that its DECL_INCOMING_RTL | |
8800 | points us to a place where a value of that type is passed. | |
8801 | ||
8802 | In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different, | |
8803 | we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL | |
8804 | because in these cases DECL_INCOMING_RTL points us to a value of some | |
8805 | type which is *different* from the type of the parameter itself. Thus, | |
8806 | if we tried to use DECL_INCOMING_RTL to generate a location attribute in | |
8807 | such cases, the debugger would end up (for example) trying to fetch a | |
8808 | `float' from a place which actually contains the first part of a | |
8809 | `double'. That would lead to really incorrect and confusing | |
8810 | output at debug-time. | |
8811 | ||
8812 | So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL | |
8813 | in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There | |
8814 | are a couple of exceptions however. On little-endian machines we can | |
8815 | get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is | |
8816 | not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is | |
8817 | an integral type that is smaller than TREE_TYPE (decl). These cases arise | |
8818 | when (on a little-endian machine) a non-prototyped function has a | |
8819 | parameter declared to be of type `short' or `char'. In such cases, | |
8820 | TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will | |
8821 | be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the | |
8822 | passed `int' value. If the debugger then uses that address to fetch | |
8823 | a `short' or a `char' (on a little-endian machine) the result will be | |
8824 | the correct data, so we allow for such exceptional cases below. | |
8825 | ||
8826 | Note that our goal here is to describe the place where the given formal | |
2ad9852d RK |
8827 | parameter lives during most of the function's activation (i.e. between the |
8828 | end of the prologue and the start of the epilogue). We'll do that as best | |
8829 | as we can. Note however that if the given formal parameter is modified | |
8830 | sometime during the execution of the function, then a stack backtrace (at | |
8831 | debug-time) will show the function as having been called with the *new* | |
8832 | value rather than the value which was originally passed in. This happens | |
8833 | rarely enough that it is not a major problem, but it *is* a problem, and | |
8834 | I'd like to fix it. | |
8835 | ||
8836 | A future version of dwarf2out.c may generate two additional attributes for | |
8837 | any given DW_TAG_formal_parameter DIE which will describe the "passed | |
8838 | type" and the "passed location" for the given formal parameter in addition | |
8839 | to the attributes we now generate to indicate the "declared type" and the | |
8840 | "active location" for each parameter. This additional set of attributes | |
8841 | could be used by debuggers for stack backtraces. Separately, note that | |
8842 | sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also. | |
8843 | This happens (for example) for inlined-instances of inline function formal | |
8844 | parameters which are never referenced. This really shouldn't be | |
8845 | happening. All PARM_DECL nodes should get valid non-NULL | |
8846 | DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these | |
8847 | values for inlined instances of inline function parameters, so when we see | |
8848 | such cases, we are just out-of-luck for the time being (until integrate.c | |
a3f97cbb JW |
8849 | gets fixed). */ |
8850 | ||
8851 | /* Use DECL_RTL as the "location" unless we find something better. */ | |
110c3568 | 8852 | rtl = DECL_RTL_IF_SET (decl); |
a3f97cbb | 8853 | |
c28abdf0 RH |
8854 | /* When generating abstract instances, ignore everything except |
8855 | constants and symbols living in memory. */ | |
8856 | if (! reload_completed) | |
8857 | { | |
8858 | if (rtl | |
8859 | && (CONSTANT_P (rtl) | |
8860 | || (GET_CODE (rtl) == MEM | |
8861 | && CONSTANT_P (XEXP (rtl, 0))))) | |
4c8c0dec JJ |
8862 | { |
8863 | #ifdef ASM_SIMPLIFY_DWARF_ADDR | |
8864 | rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); | |
8865 | #endif | |
8866 | return rtl; | |
8867 | } | |
c28abdf0 RH |
8868 | rtl = NULL_RTX; |
8869 | } | |
8870 | else if (TREE_CODE (decl) == PARM_DECL) | |
a3f97cbb JW |
8871 | { |
8872 | if (rtl == NULL_RTX || is_pseudo_reg (rtl)) | |
8873 | { | |
d8041cc8 RH |
8874 | tree declared_type = type_main_variant (TREE_TYPE (decl)); |
8875 | tree passed_type = type_main_variant (DECL_ARG_TYPE (decl)); | |
a3f97cbb | 8876 | |
71dfc51f | 8877 | /* This decl represents a formal parameter which was optimized out. |
a3f97cbb | 8878 | Note that DECL_INCOMING_RTL may be NULL in here, but we handle |
2ad9852d | 8879 | all cases where (rtl == NULL_RTX) just below. */ |
a3f97cbb | 8880 | if (declared_type == passed_type) |
71dfc51f RK |
8881 | rtl = DECL_INCOMING_RTL (decl); |
8882 | else if (! BYTES_BIG_ENDIAN | |
8883 | && TREE_CODE (declared_type) == INTEGER_TYPE | |
555b6442 HPN |
8884 | && (GET_MODE_SIZE (TYPE_MODE (declared_type)) |
8885 | <= GET_MODE_SIZE (TYPE_MODE (passed_type)))) | |
556273e0 | 8886 | rtl = DECL_INCOMING_RTL (decl); |
a3f97cbb | 8887 | } |
5a904a61 JW |
8888 | |
8889 | /* If the parm was passed in registers, but lives on the stack, then | |
8890 | make a big endian correction if the mode of the type of the | |
8891 | parameter is not the same as the mode of the rtl. */ | |
8892 | /* ??? This is the same series of checks that are made in dbxout.c before | |
8893 | we reach the big endian correction code there. It isn't clear if all | |
8894 | of these checks are necessary here, but keeping them all is the safe | |
8895 | thing to do. */ | |
8896 | else if (GET_CODE (rtl) == MEM | |
8897 | && XEXP (rtl, 0) != const0_rtx | |
8898 | && ! CONSTANT_P (XEXP (rtl, 0)) | |
8899 | /* Not passed in memory. */ | |
8900 | && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM | |
8901 | /* Not passed by invisible reference. */ | |
8902 | && (GET_CODE (XEXP (rtl, 0)) != REG | |
8903 | || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM | |
8904 | || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM | |
8905 | #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM | |
8906 | || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM | |
8907 | #endif | |
8908 | ) | |
8909 | /* Big endian correction check. */ | |
8910 | && BYTES_BIG_ENDIAN | |
8911 | && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl) | |
8912 | && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))) | |
8913 | < UNITS_PER_WORD)) | |
8914 | { | |
8915 | int offset = (UNITS_PER_WORD | |
8916 | - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))); | |
2ad9852d | 8917 | |
5a904a61 JW |
8918 | rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)), |
8919 | plus_constant (XEXP (rtl, 0), offset)); | |
8920 | } | |
a3f97cbb | 8921 | } |
71dfc51f | 8922 | |
d8041cc8 RH |
8923 | if (rtl != NULL_RTX) |
8924 | { | |
8925 | rtl = eliminate_regs (rtl, 0, NULL_RTX); | |
6a7a9f01 | 8926 | #ifdef LEAF_REG_REMAP |
d8041cc8 RH |
8927 | if (current_function_uses_only_leaf_regs) |
8928 | leaf_renumber_regs_insn (rtl); | |
6a7a9f01 | 8929 | #endif |
d8041cc8 RH |
8930 | } |
8931 | ||
2ad9852d RK |
8932 | /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant, |
8933 | and will have been substituted directly into all expressions that use it. | |
8934 | C does not have such a concept, but C++ and other languages do. */ | |
c28abdf0 | 8935 | else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl)) |
6d73371a JJ |
8936 | { |
8937 | /* If a variable is initialized with a string constant without embedded | |
8938 | zeros, build CONST_STRING. */ | |
8939 | if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST | |
8940 | && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) | |
8941 | { | |
8942 | tree arrtype = TREE_TYPE (decl); | |
8943 | tree enttype = TREE_TYPE (arrtype); | |
8944 | tree domain = TYPE_DOMAIN (arrtype); | |
8945 | tree init = DECL_INITIAL (decl); | |
8946 | enum machine_mode mode = TYPE_MODE (enttype); | |
8947 | ||
8948 | if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1 | |
8949 | && domain | |
8950 | && integer_zerop (TYPE_MIN_VALUE (domain)) | |
8951 | && compare_tree_int (TYPE_MAX_VALUE (domain), | |
8952 | TREE_STRING_LENGTH (init) - 1) == 0 | |
8953 | && ((size_t) TREE_STRING_LENGTH (init) | |
8954 | == strlen (TREE_STRING_POINTER (init)) + 1)) | |
8955 | rtl = gen_rtx_CONST_STRING (VOIDmode, TREE_STRING_POINTER (init)); | |
8956 | } | |
29b91443 JM |
8957 | /* If the initializer is something that we know will expand into an |
8958 | immediate RTL constant, expand it now. Expanding anything else | |
8959 | tends to produce unresolved symbols; see debug/5770 and c++/6381. */ | |
8960 | else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST | |
8961 | || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST) | |
6d73371a JJ |
8962 | { |
8963 | rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode, | |
8964 | EXPAND_INITIALIZER); | |
29b91443 | 8965 | /* If expand_expr returns a MEM, it wasn't immediate. */ |
6d73371a | 8966 | if (rtl && GET_CODE (rtl) == MEM) |
29b91443 | 8967 | abort (); |
6d73371a JJ |
8968 | } |
8969 | } | |
8063ddcf | 8970 | |
4c8c0dec JJ |
8971 | #ifdef ASM_SIMPLIFY_DWARF_ADDR |
8972 | if (rtl) | |
8973 | rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); | |
8974 | #endif | |
d8041cc8 RH |
8975 | return rtl; |
8976 | } | |
8977 | ||
8978 | /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value | |
8979 | data attribute for a variable or a parameter. We generate the | |
8980 | DW_AT_const_value attribute only in those cases where the given variable | |
8981 | or parameter does not have a true "location" either in memory or in a | |
8982 | register. This can happen (for example) when a constant is passed as an | |
8983 | actual argument in a call to an inline function. (It's possible that | |
8984 | these things can crop up in other ways also.) Note that one type of | |
8985 | constant value which can be passed into an inlined function is a constant | |
8986 | pointer. This can happen for example if an actual argument in an inlined | |
8987 | function call evaluates to a compile-time constant address. */ | |
8988 | ||
8989 | static void | |
8990 | add_location_or_const_value_attribute (die, decl) | |
b3694847 SS |
8991 | dw_die_ref die; |
8992 | tree decl; | |
d8041cc8 | 8993 | { |
b3694847 | 8994 | rtx rtl; |
d8041cc8 RH |
8995 | |
8996 | if (TREE_CODE (decl) == ERROR_MARK) | |
8997 | return; | |
2ad9852d | 8998 | else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL) |
d8041cc8 RH |
8999 | abort (); |
9000 | ||
9001 | rtl = rtl_for_decl_location (decl); | |
a97c9600 RH |
9002 | if (rtl == NULL_RTX) |
9003 | return; | |
6a7a9f01 | 9004 | |
732910b9 RH |
9005 | /* If we don't look past the constant pool, we risk emitting a |
9006 | reference to a constant pool entry that isn't referenced from | |
9007 | code, and thus is not emitted. */ | |
9008 | rtl = avoid_constant_pool_reference (rtl); | |
9009 | ||
a3f97cbb JW |
9010 | switch (GET_CODE (rtl)) |
9011 | { | |
e9a25f70 JL |
9012 | case ADDRESSOF: |
9013 | /* The address of a variable that was optimized away; don't emit | |
9014 | anything. */ | |
9015 | break; | |
9016 | ||
a3f97cbb JW |
9017 | case CONST_INT: |
9018 | case CONST_DOUBLE: | |
9019 | case CONST_STRING: | |
9020 | case SYMBOL_REF: | |
9021 | case LABEL_REF: | |
9022 | case CONST: | |
9023 | case PLUS: | |
9024 | /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ | |
9025 | add_const_value_attribute (die, rtl); | |
9026 | break; | |
9027 | ||
9028 | case MEM: | |
9029 | case REG: | |
9030 | case SUBREG: | |
4401bf24 | 9031 | case CONCAT: |
ef76d03b | 9032 | add_AT_location_description (die, DW_AT_location, rtl); |
a3f97cbb JW |
9033 | break; |
9034 | ||
9035 | default: | |
71dfc51f | 9036 | abort (); |
a3f97cbb JW |
9037 | } |
9038 | } | |
9039 | ||
1bfb5f8f JM |
9040 | /* If we don't have a copy of this variable in memory for some reason (such |
9041 | as a C++ member constant that doesn't have an out-of-line definition), | |
9042 | we should tell the debugger about the constant value. */ | |
9043 | ||
9044 | static void | |
9045 | tree_add_const_value_attribute (var_die, decl) | |
9046 | dw_die_ref var_die; | |
9047 | tree decl; | |
9048 | { | |
9049 | tree init = DECL_INITIAL (decl); | |
9050 | tree type = TREE_TYPE (decl); | |
9051 | ||
9052 | if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init | |
9053 | && initializer_constant_valid_p (init, type) == null_pointer_node) | |
9054 | /* OK */; | |
9055 | else | |
9056 | return; | |
9057 | ||
9058 | switch (TREE_CODE (type)) | |
9059 | { | |
9060 | case INTEGER_TYPE: | |
9061 | if (host_integerp (init, 0)) | |
9062 | add_AT_unsigned (var_die, DW_AT_const_value, | |
2ad9852d | 9063 | tree_low_cst (init, 0)); |
1bfb5f8f JM |
9064 | else |
9065 | add_AT_long_long (var_die, DW_AT_const_value, | |
9066 | TREE_INT_CST_HIGH (init), | |
9067 | TREE_INT_CST_LOW (init)); | |
9068 | break; | |
9069 | ||
9070 | default:; | |
9071 | } | |
9072 | } | |
0b34cf1e | 9073 | |
a3f97cbb JW |
9074 | /* Generate an DW_AT_name attribute given some string value to be included as |
9075 | the value of the attribute. */ | |
71dfc51f RK |
9076 | |
9077 | static inline void | |
a3f97cbb | 9078 | add_name_attribute (die, name_string) |
b3694847 SS |
9079 | dw_die_ref die; |
9080 | const char *name_string; | |
a3f97cbb | 9081 | { |
71dfc51f | 9082 | if (name_string != NULL && *name_string != 0) |
14a774a9 RK |
9083 | { |
9084 | if (demangle_name_func) | |
9085 | name_string = (*demangle_name_func) (name_string); | |
9086 | ||
9087 | add_AT_string (die, DW_AT_name, name_string); | |
9088 | } | |
a3f97cbb JW |
9089 | } |
9090 | ||
9091 | /* Given a tree node describing an array bound (either lower or upper) output | |
466446b0 | 9092 | a representation for that bound. */ |
71dfc51f | 9093 | |
a3f97cbb JW |
9094 | static void |
9095 | add_bound_info (subrange_die, bound_attr, bound) | |
b3694847 SS |
9096 | dw_die_ref subrange_die; |
9097 | enum dwarf_attribute bound_attr; | |
9098 | tree bound; | |
a3f97cbb | 9099 | { |
a3f97cbb JW |
9100 | switch (TREE_CODE (bound)) |
9101 | { | |
9102 | case ERROR_MARK: | |
9103 | return; | |
9104 | ||
3ef42a0c | 9105 | /* All fixed-bounds are represented by INTEGER_CST nodes. */ |
a3f97cbb | 9106 | case INTEGER_CST: |
665f2503 RK |
9107 | if (! host_integerp (bound, 0) |
9108 | || (bound_attr == DW_AT_lower_bound | |
28985b81 | 9109 | && (((is_c_family () || is_java ()) && integer_zerop (bound)) |
665f2503 RK |
9110 | || (is_fortran () && integer_onep (bound))))) |
9111 | /* use the default */ | |
9112 | ; | |
141719a8 | 9113 | else |
665f2503 | 9114 | add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0)); |
a3f97cbb JW |
9115 | break; |
9116 | ||
b1ccbc24 | 9117 | case CONVERT_EXPR: |
a3f97cbb | 9118 | case NOP_EXPR: |
b1ccbc24 | 9119 | case NON_LVALUE_EXPR: |
ed239f5a | 9120 | case VIEW_CONVERT_EXPR: |
b1ccbc24 RK |
9121 | add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0)); |
9122 | break; | |
556273e0 | 9123 | |
a3f97cbb JW |
9124 | case SAVE_EXPR: |
9125 | /* If optimization is turned on, the SAVE_EXPRs that describe how to | |
466446b0 JM |
9126 | access the upper bound values may be bogus. If they refer to a |
9127 | register, they may only describe how to get at these values at the | |
9128 | points in the generated code right after they have just been | |
9129 | computed. Worse yet, in the typical case, the upper bound values | |
9130 | will not even *be* computed in the optimized code (though the | |
9131 | number of elements will), so these SAVE_EXPRs are entirely | |
9132 | bogus. In order to compensate for this fact, we check here to see | |
9133 | if optimization is enabled, and if so, we don't add an attribute | |
9134 | for the (unknown and unknowable) upper bound. This should not | |
9135 | cause too much trouble for existing (stupid?) debuggers because | |
9136 | they have to deal with empty upper bounds location descriptions | |
9137 | anyway in order to be able to deal with incomplete array types. | |
9138 | Of course an intelligent debugger (GDB?) should be able to | |
4fe9b91c | 9139 | comprehend that a missing upper bound specification in an array |
466446b0 JM |
9140 | type used for a storage class `auto' local array variable |
9141 | indicates that the upper bound is both unknown (at compile- time) | |
9142 | and unknowable (at run-time) due to optimization. | |
9143 | ||
9144 | We assume that a MEM rtx is safe because gcc wouldn't put the | |
9145 | value there unless it was going to be used repeatedly in the | |
9146 | function, i.e. for cleanups. */ | |
1edf43d6 JM |
9147 | if (SAVE_EXPR_RTL (bound) |
9148 | && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)) | |
a3f97cbb | 9149 | { |
b3694847 | 9150 | dw_die_ref ctx = lookup_decl_die (current_function_decl); |
54ba1f0d | 9151 | dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound); |
b3694847 | 9152 | rtx loc = SAVE_EXPR_RTL (bound); |
f5963e61 JL |
9153 | |
9154 | /* If the RTL for the SAVE_EXPR is memory, handle the case where | |
9155 | it references an outer function's frame. */ | |
f5963e61 JL |
9156 | if (GET_CODE (loc) == MEM) |
9157 | { | |
9158 | rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound); | |
9159 | ||
9160 | if (XEXP (loc, 0) != new_addr) | |
c5c76735 | 9161 | loc = gen_rtx_MEM (GET_MODE (loc), new_addr); |
f5963e61 JL |
9162 | } |
9163 | ||
466446b0 JM |
9164 | add_AT_flag (decl_die, DW_AT_artificial, 1); |
9165 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
f5963e61 | 9166 | add_AT_location_description (decl_die, DW_AT_location, loc); |
466446b0 | 9167 | add_AT_die_ref (subrange_die, bound_attr, decl_die); |
a3f97cbb | 9168 | } |
71dfc51f RK |
9169 | |
9170 | /* Else leave out the attribute. */ | |
a3f97cbb | 9171 | break; |
3f76745e | 9172 | |
ef76d03b | 9173 | case VAR_DECL: |
d8041cc8 RH |
9174 | case PARM_DECL: |
9175 | { | |
9176 | dw_die_ref decl_die = lookup_decl_die (bound); | |
9177 | ||
9178 | /* ??? Can this happen, or should the variable have been bound | |
9179 | first? Probably it can, since I imagine that we try to create | |
9180 | the types of parameters in the order in which they exist in | |
0b34cf1e | 9181 | the list, and won't have created a forward reference to a |
d8041cc8 RH |
9182 | later parameter. */ |
9183 | if (decl_die != NULL) | |
9184 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
9185 | break; | |
9186 | } | |
ef76d03b | 9187 | |
3f76745e | 9188 | default: |
d8041cc8 RH |
9189 | { |
9190 | /* Otherwise try to create a stack operation procedure to | |
9191 | evaluate the value of the array bound. */ | |
9192 | ||
9193 | dw_die_ref ctx, decl_die; | |
9194 | dw_loc_descr_ref loc; | |
9195 | ||
9196 | loc = loc_descriptor_from_tree (bound, 0); | |
9197 | if (loc == NULL) | |
9198 | break; | |
9199 | ||
e7af1d45 RK |
9200 | if (current_function_decl == 0) |
9201 | ctx = comp_unit_die; | |
9202 | else | |
9203 | ctx = lookup_decl_die (current_function_decl); | |
d8041cc8 | 9204 | |
aea9695c RK |
9205 | /* If we weren't able to find a context, it's most likely the case |
9206 | that we are processing the return type of the function. So | |
9207 | make a SAVE_EXPR to point to it and have the limbo DIE code | |
9208 | find the proper die. The save_expr function doesn't always | |
9209 | make a SAVE_EXPR, so do it ourselves. */ | |
9210 | if (ctx == 0) | |
9211 | bound = build (SAVE_EXPR, TREE_TYPE (bound), bound, | |
9212 | current_function_decl, NULL_TREE); | |
9213 | ||
54ba1f0d | 9214 | decl_die = new_die (DW_TAG_variable, ctx, bound); |
d8041cc8 RH |
9215 | add_AT_flag (decl_die, DW_AT_artificial, 1); |
9216 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
9217 | add_AT_loc (decl_die, DW_AT_location, loc); | |
9218 | ||
9219 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
9220 | break; | |
9221 | } | |
a3f97cbb JW |
9222 | } |
9223 | } | |
9224 | ||
9225 | /* Note that the block of subscript information for an array type also | |
9226 | includes information about the element type of type given array type. */ | |
71dfc51f | 9227 | |
a3f97cbb JW |
9228 | static void |
9229 | add_subscript_info (type_die, type) | |
b3694847 SS |
9230 | dw_die_ref type_die; |
9231 | tree type; | |
a3f97cbb | 9232 | { |
081f5e7e | 9233 | #ifndef MIPS_DEBUGGING_INFO |
b3694847 | 9234 | unsigned dimension_number; |
081f5e7e | 9235 | #endif |
b3694847 SS |
9236 | tree lower, upper; |
9237 | dw_die_ref subrange_die; | |
a3f97cbb | 9238 | |
556273e0 | 9239 | /* The GNU compilers represent multidimensional array types as sequences of |
a3f97cbb JW |
9240 | one dimensional array types whose element types are themselves array |
9241 | types. Here we squish that down, so that each multidimensional array | |
556273e0 | 9242 | type gets only one array_type DIE in the Dwarf debugging info. The draft |
a3f97cbb JW |
9243 | Dwarf specification say that we are allowed to do this kind of |
9244 | compression in C (because there is no difference between an array or | |
556273e0 | 9245 | arrays and a multidimensional array in C) but for other source languages |
a3f97cbb | 9246 | (e.g. Ada) we probably shouldn't do this. */ |
71dfc51f | 9247 | |
a3f97cbb JW |
9248 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
9249 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
9250 | We work around this by disabling this feature. See also | |
9251 | gen_array_type_die. */ | |
9252 | #ifndef MIPS_DEBUGGING_INFO | |
9253 | for (dimension_number = 0; | |
9254 | TREE_CODE (type) == ARRAY_TYPE; | |
9255 | type = TREE_TYPE (type), dimension_number++) | |
a3f97cbb | 9256 | #endif |
2ad9852d | 9257 | { |
b3694847 | 9258 | tree domain = TYPE_DOMAIN (type); |
a3f97cbb JW |
9259 | |
9260 | /* Arrays come in three flavors: Unspecified bounds, fixed bounds, | |
556273e0 | 9261 | and (in GNU C only) variable bounds. Handle all three forms |
a3f97cbb | 9262 | here. */ |
54ba1f0d | 9263 | subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL); |
a3f97cbb JW |
9264 | if (domain) |
9265 | { | |
9266 | /* We have an array type with specified bounds. */ | |
9267 | lower = TYPE_MIN_VALUE (domain); | |
9268 | upper = TYPE_MAX_VALUE (domain); | |
9269 | ||
a9d38797 JM |
9270 | /* define the index type. */ |
9271 | if (TREE_TYPE (domain)) | |
ef76d03b JW |
9272 | { |
9273 | /* ??? This is probably an Ada unnamed subrange type. Ignore the | |
9274 | TREE_TYPE field. We can't emit debug info for this | |
9275 | because it is an unnamed integral type. */ | |
9276 | if (TREE_CODE (domain) == INTEGER_TYPE | |
9277 | && TYPE_NAME (domain) == NULL_TREE | |
9278 | && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE | |
9279 | && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE) | |
556273e0 | 9280 | ; |
ef76d03b JW |
9281 | else |
9282 | add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0, | |
9283 | type_die); | |
9284 | } | |
a9d38797 | 9285 | |
e1ee5cdc RH |
9286 | /* ??? If upper is NULL, the array has unspecified length, |
9287 | but it does have a lower bound. This happens with Fortran | |
9288 | dimension arr(N:*) | |
9289 | Since the debugger is definitely going to need to know N | |
9290 | to produce useful results, go ahead and output the lower | |
9291 | bound solo, and hope the debugger can cope. */ | |
9292 | ||
141719a8 | 9293 | add_bound_info (subrange_die, DW_AT_lower_bound, lower); |
e1ee5cdc RH |
9294 | if (upper) |
9295 | add_bound_info (subrange_die, DW_AT_upper_bound, upper); | |
a3f97cbb | 9296 | } |
71dfc51f | 9297 | |
2ad9852d RK |
9298 | /* Otherwise we have an array type with an unspecified length. The |
9299 | DWARF-2 spec does not say how to handle this; let's just leave out the | |
9300 | bounds. */ | |
a3f97cbb | 9301 | } |
a3f97cbb JW |
9302 | } |
9303 | ||
9304 | static void | |
9305 | add_byte_size_attribute (die, tree_node) | |
9306 | dw_die_ref die; | |
b3694847 | 9307 | tree tree_node; |
a3f97cbb | 9308 | { |
b3694847 | 9309 | unsigned size; |
a3f97cbb JW |
9310 | |
9311 | switch (TREE_CODE (tree_node)) | |
9312 | { | |
9313 | case ERROR_MARK: | |
9314 | size = 0; | |
9315 | break; | |
9316 | case ENUMERAL_TYPE: | |
9317 | case RECORD_TYPE: | |
9318 | case UNION_TYPE: | |
9319 | case QUAL_UNION_TYPE: | |
9320 | size = int_size_in_bytes (tree_node); | |
9321 | break; | |
9322 | case FIELD_DECL: | |
9323 | /* For a data member of a struct or union, the DW_AT_byte_size is | |
9324 | generally given as the number of bytes normally allocated for an | |
9325 | object of the *declared* type of the member itself. This is true | |
9326 | even for bit-fields. */ | |
9327 | size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT; | |
9328 | break; | |
9329 | default: | |
9330 | abort (); | |
9331 | } | |
9332 | ||
9333 | /* Note that `size' might be -1 when we get to this point. If it is, that | |
9334 | indicates that the byte size of the entity in question is variable. We | |
9335 | have no good way of expressing this fact in Dwarf at the present time, | |
9336 | so just let the -1 pass on through. */ | |
a3f97cbb JW |
9337 | add_AT_unsigned (die, DW_AT_byte_size, size); |
9338 | } | |
9339 | ||
9340 | /* For a FIELD_DECL node which represents a bit-field, output an attribute | |
9341 | which specifies the distance in bits from the highest order bit of the | |
9342 | "containing object" for the bit-field to the highest order bit of the | |
9343 | bit-field itself. | |
9344 | ||
2ad9852d RK |
9345 | For any given bit-field, the "containing object" is a hypothetical object |
9346 | (of some integral or enum type) within which the given bit-field lives. The | |
9347 | type of this hypothetical "containing object" is always the same as the | |
9348 | declared type of the individual bit-field itself. The determination of the | |
9349 | exact location of the "containing object" for a bit-field is rather | |
9350 | complicated. It's handled by the `field_byte_offset' function (above). | |
a3f97cbb JW |
9351 | |
9352 | Note that it is the size (in bytes) of the hypothetical "containing object" | |
9353 | which will be given in the DW_AT_byte_size attribute for this bit-field. | |
9354 | (See `byte_size_attribute' above). */ | |
71dfc51f RK |
9355 | |
9356 | static inline void | |
a3f97cbb | 9357 | add_bit_offset_attribute (die, decl) |
b3694847 SS |
9358 | dw_die_ref die; |
9359 | tree decl; | |
a3f97cbb | 9360 | { |
665f2503 RK |
9361 | HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl); |
9362 | tree type = DECL_BIT_FIELD_TYPE (decl); | |
9363 | HOST_WIDE_INT bitpos_int; | |
9364 | HOST_WIDE_INT highest_order_object_bit_offset; | |
9365 | HOST_WIDE_INT highest_order_field_bit_offset; | |
9366 | HOST_WIDE_INT unsigned bit_offset; | |
a3f97cbb | 9367 | |
3a88cbd1 JL |
9368 | /* Must be a field and a bit field. */ |
9369 | if (!type | |
9370 | || TREE_CODE (decl) != FIELD_DECL) | |
9371 | abort (); | |
a3f97cbb JW |
9372 | |
9373 | /* We can't yet handle bit-fields whose offsets are variable, so if we | |
9374 | encounter such things, just return without generating any attribute | |
665f2503 RK |
9375 | whatsoever. Likewise for variable or too large size. */ |
9376 | if (! host_integerp (bit_position (decl), 0) | |
9377 | || ! host_integerp (DECL_SIZE (decl), 1)) | |
71dfc51f RK |
9378 | return; |
9379 | ||
665f2503 | 9380 | bitpos_int = int_bit_position (decl); |
a3f97cbb JW |
9381 | |
9382 | /* Note that the bit offset is always the distance (in bits) from the | |
556273e0 KH |
9383 | highest-order bit of the "containing object" to the highest-order bit of |
9384 | the bit-field itself. Since the "high-order end" of any object or field | |
a3f97cbb JW |
9385 | is different on big-endian and little-endian machines, the computation |
9386 | below must take account of these differences. */ | |
9387 | highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; | |
9388 | highest_order_field_bit_offset = bitpos_int; | |
9389 | ||
71dfc51f | 9390 | if (! BYTES_BIG_ENDIAN) |
a3f97cbb | 9391 | { |
665f2503 | 9392 | highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0); |
a3f97cbb JW |
9393 | highest_order_object_bit_offset += simple_type_size_in_bits (type); |
9394 | } | |
71dfc51f RK |
9395 | |
9396 | bit_offset | |
9397 | = (! BYTES_BIG_ENDIAN | |
9398 | ? highest_order_object_bit_offset - highest_order_field_bit_offset | |
9399 | : highest_order_field_bit_offset - highest_order_object_bit_offset); | |
a3f97cbb JW |
9400 | |
9401 | add_AT_unsigned (die, DW_AT_bit_offset, bit_offset); | |
9402 | } | |
9403 | ||
9404 | /* For a FIELD_DECL node which represents a bit field, output an attribute | |
9405 | which specifies the length in bits of the given field. */ | |
71dfc51f RK |
9406 | |
9407 | static inline void | |
a3f97cbb | 9408 | add_bit_size_attribute (die, decl) |
b3694847 SS |
9409 | dw_die_ref die; |
9410 | tree decl; | |
a3f97cbb | 9411 | { |
3a88cbd1 JL |
9412 | /* Must be a field and a bit field. */ |
9413 | if (TREE_CODE (decl) != FIELD_DECL | |
9414 | || ! DECL_BIT_FIELD_TYPE (decl)) | |
9415 | abort (); | |
665f2503 RK |
9416 | |
9417 | if (host_integerp (DECL_SIZE (decl), 1)) | |
9418 | add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1)); | |
a3f97cbb JW |
9419 | } |
9420 | ||
88dad228 | 9421 | /* If the compiled language is ANSI C, then add a 'prototyped' |
a3f97cbb | 9422 | attribute, if arg types are given for the parameters of a function. */ |
71dfc51f RK |
9423 | |
9424 | static inline void | |
a3f97cbb | 9425 | add_prototyped_attribute (die, func_type) |
b3694847 SS |
9426 | dw_die_ref die; |
9427 | tree func_type; | |
a3f97cbb | 9428 | { |
88dad228 JM |
9429 | if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89 |
9430 | && TYPE_ARG_TYPES (func_type) != NULL) | |
9431 | add_AT_flag (die, DW_AT_prototyped, 1); | |
a3f97cbb JW |
9432 | } |
9433 | ||
a3f97cbb JW |
9434 | /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found |
9435 | by looking in either the type declaration or object declaration | |
9436 | equate table. */ | |
71dfc51f RK |
9437 | |
9438 | static inline void | |
a3f97cbb | 9439 | add_abstract_origin_attribute (die, origin) |
b3694847 SS |
9440 | dw_die_ref die; |
9441 | tree origin; | |
a3f97cbb JW |
9442 | { |
9443 | dw_die_ref origin_die = NULL; | |
bbc6ae08 | 9444 | |
d10b8e05 | 9445 | if (TREE_CODE (origin) != FUNCTION_DECL) |
e40a1c67 JM |
9446 | { |
9447 | /* We may have gotten separated from the block for the inlined | |
9448 | function, if we're in an exception handler or some such; make | |
9449 | sure that the abstract function has been written out. | |
9450 | ||
9451 | Doing this for nested functions is wrong, however; functions are | |
9452 | distinct units, and our context might not even be inline. */ | |
fb13d4d0 | 9453 | tree fn = origin; |
2ad9852d | 9454 | |
fb13d4d0 JM |
9455 | if (TYPE_P (fn)) |
9456 | fn = TYPE_STUB_DECL (fn); | |
2ad9852d | 9457 | |
fb13d4d0 | 9458 | fn = decl_function_context (fn); |
e40a1c67 | 9459 | if (fn) |
1edf43d6 | 9460 | dwarf2out_abstract_function (fn); |
e40a1c67 | 9461 | } |
44db1d9c | 9462 | |
2f939d94 | 9463 | if (DECL_P (origin)) |
71dfc51f | 9464 | origin_die = lookup_decl_die (origin); |
2f939d94 | 9465 | else if (TYPE_P (origin)) |
71dfc51f RK |
9466 | origin_die = lookup_type_die (origin); |
9467 | ||
bbc6ae08 | 9468 | if (origin_die == NULL) |
1ae8994f | 9469 | abort (); |
556273e0 | 9470 | |
a3f97cbb JW |
9471 | add_AT_die_ref (die, DW_AT_abstract_origin, origin_die); |
9472 | } | |
9473 | ||
bdb669cb JM |
9474 | /* We do not currently support the pure_virtual attribute. */ |
9475 | ||
71dfc51f | 9476 | static inline void |
a3f97cbb | 9477 | add_pure_or_virtual_attribute (die, func_decl) |
b3694847 SS |
9478 | dw_die_ref die; |
9479 | tree func_decl; | |
a3f97cbb | 9480 | { |
a94dbf2c | 9481 | if (DECL_VINDEX (func_decl)) |
a3f97cbb | 9482 | { |
bdb669cb | 9483 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); |
665f2503 RK |
9484 | |
9485 | if (host_integerp (DECL_VINDEX (func_decl), 0)) | |
9486 | add_AT_loc (die, DW_AT_vtable_elem_location, | |
9487 | new_loc_descr (DW_OP_constu, | |
9488 | tree_low_cst (DECL_VINDEX (func_decl), 0), | |
9489 | 0)); | |
71dfc51f | 9490 | |
a94dbf2c JM |
9491 | /* GNU extension: Record what type this method came from originally. */ |
9492 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
9493 | add_AT_die_ref (die, DW_AT_containing_type, | |
9494 | lookup_type_die (DECL_CONTEXT (func_decl))); | |
a3f97cbb JW |
9495 | } |
9496 | } | |
9497 | \f | |
b2932ae5 | 9498 | /* Add source coordinate attributes for the given decl. */ |
71dfc51f | 9499 | |
b2932ae5 JM |
9500 | static void |
9501 | add_src_coords_attributes (die, decl) | |
b3694847 SS |
9502 | dw_die_ref die; |
9503 | tree decl; | |
b2932ae5 | 9504 | { |
b3694847 | 9505 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
71dfc51f | 9506 | |
b2932ae5 JM |
9507 | add_AT_unsigned (die, DW_AT_decl_file, file_index); |
9508 | add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
9509 | } | |
9510 | ||
a3f97cbb JW |
9511 | /* Add an DW_AT_name attribute and source coordinate attribute for the |
9512 | given decl, but only if it actually has a name. */ | |
71dfc51f | 9513 | |
a3f97cbb JW |
9514 | static void |
9515 | add_name_and_src_coords_attributes (die, decl) | |
b3694847 SS |
9516 | dw_die_ref die; |
9517 | tree decl; | |
a3f97cbb | 9518 | { |
b3694847 | 9519 | tree decl_name; |
71dfc51f | 9520 | |
556273e0 | 9521 | decl_name = DECL_NAME (decl); |
71dfc51f | 9522 | if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL) |
a3f97cbb | 9523 | { |
a1d7ffe3 | 9524 | add_name_attribute (die, dwarf2_name (decl, 0)); |
a96c67ec JM |
9525 | if (! DECL_ARTIFICIAL (decl)) |
9526 | add_src_coords_attributes (die, decl); | |
e689ae67 | 9527 | |
a1d7ffe3 | 9528 | if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) |
bc808e0b | 9529 | && TREE_PUBLIC (decl) |
5daf7c0a JM |
9530 | && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) |
9531 | && !DECL_ABSTRACT (decl)) | |
a1d7ffe3 JM |
9532 | add_AT_string (die, DW_AT_MIPS_linkage_name, |
9533 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
a3f97cbb | 9534 | } |
7a0c8d71 DR |
9535 | |
9536 | #ifdef VMS_DEBUGGING_INFO | |
7a0c8d71 DR |
9537 | /* Get the function's name, as described by its RTL. This may be different |
9538 | from the DECL_NAME name used in the source file. */ | |
9539 | if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl)) | |
c470afad RK |
9540 | { |
9541 | add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address, | |
9542 | XEXP (DECL_RTL (decl), 0)); | |
9543 | VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0)); | |
9544 | } | |
7a0c8d71 | 9545 | #endif |
a3f97cbb JW |
9546 | } |
9547 | ||
556273e0 | 9548 | /* Push a new declaration scope. */ |
71dfc51f | 9549 | |
a3f97cbb JW |
9550 | static void |
9551 | push_decl_scope (scope) | |
9552 | tree scope; | |
9553 | { | |
244a4af0 | 9554 | VARRAY_PUSH_TREE (decl_scope_table, scope); |
a3f97cbb JW |
9555 | } |
9556 | ||
777ad4c2 | 9557 | /* Pop a declaration scope. */ |
2ad9852d | 9558 | |
777ad4c2 JM |
9559 | static inline void |
9560 | pop_decl_scope () | |
9561 | { | |
244a4af0 | 9562 | if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0) |
777ad4c2 | 9563 | abort (); |
2ad9852d | 9564 | |
244a4af0 | 9565 | VARRAY_POP (decl_scope_table); |
777ad4c2 JM |
9566 | } |
9567 | ||
9568 | /* Return the DIE for the scope that immediately contains this type. | |
9569 | Non-named types get global scope. Named types nested in other | |
9570 | types get their containing scope if it's open, or global scope | |
9571 | otherwise. All other types (i.e. function-local named types) get | |
9572 | the current active scope. */ | |
71dfc51f | 9573 | |
a3f97cbb | 9574 | static dw_die_ref |
ab72d377 | 9575 | scope_die_for (t, context_die) |
b3694847 SS |
9576 | tree t; |
9577 | dw_die_ref context_die; | |
a3f97cbb | 9578 | { |
b3694847 SS |
9579 | dw_die_ref scope_die = NULL; |
9580 | tree containing_scope; | |
9581 | int i; | |
a3f97cbb | 9582 | |
777ad4c2 JM |
9583 | /* Non-types always go in the current scope. */ |
9584 | if (! TYPE_P (t)) | |
9585 | abort (); | |
9586 | ||
9587 | containing_scope = TYPE_CONTEXT (t); | |
ab72d377 | 9588 | |
2addbe1d JM |
9589 | /* Ignore namespaces for the moment. */ |
9590 | if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL) | |
9591 | containing_scope = NULL_TREE; | |
9592 | ||
5f2f160c JM |
9593 | /* Ignore function type "scopes" from the C frontend. They mean that |
9594 | a tagged type is local to a parmlist of a function declarator, but | |
9595 | that isn't useful to DWARF. */ | |
9596 | if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE) | |
9597 | containing_scope = NULL_TREE; | |
9598 | ||
71dfc51f RK |
9599 | if (containing_scope == NULL_TREE) |
9600 | scope_die = comp_unit_die; | |
777ad4c2 | 9601 | else if (TYPE_P (containing_scope)) |
348bb3c7 | 9602 | { |
777ad4c2 JM |
9603 | /* For types, we can just look up the appropriate DIE. But |
9604 | first we check to see if we're in the middle of emitting it | |
9605 | so we know where the new DIE should go. */ | |
244a4af0 TF |
9606 | for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i) |
9607 | if (VARRAY_TREE (decl_scope_table, i) == containing_scope) | |
348bb3c7 JM |
9608 | break; |
9609 | ||
9610 | if (i < 0) | |
9611 | { | |
348bb3c7 JM |
9612 | if (debug_info_level > DINFO_LEVEL_TERSE |
9613 | && !TREE_ASM_WRITTEN (containing_scope)) | |
9614 | abort (); | |
9615 | ||
9616 | /* If none of the current dies are suitable, we get file scope. */ | |
9617 | scope_die = comp_unit_die; | |
9618 | } | |
9619 | else | |
777ad4c2 | 9620 | scope_die = lookup_type_die (containing_scope); |
348bb3c7 | 9621 | } |
a3f97cbb | 9622 | else |
777ad4c2 | 9623 | scope_die = context_die; |
71dfc51f | 9624 | |
a3f97cbb JW |
9625 | return scope_die; |
9626 | } | |
9627 | ||
2ad9852d | 9628 | /* Returns nonzero if CONTEXT_DIE is internal to a function. */ |
777ad4c2 JM |
9629 | |
9630 | static inline int | |
9631 | local_scope_p (context_die) | |
9632 | dw_die_ref context_die; | |
a3f97cbb | 9633 | { |
777ad4c2 JM |
9634 | for (; context_die; context_die = context_die->die_parent) |
9635 | if (context_die->die_tag == DW_TAG_inlined_subroutine | |
9636 | || context_die->die_tag == DW_TAG_subprogram) | |
9637 | return 1; | |
2ad9852d | 9638 | |
777ad4c2 | 9639 | return 0; |
a3f97cbb JW |
9640 | } |
9641 | ||
2ad9852d | 9642 | /* Returns nonzero if CONTEXT_DIE is a class. */ |
9765e357 JM |
9643 | |
9644 | static inline int | |
9645 | class_scope_p (context_die) | |
9646 | dw_die_ref context_die; | |
9647 | { | |
9648 | return (context_die | |
9649 | && (context_die->die_tag == DW_TAG_structure_type | |
9650 | || context_die->die_tag == DW_TAG_union_type)); | |
9651 | } | |
9652 | ||
a3f97cbb JW |
9653 | /* Many forms of DIEs require a "type description" attribute. This |
9654 | routine locates the proper "type descriptor" die for the type given | |
9655 | by 'type', and adds an DW_AT_type attribute below the given die. */ | |
71dfc51f | 9656 | |
a3f97cbb JW |
9657 | static void |
9658 | add_type_attribute (object_die, type, decl_const, decl_volatile, context_die) | |
b3694847 SS |
9659 | dw_die_ref object_die; |
9660 | tree type; | |
9661 | int decl_const; | |
9662 | int decl_volatile; | |
9663 | dw_die_ref context_die; | |
a3f97cbb | 9664 | { |
b3694847 SS |
9665 | enum tree_code code = TREE_CODE (type); |
9666 | dw_die_ref type_die = NULL; | |
a3f97cbb | 9667 | |
ef76d03b JW |
9668 | /* ??? If this type is an unnamed subrange type of an integral or |
9669 | floating-point type, use the inner type. This is because we have no | |
9670 | support for unnamed types in base_type_die. This can happen if this is | |
9671 | an Ada subrange type. Correct solution is emit a subrange type die. */ | |
b1ccbc24 RK |
9672 | if ((code == INTEGER_TYPE || code == REAL_TYPE) |
9673 | && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0) | |
9674 | type = TREE_TYPE (type), code = TREE_CODE (type); | |
9675 | ||
2ad9852d RK |
9676 | if (code == ERROR_MARK |
9677 | /* Handle a special case. For functions whose return type is void, we | |
9678 | generate *no* type attribute. (Note that no object may have type | |
9679 | `void', so this only applies to function return types). */ | |
9680 | || code == VOID_TYPE) | |
b1ccbc24 | 9681 | return; |
a3f97cbb | 9682 | |
a3f97cbb JW |
9683 | type_die = modified_type_die (type, |
9684 | decl_const || TYPE_READONLY (type), | |
9685 | decl_volatile || TYPE_VOLATILE (type), | |
ab72d377 | 9686 | context_die); |
2ad9852d | 9687 | |
a3f97cbb | 9688 | if (type_die != NULL) |
71dfc51f | 9689 | add_AT_die_ref (object_die, DW_AT_type, type_die); |
a3f97cbb JW |
9690 | } |
9691 | ||
9692 | /* Given a tree pointer to a struct, class, union, or enum type node, return | |
9693 | a pointer to the (string) tag name for the given type, or zero if the type | |
9694 | was declared without a tag. */ | |
71dfc51f | 9695 | |
d3e3972c | 9696 | static const char * |
a3f97cbb | 9697 | type_tag (type) |
b3694847 | 9698 | tree type; |
a3f97cbb | 9699 | { |
b3694847 | 9700 | const char *name = 0; |
a3f97cbb JW |
9701 | |
9702 | if (TYPE_NAME (type) != 0) | |
9703 | { | |
b3694847 | 9704 | tree t = 0; |
a3f97cbb JW |
9705 | |
9706 | /* Find the IDENTIFIER_NODE for the type name. */ | |
9707 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
9708 | t = TYPE_NAME (type); | |
bdb669cb | 9709 | |
556273e0 | 9710 | /* The g++ front end makes the TYPE_NAME of *each* tagged type point to |
a3f97cbb | 9711 | a TYPE_DECL node, regardless of whether or not a `typedef' was |
bdb669cb | 9712 | involved. */ |
a94dbf2c JM |
9713 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
9714 | && ! DECL_IGNORED_P (TYPE_NAME (type))) | |
a3f97cbb | 9715 | t = DECL_NAME (TYPE_NAME (type)); |
bdb669cb | 9716 | |
a3f97cbb JW |
9717 | /* Now get the name as a string, or invent one. */ |
9718 | if (t != 0) | |
a94dbf2c | 9719 | name = IDENTIFIER_POINTER (t); |
a3f97cbb | 9720 | } |
71dfc51f | 9721 | |
a3f97cbb JW |
9722 | return (name == 0 || *name == '\0') ? 0 : name; |
9723 | } | |
9724 | ||
9725 | /* Return the type associated with a data member, make a special check | |
9726 | for bit field types. */ | |
71dfc51f RK |
9727 | |
9728 | static inline tree | |
a3f97cbb | 9729 | member_declared_type (member) |
b3694847 | 9730 | tree member; |
a3f97cbb | 9731 | { |
71dfc51f | 9732 | return (DECL_BIT_FIELD_TYPE (member) |
2ad9852d | 9733 | ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member)); |
a3f97cbb JW |
9734 | } |
9735 | ||
d291dd49 | 9736 | /* Get the decl's label, as described by its RTL. This may be different |
a3f97cbb | 9737 | from the DECL_NAME name used in the source file. */ |
71dfc51f | 9738 | |
487a6e06 | 9739 | #if 0 |
d3e3972c | 9740 | static const char * |
d291dd49 | 9741 | decl_start_label (decl) |
b3694847 | 9742 | tree decl; |
a3f97cbb JW |
9743 | { |
9744 | rtx x; | |
d3e3972c | 9745 | const char *fnname; |
2ad9852d | 9746 | |
a3f97cbb JW |
9747 | x = DECL_RTL (decl); |
9748 | if (GET_CODE (x) != MEM) | |
71dfc51f RK |
9749 | abort (); |
9750 | ||
a3f97cbb JW |
9751 | x = XEXP (x, 0); |
9752 | if (GET_CODE (x) != SYMBOL_REF) | |
71dfc51f RK |
9753 | abort (); |
9754 | ||
a3f97cbb JW |
9755 | fnname = XSTR (x, 0); |
9756 | return fnname; | |
9757 | } | |
487a6e06 | 9758 | #endif |
a3f97cbb | 9759 | \f |
956d6950 | 9760 | /* These routines generate the internal representation of the DIE's for |
a3f97cbb | 9761 | the compilation unit. Debugging information is collected by walking |
88dad228 | 9762 | the declaration trees passed in from dwarf2out_decl(). */ |
a3f97cbb JW |
9763 | |
9764 | static void | |
9765 | gen_array_type_die (type, context_die) | |
b3694847 SS |
9766 | tree type; |
9767 | dw_die_ref context_die; | |
a3f97cbb | 9768 | { |
b3694847 SS |
9769 | dw_die_ref scope_die = scope_die_for (type, context_die); |
9770 | dw_die_ref array_die; | |
9771 | tree element_type; | |
bdb669cb | 9772 | |
a9d38797 JM |
9773 | /* ??? The SGI dwarf reader fails for array of array of enum types unless |
9774 | the inner array type comes before the outer array type. Thus we must | |
9775 | call gen_type_die before we call new_die. See below also. */ | |
9776 | #ifdef MIPS_DEBUGGING_INFO | |
9777 | gen_type_die (TREE_TYPE (type), context_die); | |
9778 | #endif | |
9779 | ||
54ba1f0d | 9780 | array_die = new_die (DW_TAG_array_type, scope_die, type); |
84f0ace0 JM |
9781 | add_name_attribute (array_die, type_tag (type)); |
9782 | equate_type_number_to_die (type, array_die); | |
9783 | ||
9784 | if (TREE_CODE (type) == VECTOR_TYPE) | |
9785 | { | |
9786 | /* The frontend feeds us a representation for the vector as a struct | |
9787 | containing an array. Pull out the array type. */ | |
9788 | type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type))); | |
9789 | add_AT_flag (array_die, DW_AT_GNU_vector, 1); | |
9790 | } | |
a9d38797 | 9791 | |
a3f97cbb JW |
9792 | #if 0 |
9793 | /* We default the array ordering. SDB will probably do | |
9794 | the right things even if DW_AT_ordering is not present. It's not even | |
9795 | an issue until we start to get into multidimensional arrays anyway. If | |
9796 | SDB is ever caught doing the Wrong Thing for multi-dimensional arrays, | |
9797 | then we'll have to put the DW_AT_ordering attribute back in. (But if | |
9798 | and when we find out that we need to put these in, we will only do so | |
9799 | for multidimensional arrays. */ | |
9800 | add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major); | |
9801 | #endif | |
9802 | ||
a9d38797 | 9803 | #ifdef MIPS_DEBUGGING_INFO |
4edb7b60 JM |
9804 | /* The SGI compilers handle arrays of unknown bound by setting |
9805 | AT_declaration and not emitting any subrange DIEs. */ | |
a9d38797 JM |
9806 | if (! TYPE_DOMAIN (type)) |
9807 | add_AT_unsigned (array_die, DW_AT_declaration, 1); | |
9808 | else | |
9809 | #endif | |
9810 | add_subscript_info (array_die, type); | |
a3f97cbb | 9811 | |
a3f97cbb JW |
9812 | /* Add representation of the type of the elements of this array type. */ |
9813 | element_type = TREE_TYPE (type); | |
71dfc51f | 9814 | |
a3f97cbb JW |
9815 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
9816 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
9817 | We work around this by disabling this feature. See also | |
9818 | add_subscript_info. */ | |
9819 | #ifndef MIPS_DEBUGGING_INFO | |
71dfc51f RK |
9820 | while (TREE_CODE (element_type) == ARRAY_TYPE) |
9821 | element_type = TREE_TYPE (element_type); | |
9822 | ||
a3f97cbb | 9823 | gen_type_die (element_type, context_die); |
a9d38797 | 9824 | #endif |
a3f97cbb JW |
9825 | |
9826 | add_type_attribute (array_die, element_type, 0, 0, context_die); | |
9827 | } | |
9828 | ||
9829 | static void | |
9830 | gen_set_type_die (type, context_die) | |
b3694847 SS |
9831 | tree type; |
9832 | dw_die_ref context_die; | |
a3f97cbb | 9833 | { |
b3694847 | 9834 | dw_die_ref type_die |
54ba1f0d | 9835 | = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type); |
71dfc51f | 9836 | |
a3f97cbb | 9837 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
9838 | add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die); |
9839 | } | |
9840 | ||
d6f4ec51 | 9841 | #if 0 |
a3f97cbb JW |
9842 | static void |
9843 | gen_entry_point_die (decl, context_die) | |
b3694847 SS |
9844 | tree decl; |
9845 | dw_die_ref context_die; | |
a3f97cbb | 9846 | { |
b3694847 | 9847 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 9848 | dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl); |
2ad9852d | 9849 | |
a3f97cbb | 9850 | if (origin != NULL) |
71dfc51f | 9851 | add_abstract_origin_attribute (decl_die, origin); |
a3f97cbb JW |
9852 | else |
9853 | { | |
9854 | add_name_and_src_coords_attributes (decl_die, decl); | |
a3f97cbb JW |
9855 | add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)), |
9856 | 0, 0, context_die); | |
9857 | } | |
71dfc51f | 9858 | |
a3f97cbb | 9859 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 9860 | equate_decl_number_to_die (decl, decl_die); |
a3f97cbb | 9861 | else |
71dfc51f | 9862 | add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl)); |
a3f97cbb | 9863 | } |
d6f4ec51 | 9864 | #endif |
a3f97cbb | 9865 | |
8a8c3656 JM |
9866 | /* Walk through the list of incomplete types again, trying once more to |
9867 | emit full debugging info for them. */ | |
9868 | ||
9869 | static void | |
9870 | retry_incomplete_types () | |
9871 | { | |
244a4af0 | 9872 | int i; |
2ad9852d | 9873 | |
244a4af0 | 9874 | for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--) |
2ad9852d | 9875 | gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die); |
8a8c3656 JM |
9876 | } |
9877 | ||
a3f97cbb | 9878 | /* Generate a DIE to represent an inlined instance of an enumeration type. */ |
71dfc51f | 9879 | |
a3f97cbb JW |
9880 | static void |
9881 | gen_inlined_enumeration_type_die (type, context_die) | |
b3694847 SS |
9882 | tree type; |
9883 | dw_die_ref context_die; | |
a3f97cbb | 9884 | { |
54ba1f0d | 9885 | dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type); |
2ad9852d | 9886 | |
bbc6ae08 NC |
9887 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9888 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9889 | add_abstract_origin_attribute (type_die, type); |
9890 | } | |
9891 | ||
9892 | /* Generate a DIE to represent an inlined instance of a structure type. */ | |
71dfc51f | 9893 | |
a3f97cbb JW |
9894 | static void |
9895 | gen_inlined_structure_type_die (type, context_die) | |
b3694847 SS |
9896 | tree type; |
9897 | dw_die_ref context_die; | |
a3f97cbb | 9898 | { |
54ba1f0d | 9899 | dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type); |
777ad4c2 | 9900 | |
bbc6ae08 NC |
9901 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9902 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9903 | add_abstract_origin_attribute (type_die, type); |
9904 | } | |
9905 | ||
9906 | /* Generate a DIE to represent an inlined instance of a union type. */ | |
71dfc51f | 9907 | |
a3f97cbb JW |
9908 | static void |
9909 | gen_inlined_union_type_die (type, context_die) | |
b3694847 SS |
9910 | tree type; |
9911 | dw_die_ref context_die; | |
a3f97cbb | 9912 | { |
54ba1f0d | 9913 | dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type); |
777ad4c2 | 9914 | |
bbc6ae08 NC |
9915 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9916 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9917 | add_abstract_origin_attribute (type_die, type); |
9918 | } | |
9919 | ||
9920 | /* Generate a DIE to represent an enumeration type. Note that these DIEs | |
9921 | include all of the information about the enumeration values also. Each | |
273dbe67 JM |
9922 | enumerated type name/value is listed as a child of the enumerated type |
9923 | DIE. */ | |
71dfc51f | 9924 | |
a3f97cbb | 9925 | static void |
273dbe67 | 9926 | gen_enumeration_type_die (type, context_die) |
b3694847 SS |
9927 | tree type; |
9928 | dw_die_ref context_die; | |
a3f97cbb | 9929 | { |
b3694847 | 9930 | dw_die_ref type_die = lookup_type_die (type); |
273dbe67 | 9931 | |
a3f97cbb JW |
9932 | if (type_die == NULL) |
9933 | { | |
9934 | type_die = new_die (DW_TAG_enumeration_type, | |
54ba1f0d | 9935 | scope_die_for (type, context_die), type); |
a3f97cbb JW |
9936 | equate_type_number_to_die (type, type_die); |
9937 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 9938 | } |
273dbe67 JM |
9939 | else if (! TYPE_SIZE (type)) |
9940 | return; | |
9941 | else | |
9942 | remove_AT (type_die, DW_AT_declaration); | |
9943 | ||
9944 | /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the | |
9945 | given enum type is incomplete, do not generate the DW_AT_byte_size | |
9946 | attribute or the DW_AT_element_list attribute. */ | |
9947 | if (TYPE_SIZE (type)) | |
a3f97cbb | 9948 | { |
b3694847 | 9949 | tree link; |
71dfc51f | 9950 | |
a082c85a | 9951 | TREE_ASM_WRITTEN (type) = 1; |
273dbe67 | 9952 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 9953 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 9954 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 9955 | |
ef76d03b JW |
9956 | /* If the first reference to this type was as the return type of an |
9957 | inline function, then it may not have a parent. Fix this now. */ | |
9958 | if (type_die->die_parent == NULL) | |
9959 | add_child_die (scope_die_for (type, context_die), type_die); | |
9960 | ||
273dbe67 JM |
9961 | for (link = TYPE_FIELDS (type); |
9962 | link != NULL; link = TREE_CHAIN (link)) | |
a3f97cbb | 9963 | { |
54ba1f0d | 9964 | dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link); |
71dfc51f | 9965 | |
273dbe67 JM |
9966 | add_name_attribute (enum_die, |
9967 | IDENTIFIER_POINTER (TREE_PURPOSE (link))); | |
665f2503 RK |
9968 | |
9969 | if (host_integerp (TREE_VALUE (link), 0)) | |
fc9e8a14 JJ |
9970 | { |
9971 | if (tree_int_cst_sgn (TREE_VALUE (link)) < 0) | |
9972 | add_AT_int (enum_die, DW_AT_const_value, | |
9973 | tree_low_cst (TREE_VALUE (link), 0)); | |
9974 | else | |
9975 | add_AT_unsigned (enum_die, DW_AT_const_value, | |
9976 | tree_low_cst (TREE_VALUE (link), 0)); | |
9977 | } | |
a3f97cbb JW |
9978 | } |
9979 | } | |
273dbe67 JM |
9980 | else |
9981 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a3f97cbb JW |
9982 | } |
9983 | ||
a3f97cbb JW |
9984 | /* Generate a DIE to represent either a real live formal parameter decl or to |
9985 | represent just the type of some formal parameter position in some function | |
9986 | type. | |
71dfc51f | 9987 | |
a3f97cbb JW |
9988 | Note that this routine is a bit unusual because its argument may be a |
9989 | ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which | |
9990 | represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE | |
9991 | node. If it's the former then this function is being called to output a | |
9992 | DIE to represent a formal parameter object (or some inlining thereof). If | |
9993 | it's the latter, then this function is only being called to output a | |
9994 | DW_TAG_formal_parameter DIE to stand as a placeholder for some formal | |
9995 | argument type of some subprogram type. */ | |
71dfc51f | 9996 | |
a94dbf2c | 9997 | static dw_die_ref |
a3f97cbb | 9998 | gen_formal_parameter_die (node, context_die) |
b3694847 SS |
9999 | tree node; |
10000 | dw_die_ref context_die; | |
a3f97cbb | 10001 | { |
b3694847 | 10002 | dw_die_ref parm_die |
54ba1f0d | 10003 | = new_die (DW_TAG_formal_parameter, context_die, node); |
b3694847 | 10004 | tree origin; |
71dfc51f | 10005 | |
a3f97cbb JW |
10006 | switch (TREE_CODE_CLASS (TREE_CODE (node))) |
10007 | { | |
a3f97cbb JW |
10008 | case 'd': |
10009 | origin = decl_ultimate_origin (node); | |
10010 | if (origin != NULL) | |
a94dbf2c | 10011 | add_abstract_origin_attribute (parm_die, origin); |
a3f97cbb JW |
10012 | else |
10013 | { | |
10014 | add_name_and_src_coords_attributes (parm_die, node); | |
10015 | add_type_attribute (parm_die, TREE_TYPE (node), | |
10016 | TREE_READONLY (node), | |
10017 | TREE_THIS_VOLATILE (node), | |
10018 | context_die); | |
bdb669cb JM |
10019 | if (DECL_ARTIFICIAL (node)) |
10020 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb | 10021 | } |
71dfc51f | 10022 | |
141719a8 JM |
10023 | equate_decl_number_to_die (node, parm_die); |
10024 | if (! DECL_ABSTRACT (node)) | |
a94dbf2c | 10025 | add_location_or_const_value_attribute (parm_die, node); |
71dfc51f | 10026 | |
a3f97cbb JW |
10027 | break; |
10028 | ||
a3f97cbb | 10029 | case 't': |
71dfc51f | 10030 | /* We were called with some kind of a ..._TYPE node. */ |
a3f97cbb JW |
10031 | add_type_attribute (parm_die, node, 0, 0, context_die); |
10032 | break; | |
10033 | ||
a3f97cbb JW |
10034 | default: |
10035 | abort (); | |
10036 | } | |
71dfc51f | 10037 | |
a94dbf2c | 10038 | return parm_die; |
a3f97cbb JW |
10039 | } |
10040 | ||
10041 | /* Generate a special type of DIE used as a stand-in for a trailing ellipsis | |
10042 | at the end of an (ANSI prototyped) formal parameters list. */ | |
71dfc51f | 10043 | |
a3f97cbb JW |
10044 | static void |
10045 | gen_unspecified_parameters_die (decl_or_type, context_die) | |
54ba1f0d | 10046 | tree decl_or_type; |
b3694847 | 10047 | dw_die_ref context_die; |
a3f97cbb | 10048 | { |
54ba1f0d | 10049 | new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type); |
a3f97cbb JW |
10050 | } |
10051 | ||
10052 | /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a | |
10053 | DW_TAG_unspecified_parameters DIE) to represent the types of the formal | |
10054 | parameters as specified in some function type specification (except for | |
1cfdcc15 | 10055 | those which appear as part of a function *definition*). */ |
71dfc51f | 10056 | |
a3f97cbb JW |
10057 | static void |
10058 | gen_formal_types_die (function_or_method_type, context_die) | |
b3694847 SS |
10059 | tree function_or_method_type; |
10060 | dw_die_ref context_die; | |
a3f97cbb | 10061 | { |
b3694847 SS |
10062 | tree link; |
10063 | tree formal_type = NULL; | |
10064 | tree first_parm_type; | |
5daf7c0a | 10065 | tree arg; |
a3f97cbb | 10066 | |
5daf7c0a JM |
10067 | if (TREE_CODE (function_or_method_type) == FUNCTION_DECL) |
10068 | { | |
10069 | arg = DECL_ARGUMENTS (function_or_method_type); | |
10070 | function_or_method_type = TREE_TYPE (function_or_method_type); | |
10071 | } | |
10072 | else | |
10073 | arg = NULL_TREE; | |
c26fbbca | 10074 | |
5daf7c0a | 10075 | first_parm_type = TYPE_ARG_TYPES (function_or_method_type); |
a3f97cbb | 10076 | |
556273e0 | 10077 | /* Make our first pass over the list of formal parameter types and output a |
a3f97cbb | 10078 | DW_TAG_formal_parameter DIE for each one. */ |
5daf7c0a | 10079 | for (link = first_parm_type; link; ) |
a3f97cbb | 10080 | { |
b3694847 | 10081 | dw_die_ref parm_die; |
556273e0 | 10082 | |
a3f97cbb JW |
10083 | formal_type = TREE_VALUE (link); |
10084 | if (formal_type == void_type_node) | |
10085 | break; | |
10086 | ||
10087 | /* Output a (nameless) DIE to represent the formal parameter itself. */ | |
a94dbf2c | 10088 | parm_die = gen_formal_parameter_die (formal_type, context_die); |
5daf7c0a JM |
10089 | if ((TREE_CODE (function_or_method_type) == METHOD_TYPE |
10090 | && link == first_parm_type) | |
10091 | || (arg && DECL_ARTIFICIAL (arg))) | |
a94dbf2c | 10092 | add_AT_flag (parm_die, DW_AT_artificial, 1); |
5daf7c0a JM |
10093 | |
10094 | link = TREE_CHAIN (link); | |
10095 | if (arg) | |
10096 | arg = TREE_CHAIN (arg); | |
a3f97cbb JW |
10097 | } |
10098 | ||
10099 | /* If this function type has an ellipsis, add a | |
10100 | DW_TAG_unspecified_parameters DIE to the end of the parameter list. */ | |
10101 | if (formal_type != void_type_node) | |
10102 | gen_unspecified_parameters_die (function_or_method_type, context_die); | |
10103 | ||
556273e0 | 10104 | /* Make our second (and final) pass over the list of formal parameter types |
a3f97cbb JW |
10105 | and output DIEs to represent those types (as necessary). */ |
10106 | for (link = TYPE_ARG_TYPES (function_or_method_type); | |
2ad9852d | 10107 | link && TREE_VALUE (link); |
a3f97cbb | 10108 | link = TREE_CHAIN (link)) |
2ad9852d | 10109 | gen_type_die (TREE_VALUE (link), context_die); |
a3f97cbb JW |
10110 | } |
10111 | ||
10a11b75 JM |
10112 | /* We want to generate the DIE for TYPE so that we can generate the |
10113 | die for MEMBER, which has been defined; we will need to refer back | |
10114 | to the member declaration nested within TYPE. If we're trying to | |
10115 | generate minimal debug info for TYPE, processing TYPE won't do the | |
10116 | trick; we need to attach the member declaration by hand. */ | |
10117 | ||
10118 | static void | |
10119 | gen_type_die_for_member (type, member, context_die) | |
10120 | tree type, member; | |
10121 | dw_die_ref context_die; | |
10122 | { | |
10123 | gen_type_die (type, context_die); | |
10124 | ||
10125 | /* If we're trying to avoid duplicate debug info, we may not have | |
10126 | emitted the member decl for this function. Emit it now. */ | |
10127 | if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)) | |
10128 | && ! lookup_decl_die (member)) | |
10129 | { | |
10130 | if (decl_ultimate_origin (member)) | |
10131 | abort (); | |
10132 | ||
10133 | push_decl_scope (type); | |
10134 | if (TREE_CODE (member) == FUNCTION_DECL) | |
10135 | gen_subprogram_die (member, lookup_type_die (type)); | |
10136 | else | |
10137 | gen_variable_die (member, lookup_type_die (type)); | |
2ad9852d | 10138 | |
10a11b75 JM |
10139 | pop_decl_scope (); |
10140 | } | |
10141 | } | |
10142 | ||
2ad9852d RK |
10143 | /* Generate the DWARF2 info for the "abstract" instance of a function which we |
10144 | may later generate inlined and/or out-of-line instances of. */ | |
10a11b75 | 10145 | |
e1772ac0 | 10146 | static void |
1edf43d6 | 10147 | dwarf2out_abstract_function (decl) |
10a11b75 JM |
10148 | tree decl; |
10149 | { | |
b3694847 | 10150 | dw_die_ref old_die; |
777ad4c2 | 10151 | tree save_fn; |
5daf7c0a JM |
10152 | tree context; |
10153 | int was_abstract = DECL_ABSTRACT (decl); | |
10154 | ||
10155 | /* Make sure we have the actual abstract inline, not a clone. */ | |
10156 | decl = DECL_ORIGIN (decl); | |
10a11b75 | 10157 | |
c26fbbca | 10158 | old_die = lookup_decl_die (decl); |
10a11b75 JM |
10159 | if (old_die && get_AT_unsigned (old_die, DW_AT_inline)) |
10160 | /* We've already generated the abstract instance. */ | |
10161 | return; | |
10162 | ||
5daf7c0a JM |
10163 | /* Be sure we've emitted the in-class declaration DIE (if any) first, so |
10164 | we don't get confused by DECL_ABSTRACT. */ | |
8458e954 JS |
10165 | if (debug_info_level > DINFO_LEVEL_TERSE) |
10166 | { | |
10167 | context = decl_class_context (decl); | |
10168 | if (context) | |
10169 | gen_type_die_for_member | |
10170 | (context, decl, decl_function_context (decl) ? NULL : comp_unit_die); | |
10171 | } | |
c26fbbca | 10172 | |
5daf7c0a | 10173 | /* Pretend we've just finished compiling this function. */ |
777ad4c2 JM |
10174 | save_fn = current_function_decl; |
10175 | current_function_decl = decl; | |
10176 | ||
10a11b75 JM |
10177 | set_decl_abstract_flags (decl, 1); |
10178 | dwarf2out_decl (decl); | |
5daf7c0a JM |
10179 | if (! was_abstract) |
10180 | set_decl_abstract_flags (decl, 0); | |
777ad4c2 JM |
10181 | |
10182 | current_function_decl = save_fn; | |
10a11b75 JM |
10183 | } |
10184 | ||
a3f97cbb JW |
10185 | /* Generate a DIE to represent a declared function (either file-scope or |
10186 | block-local). */ | |
71dfc51f | 10187 | |
a3f97cbb JW |
10188 | static void |
10189 | gen_subprogram_die (decl, context_die) | |
b3694847 SS |
10190 | tree decl; |
10191 | dw_die_ref context_die; | |
a3f97cbb JW |
10192 | { |
10193 | char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 SS |
10194 | tree origin = decl_ultimate_origin (decl); |
10195 | dw_die_ref subr_die; | |
10196 | rtx fp_reg; | |
10197 | tree fn_arg_types; | |
10198 | tree outer_scope; | |
10199 | dw_die_ref old_die = lookup_decl_die (decl); | |
10200 | int declaration = (current_function_decl != decl | |
10201 | || class_scope_p (context_die)); | |
a3f97cbb | 10202 | |
2ad9852d RK |
10203 | /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we |
10204 | started to generate the abstract instance of an inline, decided to output | |
10205 | its containing class, and proceeded to emit the declaration of the inline | |
10206 | from the member list for the class. If so, DECLARATION takes priority; | |
10207 | we'll get back to the abstract instance when done with the class. */ | |
10a11b75 | 10208 | |
1cfdcc15 JM |
10209 | /* The class-scope declaration DIE must be the primary DIE. */ |
10210 | if (origin && declaration && class_scope_p (context_die)) | |
10211 | { | |
10212 | origin = NULL; | |
10213 | if (old_die) | |
10214 | abort (); | |
10215 | } | |
10216 | ||
a3f97cbb JW |
10217 | if (origin != NULL) |
10218 | { | |
777ad4c2 | 10219 | if (declaration && ! local_scope_p (context_die)) |
10a11b75 JM |
10220 | abort (); |
10221 | ||
8d8238b6 JM |
10222 | /* Fixup die_parent for the abstract instance of a nested |
10223 | inline function. */ | |
10224 | if (old_die && old_die->die_parent == NULL) | |
10225 | add_child_die (context_die, old_die); | |
10226 | ||
54ba1f0d | 10227 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
a3f97cbb JW |
10228 | add_abstract_origin_attribute (subr_die, origin); |
10229 | } | |
bdb669cb JM |
10230 | else if (old_die) |
10231 | { | |
981975b6 | 10232 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
a94dbf2c | 10233 | |
1edf43d6 JM |
10234 | if (!get_AT_flag (old_die, DW_AT_declaration) |
10235 | /* We can have a normal definition following an inline one in the | |
10236 | case of redefinition of GNU C extern inlines. | |
10237 | It seems reasonable to use AT_specification in this case. */ | |
10238 | && !get_AT_unsigned (old_die, DW_AT_inline)) | |
b75ab88b NC |
10239 | { |
10240 | /* ??? This can happen if there is a bug in the program, for | |
10241 | instance, if it has duplicate function definitions. Ideally, | |
10242 | we should detect this case and ignore it. For now, if we have | |
10243 | already reported an error, any error at all, then assume that | |
4fe9b91c | 10244 | we got here because of an input error, not a dwarf2 bug. */ |
b75ab88b NC |
10245 | if (errorcount) |
10246 | return; | |
10247 | abort (); | |
10248 | } | |
4b674448 JM |
10249 | |
10250 | /* If the definition comes from the same place as the declaration, | |
a94dbf2c JM |
10251 | maybe use the old DIE. We always want the DIE for this function |
10252 | that has the *_pc attributes to be under comp_unit_die so the | |
cb9e9d8d JM |
10253 | debugger can find it. We also need to do this for abstract |
10254 | instances of inlines, since the spec requires the out-of-line copy | |
10255 | to have the same parent. For local class methods, this doesn't | |
10256 | apply; we just use the old DIE. */ | |
10257 | if ((old_die->die_parent == comp_unit_die || context_die == NULL) | |
a96c67ec JM |
10258 | && (DECL_ARTIFICIAL (decl) |
10259 | || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index | |
10260 | && (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 10261 | == (unsigned) DECL_SOURCE_LINE (decl))))) |
bdb669cb | 10262 | { |
4b674448 JM |
10263 | subr_die = old_die; |
10264 | ||
10265 | /* Clear out the declaration attribute and the parm types. */ | |
10266 | remove_AT (subr_die, DW_AT_declaration); | |
10267 | remove_children (subr_die); | |
10268 | } | |
10269 | else | |
10270 | { | |
54ba1f0d | 10271 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
4b674448 | 10272 | add_AT_die_ref (subr_die, DW_AT_specification, old_die); |
bdb669cb JM |
10273 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
10274 | add_AT_unsigned (subr_die, DW_AT_decl_file, file_index); | |
10275 | if (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 10276 | != (unsigned) DECL_SOURCE_LINE (decl)) |
bdb669cb JM |
10277 | add_AT_unsigned |
10278 | (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
10279 | } | |
10280 | } | |
a3f97cbb JW |
10281 | else |
10282 | { | |
54ba1f0d | 10283 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
556273e0 | 10284 | |
273dbe67 JM |
10285 | if (TREE_PUBLIC (decl)) |
10286 | add_AT_flag (subr_die, DW_AT_external, 1); | |
71dfc51f | 10287 | |
a3f97cbb | 10288 | add_name_and_src_coords_attributes (subr_die, decl); |
4927276d JM |
10289 | if (debug_info_level > DINFO_LEVEL_TERSE) |
10290 | { | |
2ad9852d RK |
10291 | add_prototyped_attribute (subr_die, TREE_TYPE (decl)); |
10292 | add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)), | |
10293 | 0, 0, context_die); | |
4927276d | 10294 | } |
71dfc51f | 10295 | |
a3f97cbb | 10296 | add_pure_or_virtual_attribute (subr_die, decl); |
273dbe67 JM |
10297 | if (DECL_ARTIFICIAL (decl)) |
10298 | add_AT_flag (subr_die, DW_AT_artificial, 1); | |
2ad9852d | 10299 | |
a94dbf2c JM |
10300 | if (TREE_PROTECTED (decl)) |
10301 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected); | |
10302 | else if (TREE_PRIVATE (decl)) | |
10303 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 10304 | } |
4edb7b60 | 10305 | |
a94dbf2c JM |
10306 | if (declaration) |
10307 | { | |
2ad9852d | 10308 | if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline)) |
1edf43d6 JM |
10309 | { |
10310 | add_AT_flag (subr_die, DW_AT_declaration, 1); | |
10311 | ||
10312 | /* The first time we see a member function, it is in the context of | |
10313 | the class to which it belongs. We make sure of this by emitting | |
10314 | the class first. The next time is the definition, which is | |
10315 | handled above. The two may come from the same source text. */ | |
10316 | if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl)) | |
10317 | equate_decl_number_to_die (decl, subr_die); | |
10318 | } | |
a94dbf2c JM |
10319 | } |
10320 | else if (DECL_ABSTRACT (decl)) | |
a3f97cbb | 10321 | { |
10a11b75 | 10322 | if (DECL_INLINE (decl) && !flag_no_inline) |
61b32c02 | 10323 | { |
10a11b75 JM |
10324 | /* ??? Checking DECL_DEFER_OUTPUT is correct for static |
10325 | inline functions, but not for extern inline functions. | |
10326 | We can't get this completely correct because information | |
10327 | about whether the function was declared inline is not | |
10328 | saved anywhere. */ | |
10329 | if (DECL_DEFER_OUTPUT (decl)) | |
61b32c02 JM |
10330 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined); |
10331 | else | |
10a11b75 | 10332 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined); |
61b32c02 | 10333 | } |
61b32c02 | 10334 | else |
10a11b75 | 10335 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined); |
61b32c02 | 10336 | |
a3f97cbb JW |
10337 | equate_decl_number_to_die (decl, subr_die); |
10338 | } | |
10339 | else if (!DECL_EXTERNAL (decl)) | |
10340 | { | |
2ad9852d | 10341 | if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline)) |
ba7b35df | 10342 | equate_decl_number_to_die (decl, subr_die); |
71dfc51f | 10343 | |
5c90448c JM |
10344 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL, |
10345 | current_funcdef_number); | |
7d4440be | 10346 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id); |
5c90448c JM |
10347 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, |
10348 | current_funcdef_number); | |
a3f97cbb JW |
10349 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id); |
10350 | ||
d291dd49 JM |
10351 | add_pubname (decl, subr_die); |
10352 | add_arange (decl, subr_die); | |
10353 | ||
a3f97cbb | 10354 | #ifdef MIPS_DEBUGGING_INFO |
a3f97cbb JW |
10355 | /* Add a reference to the FDE for this routine. */ |
10356 | add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde); | |
10357 | #endif | |
10358 | ||
810429b7 JM |
10359 | /* Define the "frame base" location for this routine. We use the |
10360 | frame pointer or stack pointer registers, since the RTL for local | |
10361 | variables is relative to one of them. */ | |
b1ccbc24 RK |
10362 | fp_reg |
10363 | = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx; | |
10364 | add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg)); | |
a3f97cbb | 10365 | |
ef76d03b JW |
10366 | #if 0 |
10367 | /* ??? This fails for nested inline functions, because context_display | |
10368 | is not part of the state saved/restored for inline functions. */ | |
88dad228 | 10369 | if (current_function_needs_context) |
ef76d03b JW |
10370 | add_AT_location_description (subr_die, DW_AT_static_link, |
10371 | lookup_static_chain (decl)); | |
10372 | #endif | |
a3f97cbb JW |
10373 | } |
10374 | ||
10375 | /* Now output descriptions of the arguments for this function. This gets | |
556273e0 | 10376 | (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list |
a3f97cbb JW |
10377 | for a FUNCTION_DECL doesn't indicate cases where there was a trailing |
10378 | `...' at the end of the formal parameter list. In order to find out if | |
10379 | there was a trailing ellipsis or not, we must instead look at the type | |
10380 | associated with the FUNCTION_DECL. This will be a node of type | |
10381 | FUNCTION_TYPE. If the chain of type nodes hanging off of this | |
556273e0 | 10382 | FUNCTION_TYPE node ends with a void_type_node then there should *not* be |
a3f97cbb | 10383 | an ellipsis at the end. */ |
71dfc51f | 10384 | |
a3f97cbb | 10385 | /* In the case where we are describing a mere function declaration, all we |
556273e0 | 10386 | need to do here (and all we *can* do here) is to describe the *types* of |
a3f97cbb | 10387 | its formal parameters. */ |
4927276d | 10388 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 10389 | ; |
4edb7b60 | 10390 | else if (declaration) |
5daf7c0a | 10391 | gen_formal_types_die (decl, subr_die); |
a3f97cbb JW |
10392 | else |
10393 | { | |
10394 | /* Generate DIEs to represent all known formal parameters */ | |
b3694847 SS |
10395 | tree arg_decls = DECL_ARGUMENTS (decl); |
10396 | tree parm; | |
a3f97cbb JW |
10397 | |
10398 | /* When generating DIEs, generate the unspecified_parameters DIE | |
10399 | instead if we come across the arg "__builtin_va_alist" */ | |
10400 | for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) | |
71dfc51f RK |
10401 | if (TREE_CODE (parm) == PARM_DECL) |
10402 | { | |
db3cf6fb MS |
10403 | if (DECL_NAME (parm) |
10404 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), | |
10405 | "__builtin_va_alist")) | |
71dfc51f RK |
10406 | gen_unspecified_parameters_die (parm, subr_die); |
10407 | else | |
10408 | gen_decl_die (parm, subr_die); | |
10409 | } | |
a3f97cbb | 10410 | |
4fe9b91c | 10411 | /* Decide whether we need an unspecified_parameters DIE at the end. |
556273e0 | 10412 | There are 2 more cases to do this for: 1) the ansi ... declaration - |
a3f97cbb JW |
10413 | this is detectable when the end of the arg list is not a |
10414 | void_type_node 2) an unprototyped function declaration (not a | |
10415 | definition). This just means that we have no info about the | |
10416 | parameters at all. */ | |
10417 | fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
71dfc51f | 10418 | if (fn_arg_types != NULL) |
a3f97cbb JW |
10419 | { |
10420 | /* this is the prototyped case, check for ... */ | |
10421 | if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) | |
71dfc51f | 10422 | gen_unspecified_parameters_die (decl, subr_die); |
a3f97cbb | 10423 | } |
71dfc51f RK |
10424 | else if (DECL_INITIAL (decl) == NULL_TREE) |
10425 | gen_unspecified_parameters_die (decl, subr_die); | |
a3f97cbb JW |
10426 | } |
10427 | ||
10428 | /* Output Dwarf info for all of the stuff within the body of the function | |
10429 | (if it has one - it may be just a declaration). */ | |
10430 | outer_scope = DECL_INITIAL (decl); | |
10431 | ||
2ad9852d RK |
10432 | /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent |
10433 | a function. This BLOCK actually represents the outermost binding contour | |
10434 | for the function, i.e. the contour in which the function's formal | |
10435 | parameters and labels get declared. Curiously, it appears that the front | |
10436 | end doesn't actually put the PARM_DECL nodes for the current function onto | |
10437 | the BLOCK_VARS list for this outer scope, but are strung off of the | |
10438 | DECL_ARGUMENTS list for the function instead. | |
10439 | ||
10440 | The BLOCK_VARS list for the `outer_scope' does provide us with a list of | |
10441 | the LABEL_DECL nodes for the function however, and we output DWARF info | |
10442 | for those in decls_for_scope. Just within the `outer_scope' there will be | |
10443 | a BLOCK node representing the function's outermost pair of curly braces, | |
10444 | and any blocks used for the base and member initializers of a C++ | |
d7248bff | 10445 | constructor function. */ |
4edb7b60 | 10446 | if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK) |
7e23cb16 JM |
10447 | { |
10448 | current_function_has_inlines = 0; | |
10449 | decls_for_scope (outer_scope, subr_die, 0); | |
71dfc51f | 10450 | |
ce61cc73 | 10451 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
7e23cb16 JM |
10452 | if (current_function_has_inlines) |
10453 | { | |
10454 | add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1); | |
10455 | if (! comp_unit_has_inlines) | |
10456 | { | |
10457 | add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1); | |
10458 | comp_unit_has_inlines = 1; | |
10459 | } | |
10460 | } | |
10461 | #endif | |
10462 | } | |
a3f97cbb JW |
10463 | } |
10464 | ||
10465 | /* Generate a DIE to represent a declared data object. */ | |
71dfc51f | 10466 | |
a3f97cbb JW |
10467 | static void |
10468 | gen_variable_die (decl, context_die) | |
b3694847 SS |
10469 | tree decl; |
10470 | dw_die_ref context_die; | |
a3f97cbb | 10471 | { |
b3694847 | 10472 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 10473 | dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl); |
71dfc51f | 10474 | |
bdb669cb | 10475 | dw_die_ref old_die = lookup_decl_die (decl); |
9765e357 JM |
10476 | int declaration = (DECL_EXTERNAL (decl) |
10477 | || class_scope_p (context_die)); | |
4edb7b60 | 10478 | |
a3f97cbb | 10479 | if (origin != NULL) |
71dfc51f | 10480 | add_abstract_origin_attribute (var_die, origin); |
2ad9852d | 10481 | |
f76b8156 | 10482 | /* Loop unrolling can create multiple blocks that refer to the same |
2ad9852d RK |
10483 | static variable, so we must test for the DW_AT_declaration flag. |
10484 | ||
10485 | ??? Loop unrolling/reorder_blocks should perhaps be rewritten to | |
f76b8156 | 10486 | copy decls and set the DECL_ABSTRACT flag on them instead of |
2ad9852d RK |
10487 | sharing them. |
10488 | ||
10489 | ??? Duplicated blocks have been rewritten to use .debug_ranges. */ | |
f76b8156 | 10490 | else if (old_die && TREE_STATIC (decl) |
c26fbbca | 10491 | && get_AT_flag (old_die, DW_AT_declaration) == 1) |
bdb669cb | 10492 | { |
e689ae67 | 10493 | /* This is a definition of a C++ class level static. */ |
bdb669cb JM |
10494 | add_AT_die_ref (var_die, DW_AT_specification, old_die); |
10495 | if (DECL_NAME (decl)) | |
10496 | { | |
981975b6 | 10497 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
71dfc51f | 10498 | |
bdb669cb JM |
10499 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
10500 | add_AT_unsigned (var_die, DW_AT_decl_file, file_index); | |
71dfc51f | 10501 | |
bdb669cb | 10502 | if (get_AT_unsigned (old_die, DW_AT_decl_line) |
556273e0 | 10503 | != (unsigned) DECL_SOURCE_LINE (decl)) |
71dfc51f RK |
10504 | |
10505 | add_AT_unsigned (var_die, DW_AT_decl_line, | |
10506 | DECL_SOURCE_LINE (decl)); | |
bdb669cb JM |
10507 | } |
10508 | } | |
a3f97cbb JW |
10509 | else |
10510 | { | |
10511 | add_name_and_src_coords_attributes (var_die, decl); | |
2ad9852d | 10512 | add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl), |
a3f97cbb | 10513 | TREE_THIS_VOLATILE (decl), context_die); |
71dfc51f | 10514 | |
273dbe67 JM |
10515 | if (TREE_PUBLIC (decl)) |
10516 | add_AT_flag (var_die, DW_AT_external, 1); | |
71dfc51f | 10517 | |
273dbe67 JM |
10518 | if (DECL_ARTIFICIAL (decl)) |
10519 | add_AT_flag (var_die, DW_AT_artificial, 1); | |
71dfc51f | 10520 | |
a94dbf2c JM |
10521 | if (TREE_PROTECTED (decl)) |
10522 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected); | |
10523 | else if (TREE_PRIVATE (decl)) | |
10524 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 10525 | } |
4edb7b60 JM |
10526 | |
10527 | if (declaration) | |
10528 | add_AT_flag (var_die, DW_AT_declaration, 1); | |
556273e0 | 10529 | |
9765e357 | 10530 | if (class_scope_p (context_die) || DECL_ABSTRACT (decl)) |
4edb7b60 JM |
10531 | equate_decl_number_to_die (decl, var_die); |
10532 | ||
10533 | if (! declaration && ! DECL_ABSTRACT (decl)) | |
a3f97cbb JW |
10534 | { |
10535 | add_location_or_const_value_attribute (var_die, decl); | |
d291dd49 | 10536 | add_pubname (decl, var_die); |
a3f97cbb | 10537 | } |
1bfb5f8f JM |
10538 | else |
10539 | tree_add_const_value_attribute (var_die, decl); | |
a3f97cbb JW |
10540 | } |
10541 | ||
10542 | /* Generate a DIE to represent a label identifier. */ | |
71dfc51f | 10543 | |
a3f97cbb JW |
10544 | static void |
10545 | gen_label_die (decl, context_die) | |
b3694847 SS |
10546 | tree decl; |
10547 | dw_die_ref context_die; | |
a3f97cbb | 10548 | { |
b3694847 | 10549 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 10550 | dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl); |
b3694847 | 10551 | rtx insn; |
a3f97cbb | 10552 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 10553 | |
a3f97cbb | 10554 | if (origin != NULL) |
71dfc51f | 10555 | add_abstract_origin_attribute (lbl_die, origin); |
a3f97cbb | 10556 | else |
71dfc51f RK |
10557 | add_name_and_src_coords_attributes (lbl_die, decl); |
10558 | ||
a3f97cbb | 10559 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 10560 | equate_decl_number_to_die (decl, lbl_die); |
a3f97cbb JW |
10561 | else |
10562 | { | |
10563 | insn = DECL_RTL (decl); | |
088e7160 NC |
10564 | |
10565 | /* Deleted labels are programmer specified labels which have been | |
10566 | eliminated because of various optimisations. We still emit them | |
10567 | here so that it is possible to put breakpoints on them. */ | |
10568 | if (GET_CODE (insn) == CODE_LABEL | |
10569 | || ((GET_CODE (insn) == NOTE | |
10570 | && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))) | |
a3f97cbb | 10571 | { |
556273e0 KH |
10572 | /* When optimization is enabled (via -O) some parts of the compiler |
10573 | (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which | |
a3f97cbb JW |
10574 | represent source-level labels which were explicitly declared by |
10575 | the user. This really shouldn't be happening though, so catch | |
10576 | it if it ever does happen. */ | |
10577 | if (INSN_DELETED_P (insn)) | |
71dfc51f RK |
10578 | abort (); |
10579 | ||
66234570 | 10580 | ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn)); |
a3f97cbb JW |
10581 | add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); |
10582 | } | |
10583 | } | |
10584 | } | |
10585 | ||
10586 | /* Generate a DIE for a lexical block. */ | |
71dfc51f | 10587 | |
a3f97cbb | 10588 | static void |
d7248bff | 10589 | gen_lexical_block_die (stmt, context_die, depth) |
b3694847 SS |
10590 | tree stmt; |
10591 | dw_die_ref context_die; | |
d7248bff | 10592 | int depth; |
a3f97cbb | 10593 | { |
54ba1f0d | 10594 | dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt); |
a3f97cbb | 10595 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f RK |
10596 | |
10597 | if (! BLOCK_ABSTRACT (stmt)) | |
a3f97cbb | 10598 | { |
a20612aa RH |
10599 | if (BLOCK_FRAGMENT_CHAIN (stmt)) |
10600 | { | |
10601 | tree chain; | |
10602 | ||
2bee6045 | 10603 | add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt)); |
a20612aa RH |
10604 | |
10605 | chain = BLOCK_FRAGMENT_CHAIN (stmt); | |
10606 | do | |
10607 | { | |
10608 | add_ranges (chain); | |
10609 | chain = BLOCK_FRAGMENT_CHAIN (chain); | |
10610 | } | |
10611 | while (chain); | |
10612 | add_ranges (NULL); | |
10613 | } | |
10614 | else | |
10615 | { | |
10616 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, | |
10617 | BLOCK_NUMBER (stmt)); | |
10618 | add_AT_lbl_id (stmt_die, DW_AT_low_pc, label); | |
10619 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, | |
10620 | BLOCK_NUMBER (stmt)); | |
10621 | add_AT_lbl_id (stmt_die, DW_AT_high_pc, label); | |
10622 | } | |
a3f97cbb | 10623 | } |
71dfc51f | 10624 | |
d7248bff | 10625 | decls_for_scope (stmt, stmt_die, depth); |
a3f97cbb JW |
10626 | } |
10627 | ||
10628 | /* Generate a DIE for an inlined subprogram. */ | |
71dfc51f | 10629 | |
a3f97cbb | 10630 | static void |
d7248bff | 10631 | gen_inlined_subroutine_die (stmt, context_die, depth) |
b3694847 SS |
10632 | tree stmt; |
10633 | dw_die_ref context_die; | |
d7248bff | 10634 | int depth; |
a3f97cbb | 10635 | { |
71dfc51f | 10636 | if (! BLOCK_ABSTRACT (stmt)) |
a3f97cbb | 10637 | { |
b3694847 | 10638 | dw_die_ref subr_die |
54ba1f0d | 10639 | = new_die (DW_TAG_inlined_subroutine, context_die, stmt); |
b3694847 | 10640 | tree decl = block_ultimate_origin (stmt); |
d7248bff | 10641 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 10642 | |
10a11b75 | 10643 | /* Emit info for the abstract instance first, if we haven't yet. */ |
1edf43d6 | 10644 | dwarf2out_abstract_function (decl); |
10a11b75 | 10645 | |
ab72d377 | 10646 | add_abstract_origin_attribute (subr_die, decl); |
5c90448c | 10647 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
18c038b9 | 10648 | BLOCK_NUMBER (stmt)); |
a3f97cbb | 10649 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label); |
18c038b9 MM |
10650 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, |
10651 | BLOCK_NUMBER (stmt)); | |
a3f97cbb | 10652 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label); |
d7248bff | 10653 | decls_for_scope (stmt, subr_die, depth); |
7e23cb16 | 10654 | current_function_has_inlines = 1; |
a3f97cbb | 10655 | } |
06e224f7 AO |
10656 | else |
10657 | /* We may get here if we're the outer block of function A that was | |
10658 | inlined into function B that was inlined into function C. When | |
10659 | generating debugging info for C, dwarf2out_abstract_function(B) | |
10660 | would mark all inlined blocks as abstract, including this one. | |
10661 | So, we wouldn't (and shouldn't) expect labels to be generated | |
10662 | for this one. Instead, just emit debugging info for | |
10663 | declarations within the block. This is particularly important | |
10664 | in the case of initializers of arguments passed from B to us: | |
10665 | if they're statement expressions containing declarations, we | |
10666 | wouldn't generate dies for their abstract variables, and then, | |
10667 | when generating dies for the real variables, we'd die (pun | |
10668 | intended :-) */ | |
10669 | gen_lexical_block_die (stmt, context_die, depth); | |
a3f97cbb JW |
10670 | } |
10671 | ||
10672 | /* Generate a DIE for a field in a record, or structure. */ | |
71dfc51f | 10673 | |
a3f97cbb JW |
10674 | static void |
10675 | gen_field_die (decl, context_die) | |
b3694847 SS |
10676 | tree decl; |
10677 | dw_die_ref context_die; | |
a3f97cbb | 10678 | { |
54ba1f0d | 10679 | dw_die_ref decl_die = new_die (DW_TAG_member, context_die, decl); |
71dfc51f | 10680 | |
a3f97cbb | 10681 | add_name_and_src_coords_attributes (decl_die, decl); |
a3f97cbb JW |
10682 | add_type_attribute (decl_die, member_declared_type (decl), |
10683 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl), | |
10684 | context_die); | |
71dfc51f | 10685 | |
a3f97cbb JW |
10686 | if (DECL_BIT_FIELD_TYPE (decl)) |
10687 | { | |
10688 | add_byte_size_attribute (decl_die, decl); | |
10689 | add_bit_size_attribute (decl_die, decl); | |
10690 | add_bit_offset_attribute (decl_die, decl); | |
10691 | } | |
71dfc51f | 10692 | |
a94dbf2c JM |
10693 | if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE) |
10694 | add_data_member_location_attribute (decl_die, decl); | |
71dfc51f | 10695 | |
273dbe67 JM |
10696 | if (DECL_ARTIFICIAL (decl)) |
10697 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
71dfc51f | 10698 | |
a94dbf2c JM |
10699 | if (TREE_PROTECTED (decl)) |
10700 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected); | |
10701 | else if (TREE_PRIVATE (decl)) | |
10702 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb JW |
10703 | } |
10704 | ||
ab72d377 JM |
10705 | #if 0 |
10706 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. | |
10707 | Use modified_type_die instead. | |
a3f97cbb JW |
10708 | We keep this code here just in case these types of DIEs may be needed to |
10709 | represent certain things in other languages (e.g. Pascal) someday. */ | |
2ad9852d | 10710 | |
a3f97cbb JW |
10711 | static void |
10712 | gen_pointer_type_die (type, context_die) | |
b3694847 SS |
10713 | tree type; |
10714 | dw_die_ref context_die; | |
a3f97cbb | 10715 | { |
b3694847 | 10716 | dw_die_ref ptr_die |
54ba1f0d | 10717 | = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type); |
71dfc51f | 10718 | |
a3f97cbb | 10719 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 10720 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 10721 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb JW |
10722 | } |
10723 | ||
ab72d377 JM |
10724 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. |
10725 | Use modified_type_die instead. | |
a3f97cbb JW |
10726 | We keep this code here just in case these types of DIEs may be needed to |
10727 | represent certain things in other languages (e.g. Pascal) someday. */ | |
2ad9852d | 10728 | |
a3f97cbb JW |
10729 | static void |
10730 | gen_reference_type_die (type, context_die) | |
b3694847 SS |
10731 | tree type; |
10732 | dw_die_ref context_die; | |
a3f97cbb | 10733 | { |
b3694847 | 10734 | dw_die_ref ref_die |
54ba1f0d | 10735 | = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type); |
71dfc51f | 10736 | |
a3f97cbb | 10737 | equate_type_number_to_die (type, ref_die); |
a3f97cbb | 10738 | add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 10739 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb | 10740 | } |
ab72d377 | 10741 | #endif |
a3f97cbb JW |
10742 | |
10743 | /* Generate a DIE for a pointer to a member type. */ | |
2ad9852d | 10744 | |
a3f97cbb JW |
10745 | static void |
10746 | gen_ptr_to_mbr_type_die (type, context_die) | |
b3694847 SS |
10747 | tree type; |
10748 | dw_die_ref context_die; | |
a3f97cbb | 10749 | { |
b3694847 | 10750 | dw_die_ref ptr_die |
54ba1f0d RH |
10751 | = new_die (DW_TAG_ptr_to_member_type, |
10752 | scope_die_for (type, context_die), type); | |
71dfc51f | 10753 | |
a3f97cbb | 10754 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 10755 | add_AT_die_ref (ptr_die, DW_AT_containing_type, |
bdb669cb | 10756 | lookup_type_die (TYPE_OFFSET_BASETYPE (type))); |
a3f97cbb JW |
10757 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
10758 | } | |
10759 | ||
10760 | /* Generate the DIE for the compilation unit. */ | |
71dfc51f | 10761 | |
a96c67ec JM |
10762 | static dw_die_ref |
10763 | gen_compile_unit_die (filename) | |
b3694847 | 10764 | const char *filename; |
a3f97cbb | 10765 | { |
b3694847 | 10766 | dw_die_ref die; |
a3f97cbb | 10767 | char producer[250]; |
d3e3972c | 10768 | const char *wd = getpwd (); |
3ac88239 | 10769 | const char *language_string = lang_hooks.name; |
a96c67ec | 10770 | int language; |
a3f97cbb | 10771 | |
54ba1f0d | 10772 | die = new_die (DW_TAG_compile_unit, NULL, NULL); |
a96c67ec | 10773 | add_name_attribute (die, filename); |
bdb669cb | 10774 | |
a96c67ec JM |
10775 | if (wd != NULL && filename[0] != DIR_SEPARATOR) |
10776 | add_AT_string (die, DW_AT_comp_dir, wd); | |
a3f97cbb JW |
10777 | |
10778 | sprintf (producer, "%s %s", language_string, version_string); | |
10779 | ||
10780 | #ifdef MIPS_DEBUGGING_INFO | |
10781 | /* The MIPS/SGI compilers place the 'cc' command line options in the producer | |
10782 | string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do | |
10783 | not appear in the producer string, the debugger reaches the conclusion | |
10784 | that the object file is stripped and has no debugging information. | |
10785 | To get the MIPS/SGI debugger to believe that there is debugging | |
10786 | information in the object file, we add a -g to the producer string. */ | |
4927276d JM |
10787 | if (debug_info_level > DINFO_LEVEL_TERSE) |
10788 | strcat (producer, " -g"); | |
a3f97cbb JW |
10789 | #endif |
10790 | ||
a96c67ec | 10791 | add_AT_string (die, DW_AT_producer, producer); |
a9d38797 | 10792 | |
a3f97cbb | 10793 | if (strcmp (language_string, "GNU C++") == 0) |
a96c67ec | 10794 | language = DW_LANG_C_plus_plus; |
a3f97cbb | 10795 | else if (strcmp (language_string, "GNU Ada") == 0) |
a96c67ec | 10796 | language = DW_LANG_Ada83; |
a9d38797 | 10797 | else if (strcmp (language_string, "GNU F77") == 0) |
a96c67ec | 10798 | language = DW_LANG_Fortran77; |
bc28c45b | 10799 | else if (strcmp (language_string, "GNU Pascal") == 0) |
a96c67ec | 10800 | language = DW_LANG_Pascal83; |
28985b81 AG |
10801 | else if (strcmp (language_string, "GNU Java") == 0) |
10802 | language = DW_LANG_Java; | |
a3f97cbb | 10803 | else |
a96c67ec | 10804 | language = DW_LANG_C89; |
a9d38797 | 10805 | |
a96c67ec | 10806 | add_AT_unsigned (die, DW_AT_language, language); |
a96c67ec | 10807 | return die; |
a3f97cbb JW |
10808 | } |
10809 | ||
10810 | /* Generate a DIE for a string type. */ | |
71dfc51f | 10811 | |
a3f97cbb JW |
10812 | static void |
10813 | gen_string_type_die (type, context_die) | |
b3694847 SS |
10814 | tree type; |
10815 | dw_die_ref context_die; | |
a3f97cbb | 10816 | { |
b3694847 | 10817 | dw_die_ref type_die |
54ba1f0d | 10818 | = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type); |
71dfc51f | 10819 | |
bdb669cb | 10820 | equate_type_number_to_die (type, type_die); |
a3f97cbb | 10821 | |
2ad9852d RK |
10822 | /* ??? Fudge the string length attribute for now. |
10823 | TODO: add string length info. */ | |
10824 | #if 0 | |
10825 | string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type))); | |
10826 | bound_representation (upper_bound, 0, 'u'); | |
10827 | #endif | |
a3f97cbb JW |
10828 | } |
10829 | ||
61b32c02 | 10830 | /* Generate the DIE for a base class. */ |
71dfc51f | 10831 | |
61b32c02 JM |
10832 | static void |
10833 | gen_inheritance_die (binfo, context_die) | |
b3694847 SS |
10834 | tree binfo; |
10835 | dw_die_ref context_die; | |
61b32c02 | 10836 | { |
54ba1f0d | 10837 | dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo); |
71dfc51f | 10838 | |
61b32c02 JM |
10839 | add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die); |
10840 | add_data_member_location_attribute (die, binfo); | |
71dfc51f | 10841 | |
61b32c02 JM |
10842 | if (TREE_VIA_VIRTUAL (binfo)) |
10843 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); | |
2ad9852d | 10844 | |
61b32c02 JM |
10845 | if (TREE_VIA_PUBLIC (binfo)) |
10846 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public); | |
10847 | else if (TREE_VIA_PROTECTED (binfo)) | |
10848 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected); | |
10849 | } | |
10850 | ||
956d6950 | 10851 | /* Generate a DIE for a class member. */ |
71dfc51f | 10852 | |
a3f97cbb JW |
10853 | static void |
10854 | gen_member_die (type, context_die) | |
b3694847 SS |
10855 | tree type; |
10856 | dw_die_ref context_die; | |
a3f97cbb | 10857 | { |
b3694847 | 10858 | tree member; |
10a11b75 | 10859 | dw_die_ref child; |
71dfc51f | 10860 | |
a3f97cbb JW |
10861 | /* If this is not an incomplete type, output descriptions of each of its |
10862 | members. Note that as we output the DIEs necessary to represent the | |
10863 | members of this record or union type, we will also be trying to output | |
10864 | DIEs to represent the *types* of those members. However the `type' | |
556273e0 | 10865 | function (above) will specifically avoid generating type DIEs for member |
eaec9b3d | 10866 | types *within* the list of member DIEs for this (containing) type except |
a3f97cbb JW |
10867 | for those types (of members) which are explicitly marked as also being |
10868 | members of this (containing) type themselves. The g++ front- end can | |
2ad9852d RK |
10869 | force any given type to be treated as a member of some other (containing) |
10870 | type by setting the TYPE_CONTEXT of the given (member) type to point to | |
10871 | the TREE node representing the appropriate (containing) type. */ | |
a3f97cbb | 10872 | |
61b32c02 JM |
10873 | /* First output info about the base classes. */ |
10874 | if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type)) | |
a3f97cbb | 10875 | { |
b3694847 SS |
10876 | tree bases = TYPE_BINFO_BASETYPES (type); |
10877 | int n_bases = TREE_VEC_LENGTH (bases); | |
10878 | int i; | |
61b32c02 JM |
10879 | |
10880 | for (i = 0; i < n_bases; i++) | |
10881 | gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die); | |
a3f97cbb JW |
10882 | } |
10883 | ||
61b32c02 JM |
10884 | /* Now output info about the data members and type members. */ |
10885 | for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member)) | |
10a11b75 JM |
10886 | { |
10887 | /* If we thought we were generating minimal debug info for TYPE | |
10888 | and then changed our minds, some of the member declarations | |
10889 | may have already been defined. Don't define them again, but | |
10890 | do put them in the right order. */ | |
10891 | ||
10892 | child = lookup_decl_die (member); | |
10893 | if (child) | |
10894 | splice_child_die (context_die, child); | |
10895 | else | |
10896 | gen_decl_die (member, context_die); | |
10897 | } | |
61b32c02 | 10898 | |
a3f97cbb | 10899 | /* Now output info about the function members (if any). */ |
61b32c02 | 10900 | for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member)) |
10a11b75 | 10901 | { |
5daf7c0a JM |
10902 | /* Don't include clones in the member list. */ |
10903 | if (DECL_ABSTRACT_ORIGIN (member)) | |
10904 | continue; | |
10905 | ||
10a11b75 JM |
10906 | child = lookup_decl_die (member); |
10907 | if (child) | |
10908 | splice_child_die (context_die, child); | |
10909 | else | |
10910 | gen_decl_die (member, context_die); | |
10911 | } | |
a3f97cbb JW |
10912 | } |
10913 | ||
10a11b75 JM |
10914 | /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG |
10915 | is set, we pretend that the type was never defined, so we only get the | |
10916 | member DIEs needed by later specification DIEs. */ | |
71dfc51f | 10917 | |
a3f97cbb | 10918 | static void |
273dbe67 | 10919 | gen_struct_or_union_type_die (type, context_die) |
b3694847 SS |
10920 | tree type; |
10921 | dw_die_ref context_die; | |
a3f97cbb | 10922 | { |
b3694847 SS |
10923 | dw_die_ref type_die = lookup_type_die (type); |
10924 | dw_die_ref scope_die = 0; | |
10925 | int nested = 0; | |
10a11b75 | 10926 | int complete = (TYPE_SIZE (type) |
65e1263a JW |
10927 | && (! TYPE_STUB_DECL (type) |
10928 | || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)))); | |
273dbe67 | 10929 | |
10a11b75 | 10930 | if (type_die && ! complete) |
273dbe67 | 10931 | return; |
a082c85a | 10932 | |
71dfc51f | 10933 | if (TYPE_CONTEXT (type) != NULL_TREE |
5f2f160c | 10934 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))) |
a082c85a JM |
10935 | nested = 1; |
10936 | ||
a94dbf2c | 10937 | scope_die = scope_die_for (type, context_die); |
a082c85a JM |
10938 | |
10939 | if (! type_die || (nested && scope_die == comp_unit_die)) | |
273dbe67 | 10940 | /* First occurrence of type or toplevel definition of nested class. */ |
a3f97cbb | 10941 | { |
b3694847 | 10942 | dw_die_ref old_die = type_die; |
71dfc51f | 10943 | |
a3f97cbb JW |
10944 | type_die = new_die (TREE_CODE (type) == RECORD_TYPE |
10945 | ? DW_TAG_structure_type : DW_TAG_union_type, | |
54ba1f0d | 10946 | scope_die, type); |
a3f97cbb | 10947 | equate_type_number_to_die (type, type_die); |
273dbe67 JM |
10948 | if (old_die) |
10949 | add_AT_die_ref (type_die, DW_AT_specification, old_die); | |
5de0e8d4 JM |
10950 | else |
10951 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 10952 | } |
4b674448 | 10953 | else |
273dbe67 | 10954 | remove_AT (type_die, DW_AT_declaration); |
a3f97cbb JW |
10955 | |
10956 | /* If this type has been completed, then give it a byte_size attribute and | |
10957 | then give a list of members. */ | |
2081603c | 10958 | if (complete) |
a3f97cbb | 10959 | { |
556273e0 | 10960 | /* Prevent infinite recursion in cases where the type of some member of |
a3f97cbb JW |
10961 | this type is expressed in terms of this type itself. */ |
10962 | TREE_ASM_WRITTEN (type) = 1; | |
273dbe67 | 10963 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 10964 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 10965 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 10966 | |
ef76d03b JW |
10967 | /* If the first reference to this type was as the return type of an |
10968 | inline function, then it may not have a parent. Fix this now. */ | |
10969 | if (type_die->die_parent == NULL) | |
10970 | add_child_die (scope_die, type_die); | |
10971 | ||
273dbe67 JM |
10972 | push_decl_scope (type); |
10973 | gen_member_die (type, type_die); | |
10974 | pop_decl_scope (); | |
71dfc51f | 10975 | |
a94dbf2c JM |
10976 | /* GNU extension: Record what type our vtable lives in. */ |
10977 | if (TYPE_VFIELD (type)) | |
10978 | { | |
10979 | tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type)); | |
71dfc51f | 10980 | |
de6e505e JM |
10981 | gen_type_die (vtype, context_die); |
10982 | add_AT_die_ref (type_die, DW_AT_containing_type, | |
10983 | lookup_type_die (vtype)); | |
a94dbf2c | 10984 | } |
a3f97cbb | 10985 | } |
4b674448 | 10986 | else |
8a8c3656 JM |
10987 | { |
10988 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a30d4514 | 10989 | |
9765e357 | 10990 | /* We don't need to do this for function-local types. */ |
9702143f RK |
10991 | if (TYPE_STUB_DECL (type) |
10992 | && ! decl_function_context (TYPE_STUB_DECL (type))) | |
2ad9852d | 10993 | VARRAY_PUSH_TREE (incomplete_types, type); |
8a8c3656 | 10994 | } |
a3f97cbb JW |
10995 | } |
10996 | ||
10997 | /* Generate a DIE for a subroutine _type_. */ | |
71dfc51f | 10998 | |
a3f97cbb JW |
10999 | static void |
11000 | gen_subroutine_type_die (type, context_die) | |
b3694847 SS |
11001 | tree type; |
11002 | dw_die_ref context_die; | |
a3f97cbb | 11003 | { |
b3694847 SS |
11004 | tree return_type = TREE_TYPE (type); |
11005 | dw_die_ref subr_die | |
54ba1f0d RH |
11006 | = new_die (DW_TAG_subroutine_type, |
11007 | scope_die_for (type, context_die), type); | |
71dfc51f | 11008 | |
a3f97cbb JW |
11009 | equate_type_number_to_die (type, subr_die); |
11010 | add_prototyped_attribute (subr_die, type); | |
a3f97cbb | 11011 | add_type_attribute (subr_die, return_type, 0, 0, context_die); |
a94dbf2c | 11012 | gen_formal_types_die (type, subr_die); |
a3f97cbb JW |
11013 | } |
11014 | ||
11015 | /* Generate a DIE for a type definition */ | |
71dfc51f | 11016 | |
a3f97cbb JW |
11017 | static void |
11018 | gen_typedef_die (decl, context_die) | |
b3694847 SS |
11019 | tree decl; |
11020 | dw_die_ref context_die; | |
a3f97cbb | 11021 | { |
b3694847 SS |
11022 | dw_die_ref type_die; |
11023 | tree origin; | |
a94dbf2c JM |
11024 | |
11025 | if (TREE_ASM_WRITTEN (decl)) | |
11026 | return; | |
a94dbf2c | 11027 | |
2ad9852d | 11028 | TREE_ASM_WRITTEN (decl) = 1; |
54ba1f0d | 11029 | type_die = new_die (DW_TAG_typedef, context_die, decl); |
a94dbf2c | 11030 | origin = decl_ultimate_origin (decl); |
a3f97cbb | 11031 | if (origin != NULL) |
a94dbf2c | 11032 | add_abstract_origin_attribute (type_die, origin); |
a3f97cbb JW |
11033 | else |
11034 | { | |
b3694847 | 11035 | tree type; |
2ad9852d | 11036 | |
a3f97cbb | 11037 | add_name_and_src_coords_attributes (type_die, decl); |
a94dbf2c JM |
11038 | if (DECL_ORIGINAL_TYPE (decl)) |
11039 | { | |
11040 | type = DECL_ORIGINAL_TYPE (decl); | |
62e3bf54 JM |
11041 | |
11042 | if (type == TREE_TYPE (decl)) | |
11043 | abort (); | |
11044 | else | |
11045 | equate_type_number_to_die (TREE_TYPE (decl), type_die); | |
a94dbf2c JM |
11046 | } |
11047 | else | |
11048 | type = TREE_TYPE (decl); | |
2ad9852d | 11049 | |
a94dbf2c JM |
11050 | add_type_attribute (type_die, type, TREE_READONLY (decl), |
11051 | TREE_THIS_VOLATILE (decl), context_die); | |
a3f97cbb | 11052 | } |
71dfc51f | 11053 | |
a3f97cbb | 11054 | if (DECL_ABSTRACT (decl)) |
a94dbf2c | 11055 | equate_decl_number_to_die (decl, type_die); |
a3f97cbb JW |
11056 | } |
11057 | ||
11058 | /* Generate a type description DIE. */ | |
71dfc51f | 11059 | |
a3f97cbb JW |
11060 | static void |
11061 | gen_type_die (type, context_die) | |
b3694847 SS |
11062 | tree type; |
11063 | dw_die_ref context_die; | |
a3f97cbb | 11064 | { |
348bb3c7 JM |
11065 | int need_pop; |
11066 | ||
71dfc51f RK |
11067 | if (type == NULL_TREE || type == error_mark_node) |
11068 | return; | |
a3f97cbb | 11069 | |
0e98f924 AH |
11070 | /* We are going to output a DIE to represent the unqualified version |
11071 | of this type (i.e. without any const or volatile qualifiers) so | |
11072 | get the main variant (i.e. the unqualified version) of this type | |
11073 | now. (Vectors are special because the debugging info is in the | |
11074 | cloned type itself). */ | |
11075 | if (TREE_CODE (type) != VECTOR_TYPE) | |
11076 | type = type_main_variant (type); | |
a3f97cbb JW |
11077 | |
11078 | if (TREE_ASM_WRITTEN (type)) | |
71dfc51f | 11079 | return; |
a3f97cbb | 11080 | |
a94dbf2c JM |
11081 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
11082 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
556273e0 | 11083 | { |
29b91443 JM |
11084 | /* Prevent broken recursion; we can't hand off to the same type. */ |
11085 | if (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) == type) | |
11086 | abort (); | |
11087 | ||
a94dbf2c JM |
11088 | TREE_ASM_WRITTEN (type) = 1; |
11089 | gen_decl_die (TYPE_NAME (type), context_die); | |
11090 | return; | |
11091 | } | |
11092 | ||
a3f97cbb JW |
11093 | switch (TREE_CODE (type)) |
11094 | { | |
11095 | case ERROR_MARK: | |
11096 | break; | |
11097 | ||
11098 | case POINTER_TYPE: | |
11099 | case REFERENCE_TYPE: | |
956d6950 JL |
11100 | /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This |
11101 | ensures that the gen_type_die recursion will terminate even if the | |
11102 | type is recursive. Recursive types are possible in Ada. */ | |
11103 | /* ??? We could perhaps do this for all types before the switch | |
11104 | statement. */ | |
11105 | TREE_ASM_WRITTEN (type) = 1; | |
11106 | ||
a3f97cbb JW |
11107 | /* For these types, all that is required is that we output a DIE (or a |
11108 | set of DIEs) to represent the "basis" type. */ | |
11109 | gen_type_die (TREE_TYPE (type), context_die); | |
11110 | break; | |
11111 | ||
11112 | case OFFSET_TYPE: | |
556273e0 | 11113 | /* This code is used for C++ pointer-to-data-member types. |
71dfc51f | 11114 | Output a description of the relevant class type. */ |
a3f97cbb | 11115 | gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die); |
71dfc51f | 11116 | |
a3f97cbb JW |
11117 | /* Output a description of the type of the object pointed to. */ |
11118 | gen_type_die (TREE_TYPE (type), context_die); | |
71dfc51f | 11119 | |
a3f97cbb JW |
11120 | /* Now output a DIE to represent this pointer-to-data-member type |
11121 | itself. */ | |
11122 | gen_ptr_to_mbr_type_die (type, context_die); | |
11123 | break; | |
11124 | ||
11125 | case SET_TYPE: | |
11126 | gen_type_die (TYPE_DOMAIN (type), context_die); | |
11127 | gen_set_type_die (type, context_die); | |
11128 | break; | |
11129 | ||
11130 | case FILE_TYPE: | |
11131 | gen_type_die (TREE_TYPE (type), context_die); | |
11132 | abort (); /* No way to represent these in Dwarf yet! */ | |
11133 | break; | |
11134 | ||
11135 | case FUNCTION_TYPE: | |
11136 | /* Force out return type (in case it wasn't forced out already). */ | |
11137 | gen_type_die (TREE_TYPE (type), context_die); | |
11138 | gen_subroutine_type_die (type, context_die); | |
11139 | break; | |
11140 | ||
11141 | case METHOD_TYPE: | |
11142 | /* Force out return type (in case it wasn't forced out already). */ | |
11143 | gen_type_die (TREE_TYPE (type), context_die); | |
11144 | gen_subroutine_type_die (type, context_die); | |
11145 | break; | |
11146 | ||
11147 | case ARRAY_TYPE: | |
11148 | if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE) | |
11149 | { | |
11150 | gen_type_die (TREE_TYPE (type), context_die); | |
11151 | gen_string_type_die (type, context_die); | |
11152 | } | |
11153 | else | |
71dfc51f | 11154 | gen_array_type_die (type, context_die); |
a3f97cbb JW |
11155 | break; |
11156 | ||
4061f623 | 11157 | case VECTOR_TYPE: |
84f0ace0 | 11158 | gen_array_type_die (type, context_die); |
4061f623 BS |
11159 | break; |
11160 | ||
a3f97cbb JW |
11161 | case ENUMERAL_TYPE: |
11162 | case RECORD_TYPE: | |
11163 | case UNION_TYPE: | |
11164 | case QUAL_UNION_TYPE: | |
2ad9852d RK |
11165 | /* If this is a nested type whose containing class hasn't been written |
11166 | out yet, writing it out will cover this one, too. This does not apply | |
11167 | to instantiations of member class templates; they need to be added to | |
11168 | the containing class as they are generated. FIXME: This hurts the | |
11169 | idea of combining type decls from multiple TUs, since we can't predict | |
11170 | what set of template instantiations we'll get. */ | |
a082c85a | 11171 | if (TYPE_CONTEXT (type) |
5f2f160c | 11172 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) |
a082c85a | 11173 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) |
a94dbf2c JM |
11174 | { |
11175 | gen_type_die (TYPE_CONTEXT (type), context_die); | |
11176 | ||
348bb3c7 | 11177 | if (TREE_ASM_WRITTEN (type)) |
a94dbf2c JM |
11178 | return; |
11179 | ||
11180 | /* If that failed, attach ourselves to the stub. */ | |
11181 | push_decl_scope (TYPE_CONTEXT (type)); | |
11182 | context_die = lookup_type_die (TYPE_CONTEXT (type)); | |
348bb3c7 | 11183 | need_pop = 1; |
a94dbf2c | 11184 | } |
348bb3c7 JM |
11185 | else |
11186 | need_pop = 0; | |
a94dbf2c JM |
11187 | |
11188 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
273dbe67 | 11189 | gen_enumeration_type_die (type, context_die); |
a3f97cbb | 11190 | else |
273dbe67 | 11191 | gen_struct_or_union_type_die (type, context_die); |
4b674448 | 11192 | |
348bb3c7 | 11193 | if (need_pop) |
a94dbf2c JM |
11194 | pop_decl_scope (); |
11195 | ||
4b674448 | 11196 | /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix |
a082c85a JM |
11197 | it up if it is ever completed. gen_*_type_die will set it for us |
11198 | when appropriate. */ | |
11199 | return; | |
a3f97cbb JW |
11200 | |
11201 | case VOID_TYPE: | |
11202 | case INTEGER_TYPE: | |
11203 | case REAL_TYPE: | |
11204 | case COMPLEX_TYPE: | |
11205 | case BOOLEAN_TYPE: | |
11206 | case CHAR_TYPE: | |
11207 | /* No DIEs needed for fundamental types. */ | |
11208 | break; | |
11209 | ||
11210 | case LANG_TYPE: | |
11211 | /* No Dwarf representation currently defined. */ | |
11212 | break; | |
11213 | ||
11214 | default: | |
11215 | abort (); | |
11216 | } | |
11217 | ||
11218 | TREE_ASM_WRITTEN (type) = 1; | |
11219 | } | |
11220 | ||
11221 | /* Generate a DIE for a tagged type instantiation. */ | |
71dfc51f | 11222 | |
a3f97cbb JW |
11223 | static void |
11224 | gen_tagged_type_instantiation_die (type, context_die) | |
b3694847 SS |
11225 | tree type; |
11226 | dw_die_ref context_die; | |
a3f97cbb | 11227 | { |
71dfc51f RK |
11228 | if (type == NULL_TREE || type == error_mark_node) |
11229 | return; | |
a3f97cbb | 11230 | |
38e01259 | 11231 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
11232 | this type (i.e. without any const or volatile qualifiers) so make sure |
11233 | that we have the main variant (i.e. the unqualified version) of this | |
11234 | type now. */ | |
bbc6ae08 | 11235 | if (type != type_main_variant (type)) |
3a88cbd1 | 11236 | abort (); |
a3f97cbb | 11237 | |
203588e7 | 11238 | /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is |
bbc6ae08 | 11239 | an instance of an unresolved type. */ |
556273e0 | 11240 | |
a3f97cbb JW |
11241 | switch (TREE_CODE (type)) |
11242 | { | |
11243 | case ERROR_MARK: | |
11244 | break; | |
11245 | ||
11246 | case ENUMERAL_TYPE: | |
11247 | gen_inlined_enumeration_type_die (type, context_die); | |
11248 | break; | |
11249 | ||
11250 | case RECORD_TYPE: | |
11251 | gen_inlined_structure_type_die (type, context_die); | |
11252 | break; | |
11253 | ||
11254 | case UNION_TYPE: | |
11255 | case QUAL_UNION_TYPE: | |
11256 | gen_inlined_union_type_die (type, context_die); | |
11257 | break; | |
11258 | ||
11259 | default: | |
71dfc51f | 11260 | abort (); |
a3f97cbb JW |
11261 | } |
11262 | } | |
11263 | ||
11264 | /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the | |
11265 | things which are local to the given block. */ | |
71dfc51f | 11266 | |
a3f97cbb | 11267 | static void |
d7248bff | 11268 | gen_block_die (stmt, context_die, depth) |
b3694847 SS |
11269 | tree stmt; |
11270 | dw_die_ref context_die; | |
d7248bff | 11271 | int depth; |
a3f97cbb | 11272 | { |
b3694847 SS |
11273 | int must_output_die = 0; |
11274 | tree origin; | |
11275 | tree decl; | |
11276 | enum tree_code origin_code; | |
a3f97cbb JW |
11277 | |
11278 | /* Ignore blocks never really used to make RTL. */ | |
1e7f092a JM |
11279 | if (stmt == NULL_TREE || !TREE_USED (stmt) |
11280 | || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt))) | |
71dfc51f | 11281 | return; |
a3f97cbb | 11282 | |
a20612aa RH |
11283 | /* If the block is one fragment of a non-contiguous block, do not |
11284 | process the variables, since they will have been done by the | |
11285 | origin block. Do process subblocks. */ | |
11286 | if (BLOCK_FRAGMENT_ORIGIN (stmt)) | |
11287 | { | |
11288 | tree sub; | |
11289 | ||
2ad9852d | 11290 | for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub)) |
a20612aa | 11291 | gen_block_die (sub, context_die, depth + 1); |
2ad9852d | 11292 | |
a20612aa RH |
11293 | return; |
11294 | } | |
11295 | ||
a3f97cbb JW |
11296 | /* Determine the "ultimate origin" of this block. This block may be an |
11297 | inlined instance of an inlined instance of inline function, so we have | |
11298 | to trace all of the way back through the origin chain to find out what | |
11299 | sort of node actually served as the original seed for the creation of | |
11300 | the current block. */ | |
11301 | origin = block_ultimate_origin (stmt); | |
11302 | origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; | |
11303 | ||
11304 | /* Determine if we need to output any Dwarf DIEs at all to represent this | |
11305 | block. */ | |
11306 | if (origin_code == FUNCTION_DECL) | |
71dfc51f RK |
11307 | /* The outer scopes for inlinings *must* always be represented. We |
11308 | generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */ | |
11309 | must_output_die = 1; | |
a3f97cbb JW |
11310 | else |
11311 | { | |
11312 | /* In the case where the current block represents an inlining of the | |
556273e0 | 11313 | "body block" of an inline function, we must *NOT* output any DIE for |
2ad9852d RK |
11314 | this block because we have already output a DIE to represent the whole |
11315 | inlined function scope and the "body block" of any function doesn't | |
11316 | really represent a different scope according to ANSI C rules. So we | |
11317 | check here to make sure that this block does not represent a "body | |
11318 | block inlining" before trying to set the MUST_OUTPUT_DIE flag. */ | |
d7248bff | 11319 | if (! is_body_block (origin ? origin : stmt)) |
a3f97cbb JW |
11320 | { |
11321 | /* Determine if this block directly contains any "significant" | |
11322 | local declarations which we will need to output DIEs for. */ | |
11323 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
71dfc51f RK |
11324 | /* We are not in terse mode so *any* local declaration counts |
11325 | as being a "significant" one. */ | |
11326 | must_output_die = (BLOCK_VARS (stmt) != NULL); | |
a3f97cbb | 11327 | else |
71dfc51f RK |
11328 | /* We are in terse mode, so only local (nested) function |
11329 | definitions count as "significant" local declarations. */ | |
11330 | for (decl = BLOCK_VARS (stmt); | |
11331 | decl != NULL; decl = TREE_CHAIN (decl)) | |
11332 | if (TREE_CODE (decl) == FUNCTION_DECL | |
11333 | && DECL_INITIAL (decl)) | |
a3f97cbb | 11334 | { |
71dfc51f RK |
11335 | must_output_die = 1; |
11336 | break; | |
a3f97cbb | 11337 | } |
a3f97cbb JW |
11338 | } |
11339 | } | |
11340 | ||
11341 | /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block | |
11342 | DIE for any block which contains no significant local declarations at | |
11343 | all. Rather, in such cases we just call `decls_for_scope' so that any | |
11344 | needed Dwarf info for any sub-blocks will get properly generated. Note | |
11345 | that in terse mode, our definition of what constitutes a "significant" | |
11346 | local declaration gets restricted to include only inlined function | |
11347 | instances and local (nested) function definitions. */ | |
11348 | if (must_output_die) | |
11349 | { | |
11350 | if (origin_code == FUNCTION_DECL) | |
71dfc51f | 11351 | gen_inlined_subroutine_die (stmt, context_die, depth); |
a3f97cbb | 11352 | else |
71dfc51f | 11353 | gen_lexical_block_die (stmt, context_die, depth); |
a3f97cbb JW |
11354 | } |
11355 | else | |
d7248bff | 11356 | decls_for_scope (stmt, context_die, depth); |
a3f97cbb JW |
11357 | } |
11358 | ||
11359 | /* Generate all of the decls declared within a given scope and (recursively) | |
9ec36da5 | 11360 | all of its sub-blocks. */ |
71dfc51f | 11361 | |
a3f97cbb | 11362 | static void |
d7248bff | 11363 | decls_for_scope (stmt, context_die, depth) |
b3694847 SS |
11364 | tree stmt; |
11365 | dw_die_ref context_die; | |
d7248bff | 11366 | int depth; |
a3f97cbb | 11367 | { |
b3694847 SS |
11368 | tree decl; |
11369 | tree subblocks; | |
71dfc51f | 11370 | |
a3f97cbb | 11371 | /* Ignore blocks never really used to make RTL. */ |
71dfc51f RK |
11372 | if (stmt == NULL_TREE || ! TREE_USED (stmt)) |
11373 | return; | |
11374 | ||
88dad228 JM |
11375 | /* Output the DIEs to represent all of the data objects and typedefs |
11376 | declared directly within this block but not within any nested | |
11377 | sub-blocks. Also, nested function and tag DIEs have been | |
11378 | generated with a parent of NULL; fix that up now. */ | |
2ad9852d | 11379 | for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl)) |
a3f97cbb | 11380 | { |
b3694847 | 11381 | dw_die_ref die; |
a94dbf2c | 11382 | |
88dad228 | 11383 | if (TREE_CODE (decl) == FUNCTION_DECL) |
a94dbf2c | 11384 | die = lookup_decl_die (decl); |
88dad228 | 11385 | else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)) |
a94dbf2c JM |
11386 | die = lookup_type_die (TREE_TYPE (decl)); |
11387 | else | |
11388 | die = NULL; | |
11389 | ||
71dfc51f | 11390 | if (die != NULL && die->die_parent == NULL) |
ef76d03b | 11391 | add_child_die (context_die, die); |
88dad228 JM |
11392 | else |
11393 | gen_decl_die (decl, context_die); | |
a3f97cbb JW |
11394 | } |
11395 | ||
11396 | /* Output the DIEs to represent all sub-blocks (and the items declared | |
11397 | therein) of this block. */ | |
11398 | for (subblocks = BLOCK_SUBBLOCKS (stmt); | |
11399 | subblocks != NULL; | |
11400 | subblocks = BLOCK_CHAIN (subblocks)) | |
71dfc51f | 11401 | gen_block_die (subblocks, context_die, depth + 1); |
a3f97cbb JW |
11402 | } |
11403 | ||
a94dbf2c | 11404 | /* Is this a typedef we can avoid emitting? */ |
71dfc51f RK |
11405 | |
11406 | static inline int | |
a94dbf2c | 11407 | is_redundant_typedef (decl) |
b3694847 | 11408 | tree decl; |
a94dbf2c JM |
11409 | { |
11410 | if (TYPE_DECL_IS_STUB (decl)) | |
11411 | return 1; | |
71dfc51f | 11412 | |
a94dbf2c JM |
11413 | if (DECL_ARTIFICIAL (decl) |
11414 | && DECL_CONTEXT (decl) | |
11415 | && is_tagged_type (DECL_CONTEXT (decl)) | |
11416 | && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL | |
11417 | && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) | |
11418 | /* Also ignore the artificial member typedef for the class name. */ | |
11419 | return 1; | |
71dfc51f | 11420 | |
a94dbf2c JM |
11421 | return 0; |
11422 | } | |
11423 | ||
a3f97cbb | 11424 | /* Generate Dwarf debug information for a decl described by DECL. */ |
71dfc51f | 11425 | |
a3f97cbb JW |
11426 | static void |
11427 | gen_decl_die (decl, context_die) | |
b3694847 SS |
11428 | tree decl; |
11429 | dw_die_ref context_die; | |
a3f97cbb | 11430 | { |
b3694847 | 11431 | tree origin; |
71dfc51f | 11432 | |
f11c3043 | 11433 | if (DECL_P (decl) && DECL_IGNORED_P (decl)) |
71dfc51f | 11434 | return; |
a3f97cbb | 11435 | |
a3f97cbb JW |
11436 | switch (TREE_CODE (decl)) |
11437 | { | |
2ad9852d RK |
11438 | case ERROR_MARK: |
11439 | break; | |
11440 | ||
a3f97cbb | 11441 | case CONST_DECL: |
556273e0 | 11442 | /* The individual enumerators of an enum type get output when we output |
a3f97cbb JW |
11443 | the Dwarf representation of the relevant enum type itself. */ |
11444 | break; | |
11445 | ||
11446 | case FUNCTION_DECL: | |
4edb7b60 JM |
11447 | /* Don't output any DIEs to represent mere function declarations, |
11448 | unless they are class members or explicit block externs. */ | |
11449 | if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE | |
777ad4c2 | 11450 | && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl))) |
71dfc51f | 11451 | break; |
bdb669cb | 11452 | |
5daf7c0a JM |
11453 | /* If we're emitting a clone, emit info for the abstract instance. */ |
11454 | if (DECL_ORIGIN (decl) != decl) | |
11455 | dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl)); | |
2ad9852d | 11456 | |
1cfdcc15 JM |
11457 | /* If we're emitting an out-of-line copy of an inline function, |
11458 | emit info for the abstract instance and set up to refer to it. */ | |
5daf7c0a JM |
11459 | else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl) |
11460 | && ! class_scope_p (context_die) | |
11461 | /* dwarf2out_abstract_function won't emit a die if this is just | |
11462 | a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in | |
11463 | that case, because that works only if we have a die. */ | |
11464 | && DECL_INITIAL (decl) != NULL_TREE) | |
1cfdcc15 | 11465 | { |
1edf43d6 | 11466 | dwarf2out_abstract_function (decl); |
1cfdcc15 JM |
11467 | set_decl_origin_self (decl); |
11468 | } | |
2ad9852d | 11469 | |
5daf7c0a JM |
11470 | /* Otherwise we're emitting the primary DIE for this decl. */ |
11471 | else if (debug_info_level > DINFO_LEVEL_TERSE) | |
a94dbf2c JM |
11472 | { |
11473 | /* Before we describe the FUNCTION_DECL itself, make sure that we | |
11474 | have described its return type. */ | |
11475 | gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); | |
11476 | ||
2081603c JM |
11477 | /* And its virtual context. */ |
11478 | if (DECL_VINDEX (decl) != NULL_TREE) | |
11479 | gen_type_die (DECL_CONTEXT (decl), context_die); | |
11480 | ||
a94dbf2c JM |
11481 | /* And its containing type. */ |
11482 | origin = decl_class_context (decl); | |
71dfc51f | 11483 | if (origin != NULL_TREE) |
10a11b75 | 11484 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 11485 | } |
a3f97cbb JW |
11486 | |
11487 | /* Now output a DIE to represent the function itself. */ | |
11488 | gen_subprogram_die (decl, context_die); | |
11489 | break; | |
11490 | ||
11491 | case TYPE_DECL: | |
11492 | /* If we are in terse mode, don't generate any DIEs to represent any | |
4927276d | 11493 | actual typedefs. */ |
a3f97cbb | 11494 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 11495 | break; |
a3f97cbb | 11496 | |
2ad9852d RK |
11497 | /* In the special case of a TYPE_DECL node representing the declaration |
11498 | of some type tag, if the given TYPE_DECL is marked as having been | |
11499 | instantiated from some other (original) TYPE_DECL node (e.g. one which | |
11500 | was generated within the original definition of an inline function) we | |
11501 | have to generate a special (abbreviated) DW_TAG_structure_type, | |
11502 | DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */ | |
2081603c | 11503 | if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE) |
a3f97cbb JW |
11504 | { |
11505 | gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die); | |
11506 | break; | |
11507 | } | |
a3f97cbb | 11508 | |
a94dbf2c JM |
11509 | if (is_redundant_typedef (decl)) |
11510 | gen_type_die (TREE_TYPE (decl), context_die); | |
11511 | else | |
71dfc51f RK |
11512 | /* Output a DIE to represent the typedef itself. */ |
11513 | gen_typedef_die (decl, context_die); | |
a3f97cbb JW |
11514 | break; |
11515 | ||
11516 | case LABEL_DECL: | |
11517 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
71dfc51f | 11518 | gen_label_die (decl, context_die); |
a3f97cbb JW |
11519 | break; |
11520 | ||
11521 | case VAR_DECL: | |
11522 | /* If we are in terse mode, don't generate any DIEs to represent any | |
11523 | variable declarations or definitions. */ | |
11524 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 11525 | break; |
a3f97cbb JW |
11526 | |
11527 | /* Output any DIEs that are needed to specify the type of this data | |
11528 | object. */ | |
11529 | gen_type_die (TREE_TYPE (decl), context_die); | |
11530 | ||
a94dbf2c JM |
11531 | /* And its containing type. */ |
11532 | origin = decl_class_context (decl); | |
71dfc51f | 11533 | if (origin != NULL_TREE) |
10a11b75 | 11534 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 11535 | |
a3f97cbb JW |
11536 | /* Now output the DIE to represent the data object itself. This gets |
11537 | complicated because of the possibility that the VAR_DECL really | |
11538 | represents an inlined instance of a formal parameter for an inline | |
11539 | function. */ | |
11540 | origin = decl_ultimate_origin (decl); | |
71dfc51f RK |
11541 | if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL) |
11542 | gen_formal_parameter_die (decl, context_die); | |
a3f97cbb | 11543 | else |
71dfc51f | 11544 | gen_variable_die (decl, context_die); |
a3f97cbb JW |
11545 | break; |
11546 | ||
11547 | case FIELD_DECL: | |
2ad9852d RK |
11548 | /* Ignore the nameless fields that are used to skip bits but handle C++ |
11549 | anonymous unions. */ | |
71dfc51f RK |
11550 | if (DECL_NAME (decl) != NULL_TREE |
11551 | || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE) | |
a3f97cbb JW |
11552 | { |
11553 | gen_type_die (member_declared_type (decl), context_die); | |
11554 | gen_field_die (decl, context_die); | |
11555 | } | |
11556 | break; | |
11557 | ||
11558 | case PARM_DECL: | |
11559 | gen_type_die (TREE_TYPE (decl), context_die); | |
11560 | gen_formal_parameter_die (decl, context_die); | |
11561 | break; | |
11562 | ||
348bb3c7 JM |
11563 | case NAMESPACE_DECL: |
11564 | /* Ignore for now. */ | |
11565 | break; | |
11566 | ||
a3f97cbb JW |
11567 | default: |
11568 | abort (); | |
11569 | } | |
a3f97cbb | 11570 | } |
54ba1f0d RH |
11571 | |
11572 | static void | |
11573 | mark_limbo_die_list (ptr) | |
11574 | void *ptr ATTRIBUTE_UNUSED; | |
11575 | { | |
11576 | limbo_die_node *node; | |
c26fbbca | 11577 | for (node = limbo_die_list; node; node = node->next) |
54ba1f0d RH |
11578 | ggc_mark_tree (node->created_for); |
11579 | } | |
a3f97cbb | 11580 | \f |
14a774a9 RK |
11581 | /* Add Ada "use" clause information for SGI Workshop debugger. */ |
11582 | ||
11583 | void | |
11584 | dwarf2out_add_library_unit_info (filename, context_list) | |
c6991660 KG |
11585 | const char *filename; |
11586 | const char *context_list; | |
14a774a9 RK |
11587 | { |
11588 | unsigned int file_index; | |
11589 | ||
11590 | if (filename != NULL) | |
11591 | { | |
54ba1f0d | 11592 | dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL); |
556273e0 | 11593 | tree context_list_decl |
14a774a9 RK |
11594 | = build_decl (LABEL_DECL, get_identifier (context_list), |
11595 | void_type_node); | |
11596 | ||
11597 | TREE_PUBLIC (context_list_decl) = TRUE; | |
11598 | add_name_attribute (unit_die, context_list); | |
981975b6 | 11599 | file_index = lookup_filename (filename); |
14a774a9 RK |
11600 | add_AT_unsigned (unit_die, DW_AT_decl_file, file_index); |
11601 | add_pubname (context_list_decl, unit_die); | |
11602 | } | |
11603 | } | |
11604 | ||
2ad9852d | 11605 | /* Output debug information for global decl DECL. Called from toplev.c after |
2b85879e | 11606 | compilation proper has finished. */ |
2ad9852d | 11607 | |
2b85879e NB |
11608 | static void |
11609 | dwarf2out_global_decl (decl) | |
11610 | tree decl; | |
11611 | { | |
11612 | /* Output DWARF2 information for file-scope tentative data object | |
2ad9852d RK |
11613 | declarations, file-scope (extern) function declarations (which had no |
11614 | corresponding body) and file-scope tagged type declarations and | |
11615 | definitions which have not yet been forced out. */ | |
2b85879e NB |
11616 | if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)) |
11617 | dwarf2out_decl (decl); | |
11618 | } | |
11619 | ||
71dfc51f RK |
11620 | /* Write the debugging output for DECL. */ |
11621 | ||
a3f97cbb | 11622 | void |
88dad228 | 11623 | dwarf2out_decl (decl) |
b3694847 | 11624 | tree decl; |
a3f97cbb | 11625 | { |
b3694847 | 11626 | dw_die_ref context_die = comp_unit_die; |
88dad228 | 11627 | |
a3f97cbb JW |
11628 | switch (TREE_CODE (decl)) |
11629 | { | |
2ad9852d RK |
11630 | case ERROR_MARK: |
11631 | return; | |
11632 | ||
a3f97cbb | 11633 | case FUNCTION_DECL: |
556273e0 | 11634 | /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a |
a3f97cbb JW |
11635 | builtin function. Explicit programmer-supplied declarations of |
11636 | these same functions should NOT be ignored however. */ | |
9765e357 | 11637 | if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl)) |
b1ccbc24 | 11638 | return; |
a3f97cbb JW |
11639 | |
11640 | /* What we would really like to do here is to filter out all mere | |
11641 | file-scope declarations of file-scope functions which are never | |
11642 | referenced later within this translation unit (and keep all of ones | |
556273e0 KH |
11643 | that *are* referenced later on) but we aren't clairvoyant, so we have |
11644 | no idea which functions will be referenced in the future (i.e. later | |
a3f97cbb | 11645 | on within the current translation unit). So here we just ignore all |
556273e0 | 11646 | file-scope function declarations which are not also definitions. If |
956d6950 | 11647 | and when the debugger needs to know something about these functions, |
556273e0 | 11648 | it will have to hunt around and find the DWARF information associated |
2ad9852d RK |
11649 | with the definition of the function. |
11650 | ||
11651 | We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL | |
11652 | nodes represent definitions and which ones represent mere | |
11653 | declarations. We have to check DECL_INITIAL instead. That's because | |
11654 | the C front-end supports some weird semantics for "extern inline" | |
11655 | function definitions. These can get inlined within the current | |
11656 | translation unit (an thus, we need to generate Dwarf info for their | |
11657 | abstract instances so that the Dwarf info for the concrete inlined | |
11658 | instances can have something to refer to) but the compiler never | |
11659 | generates any out-of-lines instances of such things (despite the fact | |
11660 | that they *are* definitions). | |
11661 | ||
11662 | The important point is that the C front-end marks these "extern | |
11663 | inline" functions as DECL_EXTERNAL, but we need to generate DWARF for | |
11664 | them anyway. Note that the C++ front-end also plays some similar games | |
11665 | for inline function definitions appearing within include files which | |
11666 | also contain `#pragma interface' pragmas. */ | |
a3f97cbb | 11667 | if (DECL_INITIAL (decl) == NULL_TREE) |
b1ccbc24 | 11668 | return; |
88dad228 | 11669 | |
9c6cd30e JM |
11670 | /* If we're a nested function, initially use a parent of NULL; if we're |
11671 | a plain function, this will be fixed up in decls_for_scope. If | |
11672 | we're a method, it will be ignored, since we already have a DIE. */ | |
88dad228 | 11673 | if (decl_function_context (decl)) |
9c6cd30e | 11674 | context_die = NULL; |
a3f97cbb JW |
11675 | break; |
11676 | ||
11677 | case VAR_DECL: | |
556273e0 | 11678 | /* Ignore this VAR_DECL if it refers to a file-scope extern data object |
a3f97cbb JW |
11679 | declaration and if the declaration was never even referenced from |
11680 | within this entire compilation unit. We suppress these DIEs in | |
11681 | order to save space in the .debug section (by eliminating entries | |
11682 | which are probably useless). Note that we must not suppress | |
11683 | block-local extern declarations (whether used or not) because that | |
11684 | would screw-up the debugger's name lookup mechanism and cause it to | |
11685 | miss things which really ought to be in scope at a given point. */ | |
11686 | if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) | |
71dfc51f | 11687 | return; |
a3f97cbb JW |
11688 | |
11689 | /* If we are in terse mode, don't generate any DIEs to represent any | |
11690 | variable declarations or definitions. */ | |
11691 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 11692 | return; |
a3f97cbb JW |
11693 | break; |
11694 | ||
11695 | case TYPE_DECL: | |
57fb7689 JM |
11696 | /* Don't emit stubs for types unless they are needed by other DIEs. */ |
11697 | if (TYPE_DECL_SUPPRESS_DEBUG (decl)) | |
11698 | return; | |
11699 | ||
a3f97cbb | 11700 | /* Don't bother trying to generate any DIEs to represent any of the |
a9d38797 JM |
11701 | normal built-in types for the language we are compiling. */ |
11702 | if (DECL_SOURCE_LINE (decl) == 0) | |
a94dbf2c JM |
11703 | { |
11704 | /* OK, we need to generate one for `bool' so GDB knows what type | |
11705 | comparisons have. */ | |
11706 | if ((get_AT_unsigned (comp_unit_die, DW_AT_language) | |
11707 | == DW_LANG_C_plus_plus) | |
f11c3043 RK |
11708 | && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE |
11709 | && ! DECL_IGNORED_P (decl)) | |
a94dbf2c | 11710 | modified_type_die (TREE_TYPE (decl), 0, 0, NULL); |
71dfc51f | 11711 | |
a94dbf2c JM |
11712 | return; |
11713 | } | |
a3f97cbb | 11714 | |
88dad228 | 11715 | /* If we are in terse mode, don't generate any DIEs for types. */ |
a3f97cbb | 11716 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 11717 | return; |
88dad228 JM |
11718 | |
11719 | /* If we're a function-scope tag, initially use a parent of NULL; | |
11720 | this will be fixed up in decls_for_scope. */ | |
11721 | if (decl_function_context (decl)) | |
3f76745e | 11722 | context_die = NULL; |
88dad228 | 11723 | |
a3f97cbb JW |
11724 | break; |
11725 | ||
11726 | default: | |
11727 | return; | |
11728 | } | |
11729 | ||
88dad228 | 11730 | gen_decl_die (decl, context_die); |
a3f97cbb JW |
11731 | } |
11732 | ||
11733 | /* Output a marker (i.e. a label) for the beginning of the generated code for | |
11734 | a lexical block. */ | |
71dfc51f | 11735 | |
a5a42b92 | 11736 | static void |
e2a12aca | 11737 | dwarf2out_begin_block (line, blocknum) |
a5a42b92 NB |
11738 | unsigned int line ATTRIBUTE_UNUSED; |
11739 | unsigned int blocknum; | |
a3f97cbb | 11740 | { |
a3f97cbb | 11741 | function_section (current_function_decl); |
8215347e | 11742 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum); |
a3f97cbb JW |
11743 | } |
11744 | ||
11745 | /* Output a marker (i.e. a label) for the end of the generated code for a | |
11746 | lexical block. */ | |
71dfc51f | 11747 | |
a5a42b92 | 11748 | static void |
e2a12aca | 11749 | dwarf2out_end_block (line, blocknum) |
a5a42b92 NB |
11750 | unsigned int line ATTRIBUTE_UNUSED; |
11751 | unsigned int blocknum; | |
a3f97cbb | 11752 | { |
a3f97cbb | 11753 | function_section (current_function_decl); |
8215347e | 11754 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum); |
a3f97cbb JW |
11755 | } |
11756 | ||
64b59a80 JM |
11757 | /* Returns nonzero if it is appropriate not to emit any debugging |
11758 | information for BLOCK, because it doesn't contain any instructions. | |
fcd7f76b | 11759 | |
64b59a80 JM |
11760 | Don't allow this for blocks with nested functions or local classes |
11761 | as we would end up with orphans, and in the presence of scheduling | |
11762 | we may end up calling them anyway. */ | |
11763 | ||
e1772ac0 | 11764 | static bool |
fcd7f76b JM |
11765 | dwarf2out_ignore_block (block) |
11766 | tree block; | |
11767 | { | |
11768 | tree decl; | |
2ad9852d | 11769 | |
fcd7f76b | 11770 | for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) |
64b59a80 JM |
11771 | if (TREE_CODE (decl) == FUNCTION_DECL |
11772 | || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))) | |
11773 | return 0; | |
2ad9852d | 11774 | |
64b59a80 | 11775 | return 1; |
fcd7f76b JM |
11776 | } |
11777 | ||
2ad9852d | 11778 | /* Lookup FILE_NAME (in the list of filenames that we know about here in |
9a666dda | 11779 | dwarf2out.c) and return its "index". The index of each (known) filename is |
2ad9852d RK |
11780 | just a unique number which is associated with only that one filename. We |
11781 | need such numbers for the sake of generating labels (in the .debug_sfnames | |
11782 | section) and references to those files numbers (in the .debug_srcinfo | |
11783 | and.debug_macinfo sections). If the filename given as an argument is not | |
11784 | found in our current list, add it to the list and assign it the next | |
11785 | available unique index number. In order to speed up searches, we remember | |
11786 | the index of the filename was looked up last. This handles the majority of | |
11787 | all searches. */ | |
71dfc51f | 11788 | |
a3f97cbb | 11789 | static unsigned |
981975b6 | 11790 | lookup_filename (file_name) |
d560ee52 | 11791 | const char *file_name; |
a3f97cbb | 11792 | { |
b3694847 | 11793 | unsigned i; |
a3f97cbb | 11794 | |
981975b6 RH |
11795 | /* ??? Why isn't DECL_SOURCE_FILE left null instead. */ |
11796 | if (strcmp (file_name, "<internal>") == 0 | |
11797 | || strcmp (file_name, "<built-in>") == 0) | |
11798 | return 0; | |
11799 | ||
2e18bbae RH |
11800 | /* Check to see if the file name that was searched on the previous |
11801 | call matches this file name. If so, return the index. */ | |
981975b6 | 11802 | if (file_table.last_lookup_index != 0) |
2ad9852d RK |
11803 | if (0 == strcmp (file_name, |
11804 | file_table.table[file_table.last_lookup_index])) | |
981975b6 | 11805 | return file_table.last_lookup_index; |
a3f97cbb JW |
11806 | |
11807 | /* Didn't match the previous lookup, search the table */ | |
2ad9852d | 11808 | for (i = 1; i < file_table.in_use; i++) |
981975b6 | 11809 | if (strcmp (file_name, file_table.table[i]) == 0) |
71dfc51f | 11810 | { |
981975b6 | 11811 | file_table.last_lookup_index = i; |
71dfc51f RK |
11812 | return i; |
11813 | } | |
a3f97cbb | 11814 | |
556273e0 | 11815 | /* Prepare to add a new table entry by making sure there is enough space in |
a3f97cbb | 11816 | the table to do so. If not, expand the current table. */ |
981975b6 | 11817 | if (i == file_table.allocated) |
a3f97cbb | 11818 | { |
981975b6 RH |
11819 | file_table.allocated = i + FILE_TABLE_INCREMENT; |
11820 | file_table.table = (char **) | |
11821 | xrealloc (file_table.table, file_table.allocated * sizeof (char *)); | |
a3f97cbb JW |
11822 | } |
11823 | ||
71dfc51f | 11824 | /* Add the new entry to the end of the filename table. */ |
981975b6 RH |
11825 | file_table.table[i] = xstrdup (file_name); |
11826 | file_table.in_use = i + 1; | |
11827 | file_table.last_lookup_index = i; | |
2e18bbae | 11828 | |
acc187f5 | 11829 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
211a0cbe GDR |
11830 | { |
11831 | fprintf (asm_out_file, "\t.file %u ", i); | |
11832 | output_quoted_string (asm_out_file, file_name); | |
11833 | fputc ('\n', asm_out_file); | |
11834 | } | |
acc187f5 | 11835 | |
2e18bbae RH |
11836 | return i; |
11837 | } | |
11838 | ||
11839 | static void | |
981975b6 | 11840 | init_file_table () |
2e18bbae RH |
11841 | { |
11842 | /* Allocate the initial hunk of the file_table. */ | |
981975b6 RH |
11843 | file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *)); |
11844 | file_table.allocated = FILE_TABLE_INCREMENT; | |
71dfc51f | 11845 | |
2e18bbae | 11846 | /* Skip the first entry - file numbers begin at 1. */ |
981975b6 RH |
11847 | file_table.in_use = 1; |
11848 | file_table.last_lookup_index = 0; | |
a3f97cbb JW |
11849 | } |
11850 | ||
11851 | /* Output a label to mark the beginning of a source code line entry | |
11852 | and record information relating to this source line, in | |
11853 | 'line_info_table' for later output of the .debug_line section. */ | |
71dfc51f | 11854 | |
e2a12aca | 11855 | static void |
653e276c NB |
11856 | dwarf2out_source_line (line, filename) |
11857 | unsigned int line; | |
b3694847 | 11858 | const char *filename; |
a3f97cbb | 11859 | { |
a3f97cbb JW |
11860 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
11861 | { | |
11862 | function_section (current_function_decl); | |
a3f97cbb | 11863 | |
8aaf55ac JM |
11864 | /* If requested, emit something human-readable. */ |
11865 | if (flag_debug_asm) | |
11866 | fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, | |
11867 | filename, line); | |
11868 | ||
b2244e22 JW |
11869 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
11870 | { | |
981975b6 | 11871 | unsigned file_num = lookup_filename (filename); |
b2244e22 | 11872 | |
981975b6 | 11873 | /* Emit the .loc directive understood by GNU as. */ |
2e18bbae | 11874 | fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line); |
b2244e22 JW |
11875 | |
11876 | /* Indicate that line number info exists. */ | |
2ad9852d | 11877 | line_info_table_in_use++; |
b2244e22 JW |
11878 | |
11879 | /* Indicate that multiple line number tables exist. */ | |
11880 | if (DECL_SECTION_NAME (current_function_decl)) | |
2ad9852d | 11881 | separate_line_info_table_in_use++; |
b2244e22 JW |
11882 | } |
11883 | else if (DECL_SECTION_NAME (current_function_decl)) | |
a3f97cbb | 11884 | { |
b3694847 | 11885 | dw_separate_line_info_ref line_info; |
5c90448c JM |
11886 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL, |
11887 | separate_line_info_table_in_use); | |
e90b62db JM |
11888 | |
11889 | /* expand the line info table if necessary */ | |
11890 | if (separate_line_info_table_in_use | |
11891 | == separate_line_info_table_allocated) | |
11892 | { | |
11893 | separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
11894 | separate_line_info_table | |
71dfc51f RK |
11895 | = (dw_separate_line_info_ref) |
11896 | xrealloc (separate_line_info_table, | |
11897 | separate_line_info_table_allocated | |
11898 | * sizeof (dw_separate_line_info_entry)); | |
e90b62db | 11899 | } |
71dfc51f RK |
11900 | |
11901 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
11902 | line_info |
11903 | = &separate_line_info_table[separate_line_info_table_in_use++]; | |
981975b6 | 11904 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db JM |
11905 | line_info->dw_line_num = line; |
11906 | line_info->function = current_funcdef_number; | |
11907 | } | |
11908 | else | |
11909 | { | |
b3694847 | 11910 | dw_line_info_ref line_info; |
71dfc51f | 11911 | |
5c90448c JM |
11912 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL, |
11913 | line_info_table_in_use); | |
e90b62db | 11914 | |
71dfc51f | 11915 | /* Expand the line info table if necessary. */ |
e90b62db JM |
11916 | if (line_info_table_in_use == line_info_table_allocated) |
11917 | { | |
11918 | line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
11919 | line_info_table | |
71dfc51f RK |
11920 | = (dw_line_info_ref) |
11921 | xrealloc (line_info_table, | |
11922 | (line_info_table_allocated | |
11923 | * sizeof (dw_line_info_entry))); | |
e90b62db | 11924 | } |
71dfc51f RK |
11925 | |
11926 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db | 11927 | line_info = &line_info_table[line_info_table_in_use++]; |
981975b6 | 11928 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db | 11929 | line_info->dw_line_num = line; |
a3f97cbb | 11930 | } |
a3f97cbb JW |
11931 | } |
11932 | } | |
11933 | ||
30f7a378 | 11934 | /* Record the beginning of a new source file. */ |
71dfc51f | 11935 | |
7f905405 | 11936 | static void |
84a5b4f8 | 11937 | dwarf2out_start_source_file (lineno, filename) |
b3694847 SS |
11938 | unsigned int lineno; |
11939 | const char *filename; | |
a3f97cbb | 11940 | { |
881c6935 JM |
11941 | if (flag_eliminate_dwarf2_dups) |
11942 | { | |
11943 | /* Record the beginning of the file for break_out_includes. */ | |
54ba1f0d | 11944 | dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL); |
881c6935 JM |
11945 | add_AT_string (bincl_die, DW_AT_name, filename); |
11946 | } | |
2ad9852d | 11947 | |
84a5b4f8 DB |
11948 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11949 | { | |
715bdd29 | 11950 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 | 11951 | dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file"); |
7c262518 RH |
11952 | dw2_asm_output_data_uleb128 (lineno, "Included from line number %d", |
11953 | lineno); | |
11954 | dw2_asm_output_data_uleb128 (lookup_filename (filename), | |
11955 | "Filename we just started"); | |
84a5b4f8 | 11956 | } |
a3f97cbb JW |
11957 | } |
11958 | ||
cc260610 | 11959 | /* Record the end of a source file. */ |
71dfc51f | 11960 | |
7f905405 NB |
11961 | static void |
11962 | dwarf2out_end_source_file (lineno) | |
11963 | unsigned int lineno ATTRIBUTE_UNUSED; | |
a3f97cbb | 11964 | { |
881c6935 | 11965 | if (flag_eliminate_dwarf2_dups) |
2ad9852d | 11966 | /* Record the end of the file for break_out_includes. */ |
54ba1f0d | 11967 | new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL); |
2ad9852d | 11968 | |
84a5b4f8 DB |
11969 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11970 | { | |
715bdd29 | 11971 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
11972 | dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); |
11973 | } | |
a3f97cbb JW |
11974 | } |
11975 | ||
cc260610 | 11976 | /* Called from debug_define in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
11977 | the tail part of the directive line, i.e. the part which is past the |
11978 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 11979 | |
7f905405 | 11980 | static void |
9a666dda | 11981 | dwarf2out_define (lineno, buffer) |
b3694847 SS |
11982 | unsigned lineno ATTRIBUTE_UNUSED; |
11983 | const char *buffer ATTRIBUTE_UNUSED; | |
a3f97cbb | 11984 | { |
84a5b4f8 DB |
11985 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11986 | { | |
715bdd29 | 11987 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
11988 | dw2_asm_output_data (1, DW_MACINFO_define, "Define macro"); |
11989 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
11990 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
11991 | } | |
a3f97cbb JW |
11992 | } |
11993 | ||
cc260610 | 11994 | /* Called from debug_undef in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
11995 | the tail part of the directive line, i.e. the part which is past the |
11996 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 11997 | |
7f905405 | 11998 | static void |
9a666dda | 11999 | dwarf2out_undef (lineno, buffer) |
b3694847 SS |
12000 | unsigned lineno ATTRIBUTE_UNUSED; |
12001 | const char *buffer ATTRIBUTE_UNUSED; | |
a3f97cbb | 12002 | { |
84a5b4f8 DB |
12003 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12004 | { | |
715bdd29 | 12005 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
12006 | dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro"); |
12007 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
12008 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
12009 | } | |
a3f97cbb JW |
12010 | } |
12011 | ||
12012 | /* Set up for Dwarf output at the start of compilation. */ | |
71dfc51f | 12013 | |
a51d908e | 12014 | static void |
e2a12aca | 12015 | dwarf2out_init (main_input_filename) |
b3694847 | 12016 | const char *main_input_filename; |
a3f97cbb | 12017 | { |
acc187f5 RH |
12018 | init_file_table (); |
12019 | ||
a3f97cbb JW |
12020 | /* Remember the name of the primary input file. */ |
12021 | primary_filename = main_input_filename; | |
12022 | ||
acc187f5 RH |
12023 | /* Add it to the file table first, under the assumption that we'll |
12024 | be emitting line number data for it first, which avoids having | |
12025 | to add an initial DW_LNS_set_file. */ | |
12026 | lookup_filename (main_input_filename); | |
a3f97cbb | 12027 | |
a3f97cbb JW |
12028 | /* Allocate the initial hunk of the decl_die_table. */ |
12029 | decl_die_table | |
3de90026 | 12030 | = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref)); |
a3f97cbb JW |
12031 | decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT; |
12032 | decl_die_table_in_use = 0; | |
12033 | ||
12034 | /* Allocate the initial hunk of the decl_scope_table. */ | |
244a4af0 TF |
12035 | VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table"); |
12036 | ggc_add_tree_varray_root (&decl_scope_table, 1); | |
a3f97cbb JW |
12037 | |
12038 | /* Allocate the initial hunk of the abbrev_die_table. */ | |
12039 | abbrev_die_table | |
3de90026 RH |
12040 | = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT, |
12041 | sizeof (dw_die_ref)); | |
a3f97cbb | 12042 | abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT; |
71dfc51f | 12043 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
12044 | abbrev_die_table_in_use = 1; |
12045 | ||
12046 | /* Allocate the initial hunk of the line_info_table. */ | |
12047 | line_info_table | |
3de90026 RH |
12048 | = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT, |
12049 | sizeof (dw_line_info_entry)); | |
a3f97cbb | 12050 | line_info_table_allocated = LINE_INFO_TABLE_INCREMENT; |
2ad9852d | 12051 | |
71dfc51f | 12052 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
12053 | line_info_table_in_use = 1; |
12054 | ||
556273e0 | 12055 | /* Generate the initial DIE for the .debug section. Note that the (string) |
a3f97cbb | 12056 | value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE |
556273e0 | 12057 | will (typically) be a relative pathname and that this pathname should be |
a3f97cbb JW |
12058 | taken as being relative to the directory from which the compiler was |
12059 | invoked when the given (base) source file was compiled. */ | |
a96c67ec | 12060 | comp_unit_die = gen_compile_unit_die (main_input_filename); |
a3f97cbb | 12061 | |
244a4af0 TF |
12062 | VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types"); |
12063 | ggc_add_tree_varray_root (&incomplete_types, 1); | |
12064 | ||
1f8f4a0b MM |
12065 | VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray"); |
12066 | ggc_add_rtx_varray_root (&used_rtx_varray, 1); | |
1865dbb5 | 12067 | |
54ba1f0d RH |
12068 | ggc_add_root (&limbo_die_list, 1, 1, mark_limbo_die_list); |
12069 | ||
5c90448c | 12070 | ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0); |
9d2f2c45 RH |
12071 | ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, |
12072 | DEBUG_ABBREV_SECTION_LABEL, 0); | |
b366352b MM |
12073 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) |
12074 | ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0); | |
12075 | else | |
f99ffb60 | 12076 | strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME)); |
2ad9852d | 12077 | |
556273e0 | 12078 | ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label, |
8b790721 | 12079 | DEBUG_INFO_SECTION_LABEL, 0); |
556273e0 | 12080 | ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label, |
8b790721 | 12081 | DEBUG_LINE_SECTION_LABEL, 0); |
2bee6045 JJ |
12082 | ASM_GENERATE_INTERNAL_LABEL (ranges_section_label, |
12083 | DEBUG_RANGES_SECTION_LABEL, 0); | |
715bdd29 | 12084 | named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG); |
8b790721 | 12085 | ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label); |
715bdd29 | 12086 | named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG); |
8b790721 | 12087 | ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label); |
715bdd29 | 12088 | named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG); |
8b790721 | 12089 | ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label); |
2ad9852d | 12090 | |
84a5b4f8 DB |
12091 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12092 | { | |
715bdd29 | 12093 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
12094 | ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label, |
12095 | DEBUG_MACINFO_SECTION_LABEL, 0); | |
12096 | ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label); | |
12097 | } | |
7c262518 RH |
12098 | |
12099 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) | |
12100 | { | |
12101 | text_section (); | |
12102 | ASM_OUTPUT_LABEL (asm_out_file, text_section_label); | |
12103 | } | |
a3f97cbb JW |
12104 | } |
12105 | ||
9eb4015a JJ |
12106 | /* Allocate a string in .debug_str hash table. */ |
12107 | ||
12108 | static hashnode | |
12109 | indirect_string_alloc (tab) | |
12110 | hash_table *tab ATTRIBUTE_UNUSED; | |
12111 | { | |
12112 | struct indirect_string_node *node; | |
12113 | ||
12114 | node = xmalloc (sizeof (struct indirect_string_node)); | |
12115 | node->refcount = 0; | |
12116 | node->form = 0; | |
12117 | node->label = NULL; | |
2ad9852d | 12118 | |
9eb4015a JJ |
12119 | return (hashnode) node; |
12120 | } | |
12121 | ||
12122 | /* A helper function for dwarf2out_finish called through | |
12123 | ht_forall. Emit one queued .debug_str string. */ | |
12124 | ||
12125 | static int | |
12126 | output_indirect_string (pfile, h, v) | |
12127 | struct cpp_reader *pfile ATTRIBUTE_UNUSED; | |
12128 | hashnode h; | |
12129 | const PTR v ATTRIBUTE_UNUSED; | |
12130 | { | |
2ad9852d | 12131 | struct indirect_string_node *node = (struct indirect_string_node *) h; |
9eb4015a | 12132 | |
9eb4015a JJ |
12133 | if (node->form == DW_FORM_strp) |
12134 | { | |
12135 | named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS); | |
12136 | ASM_OUTPUT_LABEL (asm_out_file, node->label); | |
12137 | assemble_string ((const char *) HT_STR (&node->id), | |
12138 | HT_LEN (&node->id) + 1); | |
12139 | } | |
2ad9852d | 12140 | |
9eb4015a JJ |
12141 | return 1; |
12142 | } | |
12143 | ||
a3f97cbb JW |
12144 | /* Output stuff that dwarf requires at the end of every file, |
12145 | and generate the DWARF-2 debugging info. */ | |
71dfc51f | 12146 | |
a51d908e | 12147 | static void |
e2a12aca | 12148 | dwarf2out_finish (input_filename) |
b3694847 | 12149 | const char *input_filename ATTRIBUTE_UNUSED; |
a3f97cbb | 12150 | { |
ef76d03b | 12151 | limbo_die_node *node, *next_node; |
ae0ed63a | 12152 | dw_die_ref die = 0; |
ef76d03b JW |
12153 | |
12154 | /* Traverse the limbo die list, and add parent/child links. The only | |
12155 | dies without parents that should be here are concrete instances of | |
12156 | inline functions, and the comp_unit_die. We can ignore the comp_unit_die. | |
12157 | For concrete instances, we can get the parent die from the abstract | |
12158 | instance. */ | |
12159 | for (node = limbo_die_list; node; node = next_node) | |
12160 | { | |
12161 | next_node = node->next; | |
12162 | die = node->die; | |
12163 | ||
12164 | if (die->die_parent == NULL) | |
12165 | { | |
a96c67ec | 12166 | dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin); |
54ba1f0d | 12167 | tree context; |
2ad9852d | 12168 | |
a96c67ec JM |
12169 | if (origin) |
12170 | add_child_die (origin->die_parent, die); | |
ef76d03b | 12171 | else if (die == comp_unit_die) |
a96c67ec | 12172 | ; |
aea9695c RK |
12173 | /* If this was an expression for a bound involved in a function |
12174 | return type, it may be a SAVE_EXPR for which we weren't able | |
12175 | to find a DIE previously. So try now. */ | |
12176 | else if (node->created_for | |
12177 | && TREE_CODE (node->created_for) == SAVE_EXPR | |
12178 | && 0 != (origin = (lookup_decl_die | |
12179 | (SAVE_EXPR_CONTEXT | |
12180 | (node->created_for))))) | |
12181 | add_child_die (origin, die); | |
6bb28965 JM |
12182 | else if (errorcount > 0 || sorrycount > 0) |
12183 | /* It's OK to be confused by errors in the input. */ | |
12184 | add_child_die (comp_unit_die, die); | |
54ba1f0d RH |
12185 | else if (node->created_for |
12186 | && ((DECL_P (node->created_for) | |
c26fbbca | 12187 | && (context = DECL_CONTEXT (node->created_for))) |
54ba1f0d RH |
12188 | || (TYPE_P (node->created_for) |
12189 | && (context = TYPE_CONTEXT (node->created_for)))) | |
12190 | && TREE_CODE (context) == FUNCTION_DECL) | |
12191 | { | |
12192 | /* In certain situations, the lexical block containing a | |
12193 | nested function can be optimized away, which results | |
12194 | in the nested function die being orphaned. Likewise | |
12195 | with the return type of that nested function. Force | |
12196 | this to be a child of the containing function. */ | |
12197 | origin = lookup_decl_die (context); | |
12198 | if (! origin) | |
12199 | abort (); | |
12200 | add_child_die (origin, die); | |
12201 | } | |
ef76d03b JW |
12202 | else |
12203 | abort (); | |
12204 | } | |
2ad9852d | 12205 | |
ef76d03b JW |
12206 | free (node); |
12207 | } | |
2ad9852d | 12208 | |
a96c67ec | 12209 | limbo_die_list = NULL; |
ef76d03b | 12210 | |
8a8c3656 JM |
12211 | /* Walk through the list of incomplete types again, trying once more to |
12212 | emit full debugging info for them. */ | |
12213 | retry_incomplete_types (); | |
12214 | ||
881c6935 JM |
12215 | /* We need to reverse all the dies before break_out_includes, or |
12216 | we'll see the end of an include file before the beginning. */ | |
12217 | reverse_all_dies (comp_unit_die); | |
12218 | ||
12219 | /* Generate separate CUs for each of the include files we've seen. | |
12220 | They will go into limbo_die_list. */ | |
5f632b5e JM |
12221 | if (flag_eliminate_dwarf2_dups) |
12222 | break_out_includes (comp_unit_die); | |
881c6935 JM |
12223 | |
12224 | /* Traverse the DIE's and add add sibling attributes to those DIE's | |
12225 | that have children. */ | |
a3f97cbb | 12226 | add_sibling_attributes (comp_unit_die); |
881c6935 JM |
12227 | for (node = limbo_die_list; node; node = node->next) |
12228 | add_sibling_attributes (node->die); | |
a3f97cbb JW |
12229 | |
12230 | /* Output a terminator label for the .text section. */ | |
7c262518 | 12231 | text_section (); |
5c90448c | 12232 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0); |
a3f97cbb | 12233 | |
db3c0315 MM |
12234 | /* Output the source line correspondence table. We must do this |
12235 | even if there is no line information. Otherwise, on an empty | |
12236 | translation unit, we will generate a present, but empty, | |
12237 | .debug_info section. IRIX 6.5 `nm' will then complain when | |
12238 | examining the file. */ | |
12239 | if (! DWARF2_ASM_LINE_DEBUG_INFO) | |
e90b62db | 12240 | { |
715bdd29 | 12241 | named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG); |
db3c0315 MM |
12242 | output_line_info (); |
12243 | } | |
71dfc51f | 12244 | |
b38a75e5 RH |
12245 | /* Output location list section if necessary. */ |
12246 | if (have_location_lists) | |
12247 | { | |
12248 | /* Output the location lists info. */ | |
12249 | named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG); | |
12250 | ASM_GENERATE_INTERNAL_LABEL (loc_section_label, | |
12251 | DEBUG_LOC_SECTION_LABEL, 0); | |
12252 | ASM_OUTPUT_LABEL (asm_out_file, loc_section_label); | |
12253 | output_location_lists (die); | |
12254 | have_location_lists = 0; | |
12255 | } | |
12256 | ||
db3c0315 MM |
12257 | /* We can only use the low/high_pc attributes if all of the code was |
12258 | in .text. */ | |
12259 | if (separate_line_info_table_in_use == 0) | |
12260 | { | |
12261 | add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label); | |
12262 | add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label); | |
e90b62db | 12263 | } |
2ad9852d RK |
12264 | |
12265 | /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate | |
12266 | "base address". Use zero so that these addresses become absolute. */ | |
a20612aa RH |
12267 | else if (have_location_lists || ranges_table_in_use) |
12268 | add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx); | |
e90b62db | 12269 | |
fe7cd37f RH |
12270 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
12271 | add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list, | |
12272 | debug_line_section_label); | |
db3c0315 | 12273 | |
84a5b4f8 DB |
12274 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12275 | add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label); | |
a96c67ec | 12276 | |
881c6935 JM |
12277 | /* Output all of the compilation units. We put the main one last so that |
12278 | the offsets are available to output_pubnames. */ | |
12279 | for (node = limbo_die_list; node; node = node->next) | |
12280 | output_comp_unit (node->die); | |
2ad9852d | 12281 | |
881c6935 JM |
12282 | output_comp_unit (comp_unit_die); |
12283 | ||
a3f97cbb | 12284 | /* Output the abbreviation table. */ |
715bdd29 | 12285 | named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG); |
a3f97cbb JW |
12286 | output_abbrev_section (); |
12287 | ||
2ad9852d | 12288 | /* Output public names table if necessary. */ |
d291dd49 JM |
12289 | if (pubname_table_in_use) |
12290 | { | |
715bdd29 | 12291 | named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG); |
d291dd49 JM |
12292 | output_pubnames (); |
12293 | } | |
12294 | ||
2ad9852d RK |
12295 | /* Output the address range information. We only put functions in the arange |
12296 | table, so don't write it out if we don't have any. */ | |
a3f97cbb JW |
12297 | if (fde_table_in_use) |
12298 | { | |
715bdd29 | 12299 | named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG); |
a3f97cbb JW |
12300 | output_aranges (); |
12301 | } | |
a20612aa | 12302 | |
a20612aa RH |
12303 | /* Output ranges section if necessary. */ |
12304 | if (ranges_table_in_use) | |
12305 | { | |
715bdd29 | 12306 | named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG); |
2bee6045 | 12307 | ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label); |
a20612aa RH |
12308 | output_ranges (); |
12309 | } | |
12310 | ||
30f7a378 | 12311 | /* Have to end the primary source file. */ |
cc260610 | 12312 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
c26fbbca | 12313 | { |
715bdd29 | 12314 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
cc260610 | 12315 | dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); |
2f8d482e | 12316 | dw2_asm_output_data (1, 0, "End compilation unit"); |
cc260610 | 12317 | } |
9eb4015a | 12318 | |
2ad9852d | 12319 | /* If we emitted any DW_FORM_strp form attribute, output the string |
9eb4015a JJ |
12320 | table too. */ |
12321 | if (debug_str_hash) | |
12322 | ht_forall (debug_str_hash, output_indirect_string, NULL); | |
a3f97cbb | 12323 | } |
f3a8e4f5 | 12324 | #endif /* DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO */ |