2001-02-14 Tom Tromey <tromey@redhat.com>
[official-gcc.git] / gcc / dwarf2out.c
blobfa62101ef6faa0ad4600ff3a55bc65b648b3c929
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 DIE_LABEL_PREFIX "DW"
317 /* Definitions of defaults for various types of primitive assembly language
318 output operations. These may be overridden from within the tm.h file,
319 but typically, that is unnecessary. */
321 #ifndef ASM_OUTPUT_SECTION
322 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
323 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
324 #endif
326 #ifndef ASM_OUTPUT_DWARF_DATA1
327 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
328 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
329 #endif
331 #ifndef ASM_OUTPUT_DWARF_DELTA1
332 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
333 do { fprintf ((FILE), "%s", ASM_BYTE_OP); \
334 assemble_name (FILE, LABEL1); \
335 fprintf (FILE, "-"); \
336 assemble_name (FILE, LABEL2); \
337 } while (0)
338 #endif
340 #ifdef UNALIGNED_INT_ASM_OP
342 #ifndef UNALIGNED_OFFSET_ASM_OP
343 #define UNALIGNED_OFFSET_ASM_OP \
344 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
345 #endif
347 #ifndef UNALIGNED_WORD_ASM_OP
348 #define UNALIGNED_WORD_ASM_OP \
349 ((DWARF2_ADDR_SIZE) == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP \
350 : (DWARF2_ADDR_SIZE) == 2 ? UNALIGNED_SHORT_ASM_OP \
351 : UNALIGNED_INT_ASM_OP)
352 #endif
354 #ifndef ASM_OUTPUT_DWARF_DELTA2
355 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
356 do { fprintf ((FILE), "%s", UNALIGNED_SHORT_ASM_OP); \
357 assemble_name (FILE, LABEL1); \
358 fprintf (FILE, "-"); \
359 assemble_name (FILE, LABEL2); \
360 } while (0)
361 #endif
363 #ifndef ASM_OUTPUT_DWARF_DELTA4
364 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
365 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
366 assemble_name (FILE, LABEL1); \
367 fprintf (FILE, "-"); \
368 assemble_name (FILE, LABEL2); \
369 } while (0)
370 #endif
372 #ifndef ASM_OUTPUT_DWARF_DELTA
373 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
374 do { fprintf ((FILE), "%s", UNALIGNED_OFFSET_ASM_OP); \
375 assemble_name (FILE, LABEL1); \
376 fprintf (FILE, "-"); \
377 assemble_name (FILE, LABEL2); \
378 } while (0)
379 #endif
381 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
382 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
383 do { fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
384 assemble_name (FILE, LABEL1); \
385 fprintf (FILE, "-"); \
386 assemble_name (FILE, LABEL2); \
387 } while (0)
388 #endif
390 #ifndef ASM_OUTPUT_DWARF_ADDR
391 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
392 do { fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
393 assemble_name (FILE, LABEL); \
394 } while (0)
395 #endif
397 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
398 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
399 do { \
400 fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
401 output_addr_const ((FILE), (RTX)); \
402 } while (0)
403 #endif
405 #ifndef ASM_OUTPUT_DWARF_OFFSET4
406 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
407 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
408 assemble_name (FILE, LABEL); \
409 } while (0)
410 #endif
412 #ifndef ASM_OUTPUT_DWARF_OFFSET
413 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
414 do { fprintf ((FILE), "%s", UNALIGNED_OFFSET_ASM_OP); \
415 assemble_name (FILE, LABEL); \
416 } while (0)
417 #endif
419 #ifndef ASM_OUTPUT_DWARF_DATA2
420 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
421 fprintf ((FILE), "%s0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
422 #endif
424 #ifndef ASM_OUTPUT_DWARF_DATA4
425 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
426 fprintf ((FILE), "%s0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
427 #endif
429 #ifndef ASM_OUTPUT_DWARF_DATA8
430 #define ASM_OUTPUT_DWARF_DATA8(FILE,VALUE) \
431 fprintf ((FILE), "%s0x%lx", UNALIGNED_DOUBLE_INT_ASM_OP, \
432 (unsigned long) (VALUE))
433 #endif
435 #ifndef ASM_OUTPUT_DWARF_DATA
436 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
437 fprintf ((FILE), "%s0x%lx", UNALIGNED_OFFSET_ASM_OP, \
438 (unsigned long) (VALUE))
439 #endif
441 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
442 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
443 fprintf ((FILE), "%s0x%lx", UNALIGNED_WORD_ASM_OP, \
444 (unsigned long) (VALUE))
445 #endif
447 #ifndef ASM_OUTPUT_DWARF_CONST_DOUBLE
448 #define ASM_OUTPUT_DWARF_CONST_DOUBLE(FILE,HIGH_VALUE,LOW_VALUE) \
449 do { \
450 if (WORDS_BIG_ENDIAN) \
452 fprintf ((FILE), "%s0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
453 fprintf ((FILE), "%s0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
455 else \
457 fprintf ((FILE), "%s0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
458 fprintf ((FILE), "%s0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
460 } while (0)
461 #endif
463 #else /* UNALIGNED_INT_ASM_OP */
465 /* We don't have unaligned support, let's hope the normal output works for
466 .debug_frame. But we know it won't work for .debug_info. */
468 #ifdef DWARF2_DEBUGGING_INFO
469 #error DWARF2_DEBUGGING_INFO requires UNALIGNED_INT_ASM_OP.
470 #endif
472 #ifndef ASM_OUTPUT_DWARF_ADDR
473 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
474 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), DWARF2_ADDR_SIZE, 1)
475 #endif
477 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
478 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) ASM_OUTPUT_DWARF_ADDR (FILE,RTX)
479 #endif
481 #ifndef ASM_OUTPUT_DWARF_OFFSET4
482 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
483 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
484 #endif
486 #ifndef ASM_OUTPUT_DWARF_OFFSET
487 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
488 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
489 #endif
491 #ifndef ASM_OUTPUT_DWARF_DELTA2
492 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
493 assemble_integer (gen_rtx_MINUS (HImode, \
494 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
495 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
496 2, 1)
497 #endif
499 #ifndef ASM_OUTPUT_DWARF_DELTA4
500 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
501 assemble_integer (gen_rtx_MINUS (SImode, \
502 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
503 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
504 4, 1)
505 #endif
507 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
508 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
509 assemble_integer (gen_rtx_MINUS (Pmode, \
510 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
511 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
512 DWARF2_ADDR_SIZE, 1)
513 #endif
515 #ifndef ASM_OUTPUT_DWARF_DELTA
516 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
517 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
518 #endif
520 #ifndef ASM_OUTPUT_DWARF_DATA2
521 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
522 assemble_integer (GEN_INT (VALUE), 2, 1)
523 #endif
525 #ifndef ASM_OUTPUT_DWARF_DATA4
526 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
527 assemble_integer (GEN_INT (VALUE), 4, 1)
528 #endif
530 #endif /* UNALIGNED_INT_ASM_OP */
532 #ifdef SET_ASM_OP
533 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
534 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
535 do { \
536 fprintf (FILE, "%s", SET_ASM_OP); \
537 assemble_name (FILE, SY); \
538 fputc (',', FILE); \
539 assemble_name (FILE, HI); \
540 fputc ('-', FILE); \
541 assemble_name (FILE, LO); \
542 } while (0)
543 #endif
544 #endif /* SET_ASM_OP */
546 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
547 newline is produced. When flag_debug_asm is asserted, we add commentary
548 at the end of the line, so we must avoid output of a newline here. */
549 #ifndef ASM_OUTPUT_DWARF_NSTRING
550 #define ASM_OUTPUT_DWARF_NSTRING(FILE,P,SLEN) \
551 do { \
552 register int slen = (SLEN); \
553 register const char *p = (P); \
554 register int i; \
555 fprintf (FILE, "\t.ascii \""); \
556 for (i = 0; i < slen; i++) \
558 register int c = p[i]; \
559 if (c == '\"' || c == '\\') \
560 putc ('\\', FILE); \
561 if (ISPRINT(c)) \
562 putc (c, FILE); \
563 else \
565 fprintf (FILE, "\\%o", c); \
568 fprintf (FILE, "\\0\""); \
570 while (0)
571 #endif
572 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
573 ASM_OUTPUT_DWARF_NSTRING (FILE, P, strlen (P))
575 /* The DWARF 2 CFA column which tracks the return address. Normally this
576 is the column for PC, or the first column after all of the hard
577 registers. */
578 #ifndef DWARF_FRAME_RETURN_COLUMN
579 #ifdef PC_REGNUM
580 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
581 #else
582 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
583 #endif
584 #endif
586 /* The mapping from gcc register number to DWARF 2 CFA column number. By
587 default, we just provide columns for all registers. */
588 #ifndef DWARF_FRAME_REGNUM
589 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
590 #endif
592 /* Hook used by __throw. */
595 expand_builtin_dwarf_fp_regnum ()
597 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
600 /* The offset from the incoming value of %sp to the top of the stack frame
601 for the current function. */
602 #ifndef INCOMING_FRAME_SP_OFFSET
603 #define INCOMING_FRAME_SP_OFFSET 0
604 #endif
606 /* Return a pointer to a copy of the section string name S with all
607 attributes stripped off, and an asterisk prepended (for assemble_name). */
609 static inline char *
610 stripattributes (s)
611 const char *s;
613 char *stripped = xmalloc (strlen (s) + 2);
614 char *p = stripped;
616 *p++ = '*';
618 while (*s && *s != ',')
619 *p++ = *s++;
621 *p = '\0';
622 return stripped;
625 /* Generate code to initialize the register size table. */
627 void
628 expand_builtin_init_dwarf_reg_sizes (address)
629 tree address;
631 int i;
632 enum machine_mode mode = TYPE_MODE (char_type_node);
633 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
634 rtx mem = gen_rtx_MEM (mode, addr);
636 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
638 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
639 int size = GET_MODE_SIZE (reg_raw_mode[i]);
641 if (offset < 0)
642 continue;
644 emit_move_insn (change_address (mem, mode,
645 plus_constant (addr, offset)),
646 GEN_INT (size));
650 /* Convert a DWARF call frame info. operation to its string name */
652 static const char *
653 dwarf_cfi_name (cfi_opc)
654 register unsigned cfi_opc;
656 switch (cfi_opc)
658 case DW_CFA_advance_loc:
659 return "DW_CFA_advance_loc";
660 case DW_CFA_offset:
661 return "DW_CFA_offset";
662 case DW_CFA_restore:
663 return "DW_CFA_restore";
664 case DW_CFA_nop:
665 return "DW_CFA_nop";
666 case DW_CFA_set_loc:
667 return "DW_CFA_set_loc";
668 case DW_CFA_advance_loc1:
669 return "DW_CFA_advance_loc1";
670 case DW_CFA_advance_loc2:
671 return "DW_CFA_advance_loc2";
672 case DW_CFA_advance_loc4:
673 return "DW_CFA_advance_loc4";
674 case DW_CFA_offset_extended:
675 return "DW_CFA_offset_extended";
676 case DW_CFA_restore_extended:
677 return "DW_CFA_restore_extended";
678 case DW_CFA_undefined:
679 return "DW_CFA_undefined";
680 case DW_CFA_same_value:
681 return "DW_CFA_same_value";
682 case DW_CFA_register:
683 return "DW_CFA_register";
684 case DW_CFA_remember_state:
685 return "DW_CFA_remember_state";
686 case DW_CFA_restore_state:
687 return "DW_CFA_restore_state";
688 case DW_CFA_def_cfa:
689 return "DW_CFA_def_cfa";
690 case DW_CFA_def_cfa_register:
691 return "DW_CFA_def_cfa_register";
692 case DW_CFA_def_cfa_offset:
693 return "DW_CFA_def_cfa_offset";
694 case DW_CFA_def_cfa_expression:
695 return "DW_CFA_def_cfa_expression";
697 /* SGI/MIPS specific */
698 case DW_CFA_MIPS_advance_loc8:
699 return "DW_CFA_MIPS_advance_loc8";
701 /* GNU extensions */
702 case DW_CFA_GNU_window_save:
703 return "DW_CFA_GNU_window_save";
704 case DW_CFA_GNU_args_size:
705 return "DW_CFA_GNU_args_size";
706 case DW_CFA_GNU_negative_offset_extended:
707 return "DW_CFA_GNU_negative_offset_extended";
709 default:
710 return "DW_CFA_<unknown>";
714 /* Return a pointer to a newly allocated Call Frame Instruction. */
716 static inline dw_cfi_ref
717 new_cfi ()
719 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
721 cfi->dw_cfi_next = NULL;
722 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
723 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
725 return cfi;
728 /* Add a Call Frame Instruction to list of instructions. */
730 static inline void
731 add_cfi (list_head, cfi)
732 register dw_cfi_ref *list_head;
733 register dw_cfi_ref cfi;
735 register dw_cfi_ref *p;
737 /* Find the end of the chain. */
738 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
741 *p = cfi;
744 /* Generate a new label for the CFI info to refer to. */
746 char *
747 dwarf2out_cfi_label ()
749 static char label[20];
750 static unsigned long label_num = 0;
752 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
753 ASM_OUTPUT_LABEL (asm_out_file, label);
755 return label;
758 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
759 or to the CIE if LABEL is NULL. */
761 static void
762 add_fde_cfi (label, cfi)
763 register const char *label;
764 register dw_cfi_ref cfi;
766 if (label)
768 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
770 if (*label == 0)
771 label = dwarf2out_cfi_label ();
773 if (fde->dw_fde_current_label == NULL
774 || strcmp (label, fde->dw_fde_current_label) != 0)
776 register dw_cfi_ref xcfi;
778 fde->dw_fde_current_label = label = xstrdup (label);
780 /* Set the location counter to the new label. */
781 xcfi = new_cfi ();
782 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
783 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
784 add_cfi (&fde->dw_fde_cfi, xcfi);
787 add_cfi (&fde->dw_fde_cfi, cfi);
790 else
791 add_cfi (&cie_cfi_head, cfi);
794 /* Subroutine of lookup_cfa. */
796 static inline void
797 lookup_cfa_1 (cfi, loc)
798 register dw_cfi_ref cfi;
799 register dw_cfa_location *loc;
801 switch (cfi->dw_cfi_opc)
803 case DW_CFA_def_cfa_offset:
804 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
805 break;
806 case DW_CFA_def_cfa_register:
807 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
808 break;
809 case DW_CFA_def_cfa:
810 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
811 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
812 break;
813 case DW_CFA_def_cfa_expression:
814 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
815 break;
816 default:
817 break;
821 /* Find the previous value for the CFA. */
823 static void
824 lookup_cfa (loc)
825 register dw_cfa_location *loc;
827 register dw_cfi_ref cfi;
829 loc->reg = (unsigned long) -1;
830 loc->offset = 0;
831 loc->indirect = 0;
832 loc->base_offset = 0;
834 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
835 lookup_cfa_1 (cfi, loc);
837 if (fde_table_in_use)
839 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
840 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
841 lookup_cfa_1 (cfi, loc);
845 /* The current rule for calculating the DWARF2 canonical frame address. */
846 dw_cfa_location cfa;
848 /* The register used for saving registers to the stack, and its offset
849 from the CFA. */
850 dw_cfa_location cfa_store;
852 /* The running total of the size of arguments pushed onto the stack. */
853 static long args_size;
855 /* The last args_size we actually output. */
856 static long old_args_size;
858 /* Entry point to update the canonical frame address (CFA).
859 LABEL is passed to add_fde_cfi. The value of CFA is now to be
860 calculated from REG+OFFSET. */
862 void
863 dwarf2out_def_cfa (label, reg, offset)
864 register const char *label;
865 unsigned reg;
866 long offset;
868 dw_cfa_location loc;
869 loc.indirect = 0;
870 loc.base_offset = 0;
871 loc.reg = reg;
872 loc.offset = offset;
873 def_cfa_1 (label, &loc);
876 /* This routine does the actual work. The CFA is now calculated from
877 the dw_cfa_location structure. */
878 static void
879 def_cfa_1 (label, loc_p)
880 register const char *label;
881 dw_cfa_location *loc_p;
883 register dw_cfi_ref cfi;
884 dw_cfa_location old_cfa, loc;
886 cfa = *loc_p;
887 loc = *loc_p;
889 if (cfa_store.reg == loc.reg && loc.indirect == 0)
890 cfa_store.offset = loc.offset;
892 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
893 lookup_cfa (&old_cfa);
895 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
896 loc.indirect == old_cfa.indirect)
898 if (loc.indirect == 0
899 || loc.base_offset == old_cfa.base_offset)
900 /* Nothing changed so no need to issue any call frame
901 instructions. */
902 return;
905 cfi = new_cfi ();
907 if (loc.reg == old_cfa.reg && !loc.indirect)
909 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
910 indicating the CFA register did not change but the offset
911 did. */
912 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
913 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
916 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
917 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
918 && !loc.indirect)
920 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
921 indicating the CFA register has changed to <register> but the
922 offset has not changed. */
923 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
924 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
926 #endif
928 else if (loc.indirect == 0)
930 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
931 indicating the CFA register has changed to <register> with
932 the specified offset. */
933 cfi->dw_cfi_opc = DW_CFA_def_cfa;
934 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
935 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
937 else
939 /* Construct a DW_CFA_def_cfa_expression instruction to
940 calculate the CFA using a full location expression since no
941 register-offset pair is available. */
942 struct dw_loc_descr_struct *loc_list;
943 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
944 loc_list = build_cfa_loc (&loc);
945 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
948 add_fde_cfi (label, cfi);
951 /* Add the CFI for saving a register. REG is the CFA column number.
952 LABEL is passed to add_fde_cfi.
953 If SREG is -1, the register is saved at OFFSET from the CFA;
954 otherwise it is saved in SREG. */
956 static void
957 reg_save (label, reg, sreg, offset)
958 register const char *label;
959 register unsigned reg;
960 register unsigned sreg;
961 register long offset;
963 register dw_cfi_ref cfi = new_cfi ();
965 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
967 /* The following comparison is correct. -1 is used to indicate that
968 the value isn't a register number. */
969 if (sreg == (unsigned int) -1)
971 if (reg & ~0x3f)
972 /* The register number won't fit in 6 bits, so we have to use
973 the long form. */
974 cfi->dw_cfi_opc = DW_CFA_offset_extended;
975 else
976 cfi->dw_cfi_opc = DW_CFA_offset;
978 #ifdef ENABLE_CHECKING
980 /* If we get an offset that is not a multiple of
981 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
982 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
983 description. */
984 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
986 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
987 abort ();
989 #endif
990 offset /= DWARF_CIE_DATA_ALIGNMENT;
991 if (offset < 0)
993 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
994 offset = -offset;
996 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
998 else if (sreg == reg)
999 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
1000 return;
1001 else
1003 cfi->dw_cfi_opc = DW_CFA_register;
1004 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1007 add_fde_cfi (label, cfi);
1010 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1011 This CFI tells the unwinder that it needs to restore the window registers
1012 from the previous frame's window save area.
1014 ??? Perhaps we should note in the CIE where windows are saved (instead of
1015 assuming 0(cfa)) and what registers are in the window. */
1017 void
1018 dwarf2out_window_save (label)
1019 register const char *label;
1021 register dw_cfi_ref cfi = new_cfi ();
1022 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1023 add_fde_cfi (label, cfi);
1026 /* Add a CFI to update the running total of the size of arguments
1027 pushed onto the stack. */
1029 void
1030 dwarf2out_args_size (label, size)
1031 const char *label;
1032 long size;
1034 register dw_cfi_ref cfi;
1036 if (size == old_args_size)
1037 return;
1038 old_args_size = size;
1040 cfi = new_cfi ();
1041 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1042 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1043 add_fde_cfi (label, cfi);
1046 /* Entry point for saving a register to the stack. REG is the GCC register
1047 number. LABEL and OFFSET are passed to reg_save. */
1049 void
1050 dwarf2out_reg_save (label, reg, offset)
1051 register const char *label;
1052 register unsigned reg;
1053 register long offset;
1055 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
1058 /* Entry point for saving the return address in the stack.
1059 LABEL and OFFSET are passed to reg_save. */
1061 void
1062 dwarf2out_return_save (label, offset)
1063 register const char *label;
1064 register long offset;
1066 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
1069 /* Entry point for saving the return address in a register.
1070 LABEL and SREG are passed to reg_save. */
1072 void
1073 dwarf2out_return_reg (label, sreg)
1074 register const char *label;
1075 register unsigned sreg;
1077 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
1080 /* Record the initial position of the return address. RTL is
1081 INCOMING_RETURN_ADDR_RTX. */
1083 static void
1084 initial_return_save (rtl)
1085 register rtx rtl;
1087 unsigned int reg = (unsigned int) -1;
1088 long offset = 0;
1090 switch (GET_CODE (rtl))
1092 case REG:
1093 /* RA is in a register. */
1094 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1095 break;
1096 case MEM:
1097 /* RA is on the stack. */
1098 rtl = XEXP (rtl, 0);
1099 switch (GET_CODE (rtl))
1101 case REG:
1102 if (REGNO (rtl) != STACK_POINTER_REGNUM)
1103 abort ();
1104 offset = 0;
1105 break;
1106 case PLUS:
1107 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1108 abort ();
1109 offset = INTVAL (XEXP (rtl, 1));
1110 break;
1111 case MINUS:
1112 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1113 abort ();
1114 offset = -INTVAL (XEXP (rtl, 1));
1115 break;
1116 default:
1117 abort ();
1119 break;
1120 case PLUS:
1121 /* The return address is at some offset from any value we can
1122 actually load. For instance, on the SPARC it is in %i7+8. Just
1123 ignore the offset for now; it doesn't matter for unwinding frames. */
1124 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
1125 abort ();
1126 initial_return_save (XEXP (rtl, 0));
1127 return;
1128 default:
1129 abort ();
1132 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1135 /* Given a SET, calculate the amount of stack adjustment it
1136 contains. */
1138 static long
1139 stack_adjust_offset (pattern)
1140 rtx pattern;
1142 rtx src = SET_SRC (pattern);
1143 rtx dest = SET_DEST (pattern);
1144 long offset = 0;
1145 enum rtx_code code;
1147 if (dest == stack_pointer_rtx)
1149 /* (set (reg sp) (plus (reg sp) (const_int))) */
1150 code = GET_CODE (src);
1151 if (! (code == PLUS || code == MINUS)
1152 || XEXP (src, 0) != stack_pointer_rtx
1153 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1154 return 0;
1156 offset = INTVAL (XEXP (src, 1));
1158 else if (GET_CODE (dest) == MEM)
1160 /* (set (mem (pre_dec (reg sp))) (foo)) */
1161 src = XEXP (dest, 0);
1162 code = GET_CODE (src);
1164 if (! (code == PRE_DEC || code == PRE_INC
1165 || code == PRE_MODIFY)
1166 || XEXP (src, 0) != stack_pointer_rtx)
1167 return 0;
1169 if (code == PRE_MODIFY)
1171 rtx val = XEXP (XEXP (src, 1), 1);
1172 /* We handle only adjustments by constant amount. */
1173 if (GET_CODE (XEXP (src, 1)) != PLUS ||
1174 GET_CODE (val) != CONST_INT)
1175 abort();
1176 offset = -INTVAL (val);
1178 else offset = GET_MODE_SIZE (GET_MODE (dest));
1180 else
1181 return 0;
1183 if (code == PLUS || code == PRE_INC)
1184 offset = -offset;
1186 return offset;
1189 /* Check INSN to see if it looks like a push or a stack adjustment, and
1190 make a note of it if it does. EH uses this information to find out how
1191 much extra space it needs to pop off the stack. */
1193 static void
1194 dwarf2out_stack_adjust (insn)
1195 rtx insn;
1197 long offset;
1198 const char *label;
1200 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1202 /* Extract the size of the args from the CALL rtx itself. */
1204 insn = PATTERN (insn);
1205 if (GET_CODE (insn) == PARALLEL)
1206 insn = XVECEXP (insn, 0, 0);
1207 if (GET_CODE (insn) == SET)
1208 insn = SET_SRC (insn);
1209 if (GET_CODE (insn) != CALL)
1210 abort ();
1211 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1212 return;
1215 /* If only calls can throw, and we have a frame pointer,
1216 save up adjustments until we see the CALL_INSN. */
1217 else if (! asynchronous_exceptions
1218 && cfa.reg != STACK_POINTER_REGNUM)
1219 return;
1221 if (GET_CODE (insn) == BARRIER)
1223 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1224 the compiler will have already emitted a stack adjustment, but
1225 doesn't bother for calls to noreturn functions. */
1226 #ifdef STACK_GROWS_DOWNWARD
1227 offset = -args_size;
1228 #else
1229 offset = args_size;
1230 #endif
1232 else if (GET_CODE (PATTERN (insn)) == SET)
1234 offset = stack_adjust_offset (PATTERN (insn));
1236 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1237 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1239 /* There may be stack adjustments inside compound insns. Search
1240 for them. */
1241 int j;
1243 offset = 0;
1244 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1246 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1247 if (GET_CODE (pattern) == SET)
1248 offset += stack_adjust_offset (pattern);
1251 else
1252 return;
1254 if (offset == 0)
1255 return;
1257 if (cfa.reg == STACK_POINTER_REGNUM)
1258 cfa.offset += offset;
1260 #ifndef STACK_GROWS_DOWNWARD
1261 offset = -offset;
1262 #endif
1263 args_size += offset;
1264 if (args_size < 0)
1265 args_size = 0;
1267 label = dwarf2out_cfi_label ();
1268 def_cfa_1 (label, &cfa);
1269 dwarf2out_args_size (label, args_size);
1272 /* A temporary register holding an integral value used in adjusting SP
1273 or setting up the store_reg. The "offset" field holds the integer
1274 value, not an offset. */
1275 dw_cfa_location cfa_temp;
1277 /* Record call frame debugging information for an expression EXPR,
1278 which either sets SP or FP (adjusting how we calculate the frame
1279 address) or saves a register to the stack. LABEL indicates the
1280 address of EXPR.
1282 This function encodes a state machine mapping rtxes to actions on
1283 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1284 users need not read the source code.
1286 The High-Level Picture
1288 Changes in the register we use to calculate the CFA: Currently we
1289 assume that if you copy the CFA register into another register, we
1290 should take the other one as the new CFA register; this seems to
1291 work pretty well. If it's wrong for some target, it's simple
1292 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1294 Changes in the register we use for saving registers to the stack:
1295 This is usually SP, but not always. Again, we deduce that if you
1296 copy SP into another register (and SP is not the CFA register),
1297 then the new register is the one we will be using for register
1298 saves. This also seems to work.
1300 Register saves: There's not much guesswork about this one; if
1301 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1302 register save, and the register used to calculate the destination
1303 had better be the one we think we're using for this purpose.
1305 Except: If the register being saved is the CFA register, and the
1306 offset is non-zero, we are saving the CFA, so we assume we have to
1307 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1308 the intent is to save the value of SP from the previous frame.
1310 Invariants / Summaries of Rules
1312 cfa current rule for calculating the CFA. It usually
1313 consists of a register and an offset.
1314 cfa_store register used by prologue code to save things to the stack
1315 cfa_store.offset is the offset from the value of
1316 cfa_store.reg to the actual CFA
1317 cfa_temp register holding an integral value. cfa_temp.offset
1318 stores the value, which will be used to adjust the
1319 stack pointer.
1321 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1322 with cfa.reg as the first operand changes the cfa.reg and its
1323 cfa.offset.
1325 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1326 expression yielding a constant. This sets cfa_temp.reg
1327 and cfa_temp.offset.
1329 Rule 5: Create a new register cfa_store used to save items to the
1330 stack.
1332 Rules 10-13: Save a register to the stack. Define offset as the
1333 difference of the original location and cfa_store's
1334 location.
1336 The Rules
1338 "{a,b}" indicates a choice of a xor b.
1339 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1341 Rule 1:
1342 (set <reg1> <reg2>:cfa.reg)
1343 effects: cfa.reg = <REG1>
1344 cfa.offset unchanged
1346 Rule 2:
1347 (set sp ({minus,plus} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
1348 effects: cfa.reg = sp if fp used
1349 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1350 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1351 if cfa_store.reg==sp
1353 Rule 3:
1354 (set fp ({minus,plus} <reg>:cfa.reg <const_int>))
1355 effects: cfa.reg = fp
1356 cfa_offset += +/- <const_int>
1358 Rule 4:
1359 (set <reg1> (plus <reg2>:cfa.reg <const_int>))
1360 constraints: <reg1> != fp
1361 <reg1> != sp
1362 effects: cfa.reg = <reg1>
1364 Rule 5:
1365 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1366 constraints: <reg1> != fp
1367 <reg1> != sp
1368 effects: cfa_store.reg = <reg1>
1369 cfa_store.offset = cfa.offset - cfa_temp.offset
1371 Rule 6:
1372 (set <reg> <const_int>)
1373 effects: cfa_temp.reg = <reg>
1374 cfa_temp.offset = <const_int>
1376 Rule 7:
1377 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1378 effects: cfa_temp.reg = <reg1>
1379 cfa_temp.offset |= <const_int>
1381 Rule 8:
1382 (set <reg> (high <exp>))
1383 effects: none
1385 Rule 9:
1386 (set <reg> (lo_sum <exp> <const_int>))
1387 effects: cfa_temp.reg = <reg>
1388 cfa_temp.offset = <const_int>
1390 Rule 10:
1391 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1392 effects: cfa_store.offset -= <const_int>
1393 cfa.offset = cfa_store.offset if cfa.reg == sp
1394 offset = -cfa_store.offset
1395 cfa.reg = sp
1396 cfa.base_offset = offset
1398 Rule 11:
1399 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1400 effects: cfa_store.offset += -/+ mode_size(mem)
1401 cfa.offset = cfa_store.offset if cfa.reg == sp
1402 offset = -cfa_store.offset
1403 cfa.reg = sp
1404 cfa.base_offset = offset
1406 Rule 12:
1407 (set (mem ({minus,plus} <reg1>:cfa_store <const_int>)) <reg2>)
1408 effects: cfa_store.offset += -/+ <const_int>
1409 offset = -cfa_store.offset
1410 cfa.reg = <reg1
1411 cfa.base_offset = offset
1413 Rule 13:
1414 (set (mem <reg1>:cfa_store) <reg2>)
1415 effects: offset = -cfa_store.offset
1416 cfa.reg = <reg1>
1417 cfa.base_offset = offset */
1419 static void
1420 dwarf2out_frame_debug_expr (expr, label)
1421 rtx expr;
1422 const char *label;
1424 rtx src, dest;
1425 long offset;
1427 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1428 the PARALLEL independently. The first element is always processed if
1429 it is a SET. This is for backward compatibility. Other elements
1430 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1431 flag is set in them. */
1433 if (GET_CODE (expr) == PARALLEL
1434 || GET_CODE (expr) == SEQUENCE)
1436 int par_index;
1437 int limit = XVECLEN (expr, 0);
1439 for (par_index = 0; par_index < limit; par_index++)
1441 rtx x = XVECEXP (expr, 0, par_index);
1443 if (GET_CODE (x) == SET &&
1444 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1445 dwarf2out_frame_debug_expr (x, label);
1447 return;
1450 if (GET_CODE (expr) != SET)
1451 abort ();
1453 src = SET_SRC (expr);
1454 dest = SET_DEST (expr);
1456 switch (GET_CODE (dest))
1458 case REG:
1459 /* Rule 1 */
1460 /* Update the CFA rule wrt SP or FP. Make sure src is
1461 relative to the current CFA register. */
1462 switch (GET_CODE (src))
1464 /* Setting FP from SP. */
1465 case REG:
1466 if (cfa.reg == (unsigned) REGNO (src))
1467 /* OK. */
1469 else
1470 abort ();
1472 /* We used to require that dest be either SP or FP, but the
1473 ARM copies SP to a temporary register, and from there to
1474 FP. So we just rely on the backends to only set
1475 RTX_FRAME_RELATED_P on appropriate insns. */
1476 cfa.reg = REGNO (dest);
1477 break;
1479 case PLUS:
1480 case MINUS:
1481 if (dest == stack_pointer_rtx)
1483 /* Rule 2 */
1484 /* Adjusting SP. */
1485 switch (GET_CODE (XEXP (src, 1)))
1487 case CONST_INT:
1488 offset = INTVAL (XEXP (src, 1));
1489 break;
1490 case REG:
1491 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1492 abort ();
1493 offset = cfa_temp.offset;
1494 break;
1495 default:
1496 abort ();
1499 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1501 /* Restoring SP from FP in the epilogue. */
1502 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1503 abort ();
1504 cfa.reg = STACK_POINTER_REGNUM;
1506 else if (XEXP (src, 0) != stack_pointer_rtx)
1507 abort ();
1509 if (GET_CODE (src) == PLUS)
1510 offset = -offset;
1511 if (cfa.reg == STACK_POINTER_REGNUM)
1512 cfa.offset += offset;
1513 if (cfa_store.reg == STACK_POINTER_REGNUM)
1514 cfa_store.offset += offset;
1516 else if (dest == hard_frame_pointer_rtx)
1518 /* Rule 3 */
1519 /* Either setting the FP from an offset of the SP,
1520 or adjusting the FP */
1521 if (! frame_pointer_needed)
1522 abort ();
1524 if (GET_CODE (XEXP (src, 0)) == REG
1525 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1526 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1528 offset = INTVAL (XEXP (src, 1));
1529 if (GET_CODE (src) == PLUS)
1530 offset = -offset;
1531 cfa.offset += offset;
1532 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1534 else
1535 abort ();
1537 else
1539 if (GET_CODE (src) != PLUS)
1540 abort ();
1542 /* Rule 4 */
1543 if (GET_CODE (XEXP (src, 0)) == REG
1544 && REGNO (XEXP (src, 0)) == cfa.reg
1545 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1547 /* Setting a temporary CFA register that will be copied
1548 into the FP later on. */
1549 offset = INTVAL (XEXP (src, 1));
1550 if (GET_CODE (src) == PLUS)
1551 offset = -offset;
1552 cfa.offset += offset;
1553 cfa.reg = REGNO (dest);
1555 /* Rule 5 */
1556 else
1558 /* Setting a scratch register that we will use instead
1559 of SP for saving registers to the stack. */
1560 if (XEXP (src, 1) != stack_pointer_rtx)
1561 abort ();
1562 if (GET_CODE (XEXP (src, 0)) != REG
1563 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg)
1564 abort ();
1565 if (cfa.reg != STACK_POINTER_REGNUM)
1566 abort ();
1567 cfa_store.reg = REGNO (dest);
1568 cfa_store.offset = cfa.offset - cfa_temp.offset;
1571 break;
1573 /* Rule 6 */
1574 case CONST_INT:
1575 cfa_temp.reg = REGNO (dest);
1576 cfa_temp.offset = INTVAL (src);
1577 break;
1579 /* Rule 7 */
1580 case IOR:
1581 if (GET_CODE (XEXP (src, 0)) != REG
1582 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1583 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1584 abort ();
1585 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1586 cfa_temp.reg = REGNO (dest);
1587 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1588 break;
1590 default:
1591 abort ();
1593 def_cfa_1 (label, &cfa);
1594 break;
1596 /* Skip over HIGH, assuming it will be followed by a LO_SUM, which
1597 will fill in all of the bits. */
1598 /* Rule 8 */
1599 case HIGH:
1600 break;
1602 /* Rule 9 */
1603 case LO_SUM:
1604 if (GET_CODE (XEXP (src, 1)) != CONST_INT)
1605 abort ();
1606 cfa_temp.reg = REGNO (dest);
1607 cfa_temp.offset = INTVAL (XEXP (src, 1));
1608 break;
1610 case MEM:
1611 if (GET_CODE (src) != REG)
1612 abort ();
1614 /* Saving a register to the stack. Make sure dest is relative to the
1615 CFA register. */
1616 switch (GET_CODE (XEXP (dest, 0)))
1618 /* Rule 10 */
1619 /* With a push. */
1620 case PRE_MODIFY:
1621 /* We can't handle variable size modifications. */
1622 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1623 abort();
1624 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1626 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1627 || cfa_store.reg != STACK_POINTER_REGNUM)
1628 abort ();
1629 cfa_store.offset += offset;
1630 if (cfa.reg == STACK_POINTER_REGNUM)
1631 cfa.offset = cfa_store.offset;
1633 offset = -cfa_store.offset;
1634 break;
1635 /* Rule 11 */
1636 case PRE_INC:
1637 case PRE_DEC:
1638 offset = GET_MODE_SIZE (GET_MODE (dest));
1639 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1640 offset = -offset;
1642 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1643 || cfa_store.reg != STACK_POINTER_REGNUM)
1644 abort ();
1645 cfa_store.offset += offset;
1646 if (cfa.reg == STACK_POINTER_REGNUM)
1647 cfa.offset = cfa_store.offset;
1649 offset = -cfa_store.offset;
1650 break;
1652 /* Rule 12 */
1653 /* With an offset. */
1654 case PLUS:
1655 case MINUS:
1656 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1657 abort ();
1658 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1659 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1660 offset = -offset;
1662 if (cfa_store.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1663 abort ();
1664 offset -= cfa_store.offset;
1665 break;
1667 /* Rule 13 */
1668 /* Without an offset. */
1669 case REG:
1670 if (cfa_store.reg != (unsigned) REGNO (XEXP (dest, 0)))
1671 abort ();
1672 offset = -cfa_store.offset;
1673 break;
1675 default:
1676 abort ();
1679 if (REGNO (src) != STACK_POINTER_REGNUM
1680 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1681 && (unsigned) REGNO (src) == cfa.reg)
1683 /* We're storing the current CFA reg into the stack. */
1685 if (cfa.offset == 0)
1687 /* If the source register is exactly the CFA, assume
1688 we're saving SP like any other register; this happens
1689 on the ARM. */
1691 def_cfa_1 (label, &cfa);
1692 dwarf2out_reg_save (label, STACK_POINTER_REGNUM, offset);
1693 break;
1695 else
1697 /* Otherwise, we'll need to look in the stack to
1698 calculate the CFA. */
1700 rtx x = XEXP (dest, 0);
1701 if (GET_CODE (x) != REG)
1702 x = XEXP (x, 0);
1703 if (GET_CODE (x) != REG)
1704 abort ();
1705 cfa.reg = (unsigned) REGNO (x);
1706 cfa.base_offset = offset;
1707 cfa.indirect = 1;
1708 def_cfa_1 (label, &cfa);
1709 break;
1713 def_cfa_1 (label, &cfa);
1714 dwarf2out_reg_save (label, REGNO (src), offset);
1715 break;
1717 default:
1718 abort ();
1722 /* Record call frame debugging information for INSN, which either
1723 sets SP or FP (adjusting how we calculate the frame address) or saves a
1724 register to the stack. If INSN is NULL_RTX, initialize our state. */
1726 void
1727 dwarf2out_frame_debug (insn)
1728 rtx insn;
1730 const char *label;
1731 rtx src;
1733 if (insn == NULL_RTX)
1735 /* Set up state for generating call frame debug info. */
1736 lookup_cfa (&cfa);
1737 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1738 abort ();
1739 cfa.reg = STACK_POINTER_REGNUM;
1740 cfa_store = cfa;
1741 cfa_temp.reg = -1;
1742 cfa_temp.offset = 0;
1743 return;
1746 if (! RTX_FRAME_RELATED_P (insn))
1748 dwarf2out_stack_adjust (insn);
1749 return;
1752 label = dwarf2out_cfi_label ();
1754 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1755 if (src)
1756 insn = XEXP (src, 0);
1757 else
1758 insn = PATTERN (insn);
1760 dwarf2out_frame_debug_expr (insn, label);
1763 /* Return the size of an unsigned LEB128 quantity. */
1765 static inline unsigned long
1766 size_of_uleb128 (value)
1767 register unsigned long value;
1769 register unsigned long size = 0;
1770 register unsigned byte;
1774 byte = (value & 0x7f);
1775 value >>= 7;
1776 size += 1;
1778 while (value != 0);
1780 return size;
1783 /* Return the size of a signed LEB128 quantity. */
1785 static inline unsigned long
1786 size_of_sleb128 (value)
1787 register long value;
1789 register unsigned long size = 0;
1790 register unsigned byte;
1794 byte = (value & 0x7f);
1795 value >>= 7;
1796 size += 1;
1798 while (!(((value == 0) && ((byte & 0x40) == 0))
1799 || ((value == -1) && ((byte & 0x40) != 0))));
1801 return size;
1804 /* Output an unsigned LEB128 quantity. */
1806 static void
1807 output_uleb128 (value)
1808 register unsigned long value;
1810 unsigned long save_value = value;
1812 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1815 register unsigned byte = (value & 0x7f);
1816 value >>= 7;
1817 if (value != 0)
1818 /* More bytes to follow. */
1819 byte |= 0x80;
1821 fprintf (asm_out_file, "0x%x", byte);
1822 if (value != 0)
1823 fprintf (asm_out_file, ",");
1825 while (value != 0);
1827 if (flag_debug_asm)
1828 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1831 /* Output an signed LEB128 quantity. */
1833 static void
1834 output_sleb128 (value)
1835 register long value;
1837 register int more;
1838 register unsigned byte;
1839 long save_value = value;
1841 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1844 byte = (value & 0x7f);
1845 /* arithmetic shift */
1846 value >>= 7;
1847 more = !((((value == 0) && ((byte & 0x40) == 0))
1848 || ((value == -1) && ((byte & 0x40) != 0))));
1849 if (more)
1850 byte |= 0x80;
1852 fprintf (asm_out_file, "0x%x", byte);
1853 if (more)
1854 fprintf (asm_out_file, ",");
1857 while (more);
1858 if (flag_debug_asm)
1859 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1862 /* Output a Call Frame Information opcode and its operand(s). */
1864 static void
1865 output_cfi (cfi, fde)
1866 register dw_cfi_ref cfi;
1867 register dw_fde_ref fde;
1869 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1871 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1872 cfi->dw_cfi_opc
1873 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1874 if (flag_debug_asm)
1875 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1876 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1877 fputc ('\n', asm_out_file);
1880 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1882 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1883 cfi->dw_cfi_opc
1884 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1885 if (flag_debug_asm)
1886 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1887 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1889 fputc ('\n', asm_out_file);
1890 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1891 fputc ('\n', asm_out_file);
1893 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1895 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1896 cfi->dw_cfi_opc
1897 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1898 if (flag_debug_asm)
1899 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1900 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1902 fputc ('\n', asm_out_file);
1904 else
1906 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1907 if (flag_debug_asm)
1908 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1909 dwarf_cfi_name (cfi->dw_cfi_opc));
1911 fputc ('\n', asm_out_file);
1912 switch (cfi->dw_cfi_opc)
1914 case DW_CFA_set_loc:
1915 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1916 fputc ('\n', asm_out_file);
1917 break;
1918 case DW_CFA_advance_loc1:
1919 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1920 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1921 fde->dw_fde_current_label);
1922 fputc ('\n', asm_out_file);
1923 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1924 break;
1925 case DW_CFA_advance_loc2:
1926 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1927 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1928 fde->dw_fde_current_label);
1929 fputc ('\n', asm_out_file);
1930 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1931 break;
1932 case DW_CFA_advance_loc4:
1933 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1934 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1935 fde->dw_fde_current_label);
1936 fputc ('\n', asm_out_file);
1937 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1938 break;
1939 #ifdef MIPS_DEBUGGING_INFO
1940 case DW_CFA_MIPS_advance_loc8:
1941 /* TODO: not currently implemented. */
1942 abort ();
1943 break;
1944 #endif
1945 case DW_CFA_offset_extended:
1946 case DW_CFA_GNU_negative_offset_extended:
1947 case DW_CFA_def_cfa:
1948 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1949 fputc ('\n', asm_out_file);
1950 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1951 fputc ('\n', asm_out_file);
1952 break;
1953 case DW_CFA_restore_extended:
1954 case DW_CFA_undefined:
1955 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1956 fputc ('\n', asm_out_file);
1957 break;
1958 case DW_CFA_same_value:
1959 case DW_CFA_def_cfa_register:
1960 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1961 fputc ('\n', asm_out_file);
1962 break;
1963 case DW_CFA_register:
1964 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1965 fputc ('\n', asm_out_file);
1966 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1967 fputc ('\n', asm_out_file);
1968 break;
1969 case DW_CFA_def_cfa_offset:
1970 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1971 fputc ('\n', asm_out_file);
1972 break;
1973 case DW_CFA_GNU_window_save:
1974 break;
1975 case DW_CFA_GNU_args_size:
1976 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1977 fputc ('\n', asm_out_file);
1978 break;
1979 case DW_CFA_def_cfa_expression:
1980 output_cfa_loc (cfi);
1981 break;
1982 default:
1983 break;
1988 /* Output the call frame information used to used to record information
1989 that relates to calculating the frame pointer, and records the
1990 location of saved registers. */
1992 static void
1993 output_call_frame_info (for_eh)
1994 int for_eh;
1996 register unsigned long i;
1997 register dw_fde_ref fde;
1998 register dw_cfi_ref cfi;
1999 char l1[20], l2[20];
2000 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2001 char ld[20];
2002 #endif
2004 /* Do we want to include a pointer to the exception table? */
2005 int eh_ptr = for_eh && exception_table_p ();
2007 /* If we don't have any functions we'll want to unwind out of, don't
2008 emit any EH unwind information. */
2009 if (for_eh)
2011 for (i = 0; i < fde_table_in_use; ++i)
2012 if (! fde_table[i].nothrow)
2013 goto found;
2014 return;
2015 found:;
2018 fputc ('\n', asm_out_file);
2020 /* We're going to be generating comments, so turn on app. */
2021 if (flag_debug_asm)
2022 app_enable ();
2024 if (for_eh)
2026 #ifdef EH_FRAME_SECTION
2027 EH_FRAME_SECTION ();
2028 #else
2029 tree label = get_file_function_name ('F');
2031 force_data_section ();
2032 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
2033 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2034 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
2035 #endif
2036 assemble_label ("__FRAME_BEGIN__");
2038 else
2039 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
2041 /* Output the CIE. */
2042 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2043 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2044 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2045 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
2046 if (for_eh)
2047 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
2048 else
2049 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
2050 #else
2051 if (for_eh)
2052 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
2053 else
2054 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
2055 #endif
2056 if (flag_debug_asm)
2057 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
2058 ASM_COMMENT_START);
2060 fputc ('\n', asm_out_file);
2061 ASM_OUTPUT_LABEL (asm_out_file, l1);
2063 if (for_eh)
2064 /* Now that the CIE pointer is PC-relative for EH,
2065 use 0 to identify the CIE. */
2066 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2067 else
2068 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
2070 if (flag_debug_asm)
2071 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
2073 fputc ('\n', asm_out_file);
2074 if (! for_eh && DWARF_OFFSET_SIZE == 8)
2076 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
2077 fputc ('\n', asm_out_file);
2080 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
2081 if (flag_debug_asm)
2082 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
2084 fputc ('\n', asm_out_file);
2085 if (eh_ptr)
2087 /* The CIE contains a pointer to the exception region info for the
2088 frame. Make the augmentation string three bytes (including the
2089 trailing null) so the pointer is 4-byte aligned. The Solaris ld
2090 can't handle unaligned relocs. */
2091 if (flag_debug_asm)
2093 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
2094 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
2096 else
2098 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
2100 fputc ('\n', asm_out_file);
2102 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
2103 if (flag_debug_asm)
2104 fprintf (asm_out_file, "\t%s pointer to exception region info",
2105 ASM_COMMENT_START);
2107 else
2109 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
2110 if (flag_debug_asm)
2111 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
2112 ASM_COMMENT_START);
2115 fputc ('\n', asm_out_file);
2116 output_uleb128 (1);
2117 if (flag_debug_asm)
2118 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
2120 fputc ('\n', asm_out_file);
2121 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
2122 if (flag_debug_asm)
2123 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
2125 fputc ('\n', asm_out_file);
2126 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
2127 if (flag_debug_asm)
2128 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
2130 fputc ('\n', asm_out_file);
2132 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2133 output_cfi (cfi, NULL);
2135 /* Pad the CIE out to an address sized boundary. */
2136 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
2137 ASM_OUTPUT_LABEL (asm_out_file, l2);
2138 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2139 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
2140 if (flag_debug_asm)
2141 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
2142 fputc ('\n', asm_out_file);
2143 #endif
2145 /* Loop through all of the FDE's. */
2146 for (i = 0; i < fde_table_in_use; ++i)
2148 fde = &fde_table[i];
2150 /* Don't emit EH unwind info for leaf functions. */
2151 if (for_eh && fde->nothrow)
2152 continue;
2154 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2155 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2156 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2157 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i * 2);
2158 if (for_eh)
2159 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
2160 else
2161 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
2162 #else
2163 if (for_eh)
2164 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
2165 else
2166 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
2167 #endif
2168 if (flag_debug_asm)
2169 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
2170 fputc ('\n', asm_out_file);
2171 ASM_OUTPUT_LABEL (asm_out_file, l1);
2173 /* ??? This always emits a 4 byte offset when for_eh is true, but it
2174 emits a target dependent sized offset when for_eh is not true.
2175 This inconsistency may confuse gdb. The only case where we need a
2176 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
2177 compatibility if we emit a 4 byte offset. We need a 4 byte offset
2178 though in order to be compatible with the dwarf_fde struct in frame.c.
2179 If the for_eh case is changed, then the struct in frame.c has
2180 to be adjusted appropriately. */
2181 if (for_eh)
2182 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
2183 else
2184 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
2185 if (flag_debug_asm)
2186 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
2188 fputc ('\n', asm_out_file);
2189 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
2190 if (flag_debug_asm)
2191 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
2193 fputc ('\n', asm_out_file);
2194 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
2195 fde->dw_fde_end, fde->dw_fde_begin);
2196 if (flag_debug_asm)
2197 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
2199 fputc ('\n', asm_out_file);
2201 /* Loop through the Call Frame Instructions associated with
2202 this FDE. */
2203 fde->dw_fde_current_label = fde->dw_fde_begin;
2204 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2205 output_cfi (cfi, fde);
2207 /* Pad the FDE out to an address sized boundary. */
2208 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
2209 ASM_OUTPUT_LABEL (asm_out_file, l2);
2210 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2211 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
2212 if (flag_debug_asm)
2213 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
2214 fputc ('\n', asm_out_file);
2215 #endif
2217 #ifndef EH_FRAME_SECTION
2218 if (for_eh)
2220 /* Emit terminating zero for table. */
2221 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2222 fputc ('\n', asm_out_file);
2224 #endif
2225 #ifdef MIPS_DEBUGGING_INFO
2226 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2227 get a value of 0. Putting .align 0 after the label fixes it. */
2228 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2229 #endif
2231 /* Turn off app to make assembly quicker. */
2232 if (flag_debug_asm)
2233 app_disable ();
2236 /* Output a marker (i.e. a label) for the beginning of a function, before
2237 the prologue. */
2239 void
2240 dwarf2out_begin_prologue ()
2242 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2243 register dw_fde_ref fde;
2245 ++current_funcdef_number;
2247 function_section (current_function_decl);
2248 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2249 current_funcdef_number);
2250 ASM_OUTPUT_LABEL (asm_out_file, label);
2251 current_function_func_begin_label = get_identifier (label);
2253 /* Expand the fde table if necessary. */
2254 if (fde_table_in_use == fde_table_allocated)
2256 fde_table_allocated += FDE_TABLE_INCREMENT;
2257 fde_table
2258 = (dw_fde_ref) xrealloc (fde_table,
2259 fde_table_allocated * sizeof (dw_fde_node));
2262 /* Record the FDE associated with this function. */
2263 current_funcdef_fde = fde_table_in_use;
2265 /* Add the new FDE at the end of the fde_table. */
2266 fde = &fde_table[fde_table_in_use++];
2267 fde->dw_fde_begin = xstrdup (label);
2268 fde->dw_fde_current_label = NULL;
2269 fde->dw_fde_end = NULL;
2270 fde->dw_fde_cfi = NULL;
2271 fde->nothrow = current_function_nothrow;
2273 args_size = old_args_size = 0;
2276 /* Output a marker (i.e. a label) for the absolute end of the generated code
2277 for a function definition. This gets called *after* the epilogue code has
2278 been generated. */
2280 void
2281 dwarf2out_end_epilogue ()
2283 dw_fde_ref fde;
2284 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2286 /* Output a label to mark the endpoint of the code generated for this
2287 function. */
2288 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2289 ASM_OUTPUT_LABEL (asm_out_file, label);
2290 fde = &fde_table[fde_table_in_use - 1];
2291 fde->dw_fde_end = xstrdup (label);
2294 void
2295 dwarf2out_frame_init ()
2297 /* Allocate the initial hunk of the fde_table. */
2298 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2299 fde_table_allocated = FDE_TABLE_INCREMENT;
2300 fde_table_in_use = 0;
2302 /* Generate the CFA instructions common to all FDE's. Do it now for the
2303 sake of lookup_cfa. */
2305 #ifdef DWARF2_UNWIND_INFO
2306 /* On entry, the Canonical Frame Address is at SP. */
2307 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2308 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2309 #endif
2312 void
2313 dwarf2out_frame_finish ()
2315 /* Output call frame information. */
2316 #ifdef MIPS_DEBUGGING_INFO
2317 if (write_symbols == DWARF2_DEBUG)
2318 output_call_frame_info (0);
2319 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2320 output_call_frame_info (1);
2321 #else
2322 if (write_symbols == DWARF2_DEBUG
2323 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2324 output_call_frame_info (1);
2325 #endif
2328 /* And now, the subset of the debugging information support code necessary
2329 for emitting location expressions. */
2331 typedef struct dw_val_struct *dw_val_ref;
2332 typedef struct die_struct *dw_die_ref;
2333 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2335 /* Each DIE may have a series of attribute/value pairs. Values
2336 can take on several forms. The forms that are used in this
2337 implementation are listed below. */
2339 typedef enum
2341 dw_val_class_addr,
2342 dw_val_class_loc,
2343 dw_val_class_const,
2344 dw_val_class_unsigned_const,
2345 dw_val_class_long_long,
2346 dw_val_class_float,
2347 dw_val_class_flag,
2348 dw_val_class_die_ref,
2349 dw_val_class_fde_ref,
2350 dw_val_class_lbl_id,
2351 dw_val_class_lbl_offset,
2352 dw_val_class_str
2354 dw_val_class;
2356 /* Describe a double word constant value. */
2357 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2359 typedef struct dw_long_long_struct
2361 unsigned long hi;
2362 unsigned long low;
2364 dw_long_long_const;
2366 /* Describe a floating point constant value. */
2368 typedef struct dw_fp_struct
2370 long *array;
2371 unsigned length;
2373 dw_float_const;
2375 /* The dw_val_node describes an attribute's value, as it is
2376 represented internally. */
2378 typedef struct dw_val_struct
2380 dw_val_class val_class;
2381 union
2383 rtx val_addr;
2384 dw_loc_descr_ref val_loc;
2385 long int val_int;
2386 long unsigned val_unsigned;
2387 dw_long_long_const val_long_long;
2388 dw_float_const val_float;
2389 struct {
2390 dw_die_ref die;
2391 int external;
2392 } val_die_ref;
2393 unsigned val_fde_index;
2394 char *val_str;
2395 char *val_lbl_id;
2396 unsigned char val_flag;
2400 dw_val_node;
2402 /* Locations in memory are described using a sequence of stack machine
2403 operations. */
2405 typedef struct dw_loc_descr_struct
2407 dw_loc_descr_ref dw_loc_next;
2408 enum dwarf_location_atom dw_loc_opc;
2409 dw_val_node dw_loc_oprnd1;
2410 dw_val_node dw_loc_oprnd2;
2411 int dw_loc_addr;
2413 dw_loc_descr_node;
2415 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2416 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2417 unsigned long,
2418 unsigned long));
2419 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2420 dw_loc_descr_ref));
2421 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2422 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2423 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2424 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2426 /* Convert a DWARF stack opcode into its string name. */
2428 static const char *
2429 dwarf_stack_op_name (op)
2430 register unsigned op;
2432 switch (op)
2434 case DW_OP_addr:
2435 return "DW_OP_addr";
2436 case DW_OP_deref:
2437 return "DW_OP_deref";
2438 case DW_OP_const1u:
2439 return "DW_OP_const1u";
2440 case DW_OP_const1s:
2441 return "DW_OP_const1s";
2442 case DW_OP_const2u:
2443 return "DW_OP_const2u";
2444 case DW_OP_const2s:
2445 return "DW_OP_const2s";
2446 case DW_OP_const4u:
2447 return "DW_OP_const4u";
2448 case DW_OP_const4s:
2449 return "DW_OP_const4s";
2450 case DW_OP_const8u:
2451 return "DW_OP_const8u";
2452 case DW_OP_const8s:
2453 return "DW_OP_const8s";
2454 case DW_OP_constu:
2455 return "DW_OP_constu";
2456 case DW_OP_consts:
2457 return "DW_OP_consts";
2458 case DW_OP_dup:
2459 return "DW_OP_dup";
2460 case DW_OP_drop:
2461 return "DW_OP_drop";
2462 case DW_OP_over:
2463 return "DW_OP_over";
2464 case DW_OP_pick:
2465 return "DW_OP_pick";
2466 case DW_OP_swap:
2467 return "DW_OP_swap";
2468 case DW_OP_rot:
2469 return "DW_OP_rot";
2470 case DW_OP_xderef:
2471 return "DW_OP_xderef";
2472 case DW_OP_abs:
2473 return "DW_OP_abs";
2474 case DW_OP_and:
2475 return "DW_OP_and";
2476 case DW_OP_div:
2477 return "DW_OP_div";
2478 case DW_OP_minus:
2479 return "DW_OP_minus";
2480 case DW_OP_mod:
2481 return "DW_OP_mod";
2482 case DW_OP_mul:
2483 return "DW_OP_mul";
2484 case DW_OP_neg:
2485 return "DW_OP_neg";
2486 case DW_OP_not:
2487 return "DW_OP_not";
2488 case DW_OP_or:
2489 return "DW_OP_or";
2490 case DW_OP_plus:
2491 return "DW_OP_plus";
2492 case DW_OP_plus_uconst:
2493 return "DW_OP_plus_uconst";
2494 case DW_OP_shl:
2495 return "DW_OP_shl";
2496 case DW_OP_shr:
2497 return "DW_OP_shr";
2498 case DW_OP_shra:
2499 return "DW_OP_shra";
2500 case DW_OP_xor:
2501 return "DW_OP_xor";
2502 case DW_OP_bra:
2503 return "DW_OP_bra";
2504 case DW_OP_eq:
2505 return "DW_OP_eq";
2506 case DW_OP_ge:
2507 return "DW_OP_ge";
2508 case DW_OP_gt:
2509 return "DW_OP_gt";
2510 case DW_OP_le:
2511 return "DW_OP_le";
2512 case DW_OP_lt:
2513 return "DW_OP_lt";
2514 case DW_OP_ne:
2515 return "DW_OP_ne";
2516 case DW_OP_skip:
2517 return "DW_OP_skip";
2518 case DW_OP_lit0:
2519 return "DW_OP_lit0";
2520 case DW_OP_lit1:
2521 return "DW_OP_lit1";
2522 case DW_OP_lit2:
2523 return "DW_OP_lit2";
2524 case DW_OP_lit3:
2525 return "DW_OP_lit3";
2526 case DW_OP_lit4:
2527 return "DW_OP_lit4";
2528 case DW_OP_lit5:
2529 return "DW_OP_lit5";
2530 case DW_OP_lit6:
2531 return "DW_OP_lit6";
2532 case DW_OP_lit7:
2533 return "DW_OP_lit7";
2534 case DW_OP_lit8:
2535 return "DW_OP_lit8";
2536 case DW_OP_lit9:
2537 return "DW_OP_lit9";
2538 case DW_OP_lit10:
2539 return "DW_OP_lit10";
2540 case DW_OP_lit11:
2541 return "DW_OP_lit11";
2542 case DW_OP_lit12:
2543 return "DW_OP_lit12";
2544 case DW_OP_lit13:
2545 return "DW_OP_lit13";
2546 case DW_OP_lit14:
2547 return "DW_OP_lit14";
2548 case DW_OP_lit15:
2549 return "DW_OP_lit15";
2550 case DW_OP_lit16:
2551 return "DW_OP_lit16";
2552 case DW_OP_lit17:
2553 return "DW_OP_lit17";
2554 case DW_OP_lit18:
2555 return "DW_OP_lit18";
2556 case DW_OP_lit19:
2557 return "DW_OP_lit19";
2558 case DW_OP_lit20:
2559 return "DW_OP_lit20";
2560 case DW_OP_lit21:
2561 return "DW_OP_lit21";
2562 case DW_OP_lit22:
2563 return "DW_OP_lit22";
2564 case DW_OP_lit23:
2565 return "DW_OP_lit23";
2566 case DW_OP_lit24:
2567 return "DW_OP_lit24";
2568 case DW_OP_lit25:
2569 return "DW_OP_lit25";
2570 case DW_OP_lit26:
2571 return "DW_OP_lit26";
2572 case DW_OP_lit27:
2573 return "DW_OP_lit27";
2574 case DW_OP_lit28:
2575 return "DW_OP_lit28";
2576 case DW_OP_lit29:
2577 return "DW_OP_lit29";
2578 case DW_OP_lit30:
2579 return "DW_OP_lit30";
2580 case DW_OP_lit31:
2581 return "DW_OP_lit31";
2582 case DW_OP_reg0:
2583 return "DW_OP_reg0";
2584 case DW_OP_reg1:
2585 return "DW_OP_reg1";
2586 case DW_OP_reg2:
2587 return "DW_OP_reg2";
2588 case DW_OP_reg3:
2589 return "DW_OP_reg3";
2590 case DW_OP_reg4:
2591 return "DW_OP_reg4";
2592 case DW_OP_reg5:
2593 return "DW_OP_reg5";
2594 case DW_OP_reg6:
2595 return "DW_OP_reg6";
2596 case DW_OP_reg7:
2597 return "DW_OP_reg7";
2598 case DW_OP_reg8:
2599 return "DW_OP_reg8";
2600 case DW_OP_reg9:
2601 return "DW_OP_reg9";
2602 case DW_OP_reg10:
2603 return "DW_OP_reg10";
2604 case DW_OP_reg11:
2605 return "DW_OP_reg11";
2606 case DW_OP_reg12:
2607 return "DW_OP_reg12";
2608 case DW_OP_reg13:
2609 return "DW_OP_reg13";
2610 case DW_OP_reg14:
2611 return "DW_OP_reg14";
2612 case DW_OP_reg15:
2613 return "DW_OP_reg15";
2614 case DW_OP_reg16:
2615 return "DW_OP_reg16";
2616 case DW_OP_reg17:
2617 return "DW_OP_reg17";
2618 case DW_OP_reg18:
2619 return "DW_OP_reg18";
2620 case DW_OP_reg19:
2621 return "DW_OP_reg19";
2622 case DW_OP_reg20:
2623 return "DW_OP_reg20";
2624 case DW_OP_reg21:
2625 return "DW_OP_reg21";
2626 case DW_OP_reg22:
2627 return "DW_OP_reg22";
2628 case DW_OP_reg23:
2629 return "DW_OP_reg23";
2630 case DW_OP_reg24:
2631 return "DW_OP_reg24";
2632 case DW_OP_reg25:
2633 return "DW_OP_reg25";
2634 case DW_OP_reg26:
2635 return "DW_OP_reg26";
2636 case DW_OP_reg27:
2637 return "DW_OP_reg27";
2638 case DW_OP_reg28:
2639 return "DW_OP_reg28";
2640 case DW_OP_reg29:
2641 return "DW_OP_reg29";
2642 case DW_OP_reg30:
2643 return "DW_OP_reg30";
2644 case DW_OP_reg31:
2645 return "DW_OP_reg31";
2646 case DW_OP_breg0:
2647 return "DW_OP_breg0";
2648 case DW_OP_breg1:
2649 return "DW_OP_breg1";
2650 case DW_OP_breg2:
2651 return "DW_OP_breg2";
2652 case DW_OP_breg3:
2653 return "DW_OP_breg3";
2654 case DW_OP_breg4:
2655 return "DW_OP_breg4";
2656 case DW_OP_breg5:
2657 return "DW_OP_breg5";
2658 case DW_OP_breg6:
2659 return "DW_OP_breg6";
2660 case DW_OP_breg7:
2661 return "DW_OP_breg7";
2662 case DW_OP_breg8:
2663 return "DW_OP_breg8";
2664 case DW_OP_breg9:
2665 return "DW_OP_breg9";
2666 case DW_OP_breg10:
2667 return "DW_OP_breg10";
2668 case DW_OP_breg11:
2669 return "DW_OP_breg11";
2670 case DW_OP_breg12:
2671 return "DW_OP_breg12";
2672 case DW_OP_breg13:
2673 return "DW_OP_breg13";
2674 case DW_OP_breg14:
2675 return "DW_OP_breg14";
2676 case DW_OP_breg15:
2677 return "DW_OP_breg15";
2678 case DW_OP_breg16:
2679 return "DW_OP_breg16";
2680 case DW_OP_breg17:
2681 return "DW_OP_breg17";
2682 case DW_OP_breg18:
2683 return "DW_OP_breg18";
2684 case DW_OP_breg19:
2685 return "DW_OP_breg19";
2686 case DW_OP_breg20:
2687 return "DW_OP_breg20";
2688 case DW_OP_breg21:
2689 return "DW_OP_breg21";
2690 case DW_OP_breg22:
2691 return "DW_OP_breg22";
2692 case DW_OP_breg23:
2693 return "DW_OP_breg23";
2694 case DW_OP_breg24:
2695 return "DW_OP_breg24";
2696 case DW_OP_breg25:
2697 return "DW_OP_breg25";
2698 case DW_OP_breg26:
2699 return "DW_OP_breg26";
2700 case DW_OP_breg27:
2701 return "DW_OP_breg27";
2702 case DW_OP_breg28:
2703 return "DW_OP_breg28";
2704 case DW_OP_breg29:
2705 return "DW_OP_breg29";
2706 case DW_OP_breg30:
2707 return "DW_OP_breg30";
2708 case DW_OP_breg31:
2709 return "DW_OP_breg31";
2710 case DW_OP_regx:
2711 return "DW_OP_regx";
2712 case DW_OP_fbreg:
2713 return "DW_OP_fbreg";
2714 case DW_OP_bregx:
2715 return "DW_OP_bregx";
2716 case DW_OP_piece:
2717 return "DW_OP_piece";
2718 case DW_OP_deref_size:
2719 return "DW_OP_deref_size";
2720 case DW_OP_xderef_size:
2721 return "DW_OP_xderef_size";
2722 case DW_OP_nop:
2723 return "DW_OP_nop";
2724 default:
2725 return "OP_<unknown>";
2729 /* Return a pointer to a newly allocated location description. Location
2730 descriptions are simple expression terms that can be strung
2731 together to form more complicated location (address) descriptions. */
2733 static inline dw_loc_descr_ref
2734 new_loc_descr (op, oprnd1, oprnd2)
2735 register enum dwarf_location_atom op;
2736 register unsigned long oprnd1;
2737 register unsigned long oprnd2;
2739 /* Use xcalloc here so we clear out all of the long_long constant in
2740 the union. */
2741 register dw_loc_descr_ref descr
2742 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2744 descr->dw_loc_opc = op;
2745 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2746 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2747 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2748 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2750 return descr;
2753 /* Add a location description term to a location description expression. */
2755 static inline void
2756 add_loc_descr (list_head, descr)
2757 register dw_loc_descr_ref *list_head;
2758 register dw_loc_descr_ref descr;
2760 register dw_loc_descr_ref *d;
2762 /* Find the end of the chain. */
2763 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2766 *d = descr;
2769 /* Return the size of a location descriptor. */
2771 static unsigned long
2772 size_of_loc_descr (loc)
2773 register dw_loc_descr_ref loc;
2775 register unsigned long size = 1;
2777 switch (loc->dw_loc_opc)
2779 case DW_OP_addr:
2780 size += DWARF2_ADDR_SIZE;
2781 break;
2782 case DW_OP_const1u:
2783 case DW_OP_const1s:
2784 size += 1;
2785 break;
2786 case DW_OP_const2u:
2787 case DW_OP_const2s:
2788 size += 2;
2789 break;
2790 case DW_OP_const4u:
2791 case DW_OP_const4s:
2792 size += 4;
2793 break;
2794 case DW_OP_const8u:
2795 case DW_OP_const8s:
2796 size += 8;
2797 break;
2798 case DW_OP_constu:
2799 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2800 break;
2801 case DW_OP_consts:
2802 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2803 break;
2804 case DW_OP_pick:
2805 size += 1;
2806 break;
2807 case DW_OP_plus_uconst:
2808 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2809 break;
2810 case DW_OP_skip:
2811 case DW_OP_bra:
2812 size += 2;
2813 break;
2814 case DW_OP_breg0:
2815 case DW_OP_breg1:
2816 case DW_OP_breg2:
2817 case DW_OP_breg3:
2818 case DW_OP_breg4:
2819 case DW_OP_breg5:
2820 case DW_OP_breg6:
2821 case DW_OP_breg7:
2822 case DW_OP_breg8:
2823 case DW_OP_breg9:
2824 case DW_OP_breg10:
2825 case DW_OP_breg11:
2826 case DW_OP_breg12:
2827 case DW_OP_breg13:
2828 case DW_OP_breg14:
2829 case DW_OP_breg15:
2830 case DW_OP_breg16:
2831 case DW_OP_breg17:
2832 case DW_OP_breg18:
2833 case DW_OP_breg19:
2834 case DW_OP_breg20:
2835 case DW_OP_breg21:
2836 case DW_OP_breg22:
2837 case DW_OP_breg23:
2838 case DW_OP_breg24:
2839 case DW_OP_breg25:
2840 case DW_OP_breg26:
2841 case DW_OP_breg27:
2842 case DW_OP_breg28:
2843 case DW_OP_breg29:
2844 case DW_OP_breg30:
2845 case DW_OP_breg31:
2846 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2847 break;
2848 case DW_OP_regx:
2849 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2850 break;
2851 case DW_OP_fbreg:
2852 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2853 break;
2854 case DW_OP_bregx:
2855 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2856 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2857 break;
2858 case DW_OP_piece:
2859 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2860 break;
2861 case DW_OP_deref_size:
2862 case DW_OP_xderef_size:
2863 size += 1;
2864 break;
2865 default:
2866 break;
2869 return size;
2872 /* Return the size of a series of location descriptors. */
2874 static unsigned long
2875 size_of_locs (loc)
2876 register dw_loc_descr_ref loc;
2878 register unsigned long size = 0;
2880 for (; loc != NULL; loc = loc->dw_loc_next)
2882 loc->dw_loc_addr = size;
2883 size += size_of_loc_descr (loc);
2886 return size;
2889 /* Output location description stack opcode's operands (if any). */
2891 static void
2892 output_loc_operands (loc)
2893 register dw_loc_descr_ref loc;
2895 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2896 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2898 switch (loc->dw_loc_opc)
2900 #ifdef DWARF2_DEBUGGING_INFO
2901 case DW_OP_addr:
2902 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
2903 fputc ('\n', asm_out_file);
2904 break;
2905 case DW_OP_const2u:
2906 case DW_OP_const2s:
2907 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
2908 fputc ('\n', asm_out_file);
2909 break;
2910 case DW_OP_const4u:
2911 case DW_OP_const4s:
2912 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
2913 fputc ('\n', asm_out_file);
2914 break;
2915 case DW_OP_const8u:
2916 case DW_OP_const8s:
2917 abort ();
2918 fputc ('\n', asm_out_file);
2919 break;
2920 case DW_OP_skip:
2921 case DW_OP_bra:
2923 int offset;
2925 if (val1->val_class == dw_val_class_loc)
2926 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2927 else
2928 abort ();
2930 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, offset);
2931 fputc ('\n', asm_out_file);
2933 break;
2934 #else
2935 case DW_OP_addr:
2936 case DW_OP_const2u:
2937 case DW_OP_const2s:
2938 case DW_OP_const4u:
2939 case DW_OP_const4s:
2940 case DW_OP_const8u:
2941 case DW_OP_const8s:
2942 case DW_OP_skip:
2943 case DW_OP_bra:
2944 /* We currently don't make any attempt to make sure these are
2945 aligned properly like we do for the main unwind info, so
2946 don't support emitting things larger than a byte if we're
2947 only doing unwinding. */
2948 abort ();
2949 #endif
2950 case DW_OP_const1u:
2951 case DW_OP_const1s:
2952 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2953 fputc ('\n', asm_out_file);
2954 break;
2955 case DW_OP_constu:
2956 output_uleb128 (val1->v.val_unsigned);
2957 fputc ('\n', asm_out_file);
2958 break;
2959 case DW_OP_consts:
2960 output_sleb128 (val1->v.val_int);
2961 fputc ('\n', asm_out_file);
2962 break;
2963 case DW_OP_pick:
2964 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
2965 fputc ('\n', asm_out_file);
2966 break;
2967 case DW_OP_plus_uconst:
2968 output_uleb128 (val1->v.val_unsigned);
2969 fputc ('\n', asm_out_file);
2970 break;
2971 case DW_OP_breg0:
2972 case DW_OP_breg1:
2973 case DW_OP_breg2:
2974 case DW_OP_breg3:
2975 case DW_OP_breg4:
2976 case DW_OP_breg5:
2977 case DW_OP_breg6:
2978 case DW_OP_breg7:
2979 case DW_OP_breg8:
2980 case DW_OP_breg9:
2981 case DW_OP_breg10:
2982 case DW_OP_breg11:
2983 case DW_OP_breg12:
2984 case DW_OP_breg13:
2985 case DW_OP_breg14:
2986 case DW_OP_breg15:
2987 case DW_OP_breg16:
2988 case DW_OP_breg17:
2989 case DW_OP_breg18:
2990 case DW_OP_breg19:
2991 case DW_OP_breg20:
2992 case DW_OP_breg21:
2993 case DW_OP_breg22:
2994 case DW_OP_breg23:
2995 case DW_OP_breg24:
2996 case DW_OP_breg25:
2997 case DW_OP_breg26:
2998 case DW_OP_breg27:
2999 case DW_OP_breg28:
3000 case DW_OP_breg29:
3001 case DW_OP_breg30:
3002 case DW_OP_breg31:
3003 output_sleb128 (val1->v.val_int);
3004 fputc ('\n', asm_out_file);
3005 break;
3006 case DW_OP_regx:
3007 output_uleb128 (val1->v.val_unsigned);
3008 fputc ('\n', asm_out_file);
3009 break;
3010 case DW_OP_fbreg:
3011 output_sleb128 (val1->v.val_int);
3012 fputc ('\n', asm_out_file);
3013 break;
3014 case DW_OP_bregx:
3015 output_uleb128 (val1->v.val_unsigned);
3016 fputc ('\n', asm_out_file);
3017 output_sleb128 (val2->v.val_int);
3018 fputc ('\n', asm_out_file);
3019 break;
3020 case DW_OP_piece:
3021 output_uleb128 (val1->v.val_unsigned);
3022 fputc ('\n', asm_out_file);
3023 break;
3024 case DW_OP_deref_size:
3025 case DW_OP_xderef_size:
3026 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
3027 fputc ('\n', asm_out_file);
3028 break;
3029 default:
3030 /* Other codes have no operands. */
3031 break;
3035 /* Output a sequence of location operations. */
3037 static void
3038 output_loc_sequence (loc)
3039 dw_loc_descr_ref loc;
3041 for (; loc != NULL; loc = loc->dw_loc_next)
3043 /* Output the opcode. */
3044 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
3045 if (flag_debug_asm)
3046 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
3047 dwarf_stack_op_name (loc->dw_loc_opc));
3049 fputc ('\n', asm_out_file);
3051 /* Output the operand(s) (if any). */
3052 output_loc_operands (loc);
3056 /* This routine will generate the correct assembly data for a location
3057 description based on a cfi entry with a complex address. */
3059 static void
3060 output_cfa_loc (cfi)
3061 dw_cfi_ref cfi;
3063 dw_loc_descr_ref loc;
3064 unsigned long size;
3066 /* Output the size of the block. */
3067 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3068 size = size_of_locs (loc);
3069 output_uleb128 (size);
3070 fputc ('\n', asm_out_file);
3072 /* Now output the operations themselves. */
3073 output_loc_sequence (loc);
3076 /* This function builds a dwarf location descriptor seqeunce from
3077 a dw_cfa_location. */
3079 static struct dw_loc_descr_struct *
3080 build_cfa_loc (cfa)
3081 dw_cfa_location *cfa;
3083 struct dw_loc_descr_struct *head, *tmp;
3085 if (cfa->indirect == 0)
3086 abort ();
3088 if (cfa->base_offset)
3090 if (cfa->reg <= 31)
3091 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3092 else
3093 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3095 else if (cfa->reg <= 31)
3096 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3097 else
3098 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3099 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3100 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3101 add_loc_descr (&head, tmp);
3102 if (cfa->offset != 0)
3104 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
3105 add_loc_descr (&head, tmp);
3107 return head;
3110 /* This function fills in aa dw_cfa_location structure from a
3111 dwarf location descriptor sequence. */
3113 static void
3114 get_cfa_from_loc_descr (cfa, loc)
3115 dw_cfa_location *cfa;
3116 struct dw_loc_descr_struct *loc;
3118 struct dw_loc_descr_struct *ptr;
3119 cfa->offset = 0;
3120 cfa->base_offset = 0;
3121 cfa->indirect = 0;
3122 cfa->reg = -1;
3124 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3126 enum dwarf_location_atom op = ptr->dw_loc_opc;
3127 switch (op)
3129 case DW_OP_reg0:
3130 case DW_OP_reg1:
3131 case DW_OP_reg2:
3132 case DW_OP_reg3:
3133 case DW_OP_reg4:
3134 case DW_OP_reg5:
3135 case DW_OP_reg6:
3136 case DW_OP_reg7:
3137 case DW_OP_reg8:
3138 case DW_OP_reg9:
3139 case DW_OP_reg10:
3140 case DW_OP_reg11:
3141 case DW_OP_reg12:
3142 case DW_OP_reg13:
3143 case DW_OP_reg14:
3144 case DW_OP_reg15:
3145 case DW_OP_reg16:
3146 case DW_OP_reg17:
3147 case DW_OP_reg18:
3148 case DW_OP_reg19:
3149 case DW_OP_reg20:
3150 case DW_OP_reg21:
3151 case DW_OP_reg22:
3152 case DW_OP_reg23:
3153 case DW_OP_reg24:
3154 case DW_OP_reg25:
3155 case DW_OP_reg26:
3156 case DW_OP_reg27:
3157 case DW_OP_reg28:
3158 case DW_OP_reg29:
3159 case DW_OP_reg30:
3160 case DW_OP_reg31:
3161 cfa->reg = op - DW_OP_reg0;
3162 break;
3163 case DW_OP_regx:
3164 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3165 break;
3166 case DW_OP_breg0:
3167 case DW_OP_breg1:
3168 case DW_OP_breg2:
3169 case DW_OP_breg3:
3170 case DW_OP_breg4:
3171 case DW_OP_breg5:
3172 case DW_OP_breg6:
3173 case DW_OP_breg7:
3174 case DW_OP_breg8:
3175 case DW_OP_breg9:
3176 case DW_OP_breg10:
3177 case DW_OP_breg11:
3178 case DW_OP_breg12:
3179 case DW_OP_breg13:
3180 case DW_OP_breg14:
3181 case DW_OP_breg15:
3182 case DW_OP_breg16:
3183 case DW_OP_breg17:
3184 case DW_OP_breg18:
3185 case DW_OP_breg19:
3186 case DW_OP_breg20:
3187 case DW_OP_breg21:
3188 case DW_OP_breg22:
3189 case DW_OP_breg23:
3190 case DW_OP_breg24:
3191 case DW_OP_breg25:
3192 case DW_OP_breg26:
3193 case DW_OP_breg27:
3194 case DW_OP_breg28:
3195 case DW_OP_breg29:
3196 case DW_OP_breg30:
3197 case DW_OP_breg31:
3198 cfa->reg = op - DW_OP_breg0;
3199 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3200 break;
3201 case DW_OP_bregx:
3202 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3203 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3204 break;
3205 case DW_OP_deref:
3206 cfa->indirect = 1;
3207 break;
3208 case DW_OP_plus_uconst:
3209 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3210 break;
3211 default:
3212 internal_error ("DW_LOC_OP %s not implememnted\n",
3213 dwarf_stack_op_name (ptr->dw_loc_opc));
3217 #endif /* .debug_frame support */
3219 /* And now, the support for symbolic debugging information. */
3220 #ifdef DWARF2_DEBUGGING_INFO
3222 /* NOTE: In the comments in this file, many references are made to
3223 "Debugging Information Entries". This term is abbreviated as `DIE'
3224 throughout the remainder of this file. */
3226 /* An internal representation of the DWARF output is built, and then
3227 walked to generate the DWARF debugging info. The walk of the internal
3228 representation is done after the entire program has been compiled.
3229 The types below are used to describe the internal representation. */
3231 /* Various DIE's use offsets relative to the beginning of the
3232 .debug_info section to refer to each other. */
3234 typedef long int dw_offset;
3236 /* Define typedefs here to avoid circular dependencies. */
3238 typedef struct dw_attr_struct *dw_attr_ref;
3239 typedef struct dw_line_info_struct *dw_line_info_ref;
3240 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3241 typedef struct pubname_struct *pubname_ref;
3242 typedef dw_die_ref *arange_ref;
3244 /* Each entry in the line_info_table maintains the file and
3245 line number associated with the label generated for that
3246 entry. The label gives the PC value associated with
3247 the line number entry. */
3249 typedef struct dw_line_info_struct
3251 unsigned long dw_file_num;
3252 unsigned long dw_line_num;
3254 dw_line_info_entry;
3256 /* Line information for functions in separate sections; each one gets its
3257 own sequence. */
3258 typedef struct dw_separate_line_info_struct
3260 unsigned long dw_file_num;
3261 unsigned long dw_line_num;
3262 unsigned long function;
3264 dw_separate_line_info_entry;
3266 /* Each DIE attribute has a field specifying the attribute kind,
3267 a link to the next attribute in the chain, and an attribute value.
3268 Attributes are typically linked below the DIE they modify. */
3270 typedef struct dw_attr_struct
3272 enum dwarf_attribute dw_attr;
3273 dw_attr_ref dw_attr_next;
3274 dw_val_node dw_attr_val;
3276 dw_attr_node;
3278 /* The Debugging Information Entry (DIE) structure */
3280 typedef struct die_struct
3282 enum dwarf_tag die_tag;
3283 char *die_symbol;
3284 dw_attr_ref die_attr;
3285 dw_die_ref die_parent;
3286 dw_die_ref die_child;
3287 dw_die_ref die_sib;
3288 dw_offset die_offset;
3289 unsigned long die_abbrev;
3290 int die_mark;
3292 die_node;
3294 /* The pubname structure */
3296 typedef struct pubname_struct
3298 dw_die_ref die;
3299 char *name;
3301 pubname_entry;
3303 /* The limbo die list structure. */
3304 typedef struct limbo_die_struct
3306 dw_die_ref die;
3307 struct limbo_die_struct *next;
3309 limbo_die_node;
3311 /* How to start an assembler comment. */
3312 #ifndef ASM_COMMENT_START
3313 #define ASM_COMMENT_START ";#"
3314 #endif
3316 /* Define a macro which returns non-zero for a TYPE_DECL which was
3317 implicitly generated for a tagged type.
3319 Note that unlike the gcc front end (which generates a NULL named
3320 TYPE_DECL node for each complete tagged type, each array type, and
3321 each function type node created) the g++ front end generates a
3322 _named_ TYPE_DECL node for each tagged type node created.
3323 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3324 generate a DW_TAG_typedef DIE for them. */
3326 #define TYPE_DECL_IS_STUB(decl) \
3327 (DECL_NAME (decl) == NULL_TREE \
3328 || (DECL_ARTIFICIAL (decl) \
3329 && is_tagged_type (TREE_TYPE (decl)) \
3330 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3331 /* This is necessary for stub decls that \
3332 appear in nested inline functions. */ \
3333 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3334 && (decl_ultimate_origin (decl) \
3335 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3337 /* Information concerning the compilation unit's programming
3338 language, and compiler version. */
3340 extern int flag_traditional;
3342 /* Fixed size portion of the DWARF compilation unit header. */
3343 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3345 /* Fixed size portion of debugging line information prolog. */
3346 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3348 /* Fixed size portion of public names info. */
3349 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3351 /* Fixed size portion of the address range info. */
3352 #define DWARF_ARANGES_HEADER_SIZE \
3353 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3354 - DWARF_OFFSET_SIZE)
3356 /* Size of padding portion in the address range info. It must be
3357 aligned to twice the pointer size. */
3358 #define DWARF_ARANGES_PAD_SIZE \
3359 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3360 - (2 * DWARF_OFFSET_SIZE + 4))
3362 /* Use assembler line directives if available. */
3363 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3364 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3365 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3366 #else
3367 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3368 #endif
3369 #endif
3371 /* Define the architecture-dependent minimum instruction length (in bytes).
3372 In this implementation of DWARF, this field is used for information
3373 purposes only. Since GCC generates assembly language, we have
3374 no a priori knowledge of how many instruction bytes are generated
3375 for each source line, and therefore can use only the DW_LNE_set_address
3376 and DW_LNS_fixed_advance_pc line information commands. */
3378 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3379 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3380 #endif
3382 /* Minimum line offset in a special line info. opcode.
3383 This value was chosen to give a reasonable range of values. */
3384 #define DWARF_LINE_BASE -10
3386 /* First special line opcde - leave room for the standard opcodes. */
3387 #define DWARF_LINE_OPCODE_BASE 10
3389 /* Range of line offsets in a special line info. opcode. */
3390 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3392 /* Flag that indicates the initial value of the is_stmt_start flag.
3393 In the present implementation, we do not mark any lines as
3394 the beginning of a source statement, because that information
3395 is not made available by the GCC front-end. */
3396 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3398 /* This location is used by calc_die_sizes() to keep track
3399 the offset of each DIE within the .debug_info section. */
3400 static unsigned long next_die_offset;
3402 /* Record the root of the DIE's built for the current compilation unit. */
3403 static dw_die_ref comp_unit_die;
3405 /* A list of DIEs with a NULL parent waiting to be relocated. */
3406 static limbo_die_node *limbo_die_list = 0;
3408 /* Structure used by lookup_filename to manage sets of filenames. */
3409 struct file_table
3411 char **table;
3412 unsigned allocated;
3413 unsigned in_use;
3414 unsigned last_lookup_index;
3417 /* Size (in elements) of increments by which we may expand the filename
3418 table. */
3419 #define FILE_TABLE_INCREMENT 64
3421 /* Filenames referenced by declarations this compilation unit. */
3422 static struct file_table decl_file_table;
3424 /* Filenames referenced by line numbers in this compilation unit. */
3425 static struct file_table line_file_table;
3427 /* Local pointer to the name of the main input file. Initialized in
3428 dwarf2out_init. */
3429 static const char *primary_filename;
3431 /* A pointer to the base of a table of references to DIE's that describe
3432 declarations. The table is indexed by DECL_UID() which is a unique
3433 number identifying each decl. */
3434 static dw_die_ref *decl_die_table;
3436 /* Number of elements currently allocated for the decl_die_table. */
3437 static unsigned decl_die_table_allocated;
3439 /* Number of elements in decl_die_table currently in use. */
3440 static unsigned decl_die_table_in_use;
3442 /* Size (in elements) of increments by which we may expand the
3443 decl_die_table. */
3444 #define DECL_DIE_TABLE_INCREMENT 256
3446 /* A pointer to the base of a table of references to declaration
3447 scopes. This table is a display which tracks the nesting
3448 of declaration scopes at the current scope and containing
3449 scopes. This table is used to find the proper place to
3450 define type declaration DIE's. */
3451 static tree *decl_scope_table;
3453 /* Number of elements currently allocated for the decl_scope_table. */
3454 static int decl_scope_table_allocated;
3456 /* Current level of nesting of declaration scopes. */
3457 static int decl_scope_depth;
3459 /* Size (in elements) of increments by which we may expand the
3460 decl_scope_table. */
3461 #define DECL_SCOPE_TABLE_INCREMENT 64
3463 /* A pointer to the base of a list of references to DIE's that
3464 are uniquely identified by their tag, presence/absence of
3465 children DIE's, and list of attribute/value pairs. */
3466 static dw_die_ref *abbrev_die_table;
3468 /* Number of elements currently allocated for abbrev_die_table. */
3469 static unsigned abbrev_die_table_allocated;
3471 /* Number of elements in type_die_table currently in use. */
3472 static unsigned abbrev_die_table_in_use;
3474 /* Size (in elements) of increments by which we may expand the
3475 abbrev_die_table. */
3476 #define ABBREV_DIE_TABLE_INCREMENT 256
3478 /* A pointer to the base of a table that contains line information
3479 for each source code line in .text in the compilation unit. */
3480 static dw_line_info_ref line_info_table;
3482 /* Number of elements currently allocated for line_info_table. */
3483 static unsigned line_info_table_allocated;
3485 /* Number of elements in separate_line_info_table currently in use. */
3486 static unsigned separate_line_info_table_in_use;
3488 /* A pointer to the base of a table that contains line information
3489 for each source code line outside of .text in the compilation unit. */
3490 static dw_separate_line_info_ref separate_line_info_table;
3492 /* Number of elements currently allocated for separate_line_info_table. */
3493 static unsigned separate_line_info_table_allocated;
3495 /* Number of elements in line_info_table currently in use. */
3496 static unsigned line_info_table_in_use;
3498 /* Size (in elements) of increments by which we may expand the
3499 line_info_table. */
3500 #define LINE_INFO_TABLE_INCREMENT 1024
3502 /* A pointer to the base of a table that contains a list of publicly
3503 accessible names. */
3504 static pubname_ref pubname_table;
3506 /* Number of elements currently allocated for pubname_table. */
3507 static unsigned pubname_table_allocated;
3509 /* Number of elements in pubname_table currently in use. */
3510 static unsigned pubname_table_in_use;
3512 /* Size (in elements) of increments by which we may expand the
3513 pubname_table. */
3514 #define PUBNAME_TABLE_INCREMENT 64
3516 /* A pointer to the base of a table that contains a list of publicly
3517 accessible names. */
3518 static arange_ref arange_table;
3520 /* Number of elements currently allocated for arange_table. */
3521 static unsigned arange_table_allocated;
3523 /* Number of elements in arange_table currently in use. */
3524 static unsigned arange_table_in_use;
3526 /* Size (in elements) of increments by which we may expand the
3527 arange_table. */
3528 #define ARANGE_TABLE_INCREMENT 64
3530 /* A pointer to the base of a list of incomplete types which might be
3531 completed at some later time. */
3533 static tree *incomplete_types_list;
3535 /* Number of elements currently allocated for the incomplete_types_list. */
3536 static unsigned incomplete_types_allocated;
3538 /* Number of elements of incomplete_types_list currently in use. */
3539 static unsigned incomplete_types;
3541 /* Size (in elements) of increments by which we may expand the incomplete
3542 types list. Actually, a single hunk of space of this size should
3543 be enough for most typical programs. */
3544 #define INCOMPLETE_TYPES_INCREMENT 64
3546 /* Record whether the function being analyzed contains inlined functions. */
3547 static int current_function_has_inlines;
3548 #if 0 && defined (MIPS_DEBUGGING_INFO)
3549 static int comp_unit_has_inlines;
3550 #endif
3552 /* Array of RTXes referenced by the debugging information, which therefore
3553 must be kept around forever. We do this rather than perform GC on
3554 the dwarf info because almost all of the dwarf info lives forever, and
3555 it's easier to support non-GC frontends this way. */
3556 static varray_type used_rtx_varray;
3558 /* Forward declarations for functions defined in this file. */
3560 static int is_pseudo_reg PARAMS ((rtx));
3561 static tree type_main_variant PARAMS ((tree));
3562 static int is_tagged_type PARAMS ((tree));
3563 static const char *dwarf_tag_name PARAMS ((unsigned));
3564 static const char *dwarf_attr_name PARAMS ((unsigned));
3565 static const char *dwarf_form_name PARAMS ((unsigned));
3566 #if 0
3567 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3568 #endif
3569 static tree decl_ultimate_origin PARAMS ((tree));
3570 static tree block_ultimate_origin PARAMS ((tree));
3571 static tree decl_class_context PARAMS ((tree));
3572 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3573 static void add_AT_flag PARAMS ((dw_die_ref,
3574 enum dwarf_attribute,
3575 unsigned));
3576 static void add_AT_int PARAMS ((dw_die_ref,
3577 enum dwarf_attribute, long));
3578 static void add_AT_unsigned PARAMS ((dw_die_ref,
3579 enum dwarf_attribute,
3580 unsigned long));
3581 static void add_AT_long_long PARAMS ((dw_die_ref,
3582 enum dwarf_attribute,
3583 unsigned long,
3584 unsigned long));
3585 static void add_AT_float PARAMS ((dw_die_ref,
3586 enum dwarf_attribute,
3587 unsigned, long *));
3588 static void add_AT_string PARAMS ((dw_die_ref,
3589 enum dwarf_attribute,
3590 const char *));
3591 static void add_AT_die_ref PARAMS ((dw_die_ref,
3592 enum dwarf_attribute,
3593 dw_die_ref));
3594 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3595 enum dwarf_attribute,
3596 unsigned));
3597 static void add_AT_loc PARAMS ((dw_die_ref,
3598 enum dwarf_attribute,
3599 dw_loc_descr_ref));
3600 static void add_AT_addr PARAMS ((dw_die_ref,
3601 enum dwarf_attribute,
3602 rtx));
3603 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3604 enum dwarf_attribute,
3605 const char *));
3606 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3607 enum dwarf_attribute,
3608 const char *));
3609 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3610 enum dwarf_attribute));
3611 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3612 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3613 static const char *get_AT_string PARAMS ((dw_die_ref,
3614 enum dwarf_attribute));
3615 static int get_AT_flag PARAMS ((dw_die_ref,
3616 enum dwarf_attribute));
3617 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3618 enum dwarf_attribute));
3619 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3620 enum dwarf_attribute));
3621 static int is_c_family PARAMS ((void));
3622 static int is_java PARAMS ((void));
3623 static int is_fortran PARAMS ((void));
3624 static void remove_AT PARAMS ((dw_die_ref,
3625 enum dwarf_attribute));
3626 static void remove_children PARAMS ((dw_die_ref));
3627 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3628 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3629 static dw_die_ref lookup_type_die PARAMS ((tree));
3630 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3631 static dw_die_ref lookup_decl_die PARAMS ((tree));
3632 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3633 static void print_spaces PARAMS ((FILE *));
3634 static void print_die PARAMS ((dw_die_ref, FILE *));
3635 static void print_dwarf_line_table PARAMS ((FILE *));
3636 static void reverse_die_lists PARAMS ((dw_die_ref));
3637 static void reverse_all_dies PARAMS ((dw_die_ref));
3638 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3639 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3640 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3641 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3642 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3643 static void compute_section_prefix PARAMS ((dw_die_ref));
3644 static int is_type_die PARAMS ((dw_die_ref));
3645 static int is_comdat_die PARAMS ((dw_die_ref));
3646 static int is_symbol_die PARAMS ((dw_die_ref));
3647 static char *gen_internal_sym PARAMS ((void));
3648 static void assign_symbol_names PARAMS ((dw_die_ref));
3649 static void break_out_includes PARAMS ((dw_die_ref));
3650 static void add_sibling_attributes PARAMS ((dw_die_ref));
3651 static void build_abbrev_table PARAMS ((dw_die_ref));
3652 static unsigned long size_of_string PARAMS ((const char *));
3653 static int constant_size PARAMS ((long unsigned));
3654 static unsigned long size_of_die PARAMS ((dw_die_ref));
3655 static void calc_die_sizes PARAMS ((dw_die_ref));
3656 static void mark_dies PARAMS ((dw_die_ref));
3657 static void unmark_dies PARAMS ((dw_die_ref));
3658 static unsigned long size_of_line_prolog PARAMS ((void));
3659 static unsigned long size_of_pubnames PARAMS ((void));
3660 static unsigned long size_of_aranges PARAMS ((void));
3661 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3662 static void output_value_format PARAMS ((dw_attr_ref));
3663 static void output_abbrev_section PARAMS ((void));
3664 static void output_die_symbol PARAMS ((dw_die_ref));
3665 static void output_symbolic_ref PARAMS ((dw_die_ref));
3666 static void output_die PARAMS ((dw_die_ref));
3667 static void output_compilation_unit_header PARAMS ((void));
3668 static void output_comp_unit PARAMS ((dw_die_ref));
3669 static const char *dwarf2_name PARAMS ((tree, int));
3670 static void add_pubname PARAMS ((tree, dw_die_ref));
3671 static void output_pubnames PARAMS ((void));
3672 static void add_arange PARAMS ((tree, dw_die_ref));
3673 static void output_aranges PARAMS ((void));
3674 static void output_line_info PARAMS ((void));
3675 static void output_file_names PARAMS ((void));
3676 static dw_die_ref base_type_die PARAMS ((tree));
3677 static tree root_type PARAMS ((tree));
3678 static int is_base_type PARAMS ((tree));
3679 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3680 static int type_is_enum PARAMS ((tree));
3681 static unsigned int reg_number PARAMS ((rtx));
3682 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3683 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3684 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3685 static int is_based_loc PARAMS ((rtx));
3686 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3687 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3688 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3689 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3690 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3691 static tree field_type PARAMS ((tree));
3692 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3693 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3694 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3695 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3696 static void add_AT_location_description PARAMS ((dw_die_ref,
3697 enum dwarf_attribute, rtx));
3698 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3699 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3700 static rtx rtl_for_decl_location PARAMS ((tree));
3701 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3702 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3703 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3704 static void add_bound_info PARAMS ((dw_die_ref,
3705 enum dwarf_attribute, tree));
3706 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3707 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3708 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3709 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3710 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3711 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3712 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3713 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3714 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3715 static void push_decl_scope PARAMS ((tree));
3716 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3717 static void pop_decl_scope PARAMS ((void));
3718 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3719 dw_die_ref));
3720 static const char *type_tag PARAMS ((tree));
3721 static tree member_declared_type PARAMS ((tree));
3722 #if 0
3723 static const char *decl_start_label PARAMS ((tree));
3724 #endif
3725 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3726 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3727 #if 0
3728 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3729 #endif
3730 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3731 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3732 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3733 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3734 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3735 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3736 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3737 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3738 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3739 static void gen_label_die PARAMS ((tree, dw_die_ref));
3740 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3741 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3742 static void gen_field_die PARAMS ((tree, dw_die_ref));
3743 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3744 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3745 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3746 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3747 static void gen_member_die PARAMS ((tree, dw_die_ref));
3748 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3749 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3750 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3751 static void gen_type_die PARAMS ((tree, dw_die_ref));
3752 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3753 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3754 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3755 static int is_redundant_typedef PARAMS ((tree));
3756 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3757 static unsigned lookup_filename PARAMS ((struct file_table *,
3758 const char *));
3759 static void init_file_table PARAMS ((struct file_table *));
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 void gen_abstract_function PARAMS ((tree));
3764 static rtx save_rtx PARAMS ((rtx));
3765 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3766 static int file_info_cmp PARAMS ((const void *, const void *));
3768 /* Section names used to hold DWARF debugging information. */
3769 #ifndef DEBUG_INFO_SECTION
3770 #define DEBUG_INFO_SECTION ".debug_info"
3771 #endif
3772 #ifndef ABBREV_SECTION
3773 #define ABBREV_SECTION ".debug_abbrev"
3774 #endif
3775 #ifndef ARANGES_SECTION
3776 #define ARANGES_SECTION ".debug_aranges"
3777 #endif
3778 #ifndef DW_MACINFO_SECTION
3779 #define DW_MACINFO_SECTION ".debug_macinfo"
3780 #endif
3781 #ifndef DEBUG_LINE_SECTION
3782 #define DEBUG_LINE_SECTION ".debug_line"
3783 #endif
3784 #ifndef LOC_SECTION
3785 #define LOC_SECTION ".debug_loc"
3786 #endif
3787 #ifndef PUBNAMES_SECTION
3788 #define PUBNAMES_SECTION ".debug_pubnames"
3789 #endif
3790 #ifndef STR_SECTION
3791 #define STR_SECTION ".debug_str"
3792 #endif
3794 /* Standard ELF section names for compiled code and data. */
3795 #ifndef TEXT_SECTION
3796 #define TEXT_SECTION ".text"
3797 #endif
3798 #ifndef DATA_SECTION
3799 #define DATA_SECTION ".data"
3800 #endif
3801 #ifndef BSS_SECTION
3802 #define BSS_SECTION ".bss"
3803 #endif
3805 /* Labels we insert at beginning sections we can reference instead of
3806 the section names themselves. */
3808 #ifndef TEXT_SECTION_LABEL
3809 #define TEXT_SECTION_LABEL "Ltext"
3810 #endif
3811 #ifndef DEBUG_LINE_SECTION_LABEL
3812 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3813 #endif
3814 #ifndef DEBUG_INFO_SECTION_LABEL
3815 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3816 #endif
3817 #ifndef ABBREV_SECTION_LABEL
3818 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3819 #endif
3821 /* Definitions of defaults for formats and names of various special
3822 (artificial) labels which may be generated within this file (when the -g
3823 options is used and DWARF_DEBUGGING_INFO is in effect.
3824 If necessary, these may be overridden from within the tm.h file, but
3825 typically, overriding these defaults is unnecessary. */
3827 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3828 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3829 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3830 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3831 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3833 #ifndef TEXT_END_LABEL
3834 #define TEXT_END_LABEL "Letext"
3835 #endif
3836 #ifndef DATA_END_LABEL
3837 #define DATA_END_LABEL "Ledata"
3838 #endif
3839 #ifndef BSS_END_LABEL
3840 #define BSS_END_LABEL "Lebss"
3841 #endif
3842 #ifndef BLOCK_BEGIN_LABEL
3843 #define BLOCK_BEGIN_LABEL "LBB"
3844 #endif
3845 #ifndef BLOCK_END_LABEL
3846 #define BLOCK_END_LABEL "LBE"
3847 #endif
3848 #ifndef BODY_BEGIN_LABEL
3849 #define BODY_BEGIN_LABEL "Lbb"
3850 #endif
3851 #ifndef BODY_END_LABEL
3852 #define BODY_END_LABEL "Lbe"
3853 #endif
3854 #ifndef LINE_CODE_LABEL
3855 #define LINE_CODE_LABEL "LM"
3856 #endif
3857 #ifndef SEPARATE_LINE_CODE_LABEL
3858 #define SEPARATE_LINE_CODE_LABEL "LSM"
3859 #endif
3861 /* We allow a language front-end to designate a function that is to be
3862 called to "demangle" any name before it it put into a DIE. */
3864 static const char *(*demangle_name_func) PARAMS ((const char *));
3866 void
3867 dwarf2out_set_demangle_name_func (func)
3868 const char *(*func) PARAMS ((const char *));
3870 demangle_name_func = func;
3873 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3874 that means adding it to used_rtx_varray. If not, that means making
3875 a copy on the permanent_obstack. */
3877 static rtx
3878 save_rtx (orig)
3879 register rtx orig;
3881 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3883 return orig;
3886 /* Test if rtl node points to a pseudo register. */
3888 static inline int
3889 is_pseudo_reg (rtl)
3890 register rtx rtl;
3892 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3893 || (GET_CODE (rtl) == SUBREG
3894 && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER));
3897 /* Return a reference to a type, with its const and volatile qualifiers
3898 removed. */
3900 static inline tree
3901 type_main_variant (type)
3902 register tree type;
3904 type = TYPE_MAIN_VARIANT (type);
3906 /* There really should be only one main variant among any group of variants
3907 of a given type (and all of the MAIN_VARIANT values for all members of
3908 the group should point to that one type) but sometimes the C front-end
3909 messes this up for array types, so we work around that bug here. */
3911 if (TREE_CODE (type) == ARRAY_TYPE)
3912 while (type != TYPE_MAIN_VARIANT (type))
3913 type = TYPE_MAIN_VARIANT (type);
3915 return type;
3918 /* Return non-zero if the given type node represents a tagged type. */
3920 static inline int
3921 is_tagged_type (type)
3922 register tree type;
3924 register enum tree_code code = TREE_CODE (type);
3926 return (code == RECORD_TYPE || code == UNION_TYPE
3927 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3930 /* Convert a DIE tag into its string name. */
3932 static const char *
3933 dwarf_tag_name (tag)
3934 register unsigned tag;
3936 switch (tag)
3938 case DW_TAG_padding:
3939 return "DW_TAG_padding";
3940 case DW_TAG_array_type:
3941 return "DW_TAG_array_type";
3942 case DW_TAG_class_type:
3943 return "DW_TAG_class_type";
3944 case DW_TAG_entry_point:
3945 return "DW_TAG_entry_point";
3946 case DW_TAG_enumeration_type:
3947 return "DW_TAG_enumeration_type";
3948 case DW_TAG_formal_parameter:
3949 return "DW_TAG_formal_parameter";
3950 case DW_TAG_imported_declaration:
3951 return "DW_TAG_imported_declaration";
3952 case DW_TAG_label:
3953 return "DW_TAG_label";
3954 case DW_TAG_lexical_block:
3955 return "DW_TAG_lexical_block";
3956 case DW_TAG_member:
3957 return "DW_TAG_member";
3958 case DW_TAG_pointer_type:
3959 return "DW_TAG_pointer_type";
3960 case DW_TAG_reference_type:
3961 return "DW_TAG_reference_type";
3962 case DW_TAG_compile_unit:
3963 return "DW_TAG_compile_unit";
3964 case DW_TAG_string_type:
3965 return "DW_TAG_string_type";
3966 case DW_TAG_structure_type:
3967 return "DW_TAG_structure_type";
3968 case DW_TAG_subroutine_type:
3969 return "DW_TAG_subroutine_type";
3970 case DW_TAG_typedef:
3971 return "DW_TAG_typedef";
3972 case DW_TAG_union_type:
3973 return "DW_TAG_union_type";
3974 case DW_TAG_unspecified_parameters:
3975 return "DW_TAG_unspecified_parameters";
3976 case DW_TAG_variant:
3977 return "DW_TAG_variant";
3978 case DW_TAG_common_block:
3979 return "DW_TAG_common_block";
3980 case DW_TAG_common_inclusion:
3981 return "DW_TAG_common_inclusion";
3982 case DW_TAG_inheritance:
3983 return "DW_TAG_inheritance";
3984 case DW_TAG_inlined_subroutine:
3985 return "DW_TAG_inlined_subroutine";
3986 case DW_TAG_module:
3987 return "DW_TAG_module";
3988 case DW_TAG_ptr_to_member_type:
3989 return "DW_TAG_ptr_to_member_type";
3990 case DW_TAG_set_type:
3991 return "DW_TAG_set_type";
3992 case DW_TAG_subrange_type:
3993 return "DW_TAG_subrange_type";
3994 case DW_TAG_with_stmt:
3995 return "DW_TAG_with_stmt";
3996 case DW_TAG_access_declaration:
3997 return "DW_TAG_access_declaration";
3998 case DW_TAG_base_type:
3999 return "DW_TAG_base_type";
4000 case DW_TAG_catch_block:
4001 return "DW_TAG_catch_block";
4002 case DW_TAG_const_type:
4003 return "DW_TAG_const_type";
4004 case DW_TAG_constant:
4005 return "DW_TAG_constant";
4006 case DW_TAG_enumerator:
4007 return "DW_TAG_enumerator";
4008 case DW_TAG_file_type:
4009 return "DW_TAG_file_type";
4010 case DW_TAG_friend:
4011 return "DW_TAG_friend";
4012 case DW_TAG_namelist:
4013 return "DW_TAG_namelist";
4014 case DW_TAG_namelist_item:
4015 return "DW_TAG_namelist_item";
4016 case DW_TAG_packed_type:
4017 return "DW_TAG_packed_type";
4018 case DW_TAG_subprogram:
4019 return "DW_TAG_subprogram";
4020 case DW_TAG_template_type_param:
4021 return "DW_TAG_template_type_param";
4022 case DW_TAG_template_value_param:
4023 return "DW_TAG_template_value_param";
4024 case DW_TAG_thrown_type:
4025 return "DW_TAG_thrown_type";
4026 case DW_TAG_try_block:
4027 return "DW_TAG_try_block";
4028 case DW_TAG_variant_part:
4029 return "DW_TAG_variant_part";
4030 case DW_TAG_variable:
4031 return "DW_TAG_variable";
4032 case DW_TAG_volatile_type:
4033 return "DW_TAG_volatile_type";
4034 case DW_TAG_MIPS_loop:
4035 return "DW_TAG_MIPS_loop";
4036 case DW_TAG_format_label:
4037 return "DW_TAG_format_label";
4038 case DW_TAG_function_template:
4039 return "DW_TAG_function_template";
4040 case DW_TAG_class_template:
4041 return "DW_TAG_class_template";
4042 case DW_TAG_GNU_BINCL:
4043 return "DW_TAG_GNU_BINCL";
4044 case DW_TAG_GNU_EINCL:
4045 return "DW_TAG_GNU_EINCL";
4046 default:
4047 return "DW_TAG_<unknown>";
4051 /* Convert a DWARF attribute code into its string name. */
4053 static const char *
4054 dwarf_attr_name (attr)
4055 register unsigned attr;
4057 switch (attr)
4059 case DW_AT_sibling:
4060 return "DW_AT_sibling";
4061 case DW_AT_location:
4062 return "DW_AT_location";
4063 case DW_AT_name:
4064 return "DW_AT_name";
4065 case DW_AT_ordering:
4066 return "DW_AT_ordering";
4067 case DW_AT_subscr_data:
4068 return "DW_AT_subscr_data";
4069 case DW_AT_byte_size:
4070 return "DW_AT_byte_size";
4071 case DW_AT_bit_offset:
4072 return "DW_AT_bit_offset";
4073 case DW_AT_bit_size:
4074 return "DW_AT_bit_size";
4075 case DW_AT_element_list:
4076 return "DW_AT_element_list";
4077 case DW_AT_stmt_list:
4078 return "DW_AT_stmt_list";
4079 case DW_AT_low_pc:
4080 return "DW_AT_low_pc";
4081 case DW_AT_high_pc:
4082 return "DW_AT_high_pc";
4083 case DW_AT_language:
4084 return "DW_AT_language";
4085 case DW_AT_member:
4086 return "DW_AT_member";
4087 case DW_AT_discr:
4088 return "DW_AT_discr";
4089 case DW_AT_discr_value:
4090 return "DW_AT_discr_value";
4091 case DW_AT_visibility:
4092 return "DW_AT_visibility";
4093 case DW_AT_import:
4094 return "DW_AT_import";
4095 case DW_AT_string_length:
4096 return "DW_AT_string_length";
4097 case DW_AT_common_reference:
4098 return "DW_AT_common_reference";
4099 case DW_AT_comp_dir:
4100 return "DW_AT_comp_dir";
4101 case DW_AT_const_value:
4102 return "DW_AT_const_value";
4103 case DW_AT_containing_type:
4104 return "DW_AT_containing_type";
4105 case DW_AT_default_value:
4106 return "DW_AT_default_value";
4107 case DW_AT_inline:
4108 return "DW_AT_inline";
4109 case DW_AT_is_optional:
4110 return "DW_AT_is_optional";
4111 case DW_AT_lower_bound:
4112 return "DW_AT_lower_bound";
4113 case DW_AT_producer:
4114 return "DW_AT_producer";
4115 case DW_AT_prototyped:
4116 return "DW_AT_prototyped";
4117 case DW_AT_return_addr:
4118 return "DW_AT_return_addr";
4119 case DW_AT_start_scope:
4120 return "DW_AT_start_scope";
4121 case DW_AT_stride_size:
4122 return "DW_AT_stride_size";
4123 case DW_AT_upper_bound:
4124 return "DW_AT_upper_bound";
4125 case DW_AT_abstract_origin:
4126 return "DW_AT_abstract_origin";
4127 case DW_AT_accessibility:
4128 return "DW_AT_accessibility";
4129 case DW_AT_address_class:
4130 return "DW_AT_address_class";
4131 case DW_AT_artificial:
4132 return "DW_AT_artificial";
4133 case DW_AT_base_types:
4134 return "DW_AT_base_types";
4135 case DW_AT_calling_convention:
4136 return "DW_AT_calling_convention";
4137 case DW_AT_count:
4138 return "DW_AT_count";
4139 case DW_AT_data_member_location:
4140 return "DW_AT_data_member_location";
4141 case DW_AT_decl_column:
4142 return "DW_AT_decl_column";
4143 case DW_AT_decl_file:
4144 return "DW_AT_decl_file";
4145 case DW_AT_decl_line:
4146 return "DW_AT_decl_line";
4147 case DW_AT_declaration:
4148 return "DW_AT_declaration";
4149 case DW_AT_discr_list:
4150 return "DW_AT_discr_list";
4151 case DW_AT_encoding:
4152 return "DW_AT_encoding";
4153 case DW_AT_external:
4154 return "DW_AT_external";
4155 case DW_AT_frame_base:
4156 return "DW_AT_frame_base";
4157 case DW_AT_friend:
4158 return "DW_AT_friend";
4159 case DW_AT_identifier_case:
4160 return "DW_AT_identifier_case";
4161 case DW_AT_macro_info:
4162 return "DW_AT_macro_info";
4163 case DW_AT_namelist_items:
4164 return "DW_AT_namelist_items";
4165 case DW_AT_priority:
4166 return "DW_AT_priority";
4167 case DW_AT_segment:
4168 return "DW_AT_segment";
4169 case DW_AT_specification:
4170 return "DW_AT_specification";
4171 case DW_AT_static_link:
4172 return "DW_AT_static_link";
4173 case DW_AT_type:
4174 return "DW_AT_type";
4175 case DW_AT_use_location:
4176 return "DW_AT_use_location";
4177 case DW_AT_variable_parameter:
4178 return "DW_AT_variable_parameter";
4179 case DW_AT_virtuality:
4180 return "DW_AT_virtuality";
4181 case DW_AT_vtable_elem_location:
4182 return "DW_AT_vtable_elem_location";
4184 case DW_AT_MIPS_fde:
4185 return "DW_AT_MIPS_fde";
4186 case DW_AT_MIPS_loop_begin:
4187 return "DW_AT_MIPS_loop_begin";
4188 case DW_AT_MIPS_tail_loop_begin:
4189 return "DW_AT_MIPS_tail_loop_begin";
4190 case DW_AT_MIPS_epilog_begin:
4191 return "DW_AT_MIPS_epilog_begin";
4192 case DW_AT_MIPS_loop_unroll_factor:
4193 return "DW_AT_MIPS_loop_unroll_factor";
4194 case DW_AT_MIPS_software_pipeline_depth:
4195 return "DW_AT_MIPS_software_pipeline_depth";
4196 case DW_AT_MIPS_linkage_name:
4197 return "DW_AT_MIPS_linkage_name";
4198 case DW_AT_MIPS_stride:
4199 return "DW_AT_MIPS_stride";
4200 case DW_AT_MIPS_abstract_name:
4201 return "DW_AT_MIPS_abstract_name";
4202 case DW_AT_MIPS_clone_origin:
4203 return "DW_AT_MIPS_clone_origin";
4204 case DW_AT_MIPS_has_inlines:
4205 return "DW_AT_MIPS_has_inlines";
4207 case DW_AT_sf_names:
4208 return "DW_AT_sf_names";
4209 case DW_AT_src_info:
4210 return "DW_AT_src_info";
4211 case DW_AT_mac_info:
4212 return "DW_AT_mac_info";
4213 case DW_AT_src_coords:
4214 return "DW_AT_src_coords";
4215 case DW_AT_body_begin:
4216 return "DW_AT_body_begin";
4217 case DW_AT_body_end:
4218 return "DW_AT_body_end";
4219 default:
4220 return "DW_AT_<unknown>";
4224 /* Convert a DWARF value form code into its string name. */
4226 static const char *
4227 dwarf_form_name (form)
4228 register unsigned form;
4230 switch (form)
4232 case DW_FORM_addr:
4233 return "DW_FORM_addr";
4234 case DW_FORM_block2:
4235 return "DW_FORM_block2";
4236 case DW_FORM_block4:
4237 return "DW_FORM_block4";
4238 case DW_FORM_data2:
4239 return "DW_FORM_data2";
4240 case DW_FORM_data4:
4241 return "DW_FORM_data4";
4242 case DW_FORM_data8:
4243 return "DW_FORM_data8";
4244 case DW_FORM_string:
4245 return "DW_FORM_string";
4246 case DW_FORM_block:
4247 return "DW_FORM_block";
4248 case DW_FORM_block1:
4249 return "DW_FORM_block1";
4250 case DW_FORM_data1:
4251 return "DW_FORM_data1";
4252 case DW_FORM_flag:
4253 return "DW_FORM_flag";
4254 case DW_FORM_sdata:
4255 return "DW_FORM_sdata";
4256 case DW_FORM_strp:
4257 return "DW_FORM_strp";
4258 case DW_FORM_udata:
4259 return "DW_FORM_udata";
4260 case DW_FORM_ref_addr:
4261 return "DW_FORM_ref_addr";
4262 case DW_FORM_ref1:
4263 return "DW_FORM_ref1";
4264 case DW_FORM_ref2:
4265 return "DW_FORM_ref2";
4266 case DW_FORM_ref4:
4267 return "DW_FORM_ref4";
4268 case DW_FORM_ref8:
4269 return "DW_FORM_ref8";
4270 case DW_FORM_ref_udata:
4271 return "DW_FORM_ref_udata";
4272 case DW_FORM_indirect:
4273 return "DW_FORM_indirect";
4274 default:
4275 return "DW_FORM_<unknown>";
4279 /* Convert a DWARF type code into its string name. */
4281 #if 0
4282 static const char *
4283 dwarf_type_encoding_name (enc)
4284 register unsigned enc;
4286 switch (enc)
4288 case DW_ATE_address:
4289 return "DW_ATE_address";
4290 case DW_ATE_boolean:
4291 return "DW_ATE_boolean";
4292 case DW_ATE_complex_float:
4293 return "DW_ATE_complex_float";
4294 case DW_ATE_float:
4295 return "DW_ATE_float";
4296 case DW_ATE_signed:
4297 return "DW_ATE_signed";
4298 case DW_ATE_signed_char:
4299 return "DW_ATE_signed_char";
4300 case DW_ATE_unsigned:
4301 return "DW_ATE_unsigned";
4302 case DW_ATE_unsigned_char:
4303 return "DW_ATE_unsigned_char";
4304 default:
4305 return "DW_ATE_<unknown>";
4308 #endif
4310 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4311 instance of an inlined instance of a decl which is local to an inline
4312 function, so we have to trace all of the way back through the origin chain
4313 to find out what sort of node actually served as the original seed for the
4314 given block. */
4316 static tree
4317 decl_ultimate_origin (decl)
4318 register tree decl;
4320 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4321 nodes in the function to point to themselves; ignore that if
4322 we're trying to output the abstract instance of this function. */
4323 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4324 return NULL_TREE;
4326 #ifdef ENABLE_CHECKING
4327 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4328 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4329 most distant ancestor, this should never happen. */
4330 abort ();
4331 #endif
4333 return DECL_ABSTRACT_ORIGIN (decl);
4336 /* Determine the "ultimate origin" of a block. The block may be an inlined
4337 instance of an inlined instance of a block which is local to an inline
4338 function, so we have to trace all of the way back through the origin chain
4339 to find out what sort of node actually served as the original seed for the
4340 given block. */
4342 static tree
4343 block_ultimate_origin (block)
4344 register tree block;
4346 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4348 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4349 nodes in the function to point to themselves; ignore that if
4350 we're trying to output the abstract instance of this function. */
4351 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4352 return NULL_TREE;
4354 if (immediate_origin == NULL_TREE)
4355 return NULL_TREE;
4356 else
4358 register tree ret_val;
4359 register tree lookahead = immediate_origin;
4363 ret_val = lookahead;
4364 lookahead = (TREE_CODE (ret_val) == BLOCK)
4365 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4366 : NULL;
4368 while (lookahead != NULL && lookahead != ret_val);
4370 return ret_val;
4374 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4375 of a virtual function may refer to a base class, so we check the 'this'
4376 parameter. */
4378 static tree
4379 decl_class_context (decl)
4380 tree decl;
4382 tree context = NULL_TREE;
4384 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4385 context = DECL_CONTEXT (decl);
4386 else
4387 context = TYPE_MAIN_VARIANT
4388 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4390 if (context && !TYPE_P (context))
4391 context = NULL_TREE;
4393 return context;
4396 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4397 addition order, and correct that in reverse_all_dies. */
4399 static inline void
4400 add_dwarf_attr (die, attr)
4401 register dw_die_ref die;
4402 register dw_attr_ref attr;
4404 if (die != NULL && attr != NULL)
4406 attr->dw_attr_next = die->die_attr;
4407 die->die_attr = attr;
4411 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4412 static inline dw_val_class
4413 AT_class (a)
4414 dw_attr_ref a;
4416 return a->dw_attr_val.val_class;
4419 /* Add a flag value attribute to a DIE. */
4421 static inline void
4422 add_AT_flag (die, attr_kind, flag)
4423 register dw_die_ref die;
4424 register enum dwarf_attribute attr_kind;
4425 register unsigned flag;
4427 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4429 attr->dw_attr_next = NULL;
4430 attr->dw_attr = attr_kind;
4431 attr->dw_attr_val.val_class = dw_val_class_flag;
4432 attr->dw_attr_val.v.val_flag = flag;
4433 add_dwarf_attr (die, attr);
4436 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4437 static inline unsigned
4438 AT_flag (a)
4439 register dw_attr_ref a;
4441 if (a && AT_class (a) == dw_val_class_flag)
4442 return a->dw_attr_val.v.val_flag;
4444 abort ();
4447 /* Add a signed integer attribute value to a DIE. */
4449 static inline void
4450 add_AT_int (die, attr_kind, int_val)
4451 register dw_die_ref die;
4452 register enum dwarf_attribute attr_kind;
4453 register long int int_val;
4455 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4457 attr->dw_attr_next = NULL;
4458 attr->dw_attr = attr_kind;
4459 attr->dw_attr_val.val_class = dw_val_class_const;
4460 attr->dw_attr_val.v.val_int = int_val;
4461 add_dwarf_attr (die, attr);
4464 static inline long int AT_int PARAMS ((dw_attr_ref));
4465 static inline long int
4466 AT_int (a)
4467 register dw_attr_ref a;
4469 if (a && AT_class (a) == dw_val_class_const)
4470 return a->dw_attr_val.v.val_int;
4472 abort ();
4475 /* Add an unsigned integer attribute value to a DIE. */
4477 static inline void
4478 add_AT_unsigned (die, attr_kind, unsigned_val)
4479 register dw_die_ref die;
4480 register enum dwarf_attribute attr_kind;
4481 register unsigned long unsigned_val;
4483 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4485 attr->dw_attr_next = NULL;
4486 attr->dw_attr = attr_kind;
4487 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4488 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4489 add_dwarf_attr (die, attr);
4492 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4493 static inline unsigned long
4494 AT_unsigned (a)
4495 register dw_attr_ref a;
4497 if (a && AT_class (a) == dw_val_class_unsigned_const)
4498 return a->dw_attr_val.v.val_unsigned;
4500 abort ();
4503 /* Add an unsigned double integer attribute value to a DIE. */
4505 static inline void
4506 add_AT_long_long (die, attr_kind, val_hi, val_low)
4507 register dw_die_ref die;
4508 register enum dwarf_attribute attr_kind;
4509 register unsigned long val_hi;
4510 register unsigned long val_low;
4512 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4514 attr->dw_attr_next = NULL;
4515 attr->dw_attr = attr_kind;
4516 attr->dw_attr_val.val_class = dw_val_class_long_long;
4517 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4518 attr->dw_attr_val.v.val_long_long.low = val_low;
4519 add_dwarf_attr (die, attr);
4522 /* Add a floating point attribute value to a DIE and return it. */
4524 static inline void
4525 add_AT_float (die, attr_kind, length, array)
4526 register dw_die_ref die;
4527 register enum dwarf_attribute attr_kind;
4528 register unsigned length;
4529 register long *array;
4531 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4533 attr->dw_attr_next = NULL;
4534 attr->dw_attr = attr_kind;
4535 attr->dw_attr_val.val_class = dw_val_class_float;
4536 attr->dw_attr_val.v.val_float.length = length;
4537 attr->dw_attr_val.v.val_float.array = array;
4538 add_dwarf_attr (die, attr);
4541 /* Add a string attribute value to a DIE. */
4543 static inline void
4544 add_AT_string (die, attr_kind, str)
4545 register dw_die_ref die;
4546 register enum dwarf_attribute attr_kind;
4547 register const char *str;
4549 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4551 attr->dw_attr_next = NULL;
4552 attr->dw_attr = attr_kind;
4553 attr->dw_attr_val.val_class = dw_val_class_str;
4554 attr->dw_attr_val.v.val_str = xstrdup (str);
4555 add_dwarf_attr (die, attr);
4558 static inline const char *AT_string PARAMS ((dw_attr_ref));
4559 static inline const char *
4560 AT_string (a)
4561 register dw_attr_ref a;
4563 if (a && AT_class (a) == dw_val_class_str)
4564 return a->dw_attr_val.v.val_str;
4566 abort ();
4569 /* Add a DIE reference attribute value to a DIE. */
4571 static inline void
4572 add_AT_die_ref (die, attr_kind, targ_die)
4573 register dw_die_ref die;
4574 register enum dwarf_attribute attr_kind;
4575 register dw_die_ref targ_die;
4577 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4579 attr->dw_attr_next = NULL;
4580 attr->dw_attr = attr_kind;
4581 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4582 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4583 attr->dw_attr_val.v.val_die_ref.external = 0;
4584 add_dwarf_attr (die, attr);
4587 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4588 static inline dw_die_ref
4589 AT_ref (a)
4590 register dw_attr_ref a;
4592 if (a && AT_class (a) == dw_val_class_die_ref)
4593 return a->dw_attr_val.v.val_die_ref.die;
4595 abort ();
4598 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4599 static inline int
4600 AT_ref_external (a)
4601 register dw_attr_ref a;
4603 if (a && AT_class (a) == dw_val_class_die_ref)
4604 return a->dw_attr_val.v.val_die_ref.external;
4606 return 0;
4609 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4610 static inline void
4611 set_AT_ref_external (a, i)
4612 register dw_attr_ref a;
4613 int i;
4615 if (a && AT_class (a) == dw_val_class_die_ref)
4616 a->dw_attr_val.v.val_die_ref.external = i;
4617 else
4618 abort ();
4621 /* Add an FDE reference attribute value to a DIE. */
4623 static inline void
4624 add_AT_fde_ref (die, attr_kind, targ_fde)
4625 register dw_die_ref die;
4626 register enum dwarf_attribute attr_kind;
4627 register unsigned targ_fde;
4629 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4631 attr->dw_attr_next = NULL;
4632 attr->dw_attr = attr_kind;
4633 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4634 attr->dw_attr_val.v.val_fde_index = targ_fde;
4635 add_dwarf_attr (die, attr);
4638 /* Add a location description attribute value to a DIE. */
4640 static inline void
4641 add_AT_loc (die, attr_kind, loc)
4642 register dw_die_ref die;
4643 register enum dwarf_attribute attr_kind;
4644 register dw_loc_descr_ref loc;
4646 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4648 attr->dw_attr_next = NULL;
4649 attr->dw_attr = attr_kind;
4650 attr->dw_attr_val.val_class = dw_val_class_loc;
4651 attr->dw_attr_val.v.val_loc = loc;
4652 add_dwarf_attr (die, attr);
4655 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4656 static inline dw_loc_descr_ref
4657 AT_loc (a)
4658 register dw_attr_ref a;
4660 if (a && AT_class (a) == dw_val_class_loc)
4661 return a->dw_attr_val.v.val_loc;
4663 abort ();
4666 /* Add an address constant attribute value to a DIE. */
4668 static inline void
4669 add_AT_addr (die, attr_kind, addr)
4670 register dw_die_ref die;
4671 register enum dwarf_attribute attr_kind;
4672 rtx addr;
4674 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4676 attr->dw_attr_next = NULL;
4677 attr->dw_attr = attr_kind;
4678 attr->dw_attr_val.val_class = dw_val_class_addr;
4679 attr->dw_attr_val.v.val_addr = addr;
4680 add_dwarf_attr (die, attr);
4683 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4684 static inline rtx
4685 AT_addr (a)
4686 register dw_attr_ref a;
4688 if (a && AT_class (a) == dw_val_class_addr)
4689 return a->dw_attr_val.v.val_addr;
4691 abort ();
4694 /* Add a label identifier attribute value to a DIE. */
4696 static inline void
4697 add_AT_lbl_id (die, attr_kind, lbl_id)
4698 register dw_die_ref die;
4699 register enum dwarf_attribute attr_kind;
4700 register const char *lbl_id;
4702 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4704 attr->dw_attr_next = NULL;
4705 attr->dw_attr = attr_kind;
4706 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4707 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4708 add_dwarf_attr (die, attr);
4711 /* Add a section offset attribute value to a DIE. */
4713 static inline void
4714 add_AT_lbl_offset (die, attr_kind, label)
4715 register dw_die_ref die;
4716 register enum dwarf_attribute attr_kind;
4717 register const char *label;
4719 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4721 attr->dw_attr_next = NULL;
4722 attr->dw_attr = attr_kind;
4723 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4724 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4725 add_dwarf_attr (die, attr);
4728 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4729 static inline const char *
4730 AT_lbl (a)
4731 register dw_attr_ref a;
4733 if (a && (AT_class (a) == dw_val_class_lbl_id
4734 || AT_class (a) == dw_val_class_lbl_offset))
4735 return a->dw_attr_val.v.val_lbl_id;
4737 abort ();
4740 /* Get the attribute of type attr_kind. */
4742 static inline dw_attr_ref
4743 get_AT (die, attr_kind)
4744 register dw_die_ref die;
4745 register enum dwarf_attribute attr_kind;
4747 register dw_attr_ref a;
4748 register dw_die_ref spec = NULL;
4750 if (die != NULL)
4752 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4754 if (a->dw_attr == attr_kind)
4755 return a;
4757 if (a->dw_attr == DW_AT_specification
4758 || a->dw_attr == DW_AT_abstract_origin)
4759 spec = AT_ref (a);
4762 if (spec)
4763 return get_AT (spec, attr_kind);
4766 return NULL;
4769 /* Return the "low pc" attribute value, typically associated with
4770 a subprogram DIE. Return null if the "low pc" attribute is
4771 either not prsent, or if it cannot be represented as an
4772 assembler label identifier. */
4774 static inline const char *
4775 get_AT_low_pc (die)
4776 register dw_die_ref die;
4778 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4779 return a ? AT_lbl (a) : NULL;
4782 /* Return the "high pc" attribute value, typically associated with
4783 a subprogram DIE. Return null if the "high pc" attribute is
4784 either not prsent, or if it cannot be represented as an
4785 assembler label identifier. */
4787 static inline const char *
4788 get_AT_hi_pc (die)
4789 register dw_die_ref die;
4791 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4792 return a ? AT_lbl (a) : NULL;
4795 /* Return the value of the string attribute designated by ATTR_KIND, or
4796 NULL if it is not present. */
4798 static inline const char *
4799 get_AT_string (die, attr_kind)
4800 register dw_die_ref die;
4801 register enum dwarf_attribute attr_kind;
4803 register dw_attr_ref a = get_AT (die, attr_kind);
4804 return a ? AT_string (a) : NULL;
4807 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4808 if it is not present. */
4810 static inline int
4811 get_AT_flag (die, attr_kind)
4812 register dw_die_ref die;
4813 register enum dwarf_attribute attr_kind;
4815 register dw_attr_ref a = get_AT (die, attr_kind);
4816 return a ? AT_flag (a) : 0;
4819 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4820 if it is not present. */
4822 static inline unsigned
4823 get_AT_unsigned (die, attr_kind)
4824 register dw_die_ref die;
4825 register enum dwarf_attribute attr_kind;
4827 register dw_attr_ref a = get_AT (die, attr_kind);
4828 return a ? AT_unsigned (a) : 0;
4831 static inline dw_die_ref
4832 get_AT_ref (die, attr_kind)
4833 dw_die_ref die;
4834 register enum dwarf_attribute attr_kind;
4836 register dw_attr_ref a = get_AT (die, attr_kind);
4837 return a ? AT_ref (a) : NULL;
4840 static inline int
4841 is_c_family ()
4843 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4845 return (lang == DW_LANG_C || lang == DW_LANG_C89
4846 || lang == DW_LANG_C_plus_plus);
4849 static inline int
4850 is_fortran ()
4852 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4854 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4857 static inline int
4858 is_java ()
4860 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4862 return (lang == DW_LANG_Java);
4865 /* Free up the memory used by A. */
4867 static inline void free_AT PARAMS ((dw_attr_ref));
4868 static inline void
4869 free_AT (a)
4870 dw_attr_ref a;
4872 switch (AT_class (a))
4874 case dw_val_class_str:
4875 case dw_val_class_lbl_id:
4876 case dw_val_class_lbl_offset:
4877 free (a->dw_attr_val.v.val_str);
4878 break;
4880 case dw_val_class_float:
4881 free (a->dw_attr_val.v.val_float.array);
4882 break;
4884 default:
4885 break;
4888 free (a);
4891 /* Remove the specified attribute if present. */
4893 static void
4894 remove_AT (die, attr_kind)
4895 register dw_die_ref die;
4896 register enum dwarf_attribute attr_kind;
4898 register dw_attr_ref *p;
4899 register dw_attr_ref removed = NULL;
4901 if (die != NULL)
4903 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4904 if ((*p)->dw_attr == attr_kind)
4906 removed = *p;
4907 *p = (*p)->dw_attr_next;
4908 break;
4911 if (removed != 0)
4912 free_AT (removed);
4916 /* Free up the memory used by DIE. */
4918 static inline void free_die PARAMS ((dw_die_ref));
4919 static inline void
4920 free_die (die)
4921 dw_die_ref die;
4923 remove_children (die);
4924 free (die);
4927 /* Discard the children of this DIE. */
4929 static void
4930 remove_children (die)
4931 register dw_die_ref die;
4933 register dw_die_ref child_die = die->die_child;
4935 die->die_child = NULL;
4937 while (child_die != NULL)
4939 register dw_die_ref tmp_die = child_die;
4940 register dw_attr_ref a;
4942 child_die = child_die->die_sib;
4944 for (a = tmp_die->die_attr; a != NULL;)
4946 register dw_attr_ref tmp_a = a;
4948 a = a->dw_attr_next;
4949 free_AT (tmp_a);
4952 free_die (tmp_die);
4956 /* Add a child DIE below its parent. We build the lists up in reverse
4957 addition order, and correct that in reverse_all_dies. */
4959 static inline void
4960 add_child_die (die, child_die)
4961 register dw_die_ref die;
4962 register dw_die_ref child_die;
4964 if (die != NULL && child_die != NULL)
4966 if (die == child_die)
4967 abort ();
4968 child_die->die_parent = die;
4969 child_die->die_sib = die->die_child;
4970 die->die_child = child_die;
4974 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4975 is the specification, to the front of PARENT's list of children. */
4977 static void
4978 splice_child_die (parent, child)
4979 dw_die_ref parent, child;
4981 dw_die_ref *p;
4983 /* We want the declaration DIE from inside the class, not the
4984 specification DIE at toplevel. */
4985 if (child->die_parent != parent)
4987 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4988 if (tmp)
4989 child = tmp;
4992 if (child->die_parent != parent
4993 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4994 abort ();
4996 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4997 if (*p == child)
4999 *p = child->die_sib;
5000 break;
5003 child->die_sib = parent->die_child;
5004 parent->die_child = child;
5007 /* Return a pointer to a newly created DIE node. */
5009 static inline dw_die_ref
5010 new_die (tag_value, parent_die)
5011 register enum dwarf_tag tag_value;
5012 register dw_die_ref parent_die;
5014 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
5016 die->die_tag = tag_value;
5018 if (parent_die != NULL)
5019 add_child_die (parent_die, die);
5020 else
5022 limbo_die_node *limbo_node;
5024 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
5025 limbo_node->die = die;
5026 limbo_node->next = limbo_die_list;
5027 limbo_die_list = limbo_node;
5030 return die;
5033 /* Return the DIE associated with the given type specifier. */
5035 static inline dw_die_ref
5036 lookup_type_die (type)
5037 register tree type;
5039 if (TREE_CODE (type) == VECTOR_TYPE)
5040 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
5041 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
5044 /* Equate a DIE to a given type specifier. */
5046 static inline void
5047 equate_type_number_to_die (type, type_die)
5048 register tree type;
5049 register dw_die_ref type_die;
5051 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
5054 /* Return the DIE associated with a given declaration. */
5056 static inline dw_die_ref
5057 lookup_decl_die (decl)
5058 register tree decl;
5060 register unsigned decl_id = DECL_UID (decl);
5062 return (decl_id < decl_die_table_in_use
5063 ? decl_die_table[decl_id] : NULL);
5066 /* Equate a DIE to a particular declaration. */
5068 static void
5069 equate_decl_number_to_die (decl, decl_die)
5070 register tree decl;
5071 register dw_die_ref decl_die;
5073 register unsigned decl_id = DECL_UID (decl);
5074 register unsigned num_allocated;
5076 if (decl_id >= decl_die_table_allocated)
5078 num_allocated
5079 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5080 / DECL_DIE_TABLE_INCREMENT)
5081 * DECL_DIE_TABLE_INCREMENT;
5083 decl_die_table
5084 = (dw_die_ref *) xrealloc (decl_die_table,
5085 sizeof (dw_die_ref) * num_allocated);
5087 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5088 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5089 decl_die_table_allocated = num_allocated;
5092 if (decl_id >= decl_die_table_in_use)
5093 decl_die_table_in_use = (decl_id + 1);
5095 decl_die_table[decl_id] = decl_die;
5098 /* Keep track of the number of spaces used to indent the
5099 output of the debugging routines that print the structure of
5100 the DIE internal representation. */
5101 static int print_indent;
5103 /* Indent the line the number of spaces given by print_indent. */
5105 static inline void
5106 print_spaces (outfile)
5107 FILE *outfile;
5109 fprintf (outfile, "%*s", print_indent, "");
5112 /* Print the information associated with a given DIE, and its children.
5113 This routine is a debugging aid only. */
5115 static void
5116 print_die (die, outfile)
5117 dw_die_ref die;
5118 FILE *outfile;
5120 register dw_attr_ref a;
5121 register dw_die_ref c;
5123 print_spaces (outfile);
5124 fprintf (outfile, "DIE %4lu: %s\n",
5125 die->die_offset, dwarf_tag_name (die->die_tag));
5126 print_spaces (outfile);
5127 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5128 fprintf (outfile, " offset: %lu\n", die->die_offset);
5130 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5132 print_spaces (outfile);
5133 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5135 switch (AT_class (a))
5137 case dw_val_class_addr:
5138 fprintf (outfile, "address");
5139 break;
5140 case dw_val_class_loc:
5141 fprintf (outfile, "location descriptor");
5142 break;
5143 case dw_val_class_const:
5144 fprintf (outfile, "%ld", AT_int (a));
5145 break;
5146 case dw_val_class_unsigned_const:
5147 fprintf (outfile, "%lu", AT_unsigned (a));
5148 break;
5149 case dw_val_class_long_long:
5150 fprintf (outfile, "constant (%lu,%lu)",
5151 a->dw_attr_val.v.val_long_long.hi,
5152 a->dw_attr_val.v.val_long_long.low);
5153 break;
5154 case dw_val_class_float:
5155 fprintf (outfile, "floating-point constant");
5156 break;
5157 case dw_val_class_flag:
5158 fprintf (outfile, "%u", AT_flag (a));
5159 break;
5160 case dw_val_class_die_ref:
5161 if (AT_ref (a) != NULL)
5163 if (AT_ref (a)->die_symbol)
5164 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5165 else
5166 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5168 else
5169 fprintf (outfile, "die -> <null>");
5170 break;
5171 case dw_val_class_lbl_id:
5172 case dw_val_class_lbl_offset:
5173 fprintf (outfile, "label: %s", AT_lbl (a));
5174 break;
5175 case dw_val_class_str:
5176 if (AT_string (a) != NULL)
5177 fprintf (outfile, "\"%s\"", AT_string (a));
5178 else
5179 fprintf (outfile, "<null>");
5180 break;
5181 default:
5182 break;
5185 fprintf (outfile, "\n");
5188 if (die->die_child != NULL)
5190 print_indent += 4;
5191 for (c = die->die_child; c != NULL; c = c->die_sib)
5192 print_die (c, outfile);
5194 print_indent -= 4;
5196 if (print_indent == 0)
5197 fprintf (outfile, "\n");
5200 /* Print the contents of the source code line number correspondence table.
5201 This routine is a debugging aid only. */
5203 static void
5204 print_dwarf_line_table (outfile)
5205 FILE *outfile;
5207 register unsigned i;
5208 register dw_line_info_ref line_info;
5210 fprintf (outfile, "\n\nDWARF source line information\n");
5211 for (i = 1; i < line_info_table_in_use; ++i)
5213 line_info = &line_info_table[i];
5214 fprintf (outfile, "%5d: ", i);
5215 fprintf (outfile, "%-20s", line_file_table.table[line_info->dw_file_num]);
5216 fprintf (outfile, "%6ld", line_info->dw_line_num);
5217 fprintf (outfile, "\n");
5220 fprintf (outfile, "\n\n");
5223 /* Print the information collected for a given DIE. */
5225 void
5226 debug_dwarf_die (die)
5227 dw_die_ref die;
5229 print_die (die, stderr);
5232 /* Print all DWARF information collected for the compilation unit.
5233 This routine is a debugging aid only. */
5235 void
5236 debug_dwarf ()
5238 print_indent = 0;
5239 print_die (comp_unit_die, stderr);
5240 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5241 print_dwarf_line_table (stderr);
5244 /* We build up the lists of children and attributes by pushing new ones
5245 onto the beginning of the list. Reverse the lists for DIE so that
5246 they are in order of addition. */
5248 static void
5249 reverse_die_lists (die)
5250 register dw_die_ref die;
5252 register dw_die_ref c, cp, cn;
5253 register dw_attr_ref a, ap, an;
5255 for (a = die->die_attr, ap = 0; a; a = an)
5257 an = a->dw_attr_next;
5258 a->dw_attr_next = ap;
5259 ap = a;
5261 die->die_attr = ap;
5263 for (c = die->die_child, cp = 0; c; c = cn)
5265 cn = c->die_sib;
5266 c->die_sib = cp;
5267 cp = c;
5269 die->die_child = cp;
5272 /* reverse_die_lists only reverses the single die you pass it. Since
5273 we used to reverse all dies in add_sibling_attributes, which runs
5274 through all the dies, it would reverse all the dies. Now, however,
5275 since we don't call reverse_die_lists in add_sibling_attributes, we
5276 need a routine to recursively reverse all the dies. This is that
5277 routine. */
5279 static void
5280 reverse_all_dies (die)
5281 register dw_die_ref die;
5283 register dw_die_ref c;
5285 reverse_die_lists (die);
5287 for (c = die->die_child; c; c = c->die_sib)
5288 reverse_all_dies (c);
5291 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5292 the CU for the enclosing include file, if any. BINCL_DIE is the
5293 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5294 include file. */
5296 static dw_die_ref
5297 push_new_compile_unit (old_unit, bincl_die)
5298 dw_die_ref old_unit, bincl_die;
5300 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5301 dw_die_ref new_unit = gen_compile_unit_die (filename);
5302 new_unit->die_sib = old_unit;
5303 return new_unit;
5306 /* Close an include-file CU and reopen the enclosing one. */
5308 static dw_die_ref
5309 pop_compile_unit (old_unit)
5310 dw_die_ref old_unit;
5312 dw_die_ref new_unit = old_unit->die_sib;
5313 old_unit->die_sib = NULL;
5314 return new_unit;
5317 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5318 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5320 /* Calculate the checksum of a location expression. */
5322 static inline void
5323 loc_checksum (loc, ctx)
5324 dw_loc_descr_ref loc;
5325 struct md5_ctx *ctx;
5327 PROCESS (loc->dw_loc_opc);
5328 PROCESS (loc->dw_loc_oprnd1);
5329 PROCESS (loc->dw_loc_oprnd2);
5332 /* Calculate the checksum of an attribute. */
5334 static void
5335 attr_checksum (at, ctx)
5336 dw_attr_ref at;
5337 struct md5_ctx *ctx;
5339 dw_loc_descr_ref loc;
5340 rtx r;
5342 PROCESS (at->dw_attr);
5344 /* We don't care about differences in file numbering. */
5345 if (at->dw_attr == DW_AT_decl_file
5346 /* Or that this was compiled with a different compiler snapshot; if
5347 the output is the same, that's what matters. */
5348 || at->dw_attr == DW_AT_producer)
5349 return;
5351 switch (AT_class (at))
5353 case dw_val_class_const:
5354 PROCESS (at->dw_attr_val.v.val_int);
5355 break;
5356 case dw_val_class_unsigned_const:
5357 PROCESS (at->dw_attr_val.v.val_unsigned);
5358 break;
5359 case dw_val_class_long_long:
5360 PROCESS (at->dw_attr_val.v.val_long_long);
5361 break;
5362 case dw_val_class_float:
5363 PROCESS (at->dw_attr_val.v.val_float);
5364 break;
5365 case dw_val_class_flag:
5366 PROCESS (at->dw_attr_val.v.val_flag);
5367 break;
5369 case dw_val_class_str:
5370 PROCESS_STRING (AT_string (at));
5371 break;
5372 case dw_val_class_addr:
5373 r = AT_addr (at);
5374 switch (GET_CODE (r))
5376 case SYMBOL_REF:
5377 PROCESS_STRING (XSTR (r, 0));
5378 break;
5380 default:
5381 abort ();
5383 break;
5385 case dw_val_class_loc:
5386 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5387 loc_checksum (loc, ctx);
5388 break;
5390 case dw_val_class_die_ref:
5391 if (AT_ref (at)->die_offset)
5392 PROCESS (AT_ref (at)->die_offset);
5393 /* FIXME else use target die name or something. */
5395 case dw_val_class_fde_ref:
5396 case dw_val_class_lbl_id:
5397 case dw_val_class_lbl_offset:
5399 default:
5400 break;
5404 /* Calculate the checksum of a DIE. */
5406 static void
5407 die_checksum (die, ctx)
5408 dw_die_ref die;
5409 struct md5_ctx *ctx;
5411 dw_die_ref c;
5412 dw_attr_ref a;
5414 PROCESS (die->die_tag);
5416 for (a = die->die_attr; a; a = a->dw_attr_next)
5417 attr_checksum (a, ctx);
5419 for (c = die->die_child; c; c = c->die_sib)
5420 die_checksum (c, ctx);
5423 #undef PROCESS
5424 #undef PROCESS_STRING
5426 /* The prefix to attach to symbols on DIEs in the current comdat debug
5427 info section. */
5428 static char *comdat_symbol_id;
5430 /* The index of the current symbol within the current comdat CU. */
5431 static unsigned int comdat_symbol_number;
5433 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5434 children, and set comdat_symbol_id accordingly. */
5436 static void
5437 compute_section_prefix (unit_die)
5438 dw_die_ref unit_die;
5440 char *p, *name;
5441 int i;
5442 unsigned char checksum[16];
5443 struct md5_ctx ctx;
5445 md5_init_ctx (&ctx);
5446 die_checksum (unit_die, &ctx);
5447 md5_finish_ctx (&ctx, checksum);
5449 p = file_name_nondirectory (get_AT_string (unit_die, DW_AT_name));
5450 name = (char *) alloca (strlen (p) + 64);
5451 sprintf (name, "%s.", p);
5453 clean_symbol_name (name);
5455 p = name + strlen (name);
5456 for (i = 0; i < 4; ++i)
5458 sprintf (p, "%.2x", checksum[i]);
5459 p += 2;
5462 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5463 comdat_symbol_number = 0;
5466 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5468 static int
5469 is_type_die (die)
5470 dw_die_ref die;
5472 switch (die->die_tag)
5474 case DW_TAG_array_type:
5475 case DW_TAG_class_type:
5476 case DW_TAG_enumeration_type:
5477 case DW_TAG_pointer_type:
5478 case DW_TAG_reference_type:
5479 case DW_TAG_string_type:
5480 case DW_TAG_structure_type:
5481 case DW_TAG_subroutine_type:
5482 case DW_TAG_union_type:
5483 case DW_TAG_ptr_to_member_type:
5484 case DW_TAG_set_type:
5485 case DW_TAG_subrange_type:
5486 case DW_TAG_base_type:
5487 case DW_TAG_const_type:
5488 case DW_TAG_file_type:
5489 case DW_TAG_packed_type:
5490 case DW_TAG_volatile_type:
5491 return 1;
5492 default:
5493 return 0;
5497 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5498 Basically, we want to choose the bits that are likely to be shared between
5499 compilations (types) and leave out the bits that are specific to individual
5500 compilations (functions). */
5502 static int
5503 is_comdat_die (c)
5504 dw_die_ref c;
5506 #if 1
5507 /* I think we want to leave base types and __vtbl_ptr_type in the
5508 main CU, as we do for stabs. The advantage is a greater
5509 likelihood of sharing between objects that don't include headers
5510 in the same order (and therefore would put the base types in a
5511 different comdat). jason 8/28/00 */
5512 if (c->die_tag == DW_TAG_base_type)
5513 return 0;
5515 if (c->die_tag == DW_TAG_pointer_type
5516 || c->die_tag == DW_TAG_reference_type
5517 || c->die_tag == DW_TAG_const_type
5518 || c->die_tag == DW_TAG_volatile_type)
5520 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5521 return t ? is_comdat_die (t) : 0;
5523 #endif
5525 return is_type_die (c);
5528 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5529 compilation unit. */
5531 static int
5532 is_symbol_die (c)
5533 dw_die_ref c;
5535 if (is_type_die (c))
5536 return 1;
5537 if (get_AT (c, DW_AT_declaration)
5538 && ! get_AT (c, DW_AT_specification))
5539 return 1;
5540 return 0;
5543 static char *
5544 gen_internal_sym ()
5546 char buf[256];
5547 static int label_num;
5548 ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++);
5549 return xstrdup (buf);
5552 /* Assign symbols to all worthy DIEs under DIE. */
5554 static void
5555 assign_symbol_names (die)
5556 register dw_die_ref die;
5558 register dw_die_ref c;
5560 if (is_symbol_die (die))
5562 if (comdat_symbol_id)
5564 char *p = alloca (strlen (comdat_symbol_id) + 64);
5565 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5566 comdat_symbol_id, comdat_symbol_number++);
5567 die->die_symbol = xstrdup (p);
5569 else
5570 die->die_symbol = gen_internal_sym ();
5573 for (c = die->die_child; c != NULL; c = c->die_sib)
5574 assign_symbol_names (c);
5577 /* Traverse the DIE (which is always comp_unit_die), and set up
5578 additional compilation units for each of the include files we see
5579 bracketed by BINCL/EINCL. */
5581 static void
5582 break_out_includes (die)
5583 register dw_die_ref die;
5585 dw_die_ref *ptr;
5586 register dw_die_ref unit = NULL;
5587 limbo_die_node *node;
5589 for (ptr = &(die->die_child); *ptr; )
5591 register dw_die_ref c = *ptr;
5593 if (c->die_tag == DW_TAG_GNU_BINCL
5594 || c->die_tag == DW_TAG_GNU_EINCL
5595 || (unit && is_comdat_die (c)))
5597 /* This DIE is for a secondary CU; remove it from the main one. */
5598 *ptr = c->die_sib;
5600 if (c->die_tag == DW_TAG_GNU_BINCL)
5602 unit = push_new_compile_unit (unit, c);
5603 free_die (c);
5605 else if (c->die_tag == DW_TAG_GNU_EINCL)
5607 unit = pop_compile_unit (unit);
5608 free_die (c);
5610 else
5611 add_child_die (unit, c);
5613 else
5615 /* Leave this DIE in the main CU. */
5616 ptr = &(c->die_sib);
5617 continue;
5621 #if 0
5622 /* We can only use this in debugging, since the frontend doesn't check
5623 to make sure that we leave every include file we enter. */
5624 if (unit != NULL)
5625 abort ();
5626 #endif
5628 assign_symbol_names (die);
5629 for (node = limbo_die_list; node; node = node->next)
5631 compute_section_prefix (node->die);
5632 assign_symbol_names (node->die);
5636 /* Traverse the DIE and add a sibling attribute if it may have the
5637 effect of speeding up access to siblings. To save some space,
5638 avoid generating sibling attributes for DIE's without children. */
5640 static void
5641 add_sibling_attributes (die)
5642 register dw_die_ref die;
5644 register dw_die_ref c;
5646 if (die->die_tag != DW_TAG_compile_unit
5647 && die->die_sib && die->die_child != NULL)
5648 /* Add the sibling link to the front of the attribute list. */
5649 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5651 for (c = die->die_child; c != NULL; c = c->die_sib)
5652 add_sibling_attributes (c);
5655 /* The format of each DIE (and its attribute value pairs)
5656 is encoded in an abbreviation table. This routine builds the
5657 abbreviation table and assigns a unique abbreviation id for
5658 each abbreviation entry. The children of each die are visited
5659 recursively. */
5661 static void
5662 build_abbrev_table (die)
5663 register dw_die_ref die;
5665 register unsigned long abbrev_id;
5666 register unsigned long n_alloc;
5667 register dw_die_ref c;
5668 register dw_attr_ref d_attr, a_attr;
5670 /* Scan the DIE references, and mark as external any that refer to
5671 DIEs from other CUs (i.e. those which are not marked). */
5672 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5674 if (AT_class (d_attr) == dw_val_class_die_ref
5675 && AT_ref (d_attr)->die_mark == 0)
5677 if (AT_ref (d_attr)->die_symbol == 0)
5678 abort ();
5679 set_AT_ref_external (d_attr, 1);
5683 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5685 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5687 if (abbrev->die_tag == die->die_tag)
5689 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5691 a_attr = abbrev->die_attr;
5692 d_attr = die->die_attr;
5694 while (a_attr != NULL && d_attr != NULL)
5696 if ((a_attr->dw_attr != d_attr->dw_attr)
5697 || (value_format (a_attr) != value_format (d_attr)))
5698 break;
5700 a_attr = a_attr->dw_attr_next;
5701 d_attr = d_attr->dw_attr_next;
5704 if (a_attr == NULL && d_attr == NULL)
5705 break;
5710 if (abbrev_id >= abbrev_die_table_in_use)
5712 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5714 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5715 abbrev_die_table
5716 = (dw_die_ref *) xrealloc (abbrev_die_table,
5717 sizeof (dw_die_ref) * n_alloc);
5719 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5720 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5721 abbrev_die_table_allocated = n_alloc;
5724 ++abbrev_die_table_in_use;
5725 abbrev_die_table[abbrev_id] = die;
5728 die->die_abbrev = abbrev_id;
5729 for (c = die->die_child; c != NULL; c = c->die_sib)
5730 build_abbrev_table (c);
5733 /* Return the size of a string, including the null byte.
5735 This used to treat backslashes as escapes, and hence they were not included
5736 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5737 which treats a backslash as a backslash, escaping it if necessary, and hence
5738 we must include them in the count. */
5740 static unsigned long
5741 size_of_string (str)
5742 register const char *str;
5744 return strlen (str) + 1;
5747 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5749 static int
5750 constant_size (value)
5751 long unsigned value;
5753 int log;
5755 if (value == 0)
5756 log = 0;
5757 else
5758 log = floor_log2 (value);
5760 log = log / 8;
5761 log = 1 << (floor_log2 (log) + 1);
5763 return log;
5766 /* Return the size of a DIE, as it is represented in the
5767 .debug_info section. */
5769 static unsigned long
5770 size_of_die (die)
5771 register dw_die_ref die;
5773 register unsigned long size = 0;
5774 register dw_attr_ref a;
5776 size += size_of_uleb128 (die->die_abbrev);
5777 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5779 switch (AT_class (a))
5781 case dw_val_class_addr:
5782 size += DWARF2_ADDR_SIZE;
5783 break;
5784 case dw_val_class_loc:
5786 register unsigned long lsize = size_of_locs (AT_loc (a));
5788 /* Block length. */
5789 size += constant_size (lsize);
5790 size += lsize;
5792 break;
5793 case dw_val_class_const:
5794 size += size_of_sleb128 (AT_int (a));
5795 break;
5796 case dw_val_class_unsigned_const:
5797 size += constant_size (AT_unsigned (a));
5798 break;
5799 case dw_val_class_long_long:
5800 size += 1 + 8; /* block */
5801 break;
5802 case dw_val_class_float:
5803 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5804 break;
5805 case dw_val_class_flag:
5806 size += 1;
5807 break;
5808 case dw_val_class_die_ref:
5809 size += DWARF_OFFSET_SIZE;
5810 break;
5811 case dw_val_class_fde_ref:
5812 size += DWARF_OFFSET_SIZE;
5813 break;
5814 case dw_val_class_lbl_id:
5815 size += DWARF2_ADDR_SIZE;
5816 break;
5817 case dw_val_class_lbl_offset:
5818 size += DWARF_OFFSET_SIZE;
5819 break;
5820 case dw_val_class_str:
5821 size += size_of_string (AT_string (a));
5822 break;
5823 default:
5824 abort ();
5828 return size;
5831 /* Size the debugging information associated with a given DIE.
5832 Visits the DIE's children recursively. Updates the global
5833 variable next_die_offset, on each time through. Uses the
5834 current value of next_die_offset to update the die_offset
5835 field in each DIE. */
5837 static void
5838 calc_die_sizes (die)
5839 dw_die_ref die;
5841 register dw_die_ref c;
5842 die->die_offset = next_die_offset;
5843 next_die_offset += size_of_die (die);
5845 for (c = die->die_child; c != NULL; c = c->die_sib)
5846 calc_die_sizes (c);
5848 if (die->die_child != NULL)
5849 /* Count the null byte used to terminate sibling lists. */
5850 next_die_offset += 1;
5853 /* Set the marks for a die and its children. We do this so
5854 that we know whether or not a reference needs to use FORM_ref_addr; only
5855 DIEs in the same CU will be marked. We used to clear out the offset
5856 and use that as the flag, but ran into ordering problems. */
5858 static void
5859 mark_dies (die)
5860 dw_die_ref die;
5862 register dw_die_ref c;
5863 die->die_mark = 1;
5864 for (c = die->die_child; c; c = c->die_sib)
5865 mark_dies (c);
5868 /* Clear the marks for a die and its children. */
5870 static void
5871 unmark_dies (die)
5872 dw_die_ref die;
5874 register dw_die_ref c;
5875 die->die_mark = 0;
5876 for (c = die->die_child; c; c = c->die_sib)
5877 unmark_dies (c);
5880 /* Return the size of the line information prolog generated for the
5881 compilation unit. */
5883 static unsigned long
5884 size_of_line_prolog ()
5886 register unsigned long size;
5887 register unsigned long ft_index;
5889 size = DWARF_LINE_PROLOG_HEADER_SIZE;
5891 /* Count the size of the table giving number of args for each
5892 standard opcode. */
5893 size += DWARF_LINE_OPCODE_BASE - 1;
5895 /* Include directory table is empty (at present). Count only the
5896 null byte used to terminate the table. */
5897 size += 1;
5899 for (ft_index = 1; ft_index < decl_file_table.in_use; ++ft_index)
5901 /* File name entry. */
5902 size += size_of_string (decl_file_table.table[ft_index]);
5904 /* Include directory index. */
5905 size += size_of_uleb128 (0);
5907 /* Modification time. */
5908 size += size_of_uleb128 (0);
5910 /* File length in bytes. */
5911 size += size_of_uleb128 (0);
5914 /* Count the file table terminator. */
5915 size += 1;
5916 return size;
5919 /* Return the size of the .debug_pubnames table generated for the
5920 compilation unit. */
5922 static unsigned long
5923 size_of_pubnames ()
5925 register unsigned long size;
5926 register unsigned i;
5928 size = DWARF_PUBNAMES_HEADER_SIZE;
5929 for (i = 0; i < pubname_table_in_use; ++i)
5931 register pubname_ref p = &pubname_table[i];
5932 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5935 size += DWARF_OFFSET_SIZE;
5936 return size;
5939 /* Return the size of the information in the .debug_aranges section. */
5941 static unsigned long
5942 size_of_aranges ()
5944 register unsigned long size;
5946 size = DWARF_ARANGES_HEADER_SIZE;
5948 /* Count the address/length pair for this compilation unit. */
5949 size += 2 * DWARF2_ADDR_SIZE;
5950 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5952 /* Count the two zero words used to terminated the address range table. */
5953 size += 2 * DWARF2_ADDR_SIZE;
5954 return size;
5957 /* Select the encoding of an attribute value. */
5959 static enum dwarf_form
5960 value_format (a)
5961 dw_attr_ref a;
5963 switch (a->dw_attr_val.val_class)
5965 case dw_val_class_addr:
5966 return DW_FORM_addr;
5967 case dw_val_class_loc:
5968 switch (constant_size (size_of_locs (AT_loc (a))))
5970 case 1:
5971 return DW_FORM_block1;
5972 case 2:
5973 return DW_FORM_block2;
5974 default:
5975 abort ();
5977 case dw_val_class_const:
5978 return DW_FORM_sdata;
5979 case dw_val_class_unsigned_const:
5980 switch (constant_size (AT_unsigned (a)))
5982 case 1:
5983 return DW_FORM_data1;
5984 case 2:
5985 return DW_FORM_data2;
5986 case 4:
5987 return DW_FORM_data4;
5988 case 8:
5989 return DW_FORM_data8;
5990 default:
5991 abort ();
5993 case dw_val_class_long_long:
5994 return DW_FORM_block1;
5995 case dw_val_class_float:
5996 return DW_FORM_block1;
5997 case dw_val_class_flag:
5998 return DW_FORM_flag;
5999 case dw_val_class_die_ref:
6000 if (AT_ref_external (a))
6001 return DW_FORM_ref_addr;
6002 else
6003 return DW_FORM_ref;
6004 case dw_val_class_fde_ref:
6005 return DW_FORM_data;
6006 case dw_val_class_lbl_id:
6007 return DW_FORM_addr;
6008 case dw_val_class_lbl_offset:
6009 return DW_FORM_data;
6010 case dw_val_class_str:
6011 return DW_FORM_string;
6012 default:
6013 abort ();
6017 /* Output the encoding of an attribute value. */
6019 static void
6020 output_value_format (a)
6021 dw_attr_ref a;
6023 enum dwarf_form form = value_format (a);
6025 output_uleb128 (form);
6026 if (flag_debug_asm)
6027 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
6029 fputc ('\n', asm_out_file);
6032 /* Output the .debug_abbrev section which defines the DIE abbreviation
6033 table. */
6035 static void
6036 output_abbrev_section ()
6038 unsigned long abbrev_id;
6040 dw_attr_ref a_attr;
6041 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6043 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6045 output_uleb128 (abbrev_id);
6046 if (flag_debug_asm)
6047 fprintf (asm_out_file, " (abbrev code)");
6049 fputc ('\n', asm_out_file);
6050 output_uleb128 (abbrev->die_tag);
6051 if (flag_debug_asm)
6052 fprintf (asm_out_file, " (TAG: %s)",
6053 dwarf_tag_name (abbrev->die_tag));
6055 fputc ('\n', asm_out_file);
6056 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP,
6057 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
6059 if (flag_debug_asm)
6060 fprintf (asm_out_file, "\t%s %s",
6061 ASM_COMMENT_START,
6062 (abbrev->die_child != NULL
6063 ? "DW_children_yes" : "DW_children_no"));
6065 fputc ('\n', asm_out_file);
6067 for (a_attr = abbrev->die_attr; a_attr != NULL;
6068 a_attr = a_attr->dw_attr_next)
6070 output_uleb128 (a_attr->dw_attr);
6071 if (flag_debug_asm)
6072 fprintf (asm_out_file, " (%s)",
6073 dwarf_attr_name (a_attr->dw_attr));
6075 fputc ('\n', asm_out_file);
6076 output_value_format (a_attr);
6079 fprintf (asm_out_file, "%s0,0\n", ASM_BYTE_OP);
6082 /* Terminate the table. */
6083 fprintf (asm_out_file, "%s0\n", ASM_BYTE_OP);
6086 /* Output a symbol we can use to refer to this DIE from another CU. */
6088 static inline void
6089 output_die_symbol (die)
6090 register dw_die_ref die;
6092 char *sym = die->die_symbol;
6094 if (sym == 0)
6095 return;
6097 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6098 /* We make these global, not weak; if the target doesn't support
6099 .linkonce, it doesn't support combining the sections, so debugging
6100 will break. */
6101 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
6102 ASM_OUTPUT_LABEL (asm_out_file, sym);
6105 /* Output a symbolic (i.e. FORM_ref_addr) reference to TARGET_DIE. */
6107 static inline void
6108 output_symbolic_ref (target_die)
6109 dw_die_ref target_die;
6111 char *sym = target_die->die_symbol;
6113 if (sym == 0)
6114 abort ();
6116 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, sym);
6119 /* Output the DIE and its attributes. Called recursively to generate
6120 the definitions of each child DIE. */
6122 static void
6123 output_die (die)
6124 register dw_die_ref die;
6126 register dw_attr_ref a;
6127 register dw_die_ref c;
6128 register unsigned long size;
6130 /* If someone in another CU might refer to us, set up a symbol for
6131 them to point to. */
6132 if (die->die_symbol)
6133 output_die_symbol (die);
6135 output_uleb128 (die->die_abbrev);
6136 if (flag_debug_asm)
6137 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
6138 die->die_offset, dwarf_tag_name (die->die_tag));
6140 fputc ('\n', asm_out_file);
6142 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6144 switch (AT_class (a))
6146 case dw_val_class_addr:
6147 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
6148 break;
6150 case dw_val_class_loc:
6151 size = size_of_locs (AT_loc (a));
6153 /* Output the block length for this list of location operations. */
6154 switch (constant_size (size))
6156 case 1:
6157 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
6158 break;
6159 case 2:
6160 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
6161 break;
6162 default:
6163 abort ();
6166 if (flag_debug_asm)
6167 fprintf (asm_out_file, "\t%s %s",
6168 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6170 fputc ('\n', asm_out_file);
6172 output_loc_sequence (AT_loc (a));
6173 break;
6175 case dw_val_class_const:
6176 /* ??? It would be slightly more efficient to use a scheme like is
6177 used for unsigned constants below, but gdb 4.x does not sign
6178 extend. Gdb 5.x does sign extend. */
6179 output_sleb128 (AT_int (a));
6180 break;
6182 case dw_val_class_unsigned_const:
6183 switch (constant_size (AT_unsigned (a)))
6185 case 1:
6186 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
6187 break;
6188 case 2:
6189 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
6190 break;
6191 case 4:
6192 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
6193 break;
6194 case 8:
6195 ASM_OUTPUT_DWARF_DATA8 (asm_out_file, AT_unsigned (a));
6196 break;
6197 default:
6198 abort ();
6200 break;
6202 case dw_val_class_long_long:
6203 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
6204 if (flag_debug_asm)
6205 fprintf (asm_out_file, "\t%s %s",
6206 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6208 fputc ('\n', asm_out_file);
6209 ASM_OUTPUT_DWARF_CONST_DOUBLE (asm_out_file,
6210 a->dw_attr_val.v.val_long_long.hi,
6211 a->dw_attr_val.v.val_long_long.low);
6213 if (flag_debug_asm)
6214 fprintf (asm_out_file,
6215 "\t%s long long constant", ASM_COMMENT_START);
6217 fputc ('\n', asm_out_file);
6218 break;
6220 case dw_val_class_float:
6222 register unsigned int i;
6223 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6224 a->dw_attr_val.v.val_float.length * 4);
6225 if (flag_debug_asm)
6226 fprintf (asm_out_file, "\t%s %s",
6227 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6229 fputc ('\n', asm_out_file);
6230 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
6232 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
6233 a->dw_attr_val.v.val_float.array[i]);
6234 if (flag_debug_asm)
6235 fprintf (asm_out_file, "\t%s fp constant word %u",
6236 ASM_COMMENT_START, i);
6238 fputc ('\n', asm_out_file);
6240 break;
6243 case dw_val_class_flag:
6244 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
6245 break;
6247 case dw_val_class_die_ref:
6248 if (AT_ref_external (a))
6249 output_symbolic_ref (AT_ref (a));
6250 else if (AT_ref (a)->die_offset == 0)
6251 abort ();
6252 else
6253 ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
6254 break;
6256 case dw_val_class_fde_ref:
6258 char l1[20];
6259 ASM_GENERATE_INTERNAL_LABEL
6260 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
6261 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
6262 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
6264 break;
6266 case dw_val_class_lbl_id:
6267 ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
6268 break;
6270 case dw_val_class_lbl_offset:
6271 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
6272 break;
6274 case dw_val_class_str:
6275 if (flag_debug_asm)
6276 ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
6277 else
6278 ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
6279 (int) strlen (AT_string (a)) + 1);
6280 break;
6282 default:
6283 abort ();
6286 if (AT_class (a) != dw_val_class_loc
6287 && AT_class (a) != dw_val_class_long_long
6288 && AT_class (a) != dw_val_class_float)
6290 if (flag_debug_asm)
6291 fprintf (asm_out_file, "\t%s %s",
6292 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6294 fputc ('\n', asm_out_file);
6298 for (c = die->die_child; c != NULL; c = c->die_sib)
6299 output_die (c);
6301 if (die->die_child != NULL)
6303 /* Add null byte to terminate sibling list. */
6304 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6305 if (flag_debug_asm)
6306 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
6307 ASM_COMMENT_START, die->die_offset);
6309 fputc ('\n', asm_out_file);
6313 /* Output the compilation unit that appears at the beginning of the
6314 .debug_info section, and precedes the DIE descriptions. */
6316 static void
6317 output_compilation_unit_header ()
6319 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
6320 if (flag_debug_asm)
6321 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
6322 ASM_COMMENT_START);
6324 fputc ('\n', asm_out_file);
6325 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6326 if (flag_debug_asm)
6327 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
6329 fputc ('\n', asm_out_file);
6330 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
6331 if (flag_debug_asm)
6332 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
6333 ASM_COMMENT_START);
6335 fputc ('\n', asm_out_file);
6336 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6337 if (flag_debug_asm)
6338 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
6340 fputc ('\n', asm_out_file);
6343 /* Output the compilation unit DIE and its children. */
6345 static void
6346 output_comp_unit (die)
6347 dw_die_ref die;
6349 const char *secname;
6351 if (die->die_child == 0)
6352 return;
6354 /* Mark all the DIEs in this CU so we know which get local refs. */
6355 mark_dies (die);
6357 build_abbrev_table (die);
6359 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6360 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6361 calc_die_sizes (die);
6363 if (die->die_symbol)
6365 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6366 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6367 secname = tmp;
6368 die->die_symbol = NULL;
6370 else
6371 secname = (const char *) DEBUG_INFO_SECTION;
6373 /* Output debugging information. */
6374 fputc ('\n', asm_out_file);
6375 ASM_OUTPUT_SECTION (asm_out_file, secname);
6376 output_compilation_unit_header ();
6377 output_die (die);
6379 /* Leave the marks on the main CU, so we can check them in
6380 output_pubnames. */
6381 if (die->die_symbol)
6382 unmark_dies (die);
6385 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6386 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6387 argument list, and maybe the scope. */
6389 static const char *
6390 dwarf2_name (decl, scope)
6391 tree decl;
6392 int scope;
6394 return (*decl_printable_name) (decl, scope ? 1 : 0);
6397 /* Add a new entry to .debug_pubnames if appropriate. */
6399 static void
6400 add_pubname (decl, die)
6401 tree decl;
6402 dw_die_ref die;
6404 pubname_ref p;
6406 if (! TREE_PUBLIC (decl))
6407 return;
6409 if (pubname_table_in_use == pubname_table_allocated)
6411 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6412 pubname_table = (pubname_ref) xrealloc
6413 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6416 p = &pubname_table[pubname_table_in_use++];
6417 p->die = die;
6419 p->name = xstrdup (dwarf2_name (decl, 1));
6422 /* Output the public names table used to speed up access to externally
6423 visible names. For now, only generate entries for externally
6424 visible procedures. */
6426 static void
6427 output_pubnames ()
6429 register unsigned i;
6430 register unsigned long pubnames_length = size_of_pubnames ();
6432 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
6434 if (flag_debug_asm)
6435 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
6436 ASM_COMMENT_START);
6438 fputc ('\n', asm_out_file);
6439 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6441 if (flag_debug_asm)
6442 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6444 fputc ('\n', asm_out_file);
6445 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6446 if (flag_debug_asm)
6447 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6448 ASM_COMMENT_START);
6450 fputc ('\n', asm_out_file);
6451 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
6452 if (flag_debug_asm)
6453 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
6455 fputc ('\n', asm_out_file);
6456 for (i = 0; i < pubname_table_in_use; ++i)
6458 register pubname_ref pub = &pubname_table[i];
6460 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6461 if (pub->die->die_mark == 0)
6462 abort ();
6464 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
6465 if (flag_debug_asm)
6466 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
6468 fputc ('\n', asm_out_file);
6470 if (flag_debug_asm)
6472 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
6473 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
6475 else
6477 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
6478 (int) strlen (pub->name) + 1);
6481 fputc ('\n', asm_out_file);
6484 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
6485 fputc ('\n', asm_out_file);
6488 /* Add a new entry to .debug_aranges if appropriate. */
6490 static void
6491 add_arange (decl, die)
6492 tree decl;
6493 dw_die_ref die;
6495 if (! DECL_SECTION_NAME (decl))
6496 return;
6498 if (arange_table_in_use == arange_table_allocated)
6500 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6501 arange_table
6502 = (arange_ref) xrealloc (arange_table,
6503 arange_table_allocated * sizeof (dw_die_ref));
6506 arange_table[arange_table_in_use++] = die;
6509 /* Output the information that goes into the .debug_aranges table.
6510 Namely, define the beginning and ending address range of the
6511 text section generated for this compilation unit. */
6513 static void
6514 output_aranges ()
6516 register unsigned i;
6517 register unsigned long aranges_length = size_of_aranges ();
6519 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
6520 if (flag_debug_asm)
6521 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
6522 ASM_COMMENT_START);
6524 fputc ('\n', asm_out_file);
6525 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6526 if (flag_debug_asm)
6527 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6529 fputc ('\n', asm_out_file);
6530 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6531 if (flag_debug_asm)
6532 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6533 ASM_COMMENT_START);
6535 fputc ('\n', asm_out_file);
6536 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6537 if (flag_debug_asm)
6538 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
6540 fputc ('\n', asm_out_file);
6541 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6542 if (flag_debug_asm)
6543 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
6544 ASM_COMMENT_START);
6546 fputc ('\n', asm_out_file);
6548 /* We need to align to twice the pointer size here. */
6549 if (DWARF_ARANGES_PAD_SIZE)
6551 /* Pad using a 2 bytes word so that padding is correct
6552 for any pointer size. */
6553 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
6554 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6555 fprintf (asm_out_file, ",0");
6556 if (flag_debug_asm)
6557 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
6558 ASM_COMMENT_START, 2 * DWARF2_ADDR_SIZE);
6561 fputc ('\n', asm_out_file);
6562 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
6563 if (flag_debug_asm)
6564 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6566 fputc ('\n', asm_out_file);
6567 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
6568 text_section_label);
6569 if (flag_debug_asm)
6570 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6572 fputc ('\n', asm_out_file);
6573 for (i = 0; i < arange_table_in_use; ++i)
6575 dw_die_ref die = arange_table[i];
6577 /* We shouldn't see aranges for DIEs outside of the main CU. */
6578 if (die->die_mark == 0)
6579 abort ();
6581 if (die->die_tag == DW_TAG_subprogram)
6582 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
6583 else
6585 /* A static variable; extract the symbol from DW_AT_location.
6586 Note that this code isn't currently hit, as we only emit
6587 aranges for functions (jason 9/23/99). */
6589 dw_attr_ref a = get_AT (die, DW_AT_location);
6590 dw_loc_descr_ref loc;
6591 if (! a || AT_class (a) != dw_val_class_loc)
6592 abort ();
6594 loc = AT_loc (a);
6595 if (loc->dw_loc_opc != DW_OP_addr)
6596 abort ();
6598 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
6599 loc->dw_loc_oprnd1.v.val_addr);
6602 if (flag_debug_asm)
6603 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6605 fputc ('\n', asm_out_file);
6606 if (die->die_tag == DW_TAG_subprogram)
6607 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
6608 get_AT_low_pc (die));
6609 else
6610 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
6611 get_AT_unsigned (die, DW_AT_byte_size));
6613 if (flag_debug_asm)
6614 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6616 fputc ('\n', asm_out_file);
6619 /* Output the terminator words. */
6620 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6621 fputc ('\n', asm_out_file);
6622 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6623 fputc ('\n', asm_out_file);
6627 /* Data structure containing information about input files. */
6628 struct file_info
6630 char *path; /* Complete file name. */
6631 char *fname; /* File name part. */
6632 int length; /* Length of entire string. */
6633 int file_idx; /* Index in input file table. */
6634 int dir_idx; /* Index in directory table. */
6637 /* Data structure containing information about directories with source
6638 files. */
6639 struct dir_info
6641 char *path; /* Path including directory name. */
6642 int length; /* Path length. */
6643 int prefix; /* Index of directory entry which is a prefix. */
6644 int nbytes; /* Total number of bytes in all file names excluding
6645 paths. */
6646 int count; /* Number of files in this directory. */
6647 int dir_idx; /* Index of directory used as base. */
6648 int used; /* Used in the end? */
6651 /* Callback function for file_info comparison. We sort by looking at
6652 the directories in the path. */
6653 static int
6654 file_info_cmp (p1, p2)
6655 const void *p1;
6656 const void *p2;
6658 const struct file_info *s1 = p1;
6659 const struct file_info *s2 = p2;
6660 unsigned char *cp1;
6661 unsigned char *cp2;
6663 /* Take care of file names without directories. */
6664 if (s1->path == s1->fname)
6665 return -1;
6666 else if (s2->path == s2->fname)
6667 return 1;
6669 cp1 = (unsigned char *) s1->path;
6670 cp2 = (unsigned char *) s2->path;
6672 while (1)
6674 ++cp1;
6675 ++cp2;
6676 /* Reached the end of the first path? */
6677 if (cp1 == (unsigned char *) s1->fname)
6678 /* It doesn't really matter in which order files from the
6679 same directory are sorted in. Therefore don't test for
6680 the second path reaching the end. */
6681 return -1;
6682 else if (cp2 == (unsigned char *) s2->fname)
6683 return 1;
6685 /* Character of current path component the same? */
6686 if (*cp1 != *cp2)
6687 return *cp1 - *cp2;
6691 /* Compute the maximum prefix of P2 appearing also in P1. Entire
6692 directory names must match. */
6693 static int prefix_of PARAMS ((struct dir_info *, struct dir_info *));
6694 static int
6695 prefix_of (p1, p2)
6696 struct dir_info *p1;
6697 struct dir_info *p2;
6699 char *s1 = p1->path;
6700 char *s2 = p2->path;
6701 int len = p1->length < p2->length ? p1->length : p2->length;
6703 while (*s1 == *s2 && s1 < p1->path + len)
6704 ++s1, ++s2;
6706 if (*s1 == '/' && *s2 == '/')
6707 /* The whole of P1 is the prefix. */
6708 return p1->length;
6710 /* Go back to the last directory component. */
6711 while (s1 > p1->path)
6712 if (*--s1 == '/')
6713 return s1 - p1->path + 1;
6715 return 0;
6718 /* Output the directory table and the file name table. We try to minimize
6719 the total amount of memory needed. A heuristic is used to avoid large
6720 slowdowns with many input files. */
6721 static void
6722 output_file_names ()
6724 struct file_info *files;
6725 struct dir_info *dirs;
6726 int *saved;
6727 int *savehere;
6728 int *backmap;
6729 int ndirs;
6730 int idx_offset;
6731 int i;
6732 int idx;
6734 /* Allocate the various arrays we need. */
6735 files = (struct file_info *) alloca (line_file_table.in_use
6736 * sizeof (struct file_info));
6737 dirs = (struct dir_info *) alloca (line_file_table.in_use * 2
6738 * sizeof (struct dir_info));
6740 /* Sort the file names. */
6741 for (i = 1; i < (int) line_file_table.in_use; ++i)
6743 char *f;
6745 /* Skip all leading "./". */
6746 f = line_file_table.table[i];
6747 while (f[0] == '.' && f[1] == '/')
6748 f += 2;
6750 /* Create a new array entry. */
6751 files[i].path = f;
6752 files[i].length = strlen (f);
6753 files[i].file_idx = i;
6755 /* Search for the file name part. */
6756 f = strrchr (f, '/');
6757 files[i].fname = f == NULL ? files[i].path : f + 1;
6759 qsort (files + 1, line_file_table.in_use - 1, sizeof (files[0]),
6760 file_info_cmp);
6762 /* Find all the different directories used. */
6763 dirs[0].path = files[1].path;
6764 dirs[0].length = files[1].fname - files[1].path;
6765 dirs[0].prefix = -1;
6766 dirs[0].nbytes = files[1].length - dirs[1].length + 1;
6767 dirs[0].count = 1;
6768 dirs[0].dir_idx = 0;
6769 dirs[0].used = 0;
6770 files[1].dir_idx = 0;
6771 ndirs = 1;
6773 for (i = 2; i < (int) line_file_table.in_use; ++i)
6774 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6775 && memcmp (dirs[ndirs - 1].path, files[i].path,
6776 dirs[ndirs - 1].length) == 0)
6778 /* Same directory as last entry. */
6779 files[i].dir_idx = ndirs - 1;
6780 dirs[ndirs - 1].nbytes += files[i].length - dirs[ndirs - 1].length + 1;
6781 ++dirs[ndirs - 1].count;
6783 else
6785 int j;
6786 int max_idx;
6787 int max_len;
6789 /* This is a new directory. */
6790 dirs[ndirs].path = files[i].path;
6791 dirs[ndirs].length = files[i].fname - files[i].path;
6792 dirs[ndirs].nbytes = files[i].length - dirs[i].length + 1;
6793 dirs[ndirs].count = 1;
6794 dirs[ndirs].dir_idx = ndirs;
6795 dirs[ndirs].used = 0;
6796 files[i].dir_idx = ndirs;
6798 /* Search for a prefix. */
6799 max_len = 0;
6800 max_idx = 0;
6801 for (j = 0; j < ndirs; ++j)
6802 if (dirs[j].length > max_len)
6804 int this_len = prefix_of (&dirs[j], &dirs[ndirs]);
6806 if (this_len > max_len)
6808 max_len = this_len;
6809 max_idx = j;
6813 /* Remember the prefix. If this is a known prefix simply
6814 remember the index. Otherwise we will have to create an
6815 artificial entry. */
6816 if (max_len == dirs[max_idx].length)
6817 /* This is our prefix. */
6818 dirs[ndirs].prefix = max_idx;
6819 else if (max_len > 0)
6821 /* Create an entry without associated file. Since we have
6822 to keep the dirs array sorted (means, entries with paths
6823 which come first) we have to move the new entry in the
6824 place of the old one. */
6825 dirs[++ndirs] = dirs[max_idx];
6827 /* We don't have to set .path. */
6828 dirs[max_idx].length = max_len;
6829 dirs[max_idx].nbytes = 0;
6830 dirs[max_idx].count = 0;
6831 dirs[max_idx].dir_idx = ndirs;
6832 dirs[max_idx].used = 0;
6833 dirs[max_idx].prefix = dirs[ndirs].prefix;
6835 dirs[ndirs - 1].prefix = dirs[ndirs].prefix = max_idx;
6837 else
6838 dirs[ndirs].prefix = -1;
6840 ++ndirs;
6843 /* Now to the actual work. We have to find a subset of the
6844 directories which allow expressing the file name using references
6845 to the directory table with the least amount of characters. We
6846 do not do an exhaustive search where we would have to check out
6847 every combination of every single possible prefix. Instead we
6848 use a heuristic which provides nearly optimal results in most
6849 cases and never is much off. */
6850 saved = (int *) alloca (ndirs * sizeof (int));
6851 savehere = (int *) alloca (ndirs * sizeof (int));
6853 memset (saved, '\0', ndirs * sizeof (saved[0]));
6854 for (i = 0; i < ndirs; ++i)
6856 int j;
6857 int total;
6859 /* We can always safe some space for the current directory. But
6860 this does not mean it will be enough to justify adding the
6861 directory. */
6862 savehere[i] = dirs[i].length;
6863 total = (savehere[i] - saved[i]) * dirs[i].count;
6865 for (j = i + 1; j < ndirs; ++j)
6867 savehere[j] = 0;
6869 if (saved[j] < dirs[i].length)
6871 /* Determine whether the dirs[i] path is a prefix of the
6872 dirs[j] path. */
6873 int k;
6875 k = dirs[j].prefix;
6876 while (k != -1 && k != i)
6877 k = dirs[k].prefix;
6879 if (k == i)
6881 /* Yes it is. We can possibly safe some memory but
6882 writing the filenames in dirs[j] relative to
6883 dirs[i]. */
6884 savehere[j] = dirs[i].length;
6885 total += (savehere[j] - saved[j]) * dirs[j].count;
6890 /* Check whether we can safe enough to justify adding the dirs[i]
6891 directory. */
6892 if (total > dirs[i].length + 1)
6894 /* It's worthwhile adding. */
6895 for (j = i; j < ndirs; ++j)
6896 if (savehere[j] > 0)
6898 /* Remember how much we saved for this directory so far. */
6899 saved[j] = savehere[j];
6901 /* Remember the prefix directory. */
6902 dirs[j].dir_idx = i;
6907 /* We have to emit them in the order they appear in the line_file_table
6908 array since the index is used in the debug info generation. To
6909 do this efficiently we generate a back-mapping of the indices
6910 first. */
6911 backmap = (int *) alloca (line_file_table.in_use * sizeof (int));
6912 for (i = 1; i < (int) line_file_table.in_use; ++i)
6914 backmap[files[i].file_idx] = i;
6915 /* Mark this directory as used. */
6916 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6919 /* That was it. We are ready to emit the information. First the
6920 directory name table. Here we have to make sure that the first
6921 actually emitted directory name has the index one. Zero is
6922 reserved for the current working directory. Make sure we do not
6923 confuse these indices with the one for the constructed table
6924 (even though most of the time they are identical). */
6925 idx = 1;
6926 idx_offset = dirs[0].length > 0 ? 1 : 0;
6927 for (i = 1 - idx_offset; i < ndirs; ++i)
6928 if (dirs[i].used != 0)
6930 dirs[i].used = idx++;
6932 if (flag_debug_asm)
6934 ASM_OUTPUT_DWARF_NSTRING (asm_out_file,
6935 dirs[i].path, dirs[i].length - 1);
6936 fprintf (asm_out_file, "%s Directory Entry: 0x%x\n",
6937 ASM_COMMENT_START, dirs[i].used);
6939 else
6941 ASM_OUTPUT_ASCII (asm_out_file, dirs[i].path, dirs[i].length - 1);
6942 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6943 fputc ('\n', asm_out_file);
6946 /* Correct the index for the current working directory entry if it
6947 exists. */
6948 if (idx_offset == 0)
6949 dirs[0].used = 0;
6950 /* Terminate the directory name array. */
6951 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6952 if (flag_debug_asm)
6953 fprintf (asm_out_file, "\t%s End directory table", ASM_COMMENT_START);
6954 fputc ('\n', asm_out_file);
6956 /* Now write all the file names. */
6957 for (i = 1; i < (int) line_file_table.in_use; ++i)
6959 int file_idx = backmap[i];
6960 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6962 if (flag_debug_asm)
6964 ASM_OUTPUT_DWARF_STRING (asm_out_file,
6965 files[file_idx].path
6966 + dirs[dir_idx].length);
6967 fprintf (asm_out_file, "%s File Entry: 0x%x\n",
6968 ASM_COMMENT_START, i);
6970 else
6971 ASM_OUTPUT_ASCII (asm_out_file,
6972 files[file_idx].path + dirs[dir_idx].length,
6973 (files[file_idx].length
6974 - dirs[dir_idx].length) + 1);
6976 /* Include directory index. */
6977 output_uleb128 (dirs[dir_idx].used);
6978 fputc ('\n', asm_out_file);
6980 /* Modification time. */
6981 output_uleb128 (0);
6982 fputc ('\n', asm_out_file);
6984 /* File length in bytes. */
6985 output_uleb128 (0);
6986 fputc ('\n', asm_out_file);
6989 /* Terminate the file name table */
6990 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6991 if (flag_debug_asm)
6992 fprintf (asm_out_file, "\t%s End file name table", ASM_COMMENT_START);
6993 fputc ('\n', asm_out_file);
6997 /* Output the source line number correspondence information. This
6998 information goes into the .debug_line section. */
7000 static void
7001 output_line_info ()
7003 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7004 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7005 register unsigned opc;
7006 register unsigned n_op_args;
7007 register unsigned long lt_index;
7008 register unsigned long current_line;
7009 register long line_offset;
7010 register long line_delta;
7011 register unsigned long current_file;
7012 register unsigned long function;
7014 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
7015 if (flag_debug_asm)
7016 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
7017 ASM_COMMENT_START);
7019 fputc ('\n', asm_out_file);
7020 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
7021 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
7022 if (flag_debug_asm)
7023 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
7025 fputc ('\n', asm_out_file);
7026 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
7027 if (flag_debug_asm)
7028 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
7030 fputc ('\n', asm_out_file);
7031 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
7032 if (flag_debug_asm)
7033 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
7034 ASM_COMMENT_START);
7036 fputc ('\n', asm_out_file);
7037 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
7038 if (flag_debug_asm)
7039 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
7040 ASM_COMMENT_START);
7042 fputc ('\n', asm_out_file);
7043 fprintf (asm_out_file, "%s%d", ASM_BYTE_OP, DWARF_LINE_BASE);
7044 if (flag_debug_asm)
7045 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
7046 ASM_COMMENT_START);
7048 fputc ('\n', asm_out_file);
7049 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
7050 if (flag_debug_asm)
7051 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
7052 ASM_COMMENT_START);
7054 fputc ('\n', asm_out_file);
7055 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
7056 if (flag_debug_asm)
7057 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
7059 fputc ('\n', asm_out_file);
7060 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
7062 switch (opc)
7064 case DW_LNS_advance_pc:
7065 case DW_LNS_advance_line:
7066 case DW_LNS_set_file:
7067 case DW_LNS_set_column:
7068 case DW_LNS_fixed_advance_pc:
7069 n_op_args = 1;
7070 break;
7071 default:
7072 n_op_args = 0;
7073 break;
7075 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
7076 if (flag_debug_asm)
7077 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
7078 ASM_COMMENT_START, opc, n_op_args);
7079 fputc ('\n', asm_out_file);
7082 /* Write out the information about the files we use. */
7083 output_file_names ();
7085 /* We used to set the address register to the first location in the text
7086 section here, but that didn't accomplish anything since we already
7087 have a line note for the opening brace of the first function. */
7089 /* Generate the line number to PC correspondence table, encoded as
7090 a series of state machine operations. */
7091 current_file = 1;
7092 current_line = 1;
7093 strcpy (prev_line_label, text_section_label);
7094 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7096 register dw_line_info_ref line_info = &line_info_table[lt_index];
7098 #if 0
7099 /* Disable this optimization for now; GDB wants to see two line notes
7100 at the beginning of a function so it can find the end of the
7101 prologue. */
7103 /* Don't emit anything for redundant notes. Just updating the
7104 address doesn't accomplish anything, because we already assume
7105 that anything after the last address is this line. */
7106 if (line_info->dw_line_num == current_line
7107 && line_info->dw_file_num == current_file)
7108 continue;
7109 #endif
7111 /* Emit debug info for the address of the current line, choosing
7112 the encoding that uses the least amount of space. */
7113 /* ??? Unfortunately, we have little choice here currently, and must
7114 always use the most general form. Gcc does not know the address
7115 delta itself, so we can't use DW_LNS_advance_pc. There are no known
7116 dwarf2 aware assemblers at this time, so we can't use any special
7117 pseudo ops that would allow the assembler to optimally encode this for
7118 us. Many ports do have length attributes which will give an upper
7119 bound on the address range. We could perhaps use length attributes
7120 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
7121 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7122 if (0)
7124 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7125 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7126 if (flag_debug_asm)
7127 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7128 ASM_COMMENT_START);
7130 fputc ('\n', asm_out_file);
7131 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
7132 fputc ('\n', asm_out_file);
7134 else
7136 /* This can handle any delta. This takes
7137 4+DWARF2_ADDR_SIZE bytes. */
7138 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7139 if (flag_debug_asm)
7140 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7141 ASM_COMMENT_START);
7142 fputc ('\n', asm_out_file);
7143 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7144 fputc ('\n', asm_out_file);
7145 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7146 fputc ('\n', asm_out_file);
7147 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7148 fputc ('\n', asm_out_file);
7150 strcpy (prev_line_label, line_label);
7152 /* Emit debug info for the source file of the current line, if
7153 different from the previous line. */
7154 if (line_info->dw_file_num != current_file)
7156 current_file = line_info->dw_file_num;
7157 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
7158 if (flag_debug_asm)
7159 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
7161 fputc ('\n', asm_out_file);
7162 output_uleb128 (current_file);
7163 if (flag_debug_asm)
7164 fprintf (asm_out_file, " (\"%s\")",
7165 line_file_table.table[current_file]);
7167 fputc ('\n', asm_out_file);
7170 /* Emit debug info for the current line number, choosing the encoding
7171 that uses the least amount of space. */
7172 if (line_info->dw_line_num != current_line)
7174 line_offset = line_info->dw_line_num - current_line;
7175 line_delta = line_offset - DWARF_LINE_BASE;
7176 current_line = line_info->dw_line_num;
7177 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7179 /* This can handle deltas from -10 to 234, using the current
7180 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7181 takes 1 byte. */
7182 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
7183 DWARF_LINE_OPCODE_BASE + line_delta);
7184 if (flag_debug_asm)
7185 fprintf (asm_out_file,
7186 "\t%s line %ld", ASM_COMMENT_START, current_line);
7188 fputc ('\n', asm_out_file);
7190 else
7192 /* This can handle any delta. This takes at least 4 bytes,
7193 depending on the value being encoded. */
7194 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
7195 if (flag_debug_asm)
7196 fprintf (asm_out_file, "\t%s advance to line %ld",
7197 ASM_COMMENT_START, current_line);
7199 fputc ('\n', asm_out_file);
7200 output_sleb128 (line_offset);
7201 fputc ('\n', asm_out_file);
7202 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7203 if (flag_debug_asm)
7204 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7205 fputc ('\n', asm_out_file);
7208 else
7210 /* We still need to start a new row, so output a copy insn. */
7211 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7212 if (flag_debug_asm)
7213 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7214 fputc ('\n', asm_out_file);
7218 /* Emit debug info for the address of the end of the function. */
7219 if (0)
7221 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7222 if (flag_debug_asm)
7223 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7224 ASM_COMMENT_START);
7226 fputc ('\n', asm_out_file);
7227 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
7228 fputc ('\n', asm_out_file);
7230 else
7232 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7233 if (flag_debug_asm)
7234 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
7235 fputc ('\n', asm_out_file);
7236 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7237 fputc ('\n', asm_out_file);
7238 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7239 fputc ('\n', asm_out_file);
7240 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
7241 fputc ('\n', asm_out_file);
7244 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7245 if (flag_debug_asm)
7246 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
7248 fputc ('\n', asm_out_file);
7249 output_uleb128 (1);
7250 fputc ('\n', asm_out_file);
7251 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
7252 fputc ('\n', asm_out_file);
7254 function = 0;
7255 current_file = 1;
7256 current_line = 1;
7257 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7259 register dw_separate_line_info_ref line_info
7260 = &separate_line_info_table[lt_index];
7262 #if 0
7263 /* Don't emit anything for redundant notes. */
7264 if (line_info->dw_line_num == current_line
7265 && line_info->dw_file_num == current_file
7266 && line_info->function == function)
7267 goto cont;
7268 #endif
7270 /* Emit debug info for the address of the current line. If this is
7271 a new function, or the first line of a function, then we need
7272 to handle it differently. */
7273 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7274 lt_index);
7275 if (function != line_info->function)
7277 function = line_info->function;
7279 /* Set the address register to the first line in the function */
7280 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7281 if (flag_debug_asm)
7282 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7283 ASM_COMMENT_START);
7285 fputc ('\n', asm_out_file);
7286 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7287 fputc ('\n', asm_out_file);
7288 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7289 fputc ('\n', asm_out_file);
7290 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7291 fputc ('\n', asm_out_file);
7293 else
7295 /* ??? See the DW_LNS_advance_pc comment above. */
7296 if (0)
7298 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7299 if (flag_debug_asm)
7300 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7301 ASM_COMMENT_START);
7303 fputc ('\n', asm_out_file);
7304 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
7305 prev_line_label);
7306 fputc ('\n', asm_out_file);
7308 else
7310 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7311 if (flag_debug_asm)
7312 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7313 ASM_COMMENT_START);
7314 fputc ('\n', asm_out_file);
7315 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7316 fputc ('\n', asm_out_file);
7317 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7318 fputc ('\n', asm_out_file);
7319 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7320 fputc ('\n', asm_out_file);
7323 strcpy (prev_line_label, line_label);
7325 /* Emit debug info for the source file of the current line, if
7326 different from the previous line. */
7327 if (line_info->dw_file_num != current_file)
7329 current_file = line_info->dw_file_num;
7330 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
7331 if (flag_debug_asm)
7332 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
7334 fputc ('\n', asm_out_file);
7335 output_uleb128 (current_file);
7336 if (flag_debug_asm)
7337 fprintf (asm_out_file, " (\"%s\")",
7338 line_file_table.table[current_file]);
7340 fputc ('\n', asm_out_file);
7343 /* Emit debug info for the current line number, choosing the encoding
7344 that uses the least amount of space. */
7345 if (line_info->dw_line_num != current_line)
7347 line_offset = line_info->dw_line_num - current_line;
7348 line_delta = line_offset - DWARF_LINE_BASE;
7349 current_line = line_info->dw_line_num;
7350 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7352 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
7353 DWARF_LINE_OPCODE_BASE + line_delta);
7354 if (flag_debug_asm)
7355 fprintf (asm_out_file,
7356 "\t%s line %ld", ASM_COMMENT_START, current_line);
7358 fputc ('\n', asm_out_file);
7360 else
7362 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
7363 if (flag_debug_asm)
7364 fprintf (asm_out_file, "\t%s advance to line %ld",
7365 ASM_COMMENT_START, current_line);
7367 fputc ('\n', asm_out_file);
7368 output_sleb128 (line_offset);
7369 fputc ('\n', asm_out_file);
7370 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7371 if (flag_debug_asm)
7372 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7373 fputc ('\n', asm_out_file);
7376 else
7378 /* We still need to start a new row, so output a copy insn. */
7379 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7380 if (flag_debug_asm)
7381 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7382 fputc ('\n', asm_out_file);
7385 #if 0
7386 cont:
7387 #endif
7388 ++lt_index;
7390 /* If we're done with a function, end its sequence. */
7391 if (lt_index == separate_line_info_table_in_use
7392 || separate_line_info_table[lt_index].function != function)
7394 current_file = 1;
7395 current_line = 1;
7397 /* Emit debug info for the address of the end of the function. */
7398 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7399 if (0)
7401 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7402 if (flag_debug_asm)
7403 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7404 ASM_COMMENT_START);
7406 fputc ('\n', asm_out_file);
7407 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
7408 prev_line_label);
7409 fputc ('\n', asm_out_file);
7411 else
7413 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7414 if (flag_debug_asm)
7415 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7416 ASM_COMMENT_START);
7417 fputc ('\n', asm_out_file);
7418 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7419 fputc ('\n', asm_out_file);
7420 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7421 fputc ('\n', asm_out_file);
7422 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7423 fputc ('\n', asm_out_file);
7426 /* Output the marker for the end of this sequence. */
7427 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7428 if (flag_debug_asm)
7429 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
7430 ASM_COMMENT_START);
7432 fputc ('\n', asm_out_file);
7433 output_uleb128 (1);
7434 fputc ('\n', asm_out_file);
7435 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
7436 fputc ('\n', asm_out_file);
7440 /* Output the marker for the end of the line number info. */
7441 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
7444 /* Given a pointer to a tree node for some base type, return a pointer to
7445 a DIE that describes the given type.
7447 This routine must only be called for GCC type nodes that correspond to
7448 Dwarf base (fundamental) types. */
7450 static dw_die_ref
7451 base_type_die (type)
7452 register tree type;
7454 register dw_die_ref base_type_result;
7455 register const char *type_name;
7456 register enum dwarf_type encoding;
7457 register tree name = TYPE_NAME (type);
7459 if (TREE_CODE (type) == ERROR_MARK
7460 || TREE_CODE (type) == VOID_TYPE)
7461 return 0;
7463 if (name)
7465 if (TREE_CODE (name) == TYPE_DECL)
7466 name = DECL_NAME (name);
7468 type_name = IDENTIFIER_POINTER (name);
7470 else
7471 type_name = "__unknown__";
7473 switch (TREE_CODE (type))
7475 case INTEGER_TYPE:
7476 /* Carefully distinguish the C character types, without messing
7477 up if the language is not C. Note that we check only for the names
7478 that contain spaces; other names might occur by coincidence in other
7479 languages. */
7480 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7481 && (type == char_type_node
7482 || ! strcmp (type_name, "signed char")
7483 || ! strcmp (type_name, "unsigned char"))))
7485 if (TREE_UNSIGNED (type))
7486 encoding = DW_ATE_unsigned;
7487 else
7488 encoding = DW_ATE_signed;
7489 break;
7491 /* else fall through. */
7493 case CHAR_TYPE:
7494 /* GNU Pascal/Ada CHAR type. Not used in C. */
7495 if (TREE_UNSIGNED (type))
7496 encoding = DW_ATE_unsigned_char;
7497 else
7498 encoding = DW_ATE_signed_char;
7499 break;
7501 case REAL_TYPE:
7502 encoding = DW_ATE_float;
7503 break;
7505 /* Dwarf2 doesn't know anything about complex ints, so use
7506 a user defined type for it. */
7507 case COMPLEX_TYPE:
7508 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7509 encoding = DW_ATE_complex_float;
7510 else
7511 encoding = DW_ATE_lo_user;
7512 break;
7514 case BOOLEAN_TYPE:
7515 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7516 encoding = DW_ATE_boolean;
7517 break;
7519 default:
7520 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
7523 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
7524 if (demangle_name_func)
7525 type_name = (*demangle_name_func) (type_name);
7527 add_AT_string (base_type_result, DW_AT_name, type_name);
7528 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7529 int_size_in_bytes (type));
7530 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7532 return base_type_result;
7535 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7536 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7537 a given type is generally the same as the given type, except that if the
7538 given type is a pointer or reference type, then the root type of the given
7539 type is the root type of the "basis" type for the pointer or reference
7540 type. (This definition of the "root" type is recursive.) Also, the root
7541 type of a `const' qualified type or a `volatile' qualified type is the
7542 root type of the given type without the qualifiers. */
7544 static tree
7545 root_type (type)
7546 register tree type;
7548 if (TREE_CODE (type) == ERROR_MARK)
7549 return error_mark_node;
7551 switch (TREE_CODE (type))
7553 case ERROR_MARK:
7554 return error_mark_node;
7556 case POINTER_TYPE:
7557 case REFERENCE_TYPE:
7558 return type_main_variant (root_type (TREE_TYPE (type)));
7560 default:
7561 return type_main_variant (type);
7565 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7566 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7568 static inline int
7569 is_base_type (type)
7570 register tree type;
7572 switch (TREE_CODE (type))
7574 case ERROR_MARK:
7575 case VOID_TYPE:
7576 case INTEGER_TYPE:
7577 case REAL_TYPE:
7578 case COMPLEX_TYPE:
7579 case BOOLEAN_TYPE:
7580 case CHAR_TYPE:
7581 return 1;
7583 case SET_TYPE:
7584 case ARRAY_TYPE:
7585 case RECORD_TYPE:
7586 case UNION_TYPE:
7587 case QUAL_UNION_TYPE:
7588 case ENUMERAL_TYPE:
7589 case FUNCTION_TYPE:
7590 case METHOD_TYPE:
7591 case POINTER_TYPE:
7592 case REFERENCE_TYPE:
7593 case FILE_TYPE:
7594 case OFFSET_TYPE:
7595 case LANG_TYPE:
7596 case VECTOR_TYPE:
7597 return 0;
7599 default:
7600 abort ();
7603 return 0;
7606 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7607 entry that chains various modifiers in front of the given type. */
7609 static dw_die_ref
7610 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7611 register tree type;
7612 register int is_const_type;
7613 register int is_volatile_type;
7614 register dw_die_ref context_die;
7616 register enum tree_code code = TREE_CODE (type);
7617 register dw_die_ref mod_type_die = NULL;
7618 register dw_die_ref sub_die = NULL;
7619 register tree item_type = NULL;
7621 if (code != ERROR_MARK)
7623 type = build_type_variant (type, is_const_type, is_volatile_type);
7625 mod_type_die = lookup_type_die (type);
7626 if (mod_type_die)
7627 return mod_type_die;
7629 /* Handle C typedef types. */
7630 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7631 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
7633 tree dtype = TREE_TYPE (TYPE_NAME (type));
7634 if (type == dtype)
7636 /* For a named type, use the typedef. */
7637 gen_type_die (type, context_die);
7638 mod_type_die = lookup_type_die (type);
7641 else if (is_const_type < TYPE_READONLY (dtype)
7642 || is_volatile_type < TYPE_VOLATILE (dtype))
7643 /* cv-unqualified version of named type. Just use the unnamed
7644 type to which it refers. */
7645 mod_type_die
7646 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
7647 is_const_type, is_volatile_type,
7648 context_die);
7649 /* Else cv-qualified version of named type; fall through. */
7652 if (mod_type_die)
7653 /* OK. */
7655 else if (is_const_type)
7657 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7658 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7660 else if (is_volatile_type)
7662 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7663 sub_die = modified_type_die (type, 0, 0, context_die);
7665 else if (code == POINTER_TYPE)
7667 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7668 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7669 #if 0
7670 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7671 #endif
7672 item_type = TREE_TYPE (type);
7674 else if (code == REFERENCE_TYPE)
7676 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7677 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7678 #if 0
7679 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7680 #endif
7681 item_type = TREE_TYPE (type);
7683 else if (is_base_type (type))
7684 mod_type_die = base_type_die (type);
7685 else
7687 gen_type_die (type, context_die);
7689 /* We have to get the type_main_variant here (and pass that to the
7690 `lookup_type_die' routine) because the ..._TYPE node we have
7691 might simply be a *copy* of some original type node (where the
7692 copy was created to help us keep track of typedef names) and
7693 that copy might have a different TYPE_UID from the original
7694 ..._TYPE node. */
7695 mod_type_die = lookup_type_die (type_main_variant (type));
7696 if (mod_type_die == NULL)
7697 abort ();
7701 equate_type_number_to_die (type, mod_type_die);
7702 if (item_type)
7703 /* We must do this after the equate_type_number_to_die call, in case
7704 this is a recursive type. This ensures that the modified_type_die
7705 recursion will terminate even if the type is recursive. Recursive
7706 types are possible in Ada. */
7707 sub_die = modified_type_die (item_type,
7708 TYPE_READONLY (item_type),
7709 TYPE_VOLATILE (item_type),
7710 context_die);
7712 if (sub_die != NULL)
7713 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7715 return mod_type_die;
7718 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7719 an enumerated type. */
7721 static inline int
7722 type_is_enum (type)
7723 register tree type;
7725 return TREE_CODE (type) == ENUMERAL_TYPE;
7728 /* Return the register number described by a given RTL node. */
7730 static unsigned int
7731 reg_number (rtl)
7732 register rtx rtl;
7734 register unsigned regno = REGNO (rtl);
7736 if (regno >= FIRST_PSEUDO_REGISTER)
7738 warning ("internal regno botch: regno = %d\n", regno);
7739 regno = 0;
7742 regno = DBX_REGISTER_NUMBER (regno);
7743 return regno;
7746 /* Return a location descriptor that designates a machine register. */
7748 static dw_loc_descr_ref
7749 reg_loc_descriptor (rtl)
7750 register rtx rtl;
7752 register dw_loc_descr_ref loc_result = NULL;
7753 register unsigned reg = reg_number (rtl);
7755 if (reg <= 31)
7756 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7757 else
7758 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7760 return loc_result;
7763 /* Return a location descriptor that designates a constant. */
7765 static dw_loc_descr_ref
7766 int_loc_descriptor (i)
7767 HOST_WIDE_INT i;
7769 enum dwarf_location_atom op;
7771 /* Pick the smallest representation of a constant, rather than just
7772 defaulting to the LEB encoding. */
7773 if (i >= 0)
7775 if (i <= 31)
7776 op = DW_OP_lit0 + i;
7777 else if (i <= 0xff)
7778 op = DW_OP_const1u;
7779 else if (i <= 0xffff)
7780 op = DW_OP_const2u;
7781 else if (HOST_BITS_PER_WIDE_INT == 32
7782 || i <= 0xffffffff)
7783 op = DW_OP_const4u;
7784 else
7785 op = DW_OP_constu;
7787 else
7789 if (i >= -0x80)
7790 op = DW_OP_const1s;
7791 else if (i >= -0x8000)
7792 op = DW_OP_const2s;
7793 else if (HOST_BITS_PER_WIDE_INT == 32
7794 || i >= -0x80000000)
7795 op = DW_OP_const4s;
7796 else
7797 op = DW_OP_consts;
7800 return new_loc_descr (op, i, 0);
7803 /* Return a location descriptor that designates a base+offset location. */
7805 static dw_loc_descr_ref
7806 based_loc_descr (reg, offset)
7807 unsigned reg;
7808 long int offset;
7810 register dw_loc_descr_ref loc_result;
7811 /* For the "frame base", we use the frame pointer or stack pointer
7812 registers, since the RTL for local variables is relative to one of
7813 them. */
7814 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7815 ? HARD_FRAME_POINTER_REGNUM
7816 : STACK_POINTER_REGNUM);
7818 if (reg == fp_reg)
7819 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7820 else if (reg <= 31)
7821 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7822 else
7823 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7825 return loc_result;
7828 /* Return true if this RTL expression describes a base+offset calculation. */
7830 static inline int
7831 is_based_loc (rtl)
7832 register rtx rtl;
7834 return (GET_CODE (rtl) == PLUS
7835 && ((GET_CODE (XEXP (rtl, 0)) == REG
7836 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7839 /* The following routine converts the RTL for a variable or parameter
7840 (resident in memory) into an equivalent Dwarf representation of a
7841 mechanism for getting the address of that same variable onto the top of a
7842 hypothetical "address evaluation" stack.
7844 When creating memory location descriptors, we are effectively transforming
7845 the RTL for a memory-resident object into its Dwarf postfix expression
7846 equivalent. This routine recursively descends an RTL tree, turning
7847 it into Dwarf postfix code as it goes.
7849 MODE is the mode of the memory reference, needed to handle some
7850 autoincrement addressing modes. */
7852 static dw_loc_descr_ref
7853 mem_loc_descriptor (rtl, mode)
7854 register rtx rtl;
7855 enum machine_mode mode;
7857 dw_loc_descr_ref mem_loc_result = NULL;
7858 /* Note that for a dynamically sized array, the location we will generate a
7859 description of here will be the lowest numbered location which is
7860 actually within the array. That's *not* necessarily the same as the
7861 zeroth element of the array. */
7863 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7864 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7865 #endif
7867 switch (GET_CODE (rtl))
7869 case POST_INC:
7870 case POST_DEC:
7871 case POST_MODIFY:
7872 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7873 just fall into the SUBREG code. */
7875 /* Fall through. */
7877 case SUBREG:
7878 /* The case of a subreg may arise when we have a local (register)
7879 variable or a formal (register) parameter which doesn't quite fill
7880 up an entire register. For now, just assume that it is
7881 legitimate to make the Dwarf info refer to the whole register which
7882 contains the given subreg. */
7883 rtl = XEXP (rtl, 0);
7885 /* Fall through. */
7887 case REG:
7888 /* Whenever a register number forms a part of the description of the
7889 method for calculating the (dynamic) address of a memory resident
7890 object, DWARF rules require the register number be referred to as
7891 a "base register". This distinction is not based in any way upon
7892 what category of register the hardware believes the given register
7893 belongs to. This is strictly DWARF terminology we're dealing with
7894 here. Note that in cases where the location of a memory-resident
7895 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7896 OP_CONST (0)) the actual DWARF location descriptor that we generate
7897 may just be OP_BASEREG (basereg). This may look deceptively like
7898 the object in question was allocated to a register (rather than in
7899 memory) so DWARF consumers need to be aware of the subtle
7900 distinction between OP_REG and OP_BASEREG. */
7901 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7902 break;
7904 case MEM:
7905 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7906 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7907 break;
7909 case LABEL_REF:
7910 /* Some ports can transform a symbol ref into a label ref, because
7911 the symbol ref is too far away and has to be dumped into a constant
7912 pool. */
7913 case CONST:
7914 case SYMBOL_REF:
7915 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7916 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7917 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7918 break;
7920 case PRE_MODIFY:
7921 /* Extract the PLUS expression nested inside and fall into
7922 PLUS code bellow. */
7923 rtl = XEXP (rtl, 1);
7924 goto plus;
7926 case PRE_INC:
7927 case PRE_DEC:
7928 /* Turn these into a PLUS expression and fall into the PLUS code
7929 below. */
7930 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7931 GEN_INT (GET_CODE (rtl) == PRE_INC
7932 ? GET_MODE_UNIT_SIZE (mode)
7933 : -GET_MODE_UNIT_SIZE (mode)));
7935 /* Fall through. */
7937 case PLUS:
7938 plus:
7939 if (is_based_loc (rtl))
7940 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7941 INTVAL (XEXP (rtl, 1)));
7942 else
7944 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7946 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7947 && INTVAL (XEXP (rtl, 1)) >= 0)
7949 add_loc_descr (&mem_loc_result,
7950 new_loc_descr (DW_OP_plus_uconst,
7951 INTVAL (XEXP (rtl, 1)), 0));
7953 else
7955 add_loc_descr (&mem_loc_result,
7956 mem_loc_descriptor (XEXP (rtl, 1), mode));
7957 add_loc_descr (&mem_loc_result,
7958 new_loc_descr (DW_OP_plus, 0, 0));
7961 break;
7963 case MULT:
7964 /* If a pseudo-reg is optimized away, it is possible for it to
7965 be replaced with a MEM containing a multiply. */
7966 add_loc_descr (&mem_loc_result,
7967 mem_loc_descriptor (XEXP (rtl, 0), mode));
7968 add_loc_descr (&mem_loc_result,
7969 mem_loc_descriptor (XEXP (rtl, 1), mode));
7970 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7971 break;
7973 case CONST_INT:
7974 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7975 break;
7977 default:
7978 abort ();
7981 return mem_loc_result;
7984 /* Return a descriptor that describes the concatenation of two locations.
7985 This is typically a complex variable. */
7987 static dw_loc_descr_ref
7988 concat_loc_descriptor (x0, x1)
7989 register rtx x0, x1;
7991 dw_loc_descr_ref cc_loc_result = NULL;
7993 if (!is_pseudo_reg (x0)
7994 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7995 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7996 add_loc_descr (&cc_loc_result,
7997 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7999 if (!is_pseudo_reg (x1)
8000 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
8001 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
8002 add_loc_descr (&cc_loc_result,
8003 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
8005 return cc_loc_result;
8008 /* Output a proper Dwarf location descriptor for a variable or parameter
8009 which is either allocated in a register or in a memory location. For a
8010 register, we just generate an OP_REG and the register number. For a
8011 memory location we provide a Dwarf postfix expression describing how to
8012 generate the (dynamic) address of the object onto the address stack. */
8014 static dw_loc_descr_ref
8015 loc_descriptor (rtl)
8016 register rtx rtl;
8018 dw_loc_descr_ref loc_result = NULL;
8019 switch (GET_CODE (rtl))
8021 case SUBREG:
8022 /* The case of a subreg may arise when we have a local (register)
8023 variable or a formal (register) parameter which doesn't quite fill
8024 up an entire register. For now, just assume that it is
8025 legitimate to make the Dwarf info refer to the whole register which
8026 contains the given subreg. */
8027 rtl = XEXP (rtl, 0);
8029 /* Fall through. */
8031 case REG:
8032 loc_result = reg_loc_descriptor (rtl);
8033 break;
8035 case MEM:
8036 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
8037 break;
8039 case CONCAT:
8040 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
8041 break;
8043 default:
8044 abort ();
8047 return loc_result;
8050 /* Similar, but generate the descriptor from trees instead of rtl.
8051 This comes up particularly with variable length arrays. */
8053 static dw_loc_descr_ref
8054 loc_descriptor_from_tree (loc, addressp)
8055 tree loc;
8056 int addressp;
8058 dw_loc_descr_ref ret = NULL;
8059 int indirect_size = 0;
8060 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
8061 enum dwarf_location_atom op;
8063 /* ??? Most of the time we do not take proper care for sign/zero
8064 extending the values properly. Hopefully this won't be a real
8065 problem... */
8067 switch (TREE_CODE (loc))
8069 case ERROR_MARK:
8070 break;
8072 case WITH_RECORD_EXPR:
8073 /* This case involves extracting fields from an object to determine the
8074 position of other fields. We don't try to encode this here. The
8075 only user of this is Ada, which encodes the needed information using
8076 the names of types. */
8077 return ret;
8079 case VAR_DECL:
8080 case PARM_DECL:
8082 rtx rtl = rtl_for_decl_location (loc);
8083 enum machine_mode mode = DECL_MODE (loc);
8085 if (rtl == NULL_RTX)
8086 break;
8087 else if (CONSTANT_P (rtl))
8089 ret = new_loc_descr (DW_OP_addr, 0, 0);
8090 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8091 ret->dw_loc_oprnd1.v.val_addr = rtl;
8092 indirect_size = GET_MODE_SIZE (mode);
8094 else
8096 if (GET_CODE (rtl) == MEM)
8098 indirect_size = GET_MODE_SIZE (mode);
8099 rtl = XEXP (rtl, 0);
8101 ret = mem_loc_descriptor (rtl, mode);
8104 break;
8106 case INDIRECT_REF:
8107 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8108 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
8109 break;
8111 case NOP_EXPR:
8112 case CONVERT_EXPR:
8113 case NON_LVALUE_EXPR:
8114 case SAVE_EXPR:
8115 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
8117 case COMPONENT_REF:
8118 case BIT_FIELD_REF:
8119 case ARRAY_REF:
8121 tree obj, offset;
8122 HOST_WIDE_INT bitsize, bitpos, bytepos;
8123 enum machine_mode mode;
8124 int volatilep;
8125 unsigned int alignment;
8127 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
8128 &unsignedp, &volatilep, &alignment);
8129 ret = loc_descriptor_from_tree (obj, 1);
8131 if (offset != NULL_TREE)
8133 /* Variable offset. */
8134 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
8135 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8138 if (addressp)
8140 /* We cannot address anything not on a unit boundary. */
8141 if (bitpos % BITS_PER_UNIT != 0)
8142 abort ();
8144 else
8146 if (bitpos % BITS_PER_UNIT != 0
8147 || bitsize % BITS_PER_UNIT != 0)
8149 /* ??? We could handle this by loading and shifting etc.
8150 Wait until someone needs it before expending the effort. */
8151 abort ();
8154 indirect_size = bitsize / BITS_PER_UNIT;
8157 bytepos = bitpos / BITS_PER_UNIT;
8158 if (bytepos > 0)
8159 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8160 else if (bytepos < 0)
8162 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8163 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8165 break;
8168 case INTEGER_CST:
8169 if (host_integerp (loc, 0))
8170 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8171 break;
8173 case BIT_AND_EXPR:
8174 op = DW_OP_and;
8175 goto do_binop;
8176 case BIT_XOR_EXPR:
8177 op = DW_OP_xor;
8178 goto do_binop;
8179 case BIT_IOR_EXPR:
8180 op = DW_OP_or;
8181 goto do_binop;
8182 case TRUNC_DIV_EXPR:
8183 op = DW_OP_div;
8184 goto do_binop;
8185 case MINUS_EXPR:
8186 op = DW_OP_minus;
8187 goto do_binop;
8188 case TRUNC_MOD_EXPR:
8189 op = DW_OP_mod;
8190 goto do_binop;
8191 case MULT_EXPR:
8192 op = DW_OP_mul;
8193 goto do_binop;
8194 case LSHIFT_EXPR:
8195 op = DW_OP_shl;
8196 goto do_binop;
8197 case RSHIFT_EXPR:
8198 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8199 goto do_binop;
8200 case PLUS_EXPR:
8201 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8202 && host_integerp (TREE_OPERAND (loc, 1), 0))
8204 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8205 add_loc_descr (&ret,
8206 new_loc_descr (DW_OP_plus_uconst,
8207 tree_low_cst (TREE_OPERAND (loc, 1),
8209 0));
8210 break;
8212 op = DW_OP_plus;
8213 goto do_binop;
8214 case LE_EXPR:
8215 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8216 break;
8217 op = DW_OP_le;
8218 goto do_binop;
8219 case GE_EXPR:
8220 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8221 break;
8222 op = DW_OP_ge;
8223 goto do_binop;
8224 case LT_EXPR:
8225 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8226 break;
8227 op = DW_OP_lt;
8228 goto do_binop;
8229 case GT_EXPR:
8230 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8231 break;
8232 op = DW_OP_gt;
8233 goto do_binop;
8234 case EQ_EXPR:
8235 op = DW_OP_eq;
8236 goto do_binop;
8237 case NE_EXPR:
8238 op = DW_OP_ne;
8239 goto do_binop;
8241 do_binop:
8242 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8243 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
8244 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8245 break;
8247 case BIT_NOT_EXPR:
8248 op = DW_OP_not;
8249 goto do_unop;
8250 case ABS_EXPR:
8251 op = DW_OP_abs;
8252 goto do_unop;
8253 case NEGATE_EXPR:
8254 op = DW_OP_neg;
8255 goto do_unop;
8257 do_unop:
8258 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8259 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8260 break;
8262 case MAX_EXPR:
8263 loc = build (COND_EXPR, TREE_TYPE (loc),
8264 build (LT_EXPR, integer_type_node,
8265 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8266 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8267 /* FALLTHRU */
8269 case COND_EXPR:
8271 dw_loc_descr_ref bra_node, jump_node, tmp;
8273 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8274 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8275 add_loc_descr (&ret, bra_node);
8277 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8278 add_loc_descr (&ret, tmp);
8279 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8280 add_loc_descr (&ret, jump_node);
8282 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8283 add_loc_descr (&ret, tmp);
8284 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8285 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
8287 /* ??? Need a node to point the skip at. Use a nop. */
8288 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8289 add_loc_descr (&ret, tmp);
8290 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8291 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8293 break;
8295 default:
8296 abort ();
8299 /* If we can't fill the request for an address, die. */
8300 if (addressp && indirect_size == 0)
8301 abort ();
8303 /* If we've got an address and don't want one, dereference. */
8304 if (!addressp && indirect_size > 0)
8306 if (indirect_size > DWARF2_ADDR_SIZE)
8307 abort ();
8308 if (indirect_size == DWARF2_ADDR_SIZE)
8309 op = DW_OP_deref;
8310 else
8311 op = DW_OP_deref_size;
8312 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
8315 return ret;
8318 /* Given a value, round it up to the lowest multiple of `boundary'
8319 which is not less than the value itself. */
8321 static inline HOST_WIDE_INT
8322 ceiling (value, boundary)
8323 HOST_WIDE_INT value;
8324 unsigned int boundary;
8326 return (((value + boundary - 1) / boundary) * boundary);
8329 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8330 pointer to the declared type for the relevant field variable, or return
8331 `integer_type_node' if the given node turns out to be an
8332 ERROR_MARK node. */
8334 static inline tree
8335 field_type (decl)
8336 register tree decl;
8338 register tree type;
8340 if (TREE_CODE (decl) == ERROR_MARK)
8341 return integer_type_node;
8343 type = DECL_BIT_FIELD_TYPE (decl);
8344 if (type == NULL_TREE)
8345 type = TREE_TYPE (decl);
8347 return type;
8350 /* Given a pointer to a tree node, return the alignment in bits for
8351 it, or else return BITS_PER_WORD if the node actually turns out to
8352 be an ERROR_MARK node. */
8354 static inline unsigned
8355 simple_type_align_in_bits (type)
8356 register tree type;
8358 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8361 static inline unsigned
8362 simple_decl_align_in_bits (decl)
8363 register tree decl;
8365 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8368 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8369 node, return the size in bits for the type if it is a constant, or else
8370 return the alignment for the type if the type's size is not constant, or
8371 else return BITS_PER_WORD if the type actually turns out to be an
8372 ERROR_MARK node. */
8374 static inline unsigned HOST_WIDE_INT
8375 simple_type_size_in_bits (type)
8376 register tree type;
8378 tree type_size_tree;
8380 if (TREE_CODE (type) == ERROR_MARK)
8381 return BITS_PER_WORD;
8382 type_size_tree = TYPE_SIZE (type);
8384 if (type_size_tree == NULL_TREE)
8385 return 0;
8386 if (! host_integerp (type_size_tree, 1))
8387 return TYPE_ALIGN (type);
8388 return tree_low_cst (type_size_tree, 1);
8391 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
8392 return the byte offset of the lowest addressed byte of the "containing
8393 object" for the given FIELD_DECL, or return 0 if we are unable to
8394 determine what that offset is, either because the argument turns out to
8395 be a pointer to an ERROR_MARK node, or because the offset is actually
8396 variable. (We can't handle the latter case just yet). */
8398 static HOST_WIDE_INT
8399 field_byte_offset (decl)
8400 register tree decl;
8402 unsigned int type_align_in_bits;
8403 unsigned int decl_align_in_bits;
8404 unsigned HOST_WIDE_INT type_size_in_bits;
8405 HOST_WIDE_INT object_offset_in_bits;
8406 HOST_WIDE_INT object_offset_in_bytes;
8407 tree type;
8408 tree field_size_tree;
8409 HOST_WIDE_INT bitpos_int;
8410 HOST_WIDE_INT deepest_bitpos;
8411 unsigned HOST_WIDE_INT field_size_in_bits;
8413 if (TREE_CODE (decl) == ERROR_MARK)
8414 return 0;
8416 if (TREE_CODE (decl) != FIELD_DECL)
8417 abort ();
8419 type = field_type (decl);
8420 field_size_tree = DECL_SIZE (decl);
8422 /* The size could be unspecified if there was an error, or for
8423 a flexible array member. */
8424 if (! field_size_tree)
8425 field_size_tree = bitsize_zero_node;
8427 /* We cannot yet cope with fields whose positions are variable, so
8428 for now, when we see such things, we simply return 0. Someday, we may
8429 be able to handle such cases, but it will be damn difficult. */
8430 if (! host_integerp (bit_position (decl), 0))
8431 return 0;
8433 bitpos_int = int_bit_position (decl);
8435 /* If we don't know the size of the field, pretend it's a full word. */
8436 if (host_integerp (field_size_tree, 1))
8437 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8438 else
8439 field_size_in_bits = BITS_PER_WORD;
8441 type_size_in_bits = simple_type_size_in_bits (type);
8442 type_align_in_bits = simple_type_align_in_bits (type);
8443 decl_align_in_bits = simple_decl_align_in_bits (decl);
8445 /* Note that the GCC front-end doesn't make any attempt to keep track of
8446 the starting bit offset (relative to the start of the containing
8447 structure type) of the hypothetical "containing object" for a bit-
8448 field. Thus, when computing the byte offset value for the start of the
8449 "containing object" of a bit-field, we must deduce this information on
8450 our own. This can be rather tricky to do in some cases. For example,
8451 handling the following structure type definition when compiling for an
8452 i386/i486 target (which only aligns long long's to 32-bit boundaries)
8453 can be very tricky:
8455 struct S { int field1; long long field2:31; };
8457 Fortunately, there is a simple rule-of-thumb which can be
8458 used in such cases. When compiling for an i386/i486, GCC will allocate
8459 8 bytes for the structure shown above. It decides to do this based upon
8460 one simple rule for bit-field allocation. Quite simply, GCC allocates
8461 each "containing object" for each bit-field at the first (i.e. lowest
8462 addressed) legitimate alignment boundary (based upon the required
8463 minimum alignment for the declared type of the field) which it can
8464 possibly use, subject to the condition that there is still enough
8465 available space remaining in the containing object (when allocated at
8466 the selected point) to fully accommodate all of the bits of the
8467 bit-field itself. This simple rule makes it obvious why GCC allocates
8468 8 bytes for each object of the structure type shown above. When looking
8469 for a place to allocate the "containing object" for `field2', the
8470 compiler simply tries to allocate a 64-bit "containing object" at each
8471 successive 32-bit boundary (starting at zero) until it finds a place to
8472 allocate that 64- bit field such that at least 31 contiguous (and
8473 previously unallocated) bits remain within that selected 64 bit field.
8474 (As it turns out, for the example above, the compiler finds that it is
8475 OK to allocate the "containing object" 64-bit field at bit-offset zero
8476 within the structure type.) Here we attempt to work backwards from the
8477 limited set of facts we're given, and we try to deduce from those facts,
8478 where GCC must have believed that the containing object started (within
8479 the structure type). The value we deduce is then used (by the callers of
8480 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
8481 for fields (both bit-fields and, in the case of DW_AT_location, regular
8482 fields as well). */
8484 /* Figure out the bit-distance from the start of the structure to the
8485 "deepest" bit of the bit-field. */
8486 deepest_bitpos = bitpos_int + field_size_in_bits;
8488 /* This is the tricky part. Use some fancy footwork to deduce where the
8489 lowest addressed bit of the containing object must be. */
8490 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8492 /* Round up to type_align by default. This works best for bitfields. */
8493 object_offset_in_bits += type_align_in_bits - 1;
8494 object_offset_in_bits /= type_align_in_bits;
8495 object_offset_in_bits *= type_align_in_bits;
8497 if (object_offset_in_bits > bitpos_int)
8499 /* Sigh, the decl must be packed. */
8500 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8502 /* Round up to decl_align instead. */
8503 object_offset_in_bits += decl_align_in_bits - 1;
8504 object_offset_in_bits /= decl_align_in_bits;
8505 object_offset_in_bits *= decl_align_in_bits;
8508 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
8510 return object_offset_in_bytes;
8513 /* The following routines define various Dwarf attributes and any data
8514 associated with them. */
8516 /* Add a location description attribute value to a DIE.
8518 This emits location attributes suitable for whole variables and
8519 whole parameters. Note that the location attributes for struct fields are
8520 generated by the routine `data_member_location_attribute' below. */
8522 static void
8523 add_AT_location_description (die, attr_kind, rtl)
8524 dw_die_ref die;
8525 enum dwarf_attribute attr_kind;
8526 register rtx rtl;
8528 /* Handle a special case. If we are about to output a location descriptor
8529 for a variable or parameter which has been optimized out of existence,
8530 don't do that. A variable which has been optimized out
8531 of existence will have a DECL_RTL value which denotes a pseudo-reg.
8532 Currently, in some rare cases, variables can have DECL_RTL values which
8533 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
8534 elsewhere in the compiler. We treat such cases as if the variable(s) in
8535 question had been optimized out of existence. */
8537 if (is_pseudo_reg (rtl)
8538 || (GET_CODE (rtl) == MEM
8539 && is_pseudo_reg (XEXP (rtl, 0)))
8540 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
8541 references the internal argument pointer (a pseudo) in a function
8542 where all references to the internal argument pointer were
8543 eliminated via the optimizers. */
8544 || (GET_CODE (rtl) == MEM
8545 && GET_CODE (XEXP (rtl, 0)) == PLUS
8546 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
8547 || (GET_CODE (rtl) == CONCAT
8548 && is_pseudo_reg (XEXP (rtl, 0))
8549 && is_pseudo_reg (XEXP (rtl, 1))))
8550 return;
8552 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
8555 /* Attach the specialized form of location attribute used for data
8556 members of struct and union types. In the special case of a
8557 FIELD_DECL node which represents a bit-field, the "offset" part
8558 of this special location descriptor must indicate the distance
8559 in bytes from the lowest-addressed byte of the containing struct
8560 or union type to the lowest-addressed byte of the "containing
8561 object" for the bit-field. (See the `field_byte_offset' function
8562 above).. For any given bit-field, the "containing object" is a
8563 hypothetical object (of some integral or enum type) within which
8564 the given bit-field lives. The type of this hypothetical
8565 "containing object" is always the same as the declared type of
8566 the individual bit-field itself (for GCC anyway... the DWARF
8567 spec doesn't actually mandate this). Note that it is the size
8568 (in bytes) of the hypothetical "containing object" which will
8569 be given in the DW_AT_byte_size attribute for this bit-field.
8570 (See the `byte_size_attribute' function below.) It is also used
8571 when calculating the value of the DW_AT_bit_offset attribute.
8572 (See the `bit_offset_attribute' function below). */
8574 static void
8575 add_data_member_location_attribute (die, decl)
8576 register dw_die_ref die;
8577 register tree decl;
8579 register unsigned long offset;
8580 register dw_loc_descr_ref loc_descr;
8581 register enum dwarf_location_atom op;
8583 if (TREE_CODE (decl) == TREE_VEC)
8584 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8585 else
8586 offset = field_byte_offset (decl);
8588 /* The DWARF2 standard says that we should assume that the structure address
8589 is already on the stack, so we can specify a structure field address
8590 by using DW_OP_plus_uconst. */
8592 #ifdef MIPS_DEBUGGING_INFO
8593 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
8594 correctly. It works only if we leave the offset on the stack. */
8595 op = DW_OP_constu;
8596 #else
8597 op = DW_OP_plus_uconst;
8598 #endif
8600 loc_descr = new_loc_descr (op, offset, 0);
8601 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8604 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8605 does not have a "location" either in memory or in a register. These
8606 things can arise in GNU C when a constant is passed as an actual parameter
8607 to an inlined function. They can also arise in C++ where declared
8608 constants do not necessarily get memory "homes". */
8610 static void
8611 add_const_value_attribute (die, rtl)
8612 register dw_die_ref die;
8613 register rtx rtl;
8615 switch (GET_CODE (rtl))
8617 case CONST_INT:
8618 /* Note that a CONST_INT rtx could represent either an integer or a
8619 floating-point constant. A CONST_INT is used whenever the constant
8620 will fit into a single word. In all such cases, the original mode
8621 of the constant value is wiped out, and the CONST_INT rtx is
8622 assigned VOIDmode. */
8623 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
8624 break;
8626 case CONST_DOUBLE:
8627 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8628 floating-point constant. A CONST_DOUBLE is used whenever the
8629 constant requires more than one word in order to be adequately
8630 represented. We output CONST_DOUBLEs as blocks. */
8632 register enum machine_mode mode = GET_MODE (rtl);
8634 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8636 register unsigned length = GET_MODE_SIZE (mode) / 4;
8637 long *array = (long *) xmalloc (sizeof (long) * length);
8638 REAL_VALUE_TYPE rv;
8640 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8641 switch (mode)
8643 case SFmode:
8644 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8645 break;
8647 case DFmode:
8648 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8649 break;
8651 case XFmode:
8652 case TFmode:
8653 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8654 break;
8656 default:
8657 abort ();
8660 add_AT_float (die, DW_AT_const_value, length, array);
8662 else
8663 add_AT_long_long (die, DW_AT_const_value,
8664 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8666 break;
8668 case CONST_STRING:
8669 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8670 break;
8672 case SYMBOL_REF:
8673 case LABEL_REF:
8674 case CONST:
8675 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8676 break;
8678 case PLUS:
8679 /* In cases where an inlined instance of an inline function is passed
8680 the address of an `auto' variable (which is local to the caller) we
8681 can get a situation where the DECL_RTL of the artificial local
8682 variable (for the inlining) which acts as a stand-in for the
8683 corresponding formal parameter (of the inline function) will look
8684 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8685 exactly a compile-time constant expression, but it isn't the address
8686 of the (artificial) local variable either. Rather, it represents the
8687 *value* which the artificial local variable always has during its
8688 lifetime. We currently have no way to represent such quasi-constant
8689 values in Dwarf, so for now we just punt and generate nothing. */
8690 break;
8692 default:
8693 /* No other kinds of rtx should be possible here. */
8694 abort ();
8699 static rtx
8700 rtl_for_decl_location (decl)
8701 tree decl;
8703 register rtx rtl;
8705 /* Here we have to decide where we are going to say the parameter "lives"
8706 (as far as the debugger is concerned). We only have a couple of
8707 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8709 DECL_RTL normally indicates where the parameter lives during most of the
8710 activation of the function. If optimization is enabled however, this
8711 could be either NULL or else a pseudo-reg. Both of those cases indicate
8712 that the parameter doesn't really live anywhere (as far as the code
8713 generation parts of GCC are concerned) during most of the function's
8714 activation. That will happen (for example) if the parameter is never
8715 referenced within the function.
8717 We could just generate a location descriptor here for all non-NULL
8718 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8719 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8720 where DECL_RTL is NULL or is a pseudo-reg.
8722 Note however that we can only get away with using DECL_INCOMING_RTL as
8723 a backup substitute for DECL_RTL in certain limited cases. In cases
8724 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8725 we can be sure that the parameter was passed using the same type as it is
8726 declared to have within the function, and that its DECL_INCOMING_RTL
8727 points us to a place where a value of that type is passed.
8729 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8730 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8731 because in these cases DECL_INCOMING_RTL points us to a value of some
8732 type which is *different* from the type of the parameter itself. Thus,
8733 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8734 such cases, the debugger would end up (for example) trying to fetch a
8735 `float' from a place which actually contains the first part of a
8736 `double'. That would lead to really incorrect and confusing
8737 output at debug-time.
8739 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8740 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8741 are a couple of exceptions however. On little-endian machines we can
8742 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8743 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8744 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8745 when (on a little-endian machine) a non-prototyped function has a
8746 parameter declared to be of type `short' or `char'. In such cases,
8747 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8748 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8749 passed `int' value. If the debugger then uses that address to fetch
8750 a `short' or a `char' (on a little-endian machine) the result will be
8751 the correct data, so we allow for such exceptional cases below.
8753 Note that our goal here is to describe the place where the given formal
8754 parameter lives during most of the function's activation (i.e. between
8755 the end of the prologue and the start of the epilogue). We'll do that
8756 as best as we can. Note however that if the given formal parameter is
8757 modified sometime during the execution of the function, then a stack
8758 backtrace (at debug-time) will show the function as having been
8759 called with the *new* value rather than the value which was
8760 originally passed in. This happens rarely enough that it is not
8761 a major problem, but it *is* a problem, and I'd like to fix it.
8763 A future version of dwarf2out.c may generate two additional
8764 attributes for any given DW_TAG_formal_parameter DIE which will
8765 describe the "passed type" and the "passed location" for the
8766 given formal parameter in addition to the attributes we now
8767 generate to indicate the "declared type" and the "active
8768 location" for each parameter. This additional set of attributes
8769 could be used by debuggers for stack backtraces. Separately, note
8770 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8771 NULL also. This happens (for example) for inlined-instances of
8772 inline function formal parameters which are never referenced.
8773 This really shouldn't be happening. All PARM_DECL nodes should
8774 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8775 doesn't currently generate these values for inlined instances of
8776 inline function parameters, so when we see such cases, we are
8777 just out-of-luck for the time being (until integrate.c
8778 gets fixed). */
8780 /* Use DECL_RTL as the "location" unless we find something better. */
8781 rtl = DECL_RTL (decl);
8783 if (TREE_CODE (decl) == PARM_DECL)
8785 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8787 tree declared_type = type_main_variant (TREE_TYPE (decl));
8788 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8790 /* This decl represents a formal parameter which was optimized out.
8791 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8792 all* cases where (rtl == NULL_RTX) just below. */
8793 if (declared_type == passed_type)
8794 rtl = DECL_INCOMING_RTL (decl);
8795 else if (! BYTES_BIG_ENDIAN
8796 && TREE_CODE (declared_type) == INTEGER_TYPE
8797 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8798 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8799 rtl = DECL_INCOMING_RTL (decl);
8802 /* If the parm was passed in registers, but lives on the stack, then
8803 make a big endian correction if the mode of the type of the
8804 parameter is not the same as the mode of the rtl. */
8805 /* ??? This is the same series of checks that are made in dbxout.c before
8806 we reach the big endian correction code there. It isn't clear if all
8807 of these checks are necessary here, but keeping them all is the safe
8808 thing to do. */
8809 else if (GET_CODE (rtl) == MEM
8810 && XEXP (rtl, 0) != const0_rtx
8811 && ! CONSTANT_P (XEXP (rtl, 0))
8812 /* Not passed in memory. */
8813 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8814 /* Not passed by invisible reference. */
8815 && (GET_CODE (XEXP (rtl, 0)) != REG
8816 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8817 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8818 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8819 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8820 #endif
8822 /* Big endian correction check. */
8823 && BYTES_BIG_ENDIAN
8824 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8825 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8826 < UNITS_PER_WORD))
8828 int offset = (UNITS_PER_WORD
8829 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8830 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8831 plus_constant (XEXP (rtl, 0), offset));
8835 if (rtl != NULL_RTX)
8837 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8838 #ifdef LEAF_REG_REMAP
8839 if (current_function_uses_only_leaf_regs)
8840 leaf_renumber_regs_insn (rtl);
8841 #endif
8844 return rtl;
8847 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8848 data attribute for a variable or a parameter. We generate the
8849 DW_AT_const_value attribute only in those cases where the given variable
8850 or parameter does not have a true "location" either in memory or in a
8851 register. This can happen (for example) when a constant is passed as an
8852 actual argument in a call to an inline function. (It's possible that
8853 these things can crop up in other ways also.) Note that one type of
8854 constant value which can be passed into an inlined function is a constant
8855 pointer. This can happen for example if an actual argument in an inlined
8856 function call evaluates to a compile-time constant address. */
8858 static void
8859 add_location_or_const_value_attribute (die, decl)
8860 register dw_die_ref die;
8861 register tree decl;
8863 register rtx rtl;
8865 if (TREE_CODE (decl) == ERROR_MARK)
8866 return;
8868 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8869 abort ();
8871 rtl = rtl_for_decl_location (decl);
8872 if (rtl == NULL_RTX)
8873 return;
8875 switch (GET_CODE (rtl))
8877 case ADDRESSOF:
8878 /* The address of a variable that was optimized away; don't emit
8879 anything. */
8880 break;
8882 case CONST_INT:
8883 case CONST_DOUBLE:
8884 case CONST_STRING:
8885 case SYMBOL_REF:
8886 case LABEL_REF:
8887 case CONST:
8888 case PLUS:
8889 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8890 add_const_value_attribute (die, rtl);
8891 break;
8893 case MEM:
8894 case REG:
8895 case SUBREG:
8896 case CONCAT:
8897 add_AT_location_description (die, DW_AT_location, rtl);
8898 break;
8900 default:
8901 abort ();
8905 /* If we don't have a copy of this variable in memory for some reason (such
8906 as a C++ member constant that doesn't have an out-of-line definition),
8907 we should tell the debugger about the constant value. */
8909 static void
8910 tree_add_const_value_attribute (var_die, decl)
8911 dw_die_ref var_die;
8912 tree decl;
8914 tree init = DECL_INITIAL (decl);
8915 tree type = TREE_TYPE (decl);
8917 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8918 && initializer_constant_valid_p (init, type) == null_pointer_node)
8919 /* OK */;
8920 else
8921 return;
8923 switch (TREE_CODE (type))
8925 case INTEGER_TYPE:
8926 if (host_integerp (init, 0))
8927 add_AT_unsigned (var_die, DW_AT_const_value,
8928 TREE_INT_CST_LOW (init));
8929 else
8930 add_AT_long_long (var_die, DW_AT_const_value,
8931 TREE_INT_CST_HIGH (init),
8932 TREE_INT_CST_LOW (init));
8933 break;
8935 default:;
8939 /* Generate an DW_AT_name attribute given some string value to be included as
8940 the value of the attribute. */
8942 static inline void
8943 add_name_attribute (die, name_string)
8944 register dw_die_ref die;
8945 register const char *name_string;
8947 if (name_string != NULL && *name_string != 0)
8949 if (demangle_name_func)
8950 name_string = (*demangle_name_func) (name_string);
8952 add_AT_string (die, DW_AT_name, name_string);
8956 /* Given a tree node describing an array bound (either lower or upper) output
8957 a representation for that bound. */
8959 static void
8960 add_bound_info (subrange_die, bound_attr, bound)
8961 register dw_die_ref subrange_die;
8962 register enum dwarf_attribute bound_attr;
8963 register tree bound;
8965 /* If this is an Ada unconstrained array type, then don't emit any debug
8966 info because the array bounds are unknown. They are parameterized when
8967 the type is instantiated. */
8968 if (contains_placeholder_p (bound))
8969 return;
8971 switch (TREE_CODE (bound))
8973 case ERROR_MARK:
8974 return;
8976 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8977 case INTEGER_CST:
8978 if (! host_integerp (bound, 0)
8979 || (bound_attr == DW_AT_lower_bound
8980 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8981 || (is_fortran () && integer_onep (bound)))))
8982 /* use the default */
8984 else
8985 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8986 break;
8988 case CONVERT_EXPR:
8989 case NOP_EXPR:
8990 case NON_LVALUE_EXPR:
8991 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8992 break;
8994 case SAVE_EXPR:
8995 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8996 access the upper bound values may be bogus. If they refer to a
8997 register, they may only describe how to get at these values at the
8998 points in the generated code right after they have just been
8999 computed. Worse yet, in the typical case, the upper bound values
9000 will not even *be* computed in the optimized code (though the
9001 number of elements will), so these SAVE_EXPRs are entirely
9002 bogus. In order to compensate for this fact, we check here to see
9003 if optimization is enabled, and if so, we don't add an attribute
9004 for the (unknown and unknowable) upper bound. This should not
9005 cause too much trouble for existing (stupid?) debuggers because
9006 they have to deal with empty upper bounds location descriptions
9007 anyway in order to be able to deal with incomplete array types.
9008 Of course an intelligent debugger (GDB?) should be able to
9009 comprehend that a missing upper bound specification in a array
9010 type used for a storage class `auto' local array variable
9011 indicates that the upper bound is both unknown (at compile- time)
9012 and unknowable (at run-time) due to optimization.
9014 We assume that a MEM rtx is safe because gcc wouldn't put the
9015 value there unless it was going to be used repeatedly in the
9016 function, i.e. for cleanups. */
9017 if (! optimize || (SAVE_EXPR_RTL (bound)
9018 && GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
9020 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
9021 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
9022 register rtx loc = SAVE_EXPR_RTL (bound);
9024 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9025 it references an outer function's frame. */
9027 if (GET_CODE (loc) == MEM)
9029 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
9031 if (XEXP (loc, 0) != new_addr)
9032 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
9035 add_AT_flag (decl_die, DW_AT_artificial, 1);
9036 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9037 add_AT_location_description (decl_die, DW_AT_location, loc);
9038 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9041 /* Else leave out the attribute. */
9042 break;
9044 case VAR_DECL:
9045 case PARM_DECL:
9047 dw_die_ref decl_die = lookup_decl_die (bound);
9049 /* ??? Can this happen, or should the variable have been bound
9050 first? Probably it can, since I imagine that we try to create
9051 the types of parameters in the order in which they exist in
9052 the list, and won't have created a forward reference to a
9053 later parameter. */
9054 if (decl_die != NULL)
9055 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9056 break;
9059 default:
9061 /* Otherwise try to create a stack operation procedure to
9062 evaluate the value of the array bound. */
9064 dw_die_ref ctx, decl_die;
9065 dw_loc_descr_ref loc;
9067 loc = loc_descriptor_from_tree (bound, 0);
9068 if (loc == NULL)
9069 break;
9071 ctx = lookup_decl_die (current_function_decl);
9073 decl_die = new_die (DW_TAG_variable, ctx);
9074 add_AT_flag (decl_die, DW_AT_artificial, 1);
9075 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9076 add_AT_loc (decl_die, DW_AT_location, loc);
9078 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9079 break;
9084 /* Note that the block of subscript information for an array type also
9085 includes information about the element type of type given array type. */
9087 static void
9088 add_subscript_info (type_die, type)
9089 register dw_die_ref type_die;
9090 register tree type;
9092 #ifndef MIPS_DEBUGGING_INFO
9093 register unsigned dimension_number;
9094 #endif
9095 register tree lower, upper;
9096 register dw_die_ref subrange_die;
9098 /* The GNU compilers represent multidimensional array types as sequences of
9099 one dimensional array types whose element types are themselves array
9100 types. Here we squish that down, so that each multidimensional array
9101 type gets only one array_type DIE in the Dwarf debugging info. The draft
9102 Dwarf specification say that we are allowed to do this kind of
9103 compression in C (because there is no difference between an array or
9104 arrays and a multidimensional array in C) but for other source languages
9105 (e.g. Ada) we probably shouldn't do this. */
9107 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9108 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9109 We work around this by disabling this feature. See also
9110 gen_array_type_die. */
9111 #ifndef MIPS_DEBUGGING_INFO
9112 for (dimension_number = 0;
9113 TREE_CODE (type) == ARRAY_TYPE;
9114 type = TREE_TYPE (type), dimension_number++)
9116 #endif
9117 register tree domain = TYPE_DOMAIN (type);
9119 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9120 and (in GNU C only) variable bounds. Handle all three forms
9121 here. */
9122 subrange_die = new_die (DW_TAG_subrange_type, type_die);
9123 if (domain)
9125 /* We have an array type with specified bounds. */
9126 lower = TYPE_MIN_VALUE (domain);
9127 upper = TYPE_MAX_VALUE (domain);
9129 /* define the index type. */
9130 if (TREE_TYPE (domain))
9132 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9133 TREE_TYPE field. We can't emit debug info for this
9134 because it is an unnamed integral type. */
9135 if (TREE_CODE (domain) == INTEGER_TYPE
9136 && TYPE_NAME (domain) == NULL_TREE
9137 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9138 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
9140 else
9141 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9142 type_die);
9145 /* ??? If upper is NULL, the array has unspecified length,
9146 but it does have a lower bound. This happens with Fortran
9147 dimension arr(N:*)
9148 Since the debugger is definitely going to need to know N
9149 to produce useful results, go ahead and output the lower
9150 bound solo, and hope the debugger can cope. */
9152 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
9153 if (upper)
9154 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
9156 else
9157 /* We have an array type with an unspecified length. The DWARF-2
9158 spec does not say how to handle this; let's just leave out the
9159 bounds. */
9162 #ifndef MIPS_DEBUGGING_INFO
9164 #endif
9167 static void
9168 add_byte_size_attribute (die, tree_node)
9169 dw_die_ref die;
9170 register tree tree_node;
9172 register unsigned size;
9174 switch (TREE_CODE (tree_node))
9176 case ERROR_MARK:
9177 size = 0;
9178 break;
9179 case ENUMERAL_TYPE:
9180 case RECORD_TYPE:
9181 case UNION_TYPE:
9182 case QUAL_UNION_TYPE:
9183 size = int_size_in_bytes (tree_node);
9184 break;
9185 case FIELD_DECL:
9186 /* For a data member of a struct or union, the DW_AT_byte_size is
9187 generally given as the number of bytes normally allocated for an
9188 object of the *declared* type of the member itself. This is true
9189 even for bit-fields. */
9190 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9191 break;
9192 default:
9193 abort ();
9196 /* Note that `size' might be -1 when we get to this point. If it is, that
9197 indicates that the byte size of the entity in question is variable. We
9198 have no good way of expressing this fact in Dwarf at the present time,
9199 so just let the -1 pass on through. */
9201 add_AT_unsigned (die, DW_AT_byte_size, size);
9204 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9205 which specifies the distance in bits from the highest order bit of the
9206 "containing object" for the bit-field to the highest order bit of the
9207 bit-field itself.
9209 For any given bit-field, the "containing object" is a hypothetical
9210 object (of some integral or enum type) within which the given bit-field
9211 lives. The type of this hypothetical "containing object" is always the
9212 same as the declared type of the individual bit-field itself. The
9213 determination of the exact location of the "containing object" for a
9214 bit-field is rather complicated. It's handled by the
9215 `field_byte_offset' function (above).
9217 Note that it is the size (in bytes) of the hypothetical "containing object"
9218 which will be given in the DW_AT_byte_size attribute for this bit-field.
9219 (See `byte_size_attribute' above). */
9221 static inline void
9222 add_bit_offset_attribute (die, decl)
9223 register dw_die_ref die;
9224 register tree decl;
9226 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9227 tree type = DECL_BIT_FIELD_TYPE (decl);
9228 HOST_WIDE_INT bitpos_int;
9229 HOST_WIDE_INT highest_order_object_bit_offset;
9230 HOST_WIDE_INT highest_order_field_bit_offset;
9231 HOST_WIDE_INT unsigned bit_offset;
9233 /* Must be a field and a bit field. */
9234 if (!type
9235 || TREE_CODE (decl) != FIELD_DECL)
9236 abort ();
9238 /* We can't yet handle bit-fields whose offsets are variable, so if we
9239 encounter such things, just return without generating any attribute
9240 whatsoever. Likewise for variable or too large size. */
9241 if (! host_integerp (bit_position (decl), 0)
9242 || ! host_integerp (DECL_SIZE (decl), 1))
9243 return;
9245 bitpos_int = int_bit_position (decl);
9247 /* Note that the bit offset is always the distance (in bits) from the
9248 highest-order bit of the "containing object" to the highest-order bit of
9249 the bit-field itself. Since the "high-order end" of any object or field
9250 is different on big-endian and little-endian machines, the computation
9251 below must take account of these differences. */
9252 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9253 highest_order_field_bit_offset = bitpos_int;
9255 if (! BYTES_BIG_ENDIAN)
9257 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9258 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9261 bit_offset
9262 = (! BYTES_BIG_ENDIAN
9263 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9264 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9266 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9269 /* For a FIELD_DECL node which represents a bit field, output an attribute
9270 which specifies the length in bits of the given field. */
9272 static inline void
9273 add_bit_size_attribute (die, decl)
9274 register dw_die_ref die;
9275 register tree decl;
9277 /* Must be a field and a bit field. */
9278 if (TREE_CODE (decl) != FIELD_DECL
9279 || ! DECL_BIT_FIELD_TYPE (decl))
9280 abort ();
9282 if (host_integerp (DECL_SIZE (decl), 1))
9283 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9286 /* If the compiled language is ANSI C, then add a 'prototyped'
9287 attribute, if arg types are given for the parameters of a function. */
9289 static inline void
9290 add_prototyped_attribute (die, func_type)
9291 register dw_die_ref die;
9292 register tree func_type;
9294 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9295 && TYPE_ARG_TYPES (func_type) != NULL)
9296 add_AT_flag (die, DW_AT_prototyped, 1);
9299 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9300 by looking in either the type declaration or object declaration
9301 equate table. */
9303 static inline void
9304 add_abstract_origin_attribute (die, origin)
9305 register dw_die_ref die;
9306 register tree origin;
9308 dw_die_ref origin_die = NULL;
9310 if (TREE_CODE (origin) != FUNCTION_DECL)
9312 /* We may have gotten separated from the block for the inlined
9313 function, if we're in an exception handler or some such; make
9314 sure that the abstract function has been written out.
9316 Doing this for nested functions is wrong, however; functions are
9317 distinct units, and our context might not even be inline. */
9318 tree fn = origin;
9319 if (TYPE_P (fn))
9320 fn = TYPE_STUB_DECL (fn);
9321 fn = decl_function_context (fn);
9322 if (fn)
9323 gen_abstract_function (fn);
9326 if (DECL_P (origin))
9327 origin_die = lookup_decl_die (origin);
9328 else if (TYPE_P (origin))
9329 origin_die = lookup_type_die (origin);
9331 if (origin_die == NULL)
9332 abort ();
9334 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9337 /* We do not currently support the pure_virtual attribute. */
9339 static inline void
9340 add_pure_or_virtual_attribute (die, func_decl)
9341 register dw_die_ref die;
9342 register tree func_decl;
9344 if (DECL_VINDEX (func_decl))
9346 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9348 if (host_integerp (DECL_VINDEX (func_decl), 0))
9349 add_AT_loc (die, DW_AT_vtable_elem_location,
9350 new_loc_descr (DW_OP_constu,
9351 tree_low_cst (DECL_VINDEX (func_decl), 0),
9352 0));
9354 /* GNU extension: Record what type this method came from originally. */
9355 if (debug_info_level > DINFO_LEVEL_TERSE)
9356 add_AT_die_ref (die, DW_AT_containing_type,
9357 lookup_type_die (DECL_CONTEXT (func_decl)));
9361 /* Add source coordinate attributes for the given decl. */
9363 static void
9364 add_src_coords_attributes (die, decl)
9365 register dw_die_ref die;
9366 register tree decl;
9368 register unsigned file_index = lookup_filename (&decl_file_table,
9369 DECL_SOURCE_FILE (decl));
9371 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9372 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9375 /* Add an DW_AT_name attribute and source coordinate attribute for the
9376 given decl, but only if it actually has a name. */
9378 static void
9379 add_name_and_src_coords_attributes (die, decl)
9380 register dw_die_ref die;
9381 register tree decl;
9383 register tree decl_name;
9385 decl_name = DECL_NAME (decl);
9386 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9388 add_name_attribute (die, dwarf2_name (decl, 0));
9389 if (! DECL_ARTIFICIAL (decl))
9390 add_src_coords_attributes (die, decl);
9392 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9393 && TREE_PUBLIC (decl)
9394 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
9395 add_AT_string (die, DW_AT_MIPS_linkage_name,
9396 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9400 /* Push a new declaration scope. */
9402 static void
9403 push_decl_scope (scope)
9404 tree scope;
9406 /* Make room in the decl_scope_table, if necessary. */
9407 if (decl_scope_table_allocated == decl_scope_depth)
9409 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
9410 decl_scope_table
9411 = (tree *) xrealloc (decl_scope_table,
9412 decl_scope_table_allocated * sizeof (tree));
9415 decl_scope_table[decl_scope_depth] = scope;
9416 decl_scope_depth++;
9419 /* Pop a declaration scope. */
9420 static inline void
9421 pop_decl_scope ()
9423 if (decl_scope_depth <= 0)
9424 abort ();
9425 --decl_scope_depth;
9428 /* Return the DIE for the scope that immediately contains this type.
9429 Non-named types get global scope. Named types nested in other
9430 types get their containing scope if it's open, or global scope
9431 otherwise. All other types (i.e. function-local named types) get
9432 the current active scope. */
9434 static dw_die_ref
9435 scope_die_for (t, context_die)
9436 register tree t;
9437 register dw_die_ref context_die;
9439 register dw_die_ref scope_die = NULL;
9440 register tree containing_scope;
9441 register int i;
9443 /* Non-types always go in the current scope. */
9444 if (! TYPE_P (t))
9445 abort ();
9447 containing_scope = TYPE_CONTEXT (t);
9449 /* Ignore namespaces for the moment. */
9450 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9451 containing_scope = NULL_TREE;
9453 /* Ignore function type "scopes" from the C frontend. They mean that
9454 a tagged type is local to a parmlist of a function declarator, but
9455 that isn't useful to DWARF. */
9456 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9457 containing_scope = NULL_TREE;
9459 if (containing_scope == NULL_TREE)
9460 scope_die = comp_unit_die;
9461 else if (TYPE_P (containing_scope))
9463 /* For types, we can just look up the appropriate DIE. But
9464 first we check to see if we're in the middle of emitting it
9465 so we know where the new DIE should go. */
9467 for (i = decl_scope_depth - 1; i >= 0; --i)
9468 if (decl_scope_table[i] == containing_scope)
9469 break;
9471 if (i < 0)
9473 if (debug_info_level > DINFO_LEVEL_TERSE
9474 && !TREE_ASM_WRITTEN (containing_scope))
9475 abort ();
9477 /* If none of the current dies are suitable, we get file scope. */
9478 scope_die = comp_unit_die;
9480 else
9481 scope_die = lookup_type_die (containing_scope);
9483 else
9484 scope_die = context_die;
9486 return scope_die;
9489 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
9491 static inline int local_scope_p PARAMS ((dw_die_ref));
9492 static inline int
9493 local_scope_p (context_die)
9494 dw_die_ref context_die;
9496 for (; context_die; context_die = context_die->die_parent)
9497 if (context_die->die_tag == DW_TAG_inlined_subroutine
9498 || context_die->die_tag == DW_TAG_subprogram)
9499 return 1;
9500 return 0;
9503 /* Returns nonzero iff CONTEXT_DIE is a class. */
9505 static inline int class_scope_p PARAMS ((dw_die_ref));
9506 static inline int
9507 class_scope_p (context_die)
9508 dw_die_ref context_die;
9510 return (context_die
9511 && (context_die->die_tag == DW_TAG_structure_type
9512 || context_die->die_tag == DW_TAG_union_type));
9515 /* Many forms of DIEs require a "type description" attribute. This
9516 routine locates the proper "type descriptor" die for the type given
9517 by 'type', and adds an DW_AT_type attribute below the given die. */
9519 static void
9520 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9521 register dw_die_ref object_die;
9522 register tree type;
9523 register int decl_const;
9524 register int decl_volatile;
9525 register dw_die_ref context_die;
9527 register enum tree_code code = TREE_CODE (type);
9528 register dw_die_ref type_die = NULL;
9530 /* ??? If this type is an unnamed subrange type of an integral or
9531 floating-point type, use the inner type. This is because we have no
9532 support for unnamed types in base_type_die. This can happen if this is
9533 an Ada subrange type. Correct solution is emit a subrange type die. */
9534 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9535 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9536 type = TREE_TYPE (type), code = TREE_CODE (type);
9538 if (code == ERROR_MARK)
9539 return;
9541 /* Handle a special case. For functions whose return type is void, we
9542 generate *no* type attribute. (Note that no object may have type
9543 `void', so this only applies to function return types). */
9544 if (code == VOID_TYPE)
9545 return;
9547 type_die = modified_type_die (type,
9548 decl_const || TYPE_READONLY (type),
9549 decl_volatile || TYPE_VOLATILE (type),
9550 context_die);
9551 if (type_die != NULL)
9552 add_AT_die_ref (object_die, DW_AT_type, type_die);
9555 /* Given a tree pointer to a struct, class, union, or enum type node, return
9556 a pointer to the (string) tag name for the given type, or zero if the type
9557 was declared without a tag. */
9559 static const char *
9560 type_tag (type)
9561 register tree type;
9563 register const char *name = 0;
9565 if (TYPE_NAME (type) != 0)
9567 register tree t = 0;
9569 /* Find the IDENTIFIER_NODE for the type name. */
9570 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9571 t = TYPE_NAME (type);
9573 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9574 a TYPE_DECL node, regardless of whether or not a `typedef' was
9575 involved. */
9576 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9577 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9578 t = DECL_NAME (TYPE_NAME (type));
9580 /* Now get the name as a string, or invent one. */
9581 if (t != 0)
9582 name = IDENTIFIER_POINTER (t);
9585 return (name == 0 || *name == '\0') ? 0 : name;
9588 /* Return the type associated with a data member, make a special check
9589 for bit field types. */
9591 static inline tree
9592 member_declared_type (member)
9593 register tree member;
9595 return (DECL_BIT_FIELD_TYPE (member)
9596 ? DECL_BIT_FIELD_TYPE (member)
9597 : TREE_TYPE (member));
9600 /* Get the decl's label, as described by its RTL. This may be different
9601 from the DECL_NAME name used in the source file. */
9603 #if 0
9604 static const char *
9605 decl_start_label (decl)
9606 register tree decl;
9608 rtx x;
9609 const char *fnname;
9610 x = DECL_RTL (decl);
9611 if (GET_CODE (x) != MEM)
9612 abort ();
9614 x = XEXP (x, 0);
9615 if (GET_CODE (x) != SYMBOL_REF)
9616 abort ();
9618 fnname = XSTR (x, 0);
9619 return fnname;
9621 #endif
9623 /* These routines generate the internal representation of the DIE's for
9624 the compilation unit. Debugging information is collected by walking
9625 the declaration trees passed in from dwarf2out_decl(). */
9627 static void
9628 gen_array_type_die (type, context_die)
9629 register tree type;
9630 register dw_die_ref context_die;
9632 register dw_die_ref scope_die = scope_die_for (type, context_die);
9633 register dw_die_ref array_die;
9634 register tree element_type;
9636 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9637 the inner array type comes before the outer array type. Thus we must
9638 call gen_type_die before we call new_die. See below also. */
9639 #ifdef MIPS_DEBUGGING_INFO
9640 gen_type_die (TREE_TYPE (type), context_die);
9641 #endif
9643 array_die = new_die (DW_TAG_array_type, scope_die);
9645 #if 0
9646 /* We default the array ordering. SDB will probably do
9647 the right things even if DW_AT_ordering is not present. It's not even
9648 an issue until we start to get into multidimensional arrays anyway. If
9649 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9650 then we'll have to put the DW_AT_ordering attribute back in. (But if
9651 and when we find out that we need to put these in, we will only do so
9652 for multidimensional arrays. */
9653 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9654 #endif
9656 #ifdef MIPS_DEBUGGING_INFO
9657 /* The SGI compilers handle arrays of unknown bound by setting
9658 AT_declaration and not emitting any subrange DIEs. */
9659 if (! TYPE_DOMAIN (type))
9660 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9661 else
9662 #endif
9663 add_subscript_info (array_die, type);
9665 add_name_attribute (array_die, type_tag (type));
9666 equate_type_number_to_die (type, array_die);
9668 /* Add representation of the type of the elements of this array type. */
9669 element_type = TREE_TYPE (type);
9671 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9672 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9673 We work around this by disabling this feature. See also
9674 add_subscript_info. */
9675 #ifndef MIPS_DEBUGGING_INFO
9676 while (TREE_CODE (element_type) == ARRAY_TYPE)
9677 element_type = TREE_TYPE (element_type);
9679 gen_type_die (element_type, context_die);
9680 #endif
9682 add_type_attribute (array_die, element_type, 0, 0, context_die);
9685 static void
9686 gen_set_type_die (type, context_die)
9687 register tree type;
9688 register dw_die_ref context_die;
9690 register dw_die_ref type_die
9691 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9693 equate_type_number_to_die (type, type_die);
9694 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9697 #if 0
9698 static void
9699 gen_entry_point_die (decl, context_die)
9700 register tree decl;
9701 register dw_die_ref context_die;
9703 register tree origin = decl_ultimate_origin (decl);
9704 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9705 if (origin != NULL)
9706 add_abstract_origin_attribute (decl_die, origin);
9707 else
9709 add_name_and_src_coords_attributes (decl_die, decl);
9710 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9711 0, 0, context_die);
9714 if (DECL_ABSTRACT (decl))
9715 equate_decl_number_to_die (decl, decl_die);
9716 else
9717 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9719 #endif
9721 /* Remember a type in the incomplete_types_list. */
9723 static void
9724 add_incomplete_type (type)
9725 tree type;
9727 if (incomplete_types == incomplete_types_allocated)
9729 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
9730 incomplete_types_list
9731 = (tree *) xrealloc (incomplete_types_list,
9732 sizeof (tree) * incomplete_types_allocated);
9735 incomplete_types_list[incomplete_types++] = type;
9738 /* Walk through the list of incomplete types again, trying once more to
9739 emit full debugging info for them. */
9741 static void
9742 retry_incomplete_types ()
9744 register tree type;
9746 while (incomplete_types)
9748 --incomplete_types;
9749 type = incomplete_types_list[incomplete_types];
9750 gen_type_die (type, comp_unit_die);
9754 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9756 static void
9757 gen_inlined_enumeration_type_die (type, context_die)
9758 register tree type;
9759 register dw_die_ref context_die;
9761 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9762 context_die);
9763 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9764 be incomplete and such types are not marked. */
9765 add_abstract_origin_attribute (type_die, type);
9768 /* Generate a DIE to represent an inlined instance of a structure type. */
9770 static void
9771 gen_inlined_structure_type_die (type, context_die)
9772 register tree type;
9773 register dw_die_ref context_die;
9775 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9777 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9778 be incomplete and such types are not marked. */
9779 add_abstract_origin_attribute (type_die, type);
9782 /* Generate a DIE to represent an inlined instance of a union type. */
9784 static void
9785 gen_inlined_union_type_die (type, context_die)
9786 register tree type;
9787 register dw_die_ref context_die;
9789 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9791 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9792 be incomplete and such types are not marked. */
9793 add_abstract_origin_attribute (type_die, type);
9796 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9797 include all of the information about the enumeration values also. Each
9798 enumerated type name/value is listed as a child of the enumerated type
9799 DIE. */
9801 static void
9802 gen_enumeration_type_die (type, context_die)
9803 register tree type;
9804 register dw_die_ref context_die;
9806 register dw_die_ref type_die = lookup_type_die (type);
9808 if (type_die == NULL)
9810 type_die = new_die (DW_TAG_enumeration_type,
9811 scope_die_for (type, context_die));
9812 equate_type_number_to_die (type, type_die);
9813 add_name_attribute (type_die, type_tag (type));
9815 else if (! TYPE_SIZE (type))
9816 return;
9817 else
9818 remove_AT (type_die, DW_AT_declaration);
9820 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9821 given enum type is incomplete, do not generate the DW_AT_byte_size
9822 attribute or the DW_AT_element_list attribute. */
9823 if (TYPE_SIZE (type))
9825 register tree link;
9827 TREE_ASM_WRITTEN (type) = 1;
9828 add_byte_size_attribute (type_die, type);
9829 if (TYPE_STUB_DECL (type) != NULL_TREE)
9830 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9832 /* If the first reference to this type was as the return type of an
9833 inline function, then it may not have a parent. Fix this now. */
9834 if (type_die->die_parent == NULL)
9835 add_child_die (scope_die_for (type, context_die), type_die);
9837 for (link = TYPE_FIELDS (type);
9838 link != NULL; link = TREE_CHAIN (link))
9840 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9842 add_name_attribute (enum_die,
9843 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9845 if (host_integerp (TREE_VALUE (link), 0))
9847 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9848 add_AT_int (enum_die, DW_AT_const_value,
9849 tree_low_cst (TREE_VALUE (link), 0));
9850 else
9851 add_AT_unsigned (enum_die, DW_AT_const_value,
9852 tree_low_cst (TREE_VALUE (link), 0));
9856 else
9857 add_AT_flag (type_die, DW_AT_declaration, 1);
9860 /* Generate a DIE to represent either a real live formal parameter decl or to
9861 represent just the type of some formal parameter position in some function
9862 type.
9864 Note that this routine is a bit unusual because its argument may be a
9865 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9866 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9867 node. If it's the former then this function is being called to output a
9868 DIE to represent a formal parameter object (or some inlining thereof). If
9869 it's the latter, then this function is only being called to output a
9870 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9871 argument type of some subprogram type. */
9873 static dw_die_ref
9874 gen_formal_parameter_die (node, context_die)
9875 register tree node;
9876 register dw_die_ref context_die;
9878 register dw_die_ref parm_die
9879 = new_die (DW_TAG_formal_parameter, context_die);
9880 register tree origin;
9882 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9884 case 'd':
9885 origin = decl_ultimate_origin (node);
9886 if (origin != NULL)
9887 add_abstract_origin_attribute (parm_die, origin);
9888 else
9890 add_name_and_src_coords_attributes (parm_die, node);
9891 add_type_attribute (parm_die, TREE_TYPE (node),
9892 TREE_READONLY (node),
9893 TREE_THIS_VOLATILE (node),
9894 context_die);
9895 if (DECL_ARTIFICIAL (node))
9896 add_AT_flag (parm_die, DW_AT_artificial, 1);
9899 equate_decl_number_to_die (node, parm_die);
9900 if (! DECL_ABSTRACT (node))
9901 add_location_or_const_value_attribute (parm_die, node);
9903 break;
9905 case 't':
9906 /* We were called with some kind of a ..._TYPE node. */
9907 add_type_attribute (parm_die, node, 0, 0, context_die);
9908 break;
9910 default:
9911 abort ();
9914 return parm_die;
9917 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9918 at the end of an (ANSI prototyped) formal parameters list. */
9920 static void
9921 gen_unspecified_parameters_die (decl_or_type, context_die)
9922 register tree decl_or_type ATTRIBUTE_UNUSED;
9923 register dw_die_ref context_die;
9925 new_die (DW_TAG_unspecified_parameters, context_die);
9928 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9929 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9930 parameters as specified in some function type specification (except for
9931 those which appear as part of a function *definition*). */
9933 static void
9934 gen_formal_types_die (function_or_method_type, context_die)
9935 register tree function_or_method_type;
9936 register dw_die_ref context_die;
9938 register tree link;
9939 register tree formal_type = NULL;
9940 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9942 #if 0
9943 /* In the case where we are generating a formal types list for a C++
9944 non-static member function type, skip over the first thing on the
9945 TYPE_ARG_TYPES list because it only represents the type of the hidden
9946 `this pointer'. The debugger should be able to figure out (without
9947 being explicitly told) that this non-static member function type takes a
9948 `this pointer' and should be able to figure what the type of that hidden
9949 parameter is from the DW_AT_member attribute of the parent
9950 DW_TAG_subroutine_type DIE. */
9951 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
9952 first_parm_type = TREE_CHAIN (first_parm_type);
9953 #endif
9955 /* Make our first pass over the list of formal parameter types and output a
9956 DW_TAG_formal_parameter DIE for each one. */
9957 for (link = first_parm_type; link; link = TREE_CHAIN (link))
9959 register dw_die_ref parm_die;
9961 formal_type = TREE_VALUE (link);
9962 if (formal_type == void_type_node)
9963 break;
9965 /* Output a (nameless) DIE to represent the formal parameter itself. */
9966 parm_die = gen_formal_parameter_die (formal_type, context_die);
9967 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
9968 && link == first_parm_type)
9969 add_AT_flag (parm_die, DW_AT_artificial, 1);
9972 /* If this function type has an ellipsis, add a
9973 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9974 if (formal_type != void_type_node)
9975 gen_unspecified_parameters_die (function_or_method_type, context_die);
9977 /* Make our second (and final) pass over the list of formal parameter types
9978 and output DIEs to represent those types (as necessary). */
9979 for (link = TYPE_ARG_TYPES (function_or_method_type);
9980 link;
9981 link = TREE_CHAIN (link))
9983 formal_type = TREE_VALUE (link);
9984 if (formal_type == void_type_node)
9985 break;
9987 gen_type_die (formal_type, context_die);
9991 /* We want to generate the DIE for TYPE so that we can generate the
9992 die for MEMBER, which has been defined; we will need to refer back
9993 to the member declaration nested within TYPE. If we're trying to
9994 generate minimal debug info for TYPE, processing TYPE won't do the
9995 trick; we need to attach the member declaration by hand. */
9997 static void
9998 gen_type_die_for_member (type, member, context_die)
9999 tree type, member;
10000 dw_die_ref context_die;
10002 gen_type_die (type, context_die);
10004 /* If we're trying to avoid duplicate debug info, we may not have
10005 emitted the member decl for this function. Emit it now. */
10006 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
10007 && ! lookup_decl_die (member))
10009 if (decl_ultimate_origin (member))
10010 abort ();
10012 push_decl_scope (type);
10013 if (TREE_CODE (member) == FUNCTION_DECL)
10014 gen_subprogram_die (member, lookup_type_die (type));
10015 else
10016 gen_variable_die (member, lookup_type_die (type));
10017 pop_decl_scope ();
10021 /* Generate the DWARF2 info for the "abstract" instance
10022 of a function which we may later generate inlined and/or
10023 out-of-line instances of. */
10025 static void
10026 gen_abstract_function (decl)
10027 tree decl;
10029 register dw_die_ref old_die = lookup_decl_die (decl);
10030 tree save_fn;
10032 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
10033 /* We've already generated the abstract instance. */
10034 return;
10036 save_fn = current_function_decl;
10037 current_function_decl = decl;
10039 set_decl_abstract_flags (decl, 1);
10040 dwarf2out_decl (decl);
10041 set_decl_abstract_flags (decl, 0);
10043 current_function_decl = save_fn;
10046 /* Generate a DIE to represent a declared function (either file-scope or
10047 block-local). */
10049 static void
10050 gen_subprogram_die (decl, context_die)
10051 register tree decl;
10052 register dw_die_ref context_die;
10054 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10055 register tree origin = decl_ultimate_origin (decl);
10056 register dw_die_ref subr_die;
10057 register rtx fp_reg;
10058 register tree fn_arg_types;
10059 register tree outer_scope;
10060 register dw_die_ref old_die = lookup_decl_die (decl);
10061 register int declaration = (current_function_decl != decl
10062 || class_scope_p (context_die));
10064 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
10065 be true, if we started to generate the abstract instance of an inline,
10066 decided to output its containing class, and proceeded to emit the
10067 declaration of the inline from the member list for the class. In that
10068 case, `declaration' takes priority; we'll get back to the abstract
10069 instance when we're done with the class. */
10071 /* The class-scope declaration DIE must be the primary DIE. */
10072 if (origin && declaration && class_scope_p (context_die))
10074 origin = NULL;
10075 if (old_die)
10076 abort ();
10079 if (origin != NULL)
10081 if (declaration && ! local_scope_p (context_die))
10082 abort ();
10084 /* Fixup die_parent for the abstract instance of a nested
10085 inline function. */
10086 if (old_die && old_die->die_parent == NULL)
10087 add_child_die (context_die, old_die);
10089 subr_die = new_die (DW_TAG_subprogram, context_die);
10090 add_abstract_origin_attribute (subr_die, origin);
10092 else if (old_die && DECL_ABSTRACT (decl)
10093 && get_AT_unsigned (old_die, DW_AT_inline))
10095 /* This must be a redefinition of an extern inline function.
10096 We can just reuse the old die here. */
10097 subr_die = old_die;
10099 /* Clear out the inlined attribute and parm types. */
10100 remove_AT (subr_die, DW_AT_inline);
10101 remove_children (subr_die);
10103 else if (old_die)
10105 register unsigned file_index
10106 = lookup_filename (&decl_file_table, DECL_SOURCE_FILE (decl));
10108 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
10110 /* ??? This can happen if there is a bug in the program, for
10111 instance, if it has duplicate function definitions. Ideally,
10112 we should detect this case and ignore it. For now, if we have
10113 already reported an error, any error at all, then assume that
10114 we got here because of a input error, not a dwarf2 bug. */
10115 if (errorcount)
10116 return;
10117 abort ();
10120 /* If the definition comes from the same place as the declaration,
10121 maybe use the old DIE. We always want the DIE for this function
10122 that has the *_pc attributes to be under comp_unit_die so the
10123 debugger can find it. We also need to do this for abstract
10124 instances of inlines, since the spec requires the out-of-line copy
10125 to have the same parent. For local class methods, this doesn't
10126 apply; we just use the old DIE. */
10127 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
10128 && (DECL_ARTIFICIAL (decl)
10129 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10130 && (get_AT_unsigned (old_die, DW_AT_decl_line)
10131 == (unsigned) DECL_SOURCE_LINE (decl)))))
10133 subr_die = old_die;
10135 /* Clear out the declaration attribute and the parm types. */
10136 remove_AT (subr_die, DW_AT_declaration);
10137 remove_children (subr_die);
10139 else
10141 subr_die = new_die (DW_TAG_subprogram, context_die);
10142 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
10143 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10144 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10145 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10146 != (unsigned) DECL_SOURCE_LINE (decl))
10147 add_AT_unsigned
10148 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10151 else
10153 subr_die = new_die (DW_TAG_subprogram, context_die);
10155 if (TREE_PUBLIC (decl))
10156 add_AT_flag (subr_die, DW_AT_external, 1);
10158 add_name_and_src_coords_attributes (subr_die, decl);
10159 if (debug_info_level > DINFO_LEVEL_TERSE)
10161 register tree type = TREE_TYPE (decl);
10163 add_prototyped_attribute (subr_die, type);
10164 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
10167 add_pure_or_virtual_attribute (subr_die, decl);
10168 if (DECL_ARTIFICIAL (decl))
10169 add_AT_flag (subr_die, DW_AT_artificial, 1);
10170 if (TREE_PROTECTED (decl))
10171 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10172 else if (TREE_PRIVATE (decl))
10173 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
10176 if (declaration)
10178 if (! origin)
10179 add_AT_flag (subr_die, DW_AT_declaration, 1);
10181 /* The first time we see a member function, it is in the context of
10182 the class to which it belongs. We make sure of this by emitting
10183 the class first. The next time is the definition, which is
10184 handled above. The two may come from the same source text. */
10185 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10186 equate_decl_number_to_die (decl, subr_die);
10188 else if (DECL_ABSTRACT (decl))
10190 if (DECL_INLINE (decl) && !flag_no_inline)
10192 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10193 inline functions, but not for extern inline functions.
10194 We can't get this completely correct because information
10195 about whether the function was declared inline is not
10196 saved anywhere. */
10197 if (DECL_DEFER_OUTPUT (decl))
10198 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10199 else
10200 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10202 else
10203 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10205 equate_decl_number_to_die (decl, subr_die);
10207 else if (!DECL_EXTERNAL (decl))
10209 if (origin == NULL_TREE)
10210 equate_decl_number_to_die (decl, subr_die);
10212 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10213 current_funcdef_number);
10214 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10215 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10216 current_funcdef_number);
10217 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10219 add_pubname (decl, subr_die);
10220 add_arange (decl, subr_die);
10222 #ifdef MIPS_DEBUGGING_INFO
10223 /* Add a reference to the FDE for this routine. */
10224 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10225 #endif
10227 /* Define the "frame base" location for this routine. We use the
10228 frame pointer or stack pointer registers, since the RTL for local
10229 variables is relative to one of them. */
10230 fp_reg
10231 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10232 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10234 #if 0
10235 /* ??? This fails for nested inline functions, because context_display
10236 is not part of the state saved/restored for inline functions. */
10237 if (current_function_needs_context)
10238 add_AT_location_description (subr_die, DW_AT_static_link,
10239 lookup_static_chain (decl));
10240 #endif
10243 /* Now output descriptions of the arguments for this function. This gets
10244 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10245 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10246 `...' at the end of the formal parameter list. In order to find out if
10247 there was a trailing ellipsis or not, we must instead look at the type
10248 associated with the FUNCTION_DECL. This will be a node of type
10249 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10250 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10251 an ellipsis at the end. */
10253 /* In the case where we are describing a mere function declaration, all we
10254 need to do here (and all we *can* do here) is to describe the *types* of
10255 its formal parameters. */
10256 if (debug_info_level <= DINFO_LEVEL_TERSE)
10258 else if (declaration)
10259 gen_formal_types_die (TREE_TYPE (decl), subr_die);
10260 else
10262 /* Generate DIEs to represent all known formal parameters */
10263 register tree arg_decls = DECL_ARGUMENTS (decl);
10264 register tree parm;
10266 /* When generating DIEs, generate the unspecified_parameters DIE
10267 instead if we come across the arg "__builtin_va_alist" */
10268 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10269 if (TREE_CODE (parm) == PARM_DECL)
10271 if (DECL_NAME (parm)
10272 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10273 "__builtin_va_alist"))
10274 gen_unspecified_parameters_die (parm, subr_die);
10275 else
10276 gen_decl_die (parm, subr_die);
10279 /* Decide whether we need a unspecified_parameters DIE at the end.
10280 There are 2 more cases to do this for: 1) the ansi ... declaration -
10281 this is detectable when the end of the arg list is not a
10282 void_type_node 2) an unprototyped function declaration (not a
10283 definition). This just means that we have no info about the
10284 parameters at all. */
10285 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10286 if (fn_arg_types != NULL)
10288 /* this is the prototyped case, check for ... */
10289 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10290 gen_unspecified_parameters_die (decl, subr_die);
10292 else if (DECL_INITIAL (decl) == NULL_TREE)
10293 gen_unspecified_parameters_die (decl, subr_die);
10296 /* Output Dwarf info for all of the stuff within the body of the function
10297 (if it has one - it may be just a declaration). */
10298 outer_scope = DECL_INITIAL (decl);
10300 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
10301 node created to represent a function. This outermost BLOCK actually
10302 represents the outermost binding contour for the function, i.e. the
10303 contour in which the function's formal parameters and labels get
10304 declared. Curiously, it appears that the front end doesn't actually
10305 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
10306 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
10307 list for the function instead.) The BLOCK_VARS list for the
10308 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
10309 the function however, and we output DWARF info for those in
10310 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
10311 node representing the function's outermost pair of curly braces, and
10312 any blocks used for the base and member initializers of a C++
10313 constructor function. */
10314 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10316 current_function_has_inlines = 0;
10317 decls_for_scope (outer_scope, subr_die, 0);
10319 #if 0 && defined (MIPS_DEBUGGING_INFO)
10320 if (current_function_has_inlines)
10322 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10323 if (! comp_unit_has_inlines)
10325 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10326 comp_unit_has_inlines = 1;
10329 #endif
10333 /* Generate a DIE to represent a declared data object. */
10335 static void
10336 gen_variable_die (decl, context_die)
10337 register tree decl;
10338 register dw_die_ref context_die;
10340 register tree origin = decl_ultimate_origin (decl);
10341 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
10343 dw_die_ref old_die = lookup_decl_die (decl);
10344 int declaration = (DECL_EXTERNAL (decl)
10345 || class_scope_p (context_die));
10347 if (origin != NULL)
10348 add_abstract_origin_attribute (var_die, origin);
10349 /* Loop unrolling can create multiple blocks that refer to the same
10350 static variable, so we must test for the DW_AT_declaration flag. */
10351 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10352 copy decls and set the DECL_ABSTRACT flag on them instead of
10353 sharing them. */
10354 else if (old_die && TREE_STATIC (decl)
10355 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10357 /* This is a definition of a C++ class level static. */
10358 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10359 if (DECL_NAME (decl))
10361 register unsigned file_index
10362 = lookup_filename (&decl_file_table, DECL_SOURCE_FILE (decl));
10364 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10365 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10367 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10368 != (unsigned) DECL_SOURCE_LINE (decl))
10370 add_AT_unsigned (var_die, DW_AT_decl_line,
10371 DECL_SOURCE_LINE (decl));
10374 else
10376 add_name_and_src_coords_attributes (var_die, decl);
10377 add_type_attribute (var_die, TREE_TYPE (decl),
10378 TREE_READONLY (decl),
10379 TREE_THIS_VOLATILE (decl), context_die);
10381 if (TREE_PUBLIC (decl))
10382 add_AT_flag (var_die, DW_AT_external, 1);
10384 if (DECL_ARTIFICIAL (decl))
10385 add_AT_flag (var_die, DW_AT_artificial, 1);
10387 if (TREE_PROTECTED (decl))
10388 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10390 else if (TREE_PRIVATE (decl))
10391 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10394 if (declaration)
10395 add_AT_flag (var_die, DW_AT_declaration, 1);
10397 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10398 equate_decl_number_to_die (decl, var_die);
10400 if (! declaration && ! DECL_ABSTRACT (decl))
10402 add_location_or_const_value_attribute (var_die, decl);
10403 add_pubname (decl, var_die);
10405 else
10406 tree_add_const_value_attribute (var_die, decl);
10409 /* Generate a DIE to represent a label identifier. */
10411 static void
10412 gen_label_die (decl, context_die)
10413 register tree decl;
10414 register dw_die_ref context_die;
10416 register tree origin = decl_ultimate_origin (decl);
10417 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
10418 register rtx insn;
10419 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10421 if (origin != NULL)
10422 add_abstract_origin_attribute (lbl_die, origin);
10423 else
10424 add_name_and_src_coords_attributes (lbl_die, decl);
10426 if (DECL_ABSTRACT (decl))
10427 equate_decl_number_to_die (decl, lbl_die);
10428 else
10430 insn = DECL_RTL (decl);
10432 /* Deleted labels are programmer specified labels which have been
10433 eliminated because of various optimisations. We still emit them
10434 here so that it is possible to put breakpoints on them. */
10435 if (GET_CODE (insn) == CODE_LABEL
10436 || ((GET_CODE (insn) == NOTE
10437 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10439 /* When optimization is enabled (via -O) some parts of the compiler
10440 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10441 represent source-level labels which were explicitly declared by
10442 the user. This really shouldn't be happening though, so catch
10443 it if it ever does happen. */
10444 if (INSN_DELETED_P (insn))
10445 abort ();
10447 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10448 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10453 /* Generate a DIE for a lexical block. */
10455 static void
10456 gen_lexical_block_die (stmt, context_die, depth)
10457 register tree stmt;
10458 register dw_die_ref context_die;
10459 int depth;
10461 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
10462 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10464 if (! BLOCK_ABSTRACT (stmt))
10466 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10467 BLOCK_NUMBER (stmt));
10468 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10469 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10470 BLOCK_NUMBER (stmt));
10471 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10474 decls_for_scope (stmt, stmt_die, depth);
10477 /* Generate a DIE for an inlined subprogram. */
10479 static void
10480 gen_inlined_subroutine_die (stmt, context_die, depth)
10481 register tree stmt;
10482 register dw_die_ref context_die;
10483 int depth;
10485 if (! BLOCK_ABSTRACT (stmt))
10487 register dw_die_ref subr_die
10488 = new_die (DW_TAG_inlined_subroutine, context_die);
10489 register tree decl = block_ultimate_origin (stmt);
10490 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10492 /* Emit info for the abstract instance first, if we haven't yet. */
10493 gen_abstract_function (decl);
10495 add_abstract_origin_attribute (subr_die, decl);
10496 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10497 BLOCK_NUMBER (stmt));
10498 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10499 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10500 BLOCK_NUMBER (stmt));
10501 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10502 decls_for_scope (stmt, subr_die, depth);
10503 current_function_has_inlines = 1;
10507 /* Generate a DIE for a field in a record, or structure. */
10509 static void
10510 gen_field_die (decl, context_die)
10511 register tree decl;
10512 register dw_die_ref context_die;
10514 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
10516 add_name_and_src_coords_attributes (decl_die, decl);
10517 add_type_attribute (decl_die, member_declared_type (decl),
10518 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10519 context_die);
10521 /* If this is a bit field... */
10522 if (DECL_BIT_FIELD_TYPE (decl))
10524 add_byte_size_attribute (decl_die, decl);
10525 add_bit_size_attribute (decl_die, decl);
10526 add_bit_offset_attribute (decl_die, decl);
10529 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10530 add_data_member_location_attribute (decl_die, decl);
10532 if (DECL_ARTIFICIAL (decl))
10533 add_AT_flag (decl_die, DW_AT_artificial, 1);
10535 if (TREE_PROTECTED (decl))
10536 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10538 else if (TREE_PRIVATE (decl))
10539 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10542 #if 0
10543 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10544 Use modified_type_die instead.
10545 We keep this code here just in case these types of DIEs may be needed to
10546 represent certain things in other languages (e.g. Pascal) someday. */
10547 static void
10548 gen_pointer_type_die (type, context_die)
10549 register tree type;
10550 register dw_die_ref context_die;
10552 register dw_die_ref ptr_die
10553 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
10555 equate_type_number_to_die (type, ptr_die);
10556 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10557 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10560 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10561 Use modified_type_die instead.
10562 We keep this code here just in case these types of DIEs may be needed to
10563 represent certain things in other languages (e.g. Pascal) someday. */
10564 static void
10565 gen_reference_type_die (type, context_die)
10566 register tree type;
10567 register dw_die_ref context_die;
10569 register dw_die_ref ref_die
10570 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
10572 equate_type_number_to_die (type, ref_die);
10573 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10574 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10576 #endif
10578 /* Generate a DIE for a pointer to a member type. */
10579 static void
10580 gen_ptr_to_mbr_type_die (type, context_die)
10581 register tree type;
10582 register dw_die_ref context_die;
10584 register dw_die_ref ptr_die
10585 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
10587 equate_type_number_to_die (type, ptr_die);
10588 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10589 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10590 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10593 /* Generate the DIE for the compilation unit. */
10595 static dw_die_ref
10596 gen_compile_unit_die (filename)
10597 register const char *filename;
10599 register dw_die_ref die;
10600 char producer[250];
10601 const char *wd = getpwd ();
10602 int language;
10604 die = new_die (DW_TAG_compile_unit, NULL);
10605 add_name_attribute (die, filename);
10607 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10608 add_AT_string (die, DW_AT_comp_dir, wd);
10610 sprintf (producer, "%s %s", language_string, version_string);
10612 #ifdef MIPS_DEBUGGING_INFO
10613 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10614 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10615 not appear in the producer string, the debugger reaches the conclusion
10616 that the object file is stripped and has no debugging information.
10617 To get the MIPS/SGI debugger to believe that there is debugging
10618 information in the object file, we add a -g to the producer string. */
10619 if (debug_info_level > DINFO_LEVEL_TERSE)
10620 strcat (producer, " -g");
10621 #endif
10623 add_AT_string (die, DW_AT_producer, producer);
10625 if (strcmp (language_string, "GNU C++") == 0)
10626 language = DW_LANG_C_plus_plus;
10627 else if (strcmp (language_string, "GNU Ada") == 0)
10628 language = DW_LANG_Ada83;
10629 else if (strcmp (language_string, "GNU F77") == 0)
10630 language = DW_LANG_Fortran77;
10631 else if (strcmp (language_string, "GNU Pascal") == 0)
10632 language = DW_LANG_Pascal83;
10633 else if (strcmp (language_string, "GNU Java") == 0)
10634 language = DW_LANG_Java;
10635 else if (flag_traditional)
10636 language = DW_LANG_C;
10637 else
10638 language = DW_LANG_C89;
10640 add_AT_unsigned (die, DW_AT_language, language);
10642 return die;
10645 /* Generate a DIE for a string type. */
10647 static void
10648 gen_string_type_die (type, context_die)
10649 register tree type;
10650 register dw_die_ref context_die;
10652 register dw_die_ref type_die
10653 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10655 equate_type_number_to_die (type, type_die);
10657 /* Fudge the string length attribute for now. */
10659 /* TODO: add string length info.
10660 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10661 bound_representation (upper_bound, 0, 'u'); */
10664 /* Generate the DIE for a base class. */
10666 static void
10667 gen_inheritance_die (binfo, context_die)
10668 register tree binfo;
10669 register dw_die_ref context_die;
10671 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10673 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10674 add_data_member_location_attribute (die, binfo);
10676 if (TREE_VIA_VIRTUAL (binfo))
10677 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10678 if (TREE_VIA_PUBLIC (binfo))
10679 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10680 else if (TREE_VIA_PROTECTED (binfo))
10681 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10684 /* Generate a DIE for a class member. */
10686 static void
10687 gen_member_die (type, context_die)
10688 register tree type;
10689 register dw_die_ref context_die;
10691 register tree member;
10692 dw_die_ref child;
10694 /* If this is not an incomplete type, output descriptions of each of its
10695 members. Note that as we output the DIEs necessary to represent the
10696 members of this record or union type, we will also be trying to output
10697 DIEs to represent the *types* of those members. However the `type'
10698 function (above) will specifically avoid generating type DIEs for member
10699 types *within* the list of member DIEs for this (containing) type execpt
10700 for those types (of members) which are explicitly marked as also being
10701 members of this (containing) type themselves. The g++ front- end can
10702 force any given type to be treated as a member of some other
10703 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10704 to point to the TREE node representing the appropriate (containing)
10705 type. */
10707 /* First output info about the base classes. */
10708 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10710 register tree bases = TYPE_BINFO_BASETYPES (type);
10711 register int n_bases = TREE_VEC_LENGTH (bases);
10712 register int i;
10714 for (i = 0; i < n_bases; i++)
10715 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10718 /* Now output info about the data members and type members. */
10719 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10721 /* If we thought we were generating minimal debug info for TYPE
10722 and then changed our minds, some of the member declarations
10723 may have already been defined. Don't define them again, but
10724 do put them in the right order. */
10726 child = lookup_decl_die (member);
10727 if (child)
10728 splice_child_die (context_die, child);
10729 else
10730 gen_decl_die (member, context_die);
10733 /* Now output info about the function members (if any). */
10734 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10736 child = lookup_decl_die (member);
10737 if (child)
10738 splice_child_die (context_die, child);
10739 else
10740 gen_decl_die (member, context_die);
10744 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10745 is set, we pretend that the type was never defined, so we only get the
10746 member DIEs needed by later specification DIEs. */
10748 static void
10749 gen_struct_or_union_type_die (type, context_die)
10750 register tree type;
10751 register dw_die_ref context_die;
10753 register dw_die_ref type_die = lookup_type_die (type);
10754 register dw_die_ref scope_die = 0;
10755 register int nested = 0;
10756 int complete = (TYPE_SIZE (type)
10757 && (! TYPE_STUB_DECL (type)
10758 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10760 if (type_die && ! complete)
10761 return;
10763 if (TYPE_CONTEXT (type) != NULL_TREE
10764 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10765 nested = 1;
10767 scope_die = scope_die_for (type, context_die);
10769 if (! type_die || (nested && scope_die == comp_unit_die))
10770 /* First occurrence of type or toplevel definition of nested class. */
10772 register dw_die_ref old_die = type_die;
10774 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10775 ? DW_TAG_structure_type : DW_TAG_union_type,
10776 scope_die);
10777 equate_type_number_to_die (type, type_die);
10778 if (old_die)
10779 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10780 else
10781 add_name_attribute (type_die, type_tag (type));
10783 else
10784 remove_AT (type_die, DW_AT_declaration);
10786 /* If this type has been completed, then give it a byte_size attribute and
10787 then give a list of members. */
10788 if (complete)
10790 /* Prevent infinite recursion in cases where the type of some member of
10791 this type is expressed in terms of this type itself. */
10792 TREE_ASM_WRITTEN (type) = 1;
10793 add_byte_size_attribute (type_die, type);
10794 if (TYPE_STUB_DECL (type) != NULL_TREE)
10795 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10797 /* If the first reference to this type was as the return type of an
10798 inline function, then it may not have a parent. Fix this now. */
10799 if (type_die->die_parent == NULL)
10800 add_child_die (scope_die, type_die);
10802 push_decl_scope (type);
10803 gen_member_die (type, type_die);
10804 pop_decl_scope ();
10806 /* GNU extension: Record what type our vtable lives in. */
10807 if (TYPE_VFIELD (type))
10809 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10811 gen_type_die (vtype, context_die);
10812 add_AT_die_ref (type_die, DW_AT_containing_type,
10813 lookup_type_die (vtype));
10816 else
10818 add_AT_flag (type_die, DW_AT_declaration, 1);
10820 /* We don't need to do this for function-local types. */
10821 if (! decl_function_context (TYPE_STUB_DECL (type)))
10822 add_incomplete_type (type);
10826 /* Generate a DIE for a subroutine _type_. */
10828 static void
10829 gen_subroutine_type_die (type, context_die)
10830 register tree type;
10831 register dw_die_ref context_die;
10833 register tree return_type = TREE_TYPE (type);
10834 register dw_die_ref subr_die
10835 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10837 equate_type_number_to_die (type, subr_die);
10838 add_prototyped_attribute (subr_die, type);
10839 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10840 gen_formal_types_die (type, subr_die);
10843 /* Generate a DIE for a type definition */
10845 static void
10846 gen_typedef_die (decl, context_die)
10847 register tree decl;
10848 register dw_die_ref context_die;
10850 register dw_die_ref type_die;
10851 register tree origin;
10853 if (TREE_ASM_WRITTEN (decl))
10854 return;
10855 TREE_ASM_WRITTEN (decl) = 1;
10857 type_die = new_die (DW_TAG_typedef, context_die);
10858 origin = decl_ultimate_origin (decl);
10859 if (origin != NULL)
10860 add_abstract_origin_attribute (type_die, origin);
10861 else
10863 register tree type;
10864 add_name_and_src_coords_attributes (type_die, decl);
10865 if (DECL_ORIGINAL_TYPE (decl))
10867 type = DECL_ORIGINAL_TYPE (decl);
10869 if (type == TREE_TYPE (decl))
10870 abort ();
10871 else
10872 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10874 else
10875 type = TREE_TYPE (decl);
10876 add_type_attribute (type_die, type, TREE_READONLY (decl),
10877 TREE_THIS_VOLATILE (decl), context_die);
10880 if (DECL_ABSTRACT (decl))
10881 equate_decl_number_to_die (decl, type_die);
10884 /* Generate a type description DIE. */
10886 static void
10887 gen_type_die (type, context_die)
10888 register tree type;
10889 register dw_die_ref context_die;
10891 int need_pop;
10893 if (type == NULL_TREE || type == error_mark_node)
10894 return;
10896 /* We are going to output a DIE to represent the unqualified version of
10897 this type (i.e. without any const or volatile qualifiers) so get the
10898 main variant (i.e. the unqualified version) of this type now. */
10899 type = type_main_variant (type);
10901 if (TREE_ASM_WRITTEN (type))
10902 return;
10904 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10905 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10907 TREE_ASM_WRITTEN (type) = 1;
10908 gen_decl_die (TYPE_NAME (type), context_die);
10909 return;
10912 switch (TREE_CODE (type))
10914 case ERROR_MARK:
10915 break;
10917 case POINTER_TYPE:
10918 case REFERENCE_TYPE:
10919 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10920 ensures that the gen_type_die recursion will terminate even if the
10921 type is recursive. Recursive types are possible in Ada. */
10922 /* ??? We could perhaps do this for all types before the switch
10923 statement. */
10924 TREE_ASM_WRITTEN (type) = 1;
10926 /* For these types, all that is required is that we output a DIE (or a
10927 set of DIEs) to represent the "basis" type. */
10928 gen_type_die (TREE_TYPE (type), context_die);
10929 break;
10931 case OFFSET_TYPE:
10932 /* This code is used for C++ pointer-to-data-member types.
10933 Output a description of the relevant class type. */
10934 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10936 /* Output a description of the type of the object pointed to. */
10937 gen_type_die (TREE_TYPE (type), context_die);
10939 /* Now output a DIE to represent this pointer-to-data-member type
10940 itself. */
10941 gen_ptr_to_mbr_type_die (type, context_die);
10942 break;
10944 case SET_TYPE:
10945 gen_type_die (TYPE_DOMAIN (type), context_die);
10946 gen_set_type_die (type, context_die);
10947 break;
10949 case FILE_TYPE:
10950 gen_type_die (TREE_TYPE (type), context_die);
10951 abort (); /* No way to represent these in Dwarf yet! */
10952 break;
10954 case FUNCTION_TYPE:
10955 /* Force out return type (in case it wasn't forced out already). */
10956 gen_type_die (TREE_TYPE (type), context_die);
10957 gen_subroutine_type_die (type, context_die);
10958 break;
10960 case METHOD_TYPE:
10961 /* Force out return type (in case it wasn't forced out already). */
10962 gen_type_die (TREE_TYPE (type), context_die);
10963 gen_subroutine_type_die (type, context_die);
10964 break;
10966 case ARRAY_TYPE:
10967 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10969 gen_type_die (TREE_TYPE (type), context_die);
10970 gen_string_type_die (type, context_die);
10972 else
10973 gen_array_type_die (type, context_die);
10974 break;
10976 case VECTOR_TYPE:
10977 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10978 break;
10980 case ENUMERAL_TYPE:
10981 case RECORD_TYPE:
10982 case UNION_TYPE:
10983 case QUAL_UNION_TYPE:
10984 /* If this is a nested type whose containing class hasn't been
10985 written out yet, writing it out will cover this one, too.
10986 This does not apply to instantiations of member class templates;
10987 they need to be added to the containing class as they are
10988 generated. FIXME: This hurts the idea of combining type decls
10989 from multiple TUs, since we can't predict what set of template
10990 instantiations we'll get. */
10991 if (TYPE_CONTEXT (type)
10992 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10993 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10995 gen_type_die (TYPE_CONTEXT (type), context_die);
10997 if (TREE_ASM_WRITTEN (type))
10998 return;
11000 /* If that failed, attach ourselves to the stub. */
11001 push_decl_scope (TYPE_CONTEXT (type));
11002 context_die = lookup_type_die (TYPE_CONTEXT (type));
11003 need_pop = 1;
11005 else
11006 need_pop = 0;
11008 if (TREE_CODE (type) == ENUMERAL_TYPE)
11009 gen_enumeration_type_die (type, context_die);
11010 else
11011 gen_struct_or_union_type_die (type, context_die);
11013 if (need_pop)
11014 pop_decl_scope ();
11016 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11017 it up if it is ever completed. gen_*_type_die will set it for us
11018 when appropriate. */
11019 return;
11021 case VOID_TYPE:
11022 case INTEGER_TYPE:
11023 case REAL_TYPE:
11024 case COMPLEX_TYPE:
11025 case BOOLEAN_TYPE:
11026 case CHAR_TYPE:
11027 /* No DIEs needed for fundamental types. */
11028 break;
11030 case LANG_TYPE:
11031 /* No Dwarf representation currently defined. */
11032 break;
11034 default:
11035 abort ();
11038 TREE_ASM_WRITTEN (type) = 1;
11041 /* Generate a DIE for a tagged type instantiation. */
11043 static void
11044 gen_tagged_type_instantiation_die (type, context_die)
11045 register tree type;
11046 register dw_die_ref context_die;
11048 if (type == NULL_TREE || type == error_mark_node)
11049 return;
11051 /* We are going to output a DIE to represent the unqualified version of
11052 this type (i.e. without any const or volatile qualifiers) so make sure
11053 that we have the main variant (i.e. the unqualified version) of this
11054 type now. */
11055 if (type != type_main_variant (type))
11056 abort ();
11058 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11059 an instance of an unresolved type. */
11061 switch (TREE_CODE (type))
11063 case ERROR_MARK:
11064 break;
11066 case ENUMERAL_TYPE:
11067 gen_inlined_enumeration_type_die (type, context_die);
11068 break;
11070 case RECORD_TYPE:
11071 gen_inlined_structure_type_die (type, context_die);
11072 break;
11074 case UNION_TYPE:
11075 case QUAL_UNION_TYPE:
11076 gen_inlined_union_type_die (type, context_die);
11077 break;
11079 default:
11080 abort ();
11084 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11085 things which are local to the given block. */
11087 static void
11088 gen_block_die (stmt, context_die, depth)
11089 register tree stmt;
11090 register dw_die_ref context_die;
11091 int depth;
11093 register int must_output_die = 0;
11094 register tree origin;
11095 register tree decl;
11096 register enum tree_code origin_code;
11098 /* Ignore blocks never really used to make RTL. */
11100 if (stmt == NULL_TREE || !TREE_USED (stmt)
11101 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
11102 return;
11104 /* Determine the "ultimate origin" of this block. This block may be an
11105 inlined instance of an inlined instance of inline function, so we have
11106 to trace all of the way back through the origin chain to find out what
11107 sort of node actually served as the original seed for the creation of
11108 the current block. */
11109 origin = block_ultimate_origin (stmt);
11110 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11112 /* Determine if we need to output any Dwarf DIEs at all to represent this
11113 block. */
11114 if (origin_code == FUNCTION_DECL)
11115 /* The outer scopes for inlinings *must* always be represented. We
11116 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11117 must_output_die = 1;
11118 else
11120 /* In the case where the current block represents an inlining of the
11121 "body block" of an inline function, we must *NOT* output any DIE for
11122 this block because we have already output a DIE to represent the
11123 whole inlined function scope and the "body block" of any function
11124 doesn't really represent a different scope according to ANSI C
11125 rules. So we check here to make sure that this block does not
11126 represent a "body block inlining" before trying to set the
11127 `must_output_die' flag. */
11128 if (! is_body_block (origin ? origin : stmt))
11130 /* Determine if this block directly contains any "significant"
11131 local declarations which we will need to output DIEs for. */
11132 if (debug_info_level > DINFO_LEVEL_TERSE)
11133 /* We are not in terse mode so *any* local declaration counts
11134 as being a "significant" one. */
11135 must_output_die = (BLOCK_VARS (stmt) != NULL);
11136 else
11137 /* We are in terse mode, so only local (nested) function
11138 definitions count as "significant" local declarations. */
11139 for (decl = BLOCK_VARS (stmt);
11140 decl != NULL; decl = TREE_CHAIN (decl))
11141 if (TREE_CODE (decl) == FUNCTION_DECL
11142 && DECL_INITIAL (decl))
11144 must_output_die = 1;
11145 break;
11150 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11151 DIE for any block which contains no significant local declarations at
11152 all. Rather, in such cases we just call `decls_for_scope' so that any
11153 needed Dwarf info for any sub-blocks will get properly generated. Note
11154 that in terse mode, our definition of what constitutes a "significant"
11155 local declaration gets restricted to include only inlined function
11156 instances and local (nested) function definitions. */
11157 if (must_output_die)
11159 if (origin_code == FUNCTION_DECL)
11160 gen_inlined_subroutine_die (stmt, context_die, depth);
11161 else
11162 gen_lexical_block_die (stmt, context_die, depth);
11164 else
11165 decls_for_scope (stmt, context_die, depth);
11168 /* Generate all of the decls declared within a given scope and (recursively)
11169 all of its sub-blocks. */
11171 static void
11172 decls_for_scope (stmt, context_die, depth)
11173 register tree stmt;
11174 register dw_die_ref context_die;
11175 int depth;
11177 register tree decl;
11178 register tree subblocks;
11180 /* Ignore blocks never really used to make RTL. */
11181 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11182 return;
11184 /* Output the DIEs to represent all of the data objects and typedefs
11185 declared directly within this block but not within any nested
11186 sub-blocks. Also, nested function and tag DIEs have been
11187 generated with a parent of NULL; fix that up now. */
11188 for (decl = BLOCK_VARS (stmt);
11189 decl != NULL; decl = TREE_CHAIN (decl))
11191 register dw_die_ref die;
11193 if (TREE_CODE (decl) == FUNCTION_DECL)
11194 die = lookup_decl_die (decl);
11195 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11196 die = lookup_type_die (TREE_TYPE (decl));
11197 else
11198 die = NULL;
11200 if (die != NULL && die->die_parent == NULL)
11201 add_child_die (context_die, die);
11202 else
11203 gen_decl_die (decl, context_die);
11206 /* Output the DIEs to represent all sub-blocks (and the items declared
11207 therein) of this block. */
11208 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11209 subblocks != NULL;
11210 subblocks = BLOCK_CHAIN (subblocks))
11211 gen_block_die (subblocks, context_die, depth + 1);
11214 /* Is this a typedef we can avoid emitting? */
11216 static inline int
11217 is_redundant_typedef (decl)
11218 register tree decl;
11220 if (TYPE_DECL_IS_STUB (decl))
11221 return 1;
11223 if (DECL_ARTIFICIAL (decl)
11224 && DECL_CONTEXT (decl)
11225 && is_tagged_type (DECL_CONTEXT (decl))
11226 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11227 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11228 /* Also ignore the artificial member typedef for the class name. */
11229 return 1;
11231 return 0;
11234 /* Generate Dwarf debug information for a decl described by DECL. */
11236 static void
11237 gen_decl_die (decl, context_die)
11238 register tree decl;
11239 register dw_die_ref context_die;
11241 register tree origin;
11243 if (TREE_CODE (decl) == ERROR_MARK)
11244 return;
11246 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11247 if (DECL_IGNORED_P (decl))
11248 return;
11250 switch (TREE_CODE (decl))
11252 case CONST_DECL:
11253 /* The individual enumerators of an enum type get output when we output
11254 the Dwarf representation of the relevant enum type itself. */
11255 break;
11257 case FUNCTION_DECL:
11258 /* Don't output any DIEs to represent mere function declarations,
11259 unless they are class members or explicit block externs. */
11260 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11261 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11262 break;
11264 /* If we're emitting an out-of-line copy of an inline function,
11265 emit info for the abstract instance and set up to refer to it. */
11266 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11267 && ! class_scope_p (context_die)
11268 /* gen_abstract_function won't emit a die if this is just a
11269 declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11270 that case, because that works only if we have a die. */
11271 && DECL_INITIAL (decl) != NULL_TREE)
11273 gen_abstract_function (decl);
11274 set_decl_origin_self (decl);
11277 if (debug_info_level > DINFO_LEVEL_TERSE)
11279 /* Before we describe the FUNCTION_DECL itself, make sure that we
11280 have described its return type. */
11281 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11283 /* And its virtual context. */
11284 if (DECL_VINDEX (decl) != NULL_TREE)
11285 gen_type_die (DECL_CONTEXT (decl), context_die);
11287 /* And its containing type. */
11288 origin = decl_class_context (decl);
11289 if (origin != NULL_TREE)
11290 gen_type_die_for_member (origin, decl, context_die);
11293 /* Now output a DIE to represent the function itself. */
11294 gen_subprogram_die (decl, context_die);
11295 break;
11297 case TYPE_DECL:
11298 /* If we are in terse mode, don't generate any DIEs to represent any
11299 actual typedefs. */
11300 if (debug_info_level <= DINFO_LEVEL_TERSE)
11301 break;
11303 /* In the special case of a TYPE_DECL node representing the
11304 declaration of some type tag, if the given TYPE_DECL is marked as
11305 having been instantiated from some other (original) TYPE_DECL node
11306 (e.g. one which was generated within the original definition of an
11307 inline function) we have to generate a special (abbreviated)
11308 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
11309 DIE here. */
11310 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11312 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11313 break;
11316 if (is_redundant_typedef (decl))
11317 gen_type_die (TREE_TYPE (decl), context_die);
11318 else
11319 /* Output a DIE to represent the typedef itself. */
11320 gen_typedef_die (decl, context_die);
11321 break;
11323 case LABEL_DECL:
11324 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11325 gen_label_die (decl, context_die);
11326 break;
11328 case VAR_DECL:
11329 /* If we are in terse mode, don't generate any DIEs to represent any
11330 variable declarations or definitions. */
11331 if (debug_info_level <= DINFO_LEVEL_TERSE)
11332 break;
11334 /* Output any DIEs that are needed to specify the type of this data
11335 object. */
11336 gen_type_die (TREE_TYPE (decl), context_die);
11338 /* And its containing type. */
11339 origin = decl_class_context (decl);
11340 if (origin != NULL_TREE)
11341 gen_type_die_for_member (origin, decl, context_die);
11343 /* Now output the DIE to represent the data object itself. This gets
11344 complicated because of the possibility that the VAR_DECL really
11345 represents an inlined instance of a formal parameter for an inline
11346 function. */
11347 origin = decl_ultimate_origin (decl);
11348 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11349 gen_formal_parameter_die (decl, context_die);
11350 else
11351 gen_variable_die (decl, context_die);
11352 break;
11354 case FIELD_DECL:
11355 /* Ignore the nameless fields that are used to skip bits, but
11356 handle C++ anonymous unions. */
11357 if (DECL_NAME (decl) != NULL_TREE
11358 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11360 gen_type_die (member_declared_type (decl), context_die);
11361 gen_field_die (decl, context_die);
11363 break;
11365 case PARM_DECL:
11366 gen_type_die (TREE_TYPE (decl), context_die);
11367 gen_formal_parameter_die (decl, context_die);
11368 break;
11370 case NAMESPACE_DECL:
11371 /* Ignore for now. */
11372 break;
11374 default:
11375 abort ();
11379 /* Add Ada "use" clause information for SGI Workshop debugger. */
11381 void
11382 dwarf2out_add_library_unit_info (filename, context_list)
11383 const char *filename;
11384 const char *context_list;
11386 unsigned int file_index;
11388 if (filename != NULL)
11390 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
11391 tree context_list_decl
11392 = build_decl (LABEL_DECL, get_identifier (context_list),
11393 void_type_node);
11395 TREE_PUBLIC (context_list_decl) = TRUE;
11396 add_name_attribute (unit_die, context_list);
11397 file_index = lookup_filename (&decl_file_table, filename);
11398 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11399 add_pubname (context_list_decl, unit_die);
11403 /* Write the debugging output for DECL. */
11405 void
11406 dwarf2out_decl (decl)
11407 register tree decl;
11409 register dw_die_ref context_die = comp_unit_die;
11411 if (TREE_CODE (decl) == ERROR_MARK)
11412 return;
11414 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11415 if (DECL_IGNORED_P (decl))
11416 return;
11418 switch (TREE_CODE (decl))
11420 case FUNCTION_DECL:
11421 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11422 builtin function. Explicit programmer-supplied declarations of
11423 these same functions should NOT be ignored however. */
11424 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11425 return;
11427 /* What we would really like to do here is to filter out all mere
11428 file-scope declarations of file-scope functions which are never
11429 referenced later within this translation unit (and keep all of ones
11430 that *are* referenced later on) but we aren't clairvoyant, so we have
11431 no idea which functions will be referenced in the future (i.e. later
11432 on within the current translation unit). So here we just ignore all
11433 file-scope function declarations which are not also definitions. If
11434 and when the debugger needs to know something about these functions,
11435 it will have to hunt around and find the DWARF information associated
11436 with the definition of the function. Note that we can't just check
11437 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
11438 definitions and which ones represent mere declarations. We have to
11439 check `DECL_INITIAL' instead. That's because the C front-end
11440 supports some weird semantics for "extern inline" function
11441 definitions. These can get inlined within the current translation
11442 unit (an thus, we need to generate DWARF info for their abstract
11443 instances so that the DWARF info for the concrete inlined instances
11444 can have something to refer to) but the compiler never generates any
11445 out-of-lines instances of such things (despite the fact that they
11446 *are* definitions). The important point is that the C front-end
11447 marks these "extern inline" functions as DECL_EXTERNAL, but we need
11448 to generate DWARF for them anyway. Note that the C++ front-end also
11449 plays some similar games for inline function definitions appearing
11450 within include files which also contain
11451 `#pragma interface' pragmas. */
11452 if (DECL_INITIAL (decl) == NULL_TREE)
11453 return;
11455 /* If we're a nested function, initially use a parent of NULL; if we're
11456 a plain function, this will be fixed up in decls_for_scope. If
11457 we're a method, it will be ignored, since we already have a DIE. */
11458 if (decl_function_context (decl))
11459 context_die = NULL;
11461 break;
11463 case VAR_DECL:
11464 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11465 declaration and if the declaration was never even referenced from
11466 within this entire compilation unit. We suppress these DIEs in
11467 order to save space in the .debug section (by eliminating entries
11468 which are probably useless). Note that we must not suppress
11469 block-local extern declarations (whether used or not) because that
11470 would screw-up the debugger's name lookup mechanism and cause it to
11471 miss things which really ought to be in scope at a given point. */
11472 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11473 return;
11475 /* If we are in terse mode, don't generate any DIEs to represent any
11476 variable declarations or definitions. */
11477 if (debug_info_level <= DINFO_LEVEL_TERSE)
11478 return;
11479 break;
11481 case TYPE_DECL:
11482 /* Don't emit stubs for types unless they are needed by other DIEs. */
11483 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11484 return;
11486 /* Don't bother trying to generate any DIEs to represent any of the
11487 normal built-in types for the language we are compiling. */
11488 if (DECL_SOURCE_LINE (decl) == 0)
11490 /* OK, we need to generate one for `bool' so GDB knows what type
11491 comparisons have. */
11492 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11493 == DW_LANG_C_plus_plus)
11494 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
11495 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11497 return;
11500 /* If we are in terse mode, don't generate any DIEs for types. */
11501 if (debug_info_level <= DINFO_LEVEL_TERSE)
11502 return;
11504 /* If we're a function-scope tag, initially use a parent of NULL;
11505 this will be fixed up in decls_for_scope. */
11506 if (decl_function_context (decl))
11507 context_die = NULL;
11509 break;
11511 default:
11512 return;
11515 gen_decl_die (decl, context_die);
11518 /* Output a marker (i.e. a label) for the beginning of the generated code for
11519 a lexical block. */
11521 void
11522 dwarf2out_begin_block (blocknum)
11523 register unsigned blocknum;
11525 function_section (current_function_decl);
11526 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11529 /* Output a marker (i.e. a label) for the end of the generated code for a
11530 lexical block. */
11532 void
11533 dwarf2out_end_block (blocknum)
11534 register unsigned blocknum;
11536 function_section (current_function_decl);
11537 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11540 /* Returns nonzero if it is appropriate not to emit any debugging
11541 information for BLOCK, because it doesn't contain any instructions.
11543 Don't allow this for blocks with nested functions or local classes
11544 as we would end up with orphans, and in the presence of scheduling
11545 we may end up calling them anyway. */
11548 dwarf2out_ignore_block (block)
11549 tree block;
11551 tree decl;
11552 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11553 if (TREE_CODE (decl) == FUNCTION_DECL
11554 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11555 return 0;
11556 return 1;
11559 /* Lookup a filename (in the list of filenames that we know about here in
11560 dwarf2out.c) and return its "index". The index of each (known) filename is
11561 just a unique number which is associated with only that one filename.
11562 We need such numbers for the sake of generating labels
11563 (in the .debug_sfnames section) and references to those
11564 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
11565 If the filename given as an argument is not found in our current list,
11566 add it to the list and assign it the next available unique index number.
11567 In order to speed up searches, we remember the index of the filename
11568 was looked up last. This handles the majority of all searches. */
11570 static unsigned
11571 lookup_filename (t, file_name)
11572 struct file_table *t;
11573 const char *file_name;
11575 register unsigned i;
11577 /* Check to see if the file name that was searched on the previous
11578 call matches this file name. If so, return the index. */
11579 if (t->last_lookup_index != 0)
11580 if (strcmp (file_name, t->table[t->last_lookup_index]) == 0)
11581 return t->last_lookup_index;
11583 /* Didn't match the previous lookup, search the table */
11584 for (i = 1; i < t->in_use; ++i)
11585 if (strcmp (file_name, t->table[i]) == 0)
11587 t->last_lookup_index = i;
11588 return i;
11591 /* Prepare to add a new table entry by making sure there is enough space in
11592 the table to do so. If not, expand the current table. */
11593 if (i == t->allocated)
11595 t->allocated = i + FILE_TABLE_INCREMENT;
11596 t->table = (char **)
11597 xrealloc (t->table, t->allocated * sizeof (char *));
11600 /* Add the new entry to the end of the filename table. */
11601 t->table[i] = xstrdup (file_name);
11602 t->in_use = i + 1;
11603 t->last_lookup_index = i;
11605 return i;
11608 static void
11609 init_file_table (t)
11610 struct file_table *t;
11612 /* Allocate the initial hunk of the file_table. */
11613 t->table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11614 t->allocated = FILE_TABLE_INCREMENT;
11616 /* Skip the first entry - file numbers begin at 1. */
11617 t->in_use = 1;
11618 t->last_lookup_index = 0;
11621 /* Output a label to mark the beginning of a source code line entry
11622 and record information relating to this source line, in
11623 'line_info_table' for later output of the .debug_line section. */
11625 void
11626 dwarf2out_line (filename, line)
11627 register const char *filename;
11628 register unsigned line;
11630 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11632 function_section (current_function_decl);
11634 if (DWARF2_ASM_LINE_DEBUG_INFO)
11636 #if 0
11637 unsigned old_in_use = line_file_table.in_use;
11638 #endif
11639 unsigned file_num = lookup_filename (&line_file_table, filename);
11641 /* Emit the .file and .loc directives understood by GNU as. */
11642 #if 0
11643 /* ??? As of 2000-11-25, gas has a bug in which it doesn't
11644 actually use the file number argument. It merely remembers
11645 the last .file directive emitted. */
11646 if (file_num >= old_in_use)
11647 fprintf (asm_out_file, "\t.file %d \"%s\"\n", file_num, filename);
11648 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11649 #else
11650 static unsigned int last_file_num;
11651 if (file_num != last_file_num)
11653 last_file_num = file_num;
11654 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
11656 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
11657 #endif
11659 /* Indicate that line number info exists. */
11660 ++line_info_table_in_use;
11662 /* Indicate that multiple line number tables exist. */
11663 if (DECL_SECTION_NAME (current_function_decl))
11664 ++separate_line_info_table_in_use;
11666 else if (DECL_SECTION_NAME (current_function_decl))
11668 register dw_separate_line_info_ref line_info;
11669 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11670 separate_line_info_table_in_use);
11671 if (flag_debug_asm)
11672 fprintf (asm_out_file, "\t%s %s:%d", ASM_COMMENT_START,
11673 filename, line);
11674 fputc ('\n', asm_out_file);
11676 /* expand the line info table if necessary */
11677 if (separate_line_info_table_in_use
11678 == separate_line_info_table_allocated)
11680 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11681 separate_line_info_table
11682 = (dw_separate_line_info_ref)
11683 xrealloc (separate_line_info_table,
11684 separate_line_info_table_allocated
11685 * sizeof (dw_separate_line_info_entry));
11688 /* Add the new entry at the end of the line_info_table. */
11689 line_info
11690 = &separate_line_info_table[separate_line_info_table_in_use++];
11691 line_info->dw_file_num = lookup_filename (&line_file_table, filename);
11692 line_info->dw_line_num = line;
11693 line_info->function = current_funcdef_number;
11695 else
11697 register dw_line_info_ref line_info;
11699 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11700 line_info_table_in_use);
11701 if (flag_debug_asm)
11702 fprintf (asm_out_file, "\t%s %s:%d", ASM_COMMENT_START,
11703 filename, line);
11704 fputc ('\n', asm_out_file);
11706 /* Expand the line info table if necessary. */
11707 if (line_info_table_in_use == line_info_table_allocated)
11709 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11710 line_info_table
11711 = (dw_line_info_ref)
11712 xrealloc (line_info_table,
11713 (line_info_table_allocated
11714 * sizeof (dw_line_info_entry)));
11717 /* Add the new entry at the end of the line_info_table. */
11718 line_info = &line_info_table[line_info_table_in_use++];
11719 line_info->dw_file_num = lookup_filename (&line_file_table, filename);
11720 line_info->dw_line_num = line;
11725 /* Record the beginning of a new source file, for later output
11726 of the .debug_macinfo section. At present, unimplemented. */
11728 void
11729 dwarf2out_start_source_file (filename)
11730 register const char *filename ATTRIBUTE_UNUSED;
11732 if (flag_eliminate_dwarf2_dups)
11734 /* Record the beginning of the file for break_out_includes. */
11735 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11736 add_AT_string (bincl_die, DW_AT_name, filename);
11740 /* Record the end of a source file, for later output
11741 of the .debug_macinfo section. At present, unimplemented. */
11743 void
11744 dwarf2out_end_source_file ()
11746 if (flag_eliminate_dwarf2_dups)
11748 /* Record the end of the file for break_out_includes. */
11749 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11753 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11754 the tail part of the directive line, i.e. the part which is past the
11755 initial whitespace, #, whitespace, directive-name, whitespace part. */
11757 void
11758 dwarf2out_define (lineno, buffer)
11759 register unsigned lineno ATTRIBUTE_UNUSED;
11760 register const char *buffer ATTRIBUTE_UNUSED;
11762 static int initialized = 0;
11763 if (!initialized)
11765 dwarf2out_start_source_file (primary_filename);
11766 initialized = 1;
11770 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11771 the tail part of the directive line, i.e. the part which is past the
11772 initial whitespace, #, whitespace, directive-name, whitespace part. */
11774 void
11775 dwarf2out_undef (lineno, buffer)
11776 register unsigned lineno ATTRIBUTE_UNUSED;
11777 register const char *buffer ATTRIBUTE_UNUSED;
11781 /* Set up for Dwarf output at the start of compilation. */
11783 void
11784 dwarf2out_init (asm_out_file, main_input_filename)
11785 register FILE *asm_out_file;
11786 register const char *main_input_filename;
11788 /* Remember the name of the primary input file. */
11789 primary_filename = main_input_filename;
11791 init_file_table (&decl_file_table);
11792 init_file_table (&line_file_table);
11794 /* Allocate the initial hunk of the decl_die_table. */
11795 decl_die_table
11796 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11797 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11798 decl_die_table_in_use = 0;
11800 /* Allocate the initial hunk of the decl_scope_table. */
11801 decl_scope_table
11802 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11803 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11804 decl_scope_depth = 0;
11806 /* Allocate the initial hunk of the abbrev_die_table. */
11807 abbrev_die_table
11808 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11809 sizeof (dw_die_ref));
11810 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11811 /* Zero-th entry is allocated, but unused */
11812 abbrev_die_table_in_use = 1;
11814 /* Allocate the initial hunk of the line_info_table. */
11815 line_info_table
11816 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11817 sizeof (dw_line_info_entry));
11818 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11819 /* Zero-th entry is allocated, but unused */
11820 line_info_table_in_use = 1;
11822 /* Generate the initial DIE for the .debug section. Note that the (string)
11823 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11824 will (typically) be a relative pathname and that this pathname should be
11825 taken as being relative to the directory from which the compiler was
11826 invoked when the given (base) source file was compiled. */
11827 comp_unit_die = gen_compile_unit_die (main_input_filename);
11829 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11830 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11832 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11833 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
11834 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11835 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11836 else
11837 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11838 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11839 DEBUG_INFO_SECTION_LABEL, 0);
11840 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11841 DEBUG_LINE_SECTION_LABEL, 0);
11843 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11844 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11845 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11847 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11848 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11850 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
11851 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11852 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11853 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11856 /* Output stuff that dwarf requires at the end of every file,
11857 and generate the DWARF-2 debugging info. */
11859 void
11860 dwarf2out_finish ()
11862 limbo_die_node *node, *next_node;
11863 dw_die_ref die;
11865 /* Traverse the limbo die list, and add parent/child links. The only
11866 dies without parents that should be here are concrete instances of
11867 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11868 For concrete instances, we can get the parent die from the abstract
11869 instance. */
11870 for (node = limbo_die_list; node; node = next_node)
11872 next_node = node->next;
11873 die = node->die;
11875 if (die->die_parent == NULL)
11877 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11878 if (origin)
11879 add_child_die (origin->die_parent, die);
11880 else if (die == comp_unit_die)
11882 else
11883 abort ();
11885 free (node);
11887 limbo_die_list = NULL;
11889 /* Walk through the list of incomplete types again, trying once more to
11890 emit full debugging info for them. */
11891 retry_incomplete_types ();
11893 /* We need to reverse all the dies before break_out_includes, or
11894 we'll see the end of an include file before the beginning. */
11895 reverse_all_dies (comp_unit_die);
11897 /* Generate separate CUs for each of the include files we've seen.
11898 They will go into limbo_die_list. */
11899 if (flag_eliminate_dwarf2_dups)
11900 break_out_includes (comp_unit_die);
11902 /* Traverse the DIE's and add add sibling attributes to those DIE's
11903 that have children. */
11904 add_sibling_attributes (comp_unit_die);
11905 for (node = limbo_die_list; node; node = node->next)
11906 add_sibling_attributes (node->die);
11908 /* Output a terminator label for the .text section. */
11909 fputc ('\n', asm_out_file);
11910 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11911 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11913 #if 0
11914 /* Output a terminator label for the .data section. */
11915 fputc ('\n', asm_out_file);
11916 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11917 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11919 /* Output a terminator label for the .bss section. */
11920 fputc ('\n', asm_out_file);
11921 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11922 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11923 #endif
11925 /* Output the source line correspondence table. */
11926 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
11928 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11930 fputc ('\n', asm_out_file);
11931 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11932 output_line_info ();
11935 /* We can only use the low/high_pc attributes if all of the code
11936 was in .text. */
11937 if (separate_line_info_table_in_use == 0)
11939 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11940 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11943 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11944 debug_line_section_label);
11947 #if 0 /* unimplemented */
11948 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
11949 add_AT_unsigned (die, DW_AT_macro_info, 0);
11950 #endif
11952 /* Output all of the compilation units. We put the main one last so that
11953 the offsets are available to output_pubnames. */
11954 for (node = limbo_die_list; node; node = node->next)
11955 output_comp_unit (node->die);
11956 output_comp_unit (comp_unit_die);
11958 /* Output the abbreviation table. */
11959 fputc ('\n', asm_out_file);
11960 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11961 output_abbrev_section ();
11963 if (pubname_table_in_use)
11965 /* Output public names table. */
11966 fputc ('\n', asm_out_file);
11967 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
11968 output_pubnames ();
11971 /* We only put functions in the arange table, so don't write it out if
11972 we don't have any. */
11973 if (fde_table_in_use)
11975 /* Output the address range information. */
11976 fputc ('\n', asm_out_file);
11977 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
11978 output_aranges ();
11981 #endif /* DWARF2_DEBUGGING_INFO */