]>
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" | |
41 | #include "rtl.h" | |
42 | #include "hard-reg-set.h" | |
43 | #include "regs.h" | |
44 | #include "insn-config.h" | |
45 | #include "reload.h" | |
52a11cbf | 46 | #include "function.h" |
a3f97cbb | 47 | #include "output.h" |
71dfc51f | 48 | #include "expr.h" |
e78d8e51 | 49 | #include "libfuncs.h" |
3f76745e | 50 | #include "except.h" |
a7cc7f29 | 51 | #include "dwarf2.h" |
76ead72b | 52 | #include "dwarf2out.h" |
2e4b9b8c | 53 | #include "dwarf2asm.h" |
10f0ad3d | 54 | #include "toplev.h" |
1865dbb5 | 55 | #include "varray.h" |
951a525f | 56 | #include "ggc.h" |
881c6935 | 57 | #include "md5.h" |
57bed152 | 58 | #include "tm_p.h" |
2a2b2d43 | 59 | #include "diagnostic.h" |
a51d908e | 60 | #include "debug.h" |
07c9d2eb | 61 | #include "target.h" |
3ac88239 | 62 | #include "langhooks.h" |
9eb4015a | 63 | #include "hashtable.h" |
a3f97cbb | 64 | |
653e276c NB |
65 | #ifdef DWARF2_DEBUGGING_INFO |
66 | static void dwarf2out_source_line PARAMS ((unsigned int, const char *)); | |
67 | #endif | |
68 | ||
770ca8c6 JO |
69 | /* DWARF2 Abbreviation Glossary: |
70 | CFA = Canonical Frame Address | |
00a42e21 JM |
71 | a fixed address on the stack which identifies a call frame. |
72 | We define it to be the value of SP just before the call insn. | |
73 | The CFA register and offset, which may change during the course | |
74 | of the function, are used to calculate its value at runtime. | |
a401107d JO |
75 | CFI = Call Frame Instruction |
76 | an instruction for the DWARF2 abstract machine | |
770ca8c6 JO |
77 | CIE = Common Information Entry |
78 | information describing information common to one or more FDEs | |
79 | DIE = Debugging Information Entry | |
80 | FDE = Frame Description Entry | |
81 | information describing the stack call frame, in particular, | |
82 | how to restore registers | |
83 | ||
84 | DW_CFA_... = DWARF2 CFA call frame instruction | |
85 | DW_TAG_... = DWARF2 DIE tag */ | |
86 | ||
0021b564 JM |
87 | /* Decide whether we want to emit frame unwind information for the current |
88 | translation unit. */ | |
89 | ||
90 | int | |
91 | dwarf2out_do_frame () | |
92 | { | |
93 | return (write_symbols == DWARF2_DEBUG | |
7a0c8d71 | 94 | || write_symbols == VMS_AND_DWARF2_DEBUG |
9ec36da5 | 95 | #ifdef DWARF2_FRAME_INFO |
556273e0 | 96 | || DWARF2_FRAME_INFO |
9ec36da5 | 97 | #endif |
0021b564 | 98 | #ifdef DWARF2_UNWIND_INFO |
14a774a9 | 99 | || flag_unwind_tables |
531073e7 | 100 | || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS) |
0021b564 JM |
101 | #endif |
102 | ); | |
103 | } | |
104 | ||
b1e6ab03 RH |
105 | /* The number of the current function definition for which debugging |
106 | information is being generated. These numbers range from 1 up to the | |
107 | maximum number of function definitions contained within the current | |
108 | compilation unit. These numbers are used to create unique label id's | |
109 | unique to each function definition. */ | |
110 | unsigned current_funcdef_number = 0; | |
111 | ||
f3a8e4f5 KG |
112 | /* The size of the target's pointer type. */ |
113 | #ifndef PTR_SIZE | |
114 | #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT) | |
115 | #endif | |
116 | ||
117 | /* Default version of targetm.eh_frame_section. Note this must appear | |
118 | outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro | |
119 | guards. */ | |
120 | ||
121 | void | |
122 | default_eh_frame_section () | |
123 | { | |
124 | #ifdef EH_FRAME_SECTION_NAME | |
125 | named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE); | |
126 | #else | |
127 | tree label = get_file_function_name ('F'); | |
128 | ||
129 | data_section (); | |
130 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); | |
131 | ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); | |
132 | ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); | |
133 | #endif | |
134 | } | |
135 | ||
0021b564 JM |
136 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) |
137 | ||
eaf95893 RK |
138 | /* How to start an assembler comment. */ |
139 | #ifndef ASM_COMMENT_START | |
140 | #define ASM_COMMENT_START ";#" | |
141 | #endif | |
142 | ||
a3f97cbb JW |
143 | typedef struct dw_cfi_struct *dw_cfi_ref; |
144 | typedef struct dw_fde_struct *dw_fde_ref; | |
145 | typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref; | |
a3f97cbb JW |
146 | |
147 | /* Call frames are described using a sequence of Call Frame | |
148 | Information instructions. The register number, offset | |
149 | and address fields are provided as possible operands; | |
150 | their use is selected by the opcode field. */ | |
71dfc51f | 151 | |
a3f97cbb | 152 | typedef union dw_cfi_oprnd_struct |
71dfc51f RK |
153 | { |
154 | unsigned long dw_cfi_reg_num; | |
155 | long int dw_cfi_offset; | |
d3e3972c | 156 | const char *dw_cfi_addr; |
7d9d8943 | 157 | struct dw_loc_descr_struct *dw_cfi_loc; |
71dfc51f | 158 | } |
a3f97cbb JW |
159 | dw_cfi_oprnd; |
160 | ||
161 | typedef struct dw_cfi_struct | |
71dfc51f RK |
162 | { |
163 | dw_cfi_ref dw_cfi_next; | |
164 | enum dwarf_call_frame_info dw_cfi_opc; | |
165 | dw_cfi_oprnd dw_cfi_oprnd1; | |
166 | dw_cfi_oprnd dw_cfi_oprnd2; | |
167 | } | |
a3f97cbb JW |
168 | dw_cfi_node; |
169 | ||
7d9d8943 AM |
170 | /* This is how we define the location of the CFA. We use to handle it |
171 | as REG + OFFSET all the time, but now it can be more complex. | |
172 | It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET. | |
556273e0 | 173 | Instead of passing around REG and OFFSET, we pass a copy |
7d9d8943 AM |
174 | of this structure. */ |
175 | typedef struct cfa_loc | |
176 | { | |
556273e0 | 177 | unsigned long reg; |
7d9d8943 AM |
178 | long offset; |
179 | long base_offset; | |
180 | int indirect; /* 1 if CFA is accessed via a dereference. */ | |
181 | } dw_cfa_location; | |
182 | ||
a3f97cbb | 183 | /* All call frame descriptions (FDE's) in the GCC generated DWARF |
4b674448 | 184 | refer to a single Common Information Entry (CIE), defined at |
fb530c07 | 185 | the beginning of the .debug_frame section. This use of a single |
a3f97cbb JW |
186 | CIE obviates the need to keep track of multiple CIE's |
187 | in the DWARF generation routines below. */ | |
71dfc51f | 188 | |
a3f97cbb | 189 | typedef struct dw_fde_struct |
71dfc51f | 190 | { |
d3e3972c KG |
191 | const char *dw_fde_begin; |
192 | const char *dw_fde_current_label; | |
193 | const char *dw_fde_end; | |
71dfc51f | 194 | dw_cfi_ref dw_fde_cfi; |
52a11cbf RH |
195 | unsigned funcdef_number; |
196 | unsigned nothrow : 1; | |
197 | unsigned uses_eh_lsda : 1; | |
71dfc51f | 198 | } |
a3f97cbb JW |
199 | dw_fde_node; |
200 | ||
6d2f8887 | 201 | /* Maximum size (in bytes) of an artificially generated label. */ |
a3f97cbb JW |
202 | #define MAX_ARTIFICIAL_LABEL_BYTES 30 |
203 | ||
a1a4189d JB |
204 | /* The size of addresses as they appear in the Dwarf 2 data. |
205 | Some architectures use word addresses to refer to code locations, | |
206 | but Dwarf 2 info always uses byte addresses. On such machines, | |
207 | Dwarf 2 addresses need to be larger than the architecture's | |
208 | pointers. */ | |
209 | #ifndef DWARF2_ADDR_SIZE | |
210 | #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT) | |
211 | #endif | |
212 | ||
7e23cb16 | 213 | /* The size in bytes of a DWARF field indicating an offset or length |
a1a4189d JB |
214 | relative to a debug info section, specified to be 4 bytes in the |
215 | DWARF-2 specification. The SGI/MIPS ABI defines it to be the same | |
b13fe8bf | 216 | as PTR_SIZE. */ |
71dfc51f | 217 | |
7e23cb16 JM |
218 | #ifndef DWARF_OFFSET_SIZE |
219 | #define DWARF_OFFSET_SIZE 4 | |
220 | #endif | |
221 | ||
9a666dda JM |
222 | #define DWARF_VERSION 2 |
223 | ||
7e23cb16 JM |
224 | /* Round SIZE up to the nearest BOUNDARY. */ |
225 | #define DWARF_ROUND(SIZE,BOUNDARY) \ | |
262b6384 | 226 | ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY)) |
a3f97cbb | 227 | |
a3f97cbb | 228 | /* Offsets recorded in opcodes are a multiple of this alignment factor. */ |
27c35f4b | 229 | #ifndef DWARF_CIE_DATA_ALIGNMENT |
469ac993 | 230 | #ifdef STACK_GROWS_DOWNWARD |
08cb3d38 | 231 | #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD)) |
469ac993 | 232 | #else |
08cb3d38 | 233 | #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD) |
469ac993 | 234 | #endif |
2ad9852d | 235 | #endif |
a3f97cbb | 236 | |
3f76745e JM |
237 | /* A pointer to the base of a table that contains frame description |
238 | information for each routine. */ | |
239 | static dw_fde_ref fde_table; | |
a3f97cbb | 240 | |
3f76745e JM |
241 | /* Number of elements currently allocated for fde_table. */ |
242 | static unsigned fde_table_allocated; | |
a94dbf2c | 243 | |
3f76745e JM |
244 | /* Number of elements in fde_table currently in use. */ |
245 | static unsigned fde_table_in_use; | |
a3f97cbb | 246 | |
3f76745e JM |
247 | /* Size (in elements) of increments by which we may expand the |
248 | fde_table. */ | |
249 | #define FDE_TABLE_INCREMENT 256 | |
a3f97cbb | 250 | |
a94dbf2c JM |
251 | /* A list of call frame insns for the CIE. */ |
252 | static dw_cfi_ref cie_cfi_head; | |
253 | ||
a3f97cbb JW |
254 | /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram |
255 | attribute that accelerates the lookup of the FDE associated | |
556273e0 | 256 | with the subprogram. This variable holds the table index of the FDE |
a3f97cbb JW |
257 | associated with the current function (body) definition. */ |
258 | static unsigned current_funcdef_fde; | |
259 | ||
9eb4015a JJ |
260 | struct ht *debug_str_hash; |
261 | ||
262 | struct indirect_string_node | |
263 | { | |
264 | struct ht_identifier id; | |
265 | unsigned int refcount; | |
266 | unsigned int form; | |
267 | char *label; | |
268 | }; | |
269 | ||
a3f97cbb | 270 | /* Forward declarations for functions defined in this file. */ |
71dfc51f | 271 | |
83d2b3b9 KG |
272 | static char *stripattributes PARAMS ((const char *)); |
273 | static const char *dwarf_cfi_name PARAMS ((unsigned)); | |
274 | static dw_cfi_ref new_cfi PARAMS ((void)); | |
275 | static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref)); | |
d3e3972c | 276 | static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref)); |
2ad9852d RK |
277 | static void lookup_cfa_1 PARAMS ((dw_cfi_ref, |
278 | dw_cfa_location *)); | |
7d9d8943 | 279 | static void lookup_cfa PARAMS ((dw_cfa_location *)); |
d3e3972c KG |
280 | static void reg_save PARAMS ((const char *, unsigned, |
281 | unsigned, long)); | |
83d2b3b9 | 282 | static void initial_return_save PARAMS ((rtx)); |
5e640c56 | 283 | static long stack_adjust_offset PARAMS ((rtx)); |
12f0b96b | 284 | static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int)); |
83d2b3b9 | 285 | static void output_call_frame_info PARAMS ((int)); |
83d2b3b9 | 286 | static void dwarf2out_stack_adjust PARAMS ((rtx)); |
fbfa55b0 RH |
287 | static void queue_reg_save PARAMS ((const char *, rtx, long)); |
288 | static void flush_queued_reg_saves PARAMS ((void)); | |
289 | static bool clobbers_queued_reg_save PARAMS ((rtx)); | |
d3e3972c | 290 | static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *)); |
a3f97cbb | 291 | |
7d9d8943 AM |
292 | /* Support for complex CFA locations. */ |
293 | static void output_cfa_loc PARAMS ((dw_cfi_ref)); | |
556273e0 | 294 | static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *, |
7d9d8943 AM |
295 | struct dw_loc_descr_struct *)); |
296 | static struct dw_loc_descr_struct *build_cfa_loc | |
297 | PARAMS ((dw_cfa_location *)); | |
2ad9852d RK |
298 | static void def_cfa_1 PARAMS ((const char *, |
299 | dw_cfa_location *)); | |
7d9d8943 | 300 | |
2e4b9b8c RH |
301 | /* How to start an assembler comment. */ |
302 | #ifndef ASM_COMMENT_START | |
303 | #define ASM_COMMENT_START ";#" | |
a3f97cbb JW |
304 | #endif |
305 | ||
7e23cb16 JM |
306 | /* Data and reference forms for relocatable data. */ |
307 | #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4) | |
308 | #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4) | |
309 | ||
a3f97cbb JW |
310 | /* Pseudo-op for defining a new section. */ |
311 | #ifndef SECTION_ASM_OP | |
0a3e1f45 | 312 | #define SECTION_ASM_OP "\t.section\t" |
a3f97cbb JW |
313 | #endif |
314 | ||
cf2fe500 RH |
315 | #ifndef DEBUG_FRAME_SECTION |
316 | #define DEBUG_FRAME_SECTION ".debug_frame" | |
a3f97cbb | 317 | #endif |
a3f97cbb | 318 | |
5c90448c JM |
319 | #ifndef FUNC_BEGIN_LABEL |
320 | #define FUNC_BEGIN_LABEL "LFB" | |
a3f97cbb | 321 | #endif |
2ad9852d | 322 | |
5c90448c JM |
323 | #ifndef FUNC_END_LABEL |
324 | #define FUNC_END_LABEL "LFE" | |
a3f97cbb | 325 | #endif |
2ad9852d | 326 | |
27d95cbe | 327 | #define FRAME_BEGIN_LABEL "Lframe" |
a6ab3aad JM |
328 | #define CIE_AFTER_SIZE_LABEL "LSCIE" |
329 | #define CIE_END_LABEL "LECIE" | |
2ed2af28 | 330 | #define CIE_LENGTH_LABEL "LLCIE" |
2e4b9b8c RH |
331 | #define FDE_LABEL "LSFDE" |
332 | #define FDE_AFTER_SIZE_LABEL "LASFDE" | |
a6ab3aad | 333 | #define FDE_END_LABEL "LEFDE" |
2ed2af28 | 334 | #define FDE_LENGTH_LABEL "LLFDE" |
981975b6 RH |
335 | #define LINE_NUMBER_BEGIN_LABEL "LSLT" |
336 | #define LINE_NUMBER_END_LABEL "LELT" | |
337 | #define LN_PROLOG_AS_LABEL "LASLTP" | |
338 | #define LN_PROLOG_END_LABEL "LELTP" | |
881c6935 | 339 | #define DIE_LABEL_PREFIX "DW" |
a3f97cbb | 340 | |
a3f97cbb JW |
341 | /* Definitions of defaults for various types of primitive assembly language |
342 | output operations. These may be overridden from within the tm.h file, | |
956d6950 | 343 | but typically, that is unnecessary. */ |
71dfc51f | 344 | |
2ed2af28 PDM |
345 | #ifdef SET_ASM_OP |
346 | #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL | |
3a538a66 KH |
347 | #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \ |
348 | do \ | |
349 | { \ | |
350 | fprintf (FILE, "%s", SET_ASM_OP); \ | |
351 | assemble_name (FILE, SY); \ | |
352 | fputc (',', FILE); \ | |
353 | assemble_name (FILE, HI); \ | |
354 | fputc ('-', FILE); \ | |
355 | assemble_name (FILE, LO); \ | |
356 | } \ | |
357 | while (0) | |
2ed2af28 | 358 | #endif |
2ad9852d | 359 | #endif |
2ed2af28 | 360 | |
c8cc5c4a | 361 | /* The DWARF 2 CFA column which tracks the return address. Normally this |
a94dbf2c JM |
362 | is the column for PC, or the first column after all of the hard |
363 | registers. */ | |
c8cc5c4a | 364 | #ifndef DWARF_FRAME_RETURN_COLUMN |
a94dbf2c JM |
365 | #ifdef PC_REGNUM |
366 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM) | |
367 | #else | |
3073d01c | 368 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS |
a94dbf2c | 369 | #endif |
c8cc5c4a JM |
370 | #endif |
371 | ||
372 | /* The mapping from gcc register number to DWARF 2 CFA column number. By | |
469ac993 | 373 | default, we just provide columns for all registers. */ |
c8cc5c4a | 374 | #ifndef DWARF_FRAME_REGNUM |
469ac993 | 375 | #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG) |
c8cc5c4a | 376 | #endif |
3f76745e | 377 | |
2ad9852d RK |
378 | /* The offset from the incoming value of %sp to the top of the stack frame |
379 | for the current function. */ | |
380 | #ifndef INCOMING_FRAME_SP_OFFSET | |
381 | #define INCOMING_FRAME_SP_OFFSET 0 | |
382 | #endif | |
383 | \f | |
0021b564 JM |
384 | /* Hook used by __throw. */ |
385 | ||
386 | rtx | |
387 | expand_builtin_dwarf_fp_regnum () | |
388 | { | |
389 | return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM)); | |
390 | } | |
391 | ||
71dfc51f | 392 | /* Return a pointer to a copy of the section string name S with all |
bf20f341 | 393 | attributes stripped off, and an asterisk prepended (for assemble_name). */ |
71dfc51f RK |
394 | |
395 | static inline char * | |
a3f97cbb | 396 | stripattributes (s) |
d560ee52 | 397 | const char *s; |
a3f97cbb | 398 | { |
bf20f341 | 399 | char *stripped = xmalloc (strlen (s) + 2); |
71dfc51f RK |
400 | char *p = stripped; |
401 | ||
bf20f341 JW |
402 | *p++ = '*'; |
403 | ||
404 | while (*s && *s != ',') | |
405 | *p++ = *s++; | |
71dfc51f | 406 | |
a3f97cbb JW |
407 | *p = '\0'; |
408 | return stripped; | |
409 | } | |
410 | ||
d9d5c9de | 411 | /* Generate code to initialize the register size table. */ |
2f3ca9e7 | 412 | |
d9d5c9de BS |
413 | void |
414 | expand_builtin_init_dwarf_reg_sizes (address) | |
415 | tree address; | |
2f3ca9e7 | 416 | { |
d9d5c9de BS |
417 | int i; |
418 | enum machine_mode mode = TYPE_MODE (char_type_node); | |
419 | rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0); | |
2ad9852d | 420 | rtx mem = gen_rtx_MEM (BLKmode, addr); |
2f3ca9e7 | 421 | |
2ad9852d | 422 | for (i = 0; i < DWARF_FRAME_REGISTERS; i++) |
2f3ca9e7 | 423 | { |
2ad9852d RK |
424 | HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode); |
425 | HOST_WIDE_INT size = GET_MODE_SIZE (reg_raw_mode[i]); | |
2f3ca9e7 | 426 | |
c699cee9 JM |
427 | if (offset < 0) |
428 | continue; | |
429 | ||
f4ef873c | 430 | emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size)); |
2f3ca9e7 | 431 | } |
2f3ca9e7 JM |
432 | } |
433 | ||
3f76745e | 434 | /* Convert a DWARF call frame info. operation to its string name */ |
a3f97cbb | 435 | |
d560ee52 | 436 | static const char * |
3f76745e | 437 | dwarf_cfi_name (cfi_opc) |
b3694847 | 438 | unsigned cfi_opc; |
3f76745e JM |
439 | { |
440 | switch (cfi_opc) | |
441 | { | |
442 | case DW_CFA_advance_loc: | |
443 | return "DW_CFA_advance_loc"; | |
444 | case DW_CFA_offset: | |
445 | return "DW_CFA_offset"; | |
446 | case DW_CFA_restore: | |
447 | return "DW_CFA_restore"; | |
448 | case DW_CFA_nop: | |
449 | return "DW_CFA_nop"; | |
450 | case DW_CFA_set_loc: | |
451 | return "DW_CFA_set_loc"; | |
452 | case DW_CFA_advance_loc1: | |
453 | return "DW_CFA_advance_loc1"; | |
454 | case DW_CFA_advance_loc2: | |
455 | return "DW_CFA_advance_loc2"; | |
456 | case DW_CFA_advance_loc4: | |
457 | return "DW_CFA_advance_loc4"; | |
458 | case DW_CFA_offset_extended: | |
459 | return "DW_CFA_offset_extended"; | |
460 | case DW_CFA_restore_extended: | |
461 | return "DW_CFA_restore_extended"; | |
462 | case DW_CFA_undefined: | |
463 | return "DW_CFA_undefined"; | |
464 | case DW_CFA_same_value: | |
465 | return "DW_CFA_same_value"; | |
466 | case DW_CFA_register: | |
467 | return "DW_CFA_register"; | |
468 | case DW_CFA_remember_state: | |
469 | return "DW_CFA_remember_state"; | |
470 | case DW_CFA_restore_state: | |
471 | return "DW_CFA_restore_state"; | |
472 | case DW_CFA_def_cfa: | |
473 | return "DW_CFA_def_cfa"; | |
474 | case DW_CFA_def_cfa_register: | |
475 | return "DW_CFA_def_cfa_register"; | |
476 | case DW_CFA_def_cfa_offset: | |
477 | return "DW_CFA_def_cfa_offset"; | |
6bb28965 JM |
478 | |
479 | /* DWARF 3 */ | |
7d9d8943 AM |
480 | case DW_CFA_def_cfa_expression: |
481 | return "DW_CFA_def_cfa_expression"; | |
6bb28965 JM |
482 | case DW_CFA_expression: |
483 | return "DW_CFA_expression"; | |
484 | case DW_CFA_offset_extended_sf: | |
485 | return "DW_CFA_offset_extended_sf"; | |
486 | case DW_CFA_def_cfa_sf: | |
487 | return "DW_CFA_def_cfa_sf"; | |
488 | case DW_CFA_def_cfa_offset_sf: | |
489 | return "DW_CFA_def_cfa_offset_sf"; | |
c53aa195 | 490 | |
3f76745e JM |
491 | /* SGI/MIPS specific */ |
492 | case DW_CFA_MIPS_advance_loc8: | |
493 | return "DW_CFA_MIPS_advance_loc8"; | |
c53aa195 JM |
494 | |
495 | /* GNU extensions */ | |
496 | case DW_CFA_GNU_window_save: | |
497 | return "DW_CFA_GNU_window_save"; | |
0021b564 JM |
498 | case DW_CFA_GNU_args_size: |
499 | return "DW_CFA_GNU_args_size"; | |
3f388b42 GK |
500 | case DW_CFA_GNU_negative_offset_extended: |
501 | return "DW_CFA_GNU_negative_offset_extended"; | |
c53aa195 | 502 | |
3f76745e JM |
503 | default: |
504 | return "DW_CFA_<unknown>"; | |
505 | } | |
506 | } | |
a3f97cbb | 507 | |
3f76745e | 508 | /* Return a pointer to a newly allocated Call Frame Instruction. */ |
71dfc51f | 509 | |
3f76745e JM |
510 | static inline dw_cfi_ref |
511 | new_cfi () | |
512 | { | |
b3694847 | 513 | dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node)); |
71dfc51f | 514 | |
3f76745e JM |
515 | cfi->dw_cfi_next = NULL; |
516 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0; | |
517 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0; | |
a3f97cbb | 518 | |
3f76745e JM |
519 | return cfi; |
520 | } | |
a3f97cbb | 521 | |
3f76745e | 522 | /* Add a Call Frame Instruction to list of instructions. */ |
a3f97cbb | 523 | |
3f76745e JM |
524 | static inline void |
525 | add_cfi (list_head, cfi) | |
b3694847 SS |
526 | dw_cfi_ref *list_head; |
527 | dw_cfi_ref cfi; | |
3f76745e | 528 | { |
b3694847 | 529 | dw_cfi_ref *p; |
a3f97cbb | 530 | |
3f76745e JM |
531 | /* Find the end of the chain. */ |
532 | for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next) | |
533 | ; | |
534 | ||
535 | *p = cfi; | |
a3f97cbb JW |
536 | } |
537 | ||
3f76745e | 538 | /* Generate a new label for the CFI info to refer to. */ |
71dfc51f | 539 | |
c53aa195 | 540 | char * |
3f76745e | 541 | dwarf2out_cfi_label () |
a3f97cbb | 542 | { |
3f76745e JM |
543 | static char label[20]; |
544 | static unsigned long label_num = 0; | |
556273e0 | 545 | |
3f76745e JM |
546 | ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++); |
547 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
3f76745e | 548 | return label; |
a3f97cbb JW |
549 | } |
550 | ||
3f76745e JM |
551 | /* Add CFI to the current fde at the PC value indicated by LABEL if specified, |
552 | or to the CIE if LABEL is NULL. */ | |
71dfc51f | 553 | |
3f76745e JM |
554 | static void |
555 | add_fde_cfi (label, cfi) | |
b3694847 SS |
556 | const char *label; |
557 | dw_cfi_ref cfi; | |
a3f97cbb | 558 | { |
3f76745e JM |
559 | if (label) |
560 | { | |
b3694847 | 561 | dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
a3f97cbb | 562 | |
3f76745e JM |
563 | if (*label == 0) |
564 | label = dwarf2out_cfi_label (); | |
71dfc51f | 565 | |
3f76745e JM |
566 | if (fde->dw_fde_current_label == NULL |
567 | || strcmp (label, fde->dw_fde_current_label) != 0) | |
568 | { | |
b3694847 | 569 | dw_cfi_ref xcfi; |
a3f97cbb | 570 | |
3f76745e | 571 | fde->dw_fde_current_label = label = xstrdup (label); |
71dfc51f | 572 | |
3f76745e JM |
573 | /* Set the location counter to the new label. */ |
574 | xcfi = new_cfi (); | |
575 | xcfi->dw_cfi_opc = DW_CFA_advance_loc4; | |
576 | xcfi->dw_cfi_oprnd1.dw_cfi_addr = label; | |
577 | add_cfi (&fde->dw_fde_cfi, xcfi); | |
578 | } | |
71dfc51f | 579 | |
3f76745e JM |
580 | add_cfi (&fde->dw_fde_cfi, cfi); |
581 | } | |
582 | ||
583 | else | |
584 | add_cfi (&cie_cfi_head, cfi); | |
a3f97cbb JW |
585 | } |
586 | ||
3f76745e | 587 | /* Subroutine of lookup_cfa. */ |
71dfc51f | 588 | |
3f76745e | 589 | static inline void |
7d9d8943 | 590 | lookup_cfa_1 (cfi, loc) |
b3694847 SS |
591 | dw_cfi_ref cfi; |
592 | dw_cfa_location *loc; | |
a3f97cbb | 593 | { |
3f76745e JM |
594 | switch (cfi->dw_cfi_opc) |
595 | { | |
596 | case DW_CFA_def_cfa_offset: | |
7d9d8943 | 597 | loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset; |
3f76745e JM |
598 | break; |
599 | case DW_CFA_def_cfa_register: | |
7d9d8943 | 600 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
3f76745e JM |
601 | break; |
602 | case DW_CFA_def_cfa: | |
7d9d8943 AM |
603 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
604 | loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset; | |
605 | break; | |
606 | case DW_CFA_def_cfa_expression: | |
607 | get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc); | |
3f76745e | 608 | break; |
e9a25f70 JL |
609 | default: |
610 | break; | |
3f76745e | 611 | } |
a3f97cbb JW |
612 | } |
613 | ||
3f76745e | 614 | /* Find the previous value for the CFA. */ |
71dfc51f | 615 | |
3f76745e | 616 | static void |
7d9d8943 | 617 | lookup_cfa (loc) |
b3694847 | 618 | dw_cfa_location *loc; |
a3f97cbb | 619 | { |
b3694847 | 620 | dw_cfi_ref cfi; |
3f76745e | 621 | |
7d9d8943 AM |
622 | loc->reg = (unsigned long) -1; |
623 | loc->offset = 0; | |
624 | loc->indirect = 0; | |
625 | loc->base_offset = 0; | |
3f76745e JM |
626 | |
627 | for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next) | |
7d9d8943 | 628 | lookup_cfa_1 (cfi, loc); |
3f76745e JM |
629 | |
630 | if (fde_table_in_use) | |
a3f97cbb | 631 | { |
b3694847 | 632 | dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
3f76745e | 633 | for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next) |
7d9d8943 | 634 | lookup_cfa_1 (cfi, loc); |
a3f97cbb JW |
635 | } |
636 | } | |
637 | ||
3f76745e | 638 | /* The current rule for calculating the DWARF2 canonical frame address. */ |
fbfa55b0 | 639 | static dw_cfa_location cfa; |
71dfc51f | 640 | |
3f76745e JM |
641 | /* The register used for saving registers to the stack, and its offset |
642 | from the CFA. */ | |
fbfa55b0 | 643 | static dw_cfa_location cfa_store; |
3f76745e | 644 | |
0021b564 JM |
645 | /* The running total of the size of arguments pushed onto the stack. */ |
646 | static long args_size; | |
647 | ||
b57d9225 JM |
648 | /* The last args_size we actually output. */ |
649 | static long old_args_size; | |
650 | ||
3f76745e JM |
651 | /* Entry point to update the canonical frame address (CFA). |
652 | LABEL is passed to add_fde_cfi. The value of CFA is now to be | |
653 | calculated from REG+OFFSET. */ | |
654 | ||
655 | void | |
656 | dwarf2out_def_cfa (label, reg, offset) | |
b3694847 | 657 | const char *label; |
7d9d8943 AM |
658 | unsigned reg; |
659 | long offset; | |
660 | { | |
661 | dw_cfa_location loc; | |
662 | loc.indirect = 0; | |
663 | loc.base_offset = 0; | |
664 | loc.reg = reg; | |
665 | loc.offset = offset; | |
666 | def_cfa_1 (label, &loc); | |
667 | } | |
668 | ||
770ca8c6 | 669 | /* This routine does the actual work. The CFA is now calculated from |
7d9d8943 | 670 | the dw_cfa_location structure. */ |
2ad9852d | 671 | |
7d9d8943 AM |
672 | static void |
673 | def_cfa_1 (label, loc_p) | |
b3694847 | 674 | const char *label; |
7d9d8943 | 675 | dw_cfa_location *loc_p; |
a3f97cbb | 676 | { |
b3694847 | 677 | dw_cfi_ref cfi; |
7d9d8943 | 678 | dw_cfa_location old_cfa, loc; |
3f76745e | 679 | |
7d9d8943 AM |
680 | cfa = *loc_p; |
681 | loc = *loc_p; | |
5bef9b1f | 682 | |
7d9d8943 AM |
683 | if (cfa_store.reg == loc.reg && loc.indirect == 0) |
684 | cfa_store.offset = loc.offset; | |
3f76745e | 685 | |
7d9d8943 AM |
686 | loc.reg = DWARF_FRAME_REGNUM (loc.reg); |
687 | lookup_cfa (&old_cfa); | |
688 | ||
2ad9852d RK |
689 | /* If nothing changed, no need to issue any call frame instructions. */ |
690 | if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset | |
691 | && loc.indirect == old_cfa.indirect | |
692 | && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset)) | |
693 | return; | |
3f76745e JM |
694 | |
695 | cfi = new_cfi (); | |
696 | ||
e09bbb25 | 697 | if (loc.reg == old_cfa.reg && !loc.indirect) |
a3f97cbb | 698 | { |
770ca8c6 JO |
699 | /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, |
700 | indicating the CFA register did not change but the offset | |
701 | did. */ | |
3f76745e | 702 | cfi->dw_cfi_opc = DW_CFA_def_cfa_offset; |
7d9d8943 | 703 | cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset; |
3f76745e | 704 | } |
a3f97cbb | 705 | |
3f76745e | 706 | #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */ |
7d9d8943 | 707 | else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1 |
e09bbb25 | 708 | && !loc.indirect) |
3f76745e | 709 | { |
770ca8c6 JO |
710 | /* Construct a "DW_CFA_def_cfa_register <register>" instruction, |
711 | indicating the CFA register has changed to <register> but the | |
712 | offset has not changed. */ | |
3f76745e | 713 | cfi->dw_cfi_opc = DW_CFA_def_cfa_register; |
7d9d8943 | 714 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
3f76745e JM |
715 | } |
716 | #endif | |
a3f97cbb | 717 | |
7d9d8943 | 718 | else if (loc.indirect == 0) |
3f76745e | 719 | { |
770ca8c6 JO |
720 | /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction, |
721 | indicating the CFA register has changed to <register> with | |
722 | the specified offset. */ | |
3f76745e | 723 | cfi->dw_cfi_opc = DW_CFA_def_cfa; |
7d9d8943 AM |
724 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
725 | cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset; | |
726 | } | |
727 | else | |
728 | { | |
770ca8c6 JO |
729 | /* Construct a DW_CFA_def_cfa_expression instruction to |
730 | calculate the CFA using a full location expression since no | |
731 | register-offset pair is available. */ | |
556273e0 | 732 | struct dw_loc_descr_struct *loc_list; |
2ad9852d | 733 | |
7d9d8943 AM |
734 | cfi->dw_cfi_opc = DW_CFA_def_cfa_expression; |
735 | loc_list = build_cfa_loc (&loc); | |
736 | cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list; | |
a3f97cbb | 737 | } |
3f76745e JM |
738 | |
739 | add_fde_cfi (label, cfi); | |
a3f97cbb JW |
740 | } |
741 | ||
3f76745e JM |
742 | /* Add the CFI for saving a register. REG is the CFA column number. |
743 | LABEL is passed to add_fde_cfi. | |
744 | If SREG is -1, the register is saved at OFFSET from the CFA; | |
745 | otherwise it is saved in SREG. */ | |
71dfc51f | 746 | |
3f76745e JM |
747 | static void |
748 | reg_save (label, reg, sreg, offset) | |
b3694847 SS |
749 | const char *label; |
750 | unsigned reg; | |
751 | unsigned sreg; | |
752 | long offset; | |
a3f97cbb | 753 | { |
b3694847 | 754 | dw_cfi_ref cfi = new_cfi (); |
3f76745e JM |
755 | |
756 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
757 | ||
85066503 MH |
758 | /* The following comparison is correct. -1 is used to indicate that |
759 | the value isn't a register number. */ | |
760 | if (sreg == (unsigned int) -1) | |
a3f97cbb | 761 | { |
3f76745e JM |
762 | if (reg & ~0x3f) |
763 | /* The register number won't fit in 6 bits, so we have to use | |
764 | the long form. */ | |
765 | cfi->dw_cfi_opc = DW_CFA_offset_extended; | |
766 | else | |
767 | cfi->dw_cfi_opc = DW_CFA_offset; | |
768 | ||
27c35f4b HPN |
769 | #ifdef ENABLE_CHECKING |
770 | { | |
771 | /* If we get an offset that is not a multiple of | |
772 | DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the | |
773 | definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine | |
774 | description. */ | |
775 | long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT; | |
776 | ||
777 | if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset) | |
778 | abort (); | |
779 | } | |
780 | #endif | |
3f76745e | 781 | offset /= DWARF_CIE_DATA_ALIGNMENT; |
3a88cbd1 | 782 | if (offset < 0) |
6bb28965 | 783 | cfi->dw_cfi_opc = DW_CFA_offset_extended_sf; |
2ad9852d | 784 | |
3f76745e JM |
785 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; |
786 | } | |
2c849145 JM |
787 | else if (sreg == reg) |
788 | /* We could emit a DW_CFA_same_value in this case, but don't bother. */ | |
789 | return; | |
3f76745e JM |
790 | else |
791 | { | |
792 | cfi->dw_cfi_opc = DW_CFA_register; | |
793 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg; | |
794 | } | |
795 | ||
796 | add_fde_cfi (label, cfi); | |
797 | } | |
798 | ||
c53aa195 JM |
799 | /* Add the CFI for saving a register window. LABEL is passed to reg_save. |
800 | This CFI tells the unwinder that it needs to restore the window registers | |
801 | from the previous frame's window save area. | |
556273e0 | 802 | |
c53aa195 JM |
803 | ??? Perhaps we should note in the CIE where windows are saved (instead of |
804 | assuming 0(cfa)) and what registers are in the window. */ | |
805 | ||
806 | void | |
807 | dwarf2out_window_save (label) | |
b3694847 | 808 | const char *label; |
c53aa195 | 809 | { |
b3694847 | 810 | dw_cfi_ref cfi = new_cfi (); |
2ad9852d | 811 | |
c53aa195 JM |
812 | cfi->dw_cfi_opc = DW_CFA_GNU_window_save; |
813 | add_fde_cfi (label, cfi); | |
814 | } | |
815 | ||
0021b564 JM |
816 | /* Add a CFI to update the running total of the size of arguments |
817 | pushed onto the stack. */ | |
818 | ||
819 | void | |
820 | dwarf2out_args_size (label, size) | |
d3e3972c | 821 | const char *label; |
0021b564 JM |
822 | long size; |
823 | { | |
b3694847 | 824 | dw_cfi_ref cfi; |
b57d9225 JM |
825 | |
826 | if (size == old_args_size) | |
827 | return; | |
2ad9852d | 828 | |
b57d9225 JM |
829 | old_args_size = size; |
830 | ||
831 | cfi = new_cfi (); | |
0021b564 JM |
832 | cfi->dw_cfi_opc = DW_CFA_GNU_args_size; |
833 | cfi->dw_cfi_oprnd1.dw_cfi_offset = size; | |
834 | add_fde_cfi (label, cfi); | |
835 | } | |
836 | ||
c53aa195 JM |
837 | /* Entry point for saving a register to the stack. REG is the GCC register |
838 | number. LABEL and OFFSET are passed to reg_save. */ | |
3f76745e JM |
839 | |
840 | void | |
841 | dwarf2out_reg_save (label, reg, offset) | |
b3694847 SS |
842 | const char *label; |
843 | unsigned reg; | |
844 | long offset; | |
3f76745e JM |
845 | { |
846 | reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset); | |
847 | } | |
848 | ||
c53aa195 JM |
849 | /* Entry point for saving the return address in the stack. |
850 | LABEL and OFFSET are passed to reg_save. */ | |
851 | ||
852 | void | |
853 | dwarf2out_return_save (label, offset) | |
b3694847 SS |
854 | const char *label; |
855 | long offset; | |
c53aa195 JM |
856 | { |
857 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset); | |
858 | } | |
859 | ||
860 | /* Entry point for saving the return address in a register. | |
861 | LABEL and SREG are passed to reg_save. */ | |
862 | ||
863 | void | |
864 | dwarf2out_return_reg (label, sreg) | |
b3694847 SS |
865 | const char *label; |
866 | unsigned sreg; | |
c53aa195 JM |
867 | { |
868 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0); | |
869 | } | |
870 | ||
3f76745e JM |
871 | /* Record the initial position of the return address. RTL is |
872 | INCOMING_RETURN_ADDR_RTX. */ | |
873 | ||
874 | static void | |
875 | initial_return_save (rtl) | |
b3694847 | 876 | rtx rtl; |
3f76745e | 877 | { |
973838fd | 878 | unsigned int reg = (unsigned int) -1; |
2ad9852d | 879 | HOST_WIDE_INT offset = 0; |
3f76745e JM |
880 | |
881 | switch (GET_CODE (rtl)) | |
882 | { | |
883 | case REG: | |
884 | /* RA is in a register. */ | |
2c849145 | 885 | reg = DWARF_FRAME_REGNUM (REGNO (rtl)); |
3f76745e | 886 | break; |
2ad9852d | 887 | |
3f76745e JM |
888 | case MEM: |
889 | /* RA is on the stack. */ | |
890 | rtl = XEXP (rtl, 0); | |
891 | switch (GET_CODE (rtl)) | |
892 | { | |
893 | case REG: | |
3a88cbd1 JL |
894 | if (REGNO (rtl) != STACK_POINTER_REGNUM) |
895 | abort (); | |
3f76745e JM |
896 | offset = 0; |
897 | break; | |
2ad9852d | 898 | |
3f76745e | 899 | case PLUS: |
3a88cbd1 JL |
900 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
901 | abort (); | |
3f76745e JM |
902 | offset = INTVAL (XEXP (rtl, 1)); |
903 | break; | |
2ad9852d | 904 | |
3f76745e | 905 | case MINUS: |
3a88cbd1 JL |
906 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
907 | abort (); | |
3f76745e JM |
908 | offset = -INTVAL (XEXP (rtl, 1)); |
909 | break; | |
2ad9852d | 910 | |
3f76745e JM |
911 | default: |
912 | abort (); | |
913 | } | |
2ad9852d | 914 | |
3f76745e | 915 | break; |
2ad9852d | 916 | |
c53aa195 JM |
917 | case PLUS: |
918 | /* The return address is at some offset from any value we can | |
919 | actually load. For instance, on the SPARC it is in %i7+8. Just | |
920 | ignore the offset for now; it doesn't matter for unwinding frames. */ | |
3a88cbd1 JL |
921 | if (GET_CODE (XEXP (rtl, 1)) != CONST_INT) |
922 | abort (); | |
c53aa195 JM |
923 | initial_return_save (XEXP (rtl, 0)); |
924 | return; | |
2ad9852d | 925 | |
a3f97cbb | 926 | default: |
3f76745e | 927 | abort (); |
a3f97cbb | 928 | } |
3f76745e | 929 | |
7d9d8943 | 930 | reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset); |
a3f97cbb JW |
931 | } |
932 | ||
1ba5ae8f | 933 | /* Given a SET, calculate the amount of stack adjustment it |
30f7a378 | 934 | contains. */ |
1ba5ae8f | 935 | |
5e640c56 AH |
936 | static long |
937 | stack_adjust_offset (pattern) | |
173bf5be | 938 | rtx pattern; |
1ba5ae8f AH |
939 | { |
940 | rtx src = SET_SRC (pattern); | |
941 | rtx dest = SET_DEST (pattern); | |
2ad9852d | 942 | HOST_WIDE_INT offset = 0; |
1ba5ae8f AH |
943 | enum rtx_code code; |
944 | ||
945 | if (dest == stack_pointer_rtx) | |
946 | { | |
947 | /* (set (reg sp) (plus (reg sp) (const_int))) */ | |
948 | code = GET_CODE (src); | |
949 | if (! (code == PLUS || code == MINUS) | |
950 | || XEXP (src, 0) != stack_pointer_rtx | |
951 | || GET_CODE (XEXP (src, 1)) != CONST_INT) | |
952 | return 0; | |
953 | ||
954 | offset = INTVAL (XEXP (src, 1)); | |
f472fa29 AM |
955 | if (code == PLUS) |
956 | offset = -offset; | |
1ba5ae8f AH |
957 | } |
958 | else if (GET_CODE (dest) == MEM) | |
959 | { | |
960 | /* (set (mem (pre_dec (reg sp))) (foo)) */ | |
961 | src = XEXP (dest, 0); | |
962 | code = GET_CODE (src); | |
963 | ||
c26fbbca KH |
964 | switch (code) |
965 | { | |
f472fa29 AM |
966 | case PRE_MODIFY: |
967 | case POST_MODIFY: | |
968 | if (XEXP (src, 0) == stack_pointer_rtx) | |
969 | { | |
970 | rtx val = XEXP (XEXP (src, 1), 1); | |
971 | /* We handle only adjustments by constant amount. */ | |
972 | if (GET_CODE (XEXP (src, 1)) != PLUS || | |
973 | GET_CODE (val) != CONST_INT) | |
c26fbbca | 974 | abort (); |
f472fa29 AM |
975 | offset = -INTVAL (val); |
976 | break; | |
977 | } | |
978 | return 0; | |
979 | ||
980 | case PRE_DEC: | |
981 | case POST_DEC: | |
982 | if (XEXP (src, 0) == stack_pointer_rtx) | |
983 | { | |
984 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
985 | break; | |
986 | } | |
987 | return 0; | |
988 | ||
989 | case PRE_INC: | |
990 | case POST_INC: | |
991 | if (XEXP (src, 0) == stack_pointer_rtx) | |
992 | { | |
993 | offset = -GET_MODE_SIZE (GET_MODE (dest)); | |
994 | break; | |
995 | } | |
996 | return 0; | |
2ad9852d | 997 | |
f472fa29 AM |
998 | default: |
999 | return 0; | |
e2134eea | 1000 | } |
1ba5ae8f AH |
1001 | } |
1002 | else | |
1003 | return 0; | |
1004 | ||
1ba5ae8f AH |
1005 | return offset; |
1006 | } | |
1007 | ||
0021b564 JM |
1008 | /* Check INSN to see if it looks like a push or a stack adjustment, and |
1009 | make a note of it if it does. EH uses this information to find out how | |
1010 | much extra space it needs to pop off the stack. */ | |
1011 | ||
1012 | static void | |
1013 | dwarf2out_stack_adjust (insn) | |
1014 | rtx insn; | |
1015 | { | |
2ad9852d | 1016 | HOST_WIDE_INT offset; |
d3e3972c | 1017 | const char *label; |
2ad9852d | 1018 | int i; |
0021b564 | 1019 | |
2ad9852d | 1020 | if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN) |
b57d9225 JM |
1021 | { |
1022 | /* Extract the size of the args from the CALL rtx itself. */ | |
b57d9225 JM |
1023 | insn = PATTERN (insn); |
1024 | if (GET_CODE (insn) == PARALLEL) | |
1025 | insn = XVECEXP (insn, 0, 0); | |
1026 | if (GET_CODE (insn) == SET) | |
1027 | insn = SET_SRC (insn); | |
3db35af4 MM |
1028 | if (GET_CODE (insn) != CALL) |
1029 | abort (); | |
2ad9852d | 1030 | |
b57d9225 JM |
1031 | dwarf2out_args_size ("", INTVAL (XEXP (insn, 1))); |
1032 | return; | |
1033 | } | |
1034 | ||
1035 | /* If only calls can throw, and we have a frame pointer, | |
1036 | save up adjustments until we see the CALL_INSN. */ | |
2ad9852d | 1037 | else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM) |
b57d9225 JM |
1038 | return; |
1039 | ||
6020d360 | 1040 | if (GET_CODE (insn) == BARRIER) |
0021b564 | 1041 | { |
6020d360 JM |
1042 | /* When we see a BARRIER, we know to reset args_size to 0. Usually |
1043 | the compiler will have already emitted a stack adjustment, but | |
1044 | doesn't bother for calls to noreturn functions. */ | |
1045 | #ifdef STACK_GROWS_DOWNWARD | |
1046 | offset = -args_size; | |
1047 | #else | |
1048 | offset = args_size; | |
1049 | #endif | |
0021b564 | 1050 | } |
6020d360 | 1051 | else if (GET_CODE (PATTERN (insn)) == SET) |
2ad9852d | 1052 | offset = stack_adjust_offset (PATTERN (insn)); |
1ba5ae8f AH |
1053 | else if (GET_CODE (PATTERN (insn)) == PARALLEL |
1054 | || GET_CODE (PATTERN (insn)) == SEQUENCE) | |
1055 | { | |
1056 | /* There may be stack adjustments inside compound insns. Search | |
2ad9852d RK |
1057 | for them. */ |
1058 | for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--) | |
1059 | if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET) | |
1060 | offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i)); | |
0021b564 JM |
1061 | } |
1062 | else | |
1063 | return; | |
0b34cf1e | 1064 | |
6020d360 JM |
1065 | if (offset == 0) |
1066 | return; | |
1067 | ||
7d9d8943 AM |
1068 | if (cfa.reg == STACK_POINTER_REGNUM) |
1069 | cfa.offset += offset; | |
0021b564 JM |
1070 | |
1071 | #ifndef STACK_GROWS_DOWNWARD | |
1072 | offset = -offset; | |
1073 | #endif | |
2ad9852d | 1074 | |
0021b564 JM |
1075 | args_size += offset; |
1076 | if (args_size < 0) | |
1077 | args_size = 0; | |
1078 | ||
1079 | label = dwarf2out_cfi_label (); | |
7d9d8943 | 1080 | def_cfa_1 (label, &cfa); |
0021b564 JM |
1081 | dwarf2out_args_size (label, args_size); |
1082 | } | |
1083 | ||
fbfa55b0 RH |
1084 | /* We delay emitting a register save until either (a) we reach the end |
1085 | of the prologue or (b) the register is clobbered. This clusters | |
1086 | register saves so that there are fewer pc advances. */ | |
1087 | ||
1088 | struct queued_reg_save | |
1089 | { | |
1090 | struct queued_reg_save *next; | |
1091 | rtx reg; | |
1092 | long cfa_offset; | |
1093 | }; | |
1094 | ||
1095 | static struct queued_reg_save *queued_reg_saves; | |
1096 | static const char *last_reg_save_label; | |
1097 | ||
1098 | static void | |
1099 | queue_reg_save (label, reg, offset) | |
1100 | const char *label; | |
1101 | rtx reg; | |
1102 | long offset; | |
1103 | { | |
1104 | struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q)); | |
1105 | ||
1106 | q->next = queued_reg_saves; | |
1107 | q->reg = reg; | |
1108 | q->cfa_offset = offset; | |
1109 | queued_reg_saves = q; | |
1110 | ||
1111 | last_reg_save_label = label; | |
1112 | } | |
1113 | ||
1114 | static void | |
1115 | flush_queued_reg_saves () | |
1116 | { | |
1117 | struct queued_reg_save *q, *next; | |
1118 | ||
c26fbbca | 1119 | for (q = queued_reg_saves; q; q = next) |
fbfa55b0 RH |
1120 | { |
1121 | dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset); | |
1122 | next = q->next; | |
1123 | free (q); | |
1124 | } | |
1125 | ||
1126 | queued_reg_saves = NULL; | |
1127 | last_reg_save_label = NULL; | |
1128 | } | |
1129 | ||
1130 | static bool | |
1131 | clobbers_queued_reg_save (insn) | |
1132 | rtx insn; | |
1133 | { | |
1134 | struct queued_reg_save *q; | |
1135 | ||
c26fbbca | 1136 | for (q = queued_reg_saves; q; q = q->next) |
fbfa55b0 RH |
1137 | if (modified_in_p (q->reg, insn)) |
1138 | return true; | |
1139 | ||
1140 | return false; | |
1141 | } | |
c26fbbca | 1142 | |
fbfa55b0 | 1143 | |
770ca8c6 JO |
1144 | /* A temporary register holding an integral value used in adjusting SP |
1145 | or setting up the store_reg. The "offset" field holds the integer | |
1146 | value, not an offset. */ | |
fbfa55b0 | 1147 | static dw_cfa_location cfa_temp; |
770ca8c6 JO |
1148 | |
1149 | /* Record call frame debugging information for an expression EXPR, | |
1150 | which either sets SP or FP (adjusting how we calculate the frame | |
1151 | address) or saves a register to the stack. LABEL indicates the | |
1152 | address of EXPR. | |
1153 | ||
1154 | This function encodes a state machine mapping rtxes to actions on | |
1155 | cfa, cfa_store, and cfa_temp.reg. We describe these rules so | |
1156 | users need not read the source code. | |
1157 | ||
a401107d JO |
1158 | The High-Level Picture |
1159 | ||
1160 | Changes in the register we use to calculate the CFA: Currently we | |
1161 | assume that if you copy the CFA register into another register, we | |
1162 | should take the other one as the new CFA register; this seems to | |
1163 | work pretty well. If it's wrong for some target, it's simple | |
1164 | enough not to set RTX_FRAME_RELATED_P on the insn in question. | |
1165 | ||
1166 | Changes in the register we use for saving registers to the stack: | |
1167 | This is usually SP, but not always. Again, we deduce that if you | |
1168 | copy SP into another register (and SP is not the CFA register), | |
1169 | then the new register is the one we will be using for register | |
1170 | saves. This also seems to work. | |
1171 | ||
1172 | Register saves: There's not much guesswork about this one; if | |
1173 | RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a | |
1174 | register save, and the register used to calculate the destination | |
1175 | had better be the one we think we're using for this purpose. | |
1176 | ||
1177 | Except: If the register being saved is the CFA register, and the | |
1178 | offset is non-zero, we are saving the CFA, so we assume we have to | |
1179 | use DW_CFA_def_cfa_expression. If the offset is 0, we assume that | |
1180 | the intent is to save the value of SP from the previous frame. | |
1181 | ||
770ca8c6 JO |
1182 | Invariants / Summaries of Rules |
1183 | ||
a401107d JO |
1184 | cfa current rule for calculating the CFA. It usually |
1185 | consists of a register and an offset. | |
770ca8c6 JO |
1186 | cfa_store register used by prologue code to save things to the stack |
1187 | cfa_store.offset is the offset from the value of | |
1188 | cfa_store.reg to the actual CFA | |
1189 | cfa_temp register holding an integral value. cfa_temp.offset | |
1190 | stores the value, which will be used to adjust the | |
19ec6a36 AM |
1191 | stack pointer. cfa_temp is also used like cfa_store, |
1192 | to track stores to the stack via fp or a temp reg. | |
c26fbbca | 1193 | |
770ca8c6 JO |
1194 | Rules 1- 4: Setting a register's value to cfa.reg or an expression |
1195 | with cfa.reg as the first operand changes the cfa.reg and its | |
19ec6a36 AM |
1196 | cfa.offset. Rule 1 and 4 also set cfa_temp.reg and |
1197 | cfa_temp.offset. | |
770ca8c6 JO |
1198 | |
1199 | Rules 6- 9: Set a non-cfa.reg register value to a constant or an | |
1200 | expression yielding a constant. This sets cfa_temp.reg | |
1201 | and cfa_temp.offset. | |
1202 | ||
1203 | Rule 5: Create a new register cfa_store used to save items to the | |
1204 | stack. | |
1205 | ||
19ec6a36 | 1206 | Rules 10-14: Save a register to the stack. Define offset as the |
a401107d | 1207 | difference of the original location and cfa_store's |
19ec6a36 | 1208 | location (or cfa_temp's location if cfa_temp is used). |
770ca8c6 JO |
1209 | |
1210 | The Rules | |
1211 | ||
1212 | "{a,b}" indicates a choice of a xor b. | |
1213 | "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg. | |
1214 | ||
1215 | Rule 1: | |
1216 | (set <reg1> <reg2>:cfa.reg) | |
19ec6a36 | 1217 | effects: cfa.reg = <reg1> |
770ca8c6 | 1218 | cfa.offset unchanged |
19ec6a36 AM |
1219 | cfa_temp.reg = <reg1> |
1220 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1221 | |
1222 | Rule 2: | |
2ad9852d RK |
1223 | (set sp ({minus,plus,losum} {sp,fp}:cfa.reg |
1224 | {<const_int>,<reg>:cfa_temp.reg})) | |
770ca8c6 JO |
1225 | effects: cfa.reg = sp if fp used |
1226 | cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp | |
1227 | cfa_store.offset += {+/- <const_int>, cfa_temp.offset} | |
1228 | if cfa_store.reg==sp | |
1229 | ||
1230 | Rule 3: | |
19ec6a36 | 1231 | (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>)) |
770ca8c6 JO |
1232 | effects: cfa.reg = fp |
1233 | cfa_offset += +/- <const_int> | |
1234 | ||
1235 | Rule 4: | |
19ec6a36 | 1236 | (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>)) |
770ca8c6 JO |
1237 | constraints: <reg1> != fp |
1238 | <reg1> != sp | |
1239 | effects: cfa.reg = <reg1> | |
19ec6a36 AM |
1240 | cfa_temp.reg = <reg1> |
1241 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1242 | |
1243 | Rule 5: | |
1244 | (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg)) | |
1245 | constraints: <reg1> != fp | |
1246 | <reg1> != sp | |
1247 | effects: cfa_store.reg = <reg1> | |
1248 | cfa_store.offset = cfa.offset - cfa_temp.offset | |
1249 | ||
1250 | Rule 6: | |
1251 | (set <reg> <const_int>) | |
1252 | effects: cfa_temp.reg = <reg> | |
1253 | cfa_temp.offset = <const_int> | |
1254 | ||
1255 | Rule 7: | |
1256 | (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>)) | |
1257 | effects: cfa_temp.reg = <reg1> | |
1258 | cfa_temp.offset |= <const_int> | |
1259 | ||
1260 | Rule 8: | |
1261 | (set <reg> (high <exp>)) | |
1262 | effects: none | |
1263 | ||
1264 | Rule 9: | |
1265 | (set <reg> (lo_sum <exp> <const_int>)) | |
1266 | effects: cfa_temp.reg = <reg> | |
1267 | cfa_temp.offset = <const_int> | |
1268 | ||
1269 | Rule 10: | |
1270 | (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>) | |
1271 | effects: cfa_store.offset -= <const_int> | |
1272 | cfa.offset = cfa_store.offset if cfa.reg == sp | |
770ca8c6 | 1273 | cfa.reg = sp |
19ec6a36 | 1274 | cfa.base_offset = -cfa_store.offset |
770ca8c6 JO |
1275 | |
1276 | Rule 11: | |
1277 | (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>) | |
1278 | effects: cfa_store.offset += -/+ mode_size(mem) | |
1279 | cfa.offset = cfa_store.offset if cfa.reg == sp | |
770ca8c6 | 1280 | cfa.reg = sp |
19ec6a36 | 1281 | cfa.base_offset = -cfa_store.offset |
770ca8c6 JO |
1282 | |
1283 | Rule 12: | |
2ad9852d RK |
1284 | (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) |
1285 | ||
1286 | <reg2>) | |
19ec6a36 AM |
1287 | effects: cfa.reg = <reg1> |
1288 | cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset | |
770ca8c6 JO |
1289 | |
1290 | Rule 13: | |
19ec6a36 AM |
1291 | (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>) |
1292 | effects: cfa.reg = <reg1> | |
1293 | cfa.base_offset = -{cfa_store,cfa_temp}.offset | |
1294 | ||
1295 | Rule 14: | |
1296 | (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>) | |
1297 | effects: cfa.reg = <reg1> | |
1298 | cfa.base_offset = -cfa_temp.offset | |
1299 | cfa_temp.offset -= mode_size(mem) */ | |
b664de3a AM |
1300 | |
1301 | static void | |
1302 | dwarf2out_frame_debug_expr (expr, label) | |
1303 | rtx expr; | |
d3e3972c | 1304 | const char *label; |
b664de3a AM |
1305 | { |
1306 | rtx src, dest; | |
2ad9852d | 1307 | HOST_WIDE_INT offset; |
556273e0 KH |
1308 | |
1309 | /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of | |
1310 | the PARALLEL independently. The first element is always processed if | |
770ca8c6 | 1311 | it is a SET. This is for backward compatibility. Other elements |
556273e0 KH |
1312 | are processed only if they are SETs and the RTX_FRAME_RELATED_P |
1313 | flag is set in them. */ | |
2ad9852d | 1314 | if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE) |
556273e0 | 1315 | { |
b664de3a AM |
1316 | int par_index; |
1317 | int limit = XVECLEN (expr, 0); | |
1318 | ||
1319 | for (par_index = 0; par_index < limit; par_index++) | |
2ad9852d RK |
1320 | if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET |
1321 | && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index)) | |
1322 | || par_index == 0)) | |
1323 | dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label); | |
556273e0 | 1324 | |
b664de3a AM |
1325 | return; |
1326 | } | |
556273e0 | 1327 | |
b664de3a AM |
1328 | if (GET_CODE (expr) != SET) |
1329 | abort (); | |
1330 | ||
1331 | src = SET_SRC (expr); | |
1332 | dest = SET_DEST (expr); | |
1333 | ||
1334 | switch (GET_CODE (dest)) | |
1335 | { | |
1336 | case REG: | |
770ca8c6 | 1337 | /* Rule 1 */ |
b664de3a AM |
1338 | /* Update the CFA rule wrt SP or FP. Make sure src is |
1339 | relative to the current CFA register. */ | |
1340 | switch (GET_CODE (src)) | |
556273e0 KH |
1341 | { |
1342 | /* Setting FP from SP. */ | |
1343 | case REG: | |
1344 | if (cfa.reg == (unsigned) REGNO (src)) | |
1345 | /* OK. */ | |
1346 | ; | |
626d1efd | 1347 | else |
556273e0 | 1348 | abort (); |
2c849145 JM |
1349 | |
1350 | /* We used to require that dest be either SP or FP, but the | |
1351 | ARM copies SP to a temporary register, and from there to | |
1352 | FP. So we just rely on the backends to only set | |
1353 | RTX_FRAME_RELATED_P on appropriate insns. */ | |
556273e0 | 1354 | cfa.reg = REGNO (dest); |
19ec6a36 AM |
1355 | cfa_temp.reg = cfa.reg; |
1356 | cfa_temp.offset = cfa.offset; | |
556273e0 | 1357 | break; |
b664de3a | 1358 | |
556273e0 KH |
1359 | case PLUS: |
1360 | case MINUS: | |
19ec6a36 | 1361 | case LO_SUM: |
556273e0 KH |
1362 | if (dest == stack_pointer_rtx) |
1363 | { | |
770ca8c6 | 1364 | /* Rule 2 */ |
2618f955 MM |
1365 | /* Adjusting SP. */ |
1366 | switch (GET_CODE (XEXP (src, 1))) | |
1367 | { | |
1368 | case CONST_INT: | |
1369 | offset = INTVAL (XEXP (src, 1)); | |
1370 | break; | |
1371 | case REG: | |
770ca8c6 | 1372 | if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg) |
2618f955 | 1373 | abort (); |
770ca8c6 | 1374 | offset = cfa_temp.offset; |
2618f955 MM |
1375 | break; |
1376 | default: | |
1377 | abort (); | |
1378 | } | |
1379 | ||
1380 | if (XEXP (src, 0) == hard_frame_pointer_rtx) | |
1381 | { | |
1382 | /* Restoring SP from FP in the epilogue. */ | |
7d9d8943 | 1383 | if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM) |
2618f955 | 1384 | abort (); |
7d9d8943 | 1385 | cfa.reg = STACK_POINTER_REGNUM; |
2618f955 | 1386 | } |
19ec6a36 AM |
1387 | else if (GET_CODE (src) == LO_SUM) |
1388 | /* Assume we've set the source reg of the LO_SUM from sp. */ | |
1389 | ; | |
2618f955 MM |
1390 | else if (XEXP (src, 0) != stack_pointer_rtx) |
1391 | abort (); | |
1392 | ||
19ec6a36 | 1393 | if (GET_CODE (src) != MINUS) |
2618f955 | 1394 | offset = -offset; |
7d9d8943 AM |
1395 | if (cfa.reg == STACK_POINTER_REGNUM) |
1396 | cfa.offset += offset; | |
1397 | if (cfa_store.reg == STACK_POINTER_REGNUM) | |
1398 | cfa_store.offset += offset; | |
556273e0 KH |
1399 | } |
1400 | else if (dest == hard_frame_pointer_rtx) | |
1401 | { | |
770ca8c6 | 1402 | /* Rule 3 */ |
2618f955 MM |
1403 | /* Either setting the FP from an offset of the SP, |
1404 | or adjusting the FP */ | |
2c849145 | 1405 | if (! frame_pointer_needed) |
2618f955 MM |
1406 | abort (); |
1407 | ||
2c849145 | 1408 | if (GET_CODE (XEXP (src, 0)) == REG |
7d9d8943 | 1409 | && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg |
2618f955 MM |
1410 | && GET_CODE (XEXP (src, 1)) == CONST_INT) |
1411 | { | |
2618f955 | 1412 | offset = INTVAL (XEXP (src, 1)); |
19ec6a36 | 1413 | if (GET_CODE (src) != MINUS) |
2618f955 | 1414 | offset = -offset; |
7d9d8943 AM |
1415 | cfa.offset += offset; |
1416 | cfa.reg = HARD_FRAME_POINTER_REGNUM; | |
2618f955 | 1417 | } |
556273e0 KH |
1418 | else |
1419 | abort (); | |
1420 | } | |
1421 | else | |
1422 | { | |
19ec6a36 | 1423 | if (GET_CODE (src) == MINUS) |
2618f955 | 1424 | abort (); |
b53ef1a2 | 1425 | |
770ca8c6 | 1426 | /* Rule 4 */ |
b53ef1a2 NC |
1427 | if (GET_CODE (XEXP (src, 0)) == REG |
1428 | && REGNO (XEXP (src, 0)) == cfa.reg | |
1429 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
34ce3d7b JM |
1430 | { |
1431 | /* Setting a temporary CFA register that will be copied | |
1432 | into the FP later on. */ | |
19ec6a36 | 1433 | offset = - INTVAL (XEXP (src, 1)); |
34ce3d7b JM |
1434 | cfa.offset += offset; |
1435 | cfa.reg = REGNO (dest); | |
19ec6a36 AM |
1436 | /* Or used to save regs to the stack. */ |
1437 | cfa_temp.reg = cfa.reg; | |
1438 | cfa_temp.offset = cfa.offset; | |
34ce3d7b | 1439 | } |
2ad9852d | 1440 | |
770ca8c6 | 1441 | /* Rule 5 */ |
19ec6a36 AM |
1442 | else if (GET_CODE (XEXP (src, 0)) == REG |
1443 | && REGNO (XEXP (src, 0)) == cfa_temp.reg | |
1444 | && XEXP (src, 1) == stack_pointer_rtx) | |
b53ef1a2 | 1445 | { |
00a42e21 JM |
1446 | /* Setting a scratch register that we will use instead |
1447 | of SP for saving registers to the stack. */ | |
b53ef1a2 NC |
1448 | if (cfa.reg != STACK_POINTER_REGNUM) |
1449 | abort (); | |
1450 | cfa_store.reg = REGNO (dest); | |
770ca8c6 | 1451 | cfa_store.offset = cfa.offset - cfa_temp.offset; |
b53ef1a2 | 1452 | } |
2ad9852d | 1453 | |
19ec6a36 AM |
1454 | /* Rule 9 */ |
1455 | else if (GET_CODE (src) == LO_SUM | |
1456 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
1457 | { | |
1458 | cfa_temp.reg = REGNO (dest); | |
1459 | cfa_temp.offset = INTVAL (XEXP (src, 1)); | |
1460 | } | |
1461 | else | |
1462 | abort (); | |
556273e0 KH |
1463 | } |
1464 | break; | |
b664de3a | 1465 | |
770ca8c6 | 1466 | /* Rule 6 */ |
556273e0 | 1467 | case CONST_INT: |
770ca8c6 JO |
1468 | cfa_temp.reg = REGNO (dest); |
1469 | cfa_temp.offset = INTVAL (src); | |
556273e0 | 1470 | break; |
b664de3a | 1471 | |
770ca8c6 | 1472 | /* Rule 7 */ |
556273e0 KH |
1473 | case IOR: |
1474 | if (GET_CODE (XEXP (src, 0)) != REG | |
770ca8c6 | 1475 | || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg |
2618f955 | 1476 | || GET_CODE (XEXP (src, 1)) != CONST_INT) |
556273e0 | 1477 | abort (); |
2ad9852d | 1478 | |
770ca8c6 JO |
1479 | if ((unsigned) REGNO (dest) != cfa_temp.reg) |
1480 | cfa_temp.reg = REGNO (dest); | |
1481 | cfa_temp.offset |= INTVAL (XEXP (src, 1)); | |
556273e0 | 1482 | break; |
b664de3a | 1483 | |
9ae21d2a AM |
1484 | /* Skip over HIGH, assuming it will be followed by a LO_SUM, |
1485 | which will fill in all of the bits. */ | |
1486 | /* Rule 8 */ | |
1487 | case HIGH: | |
1488 | break; | |
1489 | ||
556273e0 KH |
1490 | default: |
1491 | abort (); | |
1492 | } | |
2ad9852d | 1493 | |
7d9d8943 | 1494 | def_cfa_1 (label, &cfa); |
2618f955 | 1495 | break; |
b664de3a | 1496 | |
2618f955 | 1497 | case MEM: |
2618f955 MM |
1498 | if (GET_CODE (src) != REG) |
1499 | abort (); | |
7d9d8943 | 1500 | |
7d9d8943 AM |
1501 | /* Saving a register to the stack. Make sure dest is relative to the |
1502 | CFA register. */ | |
2618f955 MM |
1503 | switch (GET_CODE (XEXP (dest, 0))) |
1504 | { | |
770ca8c6 | 1505 | /* Rule 10 */ |
2618f955 | 1506 | /* With a push. */ |
e2134eea JH |
1507 | case PRE_MODIFY: |
1508 | /* We can't handle variable size modifications. */ | |
1509 | if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT) | |
173bf5be | 1510 | abort (); |
e2134eea JH |
1511 | offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1)); |
1512 | ||
1513 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM | |
1514 | || cfa_store.reg != STACK_POINTER_REGNUM) | |
1515 | abort (); | |
2ad9852d | 1516 | |
e2134eea JH |
1517 | cfa_store.offset += offset; |
1518 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1519 | cfa.offset = cfa_store.offset; | |
1520 | ||
1521 | offset = -cfa_store.offset; | |
1522 | break; | |
2ad9852d | 1523 | |
770ca8c6 | 1524 | /* Rule 11 */ |
2618f955 MM |
1525 | case PRE_INC: |
1526 | case PRE_DEC: | |
1527 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1528 | if (GET_CODE (XEXP (dest, 0)) == PRE_INC) | |
1529 | offset = -offset; | |
b664de3a | 1530 | |
2618f955 | 1531 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM |
7d9d8943 | 1532 | || cfa_store.reg != STACK_POINTER_REGNUM) |
2618f955 | 1533 | abort (); |
2ad9852d | 1534 | |
7d9d8943 AM |
1535 | cfa_store.offset += offset; |
1536 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1537 | cfa.offset = cfa_store.offset; | |
b664de3a | 1538 | |
7d9d8943 | 1539 | offset = -cfa_store.offset; |
2618f955 | 1540 | break; |
b664de3a | 1541 | |
770ca8c6 | 1542 | /* Rule 12 */ |
2618f955 MM |
1543 | /* With an offset. */ |
1544 | case PLUS: | |
1545 | case MINUS: | |
19ec6a36 | 1546 | case LO_SUM: |
770ca8c6 JO |
1547 | if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT) |
1548 | abort (); | |
2618f955 MM |
1549 | offset = INTVAL (XEXP (XEXP (dest, 0), 1)); |
1550 | if (GET_CODE (XEXP (dest, 0)) == MINUS) | |
1551 | offset = -offset; | |
b664de3a | 1552 | |
19ec6a36 AM |
1553 | if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) |
1554 | offset -= cfa_store.offset; | |
1555 | else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) | |
1556 | offset -= cfa_temp.offset; | |
1557 | else | |
2618f955 | 1558 | abort (); |
2618f955 MM |
1559 | break; |
1560 | ||
770ca8c6 | 1561 | /* Rule 13 */ |
2618f955 MM |
1562 | /* Without an offset. */ |
1563 | case REG: | |
19ec6a36 AM |
1564 | if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0))) |
1565 | offset = -cfa_store.offset; | |
1566 | else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0))) | |
1567 | offset = -cfa_temp.offset; | |
1568 | else | |
556273e0 | 1569 | abort (); |
19ec6a36 AM |
1570 | break; |
1571 | ||
1572 | /* Rule 14 */ | |
1573 | case POST_INC: | |
1574 | if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) | |
1575 | abort (); | |
1576 | offset = -cfa_temp.offset; | |
1577 | cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest)); | |
2618f955 MM |
1578 | break; |
1579 | ||
1580 | default: | |
1581 | abort (); | |
1582 | } | |
e09bbb25 | 1583 | |
556273e0 | 1584 | if (REGNO (src) != STACK_POINTER_REGNUM |
e09bbb25 JM |
1585 | && REGNO (src) != HARD_FRAME_POINTER_REGNUM |
1586 | && (unsigned) REGNO (src) == cfa.reg) | |
1587 | { | |
1588 | /* We're storing the current CFA reg into the stack. */ | |
1589 | ||
1590 | if (cfa.offset == 0) | |
1591 | { | |
1592 | /* If the source register is exactly the CFA, assume | |
1593 | we're saving SP like any other register; this happens | |
1594 | on the ARM. */ | |
e09bbb25 | 1595 | def_cfa_1 (label, &cfa); |
fbfa55b0 | 1596 | queue_reg_save (label, stack_pointer_rtx, offset); |
e09bbb25 JM |
1597 | break; |
1598 | } | |
1599 | else | |
1600 | { | |
1601 | /* Otherwise, we'll need to look in the stack to | |
1602 | calculate the CFA. */ | |
e09bbb25 | 1603 | rtx x = XEXP (dest, 0); |
2ad9852d | 1604 | |
e09bbb25 JM |
1605 | if (GET_CODE (x) != REG) |
1606 | x = XEXP (x, 0); | |
1607 | if (GET_CODE (x) != REG) | |
1608 | abort (); | |
2ad9852d RK |
1609 | |
1610 | cfa.reg = REGNO (x); | |
e09bbb25 JM |
1611 | cfa.base_offset = offset; |
1612 | cfa.indirect = 1; | |
1613 | def_cfa_1 (label, &cfa); | |
1614 | break; | |
1615 | } | |
1616 | } | |
1617 | ||
7d9d8943 | 1618 | def_cfa_1 (label, &cfa); |
fbfa55b0 | 1619 | queue_reg_save (label, src, offset); |
2618f955 MM |
1620 | break; |
1621 | ||
1622 | default: | |
1623 | abort (); | |
1624 | } | |
b664de3a AM |
1625 | } |
1626 | ||
3f76745e JM |
1627 | /* Record call frame debugging information for INSN, which either |
1628 | sets SP or FP (adjusting how we calculate the frame address) or saves a | |
1629 | register to the stack. If INSN is NULL_RTX, initialize our state. */ | |
71dfc51f | 1630 | |
3f76745e JM |
1631 | void |
1632 | dwarf2out_frame_debug (insn) | |
1633 | rtx insn; | |
a3f97cbb | 1634 | { |
d3e3972c | 1635 | const char *label; |
b664de3a | 1636 | rtx src; |
3f76745e JM |
1637 | |
1638 | if (insn == NULL_RTX) | |
a3f97cbb | 1639 | { |
fbfa55b0 RH |
1640 | /* Flush any queued register saves. */ |
1641 | flush_queued_reg_saves (); | |
1642 | ||
3f76745e | 1643 | /* Set up state for generating call frame debug info. */ |
7d9d8943 AM |
1644 | lookup_cfa (&cfa); |
1645 | if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)) | |
3a88cbd1 | 1646 | abort (); |
2ad9852d | 1647 | |
7d9d8943 AM |
1648 | cfa.reg = STACK_POINTER_REGNUM; |
1649 | cfa_store = cfa; | |
770ca8c6 JO |
1650 | cfa_temp.reg = -1; |
1651 | cfa_temp.offset = 0; | |
3f76745e JM |
1652 | return; |
1653 | } | |
1654 | ||
fbfa55b0 RH |
1655 | if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn)) |
1656 | flush_queued_reg_saves (); | |
1657 | ||
0021b564 JM |
1658 | if (! RTX_FRAME_RELATED_P (insn)) |
1659 | { | |
fbfa55b0 | 1660 | if (!ACCUMULATE_OUTGOING_ARGS) |
c26fbbca | 1661 | dwarf2out_stack_adjust (insn); |
2ad9852d | 1662 | |
0021b564 JM |
1663 | return; |
1664 | } | |
1665 | ||
3f76745e | 1666 | label = dwarf2out_cfi_label (); |
07ebc930 RH |
1667 | src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX); |
1668 | if (src) | |
1669 | insn = XEXP (src, 0); | |
556273e0 | 1670 | else |
07ebc930 RH |
1671 | insn = PATTERN (insn); |
1672 | ||
b664de3a | 1673 | dwarf2out_frame_debug_expr (insn, label); |
3f76745e JM |
1674 | } |
1675 | ||
3f76745e JM |
1676 | /* Output a Call Frame Information opcode and its operand(s). */ |
1677 | ||
1678 | static void | |
12f0b96b | 1679 | output_cfi (cfi, fde, for_eh) |
b3694847 SS |
1680 | dw_cfi_ref cfi; |
1681 | dw_fde_ref fde; | |
12f0b96b | 1682 | int for_eh; |
3f76745e JM |
1683 | { |
1684 | if (cfi->dw_cfi_opc == DW_CFA_advance_loc) | |
2ad9852d RK |
1685 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1686 | | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)), | |
1687 | "DW_CFA_advance_loc 0x%lx", | |
1688 | cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
3f76745e JM |
1689 | else if (cfi->dw_cfi_opc == DW_CFA_offset) |
1690 | { | |
2e4b9b8c RH |
1691 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1692 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)), | |
1693 | "DW_CFA_offset, column 0x%lx", | |
1694 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1695 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); | |
3f76745e JM |
1696 | } |
1697 | else if (cfi->dw_cfi_opc == DW_CFA_restore) | |
2ad9852d RK |
1698 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1699 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)), | |
1700 | "DW_CFA_restore, column 0x%lx", | |
1701 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
3f76745e JM |
1702 | else |
1703 | { | |
2e4b9b8c RH |
1704 | dw2_asm_output_data (1, cfi->dw_cfi_opc, |
1705 | "%s", dwarf_cfi_name (cfi->dw_cfi_opc)); | |
3f76745e | 1706 | |
3f76745e JM |
1707 | switch (cfi->dw_cfi_opc) |
1708 | { | |
1709 | case DW_CFA_set_loc: | |
e1f9550a RH |
1710 | if (for_eh) |
1711 | dw2_asm_output_encoded_addr_rtx ( | |
1712 | ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0), | |
1713 | gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr), | |
1714 | NULL); | |
1715 | else | |
1716 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, | |
1717 | cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL); | |
3f76745e | 1718 | break; |
2ad9852d | 1719 | |
3f76745e | 1720 | case DW_CFA_advance_loc1: |
2e4b9b8c RH |
1721 | dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1722 | fde->dw_fde_current_label, NULL); | |
bb727b5a | 1723 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
3f76745e | 1724 | break; |
2ad9852d | 1725 | |
3f76745e | 1726 | case DW_CFA_advance_loc2: |
2e4b9b8c RH |
1727 | dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1728 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
1729 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
1730 | break; | |
2ad9852d | 1731 | |
3f76745e | 1732 | case DW_CFA_advance_loc4: |
2e4b9b8c RH |
1733 | dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1734 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
1735 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
1736 | break; | |
2ad9852d | 1737 | |
3f76745e | 1738 | case DW_CFA_MIPS_advance_loc8: |
2e4b9b8c RH |
1739 | dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1740 | fde->dw_fde_current_label, NULL); | |
1741 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
3f76745e | 1742 | break; |
2ad9852d | 1743 | |
3f76745e JM |
1744 | case DW_CFA_offset_extended: |
1745 | case DW_CFA_def_cfa: | |
2ad9852d RK |
1746 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, |
1747 | NULL); | |
2e4b9b8c | 1748 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); |
3f76745e | 1749 | break; |
2ad9852d | 1750 | |
6bb28965 JM |
1751 | case DW_CFA_offset_extended_sf: |
1752 | case DW_CFA_def_cfa_sf: | |
1753 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, | |
1754 | NULL); | |
1755 | dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); | |
1756 | break; | |
1757 | ||
3f76745e JM |
1758 | case DW_CFA_restore_extended: |
1759 | case DW_CFA_undefined: | |
3f76745e JM |
1760 | case DW_CFA_same_value: |
1761 | case DW_CFA_def_cfa_register: | |
2ad9852d RK |
1762 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, |
1763 | NULL); | |
3f76745e | 1764 | break; |
2ad9852d | 1765 | |
3f76745e | 1766 | case DW_CFA_register: |
2ad9852d RK |
1767 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, |
1768 | NULL); | |
1769 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, | |
1770 | NULL); | |
3f76745e | 1771 | break; |
2ad9852d | 1772 | |
3f76745e | 1773 | case DW_CFA_def_cfa_offset: |
2e4b9b8c RH |
1774 | case DW_CFA_GNU_args_size: |
1775 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL); | |
3f76745e | 1776 | break; |
2ad9852d | 1777 | |
6bb28965 JM |
1778 | case DW_CFA_def_cfa_offset_sf: |
1779 | dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL); | |
1780 | break; | |
1781 | ||
c53aa195 JM |
1782 | case DW_CFA_GNU_window_save: |
1783 | break; | |
2ad9852d | 1784 | |
7d9d8943 | 1785 | case DW_CFA_def_cfa_expression: |
6bb28965 | 1786 | case DW_CFA_expression: |
7d9d8943 AM |
1787 | output_cfa_loc (cfi); |
1788 | break; | |
2ad9852d | 1789 | |
6bb28965 JM |
1790 | case DW_CFA_GNU_negative_offset_extended: |
1791 | /* Obsoleted by DW_CFA_offset_extended_sf. */ | |
1792 | abort (); | |
1793 | ||
3f76745e JM |
1794 | default: |
1795 | break; | |
1796 | } | |
556273e0 | 1797 | } |
3f76745e JM |
1798 | } |
1799 | ||
1800 | /* Output the call frame information used to used to record information | |
1801 | that relates to calculating the frame pointer, and records the | |
1802 | location of saved registers. */ | |
1803 | ||
1804 | static void | |
1805 | output_call_frame_info (for_eh) | |
1806 | int for_eh; | |
1807 | { | |
b3694847 SS |
1808 | unsigned int i; |
1809 | dw_fde_ref fde; | |
1810 | dw_cfi_ref cfi; | |
27d95cbe | 1811 | char l1[20], l2[20], section_start_label[20]; |
52a11cbf RH |
1812 | int any_lsda_needed = 0; |
1813 | char augmentation[6]; | |
e1f9550a RH |
1814 | int augmentation_size; |
1815 | int fde_encoding = DW_EH_PE_absptr; | |
1816 | int per_encoding = DW_EH_PE_absptr; | |
1817 | int lsda_encoding = DW_EH_PE_absptr; | |
3f76745e | 1818 | |
29b91443 JM |
1819 | /* Don't emit a CIE if there won't be any FDEs. */ |
1820 | if (fde_table_in_use == 0) | |
1821 | return; | |
1822 | ||
2ad9852d RK |
1823 | /* If we don't have any functions we'll want to unwind out of, don't emit any |
1824 | EH unwind information. */ | |
737faf14 JM |
1825 | if (for_eh) |
1826 | { | |
b932f770 | 1827 | int any_eh_needed = flag_asynchronous_unwind_tables; |
2ad9852d RK |
1828 | |
1829 | for (i = 0; i < fde_table_in_use; i++) | |
52a11cbf RH |
1830 | if (fde_table[i].uses_eh_lsda) |
1831 | any_eh_needed = any_lsda_needed = 1; | |
1832 | else if (! fde_table[i].nothrow) | |
1833 | any_eh_needed = 1; | |
1834 | ||
1835 | if (! any_eh_needed) | |
1836 | return; | |
737faf14 JM |
1837 | } |
1838 | ||
aa0c1401 JL |
1839 | /* We're going to be generating comments, so turn on app. */ |
1840 | if (flag_debug_asm) | |
1841 | app_enable (); | |
956d6950 | 1842 | |
3f76745e | 1843 | if (for_eh) |
07c9d2eb | 1844 | (*targetm.asm_out.eh_frame_section) (); |
3f76745e | 1845 | else |
715bdd29 | 1846 | named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG); |
3f76745e | 1847 | |
27d95cbe RH |
1848 | ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh); |
1849 | ASM_OUTPUT_LABEL (asm_out_file, section_start_label); | |
1850 | ||
556273e0 | 1851 | /* Output the CIE. */ |
a6ab3aad JM |
1852 | ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh); |
1853 | ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh); | |
2e4b9b8c RH |
1854 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
1855 | "Length of Common Information Entry"); | |
a6ab3aad JM |
1856 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1857 | ||
2e4b9b8c RH |
1858 | /* Now that the CIE pointer is PC-relative for EH, |
1859 | use 0 to identify the CIE. */ | |
1860 | dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE), | |
1861 | (for_eh ? 0 : DW_CIE_ID), | |
1862 | "CIE Identifier Tag"); | |
3f76745e | 1863 | |
2e4b9b8c | 1864 | dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version"); |
3f76745e | 1865 | |
52a11cbf | 1866 | augmentation[0] = 0; |
e1f9550a | 1867 | augmentation_size = 0; |
52a11cbf | 1868 | if (for_eh) |
a6ab3aad | 1869 | { |
e1f9550a RH |
1870 | char *p; |
1871 | ||
52a11cbf RH |
1872 | /* Augmentation: |
1873 | z Indicates that a uleb128 is present to size the | |
1874 | augmentation section. | |
e1f9550a RH |
1875 | L Indicates the encoding (and thus presence) of |
1876 | an LSDA pointer in the FDE augmentation. | |
1877 | R Indicates a non-default pointer encoding for | |
1878 | FDE code pointers. | |
1879 | P Indicates the presence of an encoding + language | |
1880 | personality routine in the CIE augmentation. */ | |
1881 | ||
1882 | fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0); | |
1883 | per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1); | |
1884 | lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0); | |
1885 | ||
1886 | p = augmentation + 1; | |
1887 | if (eh_personality_libfunc) | |
1888 | { | |
1889 | *p++ = 'P'; | |
1890 | augmentation_size += 1 + size_of_encoded_value (per_encoding); | |
1891 | } | |
52a11cbf | 1892 | if (any_lsda_needed) |
e1f9550a RH |
1893 | { |
1894 | *p++ = 'L'; | |
1895 | augmentation_size += 1; | |
1896 | } | |
1897 | if (fde_encoding != DW_EH_PE_absptr) | |
1898 | { | |
1899 | *p++ = 'R'; | |
1900 | augmentation_size += 1; | |
1901 | } | |
1902 | if (p > augmentation + 1) | |
1903 | { | |
1904 | augmentation[0] = 'z'; | |
c26fbbca | 1905 | *p = '\0'; |
e1f9550a | 1906 | } |
099c8b17 RH |
1907 | |
1908 | /* Ug. Some platforms can't do unaligned dynamic relocations at all. */ | |
1909 | if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned) | |
1910 | { | |
1911 | int offset = ( 4 /* Length */ | |
1912 | + 4 /* CIE Id */ | |
1913 | + 1 /* CIE version */ | |
1914 | + strlen (augmentation) + 1 /* Augmentation */ | |
1915 | + size_of_uleb128 (1) /* Code alignment */ | |
1916 | + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT) | |
1917 | + 1 /* RA column */ | |
1918 | + 1 /* Augmentation size */ | |
1919 | + 1 /* Personality encoding */ ); | |
1920 | int pad = -offset & (PTR_SIZE - 1); | |
1921 | ||
1922 | augmentation_size += pad; | |
1923 | ||
1924 | /* Augmentations should be small, so there's scarce need to | |
1925 | iterate for a solution. Die if we exceed one uleb128 byte. */ | |
1926 | if (size_of_uleb128 (augmentation_size) != 1) | |
1927 | abort (); | |
1928 | } | |
a6ab3aad | 1929 | } |
3f76745e | 1930 | |
2ad9852d | 1931 | dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation"); |
2e4b9b8c | 1932 | dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor"); |
2e4b9b8c RH |
1933 | dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT, |
1934 | "CIE Data Alignment Factor"); | |
2e4b9b8c | 1935 | dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column"); |
3f76745e | 1936 | |
52a11cbf RH |
1937 | if (augmentation[0]) |
1938 | { | |
e1f9550a | 1939 | dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size"); |
52a11cbf | 1940 | if (eh_personality_libfunc) |
e1f9550a RH |
1941 | { |
1942 | dw2_asm_output_data (1, per_encoding, "Personality (%s)", | |
1943 | eh_data_format_name (per_encoding)); | |
1944 | dw2_asm_output_encoded_addr_rtx (per_encoding, | |
1945 | eh_personality_libfunc, NULL); | |
1946 | } | |
2ad9852d | 1947 | |
e1f9550a RH |
1948 | if (any_lsda_needed) |
1949 | dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)", | |
1950 | eh_data_format_name (lsda_encoding)); | |
2ad9852d | 1951 | |
e1f9550a RH |
1952 | if (fde_encoding != DW_EH_PE_absptr) |
1953 | dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)", | |
1954 | eh_data_format_name (fde_encoding)); | |
52a11cbf RH |
1955 | } |
1956 | ||
3f76745e | 1957 | for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next) |
12f0b96b | 1958 | output_cfi (cfi, NULL, for_eh); |
3f76745e JM |
1959 | |
1960 | /* Pad the CIE out to an address sized boundary. */ | |
c26fbbca | 1961 | ASM_OUTPUT_ALIGN (asm_out_file, |
12f0b96b | 1962 | floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)); |
a6ab3aad | 1963 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e JM |
1964 | |
1965 | /* Loop through all of the FDE's. */ | |
2ad9852d | 1966 | for (i = 0; i < fde_table_in_use; i++) |
3f76745e JM |
1967 | { |
1968 | fde = &fde_table[i]; | |
3f76745e | 1969 | |
52a11cbf | 1970 | /* Don't emit EH unwind info for leaf functions that don't need it. */ |
194734e9 JH |
1971 | if (!flag_asynchronous_unwind_tables && for_eh && fde->nothrow |
1972 | && ! fde->uses_eh_lsda) | |
737faf14 JM |
1973 | continue; |
1974 | ||
2e4b9b8c | 1975 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2); |
556273e0 KH |
1976 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2); |
1977 | ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2); | |
2e4b9b8c RH |
1978 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
1979 | "FDE Length"); | |
a6ab3aad JM |
1980 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1981 | ||
3f76745e | 1982 | if (for_eh) |
27d95cbe | 1983 | dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset"); |
3f76745e | 1984 | else |
27d95cbe | 1985 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label, |
2e4b9b8c | 1986 | "FDE CIE offset"); |
3f76745e | 1987 | |
e1f9550a RH |
1988 | if (for_eh) |
1989 | { | |
1990 | dw2_asm_output_encoded_addr_rtx (fde_encoding, | |
1991 | gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin), | |
1992 | "FDE initial location"); | |
1993 | dw2_asm_output_delta (size_of_encoded_value (fde_encoding), | |
c26fbbca | 1994 | fde->dw_fde_end, fde->dw_fde_begin, |
e1f9550a RH |
1995 | "FDE address range"); |
1996 | } | |
1997 | else | |
1998 | { | |
1999 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin, | |
2000 | "FDE initial location"); | |
c26fbbca KH |
2001 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, |
2002 | fde->dw_fde_end, fde->dw_fde_begin, | |
e1f9550a RH |
2003 | "FDE address range"); |
2004 | } | |
3f76745e | 2005 | |
52a11cbf RH |
2006 | if (augmentation[0]) |
2007 | { | |
e1f9550a | 2008 | if (any_lsda_needed) |
52a11cbf | 2009 | { |
099c8b17 RH |
2010 | int size = size_of_encoded_value (lsda_encoding); |
2011 | ||
2012 | if (lsda_encoding == DW_EH_PE_aligned) | |
2013 | { | |
2014 | int offset = ( 4 /* Length */ | |
2015 | + 4 /* CIE offset */ | |
2016 | + 2 * size_of_encoded_value (fde_encoding) | |
2017 | + 1 /* Augmentation size */ ); | |
2018 | int pad = -offset & (PTR_SIZE - 1); | |
2019 | ||
2020 | size += pad; | |
2021 | if (size_of_uleb128 (size) != 1) | |
2022 | abort (); | |
2023 | } | |
2024 | ||
2025 | dw2_asm_output_data_uleb128 (size, "Augmentation size"); | |
e1f9550a RH |
2026 | |
2027 | if (fde->uses_eh_lsda) | |
2028 | { | |
2029 | ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA", | |
2030 | fde->funcdef_number); | |
2031 | dw2_asm_output_encoded_addr_rtx ( | |
2032 | lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1), | |
2033 | "Language Specific Data Area"); | |
2034 | } | |
2035 | else | |
099c8b17 RH |
2036 | { |
2037 | if (lsda_encoding == DW_EH_PE_aligned) | |
2038 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); | |
2ad9852d RK |
2039 | dw2_asm_output_data |
2040 | (size_of_encoded_value (lsda_encoding), 0, | |
2041 | "Language Specific Data Area (none)"); | |
099c8b17 | 2042 | } |
52a11cbf RH |
2043 | } |
2044 | else | |
e1f9550a | 2045 | dw2_asm_output_data_uleb128 (0, "Augmentation size"); |
52a11cbf RH |
2046 | } |
2047 | ||
3f76745e JM |
2048 | /* Loop through the Call Frame Instructions associated with |
2049 | this FDE. */ | |
2050 | fde->dw_fde_current_label = fde->dw_fde_begin; | |
2051 | for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next) | |
12f0b96b | 2052 | output_cfi (cfi, fde, for_eh); |
3f76745e | 2053 | |
a6ab3aad | 2054 | /* Pad the FDE out to an address sized boundary. */ |
c26fbbca | 2055 | ASM_OUTPUT_ALIGN (asm_out_file, |
e1f9550a | 2056 | floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE))); |
a6ab3aad | 2057 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e | 2058 | } |
2e4b9b8c | 2059 | |
7c262518 | 2060 | #ifndef EH_FRAME_SECTION_NAME |
3f76745e | 2061 | if (for_eh) |
2e4b9b8c | 2062 | dw2_asm_output_data (4, 0, "End of Table"); |
3f76745e | 2063 | #endif |
a6ab3aad JM |
2064 | #ifdef MIPS_DEBUGGING_INFO |
2065 | /* Work around Irix 6 assembler bug whereby labels at the end of a section | |
2066 | get a value of 0. Putting .align 0 after the label fixes it. */ | |
2067 | ASM_OUTPUT_ALIGN (asm_out_file, 0); | |
2068 | #endif | |
aa0c1401 JL |
2069 | |
2070 | /* Turn off app to make assembly quicker. */ | |
2071 | if (flag_debug_asm) | |
2072 | app_disable (); | |
a6ab3aad JM |
2073 | } |
2074 | ||
3f76745e JM |
2075 | /* Output a marker (i.e. a label) for the beginning of a function, before |
2076 | the prologue. */ | |
2077 | ||
2078 | void | |
653e276c NB |
2079 | dwarf2out_begin_prologue (line, file) |
2080 | unsigned int line ATTRIBUTE_UNUSED; | |
2081 | const char *file ATTRIBUTE_UNUSED; | |
3f76745e JM |
2082 | { |
2083 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 | 2084 | dw_fde_ref fde; |
3f76745e | 2085 | |
2a1ee410 RH |
2086 | current_function_func_begin_label = 0; |
2087 | ||
2088 | #ifdef IA64_UNWIND_INFO | |
2089 | /* ??? current_function_func_begin_label is also used by except.c | |
2090 | for call-site information. We must emit this label if it might | |
2091 | be used. */ | |
2092 | if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS) | |
2093 | && ! dwarf2out_do_frame ()) | |
2094 | return; | |
2095 | #else | |
2096 | if (! dwarf2out_do_frame ()) | |
2097 | return; | |
2098 | #endif | |
2099 | ||
2ad9852d | 2100 | current_funcdef_number++; |
3f76745e JM |
2101 | function_section (current_function_decl); |
2102 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL, | |
2103 | current_funcdef_number); | |
2a1ee410 RH |
2104 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL, |
2105 | current_funcdef_number); | |
00262c8a | 2106 | current_function_func_begin_label = get_identifier (label); |
3f76745e | 2107 | |
2a1ee410 RH |
2108 | #ifdef IA64_UNWIND_INFO |
2109 | /* We can elide the fde allocation if we're not emitting debug info. */ | |
2110 | if (! dwarf2out_do_frame ()) | |
2111 | return; | |
2112 | #endif | |
2113 | ||
3f76745e JM |
2114 | /* Expand the fde table if necessary. */ |
2115 | if (fde_table_in_use == fde_table_allocated) | |
2116 | { | |
2117 | fde_table_allocated += FDE_TABLE_INCREMENT; | |
2118 | fde_table | |
2119 | = (dw_fde_ref) xrealloc (fde_table, | |
2120 | fde_table_allocated * sizeof (dw_fde_node)); | |
a3f97cbb | 2121 | } |
3f76745e JM |
2122 | |
2123 | /* Record the FDE associated with this function. */ | |
2124 | current_funcdef_fde = fde_table_in_use; | |
2125 | ||
2126 | /* Add the new FDE at the end of the fde_table. */ | |
2127 | fde = &fde_table[fde_table_in_use++]; | |
2128 | fde->dw_fde_begin = xstrdup (label); | |
2129 | fde->dw_fde_current_label = NULL; | |
2130 | fde->dw_fde_end = NULL; | |
2131 | fde->dw_fde_cfi = NULL; | |
52a11cbf | 2132 | fde->funcdef_number = current_funcdef_number; |
fb13d4d0 | 2133 | fde->nothrow = current_function_nothrow; |
52a11cbf | 2134 | fde->uses_eh_lsda = cfun->uses_eh_lsda; |
737faf14 | 2135 | |
b57d9225 | 2136 | args_size = old_args_size = 0; |
653e276c | 2137 | |
2ad9852d RK |
2138 | /* We only want to output line number information for the genuine dwarf2 |
2139 | prologue case, not the eh frame case. */ | |
653e276c NB |
2140 | #ifdef DWARF2_DEBUGGING_INFO |
2141 | if (file) | |
2142 | dwarf2out_source_line (line, file); | |
2143 | #endif | |
3f76745e JM |
2144 | } |
2145 | ||
2146 | /* Output a marker (i.e. a label) for the absolute end of the generated code | |
2147 | for a function definition. This gets called *after* the epilogue code has | |
2148 | been generated. */ | |
2149 | ||
2150 | void | |
2151 | dwarf2out_end_epilogue () | |
2152 | { | |
2153 | dw_fde_ref fde; | |
2154 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2155 | ||
2156 | /* Output a label to mark the endpoint of the code generated for this | |
3ef42a0c | 2157 | function. */ |
3f76745e JM |
2158 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number); |
2159 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
2160 | fde = &fde_table[fde_table_in_use - 1]; | |
2161 | fde->dw_fde_end = xstrdup (label); | |
3f76745e JM |
2162 | } |
2163 | ||
2164 | void | |
2165 | dwarf2out_frame_init () | |
2166 | { | |
2167 | /* Allocate the initial hunk of the fde_table. */ | |
3de90026 | 2168 | fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node)); |
3f76745e JM |
2169 | fde_table_allocated = FDE_TABLE_INCREMENT; |
2170 | fde_table_in_use = 0; | |
2171 | ||
2172 | /* Generate the CFA instructions common to all FDE's. Do it now for the | |
2173 | sake of lookup_cfa. */ | |
2174 | ||
a6ab3aad | 2175 | #ifdef DWARF2_UNWIND_INFO |
91193900 AS |
2176 | /* On entry, the Canonical Frame Address is at SP. */ |
2177 | dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET); | |
2178 | initial_return_save (INCOMING_RETURN_ADDR_RTX); | |
3f76745e JM |
2179 | #endif |
2180 | } | |
2181 | ||
2182 | void | |
2183 | dwarf2out_frame_finish () | |
2184 | { | |
3f76745e | 2185 | /* Output call frame information. */ |
7a0c8d71 | 2186 | if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG) |
3f76745e | 2187 | output_call_frame_info (0); |
2ad9852d | 2188 | |
ddee9e8d | 2189 | if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions)) |
3f76745e | 2190 | output_call_frame_info (1); |
556273e0 | 2191 | } |
7d9d8943 AM |
2192 | \f |
2193 | /* And now, the subset of the debugging information support code necessary | |
2194 | for emitting location expressions. */ | |
3f76745e | 2195 | |
7d9d8943 AM |
2196 | typedef struct dw_val_struct *dw_val_ref; |
2197 | typedef struct die_struct *dw_die_ref; | |
2198 | typedef struct dw_loc_descr_struct *dw_loc_descr_ref; | |
63e46568 | 2199 | typedef struct dw_loc_list_struct *dw_loc_list_ref; |
3f76745e JM |
2200 | |
2201 | /* Each DIE may have a series of attribute/value pairs. Values | |
2202 | can take on several forms. The forms that are used in this | |
2203 | implementation are listed below. */ | |
2204 | ||
2205 | typedef enum | |
2206 | { | |
2207 | dw_val_class_addr, | |
a20612aa | 2208 | dw_val_class_offset, |
3f76745e | 2209 | dw_val_class_loc, |
63e46568 | 2210 | dw_val_class_loc_list, |
2bee6045 | 2211 | dw_val_class_range_list, |
3f76745e JM |
2212 | dw_val_class_const, |
2213 | dw_val_class_unsigned_const, | |
2214 | dw_val_class_long_long, | |
2215 | dw_val_class_float, | |
2216 | dw_val_class_flag, | |
2217 | dw_val_class_die_ref, | |
2218 | dw_val_class_fde_ref, | |
2219 | dw_val_class_lbl_id, | |
8b790721 | 2220 | dw_val_class_lbl_offset, |
3f76745e | 2221 | dw_val_class_str |
a3f97cbb | 2222 | } |
3f76745e | 2223 | dw_val_class; |
a3f97cbb | 2224 | |
3f76745e | 2225 | /* Describe a double word constant value. */ |
21217bd0 | 2226 | /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */ |
3f76745e JM |
2227 | |
2228 | typedef struct dw_long_long_struct | |
a3f97cbb | 2229 | { |
3f76745e JM |
2230 | unsigned long hi; |
2231 | unsigned long low; | |
2232 | } | |
2233 | dw_long_long_const; | |
2234 | ||
2235 | /* Describe a floating point constant value. */ | |
2236 | ||
2237 | typedef struct dw_fp_struct | |
2238 | { | |
2239 | long *array; | |
2240 | unsigned length; | |
2241 | } | |
2242 | dw_float_const; | |
2243 | ||
956d6950 | 2244 | /* The dw_val_node describes an attribute's value, as it is |
3f76745e JM |
2245 | represented internally. */ |
2246 | ||
2247 | typedef struct dw_val_struct | |
2248 | { | |
2249 | dw_val_class val_class; | |
2250 | union | |
a3f97cbb | 2251 | { |
1865dbb5 | 2252 | rtx val_addr; |
a20612aa | 2253 | long unsigned val_offset; |
63e46568 | 2254 | dw_loc_list_ref val_loc_list; |
3f76745e JM |
2255 | dw_loc_descr_ref val_loc; |
2256 | long int val_int; | |
2257 | long unsigned val_unsigned; | |
2258 | dw_long_long_const val_long_long; | |
2259 | dw_float_const val_float; | |
2ad9852d RK |
2260 | struct |
2261 | { | |
2262 | dw_die_ref die; | |
2263 | int external; | |
2264 | } val_die_ref; | |
3f76745e | 2265 | unsigned val_fde_index; |
9eb4015a | 2266 | struct indirect_string_node *val_str; |
3f76745e | 2267 | char *val_lbl_id; |
3f76745e | 2268 | unsigned char val_flag; |
a3f97cbb | 2269 | } |
3f76745e JM |
2270 | v; |
2271 | } | |
2272 | dw_val_node; | |
2273 | ||
2274 | /* Locations in memory are described using a sequence of stack machine | |
2275 | operations. */ | |
2276 | ||
2277 | typedef struct dw_loc_descr_struct | |
2278 | { | |
2279 | dw_loc_descr_ref dw_loc_next; | |
2280 | enum dwarf_location_atom dw_loc_opc; | |
2281 | dw_val_node dw_loc_oprnd1; | |
2282 | dw_val_node dw_loc_oprnd2; | |
d8041cc8 | 2283 | int dw_loc_addr; |
3f76745e JM |
2284 | } |
2285 | dw_loc_descr_node; | |
2286 | ||
63e46568 DB |
2287 | /* Location lists are ranges + location descriptions for that range, |
2288 | so you can track variables that are in different places over | |
30f7a378 | 2289 | their entire life. */ |
63e46568 DB |
2290 | typedef struct dw_loc_list_struct |
2291 | { | |
2292 | dw_loc_list_ref dw_loc_next; | |
2293 | const char *begin; /* Label for begin address of range */ | |
2294 | const char *end; /* Label for end address of range */ | |
2ad9852d RK |
2295 | char *ll_symbol; /* Label for beginning of location list. |
2296 | Only on head of list */ | |
63e46568 DB |
2297 | const char *section; /* Section this loclist is relative to */ |
2298 | dw_loc_descr_ref expr; | |
2299 | } dw_loc_list_node; | |
2300 | ||
7d9d8943 AM |
2301 | static const char *dwarf_stack_op_name PARAMS ((unsigned)); |
2302 | static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom, | |
2303 | unsigned long, | |
2304 | unsigned long)); | |
2305 | static void add_loc_descr PARAMS ((dw_loc_descr_ref *, | |
2306 | dw_loc_descr_ref)); | |
2307 | static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref)); | |
2308 | static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref)); | |
2309 | static void output_loc_operands PARAMS ((dw_loc_descr_ref)); | |
2310 | static void output_loc_sequence PARAMS ((dw_loc_descr_ref)); | |
3f76745e | 2311 | |
7d9d8943 | 2312 | /* Convert a DWARF stack opcode into its string name. */ |
3f76745e | 2313 | |
7d9d8943 AM |
2314 | static const char * |
2315 | dwarf_stack_op_name (op) | |
b3694847 | 2316 | unsigned op; |
ef76d03b | 2317 | { |
7d9d8943 AM |
2318 | switch (op) |
2319 | { | |
2320 | case DW_OP_addr: | |
2321 | return "DW_OP_addr"; | |
2322 | case DW_OP_deref: | |
2323 | return "DW_OP_deref"; | |
2324 | case DW_OP_const1u: | |
2325 | return "DW_OP_const1u"; | |
2326 | case DW_OP_const1s: | |
2327 | return "DW_OP_const1s"; | |
2328 | case DW_OP_const2u: | |
2329 | return "DW_OP_const2u"; | |
2330 | case DW_OP_const2s: | |
2331 | return "DW_OP_const2s"; | |
2332 | case DW_OP_const4u: | |
2333 | return "DW_OP_const4u"; | |
2334 | case DW_OP_const4s: | |
2335 | return "DW_OP_const4s"; | |
2336 | case DW_OP_const8u: | |
2337 | return "DW_OP_const8u"; | |
2338 | case DW_OP_const8s: | |
2339 | return "DW_OP_const8s"; | |
2340 | case DW_OP_constu: | |
2341 | return "DW_OP_constu"; | |
2342 | case DW_OP_consts: | |
2343 | return "DW_OP_consts"; | |
2344 | case DW_OP_dup: | |
2345 | return "DW_OP_dup"; | |
2346 | case DW_OP_drop: | |
2347 | return "DW_OP_drop"; | |
2348 | case DW_OP_over: | |
2349 | return "DW_OP_over"; | |
2350 | case DW_OP_pick: | |
2351 | return "DW_OP_pick"; | |
2352 | case DW_OP_swap: | |
2353 | return "DW_OP_swap"; | |
2354 | case DW_OP_rot: | |
2355 | return "DW_OP_rot"; | |
2356 | case DW_OP_xderef: | |
2357 | return "DW_OP_xderef"; | |
2358 | case DW_OP_abs: | |
2359 | return "DW_OP_abs"; | |
2360 | case DW_OP_and: | |
2361 | return "DW_OP_and"; | |
2362 | case DW_OP_div: | |
2363 | return "DW_OP_div"; | |
2364 | case DW_OP_minus: | |
2365 | return "DW_OP_minus"; | |
2366 | case DW_OP_mod: | |
2367 | return "DW_OP_mod"; | |
2368 | case DW_OP_mul: | |
2369 | return "DW_OP_mul"; | |
2370 | case DW_OP_neg: | |
2371 | return "DW_OP_neg"; | |
2372 | case DW_OP_not: | |
2373 | return "DW_OP_not"; | |
2374 | case DW_OP_or: | |
2375 | return "DW_OP_or"; | |
2376 | case DW_OP_plus: | |
2377 | return "DW_OP_plus"; | |
2378 | case DW_OP_plus_uconst: | |
2379 | return "DW_OP_plus_uconst"; | |
2380 | case DW_OP_shl: | |
2381 | return "DW_OP_shl"; | |
2382 | case DW_OP_shr: | |
2383 | return "DW_OP_shr"; | |
2384 | case DW_OP_shra: | |
2385 | return "DW_OP_shra"; | |
2386 | case DW_OP_xor: | |
2387 | return "DW_OP_xor"; | |
2388 | case DW_OP_bra: | |
2389 | return "DW_OP_bra"; | |
2390 | case DW_OP_eq: | |
2391 | return "DW_OP_eq"; | |
2392 | case DW_OP_ge: | |
2393 | return "DW_OP_ge"; | |
2394 | case DW_OP_gt: | |
2395 | return "DW_OP_gt"; | |
2396 | case DW_OP_le: | |
2397 | return "DW_OP_le"; | |
2398 | case DW_OP_lt: | |
2399 | return "DW_OP_lt"; | |
2400 | case DW_OP_ne: | |
2401 | return "DW_OP_ne"; | |
2402 | case DW_OP_skip: | |
2403 | return "DW_OP_skip"; | |
2404 | case DW_OP_lit0: | |
2405 | return "DW_OP_lit0"; | |
2406 | case DW_OP_lit1: | |
2407 | return "DW_OP_lit1"; | |
2408 | case DW_OP_lit2: | |
2409 | return "DW_OP_lit2"; | |
2410 | case DW_OP_lit3: | |
2411 | return "DW_OP_lit3"; | |
2412 | case DW_OP_lit4: | |
2413 | return "DW_OP_lit4"; | |
2414 | case DW_OP_lit5: | |
2415 | return "DW_OP_lit5"; | |
2416 | case DW_OP_lit6: | |
2417 | return "DW_OP_lit6"; | |
2418 | case DW_OP_lit7: | |
2419 | return "DW_OP_lit7"; | |
2420 | case DW_OP_lit8: | |
2421 | return "DW_OP_lit8"; | |
2422 | case DW_OP_lit9: | |
2423 | return "DW_OP_lit9"; | |
2424 | case DW_OP_lit10: | |
2425 | return "DW_OP_lit10"; | |
2426 | case DW_OP_lit11: | |
2427 | return "DW_OP_lit11"; | |
2428 | case DW_OP_lit12: | |
2429 | return "DW_OP_lit12"; | |
2430 | case DW_OP_lit13: | |
2431 | return "DW_OP_lit13"; | |
2432 | case DW_OP_lit14: | |
2433 | return "DW_OP_lit14"; | |
2434 | case DW_OP_lit15: | |
2435 | return "DW_OP_lit15"; | |
2436 | case DW_OP_lit16: | |
2437 | return "DW_OP_lit16"; | |
2438 | case DW_OP_lit17: | |
2439 | return "DW_OP_lit17"; | |
2440 | case DW_OP_lit18: | |
2441 | return "DW_OP_lit18"; | |
2442 | case DW_OP_lit19: | |
2443 | return "DW_OP_lit19"; | |
2444 | case DW_OP_lit20: | |
2445 | return "DW_OP_lit20"; | |
2446 | case DW_OP_lit21: | |
2447 | return "DW_OP_lit21"; | |
2448 | case DW_OP_lit22: | |
2449 | return "DW_OP_lit22"; | |
2450 | case DW_OP_lit23: | |
2451 | return "DW_OP_lit23"; | |
2452 | case DW_OP_lit24: | |
2453 | return "DW_OP_lit24"; | |
2454 | case DW_OP_lit25: | |
2455 | return "DW_OP_lit25"; | |
2456 | case DW_OP_lit26: | |
2457 | return "DW_OP_lit26"; | |
2458 | case DW_OP_lit27: | |
2459 | return "DW_OP_lit27"; | |
2460 | case DW_OP_lit28: | |
2461 | return "DW_OP_lit28"; | |
2462 | case DW_OP_lit29: | |
2463 | return "DW_OP_lit29"; | |
2464 | case DW_OP_lit30: | |
2465 | return "DW_OP_lit30"; | |
2466 | case DW_OP_lit31: | |
2467 | return "DW_OP_lit31"; | |
2468 | case DW_OP_reg0: | |
2469 | return "DW_OP_reg0"; | |
2470 | case DW_OP_reg1: | |
2471 | return "DW_OP_reg1"; | |
2472 | case DW_OP_reg2: | |
2473 | return "DW_OP_reg2"; | |
2474 | case DW_OP_reg3: | |
2475 | return "DW_OP_reg3"; | |
2476 | case DW_OP_reg4: | |
2477 | return "DW_OP_reg4"; | |
2478 | case DW_OP_reg5: | |
2479 | return "DW_OP_reg5"; | |
2480 | case DW_OP_reg6: | |
2481 | return "DW_OP_reg6"; | |
2482 | case DW_OP_reg7: | |
2483 | return "DW_OP_reg7"; | |
2484 | case DW_OP_reg8: | |
2485 | return "DW_OP_reg8"; | |
2486 | case DW_OP_reg9: | |
2487 | return "DW_OP_reg9"; | |
2488 | case DW_OP_reg10: | |
2489 | return "DW_OP_reg10"; | |
2490 | case DW_OP_reg11: | |
2491 | return "DW_OP_reg11"; | |
2492 | case DW_OP_reg12: | |
2493 | return "DW_OP_reg12"; | |
2494 | case DW_OP_reg13: | |
2495 | return "DW_OP_reg13"; | |
2496 | case DW_OP_reg14: | |
2497 | return "DW_OP_reg14"; | |
2498 | case DW_OP_reg15: | |
2499 | return "DW_OP_reg15"; | |
2500 | case DW_OP_reg16: | |
2501 | return "DW_OP_reg16"; | |
2502 | case DW_OP_reg17: | |
2503 | return "DW_OP_reg17"; | |
2504 | case DW_OP_reg18: | |
2505 | return "DW_OP_reg18"; | |
2506 | case DW_OP_reg19: | |
2507 | return "DW_OP_reg19"; | |
2508 | case DW_OP_reg20: | |
2509 | return "DW_OP_reg20"; | |
2510 | case DW_OP_reg21: | |
2511 | return "DW_OP_reg21"; | |
2512 | case DW_OP_reg22: | |
2513 | return "DW_OP_reg22"; | |
2514 | case DW_OP_reg23: | |
2515 | return "DW_OP_reg23"; | |
2516 | case DW_OP_reg24: | |
2517 | return "DW_OP_reg24"; | |
2518 | case DW_OP_reg25: | |
2519 | return "DW_OP_reg25"; | |
2520 | case DW_OP_reg26: | |
2521 | return "DW_OP_reg26"; | |
2522 | case DW_OP_reg27: | |
2523 | return "DW_OP_reg27"; | |
2524 | case DW_OP_reg28: | |
2525 | return "DW_OP_reg28"; | |
2526 | case DW_OP_reg29: | |
2527 | return "DW_OP_reg29"; | |
2528 | case DW_OP_reg30: | |
2529 | return "DW_OP_reg30"; | |
2530 | case DW_OP_reg31: | |
2531 | return "DW_OP_reg31"; | |
2532 | case DW_OP_breg0: | |
2533 | return "DW_OP_breg0"; | |
2534 | case DW_OP_breg1: | |
2535 | return "DW_OP_breg1"; | |
2536 | case DW_OP_breg2: | |
2537 | return "DW_OP_breg2"; | |
2538 | case DW_OP_breg3: | |
2539 | return "DW_OP_breg3"; | |
2540 | case DW_OP_breg4: | |
2541 | return "DW_OP_breg4"; | |
2542 | case DW_OP_breg5: | |
2543 | return "DW_OP_breg5"; | |
2544 | case DW_OP_breg6: | |
2545 | return "DW_OP_breg6"; | |
2546 | case DW_OP_breg7: | |
2547 | return "DW_OP_breg7"; | |
2548 | case DW_OP_breg8: | |
2549 | return "DW_OP_breg8"; | |
2550 | case DW_OP_breg9: | |
2551 | return "DW_OP_breg9"; | |
2552 | case DW_OP_breg10: | |
2553 | return "DW_OP_breg10"; | |
2554 | case DW_OP_breg11: | |
2555 | return "DW_OP_breg11"; | |
2556 | case DW_OP_breg12: | |
2557 | return "DW_OP_breg12"; | |
2558 | case DW_OP_breg13: | |
2559 | return "DW_OP_breg13"; | |
2560 | case DW_OP_breg14: | |
2561 | return "DW_OP_breg14"; | |
2562 | case DW_OP_breg15: | |
2563 | return "DW_OP_breg15"; | |
2564 | case DW_OP_breg16: | |
2565 | return "DW_OP_breg16"; | |
2566 | case DW_OP_breg17: | |
2567 | return "DW_OP_breg17"; | |
2568 | case DW_OP_breg18: | |
2569 | return "DW_OP_breg18"; | |
2570 | case DW_OP_breg19: | |
2571 | return "DW_OP_breg19"; | |
2572 | case DW_OP_breg20: | |
2573 | return "DW_OP_breg20"; | |
2574 | case DW_OP_breg21: | |
2575 | return "DW_OP_breg21"; | |
2576 | case DW_OP_breg22: | |
2577 | return "DW_OP_breg22"; | |
2578 | case DW_OP_breg23: | |
2579 | return "DW_OP_breg23"; | |
2580 | case DW_OP_breg24: | |
2581 | return "DW_OP_breg24"; | |
2582 | case DW_OP_breg25: | |
2583 | return "DW_OP_breg25"; | |
2584 | case DW_OP_breg26: | |
2585 | return "DW_OP_breg26"; | |
2586 | case DW_OP_breg27: | |
2587 | return "DW_OP_breg27"; | |
2588 | case DW_OP_breg28: | |
2589 | return "DW_OP_breg28"; | |
2590 | case DW_OP_breg29: | |
2591 | return "DW_OP_breg29"; | |
2592 | case DW_OP_breg30: | |
2593 | return "DW_OP_breg30"; | |
2594 | case DW_OP_breg31: | |
2595 | return "DW_OP_breg31"; | |
2596 | case DW_OP_regx: | |
2597 | return "DW_OP_regx"; | |
2598 | case DW_OP_fbreg: | |
2599 | return "DW_OP_fbreg"; | |
2600 | case DW_OP_bregx: | |
2601 | return "DW_OP_bregx"; | |
2602 | case DW_OP_piece: | |
2603 | return "DW_OP_piece"; | |
2604 | case DW_OP_deref_size: | |
2605 | return "DW_OP_deref_size"; | |
2606 | case DW_OP_xderef_size: | |
2607 | return "DW_OP_xderef_size"; | |
2608 | case DW_OP_nop: | |
2609 | return "DW_OP_nop"; | |
3f76745e | 2610 | default: |
7d9d8943 | 2611 | return "OP_<unknown>"; |
3f76745e | 2612 | } |
bdb669cb | 2613 | } |
a3f97cbb | 2614 | |
7d9d8943 AM |
2615 | /* Return a pointer to a newly allocated location description. Location |
2616 | descriptions are simple expression terms that can be strung | |
2617 | together to form more complicated location (address) descriptions. */ | |
2618 | ||
2619 | static inline dw_loc_descr_ref | |
2620 | new_loc_descr (op, oprnd1, oprnd2) | |
b3694847 SS |
2621 | enum dwarf_location_atom op; |
2622 | unsigned long oprnd1; | |
2623 | unsigned long oprnd2; | |
4b674448 | 2624 | { |
5de0e8d4 JM |
2625 | /* Use xcalloc here so we clear out all of the long_long constant in |
2626 | the union. */ | |
b3694847 | 2627 | dw_loc_descr_ref descr |
5de0e8d4 | 2628 | = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node)); |
71dfc51f | 2629 | |
7d9d8943 AM |
2630 | descr->dw_loc_opc = op; |
2631 | descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const; | |
2632 | descr->dw_loc_oprnd1.v.val_unsigned = oprnd1; | |
2633 | descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const; | |
2634 | descr->dw_loc_oprnd2.v.val_unsigned = oprnd2; | |
71dfc51f | 2635 | |
7d9d8943 AM |
2636 | return descr; |
2637 | } | |
2638 | ||
63e46568 | 2639 | |
7d9d8943 AM |
2640 | /* Add a location description term to a location description expression. */ |
2641 | ||
2642 | static inline void | |
2643 | add_loc_descr (list_head, descr) | |
b3694847 SS |
2644 | dw_loc_descr_ref *list_head; |
2645 | dw_loc_descr_ref descr; | |
7d9d8943 | 2646 | { |
b3694847 | 2647 | dw_loc_descr_ref *d; |
7d9d8943 AM |
2648 | |
2649 | /* Find the end of the chain. */ | |
2650 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
2651 | ; | |
2652 | ||
2653 | *d = descr; | |
2654 | } | |
2655 | ||
2656 | /* Return the size of a location descriptor. */ | |
2657 | ||
2658 | static unsigned long | |
2659 | size_of_loc_descr (loc) | |
b3694847 | 2660 | dw_loc_descr_ref loc; |
7d9d8943 | 2661 | { |
b3694847 | 2662 | unsigned long size = 1; |
7d9d8943 AM |
2663 | |
2664 | switch (loc->dw_loc_opc) | |
2665 | { | |
2666 | case DW_OP_addr: | |
2667 | size += DWARF2_ADDR_SIZE; | |
2668 | break; | |
2669 | case DW_OP_const1u: | |
2670 | case DW_OP_const1s: | |
2671 | size += 1; | |
2672 | break; | |
2673 | case DW_OP_const2u: | |
2674 | case DW_OP_const2s: | |
2675 | size += 2; | |
2676 | break; | |
2677 | case DW_OP_const4u: | |
2678 | case DW_OP_const4s: | |
2679 | size += 4; | |
2680 | break; | |
2681 | case DW_OP_const8u: | |
2682 | case DW_OP_const8s: | |
2683 | size += 8; | |
2684 | break; | |
2685 | case DW_OP_constu: | |
2686 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2687 | break; | |
2688 | case DW_OP_consts: | |
2689 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2690 | break; | |
2691 | case DW_OP_pick: | |
2692 | size += 1; | |
2693 | break; | |
2694 | case DW_OP_plus_uconst: | |
2695 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2696 | break; | |
2697 | case DW_OP_skip: | |
2698 | case DW_OP_bra: | |
2699 | size += 2; | |
2700 | break; | |
2701 | case DW_OP_breg0: | |
2702 | case DW_OP_breg1: | |
2703 | case DW_OP_breg2: | |
2704 | case DW_OP_breg3: | |
2705 | case DW_OP_breg4: | |
2706 | case DW_OP_breg5: | |
2707 | case DW_OP_breg6: | |
2708 | case DW_OP_breg7: | |
2709 | case DW_OP_breg8: | |
2710 | case DW_OP_breg9: | |
2711 | case DW_OP_breg10: | |
2712 | case DW_OP_breg11: | |
2713 | case DW_OP_breg12: | |
2714 | case DW_OP_breg13: | |
2715 | case DW_OP_breg14: | |
2716 | case DW_OP_breg15: | |
2717 | case DW_OP_breg16: | |
2718 | case DW_OP_breg17: | |
2719 | case DW_OP_breg18: | |
2720 | case DW_OP_breg19: | |
2721 | case DW_OP_breg20: | |
2722 | case DW_OP_breg21: | |
2723 | case DW_OP_breg22: | |
2724 | case DW_OP_breg23: | |
2725 | case DW_OP_breg24: | |
2726 | case DW_OP_breg25: | |
2727 | case DW_OP_breg26: | |
2728 | case DW_OP_breg27: | |
2729 | case DW_OP_breg28: | |
2730 | case DW_OP_breg29: | |
2731 | case DW_OP_breg30: | |
2732 | case DW_OP_breg31: | |
2733 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2734 | break; | |
2735 | case DW_OP_regx: | |
2736 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2737 | break; | |
2738 | case DW_OP_fbreg: | |
2739 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2740 | break; | |
2741 | case DW_OP_bregx: | |
2742 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2743 | size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int); | |
2744 | break; | |
2745 | case DW_OP_piece: | |
2746 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2747 | break; | |
2748 | case DW_OP_deref_size: | |
2749 | case DW_OP_xderef_size: | |
2750 | size += 1; | |
2751 | break; | |
3f76745e | 2752 | default: |
7d9d8943 | 2753 | break; |
4b674448 | 2754 | } |
7d9d8943 AM |
2755 | |
2756 | return size; | |
4b674448 JM |
2757 | } |
2758 | ||
7d9d8943 | 2759 | /* Return the size of a series of location descriptors. */ |
71dfc51f | 2760 | |
7d9d8943 AM |
2761 | static unsigned long |
2762 | size_of_locs (loc) | |
b3694847 | 2763 | dw_loc_descr_ref loc; |
4b674448 | 2764 | { |
2ad9852d | 2765 | unsigned long size; |
7d9d8943 | 2766 | |
2ad9852d | 2767 | for (size = 0; loc != NULL; loc = loc->dw_loc_next) |
d8041cc8 RH |
2768 | { |
2769 | loc->dw_loc_addr = size; | |
2770 | size += size_of_loc_descr (loc); | |
2771 | } | |
7d9d8943 AM |
2772 | |
2773 | return size; | |
4b674448 JM |
2774 | } |
2775 | ||
7d9d8943 | 2776 | /* Output location description stack opcode's operands (if any). */ |
71dfc51f | 2777 | |
7d9d8943 AM |
2778 | static void |
2779 | output_loc_operands (loc) | |
b3694847 | 2780 | dw_loc_descr_ref loc; |
a3f97cbb | 2781 | { |
b3694847 SS |
2782 | dw_val_ref val1 = &loc->dw_loc_oprnd1; |
2783 | dw_val_ref val2 = &loc->dw_loc_oprnd2; | |
7d9d8943 AM |
2784 | |
2785 | switch (loc->dw_loc_opc) | |
a3f97cbb | 2786 | { |
0517872a | 2787 | #ifdef DWARF2_DEBUGGING_INFO |
3f76745e | 2788 | case DW_OP_addr: |
2e4b9b8c | 2789 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL); |
7d9d8943 | 2790 | break; |
3f76745e | 2791 | case DW_OP_const2u: |
3f76745e | 2792 | case DW_OP_const2s: |
2e4b9b8c | 2793 | dw2_asm_output_data (2, val1->v.val_int, NULL); |
7d9d8943 | 2794 | break; |
3f76745e | 2795 | case DW_OP_const4u: |
3f76745e | 2796 | case DW_OP_const4s: |
2e4b9b8c | 2797 | dw2_asm_output_data (4, val1->v.val_int, NULL); |
7d9d8943 | 2798 | break; |
3f76745e | 2799 | case DW_OP_const8u: |
3f76745e | 2800 | case DW_OP_const8s: |
2e4b9b8c RH |
2801 | if (HOST_BITS_PER_LONG < 64) |
2802 | abort (); | |
2803 | dw2_asm_output_data (8, val1->v.val_int, NULL); | |
7d9d8943 | 2804 | break; |
0517872a JM |
2805 | case DW_OP_skip: |
2806 | case DW_OP_bra: | |
d8041cc8 RH |
2807 | { |
2808 | int offset; | |
2809 | ||
2810 | if (val1->val_class == dw_val_class_loc) | |
2811 | offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3); | |
2812 | else | |
2813 | abort (); | |
2814 | ||
2e4b9b8c | 2815 | dw2_asm_output_data (2, offset, NULL); |
d8041cc8 | 2816 | } |
0517872a | 2817 | break; |
3139472f JM |
2818 | #else |
2819 | case DW_OP_addr: | |
2820 | case DW_OP_const2u: | |
2821 | case DW_OP_const2s: | |
2822 | case DW_OP_const4u: | |
2823 | case DW_OP_const4s: | |
2824 | case DW_OP_const8u: | |
2825 | case DW_OP_const8s: | |
2826 | case DW_OP_skip: | |
2827 | case DW_OP_bra: | |
2828 | /* We currently don't make any attempt to make sure these are | |
2829 | aligned properly like we do for the main unwind info, so | |
2830 | don't support emitting things larger than a byte if we're | |
2831 | only doing unwinding. */ | |
2832 | abort (); | |
0517872a JM |
2833 | #endif |
2834 | case DW_OP_const1u: | |
2835 | case DW_OP_const1s: | |
2e4b9b8c | 2836 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
0517872a | 2837 | break; |
3f76745e | 2838 | case DW_OP_constu: |
2e4b9b8c | 2839 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2840 | break; |
3f76745e | 2841 | case DW_OP_consts: |
2e4b9b8c | 2842 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 AM |
2843 | break; |
2844 | case DW_OP_pick: | |
2e4b9b8c | 2845 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 AM |
2846 | break; |
2847 | case DW_OP_plus_uconst: | |
2e4b9b8c | 2848 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2849 | break; |
3f76745e | 2850 | case DW_OP_breg0: |
3f76745e | 2851 | case DW_OP_breg1: |
3f76745e | 2852 | case DW_OP_breg2: |
3f76745e | 2853 | case DW_OP_breg3: |
3f76745e | 2854 | case DW_OP_breg4: |
3f76745e | 2855 | case DW_OP_breg5: |
3f76745e | 2856 | case DW_OP_breg6: |
3f76745e | 2857 | case DW_OP_breg7: |
3f76745e | 2858 | case DW_OP_breg8: |
3f76745e | 2859 | case DW_OP_breg9: |
3f76745e | 2860 | case DW_OP_breg10: |
3f76745e | 2861 | case DW_OP_breg11: |
3f76745e | 2862 | case DW_OP_breg12: |
3f76745e | 2863 | case DW_OP_breg13: |
3f76745e | 2864 | case DW_OP_breg14: |
3f76745e | 2865 | case DW_OP_breg15: |
3f76745e | 2866 | case DW_OP_breg16: |
3f76745e | 2867 | case DW_OP_breg17: |
3f76745e | 2868 | case DW_OP_breg18: |
3f76745e | 2869 | case DW_OP_breg19: |
3f76745e | 2870 | case DW_OP_breg20: |
3f76745e | 2871 | case DW_OP_breg21: |
3f76745e | 2872 | case DW_OP_breg22: |
3f76745e | 2873 | case DW_OP_breg23: |
3f76745e | 2874 | case DW_OP_breg24: |
3f76745e | 2875 | case DW_OP_breg25: |
3f76745e | 2876 | case DW_OP_breg26: |
3f76745e | 2877 | case DW_OP_breg27: |
3f76745e | 2878 | case DW_OP_breg28: |
3f76745e | 2879 | case DW_OP_breg29: |
3f76745e | 2880 | case DW_OP_breg30: |
3f76745e | 2881 | case DW_OP_breg31: |
2e4b9b8c | 2882 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 2883 | break; |
3f76745e | 2884 | case DW_OP_regx: |
2e4b9b8c | 2885 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2886 | break; |
3f76745e | 2887 | case DW_OP_fbreg: |
2e4b9b8c | 2888 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 2889 | break; |
3f76745e | 2890 | case DW_OP_bregx: |
2e4b9b8c RH |
2891 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
2892 | dw2_asm_output_data_sleb128 (val2->v.val_int, NULL); | |
7d9d8943 | 2893 | break; |
3f76745e | 2894 | case DW_OP_piece: |
2e4b9b8c | 2895 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2896 | break; |
3f76745e | 2897 | case DW_OP_deref_size: |
3f76745e | 2898 | case DW_OP_xderef_size: |
2e4b9b8c | 2899 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 AM |
2900 | break; |
2901 | default: | |
3139472f JM |
2902 | /* Other codes have no operands. */ |
2903 | break; | |
7d9d8943 AM |
2904 | } |
2905 | } | |
2906 | ||
2907 | /* Output a sequence of location operations. */ | |
2908 | ||
2909 | static void | |
2910 | output_loc_sequence (loc) | |
2911 | dw_loc_descr_ref loc; | |
2912 | { | |
2913 | for (; loc != NULL; loc = loc->dw_loc_next) | |
2914 | { | |
2915 | /* Output the opcode. */ | |
2e4b9b8c RH |
2916 | dw2_asm_output_data (1, loc->dw_loc_opc, |
2917 | "%s", dwarf_stack_op_name (loc->dw_loc_opc)); | |
7d9d8943 AM |
2918 | |
2919 | /* Output the operand(s) (if any). */ | |
2920 | output_loc_operands (loc); | |
2921 | } | |
2922 | } | |
2923 | ||
2924 | /* This routine will generate the correct assembly data for a location | |
2925 | description based on a cfi entry with a complex address. */ | |
2926 | ||
2927 | static void | |
2928 | output_cfa_loc (cfi) | |
2929 | dw_cfi_ref cfi; | |
2930 | { | |
2931 | dw_loc_descr_ref loc; | |
2932 | unsigned long size; | |
2933 | ||
2934 | /* Output the size of the block. */ | |
2935 | loc = cfi->dw_cfi_oprnd1.dw_cfi_loc; | |
2936 | size = size_of_locs (loc); | |
2e4b9b8c | 2937 | dw2_asm_output_data_uleb128 (size, NULL); |
7d9d8943 AM |
2938 | |
2939 | /* Now output the operations themselves. */ | |
2940 | output_loc_sequence (loc); | |
2941 | } | |
2942 | ||
dd49a9ec | 2943 | /* This function builds a dwarf location descriptor sequence from |
556273e0 | 2944 | a dw_cfa_location. */ |
7d9d8943 AM |
2945 | |
2946 | static struct dw_loc_descr_struct * | |
2947 | build_cfa_loc (cfa) | |
2948 | dw_cfa_location *cfa; | |
2949 | { | |
2950 | struct dw_loc_descr_struct *head, *tmp; | |
2951 | ||
2952 | if (cfa->indirect == 0) | |
2953 | abort (); | |
2954 | ||
2955 | if (cfa->base_offset) | |
f299afab HPN |
2956 | { |
2957 | if (cfa->reg <= 31) | |
2958 | head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0); | |
2959 | else | |
2960 | head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset); | |
2961 | } | |
2962 | else if (cfa->reg <= 31) | |
7d9d8943 | 2963 | head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0); |
f299afab HPN |
2964 | else |
2965 | head = new_loc_descr (DW_OP_regx, cfa->reg, 0); | |
2ad9852d | 2966 | |
7d9d8943 AM |
2967 | head->dw_loc_oprnd1.val_class = dw_val_class_const; |
2968 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
2969 | add_loc_descr (&head, tmp); | |
2970 | if (cfa->offset != 0) | |
2971 | { | |
2972 | tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0); | |
2973 | add_loc_descr (&head, tmp); | |
2974 | } | |
2ad9852d | 2975 | |
7d9d8943 AM |
2976 | return head; |
2977 | } | |
2978 | ||
2ad9852d RK |
2979 | /* This function fills in aa dw_cfa_location structure from a dwarf location |
2980 | descriptor sequence. */ | |
7d9d8943 AM |
2981 | |
2982 | static void | |
2983 | get_cfa_from_loc_descr (cfa, loc) | |
2984 | dw_cfa_location *cfa; | |
556273e0 | 2985 | struct dw_loc_descr_struct *loc; |
7d9d8943 | 2986 | { |
556273e0 | 2987 | struct dw_loc_descr_struct *ptr; |
7d9d8943 AM |
2988 | cfa->offset = 0; |
2989 | cfa->base_offset = 0; | |
2990 | cfa->indirect = 0; | |
2991 | cfa->reg = -1; | |
2992 | ||
2993 | for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next) | |
2994 | { | |
2995 | enum dwarf_location_atom op = ptr->dw_loc_opc; | |
2ad9852d | 2996 | |
7d9d8943 | 2997 | switch (op) |
556273e0 | 2998 | { |
7d9d8943 AM |
2999 | case DW_OP_reg0: |
3000 | case DW_OP_reg1: | |
3001 | case DW_OP_reg2: | |
3002 | case DW_OP_reg3: | |
3003 | case DW_OP_reg4: | |
3004 | case DW_OP_reg5: | |
3005 | case DW_OP_reg6: | |
3006 | case DW_OP_reg7: | |
3007 | case DW_OP_reg8: | |
3008 | case DW_OP_reg9: | |
3009 | case DW_OP_reg10: | |
3010 | case DW_OP_reg11: | |
3011 | case DW_OP_reg12: | |
3012 | case DW_OP_reg13: | |
3013 | case DW_OP_reg14: | |
3014 | case DW_OP_reg15: | |
3015 | case DW_OP_reg16: | |
3016 | case DW_OP_reg17: | |
3017 | case DW_OP_reg18: | |
3018 | case DW_OP_reg19: | |
3019 | case DW_OP_reg20: | |
3020 | case DW_OP_reg21: | |
3021 | case DW_OP_reg22: | |
3022 | case DW_OP_reg23: | |
3023 | case DW_OP_reg24: | |
3024 | case DW_OP_reg25: | |
3025 | case DW_OP_reg26: | |
3026 | case DW_OP_reg27: | |
3027 | case DW_OP_reg28: | |
3028 | case DW_OP_reg29: | |
3029 | case DW_OP_reg30: | |
3030 | case DW_OP_reg31: | |
3031 | cfa->reg = op - DW_OP_reg0; | |
3032 | break; | |
3033 | case DW_OP_regx: | |
3034 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
3035 | break; | |
3036 | case DW_OP_breg0: | |
3037 | case DW_OP_breg1: | |
3038 | case DW_OP_breg2: | |
3039 | case DW_OP_breg3: | |
3040 | case DW_OP_breg4: | |
3041 | case DW_OP_breg5: | |
3042 | case DW_OP_breg6: | |
3043 | case DW_OP_breg7: | |
3044 | case DW_OP_breg8: | |
3045 | case DW_OP_breg9: | |
3046 | case DW_OP_breg10: | |
3047 | case DW_OP_breg11: | |
3048 | case DW_OP_breg12: | |
3049 | case DW_OP_breg13: | |
3050 | case DW_OP_breg14: | |
3051 | case DW_OP_breg15: | |
3052 | case DW_OP_breg16: | |
3053 | case DW_OP_breg17: | |
3054 | case DW_OP_breg18: | |
3055 | case DW_OP_breg19: | |
3056 | case DW_OP_breg20: | |
3057 | case DW_OP_breg21: | |
3058 | case DW_OP_breg22: | |
3059 | case DW_OP_breg23: | |
3060 | case DW_OP_breg24: | |
3061 | case DW_OP_breg25: | |
3062 | case DW_OP_breg26: | |
3063 | case DW_OP_breg27: | |
3064 | case DW_OP_breg28: | |
3065 | case DW_OP_breg29: | |
3066 | case DW_OP_breg30: | |
3067 | case DW_OP_breg31: | |
3068 | cfa->reg = op - DW_OP_breg0; | |
3069 | cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int; | |
3070 | break; | |
3071 | case DW_OP_bregx: | |
3072 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
3073 | cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int; | |
3074 | break; | |
3075 | case DW_OP_deref: | |
3076 | cfa->indirect = 1; | |
3077 | break; | |
3078 | case DW_OP_plus_uconst: | |
556273e0 | 3079 | cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned; |
7d9d8943 AM |
3080 | break; |
3081 | default: | |
a1f300c0 | 3082 | internal_error ("DW_LOC_OP %s not implemented\n", |
400500c4 | 3083 | dwarf_stack_op_name (ptr->dw_loc_opc)); |
7d9d8943 AM |
3084 | } |
3085 | } | |
3086 | } | |
3087 | #endif /* .debug_frame support */ | |
3088 | \f | |
3089 | /* And now, the support for symbolic debugging information. */ | |
3090 | #ifdef DWARF2_DEBUGGING_INFO | |
3091 | ||
117f9d28 GS |
3092 | /* .debug_str support. */ |
3093 | static hashnode indirect_string_alloc PARAMS ((hash_table *)); | |
3094 | static int output_indirect_string PARAMS ((struct cpp_reader *, | |
3095 | hashnode, const PTR)); | |
3096 | ||
3097 | ||
e2a12aca NB |
3098 | static void dwarf2out_init PARAMS ((const char *)); |
3099 | static void dwarf2out_finish PARAMS ((const char *)); | |
7f905405 NB |
3100 | static void dwarf2out_define PARAMS ((unsigned int, const char *)); |
3101 | static void dwarf2out_undef PARAMS ((unsigned int, const char *)); | |
3102 | static void dwarf2out_start_source_file PARAMS ((unsigned, const char *)); | |
3103 | static void dwarf2out_end_source_file PARAMS ((unsigned)); | |
e2a12aca NB |
3104 | static void dwarf2out_begin_block PARAMS ((unsigned, unsigned)); |
3105 | static void dwarf2out_end_block PARAMS ((unsigned, unsigned)); | |
e1772ac0 | 3106 | static bool dwarf2out_ignore_block PARAMS ((tree)); |
2b85879e | 3107 | static void dwarf2out_global_decl PARAMS ((tree)); |
e1772ac0 | 3108 | static void dwarf2out_abstract_function PARAMS ((tree)); |
7f905405 NB |
3109 | |
3110 | /* The debug hooks structure. */ | |
3111 | ||
54b6670a | 3112 | const struct gcc_debug_hooks dwarf2_debug_hooks = |
7f905405 NB |
3113 | { |
3114 | dwarf2out_init, | |
3115 | dwarf2out_finish, | |
3116 | dwarf2out_define, | |
3117 | dwarf2out_undef, | |
3118 | dwarf2out_start_source_file, | |
a5a42b92 NB |
3119 | dwarf2out_end_source_file, |
3120 | dwarf2out_begin_block, | |
e2a12aca | 3121 | dwarf2out_end_block, |
e1772ac0 | 3122 | dwarf2out_ignore_block, |
e2a12aca | 3123 | dwarf2out_source_line, |
653e276c NB |
3124 | dwarf2out_begin_prologue, |
3125 | debug_nothing_int, /* end_prologue */ | |
e2a12aca | 3126 | dwarf2out_end_epilogue, |
653e276c | 3127 | debug_nothing_tree, /* begin_function */ |
2b85879e NB |
3128 | debug_nothing_int, /* end_function */ |
3129 | dwarf2out_decl, /* function_decl */ | |
3130 | dwarf2out_global_decl, | |
e1772ac0 NB |
3131 | debug_nothing_tree, /* deferred_inline_function */ |
3132 | /* The DWARF 2 backend tries to reduce debugging bloat by not | |
3133 | emitting the abstract description of inline functions until | |
3134 | something tries to reference them. */ | |
3135 | dwarf2out_abstract_function, /* outlining_inline_function */ | |
3136 | debug_nothing_rtx /* label */ | |
7f905405 NB |
3137 | }; |
3138 | \f | |
7d9d8943 AM |
3139 | /* NOTE: In the comments in this file, many references are made to |
3140 | "Debugging Information Entries". This term is abbreviated as `DIE' | |
3141 | throughout the remainder of this file. */ | |
3142 | ||
3143 | /* An internal representation of the DWARF output is built, and then | |
3144 | walked to generate the DWARF debugging info. The walk of the internal | |
3145 | representation is done after the entire program has been compiled. | |
3146 | The types below are used to describe the internal representation. */ | |
3147 | ||
3148 | /* Various DIE's use offsets relative to the beginning of the | |
3149 | .debug_info section to refer to each other. */ | |
3150 | ||
3151 | typedef long int dw_offset; | |
3152 | ||
3153 | /* Define typedefs here to avoid circular dependencies. */ | |
3154 | ||
3155 | typedef struct dw_attr_struct *dw_attr_ref; | |
3156 | typedef struct dw_line_info_struct *dw_line_info_ref; | |
3157 | typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref; | |
3158 | typedef struct pubname_struct *pubname_ref; | |
a20612aa | 3159 | typedef struct dw_ranges_struct *dw_ranges_ref; |
7d9d8943 AM |
3160 | |
3161 | /* Each entry in the line_info_table maintains the file and | |
3162 | line number associated with the label generated for that | |
3163 | entry. The label gives the PC value associated with | |
3164 | the line number entry. */ | |
3165 | ||
3166 | typedef struct dw_line_info_struct | |
3167 | { | |
3168 | unsigned long dw_file_num; | |
3169 | unsigned long dw_line_num; | |
3170 | } | |
3171 | dw_line_info_entry; | |
3172 | ||
3173 | /* Line information for functions in separate sections; each one gets its | |
3174 | own sequence. */ | |
3175 | typedef struct dw_separate_line_info_struct | |
3176 | { | |
3177 | unsigned long dw_file_num; | |
3178 | unsigned long dw_line_num; | |
3179 | unsigned long function; | |
3180 | } | |
3181 | dw_separate_line_info_entry; | |
3182 | ||
3183 | /* Each DIE attribute has a field specifying the attribute kind, | |
3184 | a link to the next attribute in the chain, and an attribute value. | |
3185 | Attributes are typically linked below the DIE they modify. */ | |
3186 | ||
3187 | typedef struct dw_attr_struct | |
3188 | { | |
3189 | enum dwarf_attribute dw_attr; | |
3190 | dw_attr_ref dw_attr_next; | |
3191 | dw_val_node dw_attr_val; | |
3192 | } | |
3193 | dw_attr_node; | |
3194 | ||
3195 | /* The Debugging Information Entry (DIE) structure */ | |
3196 | ||
3197 | typedef struct die_struct | |
3198 | { | |
3199 | enum dwarf_tag die_tag; | |
881c6935 | 3200 | char *die_symbol; |
7d9d8943 AM |
3201 | dw_attr_ref die_attr; |
3202 | dw_die_ref die_parent; | |
3203 | dw_die_ref die_child; | |
3204 | dw_die_ref die_sib; | |
3205 | dw_offset die_offset; | |
3206 | unsigned long die_abbrev; | |
1bfb5f8f | 3207 | int die_mark; |
7d9d8943 AM |
3208 | } |
3209 | die_node; | |
3210 | ||
3211 | /* The pubname structure */ | |
3212 | ||
3213 | typedef struct pubname_struct | |
3214 | { | |
3215 | dw_die_ref die; | |
556273e0 | 3216 | char *name; |
7d9d8943 AM |
3217 | } |
3218 | pubname_entry; | |
3219 | ||
a20612aa RH |
3220 | struct dw_ranges_struct |
3221 | { | |
3222 | int block_num; | |
3223 | }; | |
3224 | ||
7d9d8943 AM |
3225 | /* The limbo die list structure. */ |
3226 | typedef struct limbo_die_struct | |
3227 | { | |
3228 | dw_die_ref die; | |
54ba1f0d | 3229 | tree created_for; |
7d9d8943 AM |
3230 | struct limbo_die_struct *next; |
3231 | } | |
3232 | limbo_die_node; | |
3233 | ||
3234 | /* How to start an assembler comment. */ | |
3235 | #ifndef ASM_COMMENT_START | |
3236 | #define ASM_COMMENT_START ";#" | |
3237 | #endif | |
3238 | ||
3239 | /* Define a macro which returns non-zero for a TYPE_DECL which was | |
3240 | implicitly generated for a tagged type. | |
3241 | ||
3242 | Note that unlike the gcc front end (which generates a NULL named | |
3243 | TYPE_DECL node for each complete tagged type, each array type, and | |
3244 | each function type node created) the g++ front end generates a | |
3245 | _named_ TYPE_DECL node for each tagged type node created. | |
3246 | These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to | |
3247 | generate a DW_TAG_typedef DIE for them. */ | |
3248 | ||
3249 | #define TYPE_DECL_IS_STUB(decl) \ | |
3250 | (DECL_NAME (decl) == NULL_TREE \ | |
3251 | || (DECL_ARTIFICIAL (decl) \ | |
3252 | && is_tagged_type (TREE_TYPE (decl)) \ | |
3253 | && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \ | |
3254 | /* This is necessary for stub decls that \ | |
3255 | appear in nested inline functions. */ \ | |
3256 | || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \ | |
3257 | && (decl_ultimate_origin (decl) \ | |
3258 | == TYPE_STUB_DECL (TREE_TYPE (decl))))))) | |
3259 | ||
3260 | /* Information concerning the compilation unit's programming | |
3261 | language, and compiler version. */ | |
3262 | ||
7d9d8943 AM |
3263 | /* Fixed size portion of the DWARF compilation unit header. */ |
3264 | #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3) | |
3265 | ||
3266 | /* Fixed size portion of debugging line information prolog. */ | |
3267 | #define DWARF_LINE_PROLOG_HEADER_SIZE 5 | |
3268 | ||
3269 | /* Fixed size portion of public names info. */ | |
3270 | #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2) | |
3271 | ||
3272 | /* Fixed size portion of the address range info. */ | |
3273 | #define DWARF_ARANGES_HEADER_SIZE \ | |
3274 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ | |
3275 | - DWARF_OFFSET_SIZE) | |
3276 | ||
3277 | /* Size of padding portion in the address range info. It must be | |
3278 | aligned to twice the pointer size. */ | |
3279 | #define DWARF_ARANGES_PAD_SIZE \ | |
3280 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ | |
3281 | - (2 * DWARF_OFFSET_SIZE + 4)) | |
3282 | ||
9d147085 | 3283 | /* Use assembler line directives if available. */ |
7d9d8943 | 3284 | #ifndef DWARF2_ASM_LINE_DEBUG_INFO |
9d147085 RH |
3285 | #ifdef HAVE_AS_DWARF2_DEBUG_LINE |
3286 | #define DWARF2_ASM_LINE_DEBUG_INFO 1 | |
3287 | #else | |
7d9d8943 AM |
3288 | #define DWARF2_ASM_LINE_DEBUG_INFO 0 |
3289 | #endif | |
9d147085 | 3290 | #endif |
7d9d8943 | 3291 | |
7d9d8943 AM |
3292 | /* Minimum line offset in a special line info. opcode. |
3293 | This value was chosen to give a reasonable range of values. */ | |
3294 | #define DWARF_LINE_BASE -10 | |
3295 | ||
a1f300c0 | 3296 | /* First special line opcode - leave room for the standard opcodes. */ |
7d9d8943 AM |
3297 | #define DWARF_LINE_OPCODE_BASE 10 |
3298 | ||
3299 | /* Range of line offsets in a special line info. opcode. */ | |
3300 | #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1) | |
3301 | ||
3302 | /* Flag that indicates the initial value of the is_stmt_start flag. | |
3303 | In the present implementation, we do not mark any lines as | |
3304 | the beginning of a source statement, because that information | |
3305 | is not made available by the GCC front-end. */ | |
3306 | #define DWARF_LINE_DEFAULT_IS_STMT_START 1 | |
3307 | ||
3308 | /* This location is used by calc_die_sizes() to keep track | |
3309 | the offset of each DIE within the .debug_info section. */ | |
3310 | static unsigned long next_die_offset; | |
3311 | ||
3312 | /* Record the root of the DIE's built for the current compilation unit. */ | |
3313 | static dw_die_ref comp_unit_die; | |
3314 | ||
3315 | /* A list of DIEs with a NULL parent waiting to be relocated. */ | |
3316 | static limbo_die_node *limbo_die_list = 0; | |
3317 | ||
2e18bbae RH |
3318 | /* Structure used by lookup_filename to manage sets of filenames. */ |
3319 | struct file_table | |
3320 | { | |
3321 | char **table; | |
3322 | unsigned allocated; | |
3323 | unsigned in_use; | |
3324 | unsigned last_lookup_index; | |
3325 | }; | |
7d9d8943 AM |
3326 | |
3327 | /* Size (in elements) of increments by which we may expand the filename | |
3328 | table. */ | |
3329 | #define FILE_TABLE_INCREMENT 64 | |
3330 | ||
981975b6 RH |
3331 | /* Filenames referenced by this compilation unit. */ |
3332 | static struct file_table file_table; | |
2e18bbae | 3333 | |
7d9d8943 AM |
3334 | /* Local pointer to the name of the main input file. Initialized in |
3335 | dwarf2out_init. */ | |
3336 | static const char *primary_filename; | |
3337 | ||
3338 | /* A pointer to the base of a table of references to DIE's that describe | |
3339 | declarations. The table is indexed by DECL_UID() which is a unique | |
3340 | number identifying each decl. */ | |
3341 | static dw_die_ref *decl_die_table; | |
3342 | ||
3343 | /* Number of elements currently allocated for the decl_die_table. */ | |
3344 | static unsigned decl_die_table_allocated; | |
3345 | ||
3346 | /* Number of elements in decl_die_table currently in use. */ | |
3347 | static unsigned decl_die_table_in_use; | |
3348 | ||
3349 | /* Size (in elements) of increments by which we may expand the | |
3350 | decl_die_table. */ | |
3351 | #define DECL_DIE_TABLE_INCREMENT 256 | |
3352 | ||
3353 | /* A pointer to the base of a table of references to declaration | |
3354 | scopes. This table is a display which tracks the nesting | |
3355 | of declaration scopes at the current scope and containing | |
3356 | scopes. This table is used to find the proper place to | |
3357 | define type declaration DIE's. */ | |
244a4af0 | 3358 | varray_type decl_scope_table; |
7d9d8943 AM |
3359 | |
3360 | /* A pointer to the base of a list of references to DIE's that | |
3361 | are uniquely identified by their tag, presence/absence of | |
3362 | children DIE's, and list of attribute/value pairs. */ | |
3363 | static dw_die_ref *abbrev_die_table; | |
3364 | ||
3365 | /* Number of elements currently allocated for abbrev_die_table. */ | |
3366 | static unsigned abbrev_die_table_allocated; | |
3367 | ||
3368 | /* Number of elements in type_die_table currently in use. */ | |
3369 | static unsigned abbrev_die_table_in_use; | |
3370 | ||
3371 | /* Size (in elements) of increments by which we may expand the | |
3372 | abbrev_die_table. */ | |
3373 | #define ABBREV_DIE_TABLE_INCREMENT 256 | |
3374 | ||
3375 | /* A pointer to the base of a table that contains line information | |
3376 | for each source code line in .text in the compilation unit. */ | |
3377 | static dw_line_info_ref line_info_table; | |
3378 | ||
3379 | /* Number of elements currently allocated for line_info_table. */ | |
3380 | static unsigned line_info_table_allocated; | |
3381 | ||
3382 | /* Number of elements in separate_line_info_table currently in use. */ | |
3383 | static unsigned separate_line_info_table_in_use; | |
3384 | ||
3385 | /* A pointer to the base of a table that contains line information | |
3386 | for each source code line outside of .text in the compilation unit. */ | |
3387 | static dw_separate_line_info_ref separate_line_info_table; | |
3388 | ||
3389 | /* Number of elements currently allocated for separate_line_info_table. */ | |
3390 | static unsigned separate_line_info_table_allocated; | |
3391 | ||
3392 | /* Number of elements in line_info_table currently in use. */ | |
3393 | static unsigned line_info_table_in_use; | |
3394 | ||
3395 | /* Size (in elements) of increments by which we may expand the | |
3396 | line_info_table. */ | |
3397 | #define LINE_INFO_TABLE_INCREMENT 1024 | |
3398 | ||
3399 | /* A pointer to the base of a table that contains a list of publicly | |
3400 | accessible names. */ | |
3401 | static pubname_ref pubname_table; | |
3402 | ||
3403 | /* Number of elements currently allocated for pubname_table. */ | |
3404 | static unsigned pubname_table_allocated; | |
3405 | ||
3406 | /* Number of elements in pubname_table currently in use. */ | |
3407 | static unsigned pubname_table_in_use; | |
3408 | ||
3409 | /* Size (in elements) of increments by which we may expand the | |
3410 | pubname_table. */ | |
3411 | #define PUBNAME_TABLE_INCREMENT 64 | |
3412 | ||
a20612aa RH |
3413 | /* Array of dies for which we should generate .debug_arange info. */ |
3414 | static dw_die_ref *arange_table; | |
7d9d8943 AM |
3415 | |
3416 | /* Number of elements currently allocated for arange_table. */ | |
3417 | static unsigned arange_table_allocated; | |
3418 | ||
3419 | /* Number of elements in arange_table currently in use. */ | |
3420 | static unsigned arange_table_in_use; | |
3421 | ||
3422 | /* Size (in elements) of increments by which we may expand the | |
3423 | arange_table. */ | |
3424 | #define ARANGE_TABLE_INCREMENT 64 | |
3425 | ||
a20612aa RH |
3426 | /* Array of dies for which we should generate .debug_ranges info. */ |
3427 | static dw_ranges_ref ranges_table; | |
3428 | ||
3429 | /* Number of elements currently allocated for ranges_table. */ | |
3430 | static unsigned ranges_table_allocated; | |
3431 | ||
3432 | /* Number of elements in ranges_table currently in use. */ | |
3433 | static unsigned ranges_table_in_use; | |
3434 | ||
3435 | /* Size (in elements) of increments by which we may expand the | |
3436 | ranges_table. */ | |
3437 | #define RANGES_TABLE_INCREMENT 64 | |
3438 | ||
63e46568 DB |
3439 | /* Whether we have location lists that need outputting */ |
3440 | static unsigned have_location_lists; | |
3441 | ||
7d9d8943 | 3442 | /* A pointer to the base of a list of incomplete types which might be |
244a4af0 | 3443 | completed at some later time. incomplete_types_list needs to be a VARRAY |
2ad9852d | 3444 | because we want to tell the garbage collector about it. */ |
244a4af0 | 3445 | varray_type incomplete_types; |
7d9d8943 AM |
3446 | |
3447 | /* Record whether the function being analyzed contains inlined functions. */ | |
3448 | static int current_function_has_inlines; | |
3449 | #if 0 && defined (MIPS_DEBUGGING_INFO) | |
3450 | static int comp_unit_has_inlines; | |
3451 | #endif | |
3452 | ||
3453 | /* Array of RTXes referenced by the debugging information, which therefore | |
c470afad | 3454 | must be kept around forever. This is a GC root. */ |
7d9d8943 AM |
3455 | static varray_type used_rtx_varray; |
3456 | ||
3457 | /* Forward declarations for functions defined in this file. */ | |
3458 | ||
3459 | static int is_pseudo_reg PARAMS ((rtx)); | |
3460 | static tree type_main_variant PARAMS ((tree)); | |
3461 | static int is_tagged_type PARAMS ((tree)); | |
3462 | static const char *dwarf_tag_name PARAMS ((unsigned)); | |
3463 | static const char *dwarf_attr_name PARAMS ((unsigned)); | |
3464 | static const char *dwarf_form_name PARAMS ((unsigned)); | |
3465 | #if 0 | |
3466 | static const char *dwarf_type_encoding_name PARAMS ((unsigned)); | |
3467 | #endif | |
3468 | static tree decl_ultimate_origin PARAMS ((tree)); | |
3469 | static tree block_ultimate_origin PARAMS ((tree)); | |
3470 | static tree decl_class_context PARAMS ((tree)); | |
3471 | static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref)); | |
2ad9852d | 3472 | static inline dw_val_class AT_class PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3473 | static void add_AT_flag PARAMS ((dw_die_ref, |
3474 | enum dwarf_attribute, | |
3475 | unsigned)); | |
2ad9852d | 3476 | static inline unsigned AT_flag PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3477 | static void add_AT_int PARAMS ((dw_die_ref, |
3478 | enum dwarf_attribute, long)); | |
2ad9852d | 3479 | static inline long int AT_int PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3480 | static void add_AT_unsigned PARAMS ((dw_die_ref, |
3481 | enum dwarf_attribute, | |
3482 | unsigned long)); | |
2ad9852d | 3483 | static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3484 | static void add_AT_long_long PARAMS ((dw_die_ref, |
3485 | enum dwarf_attribute, | |
3486 | unsigned long, | |
3487 | unsigned long)); | |
3488 | static void add_AT_float PARAMS ((dw_die_ref, | |
3489 | enum dwarf_attribute, | |
3490 | unsigned, long *)); | |
3491 | static void add_AT_string PARAMS ((dw_die_ref, | |
3492 | enum dwarf_attribute, | |
3493 | const char *)); | |
2ad9852d RK |
3494 | static inline const char *AT_string PARAMS ((dw_attr_ref)); |
3495 | static int AT_string_form PARAMS ((dw_attr_ref)); | |
7d9d8943 AM |
3496 | static void add_AT_die_ref PARAMS ((dw_die_ref, |
3497 | enum dwarf_attribute, | |
3498 | dw_die_ref)); | |
2ad9852d RK |
3499 | static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref)); |
3500 | static inline int AT_ref_external PARAMS ((dw_attr_ref)); | |
3501 | static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int)); | |
7d9d8943 AM |
3502 | static void add_AT_fde_ref PARAMS ((dw_die_ref, |
3503 | enum dwarf_attribute, | |
3504 | unsigned)); | |
3505 | static void add_AT_loc PARAMS ((dw_die_ref, | |
3506 | enum dwarf_attribute, | |
3507 | dw_loc_descr_ref)); | |
2ad9852d | 3508 | static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref)); |
63e46568 DB |
3509 | static void add_AT_loc_list PARAMS ((dw_die_ref, |
3510 | enum dwarf_attribute, | |
3511 | dw_loc_list_ref)); | |
2ad9852d | 3512 | static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3513 | static void add_AT_addr PARAMS ((dw_die_ref, |
3514 | enum dwarf_attribute, | |
3515 | rtx)); | |
2ad9852d | 3516 | static inline rtx AT_addr PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3517 | static void add_AT_lbl_id PARAMS ((dw_die_ref, |
3518 | enum dwarf_attribute, | |
3519 | const char *)); | |
3520 | static void add_AT_lbl_offset PARAMS ((dw_die_ref, | |
3521 | enum dwarf_attribute, | |
3522 | const char *)); | |
a20612aa RH |
3523 | static void add_AT_offset PARAMS ((dw_die_ref, |
3524 | enum dwarf_attribute, | |
3525 | unsigned long)); | |
2bee6045 JJ |
3526 | static void add_AT_range_list PARAMS ((dw_die_ref, |
3527 | enum dwarf_attribute, | |
3528 | unsigned long)); | |
2ad9852d | 3529 | static inline const char *AT_lbl PARAMS ((dw_attr_ref)); |
7d9d8943 AM |
3530 | static dw_attr_ref get_AT PARAMS ((dw_die_ref, |
3531 | enum dwarf_attribute)); | |
3532 | static const char *get_AT_low_pc PARAMS ((dw_die_ref)); | |
3533 | static const char *get_AT_hi_pc PARAMS ((dw_die_ref)); | |
3534 | static const char *get_AT_string PARAMS ((dw_die_ref, | |
3535 | enum dwarf_attribute)); | |
3536 | static int get_AT_flag PARAMS ((dw_die_ref, | |
3537 | enum dwarf_attribute)); | |
3538 | static unsigned get_AT_unsigned PARAMS ((dw_die_ref, | |
3539 | enum dwarf_attribute)); | |
3540 | static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref, | |
3541 | enum dwarf_attribute)); | |
3542 | static int is_c_family PARAMS ((void)); | |
710af899 | 3543 | static int is_cxx PARAMS ((void)); |
28985b81 | 3544 | static int is_java PARAMS ((void)); |
7d9d8943 AM |
3545 | static int is_fortran PARAMS ((void)); |
3546 | static void remove_AT PARAMS ((dw_die_ref, | |
3547 | enum dwarf_attribute)); | |
2ad9852d | 3548 | static inline void free_die PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3549 | static void remove_children PARAMS ((dw_die_ref)); |
3550 | static void add_child_die PARAMS ((dw_die_ref, dw_die_ref)); | |
54ba1f0d RH |
3551 | static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref, |
3552 | tree)); | |
7d9d8943 AM |
3553 | static dw_die_ref lookup_type_die PARAMS ((tree)); |
3554 | static void equate_type_number_to_die PARAMS ((tree, dw_die_ref)); | |
3555 | static dw_die_ref lookup_decl_die PARAMS ((tree)); | |
3556 | static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref)); | |
3557 | static void print_spaces PARAMS ((FILE *)); | |
3558 | static void print_die PARAMS ((dw_die_ref, FILE *)); | |
3559 | static void print_dwarf_line_table PARAMS ((FILE *)); | |
881c6935 JM |
3560 | static void reverse_die_lists PARAMS ((dw_die_ref)); |
3561 | static void reverse_all_dies PARAMS ((dw_die_ref)); | |
3562 | static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref)); | |
3563 | static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref)); | |
2ad9852d RK |
3564 | static void loc_checksum PARAMS ((dw_loc_descr_ref, |
3565 | struct md5_ctx *)); | |
3566 | static void attr_checksum PARAMS ((dw_attr_ref, | |
3567 | struct md5_ctx *)); | |
3568 | static void die_checksum PARAMS ((dw_die_ref, | |
3569 | struct md5_ctx *)); | |
881c6935 JM |
3570 | static void compute_section_prefix PARAMS ((dw_die_ref)); |
3571 | static int is_type_die PARAMS ((dw_die_ref)); | |
3572 | static int is_comdat_die PARAMS ((dw_die_ref)); | |
3573 | static int is_symbol_die PARAMS ((dw_die_ref)); | |
881c6935 JM |
3574 | static void assign_symbol_names PARAMS ((dw_die_ref)); |
3575 | static void break_out_includes PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3576 | static void add_sibling_attributes PARAMS ((dw_die_ref)); |
3577 | static void build_abbrev_table PARAMS ((dw_die_ref)); | |
63e46568 | 3578 | static void output_location_lists PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3579 | static int constant_size PARAMS ((long unsigned)); |
3580 | static unsigned long size_of_die PARAMS ((dw_die_ref)); | |
3581 | static void calc_die_sizes PARAMS ((dw_die_ref)); | |
1bfb5f8f JM |
3582 | static void mark_dies PARAMS ((dw_die_ref)); |
3583 | static void unmark_dies PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3584 | static unsigned long size_of_pubnames PARAMS ((void)); |
3585 | static unsigned long size_of_aranges PARAMS ((void)); | |
3586 | static enum dwarf_form value_format PARAMS ((dw_attr_ref)); | |
3587 | static void output_value_format PARAMS ((dw_attr_ref)); | |
3588 | static void output_abbrev_section PARAMS ((void)); | |
881c6935 | 3589 | static void output_die_symbol PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3590 | static void output_die PARAMS ((dw_die_ref)); |
3591 | static void output_compilation_unit_header PARAMS ((void)); | |
881c6935 | 3592 | static void output_comp_unit PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3593 | static const char *dwarf2_name PARAMS ((tree, int)); |
3594 | static void add_pubname PARAMS ((tree, dw_die_ref)); | |
3595 | static void output_pubnames PARAMS ((void)); | |
3596 | static void add_arange PARAMS ((tree, dw_die_ref)); | |
3597 | static void output_aranges PARAMS ((void)); | |
a20612aa RH |
3598 | static unsigned int add_ranges PARAMS ((tree)); |
3599 | static void output_ranges PARAMS ((void)); | |
7d9d8943 | 3600 | static void output_line_info PARAMS ((void)); |
0b34cf1e | 3601 | static void output_file_names PARAMS ((void)); |
7d9d8943 AM |
3602 | static dw_die_ref base_type_die PARAMS ((tree)); |
3603 | static tree root_type PARAMS ((tree)); | |
3604 | static int is_base_type PARAMS ((tree)); | |
3605 | static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref)); | |
3606 | static int type_is_enum PARAMS ((tree)); | |
3607 | static unsigned int reg_number PARAMS ((rtx)); | |
3608 | static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx)); | |
d8041cc8 | 3609 | static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT)); |
7d9d8943 AM |
3610 | static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long)); |
3611 | static int is_based_loc PARAMS ((rtx)); | |
3612 | static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode)); | |
3613 | static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx)); | |
3614 | static dw_loc_descr_ref loc_descriptor PARAMS ((rtx)); | |
d8041cc8 | 3615 | static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int)); |
7d9d8943 AM |
3616 | static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int)); |
3617 | static tree field_type PARAMS ((tree)); | |
3618 | static unsigned int simple_type_align_in_bits PARAMS ((tree)); | |
5f446d21 | 3619 | static unsigned int simple_decl_align_in_bits PARAMS ((tree)); |
7d9d8943 AM |
3620 | static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree)); |
3621 | static HOST_WIDE_INT field_byte_offset PARAMS ((tree)); | |
3622 | static void add_AT_location_description PARAMS ((dw_die_ref, | |
3623 | enum dwarf_attribute, rtx)); | |
3624 | static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree)); | |
3625 | static void add_const_value_attribute PARAMS ((dw_die_ref, rtx)); | |
d8041cc8 | 3626 | static rtx rtl_for_decl_location PARAMS ((tree)); |
7d9d8943 | 3627 | static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree)); |
1bfb5f8f | 3628 | static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree)); |
7d9d8943 AM |
3629 | static void add_name_attribute PARAMS ((dw_die_ref, const char *)); |
3630 | static void add_bound_info PARAMS ((dw_die_ref, | |
3631 | enum dwarf_attribute, tree)); | |
3632 | static void add_subscript_info PARAMS ((dw_die_ref, tree)); | |
3633 | static void add_byte_size_attribute PARAMS ((dw_die_ref, tree)); | |
3634 | static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree)); | |
3635 | static void add_bit_size_attribute PARAMS ((dw_die_ref, tree)); | |
3636 | static void add_prototyped_attribute PARAMS ((dw_die_ref, tree)); | |
3637 | static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree)); | |
3638 | static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree)); | |
3639 | static void add_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
3640 | static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
3641 | static void push_decl_scope PARAMS ((tree)); | |
7d9d8943 | 3642 | static void pop_decl_scope PARAMS ((void)); |
2ad9852d RK |
3643 | static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref)); |
3644 | static inline int local_scope_p PARAMS ((dw_die_ref)); | |
3645 | static inline int class_scope_p PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3646 | static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int, |
3647 | dw_die_ref)); | |
3648 | static const char *type_tag PARAMS ((tree)); | |
3649 | static tree member_declared_type PARAMS ((tree)); | |
3650 | #if 0 | |
3651 | static const char *decl_start_label PARAMS ((tree)); | |
3652 | #endif | |
3653 | static void gen_array_type_die PARAMS ((tree, dw_die_ref)); | |
3654 | static void gen_set_type_die PARAMS ((tree, dw_die_ref)); | |
3655 | #if 0 | |
3656 | static void gen_entry_point_die PARAMS ((tree, dw_die_ref)); | |
3657 | #endif | |
3658 | static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
3659 | static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref)); | |
3660 | static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref)); | |
3661 | static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
3662 | static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref)); | |
3663 | static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref)); | |
3664 | static void gen_formal_types_die PARAMS ((tree, dw_die_ref)); | |
3665 | static void gen_subprogram_die PARAMS ((tree, dw_die_ref)); | |
3666 | static void gen_variable_die PARAMS ((tree, dw_die_ref)); | |
3667 | static void gen_label_die PARAMS ((tree, dw_die_ref)); | |
3668 | static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int)); | |
3669 | static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int)); | |
3670 | static void gen_field_die PARAMS ((tree, dw_die_ref)); | |
3671 | static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref)); | |
3672 | static dw_die_ref gen_compile_unit_die PARAMS ((const char *)); | |
3673 | static void gen_string_type_die PARAMS ((tree, dw_die_ref)); | |
3674 | static void gen_inheritance_die PARAMS ((tree, dw_die_ref)); | |
3675 | static void gen_member_die PARAMS ((tree, dw_die_ref)); | |
3676 | static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref)); | |
3677 | static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref)); | |
3678 | static void gen_typedef_die PARAMS ((tree, dw_die_ref)); | |
3679 | static void gen_type_die PARAMS ((tree, dw_die_ref)); | |
3680 | static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref)); | |
3681 | static void gen_block_die PARAMS ((tree, dw_die_ref, int)); | |
3682 | static void decls_for_scope PARAMS ((tree, dw_die_ref, int)); | |
3683 | static int is_redundant_typedef PARAMS ((tree)); | |
3684 | static void gen_decl_die PARAMS ((tree, dw_die_ref)); | |
981975b6 RH |
3685 | static unsigned lookup_filename PARAMS ((const char *)); |
3686 | static void init_file_table PARAMS ((void)); | |
7d9d8943 AM |
3687 | static void retry_incomplete_types PARAMS ((void)); |
3688 | static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref)); | |
7d9d8943 | 3689 | static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref)); |
fc608b03 | 3690 | static int file_info_cmp PARAMS ((const void *, const void *)); |
c26fbbca | 3691 | static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref, |
84a5b4f8 DB |
3692 | const char *, const char *, |
3693 | const char *, unsigned)); | |
3694 | static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *, | |
3695 | dw_loc_descr_ref, | |
3696 | const char *, const char *, const char *)); | |
3697 | static void output_loc_list PARAMS ((dw_loc_list_ref)); | |
3698 | static char *gen_internal_sym PARAMS ((const char *)); | |
54ba1f0d | 3699 | static void mark_limbo_die_list PARAMS ((void *)); |
7d9d8943 AM |
3700 | |
3701 | /* Section names used to hold DWARF debugging information. */ | |
3702 | #ifndef DEBUG_INFO_SECTION | |
3703 | #define DEBUG_INFO_SECTION ".debug_info" | |
3704 | #endif | |
9d2f2c45 RH |
3705 | #ifndef DEBUG_ABBREV_SECTION |
3706 | #define DEBUG_ABBREV_SECTION ".debug_abbrev" | |
7d9d8943 | 3707 | #endif |
9d2f2c45 RH |
3708 | #ifndef DEBUG_ARANGES_SECTION |
3709 | #define DEBUG_ARANGES_SECTION ".debug_aranges" | |
7d9d8943 | 3710 | #endif |
9d2f2c45 RH |
3711 | #ifndef DEBUG_MACINFO_SECTION |
3712 | #define DEBUG_MACINFO_SECTION ".debug_macinfo" | |
7d9d8943 AM |
3713 | #endif |
3714 | #ifndef DEBUG_LINE_SECTION | |
3715 | #define DEBUG_LINE_SECTION ".debug_line" | |
3716 | #endif | |
9d2f2c45 RH |
3717 | #ifndef DEBUG_LOC_SECTION |
3718 | #define DEBUG_LOC_SECTION ".debug_loc" | |
7d9d8943 | 3719 | #endif |
9d2f2c45 RH |
3720 | #ifndef DEBUG_PUBNAMES_SECTION |
3721 | #define DEBUG_PUBNAMES_SECTION ".debug_pubnames" | |
7d9d8943 | 3722 | #endif |
9d2f2c45 RH |
3723 | #ifndef DEBUG_STR_SECTION |
3724 | #define DEBUG_STR_SECTION ".debug_str" | |
7d9d8943 | 3725 | #endif |
a20612aa RH |
3726 | #ifndef DEBUG_RANGES_SECTION |
3727 | #define DEBUG_RANGES_SECTION ".debug_ranges" | |
3728 | #endif | |
7d9d8943 AM |
3729 | |
3730 | /* Standard ELF section names for compiled code and data. */ | |
f99ffb60 RH |
3731 | #ifndef TEXT_SECTION_NAME |
3732 | #define TEXT_SECTION_NAME ".text" | |
7d9d8943 AM |
3733 | #endif |
3734 | ||
9eb4015a JJ |
3735 | /* Section flags for .debug_str section. */ |
3736 | #ifdef HAVE_GAS_SHF_MERGE | |
3737 | #define DEBUG_STR_SECTION_FLAGS \ | |
3738 | (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1) | |
3739 | #else | |
3740 | #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG | |
3741 | #endif | |
3742 | ||
7d9d8943 | 3743 | /* Labels we insert at beginning sections we can reference instead of |
556273e0 | 3744 | the section names themselves. */ |
7d9d8943 AM |
3745 | |
3746 | #ifndef TEXT_SECTION_LABEL | |
9d2f2c45 | 3747 | #define TEXT_SECTION_LABEL "Ltext" |
7d9d8943 AM |
3748 | #endif |
3749 | #ifndef DEBUG_LINE_SECTION_LABEL | |
9d2f2c45 | 3750 | #define DEBUG_LINE_SECTION_LABEL "Ldebug_line" |
7d9d8943 AM |
3751 | #endif |
3752 | #ifndef DEBUG_INFO_SECTION_LABEL | |
9d2f2c45 | 3753 | #define DEBUG_INFO_SECTION_LABEL "Ldebug_info" |
7d9d8943 | 3754 | #endif |
9d2f2c45 RH |
3755 | #ifndef DEBUG_ABBREV_SECTION_LABEL |
3756 | #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev" | |
7d9d8943 | 3757 | #endif |
9d2f2c45 RH |
3758 | #ifndef DEBUG_LOC_SECTION_LABEL |
3759 | #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc" | |
63e46568 | 3760 | #endif |
2bee6045 JJ |
3761 | #ifndef DEBUG_RANGES_SECTION_LABEL |
3762 | #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges" | |
3763 | #endif | |
84a5b4f8 DB |
3764 | #ifndef DEBUG_MACINFO_SECTION_LABEL |
3765 | #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo" | |
3766 | #endif | |
a20612aa | 3767 | |
7d9d8943 AM |
3768 | /* Definitions of defaults for formats and names of various special |
3769 | (artificial) labels which may be generated within this file (when the -g | |
3770 | options is used and DWARF_DEBUGGING_INFO is in effect. | |
3771 | If necessary, these may be overridden from within the tm.h file, but | |
3772 | typically, overriding these defaults is unnecessary. */ | |
3773 | ||
3774 | static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3775 | static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3776 | static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3777 | static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3778 | static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
84a5b4f8 | 3779 | static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
63e46568 | 3780 | static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
2bee6045 | 3781 | static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES]; |
2ad9852d | 3782 | |
7d9d8943 AM |
3783 | #ifndef TEXT_END_LABEL |
3784 | #define TEXT_END_LABEL "Letext" | |
3785 | #endif | |
3786 | #ifndef DATA_END_LABEL | |
3787 | #define DATA_END_LABEL "Ledata" | |
3788 | #endif | |
3789 | #ifndef BSS_END_LABEL | |
3790 | #define BSS_END_LABEL "Lebss" | |
3791 | #endif | |
7d9d8943 AM |
3792 | #ifndef BLOCK_BEGIN_LABEL |
3793 | #define BLOCK_BEGIN_LABEL "LBB" | |
3794 | #endif | |
3795 | #ifndef BLOCK_END_LABEL | |
3796 | #define BLOCK_END_LABEL "LBE" | |
3797 | #endif | |
3798 | #ifndef BODY_BEGIN_LABEL | |
3799 | #define BODY_BEGIN_LABEL "Lbb" | |
3800 | #endif | |
3801 | #ifndef BODY_END_LABEL | |
3802 | #define BODY_END_LABEL "Lbe" | |
3803 | #endif | |
3804 | #ifndef LINE_CODE_LABEL | |
3805 | #define LINE_CODE_LABEL "LM" | |
3806 | #endif | |
3807 | #ifndef SEPARATE_LINE_CODE_LABEL | |
3808 | #define SEPARATE_LINE_CODE_LABEL "LSM" | |
3809 | #endif | |
3810 | \f | |
3811 | /* We allow a language front-end to designate a function that is to be | |
3812 | called to "demangle" any name before it it put into a DIE. */ | |
3813 | ||
3814 | static const char *(*demangle_name_func) PARAMS ((const char *)); | |
3815 | ||
3816 | void | |
3817 | dwarf2out_set_demangle_name_func (func) | |
3818 | const char *(*func) PARAMS ((const char *)); | |
3819 | { | |
3820 | demangle_name_func = func; | |
3821 | } | |
7d9d8943 AM |
3822 | |
3823 | /* Test if rtl node points to a pseudo register. */ | |
3824 | ||
3825 | static inline int | |
3826 | is_pseudo_reg (rtl) | |
b3694847 | 3827 | rtx rtl; |
7d9d8943 AM |
3828 | { |
3829 | return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER) | |
3830 | || (GET_CODE (rtl) == SUBREG | |
ddef6bc7 | 3831 | && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)); |
7d9d8943 AM |
3832 | } |
3833 | ||
3834 | /* Return a reference to a type, with its const and volatile qualifiers | |
3835 | removed. */ | |
3836 | ||
3837 | static inline tree | |
3838 | type_main_variant (type) | |
b3694847 | 3839 | tree type; |
7d9d8943 AM |
3840 | { |
3841 | type = TYPE_MAIN_VARIANT (type); | |
3842 | ||
2ad9852d RK |
3843 | /* ??? There really should be only one main variant among any group of |
3844 | variants of a given type (and all of the MAIN_VARIANT values for all | |
3845 | members of the group should point to that one type) but sometimes the C | |
3846 | front-end messes this up for array types, so we work around that bug | |
3847 | here. */ | |
7d9d8943 AM |
3848 | if (TREE_CODE (type) == ARRAY_TYPE) |
3849 | while (type != TYPE_MAIN_VARIANT (type)) | |
3850 | type = TYPE_MAIN_VARIANT (type); | |
3851 | ||
3852 | return type; | |
3853 | } | |
3854 | ||
3855 | /* Return non-zero if the given type node represents a tagged type. */ | |
3856 | ||
3857 | static inline int | |
3858 | is_tagged_type (type) | |
b3694847 | 3859 | tree type; |
7d9d8943 | 3860 | { |
b3694847 | 3861 | enum tree_code code = TREE_CODE (type); |
7d9d8943 AM |
3862 | |
3863 | return (code == RECORD_TYPE || code == UNION_TYPE | |
3864 | || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); | |
3865 | } | |
3866 | ||
3867 | /* Convert a DIE tag into its string name. */ | |
3868 | ||
3869 | static const char * | |
3870 | dwarf_tag_name (tag) | |
b3694847 | 3871 | unsigned tag; |
7d9d8943 AM |
3872 | { |
3873 | switch (tag) | |
3874 | { | |
3875 | case DW_TAG_padding: | |
3876 | return "DW_TAG_padding"; | |
3877 | case DW_TAG_array_type: | |
3878 | return "DW_TAG_array_type"; | |
3879 | case DW_TAG_class_type: | |
3880 | return "DW_TAG_class_type"; | |
3881 | case DW_TAG_entry_point: | |
3882 | return "DW_TAG_entry_point"; | |
3883 | case DW_TAG_enumeration_type: | |
3884 | return "DW_TAG_enumeration_type"; | |
3885 | case DW_TAG_formal_parameter: | |
3886 | return "DW_TAG_formal_parameter"; | |
3887 | case DW_TAG_imported_declaration: | |
3888 | return "DW_TAG_imported_declaration"; | |
3889 | case DW_TAG_label: | |
3890 | return "DW_TAG_label"; | |
3891 | case DW_TAG_lexical_block: | |
3892 | return "DW_TAG_lexical_block"; | |
3893 | case DW_TAG_member: | |
3894 | return "DW_TAG_member"; | |
3895 | case DW_TAG_pointer_type: | |
3896 | return "DW_TAG_pointer_type"; | |
3897 | case DW_TAG_reference_type: | |
3898 | return "DW_TAG_reference_type"; | |
3899 | case DW_TAG_compile_unit: | |
3900 | return "DW_TAG_compile_unit"; | |
3901 | case DW_TAG_string_type: | |
3902 | return "DW_TAG_string_type"; | |
3903 | case DW_TAG_structure_type: | |
3904 | return "DW_TAG_structure_type"; | |
3905 | case DW_TAG_subroutine_type: | |
3906 | return "DW_TAG_subroutine_type"; | |
3907 | case DW_TAG_typedef: | |
3908 | return "DW_TAG_typedef"; | |
3909 | case DW_TAG_union_type: | |
3910 | return "DW_TAG_union_type"; | |
3911 | case DW_TAG_unspecified_parameters: | |
3912 | return "DW_TAG_unspecified_parameters"; | |
3913 | case DW_TAG_variant: | |
3914 | return "DW_TAG_variant"; | |
3915 | case DW_TAG_common_block: | |
3916 | return "DW_TAG_common_block"; | |
3917 | case DW_TAG_common_inclusion: | |
3918 | return "DW_TAG_common_inclusion"; | |
3919 | case DW_TAG_inheritance: | |
3920 | return "DW_TAG_inheritance"; | |
3921 | case DW_TAG_inlined_subroutine: | |
3922 | return "DW_TAG_inlined_subroutine"; | |
3923 | case DW_TAG_module: | |
3924 | return "DW_TAG_module"; | |
3925 | case DW_TAG_ptr_to_member_type: | |
3926 | return "DW_TAG_ptr_to_member_type"; | |
3927 | case DW_TAG_set_type: | |
3928 | return "DW_TAG_set_type"; | |
3929 | case DW_TAG_subrange_type: | |
3930 | return "DW_TAG_subrange_type"; | |
3931 | case DW_TAG_with_stmt: | |
3932 | return "DW_TAG_with_stmt"; | |
3933 | case DW_TAG_access_declaration: | |
3934 | return "DW_TAG_access_declaration"; | |
3935 | case DW_TAG_base_type: | |
3936 | return "DW_TAG_base_type"; | |
3937 | case DW_TAG_catch_block: | |
3938 | return "DW_TAG_catch_block"; | |
3939 | case DW_TAG_const_type: | |
3940 | return "DW_TAG_const_type"; | |
3941 | case DW_TAG_constant: | |
3942 | return "DW_TAG_constant"; | |
3943 | case DW_TAG_enumerator: | |
3944 | return "DW_TAG_enumerator"; | |
3945 | case DW_TAG_file_type: | |
3946 | return "DW_TAG_file_type"; | |
3947 | case DW_TAG_friend: | |
3948 | return "DW_TAG_friend"; | |
3949 | case DW_TAG_namelist: | |
3950 | return "DW_TAG_namelist"; | |
3951 | case DW_TAG_namelist_item: | |
3952 | return "DW_TAG_namelist_item"; | |
3953 | case DW_TAG_packed_type: | |
3954 | return "DW_TAG_packed_type"; | |
3955 | case DW_TAG_subprogram: | |
3956 | return "DW_TAG_subprogram"; | |
3957 | case DW_TAG_template_type_param: | |
3958 | return "DW_TAG_template_type_param"; | |
3959 | case DW_TAG_template_value_param: | |
3960 | return "DW_TAG_template_value_param"; | |
3961 | case DW_TAG_thrown_type: | |
3962 | return "DW_TAG_thrown_type"; | |
3963 | case DW_TAG_try_block: | |
3964 | return "DW_TAG_try_block"; | |
3965 | case DW_TAG_variant_part: | |
3966 | return "DW_TAG_variant_part"; | |
3967 | case DW_TAG_variable: | |
3968 | return "DW_TAG_variable"; | |
3969 | case DW_TAG_volatile_type: | |
3970 | return "DW_TAG_volatile_type"; | |
3971 | case DW_TAG_MIPS_loop: | |
3972 | return "DW_TAG_MIPS_loop"; | |
3973 | case DW_TAG_format_label: | |
3974 | return "DW_TAG_format_label"; | |
3975 | case DW_TAG_function_template: | |
3976 | return "DW_TAG_function_template"; | |
3977 | case DW_TAG_class_template: | |
3978 | return "DW_TAG_class_template"; | |
881c6935 JM |
3979 | case DW_TAG_GNU_BINCL: |
3980 | return "DW_TAG_GNU_BINCL"; | |
3981 | case DW_TAG_GNU_EINCL: | |
3982 | return "DW_TAG_GNU_EINCL"; | |
7d9d8943 AM |
3983 | default: |
3984 | return "DW_TAG_<unknown>"; | |
3985 | } | |
3986 | } | |
3987 | ||
3988 | /* Convert a DWARF attribute code into its string name. */ | |
3989 | ||
3990 | static const char * | |
3991 | dwarf_attr_name (attr) | |
b3694847 | 3992 | unsigned attr; |
7d9d8943 AM |
3993 | { |
3994 | switch (attr) | |
3995 | { | |
3996 | case DW_AT_sibling: | |
3997 | return "DW_AT_sibling"; | |
3998 | case DW_AT_location: | |
3999 | return "DW_AT_location"; | |
4000 | case DW_AT_name: | |
4001 | return "DW_AT_name"; | |
4002 | case DW_AT_ordering: | |
4003 | return "DW_AT_ordering"; | |
4004 | case DW_AT_subscr_data: | |
4005 | return "DW_AT_subscr_data"; | |
4006 | case DW_AT_byte_size: | |
4007 | return "DW_AT_byte_size"; | |
4008 | case DW_AT_bit_offset: | |
4009 | return "DW_AT_bit_offset"; | |
4010 | case DW_AT_bit_size: | |
4011 | return "DW_AT_bit_size"; | |
4012 | case DW_AT_element_list: | |
4013 | return "DW_AT_element_list"; | |
4014 | case DW_AT_stmt_list: | |
4015 | return "DW_AT_stmt_list"; | |
4016 | case DW_AT_low_pc: | |
4017 | return "DW_AT_low_pc"; | |
4018 | case DW_AT_high_pc: | |
4019 | return "DW_AT_high_pc"; | |
4020 | case DW_AT_language: | |
4021 | return "DW_AT_language"; | |
4022 | case DW_AT_member: | |
4023 | return "DW_AT_member"; | |
4024 | case DW_AT_discr: | |
4025 | return "DW_AT_discr"; | |
4026 | case DW_AT_discr_value: | |
4027 | return "DW_AT_discr_value"; | |
4028 | case DW_AT_visibility: | |
4029 | return "DW_AT_visibility"; | |
4030 | case DW_AT_import: | |
4031 | return "DW_AT_import"; | |
4032 | case DW_AT_string_length: | |
4033 | return "DW_AT_string_length"; | |
4034 | case DW_AT_common_reference: | |
4035 | return "DW_AT_common_reference"; | |
4036 | case DW_AT_comp_dir: | |
4037 | return "DW_AT_comp_dir"; | |
4038 | case DW_AT_const_value: | |
4039 | return "DW_AT_const_value"; | |
4040 | case DW_AT_containing_type: | |
4041 | return "DW_AT_containing_type"; | |
4042 | case DW_AT_default_value: | |
4043 | return "DW_AT_default_value"; | |
4044 | case DW_AT_inline: | |
4045 | return "DW_AT_inline"; | |
4046 | case DW_AT_is_optional: | |
4047 | return "DW_AT_is_optional"; | |
4048 | case DW_AT_lower_bound: | |
4049 | return "DW_AT_lower_bound"; | |
4050 | case DW_AT_producer: | |
4051 | return "DW_AT_producer"; | |
4052 | case DW_AT_prototyped: | |
4053 | return "DW_AT_prototyped"; | |
4054 | case DW_AT_return_addr: | |
4055 | return "DW_AT_return_addr"; | |
4056 | case DW_AT_start_scope: | |
4057 | return "DW_AT_start_scope"; | |
4058 | case DW_AT_stride_size: | |
4059 | return "DW_AT_stride_size"; | |
4060 | case DW_AT_upper_bound: | |
4061 | return "DW_AT_upper_bound"; | |
4062 | case DW_AT_abstract_origin: | |
4063 | return "DW_AT_abstract_origin"; | |
4064 | case DW_AT_accessibility: | |
4065 | return "DW_AT_accessibility"; | |
4066 | case DW_AT_address_class: | |
4067 | return "DW_AT_address_class"; | |
4068 | case DW_AT_artificial: | |
4069 | return "DW_AT_artificial"; | |
4070 | case DW_AT_base_types: | |
4071 | return "DW_AT_base_types"; | |
4072 | case DW_AT_calling_convention: | |
4073 | return "DW_AT_calling_convention"; | |
4074 | case DW_AT_count: | |
4075 | return "DW_AT_count"; | |
4076 | case DW_AT_data_member_location: | |
4077 | return "DW_AT_data_member_location"; | |
4078 | case DW_AT_decl_column: | |
4079 | return "DW_AT_decl_column"; | |
4080 | case DW_AT_decl_file: | |
4081 | return "DW_AT_decl_file"; | |
4082 | case DW_AT_decl_line: | |
4083 | return "DW_AT_decl_line"; | |
4084 | case DW_AT_declaration: | |
4085 | return "DW_AT_declaration"; | |
4086 | case DW_AT_discr_list: | |
4087 | return "DW_AT_discr_list"; | |
4088 | case DW_AT_encoding: | |
4089 | return "DW_AT_encoding"; | |
4090 | case DW_AT_external: | |
4091 | return "DW_AT_external"; | |
4092 | case DW_AT_frame_base: | |
4093 | return "DW_AT_frame_base"; | |
4094 | case DW_AT_friend: | |
4095 | return "DW_AT_friend"; | |
4096 | case DW_AT_identifier_case: | |
4097 | return "DW_AT_identifier_case"; | |
4098 | case DW_AT_macro_info: | |
4099 | return "DW_AT_macro_info"; | |
4100 | case DW_AT_namelist_items: | |
4101 | return "DW_AT_namelist_items"; | |
4102 | case DW_AT_priority: | |
4103 | return "DW_AT_priority"; | |
4104 | case DW_AT_segment: | |
4105 | return "DW_AT_segment"; | |
4106 | case DW_AT_specification: | |
4107 | return "DW_AT_specification"; | |
4108 | case DW_AT_static_link: | |
4109 | return "DW_AT_static_link"; | |
4110 | case DW_AT_type: | |
4111 | return "DW_AT_type"; | |
4112 | case DW_AT_use_location: | |
4113 | return "DW_AT_use_location"; | |
4114 | case DW_AT_variable_parameter: | |
4115 | return "DW_AT_variable_parameter"; | |
4116 | case DW_AT_virtuality: | |
4117 | return "DW_AT_virtuality"; | |
4118 | case DW_AT_vtable_elem_location: | |
4119 | return "DW_AT_vtable_elem_location"; | |
4120 | ||
a20612aa RH |
4121 | case DW_AT_allocated: |
4122 | return "DW_AT_allocated"; | |
4123 | case DW_AT_associated: | |
4124 | return "DW_AT_associated"; | |
4125 | case DW_AT_data_location: | |
4126 | return "DW_AT_data_location"; | |
4127 | case DW_AT_stride: | |
4128 | return "DW_AT_stride"; | |
4129 | case DW_AT_entry_pc: | |
4130 | return "DW_AT_entry_pc"; | |
4131 | case DW_AT_use_UTF8: | |
4132 | return "DW_AT_use_UTF8"; | |
4133 | case DW_AT_extension: | |
4134 | return "DW_AT_extension"; | |
4135 | case DW_AT_ranges: | |
4136 | return "DW_AT_ranges"; | |
4137 | case DW_AT_trampoline: | |
4138 | return "DW_AT_trampoline"; | |
4139 | case DW_AT_call_column: | |
4140 | return "DW_AT_call_column"; | |
4141 | case DW_AT_call_file: | |
4142 | return "DW_AT_call_file"; | |
4143 | case DW_AT_call_line: | |
4144 | return "DW_AT_call_line"; | |
4145 | ||
7d9d8943 AM |
4146 | case DW_AT_MIPS_fde: |
4147 | return "DW_AT_MIPS_fde"; | |
4148 | case DW_AT_MIPS_loop_begin: | |
4149 | return "DW_AT_MIPS_loop_begin"; | |
4150 | case DW_AT_MIPS_tail_loop_begin: | |
4151 | return "DW_AT_MIPS_tail_loop_begin"; | |
4152 | case DW_AT_MIPS_epilog_begin: | |
4153 | return "DW_AT_MIPS_epilog_begin"; | |
4154 | case DW_AT_MIPS_loop_unroll_factor: | |
4155 | return "DW_AT_MIPS_loop_unroll_factor"; | |
4156 | case DW_AT_MIPS_software_pipeline_depth: | |
4157 | return "DW_AT_MIPS_software_pipeline_depth"; | |
4158 | case DW_AT_MIPS_linkage_name: | |
4159 | return "DW_AT_MIPS_linkage_name"; | |
4160 | case DW_AT_MIPS_stride: | |
4161 | return "DW_AT_MIPS_stride"; | |
4162 | case DW_AT_MIPS_abstract_name: | |
4163 | return "DW_AT_MIPS_abstract_name"; | |
4164 | case DW_AT_MIPS_clone_origin: | |
4165 | return "DW_AT_MIPS_clone_origin"; | |
4166 | case DW_AT_MIPS_has_inlines: | |
4167 | return "DW_AT_MIPS_has_inlines"; | |
4168 | ||
4169 | case DW_AT_sf_names: | |
4170 | return "DW_AT_sf_names"; | |
4171 | case DW_AT_src_info: | |
4172 | return "DW_AT_src_info"; | |
4173 | case DW_AT_mac_info: | |
4174 | return "DW_AT_mac_info"; | |
4175 | case DW_AT_src_coords: | |
4176 | return "DW_AT_src_coords"; | |
4177 | case DW_AT_body_begin: | |
4178 | return "DW_AT_body_begin"; | |
4179 | case DW_AT_body_end: | |
4180 | return "DW_AT_body_end"; | |
84f0ace0 JM |
4181 | case DW_AT_GNU_vector: |
4182 | return "DW_AT_GNU_vector"; | |
4183 | ||
7a0c8d71 DR |
4184 | case DW_AT_VMS_rtnbeg_pd_address: |
4185 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
4186 | ||
7d9d8943 AM |
4187 | default: |
4188 | return "DW_AT_<unknown>"; | |
4189 | } | |
4190 | } | |
4191 | ||
4192 | /* Convert a DWARF value form code into its string name. */ | |
4193 | ||
4194 | static const char * | |
4195 | dwarf_form_name (form) | |
b3694847 | 4196 | unsigned form; |
7d9d8943 AM |
4197 | { |
4198 | switch (form) | |
4199 | { | |
4200 | case DW_FORM_addr: | |
4201 | return "DW_FORM_addr"; | |
4202 | case DW_FORM_block2: | |
4203 | return "DW_FORM_block2"; | |
4204 | case DW_FORM_block4: | |
4205 | return "DW_FORM_block4"; | |
4206 | case DW_FORM_data2: | |
4207 | return "DW_FORM_data2"; | |
4208 | case DW_FORM_data4: | |
4209 | return "DW_FORM_data4"; | |
4210 | case DW_FORM_data8: | |
4211 | return "DW_FORM_data8"; | |
4212 | case DW_FORM_string: | |
4213 | return "DW_FORM_string"; | |
4214 | case DW_FORM_block: | |
4215 | return "DW_FORM_block"; | |
4216 | case DW_FORM_block1: | |
4217 | return "DW_FORM_block1"; | |
4218 | case DW_FORM_data1: | |
4219 | return "DW_FORM_data1"; | |
4220 | case DW_FORM_flag: | |
4221 | return "DW_FORM_flag"; | |
4222 | case DW_FORM_sdata: | |
4223 | return "DW_FORM_sdata"; | |
4224 | case DW_FORM_strp: | |
4225 | return "DW_FORM_strp"; | |
4226 | case DW_FORM_udata: | |
4227 | return "DW_FORM_udata"; | |
4228 | case DW_FORM_ref_addr: | |
4229 | return "DW_FORM_ref_addr"; | |
4230 | case DW_FORM_ref1: | |
4231 | return "DW_FORM_ref1"; | |
4232 | case DW_FORM_ref2: | |
4233 | return "DW_FORM_ref2"; | |
4234 | case DW_FORM_ref4: | |
4235 | return "DW_FORM_ref4"; | |
4236 | case DW_FORM_ref8: | |
4237 | return "DW_FORM_ref8"; | |
4238 | case DW_FORM_ref_udata: | |
4239 | return "DW_FORM_ref_udata"; | |
4240 | case DW_FORM_indirect: | |
4241 | return "DW_FORM_indirect"; | |
3f76745e | 4242 | default: |
7d9d8943 | 4243 | return "DW_FORM_<unknown>"; |
a3f97cbb JW |
4244 | } |
4245 | } | |
4246 | ||
3f76745e | 4247 | /* Convert a DWARF type code into its string name. */ |
71dfc51f | 4248 | |
487a6e06 | 4249 | #if 0 |
d560ee52 | 4250 | static const char * |
3f76745e | 4251 | dwarf_type_encoding_name (enc) |
b3694847 | 4252 | unsigned enc; |
a3f97cbb | 4253 | { |
3f76745e | 4254 | switch (enc) |
a3f97cbb | 4255 | { |
3f76745e JM |
4256 | case DW_ATE_address: |
4257 | return "DW_ATE_address"; | |
4258 | case DW_ATE_boolean: | |
4259 | return "DW_ATE_boolean"; | |
4260 | case DW_ATE_complex_float: | |
4261 | return "DW_ATE_complex_float"; | |
4262 | case DW_ATE_float: | |
4263 | return "DW_ATE_float"; | |
4264 | case DW_ATE_signed: | |
4265 | return "DW_ATE_signed"; | |
4266 | case DW_ATE_signed_char: | |
4267 | return "DW_ATE_signed_char"; | |
4268 | case DW_ATE_unsigned: | |
4269 | return "DW_ATE_unsigned"; | |
4270 | case DW_ATE_unsigned_char: | |
4271 | return "DW_ATE_unsigned_char"; | |
4272 | default: | |
4273 | return "DW_ATE_<unknown>"; | |
4274 | } | |
a3f97cbb | 4275 | } |
487a6e06 | 4276 | #endif |
3f76745e JM |
4277 | \f |
4278 | /* Determine the "ultimate origin" of a decl. The decl may be an inlined | |
4279 | instance of an inlined instance of a decl which is local to an inline | |
4280 | function, so we have to trace all of the way back through the origin chain | |
4281 | to find out what sort of node actually served as the original seed for the | |
4282 | given block. */ | |
a3f97cbb | 4283 | |
3f76745e JM |
4284 | static tree |
4285 | decl_ultimate_origin (decl) | |
b3694847 | 4286 | tree decl; |
a3f97cbb | 4287 | { |
10a11b75 JM |
4288 | /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the |
4289 | nodes in the function to point to themselves; ignore that if | |
4290 | we're trying to output the abstract instance of this function. */ | |
4291 | if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl) | |
4292 | return NULL_TREE; | |
4293 | ||
556273e0 | 4294 | #ifdef ENABLE_CHECKING |
02e24c7a MM |
4295 | if (DECL_FROM_INLINE (DECL_ORIGIN (decl))) |
4296 | /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the | |
4297 | most distant ancestor, this should never happen. */ | |
4298 | abort (); | |
4299 | #endif | |
3f76745e | 4300 | |
02e24c7a | 4301 | return DECL_ABSTRACT_ORIGIN (decl); |
a3f97cbb JW |
4302 | } |
4303 | ||
3f76745e JM |
4304 | /* Determine the "ultimate origin" of a block. The block may be an inlined |
4305 | instance of an inlined instance of a block which is local to an inline | |
4306 | function, so we have to trace all of the way back through the origin chain | |
4307 | to find out what sort of node actually served as the original seed for the | |
4308 | given block. */ | |
71dfc51f | 4309 | |
3f76745e JM |
4310 | static tree |
4311 | block_ultimate_origin (block) | |
b3694847 | 4312 | tree block; |
a3f97cbb | 4313 | { |
b3694847 | 4314 | tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); |
71dfc51f | 4315 | |
10a11b75 JM |
4316 | /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the |
4317 | nodes in the function to point to themselves; ignore that if | |
4318 | we're trying to output the abstract instance of this function. */ | |
4319 | if (BLOCK_ABSTRACT (block) && immediate_origin == block) | |
4320 | return NULL_TREE; | |
4321 | ||
3f76745e JM |
4322 | if (immediate_origin == NULL_TREE) |
4323 | return NULL_TREE; | |
4324 | else | |
4325 | { | |
b3694847 SS |
4326 | tree ret_val; |
4327 | tree lookahead = immediate_origin; | |
71dfc51f | 4328 | |
3f76745e JM |
4329 | do |
4330 | { | |
4331 | ret_val = lookahead; | |
2ad9852d RK |
4332 | lookahead = (TREE_CODE (ret_val) == BLOCK |
4333 | ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL); | |
3f76745e JM |
4334 | } |
4335 | while (lookahead != NULL && lookahead != ret_val); | |
4336 | ||
4337 | return ret_val; | |
4338 | } | |
a3f97cbb JW |
4339 | } |
4340 | ||
3f76745e JM |
4341 | /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT |
4342 | of a virtual function may refer to a base class, so we check the 'this' | |
4343 | parameter. */ | |
71dfc51f | 4344 | |
3f76745e JM |
4345 | static tree |
4346 | decl_class_context (decl) | |
4347 | tree decl; | |
a3f97cbb | 4348 | { |
3f76745e | 4349 | tree context = NULL_TREE; |
71dfc51f | 4350 | |
3f76745e JM |
4351 | if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl)) |
4352 | context = DECL_CONTEXT (decl); | |
4353 | else | |
4354 | context = TYPE_MAIN_VARIANT | |
4355 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
71dfc51f | 4356 | |
2f939d94 | 4357 | if (context && !TYPE_P (context)) |
3f76745e JM |
4358 | context = NULL_TREE; |
4359 | ||
4360 | return context; | |
a3f97cbb JW |
4361 | } |
4362 | \f | |
a96c67ec | 4363 | /* Add an attribute/value pair to a DIE. We build the lists up in reverse |
881c6935 | 4364 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f RK |
4365 | |
4366 | static inline void | |
3f76745e | 4367 | add_dwarf_attr (die, attr) |
b3694847 SS |
4368 | dw_die_ref die; |
4369 | dw_attr_ref attr; | |
a3f97cbb | 4370 | { |
3f76745e | 4371 | if (die != NULL && attr != NULL) |
a3f97cbb | 4372 | { |
a96c67ec JM |
4373 | attr->dw_attr_next = die->die_attr; |
4374 | die->die_attr = attr; | |
a3f97cbb JW |
4375 | } |
4376 | } | |
4377 | ||
a96c67ec JM |
4378 | static inline dw_val_class |
4379 | AT_class (a) | |
4380 | dw_attr_ref a; | |
4381 | { | |
4382 | return a->dw_attr_val.val_class; | |
4383 | } | |
4384 | ||
3f76745e | 4385 | /* Add a flag value attribute to a DIE. */ |
71dfc51f | 4386 | |
3f76745e JM |
4387 | static inline void |
4388 | add_AT_flag (die, attr_kind, flag) | |
b3694847 SS |
4389 | dw_die_ref die; |
4390 | enum dwarf_attribute attr_kind; | |
4391 | unsigned flag; | |
a3f97cbb | 4392 | { |
b3694847 | 4393 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4394 | |
3f76745e JM |
4395 | attr->dw_attr_next = NULL; |
4396 | attr->dw_attr = attr_kind; | |
4397 | attr->dw_attr_val.val_class = dw_val_class_flag; | |
4398 | attr->dw_attr_val.v.val_flag = flag; | |
4399 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4400 | } |
4401 | ||
a96c67ec JM |
4402 | static inline unsigned |
4403 | AT_flag (a) | |
b3694847 | 4404 | dw_attr_ref a; |
a96c67ec JM |
4405 | { |
4406 | if (a && AT_class (a) == dw_val_class_flag) | |
4407 | return a->dw_attr_val.v.val_flag; | |
4408 | ||
40e8cc95 | 4409 | abort (); |
a96c67ec JM |
4410 | } |
4411 | ||
3f76745e | 4412 | /* Add a signed integer attribute value to a DIE. */ |
71dfc51f | 4413 | |
3f76745e JM |
4414 | static inline void |
4415 | add_AT_int (die, attr_kind, int_val) | |
b3694847 SS |
4416 | dw_die_ref die; |
4417 | enum dwarf_attribute attr_kind; | |
4418 | long int int_val; | |
a3f97cbb | 4419 | { |
b3694847 | 4420 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3f76745e JM |
4421 | |
4422 | attr->dw_attr_next = NULL; | |
4423 | attr->dw_attr = attr_kind; | |
4424 | attr->dw_attr_val.val_class = dw_val_class_const; | |
4425 | attr->dw_attr_val.v.val_int = int_val; | |
4426 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4427 | } |
4428 | ||
a96c67ec JM |
4429 | static inline long int |
4430 | AT_int (a) | |
b3694847 | 4431 | dw_attr_ref a; |
a96c67ec JM |
4432 | { |
4433 | if (a && AT_class (a) == dw_val_class_const) | |
4434 | return a->dw_attr_val.v.val_int; | |
4435 | ||
40e8cc95 | 4436 | abort (); |
a96c67ec JM |
4437 | } |
4438 | ||
3f76745e | 4439 | /* Add an unsigned integer attribute value to a DIE. */ |
71dfc51f | 4440 | |
3f76745e JM |
4441 | static inline void |
4442 | add_AT_unsigned (die, attr_kind, unsigned_val) | |
b3694847 SS |
4443 | dw_die_ref die; |
4444 | enum dwarf_attribute attr_kind; | |
4445 | unsigned long unsigned_val; | |
a3f97cbb | 4446 | { |
b3694847 | 4447 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3f76745e JM |
4448 | |
4449 | attr->dw_attr_next = NULL; | |
4450 | attr->dw_attr = attr_kind; | |
4451 | attr->dw_attr_val.val_class = dw_val_class_unsigned_const; | |
4452 | attr->dw_attr_val.v.val_unsigned = unsigned_val; | |
4453 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4454 | } |
71dfc51f | 4455 | |
a96c67ec JM |
4456 | static inline unsigned long |
4457 | AT_unsigned (a) | |
b3694847 | 4458 | dw_attr_ref a; |
a96c67ec JM |
4459 | { |
4460 | if (a && AT_class (a) == dw_val_class_unsigned_const) | |
4461 | return a->dw_attr_val.v.val_unsigned; | |
4462 | ||
40e8cc95 | 4463 | abort (); |
a96c67ec JM |
4464 | } |
4465 | ||
3f76745e JM |
4466 | /* Add an unsigned double integer attribute value to a DIE. */ |
4467 | ||
4468 | static inline void | |
4469 | add_AT_long_long (die, attr_kind, val_hi, val_low) | |
b3694847 SS |
4470 | dw_die_ref die; |
4471 | enum dwarf_attribute attr_kind; | |
4472 | unsigned long val_hi; | |
4473 | unsigned long val_low; | |
a3f97cbb | 4474 | { |
b3694847 | 4475 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4476 | |
3f76745e JM |
4477 | attr->dw_attr_next = NULL; |
4478 | attr->dw_attr = attr_kind; | |
4479 | attr->dw_attr_val.val_class = dw_val_class_long_long; | |
4480 | attr->dw_attr_val.v.val_long_long.hi = val_hi; | |
4481 | attr->dw_attr_val.v.val_long_long.low = val_low; | |
4482 | add_dwarf_attr (die, attr); | |
4483 | } | |
71dfc51f | 4484 | |
3f76745e | 4485 | /* Add a floating point attribute value to a DIE and return it. */ |
71dfc51f | 4486 | |
3f76745e JM |
4487 | static inline void |
4488 | add_AT_float (die, attr_kind, length, array) | |
b3694847 SS |
4489 | dw_die_ref die; |
4490 | enum dwarf_attribute attr_kind; | |
4491 | unsigned length; | |
4492 | long *array; | |
3f76745e | 4493 | { |
b3694847 | 4494 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3f76745e JM |
4495 | |
4496 | attr->dw_attr_next = NULL; | |
4497 | attr->dw_attr = attr_kind; | |
4498 | attr->dw_attr_val.val_class = dw_val_class_float; | |
4499 | attr->dw_attr_val.v.val_float.length = length; | |
4500 | attr->dw_attr_val.v.val_float.array = array; | |
4501 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4502 | } |
4503 | ||
3f76745e | 4504 | /* Add a string attribute value to a DIE. */ |
71dfc51f | 4505 | |
3f76745e JM |
4506 | static inline void |
4507 | add_AT_string (die, attr_kind, str) | |
b3694847 SS |
4508 | dw_die_ref die; |
4509 | enum dwarf_attribute attr_kind; | |
4510 | const char *str; | |
a3f97cbb | 4511 | { |
b3694847 | 4512 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
9eb4015a | 4513 | struct indirect_string_node *node; |
c26fbbca | 4514 | |
9eb4015a JJ |
4515 | if (! debug_str_hash) |
4516 | { | |
4517 | debug_str_hash = ht_create (10); | |
4518 | debug_str_hash->alloc_node = indirect_string_alloc; | |
4519 | } | |
4520 | ||
4521 | node = (struct indirect_string_node *) | |
4522 | ht_lookup (debug_str_hash, (const unsigned char *) str, | |
4523 | strlen (str), HT_ALLOC); | |
4524 | node->refcount++; | |
71dfc51f | 4525 | |
3f76745e JM |
4526 | attr->dw_attr_next = NULL; |
4527 | attr->dw_attr = attr_kind; | |
4528 | attr->dw_attr_val.val_class = dw_val_class_str; | |
9eb4015a | 4529 | attr->dw_attr_val.v.val_str = node; |
3f76745e JM |
4530 | add_dwarf_attr (die, attr); |
4531 | } | |
71dfc51f | 4532 | |
a96c67ec JM |
4533 | static inline const char * |
4534 | AT_string (a) | |
b3694847 | 4535 | dw_attr_ref a; |
a96c67ec JM |
4536 | { |
4537 | if (a && AT_class (a) == dw_val_class_str) | |
9eb4015a JJ |
4538 | return (const char *) HT_STR (&a->dw_attr_val.v.val_str->id); |
4539 | ||
4540 | abort (); | |
4541 | } | |
4542 | ||
4543 | /* Find out whether a string should be output inline in DIE | |
4544 | or out-of-line in .debug_str section. */ | |
4545 | ||
9eb4015a JJ |
4546 | static int |
4547 | AT_string_form (a) | |
4548 | dw_attr_ref a; | |
4549 | { | |
4550 | if (a && AT_class (a) == dw_val_class_str) | |
4551 | { | |
4552 | struct indirect_string_node *node; | |
4553 | unsigned int len; | |
4554 | extern int const_labelno; | |
4555 | char label[32]; | |
4556 | ||
4557 | node = a->dw_attr_val.v.val_str; | |
4558 | if (node->form) | |
4559 | return node->form; | |
4560 | ||
4561 | len = HT_LEN (&node->id) + 1; | |
4562 | ||
2ad9852d RK |
4563 | /* If the string is shorter or equal to the size of the reference, it is |
4564 | always better to put it inline. */ | |
9eb4015a JJ |
4565 | if (len <= DWARF_OFFSET_SIZE || node->refcount == 0) |
4566 | return node->form = DW_FORM_string; | |
4567 | ||
2ad9852d RK |
4568 | /* If we cannot expect the linker to merge strings in .debug_str |
4569 | section, only put it into .debug_str if it is worth even in this | |
4570 | single module. */ | |
4571 | if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0 | |
4572 | && (len - DWARF_OFFSET_SIZE) * node->refcount <= len) | |
4573 | return node->form = DW_FORM_string; | |
9eb4015a JJ |
4574 | |
4575 | ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno); | |
4576 | ++const_labelno; | |
4577 | node->label = xstrdup (label); | |
2ad9852d | 4578 | |
9eb4015a JJ |
4579 | return node->form = DW_FORM_strp; |
4580 | } | |
a96c67ec | 4581 | |
40e8cc95 | 4582 | abort (); |
a96c67ec JM |
4583 | } |
4584 | ||
3f76745e | 4585 | /* Add a DIE reference attribute value to a DIE. */ |
71dfc51f | 4586 | |
3f76745e JM |
4587 | static inline void |
4588 | add_AT_die_ref (die, attr_kind, targ_die) | |
b3694847 SS |
4589 | dw_die_ref die; |
4590 | enum dwarf_attribute attr_kind; | |
4591 | dw_die_ref targ_die; | |
3f76745e | 4592 | { |
b3694847 | 4593 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4594 | |
3f76745e JM |
4595 | attr->dw_attr_next = NULL; |
4596 | attr->dw_attr = attr_kind; | |
4597 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
881c6935 JM |
4598 | attr->dw_attr_val.v.val_die_ref.die = targ_die; |
4599 | attr->dw_attr_val.v.val_die_ref.external = 0; | |
3f76745e JM |
4600 | add_dwarf_attr (die, attr); |
4601 | } | |
b1ccbc24 | 4602 | |
a96c67ec JM |
4603 | static inline dw_die_ref |
4604 | AT_ref (a) | |
b3694847 | 4605 | dw_attr_ref a; |
a96c67ec JM |
4606 | { |
4607 | if (a && AT_class (a) == dw_val_class_die_ref) | |
881c6935 | 4608 | return a->dw_attr_val.v.val_die_ref.die; |
a96c67ec | 4609 | |
40e8cc95 | 4610 | abort (); |
a96c67ec JM |
4611 | } |
4612 | ||
881c6935 JM |
4613 | static inline int |
4614 | AT_ref_external (a) | |
b3694847 | 4615 | dw_attr_ref a; |
881c6935 JM |
4616 | { |
4617 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4618 | return a->dw_attr_val.v.val_die_ref.external; | |
4619 | ||
4620 | return 0; | |
4621 | } | |
4622 | ||
881c6935 JM |
4623 | static inline void |
4624 | set_AT_ref_external (a, i) | |
b3694847 | 4625 | dw_attr_ref a; |
881c6935 JM |
4626 | int i; |
4627 | { | |
4628 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4629 | a->dw_attr_val.v.val_die_ref.external = i; | |
4630 | else | |
4631 | abort (); | |
4632 | } | |
4633 | ||
3f76745e | 4634 | /* Add an FDE reference attribute value to a DIE. */ |
b1ccbc24 | 4635 | |
3f76745e JM |
4636 | static inline void |
4637 | add_AT_fde_ref (die, attr_kind, targ_fde) | |
b3694847 SS |
4638 | dw_die_ref die; |
4639 | enum dwarf_attribute attr_kind; | |
4640 | unsigned targ_fde; | |
3f76745e | 4641 | { |
b3694847 | 4642 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
b1ccbc24 | 4643 | |
3f76745e JM |
4644 | attr->dw_attr_next = NULL; |
4645 | attr->dw_attr = attr_kind; | |
4646 | attr->dw_attr_val.val_class = dw_val_class_fde_ref; | |
4647 | attr->dw_attr_val.v.val_fde_index = targ_fde; | |
4648 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4649 | } |
71dfc51f | 4650 | |
3f76745e | 4651 | /* Add a location description attribute value to a DIE. */ |
71dfc51f | 4652 | |
3f76745e JM |
4653 | static inline void |
4654 | add_AT_loc (die, attr_kind, loc) | |
b3694847 SS |
4655 | dw_die_ref die; |
4656 | enum dwarf_attribute attr_kind; | |
4657 | dw_loc_descr_ref loc; | |
3f76745e | 4658 | { |
b3694847 | 4659 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4660 | |
3f76745e JM |
4661 | attr->dw_attr_next = NULL; |
4662 | attr->dw_attr = attr_kind; | |
4663 | attr->dw_attr_val.val_class = dw_val_class_loc; | |
4664 | attr->dw_attr_val.v.val_loc = loc; | |
4665 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4666 | } |
4667 | ||
a96c67ec JM |
4668 | static inline dw_loc_descr_ref |
4669 | AT_loc (a) | |
b3694847 | 4670 | dw_attr_ref a; |
a96c67ec JM |
4671 | { |
4672 | if (a && AT_class (a) == dw_val_class_loc) | |
4673 | return a->dw_attr_val.v.val_loc; | |
4674 | ||
40e8cc95 | 4675 | abort (); |
a96c67ec JM |
4676 | } |
4677 | ||
63e46568 DB |
4678 | static inline void |
4679 | add_AT_loc_list (die, attr_kind, loc_list) | |
b3694847 SS |
4680 | dw_die_ref die; |
4681 | enum dwarf_attribute attr_kind; | |
4682 | dw_loc_list_ref loc_list; | |
63e46568 | 4683 | { |
b3694847 | 4684 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
63e46568 DB |
4685 | |
4686 | attr->dw_attr_next = NULL; | |
4687 | attr->dw_attr = attr_kind; | |
4688 | attr->dw_attr_val.val_class = dw_val_class_loc_list; | |
4689 | attr->dw_attr_val.v.val_loc_list = loc_list; | |
4690 | add_dwarf_attr (die, attr); | |
4691 | have_location_lists = 1; | |
4692 | } | |
4693 | ||
63e46568 DB |
4694 | static inline dw_loc_list_ref |
4695 | AT_loc_list (a) | |
b3694847 | 4696 | dw_attr_ref a; |
63e46568 DB |
4697 | { |
4698 | if (a && AT_class (a) == dw_val_class_loc_list) | |
4699 | return a->dw_attr_val.v.val_loc_list; | |
4700 | ||
4701 | abort (); | |
4702 | } | |
4703 | ||
3f76745e | 4704 | /* Add an address constant attribute value to a DIE. */ |
71dfc51f | 4705 | |
3f76745e JM |
4706 | static inline void |
4707 | add_AT_addr (die, attr_kind, addr) | |
b3694847 SS |
4708 | dw_die_ref die; |
4709 | enum dwarf_attribute attr_kind; | |
1865dbb5 | 4710 | rtx addr; |
a3f97cbb | 4711 | { |
b3694847 | 4712 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4713 | |
3f76745e JM |
4714 | attr->dw_attr_next = NULL; |
4715 | attr->dw_attr = attr_kind; | |
4716 | attr->dw_attr_val.val_class = dw_val_class_addr; | |
4717 | attr->dw_attr_val.v.val_addr = addr; | |
4718 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4719 | } |
4720 | ||
1865dbb5 | 4721 | static inline rtx |
a96c67ec | 4722 | AT_addr (a) |
b3694847 | 4723 | dw_attr_ref a; |
a96c67ec JM |
4724 | { |
4725 | if (a && AT_class (a) == dw_val_class_addr) | |
4726 | return a->dw_attr_val.v.val_addr; | |
4727 | ||
40e8cc95 | 4728 | abort (); |
a96c67ec JM |
4729 | } |
4730 | ||
3f76745e | 4731 | /* Add a label identifier attribute value to a DIE. */ |
71dfc51f | 4732 | |
3f76745e JM |
4733 | static inline void |
4734 | add_AT_lbl_id (die, attr_kind, lbl_id) | |
b3694847 SS |
4735 | dw_die_ref die; |
4736 | enum dwarf_attribute attr_kind; | |
4737 | const char *lbl_id; | |
a3f97cbb | 4738 | { |
b3694847 | 4739 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4740 | |
3f76745e JM |
4741 | attr->dw_attr_next = NULL; |
4742 | attr->dw_attr = attr_kind; | |
4743 | attr->dw_attr_val.val_class = dw_val_class_lbl_id; | |
4744 | attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); | |
4745 | add_dwarf_attr (die, attr); | |
4746 | } | |
71dfc51f | 4747 | |
3f76745e JM |
4748 | /* Add a section offset attribute value to a DIE. */ |
4749 | ||
4750 | static inline void | |
8b790721 | 4751 | add_AT_lbl_offset (die, attr_kind, label) |
b3694847 SS |
4752 | dw_die_ref die; |
4753 | enum dwarf_attribute attr_kind; | |
4754 | const char *label; | |
3f76745e | 4755 | { |
b3694847 | 4756 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4757 | |
3f76745e JM |
4758 | attr->dw_attr_next = NULL; |
4759 | attr->dw_attr = attr_kind; | |
8b790721 | 4760 | attr->dw_attr_val.val_class = dw_val_class_lbl_offset; |
a96c67ec | 4761 | attr->dw_attr_val.v.val_lbl_id = xstrdup (label); |
3f76745e | 4762 | add_dwarf_attr (die, attr); |
a3f97cbb JW |
4763 | } |
4764 | ||
a20612aa RH |
4765 | /* Add an offset attribute value to a DIE. */ |
4766 | ||
2bee6045 | 4767 | static inline void |
a20612aa | 4768 | add_AT_offset (die, attr_kind, offset) |
b3694847 SS |
4769 | dw_die_ref die; |
4770 | enum dwarf_attribute attr_kind; | |
4771 | unsigned long offset; | |
a20612aa | 4772 | { |
b3694847 | 4773 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
a20612aa RH |
4774 | |
4775 | attr->dw_attr_next = NULL; | |
4776 | attr->dw_attr = attr_kind; | |
4777 | attr->dw_attr_val.val_class = dw_val_class_offset; | |
4778 | attr->dw_attr_val.v.val_offset = offset; | |
4779 | add_dwarf_attr (die, attr); | |
4780 | } | |
4781 | ||
2bee6045 JJ |
4782 | /* Add an range_list attribute value to a DIE. */ |
4783 | ||
4784 | static void | |
4785 | add_AT_range_list (die, attr_kind, offset) | |
4786 | dw_die_ref die; | |
4787 | enum dwarf_attribute attr_kind; | |
4788 | unsigned long offset; | |
4789 | { | |
4790 | dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
4791 | ||
4792 | attr->dw_attr_next = NULL; | |
4793 | attr->dw_attr = attr_kind; | |
4794 | attr->dw_attr_val.val_class = dw_val_class_range_list; | |
4795 | attr->dw_attr_val.v.val_offset = offset; | |
4796 | add_dwarf_attr (die, attr); | |
4797 | } | |
4798 | ||
a96c67ec JM |
4799 | static inline const char * |
4800 | AT_lbl (a) | |
b3694847 | 4801 | dw_attr_ref a; |
a3f97cbb | 4802 | { |
a96c67ec JM |
4803 | if (a && (AT_class (a) == dw_val_class_lbl_id |
4804 | || AT_class (a) == dw_val_class_lbl_offset)) | |
4805 | return a->dw_attr_val.v.val_lbl_id; | |
71dfc51f | 4806 | |
40e8cc95 | 4807 | abort (); |
a3f97cbb JW |
4808 | } |
4809 | ||
3f76745e | 4810 | /* Get the attribute of type attr_kind. */ |
71dfc51f | 4811 | |
3f76745e JM |
4812 | static inline dw_attr_ref |
4813 | get_AT (die, attr_kind) | |
b3694847 SS |
4814 | dw_die_ref die; |
4815 | enum dwarf_attribute attr_kind; | |
f37230f0 | 4816 | { |
b3694847 SS |
4817 | dw_attr_ref a; |
4818 | dw_die_ref spec = NULL; | |
556273e0 | 4819 | |
3f76745e JM |
4820 | if (die != NULL) |
4821 | { | |
4822 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
2ad9852d RK |
4823 | if (a->dw_attr == attr_kind) |
4824 | return a; | |
4825 | else if (a->dw_attr == DW_AT_specification | |
4826 | || a->dw_attr == DW_AT_abstract_origin) | |
4827 | spec = AT_ref (a); | |
71dfc51f | 4828 | |
3f76745e JM |
4829 | if (spec) |
4830 | return get_AT (spec, attr_kind); | |
4831 | } | |
4832 | ||
4833 | return NULL; | |
f37230f0 JM |
4834 | } |
4835 | ||
2ad9852d RK |
4836 | /* Return the "low pc" attribute value, typically associated with a subprogram |
4837 | DIE. Return null if the "low pc" attribute is either not present, or if it | |
4838 | cannot be represented as an assembler label identifier. */ | |
71dfc51f | 4839 | |
a96c67ec | 4840 | static inline const char * |
3f76745e | 4841 | get_AT_low_pc (die) |
b3694847 | 4842 | dw_die_ref die; |
7e23cb16 | 4843 | { |
b3694847 | 4844 | dw_attr_ref a = get_AT (die, DW_AT_low_pc); |
2ad9852d | 4845 | |
40e8cc95 | 4846 | return a ? AT_lbl (a) : NULL; |
7e23cb16 JM |
4847 | } |
4848 | ||
2ad9852d RK |
4849 | /* Return the "high pc" attribute value, typically associated with a subprogram |
4850 | DIE. Return null if the "high pc" attribute is either not present, or if it | |
4851 | cannot be represented as an assembler label identifier. */ | |
71dfc51f | 4852 | |
a96c67ec | 4853 | static inline const char * |
3f76745e | 4854 | get_AT_hi_pc (die) |
b3694847 | 4855 | dw_die_ref die; |
a3f97cbb | 4856 | { |
b3694847 | 4857 | dw_attr_ref a = get_AT (die, DW_AT_high_pc); |
2ad9852d | 4858 | |
40e8cc95 | 4859 | return a ? AT_lbl (a) : NULL; |
3f76745e JM |
4860 | } |
4861 | ||
4862 | /* Return the value of the string attribute designated by ATTR_KIND, or | |
4863 | NULL if it is not present. */ | |
71dfc51f | 4864 | |
a96c67ec | 4865 | static inline const char * |
3f76745e | 4866 | get_AT_string (die, attr_kind) |
b3694847 SS |
4867 | dw_die_ref die; |
4868 | enum dwarf_attribute attr_kind; | |
3f76745e | 4869 | { |
b3694847 | 4870 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4871 | |
40e8cc95 | 4872 | return a ? AT_string (a) : NULL; |
a3f97cbb JW |
4873 | } |
4874 | ||
3f76745e JM |
4875 | /* Return the value of the flag attribute designated by ATTR_KIND, or -1 |
4876 | if it is not present. */ | |
71dfc51f | 4877 | |
3f76745e JM |
4878 | static inline int |
4879 | get_AT_flag (die, attr_kind) | |
b3694847 SS |
4880 | dw_die_ref die; |
4881 | enum dwarf_attribute attr_kind; | |
a3f97cbb | 4882 | { |
b3694847 | 4883 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4884 | |
40e8cc95 | 4885 | return a ? AT_flag (a) : 0; |
a3f97cbb JW |
4886 | } |
4887 | ||
3f76745e JM |
4888 | /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0 |
4889 | if it is not present. */ | |
71dfc51f | 4890 | |
3f76745e JM |
4891 | static inline unsigned |
4892 | get_AT_unsigned (die, attr_kind) | |
b3694847 SS |
4893 | dw_die_ref die; |
4894 | enum dwarf_attribute attr_kind; | |
a3f97cbb | 4895 | { |
b3694847 | 4896 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4897 | |
40e8cc95 | 4898 | return a ? AT_unsigned (a) : 0; |
a96c67ec | 4899 | } |
71dfc51f | 4900 | |
a96c67ec JM |
4901 | static inline dw_die_ref |
4902 | get_AT_ref (die, attr_kind) | |
4903 | dw_die_ref die; | |
b3694847 | 4904 | enum dwarf_attribute attr_kind; |
a96c67ec | 4905 | { |
b3694847 | 4906 | dw_attr_ref a = get_AT (die, attr_kind); |
2ad9852d | 4907 | |
40e8cc95 | 4908 | return a ? AT_ref (a) : NULL; |
3f76745e | 4909 | } |
71dfc51f | 4910 | |
3f76745e JM |
4911 | static inline int |
4912 | is_c_family () | |
4913 | { | |
b3694847 | 4914 | unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
71dfc51f | 4915 | |
3f76745e JM |
4916 | return (lang == DW_LANG_C || lang == DW_LANG_C89 |
4917 | || lang == DW_LANG_C_plus_plus); | |
556273e0 | 4918 | } |
71dfc51f | 4919 | |
1d3d6b1e JM |
4920 | static inline int |
4921 | is_cxx () | |
4922 | { | |
4923 | return (get_AT_unsigned (comp_unit_die, DW_AT_language) | |
4924 | == DW_LANG_C_plus_plus); | |
c26fbbca | 4925 | } |
1d3d6b1e | 4926 | |
3f76745e JM |
4927 | static inline int |
4928 | is_fortran () | |
4929 | { | |
b3694847 | 4930 | unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
71dfc51f | 4931 | |
3f76745e | 4932 | return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90); |
556273e0 | 4933 | } |
71dfc51f | 4934 | |
28985b81 AG |
4935 | static inline int |
4936 | is_java () | |
4937 | { | |
b3694847 | 4938 | unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); |
28985b81 AG |
4939 | |
4940 | return (lang == DW_LANG_Java); | |
4941 | } | |
4942 | ||
10a11b75 | 4943 | /* Free up the memory used by A. */ |
71dfc51f | 4944 | |
c6991660 | 4945 | static inline void free_AT PARAMS ((dw_attr_ref)); |
3f76745e | 4946 | static inline void |
10a11b75 JM |
4947 | free_AT (a) |
4948 | dw_attr_ref a; | |
4949 | { | |
4950 | switch (AT_class (a)) | |
4951 | { | |
10a11b75 | 4952 | case dw_val_class_str: |
9eb4015a JJ |
4953 | if (a->dw_attr_val.v.val_str->refcount) |
4954 | a->dw_attr_val.v.val_str->refcount--; | |
4955 | break; | |
4956 | ||
10a11b75 JM |
4957 | case dw_val_class_lbl_id: |
4958 | case dw_val_class_lbl_offset: | |
9eb4015a | 4959 | free (a->dw_attr_val.v.val_lbl_id); |
10a11b75 JM |
4960 | break; |
4961 | ||
3724ec07 WC |
4962 | case dw_val_class_float: |
4963 | free (a->dw_attr_val.v.val_float.array); | |
4964 | break; | |
0b34cf1e | 4965 | |
10a11b75 JM |
4966 | default: |
4967 | break; | |
4968 | } | |
4969 | ||
4970 | free (a); | |
556273e0 | 4971 | } |
10a11b75 JM |
4972 | |
4973 | /* Remove the specified attribute if present. */ | |
4974 | ||
4975 | static void | |
3f76745e | 4976 | remove_AT (die, attr_kind) |
b3694847 SS |
4977 | dw_die_ref die; |
4978 | enum dwarf_attribute attr_kind; | |
3f76745e | 4979 | { |
b3694847 SS |
4980 | dw_attr_ref *p; |
4981 | dw_attr_ref removed = NULL; | |
a3f97cbb | 4982 | |
3f76745e JM |
4983 | if (die != NULL) |
4984 | { | |
a96c67ec JM |
4985 | for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next)) |
4986 | if ((*p)->dw_attr == attr_kind) | |
4987 | { | |
4988 | removed = *p; | |
4989 | *p = (*p)->dw_attr_next; | |
4990 | break; | |
4991 | } | |
71dfc51f | 4992 | |
a96c67ec | 4993 | if (removed != 0) |
10a11b75 JM |
4994 | free_AT (removed); |
4995 | } | |
4996 | } | |
71dfc51f | 4997 | |
10a11b75 | 4998 | /* Free up the memory used by DIE. */ |
71dfc51f | 4999 | |
10a11b75 JM |
5000 | static inline void |
5001 | free_die (die) | |
5002 | dw_die_ref die; | |
5003 | { | |
5004 | remove_children (die); | |
5005 | free (die); | |
3f76745e | 5006 | } |
71dfc51f | 5007 | |
3f76745e | 5008 | /* Discard the children of this DIE. */ |
71dfc51f | 5009 | |
10a11b75 | 5010 | static void |
3f76745e | 5011 | remove_children (die) |
b3694847 | 5012 | dw_die_ref die; |
3f76745e | 5013 | { |
b3694847 | 5014 | dw_die_ref child_die = die->die_child; |
3f76745e JM |
5015 | |
5016 | die->die_child = NULL; | |
3f76745e JM |
5017 | |
5018 | while (child_die != NULL) | |
a3f97cbb | 5019 | { |
b3694847 SS |
5020 | dw_die_ref tmp_die = child_die; |
5021 | dw_attr_ref a; | |
71dfc51f | 5022 | |
3f76745e | 5023 | child_die = child_die->die_sib; |
556273e0 KH |
5024 | |
5025 | for (a = tmp_die->die_attr; a != NULL;) | |
a3f97cbb | 5026 | { |
b3694847 | 5027 | dw_attr_ref tmp_a = a; |
71dfc51f | 5028 | |
3f76745e | 5029 | a = a->dw_attr_next; |
10a11b75 | 5030 | free_AT (tmp_a); |
a3f97cbb | 5031 | } |
71dfc51f | 5032 | |
10a11b75 | 5033 | free_die (tmp_die); |
3f76745e JM |
5034 | } |
5035 | } | |
71dfc51f | 5036 | |
a96c67ec | 5037 | /* Add a child DIE below its parent. We build the lists up in reverse |
881c6935 | 5038 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f | 5039 | |
3f76745e JM |
5040 | static inline void |
5041 | add_child_die (die, child_die) | |
b3694847 SS |
5042 | dw_die_ref die; |
5043 | dw_die_ref child_die; | |
3f76745e JM |
5044 | { |
5045 | if (die != NULL && child_die != NULL) | |
e90b62db | 5046 | { |
3a88cbd1 JL |
5047 | if (die == child_die) |
5048 | abort (); | |
2ad9852d | 5049 | |
3f76745e | 5050 | child_die->die_parent = die; |
a96c67ec JM |
5051 | child_die->die_sib = die->die_child; |
5052 | die->die_child = child_die; | |
3f76745e JM |
5053 | } |
5054 | } | |
5055 | ||
2081603c JM |
5056 | /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT |
5057 | is the specification, to the front of PARENT's list of children. */ | |
10a11b75 JM |
5058 | |
5059 | static void | |
5060 | splice_child_die (parent, child) | |
5061 | dw_die_ref parent, child; | |
5062 | { | |
5063 | dw_die_ref *p; | |
5064 | ||
5065 | /* We want the declaration DIE from inside the class, not the | |
5066 | specification DIE at toplevel. */ | |
5067 | if (child->die_parent != parent) | |
2081603c JM |
5068 | { |
5069 | dw_die_ref tmp = get_AT_ref (child, DW_AT_specification); | |
2ad9852d | 5070 | |
2081603c JM |
5071 | if (tmp) |
5072 | child = tmp; | |
5073 | } | |
10a11b75 | 5074 | |
2081603c JM |
5075 | if (child->die_parent != parent |
5076 | && child->die_parent != get_AT_ref (parent, DW_AT_specification)) | |
10a11b75 JM |
5077 | abort (); |
5078 | ||
5de0e8d4 | 5079 | for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib)) |
10a11b75 JM |
5080 | if (*p == child) |
5081 | { | |
5082 | *p = child->die_sib; | |
5083 | break; | |
5084 | } | |
5085 | ||
5086 | child->die_sib = parent->die_child; | |
5087 | parent->die_child = child; | |
5088 | } | |
5089 | ||
3f76745e JM |
5090 | /* Return a pointer to a newly created DIE node. */ |
5091 | ||
5092 | static inline dw_die_ref | |
54ba1f0d | 5093 | new_die (tag_value, parent_die, t) |
b3694847 SS |
5094 | enum dwarf_tag tag_value; |
5095 | dw_die_ref parent_die; | |
54ba1f0d | 5096 | tree t; |
3f76745e | 5097 | { |
b3694847 | 5098 | dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node)); |
3f76745e JM |
5099 | |
5100 | die->die_tag = tag_value; | |
3f76745e JM |
5101 | |
5102 | if (parent_die != NULL) | |
5103 | add_child_die (parent_die, die); | |
5104 | else | |
ef76d03b JW |
5105 | { |
5106 | limbo_die_node *limbo_node; | |
5107 | ||
5108 | limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node)); | |
5109 | limbo_node->die = die; | |
54ba1f0d | 5110 | limbo_node->created_for = t; |
ef76d03b JW |
5111 | limbo_node->next = limbo_die_list; |
5112 | limbo_die_list = limbo_node; | |
5113 | } | |
71dfc51f | 5114 | |
3f76745e JM |
5115 | return die; |
5116 | } | |
71dfc51f | 5117 | |
3f76745e | 5118 | /* Return the DIE associated with the given type specifier. */ |
71dfc51f | 5119 | |
3f76745e JM |
5120 | static inline dw_die_ref |
5121 | lookup_type_die (type) | |
b3694847 | 5122 | tree type; |
3f76745e JM |
5123 | { |
5124 | return (dw_die_ref) TYPE_SYMTAB_POINTER (type); | |
5125 | } | |
e90b62db | 5126 | |
3f76745e | 5127 | /* Equate a DIE to a given type specifier. */ |
71dfc51f | 5128 | |
10a11b75 | 5129 | static inline void |
3f76745e | 5130 | equate_type_number_to_die (type, type_die) |
b3694847 SS |
5131 | tree type; |
5132 | dw_die_ref type_die; | |
3f76745e JM |
5133 | { |
5134 | TYPE_SYMTAB_POINTER (type) = (char *) type_die; | |
5135 | } | |
71dfc51f | 5136 | |
3f76745e | 5137 | /* Return the DIE associated with a given declaration. */ |
71dfc51f | 5138 | |
3f76745e JM |
5139 | static inline dw_die_ref |
5140 | lookup_decl_die (decl) | |
b3694847 | 5141 | tree decl; |
3f76745e | 5142 | { |
b3694847 | 5143 | unsigned decl_id = DECL_UID (decl); |
3f76745e | 5144 | |
2ad9852d | 5145 | return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL); |
a3f97cbb JW |
5146 | } |
5147 | ||
3f76745e | 5148 | /* Equate a DIE to a particular declaration. */ |
71dfc51f | 5149 | |
3f76745e JM |
5150 | static void |
5151 | equate_decl_number_to_die (decl, decl_die) | |
b3694847 SS |
5152 | tree decl; |
5153 | dw_die_ref decl_die; | |
a3f97cbb | 5154 | { |
aea9695c RK |
5155 | unsigned int decl_id = DECL_UID (decl); |
5156 | unsigned int num_allocated; | |
d291dd49 | 5157 | |
3f76745e | 5158 | if (decl_id >= decl_die_table_allocated) |
a3f97cbb | 5159 | { |
3f76745e JM |
5160 | num_allocated |
5161 | = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1) | |
5162 | / DECL_DIE_TABLE_INCREMENT) | |
5163 | * DECL_DIE_TABLE_INCREMENT; | |
5164 | ||
5165 | decl_die_table | |
5166 | = (dw_die_ref *) xrealloc (decl_die_table, | |
5167 | sizeof (dw_die_ref) * num_allocated); | |
5168 | ||
961192e1 | 5169 | memset ((char *) &decl_die_table[decl_die_table_allocated], 0, |
3f76745e JM |
5170 | (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref)); |
5171 | decl_die_table_allocated = num_allocated; | |
a3f97cbb | 5172 | } |
71dfc51f | 5173 | |
3f76745e JM |
5174 | if (decl_id >= decl_die_table_in_use) |
5175 | decl_die_table_in_use = (decl_id + 1); | |
5176 | ||
5177 | decl_die_table[decl_id] = decl_die; | |
a3f97cbb | 5178 | } |
3f76745e JM |
5179 | \f |
5180 | /* Keep track of the number of spaces used to indent the | |
5181 | output of the debugging routines that print the structure of | |
5182 | the DIE internal representation. */ | |
5183 | static int print_indent; | |
71dfc51f | 5184 | |
3f76745e JM |
5185 | /* Indent the line the number of spaces given by print_indent. */ |
5186 | ||
5187 | static inline void | |
5188 | print_spaces (outfile) | |
5189 | FILE *outfile; | |
5190 | { | |
5191 | fprintf (outfile, "%*s", print_indent, ""); | |
a3f97cbb JW |
5192 | } |
5193 | ||
956d6950 | 5194 | /* Print the information associated with a given DIE, and its children. |
3f76745e | 5195 | This routine is a debugging aid only. */ |
71dfc51f | 5196 | |
a3f97cbb | 5197 | static void |
3f76745e JM |
5198 | print_die (die, outfile) |
5199 | dw_die_ref die; | |
5200 | FILE *outfile; | |
a3f97cbb | 5201 | { |
b3694847 SS |
5202 | dw_attr_ref a; |
5203 | dw_die_ref c; | |
71dfc51f | 5204 | |
3f76745e | 5205 | print_spaces (outfile); |
2d8b0f3a | 5206 | fprintf (outfile, "DIE %4lu: %s\n", |
3f76745e JM |
5207 | die->die_offset, dwarf_tag_name (die->die_tag)); |
5208 | print_spaces (outfile); | |
2d8b0f3a JL |
5209 | fprintf (outfile, " abbrev id: %lu", die->die_abbrev); |
5210 | fprintf (outfile, " offset: %lu\n", die->die_offset); | |
3f76745e JM |
5211 | |
5212 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
a3f97cbb | 5213 | { |
3f76745e JM |
5214 | print_spaces (outfile); |
5215 | fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr)); | |
5216 | ||
a96c67ec | 5217 | switch (AT_class (a)) |
3f76745e JM |
5218 | { |
5219 | case dw_val_class_addr: | |
5220 | fprintf (outfile, "address"); | |
5221 | break; | |
a20612aa RH |
5222 | case dw_val_class_offset: |
5223 | fprintf (outfile, "offset"); | |
5224 | break; | |
3f76745e JM |
5225 | case dw_val_class_loc: |
5226 | fprintf (outfile, "location descriptor"); | |
5227 | break; | |
63e46568 | 5228 | case dw_val_class_loc_list: |
a20612aa RH |
5229 | fprintf (outfile, "location list -> label:%s", |
5230 | AT_loc_list (a)->ll_symbol); | |
63e46568 | 5231 | break; |
2bee6045 JJ |
5232 | case dw_val_class_range_list: |
5233 | fprintf (outfile, "range list"); | |
5234 | break; | |
3f76745e | 5235 | case dw_val_class_const: |
a96c67ec | 5236 | fprintf (outfile, "%ld", AT_int (a)); |
3f76745e JM |
5237 | break; |
5238 | case dw_val_class_unsigned_const: | |
a96c67ec | 5239 | fprintf (outfile, "%lu", AT_unsigned (a)); |
3f76745e JM |
5240 | break; |
5241 | case dw_val_class_long_long: | |
2d8b0f3a | 5242 | fprintf (outfile, "constant (%lu,%lu)", |
556273e0 KH |
5243 | a->dw_attr_val.v.val_long_long.hi, |
5244 | a->dw_attr_val.v.val_long_long.low); | |
3f76745e JM |
5245 | break; |
5246 | case dw_val_class_float: | |
5247 | fprintf (outfile, "floating-point constant"); | |
5248 | break; | |
5249 | case dw_val_class_flag: | |
a96c67ec | 5250 | fprintf (outfile, "%u", AT_flag (a)); |
3f76745e JM |
5251 | break; |
5252 | case dw_val_class_die_ref: | |
a96c67ec | 5253 | if (AT_ref (a) != NULL) |
881c6935 | 5254 | { |
1bfb5f8f | 5255 | if (AT_ref (a)->die_symbol) |
881c6935 JM |
5256 | fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol); |
5257 | else | |
5258 | fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset); | |
5259 | } | |
3f76745e JM |
5260 | else |
5261 | fprintf (outfile, "die -> <null>"); | |
5262 | break; | |
5263 | case dw_val_class_lbl_id: | |
8b790721 | 5264 | case dw_val_class_lbl_offset: |
a96c67ec | 5265 | fprintf (outfile, "label: %s", AT_lbl (a)); |
3f76745e | 5266 | break; |
3f76745e | 5267 | case dw_val_class_str: |
a96c67ec JM |
5268 | if (AT_string (a) != NULL) |
5269 | fprintf (outfile, "\"%s\"", AT_string (a)); | |
3f76745e JM |
5270 | else |
5271 | fprintf (outfile, "<null>"); | |
5272 | break; | |
e9a25f70 JL |
5273 | default: |
5274 | break; | |
3f76745e JM |
5275 | } |
5276 | ||
5277 | fprintf (outfile, "\n"); | |
5278 | } | |
5279 | ||
5280 | if (die->die_child != NULL) | |
5281 | { | |
5282 | print_indent += 4; | |
5283 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5284 | print_die (c, outfile); | |
71dfc51f | 5285 | |
3f76745e | 5286 | print_indent -= 4; |
a3f97cbb | 5287 | } |
881c6935 JM |
5288 | if (print_indent == 0) |
5289 | fprintf (outfile, "\n"); | |
a3f97cbb JW |
5290 | } |
5291 | ||
3f76745e JM |
5292 | /* Print the contents of the source code line number correspondence table. |
5293 | This routine is a debugging aid only. */ | |
71dfc51f | 5294 | |
3f76745e JM |
5295 | static void |
5296 | print_dwarf_line_table (outfile) | |
5297 | FILE *outfile; | |
a3f97cbb | 5298 | { |
b3694847 SS |
5299 | unsigned i; |
5300 | dw_line_info_ref line_info; | |
3f76745e JM |
5301 | |
5302 | fprintf (outfile, "\n\nDWARF source line information\n"); | |
2ad9852d | 5303 | for (i = 1; i < line_info_table_in_use; i++) |
a3f97cbb | 5304 | { |
3f76745e JM |
5305 | line_info = &line_info_table[i]; |
5306 | fprintf (outfile, "%5d: ", i); | |
981975b6 | 5307 | fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]); |
2d8b0f3a | 5308 | fprintf (outfile, "%6ld", line_info->dw_line_num); |
3f76745e | 5309 | fprintf (outfile, "\n"); |
a3f97cbb | 5310 | } |
3f76745e JM |
5311 | |
5312 | fprintf (outfile, "\n\n"); | |
f37230f0 JM |
5313 | } |
5314 | ||
3f76745e JM |
5315 | /* Print the information collected for a given DIE. */ |
5316 | ||
5317 | void | |
5318 | debug_dwarf_die (die) | |
5319 | dw_die_ref die; | |
5320 | { | |
5321 | print_die (die, stderr); | |
5322 | } | |
5323 | ||
5324 | /* Print all DWARF information collected for the compilation unit. | |
5325 | This routine is a debugging aid only. */ | |
5326 | ||
5327 | void | |
5328 | debug_dwarf () | |
5329 | { | |
5330 | print_indent = 0; | |
5331 | print_die (comp_unit_die, stderr); | |
b2244e22 JW |
5332 | if (! DWARF2_ASM_LINE_DEBUG_INFO) |
5333 | print_dwarf_line_table (stderr); | |
3f76745e JM |
5334 | } |
5335 | \f | |
a96c67ec JM |
5336 | /* We build up the lists of children and attributes by pushing new ones |
5337 | onto the beginning of the list. Reverse the lists for DIE so that | |
5338 | they are in order of addition. */ | |
71dfc51f | 5339 | |
f37230f0 | 5340 | static void |
a96c67ec | 5341 | reverse_die_lists (die) |
b3694847 | 5342 | dw_die_ref die; |
f37230f0 | 5343 | { |
b3694847 SS |
5344 | dw_die_ref c, cp, cn; |
5345 | dw_attr_ref a, ap, an; | |
71dfc51f | 5346 | |
a96c67ec | 5347 | for (a = die->die_attr, ap = 0; a; a = an) |
7d9d8943 AM |
5348 | { |
5349 | an = a->dw_attr_next; | |
5350 | a->dw_attr_next = ap; | |
5351 | ap = a; | |
a3f97cbb | 5352 | } |
2ad9852d | 5353 | |
7d9d8943 | 5354 | die->die_attr = ap; |
3f76745e | 5355 | |
7d9d8943 AM |
5356 | for (c = die->die_child, cp = 0; c; c = cn) |
5357 | { | |
5358 | cn = c->die_sib; | |
5359 | c->die_sib = cp; | |
5360 | cp = c; | |
5361 | } | |
2ad9852d | 5362 | |
7d9d8943 | 5363 | die->die_child = cp; |
a3f97cbb JW |
5364 | } |
5365 | ||
2ad9852d RK |
5366 | /* reverse_die_lists only reverses the single die you pass it. Since we used to |
5367 | reverse all dies in add_sibling_attributes, which runs through all the dies, | |
5368 | it would reverse all the dies. Now, however, since we don't call | |
5369 | reverse_die_lists in add_sibling_attributes, we need a routine to | |
5370 | recursively reverse all the dies. This is that routine. */ | |
71dfc51f | 5371 | |
7d9d8943 | 5372 | static void |
881c6935 | 5373 | reverse_all_dies (die) |
b3694847 | 5374 | dw_die_ref die; |
a3f97cbb | 5375 | { |
b3694847 | 5376 | dw_die_ref c; |
71dfc51f | 5377 | |
7d9d8943 | 5378 | reverse_die_lists (die); |
3f76745e | 5379 | |
881c6935 JM |
5380 | for (c = die->die_child; c; c = c->die_sib) |
5381 | reverse_all_dies (c); | |
5382 | } | |
5383 | ||
2ad9852d RK |
5384 | /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU |
5385 | for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL | |
5386 | DIE that marks the start of the DIEs for this include file. */ | |
881c6935 JM |
5387 | |
5388 | static dw_die_ref | |
5389 | push_new_compile_unit (old_unit, bincl_die) | |
5390 | dw_die_ref old_unit, bincl_die; | |
5391 | { | |
5392 | const char *filename = get_AT_string (bincl_die, DW_AT_name); | |
5393 | dw_die_ref new_unit = gen_compile_unit_die (filename); | |
2ad9852d | 5394 | |
881c6935 JM |
5395 | new_unit->die_sib = old_unit; |
5396 | return new_unit; | |
5397 | } | |
5398 | ||
5399 | /* Close an include-file CU and reopen the enclosing one. */ | |
5400 | ||
5401 | static dw_die_ref | |
5402 | pop_compile_unit (old_unit) | |
5403 | dw_die_ref old_unit; | |
5404 | { | |
5405 | dw_die_ref new_unit = old_unit->die_sib; | |
2ad9852d | 5406 | |
881c6935 JM |
5407 | old_unit->die_sib = NULL; |
5408 | return new_unit; | |
5409 | } | |
5410 | ||
2ad9852d RK |
5411 | #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx) |
5412 | #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx) | |
881c6935 JM |
5413 | |
5414 | /* Calculate the checksum of a location expression. */ | |
5415 | ||
5416 | static inline void | |
5417 | loc_checksum (loc, ctx) | |
5418 | dw_loc_descr_ref loc; | |
5419 | struct md5_ctx *ctx; | |
5420 | { | |
2ad9852d RK |
5421 | CHECKSUM (loc->dw_loc_opc); |
5422 | CHECKSUM (loc->dw_loc_oprnd1); | |
5423 | CHECKSUM (loc->dw_loc_oprnd2); | |
881c6935 JM |
5424 | } |
5425 | ||
5426 | /* Calculate the checksum of an attribute. */ | |
5427 | ||
5428 | static void | |
5429 | attr_checksum (at, ctx) | |
5430 | dw_attr_ref at; | |
5431 | struct md5_ctx *ctx; | |
5432 | { | |
5433 | dw_loc_descr_ref loc; | |
5434 | rtx r; | |
5435 | ||
2ad9852d | 5436 | CHECKSUM (at->dw_attr); |
881c6935 JM |
5437 | |
5438 | /* We don't care about differences in file numbering. */ | |
5f632b5e JM |
5439 | if (at->dw_attr == DW_AT_decl_file |
5440 | /* Or that this was compiled with a different compiler snapshot; if | |
5441 | the output is the same, that's what matters. */ | |
5442 | || at->dw_attr == DW_AT_producer) | |
881c6935 JM |
5443 | return; |
5444 | ||
5445 | switch (AT_class (at)) | |
5446 | { | |
5447 | case dw_val_class_const: | |
2ad9852d | 5448 | CHECKSUM (at->dw_attr_val.v.val_int); |
881c6935 JM |
5449 | break; |
5450 | case dw_val_class_unsigned_const: | |
2ad9852d | 5451 | CHECKSUM (at->dw_attr_val.v.val_unsigned); |
881c6935 JM |
5452 | break; |
5453 | case dw_val_class_long_long: | |
2ad9852d | 5454 | CHECKSUM (at->dw_attr_val.v.val_long_long); |
881c6935 JM |
5455 | break; |
5456 | case dw_val_class_float: | |
2ad9852d | 5457 | CHECKSUM (at->dw_attr_val.v.val_float); |
881c6935 JM |
5458 | break; |
5459 | case dw_val_class_flag: | |
2ad9852d | 5460 | CHECKSUM (at->dw_attr_val.v.val_flag); |
881c6935 | 5461 | break; |
881c6935 | 5462 | case dw_val_class_str: |
2ad9852d | 5463 | CHECKSUM_STRING (AT_string (at)); |
881c6935 | 5464 | break; |
a20612aa | 5465 | |
881c6935 JM |
5466 | case dw_val_class_addr: |
5467 | r = AT_addr (at); | |
5468 | switch (GET_CODE (r)) | |
5469 | { | |
5470 | case SYMBOL_REF: | |
2ad9852d | 5471 | CHECKSUM_STRING (XSTR (r, 0)); |
881c6935 JM |
5472 | break; |
5473 | ||
5474 | default: | |
5475 | abort (); | |
5476 | } | |
5477 | break; | |
5478 | ||
a20612aa | 5479 | case dw_val_class_offset: |
2ad9852d | 5480 | CHECKSUM (at->dw_attr_val.v.val_offset); |
a20612aa RH |
5481 | break; |
5482 | ||
881c6935 JM |
5483 | case dw_val_class_loc: |
5484 | for (loc = AT_loc (at); loc; loc = loc->dw_loc_next) | |
5485 | loc_checksum (loc, ctx); | |
5486 | break; | |
5487 | ||
5488 | case dw_val_class_die_ref: | |
5489 | if (AT_ref (at)->die_offset) | |
2ad9852d | 5490 | CHECKSUM (AT_ref (at)->die_offset); |
881c6935 JM |
5491 | /* FIXME else use target die name or something. */ |
5492 | ||
5493 | case dw_val_class_fde_ref: | |
5494 | case dw_val_class_lbl_id: | |
5495 | case dw_val_class_lbl_offset: | |
a20612aa | 5496 | break; |
881c6935 JM |
5497 | |
5498 | default: | |
5499 | break; | |
5500 | } | |
5501 | } | |
5502 | ||
5503 | /* Calculate the checksum of a DIE. */ | |
5504 | ||
5505 | static void | |
5506 | die_checksum (die, ctx) | |
5507 | dw_die_ref die; | |
5508 | struct md5_ctx *ctx; | |
5509 | { | |
5510 | dw_die_ref c; | |
5511 | dw_attr_ref a; | |
5512 | ||
2ad9852d | 5513 | CHECKSUM (die->die_tag); |
881c6935 JM |
5514 | |
5515 | for (a = die->die_attr; a; a = a->dw_attr_next) | |
5516 | attr_checksum (a, ctx); | |
5517 | ||
5518 | for (c = die->die_child; c; c = c->die_sib) | |
5519 | die_checksum (c, ctx); | |
5520 | } | |
5521 | ||
2ad9852d RK |
5522 | #undef CHECKSUM |
5523 | #undef CHECKSUM_STRING | |
881c6935 JM |
5524 | |
5525 | /* The prefix to attach to symbols on DIEs in the current comdat debug | |
5526 | info section. */ | |
5527 | static char *comdat_symbol_id; | |
5528 | ||
5529 | /* The index of the current symbol within the current comdat CU. */ | |
5530 | static unsigned int comdat_symbol_number; | |
5531 | ||
5532 | /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its | |
5533 | children, and set comdat_symbol_id accordingly. */ | |
5534 | ||
5535 | static void | |
5536 | compute_section_prefix (unit_die) | |
5537 | dw_die_ref unit_die; | |
5538 | { | |
f11c3043 RK |
5539 | const char *base = lbasename (get_AT_string (unit_die, DW_AT_name)); |
5540 | char *name = (char *) alloca (strlen (base) + 64); | |
5541 | char *p; | |
881c6935 JM |
5542 | int i; |
5543 | unsigned char checksum[16]; | |
5544 | struct md5_ctx ctx; | |
5545 | ||
f11c3043 RK |
5546 | /* Compute the checksum of the DIE, then append part of it as hex digits to |
5547 | the name filename of the unit. */ | |
5548 | ||
881c6935 JM |
5549 | md5_init_ctx (&ctx); |
5550 | die_checksum (unit_die, &ctx); | |
5551 | md5_finish_ctx (&ctx, checksum); | |
5552 | ||
0023400b | 5553 | sprintf (name, "%s.", base); |
881c6935 JM |
5554 | clean_symbol_name (name); |
5555 | ||
2ad9852d RK |
5556 | p = name + strlen (name); |
5557 | for (i = 0; i < 4; i++) | |
5558 | { | |
5559 | sprintf (p, "%.2x", checksum[i]); | |
5560 | p += 2; | |
5561 | } | |
881c6935 JM |
5562 | |
5563 | comdat_symbol_id = unit_die->die_symbol = xstrdup (name); | |
5564 | comdat_symbol_number = 0; | |
5565 | } | |
5566 | ||
f11c3043 | 5567 | /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */ |
881c6935 JM |
5568 | |
5569 | static int | |
5570 | is_type_die (die) | |
5571 | dw_die_ref die; | |
5572 | { | |
5573 | switch (die->die_tag) | |
5574 | { | |
5575 | case DW_TAG_array_type: | |
5576 | case DW_TAG_class_type: | |
5577 | case DW_TAG_enumeration_type: | |
5578 | case DW_TAG_pointer_type: | |
5579 | case DW_TAG_reference_type: | |
5580 | case DW_TAG_string_type: | |
5581 | case DW_TAG_structure_type: | |
5582 | case DW_TAG_subroutine_type: | |
5583 | case DW_TAG_union_type: | |
5584 | case DW_TAG_ptr_to_member_type: | |
5585 | case DW_TAG_set_type: | |
5586 | case DW_TAG_subrange_type: | |
5587 | case DW_TAG_base_type: | |
5588 | case DW_TAG_const_type: | |
5589 | case DW_TAG_file_type: | |
5590 | case DW_TAG_packed_type: | |
5591 | case DW_TAG_volatile_type: | |
5592 | return 1; | |
5593 | default: | |
5594 | return 0; | |
5595 | } | |
5596 | } | |
5597 | ||
5598 | /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU. | |
5599 | Basically, we want to choose the bits that are likely to be shared between | |
5600 | compilations (types) and leave out the bits that are specific to individual | |
5601 | compilations (functions). */ | |
5602 | ||
5603 | static int | |
5604 | is_comdat_die (c) | |
5605 | dw_die_ref c; | |
5606 | { | |
2ad9852d RK |
5607 | /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as |
5608 | we do for stabs. The advantage is a greater likelihood of sharing between | |
5609 | objects that don't include headers in the same order (and therefore would | |
5610 | put the base types in a different comdat). jason 8/28/00 */ | |
5611 | ||
881c6935 JM |
5612 | if (c->die_tag == DW_TAG_base_type) |
5613 | return 0; | |
5614 | ||
5615 | if (c->die_tag == DW_TAG_pointer_type | |
5616 | || c->die_tag == DW_TAG_reference_type | |
5617 | || c->die_tag == DW_TAG_const_type | |
5618 | || c->die_tag == DW_TAG_volatile_type) | |
5619 | { | |
5620 | dw_die_ref t = get_AT_ref (c, DW_AT_type); | |
2ad9852d | 5621 | |
881c6935 JM |
5622 | return t ? is_comdat_die (t) : 0; |
5623 | } | |
881c6935 JM |
5624 | |
5625 | return is_type_die (c); | |
5626 | } | |
5627 | ||
5628 | /* Returns 1 iff C is the sort of DIE that might be referred to from another | |
5629 | compilation unit. */ | |
5630 | ||
5631 | static int | |
5632 | is_symbol_die (c) | |
5633 | dw_die_ref c; | |
5634 | { | |
2ad9852d | 5635 | return (is_type_die (c) |
c26fbbca | 5636 | || (get_AT (c, DW_AT_declaration) |
2ad9852d | 5637 | && !get_AT (c, DW_AT_specification))); |
881c6935 JM |
5638 | } |
5639 | ||
5640 | static char * | |
63e46568 | 5641 | gen_internal_sym (prefix) |
173bf5be | 5642 | const char *prefix; |
881c6935 JM |
5643 | { |
5644 | char buf[256]; | |
5645 | static int label_num; | |
2ad9852d | 5646 | |
63e46568 | 5647 | ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++); |
881c6935 JM |
5648 | return xstrdup (buf); |
5649 | } | |
5650 | ||
5651 | /* Assign symbols to all worthy DIEs under DIE. */ | |
5652 | ||
5653 | static void | |
5654 | assign_symbol_names (die) | |
b3694847 | 5655 | dw_die_ref die; |
881c6935 | 5656 | { |
b3694847 | 5657 | dw_die_ref c; |
881c6935 JM |
5658 | |
5659 | if (is_symbol_die (die)) | |
5660 | { | |
5661 | if (comdat_symbol_id) | |
5662 | { | |
5663 | char *p = alloca (strlen (comdat_symbol_id) + 64); | |
2ad9852d | 5664 | |
881c6935 JM |
5665 | sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX, |
5666 | comdat_symbol_id, comdat_symbol_number++); | |
5667 | die->die_symbol = xstrdup (p); | |
5668 | } | |
5669 | else | |
63e46568 | 5670 | die->die_symbol = gen_internal_sym ("LDIE"); |
881c6935 JM |
5671 | } |
5672 | ||
5673 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5674 | assign_symbol_names (c); | |
5675 | } | |
5676 | ||
5677 | /* Traverse the DIE (which is always comp_unit_die), and set up | |
5678 | additional compilation units for each of the include files we see | |
5679 | bracketed by BINCL/EINCL. */ | |
5680 | ||
5681 | static void | |
5682 | break_out_includes (die) | |
b3694847 | 5683 | dw_die_ref die; |
881c6935 JM |
5684 | { |
5685 | dw_die_ref *ptr; | |
b3694847 | 5686 | dw_die_ref unit = NULL; |
881c6935 JM |
5687 | limbo_die_node *node; |
5688 | ||
c26fbbca | 5689 | for (ptr = &(die->die_child); *ptr;) |
881c6935 | 5690 | { |
b3694847 | 5691 | dw_die_ref c = *ptr; |
881c6935 | 5692 | |
2ad9852d | 5693 | if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL |
881c6935 JM |
5694 | || (unit && is_comdat_die (c))) |
5695 | { | |
5696 | /* This DIE is for a secondary CU; remove it from the main one. */ | |
5697 | *ptr = c->die_sib; | |
5698 | ||
5699 | if (c->die_tag == DW_TAG_GNU_BINCL) | |
5700 | { | |
5701 | unit = push_new_compile_unit (unit, c); | |
5702 | free_die (c); | |
5703 | } | |
5704 | else if (c->die_tag == DW_TAG_GNU_EINCL) | |
5705 | { | |
5706 | unit = pop_compile_unit (unit); | |
5707 | free_die (c); | |
5708 | } | |
5709 | else | |
5710 | add_child_die (unit, c); | |
5711 | } | |
5712 | else | |
5713 | { | |
5714 | /* Leave this DIE in the main CU. */ | |
5715 | ptr = &(c->die_sib); | |
5716 | continue; | |
5717 | } | |
5718 | } | |
5719 | ||
5720 | #if 0 | |
5721 | /* We can only use this in debugging, since the frontend doesn't check | |
0b34cf1e | 5722 | to make sure that we leave every include file we enter. */ |
881c6935 JM |
5723 | if (unit != NULL) |
5724 | abort (); | |
5725 | #endif | |
5726 | ||
5727 | assign_symbol_names (die); | |
5728 | for (node = limbo_die_list; node; node = node->next) | |
5729 | { | |
5730 | compute_section_prefix (node->die); | |
5731 | assign_symbol_names (node->die); | |
5732 | } | |
5733 | } | |
5734 | ||
5735 | /* Traverse the DIE and add a sibling attribute if it may have the | |
5736 | effect of speeding up access to siblings. To save some space, | |
5737 | avoid generating sibling attributes for DIE's without children. */ | |
5738 | ||
5739 | static void | |
5740 | add_sibling_attributes (die) | |
b3694847 | 5741 | dw_die_ref die; |
881c6935 | 5742 | { |
b3694847 | 5743 | dw_die_ref c; |
881c6935 JM |
5744 | |
5745 | if (die->die_tag != DW_TAG_compile_unit | |
5746 | && die->die_sib && die->die_child != NULL) | |
7d9d8943 AM |
5747 | /* Add the sibling link to the front of the attribute list. */ |
5748 | add_AT_die_ref (die, DW_AT_sibling, die->die_sib); | |
5749 | ||
5750 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5751 | add_sibling_attributes (c); | |
5752 | } | |
5753 | ||
2ad9852d RK |
5754 | /* Output all location lists for the DIE and its children. */ |
5755 | ||
63e46568 DB |
5756 | static void |
5757 | output_location_lists (die) | |
b3694847 | 5758 | dw_die_ref die; |
63e46568 DB |
5759 | { |
5760 | dw_die_ref c; | |
5761 | dw_attr_ref d_attr; | |
2ad9852d | 5762 | |
63e46568 | 5763 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) |
2ad9852d RK |
5764 | if (AT_class (d_attr) == dw_val_class_loc_list) |
5765 | output_loc_list (AT_loc_list (d_attr)); | |
5766 | ||
63e46568 DB |
5767 | for (c = die->die_child; c != NULL; c = c->die_sib) |
5768 | output_location_lists (c); | |
5769 | ||
5770 | } | |
c26fbbca | 5771 | |
2ad9852d RK |
5772 | /* The format of each DIE (and its attribute value pairs) is encoded in an |
5773 | abbreviation table. This routine builds the abbreviation table and assigns | |
5774 | a unique abbreviation id for each abbreviation entry. The children of each | |
5775 | die are visited recursively. */ | |
7d9d8943 AM |
5776 | |
5777 | static void | |
5778 | build_abbrev_table (die) | |
b3694847 | 5779 | dw_die_ref die; |
7d9d8943 | 5780 | { |
b3694847 SS |
5781 | unsigned long abbrev_id; |
5782 | unsigned int n_alloc; | |
5783 | dw_die_ref c; | |
5784 | dw_attr_ref d_attr, a_attr; | |
881c6935 JM |
5785 | |
5786 | /* Scan the DIE references, and mark as external any that refer to | |
1bfb5f8f | 5787 | DIEs from other CUs (i.e. those which are not marked). */ |
881c6935 | 5788 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) |
2ad9852d RK |
5789 | if (AT_class (d_attr) == dw_val_class_die_ref |
5790 | && AT_ref (d_attr)->die_mark == 0) | |
5791 | { | |
5792 | if (AT_ref (d_attr)->die_symbol == 0) | |
5793 | abort (); | |
5794 | ||
5795 | set_AT_ref_external (d_attr, 1); | |
5796 | } | |
881c6935 | 5797 | |
7d9d8943 AM |
5798 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
5799 | { | |
b3694847 | 5800 | dw_die_ref abbrev = abbrev_die_table[abbrev_id]; |
7d9d8943 AM |
5801 | |
5802 | if (abbrev->die_tag == die->die_tag) | |
5803 | { | |
5804 | if ((abbrev->die_child != NULL) == (die->die_child != NULL)) | |
5805 | { | |
5806 | a_attr = abbrev->die_attr; | |
5807 | d_attr = die->die_attr; | |
5808 | ||
5809 | while (a_attr != NULL && d_attr != NULL) | |
5810 | { | |
5811 | if ((a_attr->dw_attr != d_attr->dw_attr) | |
5812 | || (value_format (a_attr) != value_format (d_attr))) | |
5813 | break; | |
5814 | ||
5815 | a_attr = a_attr->dw_attr_next; | |
5816 | d_attr = d_attr->dw_attr_next; | |
5817 | } | |
5818 | ||
5819 | if (a_attr == NULL && d_attr == NULL) | |
5820 | break; | |
5821 | } | |
5822 | } | |
5823 | } | |
5824 | ||
5825 | if (abbrev_id >= abbrev_die_table_in_use) | |
5826 | { | |
5827 | if (abbrev_die_table_in_use >= abbrev_die_table_allocated) | |
5828 | { | |
5829 | n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT; | |
556273e0 | 5830 | abbrev_die_table |
7d9d8943 AM |
5831 | = (dw_die_ref *) xrealloc (abbrev_die_table, |
5832 | sizeof (dw_die_ref) * n_alloc); | |
5833 | ||
961192e1 | 5834 | memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0, |
7d9d8943 AM |
5835 | (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref)); |
5836 | abbrev_die_table_allocated = n_alloc; | |
5837 | } | |
5838 | ||
5839 | ++abbrev_die_table_in_use; | |
5840 | abbrev_die_table[abbrev_id] = die; | |
5841 | } | |
5842 | ||
5843 | die->die_abbrev = abbrev_id; | |
5844 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5845 | build_abbrev_table (c); | |
5846 | } | |
5847 | \f | |
3f76745e JM |
5848 | /* Return the power-of-two number of bytes necessary to represent VALUE. */ |
5849 | ||
5850 | static int | |
5851 | constant_size (value) | |
5852 | long unsigned value; | |
5853 | { | |
5854 | int log; | |
5855 | ||
5856 | if (value == 0) | |
5857 | log = 0; | |
a3f97cbb | 5858 | else |
3f76745e | 5859 | log = floor_log2 (value); |
71dfc51f | 5860 | |
3f76745e JM |
5861 | log = log / 8; |
5862 | log = 1 << (floor_log2 (log) + 1); | |
5863 | ||
5864 | return log; | |
a3f97cbb JW |
5865 | } |
5866 | ||
2ad9852d | 5867 | /* Return the size of a DIE as it is represented in the |
3f76745e | 5868 | .debug_info section. */ |
71dfc51f | 5869 | |
3f76745e JM |
5870 | static unsigned long |
5871 | size_of_die (die) | |
b3694847 | 5872 | dw_die_ref die; |
a3f97cbb | 5873 | { |
b3694847 SS |
5874 | unsigned long size = 0; |
5875 | dw_attr_ref a; | |
71dfc51f | 5876 | |
3f76745e | 5877 | size += size_of_uleb128 (die->die_abbrev); |
a3f97cbb JW |
5878 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
5879 | { | |
a96c67ec | 5880 | switch (AT_class (a)) |
a3f97cbb JW |
5881 | { |
5882 | case dw_val_class_addr: | |
a1a4189d | 5883 | size += DWARF2_ADDR_SIZE; |
a3f97cbb | 5884 | break; |
a20612aa RH |
5885 | case dw_val_class_offset: |
5886 | size += DWARF_OFFSET_SIZE; | |
5887 | break; | |
a3f97cbb | 5888 | case dw_val_class_loc: |
3f76745e | 5889 | { |
b3694847 | 5890 | unsigned long lsize = size_of_locs (AT_loc (a)); |
71dfc51f | 5891 | |
3f76745e JM |
5892 | /* Block length. */ |
5893 | size += constant_size (lsize); | |
5894 | size += lsize; | |
5895 | } | |
a3f97cbb | 5896 | break; |
63e46568 DB |
5897 | case dw_val_class_loc_list: |
5898 | size += DWARF_OFFSET_SIZE; | |
5899 | break; | |
2bee6045 JJ |
5900 | case dw_val_class_range_list: |
5901 | size += DWARF_OFFSET_SIZE; | |
5902 | break; | |
a3f97cbb | 5903 | case dw_val_class_const: |
25dd13ec | 5904 | size += size_of_sleb128 (AT_int (a)); |
a3f97cbb JW |
5905 | break; |
5906 | case dw_val_class_unsigned_const: | |
a96c67ec | 5907 | size += constant_size (AT_unsigned (a)); |
a3f97cbb | 5908 | break; |
469ac993 | 5909 | case dw_val_class_long_long: |
2e4b9b8c | 5910 | size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */ |
469ac993 JM |
5911 | break; |
5912 | case dw_val_class_float: | |
3f76745e | 5913 | size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */ |
a3f97cbb JW |
5914 | break; |
5915 | case dw_val_class_flag: | |
3f76745e | 5916 | size += 1; |
a3f97cbb JW |
5917 | break; |
5918 | case dw_val_class_die_ref: | |
3f76745e | 5919 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
5920 | break; |
5921 | case dw_val_class_fde_ref: | |
3f76745e | 5922 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
5923 | break; |
5924 | case dw_val_class_lbl_id: | |
a1a4189d | 5925 | size += DWARF2_ADDR_SIZE; |
3f76745e | 5926 | break; |
8b790721 | 5927 | case dw_val_class_lbl_offset: |
3f76745e JM |
5928 | size += DWARF_OFFSET_SIZE; |
5929 | break; | |
5930 | case dw_val_class_str: | |
9eb4015a JJ |
5931 | if (AT_string_form (a) == DW_FORM_strp) |
5932 | size += DWARF_OFFSET_SIZE; | |
5933 | else | |
5934 | size += HT_LEN (&a->dw_attr_val.v.val_str->id) + 1; | |
3f76745e JM |
5935 | break; |
5936 | default: | |
5937 | abort (); | |
5938 | } | |
a3f97cbb | 5939 | } |
3f76745e JM |
5940 | |
5941 | return size; | |
a3f97cbb JW |
5942 | } |
5943 | ||
2ad9852d RK |
5944 | /* Size the debugging information associated with a given DIE. Visits the |
5945 | DIE's children recursively. Updates the global variable next_die_offset, on | |
5946 | each time through. Uses the current value of next_die_offset to update the | |
5947 | die_offset field in each DIE. */ | |
71dfc51f | 5948 | |
a3f97cbb | 5949 | static void |
3f76745e JM |
5950 | calc_die_sizes (die) |
5951 | dw_die_ref die; | |
a3f97cbb | 5952 | { |
b3694847 | 5953 | dw_die_ref c; |
2ad9852d | 5954 | |
3f76745e JM |
5955 | die->die_offset = next_die_offset; |
5956 | next_die_offset += size_of_die (die); | |
71dfc51f | 5957 | |
3f76745e JM |
5958 | for (c = die->die_child; c != NULL; c = c->die_sib) |
5959 | calc_die_sizes (c); | |
71dfc51f | 5960 | |
3f76745e JM |
5961 | if (die->die_child != NULL) |
5962 | /* Count the null byte used to terminate sibling lists. */ | |
5963 | next_die_offset += 1; | |
a3f97cbb JW |
5964 | } |
5965 | ||
1bfb5f8f | 5966 | /* Set the marks for a die and its children. We do this so |
881c6935 | 5967 | that we know whether or not a reference needs to use FORM_ref_addr; only |
1bfb5f8f JM |
5968 | DIEs in the same CU will be marked. We used to clear out the offset |
5969 | and use that as the flag, but ran into ordering problems. */ | |
881c6935 JM |
5970 | |
5971 | static void | |
1bfb5f8f | 5972 | mark_dies (die) |
881c6935 JM |
5973 | dw_die_ref die; |
5974 | { | |
b3694847 | 5975 | dw_die_ref c; |
2ad9852d | 5976 | |
1bfb5f8f JM |
5977 | die->die_mark = 1; |
5978 | for (c = die->die_child; c; c = c->die_sib) | |
5979 | mark_dies (c); | |
5980 | } | |
5981 | ||
5982 | /* Clear the marks for a die and its children. */ | |
5983 | ||
5984 | static void | |
5985 | unmark_dies (die) | |
5986 | dw_die_ref die; | |
5987 | { | |
b3694847 | 5988 | dw_die_ref c; |
2ad9852d | 5989 | |
1bfb5f8f | 5990 | die->die_mark = 0; |
881c6935 | 5991 | for (c = die->die_child; c; c = c->die_sib) |
1bfb5f8f | 5992 | unmark_dies (c); |
881c6935 JM |
5993 | } |
5994 | ||
3f76745e JM |
5995 | /* Return the size of the .debug_pubnames table generated for the |
5996 | compilation unit. */ | |
a94dbf2c | 5997 | |
3f76745e JM |
5998 | static unsigned long |
5999 | size_of_pubnames () | |
a94dbf2c | 6000 | { |
b3694847 SS |
6001 | unsigned long size; |
6002 | unsigned i; | |
469ac993 | 6003 | |
3f76745e | 6004 | size = DWARF_PUBNAMES_HEADER_SIZE; |
2ad9852d | 6005 | for (i = 0; i < pubname_table_in_use; i++) |
a94dbf2c | 6006 | { |
b3694847 | 6007 | pubname_ref p = &pubname_table[i]; |
9eb4015a | 6008 | size += DWARF_OFFSET_SIZE + strlen (p->name) + 1; |
a94dbf2c JM |
6009 | } |
6010 | ||
3f76745e JM |
6011 | size += DWARF_OFFSET_SIZE; |
6012 | return size; | |
a94dbf2c JM |
6013 | } |
6014 | ||
956d6950 | 6015 | /* Return the size of the information in the .debug_aranges section. */ |
469ac993 | 6016 | |
3f76745e JM |
6017 | static unsigned long |
6018 | size_of_aranges () | |
469ac993 | 6019 | { |
b3694847 | 6020 | unsigned long size; |
469ac993 | 6021 | |
3f76745e | 6022 | size = DWARF_ARANGES_HEADER_SIZE; |
469ac993 | 6023 | |
3f76745e | 6024 | /* Count the address/length pair for this compilation unit. */ |
a1a4189d JB |
6025 | size += 2 * DWARF2_ADDR_SIZE; |
6026 | size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use; | |
469ac993 | 6027 | |
3f76745e | 6028 | /* Count the two zero words used to terminated the address range table. */ |
a1a4189d | 6029 | size += 2 * DWARF2_ADDR_SIZE; |
3f76745e JM |
6030 | return size; |
6031 | } | |
6032 | \f | |
6033 | /* Select the encoding of an attribute value. */ | |
6034 | ||
6035 | static enum dwarf_form | |
a96c67ec JM |
6036 | value_format (a) |
6037 | dw_attr_ref a; | |
3f76745e | 6038 | { |
a96c67ec | 6039 | switch (a->dw_attr_val.val_class) |
469ac993 | 6040 | { |
3f76745e JM |
6041 | case dw_val_class_addr: |
6042 | return DW_FORM_addr; | |
2bee6045 | 6043 | case dw_val_class_range_list: |
a20612aa RH |
6044 | case dw_val_class_offset: |
6045 | if (DWARF_OFFSET_SIZE == 4) | |
6046 | return DW_FORM_data4; | |
6047 | if (DWARF_OFFSET_SIZE == 8) | |
6048 | return DW_FORM_data8; | |
6049 | abort (); | |
63e46568 | 6050 | case dw_val_class_loc_list: |
9d2f2c45 RH |
6051 | /* FIXME: Could be DW_FORM_data8, with a > 32 bit size |
6052 | .debug_loc section */ | |
6053 | return DW_FORM_data4; | |
3f76745e | 6054 | case dw_val_class_loc: |
a96c67ec | 6055 | switch (constant_size (size_of_locs (AT_loc (a)))) |
469ac993 | 6056 | { |
3f76745e JM |
6057 | case 1: |
6058 | return DW_FORM_block1; | |
6059 | case 2: | |
6060 | return DW_FORM_block2; | |
469ac993 JM |
6061 | default: |
6062 | abort (); | |
6063 | } | |
3f76745e | 6064 | case dw_val_class_const: |
25dd13ec | 6065 | return DW_FORM_sdata; |
3f76745e | 6066 | case dw_val_class_unsigned_const: |
a96c67ec | 6067 | switch (constant_size (AT_unsigned (a))) |
3f76745e JM |
6068 | { |
6069 | case 1: | |
6070 | return DW_FORM_data1; | |
6071 | case 2: | |
6072 | return DW_FORM_data2; | |
6073 | case 4: | |
6074 | return DW_FORM_data4; | |
6075 | case 8: | |
6076 | return DW_FORM_data8; | |
6077 | default: | |
6078 | abort (); | |
6079 | } | |
6080 | case dw_val_class_long_long: | |
6081 | return DW_FORM_block1; | |
6082 | case dw_val_class_float: | |
6083 | return DW_FORM_block1; | |
6084 | case dw_val_class_flag: | |
6085 | return DW_FORM_flag; | |
6086 | case dw_val_class_die_ref: | |
881c6935 JM |
6087 | if (AT_ref_external (a)) |
6088 | return DW_FORM_ref_addr; | |
6089 | else | |
6090 | return DW_FORM_ref; | |
3f76745e JM |
6091 | case dw_val_class_fde_ref: |
6092 | return DW_FORM_data; | |
6093 | case dw_val_class_lbl_id: | |
6094 | return DW_FORM_addr; | |
8b790721 | 6095 | case dw_val_class_lbl_offset: |
3f76745e JM |
6096 | return DW_FORM_data; |
6097 | case dw_val_class_str: | |
9eb4015a | 6098 | return AT_string_form (a); |
a20612aa | 6099 | |
469ac993 JM |
6100 | default: |
6101 | abort (); | |
6102 | } | |
a94dbf2c JM |
6103 | } |
6104 | ||
3f76745e | 6105 | /* Output the encoding of an attribute value. */ |
469ac993 | 6106 | |
3f76745e | 6107 | static void |
a96c67ec JM |
6108 | output_value_format (a) |
6109 | dw_attr_ref a; | |
a94dbf2c | 6110 | { |
a96c67ec | 6111 | enum dwarf_form form = value_format (a); |
2ad9852d | 6112 | |
2e4b9b8c | 6113 | dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form)); |
3f76745e | 6114 | } |
469ac993 | 6115 | |
3f76745e JM |
6116 | /* Output the .debug_abbrev section which defines the DIE abbreviation |
6117 | table. */ | |
469ac993 | 6118 | |
3f76745e JM |
6119 | static void |
6120 | output_abbrev_section () | |
6121 | { | |
6122 | unsigned long abbrev_id; | |
71dfc51f | 6123 | |
3f76745e | 6124 | dw_attr_ref a_attr; |
2ad9852d | 6125 | |
3f76745e JM |
6126 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
6127 | { | |
b3694847 | 6128 | dw_die_ref abbrev = abbrev_die_table[abbrev_id]; |
71dfc51f | 6129 | |
2e4b9b8c | 6130 | dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)"); |
2e4b9b8c RH |
6131 | dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)", |
6132 | dwarf_tag_name (abbrev->die_tag)); | |
71dfc51f | 6133 | |
2e4b9b8c RH |
6134 | if (abbrev->die_child != NULL) |
6135 | dw2_asm_output_data (1, DW_children_yes, "DW_children_yes"); | |
6136 | else | |
6137 | dw2_asm_output_data (1, DW_children_no, "DW_children_no"); | |
3f76745e JM |
6138 | |
6139 | for (a_attr = abbrev->die_attr; a_attr != NULL; | |
6140 | a_attr = a_attr->dw_attr_next) | |
6141 | { | |
2e4b9b8c RH |
6142 | dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)", |
6143 | dwarf_attr_name (a_attr->dw_attr)); | |
a96c67ec | 6144 | output_value_format (a_attr); |
469ac993 | 6145 | } |
469ac993 | 6146 | |
2e4b9b8c RH |
6147 | dw2_asm_output_data (1, 0, NULL); |
6148 | dw2_asm_output_data (1, 0, NULL); | |
469ac993 | 6149 | } |
81f374eb HPN |
6150 | |
6151 | /* Terminate the table. */ | |
2e4b9b8c | 6152 | dw2_asm_output_data (1, 0, NULL); |
a94dbf2c JM |
6153 | } |
6154 | ||
881c6935 JM |
6155 | /* Output a symbol we can use to refer to this DIE from another CU. */ |
6156 | ||
6157 | static inline void | |
6158 | output_die_symbol (die) | |
b3694847 | 6159 | dw_die_ref die; |
881c6935 JM |
6160 | { |
6161 | char *sym = die->die_symbol; | |
6162 | ||
6163 | if (sym == 0) | |
6164 | return; | |
6165 | ||
6166 | if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0) | |
6167 | /* We make these global, not weak; if the target doesn't support | |
6168 | .linkonce, it doesn't support combining the sections, so debugging | |
6169 | will break. */ | |
6170 | ASM_GLOBALIZE_LABEL (asm_out_file, sym); | |
2ad9852d | 6171 | |
881c6935 JM |
6172 | ASM_OUTPUT_LABEL (asm_out_file, sym); |
6173 | } | |
6174 | ||
84a5b4f8 | 6175 | /* Return a new location list, given the begin and end range, and the |
2ad9852d RK |
6176 | expression. gensym tells us whether to generate a new internal symbol for |
6177 | this location list node, which is done for the head of the list only. */ | |
6178 | ||
84a5b4f8 DB |
6179 | static inline dw_loc_list_ref |
6180 | new_loc_list (expr, begin, end, section, gensym) | |
b3694847 SS |
6181 | dw_loc_descr_ref expr; |
6182 | const char *begin; | |
6183 | const char *end; | |
6184 | const char *section; | |
6185 | unsigned gensym; | |
84a5b4f8 | 6186 | { |
b3694847 | 6187 | dw_loc_list_ref retlist |
84a5b4f8 | 6188 | = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node)); |
2ad9852d | 6189 | |
84a5b4f8 DB |
6190 | retlist->begin = begin; |
6191 | retlist->end = end; | |
6192 | retlist->expr = expr; | |
6193 | retlist->section = section; | |
c26fbbca | 6194 | if (gensym) |
84a5b4f8 | 6195 | retlist->ll_symbol = gen_internal_sym ("LLST"); |
2ad9852d | 6196 | |
84a5b4f8 DB |
6197 | return retlist; |
6198 | } | |
6199 | ||
6200 | /* Add a location description expression to a location list */ | |
2ad9852d | 6201 | |
84a5b4f8 DB |
6202 | static inline void |
6203 | add_loc_descr_to_loc_list (list_head, descr, begin, end, section) | |
b3694847 SS |
6204 | dw_loc_list_ref *list_head; |
6205 | dw_loc_descr_ref descr; | |
6206 | const char *begin; | |
6207 | const char *end; | |
6208 | const char *section; | |
84a5b4f8 | 6209 | { |
b3694847 | 6210 | dw_loc_list_ref *d; |
c26fbbca | 6211 | |
30f7a378 | 6212 | /* Find the end of the chain. */ |
84a5b4f8 DB |
6213 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) |
6214 | ; | |
2ad9852d | 6215 | |
84a5b4f8 DB |
6216 | /* Add a new location list node to the list */ |
6217 | *d = new_loc_list (descr, begin, end, section, 0); | |
6218 | } | |
6219 | ||
63e46568 | 6220 | /* Output the location list given to us */ |
2ad9852d | 6221 | |
63e46568 DB |
6222 | static void |
6223 | output_loc_list (list_head) | |
b3694847 | 6224 | dw_loc_list_ref list_head; |
63e46568 | 6225 | { |
2ad9852d RK |
6226 | dw_loc_list_ref curr = list_head; |
6227 | ||
63e46568 | 6228 | ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol); |
a20612aa RH |
6229 | |
6230 | /* ??? This shouldn't be needed now that we've forced the | |
6231 | compilation unit base address to zero when there is code | |
6232 | in more than one section. */ | |
63e46568 DB |
6233 | if (strcmp (curr->section, ".text") == 0) |
6234 | { | |
aafdcfcd | 6235 | /* dw2_asm_output_data will mask off any extra bits in the ~0. */ |
c4f2c499 | 6236 | dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0, |
aafdcfcd NS |
6237 | "Location list base address specifier fake entry"); |
6238 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section, | |
6239 | "Location list base address specifier base"); | |
63e46568 | 6240 | } |
2ad9852d | 6241 | |
c26fbbca | 6242 | for (curr = list_head; curr != NULL; curr = curr->dw_loc_next) |
63e46568 | 6243 | { |
2bee6045 | 6244 | unsigned long size; |
2ad9852d | 6245 | |
aafdcfcd NS |
6246 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section, |
6247 | "Location list begin address (%s)", | |
6248 | list_head->ll_symbol); | |
6249 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section, | |
6250 | "Location list end address (%s)", | |
6251 | list_head->ll_symbol); | |
63e46568 | 6252 | size = size_of_locs (curr->expr); |
c26fbbca | 6253 | |
63e46568 | 6254 | /* Output the block length for this list of location operations. */ |
2bee6045 JJ |
6255 | if (size > 0xffff) |
6256 | abort (); | |
6257 | dw2_asm_output_data (2, size, "%s", "Location expression size"); | |
6258 | ||
63e46568 DB |
6259 | output_loc_sequence (curr->expr); |
6260 | } | |
2ad9852d | 6261 | |
aafdcfcd NS |
6262 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, |
6263 | "Location list terminator begin (%s)", | |
6264 | list_head->ll_symbol); | |
6265 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, | |
6266 | "Location list terminator end (%s)", | |
6267 | list_head->ll_symbol); | |
63e46568 | 6268 | } |
9eb4015a | 6269 | |
3f76745e JM |
6270 | /* Output the DIE and its attributes. Called recursively to generate |
6271 | the definitions of each child DIE. */ | |
71dfc51f | 6272 | |
a3f97cbb | 6273 | static void |
3f76745e | 6274 | output_die (die) |
b3694847 | 6275 | dw_die_ref die; |
a3f97cbb | 6276 | { |
b3694847 SS |
6277 | dw_attr_ref a; |
6278 | dw_die_ref c; | |
6279 | unsigned long size; | |
a94dbf2c | 6280 | |
881c6935 JM |
6281 | /* If someone in another CU might refer to us, set up a symbol for |
6282 | them to point to. */ | |
6283 | if (die->die_symbol) | |
6284 | output_die_symbol (die); | |
6285 | ||
2e4b9b8c RH |
6286 | dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)", |
6287 | die->die_offset, dwarf_tag_name (die->die_tag)); | |
a94dbf2c | 6288 | |
3f76745e | 6289 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
a3f97cbb | 6290 | { |
2e4b9b8c RH |
6291 | const char *name = dwarf_attr_name (a->dw_attr); |
6292 | ||
a96c67ec | 6293 | switch (AT_class (a)) |
3f76745e JM |
6294 | { |
6295 | case dw_val_class_addr: | |
2e4b9b8c | 6296 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name); |
3f76745e | 6297 | break; |
a3f97cbb | 6298 | |
a20612aa RH |
6299 | case dw_val_class_offset: |
6300 | dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset, | |
6301 | "%s", name); | |
6302 | break; | |
6303 | ||
2bee6045 JJ |
6304 | case dw_val_class_range_list: |
6305 | { | |
6306 | char *p = strchr (ranges_section_label, '\0'); | |
6307 | ||
6308 | sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset); | |
6309 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label, | |
6310 | "%s", name); | |
6311 | *p = '\0'; | |
6312 | } | |
6313 | break; | |
6314 | ||
3f76745e | 6315 | case dw_val_class_loc: |
a96c67ec | 6316 | size = size_of_locs (AT_loc (a)); |
71dfc51f | 6317 | |
3f76745e | 6318 | /* Output the block length for this list of location operations. */ |
2e4b9b8c | 6319 | dw2_asm_output_data (constant_size (size), size, "%s", name); |
71dfc51f | 6320 | |
7d9d8943 | 6321 | output_loc_sequence (AT_loc (a)); |
a3f97cbb | 6322 | break; |
3f76745e JM |
6323 | |
6324 | case dw_val_class_const: | |
25dd13ec JW |
6325 | /* ??? It would be slightly more efficient to use a scheme like is |
6326 | used for unsigned constants below, but gdb 4.x does not sign | |
6327 | extend. Gdb 5.x does sign extend. */ | |
2e4b9b8c | 6328 | dw2_asm_output_data_sleb128 (AT_int (a), "%s", name); |
a3f97cbb | 6329 | break; |
3f76745e JM |
6330 | |
6331 | case dw_val_class_unsigned_const: | |
2e4b9b8c RH |
6332 | dw2_asm_output_data (constant_size (AT_unsigned (a)), |
6333 | AT_unsigned (a), "%s", name); | |
a3f97cbb | 6334 | break; |
3f76745e JM |
6335 | |
6336 | case dw_val_class_long_long: | |
2e4b9b8c RH |
6337 | { |
6338 | unsigned HOST_WIDE_INT first, second; | |
3f76745e | 6339 | |
2ad9852d RK |
6340 | dw2_asm_output_data (1, |
6341 | 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, | |
c26fbbca | 6342 | "%s", name); |
556273e0 | 6343 | |
2e4b9b8c RH |
6344 | if (WORDS_BIG_ENDIAN) |
6345 | { | |
6346 | first = a->dw_attr_val.v.val_long_long.hi; | |
6347 | second = a->dw_attr_val.v.val_long_long.low; | |
6348 | } | |
6349 | else | |
6350 | { | |
6351 | first = a->dw_attr_val.v.val_long_long.low; | |
6352 | second = a->dw_attr_val.v.val_long_long.hi; | |
6353 | } | |
2ad9852d RK |
6354 | |
6355 | dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, | |
2e4b9b8c | 6356 | first, "long long constant"); |
2ad9852d | 6357 | dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, |
2e4b9b8c RH |
6358 | second, NULL); |
6359 | } | |
a3f97cbb | 6360 | break; |
3f76745e JM |
6361 | |
6362 | case dw_val_class_float: | |
c84e2712 | 6363 | { |
b3694847 | 6364 | unsigned int i; |
c84e2712 | 6365 | |
2e4b9b8c | 6366 | dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4, |
c26fbbca | 6367 | "%s", name); |
c84e2712 | 6368 | |
2ad9852d | 6369 | for (i = 0; i < a->dw_attr_val.v.val_float.length; i++) |
2e4b9b8c RH |
6370 | dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i], |
6371 | "fp constant word %u", i); | |
556273e0 | 6372 | break; |
c84e2712 | 6373 | } |
3f76745e JM |
6374 | |
6375 | case dw_val_class_flag: | |
2e4b9b8c | 6376 | dw2_asm_output_data (1, AT_flag (a), "%s", name); |
a3f97cbb | 6377 | break; |
a20612aa | 6378 | |
c26fbbca | 6379 | case dw_val_class_loc_list: |
63e46568 DB |
6380 | { |
6381 | char *sym = AT_loc_list (a)->ll_symbol; | |
2ad9852d | 6382 | |
63e46568 | 6383 | if (sym == 0) |
173bf5be | 6384 | abort (); |
a20612aa RH |
6385 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, |
6386 | loc_section_label, "%s", name); | |
63e46568 DB |
6387 | } |
6388 | break; | |
a20612aa | 6389 | |
3f76745e | 6390 | case dw_val_class_die_ref: |
881c6935 | 6391 | if (AT_ref_external (a)) |
2e4b9b8c RH |
6392 | { |
6393 | char *sym = AT_ref (a)->die_symbol; | |
2ad9852d | 6394 | |
2e4b9b8c RH |
6395 | if (sym == 0) |
6396 | abort (); | |
6397 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name); | |
6398 | } | |
3f4907a6 JM |
6399 | else if (AT_ref (a)->die_offset == 0) |
6400 | abort (); | |
881c6935 | 6401 | else |
2e4b9b8c RH |
6402 | dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset, |
6403 | "%s", name); | |
a3f97cbb | 6404 | break; |
3f76745e JM |
6405 | |
6406 | case dw_val_class_fde_ref: | |
a6ab3aad JM |
6407 | { |
6408 | char l1[20]; | |
2ad9852d | 6409 | |
2e4b9b8c RH |
6410 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL, |
6411 | a->dw_attr_val.v.val_fde_index * 2); | |
6412 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name); | |
a6ab3aad | 6413 | } |
a3f97cbb | 6414 | break; |
a3f97cbb | 6415 | |
3f76745e | 6416 | case dw_val_class_lbl_id: |
8e7fa2c8 | 6417 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 6418 | break; |
71dfc51f | 6419 | |
8b790721 | 6420 | case dw_val_class_lbl_offset: |
2e4b9b8c | 6421 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 6422 | break; |
a3f97cbb | 6423 | |
3f76745e | 6424 | case dw_val_class_str: |
9eb4015a JJ |
6425 | if (AT_string_form (a) == DW_FORM_strp) |
6426 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, | |
6427 | a->dw_attr_val.v.val_str->label, | |
a4cf1d85 | 6428 | "%s: \"%s\"", name, AT_string (a)); |
9eb4015a JJ |
6429 | else |
6430 | dw2_asm_output_nstring (AT_string (a), -1, "%s", name); | |
3f76745e | 6431 | break; |
b2932ae5 | 6432 | |
3f76745e JM |
6433 | default: |
6434 | abort (); | |
6435 | } | |
3f76745e | 6436 | } |
71dfc51f | 6437 | |
3f76745e JM |
6438 | for (c = die->die_child; c != NULL; c = c->die_sib) |
6439 | output_die (c); | |
71dfc51f | 6440 | |
2ad9852d | 6441 | /* Add null byte to terminate sibling list. */ |
3f76745e | 6442 | if (die->die_child != NULL) |
2ad9852d RK |
6443 | dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx", |
6444 | die->die_offset); | |
3f76745e | 6445 | } |
71dfc51f | 6446 | |
3f76745e JM |
6447 | /* Output the compilation unit that appears at the beginning of the |
6448 | .debug_info section, and precedes the DIE descriptions. */ | |
71dfc51f | 6449 | |
3f76745e JM |
6450 | static void |
6451 | output_compilation_unit_header () | |
6452 | { | |
2e4b9b8c RH |
6453 | dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE, |
6454 | "Length of Compilation Unit Info"); | |
2e4b9b8c | 6455 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number"); |
2e4b9b8c RH |
6456 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label, |
6457 | "Offset Into Abbrev. Section"); | |
2e4b9b8c | 6458 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)"); |
a3f97cbb JW |
6459 | } |
6460 | ||
881c6935 JM |
6461 | /* Output the compilation unit DIE and its children. */ |
6462 | ||
6463 | static void | |
6464 | output_comp_unit (die) | |
6465 | dw_die_ref die; | |
6466 | { | |
ce1cc601 | 6467 | const char *secname; |
881c6935 | 6468 | |
2ad9852d RK |
6469 | /* Even if there are no children of this DIE, we must output the information |
6470 | about the compilation unit. Otherwise, on an empty translation unit, we | |
6471 | will generate a present, but empty, .debug_info section. IRIX 6.5 `nm' | |
6472 | will then complain when examining the file. First mark all the DIEs in | |
6473 | this CU so we know which get local refs. */ | |
1bfb5f8f JM |
6474 | mark_dies (die); |
6475 | ||
6476 | build_abbrev_table (die); | |
6477 | ||
6d2f8887 | 6478 | /* Initialize the beginning DIE offset - and calculate sizes/offsets. */ |
881c6935 JM |
6479 | next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE; |
6480 | calc_die_sizes (die); | |
6481 | ||
881c6935 JM |
6482 | if (die->die_symbol) |
6483 | { | |
ce1cc601 | 6484 | char *tmp = (char *) alloca (strlen (die->die_symbol) + 24); |
2ad9852d | 6485 | |
ce1cc601 KG |
6486 | sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol); |
6487 | secname = tmp; | |
881c6935 JM |
6488 | die->die_symbol = NULL; |
6489 | } | |
6490 | else | |
ce1cc601 | 6491 | secname = (const char *) DEBUG_INFO_SECTION; |
881c6935 JM |
6492 | |
6493 | /* Output debugging information. */ | |
715bdd29 | 6494 | named_section_flags (secname, SECTION_DEBUG); |
881c6935 JM |
6495 | output_compilation_unit_header (); |
6496 | output_die (die); | |
6497 | ||
1bfb5f8f JM |
6498 | /* Leave the marks on the main CU, so we can check them in |
6499 | output_pubnames. */ | |
881c6935 | 6500 | if (die->die_symbol) |
1bfb5f8f | 6501 | unmark_dies (die); |
881c6935 JM |
6502 | } |
6503 | ||
7afff7cf NB |
6504 | /* The DWARF2 pubname for a nested thingy looks like "A::f". The |
6505 | output of lang_hooks.decl_printable_name for C++ looks like | |
6506 | "A::f(int)". Let's drop the argument list, and maybe the scope. */ | |
a1d7ffe3 | 6507 | |
d560ee52 | 6508 | static const char * |
a1d7ffe3 JM |
6509 | dwarf2_name (decl, scope) |
6510 | tree decl; | |
6511 | int scope; | |
6512 | { | |
7afff7cf | 6513 | return (*lang_hooks.decl_printable_name) (decl, scope ? 1 : 0); |
a1d7ffe3 JM |
6514 | } |
6515 | ||
d291dd49 | 6516 | /* Add a new entry to .debug_pubnames if appropriate. */ |
71dfc51f | 6517 | |
d291dd49 JM |
6518 | static void |
6519 | add_pubname (decl, die) | |
6520 | tree decl; | |
6521 | dw_die_ref die; | |
6522 | { | |
6523 | pubname_ref p; | |
6524 | ||
6525 | if (! TREE_PUBLIC (decl)) | |
6526 | return; | |
6527 | ||
6528 | if (pubname_table_in_use == pubname_table_allocated) | |
6529 | { | |
6530 | pubname_table_allocated += PUBNAME_TABLE_INCREMENT; | |
2ad9852d RK |
6531 | pubname_table |
6532 | = (pubname_ref) xrealloc (pubname_table, | |
6533 | (pubname_table_allocated | |
6534 | * sizeof (pubname_entry))); | |
d291dd49 | 6535 | } |
71dfc51f | 6536 | |
d291dd49 JM |
6537 | p = &pubname_table[pubname_table_in_use++]; |
6538 | p->die = die; | |
a1d7ffe3 | 6539 | p->name = xstrdup (dwarf2_name (decl, 1)); |
d291dd49 JM |
6540 | } |
6541 | ||
a3f97cbb JW |
6542 | /* Output the public names table used to speed up access to externally |
6543 | visible names. For now, only generate entries for externally | |
6544 | visible procedures. */ | |
71dfc51f | 6545 | |
a3f97cbb JW |
6546 | static void |
6547 | output_pubnames () | |
6548 | { | |
b3694847 SS |
6549 | unsigned i; |
6550 | unsigned long pubnames_length = size_of_pubnames (); | |
71dfc51f | 6551 | |
2e4b9b8c RH |
6552 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, |
6553 | "Length of Public Names Info"); | |
2e4b9b8c | 6554 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
2e4b9b8c RH |
6555 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
6556 | "Offset of Compilation Unit Info"); | |
2e4b9b8c RH |
6557 | dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset, |
6558 | "Compilation Unit Length"); | |
71dfc51f | 6559 | |
2ad9852d | 6560 | for (i = 0; i < pubname_table_in_use; i++) |
a3f97cbb | 6561 | { |
b3694847 | 6562 | pubname_ref pub = &pubname_table[i]; |
71dfc51f | 6563 | |
881c6935 | 6564 | /* We shouldn't see pubnames for DIEs outside of the main CU. */ |
1bfb5f8f | 6565 | if (pub->die->die_mark == 0) |
881c6935 JM |
6566 | abort (); |
6567 | ||
2e4b9b8c RH |
6568 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset, |
6569 | "DIE offset"); | |
71dfc51f | 6570 | |
2e4b9b8c | 6571 | dw2_asm_output_nstring (pub->name, -1, "external name"); |
a3f97cbb | 6572 | } |
71dfc51f | 6573 | |
2e4b9b8c | 6574 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL); |
a3f97cbb JW |
6575 | } |
6576 | ||
d291dd49 | 6577 | /* Add a new entry to .debug_aranges if appropriate. */ |
71dfc51f | 6578 | |
d291dd49 JM |
6579 | static void |
6580 | add_arange (decl, die) | |
6581 | tree decl; | |
6582 | dw_die_ref die; | |
6583 | { | |
6584 | if (! DECL_SECTION_NAME (decl)) | |
6585 | return; | |
6586 | ||
6587 | if (arange_table_in_use == arange_table_allocated) | |
6588 | { | |
6589 | arange_table_allocated += ARANGE_TABLE_INCREMENT; | |
a20612aa RH |
6590 | arange_table = (dw_die_ref *) |
6591 | xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref)); | |
d291dd49 | 6592 | } |
71dfc51f | 6593 | |
d291dd49 JM |
6594 | arange_table[arange_table_in_use++] = die; |
6595 | } | |
6596 | ||
a3f97cbb JW |
6597 | /* Output the information that goes into the .debug_aranges table. |
6598 | Namely, define the beginning and ending address range of the | |
6599 | text section generated for this compilation unit. */ | |
71dfc51f | 6600 | |
a3f97cbb JW |
6601 | static void |
6602 | output_aranges () | |
6603 | { | |
b3694847 SS |
6604 | unsigned i; |
6605 | unsigned long aranges_length = size_of_aranges (); | |
71dfc51f | 6606 | |
2e4b9b8c RH |
6607 | dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length, |
6608 | "Length of Address Ranges Info"); | |
2e4b9b8c | 6609 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
2e4b9b8c RH |
6610 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
6611 | "Offset of Compilation Unit Info"); | |
2e4b9b8c | 6612 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address"); |
2e4b9b8c | 6613 | dw2_asm_output_data (1, 0, "Size of Segment Descriptor"); |
71dfc51f | 6614 | |
262b6384 SC |
6615 | /* We need to align to twice the pointer size here. */ |
6616 | if (DWARF_ARANGES_PAD_SIZE) | |
6617 | { | |
2e4b9b8c RH |
6618 | /* Pad using a 2 byte words so that padding is correct for any |
6619 | pointer size. */ | |
6620 | dw2_asm_output_data (2, 0, "Pad to %d byte boundary", | |
6621 | 2 * DWARF2_ADDR_SIZE); | |
770ca8c6 | 6622 | for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2) |
2e4b9b8c | 6623 | dw2_asm_output_data (2, 0, NULL); |
262b6384 | 6624 | } |
71dfc51f | 6625 | |
8e7fa2c8 | 6626 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address"); |
2e4b9b8c RH |
6627 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label, |
6628 | text_section_label, "Length"); | |
71dfc51f | 6629 | |
2ad9852d | 6630 | for (i = 0; i < arange_table_in_use; i++) |
d291dd49 | 6631 | { |
e689ae67 | 6632 | dw_die_ref die = arange_table[i]; |
71dfc51f | 6633 | |
881c6935 | 6634 | /* We shouldn't see aranges for DIEs outside of the main CU. */ |
1bfb5f8f | 6635 | if (die->die_mark == 0) |
881c6935 JM |
6636 | abort (); |
6637 | ||
e689ae67 | 6638 | if (die->die_tag == DW_TAG_subprogram) |
2e4b9b8c | 6639 | { |
8e7fa2c8 | 6640 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die), |
173bf5be | 6641 | "Address"); |
2e4b9b8c RH |
6642 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die), |
6643 | get_AT_low_pc (die), "Length"); | |
6644 | } | |
d291dd49 | 6645 | else |
a1d7ffe3 | 6646 | { |
e689ae67 JM |
6647 | /* A static variable; extract the symbol from DW_AT_location. |
6648 | Note that this code isn't currently hit, as we only emit | |
6649 | aranges for functions (jason 9/23/99). */ | |
e689ae67 JM |
6650 | dw_attr_ref a = get_AT (die, DW_AT_location); |
6651 | dw_loc_descr_ref loc; | |
2ad9852d | 6652 | |
a96c67ec | 6653 | if (! a || AT_class (a) != dw_val_class_loc) |
e689ae67 JM |
6654 | abort (); |
6655 | ||
a96c67ec | 6656 | loc = AT_loc (a); |
e689ae67 JM |
6657 | if (loc->dw_loc_opc != DW_OP_addr) |
6658 | abort (); | |
6659 | ||
2e4b9b8c RH |
6660 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, |
6661 | loc->dw_loc_oprnd1.v.val_addr, "Address"); | |
6662 | dw2_asm_output_data (DWARF2_ADDR_SIZE, | |
6663 | get_AT_unsigned (die, DW_AT_byte_size), | |
6664 | "Length"); | |
a1d7ffe3 | 6665 | } |
d291dd49 | 6666 | } |
71dfc51f | 6667 | |
a3f97cbb | 6668 | /* Output the terminator words. */ |
2e4b9b8c RH |
6669 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); |
6670 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
a3f97cbb JW |
6671 | } |
6672 | ||
a20612aa RH |
6673 | /* Add a new entry to .debug_ranges. Return the offset at which it |
6674 | was placed. */ | |
6675 | ||
6676 | static unsigned int | |
6677 | add_ranges (block) | |
6678 | tree block; | |
6679 | { | |
6680 | unsigned int in_use = ranges_table_in_use; | |
6681 | ||
6682 | if (in_use == ranges_table_allocated) | |
6683 | { | |
6684 | ranges_table_allocated += RANGES_TABLE_INCREMENT; | |
6685 | ranges_table = (dw_ranges_ref) | |
6686 | xrealloc (ranges_table, (ranges_table_allocated | |
6687 | * sizeof (struct dw_ranges_struct))); | |
6688 | } | |
6689 | ||
6690 | ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0); | |
6691 | ranges_table_in_use = in_use + 1; | |
6692 | ||
6693 | return in_use * 2 * DWARF2_ADDR_SIZE; | |
6694 | } | |
6695 | ||
6696 | static void | |
6697 | output_ranges () | |
6698 | { | |
b3694847 | 6699 | unsigned i; |
83182544 | 6700 | static const char *const start_fmt = "Offset 0x%x"; |
a20612aa RH |
6701 | const char *fmt = start_fmt; |
6702 | ||
2ad9852d | 6703 | for (i = 0; i < ranges_table_in_use; i++) |
a20612aa RH |
6704 | { |
6705 | int block_num = ranges_table[i].block_num; | |
6706 | ||
6707 | if (block_num) | |
6708 | { | |
6709 | char blabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6710 | char elabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6711 | ||
6712 | ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num); | |
6713 | ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num); | |
6714 | ||
6715 | /* If all code is in the text section, then the compilation | |
6716 | unit base address defaults to DW_AT_low_pc, which is the | |
6717 | base of the text section. */ | |
6718 | if (separate_line_info_table_in_use == 0) | |
6719 | { | |
6720 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel, | |
6721 | text_section_label, | |
6722 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
6723 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel, | |
6724 | text_section_label, NULL); | |
6725 | } | |
2ad9852d | 6726 | |
a20612aa RH |
6727 | /* Otherwise, we add a DW_AT_entry_pc attribute to force the |
6728 | compilation unit base address to zero, which allows us to | |
6729 | use absolute addresses, and not worry about whether the | |
6730 | target supports cross-section arithmetic. */ | |
6731 | else | |
6732 | { | |
6733 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel, | |
6734 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
6735 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL); | |
6736 | } | |
6737 | ||
6738 | fmt = NULL; | |
6739 | } | |
6740 | else | |
6741 | { | |
6742 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
6743 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
6744 | fmt = start_fmt; | |
6745 | } | |
6746 | } | |
6747 | } | |
0b34cf1e UD |
6748 | |
6749 | /* Data structure containing information about input files. */ | |
6750 | struct file_info | |
6751 | { | |
6752 | char *path; /* Complete file name. */ | |
6753 | char *fname; /* File name part. */ | |
6754 | int length; /* Length of entire string. */ | |
6755 | int file_idx; /* Index in input file table. */ | |
6756 | int dir_idx; /* Index in directory table. */ | |
6757 | }; | |
6758 | ||
6759 | /* Data structure containing information about directories with source | |
6760 | files. */ | |
6761 | struct dir_info | |
6762 | { | |
6763 | char *path; /* Path including directory name. */ | |
6764 | int length; /* Path length. */ | |
6765 | int prefix; /* Index of directory entry which is a prefix. */ | |
0b34cf1e UD |
6766 | int count; /* Number of files in this directory. */ |
6767 | int dir_idx; /* Index of directory used as base. */ | |
6768 | int used; /* Used in the end? */ | |
6769 | }; | |
6770 | ||
6771 | /* Callback function for file_info comparison. We sort by looking at | |
6772 | the directories in the path. */ | |
356b0698 | 6773 | |
0b34cf1e UD |
6774 | static int |
6775 | file_info_cmp (p1, p2) | |
6776 | const void *p1; | |
6777 | const void *p2; | |
6778 | { | |
6779 | const struct file_info *s1 = p1; | |
6780 | const struct file_info *s2 = p2; | |
6781 | unsigned char *cp1; | |
6782 | unsigned char *cp2; | |
6783 | ||
356b0698 RK |
6784 | /* Take care of file names without directories. We need to make sure that |
6785 | we return consistent values to qsort since some will get confused if | |
6786 | we return the same value when identical operands are passed in opposite | |
6787 | orders. So if neither has a directory, return 0 and otherwise return | |
6788 | 1 or -1 depending on which one has the directory. */ | |
6789 | if ((s1->path == s1->fname || s2->path == s2->fname)) | |
6790 | return (s2->path == s2->fname) - (s1->path == s1->fname); | |
0b34cf1e UD |
6791 | |
6792 | cp1 = (unsigned char *) s1->path; | |
6793 | cp2 = (unsigned char *) s2->path; | |
6794 | ||
6795 | while (1) | |
6796 | { | |
6797 | ++cp1; | |
6798 | ++cp2; | |
356b0698 RK |
6799 | /* Reached the end of the first path? If so, handle like above. */ |
6800 | if ((cp1 == (unsigned char *) s1->fname) | |
6801 | || (cp2 == (unsigned char *) s2->fname)) | |
6802 | return ((cp2 == (unsigned char *) s2->fname) | |
6803 | - (cp1 == (unsigned char *) s1->fname)); | |
0b34cf1e UD |
6804 | |
6805 | /* Character of current path component the same? */ | |
356b0698 | 6806 | else if (*cp1 != *cp2) |
0b34cf1e UD |
6807 | return *cp1 - *cp2; |
6808 | } | |
6809 | } | |
6810 | ||
6811 | /* Output the directory table and the file name table. We try to minimize | |
6812 | the total amount of memory needed. A heuristic is used to avoid large | |
6813 | slowdowns with many input files. */ | |
2ad9852d | 6814 | |
0b34cf1e UD |
6815 | static void |
6816 | output_file_names () | |
6817 | { | |
6818 | struct file_info *files; | |
6819 | struct dir_info *dirs; | |
6820 | int *saved; | |
6821 | int *savehere; | |
6822 | int *backmap; | |
6823 | int ndirs; | |
6824 | int idx_offset; | |
6825 | int i; | |
6826 | int idx; | |
6827 | ||
6828 | /* Allocate the various arrays we need. */ | |
981975b6 | 6829 | files = (struct file_info *) alloca (file_table.in_use |
0b34cf1e | 6830 | * sizeof (struct file_info)); |
981975b6 | 6831 | dirs = (struct dir_info *) alloca (file_table.in_use |
0b34cf1e UD |
6832 | * sizeof (struct dir_info)); |
6833 | ||
6834 | /* Sort the file names. */ | |
2ad9852d | 6835 | for (i = 1; i < (int) file_table.in_use; i++) |
0b34cf1e UD |
6836 | { |
6837 | char *f; | |
6838 | ||
6839 | /* Skip all leading "./". */ | |
981975b6 | 6840 | f = file_table.table[i]; |
0b34cf1e UD |
6841 | while (f[0] == '.' && f[1] == '/') |
6842 | f += 2; | |
6843 | ||
6844 | /* Create a new array entry. */ | |
6845 | files[i].path = f; | |
6846 | files[i].length = strlen (f); | |
6847 | files[i].file_idx = i; | |
6848 | ||
6849 | /* Search for the file name part. */ | |
6850 | f = strrchr (f, '/'); | |
6851 | files[i].fname = f == NULL ? files[i].path : f + 1; | |
6852 | } | |
2ad9852d | 6853 | |
981975b6 | 6854 | qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp); |
0b34cf1e UD |
6855 | |
6856 | /* Find all the different directories used. */ | |
6857 | dirs[0].path = files[1].path; | |
6858 | dirs[0].length = files[1].fname - files[1].path; | |
6859 | dirs[0].prefix = -1; | |
0b34cf1e UD |
6860 | dirs[0].count = 1; |
6861 | dirs[0].dir_idx = 0; | |
6862 | dirs[0].used = 0; | |
6863 | files[1].dir_idx = 0; | |
6864 | ndirs = 1; | |
6865 | ||
2ad9852d | 6866 | for (i = 2; i < (int) file_table.in_use; i++) |
0b34cf1e UD |
6867 | if (files[i].fname - files[i].path == dirs[ndirs - 1].length |
6868 | && memcmp (dirs[ndirs - 1].path, files[i].path, | |
6869 | dirs[ndirs - 1].length) == 0) | |
6870 | { | |
6871 | /* Same directory as last entry. */ | |
6872 | files[i].dir_idx = ndirs - 1; | |
0b34cf1e UD |
6873 | ++dirs[ndirs - 1].count; |
6874 | } | |
6875 | else | |
6876 | { | |
6877 | int j; | |
6878 | ||
6879 | /* This is a new directory. */ | |
6880 | dirs[ndirs].path = files[i].path; | |
6881 | dirs[ndirs].length = files[i].fname - files[i].path; | |
0b34cf1e UD |
6882 | dirs[ndirs].count = 1; |
6883 | dirs[ndirs].dir_idx = ndirs; | |
6884 | dirs[ndirs].used = 0; | |
6885 | files[i].dir_idx = ndirs; | |
6886 | ||
6887 | /* Search for a prefix. */ | |
981975b6 | 6888 | dirs[ndirs].prefix = -1; |
2ad9852d | 6889 | for (j = 0; j < ndirs; j++) |
981975b6 RH |
6890 | if (dirs[j].length < dirs[ndirs].length |
6891 | && dirs[j].length > 1 | |
6892 | && (dirs[ndirs].prefix == -1 | |
6893 | || dirs[j].length > dirs[dirs[ndirs].prefix].length) | |
6894 | && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0) | |
6895 | dirs[ndirs].prefix = j; | |
0b34cf1e UD |
6896 | |
6897 | ++ndirs; | |
6898 | } | |
6899 | ||
2ad9852d RK |
6900 | /* Now to the actual work. We have to find a subset of the directories which |
6901 | allow expressing the file name using references to the directory table | |
6902 | with the least amount of characters. We do not do an exhaustive search | |
6903 | where we would have to check out every combination of every single | |
6904 | possible prefix. Instead we use a heuristic which provides nearly optimal | |
6905 | results in most cases and never is much off. */ | |
0b34cf1e UD |
6906 | saved = (int *) alloca (ndirs * sizeof (int)); |
6907 | savehere = (int *) alloca (ndirs * sizeof (int)); | |
6908 | ||
6909 | memset (saved, '\0', ndirs * sizeof (saved[0])); | |
2ad9852d | 6910 | for (i = 0; i < ndirs; i++) |
0b34cf1e UD |
6911 | { |
6912 | int j; | |
6913 | int total; | |
6914 | ||
2ad9852d RK |
6915 | /* We can always save some space for the current directory. But this |
6916 | does not mean it will be enough to justify adding the directory. */ | |
0b34cf1e UD |
6917 | savehere[i] = dirs[i].length; |
6918 | total = (savehere[i] - saved[i]) * dirs[i].count; | |
6919 | ||
2ad9852d | 6920 | for (j = i + 1; j < ndirs; j++) |
0b34cf1e UD |
6921 | { |
6922 | savehere[j] = 0; | |
0b34cf1e UD |
6923 | if (saved[j] < dirs[i].length) |
6924 | { | |
6925 | /* Determine whether the dirs[i] path is a prefix of the | |
6926 | dirs[j] path. */ | |
6927 | int k; | |
6928 | ||
981975b6 RH |
6929 | k = dirs[j].prefix; |
6930 | while (k != -1 && k != i) | |
6931 | k = dirs[k].prefix; | |
6932 | ||
6933 | if (k == i) | |
6934 | { | |
6935 | /* Yes it is. We can possibly safe some memory but | |
6936 | writing the filenames in dirs[j] relative to | |
6937 | dirs[i]. */ | |
6938 | savehere[j] = dirs[i].length; | |
6939 | total += (savehere[j] - saved[j]) * dirs[j].count; | |
6940 | } | |
0b34cf1e UD |
6941 | } |
6942 | } | |
6943 | ||
6944 | /* Check whether we can safe enough to justify adding the dirs[i] | |
6945 | directory. */ | |
6946 | if (total > dirs[i].length + 1) | |
6947 | { | |
981975b6 | 6948 | /* It's worthwhile adding. */ |
c26fbbca | 6949 | for (j = i; j < ndirs; j++) |
0b34cf1e UD |
6950 | if (savehere[j] > 0) |
6951 | { | |
6952 | /* Remember how much we saved for this directory so far. */ | |
6953 | saved[j] = savehere[j]; | |
6954 | ||
6955 | /* Remember the prefix directory. */ | |
6956 | dirs[j].dir_idx = i; | |
6957 | } | |
6958 | } | |
6959 | } | |
6960 | ||
2ad9852d RK |
6961 | /* We have to emit them in the order they appear in the file_table array |
6962 | since the index is used in the debug info generation. To do this | |
6963 | efficiently we generate a back-mapping of the indices first. */ | |
981975b6 | 6964 | backmap = (int *) alloca (file_table.in_use * sizeof (int)); |
2ad9852d | 6965 | for (i = 1; i < (int) file_table.in_use; i++) |
0b34cf1e UD |
6966 | { |
6967 | backmap[files[i].file_idx] = i; | |
2ad9852d | 6968 | |
0b34cf1e UD |
6969 | /* Mark this directory as used. */ |
6970 | dirs[dirs[files[i].dir_idx].dir_idx].used = 1; | |
6971 | } | |
6972 | ||
2ad9852d RK |
6973 | /* That was it. We are ready to emit the information. First emit the |
6974 | directory name table. We have to make sure the first actually emitted | |
6975 | directory name has index one; zero is reserved for the current working | |
6976 | directory. Make sure we do not confuse these indices with the one for the | |
6977 | constructed table (even though most of the time they are identical). */ | |
0b34cf1e | 6978 | idx = 1; |
e57cabac | 6979 | idx_offset = dirs[0].length > 0 ? 1 : 0; |
2ad9852d | 6980 | for (i = 1 - idx_offset; i < ndirs; i++) |
0b34cf1e UD |
6981 | if (dirs[i].used != 0) |
6982 | { | |
6983 | dirs[i].used = idx++; | |
2e4b9b8c RH |
6984 | dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1, |
6985 | "Directory Entry: 0x%x", dirs[i].used); | |
0b34cf1e | 6986 | } |
2ad9852d | 6987 | |
2e4b9b8c RH |
6988 | dw2_asm_output_data (1, 0, "End directory table"); |
6989 | ||
0b34cf1e UD |
6990 | /* Correct the index for the current working directory entry if it |
6991 | exists. */ | |
6992 | if (idx_offset == 0) | |
6993 | dirs[0].used = 0; | |
0b34cf1e UD |
6994 | |
6995 | /* Now write all the file names. */ | |
2ad9852d | 6996 | for (i = 1; i < (int) file_table.in_use; i++) |
0b34cf1e UD |
6997 | { |
6998 | int file_idx = backmap[i]; | |
6999 | int dir_idx = dirs[files[file_idx].dir_idx].dir_idx; | |
7000 | ||
2e4b9b8c RH |
7001 | dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1, |
7002 | "File Entry: 0x%x", i); | |
0b34cf1e UD |
7003 | |
7004 | /* Include directory index. */ | |
2e4b9b8c | 7005 | dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL); |
0b34cf1e UD |
7006 | |
7007 | /* Modification time. */ | |
2e4b9b8c | 7008 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e UD |
7009 | |
7010 | /* File length in bytes. */ | |
2e4b9b8c | 7011 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e | 7012 | } |
2ad9852d | 7013 | |
2e4b9b8c | 7014 | dw2_asm_output_data (1, 0, "End file name table"); |
0b34cf1e UD |
7015 | } |
7016 | ||
7017 | ||
a3f97cbb | 7018 | /* Output the source line number correspondence information. This |
14a774a9 | 7019 | information goes into the .debug_line section. */ |
71dfc51f | 7020 | |
a3f97cbb JW |
7021 | static void |
7022 | output_line_info () | |
7023 | { | |
981975b6 | 7024 | char l1[20], l2[20], p1[20], p2[20]; |
a3f97cbb JW |
7025 | char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
7026 | char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 SS |
7027 | unsigned opc; |
7028 | unsigned n_op_args; | |
7029 | unsigned long lt_index; | |
7030 | unsigned long current_line; | |
7031 | long line_offset; | |
7032 | long line_delta; | |
7033 | unsigned long current_file; | |
7034 | unsigned long function; | |
71dfc51f | 7035 | |
2e4b9b8c RH |
7036 | ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0); |
7037 | ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0); | |
981975b6 RH |
7038 | ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0); |
7039 | ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0); | |
71dfc51f | 7040 | |
2e4b9b8c RH |
7041 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1, |
7042 | "Length of Source Line Info"); | |
7043 | ASM_OUTPUT_LABEL (asm_out_file, l1); | |
71dfc51f | 7044 | |
2e4b9b8c | 7045 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
981975b6 RH |
7046 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length"); |
7047 | ASM_OUTPUT_LABEL (asm_out_file, p1); | |
71dfc51f | 7048 | |
c1a046e5 TT |
7049 | /* Define the architecture-dependent minimum instruction length (in |
7050 | bytes). In this implementation of DWARF, this field is used for | |
7051 | information purposes only. Since GCC generates assembly language, | |
7052 | we have no a priori knowledge of how many instruction bytes are | |
7053 | generated for each source line, and therefore can use only the | |
7054 | DW_LNE_set_address and DW_LNS_fixed_advance_pc line information | |
7055 | commands. Accordingly, we fix this as `1', which is "correct | |
7056 | enough" for all architectures, and don't let the target override. */ | |
7057 | dw2_asm_output_data (1, 1, | |
2e4b9b8c | 7058 | "Minimum Instruction Length"); |
c1a046e5 | 7059 | |
2e4b9b8c RH |
7060 | dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START, |
7061 | "Default is_stmt_start flag"); | |
2e4b9b8c RH |
7062 | dw2_asm_output_data (1, DWARF_LINE_BASE, |
7063 | "Line Base Value (Special Opcodes)"); | |
2e4b9b8c RH |
7064 | dw2_asm_output_data (1, DWARF_LINE_RANGE, |
7065 | "Line Range Value (Special Opcodes)"); | |
2e4b9b8c RH |
7066 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE, |
7067 | "Special Opcode Base"); | |
71dfc51f | 7068 | |
2ad9852d | 7069 | for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++) |
a3f97cbb JW |
7070 | { |
7071 | switch (opc) | |
7072 | { | |
7073 | case DW_LNS_advance_pc: | |
7074 | case DW_LNS_advance_line: | |
7075 | case DW_LNS_set_file: | |
7076 | case DW_LNS_set_column: | |
7077 | case DW_LNS_fixed_advance_pc: | |
7078 | n_op_args = 1; | |
7079 | break; | |
7080 | default: | |
7081 | n_op_args = 0; | |
7082 | break; | |
7083 | } | |
2e4b9b8c RH |
7084 | |
7085 | dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args", | |
7086 | opc, n_op_args); | |
a3f97cbb | 7087 | } |
71dfc51f | 7088 | |
0b34cf1e UD |
7089 | /* Write out the information about the files we use. */ |
7090 | output_file_names (); | |
981975b6 | 7091 | ASM_OUTPUT_LABEL (asm_out_file, p2); |
a3f97cbb | 7092 | |
2f22d404 JM |
7093 | /* We used to set the address register to the first location in the text |
7094 | section here, but that didn't accomplish anything since we already | |
7095 | have a line note for the opening brace of the first function. */ | |
a3f97cbb JW |
7096 | |
7097 | /* Generate the line number to PC correspondence table, encoded as | |
7098 | a series of state machine operations. */ | |
7099 | current_file = 1; | |
7100 | current_line = 1; | |
8b790721 | 7101 | strcpy (prev_line_label, text_section_label); |
a3f97cbb JW |
7102 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) |
7103 | { | |
b3694847 | 7104 | dw_line_info_ref line_info = &line_info_table[lt_index]; |
2f22d404 | 7105 | |
10a11b75 JM |
7106 | #if 0 |
7107 | /* Disable this optimization for now; GDB wants to see two line notes | |
7108 | at the beginning of a function so it can find the end of the | |
7109 | prologue. */ | |
7110 | ||
2f22d404 JM |
7111 | /* Don't emit anything for redundant notes. Just updating the |
7112 | address doesn't accomplish anything, because we already assume | |
7113 | that anything after the last address is this line. */ | |
7114 | if (line_info->dw_line_num == current_line | |
7115 | && line_info->dw_file_num == current_file) | |
7116 | continue; | |
10a11b75 | 7117 | #endif |
71dfc51f | 7118 | |
2e4b9b8c RH |
7119 | /* Emit debug info for the address of the current line. |
7120 | ||
7121 | Unfortunately, we have little choice here currently, and must always | |
2ad9852d | 7122 | use the most general form. GCC does not know the address delta |
2e4b9b8c RH |
7123 | itself, so we can't use DW_LNS_advance_pc. Many ports do have length |
7124 | attributes which will give an upper bound on the address range. We | |
7125 | could perhaps use length attributes to determine when it is safe to | |
7126 | use DW_LNS_fixed_advance_pc. */ | |
7127 | ||
5c90448c | 7128 | ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index); |
f19a6894 JW |
7129 | if (0) |
7130 | { | |
7131 | /* This can handle deltas up to 0xffff. This takes 3 bytes. */ | |
2e4b9b8c RH |
7132 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7133 | "DW_LNS_fixed_advance_pc"); | |
7134 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7135 | } |
7136 | else | |
7137 | { | |
a1a4189d JB |
7138 | /* This can handle any delta. This takes |
7139 | 4+DWARF2_ADDR_SIZE bytes. */ | |
2e4b9b8c RH |
7140 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7141 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7142 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7143 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7144 | } |
2ad9852d | 7145 | |
f19a6894 JW |
7146 | strcpy (prev_line_label, line_label); |
7147 | ||
7148 | /* Emit debug info for the source file of the current line, if | |
7149 | different from the previous line. */ | |
a3f97cbb JW |
7150 | if (line_info->dw_file_num != current_file) |
7151 | { | |
7152 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
7153 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
7154 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
981975b6 | 7155 | file_table.table[current_file]); |
a3f97cbb | 7156 | } |
71dfc51f | 7157 | |
f19a6894 JW |
7158 | /* Emit debug info for the current line number, choosing the encoding |
7159 | that uses the least amount of space. */ | |
2f22d404 | 7160 | if (line_info->dw_line_num != current_line) |
a3f97cbb | 7161 | { |
2f22d404 JM |
7162 | line_offset = line_info->dw_line_num - current_line; |
7163 | line_delta = line_offset - DWARF_LINE_BASE; | |
7164 | current_line = line_info->dw_line_num; | |
7165 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
2ad9852d RK |
7166 | /* This can handle deltas from -10 to 234, using the current |
7167 | definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This | |
7168 | takes 1 byte. */ | |
7169 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, | |
7170 | "line %lu", current_line); | |
2f22d404 JM |
7171 | else |
7172 | { | |
7173 | /* This can handle any delta. This takes at least 4 bytes, | |
7174 | depending on the value being encoded. */ | |
2e4b9b8c RH |
7175 | dw2_asm_output_data (1, DW_LNS_advance_line, |
7176 | "advance to line %lu", current_line); | |
7177 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
7178 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
2f22d404 | 7179 | } |
a94dbf2c JM |
7180 | } |
7181 | else | |
2ad9852d RK |
7182 | /* We still need to start a new row, so output a copy insn. */ |
7183 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
a3f97cbb JW |
7184 | } |
7185 | ||
f19a6894 JW |
7186 | /* Emit debug info for the address of the end of the function. */ |
7187 | if (0) | |
7188 | { | |
2e4b9b8c RH |
7189 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7190 | "DW_LNS_fixed_advance_pc"); | |
7191 | dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL); | |
f19a6894 JW |
7192 | } |
7193 | else | |
7194 | { | |
2e4b9b8c RH |
7195 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7196 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7197 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7198 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL); |
f19a6894 | 7199 | } |
bdb669cb | 7200 | |
2e4b9b8c RH |
7201 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
7202 | dw2_asm_output_data_uleb128 (1, NULL); | |
7203 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
7204 | |
7205 | function = 0; | |
7206 | current_file = 1; | |
7207 | current_line = 1; | |
556273e0 | 7208 | for (lt_index = 0; lt_index < separate_line_info_table_in_use;) |
e90b62db | 7209 | { |
b3694847 | 7210 | dw_separate_line_info_ref line_info |
e90b62db | 7211 | = &separate_line_info_table[lt_index]; |
71dfc51f | 7212 | |
10a11b75 | 7213 | #if 0 |
2f22d404 JM |
7214 | /* Don't emit anything for redundant notes. */ |
7215 | if (line_info->dw_line_num == current_line | |
7216 | && line_info->dw_file_num == current_file | |
7217 | && line_info->function == function) | |
7218 | goto cont; | |
10a11b75 | 7219 | #endif |
2f22d404 | 7220 | |
f19a6894 JW |
7221 | /* Emit debug info for the address of the current line. If this is |
7222 | a new function, or the first line of a function, then we need | |
7223 | to handle it differently. */ | |
5c90448c JM |
7224 | ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL, |
7225 | lt_index); | |
e90b62db JM |
7226 | if (function != line_info->function) |
7227 | { | |
7228 | function = line_info->function; | |
71dfc51f | 7229 | |
e90b62db | 7230 | /* Set the address register to the first line in the function */ |
2e4b9b8c RH |
7231 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7232 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7233 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7234 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
e90b62db JM |
7235 | } |
7236 | else | |
7237 | { | |
f19a6894 JW |
7238 | /* ??? See the DW_LNS_advance_pc comment above. */ |
7239 | if (0) | |
7240 | { | |
2e4b9b8c RH |
7241 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7242 | "DW_LNS_fixed_advance_pc"); | |
7243 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7244 | } |
7245 | else | |
7246 | { | |
2e4b9b8c RH |
7247 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7248 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7249 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7250 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7251 | } |
e90b62db | 7252 | } |
2ad9852d | 7253 | |
f19a6894 | 7254 | strcpy (prev_line_label, line_label); |
71dfc51f | 7255 | |
f19a6894 JW |
7256 | /* Emit debug info for the source file of the current line, if |
7257 | different from the previous line. */ | |
e90b62db JM |
7258 | if (line_info->dw_file_num != current_file) |
7259 | { | |
7260 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
7261 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
7262 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
981975b6 | 7263 | file_table.table[current_file]); |
e90b62db | 7264 | } |
71dfc51f | 7265 | |
f19a6894 JW |
7266 | /* Emit debug info for the current line number, choosing the encoding |
7267 | that uses the least amount of space. */ | |
e90b62db JM |
7268 | if (line_info->dw_line_num != current_line) |
7269 | { | |
7270 | line_offset = line_info->dw_line_num - current_line; | |
7271 | line_delta = line_offset - DWARF_LINE_BASE; | |
7272 | current_line = line_info->dw_line_num; | |
7273 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
2e4b9b8c RH |
7274 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, |
7275 | "line %lu", current_line); | |
e90b62db JM |
7276 | else |
7277 | { | |
2e4b9b8c RH |
7278 | dw2_asm_output_data (1, DW_LNS_advance_line, |
7279 | "advance to line %lu", current_line); | |
7280 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
7281 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
e90b62db JM |
7282 | } |
7283 | } | |
2f22d404 | 7284 | else |
2e4b9b8c | 7285 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); |
71dfc51f | 7286 | |
10a11b75 | 7287 | #if 0 |
2f22d404 | 7288 | cont: |
10a11b75 | 7289 | #endif |
2ad9852d RK |
7290 | |
7291 | lt_index++; | |
e90b62db JM |
7292 | |
7293 | /* If we're done with a function, end its sequence. */ | |
7294 | if (lt_index == separate_line_info_table_in_use | |
7295 | || separate_line_info_table[lt_index].function != function) | |
7296 | { | |
7297 | current_file = 1; | |
7298 | current_line = 1; | |
71dfc51f | 7299 | |
f19a6894 | 7300 | /* Emit debug info for the address of the end of the function. */ |
5c90448c | 7301 | ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function); |
f19a6894 JW |
7302 | if (0) |
7303 | { | |
2e4b9b8c RH |
7304 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7305 | "DW_LNS_fixed_advance_pc"); | |
7306 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7307 | } |
7308 | else | |
7309 | { | |
2e4b9b8c RH |
7310 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7311 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7312 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7313 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7314 | } |
e90b62db JM |
7315 | |
7316 | /* Output the marker for the end of this sequence. */ | |
2e4b9b8c RH |
7317 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
7318 | dw2_asm_output_data_uleb128 (1, NULL); | |
7319 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
7320 | } |
7321 | } | |
f19f17e0 JM |
7322 | |
7323 | /* Output the marker for the end of the line number info. */ | |
2e4b9b8c | 7324 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
a3f97cbb JW |
7325 | } |
7326 | \f | |
a3f97cbb JW |
7327 | /* Given a pointer to a tree node for some base type, return a pointer to |
7328 | a DIE that describes the given type. | |
7329 | ||
7330 | This routine must only be called for GCC type nodes that correspond to | |
7331 | Dwarf base (fundamental) types. */ | |
71dfc51f | 7332 | |
a3f97cbb JW |
7333 | static dw_die_ref |
7334 | base_type_die (type) | |
b3694847 | 7335 | tree type; |
a3f97cbb | 7336 | { |
b3694847 SS |
7337 | dw_die_ref base_type_result; |
7338 | const char *type_name; | |
7339 | enum dwarf_type encoding; | |
7340 | tree name = TYPE_NAME (type); | |
a3f97cbb | 7341 | |
2ad9852d | 7342 | if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE) |
a3f97cbb JW |
7343 | return 0; |
7344 | ||
405f63da MM |
7345 | if (name) |
7346 | { | |
7347 | if (TREE_CODE (name) == TYPE_DECL) | |
7348 | name = DECL_NAME (name); | |
7349 | ||
7350 | type_name = IDENTIFIER_POINTER (name); | |
7351 | } | |
7352 | else | |
7353 | type_name = "__unknown__"; | |
a9d38797 | 7354 | |
a3f97cbb JW |
7355 | switch (TREE_CODE (type)) |
7356 | { | |
a3f97cbb | 7357 | case INTEGER_TYPE: |
a9d38797 | 7358 | /* Carefully distinguish the C character types, without messing |
a3f97cbb | 7359 | up if the language is not C. Note that we check only for the names |
556273e0 | 7360 | that contain spaces; other names might occur by coincidence in other |
a3f97cbb | 7361 | languages. */ |
a9d38797 JM |
7362 | if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE |
7363 | && (type == char_type_node | |
7364 | || ! strcmp (type_name, "signed char") | |
7365 | || ! strcmp (type_name, "unsigned char")))) | |
a3f97cbb | 7366 | { |
a9d38797 JM |
7367 | if (TREE_UNSIGNED (type)) |
7368 | encoding = DW_ATE_unsigned; | |
7369 | else | |
7370 | encoding = DW_ATE_signed; | |
7371 | break; | |
a3f97cbb | 7372 | } |
556273e0 | 7373 | /* else fall through. */ |
a3f97cbb | 7374 | |
a9d38797 JM |
7375 | case CHAR_TYPE: |
7376 | /* GNU Pascal/Ada CHAR type. Not used in C. */ | |
7377 | if (TREE_UNSIGNED (type)) | |
7378 | encoding = DW_ATE_unsigned_char; | |
7379 | else | |
7380 | encoding = DW_ATE_signed_char; | |
a3f97cbb JW |
7381 | break; |
7382 | ||
7383 | case REAL_TYPE: | |
a9d38797 | 7384 | encoding = DW_ATE_float; |
a3f97cbb JW |
7385 | break; |
7386 | ||
405f63da MM |
7387 | /* Dwarf2 doesn't know anything about complex ints, so use |
7388 | a user defined type for it. */ | |
a3f97cbb | 7389 | case COMPLEX_TYPE: |
405f63da MM |
7390 | if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE) |
7391 | encoding = DW_ATE_complex_float; | |
7392 | else | |
7393 | encoding = DW_ATE_lo_user; | |
a3f97cbb JW |
7394 | break; |
7395 | ||
7396 | case BOOLEAN_TYPE: | |
a9d38797 JM |
7397 | /* GNU FORTRAN/Ada/C++ BOOLEAN type. */ |
7398 | encoding = DW_ATE_boolean; | |
a3f97cbb JW |
7399 | break; |
7400 | ||
7401 | default: | |
2ad9852d RK |
7402 | /* No other TREE_CODEs are Dwarf fundamental types. */ |
7403 | abort (); | |
a3f97cbb JW |
7404 | } |
7405 | ||
54ba1f0d | 7406 | base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type); |
14a774a9 RK |
7407 | if (demangle_name_func) |
7408 | type_name = (*demangle_name_func) (type_name); | |
7409 | ||
a9d38797 JM |
7410 | add_AT_string (base_type_result, DW_AT_name, type_name); |
7411 | add_AT_unsigned (base_type_result, DW_AT_byte_size, | |
4e5a8d7b | 7412 | int_size_in_bytes (type)); |
a9d38797 | 7413 | add_AT_unsigned (base_type_result, DW_AT_encoding, encoding); |
a3f97cbb JW |
7414 | |
7415 | return base_type_result; | |
7416 | } | |
7417 | ||
7418 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to | |
7419 | the Dwarf "root" type for the given input type. The Dwarf "root" type of | |
7420 | a given type is generally the same as the given type, except that if the | |
7421 | given type is a pointer or reference type, then the root type of the given | |
7422 | type is the root type of the "basis" type for the pointer or reference | |
7423 | type. (This definition of the "root" type is recursive.) Also, the root | |
7424 | type of a `const' qualified type or a `volatile' qualified type is the | |
7425 | root type of the given type without the qualifiers. */ | |
71dfc51f | 7426 | |
a3f97cbb JW |
7427 | static tree |
7428 | root_type (type) | |
b3694847 | 7429 | tree type; |
a3f97cbb JW |
7430 | { |
7431 | if (TREE_CODE (type) == ERROR_MARK) | |
7432 | return error_mark_node; | |
7433 | ||
7434 | switch (TREE_CODE (type)) | |
7435 | { | |
7436 | case ERROR_MARK: | |
7437 | return error_mark_node; | |
7438 | ||
7439 | case POINTER_TYPE: | |
7440 | case REFERENCE_TYPE: | |
7441 | return type_main_variant (root_type (TREE_TYPE (type))); | |
7442 | ||
7443 | default: | |
7444 | return type_main_variant (type); | |
7445 | } | |
7446 | } | |
7447 | ||
7448 | /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the | |
7449 | given input type is a Dwarf "fundamental" type. Otherwise return null. */ | |
71dfc51f RK |
7450 | |
7451 | static inline int | |
a3f97cbb | 7452 | is_base_type (type) |
b3694847 | 7453 | tree type; |
a3f97cbb JW |
7454 | { |
7455 | switch (TREE_CODE (type)) | |
7456 | { | |
7457 | case ERROR_MARK: | |
7458 | case VOID_TYPE: | |
7459 | case INTEGER_TYPE: | |
7460 | case REAL_TYPE: | |
7461 | case COMPLEX_TYPE: | |
7462 | case BOOLEAN_TYPE: | |
7463 | case CHAR_TYPE: | |
7464 | return 1; | |
7465 | ||
7466 | case SET_TYPE: | |
7467 | case ARRAY_TYPE: | |
7468 | case RECORD_TYPE: | |
7469 | case UNION_TYPE: | |
7470 | case QUAL_UNION_TYPE: | |
7471 | case ENUMERAL_TYPE: | |
7472 | case FUNCTION_TYPE: | |
7473 | case METHOD_TYPE: | |
7474 | case POINTER_TYPE: | |
7475 | case REFERENCE_TYPE: | |
7476 | case FILE_TYPE: | |
7477 | case OFFSET_TYPE: | |
7478 | case LANG_TYPE: | |
604bb87d | 7479 | case VECTOR_TYPE: |
a3f97cbb JW |
7480 | return 0; |
7481 | ||
7482 | default: | |
7483 | abort (); | |
7484 | } | |
71dfc51f | 7485 | |
a3f97cbb JW |
7486 | return 0; |
7487 | } | |
7488 | ||
7489 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging | |
7490 | entry that chains various modifiers in front of the given type. */ | |
71dfc51f | 7491 | |
a3f97cbb JW |
7492 | static dw_die_ref |
7493 | modified_type_die (type, is_const_type, is_volatile_type, context_die) | |
b3694847 SS |
7494 | tree type; |
7495 | int is_const_type; | |
7496 | int is_volatile_type; | |
7497 | dw_die_ref context_die; | |
a3f97cbb | 7498 | { |
b3694847 SS |
7499 | enum tree_code code = TREE_CODE (type); |
7500 | dw_die_ref mod_type_die = NULL; | |
7501 | dw_die_ref sub_die = NULL; | |
7502 | tree item_type = NULL; | |
a3f97cbb JW |
7503 | |
7504 | if (code != ERROR_MARK) | |
7505 | { | |
5101b304 MM |
7506 | tree qualified_type; |
7507 | ||
7508 | /* See if we already have the appropriately qualified variant of | |
7509 | this type. */ | |
c26fbbca | 7510 | qualified_type |
5101b304 MM |
7511 | = get_qualified_type (type, |
7512 | ((is_const_type ? TYPE_QUAL_CONST : 0) | |
c26fbbca | 7513 | | (is_volatile_type |
5101b304 | 7514 | ? TYPE_QUAL_VOLATILE : 0))); |
2ad9852d | 7515 | |
5101b304 MM |
7516 | /* If we do, then we can just use its DIE, if it exists. */ |
7517 | if (qualified_type) | |
7518 | { | |
7519 | mod_type_die = lookup_type_die (qualified_type); | |
7520 | if (mod_type_die) | |
7521 | return mod_type_die; | |
7522 | } | |
bdb669cb | 7523 | |
556273e0 | 7524 | /* Handle C typedef types. */ |
c26fbbca | 7525 | if (qualified_type && TYPE_NAME (qualified_type) |
5101b304 MM |
7526 | && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL |
7527 | && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type))) | |
a94dbf2c | 7528 | { |
5101b304 MM |
7529 | tree type_name = TYPE_NAME (qualified_type); |
7530 | tree dtype = TREE_TYPE (type_name); | |
2ad9852d | 7531 | |
5101b304 | 7532 | if (qualified_type == dtype) |
a94dbf2c JM |
7533 | { |
7534 | /* For a named type, use the typedef. */ | |
5101b304 MM |
7535 | gen_type_die (qualified_type, context_die); |
7536 | mod_type_die = lookup_type_die (qualified_type); | |
a94dbf2c JM |
7537 | } |
7538 | else if (is_const_type < TYPE_READONLY (dtype) | |
7539 | || is_volatile_type < TYPE_VOLATILE (dtype)) | |
7540 | /* cv-unqualified version of named type. Just use the unnamed | |
7541 | type to which it refers. */ | |
71dfc51f | 7542 | mod_type_die |
5101b304 | 7543 | = modified_type_die (DECL_ORIGINAL_TYPE (type_name), |
71dfc51f RK |
7544 | is_const_type, is_volatile_type, |
7545 | context_die); | |
2ad9852d | 7546 | |
71dfc51f | 7547 | /* Else cv-qualified version of named type; fall through. */ |
a94dbf2c JM |
7548 | } |
7549 | ||
7550 | if (mod_type_die) | |
556273e0 KH |
7551 | /* OK. */ |
7552 | ; | |
a94dbf2c | 7553 | else if (is_const_type) |
a3f97cbb | 7554 | { |
54ba1f0d | 7555 | mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type); |
a9d38797 | 7556 | sub_die = modified_type_die (type, 0, is_volatile_type, context_die); |
a3f97cbb JW |
7557 | } |
7558 | else if (is_volatile_type) | |
7559 | { | |
54ba1f0d | 7560 | mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type); |
a9d38797 | 7561 | sub_die = modified_type_die (type, 0, 0, context_die); |
a3f97cbb JW |
7562 | } |
7563 | else if (code == POINTER_TYPE) | |
7564 | { | |
54ba1f0d | 7565 | mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type); |
a3f97cbb | 7566 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 7567 | #if 0 |
a3f97cbb | 7568 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
61b32c02 | 7569 | #endif |
a3f97cbb | 7570 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
7571 | } |
7572 | else if (code == REFERENCE_TYPE) | |
7573 | { | |
54ba1f0d | 7574 | mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type); |
a3f97cbb | 7575 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 7576 | #if 0 |
a3f97cbb | 7577 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
556273e0 | 7578 | #endif |
a3f97cbb | 7579 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
7580 | } |
7581 | else if (is_base_type (type)) | |
71dfc51f | 7582 | mod_type_die = base_type_die (type); |
a3f97cbb JW |
7583 | else |
7584 | { | |
4b674448 JM |
7585 | gen_type_die (type, context_die); |
7586 | ||
a3f97cbb JW |
7587 | /* We have to get the type_main_variant here (and pass that to the |
7588 | `lookup_type_die' routine) because the ..._TYPE node we have | |
7589 | might simply be a *copy* of some original type node (where the | |
7590 | copy was created to help us keep track of typedef names) and | |
7591 | that copy might have a different TYPE_UID from the original | |
a94dbf2c | 7592 | ..._TYPE node. */ |
0e98f924 AH |
7593 | if (TREE_CODE (type) != VECTOR_TYPE) |
7594 | mod_type_die = lookup_type_die (type_main_variant (type)); | |
7595 | else | |
7596 | /* Vectors have the debugging information in the type, | |
7597 | not the main variant. */ | |
7598 | mod_type_die = lookup_type_die (type); | |
3a88cbd1 JL |
7599 | if (mod_type_die == NULL) |
7600 | abort (); | |
a3f97cbb | 7601 | } |
3d2999ba MK |
7602 | |
7603 | /* We want to equate the qualified type to the die below. */ | |
7604 | if (qualified_type) | |
7605 | type = qualified_type; | |
a3f97cbb | 7606 | } |
71dfc51f | 7607 | |
dfcf9891 JW |
7608 | equate_type_number_to_die (type, mod_type_die); |
7609 | if (item_type) | |
71dfc51f RK |
7610 | /* We must do this after the equate_type_number_to_die call, in case |
7611 | this is a recursive type. This ensures that the modified_type_die | |
7612 | recursion will terminate even if the type is recursive. Recursive | |
7613 | types are possible in Ada. */ | |
7614 | sub_die = modified_type_die (item_type, | |
7615 | TYPE_READONLY (item_type), | |
7616 | TYPE_VOLATILE (item_type), | |
7617 | context_die); | |
7618 | ||
a3f97cbb | 7619 | if (sub_die != NULL) |
71dfc51f RK |
7620 | add_AT_die_ref (mod_type_die, DW_AT_type, sub_die); |
7621 | ||
a3f97cbb JW |
7622 | return mod_type_die; |
7623 | } | |
7624 | ||
a3f97cbb | 7625 | /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is |
6d2f8887 | 7626 | an enumerated type. */ |
71dfc51f RK |
7627 | |
7628 | static inline int | |
a3f97cbb | 7629 | type_is_enum (type) |
b3694847 | 7630 | tree type; |
a3f97cbb JW |
7631 | { |
7632 | return TREE_CODE (type) == ENUMERAL_TYPE; | |
7633 | } | |
7634 | ||
7d9d8943 AM |
7635 | /* Return the register number described by a given RTL node. */ |
7636 | ||
7637 | static unsigned int | |
7638 | reg_number (rtl) | |
b3694847 | 7639 | rtx rtl; |
7d9d8943 | 7640 | { |
b3694847 | 7641 | unsigned regno = REGNO (rtl); |
7d9d8943 AM |
7642 | |
7643 | if (regno >= FIRST_PSEUDO_REGISTER) | |
e7af1d45 | 7644 | abort (); |
7d9d8943 | 7645 | |
e7af1d45 | 7646 | return DBX_REGISTER_NUMBER (regno); |
7d9d8943 AM |
7647 | } |
7648 | ||
e7af1d45 RK |
7649 | /* Return a location descriptor that designates a machine register or |
7650 | zero if there is no such. */ | |
71dfc51f | 7651 | |
a3f97cbb JW |
7652 | static dw_loc_descr_ref |
7653 | reg_loc_descriptor (rtl) | |
b3694847 | 7654 | rtx rtl; |
a3f97cbb | 7655 | { |
b3694847 | 7656 | dw_loc_descr_ref loc_result = NULL; |
e7af1d45 | 7657 | unsigned reg; |
71dfc51f | 7658 | |
e7af1d45 RK |
7659 | if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER) |
7660 | return 0; | |
7661 | ||
7662 | reg = reg_number (rtl); | |
85066503 | 7663 | if (reg <= 31) |
71dfc51f | 7664 | loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0); |
a3f97cbb | 7665 | else |
71dfc51f RK |
7666 | loc_result = new_loc_descr (DW_OP_regx, reg, 0); |
7667 | ||
a3f97cbb JW |
7668 | return loc_result; |
7669 | } | |
7670 | ||
d8041cc8 RH |
7671 | /* Return a location descriptor that designates a constant. */ |
7672 | ||
7673 | static dw_loc_descr_ref | |
7674 | int_loc_descriptor (i) | |
7675 | HOST_WIDE_INT i; | |
7676 | { | |
7677 | enum dwarf_location_atom op; | |
7678 | ||
7679 | /* Pick the smallest representation of a constant, rather than just | |
7680 | defaulting to the LEB encoding. */ | |
7681 | if (i >= 0) | |
7682 | { | |
7683 | if (i <= 31) | |
7684 | op = DW_OP_lit0 + i; | |
7685 | else if (i <= 0xff) | |
7686 | op = DW_OP_const1u; | |
7687 | else if (i <= 0xffff) | |
7688 | op = DW_OP_const2u; | |
7689 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
7690 | || i <= 0xffffffff) | |
7691 | op = DW_OP_const4u; | |
7692 | else | |
7693 | op = DW_OP_constu; | |
7694 | } | |
7695 | else | |
7696 | { | |
7697 | if (i >= -0x80) | |
7698 | op = DW_OP_const1s; | |
7699 | else if (i >= -0x8000) | |
7700 | op = DW_OP_const2s; | |
7701 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
7702 | || i >= -0x80000000) | |
7703 | op = DW_OP_const4s; | |
7704 | else | |
7705 | op = DW_OP_consts; | |
7706 | } | |
7707 | ||
7708 | return new_loc_descr (op, i, 0); | |
7709 | } | |
7710 | ||
a3f97cbb | 7711 | /* Return a location descriptor that designates a base+offset location. */ |
71dfc51f | 7712 | |
a3f97cbb JW |
7713 | static dw_loc_descr_ref |
7714 | based_loc_descr (reg, offset) | |
7715 | unsigned reg; | |
7716 | long int offset; | |
7717 | { | |
b3694847 | 7718 | dw_loc_descr_ref loc_result; |
810429b7 JM |
7719 | /* For the "frame base", we use the frame pointer or stack pointer |
7720 | registers, since the RTL for local variables is relative to one of | |
7721 | them. */ | |
b3694847 SS |
7722 | unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed |
7723 | ? HARD_FRAME_POINTER_REGNUM | |
7724 | : STACK_POINTER_REGNUM); | |
71dfc51f | 7725 | |
a3f97cbb | 7726 | if (reg == fp_reg) |
71dfc51f | 7727 | loc_result = new_loc_descr (DW_OP_fbreg, offset, 0); |
85066503 | 7728 | else if (reg <= 31) |
71dfc51f | 7729 | loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0); |
a3f97cbb | 7730 | else |
71dfc51f RK |
7731 | loc_result = new_loc_descr (DW_OP_bregx, reg, offset); |
7732 | ||
a3f97cbb JW |
7733 | return loc_result; |
7734 | } | |
7735 | ||
7736 | /* Return true if this RTL expression describes a base+offset calculation. */ | |
71dfc51f RK |
7737 | |
7738 | static inline int | |
a3f97cbb | 7739 | is_based_loc (rtl) |
b3694847 | 7740 | rtx rtl; |
a3f97cbb | 7741 | { |
173bf5be KH |
7742 | return (GET_CODE (rtl) == PLUS |
7743 | && ((GET_CODE (XEXP (rtl, 0)) == REG | |
7744 | && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER | |
7745 | && GET_CODE (XEXP (rtl, 1)) == CONST_INT))); | |
a3f97cbb JW |
7746 | } |
7747 | ||
7748 | /* The following routine converts the RTL for a variable or parameter | |
7749 | (resident in memory) into an equivalent Dwarf representation of a | |
7750 | mechanism for getting the address of that same variable onto the top of a | |
7751 | hypothetical "address evaluation" stack. | |
71dfc51f | 7752 | |
a3f97cbb JW |
7753 | When creating memory location descriptors, we are effectively transforming |
7754 | the RTL for a memory-resident object into its Dwarf postfix expression | |
7755 | equivalent. This routine recursively descends an RTL tree, turning | |
e60d4d7b JL |
7756 | it into Dwarf postfix code as it goes. |
7757 | ||
7758 | MODE is the mode of the memory reference, needed to handle some | |
e7af1d45 RK |
7759 | autoincrement addressing modes. |
7760 | ||
7761 | Return 0 if we can't represent the location. */ | |
71dfc51f | 7762 | |
a3f97cbb | 7763 | static dw_loc_descr_ref |
e60d4d7b | 7764 | mem_loc_descriptor (rtl, mode) |
b3694847 | 7765 | rtx rtl; |
e60d4d7b | 7766 | enum machine_mode mode; |
a3f97cbb JW |
7767 | { |
7768 | dw_loc_descr_ref mem_loc_result = NULL; | |
e7af1d45 | 7769 | |
556273e0 | 7770 | /* Note that for a dynamically sized array, the location we will generate a |
a3f97cbb JW |
7771 | description of here will be the lowest numbered location which is |
7772 | actually within the array. That's *not* necessarily the same as the | |
7773 | zeroth element of the array. */ | |
71dfc51f | 7774 | |
1865dbb5 JM |
7775 | #ifdef ASM_SIMPLIFY_DWARF_ADDR |
7776 | rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); | |
7777 | #endif | |
7778 | ||
a3f97cbb JW |
7779 | switch (GET_CODE (rtl)) |
7780 | { | |
e60d4d7b JL |
7781 | case POST_INC: |
7782 | case POST_DEC: | |
e2134eea | 7783 | case POST_MODIFY: |
e60d4d7b JL |
7784 | /* POST_INC and POST_DEC can be handled just like a SUBREG. So we |
7785 | just fall into the SUBREG code. */ | |
7786 | ||
2ad9852d | 7787 | /* ... fall through ... */ |
e60d4d7b | 7788 | |
a3f97cbb JW |
7789 | case SUBREG: |
7790 | /* The case of a subreg may arise when we have a local (register) | |
7791 | variable or a formal (register) parameter which doesn't quite fill | |
7792 | up an entire register. For now, just assume that it is | |
7793 | legitimate to make the Dwarf info refer to the whole register which | |
7794 | contains the given subreg. */ | |
ddef6bc7 | 7795 | rtl = SUBREG_REG (rtl); |
71dfc51f | 7796 | |
2ad9852d | 7797 | /* ... fall through ... */ |
a3f97cbb JW |
7798 | |
7799 | case REG: | |
7800 | /* Whenever a register number forms a part of the description of the | |
7801 | method for calculating the (dynamic) address of a memory resident | |
556273e0 | 7802 | object, DWARF rules require the register number be referred to as |
a3f97cbb JW |
7803 | a "base register". This distinction is not based in any way upon |
7804 | what category of register the hardware believes the given register | |
7805 | belongs to. This is strictly DWARF terminology we're dealing with | |
7806 | here. Note that in cases where the location of a memory-resident | |
7807 | data object could be expressed as: OP_ADD (OP_BASEREG (basereg), | |
7808 | OP_CONST (0)) the actual DWARF location descriptor that we generate | |
7809 | may just be OP_BASEREG (basereg). This may look deceptively like | |
7810 | the object in question was allocated to a register (rather than in | |
7811 | memory) so DWARF consumers need to be aware of the subtle | |
7812 | distinction between OP_REG and OP_BASEREG. */ | |
e7af1d45 RK |
7813 | if (REGNO (rtl) < FIRST_PSEUDO_REGISTER) |
7814 | mem_loc_result = based_loc_descr (reg_number (rtl), 0); | |
a3f97cbb JW |
7815 | break; |
7816 | ||
7817 | case MEM: | |
f7d2b0ed | 7818 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
e7af1d45 RK |
7819 | if (mem_loc_result != 0) |
7820 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0)); | |
a3f97cbb JW |
7821 | break; |
7822 | ||
d8041cc8 RH |
7823 | case LABEL_REF: |
7824 | /* Some ports can transform a symbol ref into a label ref, because | |
368f4cd6 NC |
7825 | the symbol ref is too far away and has to be dumped into a constant |
7826 | pool. */ | |
a3f97cbb JW |
7827 | case CONST: |
7828 | case SYMBOL_REF: | |
6331d1c1 | 7829 | /* Alternatively, the symbol in the constant pool might be referenced |
c6f9b9a1 | 7830 | by a different symbol. */ |
2ad9852d | 7831 | if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl)) |
79cdfa4b | 7832 | { |
149d6f9e JJ |
7833 | bool marked; |
7834 | rtx tmp = get_pool_constant_mark (rtl, &marked); | |
2ad9852d | 7835 | |
6331d1c1 | 7836 | if (GET_CODE (tmp) == SYMBOL_REF) |
149d6f9e JJ |
7837 | { |
7838 | rtl = tmp; | |
7839 | if (CONSTANT_POOL_ADDRESS_P (tmp)) | |
7840 | get_pool_constant_mark (tmp, &marked); | |
7841 | else | |
7842 | marked = true; | |
7843 | } | |
7844 | ||
7845 | /* If all references to this pool constant were optimized away, | |
7846 | it was not output and thus we can't represent it. | |
7847 | FIXME: might try to use DW_OP_const_value here, though | |
7848 | DW_OP_piece complicates it. */ | |
7849 | if (!marked) | |
7850 | return 0; | |
79cdfa4b TM |
7851 | } |
7852 | ||
a3f97cbb JW |
7853 | mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0); |
7854 | mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
c470afad RK |
7855 | mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl; |
7856 | VARRAY_PUSH_RTX (used_rtx_varray, rtl); | |
a3f97cbb JW |
7857 | break; |
7858 | ||
e2134eea JH |
7859 | case PRE_MODIFY: |
7860 | /* Extract the PLUS expression nested inside and fall into | |
0407c02b | 7861 | PLUS code below. */ |
e2134eea JH |
7862 | rtl = XEXP (rtl, 1); |
7863 | goto plus; | |
7864 | ||
e60d4d7b JL |
7865 | case PRE_INC: |
7866 | case PRE_DEC: | |
7867 | /* Turn these into a PLUS expression and fall into the PLUS code | |
7868 | below. */ | |
7869 | rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0), | |
7870 | GEN_INT (GET_CODE (rtl) == PRE_INC | |
556273e0 KH |
7871 | ? GET_MODE_UNIT_SIZE (mode) |
7872 | : -GET_MODE_UNIT_SIZE (mode))); | |
7873 | ||
2ad9852d | 7874 | /* ... fall through ... */ |
e60d4d7b | 7875 | |
a3f97cbb | 7876 | case PLUS: |
e2134eea | 7877 | plus: |
a3f97cbb | 7878 | if (is_based_loc (rtl)) |
71dfc51f RK |
7879 | mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)), |
7880 | INTVAL (XEXP (rtl, 1))); | |
a3f97cbb JW |
7881 | else |
7882 | { | |
d8041cc8 | 7883 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode); |
e7af1d45 RK |
7884 | if (mem_loc_result == 0) |
7885 | break; | |
d8041cc8 RH |
7886 | |
7887 | if (GET_CODE (XEXP (rtl, 1)) == CONST_INT | |
7888 | && INTVAL (XEXP (rtl, 1)) >= 0) | |
e7af1d45 RK |
7889 | add_loc_descr (&mem_loc_result, |
7890 | new_loc_descr (DW_OP_plus_uconst, | |
7891 | INTVAL (XEXP (rtl, 1)), 0)); | |
d8041cc8 RH |
7892 | else |
7893 | { | |
7894 | add_loc_descr (&mem_loc_result, | |
7895 | mem_loc_descriptor (XEXP (rtl, 1), mode)); | |
7896 | add_loc_descr (&mem_loc_result, | |
7897 | new_loc_descr (DW_OP_plus, 0, 0)); | |
7898 | } | |
a3f97cbb JW |
7899 | } |
7900 | break; | |
7901 | ||
dd2478ae | 7902 | case MULT: |
e7af1d45 RK |
7903 | { |
7904 | /* If a pseudo-reg is optimized away, it is possible for it to | |
7905 | be replaced with a MEM containing a multiply. */ | |
7906 | dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode); | |
7907 | dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode); | |
7908 | ||
7909 | if (op0 == 0 || op1 == 0) | |
7910 | break; | |
7911 | ||
7912 | mem_loc_result = op0; | |
7913 | add_loc_descr (&mem_loc_result, op1); | |
7914 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0)); | |
7915 | break; | |
7916 | } | |
dd2478ae | 7917 | |
a3f97cbb | 7918 | case CONST_INT: |
d8041cc8 | 7919 | mem_loc_result = int_loc_descriptor (INTVAL (rtl)); |
a3f97cbb JW |
7920 | break; |
7921 | ||
a9e8a5ee RK |
7922 | case ADDRESSOF: |
7923 | /* If this is a MEM, return its address. Otherwise, we can't | |
7924 | represent this. */ | |
7925 | if (GET_CODE (XEXP (rtl, 0)) == MEM) | |
7926 | return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode); | |
7927 | else | |
7928 | return 0; | |
7929 | ||
a3f97cbb JW |
7930 | default: |
7931 | abort (); | |
7932 | } | |
71dfc51f | 7933 | |
a3f97cbb JW |
7934 | return mem_loc_result; |
7935 | } | |
7936 | ||
956d6950 | 7937 | /* Return a descriptor that describes the concatenation of two locations. |
4401bf24 JL |
7938 | This is typically a complex variable. */ |
7939 | ||
7940 | static dw_loc_descr_ref | |
7941 | concat_loc_descriptor (x0, x1) | |
b3694847 | 7942 | rtx x0, x1; |
4401bf24 JL |
7943 | { |
7944 | dw_loc_descr_ref cc_loc_result = NULL; | |
e7af1d45 RK |
7945 | dw_loc_descr_ref x0_ref = loc_descriptor (x0); |
7946 | dw_loc_descr_ref x1_ref = loc_descriptor (x1); | |
4401bf24 | 7947 | |
e7af1d45 RK |
7948 | if (x0_ref == 0 || x1_ref == 0) |
7949 | return 0; | |
7950 | ||
7951 | cc_loc_result = x0_ref; | |
4401bf24 | 7952 | add_loc_descr (&cc_loc_result, |
e7af1d45 RK |
7953 | new_loc_descr (DW_OP_piece, |
7954 | GET_MODE_SIZE (GET_MODE (x0)), 0)); | |
4401bf24 | 7955 | |
e7af1d45 | 7956 | add_loc_descr (&cc_loc_result, x1_ref); |
4401bf24 | 7957 | add_loc_descr (&cc_loc_result, |
e7af1d45 RK |
7958 | new_loc_descr (DW_OP_piece, |
7959 | GET_MODE_SIZE (GET_MODE (x1)), 0)); | |
4401bf24 JL |
7960 | |
7961 | return cc_loc_result; | |
7962 | } | |
7963 | ||
a3f97cbb JW |
7964 | /* Output a proper Dwarf location descriptor for a variable or parameter |
7965 | which is either allocated in a register or in a memory location. For a | |
7966 | register, we just generate an OP_REG and the register number. For a | |
7967 | memory location we provide a Dwarf postfix expression describing how to | |
e7af1d45 RK |
7968 | generate the (dynamic) address of the object onto the address stack. |
7969 | ||
7970 | If we don't know how to describe it, return 0. */ | |
71dfc51f | 7971 | |
a3f97cbb JW |
7972 | static dw_loc_descr_ref |
7973 | loc_descriptor (rtl) | |
b3694847 | 7974 | rtx rtl; |
a3f97cbb JW |
7975 | { |
7976 | dw_loc_descr_ref loc_result = NULL; | |
e7af1d45 | 7977 | |
a3f97cbb JW |
7978 | switch (GET_CODE (rtl)) |
7979 | { | |
7980 | case SUBREG: | |
a3f97cbb JW |
7981 | /* The case of a subreg may arise when we have a local (register) |
7982 | variable or a formal (register) parameter which doesn't quite fill | |
71dfc51f | 7983 | up an entire register. For now, just assume that it is |
a3f97cbb JW |
7984 | legitimate to make the Dwarf info refer to the whole register which |
7985 | contains the given subreg. */ | |
ddef6bc7 | 7986 | rtl = SUBREG_REG (rtl); |
71dfc51f | 7987 | |
2ad9852d | 7988 | /* ... fall through ... */ |
a3f97cbb JW |
7989 | |
7990 | case REG: | |
5c90448c | 7991 | loc_result = reg_loc_descriptor (rtl); |
a3f97cbb JW |
7992 | break; |
7993 | ||
7994 | case MEM: | |
e60d4d7b | 7995 | loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
a3f97cbb JW |
7996 | break; |
7997 | ||
4401bf24 JL |
7998 | case CONCAT: |
7999 | loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1)); | |
8000 | break; | |
8001 | ||
a3f97cbb | 8002 | default: |
71dfc51f | 8003 | abort (); |
a3f97cbb | 8004 | } |
71dfc51f | 8005 | |
a3f97cbb JW |
8006 | return loc_result; |
8007 | } | |
8008 | ||
2ad9852d RK |
8009 | /* Similar, but generate the descriptor from trees instead of rtl. This comes |
8010 | up particularly with variable length arrays. If ADDRESSP is nonzero, we are | |
8011 | looking for an address. Otherwise, we return a value. If we can't make a | |
8012 | descriptor, return 0. */ | |
d8041cc8 RH |
8013 | |
8014 | static dw_loc_descr_ref | |
8015 | loc_descriptor_from_tree (loc, addressp) | |
8016 | tree loc; | |
8017 | int addressp; | |
8018 | { | |
e7af1d45 RK |
8019 | dw_loc_descr_ref ret, ret1; |
8020 | int indirect_p = 0; | |
d8041cc8 RH |
8021 | int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc)); |
8022 | enum dwarf_location_atom op; | |
8023 | ||
8024 | /* ??? Most of the time we do not take proper care for sign/zero | |
8025 | extending the values properly. Hopefully this won't be a real | |
8026 | problem... */ | |
8027 | ||
8028 | switch (TREE_CODE (loc)) | |
8029 | { | |
8030 | case ERROR_MARK: | |
e7af1d45 | 8031 | return 0; |
d8041cc8 | 8032 | |
b4ae5201 | 8033 | case WITH_RECORD_EXPR: |
e7af1d45 | 8034 | case PLACEHOLDER_EXPR: |
b4ae5201 RK |
8035 | /* This case involves extracting fields from an object to determine the |
8036 | position of other fields. We don't try to encode this here. The | |
8037 | only user of this is Ada, which encodes the needed information using | |
8038 | the names of types. */ | |
e7af1d45 | 8039 | return 0; |
b4ae5201 | 8040 | |
aea9695c RK |
8041 | case CALL_EXPR: |
8042 | return 0; | |
8043 | ||
8044 | case ADDR_EXPR: | |
8045 | /* We can support this only if we can look through conversions and | |
8046 | find an INDIRECT_EXPR. */ | |
8047 | for (loc = TREE_OPERAND (loc, 0); | |
8048 | TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR | |
8049 | || TREE_CODE (loc) == NON_LVALUE_EXPR | |
8050 | || TREE_CODE (loc) == VIEW_CONVERT_EXPR | |
8051 | || TREE_CODE (loc) == SAVE_EXPR; | |
8052 | loc = TREE_OPERAND (loc, 0)) | |
8053 | ; | |
8054 | ||
8055 | return (TREE_CODE (loc) == INDIRECT_REF | |
8056 | ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp) | |
8057 | : 0); | |
8058 | ||
d8041cc8 RH |
8059 | case VAR_DECL: |
8060 | case PARM_DECL: | |
8061 | { | |
8062 | rtx rtl = rtl_for_decl_location (loc); | |
d8041cc8 | 8063 | |
a97c9600 | 8064 | if (rtl == NULL_RTX) |
e7af1d45 | 8065 | return 0; |
a97c9600 | 8066 | else if (CONSTANT_P (rtl)) |
d8041cc8 RH |
8067 | { |
8068 | ret = new_loc_descr (DW_OP_addr, 0, 0); | |
8069 | ret->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
8070 | ret->dw_loc_oprnd1.v.val_addr = rtl; | |
e7af1d45 | 8071 | indirect_p = 1; |
d8041cc8 RH |
8072 | } |
8073 | else | |
8074 | { | |
c28abdf0 RH |
8075 | enum machine_mode mode = GET_MODE (rtl); |
8076 | ||
d8041cc8 RH |
8077 | if (GET_CODE (rtl) == MEM) |
8078 | { | |
e7af1d45 | 8079 | indirect_p = 1; |
d8041cc8 RH |
8080 | rtl = XEXP (rtl, 0); |
8081 | } | |
2ad9852d | 8082 | |
d8041cc8 RH |
8083 | ret = mem_loc_descriptor (rtl, mode); |
8084 | } | |
8085 | } | |
8086 | break; | |
8087 | ||
8088 | case INDIRECT_REF: | |
8089 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 | 8090 | indirect_p = 1; |
d8041cc8 RH |
8091 | break; |
8092 | ||
749552c4 RK |
8093 | case COMPOUND_EXPR: |
8094 | return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp); | |
8095 | ||
ed972b14 RK |
8096 | case NOP_EXPR: |
8097 | case CONVERT_EXPR: | |
8098 | case NON_LVALUE_EXPR: | |
ed239f5a | 8099 | case VIEW_CONVERT_EXPR: |
b4ae5201 | 8100 | case SAVE_EXPR: |
ed972b14 | 8101 | return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp); |
e57cabac | 8102 | |
d8041cc8 RH |
8103 | case COMPONENT_REF: |
8104 | case BIT_FIELD_REF: | |
8105 | case ARRAY_REF: | |
b4e3fabb | 8106 | case ARRAY_RANGE_REF: |
d8041cc8 RH |
8107 | { |
8108 | tree obj, offset; | |
8109 | HOST_WIDE_INT bitsize, bitpos, bytepos; | |
8110 | enum machine_mode mode; | |
8111 | int volatilep; | |
d8041cc8 RH |
8112 | |
8113 | obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode, | |
a06ef755 | 8114 | &unsignedp, &volatilep); |
e7af1d45 RK |
8115 | |
8116 | if (obj == loc) | |
8117 | return 0; | |
8118 | ||
d8041cc8 | 8119 | ret = loc_descriptor_from_tree (obj, 1); |
e7af1d45 | 8120 | if (ret == 0 |
2ad9852d | 8121 | || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0) |
e7af1d45 | 8122 | return 0; |
d8041cc8 RH |
8123 | |
8124 | if (offset != NULL_TREE) | |
8125 | { | |
8126 | /* Variable offset. */ | |
8127 | add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0)); | |
8128 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
8129 | } | |
8130 | ||
e7af1d45 RK |
8131 | if (!addressp) |
8132 | indirect_p = 1; | |
d8041cc8 RH |
8133 | |
8134 | bytepos = bitpos / BITS_PER_UNIT; | |
8135 | if (bytepos > 0) | |
8136 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0)); | |
8137 | else if (bytepos < 0) | |
8138 | { | |
8139 | add_loc_descr (&ret, int_loc_descriptor (bytepos)); | |
8140 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
8141 | } | |
8142 | break; | |
8143 | } | |
8144 | ||
8145 | case INTEGER_CST: | |
8146 | if (host_integerp (loc, 0)) | |
8147 | ret = int_loc_descriptor (tree_low_cst (loc, 0)); | |
e7af1d45 RK |
8148 | else |
8149 | return 0; | |
d8041cc8 | 8150 | break; |
d8041cc8 | 8151 | |
c26fbbca | 8152 | case TRUTH_AND_EXPR: |
9702143f | 8153 | case TRUTH_ANDIF_EXPR: |
d8041cc8 RH |
8154 | case BIT_AND_EXPR: |
8155 | op = DW_OP_and; | |
8156 | goto do_binop; | |
e7af1d45 | 8157 | |
9702143f | 8158 | case TRUTH_XOR_EXPR: |
d8041cc8 RH |
8159 | case BIT_XOR_EXPR: |
8160 | op = DW_OP_xor; | |
8161 | goto do_binop; | |
e7af1d45 | 8162 | |
9702143f RK |
8163 | case TRUTH_OR_EXPR: |
8164 | case TRUTH_ORIF_EXPR: | |
d8041cc8 RH |
8165 | case BIT_IOR_EXPR: |
8166 | op = DW_OP_or; | |
8167 | goto do_binop; | |
e7af1d45 | 8168 | |
d8041cc8 RH |
8169 | case TRUNC_DIV_EXPR: |
8170 | op = DW_OP_div; | |
8171 | goto do_binop; | |
e7af1d45 | 8172 | |
d8041cc8 RH |
8173 | case MINUS_EXPR: |
8174 | op = DW_OP_minus; | |
8175 | goto do_binop; | |
e7af1d45 | 8176 | |
d8041cc8 RH |
8177 | case TRUNC_MOD_EXPR: |
8178 | op = DW_OP_mod; | |
8179 | goto do_binop; | |
e7af1d45 | 8180 | |
d8041cc8 RH |
8181 | case MULT_EXPR: |
8182 | op = DW_OP_mul; | |
8183 | goto do_binop; | |
e7af1d45 | 8184 | |
d8041cc8 RH |
8185 | case LSHIFT_EXPR: |
8186 | op = DW_OP_shl; | |
8187 | goto do_binop; | |
e7af1d45 | 8188 | |
d8041cc8 RH |
8189 | case RSHIFT_EXPR: |
8190 | op = (unsignedp ? DW_OP_shr : DW_OP_shra); | |
8191 | goto do_binop; | |
e7af1d45 | 8192 | |
d8041cc8 RH |
8193 | case PLUS_EXPR: |
8194 | if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST | |
8195 | && host_integerp (TREE_OPERAND (loc, 1), 0)) | |
8196 | { | |
8197 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8198 | if (ret == 0) |
8199 | return 0; | |
8200 | ||
d8041cc8 RH |
8201 | add_loc_descr (&ret, |
8202 | new_loc_descr (DW_OP_plus_uconst, | |
8203 | tree_low_cst (TREE_OPERAND (loc, 1), | |
8204 | 0), | |
8205 | 0)); | |
8206 | break; | |
8207 | } | |
e7af1d45 | 8208 | |
d8041cc8 RH |
8209 | op = DW_OP_plus; |
8210 | goto do_binop; | |
2ad9852d | 8211 | |
d8041cc8 RH |
8212 | case LE_EXPR: |
8213 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8214 | return 0; |
8215 | ||
d8041cc8 RH |
8216 | op = DW_OP_le; |
8217 | goto do_binop; | |
e7af1d45 | 8218 | |
d8041cc8 RH |
8219 | case GE_EXPR: |
8220 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8221 | return 0; |
8222 | ||
d8041cc8 RH |
8223 | op = DW_OP_ge; |
8224 | goto do_binop; | |
e7af1d45 | 8225 | |
d8041cc8 RH |
8226 | case LT_EXPR: |
8227 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8228 | return 0; |
8229 | ||
d8041cc8 RH |
8230 | op = DW_OP_lt; |
8231 | goto do_binop; | |
e7af1d45 | 8232 | |
d8041cc8 RH |
8233 | case GT_EXPR: |
8234 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
e7af1d45 RK |
8235 | return 0; |
8236 | ||
d8041cc8 RH |
8237 | op = DW_OP_gt; |
8238 | goto do_binop; | |
e7af1d45 | 8239 | |
d8041cc8 RH |
8240 | case EQ_EXPR: |
8241 | op = DW_OP_eq; | |
8242 | goto do_binop; | |
e7af1d45 | 8243 | |
d8041cc8 RH |
8244 | case NE_EXPR: |
8245 | op = DW_OP_ne; | |
8246 | goto do_binop; | |
8247 | ||
8248 | do_binop: | |
8249 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8250 | ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); |
8251 | if (ret == 0 || ret1 == 0) | |
8252 | return 0; | |
8253 | ||
8254 | add_loc_descr (&ret, ret1); | |
d8041cc8 RH |
8255 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); |
8256 | break; | |
8257 | ||
9702143f | 8258 | case TRUTH_NOT_EXPR: |
d8041cc8 RH |
8259 | case BIT_NOT_EXPR: |
8260 | op = DW_OP_not; | |
8261 | goto do_unop; | |
e7af1d45 | 8262 | |
d8041cc8 RH |
8263 | case ABS_EXPR: |
8264 | op = DW_OP_abs; | |
8265 | goto do_unop; | |
e7af1d45 | 8266 | |
d8041cc8 RH |
8267 | case NEGATE_EXPR: |
8268 | op = DW_OP_neg; | |
8269 | goto do_unop; | |
8270 | ||
8271 | do_unop: | |
8272 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8273 | if (ret == 0) |
8274 | return 0; | |
8275 | ||
d8041cc8 RH |
8276 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); |
8277 | break; | |
8278 | ||
8279 | case MAX_EXPR: | |
8280 | loc = build (COND_EXPR, TREE_TYPE (loc), | |
8281 | build (LT_EXPR, integer_type_node, | |
8282 | TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)), | |
8283 | TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0)); | |
2ad9852d | 8284 | |
3ef42a0c | 8285 | /* ... fall through ... */ |
d8041cc8 RH |
8286 | |
8287 | case COND_EXPR: | |
8288 | { | |
e7af1d45 RK |
8289 | dw_loc_descr_ref lhs |
8290 | = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); | |
8291 | dw_loc_descr_ref rhs | |
8292 | = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0); | |
d8041cc8 RH |
8293 | dw_loc_descr_ref bra_node, jump_node, tmp; |
8294 | ||
8295 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
e7af1d45 RK |
8296 | if (ret == 0 || lhs == 0 || rhs == 0) |
8297 | return 0; | |
8298 | ||
d8041cc8 RH |
8299 | bra_node = new_loc_descr (DW_OP_bra, 0, 0); |
8300 | add_loc_descr (&ret, bra_node); | |
8301 | ||
e7af1d45 | 8302 | add_loc_descr (&ret, rhs); |
d8041cc8 RH |
8303 | jump_node = new_loc_descr (DW_OP_skip, 0, 0); |
8304 | add_loc_descr (&ret, jump_node); | |
8305 | ||
e7af1d45 | 8306 | add_loc_descr (&ret, lhs); |
d8041cc8 | 8307 | bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc; |
e7af1d45 | 8308 | bra_node->dw_loc_oprnd1.v.val_loc = lhs; |
d8041cc8 RH |
8309 | |
8310 | /* ??? Need a node to point the skip at. Use a nop. */ | |
8311 | tmp = new_loc_descr (DW_OP_nop, 0, 0); | |
8312 | add_loc_descr (&ret, tmp); | |
8313 | jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc; | |
8314 | jump_node->dw_loc_oprnd1.v.val_loc = tmp; | |
8315 | } | |
8316 | break; | |
8317 | ||
8318 | default: | |
8319 | abort (); | |
8320 | } | |
8321 | ||
e7af1d45 RK |
8322 | /* Show if we can't fill the request for an address. */ |
8323 | if (addressp && indirect_p == 0) | |
8324 | return 0; | |
d8041cc8 RH |
8325 | |
8326 | /* If we've got an address and don't want one, dereference. */ | |
e7af1d45 | 8327 | if (!addressp && indirect_p > 0) |
d8041cc8 | 8328 | { |
e7af1d45 RK |
8329 | HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc)); |
8330 | ||
8331 | if (size > DWARF2_ADDR_SIZE || size == -1) | |
8332 | return 0; | |
2ad9852d | 8333 | else if (size == DWARF2_ADDR_SIZE) |
d8041cc8 RH |
8334 | op = DW_OP_deref; |
8335 | else | |
8336 | op = DW_OP_deref_size; | |
e7af1d45 RK |
8337 | |
8338 | add_loc_descr (&ret, new_loc_descr (op, size, 0)); | |
d8041cc8 RH |
8339 | } |
8340 | ||
8341 | return ret; | |
8342 | } | |
8343 | ||
665f2503 | 8344 | /* Given a value, round it up to the lowest multiple of `boundary' |
a3f97cbb | 8345 | which is not less than the value itself. */ |
71dfc51f | 8346 | |
665f2503 | 8347 | static inline HOST_WIDE_INT |
a3f97cbb | 8348 | ceiling (value, boundary) |
665f2503 RK |
8349 | HOST_WIDE_INT value; |
8350 | unsigned int boundary; | |
a3f97cbb JW |
8351 | { |
8352 | return (((value + boundary - 1) / boundary) * boundary); | |
8353 | } | |
8354 | ||
8355 | /* Given a pointer to what is assumed to be a FIELD_DECL node, return a | |
8356 | pointer to the declared type for the relevant field variable, or return | |
8357 | `integer_type_node' if the given node turns out to be an | |
8358 | ERROR_MARK node. */ | |
71dfc51f RK |
8359 | |
8360 | static inline tree | |
a3f97cbb | 8361 | field_type (decl) |
b3694847 | 8362 | tree decl; |
a3f97cbb | 8363 | { |
b3694847 | 8364 | tree type; |
a3f97cbb JW |
8365 | |
8366 | if (TREE_CODE (decl) == ERROR_MARK) | |
8367 | return integer_type_node; | |
8368 | ||
8369 | type = DECL_BIT_FIELD_TYPE (decl); | |
71dfc51f | 8370 | if (type == NULL_TREE) |
a3f97cbb JW |
8371 | type = TREE_TYPE (decl); |
8372 | ||
8373 | return type; | |
8374 | } | |
8375 | ||
5f446d21 DD |
8376 | /* Given a pointer to a tree node, return the alignment in bits for |
8377 | it, or else return BITS_PER_WORD if the node actually turns out to | |
8378 | be an ERROR_MARK node. */ | |
71dfc51f RK |
8379 | |
8380 | static inline unsigned | |
a3f97cbb | 8381 | simple_type_align_in_bits (type) |
b3694847 | 8382 | tree type; |
a3f97cbb JW |
8383 | { |
8384 | return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; | |
8385 | } | |
8386 | ||
5f446d21 DD |
8387 | static inline unsigned |
8388 | simple_decl_align_in_bits (decl) | |
b3694847 | 8389 | tree decl; |
5f446d21 DD |
8390 | { |
8391 | return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD; | |
8392 | } | |
8393 | ||
a3f97cbb JW |
8394 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE |
8395 | node, return the size in bits for the type if it is a constant, or else | |
8396 | return the alignment for the type if the type's size is not constant, or | |
8397 | else return BITS_PER_WORD if the type actually turns out to be an | |
8398 | ERROR_MARK node. */ | |
71dfc51f | 8399 | |
665f2503 | 8400 | static inline unsigned HOST_WIDE_INT |
a3f97cbb | 8401 | simple_type_size_in_bits (type) |
b3694847 | 8402 | tree type; |
a3f97cbb | 8403 | { |
3df18884 | 8404 | |
a3f97cbb JW |
8405 | if (TREE_CODE (type) == ERROR_MARK) |
8406 | return BITS_PER_WORD; | |
2ad9852d | 8407 | else if (TYPE_SIZE (type) == NULL_TREE) |
3df18884 | 8408 | return 0; |
2ad9852d RK |
8409 | else if (host_integerp (TYPE_SIZE (type), 1)) |
8410 | return tree_low_cst (TYPE_SIZE (type), 1); | |
8411 | else | |
3df18884 | 8412 | return TYPE_ALIGN (type); |
a3f97cbb JW |
8413 | } |
8414 | ||
2ad9852d RK |
8415 | /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the |
8416 | lowest addressed byte of the "containing object" for the given FIELD_DECL, | |
8417 | or return 0 if we are unable to determine what that offset is, either | |
8418 | because the argument turns out to be a pointer to an ERROR_MARK node, or | |
8419 | because the offset is actually variable. (We can't handle the latter case | |
8420 | just yet). */ | |
71dfc51f | 8421 | |
665f2503 | 8422 | static HOST_WIDE_INT |
a3f97cbb | 8423 | field_byte_offset (decl) |
b3694847 | 8424 | tree decl; |
a3f97cbb | 8425 | { |
665f2503 | 8426 | unsigned int type_align_in_bits; |
5f446d21 | 8427 | unsigned int decl_align_in_bits; |
665f2503 | 8428 | unsigned HOST_WIDE_INT type_size_in_bits; |
665f2503 | 8429 | HOST_WIDE_INT object_offset_in_bits; |
665f2503 RK |
8430 | tree type; |
8431 | tree field_size_tree; | |
8432 | HOST_WIDE_INT bitpos_int; | |
8433 | HOST_WIDE_INT deepest_bitpos; | |
8434 | unsigned HOST_WIDE_INT field_size_in_bits; | |
a3f97cbb JW |
8435 | |
8436 | if (TREE_CODE (decl) == ERROR_MARK) | |
8437 | return 0; | |
2ad9852d | 8438 | else if (TREE_CODE (decl) != FIELD_DECL) |
a3f97cbb JW |
8439 | abort (); |
8440 | ||
8441 | type = field_type (decl); | |
a3f97cbb JW |
8442 | field_size_tree = DECL_SIZE (decl); |
8443 | ||
3df18884 RH |
8444 | /* The size could be unspecified if there was an error, or for |
8445 | a flexible array member. */ | |
50352c9c | 8446 | if (! field_size_tree) |
3df18884 | 8447 | field_size_tree = bitsize_zero_node; |
50352c9c | 8448 | |
556273e0 | 8449 | /* We cannot yet cope with fields whose positions are variable, so |
a3f97cbb JW |
8450 | for now, when we see such things, we simply return 0. Someday, we may |
8451 | be able to handle such cases, but it will be damn difficult. */ | |
665f2503 | 8452 | if (! host_integerp (bit_position (decl), 0)) |
a3f97cbb | 8453 | return 0; |
14a774a9 | 8454 | |
665f2503 | 8455 | bitpos_int = int_bit_position (decl); |
a3f97cbb | 8456 | |
3df18884 | 8457 | /* If we don't know the size of the field, pretend it's a full word. */ |
665f2503 RK |
8458 | if (host_integerp (field_size_tree, 1)) |
8459 | field_size_in_bits = tree_low_cst (field_size_tree, 1); | |
14a774a9 RK |
8460 | else |
8461 | field_size_in_bits = BITS_PER_WORD; | |
a3f97cbb JW |
8462 | |
8463 | type_size_in_bits = simple_type_size_in_bits (type); | |
a3f97cbb | 8464 | type_align_in_bits = simple_type_align_in_bits (type); |
5f446d21 | 8465 | decl_align_in_bits = simple_decl_align_in_bits (decl); |
a3f97cbb | 8466 | |
2ad9852d RK |
8467 | /* The GCC front-end doesn't make any attempt to keep track of the starting |
8468 | bit offset (relative to the start of the containing structure type) of the | |
8469 | hypothetical "containing object" for a bit-field. Thus, when computing | |
8470 | the byte offset value for the start of the "containing object" of a | |
8471 | bit-field, we must deduce this information on our own. This can be rather | |
8472 | tricky to do in some cases. For example, handling the following structure | |
8473 | type definition when compiling for an i386/i486 target (which only aligns | |
8474 | long long's to 32-bit boundaries) can be very tricky: | |
a3f97cbb JW |
8475 | |
8476 | struct S { int field1; long long field2:31; }; | |
8477 | ||
2ad9852d RK |
8478 | Fortunately, there is a simple rule-of-thumb which can be used in such |
8479 | cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the | |
8480 | structure shown above. It decides to do this based upon one simple rule | |
8481 | for bit-field allocation. GCC allocates each "containing object" for each | |
8482 | bit-field at the first (i.e. lowest addressed) legitimate alignment | |
8483 | boundary (based upon the required minimum alignment for the declared type | |
8484 | of the field) which it can possibly use, subject to the condition that | |
8485 | there is still enough available space remaining in the containing object | |
8486 | (when allocated at the selected point) to fully accommodate all of the | |
8487 | bits of the bit-field itself. | |
8488 | ||
8489 | This simple rule makes it obvious why GCC allocates 8 bytes for each | |
8490 | object of the structure type shown above. When looking for a place to | |
8491 | allocate the "containing object" for `field2', the compiler simply tries | |
8492 | to allocate a 64-bit "containing object" at each successive 32-bit | |
8493 | boundary (starting at zero) until it finds a place to allocate that 64- | |
8494 | bit field such that at least 31 contiguous (and previously unallocated) | |
8495 | bits remain within that selected 64 bit field. (As it turns out, for the | |
8496 | example above, the compiler finds it is OK to allocate the "containing | |
8497 | object" 64-bit field at bit-offset zero within the structure type.) | |
8498 | ||
8499 | Here we attempt to work backwards from the limited set of facts we're | |
8500 | given, and we try to deduce from those facts, where GCC must have believed | |
8501 | that the containing object started (within the structure type). The value | |
8502 | we deduce is then used (by the callers of this routine) to generate | |
8503 | DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields | |
8504 | and, in the case of DW_AT_location, regular fields as well). */ | |
a3f97cbb JW |
8505 | |
8506 | /* Figure out the bit-distance from the start of the structure to the | |
8507 | "deepest" bit of the bit-field. */ | |
8508 | deepest_bitpos = bitpos_int + field_size_in_bits; | |
8509 | ||
8510 | /* This is the tricky part. Use some fancy footwork to deduce where the | |
8511 | lowest addressed bit of the containing object must be. */ | |
5f446d21 DD |
8512 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; |
8513 | ||
8514 | /* Round up to type_align by default. This works best for bitfields. */ | |
8515 | object_offset_in_bits += type_align_in_bits - 1; | |
8516 | object_offset_in_bits /= type_align_in_bits; | |
8517 | object_offset_in_bits *= type_align_in_bits; | |
a3f97cbb | 8518 | |
5f446d21 DD |
8519 | if (object_offset_in_bits > bitpos_int) |
8520 | { | |
8521 | /* Sigh, the decl must be packed. */ | |
8522 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; | |
8523 | ||
8524 | /* Round up to decl_align instead. */ | |
8525 | object_offset_in_bits += decl_align_in_bits - 1; | |
8526 | object_offset_in_bits /= decl_align_in_bits; | |
8527 | object_offset_in_bits *= decl_align_in_bits; | |
8528 | } | |
a3f97cbb | 8529 | |
2ad9852d | 8530 | return object_offset_in_bits / BITS_PER_UNIT; |
a3f97cbb | 8531 | } |
a3f97cbb | 8532 | \f |
71dfc51f RK |
8533 | /* The following routines define various Dwarf attributes and any data |
8534 | associated with them. */ | |
a3f97cbb | 8535 | |
ef76d03b | 8536 | /* Add a location description attribute value to a DIE. |
a3f97cbb | 8537 | |
ef76d03b | 8538 | This emits location attributes suitable for whole variables and |
a3f97cbb JW |
8539 | whole parameters. Note that the location attributes for struct fields are |
8540 | generated by the routine `data_member_location_attribute' below. */ | |
71dfc51f | 8541 | |
a3f97cbb | 8542 | static void |
ef76d03b | 8543 | add_AT_location_description (die, attr_kind, rtl) |
a3f97cbb | 8544 | dw_die_ref die; |
ef76d03b | 8545 | enum dwarf_attribute attr_kind; |
b3694847 | 8546 | rtx rtl; |
a3f97cbb | 8547 | { |
e7af1d45 | 8548 | dw_loc_descr_ref descr = loc_descriptor (rtl); |
a3f97cbb | 8549 | |
e7af1d45 RK |
8550 | if (descr != 0) |
8551 | add_AT_loc (die, attr_kind, descr); | |
a3f97cbb JW |
8552 | } |
8553 | ||
2ad9852d RK |
8554 | /* Attach the specialized form of location attribute used for data members of |
8555 | struct and union types. In the special case of a FIELD_DECL node which | |
8556 | represents a bit-field, the "offset" part of this special location | |
8557 | descriptor must indicate the distance in bytes from the lowest-addressed | |
8558 | byte of the containing struct or union type to the lowest-addressed byte of | |
8559 | the "containing object" for the bit-field. (See the `field_byte_offset' | |
8560 | function above). | |
8561 | ||
8562 | For any given bit-field, the "containing object" is a hypothetical object | |
8563 | (of some integral or enum type) within which the given bit-field lives. The | |
8564 | type of this hypothetical "containing object" is always the same as the | |
8565 | declared type of the individual bit-field itself (for GCC anyway... the | |
8566 | DWARF spec doesn't actually mandate this). Note that it is the size (in | |
8567 | bytes) of the hypothetical "containing object" which will be given in the | |
8568 | DW_AT_byte_size attribute for this bit-field. (See the | |
8569 | `byte_size_attribute' function below.) It is also used when calculating the | |
8570 | value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute' | |
8571 | function below.) */ | |
71dfc51f | 8572 | |
a3f97cbb JW |
8573 | static void |
8574 | add_data_member_location_attribute (die, decl) | |
b3694847 SS |
8575 | dw_die_ref die; |
8576 | tree decl; | |
a3f97cbb | 8577 | { |
649ce3f2 JM |
8578 | long offset; |
8579 | dw_loc_descr_ref loc_descr = 0; | |
a3f97cbb | 8580 | |
61b32c02 | 8581 | if (TREE_CODE (decl) == TREE_VEC) |
649ce3f2 JM |
8582 | { |
8583 | /* We're working on the TAG_inheritance for a base class. */ | |
1d3d6b1e | 8584 | if (TREE_VIA_VIRTUAL (decl) && is_cxx ()) |
649ce3f2 JM |
8585 | { |
8586 | /* For C++ virtual bases we can't just use BINFO_OFFSET, as they | |
8587 | aren't at a fixed offset from all (sub)objects of the same | |
8588 | type. We need to extract the appropriate offset from our | |
8589 | vtable. The following dwarf expression means | |
8590 | ||
8591 | BaseAddr = ObAddr + *((*ObAddr) - Offset) | |
8592 | ||
8593 | This is specific to the V3 ABI, of course. */ | |
8594 | ||
8595 | dw_loc_descr_ref tmp; | |
2ad9852d | 8596 | |
649ce3f2 JM |
8597 | /* Make a copy of the object address. */ |
8598 | tmp = new_loc_descr (DW_OP_dup, 0, 0); | |
8599 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 8600 | |
649ce3f2 JM |
8601 | /* Extract the vtable address. */ |
8602 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
8603 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 8604 | |
649ce3f2 JM |
8605 | /* Calculate the address of the offset. */ |
8606 | offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0); | |
8607 | if (offset >= 0) | |
8608 | abort (); | |
2ad9852d | 8609 | |
649ce3f2 JM |
8610 | tmp = int_loc_descriptor (-offset); |
8611 | add_loc_descr (&loc_descr, tmp); | |
8612 | tmp = new_loc_descr (DW_OP_minus, 0, 0); | |
8613 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 8614 | |
649ce3f2 JM |
8615 | /* Extract the offset. */ |
8616 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
8617 | add_loc_descr (&loc_descr, tmp); | |
2ad9852d | 8618 | |
649ce3f2 JM |
8619 | /* Add it to the object address. */ |
8620 | tmp = new_loc_descr (DW_OP_plus, 0, 0); | |
8621 | add_loc_descr (&loc_descr, tmp); | |
8622 | } | |
8623 | else | |
8624 | offset = tree_low_cst (BINFO_OFFSET (decl), 0); | |
8625 | } | |
61b32c02 JM |
8626 | else |
8627 | offset = field_byte_offset (decl); | |
8628 | ||
649ce3f2 JM |
8629 | if (! loc_descr) |
8630 | { | |
8631 | enum dwarf_location_atom op; | |
8632 | ||
2ad9852d RK |
8633 | /* The DWARF2 standard says that we should assume that the structure |
8634 | address is already on the stack, so we can specify a structure field | |
8635 | address by using DW_OP_plus_uconst. */ | |
71dfc51f | 8636 | |
a3f97cbb | 8637 | #ifdef MIPS_DEBUGGING_INFO |
2ad9852d RK |
8638 | /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst |
8639 | operator correctly. It works only if we leave the offset on the | |
8640 | stack. */ | |
649ce3f2 | 8641 | op = DW_OP_constu; |
a3f97cbb | 8642 | #else |
649ce3f2 | 8643 | op = DW_OP_plus_uconst; |
a3f97cbb | 8644 | #endif |
71dfc51f | 8645 | |
649ce3f2 JM |
8646 | loc_descr = new_loc_descr (op, offset, 0); |
8647 | } | |
2ad9852d | 8648 | |
a3f97cbb JW |
8649 | add_AT_loc (die, DW_AT_data_member_location, loc_descr); |
8650 | } | |
8651 | ||
8652 | /* Attach an DW_AT_const_value attribute for a variable or a parameter which | |
8653 | does not have a "location" either in memory or in a register. These | |
8654 | things can arise in GNU C when a constant is passed as an actual parameter | |
8655 | to an inlined function. They can also arise in C++ where declared | |
8656 | constants do not necessarily get memory "homes". */ | |
71dfc51f | 8657 | |
a3f97cbb JW |
8658 | static void |
8659 | add_const_value_attribute (die, rtl) | |
b3694847 SS |
8660 | dw_die_ref die; |
8661 | rtx rtl; | |
a3f97cbb JW |
8662 | { |
8663 | switch (GET_CODE (rtl)) | |
8664 | { | |
8665 | case CONST_INT: | |
2e4b9b8c RH |
8666 | /* Note that a CONST_INT rtx could represent either an integer |
8667 | or a floating-point constant. A CONST_INT is used whenever | |
8668 | the constant will fit into a single word. In all such | |
8669 | cases, the original mode of the constant value is wiped | |
8670 | out, and the CONST_INT rtx is assigned VOIDmode. */ | |
8671 | { | |
8672 | HOST_WIDE_INT val = INTVAL (rtl); | |
c26fbbca | 8673 | |
2e4b9b8c | 8674 | /* ??? We really should be using HOST_WIDE_INT throughout. */ |
5929a2f0 | 8675 | if (val < 0 && (long) val == val) |
3d7a191f | 8676 | add_AT_int (die, DW_AT_const_value, (long) val); |
5929a2f0 RH |
8677 | else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val) |
8678 | add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val); | |
94784fb9 RK |
8679 | else |
8680 | { | |
e7af1d45 | 8681 | #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT |
94784fb9 RK |
8682 | add_AT_long_long (die, DW_AT_const_value, |
8683 | val >> HOST_BITS_PER_LONG, val); | |
e7af1d45 | 8684 | #else |
94784fb9 | 8685 | abort (); |
e7af1d45 | 8686 | #endif |
94784fb9 | 8687 | } |
2e4b9b8c | 8688 | } |
a3f97cbb JW |
8689 | break; |
8690 | ||
8691 | case CONST_DOUBLE: | |
8692 | /* Note that a CONST_DOUBLE rtx could represent either an integer or a | |
8693 | floating-point constant. A CONST_DOUBLE is used whenever the | |
8694 | constant requires more than one word in order to be adequately | |
469ac993 JM |
8695 | represented. We output CONST_DOUBLEs as blocks. */ |
8696 | { | |
b3694847 | 8697 | enum machine_mode mode = GET_MODE (rtl); |
469ac993 JM |
8698 | |
8699 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
8700 | { | |
b3694847 | 8701 | unsigned length = GET_MODE_SIZE (mode) / 4; |
c26fbbca | 8702 | long *array = (long *) xmalloc (sizeof (long) * length); |
71dfc51f | 8703 | REAL_VALUE_TYPE rv; |
469ac993 | 8704 | |
71dfc51f | 8705 | REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl); |
469ac993 JM |
8706 | switch (mode) |
8707 | { | |
8708 | case SFmode: | |
71dfc51f | 8709 | REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]); |
469ac993 JM |
8710 | break; |
8711 | ||
8712 | case DFmode: | |
71dfc51f | 8713 | REAL_VALUE_TO_TARGET_DOUBLE (rv, array); |
469ac993 JM |
8714 | break; |
8715 | ||
8716 | case XFmode: | |
8717 | case TFmode: | |
71dfc51f | 8718 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array); |
469ac993 JM |
8719 | break; |
8720 | ||
8721 | default: | |
8722 | abort (); | |
8723 | } | |
8724 | ||
469ac993 JM |
8725 | add_AT_float (die, DW_AT_const_value, length, array); |
8726 | } | |
8727 | else | |
2e4b9b8c RH |
8728 | { |
8729 | /* ??? We really should be using HOST_WIDE_INT throughout. */ | |
8730 | if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT) | |
8731 | abort (); | |
2ad9852d | 8732 | |
2e4b9b8c RH |
8733 | add_AT_long_long (die, DW_AT_const_value, |
8734 | CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl)); | |
8735 | } | |
469ac993 | 8736 | } |
a3f97cbb JW |
8737 | break; |
8738 | ||
8739 | case CONST_STRING: | |
8740 | add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0)); | |
8741 | break; | |
8742 | ||
8743 | case SYMBOL_REF: | |
8744 | case LABEL_REF: | |
8745 | case CONST: | |
c470afad RK |
8746 | add_AT_addr (die, DW_AT_const_value, rtl); |
8747 | VARRAY_PUSH_RTX (used_rtx_varray, rtl); | |
a3f97cbb JW |
8748 | break; |
8749 | ||
8750 | case PLUS: | |
8751 | /* In cases where an inlined instance of an inline function is passed | |
8752 | the address of an `auto' variable (which is local to the caller) we | |
8753 | can get a situation where the DECL_RTL of the artificial local | |
8754 | variable (for the inlining) which acts as a stand-in for the | |
8755 | corresponding formal parameter (of the inline function) will look | |
8756 | like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not | |
556273e0 KH |
8757 | exactly a compile-time constant expression, but it isn't the address |
8758 | of the (artificial) local variable either. Rather, it represents the | |
a3f97cbb | 8759 | *value* which the artificial local variable always has during its |
556273e0 | 8760 | lifetime. We currently have no way to represent such quasi-constant |
6a7a9f01 | 8761 | values in Dwarf, so for now we just punt and generate nothing. */ |
a3f97cbb JW |
8762 | break; |
8763 | ||
8764 | default: | |
8765 | /* No other kinds of rtx should be possible here. */ | |
8766 | abort (); | |
8767 | } | |
8768 | ||
8769 | } | |
8770 | ||
d8041cc8 RH |
8771 | static rtx |
8772 | rtl_for_decl_location (decl) | |
8773 | tree decl; | |
a3f97cbb | 8774 | { |
b3694847 | 8775 | rtx rtl; |
71dfc51f | 8776 | |
a3f97cbb JW |
8777 | /* Here we have to decide where we are going to say the parameter "lives" |
8778 | (as far as the debugger is concerned). We only have a couple of | |
8779 | choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. | |
71dfc51f | 8780 | |
556273e0 | 8781 | DECL_RTL normally indicates where the parameter lives during most of the |
71dfc51f | 8782 | activation of the function. If optimization is enabled however, this |
556273e0 | 8783 | could be either NULL or else a pseudo-reg. Both of those cases indicate |
a3f97cbb JW |
8784 | that the parameter doesn't really live anywhere (as far as the code |
8785 | generation parts of GCC are concerned) during most of the function's | |
8786 | activation. That will happen (for example) if the parameter is never | |
71dfc51f RK |
8787 | referenced within the function. |
8788 | ||
8789 | We could just generate a location descriptor here for all non-NULL | |
8790 | non-pseudo values of DECL_RTL and ignore all of the rest, but we can be | |
8791 | a little nicer than that if we also consider DECL_INCOMING_RTL in cases | |
8792 | where DECL_RTL is NULL or is a pseudo-reg. | |
8793 | ||
8794 | Note however that we can only get away with using DECL_INCOMING_RTL as | |
8795 | a backup substitute for DECL_RTL in certain limited cases. In cases | |
8796 | where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl), | |
8797 | we can be sure that the parameter was passed using the same type as it is | |
8798 | declared to have within the function, and that its DECL_INCOMING_RTL | |
8799 | points us to a place where a value of that type is passed. | |
8800 | ||
8801 | In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different, | |
8802 | we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL | |
8803 | because in these cases DECL_INCOMING_RTL points us to a value of some | |
8804 | type which is *different* from the type of the parameter itself. Thus, | |
8805 | if we tried to use DECL_INCOMING_RTL to generate a location attribute in | |
8806 | such cases, the debugger would end up (for example) trying to fetch a | |
8807 | `float' from a place which actually contains the first part of a | |
8808 | `double'. That would lead to really incorrect and confusing | |
8809 | output at debug-time. | |
8810 | ||
8811 | So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL | |
8812 | in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There | |
8813 | are a couple of exceptions however. On little-endian machines we can | |
8814 | get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is | |
8815 | not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is | |
8816 | an integral type that is smaller than TREE_TYPE (decl). These cases arise | |
8817 | when (on a little-endian machine) a non-prototyped function has a | |
8818 | parameter declared to be of type `short' or `char'. In such cases, | |
8819 | TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will | |
8820 | be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the | |
8821 | passed `int' value. If the debugger then uses that address to fetch | |
8822 | a `short' or a `char' (on a little-endian machine) the result will be | |
8823 | the correct data, so we allow for such exceptional cases below. | |
8824 | ||
8825 | Note that our goal here is to describe the place where the given formal | |
2ad9852d RK |
8826 | parameter lives during most of the function's activation (i.e. between the |
8827 | end of the prologue and the start of the epilogue). We'll do that as best | |
8828 | as we can. Note however that if the given formal parameter is modified | |
8829 | sometime during the execution of the function, then a stack backtrace (at | |
8830 | debug-time) will show the function as having been called with the *new* | |
8831 | value rather than the value which was originally passed in. This happens | |
8832 | rarely enough that it is not a major problem, but it *is* a problem, and | |
8833 | I'd like to fix it. | |
8834 | ||
8835 | A future version of dwarf2out.c may generate two additional attributes for | |
8836 | any given DW_TAG_formal_parameter DIE which will describe the "passed | |
8837 | type" and the "passed location" for the given formal parameter in addition | |
8838 | to the attributes we now generate to indicate the "declared type" and the | |
8839 | "active location" for each parameter. This additional set of attributes | |
8840 | could be used by debuggers for stack backtraces. Separately, note that | |
8841 | sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also. | |
8842 | This happens (for example) for inlined-instances of inline function formal | |
8843 | parameters which are never referenced. This really shouldn't be | |
8844 | happening. All PARM_DECL nodes should get valid non-NULL | |
8845 | DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these | |
8846 | values for inlined instances of inline function parameters, so when we see | |
8847 | such cases, we are just out-of-luck for the time being (until integrate.c | |
a3f97cbb JW |
8848 | gets fixed). */ |
8849 | ||
8850 | /* Use DECL_RTL as the "location" unless we find something better. */ | |
110c3568 | 8851 | rtl = DECL_RTL_IF_SET (decl); |
a3f97cbb | 8852 | |
c28abdf0 RH |
8853 | /* When generating abstract instances, ignore everything except |
8854 | constants and symbols living in memory. */ | |
8855 | if (! reload_completed) | |
8856 | { | |
8857 | if (rtl | |
8858 | && (CONSTANT_P (rtl) | |
8859 | || (GET_CODE (rtl) == MEM | |
8860 | && CONSTANT_P (XEXP (rtl, 0))))) | |
4c8c0dec JJ |
8861 | { |
8862 | #ifdef ASM_SIMPLIFY_DWARF_ADDR | |
8863 | rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); | |
8864 | #endif | |
8865 | return rtl; | |
8866 | } | |
c28abdf0 RH |
8867 | rtl = NULL_RTX; |
8868 | } | |
8869 | else if (TREE_CODE (decl) == PARM_DECL) | |
a3f97cbb JW |
8870 | { |
8871 | if (rtl == NULL_RTX || is_pseudo_reg (rtl)) | |
8872 | { | |
d8041cc8 RH |
8873 | tree declared_type = type_main_variant (TREE_TYPE (decl)); |
8874 | tree passed_type = type_main_variant (DECL_ARG_TYPE (decl)); | |
a3f97cbb | 8875 | |
71dfc51f | 8876 | /* This decl represents a formal parameter which was optimized out. |
a3f97cbb | 8877 | Note that DECL_INCOMING_RTL may be NULL in here, but we handle |
2ad9852d | 8878 | all cases where (rtl == NULL_RTX) just below. */ |
a3f97cbb | 8879 | if (declared_type == passed_type) |
71dfc51f RK |
8880 | rtl = DECL_INCOMING_RTL (decl); |
8881 | else if (! BYTES_BIG_ENDIAN | |
8882 | && TREE_CODE (declared_type) == INTEGER_TYPE | |
555b6442 HPN |
8883 | && (GET_MODE_SIZE (TYPE_MODE (declared_type)) |
8884 | <= GET_MODE_SIZE (TYPE_MODE (passed_type)))) | |
556273e0 | 8885 | rtl = DECL_INCOMING_RTL (decl); |
a3f97cbb | 8886 | } |
5a904a61 JW |
8887 | |
8888 | /* If the parm was passed in registers, but lives on the stack, then | |
8889 | make a big endian correction if the mode of the type of the | |
8890 | parameter is not the same as the mode of the rtl. */ | |
8891 | /* ??? This is the same series of checks that are made in dbxout.c before | |
8892 | we reach the big endian correction code there. It isn't clear if all | |
8893 | of these checks are necessary here, but keeping them all is the safe | |
8894 | thing to do. */ | |
8895 | else if (GET_CODE (rtl) == MEM | |
8896 | && XEXP (rtl, 0) != const0_rtx | |
8897 | && ! CONSTANT_P (XEXP (rtl, 0)) | |
8898 | /* Not passed in memory. */ | |
8899 | && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM | |
8900 | /* Not passed by invisible reference. */ | |
8901 | && (GET_CODE (XEXP (rtl, 0)) != REG | |
8902 | || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM | |
8903 | || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM | |
8904 | #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM | |
8905 | || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM | |
8906 | #endif | |
8907 | ) | |
8908 | /* Big endian correction check. */ | |
8909 | && BYTES_BIG_ENDIAN | |
8910 | && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl) | |
8911 | && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))) | |
8912 | < UNITS_PER_WORD)) | |
8913 | { | |
8914 | int offset = (UNITS_PER_WORD | |
8915 | - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))); | |
2ad9852d | 8916 | |
5a904a61 JW |
8917 | rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)), |
8918 | plus_constant (XEXP (rtl, 0), offset)); | |
8919 | } | |
a3f97cbb | 8920 | } |
71dfc51f | 8921 | |
d8041cc8 RH |
8922 | if (rtl != NULL_RTX) |
8923 | { | |
8924 | rtl = eliminate_regs (rtl, 0, NULL_RTX); | |
6a7a9f01 | 8925 | #ifdef LEAF_REG_REMAP |
d8041cc8 RH |
8926 | if (current_function_uses_only_leaf_regs) |
8927 | leaf_renumber_regs_insn (rtl); | |
6a7a9f01 | 8928 | #endif |
d8041cc8 RH |
8929 | } |
8930 | ||
2ad9852d RK |
8931 | /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant, |
8932 | and will have been substituted directly into all expressions that use it. | |
8933 | C does not have such a concept, but C++ and other languages do. */ | |
c28abdf0 | 8934 | else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl)) |
6d73371a JJ |
8935 | { |
8936 | /* If a variable is initialized with a string constant without embedded | |
8937 | zeros, build CONST_STRING. */ | |
8938 | if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST | |
8939 | && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) | |
8940 | { | |
8941 | tree arrtype = TREE_TYPE (decl); | |
8942 | tree enttype = TREE_TYPE (arrtype); | |
8943 | tree domain = TYPE_DOMAIN (arrtype); | |
8944 | tree init = DECL_INITIAL (decl); | |
8945 | enum machine_mode mode = TYPE_MODE (enttype); | |
8946 | ||
8947 | if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1 | |
8948 | && domain | |
8949 | && integer_zerop (TYPE_MIN_VALUE (domain)) | |
8950 | && compare_tree_int (TYPE_MAX_VALUE (domain), | |
8951 | TREE_STRING_LENGTH (init) - 1) == 0 | |
8952 | && ((size_t) TREE_STRING_LENGTH (init) | |
8953 | == strlen (TREE_STRING_POINTER (init)) + 1)) | |
8954 | rtl = gen_rtx_CONST_STRING (VOIDmode, TREE_STRING_POINTER (init)); | |
8955 | } | |
29b91443 JM |
8956 | /* If the initializer is something that we know will expand into an |
8957 | immediate RTL constant, expand it now. Expanding anything else | |
8958 | tends to produce unresolved symbols; see debug/5770 and c++/6381. */ | |
8959 | else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST | |
8960 | || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST) | |
6d73371a JJ |
8961 | { |
8962 | rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode, | |
8963 | EXPAND_INITIALIZER); | |
29b91443 | 8964 | /* If expand_expr returns a MEM, it wasn't immediate. */ |
6d73371a | 8965 | if (rtl && GET_CODE (rtl) == MEM) |
29b91443 | 8966 | abort (); |
6d73371a JJ |
8967 | } |
8968 | } | |
8063ddcf | 8969 | |
4c8c0dec JJ |
8970 | #ifdef ASM_SIMPLIFY_DWARF_ADDR |
8971 | if (rtl) | |
8972 | rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); | |
8973 | #endif | |
d8041cc8 RH |
8974 | return rtl; |
8975 | } | |
8976 | ||
8977 | /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value | |
8978 | data attribute for a variable or a parameter. We generate the | |
8979 | DW_AT_const_value attribute only in those cases where the given variable | |
8980 | or parameter does not have a true "location" either in memory or in a | |
8981 | register. This can happen (for example) when a constant is passed as an | |
8982 | actual argument in a call to an inline function. (It's possible that | |
8983 | these things can crop up in other ways also.) Note that one type of | |
8984 | constant value which can be passed into an inlined function is a constant | |
8985 | pointer. This can happen for example if an actual argument in an inlined | |
8986 | function call evaluates to a compile-time constant address. */ | |
8987 | ||
8988 | static void | |
8989 | add_location_or_const_value_attribute (die, decl) | |
b3694847 SS |
8990 | dw_die_ref die; |
8991 | tree decl; | |
d8041cc8 | 8992 | { |
b3694847 | 8993 | rtx rtl; |
d8041cc8 RH |
8994 | |
8995 | if (TREE_CODE (decl) == ERROR_MARK) | |
8996 | return; | |
2ad9852d | 8997 | else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL) |
d8041cc8 RH |
8998 | abort (); |
8999 | ||
9000 | rtl = rtl_for_decl_location (decl); | |
a97c9600 RH |
9001 | if (rtl == NULL_RTX) |
9002 | return; | |
6a7a9f01 | 9003 | |
732910b9 RH |
9004 | /* If we don't look past the constant pool, we risk emitting a |
9005 | reference to a constant pool entry that isn't referenced from | |
9006 | code, and thus is not emitted. */ | |
9007 | rtl = avoid_constant_pool_reference (rtl); | |
9008 | ||
a3f97cbb JW |
9009 | switch (GET_CODE (rtl)) |
9010 | { | |
e9a25f70 JL |
9011 | case ADDRESSOF: |
9012 | /* The address of a variable that was optimized away; don't emit | |
9013 | anything. */ | |
9014 | break; | |
9015 | ||
a3f97cbb JW |
9016 | case CONST_INT: |
9017 | case CONST_DOUBLE: | |
9018 | case CONST_STRING: | |
9019 | case SYMBOL_REF: | |
9020 | case LABEL_REF: | |
9021 | case CONST: | |
9022 | case PLUS: | |
9023 | /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ | |
9024 | add_const_value_attribute (die, rtl); | |
9025 | break; | |
9026 | ||
9027 | case MEM: | |
9028 | case REG: | |
9029 | case SUBREG: | |
4401bf24 | 9030 | case CONCAT: |
ef76d03b | 9031 | add_AT_location_description (die, DW_AT_location, rtl); |
a3f97cbb JW |
9032 | break; |
9033 | ||
9034 | default: | |
71dfc51f | 9035 | abort (); |
a3f97cbb JW |
9036 | } |
9037 | } | |
9038 | ||
1bfb5f8f JM |
9039 | /* If we don't have a copy of this variable in memory for some reason (such |
9040 | as a C++ member constant that doesn't have an out-of-line definition), | |
9041 | we should tell the debugger about the constant value. */ | |
9042 | ||
9043 | static void | |
9044 | tree_add_const_value_attribute (var_die, decl) | |
9045 | dw_die_ref var_die; | |
9046 | tree decl; | |
9047 | { | |
9048 | tree init = DECL_INITIAL (decl); | |
9049 | tree type = TREE_TYPE (decl); | |
9050 | ||
9051 | if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init | |
9052 | && initializer_constant_valid_p (init, type) == null_pointer_node) | |
9053 | /* OK */; | |
9054 | else | |
9055 | return; | |
9056 | ||
9057 | switch (TREE_CODE (type)) | |
9058 | { | |
9059 | case INTEGER_TYPE: | |
9060 | if (host_integerp (init, 0)) | |
9061 | add_AT_unsigned (var_die, DW_AT_const_value, | |
2ad9852d | 9062 | tree_low_cst (init, 0)); |
1bfb5f8f JM |
9063 | else |
9064 | add_AT_long_long (var_die, DW_AT_const_value, | |
9065 | TREE_INT_CST_HIGH (init), | |
9066 | TREE_INT_CST_LOW (init)); | |
9067 | break; | |
9068 | ||
9069 | default:; | |
9070 | } | |
9071 | } | |
0b34cf1e | 9072 | |
a3f97cbb JW |
9073 | /* Generate an DW_AT_name attribute given some string value to be included as |
9074 | the value of the attribute. */ | |
71dfc51f RK |
9075 | |
9076 | static inline void | |
a3f97cbb | 9077 | add_name_attribute (die, name_string) |
b3694847 SS |
9078 | dw_die_ref die; |
9079 | const char *name_string; | |
a3f97cbb | 9080 | { |
71dfc51f | 9081 | if (name_string != NULL && *name_string != 0) |
14a774a9 RK |
9082 | { |
9083 | if (demangle_name_func) | |
9084 | name_string = (*demangle_name_func) (name_string); | |
9085 | ||
9086 | add_AT_string (die, DW_AT_name, name_string); | |
9087 | } | |
a3f97cbb JW |
9088 | } |
9089 | ||
9090 | /* Given a tree node describing an array bound (either lower or upper) output | |
466446b0 | 9091 | a representation for that bound. */ |
71dfc51f | 9092 | |
a3f97cbb JW |
9093 | static void |
9094 | add_bound_info (subrange_die, bound_attr, bound) | |
b3694847 SS |
9095 | dw_die_ref subrange_die; |
9096 | enum dwarf_attribute bound_attr; | |
9097 | tree bound; | |
a3f97cbb | 9098 | { |
a3f97cbb JW |
9099 | switch (TREE_CODE (bound)) |
9100 | { | |
9101 | case ERROR_MARK: | |
9102 | return; | |
9103 | ||
3ef42a0c | 9104 | /* All fixed-bounds are represented by INTEGER_CST nodes. */ |
a3f97cbb | 9105 | case INTEGER_CST: |
665f2503 RK |
9106 | if (! host_integerp (bound, 0) |
9107 | || (bound_attr == DW_AT_lower_bound | |
28985b81 | 9108 | && (((is_c_family () || is_java ()) && integer_zerop (bound)) |
665f2503 RK |
9109 | || (is_fortran () && integer_onep (bound))))) |
9110 | /* use the default */ | |
9111 | ; | |
141719a8 | 9112 | else |
665f2503 | 9113 | add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0)); |
a3f97cbb JW |
9114 | break; |
9115 | ||
b1ccbc24 | 9116 | case CONVERT_EXPR: |
a3f97cbb | 9117 | case NOP_EXPR: |
b1ccbc24 | 9118 | case NON_LVALUE_EXPR: |
ed239f5a | 9119 | case VIEW_CONVERT_EXPR: |
b1ccbc24 RK |
9120 | add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0)); |
9121 | break; | |
556273e0 | 9122 | |
a3f97cbb JW |
9123 | case SAVE_EXPR: |
9124 | /* If optimization is turned on, the SAVE_EXPRs that describe how to | |
466446b0 JM |
9125 | access the upper bound values may be bogus. If they refer to a |
9126 | register, they may only describe how to get at these values at the | |
9127 | points in the generated code right after they have just been | |
9128 | computed. Worse yet, in the typical case, the upper bound values | |
9129 | will not even *be* computed in the optimized code (though the | |
9130 | number of elements will), so these SAVE_EXPRs are entirely | |
9131 | bogus. In order to compensate for this fact, we check here to see | |
9132 | if optimization is enabled, and if so, we don't add an attribute | |
9133 | for the (unknown and unknowable) upper bound. This should not | |
9134 | cause too much trouble for existing (stupid?) debuggers because | |
9135 | they have to deal with empty upper bounds location descriptions | |
9136 | anyway in order to be able to deal with incomplete array types. | |
9137 | Of course an intelligent debugger (GDB?) should be able to | |
4fe9b91c | 9138 | comprehend that a missing upper bound specification in an array |
466446b0 JM |
9139 | type used for a storage class `auto' local array variable |
9140 | indicates that the upper bound is both unknown (at compile- time) | |
9141 | and unknowable (at run-time) due to optimization. | |
9142 | ||
9143 | We assume that a MEM rtx is safe because gcc wouldn't put the | |
9144 | value there unless it was going to be used repeatedly in the | |
9145 | function, i.e. for cleanups. */ | |
1edf43d6 JM |
9146 | if (SAVE_EXPR_RTL (bound) |
9147 | && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)) | |
a3f97cbb | 9148 | { |
b3694847 | 9149 | dw_die_ref ctx = lookup_decl_die (current_function_decl); |
54ba1f0d | 9150 | dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound); |
b3694847 | 9151 | rtx loc = SAVE_EXPR_RTL (bound); |
f5963e61 JL |
9152 | |
9153 | /* If the RTL for the SAVE_EXPR is memory, handle the case where | |
9154 | it references an outer function's frame. */ | |
f5963e61 JL |
9155 | if (GET_CODE (loc) == MEM) |
9156 | { | |
9157 | rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound); | |
9158 | ||
9159 | if (XEXP (loc, 0) != new_addr) | |
c5c76735 | 9160 | loc = gen_rtx_MEM (GET_MODE (loc), new_addr); |
f5963e61 JL |
9161 | } |
9162 | ||
466446b0 JM |
9163 | add_AT_flag (decl_die, DW_AT_artificial, 1); |
9164 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
f5963e61 | 9165 | add_AT_location_description (decl_die, DW_AT_location, loc); |
466446b0 | 9166 | add_AT_die_ref (subrange_die, bound_attr, decl_die); |
a3f97cbb | 9167 | } |
71dfc51f RK |
9168 | |
9169 | /* Else leave out the attribute. */ | |
a3f97cbb | 9170 | break; |
3f76745e | 9171 | |
ef76d03b | 9172 | case VAR_DECL: |
d8041cc8 RH |
9173 | case PARM_DECL: |
9174 | { | |
9175 | dw_die_ref decl_die = lookup_decl_die (bound); | |
9176 | ||
9177 | /* ??? Can this happen, or should the variable have been bound | |
9178 | first? Probably it can, since I imagine that we try to create | |
9179 | the types of parameters in the order in which they exist in | |
0b34cf1e | 9180 | the list, and won't have created a forward reference to a |
d8041cc8 RH |
9181 | later parameter. */ |
9182 | if (decl_die != NULL) | |
9183 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
9184 | break; | |
9185 | } | |
ef76d03b | 9186 | |
3f76745e | 9187 | default: |
d8041cc8 RH |
9188 | { |
9189 | /* Otherwise try to create a stack operation procedure to | |
9190 | evaluate the value of the array bound. */ | |
9191 | ||
9192 | dw_die_ref ctx, decl_die; | |
9193 | dw_loc_descr_ref loc; | |
9194 | ||
9195 | loc = loc_descriptor_from_tree (bound, 0); | |
9196 | if (loc == NULL) | |
9197 | break; | |
9198 | ||
e7af1d45 RK |
9199 | if (current_function_decl == 0) |
9200 | ctx = comp_unit_die; | |
9201 | else | |
9202 | ctx = lookup_decl_die (current_function_decl); | |
d8041cc8 | 9203 | |
aea9695c RK |
9204 | /* If we weren't able to find a context, it's most likely the case |
9205 | that we are processing the return type of the function. So | |
9206 | make a SAVE_EXPR to point to it and have the limbo DIE code | |
9207 | find the proper die. The save_expr function doesn't always | |
9208 | make a SAVE_EXPR, so do it ourselves. */ | |
9209 | if (ctx == 0) | |
9210 | bound = build (SAVE_EXPR, TREE_TYPE (bound), bound, | |
9211 | current_function_decl, NULL_TREE); | |
9212 | ||
54ba1f0d | 9213 | decl_die = new_die (DW_TAG_variable, ctx, bound); |
d8041cc8 RH |
9214 | add_AT_flag (decl_die, DW_AT_artificial, 1); |
9215 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
9216 | add_AT_loc (decl_die, DW_AT_location, loc); | |
9217 | ||
9218 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
9219 | break; | |
9220 | } | |
a3f97cbb JW |
9221 | } |
9222 | } | |
9223 | ||
9224 | /* Note that the block of subscript information for an array type also | |
9225 | includes information about the element type of type given array type. */ | |
71dfc51f | 9226 | |
a3f97cbb JW |
9227 | static void |
9228 | add_subscript_info (type_die, type) | |
b3694847 SS |
9229 | dw_die_ref type_die; |
9230 | tree type; | |
a3f97cbb | 9231 | { |
081f5e7e | 9232 | #ifndef MIPS_DEBUGGING_INFO |
b3694847 | 9233 | unsigned dimension_number; |
081f5e7e | 9234 | #endif |
b3694847 SS |
9235 | tree lower, upper; |
9236 | dw_die_ref subrange_die; | |
a3f97cbb | 9237 | |
556273e0 | 9238 | /* The GNU compilers represent multidimensional array types as sequences of |
a3f97cbb JW |
9239 | one dimensional array types whose element types are themselves array |
9240 | types. Here we squish that down, so that each multidimensional array | |
556273e0 | 9241 | type gets only one array_type DIE in the Dwarf debugging info. The draft |
a3f97cbb JW |
9242 | Dwarf specification say that we are allowed to do this kind of |
9243 | compression in C (because there is no difference between an array or | |
556273e0 | 9244 | arrays and a multidimensional array in C) but for other source languages |
a3f97cbb | 9245 | (e.g. Ada) we probably shouldn't do this. */ |
71dfc51f | 9246 | |
a3f97cbb JW |
9247 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
9248 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
9249 | We work around this by disabling this feature. See also | |
9250 | gen_array_type_die. */ | |
9251 | #ifndef MIPS_DEBUGGING_INFO | |
9252 | for (dimension_number = 0; | |
9253 | TREE_CODE (type) == ARRAY_TYPE; | |
9254 | type = TREE_TYPE (type), dimension_number++) | |
a3f97cbb | 9255 | #endif |
2ad9852d | 9256 | { |
b3694847 | 9257 | tree domain = TYPE_DOMAIN (type); |
a3f97cbb JW |
9258 | |
9259 | /* Arrays come in three flavors: Unspecified bounds, fixed bounds, | |
556273e0 | 9260 | and (in GNU C only) variable bounds. Handle all three forms |
a3f97cbb | 9261 | here. */ |
54ba1f0d | 9262 | subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL); |
a3f97cbb JW |
9263 | if (domain) |
9264 | { | |
9265 | /* We have an array type with specified bounds. */ | |
9266 | lower = TYPE_MIN_VALUE (domain); | |
9267 | upper = TYPE_MAX_VALUE (domain); | |
9268 | ||
a9d38797 JM |
9269 | /* define the index type. */ |
9270 | if (TREE_TYPE (domain)) | |
ef76d03b JW |
9271 | { |
9272 | /* ??? This is probably an Ada unnamed subrange type. Ignore the | |
9273 | TREE_TYPE field. We can't emit debug info for this | |
9274 | because it is an unnamed integral type. */ | |
9275 | if (TREE_CODE (domain) == INTEGER_TYPE | |
9276 | && TYPE_NAME (domain) == NULL_TREE | |
9277 | && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE | |
9278 | && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE) | |
556273e0 | 9279 | ; |
ef76d03b JW |
9280 | else |
9281 | add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0, | |
9282 | type_die); | |
9283 | } | |
a9d38797 | 9284 | |
e1ee5cdc RH |
9285 | /* ??? If upper is NULL, the array has unspecified length, |
9286 | but it does have a lower bound. This happens with Fortran | |
9287 | dimension arr(N:*) | |
9288 | Since the debugger is definitely going to need to know N | |
9289 | to produce useful results, go ahead and output the lower | |
9290 | bound solo, and hope the debugger can cope. */ | |
9291 | ||
141719a8 | 9292 | add_bound_info (subrange_die, DW_AT_lower_bound, lower); |
e1ee5cdc RH |
9293 | if (upper) |
9294 | add_bound_info (subrange_die, DW_AT_upper_bound, upper); | |
a3f97cbb | 9295 | } |
71dfc51f | 9296 | |
2ad9852d RK |
9297 | /* Otherwise we have an array type with an unspecified length. The |
9298 | DWARF-2 spec does not say how to handle this; let's just leave out the | |
9299 | bounds. */ | |
a3f97cbb | 9300 | } |
a3f97cbb JW |
9301 | } |
9302 | ||
9303 | static void | |
9304 | add_byte_size_attribute (die, tree_node) | |
9305 | dw_die_ref die; | |
b3694847 | 9306 | tree tree_node; |
a3f97cbb | 9307 | { |
b3694847 | 9308 | unsigned size; |
a3f97cbb JW |
9309 | |
9310 | switch (TREE_CODE (tree_node)) | |
9311 | { | |
9312 | case ERROR_MARK: | |
9313 | size = 0; | |
9314 | break; | |
9315 | case ENUMERAL_TYPE: | |
9316 | case RECORD_TYPE: | |
9317 | case UNION_TYPE: | |
9318 | case QUAL_UNION_TYPE: | |
9319 | size = int_size_in_bytes (tree_node); | |
9320 | break; | |
9321 | case FIELD_DECL: | |
9322 | /* For a data member of a struct or union, the DW_AT_byte_size is | |
9323 | generally given as the number of bytes normally allocated for an | |
9324 | object of the *declared* type of the member itself. This is true | |
9325 | even for bit-fields. */ | |
9326 | size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT; | |
9327 | break; | |
9328 | default: | |
9329 | abort (); | |
9330 | } | |
9331 | ||
9332 | /* Note that `size' might be -1 when we get to this point. If it is, that | |
9333 | indicates that the byte size of the entity in question is variable. We | |
9334 | have no good way of expressing this fact in Dwarf at the present time, | |
9335 | so just let the -1 pass on through. */ | |
a3f97cbb JW |
9336 | add_AT_unsigned (die, DW_AT_byte_size, size); |
9337 | } | |
9338 | ||
9339 | /* For a FIELD_DECL node which represents a bit-field, output an attribute | |
9340 | which specifies the distance in bits from the highest order bit of the | |
9341 | "containing object" for the bit-field to the highest order bit of the | |
9342 | bit-field itself. | |
9343 | ||
2ad9852d RK |
9344 | For any given bit-field, the "containing object" is a hypothetical object |
9345 | (of some integral or enum type) within which the given bit-field lives. The | |
9346 | type of this hypothetical "containing object" is always the same as the | |
9347 | declared type of the individual bit-field itself. The determination of the | |
9348 | exact location of the "containing object" for a bit-field is rather | |
9349 | complicated. It's handled by the `field_byte_offset' function (above). | |
a3f97cbb JW |
9350 | |
9351 | Note that it is the size (in bytes) of the hypothetical "containing object" | |
9352 | which will be given in the DW_AT_byte_size attribute for this bit-field. | |
9353 | (See `byte_size_attribute' above). */ | |
71dfc51f RK |
9354 | |
9355 | static inline void | |
a3f97cbb | 9356 | add_bit_offset_attribute (die, decl) |
b3694847 SS |
9357 | dw_die_ref die; |
9358 | tree decl; | |
a3f97cbb | 9359 | { |
665f2503 RK |
9360 | HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl); |
9361 | tree type = DECL_BIT_FIELD_TYPE (decl); | |
9362 | HOST_WIDE_INT bitpos_int; | |
9363 | HOST_WIDE_INT highest_order_object_bit_offset; | |
9364 | HOST_WIDE_INT highest_order_field_bit_offset; | |
9365 | HOST_WIDE_INT unsigned bit_offset; | |
a3f97cbb | 9366 | |
3a88cbd1 JL |
9367 | /* Must be a field and a bit field. */ |
9368 | if (!type | |
9369 | || TREE_CODE (decl) != FIELD_DECL) | |
9370 | abort (); | |
a3f97cbb JW |
9371 | |
9372 | /* We can't yet handle bit-fields whose offsets are variable, so if we | |
9373 | encounter such things, just return without generating any attribute | |
665f2503 RK |
9374 | whatsoever. Likewise for variable or too large size. */ |
9375 | if (! host_integerp (bit_position (decl), 0) | |
9376 | || ! host_integerp (DECL_SIZE (decl), 1)) | |
71dfc51f RK |
9377 | return; |
9378 | ||
665f2503 | 9379 | bitpos_int = int_bit_position (decl); |
a3f97cbb JW |
9380 | |
9381 | /* Note that the bit offset is always the distance (in bits) from the | |
556273e0 KH |
9382 | highest-order bit of the "containing object" to the highest-order bit of |
9383 | the bit-field itself. Since the "high-order end" of any object or field | |
a3f97cbb JW |
9384 | is different on big-endian and little-endian machines, the computation |
9385 | below must take account of these differences. */ | |
9386 | highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; | |
9387 | highest_order_field_bit_offset = bitpos_int; | |
9388 | ||
71dfc51f | 9389 | if (! BYTES_BIG_ENDIAN) |
a3f97cbb | 9390 | { |
665f2503 | 9391 | highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0); |
a3f97cbb JW |
9392 | highest_order_object_bit_offset += simple_type_size_in_bits (type); |
9393 | } | |
71dfc51f RK |
9394 | |
9395 | bit_offset | |
9396 | = (! BYTES_BIG_ENDIAN | |
9397 | ? highest_order_object_bit_offset - highest_order_field_bit_offset | |
9398 | : highest_order_field_bit_offset - highest_order_object_bit_offset); | |
a3f97cbb JW |
9399 | |
9400 | add_AT_unsigned (die, DW_AT_bit_offset, bit_offset); | |
9401 | } | |
9402 | ||
9403 | /* For a FIELD_DECL node which represents a bit field, output an attribute | |
9404 | which specifies the length in bits of the given field. */ | |
71dfc51f RK |
9405 | |
9406 | static inline void | |
a3f97cbb | 9407 | add_bit_size_attribute (die, decl) |
b3694847 SS |
9408 | dw_die_ref die; |
9409 | tree decl; | |
a3f97cbb | 9410 | { |
3a88cbd1 JL |
9411 | /* Must be a field and a bit field. */ |
9412 | if (TREE_CODE (decl) != FIELD_DECL | |
9413 | || ! DECL_BIT_FIELD_TYPE (decl)) | |
9414 | abort (); | |
665f2503 RK |
9415 | |
9416 | if (host_integerp (DECL_SIZE (decl), 1)) | |
9417 | add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1)); | |
a3f97cbb JW |
9418 | } |
9419 | ||
88dad228 | 9420 | /* If the compiled language is ANSI C, then add a 'prototyped' |
a3f97cbb | 9421 | attribute, if arg types are given for the parameters of a function. */ |
71dfc51f RK |
9422 | |
9423 | static inline void | |
a3f97cbb | 9424 | add_prototyped_attribute (die, func_type) |
b3694847 SS |
9425 | dw_die_ref die; |
9426 | tree func_type; | |
a3f97cbb | 9427 | { |
88dad228 JM |
9428 | if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89 |
9429 | && TYPE_ARG_TYPES (func_type) != NULL) | |
9430 | add_AT_flag (die, DW_AT_prototyped, 1); | |
a3f97cbb JW |
9431 | } |
9432 | ||
a3f97cbb JW |
9433 | /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found |
9434 | by looking in either the type declaration or object declaration | |
9435 | equate table. */ | |
71dfc51f RK |
9436 | |
9437 | static inline void | |
a3f97cbb | 9438 | add_abstract_origin_attribute (die, origin) |
b3694847 SS |
9439 | dw_die_ref die; |
9440 | tree origin; | |
a3f97cbb JW |
9441 | { |
9442 | dw_die_ref origin_die = NULL; | |
bbc6ae08 | 9443 | |
d10b8e05 | 9444 | if (TREE_CODE (origin) != FUNCTION_DECL) |
e40a1c67 JM |
9445 | { |
9446 | /* We may have gotten separated from the block for the inlined | |
9447 | function, if we're in an exception handler or some such; make | |
9448 | sure that the abstract function has been written out. | |
9449 | ||
9450 | Doing this for nested functions is wrong, however; functions are | |
9451 | distinct units, and our context might not even be inline. */ | |
fb13d4d0 | 9452 | tree fn = origin; |
2ad9852d | 9453 | |
fb13d4d0 JM |
9454 | if (TYPE_P (fn)) |
9455 | fn = TYPE_STUB_DECL (fn); | |
2ad9852d | 9456 | |
fb13d4d0 | 9457 | fn = decl_function_context (fn); |
e40a1c67 | 9458 | if (fn) |
1edf43d6 | 9459 | dwarf2out_abstract_function (fn); |
e40a1c67 | 9460 | } |
44db1d9c | 9461 | |
2f939d94 | 9462 | if (DECL_P (origin)) |
71dfc51f | 9463 | origin_die = lookup_decl_die (origin); |
2f939d94 | 9464 | else if (TYPE_P (origin)) |
71dfc51f RK |
9465 | origin_die = lookup_type_die (origin); |
9466 | ||
bbc6ae08 | 9467 | if (origin_die == NULL) |
1ae8994f | 9468 | abort (); |
556273e0 | 9469 | |
a3f97cbb JW |
9470 | add_AT_die_ref (die, DW_AT_abstract_origin, origin_die); |
9471 | } | |
9472 | ||
bdb669cb JM |
9473 | /* We do not currently support the pure_virtual attribute. */ |
9474 | ||
71dfc51f | 9475 | static inline void |
a3f97cbb | 9476 | add_pure_or_virtual_attribute (die, func_decl) |
b3694847 SS |
9477 | dw_die_ref die; |
9478 | tree func_decl; | |
a3f97cbb | 9479 | { |
a94dbf2c | 9480 | if (DECL_VINDEX (func_decl)) |
a3f97cbb | 9481 | { |
bdb669cb | 9482 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); |
665f2503 RK |
9483 | |
9484 | if (host_integerp (DECL_VINDEX (func_decl), 0)) | |
9485 | add_AT_loc (die, DW_AT_vtable_elem_location, | |
9486 | new_loc_descr (DW_OP_constu, | |
9487 | tree_low_cst (DECL_VINDEX (func_decl), 0), | |
9488 | 0)); | |
71dfc51f | 9489 | |
a94dbf2c JM |
9490 | /* GNU extension: Record what type this method came from originally. */ |
9491 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
9492 | add_AT_die_ref (die, DW_AT_containing_type, | |
9493 | lookup_type_die (DECL_CONTEXT (func_decl))); | |
a3f97cbb JW |
9494 | } |
9495 | } | |
9496 | \f | |
b2932ae5 | 9497 | /* Add source coordinate attributes for the given decl. */ |
71dfc51f | 9498 | |
b2932ae5 JM |
9499 | static void |
9500 | add_src_coords_attributes (die, decl) | |
b3694847 SS |
9501 | dw_die_ref die; |
9502 | tree decl; | |
b2932ae5 | 9503 | { |
b3694847 | 9504 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
71dfc51f | 9505 | |
b2932ae5 JM |
9506 | add_AT_unsigned (die, DW_AT_decl_file, file_index); |
9507 | add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
9508 | } | |
9509 | ||
a3f97cbb JW |
9510 | /* Add an DW_AT_name attribute and source coordinate attribute for the |
9511 | given decl, but only if it actually has a name. */ | |
71dfc51f | 9512 | |
a3f97cbb JW |
9513 | static void |
9514 | add_name_and_src_coords_attributes (die, decl) | |
b3694847 SS |
9515 | dw_die_ref die; |
9516 | tree decl; | |
a3f97cbb | 9517 | { |
b3694847 | 9518 | tree decl_name; |
71dfc51f | 9519 | |
556273e0 | 9520 | decl_name = DECL_NAME (decl); |
71dfc51f | 9521 | if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL) |
a3f97cbb | 9522 | { |
a1d7ffe3 | 9523 | add_name_attribute (die, dwarf2_name (decl, 0)); |
a96c67ec JM |
9524 | if (! DECL_ARTIFICIAL (decl)) |
9525 | add_src_coords_attributes (die, decl); | |
e689ae67 | 9526 | |
a1d7ffe3 | 9527 | if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) |
bc808e0b | 9528 | && TREE_PUBLIC (decl) |
5daf7c0a JM |
9529 | && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) |
9530 | && !DECL_ABSTRACT (decl)) | |
a1d7ffe3 JM |
9531 | add_AT_string (die, DW_AT_MIPS_linkage_name, |
9532 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
a3f97cbb | 9533 | } |
7a0c8d71 DR |
9534 | |
9535 | #ifdef VMS_DEBUGGING_INFO | |
7a0c8d71 DR |
9536 | /* Get the function's name, as described by its RTL. This may be different |
9537 | from the DECL_NAME name used in the source file. */ | |
9538 | if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl)) | |
c470afad RK |
9539 | { |
9540 | add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address, | |
9541 | XEXP (DECL_RTL (decl), 0)); | |
9542 | VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0)); | |
9543 | } | |
7a0c8d71 | 9544 | #endif |
a3f97cbb JW |
9545 | } |
9546 | ||
556273e0 | 9547 | /* Push a new declaration scope. */ |
71dfc51f | 9548 | |
a3f97cbb JW |
9549 | static void |
9550 | push_decl_scope (scope) | |
9551 | tree scope; | |
9552 | { | |
244a4af0 | 9553 | VARRAY_PUSH_TREE (decl_scope_table, scope); |
a3f97cbb JW |
9554 | } |
9555 | ||
777ad4c2 | 9556 | /* Pop a declaration scope. */ |
2ad9852d | 9557 | |
777ad4c2 JM |
9558 | static inline void |
9559 | pop_decl_scope () | |
9560 | { | |
244a4af0 | 9561 | if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0) |
777ad4c2 | 9562 | abort (); |
2ad9852d | 9563 | |
244a4af0 | 9564 | VARRAY_POP (decl_scope_table); |
777ad4c2 JM |
9565 | } |
9566 | ||
9567 | /* Return the DIE for the scope that immediately contains this type. | |
9568 | Non-named types get global scope. Named types nested in other | |
9569 | types get their containing scope if it's open, or global scope | |
9570 | otherwise. All other types (i.e. function-local named types) get | |
9571 | the current active scope. */ | |
71dfc51f | 9572 | |
a3f97cbb | 9573 | static dw_die_ref |
ab72d377 | 9574 | scope_die_for (t, context_die) |
b3694847 SS |
9575 | tree t; |
9576 | dw_die_ref context_die; | |
a3f97cbb | 9577 | { |
b3694847 SS |
9578 | dw_die_ref scope_die = NULL; |
9579 | tree containing_scope; | |
9580 | int i; | |
a3f97cbb | 9581 | |
777ad4c2 JM |
9582 | /* Non-types always go in the current scope. */ |
9583 | if (! TYPE_P (t)) | |
9584 | abort (); | |
9585 | ||
9586 | containing_scope = TYPE_CONTEXT (t); | |
ab72d377 | 9587 | |
2addbe1d JM |
9588 | /* Ignore namespaces for the moment. */ |
9589 | if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL) | |
9590 | containing_scope = NULL_TREE; | |
9591 | ||
5f2f160c JM |
9592 | /* Ignore function type "scopes" from the C frontend. They mean that |
9593 | a tagged type is local to a parmlist of a function declarator, but | |
9594 | that isn't useful to DWARF. */ | |
9595 | if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE) | |
9596 | containing_scope = NULL_TREE; | |
9597 | ||
71dfc51f RK |
9598 | if (containing_scope == NULL_TREE) |
9599 | scope_die = comp_unit_die; | |
777ad4c2 | 9600 | else if (TYPE_P (containing_scope)) |
348bb3c7 | 9601 | { |
777ad4c2 JM |
9602 | /* For types, we can just look up the appropriate DIE. But |
9603 | first we check to see if we're in the middle of emitting it | |
9604 | so we know where the new DIE should go. */ | |
244a4af0 TF |
9605 | for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i) |
9606 | if (VARRAY_TREE (decl_scope_table, i) == containing_scope) | |
348bb3c7 JM |
9607 | break; |
9608 | ||
9609 | if (i < 0) | |
9610 | { | |
348bb3c7 JM |
9611 | if (debug_info_level > DINFO_LEVEL_TERSE |
9612 | && !TREE_ASM_WRITTEN (containing_scope)) | |
9613 | abort (); | |
9614 | ||
9615 | /* If none of the current dies are suitable, we get file scope. */ | |
9616 | scope_die = comp_unit_die; | |
9617 | } | |
9618 | else | |
777ad4c2 | 9619 | scope_die = lookup_type_die (containing_scope); |
348bb3c7 | 9620 | } |
a3f97cbb | 9621 | else |
777ad4c2 | 9622 | scope_die = context_die; |
71dfc51f | 9623 | |
a3f97cbb JW |
9624 | return scope_die; |
9625 | } | |
9626 | ||
2ad9852d | 9627 | /* Returns nonzero if CONTEXT_DIE is internal to a function. */ |
777ad4c2 JM |
9628 | |
9629 | static inline int | |
9630 | local_scope_p (context_die) | |
9631 | dw_die_ref context_die; | |
a3f97cbb | 9632 | { |
777ad4c2 JM |
9633 | for (; context_die; context_die = context_die->die_parent) |
9634 | if (context_die->die_tag == DW_TAG_inlined_subroutine | |
9635 | || context_die->die_tag == DW_TAG_subprogram) | |
9636 | return 1; | |
2ad9852d | 9637 | |
777ad4c2 | 9638 | return 0; |
a3f97cbb JW |
9639 | } |
9640 | ||
2ad9852d | 9641 | /* Returns nonzero if CONTEXT_DIE is a class. */ |
9765e357 JM |
9642 | |
9643 | static inline int | |
9644 | class_scope_p (context_die) | |
9645 | dw_die_ref context_die; | |
9646 | { | |
9647 | return (context_die | |
9648 | && (context_die->die_tag == DW_TAG_structure_type | |
9649 | || context_die->die_tag == DW_TAG_union_type)); | |
9650 | } | |
9651 | ||
a3f97cbb JW |
9652 | /* Many forms of DIEs require a "type description" attribute. This |
9653 | routine locates the proper "type descriptor" die for the type given | |
9654 | by 'type', and adds an DW_AT_type attribute below the given die. */ | |
71dfc51f | 9655 | |
a3f97cbb JW |
9656 | static void |
9657 | add_type_attribute (object_die, type, decl_const, decl_volatile, context_die) | |
b3694847 SS |
9658 | dw_die_ref object_die; |
9659 | tree type; | |
9660 | int decl_const; | |
9661 | int decl_volatile; | |
9662 | dw_die_ref context_die; | |
a3f97cbb | 9663 | { |
b3694847 SS |
9664 | enum tree_code code = TREE_CODE (type); |
9665 | dw_die_ref type_die = NULL; | |
a3f97cbb | 9666 | |
ef76d03b JW |
9667 | /* ??? If this type is an unnamed subrange type of an integral or |
9668 | floating-point type, use the inner type. This is because we have no | |
9669 | support for unnamed types in base_type_die. This can happen if this is | |
9670 | an Ada subrange type. Correct solution is emit a subrange type die. */ | |
b1ccbc24 RK |
9671 | if ((code == INTEGER_TYPE || code == REAL_TYPE) |
9672 | && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0) | |
9673 | type = TREE_TYPE (type), code = TREE_CODE (type); | |
9674 | ||
2ad9852d RK |
9675 | if (code == ERROR_MARK |
9676 | /* Handle a special case. For functions whose return type is void, we | |
9677 | generate *no* type attribute. (Note that no object may have type | |
9678 | `void', so this only applies to function return types). */ | |
9679 | || code == VOID_TYPE) | |
b1ccbc24 | 9680 | return; |
a3f97cbb | 9681 | |
a3f97cbb JW |
9682 | type_die = modified_type_die (type, |
9683 | decl_const || TYPE_READONLY (type), | |
9684 | decl_volatile || TYPE_VOLATILE (type), | |
ab72d377 | 9685 | context_die); |
2ad9852d | 9686 | |
a3f97cbb | 9687 | if (type_die != NULL) |
71dfc51f | 9688 | add_AT_die_ref (object_die, DW_AT_type, type_die); |
a3f97cbb JW |
9689 | } |
9690 | ||
9691 | /* Given a tree pointer to a struct, class, union, or enum type node, return | |
9692 | a pointer to the (string) tag name for the given type, or zero if the type | |
9693 | was declared without a tag. */ | |
71dfc51f | 9694 | |
d3e3972c | 9695 | static const char * |
a3f97cbb | 9696 | type_tag (type) |
b3694847 | 9697 | tree type; |
a3f97cbb | 9698 | { |
b3694847 | 9699 | const char *name = 0; |
a3f97cbb JW |
9700 | |
9701 | if (TYPE_NAME (type) != 0) | |
9702 | { | |
b3694847 | 9703 | tree t = 0; |
a3f97cbb JW |
9704 | |
9705 | /* Find the IDENTIFIER_NODE for the type name. */ | |
9706 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
9707 | t = TYPE_NAME (type); | |
bdb669cb | 9708 | |
556273e0 | 9709 | /* The g++ front end makes the TYPE_NAME of *each* tagged type point to |
a3f97cbb | 9710 | a TYPE_DECL node, regardless of whether or not a `typedef' was |
bdb669cb | 9711 | involved. */ |
a94dbf2c JM |
9712 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
9713 | && ! DECL_IGNORED_P (TYPE_NAME (type))) | |
a3f97cbb | 9714 | t = DECL_NAME (TYPE_NAME (type)); |
bdb669cb | 9715 | |
a3f97cbb JW |
9716 | /* Now get the name as a string, or invent one. */ |
9717 | if (t != 0) | |
a94dbf2c | 9718 | name = IDENTIFIER_POINTER (t); |
a3f97cbb | 9719 | } |
71dfc51f | 9720 | |
a3f97cbb JW |
9721 | return (name == 0 || *name == '\0') ? 0 : name; |
9722 | } | |
9723 | ||
9724 | /* Return the type associated with a data member, make a special check | |
9725 | for bit field types. */ | |
71dfc51f RK |
9726 | |
9727 | static inline tree | |
a3f97cbb | 9728 | member_declared_type (member) |
b3694847 | 9729 | tree member; |
a3f97cbb | 9730 | { |
71dfc51f | 9731 | return (DECL_BIT_FIELD_TYPE (member) |
2ad9852d | 9732 | ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member)); |
a3f97cbb JW |
9733 | } |
9734 | ||
d291dd49 | 9735 | /* Get the decl's label, as described by its RTL. This may be different |
a3f97cbb | 9736 | from the DECL_NAME name used in the source file. */ |
71dfc51f | 9737 | |
487a6e06 | 9738 | #if 0 |
d3e3972c | 9739 | static const char * |
d291dd49 | 9740 | decl_start_label (decl) |
b3694847 | 9741 | tree decl; |
a3f97cbb JW |
9742 | { |
9743 | rtx x; | |
d3e3972c | 9744 | const char *fnname; |
2ad9852d | 9745 | |
a3f97cbb JW |
9746 | x = DECL_RTL (decl); |
9747 | if (GET_CODE (x) != MEM) | |
71dfc51f RK |
9748 | abort (); |
9749 | ||
a3f97cbb JW |
9750 | x = XEXP (x, 0); |
9751 | if (GET_CODE (x) != SYMBOL_REF) | |
71dfc51f RK |
9752 | abort (); |
9753 | ||
a3f97cbb JW |
9754 | fnname = XSTR (x, 0); |
9755 | return fnname; | |
9756 | } | |
487a6e06 | 9757 | #endif |
a3f97cbb | 9758 | \f |
956d6950 | 9759 | /* These routines generate the internal representation of the DIE's for |
a3f97cbb | 9760 | the compilation unit. Debugging information is collected by walking |
88dad228 | 9761 | the declaration trees passed in from dwarf2out_decl(). */ |
a3f97cbb JW |
9762 | |
9763 | static void | |
9764 | gen_array_type_die (type, context_die) | |
b3694847 SS |
9765 | tree type; |
9766 | dw_die_ref context_die; | |
a3f97cbb | 9767 | { |
b3694847 SS |
9768 | dw_die_ref scope_die = scope_die_for (type, context_die); |
9769 | dw_die_ref array_die; | |
9770 | tree element_type; | |
bdb669cb | 9771 | |
a9d38797 JM |
9772 | /* ??? The SGI dwarf reader fails for array of array of enum types unless |
9773 | the inner array type comes before the outer array type. Thus we must | |
9774 | call gen_type_die before we call new_die. See below also. */ | |
9775 | #ifdef MIPS_DEBUGGING_INFO | |
9776 | gen_type_die (TREE_TYPE (type), context_die); | |
9777 | #endif | |
9778 | ||
54ba1f0d | 9779 | array_die = new_die (DW_TAG_array_type, scope_die, type); |
84f0ace0 JM |
9780 | add_name_attribute (array_die, type_tag (type)); |
9781 | equate_type_number_to_die (type, array_die); | |
9782 | ||
9783 | if (TREE_CODE (type) == VECTOR_TYPE) | |
9784 | { | |
9785 | /* The frontend feeds us a representation for the vector as a struct | |
9786 | containing an array. Pull out the array type. */ | |
9787 | type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type))); | |
9788 | add_AT_flag (array_die, DW_AT_GNU_vector, 1); | |
9789 | } | |
a9d38797 | 9790 | |
a3f97cbb JW |
9791 | #if 0 |
9792 | /* We default the array ordering. SDB will probably do | |
9793 | the right things even if DW_AT_ordering is not present. It's not even | |
9794 | an issue until we start to get into multidimensional arrays anyway. If | |
9795 | SDB is ever caught doing the Wrong Thing for multi-dimensional arrays, | |
9796 | then we'll have to put the DW_AT_ordering attribute back in. (But if | |
9797 | and when we find out that we need to put these in, we will only do so | |
9798 | for multidimensional arrays. */ | |
9799 | add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major); | |
9800 | #endif | |
9801 | ||
a9d38797 | 9802 | #ifdef MIPS_DEBUGGING_INFO |
4edb7b60 JM |
9803 | /* The SGI compilers handle arrays of unknown bound by setting |
9804 | AT_declaration and not emitting any subrange DIEs. */ | |
a9d38797 JM |
9805 | if (! TYPE_DOMAIN (type)) |
9806 | add_AT_unsigned (array_die, DW_AT_declaration, 1); | |
9807 | else | |
9808 | #endif | |
9809 | add_subscript_info (array_die, type); | |
a3f97cbb | 9810 | |
a3f97cbb JW |
9811 | /* Add representation of the type of the elements of this array type. */ |
9812 | element_type = TREE_TYPE (type); | |
71dfc51f | 9813 | |
a3f97cbb JW |
9814 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
9815 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
9816 | We work around this by disabling this feature. See also | |
9817 | add_subscript_info. */ | |
9818 | #ifndef MIPS_DEBUGGING_INFO | |
71dfc51f RK |
9819 | while (TREE_CODE (element_type) == ARRAY_TYPE) |
9820 | element_type = TREE_TYPE (element_type); | |
9821 | ||
a3f97cbb | 9822 | gen_type_die (element_type, context_die); |
a9d38797 | 9823 | #endif |
a3f97cbb JW |
9824 | |
9825 | add_type_attribute (array_die, element_type, 0, 0, context_die); | |
9826 | } | |
9827 | ||
9828 | static void | |
9829 | gen_set_type_die (type, context_die) | |
b3694847 SS |
9830 | tree type; |
9831 | dw_die_ref context_die; | |
a3f97cbb | 9832 | { |
b3694847 | 9833 | dw_die_ref type_die |
54ba1f0d | 9834 | = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type); |
71dfc51f | 9835 | |
a3f97cbb | 9836 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
9837 | add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die); |
9838 | } | |
9839 | ||
d6f4ec51 | 9840 | #if 0 |
a3f97cbb JW |
9841 | static void |
9842 | gen_entry_point_die (decl, context_die) | |
b3694847 SS |
9843 | tree decl; |
9844 | dw_die_ref context_die; | |
a3f97cbb | 9845 | { |
b3694847 | 9846 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 9847 | dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl); |
2ad9852d | 9848 | |
a3f97cbb | 9849 | if (origin != NULL) |
71dfc51f | 9850 | add_abstract_origin_attribute (decl_die, origin); |
a3f97cbb JW |
9851 | else |
9852 | { | |
9853 | add_name_and_src_coords_attributes (decl_die, decl); | |
a3f97cbb JW |
9854 | add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)), |
9855 | 0, 0, context_die); | |
9856 | } | |
71dfc51f | 9857 | |
a3f97cbb | 9858 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 9859 | equate_decl_number_to_die (decl, decl_die); |
a3f97cbb | 9860 | else |
71dfc51f | 9861 | add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl)); |
a3f97cbb | 9862 | } |
d6f4ec51 | 9863 | #endif |
a3f97cbb | 9864 | |
8a8c3656 JM |
9865 | /* Walk through the list of incomplete types again, trying once more to |
9866 | emit full debugging info for them. */ | |
9867 | ||
9868 | static void | |
9869 | retry_incomplete_types () | |
9870 | { | |
244a4af0 | 9871 | int i; |
2ad9852d | 9872 | |
244a4af0 | 9873 | for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--) |
2ad9852d | 9874 | gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die); |
8a8c3656 JM |
9875 | } |
9876 | ||
a3f97cbb | 9877 | /* Generate a DIE to represent an inlined instance of an enumeration type. */ |
71dfc51f | 9878 | |
a3f97cbb JW |
9879 | static void |
9880 | gen_inlined_enumeration_type_die (type, context_die) | |
b3694847 SS |
9881 | tree type; |
9882 | dw_die_ref context_die; | |
a3f97cbb | 9883 | { |
54ba1f0d | 9884 | dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type); |
2ad9852d | 9885 | |
bbc6ae08 NC |
9886 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9887 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9888 | add_abstract_origin_attribute (type_die, type); |
9889 | } | |
9890 | ||
9891 | /* Generate a DIE to represent an inlined instance of a structure type. */ | |
71dfc51f | 9892 | |
a3f97cbb JW |
9893 | static void |
9894 | gen_inlined_structure_type_die (type, context_die) | |
b3694847 SS |
9895 | tree type; |
9896 | dw_die_ref context_die; | |
a3f97cbb | 9897 | { |
54ba1f0d | 9898 | dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type); |
777ad4c2 | 9899 | |
bbc6ae08 NC |
9900 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9901 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9902 | add_abstract_origin_attribute (type_die, type); |
9903 | } | |
9904 | ||
9905 | /* Generate a DIE to represent an inlined instance of a union type. */ | |
71dfc51f | 9906 | |
a3f97cbb JW |
9907 | static void |
9908 | gen_inlined_union_type_die (type, context_die) | |
b3694847 SS |
9909 | tree type; |
9910 | dw_die_ref context_die; | |
a3f97cbb | 9911 | { |
54ba1f0d | 9912 | dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type); |
777ad4c2 | 9913 | |
bbc6ae08 NC |
9914 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9915 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9916 | add_abstract_origin_attribute (type_die, type); |
9917 | } | |
9918 | ||
9919 | /* Generate a DIE to represent an enumeration type. Note that these DIEs | |
9920 | include all of the information about the enumeration values also. Each | |
273dbe67 JM |
9921 | enumerated type name/value is listed as a child of the enumerated type |
9922 | DIE. */ | |
71dfc51f | 9923 | |
a3f97cbb | 9924 | static void |
273dbe67 | 9925 | gen_enumeration_type_die (type, context_die) |
b3694847 SS |
9926 | tree type; |
9927 | dw_die_ref context_die; | |
a3f97cbb | 9928 | { |
b3694847 | 9929 | dw_die_ref type_die = lookup_type_die (type); |
273dbe67 | 9930 | |
a3f97cbb JW |
9931 | if (type_die == NULL) |
9932 | { | |
9933 | type_die = new_die (DW_TAG_enumeration_type, | |
54ba1f0d | 9934 | scope_die_for (type, context_die), type); |
a3f97cbb JW |
9935 | equate_type_number_to_die (type, type_die); |
9936 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 9937 | } |
273dbe67 JM |
9938 | else if (! TYPE_SIZE (type)) |
9939 | return; | |
9940 | else | |
9941 | remove_AT (type_die, DW_AT_declaration); | |
9942 | ||
9943 | /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the | |
9944 | given enum type is incomplete, do not generate the DW_AT_byte_size | |
9945 | attribute or the DW_AT_element_list attribute. */ | |
9946 | if (TYPE_SIZE (type)) | |
a3f97cbb | 9947 | { |
b3694847 | 9948 | tree link; |
71dfc51f | 9949 | |
a082c85a | 9950 | TREE_ASM_WRITTEN (type) = 1; |
273dbe67 | 9951 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 9952 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 9953 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 9954 | |
ef76d03b JW |
9955 | /* If the first reference to this type was as the return type of an |
9956 | inline function, then it may not have a parent. Fix this now. */ | |
9957 | if (type_die->die_parent == NULL) | |
9958 | add_child_die (scope_die_for (type, context_die), type_die); | |
9959 | ||
273dbe67 JM |
9960 | for (link = TYPE_FIELDS (type); |
9961 | link != NULL; link = TREE_CHAIN (link)) | |
a3f97cbb | 9962 | { |
54ba1f0d | 9963 | dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link); |
71dfc51f | 9964 | |
273dbe67 JM |
9965 | add_name_attribute (enum_die, |
9966 | IDENTIFIER_POINTER (TREE_PURPOSE (link))); | |
665f2503 RK |
9967 | |
9968 | if (host_integerp (TREE_VALUE (link), 0)) | |
fc9e8a14 JJ |
9969 | { |
9970 | if (tree_int_cst_sgn (TREE_VALUE (link)) < 0) | |
9971 | add_AT_int (enum_die, DW_AT_const_value, | |
9972 | tree_low_cst (TREE_VALUE (link), 0)); | |
9973 | else | |
9974 | add_AT_unsigned (enum_die, DW_AT_const_value, | |
9975 | tree_low_cst (TREE_VALUE (link), 0)); | |
9976 | } | |
a3f97cbb JW |
9977 | } |
9978 | } | |
273dbe67 JM |
9979 | else |
9980 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a3f97cbb JW |
9981 | } |
9982 | ||
a3f97cbb JW |
9983 | /* Generate a DIE to represent either a real live formal parameter decl or to |
9984 | represent just the type of some formal parameter position in some function | |
9985 | type. | |
71dfc51f | 9986 | |
a3f97cbb JW |
9987 | Note that this routine is a bit unusual because its argument may be a |
9988 | ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which | |
9989 | represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE | |
9990 | node. If it's the former then this function is being called to output a | |
9991 | DIE to represent a formal parameter object (or some inlining thereof). If | |
9992 | it's the latter, then this function is only being called to output a | |
9993 | DW_TAG_formal_parameter DIE to stand as a placeholder for some formal | |
9994 | argument type of some subprogram type. */ | |
71dfc51f | 9995 | |
a94dbf2c | 9996 | static dw_die_ref |
a3f97cbb | 9997 | gen_formal_parameter_die (node, context_die) |
b3694847 SS |
9998 | tree node; |
9999 | dw_die_ref context_die; | |
a3f97cbb | 10000 | { |
b3694847 | 10001 | dw_die_ref parm_die |
54ba1f0d | 10002 | = new_die (DW_TAG_formal_parameter, context_die, node); |
b3694847 | 10003 | tree origin; |
71dfc51f | 10004 | |
a3f97cbb JW |
10005 | switch (TREE_CODE_CLASS (TREE_CODE (node))) |
10006 | { | |
a3f97cbb JW |
10007 | case 'd': |
10008 | origin = decl_ultimate_origin (node); | |
10009 | if (origin != NULL) | |
a94dbf2c | 10010 | add_abstract_origin_attribute (parm_die, origin); |
a3f97cbb JW |
10011 | else |
10012 | { | |
10013 | add_name_and_src_coords_attributes (parm_die, node); | |
10014 | add_type_attribute (parm_die, TREE_TYPE (node), | |
10015 | TREE_READONLY (node), | |
10016 | TREE_THIS_VOLATILE (node), | |
10017 | context_die); | |
bdb669cb JM |
10018 | if (DECL_ARTIFICIAL (node)) |
10019 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb | 10020 | } |
71dfc51f | 10021 | |
141719a8 JM |
10022 | equate_decl_number_to_die (node, parm_die); |
10023 | if (! DECL_ABSTRACT (node)) | |
a94dbf2c | 10024 | add_location_or_const_value_attribute (parm_die, node); |
71dfc51f | 10025 | |
a3f97cbb JW |
10026 | break; |
10027 | ||
a3f97cbb | 10028 | case 't': |
71dfc51f | 10029 | /* We were called with some kind of a ..._TYPE node. */ |
a3f97cbb JW |
10030 | add_type_attribute (parm_die, node, 0, 0, context_die); |
10031 | break; | |
10032 | ||
a3f97cbb JW |
10033 | default: |
10034 | abort (); | |
10035 | } | |
71dfc51f | 10036 | |
a94dbf2c | 10037 | return parm_die; |
a3f97cbb JW |
10038 | } |
10039 | ||
10040 | /* Generate a special type of DIE used as a stand-in for a trailing ellipsis | |
10041 | at the end of an (ANSI prototyped) formal parameters list. */ | |
71dfc51f | 10042 | |
a3f97cbb JW |
10043 | static void |
10044 | gen_unspecified_parameters_die (decl_or_type, context_die) | |
54ba1f0d | 10045 | tree decl_or_type; |
b3694847 | 10046 | dw_die_ref context_die; |
a3f97cbb | 10047 | { |
54ba1f0d | 10048 | new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type); |
a3f97cbb JW |
10049 | } |
10050 | ||
10051 | /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a | |
10052 | DW_TAG_unspecified_parameters DIE) to represent the types of the formal | |
10053 | parameters as specified in some function type specification (except for | |
1cfdcc15 | 10054 | those which appear as part of a function *definition*). */ |
71dfc51f | 10055 | |
a3f97cbb JW |
10056 | static void |
10057 | gen_formal_types_die (function_or_method_type, context_die) | |
b3694847 SS |
10058 | tree function_or_method_type; |
10059 | dw_die_ref context_die; | |
a3f97cbb | 10060 | { |
b3694847 SS |
10061 | tree link; |
10062 | tree formal_type = NULL; | |
10063 | tree first_parm_type; | |
5daf7c0a | 10064 | tree arg; |
a3f97cbb | 10065 | |
5daf7c0a JM |
10066 | if (TREE_CODE (function_or_method_type) == FUNCTION_DECL) |
10067 | { | |
10068 | arg = DECL_ARGUMENTS (function_or_method_type); | |
10069 | function_or_method_type = TREE_TYPE (function_or_method_type); | |
10070 | } | |
10071 | else | |
10072 | arg = NULL_TREE; | |
c26fbbca | 10073 | |
5daf7c0a | 10074 | first_parm_type = TYPE_ARG_TYPES (function_or_method_type); |
a3f97cbb | 10075 | |
556273e0 | 10076 | /* Make our first pass over the list of formal parameter types and output a |
a3f97cbb | 10077 | DW_TAG_formal_parameter DIE for each one. */ |
5daf7c0a | 10078 | for (link = first_parm_type; link; ) |
a3f97cbb | 10079 | { |
b3694847 | 10080 | dw_die_ref parm_die; |
556273e0 | 10081 | |
a3f97cbb JW |
10082 | formal_type = TREE_VALUE (link); |
10083 | if (formal_type == void_type_node) | |
10084 | break; | |
10085 | ||
10086 | /* Output a (nameless) DIE to represent the formal parameter itself. */ | |
a94dbf2c | 10087 | parm_die = gen_formal_parameter_die (formal_type, context_die); |
5daf7c0a JM |
10088 | if ((TREE_CODE (function_or_method_type) == METHOD_TYPE |
10089 | && link == first_parm_type) | |
10090 | || (arg && DECL_ARTIFICIAL (arg))) | |
a94dbf2c | 10091 | add_AT_flag (parm_die, DW_AT_artificial, 1); |
5daf7c0a JM |
10092 | |
10093 | link = TREE_CHAIN (link); | |
10094 | if (arg) | |
10095 | arg = TREE_CHAIN (arg); | |
a3f97cbb JW |
10096 | } |
10097 | ||
10098 | /* If this function type has an ellipsis, add a | |
10099 | DW_TAG_unspecified_parameters DIE to the end of the parameter list. */ | |
10100 | if (formal_type != void_type_node) | |
10101 | gen_unspecified_parameters_die (function_or_method_type, context_die); | |
10102 | ||
556273e0 | 10103 | /* Make our second (and final) pass over the list of formal parameter types |
a3f97cbb JW |
10104 | and output DIEs to represent those types (as necessary). */ |
10105 | for (link = TYPE_ARG_TYPES (function_or_method_type); | |
2ad9852d | 10106 | link && TREE_VALUE (link); |
a3f97cbb | 10107 | link = TREE_CHAIN (link)) |
2ad9852d | 10108 | gen_type_die (TREE_VALUE (link), context_die); |
a3f97cbb JW |
10109 | } |
10110 | ||
10a11b75 JM |
10111 | /* We want to generate the DIE for TYPE so that we can generate the |
10112 | die for MEMBER, which has been defined; we will need to refer back | |
10113 | to the member declaration nested within TYPE. If we're trying to | |
10114 | generate minimal debug info for TYPE, processing TYPE won't do the | |
10115 | trick; we need to attach the member declaration by hand. */ | |
10116 | ||
10117 | static void | |
10118 | gen_type_die_for_member (type, member, context_die) | |
10119 | tree type, member; | |
10120 | dw_die_ref context_die; | |
10121 | { | |
10122 | gen_type_die (type, context_die); | |
10123 | ||
10124 | /* If we're trying to avoid duplicate debug info, we may not have | |
10125 | emitted the member decl for this function. Emit it now. */ | |
10126 | if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)) | |
10127 | && ! lookup_decl_die (member)) | |
10128 | { | |
10129 | if (decl_ultimate_origin (member)) | |
10130 | abort (); | |
10131 | ||
10132 | push_decl_scope (type); | |
10133 | if (TREE_CODE (member) == FUNCTION_DECL) | |
10134 | gen_subprogram_die (member, lookup_type_die (type)); | |
10135 | else | |
10136 | gen_variable_die (member, lookup_type_die (type)); | |
2ad9852d | 10137 | |
10a11b75 JM |
10138 | pop_decl_scope (); |
10139 | } | |
10140 | } | |
10141 | ||
2ad9852d RK |
10142 | /* Generate the DWARF2 info for the "abstract" instance of a function which we |
10143 | may later generate inlined and/or out-of-line instances of. */ | |
10a11b75 | 10144 | |
e1772ac0 | 10145 | static void |
1edf43d6 | 10146 | dwarf2out_abstract_function (decl) |
10a11b75 JM |
10147 | tree decl; |
10148 | { | |
b3694847 | 10149 | dw_die_ref old_die; |
777ad4c2 | 10150 | tree save_fn; |
5daf7c0a JM |
10151 | tree context; |
10152 | int was_abstract = DECL_ABSTRACT (decl); | |
10153 | ||
10154 | /* Make sure we have the actual abstract inline, not a clone. */ | |
10155 | decl = DECL_ORIGIN (decl); | |
10a11b75 | 10156 | |
c26fbbca | 10157 | old_die = lookup_decl_die (decl); |
10a11b75 JM |
10158 | if (old_die && get_AT_unsigned (old_die, DW_AT_inline)) |
10159 | /* We've already generated the abstract instance. */ | |
10160 | return; | |
10161 | ||
5daf7c0a JM |
10162 | /* Be sure we've emitted the in-class declaration DIE (if any) first, so |
10163 | we don't get confused by DECL_ABSTRACT. */ | |
8458e954 JS |
10164 | if (debug_info_level > DINFO_LEVEL_TERSE) |
10165 | { | |
10166 | context = decl_class_context (decl); | |
10167 | if (context) | |
10168 | gen_type_die_for_member | |
10169 | (context, decl, decl_function_context (decl) ? NULL : comp_unit_die); | |
10170 | } | |
c26fbbca | 10171 | |
5daf7c0a | 10172 | /* Pretend we've just finished compiling this function. */ |
777ad4c2 JM |
10173 | save_fn = current_function_decl; |
10174 | current_function_decl = decl; | |
10175 | ||
10a11b75 JM |
10176 | set_decl_abstract_flags (decl, 1); |
10177 | dwarf2out_decl (decl); | |
5daf7c0a JM |
10178 | if (! was_abstract) |
10179 | set_decl_abstract_flags (decl, 0); | |
777ad4c2 JM |
10180 | |
10181 | current_function_decl = save_fn; | |
10a11b75 JM |
10182 | } |
10183 | ||
a3f97cbb JW |
10184 | /* Generate a DIE to represent a declared function (either file-scope or |
10185 | block-local). */ | |
71dfc51f | 10186 | |
a3f97cbb JW |
10187 | static void |
10188 | gen_subprogram_die (decl, context_die) | |
b3694847 SS |
10189 | tree decl; |
10190 | dw_die_ref context_die; | |
a3f97cbb JW |
10191 | { |
10192 | char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; | |
b3694847 SS |
10193 | tree origin = decl_ultimate_origin (decl); |
10194 | dw_die_ref subr_die; | |
10195 | rtx fp_reg; | |
10196 | tree fn_arg_types; | |
10197 | tree outer_scope; | |
10198 | dw_die_ref old_die = lookup_decl_die (decl); | |
10199 | int declaration = (current_function_decl != decl | |
10200 | || class_scope_p (context_die)); | |
a3f97cbb | 10201 | |
2ad9852d RK |
10202 | /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we |
10203 | started to generate the abstract instance of an inline, decided to output | |
10204 | its containing class, and proceeded to emit the declaration of the inline | |
10205 | from the member list for the class. If so, DECLARATION takes priority; | |
10206 | we'll get back to the abstract instance when done with the class. */ | |
10a11b75 | 10207 | |
1cfdcc15 JM |
10208 | /* The class-scope declaration DIE must be the primary DIE. */ |
10209 | if (origin && declaration && class_scope_p (context_die)) | |
10210 | { | |
10211 | origin = NULL; | |
10212 | if (old_die) | |
10213 | abort (); | |
10214 | } | |
10215 | ||
a3f97cbb JW |
10216 | if (origin != NULL) |
10217 | { | |
777ad4c2 | 10218 | if (declaration && ! local_scope_p (context_die)) |
10a11b75 JM |
10219 | abort (); |
10220 | ||
8d8238b6 JM |
10221 | /* Fixup die_parent for the abstract instance of a nested |
10222 | inline function. */ | |
10223 | if (old_die && old_die->die_parent == NULL) | |
10224 | add_child_die (context_die, old_die); | |
10225 | ||
54ba1f0d | 10226 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
a3f97cbb JW |
10227 | add_abstract_origin_attribute (subr_die, origin); |
10228 | } | |
bdb669cb JM |
10229 | else if (old_die) |
10230 | { | |
981975b6 | 10231 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
a94dbf2c | 10232 | |
1edf43d6 JM |
10233 | if (!get_AT_flag (old_die, DW_AT_declaration) |
10234 | /* We can have a normal definition following an inline one in the | |
10235 | case of redefinition of GNU C extern inlines. | |
10236 | It seems reasonable to use AT_specification in this case. */ | |
10237 | && !get_AT_unsigned (old_die, DW_AT_inline)) | |
b75ab88b NC |
10238 | { |
10239 | /* ??? This can happen if there is a bug in the program, for | |
10240 | instance, if it has duplicate function definitions. Ideally, | |
10241 | we should detect this case and ignore it. For now, if we have | |
10242 | already reported an error, any error at all, then assume that | |
4fe9b91c | 10243 | we got here because of an input error, not a dwarf2 bug. */ |
b75ab88b NC |
10244 | if (errorcount) |
10245 | return; | |
10246 | abort (); | |
10247 | } | |
4b674448 JM |
10248 | |
10249 | /* If the definition comes from the same place as the declaration, | |
a94dbf2c JM |
10250 | maybe use the old DIE. We always want the DIE for this function |
10251 | that has the *_pc attributes to be under comp_unit_die so the | |
cb9e9d8d JM |
10252 | debugger can find it. We also need to do this for abstract |
10253 | instances of inlines, since the spec requires the out-of-line copy | |
10254 | to have the same parent. For local class methods, this doesn't | |
10255 | apply; we just use the old DIE. */ | |
10256 | if ((old_die->die_parent == comp_unit_die || context_die == NULL) | |
a96c67ec JM |
10257 | && (DECL_ARTIFICIAL (decl) |
10258 | || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index | |
10259 | && (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 10260 | == (unsigned) DECL_SOURCE_LINE (decl))))) |
bdb669cb | 10261 | { |
4b674448 JM |
10262 | subr_die = old_die; |
10263 | ||
10264 | /* Clear out the declaration attribute and the parm types. */ | |
10265 | remove_AT (subr_die, DW_AT_declaration); | |
10266 | remove_children (subr_die); | |
10267 | } | |
10268 | else | |
10269 | { | |
54ba1f0d | 10270 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
4b674448 | 10271 | add_AT_die_ref (subr_die, DW_AT_specification, old_die); |
bdb669cb JM |
10272 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
10273 | add_AT_unsigned (subr_die, DW_AT_decl_file, file_index); | |
10274 | if (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 10275 | != (unsigned) DECL_SOURCE_LINE (decl)) |
bdb669cb JM |
10276 | add_AT_unsigned |
10277 | (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
10278 | } | |
10279 | } | |
a3f97cbb JW |
10280 | else |
10281 | { | |
54ba1f0d | 10282 | subr_die = new_die (DW_TAG_subprogram, context_die, decl); |
556273e0 | 10283 | |
273dbe67 JM |
10284 | if (TREE_PUBLIC (decl)) |
10285 | add_AT_flag (subr_die, DW_AT_external, 1); | |
71dfc51f | 10286 | |
a3f97cbb | 10287 | add_name_and_src_coords_attributes (subr_die, decl); |
4927276d JM |
10288 | if (debug_info_level > DINFO_LEVEL_TERSE) |
10289 | { | |
2ad9852d RK |
10290 | add_prototyped_attribute (subr_die, TREE_TYPE (decl)); |
10291 | add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)), | |
10292 | 0, 0, context_die); | |
4927276d | 10293 | } |
71dfc51f | 10294 | |
a3f97cbb | 10295 | add_pure_or_virtual_attribute (subr_die, decl); |
273dbe67 JM |
10296 | if (DECL_ARTIFICIAL (decl)) |
10297 | add_AT_flag (subr_die, DW_AT_artificial, 1); | |
2ad9852d | 10298 | |
a94dbf2c JM |
10299 | if (TREE_PROTECTED (decl)) |
10300 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected); | |
10301 | else if (TREE_PRIVATE (decl)) | |
10302 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 10303 | } |
4edb7b60 | 10304 | |
a94dbf2c JM |
10305 | if (declaration) |
10306 | { | |
2ad9852d | 10307 | if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline)) |
1edf43d6 JM |
10308 | { |
10309 | add_AT_flag (subr_die, DW_AT_declaration, 1); | |
10310 | ||
10311 | /* The first time we see a member function, it is in the context of | |
10312 | the class to which it belongs. We make sure of this by emitting | |
10313 | the class first. The next time is the definition, which is | |
10314 | handled above. The two may come from the same source text. */ | |
10315 | if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl)) | |
10316 | equate_decl_number_to_die (decl, subr_die); | |
10317 | } | |
a94dbf2c JM |
10318 | } |
10319 | else if (DECL_ABSTRACT (decl)) | |
a3f97cbb | 10320 | { |
10a11b75 | 10321 | if (DECL_INLINE (decl) && !flag_no_inline) |
61b32c02 | 10322 | { |
10a11b75 JM |
10323 | /* ??? Checking DECL_DEFER_OUTPUT is correct for static |
10324 | inline functions, but not for extern inline functions. | |
10325 | We can't get this completely correct because information | |
10326 | about whether the function was declared inline is not | |
10327 | saved anywhere. */ | |
10328 | if (DECL_DEFER_OUTPUT (decl)) | |
61b32c02 JM |
10329 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined); |
10330 | else | |
10a11b75 | 10331 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined); |
61b32c02 | 10332 | } |
61b32c02 | 10333 | else |
10a11b75 | 10334 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined); |
61b32c02 | 10335 | |
a3f97cbb JW |
10336 | equate_decl_number_to_die (decl, subr_die); |
10337 | } | |
10338 | else if (!DECL_EXTERNAL (decl)) | |
10339 | { | |
2ad9852d | 10340 | if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline)) |
ba7b35df | 10341 | equate_decl_number_to_die (decl, subr_die); |
71dfc51f | 10342 | |
5c90448c JM |
10343 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL, |
10344 | current_funcdef_number); | |
7d4440be | 10345 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id); |
5c90448c JM |
10346 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, |
10347 | current_funcdef_number); | |
a3f97cbb JW |
10348 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id); |
10349 | ||
d291dd49 JM |
10350 | add_pubname (decl, subr_die); |
10351 | add_arange (decl, subr_die); | |
10352 | ||
a3f97cbb | 10353 | #ifdef MIPS_DEBUGGING_INFO |
a3f97cbb JW |
10354 | /* Add a reference to the FDE for this routine. */ |
10355 | add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde); | |
10356 | #endif | |
10357 | ||
810429b7 JM |
10358 | /* Define the "frame base" location for this routine. We use the |
10359 | frame pointer or stack pointer registers, since the RTL for local | |
10360 | variables is relative to one of them. */ | |
b1ccbc24 RK |
10361 | fp_reg |
10362 | = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx; | |
10363 | add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg)); | |
a3f97cbb | 10364 | |
ef76d03b JW |
10365 | #if 0 |
10366 | /* ??? This fails for nested inline functions, because context_display | |
10367 | is not part of the state saved/restored for inline functions. */ | |
88dad228 | 10368 | if (current_function_needs_context) |
ef76d03b JW |
10369 | add_AT_location_description (subr_die, DW_AT_static_link, |
10370 | lookup_static_chain (decl)); | |
10371 | #endif | |
a3f97cbb JW |
10372 | } |
10373 | ||
10374 | /* Now output descriptions of the arguments for this function. This gets | |
556273e0 | 10375 | (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list |
a3f97cbb JW |
10376 | for a FUNCTION_DECL doesn't indicate cases where there was a trailing |
10377 | `...' at the end of the formal parameter list. In order to find out if | |
10378 | there was a trailing ellipsis or not, we must instead look at the type | |
10379 | associated with the FUNCTION_DECL. This will be a node of type | |
10380 | FUNCTION_TYPE. If the chain of type nodes hanging off of this | |
556273e0 | 10381 | FUNCTION_TYPE node ends with a void_type_node then there should *not* be |
a3f97cbb | 10382 | an ellipsis at the end. */ |
71dfc51f | 10383 | |
a3f97cbb | 10384 | /* In the case where we are describing a mere function declaration, all we |
556273e0 | 10385 | need to do here (and all we *can* do here) is to describe the *types* of |
a3f97cbb | 10386 | its formal parameters. */ |
4927276d | 10387 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 10388 | ; |
4edb7b60 | 10389 | else if (declaration) |
5daf7c0a | 10390 | gen_formal_types_die (decl, subr_die); |
a3f97cbb JW |
10391 | else |
10392 | { | |
10393 | /* Generate DIEs to represent all known formal parameters */ | |
b3694847 SS |
10394 | tree arg_decls = DECL_ARGUMENTS (decl); |
10395 | tree parm; | |
a3f97cbb JW |
10396 | |
10397 | /* When generating DIEs, generate the unspecified_parameters DIE | |
10398 | instead if we come across the arg "__builtin_va_alist" */ | |
10399 | for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) | |
71dfc51f RK |
10400 | if (TREE_CODE (parm) == PARM_DECL) |
10401 | { | |
db3cf6fb MS |
10402 | if (DECL_NAME (parm) |
10403 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), | |
10404 | "__builtin_va_alist")) | |
71dfc51f RK |
10405 | gen_unspecified_parameters_die (parm, subr_die); |
10406 | else | |
10407 | gen_decl_die (parm, subr_die); | |
10408 | } | |
a3f97cbb | 10409 | |
4fe9b91c | 10410 | /* Decide whether we need an unspecified_parameters DIE at the end. |
556273e0 | 10411 | There are 2 more cases to do this for: 1) the ansi ... declaration - |
a3f97cbb JW |
10412 | this is detectable when the end of the arg list is not a |
10413 | void_type_node 2) an unprototyped function declaration (not a | |
10414 | definition). This just means that we have no info about the | |
10415 | parameters at all. */ | |
10416 | fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
71dfc51f | 10417 | if (fn_arg_types != NULL) |
a3f97cbb JW |
10418 | { |
10419 | /* this is the prototyped case, check for ... */ | |
10420 | if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) | |
71dfc51f | 10421 | gen_unspecified_parameters_die (decl, subr_die); |
a3f97cbb | 10422 | } |
71dfc51f RK |
10423 | else if (DECL_INITIAL (decl) == NULL_TREE) |
10424 | gen_unspecified_parameters_die (decl, subr_die); | |
a3f97cbb JW |
10425 | } |
10426 | ||
10427 | /* Output Dwarf info for all of the stuff within the body of the function | |
10428 | (if it has one - it may be just a declaration). */ | |
10429 | outer_scope = DECL_INITIAL (decl); | |
10430 | ||
2ad9852d RK |
10431 | /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent |
10432 | a function. This BLOCK actually represents the outermost binding contour | |
10433 | for the function, i.e. the contour in which the function's formal | |
10434 | parameters and labels get declared. Curiously, it appears that the front | |
10435 | end doesn't actually put the PARM_DECL nodes for the current function onto | |
10436 | the BLOCK_VARS list for this outer scope, but are strung off of the | |
10437 | DECL_ARGUMENTS list for the function instead. | |
10438 | ||
10439 | The BLOCK_VARS list for the `outer_scope' does provide us with a list of | |
10440 | the LABEL_DECL nodes for the function however, and we output DWARF info | |
10441 | for those in decls_for_scope. Just within the `outer_scope' there will be | |
10442 | a BLOCK node representing the function's outermost pair of curly braces, | |
10443 | and any blocks used for the base and member initializers of a C++ | |
d7248bff | 10444 | constructor function. */ |
4edb7b60 | 10445 | if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK) |
7e23cb16 JM |
10446 | { |
10447 | current_function_has_inlines = 0; | |
10448 | decls_for_scope (outer_scope, subr_die, 0); | |
71dfc51f | 10449 | |
ce61cc73 | 10450 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
7e23cb16 JM |
10451 | if (current_function_has_inlines) |
10452 | { | |
10453 | add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1); | |
10454 | if (! comp_unit_has_inlines) | |
10455 | { | |
10456 | add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1); | |
10457 | comp_unit_has_inlines = 1; | |
10458 | } | |
10459 | } | |
10460 | #endif | |
10461 | } | |
a3f97cbb JW |
10462 | } |
10463 | ||
10464 | /* Generate a DIE to represent a declared data object. */ | |
71dfc51f | 10465 | |
a3f97cbb JW |
10466 | static void |
10467 | gen_variable_die (decl, context_die) | |
b3694847 SS |
10468 | tree decl; |
10469 | dw_die_ref context_die; | |
a3f97cbb | 10470 | { |
b3694847 | 10471 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 10472 | dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl); |
71dfc51f | 10473 | |
bdb669cb | 10474 | dw_die_ref old_die = lookup_decl_die (decl); |
9765e357 JM |
10475 | int declaration = (DECL_EXTERNAL (decl) |
10476 | || class_scope_p (context_die)); | |
4edb7b60 | 10477 | |
a3f97cbb | 10478 | if (origin != NULL) |
71dfc51f | 10479 | add_abstract_origin_attribute (var_die, origin); |
2ad9852d | 10480 | |
f76b8156 | 10481 | /* Loop unrolling can create multiple blocks that refer to the same |
2ad9852d RK |
10482 | static variable, so we must test for the DW_AT_declaration flag. |
10483 | ||
10484 | ??? Loop unrolling/reorder_blocks should perhaps be rewritten to | |
f76b8156 | 10485 | copy decls and set the DECL_ABSTRACT flag on them instead of |
2ad9852d RK |
10486 | sharing them. |
10487 | ||
10488 | ??? Duplicated blocks have been rewritten to use .debug_ranges. */ | |
f76b8156 | 10489 | else if (old_die && TREE_STATIC (decl) |
c26fbbca | 10490 | && get_AT_flag (old_die, DW_AT_declaration) == 1) |
bdb669cb | 10491 | { |
e689ae67 | 10492 | /* This is a definition of a C++ class level static. */ |
bdb669cb JM |
10493 | add_AT_die_ref (var_die, DW_AT_specification, old_die); |
10494 | if (DECL_NAME (decl)) | |
10495 | { | |
981975b6 | 10496 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
71dfc51f | 10497 | |
bdb669cb JM |
10498 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
10499 | add_AT_unsigned (var_die, DW_AT_decl_file, file_index); | |
71dfc51f | 10500 | |
bdb669cb | 10501 | if (get_AT_unsigned (old_die, DW_AT_decl_line) |
556273e0 | 10502 | != (unsigned) DECL_SOURCE_LINE (decl)) |
71dfc51f RK |
10503 | |
10504 | add_AT_unsigned (var_die, DW_AT_decl_line, | |
10505 | DECL_SOURCE_LINE (decl)); | |
bdb669cb JM |
10506 | } |
10507 | } | |
a3f97cbb JW |
10508 | else |
10509 | { | |
10510 | add_name_and_src_coords_attributes (var_die, decl); | |
2ad9852d | 10511 | add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl), |
a3f97cbb | 10512 | TREE_THIS_VOLATILE (decl), context_die); |
71dfc51f | 10513 | |
273dbe67 JM |
10514 | if (TREE_PUBLIC (decl)) |
10515 | add_AT_flag (var_die, DW_AT_external, 1); | |
71dfc51f | 10516 | |
273dbe67 JM |
10517 | if (DECL_ARTIFICIAL (decl)) |
10518 | add_AT_flag (var_die, DW_AT_artificial, 1); | |
71dfc51f | 10519 | |
a94dbf2c JM |
10520 | if (TREE_PROTECTED (decl)) |
10521 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected); | |
10522 | else if (TREE_PRIVATE (decl)) | |
10523 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 10524 | } |
4edb7b60 JM |
10525 | |
10526 | if (declaration) | |
10527 | add_AT_flag (var_die, DW_AT_declaration, 1); | |
556273e0 | 10528 | |
9765e357 | 10529 | if (class_scope_p (context_die) || DECL_ABSTRACT (decl)) |
4edb7b60 JM |
10530 | equate_decl_number_to_die (decl, var_die); |
10531 | ||
10532 | if (! declaration && ! DECL_ABSTRACT (decl)) | |
a3f97cbb JW |
10533 | { |
10534 | add_location_or_const_value_attribute (var_die, decl); | |
d291dd49 | 10535 | add_pubname (decl, var_die); |
a3f97cbb | 10536 | } |
1bfb5f8f JM |
10537 | else |
10538 | tree_add_const_value_attribute (var_die, decl); | |
a3f97cbb JW |
10539 | } |
10540 | ||
10541 | /* Generate a DIE to represent a label identifier. */ | |
71dfc51f | 10542 | |
a3f97cbb JW |
10543 | static void |
10544 | gen_label_die (decl, context_die) | |
b3694847 SS |
10545 | tree decl; |
10546 | dw_die_ref context_die; | |
a3f97cbb | 10547 | { |
b3694847 | 10548 | tree origin = decl_ultimate_origin (decl); |
54ba1f0d | 10549 | dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl); |
b3694847 | 10550 | rtx insn; |
a3f97cbb | 10551 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 10552 | |
a3f97cbb | 10553 | if (origin != NULL) |
71dfc51f | 10554 | add_abstract_origin_attribute (lbl_die, origin); |
a3f97cbb | 10555 | else |
71dfc51f RK |
10556 | add_name_and_src_coords_attributes (lbl_die, decl); |
10557 | ||
a3f97cbb | 10558 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 10559 | equate_decl_number_to_die (decl, lbl_die); |
a3f97cbb JW |
10560 | else |
10561 | { | |
10562 | insn = DECL_RTL (decl); | |
088e7160 NC |
10563 | |
10564 | /* Deleted labels are programmer specified labels which have been | |
10565 | eliminated because of various optimisations. We still emit them | |
10566 | here so that it is possible to put breakpoints on them. */ | |
10567 | if (GET_CODE (insn) == CODE_LABEL | |
10568 | || ((GET_CODE (insn) == NOTE | |
10569 | && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))) | |
a3f97cbb | 10570 | { |
556273e0 KH |
10571 | /* When optimization is enabled (via -O) some parts of the compiler |
10572 | (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which | |
a3f97cbb JW |
10573 | represent source-level labels which were explicitly declared by |
10574 | the user. This really shouldn't be happening though, so catch | |
10575 | it if it ever does happen. */ | |
10576 | if (INSN_DELETED_P (insn)) | |
71dfc51f RK |
10577 | abort (); |
10578 | ||
66234570 | 10579 | ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn)); |
a3f97cbb JW |
10580 | add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); |
10581 | } | |
10582 | } | |
10583 | } | |
10584 | ||
10585 | /* Generate a DIE for a lexical block. */ | |
71dfc51f | 10586 | |
a3f97cbb | 10587 | static void |
d7248bff | 10588 | gen_lexical_block_die (stmt, context_die, depth) |
b3694847 SS |
10589 | tree stmt; |
10590 | dw_die_ref context_die; | |
d7248bff | 10591 | int depth; |
a3f97cbb | 10592 | { |
54ba1f0d | 10593 | dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt); |
a3f97cbb | 10594 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f RK |
10595 | |
10596 | if (! BLOCK_ABSTRACT (stmt)) | |
a3f97cbb | 10597 | { |
a20612aa RH |
10598 | if (BLOCK_FRAGMENT_CHAIN (stmt)) |
10599 | { | |
10600 | tree chain; | |
10601 | ||
2bee6045 | 10602 | add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt)); |
a20612aa RH |
10603 | |
10604 | chain = BLOCK_FRAGMENT_CHAIN (stmt); | |
10605 | do | |
10606 | { | |
10607 | add_ranges (chain); | |
10608 | chain = BLOCK_FRAGMENT_CHAIN (chain); | |
10609 | } | |
10610 | while (chain); | |
10611 | add_ranges (NULL); | |
10612 | } | |
10613 | else | |
10614 | { | |
10615 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, | |
10616 | BLOCK_NUMBER (stmt)); | |
10617 | add_AT_lbl_id (stmt_die, DW_AT_low_pc, label); | |
10618 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, | |
10619 | BLOCK_NUMBER (stmt)); | |
10620 | add_AT_lbl_id (stmt_die, DW_AT_high_pc, label); | |
10621 | } | |
a3f97cbb | 10622 | } |
71dfc51f | 10623 | |
d7248bff | 10624 | decls_for_scope (stmt, stmt_die, depth); |
a3f97cbb JW |
10625 | } |
10626 | ||
10627 | /* Generate a DIE for an inlined subprogram. */ | |
71dfc51f | 10628 | |
a3f97cbb | 10629 | static void |
d7248bff | 10630 | gen_inlined_subroutine_die (stmt, context_die, depth) |
b3694847 SS |
10631 | tree stmt; |
10632 | dw_die_ref context_die; | |
d7248bff | 10633 | int depth; |
a3f97cbb | 10634 | { |
71dfc51f | 10635 | if (! BLOCK_ABSTRACT (stmt)) |
a3f97cbb | 10636 | { |
b3694847 | 10637 | dw_die_ref subr_die |
54ba1f0d | 10638 | = new_die (DW_TAG_inlined_subroutine, context_die, stmt); |
b3694847 | 10639 | tree decl = block_ultimate_origin (stmt); |
d7248bff | 10640 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 10641 | |
10a11b75 | 10642 | /* Emit info for the abstract instance first, if we haven't yet. */ |
1edf43d6 | 10643 | dwarf2out_abstract_function (decl); |
10a11b75 | 10644 | |
ab72d377 | 10645 | add_abstract_origin_attribute (subr_die, decl); |
5c90448c | 10646 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
18c038b9 | 10647 | BLOCK_NUMBER (stmt)); |
a3f97cbb | 10648 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label); |
18c038b9 MM |
10649 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, |
10650 | BLOCK_NUMBER (stmt)); | |
a3f97cbb | 10651 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label); |
d7248bff | 10652 | decls_for_scope (stmt, subr_die, depth); |
7e23cb16 | 10653 | current_function_has_inlines = 1; |
a3f97cbb | 10654 | } |
06e224f7 AO |
10655 | else |
10656 | /* We may get here if we're the outer block of function A that was | |
10657 | inlined into function B that was inlined into function C. When | |
10658 | generating debugging info for C, dwarf2out_abstract_function(B) | |
10659 | would mark all inlined blocks as abstract, including this one. | |
10660 | So, we wouldn't (and shouldn't) expect labels to be generated | |
10661 | for this one. Instead, just emit debugging info for | |
10662 | declarations within the block. This is particularly important | |
10663 | in the case of initializers of arguments passed from B to us: | |
10664 | if they're statement expressions containing declarations, we | |
10665 | wouldn't generate dies for their abstract variables, and then, | |
10666 | when generating dies for the real variables, we'd die (pun | |
10667 | intended :-) */ | |
10668 | gen_lexical_block_die (stmt, context_die, depth); | |
a3f97cbb JW |
10669 | } |
10670 | ||
10671 | /* Generate a DIE for a field in a record, or structure. */ | |
71dfc51f | 10672 | |
a3f97cbb JW |
10673 | static void |
10674 | gen_field_die (decl, context_die) | |
b3694847 SS |
10675 | tree decl; |
10676 | dw_die_ref context_die; | |
a3f97cbb | 10677 | { |
54ba1f0d | 10678 | dw_die_ref decl_die = new_die (DW_TAG_member, context_die, decl); |
71dfc51f | 10679 | |
a3f97cbb | 10680 | add_name_and_src_coords_attributes (decl_die, decl); |
a3f97cbb JW |
10681 | add_type_attribute (decl_die, member_declared_type (decl), |
10682 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl), | |
10683 | context_die); | |
71dfc51f | 10684 | |
a3f97cbb JW |
10685 | if (DECL_BIT_FIELD_TYPE (decl)) |
10686 | { | |
10687 | add_byte_size_attribute (decl_die, decl); | |
10688 | add_bit_size_attribute (decl_die, decl); | |
10689 | add_bit_offset_attribute (decl_die, decl); | |
10690 | } | |
71dfc51f | 10691 | |
a94dbf2c JM |
10692 | if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE) |
10693 | add_data_member_location_attribute (decl_die, decl); | |
71dfc51f | 10694 | |
273dbe67 JM |
10695 | if (DECL_ARTIFICIAL (decl)) |
10696 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
71dfc51f | 10697 | |
a94dbf2c JM |
10698 | if (TREE_PROTECTED (decl)) |
10699 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected); | |
10700 | else if (TREE_PRIVATE (decl)) | |
10701 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb JW |
10702 | } |
10703 | ||
ab72d377 JM |
10704 | #if 0 |
10705 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. | |
10706 | Use modified_type_die instead. | |
a3f97cbb JW |
10707 | We keep this code here just in case these types of DIEs may be needed to |
10708 | represent certain things in other languages (e.g. Pascal) someday. */ | |
2ad9852d | 10709 | |
a3f97cbb JW |
10710 | static void |
10711 | gen_pointer_type_die (type, context_die) | |
b3694847 SS |
10712 | tree type; |
10713 | dw_die_ref context_die; | |
a3f97cbb | 10714 | { |
b3694847 | 10715 | dw_die_ref ptr_die |
54ba1f0d | 10716 | = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type); |
71dfc51f | 10717 | |
a3f97cbb | 10718 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 10719 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 10720 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb JW |
10721 | } |
10722 | ||
ab72d377 JM |
10723 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. |
10724 | Use modified_type_die instead. | |
a3f97cbb JW |
10725 | We keep this code here just in case these types of DIEs may be needed to |
10726 | represent certain things in other languages (e.g. Pascal) someday. */ | |
2ad9852d | 10727 | |
a3f97cbb JW |
10728 | static void |
10729 | gen_reference_type_die (type, context_die) | |
b3694847 SS |
10730 | tree type; |
10731 | dw_die_ref context_die; | |
a3f97cbb | 10732 | { |
b3694847 | 10733 | dw_die_ref ref_die |
54ba1f0d | 10734 | = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type); |
71dfc51f | 10735 | |
a3f97cbb | 10736 | equate_type_number_to_die (type, ref_die); |
a3f97cbb | 10737 | add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 10738 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb | 10739 | } |
ab72d377 | 10740 | #endif |
a3f97cbb JW |
10741 | |
10742 | /* Generate a DIE for a pointer to a member type. */ | |
2ad9852d | 10743 | |
a3f97cbb JW |
10744 | static void |
10745 | gen_ptr_to_mbr_type_die (type, context_die) | |
b3694847 SS |
10746 | tree type; |
10747 | dw_die_ref context_die; | |
a3f97cbb | 10748 | { |
b3694847 | 10749 | dw_die_ref ptr_die |
54ba1f0d RH |
10750 | = new_die (DW_TAG_ptr_to_member_type, |
10751 | scope_die_for (type, context_die), type); | |
71dfc51f | 10752 | |
a3f97cbb | 10753 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 10754 | add_AT_die_ref (ptr_die, DW_AT_containing_type, |
bdb669cb | 10755 | lookup_type_die (TYPE_OFFSET_BASETYPE (type))); |
a3f97cbb JW |
10756 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
10757 | } | |
10758 | ||
10759 | /* Generate the DIE for the compilation unit. */ | |
71dfc51f | 10760 | |
a96c67ec JM |
10761 | static dw_die_ref |
10762 | gen_compile_unit_die (filename) | |
b3694847 | 10763 | const char *filename; |
a3f97cbb | 10764 | { |
b3694847 | 10765 | dw_die_ref die; |
a3f97cbb | 10766 | char producer[250]; |
d3e3972c | 10767 | const char *wd = getpwd (); |
3ac88239 | 10768 | const char *language_string = lang_hooks.name; |
a96c67ec | 10769 | int language; |
a3f97cbb | 10770 | |
54ba1f0d | 10771 | die = new_die (DW_TAG_compile_unit, NULL, NULL); |
a96c67ec | 10772 | add_name_attribute (die, filename); |
bdb669cb | 10773 | |
a96c67ec JM |
10774 | if (wd != NULL && filename[0] != DIR_SEPARATOR) |
10775 | add_AT_string (die, DW_AT_comp_dir, wd); | |
a3f97cbb JW |
10776 | |
10777 | sprintf (producer, "%s %s", language_string, version_string); | |
10778 | ||
10779 | #ifdef MIPS_DEBUGGING_INFO | |
10780 | /* The MIPS/SGI compilers place the 'cc' command line options in the producer | |
10781 | string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do | |
10782 | not appear in the producer string, the debugger reaches the conclusion | |
10783 | that the object file is stripped and has no debugging information. | |
10784 | To get the MIPS/SGI debugger to believe that there is debugging | |
10785 | information in the object file, we add a -g to the producer string. */ | |
4927276d JM |
10786 | if (debug_info_level > DINFO_LEVEL_TERSE) |
10787 | strcat (producer, " -g"); | |
a3f97cbb JW |
10788 | #endif |
10789 | ||
a96c67ec | 10790 | add_AT_string (die, DW_AT_producer, producer); |
a9d38797 | 10791 | |
a3f97cbb | 10792 | if (strcmp (language_string, "GNU C++") == 0) |
a96c67ec | 10793 | language = DW_LANG_C_plus_plus; |
a3f97cbb | 10794 | else if (strcmp (language_string, "GNU Ada") == 0) |
a96c67ec | 10795 | language = DW_LANG_Ada83; |
a9d38797 | 10796 | else if (strcmp (language_string, "GNU F77") == 0) |
a96c67ec | 10797 | language = DW_LANG_Fortran77; |
bc28c45b | 10798 | else if (strcmp (language_string, "GNU Pascal") == 0) |
a96c67ec | 10799 | language = DW_LANG_Pascal83; |
28985b81 AG |
10800 | else if (strcmp (language_string, "GNU Java") == 0) |
10801 | language = DW_LANG_Java; | |
a3f97cbb | 10802 | else |
a96c67ec | 10803 | language = DW_LANG_C89; |
a9d38797 | 10804 | |
a96c67ec | 10805 | add_AT_unsigned (die, DW_AT_language, language); |
a96c67ec | 10806 | return die; |
a3f97cbb JW |
10807 | } |
10808 | ||
10809 | /* Generate a DIE for a string type. */ | |
71dfc51f | 10810 | |
a3f97cbb JW |
10811 | static void |
10812 | gen_string_type_die (type, context_die) | |
b3694847 SS |
10813 | tree type; |
10814 | dw_die_ref context_die; | |
a3f97cbb | 10815 | { |
b3694847 | 10816 | dw_die_ref type_die |
54ba1f0d | 10817 | = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type); |
71dfc51f | 10818 | |
bdb669cb | 10819 | equate_type_number_to_die (type, type_die); |
a3f97cbb | 10820 | |
2ad9852d RK |
10821 | /* ??? Fudge the string length attribute for now. |
10822 | TODO: add string length info. */ | |
10823 | #if 0 | |
10824 | string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type))); | |
10825 | bound_representation (upper_bound, 0, 'u'); | |
10826 | #endif | |
a3f97cbb JW |
10827 | } |
10828 | ||
61b32c02 | 10829 | /* Generate the DIE for a base class. */ |
71dfc51f | 10830 | |
61b32c02 JM |
10831 | static void |
10832 | gen_inheritance_die (binfo, context_die) | |
b3694847 SS |
10833 | tree binfo; |
10834 | dw_die_ref context_die; | |
61b32c02 | 10835 | { |
54ba1f0d | 10836 | dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo); |
71dfc51f | 10837 | |
61b32c02 JM |
10838 | add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die); |
10839 | add_data_member_location_attribute (die, binfo); | |
71dfc51f | 10840 | |
61b32c02 JM |
10841 | if (TREE_VIA_VIRTUAL (binfo)) |
10842 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); | |
2ad9852d | 10843 | |
61b32c02 JM |
10844 | if (TREE_VIA_PUBLIC (binfo)) |
10845 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public); | |
10846 | else if (TREE_VIA_PROTECTED (binfo)) | |
10847 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected); | |
10848 | } | |
10849 | ||
956d6950 | 10850 | /* Generate a DIE for a class member. */ |
71dfc51f | 10851 | |
a3f97cbb JW |
10852 | static void |
10853 | gen_member_die (type, context_die) | |
b3694847 SS |
10854 | tree type; |
10855 | dw_die_ref context_die; | |
a3f97cbb | 10856 | { |
b3694847 | 10857 | tree member; |
10a11b75 | 10858 | dw_die_ref child; |
71dfc51f | 10859 | |
a3f97cbb JW |
10860 | /* If this is not an incomplete type, output descriptions of each of its |
10861 | members. Note that as we output the DIEs necessary to represent the | |
10862 | members of this record or union type, we will also be trying to output | |
10863 | DIEs to represent the *types* of those members. However the `type' | |
556273e0 | 10864 | function (above) will specifically avoid generating type DIEs for member |
eaec9b3d | 10865 | types *within* the list of member DIEs for this (containing) type except |
a3f97cbb JW |
10866 | for those types (of members) which are explicitly marked as also being |
10867 | members of this (containing) type themselves. The g++ front- end can | |
2ad9852d RK |
10868 | force any given type to be treated as a member of some other (containing) |
10869 | type by setting the TYPE_CONTEXT of the given (member) type to point to | |
10870 | the TREE node representing the appropriate (containing) type. */ | |
a3f97cbb | 10871 | |
61b32c02 JM |
10872 | /* First output info about the base classes. */ |
10873 | if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type)) | |
a3f97cbb | 10874 | { |
b3694847 SS |
10875 | tree bases = TYPE_BINFO_BASETYPES (type); |
10876 | int n_bases = TREE_VEC_LENGTH (bases); | |
10877 | int i; | |
61b32c02 JM |
10878 | |
10879 | for (i = 0; i < n_bases; i++) | |
10880 | gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die); | |
a3f97cbb JW |
10881 | } |
10882 | ||
61b32c02 JM |
10883 | /* Now output info about the data members and type members. */ |
10884 | for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member)) | |
10a11b75 JM |
10885 | { |
10886 | /* If we thought we were generating minimal debug info for TYPE | |
10887 | and then changed our minds, some of the member declarations | |
10888 | may have already been defined. Don't define them again, but | |
10889 | do put them in the right order. */ | |
10890 | ||
10891 | child = lookup_decl_die (member); | |
10892 | if (child) | |
10893 | splice_child_die (context_die, child); | |
10894 | else | |
10895 | gen_decl_die (member, context_die); | |
10896 | } | |
61b32c02 | 10897 | |
a3f97cbb | 10898 | /* Now output info about the function members (if any). */ |
61b32c02 | 10899 | for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member)) |
10a11b75 | 10900 | { |
5daf7c0a JM |
10901 | /* Don't include clones in the member list. */ |
10902 | if (DECL_ABSTRACT_ORIGIN (member)) | |
10903 | continue; | |
10904 | ||
10a11b75 JM |
10905 | child = lookup_decl_die (member); |
10906 | if (child) | |
10907 | splice_child_die (context_die, child); | |
10908 | else | |
10909 | gen_decl_die (member, context_die); | |
10910 | } | |
a3f97cbb JW |
10911 | } |
10912 | ||
10a11b75 JM |
10913 | /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG |
10914 | is set, we pretend that the type was never defined, so we only get the | |
10915 | member DIEs needed by later specification DIEs. */ | |
71dfc51f | 10916 | |
a3f97cbb | 10917 | static void |
273dbe67 | 10918 | gen_struct_or_union_type_die (type, context_die) |
b3694847 SS |
10919 | tree type; |
10920 | dw_die_ref context_die; | |
a3f97cbb | 10921 | { |
b3694847 SS |
10922 | dw_die_ref type_die = lookup_type_die (type); |
10923 | dw_die_ref scope_die = 0; | |
10924 | int nested = 0; | |
10a11b75 | 10925 | int complete = (TYPE_SIZE (type) |
65e1263a JW |
10926 | && (! TYPE_STUB_DECL (type) |
10927 | || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)))); | |
273dbe67 | 10928 | |
10a11b75 | 10929 | if (type_die && ! complete) |
273dbe67 | 10930 | return; |
a082c85a | 10931 | |
71dfc51f | 10932 | if (TYPE_CONTEXT (type) != NULL_TREE |
5f2f160c | 10933 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))) |
a082c85a JM |
10934 | nested = 1; |
10935 | ||
a94dbf2c | 10936 | scope_die = scope_die_for (type, context_die); |
a082c85a JM |
10937 | |
10938 | if (! type_die || (nested && scope_die == comp_unit_die)) | |
273dbe67 | 10939 | /* First occurrence of type or toplevel definition of nested class. */ |
a3f97cbb | 10940 | { |
b3694847 | 10941 | dw_die_ref old_die = type_die; |
71dfc51f | 10942 | |
a3f97cbb JW |
10943 | type_die = new_die (TREE_CODE (type) == RECORD_TYPE |
10944 | ? DW_TAG_structure_type : DW_TAG_union_type, | |
54ba1f0d | 10945 | scope_die, type); |
a3f97cbb | 10946 | equate_type_number_to_die (type, type_die); |
273dbe67 JM |
10947 | if (old_die) |
10948 | add_AT_die_ref (type_die, DW_AT_specification, old_die); | |
5de0e8d4 JM |
10949 | else |
10950 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 10951 | } |
4b674448 | 10952 | else |
273dbe67 | 10953 | remove_AT (type_die, DW_AT_declaration); |
a3f97cbb JW |
10954 | |
10955 | /* If this type has been completed, then give it a byte_size attribute and | |
10956 | then give a list of members. */ | |
2081603c | 10957 | if (complete) |
a3f97cbb | 10958 | { |
556273e0 | 10959 | /* Prevent infinite recursion in cases where the type of some member of |
a3f97cbb JW |
10960 | this type is expressed in terms of this type itself. */ |
10961 | TREE_ASM_WRITTEN (type) = 1; | |
273dbe67 | 10962 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 10963 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 10964 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 10965 | |
ef76d03b JW |
10966 | /* If the first reference to this type was as the return type of an |
10967 | inline function, then it may not have a parent. Fix this now. */ | |
10968 | if (type_die->die_parent == NULL) | |
10969 | add_child_die (scope_die, type_die); | |
10970 | ||
273dbe67 JM |
10971 | push_decl_scope (type); |
10972 | gen_member_die (type, type_die); | |
10973 | pop_decl_scope (); | |
71dfc51f | 10974 | |
a94dbf2c JM |
10975 | /* GNU extension: Record what type our vtable lives in. */ |
10976 | if (TYPE_VFIELD (type)) | |
10977 | { | |
10978 | tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type)); | |
71dfc51f | 10979 | |
de6e505e JM |
10980 | gen_type_die (vtype, context_die); |
10981 | add_AT_die_ref (type_die, DW_AT_containing_type, | |
10982 | lookup_type_die (vtype)); | |
a94dbf2c | 10983 | } |
a3f97cbb | 10984 | } |
4b674448 | 10985 | else |
8a8c3656 JM |
10986 | { |
10987 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a30d4514 | 10988 | |
9765e357 | 10989 | /* We don't need to do this for function-local types. */ |
9702143f RK |
10990 | if (TYPE_STUB_DECL (type) |
10991 | && ! decl_function_context (TYPE_STUB_DECL (type))) | |
2ad9852d | 10992 | VARRAY_PUSH_TREE (incomplete_types, type); |
8a8c3656 | 10993 | } |
a3f97cbb JW |
10994 | } |
10995 | ||
10996 | /* Generate a DIE for a subroutine _type_. */ | |
71dfc51f | 10997 | |
a3f97cbb JW |
10998 | static void |
10999 | gen_subroutine_type_die (type, context_die) | |
b3694847 SS |
11000 | tree type; |
11001 | dw_die_ref context_die; | |
a3f97cbb | 11002 | { |
b3694847 SS |
11003 | tree return_type = TREE_TYPE (type); |
11004 | dw_die_ref subr_die | |
54ba1f0d RH |
11005 | = new_die (DW_TAG_subroutine_type, |
11006 | scope_die_for (type, context_die), type); | |
71dfc51f | 11007 | |
a3f97cbb JW |
11008 | equate_type_number_to_die (type, subr_die); |
11009 | add_prototyped_attribute (subr_die, type); | |
a3f97cbb | 11010 | add_type_attribute (subr_die, return_type, 0, 0, context_die); |
a94dbf2c | 11011 | gen_formal_types_die (type, subr_die); |
a3f97cbb JW |
11012 | } |
11013 | ||
11014 | /* Generate a DIE for a type definition */ | |
71dfc51f | 11015 | |
a3f97cbb JW |
11016 | static void |
11017 | gen_typedef_die (decl, context_die) | |
b3694847 SS |
11018 | tree decl; |
11019 | dw_die_ref context_die; | |
a3f97cbb | 11020 | { |
b3694847 SS |
11021 | dw_die_ref type_die; |
11022 | tree origin; | |
a94dbf2c JM |
11023 | |
11024 | if (TREE_ASM_WRITTEN (decl)) | |
11025 | return; | |
a94dbf2c | 11026 | |
2ad9852d | 11027 | TREE_ASM_WRITTEN (decl) = 1; |
54ba1f0d | 11028 | type_die = new_die (DW_TAG_typedef, context_die, decl); |
a94dbf2c | 11029 | origin = decl_ultimate_origin (decl); |
a3f97cbb | 11030 | if (origin != NULL) |
a94dbf2c | 11031 | add_abstract_origin_attribute (type_die, origin); |
a3f97cbb JW |
11032 | else |
11033 | { | |
b3694847 | 11034 | tree type; |
2ad9852d | 11035 | |
a3f97cbb | 11036 | add_name_and_src_coords_attributes (type_die, decl); |
a94dbf2c JM |
11037 | if (DECL_ORIGINAL_TYPE (decl)) |
11038 | { | |
11039 | type = DECL_ORIGINAL_TYPE (decl); | |
62e3bf54 JM |
11040 | |
11041 | if (type == TREE_TYPE (decl)) | |
11042 | abort (); | |
11043 | else | |
11044 | equate_type_number_to_die (TREE_TYPE (decl), type_die); | |
a94dbf2c JM |
11045 | } |
11046 | else | |
11047 | type = TREE_TYPE (decl); | |
2ad9852d | 11048 | |
a94dbf2c JM |
11049 | add_type_attribute (type_die, type, TREE_READONLY (decl), |
11050 | TREE_THIS_VOLATILE (decl), context_die); | |
a3f97cbb | 11051 | } |
71dfc51f | 11052 | |
a3f97cbb | 11053 | if (DECL_ABSTRACT (decl)) |
a94dbf2c | 11054 | equate_decl_number_to_die (decl, type_die); |
a3f97cbb JW |
11055 | } |
11056 | ||
11057 | /* Generate a type description DIE. */ | |
71dfc51f | 11058 | |
a3f97cbb JW |
11059 | static void |
11060 | gen_type_die (type, context_die) | |
b3694847 SS |
11061 | tree type; |
11062 | dw_die_ref context_die; | |
a3f97cbb | 11063 | { |
348bb3c7 JM |
11064 | int need_pop; |
11065 | ||
71dfc51f RK |
11066 | if (type == NULL_TREE || type == error_mark_node) |
11067 | return; | |
a3f97cbb | 11068 | |
0e98f924 AH |
11069 | /* We are going to output a DIE to represent the unqualified version |
11070 | of this type (i.e. without any const or volatile qualifiers) so | |
11071 | get the main variant (i.e. the unqualified version) of this type | |
11072 | now. (Vectors are special because the debugging info is in the | |
11073 | cloned type itself). */ | |
11074 | if (TREE_CODE (type) != VECTOR_TYPE) | |
11075 | type = type_main_variant (type); | |
a3f97cbb JW |
11076 | |
11077 | if (TREE_ASM_WRITTEN (type)) | |
71dfc51f | 11078 | return; |
a3f97cbb | 11079 | |
a94dbf2c JM |
11080 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
11081 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
556273e0 | 11082 | { |
29b91443 JM |
11083 | /* Prevent broken recursion; we can't hand off to the same type. */ |
11084 | if (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) == type) | |
11085 | abort (); | |
11086 | ||
a94dbf2c JM |
11087 | TREE_ASM_WRITTEN (type) = 1; |
11088 | gen_decl_die (TYPE_NAME (type), context_die); | |
11089 | return; | |
11090 | } | |
11091 | ||
a3f97cbb JW |
11092 | switch (TREE_CODE (type)) |
11093 | { | |
11094 | case ERROR_MARK: | |
11095 | break; | |
11096 | ||
11097 | case POINTER_TYPE: | |
11098 | case REFERENCE_TYPE: | |
956d6950 JL |
11099 | /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This |
11100 | ensures that the gen_type_die recursion will terminate even if the | |
11101 | type is recursive. Recursive types are possible in Ada. */ | |
11102 | /* ??? We could perhaps do this for all types before the switch | |
11103 | statement. */ | |
11104 | TREE_ASM_WRITTEN (type) = 1; | |
11105 | ||
a3f97cbb JW |
11106 | /* For these types, all that is required is that we output a DIE (or a |
11107 | set of DIEs) to represent the "basis" type. */ | |
11108 | gen_type_die (TREE_TYPE (type), context_die); | |
11109 | break; | |
11110 | ||
11111 | case OFFSET_TYPE: | |
556273e0 | 11112 | /* This code is used for C++ pointer-to-data-member types. |
71dfc51f | 11113 | Output a description of the relevant class type. */ |
a3f97cbb | 11114 | gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die); |
71dfc51f | 11115 | |
a3f97cbb JW |
11116 | /* Output a description of the type of the object pointed to. */ |
11117 | gen_type_die (TREE_TYPE (type), context_die); | |
71dfc51f | 11118 | |
a3f97cbb JW |
11119 | /* Now output a DIE to represent this pointer-to-data-member type |
11120 | itself. */ | |
11121 | gen_ptr_to_mbr_type_die (type, context_die); | |
11122 | break; | |
11123 | ||
11124 | case SET_TYPE: | |
11125 | gen_type_die (TYPE_DOMAIN (type), context_die); | |
11126 | gen_set_type_die (type, context_die); | |
11127 | break; | |
11128 | ||
11129 | case FILE_TYPE: | |
11130 | gen_type_die (TREE_TYPE (type), context_die); | |
11131 | abort (); /* No way to represent these in Dwarf yet! */ | |
11132 | break; | |
11133 | ||
11134 | case FUNCTION_TYPE: | |
11135 | /* Force out return type (in case it wasn't forced out already). */ | |
11136 | gen_type_die (TREE_TYPE (type), context_die); | |
11137 | gen_subroutine_type_die (type, context_die); | |
11138 | break; | |
11139 | ||
11140 | case METHOD_TYPE: | |
11141 | /* Force out return type (in case it wasn't forced out already). */ | |
11142 | gen_type_die (TREE_TYPE (type), context_die); | |
11143 | gen_subroutine_type_die (type, context_die); | |
11144 | break; | |
11145 | ||
11146 | case ARRAY_TYPE: | |
11147 | if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE) | |
11148 | { | |
11149 | gen_type_die (TREE_TYPE (type), context_die); | |
11150 | gen_string_type_die (type, context_die); | |
11151 | } | |
11152 | else | |
71dfc51f | 11153 | gen_array_type_die (type, context_die); |
a3f97cbb JW |
11154 | break; |
11155 | ||
4061f623 | 11156 | case VECTOR_TYPE: |
84f0ace0 | 11157 | gen_array_type_die (type, context_die); |
4061f623 BS |
11158 | break; |
11159 | ||
a3f97cbb JW |
11160 | case ENUMERAL_TYPE: |
11161 | case RECORD_TYPE: | |
11162 | case UNION_TYPE: | |
11163 | case QUAL_UNION_TYPE: | |
2ad9852d RK |
11164 | /* If this is a nested type whose containing class hasn't been written |
11165 | out yet, writing it out will cover this one, too. This does not apply | |
11166 | to instantiations of member class templates; they need to be added to | |
11167 | the containing class as they are generated. FIXME: This hurts the | |
11168 | idea of combining type decls from multiple TUs, since we can't predict | |
11169 | what set of template instantiations we'll get. */ | |
a082c85a | 11170 | if (TYPE_CONTEXT (type) |
5f2f160c | 11171 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) |
a082c85a | 11172 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) |
a94dbf2c JM |
11173 | { |
11174 | gen_type_die (TYPE_CONTEXT (type), context_die); | |
11175 | ||
348bb3c7 | 11176 | if (TREE_ASM_WRITTEN (type)) |
a94dbf2c JM |
11177 | return; |
11178 | ||
11179 | /* If that failed, attach ourselves to the stub. */ | |
11180 | push_decl_scope (TYPE_CONTEXT (type)); | |
11181 | context_die = lookup_type_die (TYPE_CONTEXT (type)); | |
348bb3c7 | 11182 | need_pop = 1; |
a94dbf2c | 11183 | } |
348bb3c7 JM |
11184 | else |
11185 | need_pop = 0; | |
a94dbf2c JM |
11186 | |
11187 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
273dbe67 | 11188 | gen_enumeration_type_die (type, context_die); |
a3f97cbb | 11189 | else |
273dbe67 | 11190 | gen_struct_or_union_type_die (type, context_die); |
4b674448 | 11191 | |
348bb3c7 | 11192 | if (need_pop) |
a94dbf2c JM |
11193 | pop_decl_scope (); |
11194 | ||
4b674448 | 11195 | /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix |
a082c85a JM |
11196 | it up if it is ever completed. gen_*_type_die will set it for us |
11197 | when appropriate. */ | |
11198 | return; | |
a3f97cbb JW |
11199 | |
11200 | case VOID_TYPE: | |
11201 | case INTEGER_TYPE: | |
11202 | case REAL_TYPE: | |
11203 | case COMPLEX_TYPE: | |
11204 | case BOOLEAN_TYPE: | |
11205 | case CHAR_TYPE: | |
11206 | /* No DIEs needed for fundamental types. */ | |
11207 | break; | |
11208 | ||
11209 | case LANG_TYPE: | |
11210 | /* No Dwarf representation currently defined. */ | |
11211 | break; | |
11212 | ||
11213 | default: | |
11214 | abort (); | |
11215 | } | |
11216 | ||
11217 | TREE_ASM_WRITTEN (type) = 1; | |
11218 | } | |
11219 | ||
11220 | /* Generate a DIE for a tagged type instantiation. */ | |
71dfc51f | 11221 | |
a3f97cbb JW |
11222 | static void |
11223 | gen_tagged_type_instantiation_die (type, context_die) | |
b3694847 SS |
11224 | tree type; |
11225 | dw_die_ref context_die; | |
a3f97cbb | 11226 | { |
71dfc51f RK |
11227 | if (type == NULL_TREE || type == error_mark_node) |
11228 | return; | |
a3f97cbb | 11229 | |
38e01259 | 11230 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
11231 | this type (i.e. without any const or volatile qualifiers) so make sure |
11232 | that we have the main variant (i.e. the unqualified version) of this | |
11233 | type now. */ | |
bbc6ae08 | 11234 | if (type != type_main_variant (type)) |
3a88cbd1 | 11235 | abort (); |
a3f97cbb | 11236 | |
203588e7 | 11237 | /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is |
bbc6ae08 | 11238 | an instance of an unresolved type. */ |
556273e0 | 11239 | |
a3f97cbb JW |
11240 | switch (TREE_CODE (type)) |
11241 | { | |
11242 | case ERROR_MARK: | |
11243 | break; | |
11244 | ||
11245 | case ENUMERAL_TYPE: | |
11246 | gen_inlined_enumeration_type_die (type, context_die); | |
11247 | break; | |
11248 | ||
11249 | case RECORD_TYPE: | |
11250 | gen_inlined_structure_type_die (type, context_die); | |
11251 | break; | |
11252 | ||
11253 | case UNION_TYPE: | |
11254 | case QUAL_UNION_TYPE: | |
11255 | gen_inlined_union_type_die (type, context_die); | |
11256 | break; | |
11257 | ||
11258 | default: | |
71dfc51f | 11259 | abort (); |
a3f97cbb JW |
11260 | } |
11261 | } | |
11262 | ||
11263 | /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the | |
11264 | things which are local to the given block. */ | |
71dfc51f | 11265 | |
a3f97cbb | 11266 | static void |
d7248bff | 11267 | gen_block_die (stmt, context_die, depth) |
b3694847 SS |
11268 | tree stmt; |
11269 | dw_die_ref context_die; | |
d7248bff | 11270 | int depth; |
a3f97cbb | 11271 | { |
b3694847 SS |
11272 | int must_output_die = 0; |
11273 | tree origin; | |
11274 | tree decl; | |
11275 | enum tree_code origin_code; | |
a3f97cbb JW |
11276 | |
11277 | /* Ignore blocks never really used to make RTL. */ | |
1e7f092a JM |
11278 | if (stmt == NULL_TREE || !TREE_USED (stmt) |
11279 | || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt))) | |
71dfc51f | 11280 | return; |
a3f97cbb | 11281 | |
a20612aa RH |
11282 | /* If the block is one fragment of a non-contiguous block, do not |
11283 | process the variables, since they will have been done by the | |
11284 | origin block. Do process subblocks. */ | |
11285 | if (BLOCK_FRAGMENT_ORIGIN (stmt)) | |
11286 | { | |
11287 | tree sub; | |
11288 | ||
2ad9852d | 11289 | for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub)) |
a20612aa | 11290 | gen_block_die (sub, context_die, depth + 1); |
2ad9852d | 11291 | |
a20612aa RH |
11292 | return; |
11293 | } | |
11294 | ||
a3f97cbb JW |
11295 | /* Determine the "ultimate origin" of this block. This block may be an |
11296 | inlined instance of an inlined instance of inline function, so we have | |
11297 | to trace all of the way back through the origin chain to find out what | |
11298 | sort of node actually served as the original seed for the creation of | |
11299 | the current block. */ | |
11300 | origin = block_ultimate_origin (stmt); | |
11301 | origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; | |
11302 | ||
11303 | /* Determine if we need to output any Dwarf DIEs at all to represent this | |
11304 | block. */ | |
11305 | if (origin_code == FUNCTION_DECL) | |
71dfc51f RK |
11306 | /* The outer scopes for inlinings *must* always be represented. We |
11307 | generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */ | |
11308 | must_output_die = 1; | |
a3f97cbb JW |
11309 | else |
11310 | { | |
11311 | /* In the case where the current block represents an inlining of the | |
556273e0 | 11312 | "body block" of an inline function, we must *NOT* output any DIE for |
2ad9852d RK |
11313 | this block because we have already output a DIE to represent the whole |
11314 | inlined function scope and the "body block" of any function doesn't | |
11315 | really represent a different scope according to ANSI C rules. So we | |
11316 | check here to make sure that this block does not represent a "body | |
11317 | block inlining" before trying to set the MUST_OUTPUT_DIE flag. */ | |
d7248bff | 11318 | if (! is_body_block (origin ? origin : stmt)) |
a3f97cbb JW |
11319 | { |
11320 | /* Determine if this block directly contains any "significant" | |
11321 | local declarations which we will need to output DIEs for. */ | |
11322 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
71dfc51f RK |
11323 | /* We are not in terse mode so *any* local declaration counts |
11324 | as being a "significant" one. */ | |
11325 | must_output_die = (BLOCK_VARS (stmt) != NULL); | |
a3f97cbb | 11326 | else |
71dfc51f RK |
11327 | /* We are in terse mode, so only local (nested) function |
11328 | definitions count as "significant" local declarations. */ | |
11329 | for (decl = BLOCK_VARS (stmt); | |
11330 | decl != NULL; decl = TREE_CHAIN (decl)) | |
11331 | if (TREE_CODE (decl) == FUNCTION_DECL | |
11332 | && DECL_INITIAL (decl)) | |
a3f97cbb | 11333 | { |
71dfc51f RK |
11334 | must_output_die = 1; |
11335 | break; | |
a3f97cbb | 11336 | } |
a3f97cbb JW |
11337 | } |
11338 | } | |
11339 | ||
11340 | /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block | |
11341 | DIE for any block which contains no significant local declarations at | |
11342 | all. Rather, in such cases we just call `decls_for_scope' so that any | |
11343 | needed Dwarf info for any sub-blocks will get properly generated. Note | |
11344 | that in terse mode, our definition of what constitutes a "significant" | |
11345 | local declaration gets restricted to include only inlined function | |
11346 | instances and local (nested) function definitions. */ | |
11347 | if (must_output_die) | |
11348 | { | |
11349 | if (origin_code == FUNCTION_DECL) | |
71dfc51f | 11350 | gen_inlined_subroutine_die (stmt, context_die, depth); |
a3f97cbb | 11351 | else |
71dfc51f | 11352 | gen_lexical_block_die (stmt, context_die, depth); |
a3f97cbb JW |
11353 | } |
11354 | else | |
d7248bff | 11355 | decls_for_scope (stmt, context_die, depth); |
a3f97cbb JW |
11356 | } |
11357 | ||
11358 | /* Generate all of the decls declared within a given scope and (recursively) | |
9ec36da5 | 11359 | all of its sub-blocks. */ |
71dfc51f | 11360 | |
a3f97cbb | 11361 | static void |
d7248bff | 11362 | decls_for_scope (stmt, context_die, depth) |
b3694847 SS |
11363 | tree stmt; |
11364 | dw_die_ref context_die; | |
d7248bff | 11365 | int depth; |
a3f97cbb | 11366 | { |
b3694847 SS |
11367 | tree decl; |
11368 | tree subblocks; | |
71dfc51f | 11369 | |
a3f97cbb | 11370 | /* Ignore blocks never really used to make RTL. */ |
71dfc51f RK |
11371 | if (stmt == NULL_TREE || ! TREE_USED (stmt)) |
11372 | return; | |
11373 | ||
88dad228 JM |
11374 | /* Output the DIEs to represent all of the data objects and typedefs |
11375 | declared directly within this block but not within any nested | |
11376 | sub-blocks. Also, nested function and tag DIEs have been | |
11377 | generated with a parent of NULL; fix that up now. */ | |
2ad9852d | 11378 | for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl)) |
a3f97cbb | 11379 | { |
b3694847 | 11380 | dw_die_ref die; |
a94dbf2c | 11381 | |
88dad228 | 11382 | if (TREE_CODE (decl) == FUNCTION_DECL) |
a94dbf2c | 11383 | die = lookup_decl_die (decl); |
88dad228 | 11384 | else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)) |
a94dbf2c JM |
11385 | die = lookup_type_die (TREE_TYPE (decl)); |
11386 | else | |
11387 | die = NULL; | |
11388 | ||
71dfc51f | 11389 | if (die != NULL && die->die_parent == NULL) |
ef76d03b | 11390 | add_child_die (context_die, die); |
88dad228 JM |
11391 | else |
11392 | gen_decl_die (decl, context_die); | |
a3f97cbb JW |
11393 | } |
11394 | ||
11395 | /* Output the DIEs to represent all sub-blocks (and the items declared | |
11396 | therein) of this block. */ | |
11397 | for (subblocks = BLOCK_SUBBLOCKS (stmt); | |
11398 | subblocks != NULL; | |
11399 | subblocks = BLOCK_CHAIN (subblocks)) | |
71dfc51f | 11400 | gen_block_die (subblocks, context_die, depth + 1); |
a3f97cbb JW |
11401 | } |
11402 | ||
a94dbf2c | 11403 | /* Is this a typedef we can avoid emitting? */ |
71dfc51f RK |
11404 | |
11405 | static inline int | |
a94dbf2c | 11406 | is_redundant_typedef (decl) |
b3694847 | 11407 | tree decl; |
a94dbf2c JM |
11408 | { |
11409 | if (TYPE_DECL_IS_STUB (decl)) | |
11410 | return 1; | |
71dfc51f | 11411 | |
a94dbf2c JM |
11412 | if (DECL_ARTIFICIAL (decl) |
11413 | && DECL_CONTEXT (decl) | |
11414 | && is_tagged_type (DECL_CONTEXT (decl)) | |
11415 | && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL | |
11416 | && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) | |
11417 | /* Also ignore the artificial member typedef for the class name. */ | |
11418 | return 1; | |
71dfc51f | 11419 | |
a94dbf2c JM |
11420 | return 0; |
11421 | } | |
11422 | ||
a3f97cbb | 11423 | /* Generate Dwarf debug information for a decl described by DECL. */ |
71dfc51f | 11424 | |
a3f97cbb JW |
11425 | static void |
11426 | gen_decl_die (decl, context_die) | |
b3694847 SS |
11427 | tree decl; |
11428 | dw_die_ref context_die; | |
a3f97cbb | 11429 | { |
b3694847 | 11430 | tree origin; |
71dfc51f | 11431 | |
f11c3043 | 11432 | if (DECL_P (decl) && DECL_IGNORED_P (decl)) |
71dfc51f | 11433 | return; |
a3f97cbb | 11434 | |
a3f97cbb JW |
11435 | switch (TREE_CODE (decl)) |
11436 | { | |
2ad9852d RK |
11437 | case ERROR_MARK: |
11438 | break; | |
11439 | ||
a3f97cbb | 11440 | case CONST_DECL: |
556273e0 | 11441 | /* The individual enumerators of an enum type get output when we output |
a3f97cbb JW |
11442 | the Dwarf representation of the relevant enum type itself. */ |
11443 | break; | |
11444 | ||
11445 | case FUNCTION_DECL: | |
4edb7b60 JM |
11446 | /* Don't output any DIEs to represent mere function declarations, |
11447 | unless they are class members or explicit block externs. */ | |
11448 | if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE | |
777ad4c2 | 11449 | && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl))) |
71dfc51f | 11450 | break; |
bdb669cb | 11451 | |
5daf7c0a JM |
11452 | /* If we're emitting a clone, emit info for the abstract instance. */ |
11453 | if (DECL_ORIGIN (decl) != decl) | |
11454 | dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl)); | |
2ad9852d | 11455 | |
1cfdcc15 JM |
11456 | /* If we're emitting an out-of-line copy of an inline function, |
11457 | emit info for the abstract instance and set up to refer to it. */ | |
5daf7c0a JM |
11458 | else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl) |
11459 | && ! class_scope_p (context_die) | |
11460 | /* dwarf2out_abstract_function won't emit a die if this is just | |
11461 | a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in | |
11462 | that case, because that works only if we have a die. */ | |
11463 | && DECL_INITIAL (decl) != NULL_TREE) | |
1cfdcc15 | 11464 | { |
1edf43d6 | 11465 | dwarf2out_abstract_function (decl); |
1cfdcc15 JM |
11466 | set_decl_origin_self (decl); |
11467 | } | |
2ad9852d | 11468 | |
5daf7c0a JM |
11469 | /* Otherwise we're emitting the primary DIE for this decl. */ |
11470 | else if (debug_info_level > DINFO_LEVEL_TERSE) | |
a94dbf2c JM |
11471 | { |
11472 | /* Before we describe the FUNCTION_DECL itself, make sure that we | |
11473 | have described its return type. */ | |
11474 | gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); | |
11475 | ||
2081603c JM |
11476 | /* And its virtual context. */ |
11477 | if (DECL_VINDEX (decl) != NULL_TREE) | |
11478 | gen_type_die (DECL_CONTEXT (decl), context_die); | |
11479 | ||
a94dbf2c JM |
11480 | /* And its containing type. */ |
11481 | origin = decl_class_context (decl); | |
71dfc51f | 11482 | if (origin != NULL_TREE) |
10a11b75 | 11483 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 11484 | } |
a3f97cbb JW |
11485 | |
11486 | /* Now output a DIE to represent the function itself. */ | |
11487 | gen_subprogram_die (decl, context_die); | |
11488 | break; | |
11489 | ||
11490 | case TYPE_DECL: | |
11491 | /* If we are in terse mode, don't generate any DIEs to represent any | |
4927276d | 11492 | actual typedefs. */ |
a3f97cbb | 11493 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 11494 | break; |
a3f97cbb | 11495 | |
2ad9852d RK |
11496 | /* In the special case of a TYPE_DECL node representing the declaration |
11497 | of some type tag, if the given TYPE_DECL is marked as having been | |
11498 | instantiated from some other (original) TYPE_DECL node (e.g. one which | |
11499 | was generated within the original definition of an inline function) we | |
11500 | have to generate a special (abbreviated) DW_TAG_structure_type, | |
11501 | DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */ | |
2081603c | 11502 | if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE) |
a3f97cbb JW |
11503 | { |
11504 | gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die); | |
11505 | break; | |
11506 | } | |
a3f97cbb | 11507 | |
a94dbf2c JM |
11508 | if (is_redundant_typedef (decl)) |
11509 | gen_type_die (TREE_TYPE (decl), context_die); | |
11510 | else | |
71dfc51f RK |
11511 | /* Output a DIE to represent the typedef itself. */ |
11512 | gen_typedef_die (decl, context_die); | |
a3f97cbb JW |
11513 | break; |
11514 | ||
11515 | case LABEL_DECL: | |
11516 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
71dfc51f | 11517 | gen_label_die (decl, context_die); |
a3f97cbb JW |
11518 | break; |
11519 | ||
11520 | case VAR_DECL: | |
11521 | /* If we are in terse mode, don't generate any DIEs to represent any | |
11522 | variable declarations or definitions. */ | |
11523 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 11524 | break; |
a3f97cbb JW |
11525 | |
11526 | /* Output any DIEs that are needed to specify the type of this data | |
11527 | object. */ | |
11528 | gen_type_die (TREE_TYPE (decl), context_die); | |
11529 | ||
a94dbf2c JM |
11530 | /* And its containing type. */ |
11531 | origin = decl_class_context (decl); | |
71dfc51f | 11532 | if (origin != NULL_TREE) |
10a11b75 | 11533 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 11534 | |
a3f97cbb JW |
11535 | /* Now output the DIE to represent the data object itself. This gets |
11536 | complicated because of the possibility that the VAR_DECL really | |
11537 | represents an inlined instance of a formal parameter for an inline | |
11538 | function. */ | |
11539 | origin = decl_ultimate_origin (decl); | |
71dfc51f RK |
11540 | if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL) |
11541 | gen_formal_parameter_die (decl, context_die); | |
a3f97cbb | 11542 | else |
71dfc51f | 11543 | gen_variable_die (decl, context_die); |
a3f97cbb JW |
11544 | break; |
11545 | ||
11546 | case FIELD_DECL: | |
2ad9852d RK |
11547 | /* Ignore the nameless fields that are used to skip bits but handle C++ |
11548 | anonymous unions. */ | |
71dfc51f RK |
11549 | if (DECL_NAME (decl) != NULL_TREE |
11550 | || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE) | |
a3f97cbb JW |
11551 | { |
11552 | gen_type_die (member_declared_type (decl), context_die); | |
11553 | gen_field_die (decl, context_die); | |
11554 | } | |
11555 | break; | |
11556 | ||
11557 | case PARM_DECL: | |
11558 | gen_type_die (TREE_TYPE (decl), context_die); | |
11559 | gen_formal_parameter_die (decl, context_die); | |
11560 | break; | |
11561 | ||
348bb3c7 JM |
11562 | case NAMESPACE_DECL: |
11563 | /* Ignore for now. */ | |
11564 | break; | |
11565 | ||
a3f97cbb JW |
11566 | default: |
11567 | abort (); | |
11568 | } | |
a3f97cbb | 11569 | } |
54ba1f0d RH |
11570 | |
11571 | static void | |
11572 | mark_limbo_die_list (ptr) | |
11573 | void *ptr ATTRIBUTE_UNUSED; | |
11574 | { | |
11575 | limbo_die_node *node; | |
c26fbbca | 11576 | for (node = limbo_die_list; node; node = node->next) |
54ba1f0d RH |
11577 | ggc_mark_tree (node->created_for); |
11578 | } | |
a3f97cbb | 11579 | \f |
14a774a9 RK |
11580 | /* Add Ada "use" clause information for SGI Workshop debugger. */ |
11581 | ||
11582 | void | |
11583 | dwarf2out_add_library_unit_info (filename, context_list) | |
c6991660 KG |
11584 | const char *filename; |
11585 | const char *context_list; | |
14a774a9 RK |
11586 | { |
11587 | unsigned int file_index; | |
11588 | ||
11589 | if (filename != NULL) | |
11590 | { | |
54ba1f0d | 11591 | dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL); |
556273e0 | 11592 | tree context_list_decl |
14a774a9 RK |
11593 | = build_decl (LABEL_DECL, get_identifier (context_list), |
11594 | void_type_node); | |
11595 | ||
11596 | TREE_PUBLIC (context_list_decl) = TRUE; | |
11597 | add_name_attribute (unit_die, context_list); | |
981975b6 | 11598 | file_index = lookup_filename (filename); |
14a774a9 RK |
11599 | add_AT_unsigned (unit_die, DW_AT_decl_file, file_index); |
11600 | add_pubname (context_list_decl, unit_die); | |
11601 | } | |
11602 | } | |
11603 | ||
2ad9852d | 11604 | /* Output debug information for global decl DECL. Called from toplev.c after |
2b85879e | 11605 | compilation proper has finished. */ |
2ad9852d | 11606 | |
2b85879e NB |
11607 | static void |
11608 | dwarf2out_global_decl (decl) | |
11609 | tree decl; | |
11610 | { | |
11611 | /* Output DWARF2 information for file-scope tentative data object | |
2ad9852d RK |
11612 | declarations, file-scope (extern) function declarations (which had no |
11613 | corresponding body) and file-scope tagged type declarations and | |
11614 | definitions which have not yet been forced out. */ | |
2b85879e NB |
11615 | if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)) |
11616 | dwarf2out_decl (decl); | |
11617 | } | |
11618 | ||
71dfc51f RK |
11619 | /* Write the debugging output for DECL. */ |
11620 | ||
a3f97cbb | 11621 | void |
88dad228 | 11622 | dwarf2out_decl (decl) |
b3694847 | 11623 | tree decl; |
a3f97cbb | 11624 | { |
b3694847 | 11625 | dw_die_ref context_die = comp_unit_die; |
88dad228 | 11626 | |
a3f97cbb JW |
11627 | switch (TREE_CODE (decl)) |
11628 | { | |
2ad9852d RK |
11629 | case ERROR_MARK: |
11630 | return; | |
11631 | ||
a3f97cbb | 11632 | case FUNCTION_DECL: |
556273e0 | 11633 | /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a |
a3f97cbb JW |
11634 | builtin function. Explicit programmer-supplied declarations of |
11635 | these same functions should NOT be ignored however. */ | |
9765e357 | 11636 | if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl)) |
b1ccbc24 | 11637 | return; |
a3f97cbb JW |
11638 | |
11639 | /* What we would really like to do here is to filter out all mere | |
11640 | file-scope declarations of file-scope functions which are never | |
11641 | referenced later within this translation unit (and keep all of ones | |
556273e0 KH |
11642 | that *are* referenced later on) but we aren't clairvoyant, so we have |
11643 | no idea which functions will be referenced in the future (i.e. later | |
a3f97cbb | 11644 | on within the current translation unit). So here we just ignore all |
556273e0 | 11645 | file-scope function declarations which are not also definitions. If |
956d6950 | 11646 | and when the debugger needs to know something about these functions, |
556273e0 | 11647 | it will have to hunt around and find the DWARF information associated |
2ad9852d RK |
11648 | with the definition of the function. |
11649 | ||
11650 | We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL | |
11651 | nodes represent definitions and which ones represent mere | |
11652 | declarations. We have to check DECL_INITIAL instead. That's because | |
11653 | the C front-end supports some weird semantics for "extern inline" | |
11654 | function definitions. These can get inlined within the current | |
11655 | translation unit (an thus, we need to generate Dwarf info for their | |
11656 | abstract instances so that the Dwarf info for the concrete inlined | |
11657 | instances can have something to refer to) but the compiler never | |
11658 | generates any out-of-lines instances of such things (despite the fact | |
11659 | that they *are* definitions). | |
11660 | ||
11661 | The important point is that the C front-end marks these "extern | |
11662 | inline" functions as DECL_EXTERNAL, but we need to generate DWARF for | |
11663 | them anyway. Note that the C++ front-end also plays some similar games | |
11664 | for inline function definitions appearing within include files which | |
11665 | also contain `#pragma interface' pragmas. */ | |
a3f97cbb | 11666 | if (DECL_INITIAL (decl) == NULL_TREE) |
b1ccbc24 | 11667 | return; |
88dad228 | 11668 | |
9c6cd30e JM |
11669 | /* If we're a nested function, initially use a parent of NULL; if we're |
11670 | a plain function, this will be fixed up in decls_for_scope. If | |
11671 | we're a method, it will be ignored, since we already have a DIE. */ | |
88dad228 | 11672 | if (decl_function_context (decl)) |
9c6cd30e | 11673 | context_die = NULL; |
a3f97cbb JW |
11674 | break; |
11675 | ||
11676 | case VAR_DECL: | |
556273e0 | 11677 | /* Ignore this VAR_DECL if it refers to a file-scope extern data object |
a3f97cbb JW |
11678 | declaration and if the declaration was never even referenced from |
11679 | within this entire compilation unit. We suppress these DIEs in | |
11680 | order to save space in the .debug section (by eliminating entries | |
11681 | which are probably useless). Note that we must not suppress | |
11682 | block-local extern declarations (whether used or not) because that | |
11683 | would screw-up the debugger's name lookup mechanism and cause it to | |
11684 | miss things which really ought to be in scope at a given point. */ | |
11685 | if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) | |
71dfc51f | 11686 | return; |
a3f97cbb JW |
11687 | |
11688 | /* If we are in terse mode, don't generate any DIEs to represent any | |
11689 | variable declarations or definitions. */ | |
11690 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 11691 | return; |
a3f97cbb JW |
11692 | break; |
11693 | ||
11694 | case TYPE_DECL: | |
57fb7689 JM |
11695 | /* Don't emit stubs for types unless they are needed by other DIEs. */ |
11696 | if (TYPE_DECL_SUPPRESS_DEBUG (decl)) | |
11697 | return; | |
11698 | ||
a3f97cbb | 11699 | /* Don't bother trying to generate any DIEs to represent any of the |
a9d38797 JM |
11700 | normal built-in types for the language we are compiling. */ |
11701 | if (DECL_SOURCE_LINE (decl) == 0) | |
a94dbf2c JM |
11702 | { |
11703 | /* OK, we need to generate one for `bool' so GDB knows what type | |
11704 | comparisons have. */ | |
11705 | if ((get_AT_unsigned (comp_unit_die, DW_AT_language) | |
11706 | == DW_LANG_C_plus_plus) | |
f11c3043 RK |
11707 | && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE |
11708 | && ! DECL_IGNORED_P (decl)) | |
a94dbf2c | 11709 | modified_type_die (TREE_TYPE (decl), 0, 0, NULL); |
71dfc51f | 11710 | |
a94dbf2c JM |
11711 | return; |
11712 | } | |
a3f97cbb | 11713 | |
88dad228 | 11714 | /* If we are in terse mode, don't generate any DIEs for types. */ |
a3f97cbb | 11715 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 11716 | return; |
88dad228 JM |
11717 | |
11718 | /* If we're a function-scope tag, initially use a parent of NULL; | |
11719 | this will be fixed up in decls_for_scope. */ | |
11720 | if (decl_function_context (decl)) | |
3f76745e | 11721 | context_die = NULL; |
88dad228 | 11722 | |
a3f97cbb JW |
11723 | break; |
11724 | ||
11725 | default: | |
11726 | return; | |
11727 | } | |
11728 | ||
88dad228 | 11729 | gen_decl_die (decl, context_die); |
a3f97cbb JW |
11730 | } |
11731 | ||
11732 | /* Output a marker (i.e. a label) for the beginning of the generated code for | |
11733 | a lexical block. */ | |
71dfc51f | 11734 | |
a5a42b92 | 11735 | static void |
e2a12aca | 11736 | dwarf2out_begin_block (line, blocknum) |
a5a42b92 NB |
11737 | unsigned int line ATTRIBUTE_UNUSED; |
11738 | unsigned int blocknum; | |
a3f97cbb | 11739 | { |
a3f97cbb | 11740 | function_section (current_function_decl); |
8215347e | 11741 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum); |
a3f97cbb JW |
11742 | } |
11743 | ||
11744 | /* Output a marker (i.e. a label) for the end of the generated code for a | |
11745 | lexical block. */ | |
71dfc51f | 11746 | |
a5a42b92 | 11747 | static void |
e2a12aca | 11748 | dwarf2out_end_block (line, blocknum) |
a5a42b92 NB |
11749 | unsigned int line ATTRIBUTE_UNUSED; |
11750 | unsigned int blocknum; | |
a3f97cbb | 11751 | { |
a3f97cbb | 11752 | function_section (current_function_decl); |
8215347e | 11753 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum); |
a3f97cbb JW |
11754 | } |
11755 | ||
64b59a80 JM |
11756 | /* Returns nonzero if it is appropriate not to emit any debugging |
11757 | information for BLOCK, because it doesn't contain any instructions. | |
fcd7f76b | 11758 | |
64b59a80 JM |
11759 | Don't allow this for blocks with nested functions or local classes |
11760 | as we would end up with orphans, and in the presence of scheduling | |
11761 | we may end up calling them anyway. */ | |
11762 | ||
e1772ac0 | 11763 | static bool |
fcd7f76b JM |
11764 | dwarf2out_ignore_block (block) |
11765 | tree block; | |
11766 | { | |
11767 | tree decl; | |
2ad9852d | 11768 | |
fcd7f76b | 11769 | for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) |
64b59a80 JM |
11770 | if (TREE_CODE (decl) == FUNCTION_DECL |
11771 | || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))) | |
11772 | return 0; | |
2ad9852d | 11773 | |
64b59a80 | 11774 | return 1; |
fcd7f76b JM |
11775 | } |
11776 | ||
2ad9852d | 11777 | /* Lookup FILE_NAME (in the list of filenames that we know about here in |
9a666dda | 11778 | dwarf2out.c) and return its "index". The index of each (known) filename is |
2ad9852d RK |
11779 | just a unique number which is associated with only that one filename. We |
11780 | need such numbers for the sake of generating labels (in the .debug_sfnames | |
11781 | section) and references to those files numbers (in the .debug_srcinfo | |
11782 | and.debug_macinfo sections). If the filename given as an argument is not | |
11783 | found in our current list, add it to the list and assign it the next | |
11784 | available unique index number. In order to speed up searches, we remember | |
11785 | the index of the filename was looked up last. This handles the majority of | |
11786 | all searches. */ | |
71dfc51f | 11787 | |
a3f97cbb | 11788 | static unsigned |
981975b6 | 11789 | lookup_filename (file_name) |
d560ee52 | 11790 | const char *file_name; |
a3f97cbb | 11791 | { |
b3694847 | 11792 | unsigned i; |
a3f97cbb | 11793 | |
981975b6 RH |
11794 | /* ??? Why isn't DECL_SOURCE_FILE left null instead. */ |
11795 | if (strcmp (file_name, "<internal>") == 0 | |
11796 | || strcmp (file_name, "<built-in>") == 0) | |
11797 | return 0; | |
11798 | ||
2e18bbae RH |
11799 | /* Check to see if the file name that was searched on the previous |
11800 | call matches this file name. If so, return the index. */ | |
981975b6 | 11801 | if (file_table.last_lookup_index != 0) |
2ad9852d RK |
11802 | if (0 == strcmp (file_name, |
11803 | file_table.table[file_table.last_lookup_index])) | |
981975b6 | 11804 | return file_table.last_lookup_index; |
a3f97cbb JW |
11805 | |
11806 | /* Didn't match the previous lookup, search the table */ | |
2ad9852d | 11807 | for (i = 1; i < file_table.in_use; i++) |
981975b6 | 11808 | if (strcmp (file_name, file_table.table[i]) == 0) |
71dfc51f | 11809 | { |
981975b6 | 11810 | file_table.last_lookup_index = i; |
71dfc51f RK |
11811 | return i; |
11812 | } | |
a3f97cbb | 11813 | |
556273e0 | 11814 | /* Prepare to add a new table entry by making sure there is enough space in |
a3f97cbb | 11815 | the table to do so. If not, expand the current table. */ |
981975b6 | 11816 | if (i == file_table.allocated) |
a3f97cbb | 11817 | { |
981975b6 RH |
11818 | file_table.allocated = i + FILE_TABLE_INCREMENT; |
11819 | file_table.table = (char **) | |
11820 | xrealloc (file_table.table, file_table.allocated * sizeof (char *)); | |
a3f97cbb JW |
11821 | } |
11822 | ||
71dfc51f | 11823 | /* Add the new entry to the end of the filename table. */ |
981975b6 RH |
11824 | file_table.table[i] = xstrdup (file_name); |
11825 | file_table.in_use = i + 1; | |
11826 | file_table.last_lookup_index = i; | |
2e18bbae | 11827 | |
acc187f5 | 11828 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
211a0cbe GDR |
11829 | { |
11830 | fprintf (asm_out_file, "\t.file %u ", i); | |
11831 | output_quoted_string (asm_out_file, file_name); | |
11832 | fputc ('\n', asm_out_file); | |
11833 | } | |
acc187f5 | 11834 | |
2e18bbae RH |
11835 | return i; |
11836 | } | |
11837 | ||
11838 | static void | |
981975b6 | 11839 | init_file_table () |
2e18bbae RH |
11840 | { |
11841 | /* Allocate the initial hunk of the file_table. */ | |
981975b6 RH |
11842 | file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *)); |
11843 | file_table.allocated = FILE_TABLE_INCREMENT; | |
71dfc51f | 11844 | |
2e18bbae | 11845 | /* Skip the first entry - file numbers begin at 1. */ |
981975b6 RH |
11846 | file_table.in_use = 1; |
11847 | file_table.last_lookup_index = 0; | |
a3f97cbb JW |
11848 | } |
11849 | ||
11850 | /* Output a label to mark the beginning of a source code line entry | |
11851 | and record information relating to this source line, in | |
11852 | 'line_info_table' for later output of the .debug_line section. */ | |
71dfc51f | 11853 | |
e2a12aca | 11854 | static void |
653e276c NB |
11855 | dwarf2out_source_line (line, filename) |
11856 | unsigned int line; | |
b3694847 | 11857 | const char *filename; |
a3f97cbb | 11858 | { |
a3f97cbb JW |
11859 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
11860 | { | |
11861 | function_section (current_function_decl); | |
a3f97cbb | 11862 | |
8aaf55ac JM |
11863 | /* If requested, emit something human-readable. */ |
11864 | if (flag_debug_asm) | |
11865 | fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, | |
11866 | filename, line); | |
11867 | ||
b2244e22 JW |
11868 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
11869 | { | |
981975b6 | 11870 | unsigned file_num = lookup_filename (filename); |
b2244e22 | 11871 | |
981975b6 | 11872 | /* Emit the .loc directive understood by GNU as. */ |
2e18bbae | 11873 | fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line); |
b2244e22 JW |
11874 | |
11875 | /* Indicate that line number info exists. */ | |
2ad9852d | 11876 | line_info_table_in_use++; |
b2244e22 JW |
11877 | |
11878 | /* Indicate that multiple line number tables exist. */ | |
11879 | if (DECL_SECTION_NAME (current_function_decl)) | |
2ad9852d | 11880 | separate_line_info_table_in_use++; |
b2244e22 JW |
11881 | } |
11882 | else if (DECL_SECTION_NAME (current_function_decl)) | |
a3f97cbb | 11883 | { |
b3694847 | 11884 | dw_separate_line_info_ref line_info; |
5c90448c JM |
11885 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL, |
11886 | separate_line_info_table_in_use); | |
e90b62db JM |
11887 | |
11888 | /* expand the line info table if necessary */ | |
11889 | if (separate_line_info_table_in_use | |
11890 | == separate_line_info_table_allocated) | |
11891 | { | |
11892 | separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
11893 | separate_line_info_table | |
71dfc51f RK |
11894 | = (dw_separate_line_info_ref) |
11895 | xrealloc (separate_line_info_table, | |
11896 | separate_line_info_table_allocated | |
11897 | * sizeof (dw_separate_line_info_entry)); | |
e90b62db | 11898 | } |
71dfc51f RK |
11899 | |
11900 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
11901 | line_info |
11902 | = &separate_line_info_table[separate_line_info_table_in_use++]; | |
981975b6 | 11903 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db JM |
11904 | line_info->dw_line_num = line; |
11905 | line_info->function = current_funcdef_number; | |
11906 | } | |
11907 | else | |
11908 | { | |
b3694847 | 11909 | dw_line_info_ref line_info; |
71dfc51f | 11910 | |
5c90448c JM |
11911 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL, |
11912 | line_info_table_in_use); | |
e90b62db | 11913 | |
71dfc51f | 11914 | /* Expand the line info table if necessary. */ |
e90b62db JM |
11915 | if (line_info_table_in_use == line_info_table_allocated) |
11916 | { | |
11917 | line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
11918 | line_info_table | |
71dfc51f RK |
11919 | = (dw_line_info_ref) |
11920 | xrealloc (line_info_table, | |
11921 | (line_info_table_allocated | |
11922 | * sizeof (dw_line_info_entry))); | |
e90b62db | 11923 | } |
71dfc51f RK |
11924 | |
11925 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db | 11926 | line_info = &line_info_table[line_info_table_in_use++]; |
981975b6 | 11927 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db | 11928 | line_info->dw_line_num = line; |
a3f97cbb | 11929 | } |
a3f97cbb JW |
11930 | } |
11931 | } | |
11932 | ||
30f7a378 | 11933 | /* Record the beginning of a new source file. */ |
71dfc51f | 11934 | |
7f905405 | 11935 | static void |
84a5b4f8 | 11936 | dwarf2out_start_source_file (lineno, filename) |
b3694847 SS |
11937 | unsigned int lineno; |
11938 | const char *filename; | |
a3f97cbb | 11939 | { |
881c6935 JM |
11940 | if (flag_eliminate_dwarf2_dups) |
11941 | { | |
11942 | /* Record the beginning of the file for break_out_includes. */ | |
54ba1f0d | 11943 | dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL); |
881c6935 JM |
11944 | add_AT_string (bincl_die, DW_AT_name, filename); |
11945 | } | |
2ad9852d | 11946 | |
84a5b4f8 DB |
11947 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11948 | { | |
715bdd29 | 11949 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 | 11950 | dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file"); |
7c262518 RH |
11951 | dw2_asm_output_data_uleb128 (lineno, "Included from line number %d", |
11952 | lineno); | |
11953 | dw2_asm_output_data_uleb128 (lookup_filename (filename), | |
11954 | "Filename we just started"); | |
84a5b4f8 | 11955 | } |
a3f97cbb JW |
11956 | } |
11957 | ||
cc260610 | 11958 | /* Record the end of a source file. */ |
71dfc51f | 11959 | |
7f905405 NB |
11960 | static void |
11961 | dwarf2out_end_source_file (lineno) | |
11962 | unsigned int lineno ATTRIBUTE_UNUSED; | |
a3f97cbb | 11963 | { |
881c6935 | 11964 | if (flag_eliminate_dwarf2_dups) |
2ad9852d | 11965 | /* Record the end of the file for break_out_includes. */ |
54ba1f0d | 11966 | new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL); |
2ad9852d | 11967 | |
84a5b4f8 DB |
11968 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11969 | { | |
715bdd29 | 11970 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
11971 | dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); |
11972 | } | |
a3f97cbb JW |
11973 | } |
11974 | ||
cc260610 | 11975 | /* Called from debug_define in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
11976 | the tail part of the directive line, i.e. the part which is past the |
11977 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 11978 | |
7f905405 | 11979 | static void |
9a666dda | 11980 | dwarf2out_define (lineno, buffer) |
b3694847 SS |
11981 | unsigned lineno ATTRIBUTE_UNUSED; |
11982 | const char *buffer ATTRIBUTE_UNUSED; | |
a3f97cbb | 11983 | { |
84a5b4f8 DB |
11984 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11985 | { | |
715bdd29 | 11986 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
11987 | dw2_asm_output_data (1, DW_MACINFO_define, "Define macro"); |
11988 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
11989 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
11990 | } | |
a3f97cbb JW |
11991 | } |
11992 | ||
cc260610 | 11993 | /* Called from debug_undef in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
11994 | the tail part of the directive line, i.e. the part which is past the |
11995 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 11996 | |
7f905405 | 11997 | static void |
9a666dda | 11998 | dwarf2out_undef (lineno, buffer) |
b3694847 SS |
11999 | unsigned lineno ATTRIBUTE_UNUSED; |
12000 | const char *buffer ATTRIBUTE_UNUSED; | |
a3f97cbb | 12001 | { |
84a5b4f8 DB |
12002 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12003 | { | |
715bdd29 | 12004 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
12005 | dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro"); |
12006 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
12007 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
12008 | } | |
a3f97cbb JW |
12009 | } |
12010 | ||
12011 | /* Set up for Dwarf output at the start of compilation. */ | |
71dfc51f | 12012 | |
a51d908e | 12013 | static void |
e2a12aca | 12014 | dwarf2out_init (main_input_filename) |
b3694847 | 12015 | const char *main_input_filename; |
a3f97cbb | 12016 | { |
acc187f5 RH |
12017 | init_file_table (); |
12018 | ||
a3f97cbb JW |
12019 | /* Remember the name of the primary input file. */ |
12020 | primary_filename = main_input_filename; | |
12021 | ||
acc187f5 RH |
12022 | /* Add it to the file table first, under the assumption that we'll |
12023 | be emitting line number data for it first, which avoids having | |
12024 | to add an initial DW_LNS_set_file. */ | |
12025 | lookup_filename (main_input_filename); | |
a3f97cbb | 12026 | |
a3f97cbb JW |
12027 | /* Allocate the initial hunk of the decl_die_table. */ |
12028 | decl_die_table | |
3de90026 | 12029 | = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref)); |
a3f97cbb JW |
12030 | decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT; |
12031 | decl_die_table_in_use = 0; | |
12032 | ||
12033 | /* Allocate the initial hunk of the decl_scope_table. */ | |
244a4af0 TF |
12034 | VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table"); |
12035 | ggc_add_tree_varray_root (&decl_scope_table, 1); | |
a3f97cbb JW |
12036 | |
12037 | /* Allocate the initial hunk of the abbrev_die_table. */ | |
12038 | abbrev_die_table | |
3de90026 RH |
12039 | = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT, |
12040 | sizeof (dw_die_ref)); | |
a3f97cbb | 12041 | abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT; |
71dfc51f | 12042 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
12043 | abbrev_die_table_in_use = 1; |
12044 | ||
12045 | /* Allocate the initial hunk of the line_info_table. */ | |
12046 | line_info_table | |
3de90026 RH |
12047 | = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT, |
12048 | sizeof (dw_line_info_entry)); | |
a3f97cbb | 12049 | line_info_table_allocated = LINE_INFO_TABLE_INCREMENT; |
2ad9852d | 12050 | |
71dfc51f | 12051 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
12052 | line_info_table_in_use = 1; |
12053 | ||
556273e0 | 12054 | /* Generate the initial DIE for the .debug section. Note that the (string) |
a3f97cbb | 12055 | value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE |
556273e0 | 12056 | will (typically) be a relative pathname and that this pathname should be |
a3f97cbb JW |
12057 | taken as being relative to the directory from which the compiler was |
12058 | invoked when the given (base) source file was compiled. */ | |
a96c67ec | 12059 | comp_unit_die = gen_compile_unit_die (main_input_filename); |
a3f97cbb | 12060 | |
244a4af0 TF |
12061 | VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types"); |
12062 | ggc_add_tree_varray_root (&incomplete_types, 1); | |
12063 | ||
1f8f4a0b MM |
12064 | VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray"); |
12065 | ggc_add_rtx_varray_root (&used_rtx_varray, 1); | |
1865dbb5 | 12066 | |
54ba1f0d RH |
12067 | ggc_add_root (&limbo_die_list, 1, 1, mark_limbo_die_list); |
12068 | ||
5c90448c | 12069 | ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0); |
9d2f2c45 RH |
12070 | ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, |
12071 | DEBUG_ABBREV_SECTION_LABEL, 0); | |
b366352b MM |
12072 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) |
12073 | ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0); | |
12074 | else | |
f99ffb60 | 12075 | strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME)); |
2ad9852d | 12076 | |
556273e0 | 12077 | ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label, |
8b790721 | 12078 | DEBUG_INFO_SECTION_LABEL, 0); |
556273e0 | 12079 | ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label, |
8b790721 | 12080 | DEBUG_LINE_SECTION_LABEL, 0); |
2bee6045 JJ |
12081 | ASM_GENERATE_INTERNAL_LABEL (ranges_section_label, |
12082 | DEBUG_RANGES_SECTION_LABEL, 0); | |
715bdd29 | 12083 | named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG); |
8b790721 | 12084 | ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label); |
715bdd29 | 12085 | named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG); |
8b790721 | 12086 | ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label); |
715bdd29 | 12087 | named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG); |
8b790721 | 12088 | ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label); |
2ad9852d | 12089 | |
84a5b4f8 DB |
12090 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12091 | { | |
715bdd29 | 12092 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
12093 | ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label, |
12094 | DEBUG_MACINFO_SECTION_LABEL, 0); | |
12095 | ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label); | |
12096 | } | |
7c262518 RH |
12097 | |
12098 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) | |
12099 | { | |
12100 | text_section (); | |
12101 | ASM_OUTPUT_LABEL (asm_out_file, text_section_label); | |
12102 | } | |
a3f97cbb JW |
12103 | } |
12104 | ||
9eb4015a JJ |
12105 | /* Allocate a string in .debug_str hash table. */ |
12106 | ||
12107 | static hashnode | |
12108 | indirect_string_alloc (tab) | |
12109 | hash_table *tab ATTRIBUTE_UNUSED; | |
12110 | { | |
12111 | struct indirect_string_node *node; | |
12112 | ||
12113 | node = xmalloc (sizeof (struct indirect_string_node)); | |
12114 | node->refcount = 0; | |
12115 | node->form = 0; | |
12116 | node->label = NULL; | |
2ad9852d | 12117 | |
9eb4015a JJ |
12118 | return (hashnode) node; |
12119 | } | |
12120 | ||
12121 | /* A helper function for dwarf2out_finish called through | |
12122 | ht_forall. Emit one queued .debug_str string. */ | |
12123 | ||
12124 | static int | |
12125 | output_indirect_string (pfile, h, v) | |
12126 | struct cpp_reader *pfile ATTRIBUTE_UNUSED; | |
12127 | hashnode h; | |
12128 | const PTR v ATTRIBUTE_UNUSED; | |
12129 | { | |
2ad9852d | 12130 | struct indirect_string_node *node = (struct indirect_string_node *) h; |
9eb4015a | 12131 | |
9eb4015a JJ |
12132 | if (node->form == DW_FORM_strp) |
12133 | { | |
12134 | named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS); | |
12135 | ASM_OUTPUT_LABEL (asm_out_file, node->label); | |
12136 | assemble_string ((const char *) HT_STR (&node->id), | |
12137 | HT_LEN (&node->id) + 1); | |
12138 | } | |
2ad9852d | 12139 | |
9eb4015a JJ |
12140 | return 1; |
12141 | } | |
12142 | ||
a3f97cbb JW |
12143 | /* Output stuff that dwarf requires at the end of every file, |
12144 | and generate the DWARF-2 debugging info. */ | |
71dfc51f | 12145 | |
a51d908e | 12146 | static void |
e2a12aca | 12147 | dwarf2out_finish (input_filename) |
b3694847 | 12148 | const char *input_filename ATTRIBUTE_UNUSED; |
a3f97cbb | 12149 | { |
ef76d03b | 12150 | limbo_die_node *node, *next_node; |
ae0ed63a | 12151 | dw_die_ref die = 0; |
ef76d03b JW |
12152 | |
12153 | /* Traverse the limbo die list, and add parent/child links. The only | |
12154 | dies without parents that should be here are concrete instances of | |
12155 | inline functions, and the comp_unit_die. We can ignore the comp_unit_die. | |
12156 | For concrete instances, we can get the parent die from the abstract | |
12157 | instance. */ | |
12158 | for (node = limbo_die_list; node; node = next_node) | |
12159 | { | |
12160 | next_node = node->next; | |
12161 | die = node->die; | |
12162 | ||
12163 | if (die->die_parent == NULL) | |
12164 | { | |
a96c67ec | 12165 | dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin); |
54ba1f0d | 12166 | tree context; |
2ad9852d | 12167 | |
a96c67ec JM |
12168 | if (origin) |
12169 | add_child_die (origin->die_parent, die); | |
ef76d03b | 12170 | else if (die == comp_unit_die) |
a96c67ec | 12171 | ; |
aea9695c RK |
12172 | /* If this was an expression for a bound involved in a function |
12173 | return type, it may be a SAVE_EXPR for which we weren't able | |
12174 | to find a DIE previously. So try now. */ | |
12175 | else if (node->created_for | |
12176 | && TREE_CODE (node->created_for) == SAVE_EXPR | |
12177 | && 0 != (origin = (lookup_decl_die | |
12178 | (SAVE_EXPR_CONTEXT | |
12179 | (node->created_for))))) | |
12180 | add_child_die (origin, die); | |
6bb28965 JM |
12181 | else if (errorcount > 0 || sorrycount > 0) |
12182 | /* It's OK to be confused by errors in the input. */ | |
12183 | add_child_die (comp_unit_die, die); | |
54ba1f0d RH |
12184 | else if (node->created_for |
12185 | && ((DECL_P (node->created_for) | |
c26fbbca | 12186 | && (context = DECL_CONTEXT (node->created_for))) |
54ba1f0d RH |
12187 | || (TYPE_P (node->created_for) |
12188 | && (context = TYPE_CONTEXT (node->created_for)))) | |
12189 | && TREE_CODE (context) == FUNCTION_DECL) | |
12190 | { | |
12191 | /* In certain situations, the lexical block containing a | |
12192 | nested function can be optimized away, which results | |
12193 | in the nested function die being orphaned. Likewise | |
12194 | with the return type of that nested function. Force | |
12195 | this to be a child of the containing function. */ | |
12196 | origin = lookup_decl_die (context); | |
12197 | if (! origin) | |
12198 | abort (); | |
12199 | add_child_die (origin, die); | |
12200 | } | |
ef76d03b JW |
12201 | else |
12202 | abort (); | |
12203 | } | |
2ad9852d | 12204 | |
ef76d03b JW |
12205 | free (node); |
12206 | } | |
2ad9852d | 12207 | |
a96c67ec | 12208 | limbo_die_list = NULL; |
ef76d03b | 12209 | |
8a8c3656 JM |
12210 | /* Walk through the list of incomplete types again, trying once more to |
12211 | emit full debugging info for them. */ | |
12212 | retry_incomplete_types (); | |
12213 | ||
881c6935 JM |
12214 | /* We need to reverse all the dies before break_out_includes, or |
12215 | we'll see the end of an include file before the beginning. */ | |
12216 | reverse_all_dies (comp_unit_die); | |
12217 | ||
12218 | /* Generate separate CUs for each of the include files we've seen. | |
12219 | They will go into limbo_die_list. */ | |
5f632b5e JM |
12220 | if (flag_eliminate_dwarf2_dups) |
12221 | break_out_includes (comp_unit_die); | |
881c6935 JM |
12222 | |
12223 | /* Traverse the DIE's and add add sibling attributes to those DIE's | |
12224 | that have children. */ | |
a3f97cbb | 12225 | add_sibling_attributes (comp_unit_die); |
881c6935 JM |
12226 | for (node = limbo_die_list; node; node = node->next) |
12227 | add_sibling_attributes (node->die); | |
a3f97cbb JW |
12228 | |
12229 | /* Output a terminator label for the .text section. */ | |
7c262518 | 12230 | text_section (); |
5c90448c | 12231 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0); |
a3f97cbb | 12232 | |
db3c0315 MM |
12233 | /* Output the source line correspondence table. We must do this |
12234 | even if there is no line information. Otherwise, on an empty | |
12235 | translation unit, we will generate a present, but empty, | |
12236 | .debug_info section. IRIX 6.5 `nm' will then complain when | |
12237 | examining the file. */ | |
12238 | if (! DWARF2_ASM_LINE_DEBUG_INFO) | |
e90b62db | 12239 | { |
715bdd29 | 12240 | named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG); |
db3c0315 MM |
12241 | output_line_info (); |
12242 | } | |
71dfc51f | 12243 | |
b38a75e5 RH |
12244 | /* Output location list section if necessary. */ |
12245 | if (have_location_lists) | |
12246 | { | |
12247 | /* Output the location lists info. */ | |
12248 | named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG); | |
12249 | ASM_GENERATE_INTERNAL_LABEL (loc_section_label, | |
12250 | DEBUG_LOC_SECTION_LABEL, 0); | |
12251 | ASM_OUTPUT_LABEL (asm_out_file, loc_section_label); | |
12252 | output_location_lists (die); | |
12253 | have_location_lists = 0; | |
12254 | } | |
12255 | ||
db3c0315 MM |
12256 | /* We can only use the low/high_pc attributes if all of the code was |
12257 | in .text. */ | |
12258 | if (separate_line_info_table_in_use == 0) | |
12259 | { | |
12260 | add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label); | |
12261 | add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label); | |
e90b62db | 12262 | } |
2ad9852d RK |
12263 | |
12264 | /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate | |
12265 | "base address". Use zero so that these addresses become absolute. */ | |
a20612aa RH |
12266 | else if (have_location_lists || ranges_table_in_use) |
12267 | add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx); | |
e90b62db | 12268 | |
fe7cd37f RH |
12269 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
12270 | add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list, | |
12271 | debug_line_section_label); | |
db3c0315 | 12272 | |
84a5b4f8 DB |
12273 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
12274 | add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label); | |
a96c67ec | 12275 | |
881c6935 JM |
12276 | /* Output all of the compilation units. We put the main one last so that |
12277 | the offsets are available to output_pubnames. */ | |
12278 | for (node = limbo_die_list; node; node = node->next) | |
12279 | output_comp_unit (node->die); | |
2ad9852d | 12280 | |
881c6935 JM |
12281 | output_comp_unit (comp_unit_die); |
12282 | ||
a3f97cbb | 12283 | /* Output the abbreviation table. */ |
715bdd29 | 12284 | named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG); |
a3f97cbb JW |
12285 | output_abbrev_section (); |
12286 | ||
2ad9852d | 12287 | /* Output public names table if necessary. */ |
d291dd49 JM |
12288 | if (pubname_table_in_use) |
12289 | { | |
715bdd29 | 12290 | named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG); |
d291dd49 JM |
12291 | output_pubnames (); |
12292 | } | |
12293 | ||
2ad9852d RK |
12294 | /* Output the address range information. We only put functions in the arange |
12295 | table, so don't write it out if we don't have any. */ | |
a3f97cbb JW |
12296 | if (fde_table_in_use) |
12297 | { | |
715bdd29 | 12298 | named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG); |
a3f97cbb JW |
12299 | output_aranges (); |
12300 | } | |
a20612aa | 12301 | |
a20612aa RH |
12302 | /* Output ranges section if necessary. */ |
12303 | if (ranges_table_in_use) | |
12304 | { | |
715bdd29 | 12305 | named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG); |
2bee6045 | 12306 | ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label); |
a20612aa RH |
12307 | output_ranges (); |
12308 | } | |
12309 | ||
30f7a378 | 12310 | /* Have to end the primary source file. */ |
cc260610 | 12311 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
c26fbbca | 12312 | { |
715bdd29 | 12313 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
cc260610 | 12314 | dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); |
2f8d482e | 12315 | dw2_asm_output_data (1, 0, "End compilation unit"); |
cc260610 | 12316 | } |
9eb4015a | 12317 | |
2ad9852d | 12318 | /* If we emitted any DW_FORM_strp form attribute, output the string |
9eb4015a JJ |
12319 | table too. */ |
12320 | if (debug_str_hash) | |
12321 | ht_forall (debug_str_hash, output_indirect_string, NULL); | |
a3f97cbb | 12322 | } |
f3a8e4f5 | 12323 | #endif /* DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO */ |