]>
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 JW |
7 | |
8 | This file is part of GNU CC. | |
9 | ||
10 | GNU CC is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2, or (at your option) | |
13 | any later version. | |
14 | ||
15 | GNU CC is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
21 | along with GNU CC; see the file COPYING. If not, write to | |
5f38fdda JL |
22 | the Free Software Foundation, 59 Temple Place - Suite 330, |
23 | Boston, MA 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" |
3f76745e | 50 | #include "except.h" |
a7cc7f29 | 51 | #include "dwarf2.h" |
76ead72b | 52 | #include "dwarf2out.h" |
2e4b9b8c | 53 | #include "dwarf2asm.h" |
10f0ad3d | 54 | #include "toplev.h" |
1865dbb5 | 55 | #include "varray.h" |
951a525f | 56 | #include "ggc.h" |
881c6935 | 57 | #include "md5.h" |
57bed152 | 58 | #include "tm_p.h" |
2a2b2d43 | 59 | #include "diagnostic.h" |
a51d908e | 60 | #include "debug.h" |
a3f97cbb | 61 | |
653e276c NB |
62 | #ifdef DWARF2_DEBUGGING_INFO |
63 | static void dwarf2out_source_line PARAMS ((unsigned int, const char *)); | |
64 | #endif | |
65 | ||
770ca8c6 JO |
66 | /* DWARF2 Abbreviation Glossary: |
67 | CFA = Canonical Frame Address | |
00a42e21 JM |
68 | a fixed address on the stack which identifies a call frame. |
69 | We define it to be the value of SP just before the call insn. | |
70 | The CFA register and offset, which may change during the course | |
71 | of the function, are used to calculate its value at runtime. | |
a401107d JO |
72 | CFI = Call Frame Instruction |
73 | an instruction for the DWARF2 abstract machine | |
770ca8c6 JO |
74 | CIE = Common Information Entry |
75 | information describing information common to one or more FDEs | |
76 | DIE = Debugging Information Entry | |
77 | FDE = Frame Description Entry | |
78 | information describing the stack call frame, in particular, | |
79 | how to restore registers | |
80 | ||
81 | DW_CFA_... = DWARF2 CFA call frame instruction | |
82 | DW_TAG_... = DWARF2 DIE tag */ | |
83 | ||
0021b564 JM |
84 | /* Decide whether we want to emit frame unwind information for the current |
85 | translation unit. */ | |
86 | ||
87 | int | |
88 | dwarf2out_do_frame () | |
89 | { | |
90 | return (write_symbols == DWARF2_DEBUG | |
9ec36da5 | 91 | #ifdef DWARF2_FRAME_INFO |
556273e0 | 92 | || DWARF2_FRAME_INFO |
9ec36da5 | 93 | #endif |
0021b564 | 94 | #ifdef DWARF2_UNWIND_INFO |
14a774a9 | 95 | || flag_unwind_tables |
531073e7 | 96 | || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS) |
0021b564 JM |
97 | #endif |
98 | ); | |
99 | } | |
100 | ||
b1e6ab03 RH |
101 | /* The number of the current function definition for which debugging |
102 | information is being generated. These numbers range from 1 up to the | |
103 | maximum number of function definitions contained within the current | |
104 | compilation unit. These numbers are used to create unique label id's | |
105 | unique to each function definition. */ | |
106 | unsigned current_funcdef_number = 0; | |
107 | ||
0021b564 JM |
108 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) |
109 | ||
eaf95893 RK |
110 | /* How to start an assembler comment. */ |
111 | #ifndef ASM_COMMENT_START | |
112 | #define ASM_COMMENT_START ";#" | |
113 | #endif | |
114 | ||
a3f97cbb JW |
115 | typedef struct dw_cfi_struct *dw_cfi_ref; |
116 | typedef struct dw_fde_struct *dw_fde_ref; | |
117 | typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref; | |
a3f97cbb JW |
118 | |
119 | /* Call frames are described using a sequence of Call Frame | |
120 | Information instructions. The register number, offset | |
121 | and address fields are provided as possible operands; | |
122 | their use is selected by the opcode field. */ | |
71dfc51f | 123 | |
a3f97cbb | 124 | typedef union dw_cfi_oprnd_struct |
71dfc51f RK |
125 | { |
126 | unsigned long dw_cfi_reg_num; | |
127 | long int dw_cfi_offset; | |
d3e3972c | 128 | const char *dw_cfi_addr; |
7d9d8943 | 129 | struct dw_loc_descr_struct *dw_cfi_loc; |
71dfc51f | 130 | } |
a3f97cbb JW |
131 | dw_cfi_oprnd; |
132 | ||
133 | typedef struct dw_cfi_struct | |
71dfc51f RK |
134 | { |
135 | dw_cfi_ref dw_cfi_next; | |
136 | enum dwarf_call_frame_info dw_cfi_opc; | |
137 | dw_cfi_oprnd dw_cfi_oprnd1; | |
138 | dw_cfi_oprnd dw_cfi_oprnd2; | |
139 | } | |
a3f97cbb JW |
140 | dw_cfi_node; |
141 | ||
7d9d8943 AM |
142 | /* This is how we define the location of the CFA. We use to handle it |
143 | as REG + OFFSET all the time, but now it can be more complex. | |
144 | It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET. | |
556273e0 | 145 | Instead of passing around REG and OFFSET, we pass a copy |
7d9d8943 AM |
146 | of this structure. */ |
147 | typedef struct cfa_loc | |
148 | { | |
556273e0 | 149 | unsigned long reg; |
7d9d8943 AM |
150 | long offset; |
151 | long base_offset; | |
152 | int indirect; /* 1 if CFA is accessed via a dereference. */ | |
153 | } dw_cfa_location; | |
154 | ||
a3f97cbb | 155 | /* All call frame descriptions (FDE's) in the GCC generated DWARF |
4b674448 | 156 | refer to a single Common Information Entry (CIE), defined at |
a3f97cbb JW |
157 | the beginning of the .debug_frame section. This used of a single |
158 | CIE obviates the need to keep track of multiple CIE's | |
159 | in the DWARF generation routines below. */ | |
71dfc51f | 160 | |
a3f97cbb | 161 | typedef struct dw_fde_struct |
71dfc51f | 162 | { |
d3e3972c KG |
163 | const char *dw_fde_begin; |
164 | const char *dw_fde_current_label; | |
165 | const char *dw_fde_end; | |
71dfc51f | 166 | dw_cfi_ref dw_fde_cfi; |
52a11cbf RH |
167 | unsigned funcdef_number; |
168 | unsigned nothrow : 1; | |
169 | unsigned uses_eh_lsda : 1; | |
71dfc51f | 170 | } |
a3f97cbb JW |
171 | dw_fde_node; |
172 | ||
a3f97cbb JW |
173 | /* Maximum size (in bytes) of an artificially generated label. */ |
174 | #define MAX_ARTIFICIAL_LABEL_BYTES 30 | |
175 | ||
a1a4189d | 176 | /* The size of the target's pointer type. */ |
a3f97cbb | 177 | #ifndef PTR_SIZE |
a9d38797 | 178 | #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT) |
a3f97cbb JW |
179 | #endif |
180 | ||
a1a4189d JB |
181 | /* The size of addresses as they appear in the Dwarf 2 data. |
182 | Some architectures use word addresses to refer to code locations, | |
183 | but Dwarf 2 info always uses byte addresses. On such machines, | |
184 | Dwarf 2 addresses need to be larger than the architecture's | |
185 | pointers. */ | |
186 | #ifndef DWARF2_ADDR_SIZE | |
187 | #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT) | |
188 | #endif | |
189 | ||
7e23cb16 | 190 | /* The size in bytes of a DWARF field indicating an offset or length |
a1a4189d JB |
191 | relative to a debug info section, specified to be 4 bytes in the |
192 | DWARF-2 specification. The SGI/MIPS ABI defines it to be the same | |
b13fe8bf | 193 | as PTR_SIZE. */ |
71dfc51f | 194 | |
7e23cb16 JM |
195 | #ifndef DWARF_OFFSET_SIZE |
196 | #define DWARF_OFFSET_SIZE 4 | |
197 | #endif | |
198 | ||
9a666dda JM |
199 | #define DWARF_VERSION 2 |
200 | ||
7e23cb16 JM |
201 | /* Round SIZE up to the nearest BOUNDARY. */ |
202 | #define DWARF_ROUND(SIZE,BOUNDARY) \ | |
262b6384 | 203 | ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY)) |
a3f97cbb | 204 | |
a3f97cbb | 205 | /* Offsets recorded in opcodes are a multiple of this alignment factor. */ |
27c35f4b | 206 | #ifndef DWARF_CIE_DATA_ALIGNMENT |
469ac993 | 207 | #ifdef STACK_GROWS_DOWNWARD |
08cb3d38 | 208 | #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD)) |
469ac993 | 209 | #else |
08cb3d38 | 210 | #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD) |
469ac993 | 211 | #endif |
27c35f4b | 212 | #endif /* not DWARF_CIE_DATA_ALIGNMENT */ |
a3f97cbb | 213 | |
3f76745e JM |
214 | /* A pointer to the base of a table that contains frame description |
215 | information for each routine. */ | |
216 | static dw_fde_ref fde_table; | |
a3f97cbb | 217 | |
3f76745e JM |
218 | /* Number of elements currently allocated for fde_table. */ |
219 | static unsigned fde_table_allocated; | |
a94dbf2c | 220 | |
3f76745e JM |
221 | /* Number of elements in fde_table currently in use. */ |
222 | static unsigned fde_table_in_use; | |
a3f97cbb | 223 | |
3f76745e JM |
224 | /* Size (in elements) of increments by which we may expand the |
225 | fde_table. */ | |
226 | #define FDE_TABLE_INCREMENT 256 | |
a3f97cbb | 227 | |
a94dbf2c JM |
228 | /* A list of call frame insns for the CIE. */ |
229 | static dw_cfi_ref cie_cfi_head; | |
230 | ||
a3f97cbb JW |
231 | /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram |
232 | attribute that accelerates the lookup of the FDE associated | |
556273e0 | 233 | with the subprogram. This variable holds the table index of the FDE |
a3f97cbb JW |
234 | associated with the current function (body) definition. */ |
235 | static unsigned current_funcdef_fde; | |
236 | ||
a3f97cbb | 237 | /* Forward declarations for functions defined in this file. */ |
71dfc51f | 238 | |
83d2b3b9 KG |
239 | static char *stripattributes PARAMS ((const char *)); |
240 | static const char *dwarf_cfi_name PARAMS ((unsigned)); | |
241 | static dw_cfi_ref new_cfi PARAMS ((void)); | |
242 | static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref)); | |
d3e3972c | 243 | static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref)); |
7d9d8943 AM |
244 | static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *)); |
245 | static void lookup_cfa PARAMS ((dw_cfa_location *)); | |
d3e3972c KG |
246 | static void reg_save PARAMS ((const char *, unsigned, |
247 | unsigned, long)); | |
83d2b3b9 | 248 | static void initial_return_save PARAMS ((rtx)); |
5e640c56 | 249 | static long stack_adjust_offset PARAMS ((rtx)); |
12f0b96b | 250 | static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int)); |
83d2b3b9 | 251 | static void output_call_frame_info PARAMS ((int)); |
83d2b3b9 | 252 | static void dwarf2out_stack_adjust PARAMS ((rtx)); |
fbfa55b0 RH |
253 | static void queue_reg_save PARAMS ((const char *, rtx, long)); |
254 | static void flush_queued_reg_saves PARAMS ((void)); | |
255 | static bool clobbers_queued_reg_save PARAMS ((rtx)); | |
d3e3972c | 256 | static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *)); |
a3f97cbb | 257 | |
7d9d8943 AM |
258 | /* Support for complex CFA locations. */ |
259 | static void output_cfa_loc PARAMS ((dw_cfi_ref)); | |
556273e0 | 260 | static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *, |
7d9d8943 AM |
261 | struct dw_loc_descr_struct *)); |
262 | static struct dw_loc_descr_struct *build_cfa_loc | |
263 | PARAMS ((dw_cfa_location *)); | |
264 | static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *)); | |
265 | ||
2e4b9b8c RH |
266 | /* How to start an assembler comment. */ |
267 | #ifndef ASM_COMMENT_START | |
268 | #define ASM_COMMENT_START ";#" | |
a3f97cbb JW |
269 | #endif |
270 | ||
7e23cb16 JM |
271 | /* Data and reference forms for relocatable data. */ |
272 | #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4) | |
273 | #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4) | |
274 | ||
a3f97cbb JW |
275 | /* Pseudo-op for defining a new section. */ |
276 | #ifndef SECTION_ASM_OP | |
0a3e1f45 | 277 | #define SECTION_ASM_OP "\t.section\t" |
a3f97cbb JW |
278 | #endif |
279 | ||
280 | /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to | |
281 | print the SECTION_ASM_OP and the section name. The default here works for | |
282 | almost all svr4 assemblers, except for the sparc, where the section name | |
283 | must be enclosed in double quotes. (See sparcv4.h). */ | |
284 | #ifndef SECTION_FORMAT | |
c53aa195 JM |
285 | #ifdef PUSHSECTION_FORMAT |
286 | #define SECTION_FORMAT PUSHSECTION_FORMAT | |
287 | #else | |
e8638df0 | 288 | #define SECTION_FORMAT "%s%s\n" |
c53aa195 | 289 | #endif |
a3f97cbb JW |
290 | #endif |
291 | ||
cf2fe500 RH |
292 | #ifndef DEBUG_FRAME_SECTION |
293 | #define DEBUG_FRAME_SECTION ".debug_frame" | |
a3f97cbb | 294 | #endif |
a3f97cbb | 295 | |
5c90448c JM |
296 | #ifndef FUNC_BEGIN_LABEL |
297 | #define FUNC_BEGIN_LABEL "LFB" | |
a3f97cbb | 298 | #endif |
5c90448c JM |
299 | #ifndef FUNC_END_LABEL |
300 | #define FUNC_END_LABEL "LFE" | |
a3f97cbb | 301 | #endif |
a6ab3aad JM |
302 | #define CIE_AFTER_SIZE_LABEL "LSCIE" |
303 | #define CIE_END_LABEL "LECIE" | |
2ed2af28 | 304 | #define CIE_LENGTH_LABEL "LLCIE" |
2e4b9b8c RH |
305 | #define FDE_LABEL "LSFDE" |
306 | #define FDE_AFTER_SIZE_LABEL "LASFDE" | |
a6ab3aad | 307 | #define FDE_END_LABEL "LEFDE" |
2ed2af28 | 308 | #define FDE_LENGTH_LABEL "LLFDE" |
981975b6 RH |
309 | #define LINE_NUMBER_BEGIN_LABEL "LSLT" |
310 | #define LINE_NUMBER_END_LABEL "LELT" | |
311 | #define LN_PROLOG_AS_LABEL "LASLTP" | |
312 | #define LN_PROLOG_END_LABEL "LELTP" | |
881c6935 | 313 | #define DIE_LABEL_PREFIX "DW" |
a3f97cbb | 314 | |
a3f97cbb JW |
315 | /* Definitions of defaults for various types of primitive assembly language |
316 | output operations. These may be overridden from within the tm.h file, | |
956d6950 | 317 | but typically, that is unnecessary. */ |
71dfc51f | 318 | |
a3f97cbb JW |
319 | #ifndef ASM_OUTPUT_SECTION |
320 | #define ASM_OUTPUT_SECTION(FILE, SECTION) \ | |
321 | fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION) | |
322 | #endif | |
323 | ||
2ed2af28 PDM |
324 | #ifdef SET_ASM_OP |
325 | #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL | |
7bb9fb0e JM |
326 | #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \ |
327 | do { \ | |
e8638df0 | 328 | fprintf (FILE, "%s", SET_ASM_OP); \ |
7bb9fb0e JM |
329 | assemble_name (FILE, SY); \ |
330 | fputc (',', FILE); \ | |
331 | assemble_name (FILE, HI); \ | |
332 | fputc ('-', FILE); \ | |
333 | assemble_name (FILE, LO); \ | |
334 | } while (0) | |
2ed2af28 PDM |
335 | #endif |
336 | #endif /* SET_ASM_OP */ | |
337 | ||
c8cc5c4a | 338 | /* The DWARF 2 CFA column which tracks the return address. Normally this |
a94dbf2c JM |
339 | is the column for PC, or the first column after all of the hard |
340 | registers. */ | |
c8cc5c4a | 341 | #ifndef DWARF_FRAME_RETURN_COLUMN |
a94dbf2c JM |
342 | #ifdef PC_REGNUM |
343 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM) | |
344 | #else | |
3073d01c | 345 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS |
a94dbf2c | 346 | #endif |
c8cc5c4a JM |
347 | #endif |
348 | ||
349 | /* The mapping from gcc register number to DWARF 2 CFA column number. By | |
469ac993 | 350 | default, we just provide columns for all registers. */ |
c8cc5c4a | 351 | #ifndef DWARF_FRAME_REGNUM |
469ac993 | 352 | #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG) |
c8cc5c4a | 353 | #endif |
3f76745e | 354 | |
0021b564 JM |
355 | /* Hook used by __throw. */ |
356 | ||
357 | rtx | |
358 | expand_builtin_dwarf_fp_regnum () | |
359 | { | |
360 | return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM)); | |
361 | } | |
362 | ||
a6ab3aad JM |
363 | /* The offset from the incoming value of %sp to the top of the stack frame |
364 | for the current function. */ | |
365 | #ifndef INCOMING_FRAME_SP_OFFSET | |
366 | #define INCOMING_FRAME_SP_OFFSET 0 | |
367 | #endif | |
a51d908e | 368 | \f |
71dfc51f | 369 | /* Return a pointer to a copy of the section string name S with all |
bf20f341 | 370 | attributes stripped off, and an asterisk prepended (for assemble_name). */ |
71dfc51f RK |
371 | |
372 | static inline char * | |
a3f97cbb | 373 | stripattributes (s) |
d560ee52 | 374 | const char *s; |
a3f97cbb | 375 | { |
bf20f341 | 376 | char *stripped = xmalloc (strlen (s) + 2); |
71dfc51f RK |
377 | char *p = stripped; |
378 | ||
bf20f341 JW |
379 | *p++ = '*'; |
380 | ||
381 | while (*s && *s != ',') | |
382 | *p++ = *s++; | |
71dfc51f | 383 | |
a3f97cbb JW |
384 | *p = '\0'; |
385 | return stripped; | |
386 | } | |
387 | ||
d9d5c9de | 388 | /* Generate code to initialize the register size table. */ |
2f3ca9e7 | 389 | |
d9d5c9de BS |
390 | void |
391 | expand_builtin_init_dwarf_reg_sizes (address) | |
392 | tree address; | |
2f3ca9e7 | 393 | { |
d9d5c9de BS |
394 | int i; |
395 | enum machine_mode mode = TYPE_MODE (char_type_node); | |
396 | rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0); | |
397 | rtx mem = gen_rtx_MEM (mode, addr); | |
2f3ca9e7 | 398 | |
376e12ab | 399 | for (i = 0; i < DWARF_FRAME_REGISTERS; ++i) |
2f3ca9e7 | 400 | { |
e0e07bd1 | 401 | int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode); |
d9d5c9de | 402 | int size = GET_MODE_SIZE (reg_raw_mode[i]); |
2f3ca9e7 | 403 | |
c699cee9 JM |
404 | if (offset < 0) |
405 | continue; | |
406 | ||
f4ef873c | 407 | emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size)); |
2f3ca9e7 | 408 | } |
2f3ca9e7 JM |
409 | } |
410 | ||
3f76745e | 411 | /* Convert a DWARF call frame info. operation to its string name */ |
a3f97cbb | 412 | |
d560ee52 | 413 | static const char * |
3f76745e JM |
414 | dwarf_cfi_name (cfi_opc) |
415 | register unsigned cfi_opc; | |
416 | { | |
417 | switch (cfi_opc) | |
418 | { | |
419 | case DW_CFA_advance_loc: | |
420 | return "DW_CFA_advance_loc"; | |
421 | case DW_CFA_offset: | |
422 | return "DW_CFA_offset"; | |
423 | case DW_CFA_restore: | |
424 | return "DW_CFA_restore"; | |
425 | case DW_CFA_nop: | |
426 | return "DW_CFA_nop"; | |
427 | case DW_CFA_set_loc: | |
428 | return "DW_CFA_set_loc"; | |
429 | case DW_CFA_advance_loc1: | |
430 | return "DW_CFA_advance_loc1"; | |
431 | case DW_CFA_advance_loc2: | |
432 | return "DW_CFA_advance_loc2"; | |
433 | case DW_CFA_advance_loc4: | |
434 | return "DW_CFA_advance_loc4"; | |
435 | case DW_CFA_offset_extended: | |
436 | return "DW_CFA_offset_extended"; | |
437 | case DW_CFA_restore_extended: | |
438 | return "DW_CFA_restore_extended"; | |
439 | case DW_CFA_undefined: | |
440 | return "DW_CFA_undefined"; | |
441 | case DW_CFA_same_value: | |
442 | return "DW_CFA_same_value"; | |
443 | case DW_CFA_register: | |
444 | return "DW_CFA_register"; | |
445 | case DW_CFA_remember_state: | |
446 | return "DW_CFA_remember_state"; | |
447 | case DW_CFA_restore_state: | |
448 | return "DW_CFA_restore_state"; | |
449 | case DW_CFA_def_cfa: | |
450 | return "DW_CFA_def_cfa"; | |
451 | case DW_CFA_def_cfa_register: | |
452 | return "DW_CFA_def_cfa_register"; | |
453 | case DW_CFA_def_cfa_offset: | |
454 | return "DW_CFA_def_cfa_offset"; | |
7d9d8943 AM |
455 | case DW_CFA_def_cfa_expression: |
456 | return "DW_CFA_def_cfa_expression"; | |
c53aa195 | 457 | |
3f76745e JM |
458 | /* SGI/MIPS specific */ |
459 | case DW_CFA_MIPS_advance_loc8: | |
460 | return "DW_CFA_MIPS_advance_loc8"; | |
c53aa195 JM |
461 | |
462 | /* GNU extensions */ | |
463 | case DW_CFA_GNU_window_save: | |
464 | return "DW_CFA_GNU_window_save"; | |
0021b564 JM |
465 | case DW_CFA_GNU_args_size: |
466 | return "DW_CFA_GNU_args_size"; | |
3f388b42 GK |
467 | case DW_CFA_GNU_negative_offset_extended: |
468 | return "DW_CFA_GNU_negative_offset_extended"; | |
c53aa195 | 469 | |
3f76745e JM |
470 | default: |
471 | return "DW_CFA_<unknown>"; | |
472 | } | |
473 | } | |
a3f97cbb | 474 | |
3f76745e | 475 | /* Return a pointer to a newly allocated Call Frame Instruction. */ |
71dfc51f | 476 | |
3f76745e JM |
477 | static inline dw_cfi_ref |
478 | new_cfi () | |
479 | { | |
480 | register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node)); | |
71dfc51f | 481 | |
3f76745e JM |
482 | cfi->dw_cfi_next = NULL; |
483 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0; | |
484 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0; | |
a3f97cbb | 485 | |
3f76745e JM |
486 | return cfi; |
487 | } | |
a3f97cbb | 488 | |
3f76745e | 489 | /* Add a Call Frame Instruction to list of instructions. */ |
a3f97cbb | 490 | |
3f76745e JM |
491 | static inline void |
492 | add_cfi (list_head, cfi) | |
493 | register dw_cfi_ref *list_head; | |
494 | register dw_cfi_ref cfi; | |
495 | { | |
496 | register dw_cfi_ref *p; | |
a3f97cbb | 497 | |
3f76745e JM |
498 | /* Find the end of the chain. */ |
499 | for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next) | |
500 | ; | |
501 | ||
502 | *p = cfi; | |
a3f97cbb JW |
503 | } |
504 | ||
3f76745e | 505 | /* Generate a new label for the CFI info to refer to. */ |
71dfc51f | 506 | |
c53aa195 | 507 | char * |
3f76745e | 508 | dwarf2out_cfi_label () |
a3f97cbb | 509 | { |
3f76745e JM |
510 | static char label[20]; |
511 | static unsigned long label_num = 0; | |
556273e0 | 512 | |
3f76745e JM |
513 | ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++); |
514 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
515 | ||
516 | return label; | |
a3f97cbb JW |
517 | } |
518 | ||
3f76745e JM |
519 | /* Add CFI to the current fde at the PC value indicated by LABEL if specified, |
520 | or to the CIE if LABEL is NULL. */ | |
71dfc51f | 521 | |
3f76745e JM |
522 | static void |
523 | add_fde_cfi (label, cfi) | |
d3e3972c | 524 | register const char *label; |
3f76745e | 525 | register dw_cfi_ref cfi; |
a3f97cbb | 526 | { |
3f76745e JM |
527 | if (label) |
528 | { | |
529 | register dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; | |
a3f97cbb | 530 | |
3f76745e JM |
531 | if (*label == 0) |
532 | label = dwarf2out_cfi_label (); | |
71dfc51f | 533 | |
3f76745e JM |
534 | if (fde->dw_fde_current_label == NULL |
535 | || strcmp (label, fde->dw_fde_current_label) != 0) | |
536 | { | |
537 | register dw_cfi_ref xcfi; | |
a3f97cbb | 538 | |
3f76745e | 539 | fde->dw_fde_current_label = label = xstrdup (label); |
71dfc51f | 540 | |
3f76745e JM |
541 | /* Set the location counter to the new label. */ |
542 | xcfi = new_cfi (); | |
543 | xcfi->dw_cfi_opc = DW_CFA_advance_loc4; | |
544 | xcfi->dw_cfi_oprnd1.dw_cfi_addr = label; | |
545 | add_cfi (&fde->dw_fde_cfi, xcfi); | |
546 | } | |
71dfc51f | 547 | |
3f76745e JM |
548 | add_cfi (&fde->dw_fde_cfi, cfi); |
549 | } | |
550 | ||
551 | else | |
552 | add_cfi (&cie_cfi_head, cfi); | |
a3f97cbb JW |
553 | } |
554 | ||
3f76745e | 555 | /* Subroutine of lookup_cfa. */ |
71dfc51f | 556 | |
3f76745e | 557 | static inline void |
7d9d8943 | 558 | lookup_cfa_1 (cfi, loc) |
3f76745e | 559 | register dw_cfi_ref cfi; |
7d9d8943 | 560 | register dw_cfa_location *loc; |
a3f97cbb | 561 | { |
3f76745e JM |
562 | switch (cfi->dw_cfi_opc) |
563 | { | |
564 | case DW_CFA_def_cfa_offset: | |
7d9d8943 | 565 | loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset; |
3f76745e JM |
566 | break; |
567 | case DW_CFA_def_cfa_register: | |
7d9d8943 | 568 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
3f76745e JM |
569 | break; |
570 | case DW_CFA_def_cfa: | |
7d9d8943 AM |
571 | loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; |
572 | loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset; | |
573 | break; | |
574 | case DW_CFA_def_cfa_expression: | |
575 | get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc); | |
3f76745e | 576 | break; |
e9a25f70 JL |
577 | default: |
578 | break; | |
3f76745e | 579 | } |
a3f97cbb JW |
580 | } |
581 | ||
3f76745e | 582 | /* Find the previous value for the CFA. */ |
71dfc51f | 583 | |
3f76745e | 584 | static void |
7d9d8943 AM |
585 | lookup_cfa (loc) |
586 | register dw_cfa_location *loc; | |
a3f97cbb | 587 | { |
3f76745e JM |
588 | register dw_cfi_ref cfi; |
589 | ||
7d9d8943 AM |
590 | loc->reg = (unsigned long) -1; |
591 | loc->offset = 0; | |
592 | loc->indirect = 0; | |
593 | loc->base_offset = 0; | |
3f76745e JM |
594 | |
595 | for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next) | |
7d9d8943 | 596 | lookup_cfa_1 (cfi, loc); |
3f76745e JM |
597 | |
598 | if (fde_table_in_use) | |
a3f97cbb | 599 | { |
3f76745e JM |
600 | register dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
601 | for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next) | |
7d9d8943 | 602 | lookup_cfa_1 (cfi, loc); |
a3f97cbb JW |
603 | } |
604 | } | |
605 | ||
3f76745e | 606 | /* The current rule for calculating the DWARF2 canonical frame address. */ |
fbfa55b0 | 607 | static dw_cfa_location cfa; |
71dfc51f | 608 | |
3f76745e JM |
609 | /* The register used for saving registers to the stack, and its offset |
610 | from the CFA. */ | |
fbfa55b0 | 611 | static dw_cfa_location cfa_store; |
3f76745e | 612 | |
0021b564 JM |
613 | /* The running total of the size of arguments pushed onto the stack. */ |
614 | static long args_size; | |
615 | ||
b57d9225 JM |
616 | /* The last args_size we actually output. */ |
617 | static long old_args_size; | |
618 | ||
3f76745e JM |
619 | /* Entry point to update the canonical frame address (CFA). |
620 | LABEL is passed to add_fde_cfi. The value of CFA is now to be | |
621 | calculated from REG+OFFSET. */ | |
622 | ||
623 | void | |
624 | dwarf2out_def_cfa (label, reg, offset) | |
d3e3972c | 625 | register const char *label; |
7d9d8943 AM |
626 | unsigned reg; |
627 | long offset; | |
628 | { | |
629 | dw_cfa_location loc; | |
630 | loc.indirect = 0; | |
631 | loc.base_offset = 0; | |
632 | loc.reg = reg; | |
633 | loc.offset = offset; | |
634 | def_cfa_1 (label, &loc); | |
635 | } | |
636 | ||
770ca8c6 | 637 | /* This routine does the actual work. The CFA is now calculated from |
7d9d8943 AM |
638 | the dw_cfa_location structure. */ |
639 | static void | |
640 | def_cfa_1 (label, loc_p) | |
641 | register const char *label; | |
642 | dw_cfa_location *loc_p; | |
a3f97cbb | 643 | { |
3f76745e | 644 | register dw_cfi_ref cfi; |
7d9d8943 | 645 | dw_cfa_location old_cfa, loc; |
3f76745e | 646 | |
7d9d8943 AM |
647 | cfa = *loc_p; |
648 | loc = *loc_p; | |
5bef9b1f | 649 | |
7d9d8943 AM |
650 | if (cfa_store.reg == loc.reg && loc.indirect == 0) |
651 | cfa_store.offset = loc.offset; | |
3f76745e | 652 | |
7d9d8943 AM |
653 | loc.reg = DWARF_FRAME_REGNUM (loc.reg); |
654 | lookup_cfa (&old_cfa); | |
655 | ||
656 | if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset && | |
657 | loc.indirect == old_cfa.indirect) | |
658 | { | |
e09bbb25 JM |
659 | if (loc.indirect == 0 |
660 | || loc.base_offset == old_cfa.base_offset) | |
770ca8c6 JO |
661 | /* Nothing changed so no need to issue any call frame |
662 | instructions. */ | |
7d9d8943 | 663 | return; |
7d9d8943 | 664 | } |
3f76745e JM |
665 | |
666 | cfi = new_cfi (); | |
667 | ||
e09bbb25 | 668 | if (loc.reg == old_cfa.reg && !loc.indirect) |
a3f97cbb | 669 | { |
770ca8c6 JO |
670 | /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, |
671 | indicating the CFA register did not change but the offset | |
672 | did. */ | |
3f76745e | 673 | cfi->dw_cfi_opc = DW_CFA_def_cfa_offset; |
7d9d8943 | 674 | cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset; |
3f76745e | 675 | } |
a3f97cbb | 676 | |
3f76745e | 677 | #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */ |
7d9d8943 | 678 | else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1 |
e09bbb25 | 679 | && !loc.indirect) |
3f76745e | 680 | { |
770ca8c6 JO |
681 | /* Construct a "DW_CFA_def_cfa_register <register>" instruction, |
682 | indicating the CFA register has changed to <register> but the | |
683 | offset has not changed. */ | |
3f76745e | 684 | cfi->dw_cfi_opc = DW_CFA_def_cfa_register; |
7d9d8943 | 685 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
3f76745e JM |
686 | } |
687 | #endif | |
a3f97cbb | 688 | |
7d9d8943 | 689 | else if (loc.indirect == 0) |
3f76745e | 690 | { |
770ca8c6 JO |
691 | /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction, |
692 | indicating the CFA register has changed to <register> with | |
693 | the specified offset. */ | |
3f76745e | 694 | cfi->dw_cfi_opc = DW_CFA_def_cfa; |
7d9d8943 AM |
695 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; |
696 | cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset; | |
697 | } | |
698 | else | |
699 | { | |
770ca8c6 JO |
700 | /* Construct a DW_CFA_def_cfa_expression instruction to |
701 | calculate the CFA using a full location expression since no | |
702 | register-offset pair is available. */ | |
556273e0 | 703 | struct dw_loc_descr_struct *loc_list; |
7d9d8943 AM |
704 | cfi->dw_cfi_opc = DW_CFA_def_cfa_expression; |
705 | loc_list = build_cfa_loc (&loc); | |
706 | cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list; | |
a3f97cbb | 707 | } |
3f76745e JM |
708 | |
709 | add_fde_cfi (label, cfi); | |
a3f97cbb JW |
710 | } |
711 | ||
3f76745e JM |
712 | /* Add the CFI for saving a register. REG is the CFA column number. |
713 | LABEL is passed to add_fde_cfi. | |
714 | If SREG is -1, the register is saved at OFFSET from the CFA; | |
715 | otherwise it is saved in SREG. */ | |
71dfc51f | 716 | |
3f76745e JM |
717 | static void |
718 | reg_save (label, reg, sreg, offset) | |
d3e3972c | 719 | register const char *label; |
3f76745e JM |
720 | register unsigned reg; |
721 | register unsigned sreg; | |
722 | register long offset; | |
a3f97cbb | 723 | { |
3f76745e JM |
724 | register dw_cfi_ref cfi = new_cfi (); |
725 | ||
726 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
727 | ||
85066503 MH |
728 | /* The following comparison is correct. -1 is used to indicate that |
729 | the value isn't a register number. */ | |
730 | if (sreg == (unsigned int) -1) | |
a3f97cbb | 731 | { |
3f76745e JM |
732 | if (reg & ~0x3f) |
733 | /* The register number won't fit in 6 bits, so we have to use | |
734 | the long form. */ | |
735 | cfi->dw_cfi_opc = DW_CFA_offset_extended; | |
736 | else | |
737 | cfi->dw_cfi_opc = DW_CFA_offset; | |
738 | ||
27c35f4b HPN |
739 | #ifdef ENABLE_CHECKING |
740 | { | |
741 | /* If we get an offset that is not a multiple of | |
742 | DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the | |
743 | definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine | |
744 | description. */ | |
745 | long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT; | |
746 | ||
747 | if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset) | |
748 | abort (); | |
749 | } | |
750 | #endif | |
3f76745e | 751 | offset /= DWARF_CIE_DATA_ALIGNMENT; |
3a88cbd1 | 752 | if (offset < 0) |
3f388b42 GK |
753 | { |
754 | cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended; | |
755 | offset = -offset; | |
756 | } | |
3f76745e JM |
757 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; |
758 | } | |
2c849145 JM |
759 | else if (sreg == reg) |
760 | /* We could emit a DW_CFA_same_value in this case, but don't bother. */ | |
761 | return; | |
3f76745e JM |
762 | else |
763 | { | |
764 | cfi->dw_cfi_opc = DW_CFA_register; | |
765 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg; | |
766 | } | |
767 | ||
768 | add_fde_cfi (label, cfi); | |
769 | } | |
770 | ||
c53aa195 JM |
771 | /* Add the CFI for saving a register window. LABEL is passed to reg_save. |
772 | This CFI tells the unwinder that it needs to restore the window registers | |
773 | from the previous frame's window save area. | |
556273e0 | 774 | |
c53aa195 JM |
775 | ??? Perhaps we should note in the CIE where windows are saved (instead of |
776 | assuming 0(cfa)) and what registers are in the window. */ | |
777 | ||
778 | void | |
779 | dwarf2out_window_save (label) | |
d3e3972c | 780 | register const char *label; |
c53aa195 JM |
781 | { |
782 | register dw_cfi_ref cfi = new_cfi (); | |
783 | cfi->dw_cfi_opc = DW_CFA_GNU_window_save; | |
784 | add_fde_cfi (label, cfi); | |
785 | } | |
786 | ||
0021b564 JM |
787 | /* Add a CFI to update the running total of the size of arguments |
788 | pushed onto the stack. */ | |
789 | ||
790 | void | |
791 | dwarf2out_args_size (label, size) | |
d3e3972c | 792 | const char *label; |
0021b564 JM |
793 | long size; |
794 | { | |
b57d9225 JM |
795 | register dw_cfi_ref cfi; |
796 | ||
797 | if (size == old_args_size) | |
798 | return; | |
799 | old_args_size = size; | |
800 | ||
801 | cfi = new_cfi (); | |
0021b564 JM |
802 | cfi->dw_cfi_opc = DW_CFA_GNU_args_size; |
803 | cfi->dw_cfi_oprnd1.dw_cfi_offset = size; | |
804 | add_fde_cfi (label, cfi); | |
805 | } | |
806 | ||
c53aa195 JM |
807 | /* Entry point for saving a register to the stack. REG is the GCC register |
808 | number. LABEL and OFFSET are passed to reg_save. */ | |
3f76745e JM |
809 | |
810 | void | |
811 | dwarf2out_reg_save (label, reg, offset) | |
d3e3972c | 812 | register const char *label; |
3f76745e JM |
813 | register unsigned reg; |
814 | register long offset; | |
815 | { | |
816 | reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset); | |
817 | } | |
818 | ||
c53aa195 JM |
819 | /* Entry point for saving the return address in the stack. |
820 | LABEL and OFFSET are passed to reg_save. */ | |
821 | ||
822 | void | |
823 | dwarf2out_return_save (label, offset) | |
d3e3972c | 824 | register const char *label; |
c53aa195 JM |
825 | register long offset; |
826 | { | |
827 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset); | |
828 | } | |
829 | ||
830 | /* Entry point for saving the return address in a register. | |
831 | LABEL and SREG are passed to reg_save. */ | |
832 | ||
833 | void | |
834 | dwarf2out_return_reg (label, sreg) | |
d3e3972c | 835 | register const char *label; |
c53aa195 JM |
836 | register unsigned sreg; |
837 | { | |
838 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0); | |
839 | } | |
840 | ||
3f76745e JM |
841 | /* Record the initial position of the return address. RTL is |
842 | INCOMING_RETURN_ADDR_RTX. */ | |
843 | ||
844 | static void | |
845 | initial_return_save (rtl) | |
846 | register rtx rtl; | |
847 | { | |
973838fd | 848 | unsigned int reg = (unsigned int) -1; |
3f76745e JM |
849 | long offset = 0; |
850 | ||
851 | switch (GET_CODE (rtl)) | |
852 | { | |
853 | case REG: | |
854 | /* RA is in a register. */ | |
2c849145 | 855 | reg = DWARF_FRAME_REGNUM (REGNO (rtl)); |
3f76745e JM |
856 | break; |
857 | case MEM: | |
858 | /* RA is on the stack. */ | |
859 | rtl = XEXP (rtl, 0); | |
860 | switch (GET_CODE (rtl)) | |
861 | { | |
862 | case REG: | |
3a88cbd1 JL |
863 | if (REGNO (rtl) != STACK_POINTER_REGNUM) |
864 | abort (); | |
3f76745e JM |
865 | offset = 0; |
866 | break; | |
867 | case PLUS: | |
3a88cbd1 JL |
868 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
869 | abort (); | |
3f76745e JM |
870 | offset = INTVAL (XEXP (rtl, 1)); |
871 | break; | |
872 | case MINUS: | |
3a88cbd1 JL |
873 | if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) |
874 | abort (); | |
3f76745e JM |
875 | offset = -INTVAL (XEXP (rtl, 1)); |
876 | break; | |
877 | default: | |
878 | abort (); | |
879 | } | |
880 | break; | |
c53aa195 JM |
881 | case PLUS: |
882 | /* The return address is at some offset from any value we can | |
883 | actually load. For instance, on the SPARC it is in %i7+8. Just | |
884 | ignore the offset for now; it doesn't matter for unwinding frames. */ | |
3a88cbd1 JL |
885 | if (GET_CODE (XEXP (rtl, 1)) != CONST_INT) |
886 | abort (); | |
c53aa195 JM |
887 | initial_return_save (XEXP (rtl, 0)); |
888 | return; | |
a3f97cbb | 889 | default: |
3f76745e | 890 | abort (); |
a3f97cbb | 891 | } |
3f76745e | 892 | |
7d9d8943 | 893 | reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset); |
a3f97cbb JW |
894 | } |
895 | ||
1ba5ae8f AH |
896 | /* Given a SET, calculate the amount of stack adjustment it |
897 | contains. */ | |
898 | ||
5e640c56 AH |
899 | static long |
900 | stack_adjust_offset (pattern) | |
1ba5ae8f AH |
901 | rtx pattern; |
902 | { | |
903 | rtx src = SET_SRC (pattern); | |
904 | rtx dest = SET_DEST (pattern); | |
905 | long offset = 0; | |
906 | enum rtx_code code; | |
907 | ||
908 | if (dest == stack_pointer_rtx) | |
909 | { | |
910 | /* (set (reg sp) (plus (reg sp) (const_int))) */ | |
911 | code = GET_CODE (src); | |
912 | if (! (code == PLUS || code == MINUS) | |
913 | || XEXP (src, 0) != stack_pointer_rtx | |
914 | || GET_CODE (XEXP (src, 1)) != CONST_INT) | |
915 | return 0; | |
916 | ||
917 | offset = INTVAL (XEXP (src, 1)); | |
918 | } | |
919 | else if (GET_CODE (dest) == MEM) | |
920 | { | |
921 | /* (set (mem (pre_dec (reg sp))) (foo)) */ | |
922 | src = XEXP (dest, 0); | |
923 | code = GET_CODE (src); | |
924 | ||
e2134eea JH |
925 | if (! (code == PRE_DEC || code == PRE_INC |
926 | || code == PRE_MODIFY) | |
1ba5ae8f AH |
927 | || XEXP (src, 0) != stack_pointer_rtx) |
928 | return 0; | |
929 | ||
e2134eea JH |
930 | if (code == PRE_MODIFY) |
931 | { | |
932 | rtx val = XEXP (XEXP (src, 1), 1); | |
933 | /* We handle only adjustments by constant amount. */ | |
934 | if (GET_CODE (XEXP (src, 1)) != PLUS || | |
935 | GET_CODE (val) != CONST_INT) | |
936 | abort(); | |
937 | offset = -INTVAL (val); | |
938 | } | |
939 | else offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1ba5ae8f AH |
940 | } |
941 | else | |
942 | return 0; | |
943 | ||
944 | if (code == PLUS || code == PRE_INC) | |
945 | offset = -offset; | |
946 | ||
947 | return offset; | |
948 | } | |
949 | ||
0021b564 JM |
950 | /* Check INSN to see if it looks like a push or a stack adjustment, and |
951 | make a note of it if it does. EH uses this information to find out how | |
952 | much extra space it needs to pop off the stack. */ | |
953 | ||
954 | static void | |
955 | dwarf2out_stack_adjust (insn) | |
956 | rtx insn; | |
957 | { | |
0021b564 | 958 | long offset; |
d3e3972c | 959 | const char *label; |
0021b564 | 960 | |
c1e9f663 | 961 | if (! flag_non_call_exceptions && GET_CODE (insn) == CALL_INSN) |
b57d9225 JM |
962 | { |
963 | /* Extract the size of the args from the CALL rtx itself. */ | |
964 | ||
965 | insn = PATTERN (insn); | |
966 | if (GET_CODE (insn) == PARALLEL) | |
967 | insn = XVECEXP (insn, 0, 0); | |
968 | if (GET_CODE (insn) == SET) | |
969 | insn = SET_SRC (insn); | |
3db35af4 MM |
970 | if (GET_CODE (insn) != CALL) |
971 | abort (); | |
b57d9225 JM |
972 | dwarf2out_args_size ("", INTVAL (XEXP (insn, 1))); |
973 | return; | |
974 | } | |
975 | ||
976 | /* If only calls can throw, and we have a frame pointer, | |
977 | save up adjustments until we see the CALL_INSN. */ | |
c1e9f663 | 978 | else if (! flag_non_call_exceptions |
7d9d8943 | 979 | && cfa.reg != STACK_POINTER_REGNUM) |
b57d9225 JM |
980 | return; |
981 | ||
6020d360 | 982 | if (GET_CODE (insn) == BARRIER) |
0021b564 | 983 | { |
6020d360 JM |
984 | /* When we see a BARRIER, we know to reset args_size to 0. Usually |
985 | the compiler will have already emitted a stack adjustment, but | |
986 | doesn't bother for calls to noreturn functions. */ | |
987 | #ifdef STACK_GROWS_DOWNWARD | |
988 | offset = -args_size; | |
989 | #else | |
990 | offset = args_size; | |
991 | #endif | |
0021b564 | 992 | } |
6020d360 | 993 | else if (GET_CODE (PATTERN (insn)) == SET) |
0021b564 | 994 | { |
1ba5ae8f AH |
995 | offset = stack_adjust_offset (PATTERN (insn)); |
996 | } | |
997 | else if (GET_CODE (PATTERN (insn)) == PARALLEL | |
998 | || GET_CODE (PATTERN (insn)) == SEQUENCE) | |
999 | { | |
1000 | /* There may be stack adjustments inside compound insns. Search | |
1001 | for them. */ | |
1002 | int j; | |
0021b564 | 1003 | |
1ba5ae8f AH |
1004 | offset = 0; |
1005 | for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--) | |
6020d360 | 1006 | { |
1ba5ae8f AH |
1007 | rtx pattern = XVECEXP (PATTERN (insn), 0, j); |
1008 | if (GET_CODE (pattern) == SET) | |
1009 | offset += stack_adjust_offset (pattern); | |
6020d360 | 1010 | } |
0021b564 JM |
1011 | } |
1012 | else | |
1013 | return; | |
0b34cf1e | 1014 | |
6020d360 JM |
1015 | if (offset == 0) |
1016 | return; | |
1017 | ||
7d9d8943 AM |
1018 | if (cfa.reg == STACK_POINTER_REGNUM) |
1019 | cfa.offset += offset; | |
0021b564 JM |
1020 | |
1021 | #ifndef STACK_GROWS_DOWNWARD | |
1022 | offset = -offset; | |
1023 | #endif | |
1024 | args_size += offset; | |
1025 | if (args_size < 0) | |
1026 | args_size = 0; | |
1027 | ||
1028 | label = dwarf2out_cfi_label (); | |
7d9d8943 | 1029 | def_cfa_1 (label, &cfa); |
0021b564 JM |
1030 | dwarf2out_args_size (label, args_size); |
1031 | } | |
1032 | ||
fbfa55b0 RH |
1033 | /* We delay emitting a register save until either (a) we reach the end |
1034 | of the prologue or (b) the register is clobbered. This clusters | |
1035 | register saves so that there are fewer pc advances. */ | |
1036 | ||
1037 | struct queued_reg_save | |
1038 | { | |
1039 | struct queued_reg_save *next; | |
1040 | rtx reg; | |
1041 | long cfa_offset; | |
1042 | }; | |
1043 | ||
1044 | static struct queued_reg_save *queued_reg_saves; | |
1045 | static const char *last_reg_save_label; | |
1046 | ||
1047 | static void | |
1048 | queue_reg_save (label, reg, offset) | |
1049 | const char *label; | |
1050 | rtx reg; | |
1051 | long offset; | |
1052 | { | |
1053 | struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q)); | |
1054 | ||
1055 | q->next = queued_reg_saves; | |
1056 | q->reg = reg; | |
1057 | q->cfa_offset = offset; | |
1058 | queued_reg_saves = q; | |
1059 | ||
1060 | last_reg_save_label = label; | |
1061 | } | |
1062 | ||
1063 | static void | |
1064 | flush_queued_reg_saves () | |
1065 | { | |
1066 | struct queued_reg_save *q, *next; | |
1067 | ||
1068 | for (q = queued_reg_saves; q ; q = next) | |
1069 | { | |
1070 | dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset); | |
1071 | next = q->next; | |
1072 | free (q); | |
1073 | } | |
1074 | ||
1075 | queued_reg_saves = NULL; | |
1076 | last_reg_save_label = NULL; | |
1077 | } | |
1078 | ||
1079 | static bool | |
1080 | clobbers_queued_reg_save (insn) | |
1081 | rtx insn; | |
1082 | { | |
1083 | struct queued_reg_save *q; | |
1084 | ||
1085 | for (q = queued_reg_saves; q ; q = q->next) | |
1086 | if (modified_in_p (q->reg, insn)) | |
1087 | return true; | |
1088 | ||
1089 | return false; | |
1090 | } | |
1091 | ||
1092 | ||
770ca8c6 JO |
1093 | /* A temporary register holding an integral value used in adjusting SP |
1094 | or setting up the store_reg. The "offset" field holds the integer | |
1095 | value, not an offset. */ | |
fbfa55b0 | 1096 | static dw_cfa_location cfa_temp; |
770ca8c6 JO |
1097 | |
1098 | /* Record call frame debugging information for an expression EXPR, | |
1099 | which either sets SP or FP (adjusting how we calculate the frame | |
1100 | address) or saves a register to the stack. LABEL indicates the | |
1101 | address of EXPR. | |
1102 | ||
1103 | This function encodes a state machine mapping rtxes to actions on | |
1104 | cfa, cfa_store, and cfa_temp.reg. We describe these rules so | |
1105 | users need not read the source code. | |
1106 | ||
a401107d JO |
1107 | The High-Level Picture |
1108 | ||
1109 | Changes in the register we use to calculate the CFA: Currently we | |
1110 | assume that if you copy the CFA register into another register, we | |
1111 | should take the other one as the new CFA register; this seems to | |
1112 | work pretty well. If it's wrong for some target, it's simple | |
1113 | enough not to set RTX_FRAME_RELATED_P on the insn in question. | |
1114 | ||
1115 | Changes in the register we use for saving registers to the stack: | |
1116 | This is usually SP, but not always. Again, we deduce that if you | |
1117 | copy SP into another register (and SP is not the CFA register), | |
1118 | then the new register is the one we will be using for register | |
1119 | saves. This also seems to work. | |
1120 | ||
1121 | Register saves: There's not much guesswork about this one; if | |
1122 | RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a | |
1123 | register save, and the register used to calculate the destination | |
1124 | had better be the one we think we're using for this purpose. | |
1125 | ||
1126 | Except: If the register being saved is the CFA register, and the | |
1127 | offset is non-zero, we are saving the CFA, so we assume we have to | |
1128 | use DW_CFA_def_cfa_expression. If the offset is 0, we assume that | |
1129 | the intent is to save the value of SP from the previous frame. | |
1130 | ||
770ca8c6 JO |
1131 | Invariants / Summaries of Rules |
1132 | ||
a401107d JO |
1133 | cfa current rule for calculating the CFA. It usually |
1134 | consists of a register and an offset. | |
770ca8c6 JO |
1135 | cfa_store register used by prologue code to save things to the stack |
1136 | cfa_store.offset is the offset from the value of | |
1137 | cfa_store.reg to the actual CFA | |
1138 | cfa_temp register holding an integral value. cfa_temp.offset | |
1139 | stores the value, which will be used to adjust the | |
19ec6a36 AM |
1140 | stack pointer. cfa_temp is also used like cfa_store, |
1141 | to track stores to the stack via fp or a temp reg. | |
770ca8c6 JO |
1142 | |
1143 | Rules 1- 4: Setting a register's value to cfa.reg or an expression | |
1144 | with cfa.reg as the first operand changes the cfa.reg and its | |
19ec6a36 AM |
1145 | cfa.offset. Rule 1 and 4 also set cfa_temp.reg and |
1146 | cfa_temp.offset. | |
770ca8c6 JO |
1147 | |
1148 | Rules 6- 9: Set a non-cfa.reg register value to a constant or an | |
1149 | expression yielding a constant. This sets cfa_temp.reg | |
1150 | and cfa_temp.offset. | |
1151 | ||
1152 | Rule 5: Create a new register cfa_store used to save items to the | |
1153 | stack. | |
1154 | ||
19ec6a36 | 1155 | Rules 10-14: Save a register to the stack. Define offset as the |
a401107d | 1156 | difference of the original location and cfa_store's |
19ec6a36 | 1157 | location (or cfa_temp's location if cfa_temp is used). |
770ca8c6 JO |
1158 | |
1159 | The Rules | |
1160 | ||
1161 | "{a,b}" indicates a choice of a xor b. | |
1162 | "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg. | |
1163 | ||
1164 | Rule 1: | |
1165 | (set <reg1> <reg2>:cfa.reg) | |
19ec6a36 | 1166 | effects: cfa.reg = <reg1> |
770ca8c6 | 1167 | cfa.offset unchanged |
19ec6a36 AM |
1168 | cfa_temp.reg = <reg1> |
1169 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1170 | |
1171 | Rule 2: | |
19ec6a36 | 1172 | (set sp ({minus,plus,losum} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg})) |
770ca8c6 JO |
1173 | effects: cfa.reg = sp if fp used |
1174 | cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp | |
1175 | cfa_store.offset += {+/- <const_int>, cfa_temp.offset} | |
1176 | if cfa_store.reg==sp | |
1177 | ||
1178 | Rule 3: | |
19ec6a36 | 1179 | (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>)) |
770ca8c6 JO |
1180 | effects: cfa.reg = fp |
1181 | cfa_offset += +/- <const_int> | |
1182 | ||
1183 | Rule 4: | |
19ec6a36 | 1184 | (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>)) |
770ca8c6 JO |
1185 | constraints: <reg1> != fp |
1186 | <reg1> != sp | |
1187 | effects: cfa.reg = <reg1> | |
19ec6a36 AM |
1188 | cfa_temp.reg = <reg1> |
1189 | cfa_temp.offset = cfa.offset | |
770ca8c6 JO |
1190 | |
1191 | Rule 5: | |
1192 | (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg)) | |
1193 | constraints: <reg1> != fp | |
1194 | <reg1> != sp | |
1195 | effects: cfa_store.reg = <reg1> | |
1196 | cfa_store.offset = cfa.offset - cfa_temp.offset | |
1197 | ||
1198 | Rule 6: | |
1199 | (set <reg> <const_int>) | |
1200 | effects: cfa_temp.reg = <reg> | |
1201 | cfa_temp.offset = <const_int> | |
1202 | ||
1203 | Rule 7: | |
1204 | (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>)) | |
1205 | effects: cfa_temp.reg = <reg1> | |
1206 | cfa_temp.offset |= <const_int> | |
1207 | ||
1208 | Rule 8: | |
1209 | (set <reg> (high <exp>)) | |
1210 | effects: none | |
1211 | ||
1212 | Rule 9: | |
1213 | (set <reg> (lo_sum <exp> <const_int>)) | |
1214 | effects: cfa_temp.reg = <reg> | |
1215 | cfa_temp.offset = <const_int> | |
1216 | ||
1217 | Rule 10: | |
1218 | (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>) | |
1219 | effects: cfa_store.offset -= <const_int> | |
1220 | cfa.offset = cfa_store.offset if cfa.reg == sp | |
770ca8c6 | 1221 | cfa.reg = sp |
19ec6a36 | 1222 | cfa.base_offset = -cfa_store.offset |
770ca8c6 JO |
1223 | |
1224 | Rule 11: | |
1225 | (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>) | |
1226 | effects: cfa_store.offset += -/+ mode_size(mem) | |
1227 | cfa.offset = cfa_store.offset if cfa.reg == sp | |
770ca8c6 | 1228 | cfa.reg = sp |
19ec6a36 | 1229 | cfa.base_offset = -cfa_store.offset |
770ca8c6 JO |
1230 | |
1231 | Rule 12: | |
19ec6a36 AM |
1232 | (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) <reg2>) |
1233 | effects: cfa.reg = <reg1> | |
1234 | cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset | |
770ca8c6 JO |
1235 | |
1236 | Rule 13: | |
19ec6a36 AM |
1237 | (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>) |
1238 | effects: cfa.reg = <reg1> | |
1239 | cfa.base_offset = -{cfa_store,cfa_temp}.offset | |
1240 | ||
1241 | Rule 14: | |
1242 | (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>) | |
1243 | effects: cfa.reg = <reg1> | |
1244 | cfa.base_offset = -cfa_temp.offset | |
1245 | cfa_temp.offset -= mode_size(mem) */ | |
b664de3a AM |
1246 | |
1247 | static void | |
1248 | dwarf2out_frame_debug_expr (expr, label) | |
1249 | rtx expr; | |
d3e3972c | 1250 | const char *label; |
b664de3a AM |
1251 | { |
1252 | rtx src, dest; | |
1253 | long offset; | |
556273e0 KH |
1254 | |
1255 | /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of | |
1256 | the PARALLEL independently. The first element is always processed if | |
770ca8c6 | 1257 | it is a SET. This is for backward compatibility. Other elements |
556273e0 KH |
1258 | are processed only if they are SETs and the RTX_FRAME_RELATED_P |
1259 | flag is set in them. */ | |
b664de3a | 1260 | |
79d13342 NC |
1261 | if (GET_CODE (expr) == PARALLEL |
1262 | || GET_CODE (expr) == SEQUENCE) | |
556273e0 | 1263 | { |
b664de3a AM |
1264 | int par_index; |
1265 | int limit = XVECLEN (expr, 0); | |
1266 | ||
1267 | for (par_index = 0; par_index < limit; par_index++) | |
556273e0 KH |
1268 | { |
1269 | rtx x = XVECEXP (expr, 0, par_index); | |
1270 | ||
1271 | if (GET_CODE (x) == SET && | |
b664de3a | 1272 | (RTX_FRAME_RELATED_P (x) || par_index == 0)) |
2618f955 | 1273 | dwarf2out_frame_debug_expr (x, label); |
556273e0 | 1274 | } |
b664de3a AM |
1275 | return; |
1276 | } | |
556273e0 | 1277 | |
b664de3a AM |
1278 | if (GET_CODE (expr) != SET) |
1279 | abort (); | |
1280 | ||
1281 | src = SET_SRC (expr); | |
1282 | dest = SET_DEST (expr); | |
1283 | ||
1284 | switch (GET_CODE (dest)) | |
1285 | { | |
1286 | case REG: | |
770ca8c6 | 1287 | /* Rule 1 */ |
b664de3a AM |
1288 | /* Update the CFA rule wrt SP or FP. Make sure src is |
1289 | relative to the current CFA register. */ | |
1290 | switch (GET_CODE (src)) | |
556273e0 KH |
1291 | { |
1292 | /* Setting FP from SP. */ | |
1293 | case REG: | |
1294 | if (cfa.reg == (unsigned) REGNO (src)) | |
1295 | /* OK. */ | |
1296 | ; | |
626d1efd | 1297 | else |
556273e0 | 1298 | abort (); |
2c849145 JM |
1299 | |
1300 | /* We used to require that dest be either SP or FP, but the | |
1301 | ARM copies SP to a temporary register, and from there to | |
1302 | FP. So we just rely on the backends to only set | |
1303 | RTX_FRAME_RELATED_P on appropriate insns. */ | |
556273e0 | 1304 | cfa.reg = REGNO (dest); |
19ec6a36 AM |
1305 | cfa_temp.reg = cfa.reg; |
1306 | cfa_temp.offset = cfa.offset; | |
556273e0 | 1307 | break; |
b664de3a | 1308 | |
556273e0 KH |
1309 | case PLUS: |
1310 | case MINUS: | |
19ec6a36 | 1311 | case LO_SUM: |
556273e0 KH |
1312 | if (dest == stack_pointer_rtx) |
1313 | { | |
770ca8c6 | 1314 | /* Rule 2 */ |
2618f955 MM |
1315 | /* Adjusting SP. */ |
1316 | switch (GET_CODE (XEXP (src, 1))) | |
1317 | { | |
1318 | case CONST_INT: | |
1319 | offset = INTVAL (XEXP (src, 1)); | |
1320 | break; | |
1321 | case REG: | |
770ca8c6 | 1322 | if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg) |
2618f955 | 1323 | abort (); |
770ca8c6 | 1324 | offset = cfa_temp.offset; |
2618f955 MM |
1325 | break; |
1326 | default: | |
1327 | abort (); | |
1328 | } | |
1329 | ||
1330 | if (XEXP (src, 0) == hard_frame_pointer_rtx) | |
1331 | { | |
1332 | /* Restoring SP from FP in the epilogue. */ | |
7d9d8943 | 1333 | if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM) |
2618f955 | 1334 | abort (); |
7d9d8943 | 1335 | cfa.reg = STACK_POINTER_REGNUM; |
2618f955 | 1336 | } |
19ec6a36 AM |
1337 | else if (GET_CODE (src) == LO_SUM) |
1338 | /* Assume we've set the source reg of the LO_SUM from sp. */ | |
1339 | ; | |
2618f955 MM |
1340 | else if (XEXP (src, 0) != stack_pointer_rtx) |
1341 | abort (); | |
1342 | ||
19ec6a36 | 1343 | if (GET_CODE (src) != MINUS) |
2618f955 | 1344 | offset = -offset; |
7d9d8943 AM |
1345 | if (cfa.reg == STACK_POINTER_REGNUM) |
1346 | cfa.offset += offset; | |
1347 | if (cfa_store.reg == STACK_POINTER_REGNUM) | |
1348 | cfa_store.offset += offset; | |
556273e0 KH |
1349 | } |
1350 | else if (dest == hard_frame_pointer_rtx) | |
1351 | { | |
770ca8c6 | 1352 | /* Rule 3 */ |
2618f955 MM |
1353 | /* Either setting the FP from an offset of the SP, |
1354 | or adjusting the FP */ | |
2c849145 | 1355 | if (! frame_pointer_needed) |
2618f955 MM |
1356 | abort (); |
1357 | ||
2c849145 | 1358 | if (GET_CODE (XEXP (src, 0)) == REG |
7d9d8943 | 1359 | && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg |
2618f955 MM |
1360 | && GET_CODE (XEXP (src, 1)) == CONST_INT) |
1361 | { | |
2618f955 | 1362 | offset = INTVAL (XEXP (src, 1)); |
19ec6a36 | 1363 | if (GET_CODE (src) != MINUS) |
2618f955 | 1364 | offset = -offset; |
7d9d8943 AM |
1365 | cfa.offset += offset; |
1366 | cfa.reg = HARD_FRAME_POINTER_REGNUM; | |
2618f955 | 1367 | } |
556273e0 KH |
1368 | else |
1369 | abort (); | |
1370 | } | |
1371 | else | |
1372 | { | |
19ec6a36 | 1373 | if (GET_CODE (src) == MINUS) |
2618f955 | 1374 | abort (); |
b53ef1a2 | 1375 | |
770ca8c6 | 1376 | /* Rule 4 */ |
b53ef1a2 NC |
1377 | if (GET_CODE (XEXP (src, 0)) == REG |
1378 | && REGNO (XEXP (src, 0)) == cfa.reg | |
1379 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
34ce3d7b JM |
1380 | { |
1381 | /* Setting a temporary CFA register that will be copied | |
1382 | into the FP later on. */ | |
19ec6a36 | 1383 | offset = - INTVAL (XEXP (src, 1)); |
34ce3d7b JM |
1384 | cfa.offset += offset; |
1385 | cfa.reg = REGNO (dest); | |
19ec6a36 AM |
1386 | /* Or used to save regs to the stack. */ |
1387 | cfa_temp.reg = cfa.reg; | |
1388 | cfa_temp.offset = cfa.offset; | |
34ce3d7b | 1389 | } |
770ca8c6 | 1390 | /* Rule 5 */ |
19ec6a36 AM |
1391 | else if (GET_CODE (XEXP (src, 0)) == REG |
1392 | && REGNO (XEXP (src, 0)) == cfa_temp.reg | |
1393 | && XEXP (src, 1) == stack_pointer_rtx) | |
b53ef1a2 | 1394 | { |
00a42e21 JM |
1395 | /* Setting a scratch register that we will use instead |
1396 | of SP for saving registers to the stack. */ | |
b53ef1a2 NC |
1397 | if (cfa.reg != STACK_POINTER_REGNUM) |
1398 | abort (); | |
1399 | cfa_store.reg = REGNO (dest); | |
770ca8c6 | 1400 | cfa_store.offset = cfa.offset - cfa_temp.offset; |
b53ef1a2 | 1401 | } |
19ec6a36 AM |
1402 | /* Rule 9 */ |
1403 | else if (GET_CODE (src) == LO_SUM | |
1404 | && GET_CODE (XEXP (src, 1)) == CONST_INT) | |
1405 | { | |
1406 | cfa_temp.reg = REGNO (dest); | |
1407 | cfa_temp.offset = INTVAL (XEXP (src, 1)); | |
1408 | } | |
1409 | else | |
1410 | abort (); | |
556273e0 KH |
1411 | } |
1412 | break; | |
b664de3a | 1413 | |
770ca8c6 | 1414 | /* Rule 6 */ |
556273e0 | 1415 | case CONST_INT: |
770ca8c6 JO |
1416 | cfa_temp.reg = REGNO (dest); |
1417 | cfa_temp.offset = INTVAL (src); | |
556273e0 | 1418 | break; |
b664de3a | 1419 | |
770ca8c6 | 1420 | /* Rule 7 */ |
556273e0 KH |
1421 | case IOR: |
1422 | if (GET_CODE (XEXP (src, 0)) != REG | |
770ca8c6 | 1423 | || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg |
2618f955 | 1424 | || GET_CODE (XEXP (src, 1)) != CONST_INT) |
556273e0 | 1425 | abort (); |
770ca8c6 JO |
1426 | if ((unsigned) REGNO (dest) != cfa_temp.reg) |
1427 | cfa_temp.reg = REGNO (dest); | |
1428 | cfa_temp.offset |= INTVAL (XEXP (src, 1)); | |
556273e0 | 1429 | break; |
b664de3a | 1430 | |
9ae21d2a AM |
1431 | /* Skip over HIGH, assuming it will be followed by a LO_SUM, |
1432 | which will fill in all of the bits. */ | |
1433 | /* Rule 8 */ | |
1434 | case HIGH: | |
1435 | break; | |
1436 | ||
556273e0 KH |
1437 | default: |
1438 | abort (); | |
1439 | } | |
7d9d8943 | 1440 | def_cfa_1 (label, &cfa); |
2618f955 | 1441 | break; |
b664de3a | 1442 | |
2618f955 | 1443 | case MEM: |
2618f955 MM |
1444 | if (GET_CODE (src) != REG) |
1445 | abort (); | |
7d9d8943 | 1446 | |
7d9d8943 AM |
1447 | /* Saving a register to the stack. Make sure dest is relative to the |
1448 | CFA register. */ | |
2618f955 MM |
1449 | switch (GET_CODE (XEXP (dest, 0))) |
1450 | { | |
770ca8c6 | 1451 | /* Rule 10 */ |
2618f955 | 1452 | /* With a push. */ |
e2134eea JH |
1453 | case PRE_MODIFY: |
1454 | /* We can't handle variable size modifications. */ | |
1455 | if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT) | |
1456 | abort(); | |
1457 | offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1)); | |
1458 | ||
1459 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM | |
1460 | || cfa_store.reg != STACK_POINTER_REGNUM) | |
1461 | abort (); | |
1462 | cfa_store.offset += offset; | |
1463 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1464 | cfa.offset = cfa_store.offset; | |
1465 | ||
1466 | offset = -cfa_store.offset; | |
1467 | break; | |
770ca8c6 | 1468 | /* Rule 11 */ |
2618f955 MM |
1469 | case PRE_INC: |
1470 | case PRE_DEC: | |
1471 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
1472 | if (GET_CODE (XEXP (dest, 0)) == PRE_INC) | |
1473 | offset = -offset; | |
b664de3a | 1474 | |
2618f955 | 1475 | if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM |
7d9d8943 | 1476 | || cfa_store.reg != STACK_POINTER_REGNUM) |
2618f955 | 1477 | abort (); |
7d9d8943 AM |
1478 | cfa_store.offset += offset; |
1479 | if (cfa.reg == STACK_POINTER_REGNUM) | |
1480 | cfa.offset = cfa_store.offset; | |
b664de3a | 1481 | |
7d9d8943 | 1482 | offset = -cfa_store.offset; |
2618f955 | 1483 | break; |
b664de3a | 1484 | |
770ca8c6 | 1485 | /* Rule 12 */ |
2618f955 MM |
1486 | /* With an offset. */ |
1487 | case PLUS: | |
1488 | case MINUS: | |
19ec6a36 | 1489 | case LO_SUM: |
770ca8c6 JO |
1490 | if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT) |
1491 | abort (); | |
2618f955 MM |
1492 | offset = INTVAL (XEXP (XEXP (dest, 0), 1)); |
1493 | if (GET_CODE (XEXP (dest, 0)) == MINUS) | |
1494 | offset = -offset; | |
b664de3a | 1495 | |
19ec6a36 AM |
1496 | if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) |
1497 | offset -= cfa_store.offset; | |
1498 | else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) | |
1499 | offset -= cfa_temp.offset; | |
1500 | else | |
2618f955 | 1501 | abort (); |
2618f955 MM |
1502 | break; |
1503 | ||
770ca8c6 | 1504 | /* Rule 13 */ |
2618f955 MM |
1505 | /* Without an offset. */ |
1506 | case REG: | |
19ec6a36 AM |
1507 | if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0))) |
1508 | offset = -cfa_store.offset; | |
1509 | else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0))) | |
1510 | offset = -cfa_temp.offset; | |
1511 | else | |
556273e0 | 1512 | abort (); |
19ec6a36 AM |
1513 | break; |
1514 | ||
1515 | /* Rule 14 */ | |
1516 | case POST_INC: | |
1517 | if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) | |
1518 | abort (); | |
1519 | offset = -cfa_temp.offset; | |
1520 | cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest)); | |
2618f955 MM |
1521 | break; |
1522 | ||
1523 | default: | |
1524 | abort (); | |
1525 | } | |
e09bbb25 | 1526 | |
556273e0 | 1527 | if (REGNO (src) != STACK_POINTER_REGNUM |
e09bbb25 JM |
1528 | && REGNO (src) != HARD_FRAME_POINTER_REGNUM |
1529 | && (unsigned) REGNO (src) == cfa.reg) | |
1530 | { | |
1531 | /* We're storing the current CFA reg into the stack. */ | |
1532 | ||
1533 | if (cfa.offset == 0) | |
1534 | { | |
1535 | /* If the source register is exactly the CFA, assume | |
1536 | we're saving SP like any other register; this happens | |
1537 | on the ARM. */ | |
1538 | ||
1539 | def_cfa_1 (label, &cfa); | |
fbfa55b0 | 1540 | queue_reg_save (label, stack_pointer_rtx, offset); |
e09bbb25 JM |
1541 | break; |
1542 | } | |
1543 | else | |
1544 | { | |
1545 | /* Otherwise, we'll need to look in the stack to | |
1546 | calculate the CFA. */ | |
1547 | ||
1548 | rtx x = XEXP (dest, 0); | |
1549 | if (GET_CODE (x) != REG) | |
1550 | x = XEXP (x, 0); | |
1551 | if (GET_CODE (x) != REG) | |
1552 | abort (); | |
1553 | cfa.reg = (unsigned) REGNO (x); | |
1554 | cfa.base_offset = offset; | |
1555 | cfa.indirect = 1; | |
1556 | def_cfa_1 (label, &cfa); | |
1557 | break; | |
1558 | } | |
1559 | } | |
1560 | ||
7d9d8943 | 1561 | def_cfa_1 (label, &cfa); |
fbfa55b0 | 1562 | queue_reg_save (label, src, offset); |
2618f955 MM |
1563 | break; |
1564 | ||
1565 | default: | |
1566 | abort (); | |
1567 | } | |
b664de3a AM |
1568 | } |
1569 | ||
3f76745e JM |
1570 | /* Record call frame debugging information for INSN, which either |
1571 | sets SP or FP (adjusting how we calculate the frame address) or saves a | |
1572 | register to the stack. If INSN is NULL_RTX, initialize our state. */ | |
71dfc51f | 1573 | |
3f76745e JM |
1574 | void |
1575 | dwarf2out_frame_debug (insn) | |
1576 | rtx insn; | |
a3f97cbb | 1577 | { |
d3e3972c | 1578 | const char *label; |
b664de3a | 1579 | rtx src; |
3f76745e JM |
1580 | |
1581 | if (insn == NULL_RTX) | |
a3f97cbb | 1582 | { |
fbfa55b0 RH |
1583 | /* Flush any queued register saves. */ |
1584 | flush_queued_reg_saves (); | |
1585 | ||
3f76745e | 1586 | /* Set up state for generating call frame debug info. */ |
7d9d8943 AM |
1587 | lookup_cfa (&cfa); |
1588 | if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)) | |
3a88cbd1 | 1589 | abort (); |
7d9d8943 AM |
1590 | cfa.reg = STACK_POINTER_REGNUM; |
1591 | cfa_store = cfa; | |
770ca8c6 JO |
1592 | cfa_temp.reg = -1; |
1593 | cfa_temp.offset = 0; | |
3f76745e JM |
1594 | return; |
1595 | } | |
1596 | ||
fbfa55b0 RH |
1597 | if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn)) |
1598 | flush_queued_reg_saves (); | |
1599 | ||
0021b564 JM |
1600 | if (! RTX_FRAME_RELATED_P (insn)) |
1601 | { | |
fbfa55b0 RH |
1602 | if (!ACCUMULATE_OUTGOING_ARGS) |
1603 | dwarf2out_stack_adjust (insn); | |
0021b564 JM |
1604 | return; |
1605 | } | |
1606 | ||
3f76745e | 1607 | label = dwarf2out_cfi_label (); |
556273e0 | 1608 | |
07ebc930 RH |
1609 | src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX); |
1610 | if (src) | |
1611 | insn = XEXP (src, 0); | |
556273e0 | 1612 | else |
07ebc930 RH |
1613 | insn = PATTERN (insn); |
1614 | ||
b664de3a | 1615 | dwarf2out_frame_debug_expr (insn, label); |
3f76745e JM |
1616 | } |
1617 | ||
3f76745e JM |
1618 | /* Output a Call Frame Information opcode and its operand(s). */ |
1619 | ||
1620 | static void | |
12f0b96b | 1621 | output_cfi (cfi, fde, for_eh) |
3f76745e JM |
1622 | register dw_cfi_ref cfi; |
1623 | register dw_fde_ref fde; | |
12f0b96b | 1624 | int for_eh; |
3f76745e JM |
1625 | { |
1626 | if (cfi->dw_cfi_opc == DW_CFA_advance_loc) | |
1627 | { | |
2e4b9b8c RH |
1628 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1629 | | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)), | |
1630 | "DW_CFA_advance_loc 0x%lx", | |
1631 | cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
3f76745e | 1632 | } |
3f76745e JM |
1633 | else if (cfi->dw_cfi_opc == DW_CFA_offset) |
1634 | { | |
2e4b9b8c RH |
1635 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1636 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)), | |
1637 | "DW_CFA_offset, column 0x%lx", | |
1638 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1639 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); | |
3f76745e JM |
1640 | } |
1641 | else if (cfi->dw_cfi_opc == DW_CFA_restore) | |
1642 | { | |
2e4b9b8c RH |
1643 | dw2_asm_output_data (1, (cfi->dw_cfi_opc |
1644 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)), | |
1645 | "DW_CFA_restore, column 0x%lx", | |
1646 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
3f76745e JM |
1647 | } |
1648 | else | |
1649 | { | |
2e4b9b8c RH |
1650 | dw2_asm_output_data (1, cfi->dw_cfi_opc, |
1651 | "%s", dwarf_cfi_name (cfi->dw_cfi_opc)); | |
3f76745e | 1652 | |
3f76745e JM |
1653 | switch (cfi->dw_cfi_opc) |
1654 | { | |
1655 | case DW_CFA_set_loc: | |
e1f9550a RH |
1656 | if (for_eh) |
1657 | dw2_asm_output_encoded_addr_rtx ( | |
1658 | ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0), | |
1659 | gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr), | |
1660 | NULL); | |
1661 | else | |
1662 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, | |
1663 | cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL); | |
3f76745e JM |
1664 | break; |
1665 | case DW_CFA_advance_loc1: | |
2e4b9b8c RH |
1666 | dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1667 | fde->dw_fde_current_label, NULL); | |
bb727b5a | 1668 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
3f76745e JM |
1669 | break; |
1670 | case DW_CFA_advance_loc2: | |
2e4b9b8c RH |
1671 | dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1672 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
1673 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
1674 | break; | |
1675 | case DW_CFA_advance_loc4: | |
2e4b9b8c RH |
1676 | dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1677 | fde->dw_fde_current_label, NULL); | |
3f76745e JM |
1678 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; |
1679 | break; | |
3f76745e | 1680 | case DW_CFA_MIPS_advance_loc8: |
2e4b9b8c RH |
1681 | dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr, |
1682 | fde->dw_fde_current_label, NULL); | |
1683 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
3f76745e | 1684 | break; |
3f76745e | 1685 | case DW_CFA_offset_extended: |
3f388b42 | 1686 | case DW_CFA_GNU_negative_offset_extended: |
3f76745e | 1687 | case DW_CFA_def_cfa: |
2e4b9b8c RH |
1688 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL); |
1689 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); | |
3f76745e JM |
1690 | break; |
1691 | case DW_CFA_restore_extended: | |
1692 | case DW_CFA_undefined: | |
3f76745e JM |
1693 | case DW_CFA_same_value: |
1694 | case DW_CFA_def_cfa_register: | |
2e4b9b8c | 1695 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL); |
3f76745e JM |
1696 | break; |
1697 | case DW_CFA_register: | |
2e4b9b8c RH |
1698 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL); |
1699 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL); | |
3f76745e JM |
1700 | break; |
1701 | case DW_CFA_def_cfa_offset: | |
2e4b9b8c RH |
1702 | case DW_CFA_GNU_args_size: |
1703 | dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL); | |
3f76745e | 1704 | break; |
c53aa195 JM |
1705 | case DW_CFA_GNU_window_save: |
1706 | break; | |
7d9d8943 AM |
1707 | case DW_CFA_def_cfa_expression: |
1708 | output_cfa_loc (cfi); | |
1709 | break; | |
3f76745e JM |
1710 | default: |
1711 | break; | |
1712 | } | |
556273e0 | 1713 | } |
3f76745e JM |
1714 | } |
1715 | ||
1716 | /* Output the call frame information used to used to record information | |
1717 | that relates to calculating the frame pointer, and records the | |
1718 | location of saved registers. */ | |
1719 | ||
1720 | static void | |
1721 | output_call_frame_info (for_eh) | |
1722 | int for_eh; | |
1723 | { | |
ae0ed63a | 1724 | register unsigned int i; |
3f76745e | 1725 | register dw_fde_ref fde; |
3f76745e | 1726 | register dw_cfi_ref cfi; |
a6ab3aad | 1727 | char l1[20], l2[20]; |
52a11cbf RH |
1728 | int any_lsda_needed = 0; |
1729 | char augmentation[6]; | |
e1f9550a RH |
1730 | int augmentation_size; |
1731 | int fde_encoding = DW_EH_PE_absptr; | |
1732 | int per_encoding = DW_EH_PE_absptr; | |
1733 | int lsda_encoding = DW_EH_PE_absptr; | |
3f76745e | 1734 | |
737faf14 JM |
1735 | /* If we don't have any functions we'll want to unwind out of, don't |
1736 | emit any EH unwind information. */ | |
1737 | if (for_eh) | |
1738 | { | |
52a11cbf | 1739 | int any_eh_needed = 0; |
737faf14 | 1740 | for (i = 0; i < fde_table_in_use; ++i) |
52a11cbf RH |
1741 | if (fde_table[i].uses_eh_lsda) |
1742 | any_eh_needed = any_lsda_needed = 1; | |
1743 | else if (! fde_table[i].nothrow) | |
1744 | any_eh_needed = 1; | |
1745 | ||
1746 | if (! any_eh_needed) | |
1747 | return; | |
737faf14 JM |
1748 | } |
1749 | ||
aa0c1401 JL |
1750 | /* We're going to be generating comments, so turn on app. */ |
1751 | if (flag_debug_asm) | |
1752 | app_enable (); | |
956d6950 | 1753 | |
3f76745e JM |
1754 | if (for_eh) |
1755 | { | |
1756 | #ifdef EH_FRAME_SECTION | |
0021b564 | 1757 | EH_FRAME_SECTION (); |
3f76745e | 1758 | #else |
496651db | 1759 | tree label = get_file_function_name ('F'); |
0021b564 | 1760 | |
3167de5b | 1761 | force_data_section (); |
12f0b96b | 1762 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); |
0021b564 JM |
1763 | ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); |
1764 | ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); | |
3f76745e JM |
1765 | #endif |
1766 | assemble_label ("__FRAME_BEGIN__"); | |
1767 | } | |
1768 | else | |
cf2fe500 | 1769 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_FRAME_SECTION); |
3f76745e | 1770 | |
556273e0 | 1771 | /* Output the CIE. */ |
a6ab3aad JM |
1772 | ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh); |
1773 | ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh); | |
2e4b9b8c RH |
1774 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
1775 | "Length of Common Information Entry"); | |
a6ab3aad JM |
1776 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1777 | ||
2e4b9b8c RH |
1778 | /* Now that the CIE pointer is PC-relative for EH, |
1779 | use 0 to identify the CIE. */ | |
1780 | dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE), | |
1781 | (for_eh ? 0 : DW_CIE_ID), | |
1782 | "CIE Identifier Tag"); | |
3f76745e | 1783 | |
2e4b9b8c | 1784 | dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version"); |
3f76745e | 1785 | |
52a11cbf | 1786 | augmentation[0] = 0; |
e1f9550a | 1787 | augmentation_size = 0; |
52a11cbf | 1788 | if (for_eh) |
a6ab3aad | 1789 | { |
e1f9550a RH |
1790 | char *p; |
1791 | ||
52a11cbf RH |
1792 | /* Augmentation: |
1793 | z Indicates that a uleb128 is present to size the | |
1794 | augmentation section. | |
e1f9550a RH |
1795 | L Indicates the encoding (and thus presence) of |
1796 | an LSDA pointer in the FDE augmentation. | |
1797 | R Indicates a non-default pointer encoding for | |
1798 | FDE code pointers. | |
1799 | P Indicates the presence of an encoding + language | |
1800 | personality routine in the CIE augmentation. */ | |
1801 | ||
1802 | fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0); | |
1803 | per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1); | |
1804 | lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0); | |
1805 | ||
1806 | p = augmentation + 1; | |
1807 | if (eh_personality_libfunc) | |
1808 | { | |
1809 | *p++ = 'P'; | |
1810 | augmentation_size += 1 + size_of_encoded_value (per_encoding); | |
1811 | } | |
52a11cbf | 1812 | if (any_lsda_needed) |
e1f9550a RH |
1813 | { |
1814 | *p++ = 'L'; | |
1815 | augmentation_size += 1; | |
1816 | } | |
1817 | if (fde_encoding != DW_EH_PE_absptr) | |
1818 | { | |
1819 | *p++ = 'R'; | |
1820 | augmentation_size += 1; | |
1821 | } | |
1822 | if (p > augmentation + 1) | |
1823 | { | |
1824 | augmentation[0] = 'z'; | |
1825 | *p = '\0'; | |
1826 | } | |
099c8b17 RH |
1827 | |
1828 | /* Ug. Some platforms can't do unaligned dynamic relocations at all. */ | |
1829 | if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned) | |
1830 | { | |
1831 | int offset = ( 4 /* Length */ | |
1832 | + 4 /* CIE Id */ | |
1833 | + 1 /* CIE version */ | |
1834 | + strlen (augmentation) + 1 /* Augmentation */ | |
1835 | + size_of_uleb128 (1) /* Code alignment */ | |
1836 | + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT) | |
1837 | + 1 /* RA column */ | |
1838 | + 1 /* Augmentation size */ | |
1839 | + 1 /* Personality encoding */ ); | |
1840 | int pad = -offset & (PTR_SIZE - 1); | |
1841 | ||
1842 | augmentation_size += pad; | |
1843 | ||
1844 | /* Augmentations should be small, so there's scarce need to | |
1845 | iterate for a solution. Die if we exceed one uleb128 byte. */ | |
1846 | if (size_of_uleb128 (augmentation_size) != 1) | |
1847 | abort (); | |
1848 | } | |
a6ab3aad | 1849 | } |
52a11cbf | 1850 | dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation"); |
3f76745e | 1851 | |
2e4b9b8c | 1852 | dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor"); |
3f76745e | 1853 | |
2e4b9b8c RH |
1854 | dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT, |
1855 | "CIE Data Alignment Factor"); | |
3f76745e | 1856 | |
2e4b9b8c | 1857 | dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column"); |
3f76745e | 1858 | |
52a11cbf RH |
1859 | if (augmentation[0]) |
1860 | { | |
e1f9550a | 1861 | dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size"); |
52a11cbf | 1862 | if (eh_personality_libfunc) |
e1f9550a RH |
1863 | { |
1864 | dw2_asm_output_data (1, per_encoding, "Personality (%s)", | |
1865 | eh_data_format_name (per_encoding)); | |
1866 | dw2_asm_output_encoded_addr_rtx (per_encoding, | |
1867 | eh_personality_libfunc, NULL); | |
1868 | } | |
1869 | if (any_lsda_needed) | |
1870 | dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)", | |
1871 | eh_data_format_name (lsda_encoding)); | |
1872 | if (fde_encoding != DW_EH_PE_absptr) | |
1873 | dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)", | |
1874 | eh_data_format_name (fde_encoding)); | |
52a11cbf RH |
1875 | } |
1876 | ||
3f76745e | 1877 | for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next) |
12f0b96b | 1878 | output_cfi (cfi, NULL, for_eh); |
3f76745e JM |
1879 | |
1880 | /* Pad the CIE out to an address sized boundary. */ | |
12f0b96b AM |
1881 | ASM_OUTPUT_ALIGN (asm_out_file, |
1882 | floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)); | |
a6ab3aad | 1883 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e JM |
1884 | |
1885 | /* Loop through all of the FDE's. */ | |
1886 | for (i = 0; i < fde_table_in_use; ++i) | |
1887 | { | |
1888 | fde = &fde_table[i]; | |
3f76745e | 1889 | |
52a11cbf RH |
1890 | /* Don't emit EH unwind info for leaf functions that don't need it. */ |
1891 | if (for_eh && fde->nothrow && ! fde->uses_eh_lsda) | |
737faf14 JM |
1892 | continue; |
1893 | ||
2e4b9b8c | 1894 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2); |
556273e0 KH |
1895 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2); |
1896 | ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2); | |
2e4b9b8c RH |
1897 | dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, |
1898 | "FDE Length"); | |
a6ab3aad JM |
1899 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1900 | ||
eef906d6 JW |
1901 | /* ??? This always emits a 4 byte offset when for_eh is true, but it |
1902 | emits a target dependent sized offset when for_eh is not true. | |
1903 | This inconsistency may confuse gdb. The only case where we need a | |
1904 | non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI | |
1905 | compatibility if we emit a 4 byte offset. We need a 4 byte offset | |
1906 | though in order to be compatible with the dwarf_fde struct in frame.c. | |
1907 | If the for_eh case is changed, then the struct in frame.c has | |
1908 | to be adjusted appropriately. */ | |
3f76745e | 1909 | if (for_eh) |
2e4b9b8c | 1910 | dw2_asm_output_delta (4, l1, "__FRAME_BEGIN__", "FDE CIE offset"); |
3f76745e | 1911 | else |
2e4b9b8c | 1912 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, |
cf2fe500 | 1913 | stripattributes (DEBUG_FRAME_SECTION), |
2e4b9b8c | 1914 | "FDE CIE offset"); |
3f76745e | 1915 | |
e1f9550a RH |
1916 | if (for_eh) |
1917 | { | |
1918 | dw2_asm_output_encoded_addr_rtx (fde_encoding, | |
1919 | gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin), | |
1920 | "FDE initial location"); | |
1921 | dw2_asm_output_delta (size_of_encoded_value (fde_encoding), | |
1922 | fde->dw_fde_end, fde->dw_fde_begin, | |
1923 | "FDE address range"); | |
1924 | } | |
1925 | else | |
1926 | { | |
1927 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin, | |
1928 | "FDE initial location"); | |
1929 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, | |
1930 | fde->dw_fde_end, fde->dw_fde_begin, | |
1931 | "FDE address range"); | |
1932 | } | |
3f76745e | 1933 | |
52a11cbf RH |
1934 | if (augmentation[0]) |
1935 | { | |
e1f9550a | 1936 | if (any_lsda_needed) |
52a11cbf | 1937 | { |
099c8b17 RH |
1938 | int size = size_of_encoded_value (lsda_encoding); |
1939 | ||
1940 | if (lsda_encoding == DW_EH_PE_aligned) | |
1941 | { | |
1942 | int offset = ( 4 /* Length */ | |
1943 | + 4 /* CIE offset */ | |
1944 | + 2 * size_of_encoded_value (fde_encoding) | |
1945 | + 1 /* Augmentation size */ ); | |
1946 | int pad = -offset & (PTR_SIZE - 1); | |
1947 | ||
1948 | size += pad; | |
1949 | if (size_of_uleb128 (size) != 1) | |
1950 | abort (); | |
1951 | } | |
1952 | ||
1953 | dw2_asm_output_data_uleb128 (size, "Augmentation size"); | |
e1f9550a RH |
1954 | |
1955 | if (fde->uses_eh_lsda) | |
1956 | { | |
1957 | ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA", | |
1958 | fde->funcdef_number); | |
1959 | dw2_asm_output_encoded_addr_rtx ( | |
1960 | lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1), | |
1961 | "Language Specific Data Area"); | |
1962 | } | |
1963 | else | |
099c8b17 RH |
1964 | { |
1965 | if (lsda_encoding == DW_EH_PE_aligned) | |
1966 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); | |
1967 | dw2_asm_output_data (size_of_encoded_value (lsda_encoding), | |
1968 | 0, "Language Specific Data Area (none)"); | |
1969 | } | |
52a11cbf RH |
1970 | } |
1971 | else | |
e1f9550a | 1972 | dw2_asm_output_data_uleb128 (0, "Augmentation size"); |
52a11cbf RH |
1973 | } |
1974 | ||
3f76745e JM |
1975 | /* Loop through the Call Frame Instructions associated with |
1976 | this FDE. */ | |
1977 | fde->dw_fde_current_label = fde->dw_fde_begin; | |
1978 | for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next) | |
12f0b96b | 1979 | output_cfi (cfi, fde, for_eh); |
3f76745e | 1980 | |
a6ab3aad | 1981 | /* Pad the FDE out to an address sized boundary. */ |
12f0b96b | 1982 | ASM_OUTPUT_ALIGN (asm_out_file, |
e1f9550a | 1983 | floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE))); |
a6ab3aad | 1984 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
3f76745e | 1985 | } |
2e4b9b8c | 1986 | |
3f76745e JM |
1987 | #ifndef EH_FRAME_SECTION |
1988 | if (for_eh) | |
2e4b9b8c | 1989 | dw2_asm_output_data (4, 0, "End of Table"); |
3f76745e | 1990 | #endif |
a6ab3aad JM |
1991 | #ifdef MIPS_DEBUGGING_INFO |
1992 | /* Work around Irix 6 assembler bug whereby labels at the end of a section | |
1993 | get a value of 0. Putting .align 0 after the label fixes it. */ | |
1994 | ASM_OUTPUT_ALIGN (asm_out_file, 0); | |
1995 | #endif | |
aa0c1401 JL |
1996 | |
1997 | /* Turn off app to make assembly quicker. */ | |
1998 | if (flag_debug_asm) | |
1999 | app_disable (); | |
a6ab3aad JM |
2000 | } |
2001 | ||
3f76745e JM |
2002 | /* Output a marker (i.e. a label) for the beginning of a function, before |
2003 | the prologue. */ | |
2004 | ||
2005 | void | |
653e276c NB |
2006 | dwarf2out_begin_prologue (line, file) |
2007 | unsigned int line ATTRIBUTE_UNUSED; | |
2008 | const char *file ATTRIBUTE_UNUSED; | |
3f76745e JM |
2009 | { |
2010 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2011 | register dw_fde_ref fde; | |
2012 | ||
2a1ee410 RH |
2013 | current_function_func_begin_label = 0; |
2014 | ||
2015 | #ifdef IA64_UNWIND_INFO | |
2016 | /* ??? current_function_func_begin_label is also used by except.c | |
2017 | for call-site information. We must emit this label if it might | |
2018 | be used. */ | |
2019 | if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS) | |
2020 | && ! dwarf2out_do_frame ()) | |
2021 | return; | |
2022 | #else | |
2023 | if (! dwarf2out_do_frame ()) | |
2024 | return; | |
2025 | #endif | |
2026 | ||
4f988ea2 JM |
2027 | ++current_funcdef_number; |
2028 | ||
3f76745e JM |
2029 | function_section (current_function_decl); |
2030 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL, | |
2031 | current_funcdef_number); | |
2a1ee410 RH |
2032 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL, |
2033 | current_funcdef_number); | |
00262c8a | 2034 | current_function_func_begin_label = get_identifier (label); |
3f76745e | 2035 | |
2a1ee410 RH |
2036 | #ifdef IA64_UNWIND_INFO |
2037 | /* We can elide the fde allocation if we're not emitting debug info. */ | |
2038 | if (! dwarf2out_do_frame ()) | |
2039 | return; | |
2040 | #endif | |
2041 | ||
3f76745e JM |
2042 | /* Expand the fde table if necessary. */ |
2043 | if (fde_table_in_use == fde_table_allocated) | |
2044 | { | |
2045 | fde_table_allocated += FDE_TABLE_INCREMENT; | |
2046 | fde_table | |
2047 | = (dw_fde_ref) xrealloc (fde_table, | |
2048 | fde_table_allocated * sizeof (dw_fde_node)); | |
a3f97cbb | 2049 | } |
3f76745e JM |
2050 | |
2051 | /* Record the FDE associated with this function. */ | |
2052 | current_funcdef_fde = fde_table_in_use; | |
2053 | ||
2054 | /* Add the new FDE at the end of the fde_table. */ | |
2055 | fde = &fde_table[fde_table_in_use++]; | |
2056 | fde->dw_fde_begin = xstrdup (label); | |
2057 | fde->dw_fde_current_label = NULL; | |
2058 | fde->dw_fde_end = NULL; | |
2059 | fde->dw_fde_cfi = NULL; | |
52a11cbf | 2060 | fde->funcdef_number = current_funcdef_number; |
fb13d4d0 | 2061 | fde->nothrow = current_function_nothrow; |
52a11cbf | 2062 | fde->uses_eh_lsda = cfun->uses_eh_lsda; |
737faf14 | 2063 | |
b57d9225 | 2064 | args_size = old_args_size = 0; |
653e276c NB |
2065 | |
2066 | /* We only want to output line number information for the genuine | |
2067 | dwarf2 prologue case, not the eh frame case. */ | |
2068 | #ifdef DWARF2_DEBUGGING_INFO | |
2069 | if (file) | |
2070 | dwarf2out_source_line (line, file); | |
2071 | #endif | |
3f76745e JM |
2072 | } |
2073 | ||
2074 | /* Output a marker (i.e. a label) for the absolute end of the generated code | |
2075 | for a function definition. This gets called *after* the epilogue code has | |
2076 | been generated. */ | |
2077 | ||
2078 | void | |
2079 | dwarf2out_end_epilogue () | |
2080 | { | |
2081 | dw_fde_ref fde; | |
2082 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2083 | ||
2084 | /* Output a label to mark the endpoint of the code generated for this | |
2085 | function. */ | |
2086 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number); | |
2087 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
2088 | fde = &fde_table[fde_table_in_use - 1]; | |
2089 | fde->dw_fde_end = xstrdup (label); | |
3f76745e JM |
2090 | } |
2091 | ||
2092 | void | |
2093 | dwarf2out_frame_init () | |
2094 | { | |
2095 | /* Allocate the initial hunk of the fde_table. */ | |
3de90026 | 2096 | fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node)); |
3f76745e JM |
2097 | fde_table_allocated = FDE_TABLE_INCREMENT; |
2098 | fde_table_in_use = 0; | |
2099 | ||
2100 | /* Generate the CFA instructions common to all FDE's. Do it now for the | |
2101 | sake of lookup_cfa. */ | |
2102 | ||
a6ab3aad | 2103 | #ifdef DWARF2_UNWIND_INFO |
91193900 AS |
2104 | /* On entry, the Canonical Frame Address is at SP. */ |
2105 | dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET); | |
2106 | initial_return_save (INCOMING_RETURN_ADDR_RTX); | |
3f76745e JM |
2107 | #endif |
2108 | } | |
2109 | ||
2110 | void | |
2111 | dwarf2out_frame_finish () | |
2112 | { | |
3f76745e | 2113 | /* Output call frame information. */ |
a6ab3aad | 2114 | #ifdef MIPS_DEBUGGING_INFO |
3f76745e JM |
2115 | if (write_symbols == DWARF2_DEBUG) |
2116 | output_call_frame_info (0); | |
531073e7 | 2117 | if (flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)) |
3f76745e | 2118 | output_call_frame_info (1); |
a6ab3aad JM |
2119 | #else |
2120 | if (write_symbols == DWARF2_DEBUG | |
531073e7 | 2121 | || flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)) |
556273e0 | 2122 | output_call_frame_info (1); |
a6ab3aad | 2123 | #endif |
556273e0 | 2124 | } |
7d9d8943 AM |
2125 | \f |
2126 | /* And now, the subset of the debugging information support code necessary | |
2127 | for emitting location expressions. */ | |
3f76745e | 2128 | |
7d9d8943 AM |
2129 | typedef struct dw_val_struct *dw_val_ref; |
2130 | typedef struct die_struct *dw_die_ref; | |
2131 | typedef struct dw_loc_descr_struct *dw_loc_descr_ref; | |
63e46568 | 2132 | typedef struct dw_loc_list_struct *dw_loc_list_ref; |
3f76745e JM |
2133 | |
2134 | /* Each DIE may have a series of attribute/value pairs. Values | |
2135 | can take on several forms. The forms that are used in this | |
2136 | implementation are listed below. */ | |
2137 | ||
2138 | typedef enum | |
2139 | { | |
2140 | dw_val_class_addr, | |
a20612aa | 2141 | dw_val_class_offset, |
3f76745e | 2142 | dw_val_class_loc, |
63e46568 | 2143 | dw_val_class_loc_list, |
3f76745e JM |
2144 | dw_val_class_const, |
2145 | dw_val_class_unsigned_const, | |
2146 | dw_val_class_long_long, | |
2147 | dw_val_class_float, | |
2148 | dw_val_class_flag, | |
2149 | dw_val_class_die_ref, | |
2150 | dw_val_class_fde_ref, | |
2151 | dw_val_class_lbl_id, | |
8b790721 | 2152 | dw_val_class_lbl_offset, |
3f76745e | 2153 | dw_val_class_str |
a3f97cbb | 2154 | } |
3f76745e | 2155 | dw_val_class; |
a3f97cbb | 2156 | |
3f76745e | 2157 | /* Describe a double word constant value. */ |
21217bd0 | 2158 | /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */ |
3f76745e JM |
2159 | |
2160 | typedef struct dw_long_long_struct | |
a3f97cbb | 2161 | { |
3f76745e JM |
2162 | unsigned long hi; |
2163 | unsigned long low; | |
2164 | } | |
2165 | dw_long_long_const; | |
2166 | ||
2167 | /* Describe a floating point constant value. */ | |
2168 | ||
2169 | typedef struct dw_fp_struct | |
2170 | { | |
2171 | long *array; | |
2172 | unsigned length; | |
2173 | } | |
2174 | dw_float_const; | |
2175 | ||
956d6950 | 2176 | /* The dw_val_node describes an attribute's value, as it is |
3f76745e JM |
2177 | represented internally. */ |
2178 | ||
2179 | typedef struct dw_val_struct | |
2180 | { | |
2181 | dw_val_class val_class; | |
2182 | union | |
a3f97cbb | 2183 | { |
1865dbb5 | 2184 | rtx val_addr; |
a20612aa | 2185 | long unsigned val_offset; |
63e46568 | 2186 | dw_loc_list_ref val_loc_list; |
3f76745e JM |
2187 | dw_loc_descr_ref val_loc; |
2188 | long int val_int; | |
2189 | long unsigned val_unsigned; | |
2190 | dw_long_long_const val_long_long; | |
2191 | dw_float_const val_float; | |
881c6935 JM |
2192 | struct { |
2193 | dw_die_ref die; | |
2194 | int external; | |
2195 | } val_die_ref; | |
3f76745e JM |
2196 | unsigned val_fde_index; |
2197 | char *val_str; | |
2198 | char *val_lbl_id; | |
3f76745e | 2199 | unsigned char val_flag; |
a3f97cbb | 2200 | } |
3f76745e JM |
2201 | v; |
2202 | } | |
2203 | dw_val_node; | |
2204 | ||
2205 | /* Locations in memory are described using a sequence of stack machine | |
2206 | operations. */ | |
2207 | ||
2208 | typedef struct dw_loc_descr_struct | |
2209 | { | |
2210 | dw_loc_descr_ref dw_loc_next; | |
2211 | enum dwarf_location_atom dw_loc_opc; | |
2212 | dw_val_node dw_loc_oprnd1; | |
2213 | dw_val_node dw_loc_oprnd2; | |
d8041cc8 | 2214 | int dw_loc_addr; |
3f76745e JM |
2215 | } |
2216 | dw_loc_descr_node; | |
2217 | ||
63e46568 DB |
2218 | /* Location lists are ranges + location descriptions for that range, |
2219 | so you can track variables that are in different places over | |
2220 | their entire life. */ | |
2221 | typedef struct dw_loc_list_struct | |
2222 | { | |
2223 | dw_loc_list_ref dw_loc_next; | |
2224 | const char *begin; /* Label for begin address of range */ | |
2225 | const char *end; /* Label for end address of range */ | |
2226 | char *ll_symbol; /* Label for beginning of location list. Only on head of list */ | |
2227 | const char *section; /* Section this loclist is relative to */ | |
2228 | dw_loc_descr_ref expr; | |
2229 | } dw_loc_list_node; | |
2230 | ||
7d9d8943 AM |
2231 | static const char *dwarf_stack_op_name PARAMS ((unsigned)); |
2232 | static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom, | |
2233 | unsigned long, | |
2234 | unsigned long)); | |
2235 | static void add_loc_descr PARAMS ((dw_loc_descr_ref *, | |
2236 | dw_loc_descr_ref)); | |
2237 | static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref)); | |
2238 | static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref)); | |
2239 | static void output_loc_operands PARAMS ((dw_loc_descr_ref)); | |
2240 | static void output_loc_sequence PARAMS ((dw_loc_descr_ref)); | |
3f76745e | 2241 | |
7d9d8943 | 2242 | /* Convert a DWARF stack opcode into its string name. */ |
3f76745e | 2243 | |
7d9d8943 AM |
2244 | static const char * |
2245 | dwarf_stack_op_name (op) | |
2246 | register unsigned op; | |
ef76d03b | 2247 | { |
7d9d8943 AM |
2248 | switch (op) |
2249 | { | |
2250 | case DW_OP_addr: | |
2251 | return "DW_OP_addr"; | |
2252 | case DW_OP_deref: | |
2253 | return "DW_OP_deref"; | |
2254 | case DW_OP_const1u: | |
2255 | return "DW_OP_const1u"; | |
2256 | case DW_OP_const1s: | |
2257 | return "DW_OP_const1s"; | |
2258 | case DW_OP_const2u: | |
2259 | return "DW_OP_const2u"; | |
2260 | case DW_OP_const2s: | |
2261 | return "DW_OP_const2s"; | |
2262 | case DW_OP_const4u: | |
2263 | return "DW_OP_const4u"; | |
2264 | case DW_OP_const4s: | |
2265 | return "DW_OP_const4s"; | |
2266 | case DW_OP_const8u: | |
2267 | return "DW_OP_const8u"; | |
2268 | case DW_OP_const8s: | |
2269 | return "DW_OP_const8s"; | |
2270 | case DW_OP_constu: | |
2271 | return "DW_OP_constu"; | |
2272 | case DW_OP_consts: | |
2273 | return "DW_OP_consts"; | |
2274 | case DW_OP_dup: | |
2275 | return "DW_OP_dup"; | |
2276 | case DW_OP_drop: | |
2277 | return "DW_OP_drop"; | |
2278 | case DW_OP_over: | |
2279 | return "DW_OP_over"; | |
2280 | case DW_OP_pick: | |
2281 | return "DW_OP_pick"; | |
2282 | case DW_OP_swap: | |
2283 | return "DW_OP_swap"; | |
2284 | case DW_OP_rot: | |
2285 | return "DW_OP_rot"; | |
2286 | case DW_OP_xderef: | |
2287 | return "DW_OP_xderef"; | |
2288 | case DW_OP_abs: | |
2289 | return "DW_OP_abs"; | |
2290 | case DW_OP_and: | |
2291 | return "DW_OP_and"; | |
2292 | case DW_OP_div: | |
2293 | return "DW_OP_div"; | |
2294 | case DW_OP_minus: | |
2295 | return "DW_OP_minus"; | |
2296 | case DW_OP_mod: | |
2297 | return "DW_OP_mod"; | |
2298 | case DW_OP_mul: | |
2299 | return "DW_OP_mul"; | |
2300 | case DW_OP_neg: | |
2301 | return "DW_OP_neg"; | |
2302 | case DW_OP_not: | |
2303 | return "DW_OP_not"; | |
2304 | case DW_OP_or: | |
2305 | return "DW_OP_or"; | |
2306 | case DW_OP_plus: | |
2307 | return "DW_OP_plus"; | |
2308 | case DW_OP_plus_uconst: | |
2309 | return "DW_OP_plus_uconst"; | |
2310 | case DW_OP_shl: | |
2311 | return "DW_OP_shl"; | |
2312 | case DW_OP_shr: | |
2313 | return "DW_OP_shr"; | |
2314 | case DW_OP_shra: | |
2315 | return "DW_OP_shra"; | |
2316 | case DW_OP_xor: | |
2317 | return "DW_OP_xor"; | |
2318 | case DW_OP_bra: | |
2319 | return "DW_OP_bra"; | |
2320 | case DW_OP_eq: | |
2321 | return "DW_OP_eq"; | |
2322 | case DW_OP_ge: | |
2323 | return "DW_OP_ge"; | |
2324 | case DW_OP_gt: | |
2325 | return "DW_OP_gt"; | |
2326 | case DW_OP_le: | |
2327 | return "DW_OP_le"; | |
2328 | case DW_OP_lt: | |
2329 | return "DW_OP_lt"; | |
2330 | case DW_OP_ne: | |
2331 | return "DW_OP_ne"; | |
2332 | case DW_OP_skip: | |
2333 | return "DW_OP_skip"; | |
2334 | case DW_OP_lit0: | |
2335 | return "DW_OP_lit0"; | |
2336 | case DW_OP_lit1: | |
2337 | return "DW_OP_lit1"; | |
2338 | case DW_OP_lit2: | |
2339 | return "DW_OP_lit2"; | |
2340 | case DW_OP_lit3: | |
2341 | return "DW_OP_lit3"; | |
2342 | case DW_OP_lit4: | |
2343 | return "DW_OP_lit4"; | |
2344 | case DW_OP_lit5: | |
2345 | return "DW_OP_lit5"; | |
2346 | case DW_OP_lit6: | |
2347 | return "DW_OP_lit6"; | |
2348 | case DW_OP_lit7: | |
2349 | return "DW_OP_lit7"; | |
2350 | case DW_OP_lit8: | |
2351 | return "DW_OP_lit8"; | |
2352 | case DW_OP_lit9: | |
2353 | return "DW_OP_lit9"; | |
2354 | case DW_OP_lit10: | |
2355 | return "DW_OP_lit10"; | |
2356 | case DW_OP_lit11: | |
2357 | return "DW_OP_lit11"; | |
2358 | case DW_OP_lit12: | |
2359 | return "DW_OP_lit12"; | |
2360 | case DW_OP_lit13: | |
2361 | return "DW_OP_lit13"; | |
2362 | case DW_OP_lit14: | |
2363 | return "DW_OP_lit14"; | |
2364 | case DW_OP_lit15: | |
2365 | return "DW_OP_lit15"; | |
2366 | case DW_OP_lit16: | |
2367 | return "DW_OP_lit16"; | |
2368 | case DW_OP_lit17: | |
2369 | return "DW_OP_lit17"; | |
2370 | case DW_OP_lit18: | |
2371 | return "DW_OP_lit18"; | |
2372 | case DW_OP_lit19: | |
2373 | return "DW_OP_lit19"; | |
2374 | case DW_OP_lit20: | |
2375 | return "DW_OP_lit20"; | |
2376 | case DW_OP_lit21: | |
2377 | return "DW_OP_lit21"; | |
2378 | case DW_OP_lit22: | |
2379 | return "DW_OP_lit22"; | |
2380 | case DW_OP_lit23: | |
2381 | return "DW_OP_lit23"; | |
2382 | case DW_OP_lit24: | |
2383 | return "DW_OP_lit24"; | |
2384 | case DW_OP_lit25: | |
2385 | return "DW_OP_lit25"; | |
2386 | case DW_OP_lit26: | |
2387 | return "DW_OP_lit26"; | |
2388 | case DW_OP_lit27: | |
2389 | return "DW_OP_lit27"; | |
2390 | case DW_OP_lit28: | |
2391 | return "DW_OP_lit28"; | |
2392 | case DW_OP_lit29: | |
2393 | return "DW_OP_lit29"; | |
2394 | case DW_OP_lit30: | |
2395 | return "DW_OP_lit30"; | |
2396 | case DW_OP_lit31: | |
2397 | return "DW_OP_lit31"; | |
2398 | case DW_OP_reg0: | |
2399 | return "DW_OP_reg0"; | |
2400 | case DW_OP_reg1: | |
2401 | return "DW_OP_reg1"; | |
2402 | case DW_OP_reg2: | |
2403 | return "DW_OP_reg2"; | |
2404 | case DW_OP_reg3: | |
2405 | return "DW_OP_reg3"; | |
2406 | case DW_OP_reg4: | |
2407 | return "DW_OP_reg4"; | |
2408 | case DW_OP_reg5: | |
2409 | return "DW_OP_reg5"; | |
2410 | case DW_OP_reg6: | |
2411 | return "DW_OP_reg6"; | |
2412 | case DW_OP_reg7: | |
2413 | return "DW_OP_reg7"; | |
2414 | case DW_OP_reg8: | |
2415 | return "DW_OP_reg8"; | |
2416 | case DW_OP_reg9: | |
2417 | return "DW_OP_reg9"; | |
2418 | case DW_OP_reg10: | |
2419 | return "DW_OP_reg10"; | |
2420 | case DW_OP_reg11: | |
2421 | return "DW_OP_reg11"; | |
2422 | case DW_OP_reg12: | |
2423 | return "DW_OP_reg12"; | |
2424 | case DW_OP_reg13: | |
2425 | return "DW_OP_reg13"; | |
2426 | case DW_OP_reg14: | |
2427 | return "DW_OP_reg14"; | |
2428 | case DW_OP_reg15: | |
2429 | return "DW_OP_reg15"; | |
2430 | case DW_OP_reg16: | |
2431 | return "DW_OP_reg16"; | |
2432 | case DW_OP_reg17: | |
2433 | return "DW_OP_reg17"; | |
2434 | case DW_OP_reg18: | |
2435 | return "DW_OP_reg18"; | |
2436 | case DW_OP_reg19: | |
2437 | return "DW_OP_reg19"; | |
2438 | case DW_OP_reg20: | |
2439 | return "DW_OP_reg20"; | |
2440 | case DW_OP_reg21: | |
2441 | return "DW_OP_reg21"; | |
2442 | case DW_OP_reg22: | |
2443 | return "DW_OP_reg22"; | |
2444 | case DW_OP_reg23: | |
2445 | return "DW_OP_reg23"; | |
2446 | case DW_OP_reg24: | |
2447 | return "DW_OP_reg24"; | |
2448 | case DW_OP_reg25: | |
2449 | return "DW_OP_reg25"; | |
2450 | case DW_OP_reg26: | |
2451 | return "DW_OP_reg26"; | |
2452 | case DW_OP_reg27: | |
2453 | return "DW_OP_reg27"; | |
2454 | case DW_OP_reg28: | |
2455 | return "DW_OP_reg28"; | |
2456 | case DW_OP_reg29: | |
2457 | return "DW_OP_reg29"; | |
2458 | case DW_OP_reg30: | |
2459 | return "DW_OP_reg30"; | |
2460 | case DW_OP_reg31: | |
2461 | return "DW_OP_reg31"; | |
2462 | case DW_OP_breg0: | |
2463 | return "DW_OP_breg0"; | |
2464 | case DW_OP_breg1: | |
2465 | return "DW_OP_breg1"; | |
2466 | case DW_OP_breg2: | |
2467 | return "DW_OP_breg2"; | |
2468 | case DW_OP_breg3: | |
2469 | return "DW_OP_breg3"; | |
2470 | case DW_OP_breg4: | |
2471 | return "DW_OP_breg4"; | |
2472 | case DW_OP_breg5: | |
2473 | return "DW_OP_breg5"; | |
2474 | case DW_OP_breg6: | |
2475 | return "DW_OP_breg6"; | |
2476 | case DW_OP_breg7: | |
2477 | return "DW_OP_breg7"; | |
2478 | case DW_OP_breg8: | |
2479 | return "DW_OP_breg8"; | |
2480 | case DW_OP_breg9: | |
2481 | return "DW_OP_breg9"; | |
2482 | case DW_OP_breg10: | |
2483 | return "DW_OP_breg10"; | |
2484 | case DW_OP_breg11: | |
2485 | return "DW_OP_breg11"; | |
2486 | case DW_OP_breg12: | |
2487 | return "DW_OP_breg12"; | |
2488 | case DW_OP_breg13: | |
2489 | return "DW_OP_breg13"; | |
2490 | case DW_OP_breg14: | |
2491 | return "DW_OP_breg14"; | |
2492 | case DW_OP_breg15: | |
2493 | return "DW_OP_breg15"; | |
2494 | case DW_OP_breg16: | |
2495 | return "DW_OP_breg16"; | |
2496 | case DW_OP_breg17: | |
2497 | return "DW_OP_breg17"; | |
2498 | case DW_OP_breg18: | |
2499 | return "DW_OP_breg18"; | |
2500 | case DW_OP_breg19: | |
2501 | return "DW_OP_breg19"; | |
2502 | case DW_OP_breg20: | |
2503 | return "DW_OP_breg20"; | |
2504 | case DW_OP_breg21: | |
2505 | return "DW_OP_breg21"; | |
2506 | case DW_OP_breg22: | |
2507 | return "DW_OP_breg22"; | |
2508 | case DW_OP_breg23: | |
2509 | return "DW_OP_breg23"; | |
2510 | case DW_OP_breg24: | |
2511 | return "DW_OP_breg24"; | |
2512 | case DW_OP_breg25: | |
2513 | return "DW_OP_breg25"; | |
2514 | case DW_OP_breg26: | |
2515 | return "DW_OP_breg26"; | |
2516 | case DW_OP_breg27: | |
2517 | return "DW_OP_breg27"; | |
2518 | case DW_OP_breg28: | |
2519 | return "DW_OP_breg28"; | |
2520 | case DW_OP_breg29: | |
2521 | return "DW_OP_breg29"; | |
2522 | case DW_OP_breg30: | |
2523 | return "DW_OP_breg30"; | |
2524 | case DW_OP_breg31: | |
2525 | return "DW_OP_breg31"; | |
2526 | case DW_OP_regx: | |
2527 | return "DW_OP_regx"; | |
2528 | case DW_OP_fbreg: | |
2529 | return "DW_OP_fbreg"; | |
2530 | case DW_OP_bregx: | |
2531 | return "DW_OP_bregx"; | |
2532 | case DW_OP_piece: | |
2533 | return "DW_OP_piece"; | |
2534 | case DW_OP_deref_size: | |
2535 | return "DW_OP_deref_size"; | |
2536 | case DW_OP_xderef_size: | |
2537 | return "DW_OP_xderef_size"; | |
2538 | case DW_OP_nop: | |
2539 | return "DW_OP_nop"; | |
3f76745e | 2540 | default: |
7d9d8943 | 2541 | return "OP_<unknown>"; |
3f76745e | 2542 | } |
bdb669cb | 2543 | } |
a3f97cbb | 2544 | |
7d9d8943 AM |
2545 | /* Return a pointer to a newly allocated location description. Location |
2546 | descriptions are simple expression terms that can be strung | |
2547 | together to form more complicated location (address) descriptions. */ | |
2548 | ||
2549 | static inline dw_loc_descr_ref | |
2550 | new_loc_descr (op, oprnd1, oprnd2) | |
2551 | register enum dwarf_location_atom op; | |
2552 | register unsigned long oprnd1; | |
2553 | register unsigned long oprnd2; | |
4b674448 | 2554 | { |
5de0e8d4 JM |
2555 | /* Use xcalloc here so we clear out all of the long_long constant in |
2556 | the union. */ | |
7d9d8943 | 2557 | register dw_loc_descr_ref descr |
5de0e8d4 | 2558 | = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node)); |
71dfc51f | 2559 | |
7d9d8943 AM |
2560 | descr->dw_loc_opc = op; |
2561 | descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const; | |
2562 | descr->dw_loc_oprnd1.v.val_unsigned = oprnd1; | |
2563 | descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const; | |
2564 | descr->dw_loc_oprnd2.v.val_unsigned = oprnd2; | |
71dfc51f | 2565 | |
7d9d8943 AM |
2566 | return descr; |
2567 | } | |
2568 | ||
63e46568 | 2569 | |
7d9d8943 AM |
2570 | /* Add a location description term to a location description expression. */ |
2571 | ||
2572 | static inline void | |
2573 | add_loc_descr (list_head, descr) | |
2574 | register dw_loc_descr_ref *list_head; | |
2575 | register dw_loc_descr_ref descr; | |
2576 | { | |
2577 | register dw_loc_descr_ref *d; | |
2578 | ||
2579 | /* Find the end of the chain. */ | |
2580 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
2581 | ; | |
2582 | ||
2583 | *d = descr; | |
2584 | } | |
2585 | ||
2586 | /* Return the size of a location descriptor. */ | |
2587 | ||
2588 | static unsigned long | |
2589 | size_of_loc_descr (loc) | |
2590 | register dw_loc_descr_ref loc; | |
2591 | { | |
2592 | register unsigned long size = 1; | |
2593 | ||
2594 | switch (loc->dw_loc_opc) | |
2595 | { | |
2596 | case DW_OP_addr: | |
2597 | size += DWARF2_ADDR_SIZE; | |
2598 | break; | |
2599 | case DW_OP_const1u: | |
2600 | case DW_OP_const1s: | |
2601 | size += 1; | |
2602 | break; | |
2603 | case DW_OP_const2u: | |
2604 | case DW_OP_const2s: | |
2605 | size += 2; | |
2606 | break; | |
2607 | case DW_OP_const4u: | |
2608 | case DW_OP_const4s: | |
2609 | size += 4; | |
2610 | break; | |
2611 | case DW_OP_const8u: | |
2612 | case DW_OP_const8s: | |
2613 | size += 8; | |
2614 | break; | |
2615 | case DW_OP_constu: | |
2616 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2617 | break; | |
2618 | case DW_OP_consts: | |
2619 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2620 | break; | |
2621 | case DW_OP_pick: | |
2622 | size += 1; | |
2623 | break; | |
2624 | case DW_OP_plus_uconst: | |
2625 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2626 | break; | |
2627 | case DW_OP_skip: | |
2628 | case DW_OP_bra: | |
2629 | size += 2; | |
2630 | break; | |
2631 | case DW_OP_breg0: | |
2632 | case DW_OP_breg1: | |
2633 | case DW_OP_breg2: | |
2634 | case DW_OP_breg3: | |
2635 | case DW_OP_breg4: | |
2636 | case DW_OP_breg5: | |
2637 | case DW_OP_breg6: | |
2638 | case DW_OP_breg7: | |
2639 | case DW_OP_breg8: | |
2640 | case DW_OP_breg9: | |
2641 | case DW_OP_breg10: | |
2642 | case DW_OP_breg11: | |
2643 | case DW_OP_breg12: | |
2644 | case DW_OP_breg13: | |
2645 | case DW_OP_breg14: | |
2646 | case DW_OP_breg15: | |
2647 | case DW_OP_breg16: | |
2648 | case DW_OP_breg17: | |
2649 | case DW_OP_breg18: | |
2650 | case DW_OP_breg19: | |
2651 | case DW_OP_breg20: | |
2652 | case DW_OP_breg21: | |
2653 | case DW_OP_breg22: | |
2654 | case DW_OP_breg23: | |
2655 | case DW_OP_breg24: | |
2656 | case DW_OP_breg25: | |
2657 | case DW_OP_breg26: | |
2658 | case DW_OP_breg27: | |
2659 | case DW_OP_breg28: | |
2660 | case DW_OP_breg29: | |
2661 | case DW_OP_breg30: | |
2662 | case DW_OP_breg31: | |
2663 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2664 | break; | |
2665 | case DW_OP_regx: | |
2666 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2667 | break; | |
2668 | case DW_OP_fbreg: | |
2669 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2670 | break; | |
2671 | case DW_OP_bregx: | |
2672 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2673 | size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int); | |
2674 | break; | |
2675 | case DW_OP_piece: | |
2676 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2677 | break; | |
2678 | case DW_OP_deref_size: | |
2679 | case DW_OP_xderef_size: | |
2680 | size += 1; | |
2681 | break; | |
3f76745e | 2682 | default: |
7d9d8943 | 2683 | break; |
4b674448 | 2684 | } |
7d9d8943 AM |
2685 | |
2686 | return size; | |
4b674448 JM |
2687 | } |
2688 | ||
7d9d8943 | 2689 | /* Return the size of a series of location descriptors. */ |
71dfc51f | 2690 | |
7d9d8943 AM |
2691 | static unsigned long |
2692 | size_of_locs (loc) | |
2693 | register dw_loc_descr_ref loc; | |
4b674448 | 2694 | { |
7d9d8943 AM |
2695 | register unsigned long size = 0; |
2696 | ||
2697 | for (; loc != NULL; loc = loc->dw_loc_next) | |
d8041cc8 RH |
2698 | { |
2699 | loc->dw_loc_addr = size; | |
2700 | size += size_of_loc_descr (loc); | |
2701 | } | |
7d9d8943 AM |
2702 | |
2703 | return size; | |
4b674448 JM |
2704 | } |
2705 | ||
7d9d8943 | 2706 | /* Output location description stack opcode's operands (if any). */ |
71dfc51f | 2707 | |
7d9d8943 AM |
2708 | static void |
2709 | output_loc_operands (loc) | |
2710 | register dw_loc_descr_ref loc; | |
a3f97cbb | 2711 | { |
7d9d8943 AM |
2712 | register dw_val_ref val1 = &loc->dw_loc_oprnd1; |
2713 | register dw_val_ref val2 = &loc->dw_loc_oprnd2; | |
2714 | ||
2715 | switch (loc->dw_loc_opc) | |
a3f97cbb | 2716 | { |
0517872a | 2717 | #ifdef DWARF2_DEBUGGING_INFO |
3f76745e | 2718 | case DW_OP_addr: |
2e4b9b8c | 2719 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL); |
7d9d8943 | 2720 | break; |
3f76745e | 2721 | case DW_OP_const2u: |
3f76745e | 2722 | case DW_OP_const2s: |
2e4b9b8c | 2723 | dw2_asm_output_data (2, val1->v.val_int, NULL); |
7d9d8943 | 2724 | break; |
3f76745e | 2725 | case DW_OP_const4u: |
3f76745e | 2726 | case DW_OP_const4s: |
2e4b9b8c | 2727 | dw2_asm_output_data (4, val1->v.val_int, NULL); |
7d9d8943 | 2728 | break; |
3f76745e | 2729 | case DW_OP_const8u: |
3f76745e | 2730 | case DW_OP_const8s: |
2e4b9b8c RH |
2731 | if (HOST_BITS_PER_LONG < 64) |
2732 | abort (); | |
2733 | dw2_asm_output_data (8, val1->v.val_int, NULL); | |
7d9d8943 | 2734 | break; |
0517872a JM |
2735 | case DW_OP_skip: |
2736 | case DW_OP_bra: | |
d8041cc8 RH |
2737 | { |
2738 | int offset; | |
2739 | ||
2740 | if (val1->val_class == dw_val_class_loc) | |
2741 | offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3); | |
2742 | else | |
2743 | abort (); | |
2744 | ||
2e4b9b8c | 2745 | dw2_asm_output_data (2, offset, NULL); |
d8041cc8 | 2746 | } |
0517872a | 2747 | break; |
3139472f JM |
2748 | #else |
2749 | case DW_OP_addr: | |
2750 | case DW_OP_const2u: | |
2751 | case DW_OP_const2s: | |
2752 | case DW_OP_const4u: | |
2753 | case DW_OP_const4s: | |
2754 | case DW_OP_const8u: | |
2755 | case DW_OP_const8s: | |
2756 | case DW_OP_skip: | |
2757 | case DW_OP_bra: | |
2758 | /* We currently don't make any attempt to make sure these are | |
2759 | aligned properly like we do for the main unwind info, so | |
2760 | don't support emitting things larger than a byte if we're | |
2761 | only doing unwinding. */ | |
2762 | abort (); | |
0517872a JM |
2763 | #endif |
2764 | case DW_OP_const1u: | |
2765 | case DW_OP_const1s: | |
2e4b9b8c | 2766 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
0517872a | 2767 | break; |
3f76745e | 2768 | case DW_OP_constu: |
2e4b9b8c | 2769 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2770 | break; |
3f76745e | 2771 | case DW_OP_consts: |
2e4b9b8c | 2772 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 AM |
2773 | break; |
2774 | case DW_OP_pick: | |
2e4b9b8c | 2775 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 AM |
2776 | break; |
2777 | case DW_OP_plus_uconst: | |
2e4b9b8c | 2778 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2779 | break; |
3f76745e | 2780 | case DW_OP_breg0: |
3f76745e | 2781 | case DW_OP_breg1: |
3f76745e | 2782 | case DW_OP_breg2: |
3f76745e | 2783 | case DW_OP_breg3: |
3f76745e | 2784 | case DW_OP_breg4: |
3f76745e | 2785 | case DW_OP_breg5: |
3f76745e | 2786 | case DW_OP_breg6: |
3f76745e | 2787 | case DW_OP_breg7: |
3f76745e | 2788 | case DW_OP_breg8: |
3f76745e | 2789 | case DW_OP_breg9: |
3f76745e | 2790 | case DW_OP_breg10: |
3f76745e | 2791 | case DW_OP_breg11: |
3f76745e | 2792 | case DW_OP_breg12: |
3f76745e | 2793 | case DW_OP_breg13: |
3f76745e | 2794 | case DW_OP_breg14: |
3f76745e | 2795 | case DW_OP_breg15: |
3f76745e | 2796 | case DW_OP_breg16: |
3f76745e | 2797 | case DW_OP_breg17: |
3f76745e | 2798 | case DW_OP_breg18: |
3f76745e | 2799 | case DW_OP_breg19: |
3f76745e | 2800 | case DW_OP_breg20: |
3f76745e | 2801 | case DW_OP_breg21: |
3f76745e | 2802 | case DW_OP_breg22: |
3f76745e | 2803 | case DW_OP_breg23: |
3f76745e | 2804 | case DW_OP_breg24: |
3f76745e | 2805 | case DW_OP_breg25: |
3f76745e | 2806 | case DW_OP_breg26: |
3f76745e | 2807 | case DW_OP_breg27: |
3f76745e | 2808 | case DW_OP_breg28: |
3f76745e | 2809 | case DW_OP_breg29: |
3f76745e | 2810 | case DW_OP_breg30: |
3f76745e | 2811 | case DW_OP_breg31: |
2e4b9b8c | 2812 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 2813 | break; |
3f76745e | 2814 | case DW_OP_regx: |
2e4b9b8c | 2815 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2816 | break; |
3f76745e | 2817 | case DW_OP_fbreg: |
2e4b9b8c | 2818 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 2819 | break; |
3f76745e | 2820 | case DW_OP_bregx: |
2e4b9b8c RH |
2821 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
2822 | dw2_asm_output_data_sleb128 (val2->v.val_int, NULL); | |
7d9d8943 | 2823 | break; |
3f76745e | 2824 | case DW_OP_piece: |
2e4b9b8c | 2825 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2826 | break; |
3f76745e | 2827 | case DW_OP_deref_size: |
3f76745e | 2828 | case DW_OP_xderef_size: |
2e4b9b8c | 2829 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 AM |
2830 | break; |
2831 | default: | |
3139472f JM |
2832 | /* Other codes have no operands. */ |
2833 | break; | |
7d9d8943 AM |
2834 | } |
2835 | } | |
2836 | ||
2837 | /* Output a sequence of location operations. */ | |
2838 | ||
2839 | static void | |
2840 | output_loc_sequence (loc) | |
2841 | dw_loc_descr_ref loc; | |
2842 | { | |
2843 | for (; loc != NULL; loc = loc->dw_loc_next) | |
2844 | { | |
2845 | /* Output the opcode. */ | |
2e4b9b8c RH |
2846 | dw2_asm_output_data (1, loc->dw_loc_opc, |
2847 | "%s", dwarf_stack_op_name (loc->dw_loc_opc)); | |
7d9d8943 AM |
2848 | |
2849 | /* Output the operand(s) (if any). */ | |
2850 | output_loc_operands (loc); | |
2851 | } | |
2852 | } | |
2853 | ||
2854 | /* This routine will generate the correct assembly data for a location | |
2855 | description based on a cfi entry with a complex address. */ | |
2856 | ||
2857 | static void | |
2858 | output_cfa_loc (cfi) | |
2859 | dw_cfi_ref cfi; | |
2860 | { | |
2861 | dw_loc_descr_ref loc; | |
2862 | unsigned long size; | |
2863 | ||
2864 | /* Output the size of the block. */ | |
2865 | loc = cfi->dw_cfi_oprnd1.dw_cfi_loc; | |
2866 | size = size_of_locs (loc); | |
2e4b9b8c | 2867 | dw2_asm_output_data_uleb128 (size, NULL); |
7d9d8943 AM |
2868 | |
2869 | /* Now output the operations themselves. */ | |
2870 | output_loc_sequence (loc); | |
2871 | } | |
2872 | ||
556273e0 KH |
2873 | /* This function builds a dwarf location descriptor seqeunce from |
2874 | a dw_cfa_location. */ | |
7d9d8943 AM |
2875 | |
2876 | static struct dw_loc_descr_struct * | |
2877 | build_cfa_loc (cfa) | |
2878 | dw_cfa_location *cfa; | |
2879 | { | |
2880 | struct dw_loc_descr_struct *head, *tmp; | |
2881 | ||
2882 | if (cfa->indirect == 0) | |
2883 | abort (); | |
2884 | ||
2885 | if (cfa->base_offset) | |
f299afab HPN |
2886 | { |
2887 | if (cfa->reg <= 31) | |
2888 | head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0); | |
2889 | else | |
2890 | head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset); | |
2891 | } | |
2892 | else if (cfa->reg <= 31) | |
7d9d8943 | 2893 | head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0); |
f299afab HPN |
2894 | else |
2895 | head = new_loc_descr (DW_OP_regx, cfa->reg, 0); | |
7d9d8943 AM |
2896 | head->dw_loc_oprnd1.val_class = dw_val_class_const; |
2897 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
2898 | add_loc_descr (&head, tmp); | |
2899 | if (cfa->offset != 0) | |
2900 | { | |
2901 | tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0); | |
2902 | add_loc_descr (&head, tmp); | |
2903 | } | |
2904 | return head; | |
2905 | } | |
2906 | ||
556273e0 | 2907 | /* This function fills in aa dw_cfa_location structure from a |
7d9d8943 AM |
2908 | dwarf location descriptor sequence. */ |
2909 | ||
2910 | static void | |
2911 | get_cfa_from_loc_descr (cfa, loc) | |
2912 | dw_cfa_location *cfa; | |
556273e0 | 2913 | struct dw_loc_descr_struct *loc; |
7d9d8943 | 2914 | { |
556273e0 | 2915 | struct dw_loc_descr_struct *ptr; |
7d9d8943 AM |
2916 | cfa->offset = 0; |
2917 | cfa->base_offset = 0; | |
2918 | cfa->indirect = 0; | |
2919 | cfa->reg = -1; | |
2920 | ||
2921 | for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next) | |
2922 | { | |
2923 | enum dwarf_location_atom op = ptr->dw_loc_opc; | |
2924 | switch (op) | |
556273e0 | 2925 | { |
7d9d8943 AM |
2926 | case DW_OP_reg0: |
2927 | case DW_OP_reg1: | |
2928 | case DW_OP_reg2: | |
2929 | case DW_OP_reg3: | |
2930 | case DW_OP_reg4: | |
2931 | case DW_OP_reg5: | |
2932 | case DW_OP_reg6: | |
2933 | case DW_OP_reg7: | |
2934 | case DW_OP_reg8: | |
2935 | case DW_OP_reg9: | |
2936 | case DW_OP_reg10: | |
2937 | case DW_OP_reg11: | |
2938 | case DW_OP_reg12: | |
2939 | case DW_OP_reg13: | |
2940 | case DW_OP_reg14: | |
2941 | case DW_OP_reg15: | |
2942 | case DW_OP_reg16: | |
2943 | case DW_OP_reg17: | |
2944 | case DW_OP_reg18: | |
2945 | case DW_OP_reg19: | |
2946 | case DW_OP_reg20: | |
2947 | case DW_OP_reg21: | |
2948 | case DW_OP_reg22: | |
2949 | case DW_OP_reg23: | |
2950 | case DW_OP_reg24: | |
2951 | case DW_OP_reg25: | |
2952 | case DW_OP_reg26: | |
2953 | case DW_OP_reg27: | |
2954 | case DW_OP_reg28: | |
2955 | case DW_OP_reg29: | |
2956 | case DW_OP_reg30: | |
2957 | case DW_OP_reg31: | |
2958 | cfa->reg = op - DW_OP_reg0; | |
2959 | break; | |
2960 | case DW_OP_regx: | |
2961 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
2962 | break; | |
2963 | case DW_OP_breg0: | |
2964 | case DW_OP_breg1: | |
2965 | case DW_OP_breg2: | |
2966 | case DW_OP_breg3: | |
2967 | case DW_OP_breg4: | |
2968 | case DW_OP_breg5: | |
2969 | case DW_OP_breg6: | |
2970 | case DW_OP_breg7: | |
2971 | case DW_OP_breg8: | |
2972 | case DW_OP_breg9: | |
2973 | case DW_OP_breg10: | |
2974 | case DW_OP_breg11: | |
2975 | case DW_OP_breg12: | |
2976 | case DW_OP_breg13: | |
2977 | case DW_OP_breg14: | |
2978 | case DW_OP_breg15: | |
2979 | case DW_OP_breg16: | |
2980 | case DW_OP_breg17: | |
2981 | case DW_OP_breg18: | |
2982 | case DW_OP_breg19: | |
2983 | case DW_OP_breg20: | |
2984 | case DW_OP_breg21: | |
2985 | case DW_OP_breg22: | |
2986 | case DW_OP_breg23: | |
2987 | case DW_OP_breg24: | |
2988 | case DW_OP_breg25: | |
2989 | case DW_OP_breg26: | |
2990 | case DW_OP_breg27: | |
2991 | case DW_OP_breg28: | |
2992 | case DW_OP_breg29: | |
2993 | case DW_OP_breg30: | |
2994 | case DW_OP_breg31: | |
2995 | cfa->reg = op - DW_OP_breg0; | |
2996 | cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int; | |
2997 | break; | |
2998 | case DW_OP_bregx: | |
2999 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
3000 | cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int; | |
3001 | break; | |
3002 | case DW_OP_deref: | |
3003 | cfa->indirect = 1; | |
3004 | break; | |
3005 | case DW_OP_plus_uconst: | |
556273e0 | 3006 | cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned; |
7d9d8943 AM |
3007 | break; |
3008 | default: | |
400500c4 RK |
3009 | internal_error ("DW_LOC_OP %s not implememnted\n", |
3010 | dwarf_stack_op_name (ptr->dw_loc_opc)); | |
7d9d8943 AM |
3011 | } |
3012 | } | |
3013 | } | |
3014 | #endif /* .debug_frame support */ | |
3015 | \f | |
3016 | /* And now, the support for symbolic debugging information. */ | |
3017 | #ifdef DWARF2_DEBUGGING_INFO | |
3018 | ||
e2a12aca NB |
3019 | static void dwarf2out_init PARAMS ((const char *)); |
3020 | static void dwarf2out_finish PARAMS ((const char *)); | |
7f905405 NB |
3021 | static void dwarf2out_define PARAMS ((unsigned int, const char *)); |
3022 | static void dwarf2out_undef PARAMS ((unsigned int, const char *)); | |
3023 | static void dwarf2out_start_source_file PARAMS ((unsigned, const char *)); | |
3024 | static void dwarf2out_end_source_file PARAMS ((unsigned)); | |
e2a12aca NB |
3025 | static void dwarf2out_begin_block PARAMS ((unsigned, unsigned)); |
3026 | static void dwarf2out_end_block PARAMS ((unsigned, unsigned)); | |
e1772ac0 | 3027 | static bool dwarf2out_ignore_block PARAMS ((tree)); |
2b85879e | 3028 | static void dwarf2out_global_decl PARAMS ((tree)); |
e1772ac0 | 3029 | static void dwarf2out_abstract_function PARAMS ((tree)); |
7f905405 NB |
3030 | |
3031 | /* The debug hooks structure. */ | |
3032 | ||
3033 | struct gcc_debug_hooks dwarf2_debug_hooks = | |
3034 | { | |
3035 | dwarf2out_init, | |
3036 | dwarf2out_finish, | |
3037 | dwarf2out_define, | |
3038 | dwarf2out_undef, | |
3039 | dwarf2out_start_source_file, | |
a5a42b92 NB |
3040 | dwarf2out_end_source_file, |
3041 | dwarf2out_begin_block, | |
e2a12aca | 3042 | dwarf2out_end_block, |
e1772ac0 | 3043 | dwarf2out_ignore_block, |
e2a12aca | 3044 | dwarf2out_source_line, |
653e276c NB |
3045 | dwarf2out_begin_prologue, |
3046 | debug_nothing_int, /* end_prologue */ | |
e2a12aca | 3047 | dwarf2out_end_epilogue, |
653e276c | 3048 | debug_nothing_tree, /* begin_function */ |
2b85879e NB |
3049 | debug_nothing_int, /* end_function */ |
3050 | dwarf2out_decl, /* function_decl */ | |
3051 | dwarf2out_global_decl, | |
e1772ac0 NB |
3052 | debug_nothing_tree, /* deferred_inline_function */ |
3053 | /* The DWARF 2 backend tries to reduce debugging bloat by not | |
3054 | emitting the abstract description of inline functions until | |
3055 | something tries to reference them. */ | |
3056 | dwarf2out_abstract_function, /* outlining_inline_function */ | |
3057 | debug_nothing_rtx /* label */ | |
7f905405 NB |
3058 | }; |
3059 | \f | |
7d9d8943 AM |
3060 | /* NOTE: In the comments in this file, many references are made to |
3061 | "Debugging Information Entries". This term is abbreviated as `DIE' | |
3062 | throughout the remainder of this file. */ | |
3063 | ||
3064 | /* An internal representation of the DWARF output is built, and then | |
3065 | walked to generate the DWARF debugging info. The walk of the internal | |
3066 | representation is done after the entire program has been compiled. | |
3067 | The types below are used to describe the internal representation. */ | |
3068 | ||
3069 | /* Various DIE's use offsets relative to the beginning of the | |
3070 | .debug_info section to refer to each other. */ | |
3071 | ||
3072 | typedef long int dw_offset; | |
3073 | ||
3074 | /* Define typedefs here to avoid circular dependencies. */ | |
3075 | ||
3076 | typedef struct dw_attr_struct *dw_attr_ref; | |
3077 | typedef struct dw_line_info_struct *dw_line_info_ref; | |
3078 | typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref; | |
3079 | typedef struct pubname_struct *pubname_ref; | |
a20612aa | 3080 | typedef struct dw_ranges_struct *dw_ranges_ref; |
7d9d8943 AM |
3081 | |
3082 | /* Each entry in the line_info_table maintains the file and | |
3083 | line number associated with the label generated for that | |
3084 | entry. The label gives the PC value associated with | |
3085 | the line number entry. */ | |
3086 | ||
3087 | typedef struct dw_line_info_struct | |
3088 | { | |
3089 | unsigned long dw_file_num; | |
3090 | unsigned long dw_line_num; | |
3091 | } | |
3092 | dw_line_info_entry; | |
3093 | ||
3094 | /* Line information for functions in separate sections; each one gets its | |
3095 | own sequence. */ | |
3096 | typedef struct dw_separate_line_info_struct | |
3097 | { | |
3098 | unsigned long dw_file_num; | |
3099 | unsigned long dw_line_num; | |
3100 | unsigned long function; | |
3101 | } | |
3102 | dw_separate_line_info_entry; | |
3103 | ||
3104 | /* Each DIE attribute has a field specifying the attribute kind, | |
3105 | a link to the next attribute in the chain, and an attribute value. | |
3106 | Attributes are typically linked below the DIE they modify. */ | |
3107 | ||
3108 | typedef struct dw_attr_struct | |
3109 | { | |
3110 | enum dwarf_attribute dw_attr; | |
3111 | dw_attr_ref dw_attr_next; | |
3112 | dw_val_node dw_attr_val; | |
3113 | } | |
3114 | dw_attr_node; | |
3115 | ||
3116 | /* The Debugging Information Entry (DIE) structure */ | |
3117 | ||
3118 | typedef struct die_struct | |
3119 | { | |
3120 | enum dwarf_tag die_tag; | |
881c6935 | 3121 | char *die_symbol; |
7d9d8943 AM |
3122 | dw_attr_ref die_attr; |
3123 | dw_die_ref die_parent; | |
3124 | dw_die_ref die_child; | |
3125 | dw_die_ref die_sib; | |
3126 | dw_offset die_offset; | |
3127 | unsigned long die_abbrev; | |
1bfb5f8f | 3128 | int die_mark; |
7d9d8943 AM |
3129 | } |
3130 | die_node; | |
3131 | ||
3132 | /* The pubname structure */ | |
3133 | ||
3134 | typedef struct pubname_struct | |
3135 | { | |
3136 | dw_die_ref die; | |
556273e0 | 3137 | char *name; |
7d9d8943 AM |
3138 | } |
3139 | pubname_entry; | |
3140 | ||
a20612aa RH |
3141 | struct dw_ranges_struct |
3142 | { | |
3143 | int block_num; | |
3144 | }; | |
3145 | ||
7d9d8943 AM |
3146 | /* The limbo die list structure. */ |
3147 | typedef struct limbo_die_struct | |
3148 | { | |
3149 | dw_die_ref die; | |
3150 | struct limbo_die_struct *next; | |
3151 | } | |
3152 | limbo_die_node; | |
3153 | ||
3154 | /* How to start an assembler comment. */ | |
3155 | #ifndef ASM_COMMENT_START | |
3156 | #define ASM_COMMENT_START ";#" | |
3157 | #endif | |
3158 | ||
3159 | /* Define a macro which returns non-zero for a TYPE_DECL which was | |
3160 | implicitly generated for a tagged type. | |
3161 | ||
3162 | Note that unlike the gcc front end (which generates a NULL named | |
3163 | TYPE_DECL node for each complete tagged type, each array type, and | |
3164 | each function type node created) the g++ front end generates a | |
3165 | _named_ TYPE_DECL node for each tagged type node created. | |
3166 | These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to | |
3167 | generate a DW_TAG_typedef DIE for them. */ | |
3168 | ||
3169 | #define TYPE_DECL_IS_STUB(decl) \ | |
3170 | (DECL_NAME (decl) == NULL_TREE \ | |
3171 | || (DECL_ARTIFICIAL (decl) \ | |
3172 | && is_tagged_type (TREE_TYPE (decl)) \ | |
3173 | && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \ | |
3174 | /* This is necessary for stub decls that \ | |
3175 | appear in nested inline functions. */ \ | |
3176 | || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \ | |
3177 | && (decl_ultimate_origin (decl) \ | |
3178 | == TYPE_STUB_DECL (TREE_TYPE (decl))))))) | |
3179 | ||
3180 | /* Information concerning the compilation unit's programming | |
3181 | language, and compiler version. */ | |
3182 | ||
3183 | extern int flag_traditional; | |
3184 | ||
3185 | /* Fixed size portion of the DWARF compilation unit header. */ | |
3186 | #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3) | |
3187 | ||
3188 | /* Fixed size portion of debugging line information prolog. */ | |
3189 | #define DWARF_LINE_PROLOG_HEADER_SIZE 5 | |
3190 | ||
3191 | /* Fixed size portion of public names info. */ | |
3192 | #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2) | |
3193 | ||
3194 | /* Fixed size portion of the address range info. */ | |
3195 | #define DWARF_ARANGES_HEADER_SIZE \ | |
3196 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ | |
3197 | - DWARF_OFFSET_SIZE) | |
3198 | ||
3199 | /* Size of padding portion in the address range info. It must be | |
3200 | aligned to twice the pointer size. */ | |
3201 | #define DWARF_ARANGES_PAD_SIZE \ | |
3202 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ | |
3203 | - (2 * DWARF_OFFSET_SIZE + 4)) | |
3204 | ||
9d147085 | 3205 | /* Use assembler line directives if available. */ |
7d9d8943 | 3206 | #ifndef DWARF2_ASM_LINE_DEBUG_INFO |
9d147085 RH |
3207 | #ifdef HAVE_AS_DWARF2_DEBUG_LINE |
3208 | #define DWARF2_ASM_LINE_DEBUG_INFO 1 | |
3209 | #else | |
7d9d8943 AM |
3210 | #define DWARF2_ASM_LINE_DEBUG_INFO 0 |
3211 | #endif | |
9d147085 | 3212 | #endif |
7d9d8943 AM |
3213 | |
3214 | /* Define the architecture-dependent minimum instruction length (in bytes). | |
3215 | In this implementation of DWARF, this field is used for information | |
3216 | purposes only. Since GCC generates assembly language, we have | |
3217 | no a priori knowledge of how many instruction bytes are generated | |
3218 | for each source line, and therefore can use only the DW_LNE_set_address | |
3219 | and DW_LNS_fixed_advance_pc line information commands. */ | |
3220 | ||
3221 | #ifndef DWARF_LINE_MIN_INSTR_LENGTH | |
3222 | #define DWARF_LINE_MIN_INSTR_LENGTH 4 | |
3223 | #endif | |
3224 | ||
3225 | /* Minimum line offset in a special line info. opcode. | |
3226 | This value was chosen to give a reasonable range of values. */ | |
3227 | #define DWARF_LINE_BASE -10 | |
3228 | ||
3229 | /* First special line opcde - leave room for the standard opcodes. */ | |
3230 | #define DWARF_LINE_OPCODE_BASE 10 | |
3231 | ||
3232 | /* Range of line offsets in a special line info. opcode. */ | |
3233 | #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1) | |
3234 | ||
3235 | /* Flag that indicates the initial value of the is_stmt_start flag. | |
3236 | In the present implementation, we do not mark any lines as | |
3237 | the beginning of a source statement, because that information | |
3238 | is not made available by the GCC front-end. */ | |
3239 | #define DWARF_LINE_DEFAULT_IS_STMT_START 1 | |
3240 | ||
3241 | /* This location is used by calc_die_sizes() to keep track | |
3242 | the offset of each DIE within the .debug_info section. */ | |
3243 | static unsigned long next_die_offset; | |
3244 | ||
3245 | /* Record the root of the DIE's built for the current compilation unit. */ | |
3246 | static dw_die_ref comp_unit_die; | |
3247 | ||
3248 | /* A list of DIEs with a NULL parent waiting to be relocated. */ | |
3249 | static limbo_die_node *limbo_die_list = 0; | |
3250 | ||
2e18bbae RH |
3251 | /* Structure used by lookup_filename to manage sets of filenames. */ |
3252 | struct file_table | |
3253 | { | |
3254 | char **table; | |
3255 | unsigned allocated; | |
3256 | unsigned in_use; | |
3257 | unsigned last_lookup_index; | |
3258 | }; | |
7d9d8943 AM |
3259 | |
3260 | /* Size (in elements) of increments by which we may expand the filename | |
3261 | table. */ | |
3262 | #define FILE_TABLE_INCREMENT 64 | |
3263 | ||
981975b6 RH |
3264 | /* Filenames referenced by this compilation unit. */ |
3265 | static struct file_table file_table; | |
2e18bbae | 3266 | |
7d9d8943 AM |
3267 | /* Local pointer to the name of the main input file. Initialized in |
3268 | dwarf2out_init. */ | |
3269 | static const char *primary_filename; | |
3270 | ||
3271 | /* A pointer to the base of a table of references to DIE's that describe | |
3272 | declarations. The table is indexed by DECL_UID() which is a unique | |
3273 | number identifying each decl. */ | |
3274 | static dw_die_ref *decl_die_table; | |
3275 | ||
3276 | /* Number of elements currently allocated for the decl_die_table. */ | |
3277 | static unsigned decl_die_table_allocated; | |
3278 | ||
3279 | /* Number of elements in decl_die_table currently in use. */ | |
3280 | static unsigned decl_die_table_in_use; | |
3281 | ||
3282 | /* Size (in elements) of increments by which we may expand the | |
3283 | decl_die_table. */ | |
3284 | #define DECL_DIE_TABLE_INCREMENT 256 | |
3285 | ||
3286 | /* A pointer to the base of a table of references to declaration | |
3287 | scopes. This table is a display which tracks the nesting | |
3288 | of declaration scopes at the current scope and containing | |
3289 | scopes. This table is used to find the proper place to | |
3290 | define type declaration DIE's. */ | |
3291 | static tree *decl_scope_table; | |
3292 | ||
3293 | /* Number of elements currently allocated for the decl_scope_table. */ | |
3294 | static int decl_scope_table_allocated; | |
3295 | ||
3296 | /* Current level of nesting of declaration scopes. */ | |
3297 | static int decl_scope_depth; | |
3298 | ||
3299 | /* Size (in elements) of increments by which we may expand the | |
3300 | decl_scope_table. */ | |
3301 | #define DECL_SCOPE_TABLE_INCREMENT 64 | |
3302 | ||
3303 | /* A pointer to the base of a list of references to DIE's that | |
3304 | are uniquely identified by their tag, presence/absence of | |
3305 | children DIE's, and list of attribute/value pairs. */ | |
3306 | static dw_die_ref *abbrev_die_table; | |
3307 | ||
3308 | /* Number of elements currently allocated for abbrev_die_table. */ | |
3309 | static unsigned abbrev_die_table_allocated; | |
3310 | ||
3311 | /* Number of elements in type_die_table currently in use. */ | |
3312 | static unsigned abbrev_die_table_in_use; | |
3313 | ||
3314 | /* Size (in elements) of increments by which we may expand the | |
3315 | abbrev_die_table. */ | |
3316 | #define ABBREV_DIE_TABLE_INCREMENT 256 | |
3317 | ||
3318 | /* A pointer to the base of a table that contains line information | |
3319 | for each source code line in .text in the compilation unit. */ | |
3320 | static dw_line_info_ref line_info_table; | |
3321 | ||
3322 | /* Number of elements currently allocated for line_info_table. */ | |
3323 | static unsigned line_info_table_allocated; | |
3324 | ||
3325 | /* Number of elements in separate_line_info_table currently in use. */ | |
3326 | static unsigned separate_line_info_table_in_use; | |
3327 | ||
3328 | /* A pointer to the base of a table that contains line information | |
3329 | for each source code line outside of .text in the compilation unit. */ | |
3330 | static dw_separate_line_info_ref separate_line_info_table; | |
3331 | ||
3332 | /* Number of elements currently allocated for separate_line_info_table. */ | |
3333 | static unsigned separate_line_info_table_allocated; | |
3334 | ||
3335 | /* Number of elements in line_info_table currently in use. */ | |
3336 | static unsigned line_info_table_in_use; | |
3337 | ||
3338 | /* Size (in elements) of increments by which we may expand the | |
3339 | line_info_table. */ | |
3340 | #define LINE_INFO_TABLE_INCREMENT 1024 | |
3341 | ||
3342 | /* A pointer to the base of a table that contains a list of publicly | |
3343 | accessible names. */ | |
3344 | static pubname_ref pubname_table; | |
3345 | ||
3346 | /* Number of elements currently allocated for pubname_table. */ | |
3347 | static unsigned pubname_table_allocated; | |
3348 | ||
3349 | /* Number of elements in pubname_table currently in use. */ | |
3350 | static unsigned pubname_table_in_use; | |
3351 | ||
3352 | /* Size (in elements) of increments by which we may expand the | |
3353 | pubname_table. */ | |
3354 | #define PUBNAME_TABLE_INCREMENT 64 | |
3355 | ||
a20612aa RH |
3356 | /* Array of dies for which we should generate .debug_arange info. */ |
3357 | static dw_die_ref *arange_table; | |
7d9d8943 AM |
3358 | |
3359 | /* Number of elements currently allocated for arange_table. */ | |
3360 | static unsigned arange_table_allocated; | |
3361 | ||
3362 | /* Number of elements in arange_table currently in use. */ | |
3363 | static unsigned arange_table_in_use; | |
3364 | ||
3365 | /* Size (in elements) of increments by which we may expand the | |
3366 | arange_table. */ | |
3367 | #define ARANGE_TABLE_INCREMENT 64 | |
3368 | ||
a20612aa RH |
3369 | /* Array of dies for which we should generate .debug_ranges info. */ |
3370 | static dw_ranges_ref ranges_table; | |
3371 | ||
3372 | /* Number of elements currently allocated for ranges_table. */ | |
3373 | static unsigned ranges_table_allocated; | |
3374 | ||
3375 | /* Number of elements in ranges_table currently in use. */ | |
3376 | static unsigned ranges_table_in_use; | |
3377 | ||
3378 | /* Size (in elements) of increments by which we may expand the | |
3379 | ranges_table. */ | |
3380 | #define RANGES_TABLE_INCREMENT 64 | |
3381 | ||
63e46568 DB |
3382 | /* Whether we have location lists that need outputting */ |
3383 | static unsigned have_location_lists; | |
3384 | ||
7d9d8943 AM |
3385 | /* A pointer to the base of a list of incomplete types which might be |
3386 | completed at some later time. */ | |
3387 | ||
3388 | static tree *incomplete_types_list; | |
3389 | ||
3390 | /* Number of elements currently allocated for the incomplete_types_list. */ | |
3391 | static unsigned incomplete_types_allocated; | |
3392 | ||
3393 | /* Number of elements of incomplete_types_list currently in use. */ | |
3394 | static unsigned incomplete_types; | |
3395 | ||
3396 | /* Size (in elements) of increments by which we may expand the incomplete | |
3397 | types list. Actually, a single hunk of space of this size should | |
3398 | be enough for most typical programs. */ | |
3399 | #define INCOMPLETE_TYPES_INCREMENT 64 | |
3400 | ||
3401 | /* Record whether the function being analyzed contains inlined functions. */ | |
3402 | static int current_function_has_inlines; | |
3403 | #if 0 && defined (MIPS_DEBUGGING_INFO) | |
3404 | static int comp_unit_has_inlines; | |
3405 | #endif | |
3406 | ||
3407 | /* Array of RTXes referenced by the debugging information, which therefore | |
3408 | must be kept around forever. We do this rather than perform GC on | |
3409 | the dwarf info because almost all of the dwarf info lives forever, and | |
3410 | it's easier to support non-GC frontends this way. */ | |
3411 | static varray_type used_rtx_varray; | |
3412 | ||
3413 | /* Forward declarations for functions defined in this file. */ | |
3414 | ||
3415 | static int is_pseudo_reg PARAMS ((rtx)); | |
3416 | static tree type_main_variant PARAMS ((tree)); | |
3417 | static int is_tagged_type PARAMS ((tree)); | |
3418 | static const char *dwarf_tag_name PARAMS ((unsigned)); | |
3419 | static const char *dwarf_attr_name PARAMS ((unsigned)); | |
3420 | static const char *dwarf_form_name PARAMS ((unsigned)); | |
3421 | #if 0 | |
3422 | static const char *dwarf_type_encoding_name PARAMS ((unsigned)); | |
3423 | #endif | |
3424 | static tree decl_ultimate_origin PARAMS ((tree)); | |
3425 | static tree block_ultimate_origin PARAMS ((tree)); | |
3426 | static tree decl_class_context PARAMS ((tree)); | |
3427 | static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref)); | |
3428 | static void add_AT_flag PARAMS ((dw_die_ref, | |
3429 | enum dwarf_attribute, | |
3430 | unsigned)); | |
3431 | static void add_AT_int PARAMS ((dw_die_ref, | |
3432 | enum dwarf_attribute, long)); | |
3433 | static void add_AT_unsigned PARAMS ((dw_die_ref, | |
3434 | enum dwarf_attribute, | |
3435 | unsigned long)); | |
3436 | static void add_AT_long_long PARAMS ((dw_die_ref, | |
3437 | enum dwarf_attribute, | |
3438 | unsigned long, | |
3439 | unsigned long)); | |
3440 | static void add_AT_float PARAMS ((dw_die_ref, | |
3441 | enum dwarf_attribute, | |
3442 | unsigned, long *)); | |
3443 | static void add_AT_string PARAMS ((dw_die_ref, | |
3444 | enum dwarf_attribute, | |
3445 | const char *)); | |
3446 | static void add_AT_die_ref PARAMS ((dw_die_ref, | |
3447 | enum dwarf_attribute, | |
3448 | dw_die_ref)); | |
3449 | static void add_AT_fde_ref PARAMS ((dw_die_ref, | |
3450 | enum dwarf_attribute, | |
3451 | unsigned)); | |
3452 | static void add_AT_loc PARAMS ((dw_die_ref, | |
3453 | enum dwarf_attribute, | |
3454 | dw_loc_descr_ref)); | |
63e46568 DB |
3455 | static void add_AT_loc_list PARAMS ((dw_die_ref, |
3456 | enum dwarf_attribute, | |
3457 | dw_loc_list_ref)); | |
7d9d8943 AM |
3458 | static void add_AT_addr PARAMS ((dw_die_ref, |
3459 | enum dwarf_attribute, | |
3460 | rtx)); | |
3461 | static void add_AT_lbl_id PARAMS ((dw_die_ref, | |
3462 | enum dwarf_attribute, | |
3463 | const char *)); | |
3464 | static void add_AT_lbl_offset PARAMS ((dw_die_ref, | |
3465 | enum dwarf_attribute, | |
3466 | const char *)); | |
a20612aa RH |
3467 | static void add_AT_offset PARAMS ((dw_die_ref, |
3468 | enum dwarf_attribute, | |
3469 | unsigned long)); | |
7d9d8943 AM |
3470 | static dw_attr_ref get_AT PARAMS ((dw_die_ref, |
3471 | enum dwarf_attribute)); | |
3472 | static const char *get_AT_low_pc PARAMS ((dw_die_ref)); | |
3473 | static const char *get_AT_hi_pc PARAMS ((dw_die_ref)); | |
3474 | static const char *get_AT_string PARAMS ((dw_die_ref, | |
3475 | enum dwarf_attribute)); | |
3476 | static int get_AT_flag PARAMS ((dw_die_ref, | |
3477 | enum dwarf_attribute)); | |
3478 | static unsigned get_AT_unsigned PARAMS ((dw_die_ref, | |
3479 | enum dwarf_attribute)); | |
3480 | static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref, | |
3481 | enum dwarf_attribute)); | |
3482 | static int is_c_family PARAMS ((void)); | |
28985b81 | 3483 | static int is_java PARAMS ((void)); |
7d9d8943 AM |
3484 | static int is_fortran PARAMS ((void)); |
3485 | static void remove_AT PARAMS ((dw_die_ref, | |
3486 | enum dwarf_attribute)); | |
3487 | static void remove_children PARAMS ((dw_die_ref)); | |
3488 | static void add_child_die PARAMS ((dw_die_ref, dw_die_ref)); | |
3489 | static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref)); | |
3490 | static dw_die_ref lookup_type_die PARAMS ((tree)); | |
3491 | static void equate_type_number_to_die PARAMS ((tree, dw_die_ref)); | |
3492 | static dw_die_ref lookup_decl_die PARAMS ((tree)); | |
3493 | static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref)); | |
3494 | static void print_spaces PARAMS ((FILE *)); | |
3495 | static void print_die PARAMS ((dw_die_ref, FILE *)); | |
3496 | static void print_dwarf_line_table PARAMS ((FILE *)); | |
881c6935 JM |
3497 | static void reverse_die_lists PARAMS ((dw_die_ref)); |
3498 | static void reverse_all_dies PARAMS ((dw_die_ref)); | |
3499 | static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref)); | |
3500 | static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref)); | |
3501 | static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *)); | |
3502 | static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *)); | |
3503 | static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *)); | |
3504 | static void compute_section_prefix PARAMS ((dw_die_ref)); | |
3505 | static int is_type_die PARAMS ((dw_die_ref)); | |
3506 | static int is_comdat_die PARAMS ((dw_die_ref)); | |
3507 | static int is_symbol_die PARAMS ((dw_die_ref)); | |
881c6935 JM |
3508 | static void assign_symbol_names PARAMS ((dw_die_ref)); |
3509 | static void break_out_includes PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3510 | static void add_sibling_attributes PARAMS ((dw_die_ref)); |
3511 | static void build_abbrev_table PARAMS ((dw_die_ref)); | |
63e46568 | 3512 | static void output_location_lists PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3513 | static unsigned long size_of_string PARAMS ((const char *)); |
3514 | static int constant_size PARAMS ((long unsigned)); | |
3515 | static unsigned long size_of_die PARAMS ((dw_die_ref)); | |
3516 | static void calc_die_sizes PARAMS ((dw_die_ref)); | |
1bfb5f8f JM |
3517 | static void mark_dies PARAMS ((dw_die_ref)); |
3518 | static void unmark_dies PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3519 | static unsigned long size_of_pubnames PARAMS ((void)); |
3520 | static unsigned long size_of_aranges PARAMS ((void)); | |
3521 | static enum dwarf_form value_format PARAMS ((dw_attr_ref)); | |
3522 | static void output_value_format PARAMS ((dw_attr_ref)); | |
3523 | static void output_abbrev_section PARAMS ((void)); | |
881c6935 | 3524 | static void output_die_symbol PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3525 | static void output_die PARAMS ((dw_die_ref)); |
3526 | static void output_compilation_unit_header PARAMS ((void)); | |
881c6935 | 3527 | static void output_comp_unit PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3528 | static const char *dwarf2_name PARAMS ((tree, int)); |
3529 | static void add_pubname PARAMS ((tree, dw_die_ref)); | |
3530 | static void output_pubnames PARAMS ((void)); | |
3531 | static void add_arange PARAMS ((tree, dw_die_ref)); | |
3532 | static void output_aranges PARAMS ((void)); | |
a20612aa RH |
3533 | static unsigned int add_ranges PARAMS ((tree)); |
3534 | static void output_ranges PARAMS ((void)); | |
7d9d8943 | 3535 | static void output_line_info PARAMS ((void)); |
0b34cf1e | 3536 | static void output_file_names PARAMS ((void)); |
7d9d8943 AM |
3537 | static dw_die_ref base_type_die PARAMS ((tree)); |
3538 | static tree root_type PARAMS ((tree)); | |
3539 | static int is_base_type PARAMS ((tree)); | |
3540 | static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref)); | |
3541 | static int type_is_enum PARAMS ((tree)); | |
3542 | static unsigned int reg_number PARAMS ((rtx)); | |
3543 | static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx)); | |
d8041cc8 | 3544 | static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT)); |
7d9d8943 AM |
3545 | static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long)); |
3546 | static int is_based_loc PARAMS ((rtx)); | |
3547 | static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode)); | |
3548 | static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx)); | |
3549 | static dw_loc_descr_ref loc_descriptor PARAMS ((rtx)); | |
d8041cc8 | 3550 | static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int)); |
7d9d8943 AM |
3551 | static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int)); |
3552 | static tree field_type PARAMS ((tree)); | |
3553 | static unsigned int simple_type_align_in_bits PARAMS ((tree)); | |
5f446d21 | 3554 | static unsigned int simple_decl_align_in_bits PARAMS ((tree)); |
7d9d8943 AM |
3555 | static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree)); |
3556 | static HOST_WIDE_INT field_byte_offset PARAMS ((tree)); | |
3557 | static void add_AT_location_description PARAMS ((dw_die_ref, | |
3558 | enum dwarf_attribute, rtx)); | |
3559 | static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree)); | |
3560 | static void add_const_value_attribute PARAMS ((dw_die_ref, rtx)); | |
d8041cc8 | 3561 | static rtx rtl_for_decl_location PARAMS ((tree)); |
7d9d8943 | 3562 | static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree)); |
1bfb5f8f | 3563 | static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree)); |
7d9d8943 AM |
3564 | static void add_name_attribute PARAMS ((dw_die_ref, const char *)); |
3565 | static void add_bound_info PARAMS ((dw_die_ref, | |
3566 | enum dwarf_attribute, tree)); | |
3567 | static void add_subscript_info PARAMS ((dw_die_ref, tree)); | |
3568 | static void add_byte_size_attribute PARAMS ((dw_die_ref, tree)); | |
3569 | static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree)); | |
3570 | static void add_bit_size_attribute PARAMS ((dw_die_ref, tree)); | |
3571 | static void add_prototyped_attribute PARAMS ((dw_die_ref, tree)); | |
3572 | static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree)); | |
3573 | static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree)); | |
3574 | static void add_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
3575 | static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
3576 | static void push_decl_scope PARAMS ((tree)); | |
3577 | static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref)); | |
3578 | static void pop_decl_scope PARAMS ((void)); | |
3579 | static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int, | |
3580 | dw_die_ref)); | |
3581 | static const char *type_tag PARAMS ((tree)); | |
3582 | static tree member_declared_type PARAMS ((tree)); | |
3583 | #if 0 | |
3584 | static const char *decl_start_label PARAMS ((tree)); | |
3585 | #endif | |
3586 | static void gen_array_type_die PARAMS ((tree, dw_die_ref)); | |
3587 | static void gen_set_type_die PARAMS ((tree, dw_die_ref)); | |
3588 | #if 0 | |
3589 | static void gen_entry_point_die PARAMS ((tree, dw_die_ref)); | |
3590 | #endif | |
3591 | static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
3592 | static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref)); | |
3593 | static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref)); | |
3594 | static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
3595 | static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref)); | |
3596 | static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref)); | |
3597 | static void gen_formal_types_die PARAMS ((tree, dw_die_ref)); | |
3598 | static void gen_subprogram_die PARAMS ((tree, dw_die_ref)); | |
3599 | static void gen_variable_die PARAMS ((tree, dw_die_ref)); | |
3600 | static void gen_label_die PARAMS ((tree, dw_die_ref)); | |
3601 | static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int)); | |
3602 | static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int)); | |
3603 | static void gen_field_die PARAMS ((tree, dw_die_ref)); | |
3604 | static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref)); | |
3605 | static dw_die_ref gen_compile_unit_die PARAMS ((const char *)); | |
3606 | static void gen_string_type_die PARAMS ((tree, dw_die_ref)); | |
3607 | static void gen_inheritance_die PARAMS ((tree, dw_die_ref)); | |
3608 | static void gen_member_die PARAMS ((tree, dw_die_ref)); | |
3609 | static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref)); | |
3610 | static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref)); | |
3611 | static void gen_typedef_die PARAMS ((tree, dw_die_ref)); | |
3612 | static void gen_type_die PARAMS ((tree, dw_die_ref)); | |
3613 | static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref)); | |
3614 | static void gen_block_die PARAMS ((tree, dw_die_ref, int)); | |
3615 | static void decls_for_scope PARAMS ((tree, dw_die_ref, int)); | |
3616 | static int is_redundant_typedef PARAMS ((tree)); | |
3617 | static void gen_decl_die PARAMS ((tree, dw_die_ref)); | |
981975b6 RH |
3618 | static unsigned lookup_filename PARAMS ((const char *)); |
3619 | static void init_file_table PARAMS ((void)); | |
7d9d8943 AM |
3620 | static void add_incomplete_type PARAMS ((tree)); |
3621 | static void retry_incomplete_types PARAMS ((void)); | |
3622 | static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref)); | |
7d9d8943 AM |
3623 | static rtx save_rtx PARAMS ((rtx)); |
3624 | static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref)); | |
fc608b03 | 3625 | static int file_info_cmp PARAMS ((const void *, const void *)); |
84a5b4f8 DB |
3626 | static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref, |
3627 | const char *, const char *, | |
3628 | const char *, unsigned)); | |
3629 | static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *, | |
3630 | dw_loc_descr_ref, | |
3631 | const char *, const char *, const char *)); | |
3632 | static void output_loc_list PARAMS ((dw_loc_list_ref)); | |
3633 | static char *gen_internal_sym PARAMS ((const char *)); | |
7d9d8943 AM |
3634 | |
3635 | /* Section names used to hold DWARF debugging information. */ | |
3636 | #ifndef DEBUG_INFO_SECTION | |
3637 | #define DEBUG_INFO_SECTION ".debug_info" | |
3638 | #endif | |
9d2f2c45 RH |
3639 | #ifndef DEBUG_ABBREV_SECTION |
3640 | #define DEBUG_ABBREV_SECTION ".debug_abbrev" | |
7d9d8943 | 3641 | #endif |
9d2f2c45 RH |
3642 | #ifndef DEBUG_ARANGES_SECTION |
3643 | #define DEBUG_ARANGES_SECTION ".debug_aranges" | |
7d9d8943 | 3644 | #endif |
9d2f2c45 RH |
3645 | #ifndef DEBUG_MACINFO_SECTION |
3646 | #define DEBUG_MACINFO_SECTION ".debug_macinfo" | |
7d9d8943 AM |
3647 | #endif |
3648 | #ifndef DEBUG_LINE_SECTION | |
3649 | #define DEBUG_LINE_SECTION ".debug_line" | |
3650 | #endif | |
9d2f2c45 RH |
3651 | #ifndef DEBUG_LOC_SECTION |
3652 | #define DEBUG_LOC_SECTION ".debug_loc" | |
7d9d8943 | 3653 | #endif |
9d2f2c45 RH |
3654 | #ifndef DEBUG_PUBNAMES_SECTION |
3655 | #define DEBUG_PUBNAMES_SECTION ".debug_pubnames" | |
7d9d8943 | 3656 | #endif |
9d2f2c45 RH |
3657 | #ifndef DEBUG_STR_SECTION |
3658 | #define DEBUG_STR_SECTION ".debug_str" | |
7d9d8943 | 3659 | #endif |
a20612aa RH |
3660 | #ifndef DEBUG_RANGES_SECTION |
3661 | #define DEBUG_RANGES_SECTION ".debug_ranges" | |
3662 | #endif | |
7d9d8943 AM |
3663 | |
3664 | /* Standard ELF section names for compiled code and data. */ | |
3665 | #ifndef TEXT_SECTION | |
3666 | #define TEXT_SECTION ".text" | |
3667 | #endif | |
3668 | #ifndef DATA_SECTION | |
3669 | #define DATA_SECTION ".data" | |
3670 | #endif | |
3671 | #ifndef BSS_SECTION | |
3672 | #define BSS_SECTION ".bss" | |
3673 | #endif | |
3674 | ||
3675 | /* Labels we insert at beginning sections we can reference instead of | |
556273e0 | 3676 | the section names themselves. */ |
7d9d8943 AM |
3677 | |
3678 | #ifndef TEXT_SECTION_LABEL | |
9d2f2c45 | 3679 | #define TEXT_SECTION_LABEL "Ltext" |
7d9d8943 AM |
3680 | #endif |
3681 | #ifndef DEBUG_LINE_SECTION_LABEL | |
9d2f2c45 | 3682 | #define DEBUG_LINE_SECTION_LABEL "Ldebug_line" |
7d9d8943 AM |
3683 | #endif |
3684 | #ifndef DEBUG_INFO_SECTION_LABEL | |
9d2f2c45 | 3685 | #define DEBUG_INFO_SECTION_LABEL "Ldebug_info" |
7d9d8943 | 3686 | #endif |
9d2f2c45 RH |
3687 | #ifndef DEBUG_ABBREV_SECTION_LABEL |
3688 | #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev" | |
7d9d8943 | 3689 | #endif |
9d2f2c45 RH |
3690 | #ifndef DEBUG_LOC_SECTION_LABEL |
3691 | #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc" | |
63e46568 | 3692 | #endif |
84a5b4f8 DB |
3693 | #ifndef DEBUG_MACINFO_SECTION_LABEL |
3694 | #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo" | |
3695 | #endif | |
a20612aa | 3696 | |
7d9d8943 AM |
3697 | /* Definitions of defaults for formats and names of various special |
3698 | (artificial) labels which may be generated within this file (when the -g | |
3699 | options is used and DWARF_DEBUGGING_INFO is in effect. | |
3700 | If necessary, these may be overridden from within the tm.h file, but | |
3701 | typically, overriding these defaults is unnecessary. */ | |
3702 | ||
3703 | static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3704 | static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3705 | static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3706 | static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3707 | static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
84a5b4f8 | 3708 | static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
63e46568 | 3709 | static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
7d9d8943 AM |
3710 | #ifndef TEXT_END_LABEL |
3711 | #define TEXT_END_LABEL "Letext" | |
3712 | #endif | |
3713 | #ifndef DATA_END_LABEL | |
3714 | #define DATA_END_LABEL "Ledata" | |
3715 | #endif | |
3716 | #ifndef BSS_END_LABEL | |
3717 | #define BSS_END_LABEL "Lebss" | |
3718 | #endif | |
7d9d8943 AM |
3719 | #ifndef BLOCK_BEGIN_LABEL |
3720 | #define BLOCK_BEGIN_LABEL "LBB" | |
3721 | #endif | |
3722 | #ifndef BLOCK_END_LABEL | |
3723 | #define BLOCK_END_LABEL "LBE" | |
3724 | #endif | |
3725 | #ifndef BODY_BEGIN_LABEL | |
3726 | #define BODY_BEGIN_LABEL "Lbb" | |
3727 | #endif | |
3728 | #ifndef BODY_END_LABEL | |
3729 | #define BODY_END_LABEL "Lbe" | |
3730 | #endif | |
3731 | #ifndef LINE_CODE_LABEL | |
3732 | #define LINE_CODE_LABEL "LM" | |
3733 | #endif | |
3734 | #ifndef SEPARATE_LINE_CODE_LABEL | |
3735 | #define SEPARATE_LINE_CODE_LABEL "LSM" | |
3736 | #endif | |
3737 | \f | |
3738 | /* We allow a language front-end to designate a function that is to be | |
3739 | called to "demangle" any name before it it put into a DIE. */ | |
3740 | ||
3741 | static const char *(*demangle_name_func) PARAMS ((const char *)); | |
3742 | ||
3743 | void | |
3744 | dwarf2out_set_demangle_name_func (func) | |
3745 | const char *(*func) PARAMS ((const char *)); | |
3746 | { | |
3747 | demangle_name_func = func; | |
3748 | } | |
3749 | \f | |
3750 | /* Return an rtx like ORIG which lives forever. If we're doing GC, | |
3751 | that means adding it to used_rtx_varray. If not, that means making | |
3752 | a copy on the permanent_obstack. */ | |
3753 | ||
3754 | static rtx | |
3755 | save_rtx (orig) | |
3756 | register rtx orig; | |
3757 | { | |
1f8f4a0b | 3758 | VARRAY_PUSH_RTX (used_rtx_varray, orig); |
7d9d8943 AM |
3759 | |
3760 | return orig; | |
3761 | } | |
3762 | ||
3763 | /* Test if rtl node points to a pseudo register. */ | |
3764 | ||
3765 | static inline int | |
3766 | is_pseudo_reg (rtl) | |
3767 | register rtx rtl; | |
3768 | { | |
3769 | return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER) | |
3770 | || (GET_CODE (rtl) == SUBREG | |
ddef6bc7 | 3771 | && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)); |
7d9d8943 AM |
3772 | } |
3773 | ||
3774 | /* Return a reference to a type, with its const and volatile qualifiers | |
3775 | removed. */ | |
3776 | ||
3777 | static inline tree | |
3778 | type_main_variant (type) | |
3779 | register tree type; | |
3780 | { | |
3781 | type = TYPE_MAIN_VARIANT (type); | |
3782 | ||
556273e0 | 3783 | /* There really should be only one main variant among any group of variants |
7d9d8943 AM |
3784 | of a given type (and all of the MAIN_VARIANT values for all members of |
3785 | the group should point to that one type) but sometimes the C front-end | |
3786 | messes this up for array types, so we work around that bug here. */ | |
3787 | ||
3788 | if (TREE_CODE (type) == ARRAY_TYPE) | |
3789 | while (type != TYPE_MAIN_VARIANT (type)) | |
3790 | type = TYPE_MAIN_VARIANT (type); | |
3791 | ||
3792 | return type; | |
3793 | } | |
3794 | ||
3795 | /* Return non-zero if the given type node represents a tagged type. */ | |
3796 | ||
3797 | static inline int | |
3798 | is_tagged_type (type) | |
3799 | register tree type; | |
3800 | { | |
3801 | register enum tree_code code = TREE_CODE (type); | |
3802 | ||
3803 | return (code == RECORD_TYPE || code == UNION_TYPE | |
3804 | || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); | |
3805 | } | |
3806 | ||
3807 | /* Convert a DIE tag into its string name. */ | |
3808 | ||
3809 | static const char * | |
3810 | dwarf_tag_name (tag) | |
3811 | register unsigned tag; | |
3812 | { | |
3813 | switch (tag) | |
3814 | { | |
3815 | case DW_TAG_padding: | |
3816 | return "DW_TAG_padding"; | |
3817 | case DW_TAG_array_type: | |
3818 | return "DW_TAG_array_type"; | |
3819 | case DW_TAG_class_type: | |
3820 | return "DW_TAG_class_type"; | |
3821 | case DW_TAG_entry_point: | |
3822 | return "DW_TAG_entry_point"; | |
3823 | case DW_TAG_enumeration_type: | |
3824 | return "DW_TAG_enumeration_type"; | |
3825 | case DW_TAG_formal_parameter: | |
3826 | return "DW_TAG_formal_parameter"; | |
3827 | case DW_TAG_imported_declaration: | |
3828 | return "DW_TAG_imported_declaration"; | |
3829 | case DW_TAG_label: | |
3830 | return "DW_TAG_label"; | |
3831 | case DW_TAG_lexical_block: | |
3832 | return "DW_TAG_lexical_block"; | |
3833 | case DW_TAG_member: | |
3834 | return "DW_TAG_member"; | |
3835 | case DW_TAG_pointer_type: | |
3836 | return "DW_TAG_pointer_type"; | |
3837 | case DW_TAG_reference_type: | |
3838 | return "DW_TAG_reference_type"; | |
3839 | case DW_TAG_compile_unit: | |
3840 | return "DW_TAG_compile_unit"; | |
3841 | case DW_TAG_string_type: | |
3842 | return "DW_TAG_string_type"; | |
3843 | case DW_TAG_structure_type: | |
3844 | return "DW_TAG_structure_type"; | |
3845 | case DW_TAG_subroutine_type: | |
3846 | return "DW_TAG_subroutine_type"; | |
3847 | case DW_TAG_typedef: | |
3848 | return "DW_TAG_typedef"; | |
3849 | case DW_TAG_union_type: | |
3850 | return "DW_TAG_union_type"; | |
3851 | case DW_TAG_unspecified_parameters: | |
3852 | return "DW_TAG_unspecified_parameters"; | |
3853 | case DW_TAG_variant: | |
3854 | return "DW_TAG_variant"; | |
3855 | case DW_TAG_common_block: | |
3856 | return "DW_TAG_common_block"; | |
3857 | case DW_TAG_common_inclusion: | |
3858 | return "DW_TAG_common_inclusion"; | |
3859 | case DW_TAG_inheritance: | |
3860 | return "DW_TAG_inheritance"; | |
3861 | case DW_TAG_inlined_subroutine: | |
3862 | return "DW_TAG_inlined_subroutine"; | |
3863 | case DW_TAG_module: | |
3864 | return "DW_TAG_module"; | |
3865 | case DW_TAG_ptr_to_member_type: | |
3866 | return "DW_TAG_ptr_to_member_type"; | |
3867 | case DW_TAG_set_type: | |
3868 | return "DW_TAG_set_type"; | |
3869 | case DW_TAG_subrange_type: | |
3870 | return "DW_TAG_subrange_type"; | |
3871 | case DW_TAG_with_stmt: | |
3872 | return "DW_TAG_with_stmt"; | |
3873 | case DW_TAG_access_declaration: | |
3874 | return "DW_TAG_access_declaration"; | |
3875 | case DW_TAG_base_type: | |
3876 | return "DW_TAG_base_type"; | |
3877 | case DW_TAG_catch_block: | |
3878 | return "DW_TAG_catch_block"; | |
3879 | case DW_TAG_const_type: | |
3880 | return "DW_TAG_const_type"; | |
3881 | case DW_TAG_constant: | |
3882 | return "DW_TAG_constant"; | |
3883 | case DW_TAG_enumerator: | |
3884 | return "DW_TAG_enumerator"; | |
3885 | case DW_TAG_file_type: | |
3886 | return "DW_TAG_file_type"; | |
3887 | case DW_TAG_friend: | |
3888 | return "DW_TAG_friend"; | |
3889 | case DW_TAG_namelist: | |
3890 | return "DW_TAG_namelist"; | |
3891 | case DW_TAG_namelist_item: | |
3892 | return "DW_TAG_namelist_item"; | |
3893 | case DW_TAG_packed_type: | |
3894 | return "DW_TAG_packed_type"; | |
3895 | case DW_TAG_subprogram: | |
3896 | return "DW_TAG_subprogram"; | |
3897 | case DW_TAG_template_type_param: | |
3898 | return "DW_TAG_template_type_param"; | |
3899 | case DW_TAG_template_value_param: | |
3900 | return "DW_TAG_template_value_param"; | |
3901 | case DW_TAG_thrown_type: | |
3902 | return "DW_TAG_thrown_type"; | |
3903 | case DW_TAG_try_block: | |
3904 | return "DW_TAG_try_block"; | |
3905 | case DW_TAG_variant_part: | |
3906 | return "DW_TAG_variant_part"; | |
3907 | case DW_TAG_variable: | |
3908 | return "DW_TAG_variable"; | |
3909 | case DW_TAG_volatile_type: | |
3910 | return "DW_TAG_volatile_type"; | |
3911 | case DW_TAG_MIPS_loop: | |
3912 | return "DW_TAG_MIPS_loop"; | |
3913 | case DW_TAG_format_label: | |
3914 | return "DW_TAG_format_label"; | |
3915 | case DW_TAG_function_template: | |
3916 | return "DW_TAG_function_template"; | |
3917 | case DW_TAG_class_template: | |
3918 | return "DW_TAG_class_template"; | |
881c6935 JM |
3919 | case DW_TAG_GNU_BINCL: |
3920 | return "DW_TAG_GNU_BINCL"; | |
3921 | case DW_TAG_GNU_EINCL: | |
3922 | return "DW_TAG_GNU_EINCL"; | |
7d9d8943 AM |
3923 | default: |
3924 | return "DW_TAG_<unknown>"; | |
3925 | } | |
3926 | } | |
3927 | ||
3928 | /* Convert a DWARF attribute code into its string name. */ | |
3929 | ||
3930 | static const char * | |
3931 | dwarf_attr_name (attr) | |
3932 | register unsigned attr; | |
3933 | { | |
3934 | switch (attr) | |
3935 | { | |
3936 | case DW_AT_sibling: | |
3937 | return "DW_AT_sibling"; | |
3938 | case DW_AT_location: | |
3939 | return "DW_AT_location"; | |
3940 | case DW_AT_name: | |
3941 | return "DW_AT_name"; | |
3942 | case DW_AT_ordering: | |
3943 | return "DW_AT_ordering"; | |
3944 | case DW_AT_subscr_data: | |
3945 | return "DW_AT_subscr_data"; | |
3946 | case DW_AT_byte_size: | |
3947 | return "DW_AT_byte_size"; | |
3948 | case DW_AT_bit_offset: | |
3949 | return "DW_AT_bit_offset"; | |
3950 | case DW_AT_bit_size: | |
3951 | return "DW_AT_bit_size"; | |
3952 | case DW_AT_element_list: | |
3953 | return "DW_AT_element_list"; | |
3954 | case DW_AT_stmt_list: | |
3955 | return "DW_AT_stmt_list"; | |
3956 | case DW_AT_low_pc: | |
3957 | return "DW_AT_low_pc"; | |
3958 | case DW_AT_high_pc: | |
3959 | return "DW_AT_high_pc"; | |
3960 | case DW_AT_language: | |
3961 | return "DW_AT_language"; | |
3962 | case DW_AT_member: | |
3963 | return "DW_AT_member"; | |
3964 | case DW_AT_discr: | |
3965 | return "DW_AT_discr"; | |
3966 | case DW_AT_discr_value: | |
3967 | return "DW_AT_discr_value"; | |
3968 | case DW_AT_visibility: | |
3969 | return "DW_AT_visibility"; | |
3970 | case DW_AT_import: | |
3971 | return "DW_AT_import"; | |
3972 | case DW_AT_string_length: | |
3973 | return "DW_AT_string_length"; | |
3974 | case DW_AT_common_reference: | |
3975 | return "DW_AT_common_reference"; | |
3976 | case DW_AT_comp_dir: | |
3977 | return "DW_AT_comp_dir"; | |
3978 | case DW_AT_const_value: | |
3979 | return "DW_AT_const_value"; | |
3980 | case DW_AT_containing_type: | |
3981 | return "DW_AT_containing_type"; | |
3982 | case DW_AT_default_value: | |
3983 | return "DW_AT_default_value"; | |
3984 | case DW_AT_inline: | |
3985 | return "DW_AT_inline"; | |
3986 | case DW_AT_is_optional: | |
3987 | return "DW_AT_is_optional"; | |
3988 | case DW_AT_lower_bound: | |
3989 | return "DW_AT_lower_bound"; | |
3990 | case DW_AT_producer: | |
3991 | return "DW_AT_producer"; | |
3992 | case DW_AT_prototyped: | |
3993 | return "DW_AT_prototyped"; | |
3994 | case DW_AT_return_addr: | |
3995 | return "DW_AT_return_addr"; | |
3996 | case DW_AT_start_scope: | |
3997 | return "DW_AT_start_scope"; | |
3998 | case DW_AT_stride_size: | |
3999 | return "DW_AT_stride_size"; | |
4000 | case DW_AT_upper_bound: | |
4001 | return "DW_AT_upper_bound"; | |
4002 | case DW_AT_abstract_origin: | |
4003 | return "DW_AT_abstract_origin"; | |
4004 | case DW_AT_accessibility: | |
4005 | return "DW_AT_accessibility"; | |
4006 | case DW_AT_address_class: | |
4007 | return "DW_AT_address_class"; | |
4008 | case DW_AT_artificial: | |
4009 | return "DW_AT_artificial"; | |
4010 | case DW_AT_base_types: | |
4011 | return "DW_AT_base_types"; | |
4012 | case DW_AT_calling_convention: | |
4013 | return "DW_AT_calling_convention"; | |
4014 | case DW_AT_count: | |
4015 | return "DW_AT_count"; | |
4016 | case DW_AT_data_member_location: | |
4017 | return "DW_AT_data_member_location"; | |
4018 | case DW_AT_decl_column: | |
4019 | return "DW_AT_decl_column"; | |
4020 | case DW_AT_decl_file: | |
4021 | return "DW_AT_decl_file"; | |
4022 | case DW_AT_decl_line: | |
4023 | return "DW_AT_decl_line"; | |
4024 | case DW_AT_declaration: | |
4025 | return "DW_AT_declaration"; | |
4026 | case DW_AT_discr_list: | |
4027 | return "DW_AT_discr_list"; | |
4028 | case DW_AT_encoding: | |
4029 | return "DW_AT_encoding"; | |
4030 | case DW_AT_external: | |
4031 | return "DW_AT_external"; | |
4032 | case DW_AT_frame_base: | |
4033 | return "DW_AT_frame_base"; | |
4034 | case DW_AT_friend: | |
4035 | return "DW_AT_friend"; | |
4036 | case DW_AT_identifier_case: | |
4037 | return "DW_AT_identifier_case"; | |
4038 | case DW_AT_macro_info: | |
4039 | return "DW_AT_macro_info"; | |
4040 | case DW_AT_namelist_items: | |
4041 | return "DW_AT_namelist_items"; | |
4042 | case DW_AT_priority: | |
4043 | return "DW_AT_priority"; | |
4044 | case DW_AT_segment: | |
4045 | return "DW_AT_segment"; | |
4046 | case DW_AT_specification: | |
4047 | return "DW_AT_specification"; | |
4048 | case DW_AT_static_link: | |
4049 | return "DW_AT_static_link"; | |
4050 | case DW_AT_type: | |
4051 | return "DW_AT_type"; | |
4052 | case DW_AT_use_location: | |
4053 | return "DW_AT_use_location"; | |
4054 | case DW_AT_variable_parameter: | |
4055 | return "DW_AT_variable_parameter"; | |
4056 | case DW_AT_virtuality: | |
4057 | return "DW_AT_virtuality"; | |
4058 | case DW_AT_vtable_elem_location: | |
4059 | return "DW_AT_vtable_elem_location"; | |
4060 | ||
a20612aa RH |
4061 | case DW_AT_allocated: |
4062 | return "DW_AT_allocated"; | |
4063 | case DW_AT_associated: | |
4064 | return "DW_AT_associated"; | |
4065 | case DW_AT_data_location: | |
4066 | return "DW_AT_data_location"; | |
4067 | case DW_AT_stride: | |
4068 | return "DW_AT_stride"; | |
4069 | case DW_AT_entry_pc: | |
4070 | return "DW_AT_entry_pc"; | |
4071 | case DW_AT_use_UTF8: | |
4072 | return "DW_AT_use_UTF8"; | |
4073 | case DW_AT_extension: | |
4074 | return "DW_AT_extension"; | |
4075 | case DW_AT_ranges: | |
4076 | return "DW_AT_ranges"; | |
4077 | case DW_AT_trampoline: | |
4078 | return "DW_AT_trampoline"; | |
4079 | case DW_AT_call_column: | |
4080 | return "DW_AT_call_column"; | |
4081 | case DW_AT_call_file: | |
4082 | return "DW_AT_call_file"; | |
4083 | case DW_AT_call_line: | |
4084 | return "DW_AT_call_line"; | |
4085 | ||
7d9d8943 AM |
4086 | case DW_AT_MIPS_fde: |
4087 | return "DW_AT_MIPS_fde"; | |
4088 | case DW_AT_MIPS_loop_begin: | |
4089 | return "DW_AT_MIPS_loop_begin"; | |
4090 | case DW_AT_MIPS_tail_loop_begin: | |
4091 | return "DW_AT_MIPS_tail_loop_begin"; | |
4092 | case DW_AT_MIPS_epilog_begin: | |
4093 | return "DW_AT_MIPS_epilog_begin"; | |
4094 | case DW_AT_MIPS_loop_unroll_factor: | |
4095 | return "DW_AT_MIPS_loop_unroll_factor"; | |
4096 | case DW_AT_MIPS_software_pipeline_depth: | |
4097 | return "DW_AT_MIPS_software_pipeline_depth"; | |
4098 | case DW_AT_MIPS_linkage_name: | |
4099 | return "DW_AT_MIPS_linkage_name"; | |
4100 | case DW_AT_MIPS_stride: | |
4101 | return "DW_AT_MIPS_stride"; | |
4102 | case DW_AT_MIPS_abstract_name: | |
4103 | return "DW_AT_MIPS_abstract_name"; | |
4104 | case DW_AT_MIPS_clone_origin: | |
4105 | return "DW_AT_MIPS_clone_origin"; | |
4106 | case DW_AT_MIPS_has_inlines: | |
4107 | return "DW_AT_MIPS_has_inlines"; | |
4108 | ||
4109 | case DW_AT_sf_names: | |
4110 | return "DW_AT_sf_names"; | |
4111 | case DW_AT_src_info: | |
4112 | return "DW_AT_src_info"; | |
4113 | case DW_AT_mac_info: | |
4114 | return "DW_AT_mac_info"; | |
4115 | case DW_AT_src_coords: | |
4116 | return "DW_AT_src_coords"; | |
4117 | case DW_AT_body_begin: | |
4118 | return "DW_AT_body_begin"; | |
4119 | case DW_AT_body_end: | |
4120 | return "DW_AT_body_end"; | |
4121 | default: | |
4122 | return "DW_AT_<unknown>"; | |
4123 | } | |
4124 | } | |
4125 | ||
4126 | /* Convert a DWARF value form code into its string name. */ | |
4127 | ||
4128 | static const char * | |
4129 | dwarf_form_name (form) | |
4130 | register unsigned form; | |
4131 | { | |
4132 | switch (form) | |
4133 | { | |
4134 | case DW_FORM_addr: | |
4135 | return "DW_FORM_addr"; | |
4136 | case DW_FORM_block2: | |
4137 | return "DW_FORM_block2"; | |
4138 | case DW_FORM_block4: | |
4139 | return "DW_FORM_block4"; | |
4140 | case DW_FORM_data2: | |
4141 | return "DW_FORM_data2"; | |
4142 | case DW_FORM_data4: | |
4143 | return "DW_FORM_data4"; | |
4144 | case DW_FORM_data8: | |
4145 | return "DW_FORM_data8"; | |
4146 | case DW_FORM_string: | |
4147 | return "DW_FORM_string"; | |
4148 | case DW_FORM_block: | |
4149 | return "DW_FORM_block"; | |
4150 | case DW_FORM_block1: | |
4151 | return "DW_FORM_block1"; | |
4152 | case DW_FORM_data1: | |
4153 | return "DW_FORM_data1"; | |
4154 | case DW_FORM_flag: | |
4155 | return "DW_FORM_flag"; | |
4156 | case DW_FORM_sdata: | |
4157 | return "DW_FORM_sdata"; | |
4158 | case DW_FORM_strp: | |
4159 | return "DW_FORM_strp"; | |
4160 | case DW_FORM_udata: | |
4161 | return "DW_FORM_udata"; | |
4162 | case DW_FORM_ref_addr: | |
4163 | return "DW_FORM_ref_addr"; | |
4164 | case DW_FORM_ref1: | |
4165 | return "DW_FORM_ref1"; | |
4166 | case DW_FORM_ref2: | |
4167 | return "DW_FORM_ref2"; | |
4168 | case DW_FORM_ref4: | |
4169 | return "DW_FORM_ref4"; | |
4170 | case DW_FORM_ref8: | |
4171 | return "DW_FORM_ref8"; | |
4172 | case DW_FORM_ref_udata: | |
4173 | return "DW_FORM_ref_udata"; | |
4174 | case DW_FORM_indirect: | |
4175 | return "DW_FORM_indirect"; | |
3f76745e | 4176 | default: |
7d9d8943 | 4177 | return "DW_FORM_<unknown>"; |
a3f97cbb JW |
4178 | } |
4179 | } | |
4180 | ||
3f76745e | 4181 | /* Convert a DWARF type code into its string name. */ |
71dfc51f | 4182 | |
487a6e06 | 4183 | #if 0 |
d560ee52 | 4184 | static const char * |
3f76745e JM |
4185 | dwarf_type_encoding_name (enc) |
4186 | register unsigned enc; | |
a3f97cbb | 4187 | { |
3f76745e | 4188 | switch (enc) |
a3f97cbb | 4189 | { |
3f76745e JM |
4190 | case DW_ATE_address: |
4191 | return "DW_ATE_address"; | |
4192 | case DW_ATE_boolean: | |
4193 | return "DW_ATE_boolean"; | |
4194 | case DW_ATE_complex_float: | |
4195 | return "DW_ATE_complex_float"; | |
4196 | case DW_ATE_float: | |
4197 | return "DW_ATE_float"; | |
4198 | case DW_ATE_signed: | |
4199 | return "DW_ATE_signed"; | |
4200 | case DW_ATE_signed_char: | |
4201 | return "DW_ATE_signed_char"; | |
4202 | case DW_ATE_unsigned: | |
4203 | return "DW_ATE_unsigned"; | |
4204 | case DW_ATE_unsigned_char: | |
4205 | return "DW_ATE_unsigned_char"; | |
4206 | default: | |
4207 | return "DW_ATE_<unknown>"; | |
4208 | } | |
a3f97cbb | 4209 | } |
487a6e06 | 4210 | #endif |
3f76745e JM |
4211 | \f |
4212 | /* Determine the "ultimate origin" of a decl. The decl may be an inlined | |
4213 | instance of an inlined instance of a decl which is local to an inline | |
4214 | function, so we have to trace all of the way back through the origin chain | |
4215 | to find out what sort of node actually served as the original seed for the | |
4216 | given block. */ | |
a3f97cbb | 4217 | |
3f76745e JM |
4218 | static tree |
4219 | decl_ultimate_origin (decl) | |
4220 | register tree decl; | |
a3f97cbb | 4221 | { |
10a11b75 JM |
4222 | /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the |
4223 | nodes in the function to point to themselves; ignore that if | |
4224 | we're trying to output the abstract instance of this function. */ | |
4225 | if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl) | |
4226 | return NULL_TREE; | |
4227 | ||
556273e0 | 4228 | #ifdef ENABLE_CHECKING |
02e24c7a MM |
4229 | if (DECL_FROM_INLINE (DECL_ORIGIN (decl))) |
4230 | /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the | |
4231 | most distant ancestor, this should never happen. */ | |
4232 | abort (); | |
4233 | #endif | |
3f76745e | 4234 | |
02e24c7a | 4235 | return DECL_ABSTRACT_ORIGIN (decl); |
a3f97cbb JW |
4236 | } |
4237 | ||
3f76745e JM |
4238 | /* Determine the "ultimate origin" of a block. The block may be an inlined |
4239 | instance of an inlined instance of a block which is local to an inline | |
4240 | function, so we have to trace all of the way back through the origin chain | |
4241 | to find out what sort of node actually served as the original seed for the | |
4242 | given block. */ | |
71dfc51f | 4243 | |
3f76745e JM |
4244 | static tree |
4245 | block_ultimate_origin (block) | |
4246 | register tree block; | |
a3f97cbb | 4247 | { |
3f76745e | 4248 | register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); |
71dfc51f | 4249 | |
10a11b75 JM |
4250 | /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the |
4251 | nodes in the function to point to themselves; ignore that if | |
4252 | we're trying to output the abstract instance of this function. */ | |
4253 | if (BLOCK_ABSTRACT (block) && immediate_origin == block) | |
4254 | return NULL_TREE; | |
4255 | ||
3f76745e JM |
4256 | if (immediate_origin == NULL_TREE) |
4257 | return NULL_TREE; | |
4258 | else | |
4259 | { | |
4260 | register tree ret_val; | |
4261 | register tree lookahead = immediate_origin; | |
71dfc51f | 4262 | |
3f76745e JM |
4263 | do |
4264 | { | |
4265 | ret_val = lookahead; | |
4266 | lookahead = (TREE_CODE (ret_val) == BLOCK) | |
4267 | ? BLOCK_ABSTRACT_ORIGIN (ret_val) | |
4268 | : NULL; | |
4269 | } | |
4270 | while (lookahead != NULL && lookahead != ret_val); | |
4271 | ||
4272 | return ret_val; | |
4273 | } | |
a3f97cbb JW |
4274 | } |
4275 | ||
3f76745e JM |
4276 | /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT |
4277 | of a virtual function may refer to a base class, so we check the 'this' | |
4278 | parameter. */ | |
71dfc51f | 4279 | |
3f76745e JM |
4280 | static tree |
4281 | decl_class_context (decl) | |
4282 | tree decl; | |
a3f97cbb | 4283 | { |
3f76745e | 4284 | tree context = NULL_TREE; |
71dfc51f | 4285 | |
3f76745e JM |
4286 | if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl)) |
4287 | context = DECL_CONTEXT (decl); | |
4288 | else | |
4289 | context = TYPE_MAIN_VARIANT | |
4290 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
71dfc51f | 4291 | |
2f939d94 | 4292 | if (context && !TYPE_P (context)) |
3f76745e JM |
4293 | context = NULL_TREE; |
4294 | ||
4295 | return context; | |
a3f97cbb JW |
4296 | } |
4297 | \f | |
a96c67ec | 4298 | /* Add an attribute/value pair to a DIE. We build the lists up in reverse |
881c6935 | 4299 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f RK |
4300 | |
4301 | static inline void | |
3f76745e JM |
4302 | add_dwarf_attr (die, attr) |
4303 | register dw_die_ref die; | |
4304 | register dw_attr_ref attr; | |
a3f97cbb | 4305 | { |
3f76745e | 4306 | if (die != NULL && attr != NULL) |
a3f97cbb | 4307 | { |
a96c67ec JM |
4308 | attr->dw_attr_next = die->die_attr; |
4309 | die->die_attr = attr; | |
a3f97cbb JW |
4310 | } |
4311 | } | |
4312 | ||
c6991660 | 4313 | static inline dw_val_class AT_class PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4314 | static inline dw_val_class |
4315 | AT_class (a) | |
4316 | dw_attr_ref a; | |
4317 | { | |
4318 | return a->dw_attr_val.val_class; | |
4319 | } | |
4320 | ||
3f76745e | 4321 | /* Add a flag value attribute to a DIE. */ |
71dfc51f | 4322 | |
3f76745e JM |
4323 | static inline void |
4324 | add_AT_flag (die, attr_kind, flag) | |
4325 | register dw_die_ref die; | |
4326 | register enum dwarf_attribute attr_kind; | |
4327 | register unsigned flag; | |
a3f97cbb | 4328 | { |
3f76745e | 4329 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4330 | |
3f76745e JM |
4331 | attr->dw_attr_next = NULL; |
4332 | attr->dw_attr = attr_kind; | |
4333 | attr->dw_attr_val.val_class = dw_val_class_flag; | |
4334 | attr->dw_attr_val.v.val_flag = flag; | |
4335 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4336 | } |
4337 | ||
c6991660 | 4338 | static inline unsigned AT_flag PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4339 | static inline unsigned |
4340 | AT_flag (a) | |
4341 | register dw_attr_ref a; | |
4342 | { | |
4343 | if (a && AT_class (a) == dw_val_class_flag) | |
4344 | return a->dw_attr_val.v.val_flag; | |
4345 | ||
40e8cc95 | 4346 | abort (); |
a96c67ec JM |
4347 | } |
4348 | ||
3f76745e | 4349 | /* Add a signed integer attribute value to a DIE. */ |
71dfc51f | 4350 | |
3f76745e JM |
4351 | static inline void |
4352 | add_AT_int (die, attr_kind, int_val) | |
4353 | register dw_die_ref die; | |
4354 | register enum dwarf_attribute attr_kind; | |
4355 | register long int int_val; | |
a3f97cbb | 4356 | { |
3f76745e JM |
4357 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
4358 | ||
4359 | attr->dw_attr_next = NULL; | |
4360 | attr->dw_attr = attr_kind; | |
4361 | attr->dw_attr_val.val_class = dw_val_class_const; | |
4362 | attr->dw_attr_val.v.val_int = int_val; | |
4363 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4364 | } |
4365 | ||
c6991660 | 4366 | static inline long int AT_int PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4367 | static inline long int |
4368 | AT_int (a) | |
4369 | register dw_attr_ref a; | |
4370 | { | |
4371 | if (a && AT_class (a) == dw_val_class_const) | |
4372 | return a->dw_attr_val.v.val_int; | |
4373 | ||
40e8cc95 | 4374 | abort (); |
a96c67ec JM |
4375 | } |
4376 | ||
3f76745e | 4377 | /* Add an unsigned integer attribute value to a DIE. */ |
71dfc51f | 4378 | |
3f76745e JM |
4379 | static inline void |
4380 | add_AT_unsigned (die, attr_kind, unsigned_val) | |
4381 | register dw_die_ref die; | |
4382 | register enum dwarf_attribute attr_kind; | |
4383 | register unsigned long unsigned_val; | |
a3f97cbb | 4384 | { |
3f76745e JM |
4385 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
4386 | ||
4387 | attr->dw_attr_next = NULL; | |
4388 | attr->dw_attr = attr_kind; | |
4389 | attr->dw_attr_val.val_class = dw_val_class_unsigned_const; | |
4390 | attr->dw_attr_val.v.val_unsigned = unsigned_val; | |
4391 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4392 | } |
71dfc51f | 4393 | |
c6991660 | 4394 | static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4395 | static inline unsigned long |
4396 | AT_unsigned (a) | |
4397 | register dw_attr_ref a; | |
4398 | { | |
4399 | if (a && AT_class (a) == dw_val_class_unsigned_const) | |
4400 | return a->dw_attr_val.v.val_unsigned; | |
4401 | ||
40e8cc95 | 4402 | abort (); |
a96c67ec JM |
4403 | } |
4404 | ||
3f76745e JM |
4405 | /* Add an unsigned double integer attribute value to a DIE. */ |
4406 | ||
4407 | static inline void | |
4408 | add_AT_long_long (die, attr_kind, val_hi, val_low) | |
a3f97cbb | 4409 | register dw_die_ref die; |
3f76745e JM |
4410 | register enum dwarf_attribute attr_kind; |
4411 | register unsigned long val_hi; | |
4412 | register unsigned long val_low; | |
a3f97cbb | 4413 | { |
3f76745e | 4414 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4415 | |
3f76745e JM |
4416 | attr->dw_attr_next = NULL; |
4417 | attr->dw_attr = attr_kind; | |
4418 | attr->dw_attr_val.val_class = dw_val_class_long_long; | |
4419 | attr->dw_attr_val.v.val_long_long.hi = val_hi; | |
4420 | attr->dw_attr_val.v.val_long_long.low = val_low; | |
4421 | add_dwarf_attr (die, attr); | |
4422 | } | |
71dfc51f | 4423 | |
3f76745e | 4424 | /* Add a floating point attribute value to a DIE and return it. */ |
71dfc51f | 4425 | |
3f76745e JM |
4426 | static inline void |
4427 | add_AT_float (die, attr_kind, length, array) | |
4428 | register dw_die_ref die; | |
4429 | register enum dwarf_attribute attr_kind; | |
4430 | register unsigned length; | |
4431 | register long *array; | |
4432 | { | |
4433 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
4434 | ||
4435 | attr->dw_attr_next = NULL; | |
4436 | attr->dw_attr = attr_kind; | |
4437 | attr->dw_attr_val.val_class = dw_val_class_float; | |
4438 | attr->dw_attr_val.v.val_float.length = length; | |
4439 | attr->dw_attr_val.v.val_float.array = array; | |
4440 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4441 | } |
4442 | ||
3f76745e | 4443 | /* Add a string attribute value to a DIE. */ |
71dfc51f | 4444 | |
3f76745e JM |
4445 | static inline void |
4446 | add_AT_string (die, attr_kind, str) | |
a3f97cbb | 4447 | register dw_die_ref die; |
3f76745e | 4448 | register enum dwarf_attribute attr_kind; |
d560ee52 | 4449 | register const char *str; |
a3f97cbb | 4450 | { |
3f76745e | 4451 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4452 | |
3f76745e JM |
4453 | attr->dw_attr_next = NULL; |
4454 | attr->dw_attr = attr_kind; | |
4455 | attr->dw_attr_val.val_class = dw_val_class_str; | |
4456 | attr->dw_attr_val.v.val_str = xstrdup (str); | |
4457 | add_dwarf_attr (die, attr); | |
4458 | } | |
71dfc51f | 4459 | |
c6991660 | 4460 | static inline const char *AT_string PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4461 | static inline const char * |
4462 | AT_string (a) | |
4463 | register dw_attr_ref a; | |
4464 | { | |
4465 | if (a && AT_class (a) == dw_val_class_str) | |
4466 | return a->dw_attr_val.v.val_str; | |
4467 | ||
40e8cc95 | 4468 | abort (); |
a96c67ec JM |
4469 | } |
4470 | ||
3f76745e | 4471 | /* Add a DIE reference attribute value to a DIE. */ |
71dfc51f | 4472 | |
3f76745e JM |
4473 | static inline void |
4474 | add_AT_die_ref (die, attr_kind, targ_die) | |
4475 | register dw_die_ref die; | |
4476 | register enum dwarf_attribute attr_kind; | |
4477 | register dw_die_ref targ_die; | |
4478 | { | |
4479 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 4480 | |
3f76745e JM |
4481 | attr->dw_attr_next = NULL; |
4482 | attr->dw_attr = attr_kind; | |
4483 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
881c6935 JM |
4484 | attr->dw_attr_val.v.val_die_ref.die = targ_die; |
4485 | attr->dw_attr_val.v.val_die_ref.external = 0; | |
3f76745e JM |
4486 | add_dwarf_attr (die, attr); |
4487 | } | |
b1ccbc24 | 4488 | |
c6991660 | 4489 | static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4490 | static inline dw_die_ref |
4491 | AT_ref (a) | |
4492 | register dw_attr_ref a; | |
4493 | { | |
4494 | if (a && AT_class (a) == dw_val_class_die_ref) | |
881c6935 | 4495 | return a->dw_attr_val.v.val_die_ref.die; |
a96c67ec | 4496 | |
40e8cc95 | 4497 | abort (); |
a96c67ec JM |
4498 | } |
4499 | ||
881c6935 JM |
4500 | static inline int AT_ref_external PARAMS ((dw_attr_ref)); |
4501 | static inline int | |
4502 | AT_ref_external (a) | |
4503 | register dw_attr_ref a; | |
4504 | { | |
4505 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4506 | return a->dw_attr_val.v.val_die_ref.external; | |
4507 | ||
4508 | return 0; | |
4509 | } | |
4510 | ||
4511 | static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int)); | |
4512 | static inline void | |
4513 | set_AT_ref_external (a, i) | |
4514 | register dw_attr_ref a; | |
4515 | int i; | |
4516 | { | |
4517 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4518 | a->dw_attr_val.v.val_die_ref.external = i; | |
4519 | else | |
4520 | abort (); | |
4521 | } | |
4522 | ||
3f76745e | 4523 | /* Add an FDE reference attribute value to a DIE. */ |
b1ccbc24 | 4524 | |
3f76745e JM |
4525 | static inline void |
4526 | add_AT_fde_ref (die, attr_kind, targ_fde) | |
4527 | register dw_die_ref die; | |
4528 | register enum dwarf_attribute attr_kind; | |
4529 | register unsigned targ_fde; | |
4530 | { | |
4531 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
b1ccbc24 | 4532 | |
3f76745e JM |
4533 | attr->dw_attr_next = NULL; |
4534 | attr->dw_attr = attr_kind; | |
4535 | attr->dw_attr_val.val_class = dw_val_class_fde_ref; | |
4536 | attr->dw_attr_val.v.val_fde_index = targ_fde; | |
4537 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4538 | } |
71dfc51f | 4539 | |
3f76745e | 4540 | /* Add a location description attribute value to a DIE. */ |
71dfc51f | 4541 | |
3f76745e JM |
4542 | static inline void |
4543 | add_AT_loc (die, attr_kind, loc) | |
4544 | register dw_die_ref die; | |
4545 | register enum dwarf_attribute attr_kind; | |
4546 | register dw_loc_descr_ref loc; | |
4547 | { | |
4548 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 4549 | |
3f76745e JM |
4550 | attr->dw_attr_next = NULL; |
4551 | attr->dw_attr = attr_kind; | |
4552 | attr->dw_attr_val.val_class = dw_val_class_loc; | |
4553 | attr->dw_attr_val.v.val_loc = loc; | |
4554 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4555 | } |
4556 | ||
c6991660 | 4557 | static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4558 | static inline dw_loc_descr_ref |
4559 | AT_loc (a) | |
4560 | register dw_attr_ref a; | |
4561 | { | |
4562 | if (a && AT_class (a) == dw_val_class_loc) | |
4563 | return a->dw_attr_val.v.val_loc; | |
4564 | ||
40e8cc95 | 4565 | abort (); |
a96c67ec JM |
4566 | } |
4567 | ||
63e46568 DB |
4568 | static inline void |
4569 | add_AT_loc_list (die, attr_kind, loc_list) | |
4570 | register dw_die_ref die; | |
4571 | register enum dwarf_attribute attr_kind; | |
4572 | register dw_loc_list_ref loc_list; | |
4573 | { | |
4574 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
4575 | ||
4576 | attr->dw_attr_next = NULL; | |
4577 | attr->dw_attr = attr_kind; | |
4578 | attr->dw_attr_val.val_class = dw_val_class_loc_list; | |
4579 | attr->dw_attr_val.v.val_loc_list = loc_list; | |
4580 | add_dwarf_attr (die, attr); | |
4581 | have_location_lists = 1; | |
4582 | } | |
4583 | ||
4584 | static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref)); | |
4585 | ||
4586 | static inline dw_loc_list_ref | |
4587 | AT_loc_list (a) | |
4588 | register dw_attr_ref a; | |
4589 | { | |
4590 | if (a && AT_class (a) == dw_val_class_loc_list) | |
4591 | return a->dw_attr_val.v.val_loc_list; | |
4592 | ||
4593 | abort (); | |
4594 | } | |
4595 | ||
3f76745e | 4596 | /* Add an address constant attribute value to a DIE. */ |
71dfc51f | 4597 | |
3f76745e JM |
4598 | static inline void |
4599 | add_AT_addr (die, attr_kind, addr) | |
4600 | register dw_die_ref die; | |
4601 | register enum dwarf_attribute attr_kind; | |
1865dbb5 | 4602 | rtx addr; |
a3f97cbb | 4603 | { |
3f76745e | 4604 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4605 | |
3f76745e JM |
4606 | attr->dw_attr_next = NULL; |
4607 | attr->dw_attr = attr_kind; | |
4608 | attr->dw_attr_val.val_class = dw_val_class_addr; | |
4609 | attr->dw_attr_val.v.val_addr = addr; | |
4610 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4611 | } |
4612 | ||
c6991660 | 4613 | static inline rtx AT_addr PARAMS ((dw_attr_ref)); |
1865dbb5 | 4614 | static inline rtx |
a96c67ec JM |
4615 | AT_addr (a) |
4616 | register dw_attr_ref a; | |
4617 | { | |
4618 | if (a && AT_class (a) == dw_val_class_addr) | |
4619 | return a->dw_attr_val.v.val_addr; | |
4620 | ||
40e8cc95 | 4621 | abort (); |
a96c67ec JM |
4622 | } |
4623 | ||
3f76745e | 4624 | /* Add a label identifier attribute value to a DIE. */ |
71dfc51f | 4625 | |
3f76745e JM |
4626 | static inline void |
4627 | add_AT_lbl_id (die, attr_kind, lbl_id) | |
4628 | register dw_die_ref die; | |
4629 | register enum dwarf_attribute attr_kind; | |
d3e3972c | 4630 | register const char *lbl_id; |
a3f97cbb | 4631 | { |
3f76745e | 4632 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4633 | |
3f76745e JM |
4634 | attr->dw_attr_next = NULL; |
4635 | attr->dw_attr = attr_kind; | |
4636 | attr->dw_attr_val.val_class = dw_val_class_lbl_id; | |
4637 | attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); | |
4638 | add_dwarf_attr (die, attr); | |
4639 | } | |
71dfc51f | 4640 | |
3f76745e JM |
4641 | /* Add a section offset attribute value to a DIE. */ |
4642 | ||
4643 | static inline void | |
8b790721 | 4644 | add_AT_lbl_offset (die, attr_kind, label) |
3f76745e JM |
4645 | register dw_die_ref die; |
4646 | register enum dwarf_attribute attr_kind; | |
d3e3972c | 4647 | register const char *label; |
3f76745e JM |
4648 | { |
4649 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 4650 | |
3f76745e JM |
4651 | attr->dw_attr_next = NULL; |
4652 | attr->dw_attr = attr_kind; | |
8b790721 | 4653 | attr->dw_attr_val.val_class = dw_val_class_lbl_offset; |
a96c67ec | 4654 | attr->dw_attr_val.v.val_lbl_id = xstrdup (label); |
3f76745e | 4655 | add_dwarf_attr (die, attr); |
a3f97cbb JW |
4656 | } |
4657 | ||
a20612aa RH |
4658 | /* Add an offset attribute value to a DIE. */ |
4659 | ||
4660 | static void | |
4661 | add_AT_offset (die, attr_kind, offset) | |
4662 | register dw_die_ref die; | |
4663 | register enum dwarf_attribute attr_kind; | |
4664 | register unsigned long offset; | |
4665 | { | |
4666 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
4667 | ||
4668 | attr->dw_attr_next = NULL; | |
4669 | attr->dw_attr = attr_kind; | |
4670 | attr->dw_attr_val.val_class = dw_val_class_offset; | |
4671 | attr->dw_attr_val.v.val_offset = offset; | |
4672 | add_dwarf_attr (die, attr); | |
4673 | } | |
4674 | ||
c6991660 | 4675 | static inline const char *AT_lbl PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4676 | static inline const char * |
4677 | AT_lbl (a) | |
4678 | register dw_attr_ref a; | |
a3f97cbb | 4679 | { |
a96c67ec JM |
4680 | if (a && (AT_class (a) == dw_val_class_lbl_id |
4681 | || AT_class (a) == dw_val_class_lbl_offset)) | |
4682 | return a->dw_attr_val.v.val_lbl_id; | |
71dfc51f | 4683 | |
40e8cc95 | 4684 | abort (); |
a3f97cbb JW |
4685 | } |
4686 | ||
3f76745e | 4687 | /* Get the attribute of type attr_kind. */ |
71dfc51f | 4688 | |
3f76745e JM |
4689 | static inline dw_attr_ref |
4690 | get_AT (die, attr_kind) | |
4691 | register dw_die_ref die; | |
4692 | register enum dwarf_attribute attr_kind; | |
f37230f0 | 4693 | { |
3f76745e JM |
4694 | register dw_attr_ref a; |
4695 | register dw_die_ref spec = NULL; | |
556273e0 | 4696 | |
3f76745e JM |
4697 | if (die != NULL) |
4698 | { | |
4699 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
4700 | { | |
4701 | if (a->dw_attr == attr_kind) | |
4702 | return a; | |
71dfc51f | 4703 | |
3f76745e JM |
4704 | if (a->dw_attr == DW_AT_specification |
4705 | || a->dw_attr == DW_AT_abstract_origin) | |
a96c67ec | 4706 | spec = AT_ref (a); |
3f76745e | 4707 | } |
71dfc51f | 4708 | |
3f76745e JM |
4709 | if (spec) |
4710 | return get_AT (spec, attr_kind); | |
4711 | } | |
4712 | ||
4713 | return NULL; | |
f37230f0 JM |
4714 | } |
4715 | ||
3f76745e JM |
4716 | /* Return the "low pc" attribute value, typically associated with |
4717 | a subprogram DIE. Return null if the "low pc" attribute is | |
4718 | either not prsent, or if it cannot be represented as an | |
4719 | assembler label identifier. */ | |
71dfc51f | 4720 | |
a96c67ec | 4721 | static inline const char * |
3f76745e JM |
4722 | get_AT_low_pc (die) |
4723 | register dw_die_ref die; | |
7e23cb16 | 4724 | { |
3f76745e | 4725 | register dw_attr_ref a = get_AT (die, DW_AT_low_pc); |
40e8cc95 | 4726 | return a ? AT_lbl (a) : NULL; |
7e23cb16 JM |
4727 | } |
4728 | ||
3f76745e JM |
4729 | /* Return the "high pc" attribute value, typically associated with |
4730 | a subprogram DIE. Return null if the "high pc" attribute is | |
4731 | either not prsent, or if it cannot be represented as an | |
4732 | assembler label identifier. */ | |
71dfc51f | 4733 | |
a96c67ec | 4734 | static inline const char * |
3f76745e | 4735 | get_AT_hi_pc (die) |
a3f97cbb JW |
4736 | register dw_die_ref die; |
4737 | { | |
3f76745e | 4738 | register dw_attr_ref a = get_AT (die, DW_AT_high_pc); |
40e8cc95 | 4739 | return a ? AT_lbl (a) : NULL; |
3f76745e JM |
4740 | } |
4741 | ||
4742 | /* Return the value of the string attribute designated by ATTR_KIND, or | |
4743 | NULL if it is not present. */ | |
71dfc51f | 4744 | |
a96c67ec | 4745 | static inline const char * |
3f76745e JM |
4746 | get_AT_string (die, attr_kind) |
4747 | register dw_die_ref die; | |
4748 | register enum dwarf_attribute attr_kind; | |
4749 | { | |
4750 | register dw_attr_ref a = get_AT (die, attr_kind); | |
40e8cc95 | 4751 | return a ? AT_string (a) : NULL; |
a3f97cbb JW |
4752 | } |
4753 | ||
3f76745e JM |
4754 | /* Return the value of the flag attribute designated by ATTR_KIND, or -1 |
4755 | if it is not present. */ | |
71dfc51f | 4756 | |
3f76745e JM |
4757 | static inline int |
4758 | get_AT_flag (die, attr_kind) | |
4759 | register dw_die_ref die; | |
4760 | register enum dwarf_attribute attr_kind; | |
a3f97cbb | 4761 | { |
3f76745e | 4762 | register dw_attr_ref a = get_AT (die, attr_kind); |
40e8cc95 | 4763 | return a ? AT_flag (a) : 0; |
a3f97cbb JW |
4764 | } |
4765 | ||
3f76745e JM |
4766 | /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0 |
4767 | if it is not present. */ | |
71dfc51f | 4768 | |
3f76745e JM |
4769 | static inline unsigned |
4770 | get_AT_unsigned (die, attr_kind) | |
4771 | register dw_die_ref die; | |
4772 | register enum dwarf_attribute attr_kind; | |
a3f97cbb | 4773 | { |
3f76745e | 4774 | register dw_attr_ref a = get_AT (die, attr_kind); |
40e8cc95 | 4775 | return a ? AT_unsigned (a) : 0; |
a96c67ec | 4776 | } |
71dfc51f | 4777 | |
a96c67ec JM |
4778 | static inline dw_die_ref |
4779 | get_AT_ref (die, attr_kind) | |
4780 | dw_die_ref die; | |
4781 | register enum dwarf_attribute attr_kind; | |
4782 | { | |
4783 | register dw_attr_ref a = get_AT (die, attr_kind); | |
40e8cc95 | 4784 | return a ? AT_ref (a) : NULL; |
3f76745e | 4785 | } |
71dfc51f | 4786 | |
3f76745e JM |
4787 | static inline int |
4788 | is_c_family () | |
4789 | { | |
4790 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
71dfc51f | 4791 | |
3f76745e JM |
4792 | return (lang == DW_LANG_C || lang == DW_LANG_C89 |
4793 | || lang == DW_LANG_C_plus_plus); | |
556273e0 | 4794 | } |
71dfc51f | 4795 | |
3f76745e JM |
4796 | static inline int |
4797 | is_fortran () | |
4798 | { | |
4799 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
71dfc51f | 4800 | |
3f76745e | 4801 | return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90); |
556273e0 | 4802 | } |
71dfc51f | 4803 | |
28985b81 AG |
4804 | static inline int |
4805 | is_java () | |
4806 | { | |
4807 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
4808 | ||
4809 | return (lang == DW_LANG_Java); | |
4810 | } | |
4811 | ||
10a11b75 | 4812 | /* Free up the memory used by A. */ |
71dfc51f | 4813 | |
c6991660 | 4814 | static inline void free_AT PARAMS ((dw_attr_ref)); |
3f76745e | 4815 | static inline void |
10a11b75 JM |
4816 | free_AT (a) |
4817 | dw_attr_ref a; | |
4818 | { | |
4819 | switch (AT_class (a)) | |
4820 | { | |
10a11b75 JM |
4821 | case dw_val_class_str: |
4822 | case dw_val_class_lbl_id: | |
4823 | case dw_val_class_lbl_offset: | |
4824 | free (a->dw_attr_val.v.val_str); | |
4825 | break; | |
4826 | ||
3724ec07 WC |
4827 | case dw_val_class_float: |
4828 | free (a->dw_attr_val.v.val_float.array); | |
4829 | break; | |
0b34cf1e | 4830 | |
10a11b75 JM |
4831 | default: |
4832 | break; | |
4833 | } | |
4834 | ||
4835 | free (a); | |
556273e0 | 4836 | } |
10a11b75 JM |
4837 | |
4838 | /* Remove the specified attribute if present. */ | |
4839 | ||
4840 | static void | |
3f76745e JM |
4841 | remove_AT (die, attr_kind) |
4842 | register dw_die_ref die; | |
4843 | register enum dwarf_attribute attr_kind; | |
4844 | { | |
a96c67ec | 4845 | register dw_attr_ref *p; |
6d649d26 | 4846 | register dw_attr_ref removed = NULL; |
a3f97cbb | 4847 | |
3f76745e JM |
4848 | if (die != NULL) |
4849 | { | |
a96c67ec JM |
4850 | for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next)) |
4851 | if ((*p)->dw_attr == attr_kind) | |
4852 | { | |
4853 | removed = *p; | |
4854 | *p = (*p)->dw_attr_next; | |
4855 | break; | |
4856 | } | |
71dfc51f | 4857 | |
a96c67ec | 4858 | if (removed != 0) |
10a11b75 JM |
4859 | free_AT (removed); |
4860 | } | |
4861 | } | |
71dfc51f | 4862 | |
10a11b75 | 4863 | /* Free up the memory used by DIE. */ |
71dfc51f | 4864 | |
c6991660 | 4865 | static inline void free_die PARAMS ((dw_die_ref)); |
10a11b75 JM |
4866 | static inline void |
4867 | free_die (die) | |
4868 | dw_die_ref die; | |
4869 | { | |
4870 | remove_children (die); | |
4871 | free (die); | |
3f76745e | 4872 | } |
71dfc51f | 4873 | |
3f76745e | 4874 | /* Discard the children of this DIE. */ |
71dfc51f | 4875 | |
10a11b75 | 4876 | static void |
3f76745e JM |
4877 | remove_children (die) |
4878 | register dw_die_ref die; | |
4879 | { | |
4880 | register dw_die_ref child_die = die->die_child; | |
4881 | ||
4882 | die->die_child = NULL; | |
3f76745e JM |
4883 | |
4884 | while (child_die != NULL) | |
a3f97cbb | 4885 | { |
3f76745e JM |
4886 | register dw_die_ref tmp_die = child_die; |
4887 | register dw_attr_ref a; | |
71dfc51f | 4888 | |
3f76745e | 4889 | child_die = child_die->die_sib; |
556273e0 KH |
4890 | |
4891 | for (a = tmp_die->die_attr; a != NULL;) | |
a3f97cbb | 4892 | { |
3f76745e | 4893 | register dw_attr_ref tmp_a = a; |
71dfc51f | 4894 | |
3f76745e | 4895 | a = a->dw_attr_next; |
10a11b75 | 4896 | free_AT (tmp_a); |
a3f97cbb | 4897 | } |
71dfc51f | 4898 | |
10a11b75 | 4899 | free_die (tmp_die); |
3f76745e JM |
4900 | } |
4901 | } | |
71dfc51f | 4902 | |
a96c67ec | 4903 | /* Add a child DIE below its parent. We build the lists up in reverse |
881c6935 | 4904 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f | 4905 | |
3f76745e JM |
4906 | static inline void |
4907 | add_child_die (die, child_die) | |
4908 | register dw_die_ref die; | |
4909 | register dw_die_ref child_die; | |
4910 | { | |
4911 | if (die != NULL && child_die != NULL) | |
e90b62db | 4912 | { |
3a88cbd1 JL |
4913 | if (die == child_die) |
4914 | abort (); | |
3f76745e | 4915 | child_die->die_parent = die; |
a96c67ec JM |
4916 | child_die->die_sib = die->die_child; |
4917 | die->die_child = child_die; | |
3f76745e JM |
4918 | } |
4919 | } | |
4920 | ||
2081603c JM |
4921 | /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT |
4922 | is the specification, to the front of PARENT's list of children. */ | |
10a11b75 JM |
4923 | |
4924 | static void | |
4925 | splice_child_die (parent, child) | |
4926 | dw_die_ref parent, child; | |
4927 | { | |
4928 | dw_die_ref *p; | |
4929 | ||
4930 | /* We want the declaration DIE from inside the class, not the | |
4931 | specification DIE at toplevel. */ | |
4932 | if (child->die_parent != parent) | |
2081603c JM |
4933 | { |
4934 | dw_die_ref tmp = get_AT_ref (child, DW_AT_specification); | |
4935 | if (tmp) | |
4936 | child = tmp; | |
4937 | } | |
10a11b75 | 4938 | |
2081603c JM |
4939 | if (child->die_parent != parent |
4940 | && child->die_parent != get_AT_ref (parent, DW_AT_specification)) | |
10a11b75 JM |
4941 | abort (); |
4942 | ||
5de0e8d4 | 4943 | for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib)) |
10a11b75 JM |
4944 | if (*p == child) |
4945 | { | |
4946 | *p = child->die_sib; | |
4947 | break; | |
4948 | } | |
4949 | ||
4950 | child->die_sib = parent->die_child; | |
4951 | parent->die_child = child; | |
4952 | } | |
4953 | ||
3f76745e JM |
4954 | /* Return a pointer to a newly created DIE node. */ |
4955 | ||
4956 | static inline dw_die_ref | |
4957 | new_die (tag_value, parent_die) | |
4958 | register enum dwarf_tag tag_value; | |
4959 | register dw_die_ref parent_die; | |
4960 | { | |
3f4907a6 | 4961 | register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node)); |
3f76745e JM |
4962 | |
4963 | die->die_tag = tag_value; | |
3f76745e JM |
4964 | |
4965 | if (parent_die != NULL) | |
4966 | add_child_die (parent_die, die); | |
4967 | else | |
ef76d03b JW |
4968 | { |
4969 | limbo_die_node *limbo_node; | |
4970 | ||
4971 | limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node)); | |
4972 | limbo_node->die = die; | |
4973 | limbo_node->next = limbo_die_list; | |
4974 | limbo_die_list = limbo_node; | |
4975 | } | |
71dfc51f | 4976 | |
3f76745e JM |
4977 | return die; |
4978 | } | |
71dfc51f | 4979 | |
3f76745e | 4980 | /* Return the DIE associated with the given type specifier. */ |
71dfc51f | 4981 | |
3f76745e JM |
4982 | static inline dw_die_ref |
4983 | lookup_type_die (type) | |
4984 | register tree type; | |
4985 | { | |
4061f623 BS |
4986 | if (TREE_CODE (type) == VECTOR_TYPE) |
4987 | type = TYPE_DEBUG_REPRESENTATION_TYPE (type); | |
3f76745e JM |
4988 | return (dw_die_ref) TYPE_SYMTAB_POINTER (type); |
4989 | } | |
e90b62db | 4990 | |
3f76745e | 4991 | /* Equate a DIE to a given type specifier. */ |
71dfc51f | 4992 | |
10a11b75 | 4993 | static inline void |
3f76745e JM |
4994 | equate_type_number_to_die (type, type_die) |
4995 | register tree type; | |
4996 | register dw_die_ref type_die; | |
4997 | { | |
4998 | TYPE_SYMTAB_POINTER (type) = (char *) type_die; | |
4999 | } | |
71dfc51f | 5000 | |
3f76745e | 5001 | /* Return the DIE associated with a given declaration. */ |
71dfc51f | 5002 | |
3f76745e JM |
5003 | static inline dw_die_ref |
5004 | lookup_decl_die (decl) | |
5005 | register tree decl; | |
5006 | { | |
5007 | register unsigned decl_id = DECL_UID (decl); | |
5008 | ||
5009 | return (decl_id < decl_die_table_in_use | |
5010 | ? decl_die_table[decl_id] : NULL); | |
a3f97cbb JW |
5011 | } |
5012 | ||
3f76745e | 5013 | /* Equate a DIE to a particular declaration. */ |
71dfc51f | 5014 | |
3f76745e JM |
5015 | static void |
5016 | equate_decl_number_to_die (decl, decl_die) | |
5017 | register tree decl; | |
5018 | register dw_die_ref decl_die; | |
a3f97cbb | 5019 | { |
3f76745e | 5020 | register unsigned decl_id = DECL_UID (decl); |
3f76745e | 5021 | register unsigned num_allocated; |
d291dd49 | 5022 | |
3f76745e | 5023 | if (decl_id >= decl_die_table_allocated) |
a3f97cbb | 5024 | { |
3f76745e JM |
5025 | num_allocated |
5026 | = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1) | |
5027 | / DECL_DIE_TABLE_INCREMENT) | |
5028 | * DECL_DIE_TABLE_INCREMENT; | |
5029 | ||
5030 | decl_die_table | |
5031 | = (dw_die_ref *) xrealloc (decl_die_table, | |
5032 | sizeof (dw_die_ref) * num_allocated); | |
5033 | ||
961192e1 | 5034 | memset ((char *) &decl_die_table[decl_die_table_allocated], 0, |
3f76745e JM |
5035 | (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref)); |
5036 | decl_die_table_allocated = num_allocated; | |
a3f97cbb | 5037 | } |
71dfc51f | 5038 | |
3f76745e JM |
5039 | if (decl_id >= decl_die_table_in_use) |
5040 | decl_die_table_in_use = (decl_id + 1); | |
5041 | ||
5042 | decl_die_table[decl_id] = decl_die; | |
a3f97cbb | 5043 | } |
3f76745e JM |
5044 | \f |
5045 | /* Keep track of the number of spaces used to indent the | |
5046 | output of the debugging routines that print the structure of | |
5047 | the DIE internal representation. */ | |
5048 | static int print_indent; | |
71dfc51f | 5049 | |
3f76745e JM |
5050 | /* Indent the line the number of spaces given by print_indent. */ |
5051 | ||
5052 | static inline void | |
5053 | print_spaces (outfile) | |
5054 | FILE *outfile; | |
5055 | { | |
5056 | fprintf (outfile, "%*s", print_indent, ""); | |
a3f97cbb JW |
5057 | } |
5058 | ||
956d6950 | 5059 | /* Print the information associated with a given DIE, and its children. |
3f76745e | 5060 | This routine is a debugging aid only. */ |
71dfc51f | 5061 | |
a3f97cbb | 5062 | static void |
3f76745e JM |
5063 | print_die (die, outfile) |
5064 | dw_die_ref die; | |
5065 | FILE *outfile; | |
a3f97cbb | 5066 | { |
3f76745e JM |
5067 | register dw_attr_ref a; |
5068 | register dw_die_ref c; | |
71dfc51f | 5069 | |
3f76745e | 5070 | print_spaces (outfile); |
2d8b0f3a | 5071 | fprintf (outfile, "DIE %4lu: %s\n", |
3f76745e JM |
5072 | die->die_offset, dwarf_tag_name (die->die_tag)); |
5073 | print_spaces (outfile); | |
2d8b0f3a JL |
5074 | fprintf (outfile, " abbrev id: %lu", die->die_abbrev); |
5075 | fprintf (outfile, " offset: %lu\n", die->die_offset); | |
3f76745e JM |
5076 | |
5077 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
a3f97cbb | 5078 | { |
3f76745e JM |
5079 | print_spaces (outfile); |
5080 | fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr)); | |
5081 | ||
a96c67ec | 5082 | switch (AT_class (a)) |
3f76745e JM |
5083 | { |
5084 | case dw_val_class_addr: | |
5085 | fprintf (outfile, "address"); | |
5086 | break; | |
a20612aa RH |
5087 | case dw_val_class_offset: |
5088 | fprintf (outfile, "offset"); | |
5089 | break; | |
3f76745e JM |
5090 | case dw_val_class_loc: |
5091 | fprintf (outfile, "location descriptor"); | |
5092 | break; | |
63e46568 | 5093 | case dw_val_class_loc_list: |
a20612aa RH |
5094 | fprintf (outfile, "location list -> label:%s", |
5095 | AT_loc_list (a)->ll_symbol); | |
63e46568 | 5096 | break; |
3f76745e | 5097 | case dw_val_class_const: |
a96c67ec | 5098 | fprintf (outfile, "%ld", AT_int (a)); |
3f76745e JM |
5099 | break; |
5100 | case dw_val_class_unsigned_const: | |
a96c67ec | 5101 | fprintf (outfile, "%lu", AT_unsigned (a)); |
3f76745e JM |
5102 | break; |
5103 | case dw_val_class_long_long: | |
2d8b0f3a | 5104 | fprintf (outfile, "constant (%lu,%lu)", |
556273e0 KH |
5105 | a->dw_attr_val.v.val_long_long.hi, |
5106 | a->dw_attr_val.v.val_long_long.low); | |
3f76745e JM |
5107 | break; |
5108 | case dw_val_class_float: | |
5109 | fprintf (outfile, "floating-point constant"); | |
5110 | break; | |
5111 | case dw_val_class_flag: | |
a96c67ec | 5112 | fprintf (outfile, "%u", AT_flag (a)); |
3f76745e JM |
5113 | break; |
5114 | case dw_val_class_die_ref: | |
a96c67ec | 5115 | if (AT_ref (a) != NULL) |
881c6935 | 5116 | { |
1bfb5f8f | 5117 | if (AT_ref (a)->die_symbol) |
881c6935 JM |
5118 | fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol); |
5119 | else | |
5120 | fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset); | |
5121 | } | |
3f76745e JM |
5122 | else |
5123 | fprintf (outfile, "die -> <null>"); | |
5124 | break; | |
5125 | case dw_val_class_lbl_id: | |
8b790721 | 5126 | case dw_val_class_lbl_offset: |
a96c67ec | 5127 | fprintf (outfile, "label: %s", AT_lbl (a)); |
3f76745e | 5128 | break; |
3f76745e | 5129 | case dw_val_class_str: |
a96c67ec JM |
5130 | if (AT_string (a) != NULL) |
5131 | fprintf (outfile, "\"%s\"", AT_string (a)); | |
3f76745e JM |
5132 | else |
5133 | fprintf (outfile, "<null>"); | |
5134 | break; | |
e9a25f70 JL |
5135 | default: |
5136 | break; | |
3f76745e JM |
5137 | } |
5138 | ||
5139 | fprintf (outfile, "\n"); | |
5140 | } | |
5141 | ||
5142 | if (die->die_child != NULL) | |
5143 | { | |
5144 | print_indent += 4; | |
5145 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5146 | print_die (c, outfile); | |
71dfc51f | 5147 | |
3f76745e | 5148 | print_indent -= 4; |
a3f97cbb | 5149 | } |
881c6935 JM |
5150 | if (print_indent == 0) |
5151 | fprintf (outfile, "\n"); | |
a3f97cbb JW |
5152 | } |
5153 | ||
3f76745e JM |
5154 | /* Print the contents of the source code line number correspondence table. |
5155 | This routine is a debugging aid only. */ | |
71dfc51f | 5156 | |
3f76745e JM |
5157 | static void |
5158 | print_dwarf_line_table (outfile) | |
5159 | FILE *outfile; | |
a3f97cbb | 5160 | { |
3f76745e JM |
5161 | register unsigned i; |
5162 | register dw_line_info_ref line_info; | |
5163 | ||
5164 | fprintf (outfile, "\n\nDWARF source line information\n"); | |
5165 | for (i = 1; i < line_info_table_in_use; ++i) | |
a3f97cbb | 5166 | { |
3f76745e JM |
5167 | line_info = &line_info_table[i]; |
5168 | fprintf (outfile, "%5d: ", i); | |
981975b6 | 5169 | fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]); |
2d8b0f3a | 5170 | fprintf (outfile, "%6ld", line_info->dw_line_num); |
3f76745e | 5171 | fprintf (outfile, "\n"); |
a3f97cbb | 5172 | } |
3f76745e JM |
5173 | |
5174 | fprintf (outfile, "\n\n"); | |
f37230f0 JM |
5175 | } |
5176 | ||
3f76745e JM |
5177 | /* Print the information collected for a given DIE. */ |
5178 | ||
5179 | void | |
5180 | debug_dwarf_die (die) | |
5181 | dw_die_ref die; | |
5182 | { | |
5183 | print_die (die, stderr); | |
5184 | } | |
5185 | ||
5186 | /* Print all DWARF information collected for the compilation unit. | |
5187 | This routine is a debugging aid only. */ | |
5188 | ||
5189 | void | |
5190 | debug_dwarf () | |
5191 | { | |
5192 | print_indent = 0; | |
5193 | print_die (comp_unit_die, stderr); | |
b2244e22 JW |
5194 | if (! DWARF2_ASM_LINE_DEBUG_INFO) |
5195 | print_dwarf_line_table (stderr); | |
3f76745e JM |
5196 | } |
5197 | \f | |
a96c67ec JM |
5198 | /* We build up the lists of children and attributes by pushing new ones |
5199 | onto the beginning of the list. Reverse the lists for DIE so that | |
5200 | they are in order of addition. */ | |
71dfc51f | 5201 | |
f37230f0 | 5202 | static void |
a96c67ec | 5203 | reverse_die_lists (die) |
3f76745e | 5204 | register dw_die_ref die; |
f37230f0 | 5205 | { |
a96c67ec JM |
5206 | register dw_die_ref c, cp, cn; |
5207 | register dw_attr_ref a, ap, an; | |
71dfc51f | 5208 | |
a96c67ec | 5209 | for (a = die->die_attr, ap = 0; a; a = an) |
7d9d8943 AM |
5210 | { |
5211 | an = a->dw_attr_next; | |
5212 | a->dw_attr_next = ap; | |
5213 | ap = a; | |
a3f97cbb | 5214 | } |
7d9d8943 | 5215 | die->die_attr = ap; |
3f76745e | 5216 | |
7d9d8943 AM |
5217 | for (c = die->die_child, cp = 0; c; c = cn) |
5218 | { | |
5219 | cn = c->die_sib; | |
5220 | c->die_sib = cp; | |
5221 | cp = c; | |
5222 | } | |
5223 | die->die_child = cp; | |
a3f97cbb JW |
5224 | } |
5225 | ||
881c6935 JM |
5226 | /* reverse_die_lists only reverses the single die you pass it. Since |
5227 | we used to reverse all dies in add_sibling_attributes, which runs | |
5228 | through all the dies, it would reverse all the dies. Now, however, | |
5229 | since we don't call reverse_die_lists in add_sibling_attributes, we | |
5230 | need a routine to recursively reverse all the dies. This is that | |
5231 | routine. */ | |
71dfc51f | 5232 | |
7d9d8943 | 5233 | static void |
881c6935 | 5234 | reverse_all_dies (die) |
7d9d8943 | 5235 | register dw_die_ref die; |
a3f97cbb | 5236 | { |
7d9d8943 | 5237 | register dw_die_ref c; |
71dfc51f | 5238 | |
7d9d8943 | 5239 | reverse_die_lists (die); |
3f76745e | 5240 | |
881c6935 JM |
5241 | for (c = die->die_child; c; c = c->die_sib) |
5242 | reverse_all_dies (c); | |
5243 | } | |
5244 | ||
5245 | /* Start a new compilation unit DIE for an include file. OLD_UNIT is | |
5246 | the CU for the enclosing include file, if any. BINCL_DIE is the | |
5247 | DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this | |
5248 | include file. */ | |
5249 | ||
5250 | static dw_die_ref | |
5251 | push_new_compile_unit (old_unit, bincl_die) | |
5252 | dw_die_ref old_unit, bincl_die; | |
5253 | { | |
5254 | const char *filename = get_AT_string (bincl_die, DW_AT_name); | |
5255 | dw_die_ref new_unit = gen_compile_unit_die (filename); | |
5256 | new_unit->die_sib = old_unit; | |
5257 | return new_unit; | |
5258 | } | |
5259 | ||
5260 | /* Close an include-file CU and reopen the enclosing one. */ | |
5261 | ||
5262 | static dw_die_ref | |
5263 | pop_compile_unit (old_unit) | |
5264 | dw_die_ref old_unit; | |
5265 | { | |
5266 | dw_die_ref new_unit = old_unit->die_sib; | |
5267 | old_unit->die_sib = NULL; | |
5268 | return new_unit; | |
5269 | } | |
5270 | ||
5271 | #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx) | |
5272 | #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx) | |
5273 | ||
5274 | /* Calculate the checksum of a location expression. */ | |
5275 | ||
5276 | static inline void | |
5277 | loc_checksum (loc, ctx) | |
5278 | dw_loc_descr_ref loc; | |
5279 | struct md5_ctx *ctx; | |
5280 | { | |
5281 | PROCESS (loc->dw_loc_opc); | |
5282 | PROCESS (loc->dw_loc_oprnd1); | |
5283 | PROCESS (loc->dw_loc_oprnd2); | |
5284 | } | |
5285 | ||
5286 | /* Calculate the checksum of an attribute. */ | |
5287 | ||
5288 | static void | |
5289 | attr_checksum (at, ctx) | |
5290 | dw_attr_ref at; | |
5291 | struct md5_ctx *ctx; | |
5292 | { | |
5293 | dw_loc_descr_ref loc; | |
5294 | rtx r; | |
5295 | ||
5296 | PROCESS (at->dw_attr); | |
5297 | ||
5298 | /* We don't care about differences in file numbering. */ | |
5f632b5e JM |
5299 | if (at->dw_attr == DW_AT_decl_file |
5300 | /* Or that this was compiled with a different compiler snapshot; if | |
5301 | the output is the same, that's what matters. */ | |
5302 | || at->dw_attr == DW_AT_producer) | |
881c6935 JM |
5303 | return; |
5304 | ||
5305 | switch (AT_class (at)) | |
5306 | { | |
5307 | case dw_val_class_const: | |
5308 | PROCESS (at->dw_attr_val.v.val_int); | |
5309 | break; | |
5310 | case dw_val_class_unsigned_const: | |
5311 | PROCESS (at->dw_attr_val.v.val_unsigned); | |
5312 | break; | |
5313 | case dw_val_class_long_long: | |
5314 | PROCESS (at->dw_attr_val.v.val_long_long); | |
5315 | break; | |
5316 | case dw_val_class_float: | |
5317 | PROCESS (at->dw_attr_val.v.val_float); | |
5318 | break; | |
5319 | case dw_val_class_flag: | |
5320 | PROCESS (at->dw_attr_val.v.val_flag); | |
5321 | break; | |
5322 | ||
5323 | case dw_val_class_str: | |
5324 | PROCESS_STRING (AT_string (at)); | |
5325 | break; | |
a20612aa | 5326 | |
881c6935 JM |
5327 | case dw_val_class_addr: |
5328 | r = AT_addr (at); | |
5329 | switch (GET_CODE (r)) | |
5330 | { | |
5331 | case SYMBOL_REF: | |
5332 | PROCESS_STRING (XSTR (r, 0)); | |
5333 | break; | |
5334 | ||
5335 | default: | |
5336 | abort (); | |
5337 | } | |
5338 | break; | |
5339 | ||
a20612aa RH |
5340 | case dw_val_class_offset: |
5341 | PROCESS (at->dw_attr_val.v.val_offset); | |
5342 | break; | |
5343 | ||
881c6935 JM |
5344 | case dw_val_class_loc: |
5345 | for (loc = AT_loc (at); loc; loc = loc->dw_loc_next) | |
5346 | loc_checksum (loc, ctx); | |
5347 | break; | |
5348 | ||
5349 | case dw_val_class_die_ref: | |
5350 | if (AT_ref (at)->die_offset) | |
5351 | PROCESS (AT_ref (at)->die_offset); | |
5352 | /* FIXME else use target die name or something. */ | |
5353 | ||
5354 | case dw_val_class_fde_ref: | |
5355 | case dw_val_class_lbl_id: | |
5356 | case dw_val_class_lbl_offset: | |
a20612aa | 5357 | break; |
881c6935 JM |
5358 | |
5359 | default: | |
5360 | break; | |
5361 | } | |
5362 | } | |
5363 | ||
5364 | /* Calculate the checksum of a DIE. */ | |
5365 | ||
5366 | static void | |
5367 | die_checksum (die, ctx) | |
5368 | dw_die_ref die; | |
5369 | struct md5_ctx *ctx; | |
5370 | { | |
5371 | dw_die_ref c; | |
5372 | dw_attr_ref a; | |
5373 | ||
5374 | PROCESS (die->die_tag); | |
5375 | ||
5376 | for (a = die->die_attr; a; a = a->dw_attr_next) | |
5377 | attr_checksum (a, ctx); | |
5378 | ||
5379 | for (c = die->die_child; c; c = c->die_sib) | |
5380 | die_checksum (c, ctx); | |
5381 | } | |
5382 | ||
5383 | #undef PROCESS | |
5384 | #undef PROCESS_STRING | |
5385 | ||
5386 | /* The prefix to attach to symbols on DIEs in the current comdat debug | |
5387 | info section. */ | |
5388 | static char *comdat_symbol_id; | |
5389 | ||
5390 | /* The index of the current symbol within the current comdat CU. */ | |
5391 | static unsigned int comdat_symbol_number; | |
5392 | ||
5393 | /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its | |
5394 | children, and set comdat_symbol_id accordingly. */ | |
5395 | ||
5396 | static void | |
5397 | compute_section_prefix (unit_die) | |
5398 | dw_die_ref unit_die; | |
5399 | { | |
0821bff7 | 5400 | char *name; |
881c6935 JM |
5401 | int i; |
5402 | unsigned char checksum[16]; | |
5403 | struct md5_ctx ctx; | |
5404 | ||
5405 | md5_init_ctx (&ctx); | |
5406 | die_checksum (unit_die, &ctx); | |
5407 | md5_finish_ctx (&ctx, checksum); | |
5408 | ||
0821bff7 AC |
5409 | { |
5410 | const char *p = lbasename (get_AT_string (unit_die, DW_AT_name)); | |
5411 | name = (char *) alloca (strlen (p) + 64); | |
5412 | sprintf (name, "%s.", p); | |
5413 | } | |
881c6935 JM |
5414 | |
5415 | clean_symbol_name (name); | |
5416 | ||
0821bff7 AC |
5417 | { |
5418 | char *p = name + strlen (name); | |
5419 | for (i = 0; i < 4; ++i) | |
5420 | { | |
5421 | sprintf (p, "%.2x", checksum[i]); | |
5422 | p += 2; | |
5423 | } | |
5424 | } | |
881c6935 JM |
5425 | |
5426 | comdat_symbol_id = unit_die->die_symbol = xstrdup (name); | |
5427 | comdat_symbol_number = 0; | |
5428 | } | |
5429 | ||
5430 | /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */ | |
5431 | ||
5432 | static int | |
5433 | is_type_die (die) | |
5434 | dw_die_ref die; | |
5435 | { | |
5436 | switch (die->die_tag) | |
5437 | { | |
5438 | case DW_TAG_array_type: | |
5439 | case DW_TAG_class_type: | |
5440 | case DW_TAG_enumeration_type: | |
5441 | case DW_TAG_pointer_type: | |
5442 | case DW_TAG_reference_type: | |
5443 | case DW_TAG_string_type: | |
5444 | case DW_TAG_structure_type: | |
5445 | case DW_TAG_subroutine_type: | |
5446 | case DW_TAG_union_type: | |
5447 | case DW_TAG_ptr_to_member_type: | |
5448 | case DW_TAG_set_type: | |
5449 | case DW_TAG_subrange_type: | |
5450 | case DW_TAG_base_type: | |
5451 | case DW_TAG_const_type: | |
5452 | case DW_TAG_file_type: | |
5453 | case DW_TAG_packed_type: | |
5454 | case DW_TAG_volatile_type: | |
5455 | return 1; | |
5456 | default: | |
5457 | return 0; | |
5458 | } | |
5459 | } | |
5460 | ||
5461 | /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU. | |
5462 | Basically, we want to choose the bits that are likely to be shared between | |
5463 | compilations (types) and leave out the bits that are specific to individual | |
5464 | compilations (functions). */ | |
5465 | ||
5466 | static int | |
5467 | is_comdat_die (c) | |
5468 | dw_die_ref c; | |
5469 | { | |
5470 | #if 1 | |
5471 | /* I think we want to leave base types and __vtbl_ptr_type in the | |
5472 | main CU, as we do for stabs. The advantage is a greater | |
5473 | likelihood of sharing between objects that don't include headers | |
5474 | in the same order (and therefore would put the base types in a | |
5475 | different comdat). jason 8/28/00 */ | |
5476 | if (c->die_tag == DW_TAG_base_type) | |
5477 | return 0; | |
5478 | ||
5479 | if (c->die_tag == DW_TAG_pointer_type | |
5480 | || c->die_tag == DW_TAG_reference_type | |
5481 | || c->die_tag == DW_TAG_const_type | |
5482 | || c->die_tag == DW_TAG_volatile_type) | |
5483 | { | |
5484 | dw_die_ref t = get_AT_ref (c, DW_AT_type); | |
5485 | return t ? is_comdat_die (t) : 0; | |
5486 | } | |
5487 | #endif | |
5488 | ||
5489 | return is_type_die (c); | |
5490 | } | |
5491 | ||
5492 | /* Returns 1 iff C is the sort of DIE that might be referred to from another | |
5493 | compilation unit. */ | |
5494 | ||
5495 | static int | |
5496 | is_symbol_die (c) | |
5497 | dw_die_ref c; | |
5498 | { | |
5499 | if (is_type_die (c)) | |
5500 | return 1; | |
63e46568 | 5501 | if (get_AT (c, DW_AT_declaration) |
881c6935 JM |
5502 | && ! get_AT (c, DW_AT_specification)) |
5503 | return 1; | |
5504 | return 0; | |
5505 | } | |
5506 | ||
5507 | static char * | |
63e46568 DB |
5508 | gen_internal_sym (prefix) |
5509 | const char *prefix; | |
881c6935 JM |
5510 | { |
5511 | char buf[256]; | |
5512 | static int label_num; | |
63e46568 | 5513 | ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++); |
881c6935 JM |
5514 | return xstrdup (buf); |
5515 | } | |
5516 | ||
5517 | /* Assign symbols to all worthy DIEs under DIE. */ | |
5518 | ||
5519 | static void | |
5520 | assign_symbol_names (die) | |
5521 | register dw_die_ref die; | |
5522 | { | |
5523 | register dw_die_ref c; | |
5524 | ||
5525 | if (is_symbol_die (die)) | |
5526 | { | |
5527 | if (comdat_symbol_id) | |
5528 | { | |
5529 | char *p = alloca (strlen (comdat_symbol_id) + 64); | |
5530 | sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX, | |
5531 | comdat_symbol_id, comdat_symbol_number++); | |
5532 | die->die_symbol = xstrdup (p); | |
5533 | } | |
5534 | else | |
63e46568 | 5535 | die->die_symbol = gen_internal_sym ("LDIE"); |
881c6935 JM |
5536 | } |
5537 | ||
5538 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5539 | assign_symbol_names (c); | |
5540 | } | |
5541 | ||
5542 | /* Traverse the DIE (which is always comp_unit_die), and set up | |
5543 | additional compilation units for each of the include files we see | |
5544 | bracketed by BINCL/EINCL. */ | |
5545 | ||
5546 | static void | |
5547 | break_out_includes (die) | |
5548 | register dw_die_ref die; | |
5549 | { | |
5550 | dw_die_ref *ptr; | |
5551 | register dw_die_ref unit = NULL; | |
5552 | limbo_die_node *node; | |
5553 | ||
5554 | for (ptr = &(die->die_child); *ptr; ) | |
5555 | { | |
5556 | register dw_die_ref c = *ptr; | |
5557 | ||
5558 | if (c->die_tag == DW_TAG_GNU_BINCL | |
5559 | || c->die_tag == DW_TAG_GNU_EINCL | |
5560 | || (unit && is_comdat_die (c))) | |
5561 | { | |
5562 | /* This DIE is for a secondary CU; remove it from the main one. */ | |
5563 | *ptr = c->die_sib; | |
5564 | ||
5565 | if (c->die_tag == DW_TAG_GNU_BINCL) | |
5566 | { | |
5567 | unit = push_new_compile_unit (unit, c); | |
5568 | free_die (c); | |
5569 | } | |
5570 | else if (c->die_tag == DW_TAG_GNU_EINCL) | |
5571 | { | |
5572 | unit = pop_compile_unit (unit); | |
5573 | free_die (c); | |
5574 | } | |
5575 | else | |
5576 | add_child_die (unit, c); | |
5577 | } | |
5578 | else | |
5579 | { | |
5580 | /* Leave this DIE in the main CU. */ | |
5581 | ptr = &(c->die_sib); | |
5582 | continue; | |
5583 | } | |
5584 | } | |
5585 | ||
5586 | #if 0 | |
5587 | /* We can only use this in debugging, since the frontend doesn't check | |
0b34cf1e | 5588 | to make sure that we leave every include file we enter. */ |
881c6935 JM |
5589 | if (unit != NULL) |
5590 | abort (); | |
5591 | #endif | |
5592 | ||
5593 | assign_symbol_names (die); | |
5594 | for (node = limbo_die_list; node; node = node->next) | |
5595 | { | |
5596 | compute_section_prefix (node->die); | |
5597 | assign_symbol_names (node->die); | |
5598 | } | |
5599 | } | |
5600 | ||
5601 | /* Traverse the DIE and add a sibling attribute if it may have the | |
5602 | effect of speeding up access to siblings. To save some space, | |
5603 | avoid generating sibling attributes for DIE's without children. */ | |
5604 | ||
5605 | static void | |
5606 | add_sibling_attributes (die) | |
5607 | register dw_die_ref die; | |
5608 | { | |
5609 | register dw_die_ref c; | |
5610 | ||
5611 | if (die->die_tag != DW_TAG_compile_unit | |
5612 | && die->die_sib && die->die_child != NULL) | |
7d9d8943 AM |
5613 | /* Add the sibling link to the front of the attribute list. */ |
5614 | add_AT_die_ref (die, DW_AT_sibling, die->die_sib); | |
5615 | ||
5616 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5617 | add_sibling_attributes (c); | |
5618 | } | |
5619 | ||
63e46568 DB |
5620 | /* Output all location lists for the DIE and it's children */ |
5621 | static void | |
5622 | output_location_lists (die) | |
5623 | register dw_die_ref die; | |
5624 | { | |
5625 | dw_die_ref c; | |
5626 | dw_attr_ref d_attr; | |
5627 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) | |
5628 | { | |
5629 | if (AT_class (d_attr) == dw_val_class_loc_list) | |
5630 | { | |
5631 | output_loc_list (AT_loc_list (d_attr)); | |
5632 | } | |
5633 | } | |
5634 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5635 | output_location_lists (c); | |
5636 | ||
5637 | } | |
7d9d8943 AM |
5638 | /* The format of each DIE (and its attribute value pairs) |
5639 | is encoded in an abbreviation table. This routine builds the | |
5640 | abbreviation table and assigns a unique abbreviation id for | |
5641 | each abbreviation entry. The children of each die are visited | |
5642 | recursively. */ | |
5643 | ||
5644 | static void | |
5645 | build_abbrev_table (die) | |
5646 | register dw_die_ref die; | |
5647 | { | |
5648 | register unsigned long abbrev_id; | |
ae0ed63a | 5649 | register unsigned int n_alloc; |
7d9d8943 AM |
5650 | register dw_die_ref c; |
5651 | register dw_attr_ref d_attr, a_attr; | |
881c6935 JM |
5652 | |
5653 | /* Scan the DIE references, and mark as external any that refer to | |
1bfb5f8f | 5654 | DIEs from other CUs (i.e. those which are not marked). */ |
881c6935 JM |
5655 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) |
5656 | { | |
5657 | if (AT_class (d_attr) == dw_val_class_die_ref | |
1bfb5f8f | 5658 | && AT_ref (d_attr)->die_mark == 0) |
881c6935 JM |
5659 | { |
5660 | if (AT_ref (d_attr)->die_symbol == 0) | |
5661 | abort (); | |
5662 | set_AT_ref_external (d_attr, 1); | |
5663 | } | |
5664 | } | |
5665 | ||
7d9d8943 AM |
5666 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
5667 | { | |
5668 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
5669 | ||
5670 | if (abbrev->die_tag == die->die_tag) | |
5671 | { | |
5672 | if ((abbrev->die_child != NULL) == (die->die_child != NULL)) | |
5673 | { | |
5674 | a_attr = abbrev->die_attr; | |
5675 | d_attr = die->die_attr; | |
5676 | ||
5677 | while (a_attr != NULL && d_attr != NULL) | |
5678 | { | |
5679 | if ((a_attr->dw_attr != d_attr->dw_attr) | |
5680 | || (value_format (a_attr) != value_format (d_attr))) | |
5681 | break; | |
5682 | ||
5683 | a_attr = a_attr->dw_attr_next; | |
5684 | d_attr = d_attr->dw_attr_next; | |
5685 | } | |
5686 | ||
5687 | if (a_attr == NULL && d_attr == NULL) | |
5688 | break; | |
5689 | } | |
5690 | } | |
5691 | } | |
5692 | ||
5693 | if (abbrev_id >= abbrev_die_table_in_use) | |
5694 | { | |
5695 | if (abbrev_die_table_in_use >= abbrev_die_table_allocated) | |
5696 | { | |
5697 | n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT; | |
556273e0 | 5698 | abbrev_die_table |
7d9d8943 AM |
5699 | = (dw_die_ref *) xrealloc (abbrev_die_table, |
5700 | sizeof (dw_die_ref) * n_alloc); | |
5701 | ||
961192e1 | 5702 | memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0, |
7d9d8943 AM |
5703 | (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref)); |
5704 | abbrev_die_table_allocated = n_alloc; | |
5705 | } | |
5706 | ||
5707 | ++abbrev_die_table_in_use; | |
5708 | abbrev_die_table[abbrev_id] = die; | |
5709 | } | |
5710 | ||
5711 | die->die_abbrev = abbrev_id; | |
5712 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5713 | build_abbrev_table (c); | |
5714 | } | |
5715 | \f | |
5716 | /* Return the size of a string, including the null byte. | |
5717 | ||
5718 | This used to treat backslashes as escapes, and hence they were not included | |
5719 | in the count. However, that conflicts with what ASM_OUTPUT_ASCII does, | |
5720 | which treats a backslash as a backslash, escaping it if necessary, and hence | |
5721 | we must include them in the count. */ | |
5722 | ||
5723 | static unsigned long | |
5724 | size_of_string (str) | |
5725 | register const char *str; | |
5726 | { | |
5727 | return strlen (str) + 1; | |
3f76745e JM |
5728 | } |
5729 | ||
5730 | /* Return the power-of-two number of bytes necessary to represent VALUE. */ | |
5731 | ||
5732 | static int | |
5733 | constant_size (value) | |
5734 | long unsigned value; | |
5735 | { | |
5736 | int log; | |
5737 | ||
5738 | if (value == 0) | |
5739 | log = 0; | |
a3f97cbb | 5740 | else |
3f76745e | 5741 | log = floor_log2 (value); |
71dfc51f | 5742 | |
3f76745e JM |
5743 | log = log / 8; |
5744 | log = 1 << (floor_log2 (log) + 1); | |
5745 | ||
5746 | return log; | |
a3f97cbb JW |
5747 | } |
5748 | ||
3f76745e JM |
5749 | /* Return the size of a DIE, as it is represented in the |
5750 | .debug_info section. */ | |
71dfc51f | 5751 | |
3f76745e JM |
5752 | static unsigned long |
5753 | size_of_die (die) | |
a3f97cbb JW |
5754 | register dw_die_ref die; |
5755 | { | |
3f76745e | 5756 | register unsigned long size = 0; |
a3f97cbb | 5757 | register dw_attr_ref a; |
71dfc51f | 5758 | |
3f76745e | 5759 | size += size_of_uleb128 (die->die_abbrev); |
a3f97cbb JW |
5760 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
5761 | { | |
a96c67ec | 5762 | switch (AT_class (a)) |
a3f97cbb JW |
5763 | { |
5764 | case dw_val_class_addr: | |
a1a4189d | 5765 | size += DWARF2_ADDR_SIZE; |
a3f97cbb | 5766 | break; |
a20612aa RH |
5767 | case dw_val_class_offset: |
5768 | size += DWARF_OFFSET_SIZE; | |
5769 | break; | |
a3f97cbb | 5770 | case dw_val_class_loc: |
3f76745e | 5771 | { |
a96c67ec | 5772 | register unsigned long lsize = size_of_locs (AT_loc (a)); |
71dfc51f | 5773 | |
3f76745e JM |
5774 | /* Block length. */ |
5775 | size += constant_size (lsize); | |
5776 | size += lsize; | |
5777 | } | |
a3f97cbb | 5778 | break; |
63e46568 DB |
5779 | case dw_val_class_loc_list: |
5780 | size += DWARF_OFFSET_SIZE; | |
5781 | break; | |
a3f97cbb | 5782 | case dw_val_class_const: |
25dd13ec | 5783 | size += size_of_sleb128 (AT_int (a)); |
a3f97cbb JW |
5784 | break; |
5785 | case dw_val_class_unsigned_const: | |
a96c67ec | 5786 | size += constant_size (AT_unsigned (a)); |
a3f97cbb | 5787 | break; |
469ac993 | 5788 | case dw_val_class_long_long: |
2e4b9b8c | 5789 | size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */ |
469ac993 JM |
5790 | break; |
5791 | case dw_val_class_float: | |
3f76745e | 5792 | size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */ |
a3f97cbb JW |
5793 | break; |
5794 | case dw_val_class_flag: | |
3f76745e | 5795 | size += 1; |
a3f97cbb JW |
5796 | break; |
5797 | case dw_val_class_die_ref: | |
3f76745e | 5798 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
5799 | break; |
5800 | case dw_val_class_fde_ref: | |
3f76745e | 5801 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
5802 | break; |
5803 | case dw_val_class_lbl_id: | |
a1a4189d | 5804 | size += DWARF2_ADDR_SIZE; |
3f76745e | 5805 | break; |
8b790721 | 5806 | case dw_val_class_lbl_offset: |
3f76745e JM |
5807 | size += DWARF_OFFSET_SIZE; |
5808 | break; | |
5809 | case dw_val_class_str: | |
a96c67ec | 5810 | size += size_of_string (AT_string (a)); |
3f76745e JM |
5811 | break; |
5812 | default: | |
5813 | abort (); | |
5814 | } | |
a3f97cbb | 5815 | } |
3f76745e JM |
5816 | |
5817 | return size; | |
a3f97cbb JW |
5818 | } |
5819 | ||
956d6950 | 5820 | /* Size the debugging information associated with a given DIE. |
3f76745e JM |
5821 | Visits the DIE's children recursively. Updates the global |
5822 | variable next_die_offset, on each time through. Uses the | |
956d6950 | 5823 | current value of next_die_offset to update the die_offset |
3f76745e | 5824 | field in each DIE. */ |
71dfc51f | 5825 | |
a3f97cbb | 5826 | static void |
3f76745e JM |
5827 | calc_die_sizes (die) |
5828 | dw_die_ref die; | |
a3f97cbb | 5829 | { |
3f76745e JM |
5830 | register dw_die_ref c; |
5831 | die->die_offset = next_die_offset; | |
5832 | next_die_offset += size_of_die (die); | |
71dfc51f | 5833 | |
3f76745e JM |
5834 | for (c = die->die_child; c != NULL; c = c->die_sib) |
5835 | calc_die_sizes (c); | |
71dfc51f | 5836 | |
3f76745e JM |
5837 | if (die->die_child != NULL) |
5838 | /* Count the null byte used to terminate sibling lists. */ | |
5839 | next_die_offset += 1; | |
a3f97cbb JW |
5840 | } |
5841 | ||
1bfb5f8f | 5842 | /* Set the marks for a die and its children. We do this so |
881c6935 | 5843 | that we know whether or not a reference needs to use FORM_ref_addr; only |
1bfb5f8f JM |
5844 | DIEs in the same CU will be marked. We used to clear out the offset |
5845 | and use that as the flag, but ran into ordering problems. */ | |
881c6935 JM |
5846 | |
5847 | static void | |
1bfb5f8f | 5848 | mark_dies (die) |
881c6935 JM |
5849 | dw_die_ref die; |
5850 | { | |
5851 | register dw_die_ref c; | |
1bfb5f8f JM |
5852 | die->die_mark = 1; |
5853 | for (c = die->die_child; c; c = c->die_sib) | |
5854 | mark_dies (c); | |
5855 | } | |
5856 | ||
5857 | /* Clear the marks for a die and its children. */ | |
5858 | ||
5859 | static void | |
5860 | unmark_dies (die) | |
5861 | dw_die_ref die; | |
5862 | { | |
5863 | register dw_die_ref c; | |
5864 | die->die_mark = 0; | |
881c6935 | 5865 | for (c = die->die_child; c; c = c->die_sib) |
1bfb5f8f | 5866 | unmark_dies (c); |
881c6935 JM |
5867 | } |
5868 | ||
3f76745e JM |
5869 | /* Return the size of the .debug_pubnames table generated for the |
5870 | compilation unit. */ | |
a94dbf2c | 5871 | |
3f76745e JM |
5872 | static unsigned long |
5873 | size_of_pubnames () | |
a94dbf2c | 5874 | { |
3f76745e JM |
5875 | register unsigned long size; |
5876 | register unsigned i; | |
469ac993 | 5877 | |
3f76745e JM |
5878 | size = DWARF_PUBNAMES_HEADER_SIZE; |
5879 | for (i = 0; i < pubname_table_in_use; ++i) | |
a94dbf2c | 5880 | { |
3f76745e JM |
5881 | register pubname_ref p = &pubname_table[i]; |
5882 | size += DWARF_OFFSET_SIZE + size_of_string (p->name); | |
a94dbf2c JM |
5883 | } |
5884 | ||
3f76745e JM |
5885 | size += DWARF_OFFSET_SIZE; |
5886 | return size; | |
a94dbf2c JM |
5887 | } |
5888 | ||
956d6950 | 5889 | /* Return the size of the information in the .debug_aranges section. */ |
469ac993 | 5890 | |
3f76745e JM |
5891 | static unsigned long |
5892 | size_of_aranges () | |
469ac993 | 5893 | { |
3f76745e | 5894 | register unsigned long size; |
469ac993 | 5895 | |
3f76745e | 5896 | size = DWARF_ARANGES_HEADER_SIZE; |
469ac993 | 5897 | |
3f76745e | 5898 | /* Count the address/length pair for this compilation unit. */ |
a1a4189d JB |
5899 | size += 2 * DWARF2_ADDR_SIZE; |
5900 | size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use; | |
469ac993 | 5901 | |
3f76745e | 5902 | /* Count the two zero words used to terminated the address range table. */ |
a1a4189d | 5903 | size += 2 * DWARF2_ADDR_SIZE; |
3f76745e JM |
5904 | return size; |
5905 | } | |
5906 | \f | |
5907 | /* Select the encoding of an attribute value. */ | |
5908 | ||
5909 | static enum dwarf_form | |
a96c67ec JM |
5910 | value_format (a) |
5911 | dw_attr_ref a; | |
3f76745e | 5912 | { |
a96c67ec | 5913 | switch (a->dw_attr_val.val_class) |
469ac993 | 5914 | { |
3f76745e JM |
5915 | case dw_val_class_addr: |
5916 | return DW_FORM_addr; | |
a20612aa RH |
5917 | case dw_val_class_offset: |
5918 | if (DWARF_OFFSET_SIZE == 4) | |
5919 | return DW_FORM_data4; | |
5920 | if (DWARF_OFFSET_SIZE == 8) | |
5921 | return DW_FORM_data8; | |
5922 | abort (); | |
63e46568 | 5923 | case dw_val_class_loc_list: |
9d2f2c45 RH |
5924 | /* FIXME: Could be DW_FORM_data8, with a > 32 bit size |
5925 | .debug_loc section */ | |
5926 | return DW_FORM_data4; | |
3f76745e | 5927 | case dw_val_class_loc: |
a96c67ec | 5928 | switch (constant_size (size_of_locs (AT_loc (a)))) |
469ac993 | 5929 | { |
3f76745e JM |
5930 | case 1: |
5931 | return DW_FORM_block1; | |
5932 | case 2: | |
5933 | return DW_FORM_block2; | |
469ac993 JM |
5934 | default: |
5935 | abort (); | |
5936 | } | |
3f76745e | 5937 | case dw_val_class_const: |
25dd13ec | 5938 | return DW_FORM_sdata; |
3f76745e | 5939 | case dw_val_class_unsigned_const: |
a96c67ec | 5940 | switch (constant_size (AT_unsigned (a))) |
3f76745e JM |
5941 | { |
5942 | case 1: | |
5943 | return DW_FORM_data1; | |
5944 | case 2: | |
5945 | return DW_FORM_data2; | |
5946 | case 4: | |
5947 | return DW_FORM_data4; | |
5948 | case 8: | |
5949 | return DW_FORM_data8; | |
5950 | default: | |
5951 | abort (); | |
5952 | } | |
5953 | case dw_val_class_long_long: | |
5954 | return DW_FORM_block1; | |
5955 | case dw_val_class_float: | |
5956 | return DW_FORM_block1; | |
5957 | case dw_val_class_flag: | |
5958 | return DW_FORM_flag; | |
5959 | case dw_val_class_die_ref: | |
881c6935 JM |
5960 | if (AT_ref_external (a)) |
5961 | return DW_FORM_ref_addr; | |
5962 | else | |
5963 | return DW_FORM_ref; | |
3f76745e JM |
5964 | case dw_val_class_fde_ref: |
5965 | return DW_FORM_data; | |
5966 | case dw_val_class_lbl_id: | |
5967 | return DW_FORM_addr; | |
8b790721 | 5968 | case dw_val_class_lbl_offset: |
3f76745e JM |
5969 | return DW_FORM_data; |
5970 | case dw_val_class_str: | |
5971 | return DW_FORM_string; | |
a20612aa | 5972 | |
469ac993 JM |
5973 | default: |
5974 | abort (); | |
5975 | } | |
a94dbf2c JM |
5976 | } |
5977 | ||
3f76745e | 5978 | /* Output the encoding of an attribute value. */ |
469ac993 | 5979 | |
3f76745e | 5980 | static void |
a96c67ec JM |
5981 | output_value_format (a) |
5982 | dw_attr_ref a; | |
a94dbf2c | 5983 | { |
a96c67ec | 5984 | enum dwarf_form form = value_format (a); |
2e4b9b8c | 5985 | dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form)); |
3f76745e | 5986 | } |
469ac993 | 5987 | |
3f76745e JM |
5988 | /* Output the .debug_abbrev section which defines the DIE abbreviation |
5989 | table. */ | |
469ac993 | 5990 | |
3f76745e JM |
5991 | static void |
5992 | output_abbrev_section () | |
5993 | { | |
5994 | unsigned long abbrev_id; | |
71dfc51f | 5995 | |
3f76745e JM |
5996 | dw_attr_ref a_attr; |
5997 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) | |
5998 | { | |
5999 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
71dfc51f | 6000 | |
2e4b9b8c | 6001 | dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)"); |
469ac993 | 6002 | |
2e4b9b8c RH |
6003 | dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)", |
6004 | dwarf_tag_name (abbrev->die_tag)); | |
71dfc51f | 6005 | |
2e4b9b8c RH |
6006 | if (abbrev->die_child != NULL) |
6007 | dw2_asm_output_data (1, DW_children_yes, "DW_children_yes"); | |
6008 | else | |
6009 | dw2_asm_output_data (1, DW_children_no, "DW_children_no"); | |
3f76745e JM |
6010 | |
6011 | for (a_attr = abbrev->die_attr; a_attr != NULL; | |
6012 | a_attr = a_attr->dw_attr_next) | |
6013 | { | |
2e4b9b8c RH |
6014 | dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)", |
6015 | dwarf_attr_name (a_attr->dw_attr)); | |
a96c67ec | 6016 | output_value_format (a_attr); |
469ac993 | 6017 | } |
469ac993 | 6018 | |
2e4b9b8c RH |
6019 | dw2_asm_output_data (1, 0, NULL); |
6020 | dw2_asm_output_data (1, 0, NULL); | |
469ac993 | 6021 | } |
81f374eb HPN |
6022 | |
6023 | /* Terminate the table. */ | |
2e4b9b8c | 6024 | dw2_asm_output_data (1, 0, NULL); |
a94dbf2c JM |
6025 | } |
6026 | ||
881c6935 JM |
6027 | /* Output a symbol we can use to refer to this DIE from another CU. */ |
6028 | ||
6029 | static inline void | |
6030 | output_die_symbol (die) | |
6031 | register dw_die_ref die; | |
6032 | { | |
6033 | char *sym = die->die_symbol; | |
6034 | ||
6035 | if (sym == 0) | |
6036 | return; | |
6037 | ||
6038 | if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0) | |
6039 | /* We make these global, not weak; if the target doesn't support | |
6040 | .linkonce, it doesn't support combining the sections, so debugging | |
6041 | will break. */ | |
6042 | ASM_GLOBALIZE_LABEL (asm_out_file, sym); | |
6043 | ASM_OUTPUT_LABEL (asm_out_file, sym); | |
6044 | } | |
6045 | ||
84a5b4f8 DB |
6046 | /* Return a new location list, given the begin and end range, and the |
6047 | expression. gensym tells us whether to generate a new internal | |
6048 | symbol for this location list node, which is done for the head of | |
6049 | the list only. */ | |
6050 | static inline dw_loc_list_ref | |
6051 | new_loc_list (expr, begin, end, section, gensym) | |
6052 | register dw_loc_descr_ref expr; | |
6053 | register const char *begin; | |
6054 | register const char *end; | |
6055 | register const char *section; | |
6056 | register unsigned gensym; | |
6057 | { | |
6058 | register dw_loc_list_ref retlist | |
6059 | = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node)); | |
6060 | retlist->begin = begin; | |
6061 | retlist->end = end; | |
6062 | retlist->expr = expr; | |
6063 | retlist->section = section; | |
6064 | if (gensym) | |
6065 | retlist->ll_symbol = gen_internal_sym ("LLST"); | |
6066 | return retlist; | |
6067 | } | |
6068 | ||
6069 | /* Add a location description expression to a location list */ | |
6070 | static inline void | |
6071 | add_loc_descr_to_loc_list (list_head, descr, begin, end, section) | |
6072 | register dw_loc_list_ref *list_head; | |
6073 | register dw_loc_descr_ref descr; | |
6074 | register const char *begin; | |
6075 | register const char *end; | |
6076 | register const char *section; | |
6077 | { | |
6078 | register dw_loc_list_ref *d; | |
6079 | ||
6080 | /* Find the end of the chain. */ | |
6081 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
6082 | ; | |
6083 | /* Add a new location list node to the list */ | |
6084 | *d = new_loc_list (descr, begin, end, section, 0); | |
6085 | } | |
6086 | ||
63e46568 DB |
6087 | /* Output the location list given to us */ |
6088 | static void | |
6089 | output_loc_list (list_head) | |
6090 | register dw_loc_list_ref list_head; | |
6091 | { | |
84a5b4f8 | 6092 | register dw_loc_list_ref curr=list_head; |
63e46568 | 6093 | ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol); |
a20612aa RH |
6094 | |
6095 | /* ??? This shouldn't be needed now that we've forced the | |
6096 | compilation unit base address to zero when there is code | |
6097 | in more than one section. */ | |
63e46568 DB |
6098 | if (strcmp (curr->section, ".text") == 0) |
6099 | { | |
aafdcfcd NS |
6100 | /* dw2_asm_output_data will mask off any extra bits in the ~0. */ |
6101 | dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT)0, | |
6102 | "Location list base address specifier fake entry"); | |
6103 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section, | |
6104 | "Location list base address specifier base"); | |
63e46568 DB |
6105 | } |
6106 | for (curr = list_head; curr != NULL; curr=curr->dw_loc_next) | |
6107 | { | |
6108 | int size; | |
aafdcfcd NS |
6109 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section, |
6110 | "Location list begin address (%s)", | |
6111 | list_head->ll_symbol); | |
6112 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section, | |
6113 | "Location list end address (%s)", | |
6114 | list_head->ll_symbol); | |
63e46568 DB |
6115 | size = size_of_locs (curr->expr); |
6116 | ||
6117 | /* Output the block length for this list of location operations. */ | |
aafdcfcd NS |
6118 | dw2_asm_output_data (constant_size (size), size, "%s", |
6119 | "Location expression size"); | |
63e46568 DB |
6120 | |
6121 | output_loc_sequence (curr->expr); | |
6122 | } | |
aafdcfcd NS |
6123 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, |
6124 | "Location list terminator begin (%s)", | |
6125 | list_head->ll_symbol); | |
6126 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, | |
6127 | "Location list terminator end (%s)", | |
6128 | list_head->ll_symbol); | |
63e46568 | 6129 | } |
3f76745e JM |
6130 | /* Output the DIE and its attributes. Called recursively to generate |
6131 | the definitions of each child DIE. */ | |
71dfc51f | 6132 | |
a3f97cbb | 6133 | static void |
3f76745e JM |
6134 | output_die (die) |
6135 | register dw_die_ref die; | |
a3f97cbb | 6136 | { |
3f76745e JM |
6137 | register dw_attr_ref a; |
6138 | register dw_die_ref c; | |
3f76745e | 6139 | register unsigned long size; |
a94dbf2c | 6140 | |
881c6935 JM |
6141 | /* If someone in another CU might refer to us, set up a symbol for |
6142 | them to point to. */ | |
6143 | if (die->die_symbol) | |
6144 | output_die_symbol (die); | |
6145 | ||
2e4b9b8c RH |
6146 | dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)", |
6147 | die->die_offset, dwarf_tag_name (die->die_tag)); | |
a94dbf2c | 6148 | |
3f76745e | 6149 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
a3f97cbb | 6150 | { |
2e4b9b8c RH |
6151 | const char *name = dwarf_attr_name (a->dw_attr); |
6152 | ||
a96c67ec | 6153 | switch (AT_class (a)) |
3f76745e JM |
6154 | { |
6155 | case dw_val_class_addr: | |
2e4b9b8c | 6156 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name); |
3f76745e | 6157 | break; |
a3f97cbb | 6158 | |
a20612aa RH |
6159 | case dw_val_class_offset: |
6160 | dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset, | |
6161 | "%s", name); | |
6162 | break; | |
6163 | ||
3f76745e | 6164 | case dw_val_class_loc: |
a96c67ec | 6165 | size = size_of_locs (AT_loc (a)); |
71dfc51f | 6166 | |
3f76745e | 6167 | /* Output the block length for this list of location operations. */ |
2e4b9b8c | 6168 | dw2_asm_output_data (constant_size (size), size, "%s", name); |
71dfc51f | 6169 | |
7d9d8943 | 6170 | output_loc_sequence (AT_loc (a)); |
a3f97cbb | 6171 | break; |
3f76745e JM |
6172 | |
6173 | case dw_val_class_const: | |
25dd13ec JW |
6174 | /* ??? It would be slightly more efficient to use a scheme like is |
6175 | used for unsigned constants below, but gdb 4.x does not sign | |
6176 | extend. Gdb 5.x does sign extend. */ | |
2e4b9b8c | 6177 | dw2_asm_output_data_sleb128 (AT_int (a), "%s", name); |
a3f97cbb | 6178 | break; |
3f76745e JM |
6179 | |
6180 | case dw_val_class_unsigned_const: | |
2e4b9b8c RH |
6181 | dw2_asm_output_data (constant_size (AT_unsigned (a)), |
6182 | AT_unsigned (a), "%s", name); | |
a3f97cbb | 6183 | break; |
3f76745e JM |
6184 | |
6185 | case dw_val_class_long_long: | |
2e4b9b8c RH |
6186 | { |
6187 | unsigned HOST_WIDE_INT first, second; | |
3f76745e | 6188 | |
2e4b9b8c RH |
6189 | dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR, |
6190 | "%s", name); | |
556273e0 | 6191 | |
2e4b9b8c RH |
6192 | if (WORDS_BIG_ENDIAN) |
6193 | { | |
6194 | first = a->dw_attr_val.v.val_long_long.hi; | |
6195 | second = a->dw_attr_val.v.val_long_long.low; | |
6196 | } | |
6197 | else | |
6198 | { | |
6199 | first = a->dw_attr_val.v.val_long_long.low; | |
6200 | second = a->dw_attr_val.v.val_long_long.hi; | |
6201 | } | |
6202 | dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR, | |
6203 | first, "long long constant"); | |
6204 | dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR, | |
6205 | second, NULL); | |
6206 | } | |
a3f97cbb | 6207 | break; |
3f76745e JM |
6208 | |
6209 | case dw_val_class_float: | |
c84e2712 KG |
6210 | { |
6211 | register unsigned int i; | |
c84e2712 | 6212 | |
2e4b9b8c RH |
6213 | dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4, |
6214 | "%s", name); | |
c84e2712 | 6215 | |
2e4b9b8c RH |
6216 | for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i) |
6217 | dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i], | |
6218 | "fp constant word %u", i); | |
556273e0 | 6219 | break; |
c84e2712 | 6220 | } |
3f76745e JM |
6221 | |
6222 | case dw_val_class_flag: | |
2e4b9b8c | 6223 | dw2_asm_output_data (1, AT_flag (a), "%s", name); |
a3f97cbb | 6224 | break; |
a20612aa | 6225 | |
63e46568 DB |
6226 | case dw_val_class_loc_list: |
6227 | { | |
6228 | char *sym = AT_loc_list (a)->ll_symbol; | |
6229 | if (sym == 0) | |
6230 | abort(); | |
a20612aa RH |
6231 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, |
6232 | loc_section_label, "%s", name); | |
63e46568 DB |
6233 | } |
6234 | break; | |
a20612aa | 6235 | |
3f76745e | 6236 | case dw_val_class_die_ref: |
881c6935 | 6237 | if (AT_ref_external (a)) |
2e4b9b8c RH |
6238 | { |
6239 | char *sym = AT_ref (a)->die_symbol; | |
6240 | if (sym == 0) | |
6241 | abort (); | |
6242 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name); | |
6243 | } | |
3f4907a6 JM |
6244 | else if (AT_ref (a)->die_offset == 0) |
6245 | abort (); | |
881c6935 | 6246 | else |
2e4b9b8c RH |
6247 | dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset, |
6248 | "%s", name); | |
a3f97cbb | 6249 | break; |
3f76745e JM |
6250 | |
6251 | case dw_val_class_fde_ref: | |
a6ab3aad JM |
6252 | { |
6253 | char l1[20]; | |
2e4b9b8c RH |
6254 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL, |
6255 | a->dw_attr_val.v.val_fde_index * 2); | |
6256 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name); | |
a6ab3aad | 6257 | } |
a3f97cbb | 6258 | break; |
a3f97cbb | 6259 | |
3f76745e | 6260 | case dw_val_class_lbl_id: |
8e7fa2c8 | 6261 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 6262 | break; |
71dfc51f | 6263 | |
8b790721 | 6264 | case dw_val_class_lbl_offset: |
2e4b9b8c | 6265 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 6266 | break; |
a3f97cbb | 6267 | |
3f76745e | 6268 | case dw_val_class_str: |
2e4b9b8c | 6269 | dw2_asm_output_nstring (AT_string (a), -1, "%s", name); |
3f76745e | 6270 | break; |
b2932ae5 | 6271 | |
3f76745e JM |
6272 | default: |
6273 | abort (); | |
6274 | } | |
3f76745e | 6275 | } |
71dfc51f | 6276 | |
3f76745e JM |
6277 | for (c = die->die_child; c != NULL; c = c->die_sib) |
6278 | output_die (c); | |
71dfc51f | 6279 | |
3f76745e | 6280 | if (die->die_child != NULL) |
7e23cb16 | 6281 | { |
556273e0 | 6282 | /* Add null byte to terminate sibling list. */ |
2e4b9b8c RH |
6283 | dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx", |
6284 | die->die_offset); | |
7e23cb16 | 6285 | } |
3f76745e | 6286 | } |
71dfc51f | 6287 | |
3f76745e JM |
6288 | /* Output the compilation unit that appears at the beginning of the |
6289 | .debug_info section, and precedes the DIE descriptions. */ | |
71dfc51f | 6290 | |
3f76745e JM |
6291 | static void |
6292 | output_compilation_unit_header () | |
6293 | { | |
2e4b9b8c RH |
6294 | dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE, |
6295 | "Length of Compilation Unit Info"); | |
71dfc51f | 6296 | |
2e4b9b8c | 6297 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number"); |
71dfc51f | 6298 | |
2e4b9b8c RH |
6299 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label, |
6300 | "Offset Into Abbrev. Section"); | |
71dfc51f | 6301 | |
2e4b9b8c | 6302 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)"); |
a3f97cbb JW |
6303 | } |
6304 | ||
881c6935 JM |
6305 | /* Output the compilation unit DIE and its children. */ |
6306 | ||
6307 | static void | |
6308 | output_comp_unit (die) | |
6309 | dw_die_ref die; | |
6310 | { | |
ce1cc601 | 6311 | const char *secname; |
881c6935 | 6312 | |
db3c0315 MM |
6313 | /* Even if there are no children of this DIE, we must output the |
6314 | information about the compilation unit. Otherwise, on an empty | |
6315 | translation unit, we will generate a present, but empty, | |
6316 | .debug_info section. IRIX 6.5 `nm' will then complain when | |
6317 | examining the file. | |
6318 | ||
6319 | Mark all the DIEs in this CU so we know which get local refs. */ | |
1bfb5f8f JM |
6320 | mark_dies (die); |
6321 | ||
6322 | build_abbrev_table (die); | |
6323 | ||
881c6935 JM |
6324 | /* Initialize the beginning DIE offset - and calculate sizes/offsets. */ |
6325 | next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE; | |
6326 | calc_die_sizes (die); | |
6327 | ||
881c6935 JM |
6328 | if (die->die_symbol) |
6329 | { | |
ce1cc601 KG |
6330 | char *tmp = (char *) alloca (strlen (die->die_symbol) + 24); |
6331 | sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol); | |
6332 | secname = tmp; | |
881c6935 JM |
6333 | die->die_symbol = NULL; |
6334 | } | |
6335 | else | |
ce1cc601 | 6336 | secname = (const char *) DEBUG_INFO_SECTION; |
881c6935 JM |
6337 | |
6338 | /* Output debugging information. */ | |
881c6935 JM |
6339 | ASM_OUTPUT_SECTION (asm_out_file, secname); |
6340 | output_compilation_unit_header (); | |
6341 | output_die (die); | |
6342 | ||
1bfb5f8f JM |
6343 | /* Leave the marks on the main CU, so we can check them in |
6344 | output_pubnames. */ | |
881c6935 | 6345 | if (die->die_symbol) |
1bfb5f8f | 6346 | unmark_dies (die); |
881c6935 JM |
6347 | } |
6348 | ||
a1d7ffe3 JM |
6349 | /* The DWARF2 pubname for a nested thingy looks like "A::f". The output |
6350 | of decl_printable_name for C++ looks like "A::f(int)". Let's drop the | |
6351 | argument list, and maybe the scope. */ | |
6352 | ||
d560ee52 | 6353 | static const char * |
a1d7ffe3 JM |
6354 | dwarf2_name (decl, scope) |
6355 | tree decl; | |
6356 | int scope; | |
6357 | { | |
6358 | return (*decl_printable_name) (decl, scope ? 1 : 0); | |
6359 | } | |
6360 | ||
d291dd49 | 6361 | /* Add a new entry to .debug_pubnames if appropriate. */ |
71dfc51f | 6362 | |
d291dd49 JM |
6363 | static void |
6364 | add_pubname (decl, die) | |
6365 | tree decl; | |
6366 | dw_die_ref die; | |
6367 | { | |
6368 | pubname_ref p; | |
6369 | ||
6370 | if (! TREE_PUBLIC (decl)) | |
6371 | return; | |
6372 | ||
6373 | if (pubname_table_in_use == pubname_table_allocated) | |
6374 | { | |
6375 | pubname_table_allocated += PUBNAME_TABLE_INCREMENT; | |
6376 | pubname_table = (pubname_ref) xrealloc | |
6377 | (pubname_table, pubname_table_allocated * sizeof (pubname_entry)); | |
6378 | } | |
71dfc51f | 6379 | |
d291dd49 JM |
6380 | p = &pubname_table[pubname_table_in_use++]; |
6381 | p->die = die; | |
a1d7ffe3 JM |
6382 | |
6383 | p->name = xstrdup (dwarf2_name (decl, 1)); | |
d291dd49 JM |
6384 | } |
6385 | ||
a3f97cbb JW |
6386 | /* Output the public names table used to speed up access to externally |
6387 | visible names. For now, only generate entries for externally | |
6388 | visible procedures. */ | |
71dfc51f | 6389 | |
a3f97cbb JW |
6390 | static void |
6391 | output_pubnames () | |
6392 | { | |
d291dd49 | 6393 | register unsigned i; |
71dfc51f RK |
6394 | register unsigned long pubnames_length = size_of_pubnames (); |
6395 | ||
2e4b9b8c RH |
6396 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, |
6397 | "Length of Public Names Info"); | |
71dfc51f | 6398 | |
2e4b9b8c | 6399 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
71dfc51f | 6400 | |
2e4b9b8c RH |
6401 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
6402 | "Offset of Compilation Unit Info"); | |
71dfc51f | 6403 | |
2e4b9b8c RH |
6404 | dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset, |
6405 | "Compilation Unit Length"); | |
71dfc51f | 6406 | |
d291dd49 | 6407 | for (i = 0; i < pubname_table_in_use; ++i) |
a3f97cbb | 6408 | { |
d291dd49 | 6409 | register pubname_ref pub = &pubname_table[i]; |
71dfc51f | 6410 | |
881c6935 | 6411 | /* We shouldn't see pubnames for DIEs outside of the main CU. */ |
1bfb5f8f | 6412 | if (pub->die->die_mark == 0) |
881c6935 JM |
6413 | abort (); |
6414 | ||
2e4b9b8c RH |
6415 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset, |
6416 | "DIE offset"); | |
71dfc51f | 6417 | |
2e4b9b8c | 6418 | dw2_asm_output_nstring (pub->name, -1, "external name"); |
a3f97cbb | 6419 | } |
71dfc51f | 6420 | |
2e4b9b8c | 6421 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL); |
a3f97cbb JW |
6422 | } |
6423 | ||
d291dd49 | 6424 | /* Add a new entry to .debug_aranges if appropriate. */ |
71dfc51f | 6425 | |
d291dd49 JM |
6426 | static void |
6427 | add_arange (decl, die) | |
6428 | tree decl; | |
6429 | dw_die_ref die; | |
6430 | { | |
6431 | if (! DECL_SECTION_NAME (decl)) | |
6432 | return; | |
6433 | ||
6434 | if (arange_table_in_use == arange_table_allocated) | |
6435 | { | |
6436 | arange_table_allocated += ARANGE_TABLE_INCREMENT; | |
a20612aa RH |
6437 | arange_table = (dw_die_ref *) |
6438 | xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref)); | |
d291dd49 | 6439 | } |
71dfc51f | 6440 | |
d291dd49 JM |
6441 | arange_table[arange_table_in_use++] = die; |
6442 | } | |
6443 | ||
a3f97cbb JW |
6444 | /* Output the information that goes into the .debug_aranges table. |
6445 | Namely, define the beginning and ending address range of the | |
6446 | text section generated for this compilation unit. */ | |
71dfc51f | 6447 | |
a3f97cbb JW |
6448 | static void |
6449 | output_aranges () | |
6450 | { | |
d291dd49 | 6451 | register unsigned i; |
71dfc51f RK |
6452 | register unsigned long aranges_length = size_of_aranges (); |
6453 | ||
2e4b9b8c RH |
6454 | dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length, |
6455 | "Length of Address Ranges Info"); | |
71dfc51f | 6456 | |
2e4b9b8c | 6457 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
71dfc51f | 6458 | |
2e4b9b8c RH |
6459 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
6460 | "Offset of Compilation Unit Info"); | |
71dfc51f | 6461 | |
2e4b9b8c | 6462 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address"); |
71dfc51f | 6463 | |
2e4b9b8c | 6464 | dw2_asm_output_data (1, 0, "Size of Segment Descriptor"); |
71dfc51f | 6465 | |
262b6384 SC |
6466 | /* We need to align to twice the pointer size here. */ |
6467 | if (DWARF_ARANGES_PAD_SIZE) | |
6468 | { | |
2e4b9b8c RH |
6469 | /* Pad using a 2 byte words so that padding is correct for any |
6470 | pointer size. */ | |
6471 | dw2_asm_output_data (2, 0, "Pad to %d byte boundary", | |
6472 | 2 * DWARF2_ADDR_SIZE); | |
770ca8c6 | 6473 | for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2) |
2e4b9b8c | 6474 | dw2_asm_output_data (2, 0, NULL); |
262b6384 | 6475 | } |
71dfc51f | 6476 | |
8e7fa2c8 | 6477 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address"); |
2e4b9b8c RH |
6478 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label, |
6479 | text_section_label, "Length"); | |
71dfc51f | 6480 | |
d291dd49 JM |
6481 | for (i = 0; i < arange_table_in_use; ++i) |
6482 | { | |
e689ae67 | 6483 | dw_die_ref die = arange_table[i]; |
71dfc51f | 6484 | |
881c6935 | 6485 | /* We shouldn't see aranges for DIEs outside of the main CU. */ |
1bfb5f8f | 6486 | if (die->die_mark == 0) |
881c6935 JM |
6487 | abort (); |
6488 | ||
e689ae67 | 6489 | if (die->die_tag == DW_TAG_subprogram) |
2e4b9b8c | 6490 | { |
8e7fa2c8 | 6491 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die), |
2e4b9b8c RH |
6492 | "Address"); |
6493 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die), | |
6494 | get_AT_low_pc (die), "Length"); | |
6495 | } | |
d291dd49 | 6496 | else |
a1d7ffe3 | 6497 | { |
e689ae67 JM |
6498 | /* A static variable; extract the symbol from DW_AT_location. |
6499 | Note that this code isn't currently hit, as we only emit | |
6500 | aranges for functions (jason 9/23/99). */ | |
71dfc51f | 6501 | |
e689ae67 JM |
6502 | dw_attr_ref a = get_AT (die, DW_AT_location); |
6503 | dw_loc_descr_ref loc; | |
a96c67ec | 6504 | if (! a || AT_class (a) != dw_val_class_loc) |
e689ae67 JM |
6505 | abort (); |
6506 | ||
a96c67ec | 6507 | loc = AT_loc (a); |
e689ae67 JM |
6508 | if (loc->dw_loc_opc != DW_OP_addr) |
6509 | abort (); | |
6510 | ||
2e4b9b8c RH |
6511 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, |
6512 | loc->dw_loc_oprnd1.v.val_addr, "Address"); | |
6513 | dw2_asm_output_data (DWARF2_ADDR_SIZE, | |
6514 | get_AT_unsigned (die, DW_AT_byte_size), | |
6515 | "Length"); | |
a1d7ffe3 | 6516 | } |
d291dd49 | 6517 | } |
71dfc51f | 6518 | |
a3f97cbb | 6519 | /* Output the terminator words. */ |
2e4b9b8c RH |
6520 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); |
6521 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
a3f97cbb JW |
6522 | } |
6523 | ||
a20612aa RH |
6524 | /* Add a new entry to .debug_ranges. Return the offset at which it |
6525 | was placed. */ | |
6526 | ||
6527 | static unsigned int | |
6528 | add_ranges (block) | |
6529 | tree block; | |
6530 | { | |
6531 | unsigned int in_use = ranges_table_in_use; | |
6532 | ||
6533 | if (in_use == ranges_table_allocated) | |
6534 | { | |
6535 | ranges_table_allocated += RANGES_TABLE_INCREMENT; | |
6536 | ranges_table = (dw_ranges_ref) | |
6537 | xrealloc (ranges_table, (ranges_table_allocated | |
6538 | * sizeof (struct dw_ranges_struct))); | |
6539 | } | |
6540 | ||
6541 | ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0); | |
6542 | ranges_table_in_use = in_use + 1; | |
6543 | ||
6544 | return in_use * 2 * DWARF2_ADDR_SIZE; | |
6545 | } | |
6546 | ||
6547 | static void | |
6548 | output_ranges () | |
6549 | { | |
6550 | register unsigned i; | |
6551 | const char *start_fmt = "Offset 0x%x"; | |
6552 | const char *fmt = start_fmt; | |
6553 | ||
6554 | for (i = 0; i < ranges_table_in_use; ++i) | |
6555 | { | |
6556 | int block_num = ranges_table[i].block_num; | |
6557 | ||
6558 | if (block_num) | |
6559 | { | |
6560 | char blabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6561 | char elabel[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6562 | ||
6563 | ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num); | |
6564 | ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num); | |
6565 | ||
6566 | /* If all code is in the text section, then the compilation | |
6567 | unit base address defaults to DW_AT_low_pc, which is the | |
6568 | base of the text section. */ | |
6569 | if (separate_line_info_table_in_use == 0) | |
6570 | { | |
6571 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel, | |
6572 | text_section_label, | |
6573 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
6574 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel, | |
6575 | text_section_label, NULL); | |
6576 | } | |
6577 | /* Otherwise, we add a DW_AT_entry_pc attribute to force the | |
6578 | compilation unit base address to zero, which allows us to | |
6579 | use absolute addresses, and not worry about whether the | |
6580 | target supports cross-section arithmetic. */ | |
6581 | else | |
6582 | { | |
6583 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel, | |
6584 | fmt, i * 2 * DWARF2_ADDR_SIZE); | |
6585 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL); | |
6586 | } | |
6587 | ||
6588 | fmt = NULL; | |
6589 | } | |
6590 | else | |
6591 | { | |
6592 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
6593 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
6594 | fmt = start_fmt; | |
6595 | } | |
6596 | } | |
6597 | } | |
0b34cf1e UD |
6598 | |
6599 | /* Data structure containing information about input files. */ | |
6600 | struct file_info | |
6601 | { | |
6602 | char *path; /* Complete file name. */ | |
6603 | char *fname; /* File name part. */ | |
6604 | int length; /* Length of entire string. */ | |
6605 | int file_idx; /* Index in input file table. */ | |
6606 | int dir_idx; /* Index in directory table. */ | |
6607 | }; | |
6608 | ||
6609 | /* Data structure containing information about directories with source | |
6610 | files. */ | |
6611 | struct dir_info | |
6612 | { | |
6613 | char *path; /* Path including directory name. */ | |
6614 | int length; /* Path length. */ | |
6615 | int prefix; /* Index of directory entry which is a prefix. */ | |
0b34cf1e UD |
6616 | int count; /* Number of files in this directory. */ |
6617 | int dir_idx; /* Index of directory used as base. */ | |
6618 | int used; /* Used in the end? */ | |
6619 | }; | |
6620 | ||
6621 | /* Callback function for file_info comparison. We sort by looking at | |
6622 | the directories in the path. */ | |
6623 | static int | |
6624 | file_info_cmp (p1, p2) | |
6625 | const void *p1; | |
6626 | const void *p2; | |
6627 | { | |
6628 | const struct file_info *s1 = p1; | |
6629 | const struct file_info *s2 = p2; | |
6630 | unsigned char *cp1; | |
6631 | unsigned char *cp2; | |
6632 | ||
6633 | /* Take care of file names without directories. */ | |
6634 | if (s1->path == s1->fname) | |
6635 | return -1; | |
6636 | else if (s2->path == s2->fname) | |
6637 | return 1; | |
6638 | ||
6639 | cp1 = (unsigned char *) s1->path; | |
6640 | cp2 = (unsigned char *) s2->path; | |
6641 | ||
6642 | while (1) | |
6643 | { | |
6644 | ++cp1; | |
6645 | ++cp2; | |
6646 | /* Reached the end of the first path? */ | |
6647 | if (cp1 == (unsigned char *) s1->fname) | |
6648 | /* It doesn't really matter in which order files from the | |
6649 | same directory are sorted in. Therefore don't test for | |
6650 | the second path reaching the end. */ | |
6651 | return -1; | |
6652 | else if (cp2 == (unsigned char *) s2->fname) | |
6653 | return 1; | |
6654 | ||
6655 | /* Character of current path component the same? */ | |
6656 | if (*cp1 != *cp2) | |
6657 | return *cp1 - *cp2; | |
6658 | } | |
6659 | } | |
6660 | ||
6661 | /* Output the directory table and the file name table. We try to minimize | |
6662 | the total amount of memory needed. A heuristic is used to avoid large | |
6663 | slowdowns with many input files. */ | |
6664 | static void | |
6665 | output_file_names () | |
6666 | { | |
6667 | struct file_info *files; | |
6668 | struct dir_info *dirs; | |
6669 | int *saved; | |
6670 | int *savehere; | |
6671 | int *backmap; | |
6672 | int ndirs; | |
6673 | int idx_offset; | |
6674 | int i; | |
6675 | int idx; | |
6676 | ||
6677 | /* Allocate the various arrays we need. */ | |
981975b6 | 6678 | files = (struct file_info *) alloca (file_table.in_use |
0b34cf1e | 6679 | * sizeof (struct file_info)); |
981975b6 | 6680 | dirs = (struct dir_info *) alloca (file_table.in_use |
0b34cf1e UD |
6681 | * sizeof (struct dir_info)); |
6682 | ||
6683 | /* Sort the file names. */ | |
981975b6 | 6684 | for (i = 1; i < (int) file_table.in_use; ++i) |
0b34cf1e UD |
6685 | { |
6686 | char *f; | |
6687 | ||
6688 | /* Skip all leading "./". */ | |
981975b6 | 6689 | f = file_table.table[i]; |
0b34cf1e UD |
6690 | while (f[0] == '.' && f[1] == '/') |
6691 | f += 2; | |
6692 | ||
6693 | /* Create a new array entry. */ | |
6694 | files[i].path = f; | |
6695 | files[i].length = strlen (f); | |
6696 | files[i].file_idx = i; | |
6697 | ||
6698 | /* Search for the file name part. */ | |
6699 | f = strrchr (f, '/'); | |
6700 | files[i].fname = f == NULL ? files[i].path : f + 1; | |
6701 | } | |
981975b6 | 6702 | qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp); |
0b34cf1e UD |
6703 | |
6704 | /* Find all the different directories used. */ | |
6705 | dirs[0].path = files[1].path; | |
6706 | dirs[0].length = files[1].fname - files[1].path; | |
6707 | dirs[0].prefix = -1; | |
0b34cf1e UD |
6708 | dirs[0].count = 1; |
6709 | dirs[0].dir_idx = 0; | |
6710 | dirs[0].used = 0; | |
6711 | files[1].dir_idx = 0; | |
6712 | ndirs = 1; | |
6713 | ||
981975b6 | 6714 | for (i = 2; i < (int) file_table.in_use; ++i) |
0b34cf1e UD |
6715 | if (files[i].fname - files[i].path == dirs[ndirs - 1].length |
6716 | && memcmp (dirs[ndirs - 1].path, files[i].path, | |
6717 | dirs[ndirs - 1].length) == 0) | |
6718 | { | |
6719 | /* Same directory as last entry. */ | |
6720 | files[i].dir_idx = ndirs - 1; | |
0b34cf1e UD |
6721 | ++dirs[ndirs - 1].count; |
6722 | } | |
6723 | else | |
6724 | { | |
6725 | int j; | |
6726 | ||
6727 | /* This is a new directory. */ | |
6728 | dirs[ndirs].path = files[i].path; | |
6729 | dirs[ndirs].length = files[i].fname - files[i].path; | |
0b34cf1e UD |
6730 | dirs[ndirs].count = 1; |
6731 | dirs[ndirs].dir_idx = ndirs; | |
6732 | dirs[ndirs].used = 0; | |
6733 | files[i].dir_idx = ndirs; | |
6734 | ||
6735 | /* Search for a prefix. */ | |
981975b6 | 6736 | dirs[ndirs].prefix = -1; |
0b34cf1e | 6737 | for (j = 0; j < ndirs; ++j) |
981975b6 RH |
6738 | if (dirs[j].length < dirs[ndirs].length |
6739 | && dirs[j].length > 1 | |
6740 | && (dirs[ndirs].prefix == -1 | |
6741 | || dirs[j].length > dirs[dirs[ndirs].prefix].length) | |
6742 | && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0) | |
6743 | dirs[ndirs].prefix = j; | |
0b34cf1e UD |
6744 | |
6745 | ++ndirs; | |
6746 | } | |
6747 | ||
6748 | /* Now to the actual work. We have to find a subset of the | |
6749 | directories which allow expressing the file name using references | |
6750 | to the directory table with the least amount of characters. We | |
6751 | do not do an exhaustive search where we would have to check out | |
6752 | every combination of every single possible prefix. Instead we | |
6753 | use a heuristic which provides nearly optimal results in most | |
6754 | cases and never is much off. */ | |
6755 | saved = (int *) alloca (ndirs * sizeof (int)); | |
6756 | savehere = (int *) alloca (ndirs * sizeof (int)); | |
6757 | ||
6758 | memset (saved, '\0', ndirs * sizeof (saved[0])); | |
6759 | for (i = 0; i < ndirs; ++i) | |
6760 | { | |
6761 | int j; | |
6762 | int total; | |
6763 | ||
981975b6 | 6764 | /* We can always save some space for the current directory. But |
0b34cf1e UD |
6765 | this does not mean it will be enough to justify adding the |
6766 | directory. */ | |
6767 | savehere[i] = dirs[i].length; | |
6768 | total = (savehere[i] - saved[i]) * dirs[i].count; | |
6769 | ||
6770 | for (j = i + 1; j < ndirs; ++j) | |
6771 | { | |
6772 | savehere[j] = 0; | |
6773 | ||
6774 | if (saved[j] < dirs[i].length) | |
6775 | { | |
6776 | /* Determine whether the dirs[i] path is a prefix of the | |
6777 | dirs[j] path. */ | |
6778 | int k; | |
6779 | ||
981975b6 RH |
6780 | k = dirs[j].prefix; |
6781 | while (k != -1 && k != i) | |
6782 | k = dirs[k].prefix; | |
6783 | ||
6784 | if (k == i) | |
6785 | { | |
6786 | /* Yes it is. We can possibly safe some memory but | |
6787 | writing the filenames in dirs[j] relative to | |
6788 | dirs[i]. */ | |
6789 | savehere[j] = dirs[i].length; | |
6790 | total += (savehere[j] - saved[j]) * dirs[j].count; | |
6791 | } | |
0b34cf1e UD |
6792 | } |
6793 | } | |
6794 | ||
6795 | /* Check whether we can safe enough to justify adding the dirs[i] | |
6796 | directory. */ | |
6797 | if (total > dirs[i].length + 1) | |
6798 | { | |
981975b6 | 6799 | /* It's worthwhile adding. */ |
0b34cf1e UD |
6800 | for (j = i; j < ndirs; ++j) |
6801 | if (savehere[j] > 0) | |
6802 | { | |
6803 | /* Remember how much we saved for this directory so far. */ | |
6804 | saved[j] = savehere[j]; | |
6805 | ||
6806 | /* Remember the prefix directory. */ | |
6807 | dirs[j].dir_idx = i; | |
6808 | } | |
6809 | } | |
6810 | } | |
6811 | ||
981975b6 | 6812 | /* We have to emit them in the order they appear in the file_table |
0b34cf1e UD |
6813 | array since the index is used in the debug info generation. To |
6814 | do this efficiently we generate a back-mapping of the indices | |
6815 | first. */ | |
981975b6 RH |
6816 | backmap = (int *) alloca (file_table.in_use * sizeof (int)); |
6817 | for (i = 1; i < (int) file_table.in_use; ++i) | |
0b34cf1e UD |
6818 | { |
6819 | backmap[files[i].file_idx] = i; | |
6820 | /* Mark this directory as used. */ | |
6821 | dirs[dirs[files[i].dir_idx].dir_idx].used = 1; | |
6822 | } | |
6823 | ||
6824 | /* That was it. We are ready to emit the information. First the | |
6825 | directory name table. Here we have to make sure that the first | |
6826 | actually emitted directory name has the index one. Zero is | |
6827 | reserved for the current working directory. Make sure we do not | |
6828 | confuse these indices with the one for the constructed table | |
6829 | (even though most of the time they are identical). */ | |
6830 | idx = 1; | |
e57cabac | 6831 | idx_offset = dirs[0].length > 0 ? 1 : 0; |
0b34cf1e UD |
6832 | for (i = 1 - idx_offset; i < ndirs; ++i) |
6833 | if (dirs[i].used != 0) | |
6834 | { | |
6835 | dirs[i].used = idx++; | |
2e4b9b8c RH |
6836 | dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1, |
6837 | "Directory Entry: 0x%x", dirs[i].used); | |
0b34cf1e | 6838 | } |
2e4b9b8c RH |
6839 | dw2_asm_output_data (1, 0, "End directory table"); |
6840 | ||
0b34cf1e UD |
6841 | /* Correct the index for the current working directory entry if it |
6842 | exists. */ | |
6843 | if (idx_offset == 0) | |
6844 | dirs[0].used = 0; | |
0b34cf1e UD |
6845 | |
6846 | /* Now write all the file names. */ | |
981975b6 | 6847 | for (i = 1; i < (int) file_table.in_use; ++i) |
0b34cf1e UD |
6848 | { |
6849 | int file_idx = backmap[i]; | |
6850 | int dir_idx = dirs[files[file_idx].dir_idx].dir_idx; | |
6851 | ||
2e4b9b8c RH |
6852 | dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1, |
6853 | "File Entry: 0x%x", i); | |
0b34cf1e UD |
6854 | |
6855 | /* Include directory index. */ | |
2e4b9b8c | 6856 | dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL); |
0b34cf1e UD |
6857 | |
6858 | /* Modification time. */ | |
2e4b9b8c | 6859 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e UD |
6860 | |
6861 | /* File length in bytes. */ | |
2e4b9b8c | 6862 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e | 6863 | } |
2e4b9b8c | 6864 | dw2_asm_output_data (1, 0, "End file name table"); |
0b34cf1e UD |
6865 | } |
6866 | ||
6867 | ||
a3f97cbb | 6868 | /* Output the source line number correspondence information. This |
14a774a9 | 6869 | information goes into the .debug_line section. */ |
71dfc51f | 6870 | |
a3f97cbb JW |
6871 | static void |
6872 | output_line_info () | |
6873 | { | |
981975b6 | 6874 | char l1[20], l2[20], p1[20], p2[20]; |
a3f97cbb JW |
6875 | char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
6876 | char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6877 | register unsigned opc; | |
6878 | register unsigned n_op_args; | |
a3f97cbb JW |
6879 | register unsigned long lt_index; |
6880 | register unsigned long current_line; | |
6881 | register long line_offset; | |
6882 | register long line_delta; | |
6883 | register unsigned long current_file; | |
e90b62db | 6884 | register unsigned long function; |
71dfc51f | 6885 | |
2e4b9b8c RH |
6886 | ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0); |
6887 | ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0); | |
981975b6 RH |
6888 | ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0); |
6889 | ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0); | |
71dfc51f | 6890 | |
2e4b9b8c RH |
6891 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1, |
6892 | "Length of Source Line Info"); | |
6893 | ASM_OUTPUT_LABEL (asm_out_file, l1); | |
71dfc51f | 6894 | |
2e4b9b8c | 6895 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
71dfc51f | 6896 | |
981975b6 RH |
6897 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length"); |
6898 | ASM_OUTPUT_LABEL (asm_out_file, p1); | |
71dfc51f | 6899 | |
2e4b9b8c RH |
6900 | dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH, |
6901 | "Minimum Instruction Length"); | |
71dfc51f | 6902 | |
2e4b9b8c RH |
6903 | dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START, |
6904 | "Default is_stmt_start flag"); | |
71dfc51f | 6905 | |
2e4b9b8c RH |
6906 | dw2_asm_output_data (1, DWARF_LINE_BASE, |
6907 | "Line Base Value (Special Opcodes)"); | |
71dfc51f | 6908 | |
2e4b9b8c RH |
6909 | dw2_asm_output_data (1, DWARF_LINE_RANGE, |
6910 | "Line Range Value (Special Opcodes)"); | |
6911 | ||
6912 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE, | |
6913 | "Special Opcode Base"); | |
71dfc51f | 6914 | |
a3f97cbb JW |
6915 | for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc) |
6916 | { | |
6917 | switch (opc) | |
6918 | { | |
6919 | case DW_LNS_advance_pc: | |
6920 | case DW_LNS_advance_line: | |
6921 | case DW_LNS_set_file: | |
6922 | case DW_LNS_set_column: | |
6923 | case DW_LNS_fixed_advance_pc: | |
6924 | n_op_args = 1; | |
6925 | break; | |
6926 | default: | |
6927 | n_op_args = 0; | |
6928 | break; | |
6929 | } | |
2e4b9b8c RH |
6930 | |
6931 | dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args", | |
6932 | opc, n_op_args); | |
a3f97cbb | 6933 | } |
71dfc51f | 6934 | |
0b34cf1e UD |
6935 | /* Write out the information about the files we use. */ |
6936 | output_file_names (); | |
981975b6 | 6937 | ASM_OUTPUT_LABEL (asm_out_file, p2); |
a3f97cbb | 6938 | |
2f22d404 JM |
6939 | /* We used to set the address register to the first location in the text |
6940 | section here, but that didn't accomplish anything since we already | |
6941 | have a line note for the opening brace of the first function. */ | |
a3f97cbb JW |
6942 | |
6943 | /* Generate the line number to PC correspondence table, encoded as | |
6944 | a series of state machine operations. */ | |
6945 | current_file = 1; | |
6946 | current_line = 1; | |
8b790721 | 6947 | strcpy (prev_line_label, text_section_label); |
a3f97cbb JW |
6948 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) |
6949 | { | |
2f22d404 JM |
6950 | register dw_line_info_ref line_info = &line_info_table[lt_index]; |
6951 | ||
10a11b75 JM |
6952 | #if 0 |
6953 | /* Disable this optimization for now; GDB wants to see two line notes | |
6954 | at the beginning of a function so it can find the end of the | |
6955 | prologue. */ | |
6956 | ||
2f22d404 JM |
6957 | /* Don't emit anything for redundant notes. Just updating the |
6958 | address doesn't accomplish anything, because we already assume | |
6959 | that anything after the last address is this line. */ | |
6960 | if (line_info->dw_line_num == current_line | |
6961 | && line_info->dw_file_num == current_file) | |
6962 | continue; | |
10a11b75 | 6963 | #endif |
71dfc51f | 6964 | |
2e4b9b8c RH |
6965 | /* Emit debug info for the address of the current line. |
6966 | ||
6967 | Unfortunately, we have little choice here currently, and must always | |
6968 | use the most general form. Gcc does not know the address delta | |
6969 | itself, so we can't use DW_LNS_advance_pc. Many ports do have length | |
6970 | attributes which will give an upper bound on the address range. We | |
6971 | could perhaps use length attributes to determine when it is safe to | |
6972 | use DW_LNS_fixed_advance_pc. */ | |
6973 | ||
5c90448c | 6974 | ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index); |
f19a6894 JW |
6975 | if (0) |
6976 | { | |
6977 | /* This can handle deltas up to 0xffff. This takes 3 bytes. */ | |
2e4b9b8c RH |
6978 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
6979 | "DW_LNS_fixed_advance_pc"); | |
6980 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
6981 | } |
6982 | else | |
6983 | { | |
a1a4189d JB |
6984 | /* This can handle any delta. This takes |
6985 | 4+DWARF2_ADDR_SIZE bytes. */ | |
2e4b9b8c RH |
6986 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
6987 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
6988 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 6989 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 JW |
6990 | } |
6991 | strcpy (prev_line_label, line_label); | |
6992 | ||
6993 | /* Emit debug info for the source file of the current line, if | |
6994 | different from the previous line. */ | |
a3f97cbb JW |
6995 | if (line_info->dw_file_num != current_file) |
6996 | { | |
6997 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
6998 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
6999 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
981975b6 | 7000 | file_table.table[current_file]); |
a3f97cbb | 7001 | } |
71dfc51f | 7002 | |
f19a6894 JW |
7003 | /* Emit debug info for the current line number, choosing the encoding |
7004 | that uses the least amount of space. */ | |
2f22d404 | 7005 | if (line_info->dw_line_num != current_line) |
a3f97cbb | 7006 | { |
2f22d404 JM |
7007 | line_offset = line_info->dw_line_num - current_line; |
7008 | line_delta = line_offset - DWARF_LINE_BASE; | |
7009 | current_line = line_info->dw_line_num; | |
7010 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
7011 | { | |
7012 | /* This can handle deltas from -10 to 234, using the current | |
7013 | definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This | |
7014 | takes 1 byte. */ | |
2e4b9b8c RH |
7015 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, |
7016 | "line %lu", current_line); | |
2f22d404 JM |
7017 | } |
7018 | else | |
7019 | { | |
7020 | /* This can handle any delta. This takes at least 4 bytes, | |
7021 | depending on the value being encoded. */ | |
2e4b9b8c RH |
7022 | dw2_asm_output_data (1, DW_LNS_advance_line, |
7023 | "advance to line %lu", current_line); | |
7024 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
7025 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
2f22d404 | 7026 | } |
a94dbf2c JM |
7027 | } |
7028 | else | |
7029 | { | |
2f22d404 | 7030 | /* We still need to start a new row, so output a copy insn. */ |
2e4b9b8c | 7031 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); |
a3f97cbb | 7032 | } |
a3f97cbb JW |
7033 | } |
7034 | ||
f19a6894 JW |
7035 | /* Emit debug info for the address of the end of the function. */ |
7036 | if (0) | |
7037 | { | |
2e4b9b8c RH |
7038 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7039 | "DW_LNS_fixed_advance_pc"); | |
7040 | dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL); | |
f19a6894 JW |
7041 | } |
7042 | else | |
7043 | { | |
2e4b9b8c RH |
7044 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7045 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7046 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7047 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL); |
f19a6894 | 7048 | } |
bdb669cb | 7049 | |
2e4b9b8c RH |
7050 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
7051 | dw2_asm_output_data_uleb128 (1, NULL); | |
7052 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
7053 | |
7054 | function = 0; | |
7055 | current_file = 1; | |
7056 | current_line = 1; | |
556273e0 | 7057 | for (lt_index = 0; lt_index < separate_line_info_table_in_use;) |
e90b62db JM |
7058 | { |
7059 | register dw_separate_line_info_ref line_info | |
7060 | = &separate_line_info_table[lt_index]; | |
71dfc51f | 7061 | |
10a11b75 | 7062 | #if 0 |
2f22d404 JM |
7063 | /* Don't emit anything for redundant notes. */ |
7064 | if (line_info->dw_line_num == current_line | |
7065 | && line_info->dw_file_num == current_file | |
7066 | && line_info->function == function) | |
7067 | goto cont; | |
10a11b75 | 7068 | #endif |
2f22d404 | 7069 | |
f19a6894 JW |
7070 | /* Emit debug info for the address of the current line. If this is |
7071 | a new function, or the first line of a function, then we need | |
7072 | to handle it differently. */ | |
5c90448c JM |
7073 | ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL, |
7074 | lt_index); | |
e90b62db JM |
7075 | if (function != line_info->function) |
7076 | { | |
7077 | function = line_info->function; | |
71dfc51f | 7078 | |
e90b62db | 7079 | /* Set the address register to the first line in the function */ |
2e4b9b8c RH |
7080 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7081 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7082 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7083 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
e90b62db JM |
7084 | } |
7085 | else | |
7086 | { | |
f19a6894 JW |
7087 | /* ??? See the DW_LNS_advance_pc comment above. */ |
7088 | if (0) | |
7089 | { | |
2e4b9b8c RH |
7090 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7091 | "DW_LNS_fixed_advance_pc"); | |
7092 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7093 | } |
7094 | else | |
7095 | { | |
2e4b9b8c RH |
7096 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7097 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7098 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7099 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7100 | } |
e90b62db | 7101 | } |
f19a6894 | 7102 | strcpy (prev_line_label, line_label); |
71dfc51f | 7103 | |
f19a6894 JW |
7104 | /* Emit debug info for the source file of the current line, if |
7105 | different from the previous line. */ | |
e90b62db JM |
7106 | if (line_info->dw_file_num != current_file) |
7107 | { | |
7108 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
7109 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
7110 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
981975b6 | 7111 | file_table.table[current_file]); |
e90b62db | 7112 | } |
71dfc51f | 7113 | |
f19a6894 JW |
7114 | /* Emit debug info for the current line number, choosing the encoding |
7115 | that uses the least amount of space. */ | |
e90b62db JM |
7116 | if (line_info->dw_line_num != current_line) |
7117 | { | |
7118 | line_offset = line_info->dw_line_num - current_line; | |
7119 | line_delta = line_offset - DWARF_LINE_BASE; | |
7120 | current_line = line_info->dw_line_num; | |
7121 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
2e4b9b8c RH |
7122 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, |
7123 | "line %lu", current_line); | |
e90b62db JM |
7124 | else |
7125 | { | |
2e4b9b8c RH |
7126 | dw2_asm_output_data (1, DW_LNS_advance_line, |
7127 | "advance to line %lu", current_line); | |
7128 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
7129 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
e90b62db JM |
7130 | } |
7131 | } | |
2f22d404 | 7132 | else |
2e4b9b8c | 7133 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); |
71dfc51f | 7134 | |
10a11b75 | 7135 | #if 0 |
2f22d404 | 7136 | cont: |
10a11b75 | 7137 | #endif |
e90b62db | 7138 | ++lt_index; |
e90b62db JM |
7139 | |
7140 | /* If we're done with a function, end its sequence. */ | |
7141 | if (lt_index == separate_line_info_table_in_use | |
7142 | || separate_line_info_table[lt_index].function != function) | |
7143 | { | |
7144 | current_file = 1; | |
7145 | current_line = 1; | |
71dfc51f | 7146 | |
f19a6894 | 7147 | /* Emit debug info for the address of the end of the function. */ |
5c90448c | 7148 | ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function); |
f19a6894 JW |
7149 | if (0) |
7150 | { | |
2e4b9b8c RH |
7151 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
7152 | "DW_LNS_fixed_advance_pc"); | |
7153 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
7154 | } |
7155 | else | |
7156 | { | |
2e4b9b8c RH |
7157 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
7158 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
7159 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 7160 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 7161 | } |
e90b62db JM |
7162 | |
7163 | /* Output the marker for the end of this sequence. */ | |
2e4b9b8c RH |
7164 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
7165 | dw2_asm_output_data_uleb128 (1, NULL); | |
7166 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
7167 | } |
7168 | } | |
f19f17e0 JM |
7169 | |
7170 | /* Output the marker for the end of the line number info. */ | |
2e4b9b8c | 7171 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
a3f97cbb JW |
7172 | } |
7173 | \f | |
a3f97cbb JW |
7174 | /* Given a pointer to a tree node for some base type, return a pointer to |
7175 | a DIE that describes the given type. | |
7176 | ||
7177 | This routine must only be called for GCC type nodes that correspond to | |
7178 | Dwarf base (fundamental) types. */ | |
71dfc51f | 7179 | |
a3f97cbb JW |
7180 | static dw_die_ref |
7181 | base_type_die (type) | |
7182 | register tree type; | |
7183 | { | |
a9d38797 | 7184 | register dw_die_ref base_type_result; |
ec0ce6e2 | 7185 | register const char *type_name; |
a9d38797 | 7186 | register enum dwarf_type encoding; |
71dfc51f | 7187 | register tree name = TYPE_NAME (type); |
a3f97cbb | 7188 | |
a9d38797 JM |
7189 | if (TREE_CODE (type) == ERROR_MARK |
7190 | || TREE_CODE (type) == VOID_TYPE) | |
a3f97cbb JW |
7191 | return 0; |
7192 | ||
405f63da MM |
7193 | if (name) |
7194 | { | |
7195 | if (TREE_CODE (name) == TYPE_DECL) | |
7196 | name = DECL_NAME (name); | |
7197 | ||
7198 | type_name = IDENTIFIER_POINTER (name); | |
7199 | } | |
7200 | else | |
7201 | type_name = "__unknown__"; | |
a9d38797 | 7202 | |
a3f97cbb JW |
7203 | switch (TREE_CODE (type)) |
7204 | { | |
a3f97cbb | 7205 | case INTEGER_TYPE: |
a9d38797 | 7206 | /* Carefully distinguish the C character types, without messing |
a3f97cbb | 7207 | up if the language is not C. Note that we check only for the names |
556273e0 | 7208 | that contain spaces; other names might occur by coincidence in other |
a3f97cbb | 7209 | languages. */ |
a9d38797 JM |
7210 | if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE |
7211 | && (type == char_type_node | |
7212 | || ! strcmp (type_name, "signed char") | |
7213 | || ! strcmp (type_name, "unsigned char")))) | |
a3f97cbb | 7214 | { |
a9d38797 JM |
7215 | if (TREE_UNSIGNED (type)) |
7216 | encoding = DW_ATE_unsigned; | |
7217 | else | |
7218 | encoding = DW_ATE_signed; | |
7219 | break; | |
a3f97cbb | 7220 | } |
556273e0 | 7221 | /* else fall through. */ |
a3f97cbb | 7222 | |
a9d38797 JM |
7223 | case CHAR_TYPE: |
7224 | /* GNU Pascal/Ada CHAR type. Not used in C. */ | |
7225 | if (TREE_UNSIGNED (type)) | |
7226 | encoding = DW_ATE_unsigned_char; | |
7227 | else | |
7228 | encoding = DW_ATE_signed_char; | |
a3f97cbb JW |
7229 | break; |
7230 | ||
7231 | case REAL_TYPE: | |
a9d38797 | 7232 | encoding = DW_ATE_float; |
a3f97cbb JW |
7233 | break; |
7234 | ||
405f63da MM |
7235 | /* Dwarf2 doesn't know anything about complex ints, so use |
7236 | a user defined type for it. */ | |
a3f97cbb | 7237 | case COMPLEX_TYPE: |
405f63da MM |
7238 | if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE) |
7239 | encoding = DW_ATE_complex_float; | |
7240 | else | |
7241 | encoding = DW_ATE_lo_user; | |
a3f97cbb JW |
7242 | break; |
7243 | ||
7244 | case BOOLEAN_TYPE: | |
a9d38797 JM |
7245 | /* GNU FORTRAN/Ada/C++ BOOLEAN type. */ |
7246 | encoding = DW_ATE_boolean; | |
a3f97cbb JW |
7247 | break; |
7248 | ||
7249 | default: | |
a9d38797 | 7250 | abort (); /* No other TREE_CODEs are Dwarf fundamental types. */ |
a3f97cbb JW |
7251 | } |
7252 | ||
a9d38797 | 7253 | base_type_result = new_die (DW_TAG_base_type, comp_unit_die); |
14a774a9 RK |
7254 | if (demangle_name_func) |
7255 | type_name = (*demangle_name_func) (type_name); | |
7256 | ||
a9d38797 JM |
7257 | add_AT_string (base_type_result, DW_AT_name, type_name); |
7258 | add_AT_unsigned (base_type_result, DW_AT_byte_size, | |
4e5a8d7b | 7259 | int_size_in_bytes (type)); |
a9d38797 | 7260 | add_AT_unsigned (base_type_result, DW_AT_encoding, encoding); |
a3f97cbb JW |
7261 | |
7262 | return base_type_result; | |
7263 | } | |
7264 | ||
7265 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to | |
7266 | the Dwarf "root" type for the given input type. The Dwarf "root" type of | |
7267 | a given type is generally the same as the given type, except that if the | |
7268 | given type is a pointer or reference type, then the root type of the given | |
7269 | type is the root type of the "basis" type for the pointer or reference | |
7270 | type. (This definition of the "root" type is recursive.) Also, the root | |
7271 | type of a `const' qualified type or a `volatile' qualified type is the | |
7272 | root type of the given type without the qualifiers. */ | |
71dfc51f | 7273 | |
a3f97cbb JW |
7274 | static tree |
7275 | root_type (type) | |
7276 | register tree type; | |
7277 | { | |
7278 | if (TREE_CODE (type) == ERROR_MARK) | |
7279 | return error_mark_node; | |
7280 | ||
7281 | switch (TREE_CODE (type)) | |
7282 | { | |
7283 | case ERROR_MARK: | |
7284 | return error_mark_node; | |
7285 | ||
7286 | case POINTER_TYPE: | |
7287 | case REFERENCE_TYPE: | |
7288 | return type_main_variant (root_type (TREE_TYPE (type))); | |
7289 | ||
7290 | default: | |
7291 | return type_main_variant (type); | |
7292 | } | |
7293 | } | |
7294 | ||
7295 | /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the | |
7296 | given input type is a Dwarf "fundamental" type. Otherwise return null. */ | |
71dfc51f RK |
7297 | |
7298 | static inline int | |
a3f97cbb JW |
7299 | is_base_type (type) |
7300 | register tree type; | |
7301 | { | |
7302 | switch (TREE_CODE (type)) | |
7303 | { | |
7304 | case ERROR_MARK: | |
7305 | case VOID_TYPE: | |
7306 | case INTEGER_TYPE: | |
7307 | case REAL_TYPE: | |
7308 | case COMPLEX_TYPE: | |
7309 | case BOOLEAN_TYPE: | |
7310 | case CHAR_TYPE: | |
7311 | return 1; | |
7312 | ||
7313 | case SET_TYPE: | |
7314 | case ARRAY_TYPE: | |
7315 | case RECORD_TYPE: | |
7316 | case UNION_TYPE: | |
7317 | case QUAL_UNION_TYPE: | |
7318 | case ENUMERAL_TYPE: | |
7319 | case FUNCTION_TYPE: | |
7320 | case METHOD_TYPE: | |
7321 | case POINTER_TYPE: | |
7322 | case REFERENCE_TYPE: | |
7323 | case FILE_TYPE: | |
7324 | case OFFSET_TYPE: | |
7325 | case LANG_TYPE: | |
604bb87d | 7326 | case VECTOR_TYPE: |
a3f97cbb JW |
7327 | return 0; |
7328 | ||
7329 | default: | |
7330 | abort (); | |
7331 | } | |
71dfc51f | 7332 | |
a3f97cbb JW |
7333 | return 0; |
7334 | } | |
7335 | ||
7336 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging | |
7337 | entry that chains various modifiers in front of the given type. */ | |
71dfc51f | 7338 | |
a3f97cbb JW |
7339 | static dw_die_ref |
7340 | modified_type_die (type, is_const_type, is_volatile_type, context_die) | |
7341 | register tree type; | |
7342 | register int is_const_type; | |
7343 | register int is_volatile_type; | |
7344 | register dw_die_ref context_die; | |
7345 | { | |
7346 | register enum tree_code code = TREE_CODE (type); | |
7347 | register dw_die_ref mod_type_die = NULL; | |
7348 | register dw_die_ref sub_die = NULL; | |
dfcf9891 | 7349 | register tree item_type = NULL; |
a3f97cbb JW |
7350 | |
7351 | if (code != ERROR_MARK) | |
7352 | { | |
5101b304 MM |
7353 | tree qualified_type; |
7354 | ||
7355 | /* See if we already have the appropriately qualified variant of | |
7356 | this type. */ | |
7357 | qualified_type | |
7358 | = get_qualified_type (type, | |
7359 | ((is_const_type ? TYPE_QUAL_CONST : 0) | |
7360 | | (is_volatile_type | |
7361 | ? TYPE_QUAL_VOLATILE : 0))); | |
7362 | /* If we do, then we can just use its DIE, if it exists. */ | |
7363 | if (qualified_type) | |
7364 | { | |
7365 | mod_type_die = lookup_type_die (qualified_type); | |
7366 | if (mod_type_die) | |
7367 | return mod_type_die; | |
7368 | } | |
bdb669cb | 7369 | |
556273e0 | 7370 | /* Handle C typedef types. */ |
5101b304 MM |
7371 | if (qualified_type && TYPE_NAME (qualified_type) |
7372 | && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL | |
7373 | && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type))) | |
a94dbf2c | 7374 | { |
5101b304 MM |
7375 | tree type_name = TYPE_NAME (qualified_type); |
7376 | tree dtype = TREE_TYPE (type_name); | |
7377 | if (qualified_type == dtype) | |
a94dbf2c JM |
7378 | { |
7379 | /* For a named type, use the typedef. */ | |
5101b304 MM |
7380 | gen_type_die (qualified_type, context_die); |
7381 | mod_type_die = lookup_type_die (qualified_type); | |
a94dbf2c | 7382 | } |
71dfc51f | 7383 | |
a94dbf2c JM |
7384 | else if (is_const_type < TYPE_READONLY (dtype) |
7385 | || is_volatile_type < TYPE_VOLATILE (dtype)) | |
7386 | /* cv-unqualified version of named type. Just use the unnamed | |
7387 | type to which it refers. */ | |
71dfc51f | 7388 | mod_type_die |
5101b304 | 7389 | = modified_type_die (DECL_ORIGINAL_TYPE (type_name), |
71dfc51f RK |
7390 | is_const_type, is_volatile_type, |
7391 | context_die); | |
7392 | /* Else cv-qualified version of named type; fall through. */ | |
a94dbf2c JM |
7393 | } |
7394 | ||
7395 | if (mod_type_die) | |
556273e0 KH |
7396 | /* OK. */ |
7397 | ; | |
a94dbf2c | 7398 | else if (is_const_type) |
a3f97cbb | 7399 | { |
ab72d377 | 7400 | mod_type_die = new_die (DW_TAG_const_type, comp_unit_die); |
a9d38797 | 7401 | sub_die = modified_type_die (type, 0, is_volatile_type, context_die); |
a3f97cbb JW |
7402 | } |
7403 | else if (is_volatile_type) | |
7404 | { | |
ab72d377 | 7405 | mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die); |
a9d38797 | 7406 | sub_die = modified_type_die (type, 0, 0, context_die); |
a3f97cbb JW |
7407 | } |
7408 | else if (code == POINTER_TYPE) | |
7409 | { | |
ab72d377 | 7410 | mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die); |
a3f97cbb | 7411 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 7412 | #if 0 |
a3f97cbb | 7413 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
61b32c02 | 7414 | #endif |
a3f97cbb | 7415 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
7416 | } |
7417 | else if (code == REFERENCE_TYPE) | |
7418 | { | |
ab72d377 | 7419 | mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die); |
a3f97cbb | 7420 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 7421 | #if 0 |
a3f97cbb | 7422 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
556273e0 | 7423 | #endif |
a3f97cbb | 7424 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
7425 | } |
7426 | else if (is_base_type (type)) | |
71dfc51f | 7427 | mod_type_die = base_type_die (type); |
a3f97cbb JW |
7428 | else |
7429 | { | |
4b674448 JM |
7430 | gen_type_die (type, context_die); |
7431 | ||
a3f97cbb JW |
7432 | /* We have to get the type_main_variant here (and pass that to the |
7433 | `lookup_type_die' routine) because the ..._TYPE node we have | |
7434 | might simply be a *copy* of some original type node (where the | |
7435 | copy was created to help us keep track of typedef names) and | |
7436 | that copy might have a different TYPE_UID from the original | |
a94dbf2c | 7437 | ..._TYPE node. */ |
a3f97cbb | 7438 | mod_type_die = lookup_type_die (type_main_variant (type)); |
3a88cbd1 JL |
7439 | if (mod_type_die == NULL) |
7440 | abort (); | |
a3f97cbb | 7441 | } |
3d2999ba MK |
7442 | |
7443 | /* We want to equate the qualified type to the die below. */ | |
7444 | if (qualified_type) | |
7445 | type = qualified_type; | |
a3f97cbb | 7446 | } |
71dfc51f | 7447 | |
dfcf9891 JW |
7448 | equate_type_number_to_die (type, mod_type_die); |
7449 | if (item_type) | |
71dfc51f RK |
7450 | /* We must do this after the equate_type_number_to_die call, in case |
7451 | this is a recursive type. This ensures that the modified_type_die | |
7452 | recursion will terminate even if the type is recursive. Recursive | |
7453 | types are possible in Ada. */ | |
7454 | sub_die = modified_type_die (item_type, | |
7455 | TYPE_READONLY (item_type), | |
7456 | TYPE_VOLATILE (item_type), | |
7457 | context_die); | |
7458 | ||
a3f97cbb | 7459 | if (sub_die != NULL) |
71dfc51f RK |
7460 | add_AT_die_ref (mod_type_die, DW_AT_type, sub_die); |
7461 | ||
a3f97cbb JW |
7462 | return mod_type_die; |
7463 | } | |
7464 | ||
a3f97cbb JW |
7465 | /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is |
7466 | an enumerated type. */ | |
71dfc51f RK |
7467 | |
7468 | static inline int | |
a3f97cbb JW |
7469 | type_is_enum (type) |
7470 | register tree type; | |
7471 | { | |
7472 | return TREE_CODE (type) == ENUMERAL_TYPE; | |
7473 | } | |
7474 | ||
7d9d8943 AM |
7475 | /* Return the register number described by a given RTL node. */ |
7476 | ||
7477 | static unsigned int | |
7478 | reg_number (rtl) | |
7479 | register rtx rtl; | |
7480 | { | |
7481 | register unsigned regno = REGNO (rtl); | |
7482 | ||
7483 | if (regno >= FIRST_PSEUDO_REGISTER) | |
7484 | { | |
7485 | warning ("internal regno botch: regno = %d\n", regno); | |
7486 | regno = 0; | |
7487 | } | |
7488 | ||
7489 | regno = DBX_REGISTER_NUMBER (regno); | |
7490 | return regno; | |
7491 | } | |
7492 | ||
a3f97cbb | 7493 | /* Return a location descriptor that designates a machine register. */ |
71dfc51f | 7494 | |
a3f97cbb JW |
7495 | static dw_loc_descr_ref |
7496 | reg_loc_descriptor (rtl) | |
7497 | register rtx rtl; | |
7498 | { | |
7499 | register dw_loc_descr_ref loc_result = NULL; | |
7500 | register unsigned reg = reg_number (rtl); | |
71dfc51f | 7501 | |
85066503 | 7502 | if (reg <= 31) |
71dfc51f | 7503 | loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0); |
a3f97cbb | 7504 | else |
71dfc51f RK |
7505 | loc_result = new_loc_descr (DW_OP_regx, reg, 0); |
7506 | ||
a3f97cbb JW |
7507 | return loc_result; |
7508 | } | |
7509 | ||
d8041cc8 RH |
7510 | /* Return a location descriptor that designates a constant. */ |
7511 | ||
7512 | static dw_loc_descr_ref | |
7513 | int_loc_descriptor (i) | |
7514 | HOST_WIDE_INT i; | |
7515 | { | |
7516 | enum dwarf_location_atom op; | |
7517 | ||
7518 | /* Pick the smallest representation of a constant, rather than just | |
7519 | defaulting to the LEB encoding. */ | |
7520 | if (i >= 0) | |
7521 | { | |
7522 | if (i <= 31) | |
7523 | op = DW_OP_lit0 + i; | |
7524 | else if (i <= 0xff) | |
7525 | op = DW_OP_const1u; | |
7526 | else if (i <= 0xffff) | |
7527 | op = DW_OP_const2u; | |
7528 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
7529 | || i <= 0xffffffff) | |
7530 | op = DW_OP_const4u; | |
7531 | else | |
7532 | op = DW_OP_constu; | |
7533 | } | |
7534 | else | |
7535 | { | |
7536 | if (i >= -0x80) | |
7537 | op = DW_OP_const1s; | |
7538 | else if (i >= -0x8000) | |
7539 | op = DW_OP_const2s; | |
7540 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
7541 | || i >= -0x80000000) | |
7542 | op = DW_OP_const4s; | |
7543 | else | |
7544 | op = DW_OP_consts; | |
7545 | } | |
7546 | ||
7547 | return new_loc_descr (op, i, 0); | |
7548 | } | |
7549 | ||
a3f97cbb | 7550 | /* Return a location descriptor that designates a base+offset location. */ |
71dfc51f | 7551 | |
a3f97cbb JW |
7552 | static dw_loc_descr_ref |
7553 | based_loc_descr (reg, offset) | |
7554 | unsigned reg; | |
7555 | long int offset; | |
7556 | { | |
7557 | register dw_loc_descr_ref loc_result; | |
810429b7 JM |
7558 | /* For the "frame base", we use the frame pointer or stack pointer |
7559 | registers, since the RTL for local variables is relative to one of | |
7560 | them. */ | |
7561 | register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed | |
b1ccbc24 | 7562 | ? HARD_FRAME_POINTER_REGNUM |
810429b7 | 7563 | : STACK_POINTER_REGNUM); |
71dfc51f | 7564 | |
a3f97cbb | 7565 | if (reg == fp_reg) |
71dfc51f | 7566 | loc_result = new_loc_descr (DW_OP_fbreg, offset, 0); |
85066503 | 7567 | else if (reg <= 31) |
71dfc51f | 7568 | loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0); |
a3f97cbb | 7569 | else |
71dfc51f RK |
7570 | loc_result = new_loc_descr (DW_OP_bregx, reg, offset); |
7571 | ||
a3f97cbb JW |
7572 | return loc_result; |
7573 | } | |
7574 | ||
7575 | /* Return true if this RTL expression describes a base+offset calculation. */ | |
71dfc51f RK |
7576 | |
7577 | static inline int | |
a3f97cbb JW |
7578 | is_based_loc (rtl) |
7579 | register rtx rtl; | |
7580 | { | |
71dfc51f RK |
7581 | return (GET_CODE (rtl) == PLUS |
7582 | && ((GET_CODE (XEXP (rtl, 0)) == REG | |
7583 | && GET_CODE (XEXP (rtl, 1)) == CONST_INT))); | |
a3f97cbb JW |
7584 | } |
7585 | ||
7586 | /* The following routine converts the RTL for a variable or parameter | |
7587 | (resident in memory) into an equivalent Dwarf representation of a | |
7588 | mechanism for getting the address of that same variable onto the top of a | |
7589 | hypothetical "address evaluation" stack. | |
71dfc51f | 7590 | |
a3f97cbb JW |
7591 | When creating memory location descriptors, we are effectively transforming |
7592 | the RTL for a memory-resident object into its Dwarf postfix expression | |
7593 | equivalent. This routine recursively descends an RTL tree, turning | |
e60d4d7b JL |
7594 | it into Dwarf postfix code as it goes. |
7595 | ||
7596 | MODE is the mode of the memory reference, needed to handle some | |
7597 | autoincrement addressing modes. */ | |
71dfc51f | 7598 | |
a3f97cbb | 7599 | static dw_loc_descr_ref |
e60d4d7b | 7600 | mem_loc_descriptor (rtl, mode) |
a3f97cbb | 7601 | register rtx rtl; |
e60d4d7b | 7602 | enum machine_mode mode; |
a3f97cbb JW |
7603 | { |
7604 | dw_loc_descr_ref mem_loc_result = NULL; | |
556273e0 | 7605 | /* Note that for a dynamically sized array, the location we will generate a |
a3f97cbb JW |
7606 | description of here will be the lowest numbered location which is |
7607 | actually within the array. That's *not* necessarily the same as the | |
7608 | zeroth element of the array. */ | |
71dfc51f | 7609 | |
1865dbb5 JM |
7610 | #ifdef ASM_SIMPLIFY_DWARF_ADDR |
7611 | rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); | |
7612 | #endif | |
7613 | ||
a3f97cbb JW |
7614 | switch (GET_CODE (rtl)) |
7615 | { | |
e60d4d7b JL |
7616 | case POST_INC: |
7617 | case POST_DEC: | |
e2134eea | 7618 | case POST_MODIFY: |
e60d4d7b JL |
7619 | /* POST_INC and POST_DEC can be handled just like a SUBREG. So we |
7620 | just fall into the SUBREG code. */ | |
7621 | ||
556273e0 | 7622 | /* Fall through. */ |
e60d4d7b | 7623 | |
a3f97cbb JW |
7624 | case SUBREG: |
7625 | /* The case of a subreg may arise when we have a local (register) | |
7626 | variable or a formal (register) parameter which doesn't quite fill | |
7627 | up an entire register. For now, just assume that it is | |
7628 | legitimate to make the Dwarf info refer to the whole register which | |
7629 | contains the given subreg. */ | |
ddef6bc7 | 7630 | rtl = SUBREG_REG (rtl); |
71dfc51f | 7631 | |
556273e0 | 7632 | /* Fall through. */ |
a3f97cbb JW |
7633 | |
7634 | case REG: | |
7635 | /* Whenever a register number forms a part of the description of the | |
7636 | method for calculating the (dynamic) address of a memory resident | |
556273e0 | 7637 | object, DWARF rules require the register number be referred to as |
a3f97cbb JW |
7638 | a "base register". This distinction is not based in any way upon |
7639 | what category of register the hardware believes the given register | |
7640 | belongs to. This is strictly DWARF terminology we're dealing with | |
7641 | here. Note that in cases where the location of a memory-resident | |
7642 | data object could be expressed as: OP_ADD (OP_BASEREG (basereg), | |
7643 | OP_CONST (0)) the actual DWARF location descriptor that we generate | |
7644 | may just be OP_BASEREG (basereg). This may look deceptively like | |
7645 | the object in question was allocated to a register (rather than in | |
7646 | memory) so DWARF consumers need to be aware of the subtle | |
7647 | distinction between OP_REG and OP_BASEREG. */ | |
7648 | mem_loc_result = based_loc_descr (reg_number (rtl), 0); | |
7649 | break; | |
7650 | ||
7651 | case MEM: | |
f7d2b0ed RH |
7652 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
7653 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0)); | |
a3f97cbb JW |
7654 | break; |
7655 | ||
d8041cc8 RH |
7656 | case LABEL_REF: |
7657 | /* Some ports can transform a symbol ref into a label ref, because | |
368f4cd6 NC |
7658 | the symbol ref is too far away and has to be dumped into a constant |
7659 | pool. */ | |
a3f97cbb JW |
7660 | case CONST: |
7661 | case SYMBOL_REF: | |
6331d1c1 | 7662 | /* Alternatively, the symbol in the constant pool might be referenced |
c6f9b9a1 NC |
7663 | by a different symbol. */ |
7664 | if (GET_CODE (rtl) == SYMBOL_REF | |
79cdfa4b TM |
7665 | && CONSTANT_POOL_ADDRESS_P (rtl)) |
7666 | { | |
7667 | rtx tmp = get_pool_constant (rtl); | |
6331d1c1 | 7668 | if (GET_CODE (tmp) == SYMBOL_REF) |
79cdfa4b TM |
7669 | rtl = tmp; |
7670 | } | |
7671 | ||
a3f97cbb JW |
7672 | mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0); |
7673 | mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
1865dbb5 | 7674 | mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl); |
a3f97cbb JW |
7675 | break; |
7676 | ||
e2134eea JH |
7677 | case PRE_MODIFY: |
7678 | /* Extract the PLUS expression nested inside and fall into | |
0407c02b | 7679 | PLUS code below. */ |
e2134eea JH |
7680 | rtl = XEXP (rtl, 1); |
7681 | goto plus; | |
7682 | ||
e60d4d7b JL |
7683 | case PRE_INC: |
7684 | case PRE_DEC: | |
7685 | /* Turn these into a PLUS expression and fall into the PLUS code | |
7686 | below. */ | |
7687 | rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0), | |
7688 | GEN_INT (GET_CODE (rtl) == PRE_INC | |
556273e0 KH |
7689 | ? GET_MODE_UNIT_SIZE (mode) |
7690 | : -GET_MODE_UNIT_SIZE (mode))); | |
7691 | ||
7692 | /* Fall through. */ | |
e60d4d7b | 7693 | |
a3f97cbb | 7694 | case PLUS: |
e2134eea | 7695 | plus: |
a3f97cbb | 7696 | if (is_based_loc (rtl)) |
71dfc51f RK |
7697 | mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)), |
7698 | INTVAL (XEXP (rtl, 1))); | |
a3f97cbb JW |
7699 | else |
7700 | { | |
d8041cc8 RH |
7701 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode); |
7702 | ||
7703 | if (GET_CODE (XEXP (rtl, 1)) == CONST_INT | |
7704 | && INTVAL (XEXP (rtl, 1)) >= 0) | |
7705 | { | |
7706 | add_loc_descr (&mem_loc_result, | |
7707 | new_loc_descr (DW_OP_plus_uconst, | |
7708 | INTVAL (XEXP (rtl, 1)), 0)); | |
7709 | } | |
7710 | else | |
7711 | { | |
7712 | add_loc_descr (&mem_loc_result, | |
7713 | mem_loc_descriptor (XEXP (rtl, 1), mode)); | |
7714 | add_loc_descr (&mem_loc_result, | |
7715 | new_loc_descr (DW_OP_plus, 0, 0)); | |
7716 | } | |
a3f97cbb JW |
7717 | } |
7718 | break; | |
7719 | ||
dd2478ae JW |
7720 | case MULT: |
7721 | /* If a pseudo-reg is optimized away, it is possible for it to | |
7722 | be replaced with a MEM containing a multiply. */ | |
d8041cc8 RH |
7723 | add_loc_descr (&mem_loc_result, |
7724 | mem_loc_descriptor (XEXP (rtl, 0), mode)); | |
7725 | add_loc_descr (&mem_loc_result, | |
7726 | mem_loc_descriptor (XEXP (rtl, 1), mode)); | |
dd2478ae JW |
7727 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0)); |
7728 | break; | |
7729 | ||
a3f97cbb | 7730 | case CONST_INT: |
d8041cc8 | 7731 | mem_loc_result = int_loc_descriptor (INTVAL (rtl)); |
a3f97cbb JW |
7732 | break; |
7733 | ||
7734 | default: | |
7735 | abort (); | |
7736 | } | |
71dfc51f | 7737 | |
a3f97cbb JW |
7738 | return mem_loc_result; |
7739 | } | |
7740 | ||
956d6950 | 7741 | /* Return a descriptor that describes the concatenation of two locations. |
4401bf24 JL |
7742 | This is typically a complex variable. */ |
7743 | ||
7744 | static dw_loc_descr_ref | |
7745 | concat_loc_descriptor (x0, x1) | |
7746 | register rtx x0, x1; | |
7747 | { | |
7748 | dw_loc_descr_ref cc_loc_result = NULL; | |
7749 | ||
7750 | if (!is_pseudo_reg (x0) | |
7751 | && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0)))) | |
7752 | add_loc_descr (&cc_loc_result, loc_descriptor (x0)); | |
7753 | add_loc_descr (&cc_loc_result, | |
7754 | new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0)); | |
7755 | ||
7756 | if (!is_pseudo_reg (x1) | |
7757 | && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0)))) | |
7758 | add_loc_descr (&cc_loc_result, loc_descriptor (x1)); | |
7759 | add_loc_descr (&cc_loc_result, | |
7760 | new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0)); | |
7761 | ||
7762 | return cc_loc_result; | |
7763 | } | |
7764 | ||
a3f97cbb JW |
7765 | /* Output a proper Dwarf location descriptor for a variable or parameter |
7766 | which is either allocated in a register or in a memory location. For a | |
7767 | register, we just generate an OP_REG and the register number. For a | |
7768 | memory location we provide a Dwarf postfix expression describing how to | |
7769 | generate the (dynamic) address of the object onto the address stack. */ | |
71dfc51f | 7770 | |
a3f97cbb JW |
7771 | static dw_loc_descr_ref |
7772 | loc_descriptor (rtl) | |
7773 | register rtx rtl; | |
7774 | { | |
7775 | dw_loc_descr_ref loc_result = NULL; | |
7776 | switch (GET_CODE (rtl)) | |
7777 | { | |
7778 | case SUBREG: | |
a3f97cbb JW |
7779 | /* The case of a subreg may arise when we have a local (register) |
7780 | variable or a formal (register) parameter which doesn't quite fill | |
71dfc51f | 7781 | up an entire register. For now, just assume that it is |
a3f97cbb JW |
7782 | legitimate to make the Dwarf info refer to the whole register which |
7783 | contains the given subreg. */ | |
ddef6bc7 | 7784 | rtl = SUBREG_REG (rtl); |
71dfc51f | 7785 | |
556273e0 | 7786 | /* Fall through. */ |
a3f97cbb JW |
7787 | |
7788 | case REG: | |
5c90448c | 7789 | loc_result = reg_loc_descriptor (rtl); |
a3f97cbb JW |
7790 | break; |
7791 | ||
7792 | case MEM: | |
e60d4d7b | 7793 | loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
a3f97cbb JW |
7794 | break; |
7795 | ||
4401bf24 JL |
7796 | case CONCAT: |
7797 | loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1)); | |
7798 | break; | |
7799 | ||
a3f97cbb | 7800 | default: |
71dfc51f | 7801 | abort (); |
a3f97cbb | 7802 | } |
71dfc51f | 7803 | |
a3f97cbb JW |
7804 | return loc_result; |
7805 | } | |
7806 | ||
d8041cc8 RH |
7807 | /* Similar, but generate the descriptor from trees instead of rtl. |
7808 | This comes up particularly with variable length arrays. */ | |
7809 | ||
7810 | static dw_loc_descr_ref | |
7811 | loc_descriptor_from_tree (loc, addressp) | |
7812 | tree loc; | |
7813 | int addressp; | |
7814 | { | |
7815 | dw_loc_descr_ref ret = NULL; | |
7816 | int indirect_size = 0; | |
7817 | int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc)); | |
7818 | enum dwarf_location_atom op; | |
7819 | ||
7820 | /* ??? Most of the time we do not take proper care for sign/zero | |
7821 | extending the values properly. Hopefully this won't be a real | |
7822 | problem... */ | |
7823 | ||
7824 | switch (TREE_CODE (loc)) | |
7825 | { | |
7826 | case ERROR_MARK: | |
7827 | break; | |
7828 | ||
b4ae5201 RK |
7829 | case WITH_RECORD_EXPR: |
7830 | /* This case involves extracting fields from an object to determine the | |
7831 | position of other fields. We don't try to encode this here. The | |
7832 | only user of this is Ada, which encodes the needed information using | |
7833 | the names of types. */ | |
7834 | return ret; | |
7835 | ||
d8041cc8 RH |
7836 | case VAR_DECL: |
7837 | case PARM_DECL: | |
7838 | { | |
7839 | rtx rtl = rtl_for_decl_location (loc); | |
7840 | enum machine_mode mode = DECL_MODE (loc); | |
7841 | ||
a97c9600 RH |
7842 | if (rtl == NULL_RTX) |
7843 | break; | |
7844 | else if (CONSTANT_P (rtl)) | |
d8041cc8 RH |
7845 | { |
7846 | ret = new_loc_descr (DW_OP_addr, 0, 0); | |
7847 | ret->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
7848 | ret->dw_loc_oprnd1.v.val_addr = rtl; | |
7849 | indirect_size = GET_MODE_SIZE (mode); | |
7850 | } | |
7851 | else | |
7852 | { | |
7853 | if (GET_CODE (rtl) == MEM) | |
7854 | { | |
7855 | indirect_size = GET_MODE_SIZE (mode); | |
7856 | rtl = XEXP (rtl, 0); | |
7857 | } | |
7858 | ret = mem_loc_descriptor (rtl, mode); | |
7859 | } | |
7860 | } | |
7861 | break; | |
7862 | ||
7863 | case INDIRECT_REF: | |
7864 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7865 | indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc))); | |
7866 | break; | |
7867 | ||
ed972b14 RK |
7868 | case NOP_EXPR: |
7869 | case CONVERT_EXPR: | |
7870 | case NON_LVALUE_EXPR: | |
b4ae5201 | 7871 | case SAVE_EXPR: |
ed972b14 | 7872 | return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp); |
e57cabac | 7873 | |
d8041cc8 RH |
7874 | case COMPONENT_REF: |
7875 | case BIT_FIELD_REF: | |
7876 | case ARRAY_REF: | |
b4e3fabb | 7877 | case ARRAY_RANGE_REF: |
d8041cc8 RH |
7878 | { |
7879 | tree obj, offset; | |
7880 | HOST_WIDE_INT bitsize, bitpos, bytepos; | |
7881 | enum machine_mode mode; | |
7882 | int volatilep; | |
7883 | unsigned int alignment; | |
7884 | ||
7885 | obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode, | |
7886 | &unsignedp, &volatilep, &alignment); | |
7887 | ret = loc_descriptor_from_tree (obj, 1); | |
7888 | ||
7889 | if (offset != NULL_TREE) | |
7890 | { | |
7891 | /* Variable offset. */ | |
7892 | add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0)); | |
7893 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
7894 | } | |
7895 | ||
7896 | if (addressp) | |
7897 | { | |
7898 | /* We cannot address anything not on a unit boundary. */ | |
7899 | if (bitpos % BITS_PER_UNIT != 0) | |
7900 | abort (); | |
7901 | } | |
7902 | else | |
7903 | { | |
7904 | if (bitpos % BITS_PER_UNIT != 0 | |
7905 | || bitsize % BITS_PER_UNIT != 0) | |
7906 | { | |
7907 | /* ??? We could handle this by loading and shifting etc. | |
7908 | Wait until someone needs it before expending the effort. */ | |
7909 | abort (); | |
7910 | } | |
7911 | ||
7912 | indirect_size = bitsize / BITS_PER_UNIT; | |
7913 | } | |
7914 | ||
7915 | bytepos = bitpos / BITS_PER_UNIT; | |
7916 | if (bytepos > 0) | |
7917 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0)); | |
7918 | else if (bytepos < 0) | |
7919 | { | |
7920 | add_loc_descr (&ret, int_loc_descriptor (bytepos)); | |
7921 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
7922 | } | |
7923 | break; | |
7924 | } | |
7925 | ||
7926 | case INTEGER_CST: | |
7927 | if (host_integerp (loc, 0)) | |
7928 | ret = int_loc_descriptor (tree_low_cst (loc, 0)); | |
7929 | break; | |
d8041cc8 RH |
7930 | |
7931 | case BIT_AND_EXPR: | |
7932 | op = DW_OP_and; | |
7933 | goto do_binop; | |
7934 | case BIT_XOR_EXPR: | |
7935 | op = DW_OP_xor; | |
7936 | goto do_binop; | |
7937 | case BIT_IOR_EXPR: | |
7938 | op = DW_OP_or; | |
7939 | goto do_binop; | |
7940 | case TRUNC_DIV_EXPR: | |
7941 | op = DW_OP_div; | |
7942 | goto do_binop; | |
7943 | case MINUS_EXPR: | |
7944 | op = DW_OP_minus; | |
7945 | goto do_binop; | |
7946 | case TRUNC_MOD_EXPR: | |
7947 | op = DW_OP_mod; | |
7948 | goto do_binop; | |
7949 | case MULT_EXPR: | |
7950 | op = DW_OP_mul; | |
7951 | goto do_binop; | |
7952 | case LSHIFT_EXPR: | |
7953 | op = DW_OP_shl; | |
7954 | goto do_binop; | |
7955 | case RSHIFT_EXPR: | |
7956 | op = (unsignedp ? DW_OP_shr : DW_OP_shra); | |
7957 | goto do_binop; | |
7958 | case PLUS_EXPR: | |
7959 | if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST | |
7960 | && host_integerp (TREE_OPERAND (loc, 1), 0)) | |
7961 | { | |
7962 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7963 | add_loc_descr (&ret, | |
7964 | new_loc_descr (DW_OP_plus_uconst, | |
7965 | tree_low_cst (TREE_OPERAND (loc, 1), | |
7966 | 0), | |
7967 | 0)); | |
7968 | break; | |
7969 | } | |
7970 | op = DW_OP_plus; | |
7971 | goto do_binop; | |
7972 | case LE_EXPR: | |
7973 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7974 | break; | |
7975 | op = DW_OP_le; | |
7976 | goto do_binop; | |
7977 | case GE_EXPR: | |
7978 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7979 | break; | |
7980 | op = DW_OP_ge; | |
7981 | goto do_binop; | |
7982 | case LT_EXPR: | |
7983 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7984 | break; | |
7985 | op = DW_OP_lt; | |
7986 | goto do_binop; | |
7987 | case GT_EXPR: | |
7988 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7989 | break; | |
7990 | op = DW_OP_gt; | |
7991 | goto do_binop; | |
7992 | case EQ_EXPR: | |
7993 | op = DW_OP_eq; | |
7994 | goto do_binop; | |
7995 | case NE_EXPR: | |
7996 | op = DW_OP_ne; | |
7997 | goto do_binop; | |
7998 | ||
7999 | do_binop: | |
8000 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
8001 | add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0)); | |
8002 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); | |
8003 | break; | |
8004 | ||
8005 | case BIT_NOT_EXPR: | |
8006 | op = DW_OP_not; | |
8007 | goto do_unop; | |
8008 | case ABS_EXPR: | |
8009 | op = DW_OP_abs; | |
8010 | goto do_unop; | |
8011 | case NEGATE_EXPR: | |
8012 | op = DW_OP_neg; | |
8013 | goto do_unop; | |
8014 | ||
8015 | do_unop: | |
8016 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
8017 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); | |
8018 | break; | |
8019 | ||
8020 | case MAX_EXPR: | |
8021 | loc = build (COND_EXPR, TREE_TYPE (loc), | |
8022 | build (LT_EXPR, integer_type_node, | |
8023 | TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)), | |
8024 | TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0)); | |
8025 | /* FALLTHRU */ | |
8026 | ||
8027 | case COND_EXPR: | |
8028 | { | |
8029 | dw_loc_descr_ref bra_node, jump_node, tmp; | |
8030 | ||
8031 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
8032 | bra_node = new_loc_descr (DW_OP_bra, 0, 0); | |
8033 | add_loc_descr (&ret, bra_node); | |
8034 | ||
8035 | tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0); | |
8036 | add_loc_descr (&ret, tmp); | |
8037 | jump_node = new_loc_descr (DW_OP_skip, 0, 0); | |
8038 | add_loc_descr (&ret, jump_node); | |
8039 | ||
8040 | tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); | |
8041 | add_loc_descr (&ret, tmp); | |
8042 | bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc; | |
8043 | bra_node->dw_loc_oprnd1.v.val_loc = tmp; | |
8044 | ||
8045 | /* ??? Need a node to point the skip at. Use a nop. */ | |
8046 | tmp = new_loc_descr (DW_OP_nop, 0, 0); | |
8047 | add_loc_descr (&ret, tmp); | |
8048 | jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc; | |
8049 | jump_node->dw_loc_oprnd1.v.val_loc = tmp; | |
8050 | } | |
8051 | break; | |
8052 | ||
8053 | default: | |
8054 | abort (); | |
8055 | } | |
8056 | ||
8057 | /* If we can't fill the request for an address, die. */ | |
8058 | if (addressp && indirect_size == 0) | |
8059 | abort (); | |
8060 | ||
8061 | /* If we've got an address and don't want one, dereference. */ | |
8062 | if (!addressp && indirect_size > 0) | |
8063 | { | |
8064 | if (indirect_size > DWARF2_ADDR_SIZE) | |
8065 | abort (); | |
8066 | if (indirect_size == DWARF2_ADDR_SIZE) | |
8067 | op = DW_OP_deref; | |
8068 | else | |
8069 | op = DW_OP_deref_size; | |
8070 | add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0)); | |
8071 | } | |
8072 | ||
8073 | return ret; | |
8074 | } | |
8075 | ||
665f2503 | 8076 | /* Given a value, round it up to the lowest multiple of `boundary' |
a3f97cbb | 8077 | which is not less than the value itself. */ |
71dfc51f | 8078 | |
665f2503 | 8079 | static inline HOST_WIDE_INT |
a3f97cbb | 8080 | ceiling (value, boundary) |
665f2503 RK |
8081 | HOST_WIDE_INT value; |
8082 | unsigned int boundary; | |
a3f97cbb JW |
8083 | { |
8084 | return (((value + boundary - 1) / boundary) * boundary); | |
8085 | } | |
8086 | ||
8087 | /* Given a pointer to what is assumed to be a FIELD_DECL node, return a | |
8088 | pointer to the declared type for the relevant field variable, or return | |
8089 | `integer_type_node' if the given node turns out to be an | |
8090 | ERROR_MARK node. */ | |
71dfc51f RK |
8091 | |
8092 | static inline tree | |
a3f97cbb JW |
8093 | field_type (decl) |
8094 | register tree decl; | |
8095 | { | |
8096 | register tree type; | |
8097 | ||
8098 | if (TREE_CODE (decl) == ERROR_MARK) | |
8099 | return integer_type_node; | |
8100 | ||
8101 | type = DECL_BIT_FIELD_TYPE (decl); | |
71dfc51f | 8102 | if (type == NULL_TREE) |
a3f97cbb JW |
8103 | type = TREE_TYPE (decl); |
8104 | ||
8105 | return type; | |
8106 | } | |
8107 | ||
5f446d21 DD |
8108 | /* Given a pointer to a tree node, return the alignment in bits for |
8109 | it, or else return BITS_PER_WORD if the node actually turns out to | |
8110 | be an ERROR_MARK node. */ | |
71dfc51f RK |
8111 | |
8112 | static inline unsigned | |
a3f97cbb JW |
8113 | simple_type_align_in_bits (type) |
8114 | register tree type; | |
8115 | { | |
8116 | return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; | |
8117 | } | |
8118 | ||
5f446d21 DD |
8119 | static inline unsigned |
8120 | simple_decl_align_in_bits (decl) | |
8121 | register tree decl; | |
8122 | { | |
8123 | return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD; | |
8124 | } | |
8125 | ||
a3f97cbb JW |
8126 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE |
8127 | node, return the size in bits for the type if it is a constant, or else | |
8128 | return the alignment for the type if the type's size is not constant, or | |
8129 | else return BITS_PER_WORD if the type actually turns out to be an | |
8130 | ERROR_MARK node. */ | |
71dfc51f | 8131 | |
665f2503 | 8132 | static inline unsigned HOST_WIDE_INT |
a3f97cbb JW |
8133 | simple_type_size_in_bits (type) |
8134 | register tree type; | |
8135 | { | |
3df18884 RH |
8136 | tree type_size_tree; |
8137 | ||
a3f97cbb JW |
8138 | if (TREE_CODE (type) == ERROR_MARK) |
8139 | return BITS_PER_WORD; | |
3df18884 | 8140 | type_size_tree = TYPE_SIZE (type); |
a3f97cbb | 8141 | |
3df18884 RH |
8142 | if (type_size_tree == NULL_TREE) |
8143 | return 0; | |
8144 | if (! host_integerp (type_size_tree, 1)) | |
8145 | return TYPE_ALIGN (type); | |
8146 | return tree_low_cst (type_size_tree, 1); | |
a3f97cbb JW |
8147 | } |
8148 | ||
8149 | /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and | |
8150 | return the byte offset of the lowest addressed byte of the "containing | |
8151 | object" for the given FIELD_DECL, or return 0 if we are unable to | |
8152 | determine what that offset is, either because the argument turns out to | |
8153 | be a pointer to an ERROR_MARK node, or because the offset is actually | |
8154 | variable. (We can't handle the latter case just yet). */ | |
71dfc51f | 8155 | |
665f2503 | 8156 | static HOST_WIDE_INT |
a3f97cbb JW |
8157 | field_byte_offset (decl) |
8158 | register tree decl; | |
8159 | { | |
665f2503 | 8160 | unsigned int type_align_in_bits; |
5f446d21 | 8161 | unsigned int decl_align_in_bits; |
665f2503 | 8162 | unsigned HOST_WIDE_INT type_size_in_bits; |
665f2503 RK |
8163 | HOST_WIDE_INT object_offset_in_bits; |
8164 | HOST_WIDE_INT object_offset_in_bytes; | |
8165 | tree type; | |
8166 | tree field_size_tree; | |
8167 | HOST_WIDE_INT bitpos_int; | |
8168 | HOST_WIDE_INT deepest_bitpos; | |
8169 | unsigned HOST_WIDE_INT field_size_in_bits; | |
a3f97cbb JW |
8170 | |
8171 | if (TREE_CODE (decl) == ERROR_MARK) | |
8172 | return 0; | |
8173 | ||
8174 | if (TREE_CODE (decl) != FIELD_DECL) | |
8175 | abort (); | |
8176 | ||
8177 | type = field_type (decl); | |
a3f97cbb JW |
8178 | field_size_tree = DECL_SIZE (decl); |
8179 | ||
3df18884 RH |
8180 | /* The size could be unspecified if there was an error, or for |
8181 | a flexible array member. */ | |
50352c9c | 8182 | if (! field_size_tree) |
3df18884 | 8183 | field_size_tree = bitsize_zero_node; |
50352c9c | 8184 | |
556273e0 | 8185 | /* We cannot yet cope with fields whose positions are variable, so |
a3f97cbb JW |
8186 | for now, when we see such things, we simply return 0. Someday, we may |
8187 | be able to handle such cases, but it will be damn difficult. */ | |
665f2503 | 8188 | if (! host_integerp (bit_position (decl), 0)) |
a3f97cbb | 8189 | return 0; |
14a774a9 | 8190 | |
665f2503 | 8191 | bitpos_int = int_bit_position (decl); |
a3f97cbb | 8192 | |
3df18884 | 8193 | /* If we don't know the size of the field, pretend it's a full word. */ |
665f2503 RK |
8194 | if (host_integerp (field_size_tree, 1)) |
8195 | field_size_in_bits = tree_low_cst (field_size_tree, 1); | |
14a774a9 RK |
8196 | else |
8197 | field_size_in_bits = BITS_PER_WORD; | |
a3f97cbb JW |
8198 | |
8199 | type_size_in_bits = simple_type_size_in_bits (type); | |
a3f97cbb | 8200 | type_align_in_bits = simple_type_align_in_bits (type); |
5f446d21 | 8201 | decl_align_in_bits = simple_decl_align_in_bits (decl); |
a3f97cbb JW |
8202 | |
8203 | /* Note that the GCC front-end doesn't make any attempt to keep track of | |
8204 | the starting bit offset (relative to the start of the containing | |
8205 | structure type) of the hypothetical "containing object" for a bit- | |
8206 | field. Thus, when computing the byte offset value for the start of the | |
556273e0 | 8207 | "containing object" of a bit-field, we must deduce this information on |
a3f97cbb JW |
8208 | our own. This can be rather tricky to do in some cases. For example, |
8209 | handling the following structure type definition when compiling for an | |
8210 | i386/i486 target (which only aligns long long's to 32-bit boundaries) | |
8211 | can be very tricky: | |
8212 | ||
8213 | struct S { int field1; long long field2:31; }; | |
8214 | ||
8215 | Fortunately, there is a simple rule-of-thumb which can be | |
8216 | used in such cases. When compiling for an i386/i486, GCC will allocate | |
556273e0 | 8217 | 8 bytes for the structure shown above. It decides to do this based upon |
a3f97cbb JW |
8218 | one simple rule for bit-field allocation. Quite simply, GCC allocates |
8219 | each "containing object" for each bit-field at the first (i.e. lowest | |
8220 | addressed) legitimate alignment boundary (based upon the required | |
8221 | minimum alignment for the declared type of the field) which it can | |
8222 | possibly use, subject to the condition that there is still enough | |
8223 | available space remaining in the containing object (when allocated at | |
8224 | the selected point) to fully accommodate all of the bits of the | |
8225 | bit-field itself. This simple rule makes it obvious why GCC allocates | |
8226 | 8 bytes for each object of the structure type shown above. When looking | |
8227 | for a place to allocate the "containing object" for `field2', the | |
8228 | compiler simply tries to allocate a 64-bit "containing object" at each | |
8229 | successive 32-bit boundary (starting at zero) until it finds a place to | |
8230 | allocate that 64- bit field such that at least 31 contiguous (and | |
8231 | previously unallocated) bits remain within that selected 64 bit field. | |
8232 | (As it turns out, for the example above, the compiler finds that it is | |
8233 | OK to allocate the "containing object" 64-bit field at bit-offset zero | |
8234 | within the structure type.) Here we attempt to work backwards from the | |
556273e0 | 8235 | limited set of facts we're given, and we try to deduce from those facts, |
a3f97cbb | 8236 | where GCC must have believed that the containing object started (within |
556273e0 KH |
8237 | the structure type). The value we deduce is then used (by the callers of |
8238 | this routine) to generate DW_AT_location and DW_AT_bit_offset attributes | |
a3f97cbb JW |
8239 | for fields (both bit-fields and, in the case of DW_AT_location, regular |
8240 | fields as well). */ | |
8241 | ||
8242 | /* Figure out the bit-distance from the start of the structure to the | |
8243 | "deepest" bit of the bit-field. */ | |
8244 | deepest_bitpos = bitpos_int + field_size_in_bits; | |
8245 | ||
8246 | /* This is the tricky part. Use some fancy footwork to deduce where the | |
8247 | lowest addressed bit of the containing object must be. */ | |
5f446d21 DD |
8248 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; |
8249 | ||
8250 | /* Round up to type_align by default. This works best for bitfields. */ | |
8251 | object_offset_in_bits += type_align_in_bits - 1; | |
8252 | object_offset_in_bits /= type_align_in_bits; | |
8253 | object_offset_in_bits *= type_align_in_bits; | |
a3f97cbb | 8254 | |
5f446d21 DD |
8255 | if (object_offset_in_bits > bitpos_int) |
8256 | { | |
8257 | /* Sigh, the decl must be packed. */ | |
8258 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; | |
8259 | ||
8260 | /* Round up to decl_align instead. */ | |
8261 | object_offset_in_bits += decl_align_in_bits - 1; | |
8262 | object_offset_in_bits /= decl_align_in_bits; | |
8263 | object_offset_in_bits *= decl_align_in_bits; | |
8264 | } | |
a3f97cbb | 8265 | |
5f446d21 | 8266 | object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT; |
a3f97cbb JW |
8267 | |
8268 | return object_offset_in_bytes; | |
8269 | } | |
a3f97cbb | 8270 | \f |
71dfc51f RK |
8271 | /* The following routines define various Dwarf attributes and any data |
8272 | associated with them. */ | |
a3f97cbb | 8273 | |
ef76d03b | 8274 | /* Add a location description attribute value to a DIE. |
a3f97cbb | 8275 | |
ef76d03b | 8276 | This emits location attributes suitable for whole variables and |
a3f97cbb JW |
8277 | whole parameters. Note that the location attributes for struct fields are |
8278 | generated by the routine `data_member_location_attribute' below. */ | |
71dfc51f | 8279 | |
a3f97cbb | 8280 | static void |
ef76d03b | 8281 | add_AT_location_description (die, attr_kind, rtl) |
a3f97cbb | 8282 | dw_die_ref die; |
ef76d03b | 8283 | enum dwarf_attribute attr_kind; |
a3f97cbb JW |
8284 | register rtx rtl; |
8285 | { | |
a3f97cbb JW |
8286 | /* Handle a special case. If we are about to output a location descriptor |
8287 | for a variable or parameter which has been optimized out of existence, | |
6a7a9f01 | 8288 | don't do that. A variable which has been optimized out |
a3f97cbb JW |
8289 | of existence will have a DECL_RTL value which denotes a pseudo-reg. |
8290 | Currently, in some rare cases, variables can have DECL_RTL values which | |
8291 | look like (MEM (REG pseudo-reg#)). These cases are due to bugs | |
556273e0 | 8292 | elsewhere in the compiler. We treat such cases as if the variable(s) in |
6a7a9f01 | 8293 | question had been optimized out of existence. */ |
a3f97cbb | 8294 | |
6a7a9f01 JM |
8295 | if (is_pseudo_reg (rtl) |
8296 | || (GET_CODE (rtl) == MEM | |
4401bf24 | 8297 | && is_pseudo_reg (XEXP (rtl, 0))) |
556273e0 | 8298 | /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which |
bce8fed7 JL |
8299 | references the internal argument pointer (a pseudo) in a function |
8300 | where all references to the internal argument pointer were | |
8301 | eliminated via the optimizers. */ | |
8302 | || (GET_CODE (rtl) == MEM | |
8303 | && GET_CODE (XEXP (rtl, 0)) == PLUS | |
8304 | && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0))) | |
4401bf24 JL |
8305 | || (GET_CODE (rtl) == CONCAT |
8306 | && is_pseudo_reg (XEXP (rtl, 0)) | |
8307 | && is_pseudo_reg (XEXP (rtl, 1)))) | |
6a7a9f01 | 8308 | return; |
a3f97cbb | 8309 | |
6a7a9f01 | 8310 | add_AT_loc (die, attr_kind, loc_descriptor (rtl)); |
a3f97cbb JW |
8311 | } |
8312 | ||
8313 | /* Attach the specialized form of location attribute used for data | |
8314 | members of struct and union types. In the special case of a | |
8315 | FIELD_DECL node which represents a bit-field, the "offset" part | |
8316 | of this special location descriptor must indicate the distance | |
8317 | in bytes from the lowest-addressed byte of the containing struct | |
8318 | or union type to the lowest-addressed byte of the "containing | |
8319 | object" for the bit-field. (See the `field_byte_offset' function | |
8320 | above).. For any given bit-field, the "containing object" is a | |
8321 | hypothetical object (of some integral or enum type) within which | |
8322 | the given bit-field lives. The type of this hypothetical | |
8323 | "containing object" is always the same as the declared type of | |
8324 | the individual bit-field itself (for GCC anyway... the DWARF | |
8325 | spec doesn't actually mandate this). Note that it is the size | |
8326 | (in bytes) of the hypothetical "containing object" which will | |
8327 | be given in the DW_AT_byte_size attribute for this bit-field. | |
8328 | (See the `byte_size_attribute' function below.) It is also used | |
8329 | when calculating the value of the DW_AT_bit_offset attribute. | |
8330 | (See the `bit_offset_attribute' function below). */ | |
71dfc51f | 8331 | |
a3f97cbb JW |
8332 | static void |
8333 | add_data_member_location_attribute (die, decl) | |
8334 | register dw_die_ref die; | |
8335 | register tree decl; | |
8336 | { | |
61b32c02 | 8337 | register unsigned long offset; |
a3f97cbb JW |
8338 | register dw_loc_descr_ref loc_descr; |
8339 | register enum dwarf_location_atom op; | |
8340 | ||
61b32c02 | 8341 | if (TREE_CODE (decl) == TREE_VEC) |
665f2503 | 8342 | offset = tree_low_cst (BINFO_OFFSET (decl), 0); |
61b32c02 JM |
8343 | else |
8344 | offset = field_byte_offset (decl); | |
8345 | ||
a3f97cbb JW |
8346 | /* The DWARF2 standard says that we should assume that the structure address |
8347 | is already on the stack, so we can specify a structure field address | |
8348 | by using DW_OP_plus_uconst. */ | |
71dfc51f | 8349 | |
a3f97cbb JW |
8350 | #ifdef MIPS_DEBUGGING_INFO |
8351 | /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator | |
8352 | correctly. It works only if we leave the offset on the stack. */ | |
8353 | op = DW_OP_constu; | |
8354 | #else | |
8355 | op = DW_OP_plus_uconst; | |
8356 | #endif | |
71dfc51f | 8357 | |
a3f97cbb JW |
8358 | loc_descr = new_loc_descr (op, offset, 0); |
8359 | add_AT_loc (die, DW_AT_data_member_location, loc_descr); | |
8360 | } | |
8361 | ||
8362 | /* Attach an DW_AT_const_value attribute for a variable or a parameter which | |
8363 | does not have a "location" either in memory or in a register. These | |
8364 | things can arise in GNU C when a constant is passed as an actual parameter | |
8365 | to an inlined function. They can also arise in C++ where declared | |
8366 | constants do not necessarily get memory "homes". */ | |
71dfc51f | 8367 | |
a3f97cbb JW |
8368 | static void |
8369 | add_const_value_attribute (die, rtl) | |
8370 | register dw_die_ref die; | |
8371 | register rtx rtl; | |
8372 | { | |
8373 | switch (GET_CODE (rtl)) | |
8374 | { | |
8375 | case CONST_INT: | |
2e4b9b8c RH |
8376 | /* Note that a CONST_INT rtx could represent either an integer |
8377 | or a floating-point constant. A CONST_INT is used whenever | |
8378 | the constant will fit into a single word. In all such | |
8379 | cases, the original mode of the constant value is wiped | |
8380 | out, and the CONST_INT rtx is assigned VOIDmode. */ | |
8381 | { | |
8382 | HOST_WIDE_INT val = INTVAL (rtl); | |
8383 | ||
8384 | /* ??? We really should be using HOST_WIDE_INT throughout. */ | |
8385 | if (val < 0) | |
8386 | { | |
8387 | if ((long) val != val) | |
8388 | abort (); | |
8389 | add_AT_int (die, DW_AT_const_value, (long) val); | |
8390 | } | |
8391 | else | |
8392 | { | |
8393 | if ((unsigned long) val != (unsigned HOST_WIDE_INT) val) | |
8394 | abort (); | |
732910b9 | 8395 | add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val); |
2e4b9b8c RH |
8396 | } |
8397 | } | |
a3f97cbb JW |
8398 | break; |
8399 | ||
8400 | case CONST_DOUBLE: | |
8401 | /* Note that a CONST_DOUBLE rtx could represent either an integer or a | |
8402 | floating-point constant. A CONST_DOUBLE is used whenever the | |
8403 | constant requires more than one word in order to be adequately | |
469ac993 JM |
8404 | represented. We output CONST_DOUBLEs as blocks. */ |
8405 | { | |
8406 | register enum machine_mode mode = GET_MODE (rtl); | |
8407 | ||
8408 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
8409 | { | |
e389897b | 8410 | register unsigned length = GET_MODE_SIZE (mode) / 4; |
1bfb5f8f | 8411 | long *array = (long *) xmalloc (sizeof (long) * length); |
71dfc51f | 8412 | REAL_VALUE_TYPE rv; |
469ac993 | 8413 | |
71dfc51f | 8414 | REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl); |
469ac993 JM |
8415 | switch (mode) |
8416 | { | |
8417 | case SFmode: | |
71dfc51f | 8418 | REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]); |
469ac993 JM |
8419 | break; |
8420 | ||
8421 | case DFmode: | |
71dfc51f | 8422 | REAL_VALUE_TO_TARGET_DOUBLE (rv, array); |
469ac993 JM |
8423 | break; |
8424 | ||
8425 | case XFmode: | |
8426 | case TFmode: | |
71dfc51f | 8427 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array); |
469ac993 JM |
8428 | break; |
8429 | ||
8430 | default: | |
8431 | abort (); | |
8432 | } | |
8433 | ||
469ac993 JM |
8434 | add_AT_float (die, DW_AT_const_value, length, array); |
8435 | } | |
8436 | else | |
2e4b9b8c RH |
8437 | { |
8438 | /* ??? We really should be using HOST_WIDE_INT throughout. */ | |
8439 | if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT) | |
8440 | abort (); | |
8441 | add_AT_long_long (die, DW_AT_const_value, | |
8442 | CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl)); | |
8443 | } | |
469ac993 | 8444 | } |
a3f97cbb JW |
8445 | break; |
8446 | ||
8447 | case CONST_STRING: | |
8448 | add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0)); | |
8449 | break; | |
8450 | ||
8451 | case SYMBOL_REF: | |
8452 | case LABEL_REF: | |
8453 | case CONST: | |
1865dbb5 | 8454 | add_AT_addr (die, DW_AT_const_value, save_rtx (rtl)); |
a3f97cbb JW |
8455 | break; |
8456 | ||
8457 | case PLUS: | |
8458 | /* In cases where an inlined instance of an inline function is passed | |
8459 | the address of an `auto' variable (which is local to the caller) we | |
8460 | can get a situation where the DECL_RTL of the artificial local | |
8461 | variable (for the inlining) which acts as a stand-in for the | |
8462 | corresponding formal parameter (of the inline function) will look | |
8463 | like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not | |
556273e0 KH |
8464 | exactly a compile-time constant expression, but it isn't the address |
8465 | of the (artificial) local variable either. Rather, it represents the | |
a3f97cbb | 8466 | *value* which the artificial local variable always has during its |
556273e0 | 8467 | lifetime. We currently have no way to represent such quasi-constant |
6a7a9f01 | 8468 | values in Dwarf, so for now we just punt and generate nothing. */ |
a3f97cbb JW |
8469 | break; |
8470 | ||
8471 | default: | |
8472 | /* No other kinds of rtx should be possible here. */ | |
8473 | abort (); | |
8474 | } | |
8475 | ||
8476 | } | |
8477 | ||
d8041cc8 RH |
8478 | static rtx |
8479 | rtl_for_decl_location (decl) | |
8480 | tree decl; | |
a3f97cbb JW |
8481 | { |
8482 | register rtx rtl; | |
71dfc51f | 8483 | |
a3f97cbb JW |
8484 | /* Here we have to decide where we are going to say the parameter "lives" |
8485 | (as far as the debugger is concerned). We only have a couple of | |
8486 | choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. | |
71dfc51f | 8487 | |
556273e0 | 8488 | DECL_RTL normally indicates where the parameter lives during most of the |
71dfc51f | 8489 | activation of the function. If optimization is enabled however, this |
556273e0 | 8490 | could be either NULL or else a pseudo-reg. Both of those cases indicate |
a3f97cbb JW |
8491 | that the parameter doesn't really live anywhere (as far as the code |
8492 | generation parts of GCC are concerned) during most of the function's | |
8493 | activation. That will happen (for example) if the parameter is never | |
71dfc51f RK |
8494 | referenced within the function. |
8495 | ||
8496 | We could just generate a location descriptor here for all non-NULL | |
8497 | non-pseudo values of DECL_RTL and ignore all of the rest, but we can be | |
8498 | a little nicer than that if we also consider DECL_INCOMING_RTL in cases | |
8499 | where DECL_RTL is NULL or is a pseudo-reg. | |
8500 | ||
8501 | Note however that we can only get away with using DECL_INCOMING_RTL as | |
8502 | a backup substitute for DECL_RTL in certain limited cases. In cases | |
8503 | where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl), | |
8504 | we can be sure that the parameter was passed using the same type as it is | |
8505 | declared to have within the function, and that its DECL_INCOMING_RTL | |
8506 | points us to a place where a value of that type is passed. | |
8507 | ||
8508 | In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different, | |
8509 | we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL | |
8510 | because in these cases DECL_INCOMING_RTL points us to a value of some | |
8511 | type which is *different* from the type of the parameter itself. Thus, | |
8512 | if we tried to use DECL_INCOMING_RTL to generate a location attribute in | |
8513 | such cases, the debugger would end up (for example) trying to fetch a | |
8514 | `float' from a place which actually contains the first part of a | |
8515 | `double'. That would lead to really incorrect and confusing | |
8516 | output at debug-time. | |
8517 | ||
8518 | So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL | |
8519 | in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There | |
8520 | are a couple of exceptions however. On little-endian machines we can | |
8521 | get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is | |
8522 | not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is | |
8523 | an integral type that is smaller than TREE_TYPE (decl). These cases arise | |
8524 | when (on a little-endian machine) a non-prototyped function has a | |
8525 | parameter declared to be of type `short' or `char'. In such cases, | |
8526 | TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will | |
8527 | be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the | |
8528 | passed `int' value. If the debugger then uses that address to fetch | |
8529 | a `short' or a `char' (on a little-endian machine) the result will be | |
8530 | the correct data, so we allow for such exceptional cases below. | |
8531 | ||
8532 | Note that our goal here is to describe the place where the given formal | |
8533 | parameter lives during most of the function's activation (i.e. between | |
8534 | the end of the prologue and the start of the epilogue). We'll do that | |
8535 | as best as we can. Note however that if the given formal parameter is | |
8536 | modified sometime during the execution of the function, then a stack | |
8537 | backtrace (at debug-time) will show the function as having been | |
8538 | called with the *new* value rather than the value which was | |
8539 | originally passed in. This happens rarely enough that it is not | |
8540 | a major problem, but it *is* a problem, and I'd like to fix it. | |
8541 | ||
8542 | A future version of dwarf2out.c may generate two additional | |
8543 | attributes for any given DW_TAG_formal_parameter DIE which will | |
8544 | describe the "passed type" and the "passed location" for the | |
8545 | given formal parameter in addition to the attributes we now | |
8546 | generate to indicate the "declared type" and the "active | |
8547 | location" for each parameter. This additional set of attributes | |
8548 | could be used by debuggers for stack backtraces. Separately, note | |
8549 | that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be | |
8550 | NULL also. This happens (for example) for inlined-instances of | |
8551 | inline function formal parameters which are never referenced. | |
8552 | This really shouldn't be happening. All PARM_DECL nodes should | |
8553 | get valid non-NULL DECL_INCOMING_RTL values, but integrate.c | |
8554 | doesn't currently generate these values for inlined instances of | |
8555 | inline function parameters, so when we see such cases, we are | |
956d6950 | 8556 | just out-of-luck for the time being (until integrate.c |
a3f97cbb JW |
8557 | gets fixed). */ |
8558 | ||
8559 | /* Use DECL_RTL as the "location" unless we find something better. */ | |
110c3568 | 8560 | rtl = DECL_RTL_IF_SET (decl); |
a3f97cbb JW |
8561 | |
8562 | if (TREE_CODE (decl) == PARM_DECL) | |
8563 | { | |
8564 | if (rtl == NULL_RTX || is_pseudo_reg (rtl)) | |
8565 | { | |
d8041cc8 RH |
8566 | tree declared_type = type_main_variant (TREE_TYPE (decl)); |
8567 | tree passed_type = type_main_variant (DECL_ARG_TYPE (decl)); | |
a3f97cbb | 8568 | |
71dfc51f | 8569 | /* This decl represents a formal parameter which was optimized out. |
a3f97cbb JW |
8570 | Note that DECL_INCOMING_RTL may be NULL in here, but we handle |
8571 | all* cases where (rtl == NULL_RTX) just below. */ | |
8572 | if (declared_type == passed_type) | |
71dfc51f RK |
8573 | rtl = DECL_INCOMING_RTL (decl); |
8574 | else if (! BYTES_BIG_ENDIAN | |
8575 | && TREE_CODE (declared_type) == INTEGER_TYPE | |
555b6442 HPN |
8576 | && (GET_MODE_SIZE (TYPE_MODE (declared_type)) |
8577 | <= GET_MODE_SIZE (TYPE_MODE (passed_type)))) | |
556273e0 | 8578 | rtl = DECL_INCOMING_RTL (decl); |
a3f97cbb | 8579 | } |
5a904a61 JW |
8580 | |
8581 | /* If the parm was passed in registers, but lives on the stack, then | |
8582 | make a big endian correction if the mode of the type of the | |
8583 | parameter is not the same as the mode of the rtl. */ | |
8584 | /* ??? This is the same series of checks that are made in dbxout.c before | |
8585 | we reach the big endian correction code there. It isn't clear if all | |
8586 | of these checks are necessary here, but keeping them all is the safe | |
8587 | thing to do. */ | |
8588 | else if (GET_CODE (rtl) == MEM | |
8589 | && XEXP (rtl, 0) != const0_rtx | |
8590 | && ! CONSTANT_P (XEXP (rtl, 0)) | |
8591 | /* Not passed in memory. */ | |
8592 | && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM | |
8593 | /* Not passed by invisible reference. */ | |
8594 | && (GET_CODE (XEXP (rtl, 0)) != REG | |
8595 | || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM | |
8596 | || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM | |
8597 | #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM | |
8598 | || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM | |
8599 | #endif | |
8600 | ) | |
8601 | /* Big endian correction check. */ | |
8602 | && BYTES_BIG_ENDIAN | |
8603 | && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl) | |
8604 | && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))) | |
8605 | < UNITS_PER_WORD)) | |
8606 | { | |
8607 | int offset = (UNITS_PER_WORD | |
8608 | - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))); | |
8609 | rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)), | |
8610 | plus_constant (XEXP (rtl, 0), offset)); | |
8611 | } | |
a3f97cbb | 8612 | } |
71dfc51f | 8613 | |
d8041cc8 RH |
8614 | if (rtl != NULL_RTX) |
8615 | { | |
8616 | rtl = eliminate_regs (rtl, 0, NULL_RTX); | |
6a7a9f01 | 8617 | #ifdef LEAF_REG_REMAP |
d8041cc8 RH |
8618 | if (current_function_uses_only_leaf_regs) |
8619 | leaf_renumber_regs_insn (rtl); | |
6a7a9f01 | 8620 | #endif |
d8041cc8 RH |
8621 | } |
8622 | ||
8623 | return rtl; | |
8624 | } | |
8625 | ||
8626 | /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value | |
8627 | data attribute for a variable or a parameter. We generate the | |
8628 | DW_AT_const_value attribute only in those cases where the given variable | |
8629 | or parameter does not have a true "location" either in memory or in a | |
8630 | register. This can happen (for example) when a constant is passed as an | |
8631 | actual argument in a call to an inline function. (It's possible that | |
8632 | these things can crop up in other ways also.) Note that one type of | |
8633 | constant value which can be passed into an inlined function is a constant | |
8634 | pointer. This can happen for example if an actual argument in an inlined | |
8635 | function call evaluates to a compile-time constant address. */ | |
8636 | ||
8637 | static void | |
8638 | add_location_or_const_value_attribute (die, decl) | |
8639 | register dw_die_ref die; | |
8640 | register tree decl; | |
8641 | { | |
8642 | register rtx rtl; | |
8643 | ||
8644 | if (TREE_CODE (decl) == ERROR_MARK) | |
8645 | return; | |
8646 | ||
8647 | if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL) | |
8648 | abort (); | |
8649 | ||
8650 | rtl = rtl_for_decl_location (decl); | |
a97c9600 RH |
8651 | if (rtl == NULL_RTX) |
8652 | return; | |
6a7a9f01 | 8653 | |
732910b9 RH |
8654 | /* If we don't look past the constant pool, we risk emitting a |
8655 | reference to a constant pool entry that isn't referenced from | |
8656 | code, and thus is not emitted. */ | |
8657 | rtl = avoid_constant_pool_reference (rtl); | |
8658 | ||
a3f97cbb JW |
8659 | switch (GET_CODE (rtl)) |
8660 | { | |
e9a25f70 JL |
8661 | case ADDRESSOF: |
8662 | /* The address of a variable that was optimized away; don't emit | |
8663 | anything. */ | |
8664 | break; | |
8665 | ||
a3f97cbb JW |
8666 | case CONST_INT: |
8667 | case CONST_DOUBLE: | |
8668 | case CONST_STRING: | |
8669 | case SYMBOL_REF: | |
8670 | case LABEL_REF: | |
8671 | case CONST: | |
8672 | case PLUS: | |
8673 | /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ | |
8674 | add_const_value_attribute (die, rtl); | |
8675 | break; | |
8676 | ||
8677 | case MEM: | |
8678 | case REG: | |
8679 | case SUBREG: | |
4401bf24 | 8680 | case CONCAT: |
ef76d03b | 8681 | add_AT_location_description (die, DW_AT_location, rtl); |
a3f97cbb JW |
8682 | break; |
8683 | ||
8684 | default: | |
71dfc51f | 8685 | abort (); |
a3f97cbb JW |
8686 | } |
8687 | } | |
8688 | ||
1bfb5f8f JM |
8689 | /* If we don't have a copy of this variable in memory for some reason (such |
8690 | as a C++ member constant that doesn't have an out-of-line definition), | |
8691 | we should tell the debugger about the constant value. */ | |
8692 | ||
8693 | static void | |
8694 | tree_add_const_value_attribute (var_die, decl) | |
8695 | dw_die_ref var_die; | |
8696 | tree decl; | |
8697 | { | |
8698 | tree init = DECL_INITIAL (decl); | |
8699 | tree type = TREE_TYPE (decl); | |
8700 | ||
8701 | if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init | |
8702 | && initializer_constant_valid_p (init, type) == null_pointer_node) | |
8703 | /* OK */; | |
8704 | else | |
8705 | return; | |
8706 | ||
8707 | switch (TREE_CODE (type)) | |
8708 | { | |
8709 | case INTEGER_TYPE: | |
8710 | if (host_integerp (init, 0)) | |
8711 | add_AT_unsigned (var_die, DW_AT_const_value, | |
8712 | TREE_INT_CST_LOW (init)); | |
8713 | else | |
8714 | add_AT_long_long (var_die, DW_AT_const_value, | |
8715 | TREE_INT_CST_HIGH (init), | |
8716 | TREE_INT_CST_LOW (init)); | |
8717 | break; | |
8718 | ||
8719 | default:; | |
8720 | } | |
8721 | } | |
0b34cf1e | 8722 | |
a3f97cbb JW |
8723 | /* Generate an DW_AT_name attribute given some string value to be included as |
8724 | the value of the attribute. */ | |
71dfc51f RK |
8725 | |
8726 | static inline void | |
a3f97cbb JW |
8727 | add_name_attribute (die, name_string) |
8728 | register dw_die_ref die; | |
d560ee52 | 8729 | register const char *name_string; |
a3f97cbb | 8730 | { |
71dfc51f | 8731 | if (name_string != NULL && *name_string != 0) |
14a774a9 RK |
8732 | { |
8733 | if (demangle_name_func) | |
8734 | name_string = (*demangle_name_func) (name_string); | |
8735 | ||
8736 | add_AT_string (die, DW_AT_name, name_string); | |
8737 | } | |
a3f97cbb JW |
8738 | } |
8739 | ||
8740 | /* Given a tree node describing an array bound (either lower or upper) output | |
466446b0 | 8741 | a representation for that bound. */ |
71dfc51f | 8742 | |
a3f97cbb JW |
8743 | static void |
8744 | add_bound_info (subrange_die, bound_attr, bound) | |
8745 | register dw_die_ref subrange_die; | |
8746 | register enum dwarf_attribute bound_attr; | |
8747 | register tree bound; | |
8748 | { | |
ef76d03b JW |
8749 | /* If this is an Ada unconstrained array type, then don't emit any debug |
8750 | info because the array bounds are unknown. They are parameterized when | |
8751 | the type is instantiated. */ | |
8752 | if (contains_placeholder_p (bound)) | |
8753 | return; | |
8754 | ||
a3f97cbb JW |
8755 | switch (TREE_CODE (bound)) |
8756 | { | |
8757 | case ERROR_MARK: | |
8758 | return; | |
8759 | ||
8760 | /* All fixed-bounds are represented by INTEGER_CST nodes. */ | |
8761 | case INTEGER_CST: | |
665f2503 RK |
8762 | if (! host_integerp (bound, 0) |
8763 | || (bound_attr == DW_AT_lower_bound | |
28985b81 | 8764 | && (((is_c_family () || is_java ()) && integer_zerop (bound)) |
665f2503 RK |
8765 | || (is_fortran () && integer_onep (bound))))) |
8766 | /* use the default */ | |
8767 | ; | |
141719a8 | 8768 | else |
665f2503 | 8769 | add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0)); |
a3f97cbb JW |
8770 | break; |
8771 | ||
b1ccbc24 | 8772 | case CONVERT_EXPR: |
a3f97cbb | 8773 | case NOP_EXPR: |
b1ccbc24 RK |
8774 | case NON_LVALUE_EXPR: |
8775 | add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0)); | |
8776 | break; | |
556273e0 | 8777 | |
a3f97cbb JW |
8778 | case SAVE_EXPR: |
8779 | /* If optimization is turned on, the SAVE_EXPRs that describe how to | |
466446b0 JM |
8780 | access the upper bound values may be bogus. If they refer to a |
8781 | register, they may only describe how to get at these values at the | |
8782 | points in the generated code right after they have just been | |
8783 | computed. Worse yet, in the typical case, the upper bound values | |
8784 | will not even *be* computed in the optimized code (though the | |
8785 | number of elements will), so these SAVE_EXPRs are entirely | |
8786 | bogus. In order to compensate for this fact, we check here to see | |
8787 | if optimization is enabled, and if so, we don't add an attribute | |
8788 | for the (unknown and unknowable) upper bound. This should not | |
8789 | cause too much trouble for existing (stupid?) debuggers because | |
8790 | they have to deal with empty upper bounds location descriptions | |
8791 | anyway in order to be able to deal with incomplete array types. | |
8792 | Of course an intelligent debugger (GDB?) should be able to | |
8793 | comprehend that a missing upper bound specification in a array | |
8794 | type used for a storage class `auto' local array variable | |
8795 | indicates that the upper bound is both unknown (at compile- time) | |
8796 | and unknowable (at run-time) due to optimization. | |
8797 | ||
8798 | We assume that a MEM rtx is safe because gcc wouldn't put the | |
8799 | value there unless it was going to be used repeatedly in the | |
8800 | function, i.e. for cleanups. */ | |
1edf43d6 JM |
8801 | if (SAVE_EXPR_RTL (bound) |
8802 | && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)) | |
a3f97cbb | 8803 | { |
466446b0 JM |
8804 | register dw_die_ref ctx = lookup_decl_die (current_function_decl); |
8805 | register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx); | |
f5963e61 JL |
8806 | register rtx loc = SAVE_EXPR_RTL (bound); |
8807 | ||
8808 | /* If the RTL for the SAVE_EXPR is memory, handle the case where | |
8809 | it references an outer function's frame. */ | |
8810 | ||
8811 | if (GET_CODE (loc) == MEM) | |
8812 | { | |
8813 | rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound); | |
8814 | ||
8815 | if (XEXP (loc, 0) != new_addr) | |
c5c76735 | 8816 | loc = gen_rtx_MEM (GET_MODE (loc), new_addr); |
f5963e61 JL |
8817 | } |
8818 | ||
466446b0 JM |
8819 | add_AT_flag (decl_die, DW_AT_artificial, 1); |
8820 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
f5963e61 | 8821 | add_AT_location_description (decl_die, DW_AT_location, loc); |
466446b0 | 8822 | add_AT_die_ref (subrange_die, bound_attr, decl_die); |
a3f97cbb | 8823 | } |
71dfc51f RK |
8824 | |
8825 | /* Else leave out the attribute. */ | |
a3f97cbb | 8826 | break; |
3f76745e | 8827 | |
ef76d03b | 8828 | case VAR_DECL: |
d8041cc8 RH |
8829 | case PARM_DECL: |
8830 | { | |
8831 | dw_die_ref decl_die = lookup_decl_die (bound); | |
8832 | ||
8833 | /* ??? Can this happen, or should the variable have been bound | |
8834 | first? Probably it can, since I imagine that we try to create | |
8835 | the types of parameters in the order in which they exist in | |
0b34cf1e | 8836 | the list, and won't have created a forward reference to a |
d8041cc8 RH |
8837 | later parameter. */ |
8838 | if (decl_die != NULL) | |
8839 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
8840 | break; | |
8841 | } | |
ef76d03b | 8842 | |
3f76745e | 8843 | default: |
d8041cc8 RH |
8844 | { |
8845 | /* Otherwise try to create a stack operation procedure to | |
8846 | evaluate the value of the array bound. */ | |
8847 | ||
8848 | dw_die_ref ctx, decl_die; | |
8849 | dw_loc_descr_ref loc; | |
8850 | ||
8851 | loc = loc_descriptor_from_tree (bound, 0); | |
8852 | if (loc == NULL) | |
8853 | break; | |
8854 | ||
8855 | ctx = lookup_decl_die (current_function_decl); | |
8856 | ||
8857 | decl_die = new_die (DW_TAG_variable, ctx); | |
8858 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
8859 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
8860 | add_AT_loc (decl_die, DW_AT_location, loc); | |
8861 | ||
8862 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
8863 | break; | |
8864 | } | |
a3f97cbb JW |
8865 | } |
8866 | } | |
8867 | ||
8868 | /* Note that the block of subscript information for an array type also | |
8869 | includes information about the element type of type given array type. */ | |
71dfc51f | 8870 | |
a3f97cbb JW |
8871 | static void |
8872 | add_subscript_info (type_die, type) | |
8873 | register dw_die_ref type_die; | |
8874 | register tree type; | |
8875 | { | |
081f5e7e | 8876 | #ifndef MIPS_DEBUGGING_INFO |
a3f97cbb | 8877 | register unsigned dimension_number; |
081f5e7e | 8878 | #endif |
a3f97cbb JW |
8879 | register tree lower, upper; |
8880 | register dw_die_ref subrange_die; | |
8881 | ||
556273e0 | 8882 | /* The GNU compilers represent multidimensional array types as sequences of |
a3f97cbb JW |
8883 | one dimensional array types whose element types are themselves array |
8884 | types. Here we squish that down, so that each multidimensional array | |
556273e0 | 8885 | type gets only one array_type DIE in the Dwarf debugging info. The draft |
a3f97cbb JW |
8886 | Dwarf specification say that we are allowed to do this kind of |
8887 | compression in C (because there is no difference between an array or | |
556273e0 | 8888 | arrays and a multidimensional array in C) but for other source languages |
a3f97cbb | 8889 | (e.g. Ada) we probably shouldn't do this. */ |
71dfc51f | 8890 | |
a3f97cbb JW |
8891 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
8892 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
8893 | We work around this by disabling this feature. See also | |
8894 | gen_array_type_die. */ | |
8895 | #ifndef MIPS_DEBUGGING_INFO | |
8896 | for (dimension_number = 0; | |
8897 | TREE_CODE (type) == ARRAY_TYPE; | |
8898 | type = TREE_TYPE (type), dimension_number++) | |
8899 | { | |
8900 | #endif | |
8901 | register tree domain = TYPE_DOMAIN (type); | |
8902 | ||
8903 | /* Arrays come in three flavors: Unspecified bounds, fixed bounds, | |
556273e0 | 8904 | and (in GNU C only) variable bounds. Handle all three forms |
a3f97cbb JW |
8905 | here. */ |
8906 | subrange_die = new_die (DW_TAG_subrange_type, type_die); | |
8907 | if (domain) | |
8908 | { | |
8909 | /* We have an array type with specified bounds. */ | |
8910 | lower = TYPE_MIN_VALUE (domain); | |
8911 | upper = TYPE_MAX_VALUE (domain); | |
8912 | ||
a9d38797 JM |
8913 | /* define the index type. */ |
8914 | if (TREE_TYPE (domain)) | |
ef76d03b JW |
8915 | { |
8916 | /* ??? This is probably an Ada unnamed subrange type. Ignore the | |
8917 | TREE_TYPE field. We can't emit debug info for this | |
8918 | because it is an unnamed integral type. */ | |
8919 | if (TREE_CODE (domain) == INTEGER_TYPE | |
8920 | && TYPE_NAME (domain) == NULL_TREE | |
8921 | && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE | |
8922 | && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE) | |
556273e0 | 8923 | ; |
ef76d03b JW |
8924 | else |
8925 | add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0, | |
8926 | type_die); | |
8927 | } | |
a9d38797 | 8928 | |
e1ee5cdc RH |
8929 | /* ??? If upper is NULL, the array has unspecified length, |
8930 | but it does have a lower bound. This happens with Fortran | |
8931 | dimension arr(N:*) | |
8932 | Since the debugger is definitely going to need to know N | |
8933 | to produce useful results, go ahead and output the lower | |
8934 | bound solo, and hope the debugger can cope. */ | |
8935 | ||
141719a8 | 8936 | add_bound_info (subrange_die, DW_AT_lower_bound, lower); |
e1ee5cdc RH |
8937 | if (upper) |
8938 | add_bound_info (subrange_die, DW_AT_upper_bound, upper); | |
a3f97cbb JW |
8939 | } |
8940 | else | |
71dfc51f | 8941 | /* We have an array type with an unspecified length. The DWARF-2 |
a9d38797 JM |
8942 | spec does not say how to handle this; let's just leave out the |
8943 | bounds. */ | |
e49a1d2e | 8944 | {;} |
71dfc51f | 8945 | |
a3f97cbb JW |
8946 | #ifndef MIPS_DEBUGGING_INFO |
8947 | } | |
8948 | #endif | |
8949 | } | |
8950 | ||
8951 | static void | |
8952 | add_byte_size_attribute (die, tree_node) | |
8953 | dw_die_ref die; | |
8954 | register tree tree_node; | |
8955 | { | |
8956 | register unsigned size; | |
8957 | ||
8958 | switch (TREE_CODE (tree_node)) | |
8959 | { | |
8960 | case ERROR_MARK: | |
8961 | size = 0; | |
8962 | break; | |
8963 | case ENUMERAL_TYPE: | |
8964 | case RECORD_TYPE: | |
8965 | case UNION_TYPE: | |
8966 | case QUAL_UNION_TYPE: | |
8967 | size = int_size_in_bytes (tree_node); | |
8968 | break; | |
8969 | case FIELD_DECL: | |
8970 | /* For a data member of a struct or union, the DW_AT_byte_size is | |
8971 | generally given as the number of bytes normally allocated for an | |
8972 | object of the *declared* type of the member itself. This is true | |
8973 | even for bit-fields. */ | |
8974 | size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT; | |
8975 | break; | |
8976 | default: | |
8977 | abort (); | |
8978 | } | |
8979 | ||
8980 | /* Note that `size' might be -1 when we get to this point. If it is, that | |
8981 | indicates that the byte size of the entity in question is variable. We | |
8982 | have no good way of expressing this fact in Dwarf at the present time, | |
8983 | so just let the -1 pass on through. */ | |
8984 | ||
8985 | add_AT_unsigned (die, DW_AT_byte_size, size); | |
8986 | } | |
8987 | ||
8988 | /* For a FIELD_DECL node which represents a bit-field, output an attribute | |
8989 | which specifies the distance in bits from the highest order bit of the | |
8990 | "containing object" for the bit-field to the highest order bit of the | |
8991 | bit-field itself. | |
8992 | ||
b2932ae5 JM |
8993 | For any given bit-field, the "containing object" is a hypothetical |
8994 | object (of some integral or enum type) within which the given bit-field | |
8995 | lives. The type of this hypothetical "containing object" is always the | |
8996 | same as the declared type of the individual bit-field itself. The | |
8997 | determination of the exact location of the "containing object" for a | |
8998 | bit-field is rather complicated. It's handled by the | |
8999 | `field_byte_offset' function (above). | |
a3f97cbb JW |
9000 | |
9001 | Note that it is the size (in bytes) of the hypothetical "containing object" | |
9002 | which will be given in the DW_AT_byte_size attribute for this bit-field. | |
9003 | (See `byte_size_attribute' above). */ | |
71dfc51f RK |
9004 | |
9005 | static inline void | |
a3f97cbb JW |
9006 | add_bit_offset_attribute (die, decl) |
9007 | register dw_die_ref die; | |
9008 | register tree decl; | |
9009 | { | |
665f2503 RK |
9010 | HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl); |
9011 | tree type = DECL_BIT_FIELD_TYPE (decl); | |
9012 | HOST_WIDE_INT bitpos_int; | |
9013 | HOST_WIDE_INT highest_order_object_bit_offset; | |
9014 | HOST_WIDE_INT highest_order_field_bit_offset; | |
9015 | HOST_WIDE_INT unsigned bit_offset; | |
a3f97cbb | 9016 | |
3a88cbd1 JL |
9017 | /* Must be a field and a bit field. */ |
9018 | if (!type | |
9019 | || TREE_CODE (decl) != FIELD_DECL) | |
9020 | abort (); | |
a3f97cbb JW |
9021 | |
9022 | /* We can't yet handle bit-fields whose offsets are variable, so if we | |
9023 | encounter such things, just return without generating any attribute | |
665f2503 RK |
9024 | whatsoever. Likewise for variable or too large size. */ |
9025 | if (! host_integerp (bit_position (decl), 0) | |
9026 | || ! host_integerp (DECL_SIZE (decl), 1)) | |
71dfc51f RK |
9027 | return; |
9028 | ||
665f2503 | 9029 | bitpos_int = int_bit_position (decl); |
a3f97cbb JW |
9030 | |
9031 | /* Note that the bit offset is always the distance (in bits) from the | |
556273e0 KH |
9032 | highest-order bit of the "containing object" to the highest-order bit of |
9033 | the bit-field itself. Since the "high-order end" of any object or field | |
a3f97cbb JW |
9034 | is different on big-endian and little-endian machines, the computation |
9035 | below must take account of these differences. */ | |
9036 | highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; | |
9037 | highest_order_field_bit_offset = bitpos_int; | |
9038 | ||
71dfc51f | 9039 | if (! BYTES_BIG_ENDIAN) |
a3f97cbb | 9040 | { |
665f2503 | 9041 | highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0); |
a3f97cbb JW |
9042 | highest_order_object_bit_offset += simple_type_size_in_bits (type); |
9043 | } | |
71dfc51f RK |
9044 | |
9045 | bit_offset | |
9046 | = (! BYTES_BIG_ENDIAN | |
9047 | ? highest_order_object_bit_offset - highest_order_field_bit_offset | |
9048 | : highest_order_field_bit_offset - highest_order_object_bit_offset); | |
a3f97cbb JW |
9049 | |
9050 | add_AT_unsigned (die, DW_AT_bit_offset, bit_offset); | |
9051 | } | |
9052 | ||
9053 | /* For a FIELD_DECL node which represents a bit field, output an attribute | |
9054 | which specifies the length in bits of the given field. */ | |
71dfc51f RK |
9055 | |
9056 | static inline void | |
a3f97cbb JW |
9057 | add_bit_size_attribute (die, decl) |
9058 | register dw_die_ref die; | |
9059 | register tree decl; | |
9060 | { | |
3a88cbd1 JL |
9061 | /* Must be a field and a bit field. */ |
9062 | if (TREE_CODE (decl) != FIELD_DECL | |
9063 | || ! DECL_BIT_FIELD_TYPE (decl)) | |
9064 | abort (); | |
665f2503 RK |
9065 | |
9066 | if (host_integerp (DECL_SIZE (decl), 1)) | |
9067 | add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1)); | |
a3f97cbb JW |
9068 | } |
9069 | ||
88dad228 | 9070 | /* If the compiled language is ANSI C, then add a 'prototyped' |
a3f97cbb | 9071 | attribute, if arg types are given for the parameters of a function. */ |
71dfc51f RK |
9072 | |
9073 | static inline void | |
a3f97cbb JW |
9074 | add_prototyped_attribute (die, func_type) |
9075 | register dw_die_ref die; | |
9076 | register tree func_type; | |
9077 | { | |
88dad228 JM |
9078 | if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89 |
9079 | && TYPE_ARG_TYPES (func_type) != NULL) | |
9080 | add_AT_flag (die, DW_AT_prototyped, 1); | |
a3f97cbb JW |
9081 | } |
9082 | ||
a3f97cbb JW |
9083 | /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found |
9084 | by looking in either the type declaration or object declaration | |
9085 | equate table. */ | |
71dfc51f RK |
9086 | |
9087 | static inline void | |
a3f97cbb JW |
9088 | add_abstract_origin_attribute (die, origin) |
9089 | register dw_die_ref die; | |
9090 | register tree origin; | |
9091 | { | |
9092 | dw_die_ref origin_die = NULL; | |
bbc6ae08 | 9093 | |
d10b8e05 | 9094 | if (TREE_CODE (origin) != FUNCTION_DECL) |
e40a1c67 JM |
9095 | { |
9096 | /* We may have gotten separated from the block for the inlined | |
9097 | function, if we're in an exception handler or some such; make | |
9098 | sure that the abstract function has been written out. | |
9099 | ||
9100 | Doing this for nested functions is wrong, however; functions are | |
9101 | distinct units, and our context might not even be inline. */ | |
fb13d4d0 JM |
9102 | tree fn = origin; |
9103 | if (TYPE_P (fn)) | |
9104 | fn = TYPE_STUB_DECL (fn); | |
9105 | fn = decl_function_context (fn); | |
e40a1c67 | 9106 | if (fn) |
1edf43d6 | 9107 | dwarf2out_abstract_function (fn); |
e40a1c67 | 9108 | } |
44db1d9c | 9109 | |
2f939d94 | 9110 | if (DECL_P (origin)) |
71dfc51f | 9111 | origin_die = lookup_decl_die (origin); |
2f939d94 | 9112 | else if (TYPE_P (origin)) |
71dfc51f RK |
9113 | origin_die = lookup_type_die (origin); |
9114 | ||
bbc6ae08 | 9115 | if (origin_die == NULL) |
1ae8994f | 9116 | abort (); |
556273e0 | 9117 | |
a3f97cbb JW |
9118 | add_AT_die_ref (die, DW_AT_abstract_origin, origin_die); |
9119 | } | |
9120 | ||
bdb669cb JM |
9121 | /* We do not currently support the pure_virtual attribute. */ |
9122 | ||
71dfc51f | 9123 | static inline void |
a3f97cbb JW |
9124 | add_pure_or_virtual_attribute (die, func_decl) |
9125 | register dw_die_ref die; | |
9126 | register tree func_decl; | |
9127 | { | |
a94dbf2c | 9128 | if (DECL_VINDEX (func_decl)) |
a3f97cbb | 9129 | { |
bdb669cb | 9130 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); |
665f2503 RK |
9131 | |
9132 | if (host_integerp (DECL_VINDEX (func_decl), 0)) | |
9133 | add_AT_loc (die, DW_AT_vtable_elem_location, | |
9134 | new_loc_descr (DW_OP_constu, | |
9135 | tree_low_cst (DECL_VINDEX (func_decl), 0), | |
9136 | 0)); | |
71dfc51f | 9137 | |
a94dbf2c JM |
9138 | /* GNU extension: Record what type this method came from originally. */ |
9139 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
9140 | add_AT_die_ref (die, DW_AT_containing_type, | |
9141 | lookup_type_die (DECL_CONTEXT (func_decl))); | |
a3f97cbb JW |
9142 | } |
9143 | } | |
9144 | \f | |
b2932ae5 | 9145 | /* Add source coordinate attributes for the given decl. */ |
71dfc51f | 9146 | |
b2932ae5 JM |
9147 | static void |
9148 | add_src_coords_attributes (die, decl) | |
9149 | register dw_die_ref die; | |
9150 | register tree decl; | |
9151 | { | |
981975b6 | 9152 | register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
71dfc51f | 9153 | |
b2932ae5 JM |
9154 | add_AT_unsigned (die, DW_AT_decl_file, file_index); |
9155 | add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
9156 | } | |
9157 | ||
a3f97cbb JW |
9158 | /* Add an DW_AT_name attribute and source coordinate attribute for the |
9159 | given decl, but only if it actually has a name. */ | |
71dfc51f | 9160 | |
a3f97cbb JW |
9161 | static void |
9162 | add_name_and_src_coords_attributes (die, decl) | |
9163 | register dw_die_ref die; | |
9164 | register tree decl; | |
9165 | { | |
61b32c02 | 9166 | register tree decl_name; |
71dfc51f | 9167 | |
556273e0 | 9168 | decl_name = DECL_NAME (decl); |
71dfc51f | 9169 | if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL) |
a3f97cbb | 9170 | { |
a1d7ffe3 | 9171 | add_name_attribute (die, dwarf2_name (decl, 0)); |
a96c67ec JM |
9172 | if (! DECL_ARTIFICIAL (decl)) |
9173 | add_src_coords_attributes (die, decl); | |
e689ae67 | 9174 | |
a1d7ffe3 | 9175 | if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) |
bc808e0b | 9176 | && TREE_PUBLIC (decl) |
5daf7c0a JM |
9177 | && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) |
9178 | && !DECL_ABSTRACT (decl)) | |
a1d7ffe3 JM |
9179 | add_AT_string (die, DW_AT_MIPS_linkage_name, |
9180 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
a3f97cbb JW |
9181 | } |
9182 | } | |
9183 | ||
556273e0 | 9184 | /* Push a new declaration scope. */ |
71dfc51f | 9185 | |
a3f97cbb JW |
9186 | static void |
9187 | push_decl_scope (scope) | |
9188 | tree scope; | |
9189 | { | |
9190 | /* Make room in the decl_scope_table, if necessary. */ | |
9191 | if (decl_scope_table_allocated == decl_scope_depth) | |
9192 | { | |
9193 | decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT; | |
71dfc51f | 9194 | decl_scope_table |
777ad4c2 JM |
9195 | = (tree *) xrealloc (decl_scope_table, |
9196 | decl_scope_table_allocated * sizeof (tree)); | |
a3f97cbb | 9197 | } |
71dfc51f | 9198 | |
777ad4c2 | 9199 | decl_scope_table[decl_scope_depth] = scope; |
e3e7774e | 9200 | decl_scope_depth++; |
a3f97cbb JW |
9201 | } |
9202 | ||
777ad4c2 JM |
9203 | /* Pop a declaration scope. */ |
9204 | static inline void | |
9205 | pop_decl_scope () | |
9206 | { | |
9207 | if (decl_scope_depth <= 0) | |
9208 | abort (); | |
9209 | --decl_scope_depth; | |
9210 | } | |
9211 | ||
9212 | /* Return the DIE for the scope that immediately contains this type. | |
9213 | Non-named types get global scope. Named types nested in other | |
9214 | types get their containing scope if it's open, or global scope | |
9215 | otherwise. All other types (i.e. function-local named types) get | |
9216 | the current active scope. */ | |
71dfc51f | 9217 | |
a3f97cbb | 9218 | static dw_die_ref |
ab72d377 | 9219 | scope_die_for (t, context_die) |
556273e0 KH |
9220 | register tree t; |
9221 | register dw_die_ref context_die; | |
a3f97cbb JW |
9222 | { |
9223 | register dw_die_ref scope_die = NULL; | |
9224 | register tree containing_scope; | |
e3e7774e | 9225 | register int i; |
a3f97cbb | 9226 | |
777ad4c2 JM |
9227 | /* Non-types always go in the current scope. */ |
9228 | if (! TYPE_P (t)) | |
9229 | abort (); | |
9230 | ||
9231 | containing_scope = TYPE_CONTEXT (t); | |
ab72d377 | 9232 | |
2addbe1d JM |
9233 | /* Ignore namespaces for the moment. */ |
9234 | if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL) | |
9235 | containing_scope = NULL_TREE; | |
9236 | ||
5f2f160c JM |
9237 | /* Ignore function type "scopes" from the C frontend. They mean that |
9238 | a tagged type is local to a parmlist of a function declarator, but | |
9239 | that isn't useful to DWARF. */ | |
9240 | if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE) | |
9241 | containing_scope = NULL_TREE; | |
9242 | ||
71dfc51f RK |
9243 | if (containing_scope == NULL_TREE) |
9244 | scope_die = comp_unit_die; | |
777ad4c2 | 9245 | else if (TYPE_P (containing_scope)) |
348bb3c7 | 9246 | { |
777ad4c2 JM |
9247 | /* For types, we can just look up the appropriate DIE. But |
9248 | first we check to see if we're in the middle of emitting it | |
9249 | so we know where the new DIE should go. */ | |
348bb3c7 JM |
9250 | |
9251 | for (i = decl_scope_depth - 1; i >= 0; --i) | |
777ad4c2 | 9252 | if (decl_scope_table[i] == containing_scope) |
348bb3c7 JM |
9253 | break; |
9254 | ||
9255 | if (i < 0) | |
9256 | { | |
348bb3c7 JM |
9257 | if (debug_info_level > DINFO_LEVEL_TERSE |
9258 | && !TREE_ASM_WRITTEN (containing_scope)) | |
9259 | abort (); | |
9260 | ||
9261 | /* If none of the current dies are suitable, we get file scope. */ | |
9262 | scope_die = comp_unit_die; | |
9263 | } | |
9264 | else | |
777ad4c2 | 9265 | scope_die = lookup_type_die (containing_scope); |
348bb3c7 | 9266 | } |
a3f97cbb | 9267 | else |
777ad4c2 | 9268 | scope_die = context_die; |
71dfc51f | 9269 | |
a3f97cbb JW |
9270 | return scope_die; |
9271 | } | |
9272 | ||
777ad4c2 JM |
9273 | /* Returns nonzero iff CONTEXT_DIE is internal to a function. */ |
9274 | ||
c6991660 | 9275 | static inline int local_scope_p PARAMS ((dw_die_ref)); |
777ad4c2 JM |
9276 | static inline int |
9277 | local_scope_p (context_die) | |
9278 | dw_die_ref context_die; | |
a3f97cbb | 9279 | { |
777ad4c2 JM |
9280 | for (; context_die; context_die = context_die->die_parent) |
9281 | if (context_die->die_tag == DW_TAG_inlined_subroutine | |
9282 | || context_die->die_tag == DW_TAG_subprogram) | |
9283 | return 1; | |
9284 | return 0; | |
a3f97cbb JW |
9285 | } |
9286 | ||
9765e357 JM |
9287 | /* Returns nonzero iff CONTEXT_DIE is a class. */ |
9288 | ||
c6991660 | 9289 | static inline int class_scope_p PARAMS ((dw_die_ref)); |
9765e357 JM |
9290 | static inline int |
9291 | class_scope_p (context_die) | |
9292 | dw_die_ref context_die; | |
9293 | { | |
9294 | return (context_die | |
9295 | && (context_die->die_tag == DW_TAG_structure_type | |
9296 | || context_die->die_tag == DW_TAG_union_type)); | |
9297 | } | |
9298 | ||
a3f97cbb JW |
9299 | /* Many forms of DIEs require a "type description" attribute. This |
9300 | routine locates the proper "type descriptor" die for the type given | |
9301 | by 'type', and adds an DW_AT_type attribute below the given die. */ | |
71dfc51f | 9302 | |
a3f97cbb JW |
9303 | static void |
9304 | add_type_attribute (object_die, type, decl_const, decl_volatile, context_die) | |
9305 | register dw_die_ref object_die; | |
9306 | register tree type; | |
9307 | register int decl_const; | |
9308 | register int decl_volatile; | |
9309 | register dw_die_ref context_die; | |
9310 | { | |
9311 | register enum tree_code code = TREE_CODE (type); | |
a3f97cbb JW |
9312 | register dw_die_ref type_die = NULL; |
9313 | ||
ef76d03b JW |
9314 | /* ??? If this type is an unnamed subrange type of an integral or |
9315 | floating-point type, use the inner type. This is because we have no | |
9316 | support for unnamed types in base_type_die. This can happen if this is | |
9317 | an Ada subrange type. Correct solution is emit a subrange type die. */ | |
b1ccbc24 RK |
9318 | if ((code == INTEGER_TYPE || code == REAL_TYPE) |
9319 | && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0) | |
9320 | type = TREE_TYPE (type), code = TREE_CODE (type); | |
9321 | ||
a3f97cbb | 9322 | if (code == ERROR_MARK) |
b1ccbc24 | 9323 | return; |
a3f97cbb JW |
9324 | |
9325 | /* Handle a special case. For functions whose return type is void, we | |
9326 | generate *no* type attribute. (Note that no object may have type | |
9327 | `void', so this only applies to function return types). */ | |
9328 | if (code == VOID_TYPE) | |
b1ccbc24 | 9329 | return; |
a3f97cbb | 9330 | |
a3f97cbb JW |
9331 | type_die = modified_type_die (type, |
9332 | decl_const || TYPE_READONLY (type), | |
9333 | decl_volatile || TYPE_VOLATILE (type), | |
ab72d377 | 9334 | context_die); |
a3f97cbb | 9335 | if (type_die != NULL) |
71dfc51f | 9336 | add_AT_die_ref (object_die, DW_AT_type, type_die); |
a3f97cbb JW |
9337 | } |
9338 | ||
9339 | /* Given a tree pointer to a struct, class, union, or enum type node, return | |
9340 | a pointer to the (string) tag name for the given type, or zero if the type | |
9341 | was declared without a tag. */ | |
71dfc51f | 9342 | |
d3e3972c | 9343 | static const char * |
a3f97cbb JW |
9344 | type_tag (type) |
9345 | register tree type; | |
9346 | { | |
d3e3972c | 9347 | register const char *name = 0; |
a3f97cbb JW |
9348 | |
9349 | if (TYPE_NAME (type) != 0) | |
9350 | { | |
9351 | register tree t = 0; | |
9352 | ||
9353 | /* Find the IDENTIFIER_NODE for the type name. */ | |
9354 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
9355 | t = TYPE_NAME (type); | |
bdb669cb | 9356 | |
556273e0 | 9357 | /* The g++ front end makes the TYPE_NAME of *each* tagged type point to |
a3f97cbb | 9358 | a TYPE_DECL node, regardless of whether or not a `typedef' was |
bdb669cb | 9359 | involved. */ |
a94dbf2c JM |
9360 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
9361 | && ! DECL_IGNORED_P (TYPE_NAME (type))) | |
a3f97cbb | 9362 | t = DECL_NAME (TYPE_NAME (type)); |
bdb669cb | 9363 | |
a3f97cbb JW |
9364 | /* Now get the name as a string, or invent one. */ |
9365 | if (t != 0) | |
a94dbf2c | 9366 | name = IDENTIFIER_POINTER (t); |
a3f97cbb | 9367 | } |
71dfc51f | 9368 | |
a3f97cbb JW |
9369 | return (name == 0 || *name == '\0') ? 0 : name; |
9370 | } | |
9371 | ||
9372 | /* Return the type associated with a data member, make a special check | |
9373 | for bit field types. */ | |
71dfc51f RK |
9374 | |
9375 | static inline tree | |
a3f97cbb JW |
9376 | member_declared_type (member) |
9377 | register tree member; | |
9378 | { | |
71dfc51f RK |
9379 | return (DECL_BIT_FIELD_TYPE (member) |
9380 | ? DECL_BIT_FIELD_TYPE (member) | |
9381 | : TREE_TYPE (member)); | |
a3f97cbb JW |
9382 | } |
9383 | ||
d291dd49 | 9384 | /* Get the decl's label, as described by its RTL. This may be different |
a3f97cbb | 9385 | from the DECL_NAME name used in the source file. */ |
71dfc51f | 9386 | |
487a6e06 | 9387 | #if 0 |
d3e3972c | 9388 | static const char * |
d291dd49 | 9389 | decl_start_label (decl) |
a3f97cbb JW |
9390 | register tree decl; |
9391 | { | |
9392 | rtx x; | |
d3e3972c | 9393 | const char *fnname; |
a3f97cbb JW |
9394 | x = DECL_RTL (decl); |
9395 | if (GET_CODE (x) != MEM) | |
71dfc51f RK |
9396 | abort (); |
9397 | ||
a3f97cbb JW |
9398 | x = XEXP (x, 0); |
9399 | if (GET_CODE (x) != SYMBOL_REF) | |
71dfc51f RK |
9400 | abort (); |
9401 | ||
a3f97cbb JW |
9402 | fnname = XSTR (x, 0); |
9403 | return fnname; | |
9404 | } | |
487a6e06 | 9405 | #endif |
a3f97cbb | 9406 | \f |
956d6950 | 9407 | /* These routines generate the internal representation of the DIE's for |
a3f97cbb | 9408 | the compilation unit. Debugging information is collected by walking |
88dad228 | 9409 | the declaration trees passed in from dwarf2out_decl(). */ |
a3f97cbb JW |
9410 | |
9411 | static void | |
9412 | gen_array_type_die (type, context_die) | |
9413 | register tree type; | |
9414 | register dw_die_ref context_die; | |
9415 | { | |
ab72d377 | 9416 | register dw_die_ref scope_die = scope_die_for (type, context_die); |
a9d38797 | 9417 | register dw_die_ref array_die; |
a3f97cbb | 9418 | register tree element_type; |
bdb669cb | 9419 | |
a9d38797 JM |
9420 | /* ??? The SGI dwarf reader fails for array of array of enum types unless |
9421 | the inner array type comes before the outer array type. Thus we must | |
9422 | call gen_type_die before we call new_die. See below also. */ | |
9423 | #ifdef MIPS_DEBUGGING_INFO | |
9424 | gen_type_die (TREE_TYPE (type), context_die); | |
9425 | #endif | |
9426 | ||
9427 | array_die = new_die (DW_TAG_array_type, scope_die); | |
9428 | ||
a3f97cbb JW |
9429 | #if 0 |
9430 | /* We default the array ordering. SDB will probably do | |
9431 | the right things even if DW_AT_ordering is not present. It's not even | |
9432 | an issue until we start to get into multidimensional arrays anyway. If | |
9433 | SDB is ever caught doing the Wrong Thing for multi-dimensional arrays, | |
9434 | then we'll have to put the DW_AT_ordering attribute back in. (But if | |
9435 | and when we find out that we need to put these in, we will only do so | |
9436 | for multidimensional arrays. */ | |
9437 | add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major); | |
9438 | #endif | |
9439 | ||
a9d38797 | 9440 | #ifdef MIPS_DEBUGGING_INFO |
4edb7b60 JM |
9441 | /* The SGI compilers handle arrays of unknown bound by setting |
9442 | AT_declaration and not emitting any subrange DIEs. */ | |
a9d38797 JM |
9443 | if (! TYPE_DOMAIN (type)) |
9444 | add_AT_unsigned (array_die, DW_AT_declaration, 1); | |
9445 | else | |
9446 | #endif | |
9447 | add_subscript_info (array_die, type); | |
a3f97cbb | 9448 | |
14a774a9 | 9449 | add_name_attribute (array_die, type_tag (type)); |
a3f97cbb JW |
9450 | equate_type_number_to_die (type, array_die); |
9451 | ||
9452 | /* Add representation of the type of the elements of this array type. */ | |
9453 | element_type = TREE_TYPE (type); | |
71dfc51f | 9454 | |
a3f97cbb JW |
9455 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
9456 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
9457 | We work around this by disabling this feature. See also | |
9458 | add_subscript_info. */ | |
9459 | #ifndef MIPS_DEBUGGING_INFO | |
71dfc51f RK |
9460 | while (TREE_CODE (element_type) == ARRAY_TYPE) |
9461 | element_type = TREE_TYPE (element_type); | |
9462 | ||
a3f97cbb | 9463 | gen_type_die (element_type, context_die); |
a9d38797 | 9464 | #endif |
a3f97cbb JW |
9465 | |
9466 | add_type_attribute (array_die, element_type, 0, 0, context_die); | |
9467 | } | |
9468 | ||
9469 | static void | |
9470 | gen_set_type_die (type, context_die) | |
9471 | register tree type; | |
9472 | register dw_die_ref context_die; | |
9473 | { | |
71dfc51f RK |
9474 | register dw_die_ref type_die |
9475 | = new_die (DW_TAG_set_type, scope_die_for (type, context_die)); | |
9476 | ||
a3f97cbb | 9477 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
9478 | add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die); |
9479 | } | |
9480 | ||
d6f4ec51 | 9481 | #if 0 |
a3f97cbb JW |
9482 | static void |
9483 | gen_entry_point_die (decl, context_die) | |
9484 | register tree decl; | |
9485 | register dw_die_ref context_die; | |
9486 | { | |
9487 | register tree origin = decl_ultimate_origin (decl); | |
9488 | register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die); | |
9489 | if (origin != NULL) | |
71dfc51f | 9490 | add_abstract_origin_attribute (decl_die, origin); |
a3f97cbb JW |
9491 | else |
9492 | { | |
9493 | add_name_and_src_coords_attributes (decl_die, decl); | |
a3f97cbb JW |
9494 | add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)), |
9495 | 0, 0, context_die); | |
9496 | } | |
71dfc51f | 9497 | |
a3f97cbb | 9498 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 9499 | equate_decl_number_to_die (decl, decl_die); |
a3f97cbb | 9500 | else |
71dfc51f | 9501 | add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl)); |
a3f97cbb | 9502 | } |
d6f4ec51 | 9503 | #endif |
a3f97cbb | 9504 | |
8a8c3656 JM |
9505 | /* Remember a type in the incomplete_types_list. */ |
9506 | ||
9507 | static void | |
9508 | add_incomplete_type (type) | |
9509 | tree type; | |
9510 | { | |
9511 | if (incomplete_types == incomplete_types_allocated) | |
9512 | { | |
9513 | incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT; | |
9514 | incomplete_types_list | |
9515 | = (tree *) xrealloc (incomplete_types_list, | |
9516 | sizeof (tree) * incomplete_types_allocated); | |
9517 | } | |
9518 | ||
9519 | incomplete_types_list[incomplete_types++] = type; | |
9520 | } | |
9521 | ||
9522 | /* Walk through the list of incomplete types again, trying once more to | |
9523 | emit full debugging info for them. */ | |
9524 | ||
9525 | static void | |
9526 | retry_incomplete_types () | |
9527 | { | |
9528 | register tree type; | |
9529 | ||
9530 | while (incomplete_types) | |
9531 | { | |
9532 | --incomplete_types; | |
9533 | type = incomplete_types_list[incomplete_types]; | |
9534 | gen_type_die (type, comp_unit_die); | |
9535 | } | |
9536 | } | |
9537 | ||
a3f97cbb | 9538 | /* Generate a DIE to represent an inlined instance of an enumeration type. */ |
71dfc51f | 9539 | |
a3f97cbb JW |
9540 | static void |
9541 | gen_inlined_enumeration_type_die (type, context_die) | |
9542 | register tree type; | |
9543 | register dw_die_ref context_die; | |
9544 | { | |
71dfc51f | 9545 | register dw_die_ref type_die = new_die (DW_TAG_enumeration_type, |
777ad4c2 | 9546 | context_die); |
bbc6ae08 NC |
9547 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9548 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9549 | add_abstract_origin_attribute (type_die, type); |
9550 | } | |
9551 | ||
9552 | /* Generate a DIE to represent an inlined instance of a structure type. */ | |
71dfc51f | 9553 | |
a3f97cbb JW |
9554 | static void |
9555 | gen_inlined_structure_type_die (type, context_die) | |
9556 | register tree type; | |
9557 | register dw_die_ref context_die; | |
9558 | { | |
777ad4c2 JM |
9559 | register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die); |
9560 | ||
bbc6ae08 NC |
9561 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9562 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9563 | add_abstract_origin_attribute (type_die, type); |
9564 | } | |
9565 | ||
9566 | /* Generate a DIE to represent an inlined instance of a union type. */ | |
71dfc51f | 9567 | |
a3f97cbb JW |
9568 | static void |
9569 | gen_inlined_union_type_die (type, context_die) | |
9570 | register tree type; | |
9571 | register dw_die_ref context_die; | |
9572 | { | |
777ad4c2 JM |
9573 | register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die); |
9574 | ||
bbc6ae08 NC |
9575 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9576 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9577 | add_abstract_origin_attribute (type_die, type); |
9578 | } | |
9579 | ||
9580 | /* Generate a DIE to represent an enumeration type. Note that these DIEs | |
9581 | include all of the information about the enumeration values also. Each | |
273dbe67 JM |
9582 | enumerated type name/value is listed as a child of the enumerated type |
9583 | DIE. */ | |
71dfc51f | 9584 | |
a3f97cbb | 9585 | static void |
273dbe67 | 9586 | gen_enumeration_type_die (type, context_die) |
a3f97cbb | 9587 | register tree type; |
a3f97cbb JW |
9588 | register dw_die_ref context_die; |
9589 | { | |
273dbe67 JM |
9590 | register dw_die_ref type_die = lookup_type_die (type); |
9591 | ||
a3f97cbb JW |
9592 | if (type_die == NULL) |
9593 | { | |
9594 | type_die = new_die (DW_TAG_enumeration_type, | |
ab72d377 | 9595 | scope_die_for (type, context_die)); |
a3f97cbb JW |
9596 | equate_type_number_to_die (type, type_die); |
9597 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 9598 | } |
273dbe67 JM |
9599 | else if (! TYPE_SIZE (type)) |
9600 | return; | |
9601 | else | |
9602 | remove_AT (type_die, DW_AT_declaration); | |
9603 | ||
9604 | /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the | |
9605 | given enum type is incomplete, do not generate the DW_AT_byte_size | |
9606 | attribute or the DW_AT_element_list attribute. */ | |
9607 | if (TYPE_SIZE (type)) | |
a3f97cbb | 9608 | { |
273dbe67 | 9609 | register tree link; |
71dfc51f | 9610 | |
a082c85a | 9611 | TREE_ASM_WRITTEN (type) = 1; |
273dbe67 | 9612 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 9613 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 9614 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 9615 | |
ef76d03b JW |
9616 | /* If the first reference to this type was as the return type of an |
9617 | inline function, then it may not have a parent. Fix this now. */ | |
9618 | if (type_die->die_parent == NULL) | |
9619 | add_child_die (scope_die_for (type, context_die), type_die); | |
9620 | ||
273dbe67 JM |
9621 | for (link = TYPE_FIELDS (type); |
9622 | link != NULL; link = TREE_CHAIN (link)) | |
a3f97cbb | 9623 | { |
273dbe67 | 9624 | register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die); |
71dfc51f | 9625 | |
273dbe67 JM |
9626 | add_name_attribute (enum_die, |
9627 | IDENTIFIER_POINTER (TREE_PURPOSE (link))); | |
665f2503 RK |
9628 | |
9629 | if (host_integerp (TREE_VALUE (link), 0)) | |
fc9e8a14 JJ |
9630 | { |
9631 | if (tree_int_cst_sgn (TREE_VALUE (link)) < 0) | |
9632 | add_AT_int (enum_die, DW_AT_const_value, | |
9633 | tree_low_cst (TREE_VALUE (link), 0)); | |
9634 | else | |
9635 | add_AT_unsigned (enum_die, DW_AT_const_value, | |
9636 | tree_low_cst (TREE_VALUE (link), 0)); | |
9637 | } | |
a3f97cbb JW |
9638 | } |
9639 | } | |
273dbe67 JM |
9640 | else |
9641 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a3f97cbb JW |
9642 | } |
9643 | ||
a3f97cbb JW |
9644 | /* Generate a DIE to represent either a real live formal parameter decl or to |
9645 | represent just the type of some formal parameter position in some function | |
9646 | type. | |
71dfc51f | 9647 | |
a3f97cbb JW |
9648 | Note that this routine is a bit unusual because its argument may be a |
9649 | ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which | |
9650 | represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE | |
9651 | node. If it's the former then this function is being called to output a | |
9652 | DIE to represent a formal parameter object (or some inlining thereof). If | |
9653 | it's the latter, then this function is only being called to output a | |
9654 | DW_TAG_formal_parameter DIE to stand as a placeholder for some formal | |
9655 | argument type of some subprogram type. */ | |
71dfc51f | 9656 | |
a94dbf2c | 9657 | static dw_die_ref |
a3f97cbb JW |
9658 | gen_formal_parameter_die (node, context_die) |
9659 | register tree node; | |
9660 | register dw_die_ref context_die; | |
9661 | { | |
71dfc51f RK |
9662 | register dw_die_ref parm_die |
9663 | = new_die (DW_TAG_formal_parameter, context_die); | |
a3f97cbb | 9664 | register tree origin; |
71dfc51f | 9665 | |
a3f97cbb JW |
9666 | switch (TREE_CODE_CLASS (TREE_CODE (node))) |
9667 | { | |
a3f97cbb JW |
9668 | case 'd': |
9669 | origin = decl_ultimate_origin (node); | |
9670 | if (origin != NULL) | |
a94dbf2c | 9671 | add_abstract_origin_attribute (parm_die, origin); |
a3f97cbb JW |
9672 | else |
9673 | { | |
9674 | add_name_and_src_coords_attributes (parm_die, node); | |
9675 | add_type_attribute (parm_die, TREE_TYPE (node), | |
9676 | TREE_READONLY (node), | |
9677 | TREE_THIS_VOLATILE (node), | |
9678 | context_die); | |
bdb669cb JM |
9679 | if (DECL_ARTIFICIAL (node)) |
9680 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb | 9681 | } |
71dfc51f | 9682 | |
141719a8 JM |
9683 | equate_decl_number_to_die (node, parm_die); |
9684 | if (! DECL_ABSTRACT (node)) | |
a94dbf2c | 9685 | add_location_or_const_value_attribute (parm_die, node); |
71dfc51f | 9686 | |
a3f97cbb JW |
9687 | break; |
9688 | ||
a3f97cbb | 9689 | case 't': |
71dfc51f | 9690 | /* We were called with some kind of a ..._TYPE node. */ |
a3f97cbb JW |
9691 | add_type_attribute (parm_die, node, 0, 0, context_die); |
9692 | break; | |
9693 | ||
a3f97cbb JW |
9694 | default: |
9695 | abort (); | |
9696 | } | |
71dfc51f | 9697 | |
a94dbf2c | 9698 | return parm_die; |
a3f97cbb JW |
9699 | } |
9700 | ||
9701 | /* Generate a special type of DIE used as a stand-in for a trailing ellipsis | |
9702 | at the end of an (ANSI prototyped) formal parameters list. */ | |
71dfc51f | 9703 | |
a3f97cbb JW |
9704 | static void |
9705 | gen_unspecified_parameters_die (decl_or_type, context_die) | |
2618f955 | 9706 | register tree decl_or_type ATTRIBUTE_UNUSED; |
a3f97cbb JW |
9707 | register dw_die_ref context_die; |
9708 | { | |
487a6e06 | 9709 | new_die (DW_TAG_unspecified_parameters, context_die); |
a3f97cbb JW |
9710 | } |
9711 | ||
9712 | /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a | |
9713 | DW_TAG_unspecified_parameters DIE) to represent the types of the formal | |
9714 | parameters as specified in some function type specification (except for | |
1cfdcc15 | 9715 | those which appear as part of a function *definition*). */ |
71dfc51f | 9716 | |
a3f97cbb JW |
9717 | static void |
9718 | gen_formal_types_die (function_or_method_type, context_die) | |
9719 | register tree function_or_method_type; | |
9720 | register dw_die_ref context_die; | |
9721 | { | |
9722 | register tree link; | |
9723 | register tree formal_type = NULL; | |
5daf7c0a JM |
9724 | register tree first_parm_type; |
9725 | tree arg; | |
a3f97cbb | 9726 | |
5daf7c0a JM |
9727 | if (TREE_CODE (function_or_method_type) == FUNCTION_DECL) |
9728 | { | |
9729 | arg = DECL_ARGUMENTS (function_or_method_type); | |
9730 | function_or_method_type = TREE_TYPE (function_or_method_type); | |
9731 | } | |
9732 | else | |
9733 | arg = NULL_TREE; | |
9734 | ||
9735 | first_parm_type = TYPE_ARG_TYPES (function_or_method_type); | |
a3f97cbb | 9736 | |
556273e0 | 9737 | /* Make our first pass over the list of formal parameter types and output a |
a3f97cbb | 9738 | DW_TAG_formal_parameter DIE for each one. */ |
5daf7c0a | 9739 | for (link = first_parm_type; link; ) |
a3f97cbb | 9740 | { |
a94dbf2c | 9741 | register dw_die_ref parm_die; |
556273e0 | 9742 | |
a3f97cbb JW |
9743 | formal_type = TREE_VALUE (link); |
9744 | if (formal_type == void_type_node) | |
9745 | break; | |
9746 | ||
9747 | /* Output a (nameless) DIE to represent the formal parameter itself. */ | |
a94dbf2c | 9748 | parm_die = gen_formal_parameter_die (formal_type, context_die); |
5daf7c0a JM |
9749 | if ((TREE_CODE (function_or_method_type) == METHOD_TYPE |
9750 | && link == first_parm_type) | |
9751 | || (arg && DECL_ARTIFICIAL (arg))) | |
a94dbf2c | 9752 | add_AT_flag (parm_die, DW_AT_artificial, 1); |
5daf7c0a JM |
9753 | |
9754 | link = TREE_CHAIN (link); | |
9755 | if (arg) | |
9756 | arg = TREE_CHAIN (arg); | |
a3f97cbb JW |
9757 | } |
9758 | ||
9759 | /* If this function type has an ellipsis, add a | |
9760 | DW_TAG_unspecified_parameters DIE to the end of the parameter list. */ | |
9761 | if (formal_type != void_type_node) | |
9762 | gen_unspecified_parameters_die (function_or_method_type, context_die); | |
9763 | ||
556273e0 | 9764 | /* Make our second (and final) pass over the list of formal parameter types |
a3f97cbb JW |
9765 | and output DIEs to represent those types (as necessary). */ |
9766 | for (link = TYPE_ARG_TYPES (function_or_method_type); | |
9767 | link; | |
9768 | link = TREE_CHAIN (link)) | |
9769 | { | |
9770 | formal_type = TREE_VALUE (link); | |
9771 | if (formal_type == void_type_node) | |
9772 | break; | |
9773 | ||
b50c02f9 | 9774 | gen_type_die (formal_type, context_die); |
a3f97cbb JW |
9775 | } |
9776 | } | |
9777 | ||
10a11b75 JM |
9778 | /* We want to generate the DIE for TYPE so that we can generate the |
9779 | die for MEMBER, which has been defined; we will need to refer back | |
9780 | to the member declaration nested within TYPE. If we're trying to | |
9781 | generate minimal debug info for TYPE, processing TYPE won't do the | |
9782 | trick; we need to attach the member declaration by hand. */ | |
9783 | ||
9784 | static void | |
9785 | gen_type_die_for_member (type, member, context_die) | |
9786 | tree type, member; | |
9787 | dw_die_ref context_die; | |
9788 | { | |
9789 | gen_type_die (type, context_die); | |
9790 | ||
9791 | /* If we're trying to avoid duplicate debug info, we may not have | |
9792 | emitted the member decl for this function. Emit it now. */ | |
9793 | if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)) | |
9794 | && ! lookup_decl_die (member)) | |
9795 | { | |
9796 | if (decl_ultimate_origin (member)) | |
9797 | abort (); | |
9798 | ||
9799 | push_decl_scope (type); | |
9800 | if (TREE_CODE (member) == FUNCTION_DECL) | |
9801 | gen_subprogram_die (member, lookup_type_die (type)); | |
9802 | else | |
9803 | gen_variable_die (member, lookup_type_die (type)); | |
9804 | pop_decl_scope (); | |
9805 | } | |
9806 | } | |
9807 | ||
9808 | /* Generate the DWARF2 info for the "abstract" instance | |
9809 | of a function which we may later generate inlined and/or | |
9810 | out-of-line instances of. */ | |
9811 | ||
e1772ac0 | 9812 | static void |
1edf43d6 | 9813 | dwarf2out_abstract_function (decl) |
10a11b75 JM |
9814 | tree decl; |
9815 | { | |
5daf7c0a | 9816 | register dw_die_ref old_die; |
777ad4c2 | 9817 | tree save_fn; |
5daf7c0a JM |
9818 | tree context; |
9819 | int was_abstract = DECL_ABSTRACT (decl); | |
9820 | ||
9821 | /* Make sure we have the actual abstract inline, not a clone. */ | |
9822 | decl = DECL_ORIGIN (decl); | |
10a11b75 | 9823 | |
5daf7c0a | 9824 | old_die = lookup_decl_die (decl); |
10a11b75 JM |
9825 | if (old_die && get_AT_unsigned (old_die, DW_AT_inline)) |
9826 | /* We've already generated the abstract instance. */ | |
9827 | return; | |
9828 | ||
5daf7c0a JM |
9829 | /* Be sure we've emitted the in-class declaration DIE (if any) first, so |
9830 | we don't get confused by DECL_ABSTRACT. */ | |
8458e954 JS |
9831 | if (debug_info_level > DINFO_LEVEL_TERSE) |
9832 | { | |
9833 | context = decl_class_context (decl); | |
9834 | if (context) | |
9835 | gen_type_die_for_member | |
9836 | (context, decl, decl_function_context (decl) ? NULL : comp_unit_die); | |
9837 | } | |
5daf7c0a JM |
9838 | |
9839 | /* Pretend we've just finished compiling this function. */ | |
777ad4c2 JM |
9840 | save_fn = current_function_decl; |
9841 | current_function_decl = decl; | |
9842 | ||
10a11b75 JM |
9843 | set_decl_abstract_flags (decl, 1); |
9844 | dwarf2out_decl (decl); | |
5daf7c0a JM |
9845 | if (! was_abstract) |
9846 | set_decl_abstract_flags (decl, 0); | |
777ad4c2 JM |
9847 | |
9848 | current_function_decl = save_fn; | |
10a11b75 JM |
9849 | } |
9850 | ||
a3f97cbb JW |
9851 | /* Generate a DIE to represent a declared function (either file-scope or |
9852 | block-local). */ | |
71dfc51f | 9853 | |
a3f97cbb JW |
9854 | static void |
9855 | gen_subprogram_die (decl, context_die) | |
9856 | register tree decl; | |
9857 | register dw_die_ref context_die; | |
9858 | { | |
9859 | char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; | |
9860 | register tree origin = decl_ultimate_origin (decl); | |
4b674448 | 9861 | register dw_die_ref subr_die; |
b1ccbc24 | 9862 | register rtx fp_reg; |
a3f97cbb JW |
9863 | register tree fn_arg_types; |
9864 | register tree outer_scope; | |
a94dbf2c | 9865 | register dw_die_ref old_die = lookup_decl_die (decl); |
9765e357 JM |
9866 | register int declaration = (current_function_decl != decl |
9867 | || class_scope_p (context_die)); | |
a3f97cbb | 9868 | |
10a11b75 JM |
9869 | /* Note that it is possible to have both DECL_ABSTRACT and `declaration' |
9870 | be true, if we started to generate the abstract instance of an inline, | |
9871 | decided to output its containing class, and proceeded to emit the | |
9872 | declaration of the inline from the member list for the class. In that | |
9873 | case, `declaration' takes priority; we'll get back to the abstract | |
9874 | instance when we're done with the class. */ | |
9875 | ||
1cfdcc15 JM |
9876 | /* The class-scope declaration DIE must be the primary DIE. */ |
9877 | if (origin && declaration && class_scope_p (context_die)) | |
9878 | { | |
9879 | origin = NULL; | |
9880 | if (old_die) | |
9881 | abort (); | |
9882 | } | |
9883 | ||
a3f97cbb JW |
9884 | if (origin != NULL) |
9885 | { | |
777ad4c2 | 9886 | if (declaration && ! local_scope_p (context_die)) |
10a11b75 JM |
9887 | abort (); |
9888 | ||
8d8238b6 JM |
9889 | /* Fixup die_parent for the abstract instance of a nested |
9890 | inline function. */ | |
9891 | if (old_die && old_die->die_parent == NULL) | |
9892 | add_child_die (context_die, old_die); | |
9893 | ||
4b674448 | 9894 | subr_die = new_die (DW_TAG_subprogram, context_die); |
a3f97cbb JW |
9895 | add_abstract_origin_attribute (subr_die, origin); |
9896 | } | |
bdb669cb JM |
9897 | else if (old_die) |
9898 | { | |
981975b6 | 9899 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
a94dbf2c | 9900 | |
1edf43d6 JM |
9901 | if (!get_AT_flag (old_die, DW_AT_declaration) |
9902 | /* We can have a normal definition following an inline one in the | |
9903 | case of redefinition of GNU C extern inlines. | |
9904 | It seems reasonable to use AT_specification in this case. */ | |
9905 | && !get_AT_unsigned (old_die, DW_AT_inline)) | |
b75ab88b NC |
9906 | { |
9907 | /* ??? This can happen if there is a bug in the program, for | |
9908 | instance, if it has duplicate function definitions. Ideally, | |
9909 | we should detect this case and ignore it. For now, if we have | |
9910 | already reported an error, any error at all, then assume that | |
9911 | we got here because of a input error, not a dwarf2 bug. */ | |
b75ab88b NC |
9912 | if (errorcount) |
9913 | return; | |
9914 | abort (); | |
9915 | } | |
4b674448 JM |
9916 | |
9917 | /* If the definition comes from the same place as the declaration, | |
a94dbf2c JM |
9918 | maybe use the old DIE. We always want the DIE for this function |
9919 | that has the *_pc attributes to be under comp_unit_die so the | |
cb9e9d8d JM |
9920 | debugger can find it. We also need to do this for abstract |
9921 | instances of inlines, since the spec requires the out-of-line copy | |
9922 | to have the same parent. For local class methods, this doesn't | |
9923 | apply; we just use the old DIE. */ | |
9924 | if ((old_die->die_parent == comp_unit_die || context_die == NULL) | |
a96c67ec JM |
9925 | && (DECL_ARTIFICIAL (decl) |
9926 | || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index | |
9927 | && (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 9928 | == (unsigned) DECL_SOURCE_LINE (decl))))) |
bdb669cb | 9929 | { |
4b674448 JM |
9930 | subr_die = old_die; |
9931 | ||
9932 | /* Clear out the declaration attribute and the parm types. */ | |
9933 | remove_AT (subr_die, DW_AT_declaration); | |
9934 | remove_children (subr_die); | |
9935 | } | |
9936 | else | |
9937 | { | |
9938 | subr_die = new_die (DW_TAG_subprogram, context_die); | |
9939 | add_AT_die_ref (subr_die, DW_AT_specification, old_die); | |
bdb669cb JM |
9940 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
9941 | add_AT_unsigned (subr_die, DW_AT_decl_file, file_index); | |
9942 | if (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 9943 | != (unsigned) DECL_SOURCE_LINE (decl)) |
bdb669cb JM |
9944 | add_AT_unsigned |
9945 | (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
9946 | } | |
9947 | } | |
a3f97cbb JW |
9948 | else |
9949 | { | |
777ad4c2 | 9950 | subr_die = new_die (DW_TAG_subprogram, context_die); |
556273e0 | 9951 | |
273dbe67 JM |
9952 | if (TREE_PUBLIC (decl)) |
9953 | add_AT_flag (subr_die, DW_AT_external, 1); | |
71dfc51f | 9954 | |
a3f97cbb | 9955 | add_name_and_src_coords_attributes (subr_die, decl); |
4927276d JM |
9956 | if (debug_info_level > DINFO_LEVEL_TERSE) |
9957 | { | |
9958 | register tree type = TREE_TYPE (decl); | |
71dfc51f | 9959 | |
4927276d JM |
9960 | add_prototyped_attribute (subr_die, type); |
9961 | add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die); | |
9962 | } | |
71dfc51f | 9963 | |
a3f97cbb | 9964 | add_pure_or_virtual_attribute (subr_die, decl); |
273dbe67 JM |
9965 | if (DECL_ARTIFICIAL (decl)) |
9966 | add_AT_flag (subr_die, DW_AT_artificial, 1); | |
a94dbf2c JM |
9967 | if (TREE_PROTECTED (decl)) |
9968 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected); | |
9969 | else if (TREE_PRIVATE (decl)) | |
9970 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 9971 | } |
4edb7b60 | 9972 | |
a94dbf2c JM |
9973 | if (declaration) |
9974 | { | |
1edf43d6 JM |
9975 | if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline))) |
9976 | { | |
9977 | add_AT_flag (subr_die, DW_AT_declaration, 1); | |
9978 | ||
9979 | /* The first time we see a member function, it is in the context of | |
9980 | the class to which it belongs. We make sure of this by emitting | |
9981 | the class first. The next time is the definition, which is | |
9982 | handled above. The two may come from the same source text. */ | |
9983 | if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl)) | |
9984 | equate_decl_number_to_die (decl, subr_die); | |
9985 | } | |
a94dbf2c JM |
9986 | } |
9987 | else if (DECL_ABSTRACT (decl)) | |
a3f97cbb | 9988 | { |
10a11b75 | 9989 | if (DECL_INLINE (decl) && !flag_no_inline) |
61b32c02 | 9990 | { |
10a11b75 JM |
9991 | /* ??? Checking DECL_DEFER_OUTPUT is correct for static |
9992 | inline functions, but not for extern inline functions. | |
9993 | We can't get this completely correct because information | |
9994 | about whether the function was declared inline is not | |
9995 | saved anywhere. */ | |
9996 | if (DECL_DEFER_OUTPUT (decl)) | |
61b32c02 JM |
9997 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined); |
9998 | else | |
10a11b75 | 9999 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined); |
61b32c02 | 10000 | } |
61b32c02 | 10001 | else |
10a11b75 | 10002 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined); |
61b32c02 | 10003 | |
a3f97cbb JW |
10004 | equate_decl_number_to_die (decl, subr_die); |
10005 | } | |
10006 | else if (!DECL_EXTERNAL (decl)) | |
10007 | { | |
1edf43d6 | 10008 | if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline))) |
ba7b35df | 10009 | equate_decl_number_to_die (decl, subr_die); |
71dfc51f | 10010 | |
5c90448c JM |
10011 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL, |
10012 | current_funcdef_number); | |
7d4440be | 10013 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id); |
5c90448c JM |
10014 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, |
10015 | current_funcdef_number); | |
a3f97cbb JW |
10016 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id); |
10017 | ||
d291dd49 JM |
10018 | add_pubname (decl, subr_die); |
10019 | add_arange (decl, subr_die); | |
10020 | ||
a3f97cbb | 10021 | #ifdef MIPS_DEBUGGING_INFO |
a3f97cbb JW |
10022 | /* Add a reference to the FDE for this routine. */ |
10023 | add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde); | |
10024 | #endif | |
10025 | ||
810429b7 JM |
10026 | /* Define the "frame base" location for this routine. We use the |
10027 | frame pointer or stack pointer registers, since the RTL for local | |
10028 | variables is relative to one of them. */ | |
b1ccbc24 RK |
10029 | fp_reg |
10030 | = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx; | |
10031 | add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg)); | |
a3f97cbb | 10032 | |
ef76d03b JW |
10033 | #if 0 |
10034 | /* ??? This fails for nested inline functions, because context_display | |
10035 | is not part of the state saved/restored for inline functions. */ | |
88dad228 | 10036 | if (current_function_needs_context) |
ef76d03b JW |
10037 | add_AT_location_description (subr_die, DW_AT_static_link, |
10038 | lookup_static_chain (decl)); | |
10039 | #endif | |
a3f97cbb JW |
10040 | } |
10041 | ||
10042 | /* Now output descriptions of the arguments for this function. This gets | |
556273e0 | 10043 | (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list |
a3f97cbb JW |
10044 | for a FUNCTION_DECL doesn't indicate cases where there was a trailing |
10045 | `...' at the end of the formal parameter list. In order to find out if | |
10046 | there was a trailing ellipsis or not, we must instead look at the type | |
10047 | associated with the FUNCTION_DECL. This will be a node of type | |
10048 | FUNCTION_TYPE. If the chain of type nodes hanging off of this | |
556273e0 | 10049 | FUNCTION_TYPE node ends with a void_type_node then there should *not* be |
a3f97cbb | 10050 | an ellipsis at the end. */ |
71dfc51f | 10051 | |
a3f97cbb | 10052 | /* In the case where we are describing a mere function declaration, all we |
556273e0 | 10053 | need to do here (and all we *can* do here) is to describe the *types* of |
a3f97cbb | 10054 | its formal parameters. */ |
4927276d | 10055 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 10056 | ; |
4edb7b60 | 10057 | else if (declaration) |
5daf7c0a | 10058 | gen_formal_types_die (decl, subr_die); |
a3f97cbb JW |
10059 | else |
10060 | { | |
10061 | /* Generate DIEs to represent all known formal parameters */ | |
10062 | register tree arg_decls = DECL_ARGUMENTS (decl); | |
10063 | register tree parm; | |
10064 | ||
10065 | /* When generating DIEs, generate the unspecified_parameters DIE | |
10066 | instead if we come across the arg "__builtin_va_alist" */ | |
10067 | for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) | |
71dfc51f RK |
10068 | if (TREE_CODE (parm) == PARM_DECL) |
10069 | { | |
db3cf6fb MS |
10070 | if (DECL_NAME (parm) |
10071 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), | |
10072 | "__builtin_va_alist")) | |
71dfc51f RK |
10073 | gen_unspecified_parameters_die (parm, subr_die); |
10074 | else | |
10075 | gen_decl_die (parm, subr_die); | |
10076 | } | |
a3f97cbb JW |
10077 | |
10078 | /* Decide whether we need a unspecified_parameters DIE at the end. | |
556273e0 | 10079 | There are 2 more cases to do this for: 1) the ansi ... declaration - |
a3f97cbb JW |
10080 | this is detectable when the end of the arg list is not a |
10081 | void_type_node 2) an unprototyped function declaration (not a | |
10082 | definition). This just means that we have no info about the | |
10083 | parameters at all. */ | |
10084 | fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
71dfc51f | 10085 | if (fn_arg_types != NULL) |
a3f97cbb JW |
10086 | { |
10087 | /* this is the prototyped case, check for ... */ | |
10088 | if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) | |
71dfc51f | 10089 | gen_unspecified_parameters_die (decl, subr_die); |
a3f97cbb | 10090 | } |
71dfc51f RK |
10091 | else if (DECL_INITIAL (decl) == NULL_TREE) |
10092 | gen_unspecified_parameters_die (decl, subr_die); | |
a3f97cbb JW |
10093 | } |
10094 | ||
10095 | /* Output Dwarf info for all of the stuff within the body of the function | |
10096 | (if it has one - it may be just a declaration). */ | |
10097 | outer_scope = DECL_INITIAL (decl); | |
10098 | ||
d7248bff JM |
10099 | /* Note that here, `outer_scope' is a pointer to the outermost BLOCK |
10100 | node created to represent a function. This outermost BLOCK actually | |
10101 | represents the outermost binding contour for the function, i.e. the | |
10102 | contour in which the function's formal parameters and labels get | |
10103 | declared. Curiously, it appears that the front end doesn't actually | |
10104 | put the PARM_DECL nodes for the current function onto the BLOCK_VARS | |
10105 | list for this outer scope. (They are strung off of the DECL_ARGUMENTS | |
10106 | list for the function instead.) The BLOCK_VARS list for the | |
10107 | `outer_scope' does provide us with a list of the LABEL_DECL nodes for | |
10108 | the function however, and we output DWARF info for those in | |
10109 | decls_for_scope. Just within the `outer_scope' there will be a BLOCK | |
10110 | node representing the function's outermost pair of curly braces, and | |
10111 | any blocks used for the base and member initializers of a C++ | |
10112 | constructor function. */ | |
4edb7b60 | 10113 | if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK) |
7e23cb16 JM |
10114 | { |
10115 | current_function_has_inlines = 0; | |
10116 | decls_for_scope (outer_scope, subr_die, 0); | |
71dfc51f | 10117 | |
ce61cc73 | 10118 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
7e23cb16 JM |
10119 | if (current_function_has_inlines) |
10120 | { | |
10121 | add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1); | |
10122 | if (! comp_unit_has_inlines) | |
10123 | { | |
10124 | add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1); | |
10125 | comp_unit_has_inlines = 1; | |
10126 | } | |
10127 | } | |
10128 | #endif | |
10129 | } | |
a3f97cbb JW |
10130 | } |
10131 | ||
10132 | /* Generate a DIE to represent a declared data object. */ | |
71dfc51f | 10133 | |
a3f97cbb JW |
10134 | static void |
10135 | gen_variable_die (decl, context_die) | |
10136 | register tree decl; | |
10137 | register dw_die_ref context_die; | |
10138 | { | |
10139 | register tree origin = decl_ultimate_origin (decl); | |
10140 | register dw_die_ref var_die = new_die (DW_TAG_variable, context_die); | |
71dfc51f | 10141 | |
bdb669cb | 10142 | dw_die_ref old_die = lookup_decl_die (decl); |
9765e357 JM |
10143 | int declaration = (DECL_EXTERNAL (decl) |
10144 | || class_scope_p (context_die)); | |
4edb7b60 | 10145 | |
a3f97cbb | 10146 | if (origin != NULL) |
71dfc51f | 10147 | add_abstract_origin_attribute (var_die, origin); |
f76b8156 JW |
10148 | /* Loop unrolling can create multiple blocks that refer to the same |
10149 | static variable, so we must test for the DW_AT_declaration flag. */ | |
10150 | /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to | |
10151 | copy decls and set the DECL_ABSTRACT flag on them instead of | |
10152 | sharing them. */ | |
a20612aa | 10153 | /* ??? Duplicated blocks have been rewritten to use .debug_ranges. */ |
f76b8156 JW |
10154 | else if (old_die && TREE_STATIC (decl) |
10155 | && get_AT_flag (old_die, DW_AT_declaration) == 1) | |
bdb669cb | 10156 | { |
e689ae67 | 10157 | /* This is a definition of a C++ class level static. */ |
bdb669cb JM |
10158 | add_AT_die_ref (var_die, DW_AT_specification, old_die); |
10159 | if (DECL_NAME (decl)) | |
10160 | { | |
981975b6 | 10161 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
71dfc51f | 10162 | |
bdb669cb JM |
10163 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
10164 | add_AT_unsigned (var_die, DW_AT_decl_file, file_index); | |
71dfc51f | 10165 | |
bdb669cb | 10166 | if (get_AT_unsigned (old_die, DW_AT_decl_line) |
556273e0 | 10167 | != (unsigned) DECL_SOURCE_LINE (decl)) |
71dfc51f RK |
10168 | |
10169 | add_AT_unsigned (var_die, DW_AT_decl_line, | |
10170 | DECL_SOURCE_LINE (decl)); | |
bdb669cb JM |
10171 | } |
10172 | } | |
a3f97cbb JW |
10173 | else |
10174 | { | |
10175 | add_name_and_src_coords_attributes (var_die, decl); | |
a3f97cbb JW |
10176 | add_type_attribute (var_die, TREE_TYPE (decl), |
10177 | TREE_READONLY (decl), | |
10178 | TREE_THIS_VOLATILE (decl), context_die); | |
71dfc51f | 10179 | |
273dbe67 JM |
10180 | if (TREE_PUBLIC (decl)) |
10181 | add_AT_flag (var_die, DW_AT_external, 1); | |
71dfc51f | 10182 | |
273dbe67 JM |
10183 | if (DECL_ARTIFICIAL (decl)) |
10184 | add_AT_flag (var_die, DW_AT_artificial, 1); | |
71dfc51f | 10185 | |
a94dbf2c JM |
10186 | if (TREE_PROTECTED (decl)) |
10187 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected); | |
71dfc51f | 10188 | |
a94dbf2c JM |
10189 | else if (TREE_PRIVATE (decl)) |
10190 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 10191 | } |
4edb7b60 JM |
10192 | |
10193 | if (declaration) | |
10194 | add_AT_flag (var_die, DW_AT_declaration, 1); | |
556273e0 | 10195 | |
9765e357 | 10196 | if (class_scope_p (context_die) || DECL_ABSTRACT (decl)) |
4edb7b60 JM |
10197 | equate_decl_number_to_die (decl, var_die); |
10198 | ||
10199 | if (! declaration && ! DECL_ABSTRACT (decl)) | |
a3f97cbb JW |
10200 | { |
10201 | add_location_or_const_value_attribute (var_die, decl); | |
d291dd49 | 10202 | add_pubname (decl, var_die); |
a3f97cbb | 10203 | } |
1bfb5f8f JM |
10204 | else |
10205 | tree_add_const_value_attribute (var_die, decl); | |
a3f97cbb JW |
10206 | } |
10207 | ||
10208 | /* Generate a DIE to represent a label identifier. */ | |
71dfc51f | 10209 | |
a3f97cbb JW |
10210 | static void |
10211 | gen_label_die (decl, context_die) | |
10212 | register tree decl; | |
10213 | register dw_die_ref context_die; | |
10214 | { | |
10215 | register tree origin = decl_ultimate_origin (decl); | |
10216 | register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die); | |
10217 | register rtx insn; | |
10218 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
71dfc51f | 10219 | |
a3f97cbb | 10220 | if (origin != NULL) |
71dfc51f | 10221 | add_abstract_origin_attribute (lbl_die, origin); |
a3f97cbb | 10222 | else |
71dfc51f RK |
10223 | add_name_and_src_coords_attributes (lbl_die, decl); |
10224 | ||
a3f97cbb | 10225 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 10226 | equate_decl_number_to_die (decl, lbl_die); |
a3f97cbb JW |
10227 | else |
10228 | { | |
10229 | insn = DECL_RTL (decl); | |
088e7160 NC |
10230 | |
10231 | /* Deleted labels are programmer specified labels which have been | |
10232 | eliminated because of various optimisations. We still emit them | |
10233 | here so that it is possible to put breakpoints on them. */ | |
10234 | if (GET_CODE (insn) == CODE_LABEL | |
10235 | || ((GET_CODE (insn) == NOTE | |
10236 | && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))) | |
a3f97cbb | 10237 | { |
556273e0 KH |
10238 | /* When optimization is enabled (via -O) some parts of the compiler |
10239 | (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which | |
a3f97cbb JW |
10240 | represent source-level labels which were explicitly declared by |
10241 | the user. This really shouldn't be happening though, so catch | |
10242 | it if it ever does happen. */ | |
10243 | if (INSN_DELETED_P (insn)) | |
71dfc51f RK |
10244 | abort (); |
10245 | ||
66234570 | 10246 | ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn)); |
a3f97cbb JW |
10247 | add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); |
10248 | } | |
10249 | } | |
10250 | } | |
10251 | ||
10252 | /* Generate a DIE for a lexical block. */ | |
71dfc51f | 10253 | |
a3f97cbb | 10254 | static void |
d7248bff | 10255 | gen_lexical_block_die (stmt, context_die, depth) |
a3f97cbb JW |
10256 | register tree stmt; |
10257 | register dw_die_ref context_die; | |
d7248bff | 10258 | int depth; |
a3f97cbb JW |
10259 | { |
10260 | register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die); | |
10261 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
71dfc51f RK |
10262 | |
10263 | if (! BLOCK_ABSTRACT (stmt)) | |
a3f97cbb | 10264 | { |
a20612aa RH |
10265 | if (BLOCK_FRAGMENT_CHAIN (stmt)) |
10266 | { | |
10267 | tree chain; | |
10268 | ||
10269 | add_AT_offset (stmt_die, DW_AT_ranges, add_ranges (stmt)); | |
10270 | ||
10271 | chain = BLOCK_FRAGMENT_CHAIN (stmt); | |
10272 | do | |
10273 | { | |
10274 | add_ranges (chain); | |
10275 | chain = BLOCK_FRAGMENT_CHAIN (chain); | |
10276 | } | |
10277 | while (chain); | |
10278 | add_ranges (NULL); | |
10279 | } | |
10280 | else | |
10281 | { | |
10282 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, | |
10283 | BLOCK_NUMBER (stmt)); | |
10284 | add_AT_lbl_id (stmt_die, DW_AT_low_pc, label); | |
10285 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, | |
10286 | BLOCK_NUMBER (stmt)); | |
10287 | add_AT_lbl_id (stmt_die, DW_AT_high_pc, label); | |
10288 | } | |
a3f97cbb | 10289 | } |
71dfc51f | 10290 | |
d7248bff | 10291 | decls_for_scope (stmt, stmt_die, depth); |
a3f97cbb JW |
10292 | } |
10293 | ||
10294 | /* Generate a DIE for an inlined subprogram. */ | |
71dfc51f | 10295 | |
a3f97cbb | 10296 | static void |
d7248bff | 10297 | gen_inlined_subroutine_die (stmt, context_die, depth) |
a3f97cbb JW |
10298 | register tree stmt; |
10299 | register dw_die_ref context_die; | |
d7248bff | 10300 | int depth; |
a3f97cbb | 10301 | { |
71dfc51f | 10302 | if (! BLOCK_ABSTRACT (stmt)) |
a3f97cbb | 10303 | { |
71dfc51f RK |
10304 | register dw_die_ref subr_die |
10305 | = new_die (DW_TAG_inlined_subroutine, context_die); | |
ab72d377 | 10306 | register tree decl = block_ultimate_origin (stmt); |
d7248bff | 10307 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 10308 | |
10a11b75 | 10309 | /* Emit info for the abstract instance first, if we haven't yet. */ |
1edf43d6 | 10310 | dwarf2out_abstract_function (decl); |
10a11b75 | 10311 | |
ab72d377 | 10312 | add_abstract_origin_attribute (subr_die, decl); |
5c90448c | 10313 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
18c038b9 | 10314 | BLOCK_NUMBER (stmt)); |
a3f97cbb | 10315 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label); |
18c038b9 MM |
10316 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, |
10317 | BLOCK_NUMBER (stmt)); | |
a3f97cbb | 10318 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label); |
d7248bff | 10319 | decls_for_scope (stmt, subr_die, depth); |
7e23cb16 | 10320 | current_function_has_inlines = 1; |
a3f97cbb | 10321 | } |
a3f97cbb JW |
10322 | } |
10323 | ||
10324 | /* Generate a DIE for a field in a record, or structure. */ | |
71dfc51f | 10325 | |
a3f97cbb JW |
10326 | static void |
10327 | gen_field_die (decl, context_die) | |
10328 | register tree decl; | |
10329 | register dw_die_ref context_die; | |
10330 | { | |
10331 | register dw_die_ref decl_die = new_die (DW_TAG_member, context_die); | |
71dfc51f | 10332 | |
a3f97cbb | 10333 | add_name_and_src_coords_attributes (decl_die, decl); |
a3f97cbb JW |
10334 | add_type_attribute (decl_die, member_declared_type (decl), |
10335 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl), | |
10336 | context_die); | |
71dfc51f | 10337 | |
a3f97cbb JW |
10338 | /* If this is a bit field... */ |
10339 | if (DECL_BIT_FIELD_TYPE (decl)) | |
10340 | { | |
10341 | add_byte_size_attribute (decl_die, decl); | |
10342 | add_bit_size_attribute (decl_die, decl); | |
10343 | add_bit_offset_attribute (decl_die, decl); | |
10344 | } | |
71dfc51f | 10345 | |
a94dbf2c JM |
10346 | if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE) |
10347 | add_data_member_location_attribute (decl_die, decl); | |
71dfc51f | 10348 | |
273dbe67 JM |
10349 | if (DECL_ARTIFICIAL (decl)) |
10350 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
71dfc51f | 10351 | |
a94dbf2c JM |
10352 | if (TREE_PROTECTED (decl)) |
10353 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected); | |
71dfc51f | 10354 | |
a94dbf2c JM |
10355 | else if (TREE_PRIVATE (decl)) |
10356 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb JW |
10357 | } |
10358 | ||
ab72d377 JM |
10359 | #if 0 |
10360 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. | |
10361 | Use modified_type_die instead. | |
a3f97cbb JW |
10362 | We keep this code here just in case these types of DIEs may be needed to |
10363 | represent certain things in other languages (e.g. Pascal) someday. */ | |
10364 | static void | |
10365 | gen_pointer_type_die (type, context_die) | |
10366 | register tree type; | |
10367 | register dw_die_ref context_die; | |
10368 | { | |
71dfc51f RK |
10369 | register dw_die_ref ptr_die |
10370 | = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die)); | |
10371 | ||
a3f97cbb | 10372 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 10373 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 10374 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb JW |
10375 | } |
10376 | ||
ab72d377 JM |
10377 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. |
10378 | Use modified_type_die instead. | |
a3f97cbb JW |
10379 | We keep this code here just in case these types of DIEs may be needed to |
10380 | represent certain things in other languages (e.g. Pascal) someday. */ | |
10381 | static void | |
10382 | gen_reference_type_die (type, context_die) | |
10383 | register tree type; | |
10384 | register dw_die_ref context_die; | |
10385 | { | |
71dfc51f RK |
10386 | register dw_die_ref ref_die |
10387 | = new_die (DW_TAG_reference_type, scope_die_for (type, context_die)); | |
10388 | ||
a3f97cbb | 10389 | equate_type_number_to_die (type, ref_die); |
a3f97cbb | 10390 | add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 10391 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb | 10392 | } |
ab72d377 | 10393 | #endif |
a3f97cbb JW |
10394 | |
10395 | /* Generate a DIE for a pointer to a member type. */ | |
10396 | static void | |
10397 | gen_ptr_to_mbr_type_die (type, context_die) | |
10398 | register tree type; | |
10399 | register dw_die_ref context_die; | |
10400 | { | |
71dfc51f RK |
10401 | register dw_die_ref ptr_die |
10402 | = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die)); | |
10403 | ||
a3f97cbb | 10404 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 10405 | add_AT_die_ref (ptr_die, DW_AT_containing_type, |
bdb669cb | 10406 | lookup_type_die (TYPE_OFFSET_BASETYPE (type))); |
a3f97cbb JW |
10407 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
10408 | } | |
10409 | ||
10410 | /* Generate the DIE for the compilation unit. */ | |
71dfc51f | 10411 | |
a96c67ec JM |
10412 | static dw_die_ref |
10413 | gen_compile_unit_die (filename) | |
10414 | register const char *filename; | |
a3f97cbb | 10415 | { |
a96c67ec | 10416 | register dw_die_ref die; |
a3f97cbb | 10417 | char producer[250]; |
d3e3972c | 10418 | const char *wd = getpwd (); |
a96c67ec | 10419 | int language; |
a3f97cbb | 10420 | |
a96c67ec JM |
10421 | die = new_die (DW_TAG_compile_unit, NULL); |
10422 | add_name_attribute (die, filename); | |
bdb669cb | 10423 | |
a96c67ec JM |
10424 | if (wd != NULL && filename[0] != DIR_SEPARATOR) |
10425 | add_AT_string (die, DW_AT_comp_dir, wd); | |
a3f97cbb JW |
10426 | |
10427 | sprintf (producer, "%s %s", language_string, version_string); | |
10428 | ||
10429 | #ifdef MIPS_DEBUGGING_INFO | |
10430 | /* The MIPS/SGI compilers place the 'cc' command line options in the producer | |
10431 | string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do | |
10432 | not appear in the producer string, the debugger reaches the conclusion | |
10433 | that the object file is stripped and has no debugging information. | |
10434 | To get the MIPS/SGI debugger to believe that there is debugging | |
10435 | information in the object file, we add a -g to the producer string. */ | |
4927276d JM |
10436 | if (debug_info_level > DINFO_LEVEL_TERSE) |
10437 | strcat (producer, " -g"); | |
a3f97cbb JW |
10438 | #endif |
10439 | ||
a96c67ec | 10440 | add_AT_string (die, DW_AT_producer, producer); |
a9d38797 | 10441 | |
a3f97cbb | 10442 | if (strcmp (language_string, "GNU C++") == 0) |
a96c67ec | 10443 | language = DW_LANG_C_plus_plus; |
a3f97cbb | 10444 | else if (strcmp (language_string, "GNU Ada") == 0) |
a96c67ec | 10445 | language = DW_LANG_Ada83; |
a9d38797 | 10446 | else if (strcmp (language_string, "GNU F77") == 0) |
a96c67ec | 10447 | language = DW_LANG_Fortran77; |
bc28c45b | 10448 | else if (strcmp (language_string, "GNU Pascal") == 0) |
a96c67ec | 10449 | language = DW_LANG_Pascal83; |
28985b81 AG |
10450 | else if (strcmp (language_string, "GNU Java") == 0) |
10451 | language = DW_LANG_Java; | |
a3f97cbb | 10452 | else if (flag_traditional) |
a96c67ec | 10453 | language = DW_LANG_C; |
a3f97cbb | 10454 | else |
a96c67ec | 10455 | language = DW_LANG_C89; |
a9d38797 | 10456 | |
a96c67ec JM |
10457 | add_AT_unsigned (die, DW_AT_language, language); |
10458 | ||
10459 | return die; | |
a3f97cbb JW |
10460 | } |
10461 | ||
10462 | /* Generate a DIE for a string type. */ | |
71dfc51f | 10463 | |
a3f97cbb JW |
10464 | static void |
10465 | gen_string_type_die (type, context_die) | |
10466 | register tree type; | |
10467 | register dw_die_ref context_die; | |
10468 | { | |
71dfc51f RK |
10469 | register dw_die_ref type_die |
10470 | = new_die (DW_TAG_string_type, scope_die_for (type, context_die)); | |
10471 | ||
bdb669cb | 10472 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
10473 | |
10474 | /* Fudge the string length attribute for now. */ | |
556273e0 | 10475 | |
a3f97cbb | 10476 | /* TODO: add string length info. |
71dfc51f | 10477 | string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type))); |
a3f97cbb JW |
10478 | bound_representation (upper_bound, 0, 'u'); */ |
10479 | } | |
10480 | ||
61b32c02 | 10481 | /* Generate the DIE for a base class. */ |
71dfc51f | 10482 | |
61b32c02 JM |
10483 | static void |
10484 | gen_inheritance_die (binfo, context_die) | |
10485 | register tree binfo; | |
10486 | register dw_die_ref context_die; | |
10487 | { | |
10488 | dw_die_ref die = new_die (DW_TAG_inheritance, context_die); | |
71dfc51f | 10489 | |
61b32c02 JM |
10490 | add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die); |
10491 | add_data_member_location_attribute (die, binfo); | |
71dfc51f | 10492 | |
61b32c02 JM |
10493 | if (TREE_VIA_VIRTUAL (binfo)) |
10494 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); | |
10495 | if (TREE_VIA_PUBLIC (binfo)) | |
10496 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public); | |
10497 | else if (TREE_VIA_PROTECTED (binfo)) | |
10498 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected); | |
10499 | } | |
10500 | ||
956d6950 | 10501 | /* Generate a DIE for a class member. */ |
71dfc51f | 10502 | |
a3f97cbb JW |
10503 | static void |
10504 | gen_member_die (type, context_die) | |
10505 | register tree type; | |
10506 | register dw_die_ref context_die; | |
10507 | { | |
61b32c02 | 10508 | register tree member; |
10a11b75 | 10509 | dw_die_ref child; |
71dfc51f | 10510 | |
a3f97cbb JW |
10511 | /* If this is not an incomplete type, output descriptions of each of its |
10512 | members. Note that as we output the DIEs necessary to represent the | |
10513 | members of this record or union type, we will also be trying to output | |
10514 | DIEs to represent the *types* of those members. However the `type' | |
556273e0 KH |
10515 | function (above) will specifically avoid generating type DIEs for member |
10516 | types *within* the list of member DIEs for this (containing) type execpt | |
a3f97cbb JW |
10517 | for those types (of members) which are explicitly marked as also being |
10518 | members of this (containing) type themselves. The g++ front- end can | |
10519 | force any given type to be treated as a member of some other | |
556273e0 | 10520 | (containing) type by setting the TYPE_CONTEXT of the given (member) type |
a3f97cbb JW |
10521 | to point to the TREE node representing the appropriate (containing) |
10522 | type. */ | |
10523 | ||
61b32c02 JM |
10524 | /* First output info about the base classes. */ |
10525 | if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type)) | |
a3f97cbb | 10526 | { |
61b32c02 JM |
10527 | register tree bases = TYPE_BINFO_BASETYPES (type); |
10528 | register int n_bases = TREE_VEC_LENGTH (bases); | |
10529 | register int i; | |
10530 | ||
10531 | for (i = 0; i < n_bases; i++) | |
10532 | gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die); | |
a3f97cbb JW |
10533 | } |
10534 | ||
61b32c02 JM |
10535 | /* Now output info about the data members and type members. */ |
10536 | for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member)) | |
10a11b75 JM |
10537 | { |
10538 | /* If we thought we were generating minimal debug info for TYPE | |
10539 | and then changed our minds, some of the member declarations | |
10540 | may have already been defined. Don't define them again, but | |
10541 | do put them in the right order. */ | |
10542 | ||
10543 | child = lookup_decl_die (member); | |
10544 | if (child) | |
10545 | splice_child_die (context_die, child); | |
10546 | else | |
10547 | gen_decl_die (member, context_die); | |
10548 | } | |
61b32c02 | 10549 | |
a3f97cbb | 10550 | /* Now output info about the function members (if any). */ |
61b32c02 | 10551 | for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member)) |
10a11b75 | 10552 | { |
5daf7c0a JM |
10553 | /* Don't include clones in the member list. */ |
10554 | if (DECL_ABSTRACT_ORIGIN (member)) | |
10555 | continue; | |
10556 | ||
10a11b75 JM |
10557 | child = lookup_decl_die (member); |
10558 | if (child) | |
10559 | splice_child_die (context_die, child); | |
10560 | else | |
10561 | gen_decl_die (member, context_die); | |
10562 | } | |
a3f97cbb JW |
10563 | } |
10564 | ||
10a11b75 JM |
10565 | /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG |
10566 | is set, we pretend that the type was never defined, so we only get the | |
10567 | member DIEs needed by later specification DIEs. */ | |
71dfc51f | 10568 | |
a3f97cbb | 10569 | static void |
273dbe67 | 10570 | gen_struct_or_union_type_die (type, context_die) |
a3f97cbb | 10571 | register tree type; |
a3f97cbb JW |
10572 | register dw_die_ref context_die; |
10573 | { | |
273dbe67 | 10574 | register dw_die_ref type_die = lookup_type_die (type); |
a082c85a JM |
10575 | register dw_die_ref scope_die = 0; |
10576 | register int nested = 0; | |
10a11b75 | 10577 | int complete = (TYPE_SIZE (type) |
65e1263a JW |
10578 | && (! TYPE_STUB_DECL (type) |
10579 | || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)))); | |
273dbe67 | 10580 | |
10a11b75 | 10581 | if (type_die && ! complete) |
273dbe67 | 10582 | return; |
a082c85a | 10583 | |
71dfc51f | 10584 | if (TYPE_CONTEXT (type) != NULL_TREE |
5f2f160c | 10585 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))) |
a082c85a JM |
10586 | nested = 1; |
10587 | ||
a94dbf2c | 10588 | scope_die = scope_die_for (type, context_die); |
a082c85a JM |
10589 | |
10590 | if (! type_die || (nested && scope_die == comp_unit_die)) | |
273dbe67 | 10591 | /* First occurrence of type or toplevel definition of nested class. */ |
a3f97cbb | 10592 | { |
273dbe67 | 10593 | register dw_die_ref old_die = type_die; |
71dfc51f | 10594 | |
a3f97cbb JW |
10595 | type_die = new_die (TREE_CODE (type) == RECORD_TYPE |
10596 | ? DW_TAG_structure_type : DW_TAG_union_type, | |
a082c85a | 10597 | scope_die); |
a3f97cbb | 10598 | equate_type_number_to_die (type, type_die); |
273dbe67 JM |
10599 | if (old_die) |
10600 | add_AT_die_ref (type_die, DW_AT_specification, old_die); | |
5de0e8d4 JM |
10601 | else |
10602 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 10603 | } |
4b674448 | 10604 | else |
273dbe67 | 10605 | remove_AT (type_die, DW_AT_declaration); |
a3f97cbb JW |
10606 | |
10607 | /* If this type has been completed, then give it a byte_size attribute and | |
10608 | then give a list of members. */ | |
2081603c | 10609 | if (complete) |
a3f97cbb | 10610 | { |
556273e0 | 10611 | /* Prevent infinite recursion in cases where the type of some member of |
a3f97cbb JW |
10612 | this type is expressed in terms of this type itself. */ |
10613 | TREE_ASM_WRITTEN (type) = 1; | |
273dbe67 | 10614 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 10615 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 10616 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 10617 | |
ef76d03b JW |
10618 | /* If the first reference to this type was as the return type of an |
10619 | inline function, then it may not have a parent. Fix this now. */ | |
10620 | if (type_die->die_parent == NULL) | |
10621 | add_child_die (scope_die, type_die); | |
10622 | ||
273dbe67 JM |
10623 | push_decl_scope (type); |
10624 | gen_member_die (type, type_die); | |
10625 | pop_decl_scope (); | |
71dfc51f | 10626 | |
a94dbf2c JM |
10627 | /* GNU extension: Record what type our vtable lives in. */ |
10628 | if (TYPE_VFIELD (type)) | |
10629 | { | |
10630 | tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type)); | |
71dfc51f | 10631 | |
de6e505e JM |
10632 | gen_type_die (vtype, context_die); |
10633 | add_AT_die_ref (type_die, DW_AT_containing_type, | |
10634 | lookup_type_die (vtype)); | |
a94dbf2c | 10635 | } |
a3f97cbb | 10636 | } |
4b674448 | 10637 | else |
8a8c3656 JM |
10638 | { |
10639 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a30d4514 | 10640 | |
9765e357 | 10641 | /* We don't need to do this for function-local types. */ |
f19f17e0 | 10642 | if (! decl_function_context (TYPE_STUB_DECL (type))) |
a30d4514 | 10643 | add_incomplete_type (type); |
8a8c3656 | 10644 | } |
a3f97cbb JW |
10645 | } |
10646 | ||
10647 | /* Generate a DIE for a subroutine _type_. */ | |
71dfc51f | 10648 | |
a3f97cbb JW |
10649 | static void |
10650 | gen_subroutine_type_die (type, context_die) | |
10651 | register tree type; | |
10652 | register dw_die_ref context_die; | |
10653 | { | |
10654 | register tree return_type = TREE_TYPE (type); | |
71dfc51f RK |
10655 | register dw_die_ref subr_die |
10656 | = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die)); | |
10657 | ||
a3f97cbb JW |
10658 | equate_type_number_to_die (type, subr_die); |
10659 | add_prototyped_attribute (subr_die, type); | |
a3f97cbb | 10660 | add_type_attribute (subr_die, return_type, 0, 0, context_die); |
a94dbf2c | 10661 | gen_formal_types_die (type, subr_die); |
a3f97cbb JW |
10662 | } |
10663 | ||
10664 | /* Generate a DIE for a type definition */ | |
71dfc51f | 10665 | |
a3f97cbb JW |
10666 | static void |
10667 | gen_typedef_die (decl, context_die) | |
10668 | register tree decl; | |
10669 | register dw_die_ref context_die; | |
10670 | { | |
a3f97cbb | 10671 | register dw_die_ref type_die; |
a94dbf2c JM |
10672 | register tree origin; |
10673 | ||
10674 | if (TREE_ASM_WRITTEN (decl)) | |
10675 | return; | |
10676 | TREE_ASM_WRITTEN (decl) = 1; | |
10677 | ||
777ad4c2 | 10678 | type_die = new_die (DW_TAG_typedef, context_die); |
a94dbf2c | 10679 | origin = decl_ultimate_origin (decl); |
a3f97cbb | 10680 | if (origin != NULL) |
a94dbf2c | 10681 | add_abstract_origin_attribute (type_die, origin); |
a3f97cbb JW |
10682 | else |
10683 | { | |
a94dbf2c | 10684 | register tree type; |
a3f97cbb | 10685 | add_name_and_src_coords_attributes (type_die, decl); |
a94dbf2c JM |
10686 | if (DECL_ORIGINAL_TYPE (decl)) |
10687 | { | |
10688 | type = DECL_ORIGINAL_TYPE (decl); | |
62e3bf54 JM |
10689 | |
10690 | if (type == TREE_TYPE (decl)) | |
10691 | abort (); | |
10692 | else | |
10693 | equate_type_number_to_die (TREE_TYPE (decl), type_die); | |
a94dbf2c JM |
10694 | } |
10695 | else | |
10696 | type = TREE_TYPE (decl); | |
10697 | add_type_attribute (type_die, type, TREE_READONLY (decl), | |
10698 | TREE_THIS_VOLATILE (decl), context_die); | |
a3f97cbb | 10699 | } |
71dfc51f | 10700 | |
a3f97cbb | 10701 | if (DECL_ABSTRACT (decl)) |
a94dbf2c | 10702 | equate_decl_number_to_die (decl, type_die); |
a3f97cbb JW |
10703 | } |
10704 | ||
10705 | /* Generate a type description DIE. */ | |
71dfc51f | 10706 | |
a3f97cbb JW |
10707 | static void |
10708 | gen_type_die (type, context_die) | |
10709 | register tree type; | |
10710 | register dw_die_ref context_die; | |
10711 | { | |
348bb3c7 JM |
10712 | int need_pop; |
10713 | ||
71dfc51f RK |
10714 | if (type == NULL_TREE || type == error_mark_node) |
10715 | return; | |
a3f97cbb | 10716 | |
38e01259 | 10717 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
10718 | this type (i.e. without any const or volatile qualifiers) so get the |
10719 | main variant (i.e. the unqualified version) of this type now. */ | |
10720 | type = type_main_variant (type); | |
10721 | ||
10722 | if (TREE_ASM_WRITTEN (type)) | |
71dfc51f | 10723 | return; |
a3f97cbb | 10724 | |
a94dbf2c JM |
10725 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
10726 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
556273e0 | 10727 | { |
a94dbf2c JM |
10728 | TREE_ASM_WRITTEN (type) = 1; |
10729 | gen_decl_die (TYPE_NAME (type), context_die); | |
10730 | return; | |
10731 | } | |
10732 | ||
a3f97cbb JW |
10733 | switch (TREE_CODE (type)) |
10734 | { | |
10735 | case ERROR_MARK: | |
10736 | break; | |
10737 | ||
10738 | case POINTER_TYPE: | |
10739 | case REFERENCE_TYPE: | |
956d6950 JL |
10740 | /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This |
10741 | ensures that the gen_type_die recursion will terminate even if the | |
10742 | type is recursive. Recursive types are possible in Ada. */ | |
10743 | /* ??? We could perhaps do this for all types before the switch | |
10744 | statement. */ | |
10745 | TREE_ASM_WRITTEN (type) = 1; | |
10746 | ||
a3f97cbb JW |
10747 | /* For these types, all that is required is that we output a DIE (or a |
10748 | set of DIEs) to represent the "basis" type. */ | |
10749 | gen_type_die (TREE_TYPE (type), context_die); | |
10750 | break; | |
10751 | ||
10752 | case OFFSET_TYPE: | |
556273e0 | 10753 | /* This code is used for C++ pointer-to-data-member types. |
71dfc51f | 10754 | Output a description of the relevant class type. */ |
a3f97cbb | 10755 | gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die); |
71dfc51f | 10756 | |
a3f97cbb JW |
10757 | /* Output a description of the type of the object pointed to. */ |
10758 | gen_type_die (TREE_TYPE (type), context_die); | |
71dfc51f | 10759 | |
a3f97cbb JW |
10760 | /* Now output a DIE to represent this pointer-to-data-member type |
10761 | itself. */ | |
10762 | gen_ptr_to_mbr_type_die (type, context_die); | |
10763 | break; | |
10764 | ||
10765 | case SET_TYPE: | |
10766 | gen_type_die (TYPE_DOMAIN (type), context_die); | |
10767 | gen_set_type_die (type, context_die); | |
10768 | break; | |
10769 | ||
10770 | case FILE_TYPE: | |
10771 | gen_type_die (TREE_TYPE (type), context_die); | |
10772 | abort (); /* No way to represent these in Dwarf yet! */ | |
10773 | break; | |
10774 | ||
10775 | case FUNCTION_TYPE: | |
10776 | /* Force out return type (in case it wasn't forced out already). */ | |
10777 | gen_type_die (TREE_TYPE (type), context_die); | |
10778 | gen_subroutine_type_die (type, context_die); | |
10779 | break; | |
10780 | ||
10781 | case METHOD_TYPE: | |
10782 | /* Force out return type (in case it wasn't forced out already). */ | |
10783 | gen_type_die (TREE_TYPE (type), context_die); | |
10784 | gen_subroutine_type_die (type, context_die); | |
10785 | break; | |
10786 | ||
10787 | case ARRAY_TYPE: | |
10788 | if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE) | |
10789 | { | |
10790 | gen_type_die (TREE_TYPE (type), context_die); | |
10791 | gen_string_type_die (type, context_die); | |
10792 | } | |
10793 | else | |
71dfc51f | 10794 | gen_array_type_die (type, context_die); |
a3f97cbb JW |
10795 | break; |
10796 | ||
4061f623 BS |
10797 | case VECTOR_TYPE: |
10798 | gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die); | |
10799 | break; | |
10800 | ||
a3f97cbb JW |
10801 | case ENUMERAL_TYPE: |
10802 | case RECORD_TYPE: | |
10803 | case UNION_TYPE: | |
10804 | case QUAL_UNION_TYPE: | |
a082c85a | 10805 | /* If this is a nested type whose containing class hasn't been |
348bb3c7 JM |
10806 | written out yet, writing it out will cover this one, too. |
10807 | This does not apply to instantiations of member class templates; | |
10808 | they need to be added to the containing class as they are | |
777ad4c2 | 10809 | generated. FIXME: This hurts the idea of combining type decls |
348bb3c7 JM |
10810 | from multiple TUs, since we can't predict what set of template |
10811 | instantiations we'll get. */ | |
a082c85a | 10812 | if (TYPE_CONTEXT (type) |
5f2f160c | 10813 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) |
a082c85a | 10814 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) |
a94dbf2c JM |
10815 | { |
10816 | gen_type_die (TYPE_CONTEXT (type), context_die); | |
10817 | ||
348bb3c7 | 10818 | if (TREE_ASM_WRITTEN (type)) |
a94dbf2c JM |
10819 | return; |
10820 | ||
10821 | /* If that failed, attach ourselves to the stub. */ | |
10822 | push_decl_scope (TYPE_CONTEXT (type)); | |
10823 | context_die = lookup_type_die (TYPE_CONTEXT (type)); | |
348bb3c7 | 10824 | need_pop = 1; |
a94dbf2c | 10825 | } |
348bb3c7 JM |
10826 | else |
10827 | need_pop = 0; | |
a94dbf2c JM |
10828 | |
10829 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
273dbe67 | 10830 | gen_enumeration_type_die (type, context_die); |
a3f97cbb | 10831 | else |
273dbe67 | 10832 | gen_struct_or_union_type_die (type, context_die); |
4b674448 | 10833 | |
348bb3c7 | 10834 | if (need_pop) |
a94dbf2c JM |
10835 | pop_decl_scope (); |
10836 | ||
4b674448 | 10837 | /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix |
a082c85a JM |
10838 | it up if it is ever completed. gen_*_type_die will set it for us |
10839 | when appropriate. */ | |
10840 | return; | |
a3f97cbb JW |
10841 | |
10842 | case VOID_TYPE: | |
10843 | case INTEGER_TYPE: | |
10844 | case REAL_TYPE: | |
10845 | case COMPLEX_TYPE: | |
10846 | case BOOLEAN_TYPE: | |
10847 | case CHAR_TYPE: | |
10848 | /* No DIEs needed for fundamental types. */ | |
10849 | break; | |
10850 | ||
10851 | case LANG_TYPE: | |
10852 | /* No Dwarf representation currently defined. */ | |
10853 | break; | |
10854 | ||
10855 | default: | |
10856 | abort (); | |
10857 | } | |
10858 | ||
10859 | TREE_ASM_WRITTEN (type) = 1; | |
10860 | } | |
10861 | ||
10862 | /* Generate a DIE for a tagged type instantiation. */ | |
71dfc51f | 10863 | |
a3f97cbb JW |
10864 | static void |
10865 | gen_tagged_type_instantiation_die (type, context_die) | |
10866 | register tree type; | |
10867 | register dw_die_ref context_die; | |
10868 | { | |
71dfc51f RK |
10869 | if (type == NULL_TREE || type == error_mark_node) |
10870 | return; | |
a3f97cbb | 10871 | |
38e01259 | 10872 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
10873 | this type (i.e. without any const or volatile qualifiers) so make sure |
10874 | that we have the main variant (i.e. the unqualified version) of this | |
10875 | type now. */ | |
bbc6ae08 | 10876 | if (type != type_main_variant (type)) |
3a88cbd1 | 10877 | abort (); |
a3f97cbb | 10878 | |
203588e7 | 10879 | /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is |
bbc6ae08 | 10880 | an instance of an unresolved type. */ |
556273e0 | 10881 | |
a3f97cbb JW |
10882 | switch (TREE_CODE (type)) |
10883 | { | |
10884 | case ERROR_MARK: | |
10885 | break; | |
10886 | ||
10887 | case ENUMERAL_TYPE: | |
10888 | gen_inlined_enumeration_type_die (type, context_die); | |
10889 | break; | |
10890 | ||
10891 | case RECORD_TYPE: | |
10892 | gen_inlined_structure_type_die (type, context_die); | |
10893 | break; | |
10894 | ||
10895 | case UNION_TYPE: | |
10896 | case QUAL_UNION_TYPE: | |
10897 | gen_inlined_union_type_die (type, context_die); | |
10898 | break; | |
10899 | ||
10900 | default: | |
71dfc51f | 10901 | abort (); |
a3f97cbb JW |
10902 | } |
10903 | } | |
10904 | ||
10905 | /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the | |
10906 | things which are local to the given block. */ | |
71dfc51f | 10907 | |
a3f97cbb | 10908 | static void |
d7248bff | 10909 | gen_block_die (stmt, context_die, depth) |
a3f97cbb JW |
10910 | register tree stmt; |
10911 | register dw_die_ref context_die; | |
d7248bff | 10912 | int depth; |
a3f97cbb JW |
10913 | { |
10914 | register int must_output_die = 0; | |
10915 | register tree origin; | |
10916 | register tree decl; | |
10917 | register enum tree_code origin_code; | |
10918 | ||
10919 | /* Ignore blocks never really used to make RTL. */ | |
1e7f092a JM |
10920 | if (stmt == NULL_TREE || !TREE_USED (stmt) |
10921 | || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt))) | |
71dfc51f | 10922 | return; |
a3f97cbb | 10923 | |
a20612aa RH |
10924 | /* If the block is one fragment of a non-contiguous block, do not |
10925 | process the variables, since they will have been done by the | |
10926 | origin block. Do process subblocks. */ | |
10927 | if (BLOCK_FRAGMENT_ORIGIN (stmt)) | |
10928 | { | |
10929 | tree sub; | |
10930 | ||
10931 | for (sub= BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub)) | |
10932 | gen_block_die (sub, context_die, depth + 1); | |
10933 | return; | |
10934 | } | |
10935 | ||
a3f97cbb JW |
10936 | /* Determine the "ultimate origin" of this block. This block may be an |
10937 | inlined instance of an inlined instance of inline function, so we have | |
10938 | to trace all of the way back through the origin chain to find out what | |
10939 | sort of node actually served as the original seed for the creation of | |
10940 | the current block. */ | |
10941 | origin = block_ultimate_origin (stmt); | |
10942 | origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; | |
10943 | ||
10944 | /* Determine if we need to output any Dwarf DIEs at all to represent this | |
10945 | block. */ | |
10946 | if (origin_code == FUNCTION_DECL) | |
71dfc51f RK |
10947 | /* The outer scopes for inlinings *must* always be represented. We |
10948 | generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */ | |
10949 | must_output_die = 1; | |
a3f97cbb JW |
10950 | else |
10951 | { | |
10952 | /* In the case where the current block represents an inlining of the | |
556273e0 | 10953 | "body block" of an inline function, we must *NOT* output any DIE for |
a3f97cbb JW |
10954 | this block because we have already output a DIE to represent the |
10955 | whole inlined function scope and the "body block" of any function | |
10956 | doesn't really represent a different scope according to ANSI C | |
10957 | rules. So we check here to make sure that this block does not | |
10958 | represent a "body block inlining" before trying to set the | |
10959 | `must_output_die' flag. */ | |
d7248bff | 10960 | if (! is_body_block (origin ? origin : stmt)) |
a3f97cbb JW |
10961 | { |
10962 | /* Determine if this block directly contains any "significant" | |
10963 | local declarations which we will need to output DIEs for. */ | |
10964 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
71dfc51f RK |
10965 | /* We are not in terse mode so *any* local declaration counts |
10966 | as being a "significant" one. */ | |
10967 | must_output_die = (BLOCK_VARS (stmt) != NULL); | |
a3f97cbb | 10968 | else |
71dfc51f RK |
10969 | /* We are in terse mode, so only local (nested) function |
10970 | definitions count as "significant" local declarations. */ | |
10971 | for (decl = BLOCK_VARS (stmt); | |
10972 | decl != NULL; decl = TREE_CHAIN (decl)) | |
10973 | if (TREE_CODE (decl) == FUNCTION_DECL | |
10974 | && DECL_INITIAL (decl)) | |
a3f97cbb | 10975 | { |
71dfc51f RK |
10976 | must_output_die = 1; |
10977 | break; | |
a3f97cbb | 10978 | } |
a3f97cbb JW |
10979 | } |
10980 | } | |
10981 | ||
10982 | /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block | |
10983 | DIE for any block which contains no significant local declarations at | |
10984 | all. Rather, in such cases we just call `decls_for_scope' so that any | |
10985 | needed Dwarf info for any sub-blocks will get properly generated. Note | |
10986 | that in terse mode, our definition of what constitutes a "significant" | |
10987 | local declaration gets restricted to include only inlined function | |
10988 | instances and local (nested) function definitions. */ | |
10989 | if (must_output_die) | |
10990 | { | |
10991 | if (origin_code == FUNCTION_DECL) | |
71dfc51f | 10992 | gen_inlined_subroutine_die (stmt, context_die, depth); |
a3f97cbb | 10993 | else |
71dfc51f | 10994 | gen_lexical_block_die (stmt, context_die, depth); |
a3f97cbb JW |
10995 | } |
10996 | else | |
d7248bff | 10997 | decls_for_scope (stmt, context_die, depth); |
a3f97cbb JW |
10998 | } |
10999 | ||
11000 | /* Generate all of the decls declared within a given scope and (recursively) | |
9ec36da5 | 11001 | all of its sub-blocks. */ |
71dfc51f | 11002 | |
a3f97cbb | 11003 | static void |
d7248bff | 11004 | decls_for_scope (stmt, context_die, depth) |
a3f97cbb JW |
11005 | register tree stmt; |
11006 | register dw_die_ref context_die; | |
d7248bff | 11007 | int depth; |
a3f97cbb JW |
11008 | { |
11009 | register tree decl; | |
11010 | register tree subblocks; | |
71dfc51f | 11011 | |
a3f97cbb | 11012 | /* Ignore blocks never really used to make RTL. */ |
71dfc51f RK |
11013 | if (stmt == NULL_TREE || ! TREE_USED (stmt)) |
11014 | return; | |
11015 | ||
88dad228 JM |
11016 | /* Output the DIEs to represent all of the data objects and typedefs |
11017 | declared directly within this block but not within any nested | |
11018 | sub-blocks. Also, nested function and tag DIEs have been | |
11019 | generated with a parent of NULL; fix that up now. */ | |
a3f97cbb JW |
11020 | for (decl = BLOCK_VARS (stmt); |
11021 | decl != NULL; decl = TREE_CHAIN (decl)) | |
11022 | { | |
a94dbf2c JM |
11023 | register dw_die_ref die; |
11024 | ||
88dad228 | 11025 | if (TREE_CODE (decl) == FUNCTION_DECL) |
a94dbf2c | 11026 | die = lookup_decl_die (decl); |
88dad228 | 11027 | else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)) |
a94dbf2c JM |
11028 | die = lookup_type_die (TREE_TYPE (decl)); |
11029 | else | |
11030 | die = NULL; | |
11031 | ||
71dfc51f | 11032 | if (die != NULL && die->die_parent == NULL) |
ef76d03b | 11033 | add_child_die (context_die, die); |
88dad228 JM |
11034 | else |
11035 | gen_decl_die (decl, context_die); | |
a3f97cbb JW |
11036 | } |
11037 | ||
11038 | /* Output the DIEs to represent all sub-blocks (and the items declared | |
11039 | therein) of this block. */ | |
11040 | for (subblocks = BLOCK_SUBBLOCKS (stmt); | |
11041 | subblocks != NULL; | |
11042 | subblocks = BLOCK_CHAIN (subblocks)) | |
71dfc51f | 11043 | gen_block_die (subblocks, context_die, depth + 1); |
a3f97cbb JW |
11044 | } |
11045 | ||
a94dbf2c | 11046 | /* Is this a typedef we can avoid emitting? */ |
71dfc51f RK |
11047 | |
11048 | static inline int | |
a94dbf2c JM |
11049 | is_redundant_typedef (decl) |
11050 | register tree decl; | |
11051 | { | |
11052 | if (TYPE_DECL_IS_STUB (decl)) | |
11053 | return 1; | |
71dfc51f | 11054 | |
a94dbf2c JM |
11055 | if (DECL_ARTIFICIAL (decl) |
11056 | && DECL_CONTEXT (decl) | |
11057 | && is_tagged_type (DECL_CONTEXT (decl)) | |
11058 | && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL | |
11059 | && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) | |
11060 | /* Also ignore the artificial member typedef for the class name. */ | |
11061 | return 1; | |
71dfc51f | 11062 | |
a94dbf2c JM |
11063 | return 0; |
11064 | } | |
11065 | ||
a3f97cbb | 11066 | /* Generate Dwarf debug information for a decl described by DECL. */ |
71dfc51f | 11067 | |
a3f97cbb JW |
11068 | static void |
11069 | gen_decl_die (decl, context_die) | |
11070 | register tree decl; | |
11071 | register dw_die_ref context_die; | |
11072 | { | |
11073 | register tree origin; | |
71dfc51f | 11074 | |
a3f97cbb | 11075 | if (TREE_CODE (decl) == ERROR_MARK) |
71dfc51f | 11076 | return; |
a3f97cbb | 11077 | |
fcd7f76b JM |
11078 | /* If this ..._DECL node is marked to be ignored, then ignore it. */ |
11079 | if (DECL_IGNORED_P (decl)) | |
71dfc51f | 11080 | return; |
a3f97cbb | 11081 | |
a3f97cbb JW |
11082 | switch (TREE_CODE (decl)) |
11083 | { | |
11084 | case CONST_DECL: | |
556273e0 | 11085 | /* The individual enumerators of an enum type get output when we output |
a3f97cbb JW |
11086 | the Dwarf representation of the relevant enum type itself. */ |
11087 | break; | |
11088 | ||
11089 | case FUNCTION_DECL: | |
4edb7b60 JM |
11090 | /* Don't output any DIEs to represent mere function declarations, |
11091 | unless they are class members or explicit block externs. */ | |
11092 | if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE | |
777ad4c2 | 11093 | && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl))) |
71dfc51f | 11094 | break; |
bdb669cb | 11095 | |
5daf7c0a JM |
11096 | /* If we're emitting a clone, emit info for the abstract instance. */ |
11097 | if (DECL_ORIGIN (decl) != decl) | |
11098 | dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl)); | |
1cfdcc15 JM |
11099 | /* If we're emitting an out-of-line copy of an inline function, |
11100 | emit info for the abstract instance and set up to refer to it. */ | |
5daf7c0a JM |
11101 | else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl) |
11102 | && ! class_scope_p (context_die) | |
11103 | /* dwarf2out_abstract_function won't emit a die if this is just | |
11104 | a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in | |
11105 | that case, because that works only if we have a die. */ | |
11106 | && DECL_INITIAL (decl) != NULL_TREE) | |
1cfdcc15 | 11107 | { |
1edf43d6 | 11108 | dwarf2out_abstract_function (decl); |
1cfdcc15 JM |
11109 | set_decl_origin_self (decl); |
11110 | } | |
5daf7c0a JM |
11111 | /* Otherwise we're emitting the primary DIE for this decl. */ |
11112 | else if (debug_info_level > DINFO_LEVEL_TERSE) | |
a94dbf2c JM |
11113 | { |
11114 | /* Before we describe the FUNCTION_DECL itself, make sure that we | |
11115 | have described its return type. */ | |
11116 | gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); | |
11117 | ||
2081603c JM |
11118 | /* And its virtual context. */ |
11119 | if (DECL_VINDEX (decl) != NULL_TREE) | |
11120 | gen_type_die (DECL_CONTEXT (decl), context_die); | |
11121 | ||
a94dbf2c JM |
11122 | /* And its containing type. */ |
11123 | origin = decl_class_context (decl); | |
71dfc51f | 11124 | if (origin != NULL_TREE) |
10a11b75 | 11125 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 11126 | } |
a3f97cbb JW |
11127 | |
11128 | /* Now output a DIE to represent the function itself. */ | |
11129 | gen_subprogram_die (decl, context_die); | |
11130 | break; | |
11131 | ||
11132 | case TYPE_DECL: | |
11133 | /* If we are in terse mode, don't generate any DIEs to represent any | |
4927276d | 11134 | actual typedefs. */ |
a3f97cbb | 11135 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 11136 | break; |
a3f97cbb | 11137 | |
556273e0 | 11138 | /* In the special case of a TYPE_DECL node representing the |
5c90448c | 11139 | declaration of some type tag, if the given TYPE_DECL is marked as |
a3f97cbb JW |
11140 | having been instantiated from some other (original) TYPE_DECL node |
11141 | (e.g. one which was generated within the original definition of an | |
11142 | inline function) we have to generate a special (abbreviated) | |
556273e0 | 11143 | DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type |
a3f97cbb | 11144 | DIE here. */ |
2081603c | 11145 | if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE) |
a3f97cbb JW |
11146 | { |
11147 | gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die); | |
11148 | break; | |
11149 | } | |
a3f97cbb | 11150 | |
a94dbf2c JM |
11151 | if (is_redundant_typedef (decl)) |
11152 | gen_type_die (TREE_TYPE (decl), context_die); | |
11153 | else | |
71dfc51f RK |
11154 | /* Output a DIE to represent the typedef itself. */ |
11155 | gen_typedef_die (decl, context_die); | |
a3f97cbb JW |
11156 | break; |
11157 | ||
11158 | case LABEL_DECL: | |
11159 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
71dfc51f | 11160 | gen_label_die (decl, context_die); |
a3f97cbb JW |
11161 | break; |
11162 | ||
11163 | case VAR_DECL: | |
11164 | /* If we are in terse mode, don't generate any DIEs to represent any | |
11165 | variable declarations or definitions. */ | |
11166 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 11167 | break; |
a3f97cbb JW |
11168 | |
11169 | /* Output any DIEs that are needed to specify the type of this data | |
11170 | object. */ | |
11171 | gen_type_die (TREE_TYPE (decl), context_die); | |
11172 | ||
a94dbf2c JM |
11173 | /* And its containing type. */ |
11174 | origin = decl_class_context (decl); | |
71dfc51f | 11175 | if (origin != NULL_TREE) |
10a11b75 | 11176 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 11177 | |
a3f97cbb JW |
11178 | /* Now output the DIE to represent the data object itself. This gets |
11179 | complicated because of the possibility that the VAR_DECL really | |
11180 | represents an inlined instance of a formal parameter for an inline | |
11181 | function. */ | |
11182 | origin = decl_ultimate_origin (decl); | |
71dfc51f RK |
11183 | if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL) |
11184 | gen_formal_parameter_die (decl, context_die); | |
a3f97cbb | 11185 | else |
71dfc51f | 11186 | gen_variable_die (decl, context_die); |
a3f97cbb JW |
11187 | break; |
11188 | ||
11189 | case FIELD_DECL: | |
a94dbf2c JM |
11190 | /* Ignore the nameless fields that are used to skip bits, but |
11191 | handle C++ anonymous unions. */ | |
71dfc51f RK |
11192 | if (DECL_NAME (decl) != NULL_TREE |
11193 | || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE) | |
a3f97cbb JW |
11194 | { |
11195 | gen_type_die (member_declared_type (decl), context_die); | |
11196 | gen_field_die (decl, context_die); | |
11197 | } | |
11198 | break; | |
11199 | ||
11200 | case PARM_DECL: | |
11201 | gen_type_die (TREE_TYPE (decl), context_die); | |
11202 | gen_formal_parameter_die (decl, context_die); | |
11203 | break; | |
11204 | ||
348bb3c7 JM |
11205 | case NAMESPACE_DECL: |
11206 | /* Ignore for now. */ | |
11207 | break; | |
11208 | ||
a3f97cbb JW |
11209 | default: |
11210 | abort (); | |
11211 | } | |
a3f97cbb JW |
11212 | } |
11213 | \f | |
14a774a9 RK |
11214 | /* Add Ada "use" clause information for SGI Workshop debugger. */ |
11215 | ||
11216 | void | |
11217 | dwarf2out_add_library_unit_info (filename, context_list) | |
c6991660 KG |
11218 | const char *filename; |
11219 | const char *context_list; | |
14a774a9 RK |
11220 | { |
11221 | unsigned int file_index; | |
11222 | ||
11223 | if (filename != NULL) | |
11224 | { | |
11225 | dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die); | |
556273e0 | 11226 | tree context_list_decl |
14a774a9 RK |
11227 | = build_decl (LABEL_DECL, get_identifier (context_list), |
11228 | void_type_node); | |
11229 | ||
11230 | TREE_PUBLIC (context_list_decl) = TRUE; | |
11231 | add_name_attribute (unit_die, context_list); | |
981975b6 | 11232 | file_index = lookup_filename (filename); |
14a774a9 RK |
11233 | add_AT_unsigned (unit_die, DW_AT_decl_file, file_index); |
11234 | add_pubname (context_list_decl, unit_die); | |
11235 | } | |
11236 | } | |
11237 | ||
2b85879e NB |
11238 | /* Debug information for a global DECL. Called from toplev.c after |
11239 | compilation proper has finished. */ | |
11240 | static void | |
11241 | dwarf2out_global_decl (decl) | |
11242 | tree decl; | |
11243 | { | |
11244 | /* Output DWARF2 information for file-scope tentative data object | |
11245 | declarations, file-scope (extern) function declarations (which | |
11246 | had no corresponding body) and file-scope tagged type | |
11247 | declarations and definitions which have not yet been forced out. */ | |
11248 | ||
11249 | if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)) | |
11250 | dwarf2out_decl (decl); | |
11251 | } | |
11252 | ||
71dfc51f RK |
11253 | /* Write the debugging output for DECL. */ |
11254 | ||
a3f97cbb | 11255 | void |
88dad228 | 11256 | dwarf2out_decl (decl) |
a3f97cbb | 11257 | register tree decl; |
a3f97cbb | 11258 | { |
88dad228 JM |
11259 | register dw_die_ref context_die = comp_unit_die; |
11260 | ||
a3f97cbb | 11261 | if (TREE_CODE (decl) == ERROR_MARK) |
71dfc51f | 11262 | return; |
a3f97cbb | 11263 | |
fcd7f76b | 11264 | /* If this ..._DECL node is marked to be ignored, then ignore it. */ |
a3f97cbb | 11265 | if (DECL_IGNORED_P (decl)) |
fcd7f76b | 11266 | return; |
a3f97cbb JW |
11267 | |
11268 | switch (TREE_CODE (decl)) | |
11269 | { | |
11270 | case FUNCTION_DECL: | |
556273e0 | 11271 | /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a |
a3f97cbb JW |
11272 | builtin function. Explicit programmer-supplied declarations of |
11273 | these same functions should NOT be ignored however. */ | |
9765e357 | 11274 | if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl)) |
b1ccbc24 | 11275 | return; |
a3f97cbb JW |
11276 | |
11277 | /* What we would really like to do here is to filter out all mere | |
11278 | file-scope declarations of file-scope functions which are never | |
11279 | referenced later within this translation unit (and keep all of ones | |
556273e0 KH |
11280 | that *are* referenced later on) but we aren't clairvoyant, so we have |
11281 | no idea which functions will be referenced in the future (i.e. later | |
a3f97cbb | 11282 | on within the current translation unit). So here we just ignore all |
556273e0 | 11283 | file-scope function declarations which are not also definitions. If |
956d6950 | 11284 | and when the debugger needs to know something about these functions, |
556273e0 | 11285 | it will have to hunt around and find the DWARF information associated |
bbc6ae08 | 11286 | with the definition of the function. Note that we can't just check |
a3f97cbb JW |
11287 | `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent |
11288 | definitions and which ones represent mere declarations. We have to | |
11289 | check `DECL_INITIAL' instead. That's because the C front-end | |
11290 | supports some weird semantics for "extern inline" function | |
11291 | definitions. These can get inlined within the current translation | |
11292 | unit (an thus, we need to generate DWARF info for their abstract | |
11293 | instances so that the DWARF info for the concrete inlined instances | |
556273e0 | 11294 | can have something to refer to) but the compiler never generates any |
a3f97cbb JW |
11295 | out-of-lines instances of such things (despite the fact that they |
11296 | *are* definitions). The important point is that the C front-end | |
11297 | marks these "extern inline" functions as DECL_EXTERNAL, but we need | |
273dbe67 | 11298 | to generate DWARF for them anyway. Note that the C++ front-end also |
a3f97cbb | 11299 | plays some similar games for inline function definitions appearing |
556273e0 | 11300 | within include files which also contain |
a3f97cbb JW |
11301 | `#pragma interface' pragmas. */ |
11302 | if (DECL_INITIAL (decl) == NULL_TREE) | |
b1ccbc24 | 11303 | return; |
88dad228 | 11304 | |
9c6cd30e JM |
11305 | /* If we're a nested function, initially use a parent of NULL; if we're |
11306 | a plain function, this will be fixed up in decls_for_scope. If | |
11307 | we're a method, it will be ignored, since we already have a DIE. */ | |
88dad228 | 11308 | if (decl_function_context (decl)) |
9c6cd30e | 11309 | context_die = NULL; |
88dad228 | 11310 | |
a3f97cbb JW |
11311 | break; |
11312 | ||
11313 | case VAR_DECL: | |
556273e0 | 11314 | /* Ignore this VAR_DECL if it refers to a file-scope extern data object |
a3f97cbb JW |
11315 | declaration and if the declaration was never even referenced from |
11316 | within this entire compilation unit. We suppress these DIEs in | |
11317 | order to save space in the .debug section (by eliminating entries | |
11318 | which are probably useless). Note that we must not suppress | |
11319 | block-local extern declarations (whether used or not) because that | |
11320 | would screw-up the debugger's name lookup mechanism and cause it to | |
11321 | miss things which really ought to be in scope at a given point. */ | |
11322 | if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) | |
71dfc51f | 11323 | return; |
a3f97cbb JW |
11324 | |
11325 | /* If we are in terse mode, don't generate any DIEs to represent any | |
11326 | variable declarations or definitions. */ | |
11327 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 11328 | return; |
a3f97cbb JW |
11329 | break; |
11330 | ||
11331 | case TYPE_DECL: | |
57fb7689 JM |
11332 | /* Don't emit stubs for types unless they are needed by other DIEs. */ |
11333 | if (TYPE_DECL_SUPPRESS_DEBUG (decl)) | |
11334 | return; | |
11335 | ||
a3f97cbb | 11336 | /* Don't bother trying to generate any DIEs to represent any of the |
a9d38797 JM |
11337 | normal built-in types for the language we are compiling. */ |
11338 | if (DECL_SOURCE_LINE (decl) == 0) | |
a94dbf2c JM |
11339 | { |
11340 | /* OK, we need to generate one for `bool' so GDB knows what type | |
11341 | comparisons have. */ | |
11342 | if ((get_AT_unsigned (comp_unit_die, DW_AT_language) | |
11343 | == DW_LANG_C_plus_plus) | |
11344 | && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE) | |
11345 | modified_type_die (TREE_TYPE (decl), 0, 0, NULL); | |
71dfc51f | 11346 | |
a94dbf2c JM |
11347 | return; |
11348 | } | |
a3f97cbb | 11349 | |
88dad228 | 11350 | /* If we are in terse mode, don't generate any DIEs for types. */ |
a3f97cbb | 11351 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 11352 | return; |
88dad228 JM |
11353 | |
11354 | /* If we're a function-scope tag, initially use a parent of NULL; | |
11355 | this will be fixed up in decls_for_scope. */ | |
11356 | if (decl_function_context (decl)) | |
3f76745e | 11357 | context_die = NULL; |
88dad228 | 11358 | |
a3f97cbb JW |
11359 | break; |
11360 | ||
11361 | default: | |
11362 | return; | |
11363 | } | |
11364 | ||
88dad228 | 11365 | gen_decl_die (decl, context_die); |
a3f97cbb JW |
11366 | } |
11367 | ||
11368 | /* Output a marker (i.e. a label) for the beginning of the generated code for | |
11369 | a lexical block. */ | |
71dfc51f | 11370 | |
a5a42b92 | 11371 | static void |
e2a12aca | 11372 | dwarf2out_begin_block (line, blocknum) |
a5a42b92 NB |
11373 | unsigned int line ATTRIBUTE_UNUSED; |
11374 | unsigned int blocknum; | |
a3f97cbb | 11375 | { |
a3f97cbb | 11376 | function_section (current_function_decl); |
8215347e | 11377 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum); |
a3f97cbb JW |
11378 | } |
11379 | ||
11380 | /* Output a marker (i.e. a label) for the end of the generated code for a | |
11381 | lexical block. */ | |
71dfc51f | 11382 | |
a5a42b92 | 11383 | static void |
e2a12aca | 11384 | dwarf2out_end_block (line, blocknum) |
a5a42b92 NB |
11385 | unsigned int line ATTRIBUTE_UNUSED; |
11386 | unsigned int blocknum; | |
a3f97cbb | 11387 | { |
a3f97cbb | 11388 | function_section (current_function_decl); |
8215347e | 11389 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum); |
a3f97cbb JW |
11390 | } |
11391 | ||
64b59a80 JM |
11392 | /* Returns nonzero if it is appropriate not to emit any debugging |
11393 | information for BLOCK, because it doesn't contain any instructions. | |
fcd7f76b | 11394 | |
64b59a80 JM |
11395 | Don't allow this for blocks with nested functions or local classes |
11396 | as we would end up with orphans, and in the presence of scheduling | |
11397 | we may end up calling them anyway. */ | |
11398 | ||
e1772ac0 | 11399 | static bool |
fcd7f76b JM |
11400 | dwarf2out_ignore_block (block) |
11401 | tree block; | |
11402 | { | |
11403 | tree decl; | |
11404 | for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) | |
64b59a80 JM |
11405 | if (TREE_CODE (decl) == FUNCTION_DECL |
11406 | || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))) | |
11407 | return 0; | |
11408 | return 1; | |
fcd7f76b JM |
11409 | } |
11410 | ||
a3f97cbb | 11411 | /* Lookup a filename (in the list of filenames that we know about here in |
9a666dda | 11412 | dwarf2out.c) and return its "index". The index of each (known) filename is |
a3f97cbb JW |
11413 | just a unique number which is associated with only that one filename. |
11414 | We need such numbers for the sake of generating labels | |
11415 | (in the .debug_sfnames section) and references to those | |
11416 | files numbers (in the .debug_srcinfo and.debug_macinfo sections). | |
11417 | If the filename given as an argument is not found in our current list, | |
11418 | add it to the list and assign it the next available unique index number. | |
11419 | In order to speed up searches, we remember the index of the filename | |
11420 | was looked up last. This handles the majority of all searches. */ | |
71dfc51f | 11421 | |
a3f97cbb | 11422 | static unsigned |
981975b6 | 11423 | lookup_filename (file_name) |
d560ee52 | 11424 | const char *file_name; |
a3f97cbb | 11425 | { |
a3f97cbb JW |
11426 | register unsigned i; |
11427 | ||
981975b6 RH |
11428 | /* ??? Why isn't DECL_SOURCE_FILE left null instead. */ |
11429 | if (strcmp (file_name, "<internal>") == 0 | |
11430 | || strcmp (file_name, "<built-in>") == 0) | |
11431 | return 0; | |
11432 | ||
2e18bbae RH |
11433 | /* Check to see if the file name that was searched on the previous |
11434 | call matches this file name. If so, return the index. */ | |
981975b6 RH |
11435 | if (file_table.last_lookup_index != 0) |
11436 | if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0) | |
11437 | return file_table.last_lookup_index; | |
a3f97cbb JW |
11438 | |
11439 | /* Didn't match the previous lookup, search the table */ | |
981975b6 RH |
11440 | for (i = 1; i < file_table.in_use; ++i) |
11441 | if (strcmp (file_name, file_table.table[i]) == 0) | |
71dfc51f | 11442 | { |
981975b6 | 11443 | file_table.last_lookup_index = i; |
71dfc51f RK |
11444 | return i; |
11445 | } | |
a3f97cbb | 11446 | |
556273e0 | 11447 | /* Prepare to add a new table entry by making sure there is enough space in |
a3f97cbb | 11448 | the table to do so. If not, expand the current table. */ |
981975b6 | 11449 | if (i == file_table.allocated) |
a3f97cbb | 11450 | { |
981975b6 RH |
11451 | file_table.allocated = i + FILE_TABLE_INCREMENT; |
11452 | file_table.table = (char **) | |
11453 | xrealloc (file_table.table, file_table.allocated * sizeof (char *)); | |
a3f97cbb JW |
11454 | } |
11455 | ||
71dfc51f | 11456 | /* Add the new entry to the end of the filename table. */ |
981975b6 RH |
11457 | file_table.table[i] = xstrdup (file_name); |
11458 | file_table.in_use = i + 1; | |
11459 | file_table.last_lookup_index = i; | |
2e18bbae | 11460 | |
acc187f5 RH |
11461 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
11462 | fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name); | |
11463 | ||
2e18bbae RH |
11464 | return i; |
11465 | } | |
11466 | ||
11467 | static void | |
981975b6 | 11468 | init_file_table () |
2e18bbae RH |
11469 | { |
11470 | /* Allocate the initial hunk of the file_table. */ | |
981975b6 RH |
11471 | file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *)); |
11472 | file_table.allocated = FILE_TABLE_INCREMENT; | |
71dfc51f | 11473 | |
2e18bbae | 11474 | /* Skip the first entry - file numbers begin at 1. */ |
981975b6 RH |
11475 | file_table.in_use = 1; |
11476 | file_table.last_lookup_index = 0; | |
a3f97cbb JW |
11477 | } |
11478 | ||
11479 | /* Output a label to mark the beginning of a source code line entry | |
11480 | and record information relating to this source line, in | |
11481 | 'line_info_table' for later output of the .debug_line section. */ | |
71dfc51f | 11482 | |
e2a12aca | 11483 | static void |
653e276c NB |
11484 | dwarf2out_source_line (line, filename) |
11485 | unsigned int line; | |
d560ee52 | 11486 | register const char *filename; |
a3f97cbb | 11487 | { |
a3f97cbb JW |
11488 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
11489 | { | |
11490 | function_section (current_function_decl); | |
a3f97cbb | 11491 | |
8aaf55ac JM |
11492 | /* If requested, emit something human-readable. */ |
11493 | if (flag_debug_asm) | |
11494 | fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, | |
11495 | filename, line); | |
11496 | ||
b2244e22 JW |
11497 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
11498 | { | |
981975b6 | 11499 | unsigned file_num = lookup_filename (filename); |
b2244e22 | 11500 | |
981975b6 | 11501 | /* Emit the .loc directive understood by GNU as. */ |
2e18bbae | 11502 | fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line); |
b2244e22 JW |
11503 | |
11504 | /* Indicate that line number info exists. */ | |
11505 | ++line_info_table_in_use; | |
11506 | ||
11507 | /* Indicate that multiple line number tables exist. */ | |
11508 | if (DECL_SECTION_NAME (current_function_decl)) | |
11509 | ++separate_line_info_table_in_use; | |
11510 | } | |
11511 | else if (DECL_SECTION_NAME (current_function_decl)) | |
a3f97cbb | 11512 | { |
e90b62db | 11513 | register dw_separate_line_info_ref line_info; |
5c90448c JM |
11514 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL, |
11515 | separate_line_info_table_in_use); | |
e90b62db JM |
11516 | |
11517 | /* expand the line info table if necessary */ | |
11518 | if (separate_line_info_table_in_use | |
11519 | == separate_line_info_table_allocated) | |
11520 | { | |
11521 | separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
11522 | separate_line_info_table | |
71dfc51f RK |
11523 | = (dw_separate_line_info_ref) |
11524 | xrealloc (separate_line_info_table, | |
11525 | separate_line_info_table_allocated | |
11526 | * sizeof (dw_separate_line_info_entry)); | |
e90b62db | 11527 | } |
71dfc51f RK |
11528 | |
11529 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
11530 | line_info |
11531 | = &separate_line_info_table[separate_line_info_table_in_use++]; | |
981975b6 | 11532 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db JM |
11533 | line_info->dw_line_num = line; |
11534 | line_info->function = current_funcdef_number; | |
11535 | } | |
11536 | else | |
11537 | { | |
11538 | register dw_line_info_ref line_info; | |
71dfc51f | 11539 | |
5c90448c JM |
11540 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL, |
11541 | line_info_table_in_use); | |
e90b62db | 11542 | |
71dfc51f | 11543 | /* Expand the line info table if necessary. */ |
e90b62db JM |
11544 | if (line_info_table_in_use == line_info_table_allocated) |
11545 | { | |
11546 | line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
11547 | line_info_table | |
71dfc51f RK |
11548 | = (dw_line_info_ref) |
11549 | xrealloc (line_info_table, | |
11550 | (line_info_table_allocated | |
11551 | * sizeof (dw_line_info_entry))); | |
e90b62db | 11552 | } |
71dfc51f RK |
11553 | |
11554 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db | 11555 | line_info = &line_info_table[line_info_table_in_use++]; |
981975b6 | 11556 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db | 11557 | line_info->dw_line_num = line; |
a3f97cbb | 11558 | } |
a3f97cbb JW |
11559 | } |
11560 | } | |
11561 | ||
cc260610 | 11562 | /* Record the beginning of a new source file. */ |
71dfc51f | 11563 | |
7f905405 | 11564 | static void |
84a5b4f8 | 11565 | dwarf2out_start_source_file (lineno, filename) |
7f905405 NB |
11566 | register unsigned int lineno; |
11567 | register const char *filename; | |
a3f97cbb | 11568 | { |
881c6935 JM |
11569 | if (flag_eliminate_dwarf2_dups) |
11570 | { | |
11571 | /* Record the beginning of the file for break_out_includes. */ | |
11572 | dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die); | |
11573 | add_AT_string (bincl_die, DW_AT_name, filename); | |
11574 | } | |
84a5b4f8 DB |
11575 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11576 | { | |
11577 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION); | |
11578 | dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file"); | |
11579 | dw2_asm_output_data_uleb128 (lineno, "Included from line number %d", lineno); | |
11580 | dw2_asm_output_data_uleb128 (lookup_filename (filename), "Filename we just started"); | |
11581 | } | |
a3f97cbb JW |
11582 | } |
11583 | ||
cc260610 | 11584 | /* Record the end of a source file. */ |
71dfc51f | 11585 | |
7f905405 NB |
11586 | static void |
11587 | dwarf2out_end_source_file (lineno) | |
11588 | unsigned int lineno ATTRIBUTE_UNUSED; | |
a3f97cbb | 11589 | { |
881c6935 JM |
11590 | if (flag_eliminate_dwarf2_dups) |
11591 | { | |
11592 | /* Record the end of the file for break_out_includes. */ | |
11593 | new_die (DW_TAG_GNU_EINCL, comp_unit_die); | |
0b34cf1e | 11594 | } |
84a5b4f8 DB |
11595 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11596 | { | |
11597 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION); | |
11598 | dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); | |
11599 | } | |
a3f97cbb JW |
11600 | } |
11601 | ||
cc260610 | 11602 | /* Called from debug_define in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
11603 | the tail part of the directive line, i.e. the part which is past the |
11604 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 11605 | |
7f905405 | 11606 | static void |
9a666dda | 11607 | dwarf2out_define (lineno, buffer) |
2618f955 | 11608 | register unsigned lineno ATTRIBUTE_UNUSED; |
d560ee52 | 11609 | register const char *buffer ATTRIBUTE_UNUSED; |
a3f97cbb JW |
11610 | { |
11611 | static int initialized = 0; | |
11612 | if (!initialized) | |
11613 | { | |
84a5b4f8 | 11614 | dwarf2out_start_source_file (0, primary_filename); |
a3f97cbb JW |
11615 | initialized = 1; |
11616 | } | |
84a5b4f8 DB |
11617 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11618 | { | |
11619 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION); | |
11620 | dw2_asm_output_data (1, DW_MACINFO_define, "Define macro"); | |
11621 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
11622 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
11623 | } | |
a3f97cbb JW |
11624 | } |
11625 | ||
cc260610 | 11626 | /* Called from debug_undef in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
11627 | the tail part of the directive line, i.e. the part which is past the |
11628 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 11629 | |
7f905405 | 11630 | static void |
9a666dda | 11631 | dwarf2out_undef (lineno, buffer) |
487a6e06 | 11632 | register unsigned lineno ATTRIBUTE_UNUSED; |
d560ee52 | 11633 | register const char *buffer ATTRIBUTE_UNUSED; |
a3f97cbb | 11634 | { |
84a5b4f8 DB |
11635 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11636 | { | |
11637 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION); | |
11638 | dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro"); | |
11639 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
11640 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
11641 | } | |
a3f97cbb JW |
11642 | } |
11643 | ||
11644 | /* Set up for Dwarf output at the start of compilation. */ | |
71dfc51f | 11645 | |
a51d908e | 11646 | static void |
e2a12aca | 11647 | dwarf2out_init (main_input_filename) |
d3e3972c | 11648 | register const char *main_input_filename; |
a3f97cbb | 11649 | { |
acc187f5 RH |
11650 | init_file_table (); |
11651 | ||
a3f97cbb JW |
11652 | /* Remember the name of the primary input file. */ |
11653 | primary_filename = main_input_filename; | |
11654 | ||
acc187f5 RH |
11655 | /* Add it to the file table first, under the assumption that we'll |
11656 | be emitting line number data for it first, which avoids having | |
11657 | to add an initial DW_LNS_set_file. */ | |
11658 | lookup_filename (main_input_filename); | |
a3f97cbb | 11659 | |
a3f97cbb JW |
11660 | /* Allocate the initial hunk of the decl_die_table. */ |
11661 | decl_die_table | |
3de90026 | 11662 | = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref)); |
a3f97cbb JW |
11663 | decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT; |
11664 | decl_die_table_in_use = 0; | |
11665 | ||
11666 | /* Allocate the initial hunk of the decl_scope_table. */ | |
11667 | decl_scope_table | |
777ad4c2 | 11668 | = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree)); |
a3f97cbb JW |
11669 | decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT; |
11670 | decl_scope_depth = 0; | |
11671 | ||
11672 | /* Allocate the initial hunk of the abbrev_die_table. */ | |
11673 | abbrev_die_table | |
3de90026 RH |
11674 | = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT, |
11675 | sizeof (dw_die_ref)); | |
a3f97cbb | 11676 | abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT; |
71dfc51f | 11677 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
11678 | abbrev_die_table_in_use = 1; |
11679 | ||
11680 | /* Allocate the initial hunk of the line_info_table. */ | |
11681 | line_info_table | |
3de90026 RH |
11682 | = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT, |
11683 | sizeof (dw_line_info_entry)); | |
a3f97cbb | 11684 | line_info_table_allocated = LINE_INFO_TABLE_INCREMENT; |
71dfc51f | 11685 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
11686 | line_info_table_in_use = 1; |
11687 | ||
556273e0 | 11688 | /* Generate the initial DIE for the .debug section. Note that the (string) |
a3f97cbb | 11689 | value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE |
556273e0 | 11690 | will (typically) be a relative pathname and that this pathname should be |
a3f97cbb JW |
11691 | taken as being relative to the directory from which the compiler was |
11692 | invoked when the given (base) source file was compiled. */ | |
a96c67ec | 11693 | comp_unit_die = gen_compile_unit_die (main_input_filename); |
a3f97cbb | 11694 | |
1f8f4a0b MM |
11695 | VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray"); |
11696 | ggc_add_rtx_varray_root (&used_rtx_varray, 1); | |
1865dbb5 | 11697 | |
5c90448c | 11698 | ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0); |
9d2f2c45 RH |
11699 | ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, |
11700 | DEBUG_ABBREV_SECTION_LABEL, 0); | |
b366352b MM |
11701 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) |
11702 | ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0); | |
11703 | else | |
11704 | strcpy (text_section_label, stripattributes (TEXT_SECTION)); | |
556273e0 | 11705 | ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label, |
8b790721 | 11706 | DEBUG_INFO_SECTION_LABEL, 0); |
556273e0 | 11707 | ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label, |
8b790721 | 11708 | DEBUG_LINE_SECTION_LABEL, 0); |
9d2f2c45 RH |
11709 | ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL, 0); |
11710 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LOC_SECTION); | |
63e46568 | 11711 | ASM_OUTPUT_LABEL (asm_out_file, loc_section_label); |
9d2f2c45 | 11712 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ABBREV_SECTION); |
8b790721 | 11713 | ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label); |
b366352b | 11714 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) |
a96c67ec JM |
11715 | { |
11716 | ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION); | |
11717 | ASM_OUTPUT_LABEL (asm_out_file, text_section_label); | |
11718 | } | |
8b790721 JM |
11719 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION); |
11720 | ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label); | |
11721 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION); | |
11722 | ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label); | |
84a5b4f8 DB |
11723 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11724 | { | |
11725 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION); | |
11726 | ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label, | |
11727 | DEBUG_MACINFO_SECTION_LABEL, 0); | |
11728 | ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label); | |
11729 | } | |
a3f97cbb JW |
11730 | } |
11731 | ||
11732 | /* Output stuff that dwarf requires at the end of every file, | |
11733 | and generate the DWARF-2 debugging info. */ | |
71dfc51f | 11734 | |
a51d908e | 11735 | static void |
e2a12aca | 11736 | dwarf2out_finish (input_filename) |
a51d908e | 11737 | register const char *input_filename ATTRIBUTE_UNUSED; |
a3f97cbb | 11738 | { |
ef76d03b | 11739 | limbo_die_node *node, *next_node; |
ae0ed63a | 11740 | dw_die_ref die = 0; |
ef76d03b JW |
11741 | |
11742 | /* Traverse the limbo die list, and add parent/child links. The only | |
11743 | dies without parents that should be here are concrete instances of | |
11744 | inline functions, and the comp_unit_die. We can ignore the comp_unit_die. | |
11745 | For concrete instances, we can get the parent die from the abstract | |
11746 | instance. */ | |
11747 | for (node = limbo_die_list; node; node = next_node) | |
11748 | { | |
11749 | next_node = node->next; | |
11750 | die = node->die; | |
11751 | ||
11752 | if (die->die_parent == NULL) | |
11753 | { | |
a96c67ec JM |
11754 | dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin); |
11755 | if (origin) | |
11756 | add_child_die (origin->die_parent, die); | |
ef76d03b | 11757 | else if (die == comp_unit_die) |
a96c67ec | 11758 | ; |
ef76d03b JW |
11759 | else |
11760 | abort (); | |
11761 | } | |
11762 | free (node); | |
11763 | } | |
a96c67ec | 11764 | limbo_die_list = NULL; |
ef76d03b | 11765 | |
8a8c3656 JM |
11766 | /* Walk through the list of incomplete types again, trying once more to |
11767 | emit full debugging info for them. */ | |
11768 | retry_incomplete_types (); | |
11769 | ||
881c6935 JM |
11770 | /* We need to reverse all the dies before break_out_includes, or |
11771 | we'll see the end of an include file before the beginning. */ | |
11772 | reverse_all_dies (comp_unit_die); | |
11773 | ||
11774 | /* Generate separate CUs for each of the include files we've seen. | |
11775 | They will go into limbo_die_list. */ | |
5f632b5e JM |
11776 | if (flag_eliminate_dwarf2_dups) |
11777 | break_out_includes (comp_unit_die); | |
881c6935 JM |
11778 | |
11779 | /* Traverse the DIE's and add add sibling attributes to those DIE's | |
11780 | that have children. */ | |
a3f97cbb | 11781 | add_sibling_attributes (comp_unit_die); |
881c6935 JM |
11782 | for (node = limbo_die_list; node; node = node->next) |
11783 | add_sibling_attributes (node->die); | |
a3f97cbb JW |
11784 | |
11785 | /* Output a terminator label for the .text section. */ | |
a3f97cbb | 11786 | ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION); |
5c90448c | 11787 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0); |
a3f97cbb | 11788 | |
bdb669cb | 11789 | #if 0 |
a3f97cbb | 11790 | /* Output a terminator label for the .data section. */ |
a3f97cbb | 11791 | ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION); |
5c90448c | 11792 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0); |
a3f97cbb JW |
11793 | |
11794 | /* Output a terminator label for the .bss section. */ | |
a3f97cbb | 11795 | ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION); |
5c90448c | 11796 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0); |
bdb669cb | 11797 | #endif |
a3f97cbb | 11798 | |
db3c0315 MM |
11799 | /* Output the source line correspondence table. We must do this |
11800 | even if there is no line information. Otherwise, on an empty | |
11801 | translation unit, we will generate a present, but empty, | |
11802 | .debug_info section. IRIX 6.5 `nm' will then complain when | |
11803 | examining the file. */ | |
11804 | if (! DWARF2_ASM_LINE_DEBUG_INFO) | |
e90b62db | 11805 | { |
db3c0315 MM |
11806 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION); |
11807 | output_line_info (); | |
11808 | } | |
71dfc51f | 11809 | |
db3c0315 MM |
11810 | /* We can only use the low/high_pc attributes if all of the code was |
11811 | in .text. */ | |
11812 | if (separate_line_info_table_in_use == 0) | |
11813 | { | |
11814 | add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label); | |
11815 | add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label); | |
e90b62db | 11816 | } |
a20612aa RH |
11817 | /* And if it wasn't, we need to give .debug_loc and .debug_ranges |
11818 | an appropriate "base address". Use zero so that these addresses | |
11819 | become absolute. */ | |
11820 | else if (have_location_lists || ranges_table_in_use) | |
11821 | add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx); | |
e90b62db | 11822 | |
fe7cd37f RH |
11823 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
11824 | add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list, | |
11825 | debug_line_section_label); | |
db3c0315 | 11826 | |
84a5b4f8 DB |
11827 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11828 | add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label); | |
a96c67ec | 11829 | |
881c6935 JM |
11830 | /* Output all of the compilation units. We put the main one last so that |
11831 | the offsets are available to output_pubnames. */ | |
11832 | for (node = limbo_die_list; node; node = node->next) | |
11833 | output_comp_unit (node->die); | |
11834 | output_comp_unit (comp_unit_die); | |
11835 | ||
a3f97cbb | 11836 | /* Output the abbreviation table. */ |
9d2f2c45 | 11837 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ABBREV_SECTION); |
a3f97cbb JW |
11838 | output_abbrev_section (); |
11839 | ||
d291dd49 JM |
11840 | if (pubname_table_in_use) |
11841 | { | |
11842 | /* Output public names table. */ | |
9d2f2c45 | 11843 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION); |
d291dd49 JM |
11844 | output_pubnames (); |
11845 | } | |
11846 | ||
e689ae67 JM |
11847 | /* We only put functions in the arange table, so don't write it out if |
11848 | we don't have any. */ | |
a3f97cbb JW |
11849 | if (fde_table_in_use) |
11850 | { | |
a3f97cbb | 11851 | /* Output the address range information. */ |
9d2f2c45 | 11852 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ARANGES_SECTION); |
a3f97cbb JW |
11853 | output_aranges (); |
11854 | } | |
a20612aa RH |
11855 | |
11856 | /* Output location list section if necessary. */ | |
63e46568 DB |
11857 | if (have_location_lists) |
11858 | { | |
11859 | /* Output the location lists info. */ | |
9d2f2c45 | 11860 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LOC_SECTION); |
63e46568 DB |
11861 | output_location_lists (die); |
11862 | have_location_lists = 0; | |
11863 | } | |
cc260610 | 11864 | |
a20612aa RH |
11865 | /* Output ranges section if necessary. */ |
11866 | if (ranges_table_in_use) | |
11867 | { | |
11868 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_RANGES_SECTION); | |
11869 | output_ranges (); | |
11870 | } | |
11871 | ||
cc260610 DB |
11872 | /* Have to end the primary source file. */ |
11873 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) | |
11874 | { | |
11875 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION); | |
11876 | dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); | |
11877 | } | |
a3f97cbb | 11878 | } |
9a666dda | 11879 | #endif /* DWARF2_DEBUGGING_INFO */ |