* c-common.c (check_function_format): Don't suggest adding format
[official-gcc.git] / gcc / dwarf2out.c
blobcb4f6f7764001a3c7e06c7e5029b1f26e10c5b91
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_NSTRING
533 #define ASM_OUTPUT_DWARF_NSTRING(FILE,P,SLEN) \
534 do { \
535 register int slen = (SLEN); \
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
555 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
556 ASM_OUTPUT_DWARF_NSTRING (FILE, P, strlen (P))
558 /* The DWARF 2 CFA column which tracks the return address. Normally this
559 is the column for PC, or the first column after all of the hard
560 registers. */
561 #ifndef DWARF_FRAME_RETURN_COLUMN
562 #ifdef PC_REGNUM
563 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
564 #else
565 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
566 #endif
567 #endif
569 /* The mapping from gcc register number to DWARF 2 CFA column number. By
570 default, we just provide columns for all registers. */
571 #ifndef DWARF_FRAME_REGNUM
572 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
573 #endif
575 /* Hook used by __throw. */
578 expand_builtin_dwarf_fp_regnum ()
580 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
583 /* The offset from the incoming value of %sp to the top of the stack frame
584 for the current function. */
585 #ifndef INCOMING_FRAME_SP_OFFSET
586 #define INCOMING_FRAME_SP_OFFSET 0
587 #endif
589 /* Return a pointer to a copy of the section string name S with all
590 attributes stripped off, and an asterisk prepended (for assemble_name). */
592 static inline char *
593 stripattributes (s)
594 const char *s;
596 char *stripped = xmalloc (strlen (s) + 2);
597 char *p = stripped;
599 *p++ = '*';
601 while (*s && *s != ',')
602 *p++ = *s++;
604 *p = '\0';
605 return stripped;
608 /* Generate code to initialize the register size table. */
610 void
611 expand_builtin_init_dwarf_reg_sizes (address)
612 tree address;
614 int i;
615 enum machine_mode mode = TYPE_MODE (char_type_node);
616 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
617 rtx mem = gen_rtx_MEM (mode, addr);
619 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
621 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
622 int size = GET_MODE_SIZE (reg_raw_mode[i]);
624 if (offset < 0)
625 continue;
627 emit_move_insn (change_address (mem, mode,
628 plus_constant (addr, offset)),
629 GEN_INT (size));
633 /* Convert a DWARF call frame info. operation to its string name */
635 static const char *
636 dwarf_cfi_name (cfi_opc)
637 register unsigned cfi_opc;
639 switch (cfi_opc)
641 case DW_CFA_advance_loc:
642 return "DW_CFA_advance_loc";
643 case DW_CFA_offset:
644 return "DW_CFA_offset";
645 case DW_CFA_restore:
646 return "DW_CFA_restore";
647 case DW_CFA_nop:
648 return "DW_CFA_nop";
649 case DW_CFA_set_loc:
650 return "DW_CFA_set_loc";
651 case DW_CFA_advance_loc1:
652 return "DW_CFA_advance_loc1";
653 case DW_CFA_advance_loc2:
654 return "DW_CFA_advance_loc2";
655 case DW_CFA_advance_loc4:
656 return "DW_CFA_advance_loc4";
657 case DW_CFA_offset_extended:
658 return "DW_CFA_offset_extended";
659 case DW_CFA_restore_extended:
660 return "DW_CFA_restore_extended";
661 case DW_CFA_undefined:
662 return "DW_CFA_undefined";
663 case DW_CFA_same_value:
664 return "DW_CFA_same_value";
665 case DW_CFA_register:
666 return "DW_CFA_register";
667 case DW_CFA_remember_state:
668 return "DW_CFA_remember_state";
669 case DW_CFA_restore_state:
670 return "DW_CFA_restore_state";
671 case DW_CFA_def_cfa:
672 return "DW_CFA_def_cfa";
673 case DW_CFA_def_cfa_register:
674 return "DW_CFA_def_cfa_register";
675 case DW_CFA_def_cfa_offset:
676 return "DW_CFA_def_cfa_offset";
677 case DW_CFA_def_cfa_expression:
678 return "DW_CFA_def_cfa_expression";
680 /* SGI/MIPS specific */
681 case DW_CFA_MIPS_advance_loc8:
682 return "DW_CFA_MIPS_advance_loc8";
684 /* GNU extensions */
685 case DW_CFA_GNU_window_save:
686 return "DW_CFA_GNU_window_save";
687 case DW_CFA_GNU_args_size:
688 return "DW_CFA_GNU_args_size";
689 case DW_CFA_GNU_negative_offset_extended:
690 return "DW_CFA_GNU_negative_offset_extended";
692 default:
693 return "DW_CFA_<unknown>";
697 /* Return a pointer to a newly allocated Call Frame Instruction. */
699 static inline dw_cfi_ref
700 new_cfi ()
702 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
704 cfi->dw_cfi_next = NULL;
705 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
706 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
708 return cfi;
711 /* Add a Call Frame Instruction to list of instructions. */
713 static inline void
714 add_cfi (list_head, cfi)
715 register dw_cfi_ref *list_head;
716 register dw_cfi_ref cfi;
718 register dw_cfi_ref *p;
720 /* Find the end of the chain. */
721 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
724 *p = cfi;
727 /* Generate a new label for the CFI info to refer to. */
729 char *
730 dwarf2out_cfi_label ()
732 static char label[20];
733 static unsigned long label_num = 0;
735 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
736 ASM_OUTPUT_LABEL (asm_out_file, label);
738 return label;
741 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
742 or to the CIE if LABEL is NULL. */
744 static void
745 add_fde_cfi (label, cfi)
746 register const char *label;
747 register dw_cfi_ref cfi;
749 if (label)
751 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
753 if (*label == 0)
754 label = dwarf2out_cfi_label ();
756 if (fde->dw_fde_current_label == NULL
757 || strcmp (label, fde->dw_fde_current_label) != 0)
759 register dw_cfi_ref xcfi;
761 fde->dw_fde_current_label = label = xstrdup (label);
763 /* Set the location counter to the new label. */
764 xcfi = new_cfi ();
765 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
766 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
767 add_cfi (&fde->dw_fde_cfi, xcfi);
770 add_cfi (&fde->dw_fde_cfi, cfi);
773 else
774 add_cfi (&cie_cfi_head, cfi);
777 /* Subroutine of lookup_cfa. */
779 static inline void
780 lookup_cfa_1 (cfi, loc)
781 register dw_cfi_ref cfi;
782 register dw_cfa_location *loc;
784 switch (cfi->dw_cfi_opc)
786 case DW_CFA_def_cfa_offset:
787 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
788 break;
789 case DW_CFA_def_cfa_register:
790 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
791 break;
792 case DW_CFA_def_cfa:
793 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
794 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
795 break;
796 case DW_CFA_def_cfa_expression:
797 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
798 break;
799 default:
800 break;
804 /* Find the previous value for the CFA. */
806 static void
807 lookup_cfa (loc)
808 register dw_cfa_location *loc;
810 register dw_cfi_ref cfi;
812 loc->reg = (unsigned long) -1;
813 loc->offset = 0;
814 loc->indirect = 0;
815 loc->base_offset = 0;
817 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
818 lookup_cfa_1 (cfi, loc);
820 if (fde_table_in_use)
822 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
823 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
824 lookup_cfa_1 (cfi, loc);
828 /* The current rule for calculating the DWARF2 canonical frame address. */
829 dw_cfa_location cfa;
831 /* The register used for saving registers to the stack, and its offset
832 from the CFA. */
833 dw_cfa_location cfa_store;
835 /* The running total of the size of arguments pushed onto the stack. */
836 static long args_size;
838 /* The last args_size we actually output. */
839 static long old_args_size;
841 /* Entry point to update the canonical frame address (CFA).
842 LABEL is passed to add_fde_cfi. The value of CFA is now to be
843 calculated from REG+OFFSET. */
845 void
846 dwarf2out_def_cfa (label, reg, offset)
847 register const char *label;
848 unsigned reg;
849 long offset;
851 dw_cfa_location loc;
852 loc.indirect = 0;
853 loc.base_offset = 0;
854 loc.reg = reg;
855 loc.offset = offset;
856 def_cfa_1 (label, &loc);
859 /* This routine does the actual work. The CFA is now calculated from
860 the dw_cfa_location structure. */
861 static void
862 def_cfa_1 (label, loc_p)
863 register const char *label;
864 dw_cfa_location *loc_p;
866 register dw_cfi_ref cfi;
867 dw_cfa_location old_cfa, loc;
869 cfa = *loc_p;
870 loc = *loc_p;
872 if (cfa_store.reg == loc.reg && loc.indirect == 0)
873 cfa_store.offset = loc.offset;
875 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
876 lookup_cfa (&old_cfa);
878 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
879 loc.indirect == old_cfa.indirect)
881 if (loc.indirect == 0
882 || loc.base_offset == old_cfa.base_offset)
883 return;
886 cfi = new_cfi ();
888 if (loc.reg == old_cfa.reg && !loc.indirect)
890 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
891 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
894 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
895 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
896 && !loc.indirect)
898 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
899 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
901 #endif
903 else if (loc.indirect == 0)
905 cfi->dw_cfi_opc = DW_CFA_def_cfa;
906 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
907 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
909 else
911 struct dw_loc_descr_struct *loc_list;
912 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
913 loc_list = build_cfa_loc (&loc);
914 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
917 add_fde_cfi (label, cfi);
920 /* Add the CFI for saving a register. REG is the CFA column number.
921 LABEL is passed to add_fde_cfi.
922 If SREG is -1, the register is saved at OFFSET from the CFA;
923 otherwise it is saved in SREG. */
925 static void
926 reg_save (label, reg, sreg, offset)
927 register const char *label;
928 register unsigned reg;
929 register unsigned sreg;
930 register long offset;
932 register dw_cfi_ref cfi = new_cfi ();
934 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
936 /* The following comparison is correct. -1 is used to indicate that
937 the value isn't a register number. */
938 if (sreg == (unsigned int) -1)
940 if (reg & ~0x3f)
941 /* The register number won't fit in 6 bits, so we have to use
942 the long form. */
943 cfi->dw_cfi_opc = DW_CFA_offset_extended;
944 else
945 cfi->dw_cfi_opc = DW_CFA_offset;
947 #ifdef ENABLE_CHECKING
949 /* If we get an offset that is not a multiple of
950 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
951 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
952 description. */
953 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
955 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
956 abort ();
958 #endif
959 offset /= DWARF_CIE_DATA_ALIGNMENT;
960 if (offset < 0)
962 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
963 offset = -offset;
965 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
967 else if (sreg == reg)
968 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
969 return;
970 else
972 cfi->dw_cfi_opc = DW_CFA_register;
973 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
976 add_fde_cfi (label, cfi);
979 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
980 This CFI tells the unwinder that it needs to restore the window registers
981 from the previous frame's window save area.
983 ??? Perhaps we should note in the CIE where windows are saved (instead of
984 assuming 0(cfa)) and what registers are in the window. */
986 void
987 dwarf2out_window_save (label)
988 register const char *label;
990 register dw_cfi_ref cfi = new_cfi ();
991 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
992 add_fde_cfi (label, cfi);
995 /* Add a CFI to update the running total of the size of arguments
996 pushed onto the stack. */
998 void
999 dwarf2out_args_size (label, size)
1000 const char *label;
1001 long size;
1003 register dw_cfi_ref cfi;
1005 if (size == old_args_size)
1006 return;
1007 old_args_size = size;
1009 cfi = new_cfi ();
1010 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1011 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1012 add_fde_cfi (label, cfi);
1015 /* Entry point for saving a register to the stack. REG is the GCC register
1016 number. LABEL and OFFSET are passed to reg_save. */
1018 void
1019 dwarf2out_reg_save (label, reg, offset)
1020 register const char *label;
1021 register unsigned reg;
1022 register long offset;
1024 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
1027 /* Entry point for saving the return address in the stack.
1028 LABEL and OFFSET are passed to reg_save. */
1030 void
1031 dwarf2out_return_save (label, offset)
1032 register const char *label;
1033 register long offset;
1035 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
1038 /* Entry point for saving the return address in a register.
1039 LABEL and SREG are passed to reg_save. */
1041 void
1042 dwarf2out_return_reg (label, sreg)
1043 register const char *label;
1044 register unsigned sreg;
1046 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
1049 /* Record the initial position of the return address. RTL is
1050 INCOMING_RETURN_ADDR_RTX. */
1052 static void
1053 initial_return_save (rtl)
1054 register rtx rtl;
1056 unsigned int reg = (unsigned int) -1;
1057 long offset = 0;
1059 switch (GET_CODE (rtl))
1061 case REG:
1062 /* RA is in a register. */
1063 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1064 break;
1065 case MEM:
1066 /* RA is on the stack. */
1067 rtl = XEXP (rtl, 0);
1068 switch (GET_CODE (rtl))
1070 case REG:
1071 if (REGNO (rtl) != STACK_POINTER_REGNUM)
1072 abort ();
1073 offset = 0;
1074 break;
1075 case PLUS:
1076 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1077 abort ();
1078 offset = INTVAL (XEXP (rtl, 1));
1079 break;
1080 case MINUS:
1081 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1082 abort ();
1083 offset = -INTVAL (XEXP (rtl, 1));
1084 break;
1085 default:
1086 abort ();
1088 break;
1089 case PLUS:
1090 /* The return address is at some offset from any value we can
1091 actually load. For instance, on the SPARC it is in %i7+8. Just
1092 ignore the offset for now; it doesn't matter for unwinding frames. */
1093 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
1094 abort ();
1095 initial_return_save (XEXP (rtl, 0));
1096 return;
1097 default:
1098 abort ();
1101 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1104 /* Given a SET, calculate the amount of stack adjustment it
1105 contains. */
1107 static long
1108 stack_adjust_offset (pattern)
1109 rtx pattern;
1111 rtx src = SET_SRC (pattern);
1112 rtx dest = SET_DEST (pattern);
1113 long offset = 0;
1114 enum rtx_code code;
1116 if (dest == stack_pointer_rtx)
1118 /* (set (reg sp) (plus (reg sp) (const_int))) */
1119 code = GET_CODE (src);
1120 if (! (code == PLUS || code == MINUS)
1121 || XEXP (src, 0) != stack_pointer_rtx
1122 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1123 return 0;
1125 offset = INTVAL (XEXP (src, 1));
1127 else if (GET_CODE (dest) == MEM)
1129 /* (set (mem (pre_dec (reg sp))) (foo)) */
1130 src = XEXP (dest, 0);
1131 code = GET_CODE (src);
1133 if (! (code == PRE_DEC || code == PRE_INC)
1134 || XEXP (src, 0) != stack_pointer_rtx)
1135 return 0;
1137 offset = GET_MODE_SIZE (GET_MODE (dest));
1139 else
1140 return 0;
1142 if (code == PLUS || code == PRE_INC)
1143 offset = -offset;
1145 return offset;
1148 /* Check INSN to see if it looks like a push or a stack adjustment, and
1149 make a note of it if it does. EH uses this information to find out how
1150 much extra space it needs to pop off the stack. */
1152 static void
1153 dwarf2out_stack_adjust (insn)
1154 rtx insn;
1156 long offset;
1157 const char *label;
1159 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1161 /* Extract the size of the args from the CALL rtx itself. */
1163 insn = PATTERN (insn);
1164 if (GET_CODE (insn) == PARALLEL)
1165 insn = XVECEXP (insn, 0, 0);
1166 if (GET_CODE (insn) == SET)
1167 insn = SET_SRC (insn);
1168 if (GET_CODE (insn) != CALL)
1169 abort ();
1170 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1171 return;
1174 /* If only calls can throw, and we have a frame pointer,
1175 save up adjustments until we see the CALL_INSN. */
1176 else if (! asynchronous_exceptions
1177 && cfa.reg != STACK_POINTER_REGNUM)
1178 return;
1180 if (GET_CODE (insn) == BARRIER)
1182 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1183 the compiler will have already emitted a stack adjustment, but
1184 doesn't bother for calls to noreturn functions. */
1185 #ifdef STACK_GROWS_DOWNWARD
1186 offset = -args_size;
1187 #else
1188 offset = args_size;
1189 #endif
1191 else if (GET_CODE (PATTERN (insn)) == SET)
1193 offset = stack_adjust_offset (PATTERN (insn));
1195 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1196 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1198 /* There may be stack adjustments inside compound insns. Search
1199 for them. */
1200 int j;
1202 offset = 0;
1203 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1205 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1206 if (GET_CODE (pattern) == SET)
1207 offset += stack_adjust_offset (pattern);
1210 else
1211 return;
1213 if (offset == 0)
1214 return;
1216 if (cfa.reg == STACK_POINTER_REGNUM)
1217 cfa.offset += offset;
1219 #ifndef STACK_GROWS_DOWNWARD
1220 offset = -offset;
1221 #endif
1222 args_size += offset;
1223 if (args_size < 0)
1224 args_size = 0;
1226 label = dwarf2out_cfi_label ();
1227 def_cfa_1 (label, &cfa);
1228 dwarf2out_args_size (label, args_size);
1231 /* A temporary register used in adjusting SP or setting up the store_reg. */
1232 static unsigned cfa_temp_reg;
1234 /* A temporary value used in adjusting SP or setting up the store_reg. */
1235 static long cfa_temp_value;
1237 /* Record call frame debugging information for an expression, which either
1238 sets SP or FP (adjusting how we calculate the frame address) or saves a
1239 register to the stack. */
1241 static void
1242 dwarf2out_frame_debug_expr (expr, label)
1243 rtx expr;
1244 const char *label;
1246 rtx src, dest;
1247 long offset;
1249 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1250 the PARALLEL independently. The first element is always processed if
1251 it is a SET. This is for backward compatability. Other elements
1252 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1253 flag is set in them. */
1255 if (GET_CODE (expr) == PARALLEL
1256 || GET_CODE (expr) == SEQUENCE)
1258 int par_index;
1259 int limit = XVECLEN (expr, 0);
1261 for (par_index = 0; par_index < limit; par_index++)
1263 rtx x = XVECEXP (expr, 0, par_index);
1265 if (GET_CODE (x) == SET &&
1266 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1267 dwarf2out_frame_debug_expr (x, label);
1269 return;
1272 if (GET_CODE (expr) != SET)
1273 abort ();
1275 src = SET_SRC (expr);
1276 dest = SET_DEST (expr);
1278 switch (GET_CODE (dest))
1280 case REG:
1281 /* Update the CFA rule wrt SP or FP. Make sure src is
1282 relative to the current CFA register. */
1283 switch (GET_CODE (src))
1285 /* Setting FP from SP. */
1286 case REG:
1287 if (cfa.reg == (unsigned) REGNO (src))
1288 /* OK. */
1290 else
1291 abort ();
1293 /* We used to require that dest be either SP or FP, but the
1294 ARM copies SP to a temporary register, and from there to
1295 FP. So we just rely on the backends to only set
1296 RTX_FRAME_RELATED_P on appropriate insns. */
1297 cfa.reg = REGNO (dest);
1298 break;
1300 case PLUS:
1301 case MINUS:
1302 if (dest == stack_pointer_rtx)
1304 /* Adjusting SP. */
1305 switch (GET_CODE (XEXP (src, 1)))
1307 case CONST_INT:
1308 offset = INTVAL (XEXP (src, 1));
1309 break;
1310 case REG:
1311 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp_reg)
1312 abort ();
1313 offset = cfa_temp_value;
1314 break;
1315 default:
1316 abort ();
1319 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1321 /* Restoring SP from FP in the epilogue. */
1322 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1323 abort ();
1324 cfa.reg = STACK_POINTER_REGNUM;
1326 else if (XEXP (src, 0) != stack_pointer_rtx)
1327 abort ();
1329 if (GET_CODE (src) == PLUS)
1330 offset = -offset;
1331 if (cfa.reg == STACK_POINTER_REGNUM)
1332 cfa.offset += offset;
1333 if (cfa_store.reg == STACK_POINTER_REGNUM)
1334 cfa_store.offset += offset;
1336 else if (dest == hard_frame_pointer_rtx)
1338 /* Either setting the FP from an offset of the SP,
1339 or adjusting the FP */
1340 if (! frame_pointer_needed)
1341 abort ();
1343 if (GET_CODE (XEXP (src, 0)) == REG
1344 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1345 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1347 offset = INTVAL (XEXP (src, 1));
1348 if (GET_CODE (src) == PLUS)
1349 offset = -offset;
1350 cfa.offset += offset;
1351 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1353 else
1354 abort ();
1356 else
1358 if (GET_CODE (src) != PLUS
1359 || XEXP (src, 1) != stack_pointer_rtx)
1360 abort ();
1361 if (GET_CODE (XEXP (src, 0)) != REG
1362 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg)
1363 abort ();
1364 if (cfa.reg != STACK_POINTER_REGNUM)
1365 abort ();
1366 cfa_store.reg = REGNO (dest);
1367 cfa_store.offset = cfa.offset - cfa_temp_value;
1369 break;
1371 case CONST_INT:
1372 cfa_temp_reg = REGNO (dest);
1373 cfa_temp_value = INTVAL (src);
1374 break;
1376 case IOR:
1377 if (GET_CODE (XEXP (src, 0)) != REG
1378 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg
1379 || (unsigned) REGNO (dest) != cfa_temp_reg
1380 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1381 abort ();
1382 cfa_temp_value |= INTVAL (XEXP (src, 1));
1383 break;
1385 default:
1386 abort ();
1388 def_cfa_1 (label, &cfa);
1389 break;
1391 /* Skip over HIGH, assuming it will be followed by a LO_SUM, which
1392 will fill in all of the bits. */
1393 case HIGH:
1394 break;
1396 case LO_SUM:
1397 cfa_temp_reg = REGNO (dest);
1398 cfa_temp_value = INTVAL (XEXP (src, 1));
1399 break;
1401 case MEM:
1402 if (GET_CODE (src) != REG)
1403 abort ();
1405 /* Saving a register to the stack. Make sure dest is relative to the
1406 CFA register. */
1407 switch (GET_CODE (XEXP (dest, 0)))
1409 /* With a push. */
1410 case PRE_INC:
1411 case PRE_DEC:
1412 offset = GET_MODE_SIZE (GET_MODE (dest));
1413 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1414 offset = -offset;
1416 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1417 || cfa_store.reg != STACK_POINTER_REGNUM)
1418 abort ();
1419 cfa_store.offset += offset;
1420 if (cfa.reg == STACK_POINTER_REGNUM)
1421 cfa.offset = cfa_store.offset;
1423 offset = -cfa_store.offset;
1424 break;
1426 /* With an offset. */
1427 case PLUS:
1428 case MINUS:
1429 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1430 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1431 offset = -offset;
1433 if (cfa_store.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1434 abort ();
1435 offset -= cfa_store.offset;
1436 break;
1438 /* Without an offset. */
1439 case REG:
1440 if (cfa_store.reg != (unsigned) REGNO (XEXP (dest, 0)))
1441 abort ();
1442 offset = -cfa_store.offset;
1443 break;
1445 default:
1446 abort ();
1449 if (REGNO (src) != STACK_POINTER_REGNUM
1450 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1451 && (unsigned) REGNO (src) == cfa.reg)
1453 /* We're storing the current CFA reg into the stack. */
1455 if (cfa.offset == 0)
1457 /* If the source register is exactly the CFA, assume
1458 we're saving SP like any other register; this happens
1459 on the ARM. */
1461 def_cfa_1 (label, &cfa);
1462 dwarf2out_reg_save (label, STACK_POINTER_REGNUM, offset);
1463 break;
1465 else
1467 /* Otherwise, we'll need to look in the stack to
1468 calculate the CFA. */
1470 rtx x = XEXP (dest, 0);
1471 if (GET_CODE (x) != REG)
1472 x = XEXP (x, 0);
1473 if (GET_CODE (x) != REG)
1474 abort ();
1475 cfa.reg = (unsigned) REGNO (x);
1476 cfa.base_offset = offset;
1477 cfa.indirect = 1;
1478 def_cfa_1 (label, &cfa);
1479 break;
1483 def_cfa_1 (label, &cfa);
1484 dwarf2out_reg_save (label, REGNO (src), offset);
1485 break;
1487 default:
1488 abort ();
1492 /* Record call frame debugging information for INSN, which either
1493 sets SP or FP (adjusting how we calculate the frame address) or saves a
1494 register to the stack. If INSN is NULL_RTX, initialize our state. */
1496 void
1497 dwarf2out_frame_debug (insn)
1498 rtx insn;
1500 const char *label;
1501 rtx src;
1503 if (insn == NULL_RTX)
1505 /* Set up state for generating call frame debug info. */
1506 lookup_cfa (&cfa);
1507 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1508 abort ();
1509 cfa.reg = STACK_POINTER_REGNUM;
1510 cfa_store = cfa;
1511 cfa_temp_reg = -1;
1512 cfa_temp_value = 0;
1513 return;
1516 if (! RTX_FRAME_RELATED_P (insn))
1518 dwarf2out_stack_adjust (insn);
1519 return;
1522 label = dwarf2out_cfi_label ();
1524 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1525 if (src)
1526 insn = XEXP (src, 0);
1527 else
1528 insn = PATTERN (insn);
1530 dwarf2out_frame_debug_expr (insn, label);
1533 /* Return the size of an unsigned LEB128 quantity. */
1535 static inline unsigned long
1536 size_of_uleb128 (value)
1537 register unsigned long value;
1539 register unsigned long size = 0;
1540 register unsigned byte;
1544 byte = (value & 0x7f);
1545 value >>= 7;
1546 size += 1;
1548 while (value != 0);
1550 return size;
1553 /* Return the size of a signed LEB128 quantity. */
1555 static inline unsigned long
1556 size_of_sleb128 (value)
1557 register long value;
1559 register unsigned long size = 0;
1560 register unsigned byte;
1564 byte = (value & 0x7f);
1565 value >>= 7;
1566 size += 1;
1568 while (!(((value == 0) && ((byte & 0x40) == 0))
1569 || ((value == -1) && ((byte & 0x40) != 0))));
1571 return size;
1574 /* Output an unsigned LEB128 quantity. */
1576 static void
1577 output_uleb128 (value)
1578 register unsigned long value;
1580 unsigned long save_value = value;
1582 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1585 register unsigned byte = (value & 0x7f);
1586 value >>= 7;
1587 if (value != 0)
1588 /* More bytes to follow. */
1589 byte |= 0x80;
1591 fprintf (asm_out_file, "0x%x", byte);
1592 if (value != 0)
1593 fprintf (asm_out_file, ",");
1595 while (value != 0);
1597 if (flag_debug_asm)
1598 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1601 /* Output an signed LEB128 quantity. */
1603 static void
1604 output_sleb128 (value)
1605 register long value;
1607 register int more;
1608 register unsigned byte;
1609 long save_value = value;
1611 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1614 byte = (value & 0x7f);
1615 /* arithmetic shift */
1616 value >>= 7;
1617 more = !((((value == 0) && ((byte & 0x40) == 0))
1618 || ((value == -1) && ((byte & 0x40) != 0))));
1619 if (more)
1620 byte |= 0x80;
1622 fprintf (asm_out_file, "0x%x", byte);
1623 if (more)
1624 fprintf (asm_out_file, ",");
1627 while (more);
1628 if (flag_debug_asm)
1629 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1632 /* Output a Call Frame Information opcode and its operand(s). */
1634 static void
1635 output_cfi (cfi, fde)
1636 register dw_cfi_ref cfi;
1637 register dw_fde_ref fde;
1639 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1641 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1642 cfi->dw_cfi_opc
1643 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1644 if (flag_debug_asm)
1645 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1646 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1647 fputc ('\n', asm_out_file);
1650 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1652 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1653 cfi->dw_cfi_opc
1654 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1655 if (flag_debug_asm)
1656 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1657 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1659 fputc ('\n', asm_out_file);
1660 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1661 fputc ('\n', asm_out_file);
1663 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1665 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1666 cfi->dw_cfi_opc
1667 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1668 if (flag_debug_asm)
1669 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1670 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1672 fputc ('\n', asm_out_file);
1674 else
1676 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1677 if (flag_debug_asm)
1678 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1679 dwarf_cfi_name (cfi->dw_cfi_opc));
1681 fputc ('\n', asm_out_file);
1682 switch (cfi->dw_cfi_opc)
1684 case DW_CFA_set_loc:
1685 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1686 fputc ('\n', asm_out_file);
1687 break;
1688 case DW_CFA_advance_loc1:
1689 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1690 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1691 fde->dw_fde_current_label);
1692 fputc ('\n', asm_out_file);
1693 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1694 break;
1695 case DW_CFA_advance_loc2:
1696 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1697 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1698 fde->dw_fde_current_label);
1699 fputc ('\n', asm_out_file);
1700 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1701 break;
1702 case DW_CFA_advance_loc4:
1703 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1704 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1705 fde->dw_fde_current_label);
1706 fputc ('\n', asm_out_file);
1707 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1708 break;
1709 #ifdef MIPS_DEBUGGING_INFO
1710 case DW_CFA_MIPS_advance_loc8:
1711 /* TODO: not currently implemented. */
1712 abort ();
1713 break;
1714 #endif
1715 case DW_CFA_offset_extended:
1716 case DW_CFA_GNU_negative_offset_extended:
1717 case DW_CFA_def_cfa:
1718 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1719 fputc ('\n', asm_out_file);
1720 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1721 fputc ('\n', asm_out_file);
1722 break;
1723 case DW_CFA_restore_extended:
1724 case DW_CFA_undefined:
1725 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1726 fputc ('\n', asm_out_file);
1727 break;
1728 case DW_CFA_same_value:
1729 case DW_CFA_def_cfa_register:
1730 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1731 fputc ('\n', asm_out_file);
1732 break;
1733 case DW_CFA_register:
1734 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1735 fputc ('\n', asm_out_file);
1736 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1737 fputc ('\n', asm_out_file);
1738 break;
1739 case DW_CFA_def_cfa_offset:
1740 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1741 fputc ('\n', asm_out_file);
1742 break;
1743 case DW_CFA_GNU_window_save:
1744 break;
1745 case DW_CFA_GNU_args_size:
1746 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1747 fputc ('\n', asm_out_file);
1748 break;
1749 case DW_CFA_def_cfa_expression:
1750 output_cfa_loc (cfi);
1751 break;
1752 default:
1753 break;
1758 /* Output the call frame information used to used to record information
1759 that relates to calculating the frame pointer, and records the
1760 location of saved registers. */
1762 static void
1763 output_call_frame_info (for_eh)
1764 int for_eh;
1766 register unsigned long i;
1767 register dw_fde_ref fde;
1768 register dw_cfi_ref cfi;
1769 char l1[20], l2[20];
1770 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1771 char ld[20];
1772 #endif
1774 /* Do we want to include a pointer to the exception table? */
1775 int eh_ptr = for_eh && exception_table_p ();
1777 /* If we don't have any functions we'll want to unwind out of, don't
1778 emit any EH unwind information. */
1779 if (for_eh)
1781 for (i = 0; i < fde_table_in_use; ++i)
1782 if (! fde_table[i].nothrow)
1783 goto found;
1784 return;
1785 found:;
1788 fputc ('\n', asm_out_file);
1790 /* We're going to be generating comments, so turn on app. */
1791 if (flag_debug_asm)
1792 app_enable ();
1794 if (for_eh)
1796 #ifdef EH_FRAME_SECTION
1797 EH_FRAME_SECTION ();
1798 #else
1799 tree label = get_file_function_name ('F');
1801 force_data_section ();
1802 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1803 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1804 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1805 #endif
1806 assemble_label ("__FRAME_BEGIN__");
1808 else
1809 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1811 /* Output the CIE. */
1812 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1813 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1814 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1815 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1816 if (for_eh)
1817 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1818 else
1819 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1820 #else
1821 if (for_eh)
1822 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1823 else
1824 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1825 #endif
1826 if (flag_debug_asm)
1827 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1828 ASM_COMMENT_START);
1830 fputc ('\n', asm_out_file);
1831 ASM_OUTPUT_LABEL (asm_out_file, l1);
1833 if (for_eh)
1834 /* Now that the CIE pointer is PC-relative for EH,
1835 use 0 to identify the CIE. */
1836 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1837 else
1838 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1840 if (flag_debug_asm)
1841 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1843 fputc ('\n', asm_out_file);
1844 if (! for_eh && DWARF_OFFSET_SIZE == 8)
1846 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1847 fputc ('\n', asm_out_file);
1850 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1851 if (flag_debug_asm)
1852 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1854 fputc ('\n', asm_out_file);
1855 if (eh_ptr)
1857 /* The CIE contains a pointer to the exception region info for the
1858 frame. Make the augmentation string three bytes (including the
1859 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1860 can't handle unaligned relocs. */
1861 if (flag_debug_asm)
1863 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1864 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1866 else
1868 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1870 fputc ('\n', asm_out_file);
1872 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1873 if (flag_debug_asm)
1874 fprintf (asm_out_file, "\t%s pointer to exception region info",
1875 ASM_COMMENT_START);
1877 else
1879 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1880 if (flag_debug_asm)
1881 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1882 ASM_COMMENT_START);
1885 fputc ('\n', asm_out_file);
1886 output_uleb128 (1);
1887 if (flag_debug_asm)
1888 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1890 fputc ('\n', asm_out_file);
1891 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1892 if (flag_debug_asm)
1893 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1895 fputc ('\n', asm_out_file);
1896 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1897 if (flag_debug_asm)
1898 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1900 fputc ('\n', asm_out_file);
1902 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1903 output_cfi (cfi, NULL);
1905 /* Pad the CIE out to an address sized boundary. */
1906 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1907 ASM_OUTPUT_LABEL (asm_out_file, l2);
1908 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1909 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1910 if (flag_debug_asm)
1911 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1912 fputc ('\n', asm_out_file);
1913 #endif
1915 /* Loop through all of the FDE's. */
1916 for (i = 0; i < fde_table_in_use; ++i)
1918 fde = &fde_table[i];
1920 /* Don't emit EH unwind info for leaf functions. */
1921 if (for_eh && fde->nothrow)
1922 continue;
1924 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1925 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1926 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1927 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i * 2);
1928 if (for_eh)
1929 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1930 else
1931 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1932 #else
1933 if (for_eh)
1934 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1935 else
1936 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1937 #endif
1938 if (flag_debug_asm)
1939 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1940 fputc ('\n', asm_out_file);
1941 ASM_OUTPUT_LABEL (asm_out_file, l1);
1943 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1944 emits a target dependent sized offset when for_eh is not true.
1945 This inconsistency may confuse gdb. The only case where we need a
1946 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1947 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1948 though in order to be compatible with the dwarf_fde struct in frame.c.
1949 If the for_eh case is changed, then the struct in frame.c has
1950 to be adjusted appropriately. */
1951 if (for_eh)
1952 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
1953 else
1954 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1955 if (flag_debug_asm)
1956 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1958 fputc ('\n', asm_out_file);
1959 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1960 if (flag_debug_asm)
1961 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1963 fputc ('\n', asm_out_file);
1964 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1965 fde->dw_fde_end, fde->dw_fde_begin);
1966 if (flag_debug_asm)
1967 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1969 fputc ('\n', asm_out_file);
1971 /* Loop through the Call Frame Instructions associated with
1972 this FDE. */
1973 fde->dw_fde_current_label = fde->dw_fde_begin;
1974 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1975 output_cfi (cfi, fde);
1977 /* Pad the FDE out to an address sized boundary. */
1978 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1979 ASM_OUTPUT_LABEL (asm_out_file, l2);
1980 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1981 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1982 if (flag_debug_asm)
1983 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
1984 fputc ('\n', asm_out_file);
1985 #endif
1987 #ifndef EH_FRAME_SECTION
1988 if (for_eh)
1990 /* Emit terminating zero for table. */
1991 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1992 fputc ('\n', asm_out_file);
1994 #endif
1995 #ifdef MIPS_DEBUGGING_INFO
1996 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1997 get a value of 0. Putting .align 0 after the label fixes it. */
1998 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1999 #endif
2001 /* Turn off app to make assembly quicker. */
2002 if (flag_debug_asm)
2003 app_disable ();
2006 /* Output a marker (i.e. a label) for the beginning of a function, before
2007 the prologue. */
2009 void
2010 dwarf2out_begin_prologue ()
2012 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2013 register dw_fde_ref fde;
2015 ++current_funcdef_number;
2017 function_section (current_function_decl);
2018 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2019 current_funcdef_number);
2020 ASM_OUTPUT_LABEL (asm_out_file, label);
2021 current_function_func_begin_label = get_identifier (label);
2023 /* Expand the fde table if necessary. */
2024 if (fde_table_in_use == fde_table_allocated)
2026 fde_table_allocated += FDE_TABLE_INCREMENT;
2027 fde_table
2028 = (dw_fde_ref) xrealloc (fde_table,
2029 fde_table_allocated * sizeof (dw_fde_node));
2032 /* Record the FDE associated with this function. */
2033 current_funcdef_fde = fde_table_in_use;
2035 /* Add the new FDE at the end of the fde_table. */
2036 fde = &fde_table[fde_table_in_use++];
2037 fde->dw_fde_begin = xstrdup (label);
2038 fde->dw_fde_current_label = NULL;
2039 fde->dw_fde_end = NULL;
2040 fde->dw_fde_cfi = NULL;
2041 fde->nothrow = current_function_nothrow;
2043 args_size = old_args_size = 0;
2046 /* Output a marker (i.e. a label) for the absolute end of the generated code
2047 for a function definition. This gets called *after* the epilogue code has
2048 been generated. */
2050 void
2051 dwarf2out_end_epilogue ()
2053 dw_fde_ref fde;
2054 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2056 /* Output a label to mark the endpoint of the code generated for this
2057 function. */
2058 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2059 ASM_OUTPUT_LABEL (asm_out_file, label);
2060 fde = &fde_table[fde_table_in_use - 1];
2061 fde->dw_fde_end = xstrdup (label);
2064 void
2065 dwarf2out_frame_init ()
2067 /* Allocate the initial hunk of the fde_table. */
2068 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2069 fde_table_allocated = FDE_TABLE_INCREMENT;
2070 fde_table_in_use = 0;
2072 /* Generate the CFA instructions common to all FDE's. Do it now for the
2073 sake of lookup_cfa. */
2075 #ifdef DWARF2_UNWIND_INFO
2076 /* On entry, the Canonical Frame Address is at SP. */
2077 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2078 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2079 #endif
2082 void
2083 dwarf2out_frame_finish ()
2085 /* Output call frame information. */
2086 #ifdef MIPS_DEBUGGING_INFO
2087 if (write_symbols == DWARF2_DEBUG)
2088 output_call_frame_info (0);
2089 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2090 output_call_frame_info (1);
2091 #else
2092 if (write_symbols == DWARF2_DEBUG
2093 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2094 output_call_frame_info (1);
2095 #endif
2098 /* And now, the subset of the debugging information support code necessary
2099 for emitting location expressions. */
2101 typedef struct dw_val_struct *dw_val_ref;
2102 typedef struct die_struct *dw_die_ref;
2103 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2105 /* Each DIE may have a series of attribute/value pairs. Values
2106 can take on several forms. The forms that are used in this
2107 implementation are listed below. */
2109 typedef enum
2111 dw_val_class_addr,
2112 dw_val_class_loc,
2113 dw_val_class_const,
2114 dw_val_class_unsigned_const,
2115 dw_val_class_long_long,
2116 dw_val_class_float,
2117 dw_val_class_flag,
2118 dw_val_class_die_ref,
2119 dw_val_class_fde_ref,
2120 dw_val_class_lbl_id,
2121 dw_val_class_lbl_offset,
2122 dw_val_class_str
2124 dw_val_class;
2126 /* Describe a double word constant value. */
2127 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2129 typedef struct dw_long_long_struct
2131 unsigned long hi;
2132 unsigned long low;
2134 dw_long_long_const;
2136 /* Describe a floating point constant value. */
2138 typedef struct dw_fp_struct
2140 long *array;
2141 unsigned length;
2143 dw_float_const;
2145 /* The dw_val_node describes an attribute's value, as it is
2146 represented internally. */
2148 typedef struct dw_val_struct
2150 dw_val_class val_class;
2151 union
2153 rtx val_addr;
2154 dw_loc_descr_ref val_loc;
2155 long int val_int;
2156 long unsigned val_unsigned;
2157 dw_long_long_const val_long_long;
2158 dw_float_const val_float;
2159 struct {
2160 dw_die_ref die;
2161 int external;
2162 } val_die_ref;
2163 unsigned val_fde_index;
2164 char *val_str;
2165 char *val_lbl_id;
2166 unsigned char val_flag;
2170 dw_val_node;
2172 /* Locations in memory are described using a sequence of stack machine
2173 operations. */
2175 typedef struct dw_loc_descr_struct
2177 dw_loc_descr_ref dw_loc_next;
2178 enum dwarf_location_atom dw_loc_opc;
2179 dw_val_node dw_loc_oprnd1;
2180 dw_val_node dw_loc_oprnd2;
2181 int dw_loc_addr;
2183 dw_loc_descr_node;
2185 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2186 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2187 unsigned long,
2188 unsigned long));
2189 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2190 dw_loc_descr_ref));
2191 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2192 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2193 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2194 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2196 /* Convert a DWARF stack opcode into its string name. */
2198 static const char *
2199 dwarf_stack_op_name (op)
2200 register unsigned op;
2202 switch (op)
2204 case DW_OP_addr:
2205 return "DW_OP_addr";
2206 case DW_OP_deref:
2207 return "DW_OP_deref";
2208 case DW_OP_const1u:
2209 return "DW_OP_const1u";
2210 case DW_OP_const1s:
2211 return "DW_OP_const1s";
2212 case DW_OP_const2u:
2213 return "DW_OP_const2u";
2214 case DW_OP_const2s:
2215 return "DW_OP_const2s";
2216 case DW_OP_const4u:
2217 return "DW_OP_const4u";
2218 case DW_OP_const4s:
2219 return "DW_OP_const4s";
2220 case DW_OP_const8u:
2221 return "DW_OP_const8u";
2222 case DW_OP_const8s:
2223 return "DW_OP_const8s";
2224 case DW_OP_constu:
2225 return "DW_OP_constu";
2226 case DW_OP_consts:
2227 return "DW_OP_consts";
2228 case DW_OP_dup:
2229 return "DW_OP_dup";
2230 case DW_OP_drop:
2231 return "DW_OP_drop";
2232 case DW_OP_over:
2233 return "DW_OP_over";
2234 case DW_OP_pick:
2235 return "DW_OP_pick";
2236 case DW_OP_swap:
2237 return "DW_OP_swap";
2238 case DW_OP_rot:
2239 return "DW_OP_rot";
2240 case DW_OP_xderef:
2241 return "DW_OP_xderef";
2242 case DW_OP_abs:
2243 return "DW_OP_abs";
2244 case DW_OP_and:
2245 return "DW_OP_and";
2246 case DW_OP_div:
2247 return "DW_OP_div";
2248 case DW_OP_minus:
2249 return "DW_OP_minus";
2250 case DW_OP_mod:
2251 return "DW_OP_mod";
2252 case DW_OP_mul:
2253 return "DW_OP_mul";
2254 case DW_OP_neg:
2255 return "DW_OP_neg";
2256 case DW_OP_not:
2257 return "DW_OP_not";
2258 case DW_OP_or:
2259 return "DW_OP_or";
2260 case DW_OP_plus:
2261 return "DW_OP_plus";
2262 case DW_OP_plus_uconst:
2263 return "DW_OP_plus_uconst";
2264 case DW_OP_shl:
2265 return "DW_OP_shl";
2266 case DW_OP_shr:
2267 return "DW_OP_shr";
2268 case DW_OP_shra:
2269 return "DW_OP_shra";
2270 case DW_OP_xor:
2271 return "DW_OP_xor";
2272 case DW_OP_bra:
2273 return "DW_OP_bra";
2274 case DW_OP_eq:
2275 return "DW_OP_eq";
2276 case DW_OP_ge:
2277 return "DW_OP_ge";
2278 case DW_OP_gt:
2279 return "DW_OP_gt";
2280 case DW_OP_le:
2281 return "DW_OP_le";
2282 case DW_OP_lt:
2283 return "DW_OP_lt";
2284 case DW_OP_ne:
2285 return "DW_OP_ne";
2286 case DW_OP_skip:
2287 return "DW_OP_skip";
2288 case DW_OP_lit0:
2289 return "DW_OP_lit0";
2290 case DW_OP_lit1:
2291 return "DW_OP_lit1";
2292 case DW_OP_lit2:
2293 return "DW_OP_lit2";
2294 case DW_OP_lit3:
2295 return "DW_OP_lit3";
2296 case DW_OP_lit4:
2297 return "DW_OP_lit4";
2298 case DW_OP_lit5:
2299 return "DW_OP_lit5";
2300 case DW_OP_lit6:
2301 return "DW_OP_lit6";
2302 case DW_OP_lit7:
2303 return "DW_OP_lit7";
2304 case DW_OP_lit8:
2305 return "DW_OP_lit8";
2306 case DW_OP_lit9:
2307 return "DW_OP_lit9";
2308 case DW_OP_lit10:
2309 return "DW_OP_lit10";
2310 case DW_OP_lit11:
2311 return "DW_OP_lit11";
2312 case DW_OP_lit12:
2313 return "DW_OP_lit12";
2314 case DW_OP_lit13:
2315 return "DW_OP_lit13";
2316 case DW_OP_lit14:
2317 return "DW_OP_lit14";
2318 case DW_OP_lit15:
2319 return "DW_OP_lit15";
2320 case DW_OP_lit16:
2321 return "DW_OP_lit16";
2322 case DW_OP_lit17:
2323 return "DW_OP_lit17";
2324 case DW_OP_lit18:
2325 return "DW_OP_lit18";
2326 case DW_OP_lit19:
2327 return "DW_OP_lit19";
2328 case DW_OP_lit20:
2329 return "DW_OP_lit20";
2330 case DW_OP_lit21:
2331 return "DW_OP_lit21";
2332 case DW_OP_lit22:
2333 return "DW_OP_lit22";
2334 case DW_OP_lit23:
2335 return "DW_OP_lit23";
2336 case DW_OP_lit24:
2337 return "DW_OP_lit24";
2338 case DW_OP_lit25:
2339 return "DW_OP_lit25";
2340 case DW_OP_lit26:
2341 return "DW_OP_lit26";
2342 case DW_OP_lit27:
2343 return "DW_OP_lit27";
2344 case DW_OP_lit28:
2345 return "DW_OP_lit28";
2346 case DW_OP_lit29:
2347 return "DW_OP_lit29";
2348 case DW_OP_lit30:
2349 return "DW_OP_lit30";
2350 case DW_OP_lit31:
2351 return "DW_OP_lit31";
2352 case DW_OP_reg0:
2353 return "DW_OP_reg0";
2354 case DW_OP_reg1:
2355 return "DW_OP_reg1";
2356 case DW_OP_reg2:
2357 return "DW_OP_reg2";
2358 case DW_OP_reg3:
2359 return "DW_OP_reg3";
2360 case DW_OP_reg4:
2361 return "DW_OP_reg4";
2362 case DW_OP_reg5:
2363 return "DW_OP_reg5";
2364 case DW_OP_reg6:
2365 return "DW_OP_reg6";
2366 case DW_OP_reg7:
2367 return "DW_OP_reg7";
2368 case DW_OP_reg8:
2369 return "DW_OP_reg8";
2370 case DW_OP_reg9:
2371 return "DW_OP_reg9";
2372 case DW_OP_reg10:
2373 return "DW_OP_reg10";
2374 case DW_OP_reg11:
2375 return "DW_OP_reg11";
2376 case DW_OP_reg12:
2377 return "DW_OP_reg12";
2378 case DW_OP_reg13:
2379 return "DW_OP_reg13";
2380 case DW_OP_reg14:
2381 return "DW_OP_reg14";
2382 case DW_OP_reg15:
2383 return "DW_OP_reg15";
2384 case DW_OP_reg16:
2385 return "DW_OP_reg16";
2386 case DW_OP_reg17:
2387 return "DW_OP_reg17";
2388 case DW_OP_reg18:
2389 return "DW_OP_reg18";
2390 case DW_OP_reg19:
2391 return "DW_OP_reg19";
2392 case DW_OP_reg20:
2393 return "DW_OP_reg20";
2394 case DW_OP_reg21:
2395 return "DW_OP_reg21";
2396 case DW_OP_reg22:
2397 return "DW_OP_reg22";
2398 case DW_OP_reg23:
2399 return "DW_OP_reg23";
2400 case DW_OP_reg24:
2401 return "DW_OP_reg24";
2402 case DW_OP_reg25:
2403 return "DW_OP_reg25";
2404 case DW_OP_reg26:
2405 return "DW_OP_reg26";
2406 case DW_OP_reg27:
2407 return "DW_OP_reg27";
2408 case DW_OP_reg28:
2409 return "DW_OP_reg28";
2410 case DW_OP_reg29:
2411 return "DW_OP_reg29";
2412 case DW_OP_reg30:
2413 return "DW_OP_reg30";
2414 case DW_OP_reg31:
2415 return "DW_OP_reg31";
2416 case DW_OP_breg0:
2417 return "DW_OP_breg0";
2418 case DW_OP_breg1:
2419 return "DW_OP_breg1";
2420 case DW_OP_breg2:
2421 return "DW_OP_breg2";
2422 case DW_OP_breg3:
2423 return "DW_OP_breg3";
2424 case DW_OP_breg4:
2425 return "DW_OP_breg4";
2426 case DW_OP_breg5:
2427 return "DW_OP_breg5";
2428 case DW_OP_breg6:
2429 return "DW_OP_breg6";
2430 case DW_OP_breg7:
2431 return "DW_OP_breg7";
2432 case DW_OP_breg8:
2433 return "DW_OP_breg8";
2434 case DW_OP_breg9:
2435 return "DW_OP_breg9";
2436 case DW_OP_breg10:
2437 return "DW_OP_breg10";
2438 case DW_OP_breg11:
2439 return "DW_OP_breg11";
2440 case DW_OP_breg12:
2441 return "DW_OP_breg12";
2442 case DW_OP_breg13:
2443 return "DW_OP_breg13";
2444 case DW_OP_breg14:
2445 return "DW_OP_breg14";
2446 case DW_OP_breg15:
2447 return "DW_OP_breg15";
2448 case DW_OP_breg16:
2449 return "DW_OP_breg16";
2450 case DW_OP_breg17:
2451 return "DW_OP_breg17";
2452 case DW_OP_breg18:
2453 return "DW_OP_breg18";
2454 case DW_OP_breg19:
2455 return "DW_OP_breg19";
2456 case DW_OP_breg20:
2457 return "DW_OP_breg20";
2458 case DW_OP_breg21:
2459 return "DW_OP_breg21";
2460 case DW_OP_breg22:
2461 return "DW_OP_breg22";
2462 case DW_OP_breg23:
2463 return "DW_OP_breg23";
2464 case DW_OP_breg24:
2465 return "DW_OP_breg24";
2466 case DW_OP_breg25:
2467 return "DW_OP_breg25";
2468 case DW_OP_breg26:
2469 return "DW_OP_breg26";
2470 case DW_OP_breg27:
2471 return "DW_OP_breg27";
2472 case DW_OP_breg28:
2473 return "DW_OP_breg28";
2474 case DW_OP_breg29:
2475 return "DW_OP_breg29";
2476 case DW_OP_breg30:
2477 return "DW_OP_breg30";
2478 case DW_OP_breg31:
2479 return "DW_OP_breg31";
2480 case DW_OP_regx:
2481 return "DW_OP_regx";
2482 case DW_OP_fbreg:
2483 return "DW_OP_fbreg";
2484 case DW_OP_bregx:
2485 return "DW_OP_bregx";
2486 case DW_OP_piece:
2487 return "DW_OP_piece";
2488 case DW_OP_deref_size:
2489 return "DW_OP_deref_size";
2490 case DW_OP_xderef_size:
2491 return "DW_OP_xderef_size";
2492 case DW_OP_nop:
2493 return "DW_OP_nop";
2494 default:
2495 return "OP_<unknown>";
2499 /* Return a pointer to a newly allocated location description. Location
2500 descriptions are simple expression terms that can be strung
2501 together to form more complicated location (address) descriptions. */
2503 static inline dw_loc_descr_ref
2504 new_loc_descr (op, oprnd1, oprnd2)
2505 register enum dwarf_location_atom op;
2506 register unsigned long oprnd1;
2507 register unsigned long oprnd2;
2509 /* Use xcalloc here so we clear out all of the long_long constant in
2510 the union. */
2511 register dw_loc_descr_ref descr
2512 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2514 descr->dw_loc_opc = op;
2515 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2516 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2517 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2518 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2520 return descr;
2523 /* Add a location description term to a location description expression. */
2525 static inline void
2526 add_loc_descr (list_head, descr)
2527 register dw_loc_descr_ref *list_head;
2528 register dw_loc_descr_ref descr;
2530 register dw_loc_descr_ref *d;
2532 /* Find the end of the chain. */
2533 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2536 *d = descr;
2539 /* Return the size of a location descriptor. */
2541 static unsigned long
2542 size_of_loc_descr (loc)
2543 register dw_loc_descr_ref loc;
2545 register unsigned long size = 1;
2547 switch (loc->dw_loc_opc)
2549 case DW_OP_addr:
2550 size += DWARF2_ADDR_SIZE;
2551 break;
2552 case DW_OP_const1u:
2553 case DW_OP_const1s:
2554 size += 1;
2555 break;
2556 case DW_OP_const2u:
2557 case DW_OP_const2s:
2558 size += 2;
2559 break;
2560 case DW_OP_const4u:
2561 case DW_OP_const4s:
2562 size += 4;
2563 break;
2564 case DW_OP_const8u:
2565 case DW_OP_const8s:
2566 size += 8;
2567 break;
2568 case DW_OP_constu:
2569 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2570 break;
2571 case DW_OP_consts:
2572 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2573 break;
2574 case DW_OP_pick:
2575 size += 1;
2576 break;
2577 case DW_OP_plus_uconst:
2578 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2579 break;
2580 case DW_OP_skip:
2581 case DW_OP_bra:
2582 size += 2;
2583 break;
2584 case DW_OP_breg0:
2585 case DW_OP_breg1:
2586 case DW_OP_breg2:
2587 case DW_OP_breg3:
2588 case DW_OP_breg4:
2589 case DW_OP_breg5:
2590 case DW_OP_breg6:
2591 case DW_OP_breg7:
2592 case DW_OP_breg8:
2593 case DW_OP_breg9:
2594 case DW_OP_breg10:
2595 case DW_OP_breg11:
2596 case DW_OP_breg12:
2597 case DW_OP_breg13:
2598 case DW_OP_breg14:
2599 case DW_OP_breg15:
2600 case DW_OP_breg16:
2601 case DW_OP_breg17:
2602 case DW_OP_breg18:
2603 case DW_OP_breg19:
2604 case DW_OP_breg20:
2605 case DW_OP_breg21:
2606 case DW_OP_breg22:
2607 case DW_OP_breg23:
2608 case DW_OP_breg24:
2609 case DW_OP_breg25:
2610 case DW_OP_breg26:
2611 case DW_OP_breg27:
2612 case DW_OP_breg28:
2613 case DW_OP_breg29:
2614 case DW_OP_breg30:
2615 case DW_OP_breg31:
2616 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2617 break;
2618 case DW_OP_regx:
2619 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2620 break;
2621 case DW_OP_fbreg:
2622 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2623 break;
2624 case DW_OP_bregx:
2625 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2626 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2627 break;
2628 case DW_OP_piece:
2629 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2630 break;
2631 case DW_OP_deref_size:
2632 case DW_OP_xderef_size:
2633 size += 1;
2634 break;
2635 default:
2636 break;
2639 return size;
2642 /* Return the size of a series of location descriptors. */
2644 static unsigned long
2645 size_of_locs (loc)
2646 register dw_loc_descr_ref loc;
2648 register unsigned long size = 0;
2650 for (; loc != NULL; loc = loc->dw_loc_next)
2652 loc->dw_loc_addr = size;
2653 size += size_of_loc_descr (loc);
2656 return size;
2659 /* Output location description stack opcode's operands (if any). */
2661 static void
2662 output_loc_operands (loc)
2663 register dw_loc_descr_ref loc;
2665 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2666 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2668 switch (loc->dw_loc_opc)
2670 #ifdef DWARF2_DEBUGGING_INFO
2671 case DW_OP_addr:
2672 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
2673 fputc ('\n', asm_out_file);
2674 break;
2675 case DW_OP_const2u:
2676 case DW_OP_const2s:
2677 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
2678 fputc ('\n', asm_out_file);
2679 break;
2680 case DW_OP_const4u:
2681 case DW_OP_const4s:
2682 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
2683 fputc ('\n', asm_out_file);
2684 break;
2685 case DW_OP_const8u:
2686 case DW_OP_const8s:
2687 abort ();
2688 fputc ('\n', asm_out_file);
2689 break;
2690 case DW_OP_skip:
2691 case DW_OP_bra:
2693 int offset;
2695 if (val1->val_class == dw_val_class_loc)
2696 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2697 else
2698 abort ();
2700 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, offset);
2701 fputc ('\n', asm_out_file);
2703 break;
2704 #else
2705 case DW_OP_addr:
2706 case DW_OP_const2u:
2707 case DW_OP_const2s:
2708 case DW_OP_const4u:
2709 case DW_OP_const4s:
2710 case DW_OP_const8u:
2711 case DW_OP_const8s:
2712 case DW_OP_skip:
2713 case DW_OP_bra:
2714 /* We currently don't make any attempt to make sure these are
2715 aligned properly like we do for the main unwind info, so
2716 don't support emitting things larger than a byte if we're
2717 only doing unwinding. */
2718 abort ();
2719 #endif
2720 case DW_OP_const1u:
2721 case DW_OP_const1s:
2722 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2723 fputc ('\n', asm_out_file);
2724 break;
2725 case DW_OP_constu:
2726 output_uleb128 (val1->v.val_unsigned);
2727 fputc ('\n', asm_out_file);
2728 break;
2729 case DW_OP_consts:
2730 output_sleb128 (val1->v.val_int);
2731 fputc ('\n', asm_out_file);
2732 break;
2733 case DW_OP_pick:
2734 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
2735 fputc ('\n', asm_out_file);
2736 break;
2737 case DW_OP_plus_uconst:
2738 output_uleb128 (val1->v.val_unsigned);
2739 fputc ('\n', asm_out_file);
2740 break;
2741 case DW_OP_breg0:
2742 case DW_OP_breg1:
2743 case DW_OP_breg2:
2744 case DW_OP_breg3:
2745 case DW_OP_breg4:
2746 case DW_OP_breg5:
2747 case DW_OP_breg6:
2748 case DW_OP_breg7:
2749 case DW_OP_breg8:
2750 case DW_OP_breg9:
2751 case DW_OP_breg10:
2752 case DW_OP_breg11:
2753 case DW_OP_breg12:
2754 case DW_OP_breg13:
2755 case DW_OP_breg14:
2756 case DW_OP_breg15:
2757 case DW_OP_breg16:
2758 case DW_OP_breg17:
2759 case DW_OP_breg18:
2760 case DW_OP_breg19:
2761 case DW_OP_breg20:
2762 case DW_OP_breg21:
2763 case DW_OP_breg22:
2764 case DW_OP_breg23:
2765 case DW_OP_breg24:
2766 case DW_OP_breg25:
2767 case DW_OP_breg26:
2768 case DW_OP_breg27:
2769 case DW_OP_breg28:
2770 case DW_OP_breg29:
2771 case DW_OP_breg30:
2772 case DW_OP_breg31:
2773 output_sleb128 (val1->v.val_int);
2774 fputc ('\n', asm_out_file);
2775 break;
2776 case DW_OP_regx:
2777 output_uleb128 (val1->v.val_unsigned);
2778 fputc ('\n', asm_out_file);
2779 break;
2780 case DW_OP_fbreg:
2781 output_sleb128 (val1->v.val_int);
2782 fputc ('\n', asm_out_file);
2783 break;
2784 case DW_OP_bregx:
2785 output_uleb128 (val1->v.val_unsigned);
2786 fputc ('\n', asm_out_file);
2787 output_sleb128 (val2->v.val_int);
2788 fputc ('\n', asm_out_file);
2789 break;
2790 case DW_OP_piece:
2791 output_uleb128 (val1->v.val_unsigned);
2792 fputc ('\n', asm_out_file);
2793 break;
2794 case DW_OP_deref_size:
2795 case DW_OP_xderef_size:
2796 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2797 fputc ('\n', asm_out_file);
2798 break;
2799 default:
2800 /* Other codes have no operands. */
2801 break;
2805 /* Output a sequence of location operations. */
2807 static void
2808 output_loc_sequence (loc)
2809 dw_loc_descr_ref loc;
2811 for (; loc != NULL; loc = loc->dw_loc_next)
2813 /* Output the opcode. */
2814 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
2815 if (flag_debug_asm)
2816 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
2817 dwarf_stack_op_name (loc->dw_loc_opc));
2819 fputc ('\n', asm_out_file);
2821 /* Output the operand(s) (if any). */
2822 output_loc_operands (loc);
2826 /* This routine will generate the correct assembly data for a location
2827 description based on a cfi entry with a complex address. */
2829 static void
2830 output_cfa_loc (cfi)
2831 dw_cfi_ref cfi;
2833 dw_loc_descr_ref loc;
2834 unsigned long size;
2836 /* Output the size of the block. */
2837 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2838 size = size_of_locs (loc);
2839 output_uleb128 (size);
2840 fputc ('\n', asm_out_file);
2842 /* Now output the operations themselves. */
2843 output_loc_sequence (loc);
2846 /* This function builds a dwarf location descriptor seqeunce from
2847 a dw_cfa_location. */
2849 static struct dw_loc_descr_struct *
2850 build_cfa_loc (cfa)
2851 dw_cfa_location *cfa;
2853 struct dw_loc_descr_struct *head, *tmp;
2855 if (cfa->indirect == 0)
2856 abort ();
2858 if (cfa->base_offset)
2860 if (cfa->reg <= 31)
2861 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2862 else
2863 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2865 else if (cfa->reg <= 31)
2866 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2867 else
2868 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2869 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2870 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2871 add_loc_descr (&head, tmp);
2872 if (cfa->offset != 0)
2874 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2875 add_loc_descr (&head, tmp);
2877 return head;
2880 /* This function fills in aa dw_cfa_location structure from a
2881 dwarf location descriptor sequence. */
2883 static void
2884 get_cfa_from_loc_descr (cfa, loc)
2885 dw_cfa_location *cfa;
2886 struct dw_loc_descr_struct *loc;
2888 struct dw_loc_descr_struct *ptr;
2889 cfa->offset = 0;
2890 cfa->base_offset = 0;
2891 cfa->indirect = 0;
2892 cfa->reg = -1;
2894 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2896 enum dwarf_location_atom op = ptr->dw_loc_opc;
2897 switch (op)
2899 case DW_OP_reg0:
2900 case DW_OP_reg1:
2901 case DW_OP_reg2:
2902 case DW_OP_reg3:
2903 case DW_OP_reg4:
2904 case DW_OP_reg5:
2905 case DW_OP_reg6:
2906 case DW_OP_reg7:
2907 case DW_OP_reg8:
2908 case DW_OP_reg9:
2909 case DW_OP_reg10:
2910 case DW_OP_reg11:
2911 case DW_OP_reg12:
2912 case DW_OP_reg13:
2913 case DW_OP_reg14:
2914 case DW_OP_reg15:
2915 case DW_OP_reg16:
2916 case DW_OP_reg17:
2917 case DW_OP_reg18:
2918 case DW_OP_reg19:
2919 case DW_OP_reg20:
2920 case DW_OP_reg21:
2921 case DW_OP_reg22:
2922 case DW_OP_reg23:
2923 case DW_OP_reg24:
2924 case DW_OP_reg25:
2925 case DW_OP_reg26:
2926 case DW_OP_reg27:
2927 case DW_OP_reg28:
2928 case DW_OP_reg29:
2929 case DW_OP_reg30:
2930 case DW_OP_reg31:
2931 cfa->reg = op - DW_OP_reg0;
2932 break;
2933 case DW_OP_regx:
2934 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2935 break;
2936 case DW_OP_breg0:
2937 case DW_OP_breg1:
2938 case DW_OP_breg2:
2939 case DW_OP_breg3:
2940 case DW_OP_breg4:
2941 case DW_OP_breg5:
2942 case DW_OP_breg6:
2943 case DW_OP_breg7:
2944 case DW_OP_breg8:
2945 case DW_OP_breg9:
2946 case DW_OP_breg10:
2947 case DW_OP_breg11:
2948 case DW_OP_breg12:
2949 case DW_OP_breg13:
2950 case DW_OP_breg14:
2951 case DW_OP_breg15:
2952 case DW_OP_breg16:
2953 case DW_OP_breg17:
2954 case DW_OP_breg18:
2955 case DW_OP_breg19:
2956 case DW_OP_breg20:
2957 case DW_OP_breg21:
2958 case DW_OP_breg22:
2959 case DW_OP_breg23:
2960 case DW_OP_breg24:
2961 case DW_OP_breg25:
2962 case DW_OP_breg26:
2963 case DW_OP_breg27:
2964 case DW_OP_breg28:
2965 case DW_OP_breg29:
2966 case DW_OP_breg30:
2967 case DW_OP_breg31:
2968 cfa->reg = op - DW_OP_breg0;
2969 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2970 break;
2971 case DW_OP_bregx:
2972 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2973 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
2974 break;
2975 case DW_OP_deref:
2976 cfa->indirect = 1;
2977 break;
2978 case DW_OP_plus_uconst:
2979 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
2980 break;
2981 default:
2982 fatal ("DW_LOC_OP %s not implememnted yet.\n",
2983 dwarf_stack_op_name (ptr->dw_loc_opc));
2987 #endif /* .debug_frame support */
2989 /* And now, the support for symbolic debugging information. */
2990 #ifdef DWARF2_DEBUGGING_INFO
2992 /* NOTE: In the comments in this file, many references are made to
2993 "Debugging Information Entries". This term is abbreviated as `DIE'
2994 throughout the remainder of this file. */
2996 /* An internal representation of the DWARF output is built, and then
2997 walked to generate the DWARF debugging info. The walk of the internal
2998 representation is done after the entire program has been compiled.
2999 The types below are used to describe the internal representation. */
3001 /* Various DIE's use offsets relative to the beginning of the
3002 .debug_info section to refer to each other. */
3004 typedef long int dw_offset;
3006 /* Define typedefs here to avoid circular dependencies. */
3008 typedef struct dw_attr_struct *dw_attr_ref;
3009 typedef struct dw_line_info_struct *dw_line_info_ref;
3010 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3011 typedef struct pubname_struct *pubname_ref;
3012 typedef dw_die_ref *arange_ref;
3014 /* Each entry in the line_info_table maintains the file and
3015 line number associated with the label generated for that
3016 entry. The label gives the PC value associated with
3017 the line number entry. */
3019 typedef struct dw_line_info_struct
3021 unsigned long dw_file_num;
3022 unsigned long dw_line_num;
3024 dw_line_info_entry;
3026 /* Line information for functions in separate sections; each one gets its
3027 own sequence. */
3028 typedef struct dw_separate_line_info_struct
3030 unsigned long dw_file_num;
3031 unsigned long dw_line_num;
3032 unsigned long function;
3034 dw_separate_line_info_entry;
3036 /* Each DIE attribute has a field specifying the attribute kind,
3037 a link to the next attribute in the chain, and an attribute value.
3038 Attributes are typically linked below the DIE they modify. */
3040 typedef struct dw_attr_struct
3042 enum dwarf_attribute dw_attr;
3043 dw_attr_ref dw_attr_next;
3044 dw_val_node dw_attr_val;
3046 dw_attr_node;
3048 /* The Debugging Information Entry (DIE) structure */
3050 typedef struct die_struct
3052 enum dwarf_tag die_tag;
3053 char *die_symbol;
3054 dw_attr_ref die_attr;
3055 dw_die_ref die_parent;
3056 dw_die_ref die_child;
3057 dw_die_ref die_sib;
3058 dw_offset die_offset;
3059 unsigned long die_abbrev;
3060 int die_mark;
3062 die_node;
3064 /* The pubname structure */
3066 typedef struct pubname_struct
3068 dw_die_ref die;
3069 char *name;
3071 pubname_entry;
3073 /* The limbo die list structure. */
3074 typedef struct limbo_die_struct
3076 dw_die_ref die;
3077 struct limbo_die_struct *next;
3079 limbo_die_node;
3081 /* How to start an assembler comment. */
3082 #ifndef ASM_COMMENT_START
3083 #define ASM_COMMENT_START ";#"
3084 #endif
3086 /* Define a macro which returns non-zero for a TYPE_DECL which was
3087 implicitly generated for a tagged type.
3089 Note that unlike the gcc front end (which generates a NULL named
3090 TYPE_DECL node for each complete tagged type, each array type, and
3091 each function type node created) the g++ front end generates a
3092 _named_ TYPE_DECL node for each tagged type node created.
3093 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3094 generate a DW_TAG_typedef DIE for them. */
3096 #define TYPE_DECL_IS_STUB(decl) \
3097 (DECL_NAME (decl) == NULL_TREE \
3098 || (DECL_ARTIFICIAL (decl) \
3099 && is_tagged_type (TREE_TYPE (decl)) \
3100 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3101 /* This is necessary for stub decls that \
3102 appear in nested inline functions. */ \
3103 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3104 && (decl_ultimate_origin (decl) \
3105 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3107 /* Information concerning the compilation unit's programming
3108 language, and compiler version. */
3110 extern int flag_traditional;
3112 /* Fixed size portion of the DWARF compilation unit header. */
3113 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3115 /* Fixed size portion of debugging line information prolog. */
3116 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3118 /* Fixed size portion of public names info. */
3119 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3121 /* Fixed size portion of the address range info. */
3122 #define DWARF_ARANGES_HEADER_SIZE \
3123 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3124 - DWARF_OFFSET_SIZE)
3126 /* Size of padding portion in the address range info. It must be
3127 aligned to twice the pointer size. */
3128 #define DWARF_ARANGES_PAD_SIZE \
3129 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3130 - (2 * DWARF_OFFSET_SIZE + 4))
3132 /* Use assembler line directives if available. */
3133 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3134 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3135 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3136 #else
3137 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3138 #endif
3139 #endif
3141 /* Define the architecture-dependent minimum instruction length (in bytes).
3142 In this implementation of DWARF, this field is used for information
3143 purposes only. Since GCC generates assembly language, we have
3144 no a priori knowledge of how many instruction bytes are generated
3145 for each source line, and therefore can use only the DW_LNE_set_address
3146 and DW_LNS_fixed_advance_pc line information commands. */
3148 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3149 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3150 #endif
3152 /* Minimum line offset in a special line info. opcode.
3153 This value was chosen to give a reasonable range of values. */
3154 #define DWARF_LINE_BASE -10
3156 /* First special line opcde - leave room for the standard opcodes. */
3157 #define DWARF_LINE_OPCODE_BASE 10
3159 /* Range of line offsets in a special line info. opcode. */
3160 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3162 /* Flag that indicates the initial value of the is_stmt_start flag.
3163 In the present implementation, we do not mark any lines as
3164 the beginning of a source statement, because that information
3165 is not made available by the GCC front-end. */
3166 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3168 /* This location is used by calc_die_sizes() to keep track
3169 the offset of each DIE within the .debug_info section. */
3170 static unsigned long next_die_offset;
3172 /* Record the root of the DIE's built for the current compilation unit. */
3173 static dw_die_ref comp_unit_die;
3175 /* A list of DIEs with a NULL parent waiting to be relocated. */
3176 static limbo_die_node *limbo_die_list = 0;
3178 /* Structure used by lookup_filename to manage sets of filenames. */
3179 struct file_table
3181 char **table;
3182 unsigned allocated;
3183 unsigned in_use;
3184 unsigned last_lookup_index;
3187 /* Size (in elements) of increments by which we may expand the filename
3188 table. */
3189 #define FILE_TABLE_INCREMENT 64
3191 /* Filenames referenced by declarations this compilation unit. */
3192 static struct file_table decl_file_table;
3194 /* Filenames referenced by line numbers in this compilation unit. */
3195 static struct file_table line_file_table;
3197 /* Local pointer to the name of the main input file. Initialized in
3198 dwarf2out_init. */
3199 static const char *primary_filename;
3201 /* A pointer to the base of a table of references to DIE's that describe
3202 declarations. The table is indexed by DECL_UID() which is a unique
3203 number identifying each decl. */
3204 static dw_die_ref *decl_die_table;
3206 /* Number of elements currently allocated for the decl_die_table. */
3207 static unsigned decl_die_table_allocated;
3209 /* Number of elements in decl_die_table currently in use. */
3210 static unsigned decl_die_table_in_use;
3212 /* Size (in elements) of increments by which we may expand the
3213 decl_die_table. */
3214 #define DECL_DIE_TABLE_INCREMENT 256
3216 /* A pointer to the base of a table of references to declaration
3217 scopes. This table is a display which tracks the nesting
3218 of declaration scopes at the current scope and containing
3219 scopes. This table is used to find the proper place to
3220 define type declaration DIE's. */
3221 static tree *decl_scope_table;
3223 /* Number of elements currently allocated for the decl_scope_table. */
3224 static int decl_scope_table_allocated;
3226 /* Current level of nesting of declaration scopes. */
3227 static int decl_scope_depth;
3229 /* Size (in elements) of increments by which we may expand the
3230 decl_scope_table. */
3231 #define DECL_SCOPE_TABLE_INCREMENT 64
3233 /* A pointer to the base of a list of references to DIE's that
3234 are uniquely identified by their tag, presence/absence of
3235 children DIE's, and list of attribute/value pairs. */
3236 static dw_die_ref *abbrev_die_table;
3238 /* Number of elements currently allocated for abbrev_die_table. */
3239 static unsigned abbrev_die_table_allocated;
3241 /* Number of elements in type_die_table currently in use. */
3242 static unsigned abbrev_die_table_in_use;
3244 /* Size (in elements) of increments by which we may expand the
3245 abbrev_die_table. */
3246 #define ABBREV_DIE_TABLE_INCREMENT 256
3248 /* A pointer to the base of a table that contains line information
3249 for each source code line in .text in the compilation unit. */
3250 static dw_line_info_ref line_info_table;
3252 /* Number of elements currently allocated for line_info_table. */
3253 static unsigned line_info_table_allocated;
3255 /* Number of elements in separate_line_info_table currently in use. */
3256 static unsigned separate_line_info_table_in_use;
3258 /* A pointer to the base of a table that contains line information
3259 for each source code line outside of .text in the compilation unit. */
3260 static dw_separate_line_info_ref separate_line_info_table;
3262 /* Number of elements currently allocated for separate_line_info_table. */
3263 static unsigned separate_line_info_table_allocated;
3265 /* Number of elements in line_info_table currently in use. */
3266 static unsigned line_info_table_in_use;
3268 /* Size (in elements) of increments by which we may expand the
3269 line_info_table. */
3270 #define LINE_INFO_TABLE_INCREMENT 1024
3272 /* A pointer to the base of a table that contains a list of publicly
3273 accessible names. */
3274 static pubname_ref pubname_table;
3276 /* Number of elements currently allocated for pubname_table. */
3277 static unsigned pubname_table_allocated;
3279 /* Number of elements in pubname_table currently in use. */
3280 static unsigned pubname_table_in_use;
3282 /* Size (in elements) of increments by which we may expand the
3283 pubname_table. */
3284 #define PUBNAME_TABLE_INCREMENT 64
3286 /* A pointer to the base of a table that contains a list of publicly
3287 accessible names. */
3288 static arange_ref arange_table;
3290 /* Number of elements currently allocated for arange_table. */
3291 static unsigned arange_table_allocated;
3293 /* Number of elements in arange_table currently in use. */
3294 static unsigned arange_table_in_use;
3296 /* Size (in elements) of increments by which we may expand the
3297 arange_table. */
3298 #define ARANGE_TABLE_INCREMENT 64
3300 /* A pointer to the base of a list of incomplete types which might be
3301 completed at some later time. */
3303 static tree *incomplete_types_list;
3305 /* Number of elements currently allocated for the incomplete_types_list. */
3306 static unsigned incomplete_types_allocated;
3308 /* Number of elements of incomplete_types_list currently in use. */
3309 static unsigned incomplete_types;
3311 /* Size (in elements) of increments by which we may expand the incomplete
3312 types list. Actually, a single hunk of space of this size should
3313 be enough for most typical programs. */
3314 #define INCOMPLETE_TYPES_INCREMENT 64
3316 /* Record whether the function being analyzed contains inlined functions. */
3317 static int current_function_has_inlines;
3318 #if 0 && defined (MIPS_DEBUGGING_INFO)
3319 static int comp_unit_has_inlines;
3320 #endif
3322 /* Array of RTXes referenced by the debugging information, which therefore
3323 must be kept around forever. We do this rather than perform GC on
3324 the dwarf info because almost all of the dwarf info lives forever, and
3325 it's easier to support non-GC frontends this way. */
3326 static varray_type used_rtx_varray;
3328 /* Forward declarations for functions defined in this file. */
3330 static int is_pseudo_reg PARAMS ((rtx));
3331 static tree type_main_variant PARAMS ((tree));
3332 static int is_tagged_type PARAMS ((tree));
3333 static const char *dwarf_tag_name PARAMS ((unsigned));
3334 static const char *dwarf_attr_name PARAMS ((unsigned));
3335 static const char *dwarf_form_name PARAMS ((unsigned));
3336 #if 0
3337 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3338 #endif
3339 static tree decl_ultimate_origin PARAMS ((tree));
3340 static tree block_ultimate_origin PARAMS ((tree));
3341 static tree decl_class_context PARAMS ((tree));
3342 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3343 static void add_AT_flag PARAMS ((dw_die_ref,
3344 enum dwarf_attribute,
3345 unsigned));
3346 static void add_AT_int PARAMS ((dw_die_ref,
3347 enum dwarf_attribute, long));
3348 static void add_AT_unsigned PARAMS ((dw_die_ref,
3349 enum dwarf_attribute,
3350 unsigned long));
3351 static void add_AT_long_long PARAMS ((dw_die_ref,
3352 enum dwarf_attribute,
3353 unsigned long,
3354 unsigned long));
3355 static void add_AT_float PARAMS ((dw_die_ref,
3356 enum dwarf_attribute,
3357 unsigned, long *));
3358 static void add_AT_string PARAMS ((dw_die_ref,
3359 enum dwarf_attribute,
3360 const char *));
3361 static void add_AT_die_ref PARAMS ((dw_die_ref,
3362 enum dwarf_attribute,
3363 dw_die_ref));
3364 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3365 enum dwarf_attribute,
3366 unsigned));
3367 static void add_AT_loc PARAMS ((dw_die_ref,
3368 enum dwarf_attribute,
3369 dw_loc_descr_ref));
3370 static void add_AT_addr PARAMS ((dw_die_ref,
3371 enum dwarf_attribute,
3372 rtx));
3373 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3374 enum dwarf_attribute,
3375 const char *));
3376 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3377 enum dwarf_attribute,
3378 const char *));
3379 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3380 enum dwarf_attribute));
3381 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3382 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3383 static const char *get_AT_string PARAMS ((dw_die_ref,
3384 enum dwarf_attribute));
3385 static int get_AT_flag PARAMS ((dw_die_ref,
3386 enum dwarf_attribute));
3387 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3388 enum dwarf_attribute));
3389 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3390 enum dwarf_attribute));
3391 static int is_c_family PARAMS ((void));
3392 static int is_java PARAMS ((void));
3393 static int is_fortran PARAMS ((void));
3394 static void remove_AT PARAMS ((dw_die_ref,
3395 enum dwarf_attribute));
3396 static void remove_children PARAMS ((dw_die_ref));
3397 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3398 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3399 static dw_die_ref lookup_type_die PARAMS ((tree));
3400 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3401 static dw_die_ref lookup_decl_die PARAMS ((tree));
3402 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3403 static void print_spaces PARAMS ((FILE *));
3404 static void print_die PARAMS ((dw_die_ref, FILE *));
3405 static void print_dwarf_line_table PARAMS ((FILE *));
3406 static void reverse_die_lists PARAMS ((dw_die_ref));
3407 static void reverse_all_dies PARAMS ((dw_die_ref));
3408 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3409 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3410 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3411 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3412 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3413 static void compute_section_prefix PARAMS ((dw_die_ref));
3414 static int is_type_die PARAMS ((dw_die_ref));
3415 static int is_comdat_die PARAMS ((dw_die_ref));
3416 static int is_symbol_die PARAMS ((dw_die_ref));
3417 static char *gen_internal_sym PARAMS ((void));
3418 static void assign_symbol_names PARAMS ((dw_die_ref));
3419 static void break_out_includes PARAMS ((dw_die_ref));
3420 static void add_sibling_attributes PARAMS ((dw_die_ref));
3421 static void build_abbrev_table PARAMS ((dw_die_ref));
3422 static unsigned long size_of_string PARAMS ((const char *));
3423 static int constant_size PARAMS ((long unsigned));
3424 static unsigned long size_of_die PARAMS ((dw_die_ref));
3425 static void calc_die_sizes PARAMS ((dw_die_ref));
3426 static void mark_dies PARAMS ((dw_die_ref));
3427 static void unmark_dies PARAMS ((dw_die_ref));
3428 static unsigned long size_of_line_prolog PARAMS ((void));
3429 static unsigned long size_of_pubnames PARAMS ((void));
3430 static unsigned long size_of_aranges PARAMS ((void));
3431 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3432 static void output_value_format PARAMS ((dw_attr_ref));
3433 static void output_abbrev_section PARAMS ((void));
3434 static void output_die_symbol PARAMS ((dw_die_ref));
3435 static void output_symbolic_ref PARAMS ((dw_die_ref));
3436 static void output_die PARAMS ((dw_die_ref));
3437 static void output_compilation_unit_header PARAMS ((void));
3438 static void output_comp_unit PARAMS ((dw_die_ref));
3439 static const char *dwarf2_name PARAMS ((tree, int));
3440 static void add_pubname PARAMS ((tree, dw_die_ref));
3441 static void output_pubnames PARAMS ((void));
3442 static void add_arange PARAMS ((tree, dw_die_ref));
3443 static void output_aranges PARAMS ((void));
3444 static void output_line_info PARAMS ((void));
3445 static void output_file_names PARAMS ((void));
3446 static dw_die_ref base_type_die PARAMS ((tree));
3447 static tree root_type PARAMS ((tree));
3448 static int is_base_type PARAMS ((tree));
3449 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3450 static int type_is_enum PARAMS ((tree));
3451 static unsigned int reg_number PARAMS ((rtx));
3452 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3453 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3454 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3455 static int is_based_loc PARAMS ((rtx));
3456 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3457 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3458 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3459 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3460 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3461 static tree field_type PARAMS ((tree));
3462 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3463 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3464 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3465 static void add_AT_location_description PARAMS ((dw_die_ref,
3466 enum dwarf_attribute, rtx));
3467 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3468 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3469 static rtx rtl_for_decl_location PARAMS ((tree));
3470 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3471 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3472 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3473 static void add_bound_info PARAMS ((dw_die_ref,
3474 enum dwarf_attribute, tree));
3475 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3476 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3477 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3478 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3479 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3480 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3481 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3482 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3483 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3484 static void push_decl_scope PARAMS ((tree));
3485 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3486 static void pop_decl_scope PARAMS ((void));
3487 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3488 dw_die_ref));
3489 static const char *type_tag PARAMS ((tree));
3490 static tree member_declared_type PARAMS ((tree));
3491 #if 0
3492 static const char *decl_start_label PARAMS ((tree));
3493 #endif
3494 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3495 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3496 #if 0
3497 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3498 #endif
3499 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3500 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3501 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3502 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3503 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3504 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3505 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3506 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3507 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3508 static void gen_label_die PARAMS ((tree, dw_die_ref));
3509 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3510 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3511 static void gen_field_die PARAMS ((tree, dw_die_ref));
3512 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3513 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3514 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3515 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3516 static void gen_member_die PARAMS ((tree, dw_die_ref));
3517 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3518 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3519 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3520 static void gen_type_die PARAMS ((tree, dw_die_ref));
3521 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3522 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3523 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3524 static int is_redundant_typedef PARAMS ((tree));
3525 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3526 static unsigned lookup_filename PARAMS ((struct file_table *,
3527 const char *));
3528 static void init_file_table PARAMS ((struct file_table *));
3529 static void add_incomplete_type PARAMS ((tree));
3530 static void retry_incomplete_types PARAMS ((void));
3531 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3532 static void gen_abstract_function PARAMS ((tree));
3533 static rtx save_rtx PARAMS ((rtx));
3534 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3536 /* Section names used to hold DWARF debugging information. */
3537 #ifndef DEBUG_INFO_SECTION
3538 #define DEBUG_INFO_SECTION ".debug_info"
3539 #endif
3540 #ifndef ABBREV_SECTION
3541 #define ABBREV_SECTION ".debug_abbrev"
3542 #endif
3543 #ifndef ARANGES_SECTION
3544 #define ARANGES_SECTION ".debug_aranges"
3545 #endif
3546 #ifndef DW_MACINFO_SECTION
3547 #define DW_MACINFO_SECTION ".debug_macinfo"
3548 #endif
3549 #ifndef DEBUG_LINE_SECTION
3550 #define DEBUG_LINE_SECTION ".debug_line"
3551 #endif
3552 #ifndef LOC_SECTION
3553 #define LOC_SECTION ".debug_loc"
3554 #endif
3555 #ifndef PUBNAMES_SECTION
3556 #define PUBNAMES_SECTION ".debug_pubnames"
3557 #endif
3558 #ifndef STR_SECTION
3559 #define STR_SECTION ".debug_str"
3560 #endif
3562 /* Standard ELF section names for compiled code and data. */
3563 #ifndef TEXT_SECTION
3564 #define TEXT_SECTION ".text"
3565 #endif
3566 #ifndef DATA_SECTION
3567 #define DATA_SECTION ".data"
3568 #endif
3569 #ifndef BSS_SECTION
3570 #define BSS_SECTION ".bss"
3571 #endif
3573 /* Labels we insert at beginning sections we can reference instead of
3574 the section names themselves. */
3576 #ifndef TEXT_SECTION_LABEL
3577 #define TEXT_SECTION_LABEL "Ltext"
3578 #endif
3579 #ifndef DEBUG_LINE_SECTION_LABEL
3580 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3581 #endif
3582 #ifndef DEBUG_INFO_SECTION_LABEL
3583 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3584 #endif
3585 #ifndef ABBREV_SECTION_LABEL
3586 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3587 #endif
3589 /* Definitions of defaults for formats and names of various special
3590 (artificial) labels which may be generated within this file (when the -g
3591 options is used and DWARF_DEBUGGING_INFO is in effect.
3592 If necessary, these may be overridden from within the tm.h file, but
3593 typically, overriding these defaults is unnecessary. */
3595 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3596 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3597 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3598 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3599 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3601 #ifndef TEXT_END_LABEL
3602 #define TEXT_END_LABEL "Letext"
3603 #endif
3604 #ifndef DATA_END_LABEL
3605 #define DATA_END_LABEL "Ledata"
3606 #endif
3607 #ifndef BSS_END_LABEL
3608 #define BSS_END_LABEL "Lebss"
3609 #endif
3610 #ifndef BLOCK_BEGIN_LABEL
3611 #define BLOCK_BEGIN_LABEL "LBB"
3612 #endif
3613 #ifndef BLOCK_END_LABEL
3614 #define BLOCK_END_LABEL "LBE"
3615 #endif
3616 #ifndef BODY_BEGIN_LABEL
3617 #define BODY_BEGIN_LABEL "Lbb"
3618 #endif
3619 #ifndef BODY_END_LABEL
3620 #define BODY_END_LABEL "Lbe"
3621 #endif
3622 #ifndef LINE_CODE_LABEL
3623 #define LINE_CODE_LABEL "LM"
3624 #endif
3625 #ifndef SEPARATE_LINE_CODE_LABEL
3626 #define SEPARATE_LINE_CODE_LABEL "LSM"
3627 #endif
3629 /* We allow a language front-end to designate a function that is to be
3630 called to "demangle" any name before it it put into a DIE. */
3632 static const char *(*demangle_name_func) PARAMS ((const char *));
3634 void
3635 dwarf2out_set_demangle_name_func (func)
3636 const char *(*func) PARAMS ((const char *));
3638 demangle_name_func = func;
3641 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3642 that means adding it to used_rtx_varray. If not, that means making
3643 a copy on the permanent_obstack. */
3645 static rtx
3646 save_rtx (orig)
3647 register rtx orig;
3649 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3651 return orig;
3654 /* Test if rtl node points to a pseudo register. */
3656 static inline int
3657 is_pseudo_reg (rtl)
3658 register rtx rtl;
3660 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3661 || (GET_CODE (rtl) == SUBREG
3662 && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER));
3665 /* Return a reference to a type, with its const and volatile qualifiers
3666 removed. */
3668 static inline tree
3669 type_main_variant (type)
3670 register tree type;
3672 type = TYPE_MAIN_VARIANT (type);
3674 /* There really should be only one main variant among any group of variants
3675 of a given type (and all of the MAIN_VARIANT values for all members of
3676 the group should point to that one type) but sometimes the C front-end
3677 messes this up for array types, so we work around that bug here. */
3679 if (TREE_CODE (type) == ARRAY_TYPE)
3680 while (type != TYPE_MAIN_VARIANT (type))
3681 type = TYPE_MAIN_VARIANT (type);
3683 return type;
3686 /* Return non-zero if the given type node represents a tagged type. */
3688 static inline int
3689 is_tagged_type (type)
3690 register tree type;
3692 register enum tree_code code = TREE_CODE (type);
3694 return (code == RECORD_TYPE || code == UNION_TYPE
3695 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3698 /* Convert a DIE tag into its string name. */
3700 static const char *
3701 dwarf_tag_name (tag)
3702 register unsigned tag;
3704 switch (tag)
3706 case DW_TAG_padding:
3707 return "DW_TAG_padding";
3708 case DW_TAG_array_type:
3709 return "DW_TAG_array_type";
3710 case DW_TAG_class_type:
3711 return "DW_TAG_class_type";
3712 case DW_TAG_entry_point:
3713 return "DW_TAG_entry_point";
3714 case DW_TAG_enumeration_type:
3715 return "DW_TAG_enumeration_type";
3716 case DW_TAG_formal_parameter:
3717 return "DW_TAG_formal_parameter";
3718 case DW_TAG_imported_declaration:
3719 return "DW_TAG_imported_declaration";
3720 case DW_TAG_label:
3721 return "DW_TAG_label";
3722 case DW_TAG_lexical_block:
3723 return "DW_TAG_lexical_block";
3724 case DW_TAG_member:
3725 return "DW_TAG_member";
3726 case DW_TAG_pointer_type:
3727 return "DW_TAG_pointer_type";
3728 case DW_TAG_reference_type:
3729 return "DW_TAG_reference_type";
3730 case DW_TAG_compile_unit:
3731 return "DW_TAG_compile_unit";
3732 case DW_TAG_string_type:
3733 return "DW_TAG_string_type";
3734 case DW_TAG_structure_type:
3735 return "DW_TAG_structure_type";
3736 case DW_TAG_subroutine_type:
3737 return "DW_TAG_subroutine_type";
3738 case DW_TAG_typedef:
3739 return "DW_TAG_typedef";
3740 case DW_TAG_union_type:
3741 return "DW_TAG_union_type";
3742 case DW_TAG_unspecified_parameters:
3743 return "DW_TAG_unspecified_parameters";
3744 case DW_TAG_variant:
3745 return "DW_TAG_variant";
3746 case DW_TAG_common_block:
3747 return "DW_TAG_common_block";
3748 case DW_TAG_common_inclusion:
3749 return "DW_TAG_common_inclusion";
3750 case DW_TAG_inheritance:
3751 return "DW_TAG_inheritance";
3752 case DW_TAG_inlined_subroutine:
3753 return "DW_TAG_inlined_subroutine";
3754 case DW_TAG_module:
3755 return "DW_TAG_module";
3756 case DW_TAG_ptr_to_member_type:
3757 return "DW_TAG_ptr_to_member_type";
3758 case DW_TAG_set_type:
3759 return "DW_TAG_set_type";
3760 case DW_TAG_subrange_type:
3761 return "DW_TAG_subrange_type";
3762 case DW_TAG_with_stmt:
3763 return "DW_TAG_with_stmt";
3764 case DW_TAG_access_declaration:
3765 return "DW_TAG_access_declaration";
3766 case DW_TAG_base_type:
3767 return "DW_TAG_base_type";
3768 case DW_TAG_catch_block:
3769 return "DW_TAG_catch_block";
3770 case DW_TAG_const_type:
3771 return "DW_TAG_const_type";
3772 case DW_TAG_constant:
3773 return "DW_TAG_constant";
3774 case DW_TAG_enumerator:
3775 return "DW_TAG_enumerator";
3776 case DW_TAG_file_type:
3777 return "DW_TAG_file_type";
3778 case DW_TAG_friend:
3779 return "DW_TAG_friend";
3780 case DW_TAG_namelist:
3781 return "DW_TAG_namelist";
3782 case DW_TAG_namelist_item:
3783 return "DW_TAG_namelist_item";
3784 case DW_TAG_packed_type:
3785 return "DW_TAG_packed_type";
3786 case DW_TAG_subprogram:
3787 return "DW_TAG_subprogram";
3788 case DW_TAG_template_type_param:
3789 return "DW_TAG_template_type_param";
3790 case DW_TAG_template_value_param:
3791 return "DW_TAG_template_value_param";
3792 case DW_TAG_thrown_type:
3793 return "DW_TAG_thrown_type";
3794 case DW_TAG_try_block:
3795 return "DW_TAG_try_block";
3796 case DW_TAG_variant_part:
3797 return "DW_TAG_variant_part";
3798 case DW_TAG_variable:
3799 return "DW_TAG_variable";
3800 case DW_TAG_volatile_type:
3801 return "DW_TAG_volatile_type";
3802 case DW_TAG_MIPS_loop:
3803 return "DW_TAG_MIPS_loop";
3804 case DW_TAG_format_label:
3805 return "DW_TAG_format_label";
3806 case DW_TAG_function_template:
3807 return "DW_TAG_function_template";
3808 case DW_TAG_class_template:
3809 return "DW_TAG_class_template";
3810 case DW_TAG_GNU_BINCL:
3811 return "DW_TAG_GNU_BINCL";
3812 case DW_TAG_GNU_EINCL:
3813 return "DW_TAG_GNU_EINCL";
3814 default:
3815 return "DW_TAG_<unknown>";
3819 /* Convert a DWARF attribute code into its string name. */
3821 static const char *
3822 dwarf_attr_name (attr)
3823 register unsigned attr;
3825 switch (attr)
3827 case DW_AT_sibling:
3828 return "DW_AT_sibling";
3829 case DW_AT_location:
3830 return "DW_AT_location";
3831 case DW_AT_name:
3832 return "DW_AT_name";
3833 case DW_AT_ordering:
3834 return "DW_AT_ordering";
3835 case DW_AT_subscr_data:
3836 return "DW_AT_subscr_data";
3837 case DW_AT_byte_size:
3838 return "DW_AT_byte_size";
3839 case DW_AT_bit_offset:
3840 return "DW_AT_bit_offset";
3841 case DW_AT_bit_size:
3842 return "DW_AT_bit_size";
3843 case DW_AT_element_list:
3844 return "DW_AT_element_list";
3845 case DW_AT_stmt_list:
3846 return "DW_AT_stmt_list";
3847 case DW_AT_low_pc:
3848 return "DW_AT_low_pc";
3849 case DW_AT_high_pc:
3850 return "DW_AT_high_pc";
3851 case DW_AT_language:
3852 return "DW_AT_language";
3853 case DW_AT_member:
3854 return "DW_AT_member";
3855 case DW_AT_discr:
3856 return "DW_AT_discr";
3857 case DW_AT_discr_value:
3858 return "DW_AT_discr_value";
3859 case DW_AT_visibility:
3860 return "DW_AT_visibility";
3861 case DW_AT_import:
3862 return "DW_AT_import";
3863 case DW_AT_string_length:
3864 return "DW_AT_string_length";
3865 case DW_AT_common_reference:
3866 return "DW_AT_common_reference";
3867 case DW_AT_comp_dir:
3868 return "DW_AT_comp_dir";
3869 case DW_AT_const_value:
3870 return "DW_AT_const_value";
3871 case DW_AT_containing_type:
3872 return "DW_AT_containing_type";
3873 case DW_AT_default_value:
3874 return "DW_AT_default_value";
3875 case DW_AT_inline:
3876 return "DW_AT_inline";
3877 case DW_AT_is_optional:
3878 return "DW_AT_is_optional";
3879 case DW_AT_lower_bound:
3880 return "DW_AT_lower_bound";
3881 case DW_AT_producer:
3882 return "DW_AT_producer";
3883 case DW_AT_prototyped:
3884 return "DW_AT_prototyped";
3885 case DW_AT_return_addr:
3886 return "DW_AT_return_addr";
3887 case DW_AT_start_scope:
3888 return "DW_AT_start_scope";
3889 case DW_AT_stride_size:
3890 return "DW_AT_stride_size";
3891 case DW_AT_upper_bound:
3892 return "DW_AT_upper_bound";
3893 case DW_AT_abstract_origin:
3894 return "DW_AT_abstract_origin";
3895 case DW_AT_accessibility:
3896 return "DW_AT_accessibility";
3897 case DW_AT_address_class:
3898 return "DW_AT_address_class";
3899 case DW_AT_artificial:
3900 return "DW_AT_artificial";
3901 case DW_AT_base_types:
3902 return "DW_AT_base_types";
3903 case DW_AT_calling_convention:
3904 return "DW_AT_calling_convention";
3905 case DW_AT_count:
3906 return "DW_AT_count";
3907 case DW_AT_data_member_location:
3908 return "DW_AT_data_member_location";
3909 case DW_AT_decl_column:
3910 return "DW_AT_decl_column";
3911 case DW_AT_decl_file:
3912 return "DW_AT_decl_file";
3913 case DW_AT_decl_line:
3914 return "DW_AT_decl_line";
3915 case DW_AT_declaration:
3916 return "DW_AT_declaration";
3917 case DW_AT_discr_list:
3918 return "DW_AT_discr_list";
3919 case DW_AT_encoding:
3920 return "DW_AT_encoding";
3921 case DW_AT_external:
3922 return "DW_AT_external";
3923 case DW_AT_frame_base:
3924 return "DW_AT_frame_base";
3925 case DW_AT_friend:
3926 return "DW_AT_friend";
3927 case DW_AT_identifier_case:
3928 return "DW_AT_identifier_case";
3929 case DW_AT_macro_info:
3930 return "DW_AT_macro_info";
3931 case DW_AT_namelist_items:
3932 return "DW_AT_namelist_items";
3933 case DW_AT_priority:
3934 return "DW_AT_priority";
3935 case DW_AT_segment:
3936 return "DW_AT_segment";
3937 case DW_AT_specification:
3938 return "DW_AT_specification";
3939 case DW_AT_static_link:
3940 return "DW_AT_static_link";
3941 case DW_AT_type:
3942 return "DW_AT_type";
3943 case DW_AT_use_location:
3944 return "DW_AT_use_location";
3945 case DW_AT_variable_parameter:
3946 return "DW_AT_variable_parameter";
3947 case DW_AT_virtuality:
3948 return "DW_AT_virtuality";
3949 case DW_AT_vtable_elem_location:
3950 return "DW_AT_vtable_elem_location";
3952 case DW_AT_MIPS_fde:
3953 return "DW_AT_MIPS_fde";
3954 case DW_AT_MIPS_loop_begin:
3955 return "DW_AT_MIPS_loop_begin";
3956 case DW_AT_MIPS_tail_loop_begin:
3957 return "DW_AT_MIPS_tail_loop_begin";
3958 case DW_AT_MIPS_epilog_begin:
3959 return "DW_AT_MIPS_epilog_begin";
3960 case DW_AT_MIPS_loop_unroll_factor:
3961 return "DW_AT_MIPS_loop_unroll_factor";
3962 case DW_AT_MIPS_software_pipeline_depth:
3963 return "DW_AT_MIPS_software_pipeline_depth";
3964 case DW_AT_MIPS_linkage_name:
3965 return "DW_AT_MIPS_linkage_name";
3966 case DW_AT_MIPS_stride:
3967 return "DW_AT_MIPS_stride";
3968 case DW_AT_MIPS_abstract_name:
3969 return "DW_AT_MIPS_abstract_name";
3970 case DW_AT_MIPS_clone_origin:
3971 return "DW_AT_MIPS_clone_origin";
3972 case DW_AT_MIPS_has_inlines:
3973 return "DW_AT_MIPS_has_inlines";
3975 case DW_AT_sf_names:
3976 return "DW_AT_sf_names";
3977 case DW_AT_src_info:
3978 return "DW_AT_src_info";
3979 case DW_AT_mac_info:
3980 return "DW_AT_mac_info";
3981 case DW_AT_src_coords:
3982 return "DW_AT_src_coords";
3983 case DW_AT_body_begin:
3984 return "DW_AT_body_begin";
3985 case DW_AT_body_end:
3986 return "DW_AT_body_end";
3987 default:
3988 return "DW_AT_<unknown>";
3992 /* Convert a DWARF value form code into its string name. */
3994 static const char *
3995 dwarf_form_name (form)
3996 register unsigned form;
3998 switch (form)
4000 case DW_FORM_addr:
4001 return "DW_FORM_addr";
4002 case DW_FORM_block2:
4003 return "DW_FORM_block2";
4004 case DW_FORM_block4:
4005 return "DW_FORM_block4";
4006 case DW_FORM_data2:
4007 return "DW_FORM_data2";
4008 case DW_FORM_data4:
4009 return "DW_FORM_data4";
4010 case DW_FORM_data8:
4011 return "DW_FORM_data8";
4012 case DW_FORM_string:
4013 return "DW_FORM_string";
4014 case DW_FORM_block:
4015 return "DW_FORM_block";
4016 case DW_FORM_block1:
4017 return "DW_FORM_block1";
4018 case DW_FORM_data1:
4019 return "DW_FORM_data1";
4020 case DW_FORM_flag:
4021 return "DW_FORM_flag";
4022 case DW_FORM_sdata:
4023 return "DW_FORM_sdata";
4024 case DW_FORM_strp:
4025 return "DW_FORM_strp";
4026 case DW_FORM_udata:
4027 return "DW_FORM_udata";
4028 case DW_FORM_ref_addr:
4029 return "DW_FORM_ref_addr";
4030 case DW_FORM_ref1:
4031 return "DW_FORM_ref1";
4032 case DW_FORM_ref2:
4033 return "DW_FORM_ref2";
4034 case DW_FORM_ref4:
4035 return "DW_FORM_ref4";
4036 case DW_FORM_ref8:
4037 return "DW_FORM_ref8";
4038 case DW_FORM_ref_udata:
4039 return "DW_FORM_ref_udata";
4040 case DW_FORM_indirect:
4041 return "DW_FORM_indirect";
4042 default:
4043 return "DW_FORM_<unknown>";
4047 /* Convert a DWARF type code into its string name. */
4049 #if 0
4050 static const char *
4051 dwarf_type_encoding_name (enc)
4052 register unsigned enc;
4054 switch (enc)
4056 case DW_ATE_address:
4057 return "DW_ATE_address";
4058 case DW_ATE_boolean:
4059 return "DW_ATE_boolean";
4060 case DW_ATE_complex_float:
4061 return "DW_ATE_complex_float";
4062 case DW_ATE_float:
4063 return "DW_ATE_float";
4064 case DW_ATE_signed:
4065 return "DW_ATE_signed";
4066 case DW_ATE_signed_char:
4067 return "DW_ATE_signed_char";
4068 case DW_ATE_unsigned:
4069 return "DW_ATE_unsigned";
4070 case DW_ATE_unsigned_char:
4071 return "DW_ATE_unsigned_char";
4072 default:
4073 return "DW_ATE_<unknown>";
4076 #endif
4078 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4079 instance of an inlined instance of a decl which is local to an inline
4080 function, so we have to trace all of the way back through the origin chain
4081 to find out what sort of node actually served as the original seed for the
4082 given block. */
4084 static tree
4085 decl_ultimate_origin (decl)
4086 register tree decl;
4088 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4089 nodes in the function to point to themselves; ignore that if
4090 we're trying to output the abstract instance of this function. */
4091 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4092 return NULL_TREE;
4094 #ifdef ENABLE_CHECKING
4095 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4096 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4097 most distant ancestor, this should never happen. */
4098 abort ();
4099 #endif
4101 return DECL_ABSTRACT_ORIGIN (decl);
4104 /* Determine the "ultimate origin" of a block. The block may be an inlined
4105 instance of an inlined instance of a block which is local to an inline
4106 function, so we have to trace all of the way back through the origin chain
4107 to find out what sort of node actually served as the original seed for the
4108 given block. */
4110 static tree
4111 block_ultimate_origin (block)
4112 register tree block;
4114 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4116 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4117 nodes in the function to point to themselves; ignore that if
4118 we're trying to output the abstract instance of this function. */
4119 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4120 return NULL_TREE;
4122 if (immediate_origin == NULL_TREE)
4123 return NULL_TREE;
4124 else
4126 register tree ret_val;
4127 register tree lookahead = immediate_origin;
4131 ret_val = lookahead;
4132 lookahead = (TREE_CODE (ret_val) == BLOCK)
4133 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4134 : NULL;
4136 while (lookahead != NULL && lookahead != ret_val);
4138 return ret_val;
4142 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4143 of a virtual function may refer to a base class, so we check the 'this'
4144 parameter. */
4146 static tree
4147 decl_class_context (decl)
4148 tree decl;
4150 tree context = NULL_TREE;
4152 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4153 context = DECL_CONTEXT (decl);
4154 else
4155 context = TYPE_MAIN_VARIANT
4156 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4158 if (context && !TYPE_P (context))
4159 context = NULL_TREE;
4161 return context;
4164 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4165 addition order, and correct that in reverse_all_dies. */
4167 static inline void
4168 add_dwarf_attr (die, attr)
4169 register dw_die_ref die;
4170 register dw_attr_ref attr;
4172 if (die != NULL && attr != NULL)
4174 attr->dw_attr_next = die->die_attr;
4175 die->die_attr = attr;
4179 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4180 static inline dw_val_class
4181 AT_class (a)
4182 dw_attr_ref a;
4184 return a->dw_attr_val.val_class;
4187 /* Add a flag value attribute to a DIE. */
4189 static inline void
4190 add_AT_flag (die, attr_kind, flag)
4191 register dw_die_ref die;
4192 register enum dwarf_attribute attr_kind;
4193 register unsigned flag;
4195 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4197 attr->dw_attr_next = NULL;
4198 attr->dw_attr = attr_kind;
4199 attr->dw_attr_val.val_class = dw_val_class_flag;
4200 attr->dw_attr_val.v.val_flag = flag;
4201 add_dwarf_attr (die, attr);
4204 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4205 static inline unsigned
4206 AT_flag (a)
4207 register dw_attr_ref a;
4209 if (a && AT_class (a) == dw_val_class_flag)
4210 return a->dw_attr_val.v.val_flag;
4212 abort ();
4215 /* Add a signed integer attribute value to a DIE. */
4217 static inline void
4218 add_AT_int (die, attr_kind, int_val)
4219 register dw_die_ref die;
4220 register enum dwarf_attribute attr_kind;
4221 register long int int_val;
4223 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4225 attr->dw_attr_next = NULL;
4226 attr->dw_attr = attr_kind;
4227 attr->dw_attr_val.val_class = dw_val_class_const;
4228 attr->dw_attr_val.v.val_int = int_val;
4229 add_dwarf_attr (die, attr);
4232 static inline long int AT_int PARAMS ((dw_attr_ref));
4233 static inline long int
4234 AT_int (a)
4235 register dw_attr_ref a;
4237 if (a && AT_class (a) == dw_val_class_const)
4238 return a->dw_attr_val.v.val_int;
4240 abort ();
4243 /* Add an unsigned integer attribute value to a DIE. */
4245 static inline void
4246 add_AT_unsigned (die, attr_kind, unsigned_val)
4247 register dw_die_ref die;
4248 register enum dwarf_attribute attr_kind;
4249 register unsigned long unsigned_val;
4251 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4253 attr->dw_attr_next = NULL;
4254 attr->dw_attr = attr_kind;
4255 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4256 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4257 add_dwarf_attr (die, attr);
4260 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4261 static inline unsigned long
4262 AT_unsigned (a)
4263 register dw_attr_ref a;
4265 if (a && AT_class (a) == dw_val_class_unsigned_const)
4266 return a->dw_attr_val.v.val_unsigned;
4268 abort ();
4271 /* Add an unsigned double integer attribute value to a DIE. */
4273 static inline void
4274 add_AT_long_long (die, attr_kind, val_hi, val_low)
4275 register dw_die_ref die;
4276 register enum dwarf_attribute attr_kind;
4277 register unsigned long val_hi;
4278 register unsigned long val_low;
4280 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4282 attr->dw_attr_next = NULL;
4283 attr->dw_attr = attr_kind;
4284 attr->dw_attr_val.val_class = dw_val_class_long_long;
4285 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4286 attr->dw_attr_val.v.val_long_long.low = val_low;
4287 add_dwarf_attr (die, attr);
4290 /* Add a floating point attribute value to a DIE and return it. */
4292 static inline void
4293 add_AT_float (die, attr_kind, length, array)
4294 register dw_die_ref die;
4295 register enum dwarf_attribute attr_kind;
4296 register unsigned length;
4297 register long *array;
4299 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4301 attr->dw_attr_next = NULL;
4302 attr->dw_attr = attr_kind;
4303 attr->dw_attr_val.val_class = dw_val_class_float;
4304 attr->dw_attr_val.v.val_float.length = length;
4305 attr->dw_attr_val.v.val_float.array = array;
4306 add_dwarf_attr (die, attr);
4309 /* Add a string attribute value to a DIE. */
4311 static inline void
4312 add_AT_string (die, attr_kind, str)
4313 register dw_die_ref die;
4314 register enum dwarf_attribute attr_kind;
4315 register const char *str;
4317 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4319 attr->dw_attr_next = NULL;
4320 attr->dw_attr = attr_kind;
4321 attr->dw_attr_val.val_class = dw_val_class_str;
4322 attr->dw_attr_val.v.val_str = xstrdup (str);
4323 add_dwarf_attr (die, attr);
4326 static inline const char *AT_string PARAMS ((dw_attr_ref));
4327 static inline const char *
4328 AT_string (a)
4329 register dw_attr_ref a;
4331 if (a && AT_class (a) == dw_val_class_str)
4332 return a->dw_attr_val.v.val_str;
4334 abort ();
4337 /* Add a DIE reference attribute value to a DIE. */
4339 static inline void
4340 add_AT_die_ref (die, attr_kind, targ_die)
4341 register dw_die_ref die;
4342 register enum dwarf_attribute attr_kind;
4343 register dw_die_ref targ_die;
4345 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4347 attr->dw_attr_next = NULL;
4348 attr->dw_attr = attr_kind;
4349 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4350 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4351 attr->dw_attr_val.v.val_die_ref.external = 0;
4352 add_dwarf_attr (die, attr);
4355 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4356 static inline dw_die_ref
4357 AT_ref (a)
4358 register dw_attr_ref a;
4360 if (a && AT_class (a) == dw_val_class_die_ref)
4361 return a->dw_attr_val.v.val_die_ref.die;
4363 abort ();
4366 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4367 static inline int
4368 AT_ref_external (a)
4369 register dw_attr_ref a;
4371 if (a && AT_class (a) == dw_val_class_die_ref)
4372 return a->dw_attr_val.v.val_die_ref.external;
4374 return 0;
4377 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4378 static inline void
4379 set_AT_ref_external (a, i)
4380 register dw_attr_ref a;
4381 int i;
4383 if (a && AT_class (a) == dw_val_class_die_ref)
4384 a->dw_attr_val.v.val_die_ref.external = i;
4385 else
4386 abort ();
4389 /* Add an FDE reference attribute value to a DIE. */
4391 static inline void
4392 add_AT_fde_ref (die, attr_kind, targ_fde)
4393 register dw_die_ref die;
4394 register enum dwarf_attribute attr_kind;
4395 register unsigned targ_fde;
4397 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4399 attr->dw_attr_next = NULL;
4400 attr->dw_attr = attr_kind;
4401 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4402 attr->dw_attr_val.v.val_fde_index = targ_fde;
4403 add_dwarf_attr (die, attr);
4406 /* Add a location description attribute value to a DIE. */
4408 static inline void
4409 add_AT_loc (die, attr_kind, loc)
4410 register dw_die_ref die;
4411 register enum dwarf_attribute attr_kind;
4412 register dw_loc_descr_ref loc;
4414 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4416 attr->dw_attr_next = NULL;
4417 attr->dw_attr = attr_kind;
4418 attr->dw_attr_val.val_class = dw_val_class_loc;
4419 attr->dw_attr_val.v.val_loc = loc;
4420 add_dwarf_attr (die, attr);
4423 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4424 static inline dw_loc_descr_ref
4425 AT_loc (a)
4426 register dw_attr_ref a;
4428 if (a && AT_class (a) == dw_val_class_loc)
4429 return a->dw_attr_val.v.val_loc;
4431 abort ();
4434 /* Add an address constant attribute value to a DIE. */
4436 static inline void
4437 add_AT_addr (die, attr_kind, addr)
4438 register dw_die_ref die;
4439 register enum dwarf_attribute attr_kind;
4440 rtx addr;
4442 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4444 attr->dw_attr_next = NULL;
4445 attr->dw_attr = attr_kind;
4446 attr->dw_attr_val.val_class = dw_val_class_addr;
4447 attr->dw_attr_val.v.val_addr = addr;
4448 add_dwarf_attr (die, attr);
4451 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4452 static inline rtx
4453 AT_addr (a)
4454 register dw_attr_ref a;
4456 if (a && AT_class (a) == dw_val_class_addr)
4457 return a->dw_attr_val.v.val_addr;
4459 abort ();
4462 /* Add a label identifier attribute value to a DIE. */
4464 static inline void
4465 add_AT_lbl_id (die, attr_kind, lbl_id)
4466 register dw_die_ref die;
4467 register enum dwarf_attribute attr_kind;
4468 register const char *lbl_id;
4470 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4472 attr->dw_attr_next = NULL;
4473 attr->dw_attr = attr_kind;
4474 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4475 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4476 add_dwarf_attr (die, attr);
4479 /* Add a section offset attribute value to a DIE. */
4481 static inline void
4482 add_AT_lbl_offset (die, attr_kind, label)
4483 register dw_die_ref die;
4484 register enum dwarf_attribute attr_kind;
4485 register const char *label;
4487 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4489 attr->dw_attr_next = NULL;
4490 attr->dw_attr = attr_kind;
4491 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4492 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4493 add_dwarf_attr (die, attr);
4496 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4497 static inline const char *
4498 AT_lbl (a)
4499 register dw_attr_ref a;
4501 if (a && (AT_class (a) == dw_val_class_lbl_id
4502 || AT_class (a) == dw_val_class_lbl_offset))
4503 return a->dw_attr_val.v.val_lbl_id;
4505 abort ();
4508 /* Get the attribute of type attr_kind. */
4510 static inline dw_attr_ref
4511 get_AT (die, attr_kind)
4512 register dw_die_ref die;
4513 register enum dwarf_attribute attr_kind;
4515 register dw_attr_ref a;
4516 register dw_die_ref spec = NULL;
4518 if (die != NULL)
4520 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4522 if (a->dw_attr == attr_kind)
4523 return a;
4525 if (a->dw_attr == DW_AT_specification
4526 || a->dw_attr == DW_AT_abstract_origin)
4527 spec = AT_ref (a);
4530 if (spec)
4531 return get_AT (spec, attr_kind);
4534 return NULL;
4537 /* Return the "low pc" attribute value, typically associated with
4538 a subprogram DIE. Return null if the "low 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_low_pc (die)
4544 register dw_die_ref die;
4546 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4547 return a ? AT_lbl (a) : NULL;
4550 /* Return the "high pc" attribute value, typically associated with
4551 a subprogram DIE. Return null if the "high pc" attribute is
4552 either not prsent, or if it cannot be represented as an
4553 assembler label identifier. */
4555 static inline const char *
4556 get_AT_hi_pc (die)
4557 register dw_die_ref die;
4559 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4560 return a ? AT_lbl (a) : NULL;
4563 /* Return the value of the string attribute designated by ATTR_KIND, or
4564 NULL if it is not present. */
4566 static inline const char *
4567 get_AT_string (die, attr_kind)
4568 register dw_die_ref die;
4569 register enum dwarf_attribute attr_kind;
4571 register dw_attr_ref a = get_AT (die, attr_kind);
4572 return a ? AT_string (a) : NULL;
4575 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4576 if it is not present. */
4578 static inline int
4579 get_AT_flag (die, attr_kind)
4580 register dw_die_ref die;
4581 register enum dwarf_attribute attr_kind;
4583 register dw_attr_ref a = get_AT (die, attr_kind);
4584 return a ? AT_flag (a) : 0;
4587 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4588 if it is not present. */
4590 static inline unsigned
4591 get_AT_unsigned (die, attr_kind)
4592 register dw_die_ref die;
4593 register enum dwarf_attribute attr_kind;
4595 register dw_attr_ref a = get_AT (die, attr_kind);
4596 return a ? AT_unsigned (a) : 0;
4599 static inline dw_die_ref
4600 get_AT_ref (die, attr_kind)
4601 dw_die_ref die;
4602 register enum dwarf_attribute attr_kind;
4604 register dw_attr_ref a = get_AT (die, attr_kind);
4605 return a ? AT_ref (a) : NULL;
4608 static inline int
4609 is_c_family ()
4611 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4613 return (lang == DW_LANG_C || lang == DW_LANG_C89
4614 || lang == DW_LANG_C_plus_plus);
4617 static inline int
4618 is_fortran ()
4620 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4622 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4625 static inline int
4626 is_java ()
4628 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4630 return (lang == DW_LANG_Java);
4633 /* Free up the memory used by A. */
4635 static inline void free_AT PARAMS ((dw_attr_ref));
4636 static inline void
4637 free_AT (a)
4638 dw_attr_ref a;
4640 switch (AT_class (a))
4642 case dw_val_class_str:
4643 case dw_val_class_lbl_id:
4644 case dw_val_class_lbl_offset:
4645 free (a->dw_attr_val.v.val_str);
4646 break;
4648 case dw_val_class_float:
4649 free (a->dw_attr_val.v.val_float.array);
4650 break;
4652 default:
4653 break;
4656 free (a);
4659 /* Remove the specified attribute if present. */
4661 static void
4662 remove_AT (die, attr_kind)
4663 register dw_die_ref die;
4664 register enum dwarf_attribute attr_kind;
4666 register dw_attr_ref *p;
4667 register dw_attr_ref removed = NULL;
4669 if (die != NULL)
4671 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4672 if ((*p)->dw_attr == attr_kind)
4674 removed = *p;
4675 *p = (*p)->dw_attr_next;
4676 break;
4679 if (removed != 0)
4680 free_AT (removed);
4684 /* Free up the memory used by DIE. */
4686 static inline void free_die PARAMS ((dw_die_ref));
4687 static inline void
4688 free_die (die)
4689 dw_die_ref die;
4691 remove_children (die);
4692 free (die);
4695 /* Discard the children of this DIE. */
4697 static void
4698 remove_children (die)
4699 register dw_die_ref die;
4701 register dw_die_ref child_die = die->die_child;
4703 die->die_child = NULL;
4705 while (child_die != NULL)
4707 register dw_die_ref tmp_die = child_die;
4708 register dw_attr_ref a;
4710 child_die = child_die->die_sib;
4712 for (a = tmp_die->die_attr; a != NULL;)
4714 register dw_attr_ref tmp_a = a;
4716 a = a->dw_attr_next;
4717 free_AT (tmp_a);
4720 free_die (tmp_die);
4724 /* Add a child DIE below its parent. We build the lists up in reverse
4725 addition order, and correct that in reverse_all_dies. */
4727 static inline void
4728 add_child_die (die, child_die)
4729 register dw_die_ref die;
4730 register dw_die_ref child_die;
4732 if (die != NULL && child_die != NULL)
4734 if (die == child_die)
4735 abort ();
4736 child_die->die_parent = die;
4737 child_die->die_sib = die->die_child;
4738 die->die_child = child_die;
4742 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4743 is the specification, to the front of PARENT's list of children. */
4745 static void
4746 splice_child_die (parent, child)
4747 dw_die_ref parent, child;
4749 dw_die_ref *p;
4751 /* We want the declaration DIE from inside the class, not the
4752 specification DIE at toplevel. */
4753 if (child->die_parent != parent)
4755 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4756 if (tmp)
4757 child = tmp;
4760 if (child->die_parent != parent
4761 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4762 abort ();
4764 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4765 if (*p == child)
4767 *p = child->die_sib;
4768 break;
4771 child->die_sib = parent->die_child;
4772 parent->die_child = child;
4775 /* Return a pointer to a newly created DIE node. */
4777 static inline dw_die_ref
4778 new_die (tag_value, parent_die)
4779 register enum dwarf_tag tag_value;
4780 register dw_die_ref parent_die;
4782 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
4784 die->die_tag = tag_value;
4785 die->die_abbrev = 0;
4786 die->die_offset = 0;
4787 die->die_child = NULL;
4788 die->die_parent = NULL;
4789 die->die_sib = NULL;
4790 die->die_attr = NULL;
4791 die->die_symbol = NULL;
4793 if (parent_die != NULL)
4794 add_child_die (parent_die, die);
4795 else
4797 limbo_die_node *limbo_node;
4799 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4800 limbo_node->die = die;
4801 limbo_node->next = limbo_die_list;
4802 limbo_die_list = limbo_node;
4805 return die;
4808 /* Return the DIE associated with the given type specifier. */
4810 static inline dw_die_ref
4811 lookup_type_die (type)
4812 register tree type;
4814 if (TREE_CODE (type) == VECTOR_TYPE)
4815 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4816 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4819 /* Equate a DIE to a given type specifier. */
4821 static inline void
4822 equate_type_number_to_die (type, type_die)
4823 register tree type;
4824 register dw_die_ref type_die;
4826 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4829 /* Return the DIE associated with a given declaration. */
4831 static inline dw_die_ref
4832 lookup_decl_die (decl)
4833 register tree decl;
4835 register unsigned decl_id = DECL_UID (decl);
4837 return (decl_id < decl_die_table_in_use
4838 ? decl_die_table[decl_id] : NULL);
4841 /* Equate a DIE to a particular declaration. */
4843 static void
4844 equate_decl_number_to_die (decl, decl_die)
4845 register tree decl;
4846 register dw_die_ref decl_die;
4848 register unsigned decl_id = DECL_UID (decl);
4849 register unsigned num_allocated;
4851 if (decl_id >= decl_die_table_allocated)
4853 num_allocated
4854 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4855 / DECL_DIE_TABLE_INCREMENT)
4856 * DECL_DIE_TABLE_INCREMENT;
4858 decl_die_table
4859 = (dw_die_ref *) xrealloc (decl_die_table,
4860 sizeof (dw_die_ref) * num_allocated);
4862 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
4863 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4864 decl_die_table_allocated = num_allocated;
4867 if (decl_id >= decl_die_table_in_use)
4868 decl_die_table_in_use = (decl_id + 1);
4870 decl_die_table[decl_id] = decl_die;
4873 /* Keep track of the number of spaces used to indent the
4874 output of the debugging routines that print the structure of
4875 the DIE internal representation. */
4876 static int print_indent;
4878 /* Indent the line the number of spaces given by print_indent. */
4880 static inline void
4881 print_spaces (outfile)
4882 FILE *outfile;
4884 fprintf (outfile, "%*s", print_indent, "");
4887 /* Print the information associated with a given DIE, and its children.
4888 This routine is a debugging aid only. */
4890 static void
4891 print_die (die, outfile)
4892 dw_die_ref die;
4893 FILE *outfile;
4895 register dw_attr_ref a;
4896 register dw_die_ref c;
4898 print_spaces (outfile);
4899 fprintf (outfile, "DIE %4lu: %s\n",
4900 die->die_offset, dwarf_tag_name (die->die_tag));
4901 print_spaces (outfile);
4902 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4903 fprintf (outfile, " offset: %lu\n", die->die_offset);
4905 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4907 print_spaces (outfile);
4908 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4910 switch (AT_class (a))
4912 case dw_val_class_addr:
4913 fprintf (outfile, "address");
4914 break;
4915 case dw_val_class_loc:
4916 fprintf (outfile, "location descriptor");
4917 break;
4918 case dw_val_class_const:
4919 fprintf (outfile, "%ld", AT_int (a));
4920 break;
4921 case dw_val_class_unsigned_const:
4922 fprintf (outfile, "%lu", AT_unsigned (a));
4923 break;
4924 case dw_val_class_long_long:
4925 fprintf (outfile, "constant (%lu,%lu)",
4926 a->dw_attr_val.v.val_long_long.hi,
4927 a->dw_attr_val.v.val_long_long.low);
4928 break;
4929 case dw_val_class_float:
4930 fprintf (outfile, "floating-point constant");
4931 break;
4932 case dw_val_class_flag:
4933 fprintf (outfile, "%u", AT_flag (a));
4934 break;
4935 case dw_val_class_die_ref:
4936 if (AT_ref (a) != NULL)
4938 if (AT_ref (a)->die_symbol)
4939 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
4940 else
4941 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4943 else
4944 fprintf (outfile, "die -> <null>");
4945 break;
4946 case dw_val_class_lbl_id:
4947 case dw_val_class_lbl_offset:
4948 fprintf (outfile, "label: %s", AT_lbl (a));
4949 break;
4950 case dw_val_class_str:
4951 if (AT_string (a) != NULL)
4952 fprintf (outfile, "\"%s\"", AT_string (a));
4953 else
4954 fprintf (outfile, "<null>");
4955 break;
4956 default:
4957 break;
4960 fprintf (outfile, "\n");
4963 if (die->die_child != NULL)
4965 print_indent += 4;
4966 for (c = die->die_child; c != NULL; c = c->die_sib)
4967 print_die (c, outfile);
4969 print_indent -= 4;
4971 if (print_indent == 0)
4972 fprintf (outfile, "\n");
4975 /* Print the contents of the source code line number correspondence table.
4976 This routine is a debugging aid only. */
4978 static void
4979 print_dwarf_line_table (outfile)
4980 FILE *outfile;
4982 register unsigned i;
4983 register dw_line_info_ref line_info;
4985 fprintf (outfile, "\n\nDWARF source line information\n");
4986 for (i = 1; i < line_info_table_in_use; ++i)
4988 line_info = &line_info_table[i];
4989 fprintf (outfile, "%5d: ", i);
4990 fprintf (outfile, "%-20s", line_file_table.table[line_info->dw_file_num]);
4991 fprintf (outfile, "%6ld", line_info->dw_line_num);
4992 fprintf (outfile, "\n");
4995 fprintf (outfile, "\n\n");
4998 /* Print the information collected for a given DIE. */
5000 void
5001 debug_dwarf_die (die)
5002 dw_die_ref die;
5004 print_die (die, stderr);
5007 /* Print all DWARF information collected for the compilation unit.
5008 This routine is a debugging aid only. */
5010 void
5011 debug_dwarf ()
5013 print_indent = 0;
5014 print_die (comp_unit_die, stderr);
5015 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5016 print_dwarf_line_table (stderr);
5019 /* We build up the lists of children and attributes by pushing new ones
5020 onto the beginning of the list. Reverse the lists for DIE so that
5021 they are in order of addition. */
5023 static void
5024 reverse_die_lists (die)
5025 register dw_die_ref die;
5027 register dw_die_ref c, cp, cn;
5028 register dw_attr_ref a, ap, an;
5030 for (a = die->die_attr, ap = 0; a; a = an)
5032 an = a->dw_attr_next;
5033 a->dw_attr_next = ap;
5034 ap = a;
5036 die->die_attr = ap;
5038 for (c = die->die_child, cp = 0; c; c = cn)
5040 cn = c->die_sib;
5041 c->die_sib = cp;
5042 cp = c;
5044 die->die_child = cp;
5047 /* reverse_die_lists only reverses the single die you pass it. Since
5048 we used to reverse all dies in add_sibling_attributes, which runs
5049 through all the dies, it would reverse all the dies. Now, however,
5050 since we don't call reverse_die_lists in add_sibling_attributes, we
5051 need a routine to recursively reverse all the dies. This is that
5052 routine. */
5054 static void
5055 reverse_all_dies (die)
5056 register dw_die_ref die;
5058 register dw_die_ref c;
5060 reverse_die_lists (die);
5062 for (c = die->die_child; c; c = c->die_sib)
5063 reverse_all_dies (c);
5066 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5067 the CU for the enclosing include file, if any. BINCL_DIE is the
5068 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5069 include file. */
5071 static dw_die_ref
5072 push_new_compile_unit (old_unit, bincl_die)
5073 dw_die_ref old_unit, bincl_die;
5075 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5076 dw_die_ref new_unit = gen_compile_unit_die (filename);
5077 new_unit->die_sib = old_unit;
5078 return new_unit;
5081 /* Close an include-file CU and reopen the enclosing one. */
5083 static dw_die_ref
5084 pop_compile_unit (old_unit)
5085 dw_die_ref old_unit;
5087 dw_die_ref new_unit = old_unit->die_sib;
5088 old_unit->die_sib = NULL;
5089 return new_unit;
5092 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5093 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5095 /* Calculate the checksum of a location expression. */
5097 static inline void
5098 loc_checksum (loc, ctx)
5099 dw_loc_descr_ref loc;
5100 struct md5_ctx *ctx;
5102 PROCESS (loc->dw_loc_opc);
5103 PROCESS (loc->dw_loc_oprnd1);
5104 PROCESS (loc->dw_loc_oprnd2);
5107 /* Calculate the checksum of an attribute. */
5109 static void
5110 attr_checksum (at, ctx)
5111 dw_attr_ref at;
5112 struct md5_ctx *ctx;
5114 dw_loc_descr_ref loc;
5115 rtx r;
5117 PROCESS (at->dw_attr);
5119 /* We don't care about differences in file numbering. */
5120 if (at->dw_attr == DW_AT_decl_file
5121 /* Or that this was compiled with a different compiler snapshot; if
5122 the output is the same, that's what matters. */
5123 || at->dw_attr == DW_AT_producer)
5124 return;
5126 switch (AT_class (at))
5128 case dw_val_class_const:
5129 PROCESS (at->dw_attr_val.v.val_int);
5130 break;
5131 case dw_val_class_unsigned_const:
5132 PROCESS (at->dw_attr_val.v.val_unsigned);
5133 break;
5134 case dw_val_class_long_long:
5135 PROCESS (at->dw_attr_val.v.val_long_long);
5136 break;
5137 case dw_val_class_float:
5138 PROCESS (at->dw_attr_val.v.val_float);
5139 break;
5140 case dw_val_class_flag:
5141 PROCESS (at->dw_attr_val.v.val_flag);
5142 break;
5144 case dw_val_class_str:
5145 PROCESS_STRING (AT_string (at));
5146 break;
5147 case dw_val_class_addr:
5148 r = AT_addr (at);
5149 switch (GET_CODE (r))
5151 case SYMBOL_REF:
5152 PROCESS_STRING (XSTR (r, 0));
5153 break;
5155 default:
5156 abort ();
5158 break;
5160 case dw_val_class_loc:
5161 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5162 loc_checksum (loc, ctx);
5163 break;
5165 case dw_val_class_die_ref:
5166 if (AT_ref (at)->die_offset)
5167 PROCESS (AT_ref (at)->die_offset);
5168 /* FIXME else use target die name or something. */
5170 case dw_val_class_fde_ref:
5171 case dw_val_class_lbl_id:
5172 case dw_val_class_lbl_offset:
5174 default:
5175 break;
5179 /* Calculate the checksum of a DIE. */
5181 static void
5182 die_checksum (die, ctx)
5183 dw_die_ref die;
5184 struct md5_ctx *ctx;
5186 dw_die_ref c;
5187 dw_attr_ref a;
5189 PROCESS (die->die_tag);
5191 for (a = die->die_attr; a; a = a->dw_attr_next)
5192 attr_checksum (a, ctx);
5194 for (c = die->die_child; c; c = c->die_sib)
5195 die_checksum (c, ctx);
5198 #undef PROCESS
5199 #undef PROCESS_STRING
5201 /* The prefix to attach to symbols on DIEs in the current comdat debug
5202 info section. */
5203 static char *comdat_symbol_id;
5205 /* The index of the current symbol within the current comdat CU. */
5206 static unsigned int comdat_symbol_number;
5208 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5209 children, and set comdat_symbol_id accordingly. */
5211 static void
5212 compute_section_prefix (unit_die)
5213 dw_die_ref unit_die;
5215 char *p, *name;
5216 int i;
5217 unsigned char checksum[16];
5218 struct md5_ctx ctx;
5220 md5_init_ctx (&ctx);
5221 die_checksum (unit_die, &ctx);
5222 md5_finish_ctx (&ctx, checksum);
5224 p = file_name_nondirectory (get_AT_string (unit_die, DW_AT_name));
5225 name = (char *) alloca (strlen (p) + 64);
5226 sprintf (name, "%s.", p);
5228 clean_symbol_name (name);
5230 p = name + strlen (name);
5231 for (i = 0; i < 4; ++i)
5233 sprintf (p, "%.2x", checksum[i]);
5234 p += 2;
5237 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5238 comdat_symbol_number = 0;
5241 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5243 static int
5244 is_type_die (die)
5245 dw_die_ref die;
5247 switch (die->die_tag)
5249 case DW_TAG_array_type:
5250 case DW_TAG_class_type:
5251 case DW_TAG_enumeration_type:
5252 case DW_TAG_pointer_type:
5253 case DW_TAG_reference_type:
5254 case DW_TAG_string_type:
5255 case DW_TAG_structure_type:
5256 case DW_TAG_subroutine_type:
5257 case DW_TAG_union_type:
5258 case DW_TAG_ptr_to_member_type:
5259 case DW_TAG_set_type:
5260 case DW_TAG_subrange_type:
5261 case DW_TAG_base_type:
5262 case DW_TAG_const_type:
5263 case DW_TAG_file_type:
5264 case DW_TAG_packed_type:
5265 case DW_TAG_volatile_type:
5266 return 1;
5267 default:
5268 return 0;
5272 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5273 Basically, we want to choose the bits that are likely to be shared between
5274 compilations (types) and leave out the bits that are specific to individual
5275 compilations (functions). */
5277 static int
5278 is_comdat_die (c)
5279 dw_die_ref c;
5281 #if 1
5282 /* I think we want to leave base types and __vtbl_ptr_type in the
5283 main CU, as we do for stabs. The advantage is a greater
5284 likelihood of sharing between objects that don't include headers
5285 in the same order (and therefore would put the base types in a
5286 different comdat). jason 8/28/00 */
5287 if (c->die_tag == DW_TAG_base_type)
5288 return 0;
5290 if (c->die_tag == DW_TAG_pointer_type
5291 || c->die_tag == DW_TAG_reference_type
5292 || c->die_tag == DW_TAG_const_type
5293 || c->die_tag == DW_TAG_volatile_type)
5295 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5296 return t ? is_comdat_die (t) : 0;
5298 #endif
5300 return is_type_die (c);
5303 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5304 compilation unit. */
5306 static int
5307 is_symbol_die (c)
5308 dw_die_ref c;
5310 if (is_type_die (c))
5311 return 1;
5312 if (get_AT (c, DW_AT_declaration)
5313 && ! get_AT (c, DW_AT_specification))
5314 return 1;
5315 return 0;
5318 static char *
5319 gen_internal_sym ()
5321 char buf[256];
5322 static int label_num;
5323 ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++);
5324 return xstrdup (buf);
5327 /* Assign symbols to all worthy DIEs under DIE. */
5329 static void
5330 assign_symbol_names (die)
5331 register dw_die_ref die;
5333 register dw_die_ref c;
5335 if (is_symbol_die (die))
5337 if (comdat_symbol_id)
5339 char *p = alloca (strlen (comdat_symbol_id) + 64);
5340 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5341 comdat_symbol_id, comdat_symbol_number++);
5342 die->die_symbol = xstrdup (p);
5344 else
5345 die->die_symbol = gen_internal_sym ();
5348 for (c = die->die_child; c != NULL; c = c->die_sib)
5349 assign_symbol_names (c);
5352 /* Traverse the DIE (which is always comp_unit_die), and set up
5353 additional compilation units for each of the include files we see
5354 bracketed by BINCL/EINCL. */
5356 static void
5357 break_out_includes (die)
5358 register dw_die_ref die;
5360 dw_die_ref *ptr;
5361 register dw_die_ref unit = NULL;
5362 limbo_die_node *node;
5364 for (ptr = &(die->die_child); *ptr; )
5366 register dw_die_ref c = *ptr;
5368 if (c->die_tag == DW_TAG_GNU_BINCL
5369 || c->die_tag == DW_TAG_GNU_EINCL
5370 || (unit && is_comdat_die (c)))
5372 /* This DIE is for a secondary CU; remove it from the main one. */
5373 *ptr = c->die_sib;
5375 if (c->die_tag == DW_TAG_GNU_BINCL)
5377 unit = push_new_compile_unit (unit, c);
5378 free_die (c);
5380 else if (c->die_tag == DW_TAG_GNU_EINCL)
5382 unit = pop_compile_unit (unit);
5383 free_die (c);
5385 else
5386 add_child_die (unit, c);
5388 else
5390 /* Leave this DIE in the main CU. */
5391 ptr = &(c->die_sib);
5392 continue;
5396 #if 0
5397 /* We can only use this in debugging, since the frontend doesn't check
5398 to make sure that we leave every include file we enter. */
5399 if (unit != NULL)
5400 abort ();
5401 #endif
5403 assign_symbol_names (die);
5404 for (node = limbo_die_list; node; node = node->next)
5406 compute_section_prefix (node->die);
5407 assign_symbol_names (node->die);
5411 /* Traverse the DIE and add a sibling attribute if it may have the
5412 effect of speeding up access to siblings. To save some space,
5413 avoid generating sibling attributes for DIE's without children. */
5415 static void
5416 add_sibling_attributes (die)
5417 register dw_die_ref die;
5419 register dw_die_ref c;
5421 if (die->die_tag != DW_TAG_compile_unit
5422 && die->die_sib && die->die_child != NULL)
5423 /* Add the sibling link to the front of the attribute list. */
5424 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5426 for (c = die->die_child; c != NULL; c = c->die_sib)
5427 add_sibling_attributes (c);
5430 /* The format of each DIE (and its attribute value pairs)
5431 is encoded in an abbreviation table. This routine builds the
5432 abbreviation table and assigns a unique abbreviation id for
5433 each abbreviation entry. The children of each die are visited
5434 recursively. */
5436 static void
5437 build_abbrev_table (die)
5438 register dw_die_ref die;
5440 register unsigned long abbrev_id;
5441 register unsigned long n_alloc;
5442 register dw_die_ref c;
5443 register dw_attr_ref d_attr, a_attr;
5445 /* Scan the DIE references, and mark as external any that refer to
5446 DIEs from other CUs (i.e. those which are not marked). */
5447 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5449 if (AT_class (d_attr) == dw_val_class_die_ref
5450 && AT_ref (d_attr)->die_mark == 0)
5452 if (AT_ref (d_attr)->die_symbol == 0)
5453 abort ();
5454 set_AT_ref_external (d_attr, 1);
5458 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5460 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5462 if (abbrev->die_tag == die->die_tag)
5464 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5466 a_attr = abbrev->die_attr;
5467 d_attr = die->die_attr;
5469 while (a_attr != NULL && d_attr != NULL)
5471 if ((a_attr->dw_attr != d_attr->dw_attr)
5472 || (value_format (a_attr) != value_format (d_attr)))
5473 break;
5475 a_attr = a_attr->dw_attr_next;
5476 d_attr = d_attr->dw_attr_next;
5479 if (a_attr == NULL && d_attr == NULL)
5480 break;
5485 if (abbrev_id >= abbrev_die_table_in_use)
5487 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5489 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5490 abbrev_die_table
5491 = (dw_die_ref *) xrealloc (abbrev_die_table,
5492 sizeof (dw_die_ref) * n_alloc);
5494 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5495 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5496 abbrev_die_table_allocated = n_alloc;
5499 ++abbrev_die_table_in_use;
5500 abbrev_die_table[abbrev_id] = die;
5503 die->die_abbrev = abbrev_id;
5504 for (c = die->die_child; c != NULL; c = c->die_sib)
5505 build_abbrev_table (c);
5508 /* Return the size of a string, including the null byte.
5510 This used to treat backslashes as escapes, and hence they were not included
5511 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5512 which treats a backslash as a backslash, escaping it if necessary, and hence
5513 we must include them in the count. */
5515 static unsigned long
5516 size_of_string (str)
5517 register const char *str;
5519 return strlen (str) + 1;
5522 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5524 static int
5525 constant_size (value)
5526 long unsigned value;
5528 int log;
5530 if (value == 0)
5531 log = 0;
5532 else
5533 log = floor_log2 (value);
5535 log = log / 8;
5536 log = 1 << (floor_log2 (log) + 1);
5538 return log;
5541 /* Return the size of a DIE, as it is represented in the
5542 .debug_info section. */
5544 static unsigned long
5545 size_of_die (die)
5546 register dw_die_ref die;
5548 register unsigned long size = 0;
5549 register dw_attr_ref a;
5551 size += size_of_uleb128 (die->die_abbrev);
5552 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5554 switch (AT_class (a))
5556 case dw_val_class_addr:
5557 size += DWARF2_ADDR_SIZE;
5558 break;
5559 case dw_val_class_loc:
5561 register unsigned long lsize = size_of_locs (AT_loc (a));
5563 /* Block length. */
5564 size += constant_size (lsize);
5565 size += lsize;
5567 break;
5568 case dw_val_class_const:
5569 size += size_of_sleb128 (AT_int (a));
5570 break;
5571 case dw_val_class_unsigned_const:
5572 size += constant_size (AT_unsigned (a));
5573 break;
5574 case dw_val_class_long_long:
5575 size += 1 + 8; /* block */
5576 break;
5577 case dw_val_class_float:
5578 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5579 break;
5580 case dw_val_class_flag:
5581 size += 1;
5582 break;
5583 case dw_val_class_die_ref:
5584 size += DWARF_OFFSET_SIZE;
5585 break;
5586 case dw_val_class_fde_ref:
5587 size += DWARF_OFFSET_SIZE;
5588 break;
5589 case dw_val_class_lbl_id:
5590 size += DWARF2_ADDR_SIZE;
5591 break;
5592 case dw_val_class_lbl_offset:
5593 size += DWARF_OFFSET_SIZE;
5594 break;
5595 case dw_val_class_str:
5596 size += size_of_string (AT_string (a));
5597 break;
5598 default:
5599 abort ();
5603 return size;
5606 /* Size the debugging information associated with a given DIE.
5607 Visits the DIE's children recursively. Updates the global
5608 variable next_die_offset, on each time through. Uses the
5609 current value of next_die_offset to update the die_offset
5610 field in each DIE. */
5612 static void
5613 calc_die_sizes (die)
5614 dw_die_ref die;
5616 register dw_die_ref c;
5617 die->die_offset = next_die_offset;
5618 next_die_offset += size_of_die (die);
5620 for (c = die->die_child; c != NULL; c = c->die_sib)
5621 calc_die_sizes (c);
5623 if (die->die_child != NULL)
5624 /* Count the null byte used to terminate sibling lists. */
5625 next_die_offset += 1;
5628 /* Set the marks for a die and its children. We do this so
5629 that we know whether or not a reference needs to use FORM_ref_addr; only
5630 DIEs in the same CU will be marked. We used to clear out the offset
5631 and use that as the flag, but ran into ordering problems. */
5633 static void
5634 mark_dies (die)
5635 dw_die_ref die;
5637 register dw_die_ref c;
5638 die->die_mark = 1;
5639 for (c = die->die_child; c; c = c->die_sib)
5640 mark_dies (c);
5643 /* Clear the marks for a die and its children. */
5645 static void
5646 unmark_dies (die)
5647 dw_die_ref die;
5649 register dw_die_ref c;
5650 die->die_mark = 0;
5651 for (c = die->die_child; c; c = c->die_sib)
5652 unmark_dies (c);
5655 /* Return the size of the line information prolog generated for the
5656 compilation unit. */
5658 static unsigned long
5659 size_of_line_prolog ()
5661 register unsigned long size;
5662 register unsigned long ft_index;
5664 size = DWARF_LINE_PROLOG_HEADER_SIZE;
5666 /* Count the size of the table giving number of args for each
5667 standard opcode. */
5668 size += DWARF_LINE_OPCODE_BASE - 1;
5670 /* Include directory table is empty (at present). Count only the
5671 null byte used to terminate the table. */
5672 size += 1;
5674 for (ft_index = 1; ft_index < decl_file_table.in_use; ++ft_index)
5676 /* File name entry. */
5677 size += size_of_string (decl_file_table.table[ft_index]);
5679 /* Include directory index. */
5680 size += size_of_uleb128 (0);
5682 /* Modification time. */
5683 size += size_of_uleb128 (0);
5685 /* File length in bytes. */
5686 size += size_of_uleb128 (0);
5689 /* Count the file table terminator. */
5690 size += 1;
5691 return size;
5694 /* Return the size of the .debug_pubnames table generated for the
5695 compilation unit. */
5697 static unsigned long
5698 size_of_pubnames ()
5700 register unsigned long size;
5701 register unsigned i;
5703 size = DWARF_PUBNAMES_HEADER_SIZE;
5704 for (i = 0; i < pubname_table_in_use; ++i)
5706 register pubname_ref p = &pubname_table[i];
5707 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5710 size += DWARF_OFFSET_SIZE;
5711 return size;
5714 /* Return the size of the information in the .debug_aranges section. */
5716 static unsigned long
5717 size_of_aranges ()
5719 register unsigned long size;
5721 size = DWARF_ARANGES_HEADER_SIZE;
5723 /* Count the address/length pair for this compilation unit. */
5724 size += 2 * DWARF2_ADDR_SIZE;
5725 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5727 /* Count the two zero words used to terminated the address range table. */
5728 size += 2 * DWARF2_ADDR_SIZE;
5729 return size;
5732 /* Select the encoding of an attribute value. */
5734 static enum dwarf_form
5735 value_format (a)
5736 dw_attr_ref a;
5738 switch (a->dw_attr_val.val_class)
5740 case dw_val_class_addr:
5741 return DW_FORM_addr;
5742 case dw_val_class_loc:
5743 switch (constant_size (size_of_locs (AT_loc (a))))
5745 case 1:
5746 return DW_FORM_block1;
5747 case 2:
5748 return DW_FORM_block2;
5749 default:
5750 abort ();
5752 case dw_val_class_const:
5753 return DW_FORM_sdata;
5754 case dw_val_class_unsigned_const:
5755 switch (constant_size (AT_unsigned (a)))
5757 case 1:
5758 return DW_FORM_data1;
5759 case 2:
5760 return DW_FORM_data2;
5761 case 4:
5762 return DW_FORM_data4;
5763 case 8:
5764 return DW_FORM_data8;
5765 default:
5766 abort ();
5768 case dw_val_class_long_long:
5769 return DW_FORM_block1;
5770 case dw_val_class_float:
5771 return DW_FORM_block1;
5772 case dw_val_class_flag:
5773 return DW_FORM_flag;
5774 case dw_val_class_die_ref:
5775 if (AT_ref_external (a))
5776 return DW_FORM_ref_addr;
5777 else
5778 return DW_FORM_ref;
5779 case dw_val_class_fde_ref:
5780 return DW_FORM_data;
5781 case dw_val_class_lbl_id:
5782 return DW_FORM_addr;
5783 case dw_val_class_lbl_offset:
5784 return DW_FORM_data;
5785 case dw_val_class_str:
5786 return DW_FORM_string;
5787 default:
5788 abort ();
5792 /* Output the encoding of an attribute value. */
5794 static void
5795 output_value_format (a)
5796 dw_attr_ref a;
5798 enum dwarf_form form = value_format (a);
5800 output_uleb128 (form);
5801 if (flag_debug_asm)
5802 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
5804 fputc ('\n', asm_out_file);
5807 /* Output the .debug_abbrev section which defines the DIE abbreviation
5808 table. */
5810 static void
5811 output_abbrev_section ()
5813 unsigned long abbrev_id;
5815 dw_attr_ref a_attr;
5816 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5818 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5820 output_uleb128 (abbrev_id);
5821 if (flag_debug_asm)
5822 fprintf (asm_out_file, " (abbrev code)");
5824 fputc ('\n', asm_out_file);
5825 output_uleb128 (abbrev->die_tag);
5826 if (flag_debug_asm)
5827 fprintf (asm_out_file, " (TAG: %s)",
5828 dwarf_tag_name (abbrev->die_tag));
5830 fputc ('\n', asm_out_file);
5831 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP,
5832 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
5834 if (flag_debug_asm)
5835 fprintf (asm_out_file, "\t%s %s",
5836 ASM_COMMENT_START,
5837 (abbrev->die_child != NULL
5838 ? "DW_children_yes" : "DW_children_no"));
5840 fputc ('\n', asm_out_file);
5842 for (a_attr = abbrev->die_attr; a_attr != NULL;
5843 a_attr = a_attr->dw_attr_next)
5845 output_uleb128 (a_attr->dw_attr);
5846 if (flag_debug_asm)
5847 fprintf (asm_out_file, " (%s)",
5848 dwarf_attr_name (a_attr->dw_attr));
5850 fputc ('\n', asm_out_file);
5851 output_value_format (a_attr);
5854 fprintf (asm_out_file, "%s0,0\n", ASM_BYTE_OP);
5857 /* Terminate the table. */
5858 fprintf (asm_out_file, "%s0\n", ASM_BYTE_OP);
5861 /* Output a symbol we can use to refer to this DIE from another CU. */
5863 static inline void
5864 output_die_symbol (die)
5865 register dw_die_ref die;
5867 char *sym = die->die_symbol;
5869 if (sym == 0)
5870 return;
5872 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
5873 /* We make these global, not weak; if the target doesn't support
5874 .linkonce, it doesn't support combining the sections, so debugging
5875 will break. */
5876 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
5877 ASM_OUTPUT_LABEL (asm_out_file, sym);
5880 /* Output a symbolic (i.e. FORM_ref_addr) reference to TARGET_DIE. */
5882 static inline void
5883 output_symbolic_ref (target_die)
5884 dw_die_ref target_die;
5886 char *sym = target_die->die_symbol;
5888 if (sym == 0)
5889 abort ();
5891 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, sym);
5894 /* Output the DIE and its attributes. Called recursively to generate
5895 the definitions of each child DIE. */
5897 static void
5898 output_die (die)
5899 register dw_die_ref die;
5901 register dw_attr_ref a;
5902 register dw_die_ref c;
5903 register unsigned long size;
5905 /* If someone in another CU might refer to us, set up a symbol for
5906 them to point to. */
5907 if (die->die_symbol)
5908 output_die_symbol (die);
5910 output_uleb128 (die->die_abbrev);
5911 if (flag_debug_asm)
5912 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
5913 die->die_offset, dwarf_tag_name (die->die_tag));
5915 fputc ('\n', asm_out_file);
5917 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5919 switch (AT_class (a))
5921 case dw_val_class_addr:
5922 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
5923 break;
5925 case dw_val_class_loc:
5926 size = size_of_locs (AT_loc (a));
5928 /* Output the block length for this list of location operations. */
5929 switch (constant_size (size))
5931 case 1:
5932 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5933 break;
5934 case 2:
5935 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5936 break;
5937 default:
5938 abort ();
5941 if (flag_debug_asm)
5942 fprintf (asm_out_file, "\t%s %s",
5943 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5945 fputc ('\n', asm_out_file);
5947 output_loc_sequence (AT_loc (a));
5948 break;
5950 case dw_val_class_const:
5951 /* ??? It would be slightly more efficient to use a scheme like is
5952 used for unsigned constants below, but gdb 4.x does not sign
5953 extend. Gdb 5.x does sign extend. */
5954 output_sleb128 (AT_int (a));
5955 break;
5957 case dw_val_class_unsigned_const:
5958 switch (constant_size (AT_unsigned (a)))
5960 case 1:
5961 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
5962 break;
5963 case 2:
5964 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
5965 break;
5966 case 4:
5967 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
5968 break;
5969 case 8:
5970 ASM_OUTPUT_DWARF_DATA8 (asm_out_file, AT_unsigned (a));
5971 break;
5972 default:
5973 abort ();
5975 break;
5977 case dw_val_class_long_long:
5978 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
5979 if (flag_debug_asm)
5980 fprintf (asm_out_file, "\t%s %s",
5981 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5983 fputc ('\n', asm_out_file);
5984 ASM_OUTPUT_DWARF_CONST_DOUBLE (asm_out_file,
5985 a->dw_attr_val.v.val_long_long.hi,
5986 a->dw_attr_val.v.val_long_long.low);
5988 if (flag_debug_asm)
5989 fprintf (asm_out_file,
5990 "\t%s long long constant", ASM_COMMENT_START);
5992 fputc ('\n', asm_out_file);
5993 break;
5995 case dw_val_class_float:
5997 register unsigned int i;
5998 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5999 a->dw_attr_val.v.val_float.length * 4);
6000 if (flag_debug_asm)
6001 fprintf (asm_out_file, "\t%s %s",
6002 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6004 fputc ('\n', asm_out_file);
6005 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
6007 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
6008 a->dw_attr_val.v.val_float.array[i]);
6009 if (flag_debug_asm)
6010 fprintf (asm_out_file, "\t%s fp constant word %u",
6011 ASM_COMMENT_START, i);
6013 fputc ('\n', asm_out_file);
6015 break;
6018 case dw_val_class_flag:
6019 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
6020 break;
6022 case dw_val_class_die_ref:
6023 if (AT_ref_external (a))
6024 output_symbolic_ref (AT_ref (a));
6025 else
6026 ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
6027 break;
6029 case dw_val_class_fde_ref:
6031 char l1[20];
6032 ASM_GENERATE_INTERNAL_LABEL
6033 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
6034 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
6035 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
6037 break;
6039 case dw_val_class_lbl_id:
6040 ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
6041 break;
6043 case dw_val_class_lbl_offset:
6044 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
6045 break;
6047 case dw_val_class_str:
6048 if (flag_debug_asm)
6049 ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
6050 else
6051 ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
6052 (int) strlen (AT_string (a)) + 1);
6053 break;
6055 default:
6056 abort ();
6059 if (AT_class (a) != dw_val_class_loc
6060 && AT_class (a) != dw_val_class_long_long
6061 && AT_class (a) != dw_val_class_float)
6063 if (flag_debug_asm)
6064 fprintf (asm_out_file, "\t%s %s",
6065 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6067 fputc ('\n', asm_out_file);
6071 for (c = die->die_child; c != NULL; c = c->die_sib)
6072 output_die (c);
6074 if (die->die_child != NULL)
6076 /* Add null byte to terminate sibling list. */
6077 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6078 if (flag_debug_asm)
6079 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
6080 ASM_COMMENT_START, die->die_offset);
6082 fputc ('\n', asm_out_file);
6086 /* Output the compilation unit that appears at the beginning of the
6087 .debug_info section, and precedes the DIE descriptions. */
6089 static void
6090 output_compilation_unit_header ()
6092 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
6093 if (flag_debug_asm)
6094 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
6095 ASM_COMMENT_START);
6097 fputc ('\n', asm_out_file);
6098 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6099 if (flag_debug_asm)
6100 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
6102 fputc ('\n', asm_out_file);
6103 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
6104 if (flag_debug_asm)
6105 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
6106 ASM_COMMENT_START);
6108 fputc ('\n', asm_out_file);
6109 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6110 if (flag_debug_asm)
6111 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
6113 fputc ('\n', asm_out_file);
6116 /* Output the compilation unit DIE and its children. */
6118 static void
6119 output_comp_unit (die)
6120 dw_die_ref die;
6122 const char *secname;
6124 if (die->die_child == 0)
6125 return;
6127 /* Mark all the DIEs in this CU so we know which get local refs. */
6128 mark_dies (die);
6130 build_abbrev_table (die);
6132 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6133 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6134 calc_die_sizes (die);
6136 if (die->die_symbol)
6138 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6139 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6140 secname = tmp;
6141 die->die_symbol = NULL;
6143 else
6144 secname = (const char *) DEBUG_INFO_SECTION;
6146 /* Output debugging information. */
6147 fputc ('\n', asm_out_file);
6148 ASM_OUTPUT_SECTION (asm_out_file, secname);
6149 output_compilation_unit_header ();
6150 output_die (die);
6152 /* Leave the marks on the main CU, so we can check them in
6153 output_pubnames. */
6154 if (die->die_symbol)
6155 unmark_dies (die);
6158 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6159 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6160 argument list, and maybe the scope. */
6162 static const char *
6163 dwarf2_name (decl, scope)
6164 tree decl;
6165 int scope;
6167 return (*decl_printable_name) (decl, scope ? 1 : 0);
6170 /* Add a new entry to .debug_pubnames if appropriate. */
6172 static void
6173 add_pubname (decl, die)
6174 tree decl;
6175 dw_die_ref die;
6177 pubname_ref p;
6179 if (! TREE_PUBLIC (decl))
6180 return;
6182 if (pubname_table_in_use == pubname_table_allocated)
6184 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6185 pubname_table = (pubname_ref) xrealloc
6186 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6189 p = &pubname_table[pubname_table_in_use++];
6190 p->die = die;
6192 p->name = xstrdup (dwarf2_name (decl, 1));
6195 /* Output the public names table used to speed up access to externally
6196 visible names. For now, only generate entries for externally
6197 visible procedures. */
6199 static void
6200 output_pubnames ()
6202 register unsigned i;
6203 register unsigned long pubnames_length = size_of_pubnames ();
6205 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
6207 if (flag_debug_asm)
6208 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
6209 ASM_COMMENT_START);
6211 fputc ('\n', asm_out_file);
6212 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6214 if (flag_debug_asm)
6215 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6217 fputc ('\n', asm_out_file);
6218 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6219 if (flag_debug_asm)
6220 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6221 ASM_COMMENT_START);
6223 fputc ('\n', asm_out_file);
6224 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
6225 if (flag_debug_asm)
6226 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
6228 fputc ('\n', asm_out_file);
6229 for (i = 0; i < pubname_table_in_use; ++i)
6231 register pubname_ref pub = &pubname_table[i];
6233 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6234 if (pub->die->die_mark == 0)
6235 abort ();
6237 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
6238 if (flag_debug_asm)
6239 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
6241 fputc ('\n', asm_out_file);
6243 if (flag_debug_asm)
6245 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
6246 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
6248 else
6250 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
6251 (int) strlen (pub->name) + 1);
6254 fputc ('\n', asm_out_file);
6257 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
6258 fputc ('\n', asm_out_file);
6261 /* Add a new entry to .debug_aranges if appropriate. */
6263 static void
6264 add_arange (decl, die)
6265 tree decl;
6266 dw_die_ref die;
6268 if (! DECL_SECTION_NAME (decl))
6269 return;
6271 if (arange_table_in_use == arange_table_allocated)
6273 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6274 arange_table
6275 = (arange_ref) xrealloc (arange_table,
6276 arange_table_allocated * sizeof (dw_die_ref));
6279 arange_table[arange_table_in_use++] = die;
6282 /* Output the information that goes into the .debug_aranges table.
6283 Namely, define the beginning and ending address range of the
6284 text section generated for this compilation unit. */
6286 static void
6287 output_aranges ()
6289 register unsigned i;
6290 register unsigned long aranges_length = size_of_aranges ();
6292 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
6293 if (flag_debug_asm)
6294 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
6295 ASM_COMMENT_START);
6297 fputc ('\n', asm_out_file);
6298 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6299 if (flag_debug_asm)
6300 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6302 fputc ('\n', asm_out_file);
6303 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6304 if (flag_debug_asm)
6305 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6306 ASM_COMMENT_START);
6308 fputc ('\n', asm_out_file);
6309 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6310 if (flag_debug_asm)
6311 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
6313 fputc ('\n', asm_out_file);
6314 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6315 if (flag_debug_asm)
6316 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
6317 ASM_COMMENT_START);
6319 fputc ('\n', asm_out_file);
6321 /* We need to align to twice the pointer size here. */
6322 if (DWARF_ARANGES_PAD_SIZE)
6324 /* Pad using a 2 bytes word so that padding is correct
6325 for any pointer size. */
6326 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
6327 for (i = 2; i < DWARF_ARANGES_PAD_SIZE; i += 2)
6328 fprintf (asm_out_file, ",0");
6329 if (flag_debug_asm)
6330 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
6331 ASM_COMMENT_START, 2 * DWARF2_ADDR_SIZE);
6334 fputc ('\n', asm_out_file);
6335 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
6336 if (flag_debug_asm)
6337 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6339 fputc ('\n', asm_out_file);
6340 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
6341 text_section_label);
6342 if (flag_debug_asm)
6343 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6345 fputc ('\n', asm_out_file);
6346 for (i = 0; i < arange_table_in_use; ++i)
6348 dw_die_ref die = arange_table[i];
6350 /* We shouldn't see aranges for DIEs outside of the main CU. */
6351 if (die->die_mark == 0)
6352 abort ();
6354 if (die->die_tag == DW_TAG_subprogram)
6355 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
6356 else
6358 /* A static variable; extract the symbol from DW_AT_location.
6359 Note that this code isn't currently hit, as we only emit
6360 aranges for functions (jason 9/23/99). */
6362 dw_attr_ref a = get_AT (die, DW_AT_location);
6363 dw_loc_descr_ref loc;
6364 if (! a || AT_class (a) != dw_val_class_loc)
6365 abort ();
6367 loc = AT_loc (a);
6368 if (loc->dw_loc_opc != DW_OP_addr)
6369 abort ();
6371 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
6372 loc->dw_loc_oprnd1.v.val_addr);
6375 if (flag_debug_asm)
6376 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6378 fputc ('\n', asm_out_file);
6379 if (die->die_tag == DW_TAG_subprogram)
6380 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
6381 get_AT_low_pc (die));
6382 else
6383 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
6384 get_AT_unsigned (die, DW_AT_byte_size));
6386 if (flag_debug_asm)
6387 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6389 fputc ('\n', asm_out_file);
6392 /* Output the terminator words. */
6393 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6394 fputc ('\n', asm_out_file);
6395 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6396 fputc ('\n', asm_out_file);
6400 /* Data structure containing information about input files. */
6401 struct file_info
6403 char *path; /* Complete file name. */
6404 char *fname; /* File name part. */
6405 int length; /* Length of entire string. */
6406 int file_idx; /* Index in input file table. */
6407 int dir_idx; /* Index in directory table. */
6410 /* Data structure containing information about directories with source
6411 files. */
6412 struct dir_info
6414 char *path; /* Path including directory name. */
6415 int length; /* Path length. */
6416 int prefix; /* Index of directory entry which is a prefix. */
6417 int nbytes; /* Total number of bytes in all file names excluding
6418 paths. */
6419 int count; /* Number of files in this directory. */
6420 int dir_idx; /* Index of directory used as base. */
6421 int used; /* Used in the end? */
6424 /* Callback function for file_info comparison. We sort by looking at
6425 the directories in the path. */
6426 static int
6427 file_info_cmp (p1, p2)
6428 const void *p1;
6429 const void *p2;
6431 const struct file_info *s1 = p1;
6432 const struct file_info *s2 = p2;
6433 unsigned char *cp1;
6434 unsigned char *cp2;
6436 /* Take care of file names without directories. */
6437 if (s1->path == s1->fname)
6438 return -1;
6439 else if (s2->path == s2->fname)
6440 return 1;
6442 cp1 = (unsigned char *) s1->path;
6443 cp2 = (unsigned char *) s2->path;
6445 while (1)
6447 ++cp1;
6448 ++cp2;
6449 /* Reached the end of the first path? */
6450 if (cp1 == (unsigned char *) s1->fname)
6451 /* It doesn't really matter in which order files from the
6452 same directory are sorted in. Therefore don't test for
6453 the second path reaching the end. */
6454 return -1;
6455 else if (cp2 == (unsigned char *) s2->fname)
6456 return 1;
6458 /* Character of current path component the same? */
6459 if (*cp1 != *cp2)
6460 return *cp1 - *cp2;
6464 /* Output the directory table and the file name table. We try to minimize
6465 the total amount of memory needed. A heuristic is used to avoid large
6466 slowdowns with many input files. */
6467 static void
6468 output_file_names ()
6470 struct file_info *files;
6471 struct dir_info *dirs;
6472 int *saved;
6473 int *savehere;
6474 int *backmap;
6475 int ndirs;
6476 int idx_offset;
6477 int i;
6478 int idx;
6480 /* Allocate the various arrays we need. */
6481 files = (struct file_info *) alloca (line_file_table.in_use
6482 * sizeof (struct file_info));
6483 dirs = (struct dir_info *) alloca (line_file_table.in_use
6484 * sizeof (struct dir_info));
6486 /* Sort the file names. */
6487 for (i = 1; i < (int) line_file_table.in_use; ++i)
6489 char *f;
6491 /* Skip all leading "./". */
6492 f = line_file_table.table[i];
6493 while (f[0] == '.' && f[1] == '/')
6494 f += 2;
6496 /* Create a new array entry. */
6497 files[i].path = f;
6498 files[i].length = strlen (f);
6499 files[i].file_idx = i;
6501 /* Search for the file name part. */
6502 f = strrchr (f, '/');
6503 files[i].fname = f == NULL ? files[i].path : f + 1;
6505 qsort (files + 1, line_file_table.in_use - 1, sizeof (files[0]),
6506 file_info_cmp);
6508 /* Find all the different directories used. */
6509 dirs[0].path = files[1].path;
6510 dirs[0].length = files[1].fname - files[1].path;
6511 dirs[0].prefix = -1;
6512 dirs[0].nbytes = files[1].length - dirs[1].length + 1;
6513 dirs[0].count = 1;
6514 dirs[0].dir_idx = 0;
6515 dirs[0].used = 0;
6516 files[1].dir_idx = 0;
6517 ndirs = 1;
6519 for (i = 2; i < (int) line_file_table.in_use; ++i)
6520 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6521 && memcmp (dirs[ndirs - 1].path, files[i].path,
6522 dirs[ndirs - 1].length) == 0)
6524 /* Same directory as last entry. */
6525 files[i].dir_idx = ndirs - 1;
6526 dirs[ndirs - 1].nbytes += files[i].length - dirs[ndirs - 1].length + 1;
6527 ++dirs[ndirs - 1].count;
6529 else
6531 int j;
6533 /* This is a new directory. */
6534 dirs[ndirs].path = files[i].path;
6535 dirs[ndirs].length = files[i].fname - files[i].path;
6536 dirs[ndirs].nbytes = files[i].length - dirs[i].length + 1;
6537 dirs[ndirs].count = 1;
6538 dirs[ndirs].dir_idx = ndirs;
6539 dirs[ndirs].used = 0;
6540 files[i].dir_idx = ndirs;
6542 /* Search for a prefix. */
6543 dirs[ndirs].prefix = -1;
6544 for (j = 0; j < ndirs; ++j)
6545 if (dirs[j].length < dirs[ndirs].length
6546 && dirs[j].length != 0
6547 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6548 dirs[ndirs].prefix = j;
6550 ++ndirs;
6553 /* Now to the actual work. We have to find a subset of the
6554 directories which allow expressing the file name using references
6555 to the directory table with the least amount of characters. We
6556 do not do an exhaustive search where we would have to check out
6557 every combination of every single possible prefix. Instead we
6558 use a heuristic which provides nearly optimal results in most
6559 cases and never is much off. */
6560 saved = (int *) alloca (ndirs * sizeof (int));
6561 savehere = (int *) alloca (ndirs * sizeof (int));
6563 memset (saved, '\0', ndirs * sizeof (saved[0]));
6564 for (i = 0; i < ndirs; ++i)
6566 int j;
6567 int total;
6569 /* We can always safe some space for the current directory. But
6570 this does not mean it will be enough to justify adding the
6571 directory. */
6572 savehere[i] = dirs[i].length;
6573 total = (savehere[i] - saved[i]) * dirs[i].count;
6575 for (j = i + 1; j < ndirs; ++j)
6577 savehere[j] = 0;
6579 if (saved[j] < dirs[i].length)
6581 /* Determine whether the dirs[i] path is a prefix of the
6582 dirs[j] path. */
6583 int k;
6585 k = dirs[j].prefix;
6586 while (k != -1 && k != i)
6587 k = dirs[k].prefix;
6589 if (k == i)
6591 /* Yes it is. We can possibly safe some memory but
6592 writing the filenames in dirs[j] relative to
6593 dirs[i]. */
6594 savehere[j] = dirs[i].length;
6595 total += (savehere[j] - saved[j]) * dirs[j].count;
6600 /* Check whether we can safe enough to justify adding the dirs[i]
6601 directory. */
6602 if (total > dirs[i].length + 1)
6604 /* It's worthwhile adding. */
6605 for (j = i; j < ndirs; ++j)
6606 if (savehere[j] > 0)
6608 /* Remember how much we saved for this directory so far. */
6609 saved[j] = savehere[j];
6611 /* Remember the prefix directory. */
6612 dirs[j].dir_idx = i;
6617 /* We have to emit them in the order they appear in the line_file_table
6618 array since the index is used in the debug info generation. To
6619 do this efficiently we generate a back-mapping of the indices
6620 first. */
6621 backmap = (int *) alloca (line_file_table.in_use * sizeof (int));
6622 for (i = 1; i < (int) line_file_table.in_use; ++i)
6624 backmap[files[i].file_idx] = i;
6625 /* Mark this directory as used. */
6626 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6629 /* That was it. We are ready to emit the information. First the
6630 directory name table. Here we have to make sure that the first
6631 actually emitted directory name has the index one. Zero is
6632 reserved for the current working directory. Make sure we do not
6633 confuse these indices with the one for the constructed table
6634 (even though most of the time they are identical). */
6635 idx = 1;
6636 idx_offset = dirs[0].path[0] == '/' ? 1 : 0;
6637 for (i = 1 - idx_offset; i < ndirs; ++i)
6638 if (dirs[i].used != 0)
6640 dirs[i].used = idx++;
6642 if (flag_debug_asm)
6644 ASM_OUTPUT_DWARF_NSTRING (asm_out_file,
6645 dirs[i].path, dirs[i].length - 1);
6646 fprintf (asm_out_file, "%s Directory Entry: 0x%x\n",
6647 ASM_COMMENT_START, dirs[i].used);
6649 else
6651 ASM_OUTPUT_ASCII (asm_out_file, dirs[i].path, dirs[i].length - 1);
6652 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6653 fputc ('\n', asm_out_file);
6656 /* Correct the index for the current working directory entry if it
6657 exists. */
6658 if (idx_offset == 0)
6659 dirs[0].used = 0;
6660 /* Terminate the directory name array. */
6661 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6662 if (flag_debug_asm)
6663 fprintf (asm_out_file, "\t%s End directory table", ASM_COMMENT_START);
6664 fputc ('\n', asm_out_file);
6666 /* Now write all the file names. */
6667 for (i = 1; i < (int) line_file_table.in_use; ++i)
6669 int file_idx = backmap[i];
6670 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6672 if (flag_debug_asm)
6674 ASM_OUTPUT_DWARF_STRING (asm_out_file,
6675 files[file_idx].path
6676 + dirs[dir_idx].length);
6677 fprintf (asm_out_file, "%s File Entry: 0x%x\n",
6678 ASM_COMMENT_START, i);
6680 else
6681 ASM_OUTPUT_ASCII (asm_out_file,
6682 files[file_idx].path + dirs[dir_idx].length,
6683 (files[file_idx].length
6684 - dirs[dir_idx].length) + 1);
6686 /* Include directory index. */
6687 output_uleb128 (dirs[dir_idx].used);
6688 fputc ('\n', asm_out_file);
6690 /* Modification time. */
6691 output_uleb128 (0);
6692 fputc ('\n', asm_out_file);
6694 /* File length in bytes. */
6695 output_uleb128 (0);
6696 fputc ('\n', asm_out_file);
6699 /* Terminate the file name table */
6700 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6701 if (flag_debug_asm)
6702 fprintf (asm_out_file, "\t%s End file name table", ASM_COMMENT_START);
6703 fputc ('\n', asm_out_file);
6707 /* Output the source line number correspondence information. This
6708 information goes into the .debug_line section. */
6710 static void
6711 output_line_info ()
6713 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6714 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6715 register unsigned opc;
6716 register unsigned n_op_args;
6717 register unsigned long lt_index;
6718 register unsigned long current_line;
6719 register long line_offset;
6720 register long line_delta;
6721 register unsigned long current_file;
6722 register unsigned long function;
6724 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
6725 if (flag_debug_asm)
6726 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
6727 ASM_COMMENT_START);
6729 fputc ('\n', asm_out_file);
6730 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
6731 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6732 if (flag_debug_asm)
6733 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6735 fputc ('\n', asm_out_file);
6736 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
6737 if (flag_debug_asm)
6738 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
6740 fputc ('\n', asm_out_file);
6741 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
6742 if (flag_debug_asm)
6743 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
6744 ASM_COMMENT_START);
6746 fputc ('\n', asm_out_file);
6747 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
6748 if (flag_debug_asm)
6749 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
6750 ASM_COMMENT_START);
6752 fputc ('\n', asm_out_file);
6753 fprintf (asm_out_file, "%s%d", ASM_BYTE_OP, DWARF_LINE_BASE);
6754 if (flag_debug_asm)
6755 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
6756 ASM_COMMENT_START);
6758 fputc ('\n', asm_out_file);
6759 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
6760 if (flag_debug_asm)
6761 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
6762 ASM_COMMENT_START);
6764 fputc ('\n', asm_out_file);
6765 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
6766 if (flag_debug_asm)
6767 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
6769 fputc ('\n', asm_out_file);
6770 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6772 switch (opc)
6774 case DW_LNS_advance_pc:
6775 case DW_LNS_advance_line:
6776 case DW_LNS_set_file:
6777 case DW_LNS_set_column:
6778 case DW_LNS_fixed_advance_pc:
6779 n_op_args = 1;
6780 break;
6781 default:
6782 n_op_args = 0;
6783 break;
6785 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
6786 if (flag_debug_asm)
6787 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
6788 ASM_COMMENT_START, opc, n_op_args);
6789 fputc ('\n', asm_out_file);
6792 /* Write out the information about the files we use. */
6793 output_file_names ();
6795 /* We used to set the address register to the first location in the text
6796 section here, but that didn't accomplish anything since we already
6797 have a line note for the opening brace of the first function. */
6799 /* Generate the line number to PC correspondence table, encoded as
6800 a series of state machine operations. */
6801 current_file = 1;
6802 current_line = 1;
6803 strcpy (prev_line_label, text_section_label);
6804 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6806 register dw_line_info_ref line_info = &line_info_table[lt_index];
6808 #if 0
6809 /* Disable this optimization for now; GDB wants to see two line notes
6810 at the beginning of a function so it can find the end of the
6811 prologue. */
6813 /* Don't emit anything for redundant notes. Just updating the
6814 address doesn't accomplish anything, because we already assume
6815 that anything after the last address is this line. */
6816 if (line_info->dw_line_num == current_line
6817 && line_info->dw_file_num == current_file)
6818 continue;
6819 #endif
6821 /* Emit debug info for the address of the current line, choosing
6822 the encoding that uses the least amount of space. */
6823 /* ??? Unfortunately, we have little choice here currently, and must
6824 always use the most general form. Gcc does not know the address
6825 delta itself, so we can't use DW_LNS_advance_pc. There are no known
6826 dwarf2 aware assemblers at this time, so we can't use any special
6827 pseudo ops that would allow the assembler to optimally encode this for
6828 us. Many ports do have length attributes which will give an upper
6829 bound on the address range. We could perhaps use length attributes
6830 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
6831 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6832 if (0)
6834 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6835 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6836 if (flag_debug_asm)
6837 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6838 ASM_COMMENT_START);
6840 fputc ('\n', asm_out_file);
6841 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
6842 fputc ('\n', asm_out_file);
6844 else
6846 /* This can handle any delta. This takes
6847 4+DWARF2_ADDR_SIZE bytes. */
6848 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6849 if (flag_debug_asm)
6850 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6851 ASM_COMMENT_START);
6852 fputc ('\n', asm_out_file);
6853 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6854 fputc ('\n', asm_out_file);
6855 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6856 fputc ('\n', asm_out_file);
6857 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6858 fputc ('\n', asm_out_file);
6860 strcpy (prev_line_label, line_label);
6862 /* Emit debug info for the source file of the current line, if
6863 different from the previous line. */
6864 if (line_info->dw_file_num != current_file)
6866 current_file = line_info->dw_file_num;
6867 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
6868 if (flag_debug_asm)
6869 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
6871 fputc ('\n', asm_out_file);
6872 output_uleb128 (current_file);
6873 if (flag_debug_asm)
6874 fprintf (asm_out_file, " (\"%s\")",
6875 line_file_table.table[current_file]);
6877 fputc ('\n', asm_out_file);
6880 /* Emit debug info for the current line number, choosing the encoding
6881 that uses the least amount of space. */
6882 if (line_info->dw_line_num != current_line)
6884 line_offset = line_info->dw_line_num - current_line;
6885 line_delta = line_offset - DWARF_LINE_BASE;
6886 current_line = line_info->dw_line_num;
6887 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6889 /* This can handle deltas from -10 to 234, using the current
6890 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6891 takes 1 byte. */
6892 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6893 DWARF_LINE_OPCODE_BASE + line_delta);
6894 if (flag_debug_asm)
6895 fprintf (asm_out_file,
6896 "\t%s line %ld", ASM_COMMENT_START, current_line);
6898 fputc ('\n', asm_out_file);
6900 else
6902 /* This can handle any delta. This takes at least 4 bytes,
6903 depending on the value being encoded. */
6904 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
6905 if (flag_debug_asm)
6906 fprintf (asm_out_file, "\t%s advance to line %ld",
6907 ASM_COMMENT_START, current_line);
6909 fputc ('\n', asm_out_file);
6910 output_sleb128 (line_offset);
6911 fputc ('\n', asm_out_file);
6912 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6913 if (flag_debug_asm)
6914 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6915 fputc ('\n', asm_out_file);
6918 else
6920 /* We still need to start a new row, so output a copy insn. */
6921 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
6922 if (flag_debug_asm)
6923 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
6924 fputc ('\n', asm_out_file);
6928 /* Emit debug info for the address of the end of the function. */
6929 if (0)
6931 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6932 if (flag_debug_asm)
6933 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6934 ASM_COMMENT_START);
6936 fputc ('\n', asm_out_file);
6937 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
6938 fputc ('\n', asm_out_file);
6940 else
6942 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6943 if (flag_debug_asm)
6944 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
6945 fputc ('\n', asm_out_file);
6946 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6947 fputc ('\n', asm_out_file);
6948 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6949 fputc ('\n', asm_out_file);
6950 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
6951 fputc ('\n', asm_out_file);
6954 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6955 if (flag_debug_asm)
6956 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
6958 fputc ('\n', asm_out_file);
6959 output_uleb128 (1);
6960 fputc ('\n', asm_out_file);
6961 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
6962 fputc ('\n', asm_out_file);
6964 function = 0;
6965 current_file = 1;
6966 current_line = 1;
6967 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
6969 register dw_separate_line_info_ref line_info
6970 = &separate_line_info_table[lt_index];
6972 #if 0
6973 /* Don't emit anything for redundant notes. */
6974 if (line_info->dw_line_num == current_line
6975 && line_info->dw_file_num == current_file
6976 && line_info->function == function)
6977 goto cont;
6978 #endif
6980 /* Emit debug info for the address of the current line. If this is
6981 a new function, or the first line of a function, then we need
6982 to handle it differently. */
6983 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
6984 lt_index);
6985 if (function != line_info->function)
6987 function = line_info->function;
6989 /* Set the address register to the first line in the function */
6990 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6991 if (flag_debug_asm)
6992 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6993 ASM_COMMENT_START);
6995 fputc ('\n', asm_out_file);
6996 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6997 fputc ('\n', asm_out_file);
6998 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6999 fputc ('\n', asm_out_file);
7000 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7001 fputc ('\n', asm_out_file);
7003 else
7005 /* ??? See the DW_LNS_advance_pc comment above. */
7006 if (0)
7008 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7009 if (flag_debug_asm)
7010 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7011 ASM_COMMENT_START);
7013 fputc ('\n', asm_out_file);
7014 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
7015 prev_line_label);
7016 fputc ('\n', asm_out_file);
7018 else
7020 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7021 if (flag_debug_asm)
7022 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7023 ASM_COMMENT_START);
7024 fputc ('\n', asm_out_file);
7025 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7026 fputc ('\n', asm_out_file);
7027 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7028 fputc ('\n', asm_out_file);
7029 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7030 fputc ('\n', asm_out_file);
7033 strcpy (prev_line_label, line_label);
7035 /* Emit debug info for the source file of the current line, if
7036 different from the previous line. */
7037 if (line_info->dw_file_num != current_file)
7039 current_file = line_info->dw_file_num;
7040 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
7041 if (flag_debug_asm)
7042 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
7044 fputc ('\n', asm_out_file);
7045 output_uleb128 (current_file);
7046 if (flag_debug_asm)
7047 fprintf (asm_out_file, " (\"%s\")",
7048 line_file_table.table[current_file]);
7050 fputc ('\n', asm_out_file);
7053 /* Emit debug info for the current line number, choosing the encoding
7054 that uses the least amount of space. */
7055 if (line_info->dw_line_num != current_line)
7057 line_offset = line_info->dw_line_num - current_line;
7058 line_delta = line_offset - DWARF_LINE_BASE;
7059 current_line = line_info->dw_line_num;
7060 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7062 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
7063 DWARF_LINE_OPCODE_BASE + line_delta);
7064 if (flag_debug_asm)
7065 fprintf (asm_out_file,
7066 "\t%s line %ld", ASM_COMMENT_START, current_line);
7068 fputc ('\n', asm_out_file);
7070 else
7072 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
7073 if (flag_debug_asm)
7074 fprintf (asm_out_file, "\t%s advance to line %ld",
7075 ASM_COMMENT_START, current_line);
7077 fputc ('\n', asm_out_file);
7078 output_sleb128 (line_offset);
7079 fputc ('\n', asm_out_file);
7080 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7081 if (flag_debug_asm)
7082 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7083 fputc ('\n', asm_out_file);
7086 else
7088 /* We still need to start a new row, so output a copy insn. */
7089 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7090 if (flag_debug_asm)
7091 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7092 fputc ('\n', asm_out_file);
7095 #if 0
7096 cont:
7097 #endif
7098 ++lt_index;
7100 /* If we're done with a function, end its sequence. */
7101 if (lt_index == separate_line_info_table_in_use
7102 || separate_line_info_table[lt_index].function != function)
7104 current_file = 1;
7105 current_line = 1;
7107 /* Emit debug info for the address of the end of the function. */
7108 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7109 if (0)
7111 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7112 if (flag_debug_asm)
7113 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7114 ASM_COMMENT_START);
7116 fputc ('\n', asm_out_file);
7117 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
7118 prev_line_label);
7119 fputc ('\n', asm_out_file);
7121 else
7123 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7124 if (flag_debug_asm)
7125 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7126 ASM_COMMENT_START);
7127 fputc ('\n', asm_out_file);
7128 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7129 fputc ('\n', asm_out_file);
7130 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7131 fputc ('\n', asm_out_file);
7132 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7133 fputc ('\n', asm_out_file);
7136 /* Output the marker for the end of this sequence. */
7137 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7138 if (flag_debug_asm)
7139 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
7140 ASM_COMMENT_START);
7142 fputc ('\n', asm_out_file);
7143 output_uleb128 (1);
7144 fputc ('\n', asm_out_file);
7145 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
7146 fputc ('\n', asm_out_file);
7150 /* Output the marker for the end of the line number info. */
7151 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
7154 /* Given a pointer to a tree node for some base type, return a pointer to
7155 a DIE that describes the given type.
7157 This routine must only be called for GCC type nodes that correspond to
7158 Dwarf base (fundamental) types. */
7160 static dw_die_ref
7161 base_type_die (type)
7162 register tree type;
7164 register dw_die_ref base_type_result;
7165 register const char *type_name;
7166 register enum dwarf_type encoding;
7167 register tree name = TYPE_NAME (type);
7169 if (TREE_CODE (type) == ERROR_MARK
7170 || TREE_CODE (type) == VOID_TYPE)
7171 return 0;
7173 if (name)
7175 if (TREE_CODE (name) == TYPE_DECL)
7176 name = DECL_NAME (name);
7178 type_name = IDENTIFIER_POINTER (name);
7180 else
7181 type_name = "__unknown__";
7183 switch (TREE_CODE (type))
7185 case INTEGER_TYPE:
7186 /* Carefully distinguish the C character types, without messing
7187 up if the language is not C. Note that we check only for the names
7188 that contain spaces; other names might occur by coincidence in other
7189 languages. */
7190 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7191 && (type == char_type_node
7192 || ! strcmp (type_name, "signed char")
7193 || ! strcmp (type_name, "unsigned char"))))
7195 if (TREE_UNSIGNED (type))
7196 encoding = DW_ATE_unsigned;
7197 else
7198 encoding = DW_ATE_signed;
7199 break;
7201 /* else fall through. */
7203 case CHAR_TYPE:
7204 /* GNU Pascal/Ada CHAR type. Not used in C. */
7205 if (TREE_UNSIGNED (type))
7206 encoding = DW_ATE_unsigned_char;
7207 else
7208 encoding = DW_ATE_signed_char;
7209 break;
7211 case REAL_TYPE:
7212 encoding = DW_ATE_float;
7213 break;
7215 /* Dwarf2 doesn't know anything about complex ints, so use
7216 a user defined type for it. */
7217 case COMPLEX_TYPE:
7218 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7219 encoding = DW_ATE_complex_float;
7220 else
7221 encoding = DW_ATE_lo_user;
7222 break;
7224 case BOOLEAN_TYPE:
7225 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7226 encoding = DW_ATE_boolean;
7227 break;
7229 default:
7230 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
7233 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
7234 if (demangle_name_func)
7235 type_name = (*demangle_name_func) (type_name);
7237 add_AT_string (base_type_result, DW_AT_name, type_name);
7238 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7239 int_size_in_bytes (type));
7240 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7242 return base_type_result;
7245 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7246 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7247 a given type is generally the same as the given type, except that if the
7248 given type is a pointer or reference type, then the root type of the given
7249 type is the root type of the "basis" type for the pointer or reference
7250 type. (This definition of the "root" type is recursive.) Also, the root
7251 type of a `const' qualified type or a `volatile' qualified type is the
7252 root type of the given type without the qualifiers. */
7254 static tree
7255 root_type (type)
7256 register tree type;
7258 if (TREE_CODE (type) == ERROR_MARK)
7259 return error_mark_node;
7261 switch (TREE_CODE (type))
7263 case ERROR_MARK:
7264 return error_mark_node;
7266 case POINTER_TYPE:
7267 case REFERENCE_TYPE:
7268 return type_main_variant (root_type (TREE_TYPE (type)));
7270 default:
7271 return type_main_variant (type);
7275 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7276 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7278 static inline int
7279 is_base_type (type)
7280 register tree type;
7282 switch (TREE_CODE (type))
7284 case ERROR_MARK:
7285 case VOID_TYPE:
7286 case INTEGER_TYPE:
7287 case REAL_TYPE:
7288 case COMPLEX_TYPE:
7289 case BOOLEAN_TYPE:
7290 case CHAR_TYPE:
7291 return 1;
7293 case SET_TYPE:
7294 case ARRAY_TYPE:
7295 case RECORD_TYPE:
7296 case UNION_TYPE:
7297 case QUAL_UNION_TYPE:
7298 case ENUMERAL_TYPE:
7299 case FUNCTION_TYPE:
7300 case METHOD_TYPE:
7301 case POINTER_TYPE:
7302 case REFERENCE_TYPE:
7303 case FILE_TYPE:
7304 case OFFSET_TYPE:
7305 case LANG_TYPE:
7306 return 0;
7308 default:
7309 abort ();
7312 return 0;
7315 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7316 entry that chains various modifiers in front of the given type. */
7318 static dw_die_ref
7319 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7320 register tree type;
7321 register int is_const_type;
7322 register int is_volatile_type;
7323 register dw_die_ref context_die;
7325 register enum tree_code code = TREE_CODE (type);
7326 register dw_die_ref mod_type_die = NULL;
7327 register dw_die_ref sub_die = NULL;
7328 register tree item_type = NULL;
7330 if (code != ERROR_MARK)
7332 type = build_type_variant (type, is_const_type, is_volatile_type);
7334 mod_type_die = lookup_type_die (type);
7335 if (mod_type_die)
7336 return mod_type_die;
7338 /* Handle C typedef types. */
7339 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7340 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
7342 tree dtype = TREE_TYPE (TYPE_NAME (type));
7343 if (type == dtype)
7345 /* For a named type, use the typedef. */
7346 gen_type_die (type, context_die);
7347 mod_type_die = lookup_type_die (type);
7350 else if (is_const_type < TYPE_READONLY (dtype)
7351 || is_volatile_type < TYPE_VOLATILE (dtype))
7352 /* cv-unqualified version of named type. Just use the unnamed
7353 type to which it refers. */
7354 mod_type_die
7355 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
7356 is_const_type, is_volatile_type,
7357 context_die);
7358 /* Else cv-qualified version of named type; fall through. */
7361 if (mod_type_die)
7362 /* OK. */
7364 else if (is_const_type)
7366 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7367 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7369 else if (is_volatile_type)
7371 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7372 sub_die = modified_type_die (type, 0, 0, context_die);
7374 else if (code == POINTER_TYPE)
7376 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7377 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7378 #if 0
7379 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7380 #endif
7381 item_type = TREE_TYPE (type);
7383 else if (code == REFERENCE_TYPE)
7385 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7386 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7387 #if 0
7388 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7389 #endif
7390 item_type = TREE_TYPE (type);
7392 else if (is_base_type (type))
7393 mod_type_die = base_type_die (type);
7394 else
7396 gen_type_die (type, context_die);
7398 /* We have to get the type_main_variant here (and pass that to the
7399 `lookup_type_die' routine) because the ..._TYPE node we have
7400 might simply be a *copy* of some original type node (where the
7401 copy was created to help us keep track of typedef names) and
7402 that copy might have a different TYPE_UID from the original
7403 ..._TYPE node. */
7404 mod_type_die = lookup_type_die (type_main_variant (type));
7405 if (mod_type_die == NULL)
7406 abort ();
7410 equate_type_number_to_die (type, mod_type_die);
7411 if (item_type)
7412 /* We must do this after the equate_type_number_to_die call, in case
7413 this is a recursive type. This ensures that the modified_type_die
7414 recursion will terminate even if the type is recursive. Recursive
7415 types are possible in Ada. */
7416 sub_die = modified_type_die (item_type,
7417 TYPE_READONLY (item_type),
7418 TYPE_VOLATILE (item_type),
7419 context_die);
7421 if (sub_die != NULL)
7422 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7424 return mod_type_die;
7427 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7428 an enumerated type. */
7430 static inline int
7431 type_is_enum (type)
7432 register tree type;
7434 return TREE_CODE (type) == ENUMERAL_TYPE;
7437 /* Return the register number described by a given RTL node. */
7439 static unsigned int
7440 reg_number (rtl)
7441 register rtx rtl;
7443 register unsigned regno = REGNO (rtl);
7445 if (regno >= FIRST_PSEUDO_REGISTER)
7447 warning ("internal regno botch: regno = %d\n", regno);
7448 regno = 0;
7451 regno = DBX_REGISTER_NUMBER (regno);
7452 return regno;
7455 /* Return a location descriptor that designates a machine register. */
7457 static dw_loc_descr_ref
7458 reg_loc_descriptor (rtl)
7459 register rtx rtl;
7461 register dw_loc_descr_ref loc_result = NULL;
7462 register unsigned reg = reg_number (rtl);
7464 if (reg <= 31)
7465 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7466 else
7467 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7469 return loc_result;
7472 /* Return a location descriptor that designates a constant. */
7474 static dw_loc_descr_ref
7475 int_loc_descriptor (i)
7476 HOST_WIDE_INT i;
7478 enum dwarf_location_atom op;
7480 /* Pick the smallest representation of a constant, rather than just
7481 defaulting to the LEB encoding. */
7482 if (i >= 0)
7484 if (i <= 31)
7485 op = DW_OP_lit0 + i;
7486 else if (i <= 0xff)
7487 op = DW_OP_const1u;
7488 else if (i <= 0xffff)
7489 op = DW_OP_const2u;
7490 else if (HOST_BITS_PER_WIDE_INT == 32
7491 || i <= 0xffffffff)
7492 op = DW_OP_const4u;
7493 else
7494 op = DW_OP_constu;
7496 else
7498 if (i >= -0x80)
7499 op = DW_OP_const1s;
7500 else if (i >= -0x8000)
7501 op = DW_OP_const2s;
7502 else if (HOST_BITS_PER_WIDE_INT == 32
7503 || i >= -0x80000000)
7504 op = DW_OP_const4s;
7505 else
7506 op = DW_OP_consts;
7509 return new_loc_descr (op, i, 0);
7512 /* Return a location descriptor that designates a base+offset location. */
7514 static dw_loc_descr_ref
7515 based_loc_descr (reg, offset)
7516 unsigned reg;
7517 long int offset;
7519 register dw_loc_descr_ref loc_result;
7520 /* For the "frame base", we use the frame pointer or stack pointer
7521 registers, since the RTL for local variables is relative to one of
7522 them. */
7523 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7524 ? HARD_FRAME_POINTER_REGNUM
7525 : STACK_POINTER_REGNUM);
7527 if (reg == fp_reg)
7528 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7529 else if (reg <= 31)
7530 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7531 else
7532 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7534 return loc_result;
7537 /* Return true if this RTL expression describes a base+offset calculation. */
7539 static inline int
7540 is_based_loc (rtl)
7541 register rtx rtl;
7543 return (GET_CODE (rtl) == PLUS
7544 && ((GET_CODE (XEXP (rtl, 0)) == REG
7545 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7548 /* The following routine converts the RTL for a variable or parameter
7549 (resident in memory) into an equivalent Dwarf representation of a
7550 mechanism for getting the address of that same variable onto the top of a
7551 hypothetical "address evaluation" stack.
7553 When creating memory location descriptors, we are effectively transforming
7554 the RTL for a memory-resident object into its Dwarf postfix expression
7555 equivalent. This routine recursively descends an RTL tree, turning
7556 it into Dwarf postfix code as it goes.
7558 MODE is the mode of the memory reference, needed to handle some
7559 autoincrement addressing modes. */
7561 static dw_loc_descr_ref
7562 mem_loc_descriptor (rtl, mode)
7563 register rtx rtl;
7564 enum machine_mode mode;
7566 dw_loc_descr_ref mem_loc_result = NULL;
7567 /* Note that for a dynamically sized array, the location we will generate a
7568 description of here will be the lowest numbered location which is
7569 actually within the array. That's *not* necessarily the same as the
7570 zeroth element of the array. */
7572 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7573 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7574 #endif
7576 switch (GET_CODE (rtl))
7578 case POST_INC:
7579 case POST_DEC:
7580 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7581 just fall into the SUBREG code. */
7583 /* Fall through. */
7585 case SUBREG:
7586 /* The case of a subreg may arise when we have a local (register)
7587 variable or a formal (register) parameter which doesn't quite fill
7588 up an entire register. For now, just assume that it is
7589 legitimate to make the Dwarf info refer to the whole register which
7590 contains the given subreg. */
7591 rtl = XEXP (rtl, 0);
7593 /* Fall through. */
7595 case REG:
7596 /* Whenever a register number forms a part of the description of the
7597 method for calculating the (dynamic) address of a memory resident
7598 object, DWARF rules require the register number be referred to as
7599 a "base register". This distinction is not based in any way upon
7600 what category of register the hardware believes the given register
7601 belongs to. This is strictly DWARF terminology we're dealing with
7602 here. Note that in cases where the location of a memory-resident
7603 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7604 OP_CONST (0)) the actual DWARF location descriptor that we generate
7605 may just be OP_BASEREG (basereg). This may look deceptively like
7606 the object in question was allocated to a register (rather than in
7607 memory) so DWARF consumers need to be aware of the subtle
7608 distinction between OP_REG and OP_BASEREG. */
7609 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7610 break;
7612 case MEM:
7614 dw_loc_descr_ref deref;
7616 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7618 if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
7619 deref = new_loc_descr (DW_OP_deref, 0, 0);
7620 else
7621 deref = new_loc_descr (DW_OP_deref_size, GET_MODE_SIZE (mode), 0);
7623 add_loc_descr (&mem_loc_result, deref);
7625 break;
7627 case LABEL_REF:
7628 /* Some ports can transform a symbol ref into a label ref, because
7629 the symbol ref is too far away and has to be dumped into a constant
7630 pool. */
7631 case CONST:
7632 case SYMBOL_REF:
7633 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7634 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7635 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7636 break;
7638 case PRE_INC:
7639 case PRE_DEC:
7640 /* Turn these into a PLUS expression and fall into the PLUS code
7641 below. */
7642 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7643 GEN_INT (GET_CODE (rtl) == PRE_INC
7644 ? GET_MODE_UNIT_SIZE (mode)
7645 : -GET_MODE_UNIT_SIZE (mode)));
7647 /* Fall through. */
7649 case PLUS:
7650 if (is_based_loc (rtl))
7651 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7652 INTVAL (XEXP (rtl, 1)));
7653 else
7655 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7657 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7658 && INTVAL (XEXP (rtl, 1)) >= 0)
7660 add_loc_descr (&mem_loc_result,
7661 new_loc_descr (DW_OP_plus_uconst,
7662 INTVAL (XEXP (rtl, 1)), 0));
7664 else
7666 add_loc_descr (&mem_loc_result,
7667 mem_loc_descriptor (XEXP (rtl, 1), mode));
7668 add_loc_descr (&mem_loc_result,
7669 new_loc_descr (DW_OP_plus, 0, 0));
7672 break;
7674 case MULT:
7675 /* If a pseudo-reg is optimized away, it is possible for it to
7676 be replaced with a MEM containing a multiply. */
7677 add_loc_descr (&mem_loc_result,
7678 mem_loc_descriptor (XEXP (rtl, 0), mode));
7679 add_loc_descr (&mem_loc_result,
7680 mem_loc_descriptor (XEXP (rtl, 1), mode));
7681 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7682 break;
7684 case CONST_INT:
7685 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7686 break;
7688 default:
7689 abort ();
7692 return mem_loc_result;
7695 /* Return a descriptor that describes the concatenation of two locations.
7696 This is typically a complex variable. */
7698 static dw_loc_descr_ref
7699 concat_loc_descriptor (x0, x1)
7700 register rtx x0, x1;
7702 dw_loc_descr_ref cc_loc_result = NULL;
7704 if (!is_pseudo_reg (x0)
7705 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7706 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7707 add_loc_descr (&cc_loc_result,
7708 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7710 if (!is_pseudo_reg (x1)
7711 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7712 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7713 add_loc_descr (&cc_loc_result,
7714 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7716 return cc_loc_result;
7719 /* Output a proper Dwarf location descriptor for a variable or parameter
7720 which is either allocated in a register or in a memory location. For a
7721 register, we just generate an OP_REG and the register number. For a
7722 memory location we provide a Dwarf postfix expression describing how to
7723 generate the (dynamic) address of the object onto the address stack. */
7725 static dw_loc_descr_ref
7726 loc_descriptor (rtl)
7727 register rtx rtl;
7729 dw_loc_descr_ref loc_result = NULL;
7730 switch (GET_CODE (rtl))
7732 case SUBREG:
7733 /* The case of a subreg may arise when we have a local (register)
7734 variable or a formal (register) parameter which doesn't quite fill
7735 up an entire register. For now, just assume that it is
7736 legitimate to make the Dwarf info refer to the whole register which
7737 contains the given subreg. */
7738 rtl = XEXP (rtl, 0);
7740 /* Fall through. */
7742 case REG:
7743 loc_result = reg_loc_descriptor (rtl);
7744 break;
7746 case MEM:
7747 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7748 break;
7750 case CONCAT:
7751 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7752 break;
7754 default:
7755 abort ();
7758 return loc_result;
7761 /* Similar, but generate the descriptor from trees instead of rtl.
7762 This comes up particularly with variable length arrays. */
7764 static dw_loc_descr_ref
7765 loc_descriptor_from_tree (loc, addressp)
7766 tree loc;
7767 int addressp;
7769 dw_loc_descr_ref ret = NULL;
7770 int indirect_size = 0;
7771 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7772 enum dwarf_location_atom op;
7774 /* ??? Most of the time we do not take proper care for sign/zero
7775 extending the values properly. Hopefully this won't be a real
7776 problem... */
7778 switch (TREE_CODE (loc))
7780 case ERROR_MARK:
7781 break;
7783 case VAR_DECL:
7784 case PARM_DECL:
7786 rtx rtl = rtl_for_decl_location (loc);
7787 enum machine_mode mode = DECL_MODE (loc);
7789 if (rtl == NULL_RTX)
7790 break;
7791 else if (CONSTANT_P (rtl))
7793 ret = new_loc_descr (DW_OP_addr, 0, 0);
7794 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7795 ret->dw_loc_oprnd1.v.val_addr = rtl;
7796 indirect_size = GET_MODE_SIZE (mode);
7798 else
7800 if (GET_CODE (rtl) == MEM)
7802 indirect_size = GET_MODE_SIZE (mode);
7803 rtl = XEXP (rtl, 0);
7805 ret = mem_loc_descriptor (rtl, mode);
7808 break;
7810 case INDIRECT_REF:
7811 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7812 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
7813 break;
7815 case COMPONENT_REF:
7816 case BIT_FIELD_REF:
7817 case ARRAY_REF:
7819 tree obj, offset;
7820 HOST_WIDE_INT bitsize, bitpos, bytepos;
7821 enum machine_mode mode;
7822 int volatilep;
7823 unsigned int alignment;
7825 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7826 &unsignedp, &volatilep, &alignment);
7827 ret = loc_descriptor_from_tree (obj, 1);
7829 if (offset != NULL_TREE)
7831 /* Variable offset. */
7832 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7833 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7836 if (addressp)
7838 /* We cannot address anything not on a unit boundary. */
7839 if (bitpos % BITS_PER_UNIT != 0)
7840 abort ();
7842 else
7844 if (bitpos % BITS_PER_UNIT != 0
7845 || bitsize % BITS_PER_UNIT != 0)
7847 /* ??? We could handle this by loading and shifting etc.
7848 Wait until someone needs it before expending the effort. */
7849 abort ();
7852 indirect_size = bitsize / BITS_PER_UNIT;
7855 bytepos = bitpos / BITS_PER_UNIT;
7856 if (bytepos > 0)
7857 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7858 else if (bytepos < 0)
7860 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7861 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7863 break;
7866 case INTEGER_CST:
7867 if (host_integerp (loc, 0))
7868 ret = int_loc_descriptor (tree_low_cst (loc, 0));
7869 break;
7870 break;
7872 case BIT_AND_EXPR:
7873 op = DW_OP_and;
7874 goto do_binop;
7875 case BIT_XOR_EXPR:
7876 op = DW_OP_xor;
7877 goto do_binop;
7878 case BIT_IOR_EXPR:
7879 op = DW_OP_or;
7880 goto do_binop;
7881 case TRUNC_DIV_EXPR:
7882 op = DW_OP_div;
7883 goto do_binop;
7884 case MINUS_EXPR:
7885 op = DW_OP_minus;
7886 goto do_binop;
7887 case TRUNC_MOD_EXPR:
7888 op = DW_OP_mod;
7889 goto do_binop;
7890 case MULT_EXPR:
7891 op = DW_OP_mul;
7892 goto do_binop;
7893 case LSHIFT_EXPR:
7894 op = DW_OP_shl;
7895 goto do_binop;
7896 case RSHIFT_EXPR:
7897 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
7898 goto do_binop;
7899 case PLUS_EXPR:
7900 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
7901 && host_integerp (TREE_OPERAND (loc, 1), 0))
7903 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7904 add_loc_descr (&ret,
7905 new_loc_descr (DW_OP_plus_uconst,
7906 tree_low_cst (TREE_OPERAND (loc, 1),
7908 0));
7909 break;
7911 op = DW_OP_plus;
7912 goto do_binop;
7913 case LE_EXPR:
7914 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7915 break;
7916 op = DW_OP_le;
7917 goto do_binop;
7918 case GE_EXPR:
7919 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7920 break;
7921 op = DW_OP_ge;
7922 goto do_binop;
7923 case LT_EXPR:
7924 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7925 break;
7926 op = DW_OP_lt;
7927 goto do_binop;
7928 case GT_EXPR:
7929 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7930 break;
7931 op = DW_OP_gt;
7932 goto do_binop;
7933 case EQ_EXPR:
7934 op = DW_OP_eq;
7935 goto do_binop;
7936 case NE_EXPR:
7937 op = DW_OP_ne;
7938 goto do_binop;
7940 do_binop:
7941 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7942 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
7943 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7944 break;
7946 case BIT_NOT_EXPR:
7947 op = DW_OP_not;
7948 goto do_unop;
7949 case ABS_EXPR:
7950 op = DW_OP_abs;
7951 goto do_unop;
7952 case NEGATE_EXPR:
7953 op = DW_OP_neg;
7954 goto do_unop;
7956 do_unop:
7957 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7958 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7959 break;
7961 case MAX_EXPR:
7962 loc = build (COND_EXPR, TREE_TYPE (loc),
7963 build (LT_EXPR, integer_type_node,
7964 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
7965 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
7966 /* FALLTHRU */
7968 case COND_EXPR:
7970 dw_loc_descr_ref bra_node, jump_node, tmp;
7972 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7973 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
7974 add_loc_descr (&ret, bra_node);
7976 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
7977 add_loc_descr (&ret, tmp);
7978 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
7979 add_loc_descr (&ret, jump_node);
7981 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
7982 add_loc_descr (&ret, tmp);
7983 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7984 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
7986 /* ??? Need a node to point the skip at. Use a nop. */
7987 tmp = new_loc_descr (DW_OP_nop, 0, 0);
7988 add_loc_descr (&ret, tmp);
7989 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7990 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
7992 break;
7994 default:
7995 abort ();
7998 /* If we can't fill the request for an address, die. */
7999 if (addressp && indirect_size == 0)
8000 abort ();
8002 /* If we've got an address and don't want one, dereference. */
8003 if (!addressp && indirect_size > 0)
8005 if (indirect_size > DWARF2_ADDR_SIZE)
8006 abort ();
8007 if (indirect_size == DWARF2_ADDR_SIZE)
8008 op = DW_OP_deref;
8009 else
8010 op = DW_OP_deref_size;
8011 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
8014 return ret;
8017 /* Given a value, round it up to the lowest multiple of `boundary'
8018 which is not less than the value itself. */
8020 static inline HOST_WIDE_INT
8021 ceiling (value, boundary)
8022 HOST_WIDE_INT value;
8023 unsigned int boundary;
8025 return (((value + boundary - 1) / boundary) * boundary);
8028 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8029 pointer to the declared type for the relevant field variable, or return
8030 `integer_type_node' if the given node turns out to be an
8031 ERROR_MARK node. */
8033 static inline tree
8034 field_type (decl)
8035 register tree decl;
8037 register tree type;
8039 if (TREE_CODE (decl) == ERROR_MARK)
8040 return integer_type_node;
8042 type = DECL_BIT_FIELD_TYPE (decl);
8043 if (type == NULL_TREE)
8044 type = TREE_TYPE (decl);
8046 return type;
8049 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8050 node, return the alignment in bits for the type, or else return
8051 BITS_PER_WORD if the node actually turns out to be an
8052 ERROR_MARK node. */
8054 static inline unsigned
8055 simple_type_align_in_bits (type)
8056 register tree type;
8058 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8061 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8062 node, return the size in bits for the type if it is a constant, or else
8063 return the alignment for the type if the type's size is not constant, or
8064 else return BITS_PER_WORD if the type actually turns out to be an
8065 ERROR_MARK node. */
8067 static inline unsigned HOST_WIDE_INT
8068 simple_type_size_in_bits (type)
8069 register tree type;
8071 tree type_size_tree;
8073 if (TREE_CODE (type) == ERROR_MARK)
8074 return BITS_PER_WORD;
8075 type_size_tree = TYPE_SIZE (type);
8077 if (type_size_tree == NULL_TREE)
8078 return 0;
8079 if (! host_integerp (type_size_tree, 1))
8080 return TYPE_ALIGN (type);
8081 return tree_low_cst (type_size_tree, 1);
8084 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
8085 return the byte offset of the lowest addressed byte of the "containing
8086 object" for the given FIELD_DECL, or return 0 if we are unable to
8087 determine what that offset is, either because the argument turns out to
8088 be a pointer to an ERROR_MARK node, or because the offset is actually
8089 variable. (We can't handle the latter case just yet). */
8091 static HOST_WIDE_INT
8092 field_byte_offset (decl)
8093 register tree decl;
8095 unsigned int type_align_in_bytes;
8096 unsigned int type_align_in_bits;
8097 unsigned HOST_WIDE_INT type_size_in_bits;
8098 HOST_WIDE_INT object_offset_in_align_units;
8099 HOST_WIDE_INT object_offset_in_bits;
8100 HOST_WIDE_INT object_offset_in_bytes;
8101 tree type;
8102 tree field_size_tree;
8103 HOST_WIDE_INT bitpos_int;
8104 HOST_WIDE_INT deepest_bitpos;
8105 unsigned HOST_WIDE_INT field_size_in_bits;
8107 if (TREE_CODE (decl) == ERROR_MARK)
8108 return 0;
8110 if (TREE_CODE (decl) != FIELD_DECL)
8111 abort ();
8113 type = field_type (decl);
8114 field_size_tree = DECL_SIZE (decl);
8116 /* The size could be unspecified if there was an error, or for
8117 a flexible array member. */
8118 if (! field_size_tree)
8119 field_size_tree = bitsize_zero_node;
8121 /* We cannot yet cope with fields whose positions are variable, so
8122 for now, when we see such things, we simply return 0. Someday, we may
8123 be able to handle such cases, but it will be damn difficult. */
8124 if (! host_integerp (bit_position (decl), 0))
8125 return 0;
8127 bitpos_int = int_bit_position (decl);
8129 /* If we don't know the size of the field, pretend it's a full word. */
8130 if (host_integerp (field_size_tree, 1))
8131 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8132 else
8133 field_size_in_bits = BITS_PER_WORD;
8135 type_size_in_bits = simple_type_size_in_bits (type);
8136 type_align_in_bits = simple_type_align_in_bits (type);
8137 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
8139 /* Note that the GCC front-end doesn't make any attempt to keep track of
8140 the starting bit offset (relative to the start of the containing
8141 structure type) of the hypothetical "containing object" for a bit-
8142 field. Thus, when computing the byte offset value for the start of the
8143 "containing object" of a bit-field, we must deduce this information on
8144 our own. This can be rather tricky to do in some cases. For example,
8145 handling the following structure type definition when compiling for an
8146 i386/i486 target (which only aligns long long's to 32-bit boundaries)
8147 can be very tricky:
8149 struct S { int field1; long long field2:31; };
8151 Fortunately, there is a simple rule-of-thumb which can be
8152 used in such cases. When compiling for an i386/i486, GCC will allocate
8153 8 bytes for the structure shown above. It decides to do this based upon
8154 one simple rule for bit-field allocation. Quite simply, GCC allocates
8155 each "containing object" for each bit-field at the first (i.e. lowest
8156 addressed) legitimate alignment boundary (based upon the required
8157 minimum alignment for the declared type of the field) which it can
8158 possibly use, subject to the condition that there is still enough
8159 available space remaining in the containing object (when allocated at
8160 the selected point) to fully accommodate all of the bits of the
8161 bit-field itself. This simple rule makes it obvious why GCC allocates
8162 8 bytes for each object of the structure type shown above. When looking
8163 for a place to allocate the "containing object" for `field2', the
8164 compiler simply tries to allocate a 64-bit "containing object" at each
8165 successive 32-bit boundary (starting at zero) until it finds a place to
8166 allocate that 64- bit field such that at least 31 contiguous (and
8167 previously unallocated) bits remain within that selected 64 bit field.
8168 (As it turns out, for the example above, the compiler finds that it is
8169 OK to allocate the "containing object" 64-bit field at bit-offset zero
8170 within the structure type.) Here we attempt to work backwards from the
8171 limited set of facts we're given, and we try to deduce from those facts,
8172 where GCC must have believed that the containing object started (within
8173 the structure type). The value we deduce is then used (by the callers of
8174 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
8175 for fields (both bit-fields and, in the case of DW_AT_location, regular
8176 fields as well). */
8178 /* Figure out the bit-distance from the start of the structure to the
8179 "deepest" bit of the bit-field. */
8180 deepest_bitpos = bitpos_int + field_size_in_bits;
8182 /* This is the tricky part. Use some fancy footwork to deduce where the
8183 lowest addressed bit of the containing object must be. */
8184 object_offset_in_bits
8185 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
8187 /* Compute the offset of the containing object in "alignment units". */
8188 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
8190 /* Compute the offset of the containing object in bytes. */
8191 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
8193 return object_offset_in_bytes;
8196 /* The following routines define various Dwarf attributes and any data
8197 associated with them. */
8199 /* Add a location description attribute value to a DIE.
8201 This emits location attributes suitable for whole variables and
8202 whole parameters. Note that the location attributes for struct fields are
8203 generated by the routine `data_member_location_attribute' below. */
8205 static void
8206 add_AT_location_description (die, attr_kind, rtl)
8207 dw_die_ref die;
8208 enum dwarf_attribute attr_kind;
8209 register rtx rtl;
8211 /* Handle a special case. If we are about to output a location descriptor
8212 for a variable or parameter which has been optimized out of existence,
8213 don't do that. A variable which has been optimized out
8214 of existence will have a DECL_RTL value which denotes a pseudo-reg.
8215 Currently, in some rare cases, variables can have DECL_RTL values which
8216 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
8217 elsewhere in the compiler. We treat such cases as if the variable(s) in
8218 question had been optimized out of existence. */
8220 if (is_pseudo_reg (rtl)
8221 || (GET_CODE (rtl) == MEM
8222 && is_pseudo_reg (XEXP (rtl, 0)))
8223 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
8224 references the internal argument pointer (a pseudo) in a function
8225 where all references to the internal argument pointer were
8226 eliminated via the optimizers. */
8227 || (GET_CODE (rtl) == MEM
8228 && GET_CODE (XEXP (rtl, 0)) == PLUS
8229 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
8230 || (GET_CODE (rtl) == CONCAT
8231 && is_pseudo_reg (XEXP (rtl, 0))
8232 && is_pseudo_reg (XEXP (rtl, 1))))
8233 return;
8235 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
8238 /* Attach the specialized form of location attribute used for data
8239 members of struct and union types. In the special case of a
8240 FIELD_DECL node which represents a bit-field, the "offset" part
8241 of this special location descriptor must indicate the distance
8242 in bytes from the lowest-addressed byte of the containing struct
8243 or union type to the lowest-addressed byte of the "containing
8244 object" for the bit-field. (See the `field_byte_offset' function
8245 above).. For any given bit-field, the "containing object" is a
8246 hypothetical object (of some integral or enum type) within which
8247 the given bit-field lives. The type of this hypothetical
8248 "containing object" is always the same as the declared type of
8249 the individual bit-field itself (for GCC anyway... the DWARF
8250 spec doesn't actually mandate this). Note that it is the size
8251 (in bytes) of the hypothetical "containing object" which will
8252 be given in the DW_AT_byte_size attribute for this bit-field.
8253 (See the `byte_size_attribute' function below.) It is also used
8254 when calculating the value of the DW_AT_bit_offset attribute.
8255 (See the `bit_offset_attribute' function below). */
8257 static void
8258 add_data_member_location_attribute (die, decl)
8259 register dw_die_ref die;
8260 register tree decl;
8262 register unsigned long offset;
8263 register dw_loc_descr_ref loc_descr;
8264 register enum dwarf_location_atom op;
8266 if (TREE_CODE (decl) == TREE_VEC)
8267 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8268 else
8269 offset = field_byte_offset (decl);
8271 /* The DWARF2 standard says that we should assume that the structure address
8272 is already on the stack, so we can specify a structure field address
8273 by using DW_OP_plus_uconst. */
8275 #ifdef MIPS_DEBUGGING_INFO
8276 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
8277 correctly. It works only if we leave the offset on the stack. */
8278 op = DW_OP_constu;
8279 #else
8280 op = DW_OP_plus_uconst;
8281 #endif
8283 loc_descr = new_loc_descr (op, offset, 0);
8284 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8287 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8288 does not have a "location" either in memory or in a register. These
8289 things can arise in GNU C when a constant is passed as an actual parameter
8290 to an inlined function. They can also arise in C++ where declared
8291 constants do not necessarily get memory "homes". */
8293 static void
8294 add_const_value_attribute (die, rtl)
8295 register dw_die_ref die;
8296 register rtx rtl;
8298 switch (GET_CODE (rtl))
8300 case CONST_INT:
8301 /* Note that a CONST_INT rtx could represent either an integer or a
8302 floating-point constant. A CONST_INT is used whenever the constant
8303 will fit into a single word. In all such cases, the original mode
8304 of the constant value is wiped out, and the CONST_INT rtx is
8305 assigned VOIDmode. */
8306 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
8307 break;
8309 case CONST_DOUBLE:
8310 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8311 floating-point constant. A CONST_DOUBLE is used whenever the
8312 constant requires more than one word in order to be adequately
8313 represented. We output CONST_DOUBLEs as blocks. */
8315 register enum machine_mode mode = GET_MODE (rtl);
8317 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8319 register unsigned length = GET_MODE_SIZE (mode) / 4;
8320 long *array = (long *) xmalloc (sizeof (long) * length);
8321 REAL_VALUE_TYPE rv;
8323 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8324 switch (mode)
8326 case SFmode:
8327 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8328 break;
8330 case DFmode:
8331 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8332 break;
8334 case XFmode:
8335 case TFmode:
8336 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8337 break;
8339 default:
8340 abort ();
8343 add_AT_float (die, DW_AT_const_value, length, array);
8345 else
8346 add_AT_long_long (die, DW_AT_const_value,
8347 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8349 break;
8351 case CONST_STRING:
8352 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8353 break;
8355 case SYMBOL_REF:
8356 case LABEL_REF:
8357 case CONST:
8358 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8359 break;
8361 case PLUS:
8362 /* In cases where an inlined instance of an inline function is passed
8363 the address of an `auto' variable (which is local to the caller) we
8364 can get a situation where the DECL_RTL of the artificial local
8365 variable (for the inlining) which acts as a stand-in for the
8366 corresponding formal parameter (of the inline function) will look
8367 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8368 exactly a compile-time constant expression, but it isn't the address
8369 of the (artificial) local variable either. Rather, it represents the
8370 *value* which the artificial local variable always has during its
8371 lifetime. We currently have no way to represent such quasi-constant
8372 values in Dwarf, so for now we just punt and generate nothing. */
8373 break;
8375 default:
8376 /* No other kinds of rtx should be possible here. */
8377 abort ();
8382 static rtx
8383 rtl_for_decl_location (decl)
8384 tree decl;
8386 register rtx rtl;
8388 /* Here we have to decide where we are going to say the parameter "lives"
8389 (as far as the debugger is concerned). We only have a couple of
8390 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8392 DECL_RTL normally indicates where the parameter lives during most of the
8393 activation of the function. If optimization is enabled however, this
8394 could be either NULL or else a pseudo-reg. Both of those cases indicate
8395 that the parameter doesn't really live anywhere (as far as the code
8396 generation parts of GCC are concerned) during most of the function's
8397 activation. That will happen (for example) if the parameter is never
8398 referenced within the function.
8400 We could just generate a location descriptor here for all non-NULL
8401 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8402 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8403 where DECL_RTL is NULL or is a pseudo-reg.
8405 Note however that we can only get away with using DECL_INCOMING_RTL as
8406 a backup substitute for DECL_RTL in certain limited cases. In cases
8407 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8408 we can be sure that the parameter was passed using the same type as it is
8409 declared to have within the function, and that its DECL_INCOMING_RTL
8410 points us to a place where a value of that type is passed.
8412 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8413 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8414 because in these cases DECL_INCOMING_RTL points us to a value of some
8415 type which is *different* from the type of the parameter itself. Thus,
8416 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8417 such cases, the debugger would end up (for example) trying to fetch a
8418 `float' from a place which actually contains the first part of a
8419 `double'. That would lead to really incorrect and confusing
8420 output at debug-time.
8422 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8423 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8424 are a couple of exceptions however. On little-endian machines we can
8425 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8426 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8427 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8428 when (on a little-endian machine) a non-prototyped function has a
8429 parameter declared to be of type `short' or `char'. In such cases,
8430 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8431 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8432 passed `int' value. If the debugger then uses that address to fetch
8433 a `short' or a `char' (on a little-endian machine) the result will be
8434 the correct data, so we allow for such exceptional cases below.
8436 Note that our goal here is to describe the place where the given formal
8437 parameter lives during most of the function's activation (i.e. between
8438 the end of the prologue and the start of the epilogue). We'll do that
8439 as best as we can. Note however that if the given formal parameter is
8440 modified sometime during the execution of the function, then a stack
8441 backtrace (at debug-time) will show the function as having been
8442 called with the *new* value rather than the value which was
8443 originally passed in. This happens rarely enough that it is not
8444 a major problem, but it *is* a problem, and I'd like to fix it.
8446 A future version of dwarf2out.c may generate two additional
8447 attributes for any given DW_TAG_formal_parameter DIE which will
8448 describe the "passed type" and the "passed location" for the
8449 given formal parameter in addition to the attributes we now
8450 generate to indicate the "declared type" and the "active
8451 location" for each parameter. This additional set of attributes
8452 could be used by debuggers for stack backtraces. Separately, note
8453 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8454 NULL also. This happens (for example) for inlined-instances of
8455 inline function formal parameters which are never referenced.
8456 This really shouldn't be happening. All PARM_DECL nodes should
8457 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8458 doesn't currently generate these values for inlined instances of
8459 inline function parameters, so when we see such cases, we are
8460 just out-of-luck for the time being (until integrate.c
8461 gets fixed). */
8463 /* Use DECL_RTL as the "location" unless we find something better. */
8464 rtl = DECL_RTL (decl);
8466 if (TREE_CODE (decl) == PARM_DECL)
8468 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8470 tree declared_type = type_main_variant (TREE_TYPE (decl));
8471 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8473 /* This decl represents a formal parameter which was optimized out.
8474 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8475 all* cases where (rtl == NULL_RTX) just below. */
8476 if (declared_type == passed_type)
8477 rtl = DECL_INCOMING_RTL (decl);
8478 else if (! BYTES_BIG_ENDIAN
8479 && TREE_CODE (declared_type) == INTEGER_TYPE
8480 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8481 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8482 rtl = DECL_INCOMING_RTL (decl);
8485 /* If the parm was passed in registers, but lives on the stack, then
8486 make a big endian correction if the mode of the type of the
8487 parameter is not the same as the mode of the rtl. */
8488 /* ??? This is the same series of checks that are made in dbxout.c before
8489 we reach the big endian correction code there. It isn't clear if all
8490 of these checks are necessary here, but keeping them all is the safe
8491 thing to do. */
8492 else if (GET_CODE (rtl) == MEM
8493 && XEXP (rtl, 0) != const0_rtx
8494 && ! CONSTANT_P (XEXP (rtl, 0))
8495 /* Not passed in memory. */
8496 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8497 /* Not passed by invisible reference. */
8498 && (GET_CODE (XEXP (rtl, 0)) != REG
8499 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8500 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8501 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8502 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8503 #endif
8505 /* Big endian correction check. */
8506 && BYTES_BIG_ENDIAN
8507 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8508 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8509 < UNITS_PER_WORD))
8511 int offset = (UNITS_PER_WORD
8512 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8513 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8514 plus_constant (XEXP (rtl, 0), offset));
8518 if (rtl != NULL_RTX)
8520 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8521 #ifdef LEAF_REG_REMAP
8522 if (current_function_uses_only_leaf_regs)
8523 leaf_renumber_regs_insn (rtl);
8524 #endif
8527 return rtl;
8530 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8531 data attribute for a variable or a parameter. We generate the
8532 DW_AT_const_value attribute only in those cases where the given variable
8533 or parameter does not have a true "location" either in memory or in a
8534 register. This can happen (for example) when a constant is passed as an
8535 actual argument in a call to an inline function. (It's possible that
8536 these things can crop up in other ways also.) Note that one type of
8537 constant value which can be passed into an inlined function is a constant
8538 pointer. This can happen for example if an actual argument in an inlined
8539 function call evaluates to a compile-time constant address. */
8541 static void
8542 add_location_or_const_value_attribute (die, decl)
8543 register dw_die_ref die;
8544 register tree decl;
8546 register rtx rtl;
8548 if (TREE_CODE (decl) == ERROR_MARK)
8549 return;
8551 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8552 abort ();
8554 rtl = rtl_for_decl_location (decl);
8555 if (rtl == NULL_RTX)
8556 return;
8558 switch (GET_CODE (rtl))
8560 case ADDRESSOF:
8561 /* The address of a variable that was optimized away; don't emit
8562 anything. */
8563 break;
8565 case CONST_INT:
8566 case CONST_DOUBLE:
8567 case CONST_STRING:
8568 case SYMBOL_REF:
8569 case LABEL_REF:
8570 case CONST:
8571 case PLUS:
8572 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8573 add_const_value_attribute (die, rtl);
8574 break;
8576 case MEM:
8577 case REG:
8578 case SUBREG:
8579 case CONCAT:
8580 add_AT_location_description (die, DW_AT_location, rtl);
8581 break;
8583 default:
8584 abort ();
8588 /* If we don't have a copy of this variable in memory for some reason (such
8589 as a C++ member constant that doesn't have an out-of-line definition),
8590 we should tell the debugger about the constant value. */
8592 static void
8593 tree_add_const_value_attribute (var_die, decl)
8594 dw_die_ref var_die;
8595 tree decl;
8597 tree init = DECL_INITIAL (decl);
8598 tree type = TREE_TYPE (decl);
8600 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8601 && initializer_constant_valid_p (init, type) == null_pointer_node)
8602 /* OK */;
8603 else
8604 return;
8606 switch (TREE_CODE (type))
8608 case INTEGER_TYPE:
8609 if (host_integerp (init, 0))
8610 add_AT_unsigned (var_die, DW_AT_const_value,
8611 TREE_INT_CST_LOW (init));
8612 else
8613 add_AT_long_long (var_die, DW_AT_const_value,
8614 TREE_INT_CST_HIGH (init),
8615 TREE_INT_CST_LOW (init));
8616 break;
8618 default:;
8622 /* Generate an DW_AT_name attribute given some string value to be included as
8623 the value of the attribute. */
8625 static inline void
8626 add_name_attribute (die, name_string)
8627 register dw_die_ref die;
8628 register const char *name_string;
8630 if (name_string != NULL && *name_string != 0)
8632 if (demangle_name_func)
8633 name_string = (*demangle_name_func) (name_string);
8635 add_AT_string (die, DW_AT_name, name_string);
8639 /* Given a tree node describing an array bound (either lower or upper) output
8640 a representation for that bound. */
8642 static void
8643 add_bound_info (subrange_die, bound_attr, bound)
8644 register dw_die_ref subrange_die;
8645 register enum dwarf_attribute bound_attr;
8646 register tree bound;
8648 /* If this is an Ada unconstrained array type, then don't emit any debug
8649 info because the array bounds are unknown. They are parameterized when
8650 the type is instantiated. */
8651 if (contains_placeholder_p (bound))
8652 return;
8654 switch (TREE_CODE (bound))
8656 case ERROR_MARK:
8657 return;
8659 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8660 case INTEGER_CST:
8661 if (! host_integerp (bound, 0)
8662 || (bound_attr == DW_AT_lower_bound
8663 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8664 || (is_fortran () && integer_onep (bound)))))
8665 /* use the default */
8667 else
8668 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8669 break;
8671 case CONVERT_EXPR:
8672 case NOP_EXPR:
8673 case NON_LVALUE_EXPR:
8674 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8675 break;
8677 case SAVE_EXPR:
8678 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8679 access the upper bound values may be bogus. If they refer to a
8680 register, they may only describe how to get at these values at the
8681 points in the generated code right after they have just been
8682 computed. Worse yet, in the typical case, the upper bound values
8683 will not even *be* computed in the optimized code (though the
8684 number of elements will), so these SAVE_EXPRs are entirely
8685 bogus. In order to compensate for this fact, we check here to see
8686 if optimization is enabled, and if so, we don't add an attribute
8687 for the (unknown and unknowable) upper bound. This should not
8688 cause too much trouble for existing (stupid?) debuggers because
8689 they have to deal with empty upper bounds location descriptions
8690 anyway in order to be able to deal with incomplete array types.
8691 Of course an intelligent debugger (GDB?) should be able to
8692 comprehend that a missing upper bound specification in a array
8693 type used for a storage class `auto' local array variable
8694 indicates that the upper bound is both unknown (at compile- time)
8695 and unknowable (at run-time) due to optimization.
8697 We assume that a MEM rtx is safe because gcc wouldn't put the
8698 value there unless it was going to be used repeatedly in the
8699 function, i.e. for cleanups. */
8700 if (! optimize || (SAVE_EXPR_RTL (bound)
8701 && GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8703 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8704 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8705 register rtx loc = SAVE_EXPR_RTL (bound);
8707 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8708 it references an outer function's frame. */
8710 if (GET_CODE (loc) == MEM)
8712 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8714 if (XEXP (loc, 0) != new_addr)
8715 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8718 add_AT_flag (decl_die, DW_AT_artificial, 1);
8719 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8720 add_AT_location_description (decl_die, DW_AT_location, loc);
8721 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8724 /* Else leave out the attribute. */
8725 break;
8727 case VAR_DECL:
8728 case PARM_DECL:
8730 dw_die_ref decl_die = lookup_decl_die (bound);
8732 /* ??? Can this happen, or should the variable have been bound
8733 first? Probably it can, since I imagine that we try to create
8734 the types of parameters in the order in which they exist in
8735 the list, and won't have created a forward reference to a
8736 later parameter. */
8737 if (decl_die != NULL)
8738 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8739 break;
8742 default:
8744 /* Otherwise try to create a stack operation procedure to
8745 evaluate the value of the array bound. */
8747 dw_die_ref ctx, decl_die;
8748 dw_loc_descr_ref loc;
8750 loc = loc_descriptor_from_tree (bound, 0);
8751 if (loc == NULL)
8752 break;
8754 ctx = lookup_decl_die (current_function_decl);
8756 decl_die = new_die (DW_TAG_variable, ctx);
8757 add_AT_flag (decl_die, DW_AT_artificial, 1);
8758 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8759 add_AT_loc (decl_die, DW_AT_location, loc);
8761 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8762 break;
8767 /* Note that the block of subscript information for an array type also
8768 includes information about the element type of type given array type. */
8770 static void
8771 add_subscript_info (type_die, type)
8772 register dw_die_ref type_die;
8773 register tree type;
8775 #ifndef MIPS_DEBUGGING_INFO
8776 register unsigned dimension_number;
8777 #endif
8778 register tree lower, upper;
8779 register dw_die_ref subrange_die;
8781 /* The GNU compilers represent multidimensional array types as sequences of
8782 one dimensional array types whose element types are themselves array
8783 types. Here we squish that down, so that each multidimensional array
8784 type gets only one array_type DIE in the Dwarf debugging info. The draft
8785 Dwarf specification say that we are allowed to do this kind of
8786 compression in C (because there is no difference between an array or
8787 arrays and a multidimensional array in C) but for other source languages
8788 (e.g. Ada) we probably shouldn't do this. */
8790 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8791 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8792 We work around this by disabling this feature. See also
8793 gen_array_type_die. */
8794 #ifndef MIPS_DEBUGGING_INFO
8795 for (dimension_number = 0;
8796 TREE_CODE (type) == ARRAY_TYPE;
8797 type = TREE_TYPE (type), dimension_number++)
8799 #endif
8800 register tree domain = TYPE_DOMAIN (type);
8802 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8803 and (in GNU C only) variable bounds. Handle all three forms
8804 here. */
8805 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8806 if (domain)
8808 /* We have an array type with specified bounds. */
8809 lower = TYPE_MIN_VALUE (domain);
8810 upper = TYPE_MAX_VALUE (domain);
8812 /* define the index type. */
8813 if (TREE_TYPE (domain))
8815 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8816 TREE_TYPE field. We can't emit debug info for this
8817 because it is an unnamed integral type. */
8818 if (TREE_CODE (domain) == INTEGER_TYPE
8819 && TYPE_NAME (domain) == NULL_TREE
8820 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8821 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8823 else
8824 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8825 type_die);
8828 /* ??? If upper is NULL, the array has unspecified length,
8829 but it does have a lower bound. This happens with Fortran
8830 dimension arr(N:*)
8831 Since the debugger is definitely going to need to know N
8832 to produce useful results, go ahead and output the lower
8833 bound solo, and hope the debugger can cope. */
8835 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8836 if (upper)
8837 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8839 else
8840 /* We have an array type with an unspecified length. The DWARF-2
8841 spec does not say how to handle this; let's just leave out the
8842 bounds. */
8845 #ifndef MIPS_DEBUGGING_INFO
8847 #endif
8850 static void
8851 add_byte_size_attribute (die, tree_node)
8852 dw_die_ref die;
8853 register tree tree_node;
8855 register unsigned size;
8857 switch (TREE_CODE (tree_node))
8859 case ERROR_MARK:
8860 size = 0;
8861 break;
8862 case ENUMERAL_TYPE:
8863 case RECORD_TYPE:
8864 case UNION_TYPE:
8865 case QUAL_UNION_TYPE:
8866 size = int_size_in_bytes (tree_node);
8867 break;
8868 case FIELD_DECL:
8869 /* For a data member of a struct or union, the DW_AT_byte_size is
8870 generally given as the number of bytes normally allocated for an
8871 object of the *declared* type of the member itself. This is true
8872 even for bit-fields. */
8873 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8874 break;
8875 default:
8876 abort ();
8879 /* Note that `size' might be -1 when we get to this point. If it is, that
8880 indicates that the byte size of the entity in question is variable. We
8881 have no good way of expressing this fact in Dwarf at the present time,
8882 so just let the -1 pass on through. */
8884 add_AT_unsigned (die, DW_AT_byte_size, size);
8887 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8888 which specifies the distance in bits from the highest order bit of the
8889 "containing object" for the bit-field to the highest order bit of the
8890 bit-field itself.
8892 For any given bit-field, the "containing object" is a hypothetical
8893 object (of some integral or enum type) within which the given bit-field
8894 lives. The type of this hypothetical "containing object" is always the
8895 same as the declared type of the individual bit-field itself. The
8896 determination of the exact location of the "containing object" for a
8897 bit-field is rather complicated. It's handled by the
8898 `field_byte_offset' function (above).
8900 Note that it is the size (in bytes) of the hypothetical "containing object"
8901 which will be given in the DW_AT_byte_size attribute for this bit-field.
8902 (See `byte_size_attribute' above). */
8904 static inline void
8905 add_bit_offset_attribute (die, decl)
8906 register dw_die_ref die;
8907 register tree decl;
8909 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8910 tree type = DECL_BIT_FIELD_TYPE (decl);
8911 HOST_WIDE_INT bitpos_int;
8912 HOST_WIDE_INT highest_order_object_bit_offset;
8913 HOST_WIDE_INT highest_order_field_bit_offset;
8914 HOST_WIDE_INT unsigned bit_offset;
8916 /* Must be a field and a bit field. */
8917 if (!type
8918 || TREE_CODE (decl) != FIELD_DECL)
8919 abort ();
8921 /* We can't yet handle bit-fields whose offsets are variable, so if we
8922 encounter such things, just return without generating any attribute
8923 whatsoever. Likewise for variable or too large size. */
8924 if (! host_integerp (bit_position (decl), 0)
8925 || ! host_integerp (DECL_SIZE (decl), 1))
8926 return;
8928 bitpos_int = int_bit_position (decl);
8930 /* Note that the bit offset is always the distance (in bits) from the
8931 highest-order bit of the "containing object" to the highest-order bit of
8932 the bit-field itself. Since the "high-order end" of any object or field
8933 is different on big-endian and little-endian machines, the computation
8934 below must take account of these differences. */
8935 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
8936 highest_order_field_bit_offset = bitpos_int;
8938 if (! BYTES_BIG_ENDIAN)
8940 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
8941 highest_order_object_bit_offset += simple_type_size_in_bits (type);
8944 bit_offset
8945 = (! BYTES_BIG_ENDIAN
8946 ? highest_order_object_bit_offset - highest_order_field_bit_offset
8947 : highest_order_field_bit_offset - highest_order_object_bit_offset);
8949 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
8952 /* For a FIELD_DECL node which represents a bit field, output an attribute
8953 which specifies the length in bits of the given field. */
8955 static inline void
8956 add_bit_size_attribute (die, decl)
8957 register dw_die_ref die;
8958 register tree decl;
8960 /* Must be a field and a bit field. */
8961 if (TREE_CODE (decl) != FIELD_DECL
8962 || ! DECL_BIT_FIELD_TYPE (decl))
8963 abort ();
8965 if (host_integerp (DECL_SIZE (decl), 1))
8966 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
8969 /* If the compiled language is ANSI C, then add a 'prototyped'
8970 attribute, if arg types are given for the parameters of a function. */
8972 static inline void
8973 add_prototyped_attribute (die, func_type)
8974 register dw_die_ref die;
8975 register tree func_type;
8977 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
8978 && TYPE_ARG_TYPES (func_type) != NULL)
8979 add_AT_flag (die, DW_AT_prototyped, 1);
8982 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
8983 by looking in either the type declaration or object declaration
8984 equate table. */
8986 static inline void
8987 add_abstract_origin_attribute (die, origin)
8988 register dw_die_ref die;
8989 register tree origin;
8991 dw_die_ref origin_die = NULL;
8993 if (TREE_CODE (origin) != FUNCTION_DECL)
8995 /* We may have gotten separated from the block for the inlined
8996 function, if we're in an exception handler or some such; make
8997 sure that the abstract function has been written out.
8999 Doing this for nested functions is wrong, however; functions are
9000 distinct units, and our context might not even be inline. */
9001 tree fn = origin;
9002 if (TYPE_P (fn))
9003 fn = TYPE_STUB_DECL (fn);
9004 fn = decl_function_context (fn);
9005 if (fn)
9006 gen_abstract_function (fn);
9009 if (DECL_P (origin))
9010 origin_die = lookup_decl_die (origin);
9011 else if (TYPE_P (origin))
9012 origin_die = lookup_type_die (origin);
9014 if (origin_die == NULL)
9015 abort ();
9017 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9020 /* We do not currently support the pure_virtual attribute. */
9022 static inline void
9023 add_pure_or_virtual_attribute (die, func_decl)
9024 register dw_die_ref die;
9025 register tree func_decl;
9027 if (DECL_VINDEX (func_decl))
9029 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9031 if (host_integerp (DECL_VINDEX (func_decl), 0))
9032 add_AT_loc (die, DW_AT_vtable_elem_location,
9033 new_loc_descr (DW_OP_constu,
9034 tree_low_cst (DECL_VINDEX (func_decl), 0),
9035 0));
9037 /* GNU extension: Record what type this method came from originally. */
9038 if (debug_info_level > DINFO_LEVEL_TERSE)
9039 add_AT_die_ref (die, DW_AT_containing_type,
9040 lookup_type_die (DECL_CONTEXT (func_decl)));
9044 /* Add source coordinate attributes for the given decl. */
9046 static void
9047 add_src_coords_attributes (die, decl)
9048 register dw_die_ref die;
9049 register tree decl;
9051 register unsigned file_index = lookup_filename (&decl_file_table,
9052 DECL_SOURCE_FILE (decl));
9054 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9055 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9058 /* Add an DW_AT_name attribute and source coordinate attribute for the
9059 given decl, but only if it actually has a name. */
9061 static void
9062 add_name_and_src_coords_attributes (die, decl)
9063 register dw_die_ref die;
9064 register tree decl;
9066 register tree decl_name;
9068 decl_name = DECL_NAME (decl);
9069 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9071 add_name_attribute (die, dwarf2_name (decl, 0));
9072 if (! DECL_ARTIFICIAL (decl))
9073 add_src_coords_attributes (die, decl);
9075 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9076 && TREE_PUBLIC (decl)
9077 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
9078 add_AT_string (die, DW_AT_MIPS_linkage_name,
9079 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9083 /* Push a new declaration scope. */
9085 static void
9086 push_decl_scope (scope)
9087 tree scope;
9089 /* Make room in the decl_scope_table, if necessary. */
9090 if (decl_scope_table_allocated == decl_scope_depth)
9092 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
9093 decl_scope_table
9094 = (tree *) xrealloc (decl_scope_table,
9095 decl_scope_table_allocated * sizeof (tree));
9098 decl_scope_table[decl_scope_depth] = scope;
9099 decl_scope_depth++;
9102 /* Pop a declaration scope. */
9103 static inline void
9104 pop_decl_scope ()
9106 if (decl_scope_depth <= 0)
9107 abort ();
9108 --decl_scope_depth;
9111 /* Return the DIE for the scope that immediately contains this type.
9112 Non-named types get global scope. Named types nested in other
9113 types get their containing scope if it's open, or global scope
9114 otherwise. All other types (i.e. function-local named types) get
9115 the current active scope. */
9117 static dw_die_ref
9118 scope_die_for (t, context_die)
9119 register tree t;
9120 register dw_die_ref context_die;
9122 register dw_die_ref scope_die = NULL;
9123 register tree containing_scope;
9124 register int i;
9126 /* Non-types always go in the current scope. */
9127 if (! TYPE_P (t))
9128 abort ();
9130 containing_scope = TYPE_CONTEXT (t);
9132 /* Ignore namespaces for the moment. */
9133 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9134 containing_scope = NULL_TREE;
9136 /* Ignore function type "scopes" from the C frontend. They mean that
9137 a tagged type is local to a parmlist of a function declarator, but
9138 that isn't useful to DWARF. */
9139 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9140 containing_scope = NULL_TREE;
9142 if (containing_scope == NULL_TREE)
9143 scope_die = comp_unit_die;
9144 else if (TYPE_P (containing_scope))
9146 /* For types, we can just look up the appropriate DIE. But
9147 first we check to see if we're in the middle of emitting it
9148 so we know where the new DIE should go. */
9150 for (i = decl_scope_depth - 1; i >= 0; --i)
9151 if (decl_scope_table[i] == containing_scope)
9152 break;
9154 if (i < 0)
9156 if (debug_info_level > DINFO_LEVEL_TERSE
9157 && !TREE_ASM_WRITTEN (containing_scope))
9158 abort ();
9160 /* If none of the current dies are suitable, we get file scope. */
9161 scope_die = comp_unit_die;
9163 else
9164 scope_die = lookup_type_die (containing_scope);
9166 else
9167 scope_die = context_die;
9169 return scope_die;
9172 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
9174 static inline int local_scope_p PARAMS ((dw_die_ref));
9175 static inline int
9176 local_scope_p (context_die)
9177 dw_die_ref context_die;
9179 for (; context_die; context_die = context_die->die_parent)
9180 if (context_die->die_tag == DW_TAG_inlined_subroutine
9181 || context_die->die_tag == DW_TAG_subprogram)
9182 return 1;
9183 return 0;
9186 /* Returns nonzero iff CONTEXT_DIE is a class. */
9188 static inline int class_scope_p PARAMS ((dw_die_ref));
9189 static inline int
9190 class_scope_p (context_die)
9191 dw_die_ref context_die;
9193 return (context_die
9194 && (context_die->die_tag == DW_TAG_structure_type
9195 || context_die->die_tag == DW_TAG_union_type));
9198 /* Many forms of DIEs require a "type description" attribute. This
9199 routine locates the proper "type descriptor" die for the type given
9200 by 'type', and adds an DW_AT_type attribute below the given die. */
9202 static void
9203 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9204 register dw_die_ref object_die;
9205 register tree type;
9206 register int decl_const;
9207 register int decl_volatile;
9208 register dw_die_ref context_die;
9210 register enum tree_code code = TREE_CODE (type);
9211 register dw_die_ref type_die = NULL;
9213 /* ??? If this type is an unnamed subrange type of an integral or
9214 floating-point type, use the inner type. This is because we have no
9215 support for unnamed types in base_type_die. This can happen if this is
9216 an Ada subrange type. Correct solution is emit a subrange type die. */
9217 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9218 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9219 type = TREE_TYPE (type), code = TREE_CODE (type);
9221 if (code == ERROR_MARK)
9222 return;
9224 /* Handle a special case. For functions whose return type is void, we
9225 generate *no* type attribute. (Note that no object may have type
9226 `void', so this only applies to function return types). */
9227 if (code == VOID_TYPE)
9228 return;
9230 type_die = modified_type_die (type,
9231 decl_const || TYPE_READONLY (type),
9232 decl_volatile || TYPE_VOLATILE (type),
9233 context_die);
9234 if (type_die != NULL)
9235 add_AT_die_ref (object_die, DW_AT_type, type_die);
9238 /* Given a tree pointer to a struct, class, union, or enum type node, return
9239 a pointer to the (string) tag name for the given type, or zero if the type
9240 was declared without a tag. */
9242 static const char *
9243 type_tag (type)
9244 register tree type;
9246 register const char *name = 0;
9248 if (TYPE_NAME (type) != 0)
9250 register tree t = 0;
9252 /* Find the IDENTIFIER_NODE for the type name. */
9253 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9254 t = TYPE_NAME (type);
9256 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9257 a TYPE_DECL node, regardless of whether or not a `typedef' was
9258 involved. */
9259 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9260 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9261 t = DECL_NAME (TYPE_NAME (type));
9263 /* Now get the name as a string, or invent one. */
9264 if (t != 0)
9265 name = IDENTIFIER_POINTER (t);
9268 return (name == 0 || *name == '\0') ? 0 : name;
9271 /* Return the type associated with a data member, make a special check
9272 for bit field types. */
9274 static inline tree
9275 member_declared_type (member)
9276 register tree member;
9278 return (DECL_BIT_FIELD_TYPE (member)
9279 ? DECL_BIT_FIELD_TYPE (member)
9280 : TREE_TYPE (member));
9283 /* Get the decl's label, as described by its RTL. This may be different
9284 from the DECL_NAME name used in the source file. */
9286 #if 0
9287 static const char *
9288 decl_start_label (decl)
9289 register tree decl;
9291 rtx x;
9292 const char *fnname;
9293 x = DECL_RTL (decl);
9294 if (GET_CODE (x) != MEM)
9295 abort ();
9297 x = XEXP (x, 0);
9298 if (GET_CODE (x) != SYMBOL_REF)
9299 abort ();
9301 fnname = XSTR (x, 0);
9302 return fnname;
9304 #endif
9306 /* These routines generate the internal representation of the DIE's for
9307 the compilation unit. Debugging information is collected by walking
9308 the declaration trees passed in from dwarf2out_decl(). */
9310 static void
9311 gen_array_type_die (type, context_die)
9312 register tree type;
9313 register dw_die_ref context_die;
9315 register dw_die_ref scope_die = scope_die_for (type, context_die);
9316 register dw_die_ref array_die;
9317 register tree element_type;
9319 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9320 the inner array type comes before the outer array type. Thus we must
9321 call gen_type_die before we call new_die. See below also. */
9322 #ifdef MIPS_DEBUGGING_INFO
9323 gen_type_die (TREE_TYPE (type), context_die);
9324 #endif
9326 array_die = new_die (DW_TAG_array_type, scope_die);
9328 #if 0
9329 /* We default the array ordering. SDB will probably do
9330 the right things even if DW_AT_ordering is not present. It's not even
9331 an issue until we start to get into multidimensional arrays anyway. If
9332 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9333 then we'll have to put the DW_AT_ordering attribute back in. (But if
9334 and when we find out that we need to put these in, we will only do so
9335 for multidimensional arrays. */
9336 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9337 #endif
9339 #ifdef MIPS_DEBUGGING_INFO
9340 /* The SGI compilers handle arrays of unknown bound by setting
9341 AT_declaration and not emitting any subrange DIEs. */
9342 if (! TYPE_DOMAIN (type))
9343 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9344 else
9345 #endif
9346 add_subscript_info (array_die, type);
9348 add_name_attribute (array_die, type_tag (type));
9349 equate_type_number_to_die (type, array_die);
9351 /* Add representation of the type of the elements of this array type. */
9352 element_type = TREE_TYPE (type);
9354 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9355 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9356 We work around this by disabling this feature. See also
9357 add_subscript_info. */
9358 #ifndef MIPS_DEBUGGING_INFO
9359 while (TREE_CODE (element_type) == ARRAY_TYPE)
9360 element_type = TREE_TYPE (element_type);
9362 gen_type_die (element_type, context_die);
9363 #endif
9365 add_type_attribute (array_die, element_type, 0, 0, context_die);
9368 static void
9369 gen_set_type_die (type, context_die)
9370 register tree type;
9371 register dw_die_ref context_die;
9373 register dw_die_ref type_die
9374 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9376 equate_type_number_to_die (type, type_die);
9377 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9380 #if 0
9381 static void
9382 gen_entry_point_die (decl, context_die)
9383 register tree decl;
9384 register dw_die_ref context_die;
9386 register tree origin = decl_ultimate_origin (decl);
9387 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9388 if (origin != NULL)
9389 add_abstract_origin_attribute (decl_die, origin);
9390 else
9392 add_name_and_src_coords_attributes (decl_die, decl);
9393 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9394 0, 0, context_die);
9397 if (DECL_ABSTRACT (decl))
9398 equate_decl_number_to_die (decl, decl_die);
9399 else
9400 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9402 #endif
9404 /* Remember a type in the incomplete_types_list. */
9406 static void
9407 add_incomplete_type (type)
9408 tree type;
9410 if (incomplete_types == incomplete_types_allocated)
9412 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
9413 incomplete_types_list
9414 = (tree *) xrealloc (incomplete_types_list,
9415 sizeof (tree) * incomplete_types_allocated);
9418 incomplete_types_list[incomplete_types++] = type;
9421 /* Walk through the list of incomplete types again, trying once more to
9422 emit full debugging info for them. */
9424 static void
9425 retry_incomplete_types ()
9427 register tree type;
9429 while (incomplete_types)
9431 --incomplete_types;
9432 type = incomplete_types_list[incomplete_types];
9433 gen_type_die (type, comp_unit_die);
9437 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9439 static void
9440 gen_inlined_enumeration_type_die (type, context_die)
9441 register tree type;
9442 register dw_die_ref context_die;
9444 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9445 context_die);
9446 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9447 be incomplete and such types are not marked. */
9448 add_abstract_origin_attribute (type_die, type);
9451 /* Generate a DIE to represent an inlined instance of a structure type. */
9453 static void
9454 gen_inlined_structure_type_die (type, context_die)
9455 register tree type;
9456 register dw_die_ref context_die;
9458 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9460 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9461 be incomplete and such types are not marked. */
9462 add_abstract_origin_attribute (type_die, type);
9465 /* Generate a DIE to represent an inlined instance of a union type. */
9467 static void
9468 gen_inlined_union_type_die (type, context_die)
9469 register tree type;
9470 register dw_die_ref context_die;
9472 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9474 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9475 be incomplete and such types are not marked. */
9476 add_abstract_origin_attribute (type_die, type);
9479 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9480 include all of the information about the enumeration values also. Each
9481 enumerated type name/value is listed as a child of the enumerated type
9482 DIE. */
9484 static void
9485 gen_enumeration_type_die (type, context_die)
9486 register tree type;
9487 register dw_die_ref context_die;
9489 register dw_die_ref type_die = lookup_type_die (type);
9491 if (type_die == NULL)
9493 type_die = new_die (DW_TAG_enumeration_type,
9494 scope_die_for (type, context_die));
9495 equate_type_number_to_die (type, type_die);
9496 add_name_attribute (type_die, type_tag (type));
9498 else if (! TYPE_SIZE (type))
9499 return;
9500 else
9501 remove_AT (type_die, DW_AT_declaration);
9503 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9504 given enum type is incomplete, do not generate the DW_AT_byte_size
9505 attribute or the DW_AT_element_list attribute. */
9506 if (TYPE_SIZE (type))
9508 register tree link;
9510 TREE_ASM_WRITTEN (type) = 1;
9511 add_byte_size_attribute (type_die, type);
9512 if (TYPE_STUB_DECL (type) != NULL_TREE)
9513 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9515 /* If the first reference to this type was as the return type of an
9516 inline function, then it may not have a parent. Fix this now. */
9517 if (type_die->die_parent == NULL)
9518 add_child_die (scope_die_for (type, context_die), type_die);
9520 for (link = TYPE_FIELDS (type);
9521 link != NULL; link = TREE_CHAIN (link))
9523 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9525 add_name_attribute (enum_die,
9526 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9528 if (host_integerp (TREE_VALUE (link), 0))
9530 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9531 add_AT_int (enum_die, DW_AT_const_value,
9532 tree_low_cst (TREE_VALUE (link), 0));
9533 else
9534 add_AT_unsigned (enum_die, DW_AT_const_value,
9535 tree_low_cst (TREE_VALUE (link), 0));
9539 else
9540 add_AT_flag (type_die, DW_AT_declaration, 1);
9543 /* Generate a DIE to represent either a real live formal parameter decl or to
9544 represent just the type of some formal parameter position in some function
9545 type.
9547 Note that this routine is a bit unusual because its argument may be a
9548 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9549 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9550 node. If it's the former then this function is being called to output a
9551 DIE to represent a formal parameter object (or some inlining thereof). If
9552 it's the latter, then this function is only being called to output a
9553 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9554 argument type of some subprogram type. */
9556 static dw_die_ref
9557 gen_formal_parameter_die (node, context_die)
9558 register tree node;
9559 register dw_die_ref context_die;
9561 register dw_die_ref parm_die
9562 = new_die (DW_TAG_formal_parameter, context_die);
9563 register tree origin;
9565 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9567 case 'd':
9568 origin = decl_ultimate_origin (node);
9569 if (origin != NULL)
9570 add_abstract_origin_attribute (parm_die, origin);
9571 else
9573 add_name_and_src_coords_attributes (parm_die, node);
9574 add_type_attribute (parm_die, TREE_TYPE (node),
9575 TREE_READONLY (node),
9576 TREE_THIS_VOLATILE (node),
9577 context_die);
9578 if (DECL_ARTIFICIAL (node))
9579 add_AT_flag (parm_die, DW_AT_artificial, 1);
9582 equate_decl_number_to_die (node, parm_die);
9583 if (! DECL_ABSTRACT (node))
9584 add_location_or_const_value_attribute (parm_die, node);
9586 break;
9588 case 't':
9589 /* We were called with some kind of a ..._TYPE node. */
9590 add_type_attribute (parm_die, node, 0, 0, context_die);
9591 break;
9593 default:
9594 abort ();
9597 return parm_die;
9600 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9601 at the end of an (ANSI prototyped) formal parameters list. */
9603 static void
9604 gen_unspecified_parameters_die (decl_or_type, context_die)
9605 register tree decl_or_type ATTRIBUTE_UNUSED;
9606 register dw_die_ref context_die;
9608 new_die (DW_TAG_unspecified_parameters, context_die);
9611 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9612 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9613 parameters as specified in some function type specification (except for
9614 those which appear as part of a function *definition*). */
9616 static void
9617 gen_formal_types_die (function_or_method_type, context_die)
9618 register tree function_or_method_type;
9619 register dw_die_ref context_die;
9621 register tree link;
9622 register tree formal_type = NULL;
9623 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9625 #if 0
9626 /* In the case where we are generating a formal types list for a C++
9627 non-static member function type, skip over the first thing on the
9628 TYPE_ARG_TYPES list because it only represents the type of the hidden
9629 `this pointer'. The debugger should be able to figure out (without
9630 being explicitly told) that this non-static member function type takes a
9631 `this pointer' and should be able to figure what the type of that hidden
9632 parameter is from the DW_AT_member attribute of the parent
9633 DW_TAG_subroutine_type DIE. */
9634 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
9635 first_parm_type = TREE_CHAIN (first_parm_type);
9636 #endif
9638 /* Make our first pass over the list of formal parameter types and output a
9639 DW_TAG_formal_parameter DIE for each one. */
9640 for (link = first_parm_type; link; link = TREE_CHAIN (link))
9642 register dw_die_ref parm_die;
9644 formal_type = TREE_VALUE (link);
9645 if (formal_type == void_type_node)
9646 break;
9648 /* Output a (nameless) DIE to represent the formal parameter itself. */
9649 parm_die = gen_formal_parameter_die (formal_type, context_die);
9650 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
9651 && link == first_parm_type)
9652 add_AT_flag (parm_die, DW_AT_artificial, 1);
9655 /* If this function type has an ellipsis, add a
9656 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9657 if (formal_type != void_type_node)
9658 gen_unspecified_parameters_die (function_or_method_type, context_die);
9660 /* Make our second (and final) pass over the list of formal parameter types
9661 and output DIEs to represent those types (as necessary). */
9662 for (link = TYPE_ARG_TYPES (function_or_method_type);
9663 link;
9664 link = TREE_CHAIN (link))
9666 formal_type = TREE_VALUE (link);
9667 if (formal_type == void_type_node)
9668 break;
9670 gen_type_die (formal_type, context_die);
9674 /* We want to generate the DIE for TYPE so that we can generate the
9675 die for MEMBER, which has been defined; we will need to refer back
9676 to the member declaration nested within TYPE. If we're trying to
9677 generate minimal debug info for TYPE, processing TYPE won't do the
9678 trick; we need to attach the member declaration by hand. */
9680 static void
9681 gen_type_die_for_member (type, member, context_die)
9682 tree type, member;
9683 dw_die_ref context_die;
9685 gen_type_die (type, context_die);
9687 /* If we're trying to avoid duplicate debug info, we may not have
9688 emitted the member decl for this function. Emit it now. */
9689 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9690 && ! lookup_decl_die (member))
9692 if (decl_ultimate_origin (member))
9693 abort ();
9695 push_decl_scope (type);
9696 if (TREE_CODE (member) == FUNCTION_DECL)
9697 gen_subprogram_die (member, lookup_type_die (type));
9698 else
9699 gen_variable_die (member, lookup_type_die (type));
9700 pop_decl_scope ();
9704 /* Generate the DWARF2 info for the "abstract" instance
9705 of a function which we may later generate inlined and/or
9706 out-of-line instances of. */
9708 static void
9709 gen_abstract_function (decl)
9710 tree decl;
9712 register dw_die_ref old_die = lookup_decl_die (decl);
9713 tree save_fn;
9715 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9716 /* We've already generated the abstract instance. */
9717 return;
9719 save_fn = current_function_decl;
9720 current_function_decl = decl;
9722 set_decl_abstract_flags (decl, 1);
9723 dwarf2out_decl (decl);
9724 set_decl_abstract_flags (decl, 0);
9726 current_function_decl = save_fn;
9729 /* Generate a DIE to represent a declared function (either file-scope or
9730 block-local). */
9732 static void
9733 gen_subprogram_die (decl, context_die)
9734 register tree decl;
9735 register dw_die_ref context_die;
9737 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9738 register tree origin = decl_ultimate_origin (decl);
9739 register dw_die_ref subr_die;
9740 register rtx fp_reg;
9741 register tree fn_arg_types;
9742 register tree outer_scope;
9743 register dw_die_ref old_die = lookup_decl_die (decl);
9744 register int declaration = (current_function_decl != decl
9745 || class_scope_p (context_die));
9747 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9748 be true, if we started to generate the abstract instance of an inline,
9749 decided to output its containing class, and proceeded to emit the
9750 declaration of the inline from the member list for the class. In that
9751 case, `declaration' takes priority; we'll get back to the abstract
9752 instance when we're done with the class. */
9754 /* The class-scope declaration DIE must be the primary DIE. */
9755 if (origin && declaration && class_scope_p (context_die))
9757 origin = NULL;
9758 if (old_die)
9759 abort ();
9762 if (origin != NULL)
9764 if (declaration && ! local_scope_p (context_die))
9765 abort ();
9767 /* Fixup die_parent for the abstract instance of a nested
9768 inline function. */
9769 if (old_die && old_die->die_parent == NULL)
9770 add_child_die (context_die, old_die);
9772 subr_die = new_die (DW_TAG_subprogram, context_die);
9773 add_abstract_origin_attribute (subr_die, origin);
9775 else if (old_die && DECL_ABSTRACT (decl)
9776 && get_AT_unsigned (old_die, DW_AT_inline))
9778 /* This must be a redefinition of an extern inline function.
9779 We can just reuse the old die here. */
9780 subr_die = old_die;
9782 /* Clear out the inlined attribute and parm types. */
9783 remove_AT (subr_die, DW_AT_inline);
9784 remove_children (subr_die);
9786 else if (old_die)
9788 register unsigned file_index
9789 = lookup_filename (&decl_file_table, DECL_SOURCE_FILE (decl));
9791 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
9793 /* ??? This can happen if there is a bug in the program, for
9794 instance, if it has duplicate function definitions. Ideally,
9795 we should detect this case and ignore it. For now, if we have
9796 already reported an error, any error at all, then assume that
9797 we got here because of a input error, not a dwarf2 bug. */
9798 if (errorcount)
9799 return;
9800 abort ();
9803 /* If the definition comes from the same place as the declaration,
9804 maybe use the old DIE. We always want the DIE for this function
9805 that has the *_pc attributes to be under comp_unit_die so the
9806 debugger can find it. For inlines, that is the concrete instance,
9807 so we can use the old DIE here. For non-inline methods, we want a
9808 specification DIE at toplevel, so we need a new DIE. For local
9809 class methods, this doesn't apply; we just use the old DIE. */
9810 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
9811 || context_die == NULL)
9812 && (DECL_ARTIFICIAL (decl)
9813 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9814 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9815 == (unsigned) DECL_SOURCE_LINE (decl)))))
9817 subr_die = old_die;
9819 /* Clear out the declaration attribute and the parm types. */
9820 remove_AT (subr_die, DW_AT_declaration);
9821 remove_children (subr_die);
9823 else
9825 subr_die = new_die (DW_TAG_subprogram, context_die);
9826 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9827 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9828 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9829 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9830 != (unsigned) DECL_SOURCE_LINE (decl))
9831 add_AT_unsigned
9832 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9835 else
9837 subr_die = new_die (DW_TAG_subprogram, context_die);
9839 if (TREE_PUBLIC (decl))
9840 add_AT_flag (subr_die, DW_AT_external, 1);
9842 add_name_and_src_coords_attributes (subr_die, decl);
9843 if (debug_info_level > DINFO_LEVEL_TERSE)
9845 register tree type = TREE_TYPE (decl);
9847 add_prototyped_attribute (subr_die, type);
9848 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9851 add_pure_or_virtual_attribute (subr_die, decl);
9852 if (DECL_ARTIFICIAL (decl))
9853 add_AT_flag (subr_die, DW_AT_artificial, 1);
9854 if (TREE_PROTECTED (decl))
9855 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9856 else if (TREE_PRIVATE (decl))
9857 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9860 if (declaration)
9862 if (! origin)
9863 add_AT_flag (subr_die, DW_AT_declaration, 1);
9865 /* The first time we see a member function, it is in the context of
9866 the class to which it belongs. We make sure of this by emitting
9867 the class first. The next time is the definition, which is
9868 handled above. The two may come from the same source text. */
9869 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9870 equate_decl_number_to_die (decl, subr_die);
9872 else if (DECL_ABSTRACT (decl))
9874 if (DECL_INLINE (decl) && !flag_no_inline)
9876 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9877 inline functions, but not for extern inline functions.
9878 We can't get this completely correct because information
9879 about whether the function was declared inline is not
9880 saved anywhere. */
9881 if (DECL_DEFER_OUTPUT (decl))
9882 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9883 else
9884 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9886 else
9887 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9889 equate_decl_number_to_die (decl, subr_die);
9891 else if (!DECL_EXTERNAL (decl))
9893 if (origin == NULL_TREE)
9894 equate_decl_number_to_die (decl, subr_die);
9896 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9897 current_funcdef_number);
9898 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
9899 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
9900 current_funcdef_number);
9901 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
9903 add_pubname (decl, subr_die);
9904 add_arange (decl, subr_die);
9906 #ifdef MIPS_DEBUGGING_INFO
9907 /* Add a reference to the FDE for this routine. */
9908 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
9909 #endif
9911 /* Define the "frame base" location for this routine. We use the
9912 frame pointer or stack pointer registers, since the RTL for local
9913 variables is relative to one of them. */
9914 fp_reg
9915 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
9916 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
9918 #if 0
9919 /* ??? This fails for nested inline functions, because context_display
9920 is not part of the state saved/restored for inline functions. */
9921 if (current_function_needs_context)
9922 add_AT_location_description (subr_die, DW_AT_static_link,
9923 lookup_static_chain (decl));
9924 #endif
9927 /* Now output descriptions of the arguments for this function. This gets
9928 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
9929 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
9930 `...' at the end of the formal parameter list. In order to find out if
9931 there was a trailing ellipsis or not, we must instead look at the type
9932 associated with the FUNCTION_DECL. This will be a node of type
9933 FUNCTION_TYPE. If the chain of type nodes hanging off of this
9934 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
9935 an ellipsis at the end. */
9937 /* In the case where we are describing a mere function declaration, all we
9938 need to do here (and all we *can* do here) is to describe the *types* of
9939 its formal parameters. */
9940 if (debug_info_level <= DINFO_LEVEL_TERSE)
9942 else if (declaration)
9943 gen_formal_types_die (TREE_TYPE (decl), subr_die);
9944 else
9946 /* Generate DIEs to represent all known formal parameters */
9947 register tree arg_decls = DECL_ARGUMENTS (decl);
9948 register tree parm;
9950 /* When generating DIEs, generate the unspecified_parameters DIE
9951 instead if we come across the arg "__builtin_va_alist" */
9952 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
9953 if (TREE_CODE (parm) == PARM_DECL)
9955 if (DECL_NAME (parm)
9956 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
9957 "__builtin_va_alist"))
9958 gen_unspecified_parameters_die (parm, subr_die);
9959 else
9960 gen_decl_die (parm, subr_die);
9963 /* Decide whether we need a unspecified_parameters DIE at the end.
9964 There are 2 more cases to do this for: 1) the ansi ... declaration -
9965 this is detectable when the end of the arg list is not a
9966 void_type_node 2) an unprototyped function declaration (not a
9967 definition). This just means that we have no info about the
9968 parameters at all. */
9969 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
9970 if (fn_arg_types != NULL)
9972 /* this is the prototyped case, check for ... */
9973 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
9974 gen_unspecified_parameters_die (decl, subr_die);
9976 else if (DECL_INITIAL (decl) == NULL_TREE)
9977 gen_unspecified_parameters_die (decl, subr_die);
9980 /* Output Dwarf info for all of the stuff within the body of the function
9981 (if it has one - it may be just a declaration). */
9982 outer_scope = DECL_INITIAL (decl);
9984 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
9985 node created to represent a function. This outermost BLOCK actually
9986 represents the outermost binding contour for the function, i.e. the
9987 contour in which the function's formal parameters and labels get
9988 declared. Curiously, it appears that the front end doesn't actually
9989 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
9990 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
9991 list for the function instead.) The BLOCK_VARS list for the
9992 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
9993 the function however, and we output DWARF info for those in
9994 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
9995 node representing the function's outermost pair of curly braces, and
9996 any blocks used for the base and member initializers of a C++
9997 constructor function. */
9998 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10000 current_function_has_inlines = 0;
10001 decls_for_scope (outer_scope, subr_die, 0);
10003 #if 0 && defined (MIPS_DEBUGGING_INFO)
10004 if (current_function_has_inlines)
10006 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10007 if (! comp_unit_has_inlines)
10009 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10010 comp_unit_has_inlines = 1;
10013 #endif
10017 /* Generate a DIE to represent a declared data object. */
10019 static void
10020 gen_variable_die (decl, context_die)
10021 register tree decl;
10022 register dw_die_ref context_die;
10024 register tree origin = decl_ultimate_origin (decl);
10025 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
10027 dw_die_ref old_die = lookup_decl_die (decl);
10028 int declaration = (DECL_EXTERNAL (decl)
10029 || class_scope_p (context_die));
10031 if (origin != NULL)
10032 add_abstract_origin_attribute (var_die, origin);
10033 /* Loop unrolling can create multiple blocks that refer to the same
10034 static variable, so we must test for the DW_AT_declaration flag. */
10035 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10036 copy decls and set the DECL_ABSTRACT flag on them instead of
10037 sharing them. */
10038 else if (old_die && TREE_STATIC (decl)
10039 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10041 /* This is a definition of a C++ class level static. */
10042 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10043 if (DECL_NAME (decl))
10045 register unsigned file_index
10046 = lookup_filename (&decl_file_table, DECL_SOURCE_FILE (decl));
10048 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10049 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10051 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10052 != (unsigned) DECL_SOURCE_LINE (decl))
10054 add_AT_unsigned (var_die, DW_AT_decl_line,
10055 DECL_SOURCE_LINE (decl));
10058 else
10060 add_name_and_src_coords_attributes (var_die, decl);
10061 add_type_attribute (var_die, TREE_TYPE (decl),
10062 TREE_READONLY (decl),
10063 TREE_THIS_VOLATILE (decl), context_die);
10065 if (TREE_PUBLIC (decl))
10066 add_AT_flag (var_die, DW_AT_external, 1);
10068 if (DECL_ARTIFICIAL (decl))
10069 add_AT_flag (var_die, DW_AT_artificial, 1);
10071 if (TREE_PROTECTED (decl))
10072 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10074 else if (TREE_PRIVATE (decl))
10075 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10078 if (declaration)
10079 add_AT_flag (var_die, DW_AT_declaration, 1);
10081 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10082 equate_decl_number_to_die (decl, var_die);
10084 if (! declaration && ! DECL_ABSTRACT (decl))
10086 add_location_or_const_value_attribute (var_die, decl);
10087 add_pubname (decl, var_die);
10089 else
10090 tree_add_const_value_attribute (var_die, decl);
10093 /* Generate a DIE to represent a label identifier. */
10095 static void
10096 gen_label_die (decl, context_die)
10097 register tree decl;
10098 register dw_die_ref context_die;
10100 register tree origin = decl_ultimate_origin (decl);
10101 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
10102 register rtx insn;
10103 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10105 if (origin != NULL)
10106 add_abstract_origin_attribute (lbl_die, origin);
10107 else
10108 add_name_and_src_coords_attributes (lbl_die, decl);
10110 if (DECL_ABSTRACT (decl))
10111 equate_decl_number_to_die (decl, lbl_die);
10112 else
10114 insn = DECL_RTL (decl);
10116 /* Deleted labels are programmer specified labels which have been
10117 eliminated because of various optimisations. We still emit them
10118 here so that it is possible to put breakpoints on them. */
10119 if (GET_CODE (insn) == CODE_LABEL
10120 || ((GET_CODE (insn) == NOTE
10121 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10123 /* When optimization is enabled (via -O) some parts of the compiler
10124 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10125 represent source-level labels which were explicitly declared by
10126 the user. This really shouldn't be happening though, so catch
10127 it if it ever does happen. */
10128 if (INSN_DELETED_P (insn))
10129 abort ();
10131 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10132 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10137 /* Generate a DIE for a lexical block. */
10139 static void
10140 gen_lexical_block_die (stmt, context_die, depth)
10141 register tree stmt;
10142 register dw_die_ref context_die;
10143 int depth;
10145 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
10146 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10148 if (! BLOCK_ABSTRACT (stmt))
10150 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10151 BLOCK_NUMBER (stmt));
10152 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10153 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10154 BLOCK_NUMBER (stmt));
10155 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10158 decls_for_scope (stmt, stmt_die, depth);
10161 /* Generate a DIE for an inlined subprogram. */
10163 static void
10164 gen_inlined_subroutine_die (stmt, context_die, depth)
10165 register tree stmt;
10166 register dw_die_ref context_die;
10167 int depth;
10169 if (! BLOCK_ABSTRACT (stmt))
10171 register dw_die_ref subr_die
10172 = new_die (DW_TAG_inlined_subroutine, context_die);
10173 register tree decl = block_ultimate_origin (stmt);
10174 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10176 /* Emit info for the abstract instance first, if we haven't yet. */
10177 gen_abstract_function (decl);
10179 add_abstract_origin_attribute (subr_die, decl);
10180 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10181 BLOCK_NUMBER (stmt));
10182 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10183 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10184 BLOCK_NUMBER (stmt));
10185 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10186 decls_for_scope (stmt, subr_die, depth);
10187 current_function_has_inlines = 1;
10191 /* Generate a DIE for a field in a record, or structure. */
10193 static void
10194 gen_field_die (decl, context_die)
10195 register tree decl;
10196 register dw_die_ref context_die;
10198 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
10200 add_name_and_src_coords_attributes (decl_die, decl);
10201 add_type_attribute (decl_die, member_declared_type (decl),
10202 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10203 context_die);
10205 /* If this is a bit field... */
10206 if (DECL_BIT_FIELD_TYPE (decl))
10208 add_byte_size_attribute (decl_die, decl);
10209 add_bit_size_attribute (decl_die, decl);
10210 add_bit_offset_attribute (decl_die, decl);
10213 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10214 add_data_member_location_attribute (decl_die, decl);
10216 if (DECL_ARTIFICIAL (decl))
10217 add_AT_flag (decl_die, DW_AT_artificial, 1);
10219 if (TREE_PROTECTED (decl))
10220 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10222 else if (TREE_PRIVATE (decl))
10223 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10226 #if 0
10227 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10228 Use modified_type_die instead.
10229 We keep this code here just in case these types of DIEs may be needed to
10230 represent certain things in other languages (e.g. Pascal) someday. */
10231 static void
10232 gen_pointer_type_die (type, context_die)
10233 register tree type;
10234 register dw_die_ref context_die;
10236 register dw_die_ref ptr_die
10237 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
10239 equate_type_number_to_die (type, ptr_die);
10240 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10241 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10244 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10245 Use modified_type_die instead.
10246 We keep this code here just in case these types of DIEs may be needed to
10247 represent certain things in other languages (e.g. Pascal) someday. */
10248 static void
10249 gen_reference_type_die (type, context_die)
10250 register tree type;
10251 register dw_die_ref context_die;
10253 register dw_die_ref ref_die
10254 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
10256 equate_type_number_to_die (type, ref_die);
10257 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10258 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10260 #endif
10262 /* Generate a DIE for a pointer to a member type. */
10263 static void
10264 gen_ptr_to_mbr_type_die (type, context_die)
10265 register tree type;
10266 register dw_die_ref context_die;
10268 register dw_die_ref ptr_die
10269 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
10271 equate_type_number_to_die (type, ptr_die);
10272 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10273 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10274 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10277 /* Generate the DIE for the compilation unit. */
10279 static dw_die_ref
10280 gen_compile_unit_die (filename)
10281 register const char *filename;
10283 register dw_die_ref die;
10284 char producer[250];
10285 const char *wd = getpwd ();
10286 int language;
10288 die = new_die (DW_TAG_compile_unit, NULL);
10289 add_name_attribute (die, filename);
10291 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10292 add_AT_string (die, DW_AT_comp_dir, wd);
10294 sprintf (producer, "%s %s", language_string, version_string);
10296 #ifdef MIPS_DEBUGGING_INFO
10297 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10298 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10299 not appear in the producer string, the debugger reaches the conclusion
10300 that the object file is stripped and has no debugging information.
10301 To get the MIPS/SGI debugger to believe that there is debugging
10302 information in the object file, we add a -g to the producer string. */
10303 if (debug_info_level > DINFO_LEVEL_TERSE)
10304 strcat (producer, " -g");
10305 #endif
10307 add_AT_string (die, DW_AT_producer, producer);
10309 if (strcmp (language_string, "GNU C++") == 0)
10310 language = DW_LANG_C_plus_plus;
10311 else if (strcmp (language_string, "GNU Ada") == 0)
10312 language = DW_LANG_Ada83;
10313 else if (strcmp (language_string, "GNU F77") == 0)
10314 language = DW_LANG_Fortran77;
10315 else if (strcmp (language_string, "GNU Pascal") == 0)
10316 language = DW_LANG_Pascal83;
10317 else if (strcmp (language_string, "GNU Java") == 0)
10318 language = DW_LANG_Java;
10319 else if (flag_traditional)
10320 language = DW_LANG_C;
10321 else
10322 language = DW_LANG_C89;
10324 add_AT_unsigned (die, DW_AT_language, language);
10326 return die;
10329 /* Generate a DIE for a string type. */
10331 static void
10332 gen_string_type_die (type, context_die)
10333 register tree type;
10334 register dw_die_ref context_die;
10336 register dw_die_ref type_die
10337 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10339 equate_type_number_to_die (type, type_die);
10341 /* Fudge the string length attribute for now. */
10343 /* TODO: add string length info.
10344 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10345 bound_representation (upper_bound, 0, 'u'); */
10348 /* Generate the DIE for a base class. */
10350 static void
10351 gen_inheritance_die (binfo, context_die)
10352 register tree binfo;
10353 register dw_die_ref context_die;
10355 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10357 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10358 add_data_member_location_attribute (die, binfo);
10360 if (TREE_VIA_VIRTUAL (binfo))
10361 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10362 if (TREE_VIA_PUBLIC (binfo))
10363 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10364 else if (TREE_VIA_PROTECTED (binfo))
10365 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10368 /* Generate a DIE for a class member. */
10370 static void
10371 gen_member_die (type, context_die)
10372 register tree type;
10373 register dw_die_ref context_die;
10375 register tree member;
10376 dw_die_ref child;
10378 /* If this is not an incomplete type, output descriptions of each of its
10379 members. Note that as we output the DIEs necessary to represent the
10380 members of this record or union type, we will also be trying to output
10381 DIEs to represent the *types* of those members. However the `type'
10382 function (above) will specifically avoid generating type DIEs for member
10383 types *within* the list of member DIEs for this (containing) type execpt
10384 for those types (of members) which are explicitly marked as also being
10385 members of this (containing) type themselves. The g++ front- end can
10386 force any given type to be treated as a member of some other
10387 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10388 to point to the TREE node representing the appropriate (containing)
10389 type. */
10391 /* First output info about the base classes. */
10392 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10394 register tree bases = TYPE_BINFO_BASETYPES (type);
10395 register int n_bases = TREE_VEC_LENGTH (bases);
10396 register int i;
10398 for (i = 0; i < n_bases; i++)
10399 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10402 /* Now output info about the data members and type members. */
10403 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10405 /* If we thought we were generating minimal debug info for TYPE
10406 and then changed our minds, some of the member declarations
10407 may have already been defined. Don't define them again, but
10408 do put them in the right order. */
10410 child = lookup_decl_die (member);
10411 if (child)
10412 splice_child_die (context_die, child);
10413 else
10414 gen_decl_die (member, context_die);
10417 /* Now output info about the function members (if any). */
10418 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10420 child = lookup_decl_die (member);
10421 if (child)
10422 splice_child_die (context_die, child);
10423 else
10424 gen_decl_die (member, context_die);
10428 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10429 is set, we pretend that the type was never defined, so we only get the
10430 member DIEs needed by later specification DIEs. */
10432 static void
10433 gen_struct_or_union_type_die (type, context_die)
10434 register tree type;
10435 register dw_die_ref context_die;
10437 register dw_die_ref type_die = lookup_type_die (type);
10438 register dw_die_ref scope_die = 0;
10439 register int nested = 0;
10440 int complete = (TYPE_SIZE (type)
10441 && (! TYPE_STUB_DECL (type)
10442 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10444 if (type_die && ! complete)
10445 return;
10447 if (TYPE_CONTEXT (type) != NULL_TREE
10448 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10449 nested = 1;
10451 scope_die = scope_die_for (type, context_die);
10453 if (! type_die || (nested && scope_die == comp_unit_die))
10454 /* First occurrence of type or toplevel definition of nested class. */
10456 register dw_die_ref old_die = type_die;
10458 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10459 ? DW_TAG_structure_type : DW_TAG_union_type,
10460 scope_die);
10461 equate_type_number_to_die (type, type_die);
10462 if (old_die)
10463 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10464 else
10465 add_name_attribute (type_die, type_tag (type));
10467 else
10468 remove_AT (type_die, DW_AT_declaration);
10470 /* If this type has been completed, then give it a byte_size attribute and
10471 then give a list of members. */
10472 if (complete)
10474 /* Prevent infinite recursion in cases where the type of some member of
10475 this type is expressed in terms of this type itself. */
10476 TREE_ASM_WRITTEN (type) = 1;
10477 add_byte_size_attribute (type_die, type);
10478 if (TYPE_STUB_DECL (type) != NULL_TREE)
10479 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10481 /* If the first reference to this type was as the return type of an
10482 inline function, then it may not have a parent. Fix this now. */
10483 if (type_die->die_parent == NULL)
10484 add_child_die (scope_die, type_die);
10486 push_decl_scope (type);
10487 gen_member_die (type, type_die);
10488 pop_decl_scope ();
10490 /* GNU extension: Record what type our vtable lives in. */
10491 if (TYPE_VFIELD (type))
10493 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10495 gen_type_die (vtype, context_die);
10496 add_AT_die_ref (type_die, DW_AT_containing_type,
10497 lookup_type_die (vtype));
10500 else
10502 add_AT_flag (type_die, DW_AT_declaration, 1);
10504 /* We don't need to do this for function-local types. */
10505 if (! decl_function_context (TYPE_STUB_DECL (type)))
10506 add_incomplete_type (type);
10510 /* Generate a DIE for a subroutine _type_. */
10512 static void
10513 gen_subroutine_type_die (type, context_die)
10514 register tree type;
10515 register dw_die_ref context_die;
10517 register tree return_type = TREE_TYPE (type);
10518 register dw_die_ref subr_die
10519 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10521 equate_type_number_to_die (type, subr_die);
10522 add_prototyped_attribute (subr_die, type);
10523 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10524 gen_formal_types_die (type, subr_die);
10527 /* Generate a DIE for a type definition */
10529 static void
10530 gen_typedef_die (decl, context_die)
10531 register tree decl;
10532 register dw_die_ref context_die;
10534 register dw_die_ref type_die;
10535 register tree origin;
10537 if (TREE_ASM_WRITTEN (decl))
10538 return;
10539 TREE_ASM_WRITTEN (decl) = 1;
10541 type_die = new_die (DW_TAG_typedef, context_die);
10542 origin = decl_ultimate_origin (decl);
10543 if (origin != NULL)
10544 add_abstract_origin_attribute (type_die, origin);
10545 else
10547 register tree type;
10548 add_name_and_src_coords_attributes (type_die, decl);
10549 if (DECL_ORIGINAL_TYPE (decl))
10551 type = DECL_ORIGINAL_TYPE (decl);
10553 if (type == TREE_TYPE (decl))
10554 abort ();
10555 else
10556 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10558 else
10559 type = TREE_TYPE (decl);
10560 add_type_attribute (type_die, type, TREE_READONLY (decl),
10561 TREE_THIS_VOLATILE (decl), context_die);
10564 if (DECL_ABSTRACT (decl))
10565 equate_decl_number_to_die (decl, type_die);
10568 /* Generate a type description DIE. */
10570 static void
10571 gen_type_die (type, context_die)
10572 register tree type;
10573 register dw_die_ref context_die;
10575 int need_pop;
10577 if (type == NULL_TREE || type == error_mark_node)
10578 return;
10580 /* We are going to output a DIE to represent the unqualified version of
10581 this type (i.e. without any const or volatile qualifiers) so get the
10582 main variant (i.e. the unqualified version) of this type now. */
10583 type = type_main_variant (type);
10585 if (TREE_ASM_WRITTEN (type))
10586 return;
10588 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10589 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10591 TREE_ASM_WRITTEN (type) = 1;
10592 gen_decl_die (TYPE_NAME (type), context_die);
10593 return;
10596 switch (TREE_CODE (type))
10598 case ERROR_MARK:
10599 break;
10601 case POINTER_TYPE:
10602 case REFERENCE_TYPE:
10603 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10604 ensures that the gen_type_die recursion will terminate even if the
10605 type is recursive. Recursive types are possible in Ada. */
10606 /* ??? We could perhaps do this for all types before the switch
10607 statement. */
10608 TREE_ASM_WRITTEN (type) = 1;
10610 /* For these types, all that is required is that we output a DIE (or a
10611 set of DIEs) to represent the "basis" type. */
10612 gen_type_die (TREE_TYPE (type), context_die);
10613 break;
10615 case OFFSET_TYPE:
10616 /* This code is used for C++ pointer-to-data-member types.
10617 Output a description of the relevant class type. */
10618 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10620 /* Output a description of the type of the object pointed to. */
10621 gen_type_die (TREE_TYPE (type), context_die);
10623 /* Now output a DIE to represent this pointer-to-data-member type
10624 itself. */
10625 gen_ptr_to_mbr_type_die (type, context_die);
10626 break;
10628 case SET_TYPE:
10629 gen_type_die (TYPE_DOMAIN (type), context_die);
10630 gen_set_type_die (type, context_die);
10631 break;
10633 case FILE_TYPE:
10634 gen_type_die (TREE_TYPE (type), context_die);
10635 abort (); /* No way to represent these in Dwarf yet! */
10636 break;
10638 case FUNCTION_TYPE:
10639 /* Force out return type (in case it wasn't forced out already). */
10640 gen_type_die (TREE_TYPE (type), context_die);
10641 gen_subroutine_type_die (type, context_die);
10642 break;
10644 case METHOD_TYPE:
10645 /* Force out return type (in case it wasn't forced out already). */
10646 gen_type_die (TREE_TYPE (type), context_die);
10647 gen_subroutine_type_die (type, context_die);
10648 break;
10650 case ARRAY_TYPE:
10651 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10653 gen_type_die (TREE_TYPE (type), context_die);
10654 gen_string_type_die (type, context_die);
10656 else
10657 gen_array_type_die (type, context_die);
10658 break;
10660 case VECTOR_TYPE:
10661 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10662 break;
10664 case ENUMERAL_TYPE:
10665 case RECORD_TYPE:
10666 case UNION_TYPE:
10667 case QUAL_UNION_TYPE:
10668 /* If this is a nested type whose containing class hasn't been
10669 written out yet, writing it out will cover this one, too.
10670 This does not apply to instantiations of member class templates;
10671 they need to be added to the containing class as they are
10672 generated. FIXME: This hurts the idea of combining type decls
10673 from multiple TUs, since we can't predict what set of template
10674 instantiations we'll get. */
10675 if (TYPE_CONTEXT (type)
10676 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10677 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10679 gen_type_die (TYPE_CONTEXT (type), context_die);
10681 if (TREE_ASM_WRITTEN (type))
10682 return;
10684 /* If that failed, attach ourselves to the stub. */
10685 push_decl_scope (TYPE_CONTEXT (type));
10686 context_die = lookup_type_die (TYPE_CONTEXT (type));
10687 need_pop = 1;
10689 else
10690 need_pop = 0;
10692 if (TREE_CODE (type) == ENUMERAL_TYPE)
10693 gen_enumeration_type_die (type, context_die);
10694 else
10695 gen_struct_or_union_type_die (type, context_die);
10697 if (need_pop)
10698 pop_decl_scope ();
10700 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10701 it up if it is ever completed. gen_*_type_die will set it for us
10702 when appropriate. */
10703 return;
10705 case VOID_TYPE:
10706 case INTEGER_TYPE:
10707 case REAL_TYPE:
10708 case COMPLEX_TYPE:
10709 case BOOLEAN_TYPE:
10710 case CHAR_TYPE:
10711 /* No DIEs needed for fundamental types. */
10712 break;
10714 case LANG_TYPE:
10715 /* No Dwarf representation currently defined. */
10716 break;
10718 default:
10719 abort ();
10722 TREE_ASM_WRITTEN (type) = 1;
10725 /* Generate a DIE for a tagged type instantiation. */
10727 static void
10728 gen_tagged_type_instantiation_die (type, context_die)
10729 register tree type;
10730 register dw_die_ref context_die;
10732 if (type == NULL_TREE || type == error_mark_node)
10733 return;
10735 /* We are going to output a DIE to represent the unqualified version of
10736 this type (i.e. without any const or volatile qualifiers) so make sure
10737 that we have the main variant (i.e. the unqualified version) of this
10738 type now. */
10739 if (type != type_main_variant (type))
10740 abort ();
10742 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10743 an instance of an unresolved type. */
10745 switch (TREE_CODE (type))
10747 case ERROR_MARK:
10748 break;
10750 case ENUMERAL_TYPE:
10751 gen_inlined_enumeration_type_die (type, context_die);
10752 break;
10754 case RECORD_TYPE:
10755 gen_inlined_structure_type_die (type, context_die);
10756 break;
10758 case UNION_TYPE:
10759 case QUAL_UNION_TYPE:
10760 gen_inlined_union_type_die (type, context_die);
10761 break;
10763 default:
10764 abort ();
10768 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10769 things which are local to the given block. */
10771 static void
10772 gen_block_die (stmt, context_die, depth)
10773 register tree stmt;
10774 register dw_die_ref context_die;
10775 int depth;
10777 register int must_output_die = 0;
10778 register tree origin;
10779 register tree decl;
10780 register enum tree_code origin_code;
10782 /* Ignore blocks never really used to make RTL. */
10784 if (stmt == NULL_TREE || !TREE_USED (stmt)
10785 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10786 return;
10788 /* Determine the "ultimate origin" of this block. This block may be an
10789 inlined instance of an inlined instance of inline function, so we have
10790 to trace all of the way back through the origin chain to find out what
10791 sort of node actually served as the original seed for the creation of
10792 the current block. */
10793 origin = block_ultimate_origin (stmt);
10794 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10796 /* Determine if we need to output any Dwarf DIEs at all to represent this
10797 block. */
10798 if (origin_code == FUNCTION_DECL)
10799 /* The outer scopes for inlinings *must* always be represented. We
10800 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10801 must_output_die = 1;
10802 else
10804 /* In the case where the current block represents an inlining of the
10805 "body block" of an inline function, we must *NOT* output any DIE for
10806 this block because we have already output a DIE to represent the
10807 whole inlined function scope and the "body block" of any function
10808 doesn't really represent a different scope according to ANSI C
10809 rules. So we check here to make sure that this block does not
10810 represent a "body block inlining" before trying to set the
10811 `must_output_die' flag. */
10812 if (! is_body_block (origin ? origin : stmt))
10814 /* Determine if this block directly contains any "significant"
10815 local declarations which we will need to output DIEs for. */
10816 if (debug_info_level > DINFO_LEVEL_TERSE)
10817 /* We are not in terse mode so *any* local declaration counts
10818 as being a "significant" one. */
10819 must_output_die = (BLOCK_VARS (stmt) != NULL);
10820 else
10821 /* We are in terse mode, so only local (nested) function
10822 definitions count as "significant" local declarations. */
10823 for (decl = BLOCK_VARS (stmt);
10824 decl != NULL; decl = TREE_CHAIN (decl))
10825 if (TREE_CODE (decl) == FUNCTION_DECL
10826 && DECL_INITIAL (decl))
10828 must_output_die = 1;
10829 break;
10834 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10835 DIE for any block which contains no significant local declarations at
10836 all. Rather, in such cases we just call `decls_for_scope' so that any
10837 needed Dwarf info for any sub-blocks will get properly generated. Note
10838 that in terse mode, our definition of what constitutes a "significant"
10839 local declaration gets restricted to include only inlined function
10840 instances and local (nested) function definitions. */
10841 if (must_output_die)
10843 if (origin_code == FUNCTION_DECL)
10844 gen_inlined_subroutine_die (stmt, context_die, depth);
10845 else
10846 gen_lexical_block_die (stmt, context_die, depth);
10848 else
10849 decls_for_scope (stmt, context_die, depth);
10852 /* Generate all of the decls declared within a given scope and (recursively)
10853 all of its sub-blocks. */
10855 static void
10856 decls_for_scope (stmt, context_die, depth)
10857 register tree stmt;
10858 register dw_die_ref context_die;
10859 int depth;
10861 register tree decl;
10862 register tree subblocks;
10864 /* Ignore blocks never really used to make RTL. */
10865 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10866 return;
10868 /* Output the DIEs to represent all of the data objects and typedefs
10869 declared directly within this block but not within any nested
10870 sub-blocks. Also, nested function and tag DIEs have been
10871 generated with a parent of NULL; fix that up now. */
10872 for (decl = BLOCK_VARS (stmt);
10873 decl != NULL; decl = TREE_CHAIN (decl))
10875 register dw_die_ref die;
10877 if (TREE_CODE (decl) == FUNCTION_DECL)
10878 die = lookup_decl_die (decl);
10879 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
10880 die = lookup_type_die (TREE_TYPE (decl));
10881 else
10882 die = NULL;
10884 if (die != NULL && die->die_parent == NULL)
10885 add_child_die (context_die, die);
10886 else
10887 gen_decl_die (decl, context_die);
10890 /* Output the DIEs to represent all sub-blocks (and the items declared
10891 therein) of this block. */
10892 for (subblocks = BLOCK_SUBBLOCKS (stmt);
10893 subblocks != NULL;
10894 subblocks = BLOCK_CHAIN (subblocks))
10895 gen_block_die (subblocks, context_die, depth + 1);
10898 /* Is this a typedef we can avoid emitting? */
10900 static inline int
10901 is_redundant_typedef (decl)
10902 register tree decl;
10904 if (TYPE_DECL_IS_STUB (decl))
10905 return 1;
10907 if (DECL_ARTIFICIAL (decl)
10908 && DECL_CONTEXT (decl)
10909 && is_tagged_type (DECL_CONTEXT (decl))
10910 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
10911 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
10912 /* Also ignore the artificial member typedef for the class name. */
10913 return 1;
10915 return 0;
10918 /* Generate Dwarf debug information for a decl described by DECL. */
10920 static void
10921 gen_decl_die (decl, context_die)
10922 register tree decl;
10923 register dw_die_ref context_die;
10925 register tree origin;
10927 if (TREE_CODE (decl) == ERROR_MARK)
10928 return;
10930 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10931 if (DECL_IGNORED_P (decl))
10932 return;
10934 switch (TREE_CODE (decl))
10936 case CONST_DECL:
10937 /* The individual enumerators of an enum type get output when we output
10938 the Dwarf representation of the relevant enum type itself. */
10939 break;
10941 case FUNCTION_DECL:
10942 /* Don't output any DIEs to represent mere function declarations,
10943 unless they are class members or explicit block externs. */
10944 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
10945 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
10946 break;
10948 /* If we're emitting an out-of-line copy of an inline function,
10949 emit info for the abstract instance and set up to refer to it. */
10950 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
10951 && ! class_scope_p (context_die)
10952 /* gen_abstract_function won't emit a die if this is just a
10953 declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
10954 that case, because that works only if we have a die. */
10955 && DECL_INITIAL (decl) != NULL_TREE)
10957 gen_abstract_function (decl);
10958 set_decl_origin_self (decl);
10961 if (debug_info_level > DINFO_LEVEL_TERSE)
10963 /* Before we describe the FUNCTION_DECL itself, make sure that we
10964 have described its return type. */
10965 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
10967 /* And its virtual context. */
10968 if (DECL_VINDEX (decl) != NULL_TREE)
10969 gen_type_die (DECL_CONTEXT (decl), context_die);
10971 /* And its containing type. */
10972 origin = decl_class_context (decl);
10973 if (origin != NULL_TREE)
10974 gen_type_die_for_member (origin, decl, context_die);
10977 /* Now output a DIE to represent the function itself. */
10978 gen_subprogram_die (decl, context_die);
10979 break;
10981 case TYPE_DECL:
10982 /* If we are in terse mode, don't generate any DIEs to represent any
10983 actual typedefs. */
10984 if (debug_info_level <= DINFO_LEVEL_TERSE)
10985 break;
10987 /* In the special case of a TYPE_DECL node representing the
10988 declaration of some type tag, if the given TYPE_DECL is marked as
10989 having been instantiated from some other (original) TYPE_DECL node
10990 (e.g. one which was generated within the original definition of an
10991 inline function) we have to generate a special (abbreviated)
10992 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
10993 DIE here. */
10994 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
10996 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
10997 break;
11000 if (is_redundant_typedef (decl))
11001 gen_type_die (TREE_TYPE (decl), context_die);
11002 else
11003 /* Output a DIE to represent the typedef itself. */
11004 gen_typedef_die (decl, context_die);
11005 break;
11007 case LABEL_DECL:
11008 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11009 gen_label_die (decl, context_die);
11010 break;
11012 case VAR_DECL:
11013 /* If we are in terse mode, don't generate any DIEs to represent any
11014 variable declarations or definitions. */
11015 if (debug_info_level <= DINFO_LEVEL_TERSE)
11016 break;
11018 /* Output any DIEs that are needed to specify the type of this data
11019 object. */
11020 gen_type_die (TREE_TYPE (decl), context_die);
11022 /* And its containing type. */
11023 origin = decl_class_context (decl);
11024 if (origin != NULL_TREE)
11025 gen_type_die_for_member (origin, decl, context_die);
11027 /* Now output the DIE to represent the data object itself. This gets
11028 complicated because of the possibility that the VAR_DECL really
11029 represents an inlined instance of a formal parameter for an inline
11030 function. */
11031 origin = decl_ultimate_origin (decl);
11032 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11033 gen_formal_parameter_die (decl, context_die);
11034 else
11035 gen_variable_die (decl, context_die);
11036 break;
11038 case FIELD_DECL:
11039 /* Ignore the nameless fields that are used to skip bits, but
11040 handle C++ anonymous unions. */
11041 if (DECL_NAME (decl) != NULL_TREE
11042 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11044 gen_type_die (member_declared_type (decl), context_die);
11045 gen_field_die (decl, context_die);
11047 break;
11049 case PARM_DECL:
11050 gen_type_die (TREE_TYPE (decl), context_die);
11051 gen_formal_parameter_die (decl, context_die);
11052 break;
11054 case NAMESPACE_DECL:
11055 /* Ignore for now. */
11056 break;
11058 default:
11059 abort ();
11063 /* Add Ada "use" clause information for SGI Workshop debugger. */
11065 void
11066 dwarf2out_add_library_unit_info (filename, context_list)
11067 const char *filename;
11068 const char *context_list;
11070 unsigned int file_index;
11072 if (filename != NULL)
11074 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
11075 tree context_list_decl
11076 = build_decl (LABEL_DECL, get_identifier (context_list),
11077 void_type_node);
11079 TREE_PUBLIC (context_list_decl) = TRUE;
11080 add_name_attribute (unit_die, context_list);
11081 file_index = lookup_filename (&decl_file_table, filename);
11082 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11083 add_pubname (context_list_decl, unit_die);
11087 /* Write the debugging output for DECL. */
11089 void
11090 dwarf2out_decl (decl)
11091 register tree decl;
11093 register dw_die_ref context_die = comp_unit_die;
11095 if (TREE_CODE (decl) == ERROR_MARK)
11096 return;
11098 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11099 if (DECL_IGNORED_P (decl))
11100 return;
11102 switch (TREE_CODE (decl))
11104 case FUNCTION_DECL:
11105 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11106 builtin function. Explicit programmer-supplied declarations of
11107 these same functions should NOT be ignored however. */
11108 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11109 return;
11111 /* What we would really like to do here is to filter out all mere
11112 file-scope declarations of file-scope functions which are never
11113 referenced later within this translation unit (and keep all of ones
11114 that *are* referenced later on) but we aren't clairvoyant, so we have
11115 no idea which functions will be referenced in the future (i.e. later
11116 on within the current translation unit). So here we just ignore all
11117 file-scope function declarations which are not also definitions. If
11118 and when the debugger needs to know something about these functions,
11119 it will have to hunt around and find the DWARF information associated
11120 with the definition of the function. Note that we can't just check
11121 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
11122 definitions and which ones represent mere declarations. We have to
11123 check `DECL_INITIAL' instead. That's because the C front-end
11124 supports some weird semantics for "extern inline" function
11125 definitions. These can get inlined within the current translation
11126 unit (an thus, we need to generate DWARF info for their abstract
11127 instances so that the DWARF info for the concrete inlined instances
11128 can have something to refer to) but the compiler never generates any
11129 out-of-lines instances of such things (despite the fact that they
11130 *are* definitions). The important point is that the C front-end
11131 marks these "extern inline" functions as DECL_EXTERNAL, but we need
11132 to generate DWARF for them anyway. Note that the C++ front-end also
11133 plays some similar games for inline function definitions appearing
11134 within include files which also contain
11135 `#pragma interface' pragmas. */
11136 if (DECL_INITIAL (decl) == NULL_TREE)
11137 return;
11139 /* If we're a nested function, initially use a parent of NULL; if we're
11140 a plain function, this will be fixed up in decls_for_scope. If
11141 we're a method, it will be ignored, since we already have a DIE. */
11142 if (decl_function_context (decl))
11143 context_die = NULL;
11145 break;
11147 case VAR_DECL:
11148 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11149 declaration and if the declaration was never even referenced from
11150 within this entire compilation unit. We suppress these DIEs in
11151 order to save space in the .debug section (by eliminating entries
11152 which are probably useless). Note that we must not suppress
11153 block-local extern declarations (whether used or not) because that
11154 would screw-up the debugger's name lookup mechanism and cause it to
11155 miss things which really ought to be in scope at a given point. */
11156 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11157 return;
11159 /* If we are in terse mode, don't generate any DIEs to represent any
11160 variable declarations or definitions. */
11161 if (debug_info_level <= DINFO_LEVEL_TERSE)
11162 return;
11163 break;
11165 case TYPE_DECL:
11166 /* Don't emit stubs for types unless they are needed by other DIEs. */
11167 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11168 return;
11170 /* Don't bother trying to generate any DIEs to represent any of the
11171 normal built-in types for the language we are compiling. */
11172 if (DECL_SOURCE_LINE (decl) == 0)
11174 /* OK, we need to generate one for `bool' so GDB knows what type
11175 comparisons have. */
11176 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11177 == DW_LANG_C_plus_plus)
11178 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
11179 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11181 return;
11184 /* If we are in terse mode, don't generate any DIEs for types. */
11185 if (debug_info_level <= DINFO_LEVEL_TERSE)
11186 return;
11188 /* If we're a function-scope tag, initially use a parent of NULL;
11189 this will be fixed up in decls_for_scope. */
11190 if (decl_function_context (decl))
11191 context_die = NULL;
11193 break;
11195 default:
11196 return;
11199 gen_decl_die (decl, context_die);
11202 /* Output a marker (i.e. a label) for the beginning of the generated code for
11203 a lexical block. */
11205 void
11206 dwarf2out_begin_block (blocknum)
11207 register unsigned blocknum;
11209 function_section (current_function_decl);
11210 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11213 /* Output a marker (i.e. a label) for the end of the generated code for a
11214 lexical block. */
11216 void
11217 dwarf2out_end_block (blocknum)
11218 register unsigned blocknum;
11220 function_section (current_function_decl);
11221 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11224 /* Returns nonzero if it is appropriate not to emit any debugging
11225 information for BLOCK, because it doesn't contain any instructions.
11227 Don't allow this for blocks with nested functions or local classes
11228 as we would end up with orphans, and in the presence of scheduling
11229 we may end up calling them anyway. */
11232 dwarf2out_ignore_block (block)
11233 tree block;
11235 tree decl;
11236 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11237 if (TREE_CODE (decl) == FUNCTION_DECL
11238 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11239 return 0;
11240 return 1;
11243 /* Lookup a filename (in the list of filenames that we know about here in
11244 dwarf2out.c) and return its "index". The index of each (known) filename is
11245 just a unique number which is associated with only that one filename.
11246 We need such numbers for the sake of generating labels
11247 (in the .debug_sfnames section) and references to those
11248 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
11249 If the filename given as an argument is not found in our current list,
11250 add it to the list and assign it the next available unique index number.
11251 In order to speed up searches, we remember the index of the filename
11252 was looked up last. This handles the majority of all searches. */
11254 static unsigned
11255 lookup_filename (t, file_name)
11256 struct file_table *t;
11257 const char *file_name;
11259 register unsigned i;
11261 /* Check to see if the file name that was searched on the previous
11262 call matches this file name. If so, return the index. */
11263 if (t->last_lookup_index != 0)
11264 if (strcmp (file_name, t->table[t->last_lookup_index]) == 0)
11265 return t->last_lookup_index;
11267 /* Didn't match the previous lookup, search the table */
11268 for (i = 1; i < t->in_use; ++i)
11269 if (strcmp (file_name, t->table[i]) == 0)
11271 t->last_lookup_index = i;
11272 return i;
11275 /* Prepare to add a new table entry by making sure there is enough space in
11276 the table to do so. If not, expand the current table. */
11277 if (i == t->allocated)
11279 t->allocated = i + FILE_TABLE_INCREMENT;
11280 t->table = (char **)
11281 xrealloc (t->table, t->allocated * sizeof (char *));
11284 /* Add the new entry to the end of the filename table. */
11285 t->table[i] = xstrdup (file_name);
11286 t->in_use = i + 1;
11287 t->last_lookup_index = i;
11289 return i;
11292 static void
11293 init_file_table (t)
11294 struct file_table *t;
11296 /* Allocate the initial hunk of the file_table. */
11297 t->table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11298 t->allocated = FILE_TABLE_INCREMENT;
11300 /* Skip the first entry - file numbers begin at 1. */
11301 t->in_use = 1;
11302 t->last_lookup_index = 0;
11305 /* Output a label to mark the beginning of a source code line entry
11306 and record information relating to this source line, in
11307 'line_info_table' for later output of the .debug_line section. */
11309 void
11310 dwarf2out_line (filename, line)
11311 register const char *filename;
11312 register unsigned line;
11314 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11316 function_section (current_function_decl);
11318 if (DWARF2_ASM_LINE_DEBUG_INFO)
11320 unsigned old_in_use = line_file_table.in_use;
11321 unsigned file_num = lookup_filename (&line_file_table, filename);
11323 /* Emit the .file and .loc directives understood by GNU as. */
11324 #if 0
11325 /* ??? As of 2000-11-25, gas has a bug in which it doesn't
11326 actually use the file number argument. It merely remembers
11327 the last .file directive emitted. */
11328 if (file_num >= old_in_use)
11329 fprintf (asm_out_file, "\t.file %d \"%s\"\n", file_num, filename);
11330 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11331 #else
11332 static int last_file_num;
11333 if (file_num != last_file_num)
11335 last_file_num = file_num;
11336 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
11338 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
11339 #endif
11341 /* Indicate that line number info exists. */
11342 ++line_info_table_in_use;
11344 /* Indicate that multiple line number tables exist. */
11345 if (DECL_SECTION_NAME (current_function_decl))
11346 ++separate_line_info_table_in_use;
11348 else if (DECL_SECTION_NAME (current_function_decl))
11350 register dw_separate_line_info_ref line_info;
11351 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11352 separate_line_info_table_in_use);
11353 if (flag_debug_asm)
11354 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
11355 fputc ('\n', asm_out_file);
11357 /* expand the line info table if necessary */
11358 if (separate_line_info_table_in_use
11359 == separate_line_info_table_allocated)
11361 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11362 separate_line_info_table
11363 = (dw_separate_line_info_ref)
11364 xrealloc (separate_line_info_table,
11365 separate_line_info_table_allocated
11366 * sizeof (dw_separate_line_info_entry));
11369 /* Add the new entry at the end of the line_info_table. */
11370 line_info
11371 = &separate_line_info_table[separate_line_info_table_in_use++];
11372 line_info->dw_file_num = lookup_filename (&line_file_table, filename);
11373 line_info->dw_line_num = line;
11374 line_info->function = current_funcdef_number;
11376 else
11378 register dw_line_info_ref line_info;
11380 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11381 line_info_table_in_use);
11382 if (flag_debug_asm)
11383 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
11384 fputc ('\n', asm_out_file);
11386 /* Expand the line info table if necessary. */
11387 if (line_info_table_in_use == line_info_table_allocated)
11389 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11390 line_info_table
11391 = (dw_line_info_ref)
11392 xrealloc (line_info_table,
11393 (line_info_table_allocated
11394 * sizeof (dw_line_info_entry)));
11397 /* Add the new entry at the end of the line_info_table. */
11398 line_info = &line_info_table[line_info_table_in_use++];
11399 line_info->dw_file_num = lookup_filename (&line_file_table, filename);
11400 line_info->dw_line_num = line;
11405 /* Record the beginning of a new source file, for later output
11406 of the .debug_macinfo section. At present, unimplemented. */
11408 void
11409 dwarf2out_start_source_file (filename)
11410 register const char *filename ATTRIBUTE_UNUSED;
11412 if (flag_eliminate_dwarf2_dups)
11414 /* Record the beginning of the file for break_out_includes. */
11415 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11416 add_AT_string (bincl_die, DW_AT_name, filename);
11420 /* Record the end of a source file, for later output
11421 of the .debug_macinfo section. At present, unimplemented. */
11423 void
11424 dwarf2out_end_source_file ()
11426 if (flag_eliminate_dwarf2_dups)
11428 /* Record the end of the file for break_out_includes. */
11429 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11433 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11434 the tail part of the directive line, i.e. the part which is past the
11435 initial whitespace, #, whitespace, directive-name, whitespace part. */
11437 void
11438 dwarf2out_define (lineno, buffer)
11439 register unsigned lineno ATTRIBUTE_UNUSED;
11440 register const char *buffer ATTRIBUTE_UNUSED;
11442 static int initialized = 0;
11443 if (!initialized)
11445 dwarf2out_start_source_file (primary_filename);
11446 initialized = 1;
11450 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11451 the tail part of the directive line, i.e. the part which is past the
11452 initial whitespace, #, whitespace, directive-name, whitespace part. */
11454 void
11455 dwarf2out_undef (lineno, buffer)
11456 register unsigned lineno ATTRIBUTE_UNUSED;
11457 register const char *buffer ATTRIBUTE_UNUSED;
11461 /* Set up for Dwarf output at the start of compilation. */
11463 void
11464 dwarf2out_init (asm_out_file, main_input_filename)
11465 register FILE *asm_out_file;
11466 register const char *main_input_filename;
11468 /* Remember the name of the primary input file. */
11469 primary_filename = main_input_filename;
11471 init_file_table (&decl_file_table);
11472 init_file_table (&line_file_table);
11474 /* Allocate the initial hunk of the decl_die_table. */
11475 decl_die_table
11476 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11477 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11478 decl_die_table_in_use = 0;
11480 /* Allocate the initial hunk of the decl_scope_table. */
11481 decl_scope_table
11482 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11483 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11484 decl_scope_depth = 0;
11486 /* Allocate the initial hunk of the abbrev_die_table. */
11487 abbrev_die_table
11488 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11489 sizeof (dw_die_ref));
11490 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11491 /* Zero-th entry is allocated, but unused */
11492 abbrev_die_table_in_use = 1;
11494 /* Allocate the initial hunk of the line_info_table. */
11495 line_info_table
11496 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11497 sizeof (dw_line_info_entry));
11498 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11499 /* Zero-th entry is allocated, but unused */
11500 line_info_table_in_use = 1;
11502 /* Generate the initial DIE for the .debug section. Note that the (string)
11503 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11504 will (typically) be a relative pathname and that this pathname should be
11505 taken as being relative to the directory from which the compiler was
11506 invoked when the given (base) source file was compiled. */
11507 comp_unit_die = gen_compile_unit_die (main_input_filename);
11509 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11510 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11512 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11513 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
11514 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11515 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11516 else
11517 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11518 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11519 DEBUG_INFO_SECTION_LABEL, 0);
11520 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11521 DEBUG_LINE_SECTION_LABEL, 0);
11523 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11524 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11525 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11527 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11528 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11530 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
11531 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11532 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11533 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11536 /* Output stuff that dwarf requires at the end of every file,
11537 and generate the DWARF-2 debugging info. */
11539 void
11540 dwarf2out_finish ()
11542 limbo_die_node *node, *next_node;
11543 dw_die_ref die;
11545 /* Traverse the limbo die list, and add parent/child links. The only
11546 dies without parents that should be here are concrete instances of
11547 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11548 For concrete instances, we can get the parent die from the abstract
11549 instance. */
11550 for (node = limbo_die_list; node; node = next_node)
11552 next_node = node->next;
11553 die = node->die;
11555 if (die->die_parent == NULL)
11557 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11558 if (origin)
11559 add_child_die (origin->die_parent, die);
11560 else if (die == comp_unit_die)
11562 else
11563 abort ();
11565 free (node);
11567 limbo_die_list = NULL;
11569 /* Walk through the list of incomplete types again, trying once more to
11570 emit full debugging info for them. */
11571 retry_incomplete_types ();
11573 /* We need to reverse all the dies before break_out_includes, or
11574 we'll see the end of an include file before the beginning. */
11575 reverse_all_dies (comp_unit_die);
11577 /* Generate separate CUs for each of the include files we've seen.
11578 They will go into limbo_die_list. */
11579 if (flag_eliminate_dwarf2_dups)
11580 break_out_includes (comp_unit_die);
11582 /* Traverse the DIE's and add add sibling attributes to those DIE's
11583 that have children. */
11584 add_sibling_attributes (comp_unit_die);
11585 for (node = limbo_die_list; node; node = node->next)
11586 add_sibling_attributes (node->die);
11588 /* Output a terminator label for the .text section. */
11589 fputc ('\n', asm_out_file);
11590 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11591 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11593 #if 0
11594 /* Output a terminator label for the .data section. */
11595 fputc ('\n', asm_out_file);
11596 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11597 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11599 /* Output a terminator label for the .bss section. */
11600 fputc ('\n', asm_out_file);
11601 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11602 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11603 #endif
11605 /* Output the source line correspondence table. */
11606 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
11608 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11610 fputc ('\n', asm_out_file);
11611 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11612 output_line_info ();
11615 /* We can only use the low/high_pc attributes if all of the code
11616 was in .text. */
11617 if (separate_line_info_table_in_use == 0)
11619 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11620 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11623 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11624 debug_line_section_label);
11627 #if 0 /* unimplemented */
11628 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
11629 add_AT_unsigned (die, DW_AT_macro_info, 0);
11630 #endif
11632 /* Output all of the compilation units. We put the main one last so that
11633 the offsets are available to output_pubnames. */
11634 for (node = limbo_die_list; node; node = node->next)
11635 output_comp_unit (node->die);
11636 output_comp_unit (comp_unit_die);
11638 /* Output the abbreviation table. */
11639 fputc ('\n', asm_out_file);
11640 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11641 output_abbrev_section ();
11643 if (pubname_table_in_use)
11645 /* Output public names table. */
11646 fputc ('\n', asm_out_file);
11647 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
11648 output_pubnames ();
11651 /* We only put functions in the arange table, so don't write it out if
11652 we don't have any. */
11653 if (fde_table_in_use)
11655 /* Output the address range information. */
11656 fputc ('\n', asm_out_file);
11657 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
11658 output_aranges ();
11661 #endif /* DWARF2_DEBUGGING_INFO */