]>
Commit | Line | Data |
---|---|---|
a3f97cbb | 1 | /* Output Dwarf2 format symbol table information from the GNU C compiler. |
fa1610e9 | 2 | Copyright (C) 1992, 1993, 1995, 1996, 1997 Free Software Foundation, Inc. |
a3f97cbb JW |
3 | Contributed by Gary Funck (gary@intrepid.com). Derived from the |
4 | DWARF 1 implementation written by Ron Guilmette (rfg@monkeys.com). | |
469ac993 | 5 | Extensively modified by Jason Merrill (jason@cygnus.com). |
a3f97cbb JW |
6 | |
7 | This file is part of GNU CC. | |
8 | ||
9 | GNU CC is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 2, or (at your option) | |
12 | any later version. | |
13 | ||
14 | GNU CC is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with GNU CC; see the file COPYING. If not, write to | |
21 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
22 | ||
23 | #include "config.h" | |
a6ab3aad | 24 | #include "defaults.h" |
a3f97cbb | 25 | |
3f76745e JM |
26 | /* The first part of this file deals with the DWARF 2 frame unwind |
27 | information, which is also used by the GCC efficient exception handling | |
28 | mechanism. The second part, controlled only by an #ifdef | |
29 | DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging | |
30 | information. */ | |
31 | ||
a6ab3aad | 32 | #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) |
3f76745e | 33 | |
a3f97cbb | 34 | #include <stdio.h> |
469ac993 | 35 | #include <setjmp.h> |
a3f97cbb JW |
36 | #include "dwarf2.h" |
37 | #include "tree.h" | |
38 | #include "flags.h" | |
39 | #include "rtl.h" | |
40 | #include "hard-reg-set.h" | |
41 | #include "regs.h" | |
42 | #include "insn-config.h" | |
43 | #include "reload.h" | |
44 | #include "output.h" | |
71dfc51f | 45 | #include "expr.h" |
3f76745e | 46 | #include "except.h" |
a3f97cbb JW |
47 | |
48 | /* #define NDEBUG 1 */ | |
49 | #include "assert.h" | |
a3f97cbb | 50 | |
71dfc51f RK |
51 | #ifndef __GNUC__ |
52 | #define inline | |
a3f97cbb JW |
53 | #endif |
54 | ||
eaf95893 RK |
55 | /* How to start an assembler comment. */ |
56 | #ifndef ASM_COMMENT_START | |
57 | #define ASM_COMMENT_START ";#" | |
58 | #endif | |
59 | ||
a3f97cbb JW |
60 | typedef struct dw_cfi_struct *dw_cfi_ref; |
61 | typedef struct dw_fde_struct *dw_fde_ref; | |
62 | typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref; | |
a3f97cbb JW |
63 | |
64 | /* Call frames are described using a sequence of Call Frame | |
65 | Information instructions. The register number, offset | |
66 | and address fields are provided as possible operands; | |
67 | their use is selected by the opcode field. */ | |
71dfc51f | 68 | |
a3f97cbb | 69 | typedef union dw_cfi_oprnd_struct |
71dfc51f RK |
70 | { |
71 | unsigned long dw_cfi_reg_num; | |
72 | long int dw_cfi_offset; | |
73 | char *dw_cfi_addr; | |
74 | } | |
a3f97cbb JW |
75 | dw_cfi_oprnd; |
76 | ||
77 | typedef struct dw_cfi_struct | |
71dfc51f RK |
78 | { |
79 | dw_cfi_ref dw_cfi_next; | |
80 | enum dwarf_call_frame_info dw_cfi_opc; | |
81 | dw_cfi_oprnd dw_cfi_oprnd1; | |
82 | dw_cfi_oprnd dw_cfi_oprnd2; | |
83 | } | |
a3f97cbb JW |
84 | dw_cfi_node; |
85 | ||
86 | /* All call frame descriptions (FDE's) in the GCC generated DWARF | |
4b674448 | 87 | refer to a single Common Information Entry (CIE), defined at |
a3f97cbb JW |
88 | the beginning of the .debug_frame section. This used of a single |
89 | CIE obviates the need to keep track of multiple CIE's | |
90 | in the DWARF generation routines below. */ | |
71dfc51f | 91 | |
a3f97cbb | 92 | typedef struct dw_fde_struct |
71dfc51f | 93 | { |
71dfc51f RK |
94 | char *dw_fde_begin; |
95 | char *dw_fde_current_label; | |
96 | char *dw_fde_end; | |
97 | dw_cfi_ref dw_fde_cfi; | |
98 | } | |
a3f97cbb JW |
99 | dw_fde_node; |
100 | ||
a3f97cbb JW |
101 | /* Maximum size (in bytes) of an artificially generated label. */ |
102 | #define MAX_ARTIFICIAL_LABEL_BYTES 30 | |
103 | ||
104 | /* Make sure we know the sizes of the various types dwarf can describe. These | |
105 | are only defaults. If the sizes are different for your target, you should | |
106 | override these values by defining the appropriate symbols in your tm.h | |
107 | file. */ | |
71dfc51f | 108 | |
a3f97cbb JW |
109 | #ifndef CHAR_TYPE_SIZE |
110 | #define CHAR_TYPE_SIZE BITS_PER_UNIT | |
111 | #endif | |
a3f97cbb | 112 | #ifndef PTR_SIZE |
a9d38797 | 113 | #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT) |
a3f97cbb JW |
114 | #endif |
115 | ||
7e23cb16 JM |
116 | /* The size in bytes of a DWARF field indicating an offset or length |
117 | relative to a debug info section, specified to be 4 bytes in the DWARF-2 | |
118 | specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */ | |
71dfc51f | 119 | |
7e23cb16 JM |
120 | #ifndef DWARF_OFFSET_SIZE |
121 | #define DWARF_OFFSET_SIZE 4 | |
122 | #endif | |
123 | ||
9a666dda JM |
124 | #define DWARF_VERSION 2 |
125 | ||
7e23cb16 JM |
126 | /* Round SIZE up to the nearest BOUNDARY. */ |
127 | #define DWARF_ROUND(SIZE,BOUNDARY) \ | |
128 | (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1)) | |
a3f97cbb | 129 | |
a3f97cbb | 130 | /* Offsets recorded in opcodes are a multiple of this alignment factor. */ |
469ac993 JM |
131 | #ifdef STACK_GROWS_DOWNWARD |
132 | #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD) | |
133 | #else | |
134 | #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD | |
135 | #endif | |
a3f97cbb | 136 | |
3f76745e JM |
137 | /* A pointer to the base of a table that contains frame description |
138 | information for each routine. */ | |
139 | static dw_fde_ref fde_table; | |
a3f97cbb | 140 | |
3f76745e JM |
141 | /* Number of elements currently allocated for fde_table. */ |
142 | static unsigned fde_table_allocated; | |
a94dbf2c | 143 | |
3f76745e JM |
144 | /* Number of elements in fde_table currently in use. */ |
145 | static unsigned fde_table_in_use; | |
a3f97cbb | 146 | |
3f76745e JM |
147 | /* Size (in elements) of increments by which we may expand the |
148 | fde_table. */ | |
149 | #define FDE_TABLE_INCREMENT 256 | |
a3f97cbb | 150 | |
a94dbf2c JM |
151 | /* A list of call frame insns for the CIE. */ |
152 | static dw_cfi_ref cie_cfi_head; | |
153 | ||
a3f97cbb JW |
154 | /* The number of the current function definition for which debugging |
155 | information is being generated. These numbers range from 1 up to the | |
156 | maximum number of function definitions contained within the current | |
157 | compilation unit. These numbers are used to create unique label id's | |
158 | unique to each function definition. */ | |
4f988ea2 | 159 | static unsigned current_funcdef_number = 0; |
a3f97cbb JW |
160 | |
161 | /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram | |
162 | attribute that accelerates the lookup of the FDE associated | |
163 | with the subprogram. This variable holds the table index of the FDE | |
164 | associated with the current function (body) definition. */ | |
165 | static unsigned current_funcdef_fde; | |
166 | ||
a3f97cbb | 167 | /* Forward declarations for functions defined in this file. */ |
71dfc51f RK |
168 | |
169 | static char *stripattributes PROTO((char *)); | |
3f76745e JM |
170 | static char *dwarf_cfi_name PROTO((unsigned)); |
171 | static dw_cfi_ref new_cfi PROTO((void)); | |
172 | static void add_cfi PROTO((dw_cfi_ref *, dw_cfi_ref)); | |
71dfc51f RK |
173 | static unsigned long size_of_uleb128 PROTO((unsigned long)); |
174 | static unsigned long size_of_sleb128 PROTO((long)); | |
71dfc51f RK |
175 | static void output_uleb128 PROTO((unsigned long)); |
176 | static void output_sleb128 PROTO((long)); | |
c53aa195 | 177 | char *dwarf2out_cfi_label PROTO((void)); |
71dfc51f RK |
178 | static void add_fde_cfi PROTO((char *, dw_cfi_ref)); |
179 | static void lookup_cfa_1 PROTO((dw_cfi_ref, unsigned long *, | |
180 | long *)); | |
181 | static void lookup_cfa PROTO((unsigned long *, long *)); | |
182 | static void reg_save PROTO((char *, unsigned, unsigned, | |
183 | long)); | |
184 | static void initial_return_save PROTO((rtx)); | |
71dfc51f | 185 | static void output_cfi PROTO((dw_cfi_ref, dw_fde_ref)); |
3f76745e | 186 | static void output_call_frame_info PROTO((int)); |
71dfc51f | 187 | static unsigned reg_number PROTO((rtx)); |
a3f97cbb JW |
188 | |
189 | /* Definitions of defaults for assembler-dependent names of various | |
190 | pseudo-ops and section names. | |
191 | Theses may be overridden in the tm.h file (if necessary) for a particular | |
192 | assembler. */ | |
71dfc51f | 193 | |
a3f97cbb JW |
194 | #ifndef UNALIGNED_SHORT_ASM_OP |
195 | #define UNALIGNED_SHORT_ASM_OP ".2byte" | |
196 | #endif | |
197 | #ifndef UNALIGNED_INT_ASM_OP | |
198 | #define UNALIGNED_INT_ASM_OP ".4byte" | |
199 | #endif | |
7e23cb16 JM |
200 | #ifndef UNALIGNED_DOUBLE_INT_ASM_OP |
201 | #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte" | |
202 | #endif | |
a3f97cbb JW |
203 | #ifndef ASM_BYTE_OP |
204 | #define ASM_BYTE_OP ".byte" | |
205 | #endif | |
206 | ||
7e23cb16 JM |
207 | #ifndef UNALIGNED_OFFSET_ASM_OP |
208 | #define UNALIGNED_OFFSET_ASM_OP \ | |
209 | (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP) | |
210 | #endif | |
211 | ||
212 | #ifndef UNALIGNED_WORD_ASM_OP | |
213 | #define UNALIGNED_WORD_ASM_OP \ | |
214 | (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP) | |
215 | #endif | |
216 | ||
217 | /* Data and reference forms for relocatable data. */ | |
218 | #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4) | |
219 | #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4) | |
220 | ||
a3f97cbb JW |
221 | /* Pseudo-op for defining a new section. */ |
222 | #ifndef SECTION_ASM_OP | |
223 | #define SECTION_ASM_OP ".section" | |
224 | #endif | |
225 | ||
226 | /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to | |
227 | print the SECTION_ASM_OP and the section name. The default here works for | |
228 | almost all svr4 assemblers, except for the sparc, where the section name | |
229 | must be enclosed in double quotes. (See sparcv4.h). */ | |
230 | #ifndef SECTION_FORMAT | |
c53aa195 JM |
231 | #ifdef PUSHSECTION_FORMAT |
232 | #define SECTION_FORMAT PUSHSECTION_FORMAT | |
233 | #else | |
234 | #define SECTION_FORMAT "\t%s\t%s\n" | |
235 | #endif | |
a3f97cbb JW |
236 | #endif |
237 | ||
a3f97cbb JW |
238 | #ifndef FRAME_SECTION |
239 | #define FRAME_SECTION ".debug_frame" | |
240 | #endif | |
3f76745e JM |
241 | #if !defined (EH_FRAME_SECTION) && defined (ASM_OUTPUT_SECTION_NAME) |
242 | #define EH_FRAME_SECTION ".eh_frame" | |
a3f97cbb JW |
243 | #endif |
244 | ||
5c90448c JM |
245 | #ifndef FUNC_BEGIN_LABEL |
246 | #define FUNC_BEGIN_LABEL "LFB" | |
a3f97cbb | 247 | #endif |
5c90448c JM |
248 | #ifndef FUNC_END_LABEL |
249 | #define FUNC_END_LABEL "LFE" | |
a3f97cbb | 250 | #endif |
a6ab3aad JM |
251 | #define CIE_AFTER_SIZE_LABEL "LSCIE" |
252 | #define CIE_END_LABEL "LECIE" | |
253 | #define FDE_AFTER_SIZE_LABEL "LSFDE" | |
254 | #define FDE_END_LABEL "LEFDE" | |
a3f97cbb | 255 | |
a3f97cbb JW |
256 | /* Definitions of defaults for various types of primitive assembly language |
257 | output operations. These may be overridden from within the tm.h file, | |
258 | but typically, that is unecessary. */ | |
71dfc51f | 259 | |
a3f97cbb JW |
260 | #ifndef ASM_OUTPUT_SECTION |
261 | #define ASM_OUTPUT_SECTION(FILE, SECTION) \ | |
262 | fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION) | |
263 | #endif | |
264 | ||
265 | #ifndef ASM_OUTPUT_DWARF_DELTA2 | |
266 | #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \ | |
267 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \ | |
268 | assemble_name (FILE, LABEL1); \ | |
269 | fprintf (FILE, "-"); \ | |
270 | assemble_name (FILE, LABEL2); \ | |
271 | } while (0) | |
272 | #endif | |
273 | ||
274 | #ifndef ASM_OUTPUT_DWARF_DELTA4 | |
275 | #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \ | |
276 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ | |
277 | assemble_name (FILE, LABEL1); \ | |
278 | fprintf (FILE, "-"); \ | |
279 | assemble_name (FILE, LABEL2); \ | |
280 | } while (0) | |
281 | #endif | |
282 | ||
7e23cb16 JM |
283 | #ifndef ASM_OUTPUT_DWARF_DELTA |
284 | #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \ | |
285 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \ | |
286 | assemble_name (FILE, LABEL1); \ | |
287 | fprintf (FILE, "-"); \ | |
288 | assemble_name (FILE, LABEL2); \ | |
289 | } while (0) | |
290 | #endif | |
291 | ||
292 | #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA | |
293 | #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \ | |
294 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \ | |
295 | assemble_name (FILE, LABEL1); \ | |
296 | fprintf (FILE, "-"); \ | |
297 | assemble_name (FILE, LABEL2); \ | |
298 | } while (0) | |
299 | #endif | |
300 | ||
a3f97cbb JW |
301 | #ifndef ASM_OUTPUT_DWARF_ADDR |
302 | #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \ | |
7e23cb16 | 303 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \ |
a3f97cbb JW |
304 | assemble_name (FILE, LABEL); \ |
305 | } while (0) | |
306 | #endif | |
307 | ||
308 | #ifndef ASM_OUTPUT_DWARF_ADDR_CONST | |
309 | #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \ | |
7e23cb16 JM |
310 | fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR)) |
311 | #endif | |
312 | ||
313 | #ifndef ASM_OUTPUT_DWARF_OFFSET | |
314 | #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \ | |
315 | do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \ | |
316 | assemble_name (FILE, LABEL); \ | |
317 | } while (0) | |
a3f97cbb JW |
318 | #endif |
319 | ||
320 | #ifndef ASM_OUTPUT_DWARF_DATA1 | |
321 | #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \ | |
322 | fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, VALUE) | |
323 | #endif | |
324 | ||
325 | #ifndef ASM_OUTPUT_DWARF_DATA2 | |
326 | #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \ | |
327 | fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE) | |
328 | #endif | |
329 | ||
330 | #ifndef ASM_OUTPUT_DWARF_DATA4 | |
331 | #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \ | |
332 | fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) VALUE) | |
333 | #endif | |
334 | ||
7e23cb16 JM |
335 | #ifndef ASM_OUTPUT_DWARF_DATA |
336 | #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \ | |
337 | fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \ | |
338 | (unsigned long) VALUE) | |
339 | #endif | |
340 | ||
341 | #ifndef ASM_OUTPUT_DWARF_ADDR_DATA | |
342 | #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \ | |
343 | fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \ | |
344 | (unsigned long) VALUE) | |
345 | #endif | |
346 | ||
a3f97cbb JW |
347 | #ifndef ASM_OUTPUT_DWARF_DATA8 |
348 | #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \ | |
349 | do { \ | |
350 | if (WORDS_BIG_ENDIAN) \ | |
351 | { \ | |
352 | fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \ | |
353 | fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, LOW_VALUE);\ | |
354 | } \ | |
355 | else \ | |
356 | { \ | |
357 | fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\ | |
358 | fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \ | |
359 | } \ | |
360 | } while (0) | |
361 | #endif | |
362 | ||
a6ab3aad JM |
363 | /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing |
364 | newline is produced. When flag_verbose_asm is asserted, we add commnetary | |
365 | at the end of the line, so we must avoid output of a newline here. */ | |
366 | #ifndef ASM_OUTPUT_DWARF_STRING | |
367 | #define ASM_OUTPUT_DWARF_STRING(FILE,P) \ | |
368 | do { \ | |
369 | register int slen = strlen(P); \ | |
370 | register char *p = (P); \ | |
371 | register int i; \ | |
372 | fprintf (FILE, "\t.ascii \""); \ | |
373 | for (i = 0; i < slen; i++) \ | |
374 | { \ | |
375 | register int c = p[i]; \ | |
376 | if (c == '\"' || c == '\\') \ | |
377 | putc ('\\', FILE); \ | |
378 | if (c >= ' ' && c < 0177) \ | |
379 | putc (c, FILE); \ | |
380 | else \ | |
381 | { \ | |
382 | fprintf (FILE, "\\%o", c); \ | |
383 | } \ | |
384 | } \ | |
385 | fprintf (FILE, "\\0\""); \ | |
386 | } \ | |
387 | while (0) | |
388 | #endif | |
389 | ||
c8cc5c4a | 390 | /* The DWARF 2 CFA column which tracks the return address. Normally this |
a94dbf2c JM |
391 | is the column for PC, or the first column after all of the hard |
392 | registers. */ | |
c8cc5c4a | 393 | #ifndef DWARF_FRAME_RETURN_COLUMN |
a94dbf2c JM |
394 | #ifdef PC_REGNUM |
395 | #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM) | |
396 | #else | |
466446b0 | 397 | #define DWARF_FRAME_RETURN_COLUMN FIRST_PSEUDO_REGISTER |
a94dbf2c | 398 | #endif |
c8cc5c4a JM |
399 | #endif |
400 | ||
401 | /* The mapping from gcc register number to DWARF 2 CFA column number. By | |
469ac993 | 402 | default, we just provide columns for all registers. */ |
c8cc5c4a | 403 | #ifndef DWARF_FRAME_REGNUM |
469ac993 | 404 | #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG) |
c8cc5c4a | 405 | #endif |
3f76745e | 406 | |
a6ab3aad JM |
407 | /* The offset from the incoming value of %sp to the top of the stack frame |
408 | for the current function. */ | |
409 | #ifndef INCOMING_FRAME_SP_OFFSET | |
410 | #define INCOMING_FRAME_SP_OFFSET 0 | |
411 | #endif | |
412 | ||
71dfc51f | 413 | /* Return a pointer to a copy of the section string name S with all |
a3f97cbb | 414 | attributes stripped off. */ |
71dfc51f RK |
415 | |
416 | static inline char * | |
a3f97cbb | 417 | stripattributes (s) |
71dfc51f | 418 | char *s; |
a3f97cbb | 419 | { |
71dfc51f RK |
420 | char *stripped = xstrdup (s); |
421 | char *p = stripped; | |
422 | ||
a3f97cbb JW |
423 | while (*p && *p != ',') |
424 | p++; | |
71dfc51f | 425 | |
a3f97cbb JW |
426 | *p = '\0'; |
427 | return stripped; | |
428 | } | |
429 | ||
3f76745e | 430 | /* Return the register number described by a given RTL node. */ |
71dfc51f | 431 | |
3f76745e JM |
432 | static unsigned |
433 | reg_number (rtl) | |
434 | register rtx rtl; | |
a3f97cbb | 435 | { |
3f76745e | 436 | register unsigned regno = REGNO (rtl); |
a3f97cbb | 437 | |
3f76745e | 438 | if (regno >= FIRST_PSEUDO_REGISTER) |
a3f97cbb | 439 | { |
3f76745e JM |
440 | warning ("internal regno botch: regno = %d\n", regno); |
441 | regno = 0; | |
442 | } | |
a3f97cbb | 443 | |
3f76745e JM |
444 | regno = DBX_REGISTER_NUMBER (regno); |
445 | return regno; | |
446 | } | |
a3f97cbb | 447 | |
3f76745e | 448 | /* Convert a DWARF call frame info. operation to its string name */ |
a3f97cbb | 449 | |
3f76745e JM |
450 | static char * |
451 | dwarf_cfi_name (cfi_opc) | |
452 | register unsigned cfi_opc; | |
453 | { | |
454 | switch (cfi_opc) | |
455 | { | |
456 | case DW_CFA_advance_loc: | |
457 | return "DW_CFA_advance_loc"; | |
458 | case DW_CFA_offset: | |
459 | return "DW_CFA_offset"; | |
460 | case DW_CFA_restore: | |
461 | return "DW_CFA_restore"; | |
462 | case DW_CFA_nop: | |
463 | return "DW_CFA_nop"; | |
464 | case DW_CFA_set_loc: | |
465 | return "DW_CFA_set_loc"; | |
466 | case DW_CFA_advance_loc1: | |
467 | return "DW_CFA_advance_loc1"; | |
468 | case DW_CFA_advance_loc2: | |
469 | return "DW_CFA_advance_loc2"; | |
470 | case DW_CFA_advance_loc4: | |
471 | return "DW_CFA_advance_loc4"; | |
472 | case DW_CFA_offset_extended: | |
473 | return "DW_CFA_offset_extended"; | |
474 | case DW_CFA_restore_extended: | |
475 | return "DW_CFA_restore_extended"; | |
476 | case DW_CFA_undefined: | |
477 | return "DW_CFA_undefined"; | |
478 | case DW_CFA_same_value: | |
479 | return "DW_CFA_same_value"; | |
480 | case DW_CFA_register: | |
481 | return "DW_CFA_register"; | |
482 | case DW_CFA_remember_state: | |
483 | return "DW_CFA_remember_state"; | |
484 | case DW_CFA_restore_state: | |
485 | return "DW_CFA_restore_state"; | |
486 | case DW_CFA_def_cfa: | |
487 | return "DW_CFA_def_cfa"; | |
488 | case DW_CFA_def_cfa_register: | |
489 | return "DW_CFA_def_cfa_register"; | |
490 | case DW_CFA_def_cfa_offset: | |
491 | return "DW_CFA_def_cfa_offset"; | |
c53aa195 | 492 | |
3f76745e JM |
493 | /* SGI/MIPS specific */ |
494 | case DW_CFA_MIPS_advance_loc8: | |
495 | return "DW_CFA_MIPS_advance_loc8"; | |
c53aa195 JM |
496 | |
497 | /* GNU extensions */ | |
498 | case DW_CFA_GNU_window_save: | |
499 | return "DW_CFA_GNU_window_save"; | |
500 | ||
3f76745e JM |
501 | default: |
502 | return "DW_CFA_<unknown>"; | |
503 | } | |
504 | } | |
a3f97cbb | 505 | |
3f76745e | 506 | /* Return a pointer to a newly allocated Call Frame Instruction. */ |
71dfc51f | 507 | |
3f76745e JM |
508 | static inline dw_cfi_ref |
509 | new_cfi () | |
510 | { | |
511 | register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node)); | |
71dfc51f | 512 | |
3f76745e JM |
513 | cfi->dw_cfi_next = NULL; |
514 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0; | |
515 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0; | |
a3f97cbb | 516 | |
3f76745e JM |
517 | return cfi; |
518 | } | |
a3f97cbb | 519 | |
3f76745e | 520 | /* Add a Call Frame Instruction to list of instructions. */ |
a3f97cbb | 521 | |
3f76745e JM |
522 | static inline void |
523 | add_cfi (list_head, cfi) | |
524 | register dw_cfi_ref *list_head; | |
525 | register dw_cfi_ref cfi; | |
526 | { | |
527 | register dw_cfi_ref *p; | |
a3f97cbb | 528 | |
3f76745e JM |
529 | /* Find the end of the chain. */ |
530 | for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next) | |
531 | ; | |
532 | ||
533 | *p = cfi; | |
a3f97cbb JW |
534 | } |
535 | ||
3f76745e | 536 | /* Generate a new label for the CFI info to refer to. */ |
71dfc51f | 537 | |
c53aa195 | 538 | char * |
3f76745e | 539 | dwarf2out_cfi_label () |
a3f97cbb | 540 | { |
3f76745e JM |
541 | static char label[20]; |
542 | static unsigned long label_num = 0; | |
543 | ||
544 | ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++); | |
545 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
546 | ||
547 | return label; | |
a3f97cbb JW |
548 | } |
549 | ||
3f76745e JM |
550 | /* Add CFI to the current fde at the PC value indicated by LABEL if specified, |
551 | or to the CIE if LABEL is NULL. */ | |
71dfc51f | 552 | |
3f76745e JM |
553 | static void |
554 | add_fde_cfi (label, cfi) | |
555 | register char *label; | |
556 | register dw_cfi_ref cfi; | |
a3f97cbb | 557 | { |
3f76745e JM |
558 | if (label) |
559 | { | |
560 | register dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; | |
a3f97cbb | 561 | |
3f76745e JM |
562 | if (*label == 0) |
563 | label = dwarf2out_cfi_label (); | |
71dfc51f | 564 | |
3f76745e JM |
565 | if (fde->dw_fde_current_label == NULL |
566 | || strcmp (label, fde->dw_fde_current_label) != 0) | |
567 | { | |
568 | register dw_cfi_ref xcfi; | |
a3f97cbb | 569 | |
3f76745e | 570 | fde->dw_fde_current_label = label = xstrdup (label); |
71dfc51f | 571 | |
3f76745e JM |
572 | /* Set the location counter to the new label. */ |
573 | xcfi = new_cfi (); | |
574 | xcfi->dw_cfi_opc = DW_CFA_advance_loc4; | |
575 | xcfi->dw_cfi_oprnd1.dw_cfi_addr = label; | |
576 | add_cfi (&fde->dw_fde_cfi, xcfi); | |
577 | } | |
71dfc51f | 578 | |
3f76745e JM |
579 | add_cfi (&fde->dw_fde_cfi, cfi); |
580 | } | |
581 | ||
582 | else | |
583 | add_cfi (&cie_cfi_head, cfi); | |
a3f97cbb JW |
584 | } |
585 | ||
3f76745e | 586 | /* Subroutine of lookup_cfa. */ |
71dfc51f | 587 | |
3f76745e JM |
588 | static inline void |
589 | lookup_cfa_1 (cfi, regp, offsetp) | |
590 | register dw_cfi_ref cfi; | |
591 | register unsigned long *regp; | |
592 | register long *offsetp; | |
a3f97cbb | 593 | { |
3f76745e JM |
594 | switch (cfi->dw_cfi_opc) |
595 | { | |
596 | case DW_CFA_def_cfa_offset: | |
597 | *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset; | |
598 | break; | |
599 | case DW_CFA_def_cfa_register: | |
600 | *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; | |
601 | break; | |
602 | case DW_CFA_def_cfa: | |
603 | *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; | |
604 | *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset; | |
605 | break; | |
606 | } | |
a3f97cbb JW |
607 | } |
608 | ||
3f76745e | 609 | /* Find the previous value for the CFA. */ |
71dfc51f | 610 | |
3f76745e JM |
611 | static void |
612 | lookup_cfa (regp, offsetp) | |
613 | register unsigned long *regp; | |
614 | register long *offsetp; | |
a3f97cbb | 615 | { |
3f76745e JM |
616 | register dw_cfi_ref cfi; |
617 | ||
618 | *regp = (unsigned long) -1; | |
619 | *offsetp = 0; | |
620 | ||
621 | for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next) | |
622 | lookup_cfa_1 (cfi, regp, offsetp); | |
623 | ||
624 | if (fde_table_in_use) | |
a3f97cbb | 625 | { |
3f76745e JM |
626 | register dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; |
627 | for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next) | |
628 | lookup_cfa_1 (cfi, regp, offsetp); | |
a3f97cbb JW |
629 | } |
630 | } | |
631 | ||
3f76745e | 632 | /* The current rule for calculating the DWARF2 canonical frame address. */ |
a6ab3aad | 633 | static unsigned long cfa_reg; |
3f76745e | 634 | static long cfa_offset; |
71dfc51f | 635 | |
3f76745e JM |
636 | /* The register used for saving registers to the stack, and its offset |
637 | from the CFA. */ | |
638 | static unsigned cfa_store_reg; | |
639 | static long cfa_store_offset; | |
640 | ||
641 | /* Entry point to update the canonical frame address (CFA). | |
642 | LABEL is passed to add_fde_cfi. The value of CFA is now to be | |
643 | calculated from REG+OFFSET. */ | |
644 | ||
645 | void | |
646 | dwarf2out_def_cfa (label, reg, offset) | |
647 | register char *label; | |
648 | register unsigned reg; | |
649 | register long offset; | |
a3f97cbb | 650 | { |
3f76745e JM |
651 | register dw_cfi_ref cfi; |
652 | unsigned long old_reg; | |
653 | long old_offset; | |
654 | ||
5bef9b1f JM |
655 | cfa_reg = reg; |
656 | cfa_offset = offset; | |
657 | if (cfa_store_reg == reg) | |
658 | cfa_store_offset = offset; | |
659 | ||
3f76745e JM |
660 | reg = DWARF_FRAME_REGNUM (reg); |
661 | lookup_cfa (&old_reg, &old_offset); | |
662 | ||
663 | if (reg == old_reg && offset == old_offset) | |
664 | return; | |
665 | ||
666 | cfi = new_cfi (); | |
667 | ||
668 | if (reg == old_reg) | |
a3f97cbb | 669 | { |
3f76745e JM |
670 | cfi->dw_cfi_opc = DW_CFA_def_cfa_offset; |
671 | cfi->dw_cfi_oprnd1.dw_cfi_offset = offset; | |
672 | } | |
a3f97cbb | 673 | |
3f76745e JM |
674 | #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */ |
675 | else if (offset == old_offset && old_reg != (unsigned long) -1) | |
676 | { | |
677 | cfi->dw_cfi_opc = DW_CFA_def_cfa_register; | |
678 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
679 | } | |
680 | #endif | |
a3f97cbb | 681 | |
3f76745e JM |
682 | else |
683 | { | |
684 | cfi->dw_cfi_opc = DW_CFA_def_cfa; | |
685 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
686 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; | |
a3f97cbb | 687 | } |
3f76745e JM |
688 | |
689 | add_fde_cfi (label, cfi); | |
a3f97cbb JW |
690 | } |
691 | ||
3f76745e JM |
692 | /* Add the CFI for saving a register. REG is the CFA column number. |
693 | LABEL is passed to add_fde_cfi. | |
694 | If SREG is -1, the register is saved at OFFSET from the CFA; | |
695 | otherwise it is saved in SREG. */ | |
71dfc51f | 696 | |
3f76745e JM |
697 | static void |
698 | reg_save (label, reg, sreg, offset) | |
699 | register char * label; | |
700 | register unsigned reg; | |
701 | register unsigned sreg; | |
702 | register long offset; | |
a3f97cbb | 703 | { |
3f76745e JM |
704 | register dw_cfi_ref cfi = new_cfi (); |
705 | ||
706 | cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; | |
707 | ||
708 | if (sreg == -1) | |
a3f97cbb | 709 | { |
3f76745e JM |
710 | if (reg & ~0x3f) |
711 | /* The register number won't fit in 6 bits, so we have to use | |
712 | the long form. */ | |
713 | cfi->dw_cfi_opc = DW_CFA_offset_extended; | |
714 | else | |
715 | cfi->dw_cfi_opc = DW_CFA_offset; | |
716 | ||
717 | offset /= DWARF_CIE_DATA_ALIGNMENT; | |
718 | assert (offset >= 0); | |
719 | cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; | |
720 | } | |
721 | else | |
722 | { | |
723 | cfi->dw_cfi_opc = DW_CFA_register; | |
724 | cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg; | |
725 | } | |
726 | ||
727 | add_fde_cfi (label, cfi); | |
728 | } | |
729 | ||
c53aa195 JM |
730 | /* Add the CFI for saving a register window. LABEL is passed to reg_save. |
731 | This CFI tells the unwinder that it needs to restore the window registers | |
732 | from the previous frame's window save area. | |
733 | ||
734 | ??? Perhaps we should note in the CIE where windows are saved (instead of | |
735 | assuming 0(cfa)) and what registers are in the window. */ | |
736 | ||
737 | void | |
738 | dwarf2out_window_save (label) | |
739 | register char * label; | |
740 | { | |
741 | register dw_cfi_ref cfi = new_cfi (); | |
742 | cfi->dw_cfi_opc = DW_CFA_GNU_window_save; | |
743 | add_fde_cfi (label, cfi); | |
744 | } | |
745 | ||
746 | /* Entry point for saving a register to the stack. REG is the GCC register | |
747 | number. LABEL and OFFSET are passed to reg_save. */ | |
3f76745e JM |
748 | |
749 | void | |
750 | dwarf2out_reg_save (label, reg, offset) | |
751 | register char * label; | |
752 | register unsigned reg; | |
753 | register long offset; | |
754 | { | |
755 | reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset); | |
756 | } | |
757 | ||
c53aa195 JM |
758 | /* Entry point for saving the return address in the stack. |
759 | LABEL and OFFSET are passed to reg_save. */ | |
760 | ||
761 | void | |
762 | dwarf2out_return_save (label, offset) | |
763 | register char * label; | |
764 | register long offset; | |
765 | { | |
766 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset); | |
767 | } | |
768 | ||
769 | /* Entry point for saving the return address in a register. | |
770 | LABEL and SREG are passed to reg_save. */ | |
771 | ||
772 | void | |
773 | dwarf2out_return_reg (label, sreg) | |
774 | register char * label; | |
775 | register unsigned sreg; | |
776 | { | |
777 | reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0); | |
778 | } | |
779 | ||
3f76745e JM |
780 | /* Record the initial position of the return address. RTL is |
781 | INCOMING_RETURN_ADDR_RTX. */ | |
782 | ||
783 | static void | |
784 | initial_return_save (rtl) | |
785 | register rtx rtl; | |
786 | { | |
787 | unsigned reg = -1; | |
788 | long offset = 0; | |
789 | ||
790 | switch (GET_CODE (rtl)) | |
791 | { | |
792 | case REG: | |
793 | /* RA is in a register. */ | |
794 | reg = reg_number (rtl); | |
795 | break; | |
796 | case MEM: | |
797 | /* RA is on the stack. */ | |
798 | rtl = XEXP (rtl, 0); | |
799 | switch (GET_CODE (rtl)) | |
800 | { | |
801 | case REG: | |
802 | assert (REGNO (rtl) == STACK_POINTER_REGNUM); | |
803 | offset = 0; | |
804 | break; | |
805 | case PLUS: | |
806 | assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM); | |
807 | offset = INTVAL (XEXP (rtl, 1)); | |
808 | break; | |
809 | case MINUS: | |
810 | assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM); | |
811 | offset = -INTVAL (XEXP (rtl, 1)); | |
812 | break; | |
813 | default: | |
814 | abort (); | |
815 | } | |
816 | break; | |
c53aa195 JM |
817 | case PLUS: |
818 | /* The return address is at some offset from any value we can | |
819 | actually load. For instance, on the SPARC it is in %i7+8. Just | |
820 | ignore the offset for now; it doesn't matter for unwinding frames. */ | |
821 | assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT); | |
822 | initial_return_save (XEXP (rtl, 0)); | |
823 | return; | |
a3f97cbb | 824 | default: |
3f76745e | 825 | abort (); |
a3f97cbb | 826 | } |
3f76745e | 827 | |
a6ab3aad | 828 | reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa_offset); |
a3f97cbb JW |
829 | } |
830 | ||
3f76745e JM |
831 | /* Record call frame debugging information for INSN, which either |
832 | sets SP or FP (adjusting how we calculate the frame address) or saves a | |
833 | register to the stack. If INSN is NULL_RTX, initialize our state. */ | |
71dfc51f | 834 | |
3f76745e JM |
835 | void |
836 | dwarf2out_frame_debug (insn) | |
837 | rtx insn; | |
a3f97cbb | 838 | { |
3f76745e JM |
839 | char *label; |
840 | rtx src, dest; | |
841 | long offset; | |
842 | ||
843 | /* A temporary register used in adjusting SP or setting up the store_reg. */ | |
844 | static unsigned cfa_temp_reg; | |
845 | static long cfa_temp_value; | |
846 | ||
847 | if (insn == NULL_RTX) | |
a3f97cbb | 848 | { |
3f76745e | 849 | /* Set up state for generating call frame debug info. */ |
a6ab3aad JM |
850 | lookup_cfa (&cfa_reg, &cfa_offset); |
851 | assert (cfa_reg == DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)); | |
3f76745e | 852 | cfa_reg = STACK_POINTER_REGNUM; |
a6ab3aad JM |
853 | cfa_store_reg = cfa_reg; |
854 | cfa_store_offset = cfa_offset; | |
3f76745e JM |
855 | cfa_temp_reg = -1; |
856 | cfa_temp_value = 0; | |
857 | return; | |
858 | } | |
859 | ||
860 | label = dwarf2out_cfi_label (); | |
861 | ||
862 | insn = PATTERN (insn); | |
863 | assert (GET_CODE (insn) == SET); | |
864 | ||
865 | src = SET_SRC (insn); | |
866 | dest = SET_DEST (insn); | |
867 | ||
868 | switch (GET_CODE (dest)) | |
869 | { | |
870 | case REG: | |
871 | /* Update the CFA rule wrt SP or FP. Make sure src is | |
872 | relative to the current CFA register. */ | |
873 | switch (GET_CODE (src)) | |
874 | { | |
875 | /* Setting FP from SP. */ | |
876 | case REG: | |
877 | assert (cfa_reg == REGNO (src)); | |
878 | assert (REGNO (dest) == STACK_POINTER_REGNUM | |
879 | || (frame_pointer_needed | |
880 | && REGNO (dest) == HARD_FRAME_POINTER_REGNUM)); | |
881 | cfa_reg = REGNO (dest); | |
882 | break; | |
883 | ||
884 | case PLUS: | |
885 | case MINUS: | |
886 | if (dest == stack_pointer_rtx) | |
887 | { | |
888 | /* Adjusting SP. */ | |
889 | switch (GET_CODE (XEXP (src, 1))) | |
890 | { | |
891 | case CONST_INT: | |
892 | offset = INTVAL (XEXP (src, 1)); | |
893 | break; | |
894 | case REG: | |
895 | assert (REGNO (XEXP (src, 1)) == cfa_temp_reg); | |
896 | offset = cfa_temp_value; | |
897 | break; | |
898 | default: | |
899 | abort (); | |
900 | } | |
901 | ||
902 | if (GET_CODE (src) == PLUS) | |
903 | offset = -offset; | |
904 | if (cfa_reg == STACK_POINTER_REGNUM) | |
905 | cfa_offset += offset; | |
906 | if (cfa_store_reg == STACK_POINTER_REGNUM) | |
907 | cfa_store_offset += offset; | |
908 | assert (XEXP (src, 0) == stack_pointer_rtx); | |
909 | } | |
910 | else | |
911 | { | |
912 | /* Initializing the store base register. */ | |
913 | assert (GET_CODE (src) == PLUS); | |
914 | assert (XEXP (src, 1) == stack_pointer_rtx); | |
915 | assert (GET_CODE (XEXP (src, 0)) == REG | |
916 | && REGNO (XEXP (src, 0)) == cfa_temp_reg); | |
917 | assert (cfa_store_reg == STACK_POINTER_REGNUM); | |
918 | cfa_store_reg = REGNO (dest); | |
919 | cfa_store_offset -= cfa_temp_value; | |
920 | } | |
921 | break; | |
922 | ||
923 | case CONST_INT: | |
924 | cfa_temp_reg = REGNO (dest); | |
925 | cfa_temp_value = INTVAL (src); | |
926 | break; | |
927 | ||
ef76d03b JW |
928 | case IOR: |
929 | assert (GET_CODE (XEXP (src, 0)) == REG | |
930 | && REGNO (XEXP (src, 0)) == cfa_temp_reg); | |
931 | assert (REGNO (dest) == cfa_temp_reg); | |
932 | assert (GET_CODE (XEXP (src, 1)) == CONST_INT); | |
933 | cfa_temp_value |= INTVAL (XEXP (src, 1)); | |
934 | break; | |
935 | ||
3f76745e JM |
936 | default: |
937 | abort (); | |
938 | } | |
939 | dwarf2out_def_cfa (label, cfa_reg, cfa_offset); | |
940 | break; | |
941 | ||
942 | case MEM: | |
943 | /* Saving a register to the stack. Make sure dest is relative to the | |
944 | CFA register. */ | |
945 | assert (GET_CODE (src) == REG); | |
946 | switch (GET_CODE (XEXP (dest, 0))) | |
947 | { | |
948 | /* With a push. */ | |
949 | case PRE_INC: | |
950 | case PRE_DEC: | |
951 | offset = GET_MODE_SIZE (GET_MODE (dest)); | |
952 | if (GET_CODE (src) == PRE_INC) | |
953 | offset = -offset; | |
954 | ||
955 | assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM); | |
956 | assert (cfa_store_reg == STACK_POINTER_REGNUM); | |
957 | cfa_store_offset += offset; | |
958 | if (cfa_reg == STACK_POINTER_REGNUM) | |
959 | cfa_offset = cfa_store_offset; | |
960 | ||
961 | offset = -cfa_store_offset; | |
962 | break; | |
963 | ||
964 | /* With an offset. */ | |
965 | case PLUS: | |
966 | case MINUS: | |
967 | offset = INTVAL (XEXP (XEXP (dest, 0), 1)); | |
968 | if (GET_CODE (src) == MINUS) | |
969 | offset = -offset; | |
970 | ||
971 | assert (cfa_store_reg == REGNO (XEXP (XEXP (dest, 0), 0))); | |
972 | offset -= cfa_store_offset; | |
973 | break; | |
974 | ||
975 | default: | |
976 | abort (); | |
977 | } | |
978 | dwarf2out_def_cfa (label, cfa_reg, cfa_offset); | |
979 | dwarf2out_reg_save (label, REGNO (src), offset); | |
980 | break; | |
981 | ||
982 | default: | |
983 | abort (); | |
984 | } | |
985 | } | |
986 | ||
987 | /* Return the size of an unsigned LEB128 quantity. */ | |
988 | ||
989 | static inline unsigned long | |
990 | size_of_uleb128 (value) | |
991 | register unsigned long value; | |
992 | { | |
993 | register unsigned long size = 0; | |
994 | register unsigned byte; | |
995 | ||
996 | do | |
997 | { | |
998 | byte = (value & 0x7f); | |
999 | value >>= 7; | |
1000 | size += 1; | |
1001 | } | |
1002 | while (value != 0); | |
1003 | ||
1004 | return size; | |
1005 | } | |
1006 | ||
1007 | /* Return the size of a signed LEB128 quantity. */ | |
1008 | ||
1009 | static inline unsigned long | |
1010 | size_of_sleb128 (value) | |
1011 | register long value; | |
1012 | { | |
1013 | register unsigned long size = 0; | |
1014 | register unsigned byte; | |
1015 | ||
1016 | do | |
1017 | { | |
1018 | byte = (value & 0x7f); | |
1019 | value >>= 7; | |
1020 | size += 1; | |
1021 | } | |
1022 | while (!(((value == 0) && ((byte & 0x40) == 0)) | |
1023 | || ((value == -1) && ((byte & 0x40) != 0)))); | |
1024 | ||
1025 | return size; | |
1026 | } | |
1027 | ||
3f76745e JM |
1028 | /* Output an unsigned LEB128 quantity. */ |
1029 | ||
1030 | static void | |
1031 | output_uleb128 (value) | |
1032 | register unsigned long value; | |
1033 | { | |
1034 | unsigned long save_value = value; | |
1035 | ||
1036 | fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP); | |
1037 | do | |
1038 | { | |
1039 | register unsigned byte = (value & 0x7f); | |
1040 | value >>= 7; | |
1041 | if (value != 0) | |
1042 | /* More bytes to follow. */ | |
1043 | byte |= 0x80; | |
1044 | ||
1045 | fprintf (asm_out_file, "0x%x", byte); | |
1046 | if (value != 0) | |
1047 | fprintf (asm_out_file, ","); | |
1048 | } | |
1049 | while (value != 0); | |
1050 | ||
1051 | if (flag_verbose_asm) | |
1052 | fprintf (asm_out_file, "\t%s ULEB128 0x%x", ASM_COMMENT_START, save_value); | |
1053 | } | |
1054 | ||
1055 | /* Output an signed LEB128 quantity. */ | |
1056 | ||
1057 | static void | |
1058 | output_sleb128 (value) | |
1059 | register long value; | |
1060 | { | |
1061 | register int more; | |
1062 | register unsigned byte; | |
1063 | long save_value = value; | |
1064 | ||
1065 | fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP); | |
1066 | do | |
1067 | { | |
1068 | byte = (value & 0x7f); | |
1069 | /* arithmetic shift */ | |
1070 | value >>= 7; | |
1071 | more = !((((value == 0) && ((byte & 0x40) == 0)) | |
1072 | || ((value == -1) && ((byte & 0x40) != 0)))); | |
1073 | if (more) | |
1074 | byte |= 0x80; | |
1075 | ||
1076 | fprintf (asm_out_file, "0x%x", byte); | |
1077 | if (more) | |
1078 | fprintf (asm_out_file, ","); | |
1079 | } | |
1080 | ||
1081 | while (more); | |
1082 | if (flag_verbose_asm) | |
1083 | fprintf (asm_out_file, "\t%s SLEB128 %d", ASM_COMMENT_START, save_value); | |
1084 | } | |
1085 | ||
1086 | /* Output a Call Frame Information opcode and its operand(s). */ | |
1087 | ||
1088 | static void | |
1089 | output_cfi (cfi, fde) | |
1090 | register dw_cfi_ref cfi; | |
1091 | register dw_fde_ref fde; | |
1092 | { | |
1093 | if (cfi->dw_cfi_opc == DW_CFA_advance_loc) | |
1094 | { | |
1095 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
1096 | cfi->dw_cfi_opc | |
1097 | | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)); | |
1098 | if (flag_verbose_asm) | |
1099 | fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%x", | |
1100 | ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
1101 | fputc ('\n', asm_out_file); | |
1102 | } | |
1103 | ||
1104 | else if (cfi->dw_cfi_opc == DW_CFA_offset) | |
1105 | { | |
1106 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
1107 | cfi->dw_cfi_opc | |
1108 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)); | |
1109 | if (flag_verbose_asm) | |
1110 | fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%x", | |
1111 | ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1112 | ||
1113 | fputc ('\n', asm_out_file); | |
1114 | output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset); | |
1115 | fputc ('\n', asm_out_file); | |
1116 | } | |
1117 | else if (cfi->dw_cfi_opc == DW_CFA_restore) | |
1118 | { | |
1119 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
1120 | cfi->dw_cfi_opc | |
1121 | | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)); | |
1122 | if (flag_verbose_asm) | |
1123 | fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%x", | |
1124 | ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1125 | ||
1126 | fputc ('\n', asm_out_file); | |
1127 | } | |
1128 | else | |
1129 | { | |
1130 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc); | |
1131 | if (flag_verbose_asm) | |
1132 | fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, | |
1133 | dwarf_cfi_name (cfi->dw_cfi_opc)); | |
1134 | ||
1135 | fputc ('\n', asm_out_file); | |
1136 | switch (cfi->dw_cfi_opc) | |
1137 | { | |
1138 | case DW_CFA_set_loc: | |
1139 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr); | |
1140 | fputc ('\n', asm_out_file); | |
1141 | break; | |
1142 | case DW_CFA_advance_loc1: | |
1143 | /* TODO: not currently implemented. */ | |
1144 | abort (); | |
1145 | break; | |
1146 | case DW_CFA_advance_loc2: | |
1147 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, | |
1148 | cfi->dw_cfi_oprnd1.dw_cfi_addr, | |
1149 | fde->dw_fde_current_label); | |
1150 | fputc ('\n', asm_out_file); | |
1151 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
1152 | break; | |
1153 | case DW_CFA_advance_loc4: | |
1154 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, | |
1155 | cfi->dw_cfi_oprnd1.dw_cfi_addr, | |
1156 | fde->dw_fde_current_label); | |
1157 | fputc ('\n', asm_out_file); | |
1158 | fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; | |
1159 | break; | |
1160 | #ifdef MIPS_DEBUGGING_INFO | |
1161 | case DW_CFA_MIPS_advance_loc8: | |
1162 | /* TODO: not currently implemented. */ | |
1163 | abort (); | |
1164 | break; | |
1165 | #endif | |
1166 | case DW_CFA_offset_extended: | |
1167 | case DW_CFA_def_cfa: | |
1168 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1169 | fputc ('\n', asm_out_file); | |
1170 | output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset); | |
1171 | fputc ('\n', asm_out_file); | |
1172 | break; | |
1173 | case DW_CFA_restore_extended: | |
1174 | case DW_CFA_undefined: | |
1175 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1176 | fputc ('\n', asm_out_file); | |
1177 | break; | |
1178 | case DW_CFA_same_value: | |
1179 | case DW_CFA_def_cfa_register: | |
1180 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1181 | fputc ('\n', asm_out_file); | |
1182 | break; | |
1183 | case DW_CFA_register: | |
1184 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num); | |
1185 | fputc ('\n', asm_out_file); | |
1186 | output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num); | |
1187 | fputc ('\n', asm_out_file); | |
1188 | break; | |
1189 | case DW_CFA_def_cfa_offset: | |
1190 | output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset); | |
1191 | fputc ('\n', asm_out_file); | |
1192 | break; | |
c53aa195 JM |
1193 | case DW_CFA_GNU_window_save: |
1194 | break; | |
3f76745e JM |
1195 | default: |
1196 | break; | |
1197 | } | |
1198 | } | |
1199 | } | |
1200 | ||
1201 | /* Output the call frame information used to used to record information | |
1202 | that relates to calculating the frame pointer, and records the | |
1203 | location of saved registers. */ | |
1204 | ||
1205 | static void | |
1206 | output_call_frame_info (for_eh) | |
1207 | int for_eh; | |
1208 | { | |
1209 | register unsigned long i, j; | |
1210 | register dw_fde_ref fde; | |
1211 | register unsigned long fde_size; | |
1212 | register dw_cfi_ref cfi; | |
1213 | unsigned long fde_pad; | |
a6ab3aad JM |
1214 | char l1[20], l2[20]; |
1215 | ||
1216 | /* Do we want to include a pointer to the exception table? */ | |
1217 | int eh_ptr = for_eh && exception_table_p (); | |
3f76745e JM |
1218 | |
1219 | /* Only output the info if it will be interesting. */ | |
1220 | for (i = 0; i < fde_table_in_use; ++i) | |
1221 | if (fde_table[i].dw_fde_cfi != NULL) | |
1222 | break; | |
1223 | if (i == fde_table_in_use) | |
1224 | return; | |
1225 | ||
3f76745e JM |
1226 | fputc ('\n', asm_out_file); |
1227 | if (for_eh) | |
1228 | { | |
1229 | #ifdef EH_FRAME_SECTION | |
1230 | ASM_OUTPUT_SECTION_NAME (asm_out_file, NULL_TREE, EH_FRAME_SECTION, 0); | |
1231 | #else | |
1232 | data_section (); | |
1233 | #endif | |
1234 | assemble_label ("__FRAME_BEGIN__"); | |
1235 | } | |
1236 | else | |
1237 | ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION); | |
1238 | ||
1239 | /* Output the CIE. */ | |
a6ab3aad JM |
1240 | ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh); |
1241 | ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh); | |
1242 | ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1); | |
3f76745e JM |
1243 | if (flag_verbose_asm) |
1244 | fprintf (asm_out_file, "\t%s Length of Common Information Entry", | |
1245 | ASM_COMMENT_START); | |
1246 | ||
1247 | fputc ('\n', asm_out_file); | |
a6ab3aad JM |
1248 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1249 | ||
3f76745e JM |
1250 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID); |
1251 | if (flag_verbose_asm) | |
1252 | fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START); | |
1253 | ||
1254 | fputc ('\n', asm_out_file); | |
1255 | if (DWARF_OFFSET_SIZE == 8) | |
1256 | { | |
1257 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID); | |
1258 | fputc ('\n', asm_out_file); | |
1259 | } | |
1260 | ||
1261 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION); | |
1262 | if (flag_verbose_asm) | |
1263 | fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START); | |
1264 | ||
1265 | fputc ('\n', asm_out_file); | |
a6ab3aad JM |
1266 | if (eh_ptr) |
1267 | { | |
1268 | /* The "z" augmentation was defined by SGI; the FDE contains a pointer | |
1269 | to the exception region info for the frame. */ | |
1270 | ASM_OUTPUT_DWARF_STRING (asm_out_file, "z"); | |
1271 | if (flag_verbose_asm) | |
1272 | fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START); | |
1273 | } | |
1274 | else | |
1275 | { | |
1276 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
1277 | if (flag_verbose_asm) | |
1278 | fprintf (asm_out_file, "\t%s CIE Augmentation (none)", | |
1279 | ASM_COMMENT_START); | |
1280 | } | |
3f76745e JM |
1281 | |
1282 | fputc ('\n', asm_out_file); | |
1283 | output_uleb128 (1); | |
1284 | if (flag_verbose_asm) | |
1285 | fprintf (asm_out_file, " (CIE Code Alignment Factor)"); | |
1286 | ||
1287 | fputc ('\n', asm_out_file); | |
1288 | output_sleb128 (DWARF_CIE_DATA_ALIGNMENT); | |
1289 | if (flag_verbose_asm) | |
1290 | fprintf (asm_out_file, " (CIE Data Alignment Factor)"); | |
1291 | ||
1292 | fputc ('\n', asm_out_file); | |
1293 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN); | |
1294 | if (flag_verbose_asm) | |
1295 | fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START); | |
1296 | ||
1297 | fputc ('\n', asm_out_file); | |
a6ab3aad JM |
1298 | if (eh_ptr) |
1299 | { | |
1300 | output_uleb128 (0); | |
1301 | if (flag_verbose_asm) | |
1302 | fprintf (asm_out_file, "\t%s CIE augmentation fields length", | |
1303 | ASM_COMMENT_START); | |
1304 | fputc ('\n', asm_out_file); | |
1305 | } | |
3f76745e JM |
1306 | |
1307 | for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next) | |
1308 | output_cfi (cfi, NULL); | |
1309 | ||
1310 | /* Pad the CIE out to an address sized boundary. */ | |
a6ab3aad JM |
1311 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); |
1312 | ASM_OUTPUT_LABEL (asm_out_file, l2); | |
3f76745e JM |
1313 | |
1314 | /* Loop through all of the FDE's. */ | |
1315 | for (i = 0; i < fde_table_in_use; ++i) | |
1316 | { | |
1317 | fde = &fde_table[i]; | |
1318 | if (fde->dw_fde_cfi == NULL) | |
1319 | continue; | |
1320 | ||
a6ab3aad JM |
1321 | ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i*2); |
1322 | ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i*2); | |
1323 | ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1); | |
3f76745e JM |
1324 | if (flag_verbose_asm) |
1325 | fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START); | |
3f76745e | 1326 | fputc ('\n', asm_out_file); |
a6ab3aad JM |
1327 | ASM_OUTPUT_LABEL (asm_out_file, l1); |
1328 | ||
3f76745e JM |
1329 | if (for_eh) |
1330 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__FRAME_BEGIN__"); | |
1331 | else | |
1332 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION)); | |
1333 | if (flag_verbose_asm) | |
1334 | fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START); | |
1335 | ||
1336 | fputc ('\n', asm_out_file); | |
1337 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin); | |
1338 | if (flag_verbose_asm) | |
1339 | fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START); | |
1340 | ||
1341 | fputc ('\n', asm_out_file); | |
1342 | ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, | |
1343 | fde->dw_fde_end, fde->dw_fde_begin); | |
1344 | if (flag_verbose_asm) | |
1345 | fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START); | |
1346 | ||
1347 | fputc ('\n', asm_out_file); | |
a6ab3aad JM |
1348 | if (eh_ptr) |
1349 | { | |
1350 | output_uleb128 (PTR_SIZE); | |
1351 | if (flag_verbose_asm) | |
1352 | fprintf (asm_out_file, "\t%s FDE augmentation fields length", | |
1353 | ASM_COMMENT_START); | |
1354 | fputc ('\n', asm_out_file); | |
1355 | ||
1356 | /* For now, a pointer to the translation unit's info will do. | |
1357 | ??? Eventually this should point to the function's info. */ | |
1358 | if (exception_table_p ()) | |
1359 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__"); | |
1360 | else | |
1361 | ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0); | |
1362 | ||
1363 | if (flag_verbose_asm) | |
1364 | fprintf (asm_out_file, "\t%s pointer to exception region info", | |
1365 | ASM_COMMENT_START); | |
1366 | fputc ('\n', asm_out_file); | |
1367 | } | |
3f76745e JM |
1368 | |
1369 | /* Loop through the Call Frame Instructions associated with | |
1370 | this FDE. */ | |
1371 | fde->dw_fde_current_label = fde->dw_fde_begin; | |
1372 | for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next) | |
1373 | output_cfi (cfi, fde); | |
1374 | ||
a6ab3aad JM |
1375 | /* Pad the FDE out to an address sized boundary. */ |
1376 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); | |
1377 | ASM_OUTPUT_LABEL (asm_out_file, l2); | |
3f76745e JM |
1378 | } |
1379 | #ifndef EH_FRAME_SECTION | |
1380 | if (for_eh) | |
1381 | { | |
1382 | /* Emit terminating zero for table. */ | |
1383 | ASM_OUTPUT_DWARF_DATA (asm_out_file, 0); | |
1384 | fputc ('\n', asm_out_file); | |
1385 | } | |
1386 | #endif | |
a6ab3aad JM |
1387 | #ifdef MIPS_DEBUGGING_INFO |
1388 | /* Work around Irix 6 assembler bug whereby labels at the end of a section | |
1389 | get a value of 0. Putting .align 0 after the label fixes it. */ | |
1390 | ASM_OUTPUT_ALIGN (asm_out_file, 0); | |
1391 | #endif | |
1392 | } | |
1393 | ||
1394 | /* Decide whether we want to emit frame unwind information for the current | |
1395 | translation unit. */ | |
1396 | ||
1397 | int | |
1398 | dwarf2out_do_frame () | |
1399 | { | |
1400 | return (write_symbols == DWARF2_DEBUG | |
1401 | || (flag_exceptions && ! exceptions_via_longjmp)); | |
3f76745e JM |
1402 | } |
1403 | ||
1404 | /* Output a marker (i.e. a label) for the beginning of a function, before | |
1405 | the prologue. */ | |
1406 | ||
1407 | void | |
1408 | dwarf2out_begin_prologue () | |
1409 | { | |
1410 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1411 | register dw_fde_ref fde; | |
1412 | ||
4f988ea2 JM |
1413 | ++current_funcdef_number; |
1414 | ||
3f76745e JM |
1415 | function_section (current_function_decl); |
1416 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL, | |
1417 | current_funcdef_number); | |
1418 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
1419 | ||
1420 | /* Expand the fde table if necessary. */ | |
1421 | if (fde_table_in_use == fde_table_allocated) | |
1422 | { | |
1423 | fde_table_allocated += FDE_TABLE_INCREMENT; | |
1424 | fde_table | |
1425 | = (dw_fde_ref) xrealloc (fde_table, | |
1426 | fde_table_allocated * sizeof (dw_fde_node)); | |
a3f97cbb | 1427 | } |
3f76745e JM |
1428 | |
1429 | /* Record the FDE associated with this function. */ | |
1430 | current_funcdef_fde = fde_table_in_use; | |
1431 | ||
1432 | /* Add the new FDE at the end of the fde_table. */ | |
1433 | fde = &fde_table[fde_table_in_use++]; | |
1434 | fde->dw_fde_begin = xstrdup (label); | |
1435 | fde->dw_fde_current_label = NULL; | |
1436 | fde->dw_fde_end = NULL; | |
1437 | fde->dw_fde_cfi = NULL; | |
1438 | } | |
1439 | ||
1440 | /* Output a marker (i.e. a label) for the absolute end of the generated code | |
1441 | for a function definition. This gets called *after* the epilogue code has | |
1442 | been generated. */ | |
1443 | ||
1444 | void | |
1445 | dwarf2out_end_epilogue () | |
1446 | { | |
1447 | dw_fde_ref fde; | |
1448 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1449 | ||
1450 | /* Output a label to mark the endpoint of the code generated for this | |
1451 | function. */ | |
1452 | ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number); | |
1453 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
1454 | fde = &fde_table[fde_table_in_use - 1]; | |
1455 | fde->dw_fde_end = xstrdup (label); | |
3f76745e JM |
1456 | } |
1457 | ||
1458 | void | |
1459 | dwarf2out_frame_init () | |
1460 | { | |
1461 | /* Allocate the initial hunk of the fde_table. */ | |
1462 | fde_table | |
1463 | = (dw_fde_ref) xmalloc (FDE_TABLE_INCREMENT * sizeof (dw_fde_node)); | |
1464 | bzero ((char *) fde_table, FDE_TABLE_INCREMENT * sizeof (dw_fde_node)); | |
1465 | fde_table_allocated = FDE_TABLE_INCREMENT; | |
1466 | fde_table_in_use = 0; | |
1467 | ||
1468 | /* Generate the CFA instructions common to all FDE's. Do it now for the | |
1469 | sake of lookup_cfa. */ | |
1470 | ||
a6ab3aad JM |
1471 | #ifdef DWARF2_UNWIND_INFO |
1472 | /* On entry, the Canonical Frame Address is at SP. */ | |
1473 | dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET); | |
3f76745e JM |
1474 | initial_return_save (INCOMING_RETURN_ADDR_RTX); |
1475 | #endif | |
1476 | } | |
1477 | ||
1478 | void | |
1479 | dwarf2out_frame_finish () | |
1480 | { | |
3f76745e | 1481 | /* Output call frame information. */ |
a6ab3aad | 1482 | #ifdef MIPS_DEBUGGING_INFO |
3f76745e JM |
1483 | if (write_symbols == DWARF2_DEBUG) |
1484 | output_call_frame_info (0); | |
1485 | if (flag_exceptions && ! exceptions_via_longjmp) | |
1486 | output_call_frame_info (1); | |
a6ab3aad JM |
1487 | #else |
1488 | if (write_symbols == DWARF2_DEBUG | |
1489 | || (flag_exceptions && ! exceptions_via_longjmp)) | |
1490 | output_call_frame_info (1); | |
1491 | #endif | |
3f76745e JM |
1492 | } |
1493 | ||
1494 | #endif /* .debug_frame support */ | |
1495 | ||
1496 | /* And now, the support for symbolic debugging information. */ | |
1497 | #ifdef DWARF2_DEBUGGING_INFO | |
1498 | ||
1499 | extern char *getpwd (); | |
1500 | ||
1501 | /* NOTE: In the comments in this file, many references are made to | |
1502 | "Debugging Information Entries". This term is abbreviated as `DIE' | |
1503 | throughout the remainder of this file. */ | |
1504 | ||
1505 | /* An internal representation of the DWARF output is built, and then | |
1506 | walked to generate the DWARF debugging info. The walk of the internal | |
1507 | representation is done after the entire program has been compiled. | |
1508 | The types below are used to describe the internal representation. */ | |
1509 | ||
1510 | /* Each DIE may have a series of attribute/value pairs. Values | |
1511 | can take on several forms. The forms that are used in this | |
1512 | implementation are listed below. */ | |
1513 | ||
1514 | typedef enum | |
1515 | { | |
1516 | dw_val_class_addr, | |
1517 | dw_val_class_loc, | |
1518 | dw_val_class_const, | |
1519 | dw_val_class_unsigned_const, | |
1520 | dw_val_class_long_long, | |
1521 | dw_val_class_float, | |
1522 | dw_val_class_flag, | |
1523 | dw_val_class_die_ref, | |
1524 | dw_val_class_fde_ref, | |
1525 | dw_val_class_lbl_id, | |
1526 | dw_val_class_section_offset, | |
1527 | dw_val_class_str | |
a3f97cbb | 1528 | } |
3f76745e | 1529 | dw_val_class; |
a3f97cbb | 1530 | |
3f76745e JM |
1531 | /* Various DIE's use offsets relative to the beginning of the |
1532 | .debug_info section to refer to each other. */ | |
71dfc51f | 1533 | |
3f76745e JM |
1534 | typedef long int dw_offset; |
1535 | ||
1536 | /* Define typedefs here to avoid circular dependencies. */ | |
1537 | ||
1538 | typedef struct die_struct *dw_die_ref; | |
1539 | typedef struct dw_attr_struct *dw_attr_ref; | |
1540 | typedef struct dw_val_struct *dw_val_ref; | |
1541 | typedef struct dw_line_info_struct *dw_line_info_ref; | |
1542 | typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref; | |
1543 | typedef struct dw_loc_descr_struct *dw_loc_descr_ref; | |
1544 | typedef struct pubname_struct *pubname_ref; | |
1545 | typedef dw_die_ref *arange_ref; | |
1546 | ||
1547 | /* Describe a double word constant value. */ | |
1548 | ||
1549 | typedef struct dw_long_long_struct | |
a3f97cbb | 1550 | { |
3f76745e JM |
1551 | unsigned long hi; |
1552 | unsigned long low; | |
1553 | } | |
1554 | dw_long_long_const; | |
1555 | ||
1556 | /* Describe a floating point constant value. */ | |
1557 | ||
1558 | typedef struct dw_fp_struct | |
1559 | { | |
1560 | long *array; | |
1561 | unsigned length; | |
1562 | } | |
1563 | dw_float_const; | |
1564 | ||
1565 | /* Each entry in the line_info_table maintains the file and | |
1566 | line nuber associated with the label generated for that | |
1567 | entry. The label gives the PC value associated with | |
1568 | the line number entry. */ | |
1569 | ||
1570 | typedef struct dw_line_info_struct | |
1571 | { | |
1572 | unsigned long dw_file_num; | |
1573 | unsigned long dw_line_num; | |
1574 | } | |
1575 | dw_line_info_entry; | |
1576 | ||
1577 | /* Line information for functions in separate sections; each one gets its | |
1578 | own sequence. */ | |
1579 | typedef struct dw_separate_line_info_struct | |
1580 | { | |
1581 | unsigned long dw_file_num; | |
1582 | unsigned long dw_line_num; | |
1583 | unsigned long function; | |
1584 | } | |
1585 | dw_separate_line_info_entry; | |
1586 | ||
1587 | /* The dw_val_node describes an attibute's value, as it is | |
1588 | represented internally. */ | |
1589 | ||
1590 | typedef struct dw_val_struct | |
1591 | { | |
1592 | dw_val_class val_class; | |
1593 | union | |
a3f97cbb | 1594 | { |
3f76745e JM |
1595 | char *val_addr; |
1596 | dw_loc_descr_ref val_loc; | |
1597 | long int val_int; | |
1598 | long unsigned val_unsigned; | |
1599 | dw_long_long_const val_long_long; | |
1600 | dw_float_const val_float; | |
1601 | dw_die_ref val_die_ref; | |
1602 | unsigned val_fde_index; | |
1603 | char *val_str; | |
1604 | char *val_lbl_id; | |
1605 | char *val_section; | |
1606 | unsigned char val_flag; | |
a3f97cbb | 1607 | } |
3f76745e JM |
1608 | v; |
1609 | } | |
1610 | dw_val_node; | |
1611 | ||
1612 | /* Locations in memory are described using a sequence of stack machine | |
1613 | operations. */ | |
1614 | ||
1615 | typedef struct dw_loc_descr_struct | |
1616 | { | |
1617 | dw_loc_descr_ref dw_loc_next; | |
1618 | enum dwarf_location_atom dw_loc_opc; | |
1619 | dw_val_node dw_loc_oprnd1; | |
1620 | dw_val_node dw_loc_oprnd2; | |
1621 | } | |
1622 | dw_loc_descr_node; | |
1623 | ||
1624 | /* Each DIE attribute has a field specifying the attribute kind, | |
1625 | a link to the next attribute in the chain, and an attribute value. | |
1626 | Attributes are typically linked below the DIE they modify. */ | |
1627 | ||
1628 | typedef struct dw_attr_struct | |
1629 | { | |
1630 | enum dwarf_attribute dw_attr; | |
1631 | dw_attr_ref dw_attr_next; | |
1632 | dw_val_node dw_attr_val; | |
1633 | } | |
1634 | dw_attr_node; | |
1635 | ||
1636 | /* The Debugging Information Entry (DIE) structure */ | |
1637 | ||
1638 | typedef struct die_struct | |
1639 | { | |
1640 | enum dwarf_tag die_tag; | |
1641 | dw_attr_ref die_attr; | |
1642 | dw_attr_ref die_attr_last; | |
1643 | dw_die_ref die_parent; | |
1644 | dw_die_ref die_child; | |
1645 | dw_die_ref die_child_last; | |
1646 | dw_die_ref die_sib; | |
1647 | dw_offset die_offset; | |
1648 | unsigned long die_abbrev; | |
a3f97cbb | 1649 | } |
3f76745e JM |
1650 | die_node; |
1651 | ||
1652 | /* The pubname structure */ | |
1653 | ||
1654 | typedef struct pubname_struct | |
1655 | { | |
1656 | dw_die_ref die; | |
1657 | char * name; | |
1658 | } | |
1659 | pubname_entry; | |
1660 | ||
ef76d03b JW |
1661 | /* The limbo die list structure. */ |
1662 | typedef struct limbo_die_struct | |
1663 | { | |
1664 | dw_die_ref die; | |
1665 | struct limbo_die_struct *next; | |
1666 | } | |
1667 | limbo_die_node; | |
1668 | ||
3f76745e JM |
1669 | /* How to start an assembler comment. */ |
1670 | #ifndef ASM_COMMENT_START | |
1671 | #define ASM_COMMENT_START ";#" | |
1672 | #endif | |
1673 | ||
1674 | /* Define a macro which returns non-zero for a TYPE_DECL which was | |
1675 | implicitly generated for a tagged type. | |
1676 | ||
1677 | Note that unlike the gcc front end (which generates a NULL named | |
1678 | TYPE_DECL node for each complete tagged type, each array type, and | |
1679 | each function type node created) the g++ front end generates a | |
1680 | _named_ TYPE_DECL node for each tagged type node created. | |
1681 | These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to | |
1682 | generate a DW_TAG_typedef DIE for them. */ | |
1683 | ||
1684 | #define TYPE_DECL_IS_STUB(decl) \ | |
1685 | (DECL_NAME (decl) == NULL_TREE \ | |
1686 | || (DECL_ARTIFICIAL (decl) \ | |
1687 | && is_tagged_type (TREE_TYPE (decl)) \ | |
ef76d03b JW |
1688 | && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \ |
1689 | /* This is necessary for stub decls that \ | |
1690 | appear in nested inline functions. */ \ | |
1691 | || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \ | |
1692 | && (decl_ultimate_origin (decl) \ | |
1693 | == TYPE_STUB_DECL (TREE_TYPE (decl))))))) | |
3f76745e JM |
1694 | |
1695 | /* Information concerning the compilation unit's programming | |
1696 | language, and compiler version. */ | |
1697 | ||
1698 | extern int flag_traditional; | |
1699 | extern char *version_string; | |
1700 | extern char *language_string; | |
1701 | ||
1702 | /* Fixed size portion of the DWARF compilation unit header. */ | |
1703 | #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3) | |
1704 | ||
1705 | /* Fixed size portion of debugging line information prolog. */ | |
1706 | #define DWARF_LINE_PROLOG_HEADER_SIZE 5 | |
1707 | ||
1708 | /* Fixed size portion of public names info. */ | |
1709 | #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2) | |
1710 | ||
1711 | /* Fixed size portion of the address range info. */ | |
1712 | #define DWARF_ARANGES_HEADER_SIZE \ | |
1713 | (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE) | |
1714 | ||
1715 | /* Define the architecture-dependent minimum instruction length (in bytes). | |
1716 | In this implementation of DWARF, this field is used for information | |
1717 | purposes only. Since GCC generates assembly language, we have | |
1718 | no a priori knowledge of how many instruction bytes are generated | |
1719 | for each source line, and therefore can use only the DW_LNE_set_address | |
1720 | and DW_LNS_fixed_advance_pc line information commands. */ | |
1721 | ||
1722 | #ifndef DWARF_LINE_MIN_INSTR_LENGTH | |
1723 | #define DWARF_LINE_MIN_INSTR_LENGTH 4 | |
1724 | #endif | |
1725 | ||
1726 | /* Minimum line offset in a special line info. opcode. | |
1727 | This value was chosen to give a reasonable range of values. */ | |
1728 | #define DWARF_LINE_BASE -10 | |
1729 | ||
1730 | /* First special line opcde - leave room for the standard opcodes. */ | |
1731 | #define DWARF_LINE_OPCODE_BASE 10 | |
1732 | ||
1733 | /* Range of line offsets in a special line info. opcode. */ | |
1734 | #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1) | |
1735 | ||
1736 | /* Flag that indicates the initial value of the is_stmt_start flag. | |
1737 | In the present implementation, we do not mark any lines as | |
1738 | the beginning of a source statement, because that information | |
1739 | is not made available by the GCC front-end. */ | |
1740 | #define DWARF_LINE_DEFAULT_IS_STMT_START 1 | |
1741 | ||
1742 | /* This location is used by calc_die_sizes() to keep track | |
1743 | the offset of each DIE within the .debug_info section. */ | |
1744 | static unsigned long next_die_offset; | |
1745 | ||
1746 | /* Record the root of the DIE's built for the current compilation unit. */ | |
1747 | static dw_die_ref comp_unit_die; | |
1748 | ||
ef76d03b JW |
1749 | /* A list of DIEs with a NULL parent waiting to be relocated. */ |
1750 | static limbo_die_node *limbo_die_list = 0; | |
3f76745e JM |
1751 | |
1752 | /* Pointer to an array of filenames referenced by this compilation unit. */ | |
1753 | static char **file_table; | |
1754 | ||
1755 | /* Total number of entries in the table (i.e. array) pointed to by | |
1756 | `file_table'. This is the *total* and includes both used and unused | |
1757 | slots. */ | |
1758 | static unsigned file_table_allocated; | |
a3f97cbb | 1759 | |
3f76745e JM |
1760 | /* Number of entries in the file_table which are actually in use. */ |
1761 | static unsigned file_table_in_use; | |
71dfc51f | 1762 | |
3f76745e JM |
1763 | /* Size (in elements) of increments by which we may expand the filename |
1764 | table. */ | |
1765 | #define FILE_TABLE_INCREMENT 64 | |
71dfc51f | 1766 | |
3f76745e JM |
1767 | /* Local pointer to the name of the main input file. Initialized in |
1768 | dwarf2out_init. */ | |
1769 | static char *primary_filename; | |
a3f97cbb | 1770 | |
3f76745e JM |
1771 | /* For Dwarf output, we must assign lexical-blocks id numbers in the order in |
1772 | which their beginnings are encountered. We output Dwarf debugging info | |
1773 | that refers to the beginnings and ends of the ranges of code for each | |
1774 | lexical block. The labels themselves are generated in final.c, which | |
1775 | assigns numbers to the blocks in the same way. */ | |
1776 | static unsigned next_block_number = 2; | |
a3f97cbb | 1777 | |
3f76745e JM |
1778 | /* A pointer to the base of a table of references to DIE's that describe |
1779 | declarations. The table is indexed by DECL_UID() which is a unique | |
1780 | number, indentifying each decl. */ | |
1781 | static dw_die_ref *decl_die_table; | |
71dfc51f | 1782 | |
3f76745e JM |
1783 | /* Number of elements currently allocated for the decl_die_table. */ |
1784 | static unsigned decl_die_table_allocated; | |
a3f97cbb | 1785 | |
3f76745e JM |
1786 | /* Number of elements in decl_die_table currently in use. */ |
1787 | static unsigned decl_die_table_in_use; | |
71dfc51f | 1788 | |
3f76745e JM |
1789 | /* Size (in elements) of increments by which we may expand the |
1790 | decl_die_table. */ | |
1791 | #define DECL_DIE_TABLE_INCREMENT 256 | |
a3f97cbb | 1792 | |
3f76745e JM |
1793 | /* A pointer to the base of a table of references to declaration |
1794 | scopes. This table is a display which tracks the nesting | |
1795 | of declaration scopes at the current scope and containing | |
1796 | scopes. This table is used to find the proper place to | |
1797 | define type declaration DIE's. */ | |
1798 | static tree *decl_scope_table; | |
a3f97cbb | 1799 | |
3f76745e JM |
1800 | /* Number of elements currently allocated for the decl_scope_table. */ |
1801 | static unsigned decl_scope_table_allocated; | |
71dfc51f | 1802 | |
3f76745e JM |
1803 | /* Current level of nesting of declataion scopes. */ |
1804 | static unsigned decl_scope_depth; | |
bdb669cb | 1805 | |
3f76745e JM |
1806 | /* Size (in elements) of increments by which we may expand the |
1807 | decl_scope_table. */ | |
1808 | #define DECL_SCOPE_TABLE_INCREMENT 64 | |
bdb669cb | 1809 | |
3f76745e JM |
1810 | /* A pointer to the base of a list of references to DIE's that |
1811 | are uniquely identified by their tag, presence/absence of | |
1812 | children DIE's, and list of attribute/value pairs. */ | |
1813 | static dw_die_ref *abbrev_die_table; | |
71dfc51f | 1814 | |
3f76745e JM |
1815 | /* Number of elements currently allocated for abbrev_die_table. */ |
1816 | static unsigned abbrev_die_table_allocated; | |
bdb669cb | 1817 | |
3f76745e JM |
1818 | /* Number of elements in type_die_table currently in use. */ |
1819 | static unsigned abbrev_die_table_in_use; | |
bdb669cb | 1820 | |
3f76745e JM |
1821 | /* Size (in elements) of increments by which we may expand the |
1822 | abbrev_die_table. */ | |
1823 | #define ABBREV_DIE_TABLE_INCREMENT 256 | |
71dfc51f | 1824 | |
3f76745e JM |
1825 | /* A pointer to the base of a table that contains line information |
1826 | for each source code line in .text in the compilation unit. */ | |
1827 | static dw_line_info_ref line_info_table; | |
a3f97cbb | 1828 | |
3f76745e JM |
1829 | /* Number of elements currently allocated for line_info_table. */ |
1830 | static unsigned line_info_table_allocated; | |
71dfc51f | 1831 | |
3f76745e JM |
1832 | /* Number of elements in separate_line_info_table currently in use. */ |
1833 | static unsigned separate_line_info_table_in_use; | |
71dfc51f | 1834 | |
3f76745e JM |
1835 | /* A pointer to the base of a table that contains line information |
1836 | for each source code line outside of .text in the compilation unit. */ | |
1837 | static dw_separate_line_info_ref separate_line_info_table; | |
a3f97cbb | 1838 | |
3f76745e JM |
1839 | /* Number of elements currently allocated for separate_line_info_table. */ |
1840 | static unsigned separate_line_info_table_allocated; | |
71dfc51f | 1841 | |
3f76745e JM |
1842 | /* Number of elements in line_info_table currently in use. */ |
1843 | static unsigned line_info_table_in_use; | |
71dfc51f | 1844 | |
3f76745e JM |
1845 | /* Size (in elements) of increments by which we may expand the |
1846 | line_info_table. */ | |
1847 | #define LINE_INFO_TABLE_INCREMENT 1024 | |
a3f97cbb | 1848 | |
3f76745e JM |
1849 | /* A pointer to the base of a table that contains a list of publicly |
1850 | accessible names. */ | |
1851 | static pubname_ref pubname_table; | |
71dfc51f | 1852 | |
3f76745e JM |
1853 | /* Number of elements currently allocated for pubname_table. */ |
1854 | static unsigned pubname_table_allocated; | |
1855 | ||
1856 | /* Number of elements in pubname_table currently in use. */ | |
1857 | static unsigned pubname_table_in_use; | |
1858 | ||
1859 | /* Size (in elements) of increments by which we may expand the | |
1860 | pubname_table. */ | |
1861 | #define PUBNAME_TABLE_INCREMENT 64 | |
1862 | ||
1863 | /* A pointer to the base of a table that contains a list of publicly | |
1864 | accessible names. */ | |
1865 | static arange_ref arange_table; | |
71dfc51f | 1866 | |
3f76745e JM |
1867 | /* Number of elements currently allocated for arange_table. */ |
1868 | static unsigned arange_table_allocated; | |
a3f97cbb | 1869 | |
3f76745e JM |
1870 | /* Number of elements in arange_table currently in use. */ |
1871 | static unsigned arange_table_in_use; | |
71dfc51f | 1872 | |
3f76745e JM |
1873 | /* Size (in elements) of increments by which we may expand the |
1874 | arange_table. */ | |
1875 | #define ARANGE_TABLE_INCREMENT 64 | |
71dfc51f | 1876 | |
3f76745e JM |
1877 | /* A pointer to the base of a list of pending types which we haven't |
1878 | generated DIEs for yet, but which we will have to come back to | |
1879 | later on. */ | |
469ac993 | 1880 | |
3f76745e | 1881 | static tree *pending_types_list; |
71dfc51f | 1882 | |
3f76745e JM |
1883 | /* Number of elements currently allocated for the pending_types_list. */ |
1884 | static unsigned pending_types_allocated; | |
71dfc51f | 1885 | |
3f76745e JM |
1886 | /* Number of elements of pending_types_list currently in use. */ |
1887 | static unsigned pending_types; | |
a3f97cbb | 1888 | |
3f76745e JM |
1889 | /* Size (in elements) of increments by which we may expand the pending |
1890 | types list. Actually, a single hunk of space of this size should | |
1891 | be enough for most typical programs. */ | |
1892 | #define PENDING_TYPES_INCREMENT 64 | |
71dfc51f | 1893 | |
3f76745e JM |
1894 | /* Record whether the function being analyzed contains inlined functions. */ |
1895 | static int current_function_has_inlines; | |
1896 | static int comp_unit_has_inlines; | |
71dfc51f | 1897 | |
3f76745e JM |
1898 | /* A pointer to the ..._DECL node which we have most recently been working |
1899 | on. We keep this around just in case something about it looks screwy and | |
1900 | we want to tell the user what the source coordinates for the actual | |
1901 | declaration are. */ | |
1902 | static tree dwarf_last_decl; | |
a3f97cbb | 1903 | |
3f76745e | 1904 | /* Forward declarations for functions defined in this file. */ |
71dfc51f | 1905 | |
3f76745e JM |
1906 | static void addr_const_to_string PROTO((char *, rtx)); |
1907 | static char *addr_to_string PROTO((rtx)); | |
1908 | static int is_pseudo_reg PROTO((rtx)); | |
1909 | static tree type_main_variant PROTO((tree)); | |
1910 | static int is_tagged_type PROTO((tree)); | |
1911 | static char *dwarf_tag_name PROTO((unsigned)); | |
1912 | static char *dwarf_attr_name PROTO((unsigned)); | |
1913 | static char *dwarf_form_name PROTO((unsigned)); | |
1914 | static char *dwarf_stack_op_name PROTO((unsigned)); | |
1915 | static char *dwarf_type_encoding_name PROTO((unsigned)); | |
1916 | static tree decl_ultimate_origin PROTO((tree)); | |
1917 | static tree block_ultimate_origin PROTO((tree)); | |
1918 | static tree decl_class_context PROTO((tree)); | |
1919 | static void add_dwarf_attr PROTO((dw_die_ref, dw_attr_ref)); | |
1920 | static void add_AT_flag PROTO((dw_die_ref, | |
1921 | enum dwarf_attribute, | |
1922 | unsigned)); | |
1923 | static void add_AT_int PROTO((dw_die_ref, | |
1924 | enum dwarf_attribute, long)); | |
1925 | static void add_AT_unsigned PROTO((dw_die_ref, | |
1926 | enum dwarf_attribute, | |
1927 | unsigned long)); | |
1928 | static void add_AT_long_long PROTO((dw_die_ref, | |
1929 | enum dwarf_attribute, | |
1930 | unsigned long, unsigned long)); | |
1931 | static void add_AT_float PROTO((dw_die_ref, | |
1932 | enum dwarf_attribute, | |
1933 | unsigned, long *)); | |
1934 | static void add_AT_string PROTO((dw_die_ref, | |
1935 | enum dwarf_attribute, char *)); | |
1936 | static void add_AT_die_ref PROTO((dw_die_ref, | |
1937 | enum dwarf_attribute, | |
1938 | dw_die_ref)); | |
1939 | static void add_AT_fde_ref PROTO((dw_die_ref, | |
1940 | enum dwarf_attribute, | |
1941 | unsigned)); | |
1942 | static void add_AT_loc PROTO((dw_die_ref, | |
1943 | enum dwarf_attribute, | |
1944 | dw_loc_descr_ref)); | |
1945 | static void add_AT_addr PROTO((dw_die_ref, | |
1946 | enum dwarf_attribute, char *)); | |
1947 | static void add_AT_lbl_id PROTO((dw_die_ref, | |
1948 | enum dwarf_attribute, char *)); | |
1949 | static void add_AT_setion_offset PROTO((dw_die_ref, | |
1950 | enum dwarf_attribute, char *)); | |
1951 | static int is_extern_subr_die PROTO((dw_die_ref)); | |
1952 | static dw_attr_ref get_AT PROTO((dw_die_ref, | |
1953 | enum dwarf_attribute)); | |
1954 | static char *get_AT_low_pc PROTO((dw_die_ref)); | |
1955 | static char *get_AT_hi_pc PROTO((dw_die_ref)); | |
1956 | static char *get_AT_string PROTO((dw_die_ref, | |
1957 | enum dwarf_attribute)); | |
1958 | static int get_AT_flag PROTO((dw_die_ref, | |
1959 | enum dwarf_attribute)); | |
1960 | static unsigned get_AT_unsigned PROTO((dw_die_ref, | |
1961 | enum dwarf_attribute)); | |
1962 | static int is_c_family PROTO((void)); | |
1963 | static int is_fortran PROTO((void)); | |
1964 | static void remove_AT PROTO((dw_die_ref, | |
1965 | enum dwarf_attribute)); | |
1966 | static void remove_children PROTO((dw_die_ref)); | |
1967 | static void add_child_die PROTO((dw_die_ref, dw_die_ref)); | |
1968 | static dw_die_ref new_die PROTO((enum dwarf_tag, dw_die_ref)); | |
1969 | static dw_die_ref lookup_type_die PROTO((tree)); | |
1970 | static void equate_type_number_to_die PROTO((tree, dw_die_ref)); | |
1971 | static dw_die_ref lookup_decl_die PROTO((tree)); | |
1972 | static void equate_decl_number_to_die PROTO((tree, dw_die_ref)); | |
1973 | static dw_loc_descr_ref new_loc_descr PROTO((enum dwarf_location_atom, | |
1974 | unsigned long, unsigned long)); | |
1975 | static void add_loc_descr PROTO((dw_loc_descr_ref *, | |
1976 | dw_loc_descr_ref)); | |
1977 | static void print_spaces PROTO((FILE *)); | |
1978 | static void print_die PROTO((dw_die_ref, FILE *)); | |
1979 | static void print_dwarf_line_table PROTO((FILE *)); | |
1980 | static void add_sibling_atttributes PROTO((dw_die_ref)); | |
1981 | static void build_abbrev_table PROTO((dw_die_ref)); | |
1982 | static unsigned long size_of_string PROTO((char *)); | |
1983 | static unsigned long size_of_loc_descr PROTO((dw_loc_descr_ref)); | |
1984 | static unsigned long size_of_locs PROTO((dw_loc_descr_ref)); | |
1985 | static int constant_size PROTO((long unsigned)); | |
1986 | static unsigned long size_of_die PROTO((dw_die_ref)); | |
1987 | static void calc_die_sizes PROTO((dw_die_ref)); | |
1988 | static unsigned long size_of_prolog PROTO((void)); | |
1989 | static unsigned long size_of_line_info PROTO((void)); | |
1990 | static unsigned long size_of_pubnames PROTO((void)); | |
1991 | static unsigned long size_of_aranges PROTO((void)); | |
1992 | static enum dwarf_form value_format PROTO((dw_val_ref)); | |
1993 | static void output_value_format PROTO((dw_val_ref)); | |
1994 | static void output_abbrev_section PROTO((void)); | |
1995 | static void output_loc_operands PROTO((dw_loc_descr_ref)); | |
1996 | static unsigned long sibling_offset PROTO((dw_die_ref)); | |
1997 | static void output_die PROTO((dw_die_ref)); | |
1998 | static void output_compilation_unit_header PROTO((void)); | |
1999 | static char *dwarf2_name PROTO((tree, int)); | |
2000 | static void add_pubname PROTO((tree, dw_die_ref)); | |
2001 | static void output_pubnames PROTO((void)); | |
2002 | static void add_arrange PROTO((tree, dw_die_ref)); | |
2003 | static void output_arranges PROTO((void)); | |
2004 | static void output_line_info PROTO((void)); | |
2005 | static int is_body_block PROTO((tree)); | |
2006 | static dw_die_ref base_type_die PROTO((tree)); | |
2007 | static tree root_type PROTO((tree)); | |
2008 | static int is_base_type PROTO((tree)); | |
2009 | static dw_die_ref modified_type_die PROTO((tree, int, int, dw_die_ref)); | |
2010 | static int type_is_enum PROTO((tree)); | |
2011 | static dw_loc_descr_ref reg_loc_descr_ref PROTO((rtx)); | |
2012 | static dw_loc_descr_ref based_loc_descr PROTO((unsigned, long)); | |
2013 | static int is_based_loc PROTO((rtx)); | |
2014 | static dw_loc_descr_ref mem_loc_descriptor PROTO((rtx)); | |
2015 | static dw_loc_descr_ref loc_descriptor PROTO((rtx)); | |
2016 | static unsigned ceiling PROTO((unsigned, unsigned)); | |
2017 | static tree field_type PROTO((tree)); | |
2018 | static unsigned simple_type_align_in_bits PROTO((tree)); | |
2019 | static unsigned simple_type_size_in_bits PROTO((tree)); | |
2020 | static unsigned field_byte_offset PROTO((tree)); | |
ef76d03b JW |
2021 | static void add_AT_location_description PROTO((dw_die_ref, |
2022 | enum dwarf_attribute, rtx)); | |
3f76745e JM |
2023 | static void add_data_member_location_attribute PROTO((dw_die_ref, tree)); |
2024 | static void add_const_value_attribute PROTO((dw_die_ref, rtx)); | |
2025 | static void add_location_or_const_value_attribute PROTO((dw_die_ref, tree)); | |
2026 | static void add_name_attribute PROTO((dw_die_ref, char *)); | |
2027 | static void add_bound_info PROTO((dw_die_ref, | |
2028 | enum dwarf_attribute, tree)); | |
2029 | static void add_subscript_info PROTO((dw_die_ref, tree)); | |
2030 | static void add_byte_size_attribute PROTO((dw_die_ref, tree)); | |
2031 | static void add_bit_offset_attribute PROTO((dw_die_ref, tree)); | |
2032 | static void add_bit_size_attribute PROTO((dw_die_ref, tree)); | |
2033 | static void add_prototyped_attribute PROTO((dw_die_ref, tree)); | |
2034 | static void add_abstract_origin_attribute PROTO((dw_die_ref, tree)); | |
2035 | static void add_pure_or_virtual_attribute PROTO((dw_die_ref, tree)); | |
2036 | static void add_src_coords_attributes PROTO((dw_die_ref, tree)); | |
2037 | static void ad_name_and_src_coords_attributes PROTO((dw_die_ref, tree)); | |
2038 | static void push_decl_scope PROTO((tree)); | |
2039 | static dw_die_ref scope_die_for PROTO((tree, dw_die_ref)); | |
2040 | static void pop_decl_scope PROTO((void)); | |
2041 | static void add_type_attribute PROTO((dw_die_ref, tree, int, int, | |
2042 | dw_die_ref)); | |
2043 | static char *type_tag PROTO((tree)); | |
2044 | static tree member_declared_type PROTO((tree)); | |
2045 | static char *decl_start_label PROTO((tree)); | |
2046 | static void gen_arrqay_type_die PROTO((tree, dw_die_ref)); | |
2047 | static void gen_set_type_die PROTO((tree, dw_die_ref)); | |
2048 | static void gen_entry_point_die PROTO((tree, dw_die_ref)); | |
2049 | static void pend_type PROTO((tree)); | |
2050 | static void output_pending_types_for_scope PROTO((dw_die_ref)); | |
2051 | static void gen_inlined_enumeration_type_die PROTO((tree, dw_die_ref)); | |
2052 | static void gen_inlined_structure_type_die PROTO((tree, dw_die_ref)); | |
2053 | static void gen_inlined_union_type_die PROTO((tree, dw_die_ref)); | |
2054 | static void gen_enumeration_type_die PROTO((tree, dw_die_ref)); | |
2055 | static dw_die_ref gen_formal_parameter_die PROTO((tree, dw_die_ref)); | |
2056 | static void gen_unspecified_parameters_die PROTO((tree, dw_die_ref)); | |
2057 | static void gen_formal_types_die PROTO((tree, dw_die_ref)); | |
2058 | static void gen_subprogram_die PROTO((tree, dw_die_ref)); | |
2059 | static void gen_variable_die PROTO((tree, dw_die_ref)); | |
2060 | static void gen_label_die PROTO((tree, dw_die_ref)); | |
2061 | static void gen_lexical_block_die PROTO((tree, dw_die_ref, int)); | |
2062 | static void gen_inlined_subprogram_die PROTO((tree, dw_die_ref, int)); | |
2063 | static void gen_field_die PROTO((tree, dw_die_ref)); | |
2064 | static void gen_ptr_to_mbr_type_die PROTO((tree, dw_die_ref)); | |
2065 | static void gen_compile_unit_die PROTO((char *)); | |
2066 | static void gen_string_type_die PROTO((tree, dw_die_ref)); | |
2067 | static void gen_inheritance_die PROTO((tree, dw_die_ref)); | |
2068 | static void gen_member_die PROTO((tree, dw_die_ref)); | |
2069 | static void gen_struct_or_union_type_die PROTO((tree, dw_die_ref)); | |
2070 | static void gen_subroutine_type_die PROTO((tree, dw_die_ref)); | |
2071 | static void gen_typedef_die PROTO((tree, dw_die_ref)); | |
2072 | static void gen_type_die PROTO((tree, dw_die_ref)); | |
2073 | static void gen_tagged_type_instantiation_die PROTO((tree, dw_die_ref)); | |
2074 | static void gen_block_die PROTO((tree, dw_die_ref, int)); | |
2075 | static void decls_for_scope PROTO((tree, dw_die_ref, int)); | |
2076 | static int is_redundant_typedef PROTO((tree)); | |
2077 | static void gen_decl_die PROTO((tree, dw_die_ref)); | |
2078 | static unsigned lookup_filename PROTO((char *)); | |
71dfc51f | 2079 | |
3f76745e | 2080 | /* Section names used to hold DWARF debugging information. */ |
c53aa195 JM |
2081 | #ifndef DEBUG_INFO_SECTION |
2082 | #define DEBUG_INFO_SECTION ".debug_info" | |
3f76745e JM |
2083 | #endif |
2084 | #ifndef ABBREV_SECTION | |
2085 | #define ABBREV_SECTION ".debug_abbrev" | |
2086 | #endif | |
2087 | #ifndef ARANGES_SECTION | |
2088 | #define ARANGES_SECTION ".debug_aranges" | |
2089 | #endif | |
2090 | #ifndef DW_MACINFO_SECTION | |
2091 | #define DW_MACINFO_SECTION ".debug_macinfo" | |
2092 | #endif | |
c53aa195 JM |
2093 | #ifndef DEBUG_LINE_SECTION |
2094 | #define DEBUG_LINE_SECTION ".debug_line" | |
3f76745e JM |
2095 | #endif |
2096 | #ifndef LOC_SECTION | |
2097 | #define LOC_SECTION ".debug_loc" | |
2098 | #endif | |
2099 | #ifndef PUBNAMES_SECTION | |
2100 | #define PUBNAMES_SECTION ".debug_pubnames" | |
2101 | #endif | |
2102 | #ifndef STR_SECTION | |
2103 | #define STR_SECTION ".debug_str" | |
2104 | #endif | |
a3f97cbb | 2105 | |
3f76745e JM |
2106 | /* Standerd ELF section names for compiled code and data. */ |
2107 | #ifndef TEXT_SECTION | |
2108 | #define TEXT_SECTION ".text" | |
2109 | #endif | |
2110 | #ifndef DATA_SECTION | |
2111 | #define DATA_SECTION ".data" | |
2112 | #endif | |
2113 | #ifndef BSS_SECTION | |
2114 | #define BSS_SECTION ".bss" | |
2115 | #endif | |
71dfc51f | 2116 | |
a3f97cbb | 2117 | |
3f76745e JM |
2118 | /* Definitions of defaults for formats and names of various special |
2119 | (artificial) labels which may be generated within this file (when the -g | |
2120 | options is used and DWARF_DEBUGGING_INFO is in effect. | |
2121 | If necessary, these may be overridden from within the tm.h file, but | |
2122 | typically, overriding these defaults is unnecessary. */ | |
a3f97cbb | 2123 | |
257ebd1f | 2124 | static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 2125 | |
3f76745e JM |
2126 | #ifndef TEXT_END_LABEL |
2127 | #define TEXT_END_LABEL "Letext" | |
2128 | #endif | |
2129 | #ifndef DATA_END_LABEL | |
2130 | #define DATA_END_LABEL "Ledata" | |
2131 | #endif | |
2132 | #ifndef BSS_END_LABEL | |
2133 | #define BSS_END_LABEL "Lebss" | |
2134 | #endif | |
2135 | #ifndef INSN_LABEL_FMT | |
2136 | #define INSN_LABEL_FMT "LI%u_" | |
2137 | #endif | |
2138 | #ifndef BLOCK_BEGIN_LABEL | |
2139 | #define BLOCK_BEGIN_LABEL "LBB" | |
2140 | #endif | |
2141 | #ifndef BLOCK_END_LABEL | |
2142 | #define BLOCK_END_LABEL "LBE" | |
2143 | #endif | |
2144 | #ifndef BODY_BEGIN_LABEL | |
2145 | #define BODY_BEGIN_LABEL "Lbb" | |
2146 | #endif | |
2147 | #ifndef BODY_END_LABEL | |
2148 | #define BODY_END_LABEL "Lbe" | |
2149 | #endif | |
2150 | #ifndef LINE_CODE_LABEL | |
2151 | #define LINE_CODE_LABEL "LM" | |
2152 | #endif | |
2153 | #ifndef SEPARATE_LINE_CODE_LABEL | |
2154 | #define SEPARATE_LINE_CODE_LABEL "LSM" | |
2155 | #endif | |
71dfc51f | 2156 | |
3f76745e JM |
2157 | /* Convert a reference to the assembler name of a C-level name. This |
2158 | macro has the same effect as ASM_OUTPUT_LABELREF, but copies to | |
2159 | a string rather than writing to a file. */ | |
2160 | #ifndef ASM_NAME_TO_STRING | |
2161 | #define ASM_NAME_TO_STRING(STR, NAME) \ | |
2162 | do { \ | |
2163 | if ((NAME)[0] == '*') \ | |
2164 | strcpy (STR, NAME+1); \ | |
2165 | else \ | |
2166 | strcpy (STR, NAME); \ | |
2167 | } \ | |
2168 | while (0) | |
2169 | #endif | |
2170 | \f | |
2171 | /* Convert an integer constant expression into assembler syntax. Addition | |
2172 | and subtraction are the only arithmetic that may appear in these | |
2173 | expressions. This is an adaptation of output_addr_const in final.c. | |
2174 | Here, the target of the conversion is a string buffer. We can't use | |
2175 | output_addr_const directly, because it writes to a file. */ | |
71dfc51f | 2176 | |
3f76745e JM |
2177 | static void |
2178 | addr_const_to_string (str, x) | |
2179 | char *str; | |
2180 | rtx x; | |
a3f97cbb | 2181 | { |
3f76745e JM |
2182 | char buf1[256]; |
2183 | char buf2[256]; | |
71dfc51f | 2184 | |
3f76745e JM |
2185 | restart: |
2186 | str[0] = '\0'; | |
2187 | switch (GET_CODE (x)) | |
2188 | { | |
2189 | case PC: | |
2190 | if (flag_pic) | |
2191 | strcat (str, ","); | |
2192 | else | |
2193 | abort (); | |
2194 | break; | |
71dfc51f | 2195 | |
3f76745e JM |
2196 | case SYMBOL_REF: |
2197 | ASM_NAME_TO_STRING (buf1, XSTR (x, 0)); | |
2198 | strcat (str, buf1); | |
2199 | break; | |
a3f97cbb | 2200 | |
3f76745e JM |
2201 | case LABEL_REF: |
2202 | ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0))); | |
2203 | ASM_NAME_TO_STRING (buf2, buf1); | |
2204 | strcat (str, buf2); | |
2205 | break; | |
71dfc51f | 2206 | |
3f76745e JM |
2207 | case CODE_LABEL: |
2208 | ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x)); | |
2209 | ASM_NAME_TO_STRING (buf2, buf1); | |
2210 | strcat (str, buf2); | |
2211 | break; | |
71dfc51f | 2212 | |
3f76745e JM |
2213 | case CONST_INT: |
2214 | sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x)); | |
2215 | strcat (str, buf1); | |
2216 | break; | |
a3f97cbb | 2217 | |
3f76745e JM |
2218 | case CONST: |
2219 | /* This used to output parentheses around the expression, but that does | |
2220 | not work on the 386 (either ATT or BSD assembler). */ | |
2221 | addr_const_to_string (buf1, XEXP (x, 0)); | |
2222 | strcat (str, buf1); | |
2223 | break; | |
71dfc51f | 2224 | |
3f76745e JM |
2225 | case CONST_DOUBLE: |
2226 | if (GET_MODE (x) == VOIDmode) | |
2227 | { | |
2228 | /* We can use %d if the number is one word and positive. */ | |
2229 | if (CONST_DOUBLE_HIGH (x)) | |
2230 | sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX, | |
2231 | CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x)); | |
2232 | else if (CONST_DOUBLE_LOW (x) < 0) | |
2233 | sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x)); | |
2234 | else | |
2235 | sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, | |
2236 | CONST_DOUBLE_LOW (x)); | |
2237 | strcat (str, buf1); | |
2238 | } | |
2239 | else | |
2240 | /* We can't handle floating point constants; PRINT_OPERAND must | |
2241 | handle them. */ | |
2242 | output_operand_lossage ("floating constant misused"); | |
2243 | break; | |
71dfc51f | 2244 | |
3f76745e JM |
2245 | case PLUS: |
2246 | /* Some assemblers need integer constants to appear last (eg masm). */ | |
2247 | if (GET_CODE (XEXP (x, 0)) == CONST_INT) | |
a3f97cbb | 2248 | { |
3f76745e JM |
2249 | addr_const_to_string (buf1, XEXP (x, 1)); |
2250 | strcat (str, buf1); | |
2251 | if (INTVAL (XEXP (x, 0)) >= 0) | |
2252 | strcat (str, "+"); | |
2253 | ||
2254 | addr_const_to_string (buf1, XEXP (x, 0)); | |
2255 | strcat (str, buf1); | |
a3f97cbb | 2256 | } |
3f76745e JM |
2257 | else |
2258 | { | |
2259 | addr_const_to_string (buf1, XEXP (x, 0)); | |
2260 | strcat (str, buf1); | |
2261 | if (INTVAL (XEXP (x, 1)) >= 0) | |
2262 | strcat (str, "+"); | |
71dfc51f | 2263 | |
3f76745e JM |
2264 | addr_const_to_string (buf1, XEXP (x, 1)); |
2265 | strcat (str, buf1); | |
2266 | } | |
2267 | break; | |
a3f97cbb | 2268 | |
3f76745e JM |
2269 | case MINUS: |
2270 | /* Avoid outputting things like x-x or x+5-x, since some assemblers | |
2271 | can't handle that. */ | |
2272 | x = simplify_subtraction (x); | |
2273 | if (GET_CODE (x) != MINUS) | |
2274 | goto restart; | |
71dfc51f | 2275 | |
3f76745e JM |
2276 | addr_const_to_string (buf1, XEXP (x, 0)); |
2277 | strcat (str, buf1); | |
2278 | strcat (str, "-"); | |
2279 | if (GET_CODE (XEXP (x, 1)) == CONST_INT | |
2280 | && INTVAL (XEXP (x, 1)) < 0) | |
a3f97cbb | 2281 | { |
3f76745e JM |
2282 | strcat (str, ASM_OPEN_PAREN); |
2283 | addr_const_to_string (buf1, XEXP (x, 1)); | |
2284 | strcat (str, buf1); | |
2285 | strcat (str, ASM_CLOSE_PAREN); | |
2286 | } | |
2287 | else | |
2288 | { | |
2289 | addr_const_to_string (buf1, XEXP (x, 1)); | |
2290 | strcat (str, buf1); | |
a3f97cbb | 2291 | } |
3f76745e | 2292 | break; |
71dfc51f | 2293 | |
3f76745e JM |
2294 | case ZERO_EXTEND: |
2295 | case SIGN_EXTEND: | |
2296 | addr_const_to_string (buf1, XEXP (x, 0)); | |
2297 | strcat (str, buf1); | |
2298 | break; | |
71dfc51f | 2299 | |
3f76745e JM |
2300 | default: |
2301 | output_operand_lossage ("invalid expression as operand"); | |
2302 | } | |
d291dd49 JM |
2303 | } |
2304 | ||
3f76745e JM |
2305 | /* Convert an address constant to a string, and return a pointer to |
2306 | a copy of the result, located on the heap. */ | |
71dfc51f | 2307 | |
3f76745e JM |
2308 | static char * |
2309 | addr_to_string (x) | |
2310 | rtx x; | |
d291dd49 | 2311 | { |
3f76745e JM |
2312 | char buf[1024]; |
2313 | addr_const_to_string (buf, x); | |
2314 | return xstrdup (buf); | |
d291dd49 JM |
2315 | } |
2316 | ||
3f76745e | 2317 | /* Test if rtl node points to a psuedo register. */ |
71dfc51f | 2318 | |
3f76745e JM |
2319 | static inline int |
2320 | is_pseudo_reg (rtl) | |
2321 | register rtx rtl; | |
d291dd49 | 2322 | { |
3f76745e JM |
2323 | return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)) |
2324 | || ((GET_CODE (rtl) == SUBREG) | |
2325 | && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER))); | |
d291dd49 JM |
2326 | } |
2327 | ||
3f76745e JM |
2328 | /* Return a reference to a type, with its const and volatile qualifiers |
2329 | removed. */ | |
71dfc51f | 2330 | |
3f76745e JM |
2331 | static inline tree |
2332 | type_main_variant (type) | |
2333 | register tree type; | |
d291dd49 | 2334 | { |
3f76745e | 2335 | type = TYPE_MAIN_VARIANT (type); |
71dfc51f | 2336 | |
3f76745e JM |
2337 | /* There really should be only one main variant among any group of variants |
2338 | of a given type (and all of the MAIN_VARIANT values for all members of | |
2339 | the group should point to that one type) but sometimes the C front-end | |
2340 | messes this up for array types, so we work around that bug here. */ | |
71dfc51f | 2341 | |
3f76745e JM |
2342 | if (TREE_CODE (type) == ARRAY_TYPE) |
2343 | while (type != TYPE_MAIN_VARIANT (type)) | |
2344 | type = TYPE_MAIN_VARIANT (type); | |
2345 | ||
2346 | return type; | |
a3f97cbb JW |
2347 | } |
2348 | ||
3f76745e | 2349 | /* Return non-zero if the given type node represents a tagged type. */ |
71dfc51f RK |
2350 | |
2351 | static inline int | |
3f76745e JM |
2352 | is_tagged_type (type) |
2353 | register tree type; | |
bdb669cb | 2354 | { |
3f76745e | 2355 | register enum tree_code code = TREE_CODE (type); |
71dfc51f | 2356 | |
3f76745e JM |
2357 | return (code == RECORD_TYPE || code == UNION_TYPE |
2358 | || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); | |
bdb669cb JM |
2359 | } |
2360 | ||
3f76745e | 2361 | /* Convert a DIE tag into its string name. */ |
71dfc51f | 2362 | |
3f76745e JM |
2363 | static char * |
2364 | dwarf_tag_name (tag) | |
2365 | register unsigned tag; | |
bdb669cb | 2366 | { |
3f76745e JM |
2367 | switch (tag) |
2368 | { | |
2369 | case DW_TAG_padding: | |
2370 | return "DW_TAG_padding"; | |
2371 | case DW_TAG_array_type: | |
2372 | return "DW_TAG_array_type"; | |
2373 | case DW_TAG_class_type: | |
2374 | return "DW_TAG_class_type"; | |
2375 | case DW_TAG_entry_point: | |
2376 | return "DW_TAG_entry_point"; | |
2377 | case DW_TAG_enumeration_type: | |
2378 | return "DW_TAG_enumeration_type"; | |
2379 | case DW_TAG_formal_parameter: | |
2380 | return "DW_TAG_formal_parameter"; | |
2381 | case DW_TAG_imported_declaration: | |
2382 | return "DW_TAG_imported_declaration"; | |
2383 | case DW_TAG_label: | |
2384 | return "DW_TAG_label"; | |
2385 | case DW_TAG_lexical_block: | |
2386 | return "DW_TAG_lexical_block"; | |
2387 | case DW_TAG_member: | |
2388 | return "DW_TAG_member"; | |
2389 | case DW_TAG_pointer_type: | |
2390 | return "DW_TAG_pointer_type"; | |
2391 | case DW_TAG_reference_type: | |
2392 | return "DW_TAG_reference_type"; | |
2393 | case DW_TAG_compile_unit: | |
2394 | return "DW_TAG_compile_unit"; | |
2395 | case DW_TAG_string_type: | |
2396 | return "DW_TAG_string_type"; | |
2397 | case DW_TAG_structure_type: | |
2398 | return "DW_TAG_structure_type"; | |
2399 | case DW_TAG_subroutine_type: | |
2400 | return "DW_TAG_subroutine_type"; | |
2401 | case DW_TAG_typedef: | |
2402 | return "DW_TAG_typedef"; | |
2403 | case DW_TAG_union_type: | |
2404 | return "DW_TAG_union_type"; | |
2405 | case DW_TAG_unspecified_parameters: | |
2406 | return "DW_TAG_unspecified_parameters"; | |
2407 | case DW_TAG_variant: | |
2408 | return "DW_TAG_variant"; | |
2409 | case DW_TAG_common_block: | |
2410 | return "DW_TAG_common_block"; | |
2411 | case DW_TAG_common_inclusion: | |
2412 | return "DW_TAG_common_inclusion"; | |
2413 | case DW_TAG_inheritance: | |
2414 | return "DW_TAG_inheritance"; | |
2415 | case DW_TAG_inlined_subroutine: | |
2416 | return "DW_TAG_inlined_subroutine"; | |
2417 | case DW_TAG_module: | |
2418 | return "DW_TAG_module"; | |
2419 | case DW_TAG_ptr_to_member_type: | |
2420 | return "DW_TAG_ptr_to_member_type"; | |
2421 | case DW_TAG_set_type: | |
2422 | return "DW_TAG_set_type"; | |
2423 | case DW_TAG_subrange_type: | |
2424 | return "DW_TAG_subrange_type"; | |
2425 | case DW_TAG_with_stmt: | |
2426 | return "DW_TAG_with_stmt"; | |
2427 | case DW_TAG_access_declaration: | |
2428 | return "DW_TAG_access_declaration"; | |
2429 | case DW_TAG_base_type: | |
2430 | return "DW_TAG_base_type"; | |
2431 | case DW_TAG_catch_block: | |
2432 | return "DW_TAG_catch_block"; | |
2433 | case DW_TAG_const_type: | |
2434 | return "DW_TAG_const_type"; | |
2435 | case DW_TAG_constant: | |
2436 | return "DW_TAG_constant"; | |
2437 | case DW_TAG_enumerator: | |
2438 | return "DW_TAG_enumerator"; | |
2439 | case DW_TAG_file_type: | |
2440 | return "DW_TAG_file_type"; | |
2441 | case DW_TAG_friend: | |
2442 | return "DW_TAG_friend"; | |
2443 | case DW_TAG_namelist: | |
2444 | return "DW_TAG_namelist"; | |
2445 | case DW_TAG_namelist_item: | |
2446 | return "DW_TAG_namelist_item"; | |
2447 | case DW_TAG_packed_type: | |
2448 | return "DW_TAG_packed_type"; | |
2449 | case DW_TAG_subprogram: | |
2450 | return "DW_TAG_subprogram"; | |
2451 | case DW_TAG_template_type_param: | |
2452 | return "DW_TAG_template_type_param"; | |
2453 | case DW_TAG_template_value_param: | |
2454 | return "DW_TAG_template_value_param"; | |
2455 | case DW_TAG_thrown_type: | |
2456 | return "DW_TAG_thrown_type"; | |
2457 | case DW_TAG_try_block: | |
2458 | return "DW_TAG_try_block"; | |
2459 | case DW_TAG_variant_part: | |
2460 | return "DW_TAG_variant_part"; | |
2461 | case DW_TAG_variable: | |
2462 | return "DW_TAG_variable"; | |
2463 | case DW_TAG_volatile_type: | |
2464 | return "DW_TAG_volatile_type"; | |
2465 | case DW_TAG_MIPS_loop: | |
2466 | return "DW_TAG_MIPS_loop"; | |
2467 | case DW_TAG_format_label: | |
2468 | return "DW_TAG_format_label"; | |
2469 | case DW_TAG_function_template: | |
2470 | return "DW_TAG_function_template"; | |
2471 | case DW_TAG_class_template: | |
2472 | return "DW_TAG_class_template"; | |
2473 | default: | |
2474 | return "DW_TAG_<unknown>"; | |
2475 | } | |
bdb669cb | 2476 | } |
a3f97cbb | 2477 | |
3f76745e | 2478 | /* Convert a DWARF attribute code into its string name. */ |
71dfc51f | 2479 | |
3f76745e JM |
2480 | static char * |
2481 | dwarf_attr_name (attr) | |
2482 | register unsigned attr; | |
4b674448 | 2483 | { |
3f76745e | 2484 | switch (attr) |
4b674448 | 2485 | { |
3f76745e JM |
2486 | case DW_AT_sibling: |
2487 | return "DW_AT_sibling"; | |
2488 | case DW_AT_location: | |
2489 | return "DW_AT_location"; | |
2490 | case DW_AT_name: | |
2491 | return "DW_AT_name"; | |
2492 | case DW_AT_ordering: | |
2493 | return "DW_AT_ordering"; | |
2494 | case DW_AT_subscr_data: | |
2495 | return "DW_AT_subscr_data"; | |
2496 | case DW_AT_byte_size: | |
2497 | return "DW_AT_byte_size"; | |
2498 | case DW_AT_bit_offset: | |
2499 | return "DW_AT_bit_offset"; | |
2500 | case DW_AT_bit_size: | |
2501 | return "DW_AT_bit_size"; | |
2502 | case DW_AT_element_list: | |
2503 | return "DW_AT_element_list"; | |
2504 | case DW_AT_stmt_list: | |
2505 | return "DW_AT_stmt_list"; | |
2506 | case DW_AT_low_pc: | |
2507 | return "DW_AT_low_pc"; | |
2508 | case DW_AT_high_pc: | |
2509 | return "DW_AT_high_pc"; | |
2510 | case DW_AT_language: | |
2511 | return "DW_AT_language"; | |
2512 | case DW_AT_member: | |
2513 | return "DW_AT_member"; | |
2514 | case DW_AT_discr: | |
2515 | return "DW_AT_discr"; | |
2516 | case DW_AT_discr_value: | |
2517 | return "DW_AT_discr_value"; | |
2518 | case DW_AT_visibility: | |
2519 | return "DW_AT_visibility"; | |
2520 | case DW_AT_import: | |
2521 | return "DW_AT_import"; | |
2522 | case DW_AT_string_length: | |
2523 | return "DW_AT_string_length"; | |
2524 | case DW_AT_common_reference: | |
2525 | return "DW_AT_common_reference"; | |
2526 | case DW_AT_comp_dir: | |
2527 | return "DW_AT_comp_dir"; | |
2528 | case DW_AT_const_value: | |
2529 | return "DW_AT_const_value"; | |
2530 | case DW_AT_containing_type: | |
2531 | return "DW_AT_containing_type"; | |
2532 | case DW_AT_default_value: | |
2533 | return "DW_AT_default_value"; | |
2534 | case DW_AT_inline: | |
2535 | return "DW_AT_inline"; | |
2536 | case DW_AT_is_optional: | |
2537 | return "DW_AT_is_optional"; | |
2538 | case DW_AT_lower_bound: | |
2539 | return "DW_AT_lower_bound"; | |
2540 | case DW_AT_producer: | |
2541 | return "DW_AT_producer"; | |
2542 | case DW_AT_prototyped: | |
2543 | return "DW_AT_prototyped"; | |
2544 | case DW_AT_return_addr: | |
2545 | return "DW_AT_return_addr"; | |
2546 | case DW_AT_start_scope: | |
2547 | return "DW_AT_start_scope"; | |
2548 | case DW_AT_stride_size: | |
2549 | return "DW_AT_stride_size"; | |
2550 | case DW_AT_upper_bound: | |
2551 | return "DW_AT_upper_bound"; | |
2552 | case DW_AT_abstract_origin: | |
2553 | return "DW_AT_abstract_origin"; | |
2554 | case DW_AT_accessibility: | |
2555 | return "DW_AT_accessibility"; | |
2556 | case DW_AT_address_class: | |
2557 | return "DW_AT_address_class"; | |
2558 | case DW_AT_artificial: | |
2559 | return "DW_AT_artificial"; | |
2560 | case DW_AT_base_types: | |
2561 | return "DW_AT_base_types"; | |
2562 | case DW_AT_calling_convention: | |
2563 | return "DW_AT_calling_convention"; | |
2564 | case DW_AT_count: | |
2565 | return "DW_AT_count"; | |
2566 | case DW_AT_data_member_location: | |
2567 | return "DW_AT_data_member_location"; | |
2568 | case DW_AT_decl_column: | |
2569 | return "DW_AT_decl_column"; | |
2570 | case DW_AT_decl_file: | |
2571 | return "DW_AT_decl_file"; | |
2572 | case DW_AT_decl_line: | |
2573 | return "DW_AT_decl_line"; | |
2574 | case DW_AT_declaration: | |
2575 | return "DW_AT_declaration"; | |
2576 | case DW_AT_discr_list: | |
2577 | return "DW_AT_discr_list"; | |
2578 | case DW_AT_encoding: | |
2579 | return "DW_AT_encoding"; | |
2580 | case DW_AT_external: | |
2581 | return "DW_AT_external"; | |
2582 | case DW_AT_frame_base: | |
2583 | return "DW_AT_frame_base"; | |
2584 | case DW_AT_friend: | |
2585 | return "DW_AT_friend"; | |
2586 | case DW_AT_identifier_case: | |
2587 | return "DW_AT_identifier_case"; | |
2588 | case DW_AT_macro_info: | |
2589 | return "DW_AT_macro_info"; | |
2590 | case DW_AT_namelist_items: | |
2591 | return "DW_AT_namelist_items"; | |
2592 | case DW_AT_priority: | |
2593 | return "DW_AT_priority"; | |
2594 | case DW_AT_segment: | |
2595 | return "DW_AT_segment"; | |
2596 | case DW_AT_specification: | |
2597 | return "DW_AT_specification"; | |
2598 | case DW_AT_static_link: | |
2599 | return "DW_AT_static_link"; | |
2600 | case DW_AT_type: | |
2601 | return "DW_AT_type"; | |
2602 | case DW_AT_use_location: | |
2603 | return "DW_AT_use_location"; | |
2604 | case DW_AT_variable_parameter: | |
2605 | return "DW_AT_variable_parameter"; | |
2606 | case DW_AT_virtuality: | |
2607 | return "DW_AT_virtuality"; | |
2608 | case DW_AT_vtable_elem_location: | |
2609 | return "DW_AT_vtable_elem_location"; | |
71dfc51f | 2610 | |
3f76745e JM |
2611 | case DW_AT_MIPS_fde: |
2612 | return "DW_AT_MIPS_fde"; | |
2613 | case DW_AT_MIPS_loop_begin: | |
2614 | return "DW_AT_MIPS_loop_begin"; | |
2615 | case DW_AT_MIPS_tail_loop_begin: | |
2616 | return "DW_AT_MIPS_tail_loop_begin"; | |
2617 | case DW_AT_MIPS_epilog_begin: | |
2618 | return "DW_AT_MIPS_epilog_begin"; | |
2619 | case DW_AT_MIPS_loop_unroll_factor: | |
2620 | return "DW_AT_MIPS_loop_unroll_factor"; | |
2621 | case DW_AT_MIPS_software_pipeline_depth: | |
2622 | return "DW_AT_MIPS_software_pipeline_depth"; | |
2623 | case DW_AT_MIPS_linkage_name: | |
2624 | return "DW_AT_MIPS_linkage_name"; | |
2625 | case DW_AT_MIPS_stride: | |
2626 | return "DW_AT_MIPS_stride"; | |
2627 | case DW_AT_MIPS_abstract_name: | |
2628 | return "DW_AT_MIPS_abstract_name"; | |
2629 | case DW_AT_MIPS_clone_origin: | |
2630 | return "DW_AT_MIPS_clone_origin"; | |
2631 | case DW_AT_MIPS_has_inlines: | |
2632 | return "DW_AT_MIPS_has_inlines"; | |
71dfc51f | 2633 | |
3f76745e JM |
2634 | case DW_AT_sf_names: |
2635 | return "DW_AT_sf_names"; | |
2636 | case DW_AT_src_info: | |
2637 | return "DW_AT_src_info"; | |
2638 | case DW_AT_mac_info: | |
2639 | return "DW_AT_mac_info"; | |
2640 | case DW_AT_src_coords: | |
2641 | return "DW_AT_src_coords"; | |
2642 | case DW_AT_body_begin: | |
2643 | return "DW_AT_body_begin"; | |
2644 | case DW_AT_body_end: | |
2645 | return "DW_AT_body_end"; | |
2646 | default: | |
2647 | return "DW_AT_<unknown>"; | |
4b674448 JM |
2648 | } |
2649 | } | |
2650 | ||
3f76745e | 2651 | /* Convert a DWARF value form code into its string name. */ |
71dfc51f | 2652 | |
3f76745e JM |
2653 | static char * |
2654 | dwarf_form_name (form) | |
2655 | register unsigned form; | |
4b674448 | 2656 | { |
3f76745e | 2657 | switch (form) |
4b674448 | 2658 | { |
3f76745e JM |
2659 | case DW_FORM_addr: |
2660 | return "DW_FORM_addr"; | |
2661 | case DW_FORM_block2: | |
2662 | return "DW_FORM_block2"; | |
2663 | case DW_FORM_block4: | |
2664 | return "DW_FORM_block4"; | |
2665 | case DW_FORM_data2: | |
2666 | return "DW_FORM_data2"; | |
2667 | case DW_FORM_data4: | |
2668 | return "DW_FORM_data4"; | |
2669 | case DW_FORM_data8: | |
2670 | return "DW_FORM_data8"; | |
2671 | case DW_FORM_string: | |
2672 | return "DW_FORM_string"; | |
2673 | case DW_FORM_block: | |
2674 | return "DW_FORM_block"; | |
2675 | case DW_FORM_block1: | |
2676 | return "DW_FORM_block1"; | |
2677 | case DW_FORM_data1: | |
2678 | return "DW_FORM_data1"; | |
2679 | case DW_FORM_flag: | |
2680 | return "DW_FORM_flag"; | |
2681 | case DW_FORM_sdata: | |
2682 | return "DW_FORM_sdata"; | |
2683 | case DW_FORM_strp: | |
2684 | return "DW_FORM_strp"; | |
2685 | case DW_FORM_udata: | |
2686 | return "DW_FORM_udata"; | |
2687 | case DW_FORM_ref_addr: | |
2688 | return "DW_FORM_ref_addr"; | |
2689 | case DW_FORM_ref1: | |
2690 | return "DW_FORM_ref1"; | |
2691 | case DW_FORM_ref2: | |
2692 | return "DW_FORM_ref2"; | |
2693 | case DW_FORM_ref4: | |
2694 | return "DW_FORM_ref4"; | |
2695 | case DW_FORM_ref8: | |
2696 | return "DW_FORM_ref8"; | |
2697 | case DW_FORM_ref_udata: | |
2698 | return "DW_FORM_ref_udata"; | |
2699 | case DW_FORM_indirect: | |
2700 | return "DW_FORM_indirect"; | |
2701 | default: | |
2702 | return "DW_FORM_<unknown>"; | |
4b674448 JM |
2703 | } |
2704 | } | |
2705 | ||
3f76745e | 2706 | /* Convert a DWARF stack opcode into its string name. */ |
71dfc51f | 2707 | |
3f76745e JM |
2708 | static char * |
2709 | dwarf_stack_op_name (op) | |
2710 | register unsigned op; | |
a3f97cbb | 2711 | { |
3f76745e | 2712 | switch (op) |
a3f97cbb | 2713 | { |
3f76745e JM |
2714 | case DW_OP_addr: |
2715 | return "DW_OP_addr"; | |
2716 | case DW_OP_deref: | |
2717 | return "DW_OP_deref"; | |
2718 | case DW_OP_const1u: | |
2719 | return "DW_OP_const1u"; | |
2720 | case DW_OP_const1s: | |
2721 | return "DW_OP_const1s"; | |
2722 | case DW_OP_const2u: | |
2723 | return "DW_OP_const2u"; | |
2724 | case DW_OP_const2s: | |
2725 | return "DW_OP_const2s"; | |
2726 | case DW_OP_const4u: | |
2727 | return "DW_OP_const4u"; | |
2728 | case DW_OP_const4s: | |
2729 | return "DW_OP_const4s"; | |
2730 | case DW_OP_const8u: | |
2731 | return "DW_OP_const8u"; | |
2732 | case DW_OP_const8s: | |
2733 | return "DW_OP_const8s"; | |
2734 | case DW_OP_constu: | |
2735 | return "DW_OP_constu"; | |
2736 | case DW_OP_consts: | |
2737 | return "DW_OP_consts"; | |
2738 | case DW_OP_dup: | |
2739 | return "DW_OP_dup"; | |
2740 | case DW_OP_drop: | |
2741 | return "DW_OP_drop"; | |
2742 | case DW_OP_over: | |
2743 | return "DW_OP_over"; | |
2744 | case DW_OP_pick: | |
2745 | return "DW_OP_pick"; | |
2746 | case DW_OP_swap: | |
2747 | return "DW_OP_swap"; | |
2748 | case DW_OP_rot: | |
2749 | return "DW_OP_rot"; | |
2750 | case DW_OP_xderef: | |
2751 | return "DW_OP_xderef"; | |
2752 | case DW_OP_abs: | |
2753 | return "DW_OP_abs"; | |
2754 | case DW_OP_and: | |
2755 | return "DW_OP_and"; | |
2756 | case DW_OP_div: | |
2757 | return "DW_OP_div"; | |
2758 | case DW_OP_minus: | |
2759 | return "DW_OP_minus"; | |
2760 | case DW_OP_mod: | |
2761 | return "DW_OP_mod"; | |
2762 | case DW_OP_mul: | |
2763 | return "DW_OP_mul"; | |
2764 | case DW_OP_neg: | |
2765 | return "DW_OP_neg"; | |
2766 | case DW_OP_not: | |
2767 | return "DW_OP_not"; | |
2768 | case DW_OP_or: | |
2769 | return "DW_OP_or"; | |
2770 | case DW_OP_plus: | |
2771 | return "DW_OP_plus"; | |
2772 | case DW_OP_plus_uconst: | |
2773 | return "DW_OP_plus_uconst"; | |
2774 | case DW_OP_shl: | |
2775 | return "DW_OP_shl"; | |
2776 | case DW_OP_shr: | |
2777 | return "DW_OP_shr"; | |
2778 | case DW_OP_shra: | |
2779 | return "DW_OP_shra"; | |
2780 | case DW_OP_xor: | |
2781 | return "DW_OP_xor"; | |
2782 | case DW_OP_bra: | |
2783 | return "DW_OP_bra"; | |
2784 | case DW_OP_eq: | |
2785 | return "DW_OP_eq"; | |
2786 | case DW_OP_ge: | |
2787 | return "DW_OP_ge"; | |
2788 | case DW_OP_gt: | |
2789 | return "DW_OP_gt"; | |
2790 | case DW_OP_le: | |
2791 | return "DW_OP_le"; | |
2792 | case DW_OP_lt: | |
2793 | return "DW_OP_lt"; | |
2794 | case DW_OP_ne: | |
2795 | return "DW_OP_ne"; | |
2796 | case DW_OP_skip: | |
2797 | return "DW_OP_skip"; | |
2798 | case DW_OP_lit0: | |
2799 | return "DW_OP_lit0"; | |
2800 | case DW_OP_lit1: | |
2801 | return "DW_OP_lit1"; | |
2802 | case DW_OP_lit2: | |
2803 | return "DW_OP_lit2"; | |
2804 | case DW_OP_lit3: | |
2805 | return "DW_OP_lit3"; | |
2806 | case DW_OP_lit4: | |
2807 | return "DW_OP_lit4"; | |
2808 | case DW_OP_lit5: | |
2809 | return "DW_OP_lit5"; | |
2810 | case DW_OP_lit6: | |
2811 | return "DW_OP_lit6"; | |
2812 | case DW_OP_lit7: | |
2813 | return "DW_OP_lit7"; | |
2814 | case DW_OP_lit8: | |
2815 | return "DW_OP_lit8"; | |
2816 | case DW_OP_lit9: | |
2817 | return "DW_OP_lit9"; | |
2818 | case DW_OP_lit10: | |
2819 | return "DW_OP_lit10"; | |
2820 | case DW_OP_lit11: | |
2821 | return "DW_OP_lit11"; | |
2822 | case DW_OP_lit12: | |
2823 | return "DW_OP_lit12"; | |
2824 | case DW_OP_lit13: | |
2825 | return "DW_OP_lit13"; | |
2826 | case DW_OP_lit14: | |
2827 | return "DW_OP_lit14"; | |
2828 | case DW_OP_lit15: | |
2829 | return "DW_OP_lit15"; | |
2830 | case DW_OP_lit16: | |
2831 | return "DW_OP_lit16"; | |
2832 | case DW_OP_lit17: | |
2833 | return "DW_OP_lit17"; | |
2834 | case DW_OP_lit18: | |
2835 | return "DW_OP_lit18"; | |
2836 | case DW_OP_lit19: | |
2837 | return "DW_OP_lit19"; | |
2838 | case DW_OP_lit20: | |
2839 | return "DW_OP_lit20"; | |
2840 | case DW_OP_lit21: | |
2841 | return "DW_OP_lit21"; | |
2842 | case DW_OP_lit22: | |
2843 | return "DW_OP_lit22"; | |
2844 | case DW_OP_lit23: | |
2845 | return "DW_OP_lit23"; | |
2846 | case DW_OP_lit24: | |
2847 | return "DW_OP_lit24"; | |
2848 | case DW_OP_lit25: | |
2849 | return "DW_OP_lit25"; | |
2850 | case DW_OP_lit26: | |
2851 | return "DW_OP_lit26"; | |
2852 | case DW_OP_lit27: | |
2853 | return "DW_OP_lit27"; | |
2854 | case DW_OP_lit28: | |
2855 | return "DW_OP_lit28"; | |
2856 | case DW_OP_lit29: | |
2857 | return "DW_OP_lit29"; | |
2858 | case DW_OP_lit30: | |
2859 | return "DW_OP_lit30"; | |
2860 | case DW_OP_lit31: | |
2861 | return "DW_OP_lit31"; | |
2862 | case DW_OP_reg0: | |
2863 | return "DW_OP_reg0"; | |
2864 | case DW_OP_reg1: | |
2865 | return "DW_OP_reg1"; | |
2866 | case DW_OP_reg2: | |
2867 | return "DW_OP_reg2"; | |
2868 | case DW_OP_reg3: | |
2869 | return "DW_OP_reg3"; | |
2870 | case DW_OP_reg4: | |
2871 | return "DW_OP_reg4"; | |
2872 | case DW_OP_reg5: | |
2873 | return "DW_OP_reg5"; | |
2874 | case DW_OP_reg6: | |
2875 | return "DW_OP_reg6"; | |
2876 | case DW_OP_reg7: | |
2877 | return "DW_OP_reg7"; | |
2878 | case DW_OP_reg8: | |
2879 | return "DW_OP_reg8"; | |
2880 | case DW_OP_reg9: | |
2881 | return "DW_OP_reg9"; | |
2882 | case DW_OP_reg10: | |
2883 | return "DW_OP_reg10"; | |
2884 | case DW_OP_reg11: | |
2885 | return "DW_OP_reg11"; | |
2886 | case DW_OP_reg12: | |
2887 | return "DW_OP_reg12"; | |
2888 | case DW_OP_reg13: | |
2889 | return "DW_OP_reg13"; | |
2890 | case DW_OP_reg14: | |
2891 | return "DW_OP_reg14"; | |
2892 | case DW_OP_reg15: | |
2893 | return "DW_OP_reg15"; | |
2894 | case DW_OP_reg16: | |
2895 | return "DW_OP_reg16"; | |
2896 | case DW_OP_reg17: | |
2897 | return "DW_OP_reg17"; | |
2898 | case DW_OP_reg18: | |
2899 | return "DW_OP_reg18"; | |
2900 | case DW_OP_reg19: | |
2901 | return "DW_OP_reg19"; | |
2902 | case DW_OP_reg20: | |
2903 | return "DW_OP_reg20"; | |
2904 | case DW_OP_reg21: | |
2905 | return "DW_OP_reg21"; | |
2906 | case DW_OP_reg22: | |
2907 | return "DW_OP_reg22"; | |
2908 | case DW_OP_reg23: | |
2909 | return "DW_OP_reg23"; | |
2910 | case DW_OP_reg24: | |
2911 | return "DW_OP_reg24"; | |
2912 | case DW_OP_reg25: | |
2913 | return "DW_OP_reg25"; | |
2914 | case DW_OP_reg26: | |
2915 | return "DW_OP_reg26"; | |
2916 | case DW_OP_reg27: | |
2917 | return "DW_OP_reg27"; | |
2918 | case DW_OP_reg28: | |
2919 | return "DW_OP_reg28"; | |
2920 | case DW_OP_reg29: | |
2921 | return "DW_OP_reg29"; | |
2922 | case DW_OP_reg30: | |
2923 | return "DW_OP_reg30"; | |
2924 | case DW_OP_reg31: | |
2925 | return "DW_OP_reg31"; | |
2926 | case DW_OP_breg0: | |
2927 | return "DW_OP_breg0"; | |
2928 | case DW_OP_breg1: | |
2929 | return "DW_OP_breg1"; | |
2930 | case DW_OP_breg2: | |
2931 | return "DW_OP_breg2"; | |
2932 | case DW_OP_breg3: | |
2933 | return "DW_OP_breg3"; | |
2934 | case DW_OP_breg4: | |
2935 | return "DW_OP_breg4"; | |
2936 | case DW_OP_breg5: | |
2937 | return "DW_OP_breg5"; | |
2938 | case DW_OP_breg6: | |
2939 | return "DW_OP_breg6"; | |
2940 | case DW_OP_breg7: | |
2941 | return "DW_OP_breg7"; | |
2942 | case DW_OP_breg8: | |
2943 | return "DW_OP_breg8"; | |
2944 | case DW_OP_breg9: | |
2945 | return "DW_OP_breg9"; | |
2946 | case DW_OP_breg10: | |
2947 | return "DW_OP_breg10"; | |
2948 | case DW_OP_breg11: | |
2949 | return "DW_OP_breg11"; | |
2950 | case DW_OP_breg12: | |
2951 | return "DW_OP_breg12"; | |
2952 | case DW_OP_breg13: | |
2953 | return "DW_OP_breg13"; | |
2954 | case DW_OP_breg14: | |
2955 | return "DW_OP_breg14"; | |
2956 | case DW_OP_breg15: | |
2957 | return "DW_OP_breg15"; | |
2958 | case DW_OP_breg16: | |
2959 | return "DW_OP_breg16"; | |
2960 | case DW_OP_breg17: | |
2961 | return "DW_OP_breg17"; | |
2962 | case DW_OP_breg18: | |
2963 | return "DW_OP_breg18"; | |
2964 | case DW_OP_breg19: | |
2965 | return "DW_OP_breg19"; | |
2966 | case DW_OP_breg20: | |
2967 | return "DW_OP_breg20"; | |
2968 | case DW_OP_breg21: | |
2969 | return "DW_OP_breg21"; | |
2970 | case DW_OP_breg22: | |
2971 | return "DW_OP_breg22"; | |
2972 | case DW_OP_breg23: | |
2973 | return "DW_OP_breg23"; | |
2974 | case DW_OP_breg24: | |
2975 | return "DW_OP_breg24"; | |
2976 | case DW_OP_breg25: | |
2977 | return "DW_OP_breg25"; | |
2978 | case DW_OP_breg26: | |
2979 | return "DW_OP_breg26"; | |
2980 | case DW_OP_breg27: | |
2981 | return "DW_OP_breg27"; | |
2982 | case DW_OP_breg28: | |
2983 | return "DW_OP_breg28"; | |
2984 | case DW_OP_breg29: | |
2985 | return "DW_OP_breg29"; | |
2986 | case DW_OP_breg30: | |
2987 | return "DW_OP_breg30"; | |
2988 | case DW_OP_breg31: | |
2989 | return "DW_OP_breg31"; | |
2990 | case DW_OP_regx: | |
2991 | return "DW_OP_regx"; | |
2992 | case DW_OP_fbreg: | |
2993 | return "DW_OP_fbreg"; | |
2994 | case DW_OP_bregx: | |
2995 | return "DW_OP_bregx"; | |
2996 | case DW_OP_piece: | |
2997 | return "DW_OP_piece"; | |
2998 | case DW_OP_deref_size: | |
2999 | return "DW_OP_deref_size"; | |
3000 | case DW_OP_xderef_size: | |
3001 | return "DW_OP_xderef_size"; | |
3002 | case DW_OP_nop: | |
3003 | return "DW_OP_nop"; | |
3004 | default: | |
3005 | return "OP_<unknown>"; | |
a3f97cbb JW |
3006 | } |
3007 | } | |
3008 | ||
3f76745e | 3009 | /* Convert a DWARF type code into its string name. */ |
71dfc51f | 3010 | |
3f76745e JM |
3011 | static char * |
3012 | dwarf_type_encoding_name (enc) | |
3013 | register unsigned enc; | |
a3f97cbb | 3014 | { |
3f76745e | 3015 | switch (enc) |
a3f97cbb | 3016 | { |
3f76745e JM |
3017 | case DW_ATE_address: |
3018 | return "DW_ATE_address"; | |
3019 | case DW_ATE_boolean: | |
3020 | return "DW_ATE_boolean"; | |
3021 | case DW_ATE_complex_float: | |
3022 | return "DW_ATE_complex_float"; | |
3023 | case DW_ATE_float: | |
3024 | return "DW_ATE_float"; | |
3025 | case DW_ATE_signed: | |
3026 | return "DW_ATE_signed"; | |
3027 | case DW_ATE_signed_char: | |
3028 | return "DW_ATE_signed_char"; | |
3029 | case DW_ATE_unsigned: | |
3030 | return "DW_ATE_unsigned"; | |
3031 | case DW_ATE_unsigned_char: | |
3032 | return "DW_ATE_unsigned_char"; | |
3033 | default: | |
3034 | return "DW_ATE_<unknown>"; | |
3035 | } | |
a3f97cbb | 3036 | } |
3f76745e JM |
3037 | \f |
3038 | /* Determine the "ultimate origin" of a decl. The decl may be an inlined | |
3039 | instance of an inlined instance of a decl which is local to an inline | |
3040 | function, so we have to trace all of the way back through the origin chain | |
3041 | to find out what sort of node actually served as the original seed for the | |
3042 | given block. */ | |
a3f97cbb | 3043 | |
3f76745e JM |
3044 | static tree |
3045 | decl_ultimate_origin (decl) | |
3046 | register tree decl; | |
a3f97cbb | 3047 | { |
3f76745e | 3048 | register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl); |
71dfc51f | 3049 | |
3f76745e JM |
3050 | if (immediate_origin == NULL_TREE) |
3051 | return NULL_TREE; | |
3052 | else | |
3053 | { | |
3054 | register tree ret_val; | |
3055 | register tree lookahead = immediate_origin; | |
71dfc51f | 3056 | |
3f76745e JM |
3057 | do |
3058 | { | |
3059 | ret_val = lookahead; | |
3060 | lookahead = DECL_ABSTRACT_ORIGIN (ret_val); | |
3061 | } | |
3062 | while (lookahead != NULL && lookahead != ret_val); | |
3063 | ||
3064 | return ret_val; | |
3065 | } | |
a3f97cbb JW |
3066 | } |
3067 | ||
3f76745e JM |
3068 | /* Determine the "ultimate origin" of a block. The block may be an inlined |
3069 | instance of an inlined instance of a block which is local to an inline | |
3070 | function, so we have to trace all of the way back through the origin chain | |
3071 | to find out what sort of node actually served as the original seed for the | |
3072 | given block. */ | |
71dfc51f | 3073 | |
3f76745e JM |
3074 | static tree |
3075 | block_ultimate_origin (block) | |
3076 | register tree block; | |
a3f97cbb | 3077 | { |
3f76745e | 3078 | register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); |
71dfc51f | 3079 | |
3f76745e JM |
3080 | if (immediate_origin == NULL_TREE) |
3081 | return NULL_TREE; | |
3082 | else | |
3083 | { | |
3084 | register tree ret_val; | |
3085 | register tree lookahead = immediate_origin; | |
71dfc51f | 3086 | |
3f76745e JM |
3087 | do |
3088 | { | |
3089 | ret_val = lookahead; | |
3090 | lookahead = (TREE_CODE (ret_val) == BLOCK) | |
3091 | ? BLOCK_ABSTRACT_ORIGIN (ret_val) | |
3092 | : NULL; | |
3093 | } | |
3094 | while (lookahead != NULL && lookahead != ret_val); | |
3095 | ||
3096 | return ret_val; | |
3097 | } | |
a3f97cbb JW |
3098 | } |
3099 | ||
3f76745e JM |
3100 | /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT |
3101 | of a virtual function may refer to a base class, so we check the 'this' | |
3102 | parameter. */ | |
71dfc51f | 3103 | |
3f76745e JM |
3104 | static tree |
3105 | decl_class_context (decl) | |
3106 | tree decl; | |
a3f97cbb | 3107 | { |
3f76745e | 3108 | tree context = NULL_TREE; |
71dfc51f | 3109 | |
3f76745e JM |
3110 | if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl)) |
3111 | context = DECL_CONTEXT (decl); | |
3112 | else | |
3113 | context = TYPE_MAIN_VARIANT | |
3114 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
71dfc51f | 3115 | |
3f76745e JM |
3116 | if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't') |
3117 | context = NULL_TREE; | |
3118 | ||
3119 | return context; | |
a3f97cbb JW |
3120 | } |
3121 | \f | |
3f76745e | 3122 | /* Add an attribute/value pair to a DIE */ |
71dfc51f RK |
3123 | |
3124 | static inline void | |
3f76745e JM |
3125 | add_dwarf_attr (die, attr) |
3126 | register dw_die_ref die; | |
3127 | register dw_attr_ref attr; | |
a3f97cbb | 3128 | { |
3f76745e | 3129 | if (die != NULL && attr != NULL) |
a3f97cbb | 3130 | { |
3f76745e | 3131 | if (die->die_attr == NULL) |
a3f97cbb | 3132 | { |
3f76745e JM |
3133 | die->die_attr = attr; |
3134 | die->die_attr_last = attr; | |
3135 | } | |
3136 | else | |
3137 | { | |
3138 | die->die_attr_last->dw_attr_next = attr; | |
3139 | die->die_attr_last = attr; | |
a3f97cbb | 3140 | } |
a3f97cbb JW |
3141 | } |
3142 | } | |
3143 | ||
3f76745e | 3144 | /* Add a flag value attribute to a DIE. */ |
71dfc51f | 3145 | |
3f76745e JM |
3146 | static inline void |
3147 | add_AT_flag (die, attr_kind, flag) | |
3148 | register dw_die_ref die; | |
3149 | register enum dwarf_attribute attr_kind; | |
3150 | register unsigned flag; | |
a3f97cbb | 3151 | { |
3f76745e | 3152 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3153 | |
3f76745e JM |
3154 | attr->dw_attr_next = NULL; |
3155 | attr->dw_attr = attr_kind; | |
3156 | attr->dw_attr_val.val_class = dw_val_class_flag; | |
3157 | attr->dw_attr_val.v.val_flag = flag; | |
3158 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3159 | } |
3160 | ||
3f76745e | 3161 | /* Add a signed integer attribute value to a DIE. */ |
71dfc51f | 3162 | |
3f76745e JM |
3163 | static inline void |
3164 | add_AT_int (die, attr_kind, int_val) | |
3165 | register dw_die_ref die; | |
3166 | register enum dwarf_attribute attr_kind; | |
3167 | register long int int_val; | |
a3f97cbb | 3168 | { |
3f76745e JM |
3169 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3170 | ||
3171 | attr->dw_attr_next = NULL; | |
3172 | attr->dw_attr = attr_kind; | |
3173 | attr->dw_attr_val.val_class = dw_val_class_const; | |
3174 | attr->dw_attr_val.v.val_int = int_val; | |
3175 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3176 | } |
3177 | ||
3f76745e | 3178 | /* Add an unsigned integer attribute value to a DIE. */ |
71dfc51f | 3179 | |
3f76745e JM |
3180 | static inline void |
3181 | add_AT_unsigned (die, attr_kind, unsigned_val) | |
3182 | register dw_die_ref die; | |
3183 | register enum dwarf_attribute attr_kind; | |
3184 | register unsigned long unsigned_val; | |
a3f97cbb | 3185 | { |
3f76745e JM |
3186 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
3187 | ||
3188 | attr->dw_attr_next = NULL; | |
3189 | attr->dw_attr = attr_kind; | |
3190 | attr->dw_attr_val.val_class = dw_val_class_unsigned_const; | |
3191 | attr->dw_attr_val.v.val_unsigned = unsigned_val; | |
3192 | add_dwarf_attr (die, attr); | |
a3f97cbb | 3193 | } |
71dfc51f | 3194 | |
3f76745e JM |
3195 | /* Add an unsigned double integer attribute value to a DIE. */ |
3196 | ||
3197 | static inline void | |
3198 | add_AT_long_long (die, attr_kind, val_hi, val_low) | |
a3f97cbb | 3199 | register dw_die_ref die; |
3f76745e JM |
3200 | register enum dwarf_attribute attr_kind; |
3201 | register unsigned long val_hi; | |
3202 | register unsigned long val_low; | |
a3f97cbb | 3203 | { |
3f76745e | 3204 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3205 | |
3f76745e JM |
3206 | attr->dw_attr_next = NULL; |
3207 | attr->dw_attr = attr_kind; | |
3208 | attr->dw_attr_val.val_class = dw_val_class_long_long; | |
3209 | attr->dw_attr_val.v.val_long_long.hi = val_hi; | |
3210 | attr->dw_attr_val.v.val_long_long.low = val_low; | |
3211 | add_dwarf_attr (die, attr); | |
3212 | } | |
71dfc51f | 3213 | |
3f76745e | 3214 | /* Add a floating point attribute value to a DIE and return it. */ |
71dfc51f | 3215 | |
3f76745e JM |
3216 | static inline void |
3217 | add_AT_float (die, attr_kind, length, array) | |
3218 | register dw_die_ref die; | |
3219 | register enum dwarf_attribute attr_kind; | |
3220 | register unsigned length; | |
3221 | register long *array; | |
3222 | { | |
3223 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
3224 | ||
3225 | attr->dw_attr_next = NULL; | |
3226 | attr->dw_attr = attr_kind; | |
3227 | attr->dw_attr_val.val_class = dw_val_class_float; | |
3228 | attr->dw_attr_val.v.val_float.length = length; | |
3229 | attr->dw_attr_val.v.val_float.array = array; | |
3230 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3231 | } |
3232 | ||
3f76745e | 3233 | /* Add a string attribute value to a DIE. */ |
71dfc51f | 3234 | |
3f76745e JM |
3235 | static inline void |
3236 | add_AT_string (die, attr_kind, str) | |
a3f97cbb | 3237 | register dw_die_ref die; |
3f76745e JM |
3238 | register enum dwarf_attribute attr_kind; |
3239 | register char *str; | |
a3f97cbb | 3240 | { |
3f76745e | 3241 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3242 | |
3f76745e JM |
3243 | attr->dw_attr_next = NULL; |
3244 | attr->dw_attr = attr_kind; | |
3245 | attr->dw_attr_val.val_class = dw_val_class_str; | |
3246 | attr->dw_attr_val.v.val_str = xstrdup (str); | |
3247 | add_dwarf_attr (die, attr); | |
3248 | } | |
71dfc51f | 3249 | |
3f76745e | 3250 | /* Add a DIE reference attribute value to a DIE. */ |
71dfc51f | 3251 | |
3f76745e JM |
3252 | static inline void |
3253 | add_AT_die_ref (die, attr_kind, targ_die) | |
3254 | register dw_die_ref die; | |
3255 | register enum dwarf_attribute attr_kind; | |
3256 | register dw_die_ref targ_die; | |
3257 | { | |
3258 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 3259 | |
3f76745e JM |
3260 | attr->dw_attr_next = NULL; |
3261 | attr->dw_attr = attr_kind; | |
3262 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
3263 | attr->dw_attr_val.v.val_die_ref = targ_die; | |
3264 | add_dwarf_attr (die, attr); | |
3265 | } | |
b1ccbc24 | 3266 | |
3f76745e | 3267 | /* Add an FDE reference attribute value to a DIE. */ |
b1ccbc24 | 3268 | |
3f76745e JM |
3269 | static inline void |
3270 | add_AT_fde_ref (die, attr_kind, targ_fde) | |
3271 | register dw_die_ref die; | |
3272 | register enum dwarf_attribute attr_kind; | |
3273 | register unsigned targ_fde; | |
3274 | { | |
3275 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
b1ccbc24 | 3276 | |
3f76745e JM |
3277 | attr->dw_attr_next = NULL; |
3278 | attr->dw_attr = attr_kind; | |
3279 | attr->dw_attr_val.val_class = dw_val_class_fde_ref; | |
3280 | attr->dw_attr_val.v.val_fde_index = targ_fde; | |
3281 | add_dwarf_attr (die, attr); | |
a3f97cbb | 3282 | } |
71dfc51f | 3283 | |
3f76745e | 3284 | /* Add a location description attribute value to a DIE. */ |
71dfc51f | 3285 | |
3f76745e JM |
3286 | static inline void |
3287 | add_AT_loc (die, attr_kind, loc) | |
3288 | register dw_die_ref die; | |
3289 | register enum dwarf_attribute attr_kind; | |
3290 | register dw_loc_descr_ref loc; | |
3291 | { | |
3292 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 3293 | |
3f76745e JM |
3294 | attr->dw_attr_next = NULL; |
3295 | attr->dw_attr = attr_kind; | |
3296 | attr->dw_attr_val.val_class = dw_val_class_loc; | |
3297 | attr->dw_attr_val.v.val_loc = loc; | |
3298 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3299 | } |
3300 | ||
3f76745e | 3301 | /* Add an address constant attribute value to a DIE. */ |
71dfc51f | 3302 | |
3f76745e JM |
3303 | static inline void |
3304 | add_AT_addr (die, attr_kind, addr) | |
3305 | register dw_die_ref die; | |
3306 | register enum dwarf_attribute attr_kind; | |
3307 | char *addr; | |
a3f97cbb | 3308 | { |
3f76745e | 3309 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3310 | |
3f76745e JM |
3311 | attr->dw_attr_next = NULL; |
3312 | attr->dw_attr = attr_kind; | |
3313 | attr->dw_attr_val.val_class = dw_val_class_addr; | |
3314 | attr->dw_attr_val.v.val_addr = addr; | |
3315 | add_dwarf_attr (die, attr); | |
a3f97cbb JW |
3316 | } |
3317 | ||
3f76745e | 3318 | /* Add a label identifier attribute value to a DIE. */ |
71dfc51f | 3319 | |
3f76745e JM |
3320 | static inline void |
3321 | add_AT_lbl_id (die, attr_kind, lbl_id) | |
3322 | register dw_die_ref die; | |
3323 | register enum dwarf_attribute attr_kind; | |
3324 | register char *lbl_id; | |
a3f97cbb | 3325 | { |
3f76745e | 3326 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); |
71dfc51f | 3327 | |
3f76745e JM |
3328 | attr->dw_attr_next = NULL; |
3329 | attr->dw_attr = attr_kind; | |
3330 | attr->dw_attr_val.val_class = dw_val_class_lbl_id; | |
3331 | attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); | |
3332 | add_dwarf_attr (die, attr); | |
3333 | } | |
71dfc51f | 3334 | |
3f76745e JM |
3335 | /* Add a section offset attribute value to a DIE. */ |
3336 | ||
3337 | static inline void | |
3338 | add_AT_section_offset (die, attr_kind, section) | |
3339 | register dw_die_ref die; | |
3340 | register enum dwarf_attribute attr_kind; | |
3341 | register char *section; | |
3342 | { | |
3343 | register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
71dfc51f | 3344 | |
3f76745e JM |
3345 | attr->dw_attr_next = NULL; |
3346 | attr->dw_attr = attr_kind; | |
3347 | attr->dw_attr_val.val_class = dw_val_class_section_offset; | |
3348 | attr->dw_attr_val.v.val_section = section; | |
3349 | add_dwarf_attr (die, attr); | |
3350 | ||
a3f97cbb JW |
3351 | } |
3352 | ||
3f76745e | 3353 | /* Test if die refers to an external subroutine. */ |
71dfc51f | 3354 | |
3f76745e JM |
3355 | static inline int |
3356 | is_extern_subr_die (die) | |
3357 | register dw_die_ref die; | |
a3f97cbb | 3358 | { |
3f76745e JM |
3359 | register dw_attr_ref a; |
3360 | register int is_subr = FALSE; | |
3361 | register int is_extern = FALSE; | |
71dfc51f | 3362 | |
3f76745e | 3363 | if (die != NULL && die->die_tag == DW_TAG_subprogram) |
a3f97cbb | 3364 | { |
3f76745e JM |
3365 | is_subr = TRUE; |
3366 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
3367 | { | |
3368 | if (a->dw_attr == DW_AT_external | |
3369 | && a->dw_attr_val.val_class == dw_val_class_flag | |
3370 | && a->dw_attr_val.v.val_flag != 0) | |
3371 | { | |
3372 | is_extern = TRUE; | |
3373 | break; | |
3374 | } | |
3375 | } | |
a3f97cbb | 3376 | } |
71dfc51f | 3377 | |
3f76745e | 3378 | return is_subr && is_extern; |
a3f97cbb JW |
3379 | } |
3380 | ||
3f76745e | 3381 | /* Get the attribute of type attr_kind. */ |
71dfc51f | 3382 | |
3f76745e JM |
3383 | static inline dw_attr_ref |
3384 | get_AT (die, attr_kind) | |
3385 | register dw_die_ref die; | |
3386 | register enum dwarf_attribute attr_kind; | |
f37230f0 | 3387 | { |
3f76745e JM |
3388 | register dw_attr_ref a; |
3389 | register dw_die_ref spec = NULL; | |
3390 | ||
3391 | if (die != NULL) | |
3392 | { | |
3393 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
3394 | { | |
3395 | if (a->dw_attr == attr_kind) | |
3396 | return a; | |
71dfc51f | 3397 | |
3f76745e JM |
3398 | if (a->dw_attr == DW_AT_specification |
3399 | || a->dw_attr == DW_AT_abstract_origin) | |
3400 | spec = a->dw_attr_val.v.val_die_ref; | |
3401 | } | |
71dfc51f | 3402 | |
3f76745e JM |
3403 | if (spec) |
3404 | return get_AT (spec, attr_kind); | |
3405 | } | |
3406 | ||
3407 | return NULL; | |
f37230f0 JM |
3408 | } |
3409 | ||
3f76745e JM |
3410 | /* Return the "low pc" attribute value, typically associated with |
3411 | a subprogram DIE. Return null if the "low pc" attribute is | |
3412 | either not prsent, or if it cannot be represented as an | |
3413 | assembler label identifier. */ | |
71dfc51f | 3414 | |
3f76745e JM |
3415 | static inline char * |
3416 | get_AT_low_pc (die) | |
3417 | register dw_die_ref die; | |
7e23cb16 | 3418 | { |
3f76745e | 3419 | register dw_attr_ref a = get_AT (die, DW_AT_low_pc); |
7e23cb16 | 3420 | |
3f76745e JM |
3421 | if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id) |
3422 | return a->dw_attr_val.v.val_lbl_id; | |
7e23cb16 | 3423 | |
3f76745e | 3424 | return NULL; |
7e23cb16 JM |
3425 | } |
3426 | ||
3f76745e JM |
3427 | /* Return the "high pc" attribute value, typically associated with |
3428 | a subprogram DIE. Return null if the "high pc" attribute is | |
3429 | either not prsent, or if it cannot be represented as an | |
3430 | assembler label identifier. */ | |
71dfc51f | 3431 | |
3f76745e JM |
3432 | static inline char * |
3433 | get_AT_hi_pc (die) | |
a3f97cbb JW |
3434 | register dw_die_ref die; |
3435 | { | |
3f76745e | 3436 | register dw_attr_ref a = get_AT (die, DW_AT_high_pc); |
71dfc51f | 3437 | |
3f76745e JM |
3438 | if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id) |
3439 | return a->dw_attr_val.v.val_lbl_id; | |
f37230f0 | 3440 | |
3f76745e JM |
3441 | return NULL; |
3442 | } | |
3443 | ||
3444 | /* Return the value of the string attribute designated by ATTR_KIND, or | |
3445 | NULL if it is not present. */ | |
71dfc51f | 3446 | |
3f76745e JM |
3447 | static inline char * |
3448 | get_AT_string (die, attr_kind) | |
3449 | register dw_die_ref die; | |
3450 | register enum dwarf_attribute attr_kind; | |
3451 | { | |
3452 | register dw_attr_ref a = get_AT (die, attr_kind); | |
3453 | ||
3454 | if (a && a->dw_attr_val.val_class == dw_val_class_str) | |
3455 | return a->dw_attr_val.v.val_str; | |
3456 | ||
3457 | return NULL; | |
a3f97cbb JW |
3458 | } |
3459 | ||
3f76745e JM |
3460 | /* Return the value of the flag attribute designated by ATTR_KIND, or -1 |
3461 | if it is not present. */ | |
71dfc51f | 3462 | |
3f76745e JM |
3463 | static inline int |
3464 | get_AT_flag (die, attr_kind) | |
3465 | register dw_die_ref die; | |
3466 | register enum dwarf_attribute attr_kind; | |
a3f97cbb | 3467 | { |
3f76745e | 3468 | register dw_attr_ref a = get_AT (die, attr_kind); |
71dfc51f | 3469 | |
3f76745e JM |
3470 | if (a && a->dw_attr_val.val_class == dw_val_class_flag) |
3471 | return a->dw_attr_val.v.val_flag; | |
71dfc51f | 3472 | |
3f76745e | 3473 | return -1; |
a3f97cbb JW |
3474 | } |
3475 | ||
3f76745e JM |
3476 | /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0 |
3477 | if it is not present. */ | |
71dfc51f | 3478 | |
3f76745e JM |
3479 | static inline unsigned |
3480 | get_AT_unsigned (die, attr_kind) | |
3481 | register dw_die_ref die; | |
3482 | register enum dwarf_attribute attr_kind; | |
a3f97cbb | 3483 | { |
3f76745e | 3484 | register dw_attr_ref a = get_AT (die, attr_kind); |
71dfc51f | 3485 | |
3f76745e JM |
3486 | if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const) |
3487 | return a->dw_attr_val.v.val_unsigned; | |
71dfc51f | 3488 | |
3f76745e JM |
3489 | return 0; |
3490 | } | |
71dfc51f | 3491 | |
3f76745e JM |
3492 | static inline int |
3493 | is_c_family () | |
3494 | { | |
3495 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
71dfc51f | 3496 | |
3f76745e JM |
3497 | return (lang == DW_LANG_C || lang == DW_LANG_C89 |
3498 | || lang == DW_LANG_C_plus_plus); | |
3499 | } | |
71dfc51f | 3500 | |
3f76745e JM |
3501 | static inline int |
3502 | is_fortran () | |
3503 | { | |
3504 | register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); | |
71dfc51f | 3505 | |
3f76745e JM |
3506 | return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90); |
3507 | } | |
71dfc51f | 3508 | |
3f76745e | 3509 | /* Remove the specified attribute if present. */ |
71dfc51f | 3510 | |
3f76745e JM |
3511 | static inline void |
3512 | remove_AT (die, attr_kind) | |
3513 | register dw_die_ref die; | |
3514 | register enum dwarf_attribute attr_kind; | |
3515 | { | |
3516 | register dw_attr_ref a; | |
3517 | register dw_attr_ref removed = NULL;; | |
a3f97cbb | 3518 | |
3f76745e JM |
3519 | if (die != NULL) |
3520 | { | |
3521 | if (die->die_attr->dw_attr == attr_kind) | |
3522 | { | |
3523 | removed = die->die_attr; | |
3524 | if (die->die_attr_last == die->die_attr) | |
3525 | die->die_attr_last = NULL; | |
71dfc51f | 3526 | |
3f76745e JM |
3527 | die->die_attr = die->die_attr->dw_attr_next; |
3528 | } | |
71dfc51f | 3529 | |
3f76745e JM |
3530 | else |
3531 | for (a = die->die_attr; a->dw_attr_next != NULL; | |
3532 | a = a->dw_attr_next) | |
3533 | if (a->dw_attr_next->dw_attr == attr_kind) | |
3534 | { | |
3535 | removed = a->dw_attr_next; | |
3536 | if (die->die_attr_last == a->dw_attr_next) | |
3537 | die->die_attr_last = a; | |
71dfc51f | 3538 | |
3f76745e JM |
3539 | a->dw_attr_next = a->dw_attr_next->dw_attr_next; |
3540 | break; | |
3541 | } | |
71dfc51f | 3542 | |
3f76745e JM |
3543 | if (removed != 0) |
3544 | free (removed); | |
3545 | } | |
3546 | } | |
71dfc51f | 3547 | |
3f76745e | 3548 | /* Discard the children of this DIE. */ |
71dfc51f | 3549 | |
3f76745e JM |
3550 | static inline void |
3551 | remove_children (die) | |
3552 | register dw_die_ref die; | |
3553 | { | |
3554 | register dw_die_ref child_die = die->die_child; | |
3555 | ||
3556 | die->die_child = NULL; | |
3557 | die->die_child_last = NULL; | |
3558 | ||
3559 | while (child_die != NULL) | |
a3f97cbb | 3560 | { |
3f76745e JM |
3561 | register dw_die_ref tmp_die = child_die; |
3562 | register dw_attr_ref a; | |
71dfc51f | 3563 | |
3f76745e JM |
3564 | child_die = child_die->die_sib; |
3565 | ||
3566 | for (a = tmp_die->die_attr; a != NULL; ) | |
a3f97cbb | 3567 | { |
3f76745e | 3568 | register dw_attr_ref tmp_a = a; |
71dfc51f | 3569 | |
3f76745e JM |
3570 | a = a->dw_attr_next; |
3571 | free (tmp_a); | |
a3f97cbb | 3572 | } |
71dfc51f | 3573 | |
3f76745e JM |
3574 | free (tmp_die); |
3575 | } | |
3576 | } | |
71dfc51f | 3577 | |
3f76745e | 3578 | /* Add a child DIE below its parent. */ |
71dfc51f | 3579 | |
3f76745e JM |
3580 | static inline void |
3581 | add_child_die (die, child_die) | |
3582 | register dw_die_ref die; | |
3583 | register dw_die_ref child_die; | |
3584 | { | |
3585 | if (die != NULL && child_die != NULL) | |
e90b62db | 3586 | { |
3f76745e JM |
3587 | assert (die != child_die); |
3588 | child_die->die_parent = die; | |
3589 | child_die->die_sib = NULL; | |
3590 | ||
3591 | if (die->die_child == NULL) | |
e90b62db | 3592 | { |
3f76745e JM |
3593 | die->die_child = child_die; |
3594 | die->die_child_last = child_die; | |
e90b62db JM |
3595 | } |
3596 | else | |
e90b62db | 3597 | { |
3f76745e JM |
3598 | die->die_child_last->die_sib = child_die; |
3599 | die->die_child_last = child_die; | |
e90b62db | 3600 | } |
3f76745e JM |
3601 | } |
3602 | } | |
3603 | ||
3604 | /* Return a pointer to a newly created DIE node. */ | |
3605 | ||
3606 | static inline dw_die_ref | |
3607 | new_die (tag_value, parent_die) | |
3608 | register enum dwarf_tag tag_value; | |
3609 | register dw_die_ref parent_die; | |
3610 | { | |
3611 | register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node)); | |
3612 | ||
3613 | die->die_tag = tag_value; | |
3614 | die->die_abbrev = 0; | |
3615 | die->die_offset = 0; | |
3616 | die->die_child = NULL; | |
3617 | die->die_parent = NULL; | |
3618 | die->die_sib = NULL; | |
3619 | die->die_child_last = NULL; | |
3620 | die->die_attr = NULL; | |
3621 | die->die_attr_last = NULL; | |
3622 | ||
3623 | if (parent_die != NULL) | |
3624 | add_child_die (parent_die, die); | |
3625 | else | |
ef76d03b JW |
3626 | { |
3627 | limbo_die_node *limbo_node; | |
3628 | ||
3629 | limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node)); | |
3630 | limbo_node->die = die; | |
3631 | limbo_node->next = limbo_die_list; | |
3632 | limbo_die_list = limbo_node; | |
3633 | } | |
71dfc51f | 3634 | |
3f76745e JM |
3635 | return die; |
3636 | } | |
71dfc51f | 3637 | |
3f76745e | 3638 | /* Return the DIE associated with the given type specifier. */ |
71dfc51f | 3639 | |
3f76745e JM |
3640 | static inline dw_die_ref |
3641 | lookup_type_die (type) | |
3642 | register tree type; | |
3643 | { | |
3644 | return (dw_die_ref) TYPE_SYMTAB_POINTER (type); | |
3645 | } | |
e90b62db | 3646 | |
3f76745e | 3647 | /* Equate a DIE to a given type specifier. */ |
71dfc51f | 3648 | |
3f76745e JM |
3649 | static void |
3650 | equate_type_number_to_die (type, type_die) | |
3651 | register tree type; | |
3652 | register dw_die_ref type_die; | |
3653 | { | |
3654 | TYPE_SYMTAB_POINTER (type) = (char *) type_die; | |
3655 | } | |
71dfc51f | 3656 | |
3f76745e | 3657 | /* Return the DIE associated with a given declaration. */ |
71dfc51f | 3658 | |
3f76745e JM |
3659 | static inline dw_die_ref |
3660 | lookup_decl_die (decl) | |
3661 | register tree decl; | |
3662 | { | |
3663 | register unsigned decl_id = DECL_UID (decl); | |
3664 | ||
3665 | return (decl_id < decl_die_table_in_use | |
3666 | ? decl_die_table[decl_id] : NULL); | |
a3f97cbb JW |
3667 | } |
3668 | ||
3f76745e | 3669 | /* Equate a DIE to a particular declaration. */ |
71dfc51f | 3670 | |
3f76745e JM |
3671 | static void |
3672 | equate_decl_number_to_die (decl, decl_die) | |
3673 | register tree decl; | |
3674 | register dw_die_ref decl_die; | |
a3f97cbb | 3675 | { |
3f76745e | 3676 | register unsigned decl_id = DECL_UID (decl); |
d291dd49 | 3677 | register unsigned i; |
3f76745e | 3678 | register unsigned num_allocated; |
d291dd49 | 3679 | |
3f76745e | 3680 | if (decl_id >= decl_die_table_allocated) |
a3f97cbb | 3681 | { |
3f76745e JM |
3682 | num_allocated |
3683 | = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1) | |
3684 | / DECL_DIE_TABLE_INCREMENT) | |
3685 | * DECL_DIE_TABLE_INCREMENT; | |
3686 | ||
3687 | decl_die_table | |
3688 | = (dw_die_ref *) xrealloc (decl_die_table, | |
3689 | sizeof (dw_die_ref) * num_allocated); | |
3690 | ||
3691 | bzero ((char *) &decl_die_table[decl_die_table_allocated], | |
3692 | (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref)); | |
3693 | decl_die_table_allocated = num_allocated; | |
a3f97cbb | 3694 | } |
71dfc51f | 3695 | |
3f76745e JM |
3696 | if (decl_id >= decl_die_table_in_use) |
3697 | decl_die_table_in_use = (decl_id + 1); | |
3698 | ||
3699 | decl_die_table[decl_id] = decl_die; | |
a3f97cbb JW |
3700 | } |
3701 | ||
3f76745e JM |
3702 | /* Return a pointer to a newly allocated location description. Location |
3703 | descriptions are simple expression terms that can be strung | |
3704 | together to form more complicated location (address) descriptions. */ | |
71dfc51f | 3705 | |
3f76745e JM |
3706 | static inline dw_loc_descr_ref |
3707 | new_loc_descr (op, oprnd1, oprnd2) | |
3708 | register enum dwarf_location_atom op; | |
3709 | register unsigned long oprnd1; | |
3710 | register unsigned long oprnd2; | |
a3f97cbb | 3711 | { |
3f76745e JM |
3712 | register dw_loc_descr_ref descr |
3713 | = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node)); | |
71dfc51f | 3714 | |
3f76745e JM |
3715 | descr->dw_loc_next = NULL; |
3716 | descr->dw_loc_opc = op; | |
3717 | descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const; | |
3718 | descr->dw_loc_oprnd1.v.val_unsigned = oprnd1; | |
3719 | descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const; | |
3720 | descr->dw_loc_oprnd2.v.val_unsigned = oprnd2; | |
71dfc51f | 3721 | |
3f76745e | 3722 | return descr; |
a3f97cbb | 3723 | } |
71dfc51f | 3724 | |
3f76745e JM |
3725 | /* Add a location description term to a location description expression. */ |
3726 | ||
3727 | static inline void | |
3728 | add_loc_descr (list_head, descr) | |
3729 | register dw_loc_descr_ref *list_head; | |
3730 | register dw_loc_descr_ref descr; | |
a3f97cbb | 3731 | { |
3f76745e | 3732 | register dw_loc_descr_ref *d; |
71dfc51f | 3733 | |
3f76745e JM |
3734 | /* Find the end of the chain. */ |
3735 | for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) | |
3736 | ; | |
71dfc51f | 3737 | |
3f76745e JM |
3738 | *d = descr; |
3739 | } | |
3740 | \f | |
3741 | /* Keep track of the number of spaces used to indent the | |
3742 | output of the debugging routines that print the structure of | |
3743 | the DIE internal representation. */ | |
3744 | static int print_indent; | |
71dfc51f | 3745 | |
3f76745e JM |
3746 | /* Indent the line the number of spaces given by print_indent. */ |
3747 | ||
3748 | static inline void | |
3749 | print_spaces (outfile) | |
3750 | FILE *outfile; | |
3751 | { | |
3752 | fprintf (outfile, "%*s", print_indent, ""); | |
a3f97cbb JW |
3753 | } |
3754 | ||
3f76745e JM |
3755 | /* Print the information assoaciated with a given DIE, and its children. |
3756 | This routine is a debugging aid only. */ | |
71dfc51f | 3757 | |
a3f97cbb | 3758 | static void |
3f76745e JM |
3759 | print_die (die, outfile) |
3760 | dw_die_ref die; | |
3761 | FILE *outfile; | |
a3f97cbb | 3762 | { |
3f76745e JM |
3763 | register dw_attr_ref a; |
3764 | register dw_die_ref c; | |
71dfc51f | 3765 | |
3f76745e JM |
3766 | print_spaces (outfile); |
3767 | fprintf (outfile, "DIE %4u: %s\n", | |
3768 | die->die_offset, dwarf_tag_name (die->die_tag)); | |
3769 | print_spaces (outfile); | |
3770 | fprintf (outfile, " abbrev id: %u", die->die_abbrev); | |
3771 | fprintf (outfile, " offset: %u\n", die->die_offset); | |
3772 | ||
3773 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) | |
a3f97cbb | 3774 | { |
3f76745e JM |
3775 | print_spaces (outfile); |
3776 | fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr)); | |
3777 | ||
3778 | switch (a->dw_attr_val.val_class) | |
3779 | { | |
3780 | case dw_val_class_addr: | |
3781 | fprintf (outfile, "address"); | |
3782 | break; | |
3783 | case dw_val_class_loc: | |
3784 | fprintf (outfile, "location descriptor"); | |
3785 | break; | |
3786 | case dw_val_class_const: | |
3787 | fprintf (outfile, "%d", a->dw_attr_val.v.val_int); | |
3788 | break; | |
3789 | case dw_val_class_unsigned_const: | |
3790 | fprintf (outfile, "%u", a->dw_attr_val.v.val_unsigned); | |
3791 | break; | |
3792 | case dw_val_class_long_long: | |
3793 | fprintf (outfile, "constant (%u,%u)", | |
3794 | a->dw_attr_val.v.val_long_long.hi, | |
3795 | a->dw_attr_val.v.val_long_long.low); | |
3796 | break; | |
3797 | case dw_val_class_float: | |
3798 | fprintf (outfile, "floating-point constant"); | |
3799 | break; | |
3800 | case dw_val_class_flag: | |
3801 | fprintf (outfile, "%u", a->dw_attr_val.v.val_flag); | |
3802 | break; | |
3803 | case dw_val_class_die_ref: | |
3804 | if (a->dw_attr_val.v.val_die_ref != NULL) | |
3805 | fprintf (outfile, "die -> %u", | |
3806 | a->dw_attr_val.v.val_die_ref->die_offset); | |
3807 | else | |
3808 | fprintf (outfile, "die -> <null>"); | |
3809 | break; | |
3810 | case dw_val_class_lbl_id: | |
3811 | fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id); | |
3812 | break; | |
3813 | case dw_val_class_section_offset: | |
3814 | fprintf (outfile, "section: %s", a->dw_attr_val.v.val_section); | |
3815 | break; | |
3816 | case dw_val_class_str: | |
3817 | if (a->dw_attr_val.v.val_str != NULL) | |
3818 | fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str); | |
3819 | else | |
3820 | fprintf (outfile, "<null>"); | |
3821 | break; | |
3822 | } | |
3823 | ||
3824 | fprintf (outfile, "\n"); | |
3825 | } | |
3826 | ||
3827 | if (die->die_child != NULL) | |
3828 | { | |
3829 | print_indent += 4; | |
3830 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
3831 | print_die (c, outfile); | |
71dfc51f | 3832 | |
3f76745e | 3833 | print_indent -= 4; |
a3f97cbb | 3834 | } |
a3f97cbb JW |
3835 | } |
3836 | ||
3f76745e JM |
3837 | /* Print the contents of the source code line number correspondence table. |
3838 | This routine is a debugging aid only. */ | |
71dfc51f | 3839 | |
3f76745e JM |
3840 | static void |
3841 | print_dwarf_line_table (outfile) | |
3842 | FILE *outfile; | |
a3f97cbb | 3843 | { |
3f76745e JM |
3844 | register unsigned i; |
3845 | register dw_line_info_ref line_info; | |
3846 | ||
3847 | fprintf (outfile, "\n\nDWARF source line information\n"); | |
3848 | for (i = 1; i < line_info_table_in_use; ++i) | |
a3f97cbb | 3849 | { |
3f76745e JM |
3850 | line_info = &line_info_table[i]; |
3851 | fprintf (outfile, "%5d: ", i); | |
3852 | fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]); | |
3853 | fprintf (outfile, "%6d", line_info->dw_line_num); | |
3854 | fprintf (outfile, "\n"); | |
a3f97cbb | 3855 | } |
3f76745e JM |
3856 | |
3857 | fprintf (outfile, "\n\n"); | |
f37230f0 JM |
3858 | } |
3859 | ||
3f76745e JM |
3860 | /* Print the information collected for a given DIE. */ |
3861 | ||
3862 | void | |
3863 | debug_dwarf_die (die) | |
3864 | dw_die_ref die; | |
3865 | { | |
3866 | print_die (die, stderr); | |
3867 | } | |
3868 | ||
3869 | /* Print all DWARF information collected for the compilation unit. | |
3870 | This routine is a debugging aid only. */ | |
3871 | ||
3872 | void | |
3873 | debug_dwarf () | |
3874 | { | |
3875 | print_indent = 0; | |
3876 | print_die (comp_unit_die, stderr); | |
3877 | print_dwarf_line_table (stderr); | |
3878 | } | |
3879 | \f | |
3880 | /* Traverse the DIE, and add a sibling attribute if it may have the | |
3881 | effect of speeding up access to siblings. To save some space, | |
3882 | avoid generating sibling attributes for DIE's without children. */ | |
71dfc51f | 3883 | |
f37230f0 | 3884 | static void |
3f76745e JM |
3885 | add_sibling_attributes(die) |
3886 | register dw_die_ref die; | |
f37230f0 | 3887 | { |
3f76745e JM |
3888 | register dw_die_ref c; |
3889 | register dw_attr_ref attr; | |
3890 | if (die != comp_unit_die && die->die_child != NULL) | |
3891 | { | |
3892 | attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); | |
3893 | attr->dw_attr_next = NULL; | |
3894 | attr->dw_attr = DW_AT_sibling; | |
3895 | attr->dw_attr_val.val_class = dw_val_class_die_ref; | |
3896 | attr->dw_attr_val.v.val_die_ref = die->die_sib; | |
71dfc51f | 3897 | |
3f76745e JM |
3898 | /* Add the sibling link to the front of the attribute list. */ |
3899 | attr->dw_attr_next = die->die_attr; | |
3900 | if (die->die_attr == NULL) | |
3901 | die->die_attr_last = attr; | |
71dfc51f | 3902 | |
3f76745e JM |
3903 | die->die_attr = attr; |
3904 | } | |
3905 | ||
3906 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
3907 | add_sibling_attributes (c); | |
a3f97cbb JW |
3908 | } |
3909 | ||
3f76745e JM |
3910 | /* The format of each DIE (and its attribute value pairs) |
3911 | is encoded in an abbreviation table. This routine builds the | |
3912 | abbreviation table and assigns a unique abbreviation id for | |
3913 | each abbreviation entry. The children of each die are visited | |
3914 | recursively. */ | |
71dfc51f | 3915 | |
a3f97cbb | 3916 | static void |
3f76745e JM |
3917 | build_abbrev_table (die) |
3918 | register dw_die_ref die; | |
a3f97cbb | 3919 | { |
3f76745e JM |
3920 | register unsigned long abbrev_id; |
3921 | register unsigned long n_alloc; | |
3922 | register dw_die_ref c; | |
3923 | register dw_attr_ref d_attr, a_attr; | |
a3f97cbb JW |
3924 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) |
3925 | { | |
3926 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
71dfc51f | 3927 | |
3f76745e JM |
3928 | if (abbrev->die_tag == die->die_tag) |
3929 | { | |
3930 | if ((abbrev->die_child != NULL) == (die->die_child != NULL)) | |
3931 | { | |
3932 | a_attr = abbrev->die_attr; | |
3933 | d_attr = die->die_attr; | |
71dfc51f | 3934 | |
3f76745e JM |
3935 | while (a_attr != NULL && d_attr != NULL) |
3936 | { | |
3937 | if ((a_attr->dw_attr != d_attr->dw_attr) | |
3938 | || (value_format (&a_attr->dw_attr_val) | |
3939 | != value_format (&d_attr->dw_attr_val))) | |
3940 | break; | |
71dfc51f | 3941 | |
3f76745e JM |
3942 | a_attr = a_attr->dw_attr_next; |
3943 | d_attr = d_attr->dw_attr_next; | |
3944 | } | |
71dfc51f | 3945 | |
3f76745e JM |
3946 | if (a_attr == NULL && d_attr == NULL) |
3947 | break; | |
3948 | } | |
3949 | } | |
3950 | } | |
71dfc51f | 3951 | |
3f76745e JM |
3952 | if (abbrev_id >= abbrev_die_table_in_use) |
3953 | { | |
3954 | if (abbrev_die_table_in_use >= abbrev_die_table_allocated) | |
a3f97cbb | 3955 | { |
3f76745e JM |
3956 | n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT; |
3957 | abbrev_die_table | |
3958 | = (dw_die_ref *) xmalloc (abbrev_die_table, | |
3959 | sizeof (dw_die_ref) * n_alloc); | |
71dfc51f | 3960 | |
3f76745e JM |
3961 | bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated], |
3962 | (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref)); | |
3963 | abbrev_die_table_allocated = n_alloc; | |
a3f97cbb | 3964 | } |
71dfc51f | 3965 | |
3f76745e JM |
3966 | ++abbrev_die_table_in_use; |
3967 | abbrev_die_table[abbrev_id] = die; | |
a3f97cbb | 3968 | } |
3f76745e JM |
3969 | |
3970 | die->die_abbrev = abbrev_id; | |
3971 | for (c = die->die_child; c != NULL; c = c->die_sib) | |
3972 | build_abbrev_table (c); | |
a3f97cbb | 3973 | } |
3f76745e JM |
3974 | \f |
3975 | /* Return the size of a string, including the null byte. */ | |
a3f97cbb | 3976 | |
3f76745e JM |
3977 | static unsigned long |
3978 | size_of_string (str) | |
3979 | register char *str; | |
3980 | { | |
3981 | register unsigned long size = 0; | |
3982 | register unsigned long slen = strlen (str); | |
3983 | register unsigned long i; | |
3984 | register unsigned c; | |
71dfc51f | 3985 | |
3f76745e JM |
3986 | for (i = 0; i < slen; ++i) |
3987 | { | |
3988 | c = str[i]; | |
3989 | if (c == '\\') | |
3990 | ++i; | |
3991 | ||
3992 | size += 1; | |
3993 | } | |
3994 | ||
3995 | /* Null terminator. */ | |
3996 | size += 1; | |
3997 | return size; | |
3998 | } | |
3999 | ||
4000 | /* Return the size of a location descriptor. */ | |
4001 | ||
4002 | static unsigned long | |
4003 | size_of_loc_descr (loc) | |
a3f97cbb JW |
4004 | register dw_loc_descr_ref loc; |
4005 | { | |
3f76745e | 4006 | register unsigned long size = 1; |
71dfc51f | 4007 | |
a3f97cbb JW |
4008 | switch (loc->dw_loc_opc) |
4009 | { | |
4010 | case DW_OP_addr: | |
3f76745e | 4011 | size += PTR_SIZE; |
a3f97cbb JW |
4012 | break; |
4013 | case DW_OP_const1u: | |
4014 | case DW_OP_const1s: | |
3f76745e | 4015 | size += 1; |
a3f97cbb JW |
4016 | break; |
4017 | case DW_OP_const2u: | |
4018 | case DW_OP_const2s: | |
3f76745e | 4019 | size += 2; |
a3f97cbb JW |
4020 | break; |
4021 | case DW_OP_const4u: | |
4022 | case DW_OP_const4s: | |
3f76745e | 4023 | size += 4; |
a3f97cbb JW |
4024 | break; |
4025 | case DW_OP_const8u: | |
4026 | case DW_OP_const8s: | |
3f76745e | 4027 | size += 8; |
a3f97cbb JW |
4028 | break; |
4029 | case DW_OP_constu: | |
3f76745e | 4030 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
a3f97cbb JW |
4031 | break; |
4032 | case DW_OP_consts: | |
3f76745e | 4033 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); |
a3f97cbb JW |
4034 | break; |
4035 | case DW_OP_pick: | |
3f76745e | 4036 | size += 1; |
a3f97cbb JW |
4037 | break; |
4038 | case DW_OP_plus_uconst: | |
3f76745e | 4039 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
a3f97cbb JW |
4040 | break; |
4041 | case DW_OP_skip: | |
4042 | case DW_OP_bra: | |
3f76745e | 4043 | size += 2; |
a3f97cbb JW |
4044 | break; |
4045 | case DW_OP_breg0: | |
4046 | case DW_OP_breg1: | |
4047 | case DW_OP_breg2: | |
4048 | case DW_OP_breg3: | |
4049 | case DW_OP_breg4: | |
4050 | case DW_OP_breg5: | |
4051 | case DW_OP_breg6: | |
4052 | case DW_OP_breg7: | |
4053 | case DW_OP_breg8: | |
4054 | case DW_OP_breg9: | |
4055 | case DW_OP_breg10: | |
4056 | case DW_OP_breg11: | |
4057 | case DW_OP_breg12: | |
4058 | case DW_OP_breg13: | |
4059 | case DW_OP_breg14: | |
4060 | case DW_OP_breg15: | |
4061 | case DW_OP_breg16: | |
4062 | case DW_OP_breg17: | |
4063 | case DW_OP_breg18: | |
4064 | case DW_OP_breg19: | |
4065 | case DW_OP_breg20: | |
4066 | case DW_OP_breg21: | |
4067 | case DW_OP_breg22: | |
4068 | case DW_OP_breg23: | |
4069 | case DW_OP_breg24: | |
4070 | case DW_OP_breg25: | |
4071 | case DW_OP_breg26: | |
4072 | case DW_OP_breg27: | |
4073 | case DW_OP_breg28: | |
4074 | case DW_OP_breg29: | |
4075 | case DW_OP_breg30: | |
4076 | case DW_OP_breg31: | |
3f76745e | 4077 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); |
a3f97cbb JW |
4078 | break; |
4079 | case DW_OP_regx: | |
3f76745e | 4080 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
a3f97cbb JW |
4081 | break; |
4082 | case DW_OP_fbreg: | |
3f76745e | 4083 | size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); |
a3f97cbb JW |
4084 | break; |
4085 | case DW_OP_bregx: | |
3f76745e JM |
4086 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
4087 | size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int); | |
a3f97cbb JW |
4088 | break; |
4089 | case DW_OP_piece: | |
3f76745e | 4090 | size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); |
a3f97cbb JW |
4091 | break; |
4092 | case DW_OP_deref_size: | |
4093 | case DW_OP_xderef_size: | |
3f76745e | 4094 | size += 1; |
a3f97cbb JW |
4095 | break; |
4096 | default: | |
4097 | break; | |
4098 | } | |
3f76745e JM |
4099 | |
4100 | return size; | |
a3f97cbb JW |
4101 | } |
4102 | ||
3f76745e | 4103 | /* Return the size of a series of location descriptors. */ |
71dfc51f | 4104 | |
a3f97cbb | 4105 | static unsigned long |
3f76745e JM |
4106 | size_of_locs (loc) |
4107 | register dw_loc_descr_ref loc; | |
a3f97cbb | 4108 | { |
3f76745e | 4109 | register unsigned long size = 0; |
71dfc51f | 4110 | |
3f76745e JM |
4111 | for (; loc != NULL; loc = loc->dw_loc_next) |
4112 | size += size_of_loc_descr (loc); | |
4113 | ||
4114 | return size; | |
4115 | } | |
4116 | ||
4117 | /* Return the power-of-two number of bytes necessary to represent VALUE. */ | |
4118 | ||
4119 | static int | |
4120 | constant_size (value) | |
4121 | long unsigned value; | |
4122 | { | |
4123 | int log; | |
4124 | ||
4125 | if (value == 0) | |
4126 | log = 0; | |
a3f97cbb | 4127 | else |
3f76745e | 4128 | log = floor_log2 (value); |
71dfc51f | 4129 | |
3f76745e JM |
4130 | log = log / 8; |
4131 | log = 1 << (floor_log2 (log) + 1); | |
4132 | ||
4133 | return log; | |
a3f97cbb JW |
4134 | } |
4135 | ||
3f76745e JM |
4136 | /* Return the size of a DIE, as it is represented in the |
4137 | .debug_info section. */ | |
71dfc51f | 4138 | |
3f76745e JM |
4139 | static unsigned long |
4140 | size_of_die (die) | |
a3f97cbb JW |
4141 | register dw_die_ref die; |
4142 | { | |
3f76745e | 4143 | register unsigned long size = 0; |
a3f97cbb | 4144 | register dw_attr_ref a; |
71dfc51f | 4145 | |
3f76745e | 4146 | size += size_of_uleb128 (die->die_abbrev); |
a3f97cbb JW |
4147 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
4148 | { | |
4149 | switch (a->dw_attr_val.val_class) | |
4150 | { | |
4151 | case dw_val_class_addr: | |
3f76745e | 4152 | size += PTR_SIZE; |
a3f97cbb JW |
4153 | break; |
4154 | case dw_val_class_loc: | |
3f76745e JM |
4155 | { |
4156 | register unsigned long lsize | |
4157 | = size_of_locs (a->dw_attr_val.v.val_loc); | |
71dfc51f | 4158 | |
3f76745e JM |
4159 | /* Block length. */ |
4160 | size += constant_size (lsize); | |
4161 | size += lsize; | |
4162 | } | |
a3f97cbb JW |
4163 | break; |
4164 | case dw_val_class_const: | |
3f76745e | 4165 | size += 4; |
a3f97cbb JW |
4166 | break; |
4167 | case dw_val_class_unsigned_const: | |
3f76745e | 4168 | size += constant_size (a->dw_attr_val.v.val_unsigned); |
a3f97cbb | 4169 | break; |
469ac993 | 4170 | case dw_val_class_long_long: |
3f76745e | 4171 | size += 1 + 8; /* block */ |
469ac993 JM |
4172 | break; |
4173 | case dw_val_class_float: | |
3f76745e | 4174 | size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */ |
a3f97cbb JW |
4175 | break; |
4176 | case dw_val_class_flag: | |
3f76745e | 4177 | size += 1; |
a3f97cbb JW |
4178 | break; |
4179 | case dw_val_class_die_ref: | |
3f76745e | 4180 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
4181 | break; |
4182 | case dw_val_class_fde_ref: | |
3f76745e | 4183 | size += DWARF_OFFSET_SIZE; |
a3f97cbb JW |
4184 | break; |
4185 | case dw_val_class_lbl_id: | |
3f76745e JM |
4186 | size += PTR_SIZE; |
4187 | break; | |
4188 | case dw_val_class_section_offset: | |
4189 | size += DWARF_OFFSET_SIZE; | |
4190 | break; | |
4191 | case dw_val_class_str: | |
4192 | size += size_of_string (a->dw_attr_val.v.val_str); | |
4193 | break; | |
4194 | default: | |
4195 | abort (); | |
4196 | } | |
a3f97cbb | 4197 | } |
3f76745e JM |
4198 | |
4199 | return size; | |
a3f97cbb JW |
4200 | } |
4201 | ||
3f76745e JM |
4202 | /* Size the debgging information associted with a given DIE. |
4203 | Visits the DIE's children recursively. Updates the global | |
4204 | variable next_die_offset, on each time through. Uses the | |
4205 | current value of next_die_offset to updete the die_offset | |
4206 | field in each DIE. */ | |
71dfc51f | 4207 | |
a3f97cbb | 4208 | static void |
3f76745e JM |
4209 | calc_die_sizes (die) |
4210 | dw_die_ref die; | |
a3f97cbb | 4211 | { |
3f76745e JM |
4212 | register dw_die_ref c; |
4213 | die->die_offset = next_die_offset; | |
4214 | next_die_offset += size_of_die (die); | |
71dfc51f | 4215 | |
3f76745e JM |
4216 | for (c = die->die_child; c != NULL; c = c->die_sib) |
4217 | calc_die_sizes (c); | |
71dfc51f | 4218 | |
3f76745e JM |
4219 | if (die->die_child != NULL) |
4220 | /* Count the null byte used to terminate sibling lists. */ | |
4221 | next_die_offset += 1; | |
a3f97cbb JW |
4222 | } |
4223 | ||
3f76745e JM |
4224 | /* Return the size of the line information prolog generated for the |
4225 | compilation unit. */ | |
469ac993 | 4226 | |
3f76745e JM |
4227 | static unsigned long |
4228 | size_of_line_prolog () | |
a94dbf2c | 4229 | { |
3f76745e JM |
4230 | register unsigned long size; |
4231 | register unsigned long ft_index; | |
a94dbf2c | 4232 | |
3f76745e | 4233 | size = DWARF_LINE_PROLOG_HEADER_SIZE; |
469ac993 | 4234 | |
3f76745e JM |
4235 | /* Count the size of the table giving number of args for each |
4236 | standard opcode. */ | |
4237 | size += DWARF_LINE_OPCODE_BASE - 1; | |
71dfc51f | 4238 | |
3f76745e JM |
4239 | /* Include directory table is empty (at present). Count only the |
4240 | the null byte used to terminate the table. */ | |
4241 | size += 1; | |
71dfc51f | 4242 | |
3f76745e JM |
4243 | for (ft_index = 1; ft_index < file_table_in_use; ++ft_index) |
4244 | { | |
4245 | /* File name entry. */ | |
4246 | size += size_of_string (file_table[ft_index]); | |
a94dbf2c | 4247 | |
3f76745e JM |
4248 | /* Include directory index. */ |
4249 | size += size_of_uleb128 (0); | |
a94dbf2c | 4250 | |
3f76745e JM |
4251 | /* Modification time. */ |
4252 | size += size_of_uleb128 (0); | |
71dfc51f | 4253 | |
3f76745e JM |
4254 | /* File length in bytes. */ |
4255 | size += size_of_uleb128 (0); | |
a94dbf2c | 4256 | } |
71dfc51f | 4257 | |
3f76745e JM |
4258 | /* Count the file table terminator. */ |
4259 | size += 1; | |
4260 | return size; | |
a94dbf2c JM |
4261 | } |
4262 | ||
3f76745e JM |
4263 | /* Return the size of the line information generated for this |
4264 | compilation unit. */ | |
71dfc51f | 4265 | |
3f76745e JM |
4266 | static unsigned long |
4267 | size_of_line_info () | |
a94dbf2c | 4268 | { |
3f76745e JM |
4269 | register unsigned long size; |
4270 | register unsigned long lt_index; | |
4271 | register unsigned long current_line; | |
4272 | register long line_offset; | |
4273 | register long line_delta; | |
4274 | register unsigned long current_file; | |
4275 | register unsigned long function; | |
f19a6894 JW |
4276 | unsigned long size_of_set_address; |
4277 | ||
4278 | /* Size of a DW_LNE_set_address instruction. */ | |
4279 | size_of_set_address = 1 + size_of_uleb128 (1 + PTR_SIZE) + 1 + PTR_SIZE; | |
a94dbf2c | 4280 | |
3f76745e JM |
4281 | /* Version number. */ |
4282 | size = 2; | |
71dfc51f | 4283 | |
3f76745e JM |
4284 | /* Prolog length specifier. */ |
4285 | size += DWARF_OFFSET_SIZE; | |
71dfc51f | 4286 | |
3f76745e JM |
4287 | /* Prolog. */ |
4288 | size += size_of_line_prolog (); | |
a94dbf2c | 4289 | |
3f76745e | 4290 | /* Set address register instruction. */ |
f19a6894 | 4291 | size += size_of_set_address; |
71dfc51f | 4292 | |
3f76745e JM |
4293 | current_file = 1; |
4294 | current_line = 1; | |
4295 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) | |
a94dbf2c | 4296 | { |
3f76745e JM |
4297 | register dw_line_info_ref line_info; |
4298 | ||
4299 | /* Advance pc instruction. */ | |
f19a6894 JW |
4300 | /* ??? See the DW_LNS_advance_pc comment in output_line_info. */ |
4301 | if (0) | |
4302 | size += 1 + 2; | |
4303 | else | |
4304 | size += size_of_set_address; | |
4305 | ||
3f76745e JM |
4306 | line_info = &line_info_table[lt_index]; |
4307 | if (line_info->dw_file_num != current_file) | |
4308 | { | |
4309 | /* Set file number instruction. */ | |
4310 | size += 1; | |
4311 | current_file = line_info->dw_file_num; | |
4312 | size += size_of_uleb128 (current_file); | |
4313 | } | |
4314 | ||
4315 | if (line_info->dw_line_num != current_line) | |
4316 | { | |
4317 | line_offset = line_info->dw_line_num - current_line; | |
4318 | line_delta = line_offset - DWARF_LINE_BASE; | |
4319 | current_line = line_info->dw_line_num; | |
4320 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
4321 | /* 1-byte special line number instruction. */ | |
4322 | size += 1; | |
4323 | else | |
4324 | { | |
4325 | /* Advance line instruction. */ | |
4326 | size += 1; | |
4327 | size += size_of_sleb128 (line_offset); | |
4328 | /* Generate line entry instruction. */ | |
4329 | size += 1; | |
4330 | } | |
4331 | } | |
a94dbf2c | 4332 | } |
a94dbf2c | 4333 | |
3f76745e | 4334 | /* Advance pc instruction. */ |
f19a6894 JW |
4335 | if (0) |
4336 | size += 1 + 2; | |
4337 | else | |
4338 | size += size_of_set_address; | |
a94dbf2c | 4339 | |
3f76745e JM |
4340 | /* End of line number info. marker. */ |
4341 | size += 1 + size_of_uleb128 (1) + 1; | |
a94dbf2c | 4342 | |
3f76745e JM |
4343 | function = 0; |
4344 | current_file = 1; | |
4345 | current_line = 1; | |
4346 | for (lt_index = 0; lt_index < separate_line_info_table_in_use; ) | |
4347 | { | |
4348 | register dw_separate_line_info_ref line_info | |
4349 | = &separate_line_info_table[lt_index]; | |
4350 | if (function != line_info->function) | |
4351 | { | |
4352 | function = line_info->function; | |
4353 | /* Set address register instruction. */ | |
f19a6894 | 4354 | size += size_of_set_address; |
3f76745e JM |
4355 | } |
4356 | else | |
f19a6894 JW |
4357 | { |
4358 | /* Advance pc instruction. */ | |
4359 | if (0) | |
4360 | size += 1 + 2; | |
4361 | else | |
4362 | size += size_of_set_address; | |
4363 | } | |
3f76745e JM |
4364 | |
4365 | if (line_info->dw_file_num != current_file) | |
4366 | { | |
4367 | /* Set file number instruction. */ | |
4368 | size += 1; | |
4369 | current_file = line_info->dw_file_num; | |
4370 | size += size_of_uleb128 (current_file); | |
4371 | } | |
4372 | ||
4373 | if (line_info->dw_line_num != current_line) | |
4374 | { | |
4375 | line_offset = line_info->dw_line_num - current_line; | |
4376 | line_delta = line_offset - DWARF_LINE_BASE; | |
4377 | current_line = line_info->dw_line_num; | |
4378 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
4379 | /* 1-byte special line number instruction. */ | |
4380 | size += 1; | |
4381 | else | |
4382 | { | |
4383 | /* Advance line instruction. */ | |
4384 | size += 1; | |
4385 | size += size_of_sleb128 (line_offset); | |
a94dbf2c | 4386 | |
3f76745e JM |
4387 | /* Generate line entry instruction. */ |
4388 | size += 1; | |
4389 | } | |
4390 | } | |
a94dbf2c | 4391 | |
3f76745e | 4392 | ++lt_index; |
a94dbf2c | 4393 | |
3f76745e JM |
4394 | /* If we're done with a function, end its sequence. */ |
4395 | if (lt_index == separate_line_info_table_in_use | |
4396 | || separate_line_info_table[lt_index].function != function) | |
4397 | { | |
4398 | current_file = 1; | |
4399 | current_line = 1; | |
71dfc51f | 4400 | |
3f76745e | 4401 | /* Advance pc instruction. */ |
f19a6894 JW |
4402 | if (0) |
4403 | size += 1 + 2; | |
4404 | else | |
4405 | size += size_of_set_address; | |
71dfc51f | 4406 | |
3f76745e JM |
4407 | /* End of line number info. marker. */ |
4408 | size += 1 + size_of_uleb128 (1) + 1; | |
4409 | } | |
a94dbf2c JM |
4410 | } |
4411 | ||
3f76745e | 4412 | return size; |
a94dbf2c JM |
4413 | } |
4414 | ||
3f76745e JM |
4415 | /* Return the size of the .debug_pubnames table generated for the |
4416 | compilation unit. */ | |
a94dbf2c | 4417 | |
3f76745e JM |
4418 | static unsigned long |
4419 | size_of_pubnames () | |
a94dbf2c | 4420 | { |
3f76745e JM |
4421 | register unsigned long size; |
4422 | register unsigned i; | |
469ac993 | 4423 | |
3f76745e JM |
4424 | size = DWARF_PUBNAMES_HEADER_SIZE; |
4425 | for (i = 0; i < pubname_table_in_use; ++i) | |
a94dbf2c | 4426 | { |
3f76745e JM |
4427 | register pubname_ref p = &pubname_table[i]; |
4428 | size += DWARF_OFFSET_SIZE + size_of_string (p->name); | |
a94dbf2c JM |
4429 | } |
4430 | ||
3f76745e JM |
4431 | size += DWARF_OFFSET_SIZE; |
4432 | return size; | |
a94dbf2c JM |
4433 | } |
4434 | ||
3f76745e | 4435 | /* Return the size of the information in the .debug_aranges seciton. */ |
469ac993 | 4436 | |
3f76745e JM |
4437 | static unsigned long |
4438 | size_of_aranges () | |
469ac993 | 4439 | { |
3f76745e | 4440 | register unsigned long size; |
469ac993 | 4441 | |
3f76745e | 4442 | size = DWARF_ARANGES_HEADER_SIZE; |
469ac993 | 4443 | |
3f76745e JM |
4444 | /* Count the address/length pair for this compilation unit. */ |
4445 | size += 2 * PTR_SIZE; | |
4446 | size += 2 * PTR_SIZE * arange_table_in_use; | |
469ac993 | 4447 | |
3f76745e JM |
4448 | /* Count the two zero words used to terminated the address range table. */ |
4449 | size += 2 * PTR_SIZE; | |
4450 | return size; | |
4451 | } | |
4452 | \f | |
4453 | /* Select the encoding of an attribute value. */ | |
4454 | ||
4455 | static enum dwarf_form | |
4456 | value_format (v) | |
4457 | dw_val_ref v; | |
4458 | { | |
4459 | switch (v->val_class) | |
469ac993 | 4460 | { |
3f76745e JM |
4461 | case dw_val_class_addr: |
4462 | return DW_FORM_addr; | |
4463 | case dw_val_class_loc: | |
4464 | switch (constant_size (size_of_locs (v->v.val_loc))) | |
469ac993 | 4465 | { |
3f76745e JM |
4466 | case 1: |
4467 | return DW_FORM_block1; | |
4468 | case 2: | |
4469 | return DW_FORM_block2; | |
469ac993 JM |
4470 | default: |
4471 | abort (); | |
4472 | } | |
3f76745e JM |
4473 | case dw_val_class_const: |
4474 | return DW_FORM_data4; | |
4475 | case dw_val_class_unsigned_const: | |
4476 | switch (constant_size (v->v.val_unsigned)) | |
4477 | { | |
4478 | case 1: | |
4479 | return DW_FORM_data1; | |
4480 | case 2: | |
4481 | return DW_FORM_data2; | |
4482 | case 4: | |
4483 | return DW_FORM_data4; | |
4484 | case 8: | |
4485 | return DW_FORM_data8; | |
4486 | default: | |
4487 | abort (); | |
4488 | } | |
4489 | case dw_val_class_long_long: | |
4490 | return DW_FORM_block1; | |
4491 | case dw_val_class_float: | |
4492 | return DW_FORM_block1; | |
4493 | case dw_val_class_flag: | |
4494 | return DW_FORM_flag; | |
4495 | case dw_val_class_die_ref: | |
4496 | return DW_FORM_ref; | |
4497 | case dw_val_class_fde_ref: | |
4498 | return DW_FORM_data; | |
4499 | case dw_val_class_lbl_id: | |
4500 | return DW_FORM_addr; | |
4501 | case dw_val_class_section_offset: | |
4502 | return DW_FORM_data; | |
4503 | case dw_val_class_str: | |
4504 | return DW_FORM_string; | |
469ac993 JM |
4505 | default: |
4506 | abort (); | |
4507 | } | |
a94dbf2c JM |
4508 | } |
4509 | ||
3f76745e | 4510 | /* Output the encoding of an attribute value. */ |
469ac993 | 4511 | |
3f76745e JM |
4512 | static void |
4513 | output_value_format (v) | |
4514 | dw_val_ref v; | |
a94dbf2c | 4515 | { |
3f76745e | 4516 | enum dwarf_form form = value_format (v); |
71dfc51f | 4517 | |
3f76745e JM |
4518 | output_uleb128 (form); |
4519 | if (flag_verbose_asm) | |
4520 | fprintf (asm_out_file, " (%s)", dwarf_form_name (form)); | |
141719a8 | 4521 | |
3f76745e JM |
4522 | fputc ('\n', asm_out_file); |
4523 | } | |
469ac993 | 4524 | |
3f76745e JM |
4525 | /* Output the .debug_abbrev section which defines the DIE abbreviation |
4526 | table. */ | |
469ac993 | 4527 | |
3f76745e JM |
4528 | static void |
4529 | output_abbrev_section () | |
4530 | { | |
4531 | unsigned long abbrev_id; | |
71dfc51f | 4532 | |
3f76745e JM |
4533 | dw_attr_ref a_attr; |
4534 | for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) | |
4535 | { | |
4536 | register dw_die_ref abbrev = abbrev_die_table[abbrev_id]; | |
71dfc51f | 4537 | |
3f76745e JM |
4538 | output_uleb128 (abbrev_id); |
4539 | if (flag_verbose_asm) | |
4540 | fprintf (asm_out_file, " (abbrev code)"); | |
469ac993 | 4541 | |
3f76745e JM |
4542 | fputc ('\n', asm_out_file); |
4543 | output_uleb128 (abbrev->die_tag); | |
4544 | if (flag_verbose_asm) | |
4545 | fprintf (asm_out_file, " (TAG: %s)", | |
4546 | dwarf_tag_name (abbrev->die_tag)); | |
71dfc51f | 4547 | |
3f76745e JM |
4548 | fputc ('\n', asm_out_file); |
4549 | fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, | |
4550 | abbrev->die_child != NULL ? DW_children_yes : DW_children_no); | |
469ac993 | 4551 | |
3f76745e JM |
4552 | if (flag_verbose_asm) |
4553 | fprintf (asm_out_file, "\t%s %s", | |
4554 | ASM_COMMENT_START, | |
4555 | (abbrev->die_child != NULL | |
4556 | ? "DW_children_yes" : "DW_children_no")); | |
4557 | ||
4558 | fputc ('\n', asm_out_file); | |
4559 | ||
4560 | for (a_attr = abbrev->die_attr; a_attr != NULL; | |
4561 | a_attr = a_attr->dw_attr_next) | |
4562 | { | |
4563 | output_uleb128 (a_attr->dw_attr); | |
4564 | if (flag_verbose_asm) | |
4565 | fprintf (asm_out_file, " (%s)", | |
4566 | dwarf_attr_name (a_attr->dw_attr)); | |
4567 | ||
4568 | fputc ('\n', asm_out_file); | |
4569 | output_value_format (&a_attr->dw_attr_val); | |
469ac993 | 4570 | } |
469ac993 | 4571 | |
3f76745e | 4572 | fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP); |
469ac993 | 4573 | } |
a94dbf2c JM |
4574 | } |
4575 | ||
3f76745e | 4576 | /* Output location description stack opcode's operands (if any). */ |
71dfc51f | 4577 | |
3f76745e JM |
4578 | static void |
4579 | output_loc_operands (loc) | |
4580 | register dw_loc_descr_ref loc; | |
a3f97cbb | 4581 | { |
3f76745e JM |
4582 | register dw_val_ref val1 = &loc->dw_loc_oprnd1; |
4583 | register dw_val_ref val2 = &loc->dw_loc_oprnd2; | |
71dfc51f | 4584 | |
3f76745e | 4585 | switch (loc->dw_loc_opc) |
a3f97cbb | 4586 | { |
3f76745e JM |
4587 | case DW_OP_addr: |
4588 | ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr); | |
4589 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4590 | break; |
3f76745e JM |
4591 | case DW_OP_const1u: |
4592 | case DW_OP_const1s: | |
4593 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag); | |
4594 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4595 | break; |
3f76745e JM |
4596 | case DW_OP_const2u: |
4597 | case DW_OP_const2s: | |
4598 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int); | |
4599 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4600 | break; |
3f76745e JM |
4601 | case DW_OP_const4u: |
4602 | case DW_OP_const4s: | |
4603 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int); | |
4604 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4605 | break; |
3f76745e JM |
4606 | case DW_OP_const8u: |
4607 | case DW_OP_const8s: | |
4608 | abort (); | |
4609 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4610 | break; |
3f76745e JM |
4611 | case DW_OP_constu: |
4612 | output_uleb128 (val1->v.val_unsigned); | |
4613 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4614 | break; |
3f76745e JM |
4615 | case DW_OP_consts: |
4616 | output_sleb128 (val1->v.val_int); | |
4617 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4618 | break; |
3f76745e JM |
4619 | case DW_OP_pick: |
4620 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int); | |
4621 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4622 | break; |
3f76745e JM |
4623 | case DW_OP_plus_uconst: |
4624 | output_uleb128 (val1->v.val_unsigned); | |
4625 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4626 | break; |
3f76745e JM |
4627 | case DW_OP_skip: |
4628 | case DW_OP_bra: | |
4629 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int); | |
4630 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4631 | break; |
3f76745e JM |
4632 | case DW_OP_breg0: |
4633 | case DW_OP_breg1: | |
4634 | case DW_OP_breg2: | |
4635 | case DW_OP_breg3: | |
4636 | case DW_OP_breg4: | |
4637 | case DW_OP_breg5: | |
4638 | case DW_OP_breg6: | |
4639 | case DW_OP_breg7: | |
4640 | case DW_OP_breg8: | |
4641 | case DW_OP_breg9: | |
4642 | case DW_OP_breg10: | |
4643 | case DW_OP_breg11: | |
4644 | case DW_OP_breg12: | |
4645 | case DW_OP_breg13: | |
4646 | case DW_OP_breg14: | |
4647 | case DW_OP_breg15: | |
4648 | case DW_OP_breg16: | |
4649 | case DW_OP_breg17: | |
4650 | case DW_OP_breg18: | |
4651 | case DW_OP_breg19: | |
4652 | case DW_OP_breg20: | |
4653 | case DW_OP_breg21: | |
4654 | case DW_OP_breg22: | |
4655 | case DW_OP_breg23: | |
4656 | case DW_OP_breg24: | |
4657 | case DW_OP_breg25: | |
4658 | case DW_OP_breg26: | |
4659 | case DW_OP_breg27: | |
4660 | case DW_OP_breg28: | |
4661 | case DW_OP_breg29: | |
4662 | case DW_OP_breg30: | |
4663 | case DW_OP_breg31: | |
4664 | output_sleb128 (val1->v.val_int); | |
4665 | fputc ('\n', asm_out_file); | |
4666 | break; | |
4667 | case DW_OP_regx: | |
4668 | output_uleb128 (val1->v.val_unsigned); | |
4669 | fputc ('\n', asm_out_file); | |
4670 | break; | |
4671 | case DW_OP_fbreg: | |
4672 | output_sleb128 (val1->v.val_int); | |
4673 | fputc ('\n', asm_out_file); | |
4674 | break; | |
4675 | case DW_OP_bregx: | |
4676 | output_uleb128 (val1->v.val_unsigned); | |
4677 | fputc ('\n', asm_out_file); | |
4678 | output_sleb128 (val2->v.val_int); | |
4679 | fputc ('\n', asm_out_file); | |
4680 | break; | |
4681 | case DW_OP_piece: | |
4682 | output_uleb128 (val1->v.val_unsigned); | |
4683 | fputc ('\n', asm_out_file); | |
4684 | break; | |
4685 | case DW_OP_deref_size: | |
4686 | case DW_OP_xderef_size: | |
4687 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag); | |
4688 | fputc ('\n', asm_out_file); | |
a3f97cbb JW |
4689 | break; |
4690 | default: | |
4691 | break; | |
4692 | } | |
a3f97cbb JW |
4693 | } |
4694 | ||
3f76745e | 4695 | /* Compute the offset of a sibling. */ |
71dfc51f | 4696 | |
3f76745e JM |
4697 | static unsigned long |
4698 | sibling_offset (die) | |
4699 | dw_die_ref die; | |
a3f97cbb | 4700 | { |
3f76745e | 4701 | unsigned long offset; |
71dfc51f | 4702 | |
3f76745e JM |
4703 | if (die->die_child_last == NULL) |
4704 | offset = die->die_offset + size_of_die (die); | |
4705 | else | |
4706 | offset = sibling_offset (die->die_child_last) + 1; | |
71dfc51f | 4707 | |
3f76745e | 4708 | return offset; |
a3f97cbb JW |
4709 | } |
4710 | ||
3f76745e JM |
4711 | /* Output the DIE and its attributes. Called recursively to generate |
4712 | the definitions of each child DIE. */ | |
71dfc51f | 4713 | |
a3f97cbb | 4714 | static void |
3f76745e JM |
4715 | output_die (die) |
4716 | register dw_die_ref die; | |
a3f97cbb | 4717 | { |
3f76745e JM |
4718 | register dw_attr_ref a; |
4719 | register dw_die_ref c; | |
4720 | register unsigned long ref_offset; | |
4721 | register unsigned long size; | |
4722 | register dw_loc_descr_ref loc; | |
4723 | register int i; | |
a94dbf2c | 4724 | |
3f76745e JM |
4725 | output_uleb128 (die->die_abbrev); |
4726 | if (flag_verbose_asm) | |
4727 | fprintf (asm_out_file, " (DIE (0x%x) %s)", | |
4728 | die->die_offset, dwarf_tag_name (die->die_tag)); | |
a94dbf2c | 4729 | |
3f76745e | 4730 | fputc ('\n', asm_out_file); |
a94dbf2c | 4731 | |
3f76745e | 4732 | for (a = die->die_attr; a != NULL; a = a->dw_attr_next) |
a3f97cbb | 4733 | { |
3f76745e JM |
4734 | switch (a->dw_attr_val.val_class) |
4735 | { | |
4736 | case dw_val_class_addr: | |
4737 | ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, | |
4738 | a->dw_attr_val.v.val_addr); | |
4739 | break; | |
a3f97cbb | 4740 | |
3f76745e JM |
4741 | case dw_val_class_loc: |
4742 | size = size_of_locs (a->dw_attr_val.v.val_loc); | |
71dfc51f | 4743 | |
3f76745e JM |
4744 | /* Output the block length for this list of location operations. */ |
4745 | switch (constant_size (size)) | |
4746 | { | |
4747 | case 1: | |
4748 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size); | |
4749 | break; | |
4750 | case 2: | |
4751 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size); | |
4752 | break; | |
4753 | default: | |
4754 | abort (); | |
4755 | } | |
71dfc51f | 4756 | |
3f76745e JM |
4757 | if (flag_verbose_asm) |
4758 | fprintf (asm_out_file, "\t%s %s", | |
4759 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
71dfc51f | 4760 | |
3f76745e JM |
4761 | fputc ('\n', asm_out_file); |
4762 | for (loc = a->dw_attr_val.v.val_loc; loc != NULL; | |
4763 | loc = loc->dw_loc_next) | |
4764 | { | |
4765 | /* Output the opcode. */ | |
4766 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc); | |
4767 | if (flag_verbose_asm) | |
4768 | fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START, | |
4769 | dwarf_stack_op_name (loc->dw_loc_opc)); | |
71dfc51f | 4770 | |
3f76745e | 4771 | fputc ('\n', asm_out_file); |
71dfc51f | 4772 | |
3f76745e JM |
4773 | /* Output the operand(s) (if any). */ |
4774 | output_loc_operands (loc); | |
4775 | } | |
a3f97cbb | 4776 | break; |
3f76745e JM |
4777 | |
4778 | case dw_val_class_const: | |
4779 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int); | |
a3f97cbb | 4780 | break; |
3f76745e JM |
4781 | |
4782 | case dw_val_class_unsigned_const: | |
4783 | switch (constant_size (a->dw_attr_val.v.val_unsigned)) | |
4784 | { | |
4785 | case 1: | |
4786 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
4787 | a->dw_attr_val.v.val_unsigned); | |
4788 | break; | |
4789 | case 2: | |
4790 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, | |
4791 | a->dw_attr_val.v.val_unsigned); | |
4792 | break; | |
4793 | case 4: | |
4794 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, | |
4795 | a->dw_attr_val.v.val_unsigned); | |
4796 | break; | |
4797 | case 8: | |
4798 | ASM_OUTPUT_DWARF_DATA8 (asm_out_file, | |
4799 | a->dw_attr_val.v.val_long_long.hi, | |
4800 | a->dw_attr_val.v.val_long_long.low); | |
4801 | break; | |
4802 | default: | |
4803 | abort (); | |
4804 | } | |
a3f97cbb | 4805 | break; |
3f76745e JM |
4806 | |
4807 | case dw_val_class_long_long: | |
4808 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8); | |
4809 | if (flag_verbose_asm) | |
4810 | fprintf (asm_out_file, "\t%s %s", | |
4811 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
4812 | ||
4813 | fputc ('\n', asm_out_file); | |
4814 | ASM_OUTPUT_DWARF_DATA8 (asm_out_file, | |
4815 | a->dw_attr_val.v.val_long_long.hi, | |
4816 | a->dw_attr_val.v.val_long_long.low); | |
4817 | ||
4818 | if (flag_verbose_asm) | |
4819 | fprintf (asm_out_file, | |
4820 | "\t%s long long constant", ASM_COMMENT_START); | |
4821 | ||
4822 | fputc ('\n', asm_out_file); | |
a3f97cbb | 4823 | break; |
3f76745e JM |
4824 | |
4825 | case dw_val_class_float: | |
4826 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
4827 | a->dw_attr_val.v.val_float.length * 4); | |
4828 | if (flag_verbose_asm) | |
4829 | fprintf (asm_out_file, "\t%s %s", | |
4830 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
4831 | ||
4832 | fputc ('\n', asm_out_file); | |
4833 | for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i) | |
4834 | { | |
4835 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, | |
4836 | a->dw_attr_val.v.val_float.array[i]); | |
4837 | if (flag_verbose_asm) | |
4838 | fprintf (asm_out_file, "\t%s fp constant word %d", | |
4839 | ASM_COMMENT_START, i); | |
4840 | ||
4841 | fputc ('\n', asm_out_file); | |
4842 | } | |
a3f97cbb | 4843 | break; |
3f76745e JM |
4844 | |
4845 | case dw_val_class_flag: | |
4846 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag); | |
a3f97cbb | 4847 | break; |
3f76745e JM |
4848 | |
4849 | case dw_val_class_die_ref: | |
4850 | if (a->dw_attr_val.v.val_die_ref != NULL) | |
4851 | ref_offset = a->dw_attr_val.v.val_die_ref->die_offset; | |
4852 | else if (a->dw_attr == DW_AT_sibling) | |
4853 | ref_offset = sibling_offset(die); | |
4854 | else | |
4855 | abort (); | |
4856 | ||
4857 | ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset); | |
a3f97cbb | 4858 | break; |
3f76745e JM |
4859 | |
4860 | case dw_val_class_fde_ref: | |
a6ab3aad JM |
4861 | { |
4862 | char l1[20]; | |
4863 | ASM_GENERATE_INTERNAL_LABEL | |
4864 | (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2); | |
4865 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1); | |
4866 | fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE); | |
4867 | } | |
a3f97cbb | 4868 | break; |
a3f97cbb | 4869 | |
3f76745e JM |
4870 | case dw_val_class_lbl_id: |
4871 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id); | |
4872 | break; | |
71dfc51f | 4873 | |
3f76745e JM |
4874 | case dw_val_class_section_offset: |
4875 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, | |
4876 | stripattributes | |
4877 | (a->dw_attr_val.v.val_section)); | |
4878 | break; | |
a3f97cbb | 4879 | |
3f76745e JM |
4880 | case dw_val_class_str: |
4881 | ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str); | |
4882 | break; | |
b2932ae5 | 4883 | |
3f76745e JM |
4884 | default: |
4885 | abort (); | |
4886 | } | |
a94dbf2c | 4887 | |
3f76745e JM |
4888 | if (a->dw_attr_val.val_class != dw_val_class_loc |
4889 | && a->dw_attr_val.val_class != dw_val_class_long_long | |
4890 | && a->dw_attr_val.val_class != dw_val_class_float) | |
4891 | { | |
4892 | if (flag_verbose_asm) | |
4893 | fprintf (asm_out_file, "\t%s %s", | |
4894 | ASM_COMMENT_START, dwarf_attr_name (a->dw_attr)); | |
b2932ae5 | 4895 | |
3f76745e JM |
4896 | fputc ('\n', asm_out_file); |
4897 | } | |
4898 | } | |
71dfc51f | 4899 | |
3f76745e JM |
4900 | for (c = die->die_child; c != NULL; c = c->die_sib) |
4901 | output_die (c); | |
71dfc51f | 4902 | |
3f76745e | 4903 | if (die->die_child != NULL) |
7e23cb16 | 4904 | { |
3f76745e JM |
4905 | /* Add null byte to terminate sibling list. */ |
4906 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
4907 | if (flag_verbose_asm) | |
4908 | fprintf (asm_out_file, "\t%s end of children of DIE 0x%x", | |
4909 | ASM_COMMENT_START, die->die_offset); | |
4910 | ||
7e23cb16 JM |
4911 | fputc ('\n', asm_out_file); |
4912 | } | |
3f76745e | 4913 | } |
71dfc51f | 4914 | |
3f76745e JM |
4915 | /* Output the compilation unit that appears at the beginning of the |
4916 | .debug_info section, and precedes the DIE descriptions. */ | |
71dfc51f | 4917 | |
3f76745e JM |
4918 | static void |
4919 | output_compilation_unit_header () | |
4920 | { | |
4921 | ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE); | |
a3f97cbb | 4922 | if (flag_verbose_asm) |
3f76745e JM |
4923 | fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.", |
4924 | ASM_COMMENT_START); | |
71dfc51f | 4925 | |
a3f97cbb | 4926 | fputc ('\n', asm_out_file); |
3f76745e | 4927 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); |
a3f97cbb | 4928 | if (flag_verbose_asm) |
3f76745e | 4929 | fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START); |
71dfc51f | 4930 | |
a3f97cbb | 4931 | fputc ('\n', asm_out_file); |
3f76745e | 4932 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (ABBREV_SECTION)); |
a3f97cbb | 4933 | if (flag_verbose_asm) |
3f76745e JM |
4934 | fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section", |
4935 | ASM_COMMENT_START); | |
71dfc51f | 4936 | |
a3f97cbb | 4937 | fputc ('\n', asm_out_file); |
3f76745e | 4938 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE); |
a3f97cbb | 4939 | if (flag_verbose_asm) |
3f76745e | 4940 | fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START); |
71dfc51f | 4941 | |
a3f97cbb | 4942 | fputc ('\n', asm_out_file); |
a3f97cbb JW |
4943 | } |
4944 | ||
a1d7ffe3 JM |
4945 | /* The DWARF2 pubname for a nested thingy looks like "A::f". The output |
4946 | of decl_printable_name for C++ looks like "A::f(int)". Let's drop the | |
4947 | argument list, and maybe the scope. */ | |
4948 | ||
71dfc51f | 4949 | static char * |
a1d7ffe3 JM |
4950 | dwarf2_name (decl, scope) |
4951 | tree decl; | |
4952 | int scope; | |
4953 | { | |
4954 | return (*decl_printable_name) (decl, scope ? 1 : 0); | |
4955 | } | |
4956 | ||
d291dd49 | 4957 | /* Add a new entry to .debug_pubnames if appropriate. */ |
71dfc51f | 4958 | |
d291dd49 JM |
4959 | static void |
4960 | add_pubname (decl, die) | |
4961 | tree decl; | |
4962 | dw_die_ref die; | |
4963 | { | |
4964 | pubname_ref p; | |
4965 | ||
4966 | if (! TREE_PUBLIC (decl)) | |
4967 | return; | |
4968 | ||
4969 | if (pubname_table_in_use == pubname_table_allocated) | |
4970 | { | |
4971 | pubname_table_allocated += PUBNAME_TABLE_INCREMENT; | |
4972 | pubname_table = (pubname_ref) xrealloc | |
4973 | (pubname_table, pubname_table_allocated * sizeof (pubname_entry)); | |
4974 | } | |
71dfc51f | 4975 | |
d291dd49 JM |
4976 | p = &pubname_table[pubname_table_in_use++]; |
4977 | p->die = die; | |
a1d7ffe3 JM |
4978 | |
4979 | p->name = xstrdup (dwarf2_name (decl, 1)); | |
d291dd49 JM |
4980 | } |
4981 | ||
a3f97cbb JW |
4982 | /* Output the public names table used to speed up access to externally |
4983 | visible names. For now, only generate entries for externally | |
4984 | visible procedures. */ | |
71dfc51f | 4985 | |
a3f97cbb JW |
4986 | static void |
4987 | output_pubnames () | |
4988 | { | |
d291dd49 | 4989 | register unsigned i; |
71dfc51f RK |
4990 | register unsigned long pubnames_length = size_of_pubnames (); |
4991 | ||
4992 | ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length); | |
4993 | ||
a3f97cbb | 4994 | if (flag_verbose_asm) |
71dfc51f RK |
4995 | fprintf (asm_out_file, "\t%s Length of Public Names Info.", |
4996 | ASM_COMMENT_START); | |
4997 | ||
a3f97cbb JW |
4998 | fputc ('\n', asm_out_file); |
4999 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); | |
71dfc51f | 5000 | |
a3f97cbb | 5001 | if (flag_verbose_asm) |
71dfc51f RK |
5002 | fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START); |
5003 | ||
a3f97cbb | 5004 | fputc ('\n', asm_out_file); |
c53aa195 | 5005 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_INFO_SECTION)); |
a3f97cbb | 5006 | if (flag_verbose_asm) |
71dfc51f RK |
5007 | fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.", |
5008 | ASM_COMMENT_START); | |
5009 | ||
a3f97cbb | 5010 | fputc ('\n', asm_out_file); |
7e23cb16 | 5011 | ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset); |
a3f97cbb | 5012 | if (flag_verbose_asm) |
71dfc51f RK |
5013 | fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START); |
5014 | ||
a3f97cbb | 5015 | fputc ('\n', asm_out_file); |
d291dd49 | 5016 | for (i = 0; i < pubname_table_in_use; ++i) |
a3f97cbb | 5017 | { |
d291dd49 | 5018 | register pubname_ref pub = &pubname_table[i]; |
71dfc51f | 5019 | |
7e23cb16 | 5020 | ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset); |
d291dd49 | 5021 | if (flag_verbose_asm) |
71dfc51f RK |
5022 | fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START); |
5023 | ||
d291dd49 JM |
5024 | fputc ('\n', asm_out_file); |
5025 | ||
5026 | ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name); | |
5027 | if (flag_verbose_asm) | |
71dfc51f RK |
5028 | fprintf (asm_out_file, "%s external name", ASM_COMMENT_START); |
5029 | ||
d291dd49 | 5030 | fputc ('\n', asm_out_file); |
a3f97cbb | 5031 | } |
71dfc51f | 5032 | |
7e23cb16 | 5033 | ASM_OUTPUT_DWARF_DATA (asm_out_file, 0); |
a3f97cbb JW |
5034 | fputc ('\n', asm_out_file); |
5035 | } | |
5036 | ||
d291dd49 | 5037 | /* Add a new entry to .debug_aranges if appropriate. */ |
71dfc51f | 5038 | |
d291dd49 JM |
5039 | static void |
5040 | add_arange (decl, die) | |
5041 | tree decl; | |
5042 | dw_die_ref die; | |
5043 | { | |
5044 | if (! DECL_SECTION_NAME (decl)) | |
5045 | return; | |
5046 | ||
5047 | if (arange_table_in_use == arange_table_allocated) | |
5048 | { | |
5049 | arange_table_allocated += ARANGE_TABLE_INCREMENT; | |
71dfc51f RK |
5050 | arange_table |
5051 | = (arange_ref) xrealloc (arange_table, | |
5052 | arange_table_allocated * sizeof (dw_die_ref)); | |
d291dd49 | 5053 | } |
71dfc51f | 5054 | |
d291dd49 JM |
5055 | arange_table[arange_table_in_use++] = die; |
5056 | } | |
5057 | ||
a3f97cbb JW |
5058 | /* Output the information that goes into the .debug_aranges table. |
5059 | Namely, define the beginning and ending address range of the | |
5060 | text section generated for this compilation unit. */ | |
71dfc51f | 5061 | |
a3f97cbb JW |
5062 | static void |
5063 | output_aranges () | |
5064 | { | |
d291dd49 | 5065 | register unsigned i; |
71dfc51f RK |
5066 | register unsigned long aranges_length = size_of_aranges (); |
5067 | ||
5068 | ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length); | |
a3f97cbb | 5069 | if (flag_verbose_asm) |
71dfc51f RK |
5070 | fprintf (asm_out_file, "\t%s Length of Address Ranges Info.", |
5071 | ASM_COMMENT_START); | |
5072 | ||
a3f97cbb JW |
5073 | fputc ('\n', asm_out_file); |
5074 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); | |
5075 | if (flag_verbose_asm) | |
71dfc51f RK |
5076 | fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START); |
5077 | ||
a3f97cbb | 5078 | fputc ('\n', asm_out_file); |
c53aa195 | 5079 | ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (DEBUG_INFO_SECTION)); |
a3f97cbb | 5080 | if (flag_verbose_asm) |
71dfc51f RK |
5081 | fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.", |
5082 | ASM_COMMENT_START); | |
5083 | ||
a3f97cbb JW |
5084 | fputc ('\n', asm_out_file); |
5085 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE); | |
5086 | if (flag_verbose_asm) | |
71dfc51f RK |
5087 | fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START); |
5088 | ||
a3f97cbb JW |
5089 | fputc ('\n', asm_out_file); |
5090 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
5091 | if (flag_verbose_asm) | |
71dfc51f RK |
5092 | fprintf (asm_out_file, "\t%s Size of Segment Descriptor", |
5093 | ASM_COMMENT_START); | |
5094 | ||
a3f97cbb JW |
5095 | fputc ('\n', asm_out_file); |
5096 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4); | |
7e23cb16 JM |
5097 | if (PTR_SIZE == 8) |
5098 | fprintf (asm_out_file, ",0,0"); | |
71dfc51f | 5099 | |
a3f97cbb | 5100 | if (flag_verbose_asm) |
71dfc51f RK |
5101 | fprintf (asm_out_file, "\t%s Pad to %d byte boundary", |
5102 | ASM_COMMENT_START, 2 * PTR_SIZE); | |
5103 | ||
a3f97cbb | 5104 | fputc ('\n', asm_out_file); |
bdb669cb | 5105 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION); |
a3f97cbb | 5106 | if (flag_verbose_asm) |
71dfc51f RK |
5107 | fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START); |
5108 | ||
a3f97cbb | 5109 | fputc ('\n', asm_out_file); |
5c90448c | 5110 | ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label, TEXT_SECTION); |
a3f97cbb | 5111 | if (flag_verbose_asm) |
71dfc51f RK |
5112 | fprintf (asm_out_file, "%s Length", ASM_COMMENT_START); |
5113 | ||
a3f97cbb | 5114 | fputc ('\n', asm_out_file); |
d291dd49 JM |
5115 | for (i = 0; i < arange_table_in_use; ++i) |
5116 | { | |
5117 | dw_die_ref a = arange_table[i]; | |
71dfc51f | 5118 | |
d291dd49 JM |
5119 | if (a->die_tag == DW_TAG_subprogram) |
5120 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (a)); | |
5121 | else | |
a1d7ffe3 JM |
5122 | { |
5123 | char *name = get_AT_string (a, DW_AT_MIPS_linkage_name); | |
5124 | if (! name) | |
5125 | name = get_AT_string (a, DW_AT_name); | |
71dfc51f | 5126 | |
a1d7ffe3 JM |
5127 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, name); |
5128 | } | |
71dfc51f RK |
5129 | |
5130 | if (flag_verbose_asm) | |
5131 | fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START); | |
5132 | ||
d291dd49 JM |
5133 | fputc ('\n', asm_out_file); |
5134 | if (a->die_tag == DW_TAG_subprogram) | |
7e23cb16 JM |
5135 | ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (a), |
5136 | get_AT_low_pc (a)); | |
d291dd49 | 5137 | else |
7e23cb16 JM |
5138 | ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, |
5139 | get_AT_unsigned (a, DW_AT_byte_size)); | |
71dfc51f | 5140 | |
d291dd49 | 5141 | if (flag_verbose_asm) |
71dfc51f RK |
5142 | fprintf (asm_out_file, "%s Length", ASM_COMMENT_START); |
5143 | ||
d291dd49 JM |
5144 | fputc ('\n', asm_out_file); |
5145 | } | |
71dfc51f | 5146 | |
a3f97cbb | 5147 | /* Output the terminator words. */ |
7e23cb16 | 5148 | ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0); |
a3f97cbb | 5149 | fputc ('\n', asm_out_file); |
7e23cb16 | 5150 | ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0); |
a3f97cbb JW |
5151 | fputc ('\n', asm_out_file); |
5152 | } | |
5153 | ||
5154 | /* Output the source line number correspondence information. This | |
f19a6894 JW |
5155 | information goes into the .debug_line section. |
5156 | ||
5157 | If the format of this data changes, then the function size_of_line_info | |
5158 | must also be adjusted the same way. */ | |
71dfc51f | 5159 | |
a3f97cbb JW |
5160 | static void |
5161 | output_line_info () | |
5162 | { | |
a3f97cbb JW |
5163 | char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
5164 | char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5165 | register unsigned opc; | |
5166 | register unsigned n_op_args; | |
a3f97cbb JW |
5167 | register unsigned long ft_index; |
5168 | register unsigned long lt_index; | |
5169 | register unsigned long current_line; | |
5170 | register long line_offset; | |
5171 | register long line_delta; | |
5172 | register unsigned long current_file; | |
e90b62db | 5173 | register unsigned long function; |
71dfc51f | 5174 | |
7e23cb16 | 5175 | ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_info ()); |
a3f97cbb | 5176 | if (flag_verbose_asm) |
71dfc51f RK |
5177 | fprintf (asm_out_file, "\t%s Length of Source Line Info.", |
5178 | ASM_COMMENT_START); | |
5179 | ||
a3f97cbb JW |
5180 | fputc ('\n', asm_out_file); |
5181 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION); | |
5182 | if (flag_verbose_asm) | |
71dfc51f RK |
5183 | fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START); |
5184 | ||
a3f97cbb | 5185 | fputc ('\n', asm_out_file); |
7e23cb16 | 5186 | ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ()); |
a3f97cbb | 5187 | if (flag_verbose_asm) |
71dfc51f RK |
5188 | fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START); |
5189 | ||
a3f97cbb JW |
5190 | fputc ('\n', asm_out_file); |
5191 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH); | |
5192 | if (flag_verbose_asm) | |
71dfc51f RK |
5193 | fprintf (asm_out_file, "\t%s Minimum Instruction Length", |
5194 | ASM_COMMENT_START); | |
5195 | ||
a3f97cbb JW |
5196 | fputc ('\n', asm_out_file); |
5197 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START); | |
5198 | if (flag_verbose_asm) | |
71dfc51f RK |
5199 | fprintf (asm_out_file, "\t%s Default is_stmt_start flag", |
5200 | ASM_COMMENT_START); | |
5201 | ||
a3f97cbb JW |
5202 | fputc ('\n', asm_out_file); |
5203 | fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE); | |
5204 | if (flag_verbose_asm) | |
71dfc51f RK |
5205 | fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)", |
5206 | ASM_COMMENT_START); | |
5207 | ||
a3f97cbb JW |
5208 | fputc ('\n', asm_out_file); |
5209 | fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE); | |
5210 | if (flag_verbose_asm) | |
71dfc51f RK |
5211 | fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)", |
5212 | ASM_COMMENT_START); | |
5213 | ||
a3f97cbb JW |
5214 | fputc ('\n', asm_out_file); |
5215 | fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE); | |
5216 | if (flag_verbose_asm) | |
71dfc51f RK |
5217 | fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START); |
5218 | ||
a3f97cbb JW |
5219 | fputc ('\n', asm_out_file); |
5220 | for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc) | |
5221 | { | |
5222 | switch (opc) | |
5223 | { | |
5224 | case DW_LNS_advance_pc: | |
5225 | case DW_LNS_advance_line: | |
5226 | case DW_LNS_set_file: | |
5227 | case DW_LNS_set_column: | |
5228 | case DW_LNS_fixed_advance_pc: | |
5229 | n_op_args = 1; | |
5230 | break; | |
5231 | default: | |
5232 | n_op_args = 0; | |
5233 | break; | |
5234 | } | |
5235 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args); | |
5236 | if (flag_verbose_asm) | |
71dfc51f RK |
5237 | fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args", |
5238 | ASM_COMMENT_START, opc, n_op_args); | |
a3f97cbb JW |
5239 | fputc ('\n', asm_out_file); |
5240 | } | |
71dfc51f | 5241 | |
a3f97cbb | 5242 | if (flag_verbose_asm) |
71dfc51f RK |
5243 | fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START); |
5244 | ||
a3f97cbb JW |
5245 | /* Include directory table is empty, at present */ |
5246 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
5247 | fputc ('\n', asm_out_file); | |
5248 | if (flag_verbose_asm) | |
71dfc51f RK |
5249 | fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START); |
5250 | ||
a3f97cbb JW |
5251 | for (ft_index = 1; ft_index < file_table_in_use; ++ft_index) |
5252 | { | |
5253 | ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]); | |
5254 | if (flag_verbose_asm) | |
71dfc51f RK |
5255 | fprintf (asm_out_file, "%s File Entry: 0x%x", |
5256 | ASM_COMMENT_START, ft_index); | |
5257 | ||
a3f97cbb | 5258 | fputc ('\n', asm_out_file); |
71dfc51f | 5259 | |
a3f97cbb JW |
5260 | /* Include directory index */ |
5261 | output_uleb128 (0); | |
5262 | fputc ('\n', asm_out_file); | |
71dfc51f | 5263 | |
a3f97cbb JW |
5264 | /* Modification time */ |
5265 | output_uleb128 (0); | |
5266 | fputc ('\n', asm_out_file); | |
71dfc51f | 5267 | |
a3f97cbb JW |
5268 | /* File length in bytes */ |
5269 | output_uleb128 (0); | |
5270 | fputc ('\n', asm_out_file); | |
5271 | } | |
71dfc51f | 5272 | |
a3f97cbb JW |
5273 | /* Terminate the file name table */ |
5274 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
5275 | fputc ('\n', asm_out_file); | |
5276 | ||
5277 | /* Set the address register to the first location in the text section */ | |
5278 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
5279 | if (flag_verbose_asm) | |
71dfc51f RK |
5280 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START); |
5281 | ||
a3f97cbb JW |
5282 | fputc ('\n', asm_out_file); |
5283 | output_uleb128 (1 + PTR_SIZE); | |
5284 | fputc ('\n', asm_out_file); | |
5285 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5286 | fputc ('\n', asm_out_file); | |
bdb669cb | 5287 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_SECTION); |
a3f97cbb JW |
5288 | fputc ('\n', asm_out_file); |
5289 | ||
5290 | /* Generate the line number to PC correspondence table, encoded as | |
5291 | a series of state machine operations. */ | |
5292 | current_file = 1; | |
5293 | current_line = 1; | |
bdb669cb | 5294 | strcpy (prev_line_label, TEXT_SECTION); |
a3f97cbb JW |
5295 | for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) |
5296 | { | |
e90b62db | 5297 | register dw_line_info_ref line_info; |
71dfc51f | 5298 | |
f19a6894 JW |
5299 | /* Emit debug info for the address of the current line, choosing |
5300 | the encoding that uses the least amount of space. */ | |
5301 | /* ??? Unfortunately, we have little choice here currently, and must | |
5302 | always use the most general form. Gcc does not know the address | |
5303 | delta itself, so we can't use DW_LNS_advance_pc. There are no known | |
5304 | dwarf2 aware assemblers at this time, so we can't use any special | |
5305 | pseudo ops that would allow the assembler to optimally encode this for | |
5306 | us. Many ports do have length attributes which will give an upper | |
5307 | bound on the address range. We could perhaps use length attributes | |
5308 | to determine when it is safe to use DW_LNS_fixed_advance_pc. */ | |
5c90448c | 5309 | ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index); |
f19a6894 JW |
5310 | if (0) |
5311 | { | |
5312 | /* This can handle deltas up to 0xffff. This takes 3 bytes. */ | |
5313 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
5314 | if (flag_verbose_asm) | |
5315 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", | |
5316 | ASM_COMMENT_START); | |
5317 | ||
5318 | fputc ('\n', asm_out_file); | |
5319 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label); | |
5320 | fputc ('\n', asm_out_file); | |
5321 | } | |
5322 | else | |
5323 | { | |
5324 | /* This can handle any delta. This takes 4+PTR_SIZE bytes. */ | |
5325 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
5326 | if (flag_verbose_asm) | |
5327 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", | |
5328 | ASM_COMMENT_START); | |
5329 | fputc ('\n', asm_out_file); | |
5330 | output_uleb128 (1 + PTR_SIZE); | |
5331 | fputc ('\n', asm_out_file); | |
5332 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5333 | fputc ('\n', asm_out_file); | |
5334 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
5335 | fputc ('\n', asm_out_file); | |
5336 | } | |
5337 | strcpy (prev_line_label, line_label); | |
5338 | ||
5339 | /* Emit debug info for the source file of the current line, if | |
5340 | different from the previous line. */ | |
a3f97cbb JW |
5341 | line_info = &line_info_table[lt_index]; |
5342 | if (line_info->dw_file_num != current_file) | |
5343 | { | |
5344 | current_file = line_info->dw_file_num; | |
5345 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file); | |
5346 | if (flag_verbose_asm) | |
71dfc51f RK |
5347 | fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START); |
5348 | ||
a3f97cbb JW |
5349 | fputc ('\n', asm_out_file); |
5350 | output_uleb128 (current_file); | |
5351 | if (flag_verbose_asm) | |
b2932ae5 | 5352 | fprintf (asm_out_file, " (\"%s\")", file_table[current_file]); |
71dfc51f | 5353 | |
a3f97cbb JW |
5354 | fputc ('\n', asm_out_file); |
5355 | } | |
71dfc51f | 5356 | |
f19a6894 JW |
5357 | /* Emit debug info for the current line number, choosing the encoding |
5358 | that uses the least amount of space. */ | |
a94dbf2c JM |
5359 | line_offset = line_info->dw_line_num - current_line; |
5360 | line_delta = line_offset - DWARF_LINE_BASE; | |
5361 | current_line = line_info->dw_line_num; | |
5362 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
a3f97cbb | 5363 | { |
f19a6894 JW |
5364 | /* This can handle deltas from -10 to 234, using the current |
5365 | definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This | |
5366 | takes 1 byte. */ | |
a94dbf2c JM |
5367 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, |
5368 | DWARF_LINE_OPCODE_BASE + line_delta); | |
5369 | if (flag_verbose_asm) | |
a94dbf2c JM |
5370 | fprintf (asm_out_file, |
5371 | "\t%s line %d", ASM_COMMENT_START, current_line); | |
71dfc51f | 5372 | |
a94dbf2c JM |
5373 | fputc ('\n', asm_out_file); |
5374 | } | |
5375 | else | |
5376 | { | |
f19a6894 JW |
5377 | /* This can handle any delta. This takes at least 4 bytes, depending |
5378 | on the value being encoded. */ | |
a94dbf2c JM |
5379 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line); |
5380 | if (flag_verbose_asm) | |
71dfc51f RK |
5381 | fprintf (asm_out_file, "\t%s advance to line %d", |
5382 | ASM_COMMENT_START, current_line); | |
5383 | ||
a94dbf2c JM |
5384 | fputc ('\n', asm_out_file); |
5385 | output_sleb128 (line_offset); | |
5386 | fputc ('\n', asm_out_file); | |
5387 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy); | |
5388 | fputc ('\n', asm_out_file); | |
a3f97cbb | 5389 | } |
a3f97cbb JW |
5390 | } |
5391 | ||
f19a6894 JW |
5392 | /* Emit debug info for the address of the end of the function. */ |
5393 | if (0) | |
5394 | { | |
5395 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
5396 | if (flag_verbose_asm) | |
5397 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", | |
5398 | ASM_COMMENT_START); | |
71dfc51f | 5399 | |
f19a6894 JW |
5400 | fputc ('\n', asm_out_file); |
5401 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label); | |
5402 | fputc ('\n', asm_out_file); | |
5403 | } | |
5404 | else | |
5405 | { | |
5406 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
5407 | if (flag_verbose_asm) | |
5408 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START); | |
5409 | fputc ('\n', asm_out_file); | |
5410 | output_uleb128 (1 + PTR_SIZE); | |
5411 | fputc ('\n', asm_out_file); | |
5412 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5413 | fputc ('\n', asm_out_file); | |
5414 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label); | |
5415 | fputc ('\n', asm_out_file); | |
5416 | } | |
bdb669cb | 5417 | |
a3f97cbb JW |
5418 | /* Output the marker for the end of the line number info. */ |
5419 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
5420 | if (flag_verbose_asm) | |
71dfc51f RK |
5421 | fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START); |
5422 | ||
a3f97cbb JW |
5423 | fputc ('\n', asm_out_file); |
5424 | output_uleb128 (1); | |
5425 | fputc ('\n', asm_out_file); | |
5426 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence); | |
5427 | fputc ('\n', asm_out_file); | |
e90b62db JM |
5428 | |
5429 | function = 0; | |
5430 | current_file = 1; | |
5431 | current_line = 1; | |
5432 | for (lt_index = 0; lt_index < separate_line_info_table_in_use; ) | |
5433 | { | |
5434 | register dw_separate_line_info_ref line_info | |
5435 | = &separate_line_info_table[lt_index]; | |
71dfc51f | 5436 | |
f19a6894 JW |
5437 | /* Emit debug info for the address of the current line. If this is |
5438 | a new function, or the first line of a function, then we need | |
5439 | to handle it differently. */ | |
5c90448c JM |
5440 | ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL, |
5441 | lt_index); | |
e90b62db JM |
5442 | if (function != line_info->function) |
5443 | { | |
5444 | function = line_info->function; | |
71dfc51f | 5445 | |
e90b62db JM |
5446 | /* Set the address register to the first line in the function */ |
5447 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
5448 | if (flag_verbose_asm) | |
5449 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", | |
5450 | ASM_COMMENT_START); | |
71dfc51f | 5451 | |
e90b62db JM |
5452 | fputc ('\n', asm_out_file); |
5453 | output_uleb128 (1 + PTR_SIZE); | |
5454 | fputc ('\n', asm_out_file); | |
5455 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5456 | fputc ('\n', asm_out_file); | |
5457 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
5458 | fputc ('\n', asm_out_file); | |
5459 | } | |
5460 | else | |
5461 | { | |
f19a6894 JW |
5462 | /* ??? See the DW_LNS_advance_pc comment above. */ |
5463 | if (0) | |
5464 | { | |
5465 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
5466 | if (flag_verbose_asm) | |
5467 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", | |
5468 | ASM_COMMENT_START); | |
71dfc51f | 5469 | |
f19a6894 JW |
5470 | fputc ('\n', asm_out_file); |
5471 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, | |
5472 | prev_line_label); | |
5473 | fputc ('\n', asm_out_file); | |
5474 | } | |
5475 | else | |
5476 | { | |
5477 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
5478 | if (flag_verbose_asm) | |
5479 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", | |
5480 | ASM_COMMENT_START); | |
5481 | fputc ('\n', asm_out_file); | |
5482 | output_uleb128 (1 + PTR_SIZE); | |
5483 | fputc ('\n', asm_out_file); | |
5484 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5485 | fputc ('\n', asm_out_file); | |
5486 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
5487 | fputc ('\n', asm_out_file); | |
5488 | } | |
e90b62db | 5489 | } |
f19a6894 | 5490 | strcpy (prev_line_label, line_label); |
71dfc51f | 5491 | |
f19a6894 JW |
5492 | /* Emit debug info for the source file of the current line, if |
5493 | different from the previous line. */ | |
e90b62db JM |
5494 | if (line_info->dw_file_num != current_file) |
5495 | { | |
5496 | current_file = line_info->dw_file_num; | |
5497 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file); | |
5498 | if (flag_verbose_asm) | |
71dfc51f RK |
5499 | fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START); |
5500 | ||
e90b62db JM |
5501 | fputc ('\n', asm_out_file); |
5502 | output_uleb128 (current_file); | |
5503 | if (flag_verbose_asm) | |
b2932ae5 | 5504 | fprintf (asm_out_file, " (\"%s\")", file_table[current_file]); |
71dfc51f | 5505 | |
e90b62db JM |
5506 | fputc ('\n', asm_out_file); |
5507 | } | |
71dfc51f | 5508 | |
f19a6894 JW |
5509 | /* Emit debug info for the current line number, choosing the encoding |
5510 | that uses the least amount of space. */ | |
e90b62db JM |
5511 | if (line_info->dw_line_num != current_line) |
5512 | { | |
5513 | line_offset = line_info->dw_line_num - current_line; | |
5514 | line_delta = line_offset - DWARF_LINE_BASE; | |
5515 | current_line = line_info->dw_line_num; | |
5516 | if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) | |
5517 | { | |
5518 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, | |
5519 | DWARF_LINE_OPCODE_BASE + line_delta); | |
5520 | if (flag_verbose_asm) | |
71dfc51f RK |
5521 | fprintf (asm_out_file, |
5522 | "\t%s line %d", ASM_COMMENT_START, current_line); | |
5523 | ||
e90b62db JM |
5524 | fputc ('\n', asm_out_file); |
5525 | } | |
5526 | else | |
5527 | { | |
5528 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line); | |
5529 | if (flag_verbose_asm) | |
71dfc51f RK |
5530 | fprintf (asm_out_file, "\t%s advance to line %d", |
5531 | ASM_COMMENT_START, current_line); | |
5532 | ||
e90b62db JM |
5533 | fputc ('\n', asm_out_file); |
5534 | output_sleb128 (line_offset); | |
5535 | fputc ('\n', asm_out_file); | |
5536 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy); | |
5537 | fputc ('\n', asm_out_file); | |
5538 | } | |
5539 | } | |
71dfc51f | 5540 | |
e90b62db | 5541 | ++lt_index; |
e90b62db JM |
5542 | |
5543 | /* If we're done with a function, end its sequence. */ | |
5544 | if (lt_index == separate_line_info_table_in_use | |
5545 | || separate_line_info_table[lt_index].function != function) | |
5546 | { | |
5547 | current_file = 1; | |
5548 | current_line = 1; | |
71dfc51f | 5549 | |
f19a6894 | 5550 | /* Emit debug info for the address of the end of the function. */ |
5c90448c | 5551 | ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function); |
f19a6894 JW |
5552 | if (0) |
5553 | { | |
5554 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc); | |
5555 | if (flag_verbose_asm) | |
5556 | fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc", | |
5557 | ASM_COMMENT_START); | |
5558 | ||
5559 | fputc ('\n', asm_out_file); | |
5560 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, | |
5561 | prev_line_label); | |
5562 | fputc ('\n', asm_out_file); | |
5563 | } | |
5564 | else | |
5565 | { | |
5566 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
5567 | if (flag_verbose_asm) | |
5568 | fprintf (asm_out_file, "\t%s DW_LNE_set_address", | |
5569 | ASM_COMMENT_START); | |
5570 | fputc ('\n', asm_out_file); | |
5571 | output_uleb128 (1 + PTR_SIZE); | |
5572 | fputc ('\n', asm_out_file); | |
5573 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address); | |
5574 | fputc ('\n', asm_out_file); | |
5575 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label); | |
5576 | fputc ('\n', asm_out_file); | |
5577 | } | |
e90b62db JM |
5578 | |
5579 | /* Output the marker for the end of this sequence. */ | |
5580 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0); | |
5581 | if (flag_verbose_asm) | |
5582 | fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", | |
5583 | ASM_COMMENT_START); | |
71dfc51f | 5584 | |
e90b62db JM |
5585 | fputc ('\n', asm_out_file); |
5586 | output_uleb128 (1); | |
5587 | fputc ('\n', asm_out_file); | |
5588 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence); | |
5589 | fputc ('\n', asm_out_file); | |
5590 | } | |
5591 | } | |
a3f97cbb JW |
5592 | } |
5593 | \f | |
71dfc51f RK |
5594 | /* Given a pointer to a BLOCK node return non-zero if (and only if) the node |
5595 | in question represents the outermost pair of curly braces (i.e. the "body | |
5596 | block") of a function or method. | |
5597 | ||
5598 | For any BLOCK node representing a "body block" of a function or method, the | |
5599 | BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which | |
5600 | represents the outermost (function) scope for the function or method (i.e. | |
5601 | the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of | |
5602 | *that* node in turn will point to the relevant FUNCTION_DECL node. */ | |
5603 | ||
5604 | static inline int | |
a3f97cbb JW |
5605 | is_body_block (stmt) |
5606 | register tree stmt; | |
5607 | { | |
5608 | if (TREE_CODE (stmt) == BLOCK) | |
5609 | { | |
5610 | register tree parent = BLOCK_SUPERCONTEXT (stmt); | |
5611 | ||
5612 | if (TREE_CODE (parent) == BLOCK) | |
5613 | { | |
5614 | register tree grandparent = BLOCK_SUPERCONTEXT (parent); | |
5615 | ||
5616 | if (TREE_CODE (grandparent) == FUNCTION_DECL) | |
5617 | return 1; | |
5618 | } | |
5619 | } | |
71dfc51f | 5620 | |
a3f97cbb JW |
5621 | return 0; |
5622 | } | |
5623 | ||
a3f97cbb JW |
5624 | /* Given a pointer to a tree node for some base type, return a pointer to |
5625 | a DIE that describes the given type. | |
5626 | ||
5627 | This routine must only be called for GCC type nodes that correspond to | |
5628 | Dwarf base (fundamental) types. */ | |
71dfc51f | 5629 | |
a3f97cbb JW |
5630 | static dw_die_ref |
5631 | base_type_die (type) | |
5632 | register tree type; | |
5633 | { | |
a9d38797 JM |
5634 | register dw_die_ref base_type_result; |
5635 | register char *type_name; | |
5636 | register enum dwarf_type encoding; | |
71dfc51f | 5637 | register tree name = TYPE_NAME (type); |
a3f97cbb | 5638 | |
a9d38797 JM |
5639 | if (TREE_CODE (type) == ERROR_MARK |
5640 | || TREE_CODE (type) == VOID_TYPE) | |
a3f97cbb JW |
5641 | return 0; |
5642 | ||
71dfc51f RK |
5643 | if (TREE_CODE (name) == TYPE_DECL) |
5644 | name = DECL_NAME (name); | |
5645 | type_name = IDENTIFIER_POINTER (name); | |
a9d38797 | 5646 | |
a3f97cbb JW |
5647 | switch (TREE_CODE (type)) |
5648 | { | |
a3f97cbb | 5649 | case INTEGER_TYPE: |
a9d38797 | 5650 | /* Carefully distinguish the C character types, without messing |
a3f97cbb JW |
5651 | up if the language is not C. Note that we check only for the names |
5652 | that contain spaces; other names might occur by coincidence in other | |
5653 | languages. */ | |
a9d38797 JM |
5654 | if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE |
5655 | && (type == char_type_node | |
5656 | || ! strcmp (type_name, "signed char") | |
5657 | || ! strcmp (type_name, "unsigned char")))) | |
a3f97cbb | 5658 | { |
a9d38797 JM |
5659 | if (TREE_UNSIGNED (type)) |
5660 | encoding = DW_ATE_unsigned; | |
5661 | else | |
5662 | encoding = DW_ATE_signed; | |
5663 | break; | |
a3f97cbb | 5664 | } |
a9d38797 | 5665 | /* else fall through */ |
a3f97cbb | 5666 | |
a9d38797 JM |
5667 | case CHAR_TYPE: |
5668 | /* GNU Pascal/Ada CHAR type. Not used in C. */ | |
5669 | if (TREE_UNSIGNED (type)) | |
5670 | encoding = DW_ATE_unsigned_char; | |
5671 | else | |
5672 | encoding = DW_ATE_signed_char; | |
a3f97cbb JW |
5673 | break; |
5674 | ||
5675 | case REAL_TYPE: | |
a9d38797 | 5676 | encoding = DW_ATE_float; |
a3f97cbb JW |
5677 | break; |
5678 | ||
5679 | case COMPLEX_TYPE: | |
a9d38797 | 5680 | encoding = DW_ATE_complex_float; |
a3f97cbb JW |
5681 | break; |
5682 | ||
5683 | case BOOLEAN_TYPE: | |
a9d38797 JM |
5684 | /* GNU FORTRAN/Ada/C++ BOOLEAN type. */ |
5685 | encoding = DW_ATE_boolean; | |
a3f97cbb JW |
5686 | break; |
5687 | ||
5688 | default: | |
a9d38797 | 5689 | abort (); /* No other TREE_CODEs are Dwarf fundamental types. */ |
a3f97cbb JW |
5690 | } |
5691 | ||
a9d38797 JM |
5692 | base_type_result = new_die (DW_TAG_base_type, comp_unit_die); |
5693 | add_AT_string (base_type_result, DW_AT_name, type_name); | |
5694 | add_AT_unsigned (base_type_result, DW_AT_byte_size, | |
5695 | TYPE_PRECISION (type) / BITS_PER_UNIT); | |
5696 | add_AT_unsigned (base_type_result, DW_AT_encoding, encoding); | |
a3f97cbb JW |
5697 | |
5698 | return base_type_result; | |
5699 | } | |
5700 | ||
5701 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to | |
5702 | the Dwarf "root" type for the given input type. The Dwarf "root" type of | |
5703 | a given type is generally the same as the given type, except that if the | |
5704 | given type is a pointer or reference type, then the root type of the given | |
5705 | type is the root type of the "basis" type for the pointer or reference | |
5706 | type. (This definition of the "root" type is recursive.) Also, the root | |
5707 | type of a `const' qualified type or a `volatile' qualified type is the | |
5708 | root type of the given type without the qualifiers. */ | |
71dfc51f | 5709 | |
a3f97cbb JW |
5710 | static tree |
5711 | root_type (type) | |
5712 | register tree type; | |
5713 | { | |
5714 | if (TREE_CODE (type) == ERROR_MARK) | |
5715 | return error_mark_node; | |
5716 | ||
5717 | switch (TREE_CODE (type)) | |
5718 | { | |
5719 | case ERROR_MARK: | |
5720 | return error_mark_node; | |
5721 | ||
5722 | case POINTER_TYPE: | |
5723 | case REFERENCE_TYPE: | |
5724 | return type_main_variant (root_type (TREE_TYPE (type))); | |
5725 | ||
5726 | default: | |
5727 | return type_main_variant (type); | |
5728 | } | |
5729 | } | |
5730 | ||
5731 | /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the | |
5732 | given input type is a Dwarf "fundamental" type. Otherwise return null. */ | |
71dfc51f RK |
5733 | |
5734 | static inline int | |
a3f97cbb JW |
5735 | is_base_type (type) |
5736 | register tree type; | |
5737 | { | |
5738 | switch (TREE_CODE (type)) | |
5739 | { | |
5740 | case ERROR_MARK: | |
5741 | case VOID_TYPE: | |
5742 | case INTEGER_TYPE: | |
5743 | case REAL_TYPE: | |
5744 | case COMPLEX_TYPE: | |
5745 | case BOOLEAN_TYPE: | |
5746 | case CHAR_TYPE: | |
5747 | return 1; | |
5748 | ||
5749 | case SET_TYPE: | |
5750 | case ARRAY_TYPE: | |
5751 | case RECORD_TYPE: | |
5752 | case UNION_TYPE: | |
5753 | case QUAL_UNION_TYPE: | |
5754 | case ENUMERAL_TYPE: | |
5755 | case FUNCTION_TYPE: | |
5756 | case METHOD_TYPE: | |
5757 | case POINTER_TYPE: | |
5758 | case REFERENCE_TYPE: | |
5759 | case FILE_TYPE: | |
5760 | case OFFSET_TYPE: | |
5761 | case LANG_TYPE: | |
5762 | return 0; | |
5763 | ||
5764 | default: | |
5765 | abort (); | |
5766 | } | |
71dfc51f | 5767 | |
a3f97cbb JW |
5768 | return 0; |
5769 | } | |
5770 | ||
5771 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging | |
5772 | entry that chains various modifiers in front of the given type. */ | |
71dfc51f | 5773 | |
a3f97cbb JW |
5774 | static dw_die_ref |
5775 | modified_type_die (type, is_const_type, is_volatile_type, context_die) | |
5776 | register tree type; | |
5777 | register int is_const_type; | |
5778 | register int is_volatile_type; | |
5779 | register dw_die_ref context_die; | |
5780 | { | |
5781 | register enum tree_code code = TREE_CODE (type); | |
5782 | register dw_die_ref mod_type_die = NULL; | |
5783 | register dw_die_ref sub_die = NULL; | |
dfcf9891 | 5784 | register tree item_type = NULL; |
a3f97cbb JW |
5785 | |
5786 | if (code != ERROR_MARK) | |
5787 | { | |
a94dbf2c | 5788 | type = build_type_variant (type, is_const_type, is_volatile_type); |
bdb669cb JM |
5789 | |
5790 | mod_type_die = lookup_type_die (type); | |
5791 | if (mod_type_die) | |
5792 | return mod_type_die; | |
5793 | ||
a94dbf2c JM |
5794 | /* Handle C typedef types. */ |
5795 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
5796 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
5797 | { | |
5798 | tree dtype = TREE_TYPE (TYPE_NAME (type)); | |
5799 | if (type == dtype) | |
5800 | { | |
5801 | /* For a named type, use the typedef. */ | |
5802 | gen_type_die (type, context_die); | |
5803 | mod_type_die = lookup_type_die (type); | |
5804 | } | |
71dfc51f | 5805 | |
a94dbf2c JM |
5806 | else if (is_const_type < TYPE_READONLY (dtype) |
5807 | || is_volatile_type < TYPE_VOLATILE (dtype)) | |
5808 | /* cv-unqualified version of named type. Just use the unnamed | |
5809 | type to which it refers. */ | |
71dfc51f RK |
5810 | mod_type_die |
5811 | = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), | |
5812 | is_const_type, is_volatile_type, | |
5813 | context_die); | |
5814 | /* Else cv-qualified version of named type; fall through. */ | |
a94dbf2c JM |
5815 | } |
5816 | ||
5817 | if (mod_type_die) | |
5818 | /* OK */; | |
5819 | else if (is_const_type) | |
a3f97cbb | 5820 | { |
ab72d377 | 5821 | mod_type_die = new_die (DW_TAG_const_type, comp_unit_die); |
a9d38797 | 5822 | sub_die = modified_type_die (type, 0, is_volatile_type, context_die); |
a3f97cbb JW |
5823 | } |
5824 | else if (is_volatile_type) | |
5825 | { | |
ab72d377 | 5826 | mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die); |
a9d38797 | 5827 | sub_die = modified_type_die (type, 0, 0, context_die); |
a3f97cbb JW |
5828 | } |
5829 | else if (code == POINTER_TYPE) | |
5830 | { | |
ab72d377 | 5831 | mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die); |
a3f97cbb | 5832 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 5833 | #if 0 |
a3f97cbb | 5834 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
61b32c02 | 5835 | #endif |
a3f97cbb | 5836 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
5837 | } |
5838 | else if (code == REFERENCE_TYPE) | |
5839 | { | |
ab72d377 | 5840 | mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die); |
a3f97cbb | 5841 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
61b32c02 | 5842 | #if 0 |
a3f97cbb | 5843 | add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); |
61b32c02 | 5844 | #endif |
a3f97cbb | 5845 | item_type = TREE_TYPE (type); |
a3f97cbb JW |
5846 | } |
5847 | else if (is_base_type (type)) | |
71dfc51f | 5848 | mod_type_die = base_type_die (type); |
a3f97cbb JW |
5849 | else |
5850 | { | |
4b674448 JM |
5851 | gen_type_die (type, context_die); |
5852 | ||
a3f97cbb JW |
5853 | /* We have to get the type_main_variant here (and pass that to the |
5854 | `lookup_type_die' routine) because the ..._TYPE node we have | |
5855 | might simply be a *copy* of some original type node (where the | |
5856 | copy was created to help us keep track of typedef names) and | |
5857 | that copy might have a different TYPE_UID from the original | |
a94dbf2c | 5858 | ..._TYPE node. */ |
a3f97cbb | 5859 | mod_type_die = lookup_type_die (type_main_variant (type)); |
a94dbf2c | 5860 | assert (mod_type_die != NULL); |
a3f97cbb JW |
5861 | } |
5862 | } | |
71dfc51f | 5863 | |
dfcf9891 JW |
5864 | equate_type_number_to_die (type, mod_type_die); |
5865 | if (item_type) | |
71dfc51f RK |
5866 | /* We must do this after the equate_type_number_to_die call, in case |
5867 | this is a recursive type. This ensures that the modified_type_die | |
5868 | recursion will terminate even if the type is recursive. Recursive | |
5869 | types are possible in Ada. */ | |
5870 | sub_die = modified_type_die (item_type, | |
5871 | TYPE_READONLY (item_type), | |
5872 | TYPE_VOLATILE (item_type), | |
5873 | context_die); | |
5874 | ||
a3f97cbb | 5875 | if (sub_die != NULL) |
71dfc51f RK |
5876 | add_AT_die_ref (mod_type_die, DW_AT_type, sub_die); |
5877 | ||
a3f97cbb JW |
5878 | return mod_type_die; |
5879 | } | |
5880 | ||
a3f97cbb JW |
5881 | /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is |
5882 | an enumerated type. */ | |
71dfc51f RK |
5883 | |
5884 | static inline int | |
a3f97cbb JW |
5885 | type_is_enum (type) |
5886 | register tree type; | |
5887 | { | |
5888 | return TREE_CODE (type) == ENUMERAL_TYPE; | |
5889 | } | |
5890 | ||
a3f97cbb | 5891 | /* Return a location descriptor that designates a machine register. */ |
71dfc51f | 5892 | |
a3f97cbb JW |
5893 | static dw_loc_descr_ref |
5894 | reg_loc_descriptor (rtl) | |
5895 | register rtx rtl; | |
5896 | { | |
5897 | register dw_loc_descr_ref loc_result = NULL; | |
5898 | register unsigned reg = reg_number (rtl); | |
71dfc51f | 5899 | |
a3f97cbb | 5900 | if (reg >= 0 && reg <= 31) |
71dfc51f | 5901 | loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0); |
a3f97cbb | 5902 | else |
71dfc51f RK |
5903 | loc_result = new_loc_descr (DW_OP_regx, reg, 0); |
5904 | ||
a3f97cbb JW |
5905 | return loc_result; |
5906 | } | |
5907 | ||
5908 | /* Return a location descriptor that designates a base+offset location. */ | |
71dfc51f | 5909 | |
a3f97cbb JW |
5910 | static dw_loc_descr_ref |
5911 | based_loc_descr (reg, offset) | |
5912 | unsigned reg; | |
5913 | long int offset; | |
5914 | { | |
5915 | register dw_loc_descr_ref loc_result; | |
810429b7 JM |
5916 | /* For the "frame base", we use the frame pointer or stack pointer |
5917 | registers, since the RTL for local variables is relative to one of | |
5918 | them. */ | |
5919 | register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed | |
b1ccbc24 | 5920 | ? HARD_FRAME_POINTER_REGNUM |
810429b7 | 5921 | : STACK_POINTER_REGNUM); |
71dfc51f | 5922 | |
a3f97cbb | 5923 | if (reg == fp_reg) |
71dfc51f | 5924 | loc_result = new_loc_descr (DW_OP_fbreg, offset, 0); |
a3f97cbb | 5925 | else if (reg >= 0 && reg <= 31) |
71dfc51f | 5926 | loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0); |
a3f97cbb | 5927 | else |
71dfc51f RK |
5928 | loc_result = new_loc_descr (DW_OP_bregx, reg, offset); |
5929 | ||
a3f97cbb JW |
5930 | return loc_result; |
5931 | } | |
5932 | ||
5933 | /* Return true if this RTL expression describes a base+offset calculation. */ | |
71dfc51f RK |
5934 | |
5935 | static inline int | |
a3f97cbb JW |
5936 | is_based_loc (rtl) |
5937 | register rtx rtl; | |
5938 | { | |
71dfc51f RK |
5939 | return (GET_CODE (rtl) == PLUS |
5940 | && ((GET_CODE (XEXP (rtl, 0)) == REG | |
5941 | && GET_CODE (XEXP (rtl, 1)) == CONST_INT))); | |
a3f97cbb JW |
5942 | } |
5943 | ||
5944 | /* The following routine converts the RTL for a variable or parameter | |
5945 | (resident in memory) into an equivalent Dwarf representation of a | |
5946 | mechanism for getting the address of that same variable onto the top of a | |
5947 | hypothetical "address evaluation" stack. | |
71dfc51f | 5948 | |
a3f97cbb JW |
5949 | When creating memory location descriptors, we are effectively transforming |
5950 | the RTL for a memory-resident object into its Dwarf postfix expression | |
5951 | equivalent. This routine recursively descends an RTL tree, turning | |
5952 | it into Dwarf postfix code as it goes. */ | |
71dfc51f | 5953 | |
a3f97cbb JW |
5954 | static dw_loc_descr_ref |
5955 | mem_loc_descriptor (rtl) | |
5956 | register rtx rtl; | |
5957 | { | |
5958 | dw_loc_descr_ref mem_loc_result = NULL; | |
5959 | /* Note that for a dynamically sized array, the location we will generate a | |
5960 | description of here will be the lowest numbered location which is | |
5961 | actually within the array. That's *not* necessarily the same as the | |
5962 | zeroth element of the array. */ | |
71dfc51f | 5963 | |
a3f97cbb JW |
5964 | switch (GET_CODE (rtl)) |
5965 | { | |
5966 | case SUBREG: | |
5967 | /* The case of a subreg may arise when we have a local (register) | |
5968 | variable or a formal (register) parameter which doesn't quite fill | |
5969 | up an entire register. For now, just assume that it is | |
5970 | legitimate to make the Dwarf info refer to the whole register which | |
5971 | contains the given subreg. */ | |
5972 | rtl = XEXP (rtl, 0); | |
71dfc51f RK |
5973 | |
5974 | /* ... fall through ... */ | |
a3f97cbb JW |
5975 | |
5976 | case REG: | |
5977 | /* Whenever a register number forms a part of the description of the | |
5978 | method for calculating the (dynamic) address of a memory resident | |
5979 | object, DWARF rules require the register number be referred to as | |
5980 | a "base register". This distinction is not based in any way upon | |
5981 | what category of register the hardware believes the given register | |
5982 | belongs to. This is strictly DWARF terminology we're dealing with | |
5983 | here. Note that in cases where the location of a memory-resident | |
5984 | data object could be expressed as: OP_ADD (OP_BASEREG (basereg), | |
5985 | OP_CONST (0)) the actual DWARF location descriptor that we generate | |
5986 | may just be OP_BASEREG (basereg). This may look deceptively like | |
5987 | the object in question was allocated to a register (rather than in | |
5988 | memory) so DWARF consumers need to be aware of the subtle | |
5989 | distinction between OP_REG and OP_BASEREG. */ | |
5990 | mem_loc_result = based_loc_descr (reg_number (rtl), 0); | |
5991 | break; | |
5992 | ||
5993 | case MEM: | |
5994 | mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0)); | |
5995 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0)); | |
5996 | break; | |
5997 | ||
5998 | case CONST: | |
5999 | case SYMBOL_REF: | |
6000 | mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0); | |
6001 | mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr; | |
6002 | mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl); | |
6003 | break; | |
6004 | ||
6005 | case PLUS: | |
6006 | if (is_based_loc (rtl)) | |
71dfc51f RK |
6007 | mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)), |
6008 | INTVAL (XEXP (rtl, 1))); | |
a3f97cbb JW |
6009 | else |
6010 | { | |
6011 | add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0))); | |
6012 | add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1))); | |
6013 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0)); | |
6014 | } | |
6015 | break; | |
6016 | ||
dd2478ae JW |
6017 | case MULT: |
6018 | /* If a pseudo-reg is optimized away, it is possible for it to | |
6019 | be replaced with a MEM containing a multiply. */ | |
6020 | add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0))); | |
6021 | add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1))); | |
6022 | add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0)); | |
6023 | break; | |
6024 | ||
a3f97cbb JW |
6025 | case CONST_INT: |
6026 | mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0); | |
6027 | break; | |
6028 | ||
6029 | default: | |
6030 | abort (); | |
6031 | } | |
71dfc51f | 6032 | |
a3f97cbb JW |
6033 | return mem_loc_result; |
6034 | } | |
6035 | ||
6036 | /* Output a proper Dwarf location descriptor for a variable or parameter | |
6037 | which is either allocated in a register or in a memory location. For a | |
6038 | register, we just generate an OP_REG and the register number. For a | |
6039 | memory location we provide a Dwarf postfix expression describing how to | |
6040 | generate the (dynamic) address of the object onto the address stack. */ | |
71dfc51f | 6041 | |
a3f97cbb JW |
6042 | static dw_loc_descr_ref |
6043 | loc_descriptor (rtl) | |
6044 | register rtx rtl; | |
6045 | { | |
6046 | dw_loc_descr_ref loc_result = NULL; | |
6047 | switch (GET_CODE (rtl)) | |
6048 | { | |
6049 | case SUBREG: | |
a3f97cbb JW |
6050 | /* The case of a subreg may arise when we have a local (register) |
6051 | variable or a formal (register) parameter which doesn't quite fill | |
71dfc51f | 6052 | up an entire register. For now, just assume that it is |
a3f97cbb JW |
6053 | legitimate to make the Dwarf info refer to the whole register which |
6054 | contains the given subreg. */ | |
a3f97cbb | 6055 | rtl = XEXP (rtl, 0); |
71dfc51f RK |
6056 | |
6057 | /* ... fall through ... */ | |
a3f97cbb JW |
6058 | |
6059 | case REG: | |
5c90448c | 6060 | loc_result = reg_loc_descriptor (rtl); |
a3f97cbb JW |
6061 | break; |
6062 | ||
6063 | case MEM: | |
6064 | loc_result = mem_loc_descriptor (XEXP (rtl, 0)); | |
6065 | break; | |
6066 | ||
6067 | default: | |
71dfc51f | 6068 | abort (); |
a3f97cbb | 6069 | } |
71dfc51f | 6070 | |
a3f97cbb JW |
6071 | return loc_result; |
6072 | } | |
6073 | ||
6074 | /* Given an unsigned value, round it up to the lowest multiple of `boundary' | |
6075 | which is not less than the value itself. */ | |
71dfc51f RK |
6076 | |
6077 | static inline unsigned | |
a3f97cbb JW |
6078 | ceiling (value, boundary) |
6079 | register unsigned value; | |
6080 | register unsigned boundary; | |
6081 | { | |
6082 | return (((value + boundary - 1) / boundary) * boundary); | |
6083 | } | |
6084 | ||
6085 | /* Given a pointer to what is assumed to be a FIELD_DECL node, return a | |
6086 | pointer to the declared type for the relevant field variable, or return | |
6087 | `integer_type_node' if the given node turns out to be an | |
6088 | ERROR_MARK node. */ | |
71dfc51f RK |
6089 | |
6090 | static inline tree | |
a3f97cbb JW |
6091 | field_type (decl) |
6092 | register tree decl; | |
6093 | { | |
6094 | register tree type; | |
6095 | ||
6096 | if (TREE_CODE (decl) == ERROR_MARK) | |
6097 | return integer_type_node; | |
6098 | ||
6099 | type = DECL_BIT_FIELD_TYPE (decl); | |
71dfc51f | 6100 | if (type == NULL_TREE) |
a3f97cbb JW |
6101 | type = TREE_TYPE (decl); |
6102 | ||
6103 | return type; | |
6104 | } | |
6105 | ||
6106 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE | |
6107 | node, return the alignment in bits for the type, or else return | |
6108 | BITS_PER_WORD if the node actually turns out to be an | |
6109 | ERROR_MARK node. */ | |
71dfc51f RK |
6110 | |
6111 | static inline unsigned | |
a3f97cbb JW |
6112 | simple_type_align_in_bits (type) |
6113 | register tree type; | |
6114 | { | |
6115 | return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; | |
6116 | } | |
6117 | ||
6118 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE | |
6119 | node, return the size in bits for the type if it is a constant, or else | |
6120 | return the alignment for the type if the type's size is not constant, or | |
6121 | else return BITS_PER_WORD if the type actually turns out to be an | |
6122 | ERROR_MARK node. */ | |
71dfc51f RK |
6123 | |
6124 | static inline unsigned | |
a3f97cbb JW |
6125 | simple_type_size_in_bits (type) |
6126 | register tree type; | |
6127 | { | |
6128 | if (TREE_CODE (type) == ERROR_MARK) | |
6129 | return BITS_PER_WORD; | |
6130 | else | |
6131 | { | |
6132 | register tree type_size_tree = TYPE_SIZE (type); | |
6133 | ||
6134 | if (TREE_CODE (type_size_tree) != INTEGER_CST) | |
6135 | return TYPE_ALIGN (type); | |
6136 | ||
6137 | return (unsigned) TREE_INT_CST_LOW (type_size_tree); | |
6138 | } | |
6139 | } | |
6140 | ||
6141 | /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and | |
6142 | return the byte offset of the lowest addressed byte of the "containing | |
6143 | object" for the given FIELD_DECL, or return 0 if we are unable to | |
6144 | determine what that offset is, either because the argument turns out to | |
6145 | be a pointer to an ERROR_MARK node, or because the offset is actually | |
6146 | variable. (We can't handle the latter case just yet). */ | |
71dfc51f | 6147 | |
a3f97cbb JW |
6148 | static unsigned |
6149 | field_byte_offset (decl) | |
6150 | register tree decl; | |
6151 | { | |
6152 | register unsigned type_align_in_bytes; | |
6153 | register unsigned type_align_in_bits; | |
6154 | register unsigned type_size_in_bits; | |
6155 | register unsigned object_offset_in_align_units; | |
6156 | register unsigned object_offset_in_bits; | |
6157 | register unsigned object_offset_in_bytes; | |
6158 | register tree type; | |
6159 | register tree bitpos_tree; | |
6160 | register tree field_size_tree; | |
6161 | register unsigned bitpos_int; | |
6162 | register unsigned deepest_bitpos; | |
6163 | register unsigned field_size_in_bits; | |
6164 | ||
6165 | if (TREE_CODE (decl) == ERROR_MARK) | |
6166 | return 0; | |
6167 | ||
6168 | if (TREE_CODE (decl) != FIELD_DECL) | |
6169 | abort (); | |
6170 | ||
6171 | type = field_type (decl); | |
6172 | ||
6173 | bitpos_tree = DECL_FIELD_BITPOS (decl); | |
6174 | field_size_tree = DECL_SIZE (decl); | |
6175 | ||
6176 | /* We cannot yet cope with fields whose positions or sizes are variable, so | |
6177 | for now, when we see such things, we simply return 0. Someday, we may | |
6178 | be able to handle such cases, but it will be damn difficult. */ | |
6179 | if (TREE_CODE (bitpos_tree) != INTEGER_CST) | |
6180 | return 0; | |
6181 | bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree); | |
6182 | ||
6183 | if (TREE_CODE (field_size_tree) != INTEGER_CST) | |
6184 | return 0; | |
a3f97cbb | 6185 | |
71dfc51f | 6186 | field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree); |
a3f97cbb | 6187 | type_size_in_bits = simple_type_size_in_bits (type); |
a3f97cbb JW |
6188 | type_align_in_bits = simple_type_align_in_bits (type); |
6189 | type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT; | |
6190 | ||
6191 | /* Note that the GCC front-end doesn't make any attempt to keep track of | |
6192 | the starting bit offset (relative to the start of the containing | |
6193 | structure type) of the hypothetical "containing object" for a bit- | |
6194 | field. Thus, when computing the byte offset value for the start of the | |
6195 | "containing object" of a bit-field, we must deduce this information on | |
6196 | our own. This can be rather tricky to do in some cases. For example, | |
6197 | handling the following structure type definition when compiling for an | |
6198 | i386/i486 target (which only aligns long long's to 32-bit boundaries) | |
6199 | can be very tricky: | |
6200 | ||
6201 | struct S { int field1; long long field2:31; }; | |
6202 | ||
6203 | Fortunately, there is a simple rule-of-thumb which can be | |
6204 | used in such cases. When compiling for an i386/i486, GCC will allocate | |
6205 | 8 bytes for the structure shown above. It decides to do this based upon | |
6206 | one simple rule for bit-field allocation. Quite simply, GCC allocates | |
6207 | each "containing object" for each bit-field at the first (i.e. lowest | |
6208 | addressed) legitimate alignment boundary (based upon the required | |
6209 | minimum alignment for the declared type of the field) which it can | |
6210 | possibly use, subject to the condition that there is still enough | |
6211 | available space remaining in the containing object (when allocated at | |
6212 | the selected point) to fully accommodate all of the bits of the | |
6213 | bit-field itself. This simple rule makes it obvious why GCC allocates | |
6214 | 8 bytes for each object of the structure type shown above. When looking | |
6215 | for a place to allocate the "containing object" for `field2', the | |
6216 | compiler simply tries to allocate a 64-bit "containing object" at each | |
6217 | successive 32-bit boundary (starting at zero) until it finds a place to | |
6218 | allocate that 64- bit field such that at least 31 contiguous (and | |
6219 | previously unallocated) bits remain within that selected 64 bit field. | |
6220 | (As it turns out, for the example above, the compiler finds that it is | |
6221 | OK to allocate the "containing object" 64-bit field at bit-offset zero | |
6222 | within the structure type.) Here we attempt to work backwards from the | |
6223 | limited set of facts we're given, and we try to deduce from those facts, | |
6224 | where GCC must have believed that the containing object started (within | |
6225 | the structure type). The value we deduce is then used (by the callers of | |
6226 | this routine) to generate DW_AT_location and DW_AT_bit_offset attributes | |
6227 | for fields (both bit-fields and, in the case of DW_AT_location, regular | |
6228 | fields as well). */ | |
6229 | ||
6230 | /* Figure out the bit-distance from the start of the structure to the | |
6231 | "deepest" bit of the bit-field. */ | |
6232 | deepest_bitpos = bitpos_int + field_size_in_bits; | |
6233 | ||
6234 | /* This is the tricky part. Use some fancy footwork to deduce where the | |
6235 | lowest addressed bit of the containing object must be. */ | |
6236 | object_offset_in_bits | |
6237 | = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits; | |
6238 | ||
6239 | /* Compute the offset of the containing object in "alignment units". */ | |
6240 | object_offset_in_align_units = object_offset_in_bits / type_align_in_bits; | |
6241 | ||
6242 | /* Compute the offset of the containing object in bytes. */ | |
6243 | object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes; | |
6244 | ||
6245 | return object_offset_in_bytes; | |
6246 | } | |
a3f97cbb | 6247 | \f |
71dfc51f RK |
6248 | /* The following routines define various Dwarf attributes and any data |
6249 | associated with them. */ | |
a3f97cbb | 6250 | |
ef76d03b | 6251 | /* Add a location description attribute value to a DIE. |
a3f97cbb | 6252 | |
ef76d03b | 6253 | This emits location attributes suitable for whole variables and |
a3f97cbb JW |
6254 | whole parameters. Note that the location attributes for struct fields are |
6255 | generated by the routine `data_member_location_attribute' below. */ | |
71dfc51f | 6256 | |
a3f97cbb | 6257 | static void |
ef76d03b | 6258 | add_AT_location_description (die, attr_kind, rtl) |
a3f97cbb | 6259 | dw_die_ref die; |
ef76d03b | 6260 | enum dwarf_attribute attr_kind; |
a3f97cbb JW |
6261 | register rtx rtl; |
6262 | { | |
a3f97cbb JW |
6263 | /* Handle a special case. If we are about to output a location descriptor |
6264 | for a variable or parameter which has been optimized out of existence, | |
6a7a9f01 | 6265 | don't do that. A variable which has been optimized out |
a3f97cbb JW |
6266 | of existence will have a DECL_RTL value which denotes a pseudo-reg. |
6267 | Currently, in some rare cases, variables can have DECL_RTL values which | |
6268 | look like (MEM (REG pseudo-reg#)). These cases are due to bugs | |
6269 | elsewhere in the compiler. We treat such cases as if the variable(s) in | |
6a7a9f01 | 6270 | question had been optimized out of existence. */ |
a3f97cbb | 6271 | |
6a7a9f01 JM |
6272 | if (is_pseudo_reg (rtl) |
6273 | || (GET_CODE (rtl) == MEM | |
6274 | && is_pseudo_reg (XEXP (rtl, 0)))) | |
6275 | return; | |
a3f97cbb | 6276 | |
6a7a9f01 | 6277 | add_AT_loc (die, attr_kind, loc_descriptor (rtl)); |
a3f97cbb JW |
6278 | } |
6279 | ||
6280 | /* Attach the specialized form of location attribute used for data | |
6281 | members of struct and union types. In the special case of a | |
6282 | FIELD_DECL node which represents a bit-field, the "offset" part | |
6283 | of this special location descriptor must indicate the distance | |
6284 | in bytes from the lowest-addressed byte of the containing struct | |
6285 | or union type to the lowest-addressed byte of the "containing | |
6286 | object" for the bit-field. (See the `field_byte_offset' function | |
6287 | above).. For any given bit-field, the "containing object" is a | |
6288 | hypothetical object (of some integral or enum type) within which | |
6289 | the given bit-field lives. The type of this hypothetical | |
6290 | "containing object" is always the same as the declared type of | |
6291 | the individual bit-field itself (for GCC anyway... the DWARF | |
6292 | spec doesn't actually mandate this). Note that it is the size | |
6293 | (in bytes) of the hypothetical "containing object" which will | |
6294 | be given in the DW_AT_byte_size attribute for this bit-field. | |
6295 | (See the `byte_size_attribute' function below.) It is also used | |
6296 | when calculating the value of the DW_AT_bit_offset attribute. | |
6297 | (See the `bit_offset_attribute' function below). */ | |
71dfc51f | 6298 | |
a3f97cbb JW |
6299 | static void |
6300 | add_data_member_location_attribute (die, decl) | |
6301 | register dw_die_ref die; | |
6302 | register tree decl; | |
6303 | { | |
61b32c02 | 6304 | register unsigned long offset; |
a3f97cbb JW |
6305 | register dw_loc_descr_ref loc_descr; |
6306 | register enum dwarf_location_atom op; | |
6307 | ||
61b32c02 JM |
6308 | if (TREE_CODE (decl) == TREE_VEC) |
6309 | offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl)); | |
6310 | else | |
6311 | offset = field_byte_offset (decl); | |
6312 | ||
a3f97cbb JW |
6313 | /* The DWARF2 standard says that we should assume that the structure address |
6314 | is already on the stack, so we can specify a structure field address | |
6315 | by using DW_OP_plus_uconst. */ | |
71dfc51f | 6316 | |
a3f97cbb JW |
6317 | #ifdef MIPS_DEBUGGING_INFO |
6318 | /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator | |
6319 | correctly. It works only if we leave the offset on the stack. */ | |
6320 | op = DW_OP_constu; | |
6321 | #else | |
6322 | op = DW_OP_plus_uconst; | |
6323 | #endif | |
71dfc51f | 6324 | |
a3f97cbb JW |
6325 | loc_descr = new_loc_descr (op, offset, 0); |
6326 | add_AT_loc (die, DW_AT_data_member_location, loc_descr); | |
6327 | } | |
6328 | ||
6329 | /* Attach an DW_AT_const_value attribute for a variable or a parameter which | |
6330 | does not have a "location" either in memory or in a register. These | |
6331 | things can arise in GNU C when a constant is passed as an actual parameter | |
6332 | to an inlined function. They can also arise in C++ where declared | |
6333 | constants do not necessarily get memory "homes". */ | |
71dfc51f | 6334 | |
a3f97cbb JW |
6335 | static void |
6336 | add_const_value_attribute (die, rtl) | |
6337 | register dw_die_ref die; | |
6338 | register rtx rtl; | |
6339 | { | |
6340 | switch (GET_CODE (rtl)) | |
6341 | { | |
6342 | case CONST_INT: | |
6343 | /* Note that a CONST_INT rtx could represent either an integer or a | |
6344 | floating-point constant. A CONST_INT is used whenever the constant | |
6345 | will fit into a single word. In all such cases, the original mode | |
6346 | of the constant value is wiped out, and the CONST_INT rtx is | |
6347 | assigned VOIDmode. */ | |
6348 | add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl)); | |
6349 | break; | |
6350 | ||
6351 | case CONST_DOUBLE: | |
6352 | /* Note that a CONST_DOUBLE rtx could represent either an integer or a | |
6353 | floating-point constant. A CONST_DOUBLE is used whenever the | |
6354 | constant requires more than one word in order to be adequately | |
469ac993 JM |
6355 | represented. We output CONST_DOUBLEs as blocks. */ |
6356 | { | |
6357 | register enum machine_mode mode = GET_MODE (rtl); | |
6358 | ||
6359 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
6360 | { | |
71dfc51f RK |
6361 | register unsigned length = GET_MODE_SIZE (mode) / sizeof (long); |
6362 | long array[4]; | |
6363 | REAL_VALUE_TYPE rv; | |
469ac993 | 6364 | |
71dfc51f | 6365 | REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl); |
469ac993 JM |
6366 | switch (mode) |
6367 | { | |
6368 | case SFmode: | |
71dfc51f | 6369 | REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]); |
469ac993 JM |
6370 | break; |
6371 | ||
6372 | case DFmode: | |
71dfc51f | 6373 | REAL_VALUE_TO_TARGET_DOUBLE (rv, array); |
469ac993 JM |
6374 | break; |
6375 | ||
6376 | case XFmode: | |
6377 | case TFmode: | |
71dfc51f | 6378 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array); |
469ac993 JM |
6379 | break; |
6380 | ||
6381 | default: | |
6382 | abort (); | |
6383 | } | |
6384 | ||
469ac993 JM |
6385 | add_AT_float (die, DW_AT_const_value, length, array); |
6386 | } | |
6387 | else | |
6388 | add_AT_long_long (die, DW_AT_const_value, | |
6389 | CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl)); | |
6390 | } | |
a3f97cbb JW |
6391 | break; |
6392 | ||
6393 | case CONST_STRING: | |
6394 | add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0)); | |
6395 | break; | |
6396 | ||
6397 | case SYMBOL_REF: | |
6398 | case LABEL_REF: | |
6399 | case CONST: | |
6400 | add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl)); | |
6401 | break; | |
6402 | ||
6403 | case PLUS: | |
6404 | /* In cases where an inlined instance of an inline function is passed | |
6405 | the address of an `auto' variable (which is local to the caller) we | |
6406 | can get a situation where the DECL_RTL of the artificial local | |
6407 | variable (for the inlining) which acts as a stand-in for the | |
6408 | corresponding formal parameter (of the inline function) will look | |
6409 | like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not | |
6410 | exactly a compile-time constant expression, but it isn't the address | |
6411 | of the (artificial) local variable either. Rather, it represents the | |
6412 | *value* which the artificial local variable always has during its | |
6413 | lifetime. We currently have no way to represent such quasi-constant | |
6a7a9f01 | 6414 | values in Dwarf, so for now we just punt and generate nothing. */ |
a3f97cbb JW |
6415 | break; |
6416 | ||
6417 | default: | |
6418 | /* No other kinds of rtx should be possible here. */ | |
6419 | abort (); | |
6420 | } | |
6421 | ||
6422 | } | |
6423 | ||
6424 | /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value | |
6425 | data attribute for a variable or a parameter. We generate the | |
6426 | DW_AT_const_value attribute only in those cases where the given variable | |
6427 | or parameter does not have a true "location" either in memory or in a | |
6428 | register. This can happen (for example) when a constant is passed as an | |
6429 | actual argument in a call to an inline function. (It's possible that | |
6430 | these things can crop up in other ways also.) Note that one type of | |
6431 | constant value which can be passed into an inlined function is a constant | |
6432 | pointer. This can happen for example if an actual argument in an inlined | |
6433 | function call evaluates to a compile-time constant address. */ | |
71dfc51f | 6434 | |
a3f97cbb JW |
6435 | static void |
6436 | add_location_or_const_value_attribute (die, decl) | |
6437 | register dw_die_ref die; | |
6438 | register tree decl; | |
6439 | { | |
6440 | register rtx rtl; | |
6441 | register tree declared_type; | |
6442 | register tree passed_type; | |
6443 | ||
6444 | if (TREE_CODE (decl) == ERROR_MARK) | |
71dfc51f RK |
6445 | return; |
6446 | ||
6447 | if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL) | |
6448 | abort (); | |
6449 | ||
a3f97cbb JW |
6450 | /* Here we have to decide where we are going to say the parameter "lives" |
6451 | (as far as the debugger is concerned). We only have a couple of | |
6452 | choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. | |
71dfc51f | 6453 | |
a3f97cbb | 6454 | DECL_RTL normally indicates where the parameter lives during most of the |
71dfc51f | 6455 | activation of the function. If optimization is enabled however, this |
a3f97cbb JW |
6456 | could be either NULL or else a pseudo-reg. Both of those cases indicate |
6457 | that the parameter doesn't really live anywhere (as far as the code | |
6458 | generation parts of GCC are concerned) during most of the function's | |
6459 | activation. That will happen (for example) if the parameter is never | |
71dfc51f RK |
6460 | referenced within the function. |
6461 | ||
6462 | We could just generate a location descriptor here for all non-NULL | |
6463 | non-pseudo values of DECL_RTL and ignore all of the rest, but we can be | |
6464 | a little nicer than that if we also consider DECL_INCOMING_RTL in cases | |
6465 | where DECL_RTL is NULL or is a pseudo-reg. | |
6466 | ||
6467 | Note however that we can only get away with using DECL_INCOMING_RTL as | |
6468 | a backup substitute for DECL_RTL in certain limited cases. In cases | |
6469 | where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl), | |
6470 | we can be sure that the parameter was passed using the same type as it is | |
6471 | declared to have within the function, and that its DECL_INCOMING_RTL | |
6472 | points us to a place where a value of that type is passed. | |
6473 | ||
6474 | In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different, | |
6475 | we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL | |
6476 | because in these cases DECL_INCOMING_RTL points us to a value of some | |
6477 | type which is *different* from the type of the parameter itself. Thus, | |
6478 | if we tried to use DECL_INCOMING_RTL to generate a location attribute in | |
6479 | such cases, the debugger would end up (for example) trying to fetch a | |
6480 | `float' from a place which actually contains the first part of a | |
6481 | `double'. That would lead to really incorrect and confusing | |
6482 | output at debug-time. | |
6483 | ||
6484 | So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL | |
6485 | in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There | |
6486 | are a couple of exceptions however. On little-endian machines we can | |
6487 | get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is | |
6488 | not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is | |
6489 | an integral type that is smaller than TREE_TYPE (decl). These cases arise | |
6490 | when (on a little-endian machine) a non-prototyped function has a | |
6491 | parameter declared to be of type `short' or `char'. In such cases, | |
6492 | TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will | |
6493 | be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the | |
6494 | passed `int' value. If the debugger then uses that address to fetch | |
6495 | a `short' or a `char' (on a little-endian machine) the result will be | |
6496 | the correct data, so we allow for such exceptional cases below. | |
6497 | ||
6498 | Note that our goal here is to describe the place where the given formal | |
6499 | parameter lives during most of the function's activation (i.e. between | |
6500 | the end of the prologue and the start of the epilogue). We'll do that | |
6501 | as best as we can. Note however that if the given formal parameter is | |
6502 | modified sometime during the execution of the function, then a stack | |
6503 | backtrace (at debug-time) will show the function as having been | |
6504 | called with the *new* value rather than the value which was | |
6505 | originally passed in. This happens rarely enough that it is not | |
6506 | a major problem, but it *is* a problem, and I'd like to fix it. | |
6507 | ||
6508 | A future version of dwarf2out.c may generate two additional | |
6509 | attributes for any given DW_TAG_formal_parameter DIE which will | |
6510 | describe the "passed type" and the "passed location" for the | |
6511 | given formal parameter in addition to the attributes we now | |
6512 | generate to indicate the "declared type" and the "active | |
6513 | location" for each parameter. This additional set of attributes | |
6514 | could be used by debuggers for stack backtraces. Separately, note | |
6515 | that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be | |
6516 | NULL also. This happens (for example) for inlined-instances of | |
6517 | inline function formal parameters which are never referenced. | |
6518 | This really shouldn't be happening. All PARM_DECL nodes should | |
6519 | get valid non-NULL DECL_INCOMING_RTL values, but integrate.c | |
6520 | doesn't currently generate these values for inlined instances of | |
6521 | inline function parameters, so when we see such cases, we are | |
6522 | just SOL (shit-out-of-luck) for the time being (until integrate.c | |
a3f97cbb JW |
6523 | gets fixed). */ |
6524 | ||
6525 | /* Use DECL_RTL as the "location" unless we find something better. */ | |
6526 | rtl = DECL_RTL (decl); | |
6527 | ||
6528 | if (TREE_CODE (decl) == PARM_DECL) | |
6529 | { | |
6530 | if (rtl == NULL_RTX || is_pseudo_reg (rtl)) | |
6531 | { | |
6532 | declared_type = type_main_variant (TREE_TYPE (decl)); | |
6533 | passed_type = type_main_variant (DECL_ARG_TYPE (decl)); | |
a3f97cbb | 6534 | |
71dfc51f | 6535 | /* This decl represents a formal parameter which was optimized out. |
a3f97cbb JW |
6536 | Note that DECL_INCOMING_RTL may be NULL in here, but we handle |
6537 | all* cases where (rtl == NULL_RTX) just below. */ | |
6538 | if (declared_type == passed_type) | |
71dfc51f RK |
6539 | rtl = DECL_INCOMING_RTL (decl); |
6540 | else if (! BYTES_BIG_ENDIAN | |
6541 | && TREE_CODE (declared_type) == INTEGER_TYPE | |
6542 | && TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type)) | |
6543 | rtl = DECL_INCOMING_RTL (decl); | |
a3f97cbb JW |
6544 | } |
6545 | } | |
71dfc51f | 6546 | |
61b32c02 JM |
6547 | if (rtl == NULL_RTX) |
6548 | return; | |
6549 | ||
6a7a9f01 JM |
6550 | rtl = eliminate_regs (rtl, 0, NULL_RTX, 0); |
6551 | #ifdef LEAF_REG_REMAP | |
6552 | if (leaf_function) | |
6553 | leaf_renumber_regs_insn (DECL_RTL (decl)); | |
6554 | #endif | |
6555 | ||
a3f97cbb JW |
6556 | switch (GET_CODE (rtl)) |
6557 | { | |
6558 | case CONST_INT: | |
6559 | case CONST_DOUBLE: | |
6560 | case CONST_STRING: | |
6561 | case SYMBOL_REF: | |
6562 | case LABEL_REF: | |
6563 | case CONST: | |
6564 | case PLUS: | |
6565 | /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ | |
6566 | add_const_value_attribute (die, rtl); | |
6567 | break; | |
6568 | ||
6569 | case MEM: | |
6570 | case REG: | |
6571 | case SUBREG: | |
ef76d03b | 6572 | add_AT_location_description (die, DW_AT_location, rtl); |
a3f97cbb JW |
6573 | break; |
6574 | ||
6575 | default: | |
71dfc51f | 6576 | abort (); |
a3f97cbb JW |
6577 | } |
6578 | } | |
6579 | ||
6580 | /* Generate an DW_AT_name attribute given some string value to be included as | |
6581 | the value of the attribute. */ | |
71dfc51f RK |
6582 | |
6583 | static inline void | |
a3f97cbb JW |
6584 | add_name_attribute (die, name_string) |
6585 | register dw_die_ref die; | |
6586 | register char *name_string; | |
6587 | { | |
71dfc51f RK |
6588 | if (name_string != NULL && *name_string != 0) |
6589 | add_AT_string (die, DW_AT_name, name_string); | |
a3f97cbb JW |
6590 | } |
6591 | ||
6592 | /* Given a tree node describing an array bound (either lower or upper) output | |
466446b0 | 6593 | a representation for that bound. */ |
71dfc51f | 6594 | |
a3f97cbb JW |
6595 | static void |
6596 | add_bound_info (subrange_die, bound_attr, bound) | |
6597 | register dw_die_ref subrange_die; | |
6598 | register enum dwarf_attribute bound_attr; | |
6599 | register tree bound; | |
6600 | { | |
a3f97cbb | 6601 | register unsigned bound_value = 0; |
ef76d03b JW |
6602 | |
6603 | /* If this is an Ada unconstrained array type, then don't emit any debug | |
6604 | info because the array bounds are unknown. They are parameterized when | |
6605 | the type is instantiated. */ | |
6606 | if (contains_placeholder_p (bound)) | |
6607 | return; | |
6608 | ||
a3f97cbb JW |
6609 | switch (TREE_CODE (bound)) |
6610 | { | |
6611 | case ERROR_MARK: | |
6612 | return; | |
6613 | ||
6614 | /* All fixed-bounds are represented by INTEGER_CST nodes. */ | |
6615 | case INTEGER_CST: | |
6616 | bound_value = TREE_INT_CST_LOW (bound); | |
141719a8 JM |
6617 | if (bound_attr == DW_AT_lower_bound |
6618 | && ((is_c_family () && bound_value == 0) | |
6619 | || (is_fortran () && bound_value == 1))) | |
6620 | /* use the default */; | |
6621 | else | |
6622 | add_AT_unsigned (subrange_die, bound_attr, bound_value); | |
a3f97cbb JW |
6623 | break; |
6624 | ||
b1ccbc24 | 6625 | case CONVERT_EXPR: |
a3f97cbb | 6626 | case NOP_EXPR: |
b1ccbc24 RK |
6627 | case NON_LVALUE_EXPR: |
6628 | add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0)); | |
6629 | break; | |
6630 | ||
a3f97cbb JW |
6631 | case SAVE_EXPR: |
6632 | /* If optimization is turned on, the SAVE_EXPRs that describe how to | |
466446b0 JM |
6633 | access the upper bound values may be bogus. If they refer to a |
6634 | register, they may only describe how to get at these values at the | |
6635 | points in the generated code right after they have just been | |
6636 | computed. Worse yet, in the typical case, the upper bound values | |
6637 | will not even *be* computed in the optimized code (though the | |
6638 | number of elements will), so these SAVE_EXPRs are entirely | |
6639 | bogus. In order to compensate for this fact, we check here to see | |
6640 | if optimization is enabled, and if so, we don't add an attribute | |
6641 | for the (unknown and unknowable) upper bound. This should not | |
6642 | cause too much trouble for existing (stupid?) debuggers because | |
6643 | they have to deal with empty upper bounds location descriptions | |
6644 | anyway in order to be able to deal with incomplete array types. | |
6645 | Of course an intelligent debugger (GDB?) should be able to | |
6646 | comprehend that a missing upper bound specification in a array | |
6647 | type used for a storage class `auto' local array variable | |
6648 | indicates that the upper bound is both unknown (at compile- time) | |
6649 | and unknowable (at run-time) due to optimization. | |
6650 | ||
6651 | We assume that a MEM rtx is safe because gcc wouldn't put the | |
6652 | value there unless it was going to be used repeatedly in the | |
6653 | function, i.e. for cleanups. */ | |
6654 | if (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM) | |
a3f97cbb | 6655 | { |
466446b0 JM |
6656 | register dw_die_ref ctx = lookup_decl_die (current_function_decl); |
6657 | register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx); | |
6658 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
6659 | add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); | |
ef76d03b JW |
6660 | add_AT_location_description (decl_die, DW_AT_location, |
6661 | SAVE_EXPR_RTL (bound)); | |
466446b0 | 6662 | add_AT_die_ref (subrange_die, bound_attr, decl_die); |
a3f97cbb | 6663 | } |
71dfc51f RK |
6664 | |
6665 | /* Else leave out the attribute. */ | |
a3f97cbb | 6666 | break; |
3f76745e | 6667 | |
ef76d03b JW |
6668 | case MAX_EXPR: |
6669 | case VAR_DECL: | |
6670 | /* ??? These types of bounds can be created by the Ada front end, | |
6671 | and it isn't clear how to emit debug info for them. */ | |
6672 | break; | |
6673 | ||
3f76745e JM |
6674 | default: |
6675 | abort (); | |
a3f97cbb JW |
6676 | } |
6677 | } | |
6678 | ||
6679 | /* Note that the block of subscript information for an array type also | |
6680 | includes information about the element type of type given array type. */ | |
71dfc51f | 6681 | |
a3f97cbb JW |
6682 | static void |
6683 | add_subscript_info (type_die, type) | |
6684 | register dw_die_ref type_die; | |
6685 | register tree type; | |
6686 | { | |
6687 | register unsigned dimension_number; | |
6688 | register tree lower, upper; | |
6689 | register dw_die_ref subrange_die; | |
6690 | ||
6691 | /* The GNU compilers represent multidimensional array types as sequences of | |
6692 | one dimensional array types whose element types are themselves array | |
6693 | types. Here we squish that down, so that each multidimensional array | |
6694 | type gets only one array_type DIE in the Dwarf debugging info. The draft | |
6695 | Dwarf specification say that we are allowed to do this kind of | |
6696 | compression in C (because there is no difference between an array or | |
6697 | arrays and a multidimensional array in C) but for other source languages | |
6698 | (e.g. Ada) we probably shouldn't do this. */ | |
71dfc51f | 6699 | |
a3f97cbb JW |
6700 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
6701 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
6702 | We work around this by disabling this feature. See also | |
6703 | gen_array_type_die. */ | |
6704 | #ifndef MIPS_DEBUGGING_INFO | |
6705 | for (dimension_number = 0; | |
6706 | TREE_CODE (type) == ARRAY_TYPE; | |
6707 | type = TREE_TYPE (type), dimension_number++) | |
6708 | { | |
6709 | #endif | |
6710 | register tree domain = TYPE_DOMAIN (type); | |
6711 | ||
6712 | /* Arrays come in three flavors: Unspecified bounds, fixed bounds, | |
6713 | and (in GNU C only) variable bounds. Handle all three forms | |
6714 | here. */ | |
6715 | subrange_die = new_die (DW_TAG_subrange_type, type_die); | |
6716 | if (domain) | |
6717 | { | |
6718 | /* We have an array type with specified bounds. */ | |
6719 | lower = TYPE_MIN_VALUE (domain); | |
6720 | upper = TYPE_MAX_VALUE (domain); | |
6721 | ||
a9d38797 JM |
6722 | /* define the index type. */ |
6723 | if (TREE_TYPE (domain)) | |
ef76d03b JW |
6724 | { |
6725 | /* ??? This is probably an Ada unnamed subrange type. Ignore the | |
6726 | TREE_TYPE field. We can't emit debug info for this | |
6727 | because it is an unnamed integral type. */ | |
6728 | if (TREE_CODE (domain) == INTEGER_TYPE | |
6729 | && TYPE_NAME (domain) == NULL_TREE | |
6730 | && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE | |
6731 | && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE) | |
6732 | ; | |
6733 | else | |
6734 | add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0, | |
6735 | type_die); | |
6736 | } | |
a9d38797 | 6737 | |
141719a8 | 6738 | add_bound_info (subrange_die, DW_AT_lower_bound, lower); |
a3f97cbb JW |
6739 | add_bound_info (subrange_die, DW_AT_upper_bound, upper); |
6740 | } | |
6741 | else | |
71dfc51f | 6742 | /* We have an array type with an unspecified length. The DWARF-2 |
a9d38797 JM |
6743 | spec does not say how to handle this; let's just leave out the |
6744 | bounds. */ | |
71dfc51f RK |
6745 | ; |
6746 | ||
a3f97cbb JW |
6747 | #ifndef MIPS_DEBUGGING_INFO |
6748 | } | |
6749 | #endif | |
6750 | } | |
6751 | ||
6752 | static void | |
6753 | add_byte_size_attribute (die, tree_node) | |
6754 | dw_die_ref die; | |
6755 | register tree tree_node; | |
6756 | { | |
6757 | register unsigned size; | |
6758 | ||
6759 | switch (TREE_CODE (tree_node)) | |
6760 | { | |
6761 | case ERROR_MARK: | |
6762 | size = 0; | |
6763 | break; | |
6764 | case ENUMERAL_TYPE: | |
6765 | case RECORD_TYPE: | |
6766 | case UNION_TYPE: | |
6767 | case QUAL_UNION_TYPE: | |
6768 | size = int_size_in_bytes (tree_node); | |
6769 | break; | |
6770 | case FIELD_DECL: | |
6771 | /* For a data member of a struct or union, the DW_AT_byte_size is | |
6772 | generally given as the number of bytes normally allocated for an | |
6773 | object of the *declared* type of the member itself. This is true | |
6774 | even for bit-fields. */ | |
6775 | size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT; | |
6776 | break; | |
6777 | default: | |
6778 | abort (); | |
6779 | } | |
6780 | ||
6781 | /* Note that `size' might be -1 when we get to this point. If it is, that | |
6782 | indicates that the byte size of the entity in question is variable. We | |
6783 | have no good way of expressing this fact in Dwarf at the present time, | |
6784 | so just let the -1 pass on through. */ | |
6785 | ||
6786 | add_AT_unsigned (die, DW_AT_byte_size, size); | |
6787 | } | |
6788 | ||
6789 | /* For a FIELD_DECL node which represents a bit-field, output an attribute | |
6790 | which specifies the distance in bits from the highest order bit of the | |
6791 | "containing object" for the bit-field to the highest order bit of the | |
6792 | bit-field itself. | |
6793 | ||
b2932ae5 JM |
6794 | For any given bit-field, the "containing object" is a hypothetical |
6795 | object (of some integral or enum type) within which the given bit-field | |
6796 | lives. The type of this hypothetical "containing object" is always the | |
6797 | same as the declared type of the individual bit-field itself. The | |
6798 | determination of the exact location of the "containing object" for a | |
6799 | bit-field is rather complicated. It's handled by the | |
6800 | `field_byte_offset' function (above). | |
a3f97cbb JW |
6801 | |
6802 | Note that it is the size (in bytes) of the hypothetical "containing object" | |
6803 | which will be given in the DW_AT_byte_size attribute for this bit-field. | |
6804 | (See `byte_size_attribute' above). */ | |
71dfc51f RK |
6805 | |
6806 | static inline void | |
a3f97cbb JW |
6807 | add_bit_offset_attribute (die, decl) |
6808 | register dw_die_ref die; | |
6809 | register tree decl; | |
6810 | { | |
6811 | register unsigned object_offset_in_bytes = field_byte_offset (decl); | |
6812 | register tree type = DECL_BIT_FIELD_TYPE (decl); | |
6813 | register tree bitpos_tree = DECL_FIELD_BITPOS (decl); | |
6814 | register unsigned bitpos_int; | |
6815 | register unsigned highest_order_object_bit_offset; | |
6816 | register unsigned highest_order_field_bit_offset; | |
6817 | register unsigned bit_offset; | |
6818 | ||
6819 | assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */ | |
6820 | assert (type); /* Must be a bit field. */ | |
6821 | ||
6822 | /* We can't yet handle bit-fields whose offsets are variable, so if we | |
6823 | encounter such things, just return without generating any attribute | |
6824 | whatsoever. */ | |
6825 | if (TREE_CODE (bitpos_tree) != INTEGER_CST) | |
71dfc51f RK |
6826 | return; |
6827 | ||
a3f97cbb JW |
6828 | bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree); |
6829 | ||
6830 | /* Note that the bit offset is always the distance (in bits) from the | |
6831 | highest-order bit of the "containing object" to the highest-order bit of | |
6832 | the bit-field itself. Since the "high-order end" of any object or field | |
6833 | is different on big-endian and little-endian machines, the computation | |
6834 | below must take account of these differences. */ | |
6835 | highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; | |
6836 | highest_order_field_bit_offset = bitpos_int; | |
6837 | ||
71dfc51f | 6838 | if (! BYTES_BIG_ENDIAN) |
a3f97cbb JW |
6839 | { |
6840 | highest_order_field_bit_offset | |
6841 | += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)); | |
6842 | ||
6843 | highest_order_object_bit_offset += simple_type_size_in_bits (type); | |
6844 | } | |
71dfc51f RK |
6845 | |
6846 | bit_offset | |
6847 | = (! BYTES_BIG_ENDIAN | |
6848 | ? highest_order_object_bit_offset - highest_order_field_bit_offset | |
6849 | : highest_order_field_bit_offset - highest_order_object_bit_offset); | |
a3f97cbb JW |
6850 | |
6851 | add_AT_unsigned (die, DW_AT_bit_offset, bit_offset); | |
6852 | } | |
6853 | ||
6854 | /* For a FIELD_DECL node which represents a bit field, output an attribute | |
6855 | which specifies the length in bits of the given field. */ | |
71dfc51f RK |
6856 | |
6857 | static inline void | |
a3f97cbb JW |
6858 | add_bit_size_attribute (die, decl) |
6859 | register dw_die_ref die; | |
6860 | register tree decl; | |
6861 | { | |
6862 | assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */ | |
6863 | assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */ | |
6864 | add_AT_unsigned (die, DW_AT_bit_size, | |
6865 | (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl))); | |
6866 | } | |
6867 | ||
88dad228 | 6868 | /* If the compiled language is ANSI C, then add a 'prototyped' |
a3f97cbb | 6869 | attribute, if arg types are given for the parameters of a function. */ |
71dfc51f RK |
6870 | |
6871 | static inline void | |
a3f97cbb JW |
6872 | add_prototyped_attribute (die, func_type) |
6873 | register dw_die_ref die; | |
6874 | register tree func_type; | |
6875 | { | |
88dad228 JM |
6876 | if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89 |
6877 | && TYPE_ARG_TYPES (func_type) != NULL) | |
6878 | add_AT_flag (die, DW_AT_prototyped, 1); | |
a3f97cbb JW |
6879 | } |
6880 | ||
6881 | ||
6882 | /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found | |
6883 | by looking in either the type declaration or object declaration | |
6884 | equate table. */ | |
71dfc51f RK |
6885 | |
6886 | static inline void | |
a3f97cbb JW |
6887 | add_abstract_origin_attribute (die, origin) |
6888 | register dw_die_ref die; | |
6889 | register tree origin; | |
6890 | { | |
6891 | dw_die_ref origin_die = NULL; | |
6892 | if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd') | |
71dfc51f | 6893 | origin_die = lookup_decl_die (origin); |
a3f97cbb | 6894 | else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't') |
71dfc51f RK |
6895 | origin_die = lookup_type_die (origin); |
6896 | ||
a3f97cbb JW |
6897 | add_AT_die_ref (die, DW_AT_abstract_origin, origin_die); |
6898 | } | |
6899 | ||
bdb669cb JM |
6900 | /* We do not currently support the pure_virtual attribute. */ |
6901 | ||
71dfc51f | 6902 | static inline void |
a3f97cbb JW |
6903 | add_pure_or_virtual_attribute (die, func_decl) |
6904 | register dw_die_ref die; | |
6905 | register tree func_decl; | |
6906 | { | |
a94dbf2c | 6907 | if (DECL_VINDEX (func_decl)) |
a3f97cbb | 6908 | { |
bdb669cb | 6909 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); |
71dfc51f RK |
6910 | add_AT_loc (die, DW_AT_vtable_elem_location, |
6911 | new_loc_descr (DW_OP_constu, | |
6912 | TREE_INT_CST_LOW (DECL_VINDEX (func_decl)), | |
6913 | 0)); | |
6914 | ||
a94dbf2c JM |
6915 | /* GNU extension: Record what type this method came from originally. */ |
6916 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
6917 | add_AT_die_ref (die, DW_AT_containing_type, | |
6918 | lookup_type_die (DECL_CONTEXT (func_decl))); | |
a3f97cbb JW |
6919 | } |
6920 | } | |
6921 | \f | |
b2932ae5 | 6922 | /* Add source coordinate attributes for the given decl. */ |
71dfc51f | 6923 | |
b2932ae5 JM |
6924 | static void |
6925 | add_src_coords_attributes (die, decl) | |
6926 | register dw_die_ref die; | |
6927 | register tree decl; | |
6928 | { | |
6929 | register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); | |
71dfc51f | 6930 | |
b2932ae5 JM |
6931 | add_AT_unsigned (die, DW_AT_decl_file, file_index); |
6932 | add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
6933 | } | |
6934 | ||
a3f97cbb JW |
6935 | /* Add an DW_AT_name attribute and source coordinate attribute for the |
6936 | given decl, but only if it actually has a name. */ | |
71dfc51f | 6937 | |
a3f97cbb JW |
6938 | static void |
6939 | add_name_and_src_coords_attributes (die, decl) | |
6940 | register dw_die_ref die; | |
6941 | register tree decl; | |
6942 | { | |
61b32c02 | 6943 | register tree decl_name; |
71dfc51f | 6944 | |
a1d7ffe3 | 6945 | decl_name = DECL_NAME (decl); |
71dfc51f | 6946 | if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL) |
a3f97cbb | 6947 | { |
a1d7ffe3 | 6948 | add_name_attribute (die, dwarf2_name (decl, 0)); |
b2932ae5 | 6949 | add_src_coords_attributes (die, decl); |
a1d7ffe3 JM |
6950 | if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) |
6951 | && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)) | |
6952 | add_AT_string (die, DW_AT_MIPS_linkage_name, | |
6953 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
a3f97cbb JW |
6954 | } |
6955 | } | |
6956 | ||
6957 | /* Push a new declaration scope. */ | |
71dfc51f | 6958 | |
a3f97cbb JW |
6959 | static void |
6960 | push_decl_scope (scope) | |
6961 | tree scope; | |
6962 | { | |
6963 | /* Make room in the decl_scope_table, if necessary. */ | |
6964 | if (decl_scope_table_allocated == decl_scope_depth) | |
6965 | { | |
6966 | decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT; | |
71dfc51f RK |
6967 | decl_scope_table |
6968 | = (tree *) xrealloc (decl_scope_table, | |
6969 | decl_scope_table_allocated * sizeof (tree)); | |
a3f97cbb | 6970 | } |
71dfc51f | 6971 | |
a3f97cbb JW |
6972 | decl_scope_table[decl_scope_depth++] = scope; |
6973 | } | |
6974 | ||
6975 | /* Return the DIE for the scope the immediately contains this declaration. */ | |
71dfc51f | 6976 | |
a3f97cbb | 6977 | static dw_die_ref |
ab72d377 JM |
6978 | scope_die_for (t, context_die) |
6979 | register tree t; | |
a3f97cbb JW |
6980 | register dw_die_ref context_die; |
6981 | { | |
6982 | register dw_die_ref scope_die = NULL; | |
6983 | register tree containing_scope; | |
6984 | register unsigned long i; | |
6985 | ||
6986 | /* Walk back up the declaration tree looking for a place to define | |
6987 | this type. */ | |
ab72d377 JM |
6988 | if (TREE_CODE_CLASS (TREE_CODE (t)) == 't') |
6989 | containing_scope = TYPE_CONTEXT (t); | |
a94dbf2c | 6990 | else if (TREE_CODE (t) == FUNCTION_DECL && DECL_VINDEX (t)) |
ab72d377 JM |
6991 | containing_scope = decl_class_context (t); |
6992 | else | |
6993 | containing_scope = DECL_CONTEXT (t); | |
6994 | ||
ef76d03b JW |
6995 | /* Function-local tags and functions get stuck in limbo until they are |
6996 | fixed up by decls_for_scope. */ | |
6997 | if (context_die == NULL && containing_scope != NULL_TREE | |
6998 | && (TREE_CODE (t) == FUNCTION_DECL || is_tagged_type (t))) | |
6999 | return NULL; | |
7000 | ||
71dfc51f RK |
7001 | if (containing_scope == NULL_TREE) |
7002 | scope_die = comp_unit_die; | |
a3f97cbb JW |
7003 | else |
7004 | { | |
ab72d377 JM |
7005 | for (i = decl_scope_depth, scope_die = context_die; |
7006 | i > 0 && decl_scope_table[i - 1] != containing_scope; | |
7d4440be | 7007 | scope_die = scope_die->die_parent, --i) |
71dfc51f RK |
7008 | ; |
7009 | ||
ab72d377 | 7010 | if (i == 0) |
a3f97cbb | 7011 | { |
ab72d377 JM |
7012 | assert (scope_die == comp_unit_die); |
7013 | assert (TREE_CODE_CLASS (TREE_CODE (containing_scope)) == 't'); | |
4927276d JM |
7014 | if (debug_info_level > DINFO_LEVEL_TERSE) |
7015 | assert (TREE_ASM_WRITTEN (containing_scope)); | |
a3f97cbb JW |
7016 | } |
7017 | } | |
71dfc51f | 7018 | |
a3f97cbb JW |
7019 | return scope_die; |
7020 | } | |
7021 | ||
7022 | /* Pop a declaration scope. */ | |
71dfc51f | 7023 | static inline void |
a3f97cbb JW |
7024 | pop_decl_scope () |
7025 | { | |
7026 | assert (decl_scope_depth > 0); | |
7027 | --decl_scope_depth; | |
7028 | } | |
7029 | ||
7030 | /* Many forms of DIEs require a "type description" attribute. This | |
7031 | routine locates the proper "type descriptor" die for the type given | |
7032 | by 'type', and adds an DW_AT_type attribute below the given die. */ | |
71dfc51f | 7033 | |
a3f97cbb JW |
7034 | static void |
7035 | add_type_attribute (object_die, type, decl_const, decl_volatile, context_die) | |
7036 | register dw_die_ref object_die; | |
7037 | register tree type; | |
7038 | register int decl_const; | |
7039 | register int decl_volatile; | |
7040 | register dw_die_ref context_die; | |
7041 | { | |
7042 | register enum tree_code code = TREE_CODE (type); | |
a3f97cbb JW |
7043 | register dw_die_ref type_die = NULL; |
7044 | ||
ef76d03b JW |
7045 | /* ??? If this type is an unnamed subrange type of an integral or |
7046 | floating-point type, use the inner type. This is because we have no | |
7047 | support for unnamed types in base_type_die. This can happen if this is | |
7048 | an Ada subrange type. Correct solution is emit a subrange type die. */ | |
b1ccbc24 RK |
7049 | if ((code == INTEGER_TYPE || code == REAL_TYPE) |
7050 | && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0) | |
7051 | type = TREE_TYPE (type), code = TREE_CODE (type); | |
7052 | ||
a3f97cbb | 7053 | if (code == ERROR_MARK) |
b1ccbc24 | 7054 | return; |
a3f97cbb JW |
7055 | |
7056 | /* Handle a special case. For functions whose return type is void, we | |
7057 | generate *no* type attribute. (Note that no object may have type | |
7058 | `void', so this only applies to function return types). */ | |
7059 | if (code == VOID_TYPE) | |
b1ccbc24 | 7060 | return; |
a3f97cbb | 7061 | |
a3f97cbb JW |
7062 | type_die = modified_type_die (type, |
7063 | decl_const || TYPE_READONLY (type), | |
7064 | decl_volatile || TYPE_VOLATILE (type), | |
ab72d377 | 7065 | context_die); |
a3f97cbb | 7066 | if (type_die != NULL) |
71dfc51f | 7067 | add_AT_die_ref (object_die, DW_AT_type, type_die); |
a3f97cbb JW |
7068 | } |
7069 | ||
7070 | /* Given a tree pointer to a struct, class, union, or enum type node, return | |
7071 | a pointer to the (string) tag name for the given type, or zero if the type | |
7072 | was declared without a tag. */ | |
71dfc51f | 7073 | |
a3f97cbb JW |
7074 | static char * |
7075 | type_tag (type) | |
7076 | register tree type; | |
7077 | { | |
7078 | register char *name = 0; | |
7079 | ||
7080 | if (TYPE_NAME (type) != 0) | |
7081 | { | |
7082 | register tree t = 0; | |
7083 | ||
7084 | /* Find the IDENTIFIER_NODE for the type name. */ | |
7085 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
7086 | t = TYPE_NAME (type); | |
bdb669cb | 7087 | |
a3f97cbb JW |
7088 | /* The g++ front end makes the TYPE_NAME of *each* tagged type point to |
7089 | a TYPE_DECL node, regardless of whether or not a `typedef' was | |
bdb669cb | 7090 | involved. */ |
a94dbf2c JM |
7091 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
7092 | && ! DECL_IGNORED_P (TYPE_NAME (type))) | |
a3f97cbb | 7093 | t = DECL_NAME (TYPE_NAME (type)); |
bdb669cb | 7094 | |
a3f97cbb JW |
7095 | /* Now get the name as a string, or invent one. */ |
7096 | if (t != 0) | |
a94dbf2c | 7097 | name = IDENTIFIER_POINTER (t); |
a3f97cbb | 7098 | } |
71dfc51f | 7099 | |
a3f97cbb JW |
7100 | return (name == 0 || *name == '\0') ? 0 : name; |
7101 | } | |
7102 | ||
7103 | /* Return the type associated with a data member, make a special check | |
7104 | for bit field types. */ | |
71dfc51f RK |
7105 | |
7106 | static inline tree | |
a3f97cbb JW |
7107 | member_declared_type (member) |
7108 | register tree member; | |
7109 | { | |
71dfc51f RK |
7110 | return (DECL_BIT_FIELD_TYPE (member) |
7111 | ? DECL_BIT_FIELD_TYPE (member) | |
7112 | : TREE_TYPE (member)); | |
a3f97cbb JW |
7113 | } |
7114 | ||
d291dd49 | 7115 | /* Get the decl's label, as described by its RTL. This may be different |
a3f97cbb | 7116 | from the DECL_NAME name used in the source file. */ |
71dfc51f | 7117 | |
a3f97cbb | 7118 | static char * |
d291dd49 | 7119 | decl_start_label (decl) |
a3f97cbb JW |
7120 | register tree decl; |
7121 | { | |
7122 | rtx x; | |
7123 | char *fnname; | |
7124 | x = DECL_RTL (decl); | |
7125 | if (GET_CODE (x) != MEM) | |
71dfc51f RK |
7126 | abort (); |
7127 | ||
a3f97cbb JW |
7128 | x = XEXP (x, 0); |
7129 | if (GET_CODE (x) != SYMBOL_REF) | |
71dfc51f RK |
7130 | abort (); |
7131 | ||
a3f97cbb JW |
7132 | fnname = XSTR (x, 0); |
7133 | return fnname; | |
7134 | } | |
7135 | \f | |
a3f97cbb JW |
7136 | /* These routines generate the internnal representation of the DIE's for |
7137 | the compilation unit. Debugging information is collected by walking | |
88dad228 | 7138 | the declaration trees passed in from dwarf2out_decl(). */ |
a3f97cbb JW |
7139 | |
7140 | static void | |
7141 | gen_array_type_die (type, context_die) | |
7142 | register tree type; | |
7143 | register dw_die_ref context_die; | |
7144 | { | |
ab72d377 | 7145 | register dw_die_ref scope_die = scope_die_for (type, context_die); |
a9d38797 | 7146 | register dw_die_ref array_die; |
a3f97cbb | 7147 | register tree element_type; |
bdb669cb | 7148 | |
a9d38797 JM |
7149 | /* ??? The SGI dwarf reader fails for array of array of enum types unless |
7150 | the inner array type comes before the outer array type. Thus we must | |
7151 | call gen_type_die before we call new_die. See below also. */ | |
7152 | #ifdef MIPS_DEBUGGING_INFO | |
7153 | gen_type_die (TREE_TYPE (type), context_die); | |
7154 | #endif | |
7155 | ||
7156 | array_die = new_die (DW_TAG_array_type, scope_die); | |
7157 | ||
a3f97cbb JW |
7158 | #if 0 |
7159 | /* We default the array ordering. SDB will probably do | |
7160 | the right things even if DW_AT_ordering is not present. It's not even | |
7161 | an issue until we start to get into multidimensional arrays anyway. If | |
7162 | SDB is ever caught doing the Wrong Thing for multi-dimensional arrays, | |
7163 | then we'll have to put the DW_AT_ordering attribute back in. (But if | |
7164 | and when we find out that we need to put these in, we will only do so | |
7165 | for multidimensional arrays. */ | |
7166 | add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major); | |
7167 | #endif | |
7168 | ||
a9d38797 | 7169 | #ifdef MIPS_DEBUGGING_INFO |
4edb7b60 JM |
7170 | /* The SGI compilers handle arrays of unknown bound by setting |
7171 | AT_declaration and not emitting any subrange DIEs. */ | |
a9d38797 JM |
7172 | if (! TYPE_DOMAIN (type)) |
7173 | add_AT_unsigned (array_die, DW_AT_declaration, 1); | |
7174 | else | |
7175 | #endif | |
7176 | add_subscript_info (array_die, type); | |
a3f97cbb JW |
7177 | |
7178 | equate_type_number_to_die (type, array_die); | |
7179 | ||
7180 | /* Add representation of the type of the elements of this array type. */ | |
7181 | element_type = TREE_TYPE (type); | |
71dfc51f | 7182 | |
a3f97cbb JW |
7183 | /* ??? The SGI dwarf reader fails for multidimensional arrays with a |
7184 | const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. | |
7185 | We work around this by disabling this feature. See also | |
7186 | add_subscript_info. */ | |
7187 | #ifndef MIPS_DEBUGGING_INFO | |
71dfc51f RK |
7188 | while (TREE_CODE (element_type) == ARRAY_TYPE) |
7189 | element_type = TREE_TYPE (element_type); | |
7190 | ||
a3f97cbb | 7191 | gen_type_die (element_type, context_die); |
a9d38797 | 7192 | #endif |
a3f97cbb JW |
7193 | |
7194 | add_type_attribute (array_die, element_type, 0, 0, context_die); | |
7195 | } | |
7196 | ||
7197 | static void | |
7198 | gen_set_type_die (type, context_die) | |
7199 | register tree type; | |
7200 | register dw_die_ref context_die; | |
7201 | { | |
71dfc51f RK |
7202 | register dw_die_ref type_die |
7203 | = new_die (DW_TAG_set_type, scope_die_for (type, context_die)); | |
7204 | ||
a3f97cbb | 7205 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
7206 | add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die); |
7207 | } | |
7208 | ||
7209 | static void | |
7210 | gen_entry_point_die (decl, context_die) | |
7211 | register tree decl; | |
7212 | register dw_die_ref context_die; | |
7213 | { | |
7214 | register tree origin = decl_ultimate_origin (decl); | |
7215 | register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die); | |
7216 | if (origin != NULL) | |
71dfc51f | 7217 | add_abstract_origin_attribute (decl_die, origin); |
a3f97cbb JW |
7218 | else |
7219 | { | |
7220 | add_name_and_src_coords_attributes (decl_die, decl); | |
a3f97cbb JW |
7221 | add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)), |
7222 | 0, 0, context_die); | |
7223 | } | |
71dfc51f | 7224 | |
a3f97cbb | 7225 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 7226 | equate_decl_number_to_die (decl, decl_die); |
a3f97cbb | 7227 | else |
71dfc51f | 7228 | add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl)); |
a3f97cbb JW |
7229 | } |
7230 | ||
a94dbf2c JM |
7231 | /* Remember a type in the pending_types_list. */ |
7232 | ||
7233 | static void | |
7234 | pend_type (type) | |
7235 | register tree type; | |
7236 | { | |
7237 | if (pending_types == pending_types_allocated) | |
7238 | { | |
7239 | pending_types_allocated += PENDING_TYPES_INCREMENT; | |
7240 | pending_types_list | |
7241 | = (tree *) xrealloc (pending_types_list, | |
7242 | sizeof (tree) * pending_types_allocated); | |
7243 | } | |
71dfc51f | 7244 | |
a94dbf2c JM |
7245 | pending_types_list[pending_types++] = type; |
7246 | } | |
7247 | ||
7248 | /* Output any pending types (from the pending_types list) which we can output | |
7249 | now (taking into account the scope that we are working on now). | |
7250 | ||
7251 | For each type output, remove the given type from the pending_types_list | |
7252 | *before* we try to output it. */ | |
7253 | ||
7254 | static void | |
7255 | output_pending_types_for_scope (context_die) | |
7256 | register dw_die_ref context_die; | |
7257 | { | |
7258 | register tree type; | |
7259 | ||
7260 | while (pending_types) | |
7261 | { | |
7262 | --pending_types; | |
7263 | type = pending_types_list[pending_types]; | |
7264 | gen_type_die (type, context_die); | |
7265 | assert (TREE_ASM_WRITTEN (type)); | |
7266 | } | |
7267 | } | |
7268 | ||
a3f97cbb | 7269 | /* Generate a DIE to represent an inlined instance of an enumeration type. */ |
71dfc51f | 7270 | |
a3f97cbb JW |
7271 | static void |
7272 | gen_inlined_enumeration_type_die (type, context_die) | |
7273 | register tree type; | |
7274 | register dw_die_ref context_die; | |
7275 | { | |
71dfc51f RK |
7276 | register dw_die_ref type_die = new_die (DW_TAG_enumeration_type, |
7277 | scope_die_for (type, context_die)); | |
7278 | ||
a3f97cbb JW |
7279 | assert (TREE_ASM_WRITTEN (type)); |
7280 | add_abstract_origin_attribute (type_die, type); | |
7281 | } | |
7282 | ||
7283 | /* Generate a DIE to represent an inlined instance of a structure type. */ | |
71dfc51f | 7284 | |
a3f97cbb JW |
7285 | static void |
7286 | gen_inlined_structure_type_die (type, context_die) | |
7287 | register tree type; | |
7288 | register dw_die_ref context_die; | |
7289 | { | |
71dfc51f RK |
7290 | register dw_die_ref type_die = new_die (DW_TAG_structure_type, |
7291 | scope_die_for (type, context_die)); | |
7292 | ||
a3f97cbb JW |
7293 | assert (TREE_ASM_WRITTEN (type)); |
7294 | add_abstract_origin_attribute (type_die, type); | |
7295 | } | |
7296 | ||
7297 | /* Generate a DIE to represent an inlined instance of a union type. */ | |
71dfc51f | 7298 | |
a3f97cbb JW |
7299 | static void |
7300 | gen_inlined_union_type_die (type, context_die) | |
7301 | register tree type; | |
7302 | register dw_die_ref context_die; | |
7303 | { | |
71dfc51f RK |
7304 | register dw_die_ref type_die = new_die (DW_TAG_union_type, |
7305 | scope_die_for (type, context_die)); | |
7306 | ||
a3f97cbb JW |
7307 | assert (TREE_ASM_WRITTEN (type)); |
7308 | add_abstract_origin_attribute (type_die, type); | |
7309 | } | |
7310 | ||
7311 | /* Generate a DIE to represent an enumeration type. Note that these DIEs | |
7312 | include all of the information about the enumeration values also. Each | |
273dbe67 JM |
7313 | enumerated type name/value is listed as a child of the enumerated type |
7314 | DIE. */ | |
71dfc51f | 7315 | |
a3f97cbb | 7316 | static void |
273dbe67 | 7317 | gen_enumeration_type_die (type, context_die) |
a3f97cbb | 7318 | register tree type; |
a3f97cbb JW |
7319 | register dw_die_ref context_die; |
7320 | { | |
273dbe67 JM |
7321 | register dw_die_ref type_die = lookup_type_die (type); |
7322 | ||
a3f97cbb JW |
7323 | if (type_die == NULL) |
7324 | { | |
7325 | type_die = new_die (DW_TAG_enumeration_type, | |
ab72d377 | 7326 | scope_die_for (type, context_die)); |
a3f97cbb JW |
7327 | equate_type_number_to_die (type, type_die); |
7328 | add_name_attribute (type_die, type_tag (type)); | |
a3f97cbb | 7329 | } |
273dbe67 JM |
7330 | else if (! TYPE_SIZE (type)) |
7331 | return; | |
7332 | else | |
7333 | remove_AT (type_die, DW_AT_declaration); | |
7334 | ||
7335 | /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the | |
7336 | given enum type is incomplete, do not generate the DW_AT_byte_size | |
7337 | attribute or the DW_AT_element_list attribute. */ | |
7338 | if (TYPE_SIZE (type)) | |
a3f97cbb | 7339 | { |
273dbe67 | 7340 | register tree link; |
71dfc51f | 7341 | |
a082c85a | 7342 | TREE_ASM_WRITTEN (type) = 1; |
273dbe67 | 7343 | add_byte_size_attribute (type_die, type); |
b2932ae5 JM |
7344 | if (type_tag (type)) |
7345 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); | |
71dfc51f | 7346 | |
ef76d03b JW |
7347 | /* If the first reference to this type was as the return type of an |
7348 | inline function, then it may not have a parent. Fix this now. */ | |
7349 | if (type_die->die_parent == NULL) | |
7350 | add_child_die (scope_die_for (type, context_die), type_die); | |
7351 | ||
273dbe67 JM |
7352 | for (link = TYPE_FIELDS (type); |
7353 | link != NULL; link = TREE_CHAIN (link)) | |
a3f97cbb | 7354 | { |
273dbe67 | 7355 | register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die); |
71dfc51f | 7356 | |
273dbe67 JM |
7357 | add_name_attribute (enum_die, |
7358 | IDENTIFIER_POINTER (TREE_PURPOSE (link))); | |
7359 | add_AT_unsigned (enum_die, DW_AT_const_value, | |
a3f97cbb | 7360 | (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link))); |
a3f97cbb JW |
7361 | } |
7362 | } | |
273dbe67 JM |
7363 | else |
7364 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a3f97cbb JW |
7365 | } |
7366 | ||
7367 | ||
7368 | /* Generate a DIE to represent either a real live formal parameter decl or to | |
7369 | represent just the type of some formal parameter position in some function | |
7370 | type. | |
71dfc51f | 7371 | |
a3f97cbb JW |
7372 | Note that this routine is a bit unusual because its argument may be a |
7373 | ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which | |
7374 | represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE | |
7375 | node. If it's the former then this function is being called to output a | |
7376 | DIE to represent a formal parameter object (or some inlining thereof). If | |
7377 | it's the latter, then this function is only being called to output a | |
7378 | DW_TAG_formal_parameter DIE to stand as a placeholder for some formal | |
7379 | argument type of some subprogram type. */ | |
71dfc51f | 7380 | |
a94dbf2c | 7381 | static dw_die_ref |
a3f97cbb JW |
7382 | gen_formal_parameter_die (node, context_die) |
7383 | register tree node; | |
7384 | register dw_die_ref context_die; | |
7385 | { | |
71dfc51f RK |
7386 | register dw_die_ref parm_die |
7387 | = new_die (DW_TAG_formal_parameter, context_die); | |
a3f97cbb | 7388 | register tree origin; |
71dfc51f | 7389 | |
a3f97cbb JW |
7390 | switch (TREE_CODE_CLASS (TREE_CODE (node))) |
7391 | { | |
a3f97cbb JW |
7392 | case 'd': |
7393 | origin = decl_ultimate_origin (node); | |
7394 | if (origin != NULL) | |
a94dbf2c | 7395 | add_abstract_origin_attribute (parm_die, origin); |
a3f97cbb JW |
7396 | else |
7397 | { | |
7398 | add_name_and_src_coords_attributes (parm_die, node); | |
7399 | add_type_attribute (parm_die, TREE_TYPE (node), | |
7400 | TREE_READONLY (node), | |
7401 | TREE_THIS_VOLATILE (node), | |
7402 | context_die); | |
bdb669cb JM |
7403 | if (DECL_ARTIFICIAL (node)) |
7404 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb | 7405 | } |
71dfc51f | 7406 | |
141719a8 JM |
7407 | equate_decl_number_to_die (node, parm_die); |
7408 | if (! DECL_ABSTRACT (node)) | |
a94dbf2c | 7409 | add_location_or_const_value_attribute (parm_die, node); |
71dfc51f | 7410 | |
a3f97cbb JW |
7411 | break; |
7412 | ||
a3f97cbb | 7413 | case 't': |
71dfc51f | 7414 | /* We were called with some kind of a ..._TYPE node. */ |
a3f97cbb JW |
7415 | add_type_attribute (parm_die, node, 0, 0, context_die); |
7416 | break; | |
7417 | ||
a3f97cbb JW |
7418 | default: |
7419 | abort (); | |
7420 | } | |
71dfc51f | 7421 | |
a94dbf2c | 7422 | return parm_die; |
a3f97cbb JW |
7423 | } |
7424 | ||
7425 | /* Generate a special type of DIE used as a stand-in for a trailing ellipsis | |
7426 | at the end of an (ANSI prototyped) formal parameters list. */ | |
71dfc51f | 7427 | |
a3f97cbb JW |
7428 | static void |
7429 | gen_unspecified_parameters_die (decl_or_type, context_die) | |
7430 | register tree decl_or_type; | |
7431 | register dw_die_ref context_die; | |
7432 | { | |
7433 | register dw_die_ref parm_die = new_die (DW_TAG_unspecified_parameters, | |
7434 | context_die); | |
a3f97cbb JW |
7435 | } |
7436 | ||
7437 | /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a | |
7438 | DW_TAG_unspecified_parameters DIE) to represent the types of the formal | |
7439 | parameters as specified in some function type specification (except for | |
7440 | those which appear as part of a function *definition*). | |
71dfc51f RK |
7441 | |
7442 | Note we must be careful here to output all of the parameter DIEs before* | |
a3f97cbb JW |
7443 | we output any DIEs needed to represent the types of the formal parameters. |
7444 | This keeps svr4 SDB happy because it (incorrectly) thinks that the first | |
7445 | non-parameter DIE it sees ends the formal parameter list. */ | |
71dfc51f | 7446 | |
a3f97cbb JW |
7447 | static void |
7448 | gen_formal_types_die (function_or_method_type, context_die) | |
7449 | register tree function_or_method_type; | |
7450 | register dw_die_ref context_die; | |
7451 | { | |
7452 | register tree link; | |
7453 | register tree formal_type = NULL; | |
7454 | register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type); | |
7455 | ||
bdb669cb | 7456 | #if 0 |
a3f97cbb JW |
7457 | /* In the case where we are generating a formal types list for a C++ |
7458 | non-static member function type, skip over the first thing on the | |
7459 | TYPE_ARG_TYPES list because it only represents the type of the hidden | |
7460 | `this pointer'. The debugger should be able to figure out (without | |
7461 | being explicitly told) that this non-static member function type takes a | |
7462 | `this pointer' and should be able to figure what the type of that hidden | |
7463 | parameter is from the DW_AT_member attribute of the parent | |
7464 | DW_TAG_subroutine_type DIE. */ | |
7465 | if (TREE_CODE (function_or_method_type) == METHOD_TYPE) | |
7466 | first_parm_type = TREE_CHAIN (first_parm_type); | |
bdb669cb | 7467 | #endif |
a3f97cbb JW |
7468 | |
7469 | /* Make our first pass over the list of formal parameter types and output a | |
7470 | DW_TAG_formal_parameter DIE for each one. */ | |
7471 | for (link = first_parm_type; link; link = TREE_CHAIN (link)) | |
7472 | { | |
a94dbf2c JM |
7473 | register dw_die_ref parm_die; |
7474 | ||
a3f97cbb JW |
7475 | formal_type = TREE_VALUE (link); |
7476 | if (formal_type == void_type_node) | |
7477 | break; | |
7478 | ||
7479 | /* Output a (nameless) DIE to represent the formal parameter itself. */ | |
a94dbf2c JM |
7480 | parm_die = gen_formal_parameter_die (formal_type, context_die); |
7481 | if (TREE_CODE (function_or_method_type) == METHOD_TYPE | |
7482 | && link == first_parm_type) | |
7483 | add_AT_flag (parm_die, DW_AT_artificial, 1); | |
a3f97cbb JW |
7484 | } |
7485 | ||
7486 | /* If this function type has an ellipsis, add a | |
7487 | DW_TAG_unspecified_parameters DIE to the end of the parameter list. */ | |
7488 | if (formal_type != void_type_node) | |
7489 | gen_unspecified_parameters_die (function_or_method_type, context_die); | |
7490 | ||
7491 | /* Make our second (and final) pass over the list of formal parameter types | |
7492 | and output DIEs to represent those types (as necessary). */ | |
7493 | for (link = TYPE_ARG_TYPES (function_or_method_type); | |
7494 | link; | |
7495 | link = TREE_CHAIN (link)) | |
7496 | { | |
7497 | formal_type = TREE_VALUE (link); | |
7498 | if (formal_type == void_type_node) | |
7499 | break; | |
7500 | ||
b50c02f9 | 7501 | gen_type_die (formal_type, context_die); |
a3f97cbb JW |
7502 | } |
7503 | } | |
7504 | ||
7505 | /* Generate a DIE to represent a declared function (either file-scope or | |
7506 | block-local). */ | |
71dfc51f | 7507 | |
a3f97cbb JW |
7508 | static void |
7509 | gen_subprogram_die (decl, context_die) | |
7510 | register tree decl; | |
7511 | register dw_die_ref context_die; | |
7512 | { | |
7513 | char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; | |
7514 | register tree origin = decl_ultimate_origin (decl); | |
4b674448 | 7515 | register dw_die_ref subr_die; |
a3f97cbb | 7516 | register dw_loc_descr_ref fp_loc = NULL; |
b1ccbc24 | 7517 | register rtx fp_reg; |
a3f97cbb JW |
7518 | register tree fn_arg_types; |
7519 | register tree outer_scope; | |
a94dbf2c | 7520 | register dw_die_ref old_die = lookup_decl_die (decl); |
9c6cd30e JM |
7521 | register int declaration |
7522 | = (current_function_decl != decl | |
7523 | || (context_die | |
7524 | && (context_die->die_tag == DW_TAG_structure_type | |
7525 | || context_die->die_tag == DW_TAG_union_type))); | |
a3f97cbb | 7526 | |
a3f97cbb JW |
7527 | if (origin != NULL) |
7528 | { | |
4b674448 | 7529 | subr_die = new_die (DW_TAG_subprogram, context_die); |
a3f97cbb JW |
7530 | add_abstract_origin_attribute (subr_die, origin); |
7531 | } | |
bdb669cb JM |
7532 | else if (old_die) |
7533 | { | |
4b674448 JM |
7534 | register unsigned file_index |
7535 | = lookup_filename (DECL_SOURCE_FILE (decl)); | |
a94dbf2c JM |
7536 | |
7537 | assert (get_AT_flag (old_die, DW_AT_declaration) == 1); | |
4b674448 JM |
7538 | |
7539 | /* If the definition comes from the same place as the declaration, | |
a94dbf2c JM |
7540 | maybe use the old DIE. We always want the DIE for this function |
7541 | that has the *_pc attributes to be under comp_unit_die so the | |
7542 | debugger can find it. For inlines, that is the concrete instance, | |
7543 | so we can use the old DIE here. For non-inline methods, we want a | |
7544 | specification DIE at toplevel, so we need a new DIE. For local | |
7545 | class methods, this does not apply. */ | |
7546 | if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die | |
7547 | || context_die == NULL) | |
7548 | && get_AT_unsigned (old_die, DW_AT_decl_file) == file_index | |
4b674448 JM |
7549 | && (get_AT_unsigned (old_die, DW_AT_decl_line) |
7550 | == DECL_SOURCE_LINE (decl))) | |
bdb669cb | 7551 | { |
4b674448 JM |
7552 | subr_die = old_die; |
7553 | ||
7554 | /* Clear out the declaration attribute and the parm types. */ | |
7555 | remove_AT (subr_die, DW_AT_declaration); | |
7556 | remove_children (subr_die); | |
7557 | } | |
7558 | else | |
7559 | { | |
7560 | subr_die = new_die (DW_TAG_subprogram, context_die); | |
7561 | add_AT_die_ref (subr_die, DW_AT_specification, old_die); | |
bdb669cb JM |
7562 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
7563 | add_AT_unsigned (subr_die, DW_AT_decl_file, file_index); | |
7564 | if (get_AT_unsigned (old_die, DW_AT_decl_line) | |
7565 | != DECL_SOURCE_LINE (decl)) | |
7566 | add_AT_unsigned | |
7567 | (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); | |
7568 | } | |
7569 | } | |
a3f97cbb JW |
7570 | else |
7571 | { | |
4edb7b60 JM |
7572 | register dw_die_ref scope_die; |
7573 | ||
7574 | if (DECL_CONTEXT (decl)) | |
7575 | scope_die = scope_die_for (decl, context_die); | |
7576 | else | |
7577 | /* Don't put block extern declarations under comp_unit_die. */ | |
7578 | scope_die = context_die; | |
7579 | ||
7580 | subr_die = new_die (DW_TAG_subprogram, scope_die); | |
7581 | ||
273dbe67 JM |
7582 | if (TREE_PUBLIC (decl)) |
7583 | add_AT_flag (subr_die, DW_AT_external, 1); | |
71dfc51f | 7584 | |
a3f97cbb | 7585 | add_name_and_src_coords_attributes (subr_die, decl); |
4927276d JM |
7586 | if (debug_info_level > DINFO_LEVEL_TERSE) |
7587 | { | |
7588 | register tree type = TREE_TYPE (decl); | |
71dfc51f | 7589 | |
4927276d JM |
7590 | add_prototyped_attribute (subr_die, type); |
7591 | add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die); | |
7592 | } | |
71dfc51f | 7593 | |
a3f97cbb | 7594 | add_pure_or_virtual_attribute (subr_die, decl); |
273dbe67 JM |
7595 | if (DECL_ARTIFICIAL (decl)) |
7596 | add_AT_flag (subr_die, DW_AT_artificial, 1); | |
a94dbf2c JM |
7597 | if (TREE_PROTECTED (decl)) |
7598 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected); | |
7599 | else if (TREE_PRIVATE (decl)) | |
7600 | add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 7601 | } |
4edb7b60 | 7602 | |
a94dbf2c JM |
7603 | if (declaration) |
7604 | { | |
7605 | add_AT_flag (subr_die, DW_AT_declaration, 1); | |
7606 | ||
7607 | /* The first time we see a member function, it is in the context of | |
7608 | the class to which it belongs. We make sure of this by emitting | |
7609 | the class first. The next time is the definition, which is | |
7610 | handled above. The two may come from the same source text. */ | |
f6c74b02 | 7611 | if (DECL_CONTEXT (decl)) |
a94dbf2c JM |
7612 | equate_decl_number_to_die (decl, subr_die); |
7613 | } | |
7614 | else if (DECL_ABSTRACT (decl)) | |
a3f97cbb | 7615 | { |
61b32c02 JM |
7616 | if (DECL_DEFER_OUTPUT (decl)) |
7617 | { | |
7618 | if (DECL_INLINE (decl)) | |
7619 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined); | |
7620 | else | |
7621 | add_AT_unsigned (subr_die, DW_AT_inline, | |
7622 | DW_INL_declared_not_inlined); | |
7623 | } | |
7624 | else if (DECL_INLINE (decl)) | |
7625 | add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined); | |
7626 | else | |
7627 | abort (); | |
7628 | ||
a3f97cbb JW |
7629 | equate_decl_number_to_die (decl, subr_die); |
7630 | } | |
7631 | else if (!DECL_EXTERNAL (decl)) | |
7632 | { | |
71dfc51f | 7633 | if (origin == NULL_TREE) |
ba7b35df | 7634 | equate_decl_number_to_die (decl, subr_die); |
71dfc51f | 7635 | |
5c90448c JM |
7636 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL, |
7637 | current_funcdef_number); | |
7d4440be | 7638 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id); |
5c90448c JM |
7639 | ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, |
7640 | current_funcdef_number); | |
a3f97cbb JW |
7641 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id); |
7642 | ||
d291dd49 JM |
7643 | add_pubname (decl, subr_die); |
7644 | add_arange (decl, subr_die); | |
7645 | ||
a3f97cbb | 7646 | #ifdef MIPS_DEBUGGING_INFO |
a3f97cbb JW |
7647 | /* Add a reference to the FDE for this routine. */ |
7648 | add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde); | |
7649 | #endif | |
7650 | ||
810429b7 JM |
7651 | /* Define the "frame base" location for this routine. We use the |
7652 | frame pointer or stack pointer registers, since the RTL for local | |
7653 | variables is relative to one of them. */ | |
b1ccbc24 RK |
7654 | fp_reg |
7655 | = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx; | |
7656 | add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg)); | |
a3f97cbb | 7657 | |
ef76d03b JW |
7658 | #if 0 |
7659 | /* ??? This fails for nested inline functions, because context_display | |
7660 | is not part of the state saved/restored for inline functions. */ | |
88dad228 | 7661 | if (current_function_needs_context) |
ef76d03b JW |
7662 | add_AT_location_description (subr_die, DW_AT_static_link, |
7663 | lookup_static_chain (decl)); | |
7664 | #endif | |
a3f97cbb JW |
7665 | } |
7666 | ||
7667 | /* Now output descriptions of the arguments for this function. This gets | |
7668 | (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list | |
7669 | for a FUNCTION_DECL doesn't indicate cases where there was a trailing | |
7670 | `...' at the end of the formal parameter list. In order to find out if | |
7671 | there was a trailing ellipsis or not, we must instead look at the type | |
7672 | associated with the FUNCTION_DECL. This will be a node of type | |
7673 | FUNCTION_TYPE. If the chain of type nodes hanging off of this | |
7674 | FUNCTION_TYPE node ends with a void_type_node then there should *not* be | |
7675 | an ellipsis at the end. */ | |
ab72d377 | 7676 | push_decl_scope (decl); |
71dfc51f | 7677 | |
a3f97cbb JW |
7678 | /* In the case where we are describing a mere function declaration, all we |
7679 | need to do here (and all we *can* do here) is to describe the *types* of | |
7680 | its formal parameters. */ | |
4927276d | 7681 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
71dfc51f | 7682 | ; |
4edb7b60 JM |
7683 | else if (declaration) |
7684 | gen_formal_types_die (TREE_TYPE (decl), subr_die); | |
a3f97cbb JW |
7685 | else |
7686 | { | |
7687 | /* Generate DIEs to represent all known formal parameters */ | |
7688 | register tree arg_decls = DECL_ARGUMENTS (decl); | |
7689 | register tree parm; | |
7690 | ||
7691 | /* When generating DIEs, generate the unspecified_parameters DIE | |
7692 | instead if we come across the arg "__builtin_va_alist" */ | |
7693 | for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) | |
71dfc51f RK |
7694 | if (TREE_CODE (parm) == PARM_DECL) |
7695 | { | |
db3cf6fb MS |
7696 | if (DECL_NAME (parm) |
7697 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), | |
7698 | "__builtin_va_alist")) | |
71dfc51f RK |
7699 | gen_unspecified_parameters_die (parm, subr_die); |
7700 | else | |
7701 | gen_decl_die (parm, subr_die); | |
7702 | } | |
a3f97cbb JW |
7703 | |
7704 | /* Decide whether we need a unspecified_parameters DIE at the end. | |
7705 | There are 2 more cases to do this for: 1) the ansi ... declaration - | |
7706 | this is detectable when the end of the arg list is not a | |
7707 | void_type_node 2) an unprototyped function declaration (not a | |
7708 | definition). This just means that we have no info about the | |
7709 | parameters at all. */ | |
7710 | fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); | |
71dfc51f | 7711 | if (fn_arg_types != NULL) |
a3f97cbb JW |
7712 | { |
7713 | /* this is the prototyped case, check for ... */ | |
7714 | if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) | |
71dfc51f | 7715 | gen_unspecified_parameters_die (decl, subr_die); |
a3f97cbb | 7716 | } |
71dfc51f RK |
7717 | else if (DECL_INITIAL (decl) == NULL_TREE) |
7718 | gen_unspecified_parameters_die (decl, subr_die); | |
a3f97cbb JW |
7719 | } |
7720 | ||
7721 | /* Output Dwarf info for all of the stuff within the body of the function | |
7722 | (if it has one - it may be just a declaration). */ | |
7723 | outer_scope = DECL_INITIAL (decl); | |
7724 | ||
d7248bff JM |
7725 | /* Note that here, `outer_scope' is a pointer to the outermost BLOCK |
7726 | node created to represent a function. This outermost BLOCK actually | |
7727 | represents the outermost binding contour for the function, i.e. the | |
7728 | contour in which the function's formal parameters and labels get | |
7729 | declared. Curiously, it appears that the front end doesn't actually | |
7730 | put the PARM_DECL nodes for the current function onto the BLOCK_VARS | |
7731 | list for this outer scope. (They are strung off of the DECL_ARGUMENTS | |
7732 | list for the function instead.) The BLOCK_VARS list for the | |
7733 | `outer_scope' does provide us with a list of the LABEL_DECL nodes for | |
7734 | the function however, and we output DWARF info for those in | |
7735 | decls_for_scope. Just within the `outer_scope' there will be a BLOCK | |
7736 | node representing the function's outermost pair of curly braces, and | |
7737 | any blocks used for the base and member initializers of a C++ | |
7738 | constructor function. */ | |
4edb7b60 | 7739 | if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK) |
7e23cb16 JM |
7740 | { |
7741 | current_function_has_inlines = 0; | |
7742 | decls_for_scope (outer_scope, subr_die, 0); | |
71dfc51f | 7743 | |
ce61cc73 | 7744 | #if 0 && defined (MIPS_DEBUGGING_INFO) |
7e23cb16 JM |
7745 | if (current_function_has_inlines) |
7746 | { | |
7747 | add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1); | |
7748 | if (! comp_unit_has_inlines) | |
7749 | { | |
7750 | add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1); | |
7751 | comp_unit_has_inlines = 1; | |
7752 | } | |
7753 | } | |
7754 | #endif | |
7755 | } | |
71dfc51f | 7756 | |
ab72d377 | 7757 | pop_decl_scope (); |
a3f97cbb JW |
7758 | } |
7759 | ||
7760 | /* Generate a DIE to represent a declared data object. */ | |
71dfc51f | 7761 | |
a3f97cbb JW |
7762 | static void |
7763 | gen_variable_die (decl, context_die) | |
7764 | register tree decl; | |
7765 | register dw_die_ref context_die; | |
7766 | { | |
7767 | register tree origin = decl_ultimate_origin (decl); | |
7768 | register dw_die_ref var_die = new_die (DW_TAG_variable, context_die); | |
71dfc51f | 7769 | |
bdb669cb | 7770 | dw_die_ref old_die = lookup_decl_die (decl); |
4edb7b60 JM |
7771 | int declaration |
7772 | = (DECL_EXTERNAL (decl) | |
a94dbf2c JM |
7773 | || current_function_decl != decl_function_context (decl) |
7774 | || context_die->die_tag == DW_TAG_structure_type | |
7775 | || context_die->die_tag == DW_TAG_union_type); | |
4edb7b60 | 7776 | |
a3f97cbb | 7777 | if (origin != NULL) |
71dfc51f | 7778 | add_abstract_origin_attribute (var_die, origin); |
f76b8156 JW |
7779 | /* Loop unrolling can create multiple blocks that refer to the same |
7780 | static variable, so we must test for the DW_AT_declaration flag. */ | |
7781 | /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to | |
7782 | copy decls and set the DECL_ABSTRACT flag on them instead of | |
7783 | sharing them. */ | |
7784 | else if (old_die && TREE_STATIC (decl) | |
7785 | && get_AT_flag (old_die, DW_AT_declaration) == 1) | |
bdb669cb | 7786 | { |
f76b8156 | 7787 | /* ??? This is an instantiation of a C++ class level static. */ |
bdb669cb JM |
7788 | add_AT_die_ref (var_die, DW_AT_specification, old_die); |
7789 | if (DECL_NAME (decl)) | |
7790 | { | |
7791 | register unsigned file_index | |
7792 | = lookup_filename (DECL_SOURCE_FILE (decl)); | |
71dfc51f | 7793 | |
bdb669cb JM |
7794 | if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) |
7795 | add_AT_unsigned (var_die, DW_AT_decl_file, file_index); | |
71dfc51f | 7796 | |
bdb669cb JM |
7797 | if (get_AT_unsigned (old_die, DW_AT_decl_line) |
7798 | != DECL_SOURCE_LINE (decl)) | |
71dfc51f RK |
7799 | |
7800 | add_AT_unsigned (var_die, DW_AT_decl_line, | |
7801 | DECL_SOURCE_LINE (decl)); | |
bdb669cb JM |
7802 | } |
7803 | } | |
a3f97cbb JW |
7804 | else |
7805 | { | |
7806 | add_name_and_src_coords_attributes (var_die, decl); | |
a3f97cbb JW |
7807 | add_type_attribute (var_die, TREE_TYPE (decl), |
7808 | TREE_READONLY (decl), | |
7809 | TREE_THIS_VOLATILE (decl), context_die); | |
71dfc51f | 7810 | |
273dbe67 JM |
7811 | if (TREE_PUBLIC (decl)) |
7812 | add_AT_flag (var_die, DW_AT_external, 1); | |
71dfc51f | 7813 | |
273dbe67 JM |
7814 | if (DECL_ARTIFICIAL (decl)) |
7815 | add_AT_flag (var_die, DW_AT_artificial, 1); | |
71dfc51f | 7816 | |
a94dbf2c JM |
7817 | if (TREE_PROTECTED (decl)) |
7818 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected); | |
71dfc51f | 7819 | |
a94dbf2c JM |
7820 | else if (TREE_PRIVATE (decl)) |
7821 | add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb | 7822 | } |
4edb7b60 JM |
7823 | |
7824 | if (declaration) | |
7825 | add_AT_flag (var_die, DW_AT_declaration, 1); | |
7826 | ||
7827 | if ((declaration && decl_class_context (decl)) || DECL_ABSTRACT (decl)) | |
7828 | equate_decl_number_to_die (decl, var_die); | |
7829 | ||
7830 | if (! declaration && ! DECL_ABSTRACT (decl)) | |
a3f97cbb | 7831 | { |
141719a8 | 7832 | equate_decl_number_to_die (decl, var_die); |
a3f97cbb | 7833 | add_location_or_const_value_attribute (var_die, decl); |
d291dd49 | 7834 | add_pubname (decl, var_die); |
a3f97cbb JW |
7835 | } |
7836 | } | |
7837 | ||
7838 | /* Generate a DIE to represent a label identifier. */ | |
71dfc51f | 7839 | |
a3f97cbb JW |
7840 | static void |
7841 | gen_label_die (decl, context_die) | |
7842 | register tree decl; | |
7843 | register dw_die_ref context_die; | |
7844 | { | |
7845 | register tree origin = decl_ultimate_origin (decl); | |
7846 | register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die); | |
7847 | register rtx insn; | |
7848 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5c90448c | 7849 | char label2[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 7850 | |
a3f97cbb | 7851 | if (origin != NULL) |
71dfc51f | 7852 | add_abstract_origin_attribute (lbl_die, origin); |
a3f97cbb | 7853 | else |
71dfc51f RK |
7854 | add_name_and_src_coords_attributes (lbl_die, decl); |
7855 | ||
a3f97cbb | 7856 | if (DECL_ABSTRACT (decl)) |
71dfc51f | 7857 | equate_decl_number_to_die (decl, lbl_die); |
a3f97cbb JW |
7858 | else |
7859 | { | |
7860 | insn = DECL_RTL (decl); | |
7861 | if (GET_CODE (insn) == CODE_LABEL) | |
7862 | { | |
7863 | /* When optimization is enabled (via -O) some parts of the compiler | |
7864 | (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which | |
7865 | represent source-level labels which were explicitly declared by | |
7866 | the user. This really shouldn't be happening though, so catch | |
7867 | it if it ever does happen. */ | |
7868 | if (INSN_DELETED_P (insn)) | |
71dfc51f RK |
7869 | abort (); |
7870 | ||
5c90448c JM |
7871 | sprintf (label2, INSN_LABEL_FMT, current_funcdef_number); |
7872 | ASM_GENERATE_INTERNAL_LABEL (label, label2, | |
7873 | (unsigned) INSN_UID (insn)); | |
a3f97cbb JW |
7874 | add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); |
7875 | } | |
7876 | } | |
7877 | } | |
7878 | ||
7879 | /* Generate a DIE for a lexical block. */ | |
71dfc51f | 7880 | |
a3f97cbb | 7881 | static void |
d7248bff | 7882 | gen_lexical_block_die (stmt, context_die, depth) |
a3f97cbb JW |
7883 | register tree stmt; |
7884 | register dw_die_ref context_die; | |
d7248bff | 7885 | int depth; |
a3f97cbb JW |
7886 | { |
7887 | register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die); | |
7888 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
71dfc51f RK |
7889 | |
7890 | if (! BLOCK_ABSTRACT (stmt)) | |
a3f97cbb | 7891 | { |
5c90448c JM |
7892 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
7893 | next_block_number); | |
a3f97cbb | 7894 | add_AT_lbl_id (stmt_die, DW_AT_low_pc, label); |
5c90448c | 7895 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number); |
a3f97cbb JW |
7896 | add_AT_lbl_id (stmt_die, DW_AT_high_pc, label); |
7897 | } | |
71dfc51f | 7898 | |
7d4440be | 7899 | push_decl_scope (stmt); |
d7248bff | 7900 | decls_for_scope (stmt, stmt_die, depth); |
7d4440be | 7901 | pop_decl_scope (); |
a3f97cbb JW |
7902 | } |
7903 | ||
7904 | /* Generate a DIE for an inlined subprogram. */ | |
71dfc51f | 7905 | |
a3f97cbb | 7906 | static void |
d7248bff | 7907 | gen_inlined_subroutine_die (stmt, context_die, depth) |
a3f97cbb JW |
7908 | register tree stmt; |
7909 | register dw_die_ref context_die; | |
d7248bff | 7910 | int depth; |
a3f97cbb | 7911 | { |
71dfc51f | 7912 | if (! BLOCK_ABSTRACT (stmt)) |
a3f97cbb | 7913 | { |
71dfc51f RK |
7914 | register dw_die_ref subr_die |
7915 | = new_die (DW_TAG_inlined_subroutine, context_die); | |
ab72d377 | 7916 | register tree decl = block_ultimate_origin (stmt); |
d7248bff | 7917 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
71dfc51f | 7918 | |
ab72d377 | 7919 | add_abstract_origin_attribute (subr_die, decl); |
5c90448c JM |
7920 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, |
7921 | next_block_number); | |
a3f97cbb | 7922 | add_AT_lbl_id (subr_die, DW_AT_low_pc, label); |
5c90448c | 7923 | ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number); |
a3f97cbb | 7924 | add_AT_lbl_id (subr_die, DW_AT_high_pc, label); |
ab72d377 | 7925 | push_decl_scope (decl); |
d7248bff | 7926 | decls_for_scope (stmt, subr_die, depth); |
ab72d377 | 7927 | pop_decl_scope (); |
7e23cb16 | 7928 | current_function_has_inlines = 1; |
a3f97cbb | 7929 | } |
a3f97cbb JW |
7930 | } |
7931 | ||
7932 | /* Generate a DIE for a field in a record, or structure. */ | |
71dfc51f | 7933 | |
a3f97cbb JW |
7934 | static void |
7935 | gen_field_die (decl, context_die) | |
7936 | register tree decl; | |
7937 | register dw_die_ref context_die; | |
7938 | { | |
7939 | register dw_die_ref decl_die = new_die (DW_TAG_member, context_die); | |
71dfc51f | 7940 | |
a3f97cbb | 7941 | add_name_and_src_coords_attributes (decl_die, decl); |
a3f97cbb JW |
7942 | add_type_attribute (decl_die, member_declared_type (decl), |
7943 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl), | |
7944 | context_die); | |
71dfc51f | 7945 | |
a3f97cbb JW |
7946 | /* If this is a bit field... */ |
7947 | if (DECL_BIT_FIELD_TYPE (decl)) | |
7948 | { | |
7949 | add_byte_size_attribute (decl_die, decl); | |
7950 | add_bit_size_attribute (decl_die, decl); | |
7951 | add_bit_offset_attribute (decl_die, decl); | |
7952 | } | |
71dfc51f | 7953 | |
a94dbf2c JM |
7954 | if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE) |
7955 | add_data_member_location_attribute (decl_die, decl); | |
71dfc51f | 7956 | |
273dbe67 JM |
7957 | if (DECL_ARTIFICIAL (decl)) |
7958 | add_AT_flag (decl_die, DW_AT_artificial, 1); | |
71dfc51f | 7959 | |
a94dbf2c JM |
7960 | if (TREE_PROTECTED (decl)) |
7961 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected); | |
71dfc51f | 7962 | |
a94dbf2c JM |
7963 | else if (TREE_PRIVATE (decl)) |
7964 | add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private); | |
a3f97cbb JW |
7965 | } |
7966 | ||
ab72d377 JM |
7967 | #if 0 |
7968 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. | |
7969 | Use modified_type_die instead. | |
a3f97cbb JW |
7970 | We keep this code here just in case these types of DIEs may be needed to |
7971 | represent certain things in other languages (e.g. Pascal) someday. */ | |
7972 | static void | |
7973 | gen_pointer_type_die (type, context_die) | |
7974 | register tree type; | |
7975 | register dw_die_ref context_die; | |
7976 | { | |
71dfc51f RK |
7977 | register dw_die_ref ptr_die |
7978 | = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die)); | |
7979 | ||
a3f97cbb | 7980 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 7981 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 7982 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb JW |
7983 | } |
7984 | ||
ab72d377 JM |
7985 | /* Don't generate either pointer_type DIEs or reference_type DIEs here. |
7986 | Use modified_type_die instead. | |
a3f97cbb JW |
7987 | We keep this code here just in case these types of DIEs may be needed to |
7988 | represent certain things in other languages (e.g. Pascal) someday. */ | |
7989 | static void | |
7990 | gen_reference_type_die (type, context_die) | |
7991 | register tree type; | |
7992 | register dw_die_ref context_die; | |
7993 | { | |
71dfc51f RK |
7994 | register dw_die_ref ref_die |
7995 | = new_die (DW_TAG_reference_type, scope_die_for (type, context_die)); | |
7996 | ||
a3f97cbb | 7997 | equate_type_number_to_die (type, ref_die); |
a3f97cbb | 7998 | add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die); |
ab72d377 | 7999 | add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); |
a3f97cbb | 8000 | } |
ab72d377 | 8001 | #endif |
a3f97cbb JW |
8002 | |
8003 | /* Generate a DIE for a pointer to a member type. */ | |
8004 | static void | |
8005 | gen_ptr_to_mbr_type_die (type, context_die) | |
8006 | register tree type; | |
8007 | register dw_die_ref context_die; | |
8008 | { | |
71dfc51f RK |
8009 | register dw_die_ref ptr_die |
8010 | = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die)); | |
8011 | ||
a3f97cbb | 8012 | equate_type_number_to_die (type, ptr_die); |
a3f97cbb | 8013 | add_AT_die_ref (ptr_die, DW_AT_containing_type, |
bdb669cb | 8014 | lookup_type_die (TYPE_OFFSET_BASETYPE (type))); |
a3f97cbb JW |
8015 | add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); |
8016 | } | |
8017 | ||
8018 | /* Generate the DIE for the compilation unit. */ | |
71dfc51f | 8019 | |
a3f97cbb JW |
8020 | static void |
8021 | gen_compile_unit_die (main_input_filename) | |
8022 | register char *main_input_filename; | |
8023 | { | |
8024 | char producer[250]; | |
a3f97cbb JW |
8025 | char *wd = getpwd (); |
8026 | ||
8027 | comp_unit_die = new_die (DW_TAG_compile_unit, NULL); | |
bdb669cb JM |
8028 | add_name_attribute (comp_unit_die, main_input_filename); |
8029 | ||
71dfc51f RK |
8030 | if (wd != NULL) |
8031 | add_AT_string (comp_unit_die, DW_AT_comp_dir, wd); | |
a3f97cbb JW |
8032 | |
8033 | sprintf (producer, "%s %s", language_string, version_string); | |
8034 | ||
8035 | #ifdef MIPS_DEBUGGING_INFO | |
8036 | /* The MIPS/SGI compilers place the 'cc' command line options in the producer | |
8037 | string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do | |
8038 | not appear in the producer string, the debugger reaches the conclusion | |
8039 | that the object file is stripped and has no debugging information. | |
8040 | To get the MIPS/SGI debugger to believe that there is debugging | |
8041 | information in the object file, we add a -g to the producer string. */ | |
4927276d JM |
8042 | if (debug_info_level > DINFO_LEVEL_TERSE) |
8043 | strcat (producer, " -g"); | |
a3f97cbb JW |
8044 | #endif |
8045 | ||
8046 | add_AT_string (comp_unit_die, DW_AT_producer, producer); | |
a9d38797 | 8047 | |
a3f97cbb | 8048 | if (strcmp (language_string, "GNU C++") == 0) |
a9d38797 | 8049 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus); |
71dfc51f | 8050 | |
a3f97cbb | 8051 | else if (strcmp (language_string, "GNU Ada") == 0) |
a9d38797 | 8052 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83); |
71dfc51f | 8053 | |
a9d38797 JM |
8054 | else if (strcmp (language_string, "GNU F77") == 0) |
8055 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Fortran77); | |
71dfc51f | 8056 | |
a3f97cbb | 8057 | else if (flag_traditional) |
a9d38797 | 8058 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C); |
71dfc51f | 8059 | |
a3f97cbb | 8060 | else |
a9d38797 JM |
8061 | add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89); |
8062 | ||
8063 | #if 0 /* unimplemented */ | |
e90b62db | 8064 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) |
a9d38797 JM |
8065 | add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0); |
8066 | #endif | |
a3f97cbb JW |
8067 | } |
8068 | ||
8069 | /* Generate a DIE for a string type. */ | |
71dfc51f | 8070 | |
a3f97cbb JW |
8071 | static void |
8072 | gen_string_type_die (type, context_die) | |
8073 | register tree type; | |
8074 | register dw_die_ref context_die; | |
8075 | { | |
71dfc51f RK |
8076 | register dw_die_ref type_die |
8077 | = new_die (DW_TAG_string_type, scope_die_for (type, context_die)); | |
8078 | ||
bdb669cb | 8079 | equate_type_number_to_die (type, type_die); |
a3f97cbb JW |
8080 | |
8081 | /* Fudge the string length attribute for now. */ | |
71dfc51f | 8082 | |
a3f97cbb | 8083 | /* TODO: add string length info. |
71dfc51f | 8084 | string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type))); |
a3f97cbb JW |
8085 | bound_representation (upper_bound, 0, 'u'); */ |
8086 | } | |
8087 | ||
61b32c02 | 8088 | /* Generate the DIE for a base class. */ |
71dfc51f | 8089 | |
61b32c02 JM |
8090 | static void |
8091 | gen_inheritance_die (binfo, context_die) | |
8092 | register tree binfo; | |
8093 | register dw_die_ref context_die; | |
8094 | { | |
8095 | dw_die_ref die = new_die (DW_TAG_inheritance, context_die); | |
71dfc51f | 8096 | |
61b32c02 JM |
8097 | add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die); |
8098 | add_data_member_location_attribute (die, binfo); | |
71dfc51f | 8099 | |
61b32c02 JM |
8100 | if (TREE_VIA_VIRTUAL (binfo)) |
8101 | add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); | |
8102 | if (TREE_VIA_PUBLIC (binfo)) | |
8103 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public); | |
8104 | else if (TREE_VIA_PROTECTED (binfo)) | |
8105 | add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected); | |
8106 | } | |
8107 | ||
a3f97cbb | 8108 | /* Genearate a DIE for a class member. */ |
71dfc51f | 8109 | |
a3f97cbb JW |
8110 | static void |
8111 | gen_member_die (type, context_die) | |
8112 | register tree type; | |
8113 | register dw_die_ref context_die; | |
8114 | { | |
61b32c02 | 8115 | register tree member; |
71dfc51f | 8116 | |
a3f97cbb JW |
8117 | /* If this is not an incomplete type, output descriptions of each of its |
8118 | members. Note that as we output the DIEs necessary to represent the | |
8119 | members of this record or union type, we will also be trying to output | |
8120 | DIEs to represent the *types* of those members. However the `type' | |
8121 | function (above) will specifically avoid generating type DIEs for member | |
8122 | types *within* the list of member DIEs for this (containing) type execpt | |
8123 | for those types (of members) which are explicitly marked as also being | |
8124 | members of this (containing) type themselves. The g++ front- end can | |
8125 | force any given type to be treated as a member of some other | |
8126 | (containing) type by setting the TYPE_CONTEXT of the given (member) type | |
8127 | to point to the TREE node representing the appropriate (containing) | |
8128 | type. */ | |
8129 | ||
61b32c02 JM |
8130 | /* First output info about the base classes. */ |
8131 | if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type)) | |
a3f97cbb | 8132 | { |
61b32c02 JM |
8133 | register tree bases = TYPE_BINFO_BASETYPES (type); |
8134 | register int n_bases = TREE_VEC_LENGTH (bases); | |
8135 | register int i; | |
8136 | ||
8137 | for (i = 0; i < n_bases; i++) | |
8138 | gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die); | |
a3f97cbb JW |
8139 | } |
8140 | ||
61b32c02 JM |
8141 | /* Now output info about the data members and type members. */ |
8142 | for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member)) | |
8143 | gen_decl_die (member, context_die); | |
8144 | ||
a3f97cbb | 8145 | /* Now output info about the function members (if any). */ |
61b32c02 JM |
8146 | for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member)) |
8147 | gen_decl_die (member, context_die); | |
a3f97cbb JW |
8148 | } |
8149 | ||
8150 | /* Generate a DIE for a structure or union type. */ | |
71dfc51f | 8151 | |
a3f97cbb | 8152 | static void |
273dbe67 | 8153 | gen_struct_or_union_type_die (type, context_die) |
a3f97cbb | 8154 | register tree type; |
a3f97cbb JW |
8155 | register dw_die_ref context_die; |
8156 | { | |
273dbe67 | 8157 | register dw_die_ref type_die = lookup_type_die (type); |
a082c85a JM |
8158 | register dw_die_ref scope_die = 0; |
8159 | register int nested = 0; | |
273dbe67 JM |
8160 | |
8161 | if (type_die && ! TYPE_SIZE (type)) | |
8162 | return; | |
a082c85a | 8163 | |
71dfc51f | 8164 | if (TYPE_CONTEXT (type) != NULL_TREE |
a082c85a JM |
8165 | && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't') |
8166 | nested = 1; | |
8167 | ||
a94dbf2c | 8168 | scope_die = scope_die_for (type, context_die); |
a082c85a JM |
8169 | |
8170 | if (! type_die || (nested && scope_die == comp_unit_die)) | |
273dbe67 | 8171 | /* First occurrence of type or toplevel definition of nested class. */ |
a3f97cbb | 8172 | { |
273dbe67 | 8173 | register dw_die_ref old_die = type_die; |
71dfc51f | 8174 | |
a3f97cbb JW |
8175 | type_die = new_die (TREE_CODE (type) == RECORD_TYPE |
8176 | ? DW_TAG_structure_type : DW_TAG_union_type, | |
a082c85a | 8177 | scope_die); |
a3f97cbb JW |
8178 | equate_type_number_to_die (type, type_die); |
8179 | add_name_attribute (type_die, type_tag (type)); | |
273dbe67 JM |
8180 | if (old_die) |
8181 | add_AT_die_ref (type_die, DW_AT_specification, old_die); | |
a3f97cbb | 8182 | } |
4b674448 | 8183 | else |
273dbe67 | 8184 | remove_AT (type_die, DW_AT_declaration); |
a3f97cbb | 8185 | |
a94dbf2c JM |
8186 | /* If we're not in the right context to be defining this type, defer to |
8187 | avoid tricky recursion. */ | |
8188 | if (TYPE_SIZE (type) && decl_scope_depth > 0 && scope_die == comp_unit_die) | |
8189 | { | |
8190 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
8191 | pend_type (type); | |
8192 | } | |
a3f97cbb JW |
8193 | /* If this type has been completed, then give it a byte_size attribute and |
8194 | then give a list of members. */ | |
a94dbf2c | 8195 | else if (TYPE_SIZE (type)) |
a3f97cbb JW |
8196 | { |
8197 | /* Prevent infinite recursion in cases where the type of some member of | |
8198 | this type is expressed in terms of this type itself. */ | |
8199 | TREE_ASM_WRITTEN (type) = 1; | |
273dbe67 | 8200 | add_byte_size_attribute (type_die, type); |
b2932ae5 JM |
8201 | if (type_tag (type)) |
8202 | add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); | |
71dfc51f | 8203 | |
ef76d03b JW |
8204 | /* If the first reference to this type was as the return type of an |
8205 | inline function, then it may not have a parent. Fix this now. */ | |
8206 | if (type_die->die_parent == NULL) | |
8207 | add_child_die (scope_die, type_die); | |
8208 | ||
273dbe67 JM |
8209 | push_decl_scope (type); |
8210 | gen_member_die (type, type_die); | |
8211 | pop_decl_scope (); | |
71dfc51f | 8212 | |
a94dbf2c JM |
8213 | /* GNU extension: Record what type our vtable lives in. */ |
8214 | if (TYPE_VFIELD (type)) | |
8215 | { | |
8216 | tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type)); | |
71dfc51f | 8217 | |
a94dbf2c JM |
8218 | gen_type_die (vtype, context_die); |
8219 | add_AT_die_ref (type_die, DW_AT_containing_type, | |
8220 | lookup_type_die (vtype)); | |
8221 | } | |
a3f97cbb | 8222 | } |
4b674448 JM |
8223 | else |
8224 | add_AT_flag (type_die, DW_AT_declaration, 1); | |
a3f97cbb JW |
8225 | } |
8226 | ||
8227 | /* Generate a DIE for a subroutine _type_. */ | |
71dfc51f | 8228 | |
a3f97cbb JW |
8229 | static void |
8230 | gen_subroutine_type_die (type, context_die) | |
8231 | register tree type; | |
8232 | register dw_die_ref context_die; | |
8233 | { | |
8234 | register tree return_type = TREE_TYPE (type); | |
71dfc51f RK |
8235 | register dw_die_ref subr_die |
8236 | = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die)); | |
8237 | ||
a3f97cbb JW |
8238 | equate_type_number_to_die (type, subr_die); |
8239 | add_prototyped_attribute (subr_die, type); | |
a3f97cbb | 8240 | add_type_attribute (subr_die, return_type, 0, 0, context_die); |
a94dbf2c | 8241 | gen_formal_types_die (type, subr_die); |
a3f97cbb JW |
8242 | } |
8243 | ||
8244 | /* Generate a DIE for a type definition */ | |
71dfc51f | 8245 | |
a3f97cbb JW |
8246 | static void |
8247 | gen_typedef_die (decl, context_die) | |
8248 | register tree decl; | |
8249 | register dw_die_ref context_die; | |
8250 | { | |
a3f97cbb | 8251 | register dw_die_ref type_die; |
a94dbf2c JM |
8252 | register tree origin; |
8253 | ||
8254 | if (TREE_ASM_WRITTEN (decl)) | |
8255 | return; | |
8256 | TREE_ASM_WRITTEN (decl) = 1; | |
8257 | ||
ab72d377 | 8258 | type_die = new_die (DW_TAG_typedef, scope_die_for (decl, context_die)); |
a94dbf2c | 8259 | origin = decl_ultimate_origin (decl); |
a3f97cbb | 8260 | if (origin != NULL) |
a94dbf2c | 8261 | add_abstract_origin_attribute (type_die, origin); |
a3f97cbb JW |
8262 | else |
8263 | { | |
a94dbf2c | 8264 | register tree type; |
a3f97cbb | 8265 | add_name_and_src_coords_attributes (type_die, decl); |
a94dbf2c JM |
8266 | if (DECL_ORIGINAL_TYPE (decl)) |
8267 | { | |
8268 | type = DECL_ORIGINAL_TYPE (decl); | |
8269 | equate_type_number_to_die (TREE_TYPE (decl), type_die); | |
8270 | } | |
8271 | else | |
8272 | type = TREE_TYPE (decl); | |
8273 | add_type_attribute (type_die, type, TREE_READONLY (decl), | |
8274 | TREE_THIS_VOLATILE (decl), context_die); | |
a3f97cbb | 8275 | } |
71dfc51f | 8276 | |
a3f97cbb | 8277 | if (DECL_ABSTRACT (decl)) |
a94dbf2c | 8278 | equate_decl_number_to_die (decl, type_die); |
a3f97cbb JW |
8279 | } |
8280 | ||
8281 | /* Generate a type description DIE. */ | |
71dfc51f | 8282 | |
a3f97cbb JW |
8283 | static void |
8284 | gen_type_die (type, context_die) | |
8285 | register tree type; | |
8286 | register dw_die_ref context_die; | |
8287 | { | |
71dfc51f RK |
8288 | if (type == NULL_TREE || type == error_mark_node) |
8289 | return; | |
a3f97cbb JW |
8290 | |
8291 | /* We are going to output a DIE to represent the unqualified version of of | |
8292 | this type (i.e. without any const or volatile qualifiers) so get the | |
8293 | main variant (i.e. the unqualified version) of this type now. */ | |
8294 | type = type_main_variant (type); | |
8295 | ||
8296 | if (TREE_ASM_WRITTEN (type)) | |
71dfc51f | 8297 | return; |
a3f97cbb | 8298 | |
a94dbf2c JM |
8299 | if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
8300 | && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) | |
8301 | { | |
8302 | TREE_ASM_WRITTEN (type) = 1; | |
8303 | gen_decl_die (TYPE_NAME (type), context_die); | |
8304 | return; | |
8305 | } | |
8306 | ||
a3f97cbb JW |
8307 | switch (TREE_CODE (type)) |
8308 | { | |
8309 | case ERROR_MARK: | |
8310 | break; | |
8311 | ||
8312 | case POINTER_TYPE: | |
8313 | case REFERENCE_TYPE: | |
8314 | /* For these types, all that is required is that we output a DIE (or a | |
8315 | set of DIEs) to represent the "basis" type. */ | |
8316 | gen_type_die (TREE_TYPE (type), context_die); | |
8317 | break; | |
8318 | ||
8319 | case OFFSET_TYPE: | |
71dfc51f RK |
8320 | /* This code is used for C++ pointer-to-data-member types. |
8321 | Output a description of the relevant class type. */ | |
a3f97cbb | 8322 | gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die); |
71dfc51f | 8323 | |
a3f97cbb JW |
8324 | /* Output a description of the type of the object pointed to. */ |
8325 | gen_type_die (TREE_TYPE (type), context_die); | |
71dfc51f | 8326 | |
a3f97cbb JW |
8327 | /* Now output a DIE to represent this pointer-to-data-member type |
8328 | itself. */ | |
8329 | gen_ptr_to_mbr_type_die (type, context_die); | |
8330 | break; | |
8331 | ||
8332 | case SET_TYPE: | |
8333 | gen_type_die (TYPE_DOMAIN (type), context_die); | |
8334 | gen_set_type_die (type, context_die); | |
8335 | break; | |
8336 | ||
8337 | case FILE_TYPE: | |
8338 | gen_type_die (TREE_TYPE (type), context_die); | |
8339 | abort (); /* No way to represent these in Dwarf yet! */ | |
8340 | break; | |
8341 | ||
8342 | case FUNCTION_TYPE: | |
8343 | /* Force out return type (in case it wasn't forced out already). */ | |
8344 | gen_type_die (TREE_TYPE (type), context_die); | |
8345 | gen_subroutine_type_die (type, context_die); | |
8346 | break; | |
8347 | ||
8348 | case METHOD_TYPE: | |
8349 | /* Force out return type (in case it wasn't forced out already). */ | |
8350 | gen_type_die (TREE_TYPE (type), context_die); | |
8351 | gen_subroutine_type_die (type, context_die); | |
8352 | break; | |
8353 | ||
8354 | case ARRAY_TYPE: | |
8355 | if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE) | |
8356 | { | |
8357 | gen_type_die (TREE_TYPE (type), context_die); | |
8358 | gen_string_type_die (type, context_die); | |
8359 | } | |
8360 | else | |
71dfc51f | 8361 | gen_array_type_die (type, context_die); |
a3f97cbb JW |
8362 | break; |
8363 | ||
8364 | case ENUMERAL_TYPE: | |
8365 | case RECORD_TYPE: | |
8366 | case UNION_TYPE: | |
8367 | case QUAL_UNION_TYPE: | |
a082c85a JM |
8368 | /* If this is a nested type whose containing class hasn't been |
8369 | written out yet, writing it out will cover this one, too. */ | |
8370 | if (TYPE_CONTEXT (type) | |
8371 | && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't' | |
8372 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) | |
a94dbf2c JM |
8373 | { |
8374 | gen_type_die (TYPE_CONTEXT (type), context_die); | |
8375 | ||
8376 | if (TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) | |
8377 | return; | |
8378 | ||
8379 | /* If that failed, attach ourselves to the stub. */ | |
8380 | push_decl_scope (TYPE_CONTEXT (type)); | |
8381 | context_die = lookup_type_die (TYPE_CONTEXT (type)); | |
8382 | } | |
8383 | ||
8384 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
273dbe67 | 8385 | gen_enumeration_type_die (type, context_die); |
a3f97cbb | 8386 | else |
273dbe67 | 8387 | gen_struct_or_union_type_die (type, context_die); |
4b674448 | 8388 | |
a94dbf2c JM |
8389 | if (TYPE_CONTEXT (type) |
8390 | && TREE_CODE_CLASS (TREE_CODE (TYPE_CONTEXT (type))) == 't' | |
8391 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) | |
8392 | pop_decl_scope (); | |
8393 | ||
4b674448 | 8394 | /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix |
a082c85a JM |
8395 | it up if it is ever completed. gen_*_type_die will set it for us |
8396 | when appropriate. */ | |
8397 | return; | |
a3f97cbb JW |
8398 | |
8399 | case VOID_TYPE: | |
8400 | case INTEGER_TYPE: | |
8401 | case REAL_TYPE: | |
8402 | case COMPLEX_TYPE: | |
8403 | case BOOLEAN_TYPE: | |
8404 | case CHAR_TYPE: | |
8405 | /* No DIEs needed for fundamental types. */ | |
8406 | break; | |
8407 | ||
8408 | case LANG_TYPE: | |
8409 | /* No Dwarf representation currently defined. */ | |
8410 | break; | |
8411 | ||
8412 | default: | |
8413 | abort (); | |
8414 | } | |
8415 | ||
8416 | TREE_ASM_WRITTEN (type) = 1; | |
8417 | } | |
8418 | ||
8419 | /* Generate a DIE for a tagged type instantiation. */ | |
71dfc51f | 8420 | |
a3f97cbb JW |
8421 | static void |
8422 | gen_tagged_type_instantiation_die (type, context_die) | |
8423 | register tree type; | |
8424 | register dw_die_ref context_die; | |
8425 | { | |
71dfc51f RK |
8426 | if (type == NULL_TREE || type == error_mark_node) |
8427 | return; | |
a3f97cbb JW |
8428 | |
8429 | /* We are going to output a DIE to represent the unqualified version of of | |
8430 | this type (i.e. without any const or volatile qualifiers) so make sure | |
8431 | that we have the main variant (i.e. the unqualified version) of this | |
8432 | type now. */ | |
8433 | assert (type == type_main_variant (type)); | |
8434 | assert (TREE_ASM_WRITTEN (type)); | |
8435 | ||
8436 | switch (TREE_CODE (type)) | |
8437 | { | |
8438 | case ERROR_MARK: | |
8439 | break; | |
8440 | ||
8441 | case ENUMERAL_TYPE: | |
8442 | gen_inlined_enumeration_type_die (type, context_die); | |
8443 | break; | |
8444 | ||
8445 | case RECORD_TYPE: | |
8446 | gen_inlined_structure_type_die (type, context_die); | |
8447 | break; | |
8448 | ||
8449 | case UNION_TYPE: | |
8450 | case QUAL_UNION_TYPE: | |
8451 | gen_inlined_union_type_die (type, context_die); | |
8452 | break; | |
8453 | ||
8454 | default: | |
71dfc51f | 8455 | abort (); |
a3f97cbb JW |
8456 | } |
8457 | } | |
8458 | ||
8459 | /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the | |
8460 | things which are local to the given block. */ | |
71dfc51f | 8461 | |
a3f97cbb | 8462 | static void |
d7248bff | 8463 | gen_block_die (stmt, context_die, depth) |
a3f97cbb JW |
8464 | register tree stmt; |
8465 | register dw_die_ref context_die; | |
d7248bff | 8466 | int depth; |
a3f97cbb JW |
8467 | { |
8468 | register int must_output_die = 0; | |
8469 | register tree origin; | |
8470 | register tree decl; | |
8471 | register enum tree_code origin_code; | |
8472 | ||
8473 | /* Ignore blocks never really used to make RTL. */ | |
8474 | ||
71dfc51f RK |
8475 | if (stmt == NULL_TREE || !TREE_USED (stmt)) |
8476 | return; | |
a3f97cbb JW |
8477 | |
8478 | /* Determine the "ultimate origin" of this block. This block may be an | |
8479 | inlined instance of an inlined instance of inline function, so we have | |
8480 | to trace all of the way back through the origin chain to find out what | |
8481 | sort of node actually served as the original seed for the creation of | |
8482 | the current block. */ | |
8483 | origin = block_ultimate_origin (stmt); | |
8484 | origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; | |
8485 | ||
8486 | /* Determine if we need to output any Dwarf DIEs at all to represent this | |
8487 | block. */ | |
8488 | if (origin_code == FUNCTION_DECL) | |
71dfc51f RK |
8489 | /* The outer scopes for inlinings *must* always be represented. We |
8490 | generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */ | |
8491 | must_output_die = 1; | |
a3f97cbb JW |
8492 | else |
8493 | { | |
8494 | /* In the case where the current block represents an inlining of the | |
8495 | "body block" of an inline function, we must *NOT* output any DIE for | |
8496 | this block because we have already output a DIE to represent the | |
8497 | whole inlined function scope and the "body block" of any function | |
8498 | doesn't really represent a different scope according to ANSI C | |
8499 | rules. So we check here to make sure that this block does not | |
8500 | represent a "body block inlining" before trying to set the | |
8501 | `must_output_die' flag. */ | |
d7248bff | 8502 | if (! is_body_block (origin ? origin : stmt)) |
a3f97cbb JW |
8503 | { |
8504 | /* Determine if this block directly contains any "significant" | |
8505 | local declarations which we will need to output DIEs for. */ | |
8506 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
71dfc51f RK |
8507 | /* We are not in terse mode so *any* local declaration counts |
8508 | as being a "significant" one. */ | |
8509 | must_output_die = (BLOCK_VARS (stmt) != NULL); | |
a3f97cbb | 8510 | else |
71dfc51f RK |
8511 | /* We are in terse mode, so only local (nested) function |
8512 | definitions count as "significant" local declarations. */ | |
8513 | for (decl = BLOCK_VARS (stmt); | |
8514 | decl != NULL; decl = TREE_CHAIN (decl)) | |
8515 | if (TREE_CODE (decl) == FUNCTION_DECL | |
8516 | && DECL_INITIAL (decl)) | |
a3f97cbb | 8517 | { |
71dfc51f RK |
8518 | must_output_die = 1; |
8519 | break; | |
a3f97cbb | 8520 | } |
a3f97cbb JW |
8521 | } |
8522 | } | |
8523 | ||
8524 | /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block | |
8525 | DIE for any block which contains no significant local declarations at | |
8526 | all. Rather, in such cases we just call `decls_for_scope' so that any | |
8527 | needed Dwarf info for any sub-blocks will get properly generated. Note | |
8528 | that in terse mode, our definition of what constitutes a "significant" | |
8529 | local declaration gets restricted to include only inlined function | |
8530 | instances and local (nested) function definitions. */ | |
8531 | if (must_output_die) | |
8532 | { | |
8533 | if (origin_code == FUNCTION_DECL) | |
71dfc51f | 8534 | gen_inlined_subroutine_die (stmt, context_die, depth); |
a3f97cbb | 8535 | else |
71dfc51f | 8536 | gen_lexical_block_die (stmt, context_die, depth); |
a3f97cbb JW |
8537 | } |
8538 | else | |
d7248bff | 8539 | decls_for_scope (stmt, context_die, depth); |
a3f97cbb JW |
8540 | } |
8541 | ||
8542 | /* Generate all of the decls declared within a given scope and (recursively) | |
8543 | all of it's sub-blocks. */ | |
71dfc51f | 8544 | |
a3f97cbb | 8545 | static void |
d7248bff | 8546 | decls_for_scope (stmt, context_die, depth) |
a3f97cbb JW |
8547 | register tree stmt; |
8548 | register dw_die_ref context_die; | |
d7248bff | 8549 | int depth; |
a3f97cbb JW |
8550 | { |
8551 | register tree decl; | |
8552 | register tree subblocks; | |
71dfc51f | 8553 | |
a3f97cbb | 8554 | /* Ignore blocks never really used to make RTL. */ |
71dfc51f RK |
8555 | if (stmt == NULL_TREE || ! TREE_USED (stmt)) |
8556 | return; | |
8557 | ||
d7248bff | 8558 | if (!BLOCK_ABSTRACT (stmt) && depth > 0) |
71dfc51f | 8559 | next_block_number++; |
a3f97cbb | 8560 | |
88dad228 JM |
8561 | /* Output the DIEs to represent all of the data objects and typedefs |
8562 | declared directly within this block but not within any nested | |
8563 | sub-blocks. Also, nested function and tag DIEs have been | |
8564 | generated with a parent of NULL; fix that up now. */ | |
a3f97cbb JW |
8565 | for (decl = BLOCK_VARS (stmt); |
8566 | decl != NULL; decl = TREE_CHAIN (decl)) | |
8567 | { | |
a94dbf2c JM |
8568 | register dw_die_ref die; |
8569 | ||
88dad228 | 8570 | if (TREE_CODE (decl) == FUNCTION_DECL) |
a94dbf2c | 8571 | die = lookup_decl_die (decl); |
88dad228 | 8572 | else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)) |
a94dbf2c JM |
8573 | die = lookup_type_die (TREE_TYPE (decl)); |
8574 | else | |
8575 | die = NULL; | |
8576 | ||
71dfc51f | 8577 | if (die != NULL && die->die_parent == NULL) |
ef76d03b | 8578 | add_child_die (context_die, die); |
88dad228 JM |
8579 | else |
8580 | gen_decl_die (decl, context_die); | |
a3f97cbb JW |
8581 | } |
8582 | ||
8583 | /* Output the DIEs to represent all sub-blocks (and the items declared | |
8584 | therein) of this block. */ | |
8585 | for (subblocks = BLOCK_SUBBLOCKS (stmt); | |
8586 | subblocks != NULL; | |
8587 | subblocks = BLOCK_CHAIN (subblocks)) | |
71dfc51f | 8588 | gen_block_die (subblocks, context_die, depth + 1); |
a3f97cbb JW |
8589 | } |
8590 | ||
a94dbf2c | 8591 | /* Is this a typedef we can avoid emitting? */ |
71dfc51f RK |
8592 | |
8593 | static inline int | |
a94dbf2c JM |
8594 | is_redundant_typedef (decl) |
8595 | register tree decl; | |
8596 | { | |
8597 | if (TYPE_DECL_IS_STUB (decl)) | |
8598 | return 1; | |
71dfc51f | 8599 | |
a94dbf2c JM |
8600 | if (DECL_ARTIFICIAL (decl) |
8601 | && DECL_CONTEXT (decl) | |
8602 | && is_tagged_type (DECL_CONTEXT (decl)) | |
8603 | && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL | |
8604 | && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) | |
8605 | /* Also ignore the artificial member typedef for the class name. */ | |
8606 | return 1; | |
71dfc51f | 8607 | |
a94dbf2c JM |
8608 | return 0; |
8609 | } | |
8610 | ||
a3f97cbb | 8611 | /* Generate Dwarf debug information for a decl described by DECL. */ |
71dfc51f | 8612 | |
a3f97cbb JW |
8613 | static void |
8614 | gen_decl_die (decl, context_die) | |
8615 | register tree decl; | |
8616 | register dw_die_ref context_die; | |
8617 | { | |
8618 | register tree origin; | |
71dfc51f | 8619 | |
a3f97cbb JW |
8620 | /* Make a note of the decl node we are going to be working on. We may need |
8621 | to give the user the source coordinates of where it appeared in case we | |
8622 | notice (later on) that something about it looks screwy. */ | |
8623 | dwarf_last_decl = decl; | |
8624 | ||
8625 | if (TREE_CODE (decl) == ERROR_MARK) | |
71dfc51f | 8626 | return; |
a3f97cbb JW |
8627 | |
8628 | /* If this ..._DECL node is marked to be ignored, then ignore it. But don't | |
8629 | ignore a function definition, since that would screw up our count of | |
8630 | blocks, and that it turn will completely screw up the the labels we will | |
8631 | reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for | |
8632 | subsequent blocks). */ | |
8633 | if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL) | |
71dfc51f | 8634 | return; |
a3f97cbb | 8635 | |
a3f97cbb JW |
8636 | switch (TREE_CODE (decl)) |
8637 | { | |
8638 | case CONST_DECL: | |
8639 | /* The individual enumerators of an enum type get output when we output | |
8640 | the Dwarf representation of the relevant enum type itself. */ | |
8641 | break; | |
8642 | ||
8643 | case FUNCTION_DECL: | |
4edb7b60 JM |
8644 | /* Don't output any DIEs to represent mere function declarations, |
8645 | unless they are class members or explicit block externs. */ | |
8646 | if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE | |
8647 | && (current_function_decl == NULL_TREE || ! DECL_ARTIFICIAL (decl))) | |
71dfc51f | 8648 | break; |
bdb669cb | 8649 | |
4927276d | 8650 | if (debug_info_level > DINFO_LEVEL_TERSE) |
a94dbf2c JM |
8651 | { |
8652 | /* Before we describe the FUNCTION_DECL itself, make sure that we | |
8653 | have described its return type. */ | |
8654 | gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); | |
8655 | ||
8656 | /* And its containing type. */ | |
8657 | origin = decl_class_context (decl); | |
71dfc51f | 8658 | if (origin != NULL_TREE) |
a94dbf2c JM |
8659 | gen_type_die (origin, context_die); |
8660 | ||
8661 | /* And its virtual context. */ | |
71dfc51f | 8662 | if (DECL_VINDEX (decl) != NULL_TREE) |
a94dbf2c JM |
8663 | gen_type_die (DECL_CONTEXT (decl), context_die); |
8664 | } | |
a3f97cbb JW |
8665 | |
8666 | /* Now output a DIE to represent the function itself. */ | |
8667 | gen_subprogram_die (decl, context_die); | |
8668 | break; | |
8669 | ||
8670 | case TYPE_DECL: | |
8671 | /* If we are in terse mode, don't generate any DIEs to represent any | |
4927276d | 8672 | actual typedefs. */ |
a3f97cbb | 8673 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 8674 | break; |
a3f97cbb | 8675 | |
5c90448c JM |
8676 | /* In the special case of a TYPE_DECL node representing the |
8677 | declaration of some type tag, if the given TYPE_DECL is marked as | |
a3f97cbb JW |
8678 | having been instantiated from some other (original) TYPE_DECL node |
8679 | (e.g. one which was generated within the original definition of an | |
8680 | inline function) we have to generate a special (abbreviated) | |
ef76d03b | 8681 | DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type |
a3f97cbb | 8682 | DIE here. */ |
71dfc51f | 8683 | if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE) |
a3f97cbb JW |
8684 | { |
8685 | gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die); | |
8686 | break; | |
8687 | } | |
a3f97cbb | 8688 | |
a94dbf2c JM |
8689 | if (is_redundant_typedef (decl)) |
8690 | gen_type_die (TREE_TYPE (decl), context_die); | |
8691 | else | |
71dfc51f RK |
8692 | /* Output a DIE to represent the typedef itself. */ |
8693 | gen_typedef_die (decl, context_die); | |
a3f97cbb JW |
8694 | break; |
8695 | ||
8696 | case LABEL_DECL: | |
8697 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
71dfc51f | 8698 | gen_label_die (decl, context_die); |
a3f97cbb JW |
8699 | break; |
8700 | ||
8701 | case VAR_DECL: | |
8702 | /* If we are in terse mode, don't generate any DIEs to represent any | |
8703 | variable declarations or definitions. */ | |
8704 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 8705 | break; |
a3f97cbb JW |
8706 | |
8707 | /* Output any DIEs that are needed to specify the type of this data | |
8708 | object. */ | |
8709 | gen_type_die (TREE_TYPE (decl), context_die); | |
8710 | ||
a94dbf2c JM |
8711 | /* And its containing type. */ |
8712 | origin = decl_class_context (decl); | |
71dfc51f | 8713 | if (origin != NULL_TREE) |
a94dbf2c JM |
8714 | gen_type_die (origin, context_die); |
8715 | ||
a3f97cbb JW |
8716 | /* Now output the DIE to represent the data object itself. This gets |
8717 | complicated because of the possibility that the VAR_DECL really | |
8718 | represents an inlined instance of a formal parameter for an inline | |
8719 | function. */ | |
8720 | origin = decl_ultimate_origin (decl); | |
71dfc51f RK |
8721 | if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL) |
8722 | gen_formal_parameter_die (decl, context_die); | |
a3f97cbb | 8723 | else |
71dfc51f | 8724 | gen_variable_die (decl, context_die); |
a3f97cbb JW |
8725 | break; |
8726 | ||
8727 | case FIELD_DECL: | |
a94dbf2c JM |
8728 | /* Ignore the nameless fields that are used to skip bits, but |
8729 | handle C++ anonymous unions. */ | |
71dfc51f RK |
8730 | if (DECL_NAME (decl) != NULL_TREE |
8731 | || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE) | |
a3f97cbb JW |
8732 | { |
8733 | gen_type_die (member_declared_type (decl), context_die); | |
8734 | gen_field_die (decl, context_die); | |
8735 | } | |
8736 | break; | |
8737 | ||
8738 | case PARM_DECL: | |
8739 | gen_type_die (TREE_TYPE (decl), context_die); | |
8740 | gen_formal_parameter_die (decl, context_die); | |
8741 | break; | |
8742 | ||
8743 | default: | |
8744 | abort (); | |
8745 | } | |
a3f97cbb JW |
8746 | } |
8747 | \f | |
71dfc51f RK |
8748 | /* Write the debugging output for DECL. */ |
8749 | ||
a3f97cbb | 8750 | void |
88dad228 | 8751 | dwarf2out_decl (decl) |
a3f97cbb | 8752 | register tree decl; |
a3f97cbb | 8753 | { |
88dad228 JM |
8754 | register dw_die_ref context_die = comp_unit_die; |
8755 | ||
a3f97cbb | 8756 | if (TREE_CODE (decl) == ERROR_MARK) |
71dfc51f | 8757 | return; |
a3f97cbb JW |
8758 | |
8759 | /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta | |
8760 | hope that the node in question doesn't represent a function definition. | |
8761 | If it does, then totally ignoring it is bound to screw up our count of | |
8762 | blocks, and that it turn will completely screw up the the labels we will | |
8763 | reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for | |
8764 | subsequent blocks). (It's too bad that BLOCK nodes don't carry their | |
8765 | own sequence numbers with them!) */ | |
8766 | if (DECL_IGNORED_P (decl)) | |
8767 | { | |
8768 | if (TREE_CODE (decl) == FUNCTION_DECL | |
8769 | && DECL_INITIAL (decl) != NULL) | |
71dfc51f RK |
8770 | abort (); |
8771 | ||
a3f97cbb JW |
8772 | return; |
8773 | } | |
8774 | ||
8775 | switch (TREE_CODE (decl)) | |
8776 | { | |
8777 | case FUNCTION_DECL: | |
8778 | /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a | |
8779 | builtin function. Explicit programmer-supplied declarations of | |
8780 | these same functions should NOT be ignored however. */ | |
8781 | if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl)) | |
b1ccbc24 | 8782 | return; |
a3f97cbb JW |
8783 | |
8784 | /* What we would really like to do here is to filter out all mere | |
8785 | file-scope declarations of file-scope functions which are never | |
8786 | referenced later within this translation unit (and keep all of ones | |
8787 | that *are* referenced later on) but we aren't clarvoiant, so we have | |
8788 | no idea which functions will be referenced in the future (i.e. later | |
8789 | on within the current translation unit). So here we just ignore all | |
8790 | file-scope function declarations which are not also definitions. If | |
8791 | and when the debugger needs to know something about these funcstion, | |
8792 | it wil have to hunt around and find the DWARF information associated | |
8793 | with the definition of the function. Note that we can't just check | |
8794 | `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent | |
8795 | definitions and which ones represent mere declarations. We have to | |
8796 | check `DECL_INITIAL' instead. That's because the C front-end | |
8797 | supports some weird semantics for "extern inline" function | |
8798 | definitions. These can get inlined within the current translation | |
8799 | unit (an thus, we need to generate DWARF info for their abstract | |
8800 | instances so that the DWARF info for the concrete inlined instances | |
8801 | can have something to refer to) but the compiler never generates any | |
8802 | out-of-lines instances of such things (despite the fact that they | |
8803 | *are* definitions). The important point is that the C front-end | |
8804 | marks these "extern inline" functions as DECL_EXTERNAL, but we need | |
273dbe67 | 8805 | to generate DWARF for them anyway. Note that the C++ front-end also |
a3f97cbb JW |
8806 | plays some similar games for inline function definitions appearing |
8807 | within include files which also contain | |
8808 | `#pragma interface' pragmas. */ | |
8809 | if (DECL_INITIAL (decl) == NULL_TREE) | |
b1ccbc24 | 8810 | return; |
88dad228 | 8811 | |
9c6cd30e JM |
8812 | /* If we're a nested function, initially use a parent of NULL; if we're |
8813 | a plain function, this will be fixed up in decls_for_scope. If | |
8814 | we're a method, it will be ignored, since we already have a DIE. */ | |
88dad228 | 8815 | if (decl_function_context (decl)) |
9c6cd30e | 8816 | context_die = NULL; |
88dad228 | 8817 | |
a3f97cbb JW |
8818 | break; |
8819 | ||
8820 | case VAR_DECL: | |
8821 | /* Ignore this VAR_DECL if it refers to a file-scope extern data object | |
8822 | declaration and if the declaration was never even referenced from | |
8823 | within this entire compilation unit. We suppress these DIEs in | |
8824 | order to save space in the .debug section (by eliminating entries | |
8825 | which are probably useless). Note that we must not suppress | |
8826 | block-local extern declarations (whether used or not) because that | |
8827 | would screw-up the debugger's name lookup mechanism and cause it to | |
8828 | miss things which really ought to be in scope at a given point. */ | |
8829 | if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) | |
71dfc51f | 8830 | return; |
a3f97cbb JW |
8831 | |
8832 | /* If we are in terse mode, don't generate any DIEs to represent any | |
8833 | variable declarations or definitions. */ | |
8834 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
71dfc51f | 8835 | return; |
a3f97cbb JW |
8836 | break; |
8837 | ||
8838 | case TYPE_DECL: | |
8839 | /* Don't bother trying to generate any DIEs to represent any of the | |
a9d38797 JM |
8840 | normal built-in types for the language we are compiling. */ |
8841 | if (DECL_SOURCE_LINE (decl) == 0) | |
a94dbf2c JM |
8842 | { |
8843 | /* OK, we need to generate one for `bool' so GDB knows what type | |
8844 | comparisons have. */ | |
8845 | if ((get_AT_unsigned (comp_unit_die, DW_AT_language) | |
8846 | == DW_LANG_C_plus_plus) | |
8847 | && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE) | |
8848 | modified_type_die (TREE_TYPE (decl), 0, 0, NULL); | |
71dfc51f | 8849 | |
a94dbf2c JM |
8850 | return; |
8851 | } | |
a3f97cbb | 8852 | |
88dad228 | 8853 | /* If we are in terse mode, don't generate any DIEs for types. */ |
a3f97cbb | 8854 | if (debug_info_level <= DINFO_LEVEL_TERSE) |
4927276d | 8855 | return; |
88dad228 JM |
8856 | |
8857 | /* If we're a function-scope tag, initially use a parent of NULL; | |
8858 | this will be fixed up in decls_for_scope. */ | |
8859 | if (decl_function_context (decl)) | |
3f76745e | 8860 | context_die = NULL; |
88dad228 | 8861 | |
a3f97cbb JW |
8862 | break; |
8863 | ||
8864 | default: | |
8865 | return; | |
8866 | } | |
8867 | ||
88dad228 | 8868 | gen_decl_die (decl, context_die); |
a94dbf2c | 8869 | output_pending_types_for_scope (comp_unit_die); |
a3f97cbb JW |
8870 | } |
8871 | ||
8872 | /* Output a marker (i.e. a label) for the beginning of the generated code for | |
8873 | a lexical block. */ | |
71dfc51f | 8874 | |
a3f97cbb | 8875 | void |
9a666dda | 8876 | dwarf2out_begin_block (blocknum) |
a3f97cbb JW |
8877 | register unsigned blocknum; |
8878 | { | |
a3f97cbb | 8879 | function_section (current_function_decl); |
5c90448c | 8880 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum); |
a3f97cbb JW |
8881 | } |
8882 | ||
8883 | /* Output a marker (i.e. a label) for the end of the generated code for a | |
8884 | lexical block. */ | |
71dfc51f | 8885 | |
a3f97cbb | 8886 | void |
9a666dda | 8887 | dwarf2out_end_block (blocknum) |
a3f97cbb JW |
8888 | register unsigned blocknum; |
8889 | { | |
a3f97cbb | 8890 | function_section (current_function_decl); |
5c90448c | 8891 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum); |
a3f97cbb JW |
8892 | } |
8893 | ||
8894 | /* Output a marker (i.e. a label) at a point in the assembly code which | |
8895 | corresponds to a given source level label. */ | |
71dfc51f | 8896 | |
a3f97cbb | 8897 | void |
9a666dda | 8898 | dwarf2out_label (insn) |
a3f97cbb JW |
8899 | register rtx insn; |
8900 | { | |
8901 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
71dfc51f | 8902 | |
a3f97cbb JW |
8903 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
8904 | { | |
8905 | function_section (current_function_decl); | |
5c90448c JM |
8906 | sprintf (label, INSN_LABEL_FMT, current_funcdef_number); |
8907 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label, | |
8908 | (unsigned) INSN_UID (insn)); | |
a3f97cbb JW |
8909 | } |
8910 | } | |
8911 | ||
a3f97cbb | 8912 | /* Lookup a filename (in the list of filenames that we know about here in |
9a666dda | 8913 | dwarf2out.c) and return its "index". The index of each (known) filename is |
a3f97cbb JW |
8914 | just a unique number which is associated with only that one filename. |
8915 | We need such numbers for the sake of generating labels | |
8916 | (in the .debug_sfnames section) and references to those | |
8917 | files numbers (in the .debug_srcinfo and.debug_macinfo sections). | |
8918 | If the filename given as an argument is not found in our current list, | |
8919 | add it to the list and assign it the next available unique index number. | |
8920 | In order to speed up searches, we remember the index of the filename | |
8921 | was looked up last. This handles the majority of all searches. */ | |
71dfc51f | 8922 | |
a3f97cbb JW |
8923 | static unsigned |
8924 | lookup_filename (file_name) | |
8925 | char *file_name; | |
8926 | { | |
8927 | static unsigned last_file_lookup_index = 0; | |
a3f97cbb JW |
8928 | register unsigned i; |
8929 | ||
8930 | /* Check to see if the file name that was searched on the previous call | |
8931 | matches this file name. If so, return the index. */ | |
8932 | if (last_file_lookup_index != 0) | |
71dfc51f RK |
8933 | if (strcmp (file_name, file_table[last_file_lookup_index]) == 0) |
8934 | return last_file_lookup_index; | |
a3f97cbb JW |
8935 | |
8936 | /* Didn't match the previous lookup, search the table */ | |
8937 | for (i = 1; i < file_table_in_use; ++i) | |
71dfc51f RK |
8938 | if (strcmp (file_name, file_table[i]) == 0) |
8939 | { | |
8940 | last_file_lookup_index = i; | |
8941 | return i; | |
8942 | } | |
a3f97cbb JW |
8943 | |
8944 | /* Prepare to add a new table entry by making sure there is enough space in | |
8945 | the table to do so. If not, expand the current table. */ | |
8946 | if (file_table_in_use == file_table_allocated) | |
8947 | { | |
8948 | file_table_allocated += FILE_TABLE_INCREMENT; | |
8949 | file_table | |
71dfc51f RK |
8950 | = (char **) xrealloc (file_table, |
8951 | file_table_allocated * sizeof (char *)); | |
a3f97cbb JW |
8952 | } |
8953 | ||
71dfc51f | 8954 | /* Add the new entry to the end of the filename table. */ |
a3f97cbb JW |
8955 | file_table[file_table_in_use] = xstrdup (file_name); |
8956 | last_file_lookup_index = file_table_in_use++; | |
71dfc51f | 8957 | |
a3f97cbb JW |
8958 | return last_file_lookup_index; |
8959 | } | |
8960 | ||
8961 | /* Output a label to mark the beginning of a source code line entry | |
8962 | and record information relating to this source line, in | |
8963 | 'line_info_table' for later output of the .debug_line section. */ | |
71dfc51f | 8964 | |
a3f97cbb | 8965 | void |
9a666dda | 8966 | dwarf2out_line (filename, line) |
a3f97cbb JW |
8967 | register char *filename; |
8968 | register unsigned line; | |
8969 | { | |
a3f97cbb JW |
8970 | if (debug_info_level >= DINFO_LEVEL_NORMAL) |
8971 | { | |
8972 | function_section (current_function_decl); | |
a3f97cbb | 8973 | |
e90b62db | 8974 | if (DECL_SECTION_NAME (current_function_decl)) |
a3f97cbb | 8975 | { |
e90b62db | 8976 | register dw_separate_line_info_ref line_info; |
5c90448c JM |
8977 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL, |
8978 | separate_line_info_table_in_use); | |
e90b62db JM |
8979 | fputc ('\n', asm_out_file); |
8980 | ||
8981 | /* expand the line info table if necessary */ | |
8982 | if (separate_line_info_table_in_use | |
8983 | == separate_line_info_table_allocated) | |
8984 | { | |
8985 | separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
8986 | separate_line_info_table | |
71dfc51f RK |
8987 | = (dw_separate_line_info_ref) |
8988 | xrealloc (separate_line_info_table, | |
8989 | separate_line_info_table_allocated | |
8990 | * sizeof (dw_separate_line_info_entry)); | |
e90b62db | 8991 | } |
71dfc51f RK |
8992 | |
8993 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
8994 | line_info |
8995 | = &separate_line_info_table[separate_line_info_table_in_use++]; | |
8996 | line_info->dw_file_num = lookup_filename (filename); | |
8997 | line_info->dw_line_num = line; | |
8998 | line_info->function = current_funcdef_number; | |
8999 | } | |
9000 | else | |
9001 | { | |
9002 | register dw_line_info_ref line_info; | |
71dfc51f | 9003 | |
5c90448c JM |
9004 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL, |
9005 | line_info_table_in_use); | |
e90b62db JM |
9006 | fputc ('\n', asm_out_file); |
9007 | ||
71dfc51f | 9008 | /* Expand the line info table if necessary. */ |
e90b62db JM |
9009 | if (line_info_table_in_use == line_info_table_allocated) |
9010 | { | |
9011 | line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; | |
9012 | line_info_table | |
71dfc51f RK |
9013 | = (dw_line_info_ref) |
9014 | xrealloc (line_info_table, | |
9015 | (line_info_table_allocated | |
9016 | * sizeof (dw_line_info_entry))); | |
e90b62db | 9017 | } |
71dfc51f RK |
9018 | |
9019 | /* Add the new entry at the end of the line_info_table. */ | |
e90b62db JM |
9020 | line_info = &line_info_table[line_info_table_in_use++]; |
9021 | line_info->dw_file_num = lookup_filename (filename); | |
9022 | line_info->dw_line_num = line; | |
a3f97cbb | 9023 | } |
a3f97cbb JW |
9024 | } |
9025 | } | |
9026 | ||
9027 | /* Record the beginning of a new source file, for later output | |
9028 | of the .debug_macinfo section. At present, unimplemented. */ | |
71dfc51f | 9029 | |
a3f97cbb | 9030 | void |
9a666dda | 9031 | dwarf2out_start_source_file (filename) |
a3f97cbb JW |
9032 | register char *filename; |
9033 | { | |
9034 | } | |
9035 | ||
9a666dda | 9036 | /* Record the end of a source file, for later output |
a3f97cbb | 9037 | of the .debug_macinfo section. At present, unimplemented. */ |
71dfc51f | 9038 | |
a3f97cbb | 9039 | void |
9a666dda | 9040 | dwarf2out_end_source_file () |
a3f97cbb JW |
9041 | { |
9042 | } | |
9043 | ||
9044 | /* Called from check_newline in c-parse.y. The `buffer' parameter contains | |
9045 | the tail part of the directive line, i.e. the part which is past the | |
9046 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 9047 | |
a3f97cbb | 9048 | void |
9a666dda | 9049 | dwarf2out_define (lineno, buffer) |
a3f97cbb JW |
9050 | register unsigned lineno; |
9051 | register char *buffer; | |
9052 | { | |
9053 | static int initialized = 0; | |
9054 | if (!initialized) | |
9055 | { | |
9a666dda | 9056 | dwarf2out_start_source_file (primary_filename); |
a3f97cbb JW |
9057 | initialized = 1; |
9058 | } | |
9059 | } | |
9060 | ||
9061 | /* Called from check_newline in c-parse.y. The `buffer' parameter contains | |
9062 | the tail part of the directive line, i.e. the part which is past the | |
9063 | initial whitespace, #, whitespace, directive-name, whitespace part. */ | |
71dfc51f | 9064 | |
a3f97cbb | 9065 | void |
9a666dda | 9066 | dwarf2out_undef (lineno, buffer) |
a3f97cbb JW |
9067 | register unsigned lineno; |
9068 | register char *buffer; | |
9069 | { | |
9070 | } | |
9071 | ||
9072 | /* Set up for Dwarf output at the start of compilation. */ | |
71dfc51f | 9073 | |
a3f97cbb | 9074 | void |
9a666dda | 9075 | dwarf2out_init (asm_out_file, main_input_filename) |
a3f97cbb JW |
9076 | register FILE *asm_out_file; |
9077 | register char *main_input_filename; | |
9078 | { | |
a3f97cbb JW |
9079 | /* Remember the name of the primary input file. */ |
9080 | primary_filename = main_input_filename; | |
9081 | ||
9082 | /* Allocate the initial hunk of the file_table. */ | |
9083 | file_table = (char **) xmalloc (FILE_TABLE_INCREMENT * sizeof (char *)); | |
b1ccbc24 | 9084 | bzero ((char *) file_table, FILE_TABLE_INCREMENT * sizeof (char *)); |
a3f97cbb | 9085 | file_table_allocated = FILE_TABLE_INCREMENT; |
71dfc51f RK |
9086 | |
9087 | /* Skip the first entry - file numbers begin at 1. */ | |
a3f97cbb JW |
9088 | file_table_in_use = 1; |
9089 | ||
a3f97cbb JW |
9090 | /* Allocate the initial hunk of the decl_die_table. */ |
9091 | decl_die_table | |
9092 | = (dw_die_ref *) xmalloc (DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref)); | |
b1ccbc24 RK |
9093 | bzero ((char *) decl_die_table, |
9094 | DECL_DIE_TABLE_INCREMENT * sizeof (dw_die_ref)); | |
a3f97cbb JW |
9095 | decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT; |
9096 | decl_die_table_in_use = 0; | |
9097 | ||
9098 | /* Allocate the initial hunk of the decl_scope_table. */ | |
9099 | decl_scope_table | |
9100 | = (tree *) xmalloc (DECL_SCOPE_TABLE_INCREMENT * sizeof (tree)); | |
b1ccbc24 RK |
9101 | bzero ((char *) decl_scope_table, |
9102 | DECL_SCOPE_TABLE_INCREMENT * sizeof (tree)); | |
a3f97cbb JW |
9103 | decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT; |
9104 | decl_scope_depth = 0; | |
9105 | ||
9106 | /* Allocate the initial hunk of the abbrev_die_table. */ | |
9107 | abbrev_die_table | |
9108 | = (dw_die_ref *) xmalloc (ABBREV_DIE_TABLE_INCREMENT | |
9109 | * sizeof (dw_die_ref)); | |
b1ccbc24 RK |
9110 | bzero ((char *) abbrev_die_table, |
9111 | ABBREV_DIE_TABLE_INCREMENT * sizeof (dw_die_ref)); | |
a3f97cbb | 9112 | abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT; |
71dfc51f | 9113 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
9114 | abbrev_die_table_in_use = 1; |
9115 | ||
9116 | /* Allocate the initial hunk of the line_info_table. */ | |
9117 | line_info_table | |
9118 | = (dw_line_info_ref) xmalloc (LINE_INFO_TABLE_INCREMENT | |
9119 | * sizeof (dw_line_info_entry)); | |
b1ccbc24 RK |
9120 | bzero ((char *) line_info_table, |
9121 | LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry)); | |
a3f97cbb | 9122 | line_info_table_allocated = LINE_INFO_TABLE_INCREMENT; |
71dfc51f | 9123 | /* Zero-th entry is allocated, but unused */ |
a3f97cbb JW |
9124 | line_info_table_in_use = 1; |
9125 | ||
a3f97cbb JW |
9126 | /* Generate the initial DIE for the .debug section. Note that the (string) |
9127 | value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE | |
9128 | will (typically) be a relative pathname and that this pathname should be | |
9129 | taken as being relative to the directory from which the compiler was | |
9130 | invoked when the given (base) source file was compiled. */ | |
9131 | gen_compile_unit_die (main_input_filename); | |
9132 | ||
5c90448c | 9133 | ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0); |
a94dbf2c | 9134 | |
3f76745e JM |
9135 | /* Initialize the frame unwind information. Eventually this should be |
9136 | called from compile_file instead. */ | |
9137 | dwarf2out_frame_init (); | |
a3f97cbb JW |
9138 | } |
9139 | ||
9140 | /* Output stuff that dwarf requires at the end of every file, | |
9141 | and generate the DWARF-2 debugging info. */ | |
71dfc51f | 9142 | |
a3f97cbb | 9143 | void |
9a666dda | 9144 | dwarf2out_finish () |
a3f97cbb | 9145 | { |
ef76d03b JW |
9146 | limbo_die_node *node, *next_node; |
9147 | dw_die_ref die; | |
9148 | dw_attr_ref a; | |
9149 | ||
9150 | /* Traverse the limbo die list, and add parent/child links. The only | |
9151 | dies without parents that should be here are concrete instances of | |
9152 | inline functions, and the comp_unit_die. We can ignore the comp_unit_die. | |
9153 | For concrete instances, we can get the parent die from the abstract | |
9154 | instance. */ | |
9155 | for (node = limbo_die_list; node; node = next_node) | |
9156 | { | |
9157 | next_node = node->next; | |
9158 | die = node->die; | |
9159 | ||
9160 | if (die->die_parent == NULL) | |
9161 | { | |
9162 | a = get_AT (die, DW_AT_abstract_origin); | |
9163 | if (a) | |
9164 | add_child_die (a->dw_attr_val.v.val_die_ref->die_parent, die); | |
9165 | else if (die == comp_unit_die) | |
9166 | ; | |
9167 | else | |
9168 | abort (); | |
9169 | } | |
9170 | free (node); | |
9171 | } | |
9172 | ||
a3f97cbb JW |
9173 | /* Traverse the DIE tree and add sibling attributes to those DIE's |
9174 | that have children. */ | |
9175 | add_sibling_attributes (comp_unit_die); | |
9176 | ||
9177 | /* Output a terminator label for the .text section. */ | |
9178 | fputc ('\n', asm_out_file); | |
9179 | ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION); | |
5c90448c | 9180 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0); |
a3f97cbb | 9181 | |
bdb669cb | 9182 | #if 0 |
a3f97cbb JW |
9183 | /* Output a terminator label for the .data section. */ |
9184 | fputc ('\n', asm_out_file); | |
9185 | ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION); | |
5c90448c | 9186 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0); |
a3f97cbb JW |
9187 | |
9188 | /* Output a terminator label for the .bss section. */ | |
9189 | fputc ('\n', asm_out_file); | |
9190 | ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION); | |
5c90448c | 9191 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0); |
bdb669cb | 9192 | #endif |
a3f97cbb | 9193 | |
3f76745e JM |
9194 | /* Output the frame unwind information. Eventually this should be called |
9195 | from compile_file instead. */ | |
9196 | dwarf2out_frame_finish (); | |
9197 | ||
e90b62db JM |
9198 | /* Output the source line correspondence table. */ |
9199 | if (line_info_table_in_use > 1 || separate_line_info_table_in_use) | |
9200 | { | |
9201 | fputc ('\n', asm_out_file); | |
c53aa195 | 9202 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION); |
e90b62db JM |
9203 | output_line_info (); |
9204 | ||
9205 | /* We can only use the low/high_pc attributes if all of the code | |
9206 | was in .text. */ | |
9207 | if (separate_line_info_table_in_use == 0) | |
9208 | { | |
9209 | add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, TEXT_SECTION); | |
5c90448c | 9210 | add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label); |
e90b62db | 9211 | } |
71dfc51f | 9212 | |
c53aa195 | 9213 | add_AT_section_offset (comp_unit_die, DW_AT_stmt_list, DEBUG_LINE_SECTION); |
e90b62db JM |
9214 | } |
9215 | ||
a3f97cbb JW |
9216 | /* Output the abbreviation table. */ |
9217 | fputc ('\n', asm_out_file); | |
9218 | ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION); | |
9219 | build_abbrev_table (comp_unit_die); | |
9220 | output_abbrev_section (); | |
9221 | ||
a3f97cbb JW |
9222 | /* Initialize the beginning DIE offset - and calculate sizes/offsets. */ |
9223 | next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE; | |
9224 | calc_die_sizes (comp_unit_die); | |
9225 | ||
a3f97cbb JW |
9226 | /* Output debugging information. */ |
9227 | fputc ('\n', asm_out_file); | |
c53aa195 | 9228 | ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION); |
a3f97cbb JW |
9229 | output_compilation_unit_header (); |
9230 | output_die (comp_unit_die); | |
9231 | ||
d291dd49 JM |
9232 | if (pubname_table_in_use) |
9233 | { | |
9234 | /* Output public names table. */ | |
9235 | fputc ('\n', asm_out_file); | |
9236 | ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION); | |
9237 | output_pubnames (); | |
9238 | } | |
9239 | ||
a3f97cbb JW |
9240 | if (fde_table_in_use) |
9241 | { | |
a3f97cbb JW |
9242 | /* Output the address range information. */ |
9243 | fputc ('\n', asm_out_file); | |
9244 | ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION); | |
9245 | output_aranges (); | |
9246 | } | |
9247 | } | |
9a666dda | 9248 | #endif /* DWARF2_DEBUGGING_INFO */ |