* config/i386/i386.md (mmx_pinsrw): Output operands in correct
[official-gcc.git] / gcc / dwarf2out.c
bloba5517a2436b3570444b9424e9acc2dd646fb5e44
1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GNU CC.
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* TODO: Implement .debug_str handling, and share entries somehow.
26 Emit .debug_line header even when there are no functions, since
27 the file numbers are used by .debug_info. Alternately, leave
28 out locations for types and decls.
29 Avoid talking about ctors and op= for PODs.
30 Factor out common prologue sequences into multiple CIEs. */
32 /* The first part of this file deals with the DWARF 2 frame unwind
33 information, which is also used by the GCC efficient exception handling
34 mechanism. The second part, controlled only by an #ifdef
35 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
36 information. */
38 #include "config.h"
39 #include "system.h"
40 #include "defaults.h"
41 #include "tree.h"
42 #include "flags.h"
43 #include "rtl.h"
44 #include "hard-reg-set.h"
45 #include "regs.h"
46 #include "insn-config.h"
47 #include "reload.h"
48 #include "output.h"
49 #include "expr.h"
50 #include "except.h"
51 #include "dwarf2.h"
52 #include "dwarf2out.h"
53 #include "toplev.h"
54 #include "varray.h"
55 #include "ggc.h"
56 #include "md5.h"
57 #include "tm_p.h"
59 /* Decide whether we want to emit frame unwind information for the current
60 translation unit. */
62 int
63 dwarf2out_do_frame ()
65 return (write_symbols == DWARF2_DEBUG
66 #ifdef DWARF2_FRAME_INFO
67 || DWARF2_FRAME_INFO
68 #endif
69 #ifdef DWARF2_UNWIND_INFO
70 || flag_unwind_tables
71 || (flag_exceptions && ! exceptions_via_longjmp)
72 #endif
76 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
78 /* How to start an assembler comment. */
79 #ifndef ASM_COMMENT_START
80 #define ASM_COMMENT_START ";#"
81 #endif
83 typedef struct dw_cfi_struct *dw_cfi_ref;
84 typedef struct dw_fde_struct *dw_fde_ref;
85 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
87 /* Call frames are described using a sequence of Call Frame
88 Information instructions. The register number, offset
89 and address fields are provided as possible operands;
90 their use is selected by the opcode field. */
92 typedef union dw_cfi_oprnd_struct
94 unsigned long dw_cfi_reg_num;
95 long int dw_cfi_offset;
96 const char *dw_cfi_addr;
97 struct dw_loc_descr_struct *dw_cfi_loc;
99 dw_cfi_oprnd;
101 typedef struct dw_cfi_struct
103 dw_cfi_ref dw_cfi_next;
104 enum dwarf_call_frame_info dw_cfi_opc;
105 dw_cfi_oprnd dw_cfi_oprnd1;
106 dw_cfi_oprnd dw_cfi_oprnd2;
108 dw_cfi_node;
110 /* This is how we define the location of the CFA. We use to handle it
111 as REG + OFFSET all the time, but now it can be more complex.
112 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
113 Instead of passing around REG and OFFSET, we pass a copy
114 of this structure. */
115 typedef struct cfa_loc
117 unsigned long reg;
118 long offset;
119 long base_offset;
120 int indirect; /* 1 if CFA is accessed via a dereference. */
121 } dw_cfa_location;
123 /* All call frame descriptions (FDE's) in the GCC generated DWARF
124 refer to a single Common Information Entry (CIE), defined at
125 the beginning of the .debug_frame section. This used of a single
126 CIE obviates the need to keep track of multiple CIE's
127 in the DWARF generation routines below. */
129 typedef struct dw_fde_struct
131 const char *dw_fde_begin;
132 const char *dw_fde_current_label;
133 const char *dw_fde_end;
134 dw_cfi_ref dw_fde_cfi;
135 int nothrow;
137 dw_fde_node;
139 /* Maximum size (in bytes) of an artificially generated label. */
140 #define MAX_ARTIFICIAL_LABEL_BYTES 30
142 /* The size of the target's pointer type. */
143 #ifndef PTR_SIZE
144 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
145 #endif
147 /* The size of addresses as they appear in the Dwarf 2 data.
148 Some architectures use word addresses to refer to code locations,
149 but Dwarf 2 info always uses byte addresses. On such machines,
150 Dwarf 2 addresses need to be larger than the architecture's
151 pointers. */
152 #ifndef DWARF2_ADDR_SIZE
153 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
154 #endif
156 /* The size in bytes of a DWARF field indicating an offset or length
157 relative to a debug info section, specified to be 4 bytes in the
158 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
159 as PTR_SIZE. */
161 #ifndef DWARF_OFFSET_SIZE
162 #define DWARF_OFFSET_SIZE 4
163 #endif
165 #define DWARF_VERSION 2
167 /* Round SIZE up to the nearest BOUNDARY. */
168 #define DWARF_ROUND(SIZE,BOUNDARY) \
169 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
171 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
172 #ifndef DWARF_CIE_DATA_ALIGNMENT
173 #ifdef STACK_GROWS_DOWNWARD
174 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
175 #else
176 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
177 #endif
178 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
180 /* A pointer to the base of a table that contains frame description
181 information for each routine. */
182 static dw_fde_ref fde_table;
184 /* Number of elements currently allocated for fde_table. */
185 static unsigned fde_table_allocated;
187 /* Number of elements in fde_table currently in use. */
188 static unsigned fde_table_in_use;
190 /* Size (in elements) of increments by which we may expand the
191 fde_table. */
192 #define FDE_TABLE_INCREMENT 256
194 /* A list of call frame insns for the CIE. */
195 static dw_cfi_ref cie_cfi_head;
197 /* The number of the current function definition for which debugging
198 information is being generated. These numbers range from 1 up to the
199 maximum number of function definitions contained within the current
200 compilation unit. These numbers are used to create unique label id's
201 unique to each function definition. */
202 static unsigned current_funcdef_number = 0;
204 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
205 attribute that accelerates the lookup of the FDE associated
206 with the subprogram. This variable holds the table index of the FDE
207 associated with the current function (body) definition. */
208 static unsigned current_funcdef_fde;
210 /* Forward declarations for functions defined in this file. */
212 static char *stripattributes PARAMS ((const char *));
213 static const char *dwarf_cfi_name PARAMS ((unsigned));
214 static dw_cfi_ref new_cfi PARAMS ((void));
215 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
216 static unsigned long size_of_uleb128 PARAMS ((unsigned long));
217 static unsigned long size_of_sleb128 PARAMS ((long));
218 static void output_uleb128 PARAMS ((unsigned long));
219 static void output_sleb128 PARAMS ((long));
220 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
221 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
222 static void lookup_cfa PARAMS ((dw_cfa_location *));
223 static void reg_save PARAMS ((const char *, unsigned,
224 unsigned, long));
225 static void initial_return_save PARAMS ((rtx));
226 static long stack_adjust_offset PARAMS ((rtx));
227 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref));
228 static void output_call_frame_info PARAMS ((int));
229 static void dwarf2out_stack_adjust PARAMS ((rtx));
230 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
232 /* Support for complex CFA locations. */
233 static void output_cfa_loc PARAMS ((dw_cfi_ref));
234 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
235 struct dw_loc_descr_struct *));
236 static struct dw_loc_descr_struct *build_cfa_loc
237 PARAMS ((dw_cfa_location *));
238 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
240 /* Definitions of defaults for assembler-dependent names of various
241 pseudo-ops and section names.
242 Theses may be overridden in the tm.h file (if necessary) for a particular
243 assembler. */
245 #ifdef OBJECT_FORMAT_ELF
246 #ifndef UNALIGNED_SHORT_ASM_OP
247 #define UNALIGNED_SHORT_ASM_OP "\t.2byte\t"
248 #endif
249 #ifndef UNALIGNED_INT_ASM_OP
250 #define UNALIGNED_INT_ASM_OP "\t.4byte\t"
251 #endif
252 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
253 #define UNALIGNED_DOUBLE_INT_ASM_OP "\t.8byte\t"
254 #endif
255 #endif /* OBJECT_FORMAT_ELF */
257 #ifndef ASM_BYTE_OP
258 #define ASM_BYTE_OP "\t.byte\t"
259 #endif
261 /* Data and reference forms for relocatable data. */
262 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
263 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
265 /* Pseudo-op for defining a new section. */
266 #ifndef SECTION_ASM_OP
267 #define SECTION_ASM_OP "\t.section\t"
268 #endif
270 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
271 print the SECTION_ASM_OP and the section name. The default here works for
272 almost all svr4 assemblers, except for the sparc, where the section name
273 must be enclosed in double quotes. (See sparcv4.h). */
274 #ifndef SECTION_FORMAT
275 #ifdef PUSHSECTION_FORMAT
276 #define SECTION_FORMAT PUSHSECTION_FORMAT
277 #else
278 #define SECTION_FORMAT "%s%s\n"
279 #endif
280 #endif
282 #ifndef FRAME_SECTION
283 #define FRAME_SECTION ".debug_frame"
284 #endif
286 #ifndef FUNC_BEGIN_LABEL
287 #define FUNC_BEGIN_LABEL "LFB"
288 #endif
289 #ifndef FUNC_END_LABEL
290 #define FUNC_END_LABEL "LFE"
291 #endif
292 #define CIE_AFTER_SIZE_LABEL "LSCIE"
293 #define CIE_END_LABEL "LECIE"
294 #define CIE_LENGTH_LABEL "LLCIE"
295 #define FDE_AFTER_SIZE_LABEL "LSFDE"
296 #define FDE_END_LABEL "LEFDE"
297 #define FDE_LENGTH_LABEL "LLFDE"
298 #define DIE_LABEL_PREFIX "DW"
300 /* Definitions of defaults for various types of primitive assembly language
301 output operations. These may be overridden from within the tm.h file,
302 but typically, that is unnecessary. */
304 #ifndef ASM_OUTPUT_SECTION
305 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
306 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
307 #endif
309 #ifndef ASM_OUTPUT_DWARF_DATA1
310 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
311 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
312 #endif
314 #ifndef ASM_OUTPUT_DWARF_DELTA1
315 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
316 do { fprintf ((FILE), "%s", ASM_BYTE_OP); \
317 assemble_name (FILE, LABEL1); \
318 fprintf (FILE, "-"); \
319 assemble_name (FILE, LABEL2); \
320 } while (0)
321 #endif
323 #ifdef UNALIGNED_INT_ASM_OP
325 #ifndef UNALIGNED_OFFSET_ASM_OP
326 #define UNALIGNED_OFFSET_ASM_OP \
327 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
328 #endif
330 #ifndef UNALIGNED_WORD_ASM_OP
331 #define UNALIGNED_WORD_ASM_OP \
332 ((DWARF2_ADDR_SIZE) == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP \
333 : (DWARF2_ADDR_SIZE) == 2 ? UNALIGNED_SHORT_ASM_OP \
334 : UNALIGNED_INT_ASM_OP)
335 #endif
337 #ifndef ASM_OUTPUT_DWARF_DELTA2
338 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
339 do { fprintf ((FILE), "%s", UNALIGNED_SHORT_ASM_OP); \
340 assemble_name (FILE, LABEL1); \
341 fprintf (FILE, "-"); \
342 assemble_name (FILE, LABEL2); \
343 } while (0)
344 #endif
346 #ifndef ASM_OUTPUT_DWARF_DELTA4
347 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
348 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
349 assemble_name (FILE, LABEL1); \
350 fprintf (FILE, "-"); \
351 assemble_name (FILE, LABEL2); \
352 } while (0)
353 #endif
355 #ifndef ASM_OUTPUT_DWARF_DELTA
356 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
357 do { fprintf ((FILE), "%s", UNALIGNED_OFFSET_ASM_OP); \
358 assemble_name (FILE, LABEL1); \
359 fprintf (FILE, "-"); \
360 assemble_name (FILE, LABEL2); \
361 } while (0)
362 #endif
364 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
365 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
366 do { fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
367 assemble_name (FILE, LABEL1); \
368 fprintf (FILE, "-"); \
369 assemble_name (FILE, LABEL2); \
370 } while (0)
371 #endif
373 #ifndef ASM_OUTPUT_DWARF_ADDR
374 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
375 do { fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
376 assemble_name (FILE, LABEL); \
377 } while (0)
378 #endif
380 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
381 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
382 do { \
383 fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
384 output_addr_const ((FILE), (RTX)); \
385 } while (0)
386 #endif
388 #ifndef ASM_OUTPUT_DWARF_OFFSET4
389 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
390 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
391 assemble_name (FILE, LABEL); \
392 } while (0)
393 #endif
395 #ifndef ASM_OUTPUT_DWARF_OFFSET
396 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
397 do { fprintf ((FILE), "%s", UNALIGNED_OFFSET_ASM_OP); \
398 assemble_name (FILE, LABEL); \
399 } while (0)
400 #endif
402 #ifndef ASM_OUTPUT_DWARF_DATA2
403 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
404 fprintf ((FILE), "%s0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
405 #endif
407 #ifndef ASM_OUTPUT_DWARF_DATA4
408 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
409 fprintf ((FILE), "%s0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
410 #endif
412 #ifndef ASM_OUTPUT_DWARF_DATA8
413 #define ASM_OUTPUT_DWARF_DATA8(FILE,VALUE) \
414 fprintf ((FILE), "%s0x%lx", UNALIGNED_DOUBLE_INT_ASM_OP, \
415 (unsigned long) (VALUE))
416 #endif
418 #ifndef ASM_OUTPUT_DWARF_DATA
419 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
420 fprintf ((FILE), "%s0x%lx", UNALIGNED_OFFSET_ASM_OP, \
421 (unsigned long) (VALUE))
422 #endif
424 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
425 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
426 fprintf ((FILE), "%s0x%lx", UNALIGNED_WORD_ASM_OP, \
427 (unsigned long) (VALUE))
428 #endif
430 #ifndef ASM_OUTPUT_DWARF_CONST_DOUBLE
431 #define ASM_OUTPUT_DWARF_CONST_DOUBLE(FILE,HIGH_VALUE,LOW_VALUE) \
432 do { \
433 if (WORDS_BIG_ENDIAN) \
435 fprintf ((FILE), "%s0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
436 fprintf ((FILE), "%s0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
438 else \
440 fprintf ((FILE), "%s0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
441 fprintf ((FILE), "%s0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
443 } while (0)
444 #endif
446 #else /* UNALIGNED_INT_ASM_OP */
448 /* We don't have unaligned support, let's hope the normal output works for
449 .debug_frame. But we know it won't work for .debug_info. */
451 #ifdef DWARF2_DEBUGGING_INFO
452 #error DWARF2_DEBUGGING_INFO requires UNALIGNED_INT_ASM_OP.
453 #endif
455 #ifndef ASM_OUTPUT_DWARF_ADDR
456 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
457 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), DWARF2_ADDR_SIZE, 1)
458 #endif
460 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
461 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) ASM_OUTPUT_DWARF_ADDR (FILE,RTX)
462 #endif
464 #ifndef ASM_OUTPUT_DWARF_OFFSET4
465 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
466 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
467 #endif
469 #ifndef ASM_OUTPUT_DWARF_OFFSET
470 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
471 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
472 #endif
474 #ifndef ASM_OUTPUT_DWARF_DELTA2
475 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
476 assemble_integer (gen_rtx_MINUS (HImode, \
477 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
478 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
479 2, 1)
480 #endif
482 #ifndef ASM_OUTPUT_DWARF_DELTA4
483 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
484 assemble_integer (gen_rtx_MINUS (SImode, \
485 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
486 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
487 4, 1)
488 #endif
490 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
491 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
492 assemble_integer (gen_rtx_MINUS (Pmode, \
493 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
494 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
495 DWARF2_ADDR_SIZE, 1)
496 #endif
498 #ifndef ASM_OUTPUT_DWARF_DELTA
499 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
500 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
501 #endif
503 #ifndef ASM_OUTPUT_DWARF_DATA2
504 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
505 assemble_integer (GEN_INT (VALUE), 2, 1)
506 #endif
508 #ifndef ASM_OUTPUT_DWARF_DATA4
509 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
510 assemble_integer (GEN_INT (VALUE), 4, 1)
511 #endif
513 #endif /* UNALIGNED_INT_ASM_OP */
515 #ifdef SET_ASM_OP
516 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
517 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
518 do { \
519 fprintf (FILE, "%s", SET_ASM_OP); \
520 assemble_name (FILE, SY); \
521 fputc (',', FILE); \
522 assemble_name (FILE, HI); \
523 fputc ('-', FILE); \
524 assemble_name (FILE, LO); \
525 } while (0)
526 #endif
527 #endif /* SET_ASM_OP */
529 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
530 newline is produced. When flag_debug_asm is asserted, we add commentary
531 at the end of the line, so we must avoid output of a newline here. */
532 #ifndef ASM_OUTPUT_DWARF_STRING
533 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
534 do { \
535 register int slen = strlen(P); \
536 register const char *p = (P); \
537 register int i; \
538 fprintf (FILE, "\t.ascii \""); \
539 for (i = 0; i < slen; i++) \
541 register int c = p[i]; \
542 if (c == '\"' || c == '\\') \
543 putc ('\\', FILE); \
544 if (ISPRINT(c)) \
545 putc (c, FILE); \
546 else \
548 fprintf (FILE, "\\%o", c); \
551 fprintf (FILE, "\\0\""); \
553 while (0)
554 #endif
556 /* The DWARF 2 CFA column which tracks the return address. Normally this
557 is the column for PC, or the first column after all of the hard
558 registers. */
559 #ifndef DWARF_FRAME_RETURN_COLUMN
560 #ifdef PC_REGNUM
561 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
562 #else
563 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
564 #endif
565 #endif
567 /* The mapping from gcc register number to DWARF 2 CFA column number. By
568 default, we just provide columns for all registers. */
569 #ifndef DWARF_FRAME_REGNUM
570 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
571 #endif
573 /* Hook used by __throw. */
576 expand_builtin_dwarf_fp_regnum ()
578 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
581 /* The offset from the incoming value of %sp to the top of the stack frame
582 for the current function. */
583 #ifndef INCOMING_FRAME_SP_OFFSET
584 #define INCOMING_FRAME_SP_OFFSET 0
585 #endif
587 /* Return a pointer to a copy of the section string name S with all
588 attributes stripped off, and an asterisk prepended (for assemble_name). */
590 static inline char *
591 stripattributes (s)
592 const char *s;
594 char *stripped = xmalloc (strlen (s) + 2);
595 char *p = stripped;
597 *p++ = '*';
599 while (*s && *s != ',')
600 *p++ = *s++;
602 *p = '\0';
603 return stripped;
606 /* Generate code to initialize the register size table. */
608 void
609 expand_builtin_init_dwarf_reg_sizes (address)
610 tree address;
612 int i;
613 enum machine_mode mode = TYPE_MODE (char_type_node);
614 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
615 rtx mem = gen_rtx_MEM (mode, addr);
617 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
619 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
620 int size = GET_MODE_SIZE (reg_raw_mode[i]);
622 if (offset < 0)
623 continue;
625 emit_move_insn (change_address (mem, mode,
626 plus_constant (addr, offset)),
627 GEN_INT (size));
631 /* Convert a DWARF call frame info. operation to its string name */
633 static const char *
634 dwarf_cfi_name (cfi_opc)
635 register unsigned cfi_opc;
637 switch (cfi_opc)
639 case DW_CFA_advance_loc:
640 return "DW_CFA_advance_loc";
641 case DW_CFA_offset:
642 return "DW_CFA_offset";
643 case DW_CFA_restore:
644 return "DW_CFA_restore";
645 case DW_CFA_nop:
646 return "DW_CFA_nop";
647 case DW_CFA_set_loc:
648 return "DW_CFA_set_loc";
649 case DW_CFA_advance_loc1:
650 return "DW_CFA_advance_loc1";
651 case DW_CFA_advance_loc2:
652 return "DW_CFA_advance_loc2";
653 case DW_CFA_advance_loc4:
654 return "DW_CFA_advance_loc4";
655 case DW_CFA_offset_extended:
656 return "DW_CFA_offset_extended";
657 case DW_CFA_restore_extended:
658 return "DW_CFA_restore_extended";
659 case DW_CFA_undefined:
660 return "DW_CFA_undefined";
661 case DW_CFA_same_value:
662 return "DW_CFA_same_value";
663 case DW_CFA_register:
664 return "DW_CFA_register";
665 case DW_CFA_remember_state:
666 return "DW_CFA_remember_state";
667 case DW_CFA_restore_state:
668 return "DW_CFA_restore_state";
669 case DW_CFA_def_cfa:
670 return "DW_CFA_def_cfa";
671 case DW_CFA_def_cfa_register:
672 return "DW_CFA_def_cfa_register";
673 case DW_CFA_def_cfa_offset:
674 return "DW_CFA_def_cfa_offset";
675 case DW_CFA_def_cfa_expression:
676 return "DW_CFA_def_cfa_expression";
678 /* SGI/MIPS specific */
679 case DW_CFA_MIPS_advance_loc8:
680 return "DW_CFA_MIPS_advance_loc8";
682 /* GNU extensions */
683 case DW_CFA_GNU_window_save:
684 return "DW_CFA_GNU_window_save";
685 case DW_CFA_GNU_args_size:
686 return "DW_CFA_GNU_args_size";
687 case DW_CFA_GNU_negative_offset_extended:
688 return "DW_CFA_GNU_negative_offset_extended";
690 default:
691 return "DW_CFA_<unknown>";
695 /* Return a pointer to a newly allocated Call Frame Instruction. */
697 static inline dw_cfi_ref
698 new_cfi ()
700 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
702 cfi->dw_cfi_next = NULL;
703 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
704 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
706 return cfi;
709 /* Add a Call Frame Instruction to list of instructions. */
711 static inline void
712 add_cfi (list_head, cfi)
713 register dw_cfi_ref *list_head;
714 register dw_cfi_ref cfi;
716 register dw_cfi_ref *p;
718 /* Find the end of the chain. */
719 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
722 *p = cfi;
725 /* Generate a new label for the CFI info to refer to. */
727 char *
728 dwarf2out_cfi_label ()
730 static char label[20];
731 static unsigned long label_num = 0;
733 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
734 ASM_OUTPUT_LABEL (asm_out_file, label);
736 return label;
739 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
740 or to the CIE if LABEL is NULL. */
742 static void
743 add_fde_cfi (label, cfi)
744 register const char *label;
745 register dw_cfi_ref cfi;
747 if (label)
749 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
751 if (*label == 0)
752 label = dwarf2out_cfi_label ();
754 if (fde->dw_fde_current_label == NULL
755 || strcmp (label, fde->dw_fde_current_label) != 0)
757 register dw_cfi_ref xcfi;
759 fde->dw_fde_current_label = label = xstrdup (label);
761 /* Set the location counter to the new label. */
762 xcfi = new_cfi ();
763 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
764 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
765 add_cfi (&fde->dw_fde_cfi, xcfi);
768 add_cfi (&fde->dw_fde_cfi, cfi);
771 else
772 add_cfi (&cie_cfi_head, cfi);
775 /* Subroutine of lookup_cfa. */
777 static inline void
778 lookup_cfa_1 (cfi, loc)
779 register dw_cfi_ref cfi;
780 register dw_cfa_location *loc;
782 switch (cfi->dw_cfi_opc)
784 case DW_CFA_def_cfa_offset:
785 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
786 break;
787 case DW_CFA_def_cfa_register:
788 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
789 break;
790 case DW_CFA_def_cfa:
791 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
792 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
793 break;
794 case DW_CFA_def_cfa_expression:
795 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
796 break;
797 default:
798 break;
802 /* Find the previous value for the CFA. */
804 static void
805 lookup_cfa (loc)
806 register dw_cfa_location *loc;
808 register dw_cfi_ref cfi;
810 loc->reg = (unsigned long) -1;
811 loc->offset = 0;
812 loc->indirect = 0;
813 loc->base_offset = 0;
815 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
816 lookup_cfa_1 (cfi, loc);
818 if (fde_table_in_use)
820 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
821 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
822 lookup_cfa_1 (cfi, loc);
826 /* The current rule for calculating the DWARF2 canonical frame address. */
827 dw_cfa_location cfa;
829 /* The register used for saving registers to the stack, and its offset
830 from the CFA. */
831 dw_cfa_location cfa_store;
833 /* The running total of the size of arguments pushed onto the stack. */
834 static long args_size;
836 /* The last args_size we actually output. */
837 static long old_args_size;
839 /* Entry point to update the canonical frame address (CFA).
840 LABEL is passed to add_fde_cfi. The value of CFA is now to be
841 calculated from REG+OFFSET. */
843 void
844 dwarf2out_def_cfa (label, reg, offset)
845 register const char *label;
846 unsigned reg;
847 long offset;
849 dw_cfa_location loc;
850 loc.indirect = 0;
851 loc.base_offset = 0;
852 loc.reg = reg;
853 loc.offset = offset;
854 def_cfa_1 (label, &loc);
857 /* This routine does the actual work. The CFA is now calculated from
858 the dw_cfa_location structure. */
859 static void
860 def_cfa_1 (label, loc_p)
861 register const char *label;
862 dw_cfa_location *loc_p;
864 register dw_cfi_ref cfi;
865 dw_cfa_location old_cfa, loc;
867 cfa = *loc_p;
868 loc = *loc_p;
870 if (cfa_store.reg == loc.reg && loc.indirect == 0)
871 cfa_store.offset = loc.offset;
873 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
874 lookup_cfa (&old_cfa);
876 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
877 loc.indirect == old_cfa.indirect)
879 if (loc.indirect == 0
880 || loc.base_offset == old_cfa.base_offset)
881 return;
884 cfi = new_cfi ();
886 if (loc.reg == old_cfa.reg && !loc.indirect)
888 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
889 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
892 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
893 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
894 && !loc.indirect)
896 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
897 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
899 #endif
901 else if (loc.indirect == 0)
903 cfi->dw_cfi_opc = DW_CFA_def_cfa;
904 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
905 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
907 else
909 struct dw_loc_descr_struct *loc_list;
910 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
911 loc_list = build_cfa_loc (&loc);
912 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
915 add_fde_cfi (label, cfi);
918 /* Add the CFI for saving a register. REG is the CFA column number.
919 LABEL is passed to add_fde_cfi.
920 If SREG is -1, the register is saved at OFFSET from the CFA;
921 otherwise it is saved in SREG. */
923 static void
924 reg_save (label, reg, sreg, offset)
925 register const char *label;
926 register unsigned reg;
927 register unsigned sreg;
928 register long offset;
930 register dw_cfi_ref cfi = new_cfi ();
932 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
934 /* The following comparison is correct. -1 is used to indicate that
935 the value isn't a register number. */
936 if (sreg == (unsigned int) -1)
938 if (reg & ~0x3f)
939 /* The register number won't fit in 6 bits, so we have to use
940 the long form. */
941 cfi->dw_cfi_opc = DW_CFA_offset_extended;
942 else
943 cfi->dw_cfi_opc = DW_CFA_offset;
945 #ifdef ENABLE_CHECKING
947 /* If we get an offset that is not a multiple of
948 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
949 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
950 description. */
951 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
953 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
954 abort ();
956 #endif
957 offset /= DWARF_CIE_DATA_ALIGNMENT;
958 if (offset < 0)
960 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
961 offset = -offset;
963 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
965 else if (sreg == reg)
966 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
967 return;
968 else
970 cfi->dw_cfi_opc = DW_CFA_register;
971 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
974 add_fde_cfi (label, cfi);
977 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
978 This CFI tells the unwinder that it needs to restore the window registers
979 from the previous frame's window save area.
981 ??? Perhaps we should note in the CIE where windows are saved (instead of
982 assuming 0(cfa)) and what registers are in the window. */
984 void
985 dwarf2out_window_save (label)
986 register const char *label;
988 register dw_cfi_ref cfi = new_cfi ();
989 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
990 add_fde_cfi (label, cfi);
993 /* Add a CFI to update the running total of the size of arguments
994 pushed onto the stack. */
996 void
997 dwarf2out_args_size (label, size)
998 const char *label;
999 long size;
1001 register dw_cfi_ref cfi;
1003 if (size == old_args_size)
1004 return;
1005 old_args_size = size;
1007 cfi = new_cfi ();
1008 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1009 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1010 add_fde_cfi (label, cfi);
1013 /* Entry point for saving a register to the stack. REG is the GCC register
1014 number. LABEL and OFFSET are passed to reg_save. */
1016 void
1017 dwarf2out_reg_save (label, reg, offset)
1018 register const char *label;
1019 register unsigned reg;
1020 register long offset;
1022 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
1025 /* Entry point for saving the return address in the stack.
1026 LABEL and OFFSET are passed to reg_save. */
1028 void
1029 dwarf2out_return_save (label, offset)
1030 register const char *label;
1031 register long offset;
1033 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
1036 /* Entry point for saving the return address in a register.
1037 LABEL and SREG are passed to reg_save. */
1039 void
1040 dwarf2out_return_reg (label, sreg)
1041 register const char *label;
1042 register unsigned sreg;
1044 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
1047 /* Record the initial position of the return address. RTL is
1048 INCOMING_RETURN_ADDR_RTX. */
1050 static void
1051 initial_return_save (rtl)
1052 register rtx rtl;
1054 unsigned int reg = (unsigned int) -1;
1055 long offset = 0;
1057 switch (GET_CODE (rtl))
1059 case REG:
1060 /* RA is in a register. */
1061 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1062 break;
1063 case MEM:
1064 /* RA is on the stack. */
1065 rtl = XEXP (rtl, 0);
1066 switch (GET_CODE (rtl))
1068 case REG:
1069 if (REGNO (rtl) != STACK_POINTER_REGNUM)
1070 abort ();
1071 offset = 0;
1072 break;
1073 case PLUS:
1074 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1075 abort ();
1076 offset = INTVAL (XEXP (rtl, 1));
1077 break;
1078 case MINUS:
1079 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1080 abort ();
1081 offset = -INTVAL (XEXP (rtl, 1));
1082 break;
1083 default:
1084 abort ();
1086 break;
1087 case PLUS:
1088 /* The return address is at some offset from any value we can
1089 actually load. For instance, on the SPARC it is in %i7+8. Just
1090 ignore the offset for now; it doesn't matter for unwinding frames. */
1091 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
1092 abort ();
1093 initial_return_save (XEXP (rtl, 0));
1094 return;
1095 default:
1096 abort ();
1099 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1102 /* Given a SET, calculate the amount of stack adjustment it
1103 contains. */
1105 static long
1106 stack_adjust_offset (pattern)
1107 rtx pattern;
1109 rtx src = SET_SRC (pattern);
1110 rtx dest = SET_DEST (pattern);
1111 long offset = 0;
1112 enum rtx_code code;
1114 if (dest == stack_pointer_rtx)
1116 /* (set (reg sp) (plus (reg sp) (const_int))) */
1117 code = GET_CODE (src);
1118 if (! (code == PLUS || code == MINUS)
1119 || XEXP (src, 0) != stack_pointer_rtx
1120 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1121 return 0;
1123 offset = INTVAL (XEXP (src, 1));
1125 else if (GET_CODE (dest) == MEM)
1127 /* (set (mem (pre_dec (reg sp))) (foo)) */
1128 src = XEXP (dest, 0);
1129 code = GET_CODE (src);
1131 if (! (code == PRE_DEC || code == PRE_INC)
1132 || XEXP (src, 0) != stack_pointer_rtx)
1133 return 0;
1135 offset = GET_MODE_SIZE (GET_MODE (dest));
1137 else
1138 return 0;
1140 if (code == PLUS || code == PRE_INC)
1141 offset = -offset;
1143 return offset;
1146 /* Check INSN to see if it looks like a push or a stack adjustment, and
1147 make a note of it if it does. EH uses this information to find out how
1148 much extra space it needs to pop off the stack. */
1150 static void
1151 dwarf2out_stack_adjust (insn)
1152 rtx insn;
1154 long offset;
1155 const char *label;
1157 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1159 /* Extract the size of the args from the CALL rtx itself. */
1161 insn = PATTERN (insn);
1162 if (GET_CODE (insn) == PARALLEL)
1163 insn = XVECEXP (insn, 0, 0);
1164 if (GET_CODE (insn) == SET)
1165 insn = SET_SRC (insn);
1166 if (GET_CODE (insn) != CALL)
1167 abort ();
1168 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1169 return;
1172 /* If only calls can throw, and we have a frame pointer,
1173 save up adjustments until we see the CALL_INSN. */
1174 else if (! asynchronous_exceptions
1175 && cfa.reg != STACK_POINTER_REGNUM)
1176 return;
1178 if (GET_CODE (insn) == BARRIER)
1180 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1181 the compiler will have already emitted a stack adjustment, but
1182 doesn't bother for calls to noreturn functions. */
1183 #ifdef STACK_GROWS_DOWNWARD
1184 offset = -args_size;
1185 #else
1186 offset = args_size;
1187 #endif
1189 else if (GET_CODE (PATTERN (insn)) == SET)
1191 offset = stack_adjust_offset (PATTERN (insn));
1193 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1194 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1196 /* There may be stack adjustments inside compound insns. Search
1197 for them. */
1198 int j;
1200 offset = 0;
1201 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1203 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1204 if (GET_CODE (pattern) == SET)
1205 offset += stack_adjust_offset (pattern);
1208 else
1209 return;
1211 if (offset == 0)
1212 return;
1214 if (cfa.reg == STACK_POINTER_REGNUM)
1215 cfa.offset += offset;
1217 #ifndef STACK_GROWS_DOWNWARD
1218 offset = -offset;
1219 #endif
1220 args_size += offset;
1221 if (args_size < 0)
1222 args_size = 0;
1224 label = dwarf2out_cfi_label ();
1225 def_cfa_1 (label, &cfa);
1226 dwarf2out_args_size (label, args_size);
1229 /* A temporary register used in adjusting SP or setting up the store_reg. */
1230 static unsigned cfa_temp_reg;
1232 /* A temporary value used in adjusting SP or setting up the store_reg. */
1233 static long cfa_temp_value;
1235 /* Record call frame debugging information for an expression, which either
1236 sets SP or FP (adjusting how we calculate the frame address) or saves a
1237 register to the stack. */
1239 static void
1240 dwarf2out_frame_debug_expr (expr, label)
1241 rtx expr;
1242 const char *label;
1244 rtx src, dest;
1245 long offset;
1247 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1248 the PARALLEL independently. The first element is always processed if
1249 it is a SET. This is for backward compatability. Other elements
1250 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1251 flag is set in them. */
1253 if (GET_CODE (expr) == PARALLEL
1254 || GET_CODE (expr) == SEQUENCE)
1256 int par_index;
1257 int limit = XVECLEN (expr, 0);
1259 for (par_index = 0; par_index < limit; par_index++)
1261 rtx x = XVECEXP (expr, 0, par_index);
1263 if (GET_CODE (x) == SET &&
1264 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1265 dwarf2out_frame_debug_expr (x, label);
1267 return;
1270 if (GET_CODE (expr) != SET)
1271 abort ();
1273 src = SET_SRC (expr);
1274 dest = SET_DEST (expr);
1276 switch (GET_CODE (dest))
1278 case REG:
1279 /* Update the CFA rule wrt SP or FP. Make sure src is
1280 relative to the current CFA register. */
1281 switch (GET_CODE (src))
1283 /* Setting FP from SP. */
1284 case REG:
1285 if (cfa.reg == (unsigned) REGNO (src))
1286 /* OK. */
1288 else
1289 abort ();
1291 /* We used to require that dest be either SP or FP, but the
1292 ARM copies SP to a temporary register, and from there to
1293 FP. So we just rely on the backends to only set
1294 RTX_FRAME_RELATED_P on appropriate insns. */
1295 cfa.reg = REGNO (dest);
1296 break;
1298 case PLUS:
1299 case MINUS:
1300 if (dest == stack_pointer_rtx)
1302 /* Adjusting SP. */
1303 switch (GET_CODE (XEXP (src, 1)))
1305 case CONST_INT:
1306 offset = INTVAL (XEXP (src, 1));
1307 break;
1308 case REG:
1309 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp_reg)
1310 abort ();
1311 offset = cfa_temp_value;
1312 break;
1313 default:
1314 abort ();
1317 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1319 /* Restoring SP from FP in the epilogue. */
1320 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1321 abort ();
1322 cfa.reg = STACK_POINTER_REGNUM;
1324 else if (XEXP (src, 0) != stack_pointer_rtx)
1325 abort ();
1327 if (GET_CODE (src) == PLUS)
1328 offset = -offset;
1329 if (cfa.reg == STACK_POINTER_REGNUM)
1330 cfa.offset += offset;
1331 if (cfa_store.reg == STACK_POINTER_REGNUM)
1332 cfa_store.offset += offset;
1334 else if (dest == hard_frame_pointer_rtx)
1336 /* Either setting the FP from an offset of the SP,
1337 or adjusting the FP */
1338 if (! frame_pointer_needed)
1339 abort ();
1341 if (GET_CODE (XEXP (src, 0)) == REG
1342 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1343 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1345 offset = INTVAL (XEXP (src, 1));
1346 if (GET_CODE (src) == PLUS)
1347 offset = -offset;
1348 cfa.offset += offset;
1349 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1351 else
1352 abort ();
1354 else
1356 if (GET_CODE (src) != PLUS
1357 || XEXP (src, 1) != stack_pointer_rtx)
1358 abort ();
1359 if (GET_CODE (XEXP (src, 0)) != REG
1360 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg)
1361 abort ();
1362 if (cfa.reg != STACK_POINTER_REGNUM)
1363 abort ();
1364 cfa_store.reg = REGNO (dest);
1365 cfa_store.offset = cfa.offset - cfa_temp_value;
1367 break;
1369 case CONST_INT:
1370 cfa_temp_reg = REGNO (dest);
1371 cfa_temp_value = INTVAL (src);
1372 break;
1374 case IOR:
1375 if (GET_CODE (XEXP (src, 0)) != REG
1376 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg
1377 || (unsigned) REGNO (dest) != cfa_temp_reg
1378 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1379 abort ();
1380 cfa_temp_value |= INTVAL (XEXP (src, 1));
1381 break;
1383 default:
1384 abort ();
1386 def_cfa_1 (label, &cfa);
1387 break;
1389 /* Skip over HIGH, assuming it will be followed by a LO_SUM, which
1390 will fill in all of the bits. */
1391 case HIGH:
1392 break;
1394 case LO_SUM:
1395 cfa_temp_reg = REGNO (dest);
1396 cfa_temp_value = INTVAL (XEXP (src, 1));
1397 break;
1399 case MEM:
1400 if (GET_CODE (src) != REG)
1401 abort ();
1403 /* Saving a register to the stack. Make sure dest is relative to the
1404 CFA register. */
1405 switch (GET_CODE (XEXP (dest, 0)))
1407 /* With a push. */
1408 case PRE_INC:
1409 case PRE_DEC:
1410 offset = GET_MODE_SIZE (GET_MODE (dest));
1411 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1412 offset = -offset;
1414 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1415 || cfa_store.reg != STACK_POINTER_REGNUM)
1416 abort ();
1417 cfa_store.offset += offset;
1418 if (cfa.reg == STACK_POINTER_REGNUM)
1419 cfa.offset = cfa_store.offset;
1421 offset = -cfa_store.offset;
1422 break;
1424 /* With an offset. */
1425 case PLUS:
1426 case MINUS:
1427 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1428 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1429 offset = -offset;
1431 if (cfa_store.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1432 abort ();
1433 offset -= cfa_store.offset;
1434 break;
1436 /* Without an offset. */
1437 case REG:
1438 if (cfa_store.reg != (unsigned) REGNO (XEXP (dest, 0)))
1439 abort ();
1440 offset = -cfa_store.offset;
1441 break;
1443 default:
1444 abort ();
1447 if (REGNO (src) != STACK_POINTER_REGNUM
1448 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1449 && (unsigned) REGNO (src) == cfa.reg)
1451 /* We're storing the current CFA reg into the stack. */
1453 if (cfa.offset == 0)
1455 /* If the source register is exactly the CFA, assume
1456 we're saving SP like any other register; this happens
1457 on the ARM. */
1459 def_cfa_1 (label, &cfa);
1460 dwarf2out_reg_save (label, STACK_POINTER_REGNUM, offset);
1461 break;
1463 else
1465 /* Otherwise, we'll need to look in the stack to
1466 calculate the CFA. */
1468 rtx x = XEXP (dest, 0);
1469 if (GET_CODE (x) != REG)
1470 x = XEXP (x, 0);
1471 if (GET_CODE (x) != REG)
1472 abort ();
1473 cfa.reg = (unsigned) REGNO (x);
1474 cfa.base_offset = offset;
1475 cfa.indirect = 1;
1476 def_cfa_1 (label, &cfa);
1477 break;
1481 def_cfa_1 (label, &cfa);
1482 dwarf2out_reg_save (label, REGNO (src), offset);
1483 break;
1485 default:
1486 abort ();
1490 /* Record call frame debugging information for INSN, which either
1491 sets SP or FP (adjusting how we calculate the frame address) or saves a
1492 register to the stack. If INSN is NULL_RTX, initialize our state. */
1494 void
1495 dwarf2out_frame_debug (insn)
1496 rtx insn;
1498 const char *label;
1499 rtx src;
1501 if (insn == NULL_RTX)
1503 /* Set up state for generating call frame debug info. */
1504 lookup_cfa (&cfa);
1505 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1506 abort ();
1507 cfa.reg = STACK_POINTER_REGNUM;
1508 cfa_store = cfa;
1509 cfa_temp_reg = -1;
1510 cfa_temp_value = 0;
1511 return;
1514 if (! RTX_FRAME_RELATED_P (insn))
1516 dwarf2out_stack_adjust (insn);
1517 return;
1520 label = dwarf2out_cfi_label ();
1522 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1523 if (src)
1524 insn = XEXP (src, 0);
1525 else
1526 insn = PATTERN (insn);
1528 dwarf2out_frame_debug_expr (insn, label);
1531 /* Return the size of an unsigned LEB128 quantity. */
1533 static inline unsigned long
1534 size_of_uleb128 (value)
1535 register unsigned long value;
1537 register unsigned long size = 0;
1538 register unsigned byte;
1542 byte = (value & 0x7f);
1543 value >>= 7;
1544 size += 1;
1546 while (value != 0);
1548 return size;
1551 /* Return the size of a signed LEB128 quantity. */
1553 static inline unsigned long
1554 size_of_sleb128 (value)
1555 register long value;
1557 register unsigned long size = 0;
1558 register unsigned byte;
1562 byte = (value & 0x7f);
1563 value >>= 7;
1564 size += 1;
1566 while (!(((value == 0) && ((byte & 0x40) == 0))
1567 || ((value == -1) && ((byte & 0x40) != 0))));
1569 return size;
1572 /* Output an unsigned LEB128 quantity. */
1574 static void
1575 output_uleb128 (value)
1576 register unsigned long value;
1578 unsigned long save_value = value;
1580 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1583 register unsigned byte = (value & 0x7f);
1584 value >>= 7;
1585 if (value != 0)
1586 /* More bytes to follow. */
1587 byte |= 0x80;
1589 fprintf (asm_out_file, "0x%x", byte);
1590 if (value != 0)
1591 fprintf (asm_out_file, ",");
1593 while (value != 0);
1595 if (flag_debug_asm)
1596 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1599 /* Output an signed LEB128 quantity. */
1601 static void
1602 output_sleb128 (value)
1603 register long value;
1605 register int more;
1606 register unsigned byte;
1607 long save_value = value;
1609 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1612 byte = (value & 0x7f);
1613 /* arithmetic shift */
1614 value >>= 7;
1615 more = !((((value == 0) && ((byte & 0x40) == 0))
1616 || ((value == -1) && ((byte & 0x40) != 0))));
1617 if (more)
1618 byte |= 0x80;
1620 fprintf (asm_out_file, "0x%x", byte);
1621 if (more)
1622 fprintf (asm_out_file, ",");
1625 while (more);
1626 if (flag_debug_asm)
1627 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1630 /* Output a Call Frame Information opcode and its operand(s). */
1632 static void
1633 output_cfi (cfi, fde)
1634 register dw_cfi_ref cfi;
1635 register dw_fde_ref fde;
1637 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1639 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1640 cfi->dw_cfi_opc
1641 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1642 if (flag_debug_asm)
1643 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1644 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1645 fputc ('\n', asm_out_file);
1648 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1650 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1651 cfi->dw_cfi_opc
1652 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1653 if (flag_debug_asm)
1654 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1655 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1657 fputc ('\n', asm_out_file);
1658 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1659 fputc ('\n', asm_out_file);
1661 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1663 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1664 cfi->dw_cfi_opc
1665 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1666 if (flag_debug_asm)
1667 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1668 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1670 fputc ('\n', asm_out_file);
1672 else
1674 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1675 if (flag_debug_asm)
1676 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1677 dwarf_cfi_name (cfi->dw_cfi_opc));
1679 fputc ('\n', asm_out_file);
1680 switch (cfi->dw_cfi_opc)
1682 case DW_CFA_set_loc:
1683 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1684 fputc ('\n', asm_out_file);
1685 break;
1686 case DW_CFA_advance_loc1:
1687 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1688 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1689 fde->dw_fde_current_label);
1690 fputc ('\n', asm_out_file);
1691 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1692 break;
1693 case DW_CFA_advance_loc2:
1694 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1695 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1696 fde->dw_fde_current_label);
1697 fputc ('\n', asm_out_file);
1698 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1699 break;
1700 case DW_CFA_advance_loc4:
1701 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1702 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1703 fde->dw_fde_current_label);
1704 fputc ('\n', asm_out_file);
1705 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1706 break;
1707 #ifdef MIPS_DEBUGGING_INFO
1708 case DW_CFA_MIPS_advance_loc8:
1709 /* TODO: not currently implemented. */
1710 abort ();
1711 break;
1712 #endif
1713 case DW_CFA_offset_extended:
1714 case DW_CFA_GNU_negative_offset_extended:
1715 case DW_CFA_def_cfa:
1716 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1717 fputc ('\n', asm_out_file);
1718 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1719 fputc ('\n', asm_out_file);
1720 break;
1721 case DW_CFA_restore_extended:
1722 case DW_CFA_undefined:
1723 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1724 fputc ('\n', asm_out_file);
1725 break;
1726 case DW_CFA_same_value:
1727 case DW_CFA_def_cfa_register:
1728 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1729 fputc ('\n', asm_out_file);
1730 break;
1731 case DW_CFA_register:
1732 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1733 fputc ('\n', asm_out_file);
1734 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1735 fputc ('\n', asm_out_file);
1736 break;
1737 case DW_CFA_def_cfa_offset:
1738 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1739 fputc ('\n', asm_out_file);
1740 break;
1741 case DW_CFA_GNU_window_save:
1742 break;
1743 case DW_CFA_GNU_args_size:
1744 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1745 fputc ('\n', asm_out_file);
1746 break;
1747 case DW_CFA_def_cfa_expression:
1748 output_cfa_loc (cfi);
1749 break;
1750 default:
1751 break;
1756 /* Output the call frame information used to used to record information
1757 that relates to calculating the frame pointer, and records the
1758 location of saved registers. */
1760 static void
1761 output_call_frame_info (for_eh)
1762 int for_eh;
1764 register unsigned long i;
1765 register dw_fde_ref fde;
1766 register dw_cfi_ref cfi;
1767 char l1[20], l2[20];
1768 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1769 char ld[20];
1770 #endif
1772 /* Do we want to include a pointer to the exception table? */
1773 int eh_ptr = for_eh && exception_table_p ();
1775 /* If we don't have any functions we'll want to unwind out of, don't
1776 emit any EH unwind information. */
1777 if (for_eh)
1779 for (i = 0; i < fde_table_in_use; ++i)
1780 if (! fde_table[i].nothrow)
1781 goto found;
1782 return;
1783 found:;
1786 fputc ('\n', asm_out_file);
1788 /* We're going to be generating comments, so turn on app. */
1789 if (flag_debug_asm)
1790 app_enable ();
1792 if (for_eh)
1794 #ifdef EH_FRAME_SECTION
1795 EH_FRAME_SECTION ();
1796 #else
1797 tree label = get_file_function_name ('F');
1799 force_data_section ();
1800 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1801 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1802 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1803 #endif
1804 assemble_label ("__FRAME_BEGIN__");
1806 else
1807 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1809 /* Output the CIE. */
1810 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1811 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1812 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1813 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1814 if (for_eh)
1815 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1816 else
1817 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1818 #else
1819 if (for_eh)
1820 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1821 else
1822 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1823 #endif
1824 if (flag_debug_asm)
1825 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1826 ASM_COMMENT_START);
1828 fputc ('\n', asm_out_file);
1829 ASM_OUTPUT_LABEL (asm_out_file, l1);
1831 if (for_eh)
1832 /* Now that the CIE pointer is PC-relative for EH,
1833 use 0 to identify the CIE. */
1834 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1835 else
1836 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1838 if (flag_debug_asm)
1839 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1841 fputc ('\n', asm_out_file);
1842 if (! for_eh && DWARF_OFFSET_SIZE == 8)
1844 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1845 fputc ('\n', asm_out_file);
1848 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1849 if (flag_debug_asm)
1850 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1852 fputc ('\n', asm_out_file);
1853 if (eh_ptr)
1855 /* The CIE contains a pointer to the exception region info for the
1856 frame. Make the augmentation string three bytes (including the
1857 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1858 can't handle unaligned relocs. */
1859 if (flag_debug_asm)
1861 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1862 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1864 else
1866 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1868 fputc ('\n', asm_out_file);
1870 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1871 if (flag_debug_asm)
1872 fprintf (asm_out_file, "\t%s pointer to exception region info",
1873 ASM_COMMENT_START);
1875 else
1877 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1878 if (flag_debug_asm)
1879 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1880 ASM_COMMENT_START);
1883 fputc ('\n', asm_out_file);
1884 output_uleb128 (1);
1885 if (flag_debug_asm)
1886 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1888 fputc ('\n', asm_out_file);
1889 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1890 if (flag_debug_asm)
1891 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1893 fputc ('\n', asm_out_file);
1894 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1895 if (flag_debug_asm)
1896 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1898 fputc ('\n', asm_out_file);
1900 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1901 output_cfi (cfi, NULL);
1903 /* Pad the CIE out to an address sized boundary. */
1904 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1905 ASM_OUTPUT_LABEL (asm_out_file, l2);
1906 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1907 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1908 if (flag_debug_asm)
1909 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1910 fputc ('\n', asm_out_file);
1911 #endif
1913 /* Loop through all of the FDE's. */
1914 for (i = 0; i < fde_table_in_use; ++i)
1916 fde = &fde_table[i];
1918 /* Don't emit EH unwind info for leaf functions. */
1919 if (for_eh && fde->nothrow)
1920 continue;
1922 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1923 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1924 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1925 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i * 2);
1926 if (for_eh)
1927 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1928 else
1929 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1930 #else
1931 if (for_eh)
1932 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1933 else
1934 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1935 #endif
1936 if (flag_debug_asm)
1937 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1938 fputc ('\n', asm_out_file);
1939 ASM_OUTPUT_LABEL (asm_out_file, l1);
1941 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1942 emits a target dependent sized offset when for_eh is not true.
1943 This inconsistency may confuse gdb. The only case where we need a
1944 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1945 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1946 though in order to be compatible with the dwarf_fde struct in frame.c.
1947 If the for_eh case is changed, then the struct in frame.c has
1948 to be adjusted appropriately. */
1949 if (for_eh)
1950 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
1951 else
1952 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1953 if (flag_debug_asm)
1954 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1956 fputc ('\n', asm_out_file);
1957 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1958 if (flag_debug_asm)
1959 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1961 fputc ('\n', asm_out_file);
1962 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1963 fde->dw_fde_end, fde->dw_fde_begin);
1964 if (flag_debug_asm)
1965 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1967 fputc ('\n', asm_out_file);
1969 /* Loop through the Call Frame Instructions associated with
1970 this FDE. */
1971 fde->dw_fde_current_label = fde->dw_fde_begin;
1972 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1973 output_cfi (cfi, fde);
1975 /* Pad the FDE out to an address sized boundary. */
1976 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1977 ASM_OUTPUT_LABEL (asm_out_file, l2);
1978 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1979 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1980 if (flag_debug_asm)
1981 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
1982 fputc ('\n', asm_out_file);
1983 #endif
1985 #ifndef EH_FRAME_SECTION
1986 if (for_eh)
1988 /* Emit terminating zero for table. */
1989 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1990 fputc ('\n', asm_out_file);
1992 #endif
1993 #ifdef MIPS_DEBUGGING_INFO
1994 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1995 get a value of 0. Putting .align 0 after the label fixes it. */
1996 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1997 #endif
1999 /* Turn off app to make assembly quicker. */
2000 if (flag_debug_asm)
2001 app_disable ();
2004 /* Output a marker (i.e. a label) for the beginning of a function, before
2005 the prologue. */
2007 void
2008 dwarf2out_begin_prologue ()
2010 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2011 register dw_fde_ref fde;
2013 ++current_funcdef_number;
2015 function_section (current_function_decl);
2016 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2017 current_funcdef_number);
2018 ASM_OUTPUT_LABEL (asm_out_file, label);
2019 current_function_func_begin_label = get_identifier (label);
2021 /* Expand the fde table if necessary. */
2022 if (fde_table_in_use == fde_table_allocated)
2024 fde_table_allocated += FDE_TABLE_INCREMENT;
2025 fde_table
2026 = (dw_fde_ref) xrealloc (fde_table,
2027 fde_table_allocated * sizeof (dw_fde_node));
2030 /* Record the FDE associated with this function. */
2031 current_funcdef_fde = fde_table_in_use;
2033 /* Add the new FDE at the end of the fde_table. */
2034 fde = &fde_table[fde_table_in_use++];
2035 fde->dw_fde_begin = xstrdup (label);
2036 fde->dw_fde_current_label = NULL;
2037 fde->dw_fde_end = NULL;
2038 fde->dw_fde_cfi = NULL;
2039 fde->nothrow = current_function_nothrow;
2041 args_size = old_args_size = 0;
2044 /* Output a marker (i.e. a label) for the absolute end of the generated code
2045 for a function definition. This gets called *after* the epilogue code has
2046 been generated. */
2048 void
2049 dwarf2out_end_epilogue ()
2051 dw_fde_ref fde;
2052 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2054 /* Output a label to mark the endpoint of the code generated for this
2055 function. */
2056 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2057 ASM_OUTPUT_LABEL (asm_out_file, label);
2058 fde = &fde_table[fde_table_in_use - 1];
2059 fde->dw_fde_end = xstrdup (label);
2062 void
2063 dwarf2out_frame_init ()
2065 /* Allocate the initial hunk of the fde_table. */
2066 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2067 fde_table_allocated = FDE_TABLE_INCREMENT;
2068 fde_table_in_use = 0;
2070 /* Generate the CFA instructions common to all FDE's. Do it now for the
2071 sake of lookup_cfa. */
2073 #ifdef DWARF2_UNWIND_INFO
2074 /* On entry, the Canonical Frame Address is at SP. */
2075 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2076 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2077 #endif
2080 void
2081 dwarf2out_frame_finish ()
2083 /* Output call frame information. */
2084 #ifdef MIPS_DEBUGGING_INFO
2085 if (write_symbols == DWARF2_DEBUG)
2086 output_call_frame_info (0);
2087 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2088 output_call_frame_info (1);
2089 #else
2090 if (write_symbols == DWARF2_DEBUG
2091 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2092 output_call_frame_info (1);
2093 #endif
2096 /* And now, the subset of the debugging information support code necessary
2097 for emitting location expressions. */
2099 typedef struct dw_val_struct *dw_val_ref;
2100 typedef struct die_struct *dw_die_ref;
2101 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2103 /* Each DIE may have a series of attribute/value pairs. Values
2104 can take on several forms. The forms that are used in this
2105 implementation are listed below. */
2107 typedef enum
2109 dw_val_class_addr,
2110 dw_val_class_loc,
2111 dw_val_class_const,
2112 dw_val_class_unsigned_const,
2113 dw_val_class_long_long,
2114 dw_val_class_float,
2115 dw_val_class_flag,
2116 dw_val_class_die_ref,
2117 dw_val_class_fde_ref,
2118 dw_val_class_lbl_id,
2119 dw_val_class_lbl_offset,
2120 dw_val_class_str
2122 dw_val_class;
2124 /* Describe a double word constant value. */
2125 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2127 typedef struct dw_long_long_struct
2129 unsigned long hi;
2130 unsigned long low;
2132 dw_long_long_const;
2134 /* Describe a floating point constant value. */
2136 typedef struct dw_fp_struct
2138 long *array;
2139 unsigned length;
2141 dw_float_const;
2143 /* The dw_val_node describes an attribute's value, as it is
2144 represented internally. */
2146 typedef struct dw_val_struct
2148 dw_val_class val_class;
2149 union
2151 rtx val_addr;
2152 dw_loc_descr_ref val_loc;
2153 long int val_int;
2154 long unsigned val_unsigned;
2155 dw_long_long_const val_long_long;
2156 dw_float_const val_float;
2157 struct {
2158 dw_die_ref die;
2159 int external;
2160 } val_die_ref;
2161 unsigned val_fde_index;
2162 char *val_str;
2163 char *val_lbl_id;
2164 unsigned char val_flag;
2168 dw_val_node;
2170 /* Locations in memory are described using a sequence of stack machine
2171 operations. */
2173 typedef struct dw_loc_descr_struct
2175 dw_loc_descr_ref dw_loc_next;
2176 enum dwarf_location_atom dw_loc_opc;
2177 dw_val_node dw_loc_oprnd1;
2178 dw_val_node dw_loc_oprnd2;
2179 int dw_loc_addr;
2181 dw_loc_descr_node;
2183 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2184 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2185 unsigned long,
2186 unsigned long));
2187 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2188 dw_loc_descr_ref));
2189 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2190 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2191 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2192 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2194 /* Convert a DWARF stack opcode into its string name. */
2196 static const char *
2197 dwarf_stack_op_name (op)
2198 register unsigned op;
2200 switch (op)
2202 case DW_OP_addr:
2203 return "DW_OP_addr";
2204 case DW_OP_deref:
2205 return "DW_OP_deref";
2206 case DW_OP_const1u:
2207 return "DW_OP_const1u";
2208 case DW_OP_const1s:
2209 return "DW_OP_const1s";
2210 case DW_OP_const2u:
2211 return "DW_OP_const2u";
2212 case DW_OP_const2s:
2213 return "DW_OP_const2s";
2214 case DW_OP_const4u:
2215 return "DW_OP_const4u";
2216 case DW_OP_const4s:
2217 return "DW_OP_const4s";
2218 case DW_OP_const8u:
2219 return "DW_OP_const8u";
2220 case DW_OP_const8s:
2221 return "DW_OP_const8s";
2222 case DW_OP_constu:
2223 return "DW_OP_constu";
2224 case DW_OP_consts:
2225 return "DW_OP_consts";
2226 case DW_OP_dup:
2227 return "DW_OP_dup";
2228 case DW_OP_drop:
2229 return "DW_OP_drop";
2230 case DW_OP_over:
2231 return "DW_OP_over";
2232 case DW_OP_pick:
2233 return "DW_OP_pick";
2234 case DW_OP_swap:
2235 return "DW_OP_swap";
2236 case DW_OP_rot:
2237 return "DW_OP_rot";
2238 case DW_OP_xderef:
2239 return "DW_OP_xderef";
2240 case DW_OP_abs:
2241 return "DW_OP_abs";
2242 case DW_OP_and:
2243 return "DW_OP_and";
2244 case DW_OP_div:
2245 return "DW_OP_div";
2246 case DW_OP_minus:
2247 return "DW_OP_minus";
2248 case DW_OP_mod:
2249 return "DW_OP_mod";
2250 case DW_OP_mul:
2251 return "DW_OP_mul";
2252 case DW_OP_neg:
2253 return "DW_OP_neg";
2254 case DW_OP_not:
2255 return "DW_OP_not";
2256 case DW_OP_or:
2257 return "DW_OP_or";
2258 case DW_OP_plus:
2259 return "DW_OP_plus";
2260 case DW_OP_plus_uconst:
2261 return "DW_OP_plus_uconst";
2262 case DW_OP_shl:
2263 return "DW_OP_shl";
2264 case DW_OP_shr:
2265 return "DW_OP_shr";
2266 case DW_OP_shra:
2267 return "DW_OP_shra";
2268 case DW_OP_xor:
2269 return "DW_OP_xor";
2270 case DW_OP_bra:
2271 return "DW_OP_bra";
2272 case DW_OP_eq:
2273 return "DW_OP_eq";
2274 case DW_OP_ge:
2275 return "DW_OP_ge";
2276 case DW_OP_gt:
2277 return "DW_OP_gt";
2278 case DW_OP_le:
2279 return "DW_OP_le";
2280 case DW_OP_lt:
2281 return "DW_OP_lt";
2282 case DW_OP_ne:
2283 return "DW_OP_ne";
2284 case DW_OP_skip:
2285 return "DW_OP_skip";
2286 case DW_OP_lit0:
2287 return "DW_OP_lit0";
2288 case DW_OP_lit1:
2289 return "DW_OP_lit1";
2290 case DW_OP_lit2:
2291 return "DW_OP_lit2";
2292 case DW_OP_lit3:
2293 return "DW_OP_lit3";
2294 case DW_OP_lit4:
2295 return "DW_OP_lit4";
2296 case DW_OP_lit5:
2297 return "DW_OP_lit5";
2298 case DW_OP_lit6:
2299 return "DW_OP_lit6";
2300 case DW_OP_lit7:
2301 return "DW_OP_lit7";
2302 case DW_OP_lit8:
2303 return "DW_OP_lit8";
2304 case DW_OP_lit9:
2305 return "DW_OP_lit9";
2306 case DW_OP_lit10:
2307 return "DW_OP_lit10";
2308 case DW_OP_lit11:
2309 return "DW_OP_lit11";
2310 case DW_OP_lit12:
2311 return "DW_OP_lit12";
2312 case DW_OP_lit13:
2313 return "DW_OP_lit13";
2314 case DW_OP_lit14:
2315 return "DW_OP_lit14";
2316 case DW_OP_lit15:
2317 return "DW_OP_lit15";
2318 case DW_OP_lit16:
2319 return "DW_OP_lit16";
2320 case DW_OP_lit17:
2321 return "DW_OP_lit17";
2322 case DW_OP_lit18:
2323 return "DW_OP_lit18";
2324 case DW_OP_lit19:
2325 return "DW_OP_lit19";
2326 case DW_OP_lit20:
2327 return "DW_OP_lit20";
2328 case DW_OP_lit21:
2329 return "DW_OP_lit21";
2330 case DW_OP_lit22:
2331 return "DW_OP_lit22";
2332 case DW_OP_lit23:
2333 return "DW_OP_lit23";
2334 case DW_OP_lit24:
2335 return "DW_OP_lit24";
2336 case DW_OP_lit25:
2337 return "DW_OP_lit25";
2338 case DW_OP_lit26:
2339 return "DW_OP_lit26";
2340 case DW_OP_lit27:
2341 return "DW_OP_lit27";
2342 case DW_OP_lit28:
2343 return "DW_OP_lit28";
2344 case DW_OP_lit29:
2345 return "DW_OP_lit29";
2346 case DW_OP_lit30:
2347 return "DW_OP_lit30";
2348 case DW_OP_lit31:
2349 return "DW_OP_lit31";
2350 case DW_OP_reg0:
2351 return "DW_OP_reg0";
2352 case DW_OP_reg1:
2353 return "DW_OP_reg1";
2354 case DW_OP_reg2:
2355 return "DW_OP_reg2";
2356 case DW_OP_reg3:
2357 return "DW_OP_reg3";
2358 case DW_OP_reg4:
2359 return "DW_OP_reg4";
2360 case DW_OP_reg5:
2361 return "DW_OP_reg5";
2362 case DW_OP_reg6:
2363 return "DW_OP_reg6";
2364 case DW_OP_reg7:
2365 return "DW_OP_reg7";
2366 case DW_OP_reg8:
2367 return "DW_OP_reg8";
2368 case DW_OP_reg9:
2369 return "DW_OP_reg9";
2370 case DW_OP_reg10:
2371 return "DW_OP_reg10";
2372 case DW_OP_reg11:
2373 return "DW_OP_reg11";
2374 case DW_OP_reg12:
2375 return "DW_OP_reg12";
2376 case DW_OP_reg13:
2377 return "DW_OP_reg13";
2378 case DW_OP_reg14:
2379 return "DW_OP_reg14";
2380 case DW_OP_reg15:
2381 return "DW_OP_reg15";
2382 case DW_OP_reg16:
2383 return "DW_OP_reg16";
2384 case DW_OP_reg17:
2385 return "DW_OP_reg17";
2386 case DW_OP_reg18:
2387 return "DW_OP_reg18";
2388 case DW_OP_reg19:
2389 return "DW_OP_reg19";
2390 case DW_OP_reg20:
2391 return "DW_OP_reg20";
2392 case DW_OP_reg21:
2393 return "DW_OP_reg21";
2394 case DW_OP_reg22:
2395 return "DW_OP_reg22";
2396 case DW_OP_reg23:
2397 return "DW_OP_reg23";
2398 case DW_OP_reg24:
2399 return "DW_OP_reg24";
2400 case DW_OP_reg25:
2401 return "DW_OP_reg25";
2402 case DW_OP_reg26:
2403 return "DW_OP_reg26";
2404 case DW_OP_reg27:
2405 return "DW_OP_reg27";
2406 case DW_OP_reg28:
2407 return "DW_OP_reg28";
2408 case DW_OP_reg29:
2409 return "DW_OP_reg29";
2410 case DW_OP_reg30:
2411 return "DW_OP_reg30";
2412 case DW_OP_reg31:
2413 return "DW_OP_reg31";
2414 case DW_OP_breg0:
2415 return "DW_OP_breg0";
2416 case DW_OP_breg1:
2417 return "DW_OP_breg1";
2418 case DW_OP_breg2:
2419 return "DW_OP_breg2";
2420 case DW_OP_breg3:
2421 return "DW_OP_breg3";
2422 case DW_OP_breg4:
2423 return "DW_OP_breg4";
2424 case DW_OP_breg5:
2425 return "DW_OP_breg5";
2426 case DW_OP_breg6:
2427 return "DW_OP_breg6";
2428 case DW_OP_breg7:
2429 return "DW_OP_breg7";
2430 case DW_OP_breg8:
2431 return "DW_OP_breg8";
2432 case DW_OP_breg9:
2433 return "DW_OP_breg9";
2434 case DW_OP_breg10:
2435 return "DW_OP_breg10";
2436 case DW_OP_breg11:
2437 return "DW_OP_breg11";
2438 case DW_OP_breg12:
2439 return "DW_OP_breg12";
2440 case DW_OP_breg13:
2441 return "DW_OP_breg13";
2442 case DW_OP_breg14:
2443 return "DW_OP_breg14";
2444 case DW_OP_breg15:
2445 return "DW_OP_breg15";
2446 case DW_OP_breg16:
2447 return "DW_OP_breg16";
2448 case DW_OP_breg17:
2449 return "DW_OP_breg17";
2450 case DW_OP_breg18:
2451 return "DW_OP_breg18";
2452 case DW_OP_breg19:
2453 return "DW_OP_breg19";
2454 case DW_OP_breg20:
2455 return "DW_OP_breg20";
2456 case DW_OP_breg21:
2457 return "DW_OP_breg21";
2458 case DW_OP_breg22:
2459 return "DW_OP_breg22";
2460 case DW_OP_breg23:
2461 return "DW_OP_breg23";
2462 case DW_OP_breg24:
2463 return "DW_OP_breg24";
2464 case DW_OP_breg25:
2465 return "DW_OP_breg25";
2466 case DW_OP_breg26:
2467 return "DW_OP_breg26";
2468 case DW_OP_breg27:
2469 return "DW_OP_breg27";
2470 case DW_OP_breg28:
2471 return "DW_OP_breg28";
2472 case DW_OP_breg29:
2473 return "DW_OP_breg29";
2474 case DW_OP_breg30:
2475 return "DW_OP_breg30";
2476 case DW_OP_breg31:
2477 return "DW_OP_breg31";
2478 case DW_OP_regx:
2479 return "DW_OP_regx";
2480 case DW_OP_fbreg:
2481 return "DW_OP_fbreg";
2482 case DW_OP_bregx:
2483 return "DW_OP_bregx";
2484 case DW_OP_piece:
2485 return "DW_OP_piece";
2486 case DW_OP_deref_size:
2487 return "DW_OP_deref_size";
2488 case DW_OP_xderef_size:
2489 return "DW_OP_xderef_size";
2490 case DW_OP_nop:
2491 return "DW_OP_nop";
2492 default:
2493 return "OP_<unknown>";
2497 /* Return a pointer to a newly allocated location description. Location
2498 descriptions are simple expression terms that can be strung
2499 together to form more complicated location (address) descriptions. */
2501 static inline dw_loc_descr_ref
2502 new_loc_descr (op, oprnd1, oprnd2)
2503 register enum dwarf_location_atom op;
2504 register unsigned long oprnd1;
2505 register unsigned long oprnd2;
2507 /* Use xcalloc here so we clear out all of the long_long constant in
2508 the union. */
2509 register dw_loc_descr_ref descr
2510 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2512 descr->dw_loc_opc = op;
2513 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2514 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2515 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2516 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2518 return descr;
2521 /* Add a location description term to a location description expression. */
2523 static inline void
2524 add_loc_descr (list_head, descr)
2525 register dw_loc_descr_ref *list_head;
2526 register dw_loc_descr_ref descr;
2528 register dw_loc_descr_ref *d;
2530 /* Find the end of the chain. */
2531 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2534 *d = descr;
2537 /* Return the size of a location descriptor. */
2539 static unsigned long
2540 size_of_loc_descr (loc)
2541 register dw_loc_descr_ref loc;
2543 register unsigned long size = 1;
2545 switch (loc->dw_loc_opc)
2547 case DW_OP_addr:
2548 size += DWARF2_ADDR_SIZE;
2549 break;
2550 case DW_OP_const1u:
2551 case DW_OP_const1s:
2552 size += 1;
2553 break;
2554 case DW_OP_const2u:
2555 case DW_OP_const2s:
2556 size += 2;
2557 break;
2558 case DW_OP_const4u:
2559 case DW_OP_const4s:
2560 size += 4;
2561 break;
2562 case DW_OP_const8u:
2563 case DW_OP_const8s:
2564 size += 8;
2565 break;
2566 case DW_OP_constu:
2567 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2568 break;
2569 case DW_OP_consts:
2570 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2571 break;
2572 case DW_OP_pick:
2573 size += 1;
2574 break;
2575 case DW_OP_plus_uconst:
2576 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2577 break;
2578 case DW_OP_skip:
2579 case DW_OP_bra:
2580 size += 2;
2581 break;
2582 case DW_OP_breg0:
2583 case DW_OP_breg1:
2584 case DW_OP_breg2:
2585 case DW_OP_breg3:
2586 case DW_OP_breg4:
2587 case DW_OP_breg5:
2588 case DW_OP_breg6:
2589 case DW_OP_breg7:
2590 case DW_OP_breg8:
2591 case DW_OP_breg9:
2592 case DW_OP_breg10:
2593 case DW_OP_breg11:
2594 case DW_OP_breg12:
2595 case DW_OP_breg13:
2596 case DW_OP_breg14:
2597 case DW_OP_breg15:
2598 case DW_OP_breg16:
2599 case DW_OP_breg17:
2600 case DW_OP_breg18:
2601 case DW_OP_breg19:
2602 case DW_OP_breg20:
2603 case DW_OP_breg21:
2604 case DW_OP_breg22:
2605 case DW_OP_breg23:
2606 case DW_OP_breg24:
2607 case DW_OP_breg25:
2608 case DW_OP_breg26:
2609 case DW_OP_breg27:
2610 case DW_OP_breg28:
2611 case DW_OP_breg29:
2612 case DW_OP_breg30:
2613 case DW_OP_breg31:
2614 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2615 break;
2616 case DW_OP_regx:
2617 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2618 break;
2619 case DW_OP_fbreg:
2620 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2621 break;
2622 case DW_OP_bregx:
2623 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2624 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2625 break;
2626 case DW_OP_piece:
2627 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2628 break;
2629 case DW_OP_deref_size:
2630 case DW_OP_xderef_size:
2631 size += 1;
2632 break;
2633 default:
2634 break;
2637 return size;
2640 /* Return the size of a series of location descriptors. */
2642 static unsigned long
2643 size_of_locs (loc)
2644 register dw_loc_descr_ref loc;
2646 register unsigned long size = 0;
2648 for (; loc != NULL; loc = loc->dw_loc_next)
2650 loc->dw_loc_addr = size;
2651 size += size_of_loc_descr (loc);
2654 return size;
2657 /* Output location description stack opcode's operands (if any). */
2659 static void
2660 output_loc_operands (loc)
2661 register dw_loc_descr_ref loc;
2663 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2664 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2666 switch (loc->dw_loc_opc)
2668 #ifdef DWARF2_DEBUGGING_INFO
2669 case DW_OP_addr:
2670 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
2671 fputc ('\n', asm_out_file);
2672 break;
2673 case DW_OP_const2u:
2674 case DW_OP_const2s:
2675 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
2676 fputc ('\n', asm_out_file);
2677 break;
2678 case DW_OP_const4u:
2679 case DW_OP_const4s:
2680 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
2681 fputc ('\n', asm_out_file);
2682 break;
2683 case DW_OP_const8u:
2684 case DW_OP_const8s:
2685 abort ();
2686 fputc ('\n', asm_out_file);
2687 break;
2688 case DW_OP_skip:
2689 case DW_OP_bra:
2691 int offset;
2693 if (val1->val_class == dw_val_class_loc)
2694 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2695 else
2696 abort ();
2698 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, offset);
2699 fputc ('\n', asm_out_file);
2701 break;
2702 #else
2703 case DW_OP_addr:
2704 case DW_OP_const2u:
2705 case DW_OP_const2s:
2706 case DW_OP_const4u:
2707 case DW_OP_const4s:
2708 case DW_OP_const8u:
2709 case DW_OP_const8s:
2710 case DW_OP_skip:
2711 case DW_OP_bra:
2712 /* We currently don't make any attempt to make sure these are
2713 aligned properly like we do for the main unwind info, so
2714 don't support emitting things larger than a byte if we're
2715 only doing unwinding. */
2716 abort ();
2717 #endif
2718 case DW_OP_const1u:
2719 case DW_OP_const1s:
2720 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2721 fputc ('\n', asm_out_file);
2722 break;
2723 case DW_OP_constu:
2724 output_uleb128 (val1->v.val_unsigned);
2725 fputc ('\n', asm_out_file);
2726 break;
2727 case DW_OP_consts:
2728 output_sleb128 (val1->v.val_int);
2729 fputc ('\n', asm_out_file);
2730 break;
2731 case DW_OP_pick:
2732 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
2733 fputc ('\n', asm_out_file);
2734 break;
2735 case DW_OP_plus_uconst:
2736 output_uleb128 (val1->v.val_unsigned);
2737 fputc ('\n', asm_out_file);
2738 break;
2739 case DW_OP_breg0:
2740 case DW_OP_breg1:
2741 case DW_OP_breg2:
2742 case DW_OP_breg3:
2743 case DW_OP_breg4:
2744 case DW_OP_breg5:
2745 case DW_OP_breg6:
2746 case DW_OP_breg7:
2747 case DW_OP_breg8:
2748 case DW_OP_breg9:
2749 case DW_OP_breg10:
2750 case DW_OP_breg11:
2751 case DW_OP_breg12:
2752 case DW_OP_breg13:
2753 case DW_OP_breg14:
2754 case DW_OP_breg15:
2755 case DW_OP_breg16:
2756 case DW_OP_breg17:
2757 case DW_OP_breg18:
2758 case DW_OP_breg19:
2759 case DW_OP_breg20:
2760 case DW_OP_breg21:
2761 case DW_OP_breg22:
2762 case DW_OP_breg23:
2763 case DW_OP_breg24:
2764 case DW_OP_breg25:
2765 case DW_OP_breg26:
2766 case DW_OP_breg27:
2767 case DW_OP_breg28:
2768 case DW_OP_breg29:
2769 case DW_OP_breg30:
2770 case DW_OP_breg31:
2771 output_sleb128 (val1->v.val_int);
2772 fputc ('\n', asm_out_file);
2773 break;
2774 case DW_OP_regx:
2775 output_uleb128 (val1->v.val_unsigned);
2776 fputc ('\n', asm_out_file);
2777 break;
2778 case DW_OP_fbreg:
2779 output_sleb128 (val1->v.val_int);
2780 fputc ('\n', asm_out_file);
2781 break;
2782 case DW_OP_bregx:
2783 output_uleb128 (val1->v.val_unsigned);
2784 fputc ('\n', asm_out_file);
2785 output_sleb128 (val2->v.val_int);
2786 fputc ('\n', asm_out_file);
2787 break;
2788 case DW_OP_piece:
2789 output_uleb128 (val1->v.val_unsigned);
2790 fputc ('\n', asm_out_file);
2791 break;
2792 case DW_OP_deref_size:
2793 case DW_OP_xderef_size:
2794 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2795 fputc ('\n', asm_out_file);
2796 break;
2797 default:
2798 /* Other codes have no operands. */
2799 break;
2803 /* Output a sequence of location operations. */
2805 static void
2806 output_loc_sequence (loc)
2807 dw_loc_descr_ref loc;
2809 for (; loc != NULL; loc = loc->dw_loc_next)
2811 /* Output the opcode. */
2812 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
2813 if (flag_debug_asm)
2814 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
2815 dwarf_stack_op_name (loc->dw_loc_opc));
2817 fputc ('\n', asm_out_file);
2819 /* Output the operand(s) (if any). */
2820 output_loc_operands (loc);
2824 /* This routine will generate the correct assembly data for a location
2825 description based on a cfi entry with a complex address. */
2827 static void
2828 output_cfa_loc (cfi)
2829 dw_cfi_ref cfi;
2831 dw_loc_descr_ref loc;
2832 unsigned long size;
2834 /* Output the size of the block. */
2835 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2836 size = size_of_locs (loc);
2837 output_uleb128 (size);
2838 fputc ('\n', asm_out_file);
2840 /* Now output the operations themselves. */
2841 output_loc_sequence (loc);
2844 /* This function builds a dwarf location descriptor seqeunce from
2845 a dw_cfa_location. */
2847 static struct dw_loc_descr_struct *
2848 build_cfa_loc (cfa)
2849 dw_cfa_location *cfa;
2851 struct dw_loc_descr_struct *head, *tmp;
2853 if (cfa->indirect == 0)
2854 abort ();
2856 if (cfa->base_offset)
2858 if (cfa->reg <= 31)
2859 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2860 else
2861 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2863 else if (cfa->reg <= 31)
2864 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2865 else
2866 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2867 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2868 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2869 add_loc_descr (&head, tmp);
2870 if (cfa->offset != 0)
2872 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2873 add_loc_descr (&head, tmp);
2875 return head;
2878 /* This function fills in aa dw_cfa_location structure from a
2879 dwarf location descriptor sequence. */
2881 static void
2882 get_cfa_from_loc_descr (cfa, loc)
2883 dw_cfa_location *cfa;
2884 struct dw_loc_descr_struct *loc;
2886 struct dw_loc_descr_struct *ptr;
2887 cfa->offset = 0;
2888 cfa->base_offset = 0;
2889 cfa->indirect = 0;
2890 cfa->reg = -1;
2892 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2894 enum dwarf_location_atom op = ptr->dw_loc_opc;
2895 switch (op)
2897 case DW_OP_reg0:
2898 case DW_OP_reg1:
2899 case DW_OP_reg2:
2900 case DW_OP_reg3:
2901 case DW_OP_reg4:
2902 case DW_OP_reg5:
2903 case DW_OP_reg6:
2904 case DW_OP_reg7:
2905 case DW_OP_reg8:
2906 case DW_OP_reg9:
2907 case DW_OP_reg10:
2908 case DW_OP_reg11:
2909 case DW_OP_reg12:
2910 case DW_OP_reg13:
2911 case DW_OP_reg14:
2912 case DW_OP_reg15:
2913 case DW_OP_reg16:
2914 case DW_OP_reg17:
2915 case DW_OP_reg18:
2916 case DW_OP_reg19:
2917 case DW_OP_reg20:
2918 case DW_OP_reg21:
2919 case DW_OP_reg22:
2920 case DW_OP_reg23:
2921 case DW_OP_reg24:
2922 case DW_OP_reg25:
2923 case DW_OP_reg26:
2924 case DW_OP_reg27:
2925 case DW_OP_reg28:
2926 case DW_OP_reg29:
2927 case DW_OP_reg30:
2928 case DW_OP_reg31:
2929 cfa->reg = op - DW_OP_reg0;
2930 break;
2931 case DW_OP_regx:
2932 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2933 break;
2934 case DW_OP_breg0:
2935 case DW_OP_breg1:
2936 case DW_OP_breg2:
2937 case DW_OP_breg3:
2938 case DW_OP_breg4:
2939 case DW_OP_breg5:
2940 case DW_OP_breg6:
2941 case DW_OP_breg7:
2942 case DW_OP_breg8:
2943 case DW_OP_breg9:
2944 case DW_OP_breg10:
2945 case DW_OP_breg11:
2946 case DW_OP_breg12:
2947 case DW_OP_breg13:
2948 case DW_OP_breg14:
2949 case DW_OP_breg15:
2950 case DW_OP_breg16:
2951 case DW_OP_breg17:
2952 case DW_OP_breg18:
2953 case DW_OP_breg19:
2954 case DW_OP_breg20:
2955 case DW_OP_breg21:
2956 case DW_OP_breg22:
2957 case DW_OP_breg23:
2958 case DW_OP_breg24:
2959 case DW_OP_breg25:
2960 case DW_OP_breg26:
2961 case DW_OP_breg27:
2962 case DW_OP_breg28:
2963 case DW_OP_breg29:
2964 case DW_OP_breg30:
2965 case DW_OP_breg31:
2966 cfa->reg = op - DW_OP_breg0;
2967 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2968 break;
2969 case DW_OP_bregx:
2970 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2971 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
2972 break;
2973 case DW_OP_deref:
2974 cfa->indirect = 1;
2975 break;
2976 case DW_OP_plus_uconst:
2977 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
2978 break;
2979 default:
2980 fatal ("DW_LOC_OP %s not implememnted yet.\n",
2981 dwarf_stack_op_name (ptr->dw_loc_opc));
2985 #endif /* .debug_frame support */
2987 /* And now, the support for symbolic debugging information. */
2988 #ifdef DWARF2_DEBUGGING_INFO
2990 /* NOTE: In the comments in this file, many references are made to
2991 "Debugging Information Entries". This term is abbreviated as `DIE'
2992 throughout the remainder of this file. */
2994 /* An internal representation of the DWARF output is built, and then
2995 walked to generate the DWARF debugging info. The walk of the internal
2996 representation is done after the entire program has been compiled.
2997 The types below are used to describe the internal representation. */
2999 /* Various DIE's use offsets relative to the beginning of the
3000 .debug_info section to refer to each other. */
3002 typedef long int dw_offset;
3004 /* Define typedefs here to avoid circular dependencies. */
3006 typedef struct dw_attr_struct *dw_attr_ref;
3007 typedef struct dw_line_info_struct *dw_line_info_ref;
3008 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3009 typedef struct pubname_struct *pubname_ref;
3010 typedef dw_die_ref *arange_ref;
3012 /* Each entry in the line_info_table maintains the file and
3013 line number associated with the label generated for that
3014 entry. The label gives the PC value associated with
3015 the line number entry. */
3017 typedef struct dw_line_info_struct
3019 unsigned long dw_file_num;
3020 unsigned long dw_line_num;
3022 dw_line_info_entry;
3024 /* Line information for functions in separate sections; each one gets its
3025 own sequence. */
3026 typedef struct dw_separate_line_info_struct
3028 unsigned long dw_file_num;
3029 unsigned long dw_line_num;
3030 unsigned long function;
3032 dw_separate_line_info_entry;
3034 /* Each DIE attribute has a field specifying the attribute kind,
3035 a link to the next attribute in the chain, and an attribute value.
3036 Attributes are typically linked below the DIE they modify. */
3038 typedef struct dw_attr_struct
3040 enum dwarf_attribute dw_attr;
3041 dw_attr_ref dw_attr_next;
3042 dw_val_node dw_attr_val;
3044 dw_attr_node;
3046 /* The Debugging Information Entry (DIE) structure */
3048 typedef struct die_struct
3050 enum dwarf_tag die_tag;
3051 char *die_symbol;
3052 dw_attr_ref die_attr;
3053 dw_die_ref die_parent;
3054 dw_die_ref die_child;
3055 dw_die_ref die_sib;
3056 dw_offset die_offset;
3057 unsigned long die_abbrev;
3058 int die_mark;
3060 die_node;
3062 /* The pubname structure */
3064 typedef struct pubname_struct
3066 dw_die_ref die;
3067 char *name;
3069 pubname_entry;
3071 /* The limbo die list structure. */
3072 typedef struct limbo_die_struct
3074 dw_die_ref die;
3075 struct limbo_die_struct *next;
3077 limbo_die_node;
3079 /* How to start an assembler comment. */
3080 #ifndef ASM_COMMENT_START
3081 #define ASM_COMMENT_START ";#"
3082 #endif
3084 /* Define a macro which returns non-zero for a TYPE_DECL which was
3085 implicitly generated for a tagged type.
3087 Note that unlike the gcc front end (which generates a NULL named
3088 TYPE_DECL node for each complete tagged type, each array type, and
3089 each function type node created) the g++ front end generates a
3090 _named_ TYPE_DECL node for each tagged type node created.
3091 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3092 generate a DW_TAG_typedef DIE for them. */
3094 #define TYPE_DECL_IS_STUB(decl) \
3095 (DECL_NAME (decl) == NULL_TREE \
3096 || (DECL_ARTIFICIAL (decl) \
3097 && is_tagged_type (TREE_TYPE (decl)) \
3098 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3099 /* This is necessary for stub decls that \
3100 appear in nested inline functions. */ \
3101 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3102 && (decl_ultimate_origin (decl) \
3103 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3105 /* Information concerning the compilation unit's programming
3106 language, and compiler version. */
3108 extern int flag_traditional;
3110 /* Fixed size portion of the DWARF compilation unit header. */
3111 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3113 /* Fixed size portion of debugging line information prolog. */
3114 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3116 /* Fixed size portion of public names info. */
3117 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3119 /* Fixed size portion of the address range info. */
3120 #define DWARF_ARANGES_HEADER_SIZE \
3121 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3122 - DWARF_OFFSET_SIZE)
3124 /* Size of padding portion in the address range info. It must be
3125 aligned to twice the pointer size. */
3126 #define DWARF_ARANGES_PAD_SIZE \
3127 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3128 - (2 * DWARF_OFFSET_SIZE + 4))
3130 /* The default is to have gcc emit the line number tables. */
3131 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3132 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3133 #endif
3135 /* Define the architecture-dependent minimum instruction length (in bytes).
3136 In this implementation of DWARF, this field is used for information
3137 purposes only. Since GCC generates assembly language, we have
3138 no a priori knowledge of how many instruction bytes are generated
3139 for each source line, and therefore can use only the DW_LNE_set_address
3140 and DW_LNS_fixed_advance_pc line information commands. */
3142 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3143 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3144 #endif
3146 /* Minimum line offset in a special line info. opcode.
3147 This value was chosen to give a reasonable range of values. */
3148 #define DWARF_LINE_BASE -10
3150 /* First special line opcde - leave room for the standard opcodes. */
3151 #define DWARF_LINE_OPCODE_BASE 10
3153 /* Range of line offsets in a special line info. opcode. */
3154 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3156 /* Flag that indicates the initial value of the is_stmt_start flag.
3157 In the present implementation, we do not mark any lines as
3158 the beginning of a source statement, because that information
3159 is not made available by the GCC front-end. */
3160 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3162 /* This location is used by calc_die_sizes() to keep track
3163 the offset of each DIE within the .debug_info section. */
3164 static unsigned long next_die_offset;
3166 /* Record the root of the DIE's built for the current compilation unit. */
3167 static dw_die_ref comp_unit_die;
3169 /* A list of DIEs with a NULL parent waiting to be relocated. */
3170 static limbo_die_node *limbo_die_list = 0;
3172 /* Pointer to an array of filenames referenced by this compilation unit. */
3173 static char **file_table;
3175 /* Total number of entries in the table (i.e. array) pointed to by
3176 `file_table'. This is the *total* and includes both used and unused
3177 slots. */
3178 static unsigned file_table_allocated;
3180 /* Number of entries in the file_table which are actually in use. */
3181 static unsigned file_table_in_use;
3183 /* Size (in elements) of increments by which we may expand the filename
3184 table. */
3185 #define FILE_TABLE_INCREMENT 64
3187 /* Local pointer to the name of the main input file. Initialized in
3188 dwarf2out_init. */
3189 static const char *primary_filename;
3191 /* A pointer to the base of a table of references to DIE's that describe
3192 declarations. The table is indexed by DECL_UID() which is a unique
3193 number identifying each decl. */
3194 static dw_die_ref *decl_die_table;
3196 /* Number of elements currently allocated for the decl_die_table. */
3197 static unsigned decl_die_table_allocated;
3199 /* Number of elements in decl_die_table currently in use. */
3200 static unsigned decl_die_table_in_use;
3202 /* Size (in elements) of increments by which we may expand the
3203 decl_die_table. */
3204 #define DECL_DIE_TABLE_INCREMENT 256
3206 /* A pointer to the base of a table of references to declaration
3207 scopes. This table is a display which tracks the nesting
3208 of declaration scopes at the current scope and containing
3209 scopes. This table is used to find the proper place to
3210 define type declaration DIE's. */
3211 static tree *decl_scope_table;
3213 /* Number of elements currently allocated for the decl_scope_table. */
3214 static int decl_scope_table_allocated;
3216 /* Current level of nesting of declaration scopes. */
3217 static int decl_scope_depth;
3219 /* Size (in elements) of increments by which we may expand the
3220 decl_scope_table. */
3221 #define DECL_SCOPE_TABLE_INCREMENT 64
3223 /* A pointer to the base of a list of references to DIE's that
3224 are uniquely identified by their tag, presence/absence of
3225 children DIE's, and list of attribute/value pairs. */
3226 static dw_die_ref *abbrev_die_table;
3228 /* Number of elements currently allocated for abbrev_die_table. */
3229 static unsigned abbrev_die_table_allocated;
3231 /* Number of elements in type_die_table currently in use. */
3232 static unsigned abbrev_die_table_in_use;
3234 /* Size (in elements) of increments by which we may expand the
3235 abbrev_die_table. */
3236 #define ABBREV_DIE_TABLE_INCREMENT 256
3238 /* A pointer to the base of a table that contains line information
3239 for each source code line in .text in the compilation unit. */
3240 static dw_line_info_ref line_info_table;
3242 /* Number of elements currently allocated for line_info_table. */
3243 static unsigned line_info_table_allocated;
3245 /* Number of elements in separate_line_info_table currently in use. */
3246 static unsigned separate_line_info_table_in_use;
3248 /* A pointer to the base of a table that contains line information
3249 for each source code line outside of .text in the compilation unit. */
3250 static dw_separate_line_info_ref separate_line_info_table;
3252 /* Number of elements currently allocated for separate_line_info_table. */
3253 static unsigned separate_line_info_table_allocated;
3255 /* Number of elements in line_info_table currently in use. */
3256 static unsigned line_info_table_in_use;
3258 /* Size (in elements) of increments by which we may expand the
3259 line_info_table. */
3260 #define LINE_INFO_TABLE_INCREMENT 1024
3262 /* A pointer to the base of a table that contains a list of publicly
3263 accessible names. */
3264 static pubname_ref pubname_table;
3266 /* Number of elements currently allocated for pubname_table. */
3267 static unsigned pubname_table_allocated;
3269 /* Number of elements in pubname_table currently in use. */
3270 static unsigned pubname_table_in_use;
3272 /* Size (in elements) of increments by which we may expand the
3273 pubname_table. */
3274 #define PUBNAME_TABLE_INCREMENT 64
3276 /* A pointer to the base of a table that contains a list of publicly
3277 accessible names. */
3278 static arange_ref arange_table;
3280 /* Number of elements currently allocated for arange_table. */
3281 static unsigned arange_table_allocated;
3283 /* Number of elements in arange_table currently in use. */
3284 static unsigned arange_table_in_use;
3286 /* Size (in elements) of increments by which we may expand the
3287 arange_table. */
3288 #define ARANGE_TABLE_INCREMENT 64
3290 /* A pointer to the base of a list of incomplete types which might be
3291 completed at some later time. */
3293 static tree *incomplete_types_list;
3295 /* Number of elements currently allocated for the incomplete_types_list. */
3296 static unsigned incomplete_types_allocated;
3298 /* Number of elements of incomplete_types_list currently in use. */
3299 static unsigned incomplete_types;
3301 /* Size (in elements) of increments by which we may expand the incomplete
3302 types list. Actually, a single hunk of space of this size should
3303 be enough for most typical programs. */
3304 #define INCOMPLETE_TYPES_INCREMENT 64
3306 /* Record whether the function being analyzed contains inlined functions. */
3307 static int current_function_has_inlines;
3308 #if 0 && defined (MIPS_DEBUGGING_INFO)
3309 static int comp_unit_has_inlines;
3310 #endif
3312 /* Array of RTXes referenced by the debugging information, which therefore
3313 must be kept around forever. We do this rather than perform GC on
3314 the dwarf info because almost all of the dwarf info lives forever, and
3315 it's easier to support non-GC frontends this way. */
3316 static varray_type used_rtx_varray;
3318 /* Forward declarations for functions defined in this file. */
3320 static int is_pseudo_reg PARAMS ((rtx));
3321 static tree type_main_variant PARAMS ((tree));
3322 static int is_tagged_type PARAMS ((tree));
3323 static const char *dwarf_tag_name PARAMS ((unsigned));
3324 static const char *dwarf_attr_name PARAMS ((unsigned));
3325 static const char *dwarf_form_name PARAMS ((unsigned));
3326 #if 0
3327 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3328 #endif
3329 static tree decl_ultimate_origin PARAMS ((tree));
3330 static tree block_ultimate_origin PARAMS ((tree));
3331 static tree decl_class_context PARAMS ((tree));
3332 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3333 static void add_AT_flag PARAMS ((dw_die_ref,
3334 enum dwarf_attribute,
3335 unsigned));
3336 static void add_AT_int PARAMS ((dw_die_ref,
3337 enum dwarf_attribute, long));
3338 static void add_AT_unsigned PARAMS ((dw_die_ref,
3339 enum dwarf_attribute,
3340 unsigned long));
3341 static void add_AT_long_long PARAMS ((dw_die_ref,
3342 enum dwarf_attribute,
3343 unsigned long,
3344 unsigned long));
3345 static void add_AT_float PARAMS ((dw_die_ref,
3346 enum dwarf_attribute,
3347 unsigned, long *));
3348 static void add_AT_string PARAMS ((dw_die_ref,
3349 enum dwarf_attribute,
3350 const char *));
3351 static void add_AT_die_ref PARAMS ((dw_die_ref,
3352 enum dwarf_attribute,
3353 dw_die_ref));
3354 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3355 enum dwarf_attribute,
3356 unsigned));
3357 static void add_AT_loc PARAMS ((dw_die_ref,
3358 enum dwarf_attribute,
3359 dw_loc_descr_ref));
3360 static void add_AT_addr PARAMS ((dw_die_ref,
3361 enum dwarf_attribute,
3362 rtx));
3363 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3364 enum dwarf_attribute,
3365 const char *));
3366 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3367 enum dwarf_attribute,
3368 const char *));
3369 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3370 enum dwarf_attribute));
3371 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3372 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3373 static const char *get_AT_string PARAMS ((dw_die_ref,
3374 enum dwarf_attribute));
3375 static int get_AT_flag PARAMS ((dw_die_ref,
3376 enum dwarf_attribute));
3377 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3378 enum dwarf_attribute));
3379 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3380 enum dwarf_attribute));
3381 static int is_c_family PARAMS ((void));
3382 static int is_java PARAMS ((void));
3383 static int is_fortran PARAMS ((void));
3384 static void remove_AT PARAMS ((dw_die_ref,
3385 enum dwarf_attribute));
3386 static void remove_children PARAMS ((dw_die_ref));
3387 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3388 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3389 static dw_die_ref lookup_type_die PARAMS ((tree));
3390 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3391 static dw_die_ref lookup_decl_die PARAMS ((tree));
3392 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3393 static void print_spaces PARAMS ((FILE *));
3394 static void print_die PARAMS ((dw_die_ref, FILE *));
3395 static void print_dwarf_line_table PARAMS ((FILE *));
3396 static void reverse_die_lists PARAMS ((dw_die_ref));
3397 static void reverse_all_dies PARAMS ((dw_die_ref));
3398 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3399 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3400 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3401 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3402 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3403 static void compute_section_prefix PARAMS ((dw_die_ref));
3404 static int is_type_die PARAMS ((dw_die_ref));
3405 static int is_comdat_die PARAMS ((dw_die_ref));
3406 static int is_symbol_die PARAMS ((dw_die_ref));
3407 static char *gen_internal_sym PARAMS ((void));
3408 static void assign_symbol_names PARAMS ((dw_die_ref));
3409 static void break_out_includes PARAMS ((dw_die_ref));
3410 static void add_sibling_attributes PARAMS ((dw_die_ref));
3411 static void build_abbrev_table PARAMS ((dw_die_ref));
3412 static unsigned long size_of_string PARAMS ((const char *));
3413 static int constant_size PARAMS ((long unsigned));
3414 static unsigned long size_of_die PARAMS ((dw_die_ref));
3415 static void calc_die_sizes PARAMS ((dw_die_ref));
3416 static void mark_dies PARAMS ((dw_die_ref));
3417 static void unmark_dies PARAMS ((dw_die_ref));
3418 static unsigned long size_of_line_prolog PARAMS ((void));
3419 static unsigned long size_of_pubnames PARAMS ((void));
3420 static unsigned long size_of_aranges PARAMS ((void));
3421 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3422 static void output_value_format PARAMS ((dw_attr_ref));
3423 static void output_abbrev_section PARAMS ((void));
3424 static void output_die_symbol PARAMS ((dw_die_ref));
3425 static void output_symbolic_ref PARAMS ((dw_die_ref));
3426 static void output_die PARAMS ((dw_die_ref));
3427 static void output_compilation_unit_header PARAMS ((void));
3428 static void output_comp_unit PARAMS ((dw_die_ref));
3429 static const char *dwarf2_name PARAMS ((tree, int));
3430 static void add_pubname PARAMS ((tree, dw_die_ref));
3431 static void output_pubnames PARAMS ((void));
3432 static void add_arange PARAMS ((tree, dw_die_ref));
3433 static void output_aranges PARAMS ((void));
3434 static void output_line_info PARAMS ((void));
3435 static dw_die_ref base_type_die PARAMS ((tree));
3436 static tree root_type PARAMS ((tree));
3437 static int is_base_type PARAMS ((tree));
3438 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3439 static int type_is_enum PARAMS ((tree));
3440 static unsigned int reg_number PARAMS ((rtx));
3441 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3442 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3443 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3444 static int is_based_loc PARAMS ((rtx));
3445 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3446 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3447 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3448 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3449 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3450 static tree field_type PARAMS ((tree));
3451 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3452 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3453 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3454 static void add_AT_location_description PARAMS ((dw_die_ref,
3455 enum dwarf_attribute, rtx));
3456 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3457 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3458 static rtx rtl_for_decl_location PARAMS ((tree));
3459 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3460 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3461 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3462 static void add_bound_info PARAMS ((dw_die_ref,
3463 enum dwarf_attribute, tree));
3464 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3465 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3466 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3467 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3468 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3469 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3470 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3471 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3472 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3473 static void push_decl_scope PARAMS ((tree));
3474 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3475 static void pop_decl_scope PARAMS ((void));
3476 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3477 dw_die_ref));
3478 static const char *type_tag PARAMS ((tree));
3479 static tree member_declared_type PARAMS ((tree));
3480 #if 0
3481 static const char *decl_start_label PARAMS ((tree));
3482 #endif
3483 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3484 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3485 #if 0
3486 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3487 #endif
3488 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3489 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3490 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3491 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3492 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3493 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3494 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3495 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3496 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3497 static void gen_label_die PARAMS ((tree, dw_die_ref));
3498 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3499 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3500 static void gen_field_die PARAMS ((tree, dw_die_ref));
3501 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3502 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3503 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3504 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3505 static void gen_member_die PARAMS ((tree, dw_die_ref));
3506 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3507 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3508 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3509 static void gen_type_die PARAMS ((tree, dw_die_ref));
3510 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3511 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3512 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3513 static int is_redundant_typedef PARAMS ((tree));
3514 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3515 static unsigned lookup_filename PARAMS ((const char *));
3516 static void add_incomplete_type PARAMS ((tree));
3517 static void retry_incomplete_types PARAMS ((void));
3518 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3519 static void gen_abstract_function PARAMS ((tree));
3520 static rtx save_rtx PARAMS ((rtx));
3521 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3523 /* Section names used to hold DWARF debugging information. */
3524 #ifndef DEBUG_INFO_SECTION
3525 #define DEBUG_INFO_SECTION ".debug_info"
3526 #endif
3527 #ifndef ABBREV_SECTION
3528 #define ABBREV_SECTION ".debug_abbrev"
3529 #endif
3530 #ifndef ARANGES_SECTION
3531 #define ARANGES_SECTION ".debug_aranges"
3532 #endif
3533 #ifndef DW_MACINFO_SECTION
3534 #define DW_MACINFO_SECTION ".debug_macinfo"
3535 #endif
3536 #ifndef DEBUG_LINE_SECTION
3537 #define DEBUG_LINE_SECTION ".debug_line"
3538 #endif
3539 #ifndef LOC_SECTION
3540 #define LOC_SECTION ".debug_loc"
3541 #endif
3542 #ifndef PUBNAMES_SECTION
3543 #define PUBNAMES_SECTION ".debug_pubnames"
3544 #endif
3545 #ifndef STR_SECTION
3546 #define STR_SECTION ".debug_str"
3547 #endif
3549 /* Standard ELF section names for compiled code and data. */
3550 #ifndef TEXT_SECTION
3551 #define TEXT_SECTION ".text"
3552 #endif
3553 #ifndef DATA_SECTION
3554 #define DATA_SECTION ".data"
3555 #endif
3556 #ifndef BSS_SECTION
3557 #define BSS_SECTION ".bss"
3558 #endif
3560 /* Labels we insert at beginning sections we can reference instead of
3561 the section names themselves. */
3563 #ifndef TEXT_SECTION_LABEL
3564 #define TEXT_SECTION_LABEL "Ltext"
3565 #endif
3566 #ifndef DEBUG_LINE_SECTION_LABEL
3567 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3568 #endif
3569 #ifndef DEBUG_INFO_SECTION_LABEL
3570 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3571 #endif
3572 #ifndef ABBREV_SECTION_LABEL
3573 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3574 #endif
3576 /* Definitions of defaults for formats and names of various special
3577 (artificial) labels which may be generated within this file (when the -g
3578 options is used and DWARF_DEBUGGING_INFO is in effect.
3579 If necessary, these may be overridden from within the tm.h file, but
3580 typically, overriding these defaults is unnecessary. */
3582 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3583 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3584 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3585 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3586 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3588 #ifndef TEXT_END_LABEL
3589 #define TEXT_END_LABEL "Letext"
3590 #endif
3591 #ifndef DATA_END_LABEL
3592 #define DATA_END_LABEL "Ledata"
3593 #endif
3594 #ifndef BSS_END_LABEL
3595 #define BSS_END_LABEL "Lebss"
3596 #endif
3597 #ifndef BLOCK_BEGIN_LABEL
3598 #define BLOCK_BEGIN_LABEL "LBB"
3599 #endif
3600 #ifndef BLOCK_END_LABEL
3601 #define BLOCK_END_LABEL "LBE"
3602 #endif
3603 #ifndef BODY_BEGIN_LABEL
3604 #define BODY_BEGIN_LABEL "Lbb"
3605 #endif
3606 #ifndef BODY_END_LABEL
3607 #define BODY_END_LABEL "Lbe"
3608 #endif
3609 #ifndef LINE_CODE_LABEL
3610 #define LINE_CODE_LABEL "LM"
3611 #endif
3612 #ifndef SEPARATE_LINE_CODE_LABEL
3613 #define SEPARATE_LINE_CODE_LABEL "LSM"
3614 #endif
3616 /* We allow a language front-end to designate a function that is to be
3617 called to "demangle" any name before it it put into a DIE. */
3619 static const char *(*demangle_name_func) PARAMS ((const char *));
3621 void
3622 dwarf2out_set_demangle_name_func (func)
3623 const char *(*func) PARAMS ((const char *));
3625 demangle_name_func = func;
3628 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3629 that means adding it to used_rtx_varray. If not, that means making
3630 a copy on the permanent_obstack. */
3632 static rtx
3633 save_rtx (orig)
3634 register rtx orig;
3636 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3638 return orig;
3641 /* Test if rtl node points to a pseudo register. */
3643 static inline int
3644 is_pseudo_reg (rtl)
3645 register rtx rtl;
3647 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3648 || (GET_CODE (rtl) == SUBREG
3649 && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER));
3652 /* Return a reference to a type, with its const and volatile qualifiers
3653 removed. */
3655 static inline tree
3656 type_main_variant (type)
3657 register tree type;
3659 type = TYPE_MAIN_VARIANT (type);
3661 /* There really should be only one main variant among any group of variants
3662 of a given type (and all of the MAIN_VARIANT values for all members of
3663 the group should point to that one type) but sometimes the C front-end
3664 messes this up for array types, so we work around that bug here. */
3666 if (TREE_CODE (type) == ARRAY_TYPE)
3667 while (type != TYPE_MAIN_VARIANT (type))
3668 type = TYPE_MAIN_VARIANT (type);
3670 return type;
3673 /* Return non-zero if the given type node represents a tagged type. */
3675 static inline int
3676 is_tagged_type (type)
3677 register tree type;
3679 register enum tree_code code = TREE_CODE (type);
3681 return (code == RECORD_TYPE || code == UNION_TYPE
3682 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3685 /* Convert a DIE tag into its string name. */
3687 static const char *
3688 dwarf_tag_name (tag)
3689 register unsigned tag;
3691 switch (tag)
3693 case DW_TAG_padding:
3694 return "DW_TAG_padding";
3695 case DW_TAG_array_type:
3696 return "DW_TAG_array_type";
3697 case DW_TAG_class_type:
3698 return "DW_TAG_class_type";
3699 case DW_TAG_entry_point:
3700 return "DW_TAG_entry_point";
3701 case DW_TAG_enumeration_type:
3702 return "DW_TAG_enumeration_type";
3703 case DW_TAG_formal_parameter:
3704 return "DW_TAG_formal_parameter";
3705 case DW_TAG_imported_declaration:
3706 return "DW_TAG_imported_declaration";
3707 case DW_TAG_label:
3708 return "DW_TAG_label";
3709 case DW_TAG_lexical_block:
3710 return "DW_TAG_lexical_block";
3711 case DW_TAG_member:
3712 return "DW_TAG_member";
3713 case DW_TAG_pointer_type:
3714 return "DW_TAG_pointer_type";
3715 case DW_TAG_reference_type:
3716 return "DW_TAG_reference_type";
3717 case DW_TAG_compile_unit:
3718 return "DW_TAG_compile_unit";
3719 case DW_TAG_string_type:
3720 return "DW_TAG_string_type";
3721 case DW_TAG_structure_type:
3722 return "DW_TAG_structure_type";
3723 case DW_TAG_subroutine_type:
3724 return "DW_TAG_subroutine_type";
3725 case DW_TAG_typedef:
3726 return "DW_TAG_typedef";
3727 case DW_TAG_union_type:
3728 return "DW_TAG_union_type";
3729 case DW_TAG_unspecified_parameters:
3730 return "DW_TAG_unspecified_parameters";
3731 case DW_TAG_variant:
3732 return "DW_TAG_variant";
3733 case DW_TAG_common_block:
3734 return "DW_TAG_common_block";
3735 case DW_TAG_common_inclusion:
3736 return "DW_TAG_common_inclusion";
3737 case DW_TAG_inheritance:
3738 return "DW_TAG_inheritance";
3739 case DW_TAG_inlined_subroutine:
3740 return "DW_TAG_inlined_subroutine";
3741 case DW_TAG_module:
3742 return "DW_TAG_module";
3743 case DW_TAG_ptr_to_member_type:
3744 return "DW_TAG_ptr_to_member_type";
3745 case DW_TAG_set_type:
3746 return "DW_TAG_set_type";
3747 case DW_TAG_subrange_type:
3748 return "DW_TAG_subrange_type";
3749 case DW_TAG_with_stmt:
3750 return "DW_TAG_with_stmt";
3751 case DW_TAG_access_declaration:
3752 return "DW_TAG_access_declaration";
3753 case DW_TAG_base_type:
3754 return "DW_TAG_base_type";
3755 case DW_TAG_catch_block:
3756 return "DW_TAG_catch_block";
3757 case DW_TAG_const_type:
3758 return "DW_TAG_const_type";
3759 case DW_TAG_constant:
3760 return "DW_TAG_constant";
3761 case DW_TAG_enumerator:
3762 return "DW_TAG_enumerator";
3763 case DW_TAG_file_type:
3764 return "DW_TAG_file_type";
3765 case DW_TAG_friend:
3766 return "DW_TAG_friend";
3767 case DW_TAG_namelist:
3768 return "DW_TAG_namelist";
3769 case DW_TAG_namelist_item:
3770 return "DW_TAG_namelist_item";
3771 case DW_TAG_packed_type:
3772 return "DW_TAG_packed_type";
3773 case DW_TAG_subprogram:
3774 return "DW_TAG_subprogram";
3775 case DW_TAG_template_type_param:
3776 return "DW_TAG_template_type_param";
3777 case DW_TAG_template_value_param:
3778 return "DW_TAG_template_value_param";
3779 case DW_TAG_thrown_type:
3780 return "DW_TAG_thrown_type";
3781 case DW_TAG_try_block:
3782 return "DW_TAG_try_block";
3783 case DW_TAG_variant_part:
3784 return "DW_TAG_variant_part";
3785 case DW_TAG_variable:
3786 return "DW_TAG_variable";
3787 case DW_TAG_volatile_type:
3788 return "DW_TAG_volatile_type";
3789 case DW_TAG_MIPS_loop:
3790 return "DW_TAG_MIPS_loop";
3791 case DW_TAG_format_label:
3792 return "DW_TAG_format_label";
3793 case DW_TAG_function_template:
3794 return "DW_TAG_function_template";
3795 case DW_TAG_class_template:
3796 return "DW_TAG_class_template";
3797 case DW_TAG_GNU_BINCL:
3798 return "DW_TAG_GNU_BINCL";
3799 case DW_TAG_GNU_EINCL:
3800 return "DW_TAG_GNU_EINCL";
3801 default:
3802 return "DW_TAG_<unknown>";
3806 /* Convert a DWARF attribute code into its string name. */
3808 static const char *
3809 dwarf_attr_name (attr)
3810 register unsigned attr;
3812 switch (attr)
3814 case DW_AT_sibling:
3815 return "DW_AT_sibling";
3816 case DW_AT_location:
3817 return "DW_AT_location";
3818 case DW_AT_name:
3819 return "DW_AT_name";
3820 case DW_AT_ordering:
3821 return "DW_AT_ordering";
3822 case DW_AT_subscr_data:
3823 return "DW_AT_subscr_data";
3824 case DW_AT_byte_size:
3825 return "DW_AT_byte_size";
3826 case DW_AT_bit_offset:
3827 return "DW_AT_bit_offset";
3828 case DW_AT_bit_size:
3829 return "DW_AT_bit_size";
3830 case DW_AT_element_list:
3831 return "DW_AT_element_list";
3832 case DW_AT_stmt_list:
3833 return "DW_AT_stmt_list";
3834 case DW_AT_low_pc:
3835 return "DW_AT_low_pc";
3836 case DW_AT_high_pc:
3837 return "DW_AT_high_pc";
3838 case DW_AT_language:
3839 return "DW_AT_language";
3840 case DW_AT_member:
3841 return "DW_AT_member";
3842 case DW_AT_discr:
3843 return "DW_AT_discr";
3844 case DW_AT_discr_value:
3845 return "DW_AT_discr_value";
3846 case DW_AT_visibility:
3847 return "DW_AT_visibility";
3848 case DW_AT_import:
3849 return "DW_AT_import";
3850 case DW_AT_string_length:
3851 return "DW_AT_string_length";
3852 case DW_AT_common_reference:
3853 return "DW_AT_common_reference";
3854 case DW_AT_comp_dir:
3855 return "DW_AT_comp_dir";
3856 case DW_AT_const_value:
3857 return "DW_AT_const_value";
3858 case DW_AT_containing_type:
3859 return "DW_AT_containing_type";
3860 case DW_AT_default_value:
3861 return "DW_AT_default_value";
3862 case DW_AT_inline:
3863 return "DW_AT_inline";
3864 case DW_AT_is_optional:
3865 return "DW_AT_is_optional";
3866 case DW_AT_lower_bound:
3867 return "DW_AT_lower_bound";
3868 case DW_AT_producer:
3869 return "DW_AT_producer";
3870 case DW_AT_prototyped:
3871 return "DW_AT_prototyped";
3872 case DW_AT_return_addr:
3873 return "DW_AT_return_addr";
3874 case DW_AT_start_scope:
3875 return "DW_AT_start_scope";
3876 case DW_AT_stride_size:
3877 return "DW_AT_stride_size";
3878 case DW_AT_upper_bound:
3879 return "DW_AT_upper_bound";
3880 case DW_AT_abstract_origin:
3881 return "DW_AT_abstract_origin";
3882 case DW_AT_accessibility:
3883 return "DW_AT_accessibility";
3884 case DW_AT_address_class:
3885 return "DW_AT_address_class";
3886 case DW_AT_artificial:
3887 return "DW_AT_artificial";
3888 case DW_AT_base_types:
3889 return "DW_AT_base_types";
3890 case DW_AT_calling_convention:
3891 return "DW_AT_calling_convention";
3892 case DW_AT_count:
3893 return "DW_AT_count";
3894 case DW_AT_data_member_location:
3895 return "DW_AT_data_member_location";
3896 case DW_AT_decl_column:
3897 return "DW_AT_decl_column";
3898 case DW_AT_decl_file:
3899 return "DW_AT_decl_file";
3900 case DW_AT_decl_line:
3901 return "DW_AT_decl_line";
3902 case DW_AT_declaration:
3903 return "DW_AT_declaration";
3904 case DW_AT_discr_list:
3905 return "DW_AT_discr_list";
3906 case DW_AT_encoding:
3907 return "DW_AT_encoding";
3908 case DW_AT_external:
3909 return "DW_AT_external";
3910 case DW_AT_frame_base:
3911 return "DW_AT_frame_base";
3912 case DW_AT_friend:
3913 return "DW_AT_friend";
3914 case DW_AT_identifier_case:
3915 return "DW_AT_identifier_case";
3916 case DW_AT_macro_info:
3917 return "DW_AT_macro_info";
3918 case DW_AT_namelist_items:
3919 return "DW_AT_namelist_items";
3920 case DW_AT_priority:
3921 return "DW_AT_priority";
3922 case DW_AT_segment:
3923 return "DW_AT_segment";
3924 case DW_AT_specification:
3925 return "DW_AT_specification";
3926 case DW_AT_static_link:
3927 return "DW_AT_static_link";
3928 case DW_AT_type:
3929 return "DW_AT_type";
3930 case DW_AT_use_location:
3931 return "DW_AT_use_location";
3932 case DW_AT_variable_parameter:
3933 return "DW_AT_variable_parameter";
3934 case DW_AT_virtuality:
3935 return "DW_AT_virtuality";
3936 case DW_AT_vtable_elem_location:
3937 return "DW_AT_vtable_elem_location";
3939 case DW_AT_MIPS_fde:
3940 return "DW_AT_MIPS_fde";
3941 case DW_AT_MIPS_loop_begin:
3942 return "DW_AT_MIPS_loop_begin";
3943 case DW_AT_MIPS_tail_loop_begin:
3944 return "DW_AT_MIPS_tail_loop_begin";
3945 case DW_AT_MIPS_epilog_begin:
3946 return "DW_AT_MIPS_epilog_begin";
3947 case DW_AT_MIPS_loop_unroll_factor:
3948 return "DW_AT_MIPS_loop_unroll_factor";
3949 case DW_AT_MIPS_software_pipeline_depth:
3950 return "DW_AT_MIPS_software_pipeline_depth";
3951 case DW_AT_MIPS_linkage_name:
3952 return "DW_AT_MIPS_linkage_name";
3953 case DW_AT_MIPS_stride:
3954 return "DW_AT_MIPS_stride";
3955 case DW_AT_MIPS_abstract_name:
3956 return "DW_AT_MIPS_abstract_name";
3957 case DW_AT_MIPS_clone_origin:
3958 return "DW_AT_MIPS_clone_origin";
3959 case DW_AT_MIPS_has_inlines:
3960 return "DW_AT_MIPS_has_inlines";
3962 case DW_AT_sf_names:
3963 return "DW_AT_sf_names";
3964 case DW_AT_src_info:
3965 return "DW_AT_src_info";
3966 case DW_AT_mac_info:
3967 return "DW_AT_mac_info";
3968 case DW_AT_src_coords:
3969 return "DW_AT_src_coords";
3970 case DW_AT_body_begin:
3971 return "DW_AT_body_begin";
3972 case DW_AT_body_end:
3973 return "DW_AT_body_end";
3974 default:
3975 return "DW_AT_<unknown>";
3979 /* Convert a DWARF value form code into its string name. */
3981 static const char *
3982 dwarf_form_name (form)
3983 register unsigned form;
3985 switch (form)
3987 case DW_FORM_addr:
3988 return "DW_FORM_addr";
3989 case DW_FORM_block2:
3990 return "DW_FORM_block2";
3991 case DW_FORM_block4:
3992 return "DW_FORM_block4";
3993 case DW_FORM_data2:
3994 return "DW_FORM_data2";
3995 case DW_FORM_data4:
3996 return "DW_FORM_data4";
3997 case DW_FORM_data8:
3998 return "DW_FORM_data8";
3999 case DW_FORM_string:
4000 return "DW_FORM_string";
4001 case DW_FORM_block:
4002 return "DW_FORM_block";
4003 case DW_FORM_block1:
4004 return "DW_FORM_block1";
4005 case DW_FORM_data1:
4006 return "DW_FORM_data1";
4007 case DW_FORM_flag:
4008 return "DW_FORM_flag";
4009 case DW_FORM_sdata:
4010 return "DW_FORM_sdata";
4011 case DW_FORM_strp:
4012 return "DW_FORM_strp";
4013 case DW_FORM_udata:
4014 return "DW_FORM_udata";
4015 case DW_FORM_ref_addr:
4016 return "DW_FORM_ref_addr";
4017 case DW_FORM_ref1:
4018 return "DW_FORM_ref1";
4019 case DW_FORM_ref2:
4020 return "DW_FORM_ref2";
4021 case DW_FORM_ref4:
4022 return "DW_FORM_ref4";
4023 case DW_FORM_ref8:
4024 return "DW_FORM_ref8";
4025 case DW_FORM_ref_udata:
4026 return "DW_FORM_ref_udata";
4027 case DW_FORM_indirect:
4028 return "DW_FORM_indirect";
4029 default:
4030 return "DW_FORM_<unknown>";
4034 /* Convert a DWARF type code into its string name. */
4036 #if 0
4037 static const char *
4038 dwarf_type_encoding_name (enc)
4039 register unsigned enc;
4041 switch (enc)
4043 case DW_ATE_address:
4044 return "DW_ATE_address";
4045 case DW_ATE_boolean:
4046 return "DW_ATE_boolean";
4047 case DW_ATE_complex_float:
4048 return "DW_ATE_complex_float";
4049 case DW_ATE_float:
4050 return "DW_ATE_float";
4051 case DW_ATE_signed:
4052 return "DW_ATE_signed";
4053 case DW_ATE_signed_char:
4054 return "DW_ATE_signed_char";
4055 case DW_ATE_unsigned:
4056 return "DW_ATE_unsigned";
4057 case DW_ATE_unsigned_char:
4058 return "DW_ATE_unsigned_char";
4059 default:
4060 return "DW_ATE_<unknown>";
4063 #endif
4065 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4066 instance of an inlined instance of a decl which is local to an inline
4067 function, so we have to trace all of the way back through the origin chain
4068 to find out what sort of node actually served as the original seed for the
4069 given block. */
4071 static tree
4072 decl_ultimate_origin (decl)
4073 register tree decl;
4075 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4076 nodes in the function to point to themselves; ignore that if
4077 we're trying to output the abstract instance of this function. */
4078 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4079 return NULL_TREE;
4081 #ifdef ENABLE_CHECKING
4082 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4083 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4084 most distant ancestor, this should never happen. */
4085 abort ();
4086 #endif
4088 return DECL_ABSTRACT_ORIGIN (decl);
4091 /* Determine the "ultimate origin" of a block. The block may be an inlined
4092 instance of an inlined instance of a block which is local to an inline
4093 function, so we have to trace all of the way back through the origin chain
4094 to find out what sort of node actually served as the original seed for the
4095 given block. */
4097 static tree
4098 block_ultimate_origin (block)
4099 register tree block;
4101 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4103 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4104 nodes in the function to point to themselves; ignore that if
4105 we're trying to output the abstract instance of this function. */
4106 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4107 return NULL_TREE;
4109 if (immediate_origin == NULL_TREE)
4110 return NULL_TREE;
4111 else
4113 register tree ret_val;
4114 register tree lookahead = immediate_origin;
4118 ret_val = lookahead;
4119 lookahead = (TREE_CODE (ret_val) == BLOCK)
4120 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4121 : NULL;
4123 while (lookahead != NULL && lookahead != ret_val);
4125 return ret_val;
4129 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4130 of a virtual function may refer to a base class, so we check the 'this'
4131 parameter. */
4133 static tree
4134 decl_class_context (decl)
4135 tree decl;
4137 tree context = NULL_TREE;
4139 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4140 context = DECL_CONTEXT (decl);
4141 else
4142 context = TYPE_MAIN_VARIANT
4143 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4145 if (context && !TYPE_P (context))
4146 context = NULL_TREE;
4148 return context;
4151 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4152 addition order, and correct that in reverse_all_dies. */
4154 static inline void
4155 add_dwarf_attr (die, attr)
4156 register dw_die_ref die;
4157 register dw_attr_ref attr;
4159 if (die != NULL && attr != NULL)
4161 attr->dw_attr_next = die->die_attr;
4162 die->die_attr = attr;
4166 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4167 static inline dw_val_class
4168 AT_class (a)
4169 dw_attr_ref a;
4171 return a->dw_attr_val.val_class;
4174 /* Add a flag value attribute to a DIE. */
4176 static inline void
4177 add_AT_flag (die, attr_kind, flag)
4178 register dw_die_ref die;
4179 register enum dwarf_attribute attr_kind;
4180 register unsigned flag;
4182 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4184 attr->dw_attr_next = NULL;
4185 attr->dw_attr = attr_kind;
4186 attr->dw_attr_val.val_class = dw_val_class_flag;
4187 attr->dw_attr_val.v.val_flag = flag;
4188 add_dwarf_attr (die, attr);
4191 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4192 static inline unsigned
4193 AT_flag (a)
4194 register dw_attr_ref a;
4196 if (a && AT_class (a) == dw_val_class_flag)
4197 return a->dw_attr_val.v.val_flag;
4199 abort ();
4202 /* Add a signed integer attribute value to a DIE. */
4204 static inline void
4205 add_AT_int (die, attr_kind, int_val)
4206 register dw_die_ref die;
4207 register enum dwarf_attribute attr_kind;
4208 register long int int_val;
4210 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4212 attr->dw_attr_next = NULL;
4213 attr->dw_attr = attr_kind;
4214 attr->dw_attr_val.val_class = dw_val_class_const;
4215 attr->dw_attr_val.v.val_int = int_val;
4216 add_dwarf_attr (die, attr);
4219 static inline long int AT_int PARAMS ((dw_attr_ref));
4220 static inline long int
4221 AT_int (a)
4222 register dw_attr_ref a;
4224 if (a && AT_class (a) == dw_val_class_const)
4225 return a->dw_attr_val.v.val_int;
4227 abort ();
4230 /* Add an unsigned integer attribute value to a DIE. */
4232 static inline void
4233 add_AT_unsigned (die, attr_kind, unsigned_val)
4234 register dw_die_ref die;
4235 register enum dwarf_attribute attr_kind;
4236 register unsigned long unsigned_val;
4238 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4240 attr->dw_attr_next = NULL;
4241 attr->dw_attr = attr_kind;
4242 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4243 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4244 add_dwarf_attr (die, attr);
4247 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4248 static inline unsigned long
4249 AT_unsigned (a)
4250 register dw_attr_ref a;
4252 if (a && AT_class (a) == dw_val_class_unsigned_const)
4253 return a->dw_attr_val.v.val_unsigned;
4255 abort ();
4258 /* Add an unsigned double integer attribute value to a DIE. */
4260 static inline void
4261 add_AT_long_long (die, attr_kind, val_hi, val_low)
4262 register dw_die_ref die;
4263 register enum dwarf_attribute attr_kind;
4264 register unsigned long val_hi;
4265 register unsigned long val_low;
4267 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4269 attr->dw_attr_next = NULL;
4270 attr->dw_attr = attr_kind;
4271 attr->dw_attr_val.val_class = dw_val_class_long_long;
4272 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4273 attr->dw_attr_val.v.val_long_long.low = val_low;
4274 add_dwarf_attr (die, attr);
4277 /* Add a floating point attribute value to a DIE and return it. */
4279 static inline void
4280 add_AT_float (die, attr_kind, length, array)
4281 register dw_die_ref die;
4282 register enum dwarf_attribute attr_kind;
4283 register unsigned length;
4284 register long *array;
4286 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4288 attr->dw_attr_next = NULL;
4289 attr->dw_attr = attr_kind;
4290 attr->dw_attr_val.val_class = dw_val_class_float;
4291 attr->dw_attr_val.v.val_float.length = length;
4292 attr->dw_attr_val.v.val_float.array = array;
4293 add_dwarf_attr (die, attr);
4296 /* Add a string attribute value to a DIE. */
4298 static inline void
4299 add_AT_string (die, attr_kind, str)
4300 register dw_die_ref die;
4301 register enum dwarf_attribute attr_kind;
4302 register const char *str;
4304 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4306 attr->dw_attr_next = NULL;
4307 attr->dw_attr = attr_kind;
4308 attr->dw_attr_val.val_class = dw_val_class_str;
4309 attr->dw_attr_val.v.val_str = xstrdup (str);
4310 add_dwarf_attr (die, attr);
4313 static inline const char *AT_string PARAMS ((dw_attr_ref));
4314 static inline const char *
4315 AT_string (a)
4316 register dw_attr_ref a;
4318 if (a && AT_class (a) == dw_val_class_str)
4319 return a->dw_attr_val.v.val_str;
4321 abort ();
4324 /* Add a DIE reference attribute value to a DIE. */
4326 static inline void
4327 add_AT_die_ref (die, attr_kind, targ_die)
4328 register dw_die_ref die;
4329 register enum dwarf_attribute attr_kind;
4330 register dw_die_ref targ_die;
4332 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4334 attr->dw_attr_next = NULL;
4335 attr->dw_attr = attr_kind;
4336 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4337 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4338 attr->dw_attr_val.v.val_die_ref.external = 0;
4339 add_dwarf_attr (die, attr);
4342 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4343 static inline dw_die_ref
4344 AT_ref (a)
4345 register dw_attr_ref a;
4347 if (a && AT_class (a) == dw_val_class_die_ref)
4348 return a->dw_attr_val.v.val_die_ref.die;
4350 abort ();
4353 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4354 static inline int
4355 AT_ref_external (a)
4356 register dw_attr_ref a;
4358 if (a && AT_class (a) == dw_val_class_die_ref)
4359 return a->dw_attr_val.v.val_die_ref.external;
4361 return 0;
4364 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4365 static inline void
4366 set_AT_ref_external (a, i)
4367 register dw_attr_ref a;
4368 int i;
4370 if (a && AT_class (a) == dw_val_class_die_ref)
4371 a->dw_attr_val.v.val_die_ref.external = i;
4372 else
4373 abort ();
4376 /* Add an FDE reference attribute value to a DIE. */
4378 static inline void
4379 add_AT_fde_ref (die, attr_kind, targ_fde)
4380 register dw_die_ref die;
4381 register enum dwarf_attribute attr_kind;
4382 register unsigned targ_fde;
4384 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4386 attr->dw_attr_next = NULL;
4387 attr->dw_attr = attr_kind;
4388 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4389 attr->dw_attr_val.v.val_fde_index = targ_fde;
4390 add_dwarf_attr (die, attr);
4393 /* Add a location description attribute value to a DIE. */
4395 static inline void
4396 add_AT_loc (die, attr_kind, loc)
4397 register dw_die_ref die;
4398 register enum dwarf_attribute attr_kind;
4399 register dw_loc_descr_ref loc;
4401 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4403 attr->dw_attr_next = NULL;
4404 attr->dw_attr = attr_kind;
4405 attr->dw_attr_val.val_class = dw_val_class_loc;
4406 attr->dw_attr_val.v.val_loc = loc;
4407 add_dwarf_attr (die, attr);
4410 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4411 static inline dw_loc_descr_ref
4412 AT_loc (a)
4413 register dw_attr_ref a;
4415 if (a && AT_class (a) == dw_val_class_loc)
4416 return a->dw_attr_val.v.val_loc;
4418 abort ();
4421 /* Add an address constant attribute value to a DIE. */
4423 static inline void
4424 add_AT_addr (die, attr_kind, addr)
4425 register dw_die_ref die;
4426 register enum dwarf_attribute attr_kind;
4427 rtx addr;
4429 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4431 attr->dw_attr_next = NULL;
4432 attr->dw_attr = attr_kind;
4433 attr->dw_attr_val.val_class = dw_val_class_addr;
4434 attr->dw_attr_val.v.val_addr = addr;
4435 add_dwarf_attr (die, attr);
4438 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4439 static inline rtx
4440 AT_addr (a)
4441 register dw_attr_ref a;
4443 if (a && AT_class (a) == dw_val_class_addr)
4444 return a->dw_attr_val.v.val_addr;
4446 abort ();
4449 /* Add a label identifier attribute value to a DIE. */
4451 static inline void
4452 add_AT_lbl_id (die, attr_kind, lbl_id)
4453 register dw_die_ref die;
4454 register enum dwarf_attribute attr_kind;
4455 register const char *lbl_id;
4457 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4459 attr->dw_attr_next = NULL;
4460 attr->dw_attr = attr_kind;
4461 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4462 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4463 add_dwarf_attr (die, attr);
4466 /* Add a section offset attribute value to a DIE. */
4468 static inline void
4469 add_AT_lbl_offset (die, attr_kind, label)
4470 register dw_die_ref die;
4471 register enum dwarf_attribute attr_kind;
4472 register const char *label;
4474 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4476 attr->dw_attr_next = NULL;
4477 attr->dw_attr = attr_kind;
4478 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4479 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4480 add_dwarf_attr (die, attr);
4483 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4484 static inline const char *
4485 AT_lbl (a)
4486 register dw_attr_ref a;
4488 if (a && (AT_class (a) == dw_val_class_lbl_id
4489 || AT_class (a) == dw_val_class_lbl_offset))
4490 return a->dw_attr_val.v.val_lbl_id;
4492 abort ();
4495 /* Get the attribute of type attr_kind. */
4497 static inline dw_attr_ref
4498 get_AT (die, attr_kind)
4499 register dw_die_ref die;
4500 register enum dwarf_attribute attr_kind;
4502 register dw_attr_ref a;
4503 register dw_die_ref spec = NULL;
4505 if (die != NULL)
4507 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4509 if (a->dw_attr == attr_kind)
4510 return a;
4512 if (a->dw_attr == DW_AT_specification
4513 || a->dw_attr == DW_AT_abstract_origin)
4514 spec = AT_ref (a);
4517 if (spec)
4518 return get_AT (spec, attr_kind);
4521 return NULL;
4524 /* Return the "low pc" attribute value, typically associated with
4525 a subprogram DIE. Return null if the "low pc" attribute is
4526 either not prsent, or if it cannot be represented as an
4527 assembler label identifier. */
4529 static inline const char *
4530 get_AT_low_pc (die)
4531 register dw_die_ref die;
4533 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4534 return a ? AT_lbl (a) : NULL;
4537 /* Return the "high pc" attribute value, typically associated with
4538 a subprogram DIE. Return null if the "high pc" attribute is
4539 either not prsent, or if it cannot be represented as an
4540 assembler label identifier. */
4542 static inline const char *
4543 get_AT_hi_pc (die)
4544 register dw_die_ref die;
4546 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4547 return a ? AT_lbl (a) : NULL;
4550 /* Return the value of the string attribute designated by ATTR_KIND, or
4551 NULL if it is not present. */
4553 static inline const char *
4554 get_AT_string (die, attr_kind)
4555 register dw_die_ref die;
4556 register enum dwarf_attribute attr_kind;
4558 register dw_attr_ref a = get_AT (die, attr_kind);
4559 return a ? AT_string (a) : NULL;
4562 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4563 if it is not present. */
4565 static inline int
4566 get_AT_flag (die, attr_kind)
4567 register dw_die_ref die;
4568 register enum dwarf_attribute attr_kind;
4570 register dw_attr_ref a = get_AT (die, attr_kind);
4571 return a ? AT_flag (a) : 0;
4574 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4575 if it is not present. */
4577 static inline unsigned
4578 get_AT_unsigned (die, attr_kind)
4579 register dw_die_ref die;
4580 register enum dwarf_attribute attr_kind;
4582 register dw_attr_ref a = get_AT (die, attr_kind);
4583 return a ? AT_unsigned (a) : 0;
4586 static inline dw_die_ref
4587 get_AT_ref (die, attr_kind)
4588 dw_die_ref die;
4589 register enum dwarf_attribute attr_kind;
4591 register dw_attr_ref a = get_AT (die, attr_kind);
4592 return a ? AT_ref (a) : NULL;
4595 static inline int
4596 is_c_family ()
4598 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4600 return (lang == DW_LANG_C || lang == DW_LANG_C89
4601 || lang == DW_LANG_C_plus_plus);
4604 static inline int
4605 is_fortran ()
4607 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4609 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4612 static inline int
4613 is_java ()
4615 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4617 return (lang == DW_LANG_Java);
4620 /* Free up the memory used by A. */
4622 static inline void free_AT PARAMS ((dw_attr_ref));
4623 static inline void
4624 free_AT (a)
4625 dw_attr_ref a;
4627 switch (AT_class (a))
4629 case dw_val_class_str:
4630 case dw_val_class_lbl_id:
4631 case dw_val_class_lbl_offset:
4632 free (a->dw_attr_val.v.val_str);
4633 break;
4635 case dw_val_class_float:
4636 free (a->dw_attr_val.v.val_float.array);
4637 break;
4639 default:
4640 break;
4643 free (a);
4646 /* Remove the specified attribute if present. */
4648 static void
4649 remove_AT (die, attr_kind)
4650 register dw_die_ref die;
4651 register enum dwarf_attribute attr_kind;
4653 register dw_attr_ref *p;
4654 register dw_attr_ref removed = NULL;
4656 if (die != NULL)
4658 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4659 if ((*p)->dw_attr == attr_kind)
4661 removed = *p;
4662 *p = (*p)->dw_attr_next;
4663 break;
4666 if (removed != 0)
4667 free_AT (removed);
4671 /* Free up the memory used by DIE. */
4673 static inline void free_die PARAMS ((dw_die_ref));
4674 static inline void
4675 free_die (die)
4676 dw_die_ref die;
4678 remove_children (die);
4679 free (die);
4682 /* Discard the children of this DIE. */
4684 static void
4685 remove_children (die)
4686 register dw_die_ref die;
4688 register dw_die_ref child_die = die->die_child;
4690 die->die_child = NULL;
4692 while (child_die != NULL)
4694 register dw_die_ref tmp_die = child_die;
4695 register dw_attr_ref a;
4697 child_die = child_die->die_sib;
4699 for (a = tmp_die->die_attr; a != NULL;)
4701 register dw_attr_ref tmp_a = a;
4703 a = a->dw_attr_next;
4704 free_AT (tmp_a);
4707 free_die (tmp_die);
4711 /* Add a child DIE below its parent. We build the lists up in reverse
4712 addition order, and correct that in reverse_all_dies. */
4714 static inline void
4715 add_child_die (die, child_die)
4716 register dw_die_ref die;
4717 register dw_die_ref child_die;
4719 if (die != NULL && child_die != NULL)
4721 if (die == child_die)
4722 abort ();
4723 child_die->die_parent = die;
4724 child_die->die_sib = die->die_child;
4725 die->die_child = child_die;
4729 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4730 is the specification, to the front of PARENT's list of children. */
4732 static void
4733 splice_child_die (parent, child)
4734 dw_die_ref parent, child;
4736 dw_die_ref *p;
4738 /* We want the declaration DIE from inside the class, not the
4739 specification DIE at toplevel. */
4740 if (child->die_parent != parent)
4742 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4743 if (tmp)
4744 child = tmp;
4747 if (child->die_parent != parent
4748 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4749 abort ();
4751 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4752 if (*p == child)
4754 *p = child->die_sib;
4755 break;
4758 child->die_sib = parent->die_child;
4759 parent->die_child = child;
4762 /* Return a pointer to a newly created DIE node. */
4764 static inline dw_die_ref
4765 new_die (tag_value, parent_die)
4766 register enum dwarf_tag tag_value;
4767 register dw_die_ref parent_die;
4769 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
4771 die->die_tag = tag_value;
4772 die->die_abbrev = 0;
4773 die->die_offset = 0;
4774 die->die_child = NULL;
4775 die->die_parent = NULL;
4776 die->die_sib = NULL;
4777 die->die_attr = NULL;
4778 die->die_symbol = NULL;
4780 if (parent_die != NULL)
4781 add_child_die (parent_die, die);
4782 else
4784 limbo_die_node *limbo_node;
4786 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4787 limbo_node->die = die;
4788 limbo_node->next = limbo_die_list;
4789 limbo_die_list = limbo_node;
4792 return die;
4795 /* Return the DIE associated with the given type specifier. */
4797 static inline dw_die_ref
4798 lookup_type_die (type)
4799 register tree type;
4801 if (TREE_CODE (type) == VECTOR_TYPE)
4802 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4803 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4806 /* Equate a DIE to a given type specifier. */
4808 static inline void
4809 equate_type_number_to_die (type, type_die)
4810 register tree type;
4811 register dw_die_ref type_die;
4813 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4816 /* Return the DIE associated with a given declaration. */
4818 static inline dw_die_ref
4819 lookup_decl_die (decl)
4820 register tree decl;
4822 register unsigned decl_id = DECL_UID (decl);
4824 return (decl_id < decl_die_table_in_use
4825 ? decl_die_table[decl_id] : NULL);
4828 /* Equate a DIE to a particular declaration. */
4830 static void
4831 equate_decl_number_to_die (decl, decl_die)
4832 register tree decl;
4833 register dw_die_ref decl_die;
4835 register unsigned decl_id = DECL_UID (decl);
4836 register unsigned num_allocated;
4838 if (decl_id >= decl_die_table_allocated)
4840 num_allocated
4841 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4842 / DECL_DIE_TABLE_INCREMENT)
4843 * DECL_DIE_TABLE_INCREMENT;
4845 decl_die_table
4846 = (dw_die_ref *) xrealloc (decl_die_table,
4847 sizeof (dw_die_ref) * num_allocated);
4849 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
4850 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4851 decl_die_table_allocated = num_allocated;
4854 if (decl_id >= decl_die_table_in_use)
4855 decl_die_table_in_use = (decl_id + 1);
4857 decl_die_table[decl_id] = decl_die;
4860 /* Keep track of the number of spaces used to indent the
4861 output of the debugging routines that print the structure of
4862 the DIE internal representation. */
4863 static int print_indent;
4865 /* Indent the line the number of spaces given by print_indent. */
4867 static inline void
4868 print_spaces (outfile)
4869 FILE *outfile;
4871 fprintf (outfile, "%*s", print_indent, "");
4874 /* Print the information associated with a given DIE, and its children.
4875 This routine is a debugging aid only. */
4877 static void
4878 print_die (die, outfile)
4879 dw_die_ref die;
4880 FILE *outfile;
4882 register dw_attr_ref a;
4883 register dw_die_ref c;
4885 print_spaces (outfile);
4886 fprintf (outfile, "DIE %4lu: %s\n",
4887 die->die_offset, dwarf_tag_name (die->die_tag));
4888 print_spaces (outfile);
4889 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4890 fprintf (outfile, " offset: %lu\n", die->die_offset);
4892 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4894 print_spaces (outfile);
4895 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4897 switch (AT_class (a))
4899 case dw_val_class_addr:
4900 fprintf (outfile, "address");
4901 break;
4902 case dw_val_class_loc:
4903 fprintf (outfile, "location descriptor");
4904 break;
4905 case dw_val_class_const:
4906 fprintf (outfile, "%ld", AT_int (a));
4907 break;
4908 case dw_val_class_unsigned_const:
4909 fprintf (outfile, "%lu", AT_unsigned (a));
4910 break;
4911 case dw_val_class_long_long:
4912 fprintf (outfile, "constant (%lu,%lu)",
4913 a->dw_attr_val.v.val_long_long.hi,
4914 a->dw_attr_val.v.val_long_long.low);
4915 break;
4916 case dw_val_class_float:
4917 fprintf (outfile, "floating-point constant");
4918 break;
4919 case dw_val_class_flag:
4920 fprintf (outfile, "%u", AT_flag (a));
4921 break;
4922 case dw_val_class_die_ref:
4923 if (AT_ref (a) != NULL)
4925 if (AT_ref (a)->die_symbol)
4926 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
4927 else
4928 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4930 else
4931 fprintf (outfile, "die -> <null>");
4932 break;
4933 case dw_val_class_lbl_id:
4934 case dw_val_class_lbl_offset:
4935 fprintf (outfile, "label: %s", AT_lbl (a));
4936 break;
4937 case dw_val_class_str:
4938 if (AT_string (a) != NULL)
4939 fprintf (outfile, "\"%s\"", AT_string (a));
4940 else
4941 fprintf (outfile, "<null>");
4942 break;
4943 default:
4944 break;
4947 fprintf (outfile, "\n");
4950 if (die->die_child != NULL)
4952 print_indent += 4;
4953 for (c = die->die_child; c != NULL; c = c->die_sib)
4954 print_die (c, outfile);
4956 print_indent -= 4;
4958 if (print_indent == 0)
4959 fprintf (outfile, "\n");
4962 /* Print the contents of the source code line number correspondence table.
4963 This routine is a debugging aid only. */
4965 static void
4966 print_dwarf_line_table (outfile)
4967 FILE *outfile;
4969 register unsigned i;
4970 register dw_line_info_ref line_info;
4972 fprintf (outfile, "\n\nDWARF source line information\n");
4973 for (i = 1; i < line_info_table_in_use; ++i)
4975 line_info = &line_info_table[i];
4976 fprintf (outfile, "%5d: ", i);
4977 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
4978 fprintf (outfile, "%6ld", line_info->dw_line_num);
4979 fprintf (outfile, "\n");
4982 fprintf (outfile, "\n\n");
4985 /* Print the information collected for a given DIE. */
4987 void
4988 debug_dwarf_die (die)
4989 dw_die_ref die;
4991 print_die (die, stderr);
4994 /* Print all DWARF information collected for the compilation unit.
4995 This routine is a debugging aid only. */
4997 void
4998 debug_dwarf ()
5000 print_indent = 0;
5001 print_die (comp_unit_die, stderr);
5002 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5003 print_dwarf_line_table (stderr);
5006 /* We build up the lists of children and attributes by pushing new ones
5007 onto the beginning of the list. Reverse the lists for DIE so that
5008 they are in order of addition. */
5010 static void
5011 reverse_die_lists (die)
5012 register dw_die_ref die;
5014 register dw_die_ref c, cp, cn;
5015 register dw_attr_ref a, ap, an;
5017 for (a = die->die_attr, ap = 0; a; a = an)
5019 an = a->dw_attr_next;
5020 a->dw_attr_next = ap;
5021 ap = a;
5023 die->die_attr = ap;
5025 for (c = die->die_child, cp = 0; c; c = cn)
5027 cn = c->die_sib;
5028 c->die_sib = cp;
5029 cp = c;
5031 die->die_child = cp;
5034 /* reverse_die_lists only reverses the single die you pass it. Since
5035 we used to reverse all dies in add_sibling_attributes, which runs
5036 through all the dies, it would reverse all the dies. Now, however,
5037 since we don't call reverse_die_lists in add_sibling_attributes, we
5038 need a routine to recursively reverse all the dies. This is that
5039 routine. */
5041 static void
5042 reverse_all_dies (die)
5043 register dw_die_ref die;
5045 register dw_die_ref c;
5047 reverse_die_lists (die);
5049 for (c = die->die_child; c; c = c->die_sib)
5050 reverse_all_dies (c);
5053 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5054 the CU for the enclosing include file, if any. BINCL_DIE is the
5055 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5056 include file. */
5058 static dw_die_ref
5059 push_new_compile_unit (old_unit, bincl_die)
5060 dw_die_ref old_unit, bincl_die;
5062 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5063 dw_die_ref new_unit = gen_compile_unit_die (filename);
5064 new_unit->die_sib = old_unit;
5065 return new_unit;
5068 /* Close an include-file CU and reopen the enclosing one. */
5070 static dw_die_ref
5071 pop_compile_unit (old_unit)
5072 dw_die_ref old_unit;
5074 dw_die_ref new_unit = old_unit->die_sib;
5075 old_unit->die_sib = NULL;
5076 return new_unit;
5079 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5080 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5082 /* Calculate the checksum of a location expression. */
5084 static inline void
5085 loc_checksum (loc, ctx)
5086 dw_loc_descr_ref loc;
5087 struct md5_ctx *ctx;
5089 PROCESS (loc->dw_loc_opc);
5090 PROCESS (loc->dw_loc_oprnd1);
5091 PROCESS (loc->dw_loc_oprnd2);
5094 /* Calculate the checksum of an attribute. */
5096 static void
5097 attr_checksum (at, ctx)
5098 dw_attr_ref at;
5099 struct md5_ctx *ctx;
5101 dw_loc_descr_ref loc;
5102 rtx r;
5104 PROCESS (at->dw_attr);
5106 /* We don't care about differences in file numbering. */
5107 if (at->dw_attr == DW_AT_decl_file
5108 /* Or that this was compiled with a different compiler snapshot; if
5109 the output is the same, that's what matters. */
5110 || at->dw_attr == DW_AT_producer)
5111 return;
5113 switch (AT_class (at))
5115 case dw_val_class_const:
5116 PROCESS (at->dw_attr_val.v.val_int);
5117 break;
5118 case dw_val_class_unsigned_const:
5119 PROCESS (at->dw_attr_val.v.val_unsigned);
5120 break;
5121 case dw_val_class_long_long:
5122 PROCESS (at->dw_attr_val.v.val_long_long);
5123 break;
5124 case dw_val_class_float:
5125 PROCESS (at->dw_attr_val.v.val_float);
5126 break;
5127 case dw_val_class_flag:
5128 PROCESS (at->dw_attr_val.v.val_flag);
5129 break;
5131 case dw_val_class_str:
5132 PROCESS_STRING (AT_string (at));
5133 break;
5134 case dw_val_class_addr:
5135 r = AT_addr (at);
5136 switch (GET_CODE (r))
5138 case SYMBOL_REF:
5139 PROCESS_STRING (XSTR (r, 0));
5140 break;
5142 default:
5143 abort ();
5145 break;
5147 case dw_val_class_loc:
5148 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5149 loc_checksum (loc, ctx);
5150 break;
5152 case dw_val_class_die_ref:
5153 if (AT_ref (at)->die_offset)
5154 PROCESS (AT_ref (at)->die_offset);
5155 /* FIXME else use target die name or something. */
5157 case dw_val_class_fde_ref:
5158 case dw_val_class_lbl_id:
5159 case dw_val_class_lbl_offset:
5161 default:
5162 break;
5166 /* Calculate the checksum of a DIE. */
5168 static void
5169 die_checksum (die, ctx)
5170 dw_die_ref die;
5171 struct md5_ctx *ctx;
5173 dw_die_ref c;
5174 dw_attr_ref a;
5176 PROCESS (die->die_tag);
5178 for (a = die->die_attr; a; a = a->dw_attr_next)
5179 attr_checksum (a, ctx);
5181 for (c = die->die_child; c; c = c->die_sib)
5182 die_checksum (c, ctx);
5185 #undef PROCESS
5186 #undef PROCESS_STRING
5188 /* The prefix to attach to symbols on DIEs in the current comdat debug
5189 info section. */
5190 static char *comdat_symbol_id;
5192 /* The index of the current symbol within the current comdat CU. */
5193 static unsigned int comdat_symbol_number;
5195 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5196 children, and set comdat_symbol_id accordingly. */
5198 static void
5199 compute_section_prefix (unit_die)
5200 dw_die_ref unit_die;
5202 char *p, *name;
5203 int i;
5204 unsigned char checksum[16];
5205 struct md5_ctx ctx;
5207 md5_init_ctx (&ctx);
5208 die_checksum (unit_die, &ctx);
5209 md5_finish_ctx (&ctx, checksum);
5211 p = file_name_nondirectory (get_AT_string (unit_die, DW_AT_name));
5212 name = (char *) alloca (strlen (p) + 64);
5213 sprintf (name, "%s.", p);
5215 clean_symbol_name (name);
5217 p = name + strlen (name);
5218 for (i = 0; i < 4; ++i)
5220 sprintf (p, "%.2x", checksum[i]);
5221 p += 2;
5224 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5225 comdat_symbol_number = 0;
5228 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5230 static int
5231 is_type_die (die)
5232 dw_die_ref die;
5234 switch (die->die_tag)
5236 case DW_TAG_array_type:
5237 case DW_TAG_class_type:
5238 case DW_TAG_enumeration_type:
5239 case DW_TAG_pointer_type:
5240 case DW_TAG_reference_type:
5241 case DW_TAG_string_type:
5242 case DW_TAG_structure_type:
5243 case DW_TAG_subroutine_type:
5244 case DW_TAG_union_type:
5245 case DW_TAG_ptr_to_member_type:
5246 case DW_TAG_set_type:
5247 case DW_TAG_subrange_type:
5248 case DW_TAG_base_type:
5249 case DW_TAG_const_type:
5250 case DW_TAG_file_type:
5251 case DW_TAG_packed_type:
5252 case DW_TAG_volatile_type:
5253 return 1;
5254 default:
5255 return 0;
5259 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5260 Basically, we want to choose the bits that are likely to be shared between
5261 compilations (types) and leave out the bits that are specific to individual
5262 compilations (functions). */
5264 static int
5265 is_comdat_die (c)
5266 dw_die_ref c;
5268 #if 1
5269 /* I think we want to leave base types and __vtbl_ptr_type in the
5270 main CU, as we do for stabs. The advantage is a greater
5271 likelihood of sharing between objects that don't include headers
5272 in the same order (and therefore would put the base types in a
5273 different comdat). jason 8/28/00 */
5274 if (c->die_tag == DW_TAG_base_type)
5275 return 0;
5277 if (c->die_tag == DW_TAG_pointer_type
5278 || c->die_tag == DW_TAG_reference_type
5279 || c->die_tag == DW_TAG_const_type
5280 || c->die_tag == DW_TAG_volatile_type)
5282 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5283 return t ? is_comdat_die (t) : 0;
5285 #endif
5287 return is_type_die (c);
5290 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5291 compilation unit. */
5293 static int
5294 is_symbol_die (c)
5295 dw_die_ref c;
5297 if (is_type_die (c))
5298 return 1;
5299 if (get_AT (c, DW_AT_declaration)
5300 && ! get_AT (c, DW_AT_specification))
5301 return 1;
5302 return 0;
5305 static char *
5306 gen_internal_sym ()
5308 char buf[256];
5309 static int label_num;
5310 ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++);
5311 return xstrdup (buf);
5314 /* Assign symbols to all worthy DIEs under DIE. */
5316 static void
5317 assign_symbol_names (die)
5318 register dw_die_ref die;
5320 register dw_die_ref c;
5322 if (is_symbol_die (die))
5324 if (comdat_symbol_id)
5326 char *p = alloca (strlen (comdat_symbol_id) + 64);
5327 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5328 comdat_symbol_id, comdat_symbol_number++);
5329 die->die_symbol = xstrdup (p);
5331 else
5332 die->die_symbol = gen_internal_sym ();
5335 for (c = die->die_child; c != NULL; c = c->die_sib)
5336 assign_symbol_names (c);
5339 /* Traverse the DIE (which is always comp_unit_die), and set up
5340 additional compilation units for each of the include files we see
5341 bracketed by BINCL/EINCL. */
5343 static void
5344 break_out_includes (die)
5345 register dw_die_ref die;
5347 dw_die_ref *ptr;
5348 register dw_die_ref unit = NULL;
5349 limbo_die_node *node;
5351 for (ptr = &(die->die_child); *ptr; )
5353 register dw_die_ref c = *ptr;
5355 if (c->die_tag == DW_TAG_GNU_BINCL
5356 || c->die_tag == DW_TAG_GNU_EINCL
5357 || (unit && is_comdat_die (c)))
5359 /* This DIE is for a secondary CU; remove it from the main one. */
5360 *ptr = c->die_sib;
5362 if (c->die_tag == DW_TAG_GNU_BINCL)
5364 unit = push_new_compile_unit (unit, c);
5365 free_die (c);
5367 else if (c->die_tag == DW_TAG_GNU_EINCL)
5369 unit = pop_compile_unit (unit);
5370 free_die (c);
5372 else
5373 add_child_die (unit, c);
5375 else
5377 /* Leave this DIE in the main CU. */
5378 ptr = &(c->die_sib);
5379 continue;
5383 #if 0
5384 /* We can only use this in debugging, since the frontend doesn't check
5385 to make sure that we leave every include file we enter. */
5386 if (unit != NULL)
5387 abort ();
5388 #endif
5390 assign_symbol_names (die);
5391 for (node = limbo_die_list; node; node = node->next)
5393 compute_section_prefix (node->die);
5394 assign_symbol_names (node->die);
5398 /* Traverse the DIE and add a sibling attribute if it may have the
5399 effect of speeding up access to siblings. To save some space,
5400 avoid generating sibling attributes for DIE's without children. */
5402 static void
5403 add_sibling_attributes (die)
5404 register dw_die_ref die;
5406 register dw_die_ref c;
5408 if (die->die_tag != DW_TAG_compile_unit
5409 && die->die_sib && die->die_child != NULL)
5410 /* Add the sibling link to the front of the attribute list. */
5411 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5413 for (c = die->die_child; c != NULL; c = c->die_sib)
5414 add_sibling_attributes (c);
5417 /* The format of each DIE (and its attribute value pairs)
5418 is encoded in an abbreviation table. This routine builds the
5419 abbreviation table and assigns a unique abbreviation id for
5420 each abbreviation entry. The children of each die are visited
5421 recursively. */
5423 static void
5424 build_abbrev_table (die)
5425 register dw_die_ref die;
5427 register unsigned long abbrev_id;
5428 register unsigned long n_alloc;
5429 register dw_die_ref c;
5430 register dw_attr_ref d_attr, a_attr;
5432 /* Scan the DIE references, and mark as external any that refer to
5433 DIEs from other CUs (i.e. those which are not marked). */
5434 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5436 if (AT_class (d_attr) == dw_val_class_die_ref
5437 && AT_ref (d_attr)->die_mark == 0)
5439 if (AT_ref (d_attr)->die_symbol == 0)
5440 abort ();
5441 set_AT_ref_external (d_attr, 1);
5445 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5447 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5449 if (abbrev->die_tag == die->die_tag)
5451 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5453 a_attr = abbrev->die_attr;
5454 d_attr = die->die_attr;
5456 while (a_attr != NULL && d_attr != NULL)
5458 if ((a_attr->dw_attr != d_attr->dw_attr)
5459 || (value_format (a_attr) != value_format (d_attr)))
5460 break;
5462 a_attr = a_attr->dw_attr_next;
5463 d_attr = d_attr->dw_attr_next;
5466 if (a_attr == NULL && d_attr == NULL)
5467 break;
5472 if (abbrev_id >= abbrev_die_table_in_use)
5474 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5476 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5477 abbrev_die_table
5478 = (dw_die_ref *) xrealloc (abbrev_die_table,
5479 sizeof (dw_die_ref) * n_alloc);
5481 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5482 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5483 abbrev_die_table_allocated = n_alloc;
5486 ++abbrev_die_table_in_use;
5487 abbrev_die_table[abbrev_id] = die;
5490 die->die_abbrev = abbrev_id;
5491 for (c = die->die_child; c != NULL; c = c->die_sib)
5492 build_abbrev_table (c);
5495 /* Return the size of a string, including the null byte.
5497 This used to treat backslashes as escapes, and hence they were not included
5498 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5499 which treats a backslash as a backslash, escaping it if necessary, and hence
5500 we must include them in the count. */
5502 static unsigned long
5503 size_of_string (str)
5504 register const char *str;
5506 return strlen (str) + 1;
5509 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5511 static int
5512 constant_size (value)
5513 long unsigned value;
5515 int log;
5517 if (value == 0)
5518 log = 0;
5519 else
5520 log = floor_log2 (value);
5522 log = log / 8;
5523 log = 1 << (floor_log2 (log) + 1);
5525 return log;
5528 /* Return the size of a DIE, as it is represented in the
5529 .debug_info section. */
5531 static unsigned long
5532 size_of_die (die)
5533 register dw_die_ref die;
5535 register unsigned long size = 0;
5536 register dw_attr_ref a;
5538 size += size_of_uleb128 (die->die_abbrev);
5539 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5541 switch (AT_class (a))
5543 case dw_val_class_addr:
5544 size += DWARF2_ADDR_SIZE;
5545 break;
5546 case dw_val_class_loc:
5548 register unsigned long lsize = size_of_locs (AT_loc (a));
5550 /* Block length. */
5551 size += constant_size (lsize);
5552 size += lsize;
5554 break;
5555 case dw_val_class_const:
5556 size += size_of_sleb128 (AT_int (a));
5557 break;
5558 case dw_val_class_unsigned_const:
5559 size += constant_size (AT_unsigned (a));
5560 break;
5561 case dw_val_class_long_long:
5562 size += 1 + 8; /* block */
5563 break;
5564 case dw_val_class_float:
5565 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5566 break;
5567 case dw_val_class_flag:
5568 size += 1;
5569 break;
5570 case dw_val_class_die_ref:
5571 size += DWARF_OFFSET_SIZE;
5572 break;
5573 case dw_val_class_fde_ref:
5574 size += DWARF_OFFSET_SIZE;
5575 break;
5576 case dw_val_class_lbl_id:
5577 size += DWARF2_ADDR_SIZE;
5578 break;
5579 case dw_val_class_lbl_offset:
5580 size += DWARF_OFFSET_SIZE;
5581 break;
5582 case dw_val_class_str:
5583 size += size_of_string (AT_string (a));
5584 break;
5585 default:
5586 abort ();
5590 return size;
5593 /* Size the debugging information associated with a given DIE.
5594 Visits the DIE's children recursively. Updates the global
5595 variable next_die_offset, on each time through. Uses the
5596 current value of next_die_offset to update the die_offset
5597 field in each DIE. */
5599 static void
5600 calc_die_sizes (die)
5601 dw_die_ref die;
5603 register dw_die_ref c;
5604 die->die_offset = next_die_offset;
5605 next_die_offset += size_of_die (die);
5607 for (c = die->die_child; c != NULL; c = c->die_sib)
5608 calc_die_sizes (c);
5610 if (die->die_child != NULL)
5611 /* Count the null byte used to terminate sibling lists. */
5612 next_die_offset += 1;
5615 /* Set the marks for a die and its children. We do this so
5616 that we know whether or not a reference needs to use FORM_ref_addr; only
5617 DIEs in the same CU will be marked. We used to clear out the offset
5618 and use that as the flag, but ran into ordering problems. */
5620 static void
5621 mark_dies (die)
5622 dw_die_ref die;
5624 register dw_die_ref c;
5625 die->die_mark = 1;
5626 for (c = die->die_child; c; c = c->die_sib)
5627 mark_dies (c);
5630 /* Clear the marks for a die and its children. */
5632 static void
5633 unmark_dies (die)
5634 dw_die_ref die;
5636 register dw_die_ref c;
5637 die->die_mark = 0;
5638 for (c = die->die_child; c; c = c->die_sib)
5639 unmark_dies (c);
5642 /* Return the size of the line information prolog generated for the
5643 compilation unit. */
5645 static unsigned long
5646 size_of_line_prolog ()
5648 register unsigned long size;
5649 register unsigned long ft_index;
5651 size = DWARF_LINE_PROLOG_HEADER_SIZE;
5653 /* Count the size of the table giving number of args for each
5654 standard opcode. */
5655 size += DWARF_LINE_OPCODE_BASE - 1;
5657 /* Include directory table is empty (at present). Count only the
5658 null byte used to terminate the table. */
5659 size += 1;
5661 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5663 /* File name entry. */
5664 size += size_of_string (file_table[ft_index]);
5666 /* Include directory index. */
5667 size += size_of_uleb128 (0);
5669 /* Modification time. */
5670 size += size_of_uleb128 (0);
5672 /* File length in bytes. */
5673 size += size_of_uleb128 (0);
5676 /* Count the file table terminator. */
5677 size += 1;
5678 return size;
5681 /* Return the size of the .debug_pubnames table generated for the
5682 compilation unit. */
5684 static unsigned long
5685 size_of_pubnames ()
5687 register unsigned long size;
5688 register unsigned i;
5690 size = DWARF_PUBNAMES_HEADER_SIZE;
5691 for (i = 0; i < pubname_table_in_use; ++i)
5693 register pubname_ref p = &pubname_table[i];
5694 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5697 size += DWARF_OFFSET_SIZE;
5698 return size;
5701 /* Return the size of the information in the .debug_aranges section. */
5703 static unsigned long
5704 size_of_aranges ()
5706 register unsigned long size;
5708 size = DWARF_ARANGES_HEADER_SIZE;
5710 /* Count the address/length pair for this compilation unit. */
5711 size += 2 * DWARF2_ADDR_SIZE;
5712 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5714 /* Count the two zero words used to terminated the address range table. */
5715 size += 2 * DWARF2_ADDR_SIZE;
5716 return size;
5719 /* Select the encoding of an attribute value. */
5721 static enum dwarf_form
5722 value_format (a)
5723 dw_attr_ref a;
5725 switch (a->dw_attr_val.val_class)
5727 case dw_val_class_addr:
5728 return DW_FORM_addr;
5729 case dw_val_class_loc:
5730 switch (constant_size (size_of_locs (AT_loc (a))))
5732 case 1:
5733 return DW_FORM_block1;
5734 case 2:
5735 return DW_FORM_block2;
5736 default:
5737 abort ();
5739 case dw_val_class_const:
5740 return DW_FORM_sdata;
5741 case dw_val_class_unsigned_const:
5742 switch (constant_size (AT_unsigned (a)))
5744 case 1:
5745 return DW_FORM_data1;
5746 case 2:
5747 return DW_FORM_data2;
5748 case 4:
5749 return DW_FORM_data4;
5750 case 8:
5751 return DW_FORM_data8;
5752 default:
5753 abort ();
5755 case dw_val_class_long_long:
5756 return DW_FORM_block1;
5757 case dw_val_class_float:
5758 return DW_FORM_block1;
5759 case dw_val_class_flag:
5760 return DW_FORM_flag;
5761 case dw_val_class_die_ref:
5762 if (AT_ref_external (a))
5763 return DW_FORM_ref_addr;
5764 else
5765 return DW_FORM_ref;
5766 case dw_val_class_fde_ref:
5767 return DW_FORM_data;
5768 case dw_val_class_lbl_id:
5769 return DW_FORM_addr;
5770 case dw_val_class_lbl_offset:
5771 return DW_FORM_data;
5772 case dw_val_class_str:
5773 return DW_FORM_string;
5774 default:
5775 abort ();
5779 /* Output the encoding of an attribute value. */
5781 static void
5782 output_value_format (a)
5783 dw_attr_ref a;
5785 enum dwarf_form form = value_format (a);
5787 output_uleb128 (form);
5788 if (flag_debug_asm)
5789 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
5791 fputc ('\n', asm_out_file);
5794 /* Output the .debug_abbrev section which defines the DIE abbreviation
5795 table. */
5797 static void
5798 output_abbrev_section ()
5800 unsigned long abbrev_id;
5802 dw_attr_ref a_attr;
5803 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5805 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5807 output_uleb128 (abbrev_id);
5808 if (flag_debug_asm)
5809 fprintf (asm_out_file, " (abbrev code)");
5811 fputc ('\n', asm_out_file);
5812 output_uleb128 (abbrev->die_tag);
5813 if (flag_debug_asm)
5814 fprintf (asm_out_file, " (TAG: %s)",
5815 dwarf_tag_name (abbrev->die_tag));
5817 fputc ('\n', asm_out_file);
5818 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP,
5819 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
5821 if (flag_debug_asm)
5822 fprintf (asm_out_file, "\t%s %s",
5823 ASM_COMMENT_START,
5824 (abbrev->die_child != NULL
5825 ? "DW_children_yes" : "DW_children_no"));
5827 fputc ('\n', asm_out_file);
5829 for (a_attr = abbrev->die_attr; a_attr != NULL;
5830 a_attr = a_attr->dw_attr_next)
5832 output_uleb128 (a_attr->dw_attr);
5833 if (flag_debug_asm)
5834 fprintf (asm_out_file, " (%s)",
5835 dwarf_attr_name (a_attr->dw_attr));
5837 fputc ('\n', asm_out_file);
5838 output_value_format (a_attr);
5841 fprintf (asm_out_file, "%s0,0\n", ASM_BYTE_OP);
5844 /* Terminate the table. */
5845 fprintf (asm_out_file, "%s0\n", ASM_BYTE_OP);
5848 /* Output a symbol we can use to refer to this DIE from another CU. */
5850 static inline void
5851 output_die_symbol (die)
5852 register dw_die_ref die;
5854 char *sym = die->die_symbol;
5856 if (sym == 0)
5857 return;
5859 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
5860 /* We make these global, not weak; if the target doesn't support
5861 .linkonce, it doesn't support combining the sections, so debugging
5862 will break. */
5863 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
5864 ASM_OUTPUT_LABEL (asm_out_file, sym);
5867 /* Output a symbolic (i.e. FORM_ref_addr) reference to TARGET_DIE. */
5869 static inline void
5870 output_symbolic_ref (target_die)
5871 dw_die_ref target_die;
5873 char *sym = target_die->die_symbol;
5875 if (sym == 0)
5876 abort ();
5878 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, sym);
5881 /* Output the DIE and its attributes. Called recursively to generate
5882 the definitions of each child DIE. */
5884 static void
5885 output_die (die)
5886 register dw_die_ref die;
5888 register dw_attr_ref a;
5889 register dw_die_ref c;
5890 register unsigned long size;
5892 /* If someone in another CU might refer to us, set up a symbol for
5893 them to point to. */
5894 if (die->die_symbol)
5895 output_die_symbol (die);
5897 output_uleb128 (die->die_abbrev);
5898 if (flag_debug_asm)
5899 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
5900 die->die_offset, dwarf_tag_name (die->die_tag));
5902 fputc ('\n', asm_out_file);
5904 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5906 switch (AT_class (a))
5908 case dw_val_class_addr:
5909 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
5910 break;
5912 case dw_val_class_loc:
5913 size = size_of_locs (AT_loc (a));
5915 /* Output the block length for this list of location operations. */
5916 switch (constant_size (size))
5918 case 1:
5919 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5920 break;
5921 case 2:
5922 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5923 break;
5924 default:
5925 abort ();
5928 if (flag_debug_asm)
5929 fprintf (asm_out_file, "\t%s %s",
5930 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5932 fputc ('\n', asm_out_file);
5934 output_loc_sequence (AT_loc (a));
5935 break;
5937 case dw_val_class_const:
5938 /* ??? It would be slightly more efficient to use a scheme like is
5939 used for unsigned constants below, but gdb 4.x does not sign
5940 extend. Gdb 5.x does sign extend. */
5941 output_sleb128 (AT_int (a));
5942 break;
5944 case dw_val_class_unsigned_const:
5945 switch (constant_size (AT_unsigned (a)))
5947 case 1:
5948 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
5949 break;
5950 case 2:
5951 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
5952 break;
5953 case 4:
5954 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
5955 break;
5956 case 8:
5957 ASM_OUTPUT_DWARF_DATA8 (asm_out_file, AT_unsigned (a));
5958 break;
5959 default:
5960 abort ();
5962 break;
5964 case dw_val_class_long_long:
5965 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
5966 if (flag_debug_asm)
5967 fprintf (asm_out_file, "\t%s %s",
5968 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5970 fputc ('\n', asm_out_file);
5971 ASM_OUTPUT_DWARF_CONST_DOUBLE (asm_out_file,
5972 a->dw_attr_val.v.val_long_long.hi,
5973 a->dw_attr_val.v.val_long_long.low);
5975 if (flag_debug_asm)
5976 fprintf (asm_out_file,
5977 "\t%s long long constant", ASM_COMMENT_START);
5979 fputc ('\n', asm_out_file);
5980 break;
5982 case dw_val_class_float:
5984 register unsigned int i;
5985 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5986 a->dw_attr_val.v.val_float.length * 4);
5987 if (flag_debug_asm)
5988 fprintf (asm_out_file, "\t%s %s",
5989 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5991 fputc ('\n', asm_out_file);
5992 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5994 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5995 a->dw_attr_val.v.val_float.array[i]);
5996 if (flag_debug_asm)
5997 fprintf (asm_out_file, "\t%s fp constant word %u",
5998 ASM_COMMENT_START, i);
6000 fputc ('\n', asm_out_file);
6002 break;
6005 case dw_val_class_flag:
6006 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
6007 break;
6009 case dw_val_class_die_ref:
6010 if (AT_ref_external (a))
6011 output_symbolic_ref (AT_ref (a));
6012 else
6013 ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
6014 break;
6016 case dw_val_class_fde_ref:
6018 char l1[20];
6019 ASM_GENERATE_INTERNAL_LABEL
6020 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
6021 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
6022 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
6024 break;
6026 case dw_val_class_lbl_id:
6027 ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
6028 break;
6030 case dw_val_class_lbl_offset:
6031 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
6032 break;
6034 case dw_val_class_str:
6035 if (flag_debug_asm)
6036 ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
6037 else
6038 ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
6039 (int) strlen (AT_string (a)) + 1);
6040 break;
6042 default:
6043 abort ();
6046 if (AT_class (a) != dw_val_class_loc
6047 && AT_class (a) != dw_val_class_long_long
6048 && AT_class (a) != dw_val_class_float)
6050 if (flag_debug_asm)
6051 fprintf (asm_out_file, "\t%s %s",
6052 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6054 fputc ('\n', asm_out_file);
6058 for (c = die->die_child; c != NULL; c = c->die_sib)
6059 output_die (c);
6061 if (die->die_child != NULL)
6063 /* Add null byte to terminate sibling list. */
6064 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6065 if (flag_debug_asm)
6066 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
6067 ASM_COMMENT_START, die->die_offset);
6069 fputc ('\n', asm_out_file);
6073 /* Output the compilation unit that appears at the beginning of the
6074 .debug_info section, and precedes the DIE descriptions. */
6076 static void
6077 output_compilation_unit_header ()
6079 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
6080 if (flag_debug_asm)
6081 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
6082 ASM_COMMENT_START);
6084 fputc ('\n', asm_out_file);
6085 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6086 if (flag_debug_asm)
6087 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
6089 fputc ('\n', asm_out_file);
6090 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
6091 if (flag_debug_asm)
6092 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
6093 ASM_COMMENT_START);
6095 fputc ('\n', asm_out_file);
6096 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6097 if (flag_debug_asm)
6098 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
6100 fputc ('\n', asm_out_file);
6103 /* Output the compilation unit DIE and its children. */
6105 static void
6106 output_comp_unit (die)
6107 dw_die_ref die;
6109 char *secname;
6111 if (die->die_child == 0)
6112 return;
6114 /* Mark all the DIEs in this CU so we know which get local refs. */
6115 mark_dies (die);
6117 build_abbrev_table (die);
6119 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6120 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6121 calc_die_sizes (die);
6123 if (die->die_symbol)
6125 secname = (char *) alloca (strlen (die->die_symbol) + 24);
6126 sprintf (secname, ".gnu.linkonce.wi.%s", die->die_symbol);
6127 die->die_symbol = NULL;
6129 else
6130 secname = (char *) DEBUG_INFO_SECTION;
6132 /* Output debugging information. */
6133 fputc ('\n', asm_out_file);
6134 ASM_OUTPUT_SECTION (asm_out_file, secname);
6135 output_compilation_unit_header ();
6136 output_die (die);
6138 /* Leave the marks on the main CU, so we can check them in
6139 output_pubnames. */
6140 if (die->die_symbol)
6141 unmark_dies (die);
6144 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6145 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6146 argument list, and maybe the scope. */
6148 static const char *
6149 dwarf2_name (decl, scope)
6150 tree decl;
6151 int scope;
6153 return (*decl_printable_name) (decl, scope ? 1 : 0);
6156 /* Add a new entry to .debug_pubnames if appropriate. */
6158 static void
6159 add_pubname (decl, die)
6160 tree decl;
6161 dw_die_ref die;
6163 pubname_ref p;
6165 if (! TREE_PUBLIC (decl))
6166 return;
6168 if (pubname_table_in_use == pubname_table_allocated)
6170 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6171 pubname_table = (pubname_ref) xrealloc
6172 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6175 p = &pubname_table[pubname_table_in_use++];
6176 p->die = die;
6178 p->name = xstrdup (dwarf2_name (decl, 1));
6181 /* Output the public names table used to speed up access to externally
6182 visible names. For now, only generate entries for externally
6183 visible procedures. */
6185 static void
6186 output_pubnames ()
6188 register unsigned i;
6189 register unsigned long pubnames_length = size_of_pubnames ();
6191 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
6193 if (flag_debug_asm)
6194 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
6195 ASM_COMMENT_START);
6197 fputc ('\n', asm_out_file);
6198 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6200 if (flag_debug_asm)
6201 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6203 fputc ('\n', asm_out_file);
6204 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6205 if (flag_debug_asm)
6206 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6207 ASM_COMMENT_START);
6209 fputc ('\n', asm_out_file);
6210 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
6211 if (flag_debug_asm)
6212 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
6214 fputc ('\n', asm_out_file);
6215 for (i = 0; i < pubname_table_in_use; ++i)
6217 register pubname_ref pub = &pubname_table[i];
6219 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6220 if (pub->die->die_mark == 0)
6221 abort ();
6223 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
6224 if (flag_debug_asm)
6225 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
6227 fputc ('\n', asm_out_file);
6229 if (flag_debug_asm)
6231 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
6232 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
6234 else
6236 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
6237 (int) strlen (pub->name) + 1);
6240 fputc ('\n', asm_out_file);
6243 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
6244 fputc ('\n', asm_out_file);
6247 /* Add a new entry to .debug_aranges if appropriate. */
6249 static void
6250 add_arange (decl, die)
6251 tree decl;
6252 dw_die_ref die;
6254 if (! DECL_SECTION_NAME (decl))
6255 return;
6257 if (arange_table_in_use == arange_table_allocated)
6259 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6260 arange_table
6261 = (arange_ref) xrealloc (arange_table,
6262 arange_table_allocated * sizeof (dw_die_ref));
6265 arange_table[arange_table_in_use++] = die;
6268 /* Output the information that goes into the .debug_aranges table.
6269 Namely, define the beginning and ending address range of the
6270 text section generated for this compilation unit. */
6272 static void
6273 output_aranges ()
6275 register unsigned i;
6276 register unsigned long aranges_length = size_of_aranges ();
6278 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
6279 if (flag_debug_asm)
6280 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
6281 ASM_COMMENT_START);
6283 fputc ('\n', asm_out_file);
6284 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6285 if (flag_debug_asm)
6286 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6288 fputc ('\n', asm_out_file);
6289 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6290 if (flag_debug_asm)
6291 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6292 ASM_COMMENT_START);
6294 fputc ('\n', asm_out_file);
6295 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6296 if (flag_debug_asm)
6297 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
6299 fputc ('\n', asm_out_file);
6300 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6301 if (flag_debug_asm)
6302 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
6303 ASM_COMMENT_START);
6305 fputc ('\n', asm_out_file);
6307 /* We need to align to twice the pointer size here. */
6308 if (DWARF_ARANGES_PAD_SIZE)
6310 /* Pad using a 2 bytes word so that padding is correct
6311 for any pointer size. */
6312 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
6313 for (i = 2; i < DWARF_ARANGES_PAD_SIZE; i += 2)
6314 fprintf (asm_out_file, ",0");
6315 if (flag_debug_asm)
6316 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
6317 ASM_COMMENT_START, 2 * DWARF2_ADDR_SIZE);
6320 fputc ('\n', asm_out_file);
6321 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
6322 if (flag_debug_asm)
6323 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6325 fputc ('\n', asm_out_file);
6326 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
6327 text_section_label);
6328 if (flag_debug_asm)
6329 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6331 fputc ('\n', asm_out_file);
6332 for (i = 0; i < arange_table_in_use; ++i)
6334 dw_die_ref die = arange_table[i];
6336 /* We shouldn't see aranges for DIEs outside of the main CU. */
6337 if (die->die_mark == 0)
6338 abort ();
6340 if (die->die_tag == DW_TAG_subprogram)
6341 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
6342 else
6344 /* A static variable; extract the symbol from DW_AT_location.
6345 Note that this code isn't currently hit, as we only emit
6346 aranges for functions (jason 9/23/99). */
6348 dw_attr_ref a = get_AT (die, DW_AT_location);
6349 dw_loc_descr_ref loc;
6350 if (! a || AT_class (a) != dw_val_class_loc)
6351 abort ();
6353 loc = AT_loc (a);
6354 if (loc->dw_loc_opc != DW_OP_addr)
6355 abort ();
6357 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
6358 loc->dw_loc_oprnd1.v.val_addr);
6361 if (flag_debug_asm)
6362 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6364 fputc ('\n', asm_out_file);
6365 if (die->die_tag == DW_TAG_subprogram)
6366 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
6367 get_AT_low_pc (die));
6368 else
6369 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
6370 get_AT_unsigned (die, DW_AT_byte_size));
6372 if (flag_debug_asm)
6373 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6375 fputc ('\n', asm_out_file);
6378 /* Output the terminator words. */
6379 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6380 fputc ('\n', asm_out_file);
6381 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6382 fputc ('\n', asm_out_file);
6385 /* Output the source line number correspondence information. This
6386 information goes into the .debug_line section. */
6388 static void
6389 output_line_info ()
6391 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6392 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6393 register unsigned opc;
6394 register unsigned n_op_args;
6395 register unsigned long ft_index;
6396 register unsigned long lt_index;
6397 register unsigned long current_line;
6398 register long line_offset;
6399 register long line_delta;
6400 register unsigned long current_file;
6401 register unsigned long function;
6403 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
6404 if (flag_debug_asm)
6405 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
6406 ASM_COMMENT_START);
6408 fputc ('\n', asm_out_file);
6409 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
6410 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6411 if (flag_debug_asm)
6412 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6414 fputc ('\n', asm_out_file);
6415 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
6416 if (flag_debug_asm)
6417 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
6419 fputc ('\n', asm_out_file);
6420 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
6421 if (flag_debug_asm)
6422 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
6423 ASM_COMMENT_START);
6425 fputc ('\n', asm_out_file);
6426 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
6427 if (flag_debug_asm)
6428 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
6429 ASM_COMMENT_START);
6431 fputc ('\n', asm_out_file);
6432 fprintf (asm_out_file, "%s%d", ASM_BYTE_OP, DWARF_LINE_BASE);
6433 if (flag_debug_asm)
6434 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
6435 ASM_COMMENT_START);
6437 fputc ('\n', asm_out_file);
6438 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
6439 if (flag_debug_asm)
6440 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
6441 ASM_COMMENT_START);
6443 fputc ('\n', asm_out_file);
6444 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
6445 if (flag_debug_asm)
6446 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
6448 fputc ('\n', asm_out_file);
6449 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6451 switch (opc)
6453 case DW_LNS_advance_pc:
6454 case DW_LNS_advance_line:
6455 case DW_LNS_set_file:
6456 case DW_LNS_set_column:
6457 case DW_LNS_fixed_advance_pc:
6458 n_op_args = 1;
6459 break;
6460 default:
6461 n_op_args = 0;
6462 break;
6464 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
6465 if (flag_debug_asm)
6466 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
6467 ASM_COMMENT_START, opc, n_op_args);
6468 fputc ('\n', asm_out_file);
6471 if (flag_debug_asm)
6472 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
6474 /* Include directory table is empty, at present */
6475 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6476 fputc ('\n', asm_out_file);
6477 if (flag_debug_asm)
6478 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
6480 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
6482 if (flag_debug_asm)
6484 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
6485 fprintf (asm_out_file, "%s File Entry: 0x%lx",
6486 ASM_COMMENT_START, ft_index);
6488 else
6490 ASM_OUTPUT_ASCII (asm_out_file,
6491 file_table[ft_index],
6492 (int) strlen (file_table[ft_index]) + 1);
6495 fputc ('\n', asm_out_file);
6497 /* Include directory index */
6498 output_uleb128 (0);
6499 fputc ('\n', asm_out_file);
6501 /* Modification time */
6502 output_uleb128 (0);
6503 fputc ('\n', asm_out_file);
6505 /* File length in bytes */
6506 output_uleb128 (0);
6507 fputc ('\n', asm_out_file);
6510 /* Terminate the file name table */
6511 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6512 fputc ('\n', asm_out_file);
6514 /* We used to set the address register to the first location in the text
6515 section here, but that didn't accomplish anything since we already
6516 have a line note for the opening brace of the first function. */
6518 /* Generate the line number to PC correspondence table, encoded as
6519 a series of state machine operations. */
6520 current_file = 1;
6521 current_line = 1;
6522 strcpy (prev_line_label, text_section_label);
6523 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6525 register dw_line_info_ref line_info = &line_info_table[lt_index];
6527 #if 0
6528 /* Disable this optimization for now; GDB wants to see two line notes
6529 at the beginning of a function so it can find the end of the
6530 prologue. */
6532 /* Don't emit anything for redundant notes. Just updating the
6533 address doesn't accomplish anything, because we already assume
6534 that anything after the last address is this line. */
6535 if (line_info->dw_line_num == current_line
6536 && line_info->dw_file_num == current_file)
6537 continue;
6538 #endif
6540 /* Emit debug info for the address of the current line, choosing
6541 the encoding that uses the least amount of space. */
6542 /* ??? Unfortunately, we have little choice here currently, and must
6543 always use the most general form. Gcc does not know the address
6544 delta itself, so we can't use DW_LNS_advance_pc. There are no known
6545 dwarf2 aware assemblers at this time, so we can't use any special
6546 pseudo ops that would allow the assembler to optimally encode this for
6547 us. Many ports do have length attributes which will give an upper
6548 bound on the address range. We could perhaps use length attributes
6549 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
6550 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6551 if (0)
6553 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6554 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6555 if (flag_debug_asm)
6556 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6557 ASM_COMMENT_START);
6559 fputc ('\n', asm_out_file);
6560 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
6561 fputc ('\n', asm_out_file);
6563 else
6565 /* This can handle any delta. This takes
6566 4+DWARF2_ADDR_SIZE bytes. */
6567 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6568 if (flag_debug_asm)
6569 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6570 ASM_COMMENT_START);
6571 fputc ('\n', asm_out_file);
6572 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6573 fputc ('\n', asm_out_file);
6574 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6575 fputc ('\n', asm_out_file);
6576 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6577 fputc ('\n', asm_out_file);
6579 strcpy (prev_line_label, line_label);
6581 /* Emit debug info for the source file of the current line, if
6582 different from the previous line. */
6583 if (line_info->dw_file_num != current_file)
6585 current_file = line_info->dw_file_num;
6586 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
6587 if (flag_debug_asm)
6588 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
6590 fputc ('\n', asm_out_file);
6591 output_uleb128 (current_file);
6592 if (flag_debug_asm)
6593 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
6595 fputc ('\n', asm_out_file);
6598 /* Emit debug info for the current line number, choosing the encoding
6599 that uses the least amount of space. */
6600 if (line_info->dw_line_num != current_line)
6602 line_offset = line_info->dw_line_num - current_line;
6603 line_delta = line_offset - DWARF_LINE_BASE;
6604 current_line = line_info->dw_line_num;
6605 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6607 /* This can handle deltas from -10 to 234, using the current
6608 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6609 takes 1 byte. */
6610 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6611 DWARF_LINE_OPCODE_BASE + line_delta);
6612 if (flag_debug_asm)
6613 fprintf (asm_out_file,
6614 "\t%s line %ld", ASM_COMMENT_START, current_line);
6616 fputc ('\n', asm_out_file);
6618 else
6620 /* This can handle any delta. This takes at least 4 bytes,
6621 depending on the value being encoded. */
6622 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
6623 if (flag_debug_asm)
6624 fprintf (asm_out_file, "\t%s advance to line %ld",
6625 ASM_COMMENT_START, current_line);
6627 fputc ('\n', asm_out_file);
6628 output_sleb128 (line_offset);
6629 fputc ('\n', asm_out_file);
6630 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6631 if (flag_debug_asm)
6632 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6633 fputc ('\n', asm_out_file);
6636 else
6638 /* We still need to start a new row, so output a copy insn. */
6639 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6640 if (flag_debug_asm)
6641 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6642 fputc ('\n', asm_out_file);
6646 /* Emit debug info for the address of the end of the function. */
6647 if (0)
6649 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6650 if (flag_debug_asm)
6651 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6652 ASM_COMMENT_START);
6654 fputc ('\n', asm_out_file);
6655 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
6656 fputc ('\n', asm_out_file);
6658 else
6660 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6661 if (flag_debug_asm)
6662 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
6663 fputc ('\n', asm_out_file);
6664 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6665 fputc ('\n', asm_out_file);
6666 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6667 fputc ('\n', asm_out_file);
6668 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
6669 fputc ('\n', asm_out_file);
6672 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6673 if (flag_debug_asm)
6674 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
6676 fputc ('\n', asm_out_file);
6677 output_uleb128 (1);
6678 fputc ('\n', asm_out_file);
6679 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
6680 fputc ('\n', asm_out_file);
6682 function = 0;
6683 current_file = 1;
6684 current_line = 1;
6685 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
6687 register dw_separate_line_info_ref line_info
6688 = &separate_line_info_table[lt_index];
6690 #if 0
6691 /* Don't emit anything for redundant notes. */
6692 if (line_info->dw_line_num == current_line
6693 && line_info->dw_file_num == current_file
6694 && line_info->function == function)
6695 goto cont;
6696 #endif
6698 /* Emit debug info for the address of the current line. If this is
6699 a new function, or the first line of a function, then we need
6700 to handle it differently. */
6701 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
6702 lt_index);
6703 if (function != line_info->function)
6705 function = line_info->function;
6707 /* Set the address register to the first line in the function */
6708 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6709 if (flag_debug_asm)
6710 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6711 ASM_COMMENT_START);
6713 fputc ('\n', asm_out_file);
6714 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6715 fputc ('\n', asm_out_file);
6716 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6717 fputc ('\n', asm_out_file);
6718 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6719 fputc ('\n', asm_out_file);
6721 else
6723 /* ??? See the DW_LNS_advance_pc comment above. */
6724 if (0)
6726 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6727 if (flag_debug_asm)
6728 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6729 ASM_COMMENT_START);
6731 fputc ('\n', asm_out_file);
6732 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
6733 prev_line_label);
6734 fputc ('\n', asm_out_file);
6736 else
6738 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6739 if (flag_debug_asm)
6740 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6741 ASM_COMMENT_START);
6742 fputc ('\n', asm_out_file);
6743 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6744 fputc ('\n', asm_out_file);
6745 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6746 fputc ('\n', asm_out_file);
6747 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6748 fputc ('\n', asm_out_file);
6751 strcpy (prev_line_label, line_label);
6753 /* Emit debug info for the source file of the current line, if
6754 different from the previous line. */
6755 if (line_info->dw_file_num != current_file)
6757 current_file = line_info->dw_file_num;
6758 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
6759 if (flag_debug_asm)
6760 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
6762 fputc ('\n', asm_out_file);
6763 output_uleb128 (current_file);
6764 if (flag_debug_asm)
6765 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
6767 fputc ('\n', asm_out_file);
6770 /* Emit debug info for the current line number, choosing the encoding
6771 that uses the least amount of space. */
6772 if (line_info->dw_line_num != current_line)
6774 line_offset = line_info->dw_line_num - current_line;
6775 line_delta = line_offset - DWARF_LINE_BASE;
6776 current_line = line_info->dw_line_num;
6777 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6779 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6780 DWARF_LINE_OPCODE_BASE + line_delta);
6781 if (flag_debug_asm)
6782 fprintf (asm_out_file,
6783 "\t%s line %ld", ASM_COMMENT_START, current_line);
6785 fputc ('\n', asm_out_file);
6787 else
6789 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
6790 if (flag_debug_asm)
6791 fprintf (asm_out_file, "\t%s advance to line %ld",
6792 ASM_COMMENT_START, current_line);
6794 fputc ('\n', asm_out_file);
6795 output_sleb128 (line_offset);
6796 fputc ('\n', asm_out_file);
6797 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6798 if (flag_debug_asm)
6799 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6800 fputc ('\n', asm_out_file);
6803 else
6805 /* We still need to start a new row, so output a copy insn. */
6806 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6807 if (flag_debug_asm)
6808 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6809 fputc ('\n', asm_out_file);
6812 #if 0
6813 cont:
6814 #endif
6815 ++lt_index;
6817 /* If we're done with a function, end its sequence. */
6818 if (lt_index == separate_line_info_table_in_use
6819 || separate_line_info_table[lt_index].function != function)
6821 current_file = 1;
6822 current_line = 1;
6824 /* Emit debug info for the address of the end of the function. */
6825 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
6826 if (0)
6828 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6829 if (flag_debug_asm)
6830 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6831 ASM_COMMENT_START);
6833 fputc ('\n', asm_out_file);
6834 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
6835 prev_line_label);
6836 fputc ('\n', asm_out_file);
6838 else
6840 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6841 if (flag_debug_asm)
6842 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6843 ASM_COMMENT_START);
6844 fputc ('\n', asm_out_file);
6845 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6846 fputc ('\n', asm_out_file);
6847 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6848 fputc ('\n', asm_out_file);
6849 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6850 fputc ('\n', asm_out_file);
6853 /* Output the marker for the end of this sequence. */
6854 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6855 if (flag_debug_asm)
6856 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
6857 ASM_COMMENT_START);
6859 fputc ('\n', asm_out_file);
6860 output_uleb128 (1);
6861 fputc ('\n', asm_out_file);
6862 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
6863 fputc ('\n', asm_out_file);
6867 /* Output the marker for the end of the line number info. */
6868 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
6871 /* Given a pointer to a tree node for some base type, return a pointer to
6872 a DIE that describes the given type.
6874 This routine must only be called for GCC type nodes that correspond to
6875 Dwarf base (fundamental) types. */
6877 static dw_die_ref
6878 base_type_die (type)
6879 register tree type;
6881 register dw_die_ref base_type_result;
6882 register const char *type_name;
6883 register enum dwarf_type encoding;
6884 register tree name = TYPE_NAME (type);
6886 if (TREE_CODE (type) == ERROR_MARK
6887 || TREE_CODE (type) == VOID_TYPE)
6888 return 0;
6890 if (name)
6892 if (TREE_CODE (name) == TYPE_DECL)
6893 name = DECL_NAME (name);
6895 type_name = IDENTIFIER_POINTER (name);
6897 else
6898 type_name = "__unknown__";
6900 switch (TREE_CODE (type))
6902 case INTEGER_TYPE:
6903 /* Carefully distinguish the C character types, without messing
6904 up if the language is not C. Note that we check only for the names
6905 that contain spaces; other names might occur by coincidence in other
6906 languages. */
6907 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6908 && (type == char_type_node
6909 || ! strcmp (type_name, "signed char")
6910 || ! strcmp (type_name, "unsigned char"))))
6912 if (TREE_UNSIGNED (type))
6913 encoding = DW_ATE_unsigned;
6914 else
6915 encoding = DW_ATE_signed;
6916 break;
6918 /* else fall through. */
6920 case CHAR_TYPE:
6921 /* GNU Pascal/Ada CHAR type. Not used in C. */
6922 if (TREE_UNSIGNED (type))
6923 encoding = DW_ATE_unsigned_char;
6924 else
6925 encoding = DW_ATE_signed_char;
6926 break;
6928 case REAL_TYPE:
6929 encoding = DW_ATE_float;
6930 break;
6932 /* Dwarf2 doesn't know anything about complex ints, so use
6933 a user defined type for it. */
6934 case COMPLEX_TYPE:
6935 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6936 encoding = DW_ATE_complex_float;
6937 else
6938 encoding = DW_ATE_lo_user;
6939 break;
6941 case BOOLEAN_TYPE:
6942 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6943 encoding = DW_ATE_boolean;
6944 break;
6946 default:
6947 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6950 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6951 if (demangle_name_func)
6952 type_name = (*demangle_name_func) (type_name);
6954 add_AT_string (base_type_result, DW_AT_name, type_name);
6955 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6956 int_size_in_bytes (type));
6957 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6959 return base_type_result;
6962 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6963 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6964 a given type is generally the same as the given type, except that if the
6965 given type is a pointer or reference type, then the root type of the given
6966 type is the root type of the "basis" type for the pointer or reference
6967 type. (This definition of the "root" type is recursive.) Also, the root
6968 type of a `const' qualified type or a `volatile' qualified type is the
6969 root type of the given type without the qualifiers. */
6971 static tree
6972 root_type (type)
6973 register tree type;
6975 if (TREE_CODE (type) == ERROR_MARK)
6976 return error_mark_node;
6978 switch (TREE_CODE (type))
6980 case ERROR_MARK:
6981 return error_mark_node;
6983 case POINTER_TYPE:
6984 case REFERENCE_TYPE:
6985 return type_main_variant (root_type (TREE_TYPE (type)));
6987 default:
6988 return type_main_variant (type);
6992 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6993 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6995 static inline int
6996 is_base_type (type)
6997 register tree type;
6999 switch (TREE_CODE (type))
7001 case ERROR_MARK:
7002 case VOID_TYPE:
7003 case INTEGER_TYPE:
7004 case REAL_TYPE:
7005 case COMPLEX_TYPE:
7006 case BOOLEAN_TYPE:
7007 case CHAR_TYPE:
7008 return 1;
7010 case SET_TYPE:
7011 case ARRAY_TYPE:
7012 case RECORD_TYPE:
7013 case UNION_TYPE:
7014 case QUAL_UNION_TYPE:
7015 case ENUMERAL_TYPE:
7016 case FUNCTION_TYPE:
7017 case METHOD_TYPE:
7018 case POINTER_TYPE:
7019 case REFERENCE_TYPE:
7020 case FILE_TYPE:
7021 case OFFSET_TYPE:
7022 case LANG_TYPE:
7023 return 0;
7025 default:
7026 abort ();
7029 return 0;
7032 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7033 entry that chains various modifiers in front of the given type. */
7035 static dw_die_ref
7036 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7037 register tree type;
7038 register int is_const_type;
7039 register int is_volatile_type;
7040 register dw_die_ref context_die;
7042 register enum tree_code code = TREE_CODE (type);
7043 register dw_die_ref mod_type_die = NULL;
7044 register dw_die_ref sub_die = NULL;
7045 register tree item_type = NULL;
7047 if (code != ERROR_MARK)
7049 type = build_type_variant (type, is_const_type, is_volatile_type);
7051 mod_type_die = lookup_type_die (type);
7052 if (mod_type_die)
7053 return mod_type_die;
7055 /* Handle C typedef types. */
7056 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7057 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
7059 tree dtype = TREE_TYPE (TYPE_NAME (type));
7060 if (type == dtype)
7062 /* For a named type, use the typedef. */
7063 gen_type_die (type, context_die);
7064 mod_type_die = lookup_type_die (type);
7067 else if (is_const_type < TYPE_READONLY (dtype)
7068 || is_volatile_type < TYPE_VOLATILE (dtype))
7069 /* cv-unqualified version of named type. Just use the unnamed
7070 type to which it refers. */
7071 mod_type_die
7072 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
7073 is_const_type, is_volatile_type,
7074 context_die);
7075 /* Else cv-qualified version of named type; fall through. */
7078 if (mod_type_die)
7079 /* OK. */
7081 else if (is_const_type)
7083 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7084 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7086 else if (is_volatile_type)
7088 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7089 sub_die = modified_type_die (type, 0, 0, context_die);
7091 else if (code == POINTER_TYPE)
7093 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7094 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7095 #if 0
7096 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7097 #endif
7098 item_type = TREE_TYPE (type);
7100 else if (code == REFERENCE_TYPE)
7102 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7103 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7104 #if 0
7105 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7106 #endif
7107 item_type = TREE_TYPE (type);
7109 else if (is_base_type (type))
7110 mod_type_die = base_type_die (type);
7111 else
7113 gen_type_die (type, context_die);
7115 /* We have to get the type_main_variant here (and pass that to the
7116 `lookup_type_die' routine) because the ..._TYPE node we have
7117 might simply be a *copy* of some original type node (where the
7118 copy was created to help us keep track of typedef names) and
7119 that copy might have a different TYPE_UID from the original
7120 ..._TYPE node. */
7121 mod_type_die = lookup_type_die (type_main_variant (type));
7122 if (mod_type_die == NULL)
7123 abort ();
7127 equate_type_number_to_die (type, mod_type_die);
7128 if (item_type)
7129 /* We must do this after the equate_type_number_to_die call, in case
7130 this is a recursive type. This ensures that the modified_type_die
7131 recursion will terminate even if the type is recursive. Recursive
7132 types are possible in Ada. */
7133 sub_die = modified_type_die (item_type,
7134 TYPE_READONLY (item_type),
7135 TYPE_VOLATILE (item_type),
7136 context_die);
7138 if (sub_die != NULL)
7139 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7141 return mod_type_die;
7144 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7145 an enumerated type. */
7147 static inline int
7148 type_is_enum (type)
7149 register tree type;
7151 return TREE_CODE (type) == ENUMERAL_TYPE;
7154 /* Return the register number described by a given RTL node. */
7156 static unsigned int
7157 reg_number (rtl)
7158 register rtx rtl;
7160 register unsigned regno = REGNO (rtl);
7162 if (regno >= FIRST_PSEUDO_REGISTER)
7164 warning ("internal regno botch: regno = %d\n", regno);
7165 regno = 0;
7168 regno = DBX_REGISTER_NUMBER (regno);
7169 return regno;
7172 /* Return a location descriptor that designates a machine register. */
7174 static dw_loc_descr_ref
7175 reg_loc_descriptor (rtl)
7176 register rtx rtl;
7178 register dw_loc_descr_ref loc_result = NULL;
7179 register unsigned reg = reg_number (rtl);
7181 if (reg <= 31)
7182 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7183 else
7184 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7186 return loc_result;
7189 /* Return a location descriptor that designates a constant. */
7191 static dw_loc_descr_ref
7192 int_loc_descriptor (i)
7193 HOST_WIDE_INT i;
7195 enum dwarf_location_atom op;
7197 /* Pick the smallest representation of a constant, rather than just
7198 defaulting to the LEB encoding. */
7199 if (i >= 0)
7201 if (i <= 31)
7202 op = DW_OP_lit0 + i;
7203 else if (i <= 0xff)
7204 op = DW_OP_const1u;
7205 else if (i <= 0xffff)
7206 op = DW_OP_const2u;
7207 else if (HOST_BITS_PER_WIDE_INT == 32
7208 || i <= 0xffffffff)
7209 op = DW_OP_const4u;
7210 else
7211 op = DW_OP_constu;
7213 else
7215 if (i >= -0x80)
7216 op = DW_OP_const1s;
7217 else if (i >= -0x8000)
7218 op = DW_OP_const2s;
7219 else if (HOST_BITS_PER_WIDE_INT == 32
7220 || i >= -0x80000000)
7221 op = DW_OP_const4s;
7222 else
7223 op = DW_OP_consts;
7226 return new_loc_descr (op, i, 0);
7229 /* Return a location descriptor that designates a base+offset location. */
7231 static dw_loc_descr_ref
7232 based_loc_descr (reg, offset)
7233 unsigned reg;
7234 long int offset;
7236 register dw_loc_descr_ref loc_result;
7237 /* For the "frame base", we use the frame pointer or stack pointer
7238 registers, since the RTL for local variables is relative to one of
7239 them. */
7240 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7241 ? HARD_FRAME_POINTER_REGNUM
7242 : STACK_POINTER_REGNUM);
7244 if (reg == fp_reg)
7245 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7246 else if (reg <= 31)
7247 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7248 else
7249 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7251 return loc_result;
7254 /* Return true if this RTL expression describes a base+offset calculation. */
7256 static inline int
7257 is_based_loc (rtl)
7258 register rtx rtl;
7260 return (GET_CODE (rtl) == PLUS
7261 && ((GET_CODE (XEXP (rtl, 0)) == REG
7262 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7265 /* The following routine converts the RTL for a variable or parameter
7266 (resident in memory) into an equivalent Dwarf representation of a
7267 mechanism for getting the address of that same variable onto the top of a
7268 hypothetical "address evaluation" stack.
7270 When creating memory location descriptors, we are effectively transforming
7271 the RTL for a memory-resident object into its Dwarf postfix expression
7272 equivalent. This routine recursively descends an RTL tree, turning
7273 it into Dwarf postfix code as it goes.
7275 MODE is the mode of the memory reference, needed to handle some
7276 autoincrement addressing modes. */
7278 static dw_loc_descr_ref
7279 mem_loc_descriptor (rtl, mode)
7280 register rtx rtl;
7281 enum machine_mode mode;
7283 dw_loc_descr_ref mem_loc_result = NULL;
7284 /* Note that for a dynamically sized array, the location we will generate a
7285 description of here will be the lowest numbered location which is
7286 actually within the array. That's *not* necessarily the same as the
7287 zeroth element of the array. */
7289 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7290 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7291 #endif
7293 switch (GET_CODE (rtl))
7295 case POST_INC:
7296 case POST_DEC:
7297 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7298 just fall into the SUBREG code. */
7300 /* Fall through. */
7302 case SUBREG:
7303 /* The case of a subreg may arise when we have a local (register)
7304 variable or a formal (register) parameter which doesn't quite fill
7305 up an entire register. For now, just assume that it is
7306 legitimate to make the Dwarf info refer to the whole register which
7307 contains the given subreg. */
7308 rtl = XEXP (rtl, 0);
7310 /* Fall through. */
7312 case REG:
7313 /* Whenever a register number forms a part of the description of the
7314 method for calculating the (dynamic) address of a memory resident
7315 object, DWARF rules require the register number be referred to as
7316 a "base register". This distinction is not based in any way upon
7317 what category of register the hardware believes the given register
7318 belongs to. This is strictly DWARF terminology we're dealing with
7319 here. Note that in cases where the location of a memory-resident
7320 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7321 OP_CONST (0)) the actual DWARF location descriptor that we generate
7322 may just be OP_BASEREG (basereg). This may look deceptively like
7323 the object in question was allocated to a register (rather than in
7324 memory) so DWARF consumers need to be aware of the subtle
7325 distinction between OP_REG and OP_BASEREG. */
7326 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7327 break;
7329 case MEM:
7331 dw_loc_descr_ref deref;
7333 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7335 if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
7336 deref = new_loc_descr (DW_OP_deref, 0, 0);
7337 else
7338 deref = new_loc_descr (DW_OP_deref_size, GET_MODE_SIZE (mode), 0);
7340 add_loc_descr (&mem_loc_result, deref);
7342 break;
7344 case LABEL_REF:
7345 /* Some ports can transform a symbol ref into a label ref, because
7346 the symbol ref is too far away and has to be dumped into a constant
7347 pool. */
7348 case CONST:
7349 case SYMBOL_REF:
7350 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7351 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7352 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7353 break;
7355 case PRE_INC:
7356 case PRE_DEC:
7357 /* Turn these into a PLUS expression and fall into the PLUS code
7358 below. */
7359 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7360 GEN_INT (GET_CODE (rtl) == PRE_INC
7361 ? GET_MODE_UNIT_SIZE (mode)
7362 : -GET_MODE_UNIT_SIZE (mode)));
7364 /* Fall through. */
7366 case PLUS:
7367 if (is_based_loc (rtl))
7368 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7369 INTVAL (XEXP (rtl, 1)));
7370 else
7372 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7374 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7375 && INTVAL (XEXP (rtl, 1)) >= 0)
7377 add_loc_descr (&mem_loc_result,
7378 new_loc_descr (DW_OP_plus_uconst,
7379 INTVAL (XEXP (rtl, 1)), 0));
7381 else
7383 add_loc_descr (&mem_loc_result,
7384 mem_loc_descriptor (XEXP (rtl, 1), mode));
7385 add_loc_descr (&mem_loc_result,
7386 new_loc_descr (DW_OP_plus, 0, 0));
7389 break;
7391 case MULT:
7392 /* If a pseudo-reg is optimized away, it is possible for it to
7393 be replaced with a MEM containing a multiply. */
7394 add_loc_descr (&mem_loc_result,
7395 mem_loc_descriptor (XEXP (rtl, 0), mode));
7396 add_loc_descr (&mem_loc_result,
7397 mem_loc_descriptor (XEXP (rtl, 1), mode));
7398 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7399 break;
7401 case CONST_INT:
7402 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7403 break;
7405 default:
7406 abort ();
7409 return mem_loc_result;
7412 /* Return a descriptor that describes the concatenation of two locations.
7413 This is typically a complex variable. */
7415 static dw_loc_descr_ref
7416 concat_loc_descriptor (x0, x1)
7417 register rtx x0, x1;
7419 dw_loc_descr_ref cc_loc_result = NULL;
7421 if (!is_pseudo_reg (x0)
7422 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7423 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7424 add_loc_descr (&cc_loc_result,
7425 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7427 if (!is_pseudo_reg (x1)
7428 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7429 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7430 add_loc_descr (&cc_loc_result,
7431 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7433 return cc_loc_result;
7436 /* Output a proper Dwarf location descriptor for a variable or parameter
7437 which is either allocated in a register or in a memory location. For a
7438 register, we just generate an OP_REG and the register number. For a
7439 memory location we provide a Dwarf postfix expression describing how to
7440 generate the (dynamic) address of the object onto the address stack. */
7442 static dw_loc_descr_ref
7443 loc_descriptor (rtl)
7444 register rtx rtl;
7446 dw_loc_descr_ref loc_result = NULL;
7447 switch (GET_CODE (rtl))
7449 case SUBREG:
7450 /* The case of a subreg may arise when we have a local (register)
7451 variable or a formal (register) parameter which doesn't quite fill
7452 up an entire register. For now, just assume that it is
7453 legitimate to make the Dwarf info refer to the whole register which
7454 contains the given subreg. */
7455 rtl = XEXP (rtl, 0);
7457 /* Fall through. */
7459 case REG:
7460 loc_result = reg_loc_descriptor (rtl);
7461 break;
7463 case MEM:
7464 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7465 break;
7467 case CONCAT:
7468 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7469 break;
7471 default:
7472 abort ();
7475 return loc_result;
7478 /* Similar, but generate the descriptor from trees instead of rtl.
7479 This comes up particularly with variable length arrays. */
7481 static dw_loc_descr_ref
7482 loc_descriptor_from_tree (loc, addressp)
7483 tree loc;
7484 int addressp;
7486 dw_loc_descr_ref ret = NULL;
7487 int indirect_size = 0;
7488 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7489 enum dwarf_location_atom op;
7491 /* ??? Most of the time we do not take proper care for sign/zero
7492 extending the values properly. Hopefully this won't be a real
7493 problem... */
7495 switch (TREE_CODE (loc))
7497 case ERROR_MARK:
7498 break;
7500 case VAR_DECL:
7501 case PARM_DECL:
7503 rtx rtl = rtl_for_decl_location (loc);
7504 enum machine_mode mode = DECL_MODE (loc);
7506 if (rtl == NULL_RTX)
7507 break;
7508 else if (CONSTANT_P (rtl))
7510 ret = new_loc_descr (DW_OP_addr, 0, 0);
7511 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7512 ret->dw_loc_oprnd1.v.val_addr = rtl;
7513 indirect_size = GET_MODE_SIZE (mode);
7515 else
7517 if (GET_CODE (rtl) == MEM)
7519 indirect_size = GET_MODE_SIZE (mode);
7520 rtl = XEXP (rtl, 0);
7522 ret = mem_loc_descriptor (rtl, mode);
7525 break;
7527 case INDIRECT_REF:
7528 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7529 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
7530 break;
7532 case COMPONENT_REF:
7533 case BIT_FIELD_REF:
7534 case ARRAY_REF:
7536 tree obj, offset;
7537 HOST_WIDE_INT bitsize, bitpos, bytepos;
7538 enum machine_mode mode;
7539 int volatilep;
7540 unsigned int alignment;
7542 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7543 &unsignedp, &volatilep, &alignment);
7544 ret = loc_descriptor_from_tree (obj, 1);
7546 if (offset != NULL_TREE)
7548 /* Variable offset. */
7549 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7550 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7553 if (addressp)
7555 /* We cannot address anything not on a unit boundary. */
7556 if (bitpos % BITS_PER_UNIT != 0)
7557 abort ();
7559 else
7561 if (bitpos % BITS_PER_UNIT != 0
7562 || bitsize % BITS_PER_UNIT != 0)
7564 /* ??? We could handle this by loading and shifting etc.
7565 Wait until someone needs it before expending the effort. */
7566 abort ();
7569 indirect_size = bitsize / BITS_PER_UNIT;
7572 bytepos = bitpos / BITS_PER_UNIT;
7573 if (bytepos > 0)
7574 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7575 else if (bytepos < 0)
7577 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7578 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7580 break;
7583 case INTEGER_CST:
7584 if (host_integerp (loc, 0))
7585 ret = int_loc_descriptor (tree_low_cst (loc, 0));
7586 break;
7587 break;
7589 case BIT_AND_EXPR:
7590 op = DW_OP_and;
7591 goto do_binop;
7592 case BIT_XOR_EXPR:
7593 op = DW_OP_xor;
7594 goto do_binop;
7595 case BIT_IOR_EXPR:
7596 op = DW_OP_or;
7597 goto do_binop;
7598 case TRUNC_DIV_EXPR:
7599 op = DW_OP_div;
7600 goto do_binop;
7601 case MINUS_EXPR:
7602 op = DW_OP_minus;
7603 goto do_binop;
7604 case TRUNC_MOD_EXPR:
7605 op = DW_OP_mod;
7606 goto do_binop;
7607 case MULT_EXPR:
7608 op = DW_OP_mul;
7609 goto do_binop;
7610 case LSHIFT_EXPR:
7611 op = DW_OP_shl;
7612 goto do_binop;
7613 case RSHIFT_EXPR:
7614 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
7615 goto do_binop;
7616 case PLUS_EXPR:
7617 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
7618 && host_integerp (TREE_OPERAND (loc, 1), 0))
7620 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7621 add_loc_descr (&ret,
7622 new_loc_descr (DW_OP_plus_uconst,
7623 tree_low_cst (TREE_OPERAND (loc, 1),
7625 0));
7626 break;
7628 op = DW_OP_plus;
7629 goto do_binop;
7630 case LE_EXPR:
7631 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7632 break;
7633 op = DW_OP_le;
7634 goto do_binop;
7635 case GE_EXPR:
7636 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7637 break;
7638 op = DW_OP_ge;
7639 goto do_binop;
7640 case LT_EXPR:
7641 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7642 break;
7643 op = DW_OP_lt;
7644 goto do_binop;
7645 case GT_EXPR:
7646 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7647 break;
7648 op = DW_OP_gt;
7649 goto do_binop;
7650 case EQ_EXPR:
7651 op = DW_OP_eq;
7652 goto do_binop;
7653 case NE_EXPR:
7654 op = DW_OP_ne;
7655 goto do_binop;
7657 do_binop:
7658 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7659 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
7660 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7661 break;
7663 case BIT_NOT_EXPR:
7664 op = DW_OP_not;
7665 goto do_unop;
7666 case ABS_EXPR:
7667 op = DW_OP_abs;
7668 goto do_unop;
7669 case NEGATE_EXPR:
7670 op = DW_OP_neg;
7671 goto do_unop;
7673 do_unop:
7674 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7675 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7676 break;
7678 case MAX_EXPR:
7679 loc = build (COND_EXPR, TREE_TYPE (loc),
7680 build (LT_EXPR, integer_type_node,
7681 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
7682 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
7683 /* FALLTHRU */
7685 case COND_EXPR:
7687 dw_loc_descr_ref bra_node, jump_node, tmp;
7689 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7690 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
7691 add_loc_descr (&ret, bra_node);
7693 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
7694 add_loc_descr (&ret, tmp);
7695 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
7696 add_loc_descr (&ret, jump_node);
7698 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
7699 add_loc_descr (&ret, tmp);
7700 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7701 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
7703 /* ??? Need a node to point the skip at. Use a nop. */
7704 tmp = new_loc_descr (DW_OP_nop, 0, 0);
7705 add_loc_descr (&ret, tmp);
7706 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7707 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
7709 break;
7711 default:
7712 abort ();
7715 /* If we can't fill the request for an address, die. */
7716 if (addressp && indirect_size == 0)
7717 abort ();
7719 /* If we've got an address and don't want one, dereference. */
7720 if (!addressp && indirect_size > 0)
7722 if (indirect_size > DWARF2_ADDR_SIZE)
7723 abort ();
7724 if (indirect_size == DWARF2_ADDR_SIZE)
7725 op = DW_OP_deref;
7726 else
7727 op = DW_OP_deref_size;
7728 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
7731 return ret;
7734 /* Given a value, round it up to the lowest multiple of `boundary'
7735 which is not less than the value itself. */
7737 static inline HOST_WIDE_INT
7738 ceiling (value, boundary)
7739 HOST_WIDE_INT value;
7740 unsigned int boundary;
7742 return (((value + boundary - 1) / boundary) * boundary);
7745 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
7746 pointer to the declared type for the relevant field variable, or return
7747 `integer_type_node' if the given node turns out to be an
7748 ERROR_MARK node. */
7750 static inline tree
7751 field_type (decl)
7752 register tree decl;
7754 register tree type;
7756 if (TREE_CODE (decl) == ERROR_MARK)
7757 return integer_type_node;
7759 type = DECL_BIT_FIELD_TYPE (decl);
7760 if (type == NULL_TREE)
7761 type = TREE_TYPE (decl);
7763 return type;
7766 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7767 node, return the alignment in bits for the type, or else return
7768 BITS_PER_WORD if the node actually turns out to be an
7769 ERROR_MARK node. */
7771 static inline unsigned
7772 simple_type_align_in_bits (type)
7773 register tree type;
7775 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
7778 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7779 node, return the size in bits for the type if it is a constant, or else
7780 return the alignment for the type if the type's size is not constant, or
7781 else return BITS_PER_WORD if the type actually turns out to be an
7782 ERROR_MARK node. */
7784 static inline unsigned HOST_WIDE_INT
7785 simple_type_size_in_bits (type)
7786 register tree type;
7788 if (TREE_CODE (type) == ERROR_MARK)
7789 return BITS_PER_WORD;
7790 else
7792 register tree type_size_tree = TYPE_SIZE (type);
7794 if (! host_integerp (type_size_tree, 1))
7795 return TYPE_ALIGN (type);
7797 return tree_low_cst (type_size_tree, 1);
7801 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
7802 return the byte offset of the lowest addressed byte of the "containing
7803 object" for the given FIELD_DECL, or return 0 if we are unable to
7804 determine what that offset is, either because the argument turns out to
7805 be a pointer to an ERROR_MARK node, or because the offset is actually
7806 variable. (We can't handle the latter case just yet). */
7808 static HOST_WIDE_INT
7809 field_byte_offset (decl)
7810 register tree decl;
7812 unsigned int type_align_in_bytes;
7813 unsigned int type_align_in_bits;
7814 unsigned HOST_WIDE_INT type_size_in_bits;
7815 HOST_WIDE_INT object_offset_in_align_units;
7816 HOST_WIDE_INT object_offset_in_bits;
7817 HOST_WIDE_INT object_offset_in_bytes;
7818 tree type;
7819 tree field_size_tree;
7820 HOST_WIDE_INT bitpos_int;
7821 HOST_WIDE_INT deepest_bitpos;
7822 unsigned HOST_WIDE_INT field_size_in_bits;
7824 if (TREE_CODE (decl) == ERROR_MARK)
7825 return 0;
7827 if (TREE_CODE (decl) != FIELD_DECL)
7828 abort ();
7830 type = field_type (decl);
7831 field_size_tree = DECL_SIZE (decl);
7833 /* If there was an error, the size could be zero. */
7834 if (! field_size_tree)
7836 if (errorcount)
7837 return 0;
7839 abort ();
7842 /* We cannot yet cope with fields whose positions are variable, so
7843 for now, when we see such things, we simply return 0. Someday, we may
7844 be able to handle such cases, but it will be damn difficult. */
7845 if (! host_integerp (bit_position (decl), 0))
7846 return 0;
7848 bitpos_int = int_bit_position (decl);
7850 /* If we don't know the size of the field, pretend it's a full word. */
7851 if (host_integerp (field_size_tree, 1))
7852 field_size_in_bits = tree_low_cst (field_size_tree, 1);
7853 else
7854 field_size_in_bits = BITS_PER_WORD;
7856 type_size_in_bits = simple_type_size_in_bits (type);
7857 type_align_in_bits = simple_type_align_in_bits (type);
7858 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
7860 /* Note that the GCC front-end doesn't make any attempt to keep track of
7861 the starting bit offset (relative to the start of the containing
7862 structure type) of the hypothetical "containing object" for a bit-
7863 field. Thus, when computing the byte offset value for the start of the
7864 "containing object" of a bit-field, we must deduce this information on
7865 our own. This can be rather tricky to do in some cases. For example,
7866 handling the following structure type definition when compiling for an
7867 i386/i486 target (which only aligns long long's to 32-bit boundaries)
7868 can be very tricky:
7870 struct S { int field1; long long field2:31; };
7872 Fortunately, there is a simple rule-of-thumb which can be
7873 used in such cases. When compiling for an i386/i486, GCC will allocate
7874 8 bytes for the structure shown above. It decides to do this based upon
7875 one simple rule for bit-field allocation. Quite simply, GCC allocates
7876 each "containing object" for each bit-field at the first (i.e. lowest
7877 addressed) legitimate alignment boundary (based upon the required
7878 minimum alignment for the declared type of the field) which it can
7879 possibly use, subject to the condition that there is still enough
7880 available space remaining in the containing object (when allocated at
7881 the selected point) to fully accommodate all of the bits of the
7882 bit-field itself. This simple rule makes it obvious why GCC allocates
7883 8 bytes for each object of the structure type shown above. When looking
7884 for a place to allocate the "containing object" for `field2', the
7885 compiler simply tries to allocate a 64-bit "containing object" at each
7886 successive 32-bit boundary (starting at zero) until it finds a place to
7887 allocate that 64- bit field such that at least 31 contiguous (and
7888 previously unallocated) bits remain within that selected 64 bit field.
7889 (As it turns out, for the example above, the compiler finds that it is
7890 OK to allocate the "containing object" 64-bit field at bit-offset zero
7891 within the structure type.) Here we attempt to work backwards from the
7892 limited set of facts we're given, and we try to deduce from those facts,
7893 where GCC must have believed that the containing object started (within
7894 the structure type). The value we deduce is then used (by the callers of
7895 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
7896 for fields (both bit-fields and, in the case of DW_AT_location, regular
7897 fields as well). */
7899 /* Figure out the bit-distance from the start of the structure to the
7900 "deepest" bit of the bit-field. */
7901 deepest_bitpos = bitpos_int + field_size_in_bits;
7903 /* This is the tricky part. Use some fancy footwork to deduce where the
7904 lowest addressed bit of the containing object must be. */
7905 object_offset_in_bits
7906 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
7908 /* Compute the offset of the containing object in "alignment units". */
7909 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
7911 /* Compute the offset of the containing object in bytes. */
7912 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
7914 return object_offset_in_bytes;
7917 /* The following routines define various Dwarf attributes and any data
7918 associated with them. */
7920 /* Add a location description attribute value to a DIE.
7922 This emits location attributes suitable for whole variables and
7923 whole parameters. Note that the location attributes for struct fields are
7924 generated by the routine `data_member_location_attribute' below. */
7926 static void
7927 add_AT_location_description (die, attr_kind, rtl)
7928 dw_die_ref die;
7929 enum dwarf_attribute attr_kind;
7930 register rtx rtl;
7932 /* Handle a special case. If we are about to output a location descriptor
7933 for a variable or parameter which has been optimized out of existence,
7934 don't do that. A variable which has been optimized out
7935 of existence will have a DECL_RTL value which denotes a pseudo-reg.
7936 Currently, in some rare cases, variables can have DECL_RTL values which
7937 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
7938 elsewhere in the compiler. We treat such cases as if the variable(s) in
7939 question had been optimized out of existence. */
7941 if (is_pseudo_reg (rtl)
7942 || (GET_CODE (rtl) == MEM
7943 && is_pseudo_reg (XEXP (rtl, 0)))
7944 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
7945 references the internal argument pointer (a pseudo) in a function
7946 where all references to the internal argument pointer were
7947 eliminated via the optimizers. */
7948 || (GET_CODE (rtl) == MEM
7949 && GET_CODE (XEXP (rtl, 0)) == PLUS
7950 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
7951 || (GET_CODE (rtl) == CONCAT
7952 && is_pseudo_reg (XEXP (rtl, 0))
7953 && is_pseudo_reg (XEXP (rtl, 1))))
7954 return;
7956 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
7959 /* Attach the specialized form of location attribute used for data
7960 members of struct and union types. In the special case of a
7961 FIELD_DECL node which represents a bit-field, the "offset" part
7962 of this special location descriptor must indicate the distance
7963 in bytes from the lowest-addressed byte of the containing struct
7964 or union type to the lowest-addressed byte of the "containing
7965 object" for the bit-field. (See the `field_byte_offset' function
7966 above).. For any given bit-field, the "containing object" is a
7967 hypothetical object (of some integral or enum type) within which
7968 the given bit-field lives. The type of this hypothetical
7969 "containing object" is always the same as the declared type of
7970 the individual bit-field itself (for GCC anyway... the DWARF
7971 spec doesn't actually mandate this). Note that it is the size
7972 (in bytes) of the hypothetical "containing object" which will
7973 be given in the DW_AT_byte_size attribute for this bit-field.
7974 (See the `byte_size_attribute' function below.) It is also used
7975 when calculating the value of the DW_AT_bit_offset attribute.
7976 (See the `bit_offset_attribute' function below). */
7978 static void
7979 add_data_member_location_attribute (die, decl)
7980 register dw_die_ref die;
7981 register tree decl;
7983 register unsigned long offset;
7984 register dw_loc_descr_ref loc_descr;
7985 register enum dwarf_location_atom op;
7987 if (TREE_CODE (decl) == TREE_VEC)
7988 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
7989 else
7990 offset = field_byte_offset (decl);
7992 /* The DWARF2 standard says that we should assume that the structure address
7993 is already on the stack, so we can specify a structure field address
7994 by using DW_OP_plus_uconst. */
7996 #ifdef MIPS_DEBUGGING_INFO
7997 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
7998 correctly. It works only if we leave the offset on the stack. */
7999 op = DW_OP_constu;
8000 #else
8001 op = DW_OP_plus_uconst;
8002 #endif
8004 loc_descr = new_loc_descr (op, offset, 0);
8005 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8008 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8009 does not have a "location" either in memory or in a register. These
8010 things can arise in GNU C when a constant is passed as an actual parameter
8011 to an inlined function. They can also arise in C++ where declared
8012 constants do not necessarily get memory "homes". */
8014 static void
8015 add_const_value_attribute (die, rtl)
8016 register dw_die_ref die;
8017 register rtx rtl;
8019 switch (GET_CODE (rtl))
8021 case CONST_INT:
8022 /* Note that a CONST_INT rtx could represent either an integer or a
8023 floating-point constant. A CONST_INT is used whenever the constant
8024 will fit into a single word. In all such cases, the original mode
8025 of the constant value is wiped out, and the CONST_INT rtx is
8026 assigned VOIDmode. */
8027 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
8028 break;
8030 case CONST_DOUBLE:
8031 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8032 floating-point constant. A CONST_DOUBLE is used whenever the
8033 constant requires more than one word in order to be adequately
8034 represented. We output CONST_DOUBLEs as blocks. */
8036 register enum machine_mode mode = GET_MODE (rtl);
8038 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8040 register unsigned length = GET_MODE_SIZE (mode) / 4;
8041 long *array = (long *) xmalloc (sizeof (long) * length);
8042 REAL_VALUE_TYPE rv;
8044 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8045 switch (mode)
8047 case SFmode:
8048 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8049 break;
8051 case DFmode:
8052 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8053 break;
8055 case XFmode:
8056 case TFmode:
8057 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8058 break;
8060 default:
8061 abort ();
8064 add_AT_float (die, DW_AT_const_value, length, array);
8066 else
8067 add_AT_long_long (die, DW_AT_const_value,
8068 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8070 break;
8072 case CONST_STRING:
8073 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8074 break;
8076 case SYMBOL_REF:
8077 case LABEL_REF:
8078 case CONST:
8079 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8080 break;
8082 case PLUS:
8083 /* In cases where an inlined instance of an inline function is passed
8084 the address of an `auto' variable (which is local to the caller) we
8085 can get a situation where the DECL_RTL of the artificial local
8086 variable (for the inlining) which acts as a stand-in for the
8087 corresponding formal parameter (of the inline function) will look
8088 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8089 exactly a compile-time constant expression, but it isn't the address
8090 of the (artificial) local variable either. Rather, it represents the
8091 *value* which the artificial local variable always has during its
8092 lifetime. We currently have no way to represent such quasi-constant
8093 values in Dwarf, so for now we just punt and generate nothing. */
8094 break;
8096 default:
8097 /* No other kinds of rtx should be possible here. */
8098 abort ();
8103 static rtx
8104 rtl_for_decl_location (decl)
8105 tree decl;
8107 register rtx rtl;
8109 /* Here we have to decide where we are going to say the parameter "lives"
8110 (as far as the debugger is concerned). We only have a couple of
8111 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8113 DECL_RTL normally indicates where the parameter lives during most of the
8114 activation of the function. If optimization is enabled however, this
8115 could be either NULL or else a pseudo-reg. Both of those cases indicate
8116 that the parameter doesn't really live anywhere (as far as the code
8117 generation parts of GCC are concerned) during most of the function's
8118 activation. That will happen (for example) if the parameter is never
8119 referenced within the function.
8121 We could just generate a location descriptor here for all non-NULL
8122 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8123 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8124 where DECL_RTL is NULL or is a pseudo-reg.
8126 Note however that we can only get away with using DECL_INCOMING_RTL as
8127 a backup substitute for DECL_RTL in certain limited cases. In cases
8128 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8129 we can be sure that the parameter was passed using the same type as it is
8130 declared to have within the function, and that its DECL_INCOMING_RTL
8131 points us to a place where a value of that type is passed.
8133 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8134 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8135 because in these cases DECL_INCOMING_RTL points us to a value of some
8136 type which is *different* from the type of the parameter itself. Thus,
8137 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8138 such cases, the debugger would end up (for example) trying to fetch a
8139 `float' from a place which actually contains the first part of a
8140 `double'. That would lead to really incorrect and confusing
8141 output at debug-time.
8143 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8144 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8145 are a couple of exceptions however. On little-endian machines we can
8146 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8147 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8148 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8149 when (on a little-endian machine) a non-prototyped function has a
8150 parameter declared to be of type `short' or `char'. In such cases,
8151 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8152 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8153 passed `int' value. If the debugger then uses that address to fetch
8154 a `short' or a `char' (on a little-endian machine) the result will be
8155 the correct data, so we allow for such exceptional cases below.
8157 Note that our goal here is to describe the place where the given formal
8158 parameter lives during most of the function's activation (i.e. between
8159 the end of the prologue and the start of the epilogue). We'll do that
8160 as best as we can. Note however that if the given formal parameter is
8161 modified sometime during the execution of the function, then a stack
8162 backtrace (at debug-time) will show the function as having been
8163 called with the *new* value rather than the value which was
8164 originally passed in. This happens rarely enough that it is not
8165 a major problem, but it *is* a problem, and I'd like to fix it.
8167 A future version of dwarf2out.c may generate two additional
8168 attributes for any given DW_TAG_formal_parameter DIE which will
8169 describe the "passed type" and the "passed location" for the
8170 given formal parameter in addition to the attributes we now
8171 generate to indicate the "declared type" and the "active
8172 location" for each parameter. This additional set of attributes
8173 could be used by debuggers for stack backtraces. Separately, note
8174 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8175 NULL also. This happens (for example) for inlined-instances of
8176 inline function formal parameters which are never referenced.
8177 This really shouldn't be happening. All PARM_DECL nodes should
8178 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8179 doesn't currently generate these values for inlined instances of
8180 inline function parameters, so when we see such cases, we are
8181 just out-of-luck for the time being (until integrate.c
8182 gets fixed). */
8184 /* Use DECL_RTL as the "location" unless we find something better. */
8185 rtl = DECL_RTL (decl);
8187 if (TREE_CODE (decl) == PARM_DECL)
8189 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8191 tree declared_type = type_main_variant (TREE_TYPE (decl));
8192 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8194 /* This decl represents a formal parameter which was optimized out.
8195 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8196 all* cases where (rtl == NULL_RTX) just below. */
8197 if (declared_type == passed_type)
8198 rtl = DECL_INCOMING_RTL (decl);
8199 else if (! BYTES_BIG_ENDIAN
8200 && TREE_CODE (declared_type) == INTEGER_TYPE
8201 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8202 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8203 rtl = DECL_INCOMING_RTL (decl);
8206 /* If the parm was passed in registers, but lives on the stack, then
8207 make a big endian correction if the mode of the type of the
8208 parameter is not the same as the mode of the rtl. */
8209 /* ??? This is the same series of checks that are made in dbxout.c before
8210 we reach the big endian correction code there. It isn't clear if all
8211 of these checks are necessary here, but keeping them all is the safe
8212 thing to do. */
8213 else if (GET_CODE (rtl) == MEM
8214 && XEXP (rtl, 0) != const0_rtx
8215 && ! CONSTANT_P (XEXP (rtl, 0))
8216 /* Not passed in memory. */
8217 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8218 /* Not passed by invisible reference. */
8219 && (GET_CODE (XEXP (rtl, 0)) != REG
8220 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8221 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8222 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8223 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8224 #endif
8226 /* Big endian correction check. */
8227 && BYTES_BIG_ENDIAN
8228 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8229 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8230 < UNITS_PER_WORD))
8232 int offset = (UNITS_PER_WORD
8233 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8234 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8235 plus_constant (XEXP (rtl, 0), offset));
8239 if (rtl != NULL_RTX)
8241 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8242 #ifdef LEAF_REG_REMAP
8243 if (current_function_uses_only_leaf_regs)
8244 leaf_renumber_regs_insn (rtl);
8245 #endif
8248 return rtl;
8251 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8252 data attribute for a variable or a parameter. We generate the
8253 DW_AT_const_value attribute only in those cases where the given variable
8254 or parameter does not have a true "location" either in memory or in a
8255 register. This can happen (for example) when a constant is passed as an
8256 actual argument in a call to an inline function. (It's possible that
8257 these things can crop up in other ways also.) Note that one type of
8258 constant value which can be passed into an inlined function is a constant
8259 pointer. This can happen for example if an actual argument in an inlined
8260 function call evaluates to a compile-time constant address. */
8262 static void
8263 add_location_or_const_value_attribute (die, decl)
8264 register dw_die_ref die;
8265 register tree decl;
8267 register rtx rtl;
8269 if (TREE_CODE (decl) == ERROR_MARK)
8270 return;
8272 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8273 abort ();
8275 rtl = rtl_for_decl_location (decl);
8276 if (rtl == NULL_RTX)
8277 return;
8279 switch (GET_CODE (rtl))
8281 case ADDRESSOF:
8282 /* The address of a variable that was optimized away; don't emit
8283 anything. */
8284 break;
8286 case CONST_INT:
8287 case CONST_DOUBLE:
8288 case CONST_STRING:
8289 case SYMBOL_REF:
8290 case LABEL_REF:
8291 case CONST:
8292 case PLUS:
8293 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8294 add_const_value_attribute (die, rtl);
8295 break;
8297 case MEM:
8298 case REG:
8299 case SUBREG:
8300 case CONCAT:
8301 add_AT_location_description (die, DW_AT_location, rtl);
8302 break;
8304 default:
8305 abort ();
8309 /* If we don't have a copy of this variable in memory for some reason (such
8310 as a C++ member constant that doesn't have an out-of-line definition),
8311 we should tell the debugger about the constant value. */
8313 static void
8314 tree_add_const_value_attribute (var_die, decl)
8315 dw_die_ref var_die;
8316 tree decl;
8318 tree init = DECL_INITIAL (decl);
8319 tree type = TREE_TYPE (decl);
8321 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8322 && initializer_constant_valid_p (init, type) == null_pointer_node)
8323 /* OK */;
8324 else
8325 return;
8327 switch (TREE_CODE (type))
8329 case INTEGER_TYPE:
8330 if (host_integerp (init, 0))
8331 add_AT_unsigned (var_die, DW_AT_const_value,
8332 TREE_INT_CST_LOW (init));
8333 else
8334 add_AT_long_long (var_die, DW_AT_const_value,
8335 TREE_INT_CST_HIGH (init),
8336 TREE_INT_CST_LOW (init));
8337 break;
8339 default:;
8343 /* Generate an DW_AT_name attribute given some string value to be included as
8344 the value of the attribute. */
8346 static inline void
8347 add_name_attribute (die, name_string)
8348 register dw_die_ref die;
8349 register const char *name_string;
8351 if (name_string != NULL && *name_string != 0)
8353 if (demangle_name_func)
8354 name_string = (*demangle_name_func) (name_string);
8356 add_AT_string (die, DW_AT_name, name_string);
8360 /* Given a tree node describing an array bound (either lower or upper) output
8361 a representation for that bound. */
8363 static void
8364 add_bound_info (subrange_die, bound_attr, bound)
8365 register dw_die_ref subrange_die;
8366 register enum dwarf_attribute bound_attr;
8367 register tree bound;
8369 /* If this is an Ada unconstrained array type, then don't emit any debug
8370 info because the array bounds are unknown. They are parameterized when
8371 the type is instantiated. */
8372 if (contains_placeholder_p (bound))
8373 return;
8375 switch (TREE_CODE (bound))
8377 case ERROR_MARK:
8378 return;
8380 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8381 case INTEGER_CST:
8382 if (! host_integerp (bound, 0)
8383 || (bound_attr == DW_AT_lower_bound
8384 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8385 || (is_fortran () && integer_onep (bound)))))
8386 /* use the default */
8388 else
8389 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8390 break;
8392 case CONVERT_EXPR:
8393 case NOP_EXPR:
8394 case NON_LVALUE_EXPR:
8395 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8396 break;
8398 case SAVE_EXPR:
8399 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8400 access the upper bound values may be bogus. If they refer to a
8401 register, they may only describe how to get at these values at the
8402 points in the generated code right after they have just been
8403 computed. Worse yet, in the typical case, the upper bound values
8404 will not even *be* computed in the optimized code (though the
8405 number of elements will), so these SAVE_EXPRs are entirely
8406 bogus. In order to compensate for this fact, we check here to see
8407 if optimization is enabled, and if so, we don't add an attribute
8408 for the (unknown and unknowable) upper bound. This should not
8409 cause too much trouble for existing (stupid?) debuggers because
8410 they have to deal with empty upper bounds location descriptions
8411 anyway in order to be able to deal with incomplete array types.
8412 Of course an intelligent debugger (GDB?) should be able to
8413 comprehend that a missing upper bound specification in a array
8414 type used for a storage class `auto' local array variable
8415 indicates that the upper bound is both unknown (at compile- time)
8416 and unknowable (at run-time) due to optimization.
8418 We assume that a MEM rtx is safe because gcc wouldn't put the
8419 value there unless it was going to be used repeatedly in the
8420 function, i.e. for cleanups. */
8421 if (! optimize || (SAVE_EXPR_RTL (bound)
8422 && GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8424 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8425 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8426 register rtx loc = SAVE_EXPR_RTL (bound);
8428 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8429 it references an outer function's frame. */
8431 if (GET_CODE (loc) == MEM)
8433 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8435 if (XEXP (loc, 0) != new_addr)
8436 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8439 add_AT_flag (decl_die, DW_AT_artificial, 1);
8440 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8441 add_AT_location_description (decl_die, DW_AT_location, loc);
8442 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8445 /* Else leave out the attribute. */
8446 break;
8448 case VAR_DECL:
8449 case PARM_DECL:
8451 dw_die_ref decl_die = lookup_decl_die (bound);
8453 /* ??? Can this happen, or should the variable have been bound
8454 first? Probably it can, since I imagine that we try to create
8455 the types of parameters in the order in which they exist in
8456 the list, and won't have created a forward reference to a
8457 later parameter. */
8458 if (decl_die != NULL)
8459 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8460 break;
8463 default:
8465 /* Otherwise try to create a stack operation procedure to
8466 evaluate the value of the array bound. */
8468 dw_die_ref ctx, decl_die;
8469 dw_loc_descr_ref loc;
8471 loc = loc_descriptor_from_tree (bound, 0);
8472 if (loc == NULL)
8473 break;
8475 ctx = lookup_decl_die (current_function_decl);
8477 decl_die = new_die (DW_TAG_variable, ctx);
8478 add_AT_flag (decl_die, DW_AT_artificial, 1);
8479 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8480 add_AT_loc (decl_die, DW_AT_location, loc);
8482 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8483 break;
8488 /* Note that the block of subscript information for an array type also
8489 includes information about the element type of type given array type. */
8491 static void
8492 add_subscript_info (type_die, type)
8493 register dw_die_ref type_die;
8494 register tree type;
8496 #ifndef MIPS_DEBUGGING_INFO
8497 register unsigned dimension_number;
8498 #endif
8499 register tree lower, upper;
8500 register dw_die_ref subrange_die;
8502 /* The GNU compilers represent multidimensional array types as sequences of
8503 one dimensional array types whose element types are themselves array
8504 types. Here we squish that down, so that each multidimensional array
8505 type gets only one array_type DIE in the Dwarf debugging info. The draft
8506 Dwarf specification say that we are allowed to do this kind of
8507 compression in C (because there is no difference between an array or
8508 arrays and a multidimensional array in C) but for other source languages
8509 (e.g. Ada) we probably shouldn't do this. */
8511 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8512 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8513 We work around this by disabling this feature. See also
8514 gen_array_type_die. */
8515 #ifndef MIPS_DEBUGGING_INFO
8516 for (dimension_number = 0;
8517 TREE_CODE (type) == ARRAY_TYPE;
8518 type = TREE_TYPE (type), dimension_number++)
8520 #endif
8521 register tree domain = TYPE_DOMAIN (type);
8523 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8524 and (in GNU C only) variable bounds. Handle all three forms
8525 here. */
8526 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8527 if (domain)
8529 /* We have an array type with specified bounds. */
8530 lower = TYPE_MIN_VALUE (domain);
8531 upper = TYPE_MAX_VALUE (domain);
8533 /* define the index type. */
8534 if (TREE_TYPE (domain))
8536 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8537 TREE_TYPE field. We can't emit debug info for this
8538 because it is an unnamed integral type. */
8539 if (TREE_CODE (domain) == INTEGER_TYPE
8540 && TYPE_NAME (domain) == NULL_TREE
8541 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8542 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8544 else
8545 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8546 type_die);
8549 /* ??? If upper is NULL, the array has unspecified length,
8550 but it does have a lower bound. This happens with Fortran
8551 dimension arr(N:*)
8552 Since the debugger is definitely going to need to know N
8553 to produce useful results, go ahead and output the lower
8554 bound solo, and hope the debugger can cope. */
8556 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8557 if (upper)
8558 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8560 else
8561 /* We have an array type with an unspecified length. The DWARF-2
8562 spec does not say how to handle this; let's just leave out the
8563 bounds. */
8566 #ifndef MIPS_DEBUGGING_INFO
8568 #endif
8571 static void
8572 add_byte_size_attribute (die, tree_node)
8573 dw_die_ref die;
8574 register tree tree_node;
8576 register unsigned size;
8578 switch (TREE_CODE (tree_node))
8580 case ERROR_MARK:
8581 size = 0;
8582 break;
8583 case ENUMERAL_TYPE:
8584 case RECORD_TYPE:
8585 case UNION_TYPE:
8586 case QUAL_UNION_TYPE:
8587 size = int_size_in_bytes (tree_node);
8588 break;
8589 case FIELD_DECL:
8590 /* For a data member of a struct or union, the DW_AT_byte_size is
8591 generally given as the number of bytes normally allocated for an
8592 object of the *declared* type of the member itself. This is true
8593 even for bit-fields. */
8594 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8595 break;
8596 default:
8597 abort ();
8600 /* Note that `size' might be -1 when we get to this point. If it is, that
8601 indicates that the byte size of the entity in question is variable. We
8602 have no good way of expressing this fact in Dwarf at the present time,
8603 so just let the -1 pass on through. */
8605 add_AT_unsigned (die, DW_AT_byte_size, size);
8608 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8609 which specifies the distance in bits from the highest order bit of the
8610 "containing object" for the bit-field to the highest order bit of the
8611 bit-field itself.
8613 For any given bit-field, the "containing object" is a hypothetical
8614 object (of some integral or enum type) within which the given bit-field
8615 lives. The type of this hypothetical "containing object" is always the
8616 same as the declared type of the individual bit-field itself. The
8617 determination of the exact location of the "containing object" for a
8618 bit-field is rather complicated. It's handled by the
8619 `field_byte_offset' function (above).
8621 Note that it is the size (in bytes) of the hypothetical "containing object"
8622 which will be given in the DW_AT_byte_size attribute for this bit-field.
8623 (See `byte_size_attribute' above). */
8625 static inline void
8626 add_bit_offset_attribute (die, decl)
8627 register dw_die_ref die;
8628 register tree decl;
8630 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8631 tree type = DECL_BIT_FIELD_TYPE (decl);
8632 HOST_WIDE_INT bitpos_int;
8633 HOST_WIDE_INT highest_order_object_bit_offset;
8634 HOST_WIDE_INT highest_order_field_bit_offset;
8635 HOST_WIDE_INT unsigned bit_offset;
8637 /* Must be a field and a bit field. */
8638 if (!type
8639 || TREE_CODE (decl) != FIELD_DECL)
8640 abort ();
8642 /* We can't yet handle bit-fields whose offsets are variable, so if we
8643 encounter such things, just return without generating any attribute
8644 whatsoever. Likewise for variable or too large size. */
8645 if (! host_integerp (bit_position (decl), 0)
8646 || ! host_integerp (DECL_SIZE (decl), 1))
8647 return;
8649 bitpos_int = int_bit_position (decl);
8651 /* Note that the bit offset is always the distance (in bits) from the
8652 highest-order bit of the "containing object" to the highest-order bit of
8653 the bit-field itself. Since the "high-order end" of any object or field
8654 is different on big-endian and little-endian machines, the computation
8655 below must take account of these differences. */
8656 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
8657 highest_order_field_bit_offset = bitpos_int;
8659 if (! BYTES_BIG_ENDIAN)
8661 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
8662 highest_order_object_bit_offset += simple_type_size_in_bits (type);
8665 bit_offset
8666 = (! BYTES_BIG_ENDIAN
8667 ? highest_order_object_bit_offset - highest_order_field_bit_offset
8668 : highest_order_field_bit_offset - highest_order_object_bit_offset);
8670 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
8673 /* For a FIELD_DECL node which represents a bit field, output an attribute
8674 which specifies the length in bits of the given field. */
8676 static inline void
8677 add_bit_size_attribute (die, decl)
8678 register dw_die_ref die;
8679 register tree decl;
8681 /* Must be a field and a bit field. */
8682 if (TREE_CODE (decl) != FIELD_DECL
8683 || ! DECL_BIT_FIELD_TYPE (decl))
8684 abort ();
8686 if (host_integerp (DECL_SIZE (decl), 1))
8687 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
8690 /* If the compiled language is ANSI C, then add a 'prototyped'
8691 attribute, if arg types are given for the parameters of a function. */
8693 static inline void
8694 add_prototyped_attribute (die, func_type)
8695 register dw_die_ref die;
8696 register tree func_type;
8698 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
8699 && TYPE_ARG_TYPES (func_type) != NULL)
8700 add_AT_flag (die, DW_AT_prototyped, 1);
8703 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
8704 by looking in either the type declaration or object declaration
8705 equate table. */
8707 static inline void
8708 add_abstract_origin_attribute (die, origin)
8709 register dw_die_ref die;
8710 register tree origin;
8712 dw_die_ref origin_die = NULL;
8714 if (TREE_CODE (origin) != FUNCTION_DECL)
8716 /* We may have gotten separated from the block for the inlined
8717 function, if we're in an exception handler or some such; make
8718 sure that the abstract function has been written out.
8720 Doing this for nested functions is wrong, however; functions are
8721 distinct units, and our context might not even be inline. */
8722 tree fn = origin;
8723 if (TYPE_P (fn))
8724 fn = TYPE_STUB_DECL (fn);
8725 fn = decl_function_context (fn);
8726 if (fn)
8727 gen_abstract_function (fn);
8730 if (DECL_P (origin))
8731 origin_die = lookup_decl_die (origin);
8732 else if (TYPE_P (origin))
8733 origin_die = lookup_type_die (origin);
8735 if (origin_die == NULL)
8736 abort ();
8738 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
8741 /* We do not currently support the pure_virtual attribute. */
8743 static inline void
8744 add_pure_or_virtual_attribute (die, func_decl)
8745 register dw_die_ref die;
8746 register tree func_decl;
8748 if (DECL_VINDEX (func_decl))
8750 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8752 if (host_integerp (DECL_VINDEX (func_decl), 0))
8753 add_AT_loc (die, DW_AT_vtable_elem_location,
8754 new_loc_descr (DW_OP_constu,
8755 tree_low_cst (DECL_VINDEX (func_decl), 0),
8756 0));
8758 /* GNU extension: Record what type this method came from originally. */
8759 if (debug_info_level > DINFO_LEVEL_TERSE)
8760 add_AT_die_ref (die, DW_AT_containing_type,
8761 lookup_type_die (DECL_CONTEXT (func_decl)));
8765 /* Add source coordinate attributes for the given decl. */
8767 static void
8768 add_src_coords_attributes (die, decl)
8769 register dw_die_ref die;
8770 register tree decl;
8772 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
8774 add_AT_unsigned (die, DW_AT_decl_file, file_index);
8775 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8778 /* Add an DW_AT_name attribute and source coordinate attribute for the
8779 given decl, but only if it actually has a name. */
8781 static void
8782 add_name_and_src_coords_attributes (die, decl)
8783 register dw_die_ref die;
8784 register tree decl;
8786 register tree decl_name;
8788 decl_name = DECL_NAME (decl);
8789 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
8791 add_name_attribute (die, dwarf2_name (decl, 0));
8792 if (! DECL_ARTIFICIAL (decl))
8793 add_src_coords_attributes (die, decl);
8795 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
8796 && TREE_PUBLIC (decl)
8797 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
8798 add_AT_string (die, DW_AT_MIPS_linkage_name,
8799 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
8803 /* Push a new declaration scope. */
8805 static void
8806 push_decl_scope (scope)
8807 tree scope;
8809 /* Make room in the decl_scope_table, if necessary. */
8810 if (decl_scope_table_allocated == decl_scope_depth)
8812 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
8813 decl_scope_table
8814 = (tree *) xrealloc (decl_scope_table,
8815 decl_scope_table_allocated * sizeof (tree));
8818 decl_scope_table[decl_scope_depth] = scope;
8819 decl_scope_depth++;
8822 /* Pop a declaration scope. */
8823 static inline void
8824 pop_decl_scope ()
8826 if (decl_scope_depth <= 0)
8827 abort ();
8828 --decl_scope_depth;
8831 /* Return the DIE for the scope that immediately contains this type.
8832 Non-named types get global scope. Named types nested in other
8833 types get their containing scope if it's open, or global scope
8834 otherwise. All other types (i.e. function-local named types) get
8835 the current active scope. */
8837 static dw_die_ref
8838 scope_die_for (t, context_die)
8839 register tree t;
8840 register dw_die_ref context_die;
8842 register dw_die_ref scope_die = NULL;
8843 register tree containing_scope;
8844 register int i;
8846 /* Non-types always go in the current scope. */
8847 if (! TYPE_P (t))
8848 abort ();
8850 containing_scope = TYPE_CONTEXT (t);
8852 /* Ignore namespaces for the moment. */
8853 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
8854 containing_scope = NULL_TREE;
8856 /* Ignore function type "scopes" from the C frontend. They mean that
8857 a tagged type is local to a parmlist of a function declarator, but
8858 that isn't useful to DWARF. */
8859 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
8860 containing_scope = NULL_TREE;
8862 if (containing_scope == NULL_TREE)
8863 scope_die = comp_unit_die;
8864 else if (TYPE_P (containing_scope))
8866 /* For types, we can just look up the appropriate DIE. But
8867 first we check to see if we're in the middle of emitting it
8868 so we know where the new DIE should go. */
8870 for (i = decl_scope_depth - 1; i >= 0; --i)
8871 if (decl_scope_table[i] == containing_scope)
8872 break;
8874 if (i < 0)
8876 if (debug_info_level > DINFO_LEVEL_TERSE
8877 && !TREE_ASM_WRITTEN (containing_scope))
8878 abort ();
8880 /* If none of the current dies are suitable, we get file scope. */
8881 scope_die = comp_unit_die;
8883 else
8884 scope_die = lookup_type_die (containing_scope);
8886 else
8887 scope_die = context_die;
8889 return scope_die;
8892 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
8894 static inline int local_scope_p PARAMS ((dw_die_ref));
8895 static inline int
8896 local_scope_p (context_die)
8897 dw_die_ref context_die;
8899 for (; context_die; context_die = context_die->die_parent)
8900 if (context_die->die_tag == DW_TAG_inlined_subroutine
8901 || context_die->die_tag == DW_TAG_subprogram)
8902 return 1;
8903 return 0;
8906 /* Returns nonzero iff CONTEXT_DIE is a class. */
8908 static inline int class_scope_p PARAMS ((dw_die_ref));
8909 static inline int
8910 class_scope_p (context_die)
8911 dw_die_ref context_die;
8913 return (context_die
8914 && (context_die->die_tag == DW_TAG_structure_type
8915 || context_die->die_tag == DW_TAG_union_type));
8918 /* Many forms of DIEs require a "type description" attribute. This
8919 routine locates the proper "type descriptor" die for the type given
8920 by 'type', and adds an DW_AT_type attribute below the given die. */
8922 static void
8923 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
8924 register dw_die_ref object_die;
8925 register tree type;
8926 register int decl_const;
8927 register int decl_volatile;
8928 register dw_die_ref context_die;
8930 register enum tree_code code = TREE_CODE (type);
8931 register dw_die_ref type_die = NULL;
8933 /* ??? If this type is an unnamed subrange type of an integral or
8934 floating-point type, use the inner type. This is because we have no
8935 support for unnamed types in base_type_die. This can happen if this is
8936 an Ada subrange type. Correct solution is emit a subrange type die. */
8937 if ((code == INTEGER_TYPE || code == REAL_TYPE)
8938 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
8939 type = TREE_TYPE (type), code = TREE_CODE (type);
8941 if (code == ERROR_MARK)
8942 return;
8944 /* Handle a special case. For functions whose return type is void, we
8945 generate *no* type attribute. (Note that no object may have type
8946 `void', so this only applies to function return types). */
8947 if (code == VOID_TYPE)
8948 return;
8950 type_die = modified_type_die (type,
8951 decl_const || TYPE_READONLY (type),
8952 decl_volatile || TYPE_VOLATILE (type),
8953 context_die);
8954 if (type_die != NULL)
8955 add_AT_die_ref (object_die, DW_AT_type, type_die);
8958 /* Given a tree pointer to a struct, class, union, or enum type node, return
8959 a pointer to the (string) tag name for the given type, or zero if the type
8960 was declared without a tag. */
8962 static const char *
8963 type_tag (type)
8964 register tree type;
8966 register const char *name = 0;
8968 if (TYPE_NAME (type) != 0)
8970 register tree t = 0;
8972 /* Find the IDENTIFIER_NODE for the type name. */
8973 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
8974 t = TYPE_NAME (type);
8976 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
8977 a TYPE_DECL node, regardless of whether or not a `typedef' was
8978 involved. */
8979 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8980 && ! DECL_IGNORED_P (TYPE_NAME (type)))
8981 t = DECL_NAME (TYPE_NAME (type));
8983 /* Now get the name as a string, or invent one. */
8984 if (t != 0)
8985 name = IDENTIFIER_POINTER (t);
8988 return (name == 0 || *name == '\0') ? 0 : name;
8991 /* Return the type associated with a data member, make a special check
8992 for bit field types. */
8994 static inline tree
8995 member_declared_type (member)
8996 register tree member;
8998 return (DECL_BIT_FIELD_TYPE (member)
8999 ? DECL_BIT_FIELD_TYPE (member)
9000 : TREE_TYPE (member));
9003 /* Get the decl's label, as described by its RTL. This may be different
9004 from the DECL_NAME name used in the source file. */
9006 #if 0
9007 static const char *
9008 decl_start_label (decl)
9009 register tree decl;
9011 rtx x;
9012 const char *fnname;
9013 x = DECL_RTL (decl);
9014 if (GET_CODE (x) != MEM)
9015 abort ();
9017 x = XEXP (x, 0);
9018 if (GET_CODE (x) != SYMBOL_REF)
9019 abort ();
9021 fnname = XSTR (x, 0);
9022 return fnname;
9024 #endif
9026 /* These routines generate the internal representation of the DIE's for
9027 the compilation unit. Debugging information is collected by walking
9028 the declaration trees passed in from dwarf2out_decl(). */
9030 static void
9031 gen_array_type_die (type, context_die)
9032 register tree type;
9033 register dw_die_ref context_die;
9035 register dw_die_ref scope_die = scope_die_for (type, context_die);
9036 register dw_die_ref array_die;
9037 register tree element_type;
9039 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9040 the inner array type comes before the outer array type. Thus we must
9041 call gen_type_die before we call new_die. See below also. */
9042 #ifdef MIPS_DEBUGGING_INFO
9043 gen_type_die (TREE_TYPE (type), context_die);
9044 #endif
9046 array_die = new_die (DW_TAG_array_type, scope_die);
9048 #if 0
9049 /* We default the array ordering. SDB will probably do
9050 the right things even if DW_AT_ordering is not present. It's not even
9051 an issue until we start to get into multidimensional arrays anyway. If
9052 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9053 then we'll have to put the DW_AT_ordering attribute back in. (But if
9054 and when we find out that we need to put these in, we will only do so
9055 for multidimensional arrays. */
9056 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9057 #endif
9059 #ifdef MIPS_DEBUGGING_INFO
9060 /* The SGI compilers handle arrays of unknown bound by setting
9061 AT_declaration and not emitting any subrange DIEs. */
9062 if (! TYPE_DOMAIN (type))
9063 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9064 else
9065 #endif
9066 add_subscript_info (array_die, type);
9068 add_name_attribute (array_die, type_tag (type));
9069 equate_type_number_to_die (type, array_die);
9071 /* Add representation of the type of the elements of this array type. */
9072 element_type = TREE_TYPE (type);
9074 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9075 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9076 We work around this by disabling this feature. See also
9077 add_subscript_info. */
9078 #ifndef MIPS_DEBUGGING_INFO
9079 while (TREE_CODE (element_type) == ARRAY_TYPE)
9080 element_type = TREE_TYPE (element_type);
9082 gen_type_die (element_type, context_die);
9083 #endif
9085 add_type_attribute (array_die, element_type, 0, 0, context_die);
9088 static void
9089 gen_set_type_die (type, context_die)
9090 register tree type;
9091 register dw_die_ref context_die;
9093 register dw_die_ref type_die
9094 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9096 equate_type_number_to_die (type, type_die);
9097 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9100 #if 0
9101 static void
9102 gen_entry_point_die (decl, context_die)
9103 register tree decl;
9104 register dw_die_ref context_die;
9106 register tree origin = decl_ultimate_origin (decl);
9107 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9108 if (origin != NULL)
9109 add_abstract_origin_attribute (decl_die, origin);
9110 else
9112 add_name_and_src_coords_attributes (decl_die, decl);
9113 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9114 0, 0, context_die);
9117 if (DECL_ABSTRACT (decl))
9118 equate_decl_number_to_die (decl, decl_die);
9119 else
9120 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9122 #endif
9124 /* Remember a type in the incomplete_types_list. */
9126 static void
9127 add_incomplete_type (type)
9128 tree type;
9130 if (incomplete_types == incomplete_types_allocated)
9132 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
9133 incomplete_types_list
9134 = (tree *) xrealloc (incomplete_types_list,
9135 sizeof (tree) * incomplete_types_allocated);
9138 incomplete_types_list[incomplete_types++] = type;
9141 /* Walk through the list of incomplete types again, trying once more to
9142 emit full debugging info for them. */
9144 static void
9145 retry_incomplete_types ()
9147 register tree type;
9149 while (incomplete_types)
9151 --incomplete_types;
9152 type = incomplete_types_list[incomplete_types];
9153 gen_type_die (type, comp_unit_die);
9157 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9159 static void
9160 gen_inlined_enumeration_type_die (type, context_die)
9161 register tree type;
9162 register dw_die_ref context_die;
9164 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9165 context_die);
9166 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9167 be incomplete and such types are not marked. */
9168 add_abstract_origin_attribute (type_die, type);
9171 /* Generate a DIE to represent an inlined instance of a structure type. */
9173 static void
9174 gen_inlined_structure_type_die (type, context_die)
9175 register tree type;
9176 register dw_die_ref context_die;
9178 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9180 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9181 be incomplete and such types are not marked. */
9182 add_abstract_origin_attribute (type_die, type);
9185 /* Generate a DIE to represent an inlined instance of a union type. */
9187 static void
9188 gen_inlined_union_type_die (type, context_die)
9189 register tree type;
9190 register dw_die_ref context_die;
9192 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9194 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9195 be incomplete and such types are not marked. */
9196 add_abstract_origin_attribute (type_die, type);
9199 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9200 include all of the information about the enumeration values also. Each
9201 enumerated type name/value is listed as a child of the enumerated type
9202 DIE. */
9204 static void
9205 gen_enumeration_type_die (type, context_die)
9206 register tree type;
9207 register dw_die_ref context_die;
9209 register dw_die_ref type_die = lookup_type_die (type);
9211 if (type_die == NULL)
9213 type_die = new_die (DW_TAG_enumeration_type,
9214 scope_die_for (type, context_die));
9215 equate_type_number_to_die (type, type_die);
9216 add_name_attribute (type_die, type_tag (type));
9218 else if (! TYPE_SIZE (type))
9219 return;
9220 else
9221 remove_AT (type_die, DW_AT_declaration);
9223 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9224 given enum type is incomplete, do not generate the DW_AT_byte_size
9225 attribute or the DW_AT_element_list attribute. */
9226 if (TYPE_SIZE (type))
9228 register tree link;
9230 TREE_ASM_WRITTEN (type) = 1;
9231 add_byte_size_attribute (type_die, type);
9232 if (TYPE_STUB_DECL (type) != NULL_TREE)
9233 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9235 /* If the first reference to this type was as the return type of an
9236 inline function, then it may not have a parent. Fix this now. */
9237 if (type_die->die_parent == NULL)
9238 add_child_die (scope_die_for (type, context_die), type_die);
9240 for (link = TYPE_FIELDS (type);
9241 link != NULL; link = TREE_CHAIN (link))
9243 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9245 add_name_attribute (enum_die,
9246 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9248 if (host_integerp (TREE_VALUE (link), 0))
9250 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9251 add_AT_int (enum_die, DW_AT_const_value,
9252 tree_low_cst (TREE_VALUE (link), 0));
9253 else
9254 add_AT_unsigned (enum_die, DW_AT_const_value,
9255 tree_low_cst (TREE_VALUE (link), 0));
9259 else
9260 add_AT_flag (type_die, DW_AT_declaration, 1);
9263 /* Generate a DIE to represent either a real live formal parameter decl or to
9264 represent just the type of some formal parameter position in some function
9265 type.
9267 Note that this routine is a bit unusual because its argument may be a
9268 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9269 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9270 node. If it's the former then this function is being called to output a
9271 DIE to represent a formal parameter object (or some inlining thereof). If
9272 it's the latter, then this function is only being called to output a
9273 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9274 argument type of some subprogram type. */
9276 static dw_die_ref
9277 gen_formal_parameter_die (node, context_die)
9278 register tree node;
9279 register dw_die_ref context_die;
9281 register dw_die_ref parm_die
9282 = new_die (DW_TAG_formal_parameter, context_die);
9283 register tree origin;
9285 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9287 case 'd':
9288 origin = decl_ultimate_origin (node);
9289 if (origin != NULL)
9290 add_abstract_origin_attribute (parm_die, origin);
9291 else
9293 add_name_and_src_coords_attributes (parm_die, node);
9294 add_type_attribute (parm_die, TREE_TYPE (node),
9295 TREE_READONLY (node),
9296 TREE_THIS_VOLATILE (node),
9297 context_die);
9298 if (DECL_ARTIFICIAL (node))
9299 add_AT_flag (parm_die, DW_AT_artificial, 1);
9302 equate_decl_number_to_die (node, parm_die);
9303 if (! DECL_ABSTRACT (node))
9304 add_location_or_const_value_attribute (parm_die, node);
9306 break;
9308 case 't':
9309 /* We were called with some kind of a ..._TYPE node. */
9310 add_type_attribute (parm_die, node, 0, 0, context_die);
9311 break;
9313 default:
9314 abort ();
9317 return parm_die;
9320 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9321 at the end of an (ANSI prototyped) formal parameters list. */
9323 static void
9324 gen_unspecified_parameters_die (decl_or_type, context_die)
9325 register tree decl_or_type ATTRIBUTE_UNUSED;
9326 register dw_die_ref context_die;
9328 new_die (DW_TAG_unspecified_parameters, context_die);
9331 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9332 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9333 parameters as specified in some function type specification (except for
9334 those which appear as part of a function *definition*). */
9336 static void
9337 gen_formal_types_die (function_or_method_type, context_die)
9338 register tree function_or_method_type;
9339 register dw_die_ref context_die;
9341 register tree link;
9342 register tree formal_type = NULL;
9343 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9345 #if 0
9346 /* In the case where we are generating a formal types list for a C++
9347 non-static member function type, skip over the first thing on the
9348 TYPE_ARG_TYPES list because it only represents the type of the hidden
9349 `this pointer'. The debugger should be able to figure out (without
9350 being explicitly told) that this non-static member function type takes a
9351 `this pointer' and should be able to figure what the type of that hidden
9352 parameter is from the DW_AT_member attribute of the parent
9353 DW_TAG_subroutine_type DIE. */
9354 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
9355 first_parm_type = TREE_CHAIN (first_parm_type);
9356 #endif
9358 /* Make our first pass over the list of formal parameter types and output a
9359 DW_TAG_formal_parameter DIE for each one. */
9360 for (link = first_parm_type; link; link = TREE_CHAIN (link))
9362 register dw_die_ref parm_die;
9364 formal_type = TREE_VALUE (link);
9365 if (formal_type == void_type_node)
9366 break;
9368 /* Output a (nameless) DIE to represent the formal parameter itself. */
9369 parm_die = gen_formal_parameter_die (formal_type, context_die);
9370 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
9371 && link == first_parm_type)
9372 add_AT_flag (parm_die, DW_AT_artificial, 1);
9375 /* If this function type has an ellipsis, add a
9376 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9377 if (formal_type != void_type_node)
9378 gen_unspecified_parameters_die (function_or_method_type, context_die);
9380 /* Make our second (and final) pass over the list of formal parameter types
9381 and output DIEs to represent those types (as necessary). */
9382 for (link = TYPE_ARG_TYPES (function_or_method_type);
9383 link;
9384 link = TREE_CHAIN (link))
9386 formal_type = TREE_VALUE (link);
9387 if (formal_type == void_type_node)
9388 break;
9390 gen_type_die (formal_type, context_die);
9394 /* We want to generate the DIE for TYPE so that we can generate the
9395 die for MEMBER, which has been defined; we will need to refer back
9396 to the member declaration nested within TYPE. If we're trying to
9397 generate minimal debug info for TYPE, processing TYPE won't do the
9398 trick; we need to attach the member declaration by hand. */
9400 static void
9401 gen_type_die_for_member (type, member, context_die)
9402 tree type, member;
9403 dw_die_ref context_die;
9405 gen_type_die (type, context_die);
9407 /* If we're trying to avoid duplicate debug info, we may not have
9408 emitted the member decl for this function. Emit it now. */
9409 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9410 && ! lookup_decl_die (member))
9412 if (decl_ultimate_origin (member))
9413 abort ();
9415 push_decl_scope (type);
9416 if (TREE_CODE (member) == FUNCTION_DECL)
9417 gen_subprogram_die (member, lookup_type_die (type));
9418 else
9419 gen_variable_die (member, lookup_type_die (type));
9420 pop_decl_scope ();
9424 /* Generate the DWARF2 info for the "abstract" instance
9425 of a function which we may later generate inlined and/or
9426 out-of-line instances of. */
9428 static void
9429 gen_abstract_function (decl)
9430 tree decl;
9432 register dw_die_ref old_die = lookup_decl_die (decl);
9433 tree save_fn;
9435 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9436 /* We've already generated the abstract instance. */
9437 return;
9439 save_fn = current_function_decl;
9440 current_function_decl = decl;
9442 set_decl_abstract_flags (decl, 1);
9443 dwarf2out_decl (decl);
9444 set_decl_abstract_flags (decl, 0);
9446 current_function_decl = save_fn;
9449 /* Generate a DIE to represent a declared function (either file-scope or
9450 block-local). */
9452 static void
9453 gen_subprogram_die (decl, context_die)
9454 register tree decl;
9455 register dw_die_ref context_die;
9457 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9458 register tree origin = decl_ultimate_origin (decl);
9459 register dw_die_ref subr_die;
9460 register rtx fp_reg;
9461 register tree fn_arg_types;
9462 register tree outer_scope;
9463 register dw_die_ref old_die = lookup_decl_die (decl);
9464 register int declaration = (current_function_decl != decl
9465 || class_scope_p (context_die));
9467 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9468 be true, if we started to generate the abstract instance of an inline,
9469 decided to output its containing class, and proceeded to emit the
9470 declaration of the inline from the member list for the class. In that
9471 case, `declaration' takes priority; we'll get back to the abstract
9472 instance when we're done with the class. */
9474 /* The class-scope declaration DIE must be the primary DIE. */
9475 if (origin && declaration && class_scope_p (context_die))
9477 origin = NULL;
9478 if (old_die)
9479 abort ();
9482 if (origin != NULL)
9484 if (declaration && ! local_scope_p (context_die))
9485 abort ();
9487 /* Fixup die_parent for the abstract instance of a nested
9488 inline function. */
9489 if (old_die && old_die->die_parent == NULL)
9490 add_child_die (context_die, old_die);
9492 subr_die = new_die (DW_TAG_subprogram, context_die);
9493 add_abstract_origin_attribute (subr_die, origin);
9495 else if (old_die && DECL_ABSTRACT (decl)
9496 && get_AT_unsigned (old_die, DW_AT_inline))
9498 /* This must be a redefinition of an extern inline function.
9499 We can just reuse the old die here. */
9500 subr_die = old_die;
9502 /* Clear out the inlined attribute and parm types. */
9503 remove_AT (subr_die, DW_AT_inline);
9504 remove_children (subr_die);
9506 else if (old_die)
9508 register unsigned file_index
9509 = lookup_filename (DECL_SOURCE_FILE (decl));
9511 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
9513 /* ??? This can happen if there is a bug in the program, for
9514 instance, if it has duplicate function definitions. Ideally,
9515 we should detect this case and ignore it. For now, if we have
9516 already reported an error, any error at all, then assume that
9517 we got here because of a input error, not a dwarf2 bug. */
9518 if (errorcount)
9519 return;
9520 abort ();
9523 /* If the definition comes from the same place as the declaration,
9524 maybe use the old DIE. We always want the DIE for this function
9525 that has the *_pc attributes to be under comp_unit_die so the
9526 debugger can find it. For inlines, that is the concrete instance,
9527 so we can use the old DIE here. For non-inline methods, we want a
9528 specification DIE at toplevel, so we need a new DIE. For local
9529 class methods, this doesn't apply; we just use the old DIE. */
9530 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
9531 || context_die == NULL)
9532 && (DECL_ARTIFICIAL (decl)
9533 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9534 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9535 == (unsigned) DECL_SOURCE_LINE (decl)))))
9537 subr_die = old_die;
9539 /* Clear out the declaration attribute and the parm types. */
9540 remove_AT (subr_die, DW_AT_declaration);
9541 remove_children (subr_die);
9543 else
9545 subr_die = new_die (DW_TAG_subprogram, context_die);
9546 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9547 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9548 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9549 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9550 != (unsigned) DECL_SOURCE_LINE (decl))
9551 add_AT_unsigned
9552 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9555 else
9557 subr_die = new_die (DW_TAG_subprogram, context_die);
9559 if (TREE_PUBLIC (decl))
9560 add_AT_flag (subr_die, DW_AT_external, 1);
9562 add_name_and_src_coords_attributes (subr_die, decl);
9563 if (debug_info_level > DINFO_LEVEL_TERSE)
9565 register tree type = TREE_TYPE (decl);
9567 add_prototyped_attribute (subr_die, type);
9568 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9571 add_pure_or_virtual_attribute (subr_die, decl);
9572 if (DECL_ARTIFICIAL (decl))
9573 add_AT_flag (subr_die, DW_AT_artificial, 1);
9574 if (TREE_PROTECTED (decl))
9575 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9576 else if (TREE_PRIVATE (decl))
9577 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9580 if (declaration)
9582 if (! origin)
9583 add_AT_flag (subr_die, DW_AT_declaration, 1);
9585 /* The first time we see a member function, it is in the context of
9586 the class to which it belongs. We make sure of this by emitting
9587 the class first. The next time is the definition, which is
9588 handled above. The two may come from the same source text. */
9589 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9590 equate_decl_number_to_die (decl, subr_die);
9592 else if (DECL_ABSTRACT (decl))
9594 if (DECL_INLINE (decl) && !flag_no_inline)
9596 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9597 inline functions, but not for extern inline functions.
9598 We can't get this completely correct because information
9599 about whether the function was declared inline is not
9600 saved anywhere. */
9601 if (DECL_DEFER_OUTPUT (decl))
9602 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9603 else
9604 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9606 else
9607 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9609 equate_decl_number_to_die (decl, subr_die);
9611 else if (!DECL_EXTERNAL (decl))
9613 if (origin == NULL_TREE)
9614 equate_decl_number_to_die (decl, subr_die);
9616 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9617 current_funcdef_number);
9618 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
9619 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
9620 current_funcdef_number);
9621 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
9623 add_pubname (decl, subr_die);
9624 add_arange (decl, subr_die);
9626 #ifdef MIPS_DEBUGGING_INFO
9627 /* Add a reference to the FDE for this routine. */
9628 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
9629 #endif
9631 /* Define the "frame base" location for this routine. We use the
9632 frame pointer or stack pointer registers, since the RTL for local
9633 variables is relative to one of them. */
9634 fp_reg
9635 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
9636 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
9638 #if 0
9639 /* ??? This fails for nested inline functions, because context_display
9640 is not part of the state saved/restored for inline functions. */
9641 if (current_function_needs_context)
9642 add_AT_location_description (subr_die, DW_AT_static_link,
9643 lookup_static_chain (decl));
9644 #endif
9647 /* Now output descriptions of the arguments for this function. This gets
9648 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
9649 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
9650 `...' at the end of the formal parameter list. In order to find out if
9651 there was a trailing ellipsis or not, we must instead look at the type
9652 associated with the FUNCTION_DECL. This will be a node of type
9653 FUNCTION_TYPE. If the chain of type nodes hanging off of this
9654 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
9655 an ellipsis at the end. */
9657 /* In the case where we are describing a mere function declaration, all we
9658 need to do here (and all we *can* do here) is to describe the *types* of
9659 its formal parameters. */
9660 if (debug_info_level <= DINFO_LEVEL_TERSE)
9662 else if (declaration)
9663 gen_formal_types_die (TREE_TYPE (decl), subr_die);
9664 else
9666 /* Generate DIEs to represent all known formal parameters */
9667 register tree arg_decls = DECL_ARGUMENTS (decl);
9668 register tree parm;
9670 /* When generating DIEs, generate the unspecified_parameters DIE
9671 instead if we come across the arg "__builtin_va_alist" */
9672 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
9673 if (TREE_CODE (parm) == PARM_DECL)
9675 if (DECL_NAME (parm)
9676 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
9677 "__builtin_va_alist"))
9678 gen_unspecified_parameters_die (parm, subr_die);
9679 else
9680 gen_decl_die (parm, subr_die);
9683 /* Decide whether we need a unspecified_parameters DIE at the end.
9684 There are 2 more cases to do this for: 1) the ansi ... declaration -
9685 this is detectable when the end of the arg list is not a
9686 void_type_node 2) an unprototyped function declaration (not a
9687 definition). This just means that we have no info about the
9688 parameters at all. */
9689 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
9690 if (fn_arg_types != NULL)
9692 /* this is the prototyped case, check for ... */
9693 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
9694 gen_unspecified_parameters_die (decl, subr_die);
9696 else if (DECL_INITIAL (decl) == NULL_TREE)
9697 gen_unspecified_parameters_die (decl, subr_die);
9700 /* Output Dwarf info for all of the stuff within the body of the function
9701 (if it has one - it may be just a declaration). */
9702 outer_scope = DECL_INITIAL (decl);
9704 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
9705 node created to represent a function. This outermost BLOCK actually
9706 represents the outermost binding contour for the function, i.e. the
9707 contour in which the function's formal parameters and labels get
9708 declared. Curiously, it appears that the front end doesn't actually
9709 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
9710 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
9711 list for the function instead.) The BLOCK_VARS list for the
9712 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
9713 the function however, and we output DWARF info for those in
9714 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
9715 node representing the function's outermost pair of curly braces, and
9716 any blocks used for the base and member initializers of a C++
9717 constructor function. */
9718 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
9720 current_function_has_inlines = 0;
9721 decls_for_scope (outer_scope, subr_die, 0);
9723 #if 0 && defined (MIPS_DEBUGGING_INFO)
9724 if (current_function_has_inlines)
9726 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
9727 if (! comp_unit_has_inlines)
9729 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
9730 comp_unit_has_inlines = 1;
9733 #endif
9737 /* Generate a DIE to represent a declared data object. */
9739 static void
9740 gen_variable_die (decl, context_die)
9741 register tree decl;
9742 register dw_die_ref context_die;
9744 register tree origin = decl_ultimate_origin (decl);
9745 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
9747 dw_die_ref old_die = lookup_decl_die (decl);
9748 int declaration = (DECL_EXTERNAL (decl)
9749 || class_scope_p (context_die));
9751 if (origin != NULL)
9752 add_abstract_origin_attribute (var_die, origin);
9753 /* Loop unrolling can create multiple blocks that refer to the same
9754 static variable, so we must test for the DW_AT_declaration flag. */
9755 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
9756 copy decls and set the DECL_ABSTRACT flag on them instead of
9757 sharing them. */
9758 else if (old_die && TREE_STATIC (decl)
9759 && get_AT_flag (old_die, DW_AT_declaration) == 1)
9761 /* This is a definition of a C++ class level static. */
9762 add_AT_die_ref (var_die, DW_AT_specification, old_die);
9763 if (DECL_NAME (decl))
9765 register unsigned file_index
9766 = lookup_filename (DECL_SOURCE_FILE (decl));
9768 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9769 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
9771 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9772 != (unsigned) DECL_SOURCE_LINE (decl))
9774 add_AT_unsigned (var_die, DW_AT_decl_line,
9775 DECL_SOURCE_LINE (decl));
9778 else
9780 add_name_and_src_coords_attributes (var_die, decl);
9781 add_type_attribute (var_die, TREE_TYPE (decl),
9782 TREE_READONLY (decl),
9783 TREE_THIS_VOLATILE (decl), context_die);
9785 if (TREE_PUBLIC (decl))
9786 add_AT_flag (var_die, DW_AT_external, 1);
9788 if (DECL_ARTIFICIAL (decl))
9789 add_AT_flag (var_die, DW_AT_artificial, 1);
9791 if (TREE_PROTECTED (decl))
9792 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
9794 else if (TREE_PRIVATE (decl))
9795 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
9798 if (declaration)
9799 add_AT_flag (var_die, DW_AT_declaration, 1);
9801 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
9802 equate_decl_number_to_die (decl, var_die);
9804 if (! declaration && ! DECL_ABSTRACT (decl))
9806 add_location_or_const_value_attribute (var_die, decl);
9807 add_pubname (decl, var_die);
9809 else
9810 tree_add_const_value_attribute (var_die, decl);
9813 /* Generate a DIE to represent a label identifier. */
9815 static void
9816 gen_label_die (decl, context_die)
9817 register tree decl;
9818 register dw_die_ref context_die;
9820 register tree origin = decl_ultimate_origin (decl);
9821 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
9822 register rtx insn;
9823 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9825 if (origin != NULL)
9826 add_abstract_origin_attribute (lbl_die, origin);
9827 else
9828 add_name_and_src_coords_attributes (lbl_die, decl);
9830 if (DECL_ABSTRACT (decl))
9831 equate_decl_number_to_die (decl, lbl_die);
9832 else
9834 insn = DECL_RTL (decl);
9836 /* Deleted labels are programmer specified labels which have been
9837 eliminated because of various optimisations. We still emit them
9838 here so that it is possible to put breakpoints on them. */
9839 if (GET_CODE (insn) == CODE_LABEL
9840 || ((GET_CODE (insn) == NOTE
9841 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
9843 /* When optimization is enabled (via -O) some parts of the compiler
9844 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
9845 represent source-level labels which were explicitly declared by
9846 the user. This really shouldn't be happening though, so catch
9847 it if it ever does happen. */
9848 if (INSN_DELETED_P (insn))
9849 abort ();
9851 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
9852 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
9857 /* Generate a DIE for a lexical block. */
9859 static void
9860 gen_lexical_block_die (stmt, context_die, depth)
9861 register tree stmt;
9862 register dw_die_ref context_die;
9863 int depth;
9865 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
9866 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9868 if (! BLOCK_ABSTRACT (stmt))
9870 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9871 BLOCK_NUMBER (stmt));
9872 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
9873 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9874 BLOCK_NUMBER (stmt));
9875 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
9878 decls_for_scope (stmt, stmt_die, depth);
9881 /* Generate a DIE for an inlined subprogram. */
9883 static void
9884 gen_inlined_subroutine_die (stmt, context_die, depth)
9885 register tree stmt;
9886 register dw_die_ref context_die;
9887 int depth;
9889 if (! BLOCK_ABSTRACT (stmt))
9891 register dw_die_ref subr_die
9892 = new_die (DW_TAG_inlined_subroutine, context_die);
9893 register tree decl = block_ultimate_origin (stmt);
9894 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9896 /* Emit info for the abstract instance first, if we haven't yet. */
9897 gen_abstract_function (decl);
9899 add_abstract_origin_attribute (subr_die, decl);
9900 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9901 BLOCK_NUMBER (stmt));
9902 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
9903 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9904 BLOCK_NUMBER (stmt));
9905 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
9906 decls_for_scope (stmt, subr_die, depth);
9907 current_function_has_inlines = 1;
9911 /* Generate a DIE for a field in a record, or structure. */
9913 static void
9914 gen_field_die (decl, context_die)
9915 register tree decl;
9916 register dw_die_ref context_die;
9918 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
9920 add_name_and_src_coords_attributes (decl_die, decl);
9921 add_type_attribute (decl_die, member_declared_type (decl),
9922 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
9923 context_die);
9925 /* If this is a bit field... */
9926 if (DECL_BIT_FIELD_TYPE (decl))
9928 add_byte_size_attribute (decl_die, decl);
9929 add_bit_size_attribute (decl_die, decl);
9930 add_bit_offset_attribute (decl_die, decl);
9933 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
9934 add_data_member_location_attribute (decl_die, decl);
9936 if (DECL_ARTIFICIAL (decl))
9937 add_AT_flag (decl_die, DW_AT_artificial, 1);
9939 if (TREE_PROTECTED (decl))
9940 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
9942 else if (TREE_PRIVATE (decl))
9943 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
9946 #if 0
9947 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9948 Use modified_type_die instead.
9949 We keep this code here just in case these types of DIEs may be needed to
9950 represent certain things in other languages (e.g. Pascal) someday. */
9951 static void
9952 gen_pointer_type_die (type, context_die)
9953 register tree type;
9954 register dw_die_ref context_die;
9956 register dw_die_ref ptr_die
9957 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
9959 equate_type_number_to_die (type, ptr_die);
9960 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9961 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9964 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9965 Use modified_type_die instead.
9966 We keep this code here just in case these types of DIEs may be needed to
9967 represent certain things in other languages (e.g. Pascal) someday. */
9968 static void
9969 gen_reference_type_die (type, context_die)
9970 register tree type;
9971 register dw_die_ref context_die;
9973 register dw_die_ref ref_die
9974 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
9976 equate_type_number_to_die (type, ref_die);
9977 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
9978 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9980 #endif
9982 /* Generate a DIE for a pointer to a member type. */
9983 static void
9984 gen_ptr_to_mbr_type_die (type, context_die)
9985 register tree type;
9986 register dw_die_ref context_die;
9988 register dw_die_ref ptr_die
9989 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
9991 equate_type_number_to_die (type, ptr_die);
9992 add_AT_die_ref (ptr_die, DW_AT_containing_type,
9993 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
9994 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9997 /* Generate the DIE for the compilation unit. */
9999 static dw_die_ref
10000 gen_compile_unit_die (filename)
10001 register const char *filename;
10003 register dw_die_ref die;
10004 char producer[250];
10005 const char *wd = getpwd ();
10006 int language;
10008 die = new_die (DW_TAG_compile_unit, NULL);
10009 add_name_attribute (die, filename);
10011 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10012 add_AT_string (die, DW_AT_comp_dir, wd);
10014 sprintf (producer, "%s %s", language_string, version_string);
10016 #ifdef MIPS_DEBUGGING_INFO
10017 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10018 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10019 not appear in the producer string, the debugger reaches the conclusion
10020 that the object file is stripped and has no debugging information.
10021 To get the MIPS/SGI debugger to believe that there is debugging
10022 information in the object file, we add a -g to the producer string. */
10023 if (debug_info_level > DINFO_LEVEL_TERSE)
10024 strcat (producer, " -g");
10025 #endif
10027 add_AT_string (die, DW_AT_producer, producer);
10029 if (strcmp (language_string, "GNU C++") == 0)
10030 language = DW_LANG_C_plus_plus;
10031 else if (strcmp (language_string, "GNU Ada") == 0)
10032 language = DW_LANG_Ada83;
10033 else if (strcmp (language_string, "GNU F77") == 0)
10034 language = DW_LANG_Fortran77;
10035 else if (strcmp (language_string, "GNU Pascal") == 0)
10036 language = DW_LANG_Pascal83;
10037 else if (strcmp (language_string, "GNU Java") == 0)
10038 language = DW_LANG_Java;
10039 else if (flag_traditional)
10040 language = DW_LANG_C;
10041 else
10042 language = DW_LANG_C89;
10044 add_AT_unsigned (die, DW_AT_language, language);
10046 return die;
10049 /* Generate a DIE for a string type. */
10051 static void
10052 gen_string_type_die (type, context_die)
10053 register tree type;
10054 register dw_die_ref context_die;
10056 register dw_die_ref type_die
10057 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10059 equate_type_number_to_die (type, type_die);
10061 /* Fudge the string length attribute for now. */
10063 /* TODO: add string length info.
10064 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10065 bound_representation (upper_bound, 0, 'u'); */
10068 /* Generate the DIE for a base class. */
10070 static void
10071 gen_inheritance_die (binfo, context_die)
10072 register tree binfo;
10073 register dw_die_ref context_die;
10075 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10077 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10078 add_data_member_location_attribute (die, binfo);
10080 if (TREE_VIA_VIRTUAL (binfo))
10081 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10082 if (TREE_VIA_PUBLIC (binfo))
10083 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10084 else if (TREE_VIA_PROTECTED (binfo))
10085 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10088 /* Generate a DIE for a class member. */
10090 static void
10091 gen_member_die (type, context_die)
10092 register tree type;
10093 register dw_die_ref context_die;
10095 register tree member;
10096 dw_die_ref child;
10098 /* If this is not an incomplete type, output descriptions of each of its
10099 members. Note that as we output the DIEs necessary to represent the
10100 members of this record or union type, we will also be trying to output
10101 DIEs to represent the *types* of those members. However the `type'
10102 function (above) will specifically avoid generating type DIEs for member
10103 types *within* the list of member DIEs for this (containing) type execpt
10104 for those types (of members) which are explicitly marked as also being
10105 members of this (containing) type themselves. The g++ front- end can
10106 force any given type to be treated as a member of some other
10107 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10108 to point to the TREE node representing the appropriate (containing)
10109 type. */
10111 /* First output info about the base classes. */
10112 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10114 register tree bases = TYPE_BINFO_BASETYPES (type);
10115 register int n_bases = TREE_VEC_LENGTH (bases);
10116 register int i;
10118 for (i = 0; i < n_bases; i++)
10119 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10122 /* Now output info about the data members and type members. */
10123 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10125 /* If we thought we were generating minimal debug info for TYPE
10126 and then changed our minds, some of the member declarations
10127 may have already been defined. Don't define them again, but
10128 do put them in the right order. */
10130 child = lookup_decl_die (member);
10131 if (child)
10132 splice_child_die (context_die, child);
10133 else
10134 gen_decl_die (member, context_die);
10137 /* Now output info about the function members (if any). */
10138 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10140 child = lookup_decl_die (member);
10141 if (child)
10142 splice_child_die (context_die, child);
10143 else
10144 gen_decl_die (member, context_die);
10148 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10149 is set, we pretend that the type was never defined, so we only get the
10150 member DIEs needed by later specification DIEs. */
10152 static void
10153 gen_struct_or_union_type_die (type, context_die)
10154 register tree type;
10155 register dw_die_ref context_die;
10157 register dw_die_ref type_die = lookup_type_die (type);
10158 register dw_die_ref scope_die = 0;
10159 register int nested = 0;
10160 int complete = (TYPE_SIZE (type)
10161 && (! TYPE_STUB_DECL (type)
10162 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10164 if (type_die && ! complete)
10165 return;
10167 if (TYPE_CONTEXT (type) != NULL_TREE
10168 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10169 nested = 1;
10171 scope_die = scope_die_for (type, context_die);
10173 if (! type_die || (nested && scope_die == comp_unit_die))
10174 /* First occurrence of type or toplevel definition of nested class. */
10176 register dw_die_ref old_die = type_die;
10178 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10179 ? DW_TAG_structure_type : DW_TAG_union_type,
10180 scope_die);
10181 equate_type_number_to_die (type, type_die);
10182 if (old_die)
10183 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10184 else
10185 add_name_attribute (type_die, type_tag (type));
10187 else
10188 remove_AT (type_die, DW_AT_declaration);
10190 /* If this type has been completed, then give it a byte_size attribute and
10191 then give a list of members. */
10192 if (complete)
10194 /* Prevent infinite recursion in cases where the type of some member of
10195 this type is expressed in terms of this type itself. */
10196 TREE_ASM_WRITTEN (type) = 1;
10197 add_byte_size_attribute (type_die, type);
10198 if (TYPE_STUB_DECL (type) != NULL_TREE)
10199 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10201 /* If the first reference to this type was as the return type of an
10202 inline function, then it may not have a parent. Fix this now. */
10203 if (type_die->die_parent == NULL)
10204 add_child_die (scope_die, type_die);
10206 push_decl_scope (type);
10207 gen_member_die (type, type_die);
10208 pop_decl_scope ();
10210 /* GNU extension: Record what type our vtable lives in. */
10211 if (TYPE_VFIELD (type))
10213 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10215 gen_type_die (vtype, context_die);
10216 add_AT_die_ref (type_die, DW_AT_containing_type,
10217 lookup_type_die (vtype));
10220 else
10222 add_AT_flag (type_die, DW_AT_declaration, 1);
10224 /* We don't need to do this for function-local types. */
10225 if (! decl_function_context (TYPE_STUB_DECL (type)))
10226 add_incomplete_type (type);
10230 /* Generate a DIE for a subroutine _type_. */
10232 static void
10233 gen_subroutine_type_die (type, context_die)
10234 register tree type;
10235 register dw_die_ref context_die;
10237 register tree return_type = TREE_TYPE (type);
10238 register dw_die_ref subr_die
10239 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10241 equate_type_number_to_die (type, subr_die);
10242 add_prototyped_attribute (subr_die, type);
10243 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10244 gen_formal_types_die (type, subr_die);
10247 /* Generate a DIE for a type definition */
10249 static void
10250 gen_typedef_die (decl, context_die)
10251 register tree decl;
10252 register dw_die_ref context_die;
10254 register dw_die_ref type_die;
10255 register tree origin;
10257 if (TREE_ASM_WRITTEN (decl))
10258 return;
10259 TREE_ASM_WRITTEN (decl) = 1;
10261 type_die = new_die (DW_TAG_typedef, context_die);
10262 origin = decl_ultimate_origin (decl);
10263 if (origin != NULL)
10264 add_abstract_origin_attribute (type_die, origin);
10265 else
10267 register tree type;
10268 add_name_and_src_coords_attributes (type_die, decl);
10269 if (DECL_ORIGINAL_TYPE (decl))
10271 type = DECL_ORIGINAL_TYPE (decl);
10273 if (type == TREE_TYPE (decl))
10274 abort ();
10275 else
10276 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10278 else
10279 type = TREE_TYPE (decl);
10280 add_type_attribute (type_die, type, TREE_READONLY (decl),
10281 TREE_THIS_VOLATILE (decl), context_die);
10284 if (DECL_ABSTRACT (decl))
10285 equate_decl_number_to_die (decl, type_die);
10288 /* Generate a type description DIE. */
10290 static void
10291 gen_type_die (type, context_die)
10292 register tree type;
10293 register dw_die_ref context_die;
10295 int need_pop;
10297 if (type == NULL_TREE || type == error_mark_node)
10298 return;
10300 /* We are going to output a DIE to represent the unqualified version of
10301 this type (i.e. without any const or volatile qualifiers) so get the
10302 main variant (i.e. the unqualified version) of this type now. */
10303 type = type_main_variant (type);
10305 if (TREE_ASM_WRITTEN (type))
10306 return;
10308 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10309 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10311 TREE_ASM_WRITTEN (type) = 1;
10312 gen_decl_die (TYPE_NAME (type), context_die);
10313 return;
10316 switch (TREE_CODE (type))
10318 case ERROR_MARK:
10319 break;
10321 case POINTER_TYPE:
10322 case REFERENCE_TYPE:
10323 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10324 ensures that the gen_type_die recursion will terminate even if the
10325 type is recursive. Recursive types are possible in Ada. */
10326 /* ??? We could perhaps do this for all types before the switch
10327 statement. */
10328 TREE_ASM_WRITTEN (type) = 1;
10330 /* For these types, all that is required is that we output a DIE (or a
10331 set of DIEs) to represent the "basis" type. */
10332 gen_type_die (TREE_TYPE (type), context_die);
10333 break;
10335 case OFFSET_TYPE:
10336 /* This code is used for C++ pointer-to-data-member types.
10337 Output a description of the relevant class type. */
10338 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10340 /* Output a description of the type of the object pointed to. */
10341 gen_type_die (TREE_TYPE (type), context_die);
10343 /* Now output a DIE to represent this pointer-to-data-member type
10344 itself. */
10345 gen_ptr_to_mbr_type_die (type, context_die);
10346 break;
10348 case SET_TYPE:
10349 gen_type_die (TYPE_DOMAIN (type), context_die);
10350 gen_set_type_die (type, context_die);
10351 break;
10353 case FILE_TYPE:
10354 gen_type_die (TREE_TYPE (type), context_die);
10355 abort (); /* No way to represent these in Dwarf yet! */
10356 break;
10358 case FUNCTION_TYPE:
10359 /* Force out return type (in case it wasn't forced out already). */
10360 gen_type_die (TREE_TYPE (type), context_die);
10361 gen_subroutine_type_die (type, context_die);
10362 break;
10364 case METHOD_TYPE:
10365 /* Force out return type (in case it wasn't forced out already). */
10366 gen_type_die (TREE_TYPE (type), context_die);
10367 gen_subroutine_type_die (type, context_die);
10368 break;
10370 case ARRAY_TYPE:
10371 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10373 gen_type_die (TREE_TYPE (type), context_die);
10374 gen_string_type_die (type, context_die);
10376 else
10377 gen_array_type_die (type, context_die);
10378 break;
10380 case VECTOR_TYPE:
10381 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10382 break;
10384 case ENUMERAL_TYPE:
10385 case RECORD_TYPE:
10386 case UNION_TYPE:
10387 case QUAL_UNION_TYPE:
10388 /* If this is a nested type whose containing class hasn't been
10389 written out yet, writing it out will cover this one, too.
10390 This does not apply to instantiations of member class templates;
10391 they need to be added to the containing class as they are
10392 generated. FIXME: This hurts the idea of combining type decls
10393 from multiple TUs, since we can't predict what set of template
10394 instantiations we'll get. */
10395 if (TYPE_CONTEXT (type)
10396 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10397 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10399 gen_type_die (TYPE_CONTEXT (type), context_die);
10401 if (TREE_ASM_WRITTEN (type))
10402 return;
10404 /* If that failed, attach ourselves to the stub. */
10405 push_decl_scope (TYPE_CONTEXT (type));
10406 context_die = lookup_type_die (TYPE_CONTEXT (type));
10407 need_pop = 1;
10409 else
10410 need_pop = 0;
10412 if (TREE_CODE (type) == ENUMERAL_TYPE)
10413 gen_enumeration_type_die (type, context_die);
10414 else
10415 gen_struct_or_union_type_die (type, context_die);
10417 if (need_pop)
10418 pop_decl_scope ();
10420 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10421 it up if it is ever completed. gen_*_type_die will set it for us
10422 when appropriate. */
10423 return;
10425 case VOID_TYPE:
10426 case INTEGER_TYPE:
10427 case REAL_TYPE:
10428 case COMPLEX_TYPE:
10429 case BOOLEAN_TYPE:
10430 case CHAR_TYPE:
10431 /* No DIEs needed for fundamental types. */
10432 break;
10434 case LANG_TYPE:
10435 /* No Dwarf representation currently defined. */
10436 break;
10438 default:
10439 abort ();
10442 TREE_ASM_WRITTEN (type) = 1;
10445 /* Generate a DIE for a tagged type instantiation. */
10447 static void
10448 gen_tagged_type_instantiation_die (type, context_die)
10449 register tree type;
10450 register dw_die_ref context_die;
10452 if (type == NULL_TREE || type == error_mark_node)
10453 return;
10455 /* We are going to output a DIE to represent the unqualified version of
10456 this type (i.e. without any const or volatile qualifiers) so make sure
10457 that we have the main variant (i.e. the unqualified version) of this
10458 type now. */
10459 if (type != type_main_variant (type))
10460 abort ();
10462 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10463 an instance of an unresolved type. */
10465 switch (TREE_CODE (type))
10467 case ERROR_MARK:
10468 break;
10470 case ENUMERAL_TYPE:
10471 gen_inlined_enumeration_type_die (type, context_die);
10472 break;
10474 case RECORD_TYPE:
10475 gen_inlined_structure_type_die (type, context_die);
10476 break;
10478 case UNION_TYPE:
10479 case QUAL_UNION_TYPE:
10480 gen_inlined_union_type_die (type, context_die);
10481 break;
10483 default:
10484 abort ();
10488 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10489 things which are local to the given block. */
10491 static void
10492 gen_block_die (stmt, context_die, depth)
10493 register tree stmt;
10494 register dw_die_ref context_die;
10495 int depth;
10497 register int must_output_die = 0;
10498 register tree origin;
10499 register tree decl;
10500 register enum tree_code origin_code;
10502 /* Ignore blocks never really used to make RTL. */
10504 if (stmt == NULL_TREE || !TREE_USED (stmt)
10505 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10506 return;
10508 /* Determine the "ultimate origin" of this block. This block may be an
10509 inlined instance of an inlined instance of inline function, so we have
10510 to trace all of the way back through the origin chain to find out what
10511 sort of node actually served as the original seed for the creation of
10512 the current block. */
10513 origin = block_ultimate_origin (stmt);
10514 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10516 /* Determine if we need to output any Dwarf DIEs at all to represent this
10517 block. */
10518 if (origin_code == FUNCTION_DECL)
10519 /* The outer scopes for inlinings *must* always be represented. We
10520 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10521 must_output_die = 1;
10522 else
10524 /* In the case where the current block represents an inlining of the
10525 "body block" of an inline function, we must *NOT* output any DIE for
10526 this block because we have already output a DIE to represent the
10527 whole inlined function scope and the "body block" of any function
10528 doesn't really represent a different scope according to ANSI C
10529 rules. So we check here to make sure that this block does not
10530 represent a "body block inlining" before trying to set the
10531 `must_output_die' flag. */
10532 if (! is_body_block (origin ? origin : stmt))
10534 /* Determine if this block directly contains any "significant"
10535 local declarations which we will need to output DIEs for. */
10536 if (debug_info_level > DINFO_LEVEL_TERSE)
10537 /* We are not in terse mode so *any* local declaration counts
10538 as being a "significant" one. */
10539 must_output_die = (BLOCK_VARS (stmt) != NULL);
10540 else
10541 /* We are in terse mode, so only local (nested) function
10542 definitions count as "significant" local declarations. */
10543 for (decl = BLOCK_VARS (stmt);
10544 decl != NULL; decl = TREE_CHAIN (decl))
10545 if (TREE_CODE (decl) == FUNCTION_DECL
10546 && DECL_INITIAL (decl))
10548 must_output_die = 1;
10549 break;
10554 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10555 DIE for any block which contains no significant local declarations at
10556 all. Rather, in such cases we just call `decls_for_scope' so that any
10557 needed Dwarf info for any sub-blocks will get properly generated. Note
10558 that in terse mode, our definition of what constitutes a "significant"
10559 local declaration gets restricted to include only inlined function
10560 instances and local (nested) function definitions. */
10561 if (must_output_die)
10563 if (origin_code == FUNCTION_DECL)
10564 gen_inlined_subroutine_die (stmt, context_die, depth);
10565 else
10566 gen_lexical_block_die (stmt, context_die, depth);
10568 else
10569 decls_for_scope (stmt, context_die, depth);
10572 /* Generate all of the decls declared within a given scope and (recursively)
10573 all of its sub-blocks. */
10575 static void
10576 decls_for_scope (stmt, context_die, depth)
10577 register tree stmt;
10578 register dw_die_ref context_die;
10579 int depth;
10581 register tree decl;
10582 register tree subblocks;
10584 /* Ignore blocks never really used to make RTL. */
10585 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10586 return;
10588 /* Output the DIEs to represent all of the data objects and typedefs
10589 declared directly within this block but not within any nested
10590 sub-blocks. Also, nested function and tag DIEs have been
10591 generated with a parent of NULL; fix that up now. */
10592 for (decl = BLOCK_VARS (stmt);
10593 decl != NULL; decl = TREE_CHAIN (decl))
10595 register dw_die_ref die;
10597 if (TREE_CODE (decl) == FUNCTION_DECL)
10598 die = lookup_decl_die (decl);
10599 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
10600 die = lookup_type_die (TREE_TYPE (decl));
10601 else
10602 die = NULL;
10604 if (die != NULL && die->die_parent == NULL)
10605 add_child_die (context_die, die);
10606 else
10607 gen_decl_die (decl, context_die);
10610 /* Output the DIEs to represent all sub-blocks (and the items declared
10611 therein) of this block. */
10612 for (subblocks = BLOCK_SUBBLOCKS (stmt);
10613 subblocks != NULL;
10614 subblocks = BLOCK_CHAIN (subblocks))
10615 gen_block_die (subblocks, context_die, depth + 1);
10618 /* Is this a typedef we can avoid emitting? */
10620 static inline int
10621 is_redundant_typedef (decl)
10622 register tree decl;
10624 if (TYPE_DECL_IS_STUB (decl))
10625 return 1;
10627 if (DECL_ARTIFICIAL (decl)
10628 && DECL_CONTEXT (decl)
10629 && is_tagged_type (DECL_CONTEXT (decl))
10630 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
10631 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
10632 /* Also ignore the artificial member typedef for the class name. */
10633 return 1;
10635 return 0;
10638 /* Generate Dwarf debug information for a decl described by DECL. */
10640 static void
10641 gen_decl_die (decl, context_die)
10642 register tree decl;
10643 register dw_die_ref context_die;
10645 register tree origin;
10647 if (TREE_CODE (decl) == ERROR_MARK)
10648 return;
10650 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10651 if (DECL_IGNORED_P (decl))
10652 return;
10654 switch (TREE_CODE (decl))
10656 case CONST_DECL:
10657 /* The individual enumerators of an enum type get output when we output
10658 the Dwarf representation of the relevant enum type itself. */
10659 break;
10661 case FUNCTION_DECL:
10662 /* Don't output any DIEs to represent mere function declarations,
10663 unless they are class members or explicit block externs. */
10664 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
10665 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
10666 break;
10668 /* If we're emitting an out-of-line copy of an inline function,
10669 emit info for the abstract instance and set up to refer to it. */
10670 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
10671 && ! class_scope_p (context_die)
10672 /* gen_abstract_function won't emit a die if this is just a
10673 declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
10674 that case, because that works only if we have a die. */
10675 && DECL_INITIAL (decl) != NULL_TREE)
10677 gen_abstract_function (decl);
10678 set_decl_origin_self (decl);
10681 if (debug_info_level > DINFO_LEVEL_TERSE)
10683 /* Before we describe the FUNCTION_DECL itself, make sure that we
10684 have described its return type. */
10685 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
10687 /* And its virtual context. */
10688 if (DECL_VINDEX (decl) != NULL_TREE)
10689 gen_type_die (DECL_CONTEXT (decl), context_die);
10691 /* And its containing type. */
10692 origin = decl_class_context (decl);
10693 if (origin != NULL_TREE)
10694 gen_type_die_for_member (origin, decl, context_die);
10697 /* Now output a DIE to represent the function itself. */
10698 gen_subprogram_die (decl, context_die);
10699 break;
10701 case TYPE_DECL:
10702 /* If we are in terse mode, don't generate any DIEs to represent any
10703 actual typedefs. */
10704 if (debug_info_level <= DINFO_LEVEL_TERSE)
10705 break;
10707 /* In the special case of a TYPE_DECL node representing the
10708 declaration of some type tag, if the given TYPE_DECL is marked as
10709 having been instantiated from some other (original) TYPE_DECL node
10710 (e.g. one which was generated within the original definition of an
10711 inline function) we have to generate a special (abbreviated)
10712 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
10713 DIE here. */
10714 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
10716 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
10717 break;
10720 if (is_redundant_typedef (decl))
10721 gen_type_die (TREE_TYPE (decl), context_die);
10722 else
10723 /* Output a DIE to represent the typedef itself. */
10724 gen_typedef_die (decl, context_die);
10725 break;
10727 case LABEL_DECL:
10728 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10729 gen_label_die (decl, context_die);
10730 break;
10732 case VAR_DECL:
10733 /* If we are in terse mode, don't generate any DIEs to represent any
10734 variable declarations or definitions. */
10735 if (debug_info_level <= DINFO_LEVEL_TERSE)
10736 break;
10738 /* Output any DIEs that are needed to specify the type of this data
10739 object. */
10740 gen_type_die (TREE_TYPE (decl), context_die);
10742 /* And its containing type. */
10743 origin = decl_class_context (decl);
10744 if (origin != NULL_TREE)
10745 gen_type_die_for_member (origin, decl, context_die);
10747 /* Now output the DIE to represent the data object itself. This gets
10748 complicated because of the possibility that the VAR_DECL really
10749 represents an inlined instance of a formal parameter for an inline
10750 function. */
10751 origin = decl_ultimate_origin (decl);
10752 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
10753 gen_formal_parameter_die (decl, context_die);
10754 else
10755 gen_variable_die (decl, context_die);
10756 break;
10758 case FIELD_DECL:
10759 /* Ignore the nameless fields that are used to skip bits, but
10760 handle C++ anonymous unions. */
10761 if (DECL_NAME (decl) != NULL_TREE
10762 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
10764 gen_type_die (member_declared_type (decl), context_die);
10765 gen_field_die (decl, context_die);
10767 break;
10769 case PARM_DECL:
10770 gen_type_die (TREE_TYPE (decl), context_die);
10771 gen_formal_parameter_die (decl, context_die);
10772 break;
10774 case NAMESPACE_DECL:
10775 /* Ignore for now. */
10776 break;
10778 default:
10779 abort ();
10783 /* Add Ada "use" clause information for SGI Workshop debugger. */
10785 void
10786 dwarf2out_add_library_unit_info (filename, context_list)
10787 const char *filename;
10788 const char *context_list;
10790 unsigned int file_index;
10792 if (filename != NULL)
10794 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
10795 tree context_list_decl
10796 = build_decl (LABEL_DECL, get_identifier (context_list),
10797 void_type_node);
10799 TREE_PUBLIC (context_list_decl) = TRUE;
10800 add_name_attribute (unit_die, context_list);
10801 file_index = lookup_filename (filename);
10802 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
10803 add_pubname (context_list_decl, unit_die);
10807 /* Write the debugging output for DECL. */
10809 void
10810 dwarf2out_decl (decl)
10811 register tree decl;
10813 register dw_die_ref context_die = comp_unit_die;
10815 if (TREE_CODE (decl) == ERROR_MARK)
10816 return;
10818 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10819 if (DECL_IGNORED_P (decl))
10820 return;
10822 switch (TREE_CODE (decl))
10824 case FUNCTION_DECL:
10825 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
10826 builtin function. Explicit programmer-supplied declarations of
10827 these same functions should NOT be ignored however. */
10828 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
10829 return;
10831 /* What we would really like to do here is to filter out all mere
10832 file-scope declarations of file-scope functions which are never
10833 referenced later within this translation unit (and keep all of ones
10834 that *are* referenced later on) but we aren't clairvoyant, so we have
10835 no idea which functions will be referenced in the future (i.e. later
10836 on within the current translation unit). So here we just ignore all
10837 file-scope function declarations which are not also definitions. If
10838 and when the debugger needs to know something about these functions,
10839 it will have to hunt around and find the DWARF information associated
10840 with the definition of the function. Note that we can't just check
10841 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
10842 definitions and which ones represent mere declarations. We have to
10843 check `DECL_INITIAL' instead. That's because the C front-end
10844 supports some weird semantics for "extern inline" function
10845 definitions. These can get inlined within the current translation
10846 unit (an thus, we need to generate DWARF info for their abstract
10847 instances so that the DWARF info for the concrete inlined instances
10848 can have something to refer to) but the compiler never generates any
10849 out-of-lines instances of such things (despite the fact that they
10850 *are* definitions). The important point is that the C front-end
10851 marks these "extern inline" functions as DECL_EXTERNAL, but we need
10852 to generate DWARF for them anyway. Note that the C++ front-end also
10853 plays some similar games for inline function definitions appearing
10854 within include files which also contain
10855 `#pragma interface' pragmas. */
10856 if (DECL_INITIAL (decl) == NULL_TREE)
10857 return;
10859 /* If we're a nested function, initially use a parent of NULL; if we're
10860 a plain function, this will be fixed up in decls_for_scope. If
10861 we're a method, it will be ignored, since we already have a DIE. */
10862 if (decl_function_context (decl))
10863 context_die = NULL;
10865 break;
10867 case VAR_DECL:
10868 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
10869 declaration and if the declaration was never even referenced from
10870 within this entire compilation unit. We suppress these DIEs in
10871 order to save space in the .debug section (by eliminating entries
10872 which are probably useless). Note that we must not suppress
10873 block-local extern declarations (whether used or not) because that
10874 would screw-up the debugger's name lookup mechanism and cause it to
10875 miss things which really ought to be in scope at a given point. */
10876 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
10877 return;
10879 /* If we are in terse mode, don't generate any DIEs to represent any
10880 variable declarations or definitions. */
10881 if (debug_info_level <= DINFO_LEVEL_TERSE)
10882 return;
10883 break;
10885 case TYPE_DECL:
10886 /* Don't emit stubs for types unless they are needed by other DIEs. */
10887 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
10888 return;
10890 /* Don't bother trying to generate any DIEs to represent any of the
10891 normal built-in types for the language we are compiling. */
10892 if (DECL_SOURCE_LINE (decl) == 0)
10894 /* OK, we need to generate one for `bool' so GDB knows what type
10895 comparisons have. */
10896 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
10897 == DW_LANG_C_plus_plus)
10898 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
10899 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
10901 return;
10904 /* If we are in terse mode, don't generate any DIEs for types. */
10905 if (debug_info_level <= DINFO_LEVEL_TERSE)
10906 return;
10908 /* If we're a function-scope tag, initially use a parent of NULL;
10909 this will be fixed up in decls_for_scope. */
10910 if (decl_function_context (decl))
10911 context_die = NULL;
10913 break;
10915 default:
10916 return;
10919 gen_decl_die (decl, context_die);
10922 /* Output a marker (i.e. a label) for the beginning of the generated code for
10923 a lexical block. */
10925 void
10926 dwarf2out_begin_block (blocknum)
10927 register unsigned blocknum;
10929 function_section (current_function_decl);
10930 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
10933 /* Output a marker (i.e. a label) for the end of the generated code for a
10934 lexical block. */
10936 void
10937 dwarf2out_end_block (blocknum)
10938 register unsigned blocknum;
10940 function_section (current_function_decl);
10941 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
10944 /* Returns nonzero if it is appropriate not to emit any debugging
10945 information for BLOCK, because it doesn't contain any instructions.
10947 Don't allow this for blocks with nested functions or local classes
10948 as we would end up with orphans, and in the presence of scheduling
10949 we may end up calling them anyway. */
10952 dwarf2out_ignore_block (block)
10953 tree block;
10955 tree decl;
10956 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
10957 if (TREE_CODE (decl) == FUNCTION_DECL
10958 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
10959 return 0;
10960 return 1;
10963 /* Lookup a filename (in the list of filenames that we know about here in
10964 dwarf2out.c) and return its "index". The index of each (known) filename is
10965 just a unique number which is associated with only that one filename.
10966 We need such numbers for the sake of generating labels
10967 (in the .debug_sfnames section) and references to those
10968 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
10969 If the filename given as an argument is not found in our current list,
10970 add it to the list and assign it the next available unique index number.
10971 In order to speed up searches, we remember the index of the filename
10972 was looked up last. This handles the majority of all searches. */
10974 static unsigned
10975 lookup_filename (file_name)
10976 const char *file_name;
10978 static unsigned last_file_lookup_index = 0;
10979 register unsigned i;
10981 /* Check to see if the file name that was searched on the previous call
10982 matches this file name. If so, return the index. */
10983 if (last_file_lookup_index != 0)
10984 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
10985 return last_file_lookup_index;
10987 /* Didn't match the previous lookup, search the table */
10988 for (i = 1; i < file_table_in_use; ++i)
10989 if (strcmp (file_name, file_table[i]) == 0)
10991 last_file_lookup_index = i;
10992 return i;
10995 /* Prepare to add a new table entry by making sure there is enough space in
10996 the table to do so. If not, expand the current table. */
10997 if (file_table_in_use == file_table_allocated)
10999 file_table_allocated += FILE_TABLE_INCREMENT;
11000 file_table
11001 = (char **) xrealloc (file_table,
11002 file_table_allocated * sizeof (char *));
11005 /* Add the new entry to the end of the filename table. */
11006 file_table[file_table_in_use] = xstrdup (file_name);
11007 last_file_lookup_index = file_table_in_use++;
11009 return last_file_lookup_index;
11012 /* Output a label to mark the beginning of a source code line entry
11013 and record information relating to this source line, in
11014 'line_info_table' for later output of the .debug_line section. */
11016 void
11017 dwarf2out_line (filename, line)
11018 register const char *filename;
11019 register unsigned line;
11021 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11023 function_section (current_function_decl);
11025 if (DWARF2_ASM_LINE_DEBUG_INFO)
11027 static const char *lastfile;
11029 /* Emit the .file and .loc directives understood by GNU as. */
11030 if (lastfile == 0 || strcmp (filename, lastfile))
11032 if (lastfile == 0)
11033 ggc_add_string_root ((char **) &lastfile, 1);
11035 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
11036 lastfile = filename;
11039 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
11041 /* Indicate that line number info exists. */
11042 ++line_info_table_in_use;
11044 /* Indicate that multiple line number tables exist. */
11045 if (DECL_SECTION_NAME (current_function_decl))
11046 ++separate_line_info_table_in_use;
11048 else if (DECL_SECTION_NAME (current_function_decl))
11050 register dw_separate_line_info_ref line_info;
11051 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11052 separate_line_info_table_in_use);
11053 if (flag_debug_asm)
11054 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
11055 fputc ('\n', asm_out_file);
11057 /* expand the line info table if necessary */
11058 if (separate_line_info_table_in_use
11059 == separate_line_info_table_allocated)
11061 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11062 separate_line_info_table
11063 = (dw_separate_line_info_ref)
11064 xrealloc (separate_line_info_table,
11065 separate_line_info_table_allocated
11066 * sizeof (dw_separate_line_info_entry));
11069 /* Add the new entry at the end of the line_info_table. */
11070 line_info
11071 = &separate_line_info_table[separate_line_info_table_in_use++];
11072 line_info->dw_file_num = lookup_filename (filename);
11073 line_info->dw_line_num = line;
11074 line_info->function = current_funcdef_number;
11076 else
11078 register dw_line_info_ref line_info;
11080 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11081 line_info_table_in_use);
11082 if (flag_debug_asm)
11083 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
11084 fputc ('\n', asm_out_file);
11086 /* Expand the line info table if necessary. */
11087 if (line_info_table_in_use == line_info_table_allocated)
11089 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11090 line_info_table
11091 = (dw_line_info_ref)
11092 xrealloc (line_info_table,
11093 (line_info_table_allocated
11094 * sizeof (dw_line_info_entry)));
11097 /* Add the new entry at the end of the line_info_table. */
11098 line_info = &line_info_table[line_info_table_in_use++];
11099 line_info->dw_file_num = lookup_filename (filename);
11100 line_info->dw_line_num = line;
11105 /* Record the beginning of a new source file, for later output
11106 of the .debug_macinfo section. At present, unimplemented. */
11108 void
11109 dwarf2out_start_source_file (filename)
11110 register const char *filename ATTRIBUTE_UNUSED;
11112 if (flag_eliminate_dwarf2_dups)
11114 /* Record the beginning of the file for break_out_includes. */
11115 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11116 add_AT_string (bincl_die, DW_AT_name, filename);
11120 /* Record the end of a source file, for later output
11121 of the .debug_macinfo section. At present, unimplemented. */
11123 void
11124 dwarf2out_end_source_file ()
11126 if (flag_eliminate_dwarf2_dups)
11128 /* Record the end of the file for break_out_includes. */
11129 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11133 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11134 the tail part of the directive line, i.e. the part which is past the
11135 initial whitespace, #, whitespace, directive-name, whitespace part. */
11137 void
11138 dwarf2out_define (lineno, buffer)
11139 register unsigned lineno ATTRIBUTE_UNUSED;
11140 register const char *buffer ATTRIBUTE_UNUSED;
11142 static int initialized = 0;
11143 if (!initialized)
11145 dwarf2out_start_source_file (primary_filename);
11146 initialized = 1;
11150 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11151 the tail part of the directive line, i.e. the part which is past the
11152 initial whitespace, #, whitespace, directive-name, whitespace part. */
11154 void
11155 dwarf2out_undef (lineno, buffer)
11156 register unsigned lineno ATTRIBUTE_UNUSED;
11157 register const char *buffer ATTRIBUTE_UNUSED;
11161 /* Set up for Dwarf output at the start of compilation. */
11163 void
11164 dwarf2out_init (asm_out_file, main_input_filename)
11165 register FILE *asm_out_file;
11166 register const char *main_input_filename;
11168 /* Remember the name of the primary input file. */
11169 primary_filename = main_input_filename;
11171 /* Allocate the initial hunk of the file_table. */
11172 file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11173 file_table_allocated = FILE_TABLE_INCREMENT;
11175 /* Skip the first entry - file numbers begin at 1. */
11176 file_table_in_use = 1;
11178 /* Allocate the initial hunk of the decl_die_table. */
11179 decl_die_table
11180 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11181 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11182 decl_die_table_in_use = 0;
11184 /* Allocate the initial hunk of the decl_scope_table. */
11185 decl_scope_table
11186 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11187 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11188 decl_scope_depth = 0;
11190 /* Allocate the initial hunk of the abbrev_die_table. */
11191 abbrev_die_table
11192 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11193 sizeof (dw_die_ref));
11194 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11195 /* Zero-th entry is allocated, but unused */
11196 abbrev_die_table_in_use = 1;
11198 /* Allocate the initial hunk of the line_info_table. */
11199 line_info_table
11200 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11201 sizeof (dw_line_info_entry));
11202 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11203 /* Zero-th entry is allocated, but unused */
11204 line_info_table_in_use = 1;
11206 /* Generate the initial DIE for the .debug section. Note that the (string)
11207 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11208 will (typically) be a relative pathname and that this pathname should be
11209 taken as being relative to the directory from which the compiler was
11210 invoked when the given (base) source file was compiled. */
11211 comp_unit_die = gen_compile_unit_die (main_input_filename);
11213 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11214 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11216 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11217 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
11218 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11219 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11220 else
11221 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11222 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11223 DEBUG_INFO_SECTION_LABEL, 0);
11224 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11225 DEBUG_LINE_SECTION_LABEL, 0);
11227 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11228 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11229 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11231 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11232 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11234 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
11235 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11236 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11237 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11240 /* Output stuff that dwarf requires at the end of every file,
11241 and generate the DWARF-2 debugging info. */
11243 void
11244 dwarf2out_finish ()
11246 limbo_die_node *node, *next_node;
11247 dw_die_ref die;
11249 /* Traverse the limbo die list, and add parent/child links. The only
11250 dies without parents that should be here are concrete instances of
11251 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11252 For concrete instances, we can get the parent die from the abstract
11253 instance. */
11254 for (node = limbo_die_list; node; node = next_node)
11256 next_node = node->next;
11257 die = node->die;
11259 if (die->die_parent == NULL)
11261 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11262 if (origin)
11263 add_child_die (origin->die_parent, die);
11264 else if (die == comp_unit_die)
11266 else
11267 abort ();
11269 free (node);
11271 limbo_die_list = NULL;
11273 /* Walk through the list of incomplete types again, trying once more to
11274 emit full debugging info for them. */
11275 retry_incomplete_types ();
11277 /* We need to reverse all the dies before break_out_includes, or
11278 we'll see the end of an include file before the beginning. */
11279 reverse_all_dies (comp_unit_die);
11281 /* Generate separate CUs for each of the include files we've seen.
11282 They will go into limbo_die_list. */
11283 if (flag_eliminate_dwarf2_dups)
11284 break_out_includes (comp_unit_die);
11286 /* Traverse the DIE's and add add sibling attributes to those DIE's
11287 that have children. */
11288 add_sibling_attributes (comp_unit_die);
11289 for (node = limbo_die_list; node; node = node->next)
11290 add_sibling_attributes (node->die);
11292 /* Output a terminator label for the .text section. */
11293 fputc ('\n', asm_out_file);
11294 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11295 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11297 #if 0
11298 /* Output a terminator label for the .data section. */
11299 fputc ('\n', asm_out_file);
11300 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11301 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11303 /* Output a terminator label for the .bss section. */
11304 fputc ('\n', asm_out_file);
11305 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11306 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11307 #endif
11309 /* Output the source line correspondence table. */
11310 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
11312 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11314 fputc ('\n', asm_out_file);
11315 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11316 output_line_info ();
11319 /* We can only use the low/high_pc attributes if all of the code
11320 was in .text. */
11321 if (separate_line_info_table_in_use == 0)
11323 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11324 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11327 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11328 debug_line_section_label);
11331 #if 0 /* unimplemented */
11332 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
11333 add_AT_unsigned (die, DW_AT_macro_info, 0);
11334 #endif
11336 /* Output all of the compilation units. We put the main one last so that
11337 the offsets are available to output_pubnames. */
11338 for (node = limbo_die_list; node; node = node->next)
11339 output_comp_unit (node->die);
11340 output_comp_unit (comp_unit_die);
11342 /* Output the abbreviation table. */
11343 fputc ('\n', asm_out_file);
11344 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11345 output_abbrev_section ();
11347 if (pubname_table_in_use)
11349 /* Output public names table. */
11350 fputc ('\n', asm_out_file);
11351 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
11352 output_pubnames ();
11355 /* We only put functions in the arange table, so don't write it out if
11356 we don't have any. */
11357 if (fde_table_in_use)
11359 /* Output the address range information. */
11360 fputc ('\n', asm_out_file);
11361 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
11362 output_aranges ();
11365 #endif /* DWARF2_DEBUGGING_INFO */