]>
Commit | Line | Data |
---|---|---|
a3f97cbb | 1 | /* Output Dwarf2 format symbol table information from the GNU C compiler. |
1917ef85 | 2 | Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001 |
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 | |
a96c67ec | 25 | /* TODO: Implement .debug_str handling, and share entries somehow. |
348bb3c7 JM |
26 | Emit .debug_line header even when there are no functions, since |
27 | the file numbers are used by .debug_info. Alternately, leave | |
28 | out locations for types and decls. | |
29 | Avoid talking about ctors and op= for PODs. | |
30 | Factor out common prologue sequences into multiple CIEs. */ | |
31 | ||
3f76745e JM |
32 | /* The first part of this file deals with the DWARF 2 frame unwind |
33 | information, which is also used by the GCC efficient exception handling | |
34 | mechanism. The second part, controlled only by an #ifdef | |
35 | DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging | |
36 | information. */ | |
37 | ||
0021b564 | 38 | #include "config.h" |
670ee920 | 39 | #include "system.h" |
a3f97cbb JW |
40 | #include "tree.h" |
41 | #include "flags.h" | |
42 | #include "rtl.h" | |
43 | #include "hard-reg-set.h" | |
44 | #include "regs.h" | |
45 | #include "insn-config.h" | |
46 | #include "reload.h" | |
52a11cbf | 47 | #include "function.h" |
a3f97cbb | 48 | #include "output.h" |
71dfc51f | 49 | #include "expr.h" |
e78d8e51 | 50 | #include "libfuncs.h" |
3f76745e | 51 | #include "except.h" |
a7cc7f29 | 52 | #include "dwarf2.h" |
76ead72b | 53 | #include "dwarf2out.h" |
2e4b9b8c | 54 | #include "dwarf2asm.h" |
10f0ad3d | 55 | #include "toplev.h" |
1865dbb5 | 56 | #include "varray.h" |
951a525f | 57 | #include "ggc.h" |
881c6935 | 58 | #include "md5.h" |
57bed152 | 59 | #include "tm_p.h" |
2a2b2d43 | 60 | #include "diagnostic.h" |
a51d908e | 61 | #include "debug.h" |
a3f97cbb | 62 | |
653e276c NB |
63 | #ifdef DWARF2_DEBUGGING_INFO |
64 | static void dwarf2out_source_line PARAMS ((unsigned int, const char *)); | |
65 | #endif | |
66 | ||
770ca8c6 JO |
67 | /* DWARF2 Abbreviation Glossary: |
68 | CFA = Canonical Frame Address | |
00a42e21 JM |
69 | a fixed address on the stack which identifies a call frame. |
70 | We define it to be the value of SP just before the call insn. | |
71 | The CFA register and offset, which may change during the course | |
72 | of the function, are used to calculate its value at runtime. | |
a401107d JO |
73 | CFI = Call Frame Instruction |
74 | an instruction for the DWARF2 abstract machine | |
770ca8c6 JO |
75 | CIE = Common Information Entry |
76 | information describing information common to one or more FDEs | |
77 | DIE = Debugging Information Entry | |
78 | FDE = Frame Description Entry | |
79 | information describing the stack call frame, in particular, | |
80 | how to restore registers | |
81 | ||
82 | DW_CFA_... = DWARF2 CFA call frame instruction | |
83 | DW_TAG_... = DWARF2 DIE tag */ | |
84 | ||
0021b564 JM |
85 | /* Decide whether we want to emit frame unwind information for the current |
86 | translation unit. */ | |
87 | ||
88 | int | |
89 | dwarf2out_do_frame () | |
90 | { | |
91 | return (write_symbols == DWARF2_DEBUG | |
9ec36da5 | 92 | #ifdef DWARF2_FRAME_INFO |
556273e0 | 93 | || DWARF2_FRAME_INFO |
9ec36da5 | 94 | #endif |
0021b564 | 95 | #ifdef DWARF2_UNWIND_INFO |
14a774a9 | 96 | || flag_unwind_tables |
531073e7 | 97 | || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS) |
0021b564 JM |
98 | #endif |
99 | ); | |
100 | } | |
101 | ||
b1e6ab03 RH |
102 | /* The number of the current function definition for which debugging |
103 | information is being generated. These numbers range from 1 up to the | |
104 | maximum number of function definitions contained within the current | |
105 | compilation unit. These numbers are used to create unique label id's | |
106 | unique to each function definition. */ | |
107 | unsigned current_funcdef_number = 0; | |
108 | ||
0021b564 JM |
109 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) |
110 | ||
eaf95893 RK |
111 | /* How to start an assembler comment. */ |
112 | #ifndef ASM_COMMENT_START | |
113 | #define ASM_COMMENT_START ";#" | |
114 | #endif | |
115 | ||
a3f97cbb JW |
116 | typedef struct dw_cfi_struct *dw_cfi_ref; |
117 | typedef struct dw_fde_struct *dw_fde_ref; | |
118 | typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref; | |
a3f97cbb JW |
119 | |
120 | /* Call frames are described using a sequence of Call Frame | |
121 | Information instructions. The register number, offset | |
122 | and address fields are provided as possible operands; | |
123 | their use is selected by the opcode field. */ | |
71dfc51f | 124 | |
a3f97cbb | 125 | typedef union dw_cfi_oprnd_struct |
71dfc51f RK |
126 | { |
127 | unsigned long dw_cfi_reg_num; | |
128 | long int dw_cfi_offset; | |
d3e3972c | 129 | const char *dw_cfi_addr; |
7d9d8943 | 130 | struct dw_loc_descr_struct *dw_cfi_loc; |
71dfc51f | 131 | } |
a3f97cbb JW |
132 | dw_cfi_oprnd; |
133 | ||
134 | typedef struct dw_cfi_struct | |
71dfc51f RK |
135 | { |
136 | dw_cfi_ref dw_cfi_next; | |
137 | enum dwarf_call_frame_info dw_cfi_opc; | |
138 | dw_cfi_oprnd dw_cfi_oprnd1; | |
139 | dw_cfi_oprnd dw_cfi_oprnd2; | |
140 | } | |
a3f97cbb JW |
141 | dw_cfi_node; |
142 | ||
7d9d8943 AM |
143 | /* This is how we define the location of the CFA. We use to handle it |
144 | as REG + OFFSET all the time, but now it can be more complex. | |
145 | It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET. | |
556273e0 | 146 | Instead of passing around REG and OFFSET, we pass a copy |
7d9d8943 AM |
147 | of this structure. */ |
148 | typedef struct cfa_loc | |
149 | { | |
556273e0 | 150 | unsigned long reg; |
7d9d8943 AM |
151 | long offset; |
152 | long base_offset; | |
153 | int indirect; /* 1 if CFA is accessed via a dereference. */ | |
154 | } dw_cfa_location; | |
155 | ||
a3f97cbb | 156 | /* All call frame descriptions (FDE's) in the GCC generated DWARF |
4b674448 | 157 | refer to a single Common Information Entry (CIE), defined at |
a3f97cbb JW |
158 | the beginning of the .debug_frame section. This used of a single |
159 | CIE obviates the need to keep track of multiple CIE's | |
160 | in the DWARF generation routines below. */ | |
71dfc51f | 161 | |
a3f97cbb | 162 | typedef struct dw_fde_struct |
71dfc51f | 163 | { |
d3e3972c KG |
164 | const char *dw_fde_begin; |
165 | const char *dw_fde_current_label; | |
166 | const char *dw_fde_end; | |
71dfc51f | 167 | dw_cfi_ref dw_fde_cfi; |
52a11cbf RH |
168 | unsigned funcdef_number; |
169 | unsigned nothrow : 1; | |
170 | unsigned uses_eh_lsda : 1; | |
71dfc51f | 171 | } |
a3f97cbb JW |
172 | dw_fde_node; |
173 | ||
a3f97cbb JW |
174 | /* Maximum size (in bytes) of an artificially generated label. */ |
175 | #define MAX_ARTIFICIAL_LABEL_BYTES 30 | |
176 | ||
a1a4189d | 177 | /* The size of the target's pointer type. */ |
a3f97cbb | 178 | #ifndef PTR_SIZE |
a9d38797 | 179 | #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT) |
a3f97cbb JW |
180 | #endif |
181 | ||
a1a4189d JB |
182 | /* The size of addresses as they appear in the Dwarf 2 data. |
183 | Some architectures use word addresses to refer to code locations, | |
184 | but Dwarf 2 info always uses byte addresses. On such machines, | |
185 | Dwarf 2 addresses need to be larger than the architecture's | |
186 | pointers. */ | |
187 | #ifndef DWARF2_ADDR_SIZE | |
188 | #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT) | |
189 | #endif | |
190 | ||
7e23cb16 | 191 | /* The size in bytes of a DWARF field indicating an offset or length |
a1a4189d JB |
192 | relative to a debug info section, specified to be 4 bytes in the |
193 | DWARF-2 specification. The SGI/MIPS ABI defines it to be the same | |
b13fe8bf | 194 | as PTR_SIZE. */ |
71dfc51f | 195 | |
7e23cb16 JM |
196 | #ifndef DWARF_OFFSET_SIZE |
197 | #define DWARF_OFFSET_SIZE 4 | |
198 | #endif | |
199 | ||
9a666dda JM |
200 | #define DWARF_VERSION 2 |
201 | ||
7e23cb16 JM |
202 | /* Round SIZE up to the nearest BOUNDARY. */ |
203 | #define DWARF_ROUND(SIZE,BOUNDARY) \ | |
262b6384 | 204 | ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY)) |
a3f97cbb | 205 | |
a3f97cbb | 206 | /* Offsets recorded in opcodes are a multiple of this alignment factor. */ |
27c35f4b | 207 | #ifndef DWARF_CIE_DATA_ALIGNMENT |
469ac993 | 208 | #ifdef STACK_GROWS_DOWNWARD |
08cb3d38 | 209 | #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD)) |
469ac993 | 210 | #else |
08cb3d38 | 211 | #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD) |
469ac993 | 212 | #endif |
27c35f4b | 213 | #endif /* not DWARF_CIE_DATA_ALIGNMENT */ |
a3f97cbb | 214 | |
3f76745e JM |
215 | /* A pointer to the base of a table that contains frame description |
216 | information for each routine. */ | |
217 | static dw_fde_ref fde_table; | |
a3f97cbb | 218 | |
3f76745e JM |
219 | /* Number of elements currently allocated for fde_table. */ |
220 | static unsigned fde_table_allocated; | |
a94dbf2c | 221 | |
3f76745e JM |
222 | /* Number of elements in fde_table currently in use. */ |
223 | static unsigned fde_table_in_use; | |
a3f97cbb | 224 | |
3f76745e JM |
225 | /* Size (in elements) of increments by which we may expand the |
226 | fde_table. */ | |
227 | #define FDE_TABLE_INCREMENT 256 | |
a3f97cbb | 228 | |
a94dbf2c JM |
229 | /* A list of call frame insns for the CIE. */ |
230 | static dw_cfi_ref cie_cfi_head; | |
231 | ||
a3f97cbb JW |
232 | /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram |
233 | attribute that accelerates the lookup of the FDE associated | |
556273e0 | 234 | with the subprogram. This variable holds the table index of the FDE |
a3f97cbb JW |
235 | associated with the current function (body) definition. */ |
236 | static unsigned current_funcdef_fde; | |
237 | ||
a3f97cbb | 238 | /* Forward declarations for functions defined in this file. */ |
71dfc51f | 239 | |
83d2b3b9 KG |
240 | static char *stripattributes PARAMS ((const char *)); |
241 | static const char *dwarf_cfi_name PARAMS ((unsigned)); | |
242 | static dw_cfi_ref new_cfi PARAMS ((void)); | |
243 | static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref)); | |
d3e3972c | 244 | static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref)); |
7d9d8943 AM |
245 | static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *)); |
246 | static void lookup_cfa PARAMS ((dw_cfa_location *)); | |
d3e3972c KG |
247 | static void reg_save PARAMS ((const char *, unsigned, |
248 | unsigned, long)); | |
83d2b3b9 | 249 | static void initial_return_save PARAMS ((rtx)); |
5e640c56 | 250 | static long stack_adjust_offset PARAMS ((rtx)); |
12f0b96b | 251 | static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int)); |
83d2b3b9 | 252 | static void output_call_frame_info PARAMS ((int)); |
83d2b3b9 | 253 | static void dwarf2out_stack_adjust PARAMS ((rtx)); |
fbfa55b0 RH |
254 | static void queue_reg_save PARAMS ((const char *, rtx, long)); |
255 | static void flush_queued_reg_saves PARAMS ((void)); | |
256 | static bool clobbers_queued_reg_save PARAMS ((rtx)); | |
d3e3972c | 257 | static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *)); |
a3f97cbb | 258 | |
7d9d8943 AM |
259 | /* Support for complex CFA locations. */ |
260 | static void output_cfa_loc PARAMS ((dw_cfi_ref)); | |
556273e0 | 261 | static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *, |
7d9d8943 AM |
262 | struct dw_loc_descr_struct *)); |
263 | static struct dw_loc_descr_struct *build_cfa_loc | |
264 | PARAMS ((dw_cfa_location *)); | |
265 | static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *)); | |
266 | ||
2e4b9b8c RH |
267 | /* How to start an assembler comment. */ |
268 | #ifndef ASM_COMMENT_START | |
269 | #define ASM_COMMENT_START ";#" | |
a3f97cbb JW |
270 | #endif |
271 | ||
7e23cb16 JM |
272 | /* Data and reference forms for relocatable data. */ |
273 | #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4) | |
274 | #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4) | |
275 | ||
a3f97cbb JW |
276 | /* Pseudo-op for defining a new section. */ |
277 | #ifndef SECTION_ASM_OP | |
0a3e1f45 | 278 | #define SECTION_ASM_OP "\t.section\t" |
a3f97cbb JW |
279 | #endif |
280 | ||
cf2fe500 RH |
281 | #ifndef DEBUG_FRAME_SECTION |
282 | #define DEBUG_FRAME_SECTION ".debug_frame" | |
a3f97cbb | 283 | #endif |
a3f97cbb | 284 | |
5c90448c JM |
285 | #ifndef FUNC_BEGIN_LABEL |
286 | #define FUNC_BEGIN_LABEL "LFB" | |
a3f97cbb | 287 | #endif |
5c90448c JM |
288 | #ifndef FUNC_END_LABEL |
289 | #define FUNC_END_LABEL "LFE" | |
a3f97cbb | 290 | #endif |
a6ab3aad JM |
291 | #define CIE_AFTER_SIZE_LABEL "LSCIE" |
292 | #define CIE_END_LABEL "LECIE" | |
2ed2af28 | 293 | #define CIE_LENGTH_LABEL "LLCIE" |
2e4b9b8c RH |
294 | #define FDE_LABEL "LSFDE" |
295 | #define FDE_AFTER_SIZE_LABEL "LASFDE" | |
a6ab3aad | 296 | #define FDE_END_LABEL "LEFDE" |
2ed2af28 | 297 | #define FDE_LENGTH_LABEL "LLFDE" |
981975b6 RH |
298 | #define LINE_NUMBER_BEGIN_LABEL "LSLT" |
299 | #define LINE_NUMBER_END_LABEL "LELT" | |
300 | #define LN_PROLOG_AS_LABEL "LASLTP" | |
301 | #define LN_PROLOG_END_LABEL "LELTP" | |
881c6935 | 302 | #define DIE_LABEL_PREFIX "DW" |
a3f97cbb | 303 | |
a3f97cbb JW |
304 | /* Definitions of defaults for various types of primitive assembly language |
305 | output operations. These may be overridden from within the tm.h file, | |
956d6950 | 306 | but typically, that is unnecessary. */ |
71dfc51f | 307 | |
2ed2af28 PDM |
308 | #ifdef SET_ASM_OP |
309 | #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL | |
7bb9fb0e JM |
310 | #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \ |
311 | do { \ | |
e8638df0 | 312 | fprintf (FILE, "%s", SET_ASM_OP); \ |
7bb9fb0e JM |
313 | assemble_name (FILE, SY); \ |
314 | fputc (',', FILE); \ | |
315 | assemble_name (FILE, HI); \ | |
316 | fputc ('-', FILE); \ | |
317 | assemble_name (FILE, LO); \ | |
318 | } while (0) | |
2ed2af28 PDM |
319 | #endif |
320 | #endif /* SET_ASM_OP */ | |
321 | ||
c8cc5c4a | 322 | /* The DWARF 2 CFA column which tracks the return address. Normally this |
a94dbf2c JM |
323 | is the column for PC, or the first column after all of the hard |
324 | registers. */ | |
c8cc5c4a | 325 | #ifndef DWARF_FRAME_RETURN_COLUMN |
a94dbf2c JM |
326 | #ifdef PC_REGNUM |
327 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM) | |
328 | #else | |
3073d01c | 329 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS |
a94dbf2c | 330 | #endif |
c8cc5c4a JM |
331 | #endif |
332 | ||
333 | /* The mapping from gcc register number to DWARF 2 CFA column number. By | |
469ac993 | 334 | default, we just provide columns for all registers. */ |
c8cc5c4a | 335 | #ifndef DWARF_FRAME_REGNUM |
469ac993 | 336 | #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG) |
c8cc5c4a | 337 | #endif |
3f76745e | 338 | |
0021b564 JM |
339 | /* Hook used by __throw. */ |
340 | ||
341 | rtx | |
342 | expand_builtin_dwarf_fp_regnum () | |
343 | { | |
344 | return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM)); | |
345 | } | |
346 | ||
a6ab3aad JM |
347 | /* The offset from the incoming value of %sp to the top of the stack frame |
348 | for the current function. */ | |
349 | #ifndef INCOMING_FRAME_SP_OFFSET | |
350 | #define INCOMING_FRAME_SP_OFFSET 0 | |
351 | #endif | |
a51d908e | 352 | \f |
71dfc51f | 353 | /* Return a pointer to a copy of the section string name S with all |
bf20f341 | 354 | attributes stripped off, and an asterisk prepended (for assemble_name). */ |
71dfc51f RK |
355 | |
356 | static inline char * | |
a3f97cbb | 357 | stripattributes (s) |
d560ee52 | 358 | const char *s; |
a3f97cbb | 359 | { |
bf20f341 | 360 | char *stripped = xmalloc (strlen (s) + 2); |
71dfc51f RK |
361 | char *p = stripped; |
362 | ||
bf20f341 JW |
363 | *p++ = '*'; |
364 | ||
365 | while (*s && *s != ',') | |
366 | *p++ = *s++; | |
71dfc51f | 367 | |
a3f97cbb JW |
368 | *p = '\0'; |
369 | return stripped; | |
370 | } | |
371 | ||
d9d5c9de | 372 | /* Generate code to initialize the register size table. */ |
2f3ca9e7 | 373 | |
d9d5c9de BS |
374 | void |
375 | expand_builtin_init_dwarf_reg_sizes (address) | |
376 | tree address; | |
2f3ca9e7 | 377 | { |
d9d5c9de BS |
378 | int i; |
379 | enum machine_mode mode = TYPE_MODE (char_type_node); | |
380 | rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0); | |
381 | rtx mem = gen_rtx_MEM (mode, addr); | |
2f3ca9e7 | 382 | |
376e12ab | 383 | for (i = 0; i < DWARF_FRAME_REGISTERS; ++i) |
2f3ca9e7 | 384 | { |
e0e07bd1 | 385 | int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode); |
d9d5c9de | 386 | int size = GET_MODE_SIZE (reg_raw_mode[i]); |
2f3ca9e7 | 387 | |
c699cee9 JM |
388 | if (offset < 0) |
389 | continue; | |
390 | ||
f4ef873c | 391 | emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size)); |
2f3ca9e7 | 392 | } |
2f3ca9e7 JM |
393 | } |
394 | ||
3f76745e | 395 | /* Convert a DWARF call frame info. operation to its string name */ |
a3f97cbb | 396 | |
d560ee52 | 397 | static const char * |
3f76745e JM |
398 | dwarf_cfi_name (cfi_opc) |
399 | register unsigned cfi_opc; | |
400 | { | |
401 | switch (cfi_opc) | |
402 | { | |
403 | case DW_CFA_advance_loc: | |
404 | return "DW_CFA_advance_loc"; | |
405 | case DW_CFA_offset: | |
406 | return "DW_CFA_offset"; | |
407 | case DW_CFA_restore: | |
408 | return "DW_CFA_restore"; | |
409 | case DW_CFA_nop: | |
410 | return "DW_CFA_nop"; | |
411 | case DW_CFA_set_loc: | |
412 | return "DW_CFA_set_loc"; | |
413 | case DW_CFA_advance_loc1: | |
414 | return "DW_CFA_advance_loc1"; | |
415 | case DW_CFA_advance_loc2: | |
416 | return "DW_CFA_advance_loc2"; | |
417 | case DW_CFA_advance_loc4: | |
418 | return "DW_CFA_advance_loc4"; | |
419 | case DW_CFA_offset_extended: | |
420 | return "DW_CFA_offset_extended"; | |
421 | case DW_CFA_restore_extended: | |
422 | return "DW_CFA_restore_extended"; | |
423 | case DW_CFA_undefined: | |
424 | return "DW_CFA_undefined"; | |
425 | case DW_CFA_same_value: | |
426 | return "DW_CFA_same_value"; | |
427 | case DW_CFA_register: | |
428 | return "DW_CFA_register"; | |
429 | case DW_CFA_remember_state: | |
430 | return "DW_CFA_remember_state"; | |
431 | case DW_CFA_restore_state: | |
432 | return "DW_CFA_restore_state"; | |
433 | case DW_CFA_def_cfa: | |
434 | return "DW_CFA_def_cfa"; | |
435 | case DW_CFA_def_cfa_register: | |
436 | return "DW_CFA_def_cfa_register"; | |
437 | case DW_CFA_def_cfa_offset: | |
438 | return "DW_CFA_def_cfa_offset"; | |
7d9d8943 AM |
439 | case DW_CFA_def_cfa_expression: |
440 | return "DW_CFA_def_cfa_expression"; | |
c53aa195 | 441 | |
3f76745e JM |
442 | /* SGI/MIPS specific */ |
443 | case DW_CFA_MIPS_advance_loc8: | |
444 | return "DW_CFA_MIPS_advance_loc8"; | |
c53aa195 JM |
445 | |
446 | /* GNU extensions */ | |
447 | case DW_CFA_GNU_window_save: | |
448 | return "DW_CFA_GNU_window_save"; | |
0021b564 JM |
449 | case DW_CFA_GNU_args_size: |
450 | return "DW_CFA_GNU_args_size"; | |
3f388b42 GK |
451 | case DW_CFA_GNU_negative_offset_extended: |
452 | return "DW_CFA_GNU_negative_offset_extended"; | |
c53aa195 | 453 | |
3f76745e JM |
454 | default: |
455 | return "DW_CFA_<unknown>"; | |
456 | } | |
457 | } | |
a3f97cbb | 458 | |
3f76745e | 459 | /* Return a pointer to a newly allocated Call Frame Instruction. */ |
71dfc51f | 460 | |
3f76745e JM |
461 | static inline dw_cfi_ref |
462 | new_cfi () | |
463 | { | |
464 | register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node)); | |
71dfc51f | 465 | |
3f76745e JM |
466 | cfi->dw_cfi_next = NULL; |
467 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0; | |
468 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0; | |
a3f97cbb | 469 | |
3f76745e JM |
470 | return cfi; |
471 | } | |
a3f97cbb | 472 | |
3f76745e | 473 | /* Add a Call Frame Instruction to list of instructions. */ |
a3f97cbb | 474 | |
3f76745e JM |
475 | static inline void |
476 | add_cfi (list_head, cfi) | |
477 | register dw_cfi_ref *list_head; | |
478 | register dw_cfi_ref cfi; | |
479 | { | |
480 | register dw_cfi_ref *p; | |
a3f97cbb | 481 | |
3f76745e JM |
482 | /* Find the end of the chain. */ |
483 | for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next) | |
484 | ; | |
485 | ||
486 | *p = cfi; | |
a3f97cbb JW |
487 | } |
488 | ||
3f76745e | 489 | /* Generate a new label for the CFI info to refer to. */ |
71dfc51f | 490 | |
c53aa195 | 491 | char * |
3f76745e | 492 | dwarf2out_cfi_label () |
a3f97cbb | 493 | { |
3f76745e JM |
494 | static char label[20]; |
495 | static unsigned long label_num = 0; | |
556273e0 | 496 | |
3f76745e JM |
497 | ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++); |
498 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
499 | ||
500 | return label; | |
a3f97cbb JW |
501 | } |
502 | ||
3f76745e JM |
503 | /* Add CFI to the current fde at the PC value indicated by LABEL if specified, |
504 | or to the CIE if LABEL is NULL. */ | |
71dfc51f | 505 | |
3f76745e JM |
506 | static void |
507 | add_fde_cfi (label, cfi) | |
d3e3972c | 508 | register const char *label; |
3f76745e | 509 | register dw_cfi_ref cfi; |
a3f97cbb | 510 | { |
3f76745e JM |
511 | if (label) |
512 | { | |
513 | register dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; | |
a3f97cbb | 514 | |
3f76745e JM |
515 | if (*label == 0) |
516 | label = dwarf2out_cfi_label (); | |
71dfc51f | 517 | |
3f76745e JM |
518 | if (fde->dw_fde_current_label == NULL |
519 | || strcmp (label, fde->dw_fde_current_label) != 0) | |
520 | { | |
521 | register dw_cfi_ref xcfi; | |
a3f97cbb | 522 | |
3f76745e | 523 | fde->dw_fde_current_label = label = xstrdup (label); |
71dfc51f | 524 | |
3f76745e JM |
525 | /* Set the location counter to the new label. */ |
526 | xcfi = new_cfi (); | |
527 | xcfi->dw_cfi_opc = DW_CFA_advance_loc4; | |
528 | xcfi->dw_cfi_oprnd1.dw_cfi_addr = label; | |
529 | add_cfi (&fde->dw_fde_cfi, xcfi); | |
530 | } | |
71dfc51f | 531 | |
3f76745e JM |
532 | add_cfi (&fde->dw_fde_cfi, cfi); |
533 | } | |
534 | ||
535 | else | |
536 | add_cfi (&cie_cfi_head, cfi); | |
a3f97cbb JW |
537 | } |
538 | ||
3f76745e | 539 | /* Subroutine of lookup_cfa. */ |
71dfc51f | 540 | |
3f76745e | 541 | static inline void |
7d9d8943 | 542 | lookup_cfa_1 (cfi, loc) |
3f76745e | 543 | register dw_cfi_ref cfi; |
7d9d8943 | 544 | register dw_cfa_location *loc; |
a3f97cbb | 545 | { |
3f76745e JM |
546 | switch (cfi->dw_cfi_opc) |
547 | { | |
548 | case DW_CFA_def_cfa_offset: | |
7d9d8943 | 549 | loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset; |
3f76745e JM |
550 | break; |
551 | case DW_CFA_def_cfa_register: | |
7d9d8943 | 552 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
3f76745e JM |
553 | break; |
554 | case DW_CFA_def_cfa: | |
7d9d8943 AM |
555 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
556 | loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset; | |
557 | break; | |
558 | case DW_CFA_def_cfa_expression: | |
559 | get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc); | |
3f76745e | 560 | break; |
e9a25f70 JL |
561 | default: |
562 | break; | |
3f76745e | 563 | } |
a3f97cbb JW |
564 | } |
565 | ||
3f76745e | 566 | /* Find the previous value for the CFA. */ |
71dfc51f | 567 | |
3f76745e | 568 | static void |
7d9d8943 AM |
569 | lookup_cfa (loc) |
570 | register dw_cfa_location *loc; | |
a3f97cbb | 571 | { |
3f76745e JM |
572 | register dw_cfi_ref cfi; |
573 | ||
7d9d8943 AM |
574 | loc->reg = (unsigned long) -1; |
575 | loc->offset = 0; | |
576 | loc->indirect = 0; | |
577 | loc->base_offset = 0; | |
3f76745e JM |
578 | |
579 | for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next) | |
7d9d8943 | 580 | lookup_cfa_1 (cfi, loc); |
3f76745e JM |
581 | |
582 | if (fde_table_in_use) | |
a3f97cbb | 583 | { |
3f76745e JM |
584 | register dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
585 | for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next) | |
7d9d8943 | 586 | lookup_cfa_1 (cfi, loc); |
a3f97cbb JW |
587 | } |
588 | } | |
589 | ||
3f76745e | 590 | /* The current rule for calculating the DWARF2 canonical frame address. */ |
fbfa55b0 | 591 | static dw_cfa_location cfa; |
71dfc51f | 592 | |
3f76745e JM |
593 | /* The register used for saving registers to the stack, and its offset |
594 | from the CFA. */ | |
fbfa55b0 | 595 | static dw_cfa_location cfa_store; |
3f76745e | 596 | |
0021b564 JM |
597 | /* The running total of the size of arguments pushed onto the stack. */ |
598 | static long args_size; | |
599 | ||
b57d9225 JM |
600 | /* The last args_size we actually output. */ |
601 | static long old_args_size; | |
602 | ||
3f76745e JM |
603 | /* Entry point to update the canonical frame address (CFA). |
604 | LABEL is passed to add_fde_cfi. The value of CFA is now to be | |
605 | calculated from REG+OFFSET. */ | |
606 | ||
607 | void | |
608 | dwarf2out_def_cfa (label, reg, offset) | |
d3e3972c | 609 | register const char *label; |
7d9d8943 AM |
610 | unsigned reg; |
611 | long offset; | |
612 | { | |
613 | dw_cfa_location loc; | |
614 | loc.indirect = 0; | |
615 | loc.base_offset = 0; | |
616 | loc.reg = reg; | |
617 | loc.offset = offset; | |
618 | def_cfa_1 (label, &loc); | |
619 | } | |
620 | ||
770ca8c6 | 621 | /* This routine does the actual work. The CFA is now calculated from |
7d9d8943 AM |
622 | the dw_cfa_location structure. */ |
623 | static void | |
624 | def_cfa_1 (label, loc_p) | |
625 | register const char *label; | |
626 | dw_cfa_location *loc_p; | |
a3f97cbb | 627 | { |
3f76745e | 628 | register dw_cfi_ref cfi; |
7d9d8943 | 629 | dw_cfa_location old_cfa, loc; |
3f76745e | 630 | |
7d9d8943 AM |
631 | cfa = *loc_p; |
632 | loc = *loc_p; | |
5bef9b1f | 633 | |
7d9d8943 AM |
634 | if (cfa_store.reg == loc.reg && loc.indirect == 0) |
635 | cfa_store.offset = loc.offset; | |
3f76745e | 636 | |
7d9d8943 AM |
637 | loc.reg = DWARF_FRAME_REGNUM (loc.reg); |
638 | lookup_cfa (&old_cfa); | |
639 | ||
640 | if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset && | |
641 | loc.indirect == old_cfa.indirect) | |
642 | { | |
e09bbb25 JM |
643 | if (loc.indirect == 0 |
644 | || loc.base_offset == old_cfa.base_offset) | |
770ca8c6 JO |
645 | /* Nothing changed so no need to issue any call frame |
646 | instructions. */ | |
7d9d8943 | 647 | return; |
7d9d8943 | 648 | } |
3f76745e JM |
649 | |
650 | cfi = new_cfi (); | |
651 | ||
e09bbb25 | 652 | if (loc.reg == old_cfa.reg && !loc.indirect) |
a3f97cbb | 653 | { |
770ca8c6 JO |
654 | /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, |
655 | indicating the CFA register did not change but the offset | |
656 | did. */ | |
3f76745e | 657 | cfi->dw_cfi_opc = DW_CFA_def_cfa_offset; |
7d9d8943 | 658 | cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset; |
3f76745e | 659 | } |
a3f97cbb | 660 | |
3f76745e | 661 | #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */ |
7d9d8943 | 662 | else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1 |
e09bbb25 | 663 | && !loc.indirect) |
3f76745e | 664 | { |
770ca8c6 JO |
665 | /* Construct a "DW_CFA_def_cfa_register <register>" instruction, |
666 | indicating the CFA register has changed to <register> but the | |
667 | offset has not changed. */ | |
3f76745e | 668 | cfi->dw_cfi_opc = DW_CFA_def_cfa_register; |
7d9d8943 | 669 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
3f76745e JM |
670 | } |
671 | #endif | |
a3f97cbb | 672 | |
7d9d8943 | 673 | else if (loc.indirect == 0) |
3f76745e | 674 | { |
770ca8c6 JO |
675 | /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction, |
676 | indicating the CFA register has changed to <register> with | |
677 | the specified offset. */ | |
3f76745e | 678 | cfi->dw_cfi_opc = DW_CFA_def_cfa; |
7d9d8943 AM |
679 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
680 | cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset; | |
681 | } | |
682 | else | |
683 | { | |
770ca8c6 JO |
684 | /* Construct a DW_CFA_def_cfa_expression instruction to |
685 | calculate the CFA using a full location expression since no | |
686 | register-offset pair is available. */ | |
556273e0 | 687 | struct dw_loc_descr_struct *loc_list; |
7d9d8943 AM |
688 | cfi->dw_cfi_opc = DW_CFA_def_cfa_expression; |
689 | loc_list = build_cfa_loc (&loc); | |
690 | cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list; | |
a3f97cbb | 691 | } |
3f76745e JM |
692 | |
693 | add_fde_cfi (label, cfi); | |
a3f97cbb JW |
694 | } |
695 | ||
3f76745e JM |
696 | /* Add the CFI for saving a register. REG is the CFA column number. |
697 | LABEL is passed to add_fde_cfi. | |
698 | If SREG is -1, the register is saved at OFFSET from the CFA; | |
699 | otherwise it is saved in SREG. */ | |
71dfc51f | 700 | |
3f76745e JM |
701 | static void |
702 | reg_save (label, reg, sreg, offset) | |
d3e3972c | 703 | register const char *label; |
3f76745e JM |
704 | register unsigned reg; |
705 | register unsigned sreg; | |
706 | register long offset; | |
a3f97cbb | 707 | { |
3f76745e JM |
708 | register dw_cfi_ref cfi = new_cfi (); |
709 | ||
710 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
711 | ||
85066503 MH |
712 | /* The following comparison is correct. -1 is used to indicate that |
713 | the value isn't a register number. */ | |
714 | if (sreg == (unsigned int) -1) | |
a3f97cbb | 715 | { |
3f76745e JM |
716 | if (reg & ~0x3f) |
717 | /* The register number won't fit in 6 bits, so we have to use | |
718 | the long form. */ | |
719 | cfi->dw_cfi_opc = DW_CFA_offset_extended; | |
720 | else | |
721 | cfi->dw_cfi_opc = DW_CFA_offset; | |
722 | ||
27c35f4b HPN |
723 | #ifdef ENABLE_CHECKING |
724 | { | |
725 | /* If we get an offset that is not a multiple of | |
726 | DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the | |
727 | definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine | |
728 | description. */ | |
729 | long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT; | |
730 | ||
731 | if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset) | |
732 | abort (); | |
733 | } | |
734 | #endif | |
3f76745e | 735 | offset /= DWARF_CIE_DATA_ALIGNMENT; |
3a88cbd1 | 736 | if (offset < 0) |
3f388b42 GK |
737 | { |
738 | cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended; | |
739 | offset = -offset; | |
740 | } | |
3f76745e JM |
741 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; |
742 | } | |
2c849145 JM |
743 | else if (sreg == reg) |
744 | /* We could emit a DW_CFA_same_value in this case, but don't bother. */ | |
745 | return; | |
3f76745e JM |
746 | else |
747 | { | |
748 | cfi->dw_cfi_opc = DW_CFA_register; | |
749 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg; | |
750 | } | |
751 | ||
752 | add_fde_cfi (label, cfi); | |
753 | } | |
754 | ||
c53aa195 JM |
755 | /* Add the CFI for saving a register window. LABEL is passed to reg_save. |
756 | This CFI tells the unwinder that it needs to restore the window registers | |
757 | from the previous frame's window save area. | |
556273e0 | 758 | |
c53aa195 JM |
759 | ??? Perhaps we should note in the CIE where windows are saved (instead of |
760 | assuming 0(cfa)) and what registers are in the window. */ | |
761 | ||
762 | void | |
763 | dwarf2out_window_save (label) | |
d3e3972c | 764 | register const char *label; |
c53aa195 JM |
765 | { |
766 | register dw_cfi_ref cfi = new_cfi (); | |
767 | cfi->dw_cfi_opc = DW_CFA_GNU_window_save; | |
768 | add_fde_cfi (label, cfi); | |
769 | } | |
770 | ||
0021b564 JM |
771 | /* Add a CFI to update the running total of the size of arguments |
772 | pushed onto the stack. */ | |
773 | ||
774 | void | |
775 | dwarf2out_args_size (label, size) | |
d3e3972c | 776 | const char *label; |
0021b564 JM |
777 | long size; |
778 | { | |
b57d9225 JM |
779 | register dw_cfi_ref cfi; |
780 | ||
781 | if (size == old_args_size) | |
782 | return; | |
783 | old_args_size = size; | |
784 | ||
785 | cfi = new_cfi (); | |
0021b564 JM |
786 | cfi->dw_cfi_opc = DW_CFA_GNU_args_size; |
787 | cfi->dw_cfi_oprnd1.dw_cfi_offset = size; | |
788 | add_fde_cfi (label, cfi); | |
789 | } | |
790 | ||
c53aa195 JM |
791 | /* Entry point for saving a register to the stack. REG is the GCC register |
792 | number. LABEL and OFFSET are passed to reg_save. */ | |
3f76745e JM |
793 | |
794 | void | |
795 | dwarf2out_reg_save (label, reg, offset) | |
d3e3972c | 796 | register const char *label; |
3f76745e JM |
797 | register unsigned reg; |
798 | register long offset; | |
799 | { | |
800 | reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset); | |
801 | } | |
802 | ||
c53aa195 JM |
803 | /* Entry point for saving the return address in the stack. |
804 | LABEL and OFFSET are passed to reg_save. */ | |
805 | ||
806 | void | |
807 | dwarf2out_return_save (label, offset) | |
d3e3972c | 808 | register const char *label; |
c53aa195 JM |
809 | register long offset; |
810 | { | |
811 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset); | |
812 | } | |
813 | ||
814 | /* Entry point for saving the return address in a register. | |
815 | LABEL and SREG are passed to reg_save. */ | |
816 | ||
817 | void | |
818 | dwarf2out_return_reg (label, sreg) | |
d3e3972c | 819 | register const char *label; |
c53aa195 JM |
820 | register unsigned sreg; |
821 | { | |
822 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0); | |
823 | } | |
824 | ||
3f76745e JM |
825 | /* Record the initial position of the return address. RTL is |
826 | INCOMING_RETURN_ADDR_RTX. */ | |
827 | ||
828 | static void | |
829 | initial_return_save (rtl) | |
830 | register rtx rtl; | |
831 | { | |
973838fd | 832 | unsigned int reg = (unsigned int) -1; |
3f76745e JM |
833 | long offset = 0; |
834 | ||
835 | switch (GET_CODE (rtl)) | |
836 | { | |
837 | case REG: | |
838 | /* RA is in a register. */ | |
2c849145 | 839 | reg = DWARF_FRAME_REGNUM (REGNO (rtl)); |
3f76745e JM |
840 | break; |
841 | case MEM: | |
842 | /* RA is on the stack. */ | |
843 | rtl = XEXP (rtl, 0); | |
844 | switch (GET_CODE (rtl)) | |
845 | { | |
846 | case REG: | |
3a88cbd1 JL |
847 | if (REGNO (rtl) != STACK_POINTER_REGNUM) |
848 | abort (); | |
3f76745e JM |
849 | offset = 0; |
850 | break; | |
851 | case PLUS: | |
3a88cbd1 JL |
852 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
853 | abort (); | |
3f76745e JM |
854 | offset = INTVAL (XEXP (rtl, 1)); |
855 | break; | |
856 | case MINUS: | |
3a88cbd1 JL |
857 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
858 | abort (); | |
3f76745e JM |
859 | offset = -INTVAL (XEXP (rtl, 1)); |
860 | break; | |
861 | default: | |
862 | abort (); | |
863 | } | |
864 | break; | |
c53aa195 JM |
865 | case PLUS: |
866 | /* The return address is at some offset from any value we can | |
867 | actually load. For instance, on the SPARC it is in %i7+8. Just | |
868 | ignore the offset for now; it doesn't matter for unwinding frames. */ | |
3a88cbd1 JL |
869 | if (GET_CODE (XEXP (rtl, 1)) != CONST_INT) |
870 | abort (); | |
c53aa195 JM |
871 | initial_return_save (XEXP (rtl, 0)); |
872 | return; | |
a3f97cbb | 873 | default: |
3f76745e | 874 | abort (); |
a3f97cbb | 875 | } |
3f76745e | 876 | |
7d9d8943 | 877 | reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset); |
a3f97cbb JW |
878 | } |
879 | ||
1ba5ae8f | 880 | /* Given a SET, calculate the amount of stack adjustment it |
30f7a378 | 881 | contains. */ |
1ba5ae8f | 882 | |
5e640c56 AH |
883 | static long |
884 | stack_adjust_offset (pattern) | |
1ba5ae8f AH |
885 | rtx pattern; |
886 | { | |
887 | rtx src = SET_SRC (pattern); | |
888 | rtx dest = SET_DEST (pattern); | |
889 | long offset = 0; | |
890 | enum rtx_code code; | |
891 | ||
892 | if (dest == stack_pointer_rtx) | |
893 | { | |
894 | /* (set (reg sp) (plus (reg sp) (const_int))) */ | |
895 | code = GET_CODE (src); | |
896 | if (! (code == PLUS || code == MINUS) | |
897 | || XEXP (src, 0) != stack_pointer_rtx | |
898 | || GET_CODE (XEXP (src, 1)) != CONST_INT) | |
899 | return 0; | |
900 | ||
901 | offset = INTVAL (XEXP (src, 1)); | |
902 | } | |
903 | else if (GET_CODE (dest) == MEM) | |
904 | { | |
905 | /* (set (mem (pre_dec (reg sp))) (foo)) */ | |
906 | src = XEXP (dest, 0); | |
907 | code = GET_CODE (src); | |
908 | ||
e2134eea JH |
909 | if (! (code == PRE_DEC || code == PRE_INC |
910 | || code == PRE_MODIFY) | |
1ba5ae8f AH |
911 | || XEXP (src, 0) != stack_pointer_rtx) |
912 | return 0; | |
913 | ||
e2134eea JH |
914 | if (code == PRE_MODIFY) |
915 | { | |
916 | rtx val = XEXP (XEXP (src, 1), 1); | |
917 | /* We handle only adjustments by constant amount. */ | |
918 | if (GET_CODE (XEXP (src, 1)) != PLUS || | |
919 | GET_CODE (val) != CONST_INT) | |
920 | abort(); | |
921 | offset = -INTVAL (val); | |
922 | } | |
923 | else offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1ba5ae8f AH |
924 | } |
925 | else | |
926 | return 0; | |
927 | ||
928 | if (code == PLUS || code == PRE_INC) | |
929 | offset = -offset; | |
930 | ||
931 | return offset; | |
932 | } | |
933 | ||
0021b564 JM |
934 | /* Check INSN to see if it looks like a push or a stack adjustment, and |
935 | make a note of it if it does. EH uses this information to find out how | |
936 | much extra space it needs to pop off the stack. */ | |
937 | ||
938 | static void | |
939 | dwarf2out_stack_adjust (insn) | |
940 | rtx insn; | |
941 | { | |
0021b564 | 942 | long offset; |
d3e3972c | 943 | const char *label; |
0021b564 | 944 | |
c1e9f663 | 945 | if (! flag_non_call_exceptions && GET_CODE (insn) == CALL_INSN) |
b57d9225 JM |
946 | { |
947 | /* Extract the size of the args from the CALL rtx itself. */ | |
948 | ||
949 | insn = PATTERN (insn); | |
950 | if (GET_CODE (insn) == PARALLEL) | |
951 | insn = XVECEXP (insn, 0, 0); | |
952 | if (GET_CODE (insn) == SET) | |
953 | insn = SET_SRC (insn); | |
3db35af4 MM |
954 | if (GET_CODE (insn) != CALL) |
955 | abort (); | |
b57d9225 JM |
956 | dwarf2out_args_size ("", INTVAL (XEXP (insn, 1))); |
957 | return; | |
958 | } | |
959 | ||
960 | /* If only calls can throw, and we have a frame pointer, | |
961 | save up adjustments until we see the CALL_INSN. */ | |
c1e9f663 | 962 | else if (! flag_non_call_exceptions |
7d9d8943 | 963 | && cfa.reg != STACK_POINTER_REGNUM) |
b57d9225 JM |
964 | return; |
965 | ||
6020d360 | 966 | if (GET_CODE (insn) == BARRIER) |
0021b564 | 967 | { |
6020d360 JM |
968 | /* When we see a BARRIER, we know to reset args_size to 0. Usually |
969 | the compiler will have already emitted a stack adjustment, but | |
970 | doesn't bother for calls to noreturn functions. */ | |
971 | #ifdef STACK_GROWS_DOWNWARD | |
972 | offset = -args_size; | |
973 | #else | |
974 | offset = args_size; | |
975 | #endif | |
0021b564 | 976 | } |
6020d360 | 977 | else if (GET_CODE (PATTERN (insn)) == SET) |
0021b564 | 978 | { |
1ba5ae8f AH |
979 | offset = stack_adjust_offset (PATTERN (insn)); |
980 | } | |
981 | else if (GET_CODE (PATTERN (insn)) == PARALLEL | |
982 | || GET_CODE (PATTERN (insn)) == SEQUENCE) | |
983 | { | |
984 | /* There may be stack adjustments inside compound insns. Search | |
30f7a378 | 985 | for them. */ |
1ba5ae8f | 986 | int j; |
0021b564 | 987 | |
1ba5ae8f AH |
988 | offset = 0; |
989 | for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--) | |
6020d360 | 990 | { |
1ba5ae8f AH |
991 | rtx pattern = XVECEXP (PATTERN (insn), 0, j); |
992 | if (GET_CODE (pattern) == SET) | |
993 | offset += stack_adjust_offset (pattern); | |
6020d360 | 994 | } |
0021b564 JM |
995 | } |
996 | else | |
997 | return; | |
0b34cf1e | 998 | |
6020d360 JM |
999 | if (offset == 0) |
1000 | return; | |
1001 | ||
7d9d8943 AM |
1002 | if (cfa.reg == STACK_POINTER_REGNUM) |
1003 | cfa.offset += offset; | |
0021b564 JM |
1004 | |
1005 | #ifndef STACK_GROWS_DOWNWARD | |
1006 | offset = -offset; | |
1007 | #endif | |
1008 | args_size += offset; | |
1009 | if (args_size < 0) | |
1010 | args_size = 0; | |
1011 | ||
1012 | label = dwarf2out_cfi_label (); | |
7d9d8943 | 1013 | def_cfa_1 (label, &cfa); |
0021b564 JM |
1014 | dwarf2out_args_size (label, args_size); |
1015 | } | |
1016 | ||
fbfa55b0 RH |
1017 | /* We delay emitting a register save until either (a) we reach the end |
1018 | of the prologue or (b) the register is clobbered. This clusters | |
1019 | register saves so that there are fewer pc advances. */ | |
1020 | ||
1021 | struct queued_reg_save | |
1022 | { | |
1023 | struct queued_reg_save *next; | |
1024 | rtx reg; | |
1025 | long cfa_offset; | |
1026 | }; | |
1027 | ||
1028 | static struct queued_reg_save *queued_reg_saves; | |
1029 | static const char *last_reg_save_label; | |
1030 | ||
1031 | static void | |
1032 | queue_reg_save (label, reg, offset) | |
1033 | const char *label; | |
1034 | rtx reg; | |
1035 | long offset; | |
1036 | { | |
1037 | struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q)); | |
1038 | ||
1039 | q->next = queued_reg_saves; | |
1040 | q->reg = reg; | |
1041 | q->cfa_offset = offset; | |
1042 | queued_reg_saves = q; | |
1043 | ||
1044 | last_reg_save_label = label; | |
1045 | } | |
1046 | ||
1047 | static void | |
1048 | flush_queued_reg_saves () | |
1049 | { | |
1050 | struct queued_reg_save *q, *next; | |
1051 | ||
1052 | for (q = queued_reg_saves; q ; q = next) | |
1053 | { | |
1054 | dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset); | |
1055 | next = q->next; | |
1056 | free (q); | |
1057 | } | |
1058 | ||
1059 | queued_reg_saves = NULL; | |
1060 | last_reg_save_label = NULL; | |
1061 | } | |
1062 | ||
1063 | static bool | |
1064 | clobbers_queued_reg_save (insn) | |
1065 | rtx insn; | |
1066 | { | |
1067 | struct queued_reg_save *q; | |
1068 | ||
1069 | for (q = queued_reg_saves; q ; q = q->next) | |
1070 | if (modified_in_p (q->reg, insn)) | |
1071 | return true; | |
1072 | ||
1073 | return false; | |
1074 | } | |
1075 | ||
1076 | ||
770ca8c6 JO |
1077 | /* A temporary register holding an integral value used in adjusting SP |
1078 | or setting up the store_reg. The "offset" field holds the integer | |
1079 | value, not an offset. */ | |
fbfa55b0 | 1080 | static dw_cfa_location cfa_temp; |
770ca8c6 JO |
1081 | |
1082 | /* Record call frame debugging information for an expression EXPR, | |
1083 | which either sets SP or FP (adjusting how we calculate the frame | |
1084 | address) or saves a register to the stack. LABEL indicates the | |
1085 | address of EXPR. | |
1086 | ||
1087 | This function encodes a state machine mapping rtxes to actions on | |
1088 | cfa, cfa_store, and cfa_temp.reg. We describe these rules so | |
1089 | users need not read the source code. | |
1090 | ||
a401107d JO |
1091 | The High-Level Picture |
1092 | ||
1093 | Changes in the register we use to calculate the CFA: Currently we | |
1094 | assume that if you copy the CFA register into another register, we | |
1095 | should take the other one as the new CFA register; this seems to | |
1096 | work pretty well. If it's wrong for some target, it's simple | |
1097 | enough not to set RTX_FRAME_RELATED_P on the insn in question. | |
1098 | ||
1099 | Changes in the register we use for saving registers to the stack: | |
1100 | This is usually SP, but not always. Again, we deduce that if you | |
1101 | copy SP into another register (and SP is not the CFA register), | |
1102 | then the new register is the one we will be using for register | |
1103 | saves. This also seems to work. | |
1104 | ||
1105 | Register saves: There's not much guesswork about this one; if | |
1106 | RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a | |
1107 | register save, and the register used to calculate the destination | |
1108 | had better be the one we think we're using for this purpose. | |
1109 | ||
1110 | Except: If the register being saved is the CFA register, and the | |
1111 | offset is non-zero, we are saving the CFA, so we assume we have to | |
1112 | use DW_CFA_def_cfa_expression. If the offset is 0, we assume that | |
1113 | the intent is to save the value of SP from the previous frame. | |
1114 | ||
770ca8c6 JO |
1115 | Invariants / Summaries of Rules |
1116 | ||
a401107d JO |
1117 | cfa current rule for calculating the CFA. It usually |
1118 | consists of a register and an offset. | |
770ca8c6 JO |
1119 | cfa_store register used by prologue code to save things to the stack |
1120 | cfa_store.offset is the offset from the value of | |
1121 | cfa_store.reg to the actual CFA | |
1122 | cfa_temp register holding an integral value. cfa_temp.offset | |
1123 | stores the value, which will be used to adjust the | |
19ec6a36 AM |
1124 | stack pointer. cfa_temp is also used like cfa_store, |
1125 | to track stores to the stack via fp or a temp reg. | |
770ca8c6 JO |
1126 | |
1127 | Rules 1- 4: Setting a register's value to cfa.reg or an expression | |
1128 | with cfa.reg as the first operand changes the cfa.reg and its | |
19ec6a36 AM |
1129 | cfa.offset. Rule 1 and 4 also set cfa_temp.reg and |
1130 | cfa_temp.offset. | |
770ca8c6 JO |
1131 | |
1132 | Rules 6- 9: Set a non-cfa.reg register value to a constant or an | |
1133 | expression yielding a constant. This sets cfa_temp.reg | |
1134 | and cfa_temp.offset. | |
1135 | ||
1136 | Rule 5: Create a new register cfa_store used to save items to the | |
1137 | stack. | |
1138 | ||
19ec6a36 | 1139 | Rules 10-14: Save a register to the stack. Define offset as the |
a401107d | 1140 | difference of the original location and cfa_store's |
19ec6a36 | 1141 | location (or cfa_temp's location if cfa_temp is used). |
770ca8c6 JO |
1142 | |
1143 | The Rules | |
1144 | ||
1145 | "{a,b}" indicates a choice of a xor b. | |
1146 | "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg. | |
1147 | ||
1148 | Rule 1: | |
1149 | (set <reg1> <reg2>:cfa.reg) | |
19ec6a36 | 1150 | effects: cfa.reg = <reg1> |
770ca8c6 | 1151 | cfa.offset unchanged |
19ec6a36 AM |
1152 | cfa_temp.reg = <reg1> |
1153 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1154 | |
1155 | Rule 2: | |
19ec6a36 | 1156 | (set sp ({minus,plus,losum} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg})) |
770ca8c6 JO |
1157 | effects: cfa.reg = sp if fp used |
1158 | cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp | |
1159 | cfa_store.offset += {+/- <const_int>, cfa_temp.offset} | |
1160 | if cfa_store.reg==sp | |
1161 | ||
1162 | Rule 3: | |
19ec6a36 | 1163 | (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>)) |
770ca8c6 JO |
1164 | effects: cfa.reg = fp |
1165 | cfa_offset += +/- <const_int> | |
1166 | ||
1167 | Rule 4: | |
19ec6a36 | 1168 | (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>)) |
770ca8c6 JO |
1169 | constraints: <reg1> != fp |
1170 | <reg1> != sp | |
1171 | effects: cfa.reg = <reg1> | |
19ec6a36 AM |
1172 | cfa_temp.reg = <reg1> |
1173 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1174 | |
1175 | Rule 5: | |
1176 | (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg)) | |
1177 | constraints: <reg1> != fp | |
1178 | <reg1> != sp | |
1179 | effects: cfa_store.reg = <reg1> | |
1180 | cfa_store.offset = cfa.offset - cfa_temp.offset | |
1181 | ||
1182 | Rule 6: | |
1183 | (set <reg> <const_int>) | |
1184 | effects: cfa_temp.reg = <reg> | |
1185 | cfa_temp.offset = <const_int> | |
1186 | ||
1187 | Rule 7: | |
1188 | (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>)) | |
1189 | effects: cfa_temp.reg = <reg1> | |
1190 | cfa_temp.offset |= <const_int> | |
1191 | ||
1192 | Rule 8: | |
1193 | (set <reg> (high <exp>)) | |
1194 | effects: none | |
1195 | ||
1196 | Rule 9: | |
1197 | (set <reg> (lo_sum <exp> <const_int>)) | |
1198 | effects: cfa_temp.reg = <reg> | |
1199 | cfa_temp.offset = <const_int> | |
1200 | ||
1201 | Rule 10: | |
1202 | (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>) | |
1203 | effects: cfa_store.offset -= <const_int> | |
1204 | cfa.offset = cfa_store.offset if cfa.reg == sp | |
770ca8c6 | 1205 | cfa.reg = sp |
19ec6a36 | 1206 | cfa.base_offset = -cfa_store.offset |
770ca8c6 JO |
1207 | |
1208 | Rule 11: | |
1209 | (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>) | |
1210 | effects: cfa_store.offset += -/+ mode_size(mem) | |
1211 | cfa.offset = cfa_store.offset if cfa.reg == sp | |
770ca8c6 | 1212 | cfa.reg = sp |
19ec6a36 | 1213 | cfa.base_offset = -cfa_store.offset |
770ca8c6 JO |
1214 | |
1215 | Rule 12: | |
19ec6a36 AM |
1216 | (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) <reg2>) |
1217 | effects: cfa.reg = <reg1> | |
1218 | cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset | |
770ca8c6 JO |
1219 | |
1220 | Rule 13: | |
19ec6a36 AM |
1221 | (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>) |
1222 | effects: cfa.reg = <reg1> | |
1223 | cfa.base_offset = -{cfa_store,cfa_temp}.offset | |
1224 | ||
1225 | Rule 14: | |
1226 | (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>) | |
1227 | effects: cfa.reg = <reg1> | |
1228 | cfa.base_offset = -cfa_temp.offset | |
1229 | cfa_temp.offset -= mode_size(mem) */ | |
b664de3a AM |
1230 | |
1231 | static void | |
1232 | dwarf2out_frame_debug_expr (expr, label) | |
1233 | rtx expr; | |
d3e3972c | 1234 | const char *label; |
b664de3a AM |
1235 | { |
1236 | rtx src, dest; | |
1237 | long offset; | |
556273e0 KH |
1238 | |
1239 | /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of | |
1240 | the PARALLEL independently. The first element is always processed if | |
770ca8c6 | 1241 | it is a SET. This is for backward compatibility. Other elements |
556273e0 KH |
1242 | are processed only if they are SETs and the RTX_FRAME_RELATED_P |
1243 | flag is set in them. */ | |
b664de3a | 1244 | |
79d13342 NC |
1245 | if (GET_CODE (expr) == PARALLEL |
1246 | || GET_CODE (expr) == SEQUENCE) | |
556273e0 | 1247 | { |
b664de3a AM |
1248 | int par_index; |
1249 | int limit = XVECLEN (expr, 0); | |
1250 | ||
1251 | for (par_index = 0; par_index < limit; par_index++) | |
556273e0 KH |
1252 | { |
1253 | rtx x = XVECEXP (expr, 0, par_index); | |
1254 | ||
1255 | if (GET_CODE (x) == SET && | |
b664de3a | 1256 | (RTX_FRAME_RELATED_P (x) || par_index == 0)) |
2618f955 | 1257 | dwarf2out_frame_debug_expr (x, label); |
556273e0 | 1258 | } |
b664de3a AM |
1259 | return; |
1260 | } | |
556273e0 | 1261 | |
b664de3a AM |
1262 | if (GET_CODE (expr) != SET) |
1263 | abort (); | |
1264 | ||
1265 | src = SET_SRC (expr); | |
1266 | dest = SET_DEST (expr); | |
1267 | ||
1268 | switch (GET_CODE (dest)) | |
1269 | { | |
1270 | case REG: | |
770ca8c6 | 1271 | /* Rule 1 */ |
b664de3a AM |
1272 | /* Update the CFA rule wrt SP or FP. Make sure src is |
1273 | relative to the current CFA register. */ | |
1274 | switch (GET_CODE (src)) | |
556273e0 KH |
1275 | { |
1276 | /* Setting FP from SP. */ | |
1277 | case REG: | |
1278 | if (cfa.reg == (unsigned) REGNO (src)) | |
1279 | /* OK. */ | |
1280 | ; | |
626d1efd | 1281 | else |
556273e0 | 1282 | abort (); |
2c849145 JM |
1283 | |
1284 | /* We used to require that dest be either SP or FP, but the | |
1285 | ARM copies SP to a temporary register, and from there to | |
1286 | FP. So we just rely on the backends to only set | |
1287 | RTX_FRAME_RELATED_P on appropriate insns. */ | |
556273e0 | 1288 | cfa.reg = REGNO (dest); |
19ec6a36 AM |
1289 | cfa_temp.reg = cfa.reg; |
1290 | cfa_temp.offset = cfa.offset; | |
556273e0 | 1291 | break; |
b664de3a | 1292 | |
556273e0 KH |
1293 | case PLUS: |
1294 | case MINUS: | |
19ec6a36 | 1295 | case LO_SUM: |
556273e0 KH |
1296 | if (dest == stack_pointer_rtx) |
1297 | { | |
770ca8c6 | 1298 | /* Rule 2 */ |
2618f955 MM |
1299 | /* Adjusting SP. */ |
1300 | switch (GET_CODE (XEXP (src, 1))) | |
1301 | { | |
1302 | case CONST_INT: | |
1303 | offset = INTVAL (XEXP (src, 1)); | |
1304 | break; | |
1305 | case REG: | |
770ca8c6 | 1306 | if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg) |
2618f955 | 1307 | abort (); |
770ca8c6 | 1308 | offset = cfa_temp.offset; |
2618f955 MM |
1309 | break; |
1310 | default: | |
1311 | abort (); | |
1312 | } | |
1313 | ||
1314 | if (XEXP (src, 0) == hard_frame_pointer_rtx) | |
1315 | { | |
1316 | /* Restoring SP from FP in the epilogue. */ | |
7d9d8943 | 1317 | if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM) |
2618f955 | 1318 | abort (); |
7d9d8943 | 1319 | cfa.reg = STACK_POINTER_REGNUM; |
2618f955 | 1320 | } |
19ec6a36 AM |
1321 | else if (GET_CODE (src) == LO_SUM) |
1322 | /* Assume we've set the source reg of the LO_SUM from sp. */ | |
1323 | ; | |
2618f955 MM |
1324 | else if (XEXP (src, 0) != stack_pointer_rtx) |
1325 | abort (); | |
1326 | ||
19ec6a36 | 1327 | if (GET_CODE (src) != MINUS) |
2618f955 | 1328 | offset = -offset; |
7d9d8943 AM |
1329 | if (cfa.reg == STACK_POINTER_REGNUM) |
1330 | cfa.offset += offset; | |
1331 | if (cfa_store.reg == STACK_POINTER_REGNUM) | |
1332 | cfa_store.offset += offset; | |
556273e0 KH |
1333 | } |
1334 | else if (dest == hard_frame_pointer_rtx) | |
1335 | { | |
770ca8c6 | 1336 | /* Rule 3 */ |
2618f955 MM |
1337 | /* Either setting the FP from an offset of the SP, |
1338 | or adjusting the FP */ | |
2c849145 | 1339 | if (! frame_pointer_needed) |
2618f955 MM |
1340 | abort (); |
1341 | ||
2c849145 | 1342 | if (GET_CODE (XEXP (src, 0)) == REG |
7d9d8943 | 1343 | && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg |
2618f955 MM |
1344 | && GET_CODE (XEXP (src, 1)) == CONST_INT) |
1345 | { | |
2618f955 | 1346 | offset = INTVAL (XEXP (src, 1)); |
19ec6a36 | 1347 | if (GET_CODE (src) != MINUS) |
2618f955 | 1348 | offset = -offset; |
7d9d8943 AM |
1349 | cfa.offset += offset; |
1350 | cfa.reg = HARD_FRAME_POINTER_REGNUM; | |
2618f955 | 1351 | } |
556273e0 KH |
1352 | else |
1353 | abort (); | |
1354 | } | |
1355 | else | |
1356 | { | |
19ec6a36 | 1357 | if (GET_CODE (src) == MINUS) |
2618f955 | 1358 | abort (); |
b53ef1a2 | 1359 | |
770ca8c6 | 1360 | /* Rule 4 */ |
b53ef1a2 NC |
1361 | if (GET_CODE (XEXP (src, 0)) == REG |
1362 | && REGNO (XEXP (src, 0)) == cfa.reg | |
1363 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
34ce3d7b JM |
1364 | { |
1365 | /* Setting a temporary CFA register that will be copied | |
1366 | into the FP later on. */ | |
19ec6a36 | 1367 | offset = - INTVAL (XEXP (src, 1)); |
34ce3d7b JM |
1368 | cfa.offset += offset; |
1369 | cfa.reg = REGNO (dest); | |
19ec6a36 AM |
1370 | /* Or used to save regs to the stack. */ |
1371 | cfa_temp.reg = cfa.reg; | |
1372 | cfa_temp.offset = cfa.offset; | |
34ce3d7b | 1373 | } |
770ca8c6 | 1374 | /* Rule 5 */ |
19ec6a36 AM |
1375 | else if (GET_CODE (XEXP (src, 0)) == REG |
1376 | && REGNO (XEXP (src, 0)) == cfa_temp.reg | |
1377 | && XEXP (src, 1) == stack_pointer_rtx) | |
b53ef1a2 | 1378 | { |
00a42e21 JM |
1379 | /* Setting a scratch register that we will use instead |
1380 | of SP for saving registers to the stack. */ | |
b53ef1a2 NC |
1381 | if (cfa.reg != STACK_POINTER_REGNUM) |
1382 | abort (); | |
1383 | cfa_store.reg = REGNO (dest); | |
770ca8c6 | 1384 | cfa_store.offset = cfa.offset - cfa_temp.offset; |
b53ef1a2 | 1385 | } |
19ec6a36 AM |
1386 | /* Rule 9 */ |
1387 | else if (GET_CODE (src) == LO_SUM | |
1388 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
1389 | { | |
1390 | cfa_temp.reg = REGNO (dest); | |
1391 | cfa_temp.offset = INTVAL (XEXP (src, 1)); | |
1392 | } | |
1393 | else | |
1394 | abort (); | |
556273e0 KH |
1395 | } |
1396 | break; | |
b664de3a | 1397 | |
770ca8c6 | 1398 | /* Rule 6 */ |
556273e0 | 1399 | case CONST_INT: |
770ca8c6 JO |
1400 | cfa_temp.reg = REGNO (dest); |
1401 | cfa_temp.offset = INTVAL (src); | |
556273e0 | 1402 | break; |
b664de3a | 1403 | |
770ca8c6 | 1404 | /* Rule 7 */ |
556273e0 KH |
1405 | case IOR: |
1406 | if (GET_CODE (XEXP (src, 0)) != REG | |
770ca8c6 | 1407 | || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg |
2618f955 | 1408 | || GET_CODE (XEXP (src, 1)) != CONST_INT) |
556273e0 | 1409 | abort (); |
770ca8c6 JO |
1410 | if ((unsigned) REGNO (dest) != cfa_temp.reg) |
1411 | cfa_temp.reg = REGNO (dest); | |
1412 | cfa_temp.offset |= INTVAL (XEXP (src, 1)); | |
556273e0 | 1413 | break; |
b664de3a | 1414 | |
9ae21d2a AM |
1415 | /* Skip over HIGH, assuming it will be followed by a LO_SUM, |
1416 | which will fill in all of the bits. */ | |
1417 | /* Rule 8 */ | |
1418 | case HIGH: | |
1419 | break; | |
1420 | ||
556273e0 KH |
1421 | default: |
1422 | abort (); | |
1423 | } | |
7d9d8943 | 1424 | def_cfa_1 (label, &cfa); |
2618f955 | 1425 | break; |
b664de3a | 1426 | |
2618f955 | 1427 | case MEM: |
2618f955 MM |
1428 | if (GET_CODE (src) != REG) |
1429 | abort (); | |
7d9d8943 | 1430 | |
7d9d8943 AM |
1431 | /* Saving a register to the stack. Make sure dest is relative to the |
1432 | CFA register. */ | |
2618f955 MM |
1433 | switch (GET_CODE (XEXP (dest, 0))) |
1434 | { | |
770ca8c6 | 1435 | /* Rule 10 */ |
2618f955 | 1436 | /* With a push. */ |
e2134eea JH |
1437 | case PRE_MODIFY: |
1438 | /* We can't handle variable size modifications. */ | |
1439 | if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT) | |
1440 | abort(); | |
1441 | offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1)); | |
1442 | ||
1443 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM | |
1444 | || cfa_store.reg != STACK_POINTER_REGNUM) | |
1445 | abort (); | |
1446 | cfa_store.offset += offset; | |
1447 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1448 | cfa.offset = cfa_store.offset; | |
1449 | ||
1450 | offset = -cfa_store.offset; | |
1451 | break; | |
770ca8c6 | 1452 | /* Rule 11 */ |
2618f955 MM |
1453 | case PRE_INC: |
1454 | case PRE_DEC: | |
1455 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1456 | if (GET_CODE (XEXP (dest, 0)) == PRE_INC) | |
1457 | offset = -offset; | |
b664de3a | 1458 | |
2618f955 | 1459 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM |
7d9d8943 | 1460 | || cfa_store.reg != STACK_POINTER_REGNUM) |
2618f955 | 1461 | abort (); |
7d9d8943 AM |
1462 | cfa_store.offset += offset; |
1463 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1464 | cfa.offset = cfa_store.offset; | |
b664de3a | 1465 | |
7d9d8943 | 1466 | offset = -cfa_store.offset; |
2618f955 | 1467 | break; |
b664de3a | 1468 | |
770ca8c6 | 1469 | /* Rule 12 */ |
2618f955 MM |
1470 | /* With an offset. */ |
1471 | case PLUS: | |
1472 | case MINUS: | |
19ec6a36 | 1473 | case LO_SUM: |
770ca8c6 JO |
1474 | if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT) |
1475 | abort (); | |
2618f955 MM |
1476 | offset = INTVAL (XEXP (XEXP (dest, 0), 1)); |
1477 | if (GET_CODE (XEXP (dest, 0)) == MINUS) | |
1478 | offset = -offset; | |
b664de3a | 1479 | |
19ec6a36 AM |
1480 | if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) |
1481 | offset -= cfa_store.offset; | |
1482 | else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) | |
1483 | offset -= cfa_temp.offset; | |
1484 | else | |
2618f955 | 1485 | abort (); |
2618f955 MM |
1486 | break; |
1487 | ||
770ca8c6 | 1488 | /* Rule 13 */ |
2618f955 MM |
1489 | /* Without an offset. */ |
1490 | case REG: | |
19ec6a36 AM |
1491 | if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0))) |
1492 | offset = -cfa_store.offset; | |
1493 | else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0))) | |
1494 | offset = -cfa_temp.offset; | |
1495 | else | |
556273e0 | 1496 | abort (); |
19ec6a36 AM |
1497 | break; |
1498 | ||
1499 | /* Rule 14 */ | |
1500 | case POST_INC: | |
1501 | if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) | |
1502 | abort (); | |
1503 | offset = -cfa_temp.offset; | |
1504 | cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest)); | |
2618f955 MM |
1505 | break; |
1506 | ||
1507 | default: | |
1508 | abort (); | |
1509 | } | |
e09bbb25 | 1510 | |
556273e0 | 1511 | if (REGNO (src) != STACK_POINTER_REGNUM |
e09bbb25 JM |
1512 | && REGNO (src) != HARD_FRAME_POINTER_REGNUM |
1513 | && (unsigned) REGNO (src) == cfa.reg) | |
1514 | { | |
1515 | /* We're storing the current CFA reg into the stack. */ | |
1516 | ||
1517 | if (cfa.offset == 0) | |
1518 | { | |
1519 | /* If the source register is exactly the CFA, assume | |
1520 | we're saving SP like any other register; this happens | |
1521 | on the ARM. */ | |
1522 | ||
1523 | def_cfa_1 (label, &cfa); | |
fbfa55b0 | 1524 | queue_reg_save (label, stack_pointer_rtx, offset); |
e09bbb25 JM |
1525 | break; |
1526 | } | |
1527 | else | |
1528 | { | |
1529 | /* Otherwise, we'll need to look in the stack to | |
1530 | calculate the CFA. */ | |
1531 | ||
1532 | rtx x = XEXP (dest, 0); | |
1533 | if (GET_CODE (x) != REG) | |
1534 | x = XEXP (x, 0); | |
1535 | if (GET_CODE (x) != REG) | |
1536 | abort (); | |
1537 | cfa.reg = (unsigned) REGNO (x); | |
1538 | cfa.base_offset = offset; | |
1539 | cfa.indirect = 1; | |
1540 | def_cfa_1 (label, &cfa); | |
1541 | break; | |
1542 | } | |
1543 | } | |
1544 | ||
7d9d8943 | 1545 | def_cfa_1 (label, &cfa); |
fbfa55b0 | 1546 | queue_reg_save (label, src, offset); |
2618f955 MM |
1547 | break; |
1548 | ||
1549 | default: | |
1550 | abort (); | |
1551 | } | |
b664de3a AM |
1552 | } |
1553 | ||
3f76745e JM |
1554 | /* Record call frame debugging information for INSN, which either |
1555 | sets SP or FP (adjusting how we calculate the frame address) or saves a | |
1556 | register to the stack. If INSN is NULL_RTX, initialize our state. */ | |
71dfc51f | 1557 | |
3f76745e JM |
1558 | void |
1559 | dwarf2out_frame_debug (insn) | |
1560 | rtx insn; | |
a3f97cbb | 1561 | { |
d3e3972c | 1562 | const char *label; |
b664de3a | 1563 | rtx src; |
3f76745e JM |
1564 | |
1565 | if (insn == NULL_RTX) | |
a3f97cbb | 1566 | { |
fbfa55b0 RH |
1567 | /* Flush any queued register saves. */ |
1568 | flush_queued_reg_saves (); | |
1569 | ||
3f76745e | 1570 | /* Set up state for generating call frame debug info. */ |
7d9d8943 AM |
1571 | lookup_cfa (&cfa); |
1572 | if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)) | |
3a88cbd1 | 1573 | abort (); |
7d9d8943 AM |
1574 | cfa.reg = STACK_POINTER_REGNUM; |
1575 | cfa_store = cfa; | |
770ca8c6 JO |
1576 | cfa_temp.reg = -1; |
1577 | cfa_temp.offset = 0; | |
3f76745e JM |
1578 | return; |
1579 | } | |
1580 | ||
fbfa55b0 RH |
1581 | if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn)) |
1582 | flush_queued_reg_saves (); | |
1583 | ||
0021b564 JM |
1584 | if (! RTX_FRAME_RELATED_P (insn)) |
1585 | { | |
fbfa55b0 RH |
1586 | if (!ACCUMULATE_OUTGOING_ARGS) |
1587 | dwarf2out_stack_adjust (insn); | |
0021b564 JM |
1588 | return; |
1589 | } | |
1590 | ||
3f76745e | 1591 | label = dwarf2out_cfi_label (); |
556273e0 | 1592 | |
07ebc930 RH |
1593 | src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX); |
1594 | if (src) | |
1595 | insn = XEXP (src, 0); | |
556273e0 | 1596 | else |
07ebc930 RH |
1597 | insn = PATTERN (insn); |
1598 | ||
b664de3a | 1599 | dwarf2out_frame_debug_expr (insn, label); |
3f76745e JM |
1600 | } |
1601 | ||
3f76745e JM |
1602 | /* Output a Call Frame Information opcode and its operand(s). */ |
1603 | ||
1604 | static void | |
12f0b96b | 1605 | output_cfi (cfi, fde, for_eh) |
3f76745e JM |
1606 | register dw_cfi_ref cfi; |
1607 | register dw_fde_ref fde; | |
12f0b96b | 1608 | int for_eh; |
3f76745e JM |
1609 | { |
1610 | if (cfi->dw_cfi_opc == DW_CFA_advance_loc) | |
1611 | { | |
2e4b9b8c RH |
1612 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1613 | | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)), | |
1614 | "DW_CFA_advance_loc 0x%lx", | |
1615 | cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
3f76745e | 1616 | } |
3f76745e JM |
1617 | else if (cfi->dw_cfi_opc == DW_CFA_offset) |
1618 | { | |
2e4b9b8c RH |
1619 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1620 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)), | |
1621 | "DW_CFA_offset, column 0x%lx", | |
1622 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1623 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); | |
3f76745e JM |
1624 | } |
1625 | else if (cfi->dw_cfi_opc == DW_CFA_restore) | |
1626 | { | |
2e4b9b8c RH |
1627 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1628 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)), | |
1629 | "DW_CFA_restore, column 0x%lx", | |
1630 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
3f76745e JM |
1631 | } |
1632 | else | |
1633 | { | |
2e4b9b8c RH |
1634 | dw2_asm_output_data (1, cfi->dw_cfi_opc, |
1635 | "%s", dwarf_cfi_name (cfi->dw_cfi_opc)); | |
3f76745e | 1636 | |
3f76745e JM |
1637 | switch (cfi->dw_cfi_opc) |
1638 | { | |
1639 | case DW_CFA_set_loc: | |
e1f9550a RH |
1640 | if (for_eh) |
1641 | dw2_asm_output_encoded_addr_rtx ( | |
1642 | ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0), | |
1643 | gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr), | |
1644 | NULL); | |
1645 | else | |
1646 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, | |
1647 | cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL); | |
3f76745e JM |
1648 | break; |
1649 | case DW_CFA_advance_loc1: | |
2e4b9b8c RH |
1650 | dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1651 | fde->dw_fde_current_label, NULL); | |
bb727b5a | 1652 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
3f76745e JM |
1653 | break; |
1654 | case DW_CFA_advance_loc2: | |
2e4b9b8c RH |
1655 | dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1656 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
1657 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
1658 | break; | |
1659 | case DW_CFA_advance_loc4: | |
2e4b9b8c RH |
1660 | dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1661 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
1662 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
1663 | break; | |
3f76745e | 1664 | case DW_CFA_MIPS_advance_loc8: |
2e4b9b8c RH |
1665 | dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1666 | fde->dw_fde_current_label, NULL); | |
1667 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
3f76745e | 1668 | break; |
3f76745e | 1669 | case DW_CFA_offset_extended: |
3f388b42 | 1670 | case DW_CFA_GNU_negative_offset_extended: |
3f76745e | 1671 | case DW_CFA_def_cfa: |
2e4b9b8c RH |
1672 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL); |
1673 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); | |
3f76745e JM |
1674 | break; |
1675 | case DW_CFA_restore_extended: | |
1676 | case DW_CFA_undefined: | |
3f76745e JM |
1677 | case DW_CFA_same_value: |
1678 | case DW_CFA_def_cfa_register: | |
2e4b9b8c | 1679 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL); |
3f76745e JM |
1680 | break; |
1681 | case DW_CFA_register: | |
2e4b9b8c RH |
1682 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL); |
1683 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL); | |
3f76745e JM |
1684 | break; |
1685 | case DW_CFA_def_cfa_offset: | |
2e4b9b8c RH |
1686 | case DW_CFA_GNU_args_size: |
1687 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL); | |
3f76745e | 1688 | break; |
c53aa195 JM |
1689 | case DW_CFA_GNU_window_save: |
1690 | break; | |
7d9d8943 AM |
1691 | case DW_CFA_def_cfa_expression: |
1692 | output_cfa_loc (cfi); | |
1693 | break; | |
3f76745e JM |
1694 | default: |
1695 | break; | |
1696 | } | |
556273e0 | 1697 | } |
3f76745e JM |
1698 | } |
1699 | ||
1700 | /* Output the call frame information used to used to record information | |
1701 | that relates to calculating the frame pointer, and records the | |
1702 | location of saved registers. */ | |
1703 | ||
1704 | static void | |
1705 | output_call_frame_info (for_eh) | |
1706 | int for_eh; | |
1707 | { | |
ae0ed63a | 1708 | register unsigned int i; |
3f76745e | 1709 | register dw_fde_ref fde; |
3f76745e | 1710 | register dw_cfi_ref cfi; |
a6ab3aad | 1711 | char l1[20], l2[20]; |
52a11cbf RH |
1712 | int any_lsda_needed = 0; |
1713 | char augmentation[6]; | |
e1f9550a RH |
1714 | int augmentation_size; |
1715 | int fde_encoding = DW_EH_PE_absptr; | |
1716 | int per_encoding = DW_EH_PE_absptr; | |
1717 | int lsda_encoding = DW_EH_PE_absptr; | |
3f76745e | 1718 | |
737faf14 JM |
1719 | /* If we don't have any functions we'll want to unwind out of, don't |
1720 | emit any EH unwind information. */ | |
1721 | if (for_eh) | |
1722 | { | |
52a11cbf | 1723 | int any_eh_needed = 0; |
737faf14 | 1724 | for (i = 0; i < fde_table_in_use; ++i) |
52a11cbf RH |
1725 | if (fde_table[i].uses_eh_lsda) |
1726 | any_eh_needed = any_lsda_needed = 1; | |
1727 | else if (! fde_table[i].nothrow) | |
1728 | any_eh_needed = 1; | |
1729 | ||
1730 | if (! any_eh_needed) | |
1731 | return; | |
737faf14 JM |
1732 | } |
1733 | ||
aa0c1401 JL |
1734 | /* We're going to be generating comments, so turn on app. */ |
1735 | if (flag_debug_asm) | |
1736 | app_enable (); | |
956d6950 | 1737 | |
3f76745e JM |
1738 | if (for_eh) |
1739 | { | |
7c262518 | 1740 | #ifdef EH_FRAME_SECTION_NAME |
715bdd29 | 1741 | named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE); |
3f76745e | 1742 | #else |
496651db | 1743 | tree label = get_file_function_name ('F'); |
0021b564 | 1744 | |
7c262518 | 1745 | data_section (); |
12f0b96b | 1746 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); |
0021b564 JM |
1747 | ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); |
1748 | ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); | |
3f76745e JM |
1749 | #endif |
1750 | assemble_label ("__FRAME_BEGIN__"); | |
1751 | } | |
1752 | else | |
715bdd29 | 1753 | named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG); |
3f76745e | 1754 | |
556273e0 | 1755 | /* Output the CIE. */ |
a6ab3aad JM |
1756 | ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh); |
1757 | ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh); | |
2e4b9b8c RH |
1758 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
1759 | "Length of Common Information Entry"); | |
a6ab3aad JM |
1760 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1761 | ||
2e4b9b8c RH |
1762 | /* Now that the CIE pointer is PC-relative for EH, |
1763 | use 0 to identify the CIE. */ | |
1764 | dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE), | |
1765 | (for_eh ? 0 : DW_CIE_ID), | |
1766 | "CIE Identifier Tag"); | |
3f76745e | 1767 | |
2e4b9b8c | 1768 | dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version"); |
3f76745e | 1769 | |
52a11cbf | 1770 | augmentation[0] = 0; |
e1f9550a | 1771 | augmentation_size = 0; |
52a11cbf | 1772 | if (for_eh) |
a6ab3aad | 1773 | { |
e1f9550a RH |
1774 | char *p; |
1775 | ||
52a11cbf RH |
1776 | /* Augmentation: |
1777 | z Indicates that a uleb128 is present to size the | |
1778 | augmentation section. | |
e1f9550a RH |
1779 | L Indicates the encoding (and thus presence) of |
1780 | an LSDA pointer in the FDE augmentation. | |
1781 | R Indicates a non-default pointer encoding for | |
1782 | FDE code pointers. | |
1783 | P Indicates the presence of an encoding + language | |
1784 | personality routine in the CIE augmentation. */ | |
1785 | ||
1786 | fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0); | |
1787 | per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1); | |
1788 | lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0); | |
1789 | ||
1790 | p = augmentation + 1; | |
1791 | if (eh_personality_libfunc) | |
1792 | { | |
1793 | *p++ = 'P'; | |
1794 | augmentation_size += 1 + size_of_encoded_value (per_encoding); | |
1795 | } | |
52a11cbf | 1796 | if (any_lsda_needed) |
e1f9550a RH |
1797 | { |
1798 | *p++ = 'L'; | |
1799 | augmentation_size += 1; | |
1800 | } | |
1801 | if (fde_encoding != DW_EH_PE_absptr) | |
1802 | { | |
1803 | *p++ = 'R'; | |
1804 | augmentation_size += 1; | |
1805 | } | |
1806 | if (p > augmentation + 1) | |
1807 | { | |
1808 | augmentation[0] = 'z'; | |
1809 | *p = '\0'; | |
1810 | } | |
099c8b17 RH |
1811 | |
1812 | /* Ug. Some platforms can't do unaligned dynamic relocations at all. */ | |
1813 | if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned) | |
1814 | { | |
1815 | int offset = ( 4 /* Length */ | |
1816 | + 4 /* CIE Id */ | |
1817 | + 1 /* CIE version */ | |
1818 | + strlen (augmentation) + 1 /* Augmentation */ | |
1819 | + size_of_uleb128 (1) /* Code alignment */ | |
1820 | + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT) | |
1821 | + 1 /* RA column */ | |
1822 | + 1 /* Augmentation size */ | |
1823 | + 1 /* Personality encoding */ ); | |
1824 | int pad = -offset & (PTR_SIZE - 1); | |
1825 | ||
1826 | augmentation_size += pad; | |
1827 | ||
1828 | /* Augmentations should be small, so there's scarce need to | |
1829 | iterate for a solution. Die if we exceed one uleb128 byte. */ | |
1830 | if (size_of_uleb128 (augmentation_size) != 1) | |
1831 | abort (); | |
1832 | } | |
a6ab3aad | 1833 | } |
52a11cbf | 1834 | dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation"); |
3f76745e | 1835 | |
2e4b9b8c | 1836 | dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor"); |
3f76745e | 1837 | |
2e4b9b8c RH |
1838 | dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT, |
1839 | "CIE Data Alignment Factor"); | |
3f76745e | 1840 | |
2e4b9b8c | 1841 | dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column"); |
3f76745e | 1842 | |
52a11cbf RH |
1843 | if (augmentation[0]) |
1844 | { | |
e1f9550a | 1845 | dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size"); |
52a11cbf | 1846 | if (eh_personality_libfunc) |
e1f9550a RH |
1847 | { |
1848 | dw2_asm_output_data (1, per_encoding, "Personality (%s)", | |
1849 | eh_data_format_name (per_encoding)); | |
1850 | dw2_asm_output_encoded_addr_rtx (per_encoding, | |
1851 | eh_personality_libfunc, NULL); | |
1852 | } | |
1853 | if (any_lsda_needed) | |
1854 | dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)", | |
1855 | eh_data_format_name (lsda_encoding)); | |
1856 | if (fde_encoding != DW_EH_PE_absptr) | |
1857 | dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)", | |
1858 | eh_data_format_name (fde_encoding)); | |
52a11cbf RH |
1859 | } |
1860 | ||
3f76745e | 1861 | for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next) |
12f0b96b | 1862 | output_cfi (cfi, NULL, for_eh); |
3f76745e JM |
1863 | |
1864 | /* Pad the CIE out to an address sized boundary. */ | |
12f0b96b AM |
1865 | ASM_OUTPUT_ALIGN (asm_out_file, |
1866 | floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)); | |
a6ab3aad | 1867 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e JM |
1868 | |
1869 | /* Loop through all of the FDE's. */ | |
1870 | for (i = 0; i < fde_table_in_use; ++i) | |
1871 | { | |
1872 | fde = &fde_table[i]; | |
3f76745e | 1873 | |
52a11cbf RH |
1874 | /* Don't emit EH unwind info for leaf functions that don't need it. */ |
1875 | if (for_eh && fde->nothrow && ! fde->uses_eh_lsda) | |
737faf14 JM |
1876 | continue; |
1877 | ||
2e4b9b8c | 1878 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2); |
556273e0 KH |
1879 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2); |
1880 | ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2); | |
2e4b9b8c RH |
1881 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
1882 | "FDE Length"); | |
a6ab3aad JM |
1883 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1884 | ||
eef906d6 JW |
1885 | /* ??? This always emits a 4 byte offset when for_eh is true, but it |
1886 | emits a target dependent sized offset when for_eh is not true. | |
1887 | This inconsistency may confuse gdb. The only case where we need a | |
1888 | non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI | |
1889 | compatibility if we emit a 4 byte offset. We need a 4 byte offset | |
1890 | though in order to be compatible with the dwarf_fde struct in frame.c. | |
1891 | If the for_eh case is changed, then the struct in frame.c has | |
1892 | to be adjusted appropriately. */ | |
3f76745e | 1893 | if (for_eh) |
2e4b9b8c | 1894 | dw2_asm_output_delta (4, l1, "__FRAME_BEGIN__", "FDE CIE offset"); |
3f76745e | 1895 | else |
2e4b9b8c | 1896 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, |
cf2fe500 | 1897 | stripattributes (DEBUG_FRAME_SECTION), |
2e4b9b8c | 1898 | "FDE CIE offset"); |
3f76745e | 1899 | |
e1f9550a RH |
1900 | if (for_eh) |
1901 | { | |
1902 | dw2_asm_output_encoded_addr_rtx (fde_encoding, | |
1903 | gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin), | |
1904 | "FDE initial location"); | |
1905 | dw2_asm_output_delta (size_of_encoded_value (fde_encoding), | |
1906 | fde->dw_fde_end, fde->dw_fde_begin, | |
1907 | "FDE address range"); | |
1908 | } | |
1909 | else | |
1910 | { | |
1911 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin, | |
1912 | "FDE initial location"); | |
1913 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, | |
1914 | fde->dw_fde_end, fde->dw_fde_begin, | |
1915 | "FDE address range"); | |
1916 | } | |
3f76745e | 1917 | |
52a11cbf RH |
1918 | if (augmentation[0]) |
1919 | { | |
e1f9550a | 1920 | if (any_lsda_needed) |
52a11cbf | 1921 | { |
099c8b17 RH |
1922 | int size = size_of_encoded_value (lsda_encoding); |
1923 | ||
1924 | if (lsda_encoding == DW_EH_PE_aligned) | |
1925 | { | |
1926 | int offset = ( 4 /* Length */ | |
1927 | + 4 /* CIE offset */ | |
1928 | + 2 * size_of_encoded_value (fde_encoding) | |
1929 | + 1 /* Augmentation size */ ); | |
1930 | int pad = -offset & (PTR_SIZE - 1); | |
1931 | ||
1932 | size += pad; | |
1933 | if (size_of_uleb128 (size) != 1) | |
1934 | abort (); | |
1935 | } | |
1936 | ||
1937 | dw2_asm_output_data_uleb128 (size, "Augmentation size"); | |
e1f9550a RH |
1938 | |
1939 | if (fde->uses_eh_lsda) | |
1940 | { | |
1941 | ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA", | |
1942 | fde->funcdef_number); | |
1943 | dw2_asm_output_encoded_addr_rtx ( | |
1944 | lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1), | |
1945 | "Language Specific Data Area"); | |
1946 | } | |
1947 | else | |
099c8b17 RH |
1948 | { |
1949 | if (lsda_encoding == DW_EH_PE_aligned) | |
1950 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); | |
1951 | dw2_asm_output_data (size_of_encoded_value (lsda_encoding), | |
1952 | 0, "Language Specific Data Area (none)"); | |
1953 | } | |
52a11cbf RH |
1954 | } |
1955 | else | |
e1f9550a | 1956 | dw2_asm_output_data_uleb128 (0, "Augmentation size"); |
52a11cbf RH |
1957 | } |
1958 | ||
3f76745e JM |
1959 | /* Loop through the Call Frame Instructions associated with |
1960 | this FDE. */ | |
1961 | fde->dw_fde_current_label = fde->dw_fde_begin; | |
1962 | for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next) | |
12f0b96b | 1963 | output_cfi (cfi, fde, for_eh); |
3f76745e | 1964 | |
a6ab3aad | 1965 | /* Pad the FDE out to an address sized boundary. */ |
12f0b96b | 1966 | ASM_OUTPUT_ALIGN (asm_out_file, |
e1f9550a | 1967 | floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE))); |
a6ab3aad | 1968 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e | 1969 | } |
2e4b9b8c | 1970 | |
7c262518 | 1971 | #ifndef EH_FRAME_SECTION_NAME |
3f76745e | 1972 | if (for_eh) |
2e4b9b8c | 1973 | dw2_asm_output_data (4, 0, "End of Table"); |
3f76745e | 1974 | #endif |
a6ab3aad JM |
1975 | #ifdef MIPS_DEBUGGING_INFO |
1976 | /* Work around Irix 6 assembler bug whereby labels at the end of a section | |
1977 | get a value of 0. Putting .align 0 after the label fixes it. */ | |
1978 | ASM_OUTPUT_ALIGN (asm_out_file, 0); | |
1979 | #endif | |
aa0c1401 JL |
1980 | |
1981 | /* Turn off app to make assembly quicker. */ | |
1982 | if (flag_debug_asm) | |
1983 | app_disable (); | |
a6ab3aad JM |
1984 | } |
1985 | ||
3f76745e JM |
1986 | /* Output a marker (i.e. a label) for the beginning of a function, before |
1987 | the prologue. */ | |
1988 | ||
1989 | void | |
653e276c NB |
1990 | dwarf2out_begin_prologue (line, file) |
1991 | unsigned int line ATTRIBUTE_UNUSED; | |
1992 | const char *file ATTRIBUTE_UNUSED; | |
3f76745e JM |
1993 | { |
1994 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1995 | register dw_fde_ref fde; | |
1996 | ||
2a1ee410 RH |
1997 | current_function_func_begin_label = 0; |
1998 | ||
1999 | #ifdef IA64_UNWIND_INFO | |
2000 | /* ??? current_function_func_begin_label is also used by except.c | |
2001 | for call-site information. We must emit this label if it might | |
2002 | be used. */ | |
2003 | if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS) | |
2004 | && ! dwarf2out_do_frame ()) | |
2005 | return; | |
2006 | #else | |
2007 | if (! dwarf2out_do_frame ()) | |
2008 | return; | |
2009 | #endif | |
2010 | ||
4f988ea2 JM |
2011 | ++current_funcdef_number; |
2012 | ||
3f76745e JM |
2013 | function_section (current_function_decl); |
2014 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL, | |
2015 | current_funcdef_number); | |
2a1ee410 RH |
2016 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL, |
2017 | current_funcdef_number); | |
00262c8a | 2018 | current_function_func_begin_label = get_identifier (label); |
3f76745e | 2019 | |
2a1ee410 RH |
2020 | #ifdef IA64_UNWIND_INFO |
2021 | /* We can elide the fde allocation if we're not emitting debug info. */ | |
2022 | if (! dwarf2out_do_frame ()) | |
2023 | return; | |
2024 | #endif | |
2025 | ||
3f76745e JM |
2026 | /* Expand the fde table if necessary. */ |
2027 | if (fde_table_in_use == fde_table_allocated) | |
2028 | { | |
2029 | fde_table_allocated += FDE_TABLE_INCREMENT; | |
2030 | fde_table | |
2031 | = (dw_fde_ref) xrealloc (fde_table, | |
2032 | fde_table_allocated * sizeof (dw_fde_node)); | |
a3f97cbb | 2033 | } |
3f76745e JM |
2034 | |
2035 | /* Record the FDE associated with this function. */ | |
2036 | current_funcdef_fde = fde_table_in_use; | |
2037 | ||
2038 | /* Add the new FDE at the end of the fde_table. */ | |
2039 | fde = &fde_table[fde_table_in_use++]; | |
2040 | fde->dw_fde_begin = xstrdup (label); | |
2041 | fde->dw_fde_current_label = NULL; | |
2042 | fde->dw_fde_end = NULL; | |
2043 | fde->dw_fde_cfi = NULL; | |
52a11cbf | 2044 | fde->funcdef_number = current_funcdef_number; |
fb13d4d0 | 2045 | fde->nothrow = current_function_nothrow; |
52a11cbf | 2046 | fde->uses_eh_lsda = cfun->uses_eh_lsda; |
737faf14 | 2047 | |
b57d9225 | 2048 | args_size = old_args_size = 0; |
653e276c NB |
2049 | |
2050 | /* We only want to output line number information for the genuine | |
2051 | dwarf2 prologue case, not the eh frame case. */ | |
2052 | #ifdef DWARF2_DEBUGGING_INFO | |
2053 | if (file) | |
2054 | dwarf2out_source_line (line, file); | |
2055 | #endif | |
3f76745e JM |
2056 | } |
2057 | ||
2058 | /* Output a marker (i.e. a label) for the absolute end of the generated code | |
2059 | for a function definition. This gets called *after* the epilogue code has | |
2060 | been generated. */ | |
2061 | ||
2062 | void | |
2063 | dwarf2out_end_epilogue () | |
2064 | { | |
2065 | dw_fde_ref fde; | |
2066 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2067 | ||
2068 | /* Output a label to mark the endpoint of the code generated for this | |
2069 | function. */ | |
2070 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number); | |
2071 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
2072 | fde = &fde_table[fde_table_in_use - 1]; | |
2073 | fde->dw_fde_end = xstrdup (label); | |
3f76745e JM |
2074 | } |
2075 | ||
2076 | void | |
2077 | dwarf2out_frame_init () | |
2078 | { | |
2079 | /* Allocate the initial hunk of the fde_table. */ | |
3de90026 | 2080 | fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node)); |
3f76745e JM |
2081 | fde_table_allocated = FDE_TABLE_INCREMENT; |
2082 | fde_table_in_use = 0; | |
2083 | ||
2084 | /* Generate the CFA instructions common to all FDE's. Do it now for the | |
2085 | sake of lookup_cfa. */ | |
2086 | ||
a6ab3aad | 2087 | #ifdef DWARF2_UNWIND_INFO |
91193900 AS |
2088 | /* On entry, the Canonical Frame Address is at SP. */ |
2089 | dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET); | |
2090 | initial_return_save (INCOMING_RETURN_ADDR_RTX); | |
3f76745e JM |
2091 | #endif |
2092 | } | |
2093 | ||
2094 | void | |
2095 | dwarf2out_frame_finish () | |
2096 | { | |
3f76745e | 2097 | /* Output call frame information. */ |
a6ab3aad | 2098 | #ifdef MIPS_DEBUGGING_INFO |
3f76745e JM |
2099 | if (write_symbols == DWARF2_DEBUG) |
2100 | output_call_frame_info (0); | |
ddee9e8d | 2101 | if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions)) |
3f76745e | 2102 | output_call_frame_info (1); |
a6ab3aad | 2103 | #else |
ddee9e8d RH |
2104 | int for_eh = (! USING_SJLJ_EXCEPTIONS |
2105 | && (flag_unwind_tables || flag_exceptions)); | |
2106 | if (write_symbols == DWARF2_DEBUG || for_eh) | |
2107 | output_call_frame_info (for_eh); | |
a6ab3aad | 2108 | #endif |
556273e0 | 2109 | } |
7d9d8943 AM |
2110 | \f |
2111 | /* And now, the subset of the debugging information support code necessary | |
2112 | for emitting location expressions. */ | |
3f76745e | 2113 | |
7d9d8943 AM |
2114 | typedef struct dw_val_struct *dw_val_ref; |
2115 | typedef struct die_struct *dw_die_ref; | |
2116 | typedef struct dw_loc_descr_struct *dw_loc_descr_ref; | |
63e46568 | 2117 | typedef struct dw_loc_list_struct *dw_loc_list_ref; |
3f76745e JM |
2118 | |
2119 | /* Each DIE may have a series of attribute/value pairs. Values | |
2120 | can take on several forms. The forms that are used in this | |
2121 | implementation are listed below. */ | |
2122 | ||
2123 | typedef enum | |
2124 | { | |
2125 | dw_val_class_addr, | |
a20612aa | 2126 | dw_val_class_offset, |
3f76745e | 2127 | dw_val_class_loc, |
63e46568 | 2128 | dw_val_class_loc_list, |
3f76745e JM |
2129 | dw_val_class_const, |
2130 | dw_val_class_unsigned_const, | |
2131 | dw_val_class_long_long, | |
2132 | dw_val_class_float, | |
2133 | dw_val_class_flag, | |
2134 | dw_val_class_die_ref, | |
2135 | dw_val_class_fde_ref, | |
2136 | dw_val_class_lbl_id, | |
8b790721 | 2137 | dw_val_class_lbl_offset, |
3f76745e | 2138 | dw_val_class_str |
a3f97cbb | 2139 | } |
3f76745e | 2140 | dw_val_class; |
a3f97cbb | 2141 | |
3f76745e | 2142 | /* Describe a double word constant value. */ |
21217bd0 | 2143 | /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */ |
3f76745e JM |
2144 | |
2145 | typedef struct dw_long_long_struct | |
a3f97cbb | 2146 | { |
3f76745e JM |
2147 | unsigned long hi; |
2148 | unsigned long low; | |
2149 | } | |
2150 | dw_long_long_const; | |
2151 | ||
2152 | /* Describe a floating point constant value. */ | |
2153 | ||
2154 | typedef struct dw_fp_struct | |
2155 | { | |
2156 | long *array; | |
2157 | unsigned length; | |
2158 | } | |
2159 | dw_float_const; | |
2160 | ||
956d6950 | 2161 | /* The dw_val_node describes an attribute's value, as it is |
3f76745e JM |
2162 | represented internally. */ |
2163 | ||
2164 | typedef struct dw_val_struct | |
2165 | { | |
2166 | dw_val_class val_class; | |
2167 | union | |
a3f97cbb | 2168 | { |
1865dbb5 | 2169 | rtx val_addr; |
a20612aa | 2170 | long unsigned val_offset; |
63e46568 | 2171 | dw_loc_list_ref val_loc_list; |
3f76745e JM |
2172 | dw_loc_descr_ref val_loc; |
2173 | long int val_int; | |
2174 | long unsigned val_unsigned; | |
2175 | dw_long_long_const val_long_long; | |
2176 | dw_float_const val_float; | |
881c6935 JM |
2177 | struct { |
2178 | dw_die_ref die; | |
2179 | int external; | |
2180 | } val_die_ref; | |
3f76745e JM |
2181 | unsigned val_fde_index; |
2182 | char *val_str; | |
2183 | char *val_lbl_id; | |
3f76745e | 2184 | unsigned char val_flag; |
a3f97cbb | 2185 | } |
3f76745e JM |
2186 | v; |
2187 | } | |
2188 | dw_val_node; | |
2189 | ||
2190 | /* Locations in memory are described using a sequence of stack machine | |
2191 | operations. */ | |
2192 | ||
2193 | typedef struct dw_loc_descr_struct | |
2194 | { | |
2195 | dw_loc_descr_ref dw_loc_next; | |
2196 | enum dwarf_location_atom dw_loc_opc; | |
2197 | dw_val_node dw_loc_oprnd1; | |
2198 | dw_val_node dw_loc_oprnd2; | |
d8041cc8 | 2199 | int dw_loc_addr; |
3f76745e JM |
2200 | } |
2201 | dw_loc_descr_node; | |
2202 | ||
63e46568 DB |
2203 | /* Location lists are ranges + location descriptions for that range, |
2204 | so you can track variables that are in different places over | |
30f7a378 | 2205 | their entire life. */ |
63e46568 DB |
2206 | typedef struct dw_loc_list_struct |
2207 | { | |
2208 | dw_loc_list_ref dw_loc_next; | |
2209 | const char *begin; /* Label for begin address of range */ | |
2210 | const char *end; /* Label for end address of range */ | |
2211 | char *ll_symbol; /* Label for beginning of location list. Only on head of list */ | |
2212 | const char *section; /* Section this loclist is relative to */ | |
2213 | dw_loc_descr_ref expr; | |
2214 | } dw_loc_list_node; | |
2215 | ||
7d9d8943 AM |
2216 | static const char *dwarf_stack_op_name PARAMS ((unsigned)); |
2217 | static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom, | |
2218 | unsigned long, | |
2219 | unsigned long)); | |
2220 | static void add_loc_descr PARAMS ((dw_loc_descr_ref *, | |
2221 | dw_loc_descr_ref)); | |
2222 | static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref)); | |
2223 | static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref)); | |
2224 | static void output_loc_operands PARAMS ((dw_loc_descr_ref)); | |
2225 | static void output_loc_sequence PARAMS ((dw_loc_descr_ref)); | |
3f76745e | 2226 | |
7d9d8943 | 2227 | /* Convert a DWARF stack opcode into its string name. */ |
3f76745e | 2228 | |
7d9d8943 AM |
2229 | static const char * |
2230 | dwarf_stack_op_name (op) | |
2231 | register unsigned op; | |
ef76d03b | 2232 | { |
7d9d8943 AM |
2233 | switch (op) |
2234 | { | |
2235 | case DW_OP_addr: | |
2236 | return "DW_OP_addr"; | |
2237 | case DW_OP_deref: | |
2238 | return "DW_OP_deref"; | |
2239 | case DW_OP_const1u: | |
2240 | return "DW_OP_const1u"; | |
2241 | case DW_OP_const1s: | |
2242 | return "DW_OP_const1s"; | |
2243 | case DW_OP_const2u: | |
2244 | return "DW_OP_const2u"; | |
2245 | case DW_OP_const2s: | |
2246 | return "DW_OP_const2s"; | |
2247 | case DW_OP_const4u: | |
2248 | return "DW_OP_const4u"; | |
2249 | case DW_OP_const4s: | |
2250 | return "DW_OP_const4s"; | |
2251 | case DW_OP_const8u: | |
2252 | return "DW_OP_const8u"; | |
2253 | case DW_OP_const8s: | |
2254 | return "DW_OP_const8s"; | |
2255 | case DW_OP_constu: | |
2256 | return "DW_OP_constu"; | |
2257 | case DW_OP_consts: | |
2258 | return "DW_OP_consts"; | |
2259 | case DW_OP_dup: | |
2260 | return "DW_OP_dup"; | |
2261 | case DW_OP_drop: | |
2262 | return "DW_OP_drop"; | |
2263 | case DW_OP_over: | |
2264 | return "DW_OP_over"; | |
2265 | case DW_OP_pick: | |
2266 | return "DW_OP_pick"; | |
2267 | case DW_OP_swap: | |
2268 | return "DW_OP_swap"; | |
2269 | case DW_OP_rot: | |
2270 | return "DW_OP_rot"; | |
2271 | case DW_OP_xderef: | |
2272 | return "DW_OP_xderef"; | |
2273 | case DW_OP_abs: | |
2274 | return "DW_OP_abs"; | |
2275 | case DW_OP_and: | |
2276 | return "DW_OP_and"; | |
2277 | case DW_OP_div: | |
2278 | return "DW_OP_div"; | |
2279 | case DW_OP_minus: | |
2280 | return "DW_OP_minus"; | |
2281 | case DW_OP_mod: | |
2282 | return "DW_OP_mod"; | |
2283 | case DW_OP_mul: | |
2284 | return "DW_OP_mul"; | |
2285 | case DW_OP_neg: | |
2286 | return "DW_OP_neg"; | |
2287 | case DW_OP_not: | |
2288 | return "DW_OP_not"; | |
2289 | case DW_OP_or: | |
2290 | return "DW_OP_or"; | |
2291 | case DW_OP_plus: | |
2292 | return "DW_OP_plus"; | |
2293 | case DW_OP_plus_uconst: | |
2294 | return "DW_OP_plus_uconst"; | |
2295 | case DW_OP_shl: | |
2296 | return "DW_OP_shl"; | |
2297 | case DW_OP_shr: | |
2298 | return "DW_OP_shr"; | |
2299 | case DW_OP_shra: | |
2300 | return "DW_OP_shra"; | |
2301 | case DW_OP_xor: | |
2302 | return "DW_OP_xor"; | |
2303 | case DW_OP_bra: | |
2304 | return "DW_OP_bra"; | |
2305 | case DW_OP_eq: | |
2306 | return "DW_OP_eq"; | |
2307 | case DW_OP_ge: | |
2308 | return "DW_OP_ge"; | |
2309 | case DW_OP_gt: | |
2310 | return "DW_OP_gt"; | |
2311 | case DW_OP_le: | |
2312 | return "DW_OP_le"; | |
2313 | case DW_OP_lt: | |
2314 | return "DW_OP_lt"; | |
2315 | case DW_OP_ne: | |
2316 | return "DW_OP_ne"; | |
2317 | case DW_OP_skip: | |
2318 | return "DW_OP_skip"; | |
2319 | case DW_OP_lit0: | |
2320 | return "DW_OP_lit0"; | |
2321 | case DW_OP_lit1: | |
2322 | return "DW_OP_lit1"; | |
2323 | case DW_OP_lit2: | |
2324 | return "DW_OP_lit2"; | |
2325 | case DW_OP_lit3: | |
2326 | return "DW_OP_lit3"; | |
2327 | case DW_OP_lit4: | |
2328 | return "DW_OP_lit4"; | |
2329 | case DW_OP_lit5: | |
2330 | return "DW_OP_lit5"; | |
2331 | case DW_OP_lit6: | |
2332 | return "DW_OP_lit6"; | |
2333 | case DW_OP_lit7: | |
2334 | return "DW_OP_lit7"; | |
2335 | case DW_OP_lit8: | |
2336 | return "DW_OP_lit8"; | |
2337 | case DW_OP_lit9: | |
2338 | return "DW_OP_lit9"; | |
2339 | case DW_OP_lit10: | |
2340 | return "DW_OP_lit10"; | |
2341 | case DW_OP_lit11: | |
2342 | return "DW_OP_lit11"; | |
2343 | case DW_OP_lit12: | |
2344 | return "DW_OP_lit12"; | |
2345 | case DW_OP_lit13: | |
2346 | return "DW_OP_lit13"; | |
2347 | case DW_OP_lit14: | |
2348 | return "DW_OP_lit14"; | |
2349 | case DW_OP_lit15: | |
2350 | return "DW_OP_lit15"; | |
2351 | case DW_OP_lit16: | |
2352 | return "DW_OP_lit16"; | |
2353 | case DW_OP_lit17: | |
2354 | return "DW_OP_lit17"; | |
2355 | case DW_OP_lit18: | |
2356 | return "DW_OP_lit18"; | |
2357 | case DW_OP_lit19: | |
2358 | return "DW_OP_lit19"; | |
2359 | case DW_OP_lit20: | |
2360 | return "DW_OP_lit20"; | |
2361 | case DW_OP_lit21: | |
2362 | return "DW_OP_lit21"; | |
2363 | case DW_OP_lit22: | |
2364 | return "DW_OP_lit22"; | |
2365 | case DW_OP_lit23: | |
2366 | return "DW_OP_lit23"; | |
2367 | case DW_OP_lit24: | |
2368 | return "DW_OP_lit24"; | |
2369 | case DW_OP_lit25: | |
2370 | return "DW_OP_lit25"; | |
2371 | case DW_OP_lit26: | |
2372 | return "DW_OP_lit26"; | |
2373 | case DW_OP_lit27: | |
2374 | return "DW_OP_lit27"; | |
2375 | case DW_OP_lit28: | |
2376 | return "DW_OP_lit28"; | |
2377 | case DW_OP_lit29: | |
2378 | return "DW_OP_lit29"; | |
2379 | case DW_OP_lit30: | |
2380 | return "DW_OP_lit30"; | |
2381 | case DW_OP_lit31: | |
2382 | return "DW_OP_lit31"; | |
2383 | case DW_OP_reg0: | |
2384 | return "DW_OP_reg0"; | |
2385 | case DW_OP_reg1: | |
2386 | return "DW_OP_reg1"; | |
2387 | case DW_OP_reg2: | |
2388 | return "DW_OP_reg2"; | |
2389 | case DW_OP_reg3: | |
2390 | return "DW_OP_reg3"; | |
2391 | case DW_OP_reg4: | |
2392 | return "DW_OP_reg4"; | |
2393 | case DW_OP_reg5: | |
2394 | return "DW_OP_reg5"; | |
2395 | case DW_OP_reg6: | |
2396 | return "DW_OP_reg6"; | |
2397 | case DW_OP_reg7: | |
2398 | return "DW_OP_reg7"; | |
2399 | case DW_OP_reg8: | |
2400 | return "DW_OP_reg8"; | |
2401 | case DW_OP_reg9: | |
2402 | return "DW_OP_reg9"; | |
2403 | case DW_OP_reg10: | |
2404 | return "DW_OP_reg10"; | |
2405 | case DW_OP_reg11: | |
2406 | return "DW_OP_reg11"; | |
2407 | case DW_OP_reg12: | |
2408 | return "DW_OP_reg12"; | |
2409 | case DW_OP_reg13: | |
2410 | return "DW_OP_reg13"; | |
2411 | case DW_OP_reg14: | |
2412 | return "DW_OP_reg14"; | |
2413 | case DW_OP_reg15: | |
2414 | return "DW_OP_reg15"; | |
2415 | case DW_OP_reg16: | |
2416 | return "DW_OP_reg16"; | |
2417 | case DW_OP_reg17: | |
2418 | return "DW_OP_reg17"; | |
2419 | case DW_OP_reg18: | |
2420 | return "DW_OP_reg18"; | |
2421 | case DW_OP_reg19: | |
2422 | return "DW_OP_reg19"; | |
2423 | case DW_OP_reg20: | |
2424 | return "DW_OP_reg20"; | |
2425 | case DW_OP_reg21: | |
2426 | return "DW_OP_reg21"; | |
2427 | case DW_OP_reg22: | |
2428 | return "DW_OP_reg22"; | |
2429 | case DW_OP_reg23: | |
2430 | return "DW_OP_reg23"; | |
2431 | case DW_OP_reg24: | |
2432 | return "DW_OP_reg24"; | |
2433 | case DW_OP_reg25: | |
2434 | return "DW_OP_reg25"; | |
2435 | case DW_OP_reg26: | |
2436 | return "DW_OP_reg26"; | |
2437 | case DW_OP_reg27: | |
2438 | return "DW_OP_reg27"; | |
2439 | case DW_OP_reg28: | |
2440 | return "DW_OP_reg28"; | |
2441 | case DW_OP_reg29: | |
2442 | return "DW_OP_reg29"; | |
2443 | case DW_OP_reg30: | |
2444 | return "DW_OP_reg30"; | |
2445 | case DW_OP_reg31: | |
2446 | return "DW_OP_reg31"; | |
2447 | case DW_OP_breg0: | |
2448 | return "DW_OP_breg0"; | |
2449 | case DW_OP_breg1: | |
2450 | return "DW_OP_breg1"; | |
2451 | case DW_OP_breg2: | |
2452 | return "DW_OP_breg2"; | |
2453 | case DW_OP_breg3: | |
2454 | return "DW_OP_breg3"; | |
2455 | case DW_OP_breg4: | |
2456 | return "DW_OP_breg4"; | |
2457 | case DW_OP_breg5: | |
2458 | return "DW_OP_breg5"; | |
2459 | case DW_OP_breg6: | |
2460 | return "DW_OP_breg6"; | |
2461 | case DW_OP_breg7: | |
2462 | return "DW_OP_breg7"; | |
2463 | case DW_OP_breg8: | |
2464 | return "DW_OP_breg8"; | |
2465 | case DW_OP_breg9: | |
2466 | return "DW_OP_breg9"; | |
2467 | case DW_OP_breg10: | |
2468 | return "DW_OP_breg10"; | |
2469 | case DW_OP_breg11: | |
2470 | return "DW_OP_breg11"; | |
2471 | case DW_OP_breg12: | |
2472 | return "DW_OP_breg12"; | |
2473 | case DW_OP_breg13: | |
2474 | return "DW_OP_breg13"; | |
2475 | case DW_OP_breg14: | |
2476 | return "DW_OP_breg14"; | |
2477 | case DW_OP_breg15: | |
2478 | return "DW_OP_breg15"; | |
2479 | case DW_OP_breg16: | |
2480 | return "DW_OP_breg16"; | |
2481 | case DW_OP_breg17: | |
2482 | return "DW_OP_breg17"; | |
2483 | case DW_OP_breg18: | |
2484 | return "DW_OP_breg18"; | |
2485 | case DW_OP_breg19: | |
2486 | return "DW_OP_breg19"; | |
2487 | case DW_OP_breg20: | |
2488 | return "DW_OP_breg20"; | |
2489 | case DW_OP_breg21: | |
2490 | return "DW_OP_breg21"; | |
2491 | case DW_OP_breg22: | |
2492 | return "DW_OP_breg22"; | |
2493 | case DW_OP_breg23: | |
2494 | return "DW_OP_breg23"; | |
2495 | case DW_OP_breg24: | |
2496 | return "DW_OP_breg24"; | |
2497 | case DW_OP_breg25: | |
2498 | return "DW_OP_breg25"; | |
2499 | case DW_OP_breg26: | |
2500 | return "DW_OP_breg26"; | |
2501 | case DW_OP_breg27: | |
2502 | return "DW_OP_breg27"; | |
2503 | case DW_OP_breg28: | |
2504 | return "DW_OP_breg28"; | |
2505 | case DW_OP_breg29: | |
2506 | return "DW_OP_breg29"; | |
2507 | case DW_OP_breg30: | |
2508 | return "DW_OP_breg30"; | |
2509 | case DW_OP_breg31: | |
2510 | return "DW_OP_breg31"; | |
2511 | case DW_OP_regx: | |
2512 | return "DW_OP_regx"; | |
2513 | case DW_OP_fbreg: | |
2514 | return "DW_OP_fbreg"; | |
2515 | case DW_OP_bregx: | |
2516 | return "DW_OP_bregx"; | |
2517 | case DW_OP_piece: | |
2518 | return "DW_OP_piece"; | |
2519 | case DW_OP_deref_size: | |
2520 | return "DW_OP_deref_size"; | |
2521 | case DW_OP_xderef_size: | |
2522 | return "DW_OP_xderef_size"; | |
2523 | case DW_OP_nop: | |
2524 | return "DW_OP_nop"; | |
3f76745e | 2525 | default: |
7d9d8943 | 2526 | return "OP_<unknown>"; |
3f76745e | 2527 | } |
bdb669cb | 2528 | } |
a3f97cbb | 2529 | |
7d9d8943 AM |
2530 | /* Return a pointer to a newly allocated location description. Location |
2531 | descriptions are simple expression terms that can be strung | |
2532 | together to form more complicated location (address) descriptions. */ | |
2533 | ||
2534 | static inline dw_loc_descr_ref | |
2535 | new_loc_descr (op, oprnd1, oprnd2) | |
2536 | register enum dwarf_location_atom op; | |
2537 | register unsigned long oprnd1; | |
2538 | register unsigned long oprnd2; | |
4b674448 | 2539 | { |
5de0e8d4 JM |
2540 | /* Use xcalloc here so we clear out all of the long_long constant in |
2541 | the union. */ | |
7d9d8943 | 2542 | register dw_loc_descr_ref descr |
5de0e8d4 | 2543 | = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node)); |
71dfc51f | 2544 | |
7d9d8943 AM |
2545 | descr->dw_loc_opc = op; |
2546 | descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const; | |
2547 | descr->dw_loc_oprnd1.v.val_unsigned = oprnd1; | |
2548 | descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const; | |
2549 | descr->dw_loc_oprnd2.v.val_unsigned = oprnd2; | |
71dfc51f | 2550 | |
7d9d8943 AM |
2551 | return descr; |
2552 | } | |
2553 | ||
63e46568 | 2554 | |
7d9d8943 AM |
2555 | /* Add a location description term to a location description expression. */ |
2556 | ||
2557 | static inline void | |
2558 | add_loc_descr (list_head, descr) | |
2559 | register dw_loc_descr_ref *list_head; | |
2560 | register dw_loc_descr_ref descr; | |
2561 | { | |
2562 | register dw_loc_descr_ref *d; | |
2563 | ||
2564 | /* Find the end of the chain. */ | |
2565 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
2566 | ; | |
2567 | ||
2568 | *d = descr; | |
2569 | } | |
2570 | ||
2571 | /* Return the size of a location descriptor. */ | |
2572 | ||
2573 | static unsigned long | |
2574 | size_of_loc_descr (loc) | |
2575 | register dw_loc_descr_ref loc; | |
2576 | { | |
2577 | register unsigned long size = 1; | |
2578 | ||
2579 | switch (loc->dw_loc_opc) | |
2580 | { | |
2581 | case DW_OP_addr: | |
2582 | size += DWARF2_ADDR_SIZE; | |
2583 | break; | |
2584 | case DW_OP_const1u: | |
2585 | case DW_OP_const1s: | |
2586 | size += 1; | |
2587 | break; | |
2588 | case DW_OP_const2u: | |
2589 | case DW_OP_const2s: | |
2590 | size += 2; | |
2591 | break; | |
2592 | case DW_OP_const4u: | |
2593 | case DW_OP_const4s: | |
2594 | size += 4; | |
2595 | break; | |
2596 | case DW_OP_const8u: | |
2597 | case DW_OP_const8s: | |
2598 | size += 8; | |
2599 | break; | |
2600 | case DW_OP_constu: | |
2601 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2602 | break; | |
2603 | case DW_OP_consts: | |
2604 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2605 | break; | |
2606 | case DW_OP_pick: | |
2607 | size += 1; | |
2608 | break; | |
2609 | case DW_OP_plus_uconst: | |
2610 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2611 | break; | |
2612 | case DW_OP_skip: | |
2613 | case DW_OP_bra: | |
2614 | size += 2; | |
2615 | break; | |
2616 | case DW_OP_breg0: | |
2617 | case DW_OP_breg1: | |
2618 | case DW_OP_breg2: | |
2619 | case DW_OP_breg3: | |
2620 | case DW_OP_breg4: | |
2621 | case DW_OP_breg5: | |
2622 | case DW_OP_breg6: | |
2623 | case DW_OP_breg7: | |
2624 | case DW_OP_breg8: | |
2625 | case DW_OP_breg9: | |
2626 | case DW_OP_breg10: | |
2627 | case DW_OP_breg11: | |
2628 | case DW_OP_breg12: | |
2629 | case DW_OP_breg13: | |
2630 | case DW_OP_breg14: | |
2631 | case DW_OP_breg15: | |
2632 | case DW_OP_breg16: | |
2633 | case DW_OP_breg17: | |
2634 | case DW_OP_breg18: | |
2635 | case DW_OP_breg19: | |
2636 | case DW_OP_breg20: | |
2637 | case DW_OP_breg21: | |
2638 | case DW_OP_breg22: | |
2639 | case DW_OP_breg23: | |
2640 | case DW_OP_breg24: | |
2641 | case DW_OP_breg25: | |
2642 | case DW_OP_breg26: | |
2643 | case DW_OP_breg27: | |
2644 | case DW_OP_breg28: | |
2645 | case DW_OP_breg29: | |
2646 | case DW_OP_breg30: | |
2647 | case DW_OP_breg31: | |
2648 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2649 | break; | |
2650 | case DW_OP_regx: | |
2651 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2652 | break; | |
2653 | case DW_OP_fbreg: | |
2654 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2655 | break; | |
2656 | case DW_OP_bregx: | |
2657 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2658 | size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int); | |
2659 | break; | |
2660 | case DW_OP_piece: | |
2661 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2662 | break; | |
2663 | case DW_OP_deref_size: | |
2664 | case DW_OP_xderef_size: | |
2665 | size += 1; | |
2666 | break; | |
3f76745e | 2667 | default: |
7d9d8943 | 2668 | break; |
4b674448 | 2669 | } |
7d9d8943 AM |
2670 | |
2671 | return size; | |
4b674448 JM |
2672 | } |
2673 | ||
7d9d8943 | 2674 | /* Return the size of a series of location descriptors. */ |
71dfc51f | 2675 | |
7d9d8943 AM |
2676 | static unsigned long |
2677 | size_of_locs (loc) | |
2678 | register dw_loc_descr_ref loc; | |
4b674448 | 2679 | { |
7d9d8943 AM |
2680 | register unsigned long size = 0; |
2681 | ||
2682 | for (; loc != NULL; loc = loc->dw_loc_next) | |
d8041cc8 RH |
2683 | { |
2684 | loc->dw_loc_addr = size; | |
2685 | size += size_of_loc_descr (loc); | |
2686 | } | |
7d9d8943 AM |
2687 | |
2688 | return size; | |
4b674448 JM |
2689 | } |
2690 | ||
7d9d8943 | 2691 | /* Output location description stack opcode's operands (if any). */ |
71dfc51f | 2692 | |
7d9d8943 AM |
2693 | static void |
2694 | output_loc_operands (loc) | |
2695 | register dw_loc_descr_ref loc; | |
a3f97cbb | 2696 | { |
7d9d8943 AM |
2697 | register dw_val_ref val1 = &loc->dw_loc_oprnd1; |
2698 | register dw_val_ref val2 = &loc->dw_loc_oprnd2; | |
2699 | ||
2700 | switch (loc->dw_loc_opc) | |
a3f97cbb | 2701 | { |
0517872a | 2702 | #ifdef DWARF2_DEBUGGING_INFO |
3f76745e | 2703 | case DW_OP_addr: |
2e4b9b8c | 2704 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL); |
7d9d8943 | 2705 | break; |
3f76745e | 2706 | case DW_OP_const2u: |
3f76745e | 2707 | case DW_OP_const2s: |
2e4b9b8c | 2708 | dw2_asm_output_data (2, val1->v.val_int, NULL); |
7d9d8943 | 2709 | break; |
3f76745e | 2710 | case DW_OP_const4u: |
3f76745e | 2711 | case DW_OP_const4s: |
2e4b9b8c | 2712 | dw2_asm_output_data (4, val1->v.val_int, NULL); |
7d9d8943 | 2713 | break; |
3f76745e | 2714 | case DW_OP_const8u: |
3f76745e | 2715 | case DW_OP_const8s: |
2e4b9b8c RH |
2716 | if (HOST_BITS_PER_LONG < 64) |
2717 | abort (); | |
2718 | dw2_asm_output_data (8, val1->v.val_int, NULL); | |
7d9d8943 | 2719 | break; |
0517872a JM |
2720 | case DW_OP_skip: |
2721 | case DW_OP_bra: | |
d8041cc8 RH |
2722 | { |
2723 | int offset; | |
2724 | ||
2725 | if (val1->val_class == dw_val_class_loc) | |
2726 | offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3); | |
2727 | else | |
2728 | abort (); | |
2729 | ||
2e4b9b8c | 2730 | dw2_asm_output_data (2, offset, NULL); |
d8041cc8 | 2731 | } |
0517872a | 2732 | break; |
3139472f JM |
2733 | #else |
2734 | case DW_OP_addr: | |
2735 | case DW_OP_const2u: | |
2736 | case DW_OP_const2s: | |
2737 | case DW_OP_const4u: | |
2738 | case DW_OP_const4s: | |
2739 | case DW_OP_const8u: | |
2740 | case DW_OP_const8s: | |
2741 | case DW_OP_skip: | |
2742 | case DW_OP_bra: | |
2743 | /* We currently don't make any attempt to make sure these are | |
2744 | aligned properly like we do for the main unwind info, so | |
2745 | don't support emitting things larger than a byte if we're | |
2746 | only doing unwinding. */ | |
2747 | abort (); | |
0517872a JM |
2748 | #endif |
2749 | case DW_OP_const1u: | |
2750 | case DW_OP_const1s: | |
2e4b9b8c | 2751 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
0517872a | 2752 | break; |
3f76745e | 2753 | case DW_OP_constu: |
2e4b9b8c | 2754 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2755 | break; |
3f76745e | 2756 | case DW_OP_consts: |
2e4b9b8c | 2757 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 AM |
2758 | break; |
2759 | case DW_OP_pick: | |
2e4b9b8c | 2760 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 AM |
2761 | break; |
2762 | case DW_OP_plus_uconst: | |
2e4b9b8c | 2763 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2764 | break; |
3f76745e | 2765 | case DW_OP_breg0: |
3f76745e | 2766 | case DW_OP_breg1: |
3f76745e | 2767 | case DW_OP_breg2: |
3f76745e | 2768 | case DW_OP_breg3: |
3f76745e | 2769 | case DW_OP_breg4: |
3f76745e | 2770 | case DW_OP_breg5: |
3f76745e | 2771 | case DW_OP_breg6: |
3f76745e | 2772 | case DW_OP_breg7: |
3f76745e | 2773 | case DW_OP_breg8: |
3f76745e | 2774 | case DW_OP_breg9: |
3f76745e | 2775 | case DW_OP_breg10: |
3f76745e | 2776 | case DW_OP_breg11: |
3f76745e | 2777 | case DW_OP_breg12: |
3f76745e | 2778 | case DW_OP_breg13: |
3f76745e | 2779 | case DW_OP_breg14: |
3f76745e | 2780 | case DW_OP_breg15: |
3f76745e | 2781 | case DW_OP_breg16: |
3f76745e | 2782 | case DW_OP_breg17: |
3f76745e | 2783 | case DW_OP_breg18: |
3f76745e | 2784 | case DW_OP_breg19: |
3f76745e | 2785 | case DW_OP_breg20: |
3f76745e | 2786 | case DW_OP_breg21: |
3f76745e | 2787 | case DW_OP_breg22: |
3f76745e | 2788 | case DW_OP_breg23: |
3f76745e | 2789 | case DW_OP_breg24: |
3f76745e | 2790 | case DW_OP_breg25: |
3f76745e | 2791 | case DW_OP_breg26: |
3f76745e | 2792 | case DW_OP_breg27: |
3f76745e | 2793 | case DW_OP_breg28: |
3f76745e | 2794 | case DW_OP_breg29: |
3f76745e | 2795 | case DW_OP_breg30: |
3f76745e | 2796 | case DW_OP_breg31: |
2e4b9b8c | 2797 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 2798 | break; |
3f76745e | 2799 | case DW_OP_regx: |
2e4b9b8c | 2800 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2801 | break; |
3f76745e | 2802 | case DW_OP_fbreg: |
2e4b9b8c | 2803 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 2804 | break; |
3f76745e | 2805 | case DW_OP_bregx: |
2e4b9b8c RH |
2806 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
2807 | dw2_asm_output_data_sleb128 (val2->v.val_int, NULL); | |
7d9d8943 | 2808 | break; |
3f76745e | 2809 | case DW_OP_piece: |
2e4b9b8c | 2810 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2811 | break; |
3f76745e | 2812 | case DW_OP_deref_size: |
3f76745e | 2813 | case DW_OP_xderef_size: |
2e4b9b8c | 2814 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 AM |
2815 | break; |
2816 | default: | |
3139472f JM |
2817 | /* Other codes have no operands. */ |
2818 | break; | |
7d9d8943 AM |
2819 | } |
2820 | } | |
2821 | ||
2822 | /* Output a sequence of location operations. */ | |
2823 | ||
2824 | static void | |
2825 | output_loc_sequence (loc) | |
2826 | dw_loc_descr_ref loc; | |
2827 | { | |
2828 | for (; loc != NULL; loc = loc->dw_loc_next) | |
2829 | { | |
2830 | /* Output the opcode. */ | |
2e4b9b8c RH |
2831 | dw2_asm_output_data (1, loc->dw_loc_opc, |
2832 | "%s", dwarf_stack_op_name (loc->dw_loc_opc)); | |
7d9d8943 AM |
2833 | |
2834 | /* Output the operand(s) (if any). */ | |
2835 | output_loc_operands (loc); | |
2836 | } | |
2837 | } | |
2838 | ||
2839 | /* This routine will generate the correct assembly data for a location | |
2840 | description based on a cfi entry with a complex address. */ | |
2841 | ||
2842 | static void | |
2843 | output_cfa_loc (cfi) | |
2844 | dw_cfi_ref cfi; | |
2845 | { | |
2846 | dw_loc_descr_ref loc; | |
2847 | unsigned long size; | |
2848 | ||
2849 | /* Output the size of the block. */ | |
2850 | loc = cfi->dw_cfi_oprnd1.dw_cfi_loc; | |
2851 | size = size_of_locs (loc); | |
2e4b9b8c | 2852 | dw2_asm_output_data_uleb128 (size, NULL); |
7d9d8943 AM |
2853 | |
2854 | /* Now output the operations themselves. */ | |
2855 | output_loc_sequence (loc); | |
2856 | } | |
2857 | ||
dd49a9ec | 2858 | /* This function builds a dwarf location descriptor sequence from |
556273e0 | 2859 | a dw_cfa_location. */ |
7d9d8943 AM |
2860 | |
2861 | static struct dw_loc_descr_struct * | |
2862 | build_cfa_loc (cfa) | |
2863 | dw_cfa_location *cfa; | |
2864 | { | |
2865 | struct dw_loc_descr_struct *head, *tmp; | |
2866 | ||
2867 | if (cfa->indirect == 0) | |
2868 | abort (); | |
2869 | ||
2870 | if (cfa->base_offset) | |
f299afab HPN |
2871 | { |
2872 | if (cfa->reg <= 31) | |
2873 | head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0); | |
2874 | else | |
2875 | head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset); | |
2876 | } | |
2877 | else if (cfa->reg <= 31) | |
7d9d8943 | 2878 | head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0); |
f299afab HPN |
2879 | else |
2880 | head = new_loc_descr (DW_OP_regx, cfa->reg, 0); | |
7d9d8943 AM |
2881 | head->dw_loc_oprnd1.val_class = dw_val_class_const; |
2882 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
2883 | add_loc_descr (&head, tmp); | |
2884 | if (cfa->offset != 0) | |
2885 | { | |
2886 | tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0); | |
2887 | add_loc_descr (&head, tmp); | |
2888 | } | |
2889 | return head; | |
2890 | } | |
2891 | ||
556273e0 | 2892 | /* This function fills in aa dw_cfa_location structure from a |
7d9d8943 AM |
2893 | dwarf location descriptor sequence. */ |
2894 | ||
2895 | static void | |
2896 | get_cfa_from_loc_descr (cfa, loc) | |
2897 | dw_cfa_location *cfa; | |
556273e0 | 2898 | struct dw_loc_descr_struct *loc; |
7d9d8943 | 2899 | { |
556273e0 | 2900 | struct dw_loc_descr_struct *ptr; |
7d9d8943 AM |
2901 | cfa->offset = 0; |
2902 | cfa->base_offset = 0; | |
2903 | cfa->indirect = 0; | |
2904 | cfa->reg = -1; | |
2905 | ||
2906 | for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next) | |
2907 | { | |
2908 | enum dwarf_location_atom op = ptr->dw_loc_opc; | |
2909 | switch (op) | |
556273e0 | 2910 | { |
7d9d8943 AM |
2911 | case DW_OP_reg0: |
2912 | case DW_OP_reg1: | |
2913 | case DW_OP_reg2: | |
2914 | case DW_OP_reg3: | |
2915 | case DW_OP_reg4: | |
2916 | case DW_OP_reg5: | |
2917 | case DW_OP_reg6: | |
2918 | case DW_OP_reg7: | |
2919 | case DW_OP_reg8: | |
2920 | case DW_OP_reg9: | |
2921 | case DW_OP_reg10: | |
2922 | case DW_OP_reg11: | |
2923 | case DW_OP_reg12: | |
2924 | case DW_OP_reg13: | |
2925 | case DW_OP_reg14: | |
2926 | case DW_OP_reg15: | |
2927 | case DW_OP_reg16: | |
2928 | case DW_OP_reg17: | |
2929 | case DW_OP_reg18: | |
2930 | case DW_OP_reg19: | |
2931 | case DW_OP_reg20: | |
2932 | case DW_OP_reg21: | |
2933 | case DW_OP_reg22: | |
2934 | case DW_OP_reg23: | |
2935 | case DW_OP_reg24: | |
2936 | case DW_OP_reg25: | |
2937 | case DW_OP_reg26: | |
2938 | case DW_OP_reg27: | |
2939 | case DW_OP_reg28: | |
2940 | case DW_OP_reg29: | |
2941 | case DW_OP_reg30: | |
2942 | case DW_OP_reg31: | |
2943 | cfa->reg = op - DW_OP_reg0; | |
2944 | break; | |
2945 | case DW_OP_regx: | |
2946 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
2947 | break; | |
2948 | case DW_OP_breg0: | |
2949 | case DW_OP_breg1: | |
2950 | case DW_OP_breg2: | |
2951 | case DW_OP_breg3: | |
2952 | case DW_OP_breg4: | |
2953 | case DW_OP_breg5: | |
2954 | case DW_OP_breg6: | |
2955 | case DW_OP_breg7: | |
2956 | case DW_OP_breg8: | |
2957 | case DW_OP_breg9: | |
2958 | case DW_OP_breg10: | |
2959 | case DW_OP_breg11: | |
2960 | case DW_OP_breg12: | |
2961 | case DW_OP_breg13: | |
2962 | case DW_OP_breg14: | |
2963 | case DW_OP_breg15: | |
2964 | case DW_OP_breg16: | |
2965 | case DW_OP_breg17: | |
2966 | case DW_OP_breg18: | |
2967 | case DW_OP_breg19: | |
2968 | case DW_OP_breg20: | |
2969 | case DW_OP_breg21: | |
2970 | case DW_OP_breg22: | |
2971 | case DW_OP_breg23: | |
2972 | case DW_OP_breg24: | |
2973 | case DW_OP_breg25: | |
2974 | case DW_OP_breg26: | |
2975 | case DW_OP_breg27: | |
2976 | case DW_OP_breg28: | |
2977 | case DW_OP_breg29: | |
2978 | case DW_OP_breg30: | |
2979 | case DW_OP_breg31: | |
2980 | cfa->reg = op - DW_OP_breg0; | |
2981 | cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int; | |
2982 | break; | |
2983 | case DW_OP_bregx: | |
2984 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
2985 | cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int; | |
2986 | break; | |
2987 | case DW_OP_deref: | |
2988 | cfa->indirect = 1; | |
2989 | break; | |
2990 | case DW_OP_plus_uconst: | |
556273e0 | 2991 | cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned; |
7d9d8943 AM |
2992 | break; |
2993 | default: | |
400500c4 RK |
2994 | internal_error ("DW_LOC_OP %s not implememnted\n", |
2995 | dwarf_stack_op_name (ptr->dw_loc_opc)); | |
7d9d8943 AM |
2996 | } |
2997 | } | |
2998 | } | |
2999 | #endif /* .debug_frame support */ | |
3000 | \f | |
3001 | /* And now, the support for symbolic debugging information. */ | |
3002 | #ifdef DWARF2_DEBUGGING_INFO | |
3003 | ||
e2a12aca NB |
3004 | static void dwarf2out_init PARAMS ((const char *)); |
3005 | static void dwarf2out_finish PARAMS ((const char *)); | |
7f905405 NB |
3006 | static void dwarf2out_define PARAMS ((unsigned int, const char *)); |
3007 | static void dwarf2out_undef PARAMS ((unsigned int, const char *)); | |
3008 | static void dwarf2out_start_source_file PARAMS ((unsigned, const char *)); | |
3009 | static void dwarf2out_end_source_file PARAMS ((unsigned)); | |
e2a12aca NB |
3010 | static void dwarf2out_begin_block PARAMS ((unsigned, unsigned)); |
3011 | static void dwarf2out_end_block PARAMS ((unsigned, unsigned)); | |
e1772ac0 | 3012 | static bool dwarf2out_ignore_block PARAMS ((tree)); |
2b85879e | 3013 | static void dwarf2out_global_decl PARAMS ((tree)); |
e1772ac0 | 3014 | static void dwarf2out_abstract_function PARAMS ((tree)); |
7f905405 NB |
3015 | |
3016 | /* The debug hooks structure. */ | |
3017 | ||
3018 | struct gcc_debug_hooks dwarf2_debug_hooks = | |
3019 | { | |
3020 | dwarf2out_init, | |
3021 | dwarf2out_finish, | |
3022 | dwarf2out_define, | |
3023 | dwarf2out_undef, | |
3024 | dwarf2out_start_source_file, | |
a5a42b92 NB |
3025 | dwarf2out_end_source_file, |
3026 | dwarf2out_begin_block, | |
e2a12aca | 3027 | dwarf2out_end_block, |
e1772ac0 | 3028 | dwarf2out_ignore_block, |
e2a12aca | 3029 | dwarf2out_source_line, |
653e276c NB |
3030 | dwarf2out_begin_prologue, |
3031 | debug_nothing_int, /* end_prologue */ | |
e2a12aca | 3032 | dwarf2out_end_epilogue, |
653e276c | 3033 | debug_nothing_tree, /* begin_function */ |
2b85879e NB |
3034 | debug_nothing_int, /* end_function */ |
3035 | dwarf2out_decl, /* function_decl */ | |
3036 | dwarf2out_global_decl, | |
e1772ac0 NB |
3037 | debug_nothing_tree, /* deferred_inline_function */ |
3038 | /* The DWARF 2 backend tries to reduce debugging bloat by not | |
3039 | emitting the abstract description of inline functions until | |
3040 | something tries to reference them. */ | |
3041 | dwarf2out_abstract_function, /* outlining_inline_function */ | |
3042 | debug_nothing_rtx /* label */ | |
7f905405 NB |
3043 | }; |
3044 | \f | |
7d9d8943 AM |
3045 | /* NOTE: In the comments in this file, many references are made to |
3046 | "Debugging Information Entries". This term is abbreviated as `DIE' | |
3047 | throughout the remainder of this file. */ | |
3048 | ||
3049 | /* An internal representation of the DWARF output is built, and then | |
3050 | walked to generate the DWARF debugging info. The walk of the internal | |
3051 | representation is done after the entire program has been compiled. | |
3052 | The types below are used to describe the internal representation. */ | |
3053 | ||
3054 | /* Various DIE's use offsets relative to the beginning of the | |
3055 | .debug_info section to refer to each other. */ | |
3056 | ||
3057 | typedef long int dw_offset; | |
3058 | ||
3059 | /* Define typedefs here to avoid circular dependencies. */ | |
3060 | ||
3061 | typedef struct dw_attr_struct *dw_attr_ref; | |
3062 | typedef struct dw_line_info_struct *dw_line_info_ref; | |
3063 | typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref; | |
3064 | typedef struct pubname_struct *pubname_ref; | |
a20612aa | 3065 | typedef struct dw_ranges_struct *dw_ranges_ref; |
7d9d8943 AM |
3066 | |
3067 | /* Each entry in the line_info_table maintains the file and | |
3068 | line number associated with the label generated for that | |
3069 | entry. The label gives the PC value associated with | |
3070 | the line number entry. */ | |
3071 | ||
3072 | typedef struct dw_line_info_struct | |
3073 | { | |
3074 | unsigned long dw_file_num; | |
3075 | unsigned long dw_line_num; | |
3076 | } | |
3077 | dw_line_info_entry; | |
3078 | ||
3079 | /* Line information for functions in separate sections; each one gets its | |
3080 | own sequence. */ | |
3081 | typedef struct dw_separate_line_info_struct | |
3082 | { | |
3083 | unsigned long dw_file_num; | |
3084 | unsigned long dw_line_num; | |
3085 | unsigned long function; | |
3086 | } | |
3087 | dw_separate_line_info_entry; | |
3088 | ||
3089 | /* Each DIE attribute has a field specifying the attribute kind, | |
3090 | a link to the next attribute in the chain, and an attribute value. | |
3091 | Attributes are typically linked below the DIE they modify. */ | |
3092 | ||
3093 | typedef struct dw_attr_struct | |
3094 | { | |
3095 | enum dwarf_attribute dw_attr; | |
3096 | dw_attr_ref dw_attr_next; | |
3097 | dw_val_node dw_attr_val; | |
3098 | } | |
3099 | dw_attr_node; | |
3100 | ||
3101 | /* The Debugging Information Entry (DIE) structure */ | |
3102 | ||
3103 | typedef struct die_struct | |
3104 | { | |
3105 | enum dwarf_tag die_tag; | |
881c6935 | 3106 | char *die_symbol; |
7d9d8943 AM |
3107 | dw_attr_ref die_attr; |
3108 | dw_die_ref die_parent; | |
3109 | dw_die_ref die_child; | |
3110 | dw_die_ref die_sib; | |
3111 | dw_offset die_offset; | |
3112 | unsigned long die_abbrev; | |
1bfb5f8f | 3113 | int die_mark; |
7d9d8943 AM |
3114 | } |
3115 | die_node; | |
3116 | ||
3117 | /* The pubname structure */ | |
3118 | ||
3119 | typedef struct pubname_struct | |
3120 | { | |
3121 | dw_die_ref die; | |
556273e0 | 3122 | char *name; |
7d9d8943 AM |
3123 | } |
3124 | pubname_entry; | |
3125 | ||
a20612aa RH |
3126 | struct dw_ranges_struct |
3127 | { | |
3128 | int block_num; | |
3129 | }; | |
3130 | ||
7d9d8943 AM |
3131 | /* The limbo die list structure. */ |
3132 | typedef struct limbo_die_struct | |
3133 | { | |
3134 | dw_die_ref die; | |
3135 | struct limbo_die_struct *next; | |
3136 | } | |
3137 | limbo_die_node; | |
3138 | ||
3139 | /* How to start an assembler comment. */ | |
3140 | #ifndef ASM_COMMENT_START | |
3141 | #define ASM_COMMENT_START ";#" | |
3142 | #endif | |
3143 | ||
3144 | /* Define a macro which returns non-zero for a TYPE_DECL which was | |
3145 | implicitly generated for a tagged type. | |
3146 | ||
3147 | Note that unlike the gcc front end (which generates a NULL named | |
3148 | TYPE_DECL node for each complete tagged type, each array type, and | |
3149 | each function type node created) the g++ front end generates a | |
3150 | _named_ TYPE_DECL node for each tagged type node created. | |
3151 | These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to | |
3152 | generate a DW_TAG_typedef DIE for them. */ | |
3153 | ||
3154 | #define TYPE_DECL_IS_STUB(decl) \ | |
3155 | (DECL_NAME (decl) == NULL_TREE \ | |
3156 | || (DECL_ARTIFICIAL (decl) \ | |
3157 | && is_tagged_type (TREE_TYPE (decl)) \ | |
3158 | && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \ | |
3159 | /* This is necessary for stub decls that \ | |
3160 | appear in nested inline functions. */ \ | |
3161 | || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \ | |
3162 | && (decl_ultimate_origin (decl) \ | |
3163 | == TYPE_STUB_DECL (TREE_TYPE (decl))))))) | |
3164 | ||
3165 | /* Information concerning the compilation unit's programming | |
3166 | language, and compiler version. */ | |
3167 | ||
3168 | extern int flag_traditional; | |
3169 | ||
3170 | /* Fixed size portion of the DWARF compilation unit header. */ | |
3171 | #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3) | |
3172 | ||
3173 | /* Fixed size portion of debugging line information prolog. */ | |
3174 | #define DWARF_LINE_PROLOG_HEADER_SIZE 5 | |
3175 | ||
3176 | /* Fixed size portion of public names info. */ | |
3177 | #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2) | |
3178 | ||
3179 | /* Fixed size portion of the address range info. */ | |
3180 | #define DWARF_ARANGES_HEADER_SIZE \ | |
3181 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ | |
3182 | - DWARF_OFFSET_SIZE) | |
3183 | ||
3184 | /* Size of padding portion in the address range info. It must be | |
3185 | aligned to twice the pointer size. */ | |
3186 | #define DWARF_ARANGES_PAD_SIZE \ | |
3187 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ | |
3188 | - (2 * DWARF_OFFSET_SIZE + 4)) | |
3189 | ||
9d147085 | 3190 | /* Use assembler line directives if available. */ |
7d9d8943 | 3191 | #ifndef DWARF2_ASM_LINE_DEBUG_INFO |
9d147085 RH |
3192 | #ifdef HAVE_AS_DWARF2_DEBUG_LINE |
3193 | #define DWARF2_ASM_LINE_DEBUG_INFO 1 | |
3194 | #else | |
7d9d8943 AM |
3195 | #define DWARF2_ASM_LINE_DEBUG_INFO 0 |
3196 | #endif | |
9d147085 | 3197 | #endif |
7d9d8943 AM |
3198 | |
3199 | /* Define the architecture-dependent minimum instruction length (in bytes). | |
3200 | In this implementation of DWARF, this field is used for information | |
3201 | purposes only. Since GCC generates assembly language, we have | |
3202 | no a priori knowledge of how many instruction bytes are generated | |
3203 | for each source line, and therefore can use only the DW_LNE_set_address | |
3204 | and DW_LNS_fixed_advance_pc line information commands. */ | |
3205 | ||
3206 | #ifndef DWARF_LINE_MIN_INSTR_LENGTH | |
3207 | #define DWARF_LINE_MIN_INSTR_LENGTH 4 | |
3208 | #endif | |
3209 | ||
3210 | /* Minimum line offset in a special line info. opcode. | |
3211 | This value was chosen to give a reasonable range of values. */ | |
3212 | #define DWARF_LINE_BASE -10 | |
3213 | ||
3214 | /* First special line opcde - leave room for the standard opcodes. */ | |
3215 | #define DWARF_LINE_OPCODE_BASE 10 | |
3216 | ||
3217 | /* Range of line offsets in a special line info. opcode. */ | |
3218 | #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1) | |
3219 | ||
3220 | /* Flag that indicates the initial value of the is_stmt_start flag. | |
3221 | In the present implementation, we do not mark any lines as | |
3222 | the beginning of a source statement, because that information | |
3223 | is not made available by the GCC front-end. */ | |
3224 | #define DWARF_LINE_DEFAULT_IS_STMT_START 1 | |
3225 | ||
3226 | /* This location is used by calc_die_sizes() to keep track | |
3227 | the offset of each DIE within the .debug_info section. */ | |
3228 | static unsigned long next_die_offset; | |
3229 | ||
3230 | /* Record the root of the DIE's built for the current compilation unit. */ | |
3231 | static dw_die_ref comp_unit_die; | |
3232 | ||
3233 | /* A list of DIEs with a NULL parent waiting to be relocated. */ | |
3234 | static limbo_die_node *limbo_die_list = 0; | |
3235 | ||
2e18bbae RH |
3236 | /* Structure used by lookup_filename to manage sets of filenames. */ |
3237 | struct file_table | |
3238 | { | |
3239 | char **table; | |
3240 | unsigned allocated; | |
3241 | unsigned in_use; | |
3242 | unsigned last_lookup_index; | |
3243 | }; | |
7d9d8943 AM |
3244 | |
3245 | /* Size (in elements) of increments by which we may expand the filename | |
3246 | table. */ | |
3247 | #define FILE_TABLE_INCREMENT 64 | |
3248 | ||
981975b6 RH |
3249 | /* Filenames referenced by this compilation unit. */ |
3250 | static struct file_table file_table; | |
2e18bbae | 3251 | |
7d9d8943 AM |
3252 | /* Local pointer to the name of the main input file. Initialized in |
3253 | dwarf2out_init. */ | |
3254 | static const char *primary_filename; | |
3255 | ||
3256 | /* A pointer to the base of a table of references to DIE's that describe | |
3257 | declarations. The table is indexed by DECL_UID() which is a unique | |
3258 | number identifying each decl. */ | |
3259 | static dw_die_ref *decl_die_table; | |
3260 | ||
3261 | /* Number of elements currently allocated for the decl_die_table. */ | |
3262 | static unsigned decl_die_table_allocated; | |
3263 | ||
3264 | /* Number of elements in decl_die_table currently in use. */ | |
3265 | static unsigned decl_die_table_in_use; | |
3266 | ||
3267 | /* Size (in elements) of increments by which we may expand the | |
3268 | decl_die_table. */ | |
3269 | #define DECL_DIE_TABLE_INCREMENT 256 | |
3270 | ||
3271 | /* A pointer to the base of a table of references to declaration | |
3272 | scopes. This table is a display which tracks the nesting | |
3273 | of declaration scopes at the current scope and containing | |
3274 | scopes. This table is used to find the proper place to | |
3275 | define type declaration DIE's. */ | |
3276 | static tree *decl_scope_table; | |
3277 | ||
3278 | /* Number of elements currently allocated for the decl_scope_table. */ | |
3279 | static int decl_scope_table_allocated; | |
3280 | ||
3281 | /* Current level of nesting of declaration scopes. */ | |
3282 | static int decl_scope_depth; | |
3283 | ||
3284 | /* Size (in elements) of increments by which we may expand the | |
3285 | decl_scope_table. */ | |
3286 | #define DECL_SCOPE_TABLE_INCREMENT 64 | |
3287 | ||
3288 | /* A pointer to the base of a list of references to DIE's that | |
3289 | are uniquely identified by their tag, presence/absence of | |
3290 | children DIE's, and list of attribute/value pairs. */ | |
3291 | static dw_die_ref *abbrev_die_table; | |
3292 | ||
3293 | /* Number of elements currently allocated for abbrev_die_table. */ | |
3294 | static unsigned abbrev_die_table_allocated; | |
3295 | ||
3296 | /* Number of elements in type_die_table currently in use. */ | |
3297 | static unsigned abbrev_die_table_in_use; | |
3298 | ||
3299 | /* Size (in elements) of increments by which we may expand the | |
3300 | abbrev_die_table. */ | |
3301 | #define ABBREV_DIE_TABLE_INCREMENT 256 | |
3302 | ||
3303 | /* A pointer to the base of a table that contains line information | |
3304 | for each source code line in .text in the compilation unit. */ | |
3305 | static dw_line_info_ref line_info_table; | |
3306 | ||
3307 | /* Number of elements currently allocated for line_info_table. */ | |
3308 | static unsigned line_info_table_allocated; | |
3309 | ||
3310 | /* Number of elements in separate_line_info_table currently in use. */ | |
3311 | static unsigned separate_line_info_table_in_use; | |
3312 | ||
3313 | /* A pointer to the base of a table that contains line information | |
3314 | for each source code line outside of .text in the compilation unit. */ | |
3315 | static dw_separate_line_info_ref separate_line_info_table; | |
3316 | ||
3317 | /* Number of elements currently allocated for separate_line_info_table. */ | |
3318 | static unsigned separate_line_info_table_allocated; | |
3319 | ||
3320 | /* Number of elements in line_info_table currently in use. */ | |
3321 | static unsigned line_info_table_in_use; | |
3322 | ||
3323 | /* Size (in elements) of increments by which we may expand the | |
3324 | line_info_table. */ | |
3325 | #define LINE_INFO_TABLE_INCREMENT 1024 | |
3326 | ||
3327 | /* A pointer to the base of a table that contains a list of publicly | |
3328 | accessible names. */ | |
3329 | static pubname_ref pubname_table; | |
3330 | ||
3331 | /* Number of elements currently allocated for pubname_table. */ | |
3332 | static unsigned pubname_table_allocated; | |
3333 | ||
3334 | /* Number of elements in pubname_table currently in use. */ | |
3335 | static unsigned pubname_table_in_use; | |
3336 | ||
3337 | /* Size (in elements) of increments by which we may expand the | |
3338 | pubname_table. */ | |
3339 | #define PUBNAME_TABLE_INCREMENT 64 | |
3340 | ||
a20612aa RH |
3341 | /* Array of dies for which we should generate .debug_arange info. */ |
3342 | static dw_die_ref *arange_table; | |
7d9d8943 AM |
3343 | |
3344 | /* Number of elements currently allocated for arange_table. */ | |
3345 | static unsigned arange_table_allocated; | |
3346 | ||
3347 | /* Number of elements in arange_table currently in use. */ | |
3348 | static unsigned arange_table_in_use; | |
3349 | ||
3350 | /* Size (in elements) of increments by which we may expand the | |
3351 | arange_table. */ | |
3352 | #define ARANGE_TABLE_INCREMENT 64 | |
3353 | ||
a20612aa RH |
3354 | /* Array of dies for which we should generate .debug_ranges info. */ |
3355 | static dw_ranges_ref ranges_table; | |
3356 | ||
3357 | /* Number of elements currently allocated for ranges_table. */ | |
3358 | static unsigned ranges_table_allocated; | |
3359 | ||
3360 | /* Number of elements in ranges_table currently in use. */ | |
3361 | static unsigned ranges_table_in_use; | |
3362 | ||
3363 | /* Size (in elements) of increments by which we may expand the | |
3364 | ranges_table. */ | |
3365 | #define RANGES_TABLE_INCREMENT 64 | |
3366 | ||
63e46568 DB |
3367 | /* Whether we have location lists that need outputting */ |
3368 | static unsigned have_location_lists; | |
3369 | ||
7d9d8943 AM |
3370 | /* A pointer to the base of a list of incomplete types which might be |
3371 | completed at some later time. */ | |
3372 | ||
3373 | static tree *incomplete_types_list; | |
3374 | ||
3375 | /* Number of elements currently allocated for the incomplete_types_list. */ | |
3376 | static unsigned incomplete_types_allocated; | |
3377 | ||
3378 | /* Number of elements of incomplete_types_list currently in use. */ | |
3379 | static unsigned incomplete_types; | |
3380 | ||
3381 | /* Size (in elements) of increments by which we may expand the incomplete | |
3382 | types list. Actually, a single hunk of space of this size should | |
3383 | be enough for most typical programs. */ | |
3384 | #define INCOMPLETE_TYPES_INCREMENT 64 | |
3385 | ||
3386 | /* Record whether the function being analyzed contains inlined functions. */ | |
3387 | static int current_function_has_inlines; | |
3388 | #if 0 && defined (MIPS_DEBUGGING_INFO) | |
3389 | static int comp_unit_has_inlines; | |
3390 | #endif | |
3391 | ||
3392 | /* Array of RTXes referenced by the debugging information, which therefore | |
3393 | must be kept around forever. We do this rather than perform GC on | |
3394 | the dwarf info because almost all of the dwarf info lives forever, and | |
3395 | it's easier to support non-GC frontends this way. */ | |
3396 | static varray_type used_rtx_varray; | |
3397 | ||
3398 | /* Forward declarations for functions defined in this file. */ | |
3399 | ||
3400 | static int is_pseudo_reg PARAMS ((rtx)); | |
3401 | static tree type_main_variant PARAMS ((tree)); | |
3402 | static int is_tagged_type PARAMS ((tree)); | |
3403 | static const char *dwarf_tag_name PARAMS ((unsigned)); | |
3404 | static const char *dwarf_attr_name PARAMS ((unsigned)); | |
3405 | static const char *dwarf_form_name PARAMS ((unsigned)); | |
3406 | #if 0 | |
3407 | static const char *dwarf_type_encoding_name PARAMS ((unsigned)); | |
3408 | #endif | |
3409 | static tree decl_ultimate_origin PARAMS ((tree)); | |
3410 | static tree block_ultimate_origin PARAMS ((tree)); | |
3411 | static tree decl_class_context PARAMS ((tree)); | |
3412 | static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref)); | |
3413 | static void add_AT_flag PARAMS ((dw_die_ref, | |
3414 | enum dwarf_attribute, | |
3415 | unsigned)); | |
3416 | static void add_AT_int PARAMS ((dw_die_ref, | |
3417 | enum dwarf_attribute, long)); | |
3418 | static void add_AT_unsigned PARAMS ((dw_die_ref, | |
3419 | enum dwarf_attribute, | |
3420 | unsigned long)); | |
3421 | static void add_AT_long_long PARAMS ((dw_die_ref, | |
3422 | enum dwarf_attribute, | |
3423 | unsigned long, | |
3424 | unsigned long)); | |
3425 | static void add_AT_float PARAMS ((dw_die_ref, | |
3426 | enum dwarf_attribute, | |
3427 | unsigned, long *)); | |
3428 | static void add_AT_string PARAMS ((dw_die_ref, | |
3429 | enum dwarf_attribute, | |
3430 | const char *)); | |
3431 | static void add_AT_die_ref PARAMS ((dw_die_ref, | |
3432 | enum dwarf_attribute, | |
3433 | dw_die_ref)); | |
3434 | static void add_AT_fde_ref PARAMS ((dw_die_ref, | |
3435 | enum dwarf_attribute, | |
3436 | unsigned)); | |
3437 | static void add_AT_loc PARAMS ((dw_die_ref, | |
3438 | enum dwarf_attribute, | |
3439 | dw_loc_descr_ref)); | |
63e46568 DB |
3440 | static void add_AT_loc_list PARAMS ((dw_die_ref, |
3441 | enum dwarf_attribute, | |
3442 | dw_loc_list_ref)); | |
7d9d8943 AM |
3443 | static void add_AT_addr PARAMS ((dw_die_ref, |
3444 | enum dwarf_attribute, | |
3445 | rtx)); | |
3446 | static void add_AT_lbl_id PARAMS ((dw_die_ref, | |
3447 | enum dwarf_attribute, | |
3448 | const char *)); | |
3449 | static void add_AT_lbl_offset PARAMS ((dw_die_ref, | |
3450 | enum dwarf_attribute, | |
3451 | const char *)); | |
a20612aa RH |
3452 | static void add_AT_offset PARAMS ((dw_die_ref, |
3453 | enum dwarf_attribute, | |
3454 | unsigned long)); | |
7d9d8943 AM |
3455 | static dw_attr_ref get_AT PARAMS ((dw_die_ref, |
3456 | enum dwarf_attribute)); | |
3457 | static const char *get_AT_low_pc PARAMS ((dw_die_ref)); | |
3458 | static const char *get_AT_hi_pc PARAMS ((dw_die_ref)); | |
3459 | static const char *get_AT_string PARAMS ((dw_die_ref, | |
3460 | enum dwarf_attribute)); | |
3461 | static int get_AT_flag PARAMS ((dw_die_ref, | |
3462 | enum dwarf_attribute)); | |
3463 | static unsigned get_AT_unsigned PARAMS ((dw_die_ref, | |
3464 | enum dwarf_attribute)); | |
3465 | static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref, | |
3466 | enum dwarf_attribute)); | |
3467 | static int is_c_family PARAMS ((void)); | |
28985b81 | 3468 | static int is_java PARAMS ((void)); |
7d9d8943 AM |
3469 | static int is_fortran PARAMS ((void)); |
3470 | static void remove_AT PARAMS ((dw_die_ref, | |
3471 | enum dwarf_attribute)); | |
3472 | static void remove_children PARAMS ((dw_die_ref)); | |
3473 | static void add_child_die PARAMS ((dw_die_ref, dw_die_ref)); | |
3474 | static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref)); | |
3475 | static dw_die_ref lookup_type_die PARAMS ((tree)); | |
3476 | static void equate_type_number_to_die PARAMS ((tree, dw_die_ref)); | |
3477 | static dw_die_ref lookup_decl_die PARAMS ((tree)); | |
3478 | static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref)); | |
3479 | static void print_spaces PARAMS ((FILE *)); | |
3480 | static void print_die PARAMS ((dw_die_ref, FILE *)); | |
3481 | static void print_dwarf_line_table PARAMS ((FILE *)); | |
881c6935 JM |
3482 | static void reverse_die_lists PARAMS ((dw_die_ref)); |
3483 | static void reverse_all_dies PARAMS ((dw_die_ref)); | |
3484 | static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref)); | |
3485 | static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref)); | |
3486 | static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *)); | |
3487 | static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *)); | |
3488 | static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *)); | |
3489 | static void compute_section_prefix PARAMS ((dw_die_ref)); | |
3490 | static int is_type_die PARAMS ((dw_die_ref)); | |
3491 | static int is_comdat_die PARAMS ((dw_die_ref)); | |
3492 | static int is_symbol_die PARAMS ((dw_die_ref)); | |
881c6935 JM |
3493 | static void assign_symbol_names PARAMS ((dw_die_ref)); |
3494 | static void break_out_includes PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3495 | static void add_sibling_attributes PARAMS ((dw_die_ref)); |
3496 | static void build_abbrev_table PARAMS ((dw_die_ref)); | |
63e46568 | 3497 | static void output_location_lists PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3498 | static unsigned long size_of_string PARAMS ((const char *)); |
3499 | static int constant_size PARAMS ((long unsigned)); | |
3500 | static unsigned long size_of_die PARAMS ((dw_die_ref)); | |
3501 | static void calc_die_sizes PARAMS ((dw_die_ref)); | |
1bfb5f8f JM |
3502 | static void mark_dies PARAMS ((dw_die_ref)); |
3503 | static void unmark_dies PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3504 | static unsigned long size_of_pubnames PARAMS ((void)); |
3505 | static unsigned long size_of_aranges PARAMS ((void)); | |
3506 | static enum dwarf_form value_format PARAMS ((dw_attr_ref)); | |
3507 | static void output_value_format PARAMS ((dw_attr_ref)); | |
3508 | static void output_abbrev_section PARAMS ((void)); | |
881c6935 | 3509 | static void output_die_symbol PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3510 | static void output_die PARAMS ((dw_die_ref)); |
3511 | static void output_compilation_unit_header PARAMS ((void)); | |
881c6935 | 3512 | static void output_comp_unit PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3513 | static const char *dwarf2_name PARAMS ((tree, int)); |
3514 | static void add_pubname PARAMS ((tree, dw_die_ref)); | |
3515 | static void output_pubnames PARAMS ((void)); | |
3516 | static void add_arange PARAMS ((tree, dw_die_ref)); | |
3517 | static void output_aranges PARAMS ((void)); | |
a20612aa RH |
3518 | static unsigned int add_ranges PARAMS ((tree)); |
3519 | static void output_ranges PARAMS ((void)); | |
7d9d8943 | 3520 | static void output_line_info PARAMS ((void)); |
0b34cf1e | 3521 | static void output_file_names PARAMS ((void)); |
7d9d8943 AM |
3522 | static dw_die_ref base_type_die PARAMS ((tree)); |
3523 | static tree root_type PARAMS ((tree)); | |
3524 | static int is_base_type PARAMS ((tree)); | |
3525 | static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref)); | |
3526 | static int type_is_enum PARAMS ((tree)); | |
3527 | static unsigned int reg_number PARAMS ((rtx)); | |
3528 | static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx)); | |
d8041cc8 | 3529 | static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT)); |
7d9d8943 AM |
3530 | static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long)); |
3531 | static int is_based_loc PARAMS ((rtx)); | |
3532 | static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode)); | |
3533 | static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx)); | |
3534 | static dw_loc_descr_ref loc_descriptor PARAMS ((rtx)); | |
d8041cc8 | 3535 | static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int)); |
7d9d8943 AM |
3536 | static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int)); |
3537 | static tree field_type PARAMS ((tree)); | |
3538 | static unsigned int simple_type_align_in_bits PARAMS ((tree)); | |
5f446d21 | 3539 | static unsigned int simple_decl_align_in_bits PARAMS ((tree)); |
7d9d8943 AM |
3540 | static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree)); |
3541 | static HOST_WIDE_INT field_byte_offset PARAMS ((tree)); | |
3542 | static void add_AT_location_description PARAMS ((dw_die_ref, | |
3543 | enum dwarf_attribute, rtx)); | |
3544 | static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree)); | |
3545 | static void add_const_value_attribute PARAMS ((dw_die_ref, rtx)); | |
d8041cc8 | 3546 | static rtx rtl_for_decl_location PARAMS ((tree)); |
7d9d8943 | 3547 | static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree)); |
1bfb5f8f | 3548 | static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree)); |
7d9d8943 AM |
3549 | static void add_name_attribute PARAMS ((dw_die_ref, const char *)); |
3550 | static void add_bound_info PARAMS ((dw_die_ref, | |
3551 | enum dwarf_attribute, tree)); | |
3552 | static void add_subscript_info PARAMS ((dw_die_ref, tree)); | |
3553 | static void add_byte_size_attribute PARAMS ((dw_die_ref, tree)); | |
3554 | static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree)); | |
3555 | static void add_bit_size_attribute PARAMS ((dw_die_ref, tree)); | |
3556 | static void add_prototyped_attribute PARAMS ((dw_die_ref, tree)); | |
3557 | static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree)); | |
3558 | static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree)); | |
3559 | static void add_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
3560 | static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
3561 | static void push_decl_scope PARAMS ((tree)); | |
3562 | static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref)); | |
3563 | static void pop_decl_scope PARAMS ((void)); | |
3564 | static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int, | |
3565 | dw_die_ref)); | |
3566 | static const char *type_tag PARAMS ((tree)); | |
3567 | static tree member_declared_type PARAMS ((tree)); | |
3568 | #if 0 | |
3569 | static const char *decl_start_label PARAMS ((tree)); | |
3570 | #endif | |
3571 | static void gen_array_type_die PARAMS ((tree, dw_die_ref)); | |
3572 | static void gen_set_type_die PARAMS ((tree, dw_die_ref)); | |
3573 | #if 0 | |
3574 | static void gen_entry_point_die PARAMS ((tree, dw_die_ref)); | |
3575 | #endif | |
3576 | static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
3577 | static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref)); | |
3578 | static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref)); | |
3579 | static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
3580 | static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref)); | |
3581 | static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref)); | |
3582 | static void gen_formal_types_die PARAMS ((tree, dw_die_ref)); | |
3583 | static void gen_subprogram_die PARAMS ((tree, dw_die_ref)); | |
3584 | static void gen_variable_die PARAMS ((tree, dw_die_ref)); | |
3585 | static void gen_label_die PARAMS ((tree, dw_die_ref)); | |
3586 | static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int)); | |
3587 | static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int)); | |
3588 | static void gen_field_die PARAMS ((tree, dw_die_ref)); | |
3589 | static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref)); | |
3590 | static dw_die_ref gen_compile_unit_die PARAMS ((const char *)); | |
3591 | static void gen_string_type_die PARAMS ((tree, dw_die_ref)); | |
3592 | static void gen_inheritance_die PARAMS ((tree, dw_die_ref)); | |
3593 | static void gen_member_die PARAMS ((tree, dw_die_ref)); | |
3594 | static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref)); | |
3595 | static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref)); | |
3596 | static void gen_typedef_die PARAMS ((tree, dw_die_ref)); | |
3597 | static void gen_type_die PARAMS ((tree, dw_die_ref)); | |
3598 | static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref)); | |
3599 | static void gen_block_die PARAMS ((tree, dw_die_ref, int)); | |
3600 | static void decls_for_scope PARAMS ((tree, dw_die_ref, int)); | |
3601 | static int is_redundant_typedef PARAMS ((tree)); | |
3602 | static void gen_decl_die PARAMS ((tree, dw_die_ref)); | |
981975b6 RH |
3603 | static unsigned lookup_filename PARAMS ((const char *)); |
3604 | static void init_file_table PARAMS ((void)); | |
7d9d8943 AM |
3605 | static void add_incomplete_type PARAMS ((tree)); |
3606 | static void retry_incomplete_types PARAMS ((void)); | |
3607 | static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref)); | |
7d9d8943 AM |
3608 | static rtx save_rtx PARAMS ((rtx)); |
3609 | static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref)); | |
fc608b03 | 3610 | static int file_info_cmp PARAMS ((const void *, const void *)); |
84a5b4f8 DB |
3611 | static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref, |
3612 | const char *, const char *, | |
3613 | const char *, unsigned)); | |
3614 | static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *, | |
3615 | dw_loc_descr_ref, | |
3616 | const char *, const char *, const char *)); | |
3617 | static void output_loc_list PARAMS ((dw_loc_list_ref)); | |
3618 | static char *gen_internal_sym PARAMS ((const char *)); | |
7d9d8943 AM |
3619 | |
3620 | /* Section names used to hold DWARF debugging information. */ | |
3621 | #ifndef DEBUG_INFO_SECTION | |
3622 | #define DEBUG_INFO_SECTION ".debug_info" | |
3623 | #endif | |
9d2f2c45 RH |
3624 | #ifndef DEBUG_ABBREV_SECTION |
3625 | #define DEBUG_ABBREV_SECTION ".debug_abbrev" | |
7d9d8943 | 3626 | #endif |
9d2f2c45 RH |
3627 | #ifndef DEBUG_ARANGES_SECTION |
3628 | #define DEBUG_ARANGES_SECTION ".debug_aranges" | |
7d9d8943 | 3629 | #endif |
9d2f2c45 RH |
3630 | #ifndef DEBUG_MACINFO_SECTION |
3631 | #define DEBUG_MACINFO_SECTION ".debug_macinfo" | |
7d9d8943 AM |
3632 | #endif |
3633 | #ifndef DEBUG_LINE_SECTION | |
3634 | #define DEBUG_LINE_SECTION ".debug_line" | |
3635 | #endif | |
9d2f2c45 RH |
3636 | #ifndef DEBUG_LOC_SECTION |
3637 | #define DEBUG_LOC_SECTION ".debug_loc" | |
7d9d8943 | 3638 | #endif |
9d2f2c45 RH |
3639 | #ifndef DEBUG_PUBNAMES_SECTION |
3640 | #define DEBUG_PUBNAMES_SECTION ".debug_pubnames" | |
7d9d8943 | 3641 | #endif |
9d2f2c45 RH |
3642 | #ifndef DEBUG_STR_SECTION |
3643 | #define DEBUG_STR_SECTION ".debug_str" | |
7d9d8943 | 3644 | #endif |
a20612aa RH |
3645 | #ifndef DEBUG_RANGES_SECTION |
3646 | #define DEBUG_RANGES_SECTION ".debug_ranges" | |
3647 | #endif | |
7d9d8943 AM |
3648 | |
3649 | /* Standard ELF section names for compiled code and data. */ | |
f99ffb60 RH |
3650 | #ifndef TEXT_SECTION_NAME |
3651 | #define TEXT_SECTION_NAME ".text" | |
7d9d8943 AM |
3652 | #endif |
3653 | ||
3654 | /* Labels we insert at beginning sections we can reference instead of | |
556273e0 | 3655 | the section names themselves. */ |
7d9d8943 AM |
3656 | |
3657 | #ifndef TEXT_SECTION_LABEL | |
9d2f2c45 | 3658 | #define TEXT_SECTION_LABEL "Ltext" |
7d9d8943 AM |
3659 | #endif |
3660 | #ifndef DEBUG_LINE_SECTION_LABEL | |
9d2f2c45 | 3661 | #define DEBUG_LINE_SECTION_LABEL "Ldebug_line" |
7d9d8943 AM |
3662 | #endif |
3663 | #ifndef DEBUG_INFO_SECTION_LABEL | |
9d2f2c45 | 3664 | #define DEBUG_INFO_SECTION_LABEL "Ldebug_info" |
7d9d8943 | 3665 | #endif |
9d2f2c45 RH |
3666 | #ifndef DEBUG_ABBREV_SECTION_LABEL |
3667 | #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev" | |
7d9d8943 | 3668 | #endif |
9d2f2c45 RH |
3669 | #ifndef DEBUG_LOC_SECTION_LABEL |
3670 | #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc" | |
63e46568 | 3671 | #endif |
84a5b4f8 DB |
3672 | #ifndef DEBUG_MACINFO_SECTION_LABEL |
3673 | #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo" | |
3674 | #endif | |
a20612aa | 3675 | |
7d9d8943 AM |
3676 | /* Definitions of defaults for formats and names of various special |
3677 | (artificial) labels which may be generated within this file (when the -g | |
3678 | options is used and DWARF_DEBUGGING_INFO is in effect. | |
3679 | If necessary, these may be overridden from within the tm.h file, but | |
3680 | typically, overriding these defaults is unnecessary. */ | |
3681 | ||
3682 | static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3683 | static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3684 | static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3685 | static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3686 | static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
84a5b4f8 | 3687 | static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
63e46568 | 3688 | static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
7d9d8943 AM |
3689 | #ifndef TEXT_END_LABEL |
3690 | #define TEXT_END_LABEL "Letext" | |
3691 | #endif | |
3692 | #ifndef DATA_END_LABEL | |
3693 | #define DATA_END_LABEL "Ledata" | |
3694 | #endif | |
3695 | #ifndef BSS_END_LABEL | |
3696 | #define BSS_END_LABEL "Lebss" | |
3697 | #endif | |
7d9d8943 AM |
3698 | #ifndef BLOCK_BEGIN_LABEL |
3699 | #define BLOCK_BEGIN_LABEL "LBB" | |
3700 | #endif | |
3701 | #ifndef BLOCK_END_LABEL | |
3702 | #define BLOCK_END_LABEL "LBE" | |
3703 | #endif | |
3704 | #ifndef BODY_BEGIN_LABEL | |
3705 | #define BODY_BEGIN_LABEL "Lbb" | |
3706 | #endif | |
3707 | #ifndef BODY_END_LABEL | |
3708 | #define BODY_END_LABEL "Lbe" | |
3709 | #endif | |
3710 | #ifndef LINE_CODE_LABEL | |
3711 | #define LINE_CODE_LABEL "LM" | |
3712 | #endif | |
3713 | #ifndef SEPARATE_LINE_CODE_LABEL | |
3714 | #define SEPARATE_LINE_CODE_LABEL "LSM" | |
3715 | #endif | |
3716 | \f | |
3717 | /* We allow a language front-end to designate a function that is to be | |
3718 | called to "demangle" any name before it it put into a DIE. */ | |
3719 | ||
3720 | static const char *(*demangle_name_func) PARAMS ((const char *)); | |
3721 | ||
3722 | void | |
3723 | dwarf2out_set_demangle_name_func (func) | |
3724 | const char *(*func) PARAMS ((const char *)); | |
3725 | { | |
3726 | demangle_name_func = func; | |
3727 | } | |
3728 | \f | |
3729 | /* Return an rtx like ORIG which lives forever. If we're doing GC, | |
3730 | that means adding it to used_rtx_varray. If not, that means making | |
3731 | a copy on the permanent_obstack. */ | |
3732 | ||
3733 | static rtx | |
3734 | save_rtx (orig) | |
3735 | register rtx orig; | |
3736 | { | |
1f8f4a0b | 3737 | VARRAY_PUSH_RTX (used_rtx_varray, orig); |
7d9d8943 AM |
3738 | |
3739 | return orig; | |
3740 | } | |
3741 | ||
3742 | /* Test if rtl node points to a pseudo register. */ | |
3743 | ||
3744 | static inline int | |
3745 | is_pseudo_reg (rtl) | |
3746 | register rtx rtl; | |
3747 | { | |
3748 | return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER) | |
3749 | || (GET_CODE (rtl) == SUBREG | |
ddef6bc7 | 3750 | && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)); |
7d9d8943 AM |
3751 | } |
3752 | ||
3753 | /* Return a reference to a type, with its const and volatile qualifiers | |
3754 | removed. */ | |
3755 | ||
3756 | static inline tree | |
3757 | type_main_variant (type) | |
3758 | register tree type; | |
3759 | { | |
3760 | type = TYPE_MAIN_VARIANT (type); | |
3761 | ||
556273e0 | 3762 | /* There really should be only one main variant among any group of variants |
7d9d8943 AM |
3763 | of a given type (and all of the MAIN_VARIANT values for all members of |
3764 | the group should point to that one type) but sometimes the C front-end | |
3765 | messes this up for array types, so we work around that bug here. */ | |
3766 | ||
3767 | if (TREE_CODE (type) == ARRAY_TYPE) | |
3768 | while (type != TYPE_MAIN_VARIANT (type)) | |
3769 | type = TYPE_MAIN_VARIANT (type); | |
3770 | ||
3771 | return type; | |
3772 | } | |
3773 | ||
3774 | /* Return non-zero if the given type node represents a tagged type. */ | |
3775 | ||
3776 | static inline int | |
3777 | is_tagged_type (type) | |
3778 | register tree type; | |
3779 | { | |
3780 | register enum tree_code code = TREE_CODE (type); | |
3781 | ||
3782 | return (code == RECORD_TYPE || code == UNION_TYPE | |
3783 | || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); | |
3784 | } | |
3785 | ||
3786 | /* Convert a DIE tag into its string name. */ | |
3787 | ||
3788 | static const char * | |
3789 | dwarf_tag_name (tag) | |
3790 | register unsigned tag; | |
3791 | { | |
3792 | switch (tag) | |
3793 | { | |
3794 | case DW_TAG_padding: | |
3795 | return "DW_TAG_padding"; | |
3796 | case DW_TAG_array_type: | |
3797 | return "DW_TAG_array_type"; | |
3798 | case DW_TAG_class_type: | |
3799 | return "DW_TAG_class_type"; | |
3800 | case DW_TAG_entry_point: | |
3801 | return "DW_TAG_entry_point"; | |
3802 | case DW_TAG_enumeration_type: | |
3803 | return "DW_TAG_enumeration_type"; | |
3804 | case DW_TAG_formal_parameter: | |
3805 | return "DW_TAG_formal_parameter"; | |
3806 | case DW_TAG_imported_declaration: | |
3807 | return "DW_TAG_imported_declaration"; | |
3808 | case DW_TAG_label: | |
3809 | return "DW_TAG_label"; | |
3810 | case DW_TAG_lexical_block: | |
3811 | return "DW_TAG_lexical_block"; | |
3812 | case DW_TAG_member: | |
3813 | return "DW_TAG_member"; | |
3814 | case DW_TAG_pointer_type: | |
3815 | return "DW_TAG_pointer_type"; | |
3816 | case DW_TAG_reference_type: | |
3817 | return "DW_TAG_reference_type"; | |
3818 | case DW_TAG_compile_unit: | |
3819 | return "DW_TAG_compile_unit"; | |
3820 | case DW_TAG_string_type: | |
3821 | return "DW_TAG_string_type"; | |
3822 | case DW_TAG_structure_type: | |
3823 | return "DW_TAG_structure_type"; | |
3824 | case DW_TAG_subroutine_type: | |
3825 | return "DW_TAG_subroutine_type"; | |
3826 | case DW_TAG_typedef: | |
3827 | return "DW_TAG_typedef"; | |
3828 | case DW_TAG_union_type: | |
3829 | return "DW_TAG_union_type"; | |
3830 | case DW_TAG_unspecified_parameters: | |
3831 | return "DW_TAG_unspecified_parameters"; | |
3832 | case DW_TAG_variant: | |
3833 | return "DW_TAG_variant"; | |
3834 | case DW_TAG_common_block: | |
3835 | return "DW_TAG_common_block"; | |
3836 | case DW_TAG_common_inclusion: | |
3837 | return "DW_TAG_common_inclusion"; | |
3838 | case DW_TAG_inheritance: | |
3839 | return "DW_TAG_inheritance"; | |
3840 | case DW_TAG_inlined_subroutine: | |
3841 | return "DW_TAG_inlined_subroutine"; | |
3842 | case DW_TAG_module: | |
3843 | return "DW_TAG_module"; | |
3844 | case DW_TAG_ptr_to_member_type: | |
3845 | return "DW_TAG_ptr_to_member_type"; | |
3846 | case DW_TAG_set_type: | |
3847 | return "DW_TAG_set_type"; | |
3848 | case DW_TAG_subrange_type: | |
3849 | return "DW_TAG_subrange_type"; | |
3850 | case DW_TAG_with_stmt: | |
3851 | return "DW_TAG_with_stmt"; | |
3852 | case DW_TAG_access_declaration: | |
3853 | return "DW_TAG_access_declaration"; | |
3854 | case DW_TAG_base_type: | |
3855 | return "DW_TAG_base_type"; | |
3856 | case DW_TAG_catch_block: | |
3857 | return "DW_TAG_catch_block"; | |
3858 | case DW_TAG_const_type: | |
3859 | return "DW_TAG_const_type"; | |
3860 | case DW_TAG_constant: | |
3861 | return "DW_TAG_constant"; | |
3862 | case DW_TAG_enumerator: | |
3863 | return "DW_TAG_enumerator"; | |
3864 | case DW_TAG_file_type: | |
3865 | return "DW_TAG_file_type"; | |
3866 | case DW_TAG_friend: | |
3867 | return "DW_TAG_friend"; | |
3868 | case DW_TAG_namelist: | |
3869 | return "DW_TAG_namelist"; | |
3870 | case DW_TAG_namelist_item: | |
3871 | return "DW_TAG_namelist_item"; | |
3872 | case DW_TAG_packed_type: | |
3873 | return "DW_TAG_packed_type"; | |
3874 | case DW_TAG_subprogram: | |
3875 | return "DW_TAG_subprogram"; | |
3876 | case DW_TAG_template_type_param: | |
3877 | return "DW_TAG_template_type_param"; | |
3878 | case DW_TAG_template_value_param: | |
3879 | return "DW_TAG_template_value_param"; | |
3880 | case DW_TAG_thrown_type: | |
3881 | return "DW_TAG_thrown_type"; | |
3882 | case DW_TAG_try_block: | |
3883 | return "DW_TAG_try_block"; | |
3884 | case DW_TAG_variant_part: | |
3885 | return "DW_TAG_variant_part"; | |
3886 | case DW_TAG_variable: | |
3887 | return "DW_TAG_variable"; | |
3888 | case DW_TAG_volatile_type: | |
3889 | return "DW_TAG_volatile_type"; | |
3890 | case DW_TAG_MIPS_loop: | |
3891 | return "DW_TAG_MIPS_loop"; | |
3892 | case DW_TAG_format_label: | |
3893 | return "DW_TAG_format_label"; | |
3894 | case DW_TAG_function_template: | |
3895 | return "DW_TAG_function_template"; | |
3896 | case DW_TAG_class_template: | |
3897 | return "DW_TAG_class_template"; | |
881c6935 JM |
3898 | case DW_TAG_GNU_BINCL: |
3899 | return "DW_TAG_GNU_BINCL"; | |
3900 | case DW_TAG_GNU_EINCL: | |
3901 | return "DW_TAG_GNU_EINCL"; | |
7d9d8943 AM |
3902 | default: |
3903 | return "DW_TAG_<unknown>"; | |
3904 | } | |
3905 | } | |
3906 | ||
3907 | /* Convert a DWARF attribute code into its string name. */ | |
3908 | ||
3909 | static const char * | |
3910 | dwarf_attr_name (attr) | |
3911 | register unsigned attr; | |
3912 | { | |
3913 | switch (attr) | |
3914 | { | |
3915 | case DW_AT_sibling: | |
3916 | return "DW_AT_sibling"; | |
3917 | case DW_AT_location: | |
3918 | return "DW_AT_location"; | |
3919 | case DW_AT_name: | |
3920 | return "DW_AT_name"; | |
3921 | case DW_AT_ordering: | |
3922 | return "DW_AT_ordering"; | |
3923 | case DW_AT_subscr_data: | |
3924 | return "DW_AT_subscr_data"; | |
3925 | case DW_AT_byte_size: | |
3926 | return "DW_AT_byte_size"; | |
3927 | case DW_AT_bit_offset: | |
3928 | return "DW_AT_bit_offset"; | |
3929 | case DW_AT_bit_size: | |
3930 | return "DW_AT_bit_size"; | |
3931 | case DW_AT_element_list: | |
3932 | return "DW_AT_element_list"; | |
3933 | case DW_AT_stmt_list: | |
3934 | return "DW_AT_stmt_list"; | |
3935 | case DW_AT_low_pc: | |
3936 | return "DW_AT_low_pc"; | |
3937 | case DW_AT_high_pc: | |
3938 | return "DW_AT_high_pc"; | |
3939 | case DW_AT_language: | |
3940 | return "DW_AT_language"; | |
3941 | case DW_AT_member: | |
3942 | return "DW_AT_member"; | |
3943 | case DW_AT_discr: | |
3944 | return "DW_AT_discr"; | |
3945 | case DW_AT_discr_value: | |
3946 | return "DW_AT_discr_value"; | |
3947 | case DW_AT_visibility: | |
3948 | return "DW_AT_visibility"; | |
3949 | case DW_AT_import: | |
3950 | return "DW_AT_import"; | |
3951 | case DW_AT_string_length: | |
3952 | return "DW_AT_string_length"; | |
3953 | case DW_AT_common_reference: | |
3954 | return "DW_AT_common_reference"; | |
3955 | case DW_AT_comp_dir: | |
3956 | return "DW_AT_comp_dir"; | |
3957 | case DW_AT_const_value: | |
3958 | return "DW_AT_const_value"; | |
3959 | case DW_AT_containing_type: | |
3960 | return "DW_AT_containing_type"; | |
3961 | case DW_AT_default_value: | |
3962 | return "DW_AT_default_value"; | |
3963 | case DW_AT_inline: | |
3964 | return "DW_AT_inline"; | |
3965 | case DW_AT_is_optional: | |
3966 | return "DW_AT_is_optional"; | |
3967 | case DW_AT_lower_bound: | |
3968 | return "DW_AT_lower_bound"; | |
3969 | case DW_AT_producer: | |
3970 | return "DW_AT_producer"; | |
3971 | case DW_AT_prototyped: | |
3972 | return "DW_AT_prototyped"; | |
3973 | case DW_AT_return_addr: | |
3974 | return "DW_AT_return_addr"; | |
3975 | case DW_AT_start_scope: | |
3976 | return "DW_AT_start_scope"; | |
3977 | case DW_AT_stride_size: | |
3978 | return "DW_AT_stride_size"; | |
3979 | case DW_AT_upper_bound: | |
3980 | return "DW_AT_upper_bound"; | |
3981 | case DW_AT_abstract_origin: | |
3982 | return "DW_AT_abstract_origin"; | |
3983 | case DW_AT_accessibility: | |
3984 | return "DW_AT_accessibility"; | |
3985 | case DW_AT_address_class: | |
3986 | return "DW_AT_address_class"; | |
3987 | case DW_AT_artificial: | |
3988 | return "DW_AT_artificial"; | |
3989 | case DW_AT_base_types: | |
3990 | return "DW_AT_base_types"; | |
3991 | case DW_AT_calling_convention: | |
3992 | return "DW_AT_calling_convention"; | |
3993 | case DW_AT_count: | |
3994 | return "DW_AT_count"; | |
3995 | case DW_AT_data_member_location: | |
3996 | return "DW_AT_data_member_location"; | |
3997 | case DW_AT_decl_column: | |
3998 | return "DW_AT_decl_column"; | |
3999 | case DW_AT_decl_file: | |
4000 | return "DW_AT_decl_file"; | |
4001 | case DW_AT_decl_line: | |
4002 | return "DW_AT_decl_line"; | |
4003 | case DW_AT_declaration: | |
4004 | return "DW_AT_declaration"; | |
4005 | case DW_AT_discr_list: | |
4006 | return "DW_AT_discr_list"; | |
4007 | case DW_AT_encoding: | |
4008 | return "DW_AT_encoding"; | |
4009 | case DW_AT_external: | |
4010 | return "DW_AT_external"; | |
4011 | case DW_AT_frame_base: | |
4012 | return "DW_AT_frame_base"; | |
4013 | case DW_AT_friend: | |
4014 | return "DW_AT_friend"; | |
4015 | case DW_AT_identifier_case: | |
4016 | return "DW_AT_identifier_case"; | |
4017 | case DW_AT_macro_info: | |
4018 | return "DW_AT_macro_info"; | |
4019 | case DW_AT_namelist_items: | |
4020 | return "DW_AT_namelist_items"; | |
4021 | case DW_AT_priority: | |
4022 | return "DW_AT_priority"; | |
4023 | case DW_AT_segment: | |
4024 | return "DW_AT_segment"; | |
4025 | case DW_AT_specification: | |
4026 | return "DW_AT_specification"; | |
4027 | case DW_AT_static_link: | |
4028 | return "DW_AT_static_link"; | |
4029 | case DW_AT_type: | |
4030 | return "DW_AT_type"; | |
4031 | case DW_AT_use_location: | |
4032 | return "DW_AT_use_location"; | |
4033 | case DW_AT_variable_parameter: | |
4034 | return "DW_AT_variable_parameter"; | |
4035 | case DW_AT_virtuality: | |
4036 | return "DW_AT_virtuality"; | |
4037 | case DW_AT_vtable_elem_location: | |
4038 | return "DW_AT_vtable_elem_location"; | |
4039 | ||
a20612aa RH |
4040 | case DW_AT_allocated: |
4041 | return "DW_AT_allocated"; | |
4042 | case DW_AT_associated: | |
4043 | return "DW_AT_associated"; | |
4044 | case DW_AT_data_location: | |
4045 | return "DW_AT_data_location"; | |
4046 | case DW_AT_stride: | |
4047 | return "DW_AT_stride"; | |
4048 | case DW_AT_entry_pc: | |
4049 | return "DW_AT_entry_pc"; | |
4050 | case DW_AT_use_UTF8: | |
4051 | return "DW_AT_use_UTF8"; | |
4052 | case DW_AT_extension: | |
4053 | return "DW_AT_extension"; | |
4054 | case DW_AT_ranges: | |
4055 | return "DW_AT_ranges"; | |
4056 | case DW_AT_trampoline: | |
4057 | return "DW_AT_trampoline"; | |
4058 | case DW_AT_call_column: | |
4059 | return "DW_AT_call_column"; | |
4060 | case DW_AT_call_file: | |
4061 | return "DW_AT_call_file"; | |
4062 | case DW_AT_call_line: | |
4063 | return "DW_AT_call_line"; | |
4064 | ||
7d9d8943 AM |
4065 | case DW_AT_MIPS_fde: |
4066 | return "DW_AT_MIPS_fde"; | |
4067 | case DW_AT_MIPS_loop_begin: | |
4068 | return "DW_AT_MIPS_loop_begin"; | |
4069 | case DW_AT_MIPS_tail_loop_begin: | |
4070 | return "DW_AT_MIPS_tail_loop_begin"; | |
4071 | case DW_AT_MIPS_epilog_begin: | |
4072 | return "DW_AT_MIPS_epilog_begin"; | |
4073 | case DW_AT_MIPS_loop_unroll_factor: | |
4074 | return "DW_AT_MIPS_loop_unroll_factor"; | |
4075 | case DW_AT_MIPS_software_pipeline_depth: | |
4076 | return "DW_AT_MIPS_software_pipeline_depth"; | |
4077 | case DW_AT_MIPS_linkage_name: | |
4078 | return "DW_AT_MIPS_linkage_name"; | |
4079 | case DW_AT_MIPS_stride: | |
4080 | return "DW_AT_MIPS_stride"; | |
4081 | case DW_AT_MIPS_abstract_name: | |
4082 | return "DW_AT_MIPS_abstract_name"; | |
4083 | case DW_AT_MIPS_clone_origin: | |
4084 | return "DW_AT_MIPS_clone_origin"; | |
4085 | case DW_AT_MIPS_has_inlines: | |
4086 | return "DW_AT_MIPS_has_inlines"; | |
4087 | ||
4088 | case DW_AT_sf_names: | |
4089 | return "DW_AT_sf_names"; | |
4090 | case DW_AT_src_info: | |
4091 | return "DW_AT_src_info"; | |
4092 | case DW_AT_mac_info: | |
4093 | return "DW_AT_mac_info"; | |
4094 | case DW_AT_src_coords: | |
4095 | return "DW_AT_src_coords"; | |
4096 | case DW_AT_body_begin: | |
4097 | return "DW_AT_body_begin"; | |
4098 | case DW_AT_body_end: | |
4099 | return "DW_AT_body_end"; | |
4100 | default: | |
4101 | return "DW_AT_<unknown>"; | |
4102 | } | |
4103 | } | |
4104 | ||
4105 | /* Convert a DWARF value form code into its string name. */ | |
4106 | ||
4107 | static const char * | |
4108 | dwarf_form_name (form) | |
4109 | register unsigned form; | |
4110 | { | |
4111 | switch (form) | |
4112 | { | |
4113 | case DW_FORM_addr: | |
4114 | return "DW_FORM_addr"; | |
4115 | case DW_FORM_block2: | |
4116 | return "DW_FORM_block2"; | |
4117 | case DW_FORM_block4: | |
4118 | return "DW_FORM_block4"; | |
4119 | case DW_FORM_data2: | |
4120 | return "DW_FORM_data2"; | |
4121 | case DW_FORM_data4: | |
4122 | return "DW_FORM_data4"; | |
4123 | case DW_FORM_data8: | |
4124 | return "DW_FORM_data8"; | |
4125 | case DW_FORM_string: | |
4126 | return "DW_FORM_string"; | |
4127 | case DW_FORM_block: | |
4128 | return "DW_FORM_block"; | |
4129 | case DW_FORM_block1: | |
4130 | return "DW_FORM_block1"; | |
4131 | case DW_FORM_data1: | |
4132 | return "DW_FORM_data1"; | |
4133 | case DW_FORM_flag: | |
4134 | return "DW_FORM_flag"; | |
4135 | case DW_FORM_sdata: | |
4136 | return "DW_FORM_sdata"; | |
4137 | case DW_FORM_strp: | |
4138 | return "DW_FORM_strp"; | |
4139 | case DW_FORM_udata: | |
4140 | return "DW_FORM_udata"; | |
4141 | case DW_FORM_ref_addr: | |
4142 | return "DW_FORM_ref_addr"; | |
4143 | case DW_FORM_ref1: | |
4144 | return "DW_FORM_ref1"; | |
4145 | case DW_FORM_ref2: | |
4146 | return "DW_FORM_ref2"; | |
4147 | case DW_FORM_ref4: | |
4148 | return "DW_FORM_ref4"; | |
4149 | case DW_FORM_ref8: | |
4150 | return "DW_FORM_ref8"; | |
4151 | case DW_FORM_ref_udata: | |
4152 | return "DW_FORM_ref_udata"; | |
4153 | case DW_FORM_indirect: | |
4154 | return "DW_FORM_indirect"; | |
3f76745e | 4155 | default: |
7d9d8943 | 4156 | return "DW_FORM_<unknown>"; |
a3f97cbb JW |
4157 | } |
4158 | } | |
4159 | ||
3f76745e | 4160 | /* Convert a DWARF type code into its string name. */ |
71dfc51f | 4161 | |
487a6e06 | 4162 | #if 0 |
d560ee52 | 4163 | static const char * |
3f76745e JM |
4164 | dwarf_type_encoding_name (enc) |
4165 | register unsigned enc; | |
a3f97cbb | 4166 | { |
3f76745e | 4167 | switch (enc) |
a3f97cbb | 4168 | { |
3f76745e JM |
4169 | case DW_ATE_address: |
4170 | return "DW_ATE_address"; | |
4171 | case DW_ATE_boolean: | |
4172 | return "DW_ATE_boolean"; | |
4173 | case DW_ATE_complex_float: | |
4174 | return "DW_ATE_complex_float"; | |
4175 | case DW_ATE_float: | |
4176 | return "DW_ATE_float"; | |
4177 | case DW_ATE_signed: | |
4178 | return "DW_ATE_signed"; | |
4179 | case DW_ATE_signed_char: | |
4180 | return "DW_ATE_signed_char"; | |
4181 | case DW_ATE_unsigned: | |
4182 | return "DW_ATE_unsigned"; | |
4183 | case DW_ATE_unsigned_char: | |
4184 | return "DW_ATE_unsigned_char"; | |
4185 | default: | |
4186 | return "DW_ATE_<unknown>"; | |
4187 | } | |
a3f97cbb | 4188 | } |
487a6e06 | 4189 | #endif |
3f76745e JM |
4190 | \f |
4191 | /* Determine the "ultimate origin" of a decl. The decl may be an inlined | |
4192 | instance of an inlined instance of a decl which is local to an inline | |
4193 | function, so we have to trace all of the way back through the origin chain | |
4194 | to find out what sort of node actually served as the original seed for the | |
4195 | given block. */ | |
a3f97cbb | 4196 | |
3f76745e JM |
4197 | static tree |
4198 | decl_ultimate_origin (decl) | |
4199 | register tree decl; | |
a3f97cbb | 4200 | { |
10a11b75 JM |
4201 | /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the |
4202 | nodes in the function to point to themselves; ignore that if | |
4203 | we're trying to output the abstract instance of this function. */ | |
4204 | if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl) | |
4205 | return NULL_TREE; | |
4206 | ||
556273e0 | 4207 | #ifdef ENABLE_CHECKING |
02e24c7a MM |
4208 | if (DECL_FROM_INLINE (DECL_ORIGIN (decl))) |
4209 | /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the | |
4210 | most distant ancestor, this should never happen. */ | |
4211 | abort (); | |
4212 | #endif | |
3f76745e | 4213 | |
02e24c7a | 4214 | return DECL_ABSTRACT_ORIGIN (decl); |
a3f97cbb JW |
4215 | } |
4216 | ||
3f76745e JM |
4217 | /* Determine the "ultimate origin" of a block. The block may be an inlined |
4218 | instance of an inlined instance of a block which is local to an inline | |
4219 | function, so we have to trace all of the way back through the origin chain | |
4220 | to find out what sort of node actually served as the original seed for the | |
4221 | given block. */ | |
71dfc51f | 4222 | |
3f76745e JM |
4223 | static tree |
4224 | block_ultimate_origin (block) | |
4225 | register tree block; | |
a3f97cbb | 4226 | { |
3f76745e | 4227 | register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); |
71dfc51f | 4228 | |
10a11b75 JM |
4229 | /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the |
4230 | nodes in the function to point to themselves; ignore that if | |
4231 | we're trying to output the abstract instance of this function. */ | |
4232 | if (BLOCK_ABSTRACT (block) && immediate_origin == block) | |
4233 | return NULL_TREE; | |
4234 | ||
3f76745e JM |
4235 | if (immediate_origin == NULL_TREE) |
4236 | return NULL_TREE; | |
4237 | else | |
4238 | { | |
4239 | register tree ret_val; | |
4240 | register tree lookahead = immediate_origin; | |
71dfc51f | 4241 | |
3f76745e JM |
4242 | do |
4243 | { | |
4244 | ret_val = lookahead; | |
4245 | lookahead = (TREE_CODE (ret_val) == BLOCK) | |
4246 | ? BLOCK_ABSTRACT_ORIGIN (ret_val) | |
4247 | : NULL; | |
4248 | } | |
4249 | while (lookahead != NULL && lookahead != ret_val); | |
4250 | ||
4251 | return ret_val; | |
4252 | } | |
a3f97cbb JW |
4253 | } |
4254 | ||
3f76745e JM |
4255 | /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT |
4256 | of a virtual function may refer to a base class, so we check the 'this' | |
4257 | parameter. */ | |
71dfc51f | 4258 | |
3f76745e JM |
4259 | static tree |
4260 | decl_class_context (decl) | |
4261 | tree decl; | |
a3f97cbb | 4262 | { |
3f76745e | 4263 | tree context = NULL_TREE; |
71dfc51f | 4264 | |
3f76745e JM |
4265 | if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl)) |
4266 | context = DECL_CONTEXT (decl); | |
4267 | else | |
4268 | context = TYPE_MAIN_VARIANT | |
4269 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
71dfc51f | 4270 | |
2f939d94 | 4271 | if (context && !TYPE_P (context)) |
3f76745e JM |
4272 | context = NULL_TREE; |
4273 | ||
4274 | return context; | |
a3f97cbb JW |
4275 | } |
4276 | \f | |
a96c67ec | 4277 | /* Add an attribute/value pair to a DIE. We build the lists up in reverse |
881c6935 | 4278 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f RK |
4279 | |
4280 | static inline void | |
3f76745e JM |
4281 | add_dwarf_attr (die, attr) |
4282 | register dw_die_ref die; | |
4283 | register dw_attr_ref attr; | |
a3f97cbb | 4284 | { |
3f76745e | 4285 | if (die != NULL && attr != NULL) |
a3f97cbb | 4286 | { |
a96c67ec JM |
4287 | attr->dw_attr_next = die->die_attr; |
4288 | die->die_attr = attr; | |
a3f97cbb JW |
4289 | } |
4290 | } | |
4291 | ||
c6991660 | 4292 | static inline dw_val_class AT_class PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4293 | static inline dw_val_class |
4294 | AT_class (a) | |
4295 | dw_attr_ref a; | |
4296 | { | |
4297 | return a->dw_attr_val.val_class; | |
4298 | } | |
4299 | ||
3f76745e | 4300 | /* Add a flag value attribute to a DIE. */ |
71dfc51f | 4301 | |
3f76745e JM |
4302 | static inline void |
4303 | add_AT_flag (die, attr_kind, flag) | |
4304 | register dw_die_ref die; | |
4305 | register enum dwarf_attribute attr_kind; | |
4306 | register unsigned flag; | |
a3f97cbb | 4307 | { |
3f76745e | 4308 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4309 | |
3f76745e JM |
4310 | attr->dw_attr_next = NULL; |
4311 | attr->dw_attr = attr_kind; | |
4312 | attr->dw_attr_val.val_class = dw_val_class_flag; | |
4313 | attr->dw_attr_val.v.val_flag = flag; | |
4314 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4315 | } |
4316 | ||
c6991660 | 4317 | static inline unsigned AT_flag PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4318 | static inline unsigned |
4319 | AT_flag (a) | |
4320 | register dw_attr_ref a; | |
4321 | { | |
4322 | if (a && AT_class (a) == dw_val_class_flag) | |
4323 | return a->dw_attr_val.v.val_flag; | |
4324 | ||
40e8cc95 | 4325 | abort (); |
a96c67ec JM |
4326 | } |
4327 | ||
3f76745e | 4328 | /* Add a signed integer attribute value to a DIE. */ |
71dfc51f | 4329 | |
3f76745e JM |
4330 | static inline void |
4331 | add_AT_int (die, attr_kind, int_val) | |
4332 | register dw_die_ref die; | |
4333 | register enum dwarf_attribute attr_kind; | |
4334 | register long int int_val; | |
a3f97cbb | 4335 | { |
3f76745e JM |
4336 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
4337 | ||
4338 | attr->dw_attr_next = NULL; | |
4339 | attr->dw_attr = attr_kind; | |
4340 | attr->dw_attr_val.val_class = dw_val_class_const; | |
4341 | attr->dw_attr_val.v.val_int = int_val; | |
4342 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4343 | } |
4344 | ||
c6991660 | 4345 | static inline long int AT_int PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4346 | static inline long int |
4347 | AT_int (a) | |
4348 | register dw_attr_ref a; | |
4349 | { | |
4350 | if (a && AT_class (a) == dw_val_class_const) | |
4351 | return a->dw_attr_val.v.val_int; | |
4352 | ||
40e8cc95 | 4353 | abort (); |
a96c67ec JM |
4354 | } |
4355 | ||
3f76745e | 4356 | /* Add an unsigned integer attribute value to a DIE. */ |
71dfc51f | 4357 | |
3f76745e JM |
4358 | static inline void |
4359 | add_AT_unsigned (die, attr_kind, unsigned_val) | |
4360 | register dw_die_ref die; | |
4361 | register enum dwarf_attribute attr_kind; | |
4362 | register unsigned long unsigned_val; | |
a3f97cbb | 4363 | { |
3f76745e JM |
4364 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
4365 | ||
4366 | attr->dw_attr_next = NULL; | |
4367 | attr->dw_attr = attr_kind; | |
4368 | attr->dw_attr_val.val_class = dw_val_class_unsigned_const; | |
4369 | attr->dw_attr_val.v.val_unsigned = unsigned_val; | |
4370 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4371 | } |
71dfc51f | 4372 | |
c6991660 | 4373 | static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4374 | static inline unsigned long |
4375 | AT_unsigned (a) | |
4376 | register dw_attr_ref a; | |
4377 | { | |
4378 | if (a && AT_class (a) == dw_val_class_unsigned_const) | |
4379 | return a->dw_attr_val.v.val_unsigned; | |
4380 | ||
40e8cc95 | 4381 | abort (); |
a96c67ec JM |
4382 | } |
4383 | ||
3f76745e JM |
4384 | /* Add an unsigned double integer attribute value to a DIE. */ |
4385 | ||
4386 | static inline void | |
4387 | add_AT_long_long (die, attr_kind, val_hi, val_low) | |
a3f97cbb | 4388 | register dw_die_ref die; |
3f76745e JM |
4389 | register enum dwarf_attribute attr_kind; |
4390 | register unsigned long val_hi; | |
4391 | register unsigned long val_low; | |
a3f97cbb | 4392 | { |
3f76745e | 4393 | register 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_long_long; | |
4398 | attr->dw_attr_val.v.val_long_long.hi = val_hi; | |
4399 | attr->dw_attr_val.v.val_long_long.low = val_low; | |
4400 | add_dwarf_attr (die, attr); | |
4401 | } | |
71dfc51f | 4402 | |
3f76745e | 4403 | /* Add a floating point attribute value to a DIE and return it. */ |
71dfc51f | 4404 | |
3f76745e JM |
4405 | static inline void |
4406 | add_AT_float (die, attr_kind, length, array) | |
4407 | register dw_die_ref die; | |
4408 | register enum dwarf_attribute attr_kind; | |
4409 | register unsigned length; | |
4410 | register long *array; | |
4411 | { | |
4412 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
4413 | ||
4414 | attr->dw_attr_next = NULL; | |
4415 | attr->dw_attr = attr_kind; | |
4416 | attr->dw_attr_val.val_class = dw_val_class_float; | |
4417 | attr->dw_attr_val.v.val_float.length = length; | |
4418 | attr->dw_attr_val.v.val_float.array = array; | |
4419 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4420 | } |
4421 | ||
3f76745e | 4422 | /* Add a string attribute value to a DIE. */ |
71dfc51f | 4423 | |
3f76745e JM |
4424 | static inline void |
4425 | add_AT_string (die, attr_kind, str) | |
a3f97cbb | 4426 | register dw_die_ref die; |
3f76745e | 4427 | register enum dwarf_attribute attr_kind; |
d560ee52 | 4428 | register const char *str; |
a3f97cbb | 4429 | { |
3f76745e | 4430 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4431 | |
3f76745e JM |
4432 | attr->dw_attr_next = NULL; |
4433 | attr->dw_attr = attr_kind; | |
4434 | attr->dw_attr_val.val_class = dw_val_class_str; | |
4435 | attr->dw_attr_val.v.val_str = xstrdup (str); | |
4436 | add_dwarf_attr (die, attr); | |
4437 | } | |
71dfc51f | 4438 | |
c6991660 | 4439 | static inline const char *AT_string PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4440 | static inline const char * |
4441 | AT_string (a) | |
4442 | register dw_attr_ref a; | |
4443 | { | |
4444 | if (a && AT_class (a) == dw_val_class_str) | |
4445 | return a->dw_attr_val.v.val_str; | |
4446 | ||
40e8cc95 | 4447 | abort (); |
a96c67ec JM |
4448 | } |
4449 | ||
3f76745e | 4450 | /* Add a DIE reference attribute value to a DIE. */ |
71dfc51f | 4451 | |
3f76745e JM |
4452 | static inline void |
4453 | add_AT_die_ref (die, attr_kind, targ_die) | |
4454 | register dw_die_ref die; | |
4455 | register enum dwarf_attribute attr_kind; | |
4456 | register dw_die_ref targ_die; | |
4457 | { | |
4458 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 4459 | |
3f76745e JM |
4460 | attr->dw_attr_next = NULL; |
4461 | attr->dw_attr = attr_kind; | |
4462 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
881c6935 JM |
4463 | attr->dw_attr_val.v.val_die_ref.die = targ_die; |
4464 | attr->dw_attr_val.v.val_die_ref.external = 0; | |
3f76745e JM |
4465 | add_dwarf_attr (die, attr); |
4466 | } | |
b1ccbc24 | 4467 | |
c6991660 | 4468 | static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4469 | static inline dw_die_ref |
4470 | AT_ref (a) | |
4471 | register dw_attr_ref a; | |
4472 | { | |
4473 | if (a && AT_class (a) == dw_val_class_die_ref) | |
881c6935 | 4474 | return a->dw_attr_val.v.val_die_ref.die; |
a96c67ec | 4475 | |
40e8cc95 | 4476 | abort (); |
a96c67ec JM |
4477 | } |
4478 | ||
881c6935 JM |
4479 | static inline int AT_ref_external PARAMS ((dw_attr_ref)); |
4480 | static inline int | |
4481 | AT_ref_external (a) | |
4482 | register dw_attr_ref a; | |
4483 | { | |
4484 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4485 | return a->dw_attr_val.v.val_die_ref.external; | |
4486 | ||
4487 | return 0; | |
4488 | } | |
4489 | ||
4490 | static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int)); | |
4491 | static inline void | |
4492 | set_AT_ref_external (a, i) | |
4493 | register dw_attr_ref a; | |
4494 | int i; | |
4495 | { | |
4496 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4497 | a->dw_attr_val.v.val_die_ref.external = i; | |
4498 | else | |
4499 | abort (); | |
4500 | } | |
4501 | ||
3f76745e | 4502 | /* Add an FDE reference attribute value to a DIE. */ |
b1ccbc24 | 4503 | |
3f76745e JM |
4504 | static inline void |
4505 | add_AT_fde_ref (die, attr_kind, targ_fde) | |
4506 | register dw_die_ref die; | |
4507 | register enum dwarf_attribute attr_kind; | |
4508 | register unsigned targ_fde; | |
4509 | { | |
4510 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
b1ccbc24 | 4511 | |
3f76745e JM |
4512 | attr->dw_attr_next = NULL; |
4513 | attr->dw_attr = attr_kind; | |
4514 | attr->dw_attr_val.val_class = dw_val_class_fde_ref; | |
4515 | attr->dw_attr_val.v.val_fde_index = targ_fde; | |
4516 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4517 | } |
71dfc51f | 4518 | |
3f76745e | 4519 | /* Add a location description attribute value to a DIE. */ |
71dfc51f | 4520 | |
3f76745e JM |
4521 | static inline void |
4522 | add_AT_loc (die, attr_kind, loc) | |
4523 | register dw_die_ref die; | |
4524 | register enum dwarf_attribute attr_kind; | |
4525 | register dw_loc_descr_ref loc; | |
4526 | { | |
4527 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 4528 | |
3f76745e JM |
4529 | attr->dw_attr_next = NULL; |
4530 | attr->dw_attr = attr_kind; | |
4531 | attr->dw_attr_val.val_class = dw_val_class_loc; | |
4532 | attr->dw_attr_val.v.val_loc = loc; | |
4533 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4534 | } |
4535 | ||
c6991660 | 4536 | static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4537 | static inline dw_loc_descr_ref |
4538 | AT_loc (a) | |
4539 | register dw_attr_ref a; | |
4540 | { | |
4541 | if (a && AT_class (a) == dw_val_class_loc) | |
4542 | return a->dw_attr_val.v.val_loc; | |
4543 | ||
40e8cc95 | 4544 | abort (); |
a96c67ec JM |
4545 | } |
4546 | ||
63e46568 DB |
4547 | static inline void |
4548 | add_AT_loc_list (die, attr_kind, loc_list) | |
4549 | register dw_die_ref die; | |
4550 | register enum dwarf_attribute attr_kind; | |
4551 | register dw_loc_list_ref loc_list; | |
4552 | { | |
4553 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
4554 | ||
4555 | attr->dw_attr_next = NULL; | |
4556 | attr->dw_attr = attr_kind; | |
4557 | attr->dw_attr_val.val_class = dw_val_class_loc_list; | |
4558 | attr->dw_attr_val.v.val_loc_list = loc_list; | |
4559 | add_dwarf_attr (die, attr); | |
4560 | have_location_lists = 1; | |
4561 | } | |
4562 | ||
4563 | static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref)); | |
4564 | ||
4565 | static inline dw_loc_list_ref | |
4566 | AT_loc_list (a) | |
4567 | register dw_attr_ref a; | |
4568 | { | |
4569 | if (a && AT_class (a) == dw_val_class_loc_list) | |
4570 | return a->dw_attr_val.v.val_loc_list; | |
4571 | ||
4572 | abort (); | |
4573 | } | |
4574 | ||
3f76745e | 4575 | /* Add an address constant attribute value to a DIE. */ |
71dfc51f | 4576 | |
3f76745e JM |
4577 | static inline void |
4578 | add_AT_addr (die, attr_kind, addr) | |
4579 | register dw_die_ref die; | |
4580 | register enum dwarf_attribute attr_kind; | |
1865dbb5 | 4581 | rtx addr; |
a3f97cbb | 4582 | { |
3f76745e | 4583 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4584 | |
3f76745e JM |
4585 | attr->dw_attr_next = NULL; |
4586 | attr->dw_attr = attr_kind; | |
4587 | attr->dw_attr_val.val_class = dw_val_class_addr; | |
4588 | attr->dw_attr_val.v.val_addr = addr; | |
4589 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4590 | } |
4591 | ||
c6991660 | 4592 | static inline rtx AT_addr PARAMS ((dw_attr_ref)); |
1865dbb5 | 4593 | static inline rtx |
a96c67ec JM |
4594 | AT_addr (a) |
4595 | register dw_attr_ref a; | |
4596 | { | |
4597 | if (a && AT_class (a) == dw_val_class_addr) | |
4598 | return a->dw_attr_val.v.val_addr; | |
4599 | ||
40e8cc95 | 4600 | abort (); |
a96c67ec JM |
4601 | } |
4602 | ||
3f76745e | 4603 | /* Add a label identifier attribute value to a DIE. */ |
71dfc51f | 4604 | |
3f76745e JM |
4605 | static inline void |
4606 | add_AT_lbl_id (die, attr_kind, lbl_id) | |
4607 | register dw_die_ref die; | |
4608 | register enum dwarf_attribute attr_kind; | |
d3e3972c | 4609 | register const char *lbl_id; |
a3f97cbb | 4610 | { |
3f76745e | 4611 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4612 | |
3f76745e JM |
4613 | attr->dw_attr_next = NULL; |
4614 | attr->dw_attr = attr_kind; | |
4615 | attr->dw_attr_val.val_class = dw_val_class_lbl_id; | |
4616 | attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); | |
4617 | add_dwarf_attr (die, attr); | |
4618 | } | |
71dfc51f | 4619 | |
3f76745e JM |
4620 | /* Add a section offset attribute value to a DIE. */ |
4621 | ||
4622 | static inline void | |
8b790721 | 4623 | add_AT_lbl_offset (die, attr_kind, label) |
3f76745e JM |
4624 | register dw_die_ref die; |
4625 | register enum dwarf_attribute attr_kind; | |
d3e3972c | 4626 | register const char *label; |
3f76745e JM |
4627 | { |
4628 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 4629 | |
3f76745e JM |
4630 | attr->dw_attr_next = NULL; |
4631 | attr->dw_attr = attr_kind; | |
8b790721 | 4632 | attr->dw_attr_val.val_class = dw_val_class_lbl_offset; |
a96c67ec | 4633 | attr->dw_attr_val.v.val_lbl_id = xstrdup (label); |
3f76745e | 4634 | add_dwarf_attr (die, attr); |
a3f97cbb JW |
4635 | } |
4636 | ||
a20612aa RH |
4637 | /* Add an offset attribute value to a DIE. */ |
4638 | ||
4639 | static void | |
4640 | add_AT_offset (die, attr_kind, offset) | |
4641 | register dw_die_ref die; | |
4642 | register enum dwarf_attribute attr_kind; | |
4643 | register unsigned long offset; | |
4644 | { | |
4645 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
4646 | ||
4647 | attr->dw_attr_next = NULL; | |
4648 | attr->dw_attr = attr_kind; | |
4649 | attr->dw_attr_val.val_class = dw_val_class_offset; | |
4650 | attr->dw_attr_val.v.val_offset = offset; | |
4651 | add_dwarf_attr (die, attr); | |
4652 | } | |
4653 | ||
c6991660 | 4654 | static inline const char *AT_lbl PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4655 | static inline const char * |
4656 | AT_lbl (a) | |
4657 | register dw_attr_ref a; | |
a3f97cbb | 4658 | { |
a96c67ec JM |
4659 | if (a && (AT_class (a) == dw_val_class_lbl_id |
4660 | || AT_class (a) == dw_val_class_lbl_offset)) | |
4661 | return a->dw_attr_val.v.val_lbl_id; | |
71dfc51f | 4662 | |
40e8cc95 | 4663 | abort (); |
a3f97cbb JW |
4664 | } |
4665 | ||
3f76745e | 4666 | /* Get the attribute of type attr_kind. */ |
71dfc51f | 4667 | |
3f76745e JM |
4668 | static inline dw_attr_ref |
4669 | get_AT (die, attr_kind) | |
4670 | register dw_die_ref die; | |
4671 | register enum dwarf_attribute attr_kind; | |
f37230f0 | 4672 | { |
3f76745e JM |
4673 | register dw_attr_ref a; |
4674 | register dw_die_ref spec = NULL; | |
556273e0 | 4675 | |
3f76745e JM |
4676 | if (die != NULL) |
4677 | { | |
4678 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
4679 | { | |
4680 | if (a->dw_attr == attr_kind) | |
4681 | return a; | |
71dfc51f | 4682 | |
3f76745e JM |
4683 | if (a->dw_attr == DW_AT_specification |
4684 | || a->dw_attr == DW_AT_abstract_origin) | |
a96c67ec | 4685 | spec = AT_ref (a); |
3f76745e | 4686 | } |
71dfc51f | 4687 | |
3f76745e JM |
4688 | if (spec) |
4689 | return get_AT (spec, attr_kind); | |
4690 | } | |
4691 | ||
4692 | return NULL; | |
f37230f0 JM |
4693 | } |
4694 | ||
3f76745e JM |
4695 | /* Return the "low pc" attribute value, typically associated with |
4696 | a subprogram DIE. Return null if the "low pc" attribute is | |
4697 | either not prsent, or if it cannot be represented as an | |
4698 | assembler label identifier. */ | |
71dfc51f | 4699 | |
a96c67ec | 4700 | static inline const char * |
3f76745e JM |
4701 | get_AT_low_pc (die) |
4702 | register dw_die_ref die; | |
7e23cb16 | 4703 | { |
3f76745e | 4704 | register dw_attr_ref a = get_AT (die, DW_AT_low_pc); |
40e8cc95 | 4705 | return a ? AT_lbl (a) : NULL; |
7e23cb16 JM |
4706 | } |
4707 | ||
3f76745e JM |
4708 | /* Return the "high pc" attribute value, typically associated with |
4709 | a subprogram DIE. Return null if the "high pc" attribute is | |
4710 | either not prsent, or if it cannot be represented as an | |
4711 | assembler label identifier. */ | |
71dfc51f | 4712 | |
a96c67ec | 4713 | static inline const char * |
3f76745e | 4714 | get_AT_hi_pc (die) |
a3f97cbb JW |
4715 | register dw_die_ref die; |
4716 | { | |
3f76745e | 4717 | register dw_attr_ref a = get_AT (die, DW_AT_high_pc); |
40e8cc95 | 4718 | return a ? AT_lbl (a) : NULL; |
3f76745e JM |
4719 | } |
4720 | ||
4721 | /* Return the value of the string attribute designated by ATTR_KIND, or | |
4722 | NULL if it is not present. */ | |
71dfc51f | 4723 | |
a96c67ec | 4724 | static inline const char * |
3f76745e JM |
4725 | get_AT_string (die, attr_kind) |
4726 | register dw_die_ref die; | |
4727 | register enum dwarf_attribute attr_kind; | |
4728 | { | |
4729 | register dw_attr_ref a = get_AT (die, attr_kind); | |
40e8cc95 | 4730 | return a ? AT_string (a) : NULL; |
a3f97cbb JW |
4731 | } |
4732 | ||
3f76745e JM |
4733 | /* Return the value of the flag attribute designated by ATTR_KIND, or -1 |
4734 | if it is not present. */ | |
71dfc51f | 4735 | |
3f76745e JM |
4736 | static inline int |
4737 | get_AT_flag (die, attr_kind) | |
4738 | register dw_die_ref die; | |
4739 | register enum dwarf_attribute attr_kind; | |
a3f97cbb | 4740 | { |
3f76745e | 4741 | register dw_attr_ref a = get_AT (die, attr_kind); |
40e8cc95 | 4742 | return a ? AT_flag (a) : 0; |
a3f97cbb JW |
4743 | } |
4744 | ||
3f76745e JM |
4745 | /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0 |
4746 | if it is not present. */ | |
71dfc51f | 4747 | |
3f76745e JM |
4748 | static inline unsigned |
4749 | get_AT_unsigned (die, attr_kind) | |
4750 | register dw_die_ref die; | |
4751 | register enum dwarf_attribute attr_kind; | |
a3f97cbb | 4752 | { |
3f76745e | 4753 | register dw_attr_ref a = get_AT (die, attr_kind); |
40e8cc95 | 4754 | return a ? AT_unsigned (a) : 0; |
a96c67ec | 4755 | } |
71dfc51f | 4756 | |
a96c67ec JM |
4757 | static inline dw_die_ref |
4758 | get_AT_ref (die, attr_kind) | |
4759 | dw_die_ref die; | |
4760 | register enum dwarf_attribute attr_kind; | |
4761 | { | |
4762 | register dw_attr_ref a = get_AT (die, attr_kind); | |
40e8cc95 | 4763 | return a ? AT_ref (a) : NULL; |
3f76745e | 4764 | } |
71dfc51f | 4765 | |
3f76745e JM |
4766 | static inline int |
4767 | is_c_family () | |
4768 | { | |
4769 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
71dfc51f | 4770 | |
3f76745e JM |
4771 | return (lang == DW_LANG_C || lang == DW_LANG_C89 |
4772 | || lang == DW_LANG_C_plus_plus); | |
556273e0 | 4773 | } |
71dfc51f | 4774 | |
3f76745e JM |
4775 | static inline int |
4776 | is_fortran () | |
4777 | { | |
4778 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
71dfc51f | 4779 | |
3f76745e | 4780 | return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90); |
556273e0 | 4781 | } |
71dfc51f | 4782 | |
28985b81 AG |
4783 | static inline int |
4784 | is_java () | |
4785 | { | |
4786 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
4787 | ||
4788 | return (lang == DW_LANG_Java); | |
4789 | } | |
4790 | ||
10a11b75 | 4791 | /* Free up the memory used by A. */ |
71dfc51f | 4792 | |
c6991660 | 4793 | static inline void free_AT PARAMS ((dw_attr_ref)); |
3f76745e | 4794 | static inline void |
10a11b75 JM |
4795 | free_AT (a) |
4796 | dw_attr_ref a; | |
4797 | { | |
4798 | switch (AT_class (a)) | |
4799 | { | |
10a11b75 JM |
4800 | case dw_val_class_str: |
4801 | case dw_val_class_lbl_id: | |
4802 | case dw_val_class_lbl_offset: | |
4803 | free (a->dw_attr_val.v.val_str); | |
4804 | break; | |
4805 | ||
3724ec07 WC |
4806 | case dw_val_class_float: |
4807 | free (a->dw_attr_val.v.val_float.array); | |
4808 | break; | |
0b34cf1e | 4809 | |
10a11b75 JM |
4810 | default: |
4811 | break; | |
4812 | } | |
4813 | ||
4814 | free (a); | |
556273e0 | 4815 | } |
10a11b75 JM |
4816 | |
4817 | /* Remove the specified attribute if present. */ | |
4818 | ||
4819 | static void | |
3f76745e JM |
4820 | remove_AT (die, attr_kind) |
4821 | register dw_die_ref die; | |
4822 | register enum dwarf_attribute attr_kind; | |
4823 | { | |
a96c67ec | 4824 | register dw_attr_ref *p; |
6d649d26 | 4825 | register dw_attr_ref removed = NULL; |
a3f97cbb | 4826 | |
3f76745e JM |
4827 | if (die != NULL) |
4828 | { | |
a96c67ec JM |
4829 | for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next)) |
4830 | if ((*p)->dw_attr == attr_kind) | |
4831 | { | |
4832 | removed = *p; | |
4833 | *p = (*p)->dw_attr_next; | |
4834 | break; | |
4835 | } | |
71dfc51f | 4836 | |
a96c67ec | 4837 | if (removed != 0) |
10a11b75 JM |
4838 | free_AT (removed); |
4839 | } | |
4840 | } | |
71dfc51f | 4841 | |
10a11b75 | 4842 | /* Free up the memory used by DIE. */ |
71dfc51f | 4843 | |
c6991660 | 4844 | static inline void free_die PARAMS ((dw_die_ref)); |
10a11b75 JM |
4845 | static inline void |
4846 | free_die (die) | |
4847 | dw_die_ref die; | |
4848 | { | |
4849 | remove_children (die); | |
4850 | free (die); | |
3f76745e | 4851 | } |
71dfc51f | 4852 | |
3f76745e | 4853 | /* Discard the children of this DIE. */ |
71dfc51f | 4854 | |
10a11b75 | 4855 | static void |
3f76745e JM |
4856 | remove_children (die) |
4857 | register dw_die_ref die; | |
4858 | { | |
4859 | register dw_die_ref child_die = die->die_child; | |
4860 | ||
4861 | die->die_child = NULL; | |
3f76745e JM |
4862 | |
4863 | while (child_die != NULL) | |
a3f97cbb | 4864 | { |
3f76745e JM |
4865 | register dw_die_ref tmp_die = child_die; |
4866 | register dw_attr_ref a; | |
71dfc51f | 4867 | |
3f76745e | 4868 | child_die = child_die->die_sib; |
556273e0 KH |
4869 | |
4870 | for (a = tmp_die->die_attr; a != NULL;) | |
a3f97cbb | 4871 | { |
3f76745e | 4872 | register dw_attr_ref tmp_a = a; |
71dfc51f | 4873 | |
3f76745e | 4874 | a = a->dw_attr_next; |
10a11b75 | 4875 | free_AT (tmp_a); |
a3f97cbb | 4876 | } |
71dfc51f | 4877 | |
10a11b75 | 4878 | free_die (tmp_die); |
3f76745e JM |
4879 | } |
4880 | } | |
71dfc51f | 4881 | |
a96c67ec | 4882 | /* Add a child DIE below its parent. We build the lists up in reverse |
881c6935 | 4883 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f | 4884 | |
3f76745e JM |
4885 | static inline void |
4886 | add_child_die (die, child_die) | |
4887 | register dw_die_ref die; | |
4888 | register dw_die_ref child_die; | |
4889 | { | |
4890 | if (die != NULL && child_die != NULL) | |
e90b62db | 4891 | { |
3a88cbd1 JL |
4892 | if (die == child_die) |
4893 | abort (); | |
3f76745e | 4894 | child_die->die_parent = die; |
a96c67ec JM |
4895 | child_die->die_sib = die->die_child; |
4896 | die->die_child = child_die; | |
3f76745e JM |
4897 | } |
4898 | } | |
4899 | ||
2081603c JM |
4900 | /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT |
4901 | is the specification, to the front of PARENT's list of children. */ | |
10a11b75 JM |
4902 | |
4903 | static void | |
4904 | splice_child_die (parent, child) | |
4905 | dw_die_ref parent, child; | |
4906 | { | |
4907 | dw_die_ref *p; | |
4908 | ||
4909 | /* We want the declaration DIE from inside the class, not the | |
4910 | specification DIE at toplevel. */ | |
4911 | if (child->die_parent != parent) | |
2081603c JM |
4912 | { |
4913 | dw_die_ref tmp = get_AT_ref (child, DW_AT_specification); | |
4914 | if (tmp) | |
4915 | child = tmp; | |
4916 | } | |
10a11b75 | 4917 | |
2081603c JM |
4918 | if (child->die_parent != parent |
4919 | && child->die_parent != get_AT_ref (parent, DW_AT_specification)) | |
10a11b75 JM |
4920 | abort (); |
4921 | ||
5de0e8d4 | 4922 | for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib)) |
10a11b75 JM |
4923 | if (*p == child) |
4924 | { | |
4925 | *p = child->die_sib; | |
4926 | break; | |
4927 | } | |
4928 | ||
4929 | child->die_sib = parent->die_child; | |
4930 | parent->die_child = child; | |
4931 | } | |
4932 | ||
3f76745e JM |
4933 | /* Return a pointer to a newly created DIE node. */ |
4934 | ||
4935 | static inline dw_die_ref | |
4936 | new_die (tag_value, parent_die) | |
4937 | register enum dwarf_tag tag_value; | |
4938 | register dw_die_ref parent_die; | |
4939 | { | |
3f4907a6 | 4940 | register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node)); |
3f76745e JM |
4941 | |
4942 | die->die_tag = tag_value; | |
3f76745e JM |
4943 | |
4944 | if (parent_die != NULL) | |
4945 | add_child_die (parent_die, die); | |
4946 | else | |
ef76d03b JW |
4947 | { |
4948 | limbo_die_node *limbo_node; | |
4949 | ||
4950 | limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node)); | |
4951 | limbo_node->die = die; | |
4952 | limbo_node->next = limbo_die_list; | |
4953 | limbo_die_list = limbo_node; | |
4954 | } | |
71dfc51f | 4955 | |
3f76745e JM |
4956 | return die; |
4957 | } | |
71dfc51f | 4958 | |
3f76745e | 4959 | /* Return the DIE associated with the given type specifier. */ |
71dfc51f | 4960 | |
3f76745e JM |
4961 | static inline dw_die_ref |
4962 | lookup_type_die (type) | |
4963 | register tree type; | |
4964 | { | |
4061f623 BS |
4965 | if (TREE_CODE (type) == VECTOR_TYPE) |
4966 | type = TYPE_DEBUG_REPRESENTATION_TYPE (type); | |
3f76745e JM |
4967 | return (dw_die_ref) TYPE_SYMTAB_POINTER (type); |
4968 | } | |
e90b62db | 4969 | |
3f76745e | 4970 | /* Equate a DIE to a given type specifier. */ |
71dfc51f | 4971 | |
10a11b75 | 4972 | static inline void |
3f76745e JM |
4973 | equate_type_number_to_die (type, type_die) |
4974 | register tree type; | |
4975 | register dw_die_ref type_die; | |
4976 | { | |
4977 | TYPE_SYMTAB_POINTER (type) = (char *) type_die; | |
4978 | } | |
71dfc51f | 4979 | |
3f76745e | 4980 | /* Return the DIE associated with a given declaration. */ |
71dfc51f | 4981 | |
3f76745e JM |
4982 | static inline dw_die_ref |
4983 | lookup_decl_die (decl) | |
4984 | register tree decl; | |
4985 | { | |
4986 | register unsigned decl_id = DECL_UID (decl); | |
4987 | ||
4988 | return (decl_id < decl_die_table_in_use | |
4989 | ? decl_die_table[decl_id] : NULL); | |
a3f97cbb JW |
4990 | } |
4991 | ||
3f76745e | 4992 | /* Equate a DIE to a particular declaration. */ |
71dfc51f | 4993 | |
3f76745e JM |
4994 | static void |
4995 | equate_decl_number_to_die (decl, decl_die) | |
4996 | register tree decl; | |
4997 | register dw_die_ref decl_die; | |
a3f97cbb | 4998 | { |
3f76745e | 4999 | register unsigned decl_id = DECL_UID (decl); |
3f76745e | 5000 | register unsigned num_allocated; |
d291dd49 | 5001 | |
3f76745e | 5002 | if (decl_id >= decl_die_table_allocated) |
a3f97cbb | 5003 | { |
3f76745e JM |
5004 | num_allocated |
5005 | = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1) | |
5006 | / DECL_DIE_TABLE_INCREMENT) | |
5007 | * DECL_DIE_TABLE_INCREMENT; | |
5008 | ||
5009 | decl_die_table | |
5010 | = (dw_die_ref *) xrealloc (decl_die_table, | |
5011 | sizeof (dw_die_ref) * num_allocated); | |
5012 | ||
961192e1 | 5013 | memset ((char *) &decl_die_table[decl_die_table_allocated], 0, |
3f76745e JM |
5014 | (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref)); |
5015 | decl_die_table_allocated = num_allocated; | |
a3f97cbb | 5016 | } |
71dfc51f | 5017 | |
3f76745e JM |
5018 | if (decl_id >= decl_die_table_in_use) |
5019 | decl_die_table_in_use = (decl_id + 1); | |
5020 | ||
5021 | decl_die_table[decl_id] = decl_die; | |
a3f97cbb | 5022 | } |
3f76745e JM |
5023 | \f |
5024 | /* Keep track of the number of spaces used to indent the | |
5025 | output of the debugging routines that print the structure of | |
5026 | the DIE internal representation. */ | |
5027 | static int print_indent; | |
71dfc51f | 5028 | |
3f76745e JM |
5029 | /* Indent the line the number of spaces given by print_indent. */ |
5030 | ||
5031 | static inline void | |
5032 | print_spaces (outfile) | |
5033 | FILE *outfile; | |
5034 | { | |
5035 | fprintf (outfile, "%*s", print_indent, ""); | |
a3f97cbb JW |
5036 | } |
5037 | ||
956d6950 | 5038 | /* Print the information associated with a given DIE, and its children. |
3f76745e | 5039 | This routine is a debugging aid only. */ |
71dfc51f | 5040 | |
a3f97cbb | 5041 | static void |
3f76745e JM |
5042 | print_die (die, outfile) |
5043 | dw_die_ref die; | |
5044 | FILE *outfile; | |
a3f97cbb | 5045 | { |
3f76745e JM |
5046 | register dw_attr_ref a; |
5047 | register dw_die_ref c; | |
71dfc51f | 5048 | |
3f76745e | 5049 | print_spaces (outfile); |
2d8b0f3a | 5050 | fprintf (outfile, "DIE %4lu: %s\n", |
3f76745e JM |
5051 | die->die_offset, dwarf_tag_name (die->die_tag)); |
5052 | print_spaces (outfile); | |
2d8b0f3a JL |
5053 | fprintf (outfile, " abbrev id: %lu", die->die_abbrev); |
5054 | fprintf (outfile, " offset: %lu\n", die->die_offset); | |
3f76745e JM |
5055 | |
5056 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
a3f97cbb | 5057 | { |
3f76745e JM |
5058 | print_spaces (outfile); |
5059 | fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr)); | |
5060 | ||
a96c67ec | 5061 | switch (AT_class (a)) |
3f76745e JM |
5062 | { |
5063 | case dw_val_class_addr: | |
5064 | fprintf (outfile, "address"); | |
5065 | break; | |
a20612aa RH |
5066 | case dw_val_class_offset: |
5067 | fprintf (outfile, "offset"); | |
5068 | break; | |
3f76745e JM |
5069 | case dw_val_class_loc: |
5070 | fprintf (outfile, "location descriptor"); | |
5071 | break; | |
63e46568 | 5072 | case dw_val_class_loc_list: |
a20612aa RH |
5073 | fprintf (outfile, "location list -> label:%s", |
5074 | AT_loc_list (a)->ll_symbol); | |
63e46568 | 5075 | break; |
3f76745e | 5076 | case dw_val_class_const: |
a96c67ec | 5077 | fprintf (outfile, "%ld", AT_int (a)); |
3f76745e JM |
5078 | break; |
5079 | case dw_val_class_unsigned_const: | |
a96c67ec | 5080 | fprintf (outfile, "%lu", AT_unsigned (a)); |
3f76745e JM |
5081 | break; |
5082 | case dw_val_class_long_long: | |
2d8b0f3a | 5083 | fprintf (outfile, "constant (%lu,%lu)", |
556273e0 KH |
5084 | a->dw_attr_val.v.val_long_long.hi, |
5085 | a->dw_attr_val.v.val_long_long.low); | |
3f76745e JM |
5086 | break; |
5087 | case dw_val_class_float: | |
5088 | fprintf (outfile, "floating-point constant"); | |
5089 | break; | |
5090 | case dw_val_class_flag: | |
a96c67ec | 5091 | fprintf (outfile, "%u", AT_flag (a)); |
3f76745e JM |
5092 | break; |
5093 | case dw_val_class_die_ref: | |
a96c67ec | 5094 | if (AT_ref (a) != NULL) |
881c6935 | 5095 | { |
1bfb5f8f | 5096 | if (AT_ref (a)->die_symbol) |
881c6935 JM |
5097 | fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol); |
5098 | else | |
5099 | fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset); | |
5100 | } | |
3f76745e JM |
5101 | else |
5102 | fprintf (outfile, "die -> <null>"); | |
5103 | break; | |
5104 | case dw_val_class_lbl_id: | |
8b790721 | 5105 | case dw_val_class_lbl_offset: |
a96c67ec | 5106 | fprintf (outfile, "label: %s", AT_lbl (a)); |
3f76745e | 5107 | break; |
3f76745e | 5108 | case dw_val_class_str: |
a96c67ec JM |
5109 | if (AT_string (a) != NULL) |
5110 | fprintf (outfile, "\"%s\"", AT_string (a)); | |
3f76745e JM |
5111 | else |
5112 | fprintf (outfile, "<null>"); | |
5113 | break; | |
e9a25f70 JL |
5114 | default: |
5115 | break; | |
3f76745e JM |
5116 | } |
5117 | ||
5118 | fprintf (outfile, "\n"); | |
5119 | } | |
5120 | ||
5121 | if (die->die_child != NULL) | |
5122 | { | |
5123 | print_indent += 4; | |
5124 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5125 | print_die (c, outfile); | |
71dfc51f | 5126 | |
3f76745e | 5127 | print_indent -= 4; |
a3f97cbb | 5128 | } |
881c6935 JM |
5129 | if (print_indent == 0) |
5130 | fprintf (outfile, "\n"); | |
a3f97cbb JW |
5131 | } |
5132 | ||
3f76745e JM |
5133 | /* Print the contents of the source code line number correspondence table. |
5134 | This routine is a debugging aid only. */ | |
71dfc51f | 5135 | |
3f76745e JM |
5136 | static void |
5137 | print_dwarf_line_table (outfile) | |
5138 | FILE *outfile; | |
a3f97cbb | 5139 | { |
3f76745e JM |
5140 | register unsigned i; |
5141 | register dw_line_info_ref line_info; | |
5142 | ||
5143 | fprintf (outfile, "\n\nDWARF source line information\n"); | |
5144 | for (i = 1; i < line_info_table_in_use; ++i) | |
a3f97cbb | 5145 | { |
3f76745e JM |
5146 | line_info = &line_info_table[i]; |
5147 | fprintf (outfile, "%5d: ", i); | |
981975b6 | 5148 | fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]); |
2d8b0f3a | 5149 | fprintf (outfile, "%6ld", line_info->dw_line_num); |
3f76745e | 5150 | fprintf (outfile, "\n"); |
a3f97cbb | 5151 | } |
3f76745e JM |
5152 | |
5153 | fprintf (outfile, "\n\n"); | |
f37230f0 JM |
5154 | } |
5155 | ||
3f76745e JM |
5156 | /* Print the information collected for a given DIE. */ |
5157 | ||
5158 | void | |
5159 | debug_dwarf_die (die) | |
5160 | dw_die_ref die; | |
5161 | { | |
5162 | print_die (die, stderr); | |
5163 | } | |
5164 | ||
5165 | /* Print all DWARF information collected for the compilation unit. | |
5166 | This routine is a debugging aid only. */ | |
5167 | ||
5168 | void | |
5169 | debug_dwarf () | |
5170 | { | |
5171 | print_indent = 0; | |
5172 | print_die (comp_unit_die, stderr); | |
b2244e22 JW |
5173 | if (! DWARF2_ASM_LINE_DEBUG_INFO) |
5174 | print_dwarf_line_table (stderr); | |
3f76745e JM |
5175 | } |
5176 | \f | |
a96c67ec JM |
5177 | /* We build up the lists of children and attributes by pushing new ones |
5178 | onto the beginning of the list. Reverse the lists for DIE so that | |
5179 | they are in order of addition. */ | |
71dfc51f | 5180 | |
f37230f0 | 5181 | static void |
a96c67ec | 5182 | reverse_die_lists (die) |
3f76745e | 5183 | register dw_die_ref die; |
f37230f0 | 5184 | { |
a96c67ec JM |
5185 | register dw_die_ref c, cp, cn; |
5186 | register dw_attr_ref a, ap, an; | |
71dfc51f | 5187 | |
a96c67ec | 5188 | for (a = die->die_attr, ap = 0; a; a = an) |
7d9d8943 AM |
5189 | { |
5190 | an = a->dw_attr_next; | |
5191 | a->dw_attr_next = ap; | |
5192 | ap = a; | |
a3f97cbb | 5193 | } |
7d9d8943 | 5194 | die->die_attr = ap; |
3f76745e | 5195 | |
7d9d8943 AM |
5196 | for (c = die->die_child, cp = 0; c; c = cn) |
5197 | { | |
5198 | cn = c->die_sib; | |
5199 | c->die_sib = cp; | |
5200 | cp = c; | |
5201 | } | |
5202 | die->die_child = cp; | |
a3f97cbb JW |
5203 | } |
5204 | ||
881c6935 JM |
5205 | /* reverse_die_lists only reverses the single die you pass it. Since |
5206 | we used to reverse all dies in add_sibling_attributes, which runs | |
5207 | through all the dies, it would reverse all the dies. Now, however, | |
5208 | since we don't call reverse_die_lists in add_sibling_attributes, we | |
5209 | need a routine to recursively reverse all the dies. This is that | |
5210 | routine. */ | |
71dfc51f | 5211 | |
7d9d8943 | 5212 | static void |
881c6935 | 5213 | reverse_all_dies (die) |
7d9d8943 | 5214 | register dw_die_ref die; |
a3f97cbb | 5215 | { |
7d9d8943 | 5216 | register dw_die_ref c; |
71dfc51f | 5217 | |
7d9d8943 | 5218 | reverse_die_lists (die); |
3f76745e | 5219 | |
881c6935 JM |
5220 | for (c = die->die_child; c; c = c->die_sib) |
5221 | reverse_all_dies (c); | |
5222 | } | |
5223 | ||
5224 | /* Start a new compilation unit DIE for an include file. OLD_UNIT is | |
5225 | the CU for the enclosing include file, if any. BINCL_DIE is the | |
5226 | DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this | |
5227 | include file. */ | |
5228 | ||
5229 | static dw_die_ref | |
5230 | push_new_compile_unit (old_unit, bincl_die) | |
5231 | dw_die_ref old_unit, bincl_die; | |
5232 | { | |
5233 | const char *filename = get_AT_string (bincl_die, DW_AT_name); | |
5234 | dw_die_ref new_unit = gen_compile_unit_die (filename); | |
5235 | new_unit->die_sib = old_unit; | |
5236 | return new_unit; | |
5237 | } | |
5238 | ||
5239 | /* Close an include-file CU and reopen the enclosing one. */ | |
5240 | ||
5241 | static dw_die_ref | |
5242 | pop_compile_unit (old_unit) | |
5243 | dw_die_ref old_unit; | |
5244 | { | |
5245 | dw_die_ref new_unit = old_unit->die_sib; | |
5246 | old_unit->die_sib = NULL; | |
5247 | return new_unit; | |
5248 | } | |
5249 | ||
5250 | #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx) | |
5251 | #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx) | |
5252 | ||
5253 | /* Calculate the checksum of a location expression. */ | |
5254 | ||
5255 | static inline void | |
5256 | loc_checksum (loc, ctx) | |
5257 | dw_loc_descr_ref loc; | |
5258 | struct md5_ctx *ctx; | |
5259 | { | |
5260 | PROCESS (loc->dw_loc_opc); | |
5261 | PROCESS (loc->dw_loc_oprnd1); | |
5262 | PROCESS (loc->dw_loc_oprnd2); | |
5263 | } | |
5264 | ||
5265 | /* Calculate the checksum of an attribute. */ | |
5266 | ||
5267 | static void | |
5268 | attr_checksum (at, ctx) | |
5269 | dw_attr_ref at; | |
5270 | struct md5_ctx *ctx; | |
5271 | { | |
5272 | dw_loc_descr_ref loc; | |
5273 | rtx r; | |
5274 | ||
5275 | PROCESS (at->dw_attr); | |
5276 | ||
5277 | /* We don't care about differences in file numbering. */ | |
5f632b5e JM |
5278 | if (at->dw_attr == DW_AT_decl_file |
5279 | /* Or that this was compiled with a different compiler snapshot; if | |
5280 | the output is the same, that's what matters. */ | |
5281 | || at->dw_attr == DW_AT_producer) | |
881c6935 JM |
5282 | return; |
5283 | ||
5284 | switch (AT_class (at)) | |
5285 | { | |
5286 | case dw_val_class_const: | |
5287 | PROCESS (at->dw_attr_val.v.val_int); | |
5288 | break; | |
5289 | case dw_val_class_unsigned_const: | |
5290 | PROCESS (at->dw_attr_val.v.val_unsigned); | |
5291 | break; | |
5292 | case dw_val_class_long_long: | |
5293 | PROCESS (at->dw_attr_val.v.val_long_long); | |
5294 | break; | |
5295 | case dw_val_class_float: | |
5296 | PROCESS (at->dw_attr_val.v.val_float); | |
5297 | break; | |
5298 | case dw_val_class_flag: | |
5299 | PROCESS (at->dw_attr_val.v.val_flag); | |
5300 | break; | |
5301 | ||
5302 | case dw_val_class_str: | |
5303 | PROCESS_STRING (AT_string (at)); | |
5304 | break; | |
a20612aa | 5305 | |
881c6935 JM |
5306 | case dw_val_class_addr: |
5307 | r = AT_addr (at); | |
5308 | switch (GET_CODE (r)) | |
5309 | { | |
5310 | case SYMBOL_REF: | |
5311 | PROCESS_STRING (XSTR (r, 0)); | |
5312 | break; | |
5313 | ||
5314 | default: | |
5315 | abort (); | |
5316 | } | |
5317 | break; | |
5318 | ||
a20612aa RH |
5319 | case dw_val_class_offset: |
5320 | PROCESS (at->dw_attr_val.v.val_offset); | |
5321 | break; | |
5322 | ||
881c6935 JM |
5323 | case dw_val_class_loc: |
5324 | for (loc = AT_loc (at); loc; loc = loc->dw_loc_next) | |
5325 | loc_checksum (loc, ctx); | |
5326 | break; | |
5327 | ||
5328 | case dw_val_class_die_ref: | |
5329 | if (AT_ref (at)->die_offset) | |
5330 | PROCESS (AT_ref (at)->die_offset); | |
5331 | /* FIXME else use target die name or something. */ | |
5332 | ||
5333 | case dw_val_class_fde_ref: | |
5334 | case dw_val_class_lbl_id: | |
5335 | case dw_val_class_lbl_offset: | |
a20612aa | 5336 | break; |
881c6935 JM |
5337 | |
5338 | default: | |
5339 | break; | |
5340 | } | |
5341 | } | |
5342 | ||
5343 | /* Calculate the checksum of a DIE. */ | |
5344 | ||
5345 | static void | |
5346 | die_checksum (die, ctx) | |
5347 | dw_die_ref die; | |
5348 | struct md5_ctx *ctx; | |
5349 | { | |
5350 | dw_die_ref c; | |
5351 | dw_attr_ref a; | |
5352 | ||
5353 | PROCESS (die->die_tag); | |
5354 | ||
5355 | for (a = die->die_attr; a; a = a->dw_attr_next) | |
5356 | attr_checksum (a, ctx); | |
5357 | ||
5358 | for (c = die->die_child; c; c = c->die_sib) | |
5359 | die_checksum (c, ctx); | |
5360 | } | |
5361 | ||
5362 | #undef PROCESS | |
5363 | #undef PROCESS_STRING | |
5364 | ||
5365 | /* The prefix to attach to symbols on DIEs in the current comdat debug | |
5366 | info section. */ | |
5367 | static char *comdat_symbol_id; | |
5368 | ||
5369 | /* The index of the current symbol within the current comdat CU. */ | |
5370 | static unsigned int comdat_symbol_number; | |
5371 | ||
5372 | /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its | |
5373 | children, and set comdat_symbol_id accordingly. */ | |
5374 | ||
5375 | static void | |
5376 | compute_section_prefix (unit_die) | |
5377 | dw_die_ref unit_die; | |
5378 | { | |
0821bff7 | 5379 | char *name; |
881c6935 JM |
5380 | int i; |
5381 | unsigned char checksum[16]; | |
5382 | struct md5_ctx ctx; | |
5383 | ||
5384 | md5_init_ctx (&ctx); | |
5385 | die_checksum (unit_die, &ctx); | |
5386 | md5_finish_ctx (&ctx, checksum); | |
5387 | ||
0821bff7 AC |
5388 | { |
5389 | const char *p = lbasename (get_AT_string (unit_die, DW_AT_name)); | |
5390 | name = (char *) alloca (strlen (p) + 64); | |
5391 | sprintf (name, "%s.", p); | |
5392 | } | |
881c6935 JM |
5393 | |
5394 | clean_symbol_name (name); | |
5395 | ||
0821bff7 AC |
5396 | { |
5397 | char *p = name + strlen (name); | |
5398 | for (i = 0; i < 4; ++i) | |
5399 | { | |
5400 | sprintf (p, "%.2x", checksum[i]); | |
5401 | p += 2; | |
5402 | } | |
5403 | } | |
881c6935 JM |
5404 | |
5405 | comdat_symbol_id = unit_die->die_symbol = xstrdup (name); | |
5406 | comdat_symbol_number = 0; | |
5407 | } | |
5408 | ||
5409 | /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */ | |
5410 | ||
5411 | static int | |
5412 | is_type_die (die) | |
5413 | dw_die_ref die; | |
5414 | { | |
5415 | switch (die->die_tag) | |
5416 | { | |
5417 | case DW_TAG_array_type: | |
5418 | case DW_TAG_class_type: | |
5419 | case DW_TAG_enumeration_type: | |
5420 | case DW_TAG_pointer_type: | |
5421 | case DW_TAG_reference_type: | |
5422 | case DW_TAG_string_type: | |
5423 | case DW_TAG_structure_type: | |
5424 | case DW_TAG_subroutine_type: | |
5425 | case DW_TAG_union_type: | |
5426 | case DW_TAG_ptr_to_member_type: | |
5427 | case DW_TAG_set_type: | |
5428 | case DW_TAG_subrange_type: | |
5429 | case DW_TAG_base_type: | |
5430 | case DW_TAG_const_type: | |
5431 | case DW_TAG_file_type: | |
5432 | case DW_TAG_packed_type: | |
5433 | case DW_TAG_volatile_type: | |
5434 | return 1; | |
5435 | default: | |
5436 | return 0; | |
5437 | } | |
5438 | } | |
5439 | ||
5440 | /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU. | |
5441 | Basically, we want to choose the bits that are likely to be shared between | |
5442 | compilations (types) and leave out the bits that are specific to individual | |
5443 | compilations (functions). */ | |
5444 | ||
5445 | static int | |
5446 | is_comdat_die (c) | |
5447 | dw_die_ref c; | |
5448 | { | |
5449 | #if 1 | |
5450 | /* I think we want to leave base types and __vtbl_ptr_type in the | |
5451 | main CU, as we do for stabs. The advantage is a greater | |
5452 | likelihood of sharing between objects that don't include headers | |
5453 | in the same order (and therefore would put the base types in a | |
5454 | different comdat). jason 8/28/00 */ | |
5455 | if (c->die_tag == DW_TAG_base_type) | |
5456 | return 0; | |
5457 | ||
5458 | if (c->die_tag == DW_TAG_pointer_type | |
5459 | || c->die_tag == DW_TAG_reference_type | |
5460 | || c->die_tag == DW_TAG_const_type | |
5461 | || c->die_tag == DW_TAG_volatile_type) | |
5462 | { | |
5463 | dw_die_ref t = get_AT_ref (c, DW_AT_type); | |
5464 | return t ? is_comdat_die (t) : 0; | |
5465 | } | |
5466 | #endif | |
5467 | ||
5468 | return is_type_die (c); | |
5469 | } | |
5470 | ||
5471 | /* Returns 1 iff C is the sort of DIE that might be referred to from another | |
5472 | compilation unit. */ | |
5473 | ||
5474 | static int | |
5475 | is_symbol_die (c) | |
5476 | dw_die_ref c; | |
5477 | { | |
5478 | if (is_type_die (c)) | |
5479 | return 1; | |
63e46568 | 5480 | if (get_AT (c, DW_AT_declaration) |
881c6935 JM |
5481 | && ! get_AT (c, DW_AT_specification)) |
5482 | return 1; | |
5483 | return 0; | |
5484 | } | |
5485 | ||
5486 | static char * | |
63e46568 DB |
5487 | gen_internal_sym (prefix) |
5488 | const char *prefix; | |
881c6935 JM |
5489 | { |
5490 | char buf[256]; | |
5491 | static int label_num; | |
63e46568 | 5492 | ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++); |
881c6935 JM |
5493 | return xstrdup (buf); |
5494 | } | |
5495 | ||
5496 | /* Assign symbols to all worthy DIEs under DIE. */ | |
5497 | ||
5498 | static void | |
5499 | assign_symbol_names (die) | |
5500 | register dw_die_ref die; | |
5501 | { | |
5502 | register dw_die_ref c; | |
5503 | ||
5504 | if (is_symbol_die (die)) | |
5505 | { | |
5506 | if (comdat_symbol_id) | |
5507 | { | |
5508 | char *p = alloca (strlen (comdat_symbol_id) + 64); | |
5509 | sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX, | |
5510 | comdat_symbol_id, comdat_symbol_number++); | |
5511 | die->die_symbol = xstrdup (p); | |
5512 | } | |
5513 | else | |
63e46568 | 5514 | die->die_symbol = gen_internal_sym ("LDIE"); |
881c6935 JM |
5515 | } |
5516 | ||
5517 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5518 | assign_symbol_names (c); | |
5519 | } | |
5520 | ||
5521 | /* Traverse the DIE (which is always comp_unit_die), and set up | |
5522 | additional compilation units for each of the include files we see | |
5523 | bracketed by BINCL/EINCL. */ | |
5524 | ||
5525 | static void | |
5526 | break_out_includes (die) | |
5527 | register dw_die_ref die; | |
5528 | { | |
5529 | dw_die_ref *ptr; | |
5530 | register dw_die_ref unit = NULL; | |
5531 | limbo_die_node *node; | |
5532 | ||
5533 | for (ptr = &(die->die_child); *ptr; ) | |
5534 | { | |
5535 | register dw_die_ref c = *ptr; | |
5536 | ||
5537 | if (c->die_tag == DW_TAG_GNU_BINCL | |
5538 | || c->die_tag == DW_TAG_GNU_EINCL | |
5539 | || (unit && is_comdat_die (c))) | |
5540 | { | |
5541 | /* This DIE is for a secondary CU; remove it from the main one. */ | |
5542 | *ptr = c->die_sib; | |
5543 | ||
5544 | if (c->die_tag == DW_TAG_GNU_BINCL) | |
5545 | { | |
5546 | unit = push_new_compile_unit (unit, c); | |
5547 | free_die (c); | |
5548 | } | |
5549 | else if (c->die_tag == DW_TAG_GNU_EINCL) | |
5550 | { | |
5551 | unit = pop_compile_unit (unit); | |
5552 | free_die (c); | |
5553 | } | |
5554 | else | |
5555 | add_child_die (unit, c); | |
5556 | } | |
5557 | else | |
5558 | { | |
5559 | /* Leave this DIE in the main CU. */ | |
5560 | ptr = &(c->die_sib); | |
5561 | continue; | |
5562 | } | |
5563 | } | |
5564 | ||
5565 | #if 0 | |
5566 | /* We can only use this in debugging, since the frontend doesn't check | |
0b34cf1e | 5567 | to make sure that we leave every include file we enter. */ |
881c6935 JM |
5568 | if (unit != NULL) |
5569 | abort (); | |
5570 | #endif | |
5571 | ||
5572 | assign_symbol_names (die); | |
5573 | for (node = limbo_die_list; node; node = node->next) | |
5574 | { | |
5575 | compute_section_prefix (node->die); | |
5576 | assign_symbol_names (node->die); | |
5577 | } | |
5578 | } | |
5579 | ||
5580 | /* Traverse the DIE and add a sibling attribute if it may have the | |
5581 | effect of speeding up access to siblings. To save some space, | |
5582 | avoid generating sibling attributes for DIE's without children. */ | |
5583 | ||
5584 | static void | |
5585 | add_sibling_attributes (die) | |
5586 | register dw_die_ref die; | |
5587 | { | |
5588 | register dw_die_ref c; | |
5589 | ||
5590 | if (die->die_tag != DW_TAG_compile_unit | |
5591 | && die->die_sib && die->die_child != NULL) | |
7d9d8943 AM |
5592 | /* Add the sibling link to the front of the attribute list. */ |
5593 | add_AT_die_ref (die, DW_AT_sibling, die->die_sib); | |
5594 | ||
5595 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5596 | add_sibling_attributes (c); | |
5597 | } | |
5598 | ||
63e46568 DB |
5599 | /* Output all location lists for the DIE and it's children */ |
5600 | static void | |
5601 | output_location_lists (die) | |
5602 | register dw_die_ref die; | |
5603 | { | |
5604 | dw_die_ref c; | |
5605 | dw_attr_ref d_attr; | |
5606 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) | |
5607 | { | |
5608 | if (AT_class (d_attr) == dw_val_class_loc_list) | |
5609 | { | |
5610 | output_loc_list (AT_loc_list (d_attr)); | |
5611 | } | |
5612 | } | |
5613 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5614 | output_location_lists (c); | |
5615 | ||
5616 | } | |
7d9d8943 AM |
5617 | /* The format of each DIE (and its attribute value pairs) |
5618 | is encoded in an abbreviation table. This routine builds the | |
5619 | abbreviation table and assigns a unique abbreviation id for | |
5620 | each abbreviation entry. The children of each die are visited | |
5621 | recursively. */ | |
5622 | ||
5623 | static void | |
5624 | build_abbrev_table (die) | |
5625 | register dw_die_ref die; | |
5626 | { | |
5627 | register unsigned long abbrev_id; | |
ae0ed63a | 5628 | register unsigned int n_alloc; |
7d9d8943 AM |
5629 | register dw_die_ref c; |
5630 | register dw_attr_ref d_attr, a_attr; | |
881c6935 JM |
5631 | |
5632 | /* Scan the DIE references, and mark as external any that refer to | |
1bfb5f8f | 5633 | DIEs from other CUs (i.e. those which are not marked). */ |
881c6935 JM |
5634 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) |
5635 | { | |
5636 | if (AT_class (d_attr) == dw_val_class_die_ref | |
1bfb5f8f | 5637 | && AT_ref (d_attr)->die_mark == 0) |
881c6935 JM |
5638 | { |
5639 | if (AT_ref (d_attr)->die_symbol == 0) | |
5640 | abort (); | |
5641 | set_AT_ref_external (d_attr, 1); | |
5642 | } | |
5643 | } | |
5644 | ||
7d9d8943 AM |
5645 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
5646 | { | |
5647 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
5648 | ||
5649 | if (abbrev->die_tag == die->die_tag) | |
5650 | { | |
5651 | if ((abbrev->die_child != NULL) == (die->die_child != NULL)) | |
5652 | { | |
5653 | a_attr = abbrev->die_attr; | |
5654 | d_attr = die->die_attr; | |
5655 | ||
5656 | while (a_attr != NULL && d_attr != NULL) | |
5657 | { | |
5658 | if ((a_attr->dw_attr != d_attr->dw_attr) | |
5659 | || (value_format (a_attr) != value_format (d_attr))) | |
5660 | break; | |
5661 | ||
5662 | a_attr = a_attr->dw_attr_next; | |
5663 | d_attr = d_attr->dw_attr_next; | |
5664 | } | |
5665 | ||
5666 | if (a_attr == NULL && d_attr == NULL) | |
5667 | break; | |
5668 | } | |
5669 | } | |
5670 | } | |
5671 | ||
5672 | if (abbrev_id >= abbrev_die_table_in_use) | |
5673 | { | |
5674 | if (abbrev_die_table_in_use >= abbrev_die_table_allocated) | |
5675 | { | |
5676 | n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT; | |
556273e0 | 5677 | abbrev_die_table |
7d9d8943 AM |
5678 | = (dw_die_ref *) xrealloc (abbrev_die_table, |
5679 | sizeof (dw_die_ref) * n_alloc); | |
5680 | ||
961192e1 | 5681 | memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0, |
7d9d8943 AM |
5682 | (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref)); |
5683 | abbrev_die_table_allocated = n_alloc; | |
5684 | } | |
5685 | ||
5686 | ++abbrev_die_table_in_use; | |
5687 | abbrev_die_table[abbrev_id] = die; | |
5688 | } | |
5689 | ||
5690 | die->die_abbrev = abbrev_id; | |
5691 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5692 | build_abbrev_table (c); | |
5693 | } | |
5694 | \f | |
5695 | /* Return the size of a string, including the null byte. | |
5696 | ||
5697 | This used to treat backslashes as escapes, and hence they were not included | |
5698 | in the count. However, that conflicts with what ASM_OUTPUT_ASCII does, | |
5699 | which treats a backslash as a backslash, escaping it if necessary, and hence | |
5700 | we must include them in the count. */ | |
5701 | ||
5702 | static unsigned long | |
5703 | size_of_string (str) | |
5704 | register const char *str; | |
5705 | { | |
5706 | return strlen (str) + 1; | |
3f76745e JM |
5707 | } |
5708 | ||
5709 | /* Return the power-of-two number of bytes necessary to represent VALUE. */ | |
5710 | ||
5711 | static int | |
5712 | constant_size (value) | |
5713 | long unsigned value; | |
5714 | { | |
5715 | int log; | |
5716 | ||
5717 | if (value == 0) | |
5718 | log = 0; | |
a3f97cbb | 5719 | else |
3f76745e | 5720 | log = floor_log2 (value); |
71dfc51f | 5721 | |
3f76745e JM |
5722 | log = log / 8; |
5723 | log = 1 << (floor_log2 (log) + 1); | |
5724 | ||
5725 | return log; | |
a3f97cbb JW |
5726 | } |
5727 | ||
3f76745e JM |
5728 | /* Return the size of a DIE, as it is represented in the |
5729 | .debug_info section. */ | |
71dfc51f | 5730 | |
3f76745e JM |
5731 | static unsigned long |
5732 | size_of_die (die) | |
a3f97cbb JW |
5733 | register dw_die_ref die; |
5734 | { | |
3f76745e | 5735 | register unsigned long size = 0; |
a3f97cbb | 5736 | register dw_attr_ref a; |
71dfc51f | 5737 | |
3f76745e | 5738 | size += size_of_uleb128 (die->die_abbrev); |
a3f97cbb JW |
5739 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
5740 | { | |
a96c67ec | 5741 | switch (AT_class (a)) |
a3f97cbb JW |
5742 | { |
5743 | case dw_val_class_addr: | |
a1a4189d | 5744 | size += DWARF2_ADDR_SIZE; |
a3f97cbb | 5745 | break; |
a20612aa RH |
5746 | case dw_val_class_offset: |
5747 | size += DWARF_OFFSET_SIZE; | |
5748 | break; | |
a3f97cbb | 5749 | case dw_val_class_loc: |
3f76745e | 5750 | { |
a96c67ec | 5751 | register unsigned long lsize = size_of_locs (AT_loc (a)); |
71dfc51f | 5752 | |
3f76745e JM |
5753 | /* Block length. */ |
5754 | size += constant_size (lsize); | |
5755 | size += lsize; | |
5756 | } | |
a3f97cbb | 5757 | break; |
63e46568 DB |
5758 | case dw_val_class_loc_list: |
5759 | size += DWARF_OFFSET_SIZE; | |
5760 | break; | |
a3f97cbb | 5761 | case dw_val_class_const: |
25dd13ec | 5762 | size += size_of_sleb128 (AT_int (a)); |
a3f97cbb JW |
5763 | break; |
5764 | case dw_val_class_unsigned_const: | |
a96c67ec | 5765 | size += constant_size (AT_unsigned (a)); |
a3f97cbb | 5766 | break; |
469ac993 | 5767 | case dw_val_class_long_long: |
2e4b9b8c | 5768 | size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */ |
469ac993 JM |
5769 | break; |
5770 | case dw_val_class_float: | |
3f76745e | 5771 | size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */ |
a3f97cbb JW |
5772 | break; |
5773 | case dw_val_class_flag: | |
3f76745e | 5774 | size += 1; |
a3f97cbb JW |
5775 | break; |
5776 | case dw_val_class_die_ref: | |
3f76745e | 5777 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
5778 | break; |
5779 | case dw_val_class_fde_ref: | |
3f76745e | 5780 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
5781 | break; |
5782 | case dw_val_class_lbl_id: | |
a1a4189d | 5783 | size += DWARF2_ADDR_SIZE; |
3f76745e | 5784 | break; |
8b790721 | 5785 | case dw_val_class_lbl_offset: |
3f76745e JM |
5786 | size += DWARF_OFFSET_SIZE; |
5787 | break; | |
5788 | case dw_val_class_str: | |
a96c67ec | 5789 | size += size_of_string (AT_string (a)); |
3f76745e JM |
5790 | break; |
5791 | default: | |
5792 | abort (); | |
5793 | } | |
a3f97cbb | 5794 | } |
3f76745e JM |
5795 | |
5796 | return size; | |
a3f97cbb JW |
5797 | } |
5798 | ||
956d6950 | 5799 | /* Size the debugging information associated with a given DIE. |
3f76745e JM |
5800 | Visits the DIE's children recursively. Updates the global |
5801 | variable next_die_offset, on each time through. Uses the | |
956d6950 | 5802 | current value of next_die_offset to update the die_offset |
3f76745e | 5803 | field in each DIE. */ |
71dfc51f | 5804 | |
a3f97cbb | 5805 | static void |
3f76745e JM |
5806 | calc_die_sizes (die) |
5807 | dw_die_ref die; | |
a3f97cbb | 5808 | { |
3f76745e JM |
5809 | register dw_die_ref c; |
5810 | die->die_offset = next_die_offset; | |
5811 | next_die_offset += size_of_die (die); | |
71dfc51f | 5812 | |
3f76745e JM |
5813 | for (c = die->die_child; c != NULL; c = c->die_sib) |
5814 | calc_die_sizes (c); | |
71dfc51f | 5815 | |
3f76745e JM |
5816 | if (die->die_child != NULL) |
5817 | /* Count the null byte used to terminate sibling lists. */ | |
5818 | next_die_offset += 1; | |
a3f97cbb JW |
5819 | } |
5820 | ||
1bfb5f8f | 5821 | /* Set the marks for a die and its children. We do this so |
881c6935 | 5822 | that we know whether or not a reference needs to use FORM_ref_addr; only |
1bfb5f8f JM |
5823 | DIEs in the same CU will be marked. We used to clear out the offset |
5824 | and use that as the flag, but ran into ordering problems. */ | |
881c6935 JM |
5825 | |
5826 | static void | |
1bfb5f8f | 5827 | mark_dies (die) |
881c6935 JM |
5828 | dw_die_ref die; |
5829 | { | |
5830 | register dw_die_ref c; | |
1bfb5f8f JM |
5831 | die->die_mark = 1; |
5832 | for (c = die->die_child; c; c = c->die_sib) | |
5833 | mark_dies (c); | |
5834 | } | |
5835 | ||
5836 | /* Clear the marks for a die and its children. */ | |
5837 | ||
5838 | static void | |
5839 | unmark_dies (die) | |
5840 | dw_die_ref die; | |
5841 | { | |
5842 | register dw_die_ref c; | |
5843 | die->die_mark = 0; | |
881c6935 | 5844 | for (c = die->die_child; c; c = c->die_sib) |
1bfb5f8f | 5845 | unmark_dies (c); |
881c6935 JM |
5846 | } |
5847 | ||
3f76745e JM |
5848 | /* Return the size of the .debug_pubnames table generated for the |
5849 | compilation unit. */ | |
a94dbf2c | 5850 | |
3f76745e JM |
5851 | static unsigned long |
5852 | size_of_pubnames () | |
a94dbf2c | 5853 | { |
3f76745e JM |
5854 | register unsigned long size; |
5855 | register unsigned i; | |
469ac993 | 5856 | |
3f76745e JM |
5857 | size = DWARF_PUBNAMES_HEADER_SIZE; |
5858 | for (i = 0; i < pubname_table_in_use; ++i) | |
a94dbf2c | 5859 | { |
3f76745e JM |
5860 | register pubname_ref p = &pubname_table[i]; |
5861 | size += DWARF_OFFSET_SIZE + size_of_string (p->name); | |
a94dbf2c JM |
5862 | } |
5863 | ||
3f76745e JM |
5864 | size += DWARF_OFFSET_SIZE; |
5865 | return size; | |
a94dbf2c JM |
5866 | } |
5867 | ||
956d6950 | 5868 | /* Return the size of the information in the .debug_aranges section. */ |
469ac993 | 5869 | |
3f76745e JM |
5870 | static unsigned long |
5871 | size_of_aranges () | |
469ac993 | 5872 | { |
3f76745e | 5873 | register unsigned long size; |
469ac993 | 5874 | |
3f76745e | 5875 | size = DWARF_ARANGES_HEADER_SIZE; |
469ac993 | 5876 | |
3f76745e | 5877 | /* Count the address/length pair for this compilation unit. */ |
a1a4189d JB |
5878 | size += 2 * DWARF2_ADDR_SIZE; |
5879 | size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use; | |
469ac993 | 5880 | |
3f76745e | 5881 | /* Count the two zero words used to terminated the address range table. */ |
a1a4189d | 5882 | size += 2 * DWARF2_ADDR_SIZE; |
3f76745e JM |
5883 | return size; |
5884 | } | |
5885 | \f | |
5886 | /* Select the encoding of an attribute value. */ | |
5887 | ||
5888 | static enum dwarf_form | |
a96c67ec JM |
5889 | value_format (a) |
5890 | dw_attr_ref a; | |
3f76745e | 5891 | { |
a96c67ec | 5892 | switch (a->dw_attr_val.val_class) |
469ac993 | 5893 | { |
3f76745e JM |
5894 | case dw_val_class_addr: |
5895 | return DW_FORM_addr; | |
a20612aa RH |
5896 | case dw_val_class_offset: |
5897 | if (DWARF_OFFSET_SIZE == 4) | |
5898 | return DW_FORM_data4; | |
5899 | if (DWARF_OFFSET_SIZE == 8) | |
5900 | return DW_FORM_data8; | |
5901 | abort (); | |
63e46568 | 5902 | case dw_val_class_loc_list: |
9d2f2c45 RH |
5903 | /* FIXME: Could be DW_FORM_data8, with a > 32 bit size |
5904 | .debug_loc section */ | |
5905 | return DW_FORM_data4; | |
3f76745e | 5906 | case dw_val_class_loc: |
a96c67ec | 5907 | switch (constant_size (size_of_locs (AT_loc (a)))) |
469ac993 | 5908 | { |
3f76745e JM |
5909 | case 1: |
5910 | return DW_FORM_block1; | |
5911 | case 2: | |
5912 | return DW_FORM_block2; | |
469ac993 JM |
5913 | default: |
5914 | abort (); | |
5915 | } | |
3f76745e | 5916 | case dw_val_class_const: |
25dd13ec | 5917 | return DW_FORM_sdata; |
3f76745e | 5918 | case dw_val_class_unsigned_const: |
a96c67ec | 5919 | switch (constant_size (AT_unsigned (a))) |
3f76745e JM |
5920 | { |
5921 | case 1: | |
5922 | return DW_FORM_data1; | |
5923 | case 2: | |
5924 | return DW_FORM_data2; | |
5925 | case 4: | |
5926 | return DW_FORM_data4; | |
5927 | case 8: | |
5928 | return DW_FORM_data8; | |
5929 | default: | |
5930 | abort (); | |
5931 | } | |
5932 | case dw_val_class_long_long: | |
5933 | return DW_FORM_block1; | |
5934 | case dw_val_class_float: | |
5935 | return DW_FORM_block1; | |
5936 | case dw_val_class_flag: | |
5937 | return DW_FORM_flag; | |
5938 | case dw_val_class_die_ref: | |
881c6935 JM |
5939 | if (AT_ref_external (a)) |
5940 | return DW_FORM_ref_addr; | |
5941 | else | |
5942 | return DW_FORM_ref; | |
3f76745e JM |
5943 | case dw_val_class_fde_ref: |
5944 | return DW_FORM_data; | |
5945 | case dw_val_class_lbl_id: | |
5946 | return DW_FORM_addr; | |
8b790721 | 5947 | case dw_val_class_lbl_offset: |
3f76745e JM |
5948 | return DW_FORM_data; |
5949 | case dw_val_class_str: | |
5950 | return DW_FORM_string; | |
a20612aa | 5951 | |
469ac993 JM |
5952 | default: |
5953 | abort (); | |
5954 | } | |
a94dbf2c JM |
5955 | } |
5956 | ||
3f76745e | 5957 | /* Output the encoding of an attribute value. */ |
469ac993 | 5958 | |
3f76745e | 5959 | static void |
a96c67ec JM |
5960 | output_value_format (a) |
5961 | dw_attr_ref a; | |
a94dbf2c | 5962 | { |
a96c67ec | 5963 | enum dwarf_form form = value_format (a); |
2e4b9b8c | 5964 | dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form)); |
3f76745e | 5965 | } |
469ac993 | 5966 | |
3f76745e JM |
5967 | /* Output the .debug_abbrev section which defines the DIE abbreviation |
5968 | table. */ | |
469ac993 | 5969 | |
3f76745e JM |
5970 | static void |
5971 | output_abbrev_section () | |
5972 | { | |
5973 | unsigned long abbrev_id; | |
71dfc51f | 5974 | |
3f76745e JM |
5975 | dw_attr_ref a_attr; |
5976 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) | |
5977 | { | |
5978 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
71dfc51f | 5979 | |
2e4b9b8c | 5980 | dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)"); |
469ac993 | 5981 | |
2e4b9b8c RH |
5982 | dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)", |
5983 | dwarf_tag_name (abbrev->die_tag)); | |
71dfc51f | 5984 | |
2e4b9b8c RH |
5985 | if (abbrev->die_child != NULL) |
5986 | dw2_asm_output_data (1, DW_children_yes, "DW_children_yes"); | |
5987 | else | |
5988 | dw2_asm_output_data (1, DW_children_no, "DW_children_no"); | |
3f76745e JM |
5989 | |
5990 | for (a_attr = abbrev->die_attr; a_attr != NULL; | |
5991 | a_attr = a_attr->dw_attr_next) | |
5992 | { | |
2e4b9b8c RH |
5993 | dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)", |
5994 | dwarf_attr_name (a_attr->dw_attr)); | |
a96c67ec | 5995 | output_value_format (a_attr); |
469ac993 | 5996 | } |
469ac993 | 5997 | |
2e4b9b8c RH |
5998 | dw2_asm_output_data (1, 0, NULL); |
5999 | dw2_asm_output_data (1, 0, NULL); | |
469ac993 | 6000 | } |
81f374eb HPN |
6001 | |
6002 | /* Terminate the table. */ | |
2e4b9b8c | 6003 | dw2_asm_output_data (1, 0, NULL); |
a94dbf2c JM |
6004 | } |
6005 | ||
881c6935 JM |
6006 | /* Output a symbol we can use to refer to this DIE from another CU. */ |
6007 | ||
6008 | static inline void | |
6009 | output_die_symbol (die) | |
6010 | register dw_die_ref die; | |
6011 | { | |
6012 | char *sym = die->die_symbol; | |
6013 | ||
6014 | if (sym == 0) | |
6015 | return; | |
6016 | ||
6017 | if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0) | |
6018 | /* We make these global, not weak; if the target doesn't support | |
6019 | .linkonce, it doesn't support combining the sections, so debugging | |
6020 | will break. */ | |
6021 | ASM_GLOBALIZE_LABEL (asm_out_file, sym); | |
6022 | ASM_OUTPUT_LABEL (asm_out_file, sym); | |
6023 | } | |
6024 | ||
84a5b4f8 DB |
6025 | /* Return a new location list, given the begin and end range, and the |
6026 | expression. gensym tells us whether to generate a new internal | |
6027 | symbol for this location list node, which is done for the head of | |
30f7a378 | 6028 | the list only. */ |
84a5b4f8 DB |
6029 | static inline dw_loc_list_ref |
6030 | new_loc_list (expr, begin, end, section, gensym) | |
6031 | register dw_loc_descr_ref expr; | |
6032 | register const char *begin; | |
6033 | register const char *end; | |
6034 | register const char *section; | |
6035 | register unsigned gensym; | |
6036 | { | |
6037 | register dw_loc_list_ref retlist | |
6038 | = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node)); | |
6039 | retlist->begin = begin; | |
6040 | retlist->end = end; | |
6041 | retlist->expr = expr; | |
6042 | retlist->section = section; | |
6043 | if (gensym) | |
6044 | retlist->ll_symbol = gen_internal_sym ("LLST"); | |
6045 | return retlist; | |
6046 | } | |
6047 | ||
6048 | /* Add a location description expression to a location list */ | |
6049 | static inline void | |
6050 | add_loc_descr_to_loc_list (list_head, descr, begin, end, section) | |
6051 | register dw_loc_list_ref *list_head; | |
6052 | register dw_loc_descr_ref descr; | |
6053 | register const char *begin; | |
6054 | register const char *end; | |
6055 | register const char *section; | |
6056 | { | |
6057 | register dw_loc_list_ref *d; | |
6058 | ||
30f7a378 | 6059 | /* Find the end of the chain. */ |
84a5b4f8 DB |
6060 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) |
6061 | ; | |
6062 | /* Add a new location list node to the list */ | |
6063 | *d = new_loc_list (descr, begin, end, section, 0); | |
6064 | } | |
6065 | ||
63e46568 DB |
6066 | /* Output the location list given to us */ |
6067 | static void | |
6068 | output_loc_list (list_head) | |
6069 | register dw_loc_list_ref list_head; | |
6070 | { | |
84a5b4f8 | 6071 | register dw_loc_list_ref curr=list_head; |
63e46568 | 6072 | ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol); |
a20612aa RH |
6073 | |
6074 | /* ??? This shouldn't be needed now that we've forced the | |
6075 | compilation unit base address to zero when there is code | |
6076 | in more than one section. */ | |
63e46568 DB |
6077 | if (strcmp (curr->section, ".text") == 0) |
6078 | { | |
aafdcfcd NS |
6079 | /* dw2_asm_output_data will mask off any extra bits in the ~0. */ |
6080 | dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT)0, | |
6081 | "Location list base address specifier fake entry"); | |
6082 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section, | |
6083 | "Location list base address specifier base"); | |
63e46568 DB |
6084 | } |
6085 | for (curr = list_head; curr != NULL; curr=curr->dw_loc_next) | |
6086 | { | |
6087 | int size; | |
aafdcfcd NS |
6088 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section, |
6089 | "Location list begin address (%s)", | |
6090 | list_head->ll_symbol); | |
6091 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section, | |
6092 | "Location list end address (%s)", | |
6093 | list_head->ll_symbol); | |
63e46568 DB |
6094 | size = size_of_locs (curr->expr); |
6095 | ||
6096 | /* Output the block length for this list of location operations. */ | |
aafdcfcd NS |
6097 | dw2_asm_output_data (constant_size (size), size, "%s", |
6098 | "Location expression size"); | |
63e46568 DB |
6099 | |
6100 | output_loc_sequence (curr->expr); | |
6101 | } | |
aafdcfcd NS |
6102 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, |
6103 | "Location list terminator begin (%s)", | |
6104 | list_head->ll_symbol); | |
6105 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, | |
6106 | "Location list terminator end (%s)", | |
6107 | list_head->ll_symbol); | |
63e46568 | 6108 | } |
3f76745e JM |
6109 | /* Output the DIE and its attributes. Called recursively to generate |
6110 | the definitions of each child DIE. */ | |
71dfc51f | 6111 | |
a3f97cbb | 6112 | static void |
3f76745e JM |
6113 | output_die (die) |
6114 | register dw_die_ref die; | |
a3f97cbb | 6115 | { |
3f76745e JM |
6116 | register dw_attr_ref a; |
6117 | register dw_die_ref c; | |
3f76745e | 6118 | register unsigned long size; |
a94dbf2c | 6119 | |
881c6935 JM |
6120 | /* If someone in another CU might refer to us, set up a symbol for |
6121 | them to point to. */ | |
6122 | if (die->die_symbol) | |
6123 | output_die_symbol (die); | |
6124 | ||
2e4b9b8c RH |
6125 | dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)", |
6126 | die->die_offset, dwarf_tag_name (die->die_tag)); | |
a94dbf2c | 6127 | |
3f76745e | 6128 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
a3f97cbb | 6129 | { |
2e4b9b8c RH |
6130 | const char *name = dwarf_attr_name (a->dw_attr); |
6131 | ||
a96c67ec | 6132 | switch (AT_class (a)) |
3f76745e JM |
6133 | { |
6134 | case dw_val_class_addr: | |
2e4b9b8c | 6135 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name); |
3f76745e | 6136 | break; |
a3f97cbb | 6137 | |
a20612aa RH |
6138 | case dw_val_class_offset: |
6139 | dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset, | |
6140 | "%s", name); | |
6141 | break; | |
6142 | ||
3f76745e | 6143 | case dw_val_class_loc: |
a96c67ec | 6144 | size = size_of_locs (AT_loc (a)); |
71dfc51f | 6145 | |
3f76745e | 6146 | /* Output the block length for this list of location operations. */ |
2e4b9b8c | 6147 | dw2_asm_output_data (constant_size (size), size, "%s", name); |
71dfc51f | 6148 | |
7d9d8943 | 6149 | output_loc_sequence (AT_loc (a)); |
a3f97cbb | 6150 | break; |
3f76745e JM |
6151 | |
6152 | case dw_val_class_const: | |
25dd13ec JW |
6153 | /* ??? It would be slightly more efficient to use a scheme like is |
6154 | used for unsigned constants below, but gdb 4.x does not sign | |
6155 | extend. Gdb 5.x does sign extend. */ | |
2e4b9b8c | 6156 | dw2_asm_output_data_sleb128 (AT_int (a), "%s", name); |
a3f97cbb | 6157 | break; |
3f76745e JM |
6158 | |
6159 | case dw_val_class_unsigned_const: | |
2e4b9b8c RH |
6160 | dw2_asm_output_data (constant_size (AT_unsigned (a)), |
6161 | AT_unsigned (a), "%s", name); | |
a3f97cbb | 6162 | break; |
3f76745e JM |
6163 | |
6164 | case dw_val_class_long_long: | |
2e4b9b8c RH |
6165 | { |
6166 | unsigned HOST_WIDE_INT first, second; | |
3f76745e | 6167 | |
2e4b9b8c RH |
6168 | dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR, |
6169 | "%s", name); | |
556273e0 | 6170 | |
2e4b9b8c RH |
6171 | if (WORDS_BIG_ENDIAN) |
6172 | { | |
6173 | first = a->dw_attr_val.v.val_long_long.hi; | |
6174 | second = a->dw_attr_val.v.val_long_long.low; | |
6175 | } | |
6176 | else | |
6177 | { | |
6178 | first = a->dw_attr_val.v.val_long_long.low; | |
6179 | second = a->dw_attr_val.v.val_long_long.hi; | |
6180 | } | |
6181 | dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR, | |
6182 | first, "long long constant"); | |
6183 | dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR, | |
6184 | second, NULL); | |
6185 | } | |
a3f97cbb | 6186 | break; |
3f76745e JM |
6187 | |
6188 | case dw_val_class_float: | |
c84e2712 KG |
6189 | { |
6190 | register unsigned int i; | |
c84e2712 | 6191 | |
2e4b9b8c RH |
6192 | dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4, |
6193 | "%s", name); | |
c84e2712 | 6194 | |
2e4b9b8c RH |
6195 | for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i) |
6196 | dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i], | |
6197 | "fp constant word %u", i); | |
556273e0 | 6198 | break; |
c84e2712 | 6199 | } |
3f76745e JM |
6200 | |
6201 | case dw_val_class_flag: | |
2e4b9b8c | 6202 | dw2_asm_output_data (1, AT_flag (a), "%s", name); |
a3f97cbb | 6203 | break; |
a20612aa | 6204 | |
63e46568 DB |
6205 | case dw_val_class_loc_list: |
6206 | { | |
6207 | char *sym = AT_loc_list (a)->ll_symbol; | |
6208 | if (sym == 0) | |
6209 | abort(); | |
a20612aa RH |
6210 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, |
6211 | loc_section_label, "%s", name); | |
63e46568 DB |
6212 | } |
6213 | break; | |
a20612aa | 6214 | |
3f76745e | 6215 | case dw_val_class_die_ref: |
881c6935 | 6216 | if (AT_ref_external (a)) |
2e4b9b8c RH |
6217 | { |
6218 | char *sym = AT_ref (a)->die_symbol; | |
6219 | if (sym == 0) | |
6220 | abort (); | |
6221 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name); | |
6222 | } | |
3f4907a6 JM |
6223 | else if (AT_ref (a)->die_offset == 0) |
6224 | abort (); | |
881c6935 | 6225 | else |
2e4b9b8c RH |
6226 | dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset, |
6227 | "%s", name); | |
a3f97cbb | 6228 | break; |
3f76745e JM |
6229 | |
6230 | case dw_val_class_fde_ref: | |
a6ab3aad JM |
6231 | { |
6232 | char l1[20]; | |
2e4b9b8c RH |
6233 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL, |
6234 | a->dw_attr_val.v.val_fde_index * 2); | |
6235 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name); | |
a6ab3aad | 6236 | } |
a3f97cbb | 6237 | break; |
a3f97cbb | 6238 | |
3f76745e | 6239 | case dw_val_class_lbl_id: |
8e7fa2c8 | 6240 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 6241 | break; |
71dfc51f | 6242 | |
8b790721 | 6243 | case dw_val_class_lbl_offset: |
2e4b9b8c | 6244 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 6245 | break; |
a3f97cbb | 6246 | |
3f76745e | 6247 | case dw_val_class_str: |
2e4b9b8c | 6248 | dw2_asm_output_nstring (AT_string (a), -1, "%s", name); |
3f76745e | 6249 | break; |
b2932ae5 | 6250 | |
3f76745e JM |
6251 | default: |
6252 | abort (); | |
6253 | } | |
3f76745e | 6254 | } |
71dfc51f | 6255 | |
3f76745e JM |
6256 | for (c = die->die_child; c != NULL; c = c->die_sib) |
6257 | output_die (c); | |
71dfc51f | 6258 | |
3f76745e | 6259 | if (die->die_child != NULL) |
7e23cb16 | 6260 | { |
556273e0 | 6261 | /* Add null byte to terminate sibling list. */ |
2e4b9b8c RH |
6262 | dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx", |
6263 | die->die_offset); | |
7e23cb16 | 6264 | } |
3f76745e | 6265 | } |
71dfc51f | 6266 | |
3f76745e JM |
6267 | /* Output the compilation unit that appears at the beginning of the |
6268 | .debug_info section, and precedes the DIE descriptions. */ | |
71dfc51f | 6269 | |
3f76745e JM |
6270 | static void |
6271 | output_compilation_unit_header () | |
6272 | { | |
2e4b9b8c RH |
6273 | dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE, |
6274 | "Length of Compilation Unit Info"); | |
71dfc51f | 6275 | |
2e4b9b8c | 6276 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number"); |
71dfc51f | 6277 | |
2e4b9b8c RH |
6278 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label, |
6279 | "Offset Into Abbrev. Section"); | |
71dfc51f | 6280 | |
2e4b9b8c | 6281 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)"); |
a3f97cbb JW |
6282 | } |
6283 | ||
881c6935 JM |
6284 | /* Output the compilation unit DIE and its children. */ |
6285 | ||
6286 | static void | |
6287 | output_comp_unit (die) | |
6288 | dw_die_ref die; | |
6289 | { | |
ce1cc601 | 6290 | const char *secname; |
881c6935 | 6291 | |
db3c0315 MM |
6292 | /* Even if there are no children of this DIE, we must output the |
6293 | information about the compilation unit. Otherwise, on an empty | |
6294 | translation unit, we will generate a present, but empty, | |
6295 | .debug_info section. IRIX 6.5 `nm' will then complain when | |
6296 | examining the file. | |
6297 | ||
6298 | Mark all the DIEs in this CU so we know which get local refs. */ | |
1bfb5f8f JM |
6299 | mark_dies (die); |
6300 | ||
6301 | build_abbrev_table (die); | |
6302 | ||
881c6935 JM |
6303 | /* Initialize the beginning DIE offset - and calculate sizes/offsets. */ |
6304 | next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE; | |
6305 | calc_die_sizes (die); | |
6306 | ||
881c6935 JM |
6307 | if (die->die_symbol) |
6308 | { | |
ce1cc601 KG |
6309 | char *tmp = (char *) alloca (strlen (die->die_symbol) + 24); |
6310 | sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol); | |
6311 | secname = tmp; | |
881c6935 JM |
6312 | die->die_symbol = NULL; |
6313 | } | |
6314 | else | |
ce1cc601 | 6315 | secname = (const char *) DEBUG_INFO_SECTION; |
881c6935 JM |
6316 | |
6317 | /* Output debugging information. */ | |
715bdd29 | 6318 | named_section_flags (secname, SECTION_DEBUG); |
881c6935 JM |
6319 | output_compilation_unit_header (); |
6320 | output_die (die); | |
6321 | ||
1bfb5f8f JM |
6322 | /* Leave the marks on the main CU, so we can check them in |
6323 | output_pubnames. */ | |
881c6935 | 6324 | if (die->die_symbol) |
1bfb5f8f | 6325 | unmark_dies (die); |
881c6935 JM |
6326 | } |
6327 | ||
a1d7ffe3 JM |
6328 | /* The DWARF2 pubname for a nested thingy looks like "A::f". The output |
6329 | of decl_printable_name for C++ looks like "A::f(int)". Let's drop the | |
6330 | argument list, and maybe the scope. */ | |
6331 | ||
d560ee52 | 6332 | static const char * |
a1d7ffe3 JM |
6333 | dwarf2_name (decl, scope) |
6334 | tree decl; | |
6335 | int scope; | |
6336 | { | |
6337 | return (*decl_printable_name) (decl, scope ? 1 : 0); | |
6338 | } | |
6339 | ||
d291dd49 | 6340 | /* Add a new entry to .debug_pubnames if appropriate. */ |
71dfc51f | 6341 | |
d291dd49 JM |
6342 | static void |
6343 | add_pubname (decl, die) | |
6344 | tree decl; | |
6345 | dw_die_ref die; | |
6346 | { | |
6347 | pubname_ref p; | |
6348 | ||
6349 | if (! TREE_PUBLIC (decl)) | |
6350 | return; | |
6351 | ||
6352 | if (pubname_table_in_use == pubname_table_allocated) | |
6353 | { | |
6354 | pubname_table_allocated += PUBNAME_TABLE_INCREMENT; | |
6355 | pubname_table = (pubname_ref) xrealloc | |
6356 | (pubname_table, pubname_table_allocated * sizeof (pubname_entry)); | |
6357 | } | |
71dfc51f | 6358 | |
d291dd49 JM |
6359 | p = &pubname_table[pubname_table_in_use++]; |
6360 | p->die = die; | |
a1d7ffe3 JM |
6361 | |
6362 | p->name = xstrdup (dwarf2_name (decl, 1)); | |
d291dd49 JM |
6363 | } |
6364 | ||
a3f97cbb JW |
6365 | /* Output the public names table used to speed up access to externally |
6366 | visible names. For now, only generate entries for externally | |
6367 | visible procedures. */ | |
71dfc51f | 6368 | |
a3f97cbb JW |
6369 | static void |
6370 | output_pubnames () | |
6371 | { | |
d291dd49 | 6372 | register unsigned i; |
71dfc51f RK |
6373 | register unsigned long pubnames_length = size_of_pubnames (); |
6374 | ||
2e4b9b8c RH |
6375 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, |
6376 | "Length of Public Names Info"); | |
71dfc51f | 6377 | |
2e4b9b8c | 6378 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
71dfc51f | 6379 | |
2e4b9b8c RH |
6380 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
6381 | "Offset of Compilation Unit Info"); | |
71dfc51f | 6382 | |
2e4b9b8c RH |
6383 | dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset, |
6384 | "Compilation Unit Length"); | |
71dfc51f | 6385 | |
d291dd49 | 6386 | for (i = 0; i < pubname_table_in_use; ++i) |
a3f97cbb | 6387 | { |
d291dd49 | 6388 | register pubname_ref pub = &pubname_table[i]; |
71dfc51f | 6389 | |
881c6935 | 6390 | /* We shouldn't see pubnames for DIEs outside of the main CU. */ |
1bfb5f8f | 6391 | if (pub->die->die_mark == 0) |
881c6935 JM |
6392 | abort (); |
6393 | ||
2e4b9b8c RH |
6394 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset, |
6395 | "DIE offset"); | |
71dfc51f | 6396 | |
2e4b9b8c | 6397 | dw2_asm_output_nstring (pub->name, -1, "external name"); |
a3f97cbb | 6398 | } |
71dfc51f | 6399 | |
2e4b9b8c | 6400 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL); |
a3f97cbb JW |
6401 | } |
6402 | ||
d291dd49 | 6403 | /* Add a new entry to .debug_aranges if appropriate. */ |
71dfc51f | 6404 | |
d291dd49 JM |
6405 | static void |
6406 | add_arange (decl, die) | |
6407 | tree decl; | |
6408 | dw_die_ref die; | |
6409 | { | |
6410 | if (! DECL_SECTION_NAME (decl)) | |
6411 | return; | |
6412 | ||
6413 | if (arange_table_in_use == arange_table_allocated) | |
6414 | { | |
6415 | arange_table_allocated += ARANGE_TABLE_INCREMENT; | |
a20612aa RH |
6416 | arange_table = (dw_die_ref *) |
6417 | xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref)); | |
d291dd49 | 6418 | } |
71dfc51f | 6419 | |
d291dd49 JM |
6420 | arange_table[arange_table_in_use++] = die; |
6421 | } | |
6422 | ||
a3f97cbb JW |
6423 | /* Output the information that goes into the .debug_aranges table. |
6424 | Namely, define the beginning and ending address range of the | |
6425 | text section generated for this compilation unit. */ | |
71dfc51f | 6426 | |
a3f97cbb JW |
6427 | static void |
6428 | output_aranges () | |
6429 | { | |
d291dd49 | 6430 | register unsigned i; |
71dfc51f RK |
6431 | register unsigned long aranges_length = size_of_aranges (); |
6432 | ||
2e4b9b8c RH |
6433 | dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length, |
6434 | "Length of Address Ranges Info"); | |
71dfc51f | 6435 | |
2e4b9b8c | 6436 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
71dfc51f | 6437 | |
2e4b9b8c RH |
6438 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
6439 | "Offset of Compilation Unit Info"); | |
71dfc51f | 6440 | |
2e4b9b8c | 6441 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address"); |
71dfc51f | 6442 | |
2e4b9b8c | 6443 | dw2_asm_output_data (1, 0, "Size of Segment Descriptor"); |
71dfc51f | 6444 | |
262b6384 SC |
6445 | /* We need to align to twice the pointer size here. */ |
6446 | if (DWARF_ARANGES_PAD_SIZE) | |
6447 | { | |
2e4b9b8c RH |
6448 | /* Pad using a 2 byte words so that padding is correct for any |
6449 | pointer size. */ | |
6450 | dw2_asm_output_data (2, 0, "Pad to %d byte boundary", | |
6451 | 2 * DWARF2_ADDR_SIZE); | |
770ca8c6 | 6452 | for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2) |
2e4b9b8c | 6453 | dw2_asm_output_data (2, 0, NULL); |
262b6384 | 6454 | } |
71dfc51f | 6455 | |
8e7fa2c8 | 6456 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address"); |
2e4b9b8c RH |
6457 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label, |
6458 | text_section_label, "Length"); | |
71dfc51f | 6459 | |
d291dd49 JM |
6460 | for (i = 0; i < arange_table_in_use; ++i) |
6461 | { | |
e689ae67 | 6462 | dw_die_ref die = arange_table[i]; |
71dfc51f | 6463 | |
881c6935 | 6464 | /* We shouldn't see aranges for DIEs outside of the main CU. */ |
1bfb5f8f | 6465 | if (die->die_mark == 0) |
881c6935 JM |
6466 | abort (); |
6467 | ||
e689ae67 | 6468 | if (die->die_tag == DW_TAG_subprogram) |
2e4b9b8c | 6469 | { |
8e7fa2c8 | 6470 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die), |
2e4b9b8c RH |
6471 | "Address"); |
6472 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die), | |
6473 | get_AT_low_pc (die), "Length"); | |
6474 | } | |
d291dd49 | 6475 | else |
a1d7ffe3 | 6476 | { |
e689ae67 JM |
6477 | /* A static variable; extract the symbol from DW_AT_location. |
6478 | Note that this code isn't currently hit, as we only emit | |
6479 | aranges for functions (jason 9/23/99). */ | |
71dfc51f | 6480 | |
e689ae67 JM |
6481 | dw_attr_ref a = get_AT (die, DW_AT_location); |
6482 | dw_loc_descr_ref loc; | |
a96c67ec | 6483 | if (! a || AT_class (a) != dw_val_class_loc) |
e689ae67 JM |
6484 | abort (); |
6485 | ||
a96c67ec | 6486 | loc = AT_loc (a); |
e689ae67 JM |
6487 | if (loc->dw_loc_opc != DW_OP_addr) |
6488 | abort (); | |
6489 | ||
2e4b9b8c RH |
6490 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, |
6491 | loc->dw_loc_oprnd1.v.val_addr, "Address"); | |
6492 | dw2_asm_output_data (DWARF2_ADDR_SIZE, | |
6493 | get_AT_unsigned (die, DW_AT_byte_size), | |
6494 | "Length"); | |
a1d7ffe3 | 6495 | } |
d291dd49 | 6496 | } |
71dfc51f | 6497 | |
a3f97cbb | 6498 | /* Output the terminator words. */ |
2e4b9b8c RH |
6499 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); |
6500 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
a3f97cbb JW |
6501 | } |
6502 | ||
a20612aa RH |
6503 | /* Add a new entry to .debug_ranges. Return the offset at which it |
6504 | was placed. */ | |
6505 | ||
6506 | static unsigned int | |
6507 | add_ranges (block) | |
6508 | tree block; | |
6509 | { | |
6510 | unsigned int in_use = ranges_table_in_use; | |
6511 | ||
6512 | if (in_use == ranges_table_allocated) | |
6513 | { | |
6514 | ranges_table_allocated += RANGES_TABLE_INCREMENT; | |
6515 | ranges_table = (dw_ranges_ref) | |
6516 | xrealloc (ranges_table, (ranges_table_allocated | |
6517 | * sizeof (struct dw_ranges_struct))); | |
6518 | } | |
6519 | ||
6520 | ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0); | |
6521 | ranges_table_in_use = in_use + 1; | |
6522 | ||
6523 | return in_use * 2 * DWARF2_ADDR_SIZE; | |
6524 | } | |
6525 | ||
6526 | static void | |
6527 | output_ranges () | |
6528 | { | |
6529 | register unsigned i; | |
6530 | const char *start_fmt = "Offset 0x%x"; | |
6531 | const char *fmt = start_fmt; | |
6532 | ||
6533 | for (i = 0; i < ranges_table_in_use; ++i) | |
6534 | { | |
6535 | int block_num = ranges_table[i].block_num; | |
6536 | ||
6537 | if (block_num) | |
6538 | { | |
6539 | char blabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6540 | char elabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6541 | ||
6542 | ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num); | |
6543 | ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num); | |
6544 | ||
6545 | /* If all code is in the text section, then the compilation | |
6546 | unit base address defaults to DW_AT_low_pc, which is the | |
6547 | base of the text section. */ | |
6548 | if (separate_line_info_table_in_use == 0) | |
6549 | { | |
6550 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel, | |
6551 | text_section_label, | |
6552 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
6553 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel, | |
6554 | text_section_label, NULL); | |
6555 | } | |
6556 | /* Otherwise, we add a DW_AT_entry_pc attribute to force the | |
6557 | compilation unit base address to zero, which allows us to | |
6558 | use absolute addresses, and not worry about whether the | |
6559 | target supports cross-section arithmetic. */ | |
6560 | else | |
6561 | { | |
6562 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel, | |
6563 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
6564 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL); | |
6565 | } | |
6566 | ||
6567 | fmt = NULL; | |
6568 | } | |
6569 | else | |
6570 | { | |
6571 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
6572 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
6573 | fmt = start_fmt; | |
6574 | } | |
6575 | } | |
6576 | } | |
0b34cf1e UD |
6577 | |
6578 | /* Data structure containing information about input files. */ | |
6579 | struct file_info | |
6580 | { | |
6581 | char *path; /* Complete file name. */ | |
6582 | char *fname; /* File name part. */ | |
6583 | int length; /* Length of entire string. */ | |
6584 | int file_idx; /* Index in input file table. */ | |
6585 | int dir_idx; /* Index in directory table. */ | |
6586 | }; | |
6587 | ||
6588 | /* Data structure containing information about directories with source | |
6589 | files. */ | |
6590 | struct dir_info | |
6591 | { | |
6592 | char *path; /* Path including directory name. */ | |
6593 | int length; /* Path length. */ | |
6594 | int prefix; /* Index of directory entry which is a prefix. */ | |
0b34cf1e UD |
6595 | int count; /* Number of files in this directory. */ |
6596 | int dir_idx; /* Index of directory used as base. */ | |
6597 | int used; /* Used in the end? */ | |
6598 | }; | |
6599 | ||
6600 | /* Callback function for file_info comparison. We sort by looking at | |
6601 | the directories in the path. */ | |
6602 | static int | |
6603 | file_info_cmp (p1, p2) | |
6604 | const void *p1; | |
6605 | const void *p2; | |
6606 | { | |
6607 | const struct file_info *s1 = p1; | |
6608 | const struct file_info *s2 = p2; | |
6609 | unsigned char *cp1; | |
6610 | unsigned char *cp2; | |
6611 | ||
6612 | /* Take care of file names without directories. */ | |
6613 | if (s1->path == s1->fname) | |
6614 | return -1; | |
6615 | else if (s2->path == s2->fname) | |
6616 | return 1; | |
6617 | ||
6618 | cp1 = (unsigned char *) s1->path; | |
6619 | cp2 = (unsigned char *) s2->path; | |
6620 | ||
6621 | while (1) | |
6622 | { | |
6623 | ++cp1; | |
6624 | ++cp2; | |
6625 | /* Reached the end of the first path? */ | |
6626 | if (cp1 == (unsigned char *) s1->fname) | |
6627 | /* It doesn't really matter in which order files from the | |
6628 | same directory are sorted in. Therefore don't test for | |
6629 | the second path reaching the end. */ | |
6630 | return -1; | |
6631 | else if (cp2 == (unsigned char *) s2->fname) | |
6632 | return 1; | |
6633 | ||
6634 | /* Character of current path component the same? */ | |
6635 | if (*cp1 != *cp2) | |
6636 | return *cp1 - *cp2; | |
6637 | } | |
6638 | } | |
6639 | ||
6640 | /* Output the directory table and the file name table. We try to minimize | |
6641 | the total amount of memory needed. A heuristic is used to avoid large | |
6642 | slowdowns with many input files. */ | |
6643 | static void | |
6644 | output_file_names () | |
6645 | { | |
6646 | struct file_info *files; | |
6647 | struct dir_info *dirs; | |
6648 | int *saved; | |
6649 | int *savehere; | |
6650 | int *backmap; | |
6651 | int ndirs; | |
6652 | int idx_offset; | |
6653 | int i; | |
6654 | int idx; | |
6655 | ||
6656 | /* Allocate the various arrays we need. */ | |
981975b6 | 6657 | files = (struct file_info *) alloca (file_table.in_use |
0b34cf1e | 6658 | * sizeof (struct file_info)); |
981975b6 | 6659 | dirs = (struct dir_info *) alloca (file_table.in_use |
0b34cf1e UD |
6660 | * sizeof (struct dir_info)); |
6661 | ||
6662 | /* Sort the file names. */ | |
981975b6 | 6663 | for (i = 1; i < (int) file_table.in_use; ++i) |
0b34cf1e UD |
6664 | { |
6665 | char *f; | |
6666 | ||
6667 | /* Skip all leading "./". */ | |
981975b6 | 6668 | f = file_table.table[i]; |
0b34cf1e UD |
6669 | while (f[0] == '.' && f[1] == '/') |
6670 | f += 2; | |
6671 | ||
6672 | /* Create a new array entry. */ | |
6673 | files[i].path = f; | |
6674 | files[i].length = strlen (f); | |
6675 | files[i].file_idx = i; | |
6676 | ||
6677 | /* Search for the file name part. */ | |
6678 | f = strrchr (f, '/'); | |
6679 | files[i].fname = f == NULL ? files[i].path : f + 1; | |
6680 | } | |
981975b6 | 6681 | qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp); |
0b34cf1e UD |
6682 | |
6683 | /* Find all the different directories used. */ | |
6684 | dirs[0].path = files[1].path; | |
6685 | dirs[0].length = files[1].fname - files[1].path; | |
6686 | dirs[0].prefix = -1; | |
0b34cf1e UD |
6687 | dirs[0].count = 1; |
6688 | dirs[0].dir_idx = 0; | |
6689 | dirs[0].used = 0; | |
6690 | files[1].dir_idx = 0; | |
6691 | ndirs = 1; | |
6692 | ||
981975b6 | 6693 | for (i = 2; i < (int) file_table.in_use; ++i) |
0b34cf1e UD |
6694 | if (files[i].fname - files[i].path == dirs[ndirs - 1].length |
6695 | && memcmp (dirs[ndirs - 1].path, files[i].path, | |
6696 | dirs[ndirs - 1].length) == 0) | |
6697 | { | |
6698 | /* Same directory as last entry. */ | |
6699 | files[i].dir_idx = ndirs - 1; | |
0b34cf1e UD |
6700 | ++dirs[ndirs - 1].count; |
6701 | } | |
6702 | else | |
6703 | { | |
6704 | int j; | |
6705 | ||
6706 | /* This is a new directory. */ | |
6707 | dirs[ndirs].path = files[i].path; | |
6708 | dirs[ndirs].length = files[i].fname - files[i].path; | |
0b34cf1e UD |
6709 | dirs[ndirs].count = 1; |
6710 | dirs[ndirs].dir_idx = ndirs; | |
6711 | dirs[ndirs].used = 0; | |
6712 | files[i].dir_idx = ndirs; | |
6713 | ||
6714 | /* Search for a prefix. */ | |
981975b6 | 6715 | dirs[ndirs].prefix = -1; |
0b34cf1e | 6716 | for (j = 0; j < ndirs; ++j) |
981975b6 RH |
6717 | if (dirs[j].length < dirs[ndirs].length |
6718 | && dirs[j].length > 1 | |
6719 | && (dirs[ndirs].prefix == -1 | |
6720 | || dirs[j].length > dirs[dirs[ndirs].prefix].length) | |
6721 | && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0) | |
6722 | dirs[ndirs].prefix = j; | |
0b34cf1e UD |
6723 | |
6724 | ++ndirs; | |
6725 | } | |
6726 | ||
6727 | /* Now to the actual work. We have to find a subset of the | |
6728 | directories which allow expressing the file name using references | |
6729 | to the directory table with the least amount of characters. We | |
6730 | do not do an exhaustive search where we would have to check out | |
6731 | every combination of every single possible prefix. Instead we | |
6732 | use a heuristic which provides nearly optimal results in most | |
6733 | cases and never is much off. */ | |
6734 | saved = (int *) alloca (ndirs * sizeof (int)); | |
6735 | savehere = (int *) alloca (ndirs * sizeof (int)); | |
6736 | ||
6737 | memset (saved, '\0', ndirs * sizeof (saved[0])); | |
6738 | for (i = 0; i < ndirs; ++i) | |
6739 | { | |
6740 | int j; | |
6741 | int total; | |
6742 | ||
981975b6 | 6743 | /* We can always save some space for the current directory. But |
0b34cf1e UD |
6744 | this does not mean it will be enough to justify adding the |
6745 | directory. */ | |
6746 | savehere[i] = dirs[i].length; | |
6747 | total = (savehere[i] - saved[i]) * dirs[i].count; | |
6748 | ||
6749 | for (j = i + 1; j < ndirs; ++j) | |
6750 | { | |
6751 | savehere[j] = 0; | |
6752 | ||
6753 | if (saved[j] < dirs[i].length) | |
6754 | { | |
6755 | /* Determine whether the dirs[i] path is a prefix of the | |
6756 | dirs[j] path. */ | |
6757 | int k; | |
6758 | ||
981975b6 RH |
6759 | k = dirs[j].prefix; |
6760 | while (k != -1 && k != i) | |
6761 | k = dirs[k].prefix; | |
6762 | ||
6763 | if (k == i) | |
6764 | { | |
6765 | /* Yes it is. We can possibly safe some memory but | |
6766 | writing the filenames in dirs[j] relative to | |
6767 | dirs[i]. */ | |
6768 | savehere[j] = dirs[i].length; | |
6769 | total += (savehere[j] - saved[j]) * dirs[j].count; | |
6770 | } | |
0b34cf1e UD |
6771 | } |
6772 | } | |
6773 | ||
6774 | /* Check whether we can safe enough to justify adding the dirs[i] | |
6775 | directory. */ | |
6776 | if (total > dirs[i].length + 1) | |
6777 | { | |
981975b6 | 6778 | /* It's worthwhile adding. */ |
0b34cf1e UD |
6779 | for (j = i; j < ndirs; ++j) |
6780 | if (savehere[j] > 0) | |
6781 | { | |
6782 | /* Remember how much we saved for this directory so far. */ | |
6783 | saved[j] = savehere[j]; | |
6784 | ||
6785 | /* Remember the prefix directory. */ | |
6786 | dirs[j].dir_idx = i; | |
6787 | } | |
6788 | } | |
6789 | } | |
6790 | ||
981975b6 | 6791 | /* We have to emit them in the order they appear in the file_table |
0b34cf1e UD |
6792 | array since the index is used in the debug info generation. To |
6793 | do this efficiently we generate a back-mapping of the indices | |
6794 | first. */ | |
981975b6 RH |
6795 | backmap = (int *) alloca (file_table.in_use * sizeof (int)); |
6796 | for (i = 1; i < (int) file_table.in_use; ++i) | |
0b34cf1e UD |
6797 | { |
6798 | backmap[files[i].file_idx] = i; | |
6799 | /* Mark this directory as used. */ | |
6800 | dirs[dirs[files[i].dir_idx].dir_idx].used = 1; | |
6801 | } | |
6802 | ||
6803 | /* That was it. We are ready to emit the information. First the | |
6804 | directory name table. Here we have to make sure that the first | |
6805 | actually emitted directory name has the index one. Zero is | |
6806 | reserved for the current working directory. Make sure we do not | |
6807 | confuse these indices with the one for the constructed table | |
6808 | (even though most of the time they are identical). */ | |
6809 | idx = 1; | |
e57cabac | 6810 | idx_offset = dirs[0].length > 0 ? 1 : 0; |
0b34cf1e UD |
6811 | for (i = 1 - idx_offset; i < ndirs; ++i) |
6812 | if (dirs[i].used != 0) | |
6813 | { | |
6814 | dirs[i].used = idx++; | |
2e4b9b8c RH |
6815 | dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1, |
6816 | "Directory Entry: 0x%x", dirs[i].used); | |
0b34cf1e | 6817 | } |
2e4b9b8c RH |
6818 | dw2_asm_output_data (1, 0, "End directory table"); |
6819 | ||
0b34cf1e UD |
6820 | /* Correct the index for the current working directory entry if it |
6821 | exists. */ | |
6822 | if (idx_offset == 0) | |
6823 | dirs[0].used = 0; | |
0b34cf1e UD |
6824 | |
6825 | /* Now write all the file names. */ | |
981975b6 | 6826 | for (i = 1; i < (int) file_table.in_use; ++i) |
0b34cf1e UD |
6827 | { |
6828 | int file_idx = backmap[i]; | |
6829 | int dir_idx = dirs[files[file_idx].dir_idx].dir_idx; | |
6830 | ||
2e4b9b8c RH |
6831 | dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1, |
6832 | "File Entry: 0x%x", i); | |
0b34cf1e UD |
6833 | |
6834 | /* Include directory index. */ | |
2e4b9b8c | 6835 | dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL); |
0b34cf1e UD |
6836 | |
6837 | /* Modification time. */ | |
2e4b9b8c | 6838 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e UD |
6839 | |
6840 | /* File length in bytes. */ | |
2e4b9b8c | 6841 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e | 6842 | } |
2e4b9b8c | 6843 | dw2_asm_output_data (1, 0, "End file name table"); |
0b34cf1e UD |
6844 | } |
6845 | ||
6846 | ||
a3f97cbb | 6847 | /* Output the source line number correspondence information. This |
14a774a9 | 6848 | information goes into the .debug_line section. */ |
71dfc51f | 6849 | |
a3f97cbb JW |
6850 | static void |
6851 | output_line_info () | |
6852 | { | |
981975b6 | 6853 | char l1[20], l2[20], p1[20], p2[20]; |
a3f97cbb JW |
6854 | char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
6855 | char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6856 | register unsigned opc; | |
6857 | register unsigned n_op_args; | |
a3f97cbb JW |
6858 | register unsigned long lt_index; |
6859 | register unsigned long current_line; | |
6860 | register long line_offset; | |
6861 | register long line_delta; | |
6862 | register unsigned long current_file; | |
e90b62db | 6863 | register unsigned long function; |
71dfc51f | 6864 | |
2e4b9b8c RH |
6865 | ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0); |
6866 | ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0); | |
981975b6 RH |
6867 | ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0); |
6868 | ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0); | |
71dfc51f | 6869 | |
2e4b9b8c RH |
6870 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1, |
6871 | "Length of Source Line Info"); | |
6872 | ASM_OUTPUT_LABEL (asm_out_file, l1); | |
71dfc51f | 6873 | |
2e4b9b8c | 6874 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
71dfc51f | 6875 | |
981975b6 RH |
6876 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length"); |
6877 | ASM_OUTPUT_LABEL (asm_out_file, p1); | |
71dfc51f | 6878 | |
2e4b9b8c RH |
6879 | dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH, |
6880 | "Minimum Instruction Length"); | |
71dfc51f | 6881 | |
2e4b9b8c RH |
6882 | dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START, |
6883 | "Default is_stmt_start flag"); | |
71dfc51f | 6884 | |
2e4b9b8c RH |
6885 | dw2_asm_output_data (1, DWARF_LINE_BASE, |
6886 | "Line Base Value (Special Opcodes)"); | |
71dfc51f | 6887 | |
2e4b9b8c RH |
6888 | dw2_asm_output_data (1, DWARF_LINE_RANGE, |
6889 | "Line Range Value (Special Opcodes)"); | |
6890 | ||
6891 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE, | |
6892 | "Special Opcode Base"); | |
71dfc51f | 6893 | |
a3f97cbb JW |
6894 | for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc) |
6895 | { | |
6896 | switch (opc) | |
6897 | { | |
6898 | case DW_LNS_advance_pc: | |
6899 | case DW_LNS_advance_line: | |
6900 | case DW_LNS_set_file: | |
6901 | case DW_LNS_set_column: | |
6902 | case DW_LNS_fixed_advance_pc: | |
6903 | n_op_args = 1; | |
6904 | break; | |
6905 | default: | |
6906 | n_op_args = 0; | |
6907 | break; | |
6908 | } | |
2e4b9b8c RH |
6909 | |
6910 | dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args", | |
6911 | opc, n_op_args); | |
a3f97cbb | 6912 | } |
71dfc51f | 6913 | |
0b34cf1e UD |
6914 | /* Write out the information about the files we use. */ |
6915 | output_file_names (); | |
981975b6 | 6916 | ASM_OUTPUT_LABEL (asm_out_file, p2); |
a3f97cbb | 6917 | |
2f22d404 JM |
6918 | /* We used to set the address register to the first location in the text |
6919 | section here, but that didn't accomplish anything since we already | |
6920 | have a line note for the opening brace of the first function. */ | |
a3f97cbb JW |
6921 | |
6922 | /* Generate the line number to PC correspondence table, encoded as | |
6923 | a series of state machine operations. */ | |
6924 | current_file = 1; | |
6925 | current_line = 1; | |
8b790721 | 6926 | strcpy (prev_line_label, text_section_label); |
a3f97cbb JW |
6927 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) |
6928 | { | |
2f22d404 JM |
6929 | register dw_line_info_ref line_info = &line_info_table[lt_index]; |
6930 | ||
10a11b75 JM |
6931 | #if 0 |
6932 | /* Disable this optimization for now; GDB wants to see two line notes | |
6933 | at the beginning of a function so it can find the end of the | |
6934 | prologue. */ | |
6935 | ||
2f22d404 JM |
6936 | /* Don't emit anything for redundant notes. Just updating the |
6937 | address doesn't accomplish anything, because we already assume | |
6938 | that anything after the last address is this line. */ | |
6939 | if (line_info->dw_line_num == current_line | |
6940 | && line_info->dw_file_num == current_file) | |
6941 | continue; | |
10a11b75 | 6942 | #endif |
71dfc51f | 6943 | |
2e4b9b8c RH |
6944 | /* Emit debug info for the address of the current line. |
6945 | ||
6946 | Unfortunately, we have little choice here currently, and must always | |
6947 | use the most general form. Gcc does not know the address delta | |
6948 | itself, so we can't use DW_LNS_advance_pc. Many ports do have length | |
6949 | attributes which will give an upper bound on the address range. We | |
6950 | could perhaps use length attributes to determine when it is safe to | |
6951 | use DW_LNS_fixed_advance_pc. */ | |
6952 | ||
5c90448c | 6953 | ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index); |
f19a6894 JW |
6954 | if (0) |
6955 | { | |
6956 | /* This can handle deltas up to 0xffff. This takes 3 bytes. */ | |
2e4b9b8c RH |
6957 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
6958 | "DW_LNS_fixed_advance_pc"); | |
6959 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
6960 | } |
6961 | else | |
6962 | { | |
a1a4189d JB |
6963 | /* This can handle any delta. This takes |
6964 | 4+DWARF2_ADDR_SIZE bytes. */ | |
2e4b9b8c RH |
6965 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
6966 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
6967 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 6968 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 JW |
6969 | } |
6970 | strcpy (prev_line_label, line_label); | |
6971 | ||
6972 | /* Emit debug info for the source file of the current line, if | |
6973 | different from the previous line. */ | |
a3f97cbb JW |
6974 | if (line_info->dw_file_num != current_file) |
6975 | { | |
6976 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
6977 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
6978 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
981975b6 | 6979 | file_table.table[current_file]); |
a3f97cbb | 6980 | } |
71dfc51f | 6981 | |
f19a6894 JW |
6982 | /* Emit debug info for the current line number, choosing the encoding |
6983 | that uses the least amount of space. */ | |
2f22d404 | 6984 | if (line_info->dw_line_num != current_line) |
a3f97cbb | 6985 | { |
2f22d404 JM |
6986 | line_offset = line_info->dw_line_num - current_line; |
6987 | line_delta = line_offset - DWARF_LINE_BASE; | |
6988 | current_line = line_info->dw_line_num; | |
6989 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
6990 | { | |
6991 | /* This can handle deltas from -10 to 234, using the current | |
6992 | definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This | |
6993 | takes 1 byte. */ | |
2e4b9b8c RH |
6994 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, |
6995 | "line %lu", current_line); | |
2f22d404 JM |
6996 | } |
6997 | else | |
6998 | { | |
6999 | /* This can handle any delta. This takes at least 4 bytes, | |
7000 | depending on the value being encoded. */ | |
2e4b9b8c RH |
7001 | dw2_asm_output_data (1, DW_LNS_advance_line, |
7002 | "advance to line %lu", current_line); | |
7003 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
7004 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
2f22d404 | 7005 | } |
a94dbf2c JM |
7006 | } |
7007 | else | |
7008 | { | |
2f22d404 | 7009 | /* We still need to start a new row, so output a copy insn. */ |
2e4b9b8c | 7010 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); |
a3f97cbb | 7011 | } |
a3f97cbb JW |
7012 | } |
7013 | ||
f19a6894 JW |
7014 | /* Emit debug info for the address of the end of the function. */ |
7015 | if (0) | |
7016 | { | |
2e4b9b8c RH |
7017 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7018 | "DW_LNS_fixed_advance_pc"); | |
7019 | dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL); | |
f19a6894 JW |
7020 | } |
7021 | else | |
7022 | { | |
2e4b9b8c RH |
7023 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7024 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7025 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7026 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL); |
f19a6894 | 7027 | } |
bdb669cb | 7028 | |
2e4b9b8c RH |
7029 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
7030 | dw2_asm_output_data_uleb128 (1, NULL); | |
7031 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
7032 | |
7033 | function = 0; | |
7034 | current_file = 1; | |
7035 | current_line = 1; | |
556273e0 | 7036 | for (lt_index = 0; lt_index < separate_line_info_table_in_use;) |
e90b62db JM |
7037 | { |
7038 | register dw_separate_line_info_ref line_info | |
7039 | = &separate_line_info_table[lt_index]; | |
71dfc51f | 7040 | |
10a11b75 | 7041 | #if 0 |
2f22d404 JM |
7042 | /* Don't emit anything for redundant notes. */ |
7043 | if (line_info->dw_line_num == current_line | |
7044 | && line_info->dw_file_num == current_file | |
7045 | && line_info->function == function) | |
7046 | goto cont; | |
10a11b75 | 7047 | #endif |
2f22d404 | 7048 | |
f19a6894 JW |
7049 | /* Emit debug info for the address of the current line. If this is |
7050 | a new function, or the first line of a function, then we need | |
7051 | to handle it differently. */ | |
5c90448c JM |
7052 | ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL, |
7053 | lt_index); | |
e90b62db JM |
7054 | if (function != line_info->function) |
7055 | { | |
7056 | function = line_info->function; | |
71dfc51f | 7057 | |
e90b62db | 7058 | /* Set the address register to the first line in the function */ |
2e4b9b8c RH |
7059 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7060 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7061 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7062 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
e90b62db JM |
7063 | } |
7064 | else | |
7065 | { | |
f19a6894 JW |
7066 | /* ??? See the DW_LNS_advance_pc comment above. */ |
7067 | if (0) | |
7068 | { | |
2e4b9b8c RH |
7069 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7070 | "DW_LNS_fixed_advance_pc"); | |
7071 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7072 | } |
7073 | else | |
7074 | { | |
2e4b9b8c RH |
7075 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7076 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7077 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7078 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7079 | } |
e90b62db | 7080 | } |
f19a6894 | 7081 | strcpy (prev_line_label, line_label); |
71dfc51f | 7082 | |
f19a6894 JW |
7083 | /* Emit debug info for the source file of the current line, if |
7084 | different from the previous line. */ | |
e90b62db JM |
7085 | if (line_info->dw_file_num != current_file) |
7086 | { | |
7087 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
7088 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
7089 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
981975b6 | 7090 | file_table.table[current_file]); |
e90b62db | 7091 | } |
71dfc51f | 7092 | |
f19a6894 JW |
7093 | /* Emit debug info for the current line number, choosing the encoding |
7094 | that uses the least amount of space. */ | |
e90b62db JM |
7095 | if (line_info->dw_line_num != current_line) |
7096 | { | |
7097 | line_offset = line_info->dw_line_num - current_line; | |
7098 | line_delta = line_offset - DWARF_LINE_BASE; | |
7099 | current_line = line_info->dw_line_num; | |
7100 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
2e4b9b8c RH |
7101 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, |
7102 | "line %lu", current_line); | |
e90b62db JM |
7103 | else |
7104 | { | |
2e4b9b8c RH |
7105 | dw2_asm_output_data (1, DW_LNS_advance_line, |
7106 | "advance to line %lu", current_line); | |
7107 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
7108 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
e90b62db JM |
7109 | } |
7110 | } | |
2f22d404 | 7111 | else |
2e4b9b8c | 7112 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); |
71dfc51f | 7113 | |
10a11b75 | 7114 | #if 0 |
2f22d404 | 7115 | cont: |
10a11b75 | 7116 | #endif |
e90b62db | 7117 | ++lt_index; |
e90b62db JM |
7118 | |
7119 | /* If we're done with a function, end its sequence. */ | |
7120 | if (lt_index == separate_line_info_table_in_use | |
7121 | || separate_line_info_table[lt_index].function != function) | |
7122 | { | |
7123 | current_file = 1; | |
7124 | current_line = 1; | |
71dfc51f | 7125 | |
f19a6894 | 7126 | /* Emit debug info for the address of the end of the function. */ |
5c90448c | 7127 | ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function); |
f19a6894 JW |
7128 | if (0) |
7129 | { | |
2e4b9b8c RH |
7130 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7131 | "DW_LNS_fixed_advance_pc"); | |
7132 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7133 | } |
7134 | else | |
7135 | { | |
2e4b9b8c RH |
7136 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7137 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7138 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7139 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7140 | } |
e90b62db JM |
7141 | |
7142 | /* Output the marker for the end of this sequence. */ | |
2e4b9b8c RH |
7143 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
7144 | dw2_asm_output_data_uleb128 (1, NULL); | |
7145 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
7146 | } |
7147 | } | |
f19f17e0 JM |
7148 | |
7149 | /* Output the marker for the end of the line number info. */ | |
2e4b9b8c | 7150 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
a3f97cbb JW |
7151 | } |
7152 | \f | |
a3f97cbb JW |
7153 | /* Given a pointer to a tree node for some base type, return a pointer to |
7154 | a DIE that describes the given type. | |
7155 | ||
7156 | This routine must only be called for GCC type nodes that correspond to | |
7157 | Dwarf base (fundamental) types. */ | |
71dfc51f | 7158 | |
a3f97cbb JW |
7159 | static dw_die_ref |
7160 | base_type_die (type) | |
7161 | register tree type; | |
7162 | { | |
a9d38797 | 7163 | register dw_die_ref base_type_result; |
ec0ce6e2 | 7164 | register const char *type_name; |
a9d38797 | 7165 | register enum dwarf_type encoding; |
71dfc51f | 7166 | register tree name = TYPE_NAME (type); |
a3f97cbb | 7167 | |
a9d38797 JM |
7168 | if (TREE_CODE (type) == ERROR_MARK |
7169 | || TREE_CODE (type) == VOID_TYPE) | |
a3f97cbb JW |
7170 | return 0; |
7171 | ||
405f63da MM |
7172 | if (name) |
7173 | { | |
7174 | if (TREE_CODE (name) == TYPE_DECL) | |
7175 | name = DECL_NAME (name); | |
7176 | ||
7177 | type_name = IDENTIFIER_POINTER (name); | |
7178 | } | |
7179 | else | |
7180 | type_name = "__unknown__"; | |
a9d38797 | 7181 | |
a3f97cbb JW |
7182 | switch (TREE_CODE (type)) |
7183 | { | |
a3f97cbb | 7184 | case INTEGER_TYPE: |
a9d38797 | 7185 | /* Carefully distinguish the C character types, without messing |
a3f97cbb | 7186 | up if the language is not C. Note that we check only for the names |
556273e0 | 7187 | that contain spaces; other names might occur by coincidence in other |
a3f97cbb | 7188 | languages. */ |
a9d38797 JM |
7189 | if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE |
7190 | && (type == char_type_node | |
7191 | || ! strcmp (type_name, "signed char") | |
7192 | || ! strcmp (type_name, "unsigned char")))) | |
a3f97cbb | 7193 | { |
a9d38797 JM |
7194 | if (TREE_UNSIGNED (type)) |
7195 | encoding = DW_ATE_unsigned; | |
7196 | else | |
7197 | encoding = DW_ATE_signed; | |
7198 | break; | |
a3f97cbb | 7199 | } |
556273e0 | 7200 | /* else fall through. */ |
a3f97cbb | 7201 | |
a9d38797 JM |
7202 | case CHAR_TYPE: |
7203 | /* GNU Pascal/Ada CHAR type. Not used in C. */ | |
7204 | if (TREE_UNSIGNED (type)) | |
7205 | encoding = DW_ATE_unsigned_char; | |
7206 | else | |
7207 | encoding = DW_ATE_signed_char; | |
a3f97cbb JW |
7208 | break; |
7209 | ||
7210 | case REAL_TYPE: | |
a9d38797 | 7211 | encoding = DW_ATE_float; |
a3f97cbb JW |
7212 | break; |
7213 | ||
405f63da MM |
7214 | /* Dwarf2 doesn't know anything about complex ints, so use |
7215 | a user defined type for it. */ | |
a3f97cbb | 7216 | case COMPLEX_TYPE: |
405f63da MM |
7217 | if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE) |
7218 | encoding = DW_ATE_complex_float; | |
7219 | else | |
7220 | encoding = DW_ATE_lo_user; | |
a3f97cbb JW |
7221 | break; |
7222 | ||
7223 | case BOOLEAN_TYPE: | |
a9d38797 JM |
7224 | /* GNU FORTRAN/Ada/C++ BOOLEAN type. */ |
7225 | encoding = DW_ATE_boolean; | |
a3f97cbb JW |
7226 | break; |
7227 | ||
7228 | default: | |
a9d38797 | 7229 | abort (); /* No other TREE_CODEs are Dwarf fundamental types. */ |
a3f97cbb JW |
7230 | } |
7231 | ||
a9d38797 | 7232 | base_type_result = new_die (DW_TAG_base_type, comp_unit_die); |
14a774a9 RK |
7233 | if (demangle_name_func) |
7234 | type_name = (*demangle_name_func) (type_name); | |
7235 | ||
a9d38797 JM |
7236 | add_AT_string (base_type_result, DW_AT_name, type_name); |
7237 | add_AT_unsigned (base_type_result, DW_AT_byte_size, | |
4e5a8d7b | 7238 | int_size_in_bytes (type)); |
a9d38797 | 7239 | add_AT_unsigned (base_type_result, DW_AT_encoding, encoding); |
a3f97cbb JW |
7240 | |
7241 | return base_type_result; | |
7242 | } | |
7243 | ||
7244 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to | |
7245 | the Dwarf "root" type for the given input type. The Dwarf "root" type of | |
7246 | a given type is generally the same as the given type, except that if the | |
7247 | given type is a pointer or reference type, then the root type of the given | |
7248 | type is the root type of the "basis" type for the pointer or reference | |
7249 | type. (This definition of the "root" type is recursive.) Also, the root | |
7250 | type of a `const' qualified type or a `volatile' qualified type is the | |
7251 | root type of the given type without the qualifiers. */ | |
71dfc51f | 7252 | |
a3f97cbb JW |
7253 | static tree |
7254 | root_type (type) | |
7255 | register tree type; | |
7256 | { | |
7257 | if (TREE_CODE (type) == ERROR_MARK) | |
7258 | return error_mark_node; | |
7259 | ||
7260 | switch (TREE_CODE (type)) | |
7261 | { | |
7262 | case ERROR_MARK: | |
7263 | return error_mark_node; | |
7264 | ||
7265 | case POINTER_TYPE: | |
7266 | case REFERENCE_TYPE: | |
7267 | return type_main_variant (root_type (TREE_TYPE (type))); | |
7268 | ||
7269 | default: | |
7270 | return type_main_variant (type); | |
7271 | } | |
7272 | } | |
7273 | ||
7274 | /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the | |
7275 | given input type is a Dwarf "fundamental" type. Otherwise return null. */ | |
71dfc51f RK |
7276 | |
7277 | static inline int | |
a3f97cbb JW |
7278 | is_base_type (type) |
7279 | register tree type; | |
7280 | { | |
7281 | switch (TREE_CODE (type)) | |
7282 | { | |
7283 | case ERROR_MARK: | |
7284 | case VOID_TYPE: | |
7285 | case INTEGER_TYPE: | |
7286 | case REAL_TYPE: | |
7287 | case COMPLEX_TYPE: | |
7288 | case BOOLEAN_TYPE: | |
7289 | case CHAR_TYPE: | |
7290 | return 1; | |
7291 | ||
7292 | case SET_TYPE: | |
7293 | case ARRAY_TYPE: | |
7294 | case RECORD_TYPE: | |
7295 | case UNION_TYPE: | |
7296 | case QUAL_UNION_TYPE: | |
7297 | case ENUMERAL_TYPE: | |
7298 | case FUNCTION_TYPE: | |
7299 | case METHOD_TYPE: | |
7300 | case POINTER_TYPE: | |
7301 | case REFERENCE_TYPE: | |
7302 | case FILE_TYPE: | |
7303 | case OFFSET_TYPE: | |
7304 | case LANG_TYPE: | |
604bb87d | 7305 | case VECTOR_TYPE: |
a3f97cbb JW |
7306 | return 0; |
7307 | ||
7308 | default: | |
7309 | abort (); | |
7310 | } | |
71dfc51f | 7311 | |
a3f97cbb JW |
7312 | return 0; |
7313 | } | |
7314 | ||
7315 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging | |
7316 | entry that chains various modifiers in front of the given type. */ | |
71dfc51f | 7317 | |
a3f97cbb JW |
7318 | static dw_die_ref |
7319 | modified_type_die (type, is_const_type, is_volatile_type, context_die) | |
7320 | register tree type; | |
7321 | register int is_const_type; | |
7322 | register int is_volatile_type; | |
7323 | register dw_die_ref context_die; | |
7324 | { | |
7325 | register enum tree_code code = TREE_CODE (type); | |
7326 | register dw_die_ref mod_type_die = NULL; | |
7327 | register dw_die_ref sub_die = NULL; | |
dfcf9891 | 7328 | register tree item_type = NULL; |
a3f97cbb JW |
7329 | |
7330 | if (code != ERROR_MARK) | |
7331 | { | |
5101b304 MM |
7332 | tree qualified_type; |
7333 | ||
7334 | /* See if we already have the appropriately qualified variant of | |
7335 | this type. */ | |
7336 | qualified_type | |
7337 | = get_qualified_type (type, | |
7338 | ((is_const_type ? TYPE_QUAL_CONST : 0) | |
7339 | | (is_volatile_type | |
7340 | ? TYPE_QUAL_VOLATILE : 0))); | |
7341 | /* If we do, then we can just use its DIE, if it exists. */ | |
7342 | if (qualified_type) | |
7343 | { | |
7344 | mod_type_die = lookup_type_die (qualified_type); | |
7345 | if (mod_type_die) | |
7346 | return mod_type_die; | |
7347 | } | |
bdb669cb | 7348 | |
556273e0 | 7349 | /* Handle C typedef types. */ |
5101b304 MM |
7350 | if (qualified_type && TYPE_NAME (qualified_type) |
7351 | && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL | |
7352 | && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type))) | |
a94dbf2c | 7353 | { |
5101b304 MM |
7354 | tree type_name = TYPE_NAME (qualified_type); |
7355 | tree dtype = TREE_TYPE (type_name); | |
7356 | if (qualified_type == dtype) | |
a94dbf2c JM |
7357 | { |
7358 | /* For a named type, use the typedef. */ | |
5101b304 MM |
7359 | gen_type_die (qualified_type, context_die); |
7360 | mod_type_die = lookup_type_die (qualified_type); | |
a94dbf2c | 7361 | } |
71dfc51f | 7362 | |
a94dbf2c JM |
7363 | else if (is_const_type < TYPE_READONLY (dtype) |
7364 | || is_volatile_type < TYPE_VOLATILE (dtype)) | |
7365 | /* cv-unqualified version of named type. Just use the unnamed | |
7366 | type to which it refers. */ | |
71dfc51f | 7367 | mod_type_die |
5101b304 | 7368 | = modified_type_die (DECL_ORIGINAL_TYPE (type_name), |
71dfc51f RK |
7369 | is_const_type, is_volatile_type, |
7370 | context_die); | |
7371 | /* Else cv-qualified version of named type; fall through. */ | |
a94dbf2c JM |
7372 | } |
7373 | ||
7374 | if (mod_type_die) | |
556273e0 KH |
7375 | /* OK. */ |
7376 | ; | |
a94dbf2c | 7377 | else if (is_const_type) |
a3f97cbb | 7378 | { |
ab72d377 | 7379 | mod_type_die = new_die (DW_TAG_const_type, comp_unit_die); |
a9d38797 | 7380 | sub_die = modified_type_die (type, 0, is_volatile_type, context_die); |
a3f97cbb JW |
7381 | } |
7382 | else if (is_volatile_type) | |
7383 | { | |
ab72d377 | 7384 | mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die); |
a9d38797 | 7385 | sub_die = modified_type_die (type, 0, 0, context_die); |
a3f97cbb JW |
7386 | } |
7387 | else if (code == POINTER_TYPE) | |
7388 | { | |
ab72d377 | 7389 | mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die); |
a3f97cbb | 7390 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 7391 | #if 0 |
a3f97cbb | 7392 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
61b32c02 | 7393 | #endif |
a3f97cbb | 7394 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
7395 | } |
7396 | else if (code == REFERENCE_TYPE) | |
7397 | { | |
ab72d377 | 7398 | mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die); |
a3f97cbb | 7399 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 7400 | #if 0 |
a3f97cbb | 7401 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
556273e0 | 7402 | #endif |
a3f97cbb | 7403 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
7404 | } |
7405 | else if (is_base_type (type)) | |
71dfc51f | 7406 | mod_type_die = base_type_die (type); |
a3f97cbb JW |
7407 | else |
7408 | { | |
4b674448 JM |
7409 | gen_type_die (type, context_die); |
7410 | ||
a3f97cbb JW |
7411 | /* We have to get the type_main_variant here (and pass that to the |
7412 | `lookup_type_die' routine) because the ..._TYPE node we have | |
7413 | might simply be a *copy* of some original type node (where the | |
7414 | copy was created to help us keep track of typedef names) and | |
7415 | that copy might have a different TYPE_UID from the original | |
a94dbf2c | 7416 | ..._TYPE node. */ |
a3f97cbb | 7417 | mod_type_die = lookup_type_die (type_main_variant (type)); |
3a88cbd1 JL |
7418 | if (mod_type_die == NULL) |
7419 | abort (); | |
a3f97cbb | 7420 | } |
3d2999ba MK |
7421 | |
7422 | /* We want to equate the qualified type to the die below. */ | |
7423 | if (qualified_type) | |
7424 | type = qualified_type; | |
a3f97cbb | 7425 | } |
71dfc51f | 7426 | |
dfcf9891 JW |
7427 | equate_type_number_to_die (type, mod_type_die); |
7428 | if (item_type) | |
71dfc51f RK |
7429 | /* We must do this after the equate_type_number_to_die call, in case |
7430 | this is a recursive type. This ensures that the modified_type_die | |
7431 | recursion will terminate even if the type is recursive. Recursive | |
7432 | types are possible in Ada. */ | |
7433 | sub_die = modified_type_die (item_type, | |
7434 | TYPE_READONLY (item_type), | |
7435 | TYPE_VOLATILE (item_type), | |
7436 | context_die); | |
7437 | ||
a3f97cbb | 7438 | if (sub_die != NULL) |
71dfc51f RK |
7439 | add_AT_die_ref (mod_type_die, DW_AT_type, sub_die); |
7440 | ||
a3f97cbb JW |
7441 | return mod_type_die; |
7442 | } | |
7443 | ||
a3f97cbb JW |
7444 | /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is |
7445 | an enumerated type. */ | |
71dfc51f RK |
7446 | |
7447 | static inline int | |
a3f97cbb JW |
7448 | type_is_enum (type) |
7449 | register tree type; | |
7450 | { | |
7451 | return TREE_CODE (type) == ENUMERAL_TYPE; | |
7452 | } | |
7453 | ||
7d9d8943 AM |
7454 | /* Return the register number described by a given RTL node. */ |
7455 | ||
7456 | static unsigned int | |
7457 | reg_number (rtl) | |
7458 | register rtx rtl; | |
7459 | { | |
7460 | register unsigned regno = REGNO (rtl); | |
7461 | ||
7462 | if (regno >= FIRST_PSEUDO_REGISTER) | |
7463 | { | |
7464 | warning ("internal regno botch: regno = %d\n", regno); | |
7465 | regno = 0; | |
7466 | } | |
7467 | ||
7468 | regno = DBX_REGISTER_NUMBER (regno); | |
7469 | return regno; | |
7470 | } | |
7471 | ||
a3f97cbb | 7472 | /* Return a location descriptor that designates a machine register. */ |
71dfc51f | 7473 | |
a3f97cbb JW |
7474 | static dw_loc_descr_ref |
7475 | reg_loc_descriptor (rtl) | |
7476 | register rtx rtl; | |
7477 | { | |
7478 | register dw_loc_descr_ref loc_result = NULL; | |
7479 | register unsigned reg = reg_number (rtl); | |
71dfc51f | 7480 | |
85066503 | 7481 | if (reg <= 31) |
71dfc51f | 7482 | loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0); |
a3f97cbb | 7483 | else |
71dfc51f RK |
7484 | loc_result = new_loc_descr (DW_OP_regx, reg, 0); |
7485 | ||
a3f97cbb JW |
7486 | return loc_result; |
7487 | } | |
7488 | ||
d8041cc8 RH |
7489 | /* Return a location descriptor that designates a constant. */ |
7490 | ||
7491 | static dw_loc_descr_ref | |
7492 | int_loc_descriptor (i) | |
7493 | HOST_WIDE_INT i; | |
7494 | { | |
7495 | enum dwarf_location_atom op; | |
7496 | ||
7497 | /* Pick the smallest representation of a constant, rather than just | |
7498 | defaulting to the LEB encoding. */ | |
7499 | if (i >= 0) | |
7500 | { | |
7501 | if (i <= 31) | |
7502 | op = DW_OP_lit0 + i; | |
7503 | else if (i <= 0xff) | |
7504 | op = DW_OP_const1u; | |
7505 | else if (i <= 0xffff) | |
7506 | op = DW_OP_const2u; | |
7507 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
7508 | || i <= 0xffffffff) | |
7509 | op = DW_OP_const4u; | |
7510 | else | |
7511 | op = DW_OP_constu; | |
7512 | } | |
7513 | else | |
7514 | { | |
7515 | if (i >= -0x80) | |
7516 | op = DW_OP_const1s; | |
7517 | else if (i >= -0x8000) | |
7518 | op = DW_OP_const2s; | |
7519 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
7520 | || i >= -0x80000000) | |
7521 | op = DW_OP_const4s; | |
7522 | else | |
7523 | op = DW_OP_consts; | |
7524 | } | |
7525 | ||
7526 | return new_loc_descr (op, i, 0); | |
7527 | } | |
7528 | ||
a3f97cbb | 7529 | /* Return a location descriptor that designates a base+offset location. */ |
71dfc51f | 7530 | |
a3f97cbb JW |
7531 | static dw_loc_descr_ref |
7532 | based_loc_descr (reg, offset) | |
7533 | unsigned reg; | |
7534 | long int offset; | |
7535 | { | |
7536 | register dw_loc_descr_ref loc_result; | |
810429b7 JM |
7537 | /* For the "frame base", we use the frame pointer or stack pointer |
7538 | registers, since the RTL for local variables is relative to one of | |
7539 | them. */ | |
7540 | register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed | |
b1ccbc24 | 7541 | ? HARD_FRAME_POINTER_REGNUM |
810429b7 | 7542 | : STACK_POINTER_REGNUM); |
71dfc51f | 7543 | |
a3f97cbb | 7544 | if (reg == fp_reg) |
71dfc51f | 7545 | loc_result = new_loc_descr (DW_OP_fbreg, offset, 0); |
85066503 | 7546 | else if (reg <= 31) |
71dfc51f | 7547 | loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0); |
a3f97cbb | 7548 | else |
71dfc51f RK |
7549 | loc_result = new_loc_descr (DW_OP_bregx, reg, offset); |
7550 | ||
a3f97cbb JW |
7551 | return loc_result; |
7552 | } | |
7553 | ||
7554 | /* Return true if this RTL expression describes a base+offset calculation. */ | |
71dfc51f RK |
7555 | |
7556 | static inline int | |
a3f97cbb JW |
7557 | is_based_loc (rtl) |
7558 | register rtx rtl; | |
7559 | { | |
71dfc51f RK |
7560 | return (GET_CODE (rtl) == PLUS |
7561 | && ((GET_CODE (XEXP (rtl, 0)) == REG | |
7562 | && GET_CODE (XEXP (rtl, 1)) == CONST_INT))); | |
a3f97cbb JW |
7563 | } |
7564 | ||
7565 | /* The following routine converts the RTL for a variable or parameter | |
7566 | (resident in memory) into an equivalent Dwarf representation of a | |
7567 | mechanism for getting the address of that same variable onto the top of a | |
7568 | hypothetical "address evaluation" stack. | |
71dfc51f | 7569 | |
a3f97cbb JW |
7570 | When creating memory location descriptors, we are effectively transforming |
7571 | the RTL for a memory-resident object into its Dwarf postfix expression | |
7572 | equivalent. This routine recursively descends an RTL tree, turning | |
e60d4d7b JL |
7573 | it into Dwarf postfix code as it goes. |
7574 | ||
7575 | MODE is the mode of the memory reference, needed to handle some | |
7576 | autoincrement addressing modes. */ | |
71dfc51f | 7577 | |
a3f97cbb | 7578 | static dw_loc_descr_ref |
e60d4d7b | 7579 | mem_loc_descriptor (rtl, mode) |
a3f97cbb | 7580 | register rtx rtl; |
e60d4d7b | 7581 | enum machine_mode mode; |
a3f97cbb JW |
7582 | { |
7583 | dw_loc_descr_ref mem_loc_result = NULL; | |
556273e0 | 7584 | /* Note that for a dynamically sized array, the location we will generate a |
a3f97cbb JW |
7585 | description of here will be the lowest numbered location which is |
7586 | actually within the array. That's *not* necessarily the same as the | |
7587 | zeroth element of the array. */ | |
71dfc51f | 7588 | |
1865dbb5 JM |
7589 | #ifdef ASM_SIMPLIFY_DWARF_ADDR |
7590 | rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); | |
7591 | #endif | |
7592 | ||
a3f97cbb JW |
7593 | switch (GET_CODE (rtl)) |
7594 | { | |
e60d4d7b JL |
7595 | case POST_INC: |
7596 | case POST_DEC: | |
e2134eea | 7597 | case POST_MODIFY: |
e60d4d7b JL |
7598 | /* POST_INC and POST_DEC can be handled just like a SUBREG. So we |
7599 | just fall into the SUBREG code. */ | |
7600 | ||
556273e0 | 7601 | /* Fall through. */ |
e60d4d7b | 7602 | |
a3f97cbb JW |
7603 | case SUBREG: |
7604 | /* The case of a subreg may arise when we have a local (register) | |
7605 | variable or a formal (register) parameter which doesn't quite fill | |
7606 | up an entire register. For now, just assume that it is | |
7607 | legitimate to make the Dwarf info refer to the whole register which | |
7608 | contains the given subreg. */ | |
ddef6bc7 | 7609 | rtl = SUBREG_REG (rtl); |
71dfc51f | 7610 | |
556273e0 | 7611 | /* Fall through. */ |
a3f97cbb JW |
7612 | |
7613 | case REG: | |
7614 | /* Whenever a register number forms a part of the description of the | |
7615 | method for calculating the (dynamic) address of a memory resident | |
556273e0 | 7616 | object, DWARF rules require the register number be referred to as |
a3f97cbb JW |
7617 | a "base register". This distinction is not based in any way upon |
7618 | what category of register the hardware believes the given register | |
7619 | belongs to. This is strictly DWARF terminology we're dealing with | |
7620 | here. Note that in cases where the location of a memory-resident | |
7621 | data object could be expressed as: OP_ADD (OP_BASEREG (basereg), | |
7622 | OP_CONST (0)) the actual DWARF location descriptor that we generate | |
7623 | may just be OP_BASEREG (basereg). This may look deceptively like | |
7624 | the object in question was allocated to a register (rather than in | |
7625 | memory) so DWARF consumers need to be aware of the subtle | |
7626 | distinction between OP_REG and OP_BASEREG. */ | |
7627 | mem_loc_result = based_loc_descr (reg_number (rtl), 0); | |
7628 | break; | |
7629 | ||
7630 | case MEM: | |
f7d2b0ed RH |
7631 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
7632 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0)); | |
a3f97cbb JW |
7633 | break; |
7634 | ||
d8041cc8 RH |
7635 | case LABEL_REF: |
7636 | /* Some ports can transform a symbol ref into a label ref, because | |
368f4cd6 NC |
7637 | the symbol ref is too far away and has to be dumped into a constant |
7638 | pool. */ | |
a3f97cbb JW |
7639 | case CONST: |
7640 | case SYMBOL_REF: | |
6331d1c1 | 7641 | /* Alternatively, the symbol in the constant pool might be referenced |
c6f9b9a1 NC |
7642 | by a different symbol. */ |
7643 | if (GET_CODE (rtl) == SYMBOL_REF | |
79cdfa4b TM |
7644 | && CONSTANT_POOL_ADDRESS_P (rtl)) |
7645 | { | |
7646 | rtx tmp = get_pool_constant (rtl); | |
6331d1c1 | 7647 | if (GET_CODE (tmp) == SYMBOL_REF) |
79cdfa4b TM |
7648 | rtl = tmp; |
7649 | } | |
7650 | ||
a3f97cbb JW |
7651 | mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0); |
7652 | mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
1865dbb5 | 7653 | mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl); |
a3f97cbb JW |
7654 | break; |
7655 | ||
e2134eea JH |
7656 | case PRE_MODIFY: |
7657 | /* Extract the PLUS expression nested inside and fall into | |
0407c02b | 7658 | PLUS code below. */ |
e2134eea JH |
7659 | rtl = XEXP (rtl, 1); |
7660 | goto plus; | |
7661 | ||
e60d4d7b JL |
7662 | case PRE_INC: |
7663 | case PRE_DEC: | |
7664 | /* Turn these into a PLUS expression and fall into the PLUS code | |
7665 | below. */ | |
7666 | rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0), | |
7667 | GEN_INT (GET_CODE (rtl) == PRE_INC | |
556273e0 KH |
7668 | ? GET_MODE_UNIT_SIZE (mode) |
7669 | : -GET_MODE_UNIT_SIZE (mode))); | |
7670 | ||
7671 | /* Fall through. */ | |
e60d4d7b | 7672 | |
a3f97cbb | 7673 | case PLUS: |
e2134eea | 7674 | plus: |
a3f97cbb | 7675 | if (is_based_loc (rtl)) |
71dfc51f RK |
7676 | mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)), |
7677 | INTVAL (XEXP (rtl, 1))); | |
a3f97cbb JW |
7678 | else |
7679 | { | |
d8041cc8 RH |
7680 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode); |
7681 | ||
7682 | if (GET_CODE (XEXP (rtl, 1)) == CONST_INT | |
7683 | && INTVAL (XEXP (rtl, 1)) >= 0) | |
7684 | { | |
7685 | add_loc_descr (&mem_loc_result, | |
7686 | new_loc_descr (DW_OP_plus_uconst, | |
7687 | INTVAL (XEXP (rtl, 1)), 0)); | |
7688 | } | |
7689 | else | |
7690 | { | |
7691 | add_loc_descr (&mem_loc_result, | |
7692 | mem_loc_descriptor (XEXP (rtl, 1), mode)); | |
7693 | add_loc_descr (&mem_loc_result, | |
7694 | new_loc_descr (DW_OP_plus, 0, 0)); | |
7695 | } | |
a3f97cbb JW |
7696 | } |
7697 | break; | |
7698 | ||
dd2478ae JW |
7699 | case MULT: |
7700 | /* If a pseudo-reg is optimized away, it is possible for it to | |
7701 | be replaced with a MEM containing a multiply. */ | |
d8041cc8 RH |
7702 | add_loc_descr (&mem_loc_result, |
7703 | mem_loc_descriptor (XEXP (rtl, 0), mode)); | |
7704 | add_loc_descr (&mem_loc_result, | |
7705 | mem_loc_descriptor (XEXP (rtl, 1), mode)); | |
dd2478ae JW |
7706 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0)); |
7707 | break; | |
7708 | ||
a3f97cbb | 7709 | case CONST_INT: |
d8041cc8 | 7710 | mem_loc_result = int_loc_descriptor (INTVAL (rtl)); |
a3f97cbb JW |
7711 | break; |
7712 | ||
7713 | default: | |
7714 | abort (); | |
7715 | } | |
71dfc51f | 7716 | |
a3f97cbb JW |
7717 | return mem_loc_result; |
7718 | } | |
7719 | ||
956d6950 | 7720 | /* Return a descriptor that describes the concatenation of two locations. |
4401bf24 JL |
7721 | This is typically a complex variable. */ |
7722 | ||
7723 | static dw_loc_descr_ref | |
7724 | concat_loc_descriptor (x0, x1) | |
7725 | register rtx x0, x1; | |
7726 | { | |
7727 | dw_loc_descr_ref cc_loc_result = NULL; | |
7728 | ||
7729 | if (!is_pseudo_reg (x0) | |
7730 | && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0)))) | |
7731 | add_loc_descr (&cc_loc_result, loc_descriptor (x0)); | |
7732 | add_loc_descr (&cc_loc_result, | |
7733 | new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0)); | |
7734 | ||
7735 | if (!is_pseudo_reg (x1) | |
7736 | && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0)))) | |
7737 | add_loc_descr (&cc_loc_result, loc_descriptor (x1)); | |
7738 | add_loc_descr (&cc_loc_result, | |
7739 | new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0)); | |
7740 | ||
7741 | return cc_loc_result; | |
7742 | } | |
7743 | ||
a3f97cbb JW |
7744 | /* Output a proper Dwarf location descriptor for a variable or parameter |
7745 | which is either allocated in a register or in a memory location. For a | |
7746 | register, we just generate an OP_REG and the register number. For a | |
7747 | memory location we provide a Dwarf postfix expression describing how to | |
7748 | generate the (dynamic) address of the object onto the address stack. */ | |
71dfc51f | 7749 | |
a3f97cbb JW |
7750 | static dw_loc_descr_ref |
7751 | loc_descriptor (rtl) | |
7752 | register rtx rtl; | |
7753 | { | |
7754 | dw_loc_descr_ref loc_result = NULL; | |
7755 | switch (GET_CODE (rtl)) | |
7756 | { | |
7757 | case SUBREG: | |
a3f97cbb JW |
7758 | /* The case of a subreg may arise when we have a local (register) |
7759 | variable or a formal (register) parameter which doesn't quite fill | |
71dfc51f | 7760 | up an entire register. For now, just assume that it is |
a3f97cbb JW |
7761 | legitimate to make the Dwarf info refer to the whole register which |
7762 | contains the given subreg. */ | |
ddef6bc7 | 7763 | rtl = SUBREG_REG (rtl); |
71dfc51f | 7764 | |
556273e0 | 7765 | /* Fall through. */ |
a3f97cbb JW |
7766 | |
7767 | case REG: | |
5c90448c | 7768 | loc_result = reg_loc_descriptor (rtl); |
a3f97cbb JW |
7769 | break; |
7770 | ||
7771 | case MEM: | |
e60d4d7b | 7772 | loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
a3f97cbb JW |
7773 | break; |
7774 | ||
4401bf24 JL |
7775 | case CONCAT: |
7776 | loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1)); | |
7777 | break; | |
7778 | ||
a3f97cbb | 7779 | default: |
71dfc51f | 7780 | abort (); |
a3f97cbb | 7781 | } |
71dfc51f | 7782 | |
a3f97cbb JW |
7783 | return loc_result; |
7784 | } | |
7785 | ||
d8041cc8 RH |
7786 | /* Similar, but generate the descriptor from trees instead of rtl. |
7787 | This comes up particularly with variable length arrays. */ | |
7788 | ||
7789 | static dw_loc_descr_ref | |
7790 | loc_descriptor_from_tree (loc, addressp) | |
7791 | tree loc; | |
7792 | int addressp; | |
7793 | { | |
7794 | dw_loc_descr_ref ret = NULL; | |
7795 | int indirect_size = 0; | |
7796 | int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc)); | |
7797 | enum dwarf_location_atom op; | |
7798 | ||
7799 | /* ??? Most of the time we do not take proper care for sign/zero | |
7800 | extending the values properly. Hopefully this won't be a real | |
7801 | problem... */ | |
7802 | ||
7803 | switch (TREE_CODE (loc)) | |
7804 | { | |
7805 | case ERROR_MARK: | |
7806 | break; | |
7807 | ||
b4ae5201 RK |
7808 | case WITH_RECORD_EXPR: |
7809 | /* This case involves extracting fields from an object to determine the | |
7810 | position of other fields. We don't try to encode this here. The | |
7811 | only user of this is Ada, which encodes the needed information using | |
7812 | the names of types. */ | |
7813 | return ret; | |
7814 | ||
d8041cc8 RH |
7815 | case VAR_DECL: |
7816 | case PARM_DECL: | |
7817 | { | |
7818 | rtx rtl = rtl_for_decl_location (loc); | |
7819 | enum machine_mode mode = DECL_MODE (loc); | |
7820 | ||
a97c9600 RH |
7821 | if (rtl == NULL_RTX) |
7822 | break; | |
7823 | else if (CONSTANT_P (rtl)) | |
d8041cc8 RH |
7824 | { |
7825 | ret = new_loc_descr (DW_OP_addr, 0, 0); | |
7826 | ret->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
7827 | ret->dw_loc_oprnd1.v.val_addr = rtl; | |
7828 | indirect_size = GET_MODE_SIZE (mode); | |
7829 | } | |
7830 | else | |
7831 | { | |
7832 | if (GET_CODE (rtl) == MEM) | |
7833 | { | |
7834 | indirect_size = GET_MODE_SIZE (mode); | |
7835 | rtl = XEXP (rtl, 0); | |
7836 | } | |
7837 | ret = mem_loc_descriptor (rtl, mode); | |
7838 | } | |
7839 | } | |
7840 | break; | |
7841 | ||
7842 | case INDIRECT_REF: | |
7843 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7844 | indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc))); | |
7845 | break; | |
7846 | ||
ed972b14 RK |
7847 | case NOP_EXPR: |
7848 | case CONVERT_EXPR: | |
7849 | case NON_LVALUE_EXPR: | |
b4ae5201 | 7850 | case SAVE_EXPR: |
ed972b14 | 7851 | return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp); |
e57cabac | 7852 | |
d8041cc8 RH |
7853 | case COMPONENT_REF: |
7854 | case BIT_FIELD_REF: | |
7855 | case ARRAY_REF: | |
b4e3fabb | 7856 | case ARRAY_RANGE_REF: |
d8041cc8 RH |
7857 | { |
7858 | tree obj, offset; | |
7859 | HOST_WIDE_INT bitsize, bitpos, bytepos; | |
7860 | enum machine_mode mode; | |
7861 | int volatilep; | |
7862 | unsigned int alignment; | |
7863 | ||
7864 | obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode, | |
7865 | &unsignedp, &volatilep, &alignment); | |
7866 | ret = loc_descriptor_from_tree (obj, 1); | |
7867 | ||
7868 | if (offset != NULL_TREE) | |
7869 | { | |
7870 | /* Variable offset. */ | |
7871 | add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0)); | |
7872 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
7873 | } | |
7874 | ||
7875 | if (addressp) | |
7876 | { | |
7877 | /* We cannot address anything not on a unit boundary. */ | |
7878 | if (bitpos % BITS_PER_UNIT != 0) | |
7879 | abort (); | |
7880 | } | |
7881 | else | |
7882 | { | |
7883 | if (bitpos % BITS_PER_UNIT != 0 | |
7884 | || bitsize % BITS_PER_UNIT != 0) | |
7885 | { | |
7886 | /* ??? We could handle this by loading and shifting etc. | |
7887 | Wait until someone needs it before expending the effort. */ | |
7888 | abort (); | |
7889 | } | |
7890 | ||
7891 | indirect_size = bitsize / BITS_PER_UNIT; | |
7892 | } | |
7893 | ||
7894 | bytepos = bitpos / BITS_PER_UNIT; | |
7895 | if (bytepos > 0) | |
7896 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0)); | |
7897 | else if (bytepos < 0) | |
7898 | { | |
7899 | add_loc_descr (&ret, int_loc_descriptor (bytepos)); | |
7900 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
7901 | } | |
7902 | break; | |
7903 | } | |
7904 | ||
7905 | case INTEGER_CST: | |
7906 | if (host_integerp (loc, 0)) | |
7907 | ret = int_loc_descriptor (tree_low_cst (loc, 0)); | |
7908 | break; | |
d8041cc8 RH |
7909 | |
7910 | case BIT_AND_EXPR: | |
7911 | op = DW_OP_and; | |
7912 | goto do_binop; | |
7913 | case BIT_XOR_EXPR: | |
7914 | op = DW_OP_xor; | |
7915 | goto do_binop; | |
7916 | case BIT_IOR_EXPR: | |
7917 | op = DW_OP_or; | |
7918 | goto do_binop; | |
7919 | case TRUNC_DIV_EXPR: | |
7920 | op = DW_OP_div; | |
7921 | goto do_binop; | |
7922 | case MINUS_EXPR: | |
7923 | op = DW_OP_minus; | |
7924 | goto do_binop; | |
7925 | case TRUNC_MOD_EXPR: | |
7926 | op = DW_OP_mod; | |
7927 | goto do_binop; | |
7928 | case MULT_EXPR: | |
7929 | op = DW_OP_mul; | |
7930 | goto do_binop; | |
7931 | case LSHIFT_EXPR: | |
7932 | op = DW_OP_shl; | |
7933 | goto do_binop; | |
7934 | case RSHIFT_EXPR: | |
7935 | op = (unsignedp ? DW_OP_shr : DW_OP_shra); | |
7936 | goto do_binop; | |
7937 | case PLUS_EXPR: | |
7938 | if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST | |
7939 | && host_integerp (TREE_OPERAND (loc, 1), 0)) | |
7940 | { | |
7941 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7942 | add_loc_descr (&ret, | |
7943 | new_loc_descr (DW_OP_plus_uconst, | |
7944 | tree_low_cst (TREE_OPERAND (loc, 1), | |
7945 | 0), | |
7946 | 0)); | |
7947 | break; | |
7948 | } | |
7949 | op = DW_OP_plus; | |
7950 | goto do_binop; | |
7951 | case LE_EXPR: | |
7952 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7953 | break; | |
7954 | op = DW_OP_le; | |
7955 | goto do_binop; | |
7956 | case GE_EXPR: | |
7957 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7958 | break; | |
7959 | op = DW_OP_ge; | |
7960 | goto do_binop; | |
7961 | case LT_EXPR: | |
7962 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7963 | break; | |
7964 | op = DW_OP_lt; | |
7965 | goto do_binop; | |
7966 | case GT_EXPR: | |
7967 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7968 | break; | |
7969 | op = DW_OP_gt; | |
7970 | goto do_binop; | |
7971 | case EQ_EXPR: | |
7972 | op = DW_OP_eq; | |
7973 | goto do_binop; | |
7974 | case NE_EXPR: | |
7975 | op = DW_OP_ne; | |
7976 | goto do_binop; | |
7977 | ||
7978 | do_binop: | |
7979 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7980 | add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0)); | |
7981 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); | |
7982 | break; | |
7983 | ||
7984 | case BIT_NOT_EXPR: | |
7985 | op = DW_OP_not; | |
7986 | goto do_unop; | |
7987 | case ABS_EXPR: | |
7988 | op = DW_OP_abs; | |
7989 | goto do_unop; | |
7990 | case NEGATE_EXPR: | |
7991 | op = DW_OP_neg; | |
7992 | goto do_unop; | |
7993 | ||
7994 | do_unop: | |
7995 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7996 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); | |
7997 | break; | |
7998 | ||
7999 | case MAX_EXPR: | |
8000 | loc = build (COND_EXPR, TREE_TYPE (loc), | |
8001 | build (LT_EXPR, integer_type_node, | |
8002 | TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)), | |
8003 | TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0)); | |
8004 | /* FALLTHRU */ | |
8005 | ||
8006 | case COND_EXPR: | |
8007 | { | |
8008 | dw_loc_descr_ref bra_node, jump_node, tmp; | |
8009 | ||
8010 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
8011 | bra_node = new_loc_descr (DW_OP_bra, 0, 0); | |
8012 | add_loc_descr (&ret, bra_node); | |
8013 | ||
8014 | tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0); | |
8015 | add_loc_descr (&ret, tmp); | |
8016 | jump_node = new_loc_descr (DW_OP_skip, 0, 0); | |
8017 | add_loc_descr (&ret, jump_node); | |
8018 | ||
8019 | tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); | |
8020 | add_loc_descr (&ret, tmp); | |
8021 | bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc; | |
8022 | bra_node->dw_loc_oprnd1.v.val_loc = tmp; | |
8023 | ||
8024 | /* ??? Need a node to point the skip at. Use a nop. */ | |
8025 | tmp = new_loc_descr (DW_OP_nop, 0, 0); | |
8026 | add_loc_descr (&ret, tmp); | |
8027 | jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc; | |
8028 | jump_node->dw_loc_oprnd1.v.val_loc = tmp; | |
8029 | } | |
8030 | break; | |
8031 | ||
8032 | default: | |
8033 | abort (); | |
8034 | } | |
8035 | ||
8036 | /* If we can't fill the request for an address, die. */ | |
8037 | if (addressp && indirect_size == 0) | |
8038 | abort (); | |
8039 | ||
8040 | /* If we've got an address and don't want one, dereference. */ | |
8041 | if (!addressp && indirect_size > 0) | |
8042 | { | |
8043 | if (indirect_size > DWARF2_ADDR_SIZE) | |
8044 | abort (); | |
8045 | if (indirect_size == DWARF2_ADDR_SIZE) | |
8046 | op = DW_OP_deref; | |
8047 | else | |
8048 | op = DW_OP_deref_size; | |
8049 | add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0)); | |
8050 | } | |
8051 | ||
8052 | return ret; | |
8053 | } | |
8054 | ||
665f2503 | 8055 | /* Given a value, round it up to the lowest multiple of `boundary' |
a3f97cbb | 8056 | which is not less than the value itself. */ |
71dfc51f | 8057 | |
665f2503 | 8058 | static inline HOST_WIDE_INT |
a3f97cbb | 8059 | ceiling (value, boundary) |
665f2503 RK |
8060 | HOST_WIDE_INT value; |
8061 | unsigned int boundary; | |
a3f97cbb JW |
8062 | { |
8063 | return (((value + boundary - 1) / boundary) * boundary); | |
8064 | } | |
8065 | ||
8066 | /* Given a pointer to what is assumed to be a FIELD_DECL node, return a | |
8067 | pointer to the declared type for the relevant field variable, or return | |
8068 | `integer_type_node' if the given node turns out to be an | |
8069 | ERROR_MARK node. */ | |
71dfc51f RK |
8070 | |
8071 | static inline tree | |
a3f97cbb JW |
8072 | field_type (decl) |
8073 | register tree decl; | |
8074 | { | |
8075 | register tree type; | |
8076 | ||
8077 | if (TREE_CODE (decl) == ERROR_MARK) | |
8078 | return integer_type_node; | |
8079 | ||
8080 | type = DECL_BIT_FIELD_TYPE (decl); | |
71dfc51f | 8081 | if (type == NULL_TREE) |
a3f97cbb JW |
8082 | type = TREE_TYPE (decl); |
8083 | ||
8084 | return type; | |
8085 | } | |
8086 | ||
5f446d21 DD |
8087 | /* Given a pointer to a tree node, return the alignment in bits for |
8088 | it, or else return BITS_PER_WORD if the node actually turns out to | |
8089 | be an ERROR_MARK node. */ | |
71dfc51f RK |
8090 | |
8091 | static inline unsigned | |
a3f97cbb JW |
8092 | simple_type_align_in_bits (type) |
8093 | register tree type; | |
8094 | { | |
8095 | return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; | |
8096 | } | |
8097 | ||
5f446d21 DD |
8098 | static inline unsigned |
8099 | simple_decl_align_in_bits (decl) | |
8100 | register tree decl; | |
8101 | { | |
8102 | return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD; | |
8103 | } | |
8104 | ||
a3f97cbb JW |
8105 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE |
8106 | node, return the size in bits for the type if it is a constant, or else | |
8107 | return the alignment for the type if the type's size is not constant, or | |
8108 | else return BITS_PER_WORD if the type actually turns out to be an | |
8109 | ERROR_MARK node. */ | |
71dfc51f | 8110 | |
665f2503 | 8111 | static inline unsigned HOST_WIDE_INT |
a3f97cbb JW |
8112 | simple_type_size_in_bits (type) |
8113 | register tree type; | |
8114 | { | |
3df18884 RH |
8115 | tree type_size_tree; |
8116 | ||
a3f97cbb JW |
8117 | if (TREE_CODE (type) == ERROR_MARK) |
8118 | return BITS_PER_WORD; | |
3df18884 | 8119 | type_size_tree = TYPE_SIZE (type); |
a3f97cbb | 8120 | |
3df18884 RH |
8121 | if (type_size_tree == NULL_TREE) |
8122 | return 0; | |
8123 | if (! host_integerp (type_size_tree, 1)) | |
8124 | return TYPE_ALIGN (type); | |
8125 | return tree_low_cst (type_size_tree, 1); | |
a3f97cbb JW |
8126 | } |
8127 | ||
8128 | /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and | |
8129 | return the byte offset of the lowest addressed byte of the "containing | |
8130 | object" for the given FIELD_DECL, or return 0 if we are unable to | |
8131 | determine what that offset is, either because the argument turns out to | |
8132 | be a pointer to an ERROR_MARK node, or because the offset is actually | |
8133 | variable. (We can't handle the latter case just yet). */ | |
71dfc51f | 8134 | |
665f2503 | 8135 | static HOST_WIDE_INT |
a3f97cbb JW |
8136 | field_byte_offset (decl) |
8137 | register tree decl; | |
8138 | { | |
665f2503 | 8139 | unsigned int type_align_in_bits; |
5f446d21 | 8140 | unsigned int decl_align_in_bits; |
665f2503 | 8141 | unsigned HOST_WIDE_INT type_size_in_bits; |
665f2503 RK |
8142 | HOST_WIDE_INT object_offset_in_bits; |
8143 | HOST_WIDE_INT object_offset_in_bytes; | |
8144 | tree type; | |
8145 | tree field_size_tree; | |
8146 | HOST_WIDE_INT bitpos_int; | |
8147 | HOST_WIDE_INT deepest_bitpos; | |
8148 | unsigned HOST_WIDE_INT field_size_in_bits; | |
a3f97cbb JW |
8149 | |
8150 | if (TREE_CODE (decl) == ERROR_MARK) | |
8151 | return 0; | |
8152 | ||
8153 | if (TREE_CODE (decl) != FIELD_DECL) | |
8154 | abort (); | |
8155 | ||
8156 | type = field_type (decl); | |
a3f97cbb JW |
8157 | field_size_tree = DECL_SIZE (decl); |
8158 | ||
3df18884 RH |
8159 | /* The size could be unspecified if there was an error, or for |
8160 | a flexible array member. */ | |
50352c9c | 8161 | if (! field_size_tree) |
3df18884 | 8162 | field_size_tree = bitsize_zero_node; |
50352c9c | 8163 | |
556273e0 | 8164 | /* We cannot yet cope with fields whose positions are variable, so |
a3f97cbb JW |
8165 | for now, when we see such things, we simply return 0. Someday, we may |
8166 | be able to handle such cases, but it will be damn difficult. */ | |
665f2503 | 8167 | if (! host_integerp (bit_position (decl), 0)) |
a3f97cbb | 8168 | return 0; |
14a774a9 | 8169 | |
665f2503 | 8170 | bitpos_int = int_bit_position (decl); |
a3f97cbb | 8171 | |
3df18884 | 8172 | /* If we don't know the size of the field, pretend it's a full word. */ |
665f2503 RK |
8173 | if (host_integerp (field_size_tree, 1)) |
8174 | field_size_in_bits = tree_low_cst (field_size_tree, 1); | |
14a774a9 RK |
8175 | else |
8176 | field_size_in_bits = BITS_PER_WORD; | |
a3f97cbb JW |
8177 | |
8178 | type_size_in_bits = simple_type_size_in_bits (type); | |
a3f97cbb | 8179 | type_align_in_bits = simple_type_align_in_bits (type); |
5f446d21 | 8180 | decl_align_in_bits = simple_decl_align_in_bits (decl); |
a3f97cbb JW |
8181 | |
8182 | /* Note that the GCC front-end doesn't make any attempt to keep track of | |
8183 | the starting bit offset (relative to the start of the containing | |
8184 | structure type) of the hypothetical "containing object" for a bit- | |
8185 | field. Thus, when computing the byte offset value for the start of the | |
556273e0 | 8186 | "containing object" of a bit-field, we must deduce this information on |
a3f97cbb JW |
8187 | our own. This can be rather tricky to do in some cases. For example, |
8188 | handling the following structure type definition when compiling for an | |
8189 | i386/i486 target (which only aligns long long's to 32-bit boundaries) | |
8190 | can be very tricky: | |
8191 | ||
8192 | struct S { int field1; long long field2:31; }; | |
8193 | ||
8194 | Fortunately, there is a simple rule-of-thumb which can be | |
8195 | used in such cases. When compiling for an i386/i486, GCC will allocate | |
556273e0 | 8196 | 8 bytes for the structure shown above. It decides to do this based upon |
a3f97cbb JW |
8197 | one simple rule for bit-field allocation. Quite simply, GCC allocates |
8198 | each "containing object" for each bit-field at the first (i.e. lowest | |
8199 | addressed) legitimate alignment boundary (based upon the required | |
8200 | minimum alignment for the declared type of the field) which it can | |
8201 | possibly use, subject to the condition that there is still enough | |
8202 | available space remaining in the containing object (when allocated at | |
8203 | the selected point) to fully accommodate all of the bits of the | |
8204 | bit-field itself. This simple rule makes it obvious why GCC allocates | |
8205 | 8 bytes for each object of the structure type shown above. When looking | |
8206 | for a place to allocate the "containing object" for `field2', the | |
8207 | compiler simply tries to allocate a 64-bit "containing object" at each | |
8208 | successive 32-bit boundary (starting at zero) until it finds a place to | |
8209 | allocate that 64- bit field such that at least 31 contiguous (and | |
8210 | previously unallocated) bits remain within that selected 64 bit field. | |
8211 | (As it turns out, for the example above, the compiler finds that it is | |
8212 | OK to allocate the "containing object" 64-bit field at bit-offset zero | |
8213 | within the structure type.) Here we attempt to work backwards from the | |
556273e0 | 8214 | limited set of facts we're given, and we try to deduce from those facts, |
a3f97cbb | 8215 | where GCC must have believed that the containing object started (within |
556273e0 KH |
8216 | the structure type). The value we deduce is then used (by the callers of |
8217 | this routine) to generate DW_AT_location and DW_AT_bit_offset attributes | |
a3f97cbb JW |
8218 | for fields (both bit-fields and, in the case of DW_AT_location, regular |
8219 | fields as well). */ | |
8220 | ||
8221 | /* Figure out the bit-distance from the start of the structure to the | |
8222 | "deepest" bit of the bit-field. */ | |
8223 | deepest_bitpos = bitpos_int + field_size_in_bits; | |
8224 | ||
8225 | /* This is the tricky part. Use some fancy footwork to deduce where the | |
8226 | lowest addressed bit of the containing object must be. */ | |
5f446d21 DD |
8227 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; |
8228 | ||
8229 | /* Round up to type_align by default. This works best for bitfields. */ | |
8230 | object_offset_in_bits += type_align_in_bits - 1; | |
8231 | object_offset_in_bits /= type_align_in_bits; | |
8232 | object_offset_in_bits *= type_align_in_bits; | |
a3f97cbb | 8233 | |
5f446d21 DD |
8234 | if (object_offset_in_bits > bitpos_int) |
8235 | { | |
8236 | /* Sigh, the decl must be packed. */ | |
8237 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; | |
8238 | ||
8239 | /* Round up to decl_align instead. */ | |
8240 | object_offset_in_bits += decl_align_in_bits - 1; | |
8241 | object_offset_in_bits /= decl_align_in_bits; | |
8242 | object_offset_in_bits *= decl_align_in_bits; | |
8243 | } | |
a3f97cbb | 8244 | |
5f446d21 | 8245 | object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT; |
a3f97cbb JW |
8246 | |
8247 | return object_offset_in_bytes; | |
8248 | } | |
a3f97cbb | 8249 | \f |
71dfc51f RK |
8250 | /* The following routines define various Dwarf attributes and any data |
8251 | associated with them. */ | |
a3f97cbb | 8252 | |
ef76d03b | 8253 | /* Add a location description attribute value to a DIE. |
a3f97cbb | 8254 | |
ef76d03b | 8255 | This emits location attributes suitable for whole variables and |
a3f97cbb JW |
8256 | whole parameters. Note that the location attributes for struct fields are |
8257 | generated by the routine `data_member_location_attribute' below. */ | |
71dfc51f | 8258 | |
a3f97cbb | 8259 | static void |
ef76d03b | 8260 | add_AT_location_description (die, attr_kind, rtl) |
a3f97cbb | 8261 | dw_die_ref die; |
ef76d03b | 8262 | enum dwarf_attribute attr_kind; |
a3f97cbb JW |
8263 | register rtx rtl; |
8264 | { | |
a3f97cbb JW |
8265 | /* Handle a special case. If we are about to output a location descriptor |
8266 | for a variable or parameter which has been optimized out of existence, | |
6a7a9f01 | 8267 | don't do that. A variable which has been optimized out |
a3f97cbb JW |
8268 | of existence will have a DECL_RTL value which denotes a pseudo-reg. |
8269 | Currently, in some rare cases, variables can have DECL_RTL values which | |
8270 | look like (MEM (REG pseudo-reg#)). These cases are due to bugs | |
556273e0 | 8271 | elsewhere in the compiler. We treat such cases as if the variable(s) in |
6a7a9f01 | 8272 | question had been optimized out of existence. */ |
a3f97cbb | 8273 | |
6a7a9f01 JM |
8274 | if (is_pseudo_reg (rtl) |
8275 | || (GET_CODE (rtl) == MEM | |
4401bf24 | 8276 | && is_pseudo_reg (XEXP (rtl, 0))) |
556273e0 | 8277 | /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which |
bce8fed7 JL |
8278 | references the internal argument pointer (a pseudo) in a function |
8279 | where all references to the internal argument pointer were | |
8280 | eliminated via the optimizers. */ | |
8281 | || (GET_CODE (rtl) == MEM | |
8282 | && GET_CODE (XEXP (rtl, 0)) == PLUS | |
8283 | && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0))) | |
4401bf24 JL |
8284 | || (GET_CODE (rtl) == CONCAT |
8285 | && is_pseudo_reg (XEXP (rtl, 0)) | |
8286 | && is_pseudo_reg (XEXP (rtl, 1)))) | |
6a7a9f01 | 8287 | return; |
a3f97cbb | 8288 | |
6a7a9f01 | 8289 | add_AT_loc (die, attr_kind, loc_descriptor (rtl)); |
a3f97cbb JW |
8290 | } |
8291 | ||
8292 | /* Attach the specialized form of location attribute used for data | |
8293 | members of struct and union types. In the special case of a | |
8294 | FIELD_DECL node which represents a bit-field, the "offset" part | |
8295 | of this special location descriptor must indicate the distance | |
8296 | in bytes from the lowest-addressed byte of the containing struct | |
8297 | or union type to the lowest-addressed byte of the "containing | |
8298 | object" for the bit-field. (See the `field_byte_offset' function | |
8299 | above).. For any given bit-field, the "containing object" is a | |
8300 | hypothetical object (of some integral or enum type) within which | |
8301 | the given bit-field lives. The type of this hypothetical | |
8302 | "containing object" is always the same as the declared type of | |
8303 | the individual bit-field itself (for GCC anyway... the DWARF | |
8304 | spec doesn't actually mandate this). Note that it is the size | |
8305 | (in bytes) of the hypothetical "containing object" which will | |
8306 | be given in the DW_AT_byte_size attribute for this bit-field. | |
8307 | (See the `byte_size_attribute' function below.) It is also used | |
8308 | when calculating the value of the DW_AT_bit_offset attribute. | |
8309 | (See the `bit_offset_attribute' function below). */ | |
71dfc51f | 8310 | |
a3f97cbb JW |
8311 | static void |
8312 | add_data_member_location_attribute (die, decl) | |
8313 | register dw_die_ref die; | |
8314 | register tree decl; | |
8315 | { | |
61b32c02 | 8316 | register unsigned long offset; |
a3f97cbb JW |
8317 | register dw_loc_descr_ref loc_descr; |
8318 | register enum dwarf_location_atom op; | |
8319 | ||
61b32c02 | 8320 | if (TREE_CODE (decl) == TREE_VEC) |
665f2503 | 8321 | offset = tree_low_cst (BINFO_OFFSET (decl), 0); |
61b32c02 JM |
8322 | else |
8323 | offset = field_byte_offset (decl); | |
8324 | ||
a3f97cbb JW |
8325 | /* The DWARF2 standard says that we should assume that the structure address |
8326 | is already on the stack, so we can specify a structure field address | |
8327 | by using DW_OP_plus_uconst. */ | |
71dfc51f | 8328 | |
a3f97cbb JW |
8329 | #ifdef MIPS_DEBUGGING_INFO |
8330 | /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator | |
8331 | correctly. It works only if we leave the offset on the stack. */ | |
8332 | op = DW_OP_constu; | |
8333 | #else | |
8334 | op = DW_OP_plus_uconst; | |
8335 | #endif | |
71dfc51f | 8336 | |
a3f97cbb JW |
8337 | loc_descr = new_loc_descr (op, offset, 0); |
8338 | add_AT_loc (die, DW_AT_data_member_location, loc_descr); | |
8339 | } | |
8340 | ||
8341 | /* Attach an DW_AT_const_value attribute for a variable or a parameter which | |
8342 | does not have a "location" either in memory or in a register. These | |
8343 | things can arise in GNU C when a constant is passed as an actual parameter | |
8344 | to an inlined function. They can also arise in C++ where declared | |
8345 | constants do not necessarily get memory "homes". */ | |
71dfc51f | 8346 | |
a3f97cbb JW |
8347 | static void |
8348 | add_const_value_attribute (die, rtl) | |
8349 | register dw_die_ref die; | |
8350 | register rtx rtl; | |
8351 | { | |
8352 | switch (GET_CODE (rtl)) | |
8353 | { | |
8354 | case CONST_INT: | |
2e4b9b8c RH |
8355 | /* Note that a CONST_INT rtx could represent either an integer |
8356 | or a floating-point constant. A CONST_INT is used whenever | |
8357 | the constant will fit into a single word. In all such | |
8358 | cases, the original mode of the constant value is wiped | |
8359 | out, and the CONST_INT rtx is assigned VOIDmode. */ | |
8360 | { | |
8361 | HOST_WIDE_INT val = INTVAL (rtl); | |
8362 | ||
8363 | /* ??? We really should be using HOST_WIDE_INT throughout. */ | |
8364 | if (val < 0) | |
8365 | { | |
8366 | if ((long) val != val) | |
8367 | abort (); | |
8368 | add_AT_int (die, DW_AT_const_value, (long) val); | |
8369 | } | |
8370 | else | |
8371 | { | |
8372 | if ((unsigned long) val != (unsigned HOST_WIDE_INT) val) | |
8373 | abort (); | |
732910b9 | 8374 | add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val); |
2e4b9b8c RH |
8375 | } |
8376 | } | |
a3f97cbb JW |
8377 | break; |
8378 | ||
8379 | case CONST_DOUBLE: | |
8380 | /* Note that a CONST_DOUBLE rtx could represent either an integer or a | |
8381 | floating-point constant. A CONST_DOUBLE is used whenever the | |
8382 | constant requires more than one word in order to be adequately | |
469ac993 JM |
8383 | represented. We output CONST_DOUBLEs as blocks. */ |
8384 | { | |
8385 | register enum machine_mode mode = GET_MODE (rtl); | |
8386 | ||
8387 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
8388 | { | |
e389897b | 8389 | register unsigned length = GET_MODE_SIZE (mode) / 4; |
1bfb5f8f | 8390 | long *array = (long *) xmalloc (sizeof (long) * length); |
71dfc51f | 8391 | REAL_VALUE_TYPE rv; |
469ac993 | 8392 | |
71dfc51f | 8393 | REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl); |
469ac993 JM |
8394 | switch (mode) |
8395 | { | |
8396 | case SFmode: | |
71dfc51f | 8397 | REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]); |
469ac993 JM |
8398 | break; |
8399 | ||
8400 | case DFmode: | |
71dfc51f | 8401 | REAL_VALUE_TO_TARGET_DOUBLE (rv, array); |
469ac993 JM |
8402 | break; |
8403 | ||
8404 | case XFmode: | |
8405 | case TFmode: | |
71dfc51f | 8406 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array); |
469ac993 JM |
8407 | break; |
8408 | ||
8409 | default: | |
8410 | abort (); | |
8411 | } | |
8412 | ||
469ac993 JM |
8413 | add_AT_float (die, DW_AT_const_value, length, array); |
8414 | } | |
8415 | else | |
2e4b9b8c RH |
8416 | { |
8417 | /* ??? We really should be using HOST_WIDE_INT throughout. */ | |
8418 | if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT) | |
8419 | abort (); | |
8420 | add_AT_long_long (die, DW_AT_const_value, | |
8421 | CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl)); | |
8422 | } | |
469ac993 | 8423 | } |
a3f97cbb JW |
8424 | break; |
8425 | ||
8426 | case CONST_STRING: | |
8427 | add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0)); | |
8428 | break; | |
8429 | ||
8430 | case SYMBOL_REF: | |
8431 | case LABEL_REF: | |
8432 | case CONST: | |
1865dbb5 | 8433 | add_AT_addr (die, DW_AT_const_value, save_rtx (rtl)); |
a3f97cbb JW |
8434 | break; |
8435 | ||
8436 | case PLUS: | |
8437 | /* In cases where an inlined instance of an inline function is passed | |
8438 | the address of an `auto' variable (which is local to the caller) we | |
8439 | can get a situation where the DECL_RTL of the artificial local | |
8440 | variable (for the inlining) which acts as a stand-in for the | |
8441 | corresponding formal parameter (of the inline function) will look | |
8442 | like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not | |
556273e0 KH |
8443 | exactly a compile-time constant expression, but it isn't the address |
8444 | of the (artificial) local variable either. Rather, it represents the | |
a3f97cbb | 8445 | *value* which the artificial local variable always has during its |
556273e0 | 8446 | lifetime. We currently have no way to represent such quasi-constant |
6a7a9f01 | 8447 | values in Dwarf, so for now we just punt and generate nothing. */ |
a3f97cbb JW |
8448 | break; |
8449 | ||
8450 | default: | |
8451 | /* No other kinds of rtx should be possible here. */ | |
8452 | abort (); | |
8453 | } | |
8454 | ||
8455 | } | |
8456 | ||
d8041cc8 RH |
8457 | static rtx |
8458 | rtl_for_decl_location (decl) | |
8459 | tree decl; | |
a3f97cbb JW |
8460 | { |
8461 | register rtx rtl; | |
71dfc51f | 8462 | |
a3f97cbb JW |
8463 | /* Here we have to decide where we are going to say the parameter "lives" |
8464 | (as far as the debugger is concerned). We only have a couple of | |
8465 | choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. | |
71dfc51f | 8466 | |
556273e0 | 8467 | DECL_RTL normally indicates where the parameter lives during most of the |
71dfc51f | 8468 | activation of the function. If optimization is enabled however, this |
556273e0 | 8469 | could be either NULL or else a pseudo-reg. Both of those cases indicate |
a3f97cbb JW |
8470 | that the parameter doesn't really live anywhere (as far as the code |
8471 | generation parts of GCC are concerned) during most of the function's | |
8472 | activation. That will happen (for example) if the parameter is never | |
71dfc51f RK |
8473 | referenced within the function. |
8474 | ||
8475 | We could just generate a location descriptor here for all non-NULL | |
8476 | non-pseudo values of DECL_RTL and ignore all of the rest, but we can be | |
8477 | a little nicer than that if we also consider DECL_INCOMING_RTL in cases | |
8478 | where DECL_RTL is NULL or is a pseudo-reg. | |
8479 | ||
8480 | Note however that we can only get away with using DECL_INCOMING_RTL as | |
8481 | a backup substitute for DECL_RTL in certain limited cases. In cases | |
8482 | where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl), | |
8483 | we can be sure that the parameter was passed using the same type as it is | |
8484 | declared to have within the function, and that its DECL_INCOMING_RTL | |
8485 | points us to a place where a value of that type is passed. | |
8486 | ||
8487 | In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different, | |
8488 | we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL | |
8489 | because in these cases DECL_INCOMING_RTL points us to a value of some | |
8490 | type which is *different* from the type of the parameter itself. Thus, | |
8491 | if we tried to use DECL_INCOMING_RTL to generate a location attribute in | |
8492 | such cases, the debugger would end up (for example) trying to fetch a | |
8493 | `float' from a place which actually contains the first part of a | |
8494 | `double'. That would lead to really incorrect and confusing | |
8495 | output at debug-time. | |
8496 | ||
8497 | So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL | |
8498 | in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There | |
8499 | are a couple of exceptions however. On little-endian machines we can | |
8500 | get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is | |
8501 | not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is | |
8502 | an integral type that is smaller than TREE_TYPE (decl). These cases arise | |
8503 | when (on a little-endian machine) a non-prototyped function has a | |
8504 | parameter declared to be of type `short' or `char'. In such cases, | |
8505 | TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will | |
8506 | be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the | |
8507 | passed `int' value. If the debugger then uses that address to fetch | |
8508 | a `short' or a `char' (on a little-endian machine) the result will be | |
8509 | the correct data, so we allow for such exceptional cases below. | |
8510 | ||
8511 | Note that our goal here is to describe the place where the given formal | |
8512 | parameter lives during most of the function's activation (i.e. between | |
8513 | the end of the prologue and the start of the epilogue). We'll do that | |
8514 | as best as we can. Note however that if the given formal parameter is | |
8515 | modified sometime during the execution of the function, then a stack | |
8516 | backtrace (at debug-time) will show the function as having been | |
8517 | called with the *new* value rather than the value which was | |
8518 | originally passed in. This happens rarely enough that it is not | |
8519 | a major problem, but it *is* a problem, and I'd like to fix it. | |
8520 | ||
8521 | A future version of dwarf2out.c may generate two additional | |
8522 | attributes for any given DW_TAG_formal_parameter DIE which will | |
8523 | describe the "passed type" and the "passed location" for the | |
8524 | given formal parameter in addition to the attributes we now | |
8525 | generate to indicate the "declared type" and the "active | |
8526 | location" for each parameter. This additional set of attributes | |
8527 | could be used by debuggers for stack backtraces. Separately, note | |
8528 | that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be | |
8529 | NULL also. This happens (for example) for inlined-instances of | |
8530 | inline function formal parameters which are never referenced. | |
8531 | This really shouldn't be happening. All PARM_DECL nodes should | |
8532 | get valid non-NULL DECL_INCOMING_RTL values, but integrate.c | |
8533 | doesn't currently generate these values for inlined instances of | |
8534 | inline function parameters, so when we see such cases, we are | |
956d6950 | 8535 | just out-of-luck for the time being (until integrate.c |
a3f97cbb JW |
8536 | gets fixed). */ |
8537 | ||
8538 | /* Use DECL_RTL as the "location" unless we find something better. */ | |
110c3568 | 8539 | rtl = DECL_RTL_IF_SET (decl); |
a3f97cbb JW |
8540 | |
8541 | if (TREE_CODE (decl) == PARM_DECL) | |
8542 | { | |
8543 | if (rtl == NULL_RTX || is_pseudo_reg (rtl)) | |
8544 | { | |
d8041cc8 RH |
8545 | tree declared_type = type_main_variant (TREE_TYPE (decl)); |
8546 | tree passed_type = type_main_variant (DECL_ARG_TYPE (decl)); | |
a3f97cbb | 8547 | |
71dfc51f | 8548 | /* This decl represents a formal parameter which was optimized out. |
a3f97cbb JW |
8549 | Note that DECL_INCOMING_RTL may be NULL in here, but we handle |
8550 | all* cases where (rtl == NULL_RTX) just below. */ | |
8551 | if (declared_type == passed_type) | |
71dfc51f RK |
8552 | rtl = DECL_INCOMING_RTL (decl); |
8553 | else if (! BYTES_BIG_ENDIAN | |
8554 | && TREE_CODE (declared_type) == INTEGER_TYPE | |
555b6442 HPN |
8555 | && (GET_MODE_SIZE (TYPE_MODE (declared_type)) |
8556 | <= GET_MODE_SIZE (TYPE_MODE (passed_type)))) | |
556273e0 | 8557 | rtl = DECL_INCOMING_RTL (decl); |
a3f97cbb | 8558 | } |
5a904a61 JW |
8559 | |
8560 | /* If the parm was passed in registers, but lives on the stack, then | |
8561 | make a big endian correction if the mode of the type of the | |
8562 | parameter is not the same as the mode of the rtl. */ | |
8563 | /* ??? This is the same series of checks that are made in dbxout.c before | |
8564 | we reach the big endian correction code there. It isn't clear if all | |
8565 | of these checks are necessary here, but keeping them all is the safe | |
8566 | thing to do. */ | |
8567 | else if (GET_CODE (rtl) == MEM | |
8568 | && XEXP (rtl, 0) != const0_rtx | |
8569 | && ! CONSTANT_P (XEXP (rtl, 0)) | |
8570 | /* Not passed in memory. */ | |
8571 | && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM | |
8572 | /* Not passed by invisible reference. */ | |
8573 | && (GET_CODE (XEXP (rtl, 0)) != REG | |
8574 | || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM | |
8575 | || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM | |
8576 | #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM | |
8577 | || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM | |
8578 | #endif | |
8579 | ) | |
8580 | /* Big endian correction check. */ | |
8581 | && BYTES_BIG_ENDIAN | |
8582 | && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl) | |
8583 | && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))) | |
8584 | < UNITS_PER_WORD)) | |
8585 | { | |
8586 | int offset = (UNITS_PER_WORD | |
8587 | - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))); | |
8588 | rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)), | |
8589 | plus_constant (XEXP (rtl, 0), offset)); | |
8590 | } | |
a3f97cbb | 8591 | } |
71dfc51f | 8592 | |
d8041cc8 RH |
8593 | if (rtl != NULL_RTX) |
8594 | { | |
8595 | rtl = eliminate_regs (rtl, 0, NULL_RTX); | |
6a7a9f01 | 8596 | #ifdef LEAF_REG_REMAP |
d8041cc8 RH |
8597 | if (current_function_uses_only_leaf_regs) |
8598 | leaf_renumber_regs_insn (rtl); | |
6a7a9f01 | 8599 | #endif |
d8041cc8 RH |
8600 | } |
8601 | ||
8602 | return rtl; | |
8603 | } | |
8604 | ||
8605 | /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value | |
8606 | data attribute for a variable or a parameter. We generate the | |
8607 | DW_AT_const_value attribute only in those cases where the given variable | |
8608 | or parameter does not have a true "location" either in memory or in a | |
8609 | register. This can happen (for example) when a constant is passed as an | |
8610 | actual argument in a call to an inline function. (It's possible that | |
8611 | these things can crop up in other ways also.) Note that one type of | |
8612 | constant value which can be passed into an inlined function is a constant | |
8613 | pointer. This can happen for example if an actual argument in an inlined | |
8614 | function call evaluates to a compile-time constant address. */ | |
8615 | ||
8616 | static void | |
8617 | add_location_or_const_value_attribute (die, decl) | |
8618 | register dw_die_ref die; | |
8619 | register tree decl; | |
8620 | { | |
8621 | register rtx rtl; | |
8622 | ||
8623 | if (TREE_CODE (decl) == ERROR_MARK) | |
8624 | return; | |
8625 | ||
8626 | if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL) | |
8627 | abort (); | |
8628 | ||
8629 | rtl = rtl_for_decl_location (decl); | |
a97c9600 RH |
8630 | if (rtl == NULL_RTX) |
8631 | return; | |
6a7a9f01 | 8632 | |
732910b9 RH |
8633 | /* If we don't look past the constant pool, we risk emitting a |
8634 | reference to a constant pool entry that isn't referenced from | |
8635 | code, and thus is not emitted. */ | |
8636 | rtl = avoid_constant_pool_reference (rtl); | |
8637 | ||
a3f97cbb JW |
8638 | switch (GET_CODE (rtl)) |
8639 | { | |
e9a25f70 JL |
8640 | case ADDRESSOF: |
8641 | /* The address of a variable that was optimized away; don't emit | |
8642 | anything. */ | |
8643 | break; | |
8644 | ||
a3f97cbb JW |
8645 | case CONST_INT: |
8646 | case CONST_DOUBLE: | |
8647 | case CONST_STRING: | |
8648 | case SYMBOL_REF: | |
8649 | case LABEL_REF: | |
8650 | case CONST: | |
8651 | case PLUS: | |
8652 | /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ | |
8653 | add_const_value_attribute (die, rtl); | |
8654 | break; | |
8655 | ||
8656 | case MEM: | |
8657 | case REG: | |
8658 | case SUBREG: | |
4401bf24 | 8659 | case CONCAT: |
ef76d03b | 8660 | add_AT_location_description (die, DW_AT_location, rtl); |
a3f97cbb JW |
8661 | break; |
8662 | ||
8663 | default: | |
71dfc51f | 8664 | abort (); |
a3f97cbb JW |
8665 | } |
8666 | } | |
8667 | ||
1bfb5f8f JM |
8668 | /* If we don't have a copy of this variable in memory for some reason (such |
8669 | as a C++ member constant that doesn't have an out-of-line definition), | |
8670 | we should tell the debugger about the constant value. */ | |
8671 | ||
8672 | static void | |
8673 | tree_add_const_value_attribute (var_die, decl) | |
8674 | dw_die_ref var_die; | |
8675 | tree decl; | |
8676 | { | |
8677 | tree init = DECL_INITIAL (decl); | |
8678 | tree type = TREE_TYPE (decl); | |
8679 | ||
8680 | if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init | |
8681 | && initializer_constant_valid_p (init, type) == null_pointer_node) | |
8682 | /* OK */; | |
8683 | else | |
8684 | return; | |
8685 | ||
8686 | switch (TREE_CODE (type)) | |
8687 | { | |
8688 | case INTEGER_TYPE: | |
8689 | if (host_integerp (init, 0)) | |
8690 | add_AT_unsigned (var_die, DW_AT_const_value, | |
8691 | TREE_INT_CST_LOW (init)); | |
8692 | else | |
8693 | add_AT_long_long (var_die, DW_AT_const_value, | |
8694 | TREE_INT_CST_HIGH (init), | |
8695 | TREE_INT_CST_LOW (init)); | |
8696 | break; | |
8697 | ||
8698 | default:; | |
8699 | } | |
8700 | } | |
0b34cf1e | 8701 | |
a3f97cbb JW |
8702 | /* Generate an DW_AT_name attribute given some string value to be included as |
8703 | the value of the attribute. */ | |
71dfc51f RK |
8704 | |
8705 | static inline void | |
a3f97cbb JW |
8706 | add_name_attribute (die, name_string) |
8707 | register dw_die_ref die; | |
d560ee52 | 8708 | register const char *name_string; |
a3f97cbb | 8709 | { |
71dfc51f | 8710 | if (name_string != NULL && *name_string != 0) |
14a774a9 RK |
8711 | { |
8712 | if (demangle_name_func) | |
8713 | name_string = (*demangle_name_func) (name_string); | |
8714 | ||
8715 | add_AT_string (die, DW_AT_name, name_string); | |
8716 | } | |
a3f97cbb JW |
8717 | } |
8718 | ||
8719 | /* Given a tree node describing an array bound (either lower or upper) output | |
466446b0 | 8720 | a representation for that bound. */ |
71dfc51f | 8721 | |
a3f97cbb JW |
8722 | static void |
8723 | add_bound_info (subrange_die, bound_attr, bound) | |
8724 | register dw_die_ref subrange_die; | |
8725 | register enum dwarf_attribute bound_attr; | |
8726 | register tree bound; | |
8727 | { | |
ef76d03b JW |
8728 | /* If this is an Ada unconstrained array type, then don't emit any debug |
8729 | info because the array bounds are unknown. They are parameterized when | |
8730 | the type is instantiated. */ | |
8731 | if (contains_placeholder_p (bound)) | |
8732 | return; | |
8733 | ||
a3f97cbb JW |
8734 | switch (TREE_CODE (bound)) |
8735 | { | |
8736 | case ERROR_MARK: | |
8737 | return; | |
8738 | ||
8739 | /* All fixed-bounds are represented by INTEGER_CST nodes. */ | |
8740 | case INTEGER_CST: | |
665f2503 RK |
8741 | if (! host_integerp (bound, 0) |
8742 | || (bound_attr == DW_AT_lower_bound | |
28985b81 | 8743 | && (((is_c_family () || is_java ()) && integer_zerop (bound)) |
665f2503 RK |
8744 | || (is_fortran () && integer_onep (bound))))) |
8745 | /* use the default */ | |
8746 | ; | |
141719a8 | 8747 | else |
665f2503 | 8748 | add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0)); |
a3f97cbb JW |
8749 | break; |
8750 | ||
b1ccbc24 | 8751 | case CONVERT_EXPR: |
a3f97cbb | 8752 | case NOP_EXPR: |
b1ccbc24 RK |
8753 | case NON_LVALUE_EXPR: |
8754 | add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0)); | |
8755 | break; | |
556273e0 | 8756 | |
a3f97cbb JW |
8757 | case SAVE_EXPR: |
8758 | /* If optimization is turned on, the SAVE_EXPRs that describe how to | |
466446b0 JM |
8759 | access the upper bound values may be bogus. If they refer to a |
8760 | register, they may only describe how to get at these values at the | |
8761 | points in the generated code right after they have just been | |
8762 | computed. Worse yet, in the typical case, the upper bound values | |
8763 | will not even *be* computed in the optimized code (though the | |
8764 | number of elements will), so these SAVE_EXPRs are entirely | |
8765 | bogus. In order to compensate for this fact, we check here to see | |
8766 | if optimization is enabled, and if so, we don't add an attribute | |
8767 | for the (unknown and unknowable) upper bound. This should not | |
8768 | cause too much trouble for existing (stupid?) debuggers because | |
8769 | they have to deal with empty upper bounds location descriptions | |
8770 | anyway in order to be able to deal with incomplete array types. | |
8771 | Of course an intelligent debugger (GDB?) should be able to | |
8772 | comprehend that a missing upper bound specification in a array | |
8773 | type used for a storage class `auto' local array variable | |
8774 | indicates that the upper bound is both unknown (at compile- time) | |
8775 | and unknowable (at run-time) due to optimization. | |
8776 | ||
8777 | We assume that a MEM rtx is safe because gcc wouldn't put the | |
8778 | value there unless it was going to be used repeatedly in the | |
8779 | function, i.e. for cleanups. */ | |
1edf43d6 JM |
8780 | if (SAVE_EXPR_RTL (bound) |
8781 | && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)) | |
a3f97cbb | 8782 | { |
466446b0 JM |
8783 | register dw_die_ref ctx = lookup_decl_die (current_function_decl); |
8784 | register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx); | |
f5963e61 JL |
8785 | register rtx loc = SAVE_EXPR_RTL (bound); |
8786 | ||
8787 | /* If the RTL for the SAVE_EXPR is memory, handle the case where | |
8788 | it references an outer function's frame. */ | |
8789 | ||
8790 | if (GET_CODE (loc) == MEM) | |
8791 | { | |
8792 | rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound); | |
8793 | ||
8794 | if (XEXP (loc, 0) != new_addr) | |
c5c76735 | 8795 | loc = gen_rtx_MEM (GET_MODE (loc), new_addr); |
f5963e61 JL |
8796 | } |
8797 | ||
466446b0 JM |
8798 | add_AT_flag (decl_die, DW_AT_artificial, 1); |
8799 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
f5963e61 | 8800 | add_AT_location_description (decl_die, DW_AT_location, loc); |
466446b0 | 8801 | add_AT_die_ref (subrange_die, bound_attr, decl_die); |
a3f97cbb | 8802 | } |
71dfc51f RK |
8803 | |
8804 | /* Else leave out the attribute. */ | |
a3f97cbb | 8805 | break; |
3f76745e | 8806 | |
ef76d03b | 8807 | case VAR_DECL: |
d8041cc8 RH |
8808 | case PARM_DECL: |
8809 | { | |
8810 | dw_die_ref decl_die = lookup_decl_die (bound); | |
8811 | ||
8812 | /* ??? Can this happen, or should the variable have been bound | |
8813 | first? Probably it can, since I imagine that we try to create | |
8814 | the types of parameters in the order in which they exist in | |
0b34cf1e | 8815 | the list, and won't have created a forward reference to a |
d8041cc8 RH |
8816 | later parameter. */ |
8817 | if (decl_die != NULL) | |
8818 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
8819 | break; | |
8820 | } | |
ef76d03b | 8821 | |
3f76745e | 8822 | default: |
d8041cc8 RH |
8823 | { |
8824 | /* Otherwise try to create a stack operation procedure to | |
8825 | evaluate the value of the array bound. */ | |
8826 | ||
8827 | dw_die_ref ctx, decl_die; | |
8828 | dw_loc_descr_ref loc; | |
8829 | ||
8830 | loc = loc_descriptor_from_tree (bound, 0); | |
8831 | if (loc == NULL) | |
8832 | break; | |
8833 | ||
8834 | ctx = lookup_decl_die (current_function_decl); | |
8835 | ||
8836 | decl_die = new_die (DW_TAG_variable, ctx); | |
8837 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
8838 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
8839 | add_AT_loc (decl_die, DW_AT_location, loc); | |
8840 | ||
8841 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
8842 | break; | |
8843 | } | |
a3f97cbb JW |
8844 | } |
8845 | } | |
8846 | ||
8847 | /* Note that the block of subscript information for an array type also | |
8848 | includes information about the element type of type given array type. */ | |
71dfc51f | 8849 | |
a3f97cbb JW |
8850 | static void |
8851 | add_subscript_info (type_die, type) | |
8852 | register dw_die_ref type_die; | |
8853 | register tree type; | |
8854 | { | |
081f5e7e | 8855 | #ifndef MIPS_DEBUGGING_INFO |
a3f97cbb | 8856 | register unsigned dimension_number; |
081f5e7e | 8857 | #endif |
a3f97cbb JW |
8858 | register tree lower, upper; |
8859 | register dw_die_ref subrange_die; | |
8860 | ||
556273e0 | 8861 | /* The GNU compilers represent multidimensional array types as sequences of |
a3f97cbb JW |
8862 | one dimensional array types whose element types are themselves array |
8863 | types. Here we squish that down, so that each multidimensional array | |
556273e0 | 8864 | type gets only one array_type DIE in the Dwarf debugging info. The draft |
a3f97cbb JW |
8865 | Dwarf specification say that we are allowed to do this kind of |
8866 | compression in C (because there is no difference between an array or | |
556273e0 | 8867 | arrays and a multidimensional array in C) but for other source languages |
a3f97cbb | 8868 | (e.g. Ada) we probably shouldn't do this. */ |
71dfc51f | 8869 | |
a3f97cbb JW |
8870 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
8871 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
8872 | We work around this by disabling this feature. See also | |
8873 | gen_array_type_die. */ | |
8874 | #ifndef MIPS_DEBUGGING_INFO | |
8875 | for (dimension_number = 0; | |
8876 | TREE_CODE (type) == ARRAY_TYPE; | |
8877 | type = TREE_TYPE (type), dimension_number++) | |
8878 | { | |
8879 | #endif | |
8880 | register tree domain = TYPE_DOMAIN (type); | |
8881 | ||
8882 | /* Arrays come in three flavors: Unspecified bounds, fixed bounds, | |
556273e0 | 8883 | and (in GNU C only) variable bounds. Handle all three forms |
a3f97cbb JW |
8884 | here. */ |
8885 | subrange_die = new_die (DW_TAG_subrange_type, type_die); | |
8886 | if (domain) | |
8887 | { | |
8888 | /* We have an array type with specified bounds. */ | |
8889 | lower = TYPE_MIN_VALUE (domain); | |
8890 | upper = TYPE_MAX_VALUE (domain); | |
8891 | ||
a9d38797 JM |
8892 | /* define the index type. */ |
8893 | if (TREE_TYPE (domain)) | |
ef76d03b JW |
8894 | { |
8895 | /* ??? This is probably an Ada unnamed subrange type. Ignore the | |
8896 | TREE_TYPE field. We can't emit debug info for this | |
8897 | because it is an unnamed integral type. */ | |
8898 | if (TREE_CODE (domain) == INTEGER_TYPE | |
8899 | && TYPE_NAME (domain) == NULL_TREE | |
8900 | && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE | |
8901 | && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE) | |
556273e0 | 8902 | ; |
ef76d03b JW |
8903 | else |
8904 | add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0, | |
8905 | type_die); | |
8906 | } | |
a9d38797 | 8907 | |
e1ee5cdc RH |
8908 | /* ??? If upper is NULL, the array has unspecified length, |
8909 | but it does have a lower bound. This happens with Fortran | |
8910 | dimension arr(N:*) | |
8911 | Since the debugger is definitely going to need to know N | |
8912 | to produce useful results, go ahead and output the lower | |
8913 | bound solo, and hope the debugger can cope. */ | |
8914 | ||
141719a8 | 8915 | add_bound_info (subrange_die, DW_AT_lower_bound, lower); |
e1ee5cdc RH |
8916 | if (upper) |
8917 | add_bound_info (subrange_die, DW_AT_upper_bound, upper); | |
a3f97cbb JW |
8918 | } |
8919 | else | |
71dfc51f | 8920 | /* We have an array type with an unspecified length. The DWARF-2 |
a9d38797 JM |
8921 | spec does not say how to handle this; let's just leave out the |
8922 | bounds. */ | |
e49a1d2e | 8923 | {;} |
71dfc51f | 8924 | |
a3f97cbb JW |
8925 | #ifndef MIPS_DEBUGGING_INFO |
8926 | } | |
8927 | #endif | |
8928 | } | |
8929 | ||
8930 | static void | |
8931 | add_byte_size_attribute (die, tree_node) | |
8932 | dw_die_ref die; | |
8933 | register tree tree_node; | |
8934 | { | |
8935 | register unsigned size; | |
8936 | ||
8937 | switch (TREE_CODE (tree_node)) | |
8938 | { | |
8939 | case ERROR_MARK: | |
8940 | size = 0; | |
8941 | break; | |
8942 | case ENUMERAL_TYPE: | |
8943 | case RECORD_TYPE: | |
8944 | case UNION_TYPE: | |
8945 | case QUAL_UNION_TYPE: | |
8946 | size = int_size_in_bytes (tree_node); | |
8947 | break; | |
8948 | case FIELD_DECL: | |
8949 | /* For a data member of a struct or union, the DW_AT_byte_size is | |
8950 | generally given as the number of bytes normally allocated for an | |
8951 | object of the *declared* type of the member itself. This is true | |
8952 | even for bit-fields. */ | |
8953 | size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT; | |
8954 | break; | |
8955 | default: | |
8956 | abort (); | |
8957 | } | |
8958 | ||
8959 | /* Note that `size' might be -1 when we get to this point. If it is, that | |
8960 | indicates that the byte size of the entity in question is variable. We | |
8961 | have no good way of expressing this fact in Dwarf at the present time, | |
8962 | so just let the -1 pass on through. */ | |
8963 | ||
8964 | add_AT_unsigned (die, DW_AT_byte_size, size); | |
8965 | } | |
8966 | ||
8967 | /* For a FIELD_DECL node which represents a bit-field, output an attribute | |
8968 | which specifies the distance in bits from the highest order bit of the | |
8969 | "containing object" for the bit-field to the highest order bit of the | |
8970 | bit-field itself. | |
8971 | ||
b2932ae5 JM |
8972 | For any given bit-field, the "containing object" is a hypothetical |
8973 | object (of some integral or enum type) within which the given bit-field | |
8974 | lives. The type of this hypothetical "containing object" is always the | |
8975 | same as the declared type of the individual bit-field itself. The | |
8976 | determination of the exact location of the "containing object" for a | |
8977 | bit-field is rather complicated. It's handled by the | |
8978 | `field_byte_offset' function (above). | |
a3f97cbb JW |
8979 | |
8980 | Note that it is the size (in bytes) of the hypothetical "containing object" | |
8981 | which will be given in the DW_AT_byte_size attribute for this bit-field. | |
8982 | (See `byte_size_attribute' above). */ | |
71dfc51f RK |
8983 | |
8984 | static inline void | |
a3f97cbb JW |
8985 | add_bit_offset_attribute (die, decl) |
8986 | register dw_die_ref die; | |
8987 | register tree decl; | |
8988 | { | |
665f2503 RK |
8989 | HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl); |
8990 | tree type = DECL_BIT_FIELD_TYPE (decl); | |
8991 | HOST_WIDE_INT bitpos_int; | |
8992 | HOST_WIDE_INT highest_order_object_bit_offset; | |
8993 | HOST_WIDE_INT highest_order_field_bit_offset; | |
8994 | HOST_WIDE_INT unsigned bit_offset; | |
a3f97cbb | 8995 | |
3a88cbd1 JL |
8996 | /* Must be a field and a bit field. */ |
8997 | if (!type | |
8998 | || TREE_CODE (decl) != FIELD_DECL) | |
8999 | abort (); | |
a3f97cbb JW |
9000 | |
9001 | /* We can't yet handle bit-fields whose offsets are variable, so if we | |
9002 | encounter such things, just return without generating any attribute | |
665f2503 RK |
9003 | whatsoever. Likewise for variable or too large size. */ |
9004 | if (! host_integerp (bit_position (decl), 0) | |
9005 | || ! host_integerp (DECL_SIZE (decl), 1)) | |
71dfc51f RK |
9006 | return; |
9007 | ||
665f2503 | 9008 | bitpos_int = int_bit_position (decl); |
a3f97cbb JW |
9009 | |
9010 | /* Note that the bit offset is always the distance (in bits) from the | |
556273e0 KH |
9011 | highest-order bit of the "containing object" to the highest-order bit of |
9012 | the bit-field itself. Since the "high-order end" of any object or field | |
a3f97cbb JW |
9013 | is different on big-endian and little-endian machines, the computation |
9014 | below must take account of these differences. */ | |
9015 | highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; | |
9016 | highest_order_field_bit_offset = bitpos_int; | |
9017 | ||
71dfc51f | 9018 | if (! BYTES_BIG_ENDIAN) |
a3f97cbb | 9019 | { |
665f2503 | 9020 | highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0); |
a3f97cbb JW |
9021 | highest_order_object_bit_offset += simple_type_size_in_bits (type); |
9022 | } | |
71dfc51f RK |
9023 | |
9024 | bit_offset | |
9025 | = (! BYTES_BIG_ENDIAN | |
9026 | ? highest_order_object_bit_offset - highest_order_field_bit_offset | |
9027 | : highest_order_field_bit_offset - highest_order_object_bit_offset); | |
a3f97cbb JW |
9028 | |
9029 | add_AT_unsigned (die, DW_AT_bit_offset, bit_offset); | |
9030 | } | |
9031 | ||
9032 | /* For a FIELD_DECL node which represents a bit field, output an attribute | |
9033 | which specifies the length in bits of the given field. */ | |
71dfc51f RK |
9034 | |
9035 | static inline void | |
a3f97cbb JW |
9036 | add_bit_size_attribute (die, decl) |
9037 | register dw_die_ref die; | |
9038 | register tree decl; | |
9039 | { | |
3a88cbd1 JL |
9040 | /* Must be a field and a bit field. */ |
9041 | if (TREE_CODE (decl) != FIELD_DECL | |
9042 | || ! DECL_BIT_FIELD_TYPE (decl)) | |
9043 | abort (); | |
665f2503 RK |
9044 | |
9045 | if (host_integerp (DECL_SIZE (decl), 1)) | |
9046 | add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1)); | |
a3f97cbb JW |
9047 | } |
9048 | ||
88dad228 | 9049 | /* If the compiled language is ANSI C, then add a 'prototyped' |
a3f97cbb | 9050 | attribute, if arg types are given for the parameters of a function. */ |
71dfc51f RK |
9051 | |
9052 | static inline void | |
a3f97cbb JW |
9053 | add_prototyped_attribute (die, func_type) |
9054 | register dw_die_ref die; | |
9055 | register tree func_type; | |
9056 | { | |
88dad228 JM |
9057 | if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89 |
9058 | && TYPE_ARG_TYPES (func_type) != NULL) | |
9059 | add_AT_flag (die, DW_AT_prototyped, 1); | |
a3f97cbb JW |
9060 | } |
9061 | ||
a3f97cbb JW |
9062 | /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found |
9063 | by looking in either the type declaration or object declaration | |
9064 | equate table. */ | |
71dfc51f RK |
9065 | |
9066 | static inline void | |
a3f97cbb JW |
9067 | add_abstract_origin_attribute (die, origin) |
9068 | register dw_die_ref die; | |
9069 | register tree origin; | |
9070 | { | |
9071 | dw_die_ref origin_die = NULL; | |
bbc6ae08 | 9072 | |
d10b8e05 | 9073 | if (TREE_CODE (origin) != FUNCTION_DECL) |
e40a1c67 JM |
9074 | { |
9075 | /* We may have gotten separated from the block for the inlined | |
9076 | function, if we're in an exception handler or some such; make | |
9077 | sure that the abstract function has been written out. | |
9078 | ||
9079 | Doing this for nested functions is wrong, however; functions are | |
9080 | distinct units, and our context might not even be inline. */ | |
fb13d4d0 JM |
9081 | tree fn = origin; |
9082 | if (TYPE_P (fn)) | |
9083 | fn = TYPE_STUB_DECL (fn); | |
9084 | fn = decl_function_context (fn); | |
e40a1c67 | 9085 | if (fn) |
1edf43d6 | 9086 | dwarf2out_abstract_function (fn); |
e40a1c67 | 9087 | } |
44db1d9c | 9088 | |
2f939d94 | 9089 | if (DECL_P (origin)) |
71dfc51f | 9090 | origin_die = lookup_decl_die (origin); |
2f939d94 | 9091 | else if (TYPE_P (origin)) |
71dfc51f RK |
9092 | origin_die = lookup_type_die (origin); |
9093 | ||
bbc6ae08 | 9094 | if (origin_die == NULL) |
1ae8994f | 9095 | abort (); |
556273e0 | 9096 | |
a3f97cbb JW |
9097 | add_AT_die_ref (die, DW_AT_abstract_origin, origin_die); |
9098 | } | |
9099 | ||
bdb669cb JM |
9100 | /* We do not currently support the pure_virtual attribute. */ |
9101 | ||
71dfc51f | 9102 | static inline void |
a3f97cbb JW |
9103 | add_pure_or_virtual_attribute (die, func_decl) |
9104 | register dw_die_ref die; | |
9105 | register tree func_decl; | |
9106 | { | |
a94dbf2c | 9107 | if (DECL_VINDEX (func_decl)) |
a3f97cbb | 9108 | { |
bdb669cb | 9109 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); |
665f2503 RK |
9110 | |
9111 | if (host_integerp (DECL_VINDEX (func_decl), 0)) | |
9112 | add_AT_loc (die, DW_AT_vtable_elem_location, | |
9113 | new_loc_descr (DW_OP_constu, | |
9114 | tree_low_cst (DECL_VINDEX (func_decl), 0), | |
9115 | 0)); | |
71dfc51f | 9116 | |
a94dbf2c JM |
9117 | /* GNU extension: Record what type this method came from originally. */ |
9118 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
9119 | add_AT_die_ref (die, DW_AT_containing_type, | |
9120 | lookup_type_die (DECL_CONTEXT (func_decl))); | |
a3f97cbb JW |
9121 | } |
9122 | } | |
9123 | \f | |
b2932ae5 | 9124 | /* Add source coordinate attributes for the given decl. */ |
71dfc51f | 9125 | |
b2932ae5 JM |
9126 | static void |
9127 | add_src_coords_attributes (die, decl) | |
9128 | register dw_die_ref die; | |
9129 | register tree decl; | |
9130 | { | |
981975b6 | 9131 | register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
71dfc51f | 9132 | |
b2932ae5 JM |
9133 | add_AT_unsigned (die, DW_AT_decl_file, file_index); |
9134 | add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
9135 | } | |
9136 | ||
a3f97cbb JW |
9137 | /* Add an DW_AT_name attribute and source coordinate attribute for the |
9138 | given decl, but only if it actually has a name. */ | |
71dfc51f | 9139 | |
a3f97cbb JW |
9140 | static void |
9141 | add_name_and_src_coords_attributes (die, decl) | |
9142 | register dw_die_ref die; | |
9143 | register tree decl; | |
9144 | { | |
61b32c02 | 9145 | register tree decl_name; |
71dfc51f | 9146 | |
556273e0 | 9147 | decl_name = DECL_NAME (decl); |
71dfc51f | 9148 | if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL) |
a3f97cbb | 9149 | { |
a1d7ffe3 | 9150 | add_name_attribute (die, dwarf2_name (decl, 0)); |
a96c67ec JM |
9151 | if (! DECL_ARTIFICIAL (decl)) |
9152 | add_src_coords_attributes (die, decl); | |
e689ae67 | 9153 | |
a1d7ffe3 | 9154 | if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) |
bc808e0b | 9155 | && TREE_PUBLIC (decl) |
5daf7c0a JM |
9156 | && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) |
9157 | && !DECL_ABSTRACT (decl)) | |
a1d7ffe3 JM |
9158 | add_AT_string (die, DW_AT_MIPS_linkage_name, |
9159 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
a3f97cbb JW |
9160 | } |
9161 | } | |
9162 | ||
556273e0 | 9163 | /* Push a new declaration scope. */ |
71dfc51f | 9164 | |
a3f97cbb JW |
9165 | static void |
9166 | push_decl_scope (scope) | |
9167 | tree scope; | |
9168 | { | |
9169 | /* Make room in the decl_scope_table, if necessary. */ | |
9170 | if (decl_scope_table_allocated == decl_scope_depth) | |
9171 | { | |
9172 | decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT; | |
71dfc51f | 9173 | decl_scope_table |
777ad4c2 JM |
9174 | = (tree *) xrealloc (decl_scope_table, |
9175 | decl_scope_table_allocated * sizeof (tree)); | |
a3f97cbb | 9176 | } |
71dfc51f | 9177 | |
777ad4c2 | 9178 | decl_scope_table[decl_scope_depth] = scope; |
e3e7774e | 9179 | decl_scope_depth++; |
a3f97cbb JW |
9180 | } |
9181 | ||
777ad4c2 JM |
9182 | /* Pop a declaration scope. */ |
9183 | static inline void | |
9184 | pop_decl_scope () | |
9185 | { | |
9186 | if (decl_scope_depth <= 0) | |
9187 | abort (); | |
9188 | --decl_scope_depth; | |
9189 | } | |
9190 | ||
9191 | /* Return the DIE for the scope that immediately contains this type. | |
9192 | Non-named types get global scope. Named types nested in other | |
9193 | types get their containing scope if it's open, or global scope | |
9194 | otherwise. All other types (i.e. function-local named types) get | |
9195 | the current active scope. */ | |
71dfc51f | 9196 | |
a3f97cbb | 9197 | static dw_die_ref |
ab72d377 | 9198 | scope_die_for (t, context_die) |
556273e0 KH |
9199 | register tree t; |
9200 | register dw_die_ref context_die; | |
a3f97cbb JW |
9201 | { |
9202 | register dw_die_ref scope_die = NULL; | |
9203 | register tree containing_scope; | |
e3e7774e | 9204 | register int i; |
a3f97cbb | 9205 | |
777ad4c2 JM |
9206 | /* Non-types always go in the current scope. */ |
9207 | if (! TYPE_P (t)) | |
9208 | abort (); | |
9209 | ||
9210 | containing_scope = TYPE_CONTEXT (t); | |
ab72d377 | 9211 | |
2addbe1d JM |
9212 | /* Ignore namespaces for the moment. */ |
9213 | if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL) | |
9214 | containing_scope = NULL_TREE; | |
9215 | ||
5f2f160c JM |
9216 | /* Ignore function type "scopes" from the C frontend. They mean that |
9217 | a tagged type is local to a parmlist of a function declarator, but | |
9218 | that isn't useful to DWARF. */ | |
9219 | if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE) | |
9220 | containing_scope = NULL_TREE; | |
9221 | ||
71dfc51f RK |
9222 | if (containing_scope == NULL_TREE) |
9223 | scope_die = comp_unit_die; | |
777ad4c2 | 9224 | else if (TYPE_P (containing_scope)) |
348bb3c7 | 9225 | { |
777ad4c2 JM |
9226 | /* For types, we can just look up the appropriate DIE. But |
9227 | first we check to see if we're in the middle of emitting it | |
9228 | so we know where the new DIE should go. */ | |
348bb3c7 JM |
9229 | |
9230 | for (i = decl_scope_depth - 1; i >= 0; --i) | |
777ad4c2 | 9231 | if (decl_scope_table[i] == containing_scope) |
348bb3c7 JM |
9232 | break; |
9233 | ||
9234 | if (i < 0) | |
9235 | { | |
348bb3c7 JM |
9236 | if (debug_info_level > DINFO_LEVEL_TERSE |
9237 | && !TREE_ASM_WRITTEN (containing_scope)) | |
9238 | abort (); | |
9239 | ||
9240 | /* If none of the current dies are suitable, we get file scope. */ | |
9241 | scope_die = comp_unit_die; | |
9242 | } | |
9243 | else | |
777ad4c2 | 9244 | scope_die = lookup_type_die (containing_scope); |
348bb3c7 | 9245 | } |
a3f97cbb | 9246 | else |
777ad4c2 | 9247 | scope_die = context_die; |
71dfc51f | 9248 | |
a3f97cbb JW |
9249 | return scope_die; |
9250 | } | |
9251 | ||
777ad4c2 JM |
9252 | /* Returns nonzero iff CONTEXT_DIE is internal to a function. */ |
9253 | ||
c6991660 | 9254 | static inline int local_scope_p PARAMS ((dw_die_ref)); |
777ad4c2 JM |
9255 | static inline int |
9256 | local_scope_p (context_die) | |
9257 | dw_die_ref context_die; | |
a3f97cbb | 9258 | { |
777ad4c2 JM |
9259 | for (; context_die; context_die = context_die->die_parent) |
9260 | if (context_die->die_tag == DW_TAG_inlined_subroutine | |
9261 | || context_die->die_tag == DW_TAG_subprogram) | |
9262 | return 1; | |
9263 | return 0; | |
a3f97cbb JW |
9264 | } |
9265 | ||
9765e357 JM |
9266 | /* Returns nonzero iff CONTEXT_DIE is a class. */ |
9267 | ||
c6991660 | 9268 | static inline int class_scope_p PARAMS ((dw_die_ref)); |
9765e357 JM |
9269 | static inline int |
9270 | class_scope_p (context_die) | |
9271 | dw_die_ref context_die; | |
9272 | { | |
9273 | return (context_die | |
9274 | && (context_die->die_tag == DW_TAG_structure_type | |
9275 | || context_die->die_tag == DW_TAG_union_type)); | |
9276 | } | |
9277 | ||
a3f97cbb JW |
9278 | /* Many forms of DIEs require a "type description" attribute. This |
9279 | routine locates the proper "type descriptor" die for the type given | |
9280 | by 'type', and adds an DW_AT_type attribute below the given die. */ | |
71dfc51f | 9281 | |
a3f97cbb JW |
9282 | static void |
9283 | add_type_attribute (object_die, type, decl_const, decl_volatile, context_die) | |
9284 | register dw_die_ref object_die; | |
9285 | register tree type; | |
9286 | register int decl_const; | |
9287 | register int decl_volatile; | |
9288 | register dw_die_ref context_die; | |
9289 | { | |
9290 | register enum tree_code code = TREE_CODE (type); | |
a3f97cbb JW |
9291 | register dw_die_ref type_die = NULL; |
9292 | ||
ef76d03b JW |
9293 | /* ??? If this type is an unnamed subrange type of an integral or |
9294 | floating-point type, use the inner type. This is because we have no | |
9295 | support for unnamed types in base_type_die. This can happen if this is | |
9296 | an Ada subrange type. Correct solution is emit a subrange type die. */ | |
b1ccbc24 RK |
9297 | if ((code == INTEGER_TYPE || code == REAL_TYPE) |
9298 | && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0) | |
9299 | type = TREE_TYPE (type), code = TREE_CODE (type); | |
9300 | ||
a3f97cbb | 9301 | if (code == ERROR_MARK) |
b1ccbc24 | 9302 | return; |
a3f97cbb JW |
9303 | |
9304 | /* Handle a special case. For functions whose return type is void, we | |
9305 | generate *no* type attribute. (Note that no object may have type | |
9306 | `void', so this only applies to function return types). */ | |
9307 | if (code == VOID_TYPE) | |
b1ccbc24 | 9308 | return; |
a3f97cbb | 9309 | |
a3f97cbb JW |
9310 | type_die = modified_type_die (type, |
9311 | decl_const || TYPE_READONLY (type), | |
9312 | decl_volatile || TYPE_VOLATILE (type), | |
ab72d377 | 9313 | context_die); |
a3f97cbb | 9314 | if (type_die != NULL) |
71dfc51f | 9315 | add_AT_die_ref (object_die, DW_AT_type, type_die); |
a3f97cbb JW |
9316 | } |
9317 | ||
9318 | /* Given a tree pointer to a struct, class, union, or enum type node, return | |
9319 | a pointer to the (string) tag name for the given type, or zero if the type | |
9320 | was declared without a tag. */ | |
71dfc51f | 9321 | |
d3e3972c | 9322 | static const char * |
a3f97cbb JW |
9323 | type_tag (type) |
9324 | register tree type; | |
9325 | { | |
d3e3972c | 9326 | register const char *name = 0; |
a3f97cbb JW |
9327 | |
9328 | if (TYPE_NAME (type) != 0) | |
9329 | { | |
9330 | register tree t = 0; | |
9331 | ||
9332 | /* Find the IDENTIFIER_NODE for the type name. */ | |
9333 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
9334 | t = TYPE_NAME (type); | |
bdb669cb | 9335 | |
556273e0 | 9336 | /* The g++ front end makes the TYPE_NAME of *each* tagged type point to |
a3f97cbb | 9337 | a TYPE_DECL node, regardless of whether or not a `typedef' was |
bdb669cb | 9338 | involved. */ |
a94dbf2c JM |
9339 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
9340 | && ! DECL_IGNORED_P (TYPE_NAME (type))) | |
a3f97cbb | 9341 | t = DECL_NAME (TYPE_NAME (type)); |
bdb669cb | 9342 | |
a3f97cbb JW |
9343 | /* Now get the name as a string, or invent one. */ |
9344 | if (t != 0) | |
a94dbf2c | 9345 | name = IDENTIFIER_POINTER (t); |
a3f97cbb | 9346 | } |
71dfc51f | 9347 | |
a3f97cbb JW |
9348 | return (name == 0 || *name == '\0') ? 0 : name; |
9349 | } | |
9350 | ||
9351 | /* Return the type associated with a data member, make a special check | |
9352 | for bit field types. */ | |
71dfc51f RK |
9353 | |
9354 | static inline tree | |
a3f97cbb JW |
9355 | member_declared_type (member) |
9356 | register tree member; | |
9357 | { | |
71dfc51f RK |
9358 | return (DECL_BIT_FIELD_TYPE (member) |
9359 | ? DECL_BIT_FIELD_TYPE (member) | |
9360 | : TREE_TYPE (member)); | |
a3f97cbb JW |
9361 | } |
9362 | ||
d291dd49 | 9363 | /* Get the decl's label, as described by its RTL. This may be different |
a3f97cbb | 9364 | from the DECL_NAME name used in the source file. */ |
71dfc51f | 9365 | |
487a6e06 | 9366 | #if 0 |
d3e3972c | 9367 | static const char * |
d291dd49 | 9368 | decl_start_label (decl) |
a3f97cbb JW |
9369 | register tree decl; |
9370 | { | |
9371 | rtx x; | |
d3e3972c | 9372 | const char *fnname; |
a3f97cbb JW |
9373 | x = DECL_RTL (decl); |
9374 | if (GET_CODE (x) != MEM) | |
71dfc51f RK |
9375 | abort (); |
9376 | ||
a3f97cbb JW |
9377 | x = XEXP (x, 0); |
9378 | if (GET_CODE (x) != SYMBOL_REF) | |
71dfc51f RK |
9379 | abort (); |
9380 | ||
a3f97cbb JW |
9381 | fnname = XSTR (x, 0); |
9382 | return fnname; | |
9383 | } | |
487a6e06 | 9384 | #endif |
a3f97cbb | 9385 | \f |
956d6950 | 9386 | /* These routines generate the internal representation of the DIE's for |
a3f97cbb | 9387 | the compilation unit. Debugging information is collected by walking |
88dad228 | 9388 | the declaration trees passed in from dwarf2out_decl(). */ |
a3f97cbb JW |
9389 | |
9390 | static void | |
9391 | gen_array_type_die (type, context_die) | |
9392 | register tree type; | |
9393 | register dw_die_ref context_die; | |
9394 | { | |
ab72d377 | 9395 | register dw_die_ref scope_die = scope_die_for (type, context_die); |
a9d38797 | 9396 | register dw_die_ref array_die; |
a3f97cbb | 9397 | register tree element_type; |
bdb669cb | 9398 | |
a9d38797 JM |
9399 | /* ??? The SGI dwarf reader fails for array of array of enum types unless |
9400 | the inner array type comes before the outer array type. Thus we must | |
9401 | call gen_type_die before we call new_die. See below also. */ | |
9402 | #ifdef MIPS_DEBUGGING_INFO | |
9403 | gen_type_die (TREE_TYPE (type), context_die); | |
9404 | #endif | |
9405 | ||
9406 | array_die = new_die (DW_TAG_array_type, scope_die); | |
9407 | ||
a3f97cbb JW |
9408 | #if 0 |
9409 | /* We default the array ordering. SDB will probably do | |
9410 | the right things even if DW_AT_ordering is not present. It's not even | |
9411 | an issue until we start to get into multidimensional arrays anyway. If | |
9412 | SDB is ever caught doing the Wrong Thing for multi-dimensional arrays, | |
9413 | then we'll have to put the DW_AT_ordering attribute back in. (But if | |
9414 | and when we find out that we need to put these in, we will only do so | |
9415 | for multidimensional arrays. */ | |
9416 | add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major); | |
9417 | #endif | |
9418 | ||
a9d38797 | 9419 | #ifdef MIPS_DEBUGGING_INFO |
4edb7b60 JM |
9420 | /* The SGI compilers handle arrays of unknown bound by setting |
9421 | AT_declaration and not emitting any subrange DIEs. */ | |
a9d38797 JM |
9422 | if (! TYPE_DOMAIN (type)) |
9423 | add_AT_unsigned (array_die, DW_AT_declaration, 1); | |
9424 | else | |
9425 | #endif | |
9426 | add_subscript_info (array_die, type); | |
a3f97cbb | 9427 | |
14a774a9 | 9428 | add_name_attribute (array_die, type_tag (type)); |
a3f97cbb JW |
9429 | equate_type_number_to_die (type, array_die); |
9430 | ||
9431 | /* Add representation of the type of the elements of this array type. */ | |
9432 | element_type = TREE_TYPE (type); | |
71dfc51f | 9433 | |
a3f97cbb JW |
9434 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
9435 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
9436 | We work around this by disabling this feature. See also | |
9437 | add_subscript_info. */ | |
9438 | #ifndef MIPS_DEBUGGING_INFO | |
71dfc51f RK |
9439 | while (TREE_CODE (element_type) == ARRAY_TYPE) |
9440 | element_type = TREE_TYPE (element_type); | |
9441 | ||
a3f97cbb | 9442 | gen_type_die (element_type, context_die); |
a9d38797 | 9443 | #endif |
a3f97cbb JW |
9444 | |
9445 | add_type_attribute (array_die, element_type, 0, 0, context_die); | |
9446 | } | |
9447 | ||
9448 | static void | |
9449 | gen_set_type_die (type, context_die) | |
9450 | register tree type; | |
9451 | register dw_die_ref context_die; | |
9452 | { | |
71dfc51f RK |
9453 | register dw_die_ref type_die |
9454 | = new_die (DW_TAG_set_type, scope_die_for (type, context_die)); | |
9455 | ||
a3f97cbb | 9456 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
9457 | add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die); |
9458 | } | |
9459 | ||
d6f4ec51 | 9460 | #if 0 |
a3f97cbb JW |
9461 | static void |
9462 | gen_entry_point_die (decl, context_die) | |
9463 | register tree decl; | |
9464 | register dw_die_ref context_die; | |
9465 | { | |
9466 | register tree origin = decl_ultimate_origin (decl); | |
9467 | register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die); | |
9468 | if (origin != NULL) | |
71dfc51f | 9469 | add_abstract_origin_attribute (decl_die, origin); |
a3f97cbb JW |
9470 | else |
9471 | { | |
9472 | add_name_and_src_coords_attributes (decl_die, decl); | |
a3f97cbb JW |
9473 | add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)), |
9474 | 0, 0, context_die); | |
9475 | } | |
71dfc51f | 9476 | |
a3f97cbb | 9477 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 9478 | equate_decl_number_to_die (decl, decl_die); |
a3f97cbb | 9479 | else |
71dfc51f | 9480 | add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl)); |
a3f97cbb | 9481 | } |
d6f4ec51 | 9482 | #endif |
a3f97cbb | 9483 | |
8a8c3656 JM |
9484 | /* Remember a type in the incomplete_types_list. */ |
9485 | ||
9486 | static void | |
9487 | add_incomplete_type (type) | |
9488 | tree type; | |
9489 | { | |
9490 | if (incomplete_types == incomplete_types_allocated) | |
9491 | { | |
9492 | incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT; | |
9493 | incomplete_types_list | |
9494 | = (tree *) xrealloc (incomplete_types_list, | |
9495 | sizeof (tree) * incomplete_types_allocated); | |
9496 | } | |
9497 | ||
9498 | incomplete_types_list[incomplete_types++] = type; | |
9499 | } | |
9500 | ||
9501 | /* Walk through the list of incomplete types again, trying once more to | |
9502 | emit full debugging info for them. */ | |
9503 | ||
9504 | static void | |
9505 | retry_incomplete_types () | |
9506 | { | |
9507 | register tree type; | |
9508 | ||
9509 | while (incomplete_types) | |
9510 | { | |
9511 | --incomplete_types; | |
9512 | type = incomplete_types_list[incomplete_types]; | |
9513 | gen_type_die (type, comp_unit_die); | |
9514 | } | |
9515 | } | |
9516 | ||
a3f97cbb | 9517 | /* Generate a DIE to represent an inlined instance of an enumeration type. */ |
71dfc51f | 9518 | |
a3f97cbb JW |
9519 | static void |
9520 | gen_inlined_enumeration_type_die (type, context_die) | |
9521 | register tree type; | |
9522 | register dw_die_ref context_die; | |
9523 | { | |
71dfc51f | 9524 | register dw_die_ref type_die = new_die (DW_TAG_enumeration_type, |
777ad4c2 | 9525 | context_die); |
bbc6ae08 NC |
9526 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9527 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9528 | add_abstract_origin_attribute (type_die, type); |
9529 | } | |
9530 | ||
9531 | /* Generate a DIE to represent an inlined instance of a structure type. */ | |
71dfc51f | 9532 | |
a3f97cbb JW |
9533 | static void |
9534 | gen_inlined_structure_type_die (type, context_die) | |
9535 | register tree type; | |
9536 | register dw_die_ref context_die; | |
9537 | { | |
777ad4c2 JM |
9538 | register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die); |
9539 | ||
bbc6ae08 NC |
9540 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9541 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9542 | add_abstract_origin_attribute (type_die, type); |
9543 | } | |
9544 | ||
9545 | /* Generate a DIE to represent an inlined instance of a union type. */ | |
71dfc51f | 9546 | |
a3f97cbb JW |
9547 | static void |
9548 | gen_inlined_union_type_die (type, context_die) | |
9549 | register tree type; | |
9550 | register dw_die_ref context_die; | |
9551 | { | |
777ad4c2 JM |
9552 | register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die); |
9553 | ||
bbc6ae08 NC |
9554 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9555 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9556 | add_abstract_origin_attribute (type_die, type); |
9557 | } | |
9558 | ||
9559 | /* Generate a DIE to represent an enumeration type. Note that these DIEs | |
9560 | include all of the information about the enumeration values also. Each | |
273dbe67 JM |
9561 | enumerated type name/value is listed as a child of the enumerated type |
9562 | DIE. */ | |
71dfc51f | 9563 | |
a3f97cbb | 9564 | static void |
273dbe67 | 9565 | gen_enumeration_type_die (type, context_die) |
a3f97cbb | 9566 | register tree type; |
a3f97cbb JW |
9567 | register dw_die_ref context_die; |
9568 | { | |
273dbe67 JM |
9569 | register dw_die_ref type_die = lookup_type_die (type); |
9570 | ||
a3f97cbb JW |
9571 | if (type_die == NULL) |
9572 | { | |
9573 | type_die = new_die (DW_TAG_enumeration_type, | |
ab72d377 | 9574 | scope_die_for (type, context_die)); |
a3f97cbb JW |
9575 | equate_type_number_to_die (type, type_die); |
9576 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 9577 | } |
273dbe67 JM |
9578 | else if (! TYPE_SIZE (type)) |
9579 | return; | |
9580 | else | |
9581 | remove_AT (type_die, DW_AT_declaration); | |
9582 | ||
9583 | /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the | |
9584 | given enum type is incomplete, do not generate the DW_AT_byte_size | |
9585 | attribute or the DW_AT_element_list attribute. */ | |
9586 | if (TYPE_SIZE (type)) | |
a3f97cbb | 9587 | { |
273dbe67 | 9588 | register tree link; |
71dfc51f | 9589 | |
a082c85a | 9590 | TREE_ASM_WRITTEN (type) = 1; |
273dbe67 | 9591 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 9592 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 9593 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 9594 | |
ef76d03b JW |
9595 | /* If the first reference to this type was as the return type of an |
9596 | inline function, then it may not have a parent. Fix this now. */ | |
9597 | if (type_die->die_parent == NULL) | |
9598 | add_child_die (scope_die_for (type, context_die), type_die); | |
9599 | ||
273dbe67 JM |
9600 | for (link = TYPE_FIELDS (type); |
9601 | link != NULL; link = TREE_CHAIN (link)) | |
a3f97cbb | 9602 | { |
273dbe67 | 9603 | register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die); |
71dfc51f | 9604 | |
273dbe67 JM |
9605 | add_name_attribute (enum_die, |
9606 | IDENTIFIER_POINTER (TREE_PURPOSE (link))); | |
665f2503 RK |
9607 | |
9608 | if (host_integerp (TREE_VALUE (link), 0)) | |
fc9e8a14 JJ |
9609 | { |
9610 | if (tree_int_cst_sgn (TREE_VALUE (link)) < 0) | |
9611 | add_AT_int (enum_die, DW_AT_const_value, | |
9612 | tree_low_cst (TREE_VALUE (link), 0)); | |
9613 | else | |
9614 | add_AT_unsigned (enum_die, DW_AT_const_value, | |
9615 | tree_low_cst (TREE_VALUE (link), 0)); | |
9616 | } | |
a3f97cbb JW |
9617 | } |
9618 | } | |
273dbe67 JM |
9619 | else |
9620 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a3f97cbb JW |
9621 | } |
9622 | ||
a3f97cbb JW |
9623 | /* Generate a DIE to represent either a real live formal parameter decl or to |
9624 | represent just the type of some formal parameter position in some function | |
9625 | type. | |
71dfc51f | 9626 | |
a3f97cbb JW |
9627 | Note that this routine is a bit unusual because its argument may be a |
9628 | ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which | |
9629 | represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE | |
9630 | node. If it's the former then this function is being called to output a | |
9631 | DIE to represent a formal parameter object (or some inlining thereof). If | |
9632 | it's the latter, then this function is only being called to output a | |
9633 | DW_TAG_formal_parameter DIE to stand as a placeholder for some formal | |
9634 | argument type of some subprogram type. */ | |
71dfc51f | 9635 | |
a94dbf2c | 9636 | static dw_die_ref |
a3f97cbb JW |
9637 | gen_formal_parameter_die (node, context_die) |
9638 | register tree node; | |
9639 | register dw_die_ref context_die; | |
9640 | { | |
71dfc51f RK |
9641 | register dw_die_ref parm_die |
9642 | = new_die (DW_TAG_formal_parameter, context_die); | |
a3f97cbb | 9643 | register tree origin; |
71dfc51f | 9644 | |
a3f97cbb JW |
9645 | switch (TREE_CODE_CLASS (TREE_CODE (node))) |
9646 | { | |
a3f97cbb JW |
9647 | case 'd': |
9648 | origin = decl_ultimate_origin (node); | |
9649 | if (origin != NULL) | |
a94dbf2c | 9650 | add_abstract_origin_attribute (parm_die, origin); |
a3f97cbb JW |
9651 | else |
9652 | { | |
9653 | add_name_and_src_coords_attributes (parm_die, node); | |
9654 | add_type_attribute (parm_die, TREE_TYPE (node), | |
9655 | TREE_READONLY (node), | |
9656 | TREE_THIS_VOLATILE (node), | |
9657 | context_die); | |
bdb669cb JM |
9658 | if (DECL_ARTIFICIAL (node)) |
9659 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb | 9660 | } |
71dfc51f | 9661 | |
141719a8 JM |
9662 | equate_decl_number_to_die (node, parm_die); |
9663 | if (! DECL_ABSTRACT (node)) | |
a94dbf2c | 9664 | add_location_or_const_value_attribute (parm_die, node); |
71dfc51f | 9665 | |
a3f97cbb JW |
9666 | break; |
9667 | ||
a3f97cbb | 9668 | case 't': |
71dfc51f | 9669 | /* We were called with some kind of a ..._TYPE node. */ |
a3f97cbb JW |
9670 | add_type_attribute (parm_die, node, 0, 0, context_die); |
9671 | break; | |
9672 | ||
a3f97cbb JW |
9673 | default: |
9674 | abort (); | |
9675 | } | |
71dfc51f | 9676 | |
a94dbf2c | 9677 | return parm_die; |
a3f97cbb JW |
9678 | } |
9679 | ||
9680 | /* Generate a special type of DIE used as a stand-in for a trailing ellipsis | |
9681 | at the end of an (ANSI prototyped) formal parameters list. */ | |
71dfc51f | 9682 | |
a3f97cbb JW |
9683 | static void |
9684 | gen_unspecified_parameters_die (decl_or_type, context_die) | |
2618f955 | 9685 | register tree decl_or_type ATTRIBUTE_UNUSED; |
a3f97cbb JW |
9686 | register dw_die_ref context_die; |
9687 | { | |
487a6e06 | 9688 | new_die (DW_TAG_unspecified_parameters, context_die); |
a3f97cbb JW |
9689 | } |
9690 | ||
9691 | /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a | |
9692 | DW_TAG_unspecified_parameters DIE) to represent the types of the formal | |
9693 | parameters as specified in some function type specification (except for | |
1cfdcc15 | 9694 | those which appear as part of a function *definition*). */ |
71dfc51f | 9695 | |
a3f97cbb JW |
9696 | static void |
9697 | gen_formal_types_die (function_or_method_type, context_die) | |
9698 | register tree function_or_method_type; | |
9699 | register dw_die_ref context_die; | |
9700 | { | |
9701 | register tree link; | |
9702 | register tree formal_type = NULL; | |
5daf7c0a JM |
9703 | register tree first_parm_type; |
9704 | tree arg; | |
a3f97cbb | 9705 | |
5daf7c0a JM |
9706 | if (TREE_CODE (function_or_method_type) == FUNCTION_DECL) |
9707 | { | |
9708 | arg = DECL_ARGUMENTS (function_or_method_type); | |
9709 | function_or_method_type = TREE_TYPE (function_or_method_type); | |
9710 | } | |
9711 | else | |
9712 | arg = NULL_TREE; | |
9713 | ||
9714 | first_parm_type = TYPE_ARG_TYPES (function_or_method_type); | |
a3f97cbb | 9715 | |
556273e0 | 9716 | /* Make our first pass over the list of formal parameter types and output a |
a3f97cbb | 9717 | DW_TAG_formal_parameter DIE for each one. */ |
5daf7c0a | 9718 | for (link = first_parm_type; link; ) |
a3f97cbb | 9719 | { |
a94dbf2c | 9720 | register dw_die_ref parm_die; |
556273e0 | 9721 | |
a3f97cbb JW |
9722 | formal_type = TREE_VALUE (link); |
9723 | if (formal_type == void_type_node) | |
9724 | break; | |
9725 | ||
9726 | /* Output a (nameless) DIE to represent the formal parameter itself. */ | |
a94dbf2c | 9727 | parm_die = gen_formal_parameter_die (formal_type, context_die); |
5daf7c0a JM |
9728 | if ((TREE_CODE (function_or_method_type) == METHOD_TYPE |
9729 | && link == first_parm_type) | |
9730 | || (arg && DECL_ARTIFICIAL (arg))) | |
a94dbf2c | 9731 | add_AT_flag (parm_die, DW_AT_artificial, 1); |
5daf7c0a JM |
9732 | |
9733 | link = TREE_CHAIN (link); | |
9734 | if (arg) | |
9735 | arg = TREE_CHAIN (arg); | |
a3f97cbb JW |
9736 | } |
9737 | ||
9738 | /* If this function type has an ellipsis, add a | |
9739 | DW_TAG_unspecified_parameters DIE to the end of the parameter list. */ | |
9740 | if (formal_type != void_type_node) | |
9741 | gen_unspecified_parameters_die (function_or_method_type, context_die); | |
9742 | ||
556273e0 | 9743 | /* Make our second (and final) pass over the list of formal parameter types |
a3f97cbb JW |
9744 | and output DIEs to represent those types (as necessary). */ |
9745 | for (link = TYPE_ARG_TYPES (function_or_method_type); | |
9746 | link; | |
9747 | link = TREE_CHAIN (link)) | |
9748 | { | |
9749 | formal_type = TREE_VALUE (link); | |
9750 | if (formal_type == void_type_node) | |
9751 | break; | |
9752 | ||
b50c02f9 | 9753 | gen_type_die (formal_type, context_die); |
a3f97cbb JW |
9754 | } |
9755 | } | |
9756 | ||
10a11b75 JM |
9757 | /* We want to generate the DIE for TYPE so that we can generate the |
9758 | die for MEMBER, which has been defined; we will need to refer back | |
9759 | to the member declaration nested within TYPE. If we're trying to | |
9760 | generate minimal debug info for TYPE, processing TYPE won't do the | |
9761 | trick; we need to attach the member declaration by hand. */ | |
9762 | ||
9763 | static void | |
9764 | gen_type_die_for_member (type, member, context_die) | |
9765 | tree type, member; | |
9766 | dw_die_ref context_die; | |
9767 | { | |
9768 | gen_type_die (type, context_die); | |
9769 | ||
9770 | /* If we're trying to avoid duplicate debug info, we may not have | |
9771 | emitted the member decl for this function. Emit it now. */ | |
9772 | if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)) | |
9773 | && ! lookup_decl_die (member)) | |
9774 | { | |
9775 | if (decl_ultimate_origin (member)) | |
9776 | abort (); | |
9777 | ||
9778 | push_decl_scope (type); | |
9779 | if (TREE_CODE (member) == FUNCTION_DECL) | |
9780 | gen_subprogram_die (member, lookup_type_die (type)); | |
9781 | else | |
9782 | gen_variable_die (member, lookup_type_die (type)); | |
9783 | pop_decl_scope (); | |
9784 | } | |
9785 | } | |
9786 | ||
9787 | /* Generate the DWARF2 info for the "abstract" instance | |
9788 | of a function which we may later generate inlined and/or | |
9789 | out-of-line instances of. */ | |
9790 | ||
e1772ac0 | 9791 | static void |
1edf43d6 | 9792 | dwarf2out_abstract_function (decl) |
10a11b75 JM |
9793 | tree decl; |
9794 | { | |
5daf7c0a | 9795 | register dw_die_ref old_die; |
777ad4c2 | 9796 | tree save_fn; |
5daf7c0a JM |
9797 | tree context; |
9798 | int was_abstract = DECL_ABSTRACT (decl); | |
9799 | ||
9800 | /* Make sure we have the actual abstract inline, not a clone. */ | |
9801 | decl = DECL_ORIGIN (decl); | |
10a11b75 | 9802 | |
5daf7c0a | 9803 | old_die = lookup_decl_die (decl); |
10a11b75 JM |
9804 | if (old_die && get_AT_unsigned (old_die, DW_AT_inline)) |
9805 | /* We've already generated the abstract instance. */ | |
9806 | return; | |
9807 | ||
5daf7c0a JM |
9808 | /* Be sure we've emitted the in-class declaration DIE (if any) first, so |
9809 | we don't get confused by DECL_ABSTRACT. */ | |
8458e954 JS |
9810 | if (debug_info_level > DINFO_LEVEL_TERSE) |
9811 | { | |
9812 | context = decl_class_context (decl); | |
9813 | if (context) | |
9814 | gen_type_die_for_member | |
9815 | (context, decl, decl_function_context (decl) ? NULL : comp_unit_die); | |
9816 | } | |
5daf7c0a JM |
9817 | |
9818 | /* Pretend we've just finished compiling this function. */ | |
777ad4c2 JM |
9819 | save_fn = current_function_decl; |
9820 | current_function_decl = decl; | |
9821 | ||
10a11b75 JM |
9822 | set_decl_abstract_flags (decl, 1); |
9823 | dwarf2out_decl (decl); | |
5daf7c0a JM |
9824 | if (! was_abstract) |
9825 | set_decl_abstract_flags (decl, 0); | |
777ad4c2 JM |
9826 | |
9827 | current_function_decl = save_fn; | |
10a11b75 JM |
9828 | } |
9829 | ||
a3f97cbb JW |
9830 | /* Generate a DIE to represent a declared function (either file-scope or |
9831 | block-local). */ | |
71dfc51f | 9832 | |
a3f97cbb JW |
9833 | static void |
9834 | gen_subprogram_die (decl, context_die) | |
9835 | register tree decl; | |
9836 | register dw_die_ref context_die; | |
9837 | { | |
9838 | char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; | |
9839 | register tree origin = decl_ultimate_origin (decl); | |
4b674448 | 9840 | register dw_die_ref subr_die; |
b1ccbc24 | 9841 | register rtx fp_reg; |
a3f97cbb JW |
9842 | register tree fn_arg_types; |
9843 | register tree outer_scope; | |
a94dbf2c | 9844 | register dw_die_ref old_die = lookup_decl_die (decl); |
9765e357 JM |
9845 | register int declaration = (current_function_decl != decl |
9846 | || class_scope_p (context_die)); | |
a3f97cbb | 9847 | |
10a11b75 JM |
9848 | /* Note that it is possible to have both DECL_ABSTRACT and `declaration' |
9849 | be true, if we started to generate the abstract instance of an inline, | |
9850 | decided to output its containing class, and proceeded to emit the | |
9851 | declaration of the inline from the member list for the class. In that | |
9852 | case, `declaration' takes priority; we'll get back to the abstract | |
9853 | instance when we're done with the class. */ | |
9854 | ||
1cfdcc15 JM |
9855 | /* The class-scope declaration DIE must be the primary DIE. */ |
9856 | if (origin && declaration && class_scope_p (context_die)) | |
9857 | { | |
9858 | origin = NULL; | |
9859 | if (old_die) | |
9860 | abort (); | |
9861 | } | |
9862 | ||
a3f97cbb JW |
9863 | if (origin != NULL) |
9864 | { | |
777ad4c2 | 9865 | if (declaration && ! local_scope_p (context_die)) |
10a11b75 JM |
9866 | abort (); |
9867 | ||
8d8238b6 JM |
9868 | /* Fixup die_parent for the abstract instance of a nested |
9869 | inline function. */ | |
9870 | if (old_die && old_die->die_parent == NULL) | |
9871 | add_child_die (context_die, old_die); | |
9872 | ||
4b674448 | 9873 | subr_die = new_die (DW_TAG_subprogram, context_die); |
a3f97cbb JW |
9874 | add_abstract_origin_attribute (subr_die, origin); |
9875 | } | |
bdb669cb JM |
9876 | else if (old_die) |
9877 | { | |
981975b6 | 9878 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
a94dbf2c | 9879 | |
1edf43d6 JM |
9880 | if (!get_AT_flag (old_die, DW_AT_declaration) |
9881 | /* We can have a normal definition following an inline one in the | |
9882 | case of redefinition of GNU C extern inlines. | |
9883 | It seems reasonable to use AT_specification in this case. */ | |
9884 | && !get_AT_unsigned (old_die, DW_AT_inline)) | |
b75ab88b NC |
9885 | { |
9886 | /* ??? This can happen if there is a bug in the program, for | |
9887 | instance, if it has duplicate function definitions. Ideally, | |
9888 | we should detect this case and ignore it. For now, if we have | |
9889 | already reported an error, any error at all, then assume that | |
9890 | we got here because of a input error, not a dwarf2 bug. */ | |
b75ab88b NC |
9891 | if (errorcount) |
9892 | return; | |
9893 | abort (); | |
9894 | } | |
4b674448 JM |
9895 | |
9896 | /* If the definition comes from the same place as the declaration, | |
a94dbf2c JM |
9897 | maybe use the old DIE. We always want the DIE for this function |
9898 | that has the *_pc attributes to be under comp_unit_die so the | |
cb9e9d8d JM |
9899 | debugger can find it. We also need to do this for abstract |
9900 | instances of inlines, since the spec requires the out-of-line copy | |
9901 | to have the same parent. For local class methods, this doesn't | |
9902 | apply; we just use the old DIE. */ | |
9903 | if ((old_die->die_parent == comp_unit_die || context_die == NULL) | |
a96c67ec JM |
9904 | && (DECL_ARTIFICIAL (decl) |
9905 | || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index | |
9906 | && (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 9907 | == (unsigned) DECL_SOURCE_LINE (decl))))) |
bdb669cb | 9908 | { |
4b674448 JM |
9909 | subr_die = old_die; |
9910 | ||
9911 | /* Clear out the declaration attribute and the parm types. */ | |
9912 | remove_AT (subr_die, DW_AT_declaration); | |
9913 | remove_children (subr_die); | |
9914 | } | |
9915 | else | |
9916 | { | |
9917 | subr_die = new_die (DW_TAG_subprogram, context_die); | |
9918 | add_AT_die_ref (subr_die, DW_AT_specification, old_die); | |
bdb669cb JM |
9919 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
9920 | add_AT_unsigned (subr_die, DW_AT_decl_file, file_index); | |
9921 | if (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 9922 | != (unsigned) DECL_SOURCE_LINE (decl)) |
bdb669cb JM |
9923 | add_AT_unsigned |
9924 | (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
9925 | } | |
9926 | } | |
a3f97cbb JW |
9927 | else |
9928 | { | |
777ad4c2 | 9929 | subr_die = new_die (DW_TAG_subprogram, context_die); |
556273e0 | 9930 | |
273dbe67 JM |
9931 | if (TREE_PUBLIC (decl)) |
9932 | add_AT_flag (subr_die, DW_AT_external, 1); | |
71dfc51f | 9933 | |
a3f97cbb | 9934 | add_name_and_src_coords_attributes (subr_die, decl); |
4927276d JM |
9935 | if (debug_info_level > DINFO_LEVEL_TERSE) |
9936 | { | |
9937 | register tree type = TREE_TYPE (decl); | |
71dfc51f | 9938 | |
4927276d JM |
9939 | add_prototyped_attribute (subr_die, type); |
9940 | add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die); | |
9941 | } | |
71dfc51f | 9942 | |
a3f97cbb | 9943 | add_pure_or_virtual_attribute (subr_die, decl); |
273dbe67 JM |
9944 | if (DECL_ARTIFICIAL (decl)) |
9945 | add_AT_flag (subr_die, DW_AT_artificial, 1); | |
a94dbf2c JM |
9946 | if (TREE_PROTECTED (decl)) |
9947 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected); | |
9948 | else if (TREE_PRIVATE (decl)) | |
9949 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 9950 | } |
4edb7b60 | 9951 | |
a94dbf2c JM |
9952 | if (declaration) |
9953 | { | |
1edf43d6 JM |
9954 | if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline))) |
9955 | { | |
9956 | add_AT_flag (subr_die, DW_AT_declaration, 1); | |
9957 | ||
9958 | /* The first time we see a member function, it is in the context of | |
9959 | the class to which it belongs. We make sure of this by emitting | |
9960 | the class first. The next time is the definition, which is | |
9961 | handled above. The two may come from the same source text. */ | |
9962 | if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl)) | |
9963 | equate_decl_number_to_die (decl, subr_die); | |
9964 | } | |
a94dbf2c JM |
9965 | } |
9966 | else if (DECL_ABSTRACT (decl)) | |
a3f97cbb | 9967 | { |
10a11b75 | 9968 | if (DECL_INLINE (decl) && !flag_no_inline) |
61b32c02 | 9969 | { |
10a11b75 JM |
9970 | /* ??? Checking DECL_DEFER_OUTPUT is correct for static |
9971 | inline functions, but not for extern inline functions. | |
9972 | We can't get this completely correct because information | |
9973 | about whether the function was declared inline is not | |
9974 | saved anywhere. */ | |
9975 | if (DECL_DEFER_OUTPUT (decl)) | |
61b32c02 JM |
9976 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined); |
9977 | else | |
10a11b75 | 9978 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined); |
61b32c02 | 9979 | } |
61b32c02 | 9980 | else |
10a11b75 | 9981 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined); |
61b32c02 | 9982 | |
a3f97cbb JW |
9983 | equate_decl_number_to_die (decl, subr_die); |
9984 | } | |
9985 | else if (!DECL_EXTERNAL (decl)) | |
9986 | { | |
1edf43d6 | 9987 | if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline))) |
ba7b35df | 9988 | equate_decl_number_to_die (decl, subr_die); |
71dfc51f | 9989 | |
5c90448c JM |
9990 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL, |
9991 | current_funcdef_number); | |
7d4440be | 9992 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id); |
5c90448c JM |
9993 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, |
9994 | current_funcdef_number); | |
a3f97cbb JW |
9995 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id); |
9996 | ||
d291dd49 JM |
9997 | add_pubname (decl, subr_die); |
9998 | add_arange (decl, subr_die); | |
9999 | ||
a3f97cbb | 10000 | #ifdef MIPS_DEBUGGING_INFO |
a3f97cbb JW |
10001 | /* Add a reference to the FDE for this routine. */ |
10002 | add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde); | |
10003 | #endif | |
10004 | ||
810429b7 JM |
10005 | /* Define the "frame base" location for this routine. We use the |
10006 | frame pointer or stack pointer registers, since the RTL for local | |
10007 | variables is relative to one of them. */ | |
b1ccbc24 RK |
10008 | fp_reg |
10009 | = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx; | |
10010 | add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg)); | |
a3f97cbb | 10011 | |
ef76d03b JW |
10012 | #if 0 |
10013 | /* ??? This fails for nested inline functions, because context_display | |
10014 | is not part of the state saved/restored for inline functions. */ | |
88dad228 | 10015 | if (current_function_needs_context) |
ef76d03b JW |
10016 | add_AT_location_description (subr_die, DW_AT_static_link, |
10017 | lookup_static_chain (decl)); | |
10018 | #endif | |
a3f97cbb JW |
10019 | } |
10020 | ||
10021 | /* Now output descriptions of the arguments for this function. This gets | |
556273e0 | 10022 | (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list |
a3f97cbb JW |
10023 | for a FUNCTION_DECL doesn't indicate cases where there was a trailing |
10024 | `...' at the end of the formal parameter list. In order to find out if | |
10025 | there was a trailing ellipsis or not, we must instead look at the type | |
10026 | associated with the FUNCTION_DECL. This will be a node of type | |
10027 | FUNCTION_TYPE. If the chain of type nodes hanging off of this | |
556273e0 | 10028 | FUNCTION_TYPE node ends with a void_type_node then there should *not* be |
a3f97cbb | 10029 | an ellipsis at the end. */ |
71dfc51f | 10030 | |
a3f97cbb | 10031 | /* In the case where we are describing a mere function declaration, all we |
556273e0 | 10032 | need to do here (and all we *can* do here) is to describe the *types* of |
a3f97cbb | 10033 | its formal parameters. */ |
4927276d | 10034 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 10035 | ; |
4edb7b60 | 10036 | else if (declaration) |
5daf7c0a | 10037 | gen_formal_types_die (decl, subr_die); |
a3f97cbb JW |
10038 | else |
10039 | { | |
10040 | /* Generate DIEs to represent all known formal parameters */ | |
10041 | register tree arg_decls = DECL_ARGUMENTS (decl); | |
10042 | register tree parm; | |
10043 | ||
10044 | /* When generating DIEs, generate the unspecified_parameters DIE | |
10045 | instead if we come across the arg "__builtin_va_alist" */ | |
10046 | for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) | |
71dfc51f RK |
10047 | if (TREE_CODE (parm) == PARM_DECL) |
10048 | { | |
db3cf6fb MS |
10049 | if (DECL_NAME (parm) |
10050 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), | |
10051 | "__builtin_va_alist")) | |
71dfc51f RK |
10052 | gen_unspecified_parameters_die (parm, subr_die); |
10053 | else | |
10054 | gen_decl_die (parm, subr_die); | |
10055 | } | |
a3f97cbb JW |
10056 | |
10057 | /* Decide whether we need a unspecified_parameters DIE at the end. | |
556273e0 | 10058 | There are 2 more cases to do this for: 1) the ansi ... declaration - |
a3f97cbb JW |
10059 | this is detectable when the end of the arg list is not a |
10060 | void_type_node 2) an unprototyped function declaration (not a | |
10061 | definition). This just means that we have no info about the | |
10062 | parameters at all. */ | |
10063 | fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
71dfc51f | 10064 | if (fn_arg_types != NULL) |
a3f97cbb JW |
10065 | { |
10066 | /* this is the prototyped case, check for ... */ | |
10067 | if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) | |
71dfc51f | 10068 | gen_unspecified_parameters_die (decl, subr_die); |
a3f97cbb | 10069 | } |
71dfc51f RK |
10070 | else if (DECL_INITIAL (decl) == NULL_TREE) |
10071 | gen_unspecified_parameters_die (decl, subr_die); | |
a3f97cbb JW |
10072 | } |
10073 | ||
10074 | /* Output Dwarf info for all of the stuff within the body of the function | |
10075 | (if it has one - it may be just a declaration). */ | |
10076 | outer_scope = DECL_INITIAL (decl); | |
10077 | ||
d7248bff JM |
10078 | /* Note that here, `outer_scope' is a pointer to the outermost BLOCK |
10079 | node created to represent a function. This outermost BLOCK actually | |
10080 | represents the outermost binding contour for the function, i.e. the | |
10081 | contour in which the function's formal parameters and labels get | |
10082 | declared. Curiously, it appears that the front end doesn't actually | |
10083 | put the PARM_DECL nodes for the current function onto the BLOCK_VARS | |
10084 | list for this outer scope. (They are strung off of the DECL_ARGUMENTS | |
10085 | list for the function instead.) The BLOCK_VARS list for the | |
10086 | `outer_scope' does provide us with a list of the LABEL_DECL nodes for | |
10087 | the function however, and we output DWARF info for those in | |
10088 | decls_for_scope. Just within the `outer_scope' there will be a BLOCK | |
10089 | node representing the function's outermost pair of curly braces, and | |
10090 | any blocks used for the base and member initializers of a C++ | |
10091 | constructor function. */ | |
4edb7b60 | 10092 | if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK) |
7e23cb16 JM |
10093 | { |
10094 | current_function_has_inlines = 0; | |
10095 | decls_for_scope (outer_scope, subr_die, 0); | |
71dfc51f | 10096 | |
ce61cc73 | 10097 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
7e23cb16 JM |
10098 | if (current_function_has_inlines) |
10099 | { | |
10100 | add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1); | |
10101 | if (! comp_unit_has_inlines) | |
10102 | { | |
10103 | add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1); | |
10104 | comp_unit_has_inlines = 1; | |
10105 | } | |
10106 | } | |
10107 | #endif | |
10108 | } | |
a3f97cbb JW |
10109 | } |
10110 | ||
10111 | /* Generate a DIE to represent a declared data object. */ | |
71dfc51f | 10112 | |
a3f97cbb JW |
10113 | static void |
10114 | gen_variable_die (decl, context_die) | |
10115 | register tree decl; | |
10116 | register dw_die_ref context_die; | |
10117 | { | |
10118 | register tree origin = decl_ultimate_origin (decl); | |
10119 | register dw_die_ref var_die = new_die (DW_TAG_variable, context_die); | |
71dfc51f | 10120 | |
bdb669cb | 10121 | dw_die_ref old_die = lookup_decl_die (decl); |
9765e357 JM |
10122 | int declaration = (DECL_EXTERNAL (decl) |
10123 | || class_scope_p (context_die)); | |
4edb7b60 | 10124 | |
a3f97cbb | 10125 | if (origin != NULL) |
71dfc51f | 10126 | add_abstract_origin_attribute (var_die, origin); |
f76b8156 JW |
10127 | /* Loop unrolling can create multiple blocks that refer to the same |
10128 | static variable, so we must test for the DW_AT_declaration flag. */ | |
10129 | /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to | |
10130 | copy decls and set the DECL_ABSTRACT flag on them instead of | |
10131 | sharing them. */ | |
a20612aa | 10132 | /* ??? Duplicated blocks have been rewritten to use .debug_ranges. */ |
f76b8156 JW |
10133 | else if (old_die && TREE_STATIC (decl) |
10134 | && get_AT_flag (old_die, DW_AT_declaration) == 1) | |
bdb669cb | 10135 | { |
e689ae67 | 10136 | /* This is a definition of a C++ class level static. */ |
bdb669cb JM |
10137 | add_AT_die_ref (var_die, DW_AT_specification, old_die); |
10138 | if (DECL_NAME (decl)) | |
10139 | { | |
981975b6 | 10140 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
71dfc51f | 10141 | |
bdb669cb JM |
10142 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
10143 | add_AT_unsigned (var_die, DW_AT_decl_file, file_index); | |
71dfc51f | 10144 | |
bdb669cb | 10145 | if (get_AT_unsigned (old_die, DW_AT_decl_line) |
556273e0 | 10146 | != (unsigned) DECL_SOURCE_LINE (decl)) |
71dfc51f RK |
10147 | |
10148 | add_AT_unsigned (var_die, DW_AT_decl_line, | |
10149 | DECL_SOURCE_LINE (decl)); | |
bdb669cb JM |
10150 | } |
10151 | } | |
a3f97cbb JW |
10152 | else |
10153 | { | |
10154 | add_name_and_src_coords_attributes (var_die, decl); | |
a3f97cbb JW |
10155 | add_type_attribute (var_die, TREE_TYPE (decl), |
10156 | TREE_READONLY (decl), | |
10157 | TREE_THIS_VOLATILE (decl), context_die); | |
71dfc51f | 10158 | |
273dbe67 JM |
10159 | if (TREE_PUBLIC (decl)) |
10160 | add_AT_flag (var_die, DW_AT_external, 1); | |
71dfc51f | 10161 | |
273dbe67 JM |
10162 | if (DECL_ARTIFICIAL (decl)) |
10163 | add_AT_flag (var_die, DW_AT_artificial, 1); | |
71dfc51f | 10164 | |
a94dbf2c JM |
10165 | if (TREE_PROTECTED (decl)) |
10166 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected); | |
71dfc51f | 10167 | |
a94dbf2c JM |
10168 | else if (TREE_PRIVATE (decl)) |
10169 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 10170 | } |
4edb7b60 JM |
10171 | |
10172 | if (declaration) | |
10173 | add_AT_flag (var_die, DW_AT_declaration, 1); | |
556273e0 | 10174 | |
9765e357 | 10175 | if (class_scope_p (context_die) || DECL_ABSTRACT (decl)) |
4edb7b60 JM |
10176 | equate_decl_number_to_die (decl, var_die); |
10177 | ||
10178 | if (! declaration && ! DECL_ABSTRACT (decl)) | |
a3f97cbb JW |
10179 | { |
10180 | add_location_or_const_value_attribute (var_die, decl); | |
d291dd49 | 10181 | add_pubname (decl, var_die); |
a3f97cbb | 10182 | } |
1bfb5f8f JM |
10183 | else |
10184 | tree_add_const_value_attribute (var_die, decl); | |
a3f97cbb JW |
10185 | } |
10186 | ||
10187 | /* Generate a DIE to represent a label identifier. */ | |
71dfc51f | 10188 | |
a3f97cbb JW |
10189 | static void |
10190 | gen_label_die (decl, context_die) | |
10191 | register tree decl; | |
10192 | register dw_die_ref context_die; | |
10193 | { | |
10194 | register tree origin = decl_ultimate_origin (decl); | |
10195 | register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die); | |
10196 | register rtx insn; | |
10197 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
71dfc51f | 10198 | |
a3f97cbb | 10199 | if (origin != NULL) |
71dfc51f | 10200 | add_abstract_origin_attribute (lbl_die, origin); |
a3f97cbb | 10201 | else |
71dfc51f RK |
10202 | add_name_and_src_coords_attributes (lbl_die, decl); |
10203 | ||
a3f97cbb | 10204 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 10205 | equate_decl_number_to_die (decl, lbl_die); |
a3f97cbb JW |
10206 | else |
10207 | { | |
10208 | insn = DECL_RTL (decl); | |
088e7160 NC |
10209 | |
10210 | /* Deleted labels are programmer specified labels which have been | |
10211 | eliminated because of various optimisations. We still emit them | |
10212 | here so that it is possible to put breakpoints on them. */ | |
10213 | if (GET_CODE (insn) == CODE_LABEL | |
10214 | || ((GET_CODE (insn) == NOTE | |
10215 | && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))) | |
a3f97cbb | 10216 | { |
556273e0 KH |
10217 | /* When optimization is enabled (via -O) some parts of the compiler |
10218 | (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which | |
a3f97cbb JW |
10219 | represent source-level labels which were explicitly declared by |
10220 | the user. This really shouldn't be happening though, so catch | |
10221 | it if it ever does happen. */ | |
10222 | if (INSN_DELETED_P (insn)) | |
71dfc51f RK |
10223 | abort (); |
10224 | ||
66234570 | 10225 | ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn)); |
a3f97cbb JW |
10226 | add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); |
10227 | } | |
10228 | } | |
10229 | } | |
10230 | ||
10231 | /* Generate a DIE for a lexical block. */ | |
71dfc51f | 10232 | |
a3f97cbb | 10233 | static void |
d7248bff | 10234 | gen_lexical_block_die (stmt, context_die, depth) |
a3f97cbb JW |
10235 | register tree stmt; |
10236 | register dw_die_ref context_die; | |
d7248bff | 10237 | int depth; |
a3f97cbb JW |
10238 | { |
10239 | register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die); | |
10240 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
71dfc51f RK |
10241 | |
10242 | if (! BLOCK_ABSTRACT (stmt)) | |
a3f97cbb | 10243 | { |
a20612aa RH |
10244 | if (BLOCK_FRAGMENT_CHAIN (stmt)) |
10245 | { | |
10246 | tree chain; | |
10247 | ||
10248 | add_AT_offset (stmt_die, DW_AT_ranges, add_ranges (stmt)); | |
10249 | ||
10250 | chain = BLOCK_FRAGMENT_CHAIN (stmt); | |
10251 | do | |
10252 | { | |
10253 | add_ranges (chain); | |
10254 | chain = BLOCK_FRAGMENT_CHAIN (chain); | |
10255 | } | |
10256 | while (chain); | |
10257 | add_ranges (NULL); | |
10258 | } | |
10259 | else | |
10260 | { | |
10261 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, | |
10262 | BLOCK_NUMBER (stmt)); | |
10263 | add_AT_lbl_id (stmt_die, DW_AT_low_pc, label); | |
10264 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, | |
10265 | BLOCK_NUMBER (stmt)); | |
10266 | add_AT_lbl_id (stmt_die, DW_AT_high_pc, label); | |
10267 | } | |
a3f97cbb | 10268 | } |
71dfc51f | 10269 | |
d7248bff | 10270 | decls_for_scope (stmt, stmt_die, depth); |
a3f97cbb JW |
10271 | } |
10272 | ||
10273 | /* Generate a DIE for an inlined subprogram. */ | |
71dfc51f | 10274 | |
a3f97cbb | 10275 | static void |
d7248bff | 10276 | gen_inlined_subroutine_die (stmt, context_die, depth) |
a3f97cbb JW |
10277 | register tree stmt; |
10278 | register dw_die_ref context_die; | |
d7248bff | 10279 | int depth; |
a3f97cbb | 10280 | { |
71dfc51f | 10281 | if (! BLOCK_ABSTRACT (stmt)) |
a3f97cbb | 10282 | { |
71dfc51f RK |
10283 | register dw_die_ref subr_die |
10284 | = new_die (DW_TAG_inlined_subroutine, context_die); | |
ab72d377 | 10285 | register tree decl = block_ultimate_origin (stmt); |
d7248bff | 10286 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 10287 | |
10a11b75 | 10288 | /* Emit info for the abstract instance first, if we haven't yet. */ |
1edf43d6 | 10289 | dwarf2out_abstract_function (decl); |
10a11b75 | 10290 | |
ab72d377 | 10291 | add_abstract_origin_attribute (subr_die, decl); |
5c90448c | 10292 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
18c038b9 | 10293 | BLOCK_NUMBER (stmt)); |
a3f97cbb | 10294 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label); |
18c038b9 MM |
10295 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, |
10296 | BLOCK_NUMBER (stmt)); | |
a3f97cbb | 10297 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label); |
d7248bff | 10298 | decls_for_scope (stmt, subr_die, depth); |
7e23cb16 | 10299 | current_function_has_inlines = 1; |
a3f97cbb | 10300 | } |
a3f97cbb JW |
10301 | } |
10302 | ||
10303 | /* Generate a DIE for a field in a record, or structure. */ | |
71dfc51f | 10304 | |
a3f97cbb JW |
10305 | static void |
10306 | gen_field_die (decl, context_die) | |
10307 | register tree decl; | |
10308 | register dw_die_ref context_die; | |
10309 | { | |
10310 | register dw_die_ref decl_die = new_die (DW_TAG_member, context_die); | |
71dfc51f | 10311 | |
a3f97cbb | 10312 | add_name_and_src_coords_attributes (decl_die, decl); |
a3f97cbb JW |
10313 | add_type_attribute (decl_die, member_declared_type (decl), |
10314 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl), | |
10315 | context_die); | |
71dfc51f | 10316 | |
a3f97cbb JW |
10317 | /* If this is a bit field... */ |
10318 | if (DECL_BIT_FIELD_TYPE (decl)) | |
10319 | { | |
10320 | add_byte_size_attribute (decl_die, decl); | |
10321 | add_bit_size_attribute (decl_die, decl); | |
10322 | add_bit_offset_attribute (decl_die, decl); | |
10323 | } | |
71dfc51f | 10324 | |
a94dbf2c JM |
10325 | if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE) |
10326 | add_data_member_location_attribute (decl_die, decl); | |
71dfc51f | 10327 | |
273dbe67 JM |
10328 | if (DECL_ARTIFICIAL (decl)) |
10329 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
71dfc51f | 10330 | |
a94dbf2c JM |
10331 | if (TREE_PROTECTED (decl)) |
10332 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected); | |
71dfc51f | 10333 | |
a94dbf2c JM |
10334 | else if (TREE_PRIVATE (decl)) |
10335 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb JW |
10336 | } |
10337 | ||
ab72d377 JM |
10338 | #if 0 |
10339 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. | |
10340 | Use modified_type_die instead. | |
a3f97cbb JW |
10341 | We keep this code here just in case these types of DIEs may be needed to |
10342 | represent certain things in other languages (e.g. Pascal) someday. */ | |
10343 | static void | |
10344 | gen_pointer_type_die (type, context_die) | |
10345 | register tree type; | |
10346 | register dw_die_ref context_die; | |
10347 | { | |
71dfc51f RK |
10348 | register dw_die_ref ptr_die |
10349 | = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die)); | |
10350 | ||
a3f97cbb | 10351 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 10352 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 10353 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb JW |
10354 | } |
10355 | ||
ab72d377 JM |
10356 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. |
10357 | Use modified_type_die instead. | |
a3f97cbb JW |
10358 | We keep this code here just in case these types of DIEs may be needed to |
10359 | represent certain things in other languages (e.g. Pascal) someday. */ | |
10360 | static void | |
10361 | gen_reference_type_die (type, context_die) | |
10362 | register tree type; | |
10363 | register dw_die_ref context_die; | |
10364 | { | |
71dfc51f RK |
10365 | register dw_die_ref ref_die |
10366 | = new_die (DW_TAG_reference_type, scope_die_for (type, context_die)); | |
10367 | ||
a3f97cbb | 10368 | equate_type_number_to_die (type, ref_die); |
a3f97cbb | 10369 | add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 10370 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb | 10371 | } |
ab72d377 | 10372 | #endif |
a3f97cbb JW |
10373 | |
10374 | /* Generate a DIE for a pointer to a member type. */ | |
10375 | static void | |
10376 | gen_ptr_to_mbr_type_die (type, context_die) | |
10377 | register tree type; | |
10378 | register dw_die_ref context_die; | |
10379 | { | |
71dfc51f RK |
10380 | register dw_die_ref ptr_die |
10381 | = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die)); | |
10382 | ||
a3f97cbb | 10383 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 10384 | add_AT_die_ref (ptr_die, DW_AT_containing_type, |
bdb669cb | 10385 | lookup_type_die (TYPE_OFFSET_BASETYPE (type))); |
a3f97cbb JW |
10386 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
10387 | } | |
10388 | ||
10389 | /* Generate the DIE for the compilation unit. */ | |
71dfc51f | 10390 | |
a96c67ec JM |
10391 | static dw_die_ref |
10392 | gen_compile_unit_die (filename) | |
10393 | register const char *filename; | |
a3f97cbb | 10394 | { |
a96c67ec | 10395 | register dw_die_ref die; |
a3f97cbb | 10396 | char producer[250]; |
d3e3972c | 10397 | const char *wd = getpwd (); |
a96c67ec | 10398 | int language; |
a3f97cbb | 10399 | |
a96c67ec JM |
10400 | die = new_die (DW_TAG_compile_unit, NULL); |
10401 | add_name_attribute (die, filename); | |
bdb669cb | 10402 | |
a96c67ec JM |
10403 | if (wd != NULL && filename[0] != DIR_SEPARATOR) |
10404 | add_AT_string (die, DW_AT_comp_dir, wd); | |
a3f97cbb JW |
10405 | |
10406 | sprintf (producer, "%s %s", language_string, version_string); | |
10407 | ||
10408 | #ifdef MIPS_DEBUGGING_INFO | |
10409 | /* The MIPS/SGI compilers place the 'cc' command line options in the producer | |
10410 | string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do | |
10411 | not appear in the producer string, the debugger reaches the conclusion | |
10412 | that the object file is stripped and has no debugging information. | |
10413 | To get the MIPS/SGI debugger to believe that there is debugging | |
10414 | information in the object file, we add a -g to the producer string. */ | |
4927276d JM |
10415 | if (debug_info_level > DINFO_LEVEL_TERSE) |
10416 | strcat (producer, " -g"); | |
a3f97cbb JW |
10417 | #endif |
10418 | ||
a96c67ec | 10419 | add_AT_string (die, DW_AT_producer, producer); |
a9d38797 | 10420 | |
a3f97cbb | 10421 | if (strcmp (language_string, "GNU C++") == 0) |
a96c67ec | 10422 | language = DW_LANG_C_plus_plus; |
a3f97cbb | 10423 | else if (strcmp (language_string, "GNU Ada") == 0) |
a96c67ec | 10424 | language = DW_LANG_Ada83; |
a9d38797 | 10425 | else if (strcmp (language_string, "GNU F77") == 0) |
a96c67ec | 10426 | language = DW_LANG_Fortran77; |
bc28c45b | 10427 | else if (strcmp (language_string, "GNU Pascal") == 0) |
a96c67ec | 10428 | language = DW_LANG_Pascal83; |
28985b81 AG |
10429 | else if (strcmp (language_string, "GNU Java") == 0) |
10430 | language = DW_LANG_Java; | |
a3f97cbb | 10431 | else if (flag_traditional) |
a96c67ec | 10432 | language = DW_LANG_C; |
a3f97cbb | 10433 | else |
a96c67ec | 10434 | language = DW_LANG_C89; |
a9d38797 | 10435 | |
a96c67ec JM |
10436 | add_AT_unsigned (die, DW_AT_language, language); |
10437 | ||
10438 | return die; | |
a3f97cbb JW |
10439 | } |
10440 | ||
10441 | /* Generate a DIE for a string type. */ | |
71dfc51f | 10442 | |
a3f97cbb JW |
10443 | static void |
10444 | gen_string_type_die (type, context_die) | |
10445 | register tree type; | |
10446 | register dw_die_ref context_die; | |
10447 | { | |
71dfc51f RK |
10448 | register dw_die_ref type_die |
10449 | = new_die (DW_TAG_string_type, scope_die_for (type, context_die)); | |
10450 | ||
bdb669cb | 10451 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
10452 | |
10453 | /* Fudge the string length attribute for now. */ | |
556273e0 | 10454 | |
a3f97cbb | 10455 | /* TODO: add string length info. |
71dfc51f | 10456 | string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type))); |
a3f97cbb JW |
10457 | bound_representation (upper_bound, 0, 'u'); */ |
10458 | } | |
10459 | ||
61b32c02 | 10460 | /* Generate the DIE for a base class. */ |
71dfc51f | 10461 | |
61b32c02 JM |
10462 | static void |
10463 | gen_inheritance_die (binfo, context_die) | |
10464 | register tree binfo; | |
10465 | register dw_die_ref context_die; | |
10466 | { | |
10467 | dw_die_ref die = new_die (DW_TAG_inheritance, context_die); | |
71dfc51f | 10468 | |
61b32c02 JM |
10469 | add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die); |
10470 | add_data_member_location_attribute (die, binfo); | |
71dfc51f | 10471 | |
61b32c02 JM |
10472 | if (TREE_VIA_VIRTUAL (binfo)) |
10473 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); | |
10474 | if (TREE_VIA_PUBLIC (binfo)) | |
10475 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public); | |
10476 | else if (TREE_VIA_PROTECTED (binfo)) | |
10477 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected); | |
10478 | } | |
10479 | ||
956d6950 | 10480 | /* Generate a DIE for a class member. */ |
71dfc51f | 10481 | |
a3f97cbb JW |
10482 | static void |
10483 | gen_member_die (type, context_die) | |
10484 | register tree type; | |
10485 | register dw_die_ref context_die; | |
10486 | { | |
61b32c02 | 10487 | register tree member; |
10a11b75 | 10488 | dw_die_ref child; |
71dfc51f | 10489 | |
a3f97cbb JW |
10490 | /* If this is not an incomplete type, output descriptions of each of its |
10491 | members. Note that as we output the DIEs necessary to represent the | |
10492 | members of this record or union type, we will also be trying to output | |
10493 | DIEs to represent the *types* of those members. However the `type' | |
556273e0 KH |
10494 | function (above) will specifically avoid generating type DIEs for member |
10495 | types *within* the list of member DIEs for this (containing) type execpt | |
a3f97cbb JW |
10496 | for those types (of members) which are explicitly marked as also being |
10497 | members of this (containing) type themselves. The g++ front- end can | |
10498 | force any given type to be treated as a member of some other | |
556273e0 | 10499 | (containing) type by setting the TYPE_CONTEXT of the given (member) type |
a3f97cbb JW |
10500 | to point to the TREE node representing the appropriate (containing) |
10501 | type. */ | |
10502 | ||
61b32c02 JM |
10503 | /* First output info about the base classes. */ |
10504 | if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type)) | |
a3f97cbb | 10505 | { |
61b32c02 JM |
10506 | register tree bases = TYPE_BINFO_BASETYPES (type); |
10507 | register int n_bases = TREE_VEC_LENGTH (bases); | |
10508 | register int i; | |
10509 | ||
10510 | for (i = 0; i < n_bases; i++) | |
10511 | gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die); | |
a3f97cbb JW |
10512 | } |
10513 | ||
61b32c02 JM |
10514 | /* Now output info about the data members and type members. */ |
10515 | for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member)) | |
10a11b75 JM |
10516 | { |
10517 | /* If we thought we were generating minimal debug info for TYPE | |
10518 | and then changed our minds, some of the member declarations | |
10519 | may have already been defined. Don't define them again, but | |
10520 | do put them in the right order. */ | |
10521 | ||
10522 | child = lookup_decl_die (member); | |
10523 | if (child) | |
10524 | splice_child_die (context_die, child); | |
10525 | else | |
10526 | gen_decl_die (member, context_die); | |
10527 | } | |
61b32c02 | 10528 | |
a3f97cbb | 10529 | /* Now output info about the function members (if any). */ |
61b32c02 | 10530 | for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member)) |
10a11b75 | 10531 | { |
5daf7c0a JM |
10532 | /* Don't include clones in the member list. */ |
10533 | if (DECL_ABSTRACT_ORIGIN (member)) | |
10534 | continue; | |
10535 | ||
10a11b75 JM |
10536 | child = lookup_decl_die (member); |
10537 | if (child) | |
10538 | splice_child_die (context_die, child); | |
10539 | else | |
10540 | gen_decl_die (member, context_die); | |
10541 | } | |
a3f97cbb JW |
10542 | } |
10543 | ||
10a11b75 JM |
10544 | /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG |
10545 | is set, we pretend that the type was never defined, so we only get the | |
10546 | member DIEs needed by later specification DIEs. */ | |
71dfc51f | 10547 | |
a3f97cbb | 10548 | static void |
273dbe67 | 10549 | gen_struct_or_union_type_die (type, context_die) |
a3f97cbb | 10550 | register tree type; |
a3f97cbb JW |
10551 | register dw_die_ref context_die; |
10552 | { | |
273dbe67 | 10553 | register dw_die_ref type_die = lookup_type_die (type); |
a082c85a JM |
10554 | register dw_die_ref scope_die = 0; |
10555 | register int nested = 0; | |
10a11b75 | 10556 | int complete = (TYPE_SIZE (type) |
65e1263a JW |
10557 | && (! TYPE_STUB_DECL (type) |
10558 | || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)))); | |
273dbe67 | 10559 | |
10a11b75 | 10560 | if (type_die && ! complete) |
273dbe67 | 10561 | return; |
a082c85a | 10562 | |
71dfc51f | 10563 | if (TYPE_CONTEXT (type) != NULL_TREE |
5f2f160c | 10564 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))) |
a082c85a JM |
10565 | nested = 1; |
10566 | ||
a94dbf2c | 10567 | scope_die = scope_die_for (type, context_die); |
a082c85a JM |
10568 | |
10569 | if (! type_die || (nested && scope_die == comp_unit_die)) | |
273dbe67 | 10570 | /* First occurrence of type or toplevel definition of nested class. */ |
a3f97cbb | 10571 | { |
273dbe67 | 10572 | register dw_die_ref old_die = type_die; |
71dfc51f | 10573 | |
a3f97cbb JW |
10574 | type_die = new_die (TREE_CODE (type) == RECORD_TYPE |
10575 | ? DW_TAG_structure_type : DW_TAG_union_type, | |
a082c85a | 10576 | scope_die); |
a3f97cbb | 10577 | equate_type_number_to_die (type, type_die); |
273dbe67 JM |
10578 | if (old_die) |
10579 | add_AT_die_ref (type_die, DW_AT_specification, old_die); | |
5de0e8d4 JM |
10580 | else |
10581 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 10582 | } |
4b674448 | 10583 | else |
273dbe67 | 10584 | remove_AT (type_die, DW_AT_declaration); |
a3f97cbb JW |
10585 | |
10586 | /* If this type has been completed, then give it a byte_size attribute and | |
10587 | then give a list of members. */ | |
2081603c | 10588 | if (complete) |
a3f97cbb | 10589 | { |
556273e0 | 10590 | /* Prevent infinite recursion in cases where the type of some member of |
a3f97cbb JW |
10591 | this type is expressed in terms of this type itself. */ |
10592 | TREE_ASM_WRITTEN (type) = 1; | |
273dbe67 | 10593 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 10594 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 10595 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 10596 | |
ef76d03b JW |
10597 | /* If the first reference to this type was as the return type of an |
10598 | inline function, then it may not have a parent. Fix this now. */ | |
10599 | if (type_die->die_parent == NULL) | |
10600 | add_child_die (scope_die, type_die); | |
10601 | ||
273dbe67 JM |
10602 | push_decl_scope (type); |
10603 | gen_member_die (type, type_die); | |
10604 | pop_decl_scope (); | |
71dfc51f | 10605 | |
a94dbf2c JM |
10606 | /* GNU extension: Record what type our vtable lives in. */ |
10607 | if (TYPE_VFIELD (type)) | |
10608 | { | |
10609 | tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type)); | |
71dfc51f | 10610 | |
de6e505e JM |
10611 | gen_type_die (vtype, context_die); |
10612 | add_AT_die_ref (type_die, DW_AT_containing_type, | |
10613 | lookup_type_die (vtype)); | |
a94dbf2c | 10614 | } |
a3f97cbb | 10615 | } |
4b674448 | 10616 | else |
8a8c3656 JM |
10617 | { |
10618 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a30d4514 | 10619 | |
9765e357 | 10620 | /* We don't need to do this for function-local types. */ |
f19f17e0 | 10621 | if (! decl_function_context (TYPE_STUB_DECL (type))) |
a30d4514 | 10622 | add_incomplete_type (type); |
8a8c3656 | 10623 | } |
a3f97cbb JW |
10624 | } |
10625 | ||
10626 | /* Generate a DIE for a subroutine _type_. */ | |
71dfc51f | 10627 | |
a3f97cbb JW |
10628 | static void |
10629 | gen_subroutine_type_die (type, context_die) | |
10630 | register tree type; | |
10631 | register dw_die_ref context_die; | |
10632 | { | |
10633 | register tree return_type = TREE_TYPE (type); | |
71dfc51f RK |
10634 | register dw_die_ref subr_die |
10635 | = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die)); | |
10636 | ||
a3f97cbb JW |
10637 | equate_type_number_to_die (type, subr_die); |
10638 | add_prototyped_attribute (subr_die, type); | |
a3f97cbb | 10639 | add_type_attribute (subr_die, return_type, 0, 0, context_die); |
a94dbf2c | 10640 | gen_formal_types_die (type, subr_die); |
a3f97cbb JW |
10641 | } |
10642 | ||
10643 | /* Generate a DIE for a type definition */ | |
71dfc51f | 10644 | |
a3f97cbb JW |
10645 | static void |
10646 | gen_typedef_die (decl, context_die) | |
10647 | register tree decl; | |
10648 | register dw_die_ref context_die; | |
10649 | { | |
a3f97cbb | 10650 | register dw_die_ref type_die; |
a94dbf2c JM |
10651 | register tree origin; |
10652 | ||
10653 | if (TREE_ASM_WRITTEN (decl)) | |
10654 | return; | |
10655 | TREE_ASM_WRITTEN (decl) = 1; | |
10656 | ||
777ad4c2 | 10657 | type_die = new_die (DW_TAG_typedef, context_die); |
a94dbf2c | 10658 | origin = decl_ultimate_origin (decl); |
a3f97cbb | 10659 | if (origin != NULL) |
a94dbf2c | 10660 | add_abstract_origin_attribute (type_die, origin); |
a3f97cbb JW |
10661 | else |
10662 | { | |
a94dbf2c | 10663 | register tree type; |
a3f97cbb | 10664 | add_name_and_src_coords_attributes (type_die, decl); |
a94dbf2c JM |
10665 | if (DECL_ORIGINAL_TYPE (decl)) |
10666 | { | |
10667 | type = DECL_ORIGINAL_TYPE (decl); | |
62e3bf54 JM |
10668 | |
10669 | if (type == TREE_TYPE (decl)) | |
10670 | abort (); | |
10671 | else | |
10672 | equate_type_number_to_die (TREE_TYPE (decl), type_die); | |
a94dbf2c JM |
10673 | } |
10674 | else | |
10675 | type = TREE_TYPE (decl); | |
10676 | add_type_attribute (type_die, type, TREE_READONLY (decl), | |
10677 | TREE_THIS_VOLATILE (decl), context_die); | |
a3f97cbb | 10678 | } |
71dfc51f | 10679 | |
a3f97cbb | 10680 | if (DECL_ABSTRACT (decl)) |
a94dbf2c | 10681 | equate_decl_number_to_die (decl, type_die); |
a3f97cbb JW |
10682 | } |
10683 | ||
10684 | /* Generate a type description DIE. */ | |
71dfc51f | 10685 | |
a3f97cbb JW |
10686 | static void |
10687 | gen_type_die (type, context_die) | |
10688 | register tree type; | |
10689 | register dw_die_ref context_die; | |
10690 | { | |
348bb3c7 JM |
10691 | int need_pop; |
10692 | ||
71dfc51f RK |
10693 | if (type == NULL_TREE || type == error_mark_node) |
10694 | return; | |
a3f97cbb | 10695 | |
38e01259 | 10696 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
10697 | this type (i.e. without any const or volatile qualifiers) so get the |
10698 | main variant (i.e. the unqualified version) of this type now. */ | |
10699 | type = type_main_variant (type); | |
10700 | ||
10701 | if (TREE_ASM_WRITTEN (type)) | |
71dfc51f | 10702 | return; |
a3f97cbb | 10703 | |
a94dbf2c JM |
10704 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
10705 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
556273e0 | 10706 | { |
a94dbf2c JM |
10707 | TREE_ASM_WRITTEN (type) = 1; |
10708 | gen_decl_die (TYPE_NAME (type), context_die); | |
10709 | return; | |
10710 | } | |
10711 | ||
a3f97cbb JW |
10712 | switch (TREE_CODE (type)) |
10713 | { | |
10714 | case ERROR_MARK: | |
10715 | break; | |
10716 | ||
10717 | case POINTER_TYPE: | |
10718 | case REFERENCE_TYPE: | |
956d6950 JL |
10719 | /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This |
10720 | ensures that the gen_type_die recursion will terminate even if the | |
10721 | type is recursive. Recursive types are possible in Ada. */ | |
10722 | /* ??? We could perhaps do this for all types before the switch | |
10723 | statement. */ | |
10724 | TREE_ASM_WRITTEN (type) = 1; | |
10725 | ||
a3f97cbb JW |
10726 | /* For these types, all that is required is that we output a DIE (or a |
10727 | set of DIEs) to represent the "basis" type. */ | |
10728 | gen_type_die (TREE_TYPE (type), context_die); | |
10729 | break; | |
10730 | ||
10731 | case OFFSET_TYPE: | |
556273e0 | 10732 | /* This code is used for C++ pointer-to-data-member types. |
71dfc51f | 10733 | Output a description of the relevant class type. */ |
a3f97cbb | 10734 | gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die); |
71dfc51f | 10735 | |
a3f97cbb JW |
10736 | /* Output a description of the type of the object pointed to. */ |
10737 | gen_type_die (TREE_TYPE (type), context_die); | |
71dfc51f | 10738 | |
a3f97cbb JW |
10739 | /* Now output a DIE to represent this pointer-to-data-member type |
10740 | itself. */ | |
10741 | gen_ptr_to_mbr_type_die (type, context_die); | |
10742 | break; | |
10743 | ||
10744 | case SET_TYPE: | |
10745 | gen_type_die (TYPE_DOMAIN (type), context_die); | |
10746 | gen_set_type_die (type, context_die); | |
10747 | break; | |
10748 | ||
10749 | case FILE_TYPE: | |
10750 | gen_type_die (TREE_TYPE (type), context_die); | |
10751 | abort (); /* No way to represent these in Dwarf yet! */ | |
10752 | break; | |
10753 | ||
10754 | case FUNCTION_TYPE: | |
10755 | /* Force out return type (in case it wasn't forced out already). */ | |
10756 | gen_type_die (TREE_TYPE (type), context_die); | |
10757 | gen_subroutine_type_die (type, context_die); | |
10758 | break; | |
10759 | ||
10760 | case METHOD_TYPE: | |
10761 | /* Force out return type (in case it wasn't forced out already). */ | |
10762 | gen_type_die (TREE_TYPE (type), context_die); | |
10763 | gen_subroutine_type_die (type, context_die); | |
10764 | break; | |
10765 | ||
10766 | case ARRAY_TYPE: | |
10767 | if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE) | |
10768 | { | |
10769 | gen_type_die (TREE_TYPE (type), context_die); | |
10770 | gen_string_type_die (type, context_die); | |
10771 | } | |
10772 | else | |
71dfc51f | 10773 | gen_array_type_die (type, context_die); |
a3f97cbb JW |
10774 | break; |
10775 | ||
4061f623 BS |
10776 | case VECTOR_TYPE: |
10777 | gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die); | |
10778 | break; | |
10779 | ||
a3f97cbb JW |
10780 | case ENUMERAL_TYPE: |
10781 | case RECORD_TYPE: | |
10782 | case UNION_TYPE: | |
10783 | case QUAL_UNION_TYPE: | |
a082c85a | 10784 | /* If this is a nested type whose containing class hasn't been |
348bb3c7 JM |
10785 | written out yet, writing it out will cover this one, too. |
10786 | This does not apply to instantiations of member class templates; | |
10787 | they need to be added to the containing class as they are | |
777ad4c2 | 10788 | generated. FIXME: This hurts the idea of combining type decls |
348bb3c7 JM |
10789 | from multiple TUs, since we can't predict what set of template |
10790 | instantiations we'll get. */ | |
a082c85a | 10791 | if (TYPE_CONTEXT (type) |
5f2f160c | 10792 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) |
a082c85a | 10793 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) |
a94dbf2c JM |
10794 | { |
10795 | gen_type_die (TYPE_CONTEXT (type), context_die); | |
10796 | ||
348bb3c7 | 10797 | if (TREE_ASM_WRITTEN (type)) |
a94dbf2c JM |
10798 | return; |
10799 | ||
10800 | /* If that failed, attach ourselves to the stub. */ | |
10801 | push_decl_scope (TYPE_CONTEXT (type)); | |
10802 | context_die = lookup_type_die (TYPE_CONTEXT (type)); | |
348bb3c7 | 10803 | need_pop = 1; |
a94dbf2c | 10804 | } |
348bb3c7 JM |
10805 | else |
10806 | need_pop = 0; | |
a94dbf2c JM |
10807 | |
10808 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
273dbe67 | 10809 | gen_enumeration_type_die (type, context_die); |
a3f97cbb | 10810 | else |
273dbe67 | 10811 | gen_struct_or_union_type_die (type, context_die); |
4b674448 | 10812 | |
348bb3c7 | 10813 | if (need_pop) |
a94dbf2c JM |
10814 | pop_decl_scope (); |
10815 | ||
4b674448 | 10816 | /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix |
a082c85a JM |
10817 | it up if it is ever completed. gen_*_type_die will set it for us |
10818 | when appropriate. */ | |
10819 | return; | |
a3f97cbb JW |
10820 | |
10821 | case VOID_TYPE: | |
10822 | case INTEGER_TYPE: | |
10823 | case REAL_TYPE: | |
10824 | case COMPLEX_TYPE: | |
10825 | case BOOLEAN_TYPE: | |
10826 | case CHAR_TYPE: | |
10827 | /* No DIEs needed for fundamental types. */ | |
10828 | break; | |
10829 | ||
10830 | case LANG_TYPE: | |
10831 | /* No Dwarf representation currently defined. */ | |
10832 | break; | |
10833 | ||
10834 | default: | |
10835 | abort (); | |
10836 | } | |
10837 | ||
10838 | TREE_ASM_WRITTEN (type) = 1; | |
10839 | } | |
10840 | ||
10841 | /* Generate a DIE for a tagged type instantiation. */ | |
71dfc51f | 10842 | |
a3f97cbb JW |
10843 | static void |
10844 | gen_tagged_type_instantiation_die (type, context_die) | |
10845 | register tree type; | |
10846 | register dw_die_ref context_die; | |
10847 | { | |
71dfc51f RK |
10848 | if (type == NULL_TREE || type == error_mark_node) |
10849 | return; | |
a3f97cbb | 10850 | |
38e01259 | 10851 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
10852 | this type (i.e. without any const or volatile qualifiers) so make sure |
10853 | that we have the main variant (i.e. the unqualified version) of this | |
10854 | type now. */ | |
bbc6ae08 | 10855 | if (type != type_main_variant (type)) |
3a88cbd1 | 10856 | abort (); |
a3f97cbb | 10857 | |
203588e7 | 10858 | /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is |
bbc6ae08 | 10859 | an instance of an unresolved type. */ |
556273e0 | 10860 | |
a3f97cbb JW |
10861 | switch (TREE_CODE (type)) |
10862 | { | |
10863 | case ERROR_MARK: | |
10864 | break; | |
10865 | ||
10866 | case ENUMERAL_TYPE: | |
10867 | gen_inlined_enumeration_type_die (type, context_die); | |
10868 | break; | |
10869 | ||
10870 | case RECORD_TYPE: | |
10871 | gen_inlined_structure_type_die (type, context_die); | |
10872 | break; | |
10873 | ||
10874 | case UNION_TYPE: | |
10875 | case QUAL_UNION_TYPE: | |
10876 | gen_inlined_union_type_die (type, context_die); | |
10877 | break; | |
10878 | ||
10879 | default: | |
71dfc51f | 10880 | abort (); |
a3f97cbb JW |
10881 | } |
10882 | } | |
10883 | ||
10884 | /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the | |
10885 | things which are local to the given block. */ | |
71dfc51f | 10886 | |
a3f97cbb | 10887 | static void |
d7248bff | 10888 | gen_block_die (stmt, context_die, depth) |
a3f97cbb JW |
10889 | register tree stmt; |
10890 | register dw_die_ref context_die; | |
d7248bff | 10891 | int depth; |
a3f97cbb JW |
10892 | { |
10893 | register int must_output_die = 0; | |
10894 | register tree origin; | |
10895 | register tree decl; | |
10896 | register enum tree_code origin_code; | |
10897 | ||
10898 | /* Ignore blocks never really used to make RTL. */ | |
1e7f092a JM |
10899 | if (stmt == NULL_TREE || !TREE_USED (stmt) |
10900 | || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt))) | |
71dfc51f | 10901 | return; |
a3f97cbb | 10902 | |
a20612aa RH |
10903 | /* If the block is one fragment of a non-contiguous block, do not |
10904 | process the variables, since they will have been done by the | |
10905 | origin block. Do process subblocks. */ | |
10906 | if (BLOCK_FRAGMENT_ORIGIN (stmt)) | |
10907 | { | |
10908 | tree sub; | |
10909 | ||
10910 | for (sub= BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub)) | |
10911 | gen_block_die (sub, context_die, depth + 1); | |
10912 | return; | |
10913 | } | |
10914 | ||
a3f97cbb JW |
10915 | /* Determine the "ultimate origin" of this block. This block may be an |
10916 | inlined instance of an inlined instance of inline function, so we have | |
10917 | to trace all of the way back through the origin chain to find out what | |
10918 | sort of node actually served as the original seed for the creation of | |
10919 | the current block. */ | |
10920 | origin = block_ultimate_origin (stmt); | |
10921 | origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; | |
10922 | ||
10923 | /* Determine if we need to output any Dwarf DIEs at all to represent this | |
10924 | block. */ | |
10925 | if (origin_code == FUNCTION_DECL) | |
71dfc51f RK |
10926 | /* The outer scopes for inlinings *must* always be represented. We |
10927 | generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */ | |
10928 | must_output_die = 1; | |
a3f97cbb JW |
10929 | else |
10930 | { | |
10931 | /* In the case where the current block represents an inlining of the | |
556273e0 | 10932 | "body block" of an inline function, we must *NOT* output any DIE for |
a3f97cbb JW |
10933 | this block because we have already output a DIE to represent the |
10934 | whole inlined function scope and the "body block" of any function | |
10935 | doesn't really represent a different scope according to ANSI C | |
10936 | rules. So we check here to make sure that this block does not | |
10937 | represent a "body block inlining" before trying to set the | |
10938 | `must_output_die' flag. */ | |
d7248bff | 10939 | if (! is_body_block (origin ? origin : stmt)) |
a3f97cbb JW |
10940 | { |
10941 | /* Determine if this block directly contains any "significant" | |
10942 | local declarations which we will need to output DIEs for. */ | |
10943 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
71dfc51f RK |
10944 | /* We are not in terse mode so *any* local declaration counts |
10945 | as being a "significant" one. */ | |
10946 | must_output_die = (BLOCK_VARS (stmt) != NULL); | |
a3f97cbb | 10947 | else |
71dfc51f RK |
10948 | /* We are in terse mode, so only local (nested) function |
10949 | definitions count as "significant" local declarations. */ | |
10950 | for (decl = BLOCK_VARS (stmt); | |
10951 | decl != NULL; decl = TREE_CHAIN (decl)) | |
10952 | if (TREE_CODE (decl) == FUNCTION_DECL | |
10953 | && DECL_INITIAL (decl)) | |
a3f97cbb | 10954 | { |
71dfc51f RK |
10955 | must_output_die = 1; |
10956 | break; | |
a3f97cbb | 10957 | } |
a3f97cbb JW |
10958 | } |
10959 | } | |
10960 | ||
10961 | /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block | |
10962 | DIE for any block which contains no significant local declarations at | |
10963 | all. Rather, in such cases we just call `decls_for_scope' so that any | |
10964 | needed Dwarf info for any sub-blocks will get properly generated. Note | |
10965 | that in terse mode, our definition of what constitutes a "significant" | |
10966 | local declaration gets restricted to include only inlined function | |
10967 | instances and local (nested) function definitions. */ | |
10968 | if (must_output_die) | |
10969 | { | |
10970 | if (origin_code == FUNCTION_DECL) | |
71dfc51f | 10971 | gen_inlined_subroutine_die (stmt, context_die, depth); |
a3f97cbb | 10972 | else |
71dfc51f | 10973 | gen_lexical_block_die (stmt, context_die, depth); |
a3f97cbb JW |
10974 | } |
10975 | else | |
d7248bff | 10976 | decls_for_scope (stmt, context_die, depth); |
a3f97cbb JW |
10977 | } |
10978 | ||
10979 | /* Generate all of the decls declared within a given scope and (recursively) | |
9ec36da5 | 10980 | all of its sub-blocks. */ |
71dfc51f | 10981 | |
a3f97cbb | 10982 | static void |
d7248bff | 10983 | decls_for_scope (stmt, context_die, depth) |
a3f97cbb JW |
10984 | register tree stmt; |
10985 | register dw_die_ref context_die; | |
d7248bff | 10986 | int depth; |
a3f97cbb JW |
10987 | { |
10988 | register tree decl; | |
10989 | register tree subblocks; | |
71dfc51f | 10990 | |
a3f97cbb | 10991 | /* Ignore blocks never really used to make RTL. */ |
71dfc51f RK |
10992 | if (stmt == NULL_TREE || ! TREE_USED (stmt)) |
10993 | return; | |
10994 | ||
88dad228 JM |
10995 | /* Output the DIEs to represent all of the data objects and typedefs |
10996 | declared directly within this block but not within any nested | |
10997 | sub-blocks. Also, nested function and tag DIEs have been | |
10998 | generated with a parent of NULL; fix that up now. */ | |
a3f97cbb JW |
10999 | for (decl = BLOCK_VARS (stmt); |
11000 | decl != NULL; decl = TREE_CHAIN (decl)) | |
11001 | { | |
a94dbf2c JM |
11002 | register dw_die_ref die; |
11003 | ||
88dad228 | 11004 | if (TREE_CODE (decl) == FUNCTION_DECL) |
a94dbf2c | 11005 | die = lookup_decl_die (decl); |
88dad228 | 11006 | else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)) |
a94dbf2c JM |
11007 | die = lookup_type_die (TREE_TYPE (decl)); |
11008 | else | |
11009 | die = NULL; | |
11010 | ||
71dfc51f | 11011 | if (die != NULL && die->die_parent == NULL) |
ef76d03b | 11012 | add_child_die (context_die, die); |
88dad228 JM |
11013 | else |
11014 | gen_decl_die (decl, context_die); | |
a3f97cbb JW |
11015 | } |
11016 | ||
11017 | /* Output the DIEs to represent all sub-blocks (and the items declared | |
11018 | therein) of this block. */ | |
11019 | for (subblocks = BLOCK_SUBBLOCKS (stmt); | |
11020 | subblocks != NULL; | |
11021 | subblocks = BLOCK_CHAIN (subblocks)) | |
71dfc51f | 11022 | gen_block_die (subblocks, context_die, depth + 1); |
a3f97cbb JW |
11023 | } |
11024 | ||
a94dbf2c | 11025 | /* Is this a typedef we can avoid emitting? */ |
71dfc51f RK |
11026 | |
11027 | static inline int | |
a94dbf2c JM |
11028 | is_redundant_typedef (decl) |
11029 | register tree decl; | |
11030 | { | |
11031 | if (TYPE_DECL_IS_STUB (decl)) | |
11032 | return 1; | |
71dfc51f | 11033 | |
a94dbf2c JM |
11034 | if (DECL_ARTIFICIAL (decl) |
11035 | && DECL_CONTEXT (decl) | |
11036 | && is_tagged_type (DECL_CONTEXT (decl)) | |
11037 | && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL | |
11038 | && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) | |
11039 | /* Also ignore the artificial member typedef for the class name. */ | |
11040 | return 1; | |
71dfc51f | 11041 | |
a94dbf2c JM |
11042 | return 0; |
11043 | } | |
11044 | ||
a3f97cbb | 11045 | /* Generate Dwarf debug information for a decl described by DECL. */ |
71dfc51f | 11046 | |
a3f97cbb JW |
11047 | static void |
11048 | gen_decl_die (decl, context_die) | |
11049 | register tree decl; | |
11050 | register dw_die_ref context_die; | |
11051 | { | |
11052 | register tree origin; | |
71dfc51f | 11053 | |
a3f97cbb | 11054 | if (TREE_CODE (decl) == ERROR_MARK) |
71dfc51f | 11055 | return; |
a3f97cbb | 11056 | |
fcd7f76b JM |
11057 | /* If this ..._DECL node is marked to be ignored, then ignore it. */ |
11058 | if (DECL_IGNORED_P (decl)) | |
71dfc51f | 11059 | return; |
a3f97cbb | 11060 | |
a3f97cbb JW |
11061 | switch (TREE_CODE (decl)) |
11062 | { | |
11063 | case CONST_DECL: | |
556273e0 | 11064 | /* The individual enumerators of an enum type get output when we output |
a3f97cbb JW |
11065 | the Dwarf representation of the relevant enum type itself. */ |
11066 | break; | |
11067 | ||
11068 | case FUNCTION_DECL: | |
4edb7b60 JM |
11069 | /* Don't output any DIEs to represent mere function declarations, |
11070 | unless they are class members or explicit block externs. */ | |
11071 | if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE | |
777ad4c2 | 11072 | && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl))) |
71dfc51f | 11073 | break; |
bdb669cb | 11074 | |
5daf7c0a JM |
11075 | /* If we're emitting a clone, emit info for the abstract instance. */ |
11076 | if (DECL_ORIGIN (decl) != decl) | |
11077 | dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl)); | |
1cfdcc15 JM |
11078 | /* If we're emitting an out-of-line copy of an inline function, |
11079 | emit info for the abstract instance and set up to refer to it. */ | |
5daf7c0a JM |
11080 | else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl) |
11081 | && ! class_scope_p (context_die) | |
11082 | /* dwarf2out_abstract_function won't emit a die if this is just | |
11083 | a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in | |
11084 | that case, because that works only if we have a die. */ | |
11085 | && DECL_INITIAL (decl) != NULL_TREE) | |
1cfdcc15 | 11086 | { |
1edf43d6 | 11087 | dwarf2out_abstract_function (decl); |
1cfdcc15 JM |
11088 | set_decl_origin_self (decl); |
11089 | } | |
5daf7c0a JM |
11090 | /* Otherwise we're emitting the primary DIE for this decl. */ |
11091 | else if (debug_info_level > DINFO_LEVEL_TERSE) | |
a94dbf2c JM |
11092 | { |
11093 | /* Before we describe the FUNCTION_DECL itself, make sure that we | |
11094 | have described its return type. */ | |
11095 | gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); | |
11096 | ||
2081603c JM |
11097 | /* And its virtual context. */ |
11098 | if (DECL_VINDEX (decl) != NULL_TREE) | |
11099 | gen_type_die (DECL_CONTEXT (decl), context_die); | |
11100 | ||
a94dbf2c JM |
11101 | /* And its containing type. */ |
11102 | origin = decl_class_context (decl); | |
71dfc51f | 11103 | if (origin != NULL_TREE) |
10a11b75 | 11104 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 11105 | } |
a3f97cbb JW |
11106 | |
11107 | /* Now output a DIE to represent the function itself. */ | |
11108 | gen_subprogram_die (decl, context_die); | |
11109 | break; | |
11110 | ||
11111 | case TYPE_DECL: | |
11112 | /* If we are in terse mode, don't generate any DIEs to represent any | |
4927276d | 11113 | actual typedefs. */ |
a3f97cbb | 11114 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 11115 | break; |
a3f97cbb | 11116 | |
556273e0 | 11117 | /* In the special case of a TYPE_DECL node representing the |
5c90448c | 11118 | declaration of some type tag, if the given TYPE_DECL is marked as |
a3f97cbb JW |
11119 | having been instantiated from some other (original) TYPE_DECL node |
11120 | (e.g. one which was generated within the original definition of an | |
11121 | inline function) we have to generate a special (abbreviated) | |
556273e0 | 11122 | DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type |
a3f97cbb | 11123 | DIE here. */ |
2081603c | 11124 | if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE) |
a3f97cbb JW |
11125 | { |
11126 | gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die); | |
11127 | break; | |
11128 | } | |
a3f97cbb | 11129 | |
a94dbf2c JM |
11130 | if (is_redundant_typedef (decl)) |
11131 | gen_type_die (TREE_TYPE (decl), context_die); | |
11132 | else | |
71dfc51f RK |
11133 | /* Output a DIE to represent the typedef itself. */ |
11134 | gen_typedef_die (decl, context_die); | |
a3f97cbb JW |
11135 | break; |
11136 | ||
11137 | case LABEL_DECL: | |
11138 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
71dfc51f | 11139 | gen_label_die (decl, context_die); |
a3f97cbb JW |
11140 | break; |
11141 | ||
11142 | case VAR_DECL: | |
11143 | /* If we are in terse mode, don't generate any DIEs to represent any | |
11144 | variable declarations or definitions. */ | |
11145 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 11146 | break; |
a3f97cbb JW |
11147 | |
11148 | /* Output any DIEs that are needed to specify the type of this data | |
11149 | object. */ | |
11150 | gen_type_die (TREE_TYPE (decl), context_die); | |
11151 | ||
a94dbf2c JM |
11152 | /* And its containing type. */ |
11153 | origin = decl_class_context (decl); | |
71dfc51f | 11154 | if (origin != NULL_TREE) |
10a11b75 | 11155 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 11156 | |
a3f97cbb JW |
11157 | /* Now output the DIE to represent the data object itself. This gets |
11158 | complicated because of the possibility that the VAR_DECL really | |
11159 | represents an inlined instance of a formal parameter for an inline | |
11160 | function. */ | |
11161 | origin = decl_ultimate_origin (decl); | |
71dfc51f RK |
11162 | if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL) |
11163 | gen_formal_parameter_die (decl, context_die); | |
a3f97cbb | 11164 | else |
71dfc51f | 11165 | gen_variable_die (decl, context_die); |
a3f97cbb JW |
11166 | break; |
11167 | ||
11168 | case FIELD_DECL: | |
a94dbf2c JM |
11169 | /* Ignore the nameless fields that are used to skip bits, but |
11170 | handle C++ anonymous unions. */ | |
71dfc51f RK |
11171 | if (DECL_NAME (decl) != NULL_TREE |
11172 | || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE) | |
a3f97cbb JW |
11173 | { |
11174 | gen_type_die (member_declared_type (decl), context_die); | |
11175 | gen_field_die (decl, context_die); | |
11176 | } | |
11177 | break; | |
11178 | ||
11179 | case PARM_DECL: | |
11180 | gen_type_die (TREE_TYPE (decl), context_die); | |
11181 | gen_formal_parameter_die (decl, context_die); | |
11182 | break; | |
11183 | ||
348bb3c7 JM |
11184 | case NAMESPACE_DECL: |
11185 | /* Ignore for now. */ | |
11186 | break; | |
11187 | ||
a3f97cbb JW |
11188 | default: |
11189 | abort (); | |
11190 | } | |
a3f97cbb JW |
11191 | } |
11192 | \f | |
14a774a9 RK |
11193 | /* Add Ada "use" clause information for SGI Workshop debugger. */ |
11194 | ||
11195 | void | |
11196 | dwarf2out_add_library_unit_info (filename, context_list) | |
c6991660 KG |
11197 | const char *filename; |
11198 | const char *context_list; | |
14a774a9 RK |
11199 | { |
11200 | unsigned int file_index; | |
11201 | ||
11202 | if (filename != NULL) | |
11203 | { | |
11204 | dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die); | |
556273e0 | 11205 | tree context_list_decl |
14a774a9 RK |
11206 | = build_decl (LABEL_DECL, get_identifier (context_list), |
11207 | void_type_node); | |
11208 | ||
11209 | TREE_PUBLIC (context_list_decl) = TRUE; | |
11210 | add_name_attribute (unit_die, context_list); | |
981975b6 | 11211 | file_index = lookup_filename (filename); |
14a774a9 RK |
11212 | add_AT_unsigned (unit_die, DW_AT_decl_file, file_index); |
11213 | add_pubname (context_list_decl, unit_die); | |
11214 | } | |
11215 | } | |
11216 | ||
2b85879e NB |
11217 | /* Debug information for a global DECL. Called from toplev.c after |
11218 | compilation proper has finished. */ | |
11219 | static void | |
11220 | dwarf2out_global_decl (decl) | |
11221 | tree decl; | |
11222 | { | |
11223 | /* Output DWARF2 information for file-scope tentative data object | |
11224 | declarations, file-scope (extern) function declarations (which | |
11225 | had no corresponding body) and file-scope tagged type | |
11226 | declarations and definitions which have not yet been forced out. */ | |
11227 | ||
11228 | if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)) | |
11229 | dwarf2out_decl (decl); | |
11230 | } | |
11231 | ||
71dfc51f RK |
11232 | /* Write the debugging output for DECL. */ |
11233 | ||
a3f97cbb | 11234 | void |
88dad228 | 11235 | dwarf2out_decl (decl) |
a3f97cbb | 11236 | register tree decl; |
a3f97cbb | 11237 | { |
88dad228 JM |
11238 | register dw_die_ref context_die = comp_unit_die; |
11239 | ||
a3f97cbb | 11240 | if (TREE_CODE (decl) == ERROR_MARK) |
71dfc51f | 11241 | return; |
a3f97cbb | 11242 | |
fcd7f76b | 11243 | /* If this ..._DECL node is marked to be ignored, then ignore it. */ |
a3f97cbb | 11244 | if (DECL_IGNORED_P (decl)) |
fcd7f76b | 11245 | return; |
a3f97cbb JW |
11246 | |
11247 | switch (TREE_CODE (decl)) | |
11248 | { | |
11249 | case FUNCTION_DECL: | |
556273e0 | 11250 | /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a |
a3f97cbb JW |
11251 | builtin function. Explicit programmer-supplied declarations of |
11252 | these same functions should NOT be ignored however. */ | |
9765e357 | 11253 | if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl)) |
b1ccbc24 | 11254 | return; |
a3f97cbb JW |
11255 | |
11256 | /* What we would really like to do here is to filter out all mere | |
11257 | file-scope declarations of file-scope functions which are never | |
11258 | referenced later within this translation unit (and keep all of ones | |
556273e0 KH |
11259 | that *are* referenced later on) but we aren't clairvoyant, so we have |
11260 | no idea which functions will be referenced in the future (i.e. later | |
a3f97cbb | 11261 | on within the current translation unit). So here we just ignore all |
556273e0 | 11262 | file-scope function declarations which are not also definitions. If |
956d6950 | 11263 | and when the debugger needs to know something about these functions, |
556273e0 | 11264 | it will have to hunt around and find the DWARF information associated |
bbc6ae08 | 11265 | with the definition of the function. Note that we can't just check |
a3f97cbb JW |
11266 | `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent |
11267 | definitions and which ones represent mere declarations. We have to | |
11268 | check `DECL_INITIAL' instead. That's because the C front-end | |
11269 | supports some weird semantics for "extern inline" function | |
11270 | definitions. These can get inlined within the current translation | |
11271 | unit (an thus, we need to generate DWARF info for their abstract | |
11272 | instances so that the DWARF info for the concrete inlined instances | |
556273e0 | 11273 | can have something to refer to) but the compiler never generates any |
a3f97cbb JW |
11274 | out-of-lines instances of such things (despite the fact that they |
11275 | *are* definitions). The important point is that the C front-end | |
11276 | marks these "extern inline" functions as DECL_EXTERNAL, but we need | |
273dbe67 | 11277 | to generate DWARF for them anyway. Note that the C++ front-end also |
a3f97cbb | 11278 | plays some similar games for inline function definitions appearing |
556273e0 | 11279 | within include files which also contain |
a3f97cbb JW |
11280 | `#pragma interface' pragmas. */ |
11281 | if (DECL_INITIAL (decl) == NULL_TREE) | |
b1ccbc24 | 11282 | return; |
88dad228 | 11283 | |
9c6cd30e JM |
11284 | /* If we're a nested function, initially use a parent of NULL; if we're |
11285 | a plain function, this will be fixed up in decls_for_scope. If | |
11286 | we're a method, it will be ignored, since we already have a DIE. */ | |
88dad228 | 11287 | if (decl_function_context (decl)) |
9c6cd30e | 11288 | context_die = NULL; |
88dad228 | 11289 | |
a3f97cbb JW |
11290 | break; |
11291 | ||
11292 | case VAR_DECL: | |
556273e0 | 11293 | /* Ignore this VAR_DECL if it refers to a file-scope extern data object |
a3f97cbb JW |
11294 | declaration and if the declaration was never even referenced from |
11295 | within this entire compilation unit. We suppress these DIEs in | |
11296 | order to save space in the .debug section (by eliminating entries | |
11297 | which are probably useless). Note that we must not suppress | |
11298 | block-local extern declarations (whether used or not) because that | |
11299 | would screw-up the debugger's name lookup mechanism and cause it to | |
11300 | miss things which really ought to be in scope at a given point. */ | |
11301 | if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) | |
71dfc51f | 11302 | return; |
a3f97cbb JW |
11303 | |
11304 | /* If we are in terse mode, don't generate any DIEs to represent any | |
11305 | variable declarations or definitions. */ | |
11306 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 11307 | return; |
a3f97cbb JW |
11308 | break; |
11309 | ||
11310 | case TYPE_DECL: | |
57fb7689 JM |
11311 | /* Don't emit stubs for types unless they are needed by other DIEs. */ |
11312 | if (TYPE_DECL_SUPPRESS_DEBUG (decl)) | |
11313 | return; | |
11314 | ||
a3f97cbb | 11315 | /* Don't bother trying to generate any DIEs to represent any of the |
a9d38797 JM |
11316 | normal built-in types for the language we are compiling. */ |
11317 | if (DECL_SOURCE_LINE (decl) == 0) | |
a94dbf2c JM |
11318 | { |
11319 | /* OK, we need to generate one for `bool' so GDB knows what type | |
11320 | comparisons have. */ | |
11321 | if ((get_AT_unsigned (comp_unit_die, DW_AT_language) | |
11322 | == DW_LANG_C_plus_plus) | |
11323 | && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE) | |
11324 | modified_type_die (TREE_TYPE (decl), 0, 0, NULL); | |
71dfc51f | 11325 | |
a94dbf2c JM |
11326 | return; |
11327 | } | |
a3f97cbb | 11328 | |
88dad228 | 11329 | /* If we are in terse mode, don't generate any DIEs for types. */ |
a3f97cbb | 11330 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 11331 | return; |
88dad228 JM |
11332 | |
11333 | /* If we're a function-scope tag, initially use a parent of NULL; | |
11334 | this will be fixed up in decls_for_scope. */ | |
11335 | if (decl_function_context (decl)) | |
3f76745e | 11336 | context_die = NULL; |
88dad228 | 11337 | |
a3f97cbb JW |
11338 | break; |
11339 | ||
11340 | default: | |
11341 | return; | |
11342 | } | |
11343 | ||
88dad228 | 11344 | gen_decl_die (decl, context_die); |
a3f97cbb JW |
11345 | } |
11346 | ||
11347 | /* Output a marker (i.e. a label) for the beginning of the generated code for | |
11348 | a lexical block. */ | |
71dfc51f | 11349 | |
a5a42b92 | 11350 | static void |
e2a12aca | 11351 | dwarf2out_begin_block (line, blocknum) |
a5a42b92 NB |
11352 | unsigned int line ATTRIBUTE_UNUSED; |
11353 | unsigned int blocknum; | |
a3f97cbb | 11354 | { |
a3f97cbb | 11355 | function_section (current_function_decl); |
8215347e | 11356 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum); |
a3f97cbb JW |
11357 | } |
11358 | ||
11359 | /* Output a marker (i.e. a label) for the end of the generated code for a | |
11360 | lexical block. */ | |
71dfc51f | 11361 | |
a5a42b92 | 11362 | static void |
e2a12aca | 11363 | dwarf2out_end_block (line, blocknum) |
a5a42b92 NB |
11364 | unsigned int line ATTRIBUTE_UNUSED; |
11365 | unsigned int blocknum; | |
a3f97cbb | 11366 | { |
a3f97cbb | 11367 | function_section (current_function_decl); |
8215347e | 11368 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum); |
a3f97cbb JW |
11369 | } |
11370 | ||
64b59a80 JM |
11371 | /* Returns nonzero if it is appropriate not to emit any debugging |
11372 | information for BLOCK, because it doesn't contain any instructions. | |
fcd7f76b | 11373 | |
64b59a80 JM |
11374 | Don't allow this for blocks with nested functions or local classes |
11375 | as we would end up with orphans, and in the presence of scheduling | |
11376 | we may end up calling them anyway. */ | |
11377 | ||
e1772ac0 | 11378 | static bool |
fcd7f76b JM |
11379 | dwarf2out_ignore_block (block) |
11380 | tree block; | |
11381 | { | |
11382 | tree decl; | |
11383 | for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) | |
64b59a80 JM |
11384 | if (TREE_CODE (decl) == FUNCTION_DECL |
11385 | || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))) | |
11386 | return 0; | |
11387 | return 1; | |
fcd7f76b JM |
11388 | } |
11389 | ||
a3f97cbb | 11390 | /* Lookup a filename (in the list of filenames that we know about here in |
9a666dda | 11391 | dwarf2out.c) and return its "index". The index of each (known) filename is |
a3f97cbb JW |
11392 | just a unique number which is associated with only that one filename. |
11393 | We need such numbers for the sake of generating labels | |
11394 | (in the .debug_sfnames section) and references to those | |
11395 | files numbers (in the .debug_srcinfo and.debug_macinfo sections). | |
11396 | If the filename given as an argument is not found in our current list, | |
11397 | add it to the list and assign it the next available unique index number. | |
11398 | In order to speed up searches, we remember the index of the filename | |
11399 | was looked up last. This handles the majority of all searches. */ | |
71dfc51f | 11400 | |
a3f97cbb | 11401 | static unsigned |
981975b6 | 11402 | lookup_filename (file_name) |
d560ee52 | 11403 | const char *file_name; |
a3f97cbb | 11404 | { |
a3f97cbb JW |
11405 | register unsigned i; |
11406 | ||
981975b6 RH |
11407 | /* ??? Why isn't DECL_SOURCE_FILE left null instead. */ |
11408 | if (strcmp (file_name, "<internal>") == 0 | |
11409 | || strcmp (file_name, "<built-in>") == 0) | |
11410 | return 0; | |
11411 | ||
2e18bbae RH |
11412 | /* Check to see if the file name that was searched on the previous |
11413 | call matches this file name. If so, return the index. */ | |
981975b6 RH |
11414 | if (file_table.last_lookup_index != 0) |
11415 | if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0) | |
11416 | return file_table.last_lookup_index; | |
a3f97cbb JW |
11417 | |
11418 | /* Didn't match the previous lookup, search the table */ | |
981975b6 RH |
11419 | for (i = 1; i < file_table.in_use; ++i) |
11420 | if (strcmp (file_name, file_table.table[i]) == 0) | |
71dfc51f | 11421 | { |
981975b6 | 11422 | file_table.last_lookup_index = i; |
71dfc51f RK |
11423 | return i; |
11424 | } | |
a3f97cbb | 11425 | |
556273e0 | 11426 | /* Prepare to add a new table entry by making sure there is enough space in |
a3f97cbb | 11427 | the table to do so. If not, expand the current table. */ |
981975b6 | 11428 | if (i == file_table.allocated) |
a3f97cbb | 11429 | { |
981975b6 RH |
11430 | file_table.allocated = i + FILE_TABLE_INCREMENT; |
11431 | file_table.table = (char **) | |
11432 | xrealloc (file_table.table, file_table.allocated * sizeof (char *)); | |
a3f97cbb JW |
11433 | } |
11434 | ||
71dfc51f | 11435 | /* Add the new entry to the end of the filename table. */ |
981975b6 RH |
11436 | file_table.table[i] = xstrdup (file_name); |
11437 | file_table.in_use = i + 1; | |
11438 | file_table.last_lookup_index = i; | |
2e18bbae | 11439 | |
acc187f5 RH |
11440 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
11441 | fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name); | |
11442 | ||
2e18bbae RH |
11443 | return i; |
11444 | } | |
11445 | ||
11446 | static void | |
981975b6 | 11447 | init_file_table () |
2e18bbae RH |
11448 | { |
11449 | /* Allocate the initial hunk of the file_table. */ | |
981975b6 RH |
11450 | file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *)); |
11451 | file_table.allocated = FILE_TABLE_INCREMENT; | |
71dfc51f | 11452 | |
2e18bbae | 11453 | /* Skip the first entry - file numbers begin at 1. */ |
981975b6 RH |
11454 | file_table.in_use = 1; |
11455 | file_table.last_lookup_index = 0; | |
a3f97cbb JW |
11456 | } |
11457 | ||
11458 | /* Output a label to mark the beginning of a source code line entry | |
11459 | and record information relating to this source line, in | |
11460 | 'line_info_table' for later output of the .debug_line section. */ | |
71dfc51f | 11461 | |
e2a12aca | 11462 | static void |
653e276c NB |
11463 | dwarf2out_source_line (line, filename) |
11464 | unsigned int line; | |
d560ee52 | 11465 | register const char *filename; |
a3f97cbb | 11466 | { |
a3f97cbb JW |
11467 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
11468 | { | |
11469 | function_section (current_function_decl); | |
a3f97cbb | 11470 | |
8aaf55ac JM |
11471 | /* If requested, emit something human-readable. */ |
11472 | if (flag_debug_asm) | |
11473 | fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, | |
11474 | filename, line); | |
11475 | ||
b2244e22 JW |
11476 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
11477 | { | |
981975b6 | 11478 | unsigned file_num = lookup_filename (filename); |
b2244e22 | 11479 | |
981975b6 | 11480 | /* Emit the .loc directive understood by GNU as. */ |
2e18bbae | 11481 | fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line); |
b2244e22 JW |
11482 | |
11483 | /* Indicate that line number info exists. */ | |
11484 | ++line_info_table_in_use; | |
11485 | ||
11486 | /* Indicate that multiple line number tables exist. */ | |
11487 | if (DECL_SECTION_NAME (current_function_decl)) | |
11488 | ++separate_line_info_table_in_use; | |
11489 | } | |
11490 | else if (DECL_SECTION_NAME (current_function_decl)) | |
a3f97cbb | 11491 | { |
e90b62db | 11492 | register dw_separate_line_info_ref line_info; |
5c90448c JM |
11493 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL, |
11494 | separate_line_info_table_in_use); | |
e90b62db JM |
11495 | |
11496 | /* expand the line info table if necessary */ | |
11497 | if (separate_line_info_table_in_use | |
11498 | == separate_line_info_table_allocated) | |
11499 | { | |
11500 | separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
11501 | separate_line_info_table | |
71dfc51f RK |
11502 | = (dw_separate_line_info_ref) |
11503 | xrealloc (separate_line_info_table, | |
11504 | separate_line_info_table_allocated | |
11505 | * sizeof (dw_separate_line_info_entry)); | |
e90b62db | 11506 | } |
71dfc51f RK |
11507 | |
11508 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
11509 | line_info |
11510 | = &separate_line_info_table[separate_line_info_table_in_use++]; | |
981975b6 | 11511 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db JM |
11512 | line_info->dw_line_num = line; |
11513 | line_info->function = current_funcdef_number; | |
11514 | } | |
11515 | else | |
11516 | { | |
11517 | register dw_line_info_ref line_info; | |
71dfc51f | 11518 | |
5c90448c JM |
11519 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL, |
11520 | line_info_table_in_use); | |
e90b62db | 11521 | |
71dfc51f | 11522 | /* Expand the line info table if necessary. */ |
e90b62db JM |
11523 | if (line_info_table_in_use == line_info_table_allocated) |
11524 | { | |
11525 | line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
11526 | line_info_table | |
71dfc51f RK |
11527 | = (dw_line_info_ref) |
11528 | xrealloc (line_info_table, | |
11529 | (line_info_table_allocated | |
11530 | * sizeof (dw_line_info_entry))); | |
e90b62db | 11531 | } |
71dfc51f RK |
11532 | |
11533 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db | 11534 | line_info = &line_info_table[line_info_table_in_use++]; |
981975b6 | 11535 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db | 11536 | line_info->dw_line_num = line; |
a3f97cbb | 11537 | } |
a3f97cbb JW |
11538 | } |
11539 | } | |
11540 | ||
30f7a378 | 11541 | /* Record the beginning of a new source file. */ |
71dfc51f | 11542 | |
7f905405 | 11543 | static void |
84a5b4f8 | 11544 | dwarf2out_start_source_file (lineno, filename) |
7f905405 NB |
11545 | register unsigned int lineno; |
11546 | register const char *filename; | |
a3f97cbb | 11547 | { |
881c6935 JM |
11548 | if (flag_eliminate_dwarf2_dups) |
11549 | { | |
11550 | /* Record the beginning of the file for break_out_includes. */ | |
11551 | dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die); | |
11552 | add_AT_string (bincl_die, DW_AT_name, filename); | |
11553 | } | |
84a5b4f8 DB |
11554 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11555 | { | |
715bdd29 | 11556 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 | 11557 | dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file"); |
7c262518 RH |
11558 | dw2_asm_output_data_uleb128 (lineno, "Included from line number %d", |
11559 | lineno); | |
11560 | dw2_asm_output_data_uleb128 (lookup_filename (filename), | |
11561 | "Filename we just started"); | |
84a5b4f8 | 11562 | } |
a3f97cbb JW |
11563 | } |
11564 | ||
cc260610 | 11565 | /* Record the end of a source file. */ |
71dfc51f | 11566 | |
7f905405 NB |
11567 | static void |
11568 | dwarf2out_end_source_file (lineno) | |
11569 | unsigned int lineno ATTRIBUTE_UNUSED; | |
a3f97cbb | 11570 | { |
881c6935 JM |
11571 | if (flag_eliminate_dwarf2_dups) |
11572 | { | |
11573 | /* Record the end of the file for break_out_includes. */ | |
11574 | new_die (DW_TAG_GNU_EINCL, comp_unit_die); | |
0b34cf1e | 11575 | } |
84a5b4f8 DB |
11576 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11577 | { | |
715bdd29 | 11578 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
11579 | dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); |
11580 | } | |
a3f97cbb JW |
11581 | } |
11582 | ||
cc260610 | 11583 | /* Called from debug_define in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
11584 | the tail part of the directive line, i.e. the part which is past the |
11585 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 11586 | |
7f905405 | 11587 | static void |
9a666dda | 11588 | dwarf2out_define (lineno, buffer) |
2618f955 | 11589 | register unsigned lineno ATTRIBUTE_UNUSED; |
d560ee52 | 11590 | register const char *buffer ATTRIBUTE_UNUSED; |
a3f97cbb JW |
11591 | { |
11592 | static int initialized = 0; | |
11593 | if (!initialized) | |
11594 | { | |
84a5b4f8 | 11595 | dwarf2out_start_source_file (0, primary_filename); |
a3f97cbb JW |
11596 | initialized = 1; |
11597 | } | |
84a5b4f8 DB |
11598 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11599 | { | |
715bdd29 | 11600 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
11601 | dw2_asm_output_data (1, DW_MACINFO_define, "Define macro"); |
11602 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
11603 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
11604 | } | |
a3f97cbb JW |
11605 | } |
11606 | ||
cc260610 | 11607 | /* Called from debug_undef in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
11608 | the tail part of the directive line, i.e. the part which is past the |
11609 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 11610 | |
7f905405 | 11611 | static void |
9a666dda | 11612 | dwarf2out_undef (lineno, buffer) |
487a6e06 | 11613 | register unsigned lineno ATTRIBUTE_UNUSED; |
d560ee52 | 11614 | register const char *buffer ATTRIBUTE_UNUSED; |
a3f97cbb | 11615 | { |
84a5b4f8 DB |
11616 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11617 | { | |
715bdd29 | 11618 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
11619 | dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro"); |
11620 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
11621 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
11622 | } | |
a3f97cbb JW |
11623 | } |
11624 | ||
11625 | /* Set up for Dwarf output at the start of compilation. */ | |
71dfc51f | 11626 | |
a51d908e | 11627 | static void |
e2a12aca | 11628 | dwarf2out_init (main_input_filename) |
d3e3972c | 11629 | register const char *main_input_filename; |
a3f97cbb | 11630 | { |
acc187f5 RH |
11631 | init_file_table (); |
11632 | ||
a3f97cbb JW |
11633 | /* Remember the name of the primary input file. */ |
11634 | primary_filename = main_input_filename; | |
11635 | ||
acc187f5 RH |
11636 | /* Add it to the file table first, under the assumption that we'll |
11637 | be emitting line number data for it first, which avoids having | |
11638 | to add an initial DW_LNS_set_file. */ | |
11639 | lookup_filename (main_input_filename); | |
a3f97cbb | 11640 | |
a3f97cbb JW |
11641 | /* Allocate the initial hunk of the decl_die_table. */ |
11642 | decl_die_table | |
3de90026 | 11643 | = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref)); |
a3f97cbb JW |
11644 | decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT; |
11645 | decl_die_table_in_use = 0; | |
11646 | ||
11647 | /* Allocate the initial hunk of the decl_scope_table. */ | |
11648 | decl_scope_table | |
777ad4c2 | 11649 | = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree)); |
a3f97cbb JW |
11650 | decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT; |
11651 | decl_scope_depth = 0; | |
11652 | ||
11653 | /* Allocate the initial hunk of the abbrev_die_table. */ | |
11654 | abbrev_die_table | |
3de90026 RH |
11655 | = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT, |
11656 | sizeof (dw_die_ref)); | |
a3f97cbb | 11657 | abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT; |
71dfc51f | 11658 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
11659 | abbrev_die_table_in_use = 1; |
11660 | ||
11661 | /* Allocate the initial hunk of the line_info_table. */ | |
11662 | line_info_table | |
3de90026 RH |
11663 | = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT, |
11664 | sizeof (dw_line_info_entry)); | |
a3f97cbb | 11665 | line_info_table_allocated = LINE_INFO_TABLE_INCREMENT; |
71dfc51f | 11666 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
11667 | line_info_table_in_use = 1; |
11668 | ||
556273e0 | 11669 | /* Generate the initial DIE for the .debug section. Note that the (string) |
a3f97cbb | 11670 | value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE |
556273e0 | 11671 | will (typically) be a relative pathname and that this pathname should be |
a3f97cbb JW |
11672 | taken as being relative to the directory from which the compiler was |
11673 | invoked when the given (base) source file was compiled. */ | |
a96c67ec | 11674 | comp_unit_die = gen_compile_unit_die (main_input_filename); |
a3f97cbb | 11675 | |
1f8f4a0b MM |
11676 | VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray"); |
11677 | ggc_add_rtx_varray_root (&used_rtx_varray, 1); | |
1865dbb5 | 11678 | |
5c90448c | 11679 | ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0); |
9d2f2c45 RH |
11680 | ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, |
11681 | DEBUG_ABBREV_SECTION_LABEL, 0); | |
b366352b MM |
11682 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) |
11683 | ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0); | |
11684 | else | |
f99ffb60 | 11685 | strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME)); |
556273e0 | 11686 | ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label, |
8b790721 | 11687 | DEBUG_INFO_SECTION_LABEL, 0); |
556273e0 | 11688 | ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label, |
8b790721 | 11689 | DEBUG_LINE_SECTION_LABEL, 0); |
715bdd29 | 11690 | named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG); |
8b790721 | 11691 | ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label); |
715bdd29 | 11692 | named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG); |
8b790721 | 11693 | ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label); |
715bdd29 | 11694 | named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG); |
8b790721 | 11695 | ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label); |
84a5b4f8 DB |
11696 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11697 | { | |
715bdd29 | 11698 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
84a5b4f8 DB |
11699 | ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label, |
11700 | DEBUG_MACINFO_SECTION_LABEL, 0); | |
11701 | ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label); | |
11702 | } | |
7c262518 RH |
11703 | |
11704 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) | |
11705 | { | |
11706 | text_section (); | |
11707 | ASM_OUTPUT_LABEL (asm_out_file, text_section_label); | |
11708 | } | |
a3f97cbb JW |
11709 | } |
11710 | ||
11711 | /* Output stuff that dwarf requires at the end of every file, | |
11712 | and generate the DWARF-2 debugging info. */ | |
71dfc51f | 11713 | |
a51d908e | 11714 | static void |
e2a12aca | 11715 | dwarf2out_finish (input_filename) |
a51d908e | 11716 | register const char *input_filename ATTRIBUTE_UNUSED; |
a3f97cbb | 11717 | { |
ef76d03b | 11718 | limbo_die_node *node, *next_node; |
ae0ed63a | 11719 | dw_die_ref die = 0; |
ef76d03b JW |
11720 | |
11721 | /* Traverse the limbo die list, and add parent/child links. The only | |
11722 | dies without parents that should be here are concrete instances of | |
11723 | inline functions, and the comp_unit_die. We can ignore the comp_unit_die. | |
11724 | For concrete instances, we can get the parent die from the abstract | |
11725 | instance. */ | |
11726 | for (node = limbo_die_list; node; node = next_node) | |
11727 | { | |
11728 | next_node = node->next; | |
11729 | die = node->die; | |
11730 | ||
11731 | if (die->die_parent == NULL) | |
11732 | { | |
a96c67ec JM |
11733 | dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin); |
11734 | if (origin) | |
11735 | add_child_die (origin->die_parent, die); | |
ef76d03b | 11736 | else if (die == comp_unit_die) |
a96c67ec | 11737 | ; |
ef76d03b JW |
11738 | else |
11739 | abort (); | |
11740 | } | |
11741 | free (node); | |
11742 | } | |
a96c67ec | 11743 | limbo_die_list = NULL; |
ef76d03b | 11744 | |
8a8c3656 JM |
11745 | /* Walk through the list of incomplete types again, trying once more to |
11746 | emit full debugging info for them. */ | |
11747 | retry_incomplete_types (); | |
11748 | ||
881c6935 JM |
11749 | /* We need to reverse all the dies before break_out_includes, or |
11750 | we'll see the end of an include file before the beginning. */ | |
11751 | reverse_all_dies (comp_unit_die); | |
11752 | ||
11753 | /* Generate separate CUs for each of the include files we've seen. | |
11754 | They will go into limbo_die_list. */ | |
5f632b5e JM |
11755 | if (flag_eliminate_dwarf2_dups) |
11756 | break_out_includes (comp_unit_die); | |
881c6935 JM |
11757 | |
11758 | /* Traverse the DIE's and add add sibling attributes to those DIE's | |
11759 | that have children. */ | |
a3f97cbb | 11760 | add_sibling_attributes (comp_unit_die); |
881c6935 JM |
11761 | for (node = limbo_die_list; node; node = node->next) |
11762 | add_sibling_attributes (node->die); | |
a3f97cbb JW |
11763 | |
11764 | /* Output a terminator label for the .text section. */ | |
7c262518 | 11765 | text_section (); |
5c90448c | 11766 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0); |
a3f97cbb | 11767 | |
db3c0315 MM |
11768 | /* Output the source line correspondence table. We must do this |
11769 | even if there is no line information. Otherwise, on an empty | |
11770 | translation unit, we will generate a present, but empty, | |
11771 | .debug_info section. IRIX 6.5 `nm' will then complain when | |
11772 | examining the file. */ | |
11773 | if (! DWARF2_ASM_LINE_DEBUG_INFO) | |
e90b62db | 11774 | { |
715bdd29 | 11775 | named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG); |
db3c0315 MM |
11776 | output_line_info (); |
11777 | } | |
71dfc51f | 11778 | |
b38a75e5 RH |
11779 | /* Output location list section if necessary. */ |
11780 | if (have_location_lists) | |
11781 | { | |
11782 | /* Output the location lists info. */ | |
11783 | named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG); | |
11784 | ASM_GENERATE_INTERNAL_LABEL (loc_section_label, | |
11785 | DEBUG_LOC_SECTION_LABEL, 0); | |
11786 | ASM_OUTPUT_LABEL (asm_out_file, loc_section_label); | |
11787 | output_location_lists (die); | |
11788 | have_location_lists = 0; | |
11789 | } | |
11790 | ||
db3c0315 MM |
11791 | /* We can only use the low/high_pc attributes if all of the code was |
11792 | in .text. */ | |
11793 | if (separate_line_info_table_in_use == 0) | |
11794 | { | |
11795 | add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label); | |
11796 | add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label); | |
e90b62db | 11797 | } |
a20612aa RH |
11798 | /* And if it wasn't, we need to give .debug_loc and .debug_ranges |
11799 | an appropriate "base address". Use zero so that these addresses | |
11800 | become absolute. */ | |
11801 | else if (have_location_lists || ranges_table_in_use) | |
11802 | add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx); | |
e90b62db | 11803 | |
fe7cd37f RH |
11804 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
11805 | add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list, | |
11806 | debug_line_section_label); | |
db3c0315 | 11807 | |
84a5b4f8 DB |
11808 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11809 | add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label); | |
a96c67ec | 11810 | |
881c6935 JM |
11811 | /* Output all of the compilation units. We put the main one last so that |
11812 | the offsets are available to output_pubnames. */ | |
11813 | for (node = limbo_die_list; node; node = node->next) | |
11814 | output_comp_unit (node->die); | |
11815 | output_comp_unit (comp_unit_die); | |
11816 | ||
a3f97cbb | 11817 | /* Output the abbreviation table. */ |
715bdd29 | 11818 | named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG); |
a3f97cbb JW |
11819 | output_abbrev_section (); |
11820 | ||
d291dd49 JM |
11821 | if (pubname_table_in_use) |
11822 | { | |
11823 | /* Output public names table. */ | |
715bdd29 | 11824 | named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG); |
d291dd49 JM |
11825 | output_pubnames (); |
11826 | } | |
11827 | ||
e689ae67 JM |
11828 | /* We only put functions in the arange table, so don't write it out if |
11829 | we don't have any. */ | |
a3f97cbb JW |
11830 | if (fde_table_in_use) |
11831 | { | |
a3f97cbb | 11832 | /* Output the address range information. */ |
715bdd29 | 11833 | named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG); |
a3f97cbb JW |
11834 | output_aranges (); |
11835 | } | |
a20612aa | 11836 | |
a20612aa RH |
11837 | /* Output ranges section if necessary. */ |
11838 | if (ranges_table_in_use) | |
11839 | { | |
715bdd29 | 11840 | named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG); |
a20612aa RH |
11841 | output_ranges (); |
11842 | } | |
11843 | ||
30f7a378 | 11844 | /* Have to end the primary source file. */ |
cc260610 DB |
11845 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11846 | { | |
715bdd29 | 11847 | named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); |
cc260610 DB |
11848 | dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); |
11849 | } | |
a3f97cbb | 11850 | } |
9a666dda | 11851 | #endif /* DWARF2_DEBUGGING_INFO */ |