* configure.in: Arrange to include defaults.h in [ht]config.h/tm.h.
[official-gcc.git] / gcc / dwarf2out.c
blob0bd968c80774bfb49befb01f888bd1f492b9b8be
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 /* Decide whether we want to emit frame unwind information for the current
59 translation unit. */
61 int
62 dwarf2out_do_frame ()
64 return (write_symbols == DWARF2_DEBUG
65 #ifdef DWARF2_FRAME_INFO
66 || DWARF2_FRAME_INFO
67 #endif
68 #ifdef DWARF2_UNWIND_INFO
69 || flag_unwind_tables
70 || (flag_exceptions && ! exceptions_via_longjmp)
71 #endif
75 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
77 /* How to start an assembler comment. */
78 #ifndef ASM_COMMENT_START
79 #define ASM_COMMENT_START ";#"
80 #endif
82 typedef struct dw_cfi_struct *dw_cfi_ref;
83 typedef struct dw_fde_struct *dw_fde_ref;
84 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
86 /* Call frames are described using a sequence of Call Frame
87 Information instructions. The register number, offset
88 and address fields are provided as possible operands;
89 their use is selected by the opcode field. */
91 typedef union dw_cfi_oprnd_struct
93 unsigned long dw_cfi_reg_num;
94 long int dw_cfi_offset;
95 const char *dw_cfi_addr;
96 struct dw_loc_descr_struct *dw_cfi_loc;
98 dw_cfi_oprnd;
100 typedef struct dw_cfi_struct
102 dw_cfi_ref dw_cfi_next;
103 enum dwarf_call_frame_info dw_cfi_opc;
104 dw_cfi_oprnd dw_cfi_oprnd1;
105 dw_cfi_oprnd dw_cfi_oprnd2;
107 dw_cfi_node;
109 /* This is how we define the location of the CFA. We use to handle it
110 as REG + OFFSET all the time, but now it can be more complex.
111 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
112 Instead of passing around REG and OFFSET, we pass a copy
113 of this structure. */
114 typedef struct cfa_loc
116 unsigned long reg;
117 long offset;
118 long base_offset;
119 int indirect; /* 1 if CFA is accessed via a dereference. */
120 } dw_cfa_location;
122 /* All call frame descriptions (FDE's) in the GCC generated DWARF
123 refer to a single Common Information Entry (CIE), defined at
124 the beginning of the .debug_frame section. This used of a single
125 CIE obviates the need to keep track of multiple CIE's
126 in the DWARF generation routines below. */
128 typedef struct dw_fde_struct
130 const char *dw_fde_begin;
131 const char *dw_fde_current_label;
132 const char *dw_fde_end;
133 dw_cfi_ref dw_fde_cfi;
134 int nothrow;
136 dw_fde_node;
138 /* Maximum size (in bytes) of an artificially generated label. */
139 #define MAX_ARTIFICIAL_LABEL_BYTES 30
141 /* The size of the target's pointer type. */
142 #ifndef PTR_SIZE
143 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
144 #endif
146 /* The size of addresses as they appear in the Dwarf 2 data.
147 Some architectures use word addresses to refer to code locations,
148 but Dwarf 2 info always uses byte addresses. On such machines,
149 Dwarf 2 addresses need to be larger than the architecture's
150 pointers. */
151 #ifndef DWARF2_ADDR_SIZE
152 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
153 #endif
155 /* The size in bytes of a DWARF field indicating an offset or length
156 relative to a debug info section, specified to be 4 bytes in the
157 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
158 as PTR_SIZE. */
160 #ifndef DWARF_OFFSET_SIZE
161 #define DWARF_OFFSET_SIZE 4
162 #endif
164 #define DWARF_VERSION 2
166 /* Round SIZE up to the nearest BOUNDARY. */
167 #define DWARF_ROUND(SIZE,BOUNDARY) \
168 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
170 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
171 #ifndef DWARF_CIE_DATA_ALIGNMENT
172 #ifdef STACK_GROWS_DOWNWARD
173 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
174 #else
175 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
176 #endif
177 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
179 /* A pointer to the base of a table that contains frame description
180 information for each routine. */
181 static dw_fde_ref fde_table;
183 /* Number of elements currently allocated for fde_table. */
184 static unsigned fde_table_allocated;
186 /* Number of elements in fde_table currently in use. */
187 static unsigned fde_table_in_use;
189 /* Size (in elements) of increments by which we may expand the
190 fde_table. */
191 #define FDE_TABLE_INCREMENT 256
193 /* A list of call frame insns for the CIE. */
194 static dw_cfi_ref cie_cfi_head;
196 /* The number of the current function definition for which debugging
197 information is being generated. These numbers range from 1 up to the
198 maximum number of function definitions contained within the current
199 compilation unit. These numbers are used to create unique label id's
200 unique to each function definition. */
201 static unsigned current_funcdef_number = 0;
203 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
204 attribute that accelerates the lookup of the FDE associated
205 with the subprogram. This variable holds the table index of the FDE
206 associated with the current function (body) definition. */
207 static unsigned current_funcdef_fde;
209 /* Forward declarations for functions defined in this file. */
211 static char *stripattributes PARAMS ((const char *));
212 static const char *dwarf_cfi_name PARAMS ((unsigned));
213 static dw_cfi_ref new_cfi PARAMS ((void));
214 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
215 static unsigned long size_of_uleb128 PARAMS ((unsigned long));
216 static unsigned long size_of_sleb128 PARAMS ((long));
217 static void output_uleb128 PARAMS ((unsigned long));
218 static void output_sleb128 PARAMS ((long));
219 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
220 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
221 static void lookup_cfa PARAMS ((dw_cfa_location *));
222 static void reg_save PARAMS ((const char *, unsigned,
223 unsigned, long));
224 static void initial_return_save PARAMS ((rtx));
225 static long stack_adjust_offset PARAMS ((rtx));
226 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref));
227 static void output_call_frame_info PARAMS ((int));
228 static void dwarf2out_stack_adjust PARAMS ((rtx));
229 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
231 /* Support for complex CFA locations. */
232 static void output_cfa_loc PARAMS ((dw_cfi_ref));
233 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
234 struct dw_loc_descr_struct *));
235 static struct dw_loc_descr_struct *build_cfa_loc
236 PARAMS ((dw_cfa_location *));
237 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
239 /* Definitions of defaults for assembler-dependent names of various
240 pseudo-ops and section names.
241 Theses may be overridden in the tm.h file (if necessary) for a particular
242 assembler. */
244 #ifdef OBJECT_FORMAT_ELF
245 #ifndef UNALIGNED_SHORT_ASM_OP
246 #define UNALIGNED_SHORT_ASM_OP "\t.2byte\t"
247 #endif
248 #ifndef UNALIGNED_INT_ASM_OP
249 #define UNALIGNED_INT_ASM_OP "\t.4byte\t"
250 #endif
251 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
252 #define UNALIGNED_DOUBLE_INT_ASM_OP "\t.8byte\t"
253 #endif
254 #endif /* OBJECT_FORMAT_ELF */
256 #ifndef ASM_BYTE_OP
257 #define ASM_BYTE_OP "\t.byte\t"
258 #endif
260 /* Data and reference forms for relocatable data. */
261 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
262 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
264 /* Pseudo-op for defining a new section. */
265 #ifndef SECTION_ASM_OP
266 #define SECTION_ASM_OP "\t.section\t"
267 #endif
269 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
270 print the SECTION_ASM_OP and the section name. The default here works for
271 almost all svr4 assemblers, except for the sparc, where the section name
272 must be enclosed in double quotes. (See sparcv4.h). */
273 #ifndef SECTION_FORMAT
274 #ifdef PUSHSECTION_FORMAT
275 #define SECTION_FORMAT PUSHSECTION_FORMAT
276 #else
277 #define SECTION_FORMAT "%s%s\n"
278 #endif
279 #endif
281 #ifndef FRAME_SECTION
282 #define FRAME_SECTION ".debug_frame"
283 #endif
285 #ifndef FUNC_BEGIN_LABEL
286 #define FUNC_BEGIN_LABEL "LFB"
287 #endif
288 #ifndef FUNC_END_LABEL
289 #define FUNC_END_LABEL "LFE"
290 #endif
291 #define CIE_AFTER_SIZE_LABEL "LSCIE"
292 #define CIE_END_LABEL "LECIE"
293 #define CIE_LENGTH_LABEL "LLCIE"
294 #define FDE_AFTER_SIZE_LABEL "LSFDE"
295 #define FDE_END_LABEL "LEFDE"
296 #define FDE_LENGTH_LABEL "LLFDE"
297 #define DIE_LABEL_PREFIX "DW"
299 /* Definitions of defaults for various types of primitive assembly language
300 output operations. These may be overridden from within the tm.h file,
301 but typically, that is unnecessary. */
303 #ifndef ASM_OUTPUT_SECTION
304 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
305 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
306 #endif
308 #ifndef ASM_OUTPUT_DWARF_DATA1
309 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
310 fprintf ((FILE), "%s0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
311 #endif
313 #ifndef ASM_OUTPUT_DWARF_DELTA1
314 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
315 do { fprintf ((FILE), "%s", ASM_BYTE_OP); \
316 assemble_name (FILE, LABEL1); \
317 fprintf (FILE, "-"); \
318 assemble_name (FILE, LABEL2); \
319 } while (0)
320 #endif
322 #ifdef UNALIGNED_INT_ASM_OP
324 #ifndef UNALIGNED_OFFSET_ASM_OP
325 #define UNALIGNED_OFFSET_ASM_OP \
326 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
327 #endif
329 #ifndef UNALIGNED_WORD_ASM_OP
330 #define UNALIGNED_WORD_ASM_OP \
331 ((DWARF2_ADDR_SIZE) == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP \
332 : (DWARF2_ADDR_SIZE) == 2 ? UNALIGNED_SHORT_ASM_OP \
333 : UNALIGNED_INT_ASM_OP)
334 #endif
336 #ifndef ASM_OUTPUT_DWARF_DELTA2
337 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
338 do { fprintf ((FILE), "%s", UNALIGNED_SHORT_ASM_OP); \
339 assemble_name (FILE, LABEL1); \
340 fprintf (FILE, "-"); \
341 assemble_name (FILE, LABEL2); \
342 } while (0)
343 #endif
345 #ifndef ASM_OUTPUT_DWARF_DELTA4
346 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
347 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
348 assemble_name (FILE, LABEL1); \
349 fprintf (FILE, "-"); \
350 assemble_name (FILE, LABEL2); \
351 } while (0)
352 #endif
354 #ifndef ASM_OUTPUT_DWARF_DELTA
355 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
356 do { fprintf ((FILE), "%s", UNALIGNED_OFFSET_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_ADDR_DELTA
364 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
365 do { fprintf ((FILE), "%s", UNALIGNED_WORD_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_ADDR
373 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
374 do { fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
375 assemble_name (FILE, LABEL); \
376 } while (0)
377 #endif
379 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
380 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
381 do { \
382 fprintf ((FILE), "%s", UNALIGNED_WORD_ASM_OP); \
383 output_addr_const ((FILE), (RTX)); \
384 } while (0)
385 #endif
387 #ifndef ASM_OUTPUT_DWARF_OFFSET4
388 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
389 do { fprintf ((FILE), "%s", UNALIGNED_INT_ASM_OP); \
390 assemble_name (FILE, LABEL); \
391 } while (0)
392 #endif
394 #ifndef ASM_OUTPUT_DWARF_OFFSET
395 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
396 do { fprintf ((FILE), "%s", UNALIGNED_OFFSET_ASM_OP); \
397 assemble_name (FILE, LABEL); \
398 } while (0)
399 #endif
401 #ifndef ASM_OUTPUT_DWARF_DATA2
402 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
403 fprintf ((FILE), "%s0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
404 #endif
406 #ifndef ASM_OUTPUT_DWARF_DATA4
407 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
408 fprintf ((FILE), "%s0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
409 #endif
411 #ifndef ASM_OUTPUT_DWARF_DATA8
412 #define ASM_OUTPUT_DWARF_DATA8(FILE,VALUE) \
413 fprintf ((FILE), "%s0x%lx", UNALIGNED_DOUBLE_INT_ASM_OP, \
414 (unsigned long) (VALUE))
415 #endif
417 #ifndef ASM_OUTPUT_DWARF_DATA
418 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
419 fprintf ((FILE), "%s0x%lx", UNALIGNED_OFFSET_ASM_OP, \
420 (unsigned long) (VALUE))
421 #endif
423 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
424 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
425 fprintf ((FILE), "%s0x%lx", UNALIGNED_WORD_ASM_OP, \
426 (unsigned long) (VALUE))
427 #endif
429 #ifndef ASM_OUTPUT_DWARF_CONST_DOUBLE
430 #define ASM_OUTPUT_DWARF_CONST_DOUBLE(FILE,HIGH_VALUE,LOW_VALUE) \
431 do { \
432 if (WORDS_BIG_ENDIAN) \
434 fprintf ((FILE), "%s0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
435 fprintf ((FILE), "%s0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
437 else \
439 fprintf ((FILE), "%s0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
440 fprintf ((FILE), "%s0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
442 } while (0)
443 #endif
445 #else /* UNALIGNED_INT_ASM_OP */
447 /* We don't have unaligned support, let's hope the normal output works for
448 .debug_frame. But we know it won't work for .debug_info. */
450 #ifdef DWARF2_DEBUGGING_INFO
451 #error DWARF2_DEBUGGING_INFO requires UNALIGNED_INT_ASM_OP.
452 #endif
454 #ifndef ASM_OUTPUT_DWARF_ADDR
455 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
456 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), DWARF2_ADDR_SIZE, 1)
457 #endif
459 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
460 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) ASM_OUTPUT_DWARF_ADDR (FILE,RTX)
461 #endif
463 #ifndef ASM_OUTPUT_DWARF_OFFSET4
464 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
465 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
466 #endif
468 #ifndef ASM_OUTPUT_DWARF_OFFSET
469 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
470 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
471 #endif
473 #ifndef ASM_OUTPUT_DWARF_DELTA2
474 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
475 assemble_integer (gen_rtx_MINUS (HImode, \
476 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
477 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
478 2, 1)
479 #endif
481 #ifndef ASM_OUTPUT_DWARF_DELTA4
482 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
483 assemble_integer (gen_rtx_MINUS (SImode, \
484 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
485 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
486 4, 1)
487 #endif
489 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
490 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
491 assemble_integer (gen_rtx_MINUS (Pmode, \
492 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
493 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
494 DWARF2_ADDR_SIZE, 1)
495 #endif
497 #ifndef ASM_OUTPUT_DWARF_DELTA
498 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
499 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
500 #endif
502 #ifndef ASM_OUTPUT_DWARF_DATA2
503 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
504 assemble_integer (GEN_INT (VALUE), 2, 1)
505 #endif
507 #ifndef ASM_OUTPUT_DWARF_DATA4
508 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
509 assemble_integer (GEN_INT (VALUE), 4, 1)
510 #endif
512 #endif /* UNALIGNED_INT_ASM_OP */
514 #ifdef SET_ASM_OP
515 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
516 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
517 do { \
518 fprintf (FILE, "%s", SET_ASM_OP); \
519 assemble_name (FILE, SY); \
520 fputc (',', FILE); \
521 assemble_name (FILE, HI); \
522 fputc ('-', FILE); \
523 assemble_name (FILE, LO); \
524 } while (0)
525 #endif
526 #endif /* SET_ASM_OP */
528 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
529 newline is produced. When flag_debug_asm is asserted, we add commentary
530 at the end of the line, so we must avoid output of a newline here. */
531 #ifndef ASM_OUTPUT_DWARF_NSTRING
532 #define ASM_OUTPUT_DWARF_NSTRING(FILE,P,SLEN) \
533 do { \
534 register int slen = (SLEN); \
535 register const char *p = (P); \
536 register int i; \
537 fprintf (FILE, "\t.ascii \""); \
538 for (i = 0; i < slen; i++) \
540 register int c = p[i]; \
541 if (c == '\"' || c == '\\') \
542 putc ('\\', FILE); \
543 if (ISPRINT(c)) \
544 putc (c, FILE); \
545 else \
547 fprintf (FILE, "\\%o", c); \
550 fprintf (FILE, "\\0\""); \
552 while (0)
553 #endif
554 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
555 ASM_OUTPUT_DWARF_NSTRING (FILE, P, strlen (P))
557 /* The DWARF 2 CFA column which tracks the return address. Normally this
558 is the column for PC, or the first column after all of the hard
559 registers. */
560 #ifndef DWARF_FRAME_RETURN_COLUMN
561 #ifdef PC_REGNUM
562 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
563 #else
564 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
565 #endif
566 #endif
568 /* The mapping from gcc register number to DWARF 2 CFA column number. By
569 default, we just provide columns for all registers. */
570 #ifndef DWARF_FRAME_REGNUM
571 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
572 #endif
574 /* Hook used by __throw. */
577 expand_builtin_dwarf_fp_regnum ()
579 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
582 /* The offset from the incoming value of %sp to the top of the stack frame
583 for the current function. */
584 #ifndef INCOMING_FRAME_SP_OFFSET
585 #define INCOMING_FRAME_SP_OFFSET 0
586 #endif
588 /* Return a pointer to a copy of the section string name S with all
589 attributes stripped off, and an asterisk prepended (for assemble_name). */
591 static inline char *
592 stripattributes (s)
593 const char *s;
595 char *stripped = xmalloc (strlen (s) + 2);
596 char *p = stripped;
598 *p++ = '*';
600 while (*s && *s != ',')
601 *p++ = *s++;
603 *p = '\0';
604 return stripped;
607 /* Generate code to initialize the register size table. */
609 void
610 expand_builtin_init_dwarf_reg_sizes (address)
611 tree address;
613 int i;
614 enum machine_mode mode = TYPE_MODE (char_type_node);
615 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
616 rtx mem = gen_rtx_MEM (mode, addr);
618 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
620 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
621 int size = GET_MODE_SIZE (reg_raw_mode[i]);
623 if (offset < 0)
624 continue;
626 emit_move_insn (change_address (mem, mode,
627 plus_constant (addr, offset)),
628 GEN_INT (size));
632 /* Convert a DWARF call frame info. operation to its string name */
634 static const char *
635 dwarf_cfi_name (cfi_opc)
636 register unsigned cfi_opc;
638 switch (cfi_opc)
640 case DW_CFA_advance_loc:
641 return "DW_CFA_advance_loc";
642 case DW_CFA_offset:
643 return "DW_CFA_offset";
644 case DW_CFA_restore:
645 return "DW_CFA_restore";
646 case DW_CFA_nop:
647 return "DW_CFA_nop";
648 case DW_CFA_set_loc:
649 return "DW_CFA_set_loc";
650 case DW_CFA_advance_loc1:
651 return "DW_CFA_advance_loc1";
652 case DW_CFA_advance_loc2:
653 return "DW_CFA_advance_loc2";
654 case DW_CFA_advance_loc4:
655 return "DW_CFA_advance_loc4";
656 case DW_CFA_offset_extended:
657 return "DW_CFA_offset_extended";
658 case DW_CFA_restore_extended:
659 return "DW_CFA_restore_extended";
660 case DW_CFA_undefined:
661 return "DW_CFA_undefined";
662 case DW_CFA_same_value:
663 return "DW_CFA_same_value";
664 case DW_CFA_register:
665 return "DW_CFA_register";
666 case DW_CFA_remember_state:
667 return "DW_CFA_remember_state";
668 case DW_CFA_restore_state:
669 return "DW_CFA_restore_state";
670 case DW_CFA_def_cfa:
671 return "DW_CFA_def_cfa";
672 case DW_CFA_def_cfa_register:
673 return "DW_CFA_def_cfa_register";
674 case DW_CFA_def_cfa_offset:
675 return "DW_CFA_def_cfa_offset";
676 case DW_CFA_def_cfa_expression:
677 return "DW_CFA_def_cfa_expression";
679 /* SGI/MIPS specific */
680 case DW_CFA_MIPS_advance_loc8:
681 return "DW_CFA_MIPS_advance_loc8";
683 /* GNU extensions */
684 case DW_CFA_GNU_window_save:
685 return "DW_CFA_GNU_window_save";
686 case DW_CFA_GNU_args_size:
687 return "DW_CFA_GNU_args_size";
688 case DW_CFA_GNU_negative_offset_extended:
689 return "DW_CFA_GNU_negative_offset_extended";
691 default:
692 return "DW_CFA_<unknown>";
696 /* Return a pointer to a newly allocated Call Frame Instruction. */
698 static inline dw_cfi_ref
699 new_cfi ()
701 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
703 cfi->dw_cfi_next = NULL;
704 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
705 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
707 return cfi;
710 /* Add a Call Frame Instruction to list of instructions. */
712 static inline void
713 add_cfi (list_head, cfi)
714 register dw_cfi_ref *list_head;
715 register dw_cfi_ref cfi;
717 register dw_cfi_ref *p;
719 /* Find the end of the chain. */
720 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
723 *p = cfi;
726 /* Generate a new label for the CFI info to refer to. */
728 char *
729 dwarf2out_cfi_label ()
731 static char label[20];
732 static unsigned long label_num = 0;
734 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
735 ASM_OUTPUT_LABEL (asm_out_file, label);
737 return label;
740 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
741 or to the CIE if LABEL is NULL. */
743 static void
744 add_fde_cfi (label, cfi)
745 register const char *label;
746 register dw_cfi_ref cfi;
748 if (label)
750 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
752 if (*label == 0)
753 label = dwarf2out_cfi_label ();
755 if (fde->dw_fde_current_label == NULL
756 || strcmp (label, fde->dw_fde_current_label) != 0)
758 register dw_cfi_ref xcfi;
760 fde->dw_fde_current_label = label = xstrdup (label);
762 /* Set the location counter to the new label. */
763 xcfi = new_cfi ();
764 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
765 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
766 add_cfi (&fde->dw_fde_cfi, xcfi);
769 add_cfi (&fde->dw_fde_cfi, cfi);
772 else
773 add_cfi (&cie_cfi_head, cfi);
776 /* Subroutine of lookup_cfa. */
778 static inline void
779 lookup_cfa_1 (cfi, loc)
780 register dw_cfi_ref cfi;
781 register dw_cfa_location *loc;
783 switch (cfi->dw_cfi_opc)
785 case DW_CFA_def_cfa_offset:
786 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
787 break;
788 case DW_CFA_def_cfa_register:
789 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
790 break;
791 case DW_CFA_def_cfa:
792 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
793 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
794 break;
795 case DW_CFA_def_cfa_expression:
796 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
797 break;
798 default:
799 break;
803 /* Find the previous value for the CFA. */
805 static void
806 lookup_cfa (loc)
807 register dw_cfa_location *loc;
809 register dw_cfi_ref cfi;
811 loc->reg = (unsigned long) -1;
812 loc->offset = 0;
813 loc->indirect = 0;
814 loc->base_offset = 0;
816 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
817 lookup_cfa_1 (cfi, loc);
819 if (fde_table_in_use)
821 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
822 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
823 lookup_cfa_1 (cfi, loc);
827 /* The current rule for calculating the DWARF2 canonical frame address. */
828 dw_cfa_location cfa;
830 /* The register used for saving registers to the stack, and its offset
831 from the CFA. */
832 dw_cfa_location cfa_store;
834 /* The running total of the size of arguments pushed onto the stack. */
835 static long args_size;
837 /* The last args_size we actually output. */
838 static long old_args_size;
840 /* Entry point to update the canonical frame address (CFA).
841 LABEL is passed to add_fde_cfi. The value of CFA is now to be
842 calculated from REG+OFFSET. */
844 void
845 dwarf2out_def_cfa (label, reg, offset)
846 register const char *label;
847 unsigned reg;
848 long offset;
850 dw_cfa_location loc;
851 loc.indirect = 0;
852 loc.base_offset = 0;
853 loc.reg = reg;
854 loc.offset = offset;
855 def_cfa_1 (label, &loc);
858 /* This routine does the actual work. The CFA is now calculated from
859 the dw_cfa_location structure. */
860 static void
861 def_cfa_1 (label, loc_p)
862 register const char *label;
863 dw_cfa_location *loc_p;
865 register dw_cfi_ref cfi;
866 dw_cfa_location old_cfa, loc;
868 cfa = *loc_p;
869 loc = *loc_p;
871 if (cfa_store.reg == loc.reg && loc.indirect == 0)
872 cfa_store.offset = loc.offset;
874 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
875 lookup_cfa (&old_cfa);
877 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
878 loc.indirect == old_cfa.indirect)
880 if (loc.indirect == 0
881 || loc.base_offset == old_cfa.base_offset)
882 return;
885 cfi = new_cfi ();
887 if (loc.reg == old_cfa.reg && !loc.indirect)
889 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
890 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
893 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
894 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
895 && !loc.indirect)
897 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
898 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
900 #endif
902 else if (loc.indirect == 0)
904 cfi->dw_cfi_opc = DW_CFA_def_cfa;
905 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
906 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
908 else
910 struct dw_loc_descr_struct *loc_list;
911 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
912 loc_list = build_cfa_loc (&loc);
913 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
916 add_fde_cfi (label, cfi);
919 /* Add the CFI for saving a register. REG is the CFA column number.
920 LABEL is passed to add_fde_cfi.
921 If SREG is -1, the register is saved at OFFSET from the CFA;
922 otherwise it is saved in SREG. */
924 static void
925 reg_save (label, reg, sreg, offset)
926 register const char *label;
927 register unsigned reg;
928 register unsigned sreg;
929 register long offset;
931 register dw_cfi_ref cfi = new_cfi ();
933 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
935 /* The following comparison is correct. -1 is used to indicate that
936 the value isn't a register number. */
937 if (sreg == (unsigned int) -1)
939 if (reg & ~0x3f)
940 /* The register number won't fit in 6 bits, so we have to use
941 the long form. */
942 cfi->dw_cfi_opc = DW_CFA_offset_extended;
943 else
944 cfi->dw_cfi_opc = DW_CFA_offset;
946 #ifdef ENABLE_CHECKING
948 /* If we get an offset that is not a multiple of
949 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
950 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
951 description. */
952 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
954 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
955 abort ();
957 #endif
958 offset /= DWARF_CIE_DATA_ALIGNMENT;
959 if (offset < 0)
961 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
962 offset = -offset;
964 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
966 else if (sreg == reg)
967 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
968 return;
969 else
971 cfi->dw_cfi_opc = DW_CFA_register;
972 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
975 add_fde_cfi (label, cfi);
978 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
979 This CFI tells the unwinder that it needs to restore the window registers
980 from the previous frame's window save area.
982 ??? Perhaps we should note in the CIE where windows are saved (instead of
983 assuming 0(cfa)) and what registers are in the window. */
985 void
986 dwarf2out_window_save (label)
987 register const char *label;
989 register dw_cfi_ref cfi = new_cfi ();
990 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
991 add_fde_cfi (label, cfi);
994 /* Add a CFI to update the running total of the size of arguments
995 pushed onto the stack. */
997 void
998 dwarf2out_args_size (label, size)
999 const char *label;
1000 long size;
1002 register dw_cfi_ref cfi;
1004 if (size == old_args_size)
1005 return;
1006 old_args_size = size;
1008 cfi = new_cfi ();
1009 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1010 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1011 add_fde_cfi (label, cfi);
1014 /* Entry point for saving a register to the stack. REG is the GCC register
1015 number. LABEL and OFFSET are passed to reg_save. */
1017 void
1018 dwarf2out_reg_save (label, reg, offset)
1019 register const char *label;
1020 register unsigned reg;
1021 register long offset;
1023 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
1026 /* Entry point for saving the return address in the stack.
1027 LABEL and OFFSET are passed to reg_save. */
1029 void
1030 dwarf2out_return_save (label, offset)
1031 register const char *label;
1032 register long offset;
1034 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
1037 /* Entry point for saving the return address in a register.
1038 LABEL and SREG are passed to reg_save. */
1040 void
1041 dwarf2out_return_reg (label, sreg)
1042 register const char *label;
1043 register unsigned sreg;
1045 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
1048 /* Record the initial position of the return address. RTL is
1049 INCOMING_RETURN_ADDR_RTX. */
1051 static void
1052 initial_return_save (rtl)
1053 register rtx rtl;
1055 unsigned int reg = (unsigned int) -1;
1056 long offset = 0;
1058 switch (GET_CODE (rtl))
1060 case REG:
1061 /* RA is in a register. */
1062 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1063 break;
1064 case MEM:
1065 /* RA is on the stack. */
1066 rtl = XEXP (rtl, 0);
1067 switch (GET_CODE (rtl))
1069 case REG:
1070 if (REGNO (rtl) != STACK_POINTER_REGNUM)
1071 abort ();
1072 offset = 0;
1073 break;
1074 case PLUS:
1075 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1076 abort ();
1077 offset = INTVAL (XEXP (rtl, 1));
1078 break;
1079 case MINUS:
1080 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
1081 abort ();
1082 offset = -INTVAL (XEXP (rtl, 1));
1083 break;
1084 default:
1085 abort ();
1087 break;
1088 case PLUS:
1089 /* The return address is at some offset from any value we can
1090 actually load. For instance, on the SPARC it is in %i7+8. Just
1091 ignore the offset for now; it doesn't matter for unwinding frames. */
1092 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
1093 abort ();
1094 initial_return_save (XEXP (rtl, 0));
1095 return;
1096 default:
1097 abort ();
1100 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1103 /* Given a SET, calculate the amount of stack adjustment it
1104 contains. */
1106 static long
1107 stack_adjust_offset (pattern)
1108 rtx pattern;
1110 rtx src = SET_SRC (pattern);
1111 rtx dest = SET_DEST (pattern);
1112 long offset = 0;
1113 enum rtx_code code;
1115 if (dest == stack_pointer_rtx)
1117 /* (set (reg sp) (plus (reg sp) (const_int))) */
1118 code = GET_CODE (src);
1119 if (! (code == PLUS || code == MINUS)
1120 || XEXP (src, 0) != stack_pointer_rtx
1121 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1122 return 0;
1124 offset = INTVAL (XEXP (src, 1));
1126 else if (GET_CODE (dest) == MEM)
1128 /* (set (mem (pre_dec (reg sp))) (foo)) */
1129 src = XEXP (dest, 0);
1130 code = GET_CODE (src);
1132 if (! (code == PRE_DEC || code == PRE_INC
1133 || code == PRE_MODIFY)
1134 || XEXP (src, 0) != stack_pointer_rtx)
1135 return 0;
1137 if (code == PRE_MODIFY)
1139 rtx val = XEXP (XEXP (src, 1), 1);
1140 /* We handle only adjustments by constant amount. */
1141 if (GET_CODE (XEXP (src, 1)) != PLUS ||
1142 GET_CODE (val) != CONST_INT)
1143 abort();
1144 offset = -INTVAL (val);
1146 else offset = GET_MODE_SIZE (GET_MODE (dest));
1148 else
1149 return 0;
1151 if (code == PLUS || code == PRE_INC)
1152 offset = -offset;
1154 return offset;
1157 /* Check INSN to see if it looks like a push or a stack adjustment, and
1158 make a note of it if it does. EH uses this information to find out how
1159 much extra space it needs to pop off the stack. */
1161 static void
1162 dwarf2out_stack_adjust (insn)
1163 rtx insn;
1165 long offset;
1166 const char *label;
1168 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1170 /* Extract the size of the args from the CALL rtx itself. */
1172 insn = PATTERN (insn);
1173 if (GET_CODE (insn) == PARALLEL)
1174 insn = XVECEXP (insn, 0, 0);
1175 if (GET_CODE (insn) == SET)
1176 insn = SET_SRC (insn);
1177 if (GET_CODE (insn) != CALL)
1178 abort ();
1179 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1180 return;
1183 /* If only calls can throw, and we have a frame pointer,
1184 save up adjustments until we see the CALL_INSN. */
1185 else if (! asynchronous_exceptions
1186 && cfa.reg != STACK_POINTER_REGNUM)
1187 return;
1189 if (GET_CODE (insn) == BARRIER)
1191 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1192 the compiler will have already emitted a stack adjustment, but
1193 doesn't bother for calls to noreturn functions. */
1194 #ifdef STACK_GROWS_DOWNWARD
1195 offset = -args_size;
1196 #else
1197 offset = args_size;
1198 #endif
1200 else if (GET_CODE (PATTERN (insn)) == SET)
1202 offset = stack_adjust_offset (PATTERN (insn));
1204 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1205 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1207 /* There may be stack adjustments inside compound insns. Search
1208 for them. */
1209 int j;
1211 offset = 0;
1212 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1214 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1215 if (GET_CODE (pattern) == SET)
1216 offset += stack_adjust_offset (pattern);
1219 else
1220 return;
1222 if (offset == 0)
1223 return;
1225 if (cfa.reg == STACK_POINTER_REGNUM)
1226 cfa.offset += offset;
1228 #ifndef STACK_GROWS_DOWNWARD
1229 offset = -offset;
1230 #endif
1231 args_size += offset;
1232 if (args_size < 0)
1233 args_size = 0;
1235 label = dwarf2out_cfi_label ();
1236 def_cfa_1 (label, &cfa);
1237 dwarf2out_args_size (label, args_size);
1240 /* A temporary register used in adjusting SP or setting up the store_reg. */
1241 static unsigned cfa_temp_reg;
1243 /* A temporary value used in adjusting SP or setting up the store_reg. */
1244 static long cfa_temp_value;
1246 /* Record call frame debugging information for an expression, which either
1247 sets SP or FP (adjusting how we calculate the frame address) or saves a
1248 register to the stack. */
1250 static void
1251 dwarf2out_frame_debug_expr (expr, label)
1252 rtx expr;
1253 const char *label;
1255 rtx src, dest;
1256 long offset;
1258 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1259 the PARALLEL independently. The first element is always processed if
1260 it is a SET. This is for backward compatability. Other elements
1261 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1262 flag is set in them. */
1264 if (GET_CODE (expr) == PARALLEL
1265 || GET_CODE (expr) == SEQUENCE)
1267 int par_index;
1268 int limit = XVECLEN (expr, 0);
1270 for (par_index = 0; par_index < limit; par_index++)
1272 rtx x = XVECEXP (expr, 0, par_index);
1274 if (GET_CODE (x) == SET &&
1275 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1276 dwarf2out_frame_debug_expr (x, label);
1278 return;
1281 if (GET_CODE (expr) != SET)
1282 abort ();
1284 src = SET_SRC (expr);
1285 dest = SET_DEST (expr);
1287 switch (GET_CODE (dest))
1289 case REG:
1290 /* Update the CFA rule wrt SP or FP. Make sure src is
1291 relative to the current CFA register. */
1292 switch (GET_CODE (src))
1294 /* Setting FP from SP. */
1295 case REG:
1296 if (cfa.reg == (unsigned) REGNO (src))
1297 /* OK. */
1299 else
1300 abort ();
1302 /* We used to require that dest be either SP or FP, but the
1303 ARM copies SP to a temporary register, and from there to
1304 FP. So we just rely on the backends to only set
1305 RTX_FRAME_RELATED_P on appropriate insns. */
1306 cfa.reg = REGNO (dest);
1307 break;
1309 case PLUS:
1310 case MINUS:
1311 if (dest == stack_pointer_rtx)
1313 /* Adjusting SP. */
1314 switch (GET_CODE (XEXP (src, 1)))
1316 case CONST_INT:
1317 offset = INTVAL (XEXP (src, 1));
1318 break;
1319 case REG:
1320 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp_reg)
1321 abort ();
1322 offset = cfa_temp_value;
1323 break;
1324 default:
1325 abort ();
1328 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1330 /* Restoring SP from FP in the epilogue. */
1331 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1332 abort ();
1333 cfa.reg = STACK_POINTER_REGNUM;
1335 else if (XEXP (src, 0) != stack_pointer_rtx)
1336 abort ();
1338 if (GET_CODE (src) == PLUS)
1339 offset = -offset;
1340 if (cfa.reg == STACK_POINTER_REGNUM)
1341 cfa.offset += offset;
1342 if (cfa_store.reg == STACK_POINTER_REGNUM)
1343 cfa_store.offset += offset;
1345 else if (dest == hard_frame_pointer_rtx)
1347 /* Either setting the FP from an offset of the SP,
1348 or adjusting the FP */
1349 if (! frame_pointer_needed)
1350 abort ();
1352 if (GET_CODE (XEXP (src, 0)) == REG
1353 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1354 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1356 offset = INTVAL (XEXP (src, 1));
1357 if (GET_CODE (src) == PLUS)
1358 offset = -offset;
1359 cfa.offset += offset;
1360 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1362 else
1363 abort ();
1365 else
1367 if (GET_CODE (src) != PLUS)
1368 abort ();
1370 if (GET_CODE (XEXP (src, 0)) == REG
1371 && REGNO (XEXP (src, 0)) == cfa.reg
1372 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1373 /* Setting the FP (or a scratch that will be copied into the FP
1374 later on) from SP + const. */
1375 cfa.reg = REGNO (dest);
1376 else
1378 if (XEXP (src, 1) != stack_pointer_rtx)
1379 abort ();
1380 if (GET_CODE (XEXP (src, 0)) != REG
1381 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg)
1382 abort ();
1383 if (cfa.reg != STACK_POINTER_REGNUM)
1384 abort ();
1385 cfa_store.reg = REGNO (dest);
1386 cfa_store.offset = cfa.offset - cfa_temp_value;
1389 break;
1391 case CONST_INT:
1392 cfa_temp_reg = REGNO (dest);
1393 cfa_temp_value = INTVAL (src);
1394 break;
1396 case IOR:
1397 if (GET_CODE (XEXP (src, 0)) != REG
1398 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg
1399 || (unsigned) REGNO (dest) != cfa_temp_reg
1400 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1401 abort ();
1402 cfa_temp_value |= INTVAL (XEXP (src, 1));
1403 break;
1405 default:
1406 abort ();
1408 def_cfa_1 (label, &cfa);
1409 break;
1411 /* Skip over HIGH, assuming it will be followed by a LO_SUM, which
1412 will fill in all of the bits. */
1413 case HIGH:
1414 break;
1416 case LO_SUM:
1417 cfa_temp_reg = REGNO (dest);
1418 cfa_temp_value = INTVAL (XEXP (src, 1));
1419 break;
1421 case MEM:
1422 if (GET_CODE (src) != REG)
1423 abort ();
1425 /* Saving a register to the stack. Make sure dest is relative to the
1426 CFA register. */
1427 switch (GET_CODE (XEXP (dest, 0)))
1429 /* With a push. */
1430 case PRE_MODIFY:
1431 /* We can't handle variable size modifications. */
1432 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1433 abort();
1434 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1436 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1437 || cfa_store.reg != STACK_POINTER_REGNUM)
1438 abort ();
1439 cfa_store.offset += offset;
1440 if (cfa.reg == STACK_POINTER_REGNUM)
1441 cfa.offset = cfa_store.offset;
1443 offset = -cfa_store.offset;
1444 break;
1445 case PRE_INC:
1446 case PRE_DEC:
1447 offset = GET_MODE_SIZE (GET_MODE (dest));
1448 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1449 offset = -offset;
1451 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1452 || cfa_store.reg != STACK_POINTER_REGNUM)
1453 abort ();
1454 cfa_store.offset += offset;
1455 if (cfa.reg == STACK_POINTER_REGNUM)
1456 cfa.offset = cfa_store.offset;
1458 offset = -cfa_store.offset;
1459 break;
1461 /* With an offset. */
1462 case PLUS:
1463 case MINUS:
1464 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1465 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1466 offset = -offset;
1468 if (cfa_store.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1469 abort ();
1470 offset -= cfa_store.offset;
1471 break;
1473 /* Without an offset. */
1474 case REG:
1475 if (cfa_store.reg != (unsigned) REGNO (XEXP (dest, 0)))
1476 abort ();
1477 offset = -cfa_store.offset;
1478 break;
1480 default:
1481 abort ();
1484 if (REGNO (src) != STACK_POINTER_REGNUM
1485 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1486 && (unsigned) REGNO (src) == cfa.reg)
1488 /* We're storing the current CFA reg into the stack. */
1490 if (cfa.offset == 0)
1492 /* If the source register is exactly the CFA, assume
1493 we're saving SP like any other register; this happens
1494 on the ARM. */
1496 def_cfa_1 (label, &cfa);
1497 dwarf2out_reg_save (label, STACK_POINTER_REGNUM, offset);
1498 break;
1500 else
1502 /* Otherwise, we'll need to look in the stack to
1503 calculate the CFA. */
1505 rtx x = XEXP (dest, 0);
1506 if (GET_CODE (x) != REG)
1507 x = XEXP (x, 0);
1508 if (GET_CODE (x) != REG)
1509 abort ();
1510 cfa.reg = (unsigned) REGNO (x);
1511 cfa.base_offset = offset;
1512 cfa.indirect = 1;
1513 def_cfa_1 (label, &cfa);
1514 break;
1518 def_cfa_1 (label, &cfa);
1519 dwarf2out_reg_save (label, REGNO (src), offset);
1520 break;
1522 default:
1523 abort ();
1527 /* Record call frame debugging information for INSN, which either
1528 sets SP or FP (adjusting how we calculate the frame address) or saves a
1529 register to the stack. If INSN is NULL_RTX, initialize our state. */
1531 void
1532 dwarf2out_frame_debug (insn)
1533 rtx insn;
1535 const char *label;
1536 rtx src;
1538 if (insn == NULL_RTX)
1540 /* Set up state for generating call frame debug info. */
1541 lookup_cfa (&cfa);
1542 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1543 abort ();
1544 cfa.reg = STACK_POINTER_REGNUM;
1545 cfa_store = cfa;
1546 cfa_temp_reg = -1;
1547 cfa_temp_value = 0;
1548 return;
1551 if (! RTX_FRAME_RELATED_P (insn))
1553 dwarf2out_stack_adjust (insn);
1554 return;
1557 label = dwarf2out_cfi_label ();
1559 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1560 if (src)
1561 insn = XEXP (src, 0);
1562 else
1563 insn = PATTERN (insn);
1565 dwarf2out_frame_debug_expr (insn, label);
1568 /* Return the size of an unsigned LEB128 quantity. */
1570 static inline unsigned long
1571 size_of_uleb128 (value)
1572 register unsigned long value;
1574 register unsigned long size = 0;
1575 register unsigned byte;
1579 byte = (value & 0x7f);
1580 value >>= 7;
1581 size += 1;
1583 while (value != 0);
1585 return size;
1588 /* Return the size of a signed LEB128 quantity. */
1590 static inline unsigned long
1591 size_of_sleb128 (value)
1592 register long value;
1594 register unsigned long size = 0;
1595 register unsigned byte;
1599 byte = (value & 0x7f);
1600 value >>= 7;
1601 size += 1;
1603 while (!(((value == 0) && ((byte & 0x40) == 0))
1604 || ((value == -1) && ((byte & 0x40) != 0))));
1606 return size;
1609 /* Output an unsigned LEB128 quantity. */
1611 static void
1612 output_uleb128 (value)
1613 register unsigned long value;
1615 unsigned long save_value = value;
1617 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1620 register unsigned byte = (value & 0x7f);
1621 value >>= 7;
1622 if (value != 0)
1623 /* More bytes to follow. */
1624 byte |= 0x80;
1626 fprintf (asm_out_file, "0x%x", byte);
1627 if (value != 0)
1628 fprintf (asm_out_file, ",");
1630 while (value != 0);
1632 if (flag_debug_asm)
1633 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1636 /* Output an signed LEB128 quantity. */
1638 static void
1639 output_sleb128 (value)
1640 register long value;
1642 register int more;
1643 register unsigned byte;
1644 long save_value = value;
1646 fprintf (asm_out_file, "%s", ASM_BYTE_OP);
1649 byte = (value & 0x7f);
1650 /* arithmetic shift */
1651 value >>= 7;
1652 more = !((((value == 0) && ((byte & 0x40) == 0))
1653 || ((value == -1) && ((byte & 0x40) != 0))));
1654 if (more)
1655 byte |= 0x80;
1657 fprintf (asm_out_file, "0x%x", byte);
1658 if (more)
1659 fprintf (asm_out_file, ",");
1662 while (more);
1663 if (flag_debug_asm)
1664 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1667 /* Output a Call Frame Information opcode and its operand(s). */
1669 static void
1670 output_cfi (cfi, fde)
1671 register dw_cfi_ref cfi;
1672 register dw_fde_ref fde;
1674 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1676 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1677 cfi->dw_cfi_opc
1678 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1679 if (flag_debug_asm)
1680 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1681 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1682 fputc ('\n', asm_out_file);
1685 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1687 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1688 cfi->dw_cfi_opc
1689 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1690 if (flag_debug_asm)
1691 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1692 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1694 fputc ('\n', asm_out_file);
1695 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1696 fputc ('\n', asm_out_file);
1698 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1700 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1701 cfi->dw_cfi_opc
1702 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1703 if (flag_debug_asm)
1704 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1705 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1707 fputc ('\n', asm_out_file);
1709 else
1711 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1712 if (flag_debug_asm)
1713 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1714 dwarf_cfi_name (cfi->dw_cfi_opc));
1716 fputc ('\n', asm_out_file);
1717 switch (cfi->dw_cfi_opc)
1719 case DW_CFA_set_loc:
1720 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1721 fputc ('\n', asm_out_file);
1722 break;
1723 case DW_CFA_advance_loc1:
1724 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1725 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1726 fde->dw_fde_current_label);
1727 fputc ('\n', asm_out_file);
1728 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1729 break;
1730 case DW_CFA_advance_loc2:
1731 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1732 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1733 fde->dw_fde_current_label);
1734 fputc ('\n', asm_out_file);
1735 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1736 break;
1737 case DW_CFA_advance_loc4:
1738 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1739 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1740 fde->dw_fde_current_label);
1741 fputc ('\n', asm_out_file);
1742 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1743 break;
1744 #ifdef MIPS_DEBUGGING_INFO
1745 case DW_CFA_MIPS_advance_loc8:
1746 /* TODO: not currently implemented. */
1747 abort ();
1748 break;
1749 #endif
1750 case DW_CFA_offset_extended:
1751 case DW_CFA_GNU_negative_offset_extended:
1752 case DW_CFA_def_cfa:
1753 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1754 fputc ('\n', asm_out_file);
1755 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1756 fputc ('\n', asm_out_file);
1757 break;
1758 case DW_CFA_restore_extended:
1759 case DW_CFA_undefined:
1760 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1761 fputc ('\n', asm_out_file);
1762 break;
1763 case DW_CFA_same_value:
1764 case DW_CFA_def_cfa_register:
1765 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1766 fputc ('\n', asm_out_file);
1767 break;
1768 case DW_CFA_register:
1769 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1770 fputc ('\n', asm_out_file);
1771 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1772 fputc ('\n', asm_out_file);
1773 break;
1774 case DW_CFA_def_cfa_offset:
1775 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1776 fputc ('\n', asm_out_file);
1777 break;
1778 case DW_CFA_GNU_window_save:
1779 break;
1780 case DW_CFA_GNU_args_size:
1781 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1782 fputc ('\n', asm_out_file);
1783 break;
1784 case DW_CFA_def_cfa_expression:
1785 output_cfa_loc (cfi);
1786 break;
1787 default:
1788 break;
1793 /* Output the call frame information used to used to record information
1794 that relates to calculating the frame pointer, and records the
1795 location of saved registers. */
1797 static void
1798 output_call_frame_info (for_eh)
1799 int for_eh;
1801 register unsigned long i;
1802 register dw_fde_ref fde;
1803 register dw_cfi_ref cfi;
1804 char l1[20], l2[20];
1805 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1806 char ld[20];
1807 #endif
1809 /* Do we want to include a pointer to the exception table? */
1810 int eh_ptr = for_eh && exception_table_p ();
1812 /* If we don't have any functions we'll want to unwind out of, don't
1813 emit any EH unwind information. */
1814 if (for_eh)
1816 for (i = 0; i < fde_table_in_use; ++i)
1817 if (! fde_table[i].nothrow)
1818 goto found;
1819 return;
1820 found:;
1823 fputc ('\n', asm_out_file);
1825 /* We're going to be generating comments, so turn on app. */
1826 if (flag_debug_asm)
1827 app_enable ();
1829 if (for_eh)
1831 #ifdef EH_FRAME_SECTION
1832 EH_FRAME_SECTION ();
1833 #else
1834 tree label = get_file_function_name ('F');
1836 force_data_section ();
1837 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1838 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1839 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1840 #endif
1841 assemble_label ("__FRAME_BEGIN__");
1843 else
1844 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1846 /* Output the CIE. */
1847 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1848 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1849 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1850 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1851 if (for_eh)
1852 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1853 else
1854 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1855 #else
1856 if (for_eh)
1857 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1858 else
1859 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1860 #endif
1861 if (flag_debug_asm)
1862 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1863 ASM_COMMENT_START);
1865 fputc ('\n', asm_out_file);
1866 ASM_OUTPUT_LABEL (asm_out_file, l1);
1868 if (for_eh)
1869 /* Now that the CIE pointer is PC-relative for EH,
1870 use 0 to identify the CIE. */
1871 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1872 else
1873 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1875 if (flag_debug_asm)
1876 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1878 fputc ('\n', asm_out_file);
1879 if (! for_eh && DWARF_OFFSET_SIZE == 8)
1881 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1882 fputc ('\n', asm_out_file);
1885 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1886 if (flag_debug_asm)
1887 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1889 fputc ('\n', asm_out_file);
1890 if (eh_ptr)
1892 /* The CIE contains a pointer to the exception region info for the
1893 frame. Make the augmentation string three bytes (including the
1894 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1895 can't handle unaligned relocs. */
1896 if (flag_debug_asm)
1898 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1899 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1901 else
1903 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1905 fputc ('\n', asm_out_file);
1907 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1908 if (flag_debug_asm)
1909 fprintf (asm_out_file, "\t%s pointer to exception region info",
1910 ASM_COMMENT_START);
1912 else
1914 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1915 if (flag_debug_asm)
1916 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1917 ASM_COMMENT_START);
1920 fputc ('\n', asm_out_file);
1921 output_uleb128 (1);
1922 if (flag_debug_asm)
1923 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1925 fputc ('\n', asm_out_file);
1926 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1927 if (flag_debug_asm)
1928 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1930 fputc ('\n', asm_out_file);
1931 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1932 if (flag_debug_asm)
1933 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1935 fputc ('\n', asm_out_file);
1937 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1938 output_cfi (cfi, NULL);
1940 /* Pad the CIE out to an address sized boundary. */
1941 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
1942 ASM_OUTPUT_LABEL (asm_out_file, l2);
1943 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1944 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1945 if (flag_debug_asm)
1946 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1947 fputc ('\n', asm_out_file);
1948 #endif
1950 /* Loop through all of the FDE's. */
1951 for (i = 0; i < fde_table_in_use; ++i)
1953 fde = &fde_table[i];
1955 /* Don't emit EH unwind info for leaf functions. */
1956 if (for_eh && fde->nothrow)
1957 continue;
1959 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1960 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1961 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1962 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i * 2);
1963 if (for_eh)
1964 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1965 else
1966 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1967 #else
1968 if (for_eh)
1969 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1970 else
1971 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1972 #endif
1973 if (flag_debug_asm)
1974 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1975 fputc ('\n', asm_out_file);
1976 ASM_OUTPUT_LABEL (asm_out_file, l1);
1978 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1979 emits a target dependent sized offset when for_eh is not true.
1980 This inconsistency may confuse gdb. The only case where we need a
1981 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1982 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1983 though in order to be compatible with the dwarf_fde struct in frame.c.
1984 If the for_eh case is changed, then the struct in frame.c has
1985 to be adjusted appropriately. */
1986 if (for_eh)
1987 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
1988 else
1989 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1990 if (flag_debug_asm)
1991 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1993 fputc ('\n', asm_out_file);
1994 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1995 if (flag_debug_asm)
1996 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1998 fputc ('\n', asm_out_file);
1999 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
2000 fde->dw_fde_end, fde->dw_fde_begin);
2001 if (flag_debug_asm)
2002 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
2004 fputc ('\n', asm_out_file);
2006 /* Loop through the Call Frame Instructions associated with
2007 this FDE. */
2008 fde->dw_fde_current_label = fde->dw_fde_begin;
2009 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2010 output_cfi (cfi, fde);
2012 /* Pad the FDE out to an address sized boundary. */
2013 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DWARF2_ADDR_SIZE));
2014 ASM_OUTPUT_LABEL (asm_out_file, l2);
2015 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
2016 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
2017 if (flag_debug_asm)
2018 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
2019 fputc ('\n', asm_out_file);
2020 #endif
2022 #ifndef EH_FRAME_SECTION
2023 if (for_eh)
2025 /* Emit terminating zero for table. */
2026 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
2027 fputc ('\n', asm_out_file);
2029 #endif
2030 #ifdef MIPS_DEBUGGING_INFO
2031 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2032 get a value of 0. Putting .align 0 after the label fixes it. */
2033 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2034 #endif
2036 /* Turn off app to make assembly quicker. */
2037 if (flag_debug_asm)
2038 app_disable ();
2041 /* Output a marker (i.e. a label) for the beginning of a function, before
2042 the prologue. */
2044 void
2045 dwarf2out_begin_prologue ()
2047 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2048 register dw_fde_ref fde;
2050 ++current_funcdef_number;
2052 function_section (current_function_decl);
2053 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2054 current_funcdef_number);
2055 ASM_OUTPUT_LABEL (asm_out_file, label);
2056 current_function_func_begin_label = get_identifier (label);
2058 /* Expand the fde table if necessary. */
2059 if (fde_table_in_use == fde_table_allocated)
2061 fde_table_allocated += FDE_TABLE_INCREMENT;
2062 fde_table
2063 = (dw_fde_ref) xrealloc (fde_table,
2064 fde_table_allocated * sizeof (dw_fde_node));
2067 /* Record the FDE associated with this function. */
2068 current_funcdef_fde = fde_table_in_use;
2070 /* Add the new FDE at the end of the fde_table. */
2071 fde = &fde_table[fde_table_in_use++];
2072 fde->dw_fde_begin = xstrdup (label);
2073 fde->dw_fde_current_label = NULL;
2074 fde->dw_fde_end = NULL;
2075 fde->dw_fde_cfi = NULL;
2076 fde->nothrow = current_function_nothrow;
2078 args_size = old_args_size = 0;
2081 /* Output a marker (i.e. a label) for the absolute end of the generated code
2082 for a function definition. This gets called *after* the epilogue code has
2083 been generated. */
2085 void
2086 dwarf2out_end_epilogue ()
2088 dw_fde_ref fde;
2089 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2091 /* Output a label to mark the endpoint of the code generated for this
2092 function. */
2093 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2094 ASM_OUTPUT_LABEL (asm_out_file, label);
2095 fde = &fde_table[fde_table_in_use - 1];
2096 fde->dw_fde_end = xstrdup (label);
2099 void
2100 dwarf2out_frame_init ()
2102 /* Allocate the initial hunk of the fde_table. */
2103 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2104 fde_table_allocated = FDE_TABLE_INCREMENT;
2105 fde_table_in_use = 0;
2107 /* Generate the CFA instructions common to all FDE's. Do it now for the
2108 sake of lookup_cfa. */
2110 #ifdef DWARF2_UNWIND_INFO
2111 /* On entry, the Canonical Frame Address is at SP. */
2112 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2113 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2114 #endif
2117 void
2118 dwarf2out_frame_finish ()
2120 /* Output call frame information. */
2121 #ifdef MIPS_DEBUGGING_INFO
2122 if (write_symbols == DWARF2_DEBUG)
2123 output_call_frame_info (0);
2124 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2125 output_call_frame_info (1);
2126 #else
2127 if (write_symbols == DWARF2_DEBUG
2128 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
2129 output_call_frame_info (1);
2130 #endif
2133 /* And now, the subset of the debugging information support code necessary
2134 for emitting location expressions. */
2136 typedef struct dw_val_struct *dw_val_ref;
2137 typedef struct die_struct *dw_die_ref;
2138 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2140 /* Each DIE may have a series of attribute/value pairs. Values
2141 can take on several forms. The forms that are used in this
2142 implementation are listed below. */
2144 typedef enum
2146 dw_val_class_addr,
2147 dw_val_class_loc,
2148 dw_val_class_const,
2149 dw_val_class_unsigned_const,
2150 dw_val_class_long_long,
2151 dw_val_class_float,
2152 dw_val_class_flag,
2153 dw_val_class_die_ref,
2154 dw_val_class_fde_ref,
2155 dw_val_class_lbl_id,
2156 dw_val_class_lbl_offset,
2157 dw_val_class_str
2159 dw_val_class;
2161 /* Describe a double word constant value. */
2162 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2164 typedef struct dw_long_long_struct
2166 unsigned long hi;
2167 unsigned long low;
2169 dw_long_long_const;
2171 /* Describe a floating point constant value. */
2173 typedef struct dw_fp_struct
2175 long *array;
2176 unsigned length;
2178 dw_float_const;
2180 /* The dw_val_node describes an attribute's value, as it is
2181 represented internally. */
2183 typedef struct dw_val_struct
2185 dw_val_class val_class;
2186 union
2188 rtx val_addr;
2189 dw_loc_descr_ref val_loc;
2190 long int val_int;
2191 long unsigned val_unsigned;
2192 dw_long_long_const val_long_long;
2193 dw_float_const val_float;
2194 struct {
2195 dw_die_ref die;
2196 int external;
2197 } val_die_ref;
2198 unsigned val_fde_index;
2199 char *val_str;
2200 char *val_lbl_id;
2201 unsigned char val_flag;
2205 dw_val_node;
2207 /* Locations in memory are described using a sequence of stack machine
2208 operations. */
2210 typedef struct dw_loc_descr_struct
2212 dw_loc_descr_ref dw_loc_next;
2213 enum dwarf_location_atom dw_loc_opc;
2214 dw_val_node dw_loc_oprnd1;
2215 dw_val_node dw_loc_oprnd2;
2216 int dw_loc_addr;
2218 dw_loc_descr_node;
2220 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2221 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2222 unsigned long,
2223 unsigned long));
2224 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2225 dw_loc_descr_ref));
2226 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2227 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2228 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2229 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2231 /* Convert a DWARF stack opcode into its string name. */
2233 static const char *
2234 dwarf_stack_op_name (op)
2235 register unsigned op;
2237 switch (op)
2239 case DW_OP_addr:
2240 return "DW_OP_addr";
2241 case DW_OP_deref:
2242 return "DW_OP_deref";
2243 case DW_OP_const1u:
2244 return "DW_OP_const1u";
2245 case DW_OP_const1s:
2246 return "DW_OP_const1s";
2247 case DW_OP_const2u:
2248 return "DW_OP_const2u";
2249 case DW_OP_const2s:
2250 return "DW_OP_const2s";
2251 case DW_OP_const4u:
2252 return "DW_OP_const4u";
2253 case DW_OP_const4s:
2254 return "DW_OP_const4s";
2255 case DW_OP_const8u:
2256 return "DW_OP_const8u";
2257 case DW_OP_const8s:
2258 return "DW_OP_const8s";
2259 case DW_OP_constu:
2260 return "DW_OP_constu";
2261 case DW_OP_consts:
2262 return "DW_OP_consts";
2263 case DW_OP_dup:
2264 return "DW_OP_dup";
2265 case DW_OP_drop:
2266 return "DW_OP_drop";
2267 case DW_OP_over:
2268 return "DW_OP_over";
2269 case DW_OP_pick:
2270 return "DW_OP_pick";
2271 case DW_OP_swap:
2272 return "DW_OP_swap";
2273 case DW_OP_rot:
2274 return "DW_OP_rot";
2275 case DW_OP_xderef:
2276 return "DW_OP_xderef";
2277 case DW_OP_abs:
2278 return "DW_OP_abs";
2279 case DW_OP_and:
2280 return "DW_OP_and";
2281 case DW_OP_div:
2282 return "DW_OP_div";
2283 case DW_OP_minus:
2284 return "DW_OP_minus";
2285 case DW_OP_mod:
2286 return "DW_OP_mod";
2287 case DW_OP_mul:
2288 return "DW_OP_mul";
2289 case DW_OP_neg:
2290 return "DW_OP_neg";
2291 case DW_OP_not:
2292 return "DW_OP_not";
2293 case DW_OP_or:
2294 return "DW_OP_or";
2295 case DW_OP_plus:
2296 return "DW_OP_plus";
2297 case DW_OP_plus_uconst:
2298 return "DW_OP_plus_uconst";
2299 case DW_OP_shl:
2300 return "DW_OP_shl";
2301 case DW_OP_shr:
2302 return "DW_OP_shr";
2303 case DW_OP_shra:
2304 return "DW_OP_shra";
2305 case DW_OP_xor:
2306 return "DW_OP_xor";
2307 case DW_OP_bra:
2308 return "DW_OP_bra";
2309 case DW_OP_eq:
2310 return "DW_OP_eq";
2311 case DW_OP_ge:
2312 return "DW_OP_ge";
2313 case DW_OP_gt:
2314 return "DW_OP_gt";
2315 case DW_OP_le:
2316 return "DW_OP_le";
2317 case DW_OP_lt:
2318 return "DW_OP_lt";
2319 case DW_OP_ne:
2320 return "DW_OP_ne";
2321 case DW_OP_skip:
2322 return "DW_OP_skip";
2323 case DW_OP_lit0:
2324 return "DW_OP_lit0";
2325 case DW_OP_lit1:
2326 return "DW_OP_lit1";
2327 case DW_OP_lit2:
2328 return "DW_OP_lit2";
2329 case DW_OP_lit3:
2330 return "DW_OP_lit3";
2331 case DW_OP_lit4:
2332 return "DW_OP_lit4";
2333 case DW_OP_lit5:
2334 return "DW_OP_lit5";
2335 case DW_OP_lit6:
2336 return "DW_OP_lit6";
2337 case DW_OP_lit7:
2338 return "DW_OP_lit7";
2339 case DW_OP_lit8:
2340 return "DW_OP_lit8";
2341 case DW_OP_lit9:
2342 return "DW_OP_lit9";
2343 case DW_OP_lit10:
2344 return "DW_OP_lit10";
2345 case DW_OP_lit11:
2346 return "DW_OP_lit11";
2347 case DW_OP_lit12:
2348 return "DW_OP_lit12";
2349 case DW_OP_lit13:
2350 return "DW_OP_lit13";
2351 case DW_OP_lit14:
2352 return "DW_OP_lit14";
2353 case DW_OP_lit15:
2354 return "DW_OP_lit15";
2355 case DW_OP_lit16:
2356 return "DW_OP_lit16";
2357 case DW_OP_lit17:
2358 return "DW_OP_lit17";
2359 case DW_OP_lit18:
2360 return "DW_OP_lit18";
2361 case DW_OP_lit19:
2362 return "DW_OP_lit19";
2363 case DW_OP_lit20:
2364 return "DW_OP_lit20";
2365 case DW_OP_lit21:
2366 return "DW_OP_lit21";
2367 case DW_OP_lit22:
2368 return "DW_OP_lit22";
2369 case DW_OP_lit23:
2370 return "DW_OP_lit23";
2371 case DW_OP_lit24:
2372 return "DW_OP_lit24";
2373 case DW_OP_lit25:
2374 return "DW_OP_lit25";
2375 case DW_OP_lit26:
2376 return "DW_OP_lit26";
2377 case DW_OP_lit27:
2378 return "DW_OP_lit27";
2379 case DW_OP_lit28:
2380 return "DW_OP_lit28";
2381 case DW_OP_lit29:
2382 return "DW_OP_lit29";
2383 case DW_OP_lit30:
2384 return "DW_OP_lit30";
2385 case DW_OP_lit31:
2386 return "DW_OP_lit31";
2387 case DW_OP_reg0:
2388 return "DW_OP_reg0";
2389 case DW_OP_reg1:
2390 return "DW_OP_reg1";
2391 case DW_OP_reg2:
2392 return "DW_OP_reg2";
2393 case DW_OP_reg3:
2394 return "DW_OP_reg3";
2395 case DW_OP_reg4:
2396 return "DW_OP_reg4";
2397 case DW_OP_reg5:
2398 return "DW_OP_reg5";
2399 case DW_OP_reg6:
2400 return "DW_OP_reg6";
2401 case DW_OP_reg7:
2402 return "DW_OP_reg7";
2403 case DW_OP_reg8:
2404 return "DW_OP_reg8";
2405 case DW_OP_reg9:
2406 return "DW_OP_reg9";
2407 case DW_OP_reg10:
2408 return "DW_OP_reg10";
2409 case DW_OP_reg11:
2410 return "DW_OP_reg11";
2411 case DW_OP_reg12:
2412 return "DW_OP_reg12";
2413 case DW_OP_reg13:
2414 return "DW_OP_reg13";
2415 case DW_OP_reg14:
2416 return "DW_OP_reg14";
2417 case DW_OP_reg15:
2418 return "DW_OP_reg15";
2419 case DW_OP_reg16:
2420 return "DW_OP_reg16";
2421 case DW_OP_reg17:
2422 return "DW_OP_reg17";
2423 case DW_OP_reg18:
2424 return "DW_OP_reg18";
2425 case DW_OP_reg19:
2426 return "DW_OP_reg19";
2427 case DW_OP_reg20:
2428 return "DW_OP_reg20";
2429 case DW_OP_reg21:
2430 return "DW_OP_reg21";
2431 case DW_OP_reg22:
2432 return "DW_OP_reg22";
2433 case DW_OP_reg23:
2434 return "DW_OP_reg23";
2435 case DW_OP_reg24:
2436 return "DW_OP_reg24";
2437 case DW_OP_reg25:
2438 return "DW_OP_reg25";
2439 case DW_OP_reg26:
2440 return "DW_OP_reg26";
2441 case DW_OP_reg27:
2442 return "DW_OP_reg27";
2443 case DW_OP_reg28:
2444 return "DW_OP_reg28";
2445 case DW_OP_reg29:
2446 return "DW_OP_reg29";
2447 case DW_OP_reg30:
2448 return "DW_OP_reg30";
2449 case DW_OP_reg31:
2450 return "DW_OP_reg31";
2451 case DW_OP_breg0:
2452 return "DW_OP_breg0";
2453 case DW_OP_breg1:
2454 return "DW_OP_breg1";
2455 case DW_OP_breg2:
2456 return "DW_OP_breg2";
2457 case DW_OP_breg3:
2458 return "DW_OP_breg3";
2459 case DW_OP_breg4:
2460 return "DW_OP_breg4";
2461 case DW_OP_breg5:
2462 return "DW_OP_breg5";
2463 case DW_OP_breg6:
2464 return "DW_OP_breg6";
2465 case DW_OP_breg7:
2466 return "DW_OP_breg7";
2467 case DW_OP_breg8:
2468 return "DW_OP_breg8";
2469 case DW_OP_breg9:
2470 return "DW_OP_breg9";
2471 case DW_OP_breg10:
2472 return "DW_OP_breg10";
2473 case DW_OP_breg11:
2474 return "DW_OP_breg11";
2475 case DW_OP_breg12:
2476 return "DW_OP_breg12";
2477 case DW_OP_breg13:
2478 return "DW_OP_breg13";
2479 case DW_OP_breg14:
2480 return "DW_OP_breg14";
2481 case DW_OP_breg15:
2482 return "DW_OP_breg15";
2483 case DW_OP_breg16:
2484 return "DW_OP_breg16";
2485 case DW_OP_breg17:
2486 return "DW_OP_breg17";
2487 case DW_OP_breg18:
2488 return "DW_OP_breg18";
2489 case DW_OP_breg19:
2490 return "DW_OP_breg19";
2491 case DW_OP_breg20:
2492 return "DW_OP_breg20";
2493 case DW_OP_breg21:
2494 return "DW_OP_breg21";
2495 case DW_OP_breg22:
2496 return "DW_OP_breg22";
2497 case DW_OP_breg23:
2498 return "DW_OP_breg23";
2499 case DW_OP_breg24:
2500 return "DW_OP_breg24";
2501 case DW_OP_breg25:
2502 return "DW_OP_breg25";
2503 case DW_OP_breg26:
2504 return "DW_OP_breg26";
2505 case DW_OP_breg27:
2506 return "DW_OP_breg27";
2507 case DW_OP_breg28:
2508 return "DW_OP_breg28";
2509 case DW_OP_breg29:
2510 return "DW_OP_breg29";
2511 case DW_OP_breg30:
2512 return "DW_OP_breg30";
2513 case DW_OP_breg31:
2514 return "DW_OP_breg31";
2515 case DW_OP_regx:
2516 return "DW_OP_regx";
2517 case DW_OP_fbreg:
2518 return "DW_OP_fbreg";
2519 case DW_OP_bregx:
2520 return "DW_OP_bregx";
2521 case DW_OP_piece:
2522 return "DW_OP_piece";
2523 case DW_OP_deref_size:
2524 return "DW_OP_deref_size";
2525 case DW_OP_xderef_size:
2526 return "DW_OP_xderef_size";
2527 case DW_OP_nop:
2528 return "DW_OP_nop";
2529 default:
2530 return "OP_<unknown>";
2534 /* Return a pointer to a newly allocated location description. Location
2535 descriptions are simple expression terms that can be strung
2536 together to form more complicated location (address) descriptions. */
2538 static inline dw_loc_descr_ref
2539 new_loc_descr (op, oprnd1, oprnd2)
2540 register enum dwarf_location_atom op;
2541 register unsigned long oprnd1;
2542 register unsigned long oprnd2;
2544 /* Use xcalloc here so we clear out all of the long_long constant in
2545 the union. */
2546 register dw_loc_descr_ref descr
2547 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2549 descr->dw_loc_opc = op;
2550 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2551 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2552 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2553 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2555 return descr;
2558 /* Add a location description term to a location description expression. */
2560 static inline void
2561 add_loc_descr (list_head, descr)
2562 register dw_loc_descr_ref *list_head;
2563 register dw_loc_descr_ref descr;
2565 register dw_loc_descr_ref *d;
2567 /* Find the end of the chain. */
2568 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2571 *d = descr;
2574 /* Return the size of a location descriptor. */
2576 static unsigned long
2577 size_of_loc_descr (loc)
2578 register dw_loc_descr_ref loc;
2580 register unsigned long size = 1;
2582 switch (loc->dw_loc_opc)
2584 case DW_OP_addr:
2585 size += DWARF2_ADDR_SIZE;
2586 break;
2587 case DW_OP_const1u:
2588 case DW_OP_const1s:
2589 size += 1;
2590 break;
2591 case DW_OP_const2u:
2592 case DW_OP_const2s:
2593 size += 2;
2594 break;
2595 case DW_OP_const4u:
2596 case DW_OP_const4s:
2597 size += 4;
2598 break;
2599 case DW_OP_const8u:
2600 case DW_OP_const8s:
2601 size += 8;
2602 break;
2603 case DW_OP_constu:
2604 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2605 break;
2606 case DW_OP_consts:
2607 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2608 break;
2609 case DW_OP_pick:
2610 size += 1;
2611 break;
2612 case DW_OP_plus_uconst:
2613 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2614 break;
2615 case DW_OP_skip:
2616 case DW_OP_bra:
2617 size += 2;
2618 break;
2619 case DW_OP_breg0:
2620 case DW_OP_breg1:
2621 case DW_OP_breg2:
2622 case DW_OP_breg3:
2623 case DW_OP_breg4:
2624 case DW_OP_breg5:
2625 case DW_OP_breg6:
2626 case DW_OP_breg7:
2627 case DW_OP_breg8:
2628 case DW_OP_breg9:
2629 case DW_OP_breg10:
2630 case DW_OP_breg11:
2631 case DW_OP_breg12:
2632 case DW_OP_breg13:
2633 case DW_OP_breg14:
2634 case DW_OP_breg15:
2635 case DW_OP_breg16:
2636 case DW_OP_breg17:
2637 case DW_OP_breg18:
2638 case DW_OP_breg19:
2639 case DW_OP_breg20:
2640 case DW_OP_breg21:
2641 case DW_OP_breg22:
2642 case DW_OP_breg23:
2643 case DW_OP_breg24:
2644 case DW_OP_breg25:
2645 case DW_OP_breg26:
2646 case DW_OP_breg27:
2647 case DW_OP_breg28:
2648 case DW_OP_breg29:
2649 case DW_OP_breg30:
2650 case DW_OP_breg31:
2651 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2652 break;
2653 case DW_OP_regx:
2654 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2655 break;
2656 case DW_OP_fbreg:
2657 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2658 break;
2659 case DW_OP_bregx:
2660 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2661 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2662 break;
2663 case DW_OP_piece:
2664 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2665 break;
2666 case DW_OP_deref_size:
2667 case DW_OP_xderef_size:
2668 size += 1;
2669 break;
2670 default:
2671 break;
2674 return size;
2677 /* Return the size of a series of location descriptors. */
2679 static unsigned long
2680 size_of_locs (loc)
2681 register dw_loc_descr_ref loc;
2683 register unsigned long size = 0;
2685 for (; loc != NULL; loc = loc->dw_loc_next)
2687 loc->dw_loc_addr = size;
2688 size += size_of_loc_descr (loc);
2691 return size;
2694 /* Output location description stack opcode's operands (if any). */
2696 static void
2697 output_loc_operands (loc)
2698 register dw_loc_descr_ref loc;
2700 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2701 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2703 switch (loc->dw_loc_opc)
2705 #ifdef DWARF2_DEBUGGING_INFO
2706 case DW_OP_addr:
2707 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
2708 fputc ('\n', asm_out_file);
2709 break;
2710 case DW_OP_const2u:
2711 case DW_OP_const2s:
2712 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
2713 fputc ('\n', asm_out_file);
2714 break;
2715 case DW_OP_const4u:
2716 case DW_OP_const4s:
2717 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
2718 fputc ('\n', asm_out_file);
2719 break;
2720 case DW_OP_const8u:
2721 case DW_OP_const8s:
2722 abort ();
2723 fputc ('\n', asm_out_file);
2724 break;
2725 case DW_OP_skip:
2726 case DW_OP_bra:
2728 int offset;
2730 if (val1->val_class == dw_val_class_loc)
2731 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2732 else
2733 abort ();
2735 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, offset);
2736 fputc ('\n', asm_out_file);
2738 break;
2739 #else
2740 case DW_OP_addr:
2741 case DW_OP_const2u:
2742 case DW_OP_const2s:
2743 case DW_OP_const4u:
2744 case DW_OP_const4s:
2745 case DW_OP_const8u:
2746 case DW_OP_const8s:
2747 case DW_OP_skip:
2748 case DW_OP_bra:
2749 /* We currently don't make any attempt to make sure these are
2750 aligned properly like we do for the main unwind info, so
2751 don't support emitting things larger than a byte if we're
2752 only doing unwinding. */
2753 abort ();
2754 #endif
2755 case DW_OP_const1u:
2756 case DW_OP_const1s:
2757 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2758 fputc ('\n', asm_out_file);
2759 break;
2760 case DW_OP_constu:
2761 output_uleb128 (val1->v.val_unsigned);
2762 fputc ('\n', asm_out_file);
2763 break;
2764 case DW_OP_consts:
2765 output_sleb128 (val1->v.val_int);
2766 fputc ('\n', asm_out_file);
2767 break;
2768 case DW_OP_pick:
2769 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
2770 fputc ('\n', asm_out_file);
2771 break;
2772 case DW_OP_plus_uconst:
2773 output_uleb128 (val1->v.val_unsigned);
2774 fputc ('\n', asm_out_file);
2775 break;
2776 case DW_OP_breg0:
2777 case DW_OP_breg1:
2778 case DW_OP_breg2:
2779 case DW_OP_breg3:
2780 case DW_OP_breg4:
2781 case DW_OP_breg5:
2782 case DW_OP_breg6:
2783 case DW_OP_breg7:
2784 case DW_OP_breg8:
2785 case DW_OP_breg9:
2786 case DW_OP_breg10:
2787 case DW_OP_breg11:
2788 case DW_OP_breg12:
2789 case DW_OP_breg13:
2790 case DW_OP_breg14:
2791 case DW_OP_breg15:
2792 case DW_OP_breg16:
2793 case DW_OP_breg17:
2794 case DW_OP_breg18:
2795 case DW_OP_breg19:
2796 case DW_OP_breg20:
2797 case DW_OP_breg21:
2798 case DW_OP_breg22:
2799 case DW_OP_breg23:
2800 case DW_OP_breg24:
2801 case DW_OP_breg25:
2802 case DW_OP_breg26:
2803 case DW_OP_breg27:
2804 case DW_OP_breg28:
2805 case DW_OP_breg29:
2806 case DW_OP_breg30:
2807 case DW_OP_breg31:
2808 output_sleb128 (val1->v.val_int);
2809 fputc ('\n', asm_out_file);
2810 break;
2811 case DW_OP_regx:
2812 output_uleb128 (val1->v.val_unsigned);
2813 fputc ('\n', asm_out_file);
2814 break;
2815 case DW_OP_fbreg:
2816 output_sleb128 (val1->v.val_int);
2817 fputc ('\n', asm_out_file);
2818 break;
2819 case DW_OP_bregx:
2820 output_uleb128 (val1->v.val_unsigned);
2821 fputc ('\n', asm_out_file);
2822 output_sleb128 (val2->v.val_int);
2823 fputc ('\n', asm_out_file);
2824 break;
2825 case DW_OP_piece:
2826 output_uleb128 (val1->v.val_unsigned);
2827 fputc ('\n', asm_out_file);
2828 break;
2829 case DW_OP_deref_size:
2830 case DW_OP_xderef_size:
2831 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
2832 fputc ('\n', asm_out_file);
2833 break;
2834 default:
2835 /* Other codes have no operands. */
2836 break;
2840 /* Output a sequence of location operations. */
2842 static void
2843 output_loc_sequence (loc)
2844 dw_loc_descr_ref loc;
2846 for (; loc != NULL; loc = loc->dw_loc_next)
2848 /* Output the opcode. */
2849 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
2850 if (flag_debug_asm)
2851 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
2852 dwarf_stack_op_name (loc->dw_loc_opc));
2854 fputc ('\n', asm_out_file);
2856 /* Output the operand(s) (if any). */
2857 output_loc_operands (loc);
2861 /* This routine will generate the correct assembly data for a location
2862 description based on a cfi entry with a complex address. */
2864 static void
2865 output_cfa_loc (cfi)
2866 dw_cfi_ref cfi;
2868 dw_loc_descr_ref loc;
2869 unsigned long size;
2871 /* Output the size of the block. */
2872 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2873 size = size_of_locs (loc);
2874 output_uleb128 (size);
2875 fputc ('\n', asm_out_file);
2877 /* Now output the operations themselves. */
2878 output_loc_sequence (loc);
2881 /* This function builds a dwarf location descriptor seqeunce from
2882 a dw_cfa_location. */
2884 static struct dw_loc_descr_struct *
2885 build_cfa_loc (cfa)
2886 dw_cfa_location *cfa;
2888 struct dw_loc_descr_struct *head, *tmp;
2890 if (cfa->indirect == 0)
2891 abort ();
2893 if (cfa->base_offset)
2895 if (cfa->reg <= 31)
2896 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2897 else
2898 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2900 else if (cfa->reg <= 31)
2901 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2902 else
2903 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2904 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2905 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2906 add_loc_descr (&head, tmp);
2907 if (cfa->offset != 0)
2909 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2910 add_loc_descr (&head, tmp);
2912 return head;
2915 /* This function fills in aa dw_cfa_location structure from a
2916 dwarf location descriptor sequence. */
2918 static void
2919 get_cfa_from_loc_descr (cfa, loc)
2920 dw_cfa_location *cfa;
2921 struct dw_loc_descr_struct *loc;
2923 struct dw_loc_descr_struct *ptr;
2924 cfa->offset = 0;
2925 cfa->base_offset = 0;
2926 cfa->indirect = 0;
2927 cfa->reg = -1;
2929 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2931 enum dwarf_location_atom op = ptr->dw_loc_opc;
2932 switch (op)
2934 case DW_OP_reg0:
2935 case DW_OP_reg1:
2936 case DW_OP_reg2:
2937 case DW_OP_reg3:
2938 case DW_OP_reg4:
2939 case DW_OP_reg5:
2940 case DW_OP_reg6:
2941 case DW_OP_reg7:
2942 case DW_OP_reg8:
2943 case DW_OP_reg9:
2944 case DW_OP_reg10:
2945 case DW_OP_reg11:
2946 case DW_OP_reg12:
2947 case DW_OP_reg13:
2948 case DW_OP_reg14:
2949 case DW_OP_reg15:
2950 case DW_OP_reg16:
2951 case DW_OP_reg17:
2952 case DW_OP_reg18:
2953 case DW_OP_reg19:
2954 case DW_OP_reg20:
2955 case DW_OP_reg21:
2956 case DW_OP_reg22:
2957 case DW_OP_reg23:
2958 case DW_OP_reg24:
2959 case DW_OP_reg25:
2960 case DW_OP_reg26:
2961 case DW_OP_reg27:
2962 case DW_OP_reg28:
2963 case DW_OP_reg29:
2964 case DW_OP_reg30:
2965 case DW_OP_reg31:
2966 cfa->reg = op - DW_OP_reg0;
2967 break;
2968 case DW_OP_regx:
2969 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
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 cfa->reg = op - DW_OP_breg0;
3004 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3005 break;
3006 case DW_OP_bregx:
3007 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3008 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3009 break;
3010 case DW_OP_deref:
3011 cfa->indirect = 1;
3012 break;
3013 case DW_OP_plus_uconst:
3014 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3015 break;
3016 default:
3017 fatal ("DW_LOC_OP %s not implememnted yet.\n",
3018 dwarf_stack_op_name (ptr->dw_loc_opc));
3022 #endif /* .debug_frame support */
3024 /* And now, the support for symbolic debugging information. */
3025 #ifdef DWARF2_DEBUGGING_INFO
3027 /* NOTE: In the comments in this file, many references are made to
3028 "Debugging Information Entries". This term is abbreviated as `DIE'
3029 throughout the remainder of this file. */
3031 /* An internal representation of the DWARF output is built, and then
3032 walked to generate the DWARF debugging info. The walk of the internal
3033 representation is done after the entire program has been compiled.
3034 The types below are used to describe the internal representation. */
3036 /* Various DIE's use offsets relative to the beginning of the
3037 .debug_info section to refer to each other. */
3039 typedef long int dw_offset;
3041 /* Define typedefs here to avoid circular dependencies. */
3043 typedef struct dw_attr_struct *dw_attr_ref;
3044 typedef struct dw_line_info_struct *dw_line_info_ref;
3045 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3046 typedef struct pubname_struct *pubname_ref;
3047 typedef dw_die_ref *arange_ref;
3049 /* Each entry in the line_info_table maintains the file and
3050 line number associated with the label generated for that
3051 entry. The label gives the PC value associated with
3052 the line number entry. */
3054 typedef struct dw_line_info_struct
3056 unsigned long dw_file_num;
3057 unsigned long dw_line_num;
3059 dw_line_info_entry;
3061 /* Line information for functions in separate sections; each one gets its
3062 own sequence. */
3063 typedef struct dw_separate_line_info_struct
3065 unsigned long dw_file_num;
3066 unsigned long dw_line_num;
3067 unsigned long function;
3069 dw_separate_line_info_entry;
3071 /* Each DIE attribute has a field specifying the attribute kind,
3072 a link to the next attribute in the chain, and an attribute value.
3073 Attributes are typically linked below the DIE they modify. */
3075 typedef struct dw_attr_struct
3077 enum dwarf_attribute dw_attr;
3078 dw_attr_ref dw_attr_next;
3079 dw_val_node dw_attr_val;
3081 dw_attr_node;
3083 /* The Debugging Information Entry (DIE) structure */
3085 typedef struct die_struct
3087 enum dwarf_tag die_tag;
3088 char *die_symbol;
3089 dw_attr_ref die_attr;
3090 dw_die_ref die_parent;
3091 dw_die_ref die_child;
3092 dw_die_ref die_sib;
3093 dw_offset die_offset;
3094 unsigned long die_abbrev;
3095 int die_mark;
3097 die_node;
3099 /* The pubname structure */
3101 typedef struct pubname_struct
3103 dw_die_ref die;
3104 char *name;
3106 pubname_entry;
3108 /* The limbo die list structure. */
3109 typedef struct limbo_die_struct
3111 dw_die_ref die;
3112 struct limbo_die_struct *next;
3114 limbo_die_node;
3116 /* How to start an assembler comment. */
3117 #ifndef ASM_COMMENT_START
3118 #define ASM_COMMENT_START ";#"
3119 #endif
3121 /* Define a macro which returns non-zero for a TYPE_DECL which was
3122 implicitly generated for a tagged type.
3124 Note that unlike the gcc front end (which generates a NULL named
3125 TYPE_DECL node for each complete tagged type, each array type, and
3126 each function type node created) the g++ front end generates a
3127 _named_ TYPE_DECL node for each tagged type node created.
3128 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3129 generate a DW_TAG_typedef DIE for them. */
3131 #define TYPE_DECL_IS_STUB(decl) \
3132 (DECL_NAME (decl) == NULL_TREE \
3133 || (DECL_ARTIFICIAL (decl) \
3134 && is_tagged_type (TREE_TYPE (decl)) \
3135 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3136 /* This is necessary for stub decls that \
3137 appear in nested inline functions. */ \
3138 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3139 && (decl_ultimate_origin (decl) \
3140 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3142 /* Information concerning the compilation unit's programming
3143 language, and compiler version. */
3145 extern int flag_traditional;
3147 /* Fixed size portion of the DWARF compilation unit header. */
3148 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3150 /* Fixed size portion of debugging line information prolog. */
3151 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3153 /* Fixed size portion of public names info. */
3154 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3156 /* Fixed size portion of the address range info. */
3157 #define DWARF_ARANGES_HEADER_SIZE \
3158 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3159 - DWARF_OFFSET_SIZE)
3161 /* Size of padding portion in the address range info. It must be
3162 aligned to twice the pointer size. */
3163 #define DWARF_ARANGES_PAD_SIZE \
3164 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3165 - (2 * DWARF_OFFSET_SIZE + 4))
3167 /* Use assembler line directives if available. */
3168 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3169 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3170 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3171 #else
3172 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3173 #endif
3174 #endif
3176 /* Define the architecture-dependent minimum instruction length (in bytes).
3177 In this implementation of DWARF, this field is used for information
3178 purposes only. Since GCC generates assembly language, we have
3179 no a priori knowledge of how many instruction bytes are generated
3180 for each source line, and therefore can use only the DW_LNE_set_address
3181 and DW_LNS_fixed_advance_pc line information commands. */
3183 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3184 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3185 #endif
3187 /* Minimum line offset in a special line info. opcode.
3188 This value was chosen to give a reasonable range of values. */
3189 #define DWARF_LINE_BASE -10
3191 /* First special line opcde - leave room for the standard opcodes. */
3192 #define DWARF_LINE_OPCODE_BASE 10
3194 /* Range of line offsets in a special line info. opcode. */
3195 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3197 /* Flag that indicates the initial value of the is_stmt_start flag.
3198 In the present implementation, we do not mark any lines as
3199 the beginning of a source statement, because that information
3200 is not made available by the GCC front-end. */
3201 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3203 /* This location is used by calc_die_sizes() to keep track
3204 the offset of each DIE within the .debug_info section. */
3205 static unsigned long next_die_offset;
3207 /* Record the root of the DIE's built for the current compilation unit. */
3208 static dw_die_ref comp_unit_die;
3210 /* A list of DIEs with a NULL parent waiting to be relocated. */
3211 static limbo_die_node *limbo_die_list = 0;
3213 /* Structure used by lookup_filename to manage sets of filenames. */
3214 struct file_table
3216 char **table;
3217 unsigned allocated;
3218 unsigned in_use;
3219 unsigned last_lookup_index;
3222 /* Size (in elements) of increments by which we may expand the filename
3223 table. */
3224 #define FILE_TABLE_INCREMENT 64
3226 /* Filenames referenced by declarations this compilation unit. */
3227 static struct file_table decl_file_table;
3229 /* Filenames referenced by line numbers in this compilation unit. */
3230 static struct file_table line_file_table;
3232 /* Local pointer to the name of the main input file. Initialized in
3233 dwarf2out_init. */
3234 static const char *primary_filename;
3236 /* A pointer to the base of a table of references to DIE's that describe
3237 declarations. The table is indexed by DECL_UID() which is a unique
3238 number identifying each decl. */
3239 static dw_die_ref *decl_die_table;
3241 /* Number of elements currently allocated for the decl_die_table. */
3242 static unsigned decl_die_table_allocated;
3244 /* Number of elements in decl_die_table currently in use. */
3245 static unsigned decl_die_table_in_use;
3247 /* Size (in elements) of increments by which we may expand the
3248 decl_die_table. */
3249 #define DECL_DIE_TABLE_INCREMENT 256
3251 /* A pointer to the base of a table of references to declaration
3252 scopes. This table is a display which tracks the nesting
3253 of declaration scopes at the current scope and containing
3254 scopes. This table is used to find the proper place to
3255 define type declaration DIE's. */
3256 static tree *decl_scope_table;
3258 /* Number of elements currently allocated for the decl_scope_table. */
3259 static int decl_scope_table_allocated;
3261 /* Current level of nesting of declaration scopes. */
3262 static int decl_scope_depth;
3264 /* Size (in elements) of increments by which we may expand the
3265 decl_scope_table. */
3266 #define DECL_SCOPE_TABLE_INCREMENT 64
3268 /* A pointer to the base of a list of references to DIE's that
3269 are uniquely identified by their tag, presence/absence of
3270 children DIE's, and list of attribute/value pairs. */
3271 static dw_die_ref *abbrev_die_table;
3273 /* Number of elements currently allocated for abbrev_die_table. */
3274 static unsigned abbrev_die_table_allocated;
3276 /* Number of elements in type_die_table currently in use. */
3277 static unsigned abbrev_die_table_in_use;
3279 /* Size (in elements) of increments by which we may expand the
3280 abbrev_die_table. */
3281 #define ABBREV_DIE_TABLE_INCREMENT 256
3283 /* A pointer to the base of a table that contains line information
3284 for each source code line in .text in the compilation unit. */
3285 static dw_line_info_ref line_info_table;
3287 /* Number of elements currently allocated for line_info_table. */
3288 static unsigned line_info_table_allocated;
3290 /* Number of elements in separate_line_info_table currently in use. */
3291 static unsigned separate_line_info_table_in_use;
3293 /* A pointer to the base of a table that contains line information
3294 for each source code line outside of .text in the compilation unit. */
3295 static dw_separate_line_info_ref separate_line_info_table;
3297 /* Number of elements currently allocated for separate_line_info_table. */
3298 static unsigned separate_line_info_table_allocated;
3300 /* Number of elements in line_info_table currently in use. */
3301 static unsigned line_info_table_in_use;
3303 /* Size (in elements) of increments by which we may expand the
3304 line_info_table. */
3305 #define LINE_INFO_TABLE_INCREMENT 1024
3307 /* A pointer to the base of a table that contains a list of publicly
3308 accessible names. */
3309 static pubname_ref pubname_table;
3311 /* Number of elements currently allocated for pubname_table. */
3312 static unsigned pubname_table_allocated;
3314 /* Number of elements in pubname_table currently in use. */
3315 static unsigned pubname_table_in_use;
3317 /* Size (in elements) of increments by which we may expand the
3318 pubname_table. */
3319 #define PUBNAME_TABLE_INCREMENT 64
3321 /* A pointer to the base of a table that contains a list of publicly
3322 accessible names. */
3323 static arange_ref arange_table;
3325 /* Number of elements currently allocated for arange_table. */
3326 static unsigned arange_table_allocated;
3328 /* Number of elements in arange_table currently in use. */
3329 static unsigned arange_table_in_use;
3331 /* Size (in elements) of increments by which we may expand the
3332 arange_table. */
3333 #define ARANGE_TABLE_INCREMENT 64
3335 /* A pointer to the base of a list of incomplete types which might be
3336 completed at some later time. */
3338 static tree *incomplete_types_list;
3340 /* Number of elements currently allocated for the incomplete_types_list. */
3341 static unsigned incomplete_types_allocated;
3343 /* Number of elements of incomplete_types_list currently in use. */
3344 static unsigned incomplete_types;
3346 /* Size (in elements) of increments by which we may expand the incomplete
3347 types list. Actually, a single hunk of space of this size should
3348 be enough for most typical programs. */
3349 #define INCOMPLETE_TYPES_INCREMENT 64
3351 /* Record whether the function being analyzed contains inlined functions. */
3352 static int current_function_has_inlines;
3353 #if 0 && defined (MIPS_DEBUGGING_INFO)
3354 static int comp_unit_has_inlines;
3355 #endif
3357 /* Array of RTXes referenced by the debugging information, which therefore
3358 must be kept around forever. We do this rather than perform GC on
3359 the dwarf info because almost all of the dwarf info lives forever, and
3360 it's easier to support non-GC frontends this way. */
3361 static varray_type used_rtx_varray;
3363 /* Forward declarations for functions defined in this file. */
3365 static int is_pseudo_reg PARAMS ((rtx));
3366 static tree type_main_variant PARAMS ((tree));
3367 static int is_tagged_type PARAMS ((tree));
3368 static const char *dwarf_tag_name PARAMS ((unsigned));
3369 static const char *dwarf_attr_name PARAMS ((unsigned));
3370 static const char *dwarf_form_name PARAMS ((unsigned));
3371 #if 0
3372 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3373 #endif
3374 static tree decl_ultimate_origin PARAMS ((tree));
3375 static tree block_ultimate_origin PARAMS ((tree));
3376 static tree decl_class_context PARAMS ((tree));
3377 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3378 static void add_AT_flag PARAMS ((dw_die_ref,
3379 enum dwarf_attribute,
3380 unsigned));
3381 static void add_AT_int PARAMS ((dw_die_ref,
3382 enum dwarf_attribute, long));
3383 static void add_AT_unsigned PARAMS ((dw_die_ref,
3384 enum dwarf_attribute,
3385 unsigned long));
3386 static void add_AT_long_long PARAMS ((dw_die_ref,
3387 enum dwarf_attribute,
3388 unsigned long,
3389 unsigned long));
3390 static void add_AT_float PARAMS ((dw_die_ref,
3391 enum dwarf_attribute,
3392 unsigned, long *));
3393 static void add_AT_string PARAMS ((dw_die_ref,
3394 enum dwarf_attribute,
3395 const char *));
3396 static void add_AT_die_ref PARAMS ((dw_die_ref,
3397 enum dwarf_attribute,
3398 dw_die_ref));
3399 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3400 enum dwarf_attribute,
3401 unsigned));
3402 static void add_AT_loc PARAMS ((dw_die_ref,
3403 enum dwarf_attribute,
3404 dw_loc_descr_ref));
3405 static void add_AT_addr PARAMS ((dw_die_ref,
3406 enum dwarf_attribute,
3407 rtx));
3408 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3409 enum dwarf_attribute,
3410 const char *));
3411 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3412 enum dwarf_attribute,
3413 const char *));
3414 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3415 enum dwarf_attribute));
3416 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3417 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3418 static const char *get_AT_string PARAMS ((dw_die_ref,
3419 enum dwarf_attribute));
3420 static int get_AT_flag PARAMS ((dw_die_ref,
3421 enum dwarf_attribute));
3422 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3423 enum dwarf_attribute));
3424 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3425 enum dwarf_attribute));
3426 static int is_c_family PARAMS ((void));
3427 static int is_java PARAMS ((void));
3428 static int is_fortran PARAMS ((void));
3429 static void remove_AT PARAMS ((dw_die_ref,
3430 enum dwarf_attribute));
3431 static void remove_children PARAMS ((dw_die_ref));
3432 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3433 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3434 static dw_die_ref lookup_type_die PARAMS ((tree));
3435 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3436 static dw_die_ref lookup_decl_die PARAMS ((tree));
3437 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3438 static void print_spaces PARAMS ((FILE *));
3439 static void print_die PARAMS ((dw_die_ref, FILE *));
3440 static void print_dwarf_line_table PARAMS ((FILE *));
3441 static void reverse_die_lists PARAMS ((dw_die_ref));
3442 static void reverse_all_dies PARAMS ((dw_die_ref));
3443 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3444 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3445 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3446 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3447 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3448 static void compute_section_prefix PARAMS ((dw_die_ref));
3449 static int is_type_die PARAMS ((dw_die_ref));
3450 static int is_comdat_die PARAMS ((dw_die_ref));
3451 static int is_symbol_die PARAMS ((dw_die_ref));
3452 static char *gen_internal_sym PARAMS ((void));
3453 static void assign_symbol_names PARAMS ((dw_die_ref));
3454 static void break_out_includes PARAMS ((dw_die_ref));
3455 static void add_sibling_attributes PARAMS ((dw_die_ref));
3456 static void build_abbrev_table PARAMS ((dw_die_ref));
3457 static unsigned long size_of_string PARAMS ((const char *));
3458 static int constant_size PARAMS ((long unsigned));
3459 static unsigned long size_of_die PARAMS ((dw_die_ref));
3460 static void calc_die_sizes PARAMS ((dw_die_ref));
3461 static void mark_dies PARAMS ((dw_die_ref));
3462 static void unmark_dies PARAMS ((dw_die_ref));
3463 static unsigned long size_of_line_prolog PARAMS ((void));
3464 static unsigned long size_of_pubnames PARAMS ((void));
3465 static unsigned long size_of_aranges PARAMS ((void));
3466 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3467 static void output_value_format PARAMS ((dw_attr_ref));
3468 static void output_abbrev_section PARAMS ((void));
3469 static void output_die_symbol PARAMS ((dw_die_ref));
3470 static void output_symbolic_ref PARAMS ((dw_die_ref));
3471 static void output_die PARAMS ((dw_die_ref));
3472 static void output_compilation_unit_header PARAMS ((void));
3473 static void output_comp_unit PARAMS ((dw_die_ref));
3474 static const char *dwarf2_name PARAMS ((tree, int));
3475 static void add_pubname PARAMS ((tree, dw_die_ref));
3476 static void output_pubnames PARAMS ((void));
3477 static void add_arange PARAMS ((tree, dw_die_ref));
3478 static void output_aranges PARAMS ((void));
3479 static void output_line_info PARAMS ((void));
3480 static void output_file_names PARAMS ((void));
3481 static dw_die_ref base_type_die PARAMS ((tree));
3482 static tree root_type PARAMS ((tree));
3483 static int is_base_type PARAMS ((tree));
3484 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3485 static int type_is_enum PARAMS ((tree));
3486 static unsigned int reg_number PARAMS ((rtx));
3487 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3488 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3489 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3490 static int is_based_loc PARAMS ((rtx));
3491 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3492 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3493 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3494 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3495 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3496 static tree field_type PARAMS ((tree));
3497 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3498 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3499 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3500 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3501 static void add_AT_location_description PARAMS ((dw_die_ref,
3502 enum dwarf_attribute, rtx));
3503 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3504 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3505 static rtx rtl_for_decl_location PARAMS ((tree));
3506 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3507 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3508 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3509 static void add_bound_info PARAMS ((dw_die_ref,
3510 enum dwarf_attribute, tree));
3511 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3512 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3513 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3514 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3515 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3516 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3517 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3518 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3519 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3520 static void push_decl_scope PARAMS ((tree));
3521 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3522 static void pop_decl_scope PARAMS ((void));
3523 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3524 dw_die_ref));
3525 static const char *type_tag PARAMS ((tree));
3526 static tree member_declared_type PARAMS ((tree));
3527 #if 0
3528 static const char *decl_start_label PARAMS ((tree));
3529 #endif
3530 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3531 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3532 #if 0
3533 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3534 #endif
3535 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3536 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3537 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3538 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3539 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3540 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3541 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3542 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3543 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3544 static void gen_label_die PARAMS ((tree, dw_die_ref));
3545 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3546 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3547 static void gen_field_die PARAMS ((tree, dw_die_ref));
3548 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3549 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3550 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3551 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3552 static void gen_member_die PARAMS ((tree, dw_die_ref));
3553 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3554 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3555 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3556 static void gen_type_die PARAMS ((tree, dw_die_ref));
3557 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3558 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3559 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3560 static int is_redundant_typedef PARAMS ((tree));
3561 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3562 static unsigned lookup_filename PARAMS ((struct file_table *,
3563 const char *));
3564 static void init_file_table PARAMS ((struct file_table *));
3565 static void add_incomplete_type PARAMS ((tree));
3566 static void retry_incomplete_types PARAMS ((void));
3567 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3568 static void gen_abstract_function PARAMS ((tree));
3569 static rtx save_rtx PARAMS ((rtx));
3570 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3571 static int file_info_cmp PARAMS ((const void *, const void *));
3573 /* Section names used to hold DWARF debugging information. */
3574 #ifndef DEBUG_INFO_SECTION
3575 #define DEBUG_INFO_SECTION ".debug_info"
3576 #endif
3577 #ifndef ABBREV_SECTION
3578 #define ABBREV_SECTION ".debug_abbrev"
3579 #endif
3580 #ifndef ARANGES_SECTION
3581 #define ARANGES_SECTION ".debug_aranges"
3582 #endif
3583 #ifndef DW_MACINFO_SECTION
3584 #define DW_MACINFO_SECTION ".debug_macinfo"
3585 #endif
3586 #ifndef DEBUG_LINE_SECTION
3587 #define DEBUG_LINE_SECTION ".debug_line"
3588 #endif
3589 #ifndef LOC_SECTION
3590 #define LOC_SECTION ".debug_loc"
3591 #endif
3592 #ifndef PUBNAMES_SECTION
3593 #define PUBNAMES_SECTION ".debug_pubnames"
3594 #endif
3595 #ifndef STR_SECTION
3596 #define STR_SECTION ".debug_str"
3597 #endif
3599 /* Standard ELF section names for compiled code and data. */
3600 #ifndef TEXT_SECTION
3601 #define TEXT_SECTION ".text"
3602 #endif
3603 #ifndef DATA_SECTION
3604 #define DATA_SECTION ".data"
3605 #endif
3606 #ifndef BSS_SECTION
3607 #define BSS_SECTION ".bss"
3608 #endif
3610 /* Labels we insert at beginning sections we can reference instead of
3611 the section names themselves. */
3613 #ifndef TEXT_SECTION_LABEL
3614 #define TEXT_SECTION_LABEL "Ltext"
3615 #endif
3616 #ifndef DEBUG_LINE_SECTION_LABEL
3617 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3618 #endif
3619 #ifndef DEBUG_INFO_SECTION_LABEL
3620 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3621 #endif
3622 #ifndef ABBREV_SECTION_LABEL
3623 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3624 #endif
3626 /* Definitions of defaults for formats and names of various special
3627 (artificial) labels which may be generated within this file (when the -g
3628 options is used and DWARF_DEBUGGING_INFO is in effect.
3629 If necessary, these may be overridden from within the tm.h file, but
3630 typically, overriding these defaults is unnecessary. */
3632 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3633 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3634 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3635 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3636 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3638 #ifndef TEXT_END_LABEL
3639 #define TEXT_END_LABEL "Letext"
3640 #endif
3641 #ifndef DATA_END_LABEL
3642 #define DATA_END_LABEL "Ledata"
3643 #endif
3644 #ifndef BSS_END_LABEL
3645 #define BSS_END_LABEL "Lebss"
3646 #endif
3647 #ifndef BLOCK_BEGIN_LABEL
3648 #define BLOCK_BEGIN_LABEL "LBB"
3649 #endif
3650 #ifndef BLOCK_END_LABEL
3651 #define BLOCK_END_LABEL "LBE"
3652 #endif
3653 #ifndef BODY_BEGIN_LABEL
3654 #define BODY_BEGIN_LABEL "Lbb"
3655 #endif
3656 #ifndef BODY_END_LABEL
3657 #define BODY_END_LABEL "Lbe"
3658 #endif
3659 #ifndef LINE_CODE_LABEL
3660 #define LINE_CODE_LABEL "LM"
3661 #endif
3662 #ifndef SEPARATE_LINE_CODE_LABEL
3663 #define SEPARATE_LINE_CODE_LABEL "LSM"
3664 #endif
3666 /* We allow a language front-end to designate a function that is to be
3667 called to "demangle" any name before it it put into a DIE. */
3669 static const char *(*demangle_name_func) PARAMS ((const char *));
3671 void
3672 dwarf2out_set_demangle_name_func (func)
3673 const char *(*func) PARAMS ((const char *));
3675 demangle_name_func = func;
3678 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3679 that means adding it to used_rtx_varray. If not, that means making
3680 a copy on the permanent_obstack. */
3682 static rtx
3683 save_rtx (orig)
3684 register rtx orig;
3686 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3688 return orig;
3691 /* Test if rtl node points to a pseudo register. */
3693 static inline int
3694 is_pseudo_reg (rtl)
3695 register rtx rtl;
3697 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3698 || (GET_CODE (rtl) == SUBREG
3699 && REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER));
3702 /* Return a reference to a type, with its const and volatile qualifiers
3703 removed. */
3705 static inline tree
3706 type_main_variant (type)
3707 register tree type;
3709 type = TYPE_MAIN_VARIANT (type);
3711 /* There really should be only one main variant among any group of variants
3712 of a given type (and all of the MAIN_VARIANT values for all members of
3713 the group should point to that one type) but sometimes the C front-end
3714 messes this up for array types, so we work around that bug here. */
3716 if (TREE_CODE (type) == ARRAY_TYPE)
3717 while (type != TYPE_MAIN_VARIANT (type))
3718 type = TYPE_MAIN_VARIANT (type);
3720 return type;
3723 /* Return non-zero if the given type node represents a tagged type. */
3725 static inline int
3726 is_tagged_type (type)
3727 register tree type;
3729 register enum tree_code code = TREE_CODE (type);
3731 return (code == RECORD_TYPE || code == UNION_TYPE
3732 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3735 /* Convert a DIE tag into its string name. */
3737 static const char *
3738 dwarf_tag_name (tag)
3739 register unsigned tag;
3741 switch (tag)
3743 case DW_TAG_padding:
3744 return "DW_TAG_padding";
3745 case DW_TAG_array_type:
3746 return "DW_TAG_array_type";
3747 case DW_TAG_class_type:
3748 return "DW_TAG_class_type";
3749 case DW_TAG_entry_point:
3750 return "DW_TAG_entry_point";
3751 case DW_TAG_enumeration_type:
3752 return "DW_TAG_enumeration_type";
3753 case DW_TAG_formal_parameter:
3754 return "DW_TAG_formal_parameter";
3755 case DW_TAG_imported_declaration:
3756 return "DW_TAG_imported_declaration";
3757 case DW_TAG_label:
3758 return "DW_TAG_label";
3759 case DW_TAG_lexical_block:
3760 return "DW_TAG_lexical_block";
3761 case DW_TAG_member:
3762 return "DW_TAG_member";
3763 case DW_TAG_pointer_type:
3764 return "DW_TAG_pointer_type";
3765 case DW_TAG_reference_type:
3766 return "DW_TAG_reference_type";
3767 case DW_TAG_compile_unit:
3768 return "DW_TAG_compile_unit";
3769 case DW_TAG_string_type:
3770 return "DW_TAG_string_type";
3771 case DW_TAG_structure_type:
3772 return "DW_TAG_structure_type";
3773 case DW_TAG_subroutine_type:
3774 return "DW_TAG_subroutine_type";
3775 case DW_TAG_typedef:
3776 return "DW_TAG_typedef";
3777 case DW_TAG_union_type:
3778 return "DW_TAG_union_type";
3779 case DW_TAG_unspecified_parameters:
3780 return "DW_TAG_unspecified_parameters";
3781 case DW_TAG_variant:
3782 return "DW_TAG_variant";
3783 case DW_TAG_common_block:
3784 return "DW_TAG_common_block";
3785 case DW_TAG_common_inclusion:
3786 return "DW_TAG_common_inclusion";
3787 case DW_TAG_inheritance:
3788 return "DW_TAG_inheritance";
3789 case DW_TAG_inlined_subroutine:
3790 return "DW_TAG_inlined_subroutine";
3791 case DW_TAG_module:
3792 return "DW_TAG_module";
3793 case DW_TAG_ptr_to_member_type:
3794 return "DW_TAG_ptr_to_member_type";
3795 case DW_TAG_set_type:
3796 return "DW_TAG_set_type";
3797 case DW_TAG_subrange_type:
3798 return "DW_TAG_subrange_type";
3799 case DW_TAG_with_stmt:
3800 return "DW_TAG_with_stmt";
3801 case DW_TAG_access_declaration:
3802 return "DW_TAG_access_declaration";
3803 case DW_TAG_base_type:
3804 return "DW_TAG_base_type";
3805 case DW_TAG_catch_block:
3806 return "DW_TAG_catch_block";
3807 case DW_TAG_const_type:
3808 return "DW_TAG_const_type";
3809 case DW_TAG_constant:
3810 return "DW_TAG_constant";
3811 case DW_TAG_enumerator:
3812 return "DW_TAG_enumerator";
3813 case DW_TAG_file_type:
3814 return "DW_TAG_file_type";
3815 case DW_TAG_friend:
3816 return "DW_TAG_friend";
3817 case DW_TAG_namelist:
3818 return "DW_TAG_namelist";
3819 case DW_TAG_namelist_item:
3820 return "DW_TAG_namelist_item";
3821 case DW_TAG_packed_type:
3822 return "DW_TAG_packed_type";
3823 case DW_TAG_subprogram:
3824 return "DW_TAG_subprogram";
3825 case DW_TAG_template_type_param:
3826 return "DW_TAG_template_type_param";
3827 case DW_TAG_template_value_param:
3828 return "DW_TAG_template_value_param";
3829 case DW_TAG_thrown_type:
3830 return "DW_TAG_thrown_type";
3831 case DW_TAG_try_block:
3832 return "DW_TAG_try_block";
3833 case DW_TAG_variant_part:
3834 return "DW_TAG_variant_part";
3835 case DW_TAG_variable:
3836 return "DW_TAG_variable";
3837 case DW_TAG_volatile_type:
3838 return "DW_TAG_volatile_type";
3839 case DW_TAG_MIPS_loop:
3840 return "DW_TAG_MIPS_loop";
3841 case DW_TAG_format_label:
3842 return "DW_TAG_format_label";
3843 case DW_TAG_function_template:
3844 return "DW_TAG_function_template";
3845 case DW_TAG_class_template:
3846 return "DW_TAG_class_template";
3847 case DW_TAG_GNU_BINCL:
3848 return "DW_TAG_GNU_BINCL";
3849 case DW_TAG_GNU_EINCL:
3850 return "DW_TAG_GNU_EINCL";
3851 default:
3852 return "DW_TAG_<unknown>";
3856 /* Convert a DWARF attribute code into its string name. */
3858 static const char *
3859 dwarf_attr_name (attr)
3860 register unsigned attr;
3862 switch (attr)
3864 case DW_AT_sibling:
3865 return "DW_AT_sibling";
3866 case DW_AT_location:
3867 return "DW_AT_location";
3868 case DW_AT_name:
3869 return "DW_AT_name";
3870 case DW_AT_ordering:
3871 return "DW_AT_ordering";
3872 case DW_AT_subscr_data:
3873 return "DW_AT_subscr_data";
3874 case DW_AT_byte_size:
3875 return "DW_AT_byte_size";
3876 case DW_AT_bit_offset:
3877 return "DW_AT_bit_offset";
3878 case DW_AT_bit_size:
3879 return "DW_AT_bit_size";
3880 case DW_AT_element_list:
3881 return "DW_AT_element_list";
3882 case DW_AT_stmt_list:
3883 return "DW_AT_stmt_list";
3884 case DW_AT_low_pc:
3885 return "DW_AT_low_pc";
3886 case DW_AT_high_pc:
3887 return "DW_AT_high_pc";
3888 case DW_AT_language:
3889 return "DW_AT_language";
3890 case DW_AT_member:
3891 return "DW_AT_member";
3892 case DW_AT_discr:
3893 return "DW_AT_discr";
3894 case DW_AT_discr_value:
3895 return "DW_AT_discr_value";
3896 case DW_AT_visibility:
3897 return "DW_AT_visibility";
3898 case DW_AT_import:
3899 return "DW_AT_import";
3900 case DW_AT_string_length:
3901 return "DW_AT_string_length";
3902 case DW_AT_common_reference:
3903 return "DW_AT_common_reference";
3904 case DW_AT_comp_dir:
3905 return "DW_AT_comp_dir";
3906 case DW_AT_const_value:
3907 return "DW_AT_const_value";
3908 case DW_AT_containing_type:
3909 return "DW_AT_containing_type";
3910 case DW_AT_default_value:
3911 return "DW_AT_default_value";
3912 case DW_AT_inline:
3913 return "DW_AT_inline";
3914 case DW_AT_is_optional:
3915 return "DW_AT_is_optional";
3916 case DW_AT_lower_bound:
3917 return "DW_AT_lower_bound";
3918 case DW_AT_producer:
3919 return "DW_AT_producer";
3920 case DW_AT_prototyped:
3921 return "DW_AT_prototyped";
3922 case DW_AT_return_addr:
3923 return "DW_AT_return_addr";
3924 case DW_AT_start_scope:
3925 return "DW_AT_start_scope";
3926 case DW_AT_stride_size:
3927 return "DW_AT_stride_size";
3928 case DW_AT_upper_bound:
3929 return "DW_AT_upper_bound";
3930 case DW_AT_abstract_origin:
3931 return "DW_AT_abstract_origin";
3932 case DW_AT_accessibility:
3933 return "DW_AT_accessibility";
3934 case DW_AT_address_class:
3935 return "DW_AT_address_class";
3936 case DW_AT_artificial:
3937 return "DW_AT_artificial";
3938 case DW_AT_base_types:
3939 return "DW_AT_base_types";
3940 case DW_AT_calling_convention:
3941 return "DW_AT_calling_convention";
3942 case DW_AT_count:
3943 return "DW_AT_count";
3944 case DW_AT_data_member_location:
3945 return "DW_AT_data_member_location";
3946 case DW_AT_decl_column:
3947 return "DW_AT_decl_column";
3948 case DW_AT_decl_file:
3949 return "DW_AT_decl_file";
3950 case DW_AT_decl_line:
3951 return "DW_AT_decl_line";
3952 case DW_AT_declaration:
3953 return "DW_AT_declaration";
3954 case DW_AT_discr_list:
3955 return "DW_AT_discr_list";
3956 case DW_AT_encoding:
3957 return "DW_AT_encoding";
3958 case DW_AT_external:
3959 return "DW_AT_external";
3960 case DW_AT_frame_base:
3961 return "DW_AT_frame_base";
3962 case DW_AT_friend:
3963 return "DW_AT_friend";
3964 case DW_AT_identifier_case:
3965 return "DW_AT_identifier_case";
3966 case DW_AT_macro_info:
3967 return "DW_AT_macro_info";
3968 case DW_AT_namelist_items:
3969 return "DW_AT_namelist_items";
3970 case DW_AT_priority:
3971 return "DW_AT_priority";
3972 case DW_AT_segment:
3973 return "DW_AT_segment";
3974 case DW_AT_specification:
3975 return "DW_AT_specification";
3976 case DW_AT_static_link:
3977 return "DW_AT_static_link";
3978 case DW_AT_type:
3979 return "DW_AT_type";
3980 case DW_AT_use_location:
3981 return "DW_AT_use_location";
3982 case DW_AT_variable_parameter:
3983 return "DW_AT_variable_parameter";
3984 case DW_AT_virtuality:
3985 return "DW_AT_virtuality";
3986 case DW_AT_vtable_elem_location:
3987 return "DW_AT_vtable_elem_location";
3989 case DW_AT_MIPS_fde:
3990 return "DW_AT_MIPS_fde";
3991 case DW_AT_MIPS_loop_begin:
3992 return "DW_AT_MIPS_loop_begin";
3993 case DW_AT_MIPS_tail_loop_begin:
3994 return "DW_AT_MIPS_tail_loop_begin";
3995 case DW_AT_MIPS_epilog_begin:
3996 return "DW_AT_MIPS_epilog_begin";
3997 case DW_AT_MIPS_loop_unroll_factor:
3998 return "DW_AT_MIPS_loop_unroll_factor";
3999 case DW_AT_MIPS_software_pipeline_depth:
4000 return "DW_AT_MIPS_software_pipeline_depth";
4001 case DW_AT_MIPS_linkage_name:
4002 return "DW_AT_MIPS_linkage_name";
4003 case DW_AT_MIPS_stride:
4004 return "DW_AT_MIPS_stride";
4005 case DW_AT_MIPS_abstract_name:
4006 return "DW_AT_MIPS_abstract_name";
4007 case DW_AT_MIPS_clone_origin:
4008 return "DW_AT_MIPS_clone_origin";
4009 case DW_AT_MIPS_has_inlines:
4010 return "DW_AT_MIPS_has_inlines";
4012 case DW_AT_sf_names:
4013 return "DW_AT_sf_names";
4014 case DW_AT_src_info:
4015 return "DW_AT_src_info";
4016 case DW_AT_mac_info:
4017 return "DW_AT_mac_info";
4018 case DW_AT_src_coords:
4019 return "DW_AT_src_coords";
4020 case DW_AT_body_begin:
4021 return "DW_AT_body_begin";
4022 case DW_AT_body_end:
4023 return "DW_AT_body_end";
4024 default:
4025 return "DW_AT_<unknown>";
4029 /* Convert a DWARF value form code into its string name. */
4031 static const char *
4032 dwarf_form_name (form)
4033 register unsigned form;
4035 switch (form)
4037 case DW_FORM_addr:
4038 return "DW_FORM_addr";
4039 case DW_FORM_block2:
4040 return "DW_FORM_block2";
4041 case DW_FORM_block4:
4042 return "DW_FORM_block4";
4043 case DW_FORM_data2:
4044 return "DW_FORM_data2";
4045 case DW_FORM_data4:
4046 return "DW_FORM_data4";
4047 case DW_FORM_data8:
4048 return "DW_FORM_data8";
4049 case DW_FORM_string:
4050 return "DW_FORM_string";
4051 case DW_FORM_block:
4052 return "DW_FORM_block";
4053 case DW_FORM_block1:
4054 return "DW_FORM_block1";
4055 case DW_FORM_data1:
4056 return "DW_FORM_data1";
4057 case DW_FORM_flag:
4058 return "DW_FORM_flag";
4059 case DW_FORM_sdata:
4060 return "DW_FORM_sdata";
4061 case DW_FORM_strp:
4062 return "DW_FORM_strp";
4063 case DW_FORM_udata:
4064 return "DW_FORM_udata";
4065 case DW_FORM_ref_addr:
4066 return "DW_FORM_ref_addr";
4067 case DW_FORM_ref1:
4068 return "DW_FORM_ref1";
4069 case DW_FORM_ref2:
4070 return "DW_FORM_ref2";
4071 case DW_FORM_ref4:
4072 return "DW_FORM_ref4";
4073 case DW_FORM_ref8:
4074 return "DW_FORM_ref8";
4075 case DW_FORM_ref_udata:
4076 return "DW_FORM_ref_udata";
4077 case DW_FORM_indirect:
4078 return "DW_FORM_indirect";
4079 default:
4080 return "DW_FORM_<unknown>";
4084 /* Convert a DWARF type code into its string name. */
4086 #if 0
4087 static const char *
4088 dwarf_type_encoding_name (enc)
4089 register unsigned enc;
4091 switch (enc)
4093 case DW_ATE_address:
4094 return "DW_ATE_address";
4095 case DW_ATE_boolean:
4096 return "DW_ATE_boolean";
4097 case DW_ATE_complex_float:
4098 return "DW_ATE_complex_float";
4099 case DW_ATE_float:
4100 return "DW_ATE_float";
4101 case DW_ATE_signed:
4102 return "DW_ATE_signed";
4103 case DW_ATE_signed_char:
4104 return "DW_ATE_signed_char";
4105 case DW_ATE_unsigned:
4106 return "DW_ATE_unsigned";
4107 case DW_ATE_unsigned_char:
4108 return "DW_ATE_unsigned_char";
4109 default:
4110 return "DW_ATE_<unknown>";
4113 #endif
4115 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4116 instance of an inlined instance of a decl which is local to an inline
4117 function, so we have to trace all of the way back through the origin chain
4118 to find out what sort of node actually served as the original seed for the
4119 given block. */
4121 static tree
4122 decl_ultimate_origin (decl)
4123 register tree decl;
4125 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4126 nodes in the function to point to themselves; ignore that if
4127 we're trying to output the abstract instance of this function. */
4128 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4129 return NULL_TREE;
4131 #ifdef ENABLE_CHECKING
4132 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4133 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4134 most distant ancestor, this should never happen. */
4135 abort ();
4136 #endif
4138 return DECL_ABSTRACT_ORIGIN (decl);
4141 /* Determine the "ultimate origin" of a block. The block may be an inlined
4142 instance of an inlined instance of a block which is local to an inline
4143 function, so we have to trace all of the way back through the origin chain
4144 to find out what sort of node actually served as the original seed for the
4145 given block. */
4147 static tree
4148 block_ultimate_origin (block)
4149 register tree block;
4151 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4153 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4154 nodes in the function to point to themselves; ignore that if
4155 we're trying to output the abstract instance of this function. */
4156 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4157 return NULL_TREE;
4159 if (immediate_origin == NULL_TREE)
4160 return NULL_TREE;
4161 else
4163 register tree ret_val;
4164 register tree lookahead = immediate_origin;
4168 ret_val = lookahead;
4169 lookahead = (TREE_CODE (ret_val) == BLOCK)
4170 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4171 : NULL;
4173 while (lookahead != NULL && lookahead != ret_val);
4175 return ret_val;
4179 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4180 of a virtual function may refer to a base class, so we check the 'this'
4181 parameter. */
4183 static tree
4184 decl_class_context (decl)
4185 tree decl;
4187 tree context = NULL_TREE;
4189 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4190 context = DECL_CONTEXT (decl);
4191 else
4192 context = TYPE_MAIN_VARIANT
4193 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4195 if (context && !TYPE_P (context))
4196 context = NULL_TREE;
4198 return context;
4201 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4202 addition order, and correct that in reverse_all_dies. */
4204 static inline void
4205 add_dwarf_attr (die, attr)
4206 register dw_die_ref die;
4207 register dw_attr_ref attr;
4209 if (die != NULL && attr != NULL)
4211 attr->dw_attr_next = die->die_attr;
4212 die->die_attr = attr;
4216 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4217 static inline dw_val_class
4218 AT_class (a)
4219 dw_attr_ref a;
4221 return a->dw_attr_val.val_class;
4224 /* Add a flag value attribute to a DIE. */
4226 static inline void
4227 add_AT_flag (die, attr_kind, flag)
4228 register dw_die_ref die;
4229 register enum dwarf_attribute attr_kind;
4230 register unsigned flag;
4232 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4234 attr->dw_attr_next = NULL;
4235 attr->dw_attr = attr_kind;
4236 attr->dw_attr_val.val_class = dw_val_class_flag;
4237 attr->dw_attr_val.v.val_flag = flag;
4238 add_dwarf_attr (die, attr);
4241 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4242 static inline unsigned
4243 AT_flag (a)
4244 register dw_attr_ref a;
4246 if (a && AT_class (a) == dw_val_class_flag)
4247 return a->dw_attr_val.v.val_flag;
4249 abort ();
4252 /* Add a signed integer attribute value to a DIE. */
4254 static inline void
4255 add_AT_int (die, attr_kind, int_val)
4256 register dw_die_ref die;
4257 register enum dwarf_attribute attr_kind;
4258 register long int int_val;
4260 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4262 attr->dw_attr_next = NULL;
4263 attr->dw_attr = attr_kind;
4264 attr->dw_attr_val.val_class = dw_val_class_const;
4265 attr->dw_attr_val.v.val_int = int_val;
4266 add_dwarf_attr (die, attr);
4269 static inline long int AT_int PARAMS ((dw_attr_ref));
4270 static inline long int
4271 AT_int (a)
4272 register dw_attr_ref a;
4274 if (a && AT_class (a) == dw_val_class_const)
4275 return a->dw_attr_val.v.val_int;
4277 abort ();
4280 /* Add an unsigned integer attribute value to a DIE. */
4282 static inline void
4283 add_AT_unsigned (die, attr_kind, unsigned_val)
4284 register dw_die_ref die;
4285 register enum dwarf_attribute attr_kind;
4286 register unsigned long unsigned_val;
4288 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4290 attr->dw_attr_next = NULL;
4291 attr->dw_attr = attr_kind;
4292 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4293 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4294 add_dwarf_attr (die, attr);
4297 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4298 static inline unsigned long
4299 AT_unsigned (a)
4300 register dw_attr_ref a;
4302 if (a && AT_class (a) == dw_val_class_unsigned_const)
4303 return a->dw_attr_val.v.val_unsigned;
4305 abort ();
4308 /* Add an unsigned double integer attribute value to a DIE. */
4310 static inline void
4311 add_AT_long_long (die, attr_kind, val_hi, val_low)
4312 register dw_die_ref die;
4313 register enum dwarf_attribute attr_kind;
4314 register unsigned long val_hi;
4315 register unsigned long val_low;
4317 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4319 attr->dw_attr_next = NULL;
4320 attr->dw_attr = attr_kind;
4321 attr->dw_attr_val.val_class = dw_val_class_long_long;
4322 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4323 attr->dw_attr_val.v.val_long_long.low = val_low;
4324 add_dwarf_attr (die, attr);
4327 /* Add a floating point attribute value to a DIE and return it. */
4329 static inline void
4330 add_AT_float (die, attr_kind, length, array)
4331 register dw_die_ref die;
4332 register enum dwarf_attribute attr_kind;
4333 register unsigned length;
4334 register long *array;
4336 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4338 attr->dw_attr_next = NULL;
4339 attr->dw_attr = attr_kind;
4340 attr->dw_attr_val.val_class = dw_val_class_float;
4341 attr->dw_attr_val.v.val_float.length = length;
4342 attr->dw_attr_val.v.val_float.array = array;
4343 add_dwarf_attr (die, attr);
4346 /* Add a string attribute value to a DIE. */
4348 static inline void
4349 add_AT_string (die, attr_kind, str)
4350 register dw_die_ref die;
4351 register enum dwarf_attribute attr_kind;
4352 register const char *str;
4354 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4356 attr->dw_attr_next = NULL;
4357 attr->dw_attr = attr_kind;
4358 attr->dw_attr_val.val_class = dw_val_class_str;
4359 attr->dw_attr_val.v.val_str = xstrdup (str);
4360 add_dwarf_attr (die, attr);
4363 static inline const char *AT_string PARAMS ((dw_attr_ref));
4364 static inline const char *
4365 AT_string (a)
4366 register dw_attr_ref a;
4368 if (a && AT_class (a) == dw_val_class_str)
4369 return a->dw_attr_val.v.val_str;
4371 abort ();
4374 /* Add a DIE reference attribute value to a DIE. */
4376 static inline void
4377 add_AT_die_ref (die, attr_kind, targ_die)
4378 register dw_die_ref die;
4379 register enum dwarf_attribute attr_kind;
4380 register dw_die_ref targ_die;
4382 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4384 attr->dw_attr_next = NULL;
4385 attr->dw_attr = attr_kind;
4386 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4387 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4388 attr->dw_attr_val.v.val_die_ref.external = 0;
4389 add_dwarf_attr (die, attr);
4392 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4393 static inline dw_die_ref
4394 AT_ref (a)
4395 register dw_attr_ref a;
4397 if (a && AT_class (a) == dw_val_class_die_ref)
4398 return a->dw_attr_val.v.val_die_ref.die;
4400 abort ();
4403 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4404 static inline int
4405 AT_ref_external (a)
4406 register dw_attr_ref a;
4408 if (a && AT_class (a) == dw_val_class_die_ref)
4409 return a->dw_attr_val.v.val_die_ref.external;
4411 return 0;
4414 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4415 static inline void
4416 set_AT_ref_external (a, i)
4417 register dw_attr_ref a;
4418 int i;
4420 if (a && AT_class (a) == dw_val_class_die_ref)
4421 a->dw_attr_val.v.val_die_ref.external = i;
4422 else
4423 abort ();
4426 /* Add an FDE reference attribute value to a DIE. */
4428 static inline void
4429 add_AT_fde_ref (die, attr_kind, targ_fde)
4430 register dw_die_ref die;
4431 register enum dwarf_attribute attr_kind;
4432 register unsigned targ_fde;
4434 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4436 attr->dw_attr_next = NULL;
4437 attr->dw_attr = attr_kind;
4438 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4439 attr->dw_attr_val.v.val_fde_index = targ_fde;
4440 add_dwarf_attr (die, attr);
4443 /* Add a location description attribute value to a DIE. */
4445 static inline void
4446 add_AT_loc (die, attr_kind, loc)
4447 register dw_die_ref die;
4448 register enum dwarf_attribute attr_kind;
4449 register dw_loc_descr_ref loc;
4451 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4453 attr->dw_attr_next = NULL;
4454 attr->dw_attr = attr_kind;
4455 attr->dw_attr_val.val_class = dw_val_class_loc;
4456 attr->dw_attr_val.v.val_loc = loc;
4457 add_dwarf_attr (die, attr);
4460 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4461 static inline dw_loc_descr_ref
4462 AT_loc (a)
4463 register dw_attr_ref a;
4465 if (a && AT_class (a) == dw_val_class_loc)
4466 return a->dw_attr_val.v.val_loc;
4468 abort ();
4471 /* Add an address constant attribute value to a DIE. */
4473 static inline void
4474 add_AT_addr (die, attr_kind, addr)
4475 register dw_die_ref die;
4476 register enum dwarf_attribute attr_kind;
4477 rtx addr;
4479 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4481 attr->dw_attr_next = NULL;
4482 attr->dw_attr = attr_kind;
4483 attr->dw_attr_val.val_class = dw_val_class_addr;
4484 attr->dw_attr_val.v.val_addr = addr;
4485 add_dwarf_attr (die, attr);
4488 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4489 static inline rtx
4490 AT_addr (a)
4491 register dw_attr_ref a;
4493 if (a && AT_class (a) == dw_val_class_addr)
4494 return a->dw_attr_val.v.val_addr;
4496 abort ();
4499 /* Add a label identifier attribute value to a DIE. */
4501 static inline void
4502 add_AT_lbl_id (die, attr_kind, lbl_id)
4503 register dw_die_ref die;
4504 register enum dwarf_attribute attr_kind;
4505 register const char *lbl_id;
4507 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4509 attr->dw_attr_next = NULL;
4510 attr->dw_attr = attr_kind;
4511 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4512 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4513 add_dwarf_attr (die, attr);
4516 /* Add a section offset attribute value to a DIE. */
4518 static inline void
4519 add_AT_lbl_offset (die, attr_kind, label)
4520 register dw_die_ref die;
4521 register enum dwarf_attribute attr_kind;
4522 register const char *label;
4524 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4526 attr->dw_attr_next = NULL;
4527 attr->dw_attr = attr_kind;
4528 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4529 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4530 add_dwarf_attr (die, attr);
4533 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4534 static inline const char *
4535 AT_lbl (a)
4536 register dw_attr_ref a;
4538 if (a && (AT_class (a) == dw_val_class_lbl_id
4539 || AT_class (a) == dw_val_class_lbl_offset))
4540 return a->dw_attr_val.v.val_lbl_id;
4542 abort ();
4545 /* Get the attribute of type attr_kind. */
4547 static inline dw_attr_ref
4548 get_AT (die, attr_kind)
4549 register dw_die_ref die;
4550 register enum dwarf_attribute attr_kind;
4552 register dw_attr_ref a;
4553 register dw_die_ref spec = NULL;
4555 if (die != NULL)
4557 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4559 if (a->dw_attr == attr_kind)
4560 return a;
4562 if (a->dw_attr == DW_AT_specification
4563 || a->dw_attr == DW_AT_abstract_origin)
4564 spec = AT_ref (a);
4567 if (spec)
4568 return get_AT (spec, attr_kind);
4571 return NULL;
4574 /* Return the "low pc" attribute value, typically associated with
4575 a subprogram DIE. Return null if the "low pc" attribute is
4576 either not prsent, or if it cannot be represented as an
4577 assembler label identifier. */
4579 static inline const char *
4580 get_AT_low_pc (die)
4581 register dw_die_ref die;
4583 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4584 return a ? AT_lbl (a) : NULL;
4587 /* Return the "high pc" attribute value, typically associated with
4588 a subprogram DIE. Return null if the "high pc" attribute is
4589 either not prsent, or if it cannot be represented as an
4590 assembler label identifier. */
4592 static inline const char *
4593 get_AT_hi_pc (die)
4594 register dw_die_ref die;
4596 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4597 return a ? AT_lbl (a) : NULL;
4600 /* Return the value of the string attribute designated by ATTR_KIND, or
4601 NULL if it is not present. */
4603 static inline const char *
4604 get_AT_string (die, attr_kind)
4605 register dw_die_ref die;
4606 register enum dwarf_attribute attr_kind;
4608 register dw_attr_ref a = get_AT (die, attr_kind);
4609 return a ? AT_string (a) : NULL;
4612 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4613 if it is not present. */
4615 static inline int
4616 get_AT_flag (die, attr_kind)
4617 register dw_die_ref die;
4618 register enum dwarf_attribute attr_kind;
4620 register dw_attr_ref a = get_AT (die, attr_kind);
4621 return a ? AT_flag (a) : 0;
4624 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4625 if it is not present. */
4627 static inline unsigned
4628 get_AT_unsigned (die, attr_kind)
4629 register dw_die_ref die;
4630 register enum dwarf_attribute attr_kind;
4632 register dw_attr_ref a = get_AT (die, attr_kind);
4633 return a ? AT_unsigned (a) : 0;
4636 static inline dw_die_ref
4637 get_AT_ref (die, attr_kind)
4638 dw_die_ref die;
4639 register enum dwarf_attribute attr_kind;
4641 register dw_attr_ref a = get_AT (die, attr_kind);
4642 return a ? AT_ref (a) : NULL;
4645 static inline int
4646 is_c_family ()
4648 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4650 return (lang == DW_LANG_C || lang == DW_LANG_C89
4651 || lang == DW_LANG_C_plus_plus);
4654 static inline int
4655 is_fortran ()
4657 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4659 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4662 static inline int
4663 is_java ()
4665 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4667 return (lang == DW_LANG_Java);
4670 /* Free up the memory used by A. */
4672 static inline void free_AT PARAMS ((dw_attr_ref));
4673 static inline void
4674 free_AT (a)
4675 dw_attr_ref a;
4677 switch (AT_class (a))
4679 case dw_val_class_str:
4680 case dw_val_class_lbl_id:
4681 case dw_val_class_lbl_offset:
4682 free (a->dw_attr_val.v.val_str);
4683 break;
4685 case dw_val_class_float:
4686 free (a->dw_attr_val.v.val_float.array);
4687 break;
4689 default:
4690 break;
4693 free (a);
4696 /* Remove the specified attribute if present. */
4698 static void
4699 remove_AT (die, attr_kind)
4700 register dw_die_ref die;
4701 register enum dwarf_attribute attr_kind;
4703 register dw_attr_ref *p;
4704 register dw_attr_ref removed = NULL;
4706 if (die != NULL)
4708 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4709 if ((*p)->dw_attr == attr_kind)
4711 removed = *p;
4712 *p = (*p)->dw_attr_next;
4713 break;
4716 if (removed != 0)
4717 free_AT (removed);
4721 /* Free up the memory used by DIE. */
4723 static inline void free_die PARAMS ((dw_die_ref));
4724 static inline void
4725 free_die (die)
4726 dw_die_ref die;
4728 remove_children (die);
4729 free (die);
4732 /* Discard the children of this DIE. */
4734 static void
4735 remove_children (die)
4736 register dw_die_ref die;
4738 register dw_die_ref child_die = die->die_child;
4740 die->die_child = NULL;
4742 while (child_die != NULL)
4744 register dw_die_ref tmp_die = child_die;
4745 register dw_attr_ref a;
4747 child_die = child_die->die_sib;
4749 for (a = tmp_die->die_attr; a != NULL;)
4751 register dw_attr_ref tmp_a = a;
4753 a = a->dw_attr_next;
4754 free_AT (tmp_a);
4757 free_die (tmp_die);
4761 /* Add a child DIE below its parent. We build the lists up in reverse
4762 addition order, and correct that in reverse_all_dies. */
4764 static inline void
4765 add_child_die (die, child_die)
4766 register dw_die_ref die;
4767 register dw_die_ref child_die;
4769 if (die != NULL && child_die != NULL)
4771 if (die == child_die)
4772 abort ();
4773 child_die->die_parent = die;
4774 child_die->die_sib = die->die_child;
4775 die->die_child = child_die;
4779 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4780 is the specification, to the front of PARENT's list of children. */
4782 static void
4783 splice_child_die (parent, child)
4784 dw_die_ref parent, child;
4786 dw_die_ref *p;
4788 /* We want the declaration DIE from inside the class, not the
4789 specification DIE at toplevel. */
4790 if (child->die_parent != parent)
4792 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4793 if (tmp)
4794 child = tmp;
4797 if (child->die_parent != parent
4798 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4799 abort ();
4801 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4802 if (*p == child)
4804 *p = child->die_sib;
4805 break;
4808 child->die_sib = parent->die_child;
4809 parent->die_child = child;
4812 /* Return a pointer to a newly created DIE node. */
4814 static inline dw_die_ref
4815 new_die (tag_value, parent_die)
4816 register enum dwarf_tag tag_value;
4817 register dw_die_ref parent_die;
4819 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
4821 die->die_tag = tag_value;
4823 if (parent_die != NULL)
4824 add_child_die (parent_die, die);
4825 else
4827 limbo_die_node *limbo_node;
4829 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4830 limbo_node->die = die;
4831 limbo_node->next = limbo_die_list;
4832 limbo_die_list = limbo_node;
4835 return die;
4838 /* Return the DIE associated with the given type specifier. */
4840 static inline dw_die_ref
4841 lookup_type_die (type)
4842 register tree type;
4844 if (TREE_CODE (type) == VECTOR_TYPE)
4845 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4846 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4849 /* Equate a DIE to a given type specifier. */
4851 static inline void
4852 equate_type_number_to_die (type, type_die)
4853 register tree type;
4854 register dw_die_ref type_die;
4856 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4859 /* Return the DIE associated with a given declaration. */
4861 static inline dw_die_ref
4862 lookup_decl_die (decl)
4863 register tree decl;
4865 register unsigned decl_id = DECL_UID (decl);
4867 return (decl_id < decl_die_table_in_use
4868 ? decl_die_table[decl_id] : NULL);
4871 /* Equate a DIE to a particular declaration. */
4873 static void
4874 equate_decl_number_to_die (decl, decl_die)
4875 register tree decl;
4876 register dw_die_ref decl_die;
4878 register unsigned decl_id = DECL_UID (decl);
4879 register unsigned num_allocated;
4881 if (decl_id >= decl_die_table_allocated)
4883 num_allocated
4884 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4885 / DECL_DIE_TABLE_INCREMENT)
4886 * DECL_DIE_TABLE_INCREMENT;
4888 decl_die_table
4889 = (dw_die_ref *) xrealloc (decl_die_table,
4890 sizeof (dw_die_ref) * num_allocated);
4892 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
4893 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4894 decl_die_table_allocated = num_allocated;
4897 if (decl_id >= decl_die_table_in_use)
4898 decl_die_table_in_use = (decl_id + 1);
4900 decl_die_table[decl_id] = decl_die;
4903 /* Keep track of the number of spaces used to indent the
4904 output of the debugging routines that print the structure of
4905 the DIE internal representation. */
4906 static int print_indent;
4908 /* Indent the line the number of spaces given by print_indent. */
4910 static inline void
4911 print_spaces (outfile)
4912 FILE *outfile;
4914 fprintf (outfile, "%*s", print_indent, "");
4917 /* Print the information associated with a given DIE, and its children.
4918 This routine is a debugging aid only. */
4920 static void
4921 print_die (die, outfile)
4922 dw_die_ref die;
4923 FILE *outfile;
4925 register dw_attr_ref a;
4926 register dw_die_ref c;
4928 print_spaces (outfile);
4929 fprintf (outfile, "DIE %4lu: %s\n",
4930 die->die_offset, dwarf_tag_name (die->die_tag));
4931 print_spaces (outfile);
4932 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4933 fprintf (outfile, " offset: %lu\n", die->die_offset);
4935 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4937 print_spaces (outfile);
4938 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4940 switch (AT_class (a))
4942 case dw_val_class_addr:
4943 fprintf (outfile, "address");
4944 break;
4945 case dw_val_class_loc:
4946 fprintf (outfile, "location descriptor");
4947 break;
4948 case dw_val_class_const:
4949 fprintf (outfile, "%ld", AT_int (a));
4950 break;
4951 case dw_val_class_unsigned_const:
4952 fprintf (outfile, "%lu", AT_unsigned (a));
4953 break;
4954 case dw_val_class_long_long:
4955 fprintf (outfile, "constant (%lu,%lu)",
4956 a->dw_attr_val.v.val_long_long.hi,
4957 a->dw_attr_val.v.val_long_long.low);
4958 break;
4959 case dw_val_class_float:
4960 fprintf (outfile, "floating-point constant");
4961 break;
4962 case dw_val_class_flag:
4963 fprintf (outfile, "%u", AT_flag (a));
4964 break;
4965 case dw_val_class_die_ref:
4966 if (AT_ref (a) != NULL)
4968 if (AT_ref (a)->die_symbol)
4969 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
4970 else
4971 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4973 else
4974 fprintf (outfile, "die -> <null>");
4975 break;
4976 case dw_val_class_lbl_id:
4977 case dw_val_class_lbl_offset:
4978 fprintf (outfile, "label: %s", AT_lbl (a));
4979 break;
4980 case dw_val_class_str:
4981 if (AT_string (a) != NULL)
4982 fprintf (outfile, "\"%s\"", AT_string (a));
4983 else
4984 fprintf (outfile, "<null>");
4985 break;
4986 default:
4987 break;
4990 fprintf (outfile, "\n");
4993 if (die->die_child != NULL)
4995 print_indent += 4;
4996 for (c = die->die_child; c != NULL; c = c->die_sib)
4997 print_die (c, outfile);
4999 print_indent -= 4;
5001 if (print_indent == 0)
5002 fprintf (outfile, "\n");
5005 /* Print the contents of the source code line number correspondence table.
5006 This routine is a debugging aid only. */
5008 static void
5009 print_dwarf_line_table (outfile)
5010 FILE *outfile;
5012 register unsigned i;
5013 register dw_line_info_ref line_info;
5015 fprintf (outfile, "\n\nDWARF source line information\n");
5016 for (i = 1; i < line_info_table_in_use; ++i)
5018 line_info = &line_info_table[i];
5019 fprintf (outfile, "%5d: ", i);
5020 fprintf (outfile, "%-20s", line_file_table.table[line_info->dw_file_num]);
5021 fprintf (outfile, "%6ld", line_info->dw_line_num);
5022 fprintf (outfile, "\n");
5025 fprintf (outfile, "\n\n");
5028 /* Print the information collected for a given DIE. */
5030 void
5031 debug_dwarf_die (die)
5032 dw_die_ref die;
5034 print_die (die, stderr);
5037 /* Print all DWARF information collected for the compilation unit.
5038 This routine is a debugging aid only. */
5040 void
5041 debug_dwarf ()
5043 print_indent = 0;
5044 print_die (comp_unit_die, stderr);
5045 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5046 print_dwarf_line_table (stderr);
5049 /* We build up the lists of children and attributes by pushing new ones
5050 onto the beginning of the list. Reverse the lists for DIE so that
5051 they are in order of addition. */
5053 static void
5054 reverse_die_lists (die)
5055 register dw_die_ref die;
5057 register dw_die_ref c, cp, cn;
5058 register dw_attr_ref a, ap, an;
5060 for (a = die->die_attr, ap = 0; a; a = an)
5062 an = a->dw_attr_next;
5063 a->dw_attr_next = ap;
5064 ap = a;
5066 die->die_attr = ap;
5068 for (c = die->die_child, cp = 0; c; c = cn)
5070 cn = c->die_sib;
5071 c->die_sib = cp;
5072 cp = c;
5074 die->die_child = cp;
5077 /* reverse_die_lists only reverses the single die you pass it. Since
5078 we used to reverse all dies in add_sibling_attributes, which runs
5079 through all the dies, it would reverse all the dies. Now, however,
5080 since we don't call reverse_die_lists in add_sibling_attributes, we
5081 need a routine to recursively reverse all the dies. This is that
5082 routine. */
5084 static void
5085 reverse_all_dies (die)
5086 register dw_die_ref die;
5088 register dw_die_ref c;
5090 reverse_die_lists (die);
5092 for (c = die->die_child; c; c = c->die_sib)
5093 reverse_all_dies (c);
5096 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5097 the CU for the enclosing include file, if any. BINCL_DIE is the
5098 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5099 include file. */
5101 static dw_die_ref
5102 push_new_compile_unit (old_unit, bincl_die)
5103 dw_die_ref old_unit, bincl_die;
5105 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5106 dw_die_ref new_unit = gen_compile_unit_die (filename);
5107 new_unit->die_sib = old_unit;
5108 return new_unit;
5111 /* Close an include-file CU and reopen the enclosing one. */
5113 static dw_die_ref
5114 pop_compile_unit (old_unit)
5115 dw_die_ref old_unit;
5117 dw_die_ref new_unit = old_unit->die_sib;
5118 old_unit->die_sib = NULL;
5119 return new_unit;
5122 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5123 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5125 /* Calculate the checksum of a location expression. */
5127 static inline void
5128 loc_checksum (loc, ctx)
5129 dw_loc_descr_ref loc;
5130 struct md5_ctx *ctx;
5132 PROCESS (loc->dw_loc_opc);
5133 PROCESS (loc->dw_loc_oprnd1);
5134 PROCESS (loc->dw_loc_oprnd2);
5137 /* Calculate the checksum of an attribute. */
5139 static void
5140 attr_checksum (at, ctx)
5141 dw_attr_ref at;
5142 struct md5_ctx *ctx;
5144 dw_loc_descr_ref loc;
5145 rtx r;
5147 PROCESS (at->dw_attr);
5149 /* We don't care about differences in file numbering. */
5150 if (at->dw_attr == DW_AT_decl_file
5151 /* Or that this was compiled with a different compiler snapshot; if
5152 the output is the same, that's what matters. */
5153 || at->dw_attr == DW_AT_producer)
5154 return;
5156 switch (AT_class (at))
5158 case dw_val_class_const:
5159 PROCESS (at->dw_attr_val.v.val_int);
5160 break;
5161 case dw_val_class_unsigned_const:
5162 PROCESS (at->dw_attr_val.v.val_unsigned);
5163 break;
5164 case dw_val_class_long_long:
5165 PROCESS (at->dw_attr_val.v.val_long_long);
5166 break;
5167 case dw_val_class_float:
5168 PROCESS (at->dw_attr_val.v.val_float);
5169 break;
5170 case dw_val_class_flag:
5171 PROCESS (at->dw_attr_val.v.val_flag);
5172 break;
5174 case dw_val_class_str:
5175 PROCESS_STRING (AT_string (at));
5176 break;
5177 case dw_val_class_addr:
5178 r = AT_addr (at);
5179 switch (GET_CODE (r))
5181 case SYMBOL_REF:
5182 PROCESS_STRING (XSTR (r, 0));
5183 break;
5185 default:
5186 abort ();
5188 break;
5190 case dw_val_class_loc:
5191 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5192 loc_checksum (loc, ctx);
5193 break;
5195 case dw_val_class_die_ref:
5196 if (AT_ref (at)->die_offset)
5197 PROCESS (AT_ref (at)->die_offset);
5198 /* FIXME else use target die name or something. */
5200 case dw_val_class_fde_ref:
5201 case dw_val_class_lbl_id:
5202 case dw_val_class_lbl_offset:
5204 default:
5205 break;
5209 /* Calculate the checksum of a DIE. */
5211 static void
5212 die_checksum (die, ctx)
5213 dw_die_ref die;
5214 struct md5_ctx *ctx;
5216 dw_die_ref c;
5217 dw_attr_ref a;
5219 PROCESS (die->die_tag);
5221 for (a = die->die_attr; a; a = a->dw_attr_next)
5222 attr_checksum (a, ctx);
5224 for (c = die->die_child; c; c = c->die_sib)
5225 die_checksum (c, ctx);
5228 #undef PROCESS
5229 #undef PROCESS_STRING
5231 /* The prefix to attach to symbols on DIEs in the current comdat debug
5232 info section. */
5233 static char *comdat_symbol_id;
5235 /* The index of the current symbol within the current comdat CU. */
5236 static unsigned int comdat_symbol_number;
5238 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5239 children, and set comdat_symbol_id accordingly. */
5241 static void
5242 compute_section_prefix (unit_die)
5243 dw_die_ref unit_die;
5245 char *p, *name;
5246 int i;
5247 unsigned char checksum[16];
5248 struct md5_ctx ctx;
5250 md5_init_ctx (&ctx);
5251 die_checksum (unit_die, &ctx);
5252 md5_finish_ctx (&ctx, checksum);
5254 p = file_name_nondirectory (get_AT_string (unit_die, DW_AT_name));
5255 name = (char *) alloca (strlen (p) + 64);
5256 sprintf (name, "%s.", p);
5258 clean_symbol_name (name);
5260 p = name + strlen (name);
5261 for (i = 0; i < 4; ++i)
5263 sprintf (p, "%.2x", checksum[i]);
5264 p += 2;
5267 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5268 comdat_symbol_number = 0;
5271 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5273 static int
5274 is_type_die (die)
5275 dw_die_ref die;
5277 switch (die->die_tag)
5279 case DW_TAG_array_type:
5280 case DW_TAG_class_type:
5281 case DW_TAG_enumeration_type:
5282 case DW_TAG_pointer_type:
5283 case DW_TAG_reference_type:
5284 case DW_TAG_string_type:
5285 case DW_TAG_structure_type:
5286 case DW_TAG_subroutine_type:
5287 case DW_TAG_union_type:
5288 case DW_TAG_ptr_to_member_type:
5289 case DW_TAG_set_type:
5290 case DW_TAG_subrange_type:
5291 case DW_TAG_base_type:
5292 case DW_TAG_const_type:
5293 case DW_TAG_file_type:
5294 case DW_TAG_packed_type:
5295 case DW_TAG_volatile_type:
5296 return 1;
5297 default:
5298 return 0;
5302 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5303 Basically, we want to choose the bits that are likely to be shared between
5304 compilations (types) and leave out the bits that are specific to individual
5305 compilations (functions). */
5307 static int
5308 is_comdat_die (c)
5309 dw_die_ref c;
5311 #if 1
5312 /* I think we want to leave base types and __vtbl_ptr_type in the
5313 main CU, as we do for stabs. The advantage is a greater
5314 likelihood of sharing between objects that don't include headers
5315 in the same order (and therefore would put the base types in a
5316 different comdat). jason 8/28/00 */
5317 if (c->die_tag == DW_TAG_base_type)
5318 return 0;
5320 if (c->die_tag == DW_TAG_pointer_type
5321 || c->die_tag == DW_TAG_reference_type
5322 || c->die_tag == DW_TAG_const_type
5323 || c->die_tag == DW_TAG_volatile_type)
5325 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5326 return t ? is_comdat_die (t) : 0;
5328 #endif
5330 return is_type_die (c);
5333 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5334 compilation unit. */
5336 static int
5337 is_symbol_die (c)
5338 dw_die_ref c;
5340 if (is_type_die (c))
5341 return 1;
5342 if (get_AT (c, DW_AT_declaration)
5343 && ! get_AT (c, DW_AT_specification))
5344 return 1;
5345 return 0;
5348 static char *
5349 gen_internal_sym ()
5351 char buf[256];
5352 static int label_num;
5353 ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++);
5354 return xstrdup (buf);
5357 /* Assign symbols to all worthy DIEs under DIE. */
5359 static void
5360 assign_symbol_names (die)
5361 register dw_die_ref die;
5363 register dw_die_ref c;
5365 if (is_symbol_die (die))
5367 if (comdat_symbol_id)
5369 char *p = alloca (strlen (comdat_symbol_id) + 64);
5370 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5371 comdat_symbol_id, comdat_symbol_number++);
5372 die->die_symbol = xstrdup (p);
5374 else
5375 die->die_symbol = gen_internal_sym ();
5378 for (c = die->die_child; c != NULL; c = c->die_sib)
5379 assign_symbol_names (c);
5382 /* Traverse the DIE (which is always comp_unit_die), and set up
5383 additional compilation units for each of the include files we see
5384 bracketed by BINCL/EINCL. */
5386 static void
5387 break_out_includes (die)
5388 register dw_die_ref die;
5390 dw_die_ref *ptr;
5391 register dw_die_ref unit = NULL;
5392 limbo_die_node *node;
5394 for (ptr = &(die->die_child); *ptr; )
5396 register dw_die_ref c = *ptr;
5398 if (c->die_tag == DW_TAG_GNU_BINCL
5399 || c->die_tag == DW_TAG_GNU_EINCL
5400 || (unit && is_comdat_die (c)))
5402 /* This DIE is for a secondary CU; remove it from the main one. */
5403 *ptr = c->die_sib;
5405 if (c->die_tag == DW_TAG_GNU_BINCL)
5407 unit = push_new_compile_unit (unit, c);
5408 free_die (c);
5410 else if (c->die_tag == DW_TAG_GNU_EINCL)
5412 unit = pop_compile_unit (unit);
5413 free_die (c);
5415 else
5416 add_child_die (unit, c);
5418 else
5420 /* Leave this DIE in the main CU. */
5421 ptr = &(c->die_sib);
5422 continue;
5426 #if 0
5427 /* We can only use this in debugging, since the frontend doesn't check
5428 to make sure that we leave every include file we enter. */
5429 if (unit != NULL)
5430 abort ();
5431 #endif
5433 assign_symbol_names (die);
5434 for (node = limbo_die_list; node; node = node->next)
5436 compute_section_prefix (node->die);
5437 assign_symbol_names (node->die);
5441 /* Traverse the DIE and add a sibling attribute if it may have the
5442 effect of speeding up access to siblings. To save some space,
5443 avoid generating sibling attributes for DIE's without children. */
5445 static void
5446 add_sibling_attributes (die)
5447 register dw_die_ref die;
5449 register dw_die_ref c;
5451 if (die->die_tag != DW_TAG_compile_unit
5452 && die->die_sib && die->die_child != NULL)
5453 /* Add the sibling link to the front of the attribute list. */
5454 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5456 for (c = die->die_child; c != NULL; c = c->die_sib)
5457 add_sibling_attributes (c);
5460 /* The format of each DIE (and its attribute value pairs)
5461 is encoded in an abbreviation table. This routine builds the
5462 abbreviation table and assigns a unique abbreviation id for
5463 each abbreviation entry. The children of each die are visited
5464 recursively. */
5466 static void
5467 build_abbrev_table (die)
5468 register dw_die_ref die;
5470 register unsigned long abbrev_id;
5471 register unsigned long n_alloc;
5472 register dw_die_ref c;
5473 register dw_attr_ref d_attr, a_attr;
5475 /* Scan the DIE references, and mark as external any that refer to
5476 DIEs from other CUs (i.e. those which are not marked). */
5477 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5479 if (AT_class (d_attr) == dw_val_class_die_ref
5480 && AT_ref (d_attr)->die_mark == 0)
5482 if (AT_ref (d_attr)->die_symbol == 0)
5483 abort ();
5484 set_AT_ref_external (d_attr, 1);
5488 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5490 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5492 if (abbrev->die_tag == die->die_tag)
5494 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5496 a_attr = abbrev->die_attr;
5497 d_attr = die->die_attr;
5499 while (a_attr != NULL && d_attr != NULL)
5501 if ((a_attr->dw_attr != d_attr->dw_attr)
5502 || (value_format (a_attr) != value_format (d_attr)))
5503 break;
5505 a_attr = a_attr->dw_attr_next;
5506 d_attr = d_attr->dw_attr_next;
5509 if (a_attr == NULL && d_attr == NULL)
5510 break;
5515 if (abbrev_id >= abbrev_die_table_in_use)
5517 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5519 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5520 abbrev_die_table
5521 = (dw_die_ref *) xrealloc (abbrev_die_table,
5522 sizeof (dw_die_ref) * n_alloc);
5524 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5525 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5526 abbrev_die_table_allocated = n_alloc;
5529 ++abbrev_die_table_in_use;
5530 abbrev_die_table[abbrev_id] = die;
5533 die->die_abbrev = abbrev_id;
5534 for (c = die->die_child; c != NULL; c = c->die_sib)
5535 build_abbrev_table (c);
5538 /* Return the size of a string, including the null byte.
5540 This used to treat backslashes as escapes, and hence they were not included
5541 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5542 which treats a backslash as a backslash, escaping it if necessary, and hence
5543 we must include them in the count. */
5545 static unsigned long
5546 size_of_string (str)
5547 register const char *str;
5549 return strlen (str) + 1;
5552 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5554 static int
5555 constant_size (value)
5556 long unsigned value;
5558 int log;
5560 if (value == 0)
5561 log = 0;
5562 else
5563 log = floor_log2 (value);
5565 log = log / 8;
5566 log = 1 << (floor_log2 (log) + 1);
5568 return log;
5571 /* Return the size of a DIE, as it is represented in the
5572 .debug_info section. */
5574 static unsigned long
5575 size_of_die (die)
5576 register dw_die_ref die;
5578 register unsigned long size = 0;
5579 register dw_attr_ref a;
5581 size += size_of_uleb128 (die->die_abbrev);
5582 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5584 switch (AT_class (a))
5586 case dw_val_class_addr:
5587 size += DWARF2_ADDR_SIZE;
5588 break;
5589 case dw_val_class_loc:
5591 register unsigned long lsize = size_of_locs (AT_loc (a));
5593 /* Block length. */
5594 size += constant_size (lsize);
5595 size += lsize;
5597 break;
5598 case dw_val_class_const:
5599 size += size_of_sleb128 (AT_int (a));
5600 break;
5601 case dw_val_class_unsigned_const:
5602 size += constant_size (AT_unsigned (a));
5603 break;
5604 case dw_val_class_long_long:
5605 size += 1 + 8; /* block */
5606 break;
5607 case dw_val_class_float:
5608 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5609 break;
5610 case dw_val_class_flag:
5611 size += 1;
5612 break;
5613 case dw_val_class_die_ref:
5614 size += DWARF_OFFSET_SIZE;
5615 break;
5616 case dw_val_class_fde_ref:
5617 size += DWARF_OFFSET_SIZE;
5618 break;
5619 case dw_val_class_lbl_id:
5620 size += DWARF2_ADDR_SIZE;
5621 break;
5622 case dw_val_class_lbl_offset:
5623 size += DWARF_OFFSET_SIZE;
5624 break;
5625 case dw_val_class_str:
5626 size += size_of_string (AT_string (a));
5627 break;
5628 default:
5629 abort ();
5633 return size;
5636 /* Size the debugging information associated with a given DIE.
5637 Visits the DIE's children recursively. Updates the global
5638 variable next_die_offset, on each time through. Uses the
5639 current value of next_die_offset to update the die_offset
5640 field in each DIE. */
5642 static void
5643 calc_die_sizes (die)
5644 dw_die_ref die;
5646 register dw_die_ref c;
5647 die->die_offset = next_die_offset;
5648 next_die_offset += size_of_die (die);
5650 for (c = die->die_child; c != NULL; c = c->die_sib)
5651 calc_die_sizes (c);
5653 if (die->die_child != NULL)
5654 /* Count the null byte used to terminate sibling lists. */
5655 next_die_offset += 1;
5658 /* Set the marks for a die and its children. We do this so
5659 that we know whether or not a reference needs to use FORM_ref_addr; only
5660 DIEs in the same CU will be marked. We used to clear out the offset
5661 and use that as the flag, but ran into ordering problems. */
5663 static void
5664 mark_dies (die)
5665 dw_die_ref die;
5667 register dw_die_ref c;
5668 die->die_mark = 1;
5669 for (c = die->die_child; c; c = c->die_sib)
5670 mark_dies (c);
5673 /* Clear the marks for a die and its children. */
5675 static void
5676 unmark_dies (die)
5677 dw_die_ref die;
5679 register dw_die_ref c;
5680 die->die_mark = 0;
5681 for (c = die->die_child; c; c = c->die_sib)
5682 unmark_dies (c);
5685 /* Return the size of the line information prolog generated for the
5686 compilation unit. */
5688 static unsigned long
5689 size_of_line_prolog ()
5691 register unsigned long size;
5692 register unsigned long ft_index;
5694 size = DWARF_LINE_PROLOG_HEADER_SIZE;
5696 /* Count the size of the table giving number of args for each
5697 standard opcode. */
5698 size += DWARF_LINE_OPCODE_BASE - 1;
5700 /* Include directory table is empty (at present). Count only the
5701 null byte used to terminate the table. */
5702 size += 1;
5704 for (ft_index = 1; ft_index < decl_file_table.in_use; ++ft_index)
5706 /* File name entry. */
5707 size += size_of_string (decl_file_table.table[ft_index]);
5709 /* Include directory index. */
5710 size += size_of_uleb128 (0);
5712 /* Modification time. */
5713 size += size_of_uleb128 (0);
5715 /* File length in bytes. */
5716 size += size_of_uleb128 (0);
5719 /* Count the file table terminator. */
5720 size += 1;
5721 return size;
5724 /* Return the size of the .debug_pubnames table generated for the
5725 compilation unit. */
5727 static unsigned long
5728 size_of_pubnames ()
5730 register unsigned long size;
5731 register unsigned i;
5733 size = DWARF_PUBNAMES_HEADER_SIZE;
5734 for (i = 0; i < pubname_table_in_use; ++i)
5736 register pubname_ref p = &pubname_table[i];
5737 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5740 size += DWARF_OFFSET_SIZE;
5741 return size;
5744 /* Return the size of the information in the .debug_aranges section. */
5746 static unsigned long
5747 size_of_aranges ()
5749 register unsigned long size;
5751 size = DWARF_ARANGES_HEADER_SIZE;
5753 /* Count the address/length pair for this compilation unit. */
5754 size += 2 * DWARF2_ADDR_SIZE;
5755 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5757 /* Count the two zero words used to terminated the address range table. */
5758 size += 2 * DWARF2_ADDR_SIZE;
5759 return size;
5762 /* Select the encoding of an attribute value. */
5764 static enum dwarf_form
5765 value_format (a)
5766 dw_attr_ref a;
5768 switch (a->dw_attr_val.val_class)
5770 case dw_val_class_addr:
5771 return DW_FORM_addr;
5772 case dw_val_class_loc:
5773 switch (constant_size (size_of_locs (AT_loc (a))))
5775 case 1:
5776 return DW_FORM_block1;
5777 case 2:
5778 return DW_FORM_block2;
5779 default:
5780 abort ();
5782 case dw_val_class_const:
5783 return DW_FORM_sdata;
5784 case dw_val_class_unsigned_const:
5785 switch (constant_size (AT_unsigned (a)))
5787 case 1:
5788 return DW_FORM_data1;
5789 case 2:
5790 return DW_FORM_data2;
5791 case 4:
5792 return DW_FORM_data4;
5793 case 8:
5794 return DW_FORM_data8;
5795 default:
5796 abort ();
5798 case dw_val_class_long_long:
5799 return DW_FORM_block1;
5800 case dw_val_class_float:
5801 return DW_FORM_block1;
5802 case dw_val_class_flag:
5803 return DW_FORM_flag;
5804 case dw_val_class_die_ref:
5805 if (AT_ref_external (a))
5806 return DW_FORM_ref_addr;
5807 else
5808 return DW_FORM_ref;
5809 case dw_val_class_fde_ref:
5810 return DW_FORM_data;
5811 case dw_val_class_lbl_id:
5812 return DW_FORM_addr;
5813 case dw_val_class_lbl_offset:
5814 return DW_FORM_data;
5815 case dw_val_class_str:
5816 return DW_FORM_string;
5817 default:
5818 abort ();
5822 /* Output the encoding of an attribute value. */
5824 static void
5825 output_value_format (a)
5826 dw_attr_ref a;
5828 enum dwarf_form form = value_format (a);
5830 output_uleb128 (form);
5831 if (flag_debug_asm)
5832 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
5834 fputc ('\n', asm_out_file);
5837 /* Output the .debug_abbrev section which defines the DIE abbreviation
5838 table. */
5840 static void
5841 output_abbrev_section ()
5843 unsigned long abbrev_id;
5845 dw_attr_ref a_attr;
5846 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5848 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5850 output_uleb128 (abbrev_id);
5851 if (flag_debug_asm)
5852 fprintf (asm_out_file, " (abbrev code)");
5854 fputc ('\n', asm_out_file);
5855 output_uleb128 (abbrev->die_tag);
5856 if (flag_debug_asm)
5857 fprintf (asm_out_file, " (TAG: %s)",
5858 dwarf_tag_name (abbrev->die_tag));
5860 fputc ('\n', asm_out_file);
5861 fprintf (asm_out_file, "%s0x%x", ASM_BYTE_OP,
5862 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
5864 if (flag_debug_asm)
5865 fprintf (asm_out_file, "\t%s %s",
5866 ASM_COMMENT_START,
5867 (abbrev->die_child != NULL
5868 ? "DW_children_yes" : "DW_children_no"));
5870 fputc ('\n', asm_out_file);
5872 for (a_attr = abbrev->die_attr; a_attr != NULL;
5873 a_attr = a_attr->dw_attr_next)
5875 output_uleb128 (a_attr->dw_attr);
5876 if (flag_debug_asm)
5877 fprintf (asm_out_file, " (%s)",
5878 dwarf_attr_name (a_attr->dw_attr));
5880 fputc ('\n', asm_out_file);
5881 output_value_format (a_attr);
5884 fprintf (asm_out_file, "%s0,0\n", ASM_BYTE_OP);
5887 /* Terminate the table. */
5888 fprintf (asm_out_file, "%s0\n", ASM_BYTE_OP);
5891 /* Output a symbol we can use to refer to this DIE from another CU. */
5893 static inline void
5894 output_die_symbol (die)
5895 register dw_die_ref die;
5897 char *sym = die->die_symbol;
5899 if (sym == 0)
5900 return;
5902 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
5903 /* We make these global, not weak; if the target doesn't support
5904 .linkonce, it doesn't support combining the sections, so debugging
5905 will break. */
5906 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
5907 ASM_OUTPUT_LABEL (asm_out_file, sym);
5910 /* Output a symbolic (i.e. FORM_ref_addr) reference to TARGET_DIE. */
5912 static inline void
5913 output_symbolic_ref (target_die)
5914 dw_die_ref target_die;
5916 char *sym = target_die->die_symbol;
5918 if (sym == 0)
5919 abort ();
5921 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, sym);
5924 /* Output the DIE and its attributes. Called recursively to generate
5925 the definitions of each child DIE. */
5927 static void
5928 output_die (die)
5929 register dw_die_ref die;
5931 register dw_attr_ref a;
5932 register dw_die_ref c;
5933 register unsigned long size;
5935 /* If someone in another CU might refer to us, set up a symbol for
5936 them to point to. */
5937 if (die->die_symbol)
5938 output_die_symbol (die);
5940 output_uleb128 (die->die_abbrev);
5941 if (flag_debug_asm)
5942 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
5943 die->die_offset, dwarf_tag_name (die->die_tag));
5945 fputc ('\n', asm_out_file);
5947 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5949 switch (AT_class (a))
5951 case dw_val_class_addr:
5952 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
5953 break;
5955 case dw_val_class_loc:
5956 size = size_of_locs (AT_loc (a));
5958 /* Output the block length for this list of location operations. */
5959 switch (constant_size (size))
5961 case 1:
5962 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5963 break;
5964 case 2:
5965 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5966 break;
5967 default:
5968 abort ();
5971 if (flag_debug_asm)
5972 fprintf (asm_out_file, "\t%s %s",
5973 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5975 fputc ('\n', asm_out_file);
5977 output_loc_sequence (AT_loc (a));
5978 break;
5980 case dw_val_class_const:
5981 /* ??? It would be slightly more efficient to use a scheme like is
5982 used for unsigned constants below, but gdb 4.x does not sign
5983 extend. Gdb 5.x does sign extend. */
5984 output_sleb128 (AT_int (a));
5985 break;
5987 case dw_val_class_unsigned_const:
5988 switch (constant_size (AT_unsigned (a)))
5990 case 1:
5991 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
5992 break;
5993 case 2:
5994 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
5995 break;
5996 case 4:
5997 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
5998 break;
5999 case 8:
6000 ASM_OUTPUT_DWARF_DATA8 (asm_out_file, AT_unsigned (a));
6001 break;
6002 default:
6003 abort ();
6005 break;
6007 case dw_val_class_long_long:
6008 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
6009 if (flag_debug_asm)
6010 fprintf (asm_out_file, "\t%s %s",
6011 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6013 fputc ('\n', asm_out_file);
6014 ASM_OUTPUT_DWARF_CONST_DOUBLE (asm_out_file,
6015 a->dw_attr_val.v.val_long_long.hi,
6016 a->dw_attr_val.v.val_long_long.low);
6018 if (flag_debug_asm)
6019 fprintf (asm_out_file,
6020 "\t%s long long constant", ASM_COMMENT_START);
6022 fputc ('\n', asm_out_file);
6023 break;
6025 case dw_val_class_float:
6027 register unsigned int i;
6028 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6029 a->dw_attr_val.v.val_float.length * 4);
6030 if (flag_debug_asm)
6031 fprintf (asm_out_file, "\t%s %s",
6032 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6034 fputc ('\n', asm_out_file);
6035 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
6037 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
6038 a->dw_attr_val.v.val_float.array[i]);
6039 if (flag_debug_asm)
6040 fprintf (asm_out_file, "\t%s fp constant word %u",
6041 ASM_COMMENT_START, i);
6043 fputc ('\n', asm_out_file);
6045 break;
6048 case dw_val_class_flag:
6049 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
6050 break;
6052 case dw_val_class_die_ref:
6053 if (AT_ref_external (a))
6054 output_symbolic_ref (AT_ref (a));
6055 else if (AT_ref (a)->die_offset == 0)
6056 abort ();
6057 else
6058 ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
6059 break;
6061 case dw_val_class_fde_ref:
6063 char l1[20];
6064 ASM_GENERATE_INTERNAL_LABEL
6065 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
6066 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
6067 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
6069 break;
6071 case dw_val_class_lbl_id:
6072 ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
6073 break;
6075 case dw_val_class_lbl_offset:
6076 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
6077 break;
6079 case dw_val_class_str:
6080 if (flag_debug_asm)
6081 ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
6082 else
6083 ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
6084 (int) strlen (AT_string (a)) + 1);
6085 break;
6087 default:
6088 abort ();
6091 if (AT_class (a) != dw_val_class_loc
6092 && AT_class (a) != dw_val_class_long_long
6093 && AT_class (a) != dw_val_class_float)
6095 if (flag_debug_asm)
6096 fprintf (asm_out_file, "\t%s %s",
6097 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
6099 fputc ('\n', asm_out_file);
6103 for (c = die->die_child; c != NULL; c = c->die_sib)
6104 output_die (c);
6106 if (die->die_child != NULL)
6108 /* Add null byte to terminate sibling list. */
6109 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6110 if (flag_debug_asm)
6111 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
6112 ASM_COMMENT_START, die->die_offset);
6114 fputc ('\n', asm_out_file);
6118 /* Output the compilation unit that appears at the beginning of the
6119 .debug_info section, and precedes the DIE descriptions. */
6121 static void
6122 output_compilation_unit_header ()
6124 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
6125 if (flag_debug_asm)
6126 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
6127 ASM_COMMENT_START);
6129 fputc ('\n', asm_out_file);
6130 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6131 if (flag_debug_asm)
6132 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
6134 fputc ('\n', asm_out_file);
6135 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
6136 if (flag_debug_asm)
6137 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
6138 ASM_COMMENT_START);
6140 fputc ('\n', asm_out_file);
6141 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6142 if (flag_debug_asm)
6143 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
6145 fputc ('\n', asm_out_file);
6148 /* Output the compilation unit DIE and its children. */
6150 static void
6151 output_comp_unit (die)
6152 dw_die_ref die;
6154 const char *secname;
6156 if (die->die_child == 0)
6157 return;
6159 /* Mark all the DIEs in this CU so we know which get local refs. */
6160 mark_dies (die);
6162 build_abbrev_table (die);
6164 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6165 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6166 calc_die_sizes (die);
6168 if (die->die_symbol)
6170 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6171 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6172 secname = tmp;
6173 die->die_symbol = NULL;
6175 else
6176 secname = (const char *) DEBUG_INFO_SECTION;
6178 /* Output debugging information. */
6179 fputc ('\n', asm_out_file);
6180 ASM_OUTPUT_SECTION (asm_out_file, secname);
6181 output_compilation_unit_header ();
6182 output_die (die);
6184 /* Leave the marks on the main CU, so we can check them in
6185 output_pubnames. */
6186 if (die->die_symbol)
6187 unmark_dies (die);
6190 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6191 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6192 argument list, and maybe the scope. */
6194 static const char *
6195 dwarf2_name (decl, scope)
6196 tree decl;
6197 int scope;
6199 return (*decl_printable_name) (decl, scope ? 1 : 0);
6202 /* Add a new entry to .debug_pubnames if appropriate. */
6204 static void
6205 add_pubname (decl, die)
6206 tree decl;
6207 dw_die_ref die;
6209 pubname_ref p;
6211 if (! TREE_PUBLIC (decl))
6212 return;
6214 if (pubname_table_in_use == pubname_table_allocated)
6216 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6217 pubname_table = (pubname_ref) xrealloc
6218 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6221 p = &pubname_table[pubname_table_in_use++];
6222 p->die = die;
6224 p->name = xstrdup (dwarf2_name (decl, 1));
6227 /* Output the public names table used to speed up access to externally
6228 visible names. For now, only generate entries for externally
6229 visible procedures. */
6231 static void
6232 output_pubnames ()
6234 register unsigned i;
6235 register unsigned long pubnames_length = size_of_pubnames ();
6237 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
6239 if (flag_debug_asm)
6240 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
6241 ASM_COMMENT_START);
6243 fputc ('\n', asm_out_file);
6244 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6246 if (flag_debug_asm)
6247 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6249 fputc ('\n', asm_out_file);
6250 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6251 if (flag_debug_asm)
6252 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6253 ASM_COMMENT_START);
6255 fputc ('\n', asm_out_file);
6256 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
6257 if (flag_debug_asm)
6258 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
6260 fputc ('\n', asm_out_file);
6261 for (i = 0; i < pubname_table_in_use; ++i)
6263 register pubname_ref pub = &pubname_table[i];
6265 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6266 if (pub->die->die_mark == 0)
6267 abort ();
6269 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
6270 if (flag_debug_asm)
6271 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
6273 fputc ('\n', asm_out_file);
6275 if (flag_debug_asm)
6277 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
6278 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
6280 else
6282 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
6283 (int) strlen (pub->name) + 1);
6286 fputc ('\n', asm_out_file);
6289 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
6290 fputc ('\n', asm_out_file);
6293 /* Add a new entry to .debug_aranges if appropriate. */
6295 static void
6296 add_arange (decl, die)
6297 tree decl;
6298 dw_die_ref die;
6300 if (! DECL_SECTION_NAME (decl))
6301 return;
6303 if (arange_table_in_use == arange_table_allocated)
6305 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6306 arange_table
6307 = (arange_ref) xrealloc (arange_table,
6308 arange_table_allocated * sizeof (dw_die_ref));
6311 arange_table[arange_table_in_use++] = die;
6314 /* Output the information that goes into the .debug_aranges table.
6315 Namely, define the beginning and ending address range of the
6316 text section generated for this compilation unit. */
6318 static void
6319 output_aranges ()
6321 register unsigned i;
6322 register unsigned long aranges_length = size_of_aranges ();
6324 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
6325 if (flag_debug_asm)
6326 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
6327 ASM_COMMENT_START);
6329 fputc ('\n', asm_out_file);
6330 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6331 if (flag_debug_asm)
6332 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6334 fputc ('\n', asm_out_file);
6335 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
6336 if (flag_debug_asm)
6337 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
6338 ASM_COMMENT_START);
6340 fputc ('\n', asm_out_file);
6341 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF2_ADDR_SIZE);
6342 if (flag_debug_asm)
6343 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
6345 fputc ('\n', asm_out_file);
6346 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6347 if (flag_debug_asm)
6348 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
6349 ASM_COMMENT_START);
6351 fputc ('\n', asm_out_file);
6353 /* We need to align to twice the pointer size here. */
6354 if (DWARF_ARANGES_PAD_SIZE)
6356 /* Pad using a 2 bytes word so that padding is correct
6357 for any pointer size. */
6358 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
6359 for (i = 2; i < DWARF_ARANGES_PAD_SIZE; i += 2)
6360 fprintf (asm_out_file, ",0");
6361 if (flag_debug_asm)
6362 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
6363 ASM_COMMENT_START, 2 * DWARF2_ADDR_SIZE);
6366 fputc ('\n', asm_out_file);
6367 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
6368 if (flag_debug_asm)
6369 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6371 fputc ('\n', asm_out_file);
6372 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
6373 text_section_label);
6374 if (flag_debug_asm)
6375 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6377 fputc ('\n', asm_out_file);
6378 for (i = 0; i < arange_table_in_use; ++i)
6380 dw_die_ref die = arange_table[i];
6382 /* We shouldn't see aranges for DIEs outside of the main CU. */
6383 if (die->die_mark == 0)
6384 abort ();
6386 if (die->die_tag == DW_TAG_subprogram)
6387 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
6388 else
6390 /* A static variable; extract the symbol from DW_AT_location.
6391 Note that this code isn't currently hit, as we only emit
6392 aranges for functions (jason 9/23/99). */
6394 dw_attr_ref a = get_AT (die, DW_AT_location);
6395 dw_loc_descr_ref loc;
6396 if (! a || AT_class (a) != dw_val_class_loc)
6397 abort ();
6399 loc = AT_loc (a);
6400 if (loc->dw_loc_opc != DW_OP_addr)
6401 abort ();
6403 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
6404 loc->dw_loc_oprnd1.v.val_addr);
6407 if (flag_debug_asm)
6408 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
6410 fputc ('\n', asm_out_file);
6411 if (die->die_tag == DW_TAG_subprogram)
6412 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
6413 get_AT_low_pc (die));
6414 else
6415 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
6416 get_AT_unsigned (die, DW_AT_byte_size));
6418 if (flag_debug_asm)
6419 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
6421 fputc ('\n', asm_out_file);
6424 /* Output the terminator words. */
6425 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6426 fputc ('\n', asm_out_file);
6427 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
6428 fputc ('\n', asm_out_file);
6432 /* Data structure containing information about input files. */
6433 struct file_info
6435 char *path; /* Complete file name. */
6436 char *fname; /* File name part. */
6437 int length; /* Length of entire string. */
6438 int file_idx; /* Index in input file table. */
6439 int dir_idx; /* Index in directory table. */
6442 /* Data structure containing information about directories with source
6443 files. */
6444 struct dir_info
6446 char *path; /* Path including directory name. */
6447 int length; /* Path length. */
6448 int prefix; /* Index of directory entry which is a prefix. */
6449 int nbytes; /* Total number of bytes in all file names excluding
6450 paths. */
6451 int count; /* Number of files in this directory. */
6452 int dir_idx; /* Index of directory used as base. */
6453 int used; /* Used in the end? */
6456 /* Callback function for file_info comparison. We sort by looking at
6457 the directories in the path. */
6458 static int
6459 file_info_cmp (p1, p2)
6460 const void *p1;
6461 const void *p2;
6463 const struct file_info *s1 = p1;
6464 const struct file_info *s2 = p2;
6465 unsigned char *cp1;
6466 unsigned char *cp2;
6468 /* Take care of file names without directories. */
6469 if (s1->path == s1->fname)
6470 return -1;
6471 else if (s2->path == s2->fname)
6472 return 1;
6474 cp1 = (unsigned char *) s1->path;
6475 cp2 = (unsigned char *) s2->path;
6477 while (1)
6479 ++cp1;
6480 ++cp2;
6481 /* Reached the end of the first path? */
6482 if (cp1 == (unsigned char *) s1->fname)
6483 /* It doesn't really matter in which order files from the
6484 same directory are sorted in. Therefore don't test for
6485 the second path reaching the end. */
6486 return -1;
6487 else if (cp2 == (unsigned char *) s2->fname)
6488 return 1;
6490 /* Character of current path component the same? */
6491 if (*cp1 != *cp2)
6492 return *cp1 - *cp2;
6496 /* Compute the maximum prefix of P2 appearing also in P1. Entire
6497 directory names must match. */
6498 static int prefix_of PARAMS ((struct dir_info *, struct dir_info *));
6499 static int
6500 prefix_of (p1, p2)
6501 struct dir_info *p1;
6502 struct dir_info *p2;
6504 char *s1 = p1->path;
6505 char *s2 = p2->path;
6506 int len = p1->length < p2->length ? p1->length : p2->length;
6508 while (*s1 == *s2 && s1 < p1->path + len)
6509 ++s1, ++s2;
6511 if (*s1 == '/' && *s2 == '/')
6512 /* The whole of P1 is the prefix. */
6513 return p1->length;
6515 /* Go back to the last directory component. */
6516 while (s1 > p1->path)
6517 if (*--s1 == '/')
6518 return s1 - p1->path + 1;
6520 return 0;
6523 /* Output the directory table and the file name table. We try to minimize
6524 the total amount of memory needed. A heuristic is used to avoid large
6525 slowdowns with many input files. */
6526 static void
6527 output_file_names ()
6529 struct file_info *files;
6530 struct dir_info *dirs;
6531 int *saved;
6532 int *savehere;
6533 int *backmap;
6534 int ndirs;
6535 int idx_offset;
6536 int i;
6537 int idx;
6539 /* Allocate the various arrays we need. */
6540 files = (struct file_info *) alloca (line_file_table.in_use
6541 * sizeof (struct file_info));
6542 dirs = (struct dir_info *) alloca (line_file_table.in_use * 2
6543 * sizeof (struct dir_info));
6545 /* Sort the file names. */
6546 for (i = 1; i < (int) line_file_table.in_use; ++i)
6548 char *f;
6550 /* Skip all leading "./". */
6551 f = line_file_table.table[i];
6552 while (f[0] == '.' && f[1] == '/')
6553 f += 2;
6555 /* Create a new array entry. */
6556 files[i].path = f;
6557 files[i].length = strlen (f);
6558 files[i].file_idx = i;
6560 /* Search for the file name part. */
6561 f = strrchr (f, '/');
6562 files[i].fname = f == NULL ? files[i].path : f + 1;
6564 qsort (files + 1, line_file_table.in_use - 1, sizeof (files[0]),
6565 file_info_cmp);
6567 /* Find all the different directories used. */
6568 dirs[0].path = files[1].path;
6569 dirs[0].length = files[1].fname - files[1].path;
6570 dirs[0].prefix = -1;
6571 dirs[0].nbytes = files[1].length - dirs[1].length + 1;
6572 dirs[0].count = 1;
6573 dirs[0].dir_idx = 0;
6574 dirs[0].used = 0;
6575 files[1].dir_idx = 0;
6576 ndirs = 1;
6578 for (i = 2; i < (int) line_file_table.in_use; ++i)
6579 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6580 && memcmp (dirs[ndirs - 1].path, files[i].path,
6581 dirs[ndirs - 1].length) == 0)
6583 /* Same directory as last entry. */
6584 files[i].dir_idx = ndirs - 1;
6585 dirs[ndirs - 1].nbytes += files[i].length - dirs[ndirs - 1].length + 1;
6586 ++dirs[ndirs - 1].count;
6588 else
6590 int j;
6591 int max_idx;
6592 int max_len;
6594 /* This is a new directory. */
6595 dirs[ndirs].path = files[i].path;
6596 dirs[ndirs].length = files[i].fname - files[i].path;
6597 dirs[ndirs].nbytes = files[i].length - dirs[i].length + 1;
6598 dirs[ndirs].count = 1;
6599 dirs[ndirs].dir_idx = ndirs;
6600 dirs[ndirs].used = 0;
6601 files[i].dir_idx = ndirs;
6603 /* Search for a prefix. */
6604 max_len = 0;
6605 max_idx = 0;
6606 for (j = 0; j < ndirs; ++j)
6607 if (dirs[j].length > max_len)
6609 int this_len = prefix_of (&dirs[j], &dirs[ndirs]);
6611 if (this_len > max_len)
6613 max_len = this_len;
6614 max_idx = j;
6618 /* Remember the prefix. If this is a known prefix simply
6619 remember the index. Otherwise we will have to create an
6620 artificial entry. */
6621 if (max_len == dirs[max_idx].length)
6622 /* This is our prefix. */
6623 dirs[ndirs].prefix = max_idx;
6624 else if (max_len > 0)
6626 /* Create an entry without associated file. Since we have
6627 to keep the dirs array sorted (means, entries with paths
6628 which come first) we have to move the new entry in the
6629 place of the old one. */
6630 dirs[++ndirs] = dirs[max_idx];
6632 /* We don't have to set .path. */
6633 dirs[max_idx].length = max_len;
6634 dirs[max_idx].nbytes = 0;
6635 dirs[max_idx].count = 0;
6636 dirs[max_idx].dir_idx = ndirs;
6637 dirs[max_idx].used = 0;
6638 dirs[max_idx].prefix = dirs[ndirs].prefix;
6640 dirs[ndirs - 1].prefix = dirs[ndirs].prefix = max_idx;
6642 else
6643 dirs[ndirs].prefix = -1;
6645 ++ndirs;
6648 /* Now to the actual work. We have to find a subset of the
6649 directories which allow expressing the file name using references
6650 to the directory table with the least amount of characters. We
6651 do not do an exhaustive search where we would have to check out
6652 every combination of every single possible prefix. Instead we
6653 use a heuristic which provides nearly optimal results in most
6654 cases and never is much off. */
6655 saved = (int *) alloca (ndirs * sizeof (int));
6656 savehere = (int *) alloca (ndirs * sizeof (int));
6658 memset (saved, '\0', ndirs * sizeof (saved[0]));
6659 for (i = 0; i < ndirs; ++i)
6661 int j;
6662 int total;
6664 /* We can always safe some space for the current directory. But
6665 this does not mean it will be enough to justify adding the
6666 directory. */
6667 savehere[i] = dirs[i].length;
6668 total = (savehere[i] - saved[i]) * dirs[i].count;
6670 for (j = i + 1; j < ndirs; ++j)
6672 savehere[j] = 0;
6674 if (saved[j] < dirs[i].length)
6676 /* Determine whether the dirs[i] path is a prefix of the
6677 dirs[j] path. */
6678 int k;
6680 k = dirs[j].prefix;
6681 while (k != -1 && k != i)
6682 k = dirs[k].prefix;
6684 if (k == i)
6686 /* Yes it is. We can possibly safe some memory but
6687 writing the filenames in dirs[j] relative to
6688 dirs[i]. */
6689 savehere[j] = dirs[i].length;
6690 total += (savehere[j] - saved[j]) * dirs[j].count;
6695 /* Check whether we can safe enough to justify adding the dirs[i]
6696 directory. */
6697 if (total > dirs[i].length + 1)
6699 /* It's worthwhile adding. */
6700 for (j = i; j < ndirs; ++j)
6701 if (savehere[j] > 0)
6703 /* Remember how much we saved for this directory so far. */
6704 saved[j] = savehere[j];
6706 /* Remember the prefix directory. */
6707 dirs[j].dir_idx = i;
6712 /* We have to emit them in the order they appear in the line_file_table
6713 array since the index is used in the debug info generation. To
6714 do this efficiently we generate a back-mapping of the indices
6715 first. */
6716 backmap = (int *) alloca (line_file_table.in_use * sizeof (int));
6717 for (i = 1; i < (int) line_file_table.in_use; ++i)
6719 backmap[files[i].file_idx] = i;
6720 /* Mark this directory as used. */
6721 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6724 /* That was it. We are ready to emit the information. First the
6725 directory name table. Here we have to make sure that the first
6726 actually emitted directory name has the index one. Zero is
6727 reserved for the current working directory. Make sure we do not
6728 confuse these indices with the one for the constructed table
6729 (even though most of the time they are identical). */
6730 idx = 1;
6731 idx_offset = dirs[0].length > 0 ? 1 : 0;
6732 for (i = 1 - idx_offset; i < ndirs; ++i)
6733 if (dirs[i].used != 0)
6735 dirs[i].used = idx++;
6737 if (flag_debug_asm)
6739 ASM_OUTPUT_DWARF_NSTRING (asm_out_file,
6740 dirs[i].path, dirs[i].length - 1);
6741 fprintf (asm_out_file, "%s Directory Entry: 0x%x\n",
6742 ASM_COMMENT_START, dirs[i].used);
6744 else
6746 ASM_OUTPUT_ASCII (asm_out_file, dirs[i].path, dirs[i].length - 1);
6747 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6748 fputc ('\n', asm_out_file);
6751 /* Correct the index for the current working directory entry if it
6752 exists. */
6753 if (idx_offset == 0)
6754 dirs[0].used = 0;
6755 /* Terminate the directory name array. */
6756 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6757 if (flag_debug_asm)
6758 fprintf (asm_out_file, "\t%s End directory table", ASM_COMMENT_START);
6759 fputc ('\n', asm_out_file);
6761 /* Now write all the file names. */
6762 for (i = 1; i < (int) line_file_table.in_use; ++i)
6764 int file_idx = backmap[i];
6765 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6767 if (flag_debug_asm)
6769 ASM_OUTPUT_DWARF_STRING (asm_out_file,
6770 files[file_idx].path
6771 + dirs[dir_idx].length);
6772 fprintf (asm_out_file, "%s File Entry: 0x%x\n",
6773 ASM_COMMENT_START, i);
6775 else
6776 ASM_OUTPUT_ASCII (asm_out_file,
6777 files[file_idx].path + dirs[dir_idx].length,
6778 (files[file_idx].length
6779 - dirs[dir_idx].length) + 1);
6781 /* Include directory index. */
6782 output_uleb128 (dirs[dir_idx].used);
6783 fputc ('\n', asm_out_file);
6785 /* Modification time. */
6786 output_uleb128 (0);
6787 fputc ('\n', asm_out_file);
6789 /* File length in bytes. */
6790 output_uleb128 (0);
6791 fputc ('\n', asm_out_file);
6794 /* Terminate the file name table */
6795 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6796 if (flag_debug_asm)
6797 fprintf (asm_out_file, "\t%s End file name table", ASM_COMMENT_START);
6798 fputc ('\n', asm_out_file);
6802 /* Output the source line number correspondence information. This
6803 information goes into the .debug_line section. */
6805 static void
6806 output_line_info ()
6808 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6809 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6810 register unsigned opc;
6811 register unsigned n_op_args;
6812 register unsigned long lt_index;
6813 register unsigned long current_line;
6814 register long line_offset;
6815 register long line_delta;
6816 register unsigned long current_file;
6817 register unsigned long function;
6819 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
6820 if (flag_debug_asm)
6821 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
6822 ASM_COMMENT_START);
6824 fputc ('\n', asm_out_file);
6825 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
6826 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
6827 if (flag_debug_asm)
6828 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
6830 fputc ('\n', asm_out_file);
6831 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
6832 if (flag_debug_asm)
6833 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
6835 fputc ('\n', asm_out_file);
6836 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
6837 if (flag_debug_asm)
6838 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
6839 ASM_COMMENT_START);
6841 fputc ('\n', asm_out_file);
6842 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
6843 if (flag_debug_asm)
6844 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
6845 ASM_COMMENT_START);
6847 fputc ('\n', asm_out_file);
6848 fprintf (asm_out_file, "%s%d", ASM_BYTE_OP, DWARF_LINE_BASE);
6849 if (flag_debug_asm)
6850 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
6851 ASM_COMMENT_START);
6853 fputc ('\n', asm_out_file);
6854 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
6855 if (flag_debug_asm)
6856 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
6857 ASM_COMMENT_START);
6859 fputc ('\n', asm_out_file);
6860 fprintf (asm_out_file, "%s%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
6861 if (flag_debug_asm)
6862 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
6864 fputc ('\n', asm_out_file);
6865 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6867 switch (opc)
6869 case DW_LNS_advance_pc:
6870 case DW_LNS_advance_line:
6871 case DW_LNS_set_file:
6872 case DW_LNS_set_column:
6873 case DW_LNS_fixed_advance_pc:
6874 n_op_args = 1;
6875 break;
6876 default:
6877 n_op_args = 0;
6878 break;
6880 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
6881 if (flag_debug_asm)
6882 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
6883 ASM_COMMENT_START, opc, n_op_args);
6884 fputc ('\n', asm_out_file);
6887 /* Write out the information about the files we use. */
6888 output_file_names ();
6890 /* We used to set the address register to the first location in the text
6891 section here, but that didn't accomplish anything since we already
6892 have a line note for the opening brace of the first function. */
6894 /* Generate the line number to PC correspondence table, encoded as
6895 a series of state machine operations. */
6896 current_file = 1;
6897 current_line = 1;
6898 strcpy (prev_line_label, text_section_label);
6899 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6901 register dw_line_info_ref line_info = &line_info_table[lt_index];
6903 #if 0
6904 /* Disable this optimization for now; GDB wants to see two line notes
6905 at the beginning of a function so it can find the end of the
6906 prologue. */
6908 /* Don't emit anything for redundant notes. Just updating the
6909 address doesn't accomplish anything, because we already assume
6910 that anything after the last address is this line. */
6911 if (line_info->dw_line_num == current_line
6912 && line_info->dw_file_num == current_file)
6913 continue;
6914 #endif
6916 /* Emit debug info for the address of the current line, choosing
6917 the encoding that uses the least amount of space. */
6918 /* ??? Unfortunately, we have little choice here currently, and must
6919 always use the most general form. Gcc does not know the address
6920 delta itself, so we can't use DW_LNS_advance_pc. There are no known
6921 dwarf2 aware assemblers at this time, so we can't use any special
6922 pseudo ops that would allow the assembler to optimally encode this for
6923 us. Many ports do have length attributes which will give an upper
6924 bound on the address range. We could perhaps use length attributes
6925 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
6926 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6927 if (0)
6929 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6930 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
6931 if (flag_debug_asm)
6932 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
6933 ASM_COMMENT_START);
6935 fputc ('\n', asm_out_file);
6936 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
6937 fputc ('\n', asm_out_file);
6939 else
6941 /* This can handle any delta. This takes
6942 4+DWARF2_ADDR_SIZE bytes. */
6943 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
6944 if (flag_debug_asm)
6945 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
6946 ASM_COMMENT_START);
6947 fputc ('\n', asm_out_file);
6948 output_uleb128 (1 + DWARF2_ADDR_SIZE);
6949 fputc ('\n', asm_out_file);
6950 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
6951 fputc ('\n', asm_out_file);
6952 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
6953 fputc ('\n', asm_out_file);
6955 strcpy (prev_line_label, line_label);
6957 /* Emit debug info for the source file of the current line, if
6958 different from the previous line. */
6959 if (line_info->dw_file_num != current_file)
6961 current_file = line_info->dw_file_num;
6962 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
6963 if (flag_debug_asm)
6964 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
6966 fputc ('\n', asm_out_file);
6967 output_uleb128 (current_file);
6968 if (flag_debug_asm)
6969 fprintf (asm_out_file, " (\"%s\")",
6970 line_file_table.table[current_file]);
6972 fputc ('\n', asm_out_file);
6975 /* Emit debug info for the current line number, choosing the encoding
6976 that uses the least amount of space. */
6977 if (line_info->dw_line_num != current_line)
6979 line_offset = line_info->dw_line_num - current_line;
6980 line_delta = line_offset - DWARF_LINE_BASE;
6981 current_line = line_info->dw_line_num;
6982 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6984 /* This can handle deltas from -10 to 234, using the current
6985 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6986 takes 1 byte. */
6987 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
6988 DWARF_LINE_OPCODE_BASE + line_delta);
6989 if (flag_debug_asm)
6990 fprintf (asm_out_file,
6991 "\t%s line %ld", ASM_COMMENT_START, current_line);
6993 fputc ('\n', asm_out_file);
6995 else
6997 /* This can handle any delta. This takes at least 4 bytes,
6998 depending on the value being encoded. */
6999 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
7000 if (flag_debug_asm)
7001 fprintf (asm_out_file, "\t%s advance to line %ld",
7002 ASM_COMMENT_START, current_line);
7004 fputc ('\n', asm_out_file);
7005 output_sleb128 (line_offset);
7006 fputc ('\n', asm_out_file);
7007 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7008 if (flag_debug_asm)
7009 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7010 fputc ('\n', asm_out_file);
7013 else
7015 /* We still need to start a new row, so output a copy insn. */
7016 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7017 if (flag_debug_asm)
7018 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7019 fputc ('\n', asm_out_file);
7023 /* Emit debug info for the address of the end of the function. */
7024 if (0)
7026 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7027 if (flag_debug_asm)
7028 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7029 ASM_COMMENT_START);
7031 fputc ('\n', asm_out_file);
7032 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
7033 fputc ('\n', asm_out_file);
7035 else
7037 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7038 if (flag_debug_asm)
7039 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
7040 fputc ('\n', asm_out_file);
7041 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7042 fputc ('\n', asm_out_file);
7043 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7044 fputc ('\n', asm_out_file);
7045 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
7046 fputc ('\n', asm_out_file);
7049 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7050 if (flag_debug_asm)
7051 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
7053 fputc ('\n', asm_out_file);
7054 output_uleb128 (1);
7055 fputc ('\n', asm_out_file);
7056 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
7057 fputc ('\n', asm_out_file);
7059 function = 0;
7060 current_file = 1;
7061 current_line = 1;
7062 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7064 register dw_separate_line_info_ref line_info
7065 = &separate_line_info_table[lt_index];
7067 #if 0
7068 /* Don't emit anything for redundant notes. */
7069 if (line_info->dw_line_num == current_line
7070 && line_info->dw_file_num == current_file
7071 && line_info->function == function)
7072 goto cont;
7073 #endif
7075 /* Emit debug info for the address of the current line. If this is
7076 a new function, or the first line of a function, then we need
7077 to handle it differently. */
7078 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7079 lt_index);
7080 if (function != line_info->function)
7082 function = line_info->function;
7084 /* Set the address register to the first line in the function */
7085 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7086 if (flag_debug_asm)
7087 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7088 ASM_COMMENT_START);
7090 fputc ('\n', asm_out_file);
7091 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7092 fputc ('\n', asm_out_file);
7093 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7094 fputc ('\n', asm_out_file);
7095 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7096 fputc ('\n', asm_out_file);
7098 else
7100 /* ??? See the DW_LNS_advance_pc comment above. */
7101 if (0)
7103 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7104 if (flag_debug_asm)
7105 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7106 ASM_COMMENT_START);
7108 fputc ('\n', asm_out_file);
7109 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
7110 prev_line_label);
7111 fputc ('\n', asm_out_file);
7113 else
7115 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7116 if (flag_debug_asm)
7117 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7118 ASM_COMMENT_START);
7119 fputc ('\n', asm_out_file);
7120 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7121 fputc ('\n', asm_out_file);
7122 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7123 fputc ('\n', asm_out_file);
7124 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7125 fputc ('\n', asm_out_file);
7128 strcpy (prev_line_label, line_label);
7130 /* Emit debug info for the source file of the current line, if
7131 different from the previous line. */
7132 if (line_info->dw_file_num != current_file)
7134 current_file = line_info->dw_file_num;
7135 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
7136 if (flag_debug_asm)
7137 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
7139 fputc ('\n', asm_out_file);
7140 output_uleb128 (current_file);
7141 if (flag_debug_asm)
7142 fprintf (asm_out_file, " (\"%s\")",
7143 line_file_table.table[current_file]);
7145 fputc ('\n', asm_out_file);
7148 /* Emit debug info for the current line number, choosing the encoding
7149 that uses the least amount of space. */
7150 if (line_info->dw_line_num != current_line)
7152 line_offset = line_info->dw_line_num - current_line;
7153 line_delta = line_offset - DWARF_LINE_BASE;
7154 current_line = line_info->dw_line_num;
7155 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7157 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
7158 DWARF_LINE_OPCODE_BASE + line_delta);
7159 if (flag_debug_asm)
7160 fprintf (asm_out_file,
7161 "\t%s line %ld", ASM_COMMENT_START, current_line);
7163 fputc ('\n', asm_out_file);
7165 else
7167 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
7168 if (flag_debug_asm)
7169 fprintf (asm_out_file, "\t%s advance to line %ld",
7170 ASM_COMMENT_START, current_line);
7172 fputc ('\n', asm_out_file);
7173 output_sleb128 (line_offset);
7174 fputc ('\n', asm_out_file);
7175 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7176 if (flag_debug_asm)
7177 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7178 fputc ('\n', asm_out_file);
7181 else
7183 /* We still need to start a new row, so output a copy insn. */
7184 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
7185 if (flag_debug_asm)
7186 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
7187 fputc ('\n', asm_out_file);
7190 #if 0
7191 cont:
7192 #endif
7193 ++lt_index;
7195 /* If we're done with a function, end its sequence. */
7196 if (lt_index == separate_line_info_table_in_use
7197 || separate_line_info_table[lt_index].function != function)
7199 current_file = 1;
7200 current_line = 1;
7202 /* Emit debug info for the address of the end of the function. */
7203 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7204 if (0)
7206 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
7207 if (flag_debug_asm)
7208 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
7209 ASM_COMMENT_START);
7211 fputc ('\n', asm_out_file);
7212 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
7213 prev_line_label);
7214 fputc ('\n', asm_out_file);
7216 else
7218 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7219 if (flag_debug_asm)
7220 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
7221 ASM_COMMENT_START);
7222 fputc ('\n', asm_out_file);
7223 output_uleb128 (1 + DWARF2_ADDR_SIZE);
7224 fputc ('\n', asm_out_file);
7225 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
7226 fputc ('\n', asm_out_file);
7227 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
7228 fputc ('\n', asm_out_file);
7231 /* Output the marker for the end of this sequence. */
7232 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
7233 if (flag_debug_asm)
7234 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
7235 ASM_COMMENT_START);
7237 fputc ('\n', asm_out_file);
7238 output_uleb128 (1);
7239 fputc ('\n', asm_out_file);
7240 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
7241 fputc ('\n', asm_out_file);
7245 /* Output the marker for the end of the line number info. */
7246 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
7249 /* Given a pointer to a tree node for some base type, return a pointer to
7250 a DIE that describes the given type.
7252 This routine must only be called for GCC type nodes that correspond to
7253 Dwarf base (fundamental) types. */
7255 static dw_die_ref
7256 base_type_die (type)
7257 register tree type;
7259 register dw_die_ref base_type_result;
7260 register const char *type_name;
7261 register enum dwarf_type encoding;
7262 register tree name = TYPE_NAME (type);
7264 if (TREE_CODE (type) == ERROR_MARK
7265 || TREE_CODE (type) == VOID_TYPE)
7266 return 0;
7268 if (name)
7270 if (TREE_CODE (name) == TYPE_DECL)
7271 name = DECL_NAME (name);
7273 type_name = IDENTIFIER_POINTER (name);
7275 else
7276 type_name = "__unknown__";
7278 switch (TREE_CODE (type))
7280 case INTEGER_TYPE:
7281 /* Carefully distinguish the C character types, without messing
7282 up if the language is not C. Note that we check only for the names
7283 that contain spaces; other names might occur by coincidence in other
7284 languages. */
7285 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7286 && (type == char_type_node
7287 || ! strcmp (type_name, "signed char")
7288 || ! strcmp (type_name, "unsigned char"))))
7290 if (TREE_UNSIGNED (type))
7291 encoding = DW_ATE_unsigned;
7292 else
7293 encoding = DW_ATE_signed;
7294 break;
7296 /* else fall through. */
7298 case CHAR_TYPE:
7299 /* GNU Pascal/Ada CHAR type. Not used in C. */
7300 if (TREE_UNSIGNED (type))
7301 encoding = DW_ATE_unsigned_char;
7302 else
7303 encoding = DW_ATE_signed_char;
7304 break;
7306 case REAL_TYPE:
7307 encoding = DW_ATE_float;
7308 break;
7310 /* Dwarf2 doesn't know anything about complex ints, so use
7311 a user defined type for it. */
7312 case COMPLEX_TYPE:
7313 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7314 encoding = DW_ATE_complex_float;
7315 else
7316 encoding = DW_ATE_lo_user;
7317 break;
7319 case BOOLEAN_TYPE:
7320 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7321 encoding = DW_ATE_boolean;
7322 break;
7324 default:
7325 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
7328 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
7329 if (demangle_name_func)
7330 type_name = (*demangle_name_func) (type_name);
7332 add_AT_string (base_type_result, DW_AT_name, type_name);
7333 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7334 int_size_in_bytes (type));
7335 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7337 return base_type_result;
7340 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7341 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7342 a given type is generally the same as the given type, except that if the
7343 given type is a pointer or reference type, then the root type of the given
7344 type is the root type of the "basis" type for the pointer or reference
7345 type. (This definition of the "root" type is recursive.) Also, the root
7346 type of a `const' qualified type or a `volatile' qualified type is the
7347 root type of the given type without the qualifiers. */
7349 static tree
7350 root_type (type)
7351 register tree type;
7353 if (TREE_CODE (type) == ERROR_MARK)
7354 return error_mark_node;
7356 switch (TREE_CODE (type))
7358 case ERROR_MARK:
7359 return error_mark_node;
7361 case POINTER_TYPE:
7362 case REFERENCE_TYPE:
7363 return type_main_variant (root_type (TREE_TYPE (type)));
7365 default:
7366 return type_main_variant (type);
7370 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7371 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7373 static inline int
7374 is_base_type (type)
7375 register tree type;
7377 switch (TREE_CODE (type))
7379 case ERROR_MARK:
7380 case VOID_TYPE:
7381 case INTEGER_TYPE:
7382 case REAL_TYPE:
7383 case COMPLEX_TYPE:
7384 case BOOLEAN_TYPE:
7385 case CHAR_TYPE:
7386 return 1;
7388 case SET_TYPE:
7389 case ARRAY_TYPE:
7390 case RECORD_TYPE:
7391 case UNION_TYPE:
7392 case QUAL_UNION_TYPE:
7393 case ENUMERAL_TYPE:
7394 case FUNCTION_TYPE:
7395 case METHOD_TYPE:
7396 case POINTER_TYPE:
7397 case REFERENCE_TYPE:
7398 case FILE_TYPE:
7399 case OFFSET_TYPE:
7400 case LANG_TYPE:
7401 case VECTOR_TYPE:
7402 return 0;
7404 default:
7405 abort ();
7408 return 0;
7411 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7412 entry that chains various modifiers in front of the given type. */
7414 static dw_die_ref
7415 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7416 register tree type;
7417 register int is_const_type;
7418 register int is_volatile_type;
7419 register dw_die_ref context_die;
7421 register enum tree_code code = TREE_CODE (type);
7422 register dw_die_ref mod_type_die = NULL;
7423 register dw_die_ref sub_die = NULL;
7424 register tree item_type = NULL;
7426 if (code != ERROR_MARK)
7428 type = build_type_variant (type, is_const_type, is_volatile_type);
7430 mod_type_die = lookup_type_die (type);
7431 if (mod_type_die)
7432 return mod_type_die;
7434 /* Handle C typedef types. */
7435 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7436 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
7438 tree dtype = TREE_TYPE (TYPE_NAME (type));
7439 if (type == dtype)
7441 /* For a named type, use the typedef. */
7442 gen_type_die (type, context_die);
7443 mod_type_die = lookup_type_die (type);
7446 else if (is_const_type < TYPE_READONLY (dtype)
7447 || is_volatile_type < TYPE_VOLATILE (dtype))
7448 /* cv-unqualified version of named type. Just use the unnamed
7449 type to which it refers. */
7450 mod_type_die
7451 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
7452 is_const_type, is_volatile_type,
7453 context_die);
7454 /* Else cv-qualified version of named type; fall through. */
7457 if (mod_type_die)
7458 /* OK. */
7460 else if (is_const_type)
7462 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7463 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7465 else if (is_volatile_type)
7467 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7468 sub_die = modified_type_die (type, 0, 0, context_die);
7470 else if (code == POINTER_TYPE)
7472 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7473 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7474 #if 0
7475 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7476 #endif
7477 item_type = TREE_TYPE (type);
7479 else if (code == REFERENCE_TYPE)
7481 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7482 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7483 #if 0
7484 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7485 #endif
7486 item_type = TREE_TYPE (type);
7488 else if (is_base_type (type))
7489 mod_type_die = base_type_die (type);
7490 else
7492 gen_type_die (type, context_die);
7494 /* We have to get the type_main_variant here (and pass that to the
7495 `lookup_type_die' routine) because the ..._TYPE node we have
7496 might simply be a *copy* of some original type node (where the
7497 copy was created to help us keep track of typedef names) and
7498 that copy might have a different TYPE_UID from the original
7499 ..._TYPE node. */
7500 mod_type_die = lookup_type_die (type_main_variant (type));
7501 if (mod_type_die == NULL)
7502 abort ();
7506 equate_type_number_to_die (type, mod_type_die);
7507 if (item_type)
7508 /* We must do this after the equate_type_number_to_die call, in case
7509 this is a recursive type. This ensures that the modified_type_die
7510 recursion will terminate even if the type is recursive. Recursive
7511 types are possible in Ada. */
7512 sub_die = modified_type_die (item_type,
7513 TYPE_READONLY (item_type),
7514 TYPE_VOLATILE (item_type),
7515 context_die);
7517 if (sub_die != NULL)
7518 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7520 return mod_type_die;
7523 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7524 an enumerated type. */
7526 static inline int
7527 type_is_enum (type)
7528 register tree type;
7530 return TREE_CODE (type) == ENUMERAL_TYPE;
7533 /* Return the register number described by a given RTL node. */
7535 static unsigned int
7536 reg_number (rtl)
7537 register rtx rtl;
7539 register unsigned regno = REGNO (rtl);
7541 if (regno >= FIRST_PSEUDO_REGISTER)
7543 warning ("internal regno botch: regno = %d\n", regno);
7544 regno = 0;
7547 regno = DBX_REGISTER_NUMBER (regno);
7548 return regno;
7551 /* Return a location descriptor that designates a machine register. */
7553 static dw_loc_descr_ref
7554 reg_loc_descriptor (rtl)
7555 register rtx rtl;
7557 register dw_loc_descr_ref loc_result = NULL;
7558 register unsigned reg = reg_number (rtl);
7560 if (reg <= 31)
7561 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7562 else
7563 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7565 return loc_result;
7568 /* Return a location descriptor that designates a constant. */
7570 static dw_loc_descr_ref
7571 int_loc_descriptor (i)
7572 HOST_WIDE_INT i;
7574 enum dwarf_location_atom op;
7576 /* Pick the smallest representation of a constant, rather than just
7577 defaulting to the LEB encoding. */
7578 if (i >= 0)
7580 if (i <= 31)
7581 op = DW_OP_lit0 + i;
7582 else if (i <= 0xff)
7583 op = DW_OP_const1u;
7584 else if (i <= 0xffff)
7585 op = DW_OP_const2u;
7586 else if (HOST_BITS_PER_WIDE_INT == 32
7587 || i <= 0xffffffff)
7588 op = DW_OP_const4u;
7589 else
7590 op = DW_OP_constu;
7592 else
7594 if (i >= -0x80)
7595 op = DW_OP_const1s;
7596 else if (i >= -0x8000)
7597 op = DW_OP_const2s;
7598 else if (HOST_BITS_PER_WIDE_INT == 32
7599 || i >= -0x80000000)
7600 op = DW_OP_const4s;
7601 else
7602 op = DW_OP_consts;
7605 return new_loc_descr (op, i, 0);
7608 /* Return a location descriptor that designates a base+offset location. */
7610 static dw_loc_descr_ref
7611 based_loc_descr (reg, offset)
7612 unsigned reg;
7613 long int offset;
7615 register dw_loc_descr_ref loc_result;
7616 /* For the "frame base", we use the frame pointer or stack pointer
7617 registers, since the RTL for local variables is relative to one of
7618 them. */
7619 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7620 ? HARD_FRAME_POINTER_REGNUM
7621 : STACK_POINTER_REGNUM);
7623 if (reg == fp_reg)
7624 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7625 else if (reg <= 31)
7626 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7627 else
7628 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7630 return loc_result;
7633 /* Return true if this RTL expression describes a base+offset calculation. */
7635 static inline int
7636 is_based_loc (rtl)
7637 register rtx rtl;
7639 return (GET_CODE (rtl) == PLUS
7640 && ((GET_CODE (XEXP (rtl, 0)) == REG
7641 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7644 /* The following routine converts the RTL for a variable or parameter
7645 (resident in memory) into an equivalent Dwarf representation of a
7646 mechanism for getting the address of that same variable onto the top of a
7647 hypothetical "address evaluation" stack.
7649 When creating memory location descriptors, we are effectively transforming
7650 the RTL for a memory-resident object into its Dwarf postfix expression
7651 equivalent. This routine recursively descends an RTL tree, turning
7652 it into Dwarf postfix code as it goes.
7654 MODE is the mode of the memory reference, needed to handle some
7655 autoincrement addressing modes. */
7657 static dw_loc_descr_ref
7658 mem_loc_descriptor (rtl, mode)
7659 register rtx rtl;
7660 enum machine_mode mode;
7662 dw_loc_descr_ref mem_loc_result = NULL;
7663 /* Note that for a dynamically sized array, the location we will generate a
7664 description of here will be the lowest numbered location which is
7665 actually within the array. That's *not* necessarily the same as the
7666 zeroth element of the array. */
7668 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7669 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7670 #endif
7672 switch (GET_CODE (rtl))
7674 case POST_INC:
7675 case POST_DEC:
7676 case POST_MODIFY:
7677 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7678 just fall into the SUBREG code. */
7680 /* Fall through. */
7682 case SUBREG:
7683 /* The case of a subreg may arise when we have a local (register)
7684 variable or a formal (register) parameter which doesn't quite fill
7685 up an entire register. For now, just assume that it is
7686 legitimate to make the Dwarf info refer to the whole register which
7687 contains the given subreg. */
7688 rtl = XEXP (rtl, 0);
7690 /* Fall through. */
7692 case REG:
7693 /* Whenever a register number forms a part of the description of the
7694 method for calculating the (dynamic) address of a memory resident
7695 object, DWARF rules require the register number be referred to as
7696 a "base register". This distinction is not based in any way upon
7697 what category of register the hardware believes the given register
7698 belongs to. This is strictly DWARF terminology we're dealing with
7699 here. Note that in cases where the location of a memory-resident
7700 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7701 OP_CONST (0)) the actual DWARF location descriptor that we generate
7702 may just be OP_BASEREG (basereg). This may look deceptively like
7703 the object in question was allocated to a register (rather than in
7704 memory) so DWARF consumers need to be aware of the subtle
7705 distinction between OP_REG and OP_BASEREG. */
7706 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7707 break;
7709 case MEM:
7710 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7711 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7712 break;
7714 case LABEL_REF:
7715 /* Some ports can transform a symbol ref into a label ref, because
7716 the symbol ref is too far away and has to be dumped into a constant
7717 pool. */
7718 case CONST:
7719 case SYMBOL_REF:
7720 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7721 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7722 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7723 break;
7725 case PRE_MODIFY:
7726 /* Extract the PLUS expression nested inside and fall into
7727 PLUS code bellow. */
7728 rtl = XEXP (rtl, 1);
7729 goto plus;
7731 case PRE_INC:
7732 case PRE_DEC:
7733 /* Turn these into a PLUS expression and fall into the PLUS code
7734 below. */
7735 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7736 GEN_INT (GET_CODE (rtl) == PRE_INC
7737 ? GET_MODE_UNIT_SIZE (mode)
7738 : -GET_MODE_UNIT_SIZE (mode)));
7740 /* Fall through. */
7742 case PLUS:
7743 plus:
7744 if (is_based_loc (rtl))
7745 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7746 INTVAL (XEXP (rtl, 1)));
7747 else
7749 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7751 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7752 && INTVAL (XEXP (rtl, 1)) >= 0)
7754 add_loc_descr (&mem_loc_result,
7755 new_loc_descr (DW_OP_plus_uconst,
7756 INTVAL (XEXP (rtl, 1)), 0));
7758 else
7760 add_loc_descr (&mem_loc_result,
7761 mem_loc_descriptor (XEXP (rtl, 1), mode));
7762 add_loc_descr (&mem_loc_result,
7763 new_loc_descr (DW_OP_plus, 0, 0));
7766 break;
7768 case MULT:
7769 /* If a pseudo-reg is optimized away, it is possible for it to
7770 be replaced with a MEM containing a multiply. */
7771 add_loc_descr (&mem_loc_result,
7772 mem_loc_descriptor (XEXP (rtl, 0), mode));
7773 add_loc_descr (&mem_loc_result,
7774 mem_loc_descriptor (XEXP (rtl, 1), mode));
7775 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7776 break;
7778 case CONST_INT:
7779 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7780 break;
7782 default:
7783 abort ();
7786 return mem_loc_result;
7789 /* Return a descriptor that describes the concatenation of two locations.
7790 This is typically a complex variable. */
7792 static dw_loc_descr_ref
7793 concat_loc_descriptor (x0, x1)
7794 register rtx x0, x1;
7796 dw_loc_descr_ref cc_loc_result = NULL;
7798 if (!is_pseudo_reg (x0)
7799 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7800 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7801 add_loc_descr (&cc_loc_result,
7802 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7804 if (!is_pseudo_reg (x1)
7805 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7806 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7807 add_loc_descr (&cc_loc_result,
7808 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7810 return cc_loc_result;
7813 /* Output a proper Dwarf location descriptor for a variable or parameter
7814 which is either allocated in a register or in a memory location. For a
7815 register, we just generate an OP_REG and the register number. For a
7816 memory location we provide a Dwarf postfix expression describing how to
7817 generate the (dynamic) address of the object onto the address stack. */
7819 static dw_loc_descr_ref
7820 loc_descriptor (rtl)
7821 register rtx rtl;
7823 dw_loc_descr_ref loc_result = NULL;
7824 switch (GET_CODE (rtl))
7826 case SUBREG:
7827 /* The case of a subreg may arise when we have a local (register)
7828 variable or a formal (register) parameter which doesn't quite fill
7829 up an entire register. For now, just assume that it is
7830 legitimate to make the Dwarf info refer to the whole register which
7831 contains the given subreg. */
7832 rtl = XEXP (rtl, 0);
7834 /* Fall through. */
7836 case REG:
7837 loc_result = reg_loc_descriptor (rtl);
7838 break;
7840 case MEM:
7841 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7842 break;
7844 case CONCAT:
7845 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7846 break;
7848 default:
7849 abort ();
7852 return loc_result;
7855 /* Similar, but generate the descriptor from trees instead of rtl.
7856 This comes up particularly with variable length arrays. */
7858 static dw_loc_descr_ref
7859 loc_descriptor_from_tree (loc, addressp)
7860 tree loc;
7861 int addressp;
7863 dw_loc_descr_ref ret = NULL;
7864 int indirect_size = 0;
7865 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7866 enum dwarf_location_atom op;
7868 /* ??? Most of the time we do not take proper care for sign/zero
7869 extending the values properly. Hopefully this won't be a real
7870 problem... */
7872 switch (TREE_CODE (loc))
7874 case ERROR_MARK:
7875 break;
7877 case WITH_RECORD_EXPR:
7878 /* This case involves extracting fields from an object to determine the
7879 position of other fields. We don't try to encode this here. The
7880 only user of this is Ada, which encodes the needed information using
7881 the names of types. */
7882 return ret;
7884 case VAR_DECL:
7885 case PARM_DECL:
7887 rtx rtl = rtl_for_decl_location (loc);
7888 enum machine_mode mode = DECL_MODE (loc);
7890 if (rtl == NULL_RTX)
7891 break;
7892 else if (CONSTANT_P (rtl))
7894 ret = new_loc_descr (DW_OP_addr, 0, 0);
7895 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7896 ret->dw_loc_oprnd1.v.val_addr = rtl;
7897 indirect_size = GET_MODE_SIZE (mode);
7899 else
7901 if (GET_CODE (rtl) == MEM)
7903 indirect_size = GET_MODE_SIZE (mode);
7904 rtl = XEXP (rtl, 0);
7906 ret = mem_loc_descriptor (rtl, mode);
7909 break;
7911 case INDIRECT_REF:
7912 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7913 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
7914 break;
7916 case NOP_EXPR:
7917 case CONVERT_EXPR:
7918 case NON_LVALUE_EXPR:
7919 case SAVE_EXPR:
7920 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
7922 case COMPONENT_REF:
7923 case BIT_FIELD_REF:
7924 case ARRAY_REF:
7926 tree obj, offset;
7927 HOST_WIDE_INT bitsize, bitpos, bytepos;
7928 enum machine_mode mode;
7929 int volatilep;
7930 unsigned int alignment;
7932 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7933 &unsignedp, &volatilep, &alignment);
7934 ret = loc_descriptor_from_tree (obj, 1);
7936 if (offset != NULL_TREE)
7938 /* Variable offset. */
7939 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7940 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7943 if (addressp)
7945 /* We cannot address anything not on a unit boundary. */
7946 if (bitpos % BITS_PER_UNIT != 0)
7947 abort ();
7949 else
7951 if (bitpos % BITS_PER_UNIT != 0
7952 || bitsize % BITS_PER_UNIT != 0)
7954 /* ??? We could handle this by loading and shifting etc.
7955 Wait until someone needs it before expending the effort. */
7956 abort ();
7959 indirect_size = bitsize / BITS_PER_UNIT;
7962 bytepos = bitpos / BITS_PER_UNIT;
7963 if (bytepos > 0)
7964 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7965 else if (bytepos < 0)
7967 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7968 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7970 break;
7973 case INTEGER_CST:
7974 if (host_integerp (loc, 0))
7975 ret = int_loc_descriptor (tree_low_cst (loc, 0));
7976 break;
7978 case BIT_AND_EXPR:
7979 op = DW_OP_and;
7980 goto do_binop;
7981 case BIT_XOR_EXPR:
7982 op = DW_OP_xor;
7983 goto do_binop;
7984 case BIT_IOR_EXPR:
7985 op = DW_OP_or;
7986 goto do_binop;
7987 case TRUNC_DIV_EXPR:
7988 op = DW_OP_div;
7989 goto do_binop;
7990 case MINUS_EXPR:
7991 op = DW_OP_minus;
7992 goto do_binop;
7993 case TRUNC_MOD_EXPR:
7994 op = DW_OP_mod;
7995 goto do_binop;
7996 case MULT_EXPR:
7997 op = DW_OP_mul;
7998 goto do_binop;
7999 case LSHIFT_EXPR:
8000 op = DW_OP_shl;
8001 goto do_binop;
8002 case RSHIFT_EXPR:
8003 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8004 goto do_binop;
8005 case PLUS_EXPR:
8006 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8007 && host_integerp (TREE_OPERAND (loc, 1), 0))
8009 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8010 add_loc_descr (&ret,
8011 new_loc_descr (DW_OP_plus_uconst,
8012 tree_low_cst (TREE_OPERAND (loc, 1),
8014 0));
8015 break;
8017 op = DW_OP_plus;
8018 goto do_binop;
8019 case LE_EXPR:
8020 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8021 break;
8022 op = DW_OP_le;
8023 goto do_binop;
8024 case GE_EXPR:
8025 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8026 break;
8027 op = DW_OP_ge;
8028 goto do_binop;
8029 case LT_EXPR:
8030 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8031 break;
8032 op = DW_OP_lt;
8033 goto do_binop;
8034 case GT_EXPR:
8035 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8036 break;
8037 op = DW_OP_gt;
8038 goto do_binop;
8039 case EQ_EXPR:
8040 op = DW_OP_eq;
8041 goto do_binop;
8042 case NE_EXPR:
8043 op = DW_OP_ne;
8044 goto do_binop;
8046 do_binop:
8047 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8048 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
8049 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8050 break;
8052 case BIT_NOT_EXPR:
8053 op = DW_OP_not;
8054 goto do_unop;
8055 case ABS_EXPR:
8056 op = DW_OP_abs;
8057 goto do_unop;
8058 case NEGATE_EXPR:
8059 op = DW_OP_neg;
8060 goto do_unop;
8062 do_unop:
8063 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8064 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8065 break;
8067 case MAX_EXPR:
8068 loc = build (COND_EXPR, TREE_TYPE (loc),
8069 build (LT_EXPR, integer_type_node,
8070 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8071 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8072 /* FALLTHRU */
8074 case COND_EXPR:
8076 dw_loc_descr_ref bra_node, jump_node, tmp;
8078 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8079 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8080 add_loc_descr (&ret, bra_node);
8082 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8083 add_loc_descr (&ret, tmp);
8084 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8085 add_loc_descr (&ret, jump_node);
8087 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8088 add_loc_descr (&ret, tmp);
8089 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8090 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
8092 /* ??? Need a node to point the skip at. Use a nop. */
8093 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8094 add_loc_descr (&ret, tmp);
8095 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8096 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8098 break;
8100 default:
8101 abort ();
8104 /* If we can't fill the request for an address, die. */
8105 if (addressp && indirect_size == 0)
8106 abort ();
8108 /* If we've got an address and don't want one, dereference. */
8109 if (!addressp && indirect_size > 0)
8111 if (indirect_size > DWARF2_ADDR_SIZE)
8112 abort ();
8113 if (indirect_size == DWARF2_ADDR_SIZE)
8114 op = DW_OP_deref;
8115 else
8116 op = DW_OP_deref_size;
8117 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
8120 return ret;
8123 /* Given a value, round it up to the lowest multiple of `boundary'
8124 which is not less than the value itself. */
8126 static inline HOST_WIDE_INT
8127 ceiling (value, boundary)
8128 HOST_WIDE_INT value;
8129 unsigned int boundary;
8131 return (((value + boundary - 1) / boundary) * boundary);
8134 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8135 pointer to the declared type for the relevant field variable, or return
8136 `integer_type_node' if the given node turns out to be an
8137 ERROR_MARK node. */
8139 static inline tree
8140 field_type (decl)
8141 register tree decl;
8143 register tree type;
8145 if (TREE_CODE (decl) == ERROR_MARK)
8146 return integer_type_node;
8148 type = DECL_BIT_FIELD_TYPE (decl);
8149 if (type == NULL_TREE)
8150 type = TREE_TYPE (decl);
8152 return type;
8155 /* Given a pointer to a tree node, return the alignment in bits for
8156 it, or else return BITS_PER_WORD if the node actually turns out to
8157 be an ERROR_MARK node. */
8159 static inline unsigned
8160 simple_type_align_in_bits (type)
8161 register tree type;
8163 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8166 static inline unsigned
8167 simple_decl_align_in_bits (decl)
8168 register tree decl;
8170 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8173 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8174 node, return the size in bits for the type if it is a constant, or else
8175 return the alignment for the type if the type's size is not constant, or
8176 else return BITS_PER_WORD if the type actually turns out to be an
8177 ERROR_MARK node. */
8179 static inline unsigned HOST_WIDE_INT
8180 simple_type_size_in_bits (type)
8181 register tree type;
8183 tree type_size_tree;
8185 if (TREE_CODE (type) == ERROR_MARK)
8186 return BITS_PER_WORD;
8187 type_size_tree = TYPE_SIZE (type);
8189 if (type_size_tree == NULL_TREE)
8190 return 0;
8191 if (! host_integerp (type_size_tree, 1))
8192 return TYPE_ALIGN (type);
8193 return tree_low_cst (type_size_tree, 1);
8196 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
8197 return the byte offset of the lowest addressed byte of the "containing
8198 object" for the given FIELD_DECL, or return 0 if we are unable to
8199 determine what that offset is, either because the argument turns out to
8200 be a pointer to an ERROR_MARK node, or because the offset is actually
8201 variable. (We can't handle the latter case just yet). */
8203 static HOST_WIDE_INT
8204 field_byte_offset (decl)
8205 register tree decl;
8207 unsigned int type_align_in_bits;
8208 unsigned int decl_align_in_bits;
8209 unsigned HOST_WIDE_INT type_size_in_bits;
8210 HOST_WIDE_INT object_offset_in_bits;
8211 HOST_WIDE_INT object_offset_in_bytes;
8212 tree type;
8213 tree field_size_tree;
8214 HOST_WIDE_INT bitpos_int;
8215 HOST_WIDE_INT deepest_bitpos;
8216 unsigned HOST_WIDE_INT field_size_in_bits;
8218 if (TREE_CODE (decl) == ERROR_MARK)
8219 return 0;
8221 if (TREE_CODE (decl) != FIELD_DECL)
8222 abort ();
8224 type = field_type (decl);
8225 field_size_tree = DECL_SIZE (decl);
8227 /* The size could be unspecified if there was an error, or for
8228 a flexible array member. */
8229 if (! field_size_tree)
8230 field_size_tree = bitsize_zero_node;
8232 /* We cannot yet cope with fields whose positions are variable, so
8233 for now, when we see such things, we simply return 0. Someday, we may
8234 be able to handle such cases, but it will be damn difficult. */
8235 if (! host_integerp (bit_position (decl), 0))
8236 return 0;
8238 bitpos_int = int_bit_position (decl);
8240 /* If we don't know the size of the field, pretend it's a full word. */
8241 if (host_integerp (field_size_tree, 1))
8242 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8243 else
8244 field_size_in_bits = BITS_PER_WORD;
8246 type_size_in_bits = simple_type_size_in_bits (type);
8247 type_align_in_bits = simple_type_align_in_bits (type);
8248 decl_align_in_bits = simple_decl_align_in_bits (decl);
8250 /* Note that the GCC front-end doesn't make any attempt to keep track of
8251 the starting bit offset (relative to the start of the containing
8252 structure type) of the hypothetical "containing object" for a bit-
8253 field. Thus, when computing the byte offset value for the start of the
8254 "containing object" of a bit-field, we must deduce this information on
8255 our own. This can be rather tricky to do in some cases. For example,
8256 handling the following structure type definition when compiling for an
8257 i386/i486 target (which only aligns long long's to 32-bit boundaries)
8258 can be very tricky:
8260 struct S { int field1; long long field2:31; };
8262 Fortunately, there is a simple rule-of-thumb which can be
8263 used in such cases. When compiling for an i386/i486, GCC will allocate
8264 8 bytes for the structure shown above. It decides to do this based upon
8265 one simple rule for bit-field allocation. Quite simply, GCC allocates
8266 each "containing object" for each bit-field at the first (i.e. lowest
8267 addressed) legitimate alignment boundary (based upon the required
8268 minimum alignment for the declared type of the field) which it can
8269 possibly use, subject to the condition that there is still enough
8270 available space remaining in the containing object (when allocated at
8271 the selected point) to fully accommodate all of the bits of the
8272 bit-field itself. This simple rule makes it obvious why GCC allocates
8273 8 bytes for each object of the structure type shown above. When looking
8274 for a place to allocate the "containing object" for `field2', the
8275 compiler simply tries to allocate a 64-bit "containing object" at each
8276 successive 32-bit boundary (starting at zero) until it finds a place to
8277 allocate that 64- bit field such that at least 31 contiguous (and
8278 previously unallocated) bits remain within that selected 64 bit field.
8279 (As it turns out, for the example above, the compiler finds that it is
8280 OK to allocate the "containing object" 64-bit field at bit-offset zero
8281 within the structure type.) Here we attempt to work backwards from the
8282 limited set of facts we're given, and we try to deduce from those facts,
8283 where GCC must have believed that the containing object started (within
8284 the structure type). The value we deduce is then used (by the callers of
8285 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
8286 for fields (both bit-fields and, in the case of DW_AT_location, regular
8287 fields as well). */
8289 /* Figure out the bit-distance from the start of the structure to the
8290 "deepest" bit of the bit-field. */
8291 deepest_bitpos = bitpos_int + field_size_in_bits;
8293 /* This is the tricky part. Use some fancy footwork to deduce where the
8294 lowest addressed bit of the containing object must be. */
8295 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8297 /* Round up to type_align by default. This works best for bitfields. */
8298 object_offset_in_bits += type_align_in_bits - 1;
8299 object_offset_in_bits /= type_align_in_bits;
8300 object_offset_in_bits *= type_align_in_bits;
8302 if (object_offset_in_bits > bitpos_int)
8304 /* Sigh, the decl must be packed. */
8305 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8307 /* Round up to decl_align instead. */
8308 object_offset_in_bits += decl_align_in_bits - 1;
8309 object_offset_in_bits /= decl_align_in_bits;
8310 object_offset_in_bits *= decl_align_in_bits;
8313 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
8315 return object_offset_in_bytes;
8318 /* The following routines define various Dwarf attributes and any data
8319 associated with them. */
8321 /* Add a location description attribute value to a DIE.
8323 This emits location attributes suitable for whole variables and
8324 whole parameters. Note that the location attributes for struct fields are
8325 generated by the routine `data_member_location_attribute' below. */
8327 static void
8328 add_AT_location_description (die, attr_kind, rtl)
8329 dw_die_ref die;
8330 enum dwarf_attribute attr_kind;
8331 register rtx rtl;
8333 /* Handle a special case. If we are about to output a location descriptor
8334 for a variable or parameter which has been optimized out of existence,
8335 don't do that. A variable which has been optimized out
8336 of existence will have a DECL_RTL value which denotes a pseudo-reg.
8337 Currently, in some rare cases, variables can have DECL_RTL values which
8338 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
8339 elsewhere in the compiler. We treat such cases as if the variable(s) in
8340 question had been optimized out of existence. */
8342 if (is_pseudo_reg (rtl)
8343 || (GET_CODE (rtl) == MEM
8344 && is_pseudo_reg (XEXP (rtl, 0)))
8345 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
8346 references the internal argument pointer (a pseudo) in a function
8347 where all references to the internal argument pointer were
8348 eliminated via the optimizers. */
8349 || (GET_CODE (rtl) == MEM
8350 && GET_CODE (XEXP (rtl, 0)) == PLUS
8351 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
8352 || (GET_CODE (rtl) == CONCAT
8353 && is_pseudo_reg (XEXP (rtl, 0))
8354 && is_pseudo_reg (XEXP (rtl, 1))))
8355 return;
8357 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
8360 /* Attach the specialized form of location attribute used for data
8361 members of struct and union types. In the special case of a
8362 FIELD_DECL node which represents a bit-field, the "offset" part
8363 of this special location descriptor must indicate the distance
8364 in bytes from the lowest-addressed byte of the containing struct
8365 or union type to the lowest-addressed byte of the "containing
8366 object" for the bit-field. (See the `field_byte_offset' function
8367 above).. For any given bit-field, the "containing object" is a
8368 hypothetical object (of some integral or enum type) within which
8369 the given bit-field lives. The type of this hypothetical
8370 "containing object" is always the same as the declared type of
8371 the individual bit-field itself (for GCC anyway... the DWARF
8372 spec doesn't actually mandate this). Note that it is the size
8373 (in bytes) of the hypothetical "containing object" which will
8374 be given in the DW_AT_byte_size attribute for this bit-field.
8375 (See the `byte_size_attribute' function below.) It is also used
8376 when calculating the value of the DW_AT_bit_offset attribute.
8377 (See the `bit_offset_attribute' function below). */
8379 static void
8380 add_data_member_location_attribute (die, decl)
8381 register dw_die_ref die;
8382 register tree decl;
8384 register unsigned long offset;
8385 register dw_loc_descr_ref loc_descr;
8386 register enum dwarf_location_atom op;
8388 if (TREE_CODE (decl) == TREE_VEC)
8389 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8390 else
8391 offset = field_byte_offset (decl);
8393 /* The DWARF2 standard says that we should assume that the structure address
8394 is already on the stack, so we can specify a structure field address
8395 by using DW_OP_plus_uconst. */
8397 #ifdef MIPS_DEBUGGING_INFO
8398 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
8399 correctly. It works only if we leave the offset on the stack. */
8400 op = DW_OP_constu;
8401 #else
8402 op = DW_OP_plus_uconst;
8403 #endif
8405 loc_descr = new_loc_descr (op, offset, 0);
8406 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8409 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8410 does not have a "location" either in memory or in a register. These
8411 things can arise in GNU C when a constant is passed as an actual parameter
8412 to an inlined function. They can also arise in C++ where declared
8413 constants do not necessarily get memory "homes". */
8415 static void
8416 add_const_value_attribute (die, rtl)
8417 register dw_die_ref die;
8418 register rtx rtl;
8420 switch (GET_CODE (rtl))
8422 case CONST_INT:
8423 /* Note that a CONST_INT rtx could represent either an integer or a
8424 floating-point constant. A CONST_INT is used whenever the constant
8425 will fit into a single word. In all such cases, the original mode
8426 of the constant value is wiped out, and the CONST_INT rtx is
8427 assigned VOIDmode. */
8428 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
8429 break;
8431 case CONST_DOUBLE:
8432 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8433 floating-point constant. A CONST_DOUBLE is used whenever the
8434 constant requires more than one word in order to be adequately
8435 represented. We output CONST_DOUBLEs as blocks. */
8437 register enum machine_mode mode = GET_MODE (rtl);
8439 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8441 register unsigned length = GET_MODE_SIZE (mode) / 4;
8442 long *array = (long *) xmalloc (sizeof (long) * length);
8443 REAL_VALUE_TYPE rv;
8445 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8446 switch (mode)
8448 case SFmode:
8449 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8450 break;
8452 case DFmode:
8453 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8454 break;
8456 case XFmode:
8457 case TFmode:
8458 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8459 break;
8461 default:
8462 abort ();
8465 add_AT_float (die, DW_AT_const_value, length, array);
8467 else
8468 add_AT_long_long (die, DW_AT_const_value,
8469 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8471 break;
8473 case CONST_STRING:
8474 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8475 break;
8477 case SYMBOL_REF:
8478 case LABEL_REF:
8479 case CONST:
8480 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8481 break;
8483 case PLUS:
8484 /* In cases where an inlined instance of an inline function is passed
8485 the address of an `auto' variable (which is local to the caller) we
8486 can get a situation where the DECL_RTL of the artificial local
8487 variable (for the inlining) which acts as a stand-in for the
8488 corresponding formal parameter (of the inline function) will look
8489 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8490 exactly a compile-time constant expression, but it isn't the address
8491 of the (artificial) local variable either. Rather, it represents the
8492 *value* which the artificial local variable always has during its
8493 lifetime. We currently have no way to represent such quasi-constant
8494 values in Dwarf, so for now we just punt and generate nothing. */
8495 break;
8497 default:
8498 /* No other kinds of rtx should be possible here. */
8499 abort ();
8504 static rtx
8505 rtl_for_decl_location (decl)
8506 tree decl;
8508 register rtx rtl;
8510 /* Here we have to decide where we are going to say the parameter "lives"
8511 (as far as the debugger is concerned). We only have a couple of
8512 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8514 DECL_RTL normally indicates where the parameter lives during most of the
8515 activation of the function. If optimization is enabled however, this
8516 could be either NULL or else a pseudo-reg. Both of those cases indicate
8517 that the parameter doesn't really live anywhere (as far as the code
8518 generation parts of GCC are concerned) during most of the function's
8519 activation. That will happen (for example) if the parameter is never
8520 referenced within the function.
8522 We could just generate a location descriptor here for all non-NULL
8523 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8524 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8525 where DECL_RTL is NULL or is a pseudo-reg.
8527 Note however that we can only get away with using DECL_INCOMING_RTL as
8528 a backup substitute for DECL_RTL in certain limited cases. In cases
8529 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8530 we can be sure that the parameter was passed using the same type as it is
8531 declared to have within the function, and that its DECL_INCOMING_RTL
8532 points us to a place where a value of that type is passed.
8534 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8535 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8536 because in these cases DECL_INCOMING_RTL points us to a value of some
8537 type which is *different* from the type of the parameter itself. Thus,
8538 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8539 such cases, the debugger would end up (for example) trying to fetch a
8540 `float' from a place which actually contains the first part of a
8541 `double'. That would lead to really incorrect and confusing
8542 output at debug-time.
8544 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8545 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8546 are a couple of exceptions however. On little-endian machines we can
8547 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8548 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8549 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8550 when (on a little-endian machine) a non-prototyped function has a
8551 parameter declared to be of type `short' or `char'. In such cases,
8552 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8553 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8554 passed `int' value. If the debugger then uses that address to fetch
8555 a `short' or a `char' (on a little-endian machine) the result will be
8556 the correct data, so we allow for such exceptional cases below.
8558 Note that our goal here is to describe the place where the given formal
8559 parameter lives during most of the function's activation (i.e. between
8560 the end of the prologue and the start of the epilogue). We'll do that
8561 as best as we can. Note however that if the given formal parameter is
8562 modified sometime during the execution of the function, then a stack
8563 backtrace (at debug-time) will show the function as having been
8564 called with the *new* value rather than the value which was
8565 originally passed in. This happens rarely enough that it is not
8566 a major problem, but it *is* a problem, and I'd like to fix it.
8568 A future version of dwarf2out.c may generate two additional
8569 attributes for any given DW_TAG_formal_parameter DIE which will
8570 describe the "passed type" and the "passed location" for the
8571 given formal parameter in addition to the attributes we now
8572 generate to indicate the "declared type" and the "active
8573 location" for each parameter. This additional set of attributes
8574 could be used by debuggers for stack backtraces. Separately, note
8575 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8576 NULL also. This happens (for example) for inlined-instances of
8577 inline function formal parameters which are never referenced.
8578 This really shouldn't be happening. All PARM_DECL nodes should
8579 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8580 doesn't currently generate these values for inlined instances of
8581 inline function parameters, so when we see such cases, we are
8582 just out-of-luck for the time being (until integrate.c
8583 gets fixed). */
8585 /* Use DECL_RTL as the "location" unless we find something better. */
8586 rtl = DECL_RTL (decl);
8588 if (TREE_CODE (decl) == PARM_DECL)
8590 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8592 tree declared_type = type_main_variant (TREE_TYPE (decl));
8593 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8595 /* This decl represents a formal parameter which was optimized out.
8596 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8597 all* cases where (rtl == NULL_RTX) just below. */
8598 if (declared_type == passed_type)
8599 rtl = DECL_INCOMING_RTL (decl);
8600 else if (! BYTES_BIG_ENDIAN
8601 && TREE_CODE (declared_type) == INTEGER_TYPE
8602 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8603 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8604 rtl = DECL_INCOMING_RTL (decl);
8607 /* If the parm was passed in registers, but lives on the stack, then
8608 make a big endian correction if the mode of the type of the
8609 parameter is not the same as the mode of the rtl. */
8610 /* ??? This is the same series of checks that are made in dbxout.c before
8611 we reach the big endian correction code there. It isn't clear if all
8612 of these checks are necessary here, but keeping them all is the safe
8613 thing to do. */
8614 else if (GET_CODE (rtl) == MEM
8615 && XEXP (rtl, 0) != const0_rtx
8616 && ! CONSTANT_P (XEXP (rtl, 0))
8617 /* Not passed in memory. */
8618 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8619 /* Not passed by invisible reference. */
8620 && (GET_CODE (XEXP (rtl, 0)) != REG
8621 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8622 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8623 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8624 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8625 #endif
8627 /* Big endian correction check. */
8628 && BYTES_BIG_ENDIAN
8629 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8630 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8631 < UNITS_PER_WORD))
8633 int offset = (UNITS_PER_WORD
8634 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8635 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8636 plus_constant (XEXP (rtl, 0), offset));
8640 if (rtl != NULL_RTX)
8642 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8643 #ifdef LEAF_REG_REMAP
8644 if (current_function_uses_only_leaf_regs)
8645 leaf_renumber_regs_insn (rtl);
8646 #endif
8649 return rtl;
8652 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8653 data attribute for a variable or a parameter. We generate the
8654 DW_AT_const_value attribute only in those cases where the given variable
8655 or parameter does not have a true "location" either in memory or in a
8656 register. This can happen (for example) when a constant is passed as an
8657 actual argument in a call to an inline function. (It's possible that
8658 these things can crop up in other ways also.) Note that one type of
8659 constant value which can be passed into an inlined function is a constant
8660 pointer. This can happen for example if an actual argument in an inlined
8661 function call evaluates to a compile-time constant address. */
8663 static void
8664 add_location_or_const_value_attribute (die, decl)
8665 register dw_die_ref die;
8666 register tree decl;
8668 register rtx rtl;
8670 if (TREE_CODE (decl) == ERROR_MARK)
8671 return;
8673 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8674 abort ();
8676 rtl = rtl_for_decl_location (decl);
8677 if (rtl == NULL_RTX)
8678 return;
8680 switch (GET_CODE (rtl))
8682 case ADDRESSOF:
8683 /* The address of a variable that was optimized away; don't emit
8684 anything. */
8685 break;
8687 case CONST_INT:
8688 case CONST_DOUBLE:
8689 case CONST_STRING:
8690 case SYMBOL_REF:
8691 case LABEL_REF:
8692 case CONST:
8693 case PLUS:
8694 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8695 add_const_value_attribute (die, rtl);
8696 break;
8698 case MEM:
8699 case REG:
8700 case SUBREG:
8701 case CONCAT:
8702 add_AT_location_description (die, DW_AT_location, rtl);
8703 break;
8705 default:
8706 abort ();
8710 /* If we don't have a copy of this variable in memory for some reason (such
8711 as a C++ member constant that doesn't have an out-of-line definition),
8712 we should tell the debugger about the constant value. */
8714 static void
8715 tree_add_const_value_attribute (var_die, decl)
8716 dw_die_ref var_die;
8717 tree decl;
8719 tree init = DECL_INITIAL (decl);
8720 tree type = TREE_TYPE (decl);
8722 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8723 && initializer_constant_valid_p (init, type) == null_pointer_node)
8724 /* OK */;
8725 else
8726 return;
8728 switch (TREE_CODE (type))
8730 case INTEGER_TYPE:
8731 if (host_integerp (init, 0))
8732 add_AT_unsigned (var_die, DW_AT_const_value,
8733 TREE_INT_CST_LOW (init));
8734 else
8735 add_AT_long_long (var_die, DW_AT_const_value,
8736 TREE_INT_CST_HIGH (init),
8737 TREE_INT_CST_LOW (init));
8738 break;
8740 default:;
8744 /* Generate an DW_AT_name attribute given some string value to be included as
8745 the value of the attribute. */
8747 static inline void
8748 add_name_attribute (die, name_string)
8749 register dw_die_ref die;
8750 register const char *name_string;
8752 if (name_string != NULL && *name_string != 0)
8754 if (demangle_name_func)
8755 name_string = (*demangle_name_func) (name_string);
8757 add_AT_string (die, DW_AT_name, name_string);
8761 /* Given a tree node describing an array bound (either lower or upper) output
8762 a representation for that bound. */
8764 static void
8765 add_bound_info (subrange_die, bound_attr, bound)
8766 register dw_die_ref subrange_die;
8767 register enum dwarf_attribute bound_attr;
8768 register tree bound;
8770 /* If this is an Ada unconstrained array type, then don't emit any debug
8771 info because the array bounds are unknown. They are parameterized when
8772 the type is instantiated. */
8773 if (contains_placeholder_p (bound))
8774 return;
8776 switch (TREE_CODE (bound))
8778 case ERROR_MARK:
8779 return;
8781 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8782 case INTEGER_CST:
8783 if (! host_integerp (bound, 0)
8784 || (bound_attr == DW_AT_lower_bound
8785 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8786 || (is_fortran () && integer_onep (bound)))))
8787 /* use the default */
8789 else
8790 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8791 break;
8793 case CONVERT_EXPR:
8794 case NOP_EXPR:
8795 case NON_LVALUE_EXPR:
8796 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8797 break;
8799 case SAVE_EXPR:
8800 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8801 access the upper bound values may be bogus. If they refer to a
8802 register, they may only describe how to get at these values at the
8803 points in the generated code right after they have just been
8804 computed. Worse yet, in the typical case, the upper bound values
8805 will not even *be* computed in the optimized code (though the
8806 number of elements will), so these SAVE_EXPRs are entirely
8807 bogus. In order to compensate for this fact, we check here to see
8808 if optimization is enabled, and if so, we don't add an attribute
8809 for the (unknown and unknowable) upper bound. This should not
8810 cause too much trouble for existing (stupid?) debuggers because
8811 they have to deal with empty upper bounds location descriptions
8812 anyway in order to be able to deal with incomplete array types.
8813 Of course an intelligent debugger (GDB?) should be able to
8814 comprehend that a missing upper bound specification in a array
8815 type used for a storage class `auto' local array variable
8816 indicates that the upper bound is both unknown (at compile- time)
8817 and unknowable (at run-time) due to optimization.
8819 We assume that a MEM rtx is safe because gcc wouldn't put the
8820 value there unless it was going to be used repeatedly in the
8821 function, i.e. for cleanups. */
8822 if (! optimize || (SAVE_EXPR_RTL (bound)
8823 && GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8825 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8826 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8827 register rtx loc = SAVE_EXPR_RTL (bound);
8829 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8830 it references an outer function's frame. */
8832 if (GET_CODE (loc) == MEM)
8834 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8836 if (XEXP (loc, 0) != new_addr)
8837 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8840 add_AT_flag (decl_die, DW_AT_artificial, 1);
8841 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8842 add_AT_location_description (decl_die, DW_AT_location, loc);
8843 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8846 /* Else leave out the attribute. */
8847 break;
8849 case VAR_DECL:
8850 case PARM_DECL:
8852 dw_die_ref decl_die = lookup_decl_die (bound);
8854 /* ??? Can this happen, or should the variable have been bound
8855 first? Probably it can, since I imagine that we try to create
8856 the types of parameters in the order in which they exist in
8857 the list, and won't have created a forward reference to a
8858 later parameter. */
8859 if (decl_die != NULL)
8860 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8861 break;
8864 default:
8866 /* Otherwise try to create a stack operation procedure to
8867 evaluate the value of the array bound. */
8869 dw_die_ref ctx, decl_die;
8870 dw_loc_descr_ref loc;
8872 loc = loc_descriptor_from_tree (bound, 0);
8873 if (loc == NULL)
8874 break;
8876 ctx = lookup_decl_die (current_function_decl);
8878 decl_die = new_die (DW_TAG_variable, ctx);
8879 add_AT_flag (decl_die, DW_AT_artificial, 1);
8880 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8881 add_AT_loc (decl_die, DW_AT_location, loc);
8883 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8884 break;
8889 /* Note that the block of subscript information for an array type also
8890 includes information about the element type of type given array type. */
8892 static void
8893 add_subscript_info (type_die, type)
8894 register dw_die_ref type_die;
8895 register tree type;
8897 #ifndef MIPS_DEBUGGING_INFO
8898 register unsigned dimension_number;
8899 #endif
8900 register tree lower, upper;
8901 register dw_die_ref subrange_die;
8903 /* The GNU compilers represent multidimensional array types as sequences of
8904 one dimensional array types whose element types are themselves array
8905 types. Here we squish that down, so that each multidimensional array
8906 type gets only one array_type DIE in the Dwarf debugging info. The draft
8907 Dwarf specification say that we are allowed to do this kind of
8908 compression in C (because there is no difference between an array or
8909 arrays and a multidimensional array in C) but for other source languages
8910 (e.g. Ada) we probably shouldn't do this. */
8912 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8913 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8914 We work around this by disabling this feature. See also
8915 gen_array_type_die. */
8916 #ifndef MIPS_DEBUGGING_INFO
8917 for (dimension_number = 0;
8918 TREE_CODE (type) == ARRAY_TYPE;
8919 type = TREE_TYPE (type), dimension_number++)
8921 #endif
8922 register tree domain = TYPE_DOMAIN (type);
8924 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8925 and (in GNU C only) variable bounds. Handle all three forms
8926 here. */
8927 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8928 if (domain)
8930 /* We have an array type with specified bounds. */
8931 lower = TYPE_MIN_VALUE (domain);
8932 upper = TYPE_MAX_VALUE (domain);
8934 /* define the index type. */
8935 if (TREE_TYPE (domain))
8937 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8938 TREE_TYPE field. We can't emit debug info for this
8939 because it is an unnamed integral type. */
8940 if (TREE_CODE (domain) == INTEGER_TYPE
8941 && TYPE_NAME (domain) == NULL_TREE
8942 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8943 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8945 else
8946 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8947 type_die);
8950 /* ??? If upper is NULL, the array has unspecified length,
8951 but it does have a lower bound. This happens with Fortran
8952 dimension arr(N:*)
8953 Since the debugger is definitely going to need to know N
8954 to produce useful results, go ahead and output the lower
8955 bound solo, and hope the debugger can cope. */
8957 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8958 if (upper)
8959 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8961 else
8962 /* We have an array type with an unspecified length. The DWARF-2
8963 spec does not say how to handle this; let's just leave out the
8964 bounds. */
8967 #ifndef MIPS_DEBUGGING_INFO
8969 #endif
8972 static void
8973 add_byte_size_attribute (die, tree_node)
8974 dw_die_ref die;
8975 register tree tree_node;
8977 register unsigned size;
8979 switch (TREE_CODE (tree_node))
8981 case ERROR_MARK:
8982 size = 0;
8983 break;
8984 case ENUMERAL_TYPE:
8985 case RECORD_TYPE:
8986 case UNION_TYPE:
8987 case QUAL_UNION_TYPE:
8988 size = int_size_in_bytes (tree_node);
8989 break;
8990 case FIELD_DECL:
8991 /* For a data member of a struct or union, the DW_AT_byte_size is
8992 generally given as the number of bytes normally allocated for an
8993 object of the *declared* type of the member itself. This is true
8994 even for bit-fields. */
8995 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8996 break;
8997 default:
8998 abort ();
9001 /* Note that `size' might be -1 when we get to this point. If it is, that
9002 indicates that the byte size of the entity in question is variable. We
9003 have no good way of expressing this fact in Dwarf at the present time,
9004 so just let the -1 pass on through. */
9006 add_AT_unsigned (die, DW_AT_byte_size, size);
9009 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9010 which specifies the distance in bits from the highest order bit of the
9011 "containing object" for the bit-field to the highest order bit of the
9012 bit-field itself.
9014 For any given bit-field, the "containing object" is a hypothetical
9015 object (of some integral or enum type) within which the given bit-field
9016 lives. The type of this hypothetical "containing object" is always the
9017 same as the declared type of the individual bit-field itself. The
9018 determination of the exact location of the "containing object" for a
9019 bit-field is rather complicated. It's handled by the
9020 `field_byte_offset' function (above).
9022 Note that it is the size (in bytes) of the hypothetical "containing object"
9023 which will be given in the DW_AT_byte_size attribute for this bit-field.
9024 (See `byte_size_attribute' above). */
9026 static inline void
9027 add_bit_offset_attribute (die, decl)
9028 register dw_die_ref die;
9029 register tree decl;
9031 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9032 tree type = DECL_BIT_FIELD_TYPE (decl);
9033 HOST_WIDE_INT bitpos_int;
9034 HOST_WIDE_INT highest_order_object_bit_offset;
9035 HOST_WIDE_INT highest_order_field_bit_offset;
9036 HOST_WIDE_INT unsigned bit_offset;
9038 /* Must be a field and a bit field. */
9039 if (!type
9040 || TREE_CODE (decl) != FIELD_DECL)
9041 abort ();
9043 /* We can't yet handle bit-fields whose offsets are variable, so if we
9044 encounter such things, just return without generating any attribute
9045 whatsoever. Likewise for variable or too large size. */
9046 if (! host_integerp (bit_position (decl), 0)
9047 || ! host_integerp (DECL_SIZE (decl), 1))
9048 return;
9050 bitpos_int = int_bit_position (decl);
9052 /* Note that the bit offset is always the distance (in bits) from the
9053 highest-order bit of the "containing object" to the highest-order bit of
9054 the bit-field itself. Since the "high-order end" of any object or field
9055 is different on big-endian and little-endian machines, the computation
9056 below must take account of these differences. */
9057 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9058 highest_order_field_bit_offset = bitpos_int;
9060 if (! BYTES_BIG_ENDIAN)
9062 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9063 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9066 bit_offset
9067 = (! BYTES_BIG_ENDIAN
9068 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9069 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9071 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9074 /* For a FIELD_DECL node which represents a bit field, output an attribute
9075 which specifies the length in bits of the given field. */
9077 static inline void
9078 add_bit_size_attribute (die, decl)
9079 register dw_die_ref die;
9080 register tree decl;
9082 /* Must be a field and a bit field. */
9083 if (TREE_CODE (decl) != FIELD_DECL
9084 || ! DECL_BIT_FIELD_TYPE (decl))
9085 abort ();
9087 if (host_integerp (DECL_SIZE (decl), 1))
9088 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9091 /* If the compiled language is ANSI C, then add a 'prototyped'
9092 attribute, if arg types are given for the parameters of a function. */
9094 static inline void
9095 add_prototyped_attribute (die, func_type)
9096 register dw_die_ref die;
9097 register tree func_type;
9099 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9100 && TYPE_ARG_TYPES (func_type) != NULL)
9101 add_AT_flag (die, DW_AT_prototyped, 1);
9104 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9105 by looking in either the type declaration or object declaration
9106 equate table. */
9108 static inline void
9109 add_abstract_origin_attribute (die, origin)
9110 register dw_die_ref die;
9111 register tree origin;
9113 dw_die_ref origin_die = NULL;
9115 if (TREE_CODE (origin) != FUNCTION_DECL)
9117 /* We may have gotten separated from the block for the inlined
9118 function, if we're in an exception handler or some such; make
9119 sure that the abstract function has been written out.
9121 Doing this for nested functions is wrong, however; functions are
9122 distinct units, and our context might not even be inline. */
9123 tree fn = origin;
9124 if (TYPE_P (fn))
9125 fn = TYPE_STUB_DECL (fn);
9126 fn = decl_function_context (fn);
9127 if (fn)
9128 gen_abstract_function (fn);
9131 if (DECL_P (origin))
9132 origin_die = lookup_decl_die (origin);
9133 else if (TYPE_P (origin))
9134 origin_die = lookup_type_die (origin);
9136 if (origin_die == NULL)
9137 abort ();
9139 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9142 /* We do not currently support the pure_virtual attribute. */
9144 static inline void
9145 add_pure_or_virtual_attribute (die, func_decl)
9146 register dw_die_ref die;
9147 register tree func_decl;
9149 if (DECL_VINDEX (func_decl))
9151 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9153 if (host_integerp (DECL_VINDEX (func_decl), 0))
9154 add_AT_loc (die, DW_AT_vtable_elem_location,
9155 new_loc_descr (DW_OP_constu,
9156 tree_low_cst (DECL_VINDEX (func_decl), 0),
9157 0));
9159 /* GNU extension: Record what type this method came from originally. */
9160 if (debug_info_level > DINFO_LEVEL_TERSE)
9161 add_AT_die_ref (die, DW_AT_containing_type,
9162 lookup_type_die (DECL_CONTEXT (func_decl)));
9166 /* Add source coordinate attributes for the given decl. */
9168 static void
9169 add_src_coords_attributes (die, decl)
9170 register dw_die_ref die;
9171 register tree decl;
9173 register unsigned file_index = lookup_filename (&decl_file_table,
9174 DECL_SOURCE_FILE (decl));
9176 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9177 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9180 /* Add an DW_AT_name attribute and source coordinate attribute for the
9181 given decl, but only if it actually has a name. */
9183 static void
9184 add_name_and_src_coords_attributes (die, decl)
9185 register dw_die_ref die;
9186 register tree decl;
9188 register tree decl_name;
9190 decl_name = DECL_NAME (decl);
9191 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9193 add_name_attribute (die, dwarf2_name (decl, 0));
9194 if (! DECL_ARTIFICIAL (decl))
9195 add_src_coords_attributes (die, decl);
9197 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9198 && TREE_PUBLIC (decl)
9199 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
9200 add_AT_string (die, DW_AT_MIPS_linkage_name,
9201 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9205 /* Push a new declaration scope. */
9207 static void
9208 push_decl_scope (scope)
9209 tree scope;
9211 /* Make room in the decl_scope_table, if necessary. */
9212 if (decl_scope_table_allocated == decl_scope_depth)
9214 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
9215 decl_scope_table
9216 = (tree *) xrealloc (decl_scope_table,
9217 decl_scope_table_allocated * sizeof (tree));
9220 decl_scope_table[decl_scope_depth] = scope;
9221 decl_scope_depth++;
9224 /* Pop a declaration scope. */
9225 static inline void
9226 pop_decl_scope ()
9228 if (decl_scope_depth <= 0)
9229 abort ();
9230 --decl_scope_depth;
9233 /* Return the DIE for the scope that immediately contains this type.
9234 Non-named types get global scope. Named types nested in other
9235 types get their containing scope if it's open, or global scope
9236 otherwise. All other types (i.e. function-local named types) get
9237 the current active scope. */
9239 static dw_die_ref
9240 scope_die_for (t, context_die)
9241 register tree t;
9242 register dw_die_ref context_die;
9244 register dw_die_ref scope_die = NULL;
9245 register tree containing_scope;
9246 register int i;
9248 /* Non-types always go in the current scope. */
9249 if (! TYPE_P (t))
9250 abort ();
9252 containing_scope = TYPE_CONTEXT (t);
9254 /* Ignore namespaces for the moment. */
9255 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9256 containing_scope = NULL_TREE;
9258 /* Ignore function type "scopes" from the C frontend. They mean that
9259 a tagged type is local to a parmlist of a function declarator, but
9260 that isn't useful to DWARF. */
9261 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9262 containing_scope = NULL_TREE;
9264 if (containing_scope == NULL_TREE)
9265 scope_die = comp_unit_die;
9266 else if (TYPE_P (containing_scope))
9268 /* For types, we can just look up the appropriate DIE. But
9269 first we check to see if we're in the middle of emitting it
9270 so we know where the new DIE should go. */
9272 for (i = decl_scope_depth - 1; i >= 0; --i)
9273 if (decl_scope_table[i] == containing_scope)
9274 break;
9276 if (i < 0)
9278 if (debug_info_level > DINFO_LEVEL_TERSE
9279 && !TREE_ASM_WRITTEN (containing_scope))
9280 abort ();
9282 /* If none of the current dies are suitable, we get file scope. */
9283 scope_die = comp_unit_die;
9285 else
9286 scope_die = lookup_type_die (containing_scope);
9288 else
9289 scope_die = context_die;
9291 return scope_die;
9294 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
9296 static inline int local_scope_p PARAMS ((dw_die_ref));
9297 static inline int
9298 local_scope_p (context_die)
9299 dw_die_ref context_die;
9301 for (; context_die; context_die = context_die->die_parent)
9302 if (context_die->die_tag == DW_TAG_inlined_subroutine
9303 || context_die->die_tag == DW_TAG_subprogram)
9304 return 1;
9305 return 0;
9308 /* Returns nonzero iff CONTEXT_DIE is a class. */
9310 static inline int class_scope_p PARAMS ((dw_die_ref));
9311 static inline int
9312 class_scope_p (context_die)
9313 dw_die_ref context_die;
9315 return (context_die
9316 && (context_die->die_tag == DW_TAG_structure_type
9317 || context_die->die_tag == DW_TAG_union_type));
9320 /* Many forms of DIEs require a "type description" attribute. This
9321 routine locates the proper "type descriptor" die for the type given
9322 by 'type', and adds an DW_AT_type attribute below the given die. */
9324 static void
9325 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9326 register dw_die_ref object_die;
9327 register tree type;
9328 register int decl_const;
9329 register int decl_volatile;
9330 register dw_die_ref context_die;
9332 register enum tree_code code = TREE_CODE (type);
9333 register dw_die_ref type_die = NULL;
9335 /* ??? If this type is an unnamed subrange type of an integral or
9336 floating-point type, use the inner type. This is because we have no
9337 support for unnamed types in base_type_die. This can happen if this is
9338 an Ada subrange type. Correct solution is emit a subrange type die. */
9339 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9340 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9341 type = TREE_TYPE (type), code = TREE_CODE (type);
9343 if (code == ERROR_MARK)
9344 return;
9346 /* Handle a special case. For functions whose return type is void, we
9347 generate *no* type attribute. (Note that no object may have type
9348 `void', so this only applies to function return types). */
9349 if (code == VOID_TYPE)
9350 return;
9352 type_die = modified_type_die (type,
9353 decl_const || TYPE_READONLY (type),
9354 decl_volatile || TYPE_VOLATILE (type),
9355 context_die);
9356 if (type_die != NULL)
9357 add_AT_die_ref (object_die, DW_AT_type, type_die);
9360 /* Given a tree pointer to a struct, class, union, or enum type node, return
9361 a pointer to the (string) tag name for the given type, or zero if the type
9362 was declared without a tag. */
9364 static const char *
9365 type_tag (type)
9366 register tree type;
9368 register const char *name = 0;
9370 if (TYPE_NAME (type) != 0)
9372 register tree t = 0;
9374 /* Find the IDENTIFIER_NODE for the type name. */
9375 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9376 t = TYPE_NAME (type);
9378 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9379 a TYPE_DECL node, regardless of whether or not a `typedef' was
9380 involved. */
9381 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9382 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9383 t = DECL_NAME (TYPE_NAME (type));
9385 /* Now get the name as a string, or invent one. */
9386 if (t != 0)
9387 name = IDENTIFIER_POINTER (t);
9390 return (name == 0 || *name == '\0') ? 0 : name;
9393 /* Return the type associated with a data member, make a special check
9394 for bit field types. */
9396 static inline tree
9397 member_declared_type (member)
9398 register tree member;
9400 return (DECL_BIT_FIELD_TYPE (member)
9401 ? DECL_BIT_FIELD_TYPE (member)
9402 : TREE_TYPE (member));
9405 /* Get the decl's label, as described by its RTL. This may be different
9406 from the DECL_NAME name used in the source file. */
9408 #if 0
9409 static const char *
9410 decl_start_label (decl)
9411 register tree decl;
9413 rtx x;
9414 const char *fnname;
9415 x = DECL_RTL (decl);
9416 if (GET_CODE (x) != MEM)
9417 abort ();
9419 x = XEXP (x, 0);
9420 if (GET_CODE (x) != SYMBOL_REF)
9421 abort ();
9423 fnname = XSTR (x, 0);
9424 return fnname;
9426 #endif
9428 /* These routines generate the internal representation of the DIE's for
9429 the compilation unit. Debugging information is collected by walking
9430 the declaration trees passed in from dwarf2out_decl(). */
9432 static void
9433 gen_array_type_die (type, context_die)
9434 register tree type;
9435 register dw_die_ref context_die;
9437 register dw_die_ref scope_die = scope_die_for (type, context_die);
9438 register dw_die_ref array_die;
9439 register tree element_type;
9441 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9442 the inner array type comes before the outer array type. Thus we must
9443 call gen_type_die before we call new_die. See below also. */
9444 #ifdef MIPS_DEBUGGING_INFO
9445 gen_type_die (TREE_TYPE (type), context_die);
9446 #endif
9448 array_die = new_die (DW_TAG_array_type, scope_die);
9450 #if 0
9451 /* We default the array ordering. SDB will probably do
9452 the right things even if DW_AT_ordering is not present. It's not even
9453 an issue until we start to get into multidimensional arrays anyway. If
9454 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9455 then we'll have to put the DW_AT_ordering attribute back in. (But if
9456 and when we find out that we need to put these in, we will only do so
9457 for multidimensional arrays. */
9458 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9459 #endif
9461 #ifdef MIPS_DEBUGGING_INFO
9462 /* The SGI compilers handle arrays of unknown bound by setting
9463 AT_declaration and not emitting any subrange DIEs. */
9464 if (! TYPE_DOMAIN (type))
9465 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9466 else
9467 #endif
9468 add_subscript_info (array_die, type);
9470 add_name_attribute (array_die, type_tag (type));
9471 equate_type_number_to_die (type, array_die);
9473 /* Add representation of the type of the elements of this array type. */
9474 element_type = TREE_TYPE (type);
9476 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9477 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9478 We work around this by disabling this feature. See also
9479 add_subscript_info. */
9480 #ifndef MIPS_DEBUGGING_INFO
9481 while (TREE_CODE (element_type) == ARRAY_TYPE)
9482 element_type = TREE_TYPE (element_type);
9484 gen_type_die (element_type, context_die);
9485 #endif
9487 add_type_attribute (array_die, element_type, 0, 0, context_die);
9490 static void
9491 gen_set_type_die (type, context_die)
9492 register tree type;
9493 register dw_die_ref context_die;
9495 register dw_die_ref type_die
9496 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9498 equate_type_number_to_die (type, type_die);
9499 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9502 #if 0
9503 static void
9504 gen_entry_point_die (decl, context_die)
9505 register tree decl;
9506 register dw_die_ref context_die;
9508 register tree origin = decl_ultimate_origin (decl);
9509 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9510 if (origin != NULL)
9511 add_abstract_origin_attribute (decl_die, origin);
9512 else
9514 add_name_and_src_coords_attributes (decl_die, decl);
9515 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9516 0, 0, context_die);
9519 if (DECL_ABSTRACT (decl))
9520 equate_decl_number_to_die (decl, decl_die);
9521 else
9522 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9524 #endif
9526 /* Remember a type in the incomplete_types_list. */
9528 static void
9529 add_incomplete_type (type)
9530 tree type;
9532 if (incomplete_types == incomplete_types_allocated)
9534 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
9535 incomplete_types_list
9536 = (tree *) xrealloc (incomplete_types_list,
9537 sizeof (tree) * incomplete_types_allocated);
9540 incomplete_types_list[incomplete_types++] = type;
9543 /* Walk through the list of incomplete types again, trying once more to
9544 emit full debugging info for them. */
9546 static void
9547 retry_incomplete_types ()
9549 register tree type;
9551 while (incomplete_types)
9553 --incomplete_types;
9554 type = incomplete_types_list[incomplete_types];
9555 gen_type_die (type, comp_unit_die);
9559 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9561 static void
9562 gen_inlined_enumeration_type_die (type, context_die)
9563 register tree type;
9564 register dw_die_ref context_die;
9566 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9567 context_die);
9568 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9569 be incomplete and such types are not marked. */
9570 add_abstract_origin_attribute (type_die, type);
9573 /* Generate a DIE to represent an inlined instance of a structure type. */
9575 static void
9576 gen_inlined_structure_type_die (type, context_die)
9577 register tree type;
9578 register dw_die_ref context_die;
9580 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9582 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9583 be incomplete and such types are not marked. */
9584 add_abstract_origin_attribute (type_die, type);
9587 /* Generate a DIE to represent an inlined instance of a union type. */
9589 static void
9590 gen_inlined_union_type_die (type, context_die)
9591 register tree type;
9592 register dw_die_ref context_die;
9594 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9596 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9597 be incomplete and such types are not marked. */
9598 add_abstract_origin_attribute (type_die, type);
9601 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9602 include all of the information about the enumeration values also. Each
9603 enumerated type name/value is listed as a child of the enumerated type
9604 DIE. */
9606 static void
9607 gen_enumeration_type_die (type, context_die)
9608 register tree type;
9609 register dw_die_ref context_die;
9611 register dw_die_ref type_die = lookup_type_die (type);
9613 if (type_die == NULL)
9615 type_die = new_die (DW_TAG_enumeration_type,
9616 scope_die_for (type, context_die));
9617 equate_type_number_to_die (type, type_die);
9618 add_name_attribute (type_die, type_tag (type));
9620 else if (! TYPE_SIZE (type))
9621 return;
9622 else
9623 remove_AT (type_die, DW_AT_declaration);
9625 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9626 given enum type is incomplete, do not generate the DW_AT_byte_size
9627 attribute or the DW_AT_element_list attribute. */
9628 if (TYPE_SIZE (type))
9630 register tree link;
9632 TREE_ASM_WRITTEN (type) = 1;
9633 add_byte_size_attribute (type_die, type);
9634 if (TYPE_STUB_DECL (type) != NULL_TREE)
9635 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9637 /* If the first reference to this type was as the return type of an
9638 inline function, then it may not have a parent. Fix this now. */
9639 if (type_die->die_parent == NULL)
9640 add_child_die (scope_die_for (type, context_die), type_die);
9642 for (link = TYPE_FIELDS (type);
9643 link != NULL; link = TREE_CHAIN (link))
9645 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9647 add_name_attribute (enum_die,
9648 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9650 if (host_integerp (TREE_VALUE (link), 0))
9652 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9653 add_AT_int (enum_die, DW_AT_const_value,
9654 tree_low_cst (TREE_VALUE (link), 0));
9655 else
9656 add_AT_unsigned (enum_die, DW_AT_const_value,
9657 tree_low_cst (TREE_VALUE (link), 0));
9661 else
9662 add_AT_flag (type_die, DW_AT_declaration, 1);
9665 /* Generate a DIE to represent either a real live formal parameter decl or to
9666 represent just the type of some formal parameter position in some function
9667 type.
9669 Note that this routine is a bit unusual because its argument may be a
9670 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9671 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9672 node. If it's the former then this function is being called to output a
9673 DIE to represent a formal parameter object (or some inlining thereof). If
9674 it's the latter, then this function is only being called to output a
9675 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9676 argument type of some subprogram type. */
9678 static dw_die_ref
9679 gen_formal_parameter_die (node, context_die)
9680 register tree node;
9681 register dw_die_ref context_die;
9683 register dw_die_ref parm_die
9684 = new_die (DW_TAG_formal_parameter, context_die);
9685 register tree origin;
9687 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9689 case 'd':
9690 origin = decl_ultimate_origin (node);
9691 if (origin != NULL)
9692 add_abstract_origin_attribute (parm_die, origin);
9693 else
9695 add_name_and_src_coords_attributes (parm_die, node);
9696 add_type_attribute (parm_die, TREE_TYPE (node),
9697 TREE_READONLY (node),
9698 TREE_THIS_VOLATILE (node),
9699 context_die);
9700 if (DECL_ARTIFICIAL (node))
9701 add_AT_flag (parm_die, DW_AT_artificial, 1);
9704 equate_decl_number_to_die (node, parm_die);
9705 if (! DECL_ABSTRACT (node))
9706 add_location_or_const_value_attribute (parm_die, node);
9708 break;
9710 case 't':
9711 /* We were called with some kind of a ..._TYPE node. */
9712 add_type_attribute (parm_die, node, 0, 0, context_die);
9713 break;
9715 default:
9716 abort ();
9719 return parm_die;
9722 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9723 at the end of an (ANSI prototyped) formal parameters list. */
9725 static void
9726 gen_unspecified_parameters_die (decl_or_type, context_die)
9727 register tree decl_or_type ATTRIBUTE_UNUSED;
9728 register dw_die_ref context_die;
9730 new_die (DW_TAG_unspecified_parameters, context_die);
9733 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9734 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9735 parameters as specified in some function type specification (except for
9736 those which appear as part of a function *definition*). */
9738 static void
9739 gen_formal_types_die (function_or_method_type, context_die)
9740 register tree function_or_method_type;
9741 register dw_die_ref context_die;
9743 register tree link;
9744 register tree formal_type = NULL;
9745 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9747 #if 0
9748 /* In the case where we are generating a formal types list for a C++
9749 non-static member function type, skip over the first thing on the
9750 TYPE_ARG_TYPES list because it only represents the type of the hidden
9751 `this pointer'. The debugger should be able to figure out (without
9752 being explicitly told) that this non-static member function type takes a
9753 `this pointer' and should be able to figure what the type of that hidden
9754 parameter is from the DW_AT_member attribute of the parent
9755 DW_TAG_subroutine_type DIE. */
9756 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
9757 first_parm_type = TREE_CHAIN (first_parm_type);
9758 #endif
9760 /* Make our first pass over the list of formal parameter types and output a
9761 DW_TAG_formal_parameter DIE for each one. */
9762 for (link = first_parm_type; link; link = TREE_CHAIN (link))
9764 register dw_die_ref parm_die;
9766 formal_type = TREE_VALUE (link);
9767 if (formal_type == void_type_node)
9768 break;
9770 /* Output a (nameless) DIE to represent the formal parameter itself. */
9771 parm_die = gen_formal_parameter_die (formal_type, context_die);
9772 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
9773 && link == first_parm_type)
9774 add_AT_flag (parm_die, DW_AT_artificial, 1);
9777 /* If this function type has an ellipsis, add a
9778 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9779 if (formal_type != void_type_node)
9780 gen_unspecified_parameters_die (function_or_method_type, context_die);
9782 /* Make our second (and final) pass over the list of formal parameter types
9783 and output DIEs to represent those types (as necessary). */
9784 for (link = TYPE_ARG_TYPES (function_or_method_type);
9785 link;
9786 link = TREE_CHAIN (link))
9788 formal_type = TREE_VALUE (link);
9789 if (formal_type == void_type_node)
9790 break;
9792 gen_type_die (formal_type, context_die);
9796 /* We want to generate the DIE for TYPE so that we can generate the
9797 die for MEMBER, which has been defined; we will need to refer back
9798 to the member declaration nested within TYPE. If we're trying to
9799 generate minimal debug info for TYPE, processing TYPE won't do the
9800 trick; we need to attach the member declaration by hand. */
9802 static void
9803 gen_type_die_for_member (type, member, context_die)
9804 tree type, member;
9805 dw_die_ref context_die;
9807 gen_type_die (type, context_die);
9809 /* If we're trying to avoid duplicate debug info, we may not have
9810 emitted the member decl for this function. Emit it now. */
9811 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9812 && ! lookup_decl_die (member))
9814 if (decl_ultimate_origin (member))
9815 abort ();
9817 push_decl_scope (type);
9818 if (TREE_CODE (member) == FUNCTION_DECL)
9819 gen_subprogram_die (member, lookup_type_die (type));
9820 else
9821 gen_variable_die (member, lookup_type_die (type));
9822 pop_decl_scope ();
9826 /* Generate the DWARF2 info for the "abstract" instance
9827 of a function which we may later generate inlined and/or
9828 out-of-line instances of. */
9830 static void
9831 gen_abstract_function (decl)
9832 tree decl;
9834 register dw_die_ref old_die = lookup_decl_die (decl);
9835 tree save_fn;
9837 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9838 /* We've already generated the abstract instance. */
9839 return;
9841 save_fn = current_function_decl;
9842 current_function_decl = decl;
9844 set_decl_abstract_flags (decl, 1);
9845 dwarf2out_decl (decl);
9846 set_decl_abstract_flags (decl, 0);
9848 current_function_decl = save_fn;
9851 /* Generate a DIE to represent a declared function (either file-scope or
9852 block-local). */
9854 static void
9855 gen_subprogram_die (decl, context_die)
9856 register tree decl;
9857 register dw_die_ref context_die;
9859 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9860 register tree origin = decl_ultimate_origin (decl);
9861 register dw_die_ref subr_die;
9862 register rtx fp_reg;
9863 register tree fn_arg_types;
9864 register tree outer_scope;
9865 register dw_die_ref old_die = lookup_decl_die (decl);
9866 register int declaration = (current_function_decl != decl
9867 || class_scope_p (context_die));
9869 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9870 be true, if we started to generate the abstract instance of an inline,
9871 decided to output its containing class, and proceeded to emit the
9872 declaration of the inline from the member list for the class. In that
9873 case, `declaration' takes priority; we'll get back to the abstract
9874 instance when we're done with the class. */
9876 /* The class-scope declaration DIE must be the primary DIE. */
9877 if (origin && declaration && class_scope_p (context_die))
9879 origin = NULL;
9880 if (old_die)
9881 abort ();
9884 if (origin != NULL)
9886 if (declaration && ! local_scope_p (context_die))
9887 abort ();
9889 /* Fixup die_parent for the abstract instance of a nested
9890 inline function. */
9891 if (old_die && old_die->die_parent == NULL)
9892 add_child_die (context_die, old_die);
9894 subr_die = new_die (DW_TAG_subprogram, context_die);
9895 add_abstract_origin_attribute (subr_die, origin);
9897 else if (old_die && DECL_ABSTRACT (decl)
9898 && get_AT_unsigned (old_die, DW_AT_inline))
9900 /* This must be a redefinition of an extern inline function.
9901 We can just reuse the old die here. */
9902 subr_die = old_die;
9904 /* Clear out the inlined attribute and parm types. */
9905 remove_AT (subr_die, DW_AT_inline);
9906 remove_children (subr_die);
9908 else if (old_die)
9910 register unsigned file_index
9911 = lookup_filename (&decl_file_table, DECL_SOURCE_FILE (decl));
9913 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
9915 /* ??? This can happen if there is a bug in the program, for
9916 instance, if it has duplicate function definitions. Ideally,
9917 we should detect this case and ignore it. For now, if we have
9918 already reported an error, any error at all, then assume that
9919 we got here because of a input error, not a dwarf2 bug. */
9920 if (errorcount)
9921 return;
9922 abort ();
9925 /* If the definition comes from the same place as the declaration,
9926 maybe use the old DIE. We always want the DIE for this function
9927 that has the *_pc attributes to be under comp_unit_die so the
9928 debugger can find it. We also need to do this for abstract
9929 instances of inlines, since the spec requires the out-of-line copy
9930 to have the same parent. For local class methods, this doesn't
9931 apply; we just use the old DIE. */
9932 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
9933 && (DECL_ARTIFICIAL (decl)
9934 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9935 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9936 == (unsigned) DECL_SOURCE_LINE (decl)))))
9938 subr_die = old_die;
9940 /* Clear out the declaration attribute and the parm types. */
9941 remove_AT (subr_die, DW_AT_declaration);
9942 remove_children (subr_die);
9944 else
9946 subr_die = new_die (DW_TAG_subprogram, context_die);
9947 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9948 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9949 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9950 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9951 != (unsigned) DECL_SOURCE_LINE (decl))
9952 add_AT_unsigned
9953 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9956 else
9958 subr_die = new_die (DW_TAG_subprogram, context_die);
9960 if (TREE_PUBLIC (decl))
9961 add_AT_flag (subr_die, DW_AT_external, 1);
9963 add_name_and_src_coords_attributes (subr_die, decl);
9964 if (debug_info_level > DINFO_LEVEL_TERSE)
9966 register tree type = TREE_TYPE (decl);
9968 add_prototyped_attribute (subr_die, type);
9969 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9972 add_pure_or_virtual_attribute (subr_die, decl);
9973 if (DECL_ARTIFICIAL (decl))
9974 add_AT_flag (subr_die, DW_AT_artificial, 1);
9975 if (TREE_PROTECTED (decl))
9976 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9977 else if (TREE_PRIVATE (decl))
9978 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9981 if (declaration)
9983 if (! origin)
9984 add_AT_flag (subr_die, DW_AT_declaration, 1);
9986 /* The first time we see a member function, it is in the context of
9987 the class to which it belongs. We make sure of this by emitting
9988 the class first. The next time is the definition, which is
9989 handled above. The two may come from the same source text. */
9990 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9991 equate_decl_number_to_die (decl, subr_die);
9993 else if (DECL_ABSTRACT (decl))
9995 if (DECL_INLINE (decl) && !flag_no_inline)
9997 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9998 inline functions, but not for extern inline functions.
9999 We can't get this completely correct because information
10000 about whether the function was declared inline is not
10001 saved anywhere. */
10002 if (DECL_DEFER_OUTPUT (decl))
10003 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10004 else
10005 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10007 else
10008 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10010 equate_decl_number_to_die (decl, subr_die);
10012 else if (!DECL_EXTERNAL (decl))
10014 if (origin == NULL_TREE)
10015 equate_decl_number_to_die (decl, subr_die);
10017 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10018 current_funcdef_number);
10019 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10020 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10021 current_funcdef_number);
10022 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10024 add_pubname (decl, subr_die);
10025 add_arange (decl, subr_die);
10027 #ifdef MIPS_DEBUGGING_INFO
10028 /* Add a reference to the FDE for this routine. */
10029 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10030 #endif
10032 /* Define the "frame base" location for this routine. We use the
10033 frame pointer or stack pointer registers, since the RTL for local
10034 variables is relative to one of them. */
10035 fp_reg
10036 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10037 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10039 #if 0
10040 /* ??? This fails for nested inline functions, because context_display
10041 is not part of the state saved/restored for inline functions. */
10042 if (current_function_needs_context)
10043 add_AT_location_description (subr_die, DW_AT_static_link,
10044 lookup_static_chain (decl));
10045 #endif
10048 /* Now output descriptions of the arguments for this function. This gets
10049 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10050 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10051 `...' at the end of the formal parameter list. In order to find out if
10052 there was a trailing ellipsis or not, we must instead look at the type
10053 associated with the FUNCTION_DECL. This will be a node of type
10054 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10055 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10056 an ellipsis at the end. */
10058 /* In the case where we are describing a mere function declaration, all we
10059 need to do here (and all we *can* do here) is to describe the *types* of
10060 its formal parameters. */
10061 if (debug_info_level <= DINFO_LEVEL_TERSE)
10063 else if (declaration)
10064 gen_formal_types_die (TREE_TYPE (decl), subr_die);
10065 else
10067 /* Generate DIEs to represent all known formal parameters */
10068 register tree arg_decls = DECL_ARGUMENTS (decl);
10069 register tree parm;
10071 /* When generating DIEs, generate the unspecified_parameters DIE
10072 instead if we come across the arg "__builtin_va_alist" */
10073 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10074 if (TREE_CODE (parm) == PARM_DECL)
10076 if (DECL_NAME (parm)
10077 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10078 "__builtin_va_alist"))
10079 gen_unspecified_parameters_die (parm, subr_die);
10080 else
10081 gen_decl_die (parm, subr_die);
10084 /* Decide whether we need a unspecified_parameters DIE at the end.
10085 There are 2 more cases to do this for: 1) the ansi ... declaration -
10086 this is detectable when the end of the arg list is not a
10087 void_type_node 2) an unprototyped function declaration (not a
10088 definition). This just means that we have no info about the
10089 parameters at all. */
10090 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10091 if (fn_arg_types != NULL)
10093 /* this is the prototyped case, check for ... */
10094 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10095 gen_unspecified_parameters_die (decl, subr_die);
10097 else if (DECL_INITIAL (decl) == NULL_TREE)
10098 gen_unspecified_parameters_die (decl, subr_die);
10101 /* Output Dwarf info for all of the stuff within the body of the function
10102 (if it has one - it may be just a declaration). */
10103 outer_scope = DECL_INITIAL (decl);
10105 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
10106 node created to represent a function. This outermost BLOCK actually
10107 represents the outermost binding contour for the function, i.e. the
10108 contour in which the function's formal parameters and labels get
10109 declared. Curiously, it appears that the front end doesn't actually
10110 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
10111 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
10112 list for the function instead.) The BLOCK_VARS list for the
10113 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
10114 the function however, and we output DWARF info for those in
10115 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
10116 node representing the function's outermost pair of curly braces, and
10117 any blocks used for the base and member initializers of a C++
10118 constructor function. */
10119 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10121 current_function_has_inlines = 0;
10122 decls_for_scope (outer_scope, subr_die, 0);
10124 #if 0 && defined (MIPS_DEBUGGING_INFO)
10125 if (current_function_has_inlines)
10127 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10128 if (! comp_unit_has_inlines)
10130 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10131 comp_unit_has_inlines = 1;
10134 #endif
10138 /* Generate a DIE to represent a declared data object. */
10140 static void
10141 gen_variable_die (decl, context_die)
10142 register tree decl;
10143 register dw_die_ref context_die;
10145 register tree origin = decl_ultimate_origin (decl);
10146 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
10148 dw_die_ref old_die = lookup_decl_die (decl);
10149 int declaration = (DECL_EXTERNAL (decl)
10150 || class_scope_p (context_die));
10152 if (origin != NULL)
10153 add_abstract_origin_attribute (var_die, origin);
10154 /* Loop unrolling can create multiple blocks that refer to the same
10155 static variable, so we must test for the DW_AT_declaration flag. */
10156 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10157 copy decls and set the DECL_ABSTRACT flag on them instead of
10158 sharing them. */
10159 else if (old_die && TREE_STATIC (decl)
10160 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10162 /* This is a definition of a C++ class level static. */
10163 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10164 if (DECL_NAME (decl))
10166 register unsigned file_index
10167 = lookup_filename (&decl_file_table, DECL_SOURCE_FILE (decl));
10169 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10170 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10172 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10173 != (unsigned) DECL_SOURCE_LINE (decl))
10175 add_AT_unsigned (var_die, DW_AT_decl_line,
10176 DECL_SOURCE_LINE (decl));
10179 else
10181 add_name_and_src_coords_attributes (var_die, decl);
10182 add_type_attribute (var_die, TREE_TYPE (decl),
10183 TREE_READONLY (decl),
10184 TREE_THIS_VOLATILE (decl), context_die);
10186 if (TREE_PUBLIC (decl))
10187 add_AT_flag (var_die, DW_AT_external, 1);
10189 if (DECL_ARTIFICIAL (decl))
10190 add_AT_flag (var_die, DW_AT_artificial, 1);
10192 if (TREE_PROTECTED (decl))
10193 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10195 else if (TREE_PRIVATE (decl))
10196 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10199 if (declaration)
10200 add_AT_flag (var_die, DW_AT_declaration, 1);
10202 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10203 equate_decl_number_to_die (decl, var_die);
10205 if (! declaration && ! DECL_ABSTRACT (decl))
10207 add_location_or_const_value_attribute (var_die, decl);
10208 add_pubname (decl, var_die);
10210 else
10211 tree_add_const_value_attribute (var_die, decl);
10214 /* Generate a DIE to represent a label identifier. */
10216 static void
10217 gen_label_die (decl, context_die)
10218 register tree decl;
10219 register dw_die_ref context_die;
10221 register tree origin = decl_ultimate_origin (decl);
10222 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
10223 register rtx insn;
10224 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10226 if (origin != NULL)
10227 add_abstract_origin_attribute (lbl_die, origin);
10228 else
10229 add_name_and_src_coords_attributes (lbl_die, decl);
10231 if (DECL_ABSTRACT (decl))
10232 equate_decl_number_to_die (decl, lbl_die);
10233 else
10235 insn = DECL_RTL (decl);
10237 /* Deleted labels are programmer specified labels which have been
10238 eliminated because of various optimisations. We still emit them
10239 here so that it is possible to put breakpoints on them. */
10240 if (GET_CODE (insn) == CODE_LABEL
10241 || ((GET_CODE (insn) == NOTE
10242 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10244 /* When optimization is enabled (via -O) some parts of the compiler
10245 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10246 represent source-level labels which were explicitly declared by
10247 the user. This really shouldn't be happening though, so catch
10248 it if it ever does happen. */
10249 if (INSN_DELETED_P (insn))
10250 abort ();
10252 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10253 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10258 /* Generate a DIE for a lexical block. */
10260 static void
10261 gen_lexical_block_die (stmt, context_die, depth)
10262 register tree stmt;
10263 register dw_die_ref context_die;
10264 int depth;
10266 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
10267 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10269 if (! BLOCK_ABSTRACT (stmt))
10271 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10272 BLOCK_NUMBER (stmt));
10273 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10274 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10275 BLOCK_NUMBER (stmt));
10276 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10279 decls_for_scope (stmt, stmt_die, depth);
10282 /* Generate a DIE for an inlined subprogram. */
10284 static void
10285 gen_inlined_subroutine_die (stmt, context_die, depth)
10286 register tree stmt;
10287 register dw_die_ref context_die;
10288 int depth;
10290 if (! BLOCK_ABSTRACT (stmt))
10292 register dw_die_ref subr_die
10293 = new_die (DW_TAG_inlined_subroutine, context_die);
10294 register tree decl = block_ultimate_origin (stmt);
10295 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10297 /* Emit info for the abstract instance first, if we haven't yet. */
10298 gen_abstract_function (decl);
10300 add_abstract_origin_attribute (subr_die, decl);
10301 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10302 BLOCK_NUMBER (stmt));
10303 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10304 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10305 BLOCK_NUMBER (stmt));
10306 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10307 decls_for_scope (stmt, subr_die, depth);
10308 current_function_has_inlines = 1;
10312 /* Generate a DIE for a field in a record, or structure. */
10314 static void
10315 gen_field_die (decl, context_die)
10316 register tree decl;
10317 register dw_die_ref context_die;
10319 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
10321 add_name_and_src_coords_attributes (decl_die, decl);
10322 add_type_attribute (decl_die, member_declared_type (decl),
10323 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10324 context_die);
10326 /* If this is a bit field... */
10327 if (DECL_BIT_FIELD_TYPE (decl))
10329 add_byte_size_attribute (decl_die, decl);
10330 add_bit_size_attribute (decl_die, decl);
10331 add_bit_offset_attribute (decl_die, decl);
10334 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10335 add_data_member_location_attribute (decl_die, decl);
10337 if (DECL_ARTIFICIAL (decl))
10338 add_AT_flag (decl_die, DW_AT_artificial, 1);
10340 if (TREE_PROTECTED (decl))
10341 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10343 else if (TREE_PRIVATE (decl))
10344 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10347 #if 0
10348 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10349 Use modified_type_die instead.
10350 We keep this code here just in case these types of DIEs may be needed to
10351 represent certain things in other languages (e.g. Pascal) someday. */
10352 static void
10353 gen_pointer_type_die (type, context_die)
10354 register tree type;
10355 register dw_die_ref context_die;
10357 register dw_die_ref ptr_die
10358 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
10360 equate_type_number_to_die (type, ptr_die);
10361 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10362 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10365 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10366 Use modified_type_die instead.
10367 We keep this code here just in case these types of DIEs may be needed to
10368 represent certain things in other languages (e.g. Pascal) someday. */
10369 static void
10370 gen_reference_type_die (type, context_die)
10371 register tree type;
10372 register dw_die_ref context_die;
10374 register dw_die_ref ref_die
10375 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
10377 equate_type_number_to_die (type, ref_die);
10378 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10379 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10381 #endif
10383 /* Generate a DIE for a pointer to a member type. */
10384 static void
10385 gen_ptr_to_mbr_type_die (type, context_die)
10386 register tree type;
10387 register dw_die_ref context_die;
10389 register dw_die_ref ptr_die
10390 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
10392 equate_type_number_to_die (type, ptr_die);
10393 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10394 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10395 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10398 /* Generate the DIE for the compilation unit. */
10400 static dw_die_ref
10401 gen_compile_unit_die (filename)
10402 register const char *filename;
10404 register dw_die_ref die;
10405 char producer[250];
10406 const char *wd = getpwd ();
10407 int language;
10409 die = new_die (DW_TAG_compile_unit, NULL);
10410 add_name_attribute (die, filename);
10412 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10413 add_AT_string (die, DW_AT_comp_dir, wd);
10415 sprintf (producer, "%s %s", language_string, version_string);
10417 #ifdef MIPS_DEBUGGING_INFO
10418 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10419 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10420 not appear in the producer string, the debugger reaches the conclusion
10421 that the object file is stripped and has no debugging information.
10422 To get the MIPS/SGI debugger to believe that there is debugging
10423 information in the object file, we add a -g to the producer string. */
10424 if (debug_info_level > DINFO_LEVEL_TERSE)
10425 strcat (producer, " -g");
10426 #endif
10428 add_AT_string (die, DW_AT_producer, producer);
10430 if (strcmp (language_string, "GNU C++") == 0)
10431 language = DW_LANG_C_plus_plus;
10432 else if (strcmp (language_string, "GNU Ada") == 0)
10433 language = DW_LANG_Ada83;
10434 else if (strcmp (language_string, "GNU F77") == 0)
10435 language = DW_LANG_Fortran77;
10436 else if (strcmp (language_string, "GNU Pascal") == 0)
10437 language = DW_LANG_Pascal83;
10438 else if (strcmp (language_string, "GNU Java") == 0)
10439 language = DW_LANG_Java;
10440 else if (flag_traditional)
10441 language = DW_LANG_C;
10442 else
10443 language = DW_LANG_C89;
10445 add_AT_unsigned (die, DW_AT_language, language);
10447 return die;
10450 /* Generate a DIE for a string type. */
10452 static void
10453 gen_string_type_die (type, context_die)
10454 register tree type;
10455 register dw_die_ref context_die;
10457 register dw_die_ref type_die
10458 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10460 equate_type_number_to_die (type, type_die);
10462 /* Fudge the string length attribute for now. */
10464 /* TODO: add string length info.
10465 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10466 bound_representation (upper_bound, 0, 'u'); */
10469 /* Generate the DIE for a base class. */
10471 static void
10472 gen_inheritance_die (binfo, context_die)
10473 register tree binfo;
10474 register dw_die_ref context_die;
10476 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10478 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10479 add_data_member_location_attribute (die, binfo);
10481 if (TREE_VIA_VIRTUAL (binfo))
10482 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10483 if (TREE_VIA_PUBLIC (binfo))
10484 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10485 else if (TREE_VIA_PROTECTED (binfo))
10486 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10489 /* Generate a DIE for a class member. */
10491 static void
10492 gen_member_die (type, context_die)
10493 register tree type;
10494 register dw_die_ref context_die;
10496 register tree member;
10497 dw_die_ref child;
10499 /* If this is not an incomplete type, output descriptions of each of its
10500 members. Note that as we output the DIEs necessary to represent the
10501 members of this record or union type, we will also be trying to output
10502 DIEs to represent the *types* of those members. However the `type'
10503 function (above) will specifically avoid generating type DIEs for member
10504 types *within* the list of member DIEs for this (containing) type execpt
10505 for those types (of members) which are explicitly marked as also being
10506 members of this (containing) type themselves. The g++ front- end can
10507 force any given type to be treated as a member of some other
10508 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10509 to point to the TREE node representing the appropriate (containing)
10510 type. */
10512 /* First output info about the base classes. */
10513 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10515 register tree bases = TYPE_BINFO_BASETYPES (type);
10516 register int n_bases = TREE_VEC_LENGTH (bases);
10517 register int i;
10519 for (i = 0; i < n_bases; i++)
10520 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10523 /* Now output info about the data members and type members. */
10524 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10526 /* If we thought we were generating minimal debug info for TYPE
10527 and then changed our minds, some of the member declarations
10528 may have already been defined. Don't define them again, but
10529 do put them in the right order. */
10531 child = lookup_decl_die (member);
10532 if (child)
10533 splice_child_die (context_die, child);
10534 else
10535 gen_decl_die (member, context_die);
10538 /* Now output info about the function members (if any). */
10539 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10541 child = lookup_decl_die (member);
10542 if (child)
10543 splice_child_die (context_die, child);
10544 else
10545 gen_decl_die (member, context_die);
10549 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10550 is set, we pretend that the type was never defined, so we only get the
10551 member DIEs needed by later specification DIEs. */
10553 static void
10554 gen_struct_or_union_type_die (type, context_die)
10555 register tree type;
10556 register dw_die_ref context_die;
10558 register dw_die_ref type_die = lookup_type_die (type);
10559 register dw_die_ref scope_die = 0;
10560 register int nested = 0;
10561 int complete = (TYPE_SIZE (type)
10562 && (! TYPE_STUB_DECL (type)
10563 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10565 if (type_die && ! complete)
10566 return;
10568 if (TYPE_CONTEXT (type) != NULL_TREE
10569 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10570 nested = 1;
10572 scope_die = scope_die_for (type, context_die);
10574 if (! type_die || (nested && scope_die == comp_unit_die))
10575 /* First occurrence of type or toplevel definition of nested class. */
10577 register dw_die_ref old_die = type_die;
10579 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10580 ? DW_TAG_structure_type : DW_TAG_union_type,
10581 scope_die);
10582 equate_type_number_to_die (type, type_die);
10583 if (old_die)
10584 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10585 else
10586 add_name_attribute (type_die, type_tag (type));
10588 else
10589 remove_AT (type_die, DW_AT_declaration);
10591 /* If this type has been completed, then give it a byte_size attribute and
10592 then give a list of members. */
10593 if (complete)
10595 /* Prevent infinite recursion in cases where the type of some member of
10596 this type is expressed in terms of this type itself. */
10597 TREE_ASM_WRITTEN (type) = 1;
10598 add_byte_size_attribute (type_die, type);
10599 if (TYPE_STUB_DECL (type) != NULL_TREE)
10600 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10602 /* If the first reference to this type was as the return type of an
10603 inline function, then it may not have a parent. Fix this now. */
10604 if (type_die->die_parent == NULL)
10605 add_child_die (scope_die, type_die);
10607 push_decl_scope (type);
10608 gen_member_die (type, type_die);
10609 pop_decl_scope ();
10611 /* GNU extension: Record what type our vtable lives in. */
10612 if (TYPE_VFIELD (type))
10614 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10616 gen_type_die (vtype, context_die);
10617 add_AT_die_ref (type_die, DW_AT_containing_type,
10618 lookup_type_die (vtype));
10621 else
10623 add_AT_flag (type_die, DW_AT_declaration, 1);
10625 /* We don't need to do this for function-local types. */
10626 if (! decl_function_context (TYPE_STUB_DECL (type)))
10627 add_incomplete_type (type);
10631 /* Generate a DIE for a subroutine _type_. */
10633 static void
10634 gen_subroutine_type_die (type, context_die)
10635 register tree type;
10636 register dw_die_ref context_die;
10638 register tree return_type = TREE_TYPE (type);
10639 register dw_die_ref subr_die
10640 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10642 equate_type_number_to_die (type, subr_die);
10643 add_prototyped_attribute (subr_die, type);
10644 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10645 gen_formal_types_die (type, subr_die);
10648 /* Generate a DIE for a type definition */
10650 static void
10651 gen_typedef_die (decl, context_die)
10652 register tree decl;
10653 register dw_die_ref context_die;
10655 register dw_die_ref type_die;
10656 register tree origin;
10658 if (TREE_ASM_WRITTEN (decl))
10659 return;
10660 TREE_ASM_WRITTEN (decl) = 1;
10662 type_die = new_die (DW_TAG_typedef, context_die);
10663 origin = decl_ultimate_origin (decl);
10664 if (origin != NULL)
10665 add_abstract_origin_attribute (type_die, origin);
10666 else
10668 register tree type;
10669 add_name_and_src_coords_attributes (type_die, decl);
10670 if (DECL_ORIGINAL_TYPE (decl))
10672 type = DECL_ORIGINAL_TYPE (decl);
10674 if (type == TREE_TYPE (decl))
10675 abort ();
10676 else
10677 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10679 else
10680 type = TREE_TYPE (decl);
10681 add_type_attribute (type_die, type, TREE_READONLY (decl),
10682 TREE_THIS_VOLATILE (decl), context_die);
10685 if (DECL_ABSTRACT (decl))
10686 equate_decl_number_to_die (decl, type_die);
10689 /* Generate a type description DIE. */
10691 static void
10692 gen_type_die (type, context_die)
10693 register tree type;
10694 register dw_die_ref context_die;
10696 int need_pop;
10698 if (type == NULL_TREE || type == error_mark_node)
10699 return;
10701 /* We are going to output a DIE to represent the unqualified version of
10702 this type (i.e. without any const or volatile qualifiers) so get the
10703 main variant (i.e. the unqualified version) of this type now. */
10704 type = type_main_variant (type);
10706 if (TREE_ASM_WRITTEN (type))
10707 return;
10709 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10710 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10712 TREE_ASM_WRITTEN (type) = 1;
10713 gen_decl_die (TYPE_NAME (type), context_die);
10714 return;
10717 switch (TREE_CODE (type))
10719 case ERROR_MARK:
10720 break;
10722 case POINTER_TYPE:
10723 case REFERENCE_TYPE:
10724 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10725 ensures that the gen_type_die recursion will terminate even if the
10726 type is recursive. Recursive types are possible in Ada. */
10727 /* ??? We could perhaps do this for all types before the switch
10728 statement. */
10729 TREE_ASM_WRITTEN (type) = 1;
10731 /* For these types, all that is required is that we output a DIE (or a
10732 set of DIEs) to represent the "basis" type. */
10733 gen_type_die (TREE_TYPE (type), context_die);
10734 break;
10736 case OFFSET_TYPE:
10737 /* This code is used for C++ pointer-to-data-member types.
10738 Output a description of the relevant class type. */
10739 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10741 /* Output a description of the type of the object pointed to. */
10742 gen_type_die (TREE_TYPE (type), context_die);
10744 /* Now output a DIE to represent this pointer-to-data-member type
10745 itself. */
10746 gen_ptr_to_mbr_type_die (type, context_die);
10747 break;
10749 case SET_TYPE:
10750 gen_type_die (TYPE_DOMAIN (type), context_die);
10751 gen_set_type_die (type, context_die);
10752 break;
10754 case FILE_TYPE:
10755 gen_type_die (TREE_TYPE (type), context_die);
10756 abort (); /* No way to represent these in Dwarf yet! */
10757 break;
10759 case FUNCTION_TYPE:
10760 /* Force out return type (in case it wasn't forced out already). */
10761 gen_type_die (TREE_TYPE (type), context_die);
10762 gen_subroutine_type_die (type, context_die);
10763 break;
10765 case METHOD_TYPE:
10766 /* Force out return type (in case it wasn't forced out already). */
10767 gen_type_die (TREE_TYPE (type), context_die);
10768 gen_subroutine_type_die (type, context_die);
10769 break;
10771 case ARRAY_TYPE:
10772 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10774 gen_type_die (TREE_TYPE (type), context_die);
10775 gen_string_type_die (type, context_die);
10777 else
10778 gen_array_type_die (type, context_die);
10779 break;
10781 case VECTOR_TYPE:
10782 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10783 break;
10785 case ENUMERAL_TYPE:
10786 case RECORD_TYPE:
10787 case UNION_TYPE:
10788 case QUAL_UNION_TYPE:
10789 /* If this is a nested type whose containing class hasn't been
10790 written out yet, writing it out will cover this one, too.
10791 This does not apply to instantiations of member class templates;
10792 they need to be added to the containing class as they are
10793 generated. FIXME: This hurts the idea of combining type decls
10794 from multiple TUs, since we can't predict what set of template
10795 instantiations we'll get. */
10796 if (TYPE_CONTEXT (type)
10797 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10798 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10800 gen_type_die (TYPE_CONTEXT (type), context_die);
10802 if (TREE_ASM_WRITTEN (type))
10803 return;
10805 /* If that failed, attach ourselves to the stub. */
10806 push_decl_scope (TYPE_CONTEXT (type));
10807 context_die = lookup_type_die (TYPE_CONTEXT (type));
10808 need_pop = 1;
10810 else
10811 need_pop = 0;
10813 if (TREE_CODE (type) == ENUMERAL_TYPE)
10814 gen_enumeration_type_die (type, context_die);
10815 else
10816 gen_struct_or_union_type_die (type, context_die);
10818 if (need_pop)
10819 pop_decl_scope ();
10821 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10822 it up if it is ever completed. gen_*_type_die will set it for us
10823 when appropriate. */
10824 return;
10826 case VOID_TYPE:
10827 case INTEGER_TYPE:
10828 case REAL_TYPE:
10829 case COMPLEX_TYPE:
10830 case BOOLEAN_TYPE:
10831 case CHAR_TYPE:
10832 /* No DIEs needed for fundamental types. */
10833 break;
10835 case LANG_TYPE:
10836 /* No Dwarf representation currently defined. */
10837 break;
10839 default:
10840 abort ();
10843 TREE_ASM_WRITTEN (type) = 1;
10846 /* Generate a DIE for a tagged type instantiation. */
10848 static void
10849 gen_tagged_type_instantiation_die (type, context_die)
10850 register tree type;
10851 register dw_die_ref context_die;
10853 if (type == NULL_TREE || type == error_mark_node)
10854 return;
10856 /* We are going to output a DIE to represent the unqualified version of
10857 this type (i.e. without any const or volatile qualifiers) so make sure
10858 that we have the main variant (i.e. the unqualified version) of this
10859 type now. */
10860 if (type != type_main_variant (type))
10861 abort ();
10863 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10864 an instance of an unresolved type. */
10866 switch (TREE_CODE (type))
10868 case ERROR_MARK:
10869 break;
10871 case ENUMERAL_TYPE:
10872 gen_inlined_enumeration_type_die (type, context_die);
10873 break;
10875 case RECORD_TYPE:
10876 gen_inlined_structure_type_die (type, context_die);
10877 break;
10879 case UNION_TYPE:
10880 case QUAL_UNION_TYPE:
10881 gen_inlined_union_type_die (type, context_die);
10882 break;
10884 default:
10885 abort ();
10889 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10890 things which are local to the given block. */
10892 static void
10893 gen_block_die (stmt, context_die, depth)
10894 register tree stmt;
10895 register dw_die_ref context_die;
10896 int depth;
10898 register int must_output_die = 0;
10899 register tree origin;
10900 register tree decl;
10901 register enum tree_code origin_code;
10903 /* Ignore blocks never really used to make RTL. */
10905 if (stmt == NULL_TREE || !TREE_USED (stmt)
10906 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10907 return;
10909 /* Determine the "ultimate origin" of this block. This block may be an
10910 inlined instance of an inlined instance of inline function, so we have
10911 to trace all of the way back through the origin chain to find out what
10912 sort of node actually served as the original seed for the creation of
10913 the current block. */
10914 origin = block_ultimate_origin (stmt);
10915 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10917 /* Determine if we need to output any Dwarf DIEs at all to represent this
10918 block. */
10919 if (origin_code == FUNCTION_DECL)
10920 /* The outer scopes for inlinings *must* always be represented. We
10921 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10922 must_output_die = 1;
10923 else
10925 /* In the case where the current block represents an inlining of the
10926 "body block" of an inline function, we must *NOT* output any DIE for
10927 this block because we have already output a DIE to represent the
10928 whole inlined function scope and the "body block" of any function
10929 doesn't really represent a different scope according to ANSI C
10930 rules. So we check here to make sure that this block does not
10931 represent a "body block inlining" before trying to set the
10932 `must_output_die' flag. */
10933 if (! is_body_block (origin ? origin : stmt))
10935 /* Determine if this block directly contains any "significant"
10936 local declarations which we will need to output DIEs for. */
10937 if (debug_info_level > DINFO_LEVEL_TERSE)
10938 /* We are not in terse mode so *any* local declaration counts
10939 as being a "significant" one. */
10940 must_output_die = (BLOCK_VARS (stmt) != NULL);
10941 else
10942 /* We are in terse mode, so only local (nested) function
10943 definitions count as "significant" local declarations. */
10944 for (decl = BLOCK_VARS (stmt);
10945 decl != NULL; decl = TREE_CHAIN (decl))
10946 if (TREE_CODE (decl) == FUNCTION_DECL
10947 && DECL_INITIAL (decl))
10949 must_output_die = 1;
10950 break;
10955 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10956 DIE for any block which contains no significant local declarations at
10957 all. Rather, in such cases we just call `decls_for_scope' so that any
10958 needed Dwarf info for any sub-blocks will get properly generated. Note
10959 that in terse mode, our definition of what constitutes a "significant"
10960 local declaration gets restricted to include only inlined function
10961 instances and local (nested) function definitions. */
10962 if (must_output_die)
10964 if (origin_code == FUNCTION_DECL)
10965 gen_inlined_subroutine_die (stmt, context_die, depth);
10966 else
10967 gen_lexical_block_die (stmt, context_die, depth);
10969 else
10970 decls_for_scope (stmt, context_die, depth);
10973 /* Generate all of the decls declared within a given scope and (recursively)
10974 all of its sub-blocks. */
10976 static void
10977 decls_for_scope (stmt, context_die, depth)
10978 register tree stmt;
10979 register dw_die_ref context_die;
10980 int depth;
10982 register tree decl;
10983 register tree subblocks;
10985 /* Ignore blocks never really used to make RTL. */
10986 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10987 return;
10989 /* Output the DIEs to represent all of the data objects and typedefs
10990 declared directly within this block but not within any nested
10991 sub-blocks. Also, nested function and tag DIEs have been
10992 generated with a parent of NULL; fix that up now. */
10993 for (decl = BLOCK_VARS (stmt);
10994 decl != NULL; decl = TREE_CHAIN (decl))
10996 register dw_die_ref die;
10998 if (TREE_CODE (decl) == FUNCTION_DECL)
10999 die = lookup_decl_die (decl);
11000 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11001 die = lookup_type_die (TREE_TYPE (decl));
11002 else
11003 die = NULL;
11005 if (die != NULL && die->die_parent == NULL)
11006 add_child_die (context_die, die);
11007 else
11008 gen_decl_die (decl, context_die);
11011 /* Output the DIEs to represent all sub-blocks (and the items declared
11012 therein) of this block. */
11013 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11014 subblocks != NULL;
11015 subblocks = BLOCK_CHAIN (subblocks))
11016 gen_block_die (subblocks, context_die, depth + 1);
11019 /* Is this a typedef we can avoid emitting? */
11021 static inline int
11022 is_redundant_typedef (decl)
11023 register tree decl;
11025 if (TYPE_DECL_IS_STUB (decl))
11026 return 1;
11028 if (DECL_ARTIFICIAL (decl)
11029 && DECL_CONTEXT (decl)
11030 && is_tagged_type (DECL_CONTEXT (decl))
11031 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11032 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11033 /* Also ignore the artificial member typedef for the class name. */
11034 return 1;
11036 return 0;
11039 /* Generate Dwarf debug information for a decl described by DECL. */
11041 static void
11042 gen_decl_die (decl, context_die)
11043 register tree decl;
11044 register dw_die_ref context_die;
11046 register tree origin;
11048 if (TREE_CODE (decl) == ERROR_MARK)
11049 return;
11051 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11052 if (DECL_IGNORED_P (decl))
11053 return;
11055 switch (TREE_CODE (decl))
11057 case CONST_DECL:
11058 /* The individual enumerators of an enum type get output when we output
11059 the Dwarf representation of the relevant enum type itself. */
11060 break;
11062 case FUNCTION_DECL:
11063 /* Don't output any DIEs to represent mere function declarations,
11064 unless they are class members or explicit block externs. */
11065 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11066 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11067 break;
11069 /* If we're emitting an out-of-line copy of an inline function,
11070 emit info for the abstract instance and set up to refer to it. */
11071 if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11072 && ! class_scope_p (context_die)
11073 /* gen_abstract_function won't emit a die if this is just a
11074 declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11075 that case, because that works only if we have a die. */
11076 && DECL_INITIAL (decl) != NULL_TREE)
11078 gen_abstract_function (decl);
11079 set_decl_origin_self (decl);
11082 if (debug_info_level > DINFO_LEVEL_TERSE)
11084 /* Before we describe the FUNCTION_DECL itself, make sure that we
11085 have described its return type. */
11086 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11088 /* And its virtual context. */
11089 if (DECL_VINDEX (decl) != NULL_TREE)
11090 gen_type_die (DECL_CONTEXT (decl), context_die);
11092 /* And its containing type. */
11093 origin = decl_class_context (decl);
11094 if (origin != NULL_TREE)
11095 gen_type_die_for_member (origin, decl, context_die);
11098 /* Now output a DIE to represent the function itself. */
11099 gen_subprogram_die (decl, context_die);
11100 break;
11102 case TYPE_DECL:
11103 /* If we are in terse mode, don't generate any DIEs to represent any
11104 actual typedefs. */
11105 if (debug_info_level <= DINFO_LEVEL_TERSE)
11106 break;
11108 /* In the special case of a TYPE_DECL node representing the
11109 declaration of some type tag, if the given TYPE_DECL is marked as
11110 having been instantiated from some other (original) TYPE_DECL node
11111 (e.g. one which was generated within the original definition of an
11112 inline function) we have to generate a special (abbreviated)
11113 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
11114 DIE here. */
11115 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11117 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11118 break;
11121 if (is_redundant_typedef (decl))
11122 gen_type_die (TREE_TYPE (decl), context_die);
11123 else
11124 /* Output a DIE to represent the typedef itself. */
11125 gen_typedef_die (decl, context_die);
11126 break;
11128 case LABEL_DECL:
11129 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11130 gen_label_die (decl, context_die);
11131 break;
11133 case VAR_DECL:
11134 /* If we are in terse mode, don't generate any DIEs to represent any
11135 variable declarations or definitions. */
11136 if (debug_info_level <= DINFO_LEVEL_TERSE)
11137 break;
11139 /* Output any DIEs that are needed to specify the type of this data
11140 object. */
11141 gen_type_die (TREE_TYPE (decl), context_die);
11143 /* And its containing type. */
11144 origin = decl_class_context (decl);
11145 if (origin != NULL_TREE)
11146 gen_type_die_for_member (origin, decl, context_die);
11148 /* Now output the DIE to represent the data object itself. This gets
11149 complicated because of the possibility that the VAR_DECL really
11150 represents an inlined instance of a formal parameter for an inline
11151 function. */
11152 origin = decl_ultimate_origin (decl);
11153 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11154 gen_formal_parameter_die (decl, context_die);
11155 else
11156 gen_variable_die (decl, context_die);
11157 break;
11159 case FIELD_DECL:
11160 /* Ignore the nameless fields that are used to skip bits, but
11161 handle C++ anonymous unions. */
11162 if (DECL_NAME (decl) != NULL_TREE
11163 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11165 gen_type_die (member_declared_type (decl), context_die);
11166 gen_field_die (decl, context_die);
11168 break;
11170 case PARM_DECL:
11171 gen_type_die (TREE_TYPE (decl), context_die);
11172 gen_formal_parameter_die (decl, context_die);
11173 break;
11175 case NAMESPACE_DECL:
11176 /* Ignore for now. */
11177 break;
11179 default:
11180 abort ();
11184 /* Add Ada "use" clause information for SGI Workshop debugger. */
11186 void
11187 dwarf2out_add_library_unit_info (filename, context_list)
11188 const char *filename;
11189 const char *context_list;
11191 unsigned int file_index;
11193 if (filename != NULL)
11195 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
11196 tree context_list_decl
11197 = build_decl (LABEL_DECL, get_identifier (context_list),
11198 void_type_node);
11200 TREE_PUBLIC (context_list_decl) = TRUE;
11201 add_name_attribute (unit_die, context_list);
11202 file_index = lookup_filename (&decl_file_table, filename);
11203 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11204 add_pubname (context_list_decl, unit_die);
11208 /* Write the debugging output for DECL. */
11210 void
11211 dwarf2out_decl (decl)
11212 register tree decl;
11214 register dw_die_ref context_die = comp_unit_die;
11216 if (TREE_CODE (decl) == ERROR_MARK)
11217 return;
11219 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11220 if (DECL_IGNORED_P (decl))
11221 return;
11223 switch (TREE_CODE (decl))
11225 case FUNCTION_DECL:
11226 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11227 builtin function. Explicit programmer-supplied declarations of
11228 these same functions should NOT be ignored however. */
11229 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11230 return;
11232 /* What we would really like to do here is to filter out all mere
11233 file-scope declarations of file-scope functions which are never
11234 referenced later within this translation unit (and keep all of ones
11235 that *are* referenced later on) but we aren't clairvoyant, so we have
11236 no idea which functions will be referenced in the future (i.e. later
11237 on within the current translation unit). So here we just ignore all
11238 file-scope function declarations which are not also definitions. If
11239 and when the debugger needs to know something about these functions,
11240 it will have to hunt around and find the DWARF information associated
11241 with the definition of the function. Note that we can't just check
11242 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
11243 definitions and which ones represent mere declarations. We have to
11244 check `DECL_INITIAL' instead. That's because the C front-end
11245 supports some weird semantics for "extern inline" function
11246 definitions. These can get inlined within the current translation
11247 unit (an thus, we need to generate DWARF info for their abstract
11248 instances so that the DWARF info for the concrete inlined instances
11249 can have something to refer to) but the compiler never generates any
11250 out-of-lines instances of such things (despite the fact that they
11251 *are* definitions). The important point is that the C front-end
11252 marks these "extern inline" functions as DECL_EXTERNAL, but we need
11253 to generate DWARF for them anyway. Note that the C++ front-end also
11254 plays some similar games for inline function definitions appearing
11255 within include files which also contain
11256 `#pragma interface' pragmas. */
11257 if (DECL_INITIAL (decl) == NULL_TREE)
11258 return;
11260 /* If we're a nested function, initially use a parent of NULL; if we're
11261 a plain function, this will be fixed up in decls_for_scope. If
11262 we're a method, it will be ignored, since we already have a DIE. */
11263 if (decl_function_context (decl))
11264 context_die = NULL;
11266 break;
11268 case VAR_DECL:
11269 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11270 declaration and if the declaration was never even referenced from
11271 within this entire compilation unit. We suppress these DIEs in
11272 order to save space in the .debug section (by eliminating entries
11273 which are probably useless). Note that we must not suppress
11274 block-local extern declarations (whether used or not) because that
11275 would screw-up the debugger's name lookup mechanism and cause it to
11276 miss things which really ought to be in scope at a given point. */
11277 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11278 return;
11280 /* If we are in terse mode, don't generate any DIEs to represent any
11281 variable declarations or definitions. */
11282 if (debug_info_level <= DINFO_LEVEL_TERSE)
11283 return;
11284 break;
11286 case TYPE_DECL:
11287 /* Don't emit stubs for types unless they are needed by other DIEs. */
11288 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11289 return;
11291 /* Don't bother trying to generate any DIEs to represent any of the
11292 normal built-in types for the language we are compiling. */
11293 if (DECL_SOURCE_LINE (decl) == 0)
11295 /* OK, we need to generate one for `bool' so GDB knows what type
11296 comparisons have. */
11297 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11298 == DW_LANG_C_plus_plus)
11299 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
11300 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11302 return;
11305 /* If we are in terse mode, don't generate any DIEs for types. */
11306 if (debug_info_level <= DINFO_LEVEL_TERSE)
11307 return;
11309 /* If we're a function-scope tag, initially use a parent of NULL;
11310 this will be fixed up in decls_for_scope. */
11311 if (decl_function_context (decl))
11312 context_die = NULL;
11314 break;
11316 default:
11317 return;
11320 gen_decl_die (decl, context_die);
11323 /* Output a marker (i.e. a label) for the beginning of the generated code for
11324 a lexical block. */
11326 void
11327 dwarf2out_begin_block (blocknum)
11328 register unsigned blocknum;
11330 function_section (current_function_decl);
11331 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11334 /* Output a marker (i.e. a label) for the end of the generated code for a
11335 lexical block. */
11337 void
11338 dwarf2out_end_block (blocknum)
11339 register unsigned blocknum;
11341 function_section (current_function_decl);
11342 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11345 /* Returns nonzero if it is appropriate not to emit any debugging
11346 information for BLOCK, because it doesn't contain any instructions.
11348 Don't allow this for blocks with nested functions or local classes
11349 as we would end up with orphans, and in the presence of scheduling
11350 we may end up calling them anyway. */
11353 dwarf2out_ignore_block (block)
11354 tree block;
11356 tree decl;
11357 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11358 if (TREE_CODE (decl) == FUNCTION_DECL
11359 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11360 return 0;
11361 return 1;
11364 /* Lookup a filename (in the list of filenames that we know about here in
11365 dwarf2out.c) and return its "index". The index of each (known) filename is
11366 just a unique number which is associated with only that one filename.
11367 We need such numbers for the sake of generating labels
11368 (in the .debug_sfnames section) and references to those
11369 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
11370 If the filename given as an argument is not found in our current list,
11371 add it to the list and assign it the next available unique index number.
11372 In order to speed up searches, we remember the index of the filename
11373 was looked up last. This handles the majority of all searches. */
11375 static unsigned
11376 lookup_filename (t, file_name)
11377 struct file_table *t;
11378 const char *file_name;
11380 register unsigned i;
11382 /* Check to see if the file name that was searched on the previous
11383 call matches this file name. If so, return the index. */
11384 if (t->last_lookup_index != 0)
11385 if (strcmp (file_name, t->table[t->last_lookup_index]) == 0)
11386 return t->last_lookup_index;
11388 /* Didn't match the previous lookup, search the table */
11389 for (i = 1; i < t->in_use; ++i)
11390 if (strcmp (file_name, t->table[i]) == 0)
11392 t->last_lookup_index = i;
11393 return i;
11396 /* Prepare to add a new table entry by making sure there is enough space in
11397 the table to do so. If not, expand the current table. */
11398 if (i == t->allocated)
11400 t->allocated = i + FILE_TABLE_INCREMENT;
11401 t->table = (char **)
11402 xrealloc (t->table, t->allocated * sizeof (char *));
11405 /* Add the new entry to the end of the filename table. */
11406 t->table[i] = xstrdup (file_name);
11407 t->in_use = i + 1;
11408 t->last_lookup_index = i;
11410 return i;
11413 static void
11414 init_file_table (t)
11415 struct file_table *t;
11417 /* Allocate the initial hunk of the file_table. */
11418 t->table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11419 t->allocated = FILE_TABLE_INCREMENT;
11421 /* Skip the first entry - file numbers begin at 1. */
11422 t->in_use = 1;
11423 t->last_lookup_index = 0;
11426 /* Output a label to mark the beginning of a source code line entry
11427 and record information relating to this source line, in
11428 'line_info_table' for later output of the .debug_line section. */
11430 void
11431 dwarf2out_line (filename, line)
11432 register const char *filename;
11433 register unsigned line;
11435 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11437 function_section (current_function_decl);
11439 if (DWARF2_ASM_LINE_DEBUG_INFO)
11441 #if 0
11442 unsigned old_in_use = line_file_table.in_use;
11443 #endif
11444 unsigned file_num = lookup_filename (&line_file_table, filename);
11446 /* Emit the .file and .loc directives understood by GNU as. */
11447 #if 0
11448 /* ??? As of 2000-11-25, gas has a bug in which it doesn't
11449 actually use the file number argument. It merely remembers
11450 the last .file directive emitted. */
11451 if (file_num >= old_in_use)
11452 fprintf (asm_out_file, "\t.file %d \"%s\"\n", file_num, filename);
11453 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11454 #else
11455 static unsigned int last_file_num;
11456 if (file_num != last_file_num)
11458 last_file_num = file_num;
11459 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
11461 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
11462 #endif
11464 /* Indicate that line number info exists. */
11465 ++line_info_table_in_use;
11467 /* Indicate that multiple line number tables exist. */
11468 if (DECL_SECTION_NAME (current_function_decl))
11469 ++separate_line_info_table_in_use;
11471 else if (DECL_SECTION_NAME (current_function_decl))
11473 register dw_separate_line_info_ref line_info;
11474 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11475 separate_line_info_table_in_use);
11476 if (flag_debug_asm)
11477 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
11478 fputc ('\n', asm_out_file);
11480 /* expand the line info table if necessary */
11481 if (separate_line_info_table_in_use
11482 == separate_line_info_table_allocated)
11484 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11485 separate_line_info_table
11486 = (dw_separate_line_info_ref)
11487 xrealloc (separate_line_info_table,
11488 separate_line_info_table_allocated
11489 * sizeof (dw_separate_line_info_entry));
11492 /* Add the new entry at the end of the line_info_table. */
11493 line_info
11494 = &separate_line_info_table[separate_line_info_table_in_use++];
11495 line_info->dw_file_num = lookup_filename (&line_file_table, filename);
11496 line_info->dw_line_num = line;
11497 line_info->function = current_funcdef_number;
11499 else
11501 register dw_line_info_ref line_info;
11503 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11504 line_info_table_in_use);
11505 if (flag_debug_asm)
11506 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
11507 fputc ('\n', asm_out_file);
11509 /* Expand the line info table if necessary. */
11510 if (line_info_table_in_use == line_info_table_allocated)
11512 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11513 line_info_table
11514 = (dw_line_info_ref)
11515 xrealloc (line_info_table,
11516 (line_info_table_allocated
11517 * sizeof (dw_line_info_entry)));
11520 /* Add the new entry at the end of the line_info_table. */
11521 line_info = &line_info_table[line_info_table_in_use++];
11522 line_info->dw_file_num = lookup_filename (&line_file_table, filename);
11523 line_info->dw_line_num = line;
11528 /* Record the beginning of a new source file, for later output
11529 of the .debug_macinfo section. At present, unimplemented. */
11531 void
11532 dwarf2out_start_source_file (filename)
11533 register const char *filename ATTRIBUTE_UNUSED;
11535 if (flag_eliminate_dwarf2_dups)
11537 /* Record the beginning of the file for break_out_includes. */
11538 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11539 add_AT_string (bincl_die, DW_AT_name, filename);
11543 /* Record the end of a source file, for later output
11544 of the .debug_macinfo section. At present, unimplemented. */
11546 void
11547 dwarf2out_end_source_file ()
11549 if (flag_eliminate_dwarf2_dups)
11551 /* Record the end of the file for break_out_includes. */
11552 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11556 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11557 the tail part of the directive line, i.e. the part which is past the
11558 initial whitespace, #, whitespace, directive-name, whitespace part. */
11560 void
11561 dwarf2out_define (lineno, buffer)
11562 register unsigned lineno ATTRIBUTE_UNUSED;
11563 register const char *buffer ATTRIBUTE_UNUSED;
11565 static int initialized = 0;
11566 if (!initialized)
11568 dwarf2out_start_source_file (primary_filename);
11569 initialized = 1;
11573 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11574 the tail part of the directive line, i.e. the part which is past the
11575 initial whitespace, #, whitespace, directive-name, whitespace part. */
11577 void
11578 dwarf2out_undef (lineno, buffer)
11579 register unsigned lineno ATTRIBUTE_UNUSED;
11580 register const char *buffer ATTRIBUTE_UNUSED;
11584 /* Set up for Dwarf output at the start of compilation. */
11586 void
11587 dwarf2out_init (asm_out_file, main_input_filename)
11588 register FILE *asm_out_file;
11589 register const char *main_input_filename;
11591 /* Remember the name of the primary input file. */
11592 primary_filename = main_input_filename;
11594 init_file_table (&decl_file_table);
11595 init_file_table (&line_file_table);
11597 /* Allocate the initial hunk of the decl_die_table. */
11598 decl_die_table
11599 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11600 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11601 decl_die_table_in_use = 0;
11603 /* Allocate the initial hunk of the decl_scope_table. */
11604 decl_scope_table
11605 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11606 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11607 decl_scope_depth = 0;
11609 /* Allocate the initial hunk of the abbrev_die_table. */
11610 abbrev_die_table
11611 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11612 sizeof (dw_die_ref));
11613 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11614 /* Zero-th entry is allocated, but unused */
11615 abbrev_die_table_in_use = 1;
11617 /* Allocate the initial hunk of the line_info_table. */
11618 line_info_table
11619 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11620 sizeof (dw_line_info_entry));
11621 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11622 /* Zero-th entry is allocated, but unused */
11623 line_info_table_in_use = 1;
11625 /* Generate the initial DIE for the .debug section. Note that the (string)
11626 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11627 will (typically) be a relative pathname and that this pathname should be
11628 taken as being relative to the directory from which the compiler was
11629 invoked when the given (base) source file was compiled. */
11630 comp_unit_die = gen_compile_unit_die (main_input_filename);
11632 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11633 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11635 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11636 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
11637 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11638 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11639 else
11640 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11641 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11642 DEBUG_INFO_SECTION_LABEL, 0);
11643 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11644 DEBUG_LINE_SECTION_LABEL, 0);
11646 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11647 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11648 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11650 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11651 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11653 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
11654 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11655 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11656 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11659 /* Output stuff that dwarf requires at the end of every file,
11660 and generate the DWARF-2 debugging info. */
11662 void
11663 dwarf2out_finish ()
11665 limbo_die_node *node, *next_node;
11666 dw_die_ref die;
11668 /* Traverse the limbo die list, and add parent/child links. The only
11669 dies without parents that should be here are concrete instances of
11670 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11671 For concrete instances, we can get the parent die from the abstract
11672 instance. */
11673 for (node = limbo_die_list; node; node = next_node)
11675 next_node = node->next;
11676 die = node->die;
11678 if (die->die_parent == NULL)
11680 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11681 if (origin)
11682 add_child_die (origin->die_parent, die);
11683 else if (die == comp_unit_die)
11685 else
11686 abort ();
11688 free (node);
11690 limbo_die_list = NULL;
11692 /* Walk through the list of incomplete types again, trying once more to
11693 emit full debugging info for them. */
11694 retry_incomplete_types ();
11696 /* We need to reverse all the dies before break_out_includes, or
11697 we'll see the end of an include file before the beginning. */
11698 reverse_all_dies (comp_unit_die);
11700 /* Generate separate CUs for each of the include files we've seen.
11701 They will go into limbo_die_list. */
11702 if (flag_eliminate_dwarf2_dups)
11703 break_out_includes (comp_unit_die);
11705 /* Traverse the DIE's and add add sibling attributes to those DIE's
11706 that have children. */
11707 add_sibling_attributes (comp_unit_die);
11708 for (node = limbo_die_list; node; node = node->next)
11709 add_sibling_attributes (node->die);
11711 /* Output a terminator label for the .text section. */
11712 fputc ('\n', asm_out_file);
11713 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11714 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11716 #if 0
11717 /* Output a terminator label for the .data section. */
11718 fputc ('\n', asm_out_file);
11719 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11720 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11722 /* Output a terminator label for the .bss section. */
11723 fputc ('\n', asm_out_file);
11724 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11725 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11726 #endif
11728 /* Output the source line correspondence table. */
11729 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
11731 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11733 fputc ('\n', asm_out_file);
11734 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11735 output_line_info ();
11738 /* We can only use the low/high_pc attributes if all of the code
11739 was in .text. */
11740 if (separate_line_info_table_in_use == 0)
11742 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11743 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11746 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11747 debug_line_section_label);
11750 #if 0 /* unimplemented */
11751 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
11752 add_AT_unsigned (die, DW_AT_macro_info, 0);
11753 #endif
11755 /* Output all of the compilation units. We put the main one last so that
11756 the offsets are available to output_pubnames. */
11757 for (node = limbo_die_list; node; node = node->next)
11758 output_comp_unit (node->die);
11759 output_comp_unit (comp_unit_die);
11761 /* Output the abbreviation table. */
11762 fputc ('\n', asm_out_file);
11763 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11764 output_abbrev_section ();
11766 if (pubname_table_in_use)
11768 /* Output public names table. */
11769 fputc ('\n', asm_out_file);
11770 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
11771 output_pubnames ();
11774 /* We only put functions in the arange table, so don't write it out if
11775 we don't have any. */
11776 if (fde_table_in_use)
11778 /* Output the address range information. */
11779 fputc ('\n', asm_out_file);
11780 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
11781 output_aranges ();
11784 #endif /* DWARF2_DEBUGGING_INFO */