]>
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, | |
2141 | dw_val_class_loc, | |
63e46568 | 2142 | dw_val_class_loc_list, |
3f76745e JM |
2143 | dw_val_class_const, |
2144 | dw_val_class_unsigned_const, | |
2145 | dw_val_class_long_long, | |
2146 | dw_val_class_float, | |
2147 | dw_val_class_flag, | |
2148 | dw_val_class_die_ref, | |
2149 | dw_val_class_fde_ref, | |
2150 | dw_val_class_lbl_id, | |
8b790721 | 2151 | dw_val_class_lbl_offset, |
3f76745e | 2152 | dw_val_class_str |
a3f97cbb | 2153 | } |
3f76745e | 2154 | dw_val_class; |
a3f97cbb | 2155 | |
3f76745e | 2156 | /* Describe a double word constant value. */ |
21217bd0 | 2157 | /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */ |
3f76745e JM |
2158 | |
2159 | typedef struct dw_long_long_struct | |
a3f97cbb | 2160 | { |
3f76745e JM |
2161 | unsigned long hi; |
2162 | unsigned long low; | |
2163 | } | |
2164 | dw_long_long_const; | |
2165 | ||
2166 | /* Describe a floating point constant value. */ | |
2167 | ||
2168 | typedef struct dw_fp_struct | |
2169 | { | |
2170 | long *array; | |
2171 | unsigned length; | |
2172 | } | |
2173 | dw_float_const; | |
2174 | ||
956d6950 | 2175 | /* The dw_val_node describes an attribute's value, as it is |
3f76745e JM |
2176 | represented internally. */ |
2177 | ||
2178 | typedef struct dw_val_struct | |
2179 | { | |
2180 | dw_val_class val_class; | |
2181 | union | |
a3f97cbb | 2182 | { |
1865dbb5 | 2183 | rtx val_addr; |
63e46568 | 2184 | dw_loc_list_ref val_loc_list; |
3f76745e JM |
2185 | dw_loc_descr_ref val_loc; |
2186 | long int val_int; | |
2187 | long unsigned val_unsigned; | |
2188 | dw_long_long_const val_long_long; | |
2189 | dw_float_const val_float; | |
881c6935 JM |
2190 | struct { |
2191 | dw_die_ref die; | |
2192 | int external; | |
2193 | } val_die_ref; | |
3f76745e JM |
2194 | unsigned val_fde_index; |
2195 | char *val_str; | |
2196 | char *val_lbl_id; | |
3f76745e | 2197 | unsigned char val_flag; |
a3f97cbb | 2198 | } |
3f76745e JM |
2199 | v; |
2200 | } | |
2201 | dw_val_node; | |
2202 | ||
2203 | /* Locations in memory are described using a sequence of stack machine | |
2204 | operations. */ | |
2205 | ||
2206 | typedef struct dw_loc_descr_struct | |
2207 | { | |
2208 | dw_loc_descr_ref dw_loc_next; | |
2209 | enum dwarf_location_atom dw_loc_opc; | |
2210 | dw_val_node dw_loc_oprnd1; | |
2211 | dw_val_node dw_loc_oprnd2; | |
d8041cc8 | 2212 | int dw_loc_addr; |
3f76745e JM |
2213 | } |
2214 | dw_loc_descr_node; | |
2215 | ||
63e46568 DB |
2216 | /* Location lists are ranges + location descriptions for that range, |
2217 | so you can track variables that are in different places over | |
2218 | their entire life. */ | |
2219 | typedef struct dw_loc_list_struct | |
2220 | { | |
2221 | dw_loc_list_ref dw_loc_next; | |
2222 | const char *begin; /* Label for begin address of range */ | |
2223 | const char *end; /* Label for end address of range */ | |
2224 | char *ll_symbol; /* Label for beginning of location list. Only on head of list */ | |
2225 | const char *section; /* Section this loclist is relative to */ | |
2226 | dw_loc_descr_ref expr; | |
2227 | } dw_loc_list_node; | |
2228 | ||
7d9d8943 AM |
2229 | static const char *dwarf_stack_op_name PARAMS ((unsigned)); |
2230 | static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom, | |
2231 | unsigned long, | |
2232 | unsigned long)); | |
2233 | static void add_loc_descr PARAMS ((dw_loc_descr_ref *, | |
2234 | dw_loc_descr_ref)); | |
2235 | static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref)); | |
2236 | static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref)); | |
2237 | static void output_loc_operands PARAMS ((dw_loc_descr_ref)); | |
2238 | static void output_loc_sequence PARAMS ((dw_loc_descr_ref)); | |
3f76745e | 2239 | |
7d9d8943 | 2240 | /* Convert a DWARF stack opcode into its string name. */ |
3f76745e | 2241 | |
7d9d8943 AM |
2242 | static const char * |
2243 | dwarf_stack_op_name (op) | |
2244 | register unsigned op; | |
ef76d03b | 2245 | { |
7d9d8943 AM |
2246 | switch (op) |
2247 | { | |
2248 | case DW_OP_addr: | |
2249 | return "DW_OP_addr"; | |
2250 | case DW_OP_deref: | |
2251 | return "DW_OP_deref"; | |
2252 | case DW_OP_const1u: | |
2253 | return "DW_OP_const1u"; | |
2254 | case DW_OP_const1s: | |
2255 | return "DW_OP_const1s"; | |
2256 | case DW_OP_const2u: | |
2257 | return "DW_OP_const2u"; | |
2258 | case DW_OP_const2s: | |
2259 | return "DW_OP_const2s"; | |
2260 | case DW_OP_const4u: | |
2261 | return "DW_OP_const4u"; | |
2262 | case DW_OP_const4s: | |
2263 | return "DW_OP_const4s"; | |
2264 | case DW_OP_const8u: | |
2265 | return "DW_OP_const8u"; | |
2266 | case DW_OP_const8s: | |
2267 | return "DW_OP_const8s"; | |
2268 | case DW_OP_constu: | |
2269 | return "DW_OP_constu"; | |
2270 | case DW_OP_consts: | |
2271 | return "DW_OP_consts"; | |
2272 | case DW_OP_dup: | |
2273 | return "DW_OP_dup"; | |
2274 | case DW_OP_drop: | |
2275 | return "DW_OP_drop"; | |
2276 | case DW_OP_over: | |
2277 | return "DW_OP_over"; | |
2278 | case DW_OP_pick: | |
2279 | return "DW_OP_pick"; | |
2280 | case DW_OP_swap: | |
2281 | return "DW_OP_swap"; | |
2282 | case DW_OP_rot: | |
2283 | return "DW_OP_rot"; | |
2284 | case DW_OP_xderef: | |
2285 | return "DW_OP_xderef"; | |
2286 | case DW_OP_abs: | |
2287 | return "DW_OP_abs"; | |
2288 | case DW_OP_and: | |
2289 | return "DW_OP_and"; | |
2290 | case DW_OP_div: | |
2291 | return "DW_OP_div"; | |
2292 | case DW_OP_minus: | |
2293 | return "DW_OP_minus"; | |
2294 | case DW_OP_mod: | |
2295 | return "DW_OP_mod"; | |
2296 | case DW_OP_mul: | |
2297 | return "DW_OP_mul"; | |
2298 | case DW_OP_neg: | |
2299 | return "DW_OP_neg"; | |
2300 | case DW_OP_not: | |
2301 | return "DW_OP_not"; | |
2302 | case DW_OP_or: | |
2303 | return "DW_OP_or"; | |
2304 | case DW_OP_plus: | |
2305 | return "DW_OP_plus"; | |
2306 | case DW_OP_plus_uconst: | |
2307 | return "DW_OP_plus_uconst"; | |
2308 | case DW_OP_shl: | |
2309 | return "DW_OP_shl"; | |
2310 | case DW_OP_shr: | |
2311 | return "DW_OP_shr"; | |
2312 | case DW_OP_shra: | |
2313 | return "DW_OP_shra"; | |
2314 | case DW_OP_xor: | |
2315 | return "DW_OP_xor"; | |
2316 | case DW_OP_bra: | |
2317 | return "DW_OP_bra"; | |
2318 | case DW_OP_eq: | |
2319 | return "DW_OP_eq"; | |
2320 | case DW_OP_ge: | |
2321 | return "DW_OP_ge"; | |
2322 | case DW_OP_gt: | |
2323 | return "DW_OP_gt"; | |
2324 | case DW_OP_le: | |
2325 | return "DW_OP_le"; | |
2326 | case DW_OP_lt: | |
2327 | return "DW_OP_lt"; | |
2328 | case DW_OP_ne: | |
2329 | return "DW_OP_ne"; | |
2330 | case DW_OP_skip: | |
2331 | return "DW_OP_skip"; | |
2332 | case DW_OP_lit0: | |
2333 | return "DW_OP_lit0"; | |
2334 | case DW_OP_lit1: | |
2335 | return "DW_OP_lit1"; | |
2336 | case DW_OP_lit2: | |
2337 | return "DW_OP_lit2"; | |
2338 | case DW_OP_lit3: | |
2339 | return "DW_OP_lit3"; | |
2340 | case DW_OP_lit4: | |
2341 | return "DW_OP_lit4"; | |
2342 | case DW_OP_lit5: | |
2343 | return "DW_OP_lit5"; | |
2344 | case DW_OP_lit6: | |
2345 | return "DW_OP_lit6"; | |
2346 | case DW_OP_lit7: | |
2347 | return "DW_OP_lit7"; | |
2348 | case DW_OP_lit8: | |
2349 | return "DW_OP_lit8"; | |
2350 | case DW_OP_lit9: | |
2351 | return "DW_OP_lit9"; | |
2352 | case DW_OP_lit10: | |
2353 | return "DW_OP_lit10"; | |
2354 | case DW_OP_lit11: | |
2355 | return "DW_OP_lit11"; | |
2356 | case DW_OP_lit12: | |
2357 | return "DW_OP_lit12"; | |
2358 | case DW_OP_lit13: | |
2359 | return "DW_OP_lit13"; | |
2360 | case DW_OP_lit14: | |
2361 | return "DW_OP_lit14"; | |
2362 | case DW_OP_lit15: | |
2363 | return "DW_OP_lit15"; | |
2364 | case DW_OP_lit16: | |
2365 | return "DW_OP_lit16"; | |
2366 | case DW_OP_lit17: | |
2367 | return "DW_OP_lit17"; | |
2368 | case DW_OP_lit18: | |
2369 | return "DW_OP_lit18"; | |
2370 | case DW_OP_lit19: | |
2371 | return "DW_OP_lit19"; | |
2372 | case DW_OP_lit20: | |
2373 | return "DW_OP_lit20"; | |
2374 | case DW_OP_lit21: | |
2375 | return "DW_OP_lit21"; | |
2376 | case DW_OP_lit22: | |
2377 | return "DW_OP_lit22"; | |
2378 | case DW_OP_lit23: | |
2379 | return "DW_OP_lit23"; | |
2380 | case DW_OP_lit24: | |
2381 | return "DW_OP_lit24"; | |
2382 | case DW_OP_lit25: | |
2383 | return "DW_OP_lit25"; | |
2384 | case DW_OP_lit26: | |
2385 | return "DW_OP_lit26"; | |
2386 | case DW_OP_lit27: | |
2387 | return "DW_OP_lit27"; | |
2388 | case DW_OP_lit28: | |
2389 | return "DW_OP_lit28"; | |
2390 | case DW_OP_lit29: | |
2391 | return "DW_OP_lit29"; | |
2392 | case DW_OP_lit30: | |
2393 | return "DW_OP_lit30"; | |
2394 | case DW_OP_lit31: | |
2395 | return "DW_OP_lit31"; | |
2396 | case DW_OP_reg0: | |
2397 | return "DW_OP_reg0"; | |
2398 | case DW_OP_reg1: | |
2399 | return "DW_OP_reg1"; | |
2400 | case DW_OP_reg2: | |
2401 | return "DW_OP_reg2"; | |
2402 | case DW_OP_reg3: | |
2403 | return "DW_OP_reg3"; | |
2404 | case DW_OP_reg4: | |
2405 | return "DW_OP_reg4"; | |
2406 | case DW_OP_reg5: | |
2407 | return "DW_OP_reg5"; | |
2408 | case DW_OP_reg6: | |
2409 | return "DW_OP_reg6"; | |
2410 | case DW_OP_reg7: | |
2411 | return "DW_OP_reg7"; | |
2412 | case DW_OP_reg8: | |
2413 | return "DW_OP_reg8"; | |
2414 | case DW_OP_reg9: | |
2415 | return "DW_OP_reg9"; | |
2416 | case DW_OP_reg10: | |
2417 | return "DW_OP_reg10"; | |
2418 | case DW_OP_reg11: | |
2419 | return "DW_OP_reg11"; | |
2420 | case DW_OP_reg12: | |
2421 | return "DW_OP_reg12"; | |
2422 | case DW_OP_reg13: | |
2423 | return "DW_OP_reg13"; | |
2424 | case DW_OP_reg14: | |
2425 | return "DW_OP_reg14"; | |
2426 | case DW_OP_reg15: | |
2427 | return "DW_OP_reg15"; | |
2428 | case DW_OP_reg16: | |
2429 | return "DW_OP_reg16"; | |
2430 | case DW_OP_reg17: | |
2431 | return "DW_OP_reg17"; | |
2432 | case DW_OP_reg18: | |
2433 | return "DW_OP_reg18"; | |
2434 | case DW_OP_reg19: | |
2435 | return "DW_OP_reg19"; | |
2436 | case DW_OP_reg20: | |
2437 | return "DW_OP_reg20"; | |
2438 | case DW_OP_reg21: | |
2439 | return "DW_OP_reg21"; | |
2440 | case DW_OP_reg22: | |
2441 | return "DW_OP_reg22"; | |
2442 | case DW_OP_reg23: | |
2443 | return "DW_OP_reg23"; | |
2444 | case DW_OP_reg24: | |
2445 | return "DW_OP_reg24"; | |
2446 | case DW_OP_reg25: | |
2447 | return "DW_OP_reg25"; | |
2448 | case DW_OP_reg26: | |
2449 | return "DW_OP_reg26"; | |
2450 | case DW_OP_reg27: | |
2451 | return "DW_OP_reg27"; | |
2452 | case DW_OP_reg28: | |
2453 | return "DW_OP_reg28"; | |
2454 | case DW_OP_reg29: | |
2455 | return "DW_OP_reg29"; | |
2456 | case DW_OP_reg30: | |
2457 | return "DW_OP_reg30"; | |
2458 | case DW_OP_reg31: | |
2459 | return "DW_OP_reg31"; | |
2460 | case DW_OP_breg0: | |
2461 | return "DW_OP_breg0"; | |
2462 | case DW_OP_breg1: | |
2463 | return "DW_OP_breg1"; | |
2464 | case DW_OP_breg2: | |
2465 | return "DW_OP_breg2"; | |
2466 | case DW_OP_breg3: | |
2467 | return "DW_OP_breg3"; | |
2468 | case DW_OP_breg4: | |
2469 | return "DW_OP_breg4"; | |
2470 | case DW_OP_breg5: | |
2471 | return "DW_OP_breg5"; | |
2472 | case DW_OP_breg6: | |
2473 | return "DW_OP_breg6"; | |
2474 | case DW_OP_breg7: | |
2475 | return "DW_OP_breg7"; | |
2476 | case DW_OP_breg8: | |
2477 | return "DW_OP_breg8"; | |
2478 | case DW_OP_breg9: | |
2479 | return "DW_OP_breg9"; | |
2480 | case DW_OP_breg10: | |
2481 | return "DW_OP_breg10"; | |
2482 | case DW_OP_breg11: | |
2483 | return "DW_OP_breg11"; | |
2484 | case DW_OP_breg12: | |
2485 | return "DW_OP_breg12"; | |
2486 | case DW_OP_breg13: | |
2487 | return "DW_OP_breg13"; | |
2488 | case DW_OP_breg14: | |
2489 | return "DW_OP_breg14"; | |
2490 | case DW_OP_breg15: | |
2491 | return "DW_OP_breg15"; | |
2492 | case DW_OP_breg16: | |
2493 | return "DW_OP_breg16"; | |
2494 | case DW_OP_breg17: | |
2495 | return "DW_OP_breg17"; | |
2496 | case DW_OP_breg18: | |
2497 | return "DW_OP_breg18"; | |
2498 | case DW_OP_breg19: | |
2499 | return "DW_OP_breg19"; | |
2500 | case DW_OP_breg20: | |
2501 | return "DW_OP_breg20"; | |
2502 | case DW_OP_breg21: | |
2503 | return "DW_OP_breg21"; | |
2504 | case DW_OP_breg22: | |
2505 | return "DW_OP_breg22"; | |
2506 | case DW_OP_breg23: | |
2507 | return "DW_OP_breg23"; | |
2508 | case DW_OP_breg24: | |
2509 | return "DW_OP_breg24"; | |
2510 | case DW_OP_breg25: | |
2511 | return "DW_OP_breg25"; | |
2512 | case DW_OP_breg26: | |
2513 | return "DW_OP_breg26"; | |
2514 | case DW_OP_breg27: | |
2515 | return "DW_OP_breg27"; | |
2516 | case DW_OP_breg28: | |
2517 | return "DW_OP_breg28"; | |
2518 | case DW_OP_breg29: | |
2519 | return "DW_OP_breg29"; | |
2520 | case DW_OP_breg30: | |
2521 | return "DW_OP_breg30"; | |
2522 | case DW_OP_breg31: | |
2523 | return "DW_OP_breg31"; | |
2524 | case DW_OP_regx: | |
2525 | return "DW_OP_regx"; | |
2526 | case DW_OP_fbreg: | |
2527 | return "DW_OP_fbreg"; | |
2528 | case DW_OP_bregx: | |
2529 | return "DW_OP_bregx"; | |
2530 | case DW_OP_piece: | |
2531 | return "DW_OP_piece"; | |
2532 | case DW_OP_deref_size: | |
2533 | return "DW_OP_deref_size"; | |
2534 | case DW_OP_xderef_size: | |
2535 | return "DW_OP_xderef_size"; | |
2536 | case DW_OP_nop: | |
2537 | return "DW_OP_nop"; | |
3f76745e | 2538 | default: |
7d9d8943 | 2539 | return "OP_<unknown>"; |
3f76745e | 2540 | } |
bdb669cb | 2541 | } |
a3f97cbb | 2542 | |
7d9d8943 AM |
2543 | /* Return a pointer to a newly allocated location description. Location |
2544 | descriptions are simple expression terms that can be strung | |
2545 | together to form more complicated location (address) descriptions. */ | |
2546 | ||
2547 | static inline dw_loc_descr_ref | |
2548 | new_loc_descr (op, oprnd1, oprnd2) | |
2549 | register enum dwarf_location_atom op; | |
2550 | register unsigned long oprnd1; | |
2551 | register unsigned long oprnd2; | |
4b674448 | 2552 | { |
5de0e8d4 JM |
2553 | /* Use xcalloc here so we clear out all of the long_long constant in |
2554 | the union. */ | |
7d9d8943 | 2555 | register dw_loc_descr_ref descr |
5de0e8d4 | 2556 | = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node)); |
71dfc51f | 2557 | |
7d9d8943 AM |
2558 | descr->dw_loc_opc = op; |
2559 | descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const; | |
2560 | descr->dw_loc_oprnd1.v.val_unsigned = oprnd1; | |
2561 | descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const; | |
2562 | descr->dw_loc_oprnd2.v.val_unsigned = oprnd2; | |
71dfc51f | 2563 | |
7d9d8943 AM |
2564 | return descr; |
2565 | } | |
2566 | ||
63e46568 | 2567 | |
7d9d8943 AM |
2568 | /* Add a location description term to a location description expression. */ |
2569 | ||
2570 | static inline void | |
2571 | add_loc_descr (list_head, descr) | |
2572 | register dw_loc_descr_ref *list_head; | |
2573 | register dw_loc_descr_ref descr; | |
2574 | { | |
2575 | register dw_loc_descr_ref *d; | |
2576 | ||
2577 | /* Find the end of the chain. */ | |
2578 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
2579 | ; | |
2580 | ||
2581 | *d = descr; | |
2582 | } | |
2583 | ||
2584 | /* Return the size of a location descriptor. */ | |
2585 | ||
2586 | static unsigned long | |
2587 | size_of_loc_descr (loc) | |
2588 | register dw_loc_descr_ref loc; | |
2589 | { | |
2590 | register unsigned long size = 1; | |
2591 | ||
2592 | switch (loc->dw_loc_opc) | |
2593 | { | |
2594 | case DW_OP_addr: | |
2595 | size += DWARF2_ADDR_SIZE; | |
2596 | break; | |
2597 | case DW_OP_const1u: | |
2598 | case DW_OP_const1s: | |
2599 | size += 1; | |
2600 | break; | |
2601 | case DW_OP_const2u: | |
2602 | case DW_OP_const2s: | |
2603 | size += 2; | |
2604 | break; | |
2605 | case DW_OP_const4u: | |
2606 | case DW_OP_const4s: | |
2607 | size += 4; | |
2608 | break; | |
2609 | case DW_OP_const8u: | |
2610 | case DW_OP_const8s: | |
2611 | size += 8; | |
2612 | break; | |
2613 | case DW_OP_constu: | |
2614 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2615 | break; | |
2616 | case DW_OP_consts: | |
2617 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2618 | break; | |
2619 | case DW_OP_pick: | |
2620 | size += 1; | |
2621 | break; | |
2622 | case DW_OP_plus_uconst: | |
2623 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2624 | break; | |
2625 | case DW_OP_skip: | |
2626 | case DW_OP_bra: | |
2627 | size += 2; | |
2628 | break; | |
2629 | case DW_OP_breg0: | |
2630 | case DW_OP_breg1: | |
2631 | case DW_OP_breg2: | |
2632 | case DW_OP_breg3: | |
2633 | case DW_OP_breg4: | |
2634 | case DW_OP_breg5: | |
2635 | case DW_OP_breg6: | |
2636 | case DW_OP_breg7: | |
2637 | case DW_OP_breg8: | |
2638 | case DW_OP_breg9: | |
2639 | case DW_OP_breg10: | |
2640 | case DW_OP_breg11: | |
2641 | case DW_OP_breg12: | |
2642 | case DW_OP_breg13: | |
2643 | case DW_OP_breg14: | |
2644 | case DW_OP_breg15: | |
2645 | case DW_OP_breg16: | |
2646 | case DW_OP_breg17: | |
2647 | case DW_OP_breg18: | |
2648 | case DW_OP_breg19: | |
2649 | case DW_OP_breg20: | |
2650 | case DW_OP_breg21: | |
2651 | case DW_OP_breg22: | |
2652 | case DW_OP_breg23: | |
2653 | case DW_OP_breg24: | |
2654 | case DW_OP_breg25: | |
2655 | case DW_OP_breg26: | |
2656 | case DW_OP_breg27: | |
2657 | case DW_OP_breg28: | |
2658 | case DW_OP_breg29: | |
2659 | case DW_OP_breg30: | |
2660 | case DW_OP_breg31: | |
2661 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2662 | break; | |
2663 | case DW_OP_regx: | |
2664 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2665 | break; | |
2666 | case DW_OP_fbreg: | |
2667 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); | |
2668 | break; | |
2669 | case DW_OP_bregx: | |
2670 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2671 | size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int); | |
2672 | break; | |
2673 | case DW_OP_piece: | |
2674 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); | |
2675 | break; | |
2676 | case DW_OP_deref_size: | |
2677 | case DW_OP_xderef_size: | |
2678 | size += 1; | |
2679 | break; | |
3f76745e | 2680 | default: |
7d9d8943 | 2681 | break; |
4b674448 | 2682 | } |
7d9d8943 AM |
2683 | |
2684 | return size; | |
4b674448 JM |
2685 | } |
2686 | ||
7d9d8943 | 2687 | /* Return the size of a series of location descriptors. */ |
71dfc51f | 2688 | |
7d9d8943 AM |
2689 | static unsigned long |
2690 | size_of_locs (loc) | |
2691 | register dw_loc_descr_ref loc; | |
4b674448 | 2692 | { |
7d9d8943 AM |
2693 | register unsigned long size = 0; |
2694 | ||
2695 | for (; loc != NULL; loc = loc->dw_loc_next) | |
d8041cc8 RH |
2696 | { |
2697 | loc->dw_loc_addr = size; | |
2698 | size += size_of_loc_descr (loc); | |
2699 | } | |
7d9d8943 AM |
2700 | |
2701 | return size; | |
4b674448 JM |
2702 | } |
2703 | ||
7d9d8943 | 2704 | /* Output location description stack opcode's operands (if any). */ |
71dfc51f | 2705 | |
7d9d8943 AM |
2706 | static void |
2707 | output_loc_operands (loc) | |
2708 | register dw_loc_descr_ref loc; | |
a3f97cbb | 2709 | { |
7d9d8943 AM |
2710 | register dw_val_ref val1 = &loc->dw_loc_oprnd1; |
2711 | register dw_val_ref val2 = &loc->dw_loc_oprnd2; | |
2712 | ||
2713 | switch (loc->dw_loc_opc) | |
a3f97cbb | 2714 | { |
0517872a | 2715 | #ifdef DWARF2_DEBUGGING_INFO |
3f76745e | 2716 | case DW_OP_addr: |
2e4b9b8c | 2717 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL); |
7d9d8943 | 2718 | break; |
3f76745e | 2719 | case DW_OP_const2u: |
3f76745e | 2720 | case DW_OP_const2s: |
2e4b9b8c | 2721 | dw2_asm_output_data (2, val1->v.val_int, NULL); |
7d9d8943 | 2722 | break; |
3f76745e | 2723 | case DW_OP_const4u: |
3f76745e | 2724 | case DW_OP_const4s: |
2e4b9b8c | 2725 | dw2_asm_output_data (4, val1->v.val_int, NULL); |
7d9d8943 | 2726 | break; |
3f76745e | 2727 | case DW_OP_const8u: |
3f76745e | 2728 | case DW_OP_const8s: |
2e4b9b8c RH |
2729 | if (HOST_BITS_PER_LONG < 64) |
2730 | abort (); | |
2731 | dw2_asm_output_data (8, val1->v.val_int, NULL); | |
7d9d8943 | 2732 | break; |
0517872a JM |
2733 | case DW_OP_skip: |
2734 | case DW_OP_bra: | |
d8041cc8 RH |
2735 | { |
2736 | int offset; | |
2737 | ||
2738 | if (val1->val_class == dw_val_class_loc) | |
2739 | offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3); | |
2740 | else | |
2741 | abort (); | |
2742 | ||
2e4b9b8c | 2743 | dw2_asm_output_data (2, offset, NULL); |
d8041cc8 | 2744 | } |
0517872a | 2745 | break; |
3139472f JM |
2746 | #else |
2747 | case DW_OP_addr: | |
2748 | case DW_OP_const2u: | |
2749 | case DW_OP_const2s: | |
2750 | case DW_OP_const4u: | |
2751 | case DW_OP_const4s: | |
2752 | case DW_OP_const8u: | |
2753 | case DW_OP_const8s: | |
2754 | case DW_OP_skip: | |
2755 | case DW_OP_bra: | |
2756 | /* We currently don't make any attempt to make sure these are | |
2757 | aligned properly like we do for the main unwind info, so | |
2758 | don't support emitting things larger than a byte if we're | |
2759 | only doing unwinding. */ | |
2760 | abort (); | |
0517872a JM |
2761 | #endif |
2762 | case DW_OP_const1u: | |
2763 | case DW_OP_const1s: | |
2e4b9b8c | 2764 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
0517872a | 2765 | break; |
3f76745e | 2766 | case DW_OP_constu: |
2e4b9b8c | 2767 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2768 | break; |
3f76745e | 2769 | case DW_OP_consts: |
2e4b9b8c | 2770 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 AM |
2771 | break; |
2772 | case DW_OP_pick: | |
2e4b9b8c | 2773 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 AM |
2774 | break; |
2775 | case DW_OP_plus_uconst: | |
2e4b9b8c | 2776 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2777 | break; |
3f76745e | 2778 | case DW_OP_breg0: |
3f76745e | 2779 | case DW_OP_breg1: |
3f76745e | 2780 | case DW_OP_breg2: |
3f76745e | 2781 | case DW_OP_breg3: |
3f76745e | 2782 | case DW_OP_breg4: |
3f76745e | 2783 | case DW_OP_breg5: |
3f76745e | 2784 | case DW_OP_breg6: |
3f76745e | 2785 | case DW_OP_breg7: |
3f76745e | 2786 | case DW_OP_breg8: |
3f76745e | 2787 | case DW_OP_breg9: |
3f76745e | 2788 | case DW_OP_breg10: |
3f76745e | 2789 | case DW_OP_breg11: |
3f76745e | 2790 | case DW_OP_breg12: |
3f76745e | 2791 | case DW_OP_breg13: |
3f76745e | 2792 | case DW_OP_breg14: |
3f76745e | 2793 | case DW_OP_breg15: |
3f76745e | 2794 | case DW_OP_breg16: |
3f76745e | 2795 | case DW_OP_breg17: |
3f76745e | 2796 | case DW_OP_breg18: |
3f76745e | 2797 | case DW_OP_breg19: |
3f76745e | 2798 | case DW_OP_breg20: |
3f76745e | 2799 | case DW_OP_breg21: |
3f76745e | 2800 | case DW_OP_breg22: |
3f76745e | 2801 | case DW_OP_breg23: |
3f76745e | 2802 | case DW_OP_breg24: |
3f76745e | 2803 | case DW_OP_breg25: |
3f76745e | 2804 | case DW_OP_breg26: |
3f76745e | 2805 | case DW_OP_breg27: |
3f76745e | 2806 | case DW_OP_breg28: |
3f76745e | 2807 | case DW_OP_breg29: |
3f76745e | 2808 | case DW_OP_breg30: |
3f76745e | 2809 | case DW_OP_breg31: |
2e4b9b8c | 2810 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 2811 | break; |
3f76745e | 2812 | case DW_OP_regx: |
2e4b9b8c | 2813 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2814 | break; |
3f76745e | 2815 | case DW_OP_fbreg: |
2e4b9b8c | 2816 | dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); |
7d9d8943 | 2817 | break; |
3f76745e | 2818 | case DW_OP_bregx: |
2e4b9b8c RH |
2819 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
2820 | dw2_asm_output_data_sleb128 (val2->v.val_int, NULL); | |
7d9d8943 | 2821 | break; |
3f76745e | 2822 | case DW_OP_piece: |
2e4b9b8c | 2823 | dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); |
7d9d8943 | 2824 | break; |
3f76745e | 2825 | case DW_OP_deref_size: |
3f76745e | 2826 | case DW_OP_xderef_size: |
2e4b9b8c | 2827 | dw2_asm_output_data (1, val1->v.val_int, NULL); |
7d9d8943 AM |
2828 | break; |
2829 | default: | |
3139472f JM |
2830 | /* Other codes have no operands. */ |
2831 | break; | |
7d9d8943 AM |
2832 | } |
2833 | } | |
2834 | ||
2835 | /* Output a sequence of location operations. */ | |
2836 | ||
2837 | static void | |
2838 | output_loc_sequence (loc) | |
2839 | dw_loc_descr_ref loc; | |
2840 | { | |
2841 | for (; loc != NULL; loc = loc->dw_loc_next) | |
2842 | { | |
2843 | /* Output the opcode. */ | |
2e4b9b8c RH |
2844 | dw2_asm_output_data (1, loc->dw_loc_opc, |
2845 | "%s", dwarf_stack_op_name (loc->dw_loc_opc)); | |
7d9d8943 AM |
2846 | |
2847 | /* Output the operand(s) (if any). */ | |
2848 | output_loc_operands (loc); | |
2849 | } | |
2850 | } | |
2851 | ||
2852 | /* This routine will generate the correct assembly data for a location | |
2853 | description based on a cfi entry with a complex address. */ | |
2854 | ||
2855 | static void | |
2856 | output_cfa_loc (cfi) | |
2857 | dw_cfi_ref cfi; | |
2858 | { | |
2859 | dw_loc_descr_ref loc; | |
2860 | unsigned long size; | |
2861 | ||
2862 | /* Output the size of the block. */ | |
2863 | loc = cfi->dw_cfi_oprnd1.dw_cfi_loc; | |
2864 | size = size_of_locs (loc); | |
2e4b9b8c | 2865 | dw2_asm_output_data_uleb128 (size, NULL); |
7d9d8943 AM |
2866 | |
2867 | /* Now output the operations themselves. */ | |
2868 | output_loc_sequence (loc); | |
2869 | } | |
2870 | ||
556273e0 KH |
2871 | /* This function builds a dwarf location descriptor seqeunce from |
2872 | a dw_cfa_location. */ | |
7d9d8943 AM |
2873 | |
2874 | static struct dw_loc_descr_struct * | |
2875 | build_cfa_loc (cfa) | |
2876 | dw_cfa_location *cfa; | |
2877 | { | |
2878 | struct dw_loc_descr_struct *head, *tmp; | |
2879 | ||
2880 | if (cfa->indirect == 0) | |
2881 | abort (); | |
2882 | ||
2883 | if (cfa->base_offset) | |
f299afab HPN |
2884 | { |
2885 | if (cfa->reg <= 31) | |
2886 | head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0); | |
2887 | else | |
2888 | head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset); | |
2889 | } | |
2890 | else if (cfa->reg <= 31) | |
7d9d8943 | 2891 | head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0); |
f299afab HPN |
2892 | else |
2893 | head = new_loc_descr (DW_OP_regx, cfa->reg, 0); | |
7d9d8943 AM |
2894 | head->dw_loc_oprnd1.val_class = dw_val_class_const; |
2895 | tmp = new_loc_descr (DW_OP_deref, 0, 0); | |
2896 | add_loc_descr (&head, tmp); | |
2897 | if (cfa->offset != 0) | |
2898 | { | |
2899 | tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0); | |
2900 | add_loc_descr (&head, tmp); | |
2901 | } | |
2902 | return head; | |
2903 | } | |
2904 | ||
556273e0 | 2905 | /* This function fills in aa dw_cfa_location structure from a |
7d9d8943 AM |
2906 | dwarf location descriptor sequence. */ |
2907 | ||
2908 | static void | |
2909 | get_cfa_from_loc_descr (cfa, loc) | |
2910 | dw_cfa_location *cfa; | |
556273e0 | 2911 | struct dw_loc_descr_struct *loc; |
7d9d8943 | 2912 | { |
556273e0 | 2913 | struct dw_loc_descr_struct *ptr; |
7d9d8943 AM |
2914 | cfa->offset = 0; |
2915 | cfa->base_offset = 0; | |
2916 | cfa->indirect = 0; | |
2917 | cfa->reg = -1; | |
2918 | ||
2919 | for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next) | |
2920 | { | |
2921 | enum dwarf_location_atom op = ptr->dw_loc_opc; | |
2922 | switch (op) | |
556273e0 | 2923 | { |
7d9d8943 AM |
2924 | case DW_OP_reg0: |
2925 | case DW_OP_reg1: | |
2926 | case DW_OP_reg2: | |
2927 | case DW_OP_reg3: | |
2928 | case DW_OP_reg4: | |
2929 | case DW_OP_reg5: | |
2930 | case DW_OP_reg6: | |
2931 | case DW_OP_reg7: | |
2932 | case DW_OP_reg8: | |
2933 | case DW_OP_reg9: | |
2934 | case DW_OP_reg10: | |
2935 | case DW_OP_reg11: | |
2936 | case DW_OP_reg12: | |
2937 | case DW_OP_reg13: | |
2938 | case DW_OP_reg14: | |
2939 | case DW_OP_reg15: | |
2940 | case DW_OP_reg16: | |
2941 | case DW_OP_reg17: | |
2942 | case DW_OP_reg18: | |
2943 | case DW_OP_reg19: | |
2944 | case DW_OP_reg20: | |
2945 | case DW_OP_reg21: | |
2946 | case DW_OP_reg22: | |
2947 | case DW_OP_reg23: | |
2948 | case DW_OP_reg24: | |
2949 | case DW_OP_reg25: | |
2950 | case DW_OP_reg26: | |
2951 | case DW_OP_reg27: | |
2952 | case DW_OP_reg28: | |
2953 | case DW_OP_reg29: | |
2954 | case DW_OP_reg30: | |
2955 | case DW_OP_reg31: | |
2956 | cfa->reg = op - DW_OP_reg0; | |
2957 | break; | |
2958 | case DW_OP_regx: | |
2959 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
2960 | break; | |
2961 | case DW_OP_breg0: | |
2962 | case DW_OP_breg1: | |
2963 | case DW_OP_breg2: | |
2964 | case DW_OP_breg3: | |
2965 | case DW_OP_breg4: | |
2966 | case DW_OP_breg5: | |
2967 | case DW_OP_breg6: | |
2968 | case DW_OP_breg7: | |
2969 | case DW_OP_breg8: | |
2970 | case DW_OP_breg9: | |
2971 | case DW_OP_breg10: | |
2972 | case DW_OP_breg11: | |
2973 | case DW_OP_breg12: | |
2974 | case DW_OP_breg13: | |
2975 | case DW_OP_breg14: | |
2976 | case DW_OP_breg15: | |
2977 | case DW_OP_breg16: | |
2978 | case DW_OP_breg17: | |
2979 | case DW_OP_breg18: | |
2980 | case DW_OP_breg19: | |
2981 | case DW_OP_breg20: | |
2982 | case DW_OP_breg21: | |
2983 | case DW_OP_breg22: | |
2984 | case DW_OP_breg23: | |
2985 | case DW_OP_breg24: | |
2986 | case DW_OP_breg25: | |
2987 | case DW_OP_breg26: | |
2988 | case DW_OP_breg27: | |
2989 | case DW_OP_breg28: | |
2990 | case DW_OP_breg29: | |
2991 | case DW_OP_breg30: | |
2992 | case DW_OP_breg31: | |
2993 | cfa->reg = op - DW_OP_breg0; | |
2994 | cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int; | |
2995 | break; | |
2996 | case DW_OP_bregx: | |
2997 | cfa->reg = ptr->dw_loc_oprnd1.v.val_int; | |
2998 | cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int; | |
2999 | break; | |
3000 | case DW_OP_deref: | |
3001 | cfa->indirect = 1; | |
3002 | break; | |
3003 | case DW_OP_plus_uconst: | |
556273e0 | 3004 | cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned; |
7d9d8943 AM |
3005 | break; |
3006 | default: | |
400500c4 RK |
3007 | internal_error ("DW_LOC_OP %s not implememnted\n", |
3008 | dwarf_stack_op_name (ptr->dw_loc_opc)); | |
7d9d8943 AM |
3009 | } |
3010 | } | |
3011 | } | |
3012 | #endif /* .debug_frame support */ | |
3013 | \f | |
3014 | /* And now, the support for symbolic debugging information. */ | |
3015 | #ifdef DWARF2_DEBUGGING_INFO | |
3016 | ||
e2a12aca NB |
3017 | static void dwarf2out_init PARAMS ((const char *)); |
3018 | static void dwarf2out_finish PARAMS ((const char *)); | |
7f905405 NB |
3019 | static void dwarf2out_define PARAMS ((unsigned int, const char *)); |
3020 | static void dwarf2out_undef PARAMS ((unsigned int, const char *)); | |
3021 | static void dwarf2out_start_source_file PARAMS ((unsigned, const char *)); | |
3022 | static void dwarf2out_end_source_file PARAMS ((unsigned)); | |
e2a12aca NB |
3023 | static void dwarf2out_begin_block PARAMS ((unsigned, unsigned)); |
3024 | static void dwarf2out_end_block PARAMS ((unsigned, unsigned)); | |
e1772ac0 | 3025 | static bool dwarf2out_ignore_block PARAMS ((tree)); |
2b85879e | 3026 | static void dwarf2out_global_decl PARAMS ((tree)); |
e1772ac0 | 3027 | static void dwarf2out_abstract_function PARAMS ((tree)); |
7f905405 NB |
3028 | |
3029 | /* The debug hooks structure. */ | |
3030 | ||
3031 | struct gcc_debug_hooks dwarf2_debug_hooks = | |
3032 | { | |
3033 | dwarf2out_init, | |
3034 | dwarf2out_finish, | |
3035 | dwarf2out_define, | |
3036 | dwarf2out_undef, | |
3037 | dwarf2out_start_source_file, | |
a5a42b92 NB |
3038 | dwarf2out_end_source_file, |
3039 | dwarf2out_begin_block, | |
e2a12aca | 3040 | dwarf2out_end_block, |
e1772ac0 | 3041 | dwarf2out_ignore_block, |
e2a12aca | 3042 | dwarf2out_source_line, |
653e276c NB |
3043 | dwarf2out_begin_prologue, |
3044 | debug_nothing_int, /* end_prologue */ | |
e2a12aca | 3045 | dwarf2out_end_epilogue, |
653e276c | 3046 | debug_nothing_tree, /* begin_function */ |
2b85879e NB |
3047 | debug_nothing_int, /* end_function */ |
3048 | dwarf2out_decl, /* function_decl */ | |
3049 | dwarf2out_global_decl, | |
e1772ac0 NB |
3050 | debug_nothing_tree, /* deferred_inline_function */ |
3051 | /* The DWARF 2 backend tries to reduce debugging bloat by not | |
3052 | emitting the abstract description of inline functions until | |
3053 | something tries to reference them. */ | |
3054 | dwarf2out_abstract_function, /* outlining_inline_function */ | |
3055 | debug_nothing_rtx /* label */ | |
7f905405 NB |
3056 | }; |
3057 | \f | |
7d9d8943 AM |
3058 | /* NOTE: In the comments in this file, many references are made to |
3059 | "Debugging Information Entries". This term is abbreviated as `DIE' | |
3060 | throughout the remainder of this file. */ | |
3061 | ||
3062 | /* An internal representation of the DWARF output is built, and then | |
3063 | walked to generate the DWARF debugging info. The walk of the internal | |
3064 | representation is done after the entire program has been compiled. | |
3065 | The types below are used to describe the internal representation. */ | |
3066 | ||
3067 | /* Various DIE's use offsets relative to the beginning of the | |
3068 | .debug_info section to refer to each other. */ | |
3069 | ||
3070 | typedef long int dw_offset; | |
3071 | ||
3072 | /* Define typedefs here to avoid circular dependencies. */ | |
3073 | ||
3074 | typedef struct dw_attr_struct *dw_attr_ref; | |
3075 | typedef struct dw_line_info_struct *dw_line_info_ref; | |
3076 | typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref; | |
3077 | typedef struct pubname_struct *pubname_ref; | |
3078 | typedef dw_die_ref *arange_ref; | |
3079 | ||
3080 | /* Each entry in the line_info_table maintains the file and | |
3081 | line number associated with the label generated for that | |
3082 | entry. The label gives the PC value associated with | |
3083 | the line number entry. */ | |
3084 | ||
3085 | typedef struct dw_line_info_struct | |
3086 | { | |
3087 | unsigned long dw_file_num; | |
3088 | unsigned long dw_line_num; | |
3089 | } | |
3090 | dw_line_info_entry; | |
3091 | ||
3092 | /* Line information for functions in separate sections; each one gets its | |
3093 | own sequence. */ | |
3094 | typedef struct dw_separate_line_info_struct | |
3095 | { | |
3096 | unsigned long dw_file_num; | |
3097 | unsigned long dw_line_num; | |
3098 | unsigned long function; | |
3099 | } | |
3100 | dw_separate_line_info_entry; | |
3101 | ||
3102 | /* Each DIE attribute has a field specifying the attribute kind, | |
3103 | a link to the next attribute in the chain, and an attribute value. | |
3104 | Attributes are typically linked below the DIE they modify. */ | |
3105 | ||
3106 | typedef struct dw_attr_struct | |
3107 | { | |
3108 | enum dwarf_attribute dw_attr; | |
3109 | dw_attr_ref dw_attr_next; | |
3110 | dw_val_node dw_attr_val; | |
3111 | } | |
3112 | dw_attr_node; | |
3113 | ||
3114 | /* The Debugging Information Entry (DIE) structure */ | |
3115 | ||
3116 | typedef struct die_struct | |
3117 | { | |
3118 | enum dwarf_tag die_tag; | |
881c6935 | 3119 | char *die_symbol; |
7d9d8943 AM |
3120 | dw_attr_ref die_attr; |
3121 | dw_die_ref die_parent; | |
3122 | dw_die_ref die_child; | |
3123 | dw_die_ref die_sib; | |
3124 | dw_offset die_offset; | |
3125 | unsigned long die_abbrev; | |
1bfb5f8f | 3126 | int die_mark; |
7d9d8943 AM |
3127 | } |
3128 | die_node; | |
3129 | ||
3130 | /* The pubname structure */ | |
3131 | ||
3132 | typedef struct pubname_struct | |
3133 | { | |
3134 | dw_die_ref die; | |
556273e0 | 3135 | char *name; |
7d9d8943 AM |
3136 | } |
3137 | pubname_entry; | |
3138 | ||
3139 | /* The limbo die list structure. */ | |
3140 | typedef struct limbo_die_struct | |
3141 | { | |
3142 | dw_die_ref die; | |
3143 | struct limbo_die_struct *next; | |
3144 | } | |
3145 | limbo_die_node; | |
3146 | ||
3147 | /* How to start an assembler comment. */ | |
3148 | #ifndef ASM_COMMENT_START | |
3149 | #define ASM_COMMENT_START ";#" | |
3150 | #endif | |
3151 | ||
3152 | /* Define a macro which returns non-zero for a TYPE_DECL which was | |
3153 | implicitly generated for a tagged type. | |
3154 | ||
3155 | Note that unlike the gcc front end (which generates a NULL named | |
3156 | TYPE_DECL node for each complete tagged type, each array type, and | |
3157 | each function type node created) the g++ front end generates a | |
3158 | _named_ TYPE_DECL node for each tagged type node created. | |
3159 | These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to | |
3160 | generate a DW_TAG_typedef DIE for them. */ | |
3161 | ||
3162 | #define TYPE_DECL_IS_STUB(decl) \ | |
3163 | (DECL_NAME (decl) == NULL_TREE \ | |
3164 | || (DECL_ARTIFICIAL (decl) \ | |
3165 | && is_tagged_type (TREE_TYPE (decl)) \ | |
3166 | && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \ | |
3167 | /* This is necessary for stub decls that \ | |
3168 | appear in nested inline functions. */ \ | |
3169 | || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \ | |
3170 | && (decl_ultimate_origin (decl) \ | |
3171 | == TYPE_STUB_DECL (TREE_TYPE (decl))))))) | |
3172 | ||
3173 | /* Information concerning the compilation unit's programming | |
3174 | language, and compiler version. */ | |
3175 | ||
3176 | extern int flag_traditional; | |
3177 | ||
3178 | /* Fixed size portion of the DWARF compilation unit header. */ | |
3179 | #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3) | |
3180 | ||
3181 | /* Fixed size portion of debugging line information prolog. */ | |
3182 | #define DWARF_LINE_PROLOG_HEADER_SIZE 5 | |
3183 | ||
3184 | /* Fixed size portion of public names info. */ | |
3185 | #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2) | |
3186 | ||
3187 | /* Fixed size portion of the address range info. */ | |
3188 | #define DWARF_ARANGES_HEADER_SIZE \ | |
3189 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ | |
3190 | - DWARF_OFFSET_SIZE) | |
3191 | ||
3192 | /* Size of padding portion in the address range info. It must be | |
3193 | aligned to twice the pointer size. */ | |
3194 | #define DWARF_ARANGES_PAD_SIZE \ | |
3195 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ | |
3196 | - (2 * DWARF_OFFSET_SIZE + 4)) | |
3197 | ||
9d147085 | 3198 | /* Use assembler line directives if available. */ |
7d9d8943 | 3199 | #ifndef DWARF2_ASM_LINE_DEBUG_INFO |
9d147085 RH |
3200 | #ifdef HAVE_AS_DWARF2_DEBUG_LINE |
3201 | #define DWARF2_ASM_LINE_DEBUG_INFO 1 | |
3202 | #else | |
7d9d8943 AM |
3203 | #define DWARF2_ASM_LINE_DEBUG_INFO 0 |
3204 | #endif | |
9d147085 | 3205 | #endif |
7d9d8943 AM |
3206 | |
3207 | /* Define the architecture-dependent minimum instruction length (in bytes). | |
3208 | In this implementation of DWARF, this field is used for information | |
3209 | purposes only. Since GCC generates assembly language, we have | |
3210 | no a priori knowledge of how many instruction bytes are generated | |
3211 | for each source line, and therefore can use only the DW_LNE_set_address | |
3212 | and DW_LNS_fixed_advance_pc line information commands. */ | |
3213 | ||
3214 | #ifndef DWARF_LINE_MIN_INSTR_LENGTH | |
3215 | #define DWARF_LINE_MIN_INSTR_LENGTH 4 | |
3216 | #endif | |
3217 | ||
3218 | /* Minimum line offset in a special line info. opcode. | |
3219 | This value was chosen to give a reasonable range of values. */ | |
3220 | #define DWARF_LINE_BASE -10 | |
3221 | ||
3222 | /* First special line opcde - leave room for the standard opcodes. */ | |
3223 | #define DWARF_LINE_OPCODE_BASE 10 | |
3224 | ||
3225 | /* Range of line offsets in a special line info. opcode. */ | |
3226 | #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1) | |
3227 | ||
3228 | /* Flag that indicates the initial value of the is_stmt_start flag. | |
3229 | In the present implementation, we do not mark any lines as | |
3230 | the beginning of a source statement, because that information | |
3231 | is not made available by the GCC front-end. */ | |
3232 | #define DWARF_LINE_DEFAULT_IS_STMT_START 1 | |
3233 | ||
3234 | /* This location is used by calc_die_sizes() to keep track | |
3235 | the offset of each DIE within the .debug_info section. */ | |
3236 | static unsigned long next_die_offset; | |
3237 | ||
3238 | /* Record the root of the DIE's built for the current compilation unit. */ | |
3239 | static dw_die_ref comp_unit_die; | |
3240 | ||
3241 | /* A list of DIEs with a NULL parent waiting to be relocated. */ | |
3242 | static limbo_die_node *limbo_die_list = 0; | |
3243 | ||
2e18bbae RH |
3244 | /* Structure used by lookup_filename to manage sets of filenames. */ |
3245 | struct file_table | |
3246 | { | |
3247 | char **table; | |
3248 | unsigned allocated; | |
3249 | unsigned in_use; | |
3250 | unsigned last_lookup_index; | |
3251 | }; | |
7d9d8943 AM |
3252 | |
3253 | /* Size (in elements) of increments by which we may expand the filename | |
3254 | table. */ | |
3255 | #define FILE_TABLE_INCREMENT 64 | |
3256 | ||
981975b6 RH |
3257 | /* Filenames referenced by this compilation unit. */ |
3258 | static struct file_table file_table; | |
2e18bbae | 3259 | |
7d9d8943 AM |
3260 | /* Local pointer to the name of the main input file. Initialized in |
3261 | dwarf2out_init. */ | |
3262 | static const char *primary_filename; | |
3263 | ||
3264 | /* A pointer to the base of a table of references to DIE's that describe | |
3265 | declarations. The table is indexed by DECL_UID() which is a unique | |
3266 | number identifying each decl. */ | |
3267 | static dw_die_ref *decl_die_table; | |
3268 | ||
3269 | /* Number of elements currently allocated for the decl_die_table. */ | |
3270 | static unsigned decl_die_table_allocated; | |
3271 | ||
3272 | /* Number of elements in decl_die_table currently in use. */ | |
3273 | static unsigned decl_die_table_in_use; | |
3274 | ||
3275 | /* Size (in elements) of increments by which we may expand the | |
3276 | decl_die_table. */ | |
3277 | #define DECL_DIE_TABLE_INCREMENT 256 | |
3278 | ||
3279 | /* A pointer to the base of a table of references to declaration | |
3280 | scopes. This table is a display which tracks the nesting | |
3281 | of declaration scopes at the current scope and containing | |
3282 | scopes. This table is used to find the proper place to | |
3283 | define type declaration DIE's. */ | |
3284 | static tree *decl_scope_table; | |
3285 | ||
3286 | /* Number of elements currently allocated for the decl_scope_table. */ | |
3287 | static int decl_scope_table_allocated; | |
3288 | ||
3289 | /* Current level of nesting of declaration scopes. */ | |
3290 | static int decl_scope_depth; | |
3291 | ||
3292 | /* Size (in elements) of increments by which we may expand the | |
3293 | decl_scope_table. */ | |
3294 | #define DECL_SCOPE_TABLE_INCREMENT 64 | |
3295 | ||
3296 | /* A pointer to the base of a list of references to DIE's that | |
3297 | are uniquely identified by their tag, presence/absence of | |
3298 | children DIE's, and list of attribute/value pairs. */ | |
3299 | static dw_die_ref *abbrev_die_table; | |
3300 | ||
3301 | /* Number of elements currently allocated for abbrev_die_table. */ | |
3302 | static unsigned abbrev_die_table_allocated; | |
3303 | ||
3304 | /* Number of elements in type_die_table currently in use. */ | |
3305 | static unsigned abbrev_die_table_in_use; | |
3306 | ||
3307 | /* Size (in elements) of increments by which we may expand the | |
3308 | abbrev_die_table. */ | |
3309 | #define ABBREV_DIE_TABLE_INCREMENT 256 | |
3310 | ||
3311 | /* A pointer to the base of a table that contains line information | |
3312 | for each source code line in .text in the compilation unit. */ | |
3313 | static dw_line_info_ref line_info_table; | |
3314 | ||
3315 | /* Number of elements currently allocated for line_info_table. */ | |
3316 | static unsigned line_info_table_allocated; | |
3317 | ||
3318 | /* Number of elements in separate_line_info_table currently in use. */ | |
3319 | static unsigned separate_line_info_table_in_use; | |
3320 | ||
3321 | /* A pointer to the base of a table that contains line information | |
3322 | for each source code line outside of .text in the compilation unit. */ | |
3323 | static dw_separate_line_info_ref separate_line_info_table; | |
3324 | ||
3325 | /* Number of elements currently allocated for separate_line_info_table. */ | |
3326 | static unsigned separate_line_info_table_allocated; | |
3327 | ||
3328 | /* Number of elements in line_info_table currently in use. */ | |
3329 | static unsigned line_info_table_in_use; | |
3330 | ||
3331 | /* Size (in elements) of increments by which we may expand the | |
3332 | line_info_table. */ | |
3333 | #define LINE_INFO_TABLE_INCREMENT 1024 | |
3334 | ||
3335 | /* A pointer to the base of a table that contains a list of publicly | |
3336 | accessible names. */ | |
3337 | static pubname_ref pubname_table; | |
3338 | ||
3339 | /* Number of elements currently allocated for pubname_table. */ | |
3340 | static unsigned pubname_table_allocated; | |
3341 | ||
3342 | /* Number of elements in pubname_table currently in use. */ | |
3343 | static unsigned pubname_table_in_use; | |
3344 | ||
3345 | /* Size (in elements) of increments by which we may expand the | |
3346 | pubname_table. */ | |
3347 | #define PUBNAME_TABLE_INCREMENT 64 | |
3348 | ||
3349 | /* A pointer to the base of a table that contains a list of publicly | |
3350 | accessible names. */ | |
3351 | static arange_ref arange_table; | |
3352 | ||
3353 | /* Number of elements currently allocated for arange_table. */ | |
3354 | static unsigned arange_table_allocated; | |
3355 | ||
3356 | /* Number of elements in arange_table currently in use. */ | |
3357 | static unsigned arange_table_in_use; | |
3358 | ||
3359 | /* Size (in elements) of increments by which we may expand the | |
3360 | arange_table. */ | |
3361 | #define ARANGE_TABLE_INCREMENT 64 | |
3362 | ||
63e46568 DB |
3363 | /* Whether we have location lists that need outputting */ |
3364 | static unsigned have_location_lists; | |
3365 | ||
7d9d8943 AM |
3366 | /* A pointer to the base of a list of incomplete types which might be |
3367 | completed at some later time. */ | |
3368 | ||
3369 | static tree *incomplete_types_list; | |
3370 | ||
3371 | /* Number of elements currently allocated for the incomplete_types_list. */ | |
3372 | static unsigned incomplete_types_allocated; | |
3373 | ||
3374 | /* Number of elements of incomplete_types_list currently in use. */ | |
3375 | static unsigned incomplete_types; | |
3376 | ||
3377 | /* Size (in elements) of increments by which we may expand the incomplete | |
3378 | types list. Actually, a single hunk of space of this size should | |
3379 | be enough for most typical programs. */ | |
3380 | #define INCOMPLETE_TYPES_INCREMENT 64 | |
3381 | ||
3382 | /* Record whether the function being analyzed contains inlined functions. */ | |
3383 | static int current_function_has_inlines; | |
3384 | #if 0 && defined (MIPS_DEBUGGING_INFO) | |
3385 | static int comp_unit_has_inlines; | |
3386 | #endif | |
3387 | ||
3388 | /* Array of RTXes referenced by the debugging information, which therefore | |
3389 | must be kept around forever. We do this rather than perform GC on | |
3390 | the dwarf info because almost all of the dwarf info lives forever, and | |
3391 | it's easier to support non-GC frontends this way. */ | |
3392 | static varray_type used_rtx_varray; | |
3393 | ||
3394 | /* Forward declarations for functions defined in this file. */ | |
3395 | ||
3396 | static int is_pseudo_reg PARAMS ((rtx)); | |
3397 | static tree type_main_variant PARAMS ((tree)); | |
3398 | static int is_tagged_type PARAMS ((tree)); | |
3399 | static const char *dwarf_tag_name PARAMS ((unsigned)); | |
3400 | static const char *dwarf_attr_name PARAMS ((unsigned)); | |
3401 | static const char *dwarf_form_name PARAMS ((unsigned)); | |
3402 | #if 0 | |
3403 | static const char *dwarf_type_encoding_name PARAMS ((unsigned)); | |
3404 | #endif | |
3405 | static tree decl_ultimate_origin PARAMS ((tree)); | |
3406 | static tree block_ultimate_origin PARAMS ((tree)); | |
3407 | static tree decl_class_context PARAMS ((tree)); | |
3408 | static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref)); | |
3409 | static void add_AT_flag PARAMS ((dw_die_ref, | |
3410 | enum dwarf_attribute, | |
3411 | unsigned)); | |
3412 | static void add_AT_int PARAMS ((dw_die_ref, | |
3413 | enum dwarf_attribute, long)); | |
3414 | static void add_AT_unsigned PARAMS ((dw_die_ref, | |
3415 | enum dwarf_attribute, | |
3416 | unsigned long)); | |
3417 | static void add_AT_long_long PARAMS ((dw_die_ref, | |
3418 | enum dwarf_attribute, | |
3419 | unsigned long, | |
3420 | unsigned long)); | |
3421 | static void add_AT_float PARAMS ((dw_die_ref, | |
3422 | enum dwarf_attribute, | |
3423 | unsigned, long *)); | |
3424 | static void add_AT_string PARAMS ((dw_die_ref, | |
3425 | enum dwarf_attribute, | |
3426 | const char *)); | |
3427 | static void add_AT_die_ref PARAMS ((dw_die_ref, | |
3428 | enum dwarf_attribute, | |
3429 | dw_die_ref)); | |
3430 | static void add_AT_fde_ref PARAMS ((dw_die_ref, | |
3431 | enum dwarf_attribute, | |
3432 | unsigned)); | |
3433 | static void add_AT_loc PARAMS ((dw_die_ref, | |
3434 | enum dwarf_attribute, | |
3435 | dw_loc_descr_ref)); | |
63e46568 DB |
3436 | static void add_AT_loc_list PARAMS ((dw_die_ref, |
3437 | enum dwarf_attribute, | |
3438 | dw_loc_list_ref)); | |
7d9d8943 AM |
3439 | static void add_AT_addr PARAMS ((dw_die_ref, |
3440 | enum dwarf_attribute, | |
3441 | rtx)); | |
3442 | static void add_AT_lbl_id PARAMS ((dw_die_ref, | |
3443 | enum dwarf_attribute, | |
3444 | const char *)); | |
3445 | static void add_AT_lbl_offset PARAMS ((dw_die_ref, | |
3446 | enum dwarf_attribute, | |
3447 | const char *)); | |
3448 | static dw_attr_ref get_AT PARAMS ((dw_die_ref, | |
3449 | enum dwarf_attribute)); | |
3450 | static const char *get_AT_low_pc PARAMS ((dw_die_ref)); | |
3451 | static const char *get_AT_hi_pc PARAMS ((dw_die_ref)); | |
3452 | static const char *get_AT_string PARAMS ((dw_die_ref, | |
3453 | enum dwarf_attribute)); | |
3454 | static int get_AT_flag PARAMS ((dw_die_ref, | |
3455 | enum dwarf_attribute)); | |
3456 | static unsigned get_AT_unsigned PARAMS ((dw_die_ref, | |
3457 | enum dwarf_attribute)); | |
3458 | static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref, | |
3459 | enum dwarf_attribute)); | |
3460 | static int is_c_family PARAMS ((void)); | |
28985b81 | 3461 | static int is_java PARAMS ((void)); |
7d9d8943 AM |
3462 | static int is_fortran PARAMS ((void)); |
3463 | static void remove_AT PARAMS ((dw_die_ref, | |
3464 | enum dwarf_attribute)); | |
3465 | static void remove_children PARAMS ((dw_die_ref)); | |
3466 | static void add_child_die PARAMS ((dw_die_ref, dw_die_ref)); | |
3467 | static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref)); | |
3468 | static dw_die_ref lookup_type_die PARAMS ((tree)); | |
3469 | static void equate_type_number_to_die PARAMS ((tree, dw_die_ref)); | |
3470 | static dw_die_ref lookup_decl_die PARAMS ((tree)); | |
3471 | static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref)); | |
3472 | static void print_spaces PARAMS ((FILE *)); | |
3473 | static void print_die PARAMS ((dw_die_ref, FILE *)); | |
3474 | static void print_dwarf_line_table PARAMS ((FILE *)); | |
881c6935 JM |
3475 | static void reverse_die_lists PARAMS ((dw_die_ref)); |
3476 | static void reverse_all_dies PARAMS ((dw_die_ref)); | |
3477 | static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref)); | |
3478 | static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref)); | |
3479 | static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *)); | |
3480 | static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *)); | |
3481 | static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *)); | |
3482 | static void compute_section_prefix PARAMS ((dw_die_ref)); | |
3483 | static int is_type_die PARAMS ((dw_die_ref)); | |
3484 | static int is_comdat_die PARAMS ((dw_die_ref)); | |
3485 | static int is_symbol_die PARAMS ((dw_die_ref)); | |
881c6935 JM |
3486 | static void assign_symbol_names PARAMS ((dw_die_ref)); |
3487 | static void break_out_includes PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3488 | static void add_sibling_attributes PARAMS ((dw_die_ref)); |
3489 | static void build_abbrev_table PARAMS ((dw_die_ref)); | |
63e46568 | 3490 | static void output_location_lists PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3491 | static unsigned long size_of_string PARAMS ((const char *)); |
3492 | static int constant_size PARAMS ((long unsigned)); | |
3493 | static unsigned long size_of_die PARAMS ((dw_die_ref)); | |
3494 | static void calc_die_sizes PARAMS ((dw_die_ref)); | |
1bfb5f8f JM |
3495 | static void mark_dies PARAMS ((dw_die_ref)); |
3496 | static void unmark_dies PARAMS ((dw_die_ref)); | |
7d9d8943 AM |
3497 | static unsigned long size_of_pubnames PARAMS ((void)); |
3498 | static unsigned long size_of_aranges PARAMS ((void)); | |
3499 | static enum dwarf_form value_format PARAMS ((dw_attr_ref)); | |
3500 | static void output_value_format PARAMS ((dw_attr_ref)); | |
3501 | static void output_abbrev_section PARAMS ((void)); | |
881c6935 | 3502 | static void output_die_symbol PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3503 | static void output_die PARAMS ((dw_die_ref)); |
3504 | static void output_compilation_unit_header PARAMS ((void)); | |
881c6935 | 3505 | static void output_comp_unit PARAMS ((dw_die_ref)); |
7d9d8943 AM |
3506 | static const char *dwarf2_name PARAMS ((tree, int)); |
3507 | static void add_pubname PARAMS ((tree, dw_die_ref)); | |
3508 | static void output_pubnames PARAMS ((void)); | |
3509 | static void add_arange PARAMS ((tree, dw_die_ref)); | |
3510 | static void output_aranges PARAMS ((void)); | |
3511 | static void output_line_info PARAMS ((void)); | |
0b34cf1e | 3512 | static void output_file_names PARAMS ((void)); |
7d9d8943 AM |
3513 | static dw_die_ref base_type_die PARAMS ((tree)); |
3514 | static tree root_type PARAMS ((tree)); | |
3515 | static int is_base_type PARAMS ((tree)); | |
3516 | static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref)); | |
3517 | static int type_is_enum PARAMS ((tree)); | |
3518 | static unsigned int reg_number PARAMS ((rtx)); | |
3519 | static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx)); | |
d8041cc8 | 3520 | static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT)); |
7d9d8943 AM |
3521 | static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long)); |
3522 | static int is_based_loc PARAMS ((rtx)); | |
3523 | static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode)); | |
3524 | static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx)); | |
3525 | static dw_loc_descr_ref loc_descriptor PARAMS ((rtx)); | |
d8041cc8 | 3526 | static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int)); |
7d9d8943 AM |
3527 | static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int)); |
3528 | static tree field_type PARAMS ((tree)); | |
3529 | static unsigned int simple_type_align_in_bits PARAMS ((tree)); | |
5f446d21 | 3530 | static unsigned int simple_decl_align_in_bits PARAMS ((tree)); |
7d9d8943 AM |
3531 | static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree)); |
3532 | static HOST_WIDE_INT field_byte_offset PARAMS ((tree)); | |
3533 | static void add_AT_location_description PARAMS ((dw_die_ref, | |
3534 | enum dwarf_attribute, rtx)); | |
3535 | static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree)); | |
3536 | static void add_const_value_attribute PARAMS ((dw_die_ref, rtx)); | |
d8041cc8 | 3537 | static rtx rtl_for_decl_location PARAMS ((tree)); |
7d9d8943 | 3538 | static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree)); |
1bfb5f8f | 3539 | static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree)); |
7d9d8943 AM |
3540 | static void add_name_attribute PARAMS ((dw_die_ref, const char *)); |
3541 | static void add_bound_info PARAMS ((dw_die_ref, | |
3542 | enum dwarf_attribute, tree)); | |
3543 | static void add_subscript_info PARAMS ((dw_die_ref, tree)); | |
3544 | static void add_byte_size_attribute PARAMS ((dw_die_ref, tree)); | |
3545 | static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree)); | |
3546 | static void add_bit_size_attribute PARAMS ((dw_die_ref, tree)); | |
3547 | static void add_prototyped_attribute PARAMS ((dw_die_ref, tree)); | |
3548 | static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree)); | |
3549 | static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree)); | |
3550 | static void add_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
3551 | static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree)); | |
3552 | static void push_decl_scope PARAMS ((tree)); | |
3553 | static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref)); | |
3554 | static void pop_decl_scope PARAMS ((void)); | |
3555 | static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int, | |
3556 | dw_die_ref)); | |
3557 | static const char *type_tag PARAMS ((tree)); | |
3558 | static tree member_declared_type PARAMS ((tree)); | |
3559 | #if 0 | |
3560 | static const char *decl_start_label PARAMS ((tree)); | |
3561 | #endif | |
3562 | static void gen_array_type_die PARAMS ((tree, dw_die_ref)); | |
3563 | static void gen_set_type_die PARAMS ((tree, dw_die_ref)); | |
3564 | #if 0 | |
3565 | static void gen_entry_point_die PARAMS ((tree, dw_die_ref)); | |
3566 | #endif | |
3567 | static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
3568 | static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref)); | |
3569 | static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref)); | |
3570 | static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref)); | |
3571 | static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref)); | |
3572 | static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref)); | |
3573 | static void gen_formal_types_die PARAMS ((tree, dw_die_ref)); | |
3574 | static void gen_subprogram_die PARAMS ((tree, dw_die_ref)); | |
3575 | static void gen_variable_die PARAMS ((tree, dw_die_ref)); | |
3576 | static void gen_label_die PARAMS ((tree, dw_die_ref)); | |
3577 | static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int)); | |
3578 | static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int)); | |
3579 | static void gen_field_die PARAMS ((tree, dw_die_ref)); | |
3580 | static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref)); | |
3581 | static dw_die_ref gen_compile_unit_die PARAMS ((const char *)); | |
3582 | static void gen_string_type_die PARAMS ((tree, dw_die_ref)); | |
3583 | static void gen_inheritance_die PARAMS ((tree, dw_die_ref)); | |
3584 | static void gen_member_die PARAMS ((tree, dw_die_ref)); | |
3585 | static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref)); | |
3586 | static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref)); | |
3587 | static void gen_typedef_die PARAMS ((tree, dw_die_ref)); | |
3588 | static void gen_type_die PARAMS ((tree, dw_die_ref)); | |
3589 | static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref)); | |
3590 | static void gen_block_die PARAMS ((tree, dw_die_ref, int)); | |
3591 | static void decls_for_scope PARAMS ((tree, dw_die_ref, int)); | |
3592 | static int is_redundant_typedef PARAMS ((tree)); | |
3593 | static void gen_decl_die PARAMS ((tree, dw_die_ref)); | |
981975b6 RH |
3594 | static unsigned lookup_filename PARAMS ((const char *)); |
3595 | static void init_file_table PARAMS ((void)); | |
7d9d8943 AM |
3596 | static void add_incomplete_type PARAMS ((tree)); |
3597 | static void retry_incomplete_types PARAMS ((void)); | |
3598 | static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref)); | |
7d9d8943 AM |
3599 | static rtx save_rtx PARAMS ((rtx)); |
3600 | static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref)); | |
fc608b03 | 3601 | static int file_info_cmp PARAMS ((const void *, const void *)); |
84a5b4f8 DB |
3602 | static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref, |
3603 | const char *, const char *, | |
3604 | const char *, unsigned)); | |
3605 | static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *, | |
3606 | dw_loc_descr_ref, | |
3607 | const char *, const char *, const char *)); | |
3608 | static void output_loc_list PARAMS ((dw_loc_list_ref)); | |
3609 | static char *gen_internal_sym PARAMS ((const char *)); | |
7d9d8943 AM |
3610 | |
3611 | /* Section names used to hold DWARF debugging information. */ | |
3612 | #ifndef DEBUG_INFO_SECTION | |
3613 | #define DEBUG_INFO_SECTION ".debug_info" | |
3614 | #endif | |
9d2f2c45 RH |
3615 | #ifndef DEBUG_ABBREV_SECTION |
3616 | #define DEBUG_ABBREV_SECTION ".debug_abbrev" | |
7d9d8943 | 3617 | #endif |
9d2f2c45 RH |
3618 | #ifndef DEBUG_ARANGES_SECTION |
3619 | #define DEBUG_ARANGES_SECTION ".debug_aranges" | |
7d9d8943 | 3620 | #endif |
9d2f2c45 RH |
3621 | #ifndef DEBUG_MACINFO_SECTION |
3622 | #define DEBUG_MACINFO_SECTION ".debug_macinfo" | |
7d9d8943 AM |
3623 | #endif |
3624 | #ifndef DEBUG_LINE_SECTION | |
3625 | #define DEBUG_LINE_SECTION ".debug_line" | |
3626 | #endif | |
9d2f2c45 RH |
3627 | #ifndef DEBUG_LOC_SECTION |
3628 | #define DEBUG_LOC_SECTION ".debug_loc" | |
7d9d8943 | 3629 | #endif |
9d2f2c45 RH |
3630 | #ifndef DEBUG_PUBNAMES_SECTION |
3631 | #define DEBUG_PUBNAMES_SECTION ".debug_pubnames" | |
7d9d8943 | 3632 | #endif |
9d2f2c45 RH |
3633 | #ifndef DEBUG_STR_SECTION |
3634 | #define DEBUG_STR_SECTION ".debug_str" | |
7d9d8943 AM |
3635 | #endif |
3636 | ||
3637 | /* Standard ELF section names for compiled code and data. */ | |
3638 | #ifndef TEXT_SECTION | |
3639 | #define TEXT_SECTION ".text" | |
3640 | #endif | |
3641 | #ifndef DATA_SECTION | |
3642 | #define DATA_SECTION ".data" | |
3643 | #endif | |
3644 | #ifndef BSS_SECTION | |
3645 | #define BSS_SECTION ".bss" | |
3646 | #endif | |
3647 | ||
3648 | /* Labels we insert at beginning sections we can reference instead of | |
556273e0 | 3649 | the section names themselves. */ |
7d9d8943 AM |
3650 | |
3651 | #ifndef TEXT_SECTION_LABEL | |
9d2f2c45 | 3652 | #define TEXT_SECTION_LABEL "Ltext" |
7d9d8943 AM |
3653 | #endif |
3654 | #ifndef DEBUG_LINE_SECTION_LABEL | |
9d2f2c45 | 3655 | #define DEBUG_LINE_SECTION_LABEL "Ldebug_line" |
7d9d8943 AM |
3656 | #endif |
3657 | #ifndef DEBUG_INFO_SECTION_LABEL | |
9d2f2c45 | 3658 | #define DEBUG_INFO_SECTION_LABEL "Ldebug_info" |
7d9d8943 | 3659 | #endif |
9d2f2c45 RH |
3660 | #ifndef DEBUG_ABBREV_SECTION_LABEL |
3661 | #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev" | |
7d9d8943 | 3662 | #endif |
9d2f2c45 RH |
3663 | #ifndef DEBUG_LOC_SECTION_LABEL |
3664 | #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc" | |
63e46568 | 3665 | #endif |
84a5b4f8 DB |
3666 | #ifndef DEBUG_MACINFO_SECTION_LABEL |
3667 | #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo" | |
3668 | #endif | |
7d9d8943 AM |
3669 | /* Definitions of defaults for formats and names of various special |
3670 | (artificial) labels which may be generated within this file (when the -g | |
3671 | options is used and DWARF_DEBUGGING_INFO is in effect. | |
3672 | If necessary, these may be overridden from within the tm.h file, but | |
3673 | typically, overriding these defaults is unnecessary. */ | |
3674 | ||
3675 | static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3676 | static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3677 | static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3678 | static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3679 | static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
84a5b4f8 | 3680 | static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
63e46568 | 3681 | static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
7d9d8943 AM |
3682 | #ifndef TEXT_END_LABEL |
3683 | #define TEXT_END_LABEL "Letext" | |
3684 | #endif | |
3685 | #ifndef DATA_END_LABEL | |
3686 | #define DATA_END_LABEL "Ledata" | |
3687 | #endif | |
3688 | #ifndef BSS_END_LABEL | |
3689 | #define BSS_END_LABEL "Lebss" | |
3690 | #endif | |
7d9d8943 AM |
3691 | #ifndef BLOCK_BEGIN_LABEL |
3692 | #define BLOCK_BEGIN_LABEL "LBB" | |
3693 | #endif | |
3694 | #ifndef BLOCK_END_LABEL | |
3695 | #define BLOCK_END_LABEL "LBE" | |
3696 | #endif | |
3697 | #ifndef BODY_BEGIN_LABEL | |
3698 | #define BODY_BEGIN_LABEL "Lbb" | |
3699 | #endif | |
3700 | #ifndef BODY_END_LABEL | |
3701 | #define BODY_END_LABEL "Lbe" | |
3702 | #endif | |
3703 | #ifndef LINE_CODE_LABEL | |
3704 | #define LINE_CODE_LABEL "LM" | |
3705 | #endif | |
3706 | #ifndef SEPARATE_LINE_CODE_LABEL | |
3707 | #define SEPARATE_LINE_CODE_LABEL "LSM" | |
3708 | #endif | |
3709 | \f | |
3710 | /* We allow a language front-end to designate a function that is to be | |
3711 | called to "demangle" any name before it it put into a DIE. */ | |
3712 | ||
3713 | static const char *(*demangle_name_func) PARAMS ((const char *)); | |
3714 | ||
3715 | void | |
3716 | dwarf2out_set_demangle_name_func (func) | |
3717 | const char *(*func) PARAMS ((const char *)); | |
3718 | { | |
3719 | demangle_name_func = func; | |
3720 | } | |
3721 | \f | |
3722 | /* Return an rtx like ORIG which lives forever. If we're doing GC, | |
3723 | that means adding it to used_rtx_varray. If not, that means making | |
3724 | a copy on the permanent_obstack. */ | |
3725 | ||
3726 | static rtx | |
3727 | save_rtx (orig) | |
3728 | register rtx orig; | |
3729 | { | |
1f8f4a0b | 3730 | VARRAY_PUSH_RTX (used_rtx_varray, orig); |
7d9d8943 AM |
3731 | |
3732 | return orig; | |
3733 | } | |
3734 | ||
3735 | /* Test if rtl node points to a pseudo register. */ | |
3736 | ||
3737 | static inline int | |
3738 | is_pseudo_reg (rtl) | |
3739 | register rtx rtl; | |
3740 | { | |
3741 | return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER) | |
3742 | || (GET_CODE (rtl) == SUBREG | |
ddef6bc7 | 3743 | && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)); |
7d9d8943 AM |
3744 | } |
3745 | ||
3746 | /* Return a reference to a type, with its const and volatile qualifiers | |
3747 | removed. */ | |
3748 | ||
3749 | static inline tree | |
3750 | type_main_variant (type) | |
3751 | register tree type; | |
3752 | { | |
3753 | type = TYPE_MAIN_VARIANT (type); | |
3754 | ||
556273e0 | 3755 | /* There really should be only one main variant among any group of variants |
7d9d8943 AM |
3756 | of a given type (and all of the MAIN_VARIANT values for all members of |
3757 | the group should point to that one type) but sometimes the C front-end | |
3758 | messes this up for array types, so we work around that bug here. */ | |
3759 | ||
3760 | if (TREE_CODE (type) == ARRAY_TYPE) | |
3761 | while (type != TYPE_MAIN_VARIANT (type)) | |
3762 | type = TYPE_MAIN_VARIANT (type); | |
3763 | ||
3764 | return type; | |
3765 | } | |
3766 | ||
3767 | /* Return non-zero if the given type node represents a tagged type. */ | |
3768 | ||
3769 | static inline int | |
3770 | is_tagged_type (type) | |
3771 | register tree type; | |
3772 | { | |
3773 | register enum tree_code code = TREE_CODE (type); | |
3774 | ||
3775 | return (code == RECORD_TYPE || code == UNION_TYPE | |
3776 | || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); | |
3777 | } | |
3778 | ||
3779 | /* Convert a DIE tag into its string name. */ | |
3780 | ||
3781 | static const char * | |
3782 | dwarf_tag_name (tag) | |
3783 | register unsigned tag; | |
3784 | { | |
3785 | switch (tag) | |
3786 | { | |
3787 | case DW_TAG_padding: | |
3788 | return "DW_TAG_padding"; | |
3789 | case DW_TAG_array_type: | |
3790 | return "DW_TAG_array_type"; | |
3791 | case DW_TAG_class_type: | |
3792 | return "DW_TAG_class_type"; | |
3793 | case DW_TAG_entry_point: | |
3794 | return "DW_TAG_entry_point"; | |
3795 | case DW_TAG_enumeration_type: | |
3796 | return "DW_TAG_enumeration_type"; | |
3797 | case DW_TAG_formal_parameter: | |
3798 | return "DW_TAG_formal_parameter"; | |
3799 | case DW_TAG_imported_declaration: | |
3800 | return "DW_TAG_imported_declaration"; | |
3801 | case DW_TAG_label: | |
3802 | return "DW_TAG_label"; | |
3803 | case DW_TAG_lexical_block: | |
3804 | return "DW_TAG_lexical_block"; | |
3805 | case DW_TAG_member: | |
3806 | return "DW_TAG_member"; | |
3807 | case DW_TAG_pointer_type: | |
3808 | return "DW_TAG_pointer_type"; | |
3809 | case DW_TAG_reference_type: | |
3810 | return "DW_TAG_reference_type"; | |
3811 | case DW_TAG_compile_unit: | |
3812 | return "DW_TAG_compile_unit"; | |
3813 | case DW_TAG_string_type: | |
3814 | return "DW_TAG_string_type"; | |
3815 | case DW_TAG_structure_type: | |
3816 | return "DW_TAG_structure_type"; | |
3817 | case DW_TAG_subroutine_type: | |
3818 | return "DW_TAG_subroutine_type"; | |
3819 | case DW_TAG_typedef: | |
3820 | return "DW_TAG_typedef"; | |
3821 | case DW_TAG_union_type: | |
3822 | return "DW_TAG_union_type"; | |
3823 | case DW_TAG_unspecified_parameters: | |
3824 | return "DW_TAG_unspecified_parameters"; | |
3825 | case DW_TAG_variant: | |
3826 | return "DW_TAG_variant"; | |
3827 | case DW_TAG_common_block: | |
3828 | return "DW_TAG_common_block"; | |
3829 | case DW_TAG_common_inclusion: | |
3830 | return "DW_TAG_common_inclusion"; | |
3831 | case DW_TAG_inheritance: | |
3832 | return "DW_TAG_inheritance"; | |
3833 | case DW_TAG_inlined_subroutine: | |
3834 | return "DW_TAG_inlined_subroutine"; | |
3835 | case DW_TAG_module: | |
3836 | return "DW_TAG_module"; | |
3837 | case DW_TAG_ptr_to_member_type: | |
3838 | return "DW_TAG_ptr_to_member_type"; | |
3839 | case DW_TAG_set_type: | |
3840 | return "DW_TAG_set_type"; | |
3841 | case DW_TAG_subrange_type: | |
3842 | return "DW_TAG_subrange_type"; | |
3843 | case DW_TAG_with_stmt: | |
3844 | return "DW_TAG_with_stmt"; | |
3845 | case DW_TAG_access_declaration: | |
3846 | return "DW_TAG_access_declaration"; | |
3847 | case DW_TAG_base_type: | |
3848 | return "DW_TAG_base_type"; | |
3849 | case DW_TAG_catch_block: | |
3850 | return "DW_TAG_catch_block"; | |
3851 | case DW_TAG_const_type: | |
3852 | return "DW_TAG_const_type"; | |
3853 | case DW_TAG_constant: | |
3854 | return "DW_TAG_constant"; | |
3855 | case DW_TAG_enumerator: | |
3856 | return "DW_TAG_enumerator"; | |
3857 | case DW_TAG_file_type: | |
3858 | return "DW_TAG_file_type"; | |
3859 | case DW_TAG_friend: | |
3860 | return "DW_TAG_friend"; | |
3861 | case DW_TAG_namelist: | |
3862 | return "DW_TAG_namelist"; | |
3863 | case DW_TAG_namelist_item: | |
3864 | return "DW_TAG_namelist_item"; | |
3865 | case DW_TAG_packed_type: | |
3866 | return "DW_TAG_packed_type"; | |
3867 | case DW_TAG_subprogram: | |
3868 | return "DW_TAG_subprogram"; | |
3869 | case DW_TAG_template_type_param: | |
3870 | return "DW_TAG_template_type_param"; | |
3871 | case DW_TAG_template_value_param: | |
3872 | return "DW_TAG_template_value_param"; | |
3873 | case DW_TAG_thrown_type: | |
3874 | return "DW_TAG_thrown_type"; | |
3875 | case DW_TAG_try_block: | |
3876 | return "DW_TAG_try_block"; | |
3877 | case DW_TAG_variant_part: | |
3878 | return "DW_TAG_variant_part"; | |
3879 | case DW_TAG_variable: | |
3880 | return "DW_TAG_variable"; | |
3881 | case DW_TAG_volatile_type: | |
3882 | return "DW_TAG_volatile_type"; | |
3883 | case DW_TAG_MIPS_loop: | |
3884 | return "DW_TAG_MIPS_loop"; | |
3885 | case DW_TAG_format_label: | |
3886 | return "DW_TAG_format_label"; | |
3887 | case DW_TAG_function_template: | |
3888 | return "DW_TAG_function_template"; | |
3889 | case DW_TAG_class_template: | |
3890 | return "DW_TAG_class_template"; | |
881c6935 JM |
3891 | case DW_TAG_GNU_BINCL: |
3892 | return "DW_TAG_GNU_BINCL"; | |
3893 | case DW_TAG_GNU_EINCL: | |
3894 | return "DW_TAG_GNU_EINCL"; | |
7d9d8943 AM |
3895 | default: |
3896 | return "DW_TAG_<unknown>"; | |
3897 | } | |
3898 | } | |
3899 | ||
3900 | /* Convert a DWARF attribute code into its string name. */ | |
3901 | ||
3902 | static const char * | |
3903 | dwarf_attr_name (attr) | |
3904 | register unsigned attr; | |
3905 | { | |
3906 | switch (attr) | |
3907 | { | |
3908 | case DW_AT_sibling: | |
3909 | return "DW_AT_sibling"; | |
3910 | case DW_AT_location: | |
3911 | return "DW_AT_location"; | |
3912 | case DW_AT_name: | |
3913 | return "DW_AT_name"; | |
3914 | case DW_AT_ordering: | |
3915 | return "DW_AT_ordering"; | |
3916 | case DW_AT_subscr_data: | |
3917 | return "DW_AT_subscr_data"; | |
3918 | case DW_AT_byte_size: | |
3919 | return "DW_AT_byte_size"; | |
3920 | case DW_AT_bit_offset: | |
3921 | return "DW_AT_bit_offset"; | |
3922 | case DW_AT_bit_size: | |
3923 | return "DW_AT_bit_size"; | |
3924 | case DW_AT_element_list: | |
3925 | return "DW_AT_element_list"; | |
3926 | case DW_AT_stmt_list: | |
3927 | return "DW_AT_stmt_list"; | |
3928 | case DW_AT_low_pc: | |
3929 | return "DW_AT_low_pc"; | |
3930 | case DW_AT_high_pc: | |
3931 | return "DW_AT_high_pc"; | |
3932 | case DW_AT_language: | |
3933 | return "DW_AT_language"; | |
3934 | case DW_AT_member: | |
3935 | return "DW_AT_member"; | |
3936 | case DW_AT_discr: | |
3937 | return "DW_AT_discr"; | |
3938 | case DW_AT_discr_value: | |
3939 | return "DW_AT_discr_value"; | |
3940 | case DW_AT_visibility: | |
3941 | return "DW_AT_visibility"; | |
3942 | case DW_AT_import: | |
3943 | return "DW_AT_import"; | |
3944 | case DW_AT_string_length: | |
3945 | return "DW_AT_string_length"; | |
3946 | case DW_AT_common_reference: | |
3947 | return "DW_AT_common_reference"; | |
3948 | case DW_AT_comp_dir: | |
3949 | return "DW_AT_comp_dir"; | |
3950 | case DW_AT_const_value: | |
3951 | return "DW_AT_const_value"; | |
3952 | case DW_AT_containing_type: | |
3953 | return "DW_AT_containing_type"; | |
3954 | case DW_AT_default_value: | |
3955 | return "DW_AT_default_value"; | |
3956 | case DW_AT_inline: | |
3957 | return "DW_AT_inline"; | |
3958 | case DW_AT_is_optional: | |
3959 | return "DW_AT_is_optional"; | |
3960 | case DW_AT_lower_bound: | |
3961 | return "DW_AT_lower_bound"; | |
3962 | case DW_AT_producer: | |
3963 | return "DW_AT_producer"; | |
3964 | case DW_AT_prototyped: | |
3965 | return "DW_AT_prototyped"; | |
3966 | case DW_AT_return_addr: | |
3967 | return "DW_AT_return_addr"; | |
3968 | case DW_AT_start_scope: | |
3969 | return "DW_AT_start_scope"; | |
3970 | case DW_AT_stride_size: | |
3971 | return "DW_AT_stride_size"; | |
3972 | case DW_AT_upper_bound: | |
3973 | return "DW_AT_upper_bound"; | |
3974 | case DW_AT_abstract_origin: | |
3975 | return "DW_AT_abstract_origin"; | |
3976 | case DW_AT_accessibility: | |
3977 | return "DW_AT_accessibility"; | |
3978 | case DW_AT_address_class: | |
3979 | return "DW_AT_address_class"; | |
3980 | case DW_AT_artificial: | |
3981 | return "DW_AT_artificial"; | |
3982 | case DW_AT_base_types: | |
3983 | return "DW_AT_base_types"; | |
3984 | case DW_AT_calling_convention: | |
3985 | return "DW_AT_calling_convention"; | |
3986 | case DW_AT_count: | |
3987 | return "DW_AT_count"; | |
3988 | case DW_AT_data_member_location: | |
3989 | return "DW_AT_data_member_location"; | |
3990 | case DW_AT_decl_column: | |
3991 | return "DW_AT_decl_column"; | |
3992 | case DW_AT_decl_file: | |
3993 | return "DW_AT_decl_file"; | |
3994 | case DW_AT_decl_line: | |
3995 | return "DW_AT_decl_line"; | |
3996 | case DW_AT_declaration: | |
3997 | return "DW_AT_declaration"; | |
3998 | case DW_AT_discr_list: | |
3999 | return "DW_AT_discr_list"; | |
4000 | case DW_AT_encoding: | |
4001 | return "DW_AT_encoding"; | |
4002 | case DW_AT_external: | |
4003 | return "DW_AT_external"; | |
4004 | case DW_AT_frame_base: | |
4005 | return "DW_AT_frame_base"; | |
4006 | case DW_AT_friend: | |
4007 | return "DW_AT_friend"; | |
4008 | case DW_AT_identifier_case: | |
4009 | return "DW_AT_identifier_case"; | |
4010 | case DW_AT_macro_info: | |
4011 | return "DW_AT_macro_info"; | |
4012 | case DW_AT_namelist_items: | |
4013 | return "DW_AT_namelist_items"; | |
4014 | case DW_AT_priority: | |
4015 | return "DW_AT_priority"; | |
4016 | case DW_AT_segment: | |
4017 | return "DW_AT_segment"; | |
4018 | case DW_AT_specification: | |
4019 | return "DW_AT_specification"; | |
4020 | case DW_AT_static_link: | |
4021 | return "DW_AT_static_link"; | |
4022 | case DW_AT_type: | |
4023 | return "DW_AT_type"; | |
4024 | case DW_AT_use_location: | |
4025 | return "DW_AT_use_location"; | |
4026 | case DW_AT_variable_parameter: | |
4027 | return "DW_AT_variable_parameter"; | |
4028 | case DW_AT_virtuality: | |
4029 | return "DW_AT_virtuality"; | |
4030 | case DW_AT_vtable_elem_location: | |
4031 | return "DW_AT_vtable_elem_location"; | |
4032 | ||
4033 | case DW_AT_MIPS_fde: | |
4034 | return "DW_AT_MIPS_fde"; | |
4035 | case DW_AT_MIPS_loop_begin: | |
4036 | return "DW_AT_MIPS_loop_begin"; | |
4037 | case DW_AT_MIPS_tail_loop_begin: | |
4038 | return "DW_AT_MIPS_tail_loop_begin"; | |
4039 | case DW_AT_MIPS_epilog_begin: | |
4040 | return "DW_AT_MIPS_epilog_begin"; | |
4041 | case DW_AT_MIPS_loop_unroll_factor: | |
4042 | return "DW_AT_MIPS_loop_unroll_factor"; | |
4043 | case DW_AT_MIPS_software_pipeline_depth: | |
4044 | return "DW_AT_MIPS_software_pipeline_depth"; | |
4045 | case DW_AT_MIPS_linkage_name: | |
4046 | return "DW_AT_MIPS_linkage_name"; | |
4047 | case DW_AT_MIPS_stride: | |
4048 | return "DW_AT_MIPS_stride"; | |
4049 | case DW_AT_MIPS_abstract_name: | |
4050 | return "DW_AT_MIPS_abstract_name"; | |
4051 | case DW_AT_MIPS_clone_origin: | |
4052 | return "DW_AT_MIPS_clone_origin"; | |
4053 | case DW_AT_MIPS_has_inlines: | |
4054 | return "DW_AT_MIPS_has_inlines"; | |
4055 | ||
4056 | case DW_AT_sf_names: | |
4057 | return "DW_AT_sf_names"; | |
4058 | case DW_AT_src_info: | |
4059 | return "DW_AT_src_info"; | |
4060 | case DW_AT_mac_info: | |
4061 | return "DW_AT_mac_info"; | |
4062 | case DW_AT_src_coords: | |
4063 | return "DW_AT_src_coords"; | |
4064 | case DW_AT_body_begin: | |
4065 | return "DW_AT_body_begin"; | |
4066 | case DW_AT_body_end: | |
4067 | return "DW_AT_body_end"; | |
4068 | default: | |
4069 | return "DW_AT_<unknown>"; | |
4070 | } | |
4071 | } | |
4072 | ||
4073 | /* Convert a DWARF value form code into its string name. */ | |
4074 | ||
4075 | static const char * | |
4076 | dwarf_form_name (form) | |
4077 | register unsigned form; | |
4078 | { | |
4079 | switch (form) | |
4080 | { | |
4081 | case DW_FORM_addr: | |
4082 | return "DW_FORM_addr"; | |
4083 | case DW_FORM_block2: | |
4084 | return "DW_FORM_block2"; | |
4085 | case DW_FORM_block4: | |
4086 | return "DW_FORM_block4"; | |
4087 | case DW_FORM_data2: | |
4088 | return "DW_FORM_data2"; | |
4089 | case DW_FORM_data4: | |
4090 | return "DW_FORM_data4"; | |
4091 | case DW_FORM_data8: | |
4092 | return "DW_FORM_data8"; | |
4093 | case DW_FORM_string: | |
4094 | return "DW_FORM_string"; | |
4095 | case DW_FORM_block: | |
4096 | return "DW_FORM_block"; | |
4097 | case DW_FORM_block1: | |
4098 | return "DW_FORM_block1"; | |
4099 | case DW_FORM_data1: | |
4100 | return "DW_FORM_data1"; | |
4101 | case DW_FORM_flag: | |
4102 | return "DW_FORM_flag"; | |
4103 | case DW_FORM_sdata: | |
4104 | return "DW_FORM_sdata"; | |
4105 | case DW_FORM_strp: | |
4106 | return "DW_FORM_strp"; | |
4107 | case DW_FORM_udata: | |
4108 | return "DW_FORM_udata"; | |
4109 | case DW_FORM_ref_addr: | |
4110 | return "DW_FORM_ref_addr"; | |
4111 | case DW_FORM_ref1: | |
4112 | return "DW_FORM_ref1"; | |
4113 | case DW_FORM_ref2: | |
4114 | return "DW_FORM_ref2"; | |
4115 | case DW_FORM_ref4: | |
4116 | return "DW_FORM_ref4"; | |
4117 | case DW_FORM_ref8: | |
4118 | return "DW_FORM_ref8"; | |
4119 | case DW_FORM_ref_udata: | |
4120 | return "DW_FORM_ref_udata"; | |
4121 | case DW_FORM_indirect: | |
4122 | return "DW_FORM_indirect"; | |
3f76745e | 4123 | default: |
7d9d8943 | 4124 | return "DW_FORM_<unknown>"; |
a3f97cbb JW |
4125 | } |
4126 | } | |
4127 | ||
3f76745e | 4128 | /* Convert a DWARF type code into its string name. */ |
71dfc51f | 4129 | |
487a6e06 | 4130 | #if 0 |
d560ee52 | 4131 | static const char * |
3f76745e JM |
4132 | dwarf_type_encoding_name (enc) |
4133 | register unsigned enc; | |
a3f97cbb | 4134 | { |
3f76745e | 4135 | switch (enc) |
a3f97cbb | 4136 | { |
3f76745e JM |
4137 | case DW_ATE_address: |
4138 | return "DW_ATE_address"; | |
4139 | case DW_ATE_boolean: | |
4140 | return "DW_ATE_boolean"; | |
4141 | case DW_ATE_complex_float: | |
4142 | return "DW_ATE_complex_float"; | |
4143 | case DW_ATE_float: | |
4144 | return "DW_ATE_float"; | |
4145 | case DW_ATE_signed: | |
4146 | return "DW_ATE_signed"; | |
4147 | case DW_ATE_signed_char: | |
4148 | return "DW_ATE_signed_char"; | |
4149 | case DW_ATE_unsigned: | |
4150 | return "DW_ATE_unsigned"; | |
4151 | case DW_ATE_unsigned_char: | |
4152 | return "DW_ATE_unsigned_char"; | |
4153 | default: | |
4154 | return "DW_ATE_<unknown>"; | |
4155 | } | |
a3f97cbb | 4156 | } |
487a6e06 | 4157 | #endif |
3f76745e JM |
4158 | \f |
4159 | /* Determine the "ultimate origin" of a decl. The decl may be an inlined | |
4160 | instance of an inlined instance of a decl which is local to an inline | |
4161 | function, so we have to trace all of the way back through the origin chain | |
4162 | to find out what sort of node actually served as the original seed for the | |
4163 | given block. */ | |
a3f97cbb | 4164 | |
3f76745e JM |
4165 | static tree |
4166 | decl_ultimate_origin (decl) | |
4167 | register tree decl; | |
a3f97cbb | 4168 | { |
10a11b75 JM |
4169 | /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the |
4170 | nodes in the function to point to themselves; ignore that if | |
4171 | we're trying to output the abstract instance of this function. */ | |
4172 | if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl) | |
4173 | return NULL_TREE; | |
4174 | ||
556273e0 | 4175 | #ifdef ENABLE_CHECKING |
02e24c7a MM |
4176 | if (DECL_FROM_INLINE (DECL_ORIGIN (decl))) |
4177 | /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the | |
4178 | most distant ancestor, this should never happen. */ | |
4179 | abort (); | |
4180 | #endif | |
3f76745e | 4181 | |
02e24c7a | 4182 | return DECL_ABSTRACT_ORIGIN (decl); |
a3f97cbb JW |
4183 | } |
4184 | ||
3f76745e JM |
4185 | /* Determine the "ultimate origin" of a block. The block may be an inlined |
4186 | instance of an inlined instance of a block which is local to an inline | |
4187 | function, so we have to trace all of the way back through the origin chain | |
4188 | to find out what sort of node actually served as the original seed for the | |
4189 | given block. */ | |
71dfc51f | 4190 | |
3f76745e JM |
4191 | static tree |
4192 | block_ultimate_origin (block) | |
4193 | register tree block; | |
a3f97cbb | 4194 | { |
3f76745e | 4195 | register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); |
71dfc51f | 4196 | |
10a11b75 JM |
4197 | /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the |
4198 | nodes in the function to point to themselves; ignore that if | |
4199 | we're trying to output the abstract instance of this function. */ | |
4200 | if (BLOCK_ABSTRACT (block) && immediate_origin == block) | |
4201 | return NULL_TREE; | |
4202 | ||
3f76745e JM |
4203 | if (immediate_origin == NULL_TREE) |
4204 | return NULL_TREE; | |
4205 | else | |
4206 | { | |
4207 | register tree ret_val; | |
4208 | register tree lookahead = immediate_origin; | |
71dfc51f | 4209 | |
3f76745e JM |
4210 | do |
4211 | { | |
4212 | ret_val = lookahead; | |
4213 | lookahead = (TREE_CODE (ret_val) == BLOCK) | |
4214 | ? BLOCK_ABSTRACT_ORIGIN (ret_val) | |
4215 | : NULL; | |
4216 | } | |
4217 | while (lookahead != NULL && lookahead != ret_val); | |
4218 | ||
4219 | return ret_val; | |
4220 | } | |
a3f97cbb JW |
4221 | } |
4222 | ||
3f76745e JM |
4223 | /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT |
4224 | of a virtual function may refer to a base class, so we check the 'this' | |
4225 | parameter. */ | |
71dfc51f | 4226 | |
3f76745e JM |
4227 | static tree |
4228 | decl_class_context (decl) | |
4229 | tree decl; | |
a3f97cbb | 4230 | { |
3f76745e | 4231 | tree context = NULL_TREE; |
71dfc51f | 4232 | |
3f76745e JM |
4233 | if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl)) |
4234 | context = DECL_CONTEXT (decl); | |
4235 | else | |
4236 | context = TYPE_MAIN_VARIANT | |
4237 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
71dfc51f | 4238 | |
2f939d94 | 4239 | if (context && !TYPE_P (context)) |
3f76745e JM |
4240 | context = NULL_TREE; |
4241 | ||
4242 | return context; | |
a3f97cbb JW |
4243 | } |
4244 | \f | |
a96c67ec | 4245 | /* Add an attribute/value pair to a DIE. We build the lists up in reverse |
881c6935 | 4246 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f RK |
4247 | |
4248 | static inline void | |
3f76745e JM |
4249 | add_dwarf_attr (die, attr) |
4250 | register dw_die_ref die; | |
4251 | register dw_attr_ref attr; | |
a3f97cbb | 4252 | { |
3f76745e | 4253 | if (die != NULL && attr != NULL) |
a3f97cbb | 4254 | { |
a96c67ec JM |
4255 | attr->dw_attr_next = die->die_attr; |
4256 | die->die_attr = attr; | |
a3f97cbb JW |
4257 | } |
4258 | } | |
4259 | ||
c6991660 | 4260 | static inline dw_val_class AT_class PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4261 | static inline dw_val_class |
4262 | AT_class (a) | |
4263 | dw_attr_ref a; | |
4264 | { | |
4265 | return a->dw_attr_val.val_class; | |
4266 | } | |
4267 | ||
3f76745e | 4268 | /* Add a flag value attribute to a DIE. */ |
71dfc51f | 4269 | |
3f76745e JM |
4270 | static inline void |
4271 | add_AT_flag (die, attr_kind, flag) | |
4272 | register dw_die_ref die; | |
4273 | register enum dwarf_attribute attr_kind; | |
4274 | register unsigned flag; | |
a3f97cbb | 4275 | { |
3f76745e | 4276 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4277 | |
3f76745e JM |
4278 | attr->dw_attr_next = NULL; |
4279 | attr->dw_attr = attr_kind; | |
4280 | attr->dw_attr_val.val_class = dw_val_class_flag; | |
4281 | attr->dw_attr_val.v.val_flag = flag; | |
4282 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4283 | } |
4284 | ||
c6991660 | 4285 | static inline unsigned AT_flag PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4286 | static inline unsigned |
4287 | AT_flag (a) | |
4288 | register dw_attr_ref a; | |
4289 | { | |
4290 | if (a && AT_class (a) == dw_val_class_flag) | |
4291 | return a->dw_attr_val.v.val_flag; | |
4292 | ||
40e8cc95 | 4293 | abort (); |
a96c67ec JM |
4294 | } |
4295 | ||
3f76745e | 4296 | /* Add a signed integer attribute value to a DIE. */ |
71dfc51f | 4297 | |
3f76745e JM |
4298 | static inline void |
4299 | add_AT_int (die, attr_kind, int_val) | |
4300 | register dw_die_ref die; | |
4301 | register enum dwarf_attribute attr_kind; | |
4302 | register long int int_val; | |
a3f97cbb | 4303 | { |
3f76745e JM |
4304 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
4305 | ||
4306 | attr->dw_attr_next = NULL; | |
4307 | attr->dw_attr = attr_kind; | |
4308 | attr->dw_attr_val.val_class = dw_val_class_const; | |
4309 | attr->dw_attr_val.v.val_int = int_val; | |
4310 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4311 | } |
4312 | ||
c6991660 | 4313 | static inline long int AT_int PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4314 | static inline long int |
4315 | AT_int (a) | |
4316 | register dw_attr_ref a; | |
4317 | { | |
4318 | if (a && AT_class (a) == dw_val_class_const) | |
4319 | return a->dw_attr_val.v.val_int; | |
4320 | ||
40e8cc95 | 4321 | abort (); |
a96c67ec JM |
4322 | } |
4323 | ||
3f76745e | 4324 | /* Add an unsigned integer attribute value to a DIE. */ |
71dfc51f | 4325 | |
3f76745e JM |
4326 | static inline void |
4327 | add_AT_unsigned (die, attr_kind, unsigned_val) | |
4328 | register dw_die_ref die; | |
4329 | register enum dwarf_attribute attr_kind; | |
4330 | register unsigned long unsigned_val; | |
a3f97cbb | 4331 | { |
3f76745e JM |
4332 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
4333 | ||
4334 | attr->dw_attr_next = NULL; | |
4335 | attr->dw_attr = attr_kind; | |
4336 | attr->dw_attr_val.val_class = dw_val_class_unsigned_const; | |
4337 | attr->dw_attr_val.v.val_unsigned = unsigned_val; | |
4338 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4339 | } |
71dfc51f | 4340 | |
c6991660 | 4341 | static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4342 | static inline unsigned long |
4343 | AT_unsigned (a) | |
4344 | register dw_attr_ref a; | |
4345 | { | |
4346 | if (a && AT_class (a) == dw_val_class_unsigned_const) | |
4347 | return a->dw_attr_val.v.val_unsigned; | |
4348 | ||
40e8cc95 | 4349 | abort (); |
a96c67ec JM |
4350 | } |
4351 | ||
3f76745e JM |
4352 | /* Add an unsigned double integer attribute value to a DIE. */ |
4353 | ||
4354 | static inline void | |
4355 | add_AT_long_long (die, attr_kind, val_hi, val_low) | |
a3f97cbb | 4356 | register dw_die_ref die; |
3f76745e JM |
4357 | register enum dwarf_attribute attr_kind; |
4358 | register unsigned long val_hi; | |
4359 | register unsigned long val_low; | |
a3f97cbb | 4360 | { |
3f76745e | 4361 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4362 | |
3f76745e JM |
4363 | attr->dw_attr_next = NULL; |
4364 | attr->dw_attr = attr_kind; | |
4365 | attr->dw_attr_val.val_class = dw_val_class_long_long; | |
4366 | attr->dw_attr_val.v.val_long_long.hi = val_hi; | |
4367 | attr->dw_attr_val.v.val_long_long.low = val_low; | |
4368 | add_dwarf_attr (die, attr); | |
4369 | } | |
71dfc51f | 4370 | |
3f76745e | 4371 | /* Add a floating point attribute value to a DIE and return it. */ |
71dfc51f | 4372 | |
3f76745e JM |
4373 | static inline void |
4374 | add_AT_float (die, attr_kind, length, array) | |
4375 | register dw_die_ref die; | |
4376 | register enum dwarf_attribute attr_kind; | |
4377 | register unsigned length; | |
4378 | register long *array; | |
4379 | { | |
4380 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
4381 | ||
4382 | attr->dw_attr_next = NULL; | |
4383 | attr->dw_attr = attr_kind; | |
4384 | attr->dw_attr_val.val_class = dw_val_class_float; | |
4385 | attr->dw_attr_val.v.val_float.length = length; | |
4386 | attr->dw_attr_val.v.val_float.array = array; | |
4387 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4388 | } |
4389 | ||
3f76745e | 4390 | /* Add a string attribute value to a DIE. */ |
71dfc51f | 4391 | |
3f76745e JM |
4392 | static inline void |
4393 | add_AT_string (die, attr_kind, str) | |
a3f97cbb | 4394 | register dw_die_ref die; |
3f76745e | 4395 | register enum dwarf_attribute attr_kind; |
d560ee52 | 4396 | register const char *str; |
a3f97cbb | 4397 | { |
3f76745e | 4398 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4399 | |
3f76745e JM |
4400 | attr->dw_attr_next = NULL; |
4401 | attr->dw_attr = attr_kind; | |
4402 | attr->dw_attr_val.val_class = dw_val_class_str; | |
4403 | attr->dw_attr_val.v.val_str = xstrdup (str); | |
4404 | add_dwarf_attr (die, attr); | |
4405 | } | |
71dfc51f | 4406 | |
c6991660 | 4407 | static inline const char *AT_string PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4408 | static inline const char * |
4409 | AT_string (a) | |
4410 | register dw_attr_ref a; | |
4411 | { | |
4412 | if (a && AT_class (a) == dw_val_class_str) | |
4413 | return a->dw_attr_val.v.val_str; | |
4414 | ||
40e8cc95 | 4415 | abort (); |
a96c67ec JM |
4416 | } |
4417 | ||
3f76745e | 4418 | /* Add a DIE reference attribute value to a DIE. */ |
71dfc51f | 4419 | |
3f76745e JM |
4420 | static inline void |
4421 | add_AT_die_ref (die, attr_kind, targ_die) | |
4422 | register dw_die_ref die; | |
4423 | register enum dwarf_attribute attr_kind; | |
4424 | register dw_die_ref targ_die; | |
4425 | { | |
4426 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 4427 | |
3f76745e JM |
4428 | attr->dw_attr_next = NULL; |
4429 | attr->dw_attr = attr_kind; | |
4430 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
881c6935 JM |
4431 | attr->dw_attr_val.v.val_die_ref.die = targ_die; |
4432 | attr->dw_attr_val.v.val_die_ref.external = 0; | |
3f76745e JM |
4433 | add_dwarf_attr (die, attr); |
4434 | } | |
b1ccbc24 | 4435 | |
c6991660 | 4436 | static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4437 | static inline dw_die_ref |
4438 | AT_ref (a) | |
4439 | register dw_attr_ref a; | |
4440 | { | |
4441 | if (a && AT_class (a) == dw_val_class_die_ref) | |
881c6935 | 4442 | return a->dw_attr_val.v.val_die_ref.die; |
a96c67ec | 4443 | |
40e8cc95 | 4444 | abort (); |
a96c67ec JM |
4445 | } |
4446 | ||
881c6935 JM |
4447 | static inline int AT_ref_external PARAMS ((dw_attr_ref)); |
4448 | static inline int | |
4449 | AT_ref_external (a) | |
4450 | register dw_attr_ref a; | |
4451 | { | |
4452 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4453 | return a->dw_attr_val.v.val_die_ref.external; | |
4454 | ||
4455 | return 0; | |
4456 | } | |
4457 | ||
4458 | static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int)); | |
4459 | static inline void | |
4460 | set_AT_ref_external (a, i) | |
4461 | register dw_attr_ref a; | |
4462 | int i; | |
4463 | { | |
4464 | if (a && AT_class (a) == dw_val_class_die_ref) | |
4465 | a->dw_attr_val.v.val_die_ref.external = i; | |
4466 | else | |
4467 | abort (); | |
4468 | } | |
4469 | ||
3f76745e | 4470 | /* Add an FDE reference attribute value to a DIE. */ |
b1ccbc24 | 4471 | |
3f76745e JM |
4472 | static inline void |
4473 | add_AT_fde_ref (die, attr_kind, targ_fde) | |
4474 | register dw_die_ref die; | |
4475 | register enum dwarf_attribute attr_kind; | |
4476 | register unsigned targ_fde; | |
4477 | { | |
4478 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
b1ccbc24 | 4479 | |
3f76745e JM |
4480 | attr->dw_attr_next = NULL; |
4481 | attr->dw_attr = attr_kind; | |
4482 | attr->dw_attr_val.val_class = dw_val_class_fde_ref; | |
4483 | attr->dw_attr_val.v.val_fde_index = targ_fde; | |
4484 | add_dwarf_attr (die, attr); | |
a3f97cbb | 4485 | } |
71dfc51f | 4486 | |
3f76745e | 4487 | /* Add a location description attribute value to a DIE. */ |
71dfc51f | 4488 | |
3f76745e JM |
4489 | static inline void |
4490 | add_AT_loc (die, attr_kind, loc) | |
4491 | register dw_die_ref die; | |
4492 | register enum dwarf_attribute attr_kind; | |
4493 | register dw_loc_descr_ref loc; | |
4494 | { | |
4495 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 4496 | |
3f76745e JM |
4497 | attr->dw_attr_next = NULL; |
4498 | attr->dw_attr = attr_kind; | |
4499 | attr->dw_attr_val.val_class = dw_val_class_loc; | |
4500 | attr->dw_attr_val.v.val_loc = loc; | |
4501 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4502 | } |
4503 | ||
c6991660 | 4504 | static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4505 | static inline dw_loc_descr_ref |
4506 | AT_loc (a) | |
4507 | register dw_attr_ref a; | |
4508 | { | |
4509 | if (a && AT_class (a) == dw_val_class_loc) | |
4510 | return a->dw_attr_val.v.val_loc; | |
4511 | ||
40e8cc95 | 4512 | abort (); |
a96c67ec JM |
4513 | } |
4514 | ||
63e46568 DB |
4515 | static inline void |
4516 | add_AT_loc_list (die, attr_kind, loc_list) | |
4517 | register dw_die_ref die; | |
4518 | register enum dwarf_attribute attr_kind; | |
4519 | register dw_loc_list_ref loc_list; | |
4520 | { | |
4521 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
4522 | ||
4523 | attr->dw_attr_next = NULL; | |
4524 | attr->dw_attr = attr_kind; | |
4525 | attr->dw_attr_val.val_class = dw_val_class_loc_list; | |
4526 | attr->dw_attr_val.v.val_loc_list = loc_list; | |
4527 | add_dwarf_attr (die, attr); | |
4528 | have_location_lists = 1; | |
4529 | } | |
4530 | ||
4531 | static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref)); | |
4532 | ||
4533 | static inline dw_loc_list_ref | |
4534 | AT_loc_list (a) | |
4535 | register dw_attr_ref a; | |
4536 | { | |
4537 | if (a && AT_class (a) == dw_val_class_loc_list) | |
4538 | return a->dw_attr_val.v.val_loc_list; | |
4539 | ||
4540 | abort (); | |
4541 | } | |
4542 | ||
3f76745e | 4543 | /* Add an address constant attribute value to a DIE. */ |
71dfc51f | 4544 | |
3f76745e JM |
4545 | static inline void |
4546 | add_AT_addr (die, attr_kind, addr) | |
4547 | register dw_die_ref die; | |
4548 | register enum dwarf_attribute attr_kind; | |
1865dbb5 | 4549 | rtx addr; |
a3f97cbb | 4550 | { |
3f76745e | 4551 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4552 | |
3f76745e JM |
4553 | attr->dw_attr_next = NULL; |
4554 | attr->dw_attr = attr_kind; | |
4555 | attr->dw_attr_val.val_class = dw_val_class_addr; | |
4556 | attr->dw_attr_val.v.val_addr = addr; | |
4557 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
4558 | } |
4559 | ||
c6991660 | 4560 | static inline rtx AT_addr PARAMS ((dw_attr_ref)); |
1865dbb5 | 4561 | static inline rtx |
a96c67ec JM |
4562 | AT_addr (a) |
4563 | register dw_attr_ref a; | |
4564 | { | |
4565 | if (a && AT_class (a) == dw_val_class_addr) | |
4566 | return a->dw_attr_val.v.val_addr; | |
4567 | ||
40e8cc95 | 4568 | abort (); |
a96c67ec JM |
4569 | } |
4570 | ||
3f76745e | 4571 | /* Add a label identifier attribute value to a DIE. */ |
71dfc51f | 4572 | |
3f76745e JM |
4573 | static inline void |
4574 | add_AT_lbl_id (die, attr_kind, lbl_id) | |
4575 | register dw_die_ref die; | |
4576 | register enum dwarf_attribute attr_kind; | |
d3e3972c | 4577 | register const char *lbl_id; |
a3f97cbb | 4578 | { |
3f76745e | 4579 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 4580 | |
3f76745e JM |
4581 | attr->dw_attr_next = NULL; |
4582 | attr->dw_attr = attr_kind; | |
4583 | attr->dw_attr_val.val_class = dw_val_class_lbl_id; | |
4584 | attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); | |
4585 | add_dwarf_attr (die, attr); | |
4586 | } | |
71dfc51f | 4587 | |
3f76745e JM |
4588 | /* Add a section offset attribute value to a DIE. */ |
4589 | ||
4590 | static inline void | |
8b790721 | 4591 | add_AT_lbl_offset (die, attr_kind, label) |
3f76745e JM |
4592 | register dw_die_ref die; |
4593 | register enum dwarf_attribute attr_kind; | |
d3e3972c | 4594 | register const char *label; |
3f76745e JM |
4595 | { |
4596 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 4597 | |
3f76745e JM |
4598 | attr->dw_attr_next = NULL; |
4599 | attr->dw_attr = attr_kind; | |
8b790721 | 4600 | attr->dw_attr_val.val_class = dw_val_class_lbl_offset; |
a96c67ec | 4601 | attr->dw_attr_val.v.val_lbl_id = xstrdup (label); |
3f76745e | 4602 | add_dwarf_attr (die, attr); |
a3f97cbb JW |
4603 | } |
4604 | ||
c6991660 | 4605 | static inline const char *AT_lbl PARAMS ((dw_attr_ref)); |
a96c67ec JM |
4606 | static inline const char * |
4607 | AT_lbl (a) | |
4608 | register dw_attr_ref a; | |
a3f97cbb | 4609 | { |
a96c67ec JM |
4610 | if (a && (AT_class (a) == dw_val_class_lbl_id |
4611 | || AT_class (a) == dw_val_class_lbl_offset)) | |
4612 | return a->dw_attr_val.v.val_lbl_id; | |
71dfc51f | 4613 | |
40e8cc95 | 4614 | abort (); |
a3f97cbb JW |
4615 | } |
4616 | ||
3f76745e | 4617 | /* Get the attribute of type attr_kind. */ |
71dfc51f | 4618 | |
3f76745e JM |
4619 | static inline dw_attr_ref |
4620 | get_AT (die, attr_kind) | |
4621 | register dw_die_ref die; | |
4622 | register enum dwarf_attribute attr_kind; | |
f37230f0 | 4623 | { |
3f76745e JM |
4624 | register dw_attr_ref a; |
4625 | register dw_die_ref spec = NULL; | |
556273e0 | 4626 | |
3f76745e JM |
4627 | if (die != NULL) |
4628 | { | |
4629 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
4630 | { | |
4631 | if (a->dw_attr == attr_kind) | |
4632 | return a; | |
71dfc51f | 4633 | |
3f76745e JM |
4634 | if (a->dw_attr == DW_AT_specification |
4635 | || a->dw_attr == DW_AT_abstract_origin) | |
a96c67ec | 4636 | spec = AT_ref (a); |
3f76745e | 4637 | } |
71dfc51f | 4638 | |
3f76745e JM |
4639 | if (spec) |
4640 | return get_AT (spec, attr_kind); | |
4641 | } | |
4642 | ||
4643 | return NULL; | |
f37230f0 JM |
4644 | } |
4645 | ||
3f76745e JM |
4646 | /* Return the "low pc" attribute value, typically associated with |
4647 | a subprogram DIE. Return null if the "low pc" attribute is | |
4648 | either not prsent, or if it cannot be represented as an | |
4649 | assembler label identifier. */ | |
71dfc51f | 4650 | |
a96c67ec | 4651 | static inline const char * |
3f76745e JM |
4652 | get_AT_low_pc (die) |
4653 | register dw_die_ref die; | |
7e23cb16 | 4654 | { |
3f76745e | 4655 | register dw_attr_ref a = get_AT (die, DW_AT_low_pc); |
40e8cc95 | 4656 | return a ? AT_lbl (a) : NULL; |
7e23cb16 JM |
4657 | } |
4658 | ||
3f76745e JM |
4659 | /* Return the "high pc" attribute value, typically associated with |
4660 | a subprogram DIE. Return null if the "high pc" attribute is | |
4661 | either not prsent, or if it cannot be represented as an | |
4662 | assembler label identifier. */ | |
71dfc51f | 4663 | |
a96c67ec | 4664 | static inline const char * |
3f76745e | 4665 | get_AT_hi_pc (die) |
a3f97cbb JW |
4666 | register dw_die_ref die; |
4667 | { | |
3f76745e | 4668 | register dw_attr_ref a = get_AT (die, DW_AT_high_pc); |
40e8cc95 | 4669 | return a ? AT_lbl (a) : NULL; |
3f76745e JM |
4670 | } |
4671 | ||
4672 | /* Return the value of the string attribute designated by ATTR_KIND, or | |
4673 | NULL if it is not present. */ | |
71dfc51f | 4674 | |
a96c67ec | 4675 | static inline const char * |
3f76745e JM |
4676 | get_AT_string (die, attr_kind) |
4677 | register dw_die_ref die; | |
4678 | register enum dwarf_attribute attr_kind; | |
4679 | { | |
4680 | register dw_attr_ref a = get_AT (die, attr_kind); | |
40e8cc95 | 4681 | return a ? AT_string (a) : NULL; |
a3f97cbb JW |
4682 | } |
4683 | ||
3f76745e JM |
4684 | /* Return the value of the flag attribute designated by ATTR_KIND, or -1 |
4685 | if it is not present. */ | |
71dfc51f | 4686 | |
3f76745e JM |
4687 | static inline int |
4688 | get_AT_flag (die, attr_kind) | |
4689 | register dw_die_ref die; | |
4690 | register enum dwarf_attribute attr_kind; | |
a3f97cbb | 4691 | { |
3f76745e | 4692 | register dw_attr_ref a = get_AT (die, attr_kind); |
40e8cc95 | 4693 | return a ? AT_flag (a) : 0; |
a3f97cbb JW |
4694 | } |
4695 | ||
3f76745e JM |
4696 | /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0 |
4697 | if it is not present. */ | |
71dfc51f | 4698 | |
3f76745e JM |
4699 | static inline unsigned |
4700 | get_AT_unsigned (die, attr_kind) | |
4701 | register dw_die_ref die; | |
4702 | register enum dwarf_attribute attr_kind; | |
a3f97cbb | 4703 | { |
3f76745e | 4704 | register dw_attr_ref a = get_AT (die, attr_kind); |
40e8cc95 | 4705 | return a ? AT_unsigned (a) : 0; |
a96c67ec | 4706 | } |
71dfc51f | 4707 | |
a96c67ec JM |
4708 | static inline dw_die_ref |
4709 | get_AT_ref (die, attr_kind) | |
4710 | dw_die_ref die; | |
4711 | register enum dwarf_attribute attr_kind; | |
4712 | { | |
4713 | register dw_attr_ref a = get_AT (die, attr_kind); | |
40e8cc95 | 4714 | return a ? AT_ref (a) : NULL; |
3f76745e | 4715 | } |
71dfc51f | 4716 | |
3f76745e JM |
4717 | static inline int |
4718 | is_c_family () | |
4719 | { | |
4720 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
71dfc51f | 4721 | |
3f76745e JM |
4722 | return (lang == DW_LANG_C || lang == DW_LANG_C89 |
4723 | || lang == DW_LANG_C_plus_plus); | |
556273e0 | 4724 | } |
71dfc51f | 4725 | |
3f76745e JM |
4726 | static inline int |
4727 | is_fortran () | |
4728 | { | |
4729 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
71dfc51f | 4730 | |
3f76745e | 4731 | return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90); |
556273e0 | 4732 | } |
71dfc51f | 4733 | |
28985b81 AG |
4734 | static inline int |
4735 | is_java () | |
4736 | { | |
4737 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
4738 | ||
4739 | return (lang == DW_LANG_Java); | |
4740 | } | |
4741 | ||
10a11b75 | 4742 | /* Free up the memory used by A. */ |
71dfc51f | 4743 | |
c6991660 | 4744 | static inline void free_AT PARAMS ((dw_attr_ref)); |
3f76745e | 4745 | static inline void |
10a11b75 JM |
4746 | free_AT (a) |
4747 | dw_attr_ref a; | |
4748 | { | |
4749 | switch (AT_class (a)) | |
4750 | { | |
10a11b75 JM |
4751 | case dw_val_class_str: |
4752 | case dw_val_class_lbl_id: | |
4753 | case dw_val_class_lbl_offset: | |
4754 | free (a->dw_attr_val.v.val_str); | |
4755 | break; | |
4756 | ||
3724ec07 WC |
4757 | case dw_val_class_float: |
4758 | free (a->dw_attr_val.v.val_float.array); | |
4759 | break; | |
0b34cf1e | 4760 | |
10a11b75 JM |
4761 | default: |
4762 | break; | |
4763 | } | |
4764 | ||
4765 | free (a); | |
556273e0 | 4766 | } |
10a11b75 JM |
4767 | |
4768 | /* Remove the specified attribute if present. */ | |
4769 | ||
4770 | static void | |
3f76745e JM |
4771 | remove_AT (die, attr_kind) |
4772 | register dw_die_ref die; | |
4773 | register enum dwarf_attribute attr_kind; | |
4774 | { | |
a96c67ec | 4775 | register dw_attr_ref *p; |
6d649d26 | 4776 | register dw_attr_ref removed = NULL; |
a3f97cbb | 4777 | |
3f76745e JM |
4778 | if (die != NULL) |
4779 | { | |
a96c67ec JM |
4780 | for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next)) |
4781 | if ((*p)->dw_attr == attr_kind) | |
4782 | { | |
4783 | removed = *p; | |
4784 | *p = (*p)->dw_attr_next; | |
4785 | break; | |
4786 | } | |
71dfc51f | 4787 | |
a96c67ec | 4788 | if (removed != 0) |
10a11b75 JM |
4789 | free_AT (removed); |
4790 | } | |
4791 | } | |
71dfc51f | 4792 | |
10a11b75 | 4793 | /* Free up the memory used by DIE. */ |
71dfc51f | 4794 | |
c6991660 | 4795 | static inline void free_die PARAMS ((dw_die_ref)); |
10a11b75 JM |
4796 | static inline void |
4797 | free_die (die) | |
4798 | dw_die_ref die; | |
4799 | { | |
4800 | remove_children (die); | |
4801 | free (die); | |
3f76745e | 4802 | } |
71dfc51f | 4803 | |
3f76745e | 4804 | /* Discard the children of this DIE. */ |
71dfc51f | 4805 | |
10a11b75 | 4806 | static void |
3f76745e JM |
4807 | remove_children (die) |
4808 | register dw_die_ref die; | |
4809 | { | |
4810 | register dw_die_ref child_die = die->die_child; | |
4811 | ||
4812 | die->die_child = NULL; | |
3f76745e JM |
4813 | |
4814 | while (child_die != NULL) | |
a3f97cbb | 4815 | { |
3f76745e JM |
4816 | register dw_die_ref tmp_die = child_die; |
4817 | register dw_attr_ref a; | |
71dfc51f | 4818 | |
3f76745e | 4819 | child_die = child_die->die_sib; |
556273e0 KH |
4820 | |
4821 | for (a = tmp_die->die_attr; a != NULL;) | |
a3f97cbb | 4822 | { |
3f76745e | 4823 | register dw_attr_ref tmp_a = a; |
71dfc51f | 4824 | |
3f76745e | 4825 | a = a->dw_attr_next; |
10a11b75 | 4826 | free_AT (tmp_a); |
a3f97cbb | 4827 | } |
71dfc51f | 4828 | |
10a11b75 | 4829 | free_die (tmp_die); |
3f76745e JM |
4830 | } |
4831 | } | |
71dfc51f | 4832 | |
a96c67ec | 4833 | /* Add a child DIE below its parent. We build the lists up in reverse |
881c6935 | 4834 | addition order, and correct that in reverse_all_dies. */ |
71dfc51f | 4835 | |
3f76745e JM |
4836 | static inline void |
4837 | add_child_die (die, child_die) | |
4838 | register dw_die_ref die; | |
4839 | register dw_die_ref child_die; | |
4840 | { | |
4841 | if (die != NULL && child_die != NULL) | |
e90b62db | 4842 | { |
3a88cbd1 JL |
4843 | if (die == child_die) |
4844 | abort (); | |
3f76745e | 4845 | child_die->die_parent = die; |
a96c67ec JM |
4846 | child_die->die_sib = die->die_child; |
4847 | die->die_child = child_die; | |
3f76745e JM |
4848 | } |
4849 | } | |
4850 | ||
2081603c JM |
4851 | /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT |
4852 | is the specification, to the front of PARENT's list of children. */ | |
10a11b75 JM |
4853 | |
4854 | static void | |
4855 | splice_child_die (parent, child) | |
4856 | dw_die_ref parent, child; | |
4857 | { | |
4858 | dw_die_ref *p; | |
4859 | ||
4860 | /* We want the declaration DIE from inside the class, not the | |
4861 | specification DIE at toplevel. */ | |
4862 | if (child->die_parent != parent) | |
2081603c JM |
4863 | { |
4864 | dw_die_ref tmp = get_AT_ref (child, DW_AT_specification); | |
4865 | if (tmp) | |
4866 | child = tmp; | |
4867 | } | |
10a11b75 | 4868 | |
2081603c JM |
4869 | if (child->die_parent != parent |
4870 | && child->die_parent != get_AT_ref (parent, DW_AT_specification)) | |
10a11b75 JM |
4871 | abort (); |
4872 | ||
5de0e8d4 | 4873 | for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib)) |
10a11b75 JM |
4874 | if (*p == child) |
4875 | { | |
4876 | *p = child->die_sib; | |
4877 | break; | |
4878 | } | |
4879 | ||
4880 | child->die_sib = parent->die_child; | |
4881 | parent->die_child = child; | |
4882 | } | |
4883 | ||
3f76745e JM |
4884 | /* Return a pointer to a newly created DIE node. */ |
4885 | ||
4886 | static inline dw_die_ref | |
4887 | new_die (tag_value, parent_die) | |
4888 | register enum dwarf_tag tag_value; | |
4889 | register dw_die_ref parent_die; | |
4890 | { | |
3f4907a6 | 4891 | register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node)); |
3f76745e JM |
4892 | |
4893 | die->die_tag = tag_value; | |
3f76745e JM |
4894 | |
4895 | if (parent_die != NULL) | |
4896 | add_child_die (parent_die, die); | |
4897 | else | |
ef76d03b JW |
4898 | { |
4899 | limbo_die_node *limbo_node; | |
4900 | ||
4901 | limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node)); | |
4902 | limbo_node->die = die; | |
4903 | limbo_node->next = limbo_die_list; | |
4904 | limbo_die_list = limbo_node; | |
4905 | } | |
71dfc51f | 4906 | |
3f76745e JM |
4907 | return die; |
4908 | } | |
71dfc51f | 4909 | |
3f76745e | 4910 | /* Return the DIE associated with the given type specifier. */ |
71dfc51f | 4911 | |
3f76745e JM |
4912 | static inline dw_die_ref |
4913 | lookup_type_die (type) | |
4914 | register tree type; | |
4915 | { | |
4061f623 BS |
4916 | if (TREE_CODE (type) == VECTOR_TYPE) |
4917 | type = TYPE_DEBUG_REPRESENTATION_TYPE (type); | |
3f76745e JM |
4918 | return (dw_die_ref) TYPE_SYMTAB_POINTER (type); |
4919 | } | |
e90b62db | 4920 | |
3f76745e | 4921 | /* Equate a DIE to a given type specifier. */ |
71dfc51f | 4922 | |
10a11b75 | 4923 | static inline void |
3f76745e JM |
4924 | equate_type_number_to_die (type, type_die) |
4925 | register tree type; | |
4926 | register dw_die_ref type_die; | |
4927 | { | |
4928 | TYPE_SYMTAB_POINTER (type) = (char *) type_die; | |
4929 | } | |
71dfc51f | 4930 | |
3f76745e | 4931 | /* Return the DIE associated with a given declaration. */ |
71dfc51f | 4932 | |
3f76745e JM |
4933 | static inline dw_die_ref |
4934 | lookup_decl_die (decl) | |
4935 | register tree decl; | |
4936 | { | |
4937 | register unsigned decl_id = DECL_UID (decl); | |
4938 | ||
4939 | return (decl_id < decl_die_table_in_use | |
4940 | ? decl_die_table[decl_id] : NULL); | |
a3f97cbb JW |
4941 | } |
4942 | ||
3f76745e | 4943 | /* Equate a DIE to a particular declaration. */ |
71dfc51f | 4944 | |
3f76745e JM |
4945 | static void |
4946 | equate_decl_number_to_die (decl, decl_die) | |
4947 | register tree decl; | |
4948 | register dw_die_ref decl_die; | |
a3f97cbb | 4949 | { |
3f76745e | 4950 | register unsigned decl_id = DECL_UID (decl); |
3f76745e | 4951 | register unsigned num_allocated; |
d291dd49 | 4952 | |
3f76745e | 4953 | if (decl_id >= decl_die_table_allocated) |
a3f97cbb | 4954 | { |
3f76745e JM |
4955 | num_allocated |
4956 | = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1) | |
4957 | / DECL_DIE_TABLE_INCREMENT) | |
4958 | * DECL_DIE_TABLE_INCREMENT; | |
4959 | ||
4960 | decl_die_table | |
4961 | = (dw_die_ref *) xrealloc (decl_die_table, | |
4962 | sizeof (dw_die_ref) * num_allocated); | |
4963 | ||
961192e1 | 4964 | memset ((char *) &decl_die_table[decl_die_table_allocated], 0, |
3f76745e JM |
4965 | (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref)); |
4966 | decl_die_table_allocated = num_allocated; | |
a3f97cbb | 4967 | } |
71dfc51f | 4968 | |
3f76745e JM |
4969 | if (decl_id >= decl_die_table_in_use) |
4970 | decl_die_table_in_use = (decl_id + 1); | |
4971 | ||
4972 | decl_die_table[decl_id] = decl_die; | |
a3f97cbb | 4973 | } |
3f76745e JM |
4974 | \f |
4975 | /* Keep track of the number of spaces used to indent the | |
4976 | output of the debugging routines that print the structure of | |
4977 | the DIE internal representation. */ | |
4978 | static int print_indent; | |
71dfc51f | 4979 | |
3f76745e JM |
4980 | /* Indent the line the number of spaces given by print_indent. */ |
4981 | ||
4982 | static inline void | |
4983 | print_spaces (outfile) | |
4984 | FILE *outfile; | |
4985 | { | |
4986 | fprintf (outfile, "%*s", print_indent, ""); | |
a3f97cbb JW |
4987 | } |
4988 | ||
956d6950 | 4989 | /* Print the information associated with a given DIE, and its children. |
3f76745e | 4990 | This routine is a debugging aid only. */ |
71dfc51f | 4991 | |
a3f97cbb | 4992 | static void |
3f76745e JM |
4993 | print_die (die, outfile) |
4994 | dw_die_ref die; | |
4995 | FILE *outfile; | |
a3f97cbb | 4996 | { |
3f76745e JM |
4997 | register dw_attr_ref a; |
4998 | register dw_die_ref c; | |
71dfc51f | 4999 | |
3f76745e | 5000 | print_spaces (outfile); |
2d8b0f3a | 5001 | fprintf (outfile, "DIE %4lu: %s\n", |
3f76745e JM |
5002 | die->die_offset, dwarf_tag_name (die->die_tag)); |
5003 | print_spaces (outfile); | |
2d8b0f3a JL |
5004 | fprintf (outfile, " abbrev id: %lu", die->die_abbrev); |
5005 | fprintf (outfile, " offset: %lu\n", die->die_offset); | |
3f76745e JM |
5006 | |
5007 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
a3f97cbb | 5008 | { |
3f76745e JM |
5009 | print_spaces (outfile); |
5010 | fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr)); | |
5011 | ||
a96c67ec | 5012 | switch (AT_class (a)) |
3f76745e JM |
5013 | { |
5014 | case dw_val_class_addr: | |
5015 | fprintf (outfile, "address"); | |
5016 | break; | |
5017 | case dw_val_class_loc: | |
5018 | fprintf (outfile, "location descriptor"); | |
5019 | break; | |
63e46568 DB |
5020 | case dw_val_class_loc_list: |
5021 | fprintf (outfile, "location list -> label:%s", AT_loc_list (a)->ll_symbol); | |
5022 | break; | |
3f76745e | 5023 | case dw_val_class_const: |
a96c67ec | 5024 | fprintf (outfile, "%ld", AT_int (a)); |
3f76745e JM |
5025 | break; |
5026 | case dw_val_class_unsigned_const: | |
a96c67ec | 5027 | fprintf (outfile, "%lu", AT_unsigned (a)); |
3f76745e JM |
5028 | break; |
5029 | case dw_val_class_long_long: | |
2d8b0f3a | 5030 | fprintf (outfile, "constant (%lu,%lu)", |
556273e0 KH |
5031 | a->dw_attr_val.v.val_long_long.hi, |
5032 | a->dw_attr_val.v.val_long_long.low); | |
3f76745e JM |
5033 | break; |
5034 | case dw_val_class_float: | |
5035 | fprintf (outfile, "floating-point constant"); | |
5036 | break; | |
5037 | case dw_val_class_flag: | |
a96c67ec | 5038 | fprintf (outfile, "%u", AT_flag (a)); |
3f76745e JM |
5039 | break; |
5040 | case dw_val_class_die_ref: | |
a96c67ec | 5041 | if (AT_ref (a) != NULL) |
881c6935 | 5042 | { |
1bfb5f8f | 5043 | if (AT_ref (a)->die_symbol) |
881c6935 JM |
5044 | fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol); |
5045 | else | |
5046 | fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset); | |
5047 | } | |
3f76745e JM |
5048 | else |
5049 | fprintf (outfile, "die -> <null>"); | |
5050 | break; | |
5051 | case dw_val_class_lbl_id: | |
8b790721 | 5052 | case dw_val_class_lbl_offset: |
a96c67ec | 5053 | fprintf (outfile, "label: %s", AT_lbl (a)); |
3f76745e | 5054 | break; |
3f76745e | 5055 | case dw_val_class_str: |
a96c67ec JM |
5056 | if (AT_string (a) != NULL) |
5057 | fprintf (outfile, "\"%s\"", AT_string (a)); | |
3f76745e JM |
5058 | else |
5059 | fprintf (outfile, "<null>"); | |
5060 | break; | |
e9a25f70 JL |
5061 | default: |
5062 | break; | |
3f76745e JM |
5063 | } |
5064 | ||
5065 | fprintf (outfile, "\n"); | |
5066 | } | |
5067 | ||
5068 | if (die->die_child != NULL) | |
5069 | { | |
5070 | print_indent += 4; | |
5071 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5072 | print_die (c, outfile); | |
71dfc51f | 5073 | |
3f76745e | 5074 | print_indent -= 4; |
a3f97cbb | 5075 | } |
881c6935 JM |
5076 | if (print_indent == 0) |
5077 | fprintf (outfile, "\n"); | |
a3f97cbb JW |
5078 | } |
5079 | ||
3f76745e JM |
5080 | /* Print the contents of the source code line number correspondence table. |
5081 | This routine is a debugging aid only. */ | |
71dfc51f | 5082 | |
3f76745e JM |
5083 | static void |
5084 | print_dwarf_line_table (outfile) | |
5085 | FILE *outfile; | |
a3f97cbb | 5086 | { |
3f76745e JM |
5087 | register unsigned i; |
5088 | register dw_line_info_ref line_info; | |
5089 | ||
5090 | fprintf (outfile, "\n\nDWARF source line information\n"); | |
5091 | for (i = 1; i < line_info_table_in_use; ++i) | |
a3f97cbb | 5092 | { |
3f76745e JM |
5093 | line_info = &line_info_table[i]; |
5094 | fprintf (outfile, "%5d: ", i); | |
981975b6 | 5095 | fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]); |
2d8b0f3a | 5096 | fprintf (outfile, "%6ld", line_info->dw_line_num); |
3f76745e | 5097 | fprintf (outfile, "\n"); |
a3f97cbb | 5098 | } |
3f76745e JM |
5099 | |
5100 | fprintf (outfile, "\n\n"); | |
f37230f0 JM |
5101 | } |
5102 | ||
3f76745e JM |
5103 | /* Print the information collected for a given DIE. */ |
5104 | ||
5105 | void | |
5106 | debug_dwarf_die (die) | |
5107 | dw_die_ref die; | |
5108 | { | |
5109 | print_die (die, stderr); | |
5110 | } | |
5111 | ||
5112 | /* Print all DWARF information collected for the compilation unit. | |
5113 | This routine is a debugging aid only. */ | |
5114 | ||
5115 | void | |
5116 | debug_dwarf () | |
5117 | { | |
5118 | print_indent = 0; | |
5119 | print_die (comp_unit_die, stderr); | |
b2244e22 JW |
5120 | if (! DWARF2_ASM_LINE_DEBUG_INFO) |
5121 | print_dwarf_line_table (stderr); | |
3f76745e JM |
5122 | } |
5123 | \f | |
a96c67ec JM |
5124 | /* We build up the lists of children and attributes by pushing new ones |
5125 | onto the beginning of the list. Reverse the lists for DIE so that | |
5126 | they are in order of addition. */ | |
71dfc51f | 5127 | |
f37230f0 | 5128 | static void |
a96c67ec | 5129 | reverse_die_lists (die) |
3f76745e | 5130 | register dw_die_ref die; |
f37230f0 | 5131 | { |
a96c67ec JM |
5132 | register dw_die_ref c, cp, cn; |
5133 | register dw_attr_ref a, ap, an; | |
71dfc51f | 5134 | |
a96c67ec | 5135 | for (a = die->die_attr, ap = 0; a; a = an) |
7d9d8943 AM |
5136 | { |
5137 | an = a->dw_attr_next; | |
5138 | a->dw_attr_next = ap; | |
5139 | ap = a; | |
a3f97cbb | 5140 | } |
7d9d8943 | 5141 | die->die_attr = ap; |
3f76745e | 5142 | |
7d9d8943 AM |
5143 | for (c = die->die_child, cp = 0; c; c = cn) |
5144 | { | |
5145 | cn = c->die_sib; | |
5146 | c->die_sib = cp; | |
5147 | cp = c; | |
5148 | } | |
5149 | die->die_child = cp; | |
a3f97cbb JW |
5150 | } |
5151 | ||
881c6935 JM |
5152 | /* reverse_die_lists only reverses the single die you pass it. Since |
5153 | we used to reverse all dies in add_sibling_attributes, which runs | |
5154 | through all the dies, it would reverse all the dies. Now, however, | |
5155 | since we don't call reverse_die_lists in add_sibling_attributes, we | |
5156 | need a routine to recursively reverse all the dies. This is that | |
5157 | routine. */ | |
71dfc51f | 5158 | |
7d9d8943 | 5159 | static void |
881c6935 | 5160 | reverse_all_dies (die) |
7d9d8943 | 5161 | register dw_die_ref die; |
a3f97cbb | 5162 | { |
7d9d8943 | 5163 | register dw_die_ref c; |
71dfc51f | 5164 | |
7d9d8943 | 5165 | reverse_die_lists (die); |
3f76745e | 5166 | |
881c6935 JM |
5167 | for (c = die->die_child; c; c = c->die_sib) |
5168 | reverse_all_dies (c); | |
5169 | } | |
5170 | ||
5171 | /* Start a new compilation unit DIE for an include file. OLD_UNIT is | |
5172 | the CU for the enclosing include file, if any. BINCL_DIE is the | |
5173 | DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this | |
5174 | include file. */ | |
5175 | ||
5176 | static dw_die_ref | |
5177 | push_new_compile_unit (old_unit, bincl_die) | |
5178 | dw_die_ref old_unit, bincl_die; | |
5179 | { | |
5180 | const char *filename = get_AT_string (bincl_die, DW_AT_name); | |
5181 | dw_die_ref new_unit = gen_compile_unit_die (filename); | |
5182 | new_unit->die_sib = old_unit; | |
5183 | return new_unit; | |
5184 | } | |
5185 | ||
5186 | /* Close an include-file CU and reopen the enclosing one. */ | |
5187 | ||
5188 | static dw_die_ref | |
5189 | pop_compile_unit (old_unit) | |
5190 | dw_die_ref old_unit; | |
5191 | { | |
5192 | dw_die_ref new_unit = old_unit->die_sib; | |
5193 | old_unit->die_sib = NULL; | |
5194 | return new_unit; | |
5195 | } | |
5196 | ||
5197 | #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx) | |
5198 | #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx) | |
5199 | ||
5200 | /* Calculate the checksum of a location expression. */ | |
5201 | ||
5202 | static inline void | |
5203 | loc_checksum (loc, ctx) | |
5204 | dw_loc_descr_ref loc; | |
5205 | struct md5_ctx *ctx; | |
5206 | { | |
5207 | PROCESS (loc->dw_loc_opc); | |
5208 | PROCESS (loc->dw_loc_oprnd1); | |
5209 | PROCESS (loc->dw_loc_oprnd2); | |
5210 | } | |
5211 | ||
5212 | /* Calculate the checksum of an attribute. */ | |
5213 | ||
5214 | static void | |
5215 | attr_checksum (at, ctx) | |
5216 | dw_attr_ref at; | |
5217 | struct md5_ctx *ctx; | |
5218 | { | |
5219 | dw_loc_descr_ref loc; | |
5220 | rtx r; | |
5221 | ||
5222 | PROCESS (at->dw_attr); | |
5223 | ||
5224 | /* We don't care about differences in file numbering. */ | |
5f632b5e JM |
5225 | if (at->dw_attr == DW_AT_decl_file |
5226 | /* Or that this was compiled with a different compiler snapshot; if | |
5227 | the output is the same, that's what matters. */ | |
5228 | || at->dw_attr == DW_AT_producer) | |
881c6935 JM |
5229 | return; |
5230 | ||
5231 | switch (AT_class (at)) | |
5232 | { | |
5233 | case dw_val_class_const: | |
5234 | PROCESS (at->dw_attr_val.v.val_int); | |
5235 | break; | |
5236 | case dw_val_class_unsigned_const: | |
5237 | PROCESS (at->dw_attr_val.v.val_unsigned); | |
5238 | break; | |
5239 | case dw_val_class_long_long: | |
5240 | PROCESS (at->dw_attr_val.v.val_long_long); | |
5241 | break; | |
5242 | case dw_val_class_float: | |
5243 | PROCESS (at->dw_attr_val.v.val_float); | |
5244 | break; | |
5245 | case dw_val_class_flag: | |
5246 | PROCESS (at->dw_attr_val.v.val_flag); | |
5247 | break; | |
5248 | ||
5249 | case dw_val_class_str: | |
5250 | PROCESS_STRING (AT_string (at)); | |
5251 | break; | |
5252 | case dw_val_class_addr: | |
5253 | r = AT_addr (at); | |
5254 | switch (GET_CODE (r)) | |
5255 | { | |
5256 | case SYMBOL_REF: | |
5257 | PROCESS_STRING (XSTR (r, 0)); | |
5258 | break; | |
5259 | ||
5260 | default: | |
5261 | abort (); | |
5262 | } | |
5263 | break; | |
5264 | ||
5265 | case dw_val_class_loc: | |
5266 | for (loc = AT_loc (at); loc; loc = loc->dw_loc_next) | |
5267 | loc_checksum (loc, ctx); | |
5268 | break; | |
5269 | ||
5270 | case dw_val_class_die_ref: | |
5271 | if (AT_ref (at)->die_offset) | |
5272 | PROCESS (AT_ref (at)->die_offset); | |
5273 | /* FIXME else use target die name or something. */ | |
5274 | ||
5275 | case dw_val_class_fde_ref: | |
5276 | case dw_val_class_lbl_id: | |
5277 | case dw_val_class_lbl_offset: | |
5278 | ||
5279 | default: | |
5280 | break; | |
5281 | } | |
5282 | } | |
5283 | ||
5284 | /* Calculate the checksum of a DIE. */ | |
5285 | ||
5286 | static void | |
5287 | die_checksum (die, ctx) | |
5288 | dw_die_ref die; | |
5289 | struct md5_ctx *ctx; | |
5290 | { | |
5291 | dw_die_ref c; | |
5292 | dw_attr_ref a; | |
5293 | ||
5294 | PROCESS (die->die_tag); | |
5295 | ||
5296 | for (a = die->die_attr; a; a = a->dw_attr_next) | |
5297 | attr_checksum (a, ctx); | |
5298 | ||
5299 | for (c = die->die_child; c; c = c->die_sib) | |
5300 | die_checksum (c, ctx); | |
5301 | } | |
5302 | ||
5303 | #undef PROCESS | |
5304 | #undef PROCESS_STRING | |
5305 | ||
5306 | /* The prefix to attach to symbols on DIEs in the current comdat debug | |
5307 | info section. */ | |
5308 | static char *comdat_symbol_id; | |
5309 | ||
5310 | /* The index of the current symbol within the current comdat CU. */ | |
5311 | static unsigned int comdat_symbol_number; | |
5312 | ||
5313 | /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its | |
5314 | children, and set comdat_symbol_id accordingly. */ | |
5315 | ||
5316 | static void | |
5317 | compute_section_prefix (unit_die) | |
5318 | dw_die_ref unit_die; | |
5319 | { | |
5320 | char *p, *name; | |
5321 | int i; | |
5322 | unsigned char checksum[16]; | |
5323 | struct md5_ctx ctx; | |
5324 | ||
5325 | md5_init_ctx (&ctx); | |
5326 | die_checksum (unit_die, &ctx); | |
5327 | md5_finish_ctx (&ctx, checksum); | |
5328 | ||
b3e68a79 | 5329 | p = lbasename (get_AT_string (unit_die, DW_AT_name)); |
881c6935 JM |
5330 | name = (char *) alloca (strlen (p) + 64); |
5331 | sprintf (name, "%s.", p); | |
5332 | ||
5333 | clean_symbol_name (name); | |
5334 | ||
5335 | p = name + strlen (name); | |
5336 | for (i = 0; i < 4; ++i) | |
5337 | { | |
5338 | sprintf (p, "%.2x", checksum[i]); | |
5339 | p += 2; | |
5340 | } | |
5341 | ||
5342 | comdat_symbol_id = unit_die->die_symbol = xstrdup (name); | |
5343 | comdat_symbol_number = 0; | |
5344 | } | |
5345 | ||
5346 | /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */ | |
5347 | ||
5348 | static int | |
5349 | is_type_die (die) | |
5350 | dw_die_ref die; | |
5351 | { | |
5352 | switch (die->die_tag) | |
5353 | { | |
5354 | case DW_TAG_array_type: | |
5355 | case DW_TAG_class_type: | |
5356 | case DW_TAG_enumeration_type: | |
5357 | case DW_TAG_pointer_type: | |
5358 | case DW_TAG_reference_type: | |
5359 | case DW_TAG_string_type: | |
5360 | case DW_TAG_structure_type: | |
5361 | case DW_TAG_subroutine_type: | |
5362 | case DW_TAG_union_type: | |
5363 | case DW_TAG_ptr_to_member_type: | |
5364 | case DW_TAG_set_type: | |
5365 | case DW_TAG_subrange_type: | |
5366 | case DW_TAG_base_type: | |
5367 | case DW_TAG_const_type: | |
5368 | case DW_TAG_file_type: | |
5369 | case DW_TAG_packed_type: | |
5370 | case DW_TAG_volatile_type: | |
5371 | return 1; | |
5372 | default: | |
5373 | return 0; | |
5374 | } | |
5375 | } | |
5376 | ||
5377 | /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU. | |
5378 | Basically, we want to choose the bits that are likely to be shared between | |
5379 | compilations (types) and leave out the bits that are specific to individual | |
5380 | compilations (functions). */ | |
5381 | ||
5382 | static int | |
5383 | is_comdat_die (c) | |
5384 | dw_die_ref c; | |
5385 | { | |
5386 | #if 1 | |
5387 | /* I think we want to leave base types and __vtbl_ptr_type in the | |
5388 | main CU, as we do for stabs. The advantage is a greater | |
5389 | likelihood of sharing between objects that don't include headers | |
5390 | in the same order (and therefore would put the base types in a | |
5391 | different comdat). jason 8/28/00 */ | |
5392 | if (c->die_tag == DW_TAG_base_type) | |
5393 | return 0; | |
5394 | ||
5395 | if (c->die_tag == DW_TAG_pointer_type | |
5396 | || c->die_tag == DW_TAG_reference_type | |
5397 | || c->die_tag == DW_TAG_const_type | |
5398 | || c->die_tag == DW_TAG_volatile_type) | |
5399 | { | |
5400 | dw_die_ref t = get_AT_ref (c, DW_AT_type); | |
5401 | return t ? is_comdat_die (t) : 0; | |
5402 | } | |
5403 | #endif | |
5404 | ||
5405 | return is_type_die (c); | |
5406 | } | |
5407 | ||
5408 | /* Returns 1 iff C is the sort of DIE that might be referred to from another | |
5409 | compilation unit. */ | |
5410 | ||
5411 | static int | |
5412 | is_symbol_die (c) | |
5413 | dw_die_ref c; | |
5414 | { | |
5415 | if (is_type_die (c)) | |
5416 | return 1; | |
63e46568 | 5417 | if (get_AT (c, DW_AT_declaration) |
881c6935 JM |
5418 | && ! get_AT (c, DW_AT_specification)) |
5419 | return 1; | |
5420 | return 0; | |
5421 | } | |
5422 | ||
5423 | static char * | |
63e46568 DB |
5424 | gen_internal_sym (prefix) |
5425 | const char *prefix; | |
881c6935 JM |
5426 | { |
5427 | char buf[256]; | |
5428 | static int label_num; | |
63e46568 | 5429 | ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++); |
881c6935 JM |
5430 | return xstrdup (buf); |
5431 | } | |
5432 | ||
5433 | /* Assign symbols to all worthy DIEs under DIE. */ | |
5434 | ||
5435 | static void | |
5436 | assign_symbol_names (die) | |
5437 | register dw_die_ref die; | |
5438 | { | |
5439 | register dw_die_ref c; | |
5440 | ||
5441 | if (is_symbol_die (die)) | |
5442 | { | |
5443 | if (comdat_symbol_id) | |
5444 | { | |
5445 | char *p = alloca (strlen (comdat_symbol_id) + 64); | |
5446 | sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX, | |
5447 | comdat_symbol_id, comdat_symbol_number++); | |
5448 | die->die_symbol = xstrdup (p); | |
5449 | } | |
5450 | else | |
63e46568 | 5451 | die->die_symbol = gen_internal_sym ("LDIE"); |
881c6935 JM |
5452 | } |
5453 | ||
5454 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5455 | assign_symbol_names (c); | |
5456 | } | |
5457 | ||
5458 | /* Traverse the DIE (which is always comp_unit_die), and set up | |
5459 | additional compilation units for each of the include files we see | |
5460 | bracketed by BINCL/EINCL. */ | |
5461 | ||
5462 | static void | |
5463 | break_out_includes (die) | |
5464 | register dw_die_ref die; | |
5465 | { | |
5466 | dw_die_ref *ptr; | |
5467 | register dw_die_ref unit = NULL; | |
5468 | limbo_die_node *node; | |
5469 | ||
5470 | for (ptr = &(die->die_child); *ptr; ) | |
5471 | { | |
5472 | register dw_die_ref c = *ptr; | |
5473 | ||
5474 | if (c->die_tag == DW_TAG_GNU_BINCL | |
5475 | || c->die_tag == DW_TAG_GNU_EINCL | |
5476 | || (unit && is_comdat_die (c))) | |
5477 | { | |
5478 | /* This DIE is for a secondary CU; remove it from the main one. */ | |
5479 | *ptr = c->die_sib; | |
5480 | ||
5481 | if (c->die_tag == DW_TAG_GNU_BINCL) | |
5482 | { | |
5483 | unit = push_new_compile_unit (unit, c); | |
5484 | free_die (c); | |
5485 | } | |
5486 | else if (c->die_tag == DW_TAG_GNU_EINCL) | |
5487 | { | |
5488 | unit = pop_compile_unit (unit); | |
5489 | free_die (c); | |
5490 | } | |
5491 | else | |
5492 | add_child_die (unit, c); | |
5493 | } | |
5494 | else | |
5495 | { | |
5496 | /* Leave this DIE in the main CU. */ | |
5497 | ptr = &(c->die_sib); | |
5498 | continue; | |
5499 | } | |
5500 | } | |
5501 | ||
5502 | #if 0 | |
5503 | /* We can only use this in debugging, since the frontend doesn't check | |
0b34cf1e | 5504 | to make sure that we leave every include file we enter. */ |
881c6935 JM |
5505 | if (unit != NULL) |
5506 | abort (); | |
5507 | #endif | |
5508 | ||
5509 | assign_symbol_names (die); | |
5510 | for (node = limbo_die_list; node; node = node->next) | |
5511 | { | |
5512 | compute_section_prefix (node->die); | |
5513 | assign_symbol_names (node->die); | |
5514 | } | |
5515 | } | |
5516 | ||
5517 | /* Traverse the DIE and add a sibling attribute if it may have the | |
5518 | effect of speeding up access to siblings. To save some space, | |
5519 | avoid generating sibling attributes for DIE's without children. */ | |
5520 | ||
5521 | static void | |
5522 | add_sibling_attributes (die) | |
5523 | register dw_die_ref die; | |
5524 | { | |
5525 | register dw_die_ref c; | |
5526 | ||
5527 | if (die->die_tag != DW_TAG_compile_unit | |
5528 | && die->die_sib && die->die_child != NULL) | |
7d9d8943 AM |
5529 | /* Add the sibling link to the front of the attribute list. */ |
5530 | add_AT_die_ref (die, DW_AT_sibling, die->die_sib); | |
5531 | ||
5532 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5533 | add_sibling_attributes (c); | |
5534 | } | |
5535 | ||
63e46568 DB |
5536 | /* Output all location lists for the DIE and it's children */ |
5537 | static void | |
5538 | output_location_lists (die) | |
5539 | register dw_die_ref die; | |
5540 | { | |
5541 | dw_die_ref c; | |
5542 | dw_attr_ref d_attr; | |
5543 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) | |
5544 | { | |
5545 | if (AT_class (d_attr) == dw_val_class_loc_list) | |
5546 | { | |
5547 | output_loc_list (AT_loc_list (d_attr)); | |
5548 | } | |
5549 | } | |
5550 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5551 | output_location_lists (c); | |
5552 | ||
5553 | } | |
7d9d8943 AM |
5554 | /* The format of each DIE (and its attribute value pairs) |
5555 | is encoded in an abbreviation table. This routine builds the | |
5556 | abbreviation table and assigns a unique abbreviation id for | |
5557 | each abbreviation entry. The children of each die are visited | |
5558 | recursively. */ | |
5559 | ||
5560 | static void | |
5561 | build_abbrev_table (die) | |
5562 | register dw_die_ref die; | |
5563 | { | |
5564 | register unsigned long abbrev_id; | |
ae0ed63a | 5565 | register unsigned int n_alloc; |
7d9d8943 AM |
5566 | register dw_die_ref c; |
5567 | register dw_attr_ref d_attr, a_attr; | |
881c6935 JM |
5568 | |
5569 | /* Scan the DIE references, and mark as external any that refer to | |
1bfb5f8f | 5570 | DIEs from other CUs (i.e. those which are not marked). */ |
881c6935 JM |
5571 | for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) |
5572 | { | |
5573 | if (AT_class (d_attr) == dw_val_class_die_ref | |
1bfb5f8f | 5574 | && AT_ref (d_attr)->die_mark == 0) |
881c6935 JM |
5575 | { |
5576 | if (AT_ref (d_attr)->die_symbol == 0) | |
5577 | abort (); | |
5578 | set_AT_ref_external (d_attr, 1); | |
5579 | } | |
5580 | } | |
5581 | ||
7d9d8943 AM |
5582 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
5583 | { | |
5584 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
5585 | ||
5586 | if (abbrev->die_tag == die->die_tag) | |
5587 | { | |
5588 | if ((abbrev->die_child != NULL) == (die->die_child != NULL)) | |
5589 | { | |
5590 | a_attr = abbrev->die_attr; | |
5591 | d_attr = die->die_attr; | |
5592 | ||
5593 | while (a_attr != NULL && d_attr != NULL) | |
5594 | { | |
5595 | if ((a_attr->dw_attr != d_attr->dw_attr) | |
5596 | || (value_format (a_attr) != value_format (d_attr))) | |
5597 | break; | |
5598 | ||
5599 | a_attr = a_attr->dw_attr_next; | |
5600 | d_attr = d_attr->dw_attr_next; | |
5601 | } | |
5602 | ||
5603 | if (a_attr == NULL && d_attr == NULL) | |
5604 | break; | |
5605 | } | |
5606 | } | |
5607 | } | |
5608 | ||
5609 | if (abbrev_id >= abbrev_die_table_in_use) | |
5610 | { | |
5611 | if (abbrev_die_table_in_use >= abbrev_die_table_allocated) | |
5612 | { | |
5613 | n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT; | |
556273e0 | 5614 | abbrev_die_table |
7d9d8943 AM |
5615 | = (dw_die_ref *) xrealloc (abbrev_die_table, |
5616 | sizeof (dw_die_ref) * n_alloc); | |
5617 | ||
961192e1 | 5618 | memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0, |
7d9d8943 AM |
5619 | (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref)); |
5620 | abbrev_die_table_allocated = n_alloc; | |
5621 | } | |
5622 | ||
5623 | ++abbrev_die_table_in_use; | |
5624 | abbrev_die_table[abbrev_id] = die; | |
5625 | } | |
5626 | ||
5627 | die->die_abbrev = abbrev_id; | |
5628 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
5629 | build_abbrev_table (c); | |
5630 | } | |
5631 | \f | |
5632 | /* Return the size of a string, including the null byte. | |
5633 | ||
5634 | This used to treat backslashes as escapes, and hence they were not included | |
5635 | in the count. However, that conflicts with what ASM_OUTPUT_ASCII does, | |
5636 | which treats a backslash as a backslash, escaping it if necessary, and hence | |
5637 | we must include them in the count. */ | |
5638 | ||
5639 | static unsigned long | |
5640 | size_of_string (str) | |
5641 | register const char *str; | |
5642 | { | |
5643 | return strlen (str) + 1; | |
3f76745e JM |
5644 | } |
5645 | ||
5646 | /* Return the power-of-two number of bytes necessary to represent VALUE. */ | |
5647 | ||
5648 | static int | |
5649 | constant_size (value) | |
5650 | long unsigned value; | |
5651 | { | |
5652 | int log; | |
5653 | ||
5654 | if (value == 0) | |
5655 | log = 0; | |
a3f97cbb | 5656 | else |
3f76745e | 5657 | log = floor_log2 (value); |
71dfc51f | 5658 | |
3f76745e JM |
5659 | log = log / 8; |
5660 | log = 1 << (floor_log2 (log) + 1); | |
5661 | ||
5662 | return log; | |
a3f97cbb JW |
5663 | } |
5664 | ||
3f76745e JM |
5665 | /* Return the size of a DIE, as it is represented in the |
5666 | .debug_info section. */ | |
71dfc51f | 5667 | |
3f76745e JM |
5668 | static unsigned long |
5669 | size_of_die (die) | |
a3f97cbb JW |
5670 | register dw_die_ref die; |
5671 | { | |
3f76745e | 5672 | register unsigned long size = 0; |
a3f97cbb | 5673 | register dw_attr_ref a; |
71dfc51f | 5674 | |
3f76745e | 5675 | size += size_of_uleb128 (die->die_abbrev); |
a3f97cbb JW |
5676 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
5677 | { | |
a96c67ec | 5678 | switch (AT_class (a)) |
a3f97cbb JW |
5679 | { |
5680 | case dw_val_class_addr: | |
a1a4189d | 5681 | size += DWARF2_ADDR_SIZE; |
a3f97cbb JW |
5682 | break; |
5683 | case dw_val_class_loc: | |
3f76745e | 5684 | { |
a96c67ec | 5685 | register unsigned long lsize = size_of_locs (AT_loc (a)); |
71dfc51f | 5686 | |
3f76745e JM |
5687 | /* Block length. */ |
5688 | size += constant_size (lsize); | |
5689 | size += lsize; | |
5690 | } | |
a3f97cbb | 5691 | break; |
63e46568 DB |
5692 | case dw_val_class_loc_list: |
5693 | size += DWARF_OFFSET_SIZE; | |
5694 | break; | |
a3f97cbb | 5695 | case dw_val_class_const: |
25dd13ec | 5696 | size += size_of_sleb128 (AT_int (a)); |
a3f97cbb JW |
5697 | break; |
5698 | case dw_val_class_unsigned_const: | |
a96c67ec | 5699 | size += constant_size (AT_unsigned (a)); |
a3f97cbb | 5700 | break; |
469ac993 | 5701 | case dw_val_class_long_long: |
2e4b9b8c | 5702 | size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */ |
469ac993 JM |
5703 | break; |
5704 | case dw_val_class_float: | |
3f76745e | 5705 | size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */ |
a3f97cbb JW |
5706 | break; |
5707 | case dw_val_class_flag: | |
3f76745e | 5708 | size += 1; |
a3f97cbb JW |
5709 | break; |
5710 | case dw_val_class_die_ref: | |
3f76745e | 5711 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
5712 | break; |
5713 | case dw_val_class_fde_ref: | |
3f76745e | 5714 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
5715 | break; |
5716 | case dw_val_class_lbl_id: | |
a1a4189d | 5717 | size += DWARF2_ADDR_SIZE; |
3f76745e | 5718 | break; |
8b790721 | 5719 | case dw_val_class_lbl_offset: |
3f76745e JM |
5720 | size += DWARF_OFFSET_SIZE; |
5721 | break; | |
5722 | case dw_val_class_str: | |
a96c67ec | 5723 | size += size_of_string (AT_string (a)); |
3f76745e JM |
5724 | break; |
5725 | default: | |
5726 | abort (); | |
5727 | } | |
a3f97cbb | 5728 | } |
3f76745e JM |
5729 | |
5730 | return size; | |
a3f97cbb JW |
5731 | } |
5732 | ||
956d6950 | 5733 | /* Size the debugging information associated with a given DIE. |
3f76745e JM |
5734 | Visits the DIE's children recursively. Updates the global |
5735 | variable next_die_offset, on each time through. Uses the | |
956d6950 | 5736 | current value of next_die_offset to update the die_offset |
3f76745e | 5737 | field in each DIE. */ |
71dfc51f | 5738 | |
a3f97cbb | 5739 | static void |
3f76745e JM |
5740 | calc_die_sizes (die) |
5741 | dw_die_ref die; | |
a3f97cbb | 5742 | { |
3f76745e JM |
5743 | register dw_die_ref c; |
5744 | die->die_offset = next_die_offset; | |
5745 | next_die_offset += size_of_die (die); | |
71dfc51f | 5746 | |
3f76745e JM |
5747 | for (c = die->die_child; c != NULL; c = c->die_sib) |
5748 | calc_die_sizes (c); | |
71dfc51f | 5749 | |
3f76745e JM |
5750 | if (die->die_child != NULL) |
5751 | /* Count the null byte used to terminate sibling lists. */ | |
5752 | next_die_offset += 1; | |
a3f97cbb JW |
5753 | } |
5754 | ||
1bfb5f8f | 5755 | /* Set the marks for a die and its children. We do this so |
881c6935 | 5756 | that we know whether or not a reference needs to use FORM_ref_addr; only |
1bfb5f8f JM |
5757 | DIEs in the same CU will be marked. We used to clear out the offset |
5758 | and use that as the flag, but ran into ordering problems. */ | |
881c6935 JM |
5759 | |
5760 | static void | |
1bfb5f8f | 5761 | mark_dies (die) |
881c6935 JM |
5762 | dw_die_ref die; |
5763 | { | |
5764 | register dw_die_ref c; | |
1bfb5f8f JM |
5765 | die->die_mark = 1; |
5766 | for (c = die->die_child; c; c = c->die_sib) | |
5767 | mark_dies (c); | |
5768 | } | |
5769 | ||
5770 | /* Clear the marks for a die and its children. */ | |
5771 | ||
5772 | static void | |
5773 | unmark_dies (die) | |
5774 | dw_die_ref die; | |
5775 | { | |
5776 | register dw_die_ref c; | |
5777 | die->die_mark = 0; | |
881c6935 | 5778 | for (c = die->die_child; c; c = c->die_sib) |
1bfb5f8f | 5779 | unmark_dies (c); |
881c6935 JM |
5780 | } |
5781 | ||
3f76745e JM |
5782 | /* Return the size of the .debug_pubnames table generated for the |
5783 | compilation unit. */ | |
a94dbf2c | 5784 | |
3f76745e JM |
5785 | static unsigned long |
5786 | size_of_pubnames () | |
a94dbf2c | 5787 | { |
3f76745e JM |
5788 | register unsigned long size; |
5789 | register unsigned i; | |
469ac993 | 5790 | |
3f76745e JM |
5791 | size = DWARF_PUBNAMES_HEADER_SIZE; |
5792 | for (i = 0; i < pubname_table_in_use; ++i) | |
a94dbf2c | 5793 | { |
3f76745e JM |
5794 | register pubname_ref p = &pubname_table[i]; |
5795 | size += DWARF_OFFSET_SIZE + size_of_string (p->name); | |
a94dbf2c JM |
5796 | } |
5797 | ||
3f76745e JM |
5798 | size += DWARF_OFFSET_SIZE; |
5799 | return size; | |
a94dbf2c JM |
5800 | } |
5801 | ||
956d6950 | 5802 | /* Return the size of the information in the .debug_aranges section. */ |
469ac993 | 5803 | |
3f76745e JM |
5804 | static unsigned long |
5805 | size_of_aranges () | |
469ac993 | 5806 | { |
3f76745e | 5807 | register unsigned long size; |
469ac993 | 5808 | |
3f76745e | 5809 | size = DWARF_ARANGES_HEADER_SIZE; |
469ac993 | 5810 | |
3f76745e | 5811 | /* Count the address/length pair for this compilation unit. */ |
a1a4189d JB |
5812 | size += 2 * DWARF2_ADDR_SIZE; |
5813 | size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use; | |
469ac993 | 5814 | |
3f76745e | 5815 | /* Count the two zero words used to terminated the address range table. */ |
a1a4189d | 5816 | size += 2 * DWARF2_ADDR_SIZE; |
3f76745e JM |
5817 | return size; |
5818 | } | |
5819 | \f | |
5820 | /* Select the encoding of an attribute value. */ | |
5821 | ||
5822 | static enum dwarf_form | |
a96c67ec JM |
5823 | value_format (a) |
5824 | dw_attr_ref a; | |
3f76745e | 5825 | { |
a96c67ec | 5826 | switch (a->dw_attr_val.val_class) |
469ac993 | 5827 | { |
3f76745e JM |
5828 | case dw_val_class_addr: |
5829 | return DW_FORM_addr; | |
63e46568 | 5830 | case dw_val_class_loc_list: |
9d2f2c45 RH |
5831 | /* FIXME: Could be DW_FORM_data8, with a > 32 bit size |
5832 | .debug_loc section */ | |
5833 | return DW_FORM_data4; | |
3f76745e | 5834 | case dw_val_class_loc: |
a96c67ec | 5835 | switch (constant_size (size_of_locs (AT_loc (a)))) |
469ac993 | 5836 | { |
3f76745e JM |
5837 | case 1: |
5838 | return DW_FORM_block1; | |
5839 | case 2: | |
5840 | return DW_FORM_block2; | |
469ac993 JM |
5841 | default: |
5842 | abort (); | |
5843 | } | |
3f76745e | 5844 | case dw_val_class_const: |
25dd13ec | 5845 | return DW_FORM_sdata; |
3f76745e | 5846 | case dw_val_class_unsigned_const: |
a96c67ec | 5847 | switch (constant_size (AT_unsigned (a))) |
3f76745e JM |
5848 | { |
5849 | case 1: | |
5850 | return DW_FORM_data1; | |
5851 | case 2: | |
5852 | return DW_FORM_data2; | |
5853 | case 4: | |
5854 | return DW_FORM_data4; | |
5855 | case 8: | |
5856 | return DW_FORM_data8; | |
5857 | default: | |
5858 | abort (); | |
5859 | } | |
5860 | case dw_val_class_long_long: | |
5861 | return DW_FORM_block1; | |
5862 | case dw_val_class_float: | |
5863 | return DW_FORM_block1; | |
5864 | case dw_val_class_flag: | |
5865 | return DW_FORM_flag; | |
5866 | case dw_val_class_die_ref: | |
881c6935 JM |
5867 | if (AT_ref_external (a)) |
5868 | return DW_FORM_ref_addr; | |
5869 | else | |
5870 | return DW_FORM_ref; | |
3f76745e JM |
5871 | case dw_val_class_fde_ref: |
5872 | return DW_FORM_data; | |
5873 | case dw_val_class_lbl_id: | |
5874 | return DW_FORM_addr; | |
8b790721 | 5875 | case dw_val_class_lbl_offset: |
3f76745e JM |
5876 | return DW_FORM_data; |
5877 | case dw_val_class_str: | |
5878 | return DW_FORM_string; | |
469ac993 JM |
5879 | default: |
5880 | abort (); | |
5881 | } | |
a94dbf2c JM |
5882 | } |
5883 | ||
3f76745e | 5884 | /* Output the encoding of an attribute value. */ |
469ac993 | 5885 | |
3f76745e | 5886 | static void |
a96c67ec JM |
5887 | output_value_format (a) |
5888 | dw_attr_ref a; | |
a94dbf2c | 5889 | { |
a96c67ec | 5890 | enum dwarf_form form = value_format (a); |
2e4b9b8c | 5891 | dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form)); |
3f76745e | 5892 | } |
469ac993 | 5893 | |
3f76745e JM |
5894 | /* Output the .debug_abbrev section which defines the DIE abbreviation |
5895 | table. */ | |
469ac993 | 5896 | |
3f76745e JM |
5897 | static void |
5898 | output_abbrev_section () | |
5899 | { | |
5900 | unsigned long abbrev_id; | |
71dfc51f | 5901 | |
3f76745e JM |
5902 | dw_attr_ref a_attr; |
5903 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) | |
5904 | { | |
5905 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
71dfc51f | 5906 | |
2e4b9b8c | 5907 | dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)"); |
469ac993 | 5908 | |
2e4b9b8c RH |
5909 | dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)", |
5910 | dwarf_tag_name (abbrev->die_tag)); | |
71dfc51f | 5911 | |
2e4b9b8c RH |
5912 | if (abbrev->die_child != NULL) |
5913 | dw2_asm_output_data (1, DW_children_yes, "DW_children_yes"); | |
5914 | else | |
5915 | dw2_asm_output_data (1, DW_children_no, "DW_children_no"); | |
3f76745e JM |
5916 | |
5917 | for (a_attr = abbrev->die_attr; a_attr != NULL; | |
5918 | a_attr = a_attr->dw_attr_next) | |
5919 | { | |
2e4b9b8c RH |
5920 | dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)", |
5921 | dwarf_attr_name (a_attr->dw_attr)); | |
a96c67ec | 5922 | output_value_format (a_attr); |
469ac993 | 5923 | } |
469ac993 | 5924 | |
2e4b9b8c RH |
5925 | dw2_asm_output_data (1, 0, NULL); |
5926 | dw2_asm_output_data (1, 0, NULL); | |
469ac993 | 5927 | } |
81f374eb HPN |
5928 | |
5929 | /* Terminate the table. */ | |
2e4b9b8c | 5930 | dw2_asm_output_data (1, 0, NULL); |
a94dbf2c JM |
5931 | } |
5932 | ||
881c6935 JM |
5933 | /* Output a symbol we can use to refer to this DIE from another CU. */ |
5934 | ||
5935 | static inline void | |
5936 | output_die_symbol (die) | |
5937 | register dw_die_ref die; | |
5938 | { | |
5939 | char *sym = die->die_symbol; | |
5940 | ||
5941 | if (sym == 0) | |
5942 | return; | |
5943 | ||
5944 | if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0) | |
5945 | /* We make these global, not weak; if the target doesn't support | |
5946 | .linkonce, it doesn't support combining the sections, so debugging | |
5947 | will break. */ | |
5948 | ASM_GLOBALIZE_LABEL (asm_out_file, sym); | |
5949 | ASM_OUTPUT_LABEL (asm_out_file, sym); | |
5950 | } | |
5951 | ||
84a5b4f8 DB |
5952 | /* Return a new location list, given the begin and end range, and the |
5953 | expression. gensym tells us whether to generate a new internal | |
5954 | symbol for this location list node, which is done for the head of | |
5955 | the list only. */ | |
5956 | static inline dw_loc_list_ref | |
5957 | new_loc_list (expr, begin, end, section, gensym) | |
5958 | register dw_loc_descr_ref expr; | |
5959 | register const char *begin; | |
5960 | register const char *end; | |
5961 | register const char *section; | |
5962 | register unsigned gensym; | |
5963 | { | |
5964 | register dw_loc_list_ref retlist | |
5965 | = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node)); | |
5966 | retlist->begin = begin; | |
5967 | retlist->end = end; | |
5968 | retlist->expr = expr; | |
5969 | retlist->section = section; | |
5970 | if (gensym) | |
5971 | retlist->ll_symbol = gen_internal_sym ("LLST"); | |
5972 | return retlist; | |
5973 | } | |
5974 | ||
5975 | /* Add a location description expression to a location list */ | |
5976 | static inline void | |
5977 | add_loc_descr_to_loc_list (list_head, descr, begin, end, section) | |
5978 | register dw_loc_list_ref *list_head; | |
5979 | register dw_loc_descr_ref descr; | |
5980 | register const char *begin; | |
5981 | register const char *end; | |
5982 | register const char *section; | |
5983 | { | |
5984 | register dw_loc_list_ref *d; | |
5985 | ||
5986 | /* Find the end of the chain. */ | |
5987 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
5988 | ; | |
5989 | /* Add a new location list node to the list */ | |
5990 | *d = new_loc_list (descr, begin, end, section, 0); | |
5991 | } | |
5992 | ||
5993 | ||
5994 | ||
63e46568 DB |
5995 | /* Output the location list given to us */ |
5996 | static void | |
5997 | output_loc_list (list_head) | |
5998 | register dw_loc_list_ref list_head; | |
5999 | { | |
84a5b4f8 | 6000 | register dw_loc_list_ref curr=list_head; |
63e46568 DB |
6001 | ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol); |
6002 | if (strcmp (curr->section, ".text") == 0) | |
6003 | { | |
aafdcfcd NS |
6004 | /* dw2_asm_output_data will mask off any extra bits in the ~0. */ |
6005 | dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT)0, | |
6006 | "Location list base address specifier fake entry"); | |
6007 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section, | |
6008 | "Location list base address specifier base"); | |
63e46568 DB |
6009 | } |
6010 | for (curr = list_head; curr != NULL; curr=curr->dw_loc_next) | |
6011 | { | |
6012 | int size; | |
aafdcfcd NS |
6013 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section, |
6014 | "Location list begin address (%s)", | |
6015 | list_head->ll_symbol); | |
6016 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section, | |
6017 | "Location list end address (%s)", | |
6018 | list_head->ll_symbol); | |
63e46568 DB |
6019 | size = size_of_locs (curr->expr); |
6020 | ||
6021 | /* Output the block length for this list of location operations. */ | |
aafdcfcd NS |
6022 | dw2_asm_output_data (constant_size (size), size, "%s", |
6023 | "Location expression size"); | |
63e46568 DB |
6024 | |
6025 | output_loc_sequence (curr->expr); | |
6026 | } | |
aafdcfcd NS |
6027 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, |
6028 | "Location list terminator begin (%s)", | |
6029 | list_head->ll_symbol); | |
6030 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, | |
6031 | "Location list terminator end (%s)", | |
6032 | list_head->ll_symbol); | |
63e46568 | 6033 | } |
3f76745e JM |
6034 | /* Output the DIE and its attributes. Called recursively to generate |
6035 | the definitions of each child DIE. */ | |
71dfc51f | 6036 | |
a3f97cbb | 6037 | static void |
3f76745e JM |
6038 | output_die (die) |
6039 | register dw_die_ref die; | |
a3f97cbb | 6040 | { |
3f76745e JM |
6041 | register dw_attr_ref a; |
6042 | register dw_die_ref c; | |
3f76745e | 6043 | register unsigned long size; |
a94dbf2c | 6044 | |
881c6935 JM |
6045 | /* If someone in another CU might refer to us, set up a symbol for |
6046 | them to point to. */ | |
6047 | if (die->die_symbol) | |
6048 | output_die_symbol (die); | |
6049 | ||
2e4b9b8c RH |
6050 | dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)", |
6051 | die->die_offset, dwarf_tag_name (die->die_tag)); | |
a94dbf2c | 6052 | |
3f76745e | 6053 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
a3f97cbb | 6054 | { |
2e4b9b8c RH |
6055 | const char *name = dwarf_attr_name (a->dw_attr); |
6056 | ||
a96c67ec | 6057 | switch (AT_class (a)) |
3f76745e JM |
6058 | { |
6059 | case dw_val_class_addr: | |
2e4b9b8c | 6060 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name); |
3f76745e | 6061 | break; |
a3f97cbb | 6062 | |
3f76745e | 6063 | case dw_val_class_loc: |
a96c67ec | 6064 | size = size_of_locs (AT_loc (a)); |
71dfc51f | 6065 | |
3f76745e | 6066 | /* Output the block length for this list of location operations. */ |
2e4b9b8c | 6067 | dw2_asm_output_data (constant_size (size), size, "%s", name); |
71dfc51f | 6068 | |
7d9d8943 | 6069 | output_loc_sequence (AT_loc (a)); |
a3f97cbb | 6070 | break; |
3f76745e JM |
6071 | |
6072 | case dw_val_class_const: | |
25dd13ec JW |
6073 | /* ??? It would be slightly more efficient to use a scheme like is |
6074 | used for unsigned constants below, but gdb 4.x does not sign | |
6075 | extend. Gdb 5.x does sign extend. */ | |
2e4b9b8c | 6076 | dw2_asm_output_data_sleb128 (AT_int (a), "%s", name); |
a3f97cbb | 6077 | break; |
3f76745e JM |
6078 | |
6079 | case dw_val_class_unsigned_const: | |
2e4b9b8c RH |
6080 | dw2_asm_output_data (constant_size (AT_unsigned (a)), |
6081 | AT_unsigned (a), "%s", name); | |
a3f97cbb | 6082 | break; |
3f76745e JM |
6083 | |
6084 | case dw_val_class_long_long: | |
2e4b9b8c RH |
6085 | { |
6086 | unsigned HOST_WIDE_INT first, second; | |
3f76745e | 6087 | |
2e4b9b8c RH |
6088 | dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR, |
6089 | "%s", name); | |
556273e0 | 6090 | |
2e4b9b8c RH |
6091 | if (WORDS_BIG_ENDIAN) |
6092 | { | |
6093 | first = a->dw_attr_val.v.val_long_long.hi; | |
6094 | second = a->dw_attr_val.v.val_long_long.low; | |
6095 | } | |
6096 | else | |
6097 | { | |
6098 | first = a->dw_attr_val.v.val_long_long.low; | |
6099 | second = a->dw_attr_val.v.val_long_long.hi; | |
6100 | } | |
6101 | dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR, | |
6102 | first, "long long constant"); | |
6103 | dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR, | |
6104 | second, NULL); | |
6105 | } | |
a3f97cbb | 6106 | break; |
3f76745e JM |
6107 | |
6108 | case dw_val_class_float: | |
c84e2712 KG |
6109 | { |
6110 | register unsigned int i; | |
c84e2712 | 6111 | |
2e4b9b8c RH |
6112 | dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4, |
6113 | "%s", name); | |
c84e2712 | 6114 | |
2e4b9b8c RH |
6115 | for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i) |
6116 | dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i], | |
6117 | "fp constant word %u", i); | |
556273e0 | 6118 | break; |
c84e2712 | 6119 | } |
3f76745e JM |
6120 | |
6121 | case dw_val_class_flag: | |
2e4b9b8c | 6122 | dw2_asm_output_data (1, AT_flag (a), "%s", name); |
a3f97cbb | 6123 | break; |
63e46568 DB |
6124 | case dw_val_class_loc_list: |
6125 | { | |
6126 | char *sym = AT_loc_list (a)->ll_symbol; | |
6127 | if (sym == 0) | |
6128 | abort(); | |
6129 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, loc_section_label, name); | |
6130 | } | |
6131 | break; | |
3f76745e | 6132 | case dw_val_class_die_ref: |
881c6935 | 6133 | if (AT_ref_external (a)) |
2e4b9b8c RH |
6134 | { |
6135 | char *sym = AT_ref (a)->die_symbol; | |
6136 | if (sym == 0) | |
6137 | abort (); | |
6138 | dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name); | |
6139 | } | |
3f4907a6 JM |
6140 | else if (AT_ref (a)->die_offset == 0) |
6141 | abort (); | |
881c6935 | 6142 | else |
2e4b9b8c RH |
6143 | dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset, |
6144 | "%s", name); | |
a3f97cbb | 6145 | break; |
3f76745e JM |
6146 | |
6147 | case dw_val_class_fde_ref: | |
a6ab3aad JM |
6148 | { |
6149 | char l1[20]; | |
2e4b9b8c RH |
6150 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL, |
6151 | a->dw_attr_val.v.val_fde_index * 2); | |
6152 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name); | |
a6ab3aad | 6153 | } |
a3f97cbb | 6154 | break; |
a3f97cbb | 6155 | |
3f76745e | 6156 | case dw_val_class_lbl_id: |
8e7fa2c8 | 6157 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 6158 | break; |
71dfc51f | 6159 | |
8b790721 | 6160 | case dw_val_class_lbl_offset: |
2e4b9b8c | 6161 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name); |
3f76745e | 6162 | break; |
a3f97cbb | 6163 | |
3f76745e | 6164 | case dw_val_class_str: |
2e4b9b8c | 6165 | dw2_asm_output_nstring (AT_string (a), -1, "%s", name); |
3f76745e | 6166 | break; |
b2932ae5 | 6167 | |
3f76745e JM |
6168 | default: |
6169 | abort (); | |
6170 | } | |
3f76745e | 6171 | } |
71dfc51f | 6172 | |
3f76745e JM |
6173 | for (c = die->die_child; c != NULL; c = c->die_sib) |
6174 | output_die (c); | |
71dfc51f | 6175 | |
3f76745e | 6176 | if (die->die_child != NULL) |
7e23cb16 | 6177 | { |
556273e0 | 6178 | /* Add null byte to terminate sibling list. */ |
2e4b9b8c RH |
6179 | dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx", |
6180 | die->die_offset); | |
7e23cb16 | 6181 | } |
3f76745e | 6182 | } |
71dfc51f | 6183 | |
3f76745e JM |
6184 | /* Output the compilation unit that appears at the beginning of the |
6185 | .debug_info section, and precedes the DIE descriptions. */ | |
71dfc51f | 6186 | |
3f76745e JM |
6187 | static void |
6188 | output_compilation_unit_header () | |
6189 | { | |
2e4b9b8c RH |
6190 | dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE, |
6191 | "Length of Compilation Unit Info"); | |
71dfc51f | 6192 | |
2e4b9b8c | 6193 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number"); |
71dfc51f | 6194 | |
2e4b9b8c RH |
6195 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label, |
6196 | "Offset Into Abbrev. Section"); | |
71dfc51f | 6197 | |
2e4b9b8c | 6198 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)"); |
a3f97cbb JW |
6199 | } |
6200 | ||
881c6935 JM |
6201 | /* Output the compilation unit DIE and its children. */ |
6202 | ||
6203 | static void | |
6204 | output_comp_unit (die) | |
6205 | dw_die_ref die; | |
6206 | { | |
ce1cc601 | 6207 | const char *secname; |
881c6935 | 6208 | |
db3c0315 MM |
6209 | /* Even if there are no children of this DIE, we must output the |
6210 | information about the compilation unit. Otherwise, on an empty | |
6211 | translation unit, we will generate a present, but empty, | |
6212 | .debug_info section. IRIX 6.5 `nm' will then complain when | |
6213 | examining the file. | |
6214 | ||
6215 | Mark all the DIEs in this CU so we know which get local refs. */ | |
1bfb5f8f JM |
6216 | mark_dies (die); |
6217 | ||
6218 | build_abbrev_table (die); | |
6219 | ||
881c6935 JM |
6220 | /* Initialize the beginning DIE offset - and calculate sizes/offsets. */ |
6221 | next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE; | |
6222 | calc_die_sizes (die); | |
6223 | ||
881c6935 JM |
6224 | if (die->die_symbol) |
6225 | { | |
ce1cc601 KG |
6226 | char *tmp = (char *) alloca (strlen (die->die_symbol) + 24); |
6227 | sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol); | |
6228 | secname = tmp; | |
881c6935 JM |
6229 | die->die_symbol = NULL; |
6230 | } | |
6231 | else | |
ce1cc601 | 6232 | secname = (const char *) DEBUG_INFO_SECTION; |
881c6935 JM |
6233 | |
6234 | /* Output debugging information. */ | |
881c6935 JM |
6235 | ASM_OUTPUT_SECTION (asm_out_file, secname); |
6236 | output_compilation_unit_header (); | |
6237 | output_die (die); | |
6238 | ||
1bfb5f8f JM |
6239 | /* Leave the marks on the main CU, so we can check them in |
6240 | output_pubnames. */ | |
881c6935 | 6241 | if (die->die_symbol) |
1bfb5f8f | 6242 | unmark_dies (die); |
881c6935 JM |
6243 | } |
6244 | ||
a1d7ffe3 JM |
6245 | /* The DWARF2 pubname for a nested thingy looks like "A::f". The output |
6246 | of decl_printable_name for C++ looks like "A::f(int)". Let's drop the | |
6247 | argument list, and maybe the scope. */ | |
6248 | ||
d560ee52 | 6249 | static const char * |
a1d7ffe3 JM |
6250 | dwarf2_name (decl, scope) |
6251 | tree decl; | |
6252 | int scope; | |
6253 | { | |
6254 | return (*decl_printable_name) (decl, scope ? 1 : 0); | |
6255 | } | |
6256 | ||
d291dd49 | 6257 | /* Add a new entry to .debug_pubnames if appropriate. */ |
71dfc51f | 6258 | |
d291dd49 JM |
6259 | static void |
6260 | add_pubname (decl, die) | |
6261 | tree decl; | |
6262 | dw_die_ref die; | |
6263 | { | |
6264 | pubname_ref p; | |
6265 | ||
6266 | if (! TREE_PUBLIC (decl)) | |
6267 | return; | |
6268 | ||
6269 | if (pubname_table_in_use == pubname_table_allocated) | |
6270 | { | |
6271 | pubname_table_allocated += PUBNAME_TABLE_INCREMENT; | |
6272 | pubname_table = (pubname_ref) xrealloc | |
6273 | (pubname_table, pubname_table_allocated * sizeof (pubname_entry)); | |
6274 | } | |
71dfc51f | 6275 | |
d291dd49 JM |
6276 | p = &pubname_table[pubname_table_in_use++]; |
6277 | p->die = die; | |
a1d7ffe3 JM |
6278 | |
6279 | p->name = xstrdup (dwarf2_name (decl, 1)); | |
d291dd49 JM |
6280 | } |
6281 | ||
a3f97cbb JW |
6282 | /* Output the public names table used to speed up access to externally |
6283 | visible names. For now, only generate entries for externally | |
6284 | visible procedures. */ | |
71dfc51f | 6285 | |
a3f97cbb JW |
6286 | static void |
6287 | output_pubnames () | |
6288 | { | |
d291dd49 | 6289 | register unsigned i; |
71dfc51f RK |
6290 | register unsigned long pubnames_length = size_of_pubnames (); |
6291 | ||
2e4b9b8c RH |
6292 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, |
6293 | "Length of Public Names Info"); | |
71dfc51f | 6294 | |
2e4b9b8c | 6295 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
71dfc51f | 6296 | |
2e4b9b8c RH |
6297 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
6298 | "Offset of Compilation Unit Info"); | |
71dfc51f | 6299 | |
2e4b9b8c RH |
6300 | dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset, |
6301 | "Compilation Unit Length"); | |
71dfc51f | 6302 | |
d291dd49 | 6303 | for (i = 0; i < pubname_table_in_use; ++i) |
a3f97cbb | 6304 | { |
d291dd49 | 6305 | register pubname_ref pub = &pubname_table[i]; |
71dfc51f | 6306 | |
881c6935 | 6307 | /* We shouldn't see pubnames for DIEs outside of the main CU. */ |
1bfb5f8f | 6308 | if (pub->die->die_mark == 0) |
881c6935 JM |
6309 | abort (); |
6310 | ||
2e4b9b8c RH |
6311 | dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset, |
6312 | "DIE offset"); | |
71dfc51f | 6313 | |
2e4b9b8c | 6314 | dw2_asm_output_nstring (pub->name, -1, "external name"); |
a3f97cbb | 6315 | } |
71dfc51f | 6316 | |
2e4b9b8c | 6317 | dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL); |
a3f97cbb JW |
6318 | } |
6319 | ||
d291dd49 | 6320 | /* Add a new entry to .debug_aranges if appropriate. */ |
71dfc51f | 6321 | |
d291dd49 JM |
6322 | static void |
6323 | add_arange (decl, die) | |
6324 | tree decl; | |
6325 | dw_die_ref die; | |
6326 | { | |
6327 | if (! DECL_SECTION_NAME (decl)) | |
6328 | return; | |
6329 | ||
6330 | if (arange_table_in_use == arange_table_allocated) | |
6331 | { | |
6332 | arange_table_allocated += ARANGE_TABLE_INCREMENT; | |
71dfc51f RK |
6333 | arange_table |
6334 | = (arange_ref) xrealloc (arange_table, | |
6335 | arange_table_allocated * sizeof (dw_die_ref)); | |
d291dd49 | 6336 | } |
71dfc51f | 6337 | |
d291dd49 JM |
6338 | arange_table[arange_table_in_use++] = die; |
6339 | } | |
6340 | ||
a3f97cbb JW |
6341 | /* Output the information that goes into the .debug_aranges table. |
6342 | Namely, define the beginning and ending address range of the | |
6343 | text section generated for this compilation unit. */ | |
71dfc51f | 6344 | |
a3f97cbb JW |
6345 | static void |
6346 | output_aranges () | |
6347 | { | |
d291dd49 | 6348 | register unsigned i; |
71dfc51f RK |
6349 | register unsigned long aranges_length = size_of_aranges (); |
6350 | ||
2e4b9b8c RH |
6351 | dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length, |
6352 | "Length of Address Ranges Info"); | |
71dfc51f | 6353 | |
2e4b9b8c | 6354 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
71dfc51f | 6355 | |
2e4b9b8c RH |
6356 | dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, |
6357 | "Offset of Compilation Unit Info"); | |
71dfc51f | 6358 | |
2e4b9b8c | 6359 | dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address"); |
71dfc51f | 6360 | |
2e4b9b8c | 6361 | dw2_asm_output_data (1, 0, "Size of Segment Descriptor"); |
71dfc51f | 6362 | |
262b6384 SC |
6363 | /* We need to align to twice the pointer size here. */ |
6364 | if (DWARF_ARANGES_PAD_SIZE) | |
6365 | { | |
2e4b9b8c RH |
6366 | /* Pad using a 2 byte words so that padding is correct for any |
6367 | pointer size. */ | |
6368 | dw2_asm_output_data (2, 0, "Pad to %d byte boundary", | |
6369 | 2 * DWARF2_ADDR_SIZE); | |
770ca8c6 | 6370 | for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2) |
2e4b9b8c | 6371 | dw2_asm_output_data (2, 0, NULL); |
262b6384 | 6372 | } |
71dfc51f | 6373 | |
8e7fa2c8 | 6374 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address"); |
2e4b9b8c RH |
6375 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label, |
6376 | text_section_label, "Length"); | |
71dfc51f | 6377 | |
d291dd49 JM |
6378 | for (i = 0; i < arange_table_in_use; ++i) |
6379 | { | |
e689ae67 | 6380 | dw_die_ref die = arange_table[i]; |
71dfc51f | 6381 | |
881c6935 | 6382 | /* We shouldn't see aranges for DIEs outside of the main CU. */ |
1bfb5f8f | 6383 | if (die->die_mark == 0) |
881c6935 JM |
6384 | abort (); |
6385 | ||
e689ae67 | 6386 | if (die->die_tag == DW_TAG_subprogram) |
2e4b9b8c | 6387 | { |
8e7fa2c8 | 6388 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die), |
2e4b9b8c RH |
6389 | "Address"); |
6390 | dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die), | |
6391 | get_AT_low_pc (die), "Length"); | |
6392 | } | |
d291dd49 | 6393 | else |
a1d7ffe3 | 6394 | { |
e689ae67 JM |
6395 | /* A static variable; extract the symbol from DW_AT_location. |
6396 | Note that this code isn't currently hit, as we only emit | |
6397 | aranges for functions (jason 9/23/99). */ | |
71dfc51f | 6398 | |
e689ae67 JM |
6399 | dw_attr_ref a = get_AT (die, DW_AT_location); |
6400 | dw_loc_descr_ref loc; | |
a96c67ec | 6401 | if (! a || AT_class (a) != dw_val_class_loc) |
e689ae67 JM |
6402 | abort (); |
6403 | ||
a96c67ec | 6404 | loc = AT_loc (a); |
e689ae67 JM |
6405 | if (loc->dw_loc_opc != DW_OP_addr) |
6406 | abort (); | |
6407 | ||
2e4b9b8c RH |
6408 | dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, |
6409 | loc->dw_loc_oprnd1.v.val_addr, "Address"); | |
6410 | dw2_asm_output_data (DWARF2_ADDR_SIZE, | |
6411 | get_AT_unsigned (die, DW_AT_byte_size), | |
6412 | "Length"); | |
a1d7ffe3 | 6413 | } |
d291dd49 | 6414 | } |
71dfc51f | 6415 | |
a3f97cbb | 6416 | /* Output the terminator words. */ |
2e4b9b8c RH |
6417 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); |
6418 | dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); | |
a3f97cbb JW |
6419 | } |
6420 | ||
0b34cf1e UD |
6421 | |
6422 | /* Data structure containing information about input files. */ | |
6423 | struct file_info | |
6424 | { | |
6425 | char *path; /* Complete file name. */ | |
6426 | char *fname; /* File name part. */ | |
6427 | int length; /* Length of entire string. */ | |
6428 | int file_idx; /* Index in input file table. */ | |
6429 | int dir_idx; /* Index in directory table. */ | |
6430 | }; | |
6431 | ||
6432 | /* Data structure containing information about directories with source | |
6433 | files. */ | |
6434 | struct dir_info | |
6435 | { | |
6436 | char *path; /* Path including directory name. */ | |
6437 | int length; /* Path length. */ | |
6438 | int prefix; /* Index of directory entry which is a prefix. */ | |
0b34cf1e UD |
6439 | int count; /* Number of files in this directory. */ |
6440 | int dir_idx; /* Index of directory used as base. */ | |
6441 | int used; /* Used in the end? */ | |
6442 | }; | |
6443 | ||
6444 | /* Callback function for file_info comparison. We sort by looking at | |
6445 | the directories in the path. */ | |
6446 | static int | |
6447 | file_info_cmp (p1, p2) | |
6448 | const void *p1; | |
6449 | const void *p2; | |
6450 | { | |
6451 | const struct file_info *s1 = p1; | |
6452 | const struct file_info *s2 = p2; | |
6453 | unsigned char *cp1; | |
6454 | unsigned char *cp2; | |
6455 | ||
6456 | /* Take care of file names without directories. */ | |
6457 | if (s1->path == s1->fname) | |
6458 | return -1; | |
6459 | else if (s2->path == s2->fname) | |
6460 | return 1; | |
6461 | ||
6462 | cp1 = (unsigned char *) s1->path; | |
6463 | cp2 = (unsigned char *) s2->path; | |
6464 | ||
6465 | while (1) | |
6466 | { | |
6467 | ++cp1; | |
6468 | ++cp2; | |
6469 | /* Reached the end of the first path? */ | |
6470 | if (cp1 == (unsigned char *) s1->fname) | |
6471 | /* It doesn't really matter in which order files from the | |
6472 | same directory are sorted in. Therefore don't test for | |
6473 | the second path reaching the end. */ | |
6474 | return -1; | |
6475 | else if (cp2 == (unsigned char *) s2->fname) | |
6476 | return 1; | |
6477 | ||
6478 | /* Character of current path component the same? */ | |
6479 | if (*cp1 != *cp2) | |
6480 | return *cp1 - *cp2; | |
6481 | } | |
6482 | } | |
6483 | ||
6484 | /* Output the directory table and the file name table. We try to minimize | |
6485 | the total amount of memory needed. A heuristic is used to avoid large | |
6486 | slowdowns with many input files. */ | |
6487 | static void | |
6488 | output_file_names () | |
6489 | { | |
6490 | struct file_info *files; | |
6491 | struct dir_info *dirs; | |
6492 | int *saved; | |
6493 | int *savehere; | |
6494 | int *backmap; | |
6495 | int ndirs; | |
6496 | int idx_offset; | |
6497 | int i; | |
6498 | int idx; | |
6499 | ||
6500 | /* Allocate the various arrays we need. */ | |
981975b6 | 6501 | files = (struct file_info *) alloca (file_table.in_use |
0b34cf1e | 6502 | * sizeof (struct file_info)); |
981975b6 | 6503 | dirs = (struct dir_info *) alloca (file_table.in_use |
0b34cf1e UD |
6504 | * sizeof (struct dir_info)); |
6505 | ||
6506 | /* Sort the file names. */ | |
981975b6 | 6507 | for (i = 1; i < (int) file_table.in_use; ++i) |
0b34cf1e UD |
6508 | { |
6509 | char *f; | |
6510 | ||
6511 | /* Skip all leading "./". */ | |
981975b6 | 6512 | f = file_table.table[i]; |
0b34cf1e UD |
6513 | while (f[0] == '.' && f[1] == '/') |
6514 | f += 2; | |
6515 | ||
6516 | /* Create a new array entry. */ | |
6517 | files[i].path = f; | |
6518 | files[i].length = strlen (f); | |
6519 | files[i].file_idx = i; | |
6520 | ||
6521 | /* Search for the file name part. */ | |
6522 | f = strrchr (f, '/'); | |
6523 | files[i].fname = f == NULL ? files[i].path : f + 1; | |
6524 | } | |
981975b6 | 6525 | qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp); |
0b34cf1e UD |
6526 | |
6527 | /* Find all the different directories used. */ | |
6528 | dirs[0].path = files[1].path; | |
6529 | dirs[0].length = files[1].fname - files[1].path; | |
6530 | dirs[0].prefix = -1; | |
0b34cf1e UD |
6531 | dirs[0].count = 1; |
6532 | dirs[0].dir_idx = 0; | |
6533 | dirs[0].used = 0; | |
6534 | files[1].dir_idx = 0; | |
6535 | ndirs = 1; | |
6536 | ||
981975b6 | 6537 | for (i = 2; i < (int) file_table.in_use; ++i) |
0b34cf1e UD |
6538 | if (files[i].fname - files[i].path == dirs[ndirs - 1].length |
6539 | && memcmp (dirs[ndirs - 1].path, files[i].path, | |
6540 | dirs[ndirs - 1].length) == 0) | |
6541 | { | |
6542 | /* Same directory as last entry. */ | |
6543 | files[i].dir_idx = ndirs - 1; | |
0b34cf1e UD |
6544 | ++dirs[ndirs - 1].count; |
6545 | } | |
6546 | else | |
6547 | { | |
6548 | int j; | |
6549 | ||
6550 | /* This is a new directory. */ | |
6551 | dirs[ndirs].path = files[i].path; | |
6552 | dirs[ndirs].length = files[i].fname - files[i].path; | |
0b34cf1e UD |
6553 | dirs[ndirs].count = 1; |
6554 | dirs[ndirs].dir_idx = ndirs; | |
6555 | dirs[ndirs].used = 0; | |
6556 | files[i].dir_idx = ndirs; | |
6557 | ||
6558 | /* Search for a prefix. */ | |
981975b6 | 6559 | dirs[ndirs].prefix = -1; |
0b34cf1e | 6560 | for (j = 0; j < ndirs; ++j) |
981975b6 RH |
6561 | if (dirs[j].length < dirs[ndirs].length |
6562 | && dirs[j].length > 1 | |
6563 | && (dirs[ndirs].prefix == -1 | |
6564 | || dirs[j].length > dirs[dirs[ndirs].prefix].length) | |
6565 | && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0) | |
6566 | dirs[ndirs].prefix = j; | |
0b34cf1e UD |
6567 | |
6568 | ++ndirs; | |
6569 | } | |
6570 | ||
6571 | /* Now to the actual work. We have to find a subset of the | |
6572 | directories which allow expressing the file name using references | |
6573 | to the directory table with the least amount of characters. We | |
6574 | do not do an exhaustive search where we would have to check out | |
6575 | every combination of every single possible prefix. Instead we | |
6576 | use a heuristic which provides nearly optimal results in most | |
6577 | cases and never is much off. */ | |
6578 | saved = (int *) alloca (ndirs * sizeof (int)); | |
6579 | savehere = (int *) alloca (ndirs * sizeof (int)); | |
6580 | ||
6581 | memset (saved, '\0', ndirs * sizeof (saved[0])); | |
6582 | for (i = 0; i < ndirs; ++i) | |
6583 | { | |
6584 | int j; | |
6585 | int total; | |
6586 | ||
981975b6 | 6587 | /* We can always save some space for the current directory. But |
0b34cf1e UD |
6588 | this does not mean it will be enough to justify adding the |
6589 | directory. */ | |
6590 | savehere[i] = dirs[i].length; | |
6591 | total = (savehere[i] - saved[i]) * dirs[i].count; | |
6592 | ||
6593 | for (j = i + 1; j < ndirs; ++j) | |
6594 | { | |
6595 | savehere[j] = 0; | |
6596 | ||
6597 | if (saved[j] < dirs[i].length) | |
6598 | { | |
6599 | /* Determine whether the dirs[i] path is a prefix of the | |
6600 | dirs[j] path. */ | |
6601 | int k; | |
6602 | ||
981975b6 RH |
6603 | k = dirs[j].prefix; |
6604 | while (k != -1 && k != i) | |
6605 | k = dirs[k].prefix; | |
6606 | ||
6607 | if (k == i) | |
6608 | { | |
6609 | /* Yes it is. We can possibly safe some memory but | |
6610 | writing the filenames in dirs[j] relative to | |
6611 | dirs[i]. */ | |
6612 | savehere[j] = dirs[i].length; | |
6613 | total += (savehere[j] - saved[j]) * dirs[j].count; | |
6614 | } | |
0b34cf1e UD |
6615 | } |
6616 | } | |
6617 | ||
6618 | /* Check whether we can safe enough to justify adding the dirs[i] | |
6619 | directory. */ | |
6620 | if (total > dirs[i].length + 1) | |
6621 | { | |
981975b6 | 6622 | /* It's worthwhile adding. */ |
0b34cf1e UD |
6623 | for (j = i; j < ndirs; ++j) |
6624 | if (savehere[j] > 0) | |
6625 | { | |
6626 | /* Remember how much we saved for this directory so far. */ | |
6627 | saved[j] = savehere[j]; | |
6628 | ||
6629 | /* Remember the prefix directory. */ | |
6630 | dirs[j].dir_idx = i; | |
6631 | } | |
6632 | } | |
6633 | } | |
6634 | ||
981975b6 | 6635 | /* We have to emit them in the order they appear in the file_table |
0b34cf1e UD |
6636 | array since the index is used in the debug info generation. To |
6637 | do this efficiently we generate a back-mapping of the indices | |
6638 | first. */ | |
981975b6 RH |
6639 | backmap = (int *) alloca (file_table.in_use * sizeof (int)); |
6640 | for (i = 1; i < (int) file_table.in_use; ++i) | |
0b34cf1e UD |
6641 | { |
6642 | backmap[files[i].file_idx] = i; | |
6643 | /* Mark this directory as used. */ | |
6644 | dirs[dirs[files[i].dir_idx].dir_idx].used = 1; | |
6645 | } | |
6646 | ||
6647 | /* That was it. We are ready to emit the information. First the | |
6648 | directory name table. Here we have to make sure that the first | |
6649 | actually emitted directory name has the index one. Zero is | |
6650 | reserved for the current working directory. Make sure we do not | |
6651 | confuse these indices with the one for the constructed table | |
6652 | (even though most of the time they are identical). */ | |
6653 | idx = 1; | |
e57cabac | 6654 | idx_offset = dirs[0].length > 0 ? 1 : 0; |
0b34cf1e UD |
6655 | for (i = 1 - idx_offset; i < ndirs; ++i) |
6656 | if (dirs[i].used != 0) | |
6657 | { | |
6658 | dirs[i].used = idx++; | |
2e4b9b8c RH |
6659 | dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1, |
6660 | "Directory Entry: 0x%x", dirs[i].used); | |
0b34cf1e | 6661 | } |
2e4b9b8c RH |
6662 | dw2_asm_output_data (1, 0, "End directory table"); |
6663 | ||
0b34cf1e UD |
6664 | /* Correct the index for the current working directory entry if it |
6665 | exists. */ | |
6666 | if (idx_offset == 0) | |
6667 | dirs[0].used = 0; | |
0b34cf1e UD |
6668 | |
6669 | /* Now write all the file names. */ | |
981975b6 | 6670 | for (i = 1; i < (int) file_table.in_use; ++i) |
0b34cf1e UD |
6671 | { |
6672 | int file_idx = backmap[i]; | |
6673 | int dir_idx = dirs[files[file_idx].dir_idx].dir_idx; | |
6674 | ||
2e4b9b8c RH |
6675 | dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1, |
6676 | "File Entry: 0x%x", i); | |
0b34cf1e UD |
6677 | |
6678 | /* Include directory index. */ | |
2e4b9b8c | 6679 | dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL); |
0b34cf1e UD |
6680 | |
6681 | /* Modification time. */ | |
2e4b9b8c | 6682 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e UD |
6683 | |
6684 | /* File length in bytes. */ | |
2e4b9b8c | 6685 | dw2_asm_output_data_uleb128 (0, NULL); |
0b34cf1e | 6686 | } |
2e4b9b8c | 6687 | dw2_asm_output_data (1, 0, "End file name table"); |
0b34cf1e UD |
6688 | } |
6689 | ||
6690 | ||
a3f97cbb | 6691 | /* Output the source line number correspondence information. This |
14a774a9 | 6692 | information goes into the .debug_line section. */ |
71dfc51f | 6693 | |
a3f97cbb JW |
6694 | static void |
6695 | output_line_info () | |
6696 | { | |
981975b6 | 6697 | char l1[20], l2[20], p1[20], p2[20]; |
a3f97cbb JW |
6698 | char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
6699 | char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6700 | register unsigned opc; | |
6701 | register unsigned n_op_args; | |
a3f97cbb JW |
6702 | register unsigned long lt_index; |
6703 | register unsigned long current_line; | |
6704 | register long line_offset; | |
6705 | register long line_delta; | |
6706 | register unsigned long current_file; | |
e90b62db | 6707 | register unsigned long function; |
71dfc51f | 6708 | |
2e4b9b8c RH |
6709 | ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0); |
6710 | ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0); | |
981975b6 RH |
6711 | ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0); |
6712 | ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0); | |
71dfc51f | 6713 | |
2e4b9b8c RH |
6714 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1, |
6715 | "Length of Source Line Info"); | |
6716 | ASM_OUTPUT_LABEL (asm_out_file, l1); | |
71dfc51f | 6717 | |
2e4b9b8c | 6718 | dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); |
71dfc51f | 6719 | |
981975b6 RH |
6720 | dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length"); |
6721 | ASM_OUTPUT_LABEL (asm_out_file, p1); | |
71dfc51f | 6722 | |
2e4b9b8c RH |
6723 | dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH, |
6724 | "Minimum Instruction Length"); | |
71dfc51f | 6725 | |
2e4b9b8c RH |
6726 | dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START, |
6727 | "Default is_stmt_start flag"); | |
71dfc51f | 6728 | |
2e4b9b8c RH |
6729 | dw2_asm_output_data (1, DWARF_LINE_BASE, |
6730 | "Line Base Value (Special Opcodes)"); | |
71dfc51f | 6731 | |
2e4b9b8c RH |
6732 | dw2_asm_output_data (1, DWARF_LINE_RANGE, |
6733 | "Line Range Value (Special Opcodes)"); | |
6734 | ||
6735 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE, | |
6736 | "Special Opcode Base"); | |
71dfc51f | 6737 | |
a3f97cbb JW |
6738 | for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc) |
6739 | { | |
6740 | switch (opc) | |
6741 | { | |
6742 | case DW_LNS_advance_pc: | |
6743 | case DW_LNS_advance_line: | |
6744 | case DW_LNS_set_file: | |
6745 | case DW_LNS_set_column: | |
6746 | case DW_LNS_fixed_advance_pc: | |
6747 | n_op_args = 1; | |
6748 | break; | |
6749 | default: | |
6750 | n_op_args = 0; | |
6751 | break; | |
6752 | } | |
2e4b9b8c RH |
6753 | |
6754 | dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args", | |
6755 | opc, n_op_args); | |
a3f97cbb | 6756 | } |
71dfc51f | 6757 | |
0b34cf1e UD |
6758 | /* Write out the information about the files we use. */ |
6759 | output_file_names (); | |
981975b6 | 6760 | ASM_OUTPUT_LABEL (asm_out_file, p2); |
a3f97cbb | 6761 | |
2f22d404 JM |
6762 | /* We used to set the address register to the first location in the text |
6763 | section here, but that didn't accomplish anything since we already | |
6764 | have a line note for the opening brace of the first function. */ | |
a3f97cbb JW |
6765 | |
6766 | /* Generate the line number to PC correspondence table, encoded as | |
6767 | a series of state machine operations. */ | |
6768 | current_file = 1; | |
6769 | current_line = 1; | |
8b790721 | 6770 | strcpy (prev_line_label, text_section_label); |
a3f97cbb JW |
6771 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) |
6772 | { | |
2f22d404 JM |
6773 | register dw_line_info_ref line_info = &line_info_table[lt_index]; |
6774 | ||
10a11b75 JM |
6775 | #if 0 |
6776 | /* Disable this optimization for now; GDB wants to see two line notes | |
6777 | at the beginning of a function so it can find the end of the | |
6778 | prologue. */ | |
6779 | ||
2f22d404 JM |
6780 | /* Don't emit anything for redundant notes. Just updating the |
6781 | address doesn't accomplish anything, because we already assume | |
6782 | that anything after the last address is this line. */ | |
6783 | if (line_info->dw_line_num == current_line | |
6784 | && line_info->dw_file_num == current_file) | |
6785 | continue; | |
10a11b75 | 6786 | #endif |
71dfc51f | 6787 | |
2e4b9b8c RH |
6788 | /* Emit debug info for the address of the current line. |
6789 | ||
6790 | Unfortunately, we have little choice here currently, and must always | |
6791 | use the most general form. Gcc does not know the address delta | |
6792 | itself, so we can't use DW_LNS_advance_pc. Many ports do have length | |
6793 | attributes which will give an upper bound on the address range. We | |
6794 | could perhaps use length attributes to determine when it is safe to | |
6795 | use DW_LNS_fixed_advance_pc. */ | |
6796 | ||
5c90448c | 6797 | ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index); |
f19a6894 JW |
6798 | if (0) |
6799 | { | |
6800 | /* This can handle deltas up to 0xffff. This takes 3 bytes. */ | |
2e4b9b8c RH |
6801 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
6802 | "DW_LNS_fixed_advance_pc"); | |
6803 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
6804 | } |
6805 | else | |
6806 | { | |
a1a4189d JB |
6807 | /* This can handle any delta. This takes |
6808 | 4+DWARF2_ADDR_SIZE bytes. */ | |
2e4b9b8c RH |
6809 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
6810 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
6811 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 6812 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 JW |
6813 | } |
6814 | strcpy (prev_line_label, line_label); | |
6815 | ||
6816 | /* Emit debug info for the source file of the current line, if | |
6817 | different from the previous line. */ | |
a3f97cbb JW |
6818 | if (line_info->dw_file_num != current_file) |
6819 | { | |
6820 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
6821 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
6822 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
981975b6 | 6823 | file_table.table[current_file]); |
a3f97cbb | 6824 | } |
71dfc51f | 6825 | |
f19a6894 JW |
6826 | /* Emit debug info for the current line number, choosing the encoding |
6827 | that uses the least amount of space. */ | |
2f22d404 | 6828 | if (line_info->dw_line_num != current_line) |
a3f97cbb | 6829 | { |
2f22d404 JM |
6830 | line_offset = line_info->dw_line_num - current_line; |
6831 | line_delta = line_offset - DWARF_LINE_BASE; | |
6832 | current_line = line_info->dw_line_num; | |
6833 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
6834 | { | |
6835 | /* This can handle deltas from -10 to 234, using the current | |
6836 | definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This | |
6837 | takes 1 byte. */ | |
2e4b9b8c RH |
6838 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, |
6839 | "line %lu", current_line); | |
2f22d404 JM |
6840 | } |
6841 | else | |
6842 | { | |
6843 | /* This can handle any delta. This takes at least 4 bytes, | |
6844 | depending on the value being encoded. */ | |
2e4b9b8c RH |
6845 | dw2_asm_output_data (1, DW_LNS_advance_line, |
6846 | "advance to line %lu", current_line); | |
6847 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
6848 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
2f22d404 | 6849 | } |
a94dbf2c JM |
6850 | } |
6851 | else | |
6852 | { | |
2f22d404 | 6853 | /* We still need to start a new row, so output a copy insn. */ |
2e4b9b8c | 6854 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); |
a3f97cbb | 6855 | } |
a3f97cbb JW |
6856 | } |
6857 | ||
f19a6894 JW |
6858 | /* Emit debug info for the address of the end of the function. */ |
6859 | if (0) | |
6860 | { | |
2e4b9b8c RH |
6861 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
6862 | "DW_LNS_fixed_advance_pc"); | |
6863 | dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL); | |
f19a6894 JW |
6864 | } |
6865 | else | |
6866 | { | |
2e4b9b8c RH |
6867 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
6868 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
6869 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 6870 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL); |
f19a6894 | 6871 | } |
bdb669cb | 6872 | |
2e4b9b8c RH |
6873 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
6874 | dw2_asm_output_data_uleb128 (1, NULL); | |
6875 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
6876 | |
6877 | function = 0; | |
6878 | current_file = 1; | |
6879 | current_line = 1; | |
556273e0 | 6880 | for (lt_index = 0; lt_index < separate_line_info_table_in_use;) |
e90b62db JM |
6881 | { |
6882 | register dw_separate_line_info_ref line_info | |
6883 | = &separate_line_info_table[lt_index]; | |
71dfc51f | 6884 | |
10a11b75 | 6885 | #if 0 |
2f22d404 JM |
6886 | /* Don't emit anything for redundant notes. */ |
6887 | if (line_info->dw_line_num == current_line | |
6888 | && line_info->dw_file_num == current_file | |
6889 | && line_info->function == function) | |
6890 | goto cont; | |
10a11b75 | 6891 | #endif |
2f22d404 | 6892 | |
f19a6894 JW |
6893 | /* Emit debug info for the address of the current line. If this is |
6894 | a new function, or the first line of a function, then we need | |
6895 | to handle it differently. */ | |
5c90448c JM |
6896 | ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL, |
6897 | lt_index); | |
e90b62db JM |
6898 | if (function != line_info->function) |
6899 | { | |
6900 | function = line_info->function; | |
71dfc51f | 6901 | |
e90b62db | 6902 | /* Set the address register to the first line in the function */ |
2e4b9b8c RH |
6903 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
6904 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
6905 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 6906 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
e90b62db JM |
6907 | } |
6908 | else | |
6909 | { | |
f19a6894 JW |
6910 | /* ??? See the DW_LNS_advance_pc comment above. */ |
6911 | if (0) | |
6912 | { | |
2e4b9b8c RH |
6913 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
6914 | "DW_LNS_fixed_advance_pc"); | |
6915 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
6916 | } |
6917 | else | |
6918 | { | |
2e4b9b8c RH |
6919 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
6920 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
6921 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 6922 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 6923 | } |
e90b62db | 6924 | } |
f19a6894 | 6925 | strcpy (prev_line_label, line_label); |
71dfc51f | 6926 | |
f19a6894 JW |
6927 | /* Emit debug info for the source file of the current line, if |
6928 | different from the previous line. */ | |
e90b62db JM |
6929 | if (line_info->dw_file_num != current_file) |
6930 | { | |
6931 | current_file = line_info->dw_file_num; | |
2e4b9b8c RH |
6932 | dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); |
6933 | dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", | |
981975b6 | 6934 | file_table.table[current_file]); |
e90b62db | 6935 | } |
71dfc51f | 6936 | |
f19a6894 JW |
6937 | /* Emit debug info for the current line number, choosing the encoding |
6938 | that uses the least amount of space. */ | |
e90b62db JM |
6939 | if (line_info->dw_line_num != current_line) |
6940 | { | |
6941 | line_offset = line_info->dw_line_num - current_line; | |
6942 | line_delta = line_offset - DWARF_LINE_BASE; | |
6943 | current_line = line_info->dw_line_num; | |
6944 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
2e4b9b8c RH |
6945 | dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, |
6946 | "line %lu", current_line); | |
e90b62db JM |
6947 | else |
6948 | { | |
2e4b9b8c RH |
6949 | dw2_asm_output_data (1, DW_LNS_advance_line, |
6950 | "advance to line %lu", current_line); | |
6951 | dw2_asm_output_data_sleb128 (line_offset, NULL); | |
6952 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); | |
e90b62db JM |
6953 | } |
6954 | } | |
2f22d404 | 6955 | else |
2e4b9b8c | 6956 | dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); |
71dfc51f | 6957 | |
10a11b75 | 6958 | #if 0 |
2f22d404 | 6959 | cont: |
10a11b75 | 6960 | #endif |
e90b62db | 6961 | ++lt_index; |
e90b62db JM |
6962 | |
6963 | /* If we're done with a function, end its sequence. */ | |
6964 | if (lt_index == separate_line_info_table_in_use | |
6965 | || separate_line_info_table[lt_index].function != function) | |
6966 | { | |
6967 | current_file = 1; | |
6968 | current_line = 1; | |
71dfc51f | 6969 | |
f19a6894 | 6970 | /* Emit debug info for the address of the end of the function. */ |
5c90448c | 6971 | ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function); |
f19a6894 JW |
6972 | if (0) |
6973 | { | |
2e4b9b8c RH |
6974 | dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, |
6975 | "DW_LNS_fixed_advance_pc"); | |
6976 | dw2_asm_output_delta (2, line_label, prev_line_label, NULL); | |
f19a6894 JW |
6977 | } |
6978 | else | |
6979 | { | |
2e4b9b8c RH |
6980 | dw2_asm_output_data (1, 0, "DW_LNE_set_address"); |
6981 | dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); | |
6982 | dw2_asm_output_data (1, DW_LNE_set_address, NULL); | |
8e7fa2c8 | 6983 | dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); |
f19a6894 | 6984 | } |
e90b62db JM |
6985 | |
6986 | /* Output the marker for the end of this sequence. */ | |
2e4b9b8c RH |
6987 | dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); |
6988 | dw2_asm_output_data_uleb128 (1, NULL); | |
6989 | dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); | |
e90b62db JM |
6990 | } |
6991 | } | |
f19f17e0 JM |
6992 | |
6993 | /* Output the marker for the end of the line number info. */ | |
2e4b9b8c | 6994 | ASM_OUTPUT_LABEL (asm_out_file, l2); |
a3f97cbb JW |
6995 | } |
6996 | \f | |
a3f97cbb JW |
6997 | /* Given a pointer to a tree node for some base type, return a pointer to |
6998 | a DIE that describes the given type. | |
6999 | ||
7000 | This routine must only be called for GCC type nodes that correspond to | |
7001 | Dwarf base (fundamental) types. */ | |
71dfc51f | 7002 | |
a3f97cbb JW |
7003 | static dw_die_ref |
7004 | base_type_die (type) | |
7005 | register tree type; | |
7006 | { | |
a9d38797 | 7007 | register dw_die_ref base_type_result; |
ec0ce6e2 | 7008 | register const char *type_name; |
a9d38797 | 7009 | register enum dwarf_type encoding; |
71dfc51f | 7010 | register tree name = TYPE_NAME (type); |
a3f97cbb | 7011 | |
a9d38797 JM |
7012 | if (TREE_CODE (type) == ERROR_MARK |
7013 | || TREE_CODE (type) == VOID_TYPE) | |
a3f97cbb JW |
7014 | return 0; |
7015 | ||
405f63da MM |
7016 | if (name) |
7017 | { | |
7018 | if (TREE_CODE (name) == TYPE_DECL) | |
7019 | name = DECL_NAME (name); | |
7020 | ||
7021 | type_name = IDENTIFIER_POINTER (name); | |
7022 | } | |
7023 | else | |
7024 | type_name = "__unknown__"; | |
a9d38797 | 7025 | |
a3f97cbb JW |
7026 | switch (TREE_CODE (type)) |
7027 | { | |
a3f97cbb | 7028 | case INTEGER_TYPE: |
a9d38797 | 7029 | /* Carefully distinguish the C character types, without messing |
a3f97cbb | 7030 | up if the language is not C. Note that we check only for the names |
556273e0 | 7031 | that contain spaces; other names might occur by coincidence in other |
a3f97cbb | 7032 | languages. */ |
a9d38797 JM |
7033 | if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE |
7034 | && (type == char_type_node | |
7035 | || ! strcmp (type_name, "signed char") | |
7036 | || ! strcmp (type_name, "unsigned char")))) | |
a3f97cbb | 7037 | { |
a9d38797 JM |
7038 | if (TREE_UNSIGNED (type)) |
7039 | encoding = DW_ATE_unsigned; | |
7040 | else | |
7041 | encoding = DW_ATE_signed; | |
7042 | break; | |
a3f97cbb | 7043 | } |
556273e0 | 7044 | /* else fall through. */ |
a3f97cbb | 7045 | |
a9d38797 JM |
7046 | case CHAR_TYPE: |
7047 | /* GNU Pascal/Ada CHAR type. Not used in C. */ | |
7048 | if (TREE_UNSIGNED (type)) | |
7049 | encoding = DW_ATE_unsigned_char; | |
7050 | else | |
7051 | encoding = DW_ATE_signed_char; | |
a3f97cbb JW |
7052 | break; |
7053 | ||
7054 | case REAL_TYPE: | |
a9d38797 | 7055 | encoding = DW_ATE_float; |
a3f97cbb JW |
7056 | break; |
7057 | ||
405f63da MM |
7058 | /* Dwarf2 doesn't know anything about complex ints, so use |
7059 | a user defined type for it. */ | |
a3f97cbb | 7060 | case COMPLEX_TYPE: |
405f63da MM |
7061 | if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE) |
7062 | encoding = DW_ATE_complex_float; | |
7063 | else | |
7064 | encoding = DW_ATE_lo_user; | |
a3f97cbb JW |
7065 | break; |
7066 | ||
7067 | case BOOLEAN_TYPE: | |
a9d38797 JM |
7068 | /* GNU FORTRAN/Ada/C++ BOOLEAN type. */ |
7069 | encoding = DW_ATE_boolean; | |
a3f97cbb JW |
7070 | break; |
7071 | ||
7072 | default: | |
a9d38797 | 7073 | abort (); /* No other TREE_CODEs are Dwarf fundamental types. */ |
a3f97cbb JW |
7074 | } |
7075 | ||
a9d38797 | 7076 | base_type_result = new_die (DW_TAG_base_type, comp_unit_die); |
14a774a9 RK |
7077 | if (demangle_name_func) |
7078 | type_name = (*demangle_name_func) (type_name); | |
7079 | ||
a9d38797 JM |
7080 | add_AT_string (base_type_result, DW_AT_name, type_name); |
7081 | add_AT_unsigned (base_type_result, DW_AT_byte_size, | |
4e5a8d7b | 7082 | int_size_in_bytes (type)); |
a9d38797 | 7083 | add_AT_unsigned (base_type_result, DW_AT_encoding, encoding); |
a3f97cbb JW |
7084 | |
7085 | return base_type_result; | |
7086 | } | |
7087 | ||
7088 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to | |
7089 | the Dwarf "root" type for the given input type. The Dwarf "root" type of | |
7090 | a given type is generally the same as the given type, except that if the | |
7091 | given type is a pointer or reference type, then the root type of the given | |
7092 | type is the root type of the "basis" type for the pointer or reference | |
7093 | type. (This definition of the "root" type is recursive.) Also, the root | |
7094 | type of a `const' qualified type or a `volatile' qualified type is the | |
7095 | root type of the given type without the qualifiers. */ | |
71dfc51f | 7096 | |
a3f97cbb JW |
7097 | static tree |
7098 | root_type (type) | |
7099 | register tree type; | |
7100 | { | |
7101 | if (TREE_CODE (type) == ERROR_MARK) | |
7102 | return error_mark_node; | |
7103 | ||
7104 | switch (TREE_CODE (type)) | |
7105 | { | |
7106 | case ERROR_MARK: | |
7107 | return error_mark_node; | |
7108 | ||
7109 | case POINTER_TYPE: | |
7110 | case REFERENCE_TYPE: | |
7111 | return type_main_variant (root_type (TREE_TYPE (type))); | |
7112 | ||
7113 | default: | |
7114 | return type_main_variant (type); | |
7115 | } | |
7116 | } | |
7117 | ||
7118 | /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the | |
7119 | given input type is a Dwarf "fundamental" type. Otherwise return null. */ | |
71dfc51f RK |
7120 | |
7121 | static inline int | |
a3f97cbb JW |
7122 | is_base_type (type) |
7123 | register tree type; | |
7124 | { | |
7125 | switch (TREE_CODE (type)) | |
7126 | { | |
7127 | case ERROR_MARK: | |
7128 | case VOID_TYPE: | |
7129 | case INTEGER_TYPE: | |
7130 | case REAL_TYPE: | |
7131 | case COMPLEX_TYPE: | |
7132 | case BOOLEAN_TYPE: | |
7133 | case CHAR_TYPE: | |
7134 | return 1; | |
7135 | ||
7136 | case SET_TYPE: | |
7137 | case ARRAY_TYPE: | |
7138 | case RECORD_TYPE: | |
7139 | case UNION_TYPE: | |
7140 | case QUAL_UNION_TYPE: | |
7141 | case ENUMERAL_TYPE: | |
7142 | case FUNCTION_TYPE: | |
7143 | case METHOD_TYPE: | |
7144 | case POINTER_TYPE: | |
7145 | case REFERENCE_TYPE: | |
7146 | case FILE_TYPE: | |
7147 | case OFFSET_TYPE: | |
7148 | case LANG_TYPE: | |
604bb87d | 7149 | case VECTOR_TYPE: |
a3f97cbb JW |
7150 | return 0; |
7151 | ||
7152 | default: | |
7153 | abort (); | |
7154 | } | |
71dfc51f | 7155 | |
a3f97cbb JW |
7156 | return 0; |
7157 | } | |
7158 | ||
7159 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging | |
7160 | entry that chains various modifiers in front of the given type. */ | |
71dfc51f | 7161 | |
a3f97cbb JW |
7162 | static dw_die_ref |
7163 | modified_type_die (type, is_const_type, is_volatile_type, context_die) | |
7164 | register tree type; | |
7165 | register int is_const_type; | |
7166 | register int is_volatile_type; | |
7167 | register dw_die_ref context_die; | |
7168 | { | |
7169 | register enum tree_code code = TREE_CODE (type); | |
7170 | register dw_die_ref mod_type_die = NULL; | |
7171 | register dw_die_ref sub_die = NULL; | |
dfcf9891 | 7172 | register tree item_type = NULL; |
a3f97cbb JW |
7173 | |
7174 | if (code != ERROR_MARK) | |
7175 | { | |
5101b304 MM |
7176 | tree qualified_type; |
7177 | ||
7178 | /* See if we already have the appropriately qualified variant of | |
7179 | this type. */ | |
7180 | qualified_type | |
7181 | = get_qualified_type (type, | |
7182 | ((is_const_type ? TYPE_QUAL_CONST : 0) | |
7183 | | (is_volatile_type | |
7184 | ? TYPE_QUAL_VOLATILE : 0))); | |
7185 | /* If we do, then we can just use its DIE, if it exists. */ | |
7186 | if (qualified_type) | |
7187 | { | |
7188 | mod_type_die = lookup_type_die (qualified_type); | |
7189 | if (mod_type_die) | |
7190 | return mod_type_die; | |
7191 | } | |
bdb669cb | 7192 | |
556273e0 | 7193 | /* Handle C typedef types. */ |
5101b304 MM |
7194 | if (qualified_type && TYPE_NAME (qualified_type) |
7195 | && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL | |
7196 | && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type))) | |
a94dbf2c | 7197 | { |
5101b304 MM |
7198 | tree type_name = TYPE_NAME (qualified_type); |
7199 | tree dtype = TREE_TYPE (type_name); | |
7200 | if (qualified_type == dtype) | |
a94dbf2c JM |
7201 | { |
7202 | /* For a named type, use the typedef. */ | |
5101b304 MM |
7203 | gen_type_die (qualified_type, context_die); |
7204 | mod_type_die = lookup_type_die (qualified_type); | |
a94dbf2c | 7205 | } |
71dfc51f | 7206 | |
a94dbf2c JM |
7207 | else if (is_const_type < TYPE_READONLY (dtype) |
7208 | || is_volatile_type < TYPE_VOLATILE (dtype)) | |
7209 | /* cv-unqualified version of named type. Just use the unnamed | |
7210 | type to which it refers. */ | |
71dfc51f | 7211 | mod_type_die |
5101b304 | 7212 | = modified_type_die (DECL_ORIGINAL_TYPE (type_name), |
71dfc51f RK |
7213 | is_const_type, is_volatile_type, |
7214 | context_die); | |
7215 | /* Else cv-qualified version of named type; fall through. */ | |
a94dbf2c JM |
7216 | } |
7217 | ||
7218 | if (mod_type_die) | |
556273e0 KH |
7219 | /* OK. */ |
7220 | ; | |
a94dbf2c | 7221 | else if (is_const_type) |
a3f97cbb | 7222 | { |
ab72d377 | 7223 | mod_type_die = new_die (DW_TAG_const_type, comp_unit_die); |
a9d38797 | 7224 | sub_die = modified_type_die (type, 0, is_volatile_type, context_die); |
a3f97cbb JW |
7225 | } |
7226 | else if (is_volatile_type) | |
7227 | { | |
ab72d377 | 7228 | mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die); |
a9d38797 | 7229 | sub_die = modified_type_die (type, 0, 0, context_die); |
a3f97cbb JW |
7230 | } |
7231 | else if (code == POINTER_TYPE) | |
7232 | { | |
ab72d377 | 7233 | mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die); |
a3f97cbb | 7234 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 7235 | #if 0 |
a3f97cbb | 7236 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
61b32c02 | 7237 | #endif |
a3f97cbb | 7238 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
7239 | } |
7240 | else if (code == REFERENCE_TYPE) | |
7241 | { | |
ab72d377 | 7242 | mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die); |
a3f97cbb | 7243 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 7244 | #if 0 |
a3f97cbb | 7245 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
556273e0 | 7246 | #endif |
a3f97cbb | 7247 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
7248 | } |
7249 | else if (is_base_type (type)) | |
71dfc51f | 7250 | mod_type_die = base_type_die (type); |
a3f97cbb JW |
7251 | else |
7252 | { | |
4b674448 JM |
7253 | gen_type_die (type, context_die); |
7254 | ||
a3f97cbb JW |
7255 | /* We have to get the type_main_variant here (and pass that to the |
7256 | `lookup_type_die' routine) because the ..._TYPE node we have | |
7257 | might simply be a *copy* of some original type node (where the | |
7258 | copy was created to help us keep track of typedef names) and | |
7259 | that copy might have a different TYPE_UID from the original | |
a94dbf2c | 7260 | ..._TYPE node. */ |
a3f97cbb | 7261 | mod_type_die = lookup_type_die (type_main_variant (type)); |
3a88cbd1 JL |
7262 | if (mod_type_die == NULL) |
7263 | abort (); | |
a3f97cbb | 7264 | } |
3d2999ba MK |
7265 | |
7266 | /* We want to equate the qualified type to the die below. */ | |
7267 | if (qualified_type) | |
7268 | type = qualified_type; | |
a3f97cbb | 7269 | } |
71dfc51f | 7270 | |
dfcf9891 JW |
7271 | equate_type_number_to_die (type, mod_type_die); |
7272 | if (item_type) | |
71dfc51f RK |
7273 | /* We must do this after the equate_type_number_to_die call, in case |
7274 | this is a recursive type. This ensures that the modified_type_die | |
7275 | recursion will terminate even if the type is recursive. Recursive | |
7276 | types are possible in Ada. */ | |
7277 | sub_die = modified_type_die (item_type, | |
7278 | TYPE_READONLY (item_type), | |
7279 | TYPE_VOLATILE (item_type), | |
7280 | context_die); | |
7281 | ||
a3f97cbb | 7282 | if (sub_die != NULL) |
71dfc51f RK |
7283 | add_AT_die_ref (mod_type_die, DW_AT_type, sub_die); |
7284 | ||
a3f97cbb JW |
7285 | return mod_type_die; |
7286 | } | |
7287 | ||
a3f97cbb JW |
7288 | /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is |
7289 | an enumerated type. */ | |
71dfc51f RK |
7290 | |
7291 | static inline int | |
a3f97cbb JW |
7292 | type_is_enum (type) |
7293 | register tree type; | |
7294 | { | |
7295 | return TREE_CODE (type) == ENUMERAL_TYPE; | |
7296 | } | |
7297 | ||
7d9d8943 AM |
7298 | /* Return the register number described by a given RTL node. */ |
7299 | ||
7300 | static unsigned int | |
7301 | reg_number (rtl) | |
7302 | register rtx rtl; | |
7303 | { | |
7304 | register unsigned regno = REGNO (rtl); | |
7305 | ||
7306 | if (regno >= FIRST_PSEUDO_REGISTER) | |
7307 | { | |
7308 | warning ("internal regno botch: regno = %d\n", regno); | |
7309 | regno = 0; | |
7310 | } | |
7311 | ||
7312 | regno = DBX_REGISTER_NUMBER (regno); | |
7313 | return regno; | |
7314 | } | |
7315 | ||
a3f97cbb | 7316 | /* Return a location descriptor that designates a machine register. */ |
71dfc51f | 7317 | |
a3f97cbb JW |
7318 | static dw_loc_descr_ref |
7319 | reg_loc_descriptor (rtl) | |
7320 | register rtx rtl; | |
7321 | { | |
7322 | register dw_loc_descr_ref loc_result = NULL; | |
7323 | register unsigned reg = reg_number (rtl); | |
71dfc51f | 7324 | |
85066503 | 7325 | if (reg <= 31) |
71dfc51f | 7326 | loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0); |
a3f97cbb | 7327 | else |
71dfc51f RK |
7328 | loc_result = new_loc_descr (DW_OP_regx, reg, 0); |
7329 | ||
a3f97cbb JW |
7330 | return loc_result; |
7331 | } | |
7332 | ||
d8041cc8 RH |
7333 | /* Return a location descriptor that designates a constant. */ |
7334 | ||
7335 | static dw_loc_descr_ref | |
7336 | int_loc_descriptor (i) | |
7337 | HOST_WIDE_INT i; | |
7338 | { | |
7339 | enum dwarf_location_atom op; | |
7340 | ||
7341 | /* Pick the smallest representation of a constant, rather than just | |
7342 | defaulting to the LEB encoding. */ | |
7343 | if (i >= 0) | |
7344 | { | |
7345 | if (i <= 31) | |
7346 | op = DW_OP_lit0 + i; | |
7347 | else if (i <= 0xff) | |
7348 | op = DW_OP_const1u; | |
7349 | else if (i <= 0xffff) | |
7350 | op = DW_OP_const2u; | |
7351 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
7352 | || i <= 0xffffffff) | |
7353 | op = DW_OP_const4u; | |
7354 | else | |
7355 | op = DW_OP_constu; | |
7356 | } | |
7357 | else | |
7358 | { | |
7359 | if (i >= -0x80) | |
7360 | op = DW_OP_const1s; | |
7361 | else if (i >= -0x8000) | |
7362 | op = DW_OP_const2s; | |
7363 | else if (HOST_BITS_PER_WIDE_INT == 32 | |
7364 | || i >= -0x80000000) | |
7365 | op = DW_OP_const4s; | |
7366 | else | |
7367 | op = DW_OP_consts; | |
7368 | } | |
7369 | ||
7370 | return new_loc_descr (op, i, 0); | |
7371 | } | |
7372 | ||
a3f97cbb | 7373 | /* Return a location descriptor that designates a base+offset location. */ |
71dfc51f | 7374 | |
a3f97cbb JW |
7375 | static dw_loc_descr_ref |
7376 | based_loc_descr (reg, offset) | |
7377 | unsigned reg; | |
7378 | long int offset; | |
7379 | { | |
7380 | register dw_loc_descr_ref loc_result; | |
810429b7 JM |
7381 | /* For the "frame base", we use the frame pointer or stack pointer |
7382 | registers, since the RTL for local variables is relative to one of | |
7383 | them. */ | |
7384 | register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed | |
b1ccbc24 | 7385 | ? HARD_FRAME_POINTER_REGNUM |
810429b7 | 7386 | : STACK_POINTER_REGNUM); |
71dfc51f | 7387 | |
a3f97cbb | 7388 | if (reg == fp_reg) |
71dfc51f | 7389 | loc_result = new_loc_descr (DW_OP_fbreg, offset, 0); |
85066503 | 7390 | else if (reg <= 31) |
71dfc51f | 7391 | loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0); |
a3f97cbb | 7392 | else |
71dfc51f RK |
7393 | loc_result = new_loc_descr (DW_OP_bregx, reg, offset); |
7394 | ||
a3f97cbb JW |
7395 | return loc_result; |
7396 | } | |
7397 | ||
7398 | /* Return true if this RTL expression describes a base+offset calculation. */ | |
71dfc51f RK |
7399 | |
7400 | static inline int | |
a3f97cbb JW |
7401 | is_based_loc (rtl) |
7402 | register rtx rtl; | |
7403 | { | |
71dfc51f RK |
7404 | return (GET_CODE (rtl) == PLUS |
7405 | && ((GET_CODE (XEXP (rtl, 0)) == REG | |
7406 | && GET_CODE (XEXP (rtl, 1)) == CONST_INT))); | |
a3f97cbb JW |
7407 | } |
7408 | ||
7409 | /* The following routine converts the RTL for a variable or parameter | |
7410 | (resident in memory) into an equivalent Dwarf representation of a | |
7411 | mechanism for getting the address of that same variable onto the top of a | |
7412 | hypothetical "address evaluation" stack. | |
71dfc51f | 7413 | |
a3f97cbb JW |
7414 | When creating memory location descriptors, we are effectively transforming |
7415 | the RTL for a memory-resident object into its Dwarf postfix expression | |
7416 | equivalent. This routine recursively descends an RTL tree, turning | |
e60d4d7b JL |
7417 | it into Dwarf postfix code as it goes. |
7418 | ||
7419 | MODE is the mode of the memory reference, needed to handle some | |
7420 | autoincrement addressing modes. */ | |
71dfc51f | 7421 | |
a3f97cbb | 7422 | static dw_loc_descr_ref |
e60d4d7b | 7423 | mem_loc_descriptor (rtl, mode) |
a3f97cbb | 7424 | register rtx rtl; |
e60d4d7b | 7425 | enum machine_mode mode; |
a3f97cbb JW |
7426 | { |
7427 | dw_loc_descr_ref mem_loc_result = NULL; | |
556273e0 | 7428 | /* Note that for a dynamically sized array, the location we will generate a |
a3f97cbb JW |
7429 | description of here will be the lowest numbered location which is |
7430 | actually within the array. That's *not* necessarily the same as the | |
7431 | zeroth element of the array. */ | |
71dfc51f | 7432 | |
1865dbb5 JM |
7433 | #ifdef ASM_SIMPLIFY_DWARF_ADDR |
7434 | rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); | |
7435 | #endif | |
7436 | ||
a3f97cbb JW |
7437 | switch (GET_CODE (rtl)) |
7438 | { | |
e60d4d7b JL |
7439 | case POST_INC: |
7440 | case POST_DEC: | |
e2134eea | 7441 | case POST_MODIFY: |
e60d4d7b JL |
7442 | /* POST_INC and POST_DEC can be handled just like a SUBREG. So we |
7443 | just fall into the SUBREG code. */ | |
7444 | ||
556273e0 | 7445 | /* Fall through. */ |
e60d4d7b | 7446 | |
a3f97cbb JW |
7447 | case SUBREG: |
7448 | /* The case of a subreg may arise when we have a local (register) | |
7449 | variable or a formal (register) parameter which doesn't quite fill | |
7450 | up an entire register. For now, just assume that it is | |
7451 | legitimate to make the Dwarf info refer to the whole register which | |
7452 | contains the given subreg. */ | |
ddef6bc7 | 7453 | rtl = SUBREG_REG (rtl); |
71dfc51f | 7454 | |
556273e0 | 7455 | /* Fall through. */ |
a3f97cbb JW |
7456 | |
7457 | case REG: | |
7458 | /* Whenever a register number forms a part of the description of the | |
7459 | method for calculating the (dynamic) address of a memory resident | |
556273e0 | 7460 | object, DWARF rules require the register number be referred to as |
a3f97cbb JW |
7461 | a "base register". This distinction is not based in any way upon |
7462 | what category of register the hardware believes the given register | |
7463 | belongs to. This is strictly DWARF terminology we're dealing with | |
7464 | here. Note that in cases where the location of a memory-resident | |
7465 | data object could be expressed as: OP_ADD (OP_BASEREG (basereg), | |
7466 | OP_CONST (0)) the actual DWARF location descriptor that we generate | |
7467 | may just be OP_BASEREG (basereg). This may look deceptively like | |
7468 | the object in question was allocated to a register (rather than in | |
7469 | memory) so DWARF consumers need to be aware of the subtle | |
7470 | distinction between OP_REG and OP_BASEREG. */ | |
7471 | mem_loc_result = based_loc_descr (reg_number (rtl), 0); | |
7472 | break; | |
7473 | ||
7474 | case MEM: | |
f7d2b0ed RH |
7475 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
7476 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0)); | |
a3f97cbb JW |
7477 | break; |
7478 | ||
d8041cc8 RH |
7479 | case LABEL_REF: |
7480 | /* Some ports can transform a symbol ref into a label ref, because | |
368f4cd6 NC |
7481 | the symbol ref is too far away and has to be dumped into a constant |
7482 | pool. */ | |
a3f97cbb JW |
7483 | case CONST: |
7484 | case SYMBOL_REF: | |
6331d1c1 | 7485 | /* Alternatively, the symbol in the constant pool might be referenced |
c6f9b9a1 NC |
7486 | by a different symbol. */ |
7487 | if (GET_CODE (rtl) == SYMBOL_REF | |
79cdfa4b TM |
7488 | && CONSTANT_POOL_ADDRESS_P (rtl)) |
7489 | { | |
7490 | rtx tmp = get_pool_constant (rtl); | |
6331d1c1 | 7491 | if (GET_CODE (tmp) == SYMBOL_REF) |
79cdfa4b TM |
7492 | rtl = tmp; |
7493 | } | |
7494 | ||
a3f97cbb JW |
7495 | mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0); |
7496 | mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
1865dbb5 | 7497 | mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl); |
a3f97cbb JW |
7498 | break; |
7499 | ||
e2134eea JH |
7500 | case PRE_MODIFY: |
7501 | /* Extract the PLUS expression nested inside and fall into | |
0407c02b | 7502 | PLUS code below. */ |
e2134eea JH |
7503 | rtl = XEXP (rtl, 1); |
7504 | goto plus; | |
7505 | ||
e60d4d7b JL |
7506 | case PRE_INC: |
7507 | case PRE_DEC: | |
7508 | /* Turn these into a PLUS expression and fall into the PLUS code | |
7509 | below. */ | |
7510 | rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0), | |
7511 | GEN_INT (GET_CODE (rtl) == PRE_INC | |
556273e0 KH |
7512 | ? GET_MODE_UNIT_SIZE (mode) |
7513 | : -GET_MODE_UNIT_SIZE (mode))); | |
7514 | ||
7515 | /* Fall through. */ | |
e60d4d7b | 7516 | |
a3f97cbb | 7517 | case PLUS: |
e2134eea | 7518 | plus: |
a3f97cbb | 7519 | if (is_based_loc (rtl)) |
71dfc51f RK |
7520 | mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)), |
7521 | INTVAL (XEXP (rtl, 1))); | |
a3f97cbb JW |
7522 | else |
7523 | { | |
d8041cc8 RH |
7524 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode); |
7525 | ||
7526 | if (GET_CODE (XEXP (rtl, 1)) == CONST_INT | |
7527 | && INTVAL (XEXP (rtl, 1)) >= 0) | |
7528 | { | |
7529 | add_loc_descr (&mem_loc_result, | |
7530 | new_loc_descr (DW_OP_plus_uconst, | |
7531 | INTVAL (XEXP (rtl, 1)), 0)); | |
7532 | } | |
7533 | else | |
7534 | { | |
7535 | add_loc_descr (&mem_loc_result, | |
7536 | mem_loc_descriptor (XEXP (rtl, 1), mode)); | |
7537 | add_loc_descr (&mem_loc_result, | |
7538 | new_loc_descr (DW_OP_plus, 0, 0)); | |
7539 | } | |
a3f97cbb JW |
7540 | } |
7541 | break; | |
7542 | ||
dd2478ae JW |
7543 | case MULT: |
7544 | /* If a pseudo-reg is optimized away, it is possible for it to | |
7545 | be replaced with a MEM containing a multiply. */ | |
d8041cc8 RH |
7546 | add_loc_descr (&mem_loc_result, |
7547 | mem_loc_descriptor (XEXP (rtl, 0), mode)); | |
7548 | add_loc_descr (&mem_loc_result, | |
7549 | mem_loc_descriptor (XEXP (rtl, 1), mode)); | |
dd2478ae JW |
7550 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0)); |
7551 | break; | |
7552 | ||
a3f97cbb | 7553 | case CONST_INT: |
d8041cc8 | 7554 | mem_loc_result = int_loc_descriptor (INTVAL (rtl)); |
a3f97cbb JW |
7555 | break; |
7556 | ||
7557 | default: | |
7558 | abort (); | |
7559 | } | |
71dfc51f | 7560 | |
a3f97cbb JW |
7561 | return mem_loc_result; |
7562 | } | |
7563 | ||
956d6950 | 7564 | /* Return a descriptor that describes the concatenation of two locations. |
4401bf24 JL |
7565 | This is typically a complex variable. */ |
7566 | ||
7567 | static dw_loc_descr_ref | |
7568 | concat_loc_descriptor (x0, x1) | |
7569 | register rtx x0, x1; | |
7570 | { | |
7571 | dw_loc_descr_ref cc_loc_result = NULL; | |
7572 | ||
7573 | if (!is_pseudo_reg (x0) | |
7574 | && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0)))) | |
7575 | add_loc_descr (&cc_loc_result, loc_descriptor (x0)); | |
7576 | add_loc_descr (&cc_loc_result, | |
7577 | new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0)); | |
7578 | ||
7579 | if (!is_pseudo_reg (x1) | |
7580 | && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0)))) | |
7581 | add_loc_descr (&cc_loc_result, loc_descriptor (x1)); | |
7582 | add_loc_descr (&cc_loc_result, | |
7583 | new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0)); | |
7584 | ||
7585 | return cc_loc_result; | |
7586 | } | |
7587 | ||
a3f97cbb JW |
7588 | /* Output a proper Dwarf location descriptor for a variable or parameter |
7589 | which is either allocated in a register or in a memory location. For a | |
7590 | register, we just generate an OP_REG and the register number. For a | |
7591 | memory location we provide a Dwarf postfix expression describing how to | |
7592 | generate the (dynamic) address of the object onto the address stack. */ | |
71dfc51f | 7593 | |
a3f97cbb JW |
7594 | static dw_loc_descr_ref |
7595 | loc_descriptor (rtl) | |
7596 | register rtx rtl; | |
7597 | { | |
7598 | dw_loc_descr_ref loc_result = NULL; | |
7599 | switch (GET_CODE (rtl)) | |
7600 | { | |
7601 | case SUBREG: | |
a3f97cbb JW |
7602 | /* The case of a subreg may arise when we have a local (register) |
7603 | variable or a formal (register) parameter which doesn't quite fill | |
71dfc51f | 7604 | up an entire register. For now, just assume that it is |
a3f97cbb JW |
7605 | legitimate to make the Dwarf info refer to the whole register which |
7606 | contains the given subreg. */ | |
ddef6bc7 | 7607 | rtl = SUBREG_REG (rtl); |
71dfc51f | 7608 | |
556273e0 | 7609 | /* Fall through. */ |
a3f97cbb JW |
7610 | |
7611 | case REG: | |
5c90448c | 7612 | loc_result = reg_loc_descriptor (rtl); |
a3f97cbb JW |
7613 | break; |
7614 | ||
7615 | case MEM: | |
e60d4d7b | 7616 | loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); |
a3f97cbb JW |
7617 | break; |
7618 | ||
4401bf24 JL |
7619 | case CONCAT: |
7620 | loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1)); | |
7621 | break; | |
7622 | ||
a3f97cbb | 7623 | default: |
71dfc51f | 7624 | abort (); |
a3f97cbb | 7625 | } |
71dfc51f | 7626 | |
a3f97cbb JW |
7627 | return loc_result; |
7628 | } | |
7629 | ||
d8041cc8 RH |
7630 | /* Similar, but generate the descriptor from trees instead of rtl. |
7631 | This comes up particularly with variable length arrays. */ | |
7632 | ||
7633 | static dw_loc_descr_ref | |
7634 | loc_descriptor_from_tree (loc, addressp) | |
7635 | tree loc; | |
7636 | int addressp; | |
7637 | { | |
7638 | dw_loc_descr_ref ret = NULL; | |
7639 | int indirect_size = 0; | |
7640 | int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc)); | |
7641 | enum dwarf_location_atom op; | |
7642 | ||
7643 | /* ??? Most of the time we do not take proper care for sign/zero | |
7644 | extending the values properly. Hopefully this won't be a real | |
7645 | problem... */ | |
7646 | ||
7647 | switch (TREE_CODE (loc)) | |
7648 | { | |
7649 | case ERROR_MARK: | |
7650 | break; | |
7651 | ||
b4ae5201 RK |
7652 | case WITH_RECORD_EXPR: |
7653 | /* This case involves extracting fields from an object to determine the | |
7654 | position of other fields. We don't try to encode this here. The | |
7655 | only user of this is Ada, which encodes the needed information using | |
7656 | the names of types. */ | |
7657 | return ret; | |
7658 | ||
d8041cc8 RH |
7659 | case VAR_DECL: |
7660 | case PARM_DECL: | |
7661 | { | |
7662 | rtx rtl = rtl_for_decl_location (loc); | |
7663 | enum machine_mode mode = DECL_MODE (loc); | |
7664 | ||
a97c9600 RH |
7665 | if (rtl == NULL_RTX) |
7666 | break; | |
7667 | else if (CONSTANT_P (rtl)) | |
d8041cc8 RH |
7668 | { |
7669 | ret = new_loc_descr (DW_OP_addr, 0, 0); | |
7670 | ret->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
7671 | ret->dw_loc_oprnd1.v.val_addr = rtl; | |
7672 | indirect_size = GET_MODE_SIZE (mode); | |
7673 | } | |
7674 | else | |
7675 | { | |
7676 | if (GET_CODE (rtl) == MEM) | |
7677 | { | |
7678 | indirect_size = GET_MODE_SIZE (mode); | |
7679 | rtl = XEXP (rtl, 0); | |
7680 | } | |
7681 | ret = mem_loc_descriptor (rtl, mode); | |
7682 | } | |
7683 | } | |
7684 | break; | |
7685 | ||
7686 | case INDIRECT_REF: | |
7687 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7688 | indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc))); | |
7689 | break; | |
7690 | ||
ed972b14 RK |
7691 | case NOP_EXPR: |
7692 | case CONVERT_EXPR: | |
7693 | case NON_LVALUE_EXPR: | |
b4ae5201 | 7694 | case SAVE_EXPR: |
ed972b14 | 7695 | return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp); |
e57cabac | 7696 | |
d8041cc8 RH |
7697 | case COMPONENT_REF: |
7698 | case BIT_FIELD_REF: | |
7699 | case ARRAY_REF: | |
b4e3fabb | 7700 | case ARRAY_RANGE_REF: |
d8041cc8 RH |
7701 | { |
7702 | tree obj, offset; | |
7703 | HOST_WIDE_INT bitsize, bitpos, bytepos; | |
7704 | enum machine_mode mode; | |
7705 | int volatilep; | |
7706 | unsigned int alignment; | |
7707 | ||
7708 | obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode, | |
7709 | &unsignedp, &volatilep, &alignment); | |
7710 | ret = loc_descriptor_from_tree (obj, 1); | |
7711 | ||
7712 | if (offset != NULL_TREE) | |
7713 | { | |
7714 | /* Variable offset. */ | |
7715 | add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0)); | |
7716 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
7717 | } | |
7718 | ||
7719 | if (addressp) | |
7720 | { | |
7721 | /* We cannot address anything not on a unit boundary. */ | |
7722 | if (bitpos % BITS_PER_UNIT != 0) | |
7723 | abort (); | |
7724 | } | |
7725 | else | |
7726 | { | |
7727 | if (bitpos % BITS_PER_UNIT != 0 | |
7728 | || bitsize % BITS_PER_UNIT != 0) | |
7729 | { | |
7730 | /* ??? We could handle this by loading and shifting etc. | |
7731 | Wait until someone needs it before expending the effort. */ | |
7732 | abort (); | |
7733 | } | |
7734 | ||
7735 | indirect_size = bitsize / BITS_PER_UNIT; | |
7736 | } | |
7737 | ||
7738 | bytepos = bitpos / BITS_PER_UNIT; | |
7739 | if (bytepos > 0) | |
7740 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0)); | |
7741 | else if (bytepos < 0) | |
7742 | { | |
7743 | add_loc_descr (&ret, int_loc_descriptor (bytepos)); | |
7744 | add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); | |
7745 | } | |
7746 | break; | |
7747 | } | |
7748 | ||
7749 | case INTEGER_CST: | |
7750 | if (host_integerp (loc, 0)) | |
7751 | ret = int_loc_descriptor (tree_low_cst (loc, 0)); | |
7752 | break; | |
d8041cc8 RH |
7753 | |
7754 | case BIT_AND_EXPR: | |
7755 | op = DW_OP_and; | |
7756 | goto do_binop; | |
7757 | case BIT_XOR_EXPR: | |
7758 | op = DW_OP_xor; | |
7759 | goto do_binop; | |
7760 | case BIT_IOR_EXPR: | |
7761 | op = DW_OP_or; | |
7762 | goto do_binop; | |
7763 | case TRUNC_DIV_EXPR: | |
7764 | op = DW_OP_div; | |
7765 | goto do_binop; | |
7766 | case MINUS_EXPR: | |
7767 | op = DW_OP_minus; | |
7768 | goto do_binop; | |
7769 | case TRUNC_MOD_EXPR: | |
7770 | op = DW_OP_mod; | |
7771 | goto do_binop; | |
7772 | case MULT_EXPR: | |
7773 | op = DW_OP_mul; | |
7774 | goto do_binop; | |
7775 | case LSHIFT_EXPR: | |
7776 | op = DW_OP_shl; | |
7777 | goto do_binop; | |
7778 | case RSHIFT_EXPR: | |
7779 | op = (unsignedp ? DW_OP_shr : DW_OP_shra); | |
7780 | goto do_binop; | |
7781 | case PLUS_EXPR: | |
7782 | if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST | |
7783 | && host_integerp (TREE_OPERAND (loc, 1), 0)) | |
7784 | { | |
7785 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7786 | add_loc_descr (&ret, | |
7787 | new_loc_descr (DW_OP_plus_uconst, | |
7788 | tree_low_cst (TREE_OPERAND (loc, 1), | |
7789 | 0), | |
7790 | 0)); | |
7791 | break; | |
7792 | } | |
7793 | op = DW_OP_plus; | |
7794 | goto do_binop; | |
7795 | case LE_EXPR: | |
7796 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7797 | break; | |
7798 | op = DW_OP_le; | |
7799 | goto do_binop; | |
7800 | case GE_EXPR: | |
7801 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7802 | break; | |
7803 | op = DW_OP_ge; | |
7804 | goto do_binop; | |
7805 | case LT_EXPR: | |
7806 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7807 | break; | |
7808 | op = DW_OP_lt; | |
7809 | goto do_binop; | |
7810 | case GT_EXPR: | |
7811 | if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) | |
7812 | break; | |
7813 | op = DW_OP_gt; | |
7814 | goto do_binop; | |
7815 | case EQ_EXPR: | |
7816 | op = DW_OP_eq; | |
7817 | goto do_binop; | |
7818 | case NE_EXPR: | |
7819 | op = DW_OP_ne; | |
7820 | goto do_binop; | |
7821 | ||
7822 | do_binop: | |
7823 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7824 | add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0)); | |
7825 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); | |
7826 | break; | |
7827 | ||
7828 | case BIT_NOT_EXPR: | |
7829 | op = DW_OP_not; | |
7830 | goto do_unop; | |
7831 | case ABS_EXPR: | |
7832 | op = DW_OP_abs; | |
7833 | goto do_unop; | |
7834 | case NEGATE_EXPR: | |
7835 | op = DW_OP_neg; | |
7836 | goto do_unop; | |
7837 | ||
7838 | do_unop: | |
7839 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7840 | add_loc_descr (&ret, new_loc_descr (op, 0, 0)); | |
7841 | break; | |
7842 | ||
7843 | case MAX_EXPR: | |
7844 | loc = build (COND_EXPR, TREE_TYPE (loc), | |
7845 | build (LT_EXPR, integer_type_node, | |
7846 | TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)), | |
7847 | TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0)); | |
7848 | /* FALLTHRU */ | |
7849 | ||
7850 | case COND_EXPR: | |
7851 | { | |
7852 | dw_loc_descr_ref bra_node, jump_node, tmp; | |
7853 | ||
7854 | ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); | |
7855 | bra_node = new_loc_descr (DW_OP_bra, 0, 0); | |
7856 | add_loc_descr (&ret, bra_node); | |
7857 | ||
7858 | tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0); | |
7859 | add_loc_descr (&ret, tmp); | |
7860 | jump_node = new_loc_descr (DW_OP_skip, 0, 0); | |
7861 | add_loc_descr (&ret, jump_node); | |
7862 | ||
7863 | tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); | |
7864 | add_loc_descr (&ret, tmp); | |
7865 | bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc; | |
7866 | bra_node->dw_loc_oprnd1.v.val_loc = tmp; | |
7867 | ||
7868 | /* ??? Need a node to point the skip at. Use a nop. */ | |
7869 | tmp = new_loc_descr (DW_OP_nop, 0, 0); | |
7870 | add_loc_descr (&ret, tmp); | |
7871 | jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc; | |
7872 | jump_node->dw_loc_oprnd1.v.val_loc = tmp; | |
7873 | } | |
7874 | break; | |
7875 | ||
7876 | default: | |
7877 | abort (); | |
7878 | } | |
7879 | ||
7880 | /* If we can't fill the request for an address, die. */ | |
7881 | if (addressp && indirect_size == 0) | |
7882 | abort (); | |
7883 | ||
7884 | /* If we've got an address and don't want one, dereference. */ | |
7885 | if (!addressp && indirect_size > 0) | |
7886 | { | |
7887 | if (indirect_size > DWARF2_ADDR_SIZE) | |
7888 | abort (); | |
7889 | if (indirect_size == DWARF2_ADDR_SIZE) | |
7890 | op = DW_OP_deref; | |
7891 | else | |
7892 | op = DW_OP_deref_size; | |
7893 | add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0)); | |
7894 | } | |
7895 | ||
7896 | return ret; | |
7897 | } | |
7898 | ||
665f2503 | 7899 | /* Given a value, round it up to the lowest multiple of `boundary' |
a3f97cbb | 7900 | which is not less than the value itself. */ |
71dfc51f | 7901 | |
665f2503 | 7902 | static inline HOST_WIDE_INT |
a3f97cbb | 7903 | ceiling (value, boundary) |
665f2503 RK |
7904 | HOST_WIDE_INT value; |
7905 | unsigned int boundary; | |
a3f97cbb JW |
7906 | { |
7907 | return (((value + boundary - 1) / boundary) * boundary); | |
7908 | } | |
7909 | ||
7910 | /* Given a pointer to what is assumed to be a FIELD_DECL node, return a | |
7911 | pointer to the declared type for the relevant field variable, or return | |
7912 | `integer_type_node' if the given node turns out to be an | |
7913 | ERROR_MARK node. */ | |
71dfc51f RK |
7914 | |
7915 | static inline tree | |
a3f97cbb JW |
7916 | field_type (decl) |
7917 | register tree decl; | |
7918 | { | |
7919 | register tree type; | |
7920 | ||
7921 | if (TREE_CODE (decl) == ERROR_MARK) | |
7922 | return integer_type_node; | |
7923 | ||
7924 | type = DECL_BIT_FIELD_TYPE (decl); | |
71dfc51f | 7925 | if (type == NULL_TREE) |
a3f97cbb JW |
7926 | type = TREE_TYPE (decl); |
7927 | ||
7928 | return type; | |
7929 | } | |
7930 | ||
5f446d21 DD |
7931 | /* Given a pointer to a tree node, return the alignment in bits for |
7932 | it, or else return BITS_PER_WORD if the node actually turns out to | |
7933 | be an ERROR_MARK node. */ | |
71dfc51f RK |
7934 | |
7935 | static inline unsigned | |
a3f97cbb JW |
7936 | simple_type_align_in_bits (type) |
7937 | register tree type; | |
7938 | { | |
7939 | return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; | |
7940 | } | |
7941 | ||
5f446d21 DD |
7942 | static inline unsigned |
7943 | simple_decl_align_in_bits (decl) | |
7944 | register tree decl; | |
7945 | { | |
7946 | return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD; | |
7947 | } | |
7948 | ||
a3f97cbb JW |
7949 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE |
7950 | node, return the size in bits for the type if it is a constant, or else | |
7951 | return the alignment for the type if the type's size is not constant, or | |
7952 | else return BITS_PER_WORD if the type actually turns out to be an | |
7953 | ERROR_MARK node. */ | |
71dfc51f | 7954 | |
665f2503 | 7955 | static inline unsigned HOST_WIDE_INT |
a3f97cbb JW |
7956 | simple_type_size_in_bits (type) |
7957 | register tree type; | |
7958 | { | |
3df18884 RH |
7959 | tree type_size_tree; |
7960 | ||
a3f97cbb JW |
7961 | if (TREE_CODE (type) == ERROR_MARK) |
7962 | return BITS_PER_WORD; | |
3df18884 | 7963 | type_size_tree = TYPE_SIZE (type); |
a3f97cbb | 7964 | |
3df18884 RH |
7965 | if (type_size_tree == NULL_TREE) |
7966 | return 0; | |
7967 | if (! host_integerp (type_size_tree, 1)) | |
7968 | return TYPE_ALIGN (type); | |
7969 | return tree_low_cst (type_size_tree, 1); | |
a3f97cbb JW |
7970 | } |
7971 | ||
7972 | /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and | |
7973 | return the byte offset of the lowest addressed byte of the "containing | |
7974 | object" for the given FIELD_DECL, or return 0 if we are unable to | |
7975 | determine what that offset is, either because the argument turns out to | |
7976 | be a pointer to an ERROR_MARK node, or because the offset is actually | |
7977 | variable. (We can't handle the latter case just yet). */ | |
71dfc51f | 7978 | |
665f2503 | 7979 | static HOST_WIDE_INT |
a3f97cbb JW |
7980 | field_byte_offset (decl) |
7981 | register tree decl; | |
7982 | { | |
665f2503 | 7983 | unsigned int type_align_in_bits; |
5f446d21 | 7984 | unsigned int decl_align_in_bits; |
665f2503 | 7985 | unsigned HOST_WIDE_INT type_size_in_bits; |
665f2503 RK |
7986 | HOST_WIDE_INT object_offset_in_bits; |
7987 | HOST_WIDE_INT object_offset_in_bytes; | |
7988 | tree type; | |
7989 | tree field_size_tree; | |
7990 | HOST_WIDE_INT bitpos_int; | |
7991 | HOST_WIDE_INT deepest_bitpos; | |
7992 | unsigned HOST_WIDE_INT field_size_in_bits; | |
a3f97cbb JW |
7993 | |
7994 | if (TREE_CODE (decl) == ERROR_MARK) | |
7995 | return 0; | |
7996 | ||
7997 | if (TREE_CODE (decl) != FIELD_DECL) | |
7998 | abort (); | |
7999 | ||
8000 | type = field_type (decl); | |
a3f97cbb JW |
8001 | field_size_tree = DECL_SIZE (decl); |
8002 | ||
3df18884 RH |
8003 | /* The size could be unspecified if there was an error, or for |
8004 | a flexible array member. */ | |
50352c9c | 8005 | if (! field_size_tree) |
3df18884 | 8006 | field_size_tree = bitsize_zero_node; |
50352c9c | 8007 | |
556273e0 | 8008 | /* We cannot yet cope with fields whose positions are variable, so |
a3f97cbb JW |
8009 | for now, when we see such things, we simply return 0. Someday, we may |
8010 | be able to handle such cases, but it will be damn difficult. */ | |
665f2503 | 8011 | if (! host_integerp (bit_position (decl), 0)) |
a3f97cbb | 8012 | return 0; |
14a774a9 | 8013 | |
665f2503 | 8014 | bitpos_int = int_bit_position (decl); |
a3f97cbb | 8015 | |
3df18884 | 8016 | /* If we don't know the size of the field, pretend it's a full word. */ |
665f2503 RK |
8017 | if (host_integerp (field_size_tree, 1)) |
8018 | field_size_in_bits = tree_low_cst (field_size_tree, 1); | |
14a774a9 RK |
8019 | else |
8020 | field_size_in_bits = BITS_PER_WORD; | |
a3f97cbb JW |
8021 | |
8022 | type_size_in_bits = simple_type_size_in_bits (type); | |
a3f97cbb | 8023 | type_align_in_bits = simple_type_align_in_bits (type); |
5f446d21 | 8024 | decl_align_in_bits = simple_decl_align_in_bits (decl); |
a3f97cbb JW |
8025 | |
8026 | /* Note that the GCC front-end doesn't make any attempt to keep track of | |
8027 | the starting bit offset (relative to the start of the containing | |
8028 | structure type) of the hypothetical "containing object" for a bit- | |
8029 | field. Thus, when computing the byte offset value for the start of the | |
556273e0 | 8030 | "containing object" of a bit-field, we must deduce this information on |
a3f97cbb JW |
8031 | our own. This can be rather tricky to do in some cases. For example, |
8032 | handling the following structure type definition when compiling for an | |
8033 | i386/i486 target (which only aligns long long's to 32-bit boundaries) | |
8034 | can be very tricky: | |
8035 | ||
8036 | struct S { int field1; long long field2:31; }; | |
8037 | ||
8038 | Fortunately, there is a simple rule-of-thumb which can be | |
8039 | used in such cases. When compiling for an i386/i486, GCC will allocate | |
556273e0 | 8040 | 8 bytes for the structure shown above. It decides to do this based upon |
a3f97cbb JW |
8041 | one simple rule for bit-field allocation. Quite simply, GCC allocates |
8042 | each "containing object" for each bit-field at the first (i.e. lowest | |
8043 | addressed) legitimate alignment boundary (based upon the required | |
8044 | minimum alignment for the declared type of the field) which it can | |
8045 | possibly use, subject to the condition that there is still enough | |
8046 | available space remaining in the containing object (when allocated at | |
8047 | the selected point) to fully accommodate all of the bits of the | |
8048 | bit-field itself. This simple rule makes it obvious why GCC allocates | |
8049 | 8 bytes for each object of the structure type shown above. When looking | |
8050 | for a place to allocate the "containing object" for `field2', the | |
8051 | compiler simply tries to allocate a 64-bit "containing object" at each | |
8052 | successive 32-bit boundary (starting at zero) until it finds a place to | |
8053 | allocate that 64- bit field such that at least 31 contiguous (and | |
8054 | previously unallocated) bits remain within that selected 64 bit field. | |
8055 | (As it turns out, for the example above, the compiler finds that it is | |
8056 | OK to allocate the "containing object" 64-bit field at bit-offset zero | |
8057 | within the structure type.) Here we attempt to work backwards from the | |
556273e0 | 8058 | limited set of facts we're given, and we try to deduce from those facts, |
a3f97cbb | 8059 | where GCC must have believed that the containing object started (within |
556273e0 KH |
8060 | the structure type). The value we deduce is then used (by the callers of |
8061 | this routine) to generate DW_AT_location and DW_AT_bit_offset attributes | |
a3f97cbb JW |
8062 | for fields (both bit-fields and, in the case of DW_AT_location, regular |
8063 | fields as well). */ | |
8064 | ||
8065 | /* Figure out the bit-distance from the start of the structure to the | |
8066 | "deepest" bit of the bit-field. */ | |
8067 | deepest_bitpos = bitpos_int + field_size_in_bits; | |
8068 | ||
8069 | /* This is the tricky part. Use some fancy footwork to deduce where the | |
8070 | lowest addressed bit of the containing object must be. */ | |
5f446d21 DD |
8071 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; |
8072 | ||
8073 | /* Round up to type_align by default. This works best for bitfields. */ | |
8074 | object_offset_in_bits += type_align_in_bits - 1; | |
8075 | object_offset_in_bits /= type_align_in_bits; | |
8076 | object_offset_in_bits *= type_align_in_bits; | |
a3f97cbb | 8077 | |
5f446d21 DD |
8078 | if (object_offset_in_bits > bitpos_int) |
8079 | { | |
8080 | /* Sigh, the decl must be packed. */ | |
8081 | object_offset_in_bits = deepest_bitpos - type_size_in_bits; | |
8082 | ||
8083 | /* Round up to decl_align instead. */ | |
8084 | object_offset_in_bits += decl_align_in_bits - 1; | |
8085 | object_offset_in_bits /= decl_align_in_bits; | |
8086 | object_offset_in_bits *= decl_align_in_bits; | |
8087 | } | |
a3f97cbb | 8088 | |
5f446d21 | 8089 | object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT; |
a3f97cbb JW |
8090 | |
8091 | return object_offset_in_bytes; | |
8092 | } | |
a3f97cbb | 8093 | \f |
71dfc51f RK |
8094 | /* The following routines define various Dwarf attributes and any data |
8095 | associated with them. */ | |
a3f97cbb | 8096 | |
ef76d03b | 8097 | /* Add a location description attribute value to a DIE. |
a3f97cbb | 8098 | |
ef76d03b | 8099 | This emits location attributes suitable for whole variables and |
a3f97cbb JW |
8100 | whole parameters. Note that the location attributes for struct fields are |
8101 | generated by the routine `data_member_location_attribute' below. */ | |
71dfc51f | 8102 | |
a3f97cbb | 8103 | static void |
ef76d03b | 8104 | add_AT_location_description (die, attr_kind, rtl) |
a3f97cbb | 8105 | dw_die_ref die; |
ef76d03b | 8106 | enum dwarf_attribute attr_kind; |
a3f97cbb JW |
8107 | register rtx rtl; |
8108 | { | |
a3f97cbb JW |
8109 | /* Handle a special case. If we are about to output a location descriptor |
8110 | for a variable or parameter which has been optimized out of existence, | |
6a7a9f01 | 8111 | don't do that. A variable which has been optimized out |
a3f97cbb JW |
8112 | of existence will have a DECL_RTL value which denotes a pseudo-reg. |
8113 | Currently, in some rare cases, variables can have DECL_RTL values which | |
8114 | look like (MEM (REG pseudo-reg#)). These cases are due to bugs | |
556273e0 | 8115 | elsewhere in the compiler. We treat such cases as if the variable(s) in |
6a7a9f01 | 8116 | question had been optimized out of existence. */ |
a3f97cbb | 8117 | |
6a7a9f01 JM |
8118 | if (is_pseudo_reg (rtl) |
8119 | || (GET_CODE (rtl) == MEM | |
4401bf24 | 8120 | && is_pseudo_reg (XEXP (rtl, 0))) |
556273e0 | 8121 | /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which |
bce8fed7 JL |
8122 | references the internal argument pointer (a pseudo) in a function |
8123 | where all references to the internal argument pointer were | |
8124 | eliminated via the optimizers. */ | |
8125 | || (GET_CODE (rtl) == MEM | |
8126 | && GET_CODE (XEXP (rtl, 0)) == PLUS | |
8127 | && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0))) | |
4401bf24 JL |
8128 | || (GET_CODE (rtl) == CONCAT |
8129 | && is_pseudo_reg (XEXP (rtl, 0)) | |
8130 | && is_pseudo_reg (XEXP (rtl, 1)))) | |
6a7a9f01 | 8131 | return; |
a3f97cbb | 8132 | |
6a7a9f01 | 8133 | add_AT_loc (die, attr_kind, loc_descriptor (rtl)); |
a3f97cbb JW |
8134 | } |
8135 | ||
8136 | /* Attach the specialized form of location attribute used for data | |
8137 | members of struct and union types. In the special case of a | |
8138 | FIELD_DECL node which represents a bit-field, the "offset" part | |
8139 | of this special location descriptor must indicate the distance | |
8140 | in bytes from the lowest-addressed byte of the containing struct | |
8141 | or union type to the lowest-addressed byte of the "containing | |
8142 | object" for the bit-field. (See the `field_byte_offset' function | |
8143 | above).. For any given bit-field, the "containing object" is a | |
8144 | hypothetical object (of some integral or enum type) within which | |
8145 | the given bit-field lives. The type of this hypothetical | |
8146 | "containing object" is always the same as the declared type of | |
8147 | the individual bit-field itself (for GCC anyway... the DWARF | |
8148 | spec doesn't actually mandate this). Note that it is the size | |
8149 | (in bytes) of the hypothetical "containing object" which will | |
8150 | be given in the DW_AT_byte_size attribute for this bit-field. | |
8151 | (See the `byte_size_attribute' function below.) It is also used | |
8152 | when calculating the value of the DW_AT_bit_offset attribute. | |
8153 | (See the `bit_offset_attribute' function below). */ | |
71dfc51f | 8154 | |
a3f97cbb JW |
8155 | static void |
8156 | add_data_member_location_attribute (die, decl) | |
8157 | register dw_die_ref die; | |
8158 | register tree decl; | |
8159 | { | |
61b32c02 | 8160 | register unsigned long offset; |
a3f97cbb JW |
8161 | register dw_loc_descr_ref loc_descr; |
8162 | register enum dwarf_location_atom op; | |
8163 | ||
61b32c02 | 8164 | if (TREE_CODE (decl) == TREE_VEC) |
665f2503 | 8165 | offset = tree_low_cst (BINFO_OFFSET (decl), 0); |
61b32c02 JM |
8166 | else |
8167 | offset = field_byte_offset (decl); | |
8168 | ||
a3f97cbb JW |
8169 | /* The DWARF2 standard says that we should assume that the structure address |
8170 | is already on the stack, so we can specify a structure field address | |
8171 | by using DW_OP_plus_uconst. */ | |
71dfc51f | 8172 | |
a3f97cbb JW |
8173 | #ifdef MIPS_DEBUGGING_INFO |
8174 | /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator | |
8175 | correctly. It works only if we leave the offset on the stack. */ | |
8176 | op = DW_OP_constu; | |
8177 | #else | |
8178 | op = DW_OP_plus_uconst; | |
8179 | #endif | |
71dfc51f | 8180 | |
a3f97cbb JW |
8181 | loc_descr = new_loc_descr (op, offset, 0); |
8182 | add_AT_loc (die, DW_AT_data_member_location, loc_descr); | |
8183 | } | |
8184 | ||
8185 | /* Attach an DW_AT_const_value attribute for a variable or a parameter which | |
8186 | does not have a "location" either in memory or in a register. These | |
8187 | things can arise in GNU C when a constant is passed as an actual parameter | |
8188 | to an inlined function. They can also arise in C++ where declared | |
8189 | constants do not necessarily get memory "homes". */ | |
71dfc51f | 8190 | |
a3f97cbb JW |
8191 | static void |
8192 | add_const_value_attribute (die, rtl) | |
8193 | register dw_die_ref die; | |
8194 | register rtx rtl; | |
8195 | { | |
8196 | switch (GET_CODE (rtl)) | |
8197 | { | |
8198 | case CONST_INT: | |
2e4b9b8c RH |
8199 | /* Note that a CONST_INT rtx could represent either an integer |
8200 | or a floating-point constant. A CONST_INT is used whenever | |
8201 | the constant will fit into a single word. In all such | |
8202 | cases, the original mode of the constant value is wiped | |
8203 | out, and the CONST_INT rtx is assigned VOIDmode. */ | |
8204 | { | |
8205 | HOST_WIDE_INT val = INTVAL (rtl); | |
8206 | ||
8207 | /* ??? We really should be using HOST_WIDE_INT throughout. */ | |
8208 | if (val < 0) | |
8209 | { | |
8210 | if ((long) val != val) | |
8211 | abort (); | |
8212 | add_AT_int (die, DW_AT_const_value, (long) val); | |
8213 | } | |
8214 | else | |
8215 | { | |
8216 | if ((unsigned long) val != (unsigned HOST_WIDE_INT) val) | |
8217 | abort (); | |
8218 | add_AT_int (die, DW_AT_const_value, (unsigned long) val); | |
8219 | } | |
8220 | } | |
a3f97cbb JW |
8221 | break; |
8222 | ||
8223 | case CONST_DOUBLE: | |
8224 | /* Note that a CONST_DOUBLE rtx could represent either an integer or a | |
8225 | floating-point constant. A CONST_DOUBLE is used whenever the | |
8226 | constant requires more than one word in order to be adequately | |
469ac993 JM |
8227 | represented. We output CONST_DOUBLEs as blocks. */ |
8228 | { | |
8229 | register enum machine_mode mode = GET_MODE (rtl); | |
8230 | ||
8231 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
8232 | { | |
e389897b | 8233 | register unsigned length = GET_MODE_SIZE (mode) / 4; |
1bfb5f8f | 8234 | long *array = (long *) xmalloc (sizeof (long) * length); |
71dfc51f | 8235 | REAL_VALUE_TYPE rv; |
469ac993 | 8236 | |
71dfc51f | 8237 | REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl); |
469ac993 JM |
8238 | switch (mode) |
8239 | { | |
8240 | case SFmode: | |
71dfc51f | 8241 | REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]); |
469ac993 JM |
8242 | break; |
8243 | ||
8244 | case DFmode: | |
71dfc51f | 8245 | REAL_VALUE_TO_TARGET_DOUBLE (rv, array); |
469ac993 JM |
8246 | break; |
8247 | ||
8248 | case XFmode: | |
8249 | case TFmode: | |
71dfc51f | 8250 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array); |
469ac993 JM |
8251 | break; |
8252 | ||
8253 | default: | |
8254 | abort (); | |
8255 | } | |
8256 | ||
469ac993 JM |
8257 | add_AT_float (die, DW_AT_const_value, length, array); |
8258 | } | |
8259 | else | |
2e4b9b8c RH |
8260 | { |
8261 | /* ??? We really should be using HOST_WIDE_INT throughout. */ | |
8262 | if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT) | |
8263 | abort (); | |
8264 | add_AT_long_long (die, DW_AT_const_value, | |
8265 | CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl)); | |
8266 | } | |
469ac993 | 8267 | } |
a3f97cbb JW |
8268 | break; |
8269 | ||
8270 | case CONST_STRING: | |
8271 | add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0)); | |
8272 | break; | |
8273 | ||
8274 | case SYMBOL_REF: | |
8275 | case LABEL_REF: | |
8276 | case CONST: | |
1865dbb5 | 8277 | add_AT_addr (die, DW_AT_const_value, save_rtx (rtl)); |
a3f97cbb JW |
8278 | break; |
8279 | ||
8280 | case PLUS: | |
8281 | /* In cases where an inlined instance of an inline function is passed | |
8282 | the address of an `auto' variable (which is local to the caller) we | |
8283 | can get a situation where the DECL_RTL of the artificial local | |
8284 | variable (for the inlining) which acts as a stand-in for the | |
8285 | corresponding formal parameter (of the inline function) will look | |
8286 | like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not | |
556273e0 KH |
8287 | exactly a compile-time constant expression, but it isn't the address |
8288 | of the (artificial) local variable either. Rather, it represents the | |
a3f97cbb | 8289 | *value* which the artificial local variable always has during its |
556273e0 | 8290 | lifetime. We currently have no way to represent such quasi-constant |
6a7a9f01 | 8291 | values in Dwarf, so for now we just punt and generate nothing. */ |
a3f97cbb JW |
8292 | break; |
8293 | ||
8294 | default: | |
8295 | /* No other kinds of rtx should be possible here. */ | |
8296 | abort (); | |
8297 | } | |
8298 | ||
8299 | } | |
8300 | ||
d8041cc8 RH |
8301 | static rtx |
8302 | rtl_for_decl_location (decl) | |
8303 | tree decl; | |
a3f97cbb JW |
8304 | { |
8305 | register rtx rtl; | |
71dfc51f | 8306 | |
a3f97cbb JW |
8307 | /* Here we have to decide where we are going to say the parameter "lives" |
8308 | (as far as the debugger is concerned). We only have a couple of | |
8309 | choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. | |
71dfc51f | 8310 | |
556273e0 | 8311 | DECL_RTL normally indicates where the parameter lives during most of the |
71dfc51f | 8312 | activation of the function. If optimization is enabled however, this |
556273e0 | 8313 | could be either NULL or else a pseudo-reg. Both of those cases indicate |
a3f97cbb JW |
8314 | that the parameter doesn't really live anywhere (as far as the code |
8315 | generation parts of GCC are concerned) during most of the function's | |
8316 | activation. That will happen (for example) if the parameter is never | |
71dfc51f RK |
8317 | referenced within the function. |
8318 | ||
8319 | We could just generate a location descriptor here for all non-NULL | |
8320 | non-pseudo values of DECL_RTL and ignore all of the rest, but we can be | |
8321 | a little nicer than that if we also consider DECL_INCOMING_RTL in cases | |
8322 | where DECL_RTL is NULL or is a pseudo-reg. | |
8323 | ||
8324 | Note however that we can only get away with using DECL_INCOMING_RTL as | |
8325 | a backup substitute for DECL_RTL in certain limited cases. In cases | |
8326 | where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl), | |
8327 | we can be sure that the parameter was passed using the same type as it is | |
8328 | declared to have within the function, and that its DECL_INCOMING_RTL | |
8329 | points us to a place where a value of that type is passed. | |
8330 | ||
8331 | In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different, | |
8332 | we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL | |
8333 | because in these cases DECL_INCOMING_RTL points us to a value of some | |
8334 | type which is *different* from the type of the parameter itself. Thus, | |
8335 | if we tried to use DECL_INCOMING_RTL to generate a location attribute in | |
8336 | such cases, the debugger would end up (for example) trying to fetch a | |
8337 | `float' from a place which actually contains the first part of a | |
8338 | `double'. That would lead to really incorrect and confusing | |
8339 | output at debug-time. | |
8340 | ||
8341 | So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL | |
8342 | in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There | |
8343 | are a couple of exceptions however. On little-endian machines we can | |
8344 | get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is | |
8345 | not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is | |
8346 | an integral type that is smaller than TREE_TYPE (decl). These cases arise | |
8347 | when (on a little-endian machine) a non-prototyped function has a | |
8348 | parameter declared to be of type `short' or `char'. In such cases, | |
8349 | TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will | |
8350 | be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the | |
8351 | passed `int' value. If the debugger then uses that address to fetch | |
8352 | a `short' or a `char' (on a little-endian machine) the result will be | |
8353 | the correct data, so we allow for such exceptional cases below. | |
8354 | ||
8355 | Note that our goal here is to describe the place where the given formal | |
8356 | parameter lives during most of the function's activation (i.e. between | |
8357 | the end of the prologue and the start of the epilogue). We'll do that | |
8358 | as best as we can. Note however that if the given formal parameter is | |
8359 | modified sometime during the execution of the function, then a stack | |
8360 | backtrace (at debug-time) will show the function as having been | |
8361 | called with the *new* value rather than the value which was | |
8362 | originally passed in. This happens rarely enough that it is not | |
8363 | a major problem, but it *is* a problem, and I'd like to fix it. | |
8364 | ||
8365 | A future version of dwarf2out.c may generate two additional | |
8366 | attributes for any given DW_TAG_formal_parameter DIE which will | |
8367 | describe the "passed type" and the "passed location" for the | |
8368 | given formal parameter in addition to the attributes we now | |
8369 | generate to indicate the "declared type" and the "active | |
8370 | location" for each parameter. This additional set of attributes | |
8371 | could be used by debuggers for stack backtraces. Separately, note | |
8372 | that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be | |
8373 | NULL also. This happens (for example) for inlined-instances of | |
8374 | inline function formal parameters which are never referenced. | |
8375 | This really shouldn't be happening. All PARM_DECL nodes should | |
8376 | get valid non-NULL DECL_INCOMING_RTL values, but integrate.c | |
8377 | doesn't currently generate these values for inlined instances of | |
8378 | inline function parameters, so when we see such cases, we are | |
956d6950 | 8379 | just out-of-luck for the time being (until integrate.c |
a3f97cbb JW |
8380 | gets fixed). */ |
8381 | ||
8382 | /* Use DECL_RTL as the "location" unless we find something better. */ | |
110c3568 | 8383 | rtl = DECL_RTL_IF_SET (decl); |
a3f97cbb JW |
8384 | |
8385 | if (TREE_CODE (decl) == PARM_DECL) | |
8386 | { | |
8387 | if (rtl == NULL_RTX || is_pseudo_reg (rtl)) | |
8388 | { | |
d8041cc8 RH |
8389 | tree declared_type = type_main_variant (TREE_TYPE (decl)); |
8390 | tree passed_type = type_main_variant (DECL_ARG_TYPE (decl)); | |
a3f97cbb | 8391 | |
71dfc51f | 8392 | /* This decl represents a formal parameter which was optimized out. |
a3f97cbb JW |
8393 | Note that DECL_INCOMING_RTL may be NULL in here, but we handle |
8394 | all* cases where (rtl == NULL_RTX) just below. */ | |
8395 | if (declared_type == passed_type) | |
71dfc51f RK |
8396 | rtl = DECL_INCOMING_RTL (decl); |
8397 | else if (! BYTES_BIG_ENDIAN | |
8398 | && TREE_CODE (declared_type) == INTEGER_TYPE | |
555b6442 HPN |
8399 | && (GET_MODE_SIZE (TYPE_MODE (declared_type)) |
8400 | <= GET_MODE_SIZE (TYPE_MODE (passed_type)))) | |
556273e0 | 8401 | rtl = DECL_INCOMING_RTL (decl); |
a3f97cbb | 8402 | } |
5a904a61 JW |
8403 | |
8404 | /* If the parm was passed in registers, but lives on the stack, then | |
8405 | make a big endian correction if the mode of the type of the | |
8406 | parameter is not the same as the mode of the rtl. */ | |
8407 | /* ??? This is the same series of checks that are made in dbxout.c before | |
8408 | we reach the big endian correction code there. It isn't clear if all | |
8409 | of these checks are necessary here, but keeping them all is the safe | |
8410 | thing to do. */ | |
8411 | else if (GET_CODE (rtl) == MEM | |
8412 | && XEXP (rtl, 0) != const0_rtx | |
8413 | && ! CONSTANT_P (XEXP (rtl, 0)) | |
8414 | /* Not passed in memory. */ | |
8415 | && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM | |
8416 | /* Not passed by invisible reference. */ | |
8417 | && (GET_CODE (XEXP (rtl, 0)) != REG | |
8418 | || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM | |
8419 | || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM | |
8420 | #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM | |
8421 | || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM | |
8422 | #endif | |
8423 | ) | |
8424 | /* Big endian correction check. */ | |
8425 | && BYTES_BIG_ENDIAN | |
8426 | && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl) | |
8427 | && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))) | |
8428 | < UNITS_PER_WORD)) | |
8429 | { | |
8430 | int offset = (UNITS_PER_WORD | |
8431 | - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))); | |
8432 | rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)), | |
8433 | plus_constant (XEXP (rtl, 0), offset)); | |
8434 | } | |
a3f97cbb | 8435 | } |
71dfc51f | 8436 | |
d8041cc8 RH |
8437 | if (rtl != NULL_RTX) |
8438 | { | |
8439 | rtl = eliminate_regs (rtl, 0, NULL_RTX); | |
6a7a9f01 | 8440 | #ifdef LEAF_REG_REMAP |
d8041cc8 RH |
8441 | if (current_function_uses_only_leaf_regs) |
8442 | leaf_renumber_regs_insn (rtl); | |
6a7a9f01 | 8443 | #endif |
d8041cc8 RH |
8444 | } |
8445 | ||
8446 | return rtl; | |
8447 | } | |
8448 | ||
8449 | /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value | |
8450 | data attribute for a variable or a parameter. We generate the | |
8451 | DW_AT_const_value attribute only in those cases where the given variable | |
8452 | or parameter does not have a true "location" either in memory or in a | |
8453 | register. This can happen (for example) when a constant is passed as an | |
8454 | actual argument in a call to an inline function. (It's possible that | |
8455 | these things can crop up in other ways also.) Note that one type of | |
8456 | constant value which can be passed into an inlined function is a constant | |
8457 | pointer. This can happen for example if an actual argument in an inlined | |
8458 | function call evaluates to a compile-time constant address. */ | |
8459 | ||
8460 | static void | |
8461 | add_location_or_const_value_attribute (die, decl) | |
8462 | register dw_die_ref die; | |
8463 | register tree decl; | |
8464 | { | |
8465 | register rtx rtl; | |
8466 | ||
8467 | if (TREE_CODE (decl) == ERROR_MARK) | |
8468 | return; | |
8469 | ||
8470 | if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL) | |
8471 | abort (); | |
8472 | ||
8473 | rtl = rtl_for_decl_location (decl); | |
a97c9600 RH |
8474 | if (rtl == NULL_RTX) |
8475 | return; | |
6a7a9f01 | 8476 | |
a3f97cbb JW |
8477 | switch (GET_CODE (rtl)) |
8478 | { | |
e9a25f70 JL |
8479 | case ADDRESSOF: |
8480 | /* The address of a variable that was optimized away; don't emit | |
8481 | anything. */ | |
8482 | break; | |
8483 | ||
a3f97cbb JW |
8484 | case CONST_INT: |
8485 | case CONST_DOUBLE: | |
8486 | case CONST_STRING: | |
8487 | case SYMBOL_REF: | |
8488 | case LABEL_REF: | |
8489 | case CONST: | |
8490 | case PLUS: | |
8491 | /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ | |
8492 | add_const_value_attribute (die, rtl); | |
8493 | break; | |
8494 | ||
8495 | case MEM: | |
8496 | case REG: | |
8497 | case SUBREG: | |
4401bf24 | 8498 | case CONCAT: |
ef76d03b | 8499 | add_AT_location_description (die, DW_AT_location, rtl); |
a3f97cbb JW |
8500 | break; |
8501 | ||
8502 | default: | |
71dfc51f | 8503 | abort (); |
a3f97cbb JW |
8504 | } |
8505 | } | |
8506 | ||
1bfb5f8f JM |
8507 | /* If we don't have a copy of this variable in memory for some reason (such |
8508 | as a C++ member constant that doesn't have an out-of-line definition), | |
8509 | we should tell the debugger about the constant value. */ | |
8510 | ||
8511 | static void | |
8512 | tree_add_const_value_attribute (var_die, decl) | |
8513 | dw_die_ref var_die; | |
8514 | tree decl; | |
8515 | { | |
8516 | tree init = DECL_INITIAL (decl); | |
8517 | tree type = TREE_TYPE (decl); | |
8518 | ||
8519 | if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init | |
8520 | && initializer_constant_valid_p (init, type) == null_pointer_node) | |
8521 | /* OK */; | |
8522 | else | |
8523 | return; | |
8524 | ||
8525 | switch (TREE_CODE (type)) | |
8526 | { | |
8527 | case INTEGER_TYPE: | |
8528 | if (host_integerp (init, 0)) | |
8529 | add_AT_unsigned (var_die, DW_AT_const_value, | |
8530 | TREE_INT_CST_LOW (init)); | |
8531 | else | |
8532 | add_AT_long_long (var_die, DW_AT_const_value, | |
8533 | TREE_INT_CST_HIGH (init), | |
8534 | TREE_INT_CST_LOW (init)); | |
8535 | break; | |
8536 | ||
8537 | default:; | |
8538 | } | |
8539 | } | |
0b34cf1e | 8540 | |
a3f97cbb JW |
8541 | /* Generate an DW_AT_name attribute given some string value to be included as |
8542 | the value of the attribute. */ | |
71dfc51f RK |
8543 | |
8544 | static inline void | |
a3f97cbb JW |
8545 | add_name_attribute (die, name_string) |
8546 | register dw_die_ref die; | |
d560ee52 | 8547 | register const char *name_string; |
a3f97cbb | 8548 | { |
71dfc51f | 8549 | if (name_string != NULL && *name_string != 0) |
14a774a9 RK |
8550 | { |
8551 | if (demangle_name_func) | |
8552 | name_string = (*demangle_name_func) (name_string); | |
8553 | ||
8554 | add_AT_string (die, DW_AT_name, name_string); | |
8555 | } | |
a3f97cbb JW |
8556 | } |
8557 | ||
8558 | /* Given a tree node describing an array bound (either lower or upper) output | |
466446b0 | 8559 | a representation for that bound. */ |
71dfc51f | 8560 | |
a3f97cbb JW |
8561 | static void |
8562 | add_bound_info (subrange_die, bound_attr, bound) | |
8563 | register dw_die_ref subrange_die; | |
8564 | register enum dwarf_attribute bound_attr; | |
8565 | register tree bound; | |
8566 | { | |
ef76d03b JW |
8567 | /* If this is an Ada unconstrained array type, then don't emit any debug |
8568 | info because the array bounds are unknown. They are parameterized when | |
8569 | the type is instantiated. */ | |
8570 | if (contains_placeholder_p (bound)) | |
8571 | return; | |
8572 | ||
a3f97cbb JW |
8573 | switch (TREE_CODE (bound)) |
8574 | { | |
8575 | case ERROR_MARK: | |
8576 | return; | |
8577 | ||
8578 | /* All fixed-bounds are represented by INTEGER_CST nodes. */ | |
8579 | case INTEGER_CST: | |
665f2503 RK |
8580 | if (! host_integerp (bound, 0) |
8581 | || (bound_attr == DW_AT_lower_bound | |
28985b81 | 8582 | && (((is_c_family () || is_java ()) && integer_zerop (bound)) |
665f2503 RK |
8583 | || (is_fortran () && integer_onep (bound))))) |
8584 | /* use the default */ | |
8585 | ; | |
141719a8 | 8586 | else |
665f2503 | 8587 | add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0)); |
a3f97cbb JW |
8588 | break; |
8589 | ||
b1ccbc24 | 8590 | case CONVERT_EXPR: |
a3f97cbb | 8591 | case NOP_EXPR: |
b1ccbc24 RK |
8592 | case NON_LVALUE_EXPR: |
8593 | add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0)); | |
8594 | break; | |
556273e0 | 8595 | |
a3f97cbb JW |
8596 | case SAVE_EXPR: |
8597 | /* If optimization is turned on, the SAVE_EXPRs that describe how to | |
466446b0 JM |
8598 | access the upper bound values may be bogus. If they refer to a |
8599 | register, they may only describe how to get at these values at the | |
8600 | points in the generated code right after they have just been | |
8601 | computed. Worse yet, in the typical case, the upper bound values | |
8602 | will not even *be* computed in the optimized code (though the | |
8603 | number of elements will), so these SAVE_EXPRs are entirely | |
8604 | bogus. In order to compensate for this fact, we check here to see | |
8605 | if optimization is enabled, and if so, we don't add an attribute | |
8606 | for the (unknown and unknowable) upper bound. This should not | |
8607 | cause too much trouble for existing (stupid?) debuggers because | |
8608 | they have to deal with empty upper bounds location descriptions | |
8609 | anyway in order to be able to deal with incomplete array types. | |
8610 | Of course an intelligent debugger (GDB?) should be able to | |
8611 | comprehend that a missing upper bound specification in a array | |
8612 | type used for a storage class `auto' local array variable | |
8613 | indicates that the upper bound is both unknown (at compile- time) | |
8614 | and unknowable (at run-time) due to optimization. | |
8615 | ||
8616 | We assume that a MEM rtx is safe because gcc wouldn't put the | |
8617 | value there unless it was going to be used repeatedly in the | |
8618 | function, i.e. for cleanups. */ | |
1edf43d6 JM |
8619 | if (SAVE_EXPR_RTL (bound) |
8620 | && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)) | |
a3f97cbb | 8621 | { |
466446b0 JM |
8622 | register dw_die_ref ctx = lookup_decl_die (current_function_decl); |
8623 | register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx); | |
f5963e61 JL |
8624 | register rtx loc = SAVE_EXPR_RTL (bound); |
8625 | ||
8626 | /* If the RTL for the SAVE_EXPR is memory, handle the case where | |
8627 | it references an outer function's frame. */ | |
8628 | ||
8629 | if (GET_CODE (loc) == MEM) | |
8630 | { | |
8631 | rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound); | |
8632 | ||
8633 | if (XEXP (loc, 0) != new_addr) | |
c5c76735 | 8634 | loc = gen_rtx_MEM (GET_MODE (loc), new_addr); |
f5963e61 JL |
8635 | } |
8636 | ||
466446b0 JM |
8637 | add_AT_flag (decl_die, DW_AT_artificial, 1); |
8638 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
f5963e61 | 8639 | add_AT_location_description (decl_die, DW_AT_location, loc); |
466446b0 | 8640 | add_AT_die_ref (subrange_die, bound_attr, decl_die); |
a3f97cbb | 8641 | } |
71dfc51f RK |
8642 | |
8643 | /* Else leave out the attribute. */ | |
a3f97cbb | 8644 | break; |
3f76745e | 8645 | |
ef76d03b | 8646 | case VAR_DECL: |
d8041cc8 RH |
8647 | case PARM_DECL: |
8648 | { | |
8649 | dw_die_ref decl_die = lookup_decl_die (bound); | |
8650 | ||
8651 | /* ??? Can this happen, or should the variable have been bound | |
8652 | first? Probably it can, since I imagine that we try to create | |
8653 | the types of parameters in the order in which they exist in | |
0b34cf1e | 8654 | the list, and won't have created a forward reference to a |
d8041cc8 RH |
8655 | later parameter. */ |
8656 | if (decl_die != NULL) | |
8657 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
8658 | break; | |
8659 | } | |
ef76d03b | 8660 | |
3f76745e | 8661 | default: |
d8041cc8 RH |
8662 | { |
8663 | /* Otherwise try to create a stack operation procedure to | |
8664 | evaluate the value of the array bound. */ | |
8665 | ||
8666 | dw_die_ref ctx, decl_die; | |
8667 | dw_loc_descr_ref loc; | |
8668 | ||
8669 | loc = loc_descriptor_from_tree (bound, 0); | |
8670 | if (loc == NULL) | |
8671 | break; | |
8672 | ||
8673 | ctx = lookup_decl_die (current_function_decl); | |
8674 | ||
8675 | decl_die = new_die (DW_TAG_variable, ctx); | |
8676 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
8677 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
8678 | add_AT_loc (decl_die, DW_AT_location, loc); | |
8679 | ||
8680 | add_AT_die_ref (subrange_die, bound_attr, decl_die); | |
8681 | break; | |
8682 | } | |
a3f97cbb JW |
8683 | } |
8684 | } | |
8685 | ||
8686 | /* Note that the block of subscript information for an array type also | |
8687 | includes information about the element type of type given array type. */ | |
71dfc51f | 8688 | |
a3f97cbb JW |
8689 | static void |
8690 | add_subscript_info (type_die, type) | |
8691 | register dw_die_ref type_die; | |
8692 | register tree type; | |
8693 | { | |
081f5e7e | 8694 | #ifndef MIPS_DEBUGGING_INFO |
a3f97cbb | 8695 | register unsigned dimension_number; |
081f5e7e | 8696 | #endif |
a3f97cbb JW |
8697 | register tree lower, upper; |
8698 | register dw_die_ref subrange_die; | |
8699 | ||
556273e0 | 8700 | /* The GNU compilers represent multidimensional array types as sequences of |
a3f97cbb JW |
8701 | one dimensional array types whose element types are themselves array |
8702 | types. Here we squish that down, so that each multidimensional array | |
556273e0 | 8703 | type gets only one array_type DIE in the Dwarf debugging info. The draft |
a3f97cbb JW |
8704 | Dwarf specification say that we are allowed to do this kind of |
8705 | compression in C (because there is no difference between an array or | |
556273e0 | 8706 | arrays and a multidimensional array in C) but for other source languages |
a3f97cbb | 8707 | (e.g. Ada) we probably shouldn't do this. */ |
71dfc51f | 8708 | |
a3f97cbb JW |
8709 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
8710 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
8711 | We work around this by disabling this feature. See also | |
8712 | gen_array_type_die. */ | |
8713 | #ifndef MIPS_DEBUGGING_INFO | |
8714 | for (dimension_number = 0; | |
8715 | TREE_CODE (type) == ARRAY_TYPE; | |
8716 | type = TREE_TYPE (type), dimension_number++) | |
8717 | { | |
8718 | #endif | |
8719 | register tree domain = TYPE_DOMAIN (type); | |
8720 | ||
8721 | /* Arrays come in three flavors: Unspecified bounds, fixed bounds, | |
556273e0 | 8722 | and (in GNU C only) variable bounds. Handle all three forms |
a3f97cbb JW |
8723 | here. */ |
8724 | subrange_die = new_die (DW_TAG_subrange_type, type_die); | |
8725 | if (domain) | |
8726 | { | |
8727 | /* We have an array type with specified bounds. */ | |
8728 | lower = TYPE_MIN_VALUE (domain); | |
8729 | upper = TYPE_MAX_VALUE (domain); | |
8730 | ||
a9d38797 JM |
8731 | /* define the index type. */ |
8732 | if (TREE_TYPE (domain)) | |
ef76d03b JW |
8733 | { |
8734 | /* ??? This is probably an Ada unnamed subrange type. Ignore the | |
8735 | TREE_TYPE field. We can't emit debug info for this | |
8736 | because it is an unnamed integral type. */ | |
8737 | if (TREE_CODE (domain) == INTEGER_TYPE | |
8738 | && TYPE_NAME (domain) == NULL_TREE | |
8739 | && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE | |
8740 | && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE) | |
556273e0 | 8741 | ; |
ef76d03b JW |
8742 | else |
8743 | add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0, | |
8744 | type_die); | |
8745 | } | |
a9d38797 | 8746 | |
e1ee5cdc RH |
8747 | /* ??? If upper is NULL, the array has unspecified length, |
8748 | but it does have a lower bound. This happens with Fortran | |
8749 | dimension arr(N:*) | |
8750 | Since the debugger is definitely going to need to know N | |
8751 | to produce useful results, go ahead and output the lower | |
8752 | bound solo, and hope the debugger can cope. */ | |
8753 | ||
141719a8 | 8754 | add_bound_info (subrange_die, DW_AT_lower_bound, lower); |
e1ee5cdc RH |
8755 | if (upper) |
8756 | add_bound_info (subrange_die, DW_AT_upper_bound, upper); | |
a3f97cbb JW |
8757 | } |
8758 | else | |
71dfc51f | 8759 | /* We have an array type with an unspecified length. The DWARF-2 |
a9d38797 JM |
8760 | spec does not say how to handle this; let's just leave out the |
8761 | bounds. */ | |
e49a1d2e | 8762 | {;} |
71dfc51f | 8763 | |
a3f97cbb JW |
8764 | #ifndef MIPS_DEBUGGING_INFO |
8765 | } | |
8766 | #endif | |
8767 | } | |
8768 | ||
8769 | static void | |
8770 | add_byte_size_attribute (die, tree_node) | |
8771 | dw_die_ref die; | |
8772 | register tree tree_node; | |
8773 | { | |
8774 | register unsigned size; | |
8775 | ||
8776 | switch (TREE_CODE (tree_node)) | |
8777 | { | |
8778 | case ERROR_MARK: | |
8779 | size = 0; | |
8780 | break; | |
8781 | case ENUMERAL_TYPE: | |
8782 | case RECORD_TYPE: | |
8783 | case UNION_TYPE: | |
8784 | case QUAL_UNION_TYPE: | |
8785 | size = int_size_in_bytes (tree_node); | |
8786 | break; | |
8787 | case FIELD_DECL: | |
8788 | /* For a data member of a struct or union, the DW_AT_byte_size is | |
8789 | generally given as the number of bytes normally allocated for an | |
8790 | object of the *declared* type of the member itself. This is true | |
8791 | even for bit-fields. */ | |
8792 | size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT; | |
8793 | break; | |
8794 | default: | |
8795 | abort (); | |
8796 | } | |
8797 | ||
8798 | /* Note that `size' might be -1 when we get to this point. If it is, that | |
8799 | indicates that the byte size of the entity in question is variable. We | |
8800 | have no good way of expressing this fact in Dwarf at the present time, | |
8801 | so just let the -1 pass on through. */ | |
8802 | ||
8803 | add_AT_unsigned (die, DW_AT_byte_size, size); | |
8804 | } | |
8805 | ||
8806 | /* For a FIELD_DECL node which represents a bit-field, output an attribute | |
8807 | which specifies the distance in bits from the highest order bit of the | |
8808 | "containing object" for the bit-field to the highest order bit of the | |
8809 | bit-field itself. | |
8810 | ||
b2932ae5 JM |
8811 | For any given bit-field, the "containing object" is a hypothetical |
8812 | object (of some integral or enum type) within which the given bit-field | |
8813 | lives. The type of this hypothetical "containing object" is always the | |
8814 | same as the declared type of the individual bit-field itself. The | |
8815 | determination of the exact location of the "containing object" for a | |
8816 | bit-field is rather complicated. It's handled by the | |
8817 | `field_byte_offset' function (above). | |
a3f97cbb JW |
8818 | |
8819 | Note that it is the size (in bytes) of the hypothetical "containing object" | |
8820 | which will be given in the DW_AT_byte_size attribute for this bit-field. | |
8821 | (See `byte_size_attribute' above). */ | |
71dfc51f RK |
8822 | |
8823 | static inline void | |
a3f97cbb JW |
8824 | add_bit_offset_attribute (die, decl) |
8825 | register dw_die_ref die; | |
8826 | register tree decl; | |
8827 | { | |
665f2503 RK |
8828 | HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl); |
8829 | tree type = DECL_BIT_FIELD_TYPE (decl); | |
8830 | HOST_WIDE_INT bitpos_int; | |
8831 | HOST_WIDE_INT highest_order_object_bit_offset; | |
8832 | HOST_WIDE_INT highest_order_field_bit_offset; | |
8833 | HOST_WIDE_INT unsigned bit_offset; | |
a3f97cbb | 8834 | |
3a88cbd1 JL |
8835 | /* Must be a field and a bit field. */ |
8836 | if (!type | |
8837 | || TREE_CODE (decl) != FIELD_DECL) | |
8838 | abort (); | |
a3f97cbb JW |
8839 | |
8840 | /* We can't yet handle bit-fields whose offsets are variable, so if we | |
8841 | encounter such things, just return without generating any attribute | |
665f2503 RK |
8842 | whatsoever. Likewise for variable or too large size. */ |
8843 | if (! host_integerp (bit_position (decl), 0) | |
8844 | || ! host_integerp (DECL_SIZE (decl), 1)) | |
71dfc51f RK |
8845 | return; |
8846 | ||
665f2503 | 8847 | bitpos_int = int_bit_position (decl); |
a3f97cbb JW |
8848 | |
8849 | /* Note that the bit offset is always the distance (in bits) from the | |
556273e0 KH |
8850 | highest-order bit of the "containing object" to the highest-order bit of |
8851 | the bit-field itself. Since the "high-order end" of any object or field | |
a3f97cbb JW |
8852 | is different on big-endian and little-endian machines, the computation |
8853 | below must take account of these differences. */ | |
8854 | highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; | |
8855 | highest_order_field_bit_offset = bitpos_int; | |
8856 | ||
71dfc51f | 8857 | if (! BYTES_BIG_ENDIAN) |
a3f97cbb | 8858 | { |
665f2503 | 8859 | highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0); |
a3f97cbb JW |
8860 | highest_order_object_bit_offset += simple_type_size_in_bits (type); |
8861 | } | |
71dfc51f RK |
8862 | |
8863 | bit_offset | |
8864 | = (! BYTES_BIG_ENDIAN | |
8865 | ? highest_order_object_bit_offset - highest_order_field_bit_offset | |
8866 | : highest_order_field_bit_offset - highest_order_object_bit_offset); | |
a3f97cbb JW |
8867 | |
8868 | add_AT_unsigned (die, DW_AT_bit_offset, bit_offset); | |
8869 | } | |
8870 | ||
8871 | /* For a FIELD_DECL node which represents a bit field, output an attribute | |
8872 | which specifies the length in bits of the given field. */ | |
71dfc51f RK |
8873 | |
8874 | static inline void | |
a3f97cbb JW |
8875 | add_bit_size_attribute (die, decl) |
8876 | register dw_die_ref die; | |
8877 | register tree decl; | |
8878 | { | |
3a88cbd1 JL |
8879 | /* Must be a field and a bit field. */ |
8880 | if (TREE_CODE (decl) != FIELD_DECL | |
8881 | || ! DECL_BIT_FIELD_TYPE (decl)) | |
8882 | abort (); | |
665f2503 RK |
8883 | |
8884 | if (host_integerp (DECL_SIZE (decl), 1)) | |
8885 | add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1)); | |
a3f97cbb JW |
8886 | } |
8887 | ||
88dad228 | 8888 | /* If the compiled language is ANSI C, then add a 'prototyped' |
a3f97cbb | 8889 | attribute, if arg types are given for the parameters of a function. */ |
71dfc51f RK |
8890 | |
8891 | static inline void | |
a3f97cbb JW |
8892 | add_prototyped_attribute (die, func_type) |
8893 | register dw_die_ref die; | |
8894 | register tree func_type; | |
8895 | { | |
88dad228 JM |
8896 | if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89 |
8897 | && TYPE_ARG_TYPES (func_type) != NULL) | |
8898 | add_AT_flag (die, DW_AT_prototyped, 1); | |
a3f97cbb JW |
8899 | } |
8900 | ||
a3f97cbb JW |
8901 | /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found |
8902 | by looking in either the type declaration or object declaration | |
8903 | equate table. */ | |
71dfc51f RK |
8904 | |
8905 | static inline void | |
a3f97cbb JW |
8906 | add_abstract_origin_attribute (die, origin) |
8907 | register dw_die_ref die; | |
8908 | register tree origin; | |
8909 | { | |
8910 | dw_die_ref origin_die = NULL; | |
bbc6ae08 | 8911 | |
d10b8e05 | 8912 | if (TREE_CODE (origin) != FUNCTION_DECL) |
e40a1c67 JM |
8913 | { |
8914 | /* We may have gotten separated from the block for the inlined | |
8915 | function, if we're in an exception handler or some such; make | |
8916 | sure that the abstract function has been written out. | |
8917 | ||
8918 | Doing this for nested functions is wrong, however; functions are | |
8919 | distinct units, and our context might not even be inline. */ | |
fb13d4d0 JM |
8920 | tree fn = origin; |
8921 | if (TYPE_P (fn)) | |
8922 | fn = TYPE_STUB_DECL (fn); | |
8923 | fn = decl_function_context (fn); | |
e40a1c67 | 8924 | if (fn) |
1edf43d6 | 8925 | dwarf2out_abstract_function (fn); |
e40a1c67 | 8926 | } |
44db1d9c | 8927 | |
2f939d94 | 8928 | if (DECL_P (origin)) |
71dfc51f | 8929 | origin_die = lookup_decl_die (origin); |
2f939d94 | 8930 | else if (TYPE_P (origin)) |
71dfc51f RK |
8931 | origin_die = lookup_type_die (origin); |
8932 | ||
bbc6ae08 | 8933 | if (origin_die == NULL) |
1ae8994f | 8934 | abort (); |
556273e0 | 8935 | |
a3f97cbb JW |
8936 | add_AT_die_ref (die, DW_AT_abstract_origin, origin_die); |
8937 | } | |
8938 | ||
bdb669cb JM |
8939 | /* We do not currently support the pure_virtual attribute. */ |
8940 | ||
71dfc51f | 8941 | static inline void |
a3f97cbb JW |
8942 | add_pure_or_virtual_attribute (die, func_decl) |
8943 | register dw_die_ref die; | |
8944 | register tree func_decl; | |
8945 | { | |
a94dbf2c | 8946 | if (DECL_VINDEX (func_decl)) |
a3f97cbb | 8947 | { |
bdb669cb | 8948 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); |
665f2503 RK |
8949 | |
8950 | if (host_integerp (DECL_VINDEX (func_decl), 0)) | |
8951 | add_AT_loc (die, DW_AT_vtable_elem_location, | |
8952 | new_loc_descr (DW_OP_constu, | |
8953 | tree_low_cst (DECL_VINDEX (func_decl), 0), | |
8954 | 0)); | |
71dfc51f | 8955 | |
a94dbf2c JM |
8956 | /* GNU extension: Record what type this method came from originally. */ |
8957 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
8958 | add_AT_die_ref (die, DW_AT_containing_type, | |
8959 | lookup_type_die (DECL_CONTEXT (func_decl))); | |
a3f97cbb JW |
8960 | } |
8961 | } | |
8962 | \f | |
b2932ae5 | 8963 | /* Add source coordinate attributes for the given decl. */ |
71dfc51f | 8964 | |
b2932ae5 JM |
8965 | static void |
8966 | add_src_coords_attributes (die, decl) | |
8967 | register dw_die_ref die; | |
8968 | register tree decl; | |
8969 | { | |
981975b6 | 8970 | register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
71dfc51f | 8971 | |
b2932ae5 JM |
8972 | add_AT_unsigned (die, DW_AT_decl_file, file_index); |
8973 | add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
8974 | } | |
8975 | ||
a3f97cbb JW |
8976 | /* Add an DW_AT_name attribute and source coordinate attribute for the |
8977 | given decl, but only if it actually has a name. */ | |
71dfc51f | 8978 | |
a3f97cbb JW |
8979 | static void |
8980 | add_name_and_src_coords_attributes (die, decl) | |
8981 | register dw_die_ref die; | |
8982 | register tree decl; | |
8983 | { | |
61b32c02 | 8984 | register tree decl_name; |
71dfc51f | 8985 | |
556273e0 | 8986 | decl_name = DECL_NAME (decl); |
71dfc51f | 8987 | if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL) |
a3f97cbb | 8988 | { |
a1d7ffe3 | 8989 | add_name_attribute (die, dwarf2_name (decl, 0)); |
a96c67ec JM |
8990 | if (! DECL_ARTIFICIAL (decl)) |
8991 | add_src_coords_attributes (die, decl); | |
e689ae67 | 8992 | |
a1d7ffe3 | 8993 | if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) |
bc808e0b | 8994 | && TREE_PUBLIC (decl) |
5daf7c0a JM |
8995 | && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) |
8996 | && !DECL_ABSTRACT (decl)) | |
a1d7ffe3 JM |
8997 | add_AT_string (die, DW_AT_MIPS_linkage_name, |
8998 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
a3f97cbb JW |
8999 | } |
9000 | } | |
9001 | ||
556273e0 | 9002 | /* Push a new declaration scope. */ |
71dfc51f | 9003 | |
a3f97cbb JW |
9004 | static void |
9005 | push_decl_scope (scope) | |
9006 | tree scope; | |
9007 | { | |
9008 | /* Make room in the decl_scope_table, if necessary. */ | |
9009 | if (decl_scope_table_allocated == decl_scope_depth) | |
9010 | { | |
9011 | decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT; | |
71dfc51f | 9012 | decl_scope_table |
777ad4c2 JM |
9013 | = (tree *) xrealloc (decl_scope_table, |
9014 | decl_scope_table_allocated * sizeof (tree)); | |
a3f97cbb | 9015 | } |
71dfc51f | 9016 | |
777ad4c2 | 9017 | decl_scope_table[decl_scope_depth] = scope; |
e3e7774e | 9018 | decl_scope_depth++; |
a3f97cbb JW |
9019 | } |
9020 | ||
777ad4c2 JM |
9021 | /* Pop a declaration scope. */ |
9022 | static inline void | |
9023 | pop_decl_scope () | |
9024 | { | |
9025 | if (decl_scope_depth <= 0) | |
9026 | abort (); | |
9027 | --decl_scope_depth; | |
9028 | } | |
9029 | ||
9030 | /* Return the DIE for the scope that immediately contains this type. | |
9031 | Non-named types get global scope. Named types nested in other | |
9032 | types get their containing scope if it's open, or global scope | |
9033 | otherwise. All other types (i.e. function-local named types) get | |
9034 | the current active scope. */ | |
71dfc51f | 9035 | |
a3f97cbb | 9036 | static dw_die_ref |
ab72d377 | 9037 | scope_die_for (t, context_die) |
556273e0 KH |
9038 | register tree t; |
9039 | register dw_die_ref context_die; | |
a3f97cbb JW |
9040 | { |
9041 | register dw_die_ref scope_die = NULL; | |
9042 | register tree containing_scope; | |
e3e7774e | 9043 | register int i; |
a3f97cbb | 9044 | |
777ad4c2 JM |
9045 | /* Non-types always go in the current scope. */ |
9046 | if (! TYPE_P (t)) | |
9047 | abort (); | |
9048 | ||
9049 | containing_scope = TYPE_CONTEXT (t); | |
ab72d377 | 9050 | |
2addbe1d JM |
9051 | /* Ignore namespaces for the moment. */ |
9052 | if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL) | |
9053 | containing_scope = NULL_TREE; | |
9054 | ||
5f2f160c JM |
9055 | /* Ignore function type "scopes" from the C frontend. They mean that |
9056 | a tagged type is local to a parmlist of a function declarator, but | |
9057 | that isn't useful to DWARF. */ | |
9058 | if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE) | |
9059 | containing_scope = NULL_TREE; | |
9060 | ||
71dfc51f RK |
9061 | if (containing_scope == NULL_TREE) |
9062 | scope_die = comp_unit_die; | |
777ad4c2 | 9063 | else if (TYPE_P (containing_scope)) |
348bb3c7 | 9064 | { |
777ad4c2 JM |
9065 | /* For types, we can just look up the appropriate DIE. But |
9066 | first we check to see if we're in the middle of emitting it | |
9067 | so we know where the new DIE should go. */ | |
348bb3c7 JM |
9068 | |
9069 | for (i = decl_scope_depth - 1; i >= 0; --i) | |
777ad4c2 | 9070 | if (decl_scope_table[i] == containing_scope) |
348bb3c7 JM |
9071 | break; |
9072 | ||
9073 | if (i < 0) | |
9074 | { | |
348bb3c7 JM |
9075 | if (debug_info_level > DINFO_LEVEL_TERSE |
9076 | && !TREE_ASM_WRITTEN (containing_scope)) | |
9077 | abort (); | |
9078 | ||
9079 | /* If none of the current dies are suitable, we get file scope. */ | |
9080 | scope_die = comp_unit_die; | |
9081 | } | |
9082 | else | |
777ad4c2 | 9083 | scope_die = lookup_type_die (containing_scope); |
348bb3c7 | 9084 | } |
a3f97cbb | 9085 | else |
777ad4c2 | 9086 | scope_die = context_die; |
71dfc51f | 9087 | |
a3f97cbb JW |
9088 | return scope_die; |
9089 | } | |
9090 | ||
777ad4c2 JM |
9091 | /* Returns nonzero iff CONTEXT_DIE is internal to a function. */ |
9092 | ||
c6991660 | 9093 | static inline int local_scope_p PARAMS ((dw_die_ref)); |
777ad4c2 JM |
9094 | static inline int |
9095 | local_scope_p (context_die) | |
9096 | dw_die_ref context_die; | |
a3f97cbb | 9097 | { |
777ad4c2 JM |
9098 | for (; context_die; context_die = context_die->die_parent) |
9099 | if (context_die->die_tag == DW_TAG_inlined_subroutine | |
9100 | || context_die->die_tag == DW_TAG_subprogram) | |
9101 | return 1; | |
9102 | return 0; | |
a3f97cbb JW |
9103 | } |
9104 | ||
9765e357 JM |
9105 | /* Returns nonzero iff CONTEXT_DIE is a class. */ |
9106 | ||
c6991660 | 9107 | static inline int class_scope_p PARAMS ((dw_die_ref)); |
9765e357 JM |
9108 | static inline int |
9109 | class_scope_p (context_die) | |
9110 | dw_die_ref context_die; | |
9111 | { | |
9112 | return (context_die | |
9113 | && (context_die->die_tag == DW_TAG_structure_type | |
9114 | || context_die->die_tag == DW_TAG_union_type)); | |
9115 | } | |
9116 | ||
a3f97cbb JW |
9117 | /* Many forms of DIEs require a "type description" attribute. This |
9118 | routine locates the proper "type descriptor" die for the type given | |
9119 | by 'type', and adds an DW_AT_type attribute below the given die. */ | |
71dfc51f | 9120 | |
a3f97cbb JW |
9121 | static void |
9122 | add_type_attribute (object_die, type, decl_const, decl_volatile, context_die) | |
9123 | register dw_die_ref object_die; | |
9124 | register tree type; | |
9125 | register int decl_const; | |
9126 | register int decl_volatile; | |
9127 | register dw_die_ref context_die; | |
9128 | { | |
9129 | register enum tree_code code = TREE_CODE (type); | |
a3f97cbb JW |
9130 | register dw_die_ref type_die = NULL; |
9131 | ||
ef76d03b JW |
9132 | /* ??? If this type is an unnamed subrange type of an integral or |
9133 | floating-point type, use the inner type. This is because we have no | |
9134 | support for unnamed types in base_type_die. This can happen if this is | |
9135 | an Ada subrange type. Correct solution is emit a subrange type die. */ | |
b1ccbc24 RK |
9136 | if ((code == INTEGER_TYPE || code == REAL_TYPE) |
9137 | && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0) | |
9138 | type = TREE_TYPE (type), code = TREE_CODE (type); | |
9139 | ||
a3f97cbb | 9140 | if (code == ERROR_MARK) |
b1ccbc24 | 9141 | return; |
a3f97cbb JW |
9142 | |
9143 | /* Handle a special case. For functions whose return type is void, we | |
9144 | generate *no* type attribute. (Note that no object may have type | |
9145 | `void', so this only applies to function return types). */ | |
9146 | if (code == VOID_TYPE) | |
b1ccbc24 | 9147 | return; |
a3f97cbb | 9148 | |
a3f97cbb JW |
9149 | type_die = modified_type_die (type, |
9150 | decl_const || TYPE_READONLY (type), | |
9151 | decl_volatile || TYPE_VOLATILE (type), | |
ab72d377 | 9152 | context_die); |
a3f97cbb | 9153 | if (type_die != NULL) |
71dfc51f | 9154 | add_AT_die_ref (object_die, DW_AT_type, type_die); |
a3f97cbb JW |
9155 | } |
9156 | ||
9157 | /* Given a tree pointer to a struct, class, union, or enum type node, return | |
9158 | a pointer to the (string) tag name for the given type, or zero if the type | |
9159 | was declared without a tag. */ | |
71dfc51f | 9160 | |
d3e3972c | 9161 | static const char * |
a3f97cbb JW |
9162 | type_tag (type) |
9163 | register tree type; | |
9164 | { | |
d3e3972c | 9165 | register const char *name = 0; |
a3f97cbb JW |
9166 | |
9167 | if (TYPE_NAME (type) != 0) | |
9168 | { | |
9169 | register tree t = 0; | |
9170 | ||
9171 | /* Find the IDENTIFIER_NODE for the type name. */ | |
9172 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
9173 | t = TYPE_NAME (type); | |
bdb669cb | 9174 | |
556273e0 | 9175 | /* The g++ front end makes the TYPE_NAME of *each* tagged type point to |
a3f97cbb | 9176 | a TYPE_DECL node, regardless of whether or not a `typedef' was |
bdb669cb | 9177 | involved. */ |
a94dbf2c JM |
9178 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
9179 | && ! DECL_IGNORED_P (TYPE_NAME (type))) | |
a3f97cbb | 9180 | t = DECL_NAME (TYPE_NAME (type)); |
bdb669cb | 9181 | |
a3f97cbb JW |
9182 | /* Now get the name as a string, or invent one. */ |
9183 | if (t != 0) | |
a94dbf2c | 9184 | name = IDENTIFIER_POINTER (t); |
a3f97cbb | 9185 | } |
71dfc51f | 9186 | |
a3f97cbb JW |
9187 | return (name == 0 || *name == '\0') ? 0 : name; |
9188 | } | |
9189 | ||
9190 | /* Return the type associated with a data member, make a special check | |
9191 | for bit field types. */ | |
71dfc51f RK |
9192 | |
9193 | static inline tree | |
a3f97cbb JW |
9194 | member_declared_type (member) |
9195 | register tree member; | |
9196 | { | |
71dfc51f RK |
9197 | return (DECL_BIT_FIELD_TYPE (member) |
9198 | ? DECL_BIT_FIELD_TYPE (member) | |
9199 | : TREE_TYPE (member)); | |
a3f97cbb JW |
9200 | } |
9201 | ||
d291dd49 | 9202 | /* Get the decl's label, as described by its RTL. This may be different |
a3f97cbb | 9203 | from the DECL_NAME name used in the source file. */ |
71dfc51f | 9204 | |
487a6e06 | 9205 | #if 0 |
d3e3972c | 9206 | static const char * |
d291dd49 | 9207 | decl_start_label (decl) |
a3f97cbb JW |
9208 | register tree decl; |
9209 | { | |
9210 | rtx x; | |
d3e3972c | 9211 | const char *fnname; |
a3f97cbb JW |
9212 | x = DECL_RTL (decl); |
9213 | if (GET_CODE (x) != MEM) | |
71dfc51f RK |
9214 | abort (); |
9215 | ||
a3f97cbb JW |
9216 | x = XEXP (x, 0); |
9217 | if (GET_CODE (x) != SYMBOL_REF) | |
71dfc51f RK |
9218 | abort (); |
9219 | ||
a3f97cbb JW |
9220 | fnname = XSTR (x, 0); |
9221 | return fnname; | |
9222 | } | |
487a6e06 | 9223 | #endif |
a3f97cbb | 9224 | \f |
956d6950 | 9225 | /* These routines generate the internal representation of the DIE's for |
a3f97cbb | 9226 | the compilation unit. Debugging information is collected by walking |
88dad228 | 9227 | the declaration trees passed in from dwarf2out_decl(). */ |
a3f97cbb JW |
9228 | |
9229 | static void | |
9230 | gen_array_type_die (type, context_die) | |
9231 | register tree type; | |
9232 | register dw_die_ref context_die; | |
9233 | { | |
ab72d377 | 9234 | register dw_die_ref scope_die = scope_die_for (type, context_die); |
a9d38797 | 9235 | register dw_die_ref array_die; |
a3f97cbb | 9236 | register tree element_type; |
bdb669cb | 9237 | |
a9d38797 JM |
9238 | /* ??? The SGI dwarf reader fails for array of array of enum types unless |
9239 | the inner array type comes before the outer array type. Thus we must | |
9240 | call gen_type_die before we call new_die. See below also. */ | |
9241 | #ifdef MIPS_DEBUGGING_INFO | |
9242 | gen_type_die (TREE_TYPE (type), context_die); | |
9243 | #endif | |
9244 | ||
9245 | array_die = new_die (DW_TAG_array_type, scope_die); | |
9246 | ||
a3f97cbb JW |
9247 | #if 0 |
9248 | /* We default the array ordering. SDB will probably do | |
9249 | the right things even if DW_AT_ordering is not present. It's not even | |
9250 | an issue until we start to get into multidimensional arrays anyway. If | |
9251 | SDB is ever caught doing the Wrong Thing for multi-dimensional arrays, | |
9252 | then we'll have to put the DW_AT_ordering attribute back in. (But if | |
9253 | and when we find out that we need to put these in, we will only do so | |
9254 | for multidimensional arrays. */ | |
9255 | add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major); | |
9256 | #endif | |
9257 | ||
a9d38797 | 9258 | #ifdef MIPS_DEBUGGING_INFO |
4edb7b60 JM |
9259 | /* The SGI compilers handle arrays of unknown bound by setting |
9260 | AT_declaration and not emitting any subrange DIEs. */ | |
a9d38797 JM |
9261 | if (! TYPE_DOMAIN (type)) |
9262 | add_AT_unsigned (array_die, DW_AT_declaration, 1); | |
9263 | else | |
9264 | #endif | |
9265 | add_subscript_info (array_die, type); | |
a3f97cbb | 9266 | |
14a774a9 | 9267 | add_name_attribute (array_die, type_tag (type)); |
a3f97cbb JW |
9268 | equate_type_number_to_die (type, array_die); |
9269 | ||
9270 | /* Add representation of the type of the elements of this array type. */ | |
9271 | element_type = TREE_TYPE (type); | |
71dfc51f | 9272 | |
a3f97cbb JW |
9273 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
9274 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
9275 | We work around this by disabling this feature. See also | |
9276 | add_subscript_info. */ | |
9277 | #ifndef MIPS_DEBUGGING_INFO | |
71dfc51f RK |
9278 | while (TREE_CODE (element_type) == ARRAY_TYPE) |
9279 | element_type = TREE_TYPE (element_type); | |
9280 | ||
a3f97cbb | 9281 | gen_type_die (element_type, context_die); |
a9d38797 | 9282 | #endif |
a3f97cbb JW |
9283 | |
9284 | add_type_attribute (array_die, element_type, 0, 0, context_die); | |
9285 | } | |
9286 | ||
9287 | static void | |
9288 | gen_set_type_die (type, context_die) | |
9289 | register tree type; | |
9290 | register dw_die_ref context_die; | |
9291 | { | |
71dfc51f RK |
9292 | register dw_die_ref type_die |
9293 | = new_die (DW_TAG_set_type, scope_die_for (type, context_die)); | |
9294 | ||
a3f97cbb | 9295 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
9296 | add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die); |
9297 | } | |
9298 | ||
d6f4ec51 | 9299 | #if 0 |
a3f97cbb JW |
9300 | static void |
9301 | gen_entry_point_die (decl, context_die) | |
9302 | register tree decl; | |
9303 | register dw_die_ref context_die; | |
9304 | { | |
9305 | register tree origin = decl_ultimate_origin (decl); | |
9306 | register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die); | |
9307 | if (origin != NULL) | |
71dfc51f | 9308 | add_abstract_origin_attribute (decl_die, origin); |
a3f97cbb JW |
9309 | else |
9310 | { | |
9311 | add_name_and_src_coords_attributes (decl_die, decl); | |
a3f97cbb JW |
9312 | add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)), |
9313 | 0, 0, context_die); | |
9314 | } | |
71dfc51f | 9315 | |
a3f97cbb | 9316 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 9317 | equate_decl_number_to_die (decl, decl_die); |
a3f97cbb | 9318 | else |
71dfc51f | 9319 | add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl)); |
a3f97cbb | 9320 | } |
d6f4ec51 | 9321 | #endif |
a3f97cbb | 9322 | |
8a8c3656 JM |
9323 | /* Remember a type in the incomplete_types_list. */ |
9324 | ||
9325 | static void | |
9326 | add_incomplete_type (type) | |
9327 | tree type; | |
9328 | { | |
9329 | if (incomplete_types == incomplete_types_allocated) | |
9330 | { | |
9331 | incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT; | |
9332 | incomplete_types_list | |
9333 | = (tree *) xrealloc (incomplete_types_list, | |
9334 | sizeof (tree) * incomplete_types_allocated); | |
9335 | } | |
9336 | ||
9337 | incomplete_types_list[incomplete_types++] = type; | |
9338 | } | |
9339 | ||
9340 | /* Walk through the list of incomplete types again, trying once more to | |
9341 | emit full debugging info for them. */ | |
9342 | ||
9343 | static void | |
9344 | retry_incomplete_types () | |
9345 | { | |
9346 | register tree type; | |
9347 | ||
9348 | while (incomplete_types) | |
9349 | { | |
9350 | --incomplete_types; | |
9351 | type = incomplete_types_list[incomplete_types]; | |
9352 | gen_type_die (type, comp_unit_die); | |
9353 | } | |
9354 | } | |
9355 | ||
a3f97cbb | 9356 | /* Generate a DIE to represent an inlined instance of an enumeration type. */ |
71dfc51f | 9357 | |
a3f97cbb JW |
9358 | static void |
9359 | gen_inlined_enumeration_type_die (type, context_die) | |
9360 | register tree type; | |
9361 | register dw_die_ref context_die; | |
9362 | { | |
71dfc51f | 9363 | register dw_die_ref type_die = new_die (DW_TAG_enumeration_type, |
777ad4c2 | 9364 | context_die); |
bbc6ae08 NC |
9365 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9366 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9367 | add_abstract_origin_attribute (type_die, type); |
9368 | } | |
9369 | ||
9370 | /* Generate a DIE to represent an inlined instance of a structure type. */ | |
71dfc51f | 9371 | |
a3f97cbb JW |
9372 | static void |
9373 | gen_inlined_structure_type_die (type, context_die) | |
9374 | register tree type; | |
9375 | register dw_die_ref context_die; | |
9376 | { | |
777ad4c2 JM |
9377 | register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die); |
9378 | ||
bbc6ae08 NC |
9379 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9380 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9381 | add_abstract_origin_attribute (type_die, type); |
9382 | } | |
9383 | ||
9384 | /* Generate a DIE to represent an inlined instance of a union type. */ | |
71dfc51f | 9385 | |
a3f97cbb JW |
9386 | static void |
9387 | gen_inlined_union_type_die (type, context_die) | |
9388 | register tree type; | |
9389 | register dw_die_ref context_die; | |
9390 | { | |
777ad4c2 JM |
9391 | register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die); |
9392 | ||
bbc6ae08 NC |
9393 | /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may |
9394 | be incomplete and such types are not marked. */ | |
a3f97cbb JW |
9395 | add_abstract_origin_attribute (type_die, type); |
9396 | } | |
9397 | ||
9398 | /* Generate a DIE to represent an enumeration type. Note that these DIEs | |
9399 | include all of the information about the enumeration values also. Each | |
273dbe67 JM |
9400 | enumerated type name/value is listed as a child of the enumerated type |
9401 | DIE. */ | |
71dfc51f | 9402 | |
a3f97cbb | 9403 | static void |
273dbe67 | 9404 | gen_enumeration_type_die (type, context_die) |
a3f97cbb | 9405 | register tree type; |
a3f97cbb JW |
9406 | register dw_die_ref context_die; |
9407 | { | |
273dbe67 JM |
9408 | register dw_die_ref type_die = lookup_type_die (type); |
9409 | ||
a3f97cbb JW |
9410 | if (type_die == NULL) |
9411 | { | |
9412 | type_die = new_die (DW_TAG_enumeration_type, | |
ab72d377 | 9413 | scope_die_for (type, context_die)); |
a3f97cbb JW |
9414 | equate_type_number_to_die (type, type_die); |
9415 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 9416 | } |
273dbe67 JM |
9417 | else if (! TYPE_SIZE (type)) |
9418 | return; | |
9419 | else | |
9420 | remove_AT (type_die, DW_AT_declaration); | |
9421 | ||
9422 | /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the | |
9423 | given enum type is incomplete, do not generate the DW_AT_byte_size | |
9424 | attribute or the DW_AT_element_list attribute. */ | |
9425 | if (TYPE_SIZE (type)) | |
a3f97cbb | 9426 | { |
273dbe67 | 9427 | register tree link; |
71dfc51f | 9428 | |
a082c85a | 9429 | TREE_ASM_WRITTEN (type) = 1; |
273dbe67 | 9430 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 9431 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 9432 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 9433 | |
ef76d03b JW |
9434 | /* If the first reference to this type was as the return type of an |
9435 | inline function, then it may not have a parent. Fix this now. */ | |
9436 | if (type_die->die_parent == NULL) | |
9437 | add_child_die (scope_die_for (type, context_die), type_die); | |
9438 | ||
273dbe67 JM |
9439 | for (link = TYPE_FIELDS (type); |
9440 | link != NULL; link = TREE_CHAIN (link)) | |
a3f97cbb | 9441 | { |
273dbe67 | 9442 | register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die); |
71dfc51f | 9443 | |
273dbe67 JM |
9444 | add_name_attribute (enum_die, |
9445 | IDENTIFIER_POINTER (TREE_PURPOSE (link))); | |
665f2503 RK |
9446 | |
9447 | if (host_integerp (TREE_VALUE (link), 0)) | |
fc9e8a14 JJ |
9448 | { |
9449 | if (tree_int_cst_sgn (TREE_VALUE (link)) < 0) | |
9450 | add_AT_int (enum_die, DW_AT_const_value, | |
9451 | tree_low_cst (TREE_VALUE (link), 0)); | |
9452 | else | |
9453 | add_AT_unsigned (enum_die, DW_AT_const_value, | |
9454 | tree_low_cst (TREE_VALUE (link), 0)); | |
9455 | } | |
a3f97cbb JW |
9456 | } |
9457 | } | |
273dbe67 JM |
9458 | else |
9459 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a3f97cbb JW |
9460 | } |
9461 | ||
a3f97cbb JW |
9462 | /* Generate a DIE to represent either a real live formal parameter decl or to |
9463 | represent just the type of some formal parameter position in some function | |
9464 | type. | |
71dfc51f | 9465 | |
a3f97cbb JW |
9466 | Note that this routine is a bit unusual because its argument may be a |
9467 | ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which | |
9468 | represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE | |
9469 | node. If it's the former then this function is being called to output a | |
9470 | DIE to represent a formal parameter object (or some inlining thereof). If | |
9471 | it's the latter, then this function is only being called to output a | |
9472 | DW_TAG_formal_parameter DIE to stand as a placeholder for some formal | |
9473 | argument type of some subprogram type. */ | |
71dfc51f | 9474 | |
a94dbf2c | 9475 | static dw_die_ref |
a3f97cbb JW |
9476 | gen_formal_parameter_die (node, context_die) |
9477 | register tree node; | |
9478 | register dw_die_ref context_die; | |
9479 | { | |
71dfc51f RK |
9480 | register dw_die_ref parm_die |
9481 | = new_die (DW_TAG_formal_parameter, context_die); | |
a3f97cbb | 9482 | register tree origin; |
71dfc51f | 9483 | |
a3f97cbb JW |
9484 | switch (TREE_CODE_CLASS (TREE_CODE (node))) |
9485 | { | |
a3f97cbb JW |
9486 | case 'd': |
9487 | origin = decl_ultimate_origin (node); | |
9488 | if (origin != NULL) | |
a94dbf2c | 9489 | add_abstract_origin_attribute (parm_die, origin); |
a3f97cbb JW |
9490 | else |
9491 | { | |
9492 | add_name_and_src_coords_attributes (parm_die, node); | |
9493 | add_type_attribute (parm_die, TREE_TYPE (node), | |
9494 | TREE_READONLY (node), | |
9495 | TREE_THIS_VOLATILE (node), | |
9496 | context_die); | |
bdb669cb JM |
9497 | if (DECL_ARTIFICIAL (node)) |
9498 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb | 9499 | } |
71dfc51f | 9500 | |
141719a8 JM |
9501 | equate_decl_number_to_die (node, parm_die); |
9502 | if (! DECL_ABSTRACT (node)) | |
a94dbf2c | 9503 | add_location_or_const_value_attribute (parm_die, node); |
71dfc51f | 9504 | |
a3f97cbb JW |
9505 | break; |
9506 | ||
a3f97cbb | 9507 | case 't': |
71dfc51f | 9508 | /* We were called with some kind of a ..._TYPE node. */ |
a3f97cbb JW |
9509 | add_type_attribute (parm_die, node, 0, 0, context_die); |
9510 | break; | |
9511 | ||
a3f97cbb JW |
9512 | default: |
9513 | abort (); | |
9514 | } | |
71dfc51f | 9515 | |
a94dbf2c | 9516 | return parm_die; |
a3f97cbb JW |
9517 | } |
9518 | ||
9519 | /* Generate a special type of DIE used as a stand-in for a trailing ellipsis | |
9520 | at the end of an (ANSI prototyped) formal parameters list. */ | |
71dfc51f | 9521 | |
a3f97cbb JW |
9522 | static void |
9523 | gen_unspecified_parameters_die (decl_or_type, context_die) | |
2618f955 | 9524 | register tree decl_or_type ATTRIBUTE_UNUSED; |
a3f97cbb JW |
9525 | register dw_die_ref context_die; |
9526 | { | |
487a6e06 | 9527 | new_die (DW_TAG_unspecified_parameters, context_die); |
a3f97cbb JW |
9528 | } |
9529 | ||
9530 | /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a | |
9531 | DW_TAG_unspecified_parameters DIE) to represent the types of the formal | |
9532 | parameters as specified in some function type specification (except for | |
1cfdcc15 | 9533 | those which appear as part of a function *definition*). */ |
71dfc51f | 9534 | |
a3f97cbb JW |
9535 | static void |
9536 | gen_formal_types_die (function_or_method_type, context_die) | |
9537 | register tree function_or_method_type; | |
9538 | register dw_die_ref context_die; | |
9539 | { | |
9540 | register tree link; | |
9541 | register tree formal_type = NULL; | |
5daf7c0a JM |
9542 | register tree first_parm_type; |
9543 | tree arg; | |
a3f97cbb | 9544 | |
5daf7c0a JM |
9545 | if (TREE_CODE (function_or_method_type) == FUNCTION_DECL) |
9546 | { | |
9547 | arg = DECL_ARGUMENTS (function_or_method_type); | |
9548 | function_or_method_type = TREE_TYPE (function_or_method_type); | |
9549 | } | |
9550 | else | |
9551 | arg = NULL_TREE; | |
9552 | ||
9553 | first_parm_type = TYPE_ARG_TYPES (function_or_method_type); | |
a3f97cbb | 9554 | |
556273e0 | 9555 | /* Make our first pass over the list of formal parameter types and output a |
a3f97cbb | 9556 | DW_TAG_formal_parameter DIE for each one. */ |
5daf7c0a | 9557 | for (link = first_parm_type; link; ) |
a3f97cbb | 9558 | { |
a94dbf2c | 9559 | register dw_die_ref parm_die; |
556273e0 | 9560 | |
a3f97cbb JW |
9561 | formal_type = TREE_VALUE (link); |
9562 | if (formal_type == void_type_node) | |
9563 | break; | |
9564 | ||
9565 | /* Output a (nameless) DIE to represent the formal parameter itself. */ | |
a94dbf2c | 9566 | parm_die = gen_formal_parameter_die (formal_type, context_die); |
5daf7c0a JM |
9567 | if ((TREE_CODE (function_or_method_type) == METHOD_TYPE |
9568 | && link == first_parm_type) | |
9569 | || (arg && DECL_ARTIFICIAL (arg))) | |
a94dbf2c | 9570 | add_AT_flag (parm_die, DW_AT_artificial, 1); |
5daf7c0a JM |
9571 | |
9572 | link = TREE_CHAIN (link); | |
9573 | if (arg) | |
9574 | arg = TREE_CHAIN (arg); | |
a3f97cbb JW |
9575 | } |
9576 | ||
9577 | /* If this function type has an ellipsis, add a | |
9578 | DW_TAG_unspecified_parameters DIE to the end of the parameter list. */ | |
9579 | if (formal_type != void_type_node) | |
9580 | gen_unspecified_parameters_die (function_or_method_type, context_die); | |
9581 | ||
556273e0 | 9582 | /* Make our second (and final) pass over the list of formal parameter types |
a3f97cbb JW |
9583 | and output DIEs to represent those types (as necessary). */ |
9584 | for (link = TYPE_ARG_TYPES (function_or_method_type); | |
9585 | link; | |
9586 | link = TREE_CHAIN (link)) | |
9587 | { | |
9588 | formal_type = TREE_VALUE (link); | |
9589 | if (formal_type == void_type_node) | |
9590 | break; | |
9591 | ||
b50c02f9 | 9592 | gen_type_die (formal_type, context_die); |
a3f97cbb JW |
9593 | } |
9594 | } | |
9595 | ||
10a11b75 JM |
9596 | /* We want to generate the DIE for TYPE so that we can generate the |
9597 | die for MEMBER, which has been defined; we will need to refer back | |
9598 | to the member declaration nested within TYPE. If we're trying to | |
9599 | generate minimal debug info for TYPE, processing TYPE won't do the | |
9600 | trick; we need to attach the member declaration by hand. */ | |
9601 | ||
9602 | static void | |
9603 | gen_type_die_for_member (type, member, context_die) | |
9604 | tree type, member; | |
9605 | dw_die_ref context_die; | |
9606 | { | |
9607 | gen_type_die (type, context_die); | |
9608 | ||
9609 | /* If we're trying to avoid duplicate debug info, we may not have | |
9610 | emitted the member decl for this function. Emit it now. */ | |
9611 | if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)) | |
9612 | && ! lookup_decl_die (member)) | |
9613 | { | |
9614 | if (decl_ultimate_origin (member)) | |
9615 | abort (); | |
9616 | ||
9617 | push_decl_scope (type); | |
9618 | if (TREE_CODE (member) == FUNCTION_DECL) | |
9619 | gen_subprogram_die (member, lookup_type_die (type)); | |
9620 | else | |
9621 | gen_variable_die (member, lookup_type_die (type)); | |
9622 | pop_decl_scope (); | |
9623 | } | |
9624 | } | |
9625 | ||
9626 | /* Generate the DWARF2 info for the "abstract" instance | |
9627 | of a function which we may later generate inlined and/or | |
9628 | out-of-line instances of. */ | |
9629 | ||
e1772ac0 | 9630 | static void |
1edf43d6 | 9631 | dwarf2out_abstract_function (decl) |
10a11b75 JM |
9632 | tree decl; |
9633 | { | |
5daf7c0a | 9634 | register dw_die_ref old_die; |
777ad4c2 | 9635 | tree save_fn; |
5daf7c0a JM |
9636 | tree context; |
9637 | int was_abstract = DECL_ABSTRACT (decl); | |
9638 | ||
9639 | /* Make sure we have the actual abstract inline, not a clone. */ | |
9640 | decl = DECL_ORIGIN (decl); | |
10a11b75 | 9641 | |
5daf7c0a | 9642 | old_die = lookup_decl_die (decl); |
10a11b75 JM |
9643 | if (old_die && get_AT_unsigned (old_die, DW_AT_inline)) |
9644 | /* We've already generated the abstract instance. */ | |
9645 | return; | |
9646 | ||
5daf7c0a JM |
9647 | /* Be sure we've emitted the in-class declaration DIE (if any) first, so |
9648 | we don't get confused by DECL_ABSTRACT. */ | |
8458e954 JS |
9649 | if (debug_info_level > DINFO_LEVEL_TERSE) |
9650 | { | |
9651 | context = decl_class_context (decl); | |
9652 | if (context) | |
9653 | gen_type_die_for_member | |
9654 | (context, decl, decl_function_context (decl) ? NULL : comp_unit_die); | |
9655 | } | |
5daf7c0a JM |
9656 | |
9657 | /* Pretend we've just finished compiling this function. */ | |
777ad4c2 JM |
9658 | save_fn = current_function_decl; |
9659 | current_function_decl = decl; | |
9660 | ||
10a11b75 JM |
9661 | set_decl_abstract_flags (decl, 1); |
9662 | dwarf2out_decl (decl); | |
5daf7c0a JM |
9663 | if (! was_abstract) |
9664 | set_decl_abstract_flags (decl, 0); | |
777ad4c2 JM |
9665 | |
9666 | current_function_decl = save_fn; | |
10a11b75 JM |
9667 | } |
9668 | ||
a3f97cbb JW |
9669 | /* Generate a DIE to represent a declared function (either file-scope or |
9670 | block-local). */ | |
71dfc51f | 9671 | |
a3f97cbb JW |
9672 | static void |
9673 | gen_subprogram_die (decl, context_die) | |
9674 | register tree decl; | |
9675 | register dw_die_ref context_die; | |
9676 | { | |
9677 | char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; | |
9678 | register tree origin = decl_ultimate_origin (decl); | |
4b674448 | 9679 | register dw_die_ref subr_die; |
b1ccbc24 | 9680 | register rtx fp_reg; |
a3f97cbb JW |
9681 | register tree fn_arg_types; |
9682 | register tree outer_scope; | |
a94dbf2c | 9683 | register dw_die_ref old_die = lookup_decl_die (decl); |
9765e357 JM |
9684 | register int declaration = (current_function_decl != decl |
9685 | || class_scope_p (context_die)); | |
a3f97cbb | 9686 | |
10a11b75 JM |
9687 | /* Note that it is possible to have both DECL_ABSTRACT and `declaration' |
9688 | be true, if we started to generate the abstract instance of an inline, | |
9689 | decided to output its containing class, and proceeded to emit the | |
9690 | declaration of the inline from the member list for the class. In that | |
9691 | case, `declaration' takes priority; we'll get back to the abstract | |
9692 | instance when we're done with the class. */ | |
9693 | ||
1cfdcc15 JM |
9694 | /* The class-scope declaration DIE must be the primary DIE. */ |
9695 | if (origin && declaration && class_scope_p (context_die)) | |
9696 | { | |
9697 | origin = NULL; | |
9698 | if (old_die) | |
9699 | abort (); | |
9700 | } | |
9701 | ||
a3f97cbb JW |
9702 | if (origin != NULL) |
9703 | { | |
777ad4c2 | 9704 | if (declaration && ! local_scope_p (context_die)) |
10a11b75 JM |
9705 | abort (); |
9706 | ||
8d8238b6 JM |
9707 | /* Fixup die_parent for the abstract instance of a nested |
9708 | inline function. */ | |
9709 | if (old_die && old_die->die_parent == NULL) | |
9710 | add_child_die (context_die, old_die); | |
9711 | ||
4b674448 | 9712 | subr_die = new_die (DW_TAG_subprogram, context_die); |
a3f97cbb JW |
9713 | add_abstract_origin_attribute (subr_die, origin); |
9714 | } | |
bdb669cb JM |
9715 | else if (old_die) |
9716 | { | |
981975b6 | 9717 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
a94dbf2c | 9718 | |
1edf43d6 JM |
9719 | if (!get_AT_flag (old_die, DW_AT_declaration) |
9720 | /* We can have a normal definition following an inline one in the | |
9721 | case of redefinition of GNU C extern inlines. | |
9722 | It seems reasonable to use AT_specification in this case. */ | |
9723 | && !get_AT_unsigned (old_die, DW_AT_inline)) | |
b75ab88b NC |
9724 | { |
9725 | /* ??? This can happen if there is a bug in the program, for | |
9726 | instance, if it has duplicate function definitions. Ideally, | |
9727 | we should detect this case and ignore it. For now, if we have | |
9728 | already reported an error, any error at all, then assume that | |
9729 | we got here because of a input error, not a dwarf2 bug. */ | |
b75ab88b NC |
9730 | if (errorcount) |
9731 | return; | |
9732 | abort (); | |
9733 | } | |
4b674448 JM |
9734 | |
9735 | /* If the definition comes from the same place as the declaration, | |
a94dbf2c JM |
9736 | maybe use the old DIE. We always want the DIE for this function |
9737 | that has the *_pc attributes to be under comp_unit_die so the | |
cb9e9d8d JM |
9738 | debugger can find it. We also need to do this for abstract |
9739 | instances of inlines, since the spec requires the out-of-line copy | |
9740 | to have the same parent. For local class methods, this doesn't | |
9741 | apply; we just use the old DIE. */ | |
9742 | if ((old_die->die_parent == comp_unit_die || context_die == NULL) | |
a96c67ec JM |
9743 | && (DECL_ARTIFICIAL (decl) |
9744 | || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index | |
9745 | && (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 9746 | == (unsigned) DECL_SOURCE_LINE (decl))))) |
bdb669cb | 9747 | { |
4b674448 JM |
9748 | subr_die = old_die; |
9749 | ||
9750 | /* Clear out the declaration attribute and the parm types. */ | |
9751 | remove_AT (subr_die, DW_AT_declaration); | |
9752 | remove_children (subr_die); | |
9753 | } | |
9754 | else | |
9755 | { | |
9756 | subr_die = new_die (DW_TAG_subprogram, context_die); | |
9757 | add_AT_die_ref (subr_die, DW_AT_specification, old_die); | |
bdb669cb JM |
9758 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
9759 | add_AT_unsigned (subr_die, DW_AT_decl_file, file_index); | |
9760 | if (get_AT_unsigned (old_die, DW_AT_decl_line) | |
556273e0 | 9761 | != (unsigned) DECL_SOURCE_LINE (decl)) |
bdb669cb JM |
9762 | add_AT_unsigned |
9763 | (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
9764 | } | |
9765 | } | |
a3f97cbb JW |
9766 | else |
9767 | { | |
777ad4c2 | 9768 | subr_die = new_die (DW_TAG_subprogram, context_die); |
556273e0 | 9769 | |
273dbe67 JM |
9770 | if (TREE_PUBLIC (decl)) |
9771 | add_AT_flag (subr_die, DW_AT_external, 1); | |
71dfc51f | 9772 | |
a3f97cbb | 9773 | add_name_and_src_coords_attributes (subr_die, decl); |
4927276d JM |
9774 | if (debug_info_level > DINFO_LEVEL_TERSE) |
9775 | { | |
9776 | register tree type = TREE_TYPE (decl); | |
71dfc51f | 9777 | |
4927276d JM |
9778 | add_prototyped_attribute (subr_die, type); |
9779 | add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die); | |
9780 | } | |
71dfc51f | 9781 | |
a3f97cbb | 9782 | add_pure_or_virtual_attribute (subr_die, decl); |
273dbe67 JM |
9783 | if (DECL_ARTIFICIAL (decl)) |
9784 | add_AT_flag (subr_die, DW_AT_artificial, 1); | |
a94dbf2c JM |
9785 | if (TREE_PROTECTED (decl)) |
9786 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected); | |
9787 | else if (TREE_PRIVATE (decl)) | |
9788 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 9789 | } |
4edb7b60 | 9790 | |
a94dbf2c JM |
9791 | if (declaration) |
9792 | { | |
1edf43d6 JM |
9793 | if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline))) |
9794 | { | |
9795 | add_AT_flag (subr_die, DW_AT_declaration, 1); | |
9796 | ||
9797 | /* The first time we see a member function, it is in the context of | |
9798 | the class to which it belongs. We make sure of this by emitting | |
9799 | the class first. The next time is the definition, which is | |
9800 | handled above. The two may come from the same source text. */ | |
9801 | if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl)) | |
9802 | equate_decl_number_to_die (decl, subr_die); | |
9803 | } | |
a94dbf2c JM |
9804 | } |
9805 | else if (DECL_ABSTRACT (decl)) | |
a3f97cbb | 9806 | { |
10a11b75 | 9807 | if (DECL_INLINE (decl) && !flag_no_inline) |
61b32c02 | 9808 | { |
10a11b75 JM |
9809 | /* ??? Checking DECL_DEFER_OUTPUT is correct for static |
9810 | inline functions, but not for extern inline functions. | |
9811 | We can't get this completely correct because information | |
9812 | about whether the function was declared inline is not | |
9813 | saved anywhere. */ | |
9814 | if (DECL_DEFER_OUTPUT (decl)) | |
61b32c02 JM |
9815 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined); |
9816 | else | |
10a11b75 | 9817 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined); |
61b32c02 | 9818 | } |
61b32c02 | 9819 | else |
10a11b75 | 9820 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined); |
61b32c02 | 9821 | |
a3f97cbb JW |
9822 | equate_decl_number_to_die (decl, subr_die); |
9823 | } | |
9824 | else if (!DECL_EXTERNAL (decl)) | |
9825 | { | |
1edf43d6 | 9826 | if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline))) |
ba7b35df | 9827 | equate_decl_number_to_die (decl, subr_die); |
71dfc51f | 9828 | |
5c90448c JM |
9829 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL, |
9830 | current_funcdef_number); | |
7d4440be | 9831 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id); |
5c90448c JM |
9832 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, |
9833 | current_funcdef_number); | |
a3f97cbb JW |
9834 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id); |
9835 | ||
d291dd49 JM |
9836 | add_pubname (decl, subr_die); |
9837 | add_arange (decl, subr_die); | |
9838 | ||
a3f97cbb | 9839 | #ifdef MIPS_DEBUGGING_INFO |
a3f97cbb JW |
9840 | /* Add a reference to the FDE for this routine. */ |
9841 | add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde); | |
9842 | #endif | |
9843 | ||
810429b7 JM |
9844 | /* Define the "frame base" location for this routine. We use the |
9845 | frame pointer or stack pointer registers, since the RTL for local | |
9846 | variables is relative to one of them. */ | |
b1ccbc24 RK |
9847 | fp_reg |
9848 | = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx; | |
9849 | add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg)); | |
a3f97cbb | 9850 | |
ef76d03b JW |
9851 | #if 0 |
9852 | /* ??? This fails for nested inline functions, because context_display | |
9853 | is not part of the state saved/restored for inline functions. */ | |
88dad228 | 9854 | if (current_function_needs_context) |
ef76d03b JW |
9855 | add_AT_location_description (subr_die, DW_AT_static_link, |
9856 | lookup_static_chain (decl)); | |
9857 | #endif | |
a3f97cbb JW |
9858 | } |
9859 | ||
9860 | /* Now output descriptions of the arguments for this function. This gets | |
556273e0 | 9861 | (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list |
a3f97cbb JW |
9862 | for a FUNCTION_DECL doesn't indicate cases where there was a trailing |
9863 | `...' at the end of the formal parameter list. In order to find out if | |
9864 | there was a trailing ellipsis or not, we must instead look at the type | |
9865 | associated with the FUNCTION_DECL. This will be a node of type | |
9866 | FUNCTION_TYPE. If the chain of type nodes hanging off of this | |
556273e0 | 9867 | FUNCTION_TYPE node ends with a void_type_node then there should *not* be |
a3f97cbb | 9868 | an ellipsis at the end. */ |
71dfc51f | 9869 | |
a3f97cbb | 9870 | /* In the case where we are describing a mere function declaration, all we |
556273e0 | 9871 | need to do here (and all we *can* do here) is to describe the *types* of |
a3f97cbb | 9872 | its formal parameters. */ |
4927276d | 9873 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 9874 | ; |
4edb7b60 | 9875 | else if (declaration) |
5daf7c0a | 9876 | gen_formal_types_die (decl, subr_die); |
a3f97cbb JW |
9877 | else |
9878 | { | |
9879 | /* Generate DIEs to represent all known formal parameters */ | |
9880 | register tree arg_decls = DECL_ARGUMENTS (decl); | |
9881 | register tree parm; | |
9882 | ||
9883 | /* When generating DIEs, generate the unspecified_parameters DIE | |
9884 | instead if we come across the arg "__builtin_va_alist" */ | |
9885 | for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) | |
71dfc51f RK |
9886 | if (TREE_CODE (parm) == PARM_DECL) |
9887 | { | |
db3cf6fb MS |
9888 | if (DECL_NAME (parm) |
9889 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), | |
9890 | "__builtin_va_alist")) | |
71dfc51f RK |
9891 | gen_unspecified_parameters_die (parm, subr_die); |
9892 | else | |
9893 | gen_decl_die (parm, subr_die); | |
9894 | } | |
a3f97cbb JW |
9895 | |
9896 | /* Decide whether we need a unspecified_parameters DIE at the end. | |
556273e0 | 9897 | There are 2 more cases to do this for: 1) the ansi ... declaration - |
a3f97cbb JW |
9898 | this is detectable when the end of the arg list is not a |
9899 | void_type_node 2) an unprototyped function declaration (not a | |
9900 | definition). This just means that we have no info about the | |
9901 | parameters at all. */ | |
9902 | fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
71dfc51f | 9903 | if (fn_arg_types != NULL) |
a3f97cbb JW |
9904 | { |
9905 | /* this is the prototyped case, check for ... */ | |
9906 | if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) | |
71dfc51f | 9907 | gen_unspecified_parameters_die (decl, subr_die); |
a3f97cbb | 9908 | } |
71dfc51f RK |
9909 | else if (DECL_INITIAL (decl) == NULL_TREE) |
9910 | gen_unspecified_parameters_die (decl, subr_die); | |
a3f97cbb JW |
9911 | } |
9912 | ||
9913 | /* Output Dwarf info for all of the stuff within the body of the function | |
9914 | (if it has one - it may be just a declaration). */ | |
9915 | outer_scope = DECL_INITIAL (decl); | |
9916 | ||
d7248bff JM |
9917 | /* Note that here, `outer_scope' is a pointer to the outermost BLOCK |
9918 | node created to represent a function. This outermost BLOCK actually | |
9919 | represents the outermost binding contour for the function, i.e. the | |
9920 | contour in which the function's formal parameters and labels get | |
9921 | declared. Curiously, it appears that the front end doesn't actually | |
9922 | put the PARM_DECL nodes for the current function onto the BLOCK_VARS | |
9923 | list for this outer scope. (They are strung off of the DECL_ARGUMENTS | |
9924 | list for the function instead.) The BLOCK_VARS list for the | |
9925 | `outer_scope' does provide us with a list of the LABEL_DECL nodes for | |
9926 | the function however, and we output DWARF info for those in | |
9927 | decls_for_scope. Just within the `outer_scope' there will be a BLOCK | |
9928 | node representing the function's outermost pair of curly braces, and | |
9929 | any blocks used for the base and member initializers of a C++ | |
9930 | constructor function. */ | |
4edb7b60 | 9931 | if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK) |
7e23cb16 JM |
9932 | { |
9933 | current_function_has_inlines = 0; | |
9934 | decls_for_scope (outer_scope, subr_die, 0); | |
71dfc51f | 9935 | |
ce61cc73 | 9936 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
7e23cb16 JM |
9937 | if (current_function_has_inlines) |
9938 | { | |
9939 | add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1); | |
9940 | if (! comp_unit_has_inlines) | |
9941 | { | |
9942 | add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1); | |
9943 | comp_unit_has_inlines = 1; | |
9944 | } | |
9945 | } | |
9946 | #endif | |
9947 | } | |
a3f97cbb JW |
9948 | } |
9949 | ||
9950 | /* Generate a DIE to represent a declared data object. */ | |
71dfc51f | 9951 | |
a3f97cbb JW |
9952 | static void |
9953 | gen_variable_die (decl, context_die) | |
9954 | register tree decl; | |
9955 | register dw_die_ref context_die; | |
9956 | { | |
9957 | register tree origin = decl_ultimate_origin (decl); | |
9958 | register dw_die_ref var_die = new_die (DW_TAG_variable, context_die); | |
71dfc51f | 9959 | |
bdb669cb | 9960 | dw_die_ref old_die = lookup_decl_die (decl); |
9765e357 JM |
9961 | int declaration = (DECL_EXTERNAL (decl) |
9962 | || class_scope_p (context_die)); | |
4edb7b60 | 9963 | |
a3f97cbb | 9964 | if (origin != NULL) |
71dfc51f | 9965 | add_abstract_origin_attribute (var_die, origin); |
f76b8156 JW |
9966 | /* Loop unrolling can create multiple blocks that refer to the same |
9967 | static variable, so we must test for the DW_AT_declaration flag. */ | |
9968 | /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to | |
9969 | copy decls and set the DECL_ABSTRACT flag on them instead of | |
9970 | sharing them. */ | |
9971 | else if (old_die && TREE_STATIC (decl) | |
9972 | && get_AT_flag (old_die, DW_AT_declaration) == 1) | |
bdb669cb | 9973 | { |
e689ae67 | 9974 | /* This is a definition of a C++ class level static. */ |
bdb669cb JM |
9975 | add_AT_die_ref (var_die, DW_AT_specification, old_die); |
9976 | if (DECL_NAME (decl)) | |
9977 | { | |
981975b6 | 9978 | unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); |
71dfc51f | 9979 | |
bdb669cb JM |
9980 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
9981 | add_AT_unsigned (var_die, DW_AT_decl_file, file_index); | |
71dfc51f | 9982 | |
bdb669cb | 9983 | if (get_AT_unsigned (old_die, DW_AT_decl_line) |
556273e0 | 9984 | != (unsigned) DECL_SOURCE_LINE (decl)) |
71dfc51f RK |
9985 | |
9986 | add_AT_unsigned (var_die, DW_AT_decl_line, | |
9987 | DECL_SOURCE_LINE (decl)); | |
bdb669cb JM |
9988 | } |
9989 | } | |
a3f97cbb JW |
9990 | else |
9991 | { | |
9992 | add_name_and_src_coords_attributes (var_die, decl); | |
a3f97cbb JW |
9993 | add_type_attribute (var_die, TREE_TYPE (decl), |
9994 | TREE_READONLY (decl), | |
9995 | TREE_THIS_VOLATILE (decl), context_die); | |
71dfc51f | 9996 | |
273dbe67 JM |
9997 | if (TREE_PUBLIC (decl)) |
9998 | add_AT_flag (var_die, DW_AT_external, 1); | |
71dfc51f | 9999 | |
273dbe67 JM |
10000 | if (DECL_ARTIFICIAL (decl)) |
10001 | add_AT_flag (var_die, DW_AT_artificial, 1); | |
71dfc51f | 10002 | |
a94dbf2c JM |
10003 | if (TREE_PROTECTED (decl)) |
10004 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected); | |
71dfc51f | 10005 | |
a94dbf2c JM |
10006 | else if (TREE_PRIVATE (decl)) |
10007 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 10008 | } |
4edb7b60 JM |
10009 | |
10010 | if (declaration) | |
10011 | add_AT_flag (var_die, DW_AT_declaration, 1); | |
556273e0 | 10012 | |
9765e357 | 10013 | if (class_scope_p (context_die) || DECL_ABSTRACT (decl)) |
4edb7b60 JM |
10014 | equate_decl_number_to_die (decl, var_die); |
10015 | ||
10016 | if (! declaration && ! DECL_ABSTRACT (decl)) | |
a3f97cbb JW |
10017 | { |
10018 | add_location_or_const_value_attribute (var_die, decl); | |
d291dd49 | 10019 | add_pubname (decl, var_die); |
a3f97cbb | 10020 | } |
1bfb5f8f JM |
10021 | else |
10022 | tree_add_const_value_attribute (var_die, decl); | |
a3f97cbb JW |
10023 | } |
10024 | ||
10025 | /* Generate a DIE to represent a label identifier. */ | |
71dfc51f | 10026 | |
a3f97cbb JW |
10027 | static void |
10028 | gen_label_die (decl, context_die) | |
10029 | register tree decl; | |
10030 | register dw_die_ref context_die; | |
10031 | { | |
10032 | register tree origin = decl_ultimate_origin (decl); | |
10033 | register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die); | |
10034 | register rtx insn; | |
10035 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
71dfc51f | 10036 | |
a3f97cbb | 10037 | if (origin != NULL) |
71dfc51f | 10038 | add_abstract_origin_attribute (lbl_die, origin); |
a3f97cbb | 10039 | else |
71dfc51f RK |
10040 | add_name_and_src_coords_attributes (lbl_die, decl); |
10041 | ||
a3f97cbb | 10042 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 10043 | equate_decl_number_to_die (decl, lbl_die); |
a3f97cbb JW |
10044 | else |
10045 | { | |
10046 | insn = DECL_RTL (decl); | |
088e7160 NC |
10047 | |
10048 | /* Deleted labels are programmer specified labels which have been | |
10049 | eliminated because of various optimisations. We still emit them | |
10050 | here so that it is possible to put breakpoints on them. */ | |
10051 | if (GET_CODE (insn) == CODE_LABEL | |
10052 | || ((GET_CODE (insn) == NOTE | |
10053 | && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))) | |
a3f97cbb | 10054 | { |
556273e0 KH |
10055 | /* When optimization is enabled (via -O) some parts of the compiler |
10056 | (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which | |
a3f97cbb JW |
10057 | represent source-level labels which were explicitly declared by |
10058 | the user. This really shouldn't be happening though, so catch | |
10059 | it if it ever does happen. */ | |
10060 | if (INSN_DELETED_P (insn)) | |
71dfc51f RK |
10061 | abort (); |
10062 | ||
66234570 | 10063 | ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn)); |
a3f97cbb JW |
10064 | add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); |
10065 | } | |
10066 | } | |
10067 | } | |
10068 | ||
10069 | /* Generate a DIE for a lexical block. */ | |
71dfc51f | 10070 | |
a3f97cbb | 10071 | static void |
d7248bff | 10072 | gen_lexical_block_die (stmt, context_die, depth) |
a3f97cbb JW |
10073 | register tree stmt; |
10074 | register dw_die_ref context_die; | |
d7248bff | 10075 | int depth; |
a3f97cbb JW |
10076 | { |
10077 | register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die); | |
10078 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
71dfc51f RK |
10079 | |
10080 | if (! BLOCK_ABSTRACT (stmt)) | |
a3f97cbb | 10081 | { |
5c90448c | 10082 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
18c038b9 | 10083 | BLOCK_NUMBER (stmt)); |
a3f97cbb | 10084 | add_AT_lbl_id (stmt_die, DW_AT_low_pc, label); |
18c038b9 MM |
10085 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, |
10086 | BLOCK_NUMBER (stmt)); | |
a3f97cbb JW |
10087 | add_AT_lbl_id (stmt_die, DW_AT_high_pc, label); |
10088 | } | |
71dfc51f | 10089 | |
d7248bff | 10090 | decls_for_scope (stmt, stmt_die, depth); |
a3f97cbb JW |
10091 | } |
10092 | ||
10093 | /* Generate a DIE for an inlined subprogram. */ | |
71dfc51f | 10094 | |
a3f97cbb | 10095 | static void |
d7248bff | 10096 | gen_inlined_subroutine_die (stmt, context_die, depth) |
a3f97cbb JW |
10097 | register tree stmt; |
10098 | register dw_die_ref context_die; | |
d7248bff | 10099 | int depth; |
a3f97cbb | 10100 | { |
71dfc51f | 10101 | if (! BLOCK_ABSTRACT (stmt)) |
a3f97cbb | 10102 | { |
71dfc51f RK |
10103 | register dw_die_ref subr_die |
10104 | = new_die (DW_TAG_inlined_subroutine, context_die); | |
ab72d377 | 10105 | register tree decl = block_ultimate_origin (stmt); |
d7248bff | 10106 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 10107 | |
10a11b75 | 10108 | /* Emit info for the abstract instance first, if we haven't yet. */ |
1edf43d6 | 10109 | dwarf2out_abstract_function (decl); |
10a11b75 | 10110 | |
ab72d377 | 10111 | add_abstract_origin_attribute (subr_die, decl); |
5c90448c | 10112 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
18c038b9 | 10113 | BLOCK_NUMBER (stmt)); |
a3f97cbb | 10114 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label); |
18c038b9 MM |
10115 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, |
10116 | BLOCK_NUMBER (stmt)); | |
a3f97cbb | 10117 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label); |
d7248bff | 10118 | decls_for_scope (stmt, subr_die, depth); |
7e23cb16 | 10119 | current_function_has_inlines = 1; |
a3f97cbb | 10120 | } |
a3f97cbb JW |
10121 | } |
10122 | ||
10123 | /* Generate a DIE for a field in a record, or structure. */ | |
71dfc51f | 10124 | |
a3f97cbb JW |
10125 | static void |
10126 | gen_field_die (decl, context_die) | |
10127 | register tree decl; | |
10128 | register dw_die_ref context_die; | |
10129 | { | |
10130 | register dw_die_ref decl_die = new_die (DW_TAG_member, context_die); | |
71dfc51f | 10131 | |
a3f97cbb | 10132 | add_name_and_src_coords_attributes (decl_die, decl); |
a3f97cbb JW |
10133 | add_type_attribute (decl_die, member_declared_type (decl), |
10134 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl), | |
10135 | context_die); | |
71dfc51f | 10136 | |
a3f97cbb JW |
10137 | /* If this is a bit field... */ |
10138 | if (DECL_BIT_FIELD_TYPE (decl)) | |
10139 | { | |
10140 | add_byte_size_attribute (decl_die, decl); | |
10141 | add_bit_size_attribute (decl_die, decl); | |
10142 | add_bit_offset_attribute (decl_die, decl); | |
10143 | } | |
71dfc51f | 10144 | |
a94dbf2c JM |
10145 | if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE) |
10146 | add_data_member_location_attribute (decl_die, decl); | |
71dfc51f | 10147 | |
273dbe67 JM |
10148 | if (DECL_ARTIFICIAL (decl)) |
10149 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
71dfc51f | 10150 | |
a94dbf2c JM |
10151 | if (TREE_PROTECTED (decl)) |
10152 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected); | |
71dfc51f | 10153 | |
a94dbf2c JM |
10154 | else if (TREE_PRIVATE (decl)) |
10155 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb JW |
10156 | } |
10157 | ||
ab72d377 JM |
10158 | #if 0 |
10159 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. | |
10160 | Use modified_type_die instead. | |
a3f97cbb JW |
10161 | We keep this code here just in case these types of DIEs may be needed to |
10162 | represent certain things in other languages (e.g. Pascal) someday. */ | |
10163 | static void | |
10164 | gen_pointer_type_die (type, context_die) | |
10165 | register tree type; | |
10166 | register dw_die_ref context_die; | |
10167 | { | |
71dfc51f RK |
10168 | register dw_die_ref ptr_die |
10169 | = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die)); | |
10170 | ||
a3f97cbb | 10171 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 10172 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 10173 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb JW |
10174 | } |
10175 | ||
ab72d377 JM |
10176 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. |
10177 | Use modified_type_die instead. | |
a3f97cbb JW |
10178 | We keep this code here just in case these types of DIEs may be needed to |
10179 | represent certain things in other languages (e.g. Pascal) someday. */ | |
10180 | static void | |
10181 | gen_reference_type_die (type, context_die) | |
10182 | register tree type; | |
10183 | register dw_die_ref context_die; | |
10184 | { | |
71dfc51f RK |
10185 | register dw_die_ref ref_die |
10186 | = new_die (DW_TAG_reference_type, scope_die_for (type, context_die)); | |
10187 | ||
a3f97cbb | 10188 | equate_type_number_to_die (type, ref_die); |
a3f97cbb | 10189 | add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 10190 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb | 10191 | } |
ab72d377 | 10192 | #endif |
a3f97cbb JW |
10193 | |
10194 | /* Generate a DIE for a pointer to a member type. */ | |
10195 | static void | |
10196 | gen_ptr_to_mbr_type_die (type, context_die) | |
10197 | register tree type; | |
10198 | register dw_die_ref context_die; | |
10199 | { | |
71dfc51f RK |
10200 | register dw_die_ref ptr_die |
10201 | = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die)); | |
10202 | ||
a3f97cbb | 10203 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 10204 | add_AT_die_ref (ptr_die, DW_AT_containing_type, |
bdb669cb | 10205 | lookup_type_die (TYPE_OFFSET_BASETYPE (type))); |
a3f97cbb JW |
10206 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
10207 | } | |
10208 | ||
10209 | /* Generate the DIE for the compilation unit. */ | |
71dfc51f | 10210 | |
a96c67ec JM |
10211 | static dw_die_ref |
10212 | gen_compile_unit_die (filename) | |
10213 | register const char *filename; | |
a3f97cbb | 10214 | { |
a96c67ec | 10215 | register dw_die_ref die; |
a3f97cbb | 10216 | char producer[250]; |
d3e3972c | 10217 | const char *wd = getpwd (); |
a96c67ec | 10218 | int language; |
a3f97cbb | 10219 | |
a96c67ec JM |
10220 | die = new_die (DW_TAG_compile_unit, NULL); |
10221 | add_name_attribute (die, filename); | |
bdb669cb | 10222 | |
a96c67ec JM |
10223 | if (wd != NULL && filename[0] != DIR_SEPARATOR) |
10224 | add_AT_string (die, DW_AT_comp_dir, wd); | |
a3f97cbb JW |
10225 | |
10226 | sprintf (producer, "%s %s", language_string, version_string); | |
10227 | ||
10228 | #ifdef MIPS_DEBUGGING_INFO | |
10229 | /* The MIPS/SGI compilers place the 'cc' command line options in the producer | |
10230 | string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do | |
10231 | not appear in the producer string, the debugger reaches the conclusion | |
10232 | that the object file is stripped and has no debugging information. | |
10233 | To get the MIPS/SGI debugger to believe that there is debugging | |
10234 | information in the object file, we add a -g to the producer string. */ | |
4927276d JM |
10235 | if (debug_info_level > DINFO_LEVEL_TERSE) |
10236 | strcat (producer, " -g"); | |
a3f97cbb JW |
10237 | #endif |
10238 | ||
a96c67ec | 10239 | add_AT_string (die, DW_AT_producer, producer); |
a9d38797 | 10240 | |
a3f97cbb | 10241 | if (strcmp (language_string, "GNU C++") == 0) |
a96c67ec | 10242 | language = DW_LANG_C_plus_plus; |
a3f97cbb | 10243 | else if (strcmp (language_string, "GNU Ada") == 0) |
a96c67ec | 10244 | language = DW_LANG_Ada83; |
a9d38797 | 10245 | else if (strcmp (language_string, "GNU F77") == 0) |
a96c67ec | 10246 | language = DW_LANG_Fortran77; |
bc28c45b | 10247 | else if (strcmp (language_string, "GNU Pascal") == 0) |
a96c67ec | 10248 | language = DW_LANG_Pascal83; |
28985b81 AG |
10249 | else if (strcmp (language_string, "GNU Java") == 0) |
10250 | language = DW_LANG_Java; | |
a3f97cbb | 10251 | else if (flag_traditional) |
a96c67ec | 10252 | language = DW_LANG_C; |
a3f97cbb | 10253 | else |
a96c67ec | 10254 | language = DW_LANG_C89; |
a9d38797 | 10255 | |
a96c67ec JM |
10256 | add_AT_unsigned (die, DW_AT_language, language); |
10257 | ||
10258 | return die; | |
a3f97cbb JW |
10259 | } |
10260 | ||
10261 | /* Generate a DIE for a string type. */ | |
71dfc51f | 10262 | |
a3f97cbb JW |
10263 | static void |
10264 | gen_string_type_die (type, context_die) | |
10265 | register tree type; | |
10266 | register dw_die_ref context_die; | |
10267 | { | |
71dfc51f RK |
10268 | register dw_die_ref type_die |
10269 | = new_die (DW_TAG_string_type, scope_die_for (type, context_die)); | |
10270 | ||
bdb669cb | 10271 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
10272 | |
10273 | /* Fudge the string length attribute for now. */ | |
556273e0 | 10274 | |
a3f97cbb | 10275 | /* TODO: add string length info. |
71dfc51f | 10276 | string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type))); |
a3f97cbb JW |
10277 | bound_representation (upper_bound, 0, 'u'); */ |
10278 | } | |
10279 | ||
61b32c02 | 10280 | /* Generate the DIE for a base class. */ |
71dfc51f | 10281 | |
61b32c02 JM |
10282 | static void |
10283 | gen_inheritance_die (binfo, context_die) | |
10284 | register tree binfo; | |
10285 | register dw_die_ref context_die; | |
10286 | { | |
10287 | dw_die_ref die = new_die (DW_TAG_inheritance, context_die); | |
71dfc51f | 10288 | |
61b32c02 JM |
10289 | add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die); |
10290 | add_data_member_location_attribute (die, binfo); | |
71dfc51f | 10291 | |
61b32c02 JM |
10292 | if (TREE_VIA_VIRTUAL (binfo)) |
10293 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); | |
10294 | if (TREE_VIA_PUBLIC (binfo)) | |
10295 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public); | |
10296 | else if (TREE_VIA_PROTECTED (binfo)) | |
10297 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected); | |
10298 | } | |
10299 | ||
956d6950 | 10300 | /* Generate a DIE for a class member. */ |
71dfc51f | 10301 | |
a3f97cbb JW |
10302 | static void |
10303 | gen_member_die (type, context_die) | |
10304 | register tree type; | |
10305 | register dw_die_ref context_die; | |
10306 | { | |
61b32c02 | 10307 | register tree member; |
10a11b75 | 10308 | dw_die_ref child; |
71dfc51f | 10309 | |
a3f97cbb JW |
10310 | /* If this is not an incomplete type, output descriptions of each of its |
10311 | members. Note that as we output the DIEs necessary to represent the | |
10312 | members of this record or union type, we will also be trying to output | |
10313 | DIEs to represent the *types* of those members. However the `type' | |
556273e0 KH |
10314 | function (above) will specifically avoid generating type DIEs for member |
10315 | types *within* the list of member DIEs for this (containing) type execpt | |
a3f97cbb JW |
10316 | for those types (of members) which are explicitly marked as also being |
10317 | members of this (containing) type themselves. The g++ front- end can | |
10318 | force any given type to be treated as a member of some other | |
556273e0 | 10319 | (containing) type by setting the TYPE_CONTEXT of the given (member) type |
a3f97cbb JW |
10320 | to point to the TREE node representing the appropriate (containing) |
10321 | type. */ | |
10322 | ||
61b32c02 JM |
10323 | /* First output info about the base classes. */ |
10324 | if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type)) | |
a3f97cbb | 10325 | { |
61b32c02 JM |
10326 | register tree bases = TYPE_BINFO_BASETYPES (type); |
10327 | register int n_bases = TREE_VEC_LENGTH (bases); | |
10328 | register int i; | |
10329 | ||
10330 | for (i = 0; i < n_bases; i++) | |
10331 | gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die); | |
a3f97cbb JW |
10332 | } |
10333 | ||
61b32c02 JM |
10334 | /* Now output info about the data members and type members. */ |
10335 | for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member)) | |
10a11b75 JM |
10336 | { |
10337 | /* If we thought we were generating minimal debug info for TYPE | |
10338 | and then changed our minds, some of the member declarations | |
10339 | may have already been defined. Don't define them again, but | |
10340 | do put them in the right order. */ | |
10341 | ||
10342 | child = lookup_decl_die (member); | |
10343 | if (child) | |
10344 | splice_child_die (context_die, child); | |
10345 | else | |
10346 | gen_decl_die (member, context_die); | |
10347 | } | |
61b32c02 | 10348 | |
a3f97cbb | 10349 | /* Now output info about the function members (if any). */ |
61b32c02 | 10350 | for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member)) |
10a11b75 | 10351 | { |
5daf7c0a JM |
10352 | /* Don't include clones in the member list. */ |
10353 | if (DECL_ABSTRACT_ORIGIN (member)) | |
10354 | continue; | |
10355 | ||
10a11b75 JM |
10356 | child = lookup_decl_die (member); |
10357 | if (child) | |
10358 | splice_child_die (context_die, child); | |
10359 | else | |
10360 | gen_decl_die (member, context_die); | |
10361 | } | |
a3f97cbb JW |
10362 | } |
10363 | ||
10a11b75 JM |
10364 | /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG |
10365 | is set, we pretend that the type was never defined, so we only get the | |
10366 | member DIEs needed by later specification DIEs. */ | |
71dfc51f | 10367 | |
a3f97cbb | 10368 | static void |
273dbe67 | 10369 | gen_struct_or_union_type_die (type, context_die) |
a3f97cbb | 10370 | register tree type; |
a3f97cbb JW |
10371 | register dw_die_ref context_die; |
10372 | { | |
273dbe67 | 10373 | register dw_die_ref type_die = lookup_type_die (type); |
a082c85a JM |
10374 | register dw_die_ref scope_die = 0; |
10375 | register int nested = 0; | |
10a11b75 | 10376 | int complete = (TYPE_SIZE (type) |
65e1263a JW |
10377 | && (! TYPE_STUB_DECL (type) |
10378 | || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)))); | |
273dbe67 | 10379 | |
10a11b75 | 10380 | if (type_die && ! complete) |
273dbe67 | 10381 | return; |
a082c85a | 10382 | |
71dfc51f | 10383 | if (TYPE_CONTEXT (type) != NULL_TREE |
5f2f160c | 10384 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))) |
a082c85a JM |
10385 | nested = 1; |
10386 | ||
a94dbf2c | 10387 | scope_die = scope_die_for (type, context_die); |
a082c85a JM |
10388 | |
10389 | if (! type_die || (nested && scope_die == comp_unit_die)) | |
273dbe67 | 10390 | /* First occurrence of type or toplevel definition of nested class. */ |
a3f97cbb | 10391 | { |
273dbe67 | 10392 | register dw_die_ref old_die = type_die; |
71dfc51f | 10393 | |
a3f97cbb JW |
10394 | type_die = new_die (TREE_CODE (type) == RECORD_TYPE |
10395 | ? DW_TAG_structure_type : DW_TAG_union_type, | |
a082c85a | 10396 | scope_die); |
a3f97cbb | 10397 | equate_type_number_to_die (type, type_die); |
273dbe67 JM |
10398 | if (old_die) |
10399 | add_AT_die_ref (type_die, DW_AT_specification, old_die); | |
5de0e8d4 JM |
10400 | else |
10401 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 10402 | } |
4b674448 | 10403 | else |
273dbe67 | 10404 | remove_AT (type_die, DW_AT_declaration); |
a3f97cbb JW |
10405 | |
10406 | /* If this type has been completed, then give it a byte_size attribute and | |
10407 | then give a list of members. */ | |
2081603c | 10408 | if (complete) |
a3f97cbb | 10409 | { |
556273e0 | 10410 | /* Prevent infinite recursion in cases where the type of some member of |
a3f97cbb JW |
10411 | this type is expressed in terms of this type itself. */ |
10412 | TREE_ASM_WRITTEN (type) = 1; | |
273dbe67 | 10413 | add_byte_size_attribute (type_die, type); |
e9a25f70 | 10414 | if (TYPE_STUB_DECL (type) != NULL_TREE) |
b2932ae5 | 10415 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); |
71dfc51f | 10416 | |
ef76d03b JW |
10417 | /* If the first reference to this type was as the return type of an |
10418 | inline function, then it may not have a parent. Fix this now. */ | |
10419 | if (type_die->die_parent == NULL) | |
10420 | add_child_die (scope_die, type_die); | |
10421 | ||
273dbe67 JM |
10422 | push_decl_scope (type); |
10423 | gen_member_die (type, type_die); | |
10424 | pop_decl_scope (); | |
71dfc51f | 10425 | |
a94dbf2c JM |
10426 | /* GNU extension: Record what type our vtable lives in. */ |
10427 | if (TYPE_VFIELD (type)) | |
10428 | { | |
10429 | tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type)); | |
71dfc51f | 10430 | |
de6e505e JM |
10431 | gen_type_die (vtype, context_die); |
10432 | add_AT_die_ref (type_die, DW_AT_containing_type, | |
10433 | lookup_type_die (vtype)); | |
a94dbf2c | 10434 | } |
a3f97cbb | 10435 | } |
4b674448 | 10436 | else |
8a8c3656 JM |
10437 | { |
10438 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a30d4514 | 10439 | |
9765e357 | 10440 | /* We don't need to do this for function-local types. */ |
f19f17e0 | 10441 | if (! decl_function_context (TYPE_STUB_DECL (type))) |
a30d4514 | 10442 | add_incomplete_type (type); |
8a8c3656 | 10443 | } |
a3f97cbb JW |
10444 | } |
10445 | ||
10446 | /* Generate a DIE for a subroutine _type_. */ | |
71dfc51f | 10447 | |
a3f97cbb JW |
10448 | static void |
10449 | gen_subroutine_type_die (type, context_die) | |
10450 | register tree type; | |
10451 | register dw_die_ref context_die; | |
10452 | { | |
10453 | register tree return_type = TREE_TYPE (type); | |
71dfc51f RK |
10454 | register dw_die_ref subr_die |
10455 | = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die)); | |
10456 | ||
a3f97cbb JW |
10457 | equate_type_number_to_die (type, subr_die); |
10458 | add_prototyped_attribute (subr_die, type); | |
a3f97cbb | 10459 | add_type_attribute (subr_die, return_type, 0, 0, context_die); |
a94dbf2c | 10460 | gen_formal_types_die (type, subr_die); |
a3f97cbb JW |
10461 | } |
10462 | ||
10463 | /* Generate a DIE for a type definition */ | |
71dfc51f | 10464 | |
a3f97cbb JW |
10465 | static void |
10466 | gen_typedef_die (decl, context_die) | |
10467 | register tree decl; | |
10468 | register dw_die_ref context_die; | |
10469 | { | |
a3f97cbb | 10470 | register dw_die_ref type_die; |
a94dbf2c JM |
10471 | register tree origin; |
10472 | ||
10473 | if (TREE_ASM_WRITTEN (decl)) | |
10474 | return; | |
10475 | TREE_ASM_WRITTEN (decl) = 1; | |
10476 | ||
777ad4c2 | 10477 | type_die = new_die (DW_TAG_typedef, context_die); |
a94dbf2c | 10478 | origin = decl_ultimate_origin (decl); |
a3f97cbb | 10479 | if (origin != NULL) |
a94dbf2c | 10480 | add_abstract_origin_attribute (type_die, origin); |
a3f97cbb JW |
10481 | else |
10482 | { | |
a94dbf2c | 10483 | register tree type; |
a3f97cbb | 10484 | add_name_and_src_coords_attributes (type_die, decl); |
a94dbf2c JM |
10485 | if (DECL_ORIGINAL_TYPE (decl)) |
10486 | { | |
10487 | type = DECL_ORIGINAL_TYPE (decl); | |
62e3bf54 JM |
10488 | |
10489 | if (type == TREE_TYPE (decl)) | |
10490 | abort (); | |
10491 | else | |
10492 | equate_type_number_to_die (TREE_TYPE (decl), type_die); | |
a94dbf2c JM |
10493 | } |
10494 | else | |
10495 | type = TREE_TYPE (decl); | |
10496 | add_type_attribute (type_die, type, TREE_READONLY (decl), | |
10497 | TREE_THIS_VOLATILE (decl), context_die); | |
a3f97cbb | 10498 | } |
71dfc51f | 10499 | |
a3f97cbb | 10500 | if (DECL_ABSTRACT (decl)) |
a94dbf2c | 10501 | equate_decl_number_to_die (decl, type_die); |
a3f97cbb JW |
10502 | } |
10503 | ||
10504 | /* Generate a type description DIE. */ | |
71dfc51f | 10505 | |
a3f97cbb JW |
10506 | static void |
10507 | gen_type_die (type, context_die) | |
10508 | register tree type; | |
10509 | register dw_die_ref context_die; | |
10510 | { | |
348bb3c7 JM |
10511 | int need_pop; |
10512 | ||
71dfc51f RK |
10513 | if (type == NULL_TREE || type == error_mark_node) |
10514 | return; | |
a3f97cbb | 10515 | |
38e01259 | 10516 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
10517 | this type (i.e. without any const or volatile qualifiers) so get the |
10518 | main variant (i.e. the unqualified version) of this type now. */ | |
10519 | type = type_main_variant (type); | |
10520 | ||
10521 | if (TREE_ASM_WRITTEN (type)) | |
71dfc51f | 10522 | return; |
a3f97cbb | 10523 | |
a94dbf2c JM |
10524 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
10525 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
556273e0 | 10526 | { |
a94dbf2c JM |
10527 | TREE_ASM_WRITTEN (type) = 1; |
10528 | gen_decl_die (TYPE_NAME (type), context_die); | |
10529 | return; | |
10530 | } | |
10531 | ||
a3f97cbb JW |
10532 | switch (TREE_CODE (type)) |
10533 | { | |
10534 | case ERROR_MARK: | |
10535 | break; | |
10536 | ||
10537 | case POINTER_TYPE: | |
10538 | case REFERENCE_TYPE: | |
956d6950 JL |
10539 | /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This |
10540 | ensures that the gen_type_die recursion will terminate even if the | |
10541 | type is recursive. Recursive types are possible in Ada. */ | |
10542 | /* ??? We could perhaps do this for all types before the switch | |
10543 | statement. */ | |
10544 | TREE_ASM_WRITTEN (type) = 1; | |
10545 | ||
a3f97cbb JW |
10546 | /* For these types, all that is required is that we output a DIE (or a |
10547 | set of DIEs) to represent the "basis" type. */ | |
10548 | gen_type_die (TREE_TYPE (type), context_die); | |
10549 | break; | |
10550 | ||
10551 | case OFFSET_TYPE: | |
556273e0 | 10552 | /* This code is used for C++ pointer-to-data-member types. |
71dfc51f | 10553 | Output a description of the relevant class type. */ |
a3f97cbb | 10554 | gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die); |
71dfc51f | 10555 | |
a3f97cbb JW |
10556 | /* Output a description of the type of the object pointed to. */ |
10557 | gen_type_die (TREE_TYPE (type), context_die); | |
71dfc51f | 10558 | |
a3f97cbb JW |
10559 | /* Now output a DIE to represent this pointer-to-data-member type |
10560 | itself. */ | |
10561 | gen_ptr_to_mbr_type_die (type, context_die); | |
10562 | break; | |
10563 | ||
10564 | case SET_TYPE: | |
10565 | gen_type_die (TYPE_DOMAIN (type), context_die); | |
10566 | gen_set_type_die (type, context_die); | |
10567 | break; | |
10568 | ||
10569 | case FILE_TYPE: | |
10570 | gen_type_die (TREE_TYPE (type), context_die); | |
10571 | abort (); /* No way to represent these in Dwarf yet! */ | |
10572 | break; | |
10573 | ||
10574 | case FUNCTION_TYPE: | |
10575 | /* Force out return type (in case it wasn't forced out already). */ | |
10576 | gen_type_die (TREE_TYPE (type), context_die); | |
10577 | gen_subroutine_type_die (type, context_die); | |
10578 | break; | |
10579 | ||
10580 | case METHOD_TYPE: | |
10581 | /* Force out return type (in case it wasn't forced out already). */ | |
10582 | gen_type_die (TREE_TYPE (type), context_die); | |
10583 | gen_subroutine_type_die (type, context_die); | |
10584 | break; | |
10585 | ||
10586 | case ARRAY_TYPE: | |
10587 | if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE) | |
10588 | { | |
10589 | gen_type_die (TREE_TYPE (type), context_die); | |
10590 | gen_string_type_die (type, context_die); | |
10591 | } | |
10592 | else | |
71dfc51f | 10593 | gen_array_type_die (type, context_die); |
a3f97cbb JW |
10594 | break; |
10595 | ||
4061f623 BS |
10596 | case VECTOR_TYPE: |
10597 | gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die); | |
10598 | break; | |
10599 | ||
a3f97cbb JW |
10600 | case ENUMERAL_TYPE: |
10601 | case RECORD_TYPE: | |
10602 | case UNION_TYPE: | |
10603 | case QUAL_UNION_TYPE: | |
a082c85a | 10604 | /* If this is a nested type whose containing class hasn't been |
348bb3c7 JM |
10605 | written out yet, writing it out will cover this one, too. |
10606 | This does not apply to instantiations of member class templates; | |
10607 | they need to be added to the containing class as they are | |
777ad4c2 | 10608 | generated. FIXME: This hurts the idea of combining type decls |
348bb3c7 JM |
10609 | from multiple TUs, since we can't predict what set of template |
10610 | instantiations we'll get. */ | |
a082c85a | 10611 | if (TYPE_CONTEXT (type) |
5f2f160c | 10612 | && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) |
a082c85a | 10613 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) |
a94dbf2c JM |
10614 | { |
10615 | gen_type_die (TYPE_CONTEXT (type), context_die); | |
10616 | ||
348bb3c7 | 10617 | if (TREE_ASM_WRITTEN (type)) |
a94dbf2c JM |
10618 | return; |
10619 | ||
10620 | /* If that failed, attach ourselves to the stub. */ | |
10621 | push_decl_scope (TYPE_CONTEXT (type)); | |
10622 | context_die = lookup_type_die (TYPE_CONTEXT (type)); | |
348bb3c7 | 10623 | need_pop = 1; |
a94dbf2c | 10624 | } |
348bb3c7 JM |
10625 | else |
10626 | need_pop = 0; | |
a94dbf2c JM |
10627 | |
10628 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
273dbe67 | 10629 | gen_enumeration_type_die (type, context_die); |
a3f97cbb | 10630 | else |
273dbe67 | 10631 | gen_struct_or_union_type_die (type, context_die); |
4b674448 | 10632 | |
348bb3c7 | 10633 | if (need_pop) |
a94dbf2c JM |
10634 | pop_decl_scope (); |
10635 | ||
4b674448 | 10636 | /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix |
a082c85a JM |
10637 | it up if it is ever completed. gen_*_type_die will set it for us |
10638 | when appropriate. */ | |
10639 | return; | |
a3f97cbb JW |
10640 | |
10641 | case VOID_TYPE: | |
10642 | case INTEGER_TYPE: | |
10643 | case REAL_TYPE: | |
10644 | case COMPLEX_TYPE: | |
10645 | case BOOLEAN_TYPE: | |
10646 | case CHAR_TYPE: | |
10647 | /* No DIEs needed for fundamental types. */ | |
10648 | break; | |
10649 | ||
10650 | case LANG_TYPE: | |
10651 | /* No Dwarf representation currently defined. */ | |
10652 | break; | |
10653 | ||
10654 | default: | |
10655 | abort (); | |
10656 | } | |
10657 | ||
10658 | TREE_ASM_WRITTEN (type) = 1; | |
10659 | } | |
10660 | ||
10661 | /* Generate a DIE for a tagged type instantiation. */ | |
71dfc51f | 10662 | |
a3f97cbb JW |
10663 | static void |
10664 | gen_tagged_type_instantiation_die (type, context_die) | |
10665 | register tree type; | |
10666 | register dw_die_ref context_die; | |
10667 | { | |
71dfc51f RK |
10668 | if (type == NULL_TREE || type == error_mark_node) |
10669 | return; | |
a3f97cbb | 10670 | |
38e01259 | 10671 | /* We are going to output a DIE to represent the unqualified version of |
a3f97cbb JW |
10672 | this type (i.e. without any const or volatile qualifiers) so make sure |
10673 | that we have the main variant (i.e. the unqualified version) of this | |
10674 | type now. */ | |
bbc6ae08 | 10675 | if (type != type_main_variant (type)) |
3a88cbd1 | 10676 | abort (); |
a3f97cbb | 10677 | |
203588e7 | 10678 | /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is |
bbc6ae08 | 10679 | an instance of an unresolved type. */ |
556273e0 | 10680 | |
a3f97cbb JW |
10681 | switch (TREE_CODE (type)) |
10682 | { | |
10683 | case ERROR_MARK: | |
10684 | break; | |
10685 | ||
10686 | case ENUMERAL_TYPE: | |
10687 | gen_inlined_enumeration_type_die (type, context_die); | |
10688 | break; | |
10689 | ||
10690 | case RECORD_TYPE: | |
10691 | gen_inlined_structure_type_die (type, context_die); | |
10692 | break; | |
10693 | ||
10694 | case UNION_TYPE: | |
10695 | case QUAL_UNION_TYPE: | |
10696 | gen_inlined_union_type_die (type, context_die); | |
10697 | break; | |
10698 | ||
10699 | default: | |
71dfc51f | 10700 | abort (); |
a3f97cbb JW |
10701 | } |
10702 | } | |
10703 | ||
10704 | /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the | |
10705 | things which are local to the given block. */ | |
71dfc51f | 10706 | |
a3f97cbb | 10707 | static void |
d7248bff | 10708 | gen_block_die (stmt, context_die, depth) |
a3f97cbb JW |
10709 | register tree stmt; |
10710 | register dw_die_ref context_die; | |
d7248bff | 10711 | int depth; |
a3f97cbb JW |
10712 | { |
10713 | register int must_output_die = 0; | |
10714 | register tree origin; | |
10715 | register tree decl; | |
10716 | register enum tree_code origin_code; | |
10717 | ||
10718 | /* Ignore blocks never really used to make RTL. */ | |
10719 | ||
1e7f092a JM |
10720 | if (stmt == NULL_TREE || !TREE_USED (stmt) |
10721 | || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt))) | |
71dfc51f | 10722 | return; |
a3f97cbb JW |
10723 | |
10724 | /* Determine the "ultimate origin" of this block. This block may be an | |
10725 | inlined instance of an inlined instance of inline function, so we have | |
10726 | to trace all of the way back through the origin chain to find out what | |
10727 | sort of node actually served as the original seed for the creation of | |
10728 | the current block. */ | |
10729 | origin = block_ultimate_origin (stmt); | |
10730 | origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; | |
10731 | ||
10732 | /* Determine if we need to output any Dwarf DIEs at all to represent this | |
10733 | block. */ | |
10734 | if (origin_code == FUNCTION_DECL) | |
71dfc51f RK |
10735 | /* The outer scopes for inlinings *must* always be represented. We |
10736 | generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */ | |
10737 | must_output_die = 1; | |
a3f97cbb JW |
10738 | else |
10739 | { | |
10740 | /* In the case where the current block represents an inlining of the | |
556273e0 | 10741 | "body block" of an inline function, we must *NOT* output any DIE for |
a3f97cbb JW |
10742 | this block because we have already output a DIE to represent the |
10743 | whole inlined function scope and the "body block" of any function | |
10744 | doesn't really represent a different scope according to ANSI C | |
10745 | rules. So we check here to make sure that this block does not | |
10746 | represent a "body block inlining" before trying to set the | |
10747 | `must_output_die' flag. */ | |
d7248bff | 10748 | if (! is_body_block (origin ? origin : stmt)) |
a3f97cbb JW |
10749 | { |
10750 | /* Determine if this block directly contains any "significant" | |
10751 | local declarations which we will need to output DIEs for. */ | |
10752 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
71dfc51f RK |
10753 | /* We are not in terse mode so *any* local declaration counts |
10754 | as being a "significant" one. */ | |
10755 | must_output_die = (BLOCK_VARS (stmt) != NULL); | |
a3f97cbb | 10756 | else |
71dfc51f RK |
10757 | /* We are in terse mode, so only local (nested) function |
10758 | definitions count as "significant" local declarations. */ | |
10759 | for (decl = BLOCK_VARS (stmt); | |
10760 | decl != NULL; decl = TREE_CHAIN (decl)) | |
10761 | if (TREE_CODE (decl) == FUNCTION_DECL | |
10762 | && DECL_INITIAL (decl)) | |
a3f97cbb | 10763 | { |
71dfc51f RK |
10764 | must_output_die = 1; |
10765 | break; | |
a3f97cbb | 10766 | } |
a3f97cbb JW |
10767 | } |
10768 | } | |
10769 | ||
10770 | /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block | |
10771 | DIE for any block which contains no significant local declarations at | |
10772 | all. Rather, in such cases we just call `decls_for_scope' so that any | |
10773 | needed Dwarf info for any sub-blocks will get properly generated. Note | |
10774 | that in terse mode, our definition of what constitutes a "significant" | |
10775 | local declaration gets restricted to include only inlined function | |
10776 | instances and local (nested) function definitions. */ | |
10777 | if (must_output_die) | |
10778 | { | |
10779 | if (origin_code == FUNCTION_DECL) | |
71dfc51f | 10780 | gen_inlined_subroutine_die (stmt, context_die, depth); |
a3f97cbb | 10781 | else |
71dfc51f | 10782 | gen_lexical_block_die (stmt, context_die, depth); |
a3f97cbb JW |
10783 | } |
10784 | else | |
d7248bff | 10785 | decls_for_scope (stmt, context_die, depth); |
a3f97cbb JW |
10786 | } |
10787 | ||
10788 | /* Generate all of the decls declared within a given scope and (recursively) | |
9ec36da5 | 10789 | all of its sub-blocks. */ |
71dfc51f | 10790 | |
a3f97cbb | 10791 | static void |
d7248bff | 10792 | decls_for_scope (stmt, context_die, depth) |
a3f97cbb JW |
10793 | register tree stmt; |
10794 | register dw_die_ref context_die; | |
d7248bff | 10795 | int depth; |
a3f97cbb JW |
10796 | { |
10797 | register tree decl; | |
10798 | register tree subblocks; | |
71dfc51f | 10799 | |
a3f97cbb | 10800 | /* Ignore blocks never really used to make RTL. */ |
71dfc51f RK |
10801 | if (stmt == NULL_TREE || ! TREE_USED (stmt)) |
10802 | return; | |
10803 | ||
88dad228 JM |
10804 | /* Output the DIEs to represent all of the data objects and typedefs |
10805 | declared directly within this block but not within any nested | |
10806 | sub-blocks. Also, nested function and tag DIEs have been | |
10807 | generated with a parent of NULL; fix that up now. */ | |
a3f97cbb JW |
10808 | for (decl = BLOCK_VARS (stmt); |
10809 | decl != NULL; decl = TREE_CHAIN (decl)) | |
10810 | { | |
a94dbf2c JM |
10811 | register dw_die_ref die; |
10812 | ||
88dad228 | 10813 | if (TREE_CODE (decl) == FUNCTION_DECL) |
a94dbf2c | 10814 | die = lookup_decl_die (decl); |
88dad228 | 10815 | else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)) |
a94dbf2c JM |
10816 | die = lookup_type_die (TREE_TYPE (decl)); |
10817 | else | |
10818 | die = NULL; | |
10819 | ||
71dfc51f | 10820 | if (die != NULL && die->die_parent == NULL) |
ef76d03b | 10821 | add_child_die (context_die, die); |
88dad228 JM |
10822 | else |
10823 | gen_decl_die (decl, context_die); | |
a3f97cbb JW |
10824 | } |
10825 | ||
10826 | /* Output the DIEs to represent all sub-blocks (and the items declared | |
10827 | therein) of this block. */ | |
10828 | for (subblocks = BLOCK_SUBBLOCKS (stmt); | |
10829 | subblocks != NULL; | |
10830 | subblocks = BLOCK_CHAIN (subblocks)) | |
71dfc51f | 10831 | gen_block_die (subblocks, context_die, depth + 1); |
a3f97cbb JW |
10832 | } |
10833 | ||
a94dbf2c | 10834 | /* Is this a typedef we can avoid emitting? */ |
71dfc51f RK |
10835 | |
10836 | static inline int | |
a94dbf2c JM |
10837 | is_redundant_typedef (decl) |
10838 | register tree decl; | |
10839 | { | |
10840 | if (TYPE_DECL_IS_STUB (decl)) | |
10841 | return 1; | |
71dfc51f | 10842 | |
a94dbf2c JM |
10843 | if (DECL_ARTIFICIAL (decl) |
10844 | && DECL_CONTEXT (decl) | |
10845 | && is_tagged_type (DECL_CONTEXT (decl)) | |
10846 | && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL | |
10847 | && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) | |
10848 | /* Also ignore the artificial member typedef for the class name. */ | |
10849 | return 1; | |
71dfc51f | 10850 | |
a94dbf2c JM |
10851 | return 0; |
10852 | } | |
10853 | ||
a3f97cbb | 10854 | /* Generate Dwarf debug information for a decl described by DECL. */ |
71dfc51f | 10855 | |
a3f97cbb JW |
10856 | static void |
10857 | gen_decl_die (decl, context_die) | |
10858 | register tree decl; | |
10859 | register dw_die_ref context_die; | |
10860 | { | |
10861 | register tree origin; | |
71dfc51f | 10862 | |
a3f97cbb | 10863 | if (TREE_CODE (decl) == ERROR_MARK) |
71dfc51f | 10864 | return; |
a3f97cbb | 10865 | |
fcd7f76b JM |
10866 | /* If this ..._DECL node is marked to be ignored, then ignore it. */ |
10867 | if (DECL_IGNORED_P (decl)) | |
71dfc51f | 10868 | return; |
a3f97cbb | 10869 | |
a3f97cbb JW |
10870 | switch (TREE_CODE (decl)) |
10871 | { | |
10872 | case CONST_DECL: | |
556273e0 | 10873 | /* The individual enumerators of an enum type get output when we output |
a3f97cbb JW |
10874 | the Dwarf representation of the relevant enum type itself. */ |
10875 | break; | |
10876 | ||
10877 | case FUNCTION_DECL: | |
4edb7b60 JM |
10878 | /* Don't output any DIEs to represent mere function declarations, |
10879 | unless they are class members or explicit block externs. */ | |
10880 | if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE | |
777ad4c2 | 10881 | && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl))) |
71dfc51f | 10882 | break; |
bdb669cb | 10883 | |
5daf7c0a JM |
10884 | /* If we're emitting a clone, emit info for the abstract instance. */ |
10885 | if (DECL_ORIGIN (decl) != decl) | |
10886 | dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl)); | |
1cfdcc15 JM |
10887 | /* If we're emitting an out-of-line copy of an inline function, |
10888 | emit info for the abstract instance and set up to refer to it. */ | |
5daf7c0a JM |
10889 | else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl) |
10890 | && ! class_scope_p (context_die) | |
10891 | /* dwarf2out_abstract_function won't emit a die if this is just | |
10892 | a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in | |
10893 | that case, because that works only if we have a die. */ | |
10894 | && DECL_INITIAL (decl) != NULL_TREE) | |
1cfdcc15 | 10895 | { |
1edf43d6 | 10896 | dwarf2out_abstract_function (decl); |
1cfdcc15 JM |
10897 | set_decl_origin_self (decl); |
10898 | } | |
5daf7c0a JM |
10899 | /* Otherwise we're emitting the primary DIE for this decl. */ |
10900 | else if (debug_info_level > DINFO_LEVEL_TERSE) | |
a94dbf2c JM |
10901 | { |
10902 | /* Before we describe the FUNCTION_DECL itself, make sure that we | |
10903 | have described its return type. */ | |
10904 | gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); | |
10905 | ||
2081603c JM |
10906 | /* And its virtual context. */ |
10907 | if (DECL_VINDEX (decl) != NULL_TREE) | |
10908 | gen_type_die (DECL_CONTEXT (decl), context_die); | |
10909 | ||
a94dbf2c JM |
10910 | /* And its containing type. */ |
10911 | origin = decl_class_context (decl); | |
71dfc51f | 10912 | if (origin != NULL_TREE) |
10a11b75 | 10913 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 10914 | } |
a3f97cbb JW |
10915 | |
10916 | /* Now output a DIE to represent the function itself. */ | |
10917 | gen_subprogram_die (decl, context_die); | |
10918 | break; | |
10919 | ||
10920 | case TYPE_DECL: | |
10921 | /* If we are in terse mode, don't generate any DIEs to represent any | |
4927276d | 10922 | actual typedefs. */ |
a3f97cbb | 10923 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 10924 | break; |
a3f97cbb | 10925 | |
556273e0 | 10926 | /* In the special case of a TYPE_DECL node representing the |
5c90448c | 10927 | declaration of some type tag, if the given TYPE_DECL is marked as |
a3f97cbb JW |
10928 | having been instantiated from some other (original) TYPE_DECL node |
10929 | (e.g. one which was generated within the original definition of an | |
10930 | inline function) we have to generate a special (abbreviated) | |
556273e0 | 10931 | DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type |
a3f97cbb | 10932 | DIE here. */ |
2081603c | 10933 | if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE) |
a3f97cbb JW |
10934 | { |
10935 | gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die); | |
10936 | break; | |
10937 | } | |
a3f97cbb | 10938 | |
a94dbf2c JM |
10939 | if (is_redundant_typedef (decl)) |
10940 | gen_type_die (TREE_TYPE (decl), context_die); | |
10941 | else | |
71dfc51f RK |
10942 | /* Output a DIE to represent the typedef itself. */ |
10943 | gen_typedef_die (decl, context_die); | |
a3f97cbb JW |
10944 | break; |
10945 | ||
10946 | case LABEL_DECL: | |
10947 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
71dfc51f | 10948 | gen_label_die (decl, context_die); |
a3f97cbb JW |
10949 | break; |
10950 | ||
10951 | case VAR_DECL: | |
10952 | /* If we are in terse mode, don't generate any DIEs to represent any | |
10953 | variable declarations or definitions. */ | |
10954 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 10955 | break; |
a3f97cbb JW |
10956 | |
10957 | /* Output any DIEs that are needed to specify the type of this data | |
10958 | object. */ | |
10959 | gen_type_die (TREE_TYPE (decl), context_die); | |
10960 | ||
a94dbf2c JM |
10961 | /* And its containing type. */ |
10962 | origin = decl_class_context (decl); | |
71dfc51f | 10963 | if (origin != NULL_TREE) |
10a11b75 | 10964 | gen_type_die_for_member (origin, decl, context_die); |
a94dbf2c | 10965 | |
a3f97cbb JW |
10966 | /* Now output the DIE to represent the data object itself. This gets |
10967 | complicated because of the possibility that the VAR_DECL really | |
10968 | represents an inlined instance of a formal parameter for an inline | |
10969 | function. */ | |
10970 | origin = decl_ultimate_origin (decl); | |
71dfc51f RK |
10971 | if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL) |
10972 | gen_formal_parameter_die (decl, context_die); | |
a3f97cbb | 10973 | else |
71dfc51f | 10974 | gen_variable_die (decl, context_die); |
a3f97cbb JW |
10975 | break; |
10976 | ||
10977 | case FIELD_DECL: | |
a94dbf2c JM |
10978 | /* Ignore the nameless fields that are used to skip bits, but |
10979 | handle C++ anonymous unions. */ | |
71dfc51f RK |
10980 | if (DECL_NAME (decl) != NULL_TREE |
10981 | || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE) | |
a3f97cbb JW |
10982 | { |
10983 | gen_type_die (member_declared_type (decl), context_die); | |
10984 | gen_field_die (decl, context_die); | |
10985 | } | |
10986 | break; | |
10987 | ||
10988 | case PARM_DECL: | |
10989 | gen_type_die (TREE_TYPE (decl), context_die); | |
10990 | gen_formal_parameter_die (decl, context_die); | |
10991 | break; | |
10992 | ||
348bb3c7 JM |
10993 | case NAMESPACE_DECL: |
10994 | /* Ignore for now. */ | |
10995 | break; | |
10996 | ||
a3f97cbb JW |
10997 | default: |
10998 | abort (); | |
10999 | } | |
a3f97cbb JW |
11000 | } |
11001 | \f | |
14a774a9 RK |
11002 | /* Add Ada "use" clause information for SGI Workshop debugger. */ |
11003 | ||
11004 | void | |
11005 | dwarf2out_add_library_unit_info (filename, context_list) | |
c6991660 KG |
11006 | const char *filename; |
11007 | const char *context_list; | |
14a774a9 RK |
11008 | { |
11009 | unsigned int file_index; | |
11010 | ||
11011 | if (filename != NULL) | |
11012 | { | |
11013 | dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die); | |
556273e0 | 11014 | tree context_list_decl |
14a774a9 RK |
11015 | = build_decl (LABEL_DECL, get_identifier (context_list), |
11016 | void_type_node); | |
11017 | ||
11018 | TREE_PUBLIC (context_list_decl) = TRUE; | |
11019 | add_name_attribute (unit_die, context_list); | |
981975b6 | 11020 | file_index = lookup_filename (filename); |
14a774a9 RK |
11021 | add_AT_unsigned (unit_die, DW_AT_decl_file, file_index); |
11022 | add_pubname (context_list_decl, unit_die); | |
11023 | } | |
11024 | } | |
11025 | ||
2b85879e NB |
11026 | /* Debug information for a global DECL. Called from toplev.c after |
11027 | compilation proper has finished. */ | |
11028 | static void | |
11029 | dwarf2out_global_decl (decl) | |
11030 | tree decl; | |
11031 | { | |
11032 | /* Output DWARF2 information for file-scope tentative data object | |
11033 | declarations, file-scope (extern) function declarations (which | |
11034 | had no corresponding body) and file-scope tagged type | |
11035 | declarations and definitions which have not yet been forced out. */ | |
11036 | ||
11037 | if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)) | |
11038 | dwarf2out_decl (decl); | |
11039 | } | |
11040 | ||
71dfc51f RK |
11041 | /* Write the debugging output for DECL. */ |
11042 | ||
a3f97cbb | 11043 | void |
88dad228 | 11044 | dwarf2out_decl (decl) |
a3f97cbb | 11045 | register tree decl; |
a3f97cbb | 11046 | { |
88dad228 JM |
11047 | register dw_die_ref context_die = comp_unit_die; |
11048 | ||
a3f97cbb | 11049 | if (TREE_CODE (decl) == ERROR_MARK) |
71dfc51f | 11050 | return; |
a3f97cbb | 11051 | |
fcd7f76b | 11052 | /* If this ..._DECL node is marked to be ignored, then ignore it. */ |
a3f97cbb | 11053 | if (DECL_IGNORED_P (decl)) |
fcd7f76b | 11054 | return; |
a3f97cbb JW |
11055 | |
11056 | switch (TREE_CODE (decl)) | |
11057 | { | |
11058 | case FUNCTION_DECL: | |
556273e0 | 11059 | /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a |
a3f97cbb JW |
11060 | builtin function. Explicit programmer-supplied declarations of |
11061 | these same functions should NOT be ignored however. */ | |
9765e357 | 11062 | if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl)) |
b1ccbc24 | 11063 | return; |
a3f97cbb JW |
11064 | |
11065 | /* What we would really like to do here is to filter out all mere | |
11066 | file-scope declarations of file-scope functions which are never | |
11067 | referenced later within this translation unit (and keep all of ones | |
556273e0 KH |
11068 | that *are* referenced later on) but we aren't clairvoyant, so we have |
11069 | no idea which functions will be referenced in the future (i.e. later | |
a3f97cbb | 11070 | on within the current translation unit). So here we just ignore all |
556273e0 | 11071 | file-scope function declarations which are not also definitions. If |
956d6950 | 11072 | and when the debugger needs to know something about these functions, |
556273e0 | 11073 | it will have to hunt around and find the DWARF information associated |
bbc6ae08 | 11074 | with the definition of the function. Note that we can't just check |
a3f97cbb JW |
11075 | `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent |
11076 | definitions and which ones represent mere declarations. We have to | |
11077 | check `DECL_INITIAL' instead. That's because the C front-end | |
11078 | supports some weird semantics for "extern inline" function | |
11079 | definitions. These can get inlined within the current translation | |
11080 | unit (an thus, we need to generate DWARF info for their abstract | |
11081 | instances so that the DWARF info for the concrete inlined instances | |
556273e0 | 11082 | can have something to refer to) but the compiler never generates any |
a3f97cbb JW |
11083 | out-of-lines instances of such things (despite the fact that they |
11084 | *are* definitions). The important point is that the C front-end | |
11085 | marks these "extern inline" functions as DECL_EXTERNAL, but we need | |
273dbe67 | 11086 | to generate DWARF for them anyway. Note that the C++ front-end also |
a3f97cbb | 11087 | plays some similar games for inline function definitions appearing |
556273e0 | 11088 | within include files which also contain |
a3f97cbb JW |
11089 | `#pragma interface' pragmas. */ |
11090 | if (DECL_INITIAL (decl) == NULL_TREE) | |
b1ccbc24 | 11091 | return; |
88dad228 | 11092 | |
9c6cd30e JM |
11093 | /* If we're a nested function, initially use a parent of NULL; if we're |
11094 | a plain function, this will be fixed up in decls_for_scope. If | |
11095 | we're a method, it will be ignored, since we already have a DIE. */ | |
88dad228 | 11096 | if (decl_function_context (decl)) |
9c6cd30e | 11097 | context_die = NULL; |
88dad228 | 11098 | |
a3f97cbb JW |
11099 | break; |
11100 | ||
11101 | case VAR_DECL: | |
556273e0 | 11102 | /* Ignore this VAR_DECL if it refers to a file-scope extern data object |
a3f97cbb JW |
11103 | declaration and if the declaration was never even referenced from |
11104 | within this entire compilation unit. We suppress these DIEs in | |
11105 | order to save space in the .debug section (by eliminating entries | |
11106 | which are probably useless). Note that we must not suppress | |
11107 | block-local extern declarations (whether used or not) because that | |
11108 | would screw-up the debugger's name lookup mechanism and cause it to | |
11109 | miss things which really ought to be in scope at a given point. */ | |
11110 | if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) | |
71dfc51f | 11111 | return; |
a3f97cbb JW |
11112 | |
11113 | /* If we are in terse mode, don't generate any DIEs to represent any | |
11114 | variable declarations or definitions. */ | |
11115 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 11116 | return; |
a3f97cbb JW |
11117 | break; |
11118 | ||
11119 | case TYPE_DECL: | |
57fb7689 JM |
11120 | /* Don't emit stubs for types unless they are needed by other DIEs. */ |
11121 | if (TYPE_DECL_SUPPRESS_DEBUG (decl)) | |
11122 | return; | |
11123 | ||
a3f97cbb | 11124 | /* Don't bother trying to generate any DIEs to represent any of the |
a9d38797 JM |
11125 | normal built-in types for the language we are compiling. */ |
11126 | if (DECL_SOURCE_LINE (decl) == 0) | |
a94dbf2c JM |
11127 | { |
11128 | /* OK, we need to generate one for `bool' so GDB knows what type | |
11129 | comparisons have. */ | |
11130 | if ((get_AT_unsigned (comp_unit_die, DW_AT_language) | |
11131 | == DW_LANG_C_plus_plus) | |
11132 | && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE) | |
11133 | modified_type_die (TREE_TYPE (decl), 0, 0, NULL); | |
71dfc51f | 11134 | |
a94dbf2c JM |
11135 | return; |
11136 | } | |
a3f97cbb | 11137 | |
88dad228 | 11138 | /* If we are in terse mode, don't generate any DIEs for types. */ |
a3f97cbb | 11139 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 11140 | return; |
88dad228 JM |
11141 | |
11142 | /* If we're a function-scope tag, initially use a parent of NULL; | |
11143 | this will be fixed up in decls_for_scope. */ | |
11144 | if (decl_function_context (decl)) | |
3f76745e | 11145 | context_die = NULL; |
88dad228 | 11146 | |
a3f97cbb JW |
11147 | break; |
11148 | ||
11149 | default: | |
11150 | return; | |
11151 | } | |
11152 | ||
88dad228 | 11153 | gen_decl_die (decl, context_die); |
a3f97cbb JW |
11154 | } |
11155 | ||
11156 | /* Output a marker (i.e. a label) for the beginning of the generated code for | |
11157 | a lexical block. */ | |
71dfc51f | 11158 | |
a5a42b92 | 11159 | static void |
e2a12aca | 11160 | dwarf2out_begin_block (line, blocknum) |
a5a42b92 NB |
11161 | unsigned int line ATTRIBUTE_UNUSED; |
11162 | unsigned int blocknum; | |
a3f97cbb | 11163 | { |
a3f97cbb | 11164 | function_section (current_function_decl); |
8215347e | 11165 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum); |
a3f97cbb JW |
11166 | } |
11167 | ||
11168 | /* Output a marker (i.e. a label) for the end of the generated code for a | |
11169 | lexical block. */ | |
71dfc51f | 11170 | |
a5a42b92 | 11171 | static void |
e2a12aca | 11172 | dwarf2out_end_block (line, blocknum) |
a5a42b92 NB |
11173 | unsigned int line ATTRIBUTE_UNUSED; |
11174 | unsigned int blocknum; | |
a3f97cbb | 11175 | { |
a3f97cbb | 11176 | function_section (current_function_decl); |
8215347e | 11177 | ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum); |
a3f97cbb JW |
11178 | } |
11179 | ||
64b59a80 JM |
11180 | /* Returns nonzero if it is appropriate not to emit any debugging |
11181 | information for BLOCK, because it doesn't contain any instructions. | |
fcd7f76b | 11182 | |
64b59a80 JM |
11183 | Don't allow this for blocks with nested functions or local classes |
11184 | as we would end up with orphans, and in the presence of scheduling | |
11185 | we may end up calling them anyway. */ | |
11186 | ||
e1772ac0 | 11187 | static bool |
fcd7f76b JM |
11188 | dwarf2out_ignore_block (block) |
11189 | tree block; | |
11190 | { | |
11191 | tree decl; | |
11192 | for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) | |
64b59a80 JM |
11193 | if (TREE_CODE (decl) == FUNCTION_DECL |
11194 | || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))) | |
11195 | return 0; | |
11196 | return 1; | |
fcd7f76b JM |
11197 | } |
11198 | ||
a3f97cbb | 11199 | /* Lookup a filename (in the list of filenames that we know about here in |
9a666dda | 11200 | dwarf2out.c) and return its "index". The index of each (known) filename is |
a3f97cbb JW |
11201 | just a unique number which is associated with only that one filename. |
11202 | We need such numbers for the sake of generating labels | |
11203 | (in the .debug_sfnames section) and references to those | |
11204 | files numbers (in the .debug_srcinfo and.debug_macinfo sections). | |
11205 | If the filename given as an argument is not found in our current list, | |
11206 | add it to the list and assign it the next available unique index number. | |
11207 | In order to speed up searches, we remember the index of the filename | |
11208 | was looked up last. This handles the majority of all searches. */ | |
71dfc51f | 11209 | |
a3f97cbb | 11210 | static unsigned |
981975b6 | 11211 | lookup_filename (file_name) |
d560ee52 | 11212 | const char *file_name; |
a3f97cbb | 11213 | { |
a3f97cbb JW |
11214 | register unsigned i; |
11215 | ||
981975b6 RH |
11216 | /* ??? Why isn't DECL_SOURCE_FILE left null instead. */ |
11217 | if (strcmp (file_name, "<internal>") == 0 | |
11218 | || strcmp (file_name, "<built-in>") == 0) | |
11219 | return 0; | |
11220 | ||
2e18bbae RH |
11221 | /* Check to see if the file name that was searched on the previous |
11222 | call matches this file name. If so, return the index. */ | |
981975b6 RH |
11223 | if (file_table.last_lookup_index != 0) |
11224 | if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0) | |
11225 | return file_table.last_lookup_index; | |
a3f97cbb JW |
11226 | |
11227 | /* Didn't match the previous lookup, search the table */ | |
981975b6 RH |
11228 | for (i = 1; i < file_table.in_use; ++i) |
11229 | if (strcmp (file_name, file_table.table[i]) == 0) | |
71dfc51f | 11230 | { |
981975b6 | 11231 | file_table.last_lookup_index = i; |
71dfc51f RK |
11232 | return i; |
11233 | } | |
a3f97cbb | 11234 | |
556273e0 | 11235 | /* Prepare to add a new table entry by making sure there is enough space in |
a3f97cbb | 11236 | the table to do so. If not, expand the current table. */ |
981975b6 | 11237 | if (i == file_table.allocated) |
a3f97cbb | 11238 | { |
981975b6 RH |
11239 | file_table.allocated = i + FILE_TABLE_INCREMENT; |
11240 | file_table.table = (char **) | |
11241 | xrealloc (file_table.table, file_table.allocated * sizeof (char *)); | |
a3f97cbb JW |
11242 | } |
11243 | ||
71dfc51f | 11244 | /* Add the new entry to the end of the filename table. */ |
981975b6 RH |
11245 | file_table.table[i] = xstrdup (file_name); |
11246 | file_table.in_use = i + 1; | |
11247 | file_table.last_lookup_index = i; | |
2e18bbae | 11248 | |
acc187f5 RH |
11249 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
11250 | fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name); | |
11251 | ||
2e18bbae RH |
11252 | return i; |
11253 | } | |
11254 | ||
11255 | static void | |
981975b6 | 11256 | init_file_table () |
2e18bbae RH |
11257 | { |
11258 | /* Allocate the initial hunk of the file_table. */ | |
981975b6 RH |
11259 | file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *)); |
11260 | file_table.allocated = FILE_TABLE_INCREMENT; | |
71dfc51f | 11261 | |
2e18bbae | 11262 | /* Skip the first entry - file numbers begin at 1. */ |
981975b6 RH |
11263 | file_table.in_use = 1; |
11264 | file_table.last_lookup_index = 0; | |
a3f97cbb JW |
11265 | } |
11266 | ||
11267 | /* Output a label to mark the beginning of a source code line entry | |
11268 | and record information relating to this source line, in | |
11269 | 'line_info_table' for later output of the .debug_line section. */ | |
71dfc51f | 11270 | |
e2a12aca | 11271 | static void |
653e276c NB |
11272 | dwarf2out_source_line (line, filename) |
11273 | unsigned int line; | |
d560ee52 | 11274 | register const char *filename; |
a3f97cbb | 11275 | { |
a3f97cbb JW |
11276 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
11277 | { | |
11278 | function_section (current_function_decl); | |
a3f97cbb | 11279 | |
8aaf55ac JM |
11280 | /* If requested, emit something human-readable. */ |
11281 | if (flag_debug_asm) | |
11282 | fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, | |
11283 | filename, line); | |
11284 | ||
b2244e22 JW |
11285 | if (DWARF2_ASM_LINE_DEBUG_INFO) |
11286 | { | |
981975b6 | 11287 | unsigned file_num = lookup_filename (filename); |
b2244e22 | 11288 | |
981975b6 | 11289 | /* Emit the .loc directive understood by GNU as. */ |
2e18bbae | 11290 | fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line); |
b2244e22 JW |
11291 | |
11292 | /* Indicate that line number info exists. */ | |
11293 | ++line_info_table_in_use; | |
11294 | ||
11295 | /* Indicate that multiple line number tables exist. */ | |
11296 | if (DECL_SECTION_NAME (current_function_decl)) | |
11297 | ++separate_line_info_table_in_use; | |
11298 | } | |
11299 | else if (DECL_SECTION_NAME (current_function_decl)) | |
a3f97cbb | 11300 | { |
e90b62db | 11301 | register dw_separate_line_info_ref line_info; |
5c90448c JM |
11302 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL, |
11303 | separate_line_info_table_in_use); | |
e90b62db JM |
11304 | |
11305 | /* expand the line info table if necessary */ | |
11306 | if (separate_line_info_table_in_use | |
11307 | == separate_line_info_table_allocated) | |
11308 | { | |
11309 | separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
11310 | separate_line_info_table | |
71dfc51f RK |
11311 | = (dw_separate_line_info_ref) |
11312 | xrealloc (separate_line_info_table, | |
11313 | separate_line_info_table_allocated | |
11314 | * sizeof (dw_separate_line_info_entry)); | |
e90b62db | 11315 | } |
71dfc51f RK |
11316 | |
11317 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
11318 | line_info |
11319 | = &separate_line_info_table[separate_line_info_table_in_use++]; | |
981975b6 | 11320 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db JM |
11321 | line_info->dw_line_num = line; |
11322 | line_info->function = current_funcdef_number; | |
11323 | } | |
11324 | else | |
11325 | { | |
11326 | register dw_line_info_ref line_info; | |
71dfc51f | 11327 | |
5c90448c JM |
11328 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL, |
11329 | line_info_table_in_use); | |
e90b62db | 11330 | |
71dfc51f | 11331 | /* Expand the line info table if necessary. */ |
e90b62db JM |
11332 | if (line_info_table_in_use == line_info_table_allocated) |
11333 | { | |
11334 | line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
11335 | line_info_table | |
71dfc51f RK |
11336 | = (dw_line_info_ref) |
11337 | xrealloc (line_info_table, | |
11338 | (line_info_table_allocated | |
11339 | * sizeof (dw_line_info_entry))); | |
e90b62db | 11340 | } |
71dfc51f RK |
11341 | |
11342 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db | 11343 | line_info = &line_info_table[line_info_table_in_use++]; |
981975b6 | 11344 | line_info->dw_file_num = lookup_filename (filename); |
e90b62db | 11345 | line_info->dw_line_num = line; |
a3f97cbb | 11346 | } |
a3f97cbb JW |
11347 | } |
11348 | } | |
11349 | ||
cc260610 | 11350 | /* Record the beginning of a new source file. */ |
71dfc51f | 11351 | |
7f905405 | 11352 | static void |
84a5b4f8 | 11353 | dwarf2out_start_source_file (lineno, filename) |
7f905405 NB |
11354 | register unsigned int lineno; |
11355 | register const char *filename; | |
a3f97cbb | 11356 | { |
881c6935 JM |
11357 | if (flag_eliminate_dwarf2_dups) |
11358 | { | |
11359 | /* Record the beginning of the file for break_out_includes. */ | |
11360 | dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die); | |
11361 | add_AT_string (bincl_die, DW_AT_name, filename); | |
11362 | } | |
84a5b4f8 DB |
11363 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11364 | { | |
11365 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION); | |
11366 | dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file"); | |
11367 | dw2_asm_output_data_uleb128 (lineno, "Included from line number %d", lineno); | |
11368 | dw2_asm_output_data_uleb128 (lookup_filename (filename), "Filename we just started"); | |
11369 | } | |
a3f97cbb JW |
11370 | } |
11371 | ||
cc260610 | 11372 | /* Record the end of a source file. */ |
71dfc51f | 11373 | |
7f905405 NB |
11374 | static void |
11375 | dwarf2out_end_source_file (lineno) | |
11376 | unsigned int lineno ATTRIBUTE_UNUSED; | |
a3f97cbb | 11377 | { |
881c6935 JM |
11378 | if (flag_eliminate_dwarf2_dups) |
11379 | { | |
11380 | /* Record the end of the file for break_out_includes. */ | |
11381 | new_die (DW_TAG_GNU_EINCL, comp_unit_die); | |
0b34cf1e | 11382 | } |
84a5b4f8 DB |
11383 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11384 | { | |
11385 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION); | |
11386 | dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); | |
11387 | } | |
a3f97cbb JW |
11388 | } |
11389 | ||
cc260610 | 11390 | /* Called from debug_define in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
11391 | the tail part of the directive line, i.e. the part which is past the |
11392 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 11393 | |
7f905405 | 11394 | static void |
9a666dda | 11395 | dwarf2out_define (lineno, buffer) |
2618f955 | 11396 | register unsigned lineno ATTRIBUTE_UNUSED; |
d560ee52 | 11397 | register const char *buffer ATTRIBUTE_UNUSED; |
a3f97cbb JW |
11398 | { |
11399 | static int initialized = 0; | |
11400 | if (!initialized) | |
11401 | { | |
84a5b4f8 | 11402 | dwarf2out_start_source_file (0, primary_filename); |
a3f97cbb JW |
11403 | initialized = 1; |
11404 | } | |
84a5b4f8 DB |
11405 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11406 | { | |
11407 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION); | |
11408 | dw2_asm_output_data (1, DW_MACINFO_define, "Define macro"); | |
11409 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
11410 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
11411 | } | |
a3f97cbb JW |
11412 | } |
11413 | ||
cc260610 | 11414 | /* Called from debug_undef in toplev.c. The `buffer' parameter contains |
a3f97cbb JW |
11415 | the tail part of the directive line, i.e. the part which is past the |
11416 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 11417 | |
7f905405 | 11418 | static void |
9a666dda | 11419 | dwarf2out_undef (lineno, buffer) |
487a6e06 | 11420 | register unsigned lineno ATTRIBUTE_UNUSED; |
d560ee52 | 11421 | register const char *buffer ATTRIBUTE_UNUSED; |
a3f97cbb | 11422 | { |
84a5b4f8 DB |
11423 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11424 | { | |
11425 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION); | |
11426 | dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro"); | |
11427 | dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); | |
11428 | dw2_asm_output_nstring (buffer, -1, "The macro"); | |
11429 | } | |
a3f97cbb JW |
11430 | } |
11431 | ||
11432 | /* Set up for Dwarf output at the start of compilation. */ | |
71dfc51f | 11433 | |
a51d908e | 11434 | static void |
e2a12aca | 11435 | dwarf2out_init (main_input_filename) |
d3e3972c | 11436 | register const char *main_input_filename; |
a3f97cbb | 11437 | { |
acc187f5 RH |
11438 | init_file_table (); |
11439 | ||
a3f97cbb JW |
11440 | /* Remember the name of the primary input file. */ |
11441 | primary_filename = main_input_filename; | |
11442 | ||
acc187f5 RH |
11443 | /* Add it to the file table first, under the assumption that we'll |
11444 | be emitting line number data for it first, which avoids having | |
11445 | to add an initial DW_LNS_set_file. */ | |
11446 | lookup_filename (main_input_filename); | |
a3f97cbb | 11447 | |
a3f97cbb JW |
11448 | /* Allocate the initial hunk of the decl_die_table. */ |
11449 | decl_die_table | |
3de90026 | 11450 | = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref)); |
a3f97cbb JW |
11451 | decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT; |
11452 | decl_die_table_in_use = 0; | |
11453 | ||
11454 | /* Allocate the initial hunk of the decl_scope_table. */ | |
11455 | decl_scope_table | |
777ad4c2 | 11456 | = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree)); |
a3f97cbb JW |
11457 | decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT; |
11458 | decl_scope_depth = 0; | |
11459 | ||
11460 | /* Allocate the initial hunk of the abbrev_die_table. */ | |
11461 | abbrev_die_table | |
3de90026 RH |
11462 | = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT, |
11463 | sizeof (dw_die_ref)); | |
a3f97cbb | 11464 | abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT; |
71dfc51f | 11465 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
11466 | abbrev_die_table_in_use = 1; |
11467 | ||
11468 | /* Allocate the initial hunk of the line_info_table. */ | |
11469 | line_info_table | |
3de90026 RH |
11470 | = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT, |
11471 | sizeof (dw_line_info_entry)); | |
a3f97cbb | 11472 | line_info_table_allocated = LINE_INFO_TABLE_INCREMENT; |
71dfc51f | 11473 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
11474 | line_info_table_in_use = 1; |
11475 | ||
556273e0 | 11476 | /* Generate the initial DIE for the .debug section. Note that the (string) |
a3f97cbb | 11477 | value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE |
556273e0 | 11478 | will (typically) be a relative pathname and that this pathname should be |
a3f97cbb JW |
11479 | taken as being relative to the directory from which the compiler was |
11480 | invoked when the given (base) source file was compiled. */ | |
a96c67ec | 11481 | comp_unit_die = gen_compile_unit_die (main_input_filename); |
a3f97cbb | 11482 | |
1f8f4a0b MM |
11483 | VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray"); |
11484 | ggc_add_rtx_varray_root (&used_rtx_varray, 1); | |
1865dbb5 | 11485 | |
5c90448c | 11486 | ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0); |
9d2f2c45 RH |
11487 | ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, |
11488 | DEBUG_ABBREV_SECTION_LABEL, 0); | |
b366352b MM |
11489 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) |
11490 | ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0); | |
11491 | else | |
11492 | strcpy (text_section_label, stripattributes (TEXT_SECTION)); | |
556273e0 | 11493 | ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label, |
8b790721 | 11494 | DEBUG_INFO_SECTION_LABEL, 0); |
556273e0 | 11495 | ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label, |
8b790721 | 11496 | DEBUG_LINE_SECTION_LABEL, 0); |
9d2f2c45 RH |
11497 | ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL, 0); |
11498 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LOC_SECTION); | |
63e46568 | 11499 | ASM_OUTPUT_LABEL (asm_out_file, loc_section_label); |
9d2f2c45 | 11500 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ABBREV_SECTION); |
8b790721 | 11501 | ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label); |
b366352b | 11502 | if (DWARF2_GENERATE_TEXT_SECTION_LABEL) |
a96c67ec JM |
11503 | { |
11504 | ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION); | |
11505 | ASM_OUTPUT_LABEL (asm_out_file, text_section_label); | |
11506 | } | |
8b790721 JM |
11507 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION); |
11508 | ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label); | |
11509 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION); | |
11510 | ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label); | |
84a5b4f8 DB |
11511 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11512 | { | |
11513 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION); | |
11514 | ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label, | |
11515 | DEBUG_MACINFO_SECTION_LABEL, 0); | |
11516 | ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label); | |
11517 | } | |
a3f97cbb JW |
11518 | } |
11519 | ||
11520 | /* Output stuff that dwarf requires at the end of every file, | |
11521 | and generate the DWARF-2 debugging info. */ | |
71dfc51f | 11522 | |
a51d908e | 11523 | static void |
e2a12aca | 11524 | dwarf2out_finish (input_filename) |
a51d908e | 11525 | register const char *input_filename ATTRIBUTE_UNUSED; |
a3f97cbb | 11526 | { |
ef76d03b | 11527 | limbo_die_node *node, *next_node; |
ae0ed63a | 11528 | dw_die_ref die = 0; |
ef76d03b JW |
11529 | |
11530 | /* Traverse the limbo die list, and add parent/child links. The only | |
11531 | dies without parents that should be here are concrete instances of | |
11532 | inline functions, and the comp_unit_die. We can ignore the comp_unit_die. | |
11533 | For concrete instances, we can get the parent die from the abstract | |
11534 | instance. */ | |
11535 | for (node = limbo_die_list; node; node = next_node) | |
11536 | { | |
11537 | next_node = node->next; | |
11538 | die = node->die; | |
11539 | ||
11540 | if (die->die_parent == NULL) | |
11541 | { | |
a96c67ec JM |
11542 | dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin); |
11543 | if (origin) | |
11544 | add_child_die (origin->die_parent, die); | |
ef76d03b | 11545 | else if (die == comp_unit_die) |
a96c67ec | 11546 | ; |
ef76d03b JW |
11547 | else |
11548 | abort (); | |
11549 | } | |
11550 | free (node); | |
11551 | } | |
a96c67ec | 11552 | limbo_die_list = NULL; |
ef76d03b | 11553 | |
8a8c3656 JM |
11554 | /* Walk through the list of incomplete types again, trying once more to |
11555 | emit full debugging info for them. */ | |
11556 | retry_incomplete_types (); | |
11557 | ||
881c6935 JM |
11558 | /* We need to reverse all the dies before break_out_includes, or |
11559 | we'll see the end of an include file before the beginning. */ | |
11560 | reverse_all_dies (comp_unit_die); | |
11561 | ||
11562 | /* Generate separate CUs for each of the include files we've seen. | |
11563 | They will go into limbo_die_list. */ | |
5f632b5e JM |
11564 | if (flag_eliminate_dwarf2_dups) |
11565 | break_out_includes (comp_unit_die); | |
881c6935 JM |
11566 | |
11567 | /* Traverse the DIE's and add add sibling attributes to those DIE's | |
11568 | that have children. */ | |
a3f97cbb | 11569 | add_sibling_attributes (comp_unit_die); |
881c6935 JM |
11570 | for (node = limbo_die_list; node; node = node->next) |
11571 | add_sibling_attributes (node->die); | |
a3f97cbb JW |
11572 | |
11573 | /* Output a terminator label for the .text section. */ | |
a3f97cbb | 11574 | ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION); |
5c90448c | 11575 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0); |
a3f97cbb | 11576 | |
bdb669cb | 11577 | #if 0 |
a3f97cbb | 11578 | /* Output a terminator label for the .data section. */ |
a3f97cbb | 11579 | ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION); |
5c90448c | 11580 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0); |
a3f97cbb JW |
11581 | |
11582 | /* Output a terminator label for the .bss section. */ | |
a3f97cbb | 11583 | ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION); |
5c90448c | 11584 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0); |
bdb669cb | 11585 | #endif |
a3f97cbb | 11586 | |
db3c0315 MM |
11587 | /* Output the source line correspondence table. We must do this |
11588 | even if there is no line information. Otherwise, on an empty | |
11589 | translation unit, we will generate a present, but empty, | |
11590 | .debug_info section. IRIX 6.5 `nm' will then complain when | |
11591 | examining the file. */ | |
11592 | if (! DWARF2_ASM_LINE_DEBUG_INFO) | |
e90b62db | 11593 | { |
db3c0315 MM |
11594 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION); |
11595 | output_line_info (); | |
11596 | } | |
71dfc51f | 11597 | |
db3c0315 MM |
11598 | /* We can only use the low/high_pc attributes if all of the code was |
11599 | in .text. */ | |
11600 | if (separate_line_info_table_in_use == 0) | |
11601 | { | |
11602 | add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label); | |
11603 | add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label); | |
e90b62db JM |
11604 | } |
11605 | ||
fe7cd37f RH |
11606 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
11607 | add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list, | |
11608 | debug_line_section_label); | |
db3c0315 | 11609 | |
84a5b4f8 DB |
11610 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
11611 | add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label); | |
a96c67ec | 11612 | |
881c6935 JM |
11613 | /* Output all of the compilation units. We put the main one last so that |
11614 | the offsets are available to output_pubnames. */ | |
11615 | for (node = limbo_die_list; node; node = node->next) | |
11616 | output_comp_unit (node->die); | |
11617 | output_comp_unit (comp_unit_die); | |
11618 | ||
a3f97cbb | 11619 | /* Output the abbreviation table. */ |
9d2f2c45 | 11620 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ABBREV_SECTION); |
a3f97cbb JW |
11621 | output_abbrev_section (); |
11622 | ||
d291dd49 JM |
11623 | if (pubname_table_in_use) |
11624 | { | |
11625 | /* Output public names table. */ | |
9d2f2c45 | 11626 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION); |
d291dd49 JM |
11627 | output_pubnames (); |
11628 | } | |
11629 | ||
e689ae67 JM |
11630 | /* We only put functions in the arange table, so don't write it out if |
11631 | we don't have any. */ | |
a3f97cbb JW |
11632 | if (fde_table_in_use) |
11633 | { | |
a3f97cbb | 11634 | /* Output the address range information. */ |
9d2f2c45 | 11635 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ARANGES_SECTION); |
a3f97cbb JW |
11636 | output_aranges (); |
11637 | } | |
63e46568 DB |
11638 | /* Output location list section if necessary */ |
11639 | if (have_location_lists) | |
11640 | { | |
11641 | /* Output the location lists info. */ | |
9d2f2c45 | 11642 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LOC_SECTION); |
63e46568 DB |
11643 | output_location_lists (die); |
11644 | have_location_lists = 0; | |
11645 | } | |
cc260610 DB |
11646 | |
11647 | /* Have to end the primary source file. */ | |
11648 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) | |
11649 | { | |
11650 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION); | |
11651 | dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); | |
11652 | } | |
63e46568 | 11653 | |
a3f97cbb | 11654 | } |
9a666dda | 11655 | #endif /* DWARF2_DEBUGGING_INFO */ |