* dwarf2out.c (dwarf2out_finish): Forcibly return to the data
[official-gcc.git] / gcc / dwarf2out.c
blob6693c636646d558f395234589176054876387ee6
1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001
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 "tree.h"
41 #include "flags.h"
42 #include "rtl.h"
43 #include "hard-reg-set.h"
44 #include "regs.h"
45 #include "insn-config.h"
46 #include "reload.h"
47 #include "output.h"
48 #include "expr.h"
49 #include "except.h"
50 #include "dwarf2.h"
51 #include "dwarf2out.h"
52 #include "toplev.h"
53 #include "varray.h"
54 #include "ggc.h"
55 #include "md5.h"
56 #include "tm_p.h"
58 /* DWARF2 Abbreviation Glossary:
59 CFA = Canonical Frame Address
60 a fixed address on the stack which identifies a call frame.
61 We define it to be the value of SP just before the call insn.
62 The CFA register and offset, which may change during the course
63 of the function, are used to calculate its value at runtime.
64 CFI = Call Frame Instruction
65 an instruction for the DWARF2 abstract machine
66 CIE = Common Information Entry
67 information describing information common to one or more FDEs
68 DIE = Debugging Information Entry
69 FDE = Frame Description Entry
70 information describing the stack call frame, in particular,
71 how to restore registers
73 DW_CFA_... = DWARF2 CFA call frame instruction
74 DW_TAG_... = DWARF2 DIE tag */
76 /* Decide whether we want to emit frame unwind information for the current
77 translation unit. */
79 int
80 dwarf2out_do_frame ()
82 return (write_symbols == DWARF2_DEBUG
83 #ifdef DWARF2_FRAME_INFO
84 || DWARF2_FRAME_INFO
85 #endif
86 #ifdef DWARF2_UNWIND_INFO
87 || flag_unwind_tables
88 || (flag_exceptions && ! exceptions_via_longjmp)
89 #endif
93 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
95 /* How to start an assembler comment. */
96 #ifndef ASM_COMMENT_START
97 #define ASM_COMMENT_START ";#"
98 #endif
100 typedef struct dw_cfi_struct *dw_cfi_ref;
101 typedef struct dw_fde_struct *dw_fde_ref;
102 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
104 /* Call frames are described using a sequence of Call Frame
105 Information instructions. The register number, offset
106 and address fields are provided as possible operands;
107 their use is selected by the opcode field. */
109 typedef union dw_cfi_oprnd_struct
111 unsigned long dw_cfi_reg_num;
112 long int dw_cfi_offset;
113 const char *dw_cfi_addr;
114 struct dw_loc_descr_struct *dw_cfi_loc;
116 dw_cfi_oprnd;
118 typedef struct dw_cfi_struct
120 dw_cfi_ref dw_cfi_next;
121 enum dwarf_call_frame_info dw_cfi_opc;
122 dw_cfi_oprnd dw_cfi_oprnd1;
123 dw_cfi_oprnd dw_cfi_oprnd2;
125 dw_cfi_node;
127 /* This is how we define the location of the CFA. We use to handle it
128 as REG + OFFSET all the time, but now it can be more complex.
129 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
130 Instead of passing around REG and OFFSET, we pass a copy
131 of this structure. */
132 typedef struct cfa_loc
134 unsigned long reg;
135 long offset;
136 long base_offset;
137 int indirect; /* 1 if CFA is accessed via a dereference. */
138 } dw_cfa_location;
140 /* All call frame descriptions (FDE's) in the GCC generated DWARF
141 refer to a single Common Information Entry (CIE), defined at
142 the beginning of the .debug_frame section. This used of a single
143 CIE obviates the need to keep track of multiple CIE's
144 in the DWARF generation routines below. */
146 typedef struct dw_fde_struct
148 const char *dw_fde_begin;
149 const char *dw_fde_current_label;
150 const char *dw_fde_end;
151 dw_cfi_ref dw_fde_cfi;
152 int nothrow;
154 dw_fde_node;
156 /* Maximum size (in bytes) of an artificially generated label. */
157 #define MAX_ARTIFICIAL_LABEL_BYTES 30
159 /* The size of the target's pointer type. */
160 #ifndef PTR_SIZE
161 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
162 #endif
164 /* The size of addresses as they appear in the Dwarf 2 data.
165 Some architectures use word addresses to refer to code locations,
166 but Dwarf 2 info always uses byte addresses. On such machines,
167 Dwarf 2 addresses need to be larger than the architecture's
168 pointers. */
169 #ifndef DWARF2_ADDR_SIZE
170 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
171 #endif
173 /* The size in bytes of a DWARF field indicating an offset or length
174 relative to a debug info section, specified to be 4 bytes in the
175 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
176 as PTR_SIZE. */
178 #ifndef DWARF_OFFSET_SIZE
179 #define DWARF_OFFSET_SIZE 4
180 #endif
182 #define DWARF_VERSION 2
184 /* Round SIZE up to the nearest BOUNDARY. */
185 #define DWARF_ROUND(SIZE,BOUNDARY) \
186 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
188 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
189 #ifndef DWARF_CIE_DATA_ALIGNMENT
190 #ifdef STACK_GROWS_DOWNWARD
191 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
192 #else
193 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
194 #endif
195 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
197 /* A pointer to the base of a table that contains frame description
198 information for each routine. */
199 static dw_fde_ref fde_table;
201 /* Number of elements currently allocated for fde_table. */
202 static unsigned fde_table_allocated;
204 /* Number of elements in fde_table currently in use. */
205 static unsigned fde_table_in_use;
207 /* Size (in elements) of increments by which we may expand the
208 fde_table. */
209 #define FDE_TABLE_INCREMENT 256
211 /* A list of call frame insns for the CIE. */
212 static dw_cfi_ref cie_cfi_head;
214 /* The number of the current function definition for which debugging
215 information is being generated. These numbers range from 1 up to the
216 maximum number of function definitions contained within the current
217 compilation unit. These numbers are used to create unique label id's
218 unique to each function definition. */
219 static unsigned current_funcdef_number = 0;
221 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
222 attribute that accelerates the lookup of the FDE associated
223 with the subprogram. This variable holds the table index of the FDE
224 associated with the current function (body) definition. */
225 static unsigned current_funcdef_fde;
227 /* Forward declarations for functions defined in this file. */
229 static char *stripattributes PARAMS ((const char *));
230 static const char *dwarf_cfi_name PARAMS ((unsigned));
231 static dw_cfi_ref new_cfi PARAMS ((void));
232 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
233 static unsigned long size_of_uleb128 PARAMS ((unsigned long));
234 static unsigned long size_of_sleb128 PARAMS ((long));
235 static void output_uleb128 PARAMS ((unsigned long));
236 static void output_sleb128 PARAMS ((long));
237 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
238 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
239 static void lookup_cfa PARAMS ((dw_cfa_location *));
240 static void reg_save PARAMS ((const char *, unsigned,
241 unsigned, long));
242 static void initial_return_save PARAMS ((rtx));
243 static long stack_adjust_offset PARAMS ((rtx));
244 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref));
245 static void output_call_frame_info PARAMS ((int));
246 static void dwarf2out_stack_adjust PARAMS ((rtx));
247 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
249 /* Support for complex CFA locations. */
250 static void output_cfa_loc PARAMS ((dw_cfi_ref));
251 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
252 struct dw_loc_descr_struct *));
253 static struct dw_loc_descr_struct *build_cfa_loc
254 PARAMS ((dw_cfa_location *));
255 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
257 /* Definitions of defaults for assembler-dependent names of various
258 pseudo-ops and section names.
259 Theses may be overridden in the tm.h file (if necessary) for a particular
260 assembler. */
262 #ifdef OBJECT_FORMAT_ELF
263 #ifndef UNALIGNED_SHORT_ASM_OP
264 #define UNALIGNED_SHORT_ASM_OP "\t.2byte\t"
265 #endif
266 #ifndef UNALIGNED_INT_ASM_OP
267 #define UNALIGNED_INT_ASM_OP "\t.4byte\t"
268 #endif
269 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
270 #define UNALIGNED_DOUBLE_INT_ASM_OP "\t.8byte\t"
271 #endif
272 #endif /* OBJECT_FORMAT_ELF */
274 #ifndef ASM_BYTE_OP
275 #define ASM_BYTE_OP "\t.byte\t"
276 #endif
278 /* Data and reference forms for relocatable data. */
279 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
280 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
282 /* Pseudo-op for defining a new section. */
283 #ifndef SECTION_ASM_OP
284 #define SECTION_ASM_OP "\t.section\t"
285 #endif
287 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
288 print the SECTION_ASM_OP and the section name. The default here works for
289 almost all svr4 assemblers, except for the sparc, where the section name
290 must be enclosed in double quotes. (See sparcv4.h). */
291 #ifndef SECTION_FORMAT
292 #ifdef PUSHSECTION_FORMAT
293 #define SECTION_FORMAT PUSHSECTION_FORMAT
294 #else
295 #define SECTION_FORMAT "%s%s\n"
296 #endif
297 #endif
299 #ifndef FRAME_SECTION
300 #define FRAME_SECTION ".debug_frame"
301 #endif
303 #ifndef FUNC_BEGIN_LABEL
304 #define FUNC_BEGIN_LABEL "LFB"
305 #endif
306 #ifndef FUNC_END_LABEL
307 #define FUNC_END_LABEL "LFE"
308 #endif
309 #define CIE_AFTER_SIZE_LABEL "LSCIE"
310 #define CIE_END_LABEL "LECIE"
311 #define CIE_LENGTH_LABEL "LLCIE"
312 #define FDE_AFTER_SIZE_LABEL "LSFDE"
313 #define FDE_END_LABEL "LEFDE"
314 #define FDE_LENGTH_LABEL "LLFDE"
315 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
316 #define LINE_NUMBER_END_LABEL "LELT"
317 #define LN_PROLOG_AS_LABEL "LASLTP"
318 #define LN_PROLOG_END_LABEL "LELTP"
320 #define DIE_LABEL_PREFIX "DW"
322 /* Definitions of defaults for various types of primitive assembly language
323 output operations. These may be overridden from within the tm.h file,
324 but typically, that is unnecessary. */
326 #ifndef ASM_OUTPUT_SECTION
327 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
328 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
329 #endif
331 #ifndef ASM_OUTPUT_DWARF_DATA1
332 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
333 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
334 #endif
336 #ifndef ASM_OUTPUT_DWARF_DELTA1
337 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
338 do { fprintf ((FILE), "%s", ASM_BYTE_OP); \
339 assemble_name (FILE, LABEL1); \
340 fprintf (FILE, "-"); \
341 assemble_name (FILE, LABEL2); \
342 } while (0)
343 #endif
345 #ifdef UNALIGNED_INT_ASM_OP
347 #ifndef UNALIGNED_OFFSET_ASM_OP
348 #define UNALIGNED_OFFSET_ASM_OP \
349 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
350 #endif
352 #ifndef UNALIGNED_WORD_ASM_OP
353 #define UNALIGNED_WORD_ASM_OP \
354 ((DWARF2_ADDR_SIZE) == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP \
355 : (DWARF2_ADDR_SIZE) == 2 ? UNALIGNED_SHORT_ASM_OP \
356 : UNALIGNED_INT_ASM_OP)
357 #endif
359 #ifndef ASM_OUTPUT_DWARF_DELTA2
360 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
361 do { fprintf ((FILE), "%s", UNALIGNED_SHORT_ASM_OP); \
362 assemble_name (FILE, LABEL1); \
363 fprintf (FILE, "-"); \
364 assemble_name (FILE, LABEL2); \
365 } while (0)
366 #endif
368 #ifndef ASM_OUTPUT_DWARF_DELTA4
369 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
370 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
371 assemble_name (FILE, LABEL1); \
372 fprintf (FILE, "-"); \
373 assemble_name (FILE, LABEL2); \
374 } while (0)
375 #endif
377 #ifndef ASM_OUTPUT_DWARF_DELTA
378 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
379 do { fprintf ((FILE), "%s", UNALIGNED_OFFSET_ASM_OP); \
380 assemble_name (FILE, LABEL1); \
381 fprintf (FILE, "-"); \
382 assemble_name (FILE, LABEL2); \
383 } while (0)
384 #endif
386 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
387 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
388 do { fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
389 assemble_name (FILE, LABEL1); \
390 fprintf (FILE, "-"); \
391 assemble_name (FILE, LABEL2); \
392 } while (0)
393 #endif
395 #ifndef ASM_OUTPUT_DWARF_ADDR
396 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
397 do { fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
398 assemble_name (FILE, LABEL); \
399 } while (0)
400 #endif
402 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
403 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
404 do { \
405 fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
406 output_addr_const ((FILE), (RTX)); \
407 } while (0)
408 #endif
410 #ifndef ASM_OUTPUT_DWARF_OFFSET4
411 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
412 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
413 assemble_name (FILE, LABEL); \
414 } while (0)
415 #endif
417 #ifndef ASM_OUTPUT_DWARF_OFFSET
418 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
419 do { fprintf ((FILE), "%s", UNALIGNED_OFFSET_ASM_OP); \
420 assemble_name (FILE, LABEL); \
421 } while (0)
422 #endif
424 #ifndef ASM_OUTPUT_DWARF_DATA2
425 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
426 fprintf ((FILE), "%s0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
427 #endif
429 #ifndef ASM_OUTPUT_DWARF_DATA4
430 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
431 fprintf ((FILE), "%s0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
432 #endif
434 #ifndef ASM_OUTPUT_DWARF_DATA8
435 #define ASM_OUTPUT_DWARF_DATA8(FILE,VALUE) \
436 fprintf ((FILE), "%s0x%lx", UNALIGNED_DOUBLE_INT_ASM_OP, \
437 (unsigned long) (VALUE))
438 #endif
440 #ifndef ASM_OUTPUT_DWARF_DATA
441 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
442 fprintf ((FILE), "%s0x%lx", UNALIGNED_OFFSET_ASM_OP, \
443 (unsigned long) (VALUE))
444 #endif
446 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
447 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
448 fprintf ((FILE), "%s0x%lx", UNALIGNED_WORD_ASM_OP, \
449 (unsigned long) (VALUE))
450 #endif
452 #ifndef ASM_OUTPUT_DWARF_CONST_DOUBLE
453 #define ASM_OUTPUT_DWARF_CONST_DOUBLE(FILE,HIGH_VALUE,LOW_VALUE) \
454 do { \
455 if (WORDS_BIG_ENDIAN) \
457 fprintf ((FILE), "%s0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
458 fprintf ((FILE), "%s0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
460 else \
462 fprintf ((FILE), "%s0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
463 fprintf ((FILE), "%s0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
465 } while (0)
466 #endif
468 #else /* UNALIGNED_INT_ASM_OP */
470 /* We don't have unaligned support, let's hope the normal output works for
471 .debug_frame. But we know it won't work for .debug_info. */
473 #ifdef DWARF2_DEBUGGING_INFO
474 #error DWARF2_DEBUGGING_INFO requires UNALIGNED_INT_ASM_OP.
475 #endif
477 #ifndef ASM_OUTPUT_DWARF_ADDR
478 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
479 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), DWARF2_ADDR_SIZE, 1)
480 #endif
482 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
483 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) ASM_OUTPUT_DWARF_ADDR (FILE,RTX)
484 #endif
486 #ifndef ASM_OUTPUT_DWARF_OFFSET4
487 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
488 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
489 #endif
491 #ifndef ASM_OUTPUT_DWARF_OFFSET
492 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
493 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
494 #endif
496 #ifndef ASM_OUTPUT_DWARF_DELTA2
497 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
498 assemble_integer (gen_rtx_MINUS (HImode, \
499 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
500 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
501 2, 1)
502 #endif
504 #ifndef ASM_OUTPUT_DWARF_DELTA4
505 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
506 assemble_integer (gen_rtx_MINUS (SImode, \
507 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
508 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
509 4, 1)
510 #endif
512 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
513 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
514 assemble_integer (gen_rtx_MINUS (Pmode, \
515 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
516 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
517 DWARF2_ADDR_SIZE, 1)
518 #endif
520 #ifndef ASM_OUTPUT_DWARF_DELTA
521 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
522 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
523 #endif
525 #ifndef ASM_OUTPUT_DWARF_DATA2
526 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
527 assemble_integer (GEN_INT (VALUE), 2, 1)
528 #endif
530 #ifndef ASM_OUTPUT_DWARF_DATA4
531 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
532 assemble_integer (GEN_INT (VALUE), 4, 1)
533 #endif
535 #endif /* UNALIGNED_INT_ASM_OP */
537 #ifdef SET_ASM_OP
538 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
539 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
540 do { \
541 fprintf (FILE, "%s", SET_ASM_OP); \
542 assemble_name (FILE, SY); \
543 fputc (',', FILE); \
544 assemble_name (FILE, HI); \
545 fputc ('-', FILE); \
546 assemble_name (FILE, LO); \
547 } while (0)
548 #endif
549 #endif /* SET_ASM_OP */
551 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
552 newline is produced. When flag_debug_asm is asserted, we add commentary
553 at the end of the line, so we must avoid output of a newline here. */
554 #ifndef ASM_OUTPUT_DWARF_NSTRING
555 #define ASM_OUTPUT_DWARF_NSTRING(FILE,P,SLEN) \
556 do { \
557 register int slen = (SLEN); \
558 register const char *p = (P); \
559 register int i; \
560 fprintf (FILE, "\t.ascii \""); \
561 for (i = 0; i < slen; i++) \
563 register int c = p[i]; \
564 if (c == '\"' || c == '\\') \
565 putc ('\\', FILE); \
566 if (ISPRINT(c)) \
567 putc (c, FILE); \
568 else \
570 fprintf (FILE, "\\%o", c); \
573 fprintf (FILE, "\\0\""); \
575 while (0)
576 #endif
577 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
578 ASM_OUTPUT_DWARF_NSTRING (FILE, P, strlen (P))
580 /* The DWARF 2 CFA column which tracks the return address. Normally this
581 is the column for PC, or the first column after all of the hard
582 registers. */
583 #ifndef DWARF_FRAME_RETURN_COLUMN
584 #ifdef PC_REGNUM
585 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
586 #else
587 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
588 #endif
589 #endif
591 /* The mapping from gcc register number to DWARF 2 CFA column number. By
592 default, we just provide columns for all registers. */
593 #ifndef DWARF_FRAME_REGNUM
594 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
595 #endif
597 /* Hook used by __throw. */
600 expand_builtin_dwarf_fp_regnum ()
602 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
605 /* The offset from the incoming value of %sp to the top of the stack frame
606 for the current function. */
607 #ifndef INCOMING_FRAME_SP_OFFSET
608 #define INCOMING_FRAME_SP_OFFSET 0
609 #endif
611 /* Return a pointer to a copy of the section string name S with all
612 attributes stripped off, and an asterisk prepended (for assemble_name). */
614 static inline char *
615 stripattributes (s)
616 const char *s;
618 char *stripped = xmalloc (strlen (s) + 2);
619 char *p = stripped;
621 *p++ = '*';
623 while (*s && *s != ',')
624 *p++ = *s++;
626 *p = '\0';
627 return stripped;
630 /* Generate code to initialize the register size table. */
632 void
633 expand_builtin_init_dwarf_reg_sizes (address)
634 tree address;
636 int i;
637 enum machine_mode mode = TYPE_MODE (char_type_node);
638 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
639 rtx mem = gen_rtx_MEM (mode, addr);
641 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
643 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
644 int size = GET_MODE_SIZE (reg_raw_mode[i]);
646 if (offset < 0)
647 continue;
649 emit_move_insn (change_address (mem, mode,
650 plus_constant (addr, offset)),
651 GEN_INT (size));
655 /* Convert a DWARF call frame info. operation to its string name */
657 static const char *
658 dwarf_cfi_name (cfi_opc)
659 register unsigned cfi_opc;
661 switch (cfi_opc)
663 case DW_CFA_advance_loc:
664 return "DW_CFA_advance_loc";
665 case DW_CFA_offset:
666 return "DW_CFA_offset";
667 case DW_CFA_restore:
668 return "DW_CFA_restore";
669 case DW_CFA_nop:
670 return "DW_CFA_nop";
671 case DW_CFA_set_loc:
672 return "DW_CFA_set_loc";
673 case DW_CFA_advance_loc1:
674 return "DW_CFA_advance_loc1";
675 case DW_CFA_advance_loc2:
676 return "DW_CFA_advance_loc2";
677 case DW_CFA_advance_loc4:
678 return "DW_CFA_advance_loc4";
679 case DW_CFA_offset_extended:
680 return "DW_CFA_offset_extended";
681 case DW_CFA_restore_extended:
682 return "DW_CFA_restore_extended";
683 case DW_CFA_undefined:
684 return "DW_CFA_undefined";
685 case DW_CFA_same_value:
686 return "DW_CFA_same_value";
687 case DW_CFA_register:
688 return "DW_CFA_register";
689 case DW_CFA_remember_state:
690 return "DW_CFA_remember_state";
691 case DW_CFA_restore_state:
692 return "DW_CFA_restore_state";
693 case DW_CFA_def_cfa:
694 return "DW_CFA_def_cfa";
695 case DW_CFA_def_cfa_register:
696 return "DW_CFA_def_cfa_register";
697 case DW_CFA_def_cfa_offset:
698 return "DW_CFA_def_cfa_offset";
699 case DW_CFA_def_cfa_expression:
700 return "DW_CFA_def_cfa_expression";
702 /* SGI/MIPS specific */
703 case DW_CFA_MIPS_advance_loc8:
704 return "DW_CFA_MIPS_advance_loc8";
706 /* GNU extensions */
707 case DW_CFA_GNU_window_save:
708 return "DW_CFA_GNU_window_save";
709 case DW_CFA_GNU_args_size:
710 return "DW_CFA_GNU_args_size";
711 case DW_CFA_GNU_negative_offset_extended:
712 return "DW_CFA_GNU_negative_offset_extended";
714 default:
715 return "DW_CFA_<unknown>";
719 /* Return a pointer to a newly allocated Call Frame Instruction. */
721 static inline dw_cfi_ref
722 new_cfi ()
724 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
726 cfi->dw_cfi_next = NULL;
727 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
728 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
730 return cfi;
733 /* Add a Call Frame Instruction to list of instructions. */
735 static inline void
736 add_cfi (list_head, cfi)
737 register dw_cfi_ref *list_head;
738 register dw_cfi_ref cfi;
740 register dw_cfi_ref *p;
742 /* Find the end of the chain. */
743 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
746 *p = cfi;
749 /* Generate a new label for the CFI info to refer to. */
751 char *
752 dwarf2out_cfi_label ()
754 static char label[20];
755 static unsigned long label_num = 0;
757 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
758 ASM_OUTPUT_LABEL (asm_out_file, label);
760 return label;
763 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
764 or to the CIE if LABEL is NULL. */
766 static void
767 add_fde_cfi (label, cfi)
768 register const char *label;
769 register dw_cfi_ref cfi;
771 if (label)
773 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
775 if (*label == 0)
776 label = dwarf2out_cfi_label ();
778 if (fde->dw_fde_current_label == NULL
779 || strcmp (label, fde->dw_fde_current_label) != 0)
781 register dw_cfi_ref xcfi;
783 fde->dw_fde_current_label = label = xstrdup (label);
785 /* Set the location counter to the new label. */
786 xcfi = new_cfi ();
787 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
788 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
789 add_cfi (&fde->dw_fde_cfi, xcfi);
792 add_cfi (&fde->dw_fde_cfi, cfi);
795 else
796 add_cfi (&cie_cfi_head, cfi);
799 /* Subroutine of lookup_cfa. */
801 static inline void
802 lookup_cfa_1 (cfi, loc)
803 register dw_cfi_ref cfi;
804 register dw_cfa_location *loc;
806 switch (cfi->dw_cfi_opc)
808 case DW_CFA_def_cfa_offset:
809 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
810 break;
811 case DW_CFA_def_cfa_register:
812 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
813 break;
814 case DW_CFA_def_cfa:
815 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
816 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
817 break;
818 case DW_CFA_def_cfa_expression:
819 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
820 break;
821 default:
822 break;
826 /* Find the previous value for the CFA. */
828 static void
829 lookup_cfa (loc)
830 register dw_cfa_location *loc;
832 register dw_cfi_ref cfi;
834 loc->reg = (unsigned long) -1;
835 loc->offset = 0;
836 loc->indirect = 0;
837 loc->base_offset = 0;
839 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
840 lookup_cfa_1 (cfi, loc);
842 if (fde_table_in_use)
844 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
845 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
846 lookup_cfa_1 (cfi, loc);
850 /* The current rule for calculating the DWARF2 canonical frame address. */
851 dw_cfa_location cfa;
853 /* The register used for saving registers to the stack, and its offset
854 from the CFA. */
855 dw_cfa_location cfa_store;
857 /* The running total of the size of arguments pushed onto the stack. */
858 static long args_size;
860 /* The last args_size we actually output. */
861 static long old_args_size;
863 /* Entry point to update the canonical frame address (CFA).
864 LABEL is passed to add_fde_cfi. The value of CFA is now to be
865 calculated from REG+OFFSET. */
867 void
868 dwarf2out_def_cfa (label, reg, offset)
869 register const char *label;
870 unsigned reg;
871 long offset;
873 dw_cfa_location loc;
874 loc.indirect = 0;
875 loc.base_offset = 0;
876 loc.reg = reg;
877 loc.offset = offset;
878 def_cfa_1 (label, &loc);
881 /* This routine does the actual work. The CFA is now calculated from
882 the dw_cfa_location structure. */
883 static void
884 def_cfa_1 (label, loc_p)
885 register const char *label;
886 dw_cfa_location *loc_p;
888 register dw_cfi_ref cfi;
889 dw_cfa_location old_cfa, loc;
891 cfa = *loc_p;
892 loc = *loc_p;
894 if (cfa_store.reg == loc.reg && loc.indirect == 0)
895 cfa_store.offset = loc.offset;
897 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
898 lookup_cfa (&old_cfa);
900 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
901 loc.indirect == old_cfa.indirect)
903 if (loc.indirect == 0
904 || loc.base_offset == old_cfa.base_offset)
905 /* Nothing changed so no need to issue any call frame
906 instructions. */
907 return;
910 cfi = new_cfi ();
912 if (loc.reg == old_cfa.reg && !loc.indirect)
914 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
915 indicating the CFA register did not change but the offset
916 did. */
917 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
918 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
921 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
922 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
923 && !loc.indirect)
925 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
926 indicating the CFA register has changed to <register> but the
927 offset has not changed. */
928 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
929 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
931 #endif
933 else if (loc.indirect == 0)
935 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
936 indicating the CFA register has changed to <register> with
937 the specified offset. */
938 cfi->dw_cfi_opc = DW_CFA_def_cfa;
939 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
940 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
942 else
944 /* Construct a DW_CFA_def_cfa_expression instruction to
945 calculate the CFA using a full location expression since no
946 register-offset pair is available. */
947 struct dw_loc_descr_struct *loc_list;
948 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
949 loc_list = build_cfa_loc (&loc);
950 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
953 add_fde_cfi (label, cfi);
956 /* Add the CFI for saving a register. REG is the CFA column number.
957 LABEL is passed to add_fde_cfi.
958 If SREG is -1, the register is saved at OFFSET from the CFA;
959 otherwise it is saved in SREG. */
961 static void
962 reg_save (label, reg, sreg, offset)
963 register const char *label;
964 register unsigned reg;
965 register unsigned sreg;
966 register long offset;
968 register dw_cfi_ref cfi = new_cfi ();
970 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
972 /* The following comparison is correct. -1 is used to indicate that
973 the value isn't a register number. */
974 if (sreg == (unsigned int) -1)
976 if (reg & ~0x3f)
977 /* The register number won't fit in 6 bits, so we have to use
978 the long form. */
979 cfi->dw_cfi_opc = DW_CFA_offset_extended;
980 else
981 cfi->dw_cfi_opc = DW_CFA_offset;
983 #ifdef ENABLE_CHECKING
985 /* If we get an offset that is not a multiple of
986 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
987 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
988 description. */
989 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
991 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
992 abort ();
994 #endif
995 offset /= DWARF_CIE_DATA_ALIGNMENT;
996 if (offset < 0)
998 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
999 offset = -offset;
1001 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1003 else if (sreg == reg)
1004 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
1005 return;
1006 else
1008 cfi->dw_cfi_opc = DW_CFA_register;
1009 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1012 add_fde_cfi (label, cfi);
1015 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1016 This CFI tells the unwinder that it needs to restore the window registers
1017 from the previous frame's window save area.
1019 ??? Perhaps we should note in the CIE where windows are saved (instead of
1020 assuming 0(cfa)) and what registers are in the window. */
1022 void
1023 dwarf2out_window_save (label)
1024 register const char *label;
1026 register dw_cfi_ref cfi = new_cfi ();
1027 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1028 add_fde_cfi (label, cfi);
1031 /* Add a CFI to update the running total of the size of arguments
1032 pushed onto the stack. */
1034 void
1035 dwarf2out_args_size (label, size)
1036 const char *label;
1037 long size;
1039 register dw_cfi_ref cfi;
1041 if (size == old_args_size)
1042 return;
1043 old_args_size = size;
1045 cfi = new_cfi ();
1046 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1047 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1048 add_fde_cfi (label, cfi);
1051 /* Entry point for saving a register to the stack. REG is the GCC register
1052 number. LABEL and OFFSET are passed to reg_save. */
1054 void
1055 dwarf2out_reg_save (label, reg, offset)
1056 register const char *label;
1057 register unsigned reg;
1058 register long offset;
1060 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
1063 /* Entry point for saving the return address in the stack.
1064 LABEL and OFFSET are passed to reg_save. */
1066 void
1067 dwarf2out_return_save (label, offset)
1068 register const char *label;
1069 register long offset;
1071 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
1074 /* Entry point for saving the return address in a register.
1075 LABEL and SREG are passed to reg_save. */
1077 void
1078 dwarf2out_return_reg (label, sreg)
1079 register const char *label;
1080 register unsigned sreg;
1082 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
1085 /* Record the initial position of the return address. RTL is
1086 INCOMING_RETURN_ADDR_RTX. */
1088 static void
1089 initial_return_save (rtl)
1090 register rtx rtl;
1092 unsigned int reg = (unsigned int) -1;
1093 long offset = 0;
1095 switch (GET_CODE (rtl))
1097 case REG:
1098 /* RA is in a register. */
1099 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1100 break;
1101 case MEM:
1102 /* RA is on the stack. */
1103 rtl = XEXP (rtl, 0);
1104 switch (GET_CODE (rtl))
1106 case REG:
1107 if (REGNO (rtl) != STACK_POINTER_REGNUM)
1108 abort ();
1109 offset = 0;
1110 break;
1111 case PLUS:
1112 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1113 abort ();
1114 offset = INTVAL (XEXP (rtl, 1));
1115 break;
1116 case MINUS:
1117 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1118 abort ();
1119 offset = -INTVAL (XEXP (rtl, 1));
1120 break;
1121 default:
1122 abort ();
1124 break;
1125 case PLUS:
1126 /* The return address is at some offset from any value we can
1127 actually load. For instance, on the SPARC it is in %i7+8. Just
1128 ignore the offset for now; it doesn't matter for unwinding frames. */
1129 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
1130 abort ();
1131 initial_return_save (XEXP (rtl, 0));
1132 return;
1133 default:
1134 abort ();
1137 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1140 /* Given a SET, calculate the amount of stack adjustment it
1141 contains. */
1143 static long
1144 stack_adjust_offset (pattern)
1145 rtx pattern;
1147 rtx src = SET_SRC (pattern);
1148 rtx dest = SET_DEST (pattern);
1149 long offset = 0;
1150 enum rtx_code code;
1152 if (dest == stack_pointer_rtx)
1154 /* (set (reg sp) (plus (reg sp) (const_int))) */
1155 code = GET_CODE (src);
1156 if (! (code == PLUS || code == MINUS)
1157 || XEXP (src, 0) != stack_pointer_rtx
1158 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1159 return 0;
1161 offset = INTVAL (XEXP (src, 1));
1163 else if (GET_CODE (dest) == MEM)
1165 /* (set (mem (pre_dec (reg sp))) (foo)) */
1166 src = XEXP (dest, 0);
1167 code = GET_CODE (src);
1169 if (! (code == PRE_DEC || code == PRE_INC
1170 || code == PRE_MODIFY)
1171 || XEXP (src, 0) != stack_pointer_rtx)
1172 return 0;
1174 if (code == PRE_MODIFY)
1176 rtx val = XEXP (XEXP (src, 1), 1);
1177 /* We handle only adjustments by constant amount. */
1178 if (GET_CODE (XEXP (src, 1)) != PLUS ||
1179 GET_CODE (val) != CONST_INT)
1180 abort();
1181 offset = -INTVAL (val);
1183 else offset = GET_MODE_SIZE (GET_MODE (dest));
1185 else
1186 return 0;
1188 if (code == PLUS || code == PRE_INC)
1189 offset = -offset;
1191 return offset;
1194 /* Check INSN to see if it looks like a push or a stack adjustment, and
1195 make a note of it if it does. EH uses this information to find out how
1196 much extra space it needs to pop off the stack. */
1198 static void
1199 dwarf2out_stack_adjust (insn)
1200 rtx insn;
1202 long offset;
1203 const char *label;
1205 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1207 /* Extract the size of the args from the CALL rtx itself. */
1209 insn = PATTERN (insn);
1210 if (GET_CODE (insn) == PARALLEL)
1211 insn = XVECEXP (insn, 0, 0);
1212 if (GET_CODE (insn) == SET)
1213 insn = SET_SRC (insn);
1214 if (GET_CODE (insn) != CALL)
1215 abort ();
1216 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1217 return;
1220 /* If only calls can throw, and we have a frame pointer,
1221 save up adjustments until we see the CALL_INSN. */
1222 else if (! asynchronous_exceptions
1223 && cfa.reg != STACK_POINTER_REGNUM)
1224 return;
1226 if (GET_CODE (insn) == BARRIER)
1228 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1229 the compiler will have already emitted a stack adjustment, but
1230 doesn't bother for calls to noreturn functions. */
1231 #ifdef STACK_GROWS_DOWNWARD
1232 offset = -args_size;
1233 #else
1234 offset = args_size;
1235 #endif
1237 else if (GET_CODE (PATTERN (insn)) == SET)
1239 offset = stack_adjust_offset (PATTERN (insn));
1241 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1242 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1244 /* There may be stack adjustments inside compound insns. Search
1245 for them. */
1246 int j;
1248 offset = 0;
1249 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1251 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1252 if (GET_CODE (pattern) == SET)
1253 offset += stack_adjust_offset (pattern);
1256 else
1257 return;
1259 if (offset == 0)
1260 return;
1262 if (cfa.reg == STACK_POINTER_REGNUM)
1263 cfa.offset += offset;
1265 #ifndef STACK_GROWS_DOWNWARD
1266 offset = -offset;
1267 #endif
1268 args_size += offset;
1269 if (args_size < 0)
1270 args_size = 0;
1272 label = dwarf2out_cfi_label ();
1273 def_cfa_1 (label, &cfa);
1274 dwarf2out_args_size (label, args_size);
1277 /* A temporary register holding an integral value used in adjusting SP
1278 or setting up the store_reg. The "offset" field holds the integer
1279 value, not an offset. */
1280 dw_cfa_location cfa_temp;
1282 /* Record call frame debugging information for an expression EXPR,
1283 which either sets SP or FP (adjusting how we calculate the frame
1284 address) or saves a register to the stack. LABEL indicates the
1285 address of EXPR.
1287 This function encodes a state machine mapping rtxes to actions on
1288 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1289 users need not read the source code.
1291 The High-Level Picture
1293 Changes in the register we use to calculate the CFA: Currently we
1294 assume that if you copy the CFA register into another register, we
1295 should take the other one as the new CFA register; this seems to
1296 work pretty well. If it's wrong for some target, it's simple
1297 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1299 Changes in the register we use for saving registers to the stack:
1300 This is usually SP, but not always. Again, we deduce that if you
1301 copy SP into another register (and SP is not the CFA register),
1302 then the new register is the one we will be using for register
1303 saves. This also seems to work.
1305 Register saves: There's not much guesswork about this one; if
1306 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1307 register save, and the register used to calculate the destination
1308 had better be the one we think we're using for this purpose.
1310 Except: If the register being saved is the CFA register, and the
1311 offset is non-zero, we are saving the CFA, so we assume we have to
1312 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1313 the intent is to save the value of SP from the previous frame.
1315 Invariants / Summaries of Rules
1317 cfa current rule for calculating the CFA. It usually
1318 consists of a register and an offset.
1319 cfa_store register used by prologue code to save things to the stack
1320 cfa_store.offset is the offset from the value of
1321 cfa_store.reg to the actual CFA
1322 cfa_temp register holding an integral value. cfa_temp.offset
1323 stores the value, which will be used to adjust the
1324 stack pointer.
1326 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1327 with cfa.reg as the first operand changes the cfa.reg and its
1328 cfa.offset.
1330 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1331 expression yielding a constant. This sets cfa_temp.reg
1332 and cfa_temp.offset.
1334 Rule 5: Create a new register cfa_store used to save items to the
1335 stack.
1337 Rules 10-13: Save a register to the stack. Define offset as the
1338 difference of the original location and cfa_store's
1339 location.
1341 The Rules
1343 "{a,b}" indicates a choice of a xor b.
1344 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1346 Rule 1:
1347 (set <reg1> <reg2>:cfa.reg)
1348 effects: cfa.reg = <REG1>
1349 cfa.offset unchanged
1351 Rule 2:
1352 (set sp ({minus,plus} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
1353 effects: cfa.reg = sp if fp used
1354 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1355 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1356 if cfa_store.reg==sp
1358 Rule 3:
1359 (set fp ({minus,plus} <reg>:cfa.reg <const_int>))
1360 effects: cfa.reg = fp
1361 cfa_offset += +/- <const_int>
1363 Rule 4:
1364 (set <reg1> (plus <reg2>:cfa.reg <const_int>))
1365 constraints: <reg1> != fp
1366 <reg1> != sp
1367 effects: cfa.reg = <reg1>
1369 Rule 5:
1370 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1371 constraints: <reg1> != fp
1372 <reg1> != sp
1373 effects: cfa_store.reg = <reg1>
1374 cfa_store.offset = cfa.offset - cfa_temp.offset
1376 Rule 6:
1377 (set <reg> <const_int>)
1378 effects: cfa_temp.reg = <reg>
1379 cfa_temp.offset = <const_int>
1381 Rule 7:
1382 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1383 effects: cfa_temp.reg = <reg1>
1384 cfa_temp.offset |= <const_int>
1386 Rule 8:
1387 (set <reg> (high <exp>))
1388 effects: none
1390 Rule 9:
1391 (set <reg> (lo_sum <exp> <const_int>))
1392 effects: cfa_temp.reg = <reg>
1393 cfa_temp.offset = <const_int>
1395 Rule 10:
1396 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1397 effects: cfa_store.offset -= <const_int>
1398 cfa.offset = cfa_store.offset if cfa.reg == sp
1399 offset = -cfa_store.offset
1400 cfa.reg = sp
1401 cfa.base_offset = offset
1403 Rule 11:
1404 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1405 effects: cfa_store.offset += -/+ mode_size(mem)
1406 cfa.offset = cfa_store.offset if cfa.reg == sp
1407 offset = -cfa_store.offset
1408 cfa.reg = sp
1409 cfa.base_offset = offset
1411 Rule 12:
1412 (set (mem ({minus,plus} <reg1>:cfa_store <const_int>)) <reg2>)
1413 effects: cfa_store.offset += -/+ <const_int>
1414 offset = -cfa_store.offset
1415 cfa.reg = <reg1
1416 cfa.base_offset = offset
1418 Rule 13:
1419 (set (mem <reg1>:cfa_store) <reg2>)
1420 effects: offset = -cfa_store.offset
1421 cfa.reg = <reg1>
1422 cfa.base_offset = offset */
1424 static void
1425 dwarf2out_frame_debug_expr (expr, label)
1426 rtx expr;
1427 const char *label;
1429 rtx src, dest;
1430 long offset;
1432 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1433 the PARALLEL independently. The first element is always processed if
1434 it is a SET. This is for backward compatibility. Other elements
1435 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1436 flag is set in them. */
1438 if (GET_CODE (expr) == PARALLEL
1439 || GET_CODE (expr) == SEQUENCE)
1441 int par_index;
1442 int limit = XVECLEN (expr, 0);
1444 for (par_index = 0; par_index < limit; par_index++)
1446 rtx x = XVECEXP (expr, 0, par_index);
1448 if (GET_CODE (x) == SET &&
1449 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1450 dwarf2out_frame_debug_expr (x, label);
1452 return;
1455 if (GET_CODE (expr) != SET)
1456 abort ();
1458 src = SET_SRC (expr);
1459 dest = SET_DEST (expr);
1461 switch (GET_CODE (dest))
1463 case REG:
1464 /* Rule 1 */
1465 /* Update the CFA rule wrt SP or FP. Make sure src is
1466 relative to the current CFA register. */
1467 switch (GET_CODE (src))
1469 /* Setting FP from SP. */
1470 case REG:
1471 if (cfa.reg == (unsigned) REGNO (src))
1472 /* OK. */
1474 else
1475 abort ();
1477 /* We used to require that dest be either SP or FP, but the
1478 ARM copies SP to a temporary register, and from there to
1479 FP. So we just rely on the backends to only set
1480 RTX_FRAME_RELATED_P on appropriate insns. */
1481 cfa.reg = REGNO (dest);
1482 break;
1484 case PLUS:
1485 case MINUS:
1486 if (dest == stack_pointer_rtx)
1488 /* Rule 2 */
1489 /* Adjusting SP. */
1490 switch (GET_CODE (XEXP (src, 1)))
1492 case CONST_INT:
1493 offset = INTVAL (XEXP (src, 1));
1494 break;
1495 case REG:
1496 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1497 abort ();
1498 offset = cfa_temp.offset;
1499 break;
1500 default:
1501 abort ();
1504 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1506 /* Restoring SP from FP in the epilogue. */
1507 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1508 abort ();
1509 cfa.reg = STACK_POINTER_REGNUM;
1511 else if (XEXP (src, 0) != stack_pointer_rtx)
1512 abort ();
1514 if (GET_CODE (src) == PLUS)
1515 offset = -offset;
1516 if (cfa.reg == STACK_POINTER_REGNUM)
1517 cfa.offset += offset;
1518 if (cfa_store.reg == STACK_POINTER_REGNUM)
1519 cfa_store.offset += offset;
1521 else if (dest == hard_frame_pointer_rtx)
1523 /* Rule 3 */
1524 /* Either setting the FP from an offset of the SP,
1525 or adjusting the FP */
1526 if (! frame_pointer_needed)
1527 abort ();
1529 if (GET_CODE (XEXP (src, 0)) == REG
1530 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1531 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1533 offset = INTVAL (XEXP (src, 1));
1534 if (GET_CODE (src) == PLUS)
1535 offset = -offset;
1536 cfa.offset += offset;
1537 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1539 else
1540 abort ();
1542 else
1544 if (GET_CODE (src) != PLUS)
1545 abort ();
1547 /* Rule 4 */
1548 if (GET_CODE (XEXP (src, 0)) == REG
1549 && REGNO (XEXP (src, 0)) == cfa.reg
1550 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1552 /* Setting a temporary CFA register that will be copied
1553 into the FP later on. */
1554 offset = INTVAL (XEXP (src, 1));
1555 if (GET_CODE (src) == PLUS)
1556 offset = -offset;
1557 cfa.offset += offset;
1558 cfa.reg = REGNO (dest);
1560 /* Rule 5 */
1561 else
1563 /* Setting a scratch register that we will use instead
1564 of SP for saving registers to the stack. */
1565 if (XEXP (src, 1) != stack_pointer_rtx)
1566 abort ();
1567 if (GET_CODE (XEXP (src, 0)) != REG
1568 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg)
1569 abort ();
1570 if (cfa.reg != STACK_POINTER_REGNUM)
1571 abort ();
1572 cfa_store.reg = REGNO (dest);
1573 cfa_store.offset = cfa.offset - cfa_temp.offset;
1576 break;
1578 /* Rule 6 */
1579 case CONST_INT:
1580 cfa_temp.reg = REGNO (dest);
1581 cfa_temp.offset = INTVAL (src);
1582 break;
1584 /* Rule 7 */
1585 case IOR:
1586 if (GET_CODE (XEXP (src, 0)) != REG
1587 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1588 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1589 abort ();
1590 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1591 cfa_temp.reg = REGNO (dest);
1592 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1593 break;
1595 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1596 which will fill in all of the bits. */
1597 /* Rule 8 */
1598 case HIGH:
1599 break;
1601 /* Rule 9 */
1602 case LO_SUM:
1603 if (GET_CODE (XEXP (src, 1)) != CONST_INT)
1604 abort ();
1605 cfa_temp.reg = REGNO (dest);
1606 cfa_temp.offset = INTVAL (XEXP (src, 1));
1607 break;
1609 default:
1610 abort ();
1612 def_cfa_1 (label, &cfa);
1613 break;
1615 case MEM:
1616 if (GET_CODE (src) != REG)
1617 abort ();
1619 /* Saving a register to the stack. Make sure dest is relative to the
1620 CFA register. */
1621 switch (GET_CODE (XEXP (dest, 0)))
1623 /* Rule 10 */
1624 /* With a push. */
1625 case PRE_MODIFY:
1626 /* We can't handle variable size modifications. */
1627 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1628 abort();
1629 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1631 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1632 || cfa_store.reg != STACK_POINTER_REGNUM)
1633 abort ();
1634 cfa_store.offset += offset;
1635 if (cfa.reg == STACK_POINTER_REGNUM)
1636 cfa.offset = cfa_store.offset;
1638 offset = -cfa_store.offset;
1639 break;
1640 /* Rule 11 */
1641 case PRE_INC:
1642 case PRE_DEC:
1643 offset = GET_MODE_SIZE (GET_MODE (dest));
1644 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1645 offset = -offset;
1647 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1648 || cfa_store.reg != STACK_POINTER_REGNUM)
1649 abort ();
1650 cfa_store.offset += offset;
1651 if (cfa.reg == STACK_POINTER_REGNUM)
1652 cfa.offset = cfa_store.offset;
1654 offset = -cfa_store.offset;
1655 break;
1657 /* Rule 12 */
1658 /* With an offset. */
1659 case PLUS:
1660 case MINUS:
1661 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1662 abort ();
1663 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1664 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1665 offset = -offset;
1667 if (cfa_store.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1668 abort ();
1669 offset -= cfa_store.offset;
1670 break;
1672 /* Rule 13 */
1673 /* Without an offset. */
1674 case REG:
1675 if (cfa_store.reg != (unsigned) REGNO (XEXP (dest, 0)))
1676 abort ();
1677 offset = -cfa_store.offset;
1678 break;
1680 default:
1681 abort ();
1684 if (REGNO (src) != STACK_POINTER_REGNUM
1685 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1686 && (unsigned) REGNO (src) == cfa.reg)
1688 /* We're storing the current CFA reg into the stack. */
1690 if (cfa.offset == 0)
1692 /* If the source register is exactly the CFA, assume
1693 we're saving SP like any other register; this happens
1694 on the ARM. */
1696 def_cfa_1 (label, &cfa);
1697 dwarf2out_reg_save (label, STACK_POINTER_REGNUM, offset);
1698 break;
1700 else
1702 /* Otherwise, we'll need to look in the stack to
1703 calculate the CFA. */
1705 rtx x = XEXP (dest, 0);
1706 if (GET_CODE (x) != REG)
1707 x = XEXP (x, 0);
1708 if (GET_CODE (x) != REG)
1709 abort ();
1710 cfa.reg = (unsigned) REGNO (x);
1711 cfa.base_offset = offset;
1712 cfa.indirect = 1;
1713 def_cfa_1 (label, &cfa);
1714 break;
1718 def_cfa_1 (label, &cfa);
1719 dwarf2out_reg_save (label, REGNO (src), offset);
1720 break;
1722 default:
1723 abort ();
1727 /* Record call frame debugging information for INSN, which either
1728 sets SP or FP (adjusting how we calculate the frame address) or saves a
1729 register to the stack. If INSN is NULL_RTX, initialize our state. */
1731 void
1732 dwarf2out_frame_debug (insn)
1733 rtx insn;
1735 const char *label;
1736 rtx src;
1738 if (insn == NULL_RTX)
1740 /* Set up state for generating call frame debug info. */
1741 lookup_cfa (&cfa);
1742 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1743 abort ();
1744 cfa.reg = STACK_POINTER_REGNUM;
1745 cfa_store = cfa;
1746 cfa_temp.reg = -1;
1747 cfa_temp.offset = 0;
1748 return;
1751 if (! RTX_FRAME_RELATED_P (insn))
1753 dwarf2out_stack_adjust (insn);
1754 return;
1757 label = dwarf2out_cfi_label ();
1759 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1760 if (src)
1761 insn = XEXP (src, 0);
1762 else
1763 insn = PATTERN (insn);
1765 dwarf2out_frame_debug_expr (insn, label);
1768 /* Return the size of an unsigned LEB128 quantity. */
1770 static inline unsigned long
1771 size_of_uleb128 (value)
1772 register unsigned long value;
1774 register unsigned long size = 0;
1775 register unsigned byte;
1779 byte = (value & 0x7f);
1780 value >>= 7;
1781 size += 1;
1783 while (value != 0);
1785 return size;
1788 /* Return the size of a signed LEB128 quantity. */
1790 static inline unsigned long
1791 size_of_sleb128 (value)
1792 register long value;
1794 register unsigned long size = 0;
1795 register unsigned byte;
1799 byte = (value & 0x7f);
1800 value >>= 7;
1801 size += 1;
1803 while (!(((value == 0) && ((byte & 0x40) == 0))
1804 || ((value == -1) && ((byte & 0x40) != 0))));
1806 return size;
1809 /* Output an unsigned LEB128 quantity. */
1811 static void
1812 output_uleb128 (value)
1813 register unsigned long value;
1815 unsigned long save_value = value;
1817 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1820 register unsigned byte = (value & 0x7f);
1821 value >>= 7;
1822 if (value != 0)
1823 /* More bytes to follow. */
1824 byte |= 0x80;
1826 fprintf (asm_out_file, "0x%x", byte);
1827 if (value != 0)
1828 fprintf (asm_out_file, ",");
1830 while (value != 0);
1832 if (flag_debug_asm)
1833 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1836 /* Output an signed LEB128 quantity. */
1838 static void
1839 output_sleb128 (value)
1840 register long value;
1842 register int more;
1843 register unsigned byte;
1844 long save_value = value;
1846 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1849 byte = (value & 0x7f);
1850 /* arithmetic shift */
1851 value >>= 7;
1852 more = !((((value == 0) && ((byte & 0x40) == 0))
1853 || ((value == -1) && ((byte & 0x40) != 0))));
1854 if (more)
1855 byte |= 0x80;
1857 fprintf (asm_out_file, "0x%x", byte);
1858 if (more)
1859 fprintf (asm_out_file, ",");
1862 while (more);
1863 if (flag_debug_asm)
1864 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1867 /* Output a Call Frame Information opcode and its operand(s). */
1869 static void
1870 output_cfi (cfi, fde)
1871 register dw_cfi_ref cfi;
1872 register dw_fde_ref fde;
1874 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1876 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1877 cfi->dw_cfi_opc
1878 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1879 if (flag_debug_asm)
1880 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1881 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1882 fputc ('\n', asm_out_file);
1885 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1887 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1888 cfi->dw_cfi_opc
1889 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1890 if (flag_debug_asm)
1891 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1892 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1894 fputc ('\n', asm_out_file);
1895 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1896 fputc ('\n', asm_out_file);
1898 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1900 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1901 cfi->dw_cfi_opc
1902 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1903 if (flag_debug_asm)
1904 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1905 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1907 fputc ('\n', asm_out_file);
1909 else
1911 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1912 if (flag_debug_asm)
1913 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1914 dwarf_cfi_name (cfi->dw_cfi_opc));
1916 fputc ('\n', asm_out_file);
1917 switch (cfi->dw_cfi_opc)
1919 case DW_CFA_set_loc:
1920 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1921 fputc ('\n', asm_out_file);
1922 break;
1923 case DW_CFA_advance_loc1:
1924 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1925 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1926 fde->dw_fde_current_label);
1927 fputc ('\n', asm_out_file);
1928 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1929 break;
1930 case DW_CFA_advance_loc2:
1931 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1932 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1933 fde->dw_fde_current_label);
1934 fputc ('\n', asm_out_file);
1935 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1936 break;
1937 case DW_CFA_advance_loc4:
1938 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1939 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1940 fde->dw_fde_current_label);
1941 fputc ('\n', asm_out_file);
1942 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1943 break;
1944 #ifdef MIPS_DEBUGGING_INFO
1945 case DW_CFA_MIPS_advance_loc8:
1946 /* TODO: not currently implemented. */
1947 abort ();
1948 break;
1949 #endif
1950 case DW_CFA_offset_extended:
1951 case DW_CFA_GNU_negative_offset_extended:
1952 case DW_CFA_def_cfa:
1953 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1954 fputc ('\n', asm_out_file);
1955 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1956 fputc ('\n', asm_out_file);
1957 break;
1958 case DW_CFA_restore_extended:
1959 case DW_CFA_undefined:
1960 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1961 fputc ('\n', asm_out_file);
1962 break;
1963 case DW_CFA_same_value:
1964 case DW_CFA_def_cfa_register:
1965 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1966 fputc ('\n', asm_out_file);
1967 break;
1968 case DW_CFA_register:
1969 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1970 fputc ('\n', asm_out_file);
1971 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1972 fputc ('\n', asm_out_file);
1973 break;
1974 case DW_CFA_def_cfa_offset:
1975 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1976 fputc ('\n', asm_out_file);
1977 break;
1978 case DW_CFA_GNU_window_save:
1979 break;
1980 case DW_CFA_GNU_args_size:
1981 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1982 fputc ('\n', asm_out_file);
1983 break;
1984 case DW_CFA_def_cfa_expression:
1985 output_cfa_loc (cfi);
1986 break;
1987 default:
1988 break;
1993 /* Output the call frame information used to used to record information
1994 that relates to calculating the frame pointer, and records the
1995 location of saved registers. */
1997 static void
1998 output_call_frame_info (for_eh)
1999 int for_eh;
2001 register unsigned long i;
2002 register dw_fde_ref fde;
2003 register dw_cfi_ref cfi;
2004 char l1[20], l2[20];
2005 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2006 char ld[20];
2007 #endif
2009 /* Do we want to include a pointer to the exception table? */
2010 int eh_ptr = for_eh && exception_table_p ();
2012 /* If we don't have any functions we'll want to unwind out of, don't
2013 emit any EH unwind information. */
2014 if (for_eh)
2016 for (i = 0; i < fde_table_in_use; ++i)
2017 if (! fde_table[i].nothrow)
2018 goto found;
2019 return;
2020 found:;
2023 fputc ('\n', asm_out_file);
2025 /* We're going to be generating comments, so turn on app. */
2026 if (flag_debug_asm)
2027 app_enable ();
2029 if (for_eh)
2031 #ifdef EH_FRAME_SECTION
2032 EH_FRAME_SECTION ();
2033 #else
2034 tree label = get_file_function_name ('F');
2036 force_data_section ();
2037 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
2038 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2039 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2040 #endif
2041 assemble_label ("__FRAME_BEGIN__");
2043 else
2044 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
2046 /* Output the CIE. */
2047 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2048 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2049 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2050 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
2051 if (for_eh)
2052 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
2053 else
2054 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
2055 #else
2056 if (for_eh)
2057 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
2058 else
2059 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
2060 #endif
2061 if (flag_debug_asm)
2062 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
2063 ASM_COMMENT_START);
2065 fputc ('\n', asm_out_file);
2066 ASM_OUTPUT_LABEL (asm_out_file, l1);
2068 if (for_eh)
2069 /* Now that the CIE pointer is PC-relative for EH,
2070 use 0 to identify the CIE. */
2071 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2072 else
2073 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
2075 if (flag_debug_asm)
2076 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
2078 fputc ('\n', asm_out_file);
2079 if (! for_eh && DWARF_OFFSET_SIZE == 8)
2081 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
2082 fputc ('\n', asm_out_file);
2085 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
2086 if (flag_debug_asm)
2087 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
2089 fputc ('\n', asm_out_file);
2090 if (eh_ptr)
2092 /* The CIE contains a pointer to the exception region info for the
2093 frame. Make the augmentation string three bytes (including the
2094 trailing null) so the pointer is 4-byte aligned. The Solaris ld
2095 can't handle unaligned relocs. */
2096 if (flag_debug_asm)
2098 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
2099 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
2101 else
2103 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
2105 fputc ('\n', asm_out_file);
2107 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
2108 if (flag_debug_asm)
2109 fprintf (asm_out_file, "\t%s pointer to exception region info",
2110 ASM_COMMENT_START);
2112 else
2114 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
2115 if (flag_debug_asm)
2116 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
2117 ASM_COMMENT_START);
2120 fputc ('\n', asm_out_file);
2121 output_uleb128 (1);
2122 if (flag_debug_asm)
2123 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
2125 fputc ('\n', asm_out_file);
2126 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
2127 if (flag_debug_asm)
2128 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
2130 fputc ('\n', asm_out_file);
2131 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
2132 if (flag_debug_asm)
2133 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
2135 fputc ('\n', asm_out_file);
2137 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2138 output_cfi (cfi, NULL);
2140 /* Pad the CIE out to an address sized boundary. */
2141 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
2142 ASM_OUTPUT_LABEL (asm_out_file, l2);
2143 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2144 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
2145 if (flag_debug_asm)
2146 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
2147 fputc ('\n', asm_out_file);
2148 #endif
2150 /* Loop through all of the FDE's. */
2151 for (i = 0; i < fde_table_in_use; ++i)
2153 fde = &fde_table[i];
2155 /* Don't emit EH unwind info for leaf functions. */
2156 if (for_eh && fde->nothrow)
2157 continue;
2159 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2160 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2161 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2162 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i * 2);
2163 if (for_eh)
2164 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
2165 else
2166 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
2167 #else
2168 if (for_eh)
2169 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
2170 else
2171 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
2172 #endif
2173 if (flag_debug_asm)
2174 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
2175 fputc ('\n', asm_out_file);
2176 ASM_OUTPUT_LABEL (asm_out_file, l1);
2178 /* ??? This always emits a 4 byte offset when for_eh is true, but it
2179 emits a target dependent sized offset when for_eh is not true.
2180 This inconsistency may confuse gdb. The only case where we need a
2181 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
2182 compatibility if we emit a 4 byte offset. We need a 4 byte offset
2183 though in order to be compatible with the dwarf_fde struct in frame.c.
2184 If the for_eh case is changed, then the struct in frame.c has
2185 to be adjusted appropriately. */
2186 if (for_eh)
2187 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
2188 else
2189 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
2190 if (flag_debug_asm)
2191 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
2193 fputc ('\n', asm_out_file);
2194 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
2195 if (flag_debug_asm)
2196 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
2198 fputc ('\n', asm_out_file);
2199 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
2200 fde->dw_fde_end, fde->dw_fde_begin);
2201 if (flag_debug_asm)
2202 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
2204 fputc ('\n', asm_out_file);
2206 /* Loop through the Call Frame Instructions associated with
2207 this FDE. */
2208 fde->dw_fde_current_label = fde->dw_fde_begin;
2209 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2210 output_cfi (cfi, fde);
2212 /* Pad the FDE out to an address sized boundary. */
2213 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
2214 ASM_OUTPUT_LABEL (asm_out_file, l2);
2215 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2216 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
2217 if (flag_debug_asm)
2218 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
2219 fputc ('\n', asm_out_file);
2220 #endif
2222 #ifndef EH_FRAME_SECTION
2223 if (for_eh)
2225 /* Emit terminating zero for table. */
2226 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2227 fputc ('\n', asm_out_file);
2229 #endif
2230 #ifdef MIPS_DEBUGGING_INFO
2231 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2232 get a value of 0. Putting .align 0 after the label fixes it. */
2233 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2234 #endif
2236 /* Turn off app to make assembly quicker. */
2237 if (flag_debug_asm)
2238 app_disable ();
2241 /* Output a marker (i.e. a label) for the beginning of a function, before
2242 the prologue. */
2244 void
2245 dwarf2out_begin_prologue ()
2247 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2248 register dw_fde_ref fde;
2250 ++current_funcdef_number;
2252 function_section (current_function_decl);
2253 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2254 current_funcdef_number);
2255 ASM_OUTPUT_LABEL (asm_out_file, label);
2256 current_function_func_begin_label = get_identifier (label);
2258 /* Expand the fde table if necessary. */
2259 if (fde_table_in_use == fde_table_allocated)
2261 fde_table_allocated += FDE_TABLE_INCREMENT;
2262 fde_table
2263 = (dw_fde_ref) xrealloc (fde_table,
2264 fde_table_allocated * sizeof (dw_fde_node));
2267 /* Record the FDE associated with this function. */
2268 current_funcdef_fde = fde_table_in_use;
2270 /* Add the new FDE at the end of the fde_table. */
2271 fde = &fde_table[fde_table_in_use++];
2272 fde->dw_fde_begin = xstrdup (label);
2273 fde->dw_fde_current_label = NULL;
2274 fde->dw_fde_end = NULL;
2275 fde->dw_fde_cfi = NULL;
2276 fde->nothrow = current_function_nothrow;
2278 args_size = old_args_size = 0;
2281 /* Output a marker (i.e. a label) for the absolute end of the generated code
2282 for a function definition. This gets called *after* the epilogue code has
2283 been generated. */
2285 void
2286 dwarf2out_end_epilogue ()
2288 dw_fde_ref fde;
2289 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2291 /* Output a label to mark the endpoint of the code generated for this
2292 function. */
2293 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2294 ASM_OUTPUT_LABEL (asm_out_file, label);
2295 fde = &fde_table[fde_table_in_use - 1];
2296 fde->dw_fde_end = xstrdup (label);
2299 void
2300 dwarf2out_frame_init ()
2302 /* Allocate the initial hunk of the fde_table. */
2303 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2304 fde_table_allocated = FDE_TABLE_INCREMENT;
2305 fde_table_in_use = 0;
2307 /* Generate the CFA instructions common to all FDE's. Do it now for the
2308 sake of lookup_cfa. */
2310 #ifdef DWARF2_UNWIND_INFO
2311 /* On entry, the Canonical Frame Address is at SP. */
2312 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2313 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2314 #endif
2317 void
2318 dwarf2out_frame_finish ()
2320 /* Output call frame information. */
2321 #ifdef MIPS_DEBUGGING_INFO
2322 if (write_symbols == DWARF2_DEBUG)
2323 output_call_frame_info (0);
2324 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2325 output_call_frame_info (1);
2326 #else
2327 if (write_symbols == DWARF2_DEBUG
2328 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2329 output_call_frame_info (1);
2330 #endif
2333 /* And now, the subset of the debugging information support code necessary
2334 for emitting location expressions. */
2336 typedef struct dw_val_struct *dw_val_ref;
2337 typedef struct die_struct *dw_die_ref;
2338 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2340 /* Each DIE may have a series of attribute/value pairs. Values
2341 can take on several forms. The forms that are used in this
2342 implementation are listed below. */
2344 typedef enum
2346 dw_val_class_addr,
2347 dw_val_class_loc,
2348 dw_val_class_const,
2349 dw_val_class_unsigned_const,
2350 dw_val_class_long_long,
2351 dw_val_class_float,
2352 dw_val_class_flag,
2353 dw_val_class_die_ref,
2354 dw_val_class_fde_ref,
2355 dw_val_class_lbl_id,
2356 dw_val_class_lbl_offset,
2357 dw_val_class_str
2359 dw_val_class;
2361 /* Describe a double word constant value. */
2362 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2364 typedef struct dw_long_long_struct
2366 unsigned long hi;
2367 unsigned long low;
2369 dw_long_long_const;
2371 /* Describe a floating point constant value. */
2373 typedef struct dw_fp_struct
2375 long *array;
2376 unsigned length;
2378 dw_float_const;
2380 /* The dw_val_node describes an attribute's value, as it is
2381 represented internally. */
2383 typedef struct dw_val_struct
2385 dw_val_class val_class;
2386 union
2388 rtx val_addr;
2389 dw_loc_descr_ref val_loc;
2390 long int val_int;
2391 long unsigned val_unsigned;
2392 dw_long_long_const val_long_long;
2393 dw_float_const val_float;
2394 struct {
2395 dw_die_ref die;
2396 int external;
2397 } val_die_ref;
2398 unsigned val_fde_index;
2399 char *val_str;
2400 char *val_lbl_id;
2401 unsigned char val_flag;
2405 dw_val_node;
2407 /* Locations in memory are described using a sequence of stack machine
2408 operations. */
2410 typedef struct dw_loc_descr_struct
2412 dw_loc_descr_ref dw_loc_next;
2413 enum dwarf_location_atom dw_loc_opc;
2414 dw_val_node dw_loc_oprnd1;
2415 dw_val_node dw_loc_oprnd2;
2416 int dw_loc_addr;
2418 dw_loc_descr_node;
2420 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2421 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2422 unsigned long,
2423 unsigned long));
2424 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2425 dw_loc_descr_ref));
2426 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2427 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2428 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2429 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2431 /* Convert a DWARF stack opcode into its string name. */
2433 static const char *
2434 dwarf_stack_op_name (op)
2435 register unsigned op;
2437 switch (op)
2439 case DW_OP_addr:
2440 return "DW_OP_addr";
2441 case DW_OP_deref:
2442 return "DW_OP_deref";
2443 case DW_OP_const1u:
2444 return "DW_OP_const1u";
2445 case DW_OP_const1s:
2446 return "DW_OP_const1s";
2447 case DW_OP_const2u:
2448 return "DW_OP_const2u";
2449 case DW_OP_const2s:
2450 return "DW_OP_const2s";
2451 case DW_OP_const4u:
2452 return "DW_OP_const4u";
2453 case DW_OP_const4s:
2454 return "DW_OP_const4s";
2455 case DW_OP_const8u:
2456 return "DW_OP_const8u";
2457 case DW_OP_const8s:
2458 return "DW_OP_const8s";
2459 case DW_OP_constu:
2460 return "DW_OP_constu";
2461 case DW_OP_consts:
2462 return "DW_OP_consts";
2463 case DW_OP_dup:
2464 return "DW_OP_dup";
2465 case DW_OP_drop:
2466 return "DW_OP_drop";
2467 case DW_OP_over:
2468 return "DW_OP_over";
2469 case DW_OP_pick:
2470 return "DW_OP_pick";
2471 case DW_OP_swap:
2472 return "DW_OP_swap";
2473 case DW_OP_rot:
2474 return "DW_OP_rot";
2475 case DW_OP_xderef:
2476 return "DW_OP_xderef";
2477 case DW_OP_abs:
2478 return "DW_OP_abs";
2479 case DW_OP_and:
2480 return "DW_OP_and";
2481 case DW_OP_div:
2482 return "DW_OP_div";
2483 case DW_OP_minus:
2484 return "DW_OP_minus";
2485 case DW_OP_mod:
2486 return "DW_OP_mod";
2487 case DW_OP_mul:
2488 return "DW_OP_mul";
2489 case DW_OP_neg:
2490 return "DW_OP_neg";
2491 case DW_OP_not:
2492 return "DW_OP_not";
2493 case DW_OP_or:
2494 return "DW_OP_or";
2495 case DW_OP_plus:
2496 return "DW_OP_plus";
2497 case DW_OP_plus_uconst:
2498 return "DW_OP_plus_uconst";
2499 case DW_OP_shl:
2500 return "DW_OP_shl";
2501 case DW_OP_shr:
2502 return "DW_OP_shr";
2503 case DW_OP_shra:
2504 return "DW_OP_shra";
2505 case DW_OP_xor:
2506 return "DW_OP_xor";
2507 case DW_OP_bra:
2508 return "DW_OP_bra";
2509 case DW_OP_eq:
2510 return "DW_OP_eq";
2511 case DW_OP_ge:
2512 return "DW_OP_ge";
2513 case DW_OP_gt:
2514 return "DW_OP_gt";
2515 case DW_OP_le:
2516 return "DW_OP_le";
2517 case DW_OP_lt:
2518 return "DW_OP_lt";
2519 case DW_OP_ne:
2520 return "DW_OP_ne";
2521 case DW_OP_skip:
2522 return "DW_OP_skip";
2523 case DW_OP_lit0:
2524 return "DW_OP_lit0";
2525 case DW_OP_lit1:
2526 return "DW_OP_lit1";
2527 case DW_OP_lit2:
2528 return "DW_OP_lit2";
2529 case DW_OP_lit3:
2530 return "DW_OP_lit3";
2531 case DW_OP_lit4:
2532 return "DW_OP_lit4";
2533 case DW_OP_lit5:
2534 return "DW_OP_lit5";
2535 case DW_OP_lit6:
2536 return "DW_OP_lit6";
2537 case DW_OP_lit7:
2538 return "DW_OP_lit7";
2539 case DW_OP_lit8:
2540 return "DW_OP_lit8";
2541 case DW_OP_lit9:
2542 return "DW_OP_lit9";
2543 case DW_OP_lit10:
2544 return "DW_OP_lit10";
2545 case DW_OP_lit11:
2546 return "DW_OP_lit11";
2547 case DW_OP_lit12:
2548 return "DW_OP_lit12";
2549 case DW_OP_lit13:
2550 return "DW_OP_lit13";
2551 case DW_OP_lit14:
2552 return "DW_OP_lit14";
2553 case DW_OP_lit15:
2554 return "DW_OP_lit15";
2555 case DW_OP_lit16:
2556 return "DW_OP_lit16";
2557 case DW_OP_lit17:
2558 return "DW_OP_lit17";
2559 case DW_OP_lit18:
2560 return "DW_OP_lit18";
2561 case DW_OP_lit19:
2562 return "DW_OP_lit19";
2563 case DW_OP_lit20:
2564 return "DW_OP_lit20";
2565 case DW_OP_lit21:
2566 return "DW_OP_lit21";
2567 case DW_OP_lit22:
2568 return "DW_OP_lit22";
2569 case DW_OP_lit23:
2570 return "DW_OP_lit23";
2571 case DW_OP_lit24:
2572 return "DW_OP_lit24";
2573 case DW_OP_lit25:
2574 return "DW_OP_lit25";
2575 case DW_OP_lit26:
2576 return "DW_OP_lit26";
2577 case DW_OP_lit27:
2578 return "DW_OP_lit27";
2579 case DW_OP_lit28:
2580 return "DW_OP_lit28";
2581 case DW_OP_lit29:
2582 return "DW_OP_lit29";
2583 case DW_OP_lit30:
2584 return "DW_OP_lit30";
2585 case DW_OP_lit31:
2586 return "DW_OP_lit31";
2587 case DW_OP_reg0:
2588 return "DW_OP_reg0";
2589 case DW_OP_reg1:
2590 return "DW_OP_reg1";
2591 case DW_OP_reg2:
2592 return "DW_OP_reg2";
2593 case DW_OP_reg3:
2594 return "DW_OP_reg3";
2595 case DW_OP_reg4:
2596 return "DW_OP_reg4";
2597 case DW_OP_reg5:
2598 return "DW_OP_reg5";
2599 case DW_OP_reg6:
2600 return "DW_OP_reg6";
2601 case DW_OP_reg7:
2602 return "DW_OP_reg7";
2603 case DW_OP_reg8:
2604 return "DW_OP_reg8";
2605 case DW_OP_reg9:
2606 return "DW_OP_reg9";
2607 case DW_OP_reg10:
2608 return "DW_OP_reg10";
2609 case DW_OP_reg11:
2610 return "DW_OP_reg11";
2611 case DW_OP_reg12:
2612 return "DW_OP_reg12";
2613 case DW_OP_reg13:
2614 return "DW_OP_reg13";
2615 case DW_OP_reg14:
2616 return "DW_OP_reg14";
2617 case DW_OP_reg15:
2618 return "DW_OP_reg15";
2619 case DW_OP_reg16:
2620 return "DW_OP_reg16";
2621 case DW_OP_reg17:
2622 return "DW_OP_reg17";
2623 case DW_OP_reg18:
2624 return "DW_OP_reg18";
2625 case DW_OP_reg19:
2626 return "DW_OP_reg19";
2627 case DW_OP_reg20:
2628 return "DW_OP_reg20";
2629 case DW_OP_reg21:
2630 return "DW_OP_reg21";
2631 case DW_OP_reg22:
2632 return "DW_OP_reg22";
2633 case DW_OP_reg23:
2634 return "DW_OP_reg23";
2635 case DW_OP_reg24:
2636 return "DW_OP_reg24";
2637 case DW_OP_reg25:
2638 return "DW_OP_reg25";
2639 case DW_OP_reg26:
2640 return "DW_OP_reg26";
2641 case DW_OP_reg27:
2642 return "DW_OP_reg27";
2643 case DW_OP_reg28:
2644 return "DW_OP_reg28";
2645 case DW_OP_reg29:
2646 return "DW_OP_reg29";
2647 case DW_OP_reg30:
2648 return "DW_OP_reg30";
2649 case DW_OP_reg31:
2650 return "DW_OP_reg31";
2651 case DW_OP_breg0:
2652 return "DW_OP_breg0";
2653 case DW_OP_breg1:
2654 return "DW_OP_breg1";
2655 case DW_OP_breg2:
2656 return "DW_OP_breg2";
2657 case DW_OP_breg3:
2658 return "DW_OP_breg3";
2659 case DW_OP_breg4:
2660 return "DW_OP_breg4";
2661 case DW_OP_breg5:
2662 return "DW_OP_breg5";
2663 case DW_OP_breg6:
2664 return "DW_OP_breg6";
2665 case DW_OP_breg7:
2666 return "DW_OP_breg7";
2667 case DW_OP_breg8:
2668 return "DW_OP_breg8";
2669 case DW_OP_breg9:
2670 return "DW_OP_breg9";
2671 case DW_OP_breg10:
2672 return "DW_OP_breg10";
2673 case DW_OP_breg11:
2674 return "DW_OP_breg11";
2675 case DW_OP_breg12:
2676 return "DW_OP_breg12";
2677 case DW_OP_breg13:
2678 return "DW_OP_breg13";
2679 case DW_OP_breg14:
2680 return "DW_OP_breg14";
2681 case DW_OP_breg15:
2682 return "DW_OP_breg15";
2683 case DW_OP_breg16:
2684 return "DW_OP_breg16";
2685 case DW_OP_breg17:
2686 return "DW_OP_breg17";
2687 case DW_OP_breg18:
2688 return "DW_OP_breg18";
2689 case DW_OP_breg19:
2690 return "DW_OP_breg19";
2691 case DW_OP_breg20:
2692 return "DW_OP_breg20";
2693 case DW_OP_breg21:
2694 return "DW_OP_breg21";
2695 case DW_OP_breg22:
2696 return "DW_OP_breg22";
2697 case DW_OP_breg23:
2698 return "DW_OP_breg23";
2699 case DW_OP_breg24:
2700 return "DW_OP_breg24";
2701 case DW_OP_breg25:
2702 return "DW_OP_breg25";
2703 case DW_OP_breg26:
2704 return "DW_OP_breg26";
2705 case DW_OP_breg27:
2706 return "DW_OP_breg27";
2707 case DW_OP_breg28:
2708 return "DW_OP_breg28";
2709 case DW_OP_breg29:
2710 return "DW_OP_breg29";
2711 case DW_OP_breg30:
2712 return "DW_OP_breg30";
2713 case DW_OP_breg31:
2714 return "DW_OP_breg31";
2715 case DW_OP_regx:
2716 return "DW_OP_regx";
2717 case DW_OP_fbreg:
2718 return "DW_OP_fbreg";
2719 case DW_OP_bregx:
2720 return "DW_OP_bregx";
2721 case DW_OP_piece:
2722 return "DW_OP_piece";
2723 case DW_OP_deref_size:
2724 return "DW_OP_deref_size";
2725 case DW_OP_xderef_size:
2726 return "DW_OP_xderef_size";
2727 case DW_OP_nop:
2728 return "DW_OP_nop";
2729 default:
2730 return "OP_<unknown>";
2734 /* Return a pointer to a newly allocated location description. Location
2735 descriptions are simple expression terms that can be strung
2736 together to form more complicated location (address) descriptions. */
2738 static inline dw_loc_descr_ref
2739 new_loc_descr (op, oprnd1, oprnd2)
2740 register enum dwarf_location_atom op;
2741 register unsigned long oprnd1;
2742 register unsigned long oprnd2;
2744 /* Use xcalloc here so we clear out all of the long_long constant in
2745 the union. */
2746 register dw_loc_descr_ref descr
2747 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2749 descr->dw_loc_opc = op;
2750 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2751 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2752 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2753 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2755 return descr;
2758 /* Add a location description term to a location description expression. */
2760 static inline void
2761 add_loc_descr (list_head, descr)
2762 register dw_loc_descr_ref *list_head;
2763 register dw_loc_descr_ref descr;
2765 register dw_loc_descr_ref *d;
2767 /* Find the end of the chain. */
2768 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2771 *d = descr;
2774 /* Return the size of a location descriptor. */
2776 static unsigned long
2777 size_of_loc_descr (loc)
2778 register dw_loc_descr_ref loc;
2780 register unsigned long size = 1;
2782 switch (loc->dw_loc_opc)
2784 case DW_OP_addr:
2785 size += DWARF2_ADDR_SIZE;
2786 break;
2787 case DW_OP_const1u:
2788 case DW_OP_const1s:
2789 size += 1;
2790 break;
2791 case DW_OP_const2u:
2792 case DW_OP_const2s:
2793 size += 2;
2794 break;
2795 case DW_OP_const4u:
2796 case DW_OP_const4s:
2797 size += 4;
2798 break;
2799 case DW_OP_const8u:
2800 case DW_OP_const8s:
2801 size += 8;
2802 break;
2803 case DW_OP_constu:
2804 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2805 break;
2806 case DW_OP_consts:
2807 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2808 break;
2809 case DW_OP_pick:
2810 size += 1;
2811 break;
2812 case DW_OP_plus_uconst:
2813 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2814 break;
2815 case DW_OP_skip:
2816 case DW_OP_bra:
2817 size += 2;
2818 break;
2819 case DW_OP_breg0:
2820 case DW_OP_breg1:
2821 case DW_OP_breg2:
2822 case DW_OP_breg3:
2823 case DW_OP_breg4:
2824 case DW_OP_breg5:
2825 case DW_OP_breg6:
2826 case DW_OP_breg7:
2827 case DW_OP_breg8:
2828 case DW_OP_breg9:
2829 case DW_OP_breg10:
2830 case DW_OP_breg11:
2831 case DW_OP_breg12:
2832 case DW_OP_breg13:
2833 case DW_OP_breg14:
2834 case DW_OP_breg15:
2835 case DW_OP_breg16:
2836 case DW_OP_breg17:
2837 case DW_OP_breg18:
2838 case DW_OP_breg19:
2839 case DW_OP_breg20:
2840 case DW_OP_breg21:
2841 case DW_OP_breg22:
2842 case DW_OP_breg23:
2843 case DW_OP_breg24:
2844 case DW_OP_breg25:
2845 case DW_OP_breg26:
2846 case DW_OP_breg27:
2847 case DW_OP_breg28:
2848 case DW_OP_breg29:
2849 case DW_OP_breg30:
2850 case DW_OP_breg31:
2851 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2852 break;
2853 case DW_OP_regx:
2854 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2855 break;
2856 case DW_OP_fbreg:
2857 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2858 break;
2859 case DW_OP_bregx:
2860 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2861 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2862 break;
2863 case DW_OP_piece:
2864 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2865 break;
2866 case DW_OP_deref_size:
2867 case DW_OP_xderef_size:
2868 size += 1;
2869 break;
2870 default:
2871 break;
2874 return size;
2877 /* Return the size of a series of location descriptors. */
2879 static unsigned long
2880 size_of_locs (loc)
2881 register dw_loc_descr_ref loc;
2883 register unsigned long size = 0;
2885 for (; loc != NULL; loc = loc->dw_loc_next)
2887 loc->dw_loc_addr = size;
2888 size += size_of_loc_descr (loc);
2891 return size;
2894 /* Output location description stack opcode's operands (if any). */
2896 static void
2897 output_loc_operands (loc)
2898 register dw_loc_descr_ref loc;
2900 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2901 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2903 switch (loc->dw_loc_opc)
2905 #ifdef DWARF2_DEBUGGING_INFO
2906 case DW_OP_addr:
2907 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
2908 fputc ('\n', asm_out_file);
2909 break;
2910 case DW_OP_const2u:
2911 case DW_OP_const2s:
2912 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
2913 fputc ('\n', asm_out_file);
2914 break;
2915 case DW_OP_const4u:
2916 case DW_OP_const4s:
2917 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
2918 fputc ('\n', asm_out_file);
2919 break;
2920 case DW_OP_const8u:
2921 case DW_OP_const8s:
2922 abort ();
2923 fputc ('\n', asm_out_file);
2924 break;
2925 case DW_OP_skip:
2926 case DW_OP_bra:
2928 int offset;
2930 if (val1->val_class == dw_val_class_loc)
2931 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2932 else
2933 abort ();
2935 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, offset);
2936 fputc ('\n', asm_out_file);
2938 break;
2939 #else
2940 case DW_OP_addr:
2941 case DW_OP_const2u:
2942 case DW_OP_const2s:
2943 case DW_OP_const4u:
2944 case DW_OP_const4s:
2945 case DW_OP_const8u:
2946 case DW_OP_const8s:
2947 case DW_OP_skip:
2948 case DW_OP_bra:
2949 /* We currently don't make any attempt to make sure these are
2950 aligned properly like we do for the main unwind info, so
2951 don't support emitting things larger than a byte if we're
2952 only doing unwinding. */
2953 abort ();
2954 #endif
2955 case DW_OP_const1u:
2956 case DW_OP_const1s:
2957 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2958 fputc ('\n', asm_out_file);
2959 break;
2960 case DW_OP_constu:
2961 output_uleb128 (val1->v.val_unsigned);
2962 fputc ('\n', asm_out_file);
2963 break;
2964 case DW_OP_consts:
2965 output_sleb128 (val1->v.val_int);
2966 fputc ('\n', asm_out_file);
2967 break;
2968 case DW_OP_pick:
2969 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
2970 fputc ('\n', asm_out_file);
2971 break;
2972 case DW_OP_plus_uconst:
2973 output_uleb128 (val1->v.val_unsigned);
2974 fputc ('\n', asm_out_file);
2975 break;
2976 case DW_OP_breg0:
2977 case DW_OP_breg1:
2978 case DW_OP_breg2:
2979 case DW_OP_breg3:
2980 case DW_OP_breg4:
2981 case DW_OP_breg5:
2982 case DW_OP_breg6:
2983 case DW_OP_breg7:
2984 case DW_OP_breg8:
2985 case DW_OP_breg9:
2986 case DW_OP_breg10:
2987 case DW_OP_breg11:
2988 case DW_OP_breg12:
2989 case DW_OP_breg13:
2990 case DW_OP_breg14:
2991 case DW_OP_breg15:
2992 case DW_OP_breg16:
2993 case DW_OP_breg17:
2994 case DW_OP_breg18:
2995 case DW_OP_breg19:
2996 case DW_OP_breg20:
2997 case DW_OP_breg21:
2998 case DW_OP_breg22:
2999 case DW_OP_breg23:
3000 case DW_OP_breg24:
3001 case DW_OP_breg25:
3002 case DW_OP_breg26:
3003 case DW_OP_breg27:
3004 case DW_OP_breg28:
3005 case DW_OP_breg29:
3006 case DW_OP_breg30:
3007 case DW_OP_breg31:
3008 output_sleb128 (val1->v.val_int);
3009 fputc ('\n', asm_out_file);
3010 break;
3011 case DW_OP_regx:
3012 output_uleb128 (val1->v.val_unsigned);
3013 fputc ('\n', asm_out_file);
3014 break;
3015 case DW_OP_fbreg:
3016 output_sleb128 (val1->v.val_int);
3017 fputc ('\n', asm_out_file);
3018 break;
3019 case DW_OP_bregx:
3020 output_uleb128 (val1->v.val_unsigned);
3021 fputc ('\n', asm_out_file);
3022 output_sleb128 (val2->v.val_int);
3023 fputc ('\n', asm_out_file);
3024 break;
3025 case DW_OP_piece:
3026 output_uleb128 (val1->v.val_unsigned);
3027 fputc ('\n', asm_out_file);
3028 break;
3029 case DW_OP_deref_size:
3030 case DW_OP_xderef_size:
3031 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
3032 fputc ('\n', asm_out_file);
3033 break;
3034 default:
3035 /* Other codes have no operands. */
3036 break;
3040 /* Output a sequence of location operations. */
3042 static void
3043 output_loc_sequence (loc)
3044 dw_loc_descr_ref loc;
3046 for (; loc != NULL; loc = loc->dw_loc_next)
3048 /* Output the opcode. */
3049 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
3050 if (flag_debug_asm)
3051 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
3052 dwarf_stack_op_name (loc->dw_loc_opc));
3054 fputc ('\n', asm_out_file);
3056 /* Output the operand(s) (if any). */
3057 output_loc_operands (loc);
3061 /* This routine will generate the correct assembly data for a location
3062 description based on a cfi entry with a complex address. */
3064 static void
3065 output_cfa_loc (cfi)
3066 dw_cfi_ref cfi;
3068 dw_loc_descr_ref loc;
3069 unsigned long size;
3071 /* Output the size of the block. */
3072 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3073 size = size_of_locs (loc);
3074 output_uleb128 (size);
3075 fputc ('\n', asm_out_file);
3077 /* Now output the operations themselves. */
3078 output_loc_sequence (loc);
3081 /* This function builds a dwarf location descriptor seqeunce from
3082 a dw_cfa_location. */
3084 static struct dw_loc_descr_struct *
3085 build_cfa_loc (cfa)
3086 dw_cfa_location *cfa;
3088 struct dw_loc_descr_struct *head, *tmp;
3090 if (cfa->indirect == 0)
3091 abort ();
3093 if (cfa->base_offset)
3095 if (cfa->reg <= 31)
3096 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3097 else
3098 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3100 else if (cfa->reg <= 31)
3101 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3102 else
3103 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3104 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3105 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3106 add_loc_descr (&head, tmp);
3107 if (cfa->offset != 0)
3109 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
3110 add_loc_descr (&head, tmp);
3112 return head;
3115 /* This function fills in aa dw_cfa_location structure from a
3116 dwarf location descriptor sequence. */
3118 static void
3119 get_cfa_from_loc_descr (cfa, loc)
3120 dw_cfa_location *cfa;
3121 struct dw_loc_descr_struct *loc;
3123 struct dw_loc_descr_struct *ptr;
3124 cfa->offset = 0;
3125 cfa->base_offset = 0;
3126 cfa->indirect = 0;
3127 cfa->reg = -1;
3129 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3131 enum dwarf_location_atom op = ptr->dw_loc_opc;
3132 switch (op)
3134 case DW_OP_reg0:
3135 case DW_OP_reg1:
3136 case DW_OP_reg2:
3137 case DW_OP_reg3:
3138 case DW_OP_reg4:
3139 case DW_OP_reg5:
3140 case DW_OP_reg6:
3141 case DW_OP_reg7:
3142 case DW_OP_reg8:
3143 case DW_OP_reg9:
3144 case DW_OP_reg10:
3145 case DW_OP_reg11:
3146 case DW_OP_reg12:
3147 case DW_OP_reg13:
3148 case DW_OP_reg14:
3149 case DW_OP_reg15:
3150 case DW_OP_reg16:
3151 case DW_OP_reg17:
3152 case DW_OP_reg18:
3153 case DW_OP_reg19:
3154 case DW_OP_reg20:
3155 case DW_OP_reg21:
3156 case DW_OP_reg22:
3157 case DW_OP_reg23:
3158 case DW_OP_reg24:
3159 case DW_OP_reg25:
3160 case DW_OP_reg26:
3161 case DW_OP_reg27:
3162 case DW_OP_reg28:
3163 case DW_OP_reg29:
3164 case DW_OP_reg30:
3165 case DW_OP_reg31:
3166 cfa->reg = op - DW_OP_reg0;
3167 break;
3168 case DW_OP_regx:
3169 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3170 break;
3171 case DW_OP_breg0:
3172 case DW_OP_breg1:
3173 case DW_OP_breg2:
3174 case DW_OP_breg3:
3175 case DW_OP_breg4:
3176 case DW_OP_breg5:
3177 case DW_OP_breg6:
3178 case DW_OP_breg7:
3179 case DW_OP_breg8:
3180 case DW_OP_breg9:
3181 case DW_OP_breg10:
3182 case DW_OP_breg11:
3183 case DW_OP_breg12:
3184 case DW_OP_breg13:
3185 case DW_OP_breg14:
3186 case DW_OP_breg15:
3187 case DW_OP_breg16:
3188 case DW_OP_breg17:
3189 case DW_OP_breg18:
3190 case DW_OP_breg19:
3191 case DW_OP_breg20:
3192 case DW_OP_breg21:
3193 case DW_OP_breg22:
3194 case DW_OP_breg23:
3195 case DW_OP_breg24:
3196 case DW_OP_breg25:
3197 case DW_OP_breg26:
3198 case DW_OP_breg27:
3199 case DW_OP_breg28:
3200 case DW_OP_breg29:
3201 case DW_OP_breg30:
3202 case DW_OP_breg31:
3203 cfa->reg = op - DW_OP_breg0;
3204 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3205 break;
3206 case DW_OP_bregx:
3207 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3208 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3209 break;
3210 case DW_OP_deref:
3211 cfa->indirect = 1;
3212 break;
3213 case DW_OP_plus_uconst:
3214 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3215 break;
3216 default:
3217 internal_error ("DW_LOC_OP %s not implememnted\n",
3218 dwarf_stack_op_name (ptr->dw_loc_opc));
3222 #endif /* .debug_frame support */
3224 /* And now, the support for symbolic debugging information. */
3225 #ifdef DWARF2_DEBUGGING_INFO
3227 /* NOTE: In the comments in this file, many references are made to
3228 "Debugging Information Entries". This term is abbreviated as `DIE'
3229 throughout the remainder of this file. */
3231 /* An internal representation of the DWARF output is built, and then
3232 walked to generate the DWARF debugging info. The walk of the internal
3233 representation is done after the entire program has been compiled.
3234 The types below are used to describe the internal representation. */
3236 /* Various DIE's use offsets relative to the beginning of the
3237 .debug_info section to refer to each other. */
3239 typedef long int dw_offset;
3241 /* Define typedefs here to avoid circular dependencies. */
3243 typedef struct dw_attr_struct *dw_attr_ref;
3244 typedef struct dw_line_info_struct *dw_line_info_ref;
3245 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3246 typedef struct pubname_struct *pubname_ref;
3247 typedef dw_die_ref *arange_ref;
3249 /* Each entry in the line_info_table maintains the file and
3250 line number associated with the label generated for that
3251 entry. The label gives the PC value associated with
3252 the line number entry. */
3254 typedef struct dw_line_info_struct
3256 unsigned long dw_file_num;
3257 unsigned long dw_line_num;
3259 dw_line_info_entry;
3261 /* Line information for functions in separate sections; each one gets its
3262 own sequence. */
3263 typedef struct dw_separate_line_info_struct
3265 unsigned long dw_file_num;
3266 unsigned long dw_line_num;
3267 unsigned long function;
3269 dw_separate_line_info_entry;
3271 /* Each DIE attribute has a field specifying the attribute kind,
3272 a link to the next attribute in the chain, and an attribute value.
3273 Attributes are typically linked below the DIE they modify. */
3275 typedef struct dw_attr_struct
3277 enum dwarf_attribute dw_attr;
3278 dw_attr_ref dw_attr_next;
3279 dw_val_node dw_attr_val;
3281 dw_attr_node;
3283 /* The Debugging Information Entry (DIE) structure */
3285 typedef struct die_struct
3287 enum dwarf_tag die_tag;
3288 char *die_symbol;
3289 dw_attr_ref die_attr;
3290 dw_die_ref die_parent;
3291 dw_die_ref die_child;
3292 dw_die_ref die_sib;
3293 dw_offset die_offset;
3294 unsigned long die_abbrev;
3295 int die_mark;
3297 die_node;
3299 /* The pubname structure */
3301 typedef struct pubname_struct
3303 dw_die_ref die;
3304 char *name;
3306 pubname_entry;
3308 /* The limbo die list structure. */
3309 typedef struct limbo_die_struct
3311 dw_die_ref die;
3312 struct limbo_die_struct *next;
3314 limbo_die_node;
3316 /* How to start an assembler comment. */
3317 #ifndef ASM_COMMENT_START
3318 #define ASM_COMMENT_START ";#"
3319 #endif
3321 /* Define a macro which returns non-zero for a TYPE_DECL which was
3322 implicitly generated for a tagged type.
3324 Note that unlike the gcc front end (which generates a NULL named
3325 TYPE_DECL node for each complete tagged type, each array type, and
3326 each function type node created) the g++ front end generates a
3327 _named_ TYPE_DECL node for each tagged type node created.
3328 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3329 generate a DW_TAG_typedef DIE for them. */
3331 #define TYPE_DECL_IS_STUB(decl) \
3332 (DECL_NAME (decl) == NULL_TREE \
3333 || (DECL_ARTIFICIAL (decl) \
3334 && is_tagged_type (TREE_TYPE (decl)) \
3335 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3336 /* This is necessary for stub decls that \
3337 appear in nested inline functions. */ \
3338 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3339 && (decl_ultimate_origin (decl) \
3340 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3342 /* Information concerning the compilation unit's programming
3343 language, and compiler version. */
3345 extern int flag_traditional;
3347 /* Fixed size portion of the DWARF compilation unit header. */
3348 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3350 /* Fixed size portion of debugging line information prolog. */
3351 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3353 /* Fixed size portion of public names info. */
3354 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3356 /* Fixed size portion of the address range info. */
3357 #define DWARF_ARANGES_HEADER_SIZE \
3358 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3359 - DWARF_OFFSET_SIZE)
3361 /* Size of padding portion in the address range info. It must be
3362 aligned to twice the pointer size. */
3363 #define DWARF_ARANGES_PAD_SIZE \
3364 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3365 - (2 * DWARF_OFFSET_SIZE + 4))
3367 /* Use assembler line directives if available. */
3368 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3369 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3370 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3371 #else
3372 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3373 #endif
3374 #endif
3376 /* Define the architecture-dependent minimum instruction length (in bytes).
3377 In this implementation of DWARF, this field is used for information
3378 purposes only. Since GCC generates assembly language, we have
3379 no a priori knowledge of how many instruction bytes are generated
3380 for each source line, and therefore can use only the DW_LNE_set_address
3381 and DW_LNS_fixed_advance_pc line information commands. */
3383 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3384 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3385 #endif
3387 /* Minimum line offset in a special line info. opcode.
3388 This value was chosen to give a reasonable range of values. */
3389 #define DWARF_LINE_BASE -10
3391 /* First special line opcde - leave room for the standard opcodes. */
3392 #define DWARF_LINE_OPCODE_BASE 10
3394 /* Range of line offsets in a special line info. opcode. */
3395 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3397 /* Flag that indicates the initial value of the is_stmt_start flag.
3398 In the present implementation, we do not mark any lines as
3399 the beginning of a source statement, because that information
3400 is not made available by the GCC front-end. */
3401 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3403 /* This location is used by calc_die_sizes() to keep track
3404 the offset of each DIE within the .debug_info section. */
3405 static unsigned long next_die_offset;
3407 /* Record the root of the DIE's built for the current compilation unit. */
3408 static dw_die_ref comp_unit_die;
3410 /* A list of DIEs with a NULL parent waiting to be relocated. */
3411 static limbo_die_node *limbo_die_list = 0;
3413 /* Structure used by lookup_filename to manage sets of filenames. */
3414 struct file_table
3416 char **table;
3417 unsigned allocated;
3418 unsigned in_use;
3419 unsigned last_lookup_index;
3422 /* Size (in elements) of increments by which we may expand the filename
3423 table. */
3424 #define FILE_TABLE_INCREMENT 64
3426 /* Filenames referenced by this compilation unit. */
3427 static struct file_table file_table;
3429 /* Local pointer to the name of the main input file. Initialized in
3430 dwarf2out_init. */
3431 static const char *primary_filename;
3433 /* A pointer to the base of a table of references to DIE's that describe
3434 declarations. The table is indexed by DECL_UID() which is a unique
3435 number identifying each decl. */
3436 static dw_die_ref *decl_die_table;
3438 /* Number of elements currently allocated for the decl_die_table. */
3439 static unsigned decl_die_table_allocated;
3441 /* Number of elements in decl_die_table currently in use. */
3442 static unsigned decl_die_table_in_use;
3444 /* Size (in elements) of increments by which we may expand the
3445 decl_die_table. */
3446 #define DECL_DIE_TABLE_INCREMENT 256
3448 /* A pointer to the base of a table of references to declaration
3449 scopes. This table is a display which tracks the nesting
3450 of declaration scopes at the current scope and containing
3451 scopes. This table is used to find the proper place to
3452 define type declaration DIE's. */
3453 static tree *decl_scope_table;
3455 /* Number of elements currently allocated for the decl_scope_table. */
3456 static int decl_scope_table_allocated;
3458 /* Current level of nesting of declaration scopes. */
3459 static int decl_scope_depth;
3461 /* Size (in elements) of increments by which we may expand the
3462 decl_scope_table. */
3463 #define DECL_SCOPE_TABLE_INCREMENT 64
3465 /* A pointer to the base of a list of references to DIE's that
3466 are uniquely identified by their tag, presence/absence of
3467 children DIE's, and list of attribute/value pairs. */
3468 static dw_die_ref *abbrev_die_table;
3470 /* Number of elements currently allocated for abbrev_die_table. */
3471 static unsigned abbrev_die_table_allocated;
3473 /* Number of elements in type_die_table currently in use. */
3474 static unsigned abbrev_die_table_in_use;
3476 /* Size (in elements) of increments by which we may expand the
3477 abbrev_die_table. */
3478 #define ABBREV_DIE_TABLE_INCREMENT 256
3480 /* A pointer to the base of a table that contains line information
3481 for each source code line in .text in the compilation unit. */
3482 static dw_line_info_ref line_info_table;
3484 /* Number of elements currently allocated for line_info_table. */
3485 static unsigned line_info_table_allocated;
3487 /* Number of elements in separate_line_info_table currently in use. */
3488 static unsigned separate_line_info_table_in_use;
3490 /* A pointer to the base of a table that contains line information
3491 for each source code line outside of .text in the compilation unit. */
3492 static dw_separate_line_info_ref separate_line_info_table;
3494 /* Number of elements currently allocated for separate_line_info_table. */
3495 static unsigned separate_line_info_table_allocated;
3497 /* Number of elements in line_info_table currently in use. */
3498 static unsigned line_info_table_in_use;
3500 /* Size (in elements) of increments by which we may expand the
3501 line_info_table. */
3502 #define LINE_INFO_TABLE_INCREMENT 1024
3504 /* A pointer to the base of a table that contains a list of publicly
3505 accessible names. */
3506 static pubname_ref pubname_table;
3508 /* Number of elements currently allocated for pubname_table. */
3509 static unsigned pubname_table_allocated;
3511 /* Number of elements in pubname_table currently in use. */
3512 static unsigned pubname_table_in_use;
3514 /* Size (in elements) of increments by which we may expand the
3515 pubname_table. */
3516 #define PUBNAME_TABLE_INCREMENT 64
3518 /* A pointer to the base of a table that contains a list of publicly
3519 accessible names. */
3520 static arange_ref arange_table;
3522 /* Number of elements currently allocated for arange_table. */
3523 static unsigned arange_table_allocated;
3525 /* Number of elements in arange_table currently in use. */
3526 static unsigned arange_table_in_use;
3528 /* Size (in elements) of increments by which we may expand the
3529 arange_table. */
3530 #define ARANGE_TABLE_INCREMENT 64
3532 /* A pointer to the base of a list of incomplete types which might be
3533 completed at some later time. */
3535 static tree *incomplete_types_list;
3537 /* Number of elements currently allocated for the incomplete_types_list. */
3538 static unsigned incomplete_types_allocated;
3540 /* Number of elements of incomplete_types_list currently in use. */
3541 static unsigned incomplete_types;
3543 /* Size (in elements) of increments by which we may expand the incomplete
3544 types list. Actually, a single hunk of space of this size should
3545 be enough for most typical programs. */
3546 #define INCOMPLETE_TYPES_INCREMENT 64
3548 /* Record whether the function being analyzed contains inlined functions. */
3549 static int current_function_has_inlines;
3550 #if 0 && defined (MIPS_DEBUGGING_INFO)
3551 static int comp_unit_has_inlines;
3552 #endif
3554 /* Array of RTXes referenced by the debugging information, which therefore
3555 must be kept around forever. We do this rather than perform GC on
3556 the dwarf info because almost all of the dwarf info lives forever, and
3557 it's easier to support non-GC frontends this way. */
3558 static varray_type used_rtx_varray;
3560 /* Forward declarations for functions defined in this file. */
3562 static int is_pseudo_reg PARAMS ((rtx));
3563 static tree type_main_variant PARAMS ((tree));
3564 static int is_tagged_type PARAMS ((tree));
3565 static const char *dwarf_tag_name PARAMS ((unsigned));
3566 static const char *dwarf_attr_name PARAMS ((unsigned));
3567 static const char *dwarf_form_name PARAMS ((unsigned));
3568 #if 0
3569 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3570 #endif
3571 static tree decl_ultimate_origin PARAMS ((tree));
3572 static tree block_ultimate_origin PARAMS ((tree));
3573 static tree decl_class_context PARAMS ((tree));
3574 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3575 static void add_AT_flag PARAMS ((dw_die_ref,
3576 enum dwarf_attribute,
3577 unsigned));
3578 static void add_AT_int PARAMS ((dw_die_ref,
3579 enum dwarf_attribute, long));
3580 static void add_AT_unsigned PARAMS ((dw_die_ref,
3581 enum dwarf_attribute,
3582 unsigned long));
3583 static void add_AT_long_long PARAMS ((dw_die_ref,
3584 enum dwarf_attribute,
3585 unsigned long,
3586 unsigned long));
3587 static void add_AT_float PARAMS ((dw_die_ref,
3588 enum dwarf_attribute,
3589 unsigned, long *));
3590 static void add_AT_string PARAMS ((dw_die_ref,
3591 enum dwarf_attribute,
3592 const char *));
3593 static void add_AT_die_ref PARAMS ((dw_die_ref,
3594 enum dwarf_attribute,
3595 dw_die_ref));
3596 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3597 enum dwarf_attribute,
3598 unsigned));
3599 static void add_AT_loc PARAMS ((dw_die_ref,
3600 enum dwarf_attribute,
3601 dw_loc_descr_ref));
3602 static void add_AT_addr PARAMS ((dw_die_ref,
3603 enum dwarf_attribute,
3604 rtx));
3605 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3606 enum dwarf_attribute,
3607 const char *));
3608 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3609 enum dwarf_attribute,
3610 const char *));
3611 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3612 enum dwarf_attribute));
3613 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3614 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3615 static const char *get_AT_string PARAMS ((dw_die_ref,
3616 enum dwarf_attribute));
3617 static int get_AT_flag PARAMS ((dw_die_ref,
3618 enum dwarf_attribute));
3619 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3620 enum dwarf_attribute));
3621 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3622 enum dwarf_attribute));
3623 static int is_c_family PARAMS ((void));
3624 static int is_java PARAMS ((void));
3625 static int is_fortran PARAMS ((void));
3626 static void remove_AT PARAMS ((dw_die_ref,
3627 enum dwarf_attribute));
3628 static void remove_children PARAMS ((dw_die_ref));
3629 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3630 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3631 static dw_die_ref lookup_type_die PARAMS ((tree));
3632 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3633 static dw_die_ref lookup_decl_die PARAMS ((tree));
3634 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3635 static void print_spaces PARAMS ((FILE *));
3636 static void print_die PARAMS ((dw_die_ref, FILE *));
3637 static void print_dwarf_line_table PARAMS ((FILE *));
3638 static void reverse_die_lists PARAMS ((dw_die_ref));
3639 static void reverse_all_dies PARAMS ((dw_die_ref));
3640 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3641 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3642 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3643 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3644 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3645 static void compute_section_prefix PARAMS ((dw_die_ref));
3646 static int is_type_die PARAMS ((dw_die_ref));
3647 static int is_comdat_die PARAMS ((dw_die_ref));
3648 static int is_symbol_die PARAMS ((dw_die_ref));
3649 static char *gen_internal_sym PARAMS ((void));
3650 static void assign_symbol_names PARAMS ((dw_die_ref));
3651 static void break_out_includes PARAMS ((dw_die_ref));
3652 static void add_sibling_attributes PARAMS ((dw_die_ref));
3653 static void build_abbrev_table PARAMS ((dw_die_ref));
3654 static unsigned long size_of_string PARAMS ((const char *));
3655 static int constant_size PARAMS ((long unsigned));
3656 static unsigned long size_of_die PARAMS ((dw_die_ref));
3657 static void calc_die_sizes PARAMS ((dw_die_ref));
3658 static void mark_dies PARAMS ((dw_die_ref));
3659 static void unmark_dies PARAMS ((dw_die_ref));
3660 static unsigned long size_of_pubnames PARAMS ((void));
3661 static unsigned long size_of_aranges PARAMS ((void));
3662 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3663 static void output_value_format PARAMS ((dw_attr_ref));
3664 static void output_abbrev_section PARAMS ((void));
3665 static void output_die_symbol PARAMS ((dw_die_ref));
3666 static void output_symbolic_ref PARAMS ((dw_die_ref));
3667 static void output_die PARAMS ((dw_die_ref));
3668 static void output_compilation_unit_header PARAMS ((void));
3669 static void output_comp_unit PARAMS ((dw_die_ref));
3670 static const char *dwarf2_name PARAMS ((tree, int));
3671 static void add_pubname PARAMS ((tree, dw_die_ref));
3672 static void output_pubnames PARAMS ((void));
3673 static void add_arange PARAMS ((tree, dw_die_ref));
3674 static void output_aranges PARAMS ((void));
3675 static void output_line_info PARAMS ((void));
3676 static void output_file_names PARAMS ((void));
3677 static dw_die_ref base_type_die PARAMS ((tree));
3678 static tree root_type PARAMS ((tree));
3679 static int is_base_type PARAMS ((tree));
3680 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3681 static int type_is_enum PARAMS ((tree));
3682 static unsigned int reg_number PARAMS ((rtx));
3683 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3684 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3685 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3686 static int is_based_loc PARAMS ((rtx));
3687 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3688 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3689 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3690 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3691 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3692 static tree field_type PARAMS ((tree));
3693 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3694 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3695 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3696 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3697 static void add_AT_location_description PARAMS ((dw_die_ref,
3698 enum dwarf_attribute, rtx));
3699 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3700 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3701 static rtx rtl_for_decl_location PARAMS ((tree));
3702 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3703 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3704 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3705 static void add_bound_info PARAMS ((dw_die_ref,
3706 enum dwarf_attribute, tree));
3707 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3708 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3709 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3710 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3711 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3712 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3713 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3714 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3715 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3716 static void push_decl_scope PARAMS ((tree));
3717 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3718 static void pop_decl_scope PARAMS ((void));
3719 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3720 dw_die_ref));
3721 static const char *type_tag PARAMS ((tree));
3722 static tree member_declared_type PARAMS ((tree));
3723 #if 0
3724 static const char *decl_start_label PARAMS ((tree));
3725 #endif
3726 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3727 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3728 #if 0
3729 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3730 #endif
3731 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3732 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3733 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3734 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3735 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3736 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3737 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3738 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3739 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3740 static void gen_label_die PARAMS ((tree, dw_die_ref));
3741 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3742 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3743 static void gen_field_die PARAMS ((tree, dw_die_ref));
3744 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3745 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3746 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3747 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3748 static void gen_member_die PARAMS ((tree, dw_die_ref));
3749 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3750 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3751 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3752 static void gen_type_die PARAMS ((tree, dw_die_ref));
3753 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3754 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3755 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3756 static int is_redundant_typedef PARAMS ((tree));
3757 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3758 static unsigned lookup_filename PARAMS ((const char *));
3759 static void init_file_table PARAMS ((void));
3760 static void add_incomplete_type PARAMS ((tree));
3761 static void retry_incomplete_types PARAMS ((void));
3762 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3763 static rtx save_rtx PARAMS ((rtx));
3764 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3765 static int file_info_cmp PARAMS ((const void *, const void *));
3767 /* Section names used to hold DWARF debugging information. */
3768 #ifndef DEBUG_INFO_SECTION
3769 #define DEBUG_INFO_SECTION ".debug_info"
3770 #endif
3771 #ifndef ABBREV_SECTION
3772 #define ABBREV_SECTION ".debug_abbrev"
3773 #endif
3774 #ifndef ARANGES_SECTION
3775 #define ARANGES_SECTION ".debug_aranges"
3776 #endif
3777 #ifndef DW_MACINFO_SECTION
3778 #define DW_MACINFO_SECTION ".debug_macinfo"
3779 #endif
3780 #ifndef DEBUG_LINE_SECTION
3781 #define DEBUG_LINE_SECTION ".debug_line"
3782 #endif
3783 #ifndef LOC_SECTION
3784 #define LOC_SECTION ".debug_loc"
3785 #endif
3786 #ifndef PUBNAMES_SECTION
3787 #define PUBNAMES_SECTION ".debug_pubnames"
3788 #endif
3789 #ifndef STR_SECTION
3790 #define STR_SECTION ".debug_str"
3791 #endif
3793 /* Standard ELF section names for compiled code and data. */
3794 #ifndef TEXT_SECTION
3795 #define TEXT_SECTION ".text"
3796 #endif
3797 #ifndef DATA_SECTION
3798 #define DATA_SECTION ".data"
3799 #endif
3800 #ifndef BSS_SECTION
3801 #define BSS_SECTION ".bss"
3802 #endif
3804 /* Labels we insert at beginning sections we can reference instead of
3805 the section names themselves. */
3807 #ifndef TEXT_SECTION_LABEL
3808 #define TEXT_SECTION_LABEL "Ltext"
3809 #endif
3810 #ifndef DEBUG_LINE_SECTION_LABEL
3811 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3812 #endif
3813 #ifndef DEBUG_INFO_SECTION_LABEL
3814 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3815 #endif
3816 #ifndef ABBREV_SECTION_LABEL
3817 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3818 #endif
3820 /* Definitions of defaults for formats and names of various special
3821 (artificial) labels which may be generated within this file (when the -g
3822 options is used and DWARF_DEBUGGING_INFO is in effect.
3823 If necessary, these may be overridden from within the tm.h file, but
3824 typically, overriding these defaults is unnecessary. */
3826 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3827 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3828 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3829 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3830 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3832 #ifndef TEXT_END_LABEL
3833 #define TEXT_END_LABEL "Letext"
3834 #endif
3835 #ifndef DATA_END_LABEL
3836 #define DATA_END_LABEL "Ledata"
3837 #endif
3838 #ifndef BSS_END_LABEL
3839 #define BSS_END_LABEL "Lebss"
3840 #endif
3841 #ifndef BLOCK_BEGIN_LABEL
3842 #define BLOCK_BEGIN_LABEL "LBB"
3843 #endif
3844 #ifndef BLOCK_END_LABEL
3845 #define BLOCK_END_LABEL "LBE"
3846 #endif
3847 #ifndef BODY_BEGIN_LABEL
3848 #define BODY_BEGIN_LABEL "Lbb"
3849 #endif
3850 #ifndef BODY_END_LABEL
3851 #define BODY_END_LABEL "Lbe"
3852 #endif
3853 #ifndef LINE_CODE_LABEL
3854 #define LINE_CODE_LABEL "LM"
3855 #endif
3856 #ifndef SEPARATE_LINE_CODE_LABEL
3857 #define SEPARATE_LINE_CODE_LABEL "LSM"
3858 #endif
3860 /* We allow a language front-end to designate a function that is to be
3861 called to "demangle" any name before it it put into a DIE. */
3863 static const char *(*demangle_name_func) PARAMS ((const char *));
3865 void
3866 dwarf2out_set_demangle_name_func (func)
3867 const char *(*func) PARAMS ((const char *));
3869 demangle_name_func = func;
3872 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3873 that means adding it to used_rtx_varray. If not, that means making
3874 a copy on the permanent_obstack. */
3876 static rtx
3877 save_rtx (orig)
3878 register rtx orig;
3880 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3882 return orig;
3885 /* Test if rtl node points to a pseudo register. */
3887 static inline int
3888 is_pseudo_reg (rtl)
3889 register rtx rtl;
3891 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3892 || (GET_CODE (rtl) == SUBREG
3893 && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER));
3896 /* Return a reference to a type, with its const and volatile qualifiers
3897 removed. */
3899 static inline tree
3900 type_main_variant (type)
3901 register tree type;
3903 type = TYPE_MAIN_VARIANT (type);
3905 /* There really should be only one main variant among any group of variants
3906 of a given type (and all of the MAIN_VARIANT values for all members of
3907 the group should point to that one type) but sometimes the C front-end
3908 messes this up for array types, so we work around that bug here. */
3910 if (TREE_CODE (type) == ARRAY_TYPE)
3911 while (type != TYPE_MAIN_VARIANT (type))
3912 type = TYPE_MAIN_VARIANT (type);
3914 return type;
3917 /* Return non-zero if the given type node represents a tagged type. */
3919 static inline int
3920 is_tagged_type (type)
3921 register tree type;
3923 register enum tree_code code = TREE_CODE (type);
3925 return (code == RECORD_TYPE || code == UNION_TYPE
3926 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3929 /* Convert a DIE tag into its string name. */
3931 static const char *
3932 dwarf_tag_name (tag)
3933 register unsigned tag;
3935 switch (tag)
3937 case DW_TAG_padding:
3938 return "DW_TAG_padding";
3939 case DW_TAG_array_type:
3940 return "DW_TAG_array_type";
3941 case DW_TAG_class_type:
3942 return "DW_TAG_class_type";
3943 case DW_TAG_entry_point:
3944 return "DW_TAG_entry_point";
3945 case DW_TAG_enumeration_type:
3946 return "DW_TAG_enumeration_type";
3947 case DW_TAG_formal_parameter:
3948 return "DW_TAG_formal_parameter";
3949 case DW_TAG_imported_declaration:
3950 return "DW_TAG_imported_declaration";
3951 case DW_TAG_label:
3952 return "DW_TAG_label";
3953 case DW_TAG_lexical_block:
3954 return "DW_TAG_lexical_block";
3955 case DW_TAG_member:
3956 return "DW_TAG_member";
3957 case DW_TAG_pointer_type:
3958 return "DW_TAG_pointer_type";
3959 case DW_TAG_reference_type:
3960 return "DW_TAG_reference_type";
3961 case DW_TAG_compile_unit:
3962 return "DW_TAG_compile_unit";
3963 case DW_TAG_string_type:
3964 return "DW_TAG_string_type";
3965 case DW_TAG_structure_type:
3966 return "DW_TAG_structure_type";
3967 case DW_TAG_subroutine_type:
3968 return "DW_TAG_subroutine_type";
3969 case DW_TAG_typedef:
3970 return "DW_TAG_typedef";
3971 case DW_TAG_union_type:
3972 return "DW_TAG_union_type";
3973 case DW_TAG_unspecified_parameters:
3974 return "DW_TAG_unspecified_parameters";
3975 case DW_TAG_variant:
3976 return "DW_TAG_variant";
3977 case DW_TAG_common_block:
3978 return "DW_TAG_common_block";
3979 case DW_TAG_common_inclusion:
3980 return "DW_TAG_common_inclusion";
3981 case DW_TAG_inheritance:
3982 return "DW_TAG_inheritance";
3983 case DW_TAG_inlined_subroutine:
3984 return "DW_TAG_inlined_subroutine";
3985 case DW_TAG_module:
3986 return "DW_TAG_module";
3987 case DW_TAG_ptr_to_member_type:
3988 return "DW_TAG_ptr_to_member_type";
3989 case DW_TAG_set_type:
3990 return "DW_TAG_set_type";
3991 case DW_TAG_subrange_type:
3992 return "DW_TAG_subrange_type";
3993 case DW_TAG_with_stmt:
3994 return "DW_TAG_with_stmt";
3995 case DW_TAG_access_declaration:
3996 return "DW_TAG_access_declaration";
3997 case DW_TAG_base_type:
3998 return "DW_TAG_base_type";
3999 case DW_TAG_catch_block:
4000 return "DW_TAG_catch_block";
4001 case DW_TAG_const_type:
4002 return "DW_TAG_const_type";
4003 case DW_TAG_constant:
4004 return "DW_TAG_constant";
4005 case DW_TAG_enumerator:
4006 return "DW_TAG_enumerator";
4007 case DW_TAG_file_type:
4008 return "DW_TAG_file_type";
4009 case DW_TAG_friend:
4010 return "DW_TAG_friend";
4011 case DW_TAG_namelist:
4012 return "DW_TAG_namelist";
4013 case DW_TAG_namelist_item:
4014 return "DW_TAG_namelist_item";
4015 case DW_TAG_packed_type:
4016 return "DW_TAG_packed_type";
4017 case DW_TAG_subprogram:
4018 return "DW_TAG_subprogram";
4019 case DW_TAG_template_type_param:
4020 return "DW_TAG_template_type_param";
4021 case DW_TAG_template_value_param:
4022 return "DW_TAG_template_value_param";
4023 case DW_TAG_thrown_type:
4024 return "DW_TAG_thrown_type";
4025 case DW_TAG_try_block:
4026 return "DW_TAG_try_block";
4027 case DW_TAG_variant_part:
4028 return "DW_TAG_variant_part";
4029 case DW_TAG_variable:
4030 return "DW_TAG_variable";
4031 case DW_TAG_volatile_type:
4032 return "DW_TAG_volatile_type";
4033 case DW_TAG_MIPS_loop:
4034 return "DW_TAG_MIPS_loop";
4035 case DW_TAG_format_label:
4036 return "DW_TAG_format_label";
4037 case DW_TAG_function_template:
4038 return "DW_TAG_function_template";
4039 case DW_TAG_class_template:
4040 return "DW_TAG_class_template";
4041 case DW_TAG_GNU_BINCL:
4042 return "DW_TAG_GNU_BINCL";
4043 case DW_TAG_GNU_EINCL:
4044 return "DW_TAG_GNU_EINCL";
4045 default:
4046 return "DW_TAG_<unknown>";
4050 /* Convert a DWARF attribute code into its string name. */
4052 static const char *
4053 dwarf_attr_name (attr)
4054 register unsigned attr;
4056 switch (attr)
4058 case DW_AT_sibling:
4059 return "DW_AT_sibling";
4060 case DW_AT_location:
4061 return "DW_AT_location";
4062 case DW_AT_name:
4063 return "DW_AT_name";
4064 case DW_AT_ordering:
4065 return "DW_AT_ordering";
4066 case DW_AT_subscr_data:
4067 return "DW_AT_subscr_data";
4068 case DW_AT_byte_size:
4069 return "DW_AT_byte_size";
4070 case DW_AT_bit_offset:
4071 return "DW_AT_bit_offset";
4072 case DW_AT_bit_size:
4073 return "DW_AT_bit_size";
4074 case DW_AT_element_list:
4075 return "DW_AT_element_list";
4076 case DW_AT_stmt_list:
4077 return "DW_AT_stmt_list";
4078 case DW_AT_low_pc:
4079 return "DW_AT_low_pc";
4080 case DW_AT_high_pc:
4081 return "DW_AT_high_pc";
4082 case DW_AT_language:
4083 return "DW_AT_language";
4084 case DW_AT_member:
4085 return "DW_AT_member";
4086 case DW_AT_discr:
4087 return "DW_AT_discr";
4088 case DW_AT_discr_value:
4089 return "DW_AT_discr_value";
4090 case DW_AT_visibility:
4091 return "DW_AT_visibility";
4092 case DW_AT_import:
4093 return "DW_AT_import";
4094 case DW_AT_string_length:
4095 return "DW_AT_string_length";
4096 case DW_AT_common_reference:
4097 return "DW_AT_common_reference";
4098 case DW_AT_comp_dir:
4099 return "DW_AT_comp_dir";
4100 case DW_AT_const_value:
4101 return "DW_AT_const_value";
4102 case DW_AT_containing_type:
4103 return "DW_AT_containing_type";
4104 case DW_AT_default_value:
4105 return "DW_AT_default_value";
4106 case DW_AT_inline:
4107 return "DW_AT_inline";
4108 case DW_AT_is_optional:
4109 return "DW_AT_is_optional";
4110 case DW_AT_lower_bound:
4111 return "DW_AT_lower_bound";
4112 case DW_AT_producer:
4113 return "DW_AT_producer";
4114 case DW_AT_prototyped:
4115 return "DW_AT_prototyped";
4116 case DW_AT_return_addr:
4117 return "DW_AT_return_addr";
4118 case DW_AT_start_scope:
4119 return "DW_AT_start_scope";
4120 case DW_AT_stride_size:
4121 return "DW_AT_stride_size";
4122 case DW_AT_upper_bound:
4123 return "DW_AT_upper_bound";
4124 case DW_AT_abstract_origin:
4125 return "DW_AT_abstract_origin";
4126 case DW_AT_accessibility:
4127 return "DW_AT_accessibility";
4128 case DW_AT_address_class:
4129 return "DW_AT_address_class";
4130 case DW_AT_artificial:
4131 return "DW_AT_artificial";
4132 case DW_AT_base_types:
4133 return "DW_AT_base_types";
4134 case DW_AT_calling_convention:
4135 return "DW_AT_calling_convention";
4136 case DW_AT_count:
4137 return "DW_AT_count";
4138 case DW_AT_data_member_location:
4139 return "DW_AT_data_member_location";
4140 case DW_AT_decl_column:
4141 return "DW_AT_decl_column";
4142 case DW_AT_decl_file:
4143 return "DW_AT_decl_file";
4144 case DW_AT_decl_line:
4145 return "DW_AT_decl_line";
4146 case DW_AT_declaration:
4147 return "DW_AT_declaration";
4148 case DW_AT_discr_list:
4149 return "DW_AT_discr_list";
4150 case DW_AT_encoding:
4151 return "DW_AT_encoding";
4152 case DW_AT_external:
4153 return "DW_AT_external";
4154 case DW_AT_frame_base:
4155 return "DW_AT_frame_base";
4156 case DW_AT_friend:
4157 return "DW_AT_friend";
4158 case DW_AT_identifier_case:
4159 return "DW_AT_identifier_case";
4160 case DW_AT_macro_info:
4161 return "DW_AT_macro_info";
4162 case DW_AT_namelist_items:
4163 return "DW_AT_namelist_items";
4164 case DW_AT_priority:
4165 return "DW_AT_priority";
4166 case DW_AT_segment:
4167 return "DW_AT_segment";
4168 case DW_AT_specification:
4169 return "DW_AT_specification";
4170 case DW_AT_static_link:
4171 return "DW_AT_static_link";
4172 case DW_AT_type:
4173 return "DW_AT_type";
4174 case DW_AT_use_location:
4175 return "DW_AT_use_location";
4176 case DW_AT_variable_parameter:
4177 return "DW_AT_variable_parameter";
4178 case DW_AT_virtuality:
4179 return "DW_AT_virtuality";
4180 case DW_AT_vtable_elem_location:
4181 return "DW_AT_vtable_elem_location";
4183 case DW_AT_MIPS_fde:
4184 return "DW_AT_MIPS_fde";
4185 case DW_AT_MIPS_loop_begin:
4186 return "DW_AT_MIPS_loop_begin";
4187 case DW_AT_MIPS_tail_loop_begin:
4188 return "DW_AT_MIPS_tail_loop_begin";
4189 case DW_AT_MIPS_epilog_begin:
4190 return "DW_AT_MIPS_epilog_begin";
4191 case DW_AT_MIPS_loop_unroll_factor:
4192 return "DW_AT_MIPS_loop_unroll_factor";
4193 case DW_AT_MIPS_software_pipeline_depth:
4194 return "DW_AT_MIPS_software_pipeline_depth";
4195 case DW_AT_MIPS_linkage_name:
4196 return "DW_AT_MIPS_linkage_name";
4197 case DW_AT_MIPS_stride:
4198 return "DW_AT_MIPS_stride";
4199 case DW_AT_MIPS_abstract_name:
4200 return "DW_AT_MIPS_abstract_name";
4201 case DW_AT_MIPS_clone_origin:
4202 return "DW_AT_MIPS_clone_origin";
4203 case DW_AT_MIPS_has_inlines:
4204 return "DW_AT_MIPS_has_inlines";
4206 case DW_AT_sf_names:
4207 return "DW_AT_sf_names";
4208 case DW_AT_src_info:
4209 return "DW_AT_src_info";
4210 case DW_AT_mac_info:
4211 return "DW_AT_mac_info";
4212 case DW_AT_src_coords:
4213 return "DW_AT_src_coords";
4214 case DW_AT_body_begin:
4215 return "DW_AT_body_begin";
4216 case DW_AT_body_end:
4217 return "DW_AT_body_end";
4218 default:
4219 return "DW_AT_<unknown>";
4223 /* Convert a DWARF value form code into its string name. */
4225 static const char *
4226 dwarf_form_name (form)
4227 register unsigned form;
4229 switch (form)
4231 case DW_FORM_addr:
4232 return "DW_FORM_addr";
4233 case DW_FORM_block2:
4234 return "DW_FORM_block2";
4235 case DW_FORM_block4:
4236 return "DW_FORM_block4";
4237 case DW_FORM_data2:
4238 return "DW_FORM_data2";
4239 case DW_FORM_data4:
4240 return "DW_FORM_data4";
4241 case DW_FORM_data8:
4242 return "DW_FORM_data8";
4243 case DW_FORM_string:
4244 return "DW_FORM_string";
4245 case DW_FORM_block:
4246 return "DW_FORM_block";
4247 case DW_FORM_block1:
4248 return "DW_FORM_block1";
4249 case DW_FORM_data1:
4250 return "DW_FORM_data1";
4251 case DW_FORM_flag:
4252 return "DW_FORM_flag";
4253 case DW_FORM_sdata:
4254 return "DW_FORM_sdata";
4255 case DW_FORM_strp:
4256 return "DW_FORM_strp";
4257 case DW_FORM_udata:
4258 return "DW_FORM_udata";
4259 case DW_FORM_ref_addr:
4260 return "DW_FORM_ref_addr";
4261 case DW_FORM_ref1:
4262 return "DW_FORM_ref1";
4263 case DW_FORM_ref2:
4264 return "DW_FORM_ref2";
4265 case DW_FORM_ref4:
4266 return "DW_FORM_ref4";
4267 case DW_FORM_ref8:
4268 return "DW_FORM_ref8";
4269 case DW_FORM_ref_udata:
4270 return "DW_FORM_ref_udata";
4271 case DW_FORM_indirect:
4272 return "DW_FORM_indirect";
4273 default:
4274 return "DW_FORM_<unknown>";
4278 /* Convert a DWARF type code into its string name. */
4280 #if 0
4281 static const char *
4282 dwarf_type_encoding_name (enc)
4283 register unsigned enc;
4285 switch (enc)
4287 case DW_ATE_address:
4288 return "DW_ATE_address";
4289 case DW_ATE_boolean:
4290 return "DW_ATE_boolean";
4291 case DW_ATE_complex_float:
4292 return "DW_ATE_complex_float";
4293 case DW_ATE_float:
4294 return "DW_ATE_float";
4295 case DW_ATE_signed:
4296 return "DW_ATE_signed";
4297 case DW_ATE_signed_char:
4298 return "DW_ATE_signed_char";
4299 case DW_ATE_unsigned:
4300 return "DW_ATE_unsigned";
4301 case DW_ATE_unsigned_char:
4302 return "DW_ATE_unsigned_char";
4303 default:
4304 return "DW_ATE_<unknown>";
4307 #endif
4309 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4310 instance of an inlined instance of a decl which is local to an inline
4311 function, so we have to trace all of the way back through the origin chain
4312 to find out what sort of node actually served as the original seed for the
4313 given block. */
4315 static tree
4316 decl_ultimate_origin (decl)
4317 register tree decl;
4319 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4320 nodes in the function to point to themselves; ignore that if
4321 we're trying to output the abstract instance of this function. */
4322 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4323 return NULL_TREE;
4325 #ifdef ENABLE_CHECKING
4326 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4327 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4328 most distant ancestor, this should never happen. */
4329 abort ();
4330 #endif
4332 return DECL_ABSTRACT_ORIGIN (decl);
4335 /* Determine the "ultimate origin" of a block. The block may be an inlined
4336 instance of an inlined instance of a block which is local to an inline
4337 function, so we have to trace all of the way back through the origin chain
4338 to find out what sort of node actually served as the original seed for the
4339 given block. */
4341 static tree
4342 block_ultimate_origin (block)
4343 register tree block;
4345 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4347 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4348 nodes in the function to point to themselves; ignore that if
4349 we're trying to output the abstract instance of this function. */
4350 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4351 return NULL_TREE;
4353 if (immediate_origin == NULL_TREE)
4354 return NULL_TREE;
4355 else
4357 register tree ret_val;
4358 register tree lookahead = immediate_origin;
4362 ret_val = lookahead;
4363 lookahead = (TREE_CODE (ret_val) == BLOCK)
4364 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4365 : NULL;
4367 while (lookahead != NULL && lookahead != ret_val);
4369 return ret_val;
4373 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4374 of a virtual function may refer to a base class, so we check the 'this'
4375 parameter. */
4377 static tree
4378 decl_class_context (decl)
4379 tree decl;
4381 tree context = NULL_TREE;
4383 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4384 context = DECL_CONTEXT (decl);
4385 else
4386 context = TYPE_MAIN_VARIANT
4387 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4389 if (context && !TYPE_P (context))
4390 context = NULL_TREE;
4392 return context;
4395 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4396 addition order, and correct that in reverse_all_dies. */
4398 static inline void
4399 add_dwarf_attr (die, attr)
4400 register dw_die_ref die;
4401 register dw_attr_ref attr;
4403 if (die != NULL && attr != NULL)
4405 attr->dw_attr_next = die->die_attr;
4406 die->die_attr = attr;
4410 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4411 static inline dw_val_class
4412 AT_class (a)
4413 dw_attr_ref a;
4415 return a->dw_attr_val.val_class;
4418 /* Add a flag value attribute to a DIE. */
4420 static inline void
4421 add_AT_flag (die, attr_kind, flag)
4422 register dw_die_ref die;
4423 register enum dwarf_attribute attr_kind;
4424 register unsigned flag;
4426 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4428 attr->dw_attr_next = NULL;
4429 attr->dw_attr = attr_kind;
4430 attr->dw_attr_val.val_class = dw_val_class_flag;
4431 attr->dw_attr_val.v.val_flag = flag;
4432 add_dwarf_attr (die, attr);
4435 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4436 static inline unsigned
4437 AT_flag (a)
4438 register dw_attr_ref a;
4440 if (a && AT_class (a) == dw_val_class_flag)
4441 return a->dw_attr_val.v.val_flag;
4443 abort ();
4446 /* Add a signed integer attribute value to a DIE. */
4448 static inline void
4449 add_AT_int (die, attr_kind, int_val)
4450 register dw_die_ref die;
4451 register enum dwarf_attribute attr_kind;
4452 register long int int_val;
4454 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4456 attr->dw_attr_next = NULL;
4457 attr->dw_attr = attr_kind;
4458 attr->dw_attr_val.val_class = dw_val_class_const;
4459 attr->dw_attr_val.v.val_int = int_val;
4460 add_dwarf_attr (die, attr);
4463 static inline long int AT_int PARAMS ((dw_attr_ref));
4464 static inline long int
4465 AT_int (a)
4466 register dw_attr_ref a;
4468 if (a && AT_class (a) == dw_val_class_const)
4469 return a->dw_attr_val.v.val_int;
4471 abort ();
4474 /* Add an unsigned integer attribute value to a DIE. */
4476 static inline void
4477 add_AT_unsigned (die, attr_kind, unsigned_val)
4478 register dw_die_ref die;
4479 register enum dwarf_attribute attr_kind;
4480 register unsigned long unsigned_val;
4482 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4484 attr->dw_attr_next = NULL;
4485 attr->dw_attr = attr_kind;
4486 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4487 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4488 add_dwarf_attr (die, attr);
4491 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4492 static inline unsigned long
4493 AT_unsigned (a)
4494 register dw_attr_ref a;
4496 if (a && AT_class (a) == dw_val_class_unsigned_const)
4497 return a->dw_attr_val.v.val_unsigned;
4499 abort ();
4502 /* Add an unsigned double integer attribute value to a DIE. */
4504 static inline void
4505 add_AT_long_long (die, attr_kind, val_hi, val_low)
4506 register dw_die_ref die;
4507 register enum dwarf_attribute attr_kind;
4508 register unsigned long val_hi;
4509 register unsigned long val_low;
4511 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4513 attr->dw_attr_next = NULL;
4514 attr->dw_attr = attr_kind;
4515 attr->dw_attr_val.val_class = dw_val_class_long_long;
4516 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4517 attr->dw_attr_val.v.val_long_long.low = val_low;
4518 add_dwarf_attr (die, attr);
4521 /* Add a floating point attribute value to a DIE and return it. */
4523 static inline void
4524 add_AT_float (die, attr_kind, length, array)
4525 register dw_die_ref die;
4526 register enum dwarf_attribute attr_kind;
4527 register unsigned length;
4528 register long *array;
4530 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4532 attr->dw_attr_next = NULL;
4533 attr->dw_attr = attr_kind;
4534 attr->dw_attr_val.val_class = dw_val_class_float;
4535 attr->dw_attr_val.v.val_float.length = length;
4536 attr->dw_attr_val.v.val_float.array = array;
4537 add_dwarf_attr (die, attr);
4540 /* Add a string attribute value to a DIE. */
4542 static inline void
4543 add_AT_string (die, attr_kind, str)
4544 register dw_die_ref die;
4545 register enum dwarf_attribute attr_kind;
4546 register const char *str;
4548 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4550 attr->dw_attr_next = NULL;
4551 attr->dw_attr = attr_kind;
4552 attr->dw_attr_val.val_class = dw_val_class_str;
4553 attr->dw_attr_val.v.val_str = xstrdup (str);
4554 add_dwarf_attr (die, attr);
4557 static inline const char *AT_string PARAMS ((dw_attr_ref));
4558 static inline const char *
4559 AT_string (a)
4560 register dw_attr_ref a;
4562 if (a && AT_class (a) == dw_val_class_str)
4563 return a->dw_attr_val.v.val_str;
4565 abort ();
4568 /* Add a DIE reference attribute value to a DIE. */
4570 static inline void
4571 add_AT_die_ref (die, attr_kind, targ_die)
4572 register dw_die_ref die;
4573 register enum dwarf_attribute attr_kind;
4574 register dw_die_ref targ_die;
4576 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4578 attr->dw_attr_next = NULL;
4579 attr->dw_attr = attr_kind;
4580 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4581 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4582 attr->dw_attr_val.v.val_die_ref.external = 0;
4583 add_dwarf_attr (die, attr);
4586 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4587 static inline dw_die_ref
4588 AT_ref (a)
4589 register dw_attr_ref a;
4591 if (a && AT_class (a) == dw_val_class_die_ref)
4592 return a->dw_attr_val.v.val_die_ref.die;
4594 abort ();
4597 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4598 static inline int
4599 AT_ref_external (a)
4600 register dw_attr_ref a;
4602 if (a && AT_class (a) == dw_val_class_die_ref)
4603 return a->dw_attr_val.v.val_die_ref.external;
4605 return 0;
4608 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4609 static inline void
4610 set_AT_ref_external (a, i)
4611 register dw_attr_ref a;
4612 int i;
4614 if (a && AT_class (a) == dw_val_class_die_ref)
4615 a->dw_attr_val.v.val_die_ref.external = i;
4616 else
4617 abort ();
4620 /* Add an FDE reference attribute value to a DIE. */
4622 static inline void
4623 add_AT_fde_ref (die, attr_kind, targ_fde)
4624 register dw_die_ref die;
4625 register enum dwarf_attribute attr_kind;
4626 register unsigned targ_fde;
4628 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4630 attr->dw_attr_next = NULL;
4631 attr->dw_attr = attr_kind;
4632 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4633 attr->dw_attr_val.v.val_fde_index = targ_fde;
4634 add_dwarf_attr (die, attr);
4637 /* Add a location description attribute value to a DIE. */
4639 static inline void
4640 add_AT_loc (die, attr_kind, loc)
4641 register dw_die_ref die;
4642 register enum dwarf_attribute attr_kind;
4643 register dw_loc_descr_ref loc;
4645 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4647 attr->dw_attr_next = NULL;
4648 attr->dw_attr = attr_kind;
4649 attr->dw_attr_val.val_class = dw_val_class_loc;
4650 attr->dw_attr_val.v.val_loc = loc;
4651 add_dwarf_attr (die, attr);
4654 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4655 static inline dw_loc_descr_ref
4656 AT_loc (a)
4657 register dw_attr_ref a;
4659 if (a && AT_class (a) == dw_val_class_loc)
4660 return a->dw_attr_val.v.val_loc;
4662 abort ();
4665 /* Add an address constant attribute value to a DIE. */
4667 static inline void
4668 add_AT_addr (die, attr_kind, addr)
4669 register dw_die_ref die;
4670 register enum dwarf_attribute attr_kind;
4671 rtx addr;
4673 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4675 attr->dw_attr_next = NULL;
4676 attr->dw_attr = attr_kind;
4677 attr->dw_attr_val.val_class = dw_val_class_addr;
4678 attr->dw_attr_val.v.val_addr = addr;
4679 add_dwarf_attr (die, attr);
4682 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4683 static inline rtx
4684 AT_addr (a)
4685 register dw_attr_ref a;
4687 if (a && AT_class (a) == dw_val_class_addr)
4688 return a->dw_attr_val.v.val_addr;
4690 abort ();
4693 /* Add a label identifier attribute value to a DIE. */
4695 static inline void
4696 add_AT_lbl_id (die, attr_kind, lbl_id)
4697 register dw_die_ref die;
4698 register enum dwarf_attribute attr_kind;
4699 register const char *lbl_id;
4701 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4703 attr->dw_attr_next = NULL;
4704 attr->dw_attr = attr_kind;
4705 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4706 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4707 add_dwarf_attr (die, attr);
4710 /* Add a section offset attribute value to a DIE. */
4712 static inline void
4713 add_AT_lbl_offset (die, attr_kind, label)
4714 register dw_die_ref die;
4715 register enum dwarf_attribute attr_kind;
4716 register const char *label;
4718 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4720 attr->dw_attr_next = NULL;
4721 attr->dw_attr = attr_kind;
4722 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4723 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4724 add_dwarf_attr (die, attr);
4727 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4728 static inline const char *
4729 AT_lbl (a)
4730 register dw_attr_ref a;
4732 if (a && (AT_class (a) == dw_val_class_lbl_id
4733 || AT_class (a) == dw_val_class_lbl_offset))
4734 return a->dw_attr_val.v.val_lbl_id;
4736 abort ();
4739 /* Get the attribute of type attr_kind. */
4741 static inline dw_attr_ref
4742 get_AT (die, attr_kind)
4743 register dw_die_ref die;
4744 register enum dwarf_attribute attr_kind;
4746 register dw_attr_ref a;
4747 register dw_die_ref spec = NULL;
4749 if (die != NULL)
4751 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4753 if (a->dw_attr == attr_kind)
4754 return a;
4756 if (a->dw_attr == DW_AT_specification
4757 || a->dw_attr == DW_AT_abstract_origin)
4758 spec = AT_ref (a);
4761 if (spec)
4762 return get_AT (spec, attr_kind);
4765 return NULL;
4768 /* Return the "low pc" attribute value, typically associated with
4769 a subprogram DIE. Return null if the "low pc" attribute is
4770 either not prsent, or if it cannot be represented as an
4771 assembler label identifier. */
4773 static inline const char *
4774 get_AT_low_pc (die)
4775 register dw_die_ref die;
4777 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4778 return a ? AT_lbl (a) : NULL;
4781 /* Return the "high pc" attribute value, typically associated with
4782 a subprogram DIE. Return null if the "high pc" attribute is
4783 either not prsent, or if it cannot be represented as an
4784 assembler label identifier. */
4786 static inline const char *
4787 get_AT_hi_pc (die)
4788 register dw_die_ref die;
4790 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4791 return a ? AT_lbl (a) : NULL;
4794 /* Return the value of the string attribute designated by ATTR_KIND, or
4795 NULL if it is not present. */
4797 static inline const char *
4798 get_AT_string (die, attr_kind)
4799 register dw_die_ref die;
4800 register enum dwarf_attribute attr_kind;
4802 register dw_attr_ref a = get_AT (die, attr_kind);
4803 return a ? AT_string (a) : NULL;
4806 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4807 if it is not present. */
4809 static inline int
4810 get_AT_flag (die, attr_kind)
4811 register dw_die_ref die;
4812 register enum dwarf_attribute attr_kind;
4814 register dw_attr_ref a = get_AT (die, attr_kind);
4815 return a ? AT_flag (a) : 0;
4818 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4819 if it is not present. */
4821 static inline unsigned
4822 get_AT_unsigned (die, attr_kind)
4823 register dw_die_ref die;
4824 register enum dwarf_attribute attr_kind;
4826 register dw_attr_ref a = get_AT (die, attr_kind);
4827 return a ? AT_unsigned (a) : 0;
4830 static inline dw_die_ref
4831 get_AT_ref (die, attr_kind)
4832 dw_die_ref die;
4833 register enum dwarf_attribute attr_kind;
4835 register dw_attr_ref a = get_AT (die, attr_kind);
4836 return a ? AT_ref (a) : NULL;
4839 static inline int
4840 is_c_family ()
4842 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4844 return (lang == DW_LANG_C || lang == DW_LANG_C89
4845 || lang == DW_LANG_C_plus_plus);
4848 static inline int
4849 is_fortran ()
4851 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4853 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4856 static inline int
4857 is_java ()
4859 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4861 return (lang == DW_LANG_Java);
4864 /* Free up the memory used by A. */
4866 static inline void free_AT PARAMS ((dw_attr_ref));
4867 static inline void
4868 free_AT (a)
4869 dw_attr_ref a;
4871 switch (AT_class (a))
4873 case dw_val_class_str:
4874 case dw_val_class_lbl_id:
4875 case dw_val_class_lbl_offset:
4876 free (a->dw_attr_val.v.val_str);
4877 break;
4879 case dw_val_class_float:
4880 free (a->dw_attr_val.v.val_float.array);
4881 break;
4883 default:
4884 break;
4887 free (a);
4890 /* Remove the specified attribute if present. */
4892 static void
4893 remove_AT (die, attr_kind)
4894 register dw_die_ref die;
4895 register enum dwarf_attribute attr_kind;
4897 register dw_attr_ref *p;
4898 register dw_attr_ref removed = NULL;
4900 if (die != NULL)
4902 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4903 if ((*p)->dw_attr == attr_kind)
4905 removed = *p;
4906 *p = (*p)->dw_attr_next;
4907 break;
4910 if (removed != 0)
4911 free_AT (removed);
4915 /* Free up the memory used by DIE. */
4917 static inline void free_die PARAMS ((dw_die_ref));
4918 static inline void
4919 free_die (die)
4920 dw_die_ref die;
4922 remove_children (die);
4923 free (die);
4926 /* Discard the children of this DIE. */
4928 static void
4929 remove_children (die)
4930 register dw_die_ref die;
4932 register dw_die_ref child_die = die->die_child;
4934 die->die_child = NULL;
4936 while (child_die != NULL)
4938 register dw_die_ref tmp_die = child_die;
4939 register dw_attr_ref a;
4941 child_die = child_die->die_sib;
4943 for (a = tmp_die->die_attr; a != NULL;)
4945 register dw_attr_ref tmp_a = a;
4947 a = a->dw_attr_next;
4948 free_AT (tmp_a);
4951 free_die (tmp_die);
4955 /* Add a child DIE below its parent. We build the lists up in reverse
4956 addition order, and correct that in reverse_all_dies. */
4958 static inline void
4959 add_child_die (die, child_die)
4960 register dw_die_ref die;
4961 register dw_die_ref child_die;
4963 if (die != NULL && child_die != NULL)
4965 if (die == child_die)
4966 abort ();
4967 child_die->die_parent = die;
4968 child_die->die_sib = die->die_child;
4969 die->die_child = child_die;
4973 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4974 is the specification, to the front of PARENT's list of children. */
4976 static void
4977 splice_child_die (parent, child)
4978 dw_die_ref parent, child;
4980 dw_die_ref *p;
4982 /* We want the declaration DIE from inside the class, not the
4983 specification DIE at toplevel. */
4984 if (child->die_parent != parent)
4986 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4987 if (tmp)
4988 child = tmp;
4991 if (child->die_parent != parent
4992 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4993 abort ();
4995 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4996 if (*p == child)
4998 *p = child->die_sib;
4999 break;
5002 child->die_sib = parent->die_child;
5003 parent->die_child = child;
5006 /* Return a pointer to a newly created DIE node. */
5008 static inline dw_die_ref
5009 new_die (tag_value, parent_die)
5010 register enum dwarf_tag tag_value;
5011 register dw_die_ref parent_die;
5013 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
5015 die->die_tag = tag_value;
5017 if (parent_die != NULL)
5018 add_child_die (parent_die, die);
5019 else
5021 limbo_die_node *limbo_node;
5023 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
5024 limbo_node->die = die;
5025 limbo_node->next = limbo_die_list;
5026 limbo_die_list = limbo_node;
5029 return die;
5032 /* Return the DIE associated with the given type specifier. */
5034 static inline dw_die_ref
5035 lookup_type_die (type)
5036 register tree type;
5038 if (TREE_CODE (type) == VECTOR_TYPE)
5039 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
5040 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
5043 /* Equate a DIE to a given type specifier. */
5045 static inline void
5046 equate_type_number_to_die (type, type_die)
5047 register tree type;
5048 register dw_die_ref type_die;
5050 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
5053 /* Return the DIE associated with a given declaration. */
5055 static inline dw_die_ref
5056 lookup_decl_die (decl)
5057 register tree decl;
5059 register unsigned decl_id = DECL_UID (decl);
5061 return (decl_id < decl_die_table_in_use
5062 ? decl_die_table[decl_id] : NULL);
5065 /* Equate a DIE to a particular declaration. */
5067 static void
5068 equate_decl_number_to_die (decl, decl_die)
5069 register tree decl;
5070 register dw_die_ref decl_die;
5072 register unsigned decl_id = DECL_UID (decl);
5073 register unsigned num_allocated;
5075 if (decl_id >= decl_die_table_allocated)
5077 num_allocated
5078 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5079 / DECL_DIE_TABLE_INCREMENT)
5080 * DECL_DIE_TABLE_INCREMENT;
5082 decl_die_table
5083 = (dw_die_ref *) xrealloc (decl_die_table,
5084 sizeof (dw_die_ref) * num_allocated);
5086 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5087 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5088 decl_die_table_allocated = num_allocated;
5091 if (decl_id >= decl_die_table_in_use)
5092 decl_die_table_in_use = (decl_id + 1);
5094 decl_die_table[decl_id] = decl_die;
5097 /* Keep track of the number of spaces used to indent the
5098 output of the debugging routines that print the structure of
5099 the DIE internal representation. */
5100 static int print_indent;
5102 /* Indent the line the number of spaces given by print_indent. */
5104 static inline void
5105 print_spaces (outfile)
5106 FILE *outfile;
5108 fprintf (outfile, "%*s", print_indent, "");
5111 /* Print the information associated with a given DIE, and its children.
5112 This routine is a debugging aid only. */
5114 static void
5115 print_die (die, outfile)
5116 dw_die_ref die;
5117 FILE *outfile;
5119 register dw_attr_ref a;
5120 register dw_die_ref c;
5122 print_spaces (outfile);
5123 fprintf (outfile, "DIE %4lu: %s\n",
5124 die->die_offset, dwarf_tag_name (die->die_tag));
5125 print_spaces (outfile);
5126 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5127 fprintf (outfile, " offset: %lu\n", die->die_offset);
5129 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5131 print_spaces (outfile);
5132 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5134 switch (AT_class (a))
5136 case dw_val_class_addr:
5137 fprintf (outfile, "address");
5138 break;
5139 case dw_val_class_loc:
5140 fprintf (outfile, "location descriptor");
5141 break;
5142 case dw_val_class_const:
5143 fprintf (outfile, "%ld", AT_int (a));
5144 break;
5145 case dw_val_class_unsigned_const:
5146 fprintf (outfile, "%lu", AT_unsigned (a));
5147 break;
5148 case dw_val_class_long_long:
5149 fprintf (outfile, "constant (%lu,%lu)",
5150 a->dw_attr_val.v.val_long_long.hi,
5151 a->dw_attr_val.v.val_long_long.low);
5152 break;
5153 case dw_val_class_float:
5154 fprintf (outfile, "floating-point constant");
5155 break;
5156 case dw_val_class_flag:
5157 fprintf (outfile, "%u", AT_flag (a));
5158 break;
5159 case dw_val_class_die_ref:
5160 if (AT_ref (a) != NULL)
5162 if (AT_ref (a)->die_symbol)
5163 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5164 else
5165 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5167 else
5168 fprintf (outfile, "die -> <null>");
5169 break;
5170 case dw_val_class_lbl_id:
5171 case dw_val_class_lbl_offset:
5172 fprintf (outfile, "label: %s", AT_lbl (a));
5173 break;
5174 case dw_val_class_str:
5175 if (AT_string (a) != NULL)
5176 fprintf (outfile, "\"%s\"", AT_string (a));
5177 else
5178 fprintf (outfile, "<null>");
5179 break;
5180 default:
5181 break;
5184 fprintf (outfile, "\n");
5187 if (die->die_child != NULL)
5189 print_indent += 4;
5190 for (c = die->die_child; c != NULL; c = c->die_sib)
5191 print_die (c, outfile);
5193 print_indent -= 4;
5195 if (print_indent == 0)
5196 fprintf (outfile, "\n");
5199 /* Print the contents of the source code line number correspondence table.
5200 This routine is a debugging aid only. */
5202 static void
5203 print_dwarf_line_table (outfile)
5204 FILE *outfile;
5206 register unsigned i;
5207 register dw_line_info_ref line_info;
5209 fprintf (outfile, "\n\nDWARF source line information\n");
5210 for (i = 1; i < line_info_table_in_use; ++i)
5212 line_info = &line_info_table[i];
5213 fprintf (outfile, "%5d: ", i);
5214 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5215 fprintf (outfile, "%6ld", line_info->dw_line_num);
5216 fprintf (outfile, "\n");
5219 fprintf (outfile, "\n\n");
5222 /* Print the information collected for a given DIE. */
5224 void
5225 debug_dwarf_die (die)
5226 dw_die_ref die;
5228 print_die (die, stderr);
5231 /* Print all DWARF information collected for the compilation unit.
5232 This routine is a debugging aid only. */
5234 void
5235 debug_dwarf ()
5237 print_indent = 0;
5238 print_die (comp_unit_die, stderr);
5239 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5240 print_dwarf_line_table (stderr);
5243 /* We build up the lists of children and attributes by pushing new ones
5244 onto the beginning of the list. Reverse the lists for DIE so that
5245 they are in order of addition. */
5247 static void
5248 reverse_die_lists (die)
5249 register dw_die_ref die;
5251 register dw_die_ref c, cp, cn;
5252 register dw_attr_ref a, ap, an;
5254 for (a = die->die_attr, ap = 0; a; a = an)
5256 an = a->dw_attr_next;
5257 a->dw_attr_next = ap;
5258 ap = a;
5260 die->die_attr = ap;
5262 for (c = die->die_child, cp = 0; c; c = cn)
5264 cn = c->die_sib;
5265 c->die_sib = cp;
5266 cp = c;
5268 die->die_child = cp;
5271 /* reverse_die_lists only reverses the single die you pass it. Since
5272 we used to reverse all dies in add_sibling_attributes, which runs
5273 through all the dies, it would reverse all the dies. Now, however,
5274 since we don't call reverse_die_lists in add_sibling_attributes, we
5275 need a routine to recursively reverse all the dies. This is that
5276 routine. */
5278 static void
5279 reverse_all_dies (die)
5280 register dw_die_ref die;
5282 register dw_die_ref c;
5284 reverse_die_lists (die);
5286 for (c = die->die_child; c; c = c->die_sib)
5287 reverse_all_dies (c);
5290 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5291 the CU for the enclosing include file, if any. BINCL_DIE is the
5292 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5293 include file. */
5295 static dw_die_ref
5296 push_new_compile_unit (old_unit, bincl_die)
5297 dw_die_ref old_unit, bincl_die;
5299 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5300 dw_die_ref new_unit = gen_compile_unit_die (filename);
5301 new_unit->die_sib = old_unit;
5302 return new_unit;
5305 /* Close an include-file CU and reopen the enclosing one. */
5307 static dw_die_ref
5308 pop_compile_unit (old_unit)
5309 dw_die_ref old_unit;
5311 dw_die_ref new_unit = old_unit->die_sib;
5312 old_unit->die_sib = NULL;
5313 return new_unit;
5316 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5317 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5319 /* Calculate the checksum of a location expression. */
5321 static inline void
5322 loc_checksum (loc, ctx)
5323 dw_loc_descr_ref loc;
5324 struct md5_ctx *ctx;
5326 PROCESS (loc->dw_loc_opc);
5327 PROCESS (loc->dw_loc_oprnd1);
5328 PROCESS (loc->dw_loc_oprnd2);
5331 /* Calculate the checksum of an attribute. */
5333 static void
5334 attr_checksum (at, ctx)
5335 dw_attr_ref at;
5336 struct md5_ctx *ctx;
5338 dw_loc_descr_ref loc;
5339 rtx r;
5341 PROCESS (at->dw_attr);
5343 /* We don't care about differences in file numbering. */
5344 if (at->dw_attr == DW_AT_decl_file
5345 /* Or that this was compiled with a different compiler snapshot; if
5346 the output is the same, that's what matters. */
5347 || at->dw_attr == DW_AT_producer)
5348 return;
5350 switch (AT_class (at))
5352 case dw_val_class_const:
5353 PROCESS (at->dw_attr_val.v.val_int);
5354 break;
5355 case dw_val_class_unsigned_const:
5356 PROCESS (at->dw_attr_val.v.val_unsigned);
5357 break;
5358 case dw_val_class_long_long:
5359 PROCESS (at->dw_attr_val.v.val_long_long);
5360 break;
5361 case dw_val_class_float:
5362 PROCESS (at->dw_attr_val.v.val_float);
5363 break;
5364 case dw_val_class_flag:
5365 PROCESS (at->dw_attr_val.v.val_flag);
5366 break;
5368 case dw_val_class_str:
5369 PROCESS_STRING (AT_string (at));
5370 break;
5371 case dw_val_class_addr:
5372 r = AT_addr (at);
5373 switch (GET_CODE (r))
5375 case SYMBOL_REF:
5376 PROCESS_STRING (XSTR (r, 0));
5377 break;
5379 default:
5380 abort ();
5382 break;
5384 case dw_val_class_loc:
5385 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5386 loc_checksum (loc, ctx);
5387 break;
5389 case dw_val_class_die_ref:
5390 if (AT_ref (at)->die_offset)
5391 PROCESS (AT_ref (at)->die_offset);
5392 /* FIXME else use target die name or something. */
5394 case dw_val_class_fde_ref:
5395 case dw_val_class_lbl_id:
5396 case dw_val_class_lbl_offset:
5398 default:
5399 break;
5403 /* Calculate the checksum of a DIE. */
5405 static void
5406 die_checksum (die, ctx)
5407 dw_die_ref die;
5408 struct md5_ctx *ctx;
5410 dw_die_ref c;
5411 dw_attr_ref a;
5413 PROCESS (die->die_tag);
5415 for (a = die->die_attr; a; a = a->dw_attr_next)
5416 attr_checksum (a, ctx);
5418 for (c = die->die_child; c; c = c->die_sib)
5419 die_checksum (c, ctx);
5422 #undef PROCESS
5423 #undef PROCESS_STRING
5425 /* The prefix to attach to symbols on DIEs in the current comdat debug
5426 info section. */
5427 static char *comdat_symbol_id;
5429 /* The index of the current symbol within the current comdat CU. */
5430 static unsigned int comdat_symbol_number;
5432 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5433 children, and set comdat_symbol_id accordingly. */
5435 static void
5436 compute_section_prefix (unit_die)
5437 dw_die_ref unit_die;
5439 char *p, *name;
5440 int i;
5441 unsigned char checksum[16];
5442 struct md5_ctx ctx;
5444 md5_init_ctx (&ctx);
5445 die_checksum (unit_die, &ctx);
5446 md5_finish_ctx (&ctx, checksum);
5448 p = file_name_nondirectory (get_AT_string (unit_die, DW_AT_name));
5449 name = (char *) alloca (strlen (p) + 64);
5450 sprintf (name, "%s.", p);
5452 clean_symbol_name (name);
5454 p = name + strlen (name);
5455 for (i = 0; i < 4; ++i)
5457 sprintf (p, "%.2x", checksum[i]);
5458 p += 2;
5461 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5462 comdat_symbol_number = 0;
5465 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5467 static int
5468 is_type_die (die)
5469 dw_die_ref die;
5471 switch (die->die_tag)
5473 case DW_TAG_array_type:
5474 case DW_TAG_class_type:
5475 case DW_TAG_enumeration_type:
5476 case DW_TAG_pointer_type:
5477 case DW_TAG_reference_type:
5478 case DW_TAG_string_type:
5479 case DW_TAG_structure_type:
5480 case DW_TAG_subroutine_type:
5481 case DW_TAG_union_type:
5482 case DW_TAG_ptr_to_member_type:
5483 case DW_TAG_set_type:
5484 case DW_TAG_subrange_type:
5485 case DW_TAG_base_type:
5486 case DW_TAG_const_type:
5487 case DW_TAG_file_type:
5488 case DW_TAG_packed_type:
5489 case DW_TAG_volatile_type:
5490 return 1;
5491 default:
5492 return 0;
5496 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5497 Basically, we want to choose the bits that are likely to be shared between
5498 compilations (types) and leave out the bits that are specific to individual
5499 compilations (functions). */
5501 static int
5502 is_comdat_die (c)
5503 dw_die_ref c;
5505 #if 1
5506 /* I think we want to leave base types and __vtbl_ptr_type in the
5507 main CU, as we do for stabs. The advantage is a greater
5508 likelihood of sharing between objects that don't include headers
5509 in the same order (and therefore would put the base types in a
5510 different comdat). jason 8/28/00 */
5511 if (c->die_tag == DW_TAG_base_type)
5512 return 0;
5514 if (c->die_tag == DW_TAG_pointer_type
5515 || c->die_tag == DW_TAG_reference_type
5516 || c->die_tag == DW_TAG_const_type
5517 || c->die_tag == DW_TAG_volatile_type)
5519 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5520 return t ? is_comdat_die (t) : 0;
5522 #endif
5524 return is_type_die (c);
5527 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5528 compilation unit. */
5530 static int
5531 is_symbol_die (c)
5532 dw_die_ref c;
5534 if (is_type_die (c))
5535 return 1;
5536 if (get_AT (c, DW_AT_declaration)
5537 && ! get_AT (c, DW_AT_specification))
5538 return 1;
5539 return 0;
5542 static char *
5543 gen_internal_sym ()
5545 char buf[256];
5546 static int label_num;
5547 ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++);
5548 return xstrdup (buf);
5551 /* Assign symbols to all worthy DIEs under DIE. */
5553 static void
5554 assign_symbol_names (die)
5555 register dw_die_ref die;
5557 register dw_die_ref c;
5559 if (is_symbol_die (die))
5561 if (comdat_symbol_id)
5563 char *p = alloca (strlen (comdat_symbol_id) + 64);
5564 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5565 comdat_symbol_id, comdat_symbol_number++);
5566 die->die_symbol = xstrdup (p);
5568 else
5569 die->die_symbol = gen_internal_sym ();
5572 for (c = die->die_child; c != NULL; c = c->die_sib)
5573 assign_symbol_names (c);
5576 /* Traverse the DIE (which is always comp_unit_die), and set up
5577 additional compilation units for each of the include files we see
5578 bracketed by BINCL/EINCL. */
5580 static void
5581 break_out_includes (die)
5582 register dw_die_ref die;
5584 dw_die_ref *ptr;
5585 register dw_die_ref unit = NULL;
5586 limbo_die_node *node;
5588 for (ptr = &(die->die_child); *ptr; )
5590 register dw_die_ref c = *ptr;
5592 if (c->die_tag == DW_TAG_GNU_BINCL
5593 || c->die_tag == DW_TAG_GNU_EINCL
5594 || (unit && is_comdat_die (c)))
5596 /* This DIE is for a secondary CU; remove it from the main one. */
5597 *ptr = c->die_sib;
5599 if (c->die_tag == DW_TAG_GNU_BINCL)
5601 unit = push_new_compile_unit (unit, c);
5602 free_die (c);
5604 else if (c->die_tag == DW_TAG_GNU_EINCL)
5606 unit = pop_compile_unit (unit);
5607 free_die (c);
5609 else
5610 add_child_die (unit, c);
5612 else
5614 /* Leave this DIE in the main CU. */
5615 ptr = &(c->die_sib);
5616 continue;
5620 #if 0
5621 /* We can only use this in debugging, since the frontend doesn't check
5622 to make sure that we leave every include file we enter. */
5623 if (unit != NULL)
5624 abort ();
5625 #endif
5627 assign_symbol_names (die);
5628 for (node = limbo_die_list; node; node = node->next)
5630 compute_section_prefix (node->die);
5631 assign_symbol_names (node->die);
5635 /* Traverse the DIE and add a sibling attribute if it may have the
5636 effect of speeding up access to siblings. To save some space,
5637 avoid generating sibling attributes for DIE's without children. */
5639 static void
5640 add_sibling_attributes (die)
5641 register dw_die_ref die;
5643 register dw_die_ref c;
5645 if (die->die_tag != DW_TAG_compile_unit
5646 && die->die_sib && die->die_child != NULL)
5647 /* Add the sibling link to the front of the attribute list. */
5648 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5650 for (c = die->die_child; c != NULL; c = c->die_sib)
5651 add_sibling_attributes (c);
5654 /* The format of each DIE (and its attribute value pairs)
5655 is encoded in an abbreviation table. This routine builds the
5656 abbreviation table and assigns a unique abbreviation id for
5657 each abbreviation entry. The children of each die are visited
5658 recursively. */
5660 static void
5661 build_abbrev_table (die)
5662 register dw_die_ref die;
5664 register unsigned long abbrev_id;
5665 register unsigned long n_alloc;
5666 register dw_die_ref c;
5667 register dw_attr_ref d_attr, a_attr;
5669 /* Scan the DIE references, and mark as external any that refer to
5670 DIEs from other CUs (i.e. those which are not marked). */
5671 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5673 if (AT_class (d_attr) == dw_val_class_die_ref
5674 && AT_ref (d_attr)->die_mark == 0)
5676 if (AT_ref (d_attr)->die_symbol == 0)
5677 abort ();
5678 set_AT_ref_external (d_attr, 1);
5682 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5684 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5686 if (abbrev->die_tag == die->die_tag)
5688 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5690 a_attr = abbrev->die_attr;
5691 d_attr = die->die_attr;
5693 while (a_attr != NULL && d_attr != NULL)
5695 if ((a_attr->dw_attr != d_attr->dw_attr)
5696 || (value_format (a_attr) != value_format (d_attr)))
5697 break;
5699 a_attr = a_attr->dw_attr_next;
5700 d_attr = d_attr->dw_attr_next;
5703 if (a_attr == NULL && d_attr == NULL)
5704 break;
5709 if (abbrev_id >= abbrev_die_table_in_use)
5711 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5713 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5714 abbrev_die_table
5715 = (dw_die_ref *) xrealloc (abbrev_die_table,
5716 sizeof (dw_die_ref) * n_alloc);
5718 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5719 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5720 abbrev_die_table_allocated = n_alloc;
5723 ++abbrev_die_table_in_use;
5724 abbrev_die_table[abbrev_id] = die;
5727 die->die_abbrev = abbrev_id;
5728 for (c = die->die_child; c != NULL; c = c->die_sib)
5729 build_abbrev_table (c);
5732 /* Return the size of a string, including the null byte.
5734 This used to treat backslashes as escapes, and hence they were not included
5735 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5736 which treats a backslash as a backslash, escaping it if necessary, and hence
5737 we must include them in the count. */
5739 static unsigned long
5740 size_of_string (str)
5741 register const char *str;
5743 return strlen (str) + 1;
5746 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5748 static int
5749 constant_size (value)
5750 long unsigned value;
5752 int log;
5754 if (value == 0)
5755 log = 0;
5756 else
5757 log = floor_log2 (value);
5759 log = log / 8;
5760 log = 1 << (floor_log2 (log) + 1);
5762 return log;
5765 /* Return the size of a DIE, as it is represented in the
5766 .debug_info section. */
5768 static unsigned long
5769 size_of_die (die)
5770 register dw_die_ref die;
5772 register unsigned long size = 0;
5773 register dw_attr_ref a;
5775 size += size_of_uleb128 (die->die_abbrev);
5776 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5778 switch (AT_class (a))
5780 case dw_val_class_addr:
5781 size += DWARF2_ADDR_SIZE;
5782 break;
5783 case dw_val_class_loc:
5785 register unsigned long lsize = size_of_locs (AT_loc (a));
5787 /* Block length. */
5788 size += constant_size (lsize);
5789 size += lsize;
5791 break;
5792 case dw_val_class_const:
5793 size += size_of_sleb128 (AT_int (a));
5794 break;
5795 case dw_val_class_unsigned_const:
5796 size += constant_size (AT_unsigned (a));
5797 break;
5798 case dw_val_class_long_long:
5799 size += 1 + 8; /* block */
5800 break;
5801 case dw_val_class_float:
5802 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5803 break;
5804 case dw_val_class_flag:
5805 size += 1;
5806 break;
5807 case dw_val_class_die_ref:
5808 size += DWARF_OFFSET_SIZE;
5809 break;
5810 case dw_val_class_fde_ref:
5811 size += DWARF_OFFSET_SIZE;
5812 break;
5813 case dw_val_class_lbl_id:
5814 size += DWARF2_ADDR_SIZE;
5815 break;
5816 case dw_val_class_lbl_offset:
5817 size += DWARF_OFFSET_SIZE;
5818 break;
5819 case dw_val_class_str:
5820 size += size_of_string (AT_string (a));
5821 break;
5822 default:
5823 abort ();
5827 return size;
5830 /* Size the debugging information associated with a given DIE.
5831 Visits the DIE's children recursively. Updates the global
5832 variable next_die_offset, on each time through. Uses the
5833 current value of next_die_offset to update the die_offset
5834 field in each DIE. */
5836 static void
5837 calc_die_sizes (die)
5838 dw_die_ref die;
5840 register dw_die_ref c;
5841 die->die_offset = next_die_offset;
5842 next_die_offset += size_of_die (die);
5844 for (c = die->die_child; c != NULL; c = c->die_sib)
5845 calc_die_sizes (c);
5847 if (die->die_child != NULL)
5848 /* Count the null byte used to terminate sibling lists. */
5849 next_die_offset += 1;
5852 /* Set the marks for a die and its children. We do this so
5853 that we know whether or not a reference needs to use FORM_ref_addr; only
5854 DIEs in the same CU will be marked. We used to clear out the offset
5855 and use that as the flag, but ran into ordering problems. */
5857 static void
5858 mark_dies (die)
5859 dw_die_ref die;
5861 register dw_die_ref c;
5862 die->die_mark = 1;
5863 for (c = die->die_child; c; c = c->die_sib)
5864 mark_dies (c);
5867 /* Clear the marks for a die and its children. */
5869 static void
5870 unmark_dies (die)
5871 dw_die_ref die;
5873 register dw_die_ref c;
5874 die->die_mark = 0;
5875 for (c = die->die_child; c; c = c->die_sib)
5876 unmark_dies (c);
5879 /* Return the size of the .debug_pubnames table generated for the
5880 compilation unit. */
5882 static unsigned long
5883 size_of_pubnames ()
5885 register unsigned long size;
5886 register unsigned i;
5888 size = DWARF_PUBNAMES_HEADER_SIZE;
5889 for (i = 0; i < pubname_table_in_use; ++i)
5891 register pubname_ref p = &pubname_table[i];
5892 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5895 size += DWARF_OFFSET_SIZE;
5896 return size;
5899 /* Return the size of the information in the .debug_aranges section. */
5901 static unsigned long
5902 size_of_aranges ()
5904 register unsigned long size;
5906 size = DWARF_ARANGES_HEADER_SIZE;
5908 /* Count the address/length pair for this compilation unit. */
5909 size += 2 * DWARF2_ADDR_SIZE;
5910 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5912 /* Count the two zero words used to terminated the address range table. */
5913 size += 2 * DWARF2_ADDR_SIZE;
5914 return size;
5917 /* Select the encoding of an attribute value. */
5919 static enum dwarf_form
5920 value_format (a)
5921 dw_attr_ref a;
5923 switch (a->dw_attr_val.val_class)
5925 case dw_val_class_addr:
5926 return DW_FORM_addr;
5927 case dw_val_class_loc:
5928 switch (constant_size (size_of_locs (AT_loc (a))))
5930 case 1:
5931 return DW_FORM_block1;
5932 case 2:
5933 return DW_FORM_block2;
5934 default:
5935 abort ();
5937 case dw_val_class_const:
5938 return DW_FORM_sdata;
5939 case dw_val_class_unsigned_const:
5940 switch (constant_size (AT_unsigned (a)))
5942 case 1:
5943 return DW_FORM_data1;
5944 case 2:
5945 return DW_FORM_data2;
5946 case 4:
5947 return DW_FORM_data4;
5948 case 8:
5949 return DW_FORM_data8;
5950 default:
5951 abort ();
5953 case dw_val_class_long_long:
5954 return DW_FORM_block1;
5955 case dw_val_class_float:
5956 return DW_FORM_block1;
5957 case dw_val_class_flag:
5958 return DW_FORM_flag;
5959 case dw_val_class_die_ref:
5960 if (AT_ref_external (a))
5961 return DW_FORM_ref_addr;
5962 else
5963 return DW_FORM_ref;
5964 case dw_val_class_fde_ref:
5965 return DW_FORM_data;
5966 case dw_val_class_lbl_id:
5967 return DW_FORM_addr;
5968 case dw_val_class_lbl_offset:
5969 return DW_FORM_data;
5970 case dw_val_class_str:
5971 return DW_FORM_string;
5972 default:
5973 abort ();
5977 /* Output the encoding of an attribute value. */
5979 static void
5980 output_value_format (a)
5981 dw_attr_ref a;
5983 enum dwarf_form form = value_format (a);
5985 output_uleb128 (form);
5986 if (flag_debug_asm)
5987 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
5989 fputc ('\n', asm_out_file);
5992 /* Output the .debug_abbrev section which defines the DIE abbreviation
5993 table. */
5995 static void
5996 output_abbrev_section ()
5998 unsigned long abbrev_id;
6000 dw_attr_ref a_attr;
6001 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6003 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6005 output_uleb128 (abbrev_id);
6006 if (flag_debug_asm)
6007 fprintf (asm_out_file, " (abbrev code)");
6009 fputc ('\n', asm_out_file);
6010 output_uleb128 (abbrev->die_tag);
6011 if (flag_debug_asm)
6012 fprintf (asm_out_file, " (TAG: %s)",
6013 dwarf_tag_name (abbrev->die_tag));
6015 fputc ('\n', asm_out_file);
6016 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP,
6017 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
6019 if (flag_debug_asm)
6020 fprintf (asm_out_file, "\t%s %s",
6021 ASM_COMMENT_START,
6022 (abbrev->die_child != NULL
6023 ? "DW_children_yes" : "DW_children_no"));
6025 fputc ('\n', asm_out_file);
6027 for (a_attr = abbrev->die_attr; a_attr != NULL;
6028 a_attr = a_attr->dw_attr_next)
6030 output_uleb128 (a_attr->dw_attr);
6031 if (flag_debug_asm)
6032 fprintf (asm_out_file, " (%s)",
6033 dwarf_attr_name (a_attr->dw_attr));
6035 fputc ('\n', asm_out_file);
6036 output_value_format (a_attr);
6039 fprintf (asm_out_file, "%s0,0\n", ASM_BYTE_OP);
6042 /* Terminate the table. */
6043 fprintf (asm_out_file, "%s0\n", ASM_BYTE_OP);
6046 /* Output a symbol we can use to refer to this DIE from another CU. */
6048 static inline void
6049 output_die_symbol (die)
6050 register dw_die_ref die;
6052 char *sym = die->die_symbol;
6054 if (sym == 0)
6055 return;
6057 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6058 /* We make these global, not weak; if the target doesn't support
6059 .linkonce, it doesn't support combining the sections, so debugging
6060 will break. */
6061 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
6062 ASM_OUTPUT_LABEL (asm_out_file, sym);
6065 /* Output a symbolic (i.e. FORM_ref_addr) reference to TARGET_DIE. */
6067 static inline void
6068 output_symbolic_ref (target_die)
6069 dw_die_ref target_die;
6071 char *sym = target_die->die_symbol;
6073 if (sym == 0)
6074 abort ();
6076 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, sym);
6079 /* Output the DIE and its attributes. Called recursively to generate
6080 the definitions of each child DIE. */
6082 static void
6083 output_die (die)
6084 register dw_die_ref die;
6086 register dw_attr_ref a;
6087 register dw_die_ref c;
6088 register unsigned long size;
6090 /* If someone in another CU might refer to us, set up a symbol for
6091 them to point to. */
6092 if (die->die_symbol)
6093 output_die_symbol (die);
6095 output_uleb128 (die->die_abbrev);
6096 if (flag_debug_asm)
6097 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
6098 die->die_offset, dwarf_tag_name (die->die_tag));
6100 fputc ('\n', asm_out_file);
6102 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6104 switch (AT_class (a))
6106 case dw_val_class_addr:
6107 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
6108 break;
6110 case dw_val_class_loc:
6111 size = size_of_locs (AT_loc (a));
6113 /* Output the block length for this list of location operations. */
6114 switch (constant_size (size))
6116 case 1:
6117 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
6118 break;
6119 case 2:
6120 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
6121 break;
6122 default:
6123 abort ();
6126 if (flag_debug_asm)
6127 fprintf (asm_out_file, "\t%s %s",
6128 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6130 fputc ('\n', asm_out_file);
6132 output_loc_sequence (AT_loc (a));
6133 break;
6135 case dw_val_class_const:
6136 /* ??? It would be slightly more efficient to use a scheme like is
6137 used for unsigned constants below, but gdb 4.x does not sign
6138 extend. Gdb 5.x does sign extend. */
6139 output_sleb128 (AT_int (a));
6140 break;
6142 case dw_val_class_unsigned_const:
6143 switch (constant_size (AT_unsigned (a)))
6145 case 1:
6146 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
6147 break;
6148 case 2:
6149 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
6150 break;
6151 case 4:
6152 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
6153 break;
6154 case 8:
6155 ASM_OUTPUT_DWARF_DATA8 (asm_out_file, AT_unsigned (a));
6156 break;
6157 default:
6158 abort ();
6160 break;
6162 case dw_val_class_long_long:
6163 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
6164 if (flag_debug_asm)
6165 fprintf (asm_out_file, "\t%s %s",
6166 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6168 fputc ('\n', asm_out_file);
6169 ASM_OUTPUT_DWARF_CONST_DOUBLE (asm_out_file,
6170 a->dw_attr_val.v.val_long_long.hi,
6171 a->dw_attr_val.v.val_long_long.low);
6173 if (flag_debug_asm)
6174 fprintf (asm_out_file,
6175 "\t%s long long constant", ASM_COMMENT_START);
6177 fputc ('\n', asm_out_file);
6178 break;
6180 case dw_val_class_float:
6182 register unsigned int i;
6183 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6184 a->dw_attr_val.v.val_float.length * 4);
6185 if (flag_debug_asm)
6186 fprintf (asm_out_file, "\t%s %s",
6187 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6189 fputc ('\n', asm_out_file);
6190 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
6192 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
6193 a->dw_attr_val.v.val_float.array[i]);
6194 if (flag_debug_asm)
6195 fprintf (asm_out_file, "\t%s fp constant word %u",
6196 ASM_COMMENT_START, i);
6198 fputc ('\n', asm_out_file);
6200 break;
6203 case dw_val_class_flag:
6204 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
6205 break;
6207 case dw_val_class_die_ref:
6208 if (AT_ref_external (a))
6209 output_symbolic_ref (AT_ref (a));
6210 else if (AT_ref (a)->die_offset == 0)
6211 abort ();
6212 else
6213 ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
6214 break;
6216 case dw_val_class_fde_ref:
6218 char l1[20];
6219 ASM_GENERATE_INTERNAL_LABEL
6220 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
6221 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
6222 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
6224 break;
6226 case dw_val_class_lbl_id:
6227 ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
6228 break;
6230 case dw_val_class_lbl_offset:
6231 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
6232 break;
6234 case dw_val_class_str:
6235 if (flag_debug_asm)
6236 ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
6237 else
6238 ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
6239 (int) strlen (AT_string (a)) + 1);
6240 break;
6242 default:
6243 abort ();
6246 if (AT_class (a) != dw_val_class_loc
6247 && AT_class (a) != dw_val_class_long_long
6248 && AT_class (a) != dw_val_class_float)
6250 if (flag_debug_asm)
6251 fprintf (asm_out_file, "\t%s %s",
6252 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6254 fputc ('\n', asm_out_file);
6258 for (c = die->die_child; c != NULL; c = c->die_sib)
6259 output_die (c);
6261 if (die->die_child != NULL)
6263 /* Add null byte to terminate sibling list. */
6264 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6265 if (flag_debug_asm)
6266 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
6267 ASM_COMMENT_START, die->die_offset);
6269 fputc ('\n', asm_out_file);
6273 /* Output the compilation unit that appears at the beginning of the
6274 .debug_info section, and precedes the DIE descriptions. */
6276 static void
6277 output_compilation_unit_header ()
6279 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
6280 if (flag_debug_asm)
6281 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
6282 ASM_COMMENT_START);
6284 fputc ('\n', asm_out_file);
6285 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6286 if (flag_debug_asm)
6287 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
6289 fputc ('\n', asm_out_file);
6290 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
6291 if (flag_debug_asm)
6292 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
6293 ASM_COMMENT_START);
6295 fputc ('\n', asm_out_file);
6296 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6297 if (flag_debug_asm)
6298 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
6300 fputc ('\n', asm_out_file);
6303 /* Output the compilation unit DIE and its children. */
6305 static void
6306 output_comp_unit (die)
6307 dw_die_ref die;
6309 const char *secname;
6311 if (die->die_child == 0)
6312 return;
6314 /* Mark all the DIEs in this CU so we know which get local refs. */
6315 mark_dies (die);
6317 build_abbrev_table (die);
6319 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6320 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6321 calc_die_sizes (die);
6323 if (die->die_symbol)
6325 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6326 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6327 secname = tmp;
6328 die->die_symbol = NULL;
6330 else
6331 secname = (const char *) DEBUG_INFO_SECTION;
6333 /* Output debugging information. */
6334 fputc ('\n', asm_out_file);
6335 ASM_OUTPUT_SECTION (asm_out_file, secname);
6336 output_compilation_unit_header ();
6337 output_die (die);
6339 /* Leave the marks on the main CU, so we can check them in
6340 output_pubnames. */
6341 if (die->die_symbol)
6342 unmark_dies (die);
6345 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6346 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6347 argument list, and maybe the scope. */
6349 static const char *
6350 dwarf2_name (decl, scope)
6351 tree decl;
6352 int scope;
6354 return (*decl_printable_name) (decl, scope ? 1 : 0);
6357 /* Add a new entry to .debug_pubnames if appropriate. */
6359 static void
6360 add_pubname (decl, die)
6361 tree decl;
6362 dw_die_ref die;
6364 pubname_ref p;
6366 if (! TREE_PUBLIC (decl))
6367 return;
6369 if (pubname_table_in_use == pubname_table_allocated)
6371 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6372 pubname_table = (pubname_ref) xrealloc
6373 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6376 p = &pubname_table[pubname_table_in_use++];
6377 p->die = die;
6379 p->name = xstrdup (dwarf2_name (decl, 1));
6382 /* Output the public names table used to speed up access to externally
6383 visible names. For now, only generate entries for externally
6384 visible procedures. */
6386 static void
6387 output_pubnames ()
6389 register unsigned i;
6390 register unsigned long pubnames_length = size_of_pubnames ();
6392 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
6394 if (flag_debug_asm)
6395 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
6396 ASM_COMMENT_START);
6398 fputc ('\n', asm_out_file);
6399 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6401 if (flag_debug_asm)
6402 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6404 fputc ('\n', asm_out_file);
6405 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6406 if (flag_debug_asm)
6407 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6408 ASM_COMMENT_START);
6410 fputc ('\n', asm_out_file);
6411 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
6412 if (flag_debug_asm)
6413 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
6415 fputc ('\n', asm_out_file);
6416 for (i = 0; i < pubname_table_in_use; ++i)
6418 register pubname_ref pub = &pubname_table[i];
6420 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6421 if (pub->die->die_mark == 0)
6422 abort ();
6424 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
6425 if (flag_debug_asm)
6426 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
6428 fputc ('\n', asm_out_file);
6430 if (flag_debug_asm)
6432 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
6433 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
6435 else
6437 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
6438 (int) strlen (pub->name) + 1);
6441 fputc ('\n', asm_out_file);
6444 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
6445 fputc ('\n', asm_out_file);
6448 /* Add a new entry to .debug_aranges if appropriate. */
6450 static void
6451 add_arange (decl, die)
6452 tree decl;
6453 dw_die_ref die;
6455 if (! DECL_SECTION_NAME (decl))
6456 return;
6458 if (arange_table_in_use == arange_table_allocated)
6460 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6461 arange_table
6462 = (arange_ref) xrealloc (arange_table,
6463 arange_table_allocated * sizeof (dw_die_ref));
6466 arange_table[arange_table_in_use++] = die;
6469 /* Output the information that goes into the .debug_aranges table.
6470 Namely, define the beginning and ending address range of the
6471 text section generated for this compilation unit. */
6473 static void
6474 output_aranges ()
6476 register unsigned i;
6477 register unsigned long aranges_length = size_of_aranges ();
6479 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
6480 if (flag_debug_asm)
6481 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
6482 ASM_COMMENT_START);
6484 fputc ('\n', asm_out_file);
6485 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6486 if (flag_debug_asm)
6487 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6489 fputc ('\n', asm_out_file);
6490 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6491 if (flag_debug_asm)
6492 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6493 ASM_COMMENT_START);
6495 fputc ('\n', asm_out_file);
6496 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6497 if (flag_debug_asm)
6498 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
6500 fputc ('\n', asm_out_file);
6501 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6502 if (flag_debug_asm)
6503 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
6504 ASM_COMMENT_START);
6506 fputc ('\n', asm_out_file);
6508 /* We need to align to twice the pointer size here. */
6509 if (DWARF_ARANGES_PAD_SIZE)
6511 /* Pad using a 2 bytes word so that padding is correct
6512 for any pointer size. */
6513 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
6514 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6515 fprintf (asm_out_file, ",0");
6516 if (flag_debug_asm)
6517 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
6518 ASM_COMMENT_START, 2 * DWARF2_ADDR_SIZE);
6521 fputc ('\n', asm_out_file);
6522 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
6523 if (flag_debug_asm)
6524 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6526 fputc ('\n', asm_out_file);
6527 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
6528 text_section_label);
6529 if (flag_debug_asm)
6530 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6532 fputc ('\n', asm_out_file);
6533 for (i = 0; i < arange_table_in_use; ++i)
6535 dw_die_ref die = arange_table[i];
6537 /* We shouldn't see aranges for DIEs outside of the main CU. */
6538 if (die->die_mark == 0)
6539 abort ();
6541 if (die->die_tag == DW_TAG_subprogram)
6542 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
6543 else
6545 /* A static variable; extract the symbol from DW_AT_location.
6546 Note that this code isn't currently hit, as we only emit
6547 aranges for functions (jason 9/23/99). */
6549 dw_attr_ref a = get_AT (die, DW_AT_location);
6550 dw_loc_descr_ref loc;
6551 if (! a || AT_class (a) != dw_val_class_loc)
6552 abort ();
6554 loc = AT_loc (a);
6555 if (loc->dw_loc_opc != DW_OP_addr)
6556 abort ();
6558 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
6559 loc->dw_loc_oprnd1.v.val_addr);
6562 if (flag_debug_asm)
6563 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6565 fputc ('\n', asm_out_file);
6566 if (die->die_tag == DW_TAG_subprogram)
6567 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
6568 get_AT_low_pc (die));
6569 else
6570 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
6571 get_AT_unsigned (die, DW_AT_byte_size));
6573 if (flag_debug_asm)
6574 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6576 fputc ('\n', asm_out_file);
6579 /* Output the terminator words. */
6580 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6581 fputc ('\n', asm_out_file);
6582 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6583 fputc ('\n', asm_out_file);
6587 /* Data structure containing information about input files. */
6588 struct file_info
6590 char *path; /* Complete file name. */
6591 char *fname; /* File name part. */
6592 int length; /* Length of entire string. */
6593 int file_idx; /* Index in input file table. */
6594 int dir_idx; /* Index in directory table. */
6597 /* Data structure containing information about directories with source
6598 files. */
6599 struct dir_info
6601 char *path; /* Path including directory name. */
6602 int length; /* Path length. */
6603 int prefix; /* Index of directory entry which is a prefix. */
6604 int count; /* Number of files in this directory. */
6605 int dir_idx; /* Index of directory used as base. */
6606 int used; /* Used in the end? */
6609 /* Callback function for file_info comparison. We sort by looking at
6610 the directories in the path. */
6611 static int
6612 file_info_cmp (p1, p2)
6613 const void *p1;
6614 const void *p2;
6616 const struct file_info *s1 = p1;
6617 const struct file_info *s2 = p2;
6618 unsigned char *cp1;
6619 unsigned char *cp2;
6621 /* Take care of file names without directories. */
6622 if (s1->path == s1->fname)
6623 return -1;
6624 else if (s2->path == s2->fname)
6625 return 1;
6627 cp1 = (unsigned char *) s1->path;
6628 cp2 = (unsigned char *) s2->path;
6630 while (1)
6632 ++cp1;
6633 ++cp2;
6634 /* Reached the end of the first path? */
6635 if (cp1 == (unsigned char *) s1->fname)
6636 /* It doesn't really matter in which order files from the
6637 same directory are sorted in. Therefore don't test for
6638 the second path reaching the end. */
6639 return -1;
6640 else if (cp2 == (unsigned char *) s2->fname)
6641 return 1;
6643 /* Character of current path component the same? */
6644 if (*cp1 != *cp2)
6645 return *cp1 - *cp2;
6649 /* Output the directory table and the file name table. We try to minimize
6650 the total amount of memory needed. A heuristic is used to avoid large
6651 slowdowns with many input files. */
6652 static void
6653 output_file_names ()
6655 struct file_info *files;
6656 struct dir_info *dirs;
6657 int *saved;
6658 int *savehere;
6659 int *backmap;
6660 int ndirs;
6661 int idx_offset;
6662 int i;
6663 int idx;
6665 /* Allocate the various arrays we need. */
6666 files = (struct file_info *) alloca (file_table.in_use
6667 * sizeof (struct file_info));
6668 dirs = (struct dir_info *) alloca (file_table.in_use
6669 * sizeof (struct dir_info));
6671 /* Sort the file names. */
6672 for (i = 1; i < (int) file_table.in_use; ++i)
6674 char *f;
6676 /* Skip all leading "./". */
6677 f = file_table.table[i];
6678 while (f[0] == '.' && f[1] == '/')
6679 f += 2;
6681 /* Create a new array entry. */
6682 files[i].path = f;
6683 files[i].length = strlen (f);
6684 files[i].file_idx = i;
6686 /* Search for the file name part. */
6687 f = strrchr (f, '/');
6688 files[i].fname = f == NULL ? files[i].path : f + 1;
6690 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]),
6691 file_info_cmp);
6693 /* Find all the different directories used. */
6694 dirs[0].path = files[1].path;
6695 dirs[0].length = files[1].fname - files[1].path;
6696 dirs[0].prefix = -1;
6697 dirs[0].count = 1;
6698 dirs[0].dir_idx = 0;
6699 dirs[0].used = 0;
6700 files[1].dir_idx = 0;
6701 ndirs = 1;
6703 for (i = 2; i < (int) file_table.in_use; ++i)
6704 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6705 && memcmp (dirs[ndirs - 1].path, files[i].path,
6706 dirs[ndirs - 1].length) == 0)
6708 /* Same directory as last entry. */
6709 files[i].dir_idx = ndirs - 1;
6710 ++dirs[ndirs - 1].count;
6712 else
6714 int j;
6716 /* This is a new directory. */
6717 dirs[ndirs].path = files[i].path;
6718 dirs[ndirs].length = files[i].fname - files[i].path;
6719 dirs[ndirs].count = 1;
6720 dirs[ndirs].dir_idx = ndirs;
6721 dirs[ndirs].used = 0;
6722 files[i].dir_idx = ndirs;
6724 /* Search for a prefix. */
6725 dirs[ndirs].prefix = -1;
6726 for (j = 0; j < ndirs; ++j)
6727 if (dirs[j].length < dirs[ndirs].length
6728 && dirs[j].length > 1
6729 && (dirs[ndirs].prefix == -1
6730 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6731 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6732 dirs[ndirs].prefix = j;
6734 ++ndirs;
6737 /* Now to the actual work. We have to find a subset of the
6738 directories which allow expressing the file name using references
6739 to the directory table with the least amount of characters. We
6740 do not do an exhaustive search where we would have to check out
6741 every combination of every single possible prefix. Instead we
6742 use a heuristic which provides nearly optimal results in most
6743 cases and never is much off. */
6744 saved = (int *) alloca (ndirs * sizeof (int));
6745 savehere = (int *) alloca (ndirs * sizeof (int));
6747 memset (saved, '\0', ndirs * sizeof (saved[0]));
6748 for (i = 0; i < ndirs; ++i)
6750 int j;
6751 int total;
6753 /* We can always save some space for the current directory. But
6754 this does not mean it will be enough to justify adding the
6755 directory. */
6756 savehere[i] = dirs[i].length;
6757 total = (savehere[i] - saved[i]) * dirs[i].count;
6759 for (j = i + 1; j < ndirs; ++j)
6761 savehere[j] = 0;
6763 if (saved[j] < dirs[i].length)
6765 /* Determine whether the dirs[i] path is a prefix of the
6766 dirs[j] path. */
6767 int k;
6769 k = dirs[j].prefix;
6770 while (k != -1 && k != i)
6771 k = dirs[k].prefix;
6773 if (k == i)
6775 /* Yes it is. We can possibly save some memory but
6776 writing the filenames in dirs[j] relative to
6777 dirs[i]. */
6778 savehere[j] = dirs[i].length;
6779 total += (savehere[j] - saved[j]) * dirs[j].count;
6784 /* Check whether we can save enough to justify adding the dirs[i]
6785 directory. */
6786 if (total > dirs[i].length + 1)
6788 /* It's worthwhile adding. */
6789 for (j = i; j < ndirs; ++j)
6790 if (savehere[j] > 0)
6792 /* Remember how much we saved for this directory so far. */
6793 saved[j] = savehere[j];
6795 /* Remember the prefix directory. */
6796 dirs[j].dir_idx = i;
6801 /* We have to emit them in the order they appear in the file_table
6802 array since the index is used in the debug info generation. To
6803 do this efficiently we generate a back-mapping of the indices
6804 first. */
6805 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6806 for (i = 1; i < (int) file_table.in_use; ++i)
6808 backmap[files[i].file_idx] = i;
6809 /* Mark this directory as used. */
6810 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6813 /* That was it. We are ready to emit the information. First the
6814 directory name table. Here we have to make sure that the first
6815 actually emitted directory name has the index one. Zero is
6816 reserved for the current working directory. Make sure we do not
6817 confuse these indices with the one for the constructed table
6818 (even though most of the time they are identical). */
6819 idx = 1;
6820 idx_offset = dirs[0].length > 0 ? 1 : 0;
6821 for (i = 1 - idx_offset; i < ndirs; ++i)
6822 if (dirs[i].used != 0)
6824 dirs[i].used = idx++;
6826 if (flag_debug_asm)
6828 ASM_OUTPUT_DWARF_NSTRING (asm_out_file,
6829 dirs[i].path, dirs[i].length - 1);
6830 fprintf (asm_out_file, "%s Directory Entry: 0x%x\n",
6831 ASM_COMMENT_START, dirs[i].used);
6833 else
6835 ASM_OUTPUT_ASCII (asm_out_file, dirs[i].path, dirs[i].length - 1);
6836 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6837 fputc ('\n', asm_out_file);
6840 /* Correct the index for the current working directory entry if it
6841 exists. */
6842 if (idx_offset == 0)
6843 dirs[0].used = 0;
6844 /* Terminate the directory name array. */
6845 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6846 if (flag_debug_asm)
6847 fprintf (asm_out_file, "\t%s End directory table", ASM_COMMENT_START);
6848 fputc ('\n', asm_out_file);
6850 /* Now write all the file names. */
6851 for (i = 1; i < (int) file_table.in_use; ++i)
6853 int file_idx = backmap[i];
6854 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6856 if (flag_debug_asm)
6858 ASM_OUTPUT_DWARF_STRING (asm_out_file,
6859 files[file_idx].path
6860 + dirs[dir_idx].length);
6861 fprintf (asm_out_file, "%s File Entry: 0x%x\n",
6862 ASM_COMMENT_START, i);
6864 else
6865 ASM_OUTPUT_ASCII (asm_out_file,
6866 files[file_idx].path + dirs[dir_idx].length,
6867 (files[file_idx].length
6868 - dirs[dir_idx].length) + 1);
6870 /* Include directory index. */
6871 output_uleb128 (dirs[dir_idx].used);
6872 fputc ('\n', asm_out_file);
6874 /* Modification time. */
6875 output_uleb128 (0);
6876 fputc ('\n', asm_out_file);
6878 /* File length in bytes. */
6879 output_uleb128 (0);
6880 fputc ('\n', asm_out_file);
6883 /* Terminate the file name table */
6884 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6885 if (flag_debug_asm)
6886 fprintf (asm_out_file, "\t%s End file name table", ASM_COMMENT_START);
6887 fputc ('\n', asm_out_file);
6891 /* Output the source line number correspondence information. This
6892 information goes into the .debug_line section. */
6894 static void
6895 output_line_info ()
6897 char l1[20], l2[20], p1[20], p2[20];
6898 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6899 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6900 register unsigned opc;
6901 register unsigned n_op_args;
6902 register unsigned long lt_index;
6903 register unsigned long current_line;
6904 register long line_offset;
6905 register long line_delta;
6906 register unsigned long current_file;
6907 register unsigned long function;
6909 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
6910 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
6911 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
6912 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
6914 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l1, l2);
6915 if (flag_debug_asm)
6916 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
6917 ASM_COMMENT_START);
6919 fputc ('\n', asm_out_file);
6920 ASM_OUTPUT_LABEL (asm_out_file, l1);
6921 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6922 if (flag_debug_asm)
6923 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6925 fputc ('\n', asm_out_file);
6926 ASM_OUTPUT_DWARF_DELTA (asm_out_file, p1, p2);
6927 if (flag_debug_asm)
6928 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
6930 fputc ('\n', asm_out_file);
6931 ASM_OUTPUT_LABEL (asm_out_file, p1);
6932 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
6933 if (flag_debug_asm)
6934 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
6935 ASM_COMMENT_START);
6937 fputc ('\n', asm_out_file);
6938 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
6939 if (flag_debug_asm)
6940 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
6941 ASM_COMMENT_START);
6943 fputc ('\n', asm_out_file);
6944 fprintf (asm_out_file, "%s%d", ASM_BYTE_OP, DWARF_LINE_BASE);
6945 if (flag_debug_asm)
6946 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
6947 ASM_COMMENT_START);
6949 fputc ('\n', asm_out_file);
6950 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
6951 if (flag_debug_asm)
6952 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
6953 ASM_COMMENT_START);
6955 fputc ('\n', asm_out_file);
6956 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
6957 if (flag_debug_asm)
6958 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
6960 fputc ('\n', asm_out_file);
6961 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6963 switch (opc)
6965 case DW_LNS_advance_pc:
6966 case DW_LNS_advance_line:
6967 case DW_LNS_set_file:
6968 case DW_LNS_set_column:
6969 case DW_LNS_fixed_advance_pc:
6970 n_op_args = 1;
6971 break;
6972 default:
6973 n_op_args = 0;
6974 break;
6976 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
6977 if (flag_debug_asm)
6978 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
6979 ASM_COMMENT_START, opc, n_op_args);
6980 fputc ('\n', asm_out_file);
6983 /* Write out the information about the files we use. */
6984 output_file_names ();
6985 ASM_OUTPUT_LABEL (asm_out_file, p2);
6987 /* We used to set the address register to the first location in the text
6988 section here, but that didn't accomplish anything since we already
6989 have a line note for the opening brace of the first function. */
6991 /* Generate the line number to PC correspondence table, encoded as
6992 a series of state machine operations. */
6993 current_file = 1;
6994 current_line = 1;
6995 strcpy (prev_line_label, text_section_label);
6996 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6998 register dw_line_info_ref line_info = &line_info_table[lt_index];
7000 #if 0
7001 /* Disable this optimization for now; GDB wants to see two line notes
7002 at the beginning of a function so it can find the end of the
7003 prologue. */
7005 /* Don't emit anything for redundant notes. Just updating the
7006 address doesn't accomplish anything, because we already assume
7007 that anything after the last address is this line. */
7008 if (line_info->dw_line_num == current_line
7009 && line_info->dw_file_num == current_file)
7010 continue;
7011 #endif
7013 /* Emit debug info for the address of the current line, choosing
7014 the encoding that uses the least amount of space. */
7015 /* ??? Unfortunately, we have little choice here currently, and must
7016 always use the most general form. Gcc does not know the address
7017 delta itself, so we can't use DW_LNS_advance_pc. There are no known
7018 dwarf2 aware assemblers at this time, so we can't use any special
7019 pseudo ops that would allow the assembler to optimally encode this for
7020 us. Many ports do have length attributes which will give an upper
7021 bound on the address range. We could perhaps use length attributes
7022 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
7023 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7024 if (0)
7026 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7027 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7028 if (flag_debug_asm)
7029 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7030 ASM_COMMENT_START);
7032 fputc ('\n', asm_out_file);
7033 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
7034 fputc ('\n', asm_out_file);
7036 else
7038 /* This can handle any delta. This takes
7039 4+DWARF2_ADDR_SIZE bytes. */
7040 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7041 if (flag_debug_asm)
7042 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7043 ASM_COMMENT_START);
7044 fputc ('\n', asm_out_file);
7045 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7046 fputc ('\n', asm_out_file);
7047 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7048 fputc ('\n', asm_out_file);
7049 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7050 fputc ('\n', asm_out_file);
7052 strcpy (prev_line_label, line_label);
7054 /* Emit debug info for the source file of the current line, if
7055 different from the previous line. */
7056 if (line_info->dw_file_num != current_file)
7058 current_file = line_info->dw_file_num;
7059 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
7060 if (flag_debug_asm)
7061 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
7063 fputc ('\n', asm_out_file);
7064 output_uleb128 (current_file);
7065 if (flag_debug_asm)
7066 fprintf (asm_out_file, " (\"%s\")",
7067 file_table.table[current_file]);
7069 fputc ('\n', asm_out_file);
7072 /* Emit debug info for the current line number, choosing the encoding
7073 that uses the least amount of space. */
7074 if (line_info->dw_line_num != current_line)
7076 line_offset = line_info->dw_line_num - current_line;
7077 line_delta = line_offset - DWARF_LINE_BASE;
7078 current_line = line_info->dw_line_num;
7079 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7081 /* This can handle deltas from -10 to 234, using the current
7082 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7083 takes 1 byte. */
7084 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
7085 DWARF_LINE_OPCODE_BASE + line_delta);
7086 if (flag_debug_asm)
7087 fprintf (asm_out_file,
7088 "\t%s line %ld", ASM_COMMENT_START, current_line);
7090 fputc ('\n', asm_out_file);
7092 else
7094 /* This can handle any delta. This takes at least 4 bytes,
7095 depending on the value being encoded. */
7096 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
7097 if (flag_debug_asm)
7098 fprintf (asm_out_file, "\t%s advance to line %ld",
7099 ASM_COMMENT_START, current_line);
7101 fputc ('\n', asm_out_file);
7102 output_sleb128 (line_offset);
7103 fputc ('\n', asm_out_file);
7104 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7105 if (flag_debug_asm)
7106 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7107 fputc ('\n', asm_out_file);
7110 else
7112 /* We still need to start a new row, so output a copy insn. */
7113 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7114 if (flag_debug_asm)
7115 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7116 fputc ('\n', asm_out_file);
7120 /* Emit debug info for the address of the end of the function. */
7121 if (0)
7123 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7124 if (flag_debug_asm)
7125 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7126 ASM_COMMENT_START);
7128 fputc ('\n', asm_out_file);
7129 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
7130 fputc ('\n', asm_out_file);
7132 else
7134 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7135 if (flag_debug_asm)
7136 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
7137 fputc ('\n', asm_out_file);
7138 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7139 fputc ('\n', asm_out_file);
7140 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7141 fputc ('\n', asm_out_file);
7142 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
7143 fputc ('\n', asm_out_file);
7146 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7147 if (flag_debug_asm)
7148 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
7150 fputc ('\n', asm_out_file);
7151 output_uleb128 (1);
7152 fputc ('\n', asm_out_file);
7153 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
7154 fputc ('\n', asm_out_file);
7156 function = 0;
7157 current_file = 1;
7158 current_line = 1;
7159 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7161 register dw_separate_line_info_ref line_info
7162 = &separate_line_info_table[lt_index];
7164 #if 0
7165 /* Don't emit anything for redundant notes. */
7166 if (line_info->dw_line_num == current_line
7167 && line_info->dw_file_num == current_file
7168 && line_info->function == function)
7169 goto cont;
7170 #endif
7172 /* Emit debug info for the address of the current line. If this is
7173 a new function, or the first line of a function, then we need
7174 to handle it differently. */
7175 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7176 lt_index);
7177 if (function != line_info->function)
7179 function = line_info->function;
7181 /* Set the address register to the first line in the function */
7182 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7183 if (flag_debug_asm)
7184 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7185 ASM_COMMENT_START);
7187 fputc ('\n', asm_out_file);
7188 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7189 fputc ('\n', asm_out_file);
7190 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7191 fputc ('\n', asm_out_file);
7192 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7193 fputc ('\n', asm_out_file);
7195 else
7197 /* ??? See the DW_LNS_advance_pc comment above. */
7198 if (0)
7200 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7201 if (flag_debug_asm)
7202 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7203 ASM_COMMENT_START);
7205 fputc ('\n', asm_out_file);
7206 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
7207 prev_line_label);
7208 fputc ('\n', asm_out_file);
7210 else
7212 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7213 if (flag_debug_asm)
7214 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7215 ASM_COMMENT_START);
7216 fputc ('\n', asm_out_file);
7217 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7218 fputc ('\n', asm_out_file);
7219 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7220 fputc ('\n', asm_out_file);
7221 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7222 fputc ('\n', asm_out_file);
7225 strcpy (prev_line_label, line_label);
7227 /* Emit debug info for the source file of the current line, if
7228 different from the previous line. */
7229 if (line_info->dw_file_num != current_file)
7231 current_file = line_info->dw_file_num;
7232 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
7233 if (flag_debug_asm)
7234 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
7236 fputc ('\n', asm_out_file);
7237 output_uleb128 (current_file);
7238 if (flag_debug_asm)
7239 fprintf (asm_out_file, " (\"%s\")",
7240 file_table.table[current_file]);
7242 fputc ('\n', asm_out_file);
7245 /* Emit debug info for the current line number, choosing the encoding
7246 that uses the least amount of space. */
7247 if (line_info->dw_line_num != current_line)
7249 line_offset = line_info->dw_line_num - current_line;
7250 line_delta = line_offset - DWARF_LINE_BASE;
7251 current_line = line_info->dw_line_num;
7252 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7254 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
7255 DWARF_LINE_OPCODE_BASE + line_delta);
7256 if (flag_debug_asm)
7257 fprintf (asm_out_file,
7258 "\t%s line %ld", ASM_COMMENT_START, current_line);
7260 fputc ('\n', asm_out_file);
7262 else
7264 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
7265 if (flag_debug_asm)
7266 fprintf (asm_out_file, "\t%s advance to line %ld",
7267 ASM_COMMENT_START, current_line);
7269 fputc ('\n', asm_out_file);
7270 output_sleb128 (line_offset);
7271 fputc ('\n', asm_out_file);
7272 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7273 if (flag_debug_asm)
7274 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7275 fputc ('\n', asm_out_file);
7278 else
7280 /* We still need to start a new row, so output a copy insn. */
7281 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7282 if (flag_debug_asm)
7283 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7284 fputc ('\n', asm_out_file);
7287 #if 0
7288 cont:
7289 #endif
7290 ++lt_index;
7292 /* If we're done with a function, end its sequence. */
7293 if (lt_index == separate_line_info_table_in_use
7294 || separate_line_info_table[lt_index].function != function)
7296 current_file = 1;
7297 current_line = 1;
7299 /* Emit debug info for the address of the end of the function. */
7300 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7301 if (0)
7303 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7304 if (flag_debug_asm)
7305 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7306 ASM_COMMENT_START);
7308 fputc ('\n', asm_out_file);
7309 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
7310 prev_line_label);
7311 fputc ('\n', asm_out_file);
7313 else
7315 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7316 if (flag_debug_asm)
7317 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7318 ASM_COMMENT_START);
7319 fputc ('\n', asm_out_file);
7320 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7321 fputc ('\n', asm_out_file);
7322 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7323 fputc ('\n', asm_out_file);
7324 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7325 fputc ('\n', asm_out_file);
7328 /* Output the marker for the end of this sequence. */
7329 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7330 if (flag_debug_asm)
7331 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
7332 ASM_COMMENT_START);
7334 fputc ('\n', asm_out_file);
7335 output_uleb128 (1);
7336 fputc ('\n', asm_out_file);
7337 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
7338 fputc ('\n', asm_out_file);
7342 /* Output the marker for the end of the line number info. */
7343 ASM_OUTPUT_LABEL (asm_out_file, l2);
7346 /* Given a pointer to a tree node for some base type, return a pointer to
7347 a DIE that describes the given type.
7349 This routine must only be called for GCC type nodes that correspond to
7350 Dwarf base (fundamental) types. */
7352 static dw_die_ref
7353 base_type_die (type)
7354 register tree type;
7356 register dw_die_ref base_type_result;
7357 register const char *type_name;
7358 register enum dwarf_type encoding;
7359 register tree name = TYPE_NAME (type);
7361 if (TREE_CODE (type) == ERROR_MARK
7362 || TREE_CODE (type) == VOID_TYPE)
7363 return 0;
7365 if (name)
7367 if (TREE_CODE (name) == TYPE_DECL)
7368 name = DECL_NAME (name);
7370 type_name = IDENTIFIER_POINTER (name);
7372 else
7373 type_name = "__unknown__";
7375 switch (TREE_CODE (type))
7377 case INTEGER_TYPE:
7378 /* Carefully distinguish the C character types, without messing
7379 up if the language is not C. Note that we check only for the names
7380 that contain spaces; other names might occur by coincidence in other
7381 languages. */
7382 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7383 && (type == char_type_node
7384 || ! strcmp (type_name, "signed char")
7385 || ! strcmp (type_name, "unsigned char"))))
7387 if (TREE_UNSIGNED (type))
7388 encoding = DW_ATE_unsigned;
7389 else
7390 encoding = DW_ATE_signed;
7391 break;
7393 /* else fall through. */
7395 case CHAR_TYPE:
7396 /* GNU Pascal/Ada CHAR type. Not used in C. */
7397 if (TREE_UNSIGNED (type))
7398 encoding = DW_ATE_unsigned_char;
7399 else
7400 encoding = DW_ATE_signed_char;
7401 break;
7403 case REAL_TYPE:
7404 encoding = DW_ATE_float;
7405 break;
7407 /* Dwarf2 doesn't know anything about complex ints, so use
7408 a user defined type for it. */
7409 case COMPLEX_TYPE:
7410 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7411 encoding = DW_ATE_complex_float;
7412 else
7413 encoding = DW_ATE_lo_user;
7414 break;
7416 case BOOLEAN_TYPE:
7417 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7418 encoding = DW_ATE_boolean;
7419 break;
7421 default:
7422 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
7425 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
7426 if (demangle_name_func)
7427 type_name = (*demangle_name_func) (type_name);
7429 add_AT_string (base_type_result, DW_AT_name, type_name);
7430 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7431 int_size_in_bytes (type));
7432 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7434 return base_type_result;
7437 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7438 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7439 a given type is generally the same as the given type, except that if the
7440 given type is a pointer or reference type, then the root type of the given
7441 type is the root type of the "basis" type for the pointer or reference
7442 type. (This definition of the "root" type is recursive.) Also, the root
7443 type of a `const' qualified type or a `volatile' qualified type is the
7444 root type of the given type without the qualifiers. */
7446 static tree
7447 root_type (type)
7448 register tree type;
7450 if (TREE_CODE (type) == ERROR_MARK)
7451 return error_mark_node;
7453 switch (TREE_CODE (type))
7455 case ERROR_MARK:
7456 return error_mark_node;
7458 case POINTER_TYPE:
7459 case REFERENCE_TYPE:
7460 return type_main_variant (root_type (TREE_TYPE (type)));
7462 default:
7463 return type_main_variant (type);
7467 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7468 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7470 static inline int
7471 is_base_type (type)
7472 register tree type;
7474 switch (TREE_CODE (type))
7476 case ERROR_MARK:
7477 case VOID_TYPE:
7478 case INTEGER_TYPE:
7479 case REAL_TYPE:
7480 case COMPLEX_TYPE:
7481 case BOOLEAN_TYPE:
7482 case CHAR_TYPE:
7483 return 1;
7485 case SET_TYPE:
7486 case ARRAY_TYPE:
7487 case RECORD_TYPE:
7488 case UNION_TYPE:
7489 case QUAL_UNION_TYPE:
7490 case ENUMERAL_TYPE:
7491 case FUNCTION_TYPE:
7492 case METHOD_TYPE:
7493 case POINTER_TYPE:
7494 case REFERENCE_TYPE:
7495 case FILE_TYPE:
7496 case OFFSET_TYPE:
7497 case LANG_TYPE:
7498 case VECTOR_TYPE:
7499 return 0;
7501 default:
7502 abort ();
7505 return 0;
7508 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7509 entry that chains various modifiers in front of the given type. */
7511 static dw_die_ref
7512 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7513 register tree type;
7514 register int is_const_type;
7515 register int is_volatile_type;
7516 register dw_die_ref context_die;
7518 register enum tree_code code = TREE_CODE (type);
7519 register dw_die_ref mod_type_die = NULL;
7520 register dw_die_ref sub_die = NULL;
7521 register tree item_type = NULL;
7523 if (code != ERROR_MARK)
7525 tree qualified_type;
7527 /* See if we already have the appropriately qualified variant of
7528 this type. */
7529 qualified_type
7530 = get_qualified_type (type,
7531 ((is_const_type ? TYPE_QUAL_CONST : 0)
7532 | (is_volatile_type
7533 ? TYPE_QUAL_VOLATILE : 0)));
7534 /* If we do, then we can just use its DIE, if it exists. */
7535 if (qualified_type)
7537 mod_type_die = lookup_type_die (qualified_type);
7538 if (mod_type_die)
7539 return mod_type_die;
7542 /* Handle C typedef types. */
7543 if (qualified_type && TYPE_NAME (qualified_type)
7544 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7545 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7547 tree type_name = TYPE_NAME (qualified_type);
7548 tree dtype = TREE_TYPE (type_name);
7549 if (qualified_type == dtype)
7551 /* For a named type, use the typedef. */
7552 gen_type_die (qualified_type, context_die);
7553 mod_type_die = lookup_type_die (qualified_type);
7556 else if (is_const_type < TYPE_READONLY (dtype)
7557 || is_volatile_type < TYPE_VOLATILE (dtype))
7558 /* cv-unqualified version of named type. Just use the unnamed
7559 type to which it refers. */
7560 mod_type_die
7561 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7562 is_const_type, is_volatile_type,
7563 context_die);
7564 /* Else cv-qualified version of named type; fall through. */
7567 if (mod_type_die)
7568 /* OK. */
7570 else if (is_const_type)
7572 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7573 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7575 else if (is_volatile_type)
7577 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7578 sub_die = modified_type_die (type, 0, 0, context_die);
7580 else if (code == POINTER_TYPE)
7582 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7583 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7584 #if 0
7585 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7586 #endif
7587 item_type = TREE_TYPE (type);
7589 else if (code == REFERENCE_TYPE)
7591 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7592 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7593 #if 0
7594 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7595 #endif
7596 item_type = TREE_TYPE (type);
7598 else if (is_base_type (type))
7599 mod_type_die = base_type_die (type);
7600 else
7602 gen_type_die (type, context_die);
7604 /* We have to get the type_main_variant here (and pass that to the
7605 `lookup_type_die' routine) because the ..._TYPE node we have
7606 might simply be a *copy* of some original type node (where the
7607 copy was created to help us keep track of typedef names) and
7608 that copy might have a different TYPE_UID from the original
7609 ..._TYPE node. */
7610 mod_type_die = lookup_type_die (type_main_variant (type));
7611 if (mod_type_die == NULL)
7612 abort ();
7616 equate_type_number_to_die (type, mod_type_die);
7617 if (item_type)
7618 /* We must do this after the equate_type_number_to_die call, in case
7619 this is a recursive type. This ensures that the modified_type_die
7620 recursion will terminate even if the type is recursive. Recursive
7621 types are possible in Ada. */
7622 sub_die = modified_type_die (item_type,
7623 TYPE_READONLY (item_type),
7624 TYPE_VOLATILE (item_type),
7625 context_die);
7627 if (sub_die != NULL)
7628 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7630 return mod_type_die;
7633 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7634 an enumerated type. */
7636 static inline int
7637 type_is_enum (type)
7638 register tree type;
7640 return TREE_CODE (type) == ENUMERAL_TYPE;
7643 /* Return the register number described by a given RTL node. */
7645 static unsigned int
7646 reg_number (rtl)
7647 register rtx rtl;
7649 register unsigned regno = REGNO (rtl);
7651 if (regno >= FIRST_PSEUDO_REGISTER)
7653 warning ("internal regno botch: regno = %d\n", regno);
7654 regno = 0;
7657 regno = DBX_REGISTER_NUMBER (regno);
7658 return regno;
7661 /* Return a location descriptor that designates a machine register. */
7663 static dw_loc_descr_ref
7664 reg_loc_descriptor (rtl)
7665 register rtx rtl;
7667 register dw_loc_descr_ref loc_result = NULL;
7668 register unsigned reg = reg_number (rtl);
7670 if (reg <= 31)
7671 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7672 else
7673 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7675 return loc_result;
7678 /* Return a location descriptor that designates a constant. */
7680 static dw_loc_descr_ref
7681 int_loc_descriptor (i)
7682 HOST_WIDE_INT i;
7684 enum dwarf_location_atom op;
7686 /* Pick the smallest representation of a constant, rather than just
7687 defaulting to the LEB encoding. */
7688 if (i >= 0)
7690 if (i <= 31)
7691 op = DW_OP_lit0 + i;
7692 else if (i <= 0xff)
7693 op = DW_OP_const1u;
7694 else if (i <= 0xffff)
7695 op = DW_OP_const2u;
7696 else if (HOST_BITS_PER_WIDE_INT == 32
7697 || i <= 0xffffffff)
7698 op = DW_OP_const4u;
7699 else
7700 op = DW_OP_constu;
7702 else
7704 if (i >= -0x80)
7705 op = DW_OP_const1s;
7706 else if (i >= -0x8000)
7707 op = DW_OP_const2s;
7708 else if (HOST_BITS_PER_WIDE_INT == 32
7709 || i >= -0x80000000)
7710 op = DW_OP_const4s;
7711 else
7712 op = DW_OP_consts;
7715 return new_loc_descr (op, i, 0);
7718 /* Return a location descriptor that designates a base+offset location. */
7720 static dw_loc_descr_ref
7721 based_loc_descr (reg, offset)
7722 unsigned reg;
7723 long int offset;
7725 register dw_loc_descr_ref loc_result;
7726 /* For the "frame base", we use the frame pointer or stack pointer
7727 registers, since the RTL for local variables is relative to one of
7728 them. */
7729 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7730 ? HARD_FRAME_POINTER_REGNUM
7731 : STACK_POINTER_REGNUM);
7733 if (reg == fp_reg)
7734 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7735 else if (reg <= 31)
7736 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7737 else
7738 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7740 return loc_result;
7743 /* Return true if this RTL expression describes a base+offset calculation. */
7745 static inline int
7746 is_based_loc (rtl)
7747 register rtx rtl;
7749 return (GET_CODE (rtl) == PLUS
7750 && ((GET_CODE (XEXP (rtl, 0)) == REG
7751 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7754 /* The following routine converts the RTL for a variable or parameter
7755 (resident in memory) into an equivalent Dwarf representation of a
7756 mechanism for getting the address of that same variable onto the top of a
7757 hypothetical "address evaluation" stack.
7759 When creating memory location descriptors, we are effectively transforming
7760 the RTL for a memory-resident object into its Dwarf postfix expression
7761 equivalent. This routine recursively descends an RTL tree, turning
7762 it into Dwarf postfix code as it goes.
7764 MODE is the mode of the memory reference, needed to handle some
7765 autoincrement addressing modes. */
7767 static dw_loc_descr_ref
7768 mem_loc_descriptor (rtl, mode)
7769 register rtx rtl;
7770 enum machine_mode mode;
7772 dw_loc_descr_ref mem_loc_result = NULL;
7773 /* Note that for a dynamically sized array, the location we will generate a
7774 description of here will be the lowest numbered location which is
7775 actually within the array. That's *not* necessarily the same as the
7776 zeroth element of the array. */
7778 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7779 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7780 #endif
7782 switch (GET_CODE (rtl))
7784 case POST_INC:
7785 case POST_DEC:
7786 case POST_MODIFY:
7787 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7788 just fall into the SUBREG code. */
7790 /* Fall through. */
7792 case SUBREG:
7793 /* The case of a subreg may arise when we have a local (register)
7794 variable or a formal (register) parameter which doesn't quite fill
7795 up an entire register. For now, just assume that it is
7796 legitimate to make the Dwarf info refer to the whole register which
7797 contains the given subreg. */
7798 rtl = XEXP (rtl, 0);
7800 /* Fall through. */
7802 case REG:
7803 /* Whenever a register number forms a part of the description of the
7804 method for calculating the (dynamic) address of a memory resident
7805 object, DWARF rules require the register number be referred to as
7806 a "base register". This distinction is not based in any way upon
7807 what category of register the hardware believes the given register
7808 belongs to. This is strictly DWARF terminology we're dealing with
7809 here. Note that in cases where the location of a memory-resident
7810 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7811 OP_CONST (0)) the actual DWARF location descriptor that we generate
7812 may just be OP_BASEREG (basereg). This may look deceptively like
7813 the object in question was allocated to a register (rather than in
7814 memory) so DWARF consumers need to be aware of the subtle
7815 distinction between OP_REG and OP_BASEREG. */
7816 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7817 break;
7819 case MEM:
7820 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7821 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7822 break;
7824 case LABEL_REF:
7825 /* Some ports can transform a symbol ref into a label ref, because
7826 the symbol ref is too far away and has to be dumped into a constant
7827 pool. */
7828 case CONST:
7829 case SYMBOL_REF:
7830 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7831 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7832 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7833 break;
7835 case PRE_MODIFY:
7836 /* Extract the PLUS expression nested inside and fall into
7837 PLUS code bellow. */
7838 rtl = XEXP (rtl, 1);
7839 goto plus;
7841 case PRE_INC:
7842 case PRE_DEC:
7843 /* Turn these into a PLUS expression and fall into the PLUS code
7844 below. */
7845 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7846 GEN_INT (GET_CODE (rtl) == PRE_INC
7847 ? GET_MODE_UNIT_SIZE (mode)
7848 : -GET_MODE_UNIT_SIZE (mode)));
7850 /* Fall through. */
7852 case PLUS:
7853 plus:
7854 if (is_based_loc (rtl))
7855 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7856 INTVAL (XEXP (rtl, 1)));
7857 else
7859 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7861 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7862 && INTVAL (XEXP (rtl, 1)) >= 0)
7864 add_loc_descr (&mem_loc_result,
7865 new_loc_descr (DW_OP_plus_uconst,
7866 INTVAL (XEXP (rtl, 1)), 0));
7868 else
7870 add_loc_descr (&mem_loc_result,
7871 mem_loc_descriptor (XEXP (rtl, 1), mode));
7872 add_loc_descr (&mem_loc_result,
7873 new_loc_descr (DW_OP_plus, 0, 0));
7876 break;
7878 case MULT:
7879 /* If a pseudo-reg is optimized away, it is possible for it to
7880 be replaced with a MEM containing a multiply. */
7881 add_loc_descr (&mem_loc_result,
7882 mem_loc_descriptor (XEXP (rtl, 0), mode));
7883 add_loc_descr (&mem_loc_result,
7884 mem_loc_descriptor (XEXP (rtl, 1), mode));
7885 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7886 break;
7888 case CONST_INT:
7889 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7890 break;
7892 default:
7893 abort ();
7896 return mem_loc_result;
7899 /* Return a descriptor that describes the concatenation of two locations.
7900 This is typically a complex variable. */
7902 static dw_loc_descr_ref
7903 concat_loc_descriptor (x0, x1)
7904 register rtx x0, x1;
7906 dw_loc_descr_ref cc_loc_result = NULL;
7908 if (!is_pseudo_reg (x0)
7909 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7910 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7911 add_loc_descr (&cc_loc_result,
7912 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7914 if (!is_pseudo_reg (x1)
7915 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7916 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7917 add_loc_descr (&cc_loc_result,
7918 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7920 return cc_loc_result;
7923 /* Output a proper Dwarf location descriptor for a variable or parameter
7924 which is either allocated in a register or in a memory location. For a
7925 register, we just generate an OP_REG and the register number. For a
7926 memory location we provide a Dwarf postfix expression describing how to
7927 generate the (dynamic) address of the object onto the address stack. */
7929 static dw_loc_descr_ref
7930 loc_descriptor (rtl)
7931 register rtx rtl;
7933 dw_loc_descr_ref loc_result = NULL;
7934 switch (GET_CODE (rtl))
7936 case SUBREG:
7937 /* The case of a subreg may arise when we have a local (register)
7938 variable or a formal (register) parameter which doesn't quite fill
7939 up an entire register. For now, just assume that it is
7940 legitimate to make the Dwarf info refer to the whole register which
7941 contains the given subreg. */
7942 rtl = XEXP (rtl, 0);
7944 /* Fall through. */
7946 case REG:
7947 loc_result = reg_loc_descriptor (rtl);
7948 break;
7950 case MEM:
7951 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7952 break;
7954 case CONCAT:
7955 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7956 break;
7958 default:
7959 abort ();
7962 return loc_result;
7965 /* Similar, but generate the descriptor from trees instead of rtl.
7966 This comes up particularly with variable length arrays. */
7968 static dw_loc_descr_ref
7969 loc_descriptor_from_tree (loc, addressp)
7970 tree loc;
7971 int addressp;
7973 dw_loc_descr_ref ret = NULL;
7974 int indirect_size = 0;
7975 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7976 enum dwarf_location_atom op;
7978 /* ??? Most of the time we do not take proper care for sign/zero
7979 extending the values properly. Hopefully this won't be a real
7980 problem... */
7982 switch (TREE_CODE (loc))
7984 case ERROR_MARK:
7985 break;
7987 case WITH_RECORD_EXPR:
7988 /* This case involves extracting fields from an object to determine the
7989 position of other fields. We don't try to encode this here. The
7990 only user of this is Ada, which encodes the needed information using
7991 the names of types. */
7992 return ret;
7994 case VAR_DECL:
7995 case PARM_DECL:
7997 rtx rtl = rtl_for_decl_location (loc);
7998 enum machine_mode mode = DECL_MODE (loc);
8000 if (rtl == NULL_RTX)
8001 break;
8002 else if (CONSTANT_P (rtl))
8004 ret = new_loc_descr (DW_OP_addr, 0, 0);
8005 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8006 ret->dw_loc_oprnd1.v.val_addr = rtl;
8007 indirect_size = GET_MODE_SIZE (mode);
8009 else
8011 if (GET_CODE (rtl) == MEM)
8013 indirect_size = GET_MODE_SIZE (mode);
8014 rtl = XEXP (rtl, 0);
8016 ret = mem_loc_descriptor (rtl, mode);
8019 break;
8021 case INDIRECT_REF:
8022 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8023 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
8024 break;
8026 case NOP_EXPR:
8027 case CONVERT_EXPR:
8028 case NON_LVALUE_EXPR:
8029 case SAVE_EXPR:
8030 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
8032 case COMPONENT_REF:
8033 case BIT_FIELD_REF:
8034 case ARRAY_REF:
8036 tree obj, offset;
8037 HOST_WIDE_INT bitsize, bitpos, bytepos;
8038 enum machine_mode mode;
8039 int volatilep;
8040 unsigned int alignment;
8042 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
8043 &unsignedp, &volatilep, &alignment);
8044 ret = loc_descriptor_from_tree (obj, 1);
8046 if (offset != NULL_TREE)
8048 /* Variable offset. */
8049 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
8050 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8053 if (addressp)
8055 /* We cannot address anything not on a unit boundary. */
8056 if (bitpos % BITS_PER_UNIT != 0)
8057 abort ();
8059 else
8061 if (bitpos % BITS_PER_UNIT != 0
8062 || bitsize % BITS_PER_UNIT != 0)
8064 /* ??? We could handle this by loading and shifting etc.
8065 Wait until someone needs it before expending the effort. */
8066 abort ();
8069 indirect_size = bitsize / BITS_PER_UNIT;
8072 bytepos = bitpos / BITS_PER_UNIT;
8073 if (bytepos > 0)
8074 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8075 else if (bytepos < 0)
8077 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8078 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8080 break;
8083 case INTEGER_CST:
8084 if (host_integerp (loc, 0))
8085 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8086 break;
8088 case BIT_AND_EXPR:
8089 op = DW_OP_and;
8090 goto do_binop;
8091 case BIT_XOR_EXPR:
8092 op = DW_OP_xor;
8093 goto do_binop;
8094 case BIT_IOR_EXPR:
8095 op = DW_OP_or;
8096 goto do_binop;
8097 case TRUNC_DIV_EXPR:
8098 op = DW_OP_div;
8099 goto do_binop;
8100 case MINUS_EXPR:
8101 op = DW_OP_minus;
8102 goto do_binop;
8103 case TRUNC_MOD_EXPR:
8104 op = DW_OP_mod;
8105 goto do_binop;
8106 case MULT_EXPR:
8107 op = DW_OP_mul;
8108 goto do_binop;
8109 case LSHIFT_EXPR:
8110 op = DW_OP_shl;
8111 goto do_binop;
8112 case RSHIFT_EXPR:
8113 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8114 goto do_binop;
8115 case PLUS_EXPR:
8116 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8117 && host_integerp (TREE_OPERAND (loc, 1), 0))
8119 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8120 add_loc_descr (&ret,
8121 new_loc_descr (DW_OP_plus_uconst,
8122 tree_low_cst (TREE_OPERAND (loc, 1),
8124 0));
8125 break;
8127 op = DW_OP_plus;
8128 goto do_binop;
8129 case LE_EXPR:
8130 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8131 break;
8132 op = DW_OP_le;
8133 goto do_binop;
8134 case GE_EXPR:
8135 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8136 break;
8137 op = DW_OP_ge;
8138 goto do_binop;
8139 case LT_EXPR:
8140 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8141 break;
8142 op = DW_OP_lt;
8143 goto do_binop;
8144 case GT_EXPR:
8145 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8146 break;
8147 op = DW_OP_gt;
8148 goto do_binop;
8149 case EQ_EXPR:
8150 op = DW_OP_eq;
8151 goto do_binop;
8152 case NE_EXPR:
8153 op = DW_OP_ne;
8154 goto do_binop;
8156 do_binop:
8157 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8158 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
8159 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8160 break;
8162 case BIT_NOT_EXPR:
8163 op = DW_OP_not;
8164 goto do_unop;
8165 case ABS_EXPR:
8166 op = DW_OP_abs;
8167 goto do_unop;
8168 case NEGATE_EXPR:
8169 op = DW_OP_neg;
8170 goto do_unop;
8172 do_unop:
8173 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8174 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8175 break;
8177 case MAX_EXPR:
8178 loc = build (COND_EXPR, TREE_TYPE (loc),
8179 build (LT_EXPR, integer_type_node,
8180 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8181 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8182 /* FALLTHRU */
8184 case COND_EXPR:
8186 dw_loc_descr_ref bra_node, jump_node, tmp;
8188 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8189 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8190 add_loc_descr (&ret, bra_node);
8192 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8193 add_loc_descr (&ret, tmp);
8194 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8195 add_loc_descr (&ret, jump_node);
8197 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8198 add_loc_descr (&ret, tmp);
8199 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8200 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
8202 /* ??? Need a node to point the skip at. Use a nop. */
8203 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8204 add_loc_descr (&ret, tmp);
8205 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8206 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8208 break;
8210 default:
8211 abort ();
8214 /* If we can't fill the request for an address, die. */
8215 if (addressp && indirect_size == 0)
8216 abort ();
8218 /* If we've got an address and don't want one, dereference. */
8219 if (!addressp && indirect_size > 0)
8221 if (indirect_size > DWARF2_ADDR_SIZE)
8222 abort ();
8223 if (indirect_size == DWARF2_ADDR_SIZE)
8224 op = DW_OP_deref;
8225 else
8226 op = DW_OP_deref_size;
8227 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
8230 return ret;
8233 /* Given a value, round it up to the lowest multiple of `boundary'
8234 which is not less than the value itself. */
8236 static inline HOST_WIDE_INT
8237 ceiling (value, boundary)
8238 HOST_WIDE_INT value;
8239 unsigned int boundary;
8241 return (((value + boundary - 1) / boundary) * boundary);
8244 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8245 pointer to the declared type for the relevant field variable, or return
8246 `integer_type_node' if the given node turns out to be an
8247 ERROR_MARK node. */
8249 static inline tree
8250 field_type (decl)
8251 register tree decl;
8253 register tree type;
8255 if (TREE_CODE (decl) == ERROR_MARK)
8256 return integer_type_node;
8258 type = DECL_BIT_FIELD_TYPE (decl);
8259 if (type == NULL_TREE)
8260 type = TREE_TYPE (decl);
8262 return type;
8265 /* Given a pointer to a tree node, return the alignment in bits for
8266 it, or else return BITS_PER_WORD if the node actually turns out to
8267 be an ERROR_MARK node. */
8269 static inline unsigned
8270 simple_type_align_in_bits (type)
8271 register tree type;
8273 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8276 static inline unsigned
8277 simple_decl_align_in_bits (decl)
8278 register tree decl;
8280 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8283 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8284 node, return the size in bits for the type if it is a constant, or else
8285 return the alignment for the type if the type's size is not constant, or
8286 else return BITS_PER_WORD if the type actually turns out to be an
8287 ERROR_MARK node. */
8289 static inline unsigned HOST_WIDE_INT
8290 simple_type_size_in_bits (type)
8291 register tree type;
8293 tree type_size_tree;
8295 if (TREE_CODE (type) == ERROR_MARK)
8296 return BITS_PER_WORD;
8297 type_size_tree = TYPE_SIZE (type);
8299 if (type_size_tree == NULL_TREE)
8300 return 0;
8301 if (! host_integerp (type_size_tree, 1))
8302 return TYPE_ALIGN (type);
8303 return tree_low_cst (type_size_tree, 1);
8306 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
8307 return the byte offset of the lowest addressed byte of the "containing
8308 object" for the given FIELD_DECL, or return 0 if we are unable to
8309 determine what that offset is, either because the argument turns out to
8310 be a pointer to an ERROR_MARK node, or because the offset is actually
8311 variable. (We can't handle the latter case just yet). */
8313 static HOST_WIDE_INT
8314 field_byte_offset (decl)
8315 register tree decl;
8317 unsigned int type_align_in_bits;
8318 unsigned int decl_align_in_bits;
8319 unsigned HOST_WIDE_INT type_size_in_bits;
8320 HOST_WIDE_INT object_offset_in_bits;
8321 HOST_WIDE_INT object_offset_in_bytes;
8322 tree type;
8323 tree field_size_tree;
8324 HOST_WIDE_INT bitpos_int;
8325 HOST_WIDE_INT deepest_bitpos;
8326 unsigned HOST_WIDE_INT field_size_in_bits;
8328 if (TREE_CODE (decl) == ERROR_MARK)
8329 return 0;
8331 if (TREE_CODE (decl) != FIELD_DECL)
8332 abort ();
8334 type = field_type (decl);
8335 field_size_tree = DECL_SIZE (decl);
8337 /* The size could be unspecified if there was an error, or for
8338 a flexible array member. */
8339 if (! field_size_tree)
8340 field_size_tree = bitsize_zero_node;
8342 /* We cannot yet cope with fields whose positions are variable, so
8343 for now, when we see such things, we simply return 0. Someday, we may
8344 be able to handle such cases, but it will be damn difficult. */
8345 if (! host_integerp (bit_position (decl), 0))
8346 return 0;
8348 bitpos_int = int_bit_position (decl);
8350 /* If we don't know the size of the field, pretend it's a full word. */
8351 if (host_integerp (field_size_tree, 1))
8352 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8353 else
8354 field_size_in_bits = BITS_PER_WORD;
8356 type_size_in_bits = simple_type_size_in_bits (type);
8357 type_align_in_bits = simple_type_align_in_bits (type);
8358 decl_align_in_bits = simple_decl_align_in_bits (decl);
8360 /* Note that the GCC front-end doesn't make any attempt to keep track of
8361 the starting bit offset (relative to the start of the containing
8362 structure type) of the hypothetical "containing object" for a bit-
8363 field. Thus, when computing the byte offset value for the start of the
8364 "containing object" of a bit-field, we must deduce this information on
8365 our own. This can be rather tricky to do in some cases. For example,
8366 handling the following structure type definition when compiling for an
8367 i386/i486 target (which only aligns long long's to 32-bit boundaries)
8368 can be very tricky:
8370 struct S { int field1; long long field2:31; };
8372 Fortunately, there is a simple rule-of-thumb which can be
8373 used in such cases. When compiling for an i386/i486, GCC will allocate
8374 8 bytes for the structure shown above. It decides to do this based upon
8375 one simple rule for bit-field allocation. Quite simply, GCC allocates
8376 each "containing object" for each bit-field at the first (i.e. lowest
8377 addressed) legitimate alignment boundary (based upon the required
8378 minimum alignment for the declared type of the field) which it can
8379 possibly use, subject to the condition that there is still enough
8380 available space remaining in the containing object (when allocated at
8381 the selected point) to fully accommodate all of the bits of the
8382 bit-field itself. This simple rule makes it obvious why GCC allocates
8383 8 bytes for each object of the structure type shown above. When looking
8384 for a place to allocate the "containing object" for `field2', the
8385 compiler simply tries to allocate a 64-bit "containing object" at each
8386 successive 32-bit boundary (starting at zero) until it finds a place to
8387 allocate that 64- bit field such that at least 31 contiguous (and
8388 previously unallocated) bits remain within that selected 64 bit field.
8389 (As it turns out, for the example above, the compiler finds that it is
8390 OK to allocate the "containing object" 64-bit field at bit-offset zero
8391 within the structure type.) Here we attempt to work backwards from the
8392 limited set of facts we're given, and we try to deduce from those facts,
8393 where GCC must have believed that the containing object started (within
8394 the structure type). The value we deduce is then used (by the callers of
8395 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
8396 for fields (both bit-fields and, in the case of DW_AT_location, regular
8397 fields as well). */
8399 /* Figure out the bit-distance from the start of the structure to the
8400 "deepest" bit of the bit-field. */
8401 deepest_bitpos = bitpos_int + field_size_in_bits;
8403 /* This is the tricky part. Use some fancy footwork to deduce where the
8404 lowest addressed bit of the containing object must be. */
8405 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8407 /* Round up to type_align by default. This works best for bitfields. */
8408 object_offset_in_bits += type_align_in_bits - 1;
8409 object_offset_in_bits /= type_align_in_bits;
8410 object_offset_in_bits *= type_align_in_bits;
8412 if (object_offset_in_bits > bitpos_int)
8414 /* Sigh, the decl must be packed. */
8415 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8417 /* Round up to decl_align instead. */
8418 object_offset_in_bits += decl_align_in_bits - 1;
8419 object_offset_in_bits /= decl_align_in_bits;
8420 object_offset_in_bits *= decl_align_in_bits;
8423 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
8425 return object_offset_in_bytes;
8428 /* The following routines define various Dwarf attributes and any data
8429 associated with them. */
8431 /* Add a location description attribute value to a DIE.
8433 This emits location attributes suitable for whole variables and
8434 whole parameters. Note that the location attributes for struct fields are
8435 generated by the routine `data_member_location_attribute' below. */
8437 static void
8438 add_AT_location_description (die, attr_kind, rtl)
8439 dw_die_ref die;
8440 enum dwarf_attribute attr_kind;
8441 register rtx rtl;
8443 /* Handle a special case. If we are about to output a location descriptor
8444 for a variable or parameter which has been optimized out of existence,
8445 don't do that. A variable which has been optimized out
8446 of existence will have a DECL_RTL value which denotes a pseudo-reg.
8447 Currently, in some rare cases, variables can have DECL_RTL values which
8448 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
8449 elsewhere in the compiler. We treat such cases as if the variable(s) in
8450 question had been optimized out of existence. */
8452 if (is_pseudo_reg (rtl)
8453 || (GET_CODE (rtl) == MEM
8454 && is_pseudo_reg (XEXP (rtl, 0)))
8455 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
8456 references the internal argument pointer (a pseudo) in a function
8457 where all references to the internal argument pointer were
8458 eliminated via the optimizers. */
8459 || (GET_CODE (rtl) == MEM
8460 && GET_CODE (XEXP (rtl, 0)) == PLUS
8461 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
8462 || (GET_CODE (rtl) == CONCAT
8463 && is_pseudo_reg (XEXP (rtl, 0))
8464 && is_pseudo_reg (XEXP (rtl, 1))))
8465 return;
8467 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
8470 /* Attach the specialized form of location attribute used for data
8471 members of struct and union types. In the special case of a
8472 FIELD_DECL node which represents a bit-field, the "offset" part
8473 of this special location descriptor must indicate the distance
8474 in bytes from the lowest-addressed byte of the containing struct
8475 or union type to the lowest-addressed byte of the "containing
8476 object" for the bit-field. (See the `field_byte_offset' function
8477 above).. For any given bit-field, the "containing object" is a
8478 hypothetical object (of some integral or enum type) within which
8479 the given bit-field lives. The type of this hypothetical
8480 "containing object" is always the same as the declared type of
8481 the individual bit-field itself (for GCC anyway... the DWARF
8482 spec doesn't actually mandate this). Note that it is the size
8483 (in bytes) of the hypothetical "containing object" which will
8484 be given in the DW_AT_byte_size attribute for this bit-field.
8485 (See the `byte_size_attribute' function below.) It is also used
8486 when calculating the value of the DW_AT_bit_offset attribute.
8487 (See the `bit_offset_attribute' function below). */
8489 static void
8490 add_data_member_location_attribute (die, decl)
8491 register dw_die_ref die;
8492 register tree decl;
8494 register unsigned long offset;
8495 register dw_loc_descr_ref loc_descr;
8496 register enum dwarf_location_atom op;
8498 if (TREE_CODE (decl) == TREE_VEC)
8499 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8500 else
8501 offset = field_byte_offset (decl);
8503 /* The DWARF2 standard says that we should assume that the structure address
8504 is already on the stack, so we can specify a structure field address
8505 by using DW_OP_plus_uconst. */
8507 #ifdef MIPS_DEBUGGING_INFO
8508 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
8509 correctly. It works only if we leave the offset on the stack. */
8510 op = DW_OP_constu;
8511 #else
8512 op = DW_OP_plus_uconst;
8513 #endif
8515 loc_descr = new_loc_descr (op, offset, 0);
8516 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8519 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8520 does not have a "location" either in memory or in a register. These
8521 things can arise in GNU C when a constant is passed as an actual parameter
8522 to an inlined function. They can also arise in C++ where declared
8523 constants do not necessarily get memory "homes". */
8525 static void
8526 add_const_value_attribute (die, rtl)
8527 register dw_die_ref die;
8528 register rtx rtl;
8530 switch (GET_CODE (rtl))
8532 case CONST_INT:
8533 /* Note that a CONST_INT rtx could represent either an integer or a
8534 floating-point constant. A CONST_INT is used whenever the constant
8535 will fit into a single word. In all such cases, the original mode
8536 of the constant value is wiped out, and the CONST_INT rtx is
8537 assigned VOIDmode. */
8538 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
8539 break;
8541 case CONST_DOUBLE:
8542 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8543 floating-point constant. A CONST_DOUBLE is used whenever the
8544 constant requires more than one word in order to be adequately
8545 represented. We output CONST_DOUBLEs as blocks. */
8547 register enum machine_mode mode = GET_MODE (rtl);
8549 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8551 register unsigned length = GET_MODE_SIZE (mode) / 4;
8552 long *array = (long *) xmalloc (sizeof (long) * length);
8553 REAL_VALUE_TYPE rv;
8555 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8556 switch (mode)
8558 case SFmode:
8559 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8560 break;
8562 case DFmode:
8563 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8564 break;
8566 case XFmode:
8567 case TFmode:
8568 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8569 break;
8571 default:
8572 abort ();
8575 add_AT_float (die, DW_AT_const_value, length, array);
8577 else
8578 add_AT_long_long (die, DW_AT_const_value,
8579 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8581 break;
8583 case CONST_STRING:
8584 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8585 break;
8587 case SYMBOL_REF:
8588 case LABEL_REF:
8589 case CONST:
8590 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8591 break;
8593 case PLUS:
8594 /* In cases where an inlined instance of an inline function is passed
8595 the address of an `auto' variable (which is local to the caller) we
8596 can get a situation where the DECL_RTL of the artificial local
8597 variable (for the inlining) which acts as a stand-in for the
8598 corresponding formal parameter (of the inline function) will look
8599 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8600 exactly a compile-time constant expression, but it isn't the address
8601 of the (artificial) local variable either. Rather, it represents the
8602 *value* which the artificial local variable always has during its
8603 lifetime. We currently have no way to represent such quasi-constant
8604 values in Dwarf, so for now we just punt and generate nothing. */
8605 break;
8607 default:
8608 /* No other kinds of rtx should be possible here. */
8609 abort ();
8614 /* Returns RTL for DECL indicating the location the debugger should
8615 use to find the value of DECL at runtime. Returns NULL_RTX if
8616 there is no such location, or if a satisfactory location could not
8617 be determined. */
8619 static rtx
8620 rtl_for_decl_location (decl)
8621 tree decl;
8623 register rtx rtl;
8625 /* This function should not be called with an abstract declaration,
8626 since such things have no location. */
8627 if (DECL_ABSTRACT (decl))
8628 abort ();
8630 /* Here we have to decide where we are going to say the parameter "lives"
8631 (as far as the debugger is concerned). We only have a couple of
8632 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8634 DECL_RTL normally indicates where the parameter lives during most of the
8635 activation of the function. If optimization is enabled however, this
8636 could be either NULL or else a pseudo-reg. Both of those cases indicate
8637 that the parameter doesn't really live anywhere (as far as the code
8638 generation parts of GCC are concerned) during most of the function's
8639 activation. That will happen (for example) if the parameter is never
8640 referenced within the function.
8642 We could just generate a location descriptor here for all non-NULL
8643 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8644 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8645 where DECL_RTL is NULL or is a pseudo-reg.
8647 Note however that we can only get away with using DECL_INCOMING_RTL as
8648 a backup substitute for DECL_RTL in certain limited cases. In cases
8649 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8650 we can be sure that the parameter was passed using the same type as it is
8651 declared to have within the function, and that its DECL_INCOMING_RTL
8652 points us to a place where a value of that type is passed.
8654 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8655 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8656 because in these cases DECL_INCOMING_RTL points us to a value of some
8657 type which is *different* from the type of the parameter itself. Thus,
8658 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8659 such cases, the debugger would end up (for example) trying to fetch a
8660 `float' from a place which actually contains the first part of a
8661 `double'. That would lead to really incorrect and confusing
8662 output at debug-time.
8664 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8665 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8666 are a couple of exceptions however. On little-endian machines we can
8667 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8668 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8669 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8670 when (on a little-endian machine) a non-prototyped function has a
8671 parameter declared to be of type `short' or `char'. In such cases,
8672 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8673 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8674 passed `int' value. If the debugger then uses that address to fetch
8675 a `short' or a `char' (on a little-endian machine) the result will be
8676 the correct data, so we allow for such exceptional cases below.
8678 Note that our goal here is to describe the place where the given formal
8679 parameter lives during most of the function's activation (i.e. between
8680 the end of the prologue and the start of the epilogue). We'll do that
8681 as best as we can. Note however that if the given formal parameter is
8682 modified sometime during the execution of the function, then a stack
8683 backtrace (at debug-time) will show the function as having been
8684 called with the *new* value rather than the value which was
8685 originally passed in. This happens rarely enough that it is not
8686 a major problem, but it *is* a problem, and I'd like to fix it.
8688 A future version of dwarf2out.c may generate two additional
8689 attributes for any given DW_TAG_formal_parameter DIE which will
8690 describe the "passed type" and the "passed location" for the
8691 given formal parameter in addition to the attributes we now
8692 generate to indicate the "declared type" and the "active
8693 location" for each parameter. This additional set of attributes
8694 could be used by debuggers for stack backtraces. Separately, note
8695 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8696 NULL also. This happens (for example) for inlined-instances of
8697 inline function formal parameters which are never referenced.
8698 This really shouldn't be happening. All PARM_DECL nodes should
8699 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8700 doesn't currently generate these values for inlined instances of
8701 inline function parameters, so when we see such cases, we are
8702 just out-of-luck for the time being (until integrate.c
8703 gets fixed). */
8705 /* Use DECL_RTL as the "location" unless we find something better. */
8706 rtl = DECL_RTL_IF_SET (decl);
8708 if (TREE_CODE (decl) == PARM_DECL)
8710 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8712 tree declared_type = type_main_variant (TREE_TYPE (decl));
8713 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8715 /* This decl represents a formal parameter which was optimized out.
8716 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8717 all* cases where (rtl == NULL_RTX) just below. */
8718 if (declared_type == passed_type)
8719 rtl = DECL_INCOMING_RTL (decl);
8720 else if (! BYTES_BIG_ENDIAN
8721 && TREE_CODE (declared_type) == INTEGER_TYPE
8722 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8723 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8724 rtl = DECL_INCOMING_RTL (decl);
8727 /* If the parm was passed in registers, but lives on the stack, then
8728 make a big endian correction if the mode of the type of the
8729 parameter is not the same as the mode of the rtl. */
8730 /* ??? This is the same series of checks that are made in dbxout.c before
8731 we reach the big endian correction code there. It isn't clear if all
8732 of these checks are necessary here, but keeping them all is the safe
8733 thing to do. */
8734 else if (GET_CODE (rtl) == MEM
8735 && XEXP (rtl, 0) != const0_rtx
8736 && ! CONSTANT_P (XEXP (rtl, 0))
8737 /* Not passed in memory. */
8738 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8739 /* Not passed by invisible reference. */
8740 && (GET_CODE (XEXP (rtl, 0)) != REG
8741 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8742 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8743 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8744 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8745 #endif
8747 /* Big endian correction check. */
8748 && BYTES_BIG_ENDIAN
8749 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8750 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8751 < UNITS_PER_WORD))
8753 int offset = (UNITS_PER_WORD
8754 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8755 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8756 plus_constant (XEXP (rtl, 0), offset));
8760 if (rtl != NULL_RTX)
8762 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8763 #ifdef LEAF_REG_REMAP
8764 if (current_function_uses_only_leaf_regs)
8765 leaf_renumber_regs_insn (rtl);
8766 #endif
8769 return rtl;
8772 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8773 data attribute for a variable or a parameter. We generate the
8774 DW_AT_const_value attribute only in those cases where the given variable
8775 or parameter does not have a true "location" either in memory or in a
8776 register. This can happen (for example) when a constant is passed as an
8777 actual argument in a call to an inline function. (It's possible that
8778 these things can crop up in other ways also.) Note that one type of
8779 constant value which can be passed into an inlined function is a constant
8780 pointer. This can happen for example if an actual argument in an inlined
8781 function call evaluates to a compile-time constant address. */
8783 static void
8784 add_location_or_const_value_attribute (die, decl)
8785 register dw_die_ref die;
8786 register tree decl;
8788 register rtx rtl;
8790 if (TREE_CODE (decl) == ERROR_MARK)
8791 return;
8793 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8794 abort ();
8796 rtl = rtl_for_decl_location (decl);
8797 if (rtl == NULL_RTX)
8798 return;
8800 switch (GET_CODE (rtl))
8802 case ADDRESSOF:
8803 /* The address of a variable that was optimized away; don't emit
8804 anything. */
8805 break;
8807 case CONST_INT:
8808 case CONST_DOUBLE:
8809 case CONST_STRING:
8810 case SYMBOL_REF:
8811 case LABEL_REF:
8812 case CONST:
8813 case PLUS:
8814 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8815 add_const_value_attribute (die, rtl);
8816 break;
8818 case MEM:
8819 case REG:
8820 case SUBREG:
8821 case CONCAT:
8822 add_AT_location_description (die, DW_AT_location, rtl);
8823 break;
8825 default:
8826 abort ();
8830 /* If we don't have a copy of this variable in memory for some reason (such
8831 as a C++ member constant that doesn't have an out-of-line definition),
8832 we should tell the debugger about the constant value. */
8834 static void
8835 tree_add_const_value_attribute (var_die, decl)
8836 dw_die_ref var_die;
8837 tree decl;
8839 tree init = DECL_INITIAL (decl);
8840 tree type = TREE_TYPE (decl);
8842 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8843 && initializer_constant_valid_p (init, type) == null_pointer_node)
8844 /* OK */;
8845 else
8846 return;
8848 switch (TREE_CODE (type))
8850 case INTEGER_TYPE:
8851 if (host_integerp (init, 0))
8852 add_AT_unsigned (var_die, DW_AT_const_value,
8853 TREE_INT_CST_LOW (init));
8854 else
8855 add_AT_long_long (var_die, DW_AT_const_value,
8856 TREE_INT_CST_HIGH (init),
8857 TREE_INT_CST_LOW (init));
8858 break;
8860 default:;
8864 /* Generate an DW_AT_name attribute given some string value to be included as
8865 the value of the attribute. */
8867 static inline void
8868 add_name_attribute (die, name_string)
8869 register dw_die_ref die;
8870 register const char *name_string;
8872 if (name_string != NULL && *name_string != 0)
8874 if (demangle_name_func)
8875 name_string = (*demangle_name_func) (name_string);
8877 add_AT_string (die, DW_AT_name, name_string);
8881 /* Given a tree node describing an array bound (either lower or upper) output
8882 a representation for that bound. */
8884 static void
8885 add_bound_info (subrange_die, bound_attr, bound)
8886 register dw_die_ref subrange_die;
8887 register enum dwarf_attribute bound_attr;
8888 register tree bound;
8890 /* If this is an Ada unconstrained array type, then don't emit any debug
8891 info because the array bounds are unknown. They are parameterized when
8892 the type is instantiated. */
8893 if (contains_placeholder_p (bound))
8894 return;
8896 switch (TREE_CODE (bound))
8898 case ERROR_MARK:
8899 return;
8901 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8902 case INTEGER_CST:
8903 if (! host_integerp (bound, 0)
8904 || (bound_attr == DW_AT_lower_bound
8905 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8906 || (is_fortran () && integer_onep (bound)))))
8907 /* use the default */
8909 else
8910 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8911 break;
8913 case CONVERT_EXPR:
8914 case NOP_EXPR:
8915 case NON_LVALUE_EXPR:
8916 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8917 break;
8919 case SAVE_EXPR:
8920 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8921 access the upper bound values may be bogus. If they refer to a
8922 register, they may only describe how to get at these values at the
8923 points in the generated code right after they have just been
8924 computed. Worse yet, in the typical case, the upper bound values
8925 will not even *be* computed in the optimized code (though the
8926 number of elements will), so these SAVE_EXPRs are entirely
8927 bogus. In order to compensate for this fact, we check here to see
8928 if optimization is enabled, and if so, we don't add an attribute
8929 for the (unknown and unknowable) upper bound. This should not
8930 cause too much trouble for existing (stupid?) debuggers because
8931 they have to deal with empty upper bounds location descriptions
8932 anyway in order to be able to deal with incomplete array types.
8933 Of course an intelligent debugger (GDB?) should be able to
8934 comprehend that a missing upper bound specification in a array
8935 type used for a storage class `auto' local array variable
8936 indicates that the upper bound is both unknown (at compile- time)
8937 and unknowable (at run-time) due to optimization.
8939 We assume that a MEM rtx is safe because gcc wouldn't put the
8940 value there unless it was going to be used repeatedly in the
8941 function, i.e. for cleanups. */
8942 if (SAVE_EXPR_RTL (bound)
8943 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8945 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8946 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8947 register rtx loc = SAVE_EXPR_RTL (bound);
8949 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8950 it references an outer function's frame. */
8952 if (GET_CODE (loc) == MEM)
8954 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8956 if (XEXP (loc, 0) != new_addr)
8957 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8960 add_AT_flag (decl_die, DW_AT_artificial, 1);
8961 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8962 add_AT_location_description (decl_die, DW_AT_location, loc);
8963 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8966 /* Else leave out the attribute. */
8967 break;
8969 case VAR_DECL:
8970 case PARM_DECL:
8972 dw_die_ref decl_die = lookup_decl_die (bound);
8974 /* ??? Can this happen, or should the variable have been bound
8975 first? Probably it can, since I imagine that we try to create
8976 the types of parameters in the order in which they exist in
8977 the list, and won't have created a forward reference to a
8978 later parameter. */
8979 if (decl_die != NULL)
8980 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8981 break;
8984 default:
8986 /* Otherwise try to create a stack operation procedure to
8987 evaluate the value of the array bound. */
8989 dw_die_ref ctx, decl_die;
8990 dw_loc_descr_ref loc;
8992 /* If the CURRENT_FUNCTION_DECL is abstract, then we cannot
8993 compute the array bound based on the location of the BOUND,
8994 since the BOUND does not really exist. Therefore, we
8995 simply omit the bound information.
8997 Ideally, we would do better, and express the computation in
8998 some other way. */
8999 if (DECL_ABSTRACT (current_function_decl))
9000 break;
9002 loc = loc_descriptor_from_tree (bound, 0);
9003 if (loc == NULL)
9004 break;
9006 ctx = lookup_decl_die (current_function_decl);
9008 decl_die = new_die (DW_TAG_variable, ctx);
9009 add_AT_flag (decl_die, DW_AT_artificial, 1);
9010 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9011 add_AT_loc (decl_die, DW_AT_location, loc);
9013 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9014 break;
9019 /* Note that the block of subscript information for an array type also
9020 includes information about the element type of type given array type. */
9022 static void
9023 add_subscript_info (type_die, type)
9024 register dw_die_ref type_die;
9025 register tree type;
9027 #ifndef MIPS_DEBUGGING_INFO
9028 register unsigned dimension_number;
9029 #endif
9030 register tree lower, upper;
9031 register dw_die_ref subrange_die;
9033 /* The GNU compilers represent multidimensional array types as sequences of
9034 one dimensional array types whose element types are themselves array
9035 types. Here we squish that down, so that each multidimensional array
9036 type gets only one array_type DIE in the Dwarf debugging info. The draft
9037 Dwarf specification say that we are allowed to do this kind of
9038 compression in C (because there is no difference between an array or
9039 arrays and a multidimensional array in C) but for other source languages
9040 (e.g. Ada) we probably shouldn't do this. */
9042 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9043 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9044 We work around this by disabling this feature. See also
9045 gen_array_type_die. */
9046 #ifndef MIPS_DEBUGGING_INFO
9047 for (dimension_number = 0;
9048 TREE_CODE (type) == ARRAY_TYPE;
9049 type = TREE_TYPE (type), dimension_number++)
9051 #endif
9052 register tree domain = TYPE_DOMAIN (type);
9054 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9055 and (in GNU C only) variable bounds. Handle all three forms
9056 here. */
9057 subrange_die = new_die (DW_TAG_subrange_type, type_die);
9058 if (domain)
9060 /* We have an array type with specified bounds. */
9061 lower = TYPE_MIN_VALUE (domain);
9062 upper = TYPE_MAX_VALUE (domain);
9064 /* define the index type. */
9065 if (TREE_TYPE (domain))
9067 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9068 TREE_TYPE field. We can't emit debug info for this
9069 because it is an unnamed integral type. */
9070 if (TREE_CODE (domain) == INTEGER_TYPE
9071 && TYPE_NAME (domain) == NULL_TREE
9072 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9073 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
9075 else
9076 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9077 type_die);
9080 /* ??? If upper is NULL, the array has unspecified length,
9081 but it does have a lower bound. This happens with Fortran
9082 dimension arr(N:*)
9083 Since the debugger is definitely going to need to know N
9084 to produce useful results, go ahead and output the lower
9085 bound solo, and hope the debugger can cope. */
9087 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
9088 if (upper)
9089 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
9091 else
9092 /* We have an array type with an unspecified length. The DWARF-2
9093 spec does not say how to handle this; let's just leave out the
9094 bounds. */
9097 #ifndef MIPS_DEBUGGING_INFO
9099 #endif
9102 static void
9103 add_byte_size_attribute (die, tree_node)
9104 dw_die_ref die;
9105 register tree tree_node;
9107 register unsigned size;
9109 switch (TREE_CODE (tree_node))
9111 case ERROR_MARK:
9112 size = 0;
9113 break;
9114 case ENUMERAL_TYPE:
9115 case RECORD_TYPE:
9116 case UNION_TYPE:
9117 case QUAL_UNION_TYPE:
9118 size = int_size_in_bytes (tree_node);
9119 break;
9120 case FIELD_DECL:
9121 /* For a data member of a struct or union, the DW_AT_byte_size is
9122 generally given as the number of bytes normally allocated for an
9123 object of the *declared* type of the member itself. This is true
9124 even for bit-fields. */
9125 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9126 break;
9127 default:
9128 abort ();
9131 /* Note that `size' might be -1 when we get to this point. If it is, that
9132 indicates that the byte size of the entity in question is variable. We
9133 have no good way of expressing this fact in Dwarf at the present time,
9134 so just let the -1 pass on through. */
9136 add_AT_unsigned (die, DW_AT_byte_size, size);
9139 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9140 which specifies the distance in bits from the highest order bit of the
9141 "containing object" for the bit-field to the highest order bit of the
9142 bit-field itself.
9144 For any given bit-field, the "containing object" is a hypothetical
9145 object (of some integral or enum type) within which the given bit-field
9146 lives. The type of this hypothetical "containing object" is always the
9147 same as the declared type of the individual bit-field itself. The
9148 determination of the exact location of the "containing object" for a
9149 bit-field is rather complicated. It's handled by the
9150 `field_byte_offset' function (above).
9152 Note that it is the size (in bytes) of the hypothetical "containing object"
9153 which will be given in the DW_AT_byte_size attribute for this bit-field.
9154 (See `byte_size_attribute' above). */
9156 static inline void
9157 add_bit_offset_attribute (die, decl)
9158 register dw_die_ref die;
9159 register tree decl;
9161 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9162 tree type = DECL_BIT_FIELD_TYPE (decl);
9163 HOST_WIDE_INT bitpos_int;
9164 HOST_WIDE_INT highest_order_object_bit_offset;
9165 HOST_WIDE_INT highest_order_field_bit_offset;
9166 HOST_WIDE_INT unsigned bit_offset;
9168 /* Must be a field and a bit field. */
9169 if (!type
9170 || TREE_CODE (decl) != FIELD_DECL)
9171 abort ();
9173 /* We can't yet handle bit-fields whose offsets are variable, so if we
9174 encounter such things, just return without generating any attribute
9175 whatsoever. Likewise for variable or too large size. */
9176 if (! host_integerp (bit_position (decl), 0)
9177 || ! host_integerp (DECL_SIZE (decl), 1))
9178 return;
9180 bitpos_int = int_bit_position (decl);
9182 /* Note that the bit offset is always the distance (in bits) from the
9183 highest-order bit of the "containing object" to the highest-order bit of
9184 the bit-field itself. Since the "high-order end" of any object or field
9185 is different on big-endian and little-endian machines, the computation
9186 below must take account of these differences. */
9187 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9188 highest_order_field_bit_offset = bitpos_int;
9190 if (! BYTES_BIG_ENDIAN)
9192 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9193 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9196 bit_offset
9197 = (! BYTES_BIG_ENDIAN
9198 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9199 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9201 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9204 /* For a FIELD_DECL node which represents a bit field, output an attribute
9205 which specifies the length in bits of the given field. */
9207 static inline void
9208 add_bit_size_attribute (die, decl)
9209 register dw_die_ref die;
9210 register tree decl;
9212 /* Must be a field and a bit field. */
9213 if (TREE_CODE (decl) != FIELD_DECL
9214 || ! DECL_BIT_FIELD_TYPE (decl))
9215 abort ();
9217 if (host_integerp (DECL_SIZE (decl), 1))
9218 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9221 /* If the compiled language is ANSI C, then add a 'prototyped'
9222 attribute, if arg types are given for the parameters of a function. */
9224 static inline void
9225 add_prototyped_attribute (die, func_type)
9226 register dw_die_ref die;
9227 register tree func_type;
9229 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9230 && TYPE_ARG_TYPES (func_type) != NULL)
9231 add_AT_flag (die, DW_AT_prototyped, 1);
9234 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9235 by looking in either the type declaration or object declaration
9236 equate table. */
9238 static inline void
9239 add_abstract_origin_attribute (die, origin)
9240 register dw_die_ref die;
9241 register tree origin;
9243 dw_die_ref origin_die = NULL;
9245 if (TREE_CODE (origin) != FUNCTION_DECL)
9247 /* We may have gotten separated from the block for the inlined
9248 function, if we're in an exception handler or some such; make
9249 sure that the abstract function has been written out.
9251 Doing this for nested functions is wrong, however; functions are
9252 distinct units, and our context might not even be inline. */
9253 tree fn = origin;
9254 if (TYPE_P (fn))
9255 fn = TYPE_STUB_DECL (fn);
9256 fn = decl_function_context (fn);
9257 if (fn)
9258 dwarf2out_abstract_function (fn);
9261 if (DECL_P (origin))
9262 origin_die = lookup_decl_die (origin);
9263 else if (TYPE_P (origin))
9264 origin_die = lookup_type_die (origin);
9266 if (origin_die == NULL)
9267 abort ();
9269 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9272 /* We do not currently support the pure_virtual attribute. */
9274 static inline void
9275 add_pure_or_virtual_attribute (die, func_decl)
9276 register dw_die_ref die;
9277 register tree func_decl;
9279 if (DECL_VINDEX (func_decl))
9281 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9283 if (host_integerp (DECL_VINDEX (func_decl), 0))
9284 add_AT_loc (die, DW_AT_vtable_elem_location,
9285 new_loc_descr (DW_OP_constu,
9286 tree_low_cst (DECL_VINDEX (func_decl), 0),
9287 0));
9289 /* GNU extension: Record what type this method came from originally. */
9290 if (debug_info_level > DINFO_LEVEL_TERSE)
9291 add_AT_die_ref (die, DW_AT_containing_type,
9292 lookup_type_die (DECL_CONTEXT (func_decl)));
9296 /* Add source coordinate attributes for the given decl. */
9298 static void
9299 add_src_coords_attributes (die, decl)
9300 register dw_die_ref die;
9301 register tree decl;
9303 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9305 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9306 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9309 /* Add an DW_AT_name attribute and source coordinate attribute for the
9310 given decl, but only if it actually has a name. */
9312 static void
9313 add_name_and_src_coords_attributes (die, decl)
9314 register dw_die_ref die;
9315 register tree decl;
9317 register tree decl_name;
9319 decl_name = DECL_NAME (decl);
9320 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9322 add_name_attribute (die, dwarf2_name (decl, 0));
9323 if (! DECL_ARTIFICIAL (decl))
9324 add_src_coords_attributes (die, decl);
9326 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9327 && TREE_PUBLIC (decl)
9328 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9329 && !DECL_ABSTRACT (decl))
9330 add_AT_string (die, DW_AT_MIPS_linkage_name,
9331 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9335 /* Push a new declaration scope. */
9337 static void
9338 push_decl_scope (scope)
9339 tree scope;
9341 /* Make room in the decl_scope_table, if necessary. */
9342 if (decl_scope_table_allocated == decl_scope_depth)
9344 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
9345 decl_scope_table
9346 = (tree *) xrealloc (decl_scope_table,
9347 decl_scope_table_allocated * sizeof (tree));
9350 decl_scope_table[decl_scope_depth] = scope;
9351 decl_scope_depth++;
9354 /* Pop a declaration scope. */
9355 static inline void
9356 pop_decl_scope ()
9358 if (decl_scope_depth <= 0)
9359 abort ();
9360 --decl_scope_depth;
9363 /* Return the DIE for the scope that immediately contains this type.
9364 Non-named types get global scope. Named types nested in other
9365 types get their containing scope if it's open, or global scope
9366 otherwise. All other types (i.e. function-local named types) get
9367 the current active scope. */
9369 static dw_die_ref
9370 scope_die_for (t, context_die)
9371 register tree t;
9372 register dw_die_ref context_die;
9374 register dw_die_ref scope_die = NULL;
9375 register tree containing_scope;
9376 register int i;
9378 /* Non-types always go in the current scope. */
9379 if (! TYPE_P (t))
9380 abort ();
9382 containing_scope = TYPE_CONTEXT (t);
9384 /* Ignore namespaces for the moment. */
9385 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9386 containing_scope = NULL_TREE;
9388 /* Ignore function type "scopes" from the C frontend. They mean that
9389 a tagged type is local to a parmlist of a function declarator, but
9390 that isn't useful to DWARF. */
9391 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9392 containing_scope = NULL_TREE;
9394 if (containing_scope == NULL_TREE)
9395 scope_die = comp_unit_die;
9396 else if (TYPE_P (containing_scope))
9398 /* For types, we can just look up the appropriate DIE. But
9399 first we check to see if we're in the middle of emitting it
9400 so we know where the new DIE should go. */
9402 for (i = decl_scope_depth - 1; i >= 0; --i)
9403 if (decl_scope_table[i] == containing_scope)
9404 break;
9406 if (i < 0)
9408 if (debug_info_level > DINFO_LEVEL_TERSE
9409 && !TREE_ASM_WRITTEN (containing_scope))
9410 abort ();
9412 /* If none of the current dies are suitable, we get file scope. */
9413 scope_die = comp_unit_die;
9415 else
9416 scope_die = lookup_type_die (containing_scope);
9418 else
9419 scope_die = context_die;
9421 return scope_die;
9424 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
9426 static inline int local_scope_p PARAMS ((dw_die_ref));
9427 static inline int
9428 local_scope_p (context_die)
9429 dw_die_ref context_die;
9431 for (; context_die; context_die = context_die->die_parent)
9432 if (context_die->die_tag == DW_TAG_inlined_subroutine
9433 || context_die->die_tag == DW_TAG_subprogram)
9434 return 1;
9435 return 0;
9438 /* Returns nonzero iff CONTEXT_DIE is a class. */
9440 static inline int class_scope_p PARAMS ((dw_die_ref));
9441 static inline int
9442 class_scope_p (context_die)
9443 dw_die_ref context_die;
9445 return (context_die
9446 && (context_die->die_tag == DW_TAG_structure_type
9447 || context_die->die_tag == DW_TAG_union_type));
9450 /* Many forms of DIEs require a "type description" attribute. This
9451 routine locates the proper "type descriptor" die for the type given
9452 by 'type', and adds an DW_AT_type attribute below the given die. */
9454 static void
9455 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9456 register dw_die_ref object_die;
9457 register tree type;
9458 register int decl_const;
9459 register int decl_volatile;
9460 register dw_die_ref context_die;
9462 register enum tree_code code = TREE_CODE (type);
9463 register dw_die_ref type_die = NULL;
9465 /* ??? If this type is an unnamed subrange type of an integral or
9466 floating-point type, use the inner type. This is because we have no
9467 support for unnamed types in base_type_die. This can happen if this is
9468 an Ada subrange type. Correct solution is emit a subrange type die. */
9469 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9470 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9471 type = TREE_TYPE (type), code = TREE_CODE (type);
9473 if (code == ERROR_MARK)
9474 return;
9476 /* Handle a special case. For functions whose return type is void, we
9477 generate *no* type attribute. (Note that no object may have type
9478 `void', so this only applies to function return types). */
9479 if (code == VOID_TYPE)
9480 return;
9482 type_die = modified_type_die (type,
9483 decl_const || TYPE_READONLY (type),
9484 decl_volatile || TYPE_VOLATILE (type),
9485 context_die);
9486 if (type_die != NULL)
9487 add_AT_die_ref (object_die, DW_AT_type, type_die);
9490 /* Given a tree pointer to a struct, class, union, or enum type node, return
9491 a pointer to the (string) tag name for the given type, or zero if the type
9492 was declared without a tag. */
9494 static const char *
9495 type_tag (type)
9496 register tree type;
9498 register const char *name = 0;
9500 if (TYPE_NAME (type) != 0)
9502 register tree t = 0;
9504 /* Find the IDENTIFIER_NODE for the type name. */
9505 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9506 t = TYPE_NAME (type);
9508 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9509 a TYPE_DECL node, regardless of whether or not a `typedef' was
9510 involved. */
9511 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9512 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9513 t = DECL_NAME (TYPE_NAME (type));
9515 /* Now get the name as a string, or invent one. */
9516 if (t != 0)
9517 name = IDENTIFIER_POINTER (t);
9520 return (name == 0 || *name == '\0') ? 0 : name;
9523 /* Return the type associated with a data member, make a special check
9524 for bit field types. */
9526 static inline tree
9527 member_declared_type (member)
9528 register tree member;
9530 return (DECL_BIT_FIELD_TYPE (member)
9531 ? DECL_BIT_FIELD_TYPE (member)
9532 : TREE_TYPE (member));
9535 /* Get the decl's label, as described by its RTL. This may be different
9536 from the DECL_NAME name used in the source file. */
9538 #if 0
9539 static const char *
9540 decl_start_label (decl)
9541 register tree decl;
9543 rtx x;
9544 const char *fnname;
9545 x = DECL_RTL (decl);
9546 if (GET_CODE (x) != MEM)
9547 abort ();
9549 x = XEXP (x, 0);
9550 if (GET_CODE (x) != SYMBOL_REF)
9551 abort ();
9553 fnname = XSTR (x, 0);
9554 return fnname;
9556 #endif
9558 /* These routines generate the internal representation of the DIE's for
9559 the compilation unit. Debugging information is collected by walking
9560 the declaration trees passed in from dwarf2out_decl(). */
9562 static void
9563 gen_array_type_die (type, context_die)
9564 register tree type;
9565 register dw_die_ref context_die;
9567 register dw_die_ref scope_die = scope_die_for (type, context_die);
9568 register dw_die_ref array_die;
9569 register tree element_type;
9571 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9572 the inner array type comes before the outer array type. Thus we must
9573 call gen_type_die before we call new_die. See below also. */
9574 #ifdef MIPS_DEBUGGING_INFO
9575 gen_type_die (TREE_TYPE (type), context_die);
9576 #endif
9578 array_die = new_die (DW_TAG_array_type, scope_die);
9580 #if 0
9581 /* We default the array ordering. SDB will probably do
9582 the right things even if DW_AT_ordering is not present. It's not even
9583 an issue until we start to get into multidimensional arrays anyway. If
9584 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9585 then we'll have to put the DW_AT_ordering attribute back in. (But if
9586 and when we find out that we need to put these in, we will only do so
9587 for multidimensional arrays. */
9588 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9589 #endif
9591 #ifdef MIPS_DEBUGGING_INFO
9592 /* The SGI compilers handle arrays of unknown bound by setting
9593 AT_declaration and not emitting any subrange DIEs. */
9594 if (! TYPE_DOMAIN (type))
9595 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9596 else
9597 #endif
9598 add_subscript_info (array_die, type);
9600 add_name_attribute (array_die, type_tag (type));
9601 equate_type_number_to_die (type, array_die);
9603 /* Add representation of the type of the elements of this array type. */
9604 element_type = TREE_TYPE (type);
9606 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9607 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9608 We work around this by disabling this feature. See also
9609 add_subscript_info. */
9610 #ifndef MIPS_DEBUGGING_INFO
9611 while (TREE_CODE (element_type) == ARRAY_TYPE)
9612 element_type = TREE_TYPE (element_type);
9614 gen_type_die (element_type, context_die);
9615 #endif
9617 add_type_attribute (array_die, element_type, 0, 0, context_die);
9620 static void
9621 gen_set_type_die (type, context_die)
9622 register tree type;
9623 register dw_die_ref context_die;
9625 register dw_die_ref type_die
9626 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9628 equate_type_number_to_die (type, type_die);
9629 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9632 #if 0
9633 static void
9634 gen_entry_point_die (decl, context_die)
9635 register tree decl;
9636 register dw_die_ref context_die;
9638 register tree origin = decl_ultimate_origin (decl);
9639 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9640 if (origin != NULL)
9641 add_abstract_origin_attribute (decl_die, origin);
9642 else
9644 add_name_and_src_coords_attributes (decl_die, decl);
9645 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9646 0, 0, context_die);
9649 if (DECL_ABSTRACT (decl))
9650 equate_decl_number_to_die (decl, decl_die);
9651 else
9652 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9654 #endif
9656 /* Remember a type in the incomplete_types_list. */
9658 static void
9659 add_incomplete_type (type)
9660 tree type;
9662 if (incomplete_types == incomplete_types_allocated)
9664 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
9665 incomplete_types_list
9666 = (tree *) xrealloc (incomplete_types_list,
9667 sizeof (tree) * incomplete_types_allocated);
9670 incomplete_types_list[incomplete_types++] = type;
9673 /* Walk through the list of incomplete types again, trying once more to
9674 emit full debugging info for them. */
9676 static void
9677 retry_incomplete_types ()
9679 register tree type;
9681 while (incomplete_types)
9683 --incomplete_types;
9684 type = incomplete_types_list[incomplete_types];
9685 gen_type_die (type, comp_unit_die);
9689 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9691 static void
9692 gen_inlined_enumeration_type_die (type, context_die)
9693 register tree type;
9694 register dw_die_ref context_die;
9696 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9697 context_die);
9698 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9699 be incomplete and such types are not marked. */
9700 add_abstract_origin_attribute (type_die, type);
9703 /* Generate a DIE to represent an inlined instance of a structure type. */
9705 static void
9706 gen_inlined_structure_type_die (type, context_die)
9707 register tree type;
9708 register dw_die_ref context_die;
9710 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9712 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9713 be incomplete and such types are not marked. */
9714 add_abstract_origin_attribute (type_die, type);
9717 /* Generate a DIE to represent an inlined instance of a union type. */
9719 static void
9720 gen_inlined_union_type_die (type, context_die)
9721 register tree type;
9722 register dw_die_ref context_die;
9724 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9726 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9727 be incomplete and such types are not marked. */
9728 add_abstract_origin_attribute (type_die, type);
9731 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9732 include all of the information about the enumeration values also. Each
9733 enumerated type name/value is listed as a child of the enumerated type
9734 DIE. */
9736 static void
9737 gen_enumeration_type_die (type, context_die)
9738 register tree type;
9739 register dw_die_ref context_die;
9741 register dw_die_ref type_die = lookup_type_die (type);
9743 if (type_die == NULL)
9745 type_die = new_die (DW_TAG_enumeration_type,
9746 scope_die_for (type, context_die));
9747 equate_type_number_to_die (type, type_die);
9748 add_name_attribute (type_die, type_tag (type));
9750 else if (! TYPE_SIZE (type))
9751 return;
9752 else
9753 remove_AT (type_die, DW_AT_declaration);
9755 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9756 given enum type is incomplete, do not generate the DW_AT_byte_size
9757 attribute or the DW_AT_element_list attribute. */
9758 if (TYPE_SIZE (type))
9760 register tree link;
9762 TREE_ASM_WRITTEN (type) = 1;
9763 add_byte_size_attribute (type_die, type);
9764 if (TYPE_STUB_DECL (type) != NULL_TREE)
9765 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9767 /* If the first reference to this type was as the return type of an
9768 inline function, then it may not have a parent. Fix this now. */
9769 if (type_die->die_parent == NULL)
9770 add_child_die (scope_die_for (type, context_die), type_die);
9772 for (link = TYPE_FIELDS (type);
9773 link != NULL; link = TREE_CHAIN (link))
9775 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9777 add_name_attribute (enum_die,
9778 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9780 if (host_integerp (TREE_VALUE (link), 0))
9782 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9783 add_AT_int (enum_die, DW_AT_const_value,
9784 tree_low_cst (TREE_VALUE (link), 0));
9785 else
9786 add_AT_unsigned (enum_die, DW_AT_const_value,
9787 tree_low_cst (TREE_VALUE (link), 0));
9791 else
9792 add_AT_flag (type_die, DW_AT_declaration, 1);
9795 /* Generate a DIE to represent either a real live formal parameter decl or to
9796 represent just the type of some formal parameter position in some function
9797 type.
9799 Note that this routine is a bit unusual because its argument may be a
9800 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9801 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9802 node. If it's the former then this function is being called to output a
9803 DIE to represent a formal parameter object (or some inlining thereof). If
9804 it's the latter, then this function is only being called to output a
9805 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9806 argument type of some subprogram type. */
9808 static dw_die_ref
9809 gen_formal_parameter_die (node, context_die)
9810 register tree node;
9811 register dw_die_ref context_die;
9813 register dw_die_ref parm_die
9814 = new_die (DW_TAG_formal_parameter, context_die);
9815 register tree origin;
9817 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9819 case 'd':
9820 origin = decl_ultimate_origin (node);
9821 if (origin != NULL)
9822 add_abstract_origin_attribute (parm_die, origin);
9823 else
9825 add_name_and_src_coords_attributes (parm_die, node);
9826 add_type_attribute (parm_die, TREE_TYPE (node),
9827 TREE_READONLY (node),
9828 TREE_THIS_VOLATILE (node),
9829 context_die);
9830 if (DECL_ARTIFICIAL (node))
9831 add_AT_flag (parm_die, DW_AT_artificial, 1);
9834 equate_decl_number_to_die (node, parm_die);
9835 if (! DECL_ABSTRACT (node))
9836 add_location_or_const_value_attribute (parm_die, node);
9838 break;
9840 case 't':
9841 /* We were called with some kind of a ..._TYPE node. */
9842 add_type_attribute (parm_die, node, 0, 0, context_die);
9843 break;
9845 default:
9846 abort ();
9849 return parm_die;
9852 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9853 at the end of an (ANSI prototyped) formal parameters list. */
9855 static void
9856 gen_unspecified_parameters_die (decl_or_type, context_die)
9857 register tree decl_or_type ATTRIBUTE_UNUSED;
9858 register dw_die_ref context_die;
9860 new_die (DW_TAG_unspecified_parameters, context_die);
9863 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9864 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9865 parameters as specified in some function type specification (except for
9866 those which appear as part of a function *definition*). */
9868 static void
9869 gen_formal_types_die (function_or_method_type, context_die)
9870 register tree function_or_method_type;
9871 register dw_die_ref context_die;
9873 register tree link;
9874 register tree formal_type = NULL;
9875 register tree first_parm_type;
9876 tree arg;
9878 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
9880 arg = DECL_ARGUMENTS (function_or_method_type);
9881 function_or_method_type = TREE_TYPE (function_or_method_type);
9883 else
9884 arg = NULL_TREE;
9886 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9888 /* Make our first pass over the list of formal parameter types and output a
9889 DW_TAG_formal_parameter DIE for each one. */
9890 for (link = first_parm_type; link; )
9892 register dw_die_ref parm_die;
9894 formal_type = TREE_VALUE (link);
9895 if (formal_type == void_type_node)
9896 break;
9898 /* Output a (nameless) DIE to represent the formal parameter itself. */
9899 parm_die = gen_formal_parameter_die (formal_type, context_die);
9900 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
9901 && link == first_parm_type)
9902 || (arg && DECL_ARTIFICIAL (arg)))
9903 add_AT_flag (parm_die, DW_AT_artificial, 1);
9905 link = TREE_CHAIN (link);
9906 if (arg)
9907 arg = TREE_CHAIN (arg);
9910 /* If this function type has an ellipsis, add a
9911 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9912 if (formal_type != void_type_node)
9913 gen_unspecified_parameters_die (function_or_method_type, context_die);
9915 /* Make our second (and final) pass over the list of formal parameter types
9916 and output DIEs to represent those types (as necessary). */
9917 for (link = TYPE_ARG_TYPES (function_or_method_type);
9918 link;
9919 link = TREE_CHAIN (link))
9921 formal_type = TREE_VALUE (link);
9922 if (formal_type == void_type_node)
9923 break;
9925 gen_type_die (formal_type, context_die);
9929 /* We want to generate the DIE for TYPE so that we can generate the
9930 die for MEMBER, which has been defined; we will need to refer back
9931 to the member declaration nested within TYPE. If we're trying to
9932 generate minimal debug info for TYPE, processing TYPE won't do the
9933 trick; we need to attach the member declaration by hand. */
9935 static void
9936 gen_type_die_for_member (type, member, context_die)
9937 tree type, member;
9938 dw_die_ref context_die;
9940 gen_type_die (type, context_die);
9942 /* If we're trying to avoid duplicate debug info, we may not have
9943 emitted the member decl for this function. Emit it now. */
9944 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9945 && ! lookup_decl_die (member))
9947 if (decl_ultimate_origin (member))
9948 abort ();
9950 push_decl_scope (type);
9951 if (TREE_CODE (member) == FUNCTION_DECL)
9952 gen_subprogram_die (member, lookup_type_die (type));
9953 else
9954 gen_variable_die (member, lookup_type_die (type));
9955 pop_decl_scope ();
9959 /* Generate the DWARF2 info for the "abstract" instance
9960 of a function which we may later generate inlined and/or
9961 out-of-line instances of. */
9963 void
9964 dwarf2out_abstract_function (decl)
9965 tree decl;
9967 register dw_die_ref old_die;
9968 tree save_fn;
9969 tree context;
9970 int was_abstract = DECL_ABSTRACT (decl);
9972 /* Make sure we have the actual abstract inline, not a clone. */
9973 decl = DECL_ORIGIN (decl);
9975 old_die = lookup_decl_die (decl);
9976 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9977 /* We've already generated the abstract instance. */
9978 return;
9980 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
9981 we don't get confused by DECL_ABSTRACT. */
9982 context = decl_class_context (decl);
9983 if (context)
9984 gen_type_die_for_member
9985 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
9987 /* Pretend we've just finished compiling this function. */
9988 save_fn = current_function_decl;
9989 current_function_decl = decl;
9991 set_decl_abstract_flags (decl, 1);
9992 dwarf2out_decl (decl);
9993 if (! was_abstract)
9994 set_decl_abstract_flags (decl, 0);
9996 current_function_decl = save_fn;
9999 /* Generate a DIE to represent a declared function (either file-scope or
10000 block-local). */
10002 static void
10003 gen_subprogram_die (decl, context_die)
10004 register tree decl;
10005 register dw_die_ref context_die;
10007 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10008 register tree origin = decl_ultimate_origin (decl);
10009 register dw_die_ref subr_die;
10010 register rtx fp_reg;
10011 register tree fn_arg_types;
10012 register tree outer_scope;
10013 register dw_die_ref old_die = lookup_decl_die (decl);
10014 register int declaration = (current_function_decl != decl
10015 || class_scope_p (context_die));
10017 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
10018 be true, if we started to generate the abstract instance of an inline,
10019 decided to output its containing class, and proceeded to emit the
10020 declaration of the inline from the member list for the class. In that
10021 case, `declaration' takes priority; we'll get back to the abstract
10022 instance when we're done with the class. */
10024 /* The class-scope declaration DIE must be the primary DIE. */
10025 if (origin && declaration && class_scope_p (context_die))
10027 origin = NULL;
10028 if (old_die)
10029 abort ();
10032 if (origin != NULL)
10034 if (declaration && ! local_scope_p (context_die))
10035 abort ();
10037 /* Fixup die_parent for the abstract instance of a nested
10038 inline function. */
10039 if (old_die && old_die->die_parent == NULL)
10040 add_child_die (context_die, old_die);
10042 subr_die = new_die (DW_TAG_subprogram, context_die);
10043 add_abstract_origin_attribute (subr_die, origin);
10045 else if (old_die)
10047 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10049 if (!get_AT_flag (old_die, DW_AT_declaration)
10050 /* We can have a normal definition following an inline one in the
10051 case of redefinition of GNU C extern inlines.
10052 It seems reasonable to use AT_specification in this case. */
10053 && !get_AT_unsigned (old_die, DW_AT_inline))
10055 /* ??? This can happen if there is a bug in the program, for
10056 instance, if it has duplicate function definitions. Ideally,
10057 we should detect this case and ignore it. For now, if we have
10058 already reported an error, any error at all, then assume that
10059 we got here because of a input error, not a dwarf2 bug. */
10060 if (errorcount)
10061 return;
10062 abort ();
10065 /* If the definition comes from the same place as the declaration,
10066 maybe use the old DIE. We always want the DIE for this function
10067 that has the *_pc attributes to be under comp_unit_die so the
10068 debugger can find it. We also need to do this for abstract
10069 instances of inlines, since the spec requires the out-of-line copy
10070 to have the same parent. For local class methods, this doesn't
10071 apply; we just use the old DIE. */
10072 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
10073 && (DECL_ARTIFICIAL (decl)
10074 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10075 && (get_AT_unsigned (old_die, DW_AT_decl_line)
10076 == (unsigned) DECL_SOURCE_LINE (decl)))))
10078 subr_die = old_die;
10080 /* Clear out the declaration attribute and the parm types. */
10081 remove_AT (subr_die, DW_AT_declaration);
10082 remove_children (subr_die);
10084 else
10086 subr_die = new_die (DW_TAG_subprogram, context_die);
10087 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
10088 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10089 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10090 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10091 != (unsigned) DECL_SOURCE_LINE (decl))
10092 add_AT_unsigned
10093 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10096 else
10098 subr_die = new_die (DW_TAG_subprogram, context_die);
10100 if (TREE_PUBLIC (decl))
10101 add_AT_flag (subr_die, DW_AT_external, 1);
10103 add_name_and_src_coords_attributes (subr_die, decl);
10104 if (debug_info_level > DINFO_LEVEL_TERSE)
10106 register tree type = TREE_TYPE (decl);
10108 add_prototyped_attribute (subr_die, type);
10109 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
10112 add_pure_or_virtual_attribute (subr_die, decl);
10113 if (DECL_ARTIFICIAL (decl))
10114 add_AT_flag (subr_die, DW_AT_artificial, 1);
10115 if (TREE_PROTECTED (decl))
10116 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10117 else if (TREE_PRIVATE (decl))
10118 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
10121 if (declaration)
10123 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
10125 add_AT_flag (subr_die, DW_AT_declaration, 1);
10127 /* The first time we see a member function, it is in the context of
10128 the class to which it belongs. We make sure of this by emitting
10129 the class first. The next time is the definition, which is
10130 handled above. The two may come from the same source text. */
10131 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10132 equate_decl_number_to_die (decl, subr_die);
10135 else if (DECL_ABSTRACT (decl))
10137 if (DECL_INLINE (decl) && !flag_no_inline)
10139 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10140 inline functions, but not for extern inline functions.
10141 We can't get this completely correct because information
10142 about whether the function was declared inline is not
10143 saved anywhere. */
10144 if (DECL_DEFER_OUTPUT (decl))
10145 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10146 else
10147 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10149 else
10150 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10152 equate_decl_number_to_die (decl, subr_die);
10154 else if (!DECL_EXTERNAL (decl))
10156 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
10157 equate_decl_number_to_die (decl, subr_die);
10159 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10160 current_funcdef_number);
10161 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10162 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10163 current_funcdef_number);
10164 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10166 add_pubname (decl, subr_die);
10167 add_arange (decl, subr_die);
10169 #ifdef MIPS_DEBUGGING_INFO
10170 /* Add a reference to the FDE for this routine. */
10171 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10172 #endif
10174 /* Define the "frame base" location for this routine. We use the
10175 frame pointer or stack pointer registers, since the RTL for local
10176 variables is relative to one of them. */
10177 fp_reg
10178 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10179 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10181 #if 0
10182 /* ??? This fails for nested inline functions, because context_display
10183 is not part of the state saved/restored for inline functions. */
10184 if (current_function_needs_context)
10185 add_AT_location_description (subr_die, DW_AT_static_link,
10186 lookup_static_chain (decl));
10187 #endif
10190 /* Now output descriptions of the arguments for this function. This gets
10191 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10192 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10193 `...' at the end of the formal parameter list. In order to find out if
10194 there was a trailing ellipsis or not, we must instead look at the type
10195 associated with the FUNCTION_DECL. This will be a node of type
10196 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10197 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10198 an ellipsis at the end. */
10200 /* In the case where we are describing a mere function declaration, all we
10201 need to do here (and all we *can* do here) is to describe the *types* of
10202 its formal parameters. */
10203 if (debug_info_level <= DINFO_LEVEL_TERSE)
10205 else if (declaration)
10206 gen_formal_types_die (decl, subr_die);
10207 else
10209 /* Generate DIEs to represent all known formal parameters */
10210 register tree arg_decls = DECL_ARGUMENTS (decl);
10211 register tree parm;
10213 /* When generating DIEs, generate the unspecified_parameters DIE
10214 instead if we come across the arg "__builtin_va_alist" */
10215 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10216 if (TREE_CODE (parm) == PARM_DECL)
10218 if (DECL_NAME (parm)
10219 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10220 "__builtin_va_alist"))
10221 gen_unspecified_parameters_die (parm, subr_die);
10222 else
10223 gen_decl_die (parm, subr_die);
10226 /* Decide whether we need a unspecified_parameters DIE at the end.
10227 There are 2 more cases to do this for: 1) the ansi ... declaration -
10228 this is detectable when the end of the arg list is not a
10229 void_type_node 2) an unprototyped function declaration (not a
10230 definition). This just means that we have no info about the
10231 parameters at all. */
10232 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10233 if (fn_arg_types != NULL)
10235 /* this is the prototyped case, check for ... */
10236 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10237 gen_unspecified_parameters_die (decl, subr_die);
10239 else if (DECL_INITIAL (decl) == NULL_TREE)
10240 gen_unspecified_parameters_die (decl, subr_die);
10243 /* Output Dwarf info for all of the stuff within the body of the function
10244 (if it has one - it may be just a declaration). */
10245 outer_scope = DECL_INITIAL (decl);
10247 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
10248 node created to represent a function. This outermost BLOCK actually
10249 represents the outermost binding contour for the function, i.e. the
10250 contour in which the function's formal parameters and labels get
10251 declared. Curiously, it appears that the front end doesn't actually
10252 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
10253 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
10254 list for the function instead.) The BLOCK_VARS list for the
10255 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
10256 the function however, and we output DWARF info for those in
10257 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
10258 node representing the function's outermost pair of curly braces, and
10259 any blocks used for the base and member initializers of a C++
10260 constructor function. */
10261 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10263 current_function_has_inlines = 0;
10264 decls_for_scope (outer_scope, subr_die, 0);
10266 #if 0 && defined (MIPS_DEBUGGING_INFO)
10267 if (current_function_has_inlines)
10269 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10270 if (! comp_unit_has_inlines)
10272 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10273 comp_unit_has_inlines = 1;
10276 #endif
10280 /* Generate a DIE to represent a declared data object. */
10282 static void
10283 gen_variable_die (decl, context_die)
10284 register tree decl;
10285 register dw_die_ref context_die;
10287 register tree origin = decl_ultimate_origin (decl);
10288 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
10290 dw_die_ref old_die = lookup_decl_die (decl);
10291 int declaration = (DECL_EXTERNAL (decl)
10292 || class_scope_p (context_die));
10294 if (origin != NULL)
10295 add_abstract_origin_attribute (var_die, origin);
10296 /* Loop unrolling can create multiple blocks that refer to the same
10297 static variable, so we must test for the DW_AT_declaration flag. */
10298 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10299 copy decls and set the DECL_ABSTRACT flag on them instead of
10300 sharing them. */
10301 else if (old_die && TREE_STATIC (decl)
10302 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10304 /* This is a definition of a C++ class level static. */
10305 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10306 if (DECL_NAME (decl))
10308 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10310 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10311 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10313 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10314 != (unsigned) DECL_SOURCE_LINE (decl))
10316 add_AT_unsigned (var_die, DW_AT_decl_line,
10317 DECL_SOURCE_LINE (decl));
10320 else
10322 add_name_and_src_coords_attributes (var_die, decl);
10323 add_type_attribute (var_die, TREE_TYPE (decl),
10324 TREE_READONLY (decl),
10325 TREE_THIS_VOLATILE (decl), context_die);
10327 if (TREE_PUBLIC (decl))
10328 add_AT_flag (var_die, DW_AT_external, 1);
10330 if (DECL_ARTIFICIAL (decl))
10331 add_AT_flag (var_die, DW_AT_artificial, 1);
10333 if (TREE_PROTECTED (decl))
10334 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10336 else if (TREE_PRIVATE (decl))
10337 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10340 if (declaration)
10341 add_AT_flag (var_die, DW_AT_declaration, 1);
10343 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10344 equate_decl_number_to_die (decl, var_die);
10346 if (! declaration && ! DECL_ABSTRACT (decl))
10348 add_location_or_const_value_attribute (var_die, decl);
10349 add_pubname (decl, var_die);
10351 else
10352 tree_add_const_value_attribute (var_die, decl);
10355 /* Generate a DIE to represent a label identifier. */
10357 static void
10358 gen_label_die (decl, context_die)
10359 register tree decl;
10360 register dw_die_ref context_die;
10362 register tree origin = decl_ultimate_origin (decl);
10363 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
10364 register rtx insn;
10365 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10367 if (origin != NULL)
10368 add_abstract_origin_attribute (lbl_die, origin);
10369 else
10370 add_name_and_src_coords_attributes (lbl_die, decl);
10372 if (DECL_ABSTRACT (decl))
10373 equate_decl_number_to_die (decl, lbl_die);
10374 else
10376 insn = DECL_RTL (decl);
10378 /* Deleted labels are programmer specified labels which have been
10379 eliminated because of various optimisations. We still emit them
10380 here so that it is possible to put breakpoints on them. */
10381 if (GET_CODE (insn) == CODE_LABEL
10382 || ((GET_CODE (insn) == NOTE
10383 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10385 /* When optimization is enabled (via -O) some parts of the compiler
10386 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10387 represent source-level labels which were explicitly declared by
10388 the user. This really shouldn't be happening though, so catch
10389 it if it ever does happen. */
10390 if (INSN_DELETED_P (insn))
10391 abort ();
10393 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10394 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10399 /* Generate a DIE for a lexical block. */
10401 static void
10402 gen_lexical_block_die (stmt, context_die, depth)
10403 register tree stmt;
10404 register dw_die_ref context_die;
10405 int depth;
10407 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
10408 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10410 if (! BLOCK_ABSTRACT (stmt))
10412 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10413 BLOCK_NUMBER (stmt));
10414 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10415 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10416 BLOCK_NUMBER (stmt));
10417 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10420 decls_for_scope (stmt, stmt_die, depth);
10423 /* Generate a DIE for an inlined subprogram. */
10425 static void
10426 gen_inlined_subroutine_die (stmt, context_die, depth)
10427 register tree stmt;
10428 register dw_die_ref context_die;
10429 int depth;
10431 if (! BLOCK_ABSTRACT (stmt))
10433 register dw_die_ref subr_die
10434 = new_die (DW_TAG_inlined_subroutine, context_die);
10435 register tree decl = block_ultimate_origin (stmt);
10436 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10438 /* Emit info for the abstract instance first, if we haven't yet. */
10439 dwarf2out_abstract_function (decl);
10441 add_abstract_origin_attribute (subr_die, decl);
10442 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10443 BLOCK_NUMBER (stmt));
10444 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10445 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10446 BLOCK_NUMBER (stmt));
10447 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10448 decls_for_scope (stmt, subr_die, depth);
10449 current_function_has_inlines = 1;
10453 /* Generate a DIE for a field in a record, or structure. */
10455 static void
10456 gen_field_die (decl, context_die)
10457 register tree decl;
10458 register dw_die_ref context_die;
10460 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
10462 add_name_and_src_coords_attributes (decl_die, decl);
10463 add_type_attribute (decl_die, member_declared_type (decl),
10464 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10465 context_die);
10467 /* If this is a bit field... */
10468 if (DECL_BIT_FIELD_TYPE (decl))
10470 add_byte_size_attribute (decl_die, decl);
10471 add_bit_size_attribute (decl_die, decl);
10472 add_bit_offset_attribute (decl_die, decl);
10475 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10476 add_data_member_location_attribute (decl_die, decl);
10478 if (DECL_ARTIFICIAL (decl))
10479 add_AT_flag (decl_die, DW_AT_artificial, 1);
10481 if (TREE_PROTECTED (decl))
10482 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10484 else if (TREE_PRIVATE (decl))
10485 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10488 #if 0
10489 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10490 Use modified_type_die instead.
10491 We keep this code here just in case these types of DIEs may be needed to
10492 represent certain things in other languages (e.g. Pascal) someday. */
10493 static void
10494 gen_pointer_type_die (type, context_die)
10495 register tree type;
10496 register dw_die_ref context_die;
10498 register dw_die_ref ptr_die
10499 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
10501 equate_type_number_to_die (type, ptr_die);
10502 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10503 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10506 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10507 Use modified_type_die instead.
10508 We keep this code here just in case these types of DIEs may be needed to
10509 represent certain things in other languages (e.g. Pascal) someday. */
10510 static void
10511 gen_reference_type_die (type, context_die)
10512 register tree type;
10513 register dw_die_ref context_die;
10515 register dw_die_ref ref_die
10516 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
10518 equate_type_number_to_die (type, ref_die);
10519 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10520 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10522 #endif
10524 /* Generate a DIE for a pointer to a member type. */
10525 static void
10526 gen_ptr_to_mbr_type_die (type, context_die)
10527 register tree type;
10528 register dw_die_ref context_die;
10530 register dw_die_ref ptr_die
10531 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
10533 equate_type_number_to_die (type, ptr_die);
10534 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10535 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10536 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10539 /* Generate the DIE for the compilation unit. */
10541 static dw_die_ref
10542 gen_compile_unit_die (filename)
10543 register const char *filename;
10545 register dw_die_ref die;
10546 char producer[250];
10547 const char *wd = getpwd ();
10548 int language;
10550 die = new_die (DW_TAG_compile_unit, NULL);
10551 add_name_attribute (die, filename);
10553 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10554 add_AT_string (die, DW_AT_comp_dir, wd);
10556 sprintf (producer, "%s %s", language_string, version_string);
10558 #ifdef MIPS_DEBUGGING_INFO
10559 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10560 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10561 not appear in the producer string, the debugger reaches the conclusion
10562 that the object file is stripped and has no debugging information.
10563 To get the MIPS/SGI debugger to believe that there is debugging
10564 information in the object file, we add a -g to the producer string. */
10565 if (debug_info_level > DINFO_LEVEL_TERSE)
10566 strcat (producer, " -g");
10567 #endif
10569 add_AT_string (die, DW_AT_producer, producer);
10571 if (strcmp (language_string, "GNU C++") == 0)
10572 language = DW_LANG_C_plus_plus;
10573 else if (strcmp (language_string, "GNU Ada") == 0)
10574 language = DW_LANG_Ada83;
10575 else if (strcmp (language_string, "GNU F77") == 0)
10576 language = DW_LANG_Fortran77;
10577 else if (strcmp (language_string, "GNU Pascal") == 0)
10578 language = DW_LANG_Pascal83;
10579 else if (strcmp (language_string, "GNU Java") == 0)
10580 language = DW_LANG_Java;
10581 else if (flag_traditional)
10582 language = DW_LANG_C;
10583 else
10584 language = DW_LANG_C89;
10586 add_AT_unsigned (die, DW_AT_language, language);
10588 return die;
10591 /* Generate a DIE for a string type. */
10593 static void
10594 gen_string_type_die (type, context_die)
10595 register tree type;
10596 register dw_die_ref context_die;
10598 register dw_die_ref type_die
10599 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10601 equate_type_number_to_die (type, type_die);
10603 /* Fudge the string length attribute for now. */
10605 /* TODO: add string length info.
10606 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10607 bound_representation (upper_bound, 0, 'u'); */
10610 /* Generate the DIE for a base class. */
10612 static void
10613 gen_inheritance_die (binfo, context_die)
10614 register tree binfo;
10615 register dw_die_ref context_die;
10617 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10619 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10620 add_data_member_location_attribute (die, binfo);
10622 if (TREE_VIA_VIRTUAL (binfo))
10623 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10624 if (TREE_VIA_PUBLIC (binfo))
10625 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10626 else if (TREE_VIA_PROTECTED (binfo))
10627 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10630 /* Generate a DIE for a class member. */
10632 static void
10633 gen_member_die (type, context_die)
10634 register tree type;
10635 register dw_die_ref context_die;
10637 register tree member;
10638 dw_die_ref child;
10640 /* If this is not an incomplete type, output descriptions of each of its
10641 members. Note that as we output the DIEs necessary to represent the
10642 members of this record or union type, we will also be trying to output
10643 DIEs to represent the *types* of those members. However the `type'
10644 function (above) will specifically avoid generating type DIEs for member
10645 types *within* the list of member DIEs for this (containing) type execpt
10646 for those types (of members) which are explicitly marked as also being
10647 members of this (containing) type themselves. The g++ front- end can
10648 force any given type to be treated as a member of some other
10649 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10650 to point to the TREE node representing the appropriate (containing)
10651 type. */
10653 /* First output info about the base classes. */
10654 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10656 register tree bases = TYPE_BINFO_BASETYPES (type);
10657 register int n_bases = TREE_VEC_LENGTH (bases);
10658 register int i;
10660 for (i = 0; i < n_bases; i++)
10661 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10664 /* Now output info about the data members and type members. */
10665 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10667 /* If we thought we were generating minimal debug info for TYPE
10668 and then changed our minds, some of the member declarations
10669 may have already been defined. Don't define them again, but
10670 do put them in the right order. */
10672 child = lookup_decl_die (member);
10673 if (child)
10674 splice_child_die (context_die, child);
10675 else
10676 gen_decl_die (member, context_die);
10679 /* Now output info about the function members (if any). */
10680 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10682 /* Don't include clones in the member list. */
10683 if (DECL_ABSTRACT_ORIGIN (member))
10684 continue;
10686 child = lookup_decl_die (member);
10687 if (child)
10688 splice_child_die (context_die, child);
10689 else
10690 gen_decl_die (member, context_die);
10694 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10695 is set, we pretend that the type was never defined, so we only get the
10696 member DIEs needed by later specification DIEs. */
10698 static void
10699 gen_struct_or_union_type_die (type, context_die)
10700 register tree type;
10701 register dw_die_ref context_die;
10703 register dw_die_ref type_die = lookup_type_die (type);
10704 register dw_die_ref scope_die = 0;
10705 register int nested = 0;
10706 int complete = (TYPE_SIZE (type)
10707 && (! TYPE_STUB_DECL (type)
10708 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10710 if (type_die && ! complete)
10711 return;
10713 if (TYPE_CONTEXT (type) != NULL_TREE
10714 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10715 nested = 1;
10717 scope_die = scope_die_for (type, context_die);
10719 if (! type_die || (nested && scope_die == comp_unit_die))
10720 /* First occurrence of type or toplevel definition of nested class. */
10722 register dw_die_ref old_die = type_die;
10724 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10725 ? DW_TAG_structure_type : DW_TAG_union_type,
10726 scope_die);
10727 equate_type_number_to_die (type, type_die);
10728 if (old_die)
10729 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10730 else
10731 add_name_attribute (type_die, type_tag (type));
10733 else
10734 remove_AT (type_die, DW_AT_declaration);
10736 /* If this type has been completed, then give it a byte_size attribute and
10737 then give a list of members. */
10738 if (complete)
10740 /* Prevent infinite recursion in cases where the type of some member of
10741 this type is expressed in terms of this type itself. */
10742 TREE_ASM_WRITTEN (type) = 1;
10743 add_byte_size_attribute (type_die, type);
10744 if (TYPE_STUB_DECL (type) != NULL_TREE)
10745 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10747 /* If the first reference to this type was as the return type of an
10748 inline function, then it may not have a parent. Fix this now. */
10749 if (type_die->die_parent == NULL)
10750 add_child_die (scope_die, type_die);
10752 push_decl_scope (type);
10753 gen_member_die (type, type_die);
10754 pop_decl_scope ();
10756 /* GNU extension: Record what type our vtable lives in. */
10757 if (TYPE_VFIELD (type))
10759 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10761 gen_type_die (vtype, context_die);
10762 add_AT_die_ref (type_die, DW_AT_containing_type,
10763 lookup_type_die (vtype));
10766 else
10768 add_AT_flag (type_die, DW_AT_declaration, 1);
10770 /* We don't need to do this for function-local types. */
10771 if (! decl_function_context (TYPE_STUB_DECL (type)))
10772 add_incomplete_type (type);
10776 /* Generate a DIE for a subroutine _type_. */
10778 static void
10779 gen_subroutine_type_die (type, context_die)
10780 register tree type;
10781 register dw_die_ref context_die;
10783 register tree return_type = TREE_TYPE (type);
10784 register dw_die_ref subr_die
10785 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10787 equate_type_number_to_die (type, subr_die);
10788 add_prototyped_attribute (subr_die, type);
10789 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10790 gen_formal_types_die (type, subr_die);
10793 /* Generate a DIE for a type definition */
10795 static void
10796 gen_typedef_die (decl, context_die)
10797 register tree decl;
10798 register dw_die_ref context_die;
10800 register dw_die_ref type_die;
10801 register tree origin;
10803 if (TREE_ASM_WRITTEN (decl))
10804 return;
10805 TREE_ASM_WRITTEN (decl) = 1;
10807 type_die = new_die (DW_TAG_typedef, context_die);
10808 origin = decl_ultimate_origin (decl);
10809 if (origin != NULL)
10810 add_abstract_origin_attribute (type_die, origin);
10811 else
10813 register tree type;
10814 add_name_and_src_coords_attributes (type_die, decl);
10815 if (DECL_ORIGINAL_TYPE (decl))
10817 type = DECL_ORIGINAL_TYPE (decl);
10819 if (type == TREE_TYPE (decl))
10820 abort ();
10821 else
10822 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10824 else
10825 type = TREE_TYPE (decl);
10826 add_type_attribute (type_die, type, TREE_READONLY (decl),
10827 TREE_THIS_VOLATILE (decl), context_die);
10830 if (DECL_ABSTRACT (decl))
10831 equate_decl_number_to_die (decl, type_die);
10834 /* Generate a type description DIE. */
10836 static void
10837 gen_type_die (type, context_die)
10838 register tree type;
10839 register dw_die_ref context_die;
10841 int need_pop;
10843 if (type == NULL_TREE || type == error_mark_node)
10844 return;
10846 /* We are going to output a DIE to represent the unqualified version of
10847 this type (i.e. without any const or volatile qualifiers) so get the
10848 main variant (i.e. the unqualified version) of this type now. */
10849 type = type_main_variant (type);
10851 if (TREE_ASM_WRITTEN (type))
10852 return;
10854 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10855 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10857 TREE_ASM_WRITTEN (type) = 1;
10858 gen_decl_die (TYPE_NAME (type), context_die);
10859 return;
10862 switch (TREE_CODE (type))
10864 case ERROR_MARK:
10865 break;
10867 case POINTER_TYPE:
10868 case REFERENCE_TYPE:
10869 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10870 ensures that the gen_type_die recursion will terminate even if the
10871 type is recursive. Recursive types are possible in Ada. */
10872 /* ??? We could perhaps do this for all types before the switch
10873 statement. */
10874 TREE_ASM_WRITTEN (type) = 1;
10876 /* For these types, all that is required is that we output a DIE (or a
10877 set of DIEs) to represent the "basis" type. */
10878 gen_type_die (TREE_TYPE (type), context_die);
10879 break;
10881 case OFFSET_TYPE:
10882 /* This code is used for C++ pointer-to-data-member types.
10883 Output a description of the relevant class type. */
10884 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10886 /* Output a description of the type of the object pointed to. */
10887 gen_type_die (TREE_TYPE (type), context_die);
10889 /* Now output a DIE to represent this pointer-to-data-member type
10890 itself. */
10891 gen_ptr_to_mbr_type_die (type, context_die);
10892 break;
10894 case SET_TYPE:
10895 gen_type_die (TYPE_DOMAIN (type), context_die);
10896 gen_set_type_die (type, context_die);
10897 break;
10899 case FILE_TYPE:
10900 gen_type_die (TREE_TYPE (type), context_die);
10901 abort (); /* No way to represent these in Dwarf yet! */
10902 break;
10904 case FUNCTION_TYPE:
10905 /* Force out return type (in case it wasn't forced out already). */
10906 gen_type_die (TREE_TYPE (type), context_die);
10907 gen_subroutine_type_die (type, context_die);
10908 break;
10910 case METHOD_TYPE:
10911 /* Force out return type (in case it wasn't forced out already). */
10912 gen_type_die (TREE_TYPE (type), context_die);
10913 gen_subroutine_type_die (type, context_die);
10914 break;
10916 case ARRAY_TYPE:
10917 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10919 gen_type_die (TREE_TYPE (type), context_die);
10920 gen_string_type_die (type, context_die);
10922 else
10923 gen_array_type_die (type, context_die);
10924 break;
10926 case VECTOR_TYPE:
10927 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10928 break;
10930 case ENUMERAL_TYPE:
10931 case RECORD_TYPE:
10932 case UNION_TYPE:
10933 case QUAL_UNION_TYPE:
10934 /* If this is a nested type whose containing class hasn't been
10935 written out yet, writing it out will cover this one, too.
10936 This does not apply to instantiations of member class templates;
10937 they need to be added to the containing class as they are
10938 generated. FIXME: This hurts the idea of combining type decls
10939 from multiple TUs, since we can't predict what set of template
10940 instantiations we'll get. */
10941 if (TYPE_CONTEXT (type)
10942 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10943 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10945 gen_type_die (TYPE_CONTEXT (type), context_die);
10947 if (TREE_ASM_WRITTEN (type))
10948 return;
10950 /* If that failed, attach ourselves to the stub. */
10951 push_decl_scope (TYPE_CONTEXT (type));
10952 context_die = lookup_type_die (TYPE_CONTEXT (type));
10953 need_pop = 1;
10955 else
10956 need_pop = 0;
10958 if (TREE_CODE (type) == ENUMERAL_TYPE)
10959 gen_enumeration_type_die (type, context_die);
10960 else
10961 gen_struct_or_union_type_die (type, context_die);
10963 if (need_pop)
10964 pop_decl_scope ();
10966 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10967 it up if it is ever completed. gen_*_type_die will set it for us
10968 when appropriate. */
10969 return;
10971 case VOID_TYPE:
10972 case INTEGER_TYPE:
10973 case REAL_TYPE:
10974 case COMPLEX_TYPE:
10975 case BOOLEAN_TYPE:
10976 case CHAR_TYPE:
10977 /* No DIEs needed for fundamental types. */
10978 break;
10980 case LANG_TYPE:
10981 /* No Dwarf representation currently defined. */
10982 break;
10984 default:
10985 abort ();
10988 TREE_ASM_WRITTEN (type) = 1;
10991 /* Generate a DIE for a tagged type instantiation. */
10993 static void
10994 gen_tagged_type_instantiation_die (type, context_die)
10995 register tree type;
10996 register dw_die_ref context_die;
10998 if (type == NULL_TREE || type == error_mark_node)
10999 return;
11001 /* We are going to output a DIE to represent the unqualified version of
11002 this type (i.e. without any const or volatile qualifiers) so make sure
11003 that we have the main variant (i.e. the unqualified version) of this
11004 type now. */
11005 if (type != type_main_variant (type))
11006 abort ();
11008 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11009 an instance of an unresolved type. */
11011 switch (TREE_CODE (type))
11013 case ERROR_MARK:
11014 break;
11016 case ENUMERAL_TYPE:
11017 gen_inlined_enumeration_type_die (type, context_die);
11018 break;
11020 case RECORD_TYPE:
11021 gen_inlined_structure_type_die (type, context_die);
11022 break;
11024 case UNION_TYPE:
11025 case QUAL_UNION_TYPE:
11026 gen_inlined_union_type_die (type, context_die);
11027 break;
11029 default:
11030 abort ();
11034 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11035 things which are local to the given block. */
11037 static void
11038 gen_block_die (stmt, context_die, depth)
11039 register tree stmt;
11040 register dw_die_ref context_die;
11041 int depth;
11043 register int must_output_die = 0;
11044 register tree origin;
11045 register tree decl;
11046 register enum tree_code origin_code;
11048 /* Ignore blocks never really used to make RTL. */
11050 if (stmt == NULL_TREE || !TREE_USED (stmt)
11051 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
11052 return;
11054 /* Determine the "ultimate origin" of this block. This block may be an
11055 inlined instance of an inlined instance of inline function, so we have
11056 to trace all of the way back through the origin chain to find out what
11057 sort of node actually served as the original seed for the creation of
11058 the current block. */
11059 origin = block_ultimate_origin (stmt);
11060 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11062 /* Determine if we need to output any Dwarf DIEs at all to represent this
11063 block. */
11064 if (origin_code == FUNCTION_DECL)
11065 /* The outer scopes for inlinings *must* always be represented. We
11066 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11067 must_output_die = 1;
11068 else
11070 /* In the case where the current block represents an inlining of the
11071 "body block" of an inline function, we must *NOT* output any DIE for
11072 this block because we have already output a DIE to represent the
11073 whole inlined function scope and the "body block" of any function
11074 doesn't really represent a different scope according to ANSI C
11075 rules. So we check here to make sure that this block does not
11076 represent a "body block inlining" before trying to set the
11077 `must_output_die' flag. */
11078 if (! is_body_block (origin ? origin : stmt))
11080 /* Determine if this block directly contains any "significant"
11081 local declarations which we will need to output DIEs for. */
11082 if (debug_info_level > DINFO_LEVEL_TERSE)
11083 /* We are not in terse mode so *any* local declaration counts
11084 as being a "significant" one. */
11085 must_output_die = (BLOCK_VARS (stmt) != NULL);
11086 else
11087 /* We are in terse mode, so only local (nested) function
11088 definitions count as "significant" local declarations. */
11089 for (decl = BLOCK_VARS (stmt);
11090 decl != NULL; decl = TREE_CHAIN (decl))
11091 if (TREE_CODE (decl) == FUNCTION_DECL
11092 && DECL_INITIAL (decl))
11094 must_output_die = 1;
11095 break;
11100 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11101 DIE for any block which contains no significant local declarations at
11102 all. Rather, in such cases we just call `decls_for_scope' so that any
11103 needed Dwarf info for any sub-blocks will get properly generated. Note
11104 that in terse mode, our definition of what constitutes a "significant"
11105 local declaration gets restricted to include only inlined function
11106 instances and local (nested) function definitions. */
11107 if (must_output_die)
11109 if (origin_code == FUNCTION_DECL)
11110 gen_inlined_subroutine_die (stmt, context_die, depth);
11111 else
11112 gen_lexical_block_die (stmt, context_die, depth);
11114 else
11115 decls_for_scope (stmt, context_die, depth);
11118 /* Generate all of the decls declared within a given scope and (recursively)
11119 all of its sub-blocks. */
11121 static void
11122 decls_for_scope (stmt, context_die, depth)
11123 register tree stmt;
11124 register dw_die_ref context_die;
11125 int depth;
11127 register tree decl;
11128 register tree subblocks;
11130 /* Ignore blocks never really used to make RTL. */
11131 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11132 return;
11134 /* Output the DIEs to represent all of the data objects and typedefs
11135 declared directly within this block but not within any nested
11136 sub-blocks. Also, nested function and tag DIEs have been
11137 generated with a parent of NULL; fix that up now. */
11138 for (decl = BLOCK_VARS (stmt);
11139 decl != NULL; decl = TREE_CHAIN (decl))
11141 register dw_die_ref die;
11143 if (TREE_CODE (decl) == FUNCTION_DECL)
11144 die = lookup_decl_die (decl);
11145 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11146 die = lookup_type_die (TREE_TYPE (decl));
11147 else
11148 die = NULL;
11150 if (die != NULL && die->die_parent == NULL)
11151 add_child_die (context_die, die);
11152 else
11153 gen_decl_die (decl, context_die);
11156 /* Output the DIEs to represent all sub-blocks (and the items declared
11157 therein) of this block. */
11158 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11159 subblocks != NULL;
11160 subblocks = BLOCK_CHAIN (subblocks))
11161 gen_block_die (subblocks, context_die, depth + 1);
11164 /* Is this a typedef we can avoid emitting? */
11166 static inline int
11167 is_redundant_typedef (decl)
11168 register tree decl;
11170 if (TYPE_DECL_IS_STUB (decl))
11171 return 1;
11173 if (DECL_ARTIFICIAL (decl)
11174 && DECL_CONTEXT (decl)
11175 && is_tagged_type (DECL_CONTEXT (decl))
11176 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11177 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11178 /* Also ignore the artificial member typedef for the class name. */
11179 return 1;
11181 return 0;
11184 /* Generate Dwarf debug information for a decl described by DECL. */
11186 static void
11187 gen_decl_die (decl, context_die)
11188 register tree decl;
11189 register dw_die_ref context_die;
11191 register tree origin;
11193 if (TREE_CODE (decl) == ERROR_MARK)
11194 return;
11196 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11197 if (DECL_IGNORED_P (decl))
11198 return;
11200 switch (TREE_CODE (decl))
11202 case CONST_DECL:
11203 /* The individual enumerators of an enum type get output when we output
11204 the Dwarf representation of the relevant enum type itself. */
11205 break;
11207 case FUNCTION_DECL:
11208 /* Don't output any DIEs to represent mere function declarations,
11209 unless they are class members or explicit block externs. */
11210 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11211 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11212 break;
11214 /* If we're emitting a clone, emit info for the abstract instance. */
11215 if (DECL_ORIGIN (decl) != decl)
11216 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
11217 /* If we're emitting an out-of-line copy of an inline function,
11218 emit info for the abstract instance and set up to refer to it. */
11219 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11220 && ! class_scope_p (context_die)
11221 /* dwarf2out_abstract_function won't emit a die if this is just
11222 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11223 that case, because that works only if we have a die. */
11224 && DECL_INITIAL (decl) != NULL_TREE)
11226 dwarf2out_abstract_function (decl);
11227 set_decl_origin_self (decl);
11229 /* Otherwise we're emitting the primary DIE for this decl. */
11230 else if (debug_info_level > DINFO_LEVEL_TERSE)
11232 /* Before we describe the FUNCTION_DECL itself, make sure that we
11233 have described its return type. */
11234 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11236 /* And its virtual context. */
11237 if (DECL_VINDEX (decl) != NULL_TREE)
11238 gen_type_die (DECL_CONTEXT (decl), context_die);
11240 /* And its containing type. */
11241 origin = decl_class_context (decl);
11242 if (origin != NULL_TREE)
11243 gen_type_die_for_member (origin, decl, context_die);
11246 /* Now output a DIE to represent the function itself. */
11247 gen_subprogram_die (decl, context_die);
11248 break;
11250 case TYPE_DECL:
11251 /* If we are in terse mode, don't generate any DIEs to represent any
11252 actual typedefs. */
11253 if (debug_info_level <= DINFO_LEVEL_TERSE)
11254 break;
11256 /* In the special case of a TYPE_DECL node representing the
11257 declaration of some type tag, if the given TYPE_DECL is marked as
11258 having been instantiated from some other (original) TYPE_DECL node
11259 (e.g. one which was generated within the original definition of an
11260 inline function) we have to generate a special (abbreviated)
11261 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
11262 DIE here. */
11263 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11265 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11266 break;
11269 if (is_redundant_typedef (decl))
11270 gen_type_die (TREE_TYPE (decl), context_die);
11271 else
11272 /* Output a DIE to represent the typedef itself. */
11273 gen_typedef_die (decl, context_die);
11274 break;
11276 case LABEL_DECL:
11277 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11278 gen_label_die (decl, context_die);
11279 break;
11281 case VAR_DECL:
11282 /* If we are in terse mode, don't generate any DIEs to represent any
11283 variable declarations or definitions. */
11284 if (debug_info_level <= DINFO_LEVEL_TERSE)
11285 break;
11287 /* Output any DIEs that are needed to specify the type of this data
11288 object. */
11289 gen_type_die (TREE_TYPE (decl), context_die);
11291 /* And its containing type. */
11292 origin = decl_class_context (decl);
11293 if (origin != NULL_TREE)
11294 gen_type_die_for_member (origin, decl, context_die);
11296 /* Now output the DIE to represent the data object itself. This gets
11297 complicated because of the possibility that the VAR_DECL really
11298 represents an inlined instance of a formal parameter for an inline
11299 function. */
11300 origin = decl_ultimate_origin (decl);
11301 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11302 gen_formal_parameter_die (decl, context_die);
11303 else
11304 gen_variable_die (decl, context_die);
11305 break;
11307 case FIELD_DECL:
11308 /* Ignore the nameless fields that are used to skip bits, but
11309 handle C++ anonymous unions. */
11310 if (DECL_NAME (decl) != NULL_TREE
11311 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11313 gen_type_die (member_declared_type (decl), context_die);
11314 gen_field_die (decl, context_die);
11316 break;
11318 case PARM_DECL:
11319 gen_type_die (TREE_TYPE (decl), context_die);
11320 gen_formal_parameter_die (decl, context_die);
11321 break;
11323 case NAMESPACE_DECL:
11324 /* Ignore for now. */
11325 break;
11327 default:
11328 abort ();
11332 /* Add Ada "use" clause information for SGI Workshop debugger. */
11334 void
11335 dwarf2out_add_library_unit_info (filename, context_list)
11336 const char *filename;
11337 const char *context_list;
11339 unsigned int file_index;
11341 if (filename != NULL)
11343 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
11344 tree context_list_decl
11345 = build_decl (LABEL_DECL, get_identifier (context_list),
11346 void_type_node);
11348 TREE_PUBLIC (context_list_decl) = TRUE;
11349 add_name_attribute (unit_die, context_list);
11350 file_index = lookup_filename (filename);
11351 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11352 add_pubname (context_list_decl, unit_die);
11356 /* Write the debugging output for DECL. */
11358 void
11359 dwarf2out_decl (decl)
11360 register tree decl;
11362 register dw_die_ref context_die = comp_unit_die;
11364 if (TREE_CODE (decl) == ERROR_MARK)
11365 return;
11367 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11368 if (DECL_IGNORED_P (decl))
11369 return;
11371 switch (TREE_CODE (decl))
11373 case FUNCTION_DECL:
11374 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11375 builtin function. Explicit programmer-supplied declarations of
11376 these same functions should NOT be ignored however. */
11377 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11378 return;
11380 /* What we would really like to do here is to filter out all mere
11381 file-scope declarations of file-scope functions which are never
11382 referenced later within this translation unit (and keep all of ones
11383 that *are* referenced later on) but we aren't clairvoyant, so we have
11384 no idea which functions will be referenced in the future (i.e. later
11385 on within the current translation unit). So here we just ignore all
11386 file-scope function declarations which are not also definitions. If
11387 and when the debugger needs to know something about these functions,
11388 it will have to hunt around and find the DWARF information associated
11389 with the definition of the function. Note that we can't just check
11390 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
11391 definitions and which ones represent mere declarations. We have to
11392 check `DECL_INITIAL' instead. That's because the C front-end
11393 supports some weird semantics for "extern inline" function
11394 definitions. These can get inlined within the current translation
11395 unit (an thus, we need to generate DWARF info for their abstract
11396 instances so that the DWARF info for the concrete inlined instances
11397 can have something to refer to) but the compiler never generates any
11398 out-of-lines instances of such things (despite the fact that they
11399 *are* definitions). The important point is that the C front-end
11400 marks these "extern inline" functions as DECL_EXTERNAL, but we need
11401 to generate DWARF for them anyway. Note that the C++ front-end also
11402 plays some similar games for inline function definitions appearing
11403 within include files which also contain
11404 `#pragma interface' pragmas. */
11405 if (DECL_INITIAL (decl) == NULL_TREE)
11406 return;
11408 /* If we're a nested function, initially use a parent of NULL; if we're
11409 a plain function, this will be fixed up in decls_for_scope. If
11410 we're a method, it will be ignored, since we already have a DIE. */
11411 if (decl_function_context (decl))
11412 context_die = NULL;
11414 break;
11416 case VAR_DECL:
11417 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11418 declaration and if the declaration was never even referenced from
11419 within this entire compilation unit. We suppress these DIEs in
11420 order to save space in the .debug section (by eliminating entries
11421 which are probably useless). Note that we must not suppress
11422 block-local extern declarations (whether used or not) because that
11423 would screw-up the debugger's name lookup mechanism and cause it to
11424 miss things which really ought to be in scope at a given point. */
11425 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11426 return;
11428 /* If we are in terse mode, don't generate any DIEs to represent any
11429 variable declarations or definitions. */
11430 if (debug_info_level <= DINFO_LEVEL_TERSE)
11431 return;
11432 break;
11434 case TYPE_DECL:
11435 /* Don't emit stubs for types unless they are needed by other DIEs. */
11436 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11437 return;
11439 /* Don't bother trying to generate any DIEs to represent any of the
11440 normal built-in types for the language we are compiling. */
11441 if (DECL_SOURCE_LINE (decl) == 0)
11443 /* OK, we need to generate one for `bool' so GDB knows what type
11444 comparisons have. */
11445 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11446 == DW_LANG_C_plus_plus)
11447 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
11448 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11450 return;
11453 /* If we are in terse mode, don't generate any DIEs for types. */
11454 if (debug_info_level <= DINFO_LEVEL_TERSE)
11455 return;
11457 /* If we're a function-scope tag, initially use a parent of NULL;
11458 this will be fixed up in decls_for_scope. */
11459 if (decl_function_context (decl))
11460 context_die = NULL;
11462 break;
11464 default:
11465 return;
11468 gen_decl_die (decl, context_die);
11471 /* Output a marker (i.e. a label) for the beginning of the generated code for
11472 a lexical block. */
11474 void
11475 dwarf2out_begin_block (blocknum)
11476 register unsigned blocknum;
11478 function_section (current_function_decl);
11479 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11482 /* Output a marker (i.e. a label) for the end of the generated code for a
11483 lexical block. */
11485 void
11486 dwarf2out_end_block (blocknum)
11487 register unsigned blocknum;
11489 function_section (current_function_decl);
11490 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11493 /* Returns nonzero if it is appropriate not to emit any debugging
11494 information for BLOCK, because it doesn't contain any instructions.
11496 Don't allow this for blocks with nested functions or local classes
11497 as we would end up with orphans, and in the presence of scheduling
11498 we may end up calling them anyway. */
11501 dwarf2out_ignore_block (block)
11502 tree block;
11504 tree decl;
11505 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11506 if (TREE_CODE (decl) == FUNCTION_DECL
11507 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11508 return 0;
11509 return 1;
11512 /* Lookup a filename (in the list of filenames that we know about here in
11513 dwarf2out.c) and return its "index". The index of each (known) filename is
11514 just a unique number which is associated with only that one filename.
11515 We need such numbers for the sake of generating labels
11516 (in the .debug_sfnames section) and references to those
11517 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
11518 If the filename given as an argument is not found in our current list,
11519 add it to the list and assign it the next available unique index number.
11520 In order to speed up searches, we remember the index of the filename
11521 was looked up last. This handles the majority of all searches. */
11523 static unsigned
11524 lookup_filename (file_name)
11525 const char *file_name;
11527 register unsigned i;
11529 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11530 if (strcmp (file_name, "<internal>") == 0
11531 || strcmp (file_name, "<built-in>") == 0)
11532 return 0;
11534 /* Check to see if the file name that was searched on the previous
11535 call matches this file name. If so, return the index. */
11536 if (file_table.last_lookup_index != 0)
11537 if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0)
11538 return file_table.last_lookup_index;
11540 /* Didn't match the previous lookup, search the table */
11541 for (i = 1; i < file_table.in_use; ++i)
11542 if (strcmp (file_name, file_table.table[i]) == 0)
11544 file_table.last_lookup_index = i;
11545 return i;
11548 /* Prepare to add a new table entry by making sure there is enough space in
11549 the table to do so. If not, expand the current table. */
11550 if (i == file_table.allocated)
11552 file_table.allocated = i + FILE_TABLE_INCREMENT;
11553 file_table.table = (char **)
11554 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11557 /* Add the new entry to the end of the filename table. */
11558 file_table.table[i] = xstrdup (file_name);
11559 file_table.in_use = i + 1;
11560 file_table.last_lookup_index = i;
11562 if (DWARF2_ASM_LINE_DEBUG_INFO)
11563 fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
11565 return i;
11568 static void
11569 init_file_table ()
11571 /* Allocate the initial hunk of the file_table. */
11572 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11573 file_table.allocated = FILE_TABLE_INCREMENT;
11575 /* Skip the first entry - file numbers begin at 1. */
11576 file_table.in_use = 1;
11577 file_table.last_lookup_index = 0;
11580 /* Output a label to mark the beginning of a source code line entry
11581 and record information relating to this source line, in
11582 'line_info_table' for later output of the .debug_line section. */
11584 void
11585 dwarf2out_line (filename, line)
11586 register const char *filename;
11587 register unsigned line;
11589 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11591 function_section (current_function_decl);
11593 if (DWARF2_ASM_LINE_DEBUG_INFO)
11595 unsigned file_num = lookup_filename (filename);
11597 /* Emit the .loc directive understood by GNU as. */
11598 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11600 /* Indicate that line number info exists. */
11601 ++line_info_table_in_use;
11603 /* Indicate that multiple line number tables exist. */
11604 if (DECL_SECTION_NAME (current_function_decl))
11605 ++separate_line_info_table_in_use;
11607 else if (DECL_SECTION_NAME (current_function_decl))
11609 register dw_separate_line_info_ref line_info;
11610 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11611 separate_line_info_table_in_use);
11612 if (flag_debug_asm)
11613 fprintf (asm_out_file, "\t%s %s:%d", ASM_COMMENT_START,
11614 filename, line);
11615 fputc ('\n', asm_out_file);
11617 /* expand the line info table if necessary */
11618 if (separate_line_info_table_in_use
11619 == separate_line_info_table_allocated)
11621 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11622 separate_line_info_table
11623 = (dw_separate_line_info_ref)
11624 xrealloc (separate_line_info_table,
11625 separate_line_info_table_allocated
11626 * sizeof (dw_separate_line_info_entry));
11629 /* Add the new entry at the end of the line_info_table. */
11630 line_info
11631 = &separate_line_info_table[separate_line_info_table_in_use++];
11632 line_info->dw_file_num = lookup_filename (filename);
11633 line_info->dw_line_num = line;
11634 line_info->function = current_funcdef_number;
11636 else
11638 register dw_line_info_ref line_info;
11640 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11641 line_info_table_in_use);
11642 if (flag_debug_asm)
11643 fprintf (asm_out_file, "\t%s %s:%d", ASM_COMMENT_START,
11644 filename, line);
11645 fputc ('\n', asm_out_file);
11647 /* Expand the line info table if necessary. */
11648 if (line_info_table_in_use == line_info_table_allocated)
11650 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11651 line_info_table
11652 = (dw_line_info_ref)
11653 xrealloc (line_info_table,
11654 (line_info_table_allocated
11655 * sizeof (dw_line_info_entry)));
11658 /* Add the new entry at the end of the line_info_table. */
11659 line_info = &line_info_table[line_info_table_in_use++];
11660 line_info->dw_file_num = lookup_filename (filename);
11661 line_info->dw_line_num = line;
11666 /* Record the beginning of a new source file, for later output
11667 of the .debug_macinfo section. At present, unimplemented. */
11669 void
11670 dwarf2out_start_source_file (filename)
11671 register const char *filename ATTRIBUTE_UNUSED;
11673 if (flag_eliminate_dwarf2_dups)
11675 /* Record the beginning of the file for break_out_includes. */
11676 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11677 add_AT_string (bincl_die, DW_AT_name, filename);
11681 /* Record the end of a source file, for later output
11682 of the .debug_macinfo section. At present, unimplemented. */
11684 void
11685 dwarf2out_end_source_file ()
11687 if (flag_eliminate_dwarf2_dups)
11689 /* Record the end of the file for break_out_includes. */
11690 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11694 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11695 the tail part of the directive line, i.e. the part which is past the
11696 initial whitespace, #, whitespace, directive-name, whitespace part. */
11698 void
11699 dwarf2out_define (lineno, buffer)
11700 register unsigned lineno ATTRIBUTE_UNUSED;
11701 register const char *buffer ATTRIBUTE_UNUSED;
11703 static int initialized = 0;
11704 if (!initialized)
11706 dwarf2out_start_source_file (primary_filename);
11707 initialized = 1;
11711 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11712 the tail part of the directive line, i.e. the part which is past the
11713 initial whitespace, #, whitespace, directive-name, whitespace part. */
11715 void
11716 dwarf2out_undef (lineno, buffer)
11717 register unsigned lineno ATTRIBUTE_UNUSED;
11718 register const char *buffer ATTRIBUTE_UNUSED;
11722 /* Set up for Dwarf output at the start of compilation. */
11724 void
11725 dwarf2out_init (asm_out_file, main_input_filename)
11726 register FILE *asm_out_file;
11727 register const char *main_input_filename;
11729 init_file_table ();
11731 /* Remember the name of the primary input file. */
11732 primary_filename = main_input_filename;
11734 /* Add it to the file table first, under the assumption that we'll
11735 be emitting line number data for it first, which avoids having
11736 to add an initial DW_LNS_set_file. */
11737 lookup_filename (main_input_filename);
11739 /* Allocate the initial hunk of the decl_die_table. */
11740 decl_die_table
11741 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11742 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11743 decl_die_table_in_use = 0;
11745 /* Allocate the initial hunk of the decl_scope_table. */
11746 decl_scope_table
11747 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11748 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11749 decl_scope_depth = 0;
11751 /* Allocate the initial hunk of the abbrev_die_table. */
11752 abbrev_die_table
11753 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11754 sizeof (dw_die_ref));
11755 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11756 /* Zero-th entry is allocated, but unused */
11757 abbrev_die_table_in_use = 1;
11759 /* Allocate the initial hunk of the line_info_table. */
11760 line_info_table
11761 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11762 sizeof (dw_line_info_entry));
11763 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11764 /* Zero-th entry is allocated, but unused */
11765 line_info_table_in_use = 1;
11767 /* Generate the initial DIE for the .debug section. Note that the (string)
11768 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11769 will (typically) be a relative pathname and that this pathname should be
11770 taken as being relative to the directory from which the compiler was
11771 invoked when the given (base) source file was compiled. */
11772 comp_unit_die = gen_compile_unit_die (main_input_filename);
11774 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11775 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11777 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11778 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
11779 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11780 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11781 else
11782 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11783 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11784 DEBUG_INFO_SECTION_LABEL, 0);
11785 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11786 DEBUG_LINE_SECTION_LABEL, 0);
11788 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11789 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11790 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11792 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11793 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11795 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
11796 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11797 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11798 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11801 /* Output stuff that dwarf requires at the end of every file,
11802 and generate the DWARF-2 debugging info. */
11804 void
11805 dwarf2out_finish ()
11807 limbo_die_node *node, *next_node;
11808 dw_die_ref die;
11810 /* Traverse the limbo die list, and add parent/child links. The only
11811 dies without parents that should be here are concrete instances of
11812 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11813 For concrete instances, we can get the parent die from the abstract
11814 instance. */
11815 for (node = limbo_die_list; node; node = next_node)
11817 next_node = node->next;
11818 die = node->die;
11820 if (die->die_parent == NULL)
11822 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11823 if (origin)
11824 add_child_die (origin->die_parent, die);
11825 else if (die == comp_unit_die)
11827 else
11828 abort ();
11830 free (node);
11832 limbo_die_list = NULL;
11834 /* Walk through the list of incomplete types again, trying once more to
11835 emit full debugging info for them. */
11836 retry_incomplete_types ();
11838 /* We need to reverse all the dies before break_out_includes, or
11839 we'll see the end of an include file before the beginning. */
11840 reverse_all_dies (comp_unit_die);
11842 /* Generate separate CUs for each of the include files we've seen.
11843 They will go into limbo_die_list. */
11844 if (flag_eliminate_dwarf2_dups)
11845 break_out_includes (comp_unit_die);
11847 /* Traverse the DIE's and add add sibling attributes to those DIE's
11848 that have children. */
11849 add_sibling_attributes (comp_unit_die);
11850 for (node = limbo_die_list; node; node = node->next)
11851 add_sibling_attributes (node->die);
11853 /* Output a terminator label for the .text section. */
11854 fputc ('\n', asm_out_file);
11855 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11856 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11858 #if 0
11859 /* Output a terminator label for the .data section. */
11860 fputc ('\n', asm_out_file);
11861 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11862 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11864 /* Output a terminator label for the .bss section. */
11865 fputc ('\n', asm_out_file);
11866 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11867 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11868 #endif
11870 /* Output the source line correspondence table. */
11871 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
11873 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11875 fputc ('\n', asm_out_file);
11876 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11877 output_line_info ();
11880 /* We can only use the low/high_pc attributes if all of the code
11881 was in .text. */
11882 if (separate_line_info_table_in_use == 0)
11884 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11885 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11888 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11889 debug_line_section_label);
11892 #if 0 /* unimplemented */
11893 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
11894 add_AT_unsigned (die, DW_AT_macro_info, 0);
11895 #endif
11897 /* Output all of the compilation units. We put the main one last so that
11898 the offsets are available to output_pubnames. */
11899 for (node = limbo_die_list; node; node = node->next)
11900 output_comp_unit (node->die);
11901 output_comp_unit (comp_unit_die);
11903 /* Output the abbreviation table. */
11904 fputc ('\n', asm_out_file);
11905 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11906 output_abbrev_section ();
11908 if (pubname_table_in_use)
11910 /* Output public names table. */
11911 fputc ('\n', asm_out_file);
11912 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
11913 output_pubnames ();
11916 /* We only put functions in the arange table, so don't write it out if
11917 we don't have any. */
11918 if (fde_table_in_use)
11920 /* Output the address range information. */
11921 fputc ('\n', asm_out_file);
11922 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
11923 output_aranges ();
11926 /* At this point, we've switched sections like mad, but we've done
11927 so behind the back of varasm.c. Unfortunately, used
11928 named_section to switch sections doesn't work either; GAS 2.9.5
11929 is not pleased by:
11931 .section debug_aranges,"a",@progbits
11933 on i686-pc-linux-gnu.
11935 By calling force_data_section, we get varasm.c synched back up
11936 with reality. That makes subsequent calls to text_section and
11937 such make sense. */
11938 force_data_section ();
11940 #endif /* DWARF2_DEBUGGING_INFO */