2000-05-02 Jeff Sturm <jsturm@one-point.com>
[official-gcc.git] / gcc / dwarf2out.c
blobdb839323df84a40a41b069abb480dd2c65d1f13e
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 "function.h"
48 #include "output.h"
49 #include "expr.h"
50 #include "except.h"
51 #include "dwarf2.h"
52 #include "dwarf2out.h"
53 #include "dwarf2asm.h"
54 #include "toplev.h"
55 #include "varray.h"
56 #include "ggc.h"
57 #include "md5.h"
58 #include "tm_p.h"
60 /* DWARF2 Abbreviation Glossary:
61 CFA = Canonical Frame Address
62 a fixed address on the stack which identifies a call frame.
63 We define it to be the value of SP just before the call insn.
64 The CFA register and offset, which may change during the course
65 of the function, are used to calculate its value at runtime.
66 CFI = Call Frame Instruction
67 an instruction for the DWARF2 abstract machine
68 CIE = Common Information Entry
69 information describing information common to one or more FDEs
70 DIE = Debugging Information Entry
71 FDE = Frame Description Entry
72 information describing the stack call frame, in particular,
73 how to restore registers
75 DW_CFA_... = DWARF2 CFA call frame instruction
76 DW_TAG_... = DWARF2 DIE tag */
78 /* Decide whether we want to emit frame unwind information for the current
79 translation unit. */
81 int
82 dwarf2out_do_frame ()
84 return (write_symbols == DWARF2_DEBUG
85 #ifdef DWARF2_FRAME_INFO
86 || DWARF2_FRAME_INFO
87 #endif
88 #ifdef DWARF2_UNWIND_INFO
89 || flag_unwind_tables
90 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
91 #endif
95 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
97 /* How to start an assembler comment. */
98 #ifndef ASM_COMMENT_START
99 #define ASM_COMMENT_START ";#"
100 #endif
102 typedef struct dw_cfi_struct *dw_cfi_ref;
103 typedef struct dw_fde_struct *dw_fde_ref;
104 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
106 /* Call frames are described using a sequence of Call Frame
107 Information instructions. The register number, offset
108 and address fields are provided as possible operands;
109 their use is selected by the opcode field. */
111 typedef union dw_cfi_oprnd_struct
113 unsigned long dw_cfi_reg_num;
114 long int dw_cfi_offset;
115 const char *dw_cfi_addr;
116 struct dw_loc_descr_struct *dw_cfi_loc;
118 dw_cfi_oprnd;
120 typedef struct dw_cfi_struct
122 dw_cfi_ref dw_cfi_next;
123 enum dwarf_call_frame_info dw_cfi_opc;
124 dw_cfi_oprnd dw_cfi_oprnd1;
125 dw_cfi_oprnd dw_cfi_oprnd2;
127 dw_cfi_node;
129 /* This is how we define the location of the CFA. We use to handle it
130 as REG + OFFSET all the time, but now it can be more complex.
131 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
132 Instead of passing around REG and OFFSET, we pass a copy
133 of this structure. */
134 typedef struct cfa_loc
136 unsigned long reg;
137 long offset;
138 long base_offset;
139 int indirect; /* 1 if CFA is accessed via a dereference. */
140 } dw_cfa_location;
142 /* All call frame descriptions (FDE's) in the GCC generated DWARF
143 refer to a single Common Information Entry (CIE), defined at
144 the beginning of the .debug_frame section. This used of a single
145 CIE obviates the need to keep track of multiple CIE's
146 in the DWARF generation routines below. */
148 typedef struct dw_fde_struct
150 const char *dw_fde_begin;
151 const char *dw_fde_current_label;
152 const char *dw_fde_end;
153 dw_cfi_ref dw_fde_cfi;
154 unsigned funcdef_number;
155 unsigned nothrow : 1;
156 unsigned uses_eh_lsda : 1;
158 dw_fde_node;
160 /* Maximum size (in bytes) of an artificially generated label. */
161 #define MAX_ARTIFICIAL_LABEL_BYTES 30
163 /* The size of the target's pointer type. */
164 #ifndef PTR_SIZE
165 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
166 #endif
168 /* The size of addresses as they appear in the Dwarf 2 data.
169 Some architectures use word addresses to refer to code locations,
170 but Dwarf 2 info always uses byte addresses. On such machines,
171 Dwarf 2 addresses need to be larger than the architecture's
172 pointers. */
173 #ifndef DWARF2_ADDR_SIZE
174 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
175 #endif
177 /* The size in bytes of a DWARF field indicating an offset or length
178 relative to a debug info section, specified to be 4 bytes in the
179 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
180 as PTR_SIZE. */
182 #ifndef DWARF_OFFSET_SIZE
183 #define DWARF_OFFSET_SIZE 4
184 #endif
186 #define DWARF_VERSION 2
188 /* Round SIZE up to the nearest BOUNDARY. */
189 #define DWARF_ROUND(SIZE,BOUNDARY) \
190 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
192 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
193 #ifndef DWARF_CIE_DATA_ALIGNMENT
194 #ifdef STACK_GROWS_DOWNWARD
195 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
196 #else
197 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
198 #endif
199 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
201 /* A pointer to the base of a table that contains frame description
202 information for each routine. */
203 static dw_fde_ref fde_table;
205 /* Number of elements currently allocated for fde_table. */
206 static unsigned fde_table_allocated;
208 /* Number of elements in fde_table currently in use. */
209 static unsigned fde_table_in_use;
211 /* Size (in elements) of increments by which we may expand the
212 fde_table. */
213 #define FDE_TABLE_INCREMENT 256
215 /* A list of call frame insns for the CIE. */
216 static dw_cfi_ref cie_cfi_head;
218 /* The number of the current function definition for which debugging
219 information is being generated. These numbers range from 1 up to the
220 maximum number of function definitions contained within the current
221 compilation unit. These numbers are used to create unique label id's
222 unique to each function definition. */
223 unsigned current_funcdef_number = 0;
225 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
226 attribute that accelerates the lookup of the FDE associated
227 with the subprogram. This variable holds the table index of the FDE
228 associated with the current function (body) definition. */
229 static unsigned current_funcdef_fde;
231 /* Forward declarations for functions defined in this file. */
233 static char *stripattributes PARAMS ((const char *));
234 static const char *dwarf_cfi_name PARAMS ((unsigned));
235 static dw_cfi_ref new_cfi PARAMS ((void));
236 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
237 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
238 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
239 static void lookup_cfa PARAMS ((dw_cfa_location *));
240 static void reg_save PARAMS ((const char *, unsigned,
241 unsigned, long));
242 static void initial_return_save PARAMS ((rtx));
243 static long stack_adjust_offset PARAMS ((rtx));
244 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
245 static void output_call_frame_info PARAMS ((int));
246 static void dwarf2out_stack_adjust PARAMS ((rtx));
247 static void queue_reg_save PARAMS ((const char *, rtx, long));
248 static void flush_queued_reg_saves PARAMS ((void));
249 static bool clobbers_queued_reg_save PARAMS ((rtx));
250 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
252 /* Support for complex CFA locations. */
253 static void output_cfa_loc PARAMS ((dw_cfi_ref));
254 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
255 struct dw_loc_descr_struct *));
256 static struct dw_loc_descr_struct *build_cfa_loc
257 PARAMS ((dw_cfa_location *));
258 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
260 /* How to start an assembler comment. */
261 #ifndef ASM_COMMENT_START
262 #define ASM_COMMENT_START ";#"
263 #endif
265 /* Data and reference forms for relocatable data. */
266 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
267 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
269 /* Pseudo-op for defining a new section. */
270 #ifndef SECTION_ASM_OP
271 #define SECTION_ASM_OP "\t.section\t"
272 #endif
274 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
275 print the SECTION_ASM_OP and the section name. The default here works for
276 almost all svr4 assemblers, except for the sparc, where the section name
277 must be enclosed in double quotes. (See sparcv4.h). */
278 #ifndef SECTION_FORMAT
279 #ifdef PUSHSECTION_FORMAT
280 #define SECTION_FORMAT PUSHSECTION_FORMAT
281 #else
282 #define SECTION_FORMAT "%s%s\n"
283 #endif
284 #endif
286 #ifndef FRAME_SECTION
287 #define FRAME_SECTION ".debug_frame"
288 #endif
290 #ifndef FUNC_BEGIN_LABEL
291 #define FUNC_BEGIN_LABEL "LFB"
292 #endif
293 #ifndef FUNC_END_LABEL
294 #define FUNC_END_LABEL "LFE"
295 #endif
296 #define CIE_AFTER_SIZE_LABEL "LSCIE"
297 #define CIE_END_LABEL "LECIE"
298 #define CIE_LENGTH_LABEL "LLCIE"
299 #define FDE_LABEL "LSFDE"
300 #define FDE_AFTER_SIZE_LABEL "LASFDE"
301 #define FDE_END_LABEL "LEFDE"
302 #define FDE_LENGTH_LABEL "LLFDE"
303 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
304 #define LINE_NUMBER_END_LABEL "LELT"
305 #define LN_PROLOG_AS_LABEL "LASLTP"
306 #define LN_PROLOG_END_LABEL "LELTP"
307 #define DIE_LABEL_PREFIX "DW"
309 /* Definitions of defaults for various types of primitive assembly language
310 output operations. These may be overridden from within the tm.h file,
311 but typically, that is unnecessary. */
313 #ifndef ASM_OUTPUT_SECTION
314 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
315 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
316 #endif
318 #ifdef SET_ASM_OP
319 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
320 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
321 do { \
322 fprintf (FILE, "%s", SET_ASM_OP); \
323 assemble_name (FILE, SY); \
324 fputc (',', FILE); \
325 assemble_name (FILE, HI); \
326 fputc ('-', FILE); \
327 assemble_name (FILE, LO); \
328 } while (0)
329 #endif
330 #endif /* SET_ASM_OP */
332 /* The DWARF 2 CFA column which tracks the return address. Normally this
333 is the column for PC, or the first column after all of the hard
334 registers. */
335 #ifndef DWARF_FRAME_RETURN_COLUMN
336 #ifdef PC_REGNUM
337 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
338 #else
339 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
340 #endif
341 #endif
343 /* The mapping from gcc register number to DWARF 2 CFA column number. By
344 default, we just provide columns for all registers. */
345 #ifndef DWARF_FRAME_REGNUM
346 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
347 #endif
349 /* Hook used by __throw. */
352 expand_builtin_dwarf_fp_regnum ()
354 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
357 /* The offset from the incoming value of %sp to the top of the stack frame
358 for the current function. */
359 #ifndef INCOMING_FRAME_SP_OFFSET
360 #define INCOMING_FRAME_SP_OFFSET 0
361 #endif
363 /* Return a pointer to a copy of the section string name S with all
364 attributes stripped off, and an asterisk prepended (for assemble_name). */
366 static inline char *
367 stripattributes (s)
368 const char *s;
370 char *stripped = xmalloc (strlen (s) + 2);
371 char *p = stripped;
373 *p++ = '*';
375 while (*s && *s != ',')
376 *p++ = *s++;
378 *p = '\0';
379 return stripped;
382 /* Generate code to initialize the register size table. */
384 void
385 expand_builtin_init_dwarf_reg_sizes (address)
386 tree address;
388 int i;
389 enum machine_mode mode = TYPE_MODE (char_type_node);
390 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
391 rtx mem = gen_rtx_MEM (mode, addr);
393 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
395 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
396 int size = GET_MODE_SIZE (reg_raw_mode[i]);
398 if (offset < 0)
399 continue;
401 emit_move_insn (change_address (mem, mode,
402 plus_constant (addr, offset)),
403 GEN_INT (size));
407 /* Convert a DWARF call frame info. operation to its string name */
409 static const char *
410 dwarf_cfi_name (cfi_opc)
411 register unsigned cfi_opc;
413 switch (cfi_opc)
415 case DW_CFA_advance_loc:
416 return "DW_CFA_advance_loc";
417 case DW_CFA_offset:
418 return "DW_CFA_offset";
419 case DW_CFA_restore:
420 return "DW_CFA_restore";
421 case DW_CFA_nop:
422 return "DW_CFA_nop";
423 case DW_CFA_set_loc:
424 return "DW_CFA_set_loc";
425 case DW_CFA_advance_loc1:
426 return "DW_CFA_advance_loc1";
427 case DW_CFA_advance_loc2:
428 return "DW_CFA_advance_loc2";
429 case DW_CFA_advance_loc4:
430 return "DW_CFA_advance_loc4";
431 case DW_CFA_offset_extended:
432 return "DW_CFA_offset_extended";
433 case DW_CFA_restore_extended:
434 return "DW_CFA_restore_extended";
435 case DW_CFA_undefined:
436 return "DW_CFA_undefined";
437 case DW_CFA_same_value:
438 return "DW_CFA_same_value";
439 case DW_CFA_register:
440 return "DW_CFA_register";
441 case DW_CFA_remember_state:
442 return "DW_CFA_remember_state";
443 case DW_CFA_restore_state:
444 return "DW_CFA_restore_state";
445 case DW_CFA_def_cfa:
446 return "DW_CFA_def_cfa";
447 case DW_CFA_def_cfa_register:
448 return "DW_CFA_def_cfa_register";
449 case DW_CFA_def_cfa_offset:
450 return "DW_CFA_def_cfa_offset";
451 case DW_CFA_def_cfa_expression:
452 return "DW_CFA_def_cfa_expression";
454 /* SGI/MIPS specific */
455 case DW_CFA_MIPS_advance_loc8:
456 return "DW_CFA_MIPS_advance_loc8";
458 /* GNU extensions */
459 case DW_CFA_GNU_window_save:
460 return "DW_CFA_GNU_window_save";
461 case DW_CFA_GNU_args_size:
462 return "DW_CFA_GNU_args_size";
463 case DW_CFA_GNU_negative_offset_extended:
464 return "DW_CFA_GNU_negative_offset_extended";
466 default:
467 return "DW_CFA_<unknown>";
471 /* Return a pointer to a newly allocated Call Frame Instruction. */
473 static inline dw_cfi_ref
474 new_cfi ()
476 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
478 cfi->dw_cfi_next = NULL;
479 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
480 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
482 return cfi;
485 /* Add a Call Frame Instruction to list of instructions. */
487 static inline void
488 add_cfi (list_head, cfi)
489 register dw_cfi_ref *list_head;
490 register dw_cfi_ref cfi;
492 register dw_cfi_ref *p;
494 /* Find the end of the chain. */
495 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
498 *p = cfi;
501 /* Generate a new label for the CFI info to refer to. */
503 char *
504 dwarf2out_cfi_label ()
506 static char label[20];
507 static unsigned long label_num = 0;
509 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
510 ASM_OUTPUT_LABEL (asm_out_file, label);
512 return label;
515 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
516 or to the CIE if LABEL is NULL. */
518 static void
519 add_fde_cfi (label, cfi)
520 register const char *label;
521 register dw_cfi_ref cfi;
523 if (label)
525 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
527 if (*label == 0)
528 label = dwarf2out_cfi_label ();
530 if (fde->dw_fde_current_label == NULL
531 || strcmp (label, fde->dw_fde_current_label) != 0)
533 register dw_cfi_ref xcfi;
535 fde->dw_fde_current_label = label = xstrdup (label);
537 /* Set the location counter to the new label. */
538 xcfi = new_cfi ();
539 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
540 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
541 add_cfi (&fde->dw_fde_cfi, xcfi);
544 add_cfi (&fde->dw_fde_cfi, cfi);
547 else
548 add_cfi (&cie_cfi_head, cfi);
551 /* Subroutine of lookup_cfa. */
553 static inline void
554 lookup_cfa_1 (cfi, loc)
555 register dw_cfi_ref cfi;
556 register dw_cfa_location *loc;
558 switch (cfi->dw_cfi_opc)
560 case DW_CFA_def_cfa_offset:
561 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
562 break;
563 case DW_CFA_def_cfa_register:
564 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
565 break;
566 case DW_CFA_def_cfa:
567 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
568 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
569 break;
570 case DW_CFA_def_cfa_expression:
571 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
572 break;
573 default:
574 break;
578 /* Find the previous value for the CFA. */
580 static void
581 lookup_cfa (loc)
582 register dw_cfa_location *loc;
584 register dw_cfi_ref cfi;
586 loc->reg = (unsigned long) -1;
587 loc->offset = 0;
588 loc->indirect = 0;
589 loc->base_offset = 0;
591 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
592 lookup_cfa_1 (cfi, loc);
594 if (fde_table_in_use)
596 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
597 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
598 lookup_cfa_1 (cfi, loc);
602 /* The current rule for calculating the DWARF2 canonical frame address. */
603 static dw_cfa_location cfa;
605 /* The register used for saving registers to the stack, and its offset
606 from the CFA. */
607 static dw_cfa_location cfa_store;
609 /* The running total of the size of arguments pushed onto the stack. */
610 static long args_size;
612 /* The last args_size we actually output. */
613 static long old_args_size;
615 /* Entry point to update the canonical frame address (CFA).
616 LABEL is passed to add_fde_cfi. The value of CFA is now to be
617 calculated from REG+OFFSET. */
619 void
620 dwarf2out_def_cfa (label, reg, offset)
621 register const char *label;
622 unsigned reg;
623 long offset;
625 dw_cfa_location loc;
626 loc.indirect = 0;
627 loc.base_offset = 0;
628 loc.reg = reg;
629 loc.offset = offset;
630 def_cfa_1 (label, &loc);
633 /* This routine does the actual work. The CFA is now calculated from
634 the dw_cfa_location structure. */
635 static void
636 def_cfa_1 (label, loc_p)
637 register const char *label;
638 dw_cfa_location *loc_p;
640 register dw_cfi_ref cfi;
641 dw_cfa_location old_cfa, loc;
643 cfa = *loc_p;
644 loc = *loc_p;
646 if (cfa_store.reg == loc.reg && loc.indirect == 0)
647 cfa_store.offset = loc.offset;
649 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
650 lookup_cfa (&old_cfa);
652 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
653 loc.indirect == old_cfa.indirect)
655 if (loc.indirect == 0
656 || loc.base_offset == old_cfa.base_offset)
657 /* Nothing changed so no need to issue any call frame
658 instructions. */
659 return;
662 cfi = new_cfi ();
664 if (loc.reg == old_cfa.reg && !loc.indirect)
666 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
667 indicating the CFA register did not change but the offset
668 did. */
669 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
670 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
673 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
674 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
675 && !loc.indirect)
677 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
678 indicating the CFA register has changed to <register> but the
679 offset has not changed. */
680 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
681 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
683 #endif
685 else if (loc.indirect == 0)
687 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
688 indicating the CFA register has changed to <register> with
689 the specified offset. */
690 cfi->dw_cfi_opc = DW_CFA_def_cfa;
691 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
692 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
694 else
696 /* Construct a DW_CFA_def_cfa_expression instruction to
697 calculate the CFA using a full location expression since no
698 register-offset pair is available. */
699 struct dw_loc_descr_struct *loc_list;
700 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
701 loc_list = build_cfa_loc (&loc);
702 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
705 add_fde_cfi (label, cfi);
708 /* Add the CFI for saving a register. REG is the CFA column number.
709 LABEL is passed to add_fde_cfi.
710 If SREG is -1, the register is saved at OFFSET from the CFA;
711 otherwise it is saved in SREG. */
713 static void
714 reg_save (label, reg, sreg, offset)
715 register const char *label;
716 register unsigned reg;
717 register unsigned sreg;
718 register long offset;
720 register dw_cfi_ref cfi = new_cfi ();
722 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
724 /* The following comparison is correct. -1 is used to indicate that
725 the value isn't a register number. */
726 if (sreg == (unsigned int) -1)
728 if (reg & ~0x3f)
729 /* The register number won't fit in 6 bits, so we have to use
730 the long form. */
731 cfi->dw_cfi_opc = DW_CFA_offset_extended;
732 else
733 cfi->dw_cfi_opc = DW_CFA_offset;
735 #ifdef ENABLE_CHECKING
737 /* If we get an offset that is not a multiple of
738 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
739 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
740 description. */
741 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
743 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
744 abort ();
746 #endif
747 offset /= DWARF_CIE_DATA_ALIGNMENT;
748 if (offset < 0)
750 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
751 offset = -offset;
753 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
755 else if (sreg == reg)
756 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
757 return;
758 else
760 cfi->dw_cfi_opc = DW_CFA_register;
761 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
764 add_fde_cfi (label, cfi);
767 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
768 This CFI tells the unwinder that it needs to restore the window registers
769 from the previous frame's window save area.
771 ??? Perhaps we should note in the CIE where windows are saved (instead of
772 assuming 0(cfa)) and what registers are in the window. */
774 void
775 dwarf2out_window_save (label)
776 register const char *label;
778 register dw_cfi_ref cfi = new_cfi ();
779 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
780 add_fde_cfi (label, cfi);
783 /* Add a CFI to update the running total of the size of arguments
784 pushed onto the stack. */
786 void
787 dwarf2out_args_size (label, size)
788 const char *label;
789 long size;
791 register dw_cfi_ref cfi;
793 if (size == old_args_size)
794 return;
795 old_args_size = size;
797 cfi = new_cfi ();
798 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
799 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
800 add_fde_cfi (label, cfi);
803 /* Entry point for saving a register to the stack. REG is the GCC register
804 number. LABEL and OFFSET are passed to reg_save. */
806 void
807 dwarf2out_reg_save (label, reg, offset)
808 register const char *label;
809 register unsigned reg;
810 register long offset;
812 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
815 /* Entry point for saving the return address in the stack.
816 LABEL and OFFSET are passed to reg_save. */
818 void
819 dwarf2out_return_save (label, offset)
820 register const char *label;
821 register long offset;
823 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
826 /* Entry point for saving the return address in a register.
827 LABEL and SREG are passed to reg_save. */
829 void
830 dwarf2out_return_reg (label, sreg)
831 register const char *label;
832 register unsigned sreg;
834 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
837 /* Record the initial position of the return address. RTL is
838 INCOMING_RETURN_ADDR_RTX. */
840 static void
841 initial_return_save (rtl)
842 register rtx rtl;
844 unsigned int reg = (unsigned int) -1;
845 long offset = 0;
847 switch (GET_CODE (rtl))
849 case REG:
850 /* RA is in a register. */
851 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
852 break;
853 case MEM:
854 /* RA is on the stack. */
855 rtl = XEXP (rtl, 0);
856 switch (GET_CODE (rtl))
858 case REG:
859 if (REGNO (rtl) != STACK_POINTER_REGNUM)
860 abort ();
861 offset = 0;
862 break;
863 case PLUS:
864 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
865 abort ();
866 offset = INTVAL (XEXP (rtl, 1));
867 break;
868 case MINUS:
869 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
870 abort ();
871 offset = -INTVAL (XEXP (rtl, 1));
872 break;
873 default:
874 abort ();
876 break;
877 case PLUS:
878 /* The return address is at some offset from any value we can
879 actually load. For instance, on the SPARC it is in %i7+8. Just
880 ignore the offset for now; it doesn't matter for unwinding frames. */
881 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
882 abort ();
883 initial_return_save (XEXP (rtl, 0));
884 return;
885 default:
886 abort ();
889 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
892 /* Given a SET, calculate the amount of stack adjustment it
893 contains. */
895 static long
896 stack_adjust_offset (pattern)
897 rtx pattern;
899 rtx src = SET_SRC (pattern);
900 rtx dest = SET_DEST (pattern);
901 long offset = 0;
902 enum rtx_code code;
904 if (dest == stack_pointer_rtx)
906 /* (set (reg sp) (plus (reg sp) (const_int))) */
907 code = GET_CODE (src);
908 if (! (code == PLUS || code == MINUS)
909 || XEXP (src, 0) != stack_pointer_rtx
910 || GET_CODE (XEXP (src, 1)) != CONST_INT)
911 return 0;
913 offset = INTVAL (XEXP (src, 1));
915 else if (GET_CODE (dest) == MEM)
917 /* (set (mem (pre_dec (reg sp))) (foo)) */
918 src = XEXP (dest, 0);
919 code = GET_CODE (src);
921 if (! (code == PRE_DEC || code == PRE_INC
922 || code == PRE_MODIFY)
923 || XEXP (src, 0) != stack_pointer_rtx)
924 return 0;
926 if (code == PRE_MODIFY)
928 rtx val = XEXP (XEXP (src, 1), 1);
929 /* We handle only adjustments by constant amount. */
930 if (GET_CODE (XEXP (src, 1)) != PLUS ||
931 GET_CODE (val) != CONST_INT)
932 abort();
933 offset = -INTVAL (val);
935 else offset = GET_MODE_SIZE (GET_MODE (dest));
937 else
938 return 0;
940 if (code == PLUS || code == PRE_INC)
941 offset = -offset;
943 return offset;
946 /* Check INSN to see if it looks like a push or a stack adjustment, and
947 make a note of it if it does. EH uses this information to find out how
948 much extra space it needs to pop off the stack. */
950 static void
951 dwarf2out_stack_adjust (insn)
952 rtx insn;
954 long offset;
955 const char *label;
957 if (! flag_non_call_exceptions && GET_CODE (insn) == CALL_INSN)
959 /* Extract the size of the args from the CALL rtx itself. */
961 insn = PATTERN (insn);
962 if (GET_CODE (insn) == PARALLEL)
963 insn = XVECEXP (insn, 0, 0);
964 if (GET_CODE (insn) == SET)
965 insn = SET_SRC (insn);
966 if (GET_CODE (insn) != CALL)
967 abort ();
968 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
969 return;
972 /* If only calls can throw, and we have a frame pointer,
973 save up adjustments until we see the CALL_INSN. */
974 else if (! flag_non_call_exceptions
975 && cfa.reg != STACK_POINTER_REGNUM)
976 return;
978 if (GET_CODE (insn) == BARRIER)
980 /* When we see a BARRIER, we know to reset args_size to 0. Usually
981 the compiler will have already emitted a stack adjustment, but
982 doesn't bother for calls to noreturn functions. */
983 #ifdef STACK_GROWS_DOWNWARD
984 offset = -args_size;
985 #else
986 offset = args_size;
987 #endif
989 else if (GET_CODE (PATTERN (insn)) == SET)
991 offset = stack_adjust_offset (PATTERN (insn));
993 else if (GET_CODE (PATTERN (insn)) == PARALLEL
994 || GET_CODE (PATTERN (insn)) == SEQUENCE)
996 /* There may be stack adjustments inside compound insns. Search
997 for them. */
998 int j;
1000 offset = 0;
1001 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1003 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1004 if (GET_CODE (pattern) == SET)
1005 offset += stack_adjust_offset (pattern);
1008 else
1009 return;
1011 if (offset == 0)
1012 return;
1014 if (cfa.reg == STACK_POINTER_REGNUM)
1015 cfa.offset += offset;
1017 #ifndef STACK_GROWS_DOWNWARD
1018 offset = -offset;
1019 #endif
1020 args_size += offset;
1021 if (args_size < 0)
1022 args_size = 0;
1024 label = dwarf2out_cfi_label ();
1025 def_cfa_1 (label, &cfa);
1026 dwarf2out_args_size (label, args_size);
1029 /* We delay emitting a register save until either (a) we reach the end
1030 of the prologue or (b) the register is clobbered. This clusters
1031 register saves so that there are fewer pc advances. */
1033 struct queued_reg_save
1035 struct queued_reg_save *next;
1036 rtx reg;
1037 long cfa_offset;
1040 static struct queued_reg_save *queued_reg_saves;
1041 static const char *last_reg_save_label;
1043 static void
1044 queue_reg_save (label, reg, offset)
1045 const char *label;
1046 rtx reg;
1047 long offset;
1049 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1051 q->next = queued_reg_saves;
1052 q->reg = reg;
1053 q->cfa_offset = offset;
1054 queued_reg_saves = q;
1056 last_reg_save_label = label;
1059 static void
1060 flush_queued_reg_saves ()
1062 struct queued_reg_save *q, *next;
1064 for (q = queued_reg_saves; q ; q = next)
1066 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1067 next = q->next;
1068 free (q);
1071 queued_reg_saves = NULL;
1072 last_reg_save_label = NULL;
1075 static bool
1076 clobbers_queued_reg_save (insn)
1077 rtx insn;
1079 struct queued_reg_save *q;
1081 for (q = queued_reg_saves; q ; q = q->next)
1082 if (modified_in_p (q->reg, insn))
1083 return true;
1085 return false;
1089 /* A temporary register holding an integral value used in adjusting SP
1090 or setting up the store_reg. The "offset" field holds the integer
1091 value, not an offset. */
1092 static dw_cfa_location cfa_temp;
1094 /* Record call frame debugging information for an expression EXPR,
1095 which either sets SP or FP (adjusting how we calculate the frame
1096 address) or saves a register to the stack. LABEL indicates the
1097 address of EXPR.
1099 This function encodes a state machine mapping rtxes to actions on
1100 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1101 users need not read the source code.
1103 The High-Level Picture
1105 Changes in the register we use to calculate the CFA: Currently we
1106 assume that if you copy the CFA register into another register, we
1107 should take the other one as the new CFA register; this seems to
1108 work pretty well. If it's wrong for some target, it's simple
1109 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1111 Changes in the register we use for saving registers to the stack:
1112 This is usually SP, but not always. Again, we deduce that if you
1113 copy SP into another register (and SP is not the CFA register),
1114 then the new register is the one we will be using for register
1115 saves. This also seems to work.
1117 Register saves: There's not much guesswork about this one; if
1118 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1119 register save, and the register used to calculate the destination
1120 had better be the one we think we're using for this purpose.
1122 Except: If the register being saved is the CFA register, and the
1123 offset is non-zero, we are saving the CFA, so we assume we have to
1124 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1125 the intent is to save the value of SP from the previous frame.
1127 Invariants / Summaries of Rules
1129 cfa current rule for calculating the CFA. It usually
1130 consists of a register and an offset.
1131 cfa_store register used by prologue code to save things to the stack
1132 cfa_store.offset is the offset from the value of
1133 cfa_store.reg to the actual CFA
1134 cfa_temp register holding an integral value. cfa_temp.offset
1135 stores the value, which will be used to adjust the
1136 stack pointer. cfa_temp is also used like cfa_store,
1137 to track stores to the stack via fp or a temp reg.
1139 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1140 with cfa.reg as the first operand changes the cfa.reg and its
1141 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1142 cfa_temp.offset.
1144 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1145 expression yielding a constant. This sets cfa_temp.reg
1146 and cfa_temp.offset.
1148 Rule 5: Create a new register cfa_store used to save items to the
1149 stack.
1151 Rules 10-14: Save a register to the stack. Define offset as the
1152 difference of the original location and cfa_store's
1153 location (or cfa_temp's location if cfa_temp is used).
1155 The Rules
1157 "{a,b}" indicates a choice of a xor b.
1158 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1160 Rule 1:
1161 (set <reg1> <reg2>:cfa.reg)
1162 effects: cfa.reg = <reg1>
1163 cfa.offset unchanged
1164 cfa_temp.reg = <reg1>
1165 cfa_temp.offset = cfa.offset
1167 Rule 2:
1168 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
1169 effects: cfa.reg = sp if fp used
1170 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1171 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1172 if cfa_store.reg==sp
1174 Rule 3:
1175 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1176 effects: cfa.reg = fp
1177 cfa_offset += +/- <const_int>
1179 Rule 4:
1180 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1181 constraints: <reg1> != fp
1182 <reg1> != sp
1183 effects: cfa.reg = <reg1>
1184 cfa_temp.reg = <reg1>
1185 cfa_temp.offset = cfa.offset
1187 Rule 5:
1188 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1189 constraints: <reg1> != fp
1190 <reg1> != sp
1191 effects: cfa_store.reg = <reg1>
1192 cfa_store.offset = cfa.offset - cfa_temp.offset
1194 Rule 6:
1195 (set <reg> <const_int>)
1196 effects: cfa_temp.reg = <reg>
1197 cfa_temp.offset = <const_int>
1199 Rule 7:
1200 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1201 effects: cfa_temp.reg = <reg1>
1202 cfa_temp.offset |= <const_int>
1204 Rule 8:
1205 (set <reg> (high <exp>))
1206 effects: none
1208 Rule 9:
1209 (set <reg> (lo_sum <exp> <const_int>))
1210 effects: cfa_temp.reg = <reg>
1211 cfa_temp.offset = <const_int>
1213 Rule 10:
1214 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1215 effects: cfa_store.offset -= <const_int>
1216 cfa.offset = cfa_store.offset if cfa.reg == sp
1217 cfa.reg = sp
1218 cfa.base_offset = -cfa_store.offset
1220 Rule 11:
1221 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1222 effects: cfa_store.offset += -/+ mode_size(mem)
1223 cfa.offset = cfa_store.offset if cfa.reg == sp
1224 cfa.reg = sp
1225 cfa.base_offset = -cfa_store.offset
1227 Rule 12:
1228 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) <reg2>)
1229 effects: cfa.reg = <reg1>
1230 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1232 Rule 13:
1233 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1234 effects: cfa.reg = <reg1>
1235 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1237 Rule 14:
1238 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1239 effects: cfa.reg = <reg1>
1240 cfa.base_offset = -cfa_temp.offset
1241 cfa_temp.offset -= mode_size(mem) */
1243 static void
1244 dwarf2out_frame_debug_expr (expr, label)
1245 rtx expr;
1246 const char *label;
1248 rtx src, dest;
1249 long offset;
1251 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1252 the PARALLEL independently. The first element is always processed if
1253 it is a SET. This is for backward compatibility. Other elements
1254 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1255 flag is set in them. */
1257 if (GET_CODE (expr) == PARALLEL
1258 || GET_CODE (expr) == SEQUENCE)
1260 int par_index;
1261 int limit = XVECLEN (expr, 0);
1263 for (par_index = 0; par_index < limit; par_index++)
1265 rtx x = XVECEXP (expr, 0, par_index);
1267 if (GET_CODE (x) == SET &&
1268 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1269 dwarf2out_frame_debug_expr (x, label);
1271 return;
1274 if (GET_CODE (expr) != SET)
1275 abort ();
1277 src = SET_SRC (expr);
1278 dest = SET_DEST (expr);
1280 switch (GET_CODE (dest))
1282 case REG:
1283 /* Rule 1 */
1284 /* Update the CFA rule wrt SP or FP. Make sure src is
1285 relative to the current CFA register. */
1286 switch (GET_CODE (src))
1288 /* Setting FP from SP. */
1289 case REG:
1290 if (cfa.reg == (unsigned) REGNO (src))
1291 /* OK. */
1293 else
1294 abort ();
1296 /* We used to require that dest be either SP or FP, but the
1297 ARM copies SP to a temporary register, and from there to
1298 FP. So we just rely on the backends to only set
1299 RTX_FRAME_RELATED_P on appropriate insns. */
1300 cfa.reg = REGNO (dest);
1301 cfa_temp.reg = cfa.reg;
1302 cfa_temp.offset = cfa.offset;
1303 break;
1305 case PLUS:
1306 case MINUS:
1307 case LO_SUM:
1308 if (dest == stack_pointer_rtx)
1310 /* Rule 2 */
1311 /* Adjusting SP. */
1312 switch (GET_CODE (XEXP (src, 1)))
1314 case CONST_INT:
1315 offset = INTVAL (XEXP (src, 1));
1316 break;
1317 case REG:
1318 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1319 abort ();
1320 offset = cfa_temp.offset;
1321 break;
1322 default:
1323 abort ();
1326 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1328 /* Restoring SP from FP in the epilogue. */
1329 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1330 abort ();
1331 cfa.reg = STACK_POINTER_REGNUM;
1333 else if (GET_CODE (src) == LO_SUM)
1334 /* Assume we've set the source reg of the LO_SUM from sp. */
1336 else if (XEXP (src, 0) != stack_pointer_rtx)
1337 abort ();
1339 if (GET_CODE (src) != MINUS)
1340 offset = -offset;
1341 if (cfa.reg == STACK_POINTER_REGNUM)
1342 cfa.offset += offset;
1343 if (cfa_store.reg == STACK_POINTER_REGNUM)
1344 cfa_store.offset += offset;
1346 else if (dest == hard_frame_pointer_rtx)
1348 /* Rule 3 */
1349 /* Either setting the FP from an offset of the SP,
1350 or adjusting the FP */
1351 if (! frame_pointer_needed)
1352 abort ();
1354 if (GET_CODE (XEXP (src, 0)) == REG
1355 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1356 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1358 offset = INTVAL (XEXP (src, 1));
1359 if (GET_CODE (src) != MINUS)
1360 offset = -offset;
1361 cfa.offset += offset;
1362 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1364 else
1365 abort ();
1367 else
1369 if (GET_CODE (src) == MINUS)
1370 abort ();
1372 /* Rule 4 */
1373 if (GET_CODE (XEXP (src, 0)) == REG
1374 && REGNO (XEXP (src, 0)) == cfa.reg
1375 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1377 /* Setting a temporary CFA register that will be copied
1378 into the FP later on. */
1379 offset = - INTVAL (XEXP (src, 1));
1380 cfa.offset += offset;
1381 cfa.reg = REGNO (dest);
1382 /* Or used to save regs to the stack. */
1383 cfa_temp.reg = cfa.reg;
1384 cfa_temp.offset = cfa.offset;
1386 /* Rule 5 */
1387 else if (GET_CODE (XEXP (src, 0)) == REG
1388 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1389 && XEXP (src, 1) == stack_pointer_rtx)
1391 /* Setting a scratch register that we will use instead
1392 of SP for saving registers to the stack. */
1393 if (cfa.reg != STACK_POINTER_REGNUM)
1394 abort ();
1395 cfa_store.reg = REGNO (dest);
1396 cfa_store.offset = cfa.offset - cfa_temp.offset;
1398 /* Rule 9 */
1399 else if (GET_CODE (src) == LO_SUM
1400 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1402 cfa_temp.reg = REGNO (dest);
1403 cfa_temp.offset = INTVAL (XEXP (src, 1));
1405 else
1406 abort ();
1408 break;
1410 /* Rule 6 */
1411 case CONST_INT:
1412 cfa_temp.reg = REGNO (dest);
1413 cfa_temp.offset = INTVAL (src);
1414 break;
1416 /* Rule 7 */
1417 case IOR:
1418 if (GET_CODE (XEXP (src, 0)) != REG
1419 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1420 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1421 abort ();
1422 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1423 cfa_temp.reg = REGNO (dest);
1424 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1425 break;
1427 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1428 which will fill in all of the bits. */
1429 /* Rule 8 */
1430 case HIGH:
1431 break;
1433 default:
1434 abort ();
1436 def_cfa_1 (label, &cfa);
1437 break;
1439 case MEM:
1440 if (GET_CODE (src) != REG)
1441 abort ();
1443 /* Saving a register to the stack. Make sure dest is relative to the
1444 CFA register. */
1445 switch (GET_CODE (XEXP (dest, 0)))
1447 /* Rule 10 */
1448 /* With a push. */
1449 case PRE_MODIFY:
1450 /* We can't handle variable size modifications. */
1451 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1452 abort();
1453 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1455 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1456 || cfa_store.reg != STACK_POINTER_REGNUM)
1457 abort ();
1458 cfa_store.offset += offset;
1459 if (cfa.reg == STACK_POINTER_REGNUM)
1460 cfa.offset = cfa_store.offset;
1462 offset = -cfa_store.offset;
1463 break;
1464 /* Rule 11 */
1465 case PRE_INC:
1466 case PRE_DEC:
1467 offset = GET_MODE_SIZE (GET_MODE (dest));
1468 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1469 offset = -offset;
1471 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1472 || cfa_store.reg != STACK_POINTER_REGNUM)
1473 abort ();
1474 cfa_store.offset += offset;
1475 if (cfa.reg == STACK_POINTER_REGNUM)
1476 cfa.offset = cfa_store.offset;
1478 offset = -cfa_store.offset;
1479 break;
1481 /* Rule 12 */
1482 /* With an offset. */
1483 case PLUS:
1484 case MINUS:
1485 case LO_SUM:
1486 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1487 abort ();
1488 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1489 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1490 offset = -offset;
1492 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1493 offset -= cfa_store.offset;
1494 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1495 offset -= cfa_temp.offset;
1496 else
1497 abort ();
1498 break;
1500 /* Rule 13 */
1501 /* Without an offset. */
1502 case REG:
1503 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1504 offset = -cfa_store.offset;
1505 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1506 offset = -cfa_temp.offset;
1507 else
1508 abort ();
1509 break;
1511 /* Rule 14 */
1512 case POST_INC:
1513 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1514 abort ();
1515 offset = -cfa_temp.offset;
1516 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1517 break;
1519 default:
1520 abort ();
1523 if (REGNO (src) != STACK_POINTER_REGNUM
1524 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1525 && (unsigned) REGNO (src) == cfa.reg)
1527 /* We're storing the current CFA reg into the stack. */
1529 if (cfa.offset == 0)
1531 /* If the source register is exactly the CFA, assume
1532 we're saving SP like any other register; this happens
1533 on the ARM. */
1535 def_cfa_1 (label, &cfa);
1536 queue_reg_save (label, stack_pointer_rtx, offset);
1537 break;
1539 else
1541 /* Otherwise, we'll need to look in the stack to
1542 calculate the CFA. */
1544 rtx x = XEXP (dest, 0);
1545 if (GET_CODE (x) != REG)
1546 x = XEXP (x, 0);
1547 if (GET_CODE (x) != REG)
1548 abort ();
1549 cfa.reg = (unsigned) REGNO (x);
1550 cfa.base_offset = offset;
1551 cfa.indirect = 1;
1552 def_cfa_1 (label, &cfa);
1553 break;
1557 def_cfa_1 (label, &cfa);
1558 queue_reg_save (label, src, offset);
1559 break;
1561 default:
1562 abort ();
1566 /* Record call frame debugging information for INSN, which either
1567 sets SP or FP (adjusting how we calculate the frame address) or saves a
1568 register to the stack. If INSN is NULL_RTX, initialize our state. */
1570 void
1571 dwarf2out_frame_debug (insn)
1572 rtx insn;
1574 const char *label;
1575 rtx src;
1577 if (insn == NULL_RTX)
1579 /* Flush any queued register saves. */
1580 flush_queued_reg_saves ();
1582 /* Set up state for generating call frame debug info. */
1583 lookup_cfa (&cfa);
1584 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1585 abort ();
1586 cfa.reg = STACK_POINTER_REGNUM;
1587 cfa_store = cfa;
1588 cfa_temp.reg = -1;
1589 cfa_temp.offset = 0;
1590 return;
1593 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1594 flush_queued_reg_saves ();
1596 if (! RTX_FRAME_RELATED_P (insn))
1598 if (!ACCUMULATE_OUTGOING_ARGS)
1599 dwarf2out_stack_adjust (insn);
1600 return;
1603 label = dwarf2out_cfi_label ();
1605 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1606 if (src)
1607 insn = XEXP (src, 0);
1608 else
1609 insn = PATTERN (insn);
1611 dwarf2out_frame_debug_expr (insn, label);
1614 /* Output a Call Frame Information opcode and its operand(s). */
1616 static void
1617 output_cfi (cfi, fde, for_eh)
1618 register dw_cfi_ref cfi;
1619 register dw_fde_ref fde;
1620 int for_eh;
1622 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1624 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1625 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1626 "DW_CFA_advance_loc 0x%lx",
1627 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1629 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1631 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1632 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1633 "DW_CFA_offset, column 0x%lx",
1634 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1635 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1637 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1639 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1640 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1641 "DW_CFA_restore, column 0x%lx",
1642 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1644 else
1646 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1647 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1649 switch (cfi->dw_cfi_opc)
1651 case DW_CFA_set_loc:
1652 dw2_asm_output_addr ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE),
1653 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1654 break;
1655 case DW_CFA_advance_loc1:
1656 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1657 fde->dw_fde_current_label, NULL);
1658 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1659 break;
1660 case DW_CFA_advance_loc2:
1661 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1662 fde->dw_fde_current_label, NULL);
1663 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1664 break;
1665 case DW_CFA_advance_loc4:
1666 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1667 fde->dw_fde_current_label, NULL);
1668 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1669 break;
1670 case DW_CFA_MIPS_advance_loc8:
1671 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1672 fde->dw_fde_current_label, NULL);
1673 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1674 break;
1675 case DW_CFA_offset_extended:
1676 case DW_CFA_GNU_negative_offset_extended:
1677 case DW_CFA_def_cfa:
1678 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1679 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1680 break;
1681 case DW_CFA_restore_extended:
1682 case DW_CFA_undefined:
1683 case DW_CFA_same_value:
1684 case DW_CFA_def_cfa_register:
1685 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1686 break;
1687 case DW_CFA_register:
1688 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1689 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
1690 break;
1691 case DW_CFA_def_cfa_offset:
1692 case DW_CFA_GNU_args_size:
1693 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1694 break;
1695 case DW_CFA_GNU_window_save:
1696 break;
1697 case DW_CFA_def_cfa_expression:
1698 output_cfa_loc (cfi);
1699 break;
1700 default:
1701 break;
1706 /* Output the call frame information used to used to record information
1707 that relates to calculating the frame pointer, and records the
1708 location of saved registers. */
1710 static void
1711 output_call_frame_info (for_eh)
1712 int for_eh;
1714 register unsigned long i;
1715 register dw_fde_ref fde;
1716 register dw_cfi_ref cfi;
1717 char l1[20], l2[20];
1718 int any_lsda_needed = 0;
1719 char augmentation[6];
1721 /* If we don't have any functions we'll want to unwind out of, don't
1722 emit any EH unwind information. */
1723 if (for_eh)
1725 int any_eh_needed = 0;
1726 for (i = 0; i < fde_table_in_use; ++i)
1727 if (fde_table[i].uses_eh_lsda)
1728 any_eh_needed = any_lsda_needed = 1;
1729 else if (! fde_table[i].nothrow)
1730 any_eh_needed = 1;
1732 if (! any_eh_needed)
1733 return;
1736 /* We're going to be generating comments, so turn on app. */
1737 if (flag_debug_asm)
1738 app_enable ();
1740 if (for_eh)
1742 #ifdef EH_FRAME_SECTION
1743 EH_FRAME_SECTION ();
1744 #else
1745 tree label = get_file_function_name ('F');
1747 force_data_section ();
1748 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1749 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1750 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1751 #endif
1752 assemble_label ("__FRAME_BEGIN__");
1754 else
1755 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1757 /* Output the CIE. */
1758 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1759 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1760 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1761 "Length of Common Information Entry");
1762 ASM_OUTPUT_LABEL (asm_out_file, l1);
1764 /* Now that the CIE pointer is PC-relative for EH,
1765 use 0 to identify the CIE. */
1766 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1767 (for_eh ? 0 : DW_CIE_ID),
1768 "CIE Identifier Tag");
1770 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1772 augmentation[0] = 0;
1773 if (for_eh)
1775 /* Augmentation:
1776 z Indicates that a uleb128 is present to size the
1777 augmentation section.
1778 R Indicates a pointer encoding for CIE and FDE pointers.
1779 P Indicates the presence of a language personality
1780 routine in the CIE augmentation and an LSDA in the
1781 FDE augmentation. */
1783 /* ??? Handle pointer encodings. */
1785 if (any_lsda_needed)
1786 strcpy (augmentation, "zP");
1788 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1790 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1792 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1793 "CIE Data Alignment Factor");
1795 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1797 if (augmentation[0])
1799 dw2_asm_output_data_uleb128 (PTR_SIZE, "Augmentation size");
1800 if (eh_personality_libfunc)
1801 dw2_asm_output_addr_rtx (PTR_SIZE, eh_personality_libfunc,
1802 "Personality");
1803 else
1804 dw2_asm_output_data (PTR_SIZE, 0, "Personality (none)");
1807 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1808 output_cfi (cfi, NULL, for_eh);
1810 /* Pad the CIE out to an address sized boundary. */
1811 ASM_OUTPUT_ALIGN (asm_out_file,
1812 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1813 ASM_OUTPUT_LABEL (asm_out_file, l2);
1815 /* Loop through all of the FDE's. */
1816 for (i = 0; i < fde_table_in_use; ++i)
1818 fde = &fde_table[i];
1820 /* Don't emit EH unwind info for leaf functions that don't need it. */
1821 if (for_eh && fde->nothrow && ! fde->uses_eh_lsda)
1822 continue;
1824 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1825 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1826 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1827 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1828 "FDE Length");
1829 ASM_OUTPUT_LABEL (asm_out_file, l1);
1831 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1832 emits a target dependent sized offset when for_eh is not true.
1833 This inconsistency may confuse gdb. The only case where we need a
1834 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1835 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1836 though in order to be compatible with the dwarf_fde struct in frame.c.
1837 If the for_eh case is changed, then the struct in frame.c has
1838 to be adjusted appropriately. */
1839 if (for_eh)
1840 dw2_asm_output_delta (4, l1, "__FRAME_BEGIN__", "FDE CIE offset");
1841 else
1842 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
1843 stripattributes (FRAME_SECTION),
1844 "FDE CIE offset");
1846 dw2_asm_output_addr ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE),
1847 fde->dw_fde_begin,
1848 "FDE initial location");
1850 dw2_asm_output_delta ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE),
1851 fde->dw_fde_end,
1852 fde->dw_fde_begin,
1853 "FDE address range");
1855 if (augmentation[0])
1857 dw2_asm_output_data_uleb128 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE),
1858 "Augmentation size");
1860 if (fde->uses_eh_lsda)
1862 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA", fde->funcdef_number);
1863 dw2_asm_output_offset ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE),
1864 l1, "Language Specific Data Area");
1866 else
1867 dw2_asm_output_data ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE),
1868 0, "Language Specific Data Area (none)");
1871 /* Loop through the Call Frame Instructions associated with
1872 this FDE. */
1873 fde->dw_fde_current_label = fde->dw_fde_begin;
1874 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1875 output_cfi (cfi, fde, for_eh);
1877 /* Pad the FDE out to an address sized boundary. */
1878 ASM_OUTPUT_ALIGN (asm_out_file,
1879 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
1880 ASM_OUTPUT_LABEL (asm_out_file, l2);
1883 #ifndef EH_FRAME_SECTION
1884 if (for_eh)
1885 dw2_asm_output_data (4, 0, "End of Table");
1886 #endif
1887 #ifdef MIPS_DEBUGGING_INFO
1888 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1889 get a value of 0. Putting .align 0 after the label fixes it. */
1890 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1891 #endif
1893 /* Turn off app to make assembly quicker. */
1894 if (flag_debug_asm)
1895 app_disable ();
1898 /* Output a marker (i.e. a label) for the beginning of a function, before
1899 the prologue. */
1901 void
1902 dwarf2out_begin_prologue ()
1904 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1905 register dw_fde_ref fde;
1907 current_function_func_begin_label = 0;
1909 #ifdef IA64_UNWIND_INFO
1910 /* ??? current_function_func_begin_label is also used by except.c
1911 for call-site information. We must emit this label if it might
1912 be used. */
1913 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
1914 && ! dwarf2out_do_frame ())
1915 return;
1916 #else
1917 if (! dwarf2out_do_frame ())
1918 return;
1919 #endif
1921 ++current_funcdef_number;
1923 function_section (current_function_decl);
1924 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1925 current_funcdef_number);
1926 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
1927 current_funcdef_number);
1928 current_function_func_begin_label = get_identifier (label);
1930 #ifdef IA64_UNWIND_INFO
1931 /* We can elide the fde allocation if we're not emitting debug info. */
1932 if (! dwarf2out_do_frame ())
1933 return;
1934 #endif
1936 /* Expand the fde table if necessary. */
1937 if (fde_table_in_use == fde_table_allocated)
1939 fde_table_allocated += FDE_TABLE_INCREMENT;
1940 fde_table
1941 = (dw_fde_ref) xrealloc (fde_table,
1942 fde_table_allocated * sizeof (dw_fde_node));
1945 /* Record the FDE associated with this function. */
1946 current_funcdef_fde = fde_table_in_use;
1948 /* Add the new FDE at the end of the fde_table. */
1949 fde = &fde_table[fde_table_in_use++];
1950 fde->dw_fde_begin = xstrdup (label);
1951 fde->dw_fde_current_label = NULL;
1952 fde->dw_fde_end = NULL;
1953 fde->dw_fde_cfi = NULL;
1954 fde->funcdef_number = current_funcdef_number;
1955 fde->nothrow = current_function_nothrow;
1956 fde->uses_eh_lsda = cfun->uses_eh_lsda;
1958 args_size = old_args_size = 0;
1961 /* Output a marker (i.e. a label) for the absolute end of the generated code
1962 for a function definition. This gets called *after* the epilogue code has
1963 been generated. */
1965 void
1966 dwarf2out_end_epilogue ()
1968 dw_fde_ref fde;
1969 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1971 /* Output a label to mark the endpoint of the code generated for this
1972 function. */
1973 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1974 ASM_OUTPUT_LABEL (asm_out_file, label);
1975 fde = &fde_table[fde_table_in_use - 1];
1976 fde->dw_fde_end = xstrdup (label);
1979 void
1980 dwarf2out_frame_init ()
1982 /* Allocate the initial hunk of the fde_table. */
1983 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
1984 fde_table_allocated = FDE_TABLE_INCREMENT;
1985 fde_table_in_use = 0;
1987 /* Generate the CFA instructions common to all FDE's. Do it now for the
1988 sake of lookup_cfa. */
1990 #ifdef DWARF2_UNWIND_INFO
1991 /* On entry, the Canonical Frame Address is at SP. */
1992 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
1993 initial_return_save (INCOMING_RETURN_ADDR_RTX);
1994 #endif
1997 void
1998 dwarf2out_frame_finish ()
2000 /* Output call frame information. */
2001 #ifdef MIPS_DEBUGGING_INFO
2002 if (write_symbols == DWARF2_DEBUG)
2003 output_call_frame_info (0);
2004 if (flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS))
2005 output_call_frame_info (1);
2006 #else
2007 if (write_symbols == DWARF2_DEBUG
2008 || flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS))
2009 output_call_frame_info (1);
2010 #endif
2013 /* And now, the subset of the debugging information support code necessary
2014 for emitting location expressions. */
2016 typedef struct dw_val_struct *dw_val_ref;
2017 typedef struct die_struct *dw_die_ref;
2018 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2020 /* Each DIE may have a series of attribute/value pairs. Values
2021 can take on several forms. The forms that are used in this
2022 implementation are listed below. */
2024 typedef enum
2026 dw_val_class_addr,
2027 dw_val_class_loc,
2028 dw_val_class_const,
2029 dw_val_class_unsigned_const,
2030 dw_val_class_long_long,
2031 dw_val_class_float,
2032 dw_val_class_flag,
2033 dw_val_class_die_ref,
2034 dw_val_class_fde_ref,
2035 dw_val_class_lbl_id,
2036 dw_val_class_lbl_offset,
2037 dw_val_class_str
2039 dw_val_class;
2041 /* Describe a double word constant value. */
2042 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2044 typedef struct dw_long_long_struct
2046 unsigned long hi;
2047 unsigned long low;
2049 dw_long_long_const;
2051 /* Describe a floating point constant value. */
2053 typedef struct dw_fp_struct
2055 long *array;
2056 unsigned length;
2058 dw_float_const;
2060 /* The dw_val_node describes an attribute's value, as it is
2061 represented internally. */
2063 typedef struct dw_val_struct
2065 dw_val_class val_class;
2066 union
2068 rtx val_addr;
2069 dw_loc_descr_ref val_loc;
2070 long int val_int;
2071 long unsigned val_unsigned;
2072 dw_long_long_const val_long_long;
2073 dw_float_const val_float;
2074 struct {
2075 dw_die_ref die;
2076 int external;
2077 } val_die_ref;
2078 unsigned val_fde_index;
2079 char *val_str;
2080 char *val_lbl_id;
2081 unsigned char val_flag;
2085 dw_val_node;
2087 /* Locations in memory are described using a sequence of stack machine
2088 operations. */
2090 typedef struct dw_loc_descr_struct
2092 dw_loc_descr_ref dw_loc_next;
2093 enum dwarf_location_atom dw_loc_opc;
2094 dw_val_node dw_loc_oprnd1;
2095 dw_val_node dw_loc_oprnd2;
2096 int dw_loc_addr;
2098 dw_loc_descr_node;
2100 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2101 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2102 unsigned long,
2103 unsigned long));
2104 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2105 dw_loc_descr_ref));
2106 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2107 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2108 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2109 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2111 /* Convert a DWARF stack opcode into its string name. */
2113 static const char *
2114 dwarf_stack_op_name (op)
2115 register unsigned op;
2117 switch (op)
2119 case DW_OP_addr:
2120 return "DW_OP_addr";
2121 case DW_OP_deref:
2122 return "DW_OP_deref";
2123 case DW_OP_const1u:
2124 return "DW_OP_const1u";
2125 case DW_OP_const1s:
2126 return "DW_OP_const1s";
2127 case DW_OP_const2u:
2128 return "DW_OP_const2u";
2129 case DW_OP_const2s:
2130 return "DW_OP_const2s";
2131 case DW_OP_const4u:
2132 return "DW_OP_const4u";
2133 case DW_OP_const4s:
2134 return "DW_OP_const4s";
2135 case DW_OP_const8u:
2136 return "DW_OP_const8u";
2137 case DW_OP_const8s:
2138 return "DW_OP_const8s";
2139 case DW_OP_constu:
2140 return "DW_OP_constu";
2141 case DW_OP_consts:
2142 return "DW_OP_consts";
2143 case DW_OP_dup:
2144 return "DW_OP_dup";
2145 case DW_OP_drop:
2146 return "DW_OP_drop";
2147 case DW_OP_over:
2148 return "DW_OP_over";
2149 case DW_OP_pick:
2150 return "DW_OP_pick";
2151 case DW_OP_swap:
2152 return "DW_OP_swap";
2153 case DW_OP_rot:
2154 return "DW_OP_rot";
2155 case DW_OP_xderef:
2156 return "DW_OP_xderef";
2157 case DW_OP_abs:
2158 return "DW_OP_abs";
2159 case DW_OP_and:
2160 return "DW_OP_and";
2161 case DW_OP_div:
2162 return "DW_OP_div";
2163 case DW_OP_minus:
2164 return "DW_OP_minus";
2165 case DW_OP_mod:
2166 return "DW_OP_mod";
2167 case DW_OP_mul:
2168 return "DW_OP_mul";
2169 case DW_OP_neg:
2170 return "DW_OP_neg";
2171 case DW_OP_not:
2172 return "DW_OP_not";
2173 case DW_OP_or:
2174 return "DW_OP_or";
2175 case DW_OP_plus:
2176 return "DW_OP_plus";
2177 case DW_OP_plus_uconst:
2178 return "DW_OP_plus_uconst";
2179 case DW_OP_shl:
2180 return "DW_OP_shl";
2181 case DW_OP_shr:
2182 return "DW_OP_shr";
2183 case DW_OP_shra:
2184 return "DW_OP_shra";
2185 case DW_OP_xor:
2186 return "DW_OP_xor";
2187 case DW_OP_bra:
2188 return "DW_OP_bra";
2189 case DW_OP_eq:
2190 return "DW_OP_eq";
2191 case DW_OP_ge:
2192 return "DW_OP_ge";
2193 case DW_OP_gt:
2194 return "DW_OP_gt";
2195 case DW_OP_le:
2196 return "DW_OP_le";
2197 case DW_OP_lt:
2198 return "DW_OP_lt";
2199 case DW_OP_ne:
2200 return "DW_OP_ne";
2201 case DW_OP_skip:
2202 return "DW_OP_skip";
2203 case DW_OP_lit0:
2204 return "DW_OP_lit0";
2205 case DW_OP_lit1:
2206 return "DW_OP_lit1";
2207 case DW_OP_lit2:
2208 return "DW_OP_lit2";
2209 case DW_OP_lit3:
2210 return "DW_OP_lit3";
2211 case DW_OP_lit4:
2212 return "DW_OP_lit4";
2213 case DW_OP_lit5:
2214 return "DW_OP_lit5";
2215 case DW_OP_lit6:
2216 return "DW_OP_lit6";
2217 case DW_OP_lit7:
2218 return "DW_OP_lit7";
2219 case DW_OP_lit8:
2220 return "DW_OP_lit8";
2221 case DW_OP_lit9:
2222 return "DW_OP_lit9";
2223 case DW_OP_lit10:
2224 return "DW_OP_lit10";
2225 case DW_OP_lit11:
2226 return "DW_OP_lit11";
2227 case DW_OP_lit12:
2228 return "DW_OP_lit12";
2229 case DW_OP_lit13:
2230 return "DW_OP_lit13";
2231 case DW_OP_lit14:
2232 return "DW_OP_lit14";
2233 case DW_OP_lit15:
2234 return "DW_OP_lit15";
2235 case DW_OP_lit16:
2236 return "DW_OP_lit16";
2237 case DW_OP_lit17:
2238 return "DW_OP_lit17";
2239 case DW_OP_lit18:
2240 return "DW_OP_lit18";
2241 case DW_OP_lit19:
2242 return "DW_OP_lit19";
2243 case DW_OP_lit20:
2244 return "DW_OP_lit20";
2245 case DW_OP_lit21:
2246 return "DW_OP_lit21";
2247 case DW_OP_lit22:
2248 return "DW_OP_lit22";
2249 case DW_OP_lit23:
2250 return "DW_OP_lit23";
2251 case DW_OP_lit24:
2252 return "DW_OP_lit24";
2253 case DW_OP_lit25:
2254 return "DW_OP_lit25";
2255 case DW_OP_lit26:
2256 return "DW_OP_lit26";
2257 case DW_OP_lit27:
2258 return "DW_OP_lit27";
2259 case DW_OP_lit28:
2260 return "DW_OP_lit28";
2261 case DW_OP_lit29:
2262 return "DW_OP_lit29";
2263 case DW_OP_lit30:
2264 return "DW_OP_lit30";
2265 case DW_OP_lit31:
2266 return "DW_OP_lit31";
2267 case DW_OP_reg0:
2268 return "DW_OP_reg0";
2269 case DW_OP_reg1:
2270 return "DW_OP_reg1";
2271 case DW_OP_reg2:
2272 return "DW_OP_reg2";
2273 case DW_OP_reg3:
2274 return "DW_OP_reg3";
2275 case DW_OP_reg4:
2276 return "DW_OP_reg4";
2277 case DW_OP_reg5:
2278 return "DW_OP_reg5";
2279 case DW_OP_reg6:
2280 return "DW_OP_reg6";
2281 case DW_OP_reg7:
2282 return "DW_OP_reg7";
2283 case DW_OP_reg8:
2284 return "DW_OP_reg8";
2285 case DW_OP_reg9:
2286 return "DW_OP_reg9";
2287 case DW_OP_reg10:
2288 return "DW_OP_reg10";
2289 case DW_OP_reg11:
2290 return "DW_OP_reg11";
2291 case DW_OP_reg12:
2292 return "DW_OP_reg12";
2293 case DW_OP_reg13:
2294 return "DW_OP_reg13";
2295 case DW_OP_reg14:
2296 return "DW_OP_reg14";
2297 case DW_OP_reg15:
2298 return "DW_OP_reg15";
2299 case DW_OP_reg16:
2300 return "DW_OP_reg16";
2301 case DW_OP_reg17:
2302 return "DW_OP_reg17";
2303 case DW_OP_reg18:
2304 return "DW_OP_reg18";
2305 case DW_OP_reg19:
2306 return "DW_OP_reg19";
2307 case DW_OP_reg20:
2308 return "DW_OP_reg20";
2309 case DW_OP_reg21:
2310 return "DW_OP_reg21";
2311 case DW_OP_reg22:
2312 return "DW_OP_reg22";
2313 case DW_OP_reg23:
2314 return "DW_OP_reg23";
2315 case DW_OP_reg24:
2316 return "DW_OP_reg24";
2317 case DW_OP_reg25:
2318 return "DW_OP_reg25";
2319 case DW_OP_reg26:
2320 return "DW_OP_reg26";
2321 case DW_OP_reg27:
2322 return "DW_OP_reg27";
2323 case DW_OP_reg28:
2324 return "DW_OP_reg28";
2325 case DW_OP_reg29:
2326 return "DW_OP_reg29";
2327 case DW_OP_reg30:
2328 return "DW_OP_reg30";
2329 case DW_OP_reg31:
2330 return "DW_OP_reg31";
2331 case DW_OP_breg0:
2332 return "DW_OP_breg0";
2333 case DW_OP_breg1:
2334 return "DW_OP_breg1";
2335 case DW_OP_breg2:
2336 return "DW_OP_breg2";
2337 case DW_OP_breg3:
2338 return "DW_OP_breg3";
2339 case DW_OP_breg4:
2340 return "DW_OP_breg4";
2341 case DW_OP_breg5:
2342 return "DW_OP_breg5";
2343 case DW_OP_breg6:
2344 return "DW_OP_breg6";
2345 case DW_OP_breg7:
2346 return "DW_OP_breg7";
2347 case DW_OP_breg8:
2348 return "DW_OP_breg8";
2349 case DW_OP_breg9:
2350 return "DW_OP_breg9";
2351 case DW_OP_breg10:
2352 return "DW_OP_breg10";
2353 case DW_OP_breg11:
2354 return "DW_OP_breg11";
2355 case DW_OP_breg12:
2356 return "DW_OP_breg12";
2357 case DW_OP_breg13:
2358 return "DW_OP_breg13";
2359 case DW_OP_breg14:
2360 return "DW_OP_breg14";
2361 case DW_OP_breg15:
2362 return "DW_OP_breg15";
2363 case DW_OP_breg16:
2364 return "DW_OP_breg16";
2365 case DW_OP_breg17:
2366 return "DW_OP_breg17";
2367 case DW_OP_breg18:
2368 return "DW_OP_breg18";
2369 case DW_OP_breg19:
2370 return "DW_OP_breg19";
2371 case DW_OP_breg20:
2372 return "DW_OP_breg20";
2373 case DW_OP_breg21:
2374 return "DW_OP_breg21";
2375 case DW_OP_breg22:
2376 return "DW_OP_breg22";
2377 case DW_OP_breg23:
2378 return "DW_OP_breg23";
2379 case DW_OP_breg24:
2380 return "DW_OP_breg24";
2381 case DW_OP_breg25:
2382 return "DW_OP_breg25";
2383 case DW_OP_breg26:
2384 return "DW_OP_breg26";
2385 case DW_OP_breg27:
2386 return "DW_OP_breg27";
2387 case DW_OP_breg28:
2388 return "DW_OP_breg28";
2389 case DW_OP_breg29:
2390 return "DW_OP_breg29";
2391 case DW_OP_breg30:
2392 return "DW_OP_breg30";
2393 case DW_OP_breg31:
2394 return "DW_OP_breg31";
2395 case DW_OP_regx:
2396 return "DW_OP_regx";
2397 case DW_OP_fbreg:
2398 return "DW_OP_fbreg";
2399 case DW_OP_bregx:
2400 return "DW_OP_bregx";
2401 case DW_OP_piece:
2402 return "DW_OP_piece";
2403 case DW_OP_deref_size:
2404 return "DW_OP_deref_size";
2405 case DW_OP_xderef_size:
2406 return "DW_OP_xderef_size";
2407 case DW_OP_nop:
2408 return "DW_OP_nop";
2409 default:
2410 return "OP_<unknown>";
2414 /* Return a pointer to a newly allocated location description. Location
2415 descriptions are simple expression terms that can be strung
2416 together to form more complicated location (address) descriptions. */
2418 static inline dw_loc_descr_ref
2419 new_loc_descr (op, oprnd1, oprnd2)
2420 register enum dwarf_location_atom op;
2421 register unsigned long oprnd1;
2422 register unsigned long oprnd2;
2424 /* Use xcalloc here so we clear out all of the long_long constant in
2425 the union. */
2426 register dw_loc_descr_ref descr
2427 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2429 descr->dw_loc_opc = op;
2430 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2431 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2432 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2433 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2435 return descr;
2438 /* Add a location description term to a location description expression. */
2440 static inline void
2441 add_loc_descr (list_head, descr)
2442 register dw_loc_descr_ref *list_head;
2443 register dw_loc_descr_ref descr;
2445 register dw_loc_descr_ref *d;
2447 /* Find the end of the chain. */
2448 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2451 *d = descr;
2454 /* Return the size of a location descriptor. */
2456 static unsigned long
2457 size_of_loc_descr (loc)
2458 register dw_loc_descr_ref loc;
2460 register unsigned long size = 1;
2462 switch (loc->dw_loc_opc)
2464 case DW_OP_addr:
2465 size += DWARF2_ADDR_SIZE;
2466 break;
2467 case DW_OP_const1u:
2468 case DW_OP_const1s:
2469 size += 1;
2470 break;
2471 case DW_OP_const2u:
2472 case DW_OP_const2s:
2473 size += 2;
2474 break;
2475 case DW_OP_const4u:
2476 case DW_OP_const4s:
2477 size += 4;
2478 break;
2479 case DW_OP_const8u:
2480 case DW_OP_const8s:
2481 size += 8;
2482 break;
2483 case DW_OP_constu:
2484 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2485 break;
2486 case DW_OP_consts:
2487 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2488 break;
2489 case DW_OP_pick:
2490 size += 1;
2491 break;
2492 case DW_OP_plus_uconst:
2493 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2494 break;
2495 case DW_OP_skip:
2496 case DW_OP_bra:
2497 size += 2;
2498 break;
2499 case DW_OP_breg0:
2500 case DW_OP_breg1:
2501 case DW_OP_breg2:
2502 case DW_OP_breg3:
2503 case DW_OP_breg4:
2504 case DW_OP_breg5:
2505 case DW_OP_breg6:
2506 case DW_OP_breg7:
2507 case DW_OP_breg8:
2508 case DW_OP_breg9:
2509 case DW_OP_breg10:
2510 case DW_OP_breg11:
2511 case DW_OP_breg12:
2512 case DW_OP_breg13:
2513 case DW_OP_breg14:
2514 case DW_OP_breg15:
2515 case DW_OP_breg16:
2516 case DW_OP_breg17:
2517 case DW_OP_breg18:
2518 case DW_OP_breg19:
2519 case DW_OP_breg20:
2520 case DW_OP_breg21:
2521 case DW_OP_breg22:
2522 case DW_OP_breg23:
2523 case DW_OP_breg24:
2524 case DW_OP_breg25:
2525 case DW_OP_breg26:
2526 case DW_OP_breg27:
2527 case DW_OP_breg28:
2528 case DW_OP_breg29:
2529 case DW_OP_breg30:
2530 case DW_OP_breg31:
2531 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2532 break;
2533 case DW_OP_regx:
2534 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2535 break;
2536 case DW_OP_fbreg:
2537 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2538 break;
2539 case DW_OP_bregx:
2540 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2541 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2542 break;
2543 case DW_OP_piece:
2544 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2545 break;
2546 case DW_OP_deref_size:
2547 case DW_OP_xderef_size:
2548 size += 1;
2549 break;
2550 default:
2551 break;
2554 return size;
2557 /* Return the size of a series of location descriptors. */
2559 static unsigned long
2560 size_of_locs (loc)
2561 register dw_loc_descr_ref loc;
2563 register unsigned long size = 0;
2565 for (; loc != NULL; loc = loc->dw_loc_next)
2567 loc->dw_loc_addr = size;
2568 size += size_of_loc_descr (loc);
2571 return size;
2574 /* Output location description stack opcode's operands (if any). */
2576 static void
2577 output_loc_operands (loc)
2578 register dw_loc_descr_ref loc;
2580 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2581 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2583 switch (loc->dw_loc_opc)
2585 #ifdef DWARF2_DEBUGGING_INFO
2586 case DW_OP_addr:
2587 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2588 break;
2589 case DW_OP_const2u:
2590 case DW_OP_const2s:
2591 dw2_asm_output_data (2, val1->v.val_int, NULL);
2592 break;
2593 case DW_OP_const4u:
2594 case DW_OP_const4s:
2595 dw2_asm_output_data (4, val1->v.val_int, NULL);
2596 break;
2597 case DW_OP_const8u:
2598 case DW_OP_const8s:
2599 if (HOST_BITS_PER_LONG < 64)
2600 abort ();
2601 dw2_asm_output_data (8, val1->v.val_int, NULL);
2602 break;
2603 case DW_OP_skip:
2604 case DW_OP_bra:
2606 int offset;
2608 if (val1->val_class == dw_val_class_loc)
2609 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2610 else
2611 abort ();
2613 dw2_asm_output_data (2, offset, NULL);
2615 break;
2616 #else
2617 case DW_OP_addr:
2618 case DW_OP_const2u:
2619 case DW_OP_const2s:
2620 case DW_OP_const4u:
2621 case DW_OP_const4s:
2622 case DW_OP_const8u:
2623 case DW_OP_const8s:
2624 case DW_OP_skip:
2625 case DW_OP_bra:
2626 /* We currently don't make any attempt to make sure these are
2627 aligned properly like we do for the main unwind info, so
2628 don't support emitting things larger than a byte if we're
2629 only doing unwinding. */
2630 abort ();
2631 #endif
2632 case DW_OP_const1u:
2633 case DW_OP_const1s:
2634 dw2_asm_output_data (1, val1->v.val_int, NULL);
2635 break;
2636 case DW_OP_constu:
2637 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2638 break;
2639 case DW_OP_consts:
2640 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2641 break;
2642 case DW_OP_pick:
2643 dw2_asm_output_data (1, val1->v.val_int, NULL);
2644 break;
2645 case DW_OP_plus_uconst:
2646 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2647 break;
2648 case DW_OP_breg0:
2649 case DW_OP_breg1:
2650 case DW_OP_breg2:
2651 case DW_OP_breg3:
2652 case DW_OP_breg4:
2653 case DW_OP_breg5:
2654 case DW_OP_breg6:
2655 case DW_OP_breg7:
2656 case DW_OP_breg8:
2657 case DW_OP_breg9:
2658 case DW_OP_breg10:
2659 case DW_OP_breg11:
2660 case DW_OP_breg12:
2661 case DW_OP_breg13:
2662 case DW_OP_breg14:
2663 case DW_OP_breg15:
2664 case DW_OP_breg16:
2665 case DW_OP_breg17:
2666 case DW_OP_breg18:
2667 case DW_OP_breg19:
2668 case DW_OP_breg20:
2669 case DW_OP_breg21:
2670 case DW_OP_breg22:
2671 case DW_OP_breg23:
2672 case DW_OP_breg24:
2673 case DW_OP_breg25:
2674 case DW_OP_breg26:
2675 case DW_OP_breg27:
2676 case DW_OP_breg28:
2677 case DW_OP_breg29:
2678 case DW_OP_breg30:
2679 case DW_OP_breg31:
2680 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2681 break;
2682 case DW_OP_regx:
2683 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2684 break;
2685 case DW_OP_fbreg:
2686 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2687 break;
2688 case DW_OP_bregx:
2689 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2690 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2691 break;
2692 case DW_OP_piece:
2693 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2694 break;
2695 case DW_OP_deref_size:
2696 case DW_OP_xderef_size:
2697 dw2_asm_output_data (1, val1->v.val_int, NULL);
2698 break;
2699 default:
2700 /* Other codes have no operands. */
2701 break;
2705 /* Output a sequence of location operations. */
2707 static void
2708 output_loc_sequence (loc)
2709 dw_loc_descr_ref loc;
2711 for (; loc != NULL; loc = loc->dw_loc_next)
2713 /* Output the opcode. */
2714 dw2_asm_output_data (1, loc->dw_loc_opc,
2715 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2717 /* Output the operand(s) (if any). */
2718 output_loc_operands (loc);
2722 /* This routine will generate the correct assembly data for a location
2723 description based on a cfi entry with a complex address. */
2725 static void
2726 output_cfa_loc (cfi)
2727 dw_cfi_ref cfi;
2729 dw_loc_descr_ref loc;
2730 unsigned long size;
2732 /* Output the size of the block. */
2733 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2734 size = size_of_locs (loc);
2735 dw2_asm_output_data_uleb128 (size, NULL);
2737 /* Now output the operations themselves. */
2738 output_loc_sequence (loc);
2741 /* This function builds a dwarf location descriptor seqeunce from
2742 a dw_cfa_location. */
2744 static struct dw_loc_descr_struct *
2745 build_cfa_loc (cfa)
2746 dw_cfa_location *cfa;
2748 struct dw_loc_descr_struct *head, *tmp;
2750 if (cfa->indirect == 0)
2751 abort ();
2753 if (cfa->base_offset)
2755 if (cfa->reg <= 31)
2756 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2757 else
2758 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2760 else if (cfa->reg <= 31)
2761 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2762 else
2763 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2764 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2765 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2766 add_loc_descr (&head, tmp);
2767 if (cfa->offset != 0)
2769 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2770 add_loc_descr (&head, tmp);
2772 return head;
2775 /* This function fills in aa dw_cfa_location structure from a
2776 dwarf location descriptor sequence. */
2778 static void
2779 get_cfa_from_loc_descr (cfa, loc)
2780 dw_cfa_location *cfa;
2781 struct dw_loc_descr_struct *loc;
2783 struct dw_loc_descr_struct *ptr;
2784 cfa->offset = 0;
2785 cfa->base_offset = 0;
2786 cfa->indirect = 0;
2787 cfa->reg = -1;
2789 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2791 enum dwarf_location_atom op = ptr->dw_loc_opc;
2792 switch (op)
2794 case DW_OP_reg0:
2795 case DW_OP_reg1:
2796 case DW_OP_reg2:
2797 case DW_OP_reg3:
2798 case DW_OP_reg4:
2799 case DW_OP_reg5:
2800 case DW_OP_reg6:
2801 case DW_OP_reg7:
2802 case DW_OP_reg8:
2803 case DW_OP_reg9:
2804 case DW_OP_reg10:
2805 case DW_OP_reg11:
2806 case DW_OP_reg12:
2807 case DW_OP_reg13:
2808 case DW_OP_reg14:
2809 case DW_OP_reg15:
2810 case DW_OP_reg16:
2811 case DW_OP_reg17:
2812 case DW_OP_reg18:
2813 case DW_OP_reg19:
2814 case DW_OP_reg20:
2815 case DW_OP_reg21:
2816 case DW_OP_reg22:
2817 case DW_OP_reg23:
2818 case DW_OP_reg24:
2819 case DW_OP_reg25:
2820 case DW_OP_reg26:
2821 case DW_OP_reg27:
2822 case DW_OP_reg28:
2823 case DW_OP_reg29:
2824 case DW_OP_reg30:
2825 case DW_OP_reg31:
2826 cfa->reg = op - DW_OP_reg0;
2827 break;
2828 case DW_OP_regx:
2829 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2830 break;
2831 case DW_OP_breg0:
2832 case DW_OP_breg1:
2833 case DW_OP_breg2:
2834 case DW_OP_breg3:
2835 case DW_OP_breg4:
2836 case DW_OP_breg5:
2837 case DW_OP_breg6:
2838 case DW_OP_breg7:
2839 case DW_OP_breg8:
2840 case DW_OP_breg9:
2841 case DW_OP_breg10:
2842 case DW_OP_breg11:
2843 case DW_OP_breg12:
2844 case DW_OP_breg13:
2845 case DW_OP_breg14:
2846 case DW_OP_breg15:
2847 case DW_OP_breg16:
2848 case DW_OP_breg17:
2849 case DW_OP_breg18:
2850 case DW_OP_breg19:
2851 case DW_OP_breg20:
2852 case DW_OP_breg21:
2853 case DW_OP_breg22:
2854 case DW_OP_breg23:
2855 case DW_OP_breg24:
2856 case DW_OP_breg25:
2857 case DW_OP_breg26:
2858 case DW_OP_breg27:
2859 case DW_OP_breg28:
2860 case DW_OP_breg29:
2861 case DW_OP_breg30:
2862 case DW_OP_breg31:
2863 cfa->reg = op - DW_OP_breg0;
2864 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2865 break;
2866 case DW_OP_bregx:
2867 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2868 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
2869 break;
2870 case DW_OP_deref:
2871 cfa->indirect = 1;
2872 break;
2873 case DW_OP_plus_uconst:
2874 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
2875 break;
2876 default:
2877 internal_error ("DW_LOC_OP %s not implememnted\n",
2878 dwarf_stack_op_name (ptr->dw_loc_opc));
2882 #endif /* .debug_frame support */
2884 /* And now, the support for symbolic debugging information. */
2885 #ifdef DWARF2_DEBUGGING_INFO
2887 /* NOTE: In the comments in this file, many references are made to
2888 "Debugging Information Entries". This term is abbreviated as `DIE'
2889 throughout the remainder of this file. */
2891 /* An internal representation of the DWARF output is built, and then
2892 walked to generate the DWARF debugging info. The walk of the internal
2893 representation is done after the entire program has been compiled.
2894 The types below are used to describe the internal representation. */
2896 /* Various DIE's use offsets relative to the beginning of the
2897 .debug_info section to refer to each other. */
2899 typedef long int dw_offset;
2901 /* Define typedefs here to avoid circular dependencies. */
2903 typedef struct dw_attr_struct *dw_attr_ref;
2904 typedef struct dw_line_info_struct *dw_line_info_ref;
2905 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
2906 typedef struct pubname_struct *pubname_ref;
2907 typedef dw_die_ref *arange_ref;
2909 /* Each entry in the line_info_table maintains the file and
2910 line number associated with the label generated for that
2911 entry. The label gives the PC value associated with
2912 the line number entry. */
2914 typedef struct dw_line_info_struct
2916 unsigned long dw_file_num;
2917 unsigned long dw_line_num;
2919 dw_line_info_entry;
2921 /* Line information for functions in separate sections; each one gets its
2922 own sequence. */
2923 typedef struct dw_separate_line_info_struct
2925 unsigned long dw_file_num;
2926 unsigned long dw_line_num;
2927 unsigned long function;
2929 dw_separate_line_info_entry;
2931 /* Each DIE attribute has a field specifying the attribute kind,
2932 a link to the next attribute in the chain, and an attribute value.
2933 Attributes are typically linked below the DIE they modify. */
2935 typedef struct dw_attr_struct
2937 enum dwarf_attribute dw_attr;
2938 dw_attr_ref dw_attr_next;
2939 dw_val_node dw_attr_val;
2941 dw_attr_node;
2943 /* The Debugging Information Entry (DIE) structure */
2945 typedef struct die_struct
2947 enum dwarf_tag die_tag;
2948 char *die_symbol;
2949 dw_attr_ref die_attr;
2950 dw_die_ref die_parent;
2951 dw_die_ref die_child;
2952 dw_die_ref die_sib;
2953 dw_offset die_offset;
2954 unsigned long die_abbrev;
2955 int die_mark;
2957 die_node;
2959 /* The pubname structure */
2961 typedef struct pubname_struct
2963 dw_die_ref die;
2964 char *name;
2966 pubname_entry;
2968 /* The limbo die list structure. */
2969 typedef struct limbo_die_struct
2971 dw_die_ref die;
2972 struct limbo_die_struct *next;
2974 limbo_die_node;
2976 /* How to start an assembler comment. */
2977 #ifndef ASM_COMMENT_START
2978 #define ASM_COMMENT_START ";#"
2979 #endif
2981 /* Define a macro which returns non-zero for a TYPE_DECL which was
2982 implicitly generated for a tagged type.
2984 Note that unlike the gcc front end (which generates a NULL named
2985 TYPE_DECL node for each complete tagged type, each array type, and
2986 each function type node created) the g++ front end generates a
2987 _named_ TYPE_DECL node for each tagged type node created.
2988 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2989 generate a DW_TAG_typedef DIE for them. */
2991 #define TYPE_DECL_IS_STUB(decl) \
2992 (DECL_NAME (decl) == NULL_TREE \
2993 || (DECL_ARTIFICIAL (decl) \
2994 && is_tagged_type (TREE_TYPE (decl)) \
2995 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2996 /* This is necessary for stub decls that \
2997 appear in nested inline functions. */ \
2998 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2999 && (decl_ultimate_origin (decl) \
3000 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3002 /* Information concerning the compilation unit's programming
3003 language, and compiler version. */
3005 extern int flag_traditional;
3007 /* Fixed size portion of the DWARF compilation unit header. */
3008 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3010 /* Fixed size portion of debugging line information prolog. */
3011 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3013 /* Fixed size portion of public names info. */
3014 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3016 /* Fixed size portion of the address range info. */
3017 #define DWARF_ARANGES_HEADER_SIZE \
3018 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3019 - DWARF_OFFSET_SIZE)
3021 /* Size of padding portion in the address range info. It must be
3022 aligned to twice the pointer size. */
3023 #define DWARF_ARANGES_PAD_SIZE \
3024 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3025 - (2 * DWARF_OFFSET_SIZE + 4))
3027 /* Use assembler line directives if available. */
3028 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3029 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3030 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3031 #else
3032 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3033 #endif
3034 #endif
3036 /* Define the architecture-dependent minimum instruction length (in bytes).
3037 In this implementation of DWARF, this field is used for information
3038 purposes only. Since GCC generates assembly language, we have
3039 no a priori knowledge of how many instruction bytes are generated
3040 for each source line, and therefore can use only the DW_LNE_set_address
3041 and DW_LNS_fixed_advance_pc line information commands. */
3043 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3044 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3045 #endif
3047 /* Minimum line offset in a special line info. opcode.
3048 This value was chosen to give a reasonable range of values. */
3049 #define DWARF_LINE_BASE -10
3051 /* First special line opcde - leave room for the standard opcodes. */
3052 #define DWARF_LINE_OPCODE_BASE 10
3054 /* Range of line offsets in a special line info. opcode. */
3055 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3057 /* Flag that indicates the initial value of the is_stmt_start flag.
3058 In the present implementation, we do not mark any lines as
3059 the beginning of a source statement, because that information
3060 is not made available by the GCC front-end. */
3061 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3063 /* This location is used by calc_die_sizes() to keep track
3064 the offset of each DIE within the .debug_info section. */
3065 static unsigned long next_die_offset;
3067 /* Record the root of the DIE's built for the current compilation unit. */
3068 static dw_die_ref comp_unit_die;
3070 /* A list of DIEs with a NULL parent waiting to be relocated. */
3071 static limbo_die_node *limbo_die_list = 0;
3073 /* Structure used by lookup_filename to manage sets of filenames. */
3074 struct file_table
3076 char **table;
3077 unsigned allocated;
3078 unsigned in_use;
3079 unsigned last_lookup_index;
3082 /* Size (in elements) of increments by which we may expand the filename
3083 table. */
3084 #define FILE_TABLE_INCREMENT 64
3086 /* Filenames referenced by this compilation unit. */
3087 static struct file_table file_table;
3089 /* Local pointer to the name of the main input file. Initialized in
3090 dwarf2out_init. */
3091 static const char *primary_filename;
3093 /* A pointer to the base of a table of references to DIE's that describe
3094 declarations. The table is indexed by DECL_UID() which is a unique
3095 number identifying each decl. */
3096 static dw_die_ref *decl_die_table;
3098 /* Number of elements currently allocated for the decl_die_table. */
3099 static unsigned decl_die_table_allocated;
3101 /* Number of elements in decl_die_table currently in use. */
3102 static unsigned decl_die_table_in_use;
3104 /* Size (in elements) of increments by which we may expand the
3105 decl_die_table. */
3106 #define DECL_DIE_TABLE_INCREMENT 256
3108 /* A pointer to the base of a table of references to declaration
3109 scopes. This table is a display which tracks the nesting
3110 of declaration scopes at the current scope and containing
3111 scopes. This table is used to find the proper place to
3112 define type declaration DIE's. */
3113 static tree *decl_scope_table;
3115 /* Number of elements currently allocated for the decl_scope_table. */
3116 static int decl_scope_table_allocated;
3118 /* Current level of nesting of declaration scopes. */
3119 static int decl_scope_depth;
3121 /* Size (in elements) of increments by which we may expand the
3122 decl_scope_table. */
3123 #define DECL_SCOPE_TABLE_INCREMENT 64
3125 /* A pointer to the base of a list of references to DIE's that
3126 are uniquely identified by their tag, presence/absence of
3127 children DIE's, and list of attribute/value pairs. */
3128 static dw_die_ref *abbrev_die_table;
3130 /* Number of elements currently allocated for abbrev_die_table. */
3131 static unsigned abbrev_die_table_allocated;
3133 /* Number of elements in type_die_table currently in use. */
3134 static unsigned abbrev_die_table_in_use;
3136 /* Size (in elements) of increments by which we may expand the
3137 abbrev_die_table. */
3138 #define ABBREV_DIE_TABLE_INCREMENT 256
3140 /* A pointer to the base of a table that contains line information
3141 for each source code line in .text in the compilation unit. */
3142 static dw_line_info_ref line_info_table;
3144 /* Number of elements currently allocated for line_info_table. */
3145 static unsigned line_info_table_allocated;
3147 /* Number of elements in separate_line_info_table currently in use. */
3148 static unsigned separate_line_info_table_in_use;
3150 /* A pointer to the base of a table that contains line information
3151 for each source code line outside of .text in the compilation unit. */
3152 static dw_separate_line_info_ref separate_line_info_table;
3154 /* Number of elements currently allocated for separate_line_info_table. */
3155 static unsigned separate_line_info_table_allocated;
3157 /* Number of elements in line_info_table currently in use. */
3158 static unsigned line_info_table_in_use;
3160 /* Size (in elements) of increments by which we may expand the
3161 line_info_table. */
3162 #define LINE_INFO_TABLE_INCREMENT 1024
3164 /* A pointer to the base of a table that contains a list of publicly
3165 accessible names. */
3166 static pubname_ref pubname_table;
3168 /* Number of elements currently allocated for pubname_table. */
3169 static unsigned pubname_table_allocated;
3171 /* Number of elements in pubname_table currently in use. */
3172 static unsigned pubname_table_in_use;
3174 /* Size (in elements) of increments by which we may expand the
3175 pubname_table. */
3176 #define PUBNAME_TABLE_INCREMENT 64
3178 /* A pointer to the base of a table that contains a list of publicly
3179 accessible names. */
3180 static arange_ref arange_table;
3182 /* Number of elements currently allocated for arange_table. */
3183 static unsigned arange_table_allocated;
3185 /* Number of elements in arange_table currently in use. */
3186 static unsigned arange_table_in_use;
3188 /* Size (in elements) of increments by which we may expand the
3189 arange_table. */
3190 #define ARANGE_TABLE_INCREMENT 64
3192 /* A pointer to the base of a list of incomplete types which might be
3193 completed at some later time. */
3195 static tree *incomplete_types_list;
3197 /* Number of elements currently allocated for the incomplete_types_list. */
3198 static unsigned incomplete_types_allocated;
3200 /* Number of elements of incomplete_types_list currently in use. */
3201 static unsigned incomplete_types;
3203 /* Size (in elements) of increments by which we may expand the incomplete
3204 types list. Actually, a single hunk of space of this size should
3205 be enough for most typical programs. */
3206 #define INCOMPLETE_TYPES_INCREMENT 64
3208 /* Record whether the function being analyzed contains inlined functions. */
3209 static int current_function_has_inlines;
3210 #if 0 && defined (MIPS_DEBUGGING_INFO)
3211 static int comp_unit_has_inlines;
3212 #endif
3214 /* Array of RTXes referenced by the debugging information, which therefore
3215 must be kept around forever. We do this rather than perform GC on
3216 the dwarf info because almost all of the dwarf info lives forever, and
3217 it's easier to support non-GC frontends this way. */
3218 static varray_type used_rtx_varray;
3220 /* Forward declarations for functions defined in this file. */
3222 static int is_pseudo_reg PARAMS ((rtx));
3223 static tree type_main_variant PARAMS ((tree));
3224 static int is_tagged_type PARAMS ((tree));
3225 static const char *dwarf_tag_name PARAMS ((unsigned));
3226 static const char *dwarf_attr_name PARAMS ((unsigned));
3227 static const char *dwarf_form_name PARAMS ((unsigned));
3228 #if 0
3229 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3230 #endif
3231 static tree decl_ultimate_origin PARAMS ((tree));
3232 static tree block_ultimate_origin PARAMS ((tree));
3233 static tree decl_class_context PARAMS ((tree));
3234 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3235 static void add_AT_flag PARAMS ((dw_die_ref,
3236 enum dwarf_attribute,
3237 unsigned));
3238 static void add_AT_int PARAMS ((dw_die_ref,
3239 enum dwarf_attribute, long));
3240 static void add_AT_unsigned PARAMS ((dw_die_ref,
3241 enum dwarf_attribute,
3242 unsigned long));
3243 static void add_AT_long_long PARAMS ((dw_die_ref,
3244 enum dwarf_attribute,
3245 unsigned long,
3246 unsigned long));
3247 static void add_AT_float PARAMS ((dw_die_ref,
3248 enum dwarf_attribute,
3249 unsigned, long *));
3250 static void add_AT_string PARAMS ((dw_die_ref,
3251 enum dwarf_attribute,
3252 const char *));
3253 static void add_AT_die_ref PARAMS ((dw_die_ref,
3254 enum dwarf_attribute,
3255 dw_die_ref));
3256 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3257 enum dwarf_attribute,
3258 unsigned));
3259 static void add_AT_loc PARAMS ((dw_die_ref,
3260 enum dwarf_attribute,
3261 dw_loc_descr_ref));
3262 static void add_AT_addr PARAMS ((dw_die_ref,
3263 enum dwarf_attribute,
3264 rtx));
3265 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3266 enum dwarf_attribute,
3267 const char *));
3268 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3269 enum dwarf_attribute,
3270 const char *));
3271 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3272 enum dwarf_attribute));
3273 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3274 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3275 static const char *get_AT_string PARAMS ((dw_die_ref,
3276 enum dwarf_attribute));
3277 static int get_AT_flag PARAMS ((dw_die_ref,
3278 enum dwarf_attribute));
3279 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3280 enum dwarf_attribute));
3281 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3282 enum dwarf_attribute));
3283 static int is_c_family PARAMS ((void));
3284 static int is_java PARAMS ((void));
3285 static int is_fortran PARAMS ((void));
3286 static void remove_AT PARAMS ((dw_die_ref,
3287 enum dwarf_attribute));
3288 static void remove_children PARAMS ((dw_die_ref));
3289 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3290 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3291 static dw_die_ref lookup_type_die PARAMS ((tree));
3292 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3293 static dw_die_ref lookup_decl_die PARAMS ((tree));
3294 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3295 static void print_spaces PARAMS ((FILE *));
3296 static void print_die PARAMS ((dw_die_ref, FILE *));
3297 static void print_dwarf_line_table PARAMS ((FILE *));
3298 static void reverse_die_lists PARAMS ((dw_die_ref));
3299 static void reverse_all_dies PARAMS ((dw_die_ref));
3300 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3301 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3302 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3303 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3304 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3305 static void compute_section_prefix PARAMS ((dw_die_ref));
3306 static int is_type_die PARAMS ((dw_die_ref));
3307 static int is_comdat_die PARAMS ((dw_die_ref));
3308 static int is_symbol_die PARAMS ((dw_die_ref));
3309 static char *gen_internal_sym PARAMS ((void));
3310 static void assign_symbol_names PARAMS ((dw_die_ref));
3311 static void break_out_includes PARAMS ((dw_die_ref));
3312 static void add_sibling_attributes PARAMS ((dw_die_ref));
3313 static void build_abbrev_table PARAMS ((dw_die_ref));
3314 static unsigned long size_of_string PARAMS ((const char *));
3315 static int constant_size PARAMS ((long unsigned));
3316 static unsigned long size_of_die PARAMS ((dw_die_ref));
3317 static void calc_die_sizes PARAMS ((dw_die_ref));
3318 static void mark_dies PARAMS ((dw_die_ref));
3319 static void unmark_dies PARAMS ((dw_die_ref));
3320 static unsigned long size_of_pubnames PARAMS ((void));
3321 static unsigned long size_of_aranges PARAMS ((void));
3322 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3323 static void output_value_format PARAMS ((dw_attr_ref));
3324 static void output_abbrev_section PARAMS ((void));
3325 static void output_die_symbol PARAMS ((dw_die_ref));
3326 static void output_die PARAMS ((dw_die_ref));
3327 static void output_compilation_unit_header PARAMS ((void));
3328 static void output_comp_unit PARAMS ((dw_die_ref));
3329 static const char *dwarf2_name PARAMS ((tree, int));
3330 static void add_pubname PARAMS ((tree, dw_die_ref));
3331 static void output_pubnames PARAMS ((void));
3332 static void add_arange PARAMS ((tree, dw_die_ref));
3333 static void output_aranges PARAMS ((void));
3334 static void output_line_info PARAMS ((void));
3335 static void output_file_names PARAMS ((void));
3336 static dw_die_ref base_type_die PARAMS ((tree));
3337 static tree root_type PARAMS ((tree));
3338 static int is_base_type PARAMS ((tree));
3339 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3340 static int type_is_enum PARAMS ((tree));
3341 static unsigned int reg_number PARAMS ((rtx));
3342 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3343 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3344 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3345 static int is_based_loc PARAMS ((rtx));
3346 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3347 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3348 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3349 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3350 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3351 static tree field_type PARAMS ((tree));
3352 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3353 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3354 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3355 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3356 static void add_AT_location_description PARAMS ((dw_die_ref,
3357 enum dwarf_attribute, rtx));
3358 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3359 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3360 static rtx rtl_for_decl_location PARAMS ((tree));
3361 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3362 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3363 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3364 static void add_bound_info PARAMS ((dw_die_ref,
3365 enum dwarf_attribute, tree));
3366 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3367 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3368 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3369 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3370 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3371 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3372 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3373 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3374 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3375 static void push_decl_scope PARAMS ((tree));
3376 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3377 static void pop_decl_scope PARAMS ((void));
3378 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3379 dw_die_ref));
3380 static const char *type_tag PARAMS ((tree));
3381 static tree member_declared_type PARAMS ((tree));
3382 #if 0
3383 static const char *decl_start_label PARAMS ((tree));
3384 #endif
3385 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3386 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3387 #if 0
3388 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3389 #endif
3390 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3391 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3392 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3393 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3394 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3395 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3396 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3397 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3398 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3399 static void gen_label_die PARAMS ((tree, dw_die_ref));
3400 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3401 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3402 static void gen_field_die PARAMS ((tree, dw_die_ref));
3403 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3404 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3405 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3406 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3407 static void gen_member_die PARAMS ((tree, dw_die_ref));
3408 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3409 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3410 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3411 static void gen_type_die PARAMS ((tree, dw_die_ref));
3412 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3413 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3414 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3415 static int is_redundant_typedef PARAMS ((tree));
3416 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3417 static unsigned lookup_filename PARAMS ((const char *));
3418 static void init_file_table PARAMS ((void));
3419 static void add_incomplete_type PARAMS ((tree));
3420 static void retry_incomplete_types PARAMS ((void));
3421 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3422 static rtx save_rtx PARAMS ((rtx));
3423 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3424 static int file_info_cmp PARAMS ((const void *, const void *));
3426 /* Section names used to hold DWARF debugging information. */
3427 #ifndef DEBUG_INFO_SECTION
3428 #define DEBUG_INFO_SECTION ".debug_info"
3429 #endif
3430 #ifndef ABBREV_SECTION
3431 #define ABBREV_SECTION ".debug_abbrev"
3432 #endif
3433 #ifndef ARANGES_SECTION
3434 #define ARANGES_SECTION ".debug_aranges"
3435 #endif
3436 #ifndef DW_MACINFO_SECTION
3437 #define DW_MACINFO_SECTION ".debug_macinfo"
3438 #endif
3439 #ifndef DEBUG_LINE_SECTION
3440 #define DEBUG_LINE_SECTION ".debug_line"
3441 #endif
3442 #ifndef LOC_SECTION
3443 #define LOC_SECTION ".debug_loc"
3444 #endif
3445 #ifndef PUBNAMES_SECTION
3446 #define PUBNAMES_SECTION ".debug_pubnames"
3447 #endif
3448 #ifndef STR_SECTION
3449 #define STR_SECTION ".debug_str"
3450 #endif
3452 /* Standard ELF section names for compiled code and data. */
3453 #ifndef TEXT_SECTION
3454 #define TEXT_SECTION ".text"
3455 #endif
3456 #ifndef DATA_SECTION
3457 #define DATA_SECTION ".data"
3458 #endif
3459 #ifndef BSS_SECTION
3460 #define BSS_SECTION ".bss"
3461 #endif
3463 /* Labels we insert at beginning sections we can reference instead of
3464 the section names themselves. */
3466 #ifndef TEXT_SECTION_LABEL
3467 #define TEXT_SECTION_LABEL "Ltext"
3468 #endif
3469 #ifndef DEBUG_LINE_SECTION_LABEL
3470 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3471 #endif
3472 #ifndef DEBUG_INFO_SECTION_LABEL
3473 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3474 #endif
3475 #ifndef ABBREV_SECTION_LABEL
3476 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
3477 #endif
3479 /* Definitions of defaults for formats and names of various special
3480 (artificial) labels which may be generated within this file (when the -g
3481 options is used and DWARF_DEBUGGING_INFO is in effect.
3482 If necessary, these may be overridden from within the tm.h file, but
3483 typically, overriding these defaults is unnecessary. */
3485 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3486 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3487 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3488 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3489 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3491 #ifndef TEXT_END_LABEL
3492 #define TEXT_END_LABEL "Letext"
3493 #endif
3494 #ifndef DATA_END_LABEL
3495 #define DATA_END_LABEL "Ledata"
3496 #endif
3497 #ifndef BSS_END_LABEL
3498 #define BSS_END_LABEL "Lebss"
3499 #endif
3500 #ifndef BLOCK_BEGIN_LABEL
3501 #define BLOCK_BEGIN_LABEL "LBB"
3502 #endif
3503 #ifndef BLOCK_END_LABEL
3504 #define BLOCK_END_LABEL "LBE"
3505 #endif
3506 #ifndef BODY_BEGIN_LABEL
3507 #define BODY_BEGIN_LABEL "Lbb"
3508 #endif
3509 #ifndef BODY_END_LABEL
3510 #define BODY_END_LABEL "Lbe"
3511 #endif
3512 #ifndef LINE_CODE_LABEL
3513 #define LINE_CODE_LABEL "LM"
3514 #endif
3515 #ifndef SEPARATE_LINE_CODE_LABEL
3516 #define SEPARATE_LINE_CODE_LABEL "LSM"
3517 #endif
3519 /* We allow a language front-end to designate a function that is to be
3520 called to "demangle" any name before it it put into a DIE. */
3522 static const char *(*demangle_name_func) PARAMS ((const char *));
3524 void
3525 dwarf2out_set_demangle_name_func (func)
3526 const char *(*func) PARAMS ((const char *));
3528 demangle_name_func = func;
3531 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3532 that means adding it to used_rtx_varray. If not, that means making
3533 a copy on the permanent_obstack. */
3535 static rtx
3536 save_rtx (orig)
3537 register rtx orig;
3539 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3541 return orig;
3544 /* Test if rtl node points to a pseudo register. */
3546 static inline int
3547 is_pseudo_reg (rtl)
3548 register rtx rtl;
3550 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3551 || (GET_CODE (rtl) == SUBREG
3552 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3555 /* Return a reference to a type, with its const and volatile qualifiers
3556 removed. */
3558 static inline tree
3559 type_main_variant (type)
3560 register tree type;
3562 type = TYPE_MAIN_VARIANT (type);
3564 /* There really should be only one main variant among any group of variants
3565 of a given type (and all of the MAIN_VARIANT values for all members of
3566 the group should point to that one type) but sometimes the C front-end
3567 messes this up for array types, so we work around that bug here. */
3569 if (TREE_CODE (type) == ARRAY_TYPE)
3570 while (type != TYPE_MAIN_VARIANT (type))
3571 type = TYPE_MAIN_VARIANT (type);
3573 return type;
3576 /* Return non-zero if the given type node represents a tagged type. */
3578 static inline int
3579 is_tagged_type (type)
3580 register tree type;
3582 register enum tree_code code = TREE_CODE (type);
3584 return (code == RECORD_TYPE || code == UNION_TYPE
3585 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3588 /* Convert a DIE tag into its string name. */
3590 static const char *
3591 dwarf_tag_name (tag)
3592 register unsigned tag;
3594 switch (tag)
3596 case DW_TAG_padding:
3597 return "DW_TAG_padding";
3598 case DW_TAG_array_type:
3599 return "DW_TAG_array_type";
3600 case DW_TAG_class_type:
3601 return "DW_TAG_class_type";
3602 case DW_TAG_entry_point:
3603 return "DW_TAG_entry_point";
3604 case DW_TAG_enumeration_type:
3605 return "DW_TAG_enumeration_type";
3606 case DW_TAG_formal_parameter:
3607 return "DW_TAG_formal_parameter";
3608 case DW_TAG_imported_declaration:
3609 return "DW_TAG_imported_declaration";
3610 case DW_TAG_label:
3611 return "DW_TAG_label";
3612 case DW_TAG_lexical_block:
3613 return "DW_TAG_lexical_block";
3614 case DW_TAG_member:
3615 return "DW_TAG_member";
3616 case DW_TAG_pointer_type:
3617 return "DW_TAG_pointer_type";
3618 case DW_TAG_reference_type:
3619 return "DW_TAG_reference_type";
3620 case DW_TAG_compile_unit:
3621 return "DW_TAG_compile_unit";
3622 case DW_TAG_string_type:
3623 return "DW_TAG_string_type";
3624 case DW_TAG_structure_type:
3625 return "DW_TAG_structure_type";
3626 case DW_TAG_subroutine_type:
3627 return "DW_TAG_subroutine_type";
3628 case DW_TAG_typedef:
3629 return "DW_TAG_typedef";
3630 case DW_TAG_union_type:
3631 return "DW_TAG_union_type";
3632 case DW_TAG_unspecified_parameters:
3633 return "DW_TAG_unspecified_parameters";
3634 case DW_TAG_variant:
3635 return "DW_TAG_variant";
3636 case DW_TAG_common_block:
3637 return "DW_TAG_common_block";
3638 case DW_TAG_common_inclusion:
3639 return "DW_TAG_common_inclusion";
3640 case DW_TAG_inheritance:
3641 return "DW_TAG_inheritance";
3642 case DW_TAG_inlined_subroutine:
3643 return "DW_TAG_inlined_subroutine";
3644 case DW_TAG_module:
3645 return "DW_TAG_module";
3646 case DW_TAG_ptr_to_member_type:
3647 return "DW_TAG_ptr_to_member_type";
3648 case DW_TAG_set_type:
3649 return "DW_TAG_set_type";
3650 case DW_TAG_subrange_type:
3651 return "DW_TAG_subrange_type";
3652 case DW_TAG_with_stmt:
3653 return "DW_TAG_with_stmt";
3654 case DW_TAG_access_declaration:
3655 return "DW_TAG_access_declaration";
3656 case DW_TAG_base_type:
3657 return "DW_TAG_base_type";
3658 case DW_TAG_catch_block:
3659 return "DW_TAG_catch_block";
3660 case DW_TAG_const_type:
3661 return "DW_TAG_const_type";
3662 case DW_TAG_constant:
3663 return "DW_TAG_constant";
3664 case DW_TAG_enumerator:
3665 return "DW_TAG_enumerator";
3666 case DW_TAG_file_type:
3667 return "DW_TAG_file_type";
3668 case DW_TAG_friend:
3669 return "DW_TAG_friend";
3670 case DW_TAG_namelist:
3671 return "DW_TAG_namelist";
3672 case DW_TAG_namelist_item:
3673 return "DW_TAG_namelist_item";
3674 case DW_TAG_packed_type:
3675 return "DW_TAG_packed_type";
3676 case DW_TAG_subprogram:
3677 return "DW_TAG_subprogram";
3678 case DW_TAG_template_type_param:
3679 return "DW_TAG_template_type_param";
3680 case DW_TAG_template_value_param:
3681 return "DW_TAG_template_value_param";
3682 case DW_TAG_thrown_type:
3683 return "DW_TAG_thrown_type";
3684 case DW_TAG_try_block:
3685 return "DW_TAG_try_block";
3686 case DW_TAG_variant_part:
3687 return "DW_TAG_variant_part";
3688 case DW_TAG_variable:
3689 return "DW_TAG_variable";
3690 case DW_TAG_volatile_type:
3691 return "DW_TAG_volatile_type";
3692 case DW_TAG_MIPS_loop:
3693 return "DW_TAG_MIPS_loop";
3694 case DW_TAG_format_label:
3695 return "DW_TAG_format_label";
3696 case DW_TAG_function_template:
3697 return "DW_TAG_function_template";
3698 case DW_TAG_class_template:
3699 return "DW_TAG_class_template";
3700 case DW_TAG_GNU_BINCL:
3701 return "DW_TAG_GNU_BINCL";
3702 case DW_TAG_GNU_EINCL:
3703 return "DW_TAG_GNU_EINCL";
3704 default:
3705 return "DW_TAG_<unknown>";
3709 /* Convert a DWARF attribute code into its string name. */
3711 static const char *
3712 dwarf_attr_name (attr)
3713 register unsigned attr;
3715 switch (attr)
3717 case DW_AT_sibling:
3718 return "DW_AT_sibling";
3719 case DW_AT_location:
3720 return "DW_AT_location";
3721 case DW_AT_name:
3722 return "DW_AT_name";
3723 case DW_AT_ordering:
3724 return "DW_AT_ordering";
3725 case DW_AT_subscr_data:
3726 return "DW_AT_subscr_data";
3727 case DW_AT_byte_size:
3728 return "DW_AT_byte_size";
3729 case DW_AT_bit_offset:
3730 return "DW_AT_bit_offset";
3731 case DW_AT_bit_size:
3732 return "DW_AT_bit_size";
3733 case DW_AT_element_list:
3734 return "DW_AT_element_list";
3735 case DW_AT_stmt_list:
3736 return "DW_AT_stmt_list";
3737 case DW_AT_low_pc:
3738 return "DW_AT_low_pc";
3739 case DW_AT_high_pc:
3740 return "DW_AT_high_pc";
3741 case DW_AT_language:
3742 return "DW_AT_language";
3743 case DW_AT_member:
3744 return "DW_AT_member";
3745 case DW_AT_discr:
3746 return "DW_AT_discr";
3747 case DW_AT_discr_value:
3748 return "DW_AT_discr_value";
3749 case DW_AT_visibility:
3750 return "DW_AT_visibility";
3751 case DW_AT_import:
3752 return "DW_AT_import";
3753 case DW_AT_string_length:
3754 return "DW_AT_string_length";
3755 case DW_AT_common_reference:
3756 return "DW_AT_common_reference";
3757 case DW_AT_comp_dir:
3758 return "DW_AT_comp_dir";
3759 case DW_AT_const_value:
3760 return "DW_AT_const_value";
3761 case DW_AT_containing_type:
3762 return "DW_AT_containing_type";
3763 case DW_AT_default_value:
3764 return "DW_AT_default_value";
3765 case DW_AT_inline:
3766 return "DW_AT_inline";
3767 case DW_AT_is_optional:
3768 return "DW_AT_is_optional";
3769 case DW_AT_lower_bound:
3770 return "DW_AT_lower_bound";
3771 case DW_AT_producer:
3772 return "DW_AT_producer";
3773 case DW_AT_prototyped:
3774 return "DW_AT_prototyped";
3775 case DW_AT_return_addr:
3776 return "DW_AT_return_addr";
3777 case DW_AT_start_scope:
3778 return "DW_AT_start_scope";
3779 case DW_AT_stride_size:
3780 return "DW_AT_stride_size";
3781 case DW_AT_upper_bound:
3782 return "DW_AT_upper_bound";
3783 case DW_AT_abstract_origin:
3784 return "DW_AT_abstract_origin";
3785 case DW_AT_accessibility:
3786 return "DW_AT_accessibility";
3787 case DW_AT_address_class:
3788 return "DW_AT_address_class";
3789 case DW_AT_artificial:
3790 return "DW_AT_artificial";
3791 case DW_AT_base_types:
3792 return "DW_AT_base_types";
3793 case DW_AT_calling_convention:
3794 return "DW_AT_calling_convention";
3795 case DW_AT_count:
3796 return "DW_AT_count";
3797 case DW_AT_data_member_location:
3798 return "DW_AT_data_member_location";
3799 case DW_AT_decl_column:
3800 return "DW_AT_decl_column";
3801 case DW_AT_decl_file:
3802 return "DW_AT_decl_file";
3803 case DW_AT_decl_line:
3804 return "DW_AT_decl_line";
3805 case DW_AT_declaration:
3806 return "DW_AT_declaration";
3807 case DW_AT_discr_list:
3808 return "DW_AT_discr_list";
3809 case DW_AT_encoding:
3810 return "DW_AT_encoding";
3811 case DW_AT_external:
3812 return "DW_AT_external";
3813 case DW_AT_frame_base:
3814 return "DW_AT_frame_base";
3815 case DW_AT_friend:
3816 return "DW_AT_friend";
3817 case DW_AT_identifier_case:
3818 return "DW_AT_identifier_case";
3819 case DW_AT_macro_info:
3820 return "DW_AT_macro_info";
3821 case DW_AT_namelist_items:
3822 return "DW_AT_namelist_items";
3823 case DW_AT_priority:
3824 return "DW_AT_priority";
3825 case DW_AT_segment:
3826 return "DW_AT_segment";
3827 case DW_AT_specification:
3828 return "DW_AT_specification";
3829 case DW_AT_static_link:
3830 return "DW_AT_static_link";
3831 case DW_AT_type:
3832 return "DW_AT_type";
3833 case DW_AT_use_location:
3834 return "DW_AT_use_location";
3835 case DW_AT_variable_parameter:
3836 return "DW_AT_variable_parameter";
3837 case DW_AT_virtuality:
3838 return "DW_AT_virtuality";
3839 case DW_AT_vtable_elem_location:
3840 return "DW_AT_vtable_elem_location";
3842 case DW_AT_MIPS_fde:
3843 return "DW_AT_MIPS_fde";
3844 case DW_AT_MIPS_loop_begin:
3845 return "DW_AT_MIPS_loop_begin";
3846 case DW_AT_MIPS_tail_loop_begin:
3847 return "DW_AT_MIPS_tail_loop_begin";
3848 case DW_AT_MIPS_epilog_begin:
3849 return "DW_AT_MIPS_epilog_begin";
3850 case DW_AT_MIPS_loop_unroll_factor:
3851 return "DW_AT_MIPS_loop_unroll_factor";
3852 case DW_AT_MIPS_software_pipeline_depth:
3853 return "DW_AT_MIPS_software_pipeline_depth";
3854 case DW_AT_MIPS_linkage_name:
3855 return "DW_AT_MIPS_linkage_name";
3856 case DW_AT_MIPS_stride:
3857 return "DW_AT_MIPS_stride";
3858 case DW_AT_MIPS_abstract_name:
3859 return "DW_AT_MIPS_abstract_name";
3860 case DW_AT_MIPS_clone_origin:
3861 return "DW_AT_MIPS_clone_origin";
3862 case DW_AT_MIPS_has_inlines:
3863 return "DW_AT_MIPS_has_inlines";
3865 case DW_AT_sf_names:
3866 return "DW_AT_sf_names";
3867 case DW_AT_src_info:
3868 return "DW_AT_src_info";
3869 case DW_AT_mac_info:
3870 return "DW_AT_mac_info";
3871 case DW_AT_src_coords:
3872 return "DW_AT_src_coords";
3873 case DW_AT_body_begin:
3874 return "DW_AT_body_begin";
3875 case DW_AT_body_end:
3876 return "DW_AT_body_end";
3877 default:
3878 return "DW_AT_<unknown>";
3882 /* Convert a DWARF value form code into its string name. */
3884 static const char *
3885 dwarf_form_name (form)
3886 register unsigned form;
3888 switch (form)
3890 case DW_FORM_addr:
3891 return "DW_FORM_addr";
3892 case DW_FORM_block2:
3893 return "DW_FORM_block2";
3894 case DW_FORM_block4:
3895 return "DW_FORM_block4";
3896 case DW_FORM_data2:
3897 return "DW_FORM_data2";
3898 case DW_FORM_data4:
3899 return "DW_FORM_data4";
3900 case DW_FORM_data8:
3901 return "DW_FORM_data8";
3902 case DW_FORM_string:
3903 return "DW_FORM_string";
3904 case DW_FORM_block:
3905 return "DW_FORM_block";
3906 case DW_FORM_block1:
3907 return "DW_FORM_block1";
3908 case DW_FORM_data1:
3909 return "DW_FORM_data1";
3910 case DW_FORM_flag:
3911 return "DW_FORM_flag";
3912 case DW_FORM_sdata:
3913 return "DW_FORM_sdata";
3914 case DW_FORM_strp:
3915 return "DW_FORM_strp";
3916 case DW_FORM_udata:
3917 return "DW_FORM_udata";
3918 case DW_FORM_ref_addr:
3919 return "DW_FORM_ref_addr";
3920 case DW_FORM_ref1:
3921 return "DW_FORM_ref1";
3922 case DW_FORM_ref2:
3923 return "DW_FORM_ref2";
3924 case DW_FORM_ref4:
3925 return "DW_FORM_ref4";
3926 case DW_FORM_ref8:
3927 return "DW_FORM_ref8";
3928 case DW_FORM_ref_udata:
3929 return "DW_FORM_ref_udata";
3930 case DW_FORM_indirect:
3931 return "DW_FORM_indirect";
3932 default:
3933 return "DW_FORM_<unknown>";
3937 /* Convert a DWARF type code into its string name. */
3939 #if 0
3940 static const char *
3941 dwarf_type_encoding_name (enc)
3942 register unsigned enc;
3944 switch (enc)
3946 case DW_ATE_address:
3947 return "DW_ATE_address";
3948 case DW_ATE_boolean:
3949 return "DW_ATE_boolean";
3950 case DW_ATE_complex_float:
3951 return "DW_ATE_complex_float";
3952 case DW_ATE_float:
3953 return "DW_ATE_float";
3954 case DW_ATE_signed:
3955 return "DW_ATE_signed";
3956 case DW_ATE_signed_char:
3957 return "DW_ATE_signed_char";
3958 case DW_ATE_unsigned:
3959 return "DW_ATE_unsigned";
3960 case DW_ATE_unsigned_char:
3961 return "DW_ATE_unsigned_char";
3962 default:
3963 return "DW_ATE_<unknown>";
3966 #endif
3968 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3969 instance of an inlined instance of a decl which is local to an inline
3970 function, so we have to trace all of the way back through the origin chain
3971 to find out what sort of node actually served as the original seed for the
3972 given block. */
3974 static tree
3975 decl_ultimate_origin (decl)
3976 register tree decl;
3978 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3979 nodes in the function to point to themselves; ignore that if
3980 we're trying to output the abstract instance of this function. */
3981 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
3982 return NULL_TREE;
3984 #ifdef ENABLE_CHECKING
3985 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
3986 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3987 most distant ancestor, this should never happen. */
3988 abort ();
3989 #endif
3991 return DECL_ABSTRACT_ORIGIN (decl);
3994 /* Determine the "ultimate origin" of a block. The block may be an inlined
3995 instance of an inlined instance of a block which is local to an inline
3996 function, so we have to trace all of the way back through the origin chain
3997 to find out what sort of node actually served as the original seed for the
3998 given block. */
4000 static tree
4001 block_ultimate_origin (block)
4002 register tree block;
4004 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4006 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4007 nodes in the function to point to themselves; ignore that if
4008 we're trying to output the abstract instance of this function. */
4009 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4010 return NULL_TREE;
4012 if (immediate_origin == NULL_TREE)
4013 return NULL_TREE;
4014 else
4016 register tree ret_val;
4017 register tree lookahead = immediate_origin;
4021 ret_val = lookahead;
4022 lookahead = (TREE_CODE (ret_val) == BLOCK)
4023 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4024 : NULL;
4026 while (lookahead != NULL && lookahead != ret_val);
4028 return ret_val;
4032 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4033 of a virtual function may refer to a base class, so we check the 'this'
4034 parameter. */
4036 static tree
4037 decl_class_context (decl)
4038 tree decl;
4040 tree context = NULL_TREE;
4042 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4043 context = DECL_CONTEXT (decl);
4044 else
4045 context = TYPE_MAIN_VARIANT
4046 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4048 if (context && !TYPE_P (context))
4049 context = NULL_TREE;
4051 return context;
4054 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4055 addition order, and correct that in reverse_all_dies. */
4057 static inline void
4058 add_dwarf_attr (die, attr)
4059 register dw_die_ref die;
4060 register dw_attr_ref attr;
4062 if (die != NULL && attr != NULL)
4064 attr->dw_attr_next = die->die_attr;
4065 die->die_attr = attr;
4069 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4070 static inline dw_val_class
4071 AT_class (a)
4072 dw_attr_ref a;
4074 return a->dw_attr_val.val_class;
4077 /* Add a flag value attribute to a DIE. */
4079 static inline void
4080 add_AT_flag (die, attr_kind, flag)
4081 register dw_die_ref die;
4082 register enum dwarf_attribute attr_kind;
4083 register unsigned flag;
4085 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4087 attr->dw_attr_next = NULL;
4088 attr->dw_attr = attr_kind;
4089 attr->dw_attr_val.val_class = dw_val_class_flag;
4090 attr->dw_attr_val.v.val_flag = flag;
4091 add_dwarf_attr (die, attr);
4094 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4095 static inline unsigned
4096 AT_flag (a)
4097 register dw_attr_ref a;
4099 if (a && AT_class (a) == dw_val_class_flag)
4100 return a->dw_attr_val.v.val_flag;
4102 abort ();
4105 /* Add a signed integer attribute value to a DIE. */
4107 static inline void
4108 add_AT_int (die, attr_kind, int_val)
4109 register dw_die_ref die;
4110 register enum dwarf_attribute attr_kind;
4111 register long int int_val;
4113 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4115 attr->dw_attr_next = NULL;
4116 attr->dw_attr = attr_kind;
4117 attr->dw_attr_val.val_class = dw_val_class_const;
4118 attr->dw_attr_val.v.val_int = int_val;
4119 add_dwarf_attr (die, attr);
4122 static inline long int AT_int PARAMS ((dw_attr_ref));
4123 static inline long int
4124 AT_int (a)
4125 register dw_attr_ref a;
4127 if (a && AT_class (a) == dw_val_class_const)
4128 return a->dw_attr_val.v.val_int;
4130 abort ();
4133 /* Add an unsigned integer attribute value to a DIE. */
4135 static inline void
4136 add_AT_unsigned (die, attr_kind, unsigned_val)
4137 register dw_die_ref die;
4138 register enum dwarf_attribute attr_kind;
4139 register unsigned long unsigned_val;
4141 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4143 attr->dw_attr_next = NULL;
4144 attr->dw_attr = attr_kind;
4145 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4146 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4147 add_dwarf_attr (die, attr);
4150 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4151 static inline unsigned long
4152 AT_unsigned (a)
4153 register dw_attr_ref a;
4155 if (a && AT_class (a) == dw_val_class_unsigned_const)
4156 return a->dw_attr_val.v.val_unsigned;
4158 abort ();
4161 /* Add an unsigned double integer attribute value to a DIE. */
4163 static inline void
4164 add_AT_long_long (die, attr_kind, val_hi, val_low)
4165 register dw_die_ref die;
4166 register enum dwarf_attribute attr_kind;
4167 register unsigned long val_hi;
4168 register unsigned long val_low;
4170 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4172 attr->dw_attr_next = NULL;
4173 attr->dw_attr = attr_kind;
4174 attr->dw_attr_val.val_class = dw_val_class_long_long;
4175 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4176 attr->dw_attr_val.v.val_long_long.low = val_low;
4177 add_dwarf_attr (die, attr);
4180 /* Add a floating point attribute value to a DIE and return it. */
4182 static inline void
4183 add_AT_float (die, attr_kind, length, array)
4184 register dw_die_ref die;
4185 register enum dwarf_attribute attr_kind;
4186 register unsigned length;
4187 register long *array;
4189 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4191 attr->dw_attr_next = NULL;
4192 attr->dw_attr = attr_kind;
4193 attr->dw_attr_val.val_class = dw_val_class_float;
4194 attr->dw_attr_val.v.val_float.length = length;
4195 attr->dw_attr_val.v.val_float.array = array;
4196 add_dwarf_attr (die, attr);
4199 /* Add a string attribute value to a DIE. */
4201 static inline void
4202 add_AT_string (die, attr_kind, str)
4203 register dw_die_ref die;
4204 register enum dwarf_attribute attr_kind;
4205 register const char *str;
4207 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4209 attr->dw_attr_next = NULL;
4210 attr->dw_attr = attr_kind;
4211 attr->dw_attr_val.val_class = dw_val_class_str;
4212 attr->dw_attr_val.v.val_str = xstrdup (str);
4213 add_dwarf_attr (die, attr);
4216 static inline const char *AT_string PARAMS ((dw_attr_ref));
4217 static inline const char *
4218 AT_string (a)
4219 register dw_attr_ref a;
4221 if (a && AT_class (a) == dw_val_class_str)
4222 return a->dw_attr_val.v.val_str;
4224 abort ();
4227 /* Add a DIE reference attribute value to a DIE. */
4229 static inline void
4230 add_AT_die_ref (die, attr_kind, targ_die)
4231 register dw_die_ref die;
4232 register enum dwarf_attribute attr_kind;
4233 register dw_die_ref targ_die;
4235 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4237 attr->dw_attr_next = NULL;
4238 attr->dw_attr = attr_kind;
4239 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4240 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4241 attr->dw_attr_val.v.val_die_ref.external = 0;
4242 add_dwarf_attr (die, attr);
4245 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4246 static inline dw_die_ref
4247 AT_ref (a)
4248 register dw_attr_ref a;
4250 if (a && AT_class (a) == dw_val_class_die_ref)
4251 return a->dw_attr_val.v.val_die_ref.die;
4253 abort ();
4256 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4257 static inline int
4258 AT_ref_external (a)
4259 register dw_attr_ref a;
4261 if (a && AT_class (a) == dw_val_class_die_ref)
4262 return a->dw_attr_val.v.val_die_ref.external;
4264 return 0;
4267 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4268 static inline void
4269 set_AT_ref_external (a, i)
4270 register dw_attr_ref a;
4271 int i;
4273 if (a && AT_class (a) == dw_val_class_die_ref)
4274 a->dw_attr_val.v.val_die_ref.external = i;
4275 else
4276 abort ();
4279 /* Add an FDE reference attribute value to a DIE. */
4281 static inline void
4282 add_AT_fde_ref (die, attr_kind, targ_fde)
4283 register dw_die_ref die;
4284 register enum dwarf_attribute attr_kind;
4285 register unsigned targ_fde;
4287 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4289 attr->dw_attr_next = NULL;
4290 attr->dw_attr = attr_kind;
4291 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4292 attr->dw_attr_val.v.val_fde_index = targ_fde;
4293 add_dwarf_attr (die, attr);
4296 /* Add a location description attribute value to a DIE. */
4298 static inline void
4299 add_AT_loc (die, attr_kind, loc)
4300 register dw_die_ref die;
4301 register enum dwarf_attribute attr_kind;
4302 register dw_loc_descr_ref loc;
4304 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4306 attr->dw_attr_next = NULL;
4307 attr->dw_attr = attr_kind;
4308 attr->dw_attr_val.val_class = dw_val_class_loc;
4309 attr->dw_attr_val.v.val_loc = loc;
4310 add_dwarf_attr (die, attr);
4313 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4314 static inline dw_loc_descr_ref
4315 AT_loc (a)
4316 register dw_attr_ref a;
4318 if (a && AT_class (a) == dw_val_class_loc)
4319 return a->dw_attr_val.v.val_loc;
4321 abort ();
4324 /* Add an address constant attribute value to a DIE. */
4326 static inline void
4327 add_AT_addr (die, attr_kind, addr)
4328 register dw_die_ref die;
4329 register enum dwarf_attribute attr_kind;
4330 rtx addr;
4332 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4334 attr->dw_attr_next = NULL;
4335 attr->dw_attr = attr_kind;
4336 attr->dw_attr_val.val_class = dw_val_class_addr;
4337 attr->dw_attr_val.v.val_addr = addr;
4338 add_dwarf_attr (die, attr);
4341 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4342 static inline rtx
4343 AT_addr (a)
4344 register dw_attr_ref a;
4346 if (a && AT_class (a) == dw_val_class_addr)
4347 return a->dw_attr_val.v.val_addr;
4349 abort ();
4352 /* Add a label identifier attribute value to a DIE. */
4354 static inline void
4355 add_AT_lbl_id (die, attr_kind, lbl_id)
4356 register dw_die_ref die;
4357 register enum dwarf_attribute attr_kind;
4358 register const char *lbl_id;
4360 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4362 attr->dw_attr_next = NULL;
4363 attr->dw_attr = attr_kind;
4364 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4365 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4366 add_dwarf_attr (die, attr);
4369 /* Add a section offset attribute value to a DIE. */
4371 static inline void
4372 add_AT_lbl_offset (die, attr_kind, label)
4373 register dw_die_ref die;
4374 register enum dwarf_attribute attr_kind;
4375 register const char *label;
4377 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4379 attr->dw_attr_next = NULL;
4380 attr->dw_attr = attr_kind;
4381 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4382 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4383 add_dwarf_attr (die, attr);
4386 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4387 static inline const char *
4388 AT_lbl (a)
4389 register dw_attr_ref a;
4391 if (a && (AT_class (a) == dw_val_class_lbl_id
4392 || AT_class (a) == dw_val_class_lbl_offset))
4393 return a->dw_attr_val.v.val_lbl_id;
4395 abort ();
4398 /* Get the attribute of type attr_kind. */
4400 static inline dw_attr_ref
4401 get_AT (die, attr_kind)
4402 register dw_die_ref die;
4403 register enum dwarf_attribute attr_kind;
4405 register dw_attr_ref a;
4406 register dw_die_ref spec = NULL;
4408 if (die != NULL)
4410 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4412 if (a->dw_attr == attr_kind)
4413 return a;
4415 if (a->dw_attr == DW_AT_specification
4416 || a->dw_attr == DW_AT_abstract_origin)
4417 spec = AT_ref (a);
4420 if (spec)
4421 return get_AT (spec, attr_kind);
4424 return NULL;
4427 /* Return the "low pc" attribute value, typically associated with
4428 a subprogram DIE. Return null if the "low pc" attribute is
4429 either not prsent, or if it cannot be represented as an
4430 assembler label identifier. */
4432 static inline const char *
4433 get_AT_low_pc (die)
4434 register dw_die_ref die;
4436 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4437 return a ? AT_lbl (a) : NULL;
4440 /* Return the "high pc" attribute value, typically associated with
4441 a subprogram DIE. Return null if the "high pc" attribute is
4442 either not prsent, or if it cannot be represented as an
4443 assembler label identifier. */
4445 static inline const char *
4446 get_AT_hi_pc (die)
4447 register dw_die_ref die;
4449 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4450 return a ? AT_lbl (a) : NULL;
4453 /* Return the value of the string attribute designated by ATTR_KIND, or
4454 NULL if it is not present. */
4456 static inline const char *
4457 get_AT_string (die, attr_kind)
4458 register dw_die_ref die;
4459 register enum dwarf_attribute attr_kind;
4461 register dw_attr_ref a = get_AT (die, attr_kind);
4462 return a ? AT_string (a) : NULL;
4465 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4466 if it is not present. */
4468 static inline int
4469 get_AT_flag (die, attr_kind)
4470 register dw_die_ref die;
4471 register enum dwarf_attribute attr_kind;
4473 register dw_attr_ref a = get_AT (die, attr_kind);
4474 return a ? AT_flag (a) : 0;
4477 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4478 if it is not present. */
4480 static inline unsigned
4481 get_AT_unsigned (die, attr_kind)
4482 register dw_die_ref die;
4483 register enum dwarf_attribute attr_kind;
4485 register dw_attr_ref a = get_AT (die, attr_kind);
4486 return a ? AT_unsigned (a) : 0;
4489 static inline dw_die_ref
4490 get_AT_ref (die, attr_kind)
4491 dw_die_ref die;
4492 register enum dwarf_attribute attr_kind;
4494 register dw_attr_ref a = get_AT (die, attr_kind);
4495 return a ? AT_ref (a) : NULL;
4498 static inline int
4499 is_c_family ()
4501 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4503 return (lang == DW_LANG_C || lang == DW_LANG_C89
4504 || lang == DW_LANG_C_plus_plus);
4507 static inline int
4508 is_fortran ()
4510 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4512 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4515 static inline int
4516 is_java ()
4518 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4520 return (lang == DW_LANG_Java);
4523 /* Free up the memory used by A. */
4525 static inline void free_AT PARAMS ((dw_attr_ref));
4526 static inline void
4527 free_AT (a)
4528 dw_attr_ref a;
4530 switch (AT_class (a))
4532 case dw_val_class_str:
4533 case dw_val_class_lbl_id:
4534 case dw_val_class_lbl_offset:
4535 free (a->dw_attr_val.v.val_str);
4536 break;
4538 case dw_val_class_float:
4539 free (a->dw_attr_val.v.val_float.array);
4540 break;
4542 default:
4543 break;
4546 free (a);
4549 /* Remove the specified attribute if present. */
4551 static void
4552 remove_AT (die, attr_kind)
4553 register dw_die_ref die;
4554 register enum dwarf_attribute attr_kind;
4556 register dw_attr_ref *p;
4557 register dw_attr_ref removed = NULL;
4559 if (die != NULL)
4561 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4562 if ((*p)->dw_attr == attr_kind)
4564 removed = *p;
4565 *p = (*p)->dw_attr_next;
4566 break;
4569 if (removed != 0)
4570 free_AT (removed);
4574 /* Free up the memory used by DIE. */
4576 static inline void free_die PARAMS ((dw_die_ref));
4577 static inline void
4578 free_die (die)
4579 dw_die_ref die;
4581 remove_children (die);
4582 free (die);
4585 /* Discard the children of this DIE. */
4587 static void
4588 remove_children (die)
4589 register dw_die_ref die;
4591 register dw_die_ref child_die = die->die_child;
4593 die->die_child = NULL;
4595 while (child_die != NULL)
4597 register dw_die_ref tmp_die = child_die;
4598 register dw_attr_ref a;
4600 child_die = child_die->die_sib;
4602 for (a = tmp_die->die_attr; a != NULL;)
4604 register dw_attr_ref tmp_a = a;
4606 a = a->dw_attr_next;
4607 free_AT (tmp_a);
4610 free_die (tmp_die);
4614 /* Add a child DIE below its parent. We build the lists up in reverse
4615 addition order, and correct that in reverse_all_dies. */
4617 static inline void
4618 add_child_die (die, child_die)
4619 register dw_die_ref die;
4620 register dw_die_ref child_die;
4622 if (die != NULL && child_die != NULL)
4624 if (die == child_die)
4625 abort ();
4626 child_die->die_parent = die;
4627 child_die->die_sib = die->die_child;
4628 die->die_child = child_die;
4632 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4633 is the specification, to the front of PARENT's list of children. */
4635 static void
4636 splice_child_die (parent, child)
4637 dw_die_ref parent, child;
4639 dw_die_ref *p;
4641 /* We want the declaration DIE from inside the class, not the
4642 specification DIE at toplevel. */
4643 if (child->die_parent != parent)
4645 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4646 if (tmp)
4647 child = tmp;
4650 if (child->die_parent != parent
4651 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4652 abort ();
4654 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4655 if (*p == child)
4657 *p = child->die_sib;
4658 break;
4661 child->die_sib = parent->die_child;
4662 parent->die_child = child;
4665 /* Return a pointer to a newly created DIE node. */
4667 static inline dw_die_ref
4668 new_die (tag_value, parent_die)
4669 register enum dwarf_tag tag_value;
4670 register dw_die_ref parent_die;
4672 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
4674 die->die_tag = tag_value;
4676 if (parent_die != NULL)
4677 add_child_die (parent_die, die);
4678 else
4680 limbo_die_node *limbo_node;
4682 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4683 limbo_node->die = die;
4684 limbo_node->next = limbo_die_list;
4685 limbo_die_list = limbo_node;
4688 return die;
4691 /* Return the DIE associated with the given type specifier. */
4693 static inline dw_die_ref
4694 lookup_type_die (type)
4695 register tree type;
4697 if (TREE_CODE (type) == VECTOR_TYPE)
4698 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4699 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4702 /* Equate a DIE to a given type specifier. */
4704 static inline void
4705 equate_type_number_to_die (type, type_die)
4706 register tree type;
4707 register dw_die_ref type_die;
4709 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4712 /* Return the DIE associated with a given declaration. */
4714 static inline dw_die_ref
4715 lookup_decl_die (decl)
4716 register tree decl;
4718 register unsigned decl_id = DECL_UID (decl);
4720 return (decl_id < decl_die_table_in_use
4721 ? decl_die_table[decl_id] : NULL);
4724 /* Equate a DIE to a particular declaration. */
4726 static void
4727 equate_decl_number_to_die (decl, decl_die)
4728 register tree decl;
4729 register dw_die_ref decl_die;
4731 register unsigned decl_id = DECL_UID (decl);
4732 register unsigned num_allocated;
4734 if (decl_id >= decl_die_table_allocated)
4736 num_allocated
4737 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4738 / DECL_DIE_TABLE_INCREMENT)
4739 * DECL_DIE_TABLE_INCREMENT;
4741 decl_die_table
4742 = (dw_die_ref *) xrealloc (decl_die_table,
4743 sizeof (dw_die_ref) * num_allocated);
4745 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
4746 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4747 decl_die_table_allocated = num_allocated;
4750 if (decl_id >= decl_die_table_in_use)
4751 decl_die_table_in_use = (decl_id + 1);
4753 decl_die_table[decl_id] = decl_die;
4756 /* Keep track of the number of spaces used to indent the
4757 output of the debugging routines that print the structure of
4758 the DIE internal representation. */
4759 static int print_indent;
4761 /* Indent the line the number of spaces given by print_indent. */
4763 static inline void
4764 print_spaces (outfile)
4765 FILE *outfile;
4767 fprintf (outfile, "%*s", print_indent, "");
4770 /* Print the information associated with a given DIE, and its children.
4771 This routine is a debugging aid only. */
4773 static void
4774 print_die (die, outfile)
4775 dw_die_ref die;
4776 FILE *outfile;
4778 register dw_attr_ref a;
4779 register dw_die_ref c;
4781 print_spaces (outfile);
4782 fprintf (outfile, "DIE %4lu: %s\n",
4783 die->die_offset, dwarf_tag_name (die->die_tag));
4784 print_spaces (outfile);
4785 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4786 fprintf (outfile, " offset: %lu\n", die->die_offset);
4788 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4790 print_spaces (outfile);
4791 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4793 switch (AT_class (a))
4795 case dw_val_class_addr:
4796 fprintf (outfile, "address");
4797 break;
4798 case dw_val_class_loc:
4799 fprintf (outfile, "location descriptor");
4800 break;
4801 case dw_val_class_const:
4802 fprintf (outfile, "%ld", AT_int (a));
4803 break;
4804 case dw_val_class_unsigned_const:
4805 fprintf (outfile, "%lu", AT_unsigned (a));
4806 break;
4807 case dw_val_class_long_long:
4808 fprintf (outfile, "constant (%lu,%lu)",
4809 a->dw_attr_val.v.val_long_long.hi,
4810 a->dw_attr_val.v.val_long_long.low);
4811 break;
4812 case dw_val_class_float:
4813 fprintf (outfile, "floating-point constant");
4814 break;
4815 case dw_val_class_flag:
4816 fprintf (outfile, "%u", AT_flag (a));
4817 break;
4818 case dw_val_class_die_ref:
4819 if (AT_ref (a) != NULL)
4821 if (AT_ref (a)->die_symbol)
4822 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
4823 else
4824 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4826 else
4827 fprintf (outfile, "die -> <null>");
4828 break;
4829 case dw_val_class_lbl_id:
4830 case dw_val_class_lbl_offset:
4831 fprintf (outfile, "label: %s", AT_lbl (a));
4832 break;
4833 case dw_val_class_str:
4834 if (AT_string (a) != NULL)
4835 fprintf (outfile, "\"%s\"", AT_string (a));
4836 else
4837 fprintf (outfile, "<null>");
4838 break;
4839 default:
4840 break;
4843 fprintf (outfile, "\n");
4846 if (die->die_child != NULL)
4848 print_indent += 4;
4849 for (c = die->die_child; c != NULL; c = c->die_sib)
4850 print_die (c, outfile);
4852 print_indent -= 4;
4854 if (print_indent == 0)
4855 fprintf (outfile, "\n");
4858 /* Print the contents of the source code line number correspondence table.
4859 This routine is a debugging aid only. */
4861 static void
4862 print_dwarf_line_table (outfile)
4863 FILE *outfile;
4865 register unsigned i;
4866 register dw_line_info_ref line_info;
4868 fprintf (outfile, "\n\nDWARF source line information\n");
4869 for (i = 1; i < line_info_table_in_use; ++i)
4871 line_info = &line_info_table[i];
4872 fprintf (outfile, "%5d: ", i);
4873 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
4874 fprintf (outfile, "%6ld", line_info->dw_line_num);
4875 fprintf (outfile, "\n");
4878 fprintf (outfile, "\n\n");
4881 /* Print the information collected for a given DIE. */
4883 void
4884 debug_dwarf_die (die)
4885 dw_die_ref die;
4887 print_die (die, stderr);
4890 /* Print all DWARF information collected for the compilation unit.
4891 This routine is a debugging aid only. */
4893 void
4894 debug_dwarf ()
4896 print_indent = 0;
4897 print_die (comp_unit_die, stderr);
4898 if (! DWARF2_ASM_LINE_DEBUG_INFO)
4899 print_dwarf_line_table (stderr);
4902 /* We build up the lists of children and attributes by pushing new ones
4903 onto the beginning of the list. Reverse the lists for DIE so that
4904 they are in order of addition. */
4906 static void
4907 reverse_die_lists (die)
4908 register dw_die_ref die;
4910 register dw_die_ref c, cp, cn;
4911 register dw_attr_ref a, ap, an;
4913 for (a = die->die_attr, ap = 0; a; a = an)
4915 an = a->dw_attr_next;
4916 a->dw_attr_next = ap;
4917 ap = a;
4919 die->die_attr = ap;
4921 for (c = die->die_child, cp = 0; c; c = cn)
4923 cn = c->die_sib;
4924 c->die_sib = cp;
4925 cp = c;
4927 die->die_child = cp;
4930 /* reverse_die_lists only reverses the single die you pass it. Since
4931 we used to reverse all dies in add_sibling_attributes, which runs
4932 through all the dies, it would reverse all the dies. Now, however,
4933 since we don't call reverse_die_lists in add_sibling_attributes, we
4934 need a routine to recursively reverse all the dies. This is that
4935 routine. */
4937 static void
4938 reverse_all_dies (die)
4939 register dw_die_ref die;
4941 register dw_die_ref c;
4943 reverse_die_lists (die);
4945 for (c = die->die_child; c; c = c->die_sib)
4946 reverse_all_dies (c);
4949 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
4950 the CU for the enclosing include file, if any. BINCL_DIE is the
4951 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
4952 include file. */
4954 static dw_die_ref
4955 push_new_compile_unit (old_unit, bincl_die)
4956 dw_die_ref old_unit, bincl_die;
4958 const char *filename = get_AT_string (bincl_die, DW_AT_name);
4959 dw_die_ref new_unit = gen_compile_unit_die (filename);
4960 new_unit->die_sib = old_unit;
4961 return new_unit;
4964 /* Close an include-file CU and reopen the enclosing one. */
4966 static dw_die_ref
4967 pop_compile_unit (old_unit)
4968 dw_die_ref old_unit;
4970 dw_die_ref new_unit = old_unit->die_sib;
4971 old_unit->die_sib = NULL;
4972 return new_unit;
4975 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
4976 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
4978 /* Calculate the checksum of a location expression. */
4980 static inline void
4981 loc_checksum (loc, ctx)
4982 dw_loc_descr_ref loc;
4983 struct md5_ctx *ctx;
4985 PROCESS (loc->dw_loc_opc);
4986 PROCESS (loc->dw_loc_oprnd1);
4987 PROCESS (loc->dw_loc_oprnd2);
4990 /* Calculate the checksum of an attribute. */
4992 static void
4993 attr_checksum (at, ctx)
4994 dw_attr_ref at;
4995 struct md5_ctx *ctx;
4997 dw_loc_descr_ref loc;
4998 rtx r;
5000 PROCESS (at->dw_attr);
5002 /* We don't care about differences in file numbering. */
5003 if (at->dw_attr == DW_AT_decl_file
5004 /* Or that this was compiled with a different compiler snapshot; if
5005 the output is the same, that's what matters. */
5006 || at->dw_attr == DW_AT_producer)
5007 return;
5009 switch (AT_class (at))
5011 case dw_val_class_const:
5012 PROCESS (at->dw_attr_val.v.val_int);
5013 break;
5014 case dw_val_class_unsigned_const:
5015 PROCESS (at->dw_attr_val.v.val_unsigned);
5016 break;
5017 case dw_val_class_long_long:
5018 PROCESS (at->dw_attr_val.v.val_long_long);
5019 break;
5020 case dw_val_class_float:
5021 PROCESS (at->dw_attr_val.v.val_float);
5022 break;
5023 case dw_val_class_flag:
5024 PROCESS (at->dw_attr_val.v.val_flag);
5025 break;
5027 case dw_val_class_str:
5028 PROCESS_STRING (AT_string (at));
5029 break;
5030 case dw_val_class_addr:
5031 r = AT_addr (at);
5032 switch (GET_CODE (r))
5034 case SYMBOL_REF:
5035 PROCESS_STRING (XSTR (r, 0));
5036 break;
5038 default:
5039 abort ();
5041 break;
5043 case dw_val_class_loc:
5044 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5045 loc_checksum (loc, ctx);
5046 break;
5048 case dw_val_class_die_ref:
5049 if (AT_ref (at)->die_offset)
5050 PROCESS (AT_ref (at)->die_offset);
5051 /* FIXME else use target die name or something. */
5053 case dw_val_class_fde_ref:
5054 case dw_val_class_lbl_id:
5055 case dw_val_class_lbl_offset:
5057 default:
5058 break;
5062 /* Calculate the checksum of a DIE. */
5064 static void
5065 die_checksum (die, ctx)
5066 dw_die_ref die;
5067 struct md5_ctx *ctx;
5069 dw_die_ref c;
5070 dw_attr_ref a;
5072 PROCESS (die->die_tag);
5074 for (a = die->die_attr; a; a = a->dw_attr_next)
5075 attr_checksum (a, ctx);
5077 for (c = die->die_child; c; c = c->die_sib)
5078 die_checksum (c, ctx);
5081 #undef PROCESS
5082 #undef PROCESS_STRING
5084 /* The prefix to attach to symbols on DIEs in the current comdat debug
5085 info section. */
5086 static char *comdat_symbol_id;
5088 /* The index of the current symbol within the current comdat CU. */
5089 static unsigned int comdat_symbol_number;
5091 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5092 children, and set comdat_symbol_id accordingly. */
5094 static void
5095 compute_section_prefix (unit_die)
5096 dw_die_ref unit_die;
5098 char *p, *name;
5099 int i;
5100 unsigned char checksum[16];
5101 struct md5_ctx ctx;
5103 md5_init_ctx (&ctx);
5104 die_checksum (unit_die, &ctx);
5105 md5_finish_ctx (&ctx, checksum);
5107 p = lbasename (get_AT_string (unit_die, DW_AT_name));
5108 name = (char *) alloca (strlen (p) + 64);
5109 sprintf (name, "%s.", p);
5111 clean_symbol_name (name);
5113 p = name + strlen (name);
5114 for (i = 0; i < 4; ++i)
5116 sprintf (p, "%.2x", checksum[i]);
5117 p += 2;
5120 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5121 comdat_symbol_number = 0;
5124 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5126 static int
5127 is_type_die (die)
5128 dw_die_ref die;
5130 switch (die->die_tag)
5132 case DW_TAG_array_type:
5133 case DW_TAG_class_type:
5134 case DW_TAG_enumeration_type:
5135 case DW_TAG_pointer_type:
5136 case DW_TAG_reference_type:
5137 case DW_TAG_string_type:
5138 case DW_TAG_structure_type:
5139 case DW_TAG_subroutine_type:
5140 case DW_TAG_union_type:
5141 case DW_TAG_ptr_to_member_type:
5142 case DW_TAG_set_type:
5143 case DW_TAG_subrange_type:
5144 case DW_TAG_base_type:
5145 case DW_TAG_const_type:
5146 case DW_TAG_file_type:
5147 case DW_TAG_packed_type:
5148 case DW_TAG_volatile_type:
5149 return 1;
5150 default:
5151 return 0;
5155 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5156 Basically, we want to choose the bits that are likely to be shared between
5157 compilations (types) and leave out the bits that are specific to individual
5158 compilations (functions). */
5160 static int
5161 is_comdat_die (c)
5162 dw_die_ref c;
5164 #if 1
5165 /* I think we want to leave base types and __vtbl_ptr_type in the
5166 main CU, as we do for stabs. The advantage is a greater
5167 likelihood of sharing between objects that don't include headers
5168 in the same order (and therefore would put the base types in a
5169 different comdat). jason 8/28/00 */
5170 if (c->die_tag == DW_TAG_base_type)
5171 return 0;
5173 if (c->die_tag == DW_TAG_pointer_type
5174 || c->die_tag == DW_TAG_reference_type
5175 || c->die_tag == DW_TAG_const_type
5176 || c->die_tag == DW_TAG_volatile_type)
5178 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5179 return t ? is_comdat_die (t) : 0;
5181 #endif
5183 return is_type_die (c);
5186 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5187 compilation unit. */
5189 static int
5190 is_symbol_die (c)
5191 dw_die_ref c;
5193 if (is_type_die (c))
5194 return 1;
5195 if (get_AT (c, DW_AT_declaration)
5196 && ! get_AT (c, DW_AT_specification))
5197 return 1;
5198 return 0;
5201 static char *
5202 gen_internal_sym ()
5204 char buf[256];
5205 static int label_num;
5206 ASM_GENERATE_INTERNAL_LABEL (buf, "LDIE", label_num++);
5207 return xstrdup (buf);
5210 /* Assign symbols to all worthy DIEs under DIE. */
5212 static void
5213 assign_symbol_names (die)
5214 register dw_die_ref die;
5216 register dw_die_ref c;
5218 if (is_symbol_die (die))
5220 if (comdat_symbol_id)
5222 char *p = alloca (strlen (comdat_symbol_id) + 64);
5223 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5224 comdat_symbol_id, comdat_symbol_number++);
5225 die->die_symbol = xstrdup (p);
5227 else
5228 die->die_symbol = gen_internal_sym ();
5231 for (c = die->die_child; c != NULL; c = c->die_sib)
5232 assign_symbol_names (c);
5235 /* Traverse the DIE (which is always comp_unit_die), and set up
5236 additional compilation units for each of the include files we see
5237 bracketed by BINCL/EINCL. */
5239 static void
5240 break_out_includes (die)
5241 register dw_die_ref die;
5243 dw_die_ref *ptr;
5244 register dw_die_ref unit = NULL;
5245 limbo_die_node *node;
5247 for (ptr = &(die->die_child); *ptr; )
5249 register dw_die_ref c = *ptr;
5251 if (c->die_tag == DW_TAG_GNU_BINCL
5252 || c->die_tag == DW_TAG_GNU_EINCL
5253 || (unit && is_comdat_die (c)))
5255 /* This DIE is for a secondary CU; remove it from the main one. */
5256 *ptr = c->die_sib;
5258 if (c->die_tag == DW_TAG_GNU_BINCL)
5260 unit = push_new_compile_unit (unit, c);
5261 free_die (c);
5263 else if (c->die_tag == DW_TAG_GNU_EINCL)
5265 unit = pop_compile_unit (unit);
5266 free_die (c);
5268 else
5269 add_child_die (unit, c);
5271 else
5273 /* Leave this DIE in the main CU. */
5274 ptr = &(c->die_sib);
5275 continue;
5279 #if 0
5280 /* We can only use this in debugging, since the frontend doesn't check
5281 to make sure that we leave every include file we enter. */
5282 if (unit != NULL)
5283 abort ();
5284 #endif
5286 assign_symbol_names (die);
5287 for (node = limbo_die_list; node; node = node->next)
5289 compute_section_prefix (node->die);
5290 assign_symbol_names (node->die);
5294 /* Traverse the DIE and add a sibling attribute if it may have the
5295 effect of speeding up access to siblings. To save some space,
5296 avoid generating sibling attributes for DIE's without children. */
5298 static void
5299 add_sibling_attributes (die)
5300 register dw_die_ref die;
5302 register dw_die_ref c;
5304 if (die->die_tag != DW_TAG_compile_unit
5305 && die->die_sib && die->die_child != NULL)
5306 /* Add the sibling link to the front of the attribute list. */
5307 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5309 for (c = die->die_child; c != NULL; c = c->die_sib)
5310 add_sibling_attributes (c);
5313 /* The format of each DIE (and its attribute value pairs)
5314 is encoded in an abbreviation table. This routine builds the
5315 abbreviation table and assigns a unique abbreviation id for
5316 each abbreviation entry. The children of each die are visited
5317 recursively. */
5319 static void
5320 build_abbrev_table (die)
5321 register dw_die_ref die;
5323 register unsigned long abbrev_id;
5324 register unsigned long n_alloc;
5325 register dw_die_ref c;
5326 register dw_attr_ref d_attr, a_attr;
5328 /* Scan the DIE references, and mark as external any that refer to
5329 DIEs from other CUs (i.e. those which are not marked). */
5330 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5332 if (AT_class (d_attr) == dw_val_class_die_ref
5333 && AT_ref (d_attr)->die_mark == 0)
5335 if (AT_ref (d_attr)->die_symbol == 0)
5336 abort ();
5337 set_AT_ref_external (d_attr, 1);
5341 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5343 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5345 if (abbrev->die_tag == die->die_tag)
5347 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5349 a_attr = abbrev->die_attr;
5350 d_attr = die->die_attr;
5352 while (a_attr != NULL && d_attr != NULL)
5354 if ((a_attr->dw_attr != d_attr->dw_attr)
5355 || (value_format (a_attr) != value_format (d_attr)))
5356 break;
5358 a_attr = a_attr->dw_attr_next;
5359 d_attr = d_attr->dw_attr_next;
5362 if (a_attr == NULL && d_attr == NULL)
5363 break;
5368 if (abbrev_id >= abbrev_die_table_in_use)
5370 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5372 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5373 abbrev_die_table
5374 = (dw_die_ref *) xrealloc (abbrev_die_table,
5375 sizeof (dw_die_ref) * n_alloc);
5377 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5378 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5379 abbrev_die_table_allocated = n_alloc;
5382 ++abbrev_die_table_in_use;
5383 abbrev_die_table[abbrev_id] = die;
5386 die->die_abbrev = abbrev_id;
5387 for (c = die->die_child; c != NULL; c = c->die_sib)
5388 build_abbrev_table (c);
5391 /* Return the size of a string, including the null byte.
5393 This used to treat backslashes as escapes, and hence they were not included
5394 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5395 which treats a backslash as a backslash, escaping it if necessary, and hence
5396 we must include them in the count. */
5398 static unsigned long
5399 size_of_string (str)
5400 register const char *str;
5402 return strlen (str) + 1;
5405 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5407 static int
5408 constant_size (value)
5409 long unsigned value;
5411 int log;
5413 if (value == 0)
5414 log = 0;
5415 else
5416 log = floor_log2 (value);
5418 log = log / 8;
5419 log = 1 << (floor_log2 (log) + 1);
5421 return log;
5424 /* Return the size of a DIE, as it is represented in the
5425 .debug_info section. */
5427 static unsigned long
5428 size_of_die (die)
5429 register dw_die_ref die;
5431 register unsigned long size = 0;
5432 register dw_attr_ref a;
5434 size += size_of_uleb128 (die->die_abbrev);
5435 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5437 switch (AT_class (a))
5439 case dw_val_class_addr:
5440 size += DWARF2_ADDR_SIZE;
5441 break;
5442 case dw_val_class_loc:
5444 register unsigned long lsize = size_of_locs (AT_loc (a));
5446 /* Block length. */
5447 size += constant_size (lsize);
5448 size += lsize;
5450 break;
5451 case dw_val_class_const:
5452 size += size_of_sleb128 (AT_int (a));
5453 break;
5454 case dw_val_class_unsigned_const:
5455 size += constant_size (AT_unsigned (a));
5456 break;
5457 case dw_val_class_long_long:
5458 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5459 break;
5460 case dw_val_class_float:
5461 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5462 break;
5463 case dw_val_class_flag:
5464 size += 1;
5465 break;
5466 case dw_val_class_die_ref:
5467 size += DWARF_OFFSET_SIZE;
5468 break;
5469 case dw_val_class_fde_ref:
5470 size += DWARF_OFFSET_SIZE;
5471 break;
5472 case dw_val_class_lbl_id:
5473 size += DWARF2_ADDR_SIZE;
5474 break;
5475 case dw_val_class_lbl_offset:
5476 size += DWARF_OFFSET_SIZE;
5477 break;
5478 case dw_val_class_str:
5479 size += size_of_string (AT_string (a));
5480 break;
5481 default:
5482 abort ();
5486 return size;
5489 /* Size the debugging information associated with a given DIE.
5490 Visits the DIE's children recursively. Updates the global
5491 variable next_die_offset, on each time through. Uses the
5492 current value of next_die_offset to update the die_offset
5493 field in each DIE. */
5495 static void
5496 calc_die_sizes (die)
5497 dw_die_ref die;
5499 register dw_die_ref c;
5500 die->die_offset = next_die_offset;
5501 next_die_offset += size_of_die (die);
5503 for (c = die->die_child; c != NULL; c = c->die_sib)
5504 calc_die_sizes (c);
5506 if (die->die_child != NULL)
5507 /* Count the null byte used to terminate sibling lists. */
5508 next_die_offset += 1;
5511 /* Set the marks for a die and its children. We do this so
5512 that we know whether or not a reference needs to use FORM_ref_addr; only
5513 DIEs in the same CU will be marked. We used to clear out the offset
5514 and use that as the flag, but ran into ordering problems. */
5516 static void
5517 mark_dies (die)
5518 dw_die_ref die;
5520 register dw_die_ref c;
5521 die->die_mark = 1;
5522 for (c = die->die_child; c; c = c->die_sib)
5523 mark_dies (c);
5526 /* Clear the marks for a die and its children. */
5528 static void
5529 unmark_dies (die)
5530 dw_die_ref die;
5532 register dw_die_ref c;
5533 die->die_mark = 0;
5534 for (c = die->die_child; c; c = c->die_sib)
5535 unmark_dies (c);
5538 /* Return the size of the .debug_pubnames table generated for the
5539 compilation unit. */
5541 static unsigned long
5542 size_of_pubnames ()
5544 register unsigned long size;
5545 register unsigned i;
5547 size = DWARF_PUBNAMES_HEADER_SIZE;
5548 for (i = 0; i < pubname_table_in_use; ++i)
5550 register pubname_ref p = &pubname_table[i];
5551 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5554 size += DWARF_OFFSET_SIZE;
5555 return size;
5558 /* Return the size of the information in the .debug_aranges section. */
5560 static unsigned long
5561 size_of_aranges ()
5563 register unsigned long size;
5565 size = DWARF_ARANGES_HEADER_SIZE;
5567 /* Count the address/length pair for this compilation unit. */
5568 size += 2 * DWARF2_ADDR_SIZE;
5569 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5571 /* Count the two zero words used to terminated the address range table. */
5572 size += 2 * DWARF2_ADDR_SIZE;
5573 return size;
5576 /* Select the encoding of an attribute value. */
5578 static enum dwarf_form
5579 value_format (a)
5580 dw_attr_ref a;
5582 switch (a->dw_attr_val.val_class)
5584 case dw_val_class_addr:
5585 return DW_FORM_addr;
5586 case dw_val_class_loc:
5587 switch (constant_size (size_of_locs (AT_loc (a))))
5589 case 1:
5590 return DW_FORM_block1;
5591 case 2:
5592 return DW_FORM_block2;
5593 default:
5594 abort ();
5596 case dw_val_class_const:
5597 return DW_FORM_sdata;
5598 case dw_val_class_unsigned_const:
5599 switch (constant_size (AT_unsigned (a)))
5601 case 1:
5602 return DW_FORM_data1;
5603 case 2:
5604 return DW_FORM_data2;
5605 case 4:
5606 return DW_FORM_data4;
5607 case 8:
5608 return DW_FORM_data8;
5609 default:
5610 abort ();
5612 case dw_val_class_long_long:
5613 return DW_FORM_block1;
5614 case dw_val_class_float:
5615 return DW_FORM_block1;
5616 case dw_val_class_flag:
5617 return DW_FORM_flag;
5618 case dw_val_class_die_ref:
5619 if (AT_ref_external (a))
5620 return DW_FORM_ref_addr;
5621 else
5622 return DW_FORM_ref;
5623 case dw_val_class_fde_ref:
5624 return DW_FORM_data;
5625 case dw_val_class_lbl_id:
5626 return DW_FORM_addr;
5627 case dw_val_class_lbl_offset:
5628 return DW_FORM_data;
5629 case dw_val_class_str:
5630 return DW_FORM_string;
5631 default:
5632 abort ();
5636 /* Output the encoding of an attribute value. */
5638 static void
5639 output_value_format (a)
5640 dw_attr_ref a;
5642 enum dwarf_form form = value_format (a);
5643 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
5646 /* Output the .debug_abbrev section which defines the DIE abbreviation
5647 table. */
5649 static void
5650 output_abbrev_section ()
5652 unsigned long abbrev_id;
5654 dw_attr_ref a_attr;
5655 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5657 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5659 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
5661 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
5662 dwarf_tag_name (abbrev->die_tag));
5664 if (abbrev->die_child != NULL)
5665 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
5666 else
5667 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
5669 for (a_attr = abbrev->die_attr; a_attr != NULL;
5670 a_attr = a_attr->dw_attr_next)
5672 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
5673 dwarf_attr_name (a_attr->dw_attr));
5674 output_value_format (a_attr);
5677 dw2_asm_output_data (1, 0, NULL);
5678 dw2_asm_output_data (1, 0, NULL);
5681 /* Terminate the table. */
5682 dw2_asm_output_data (1, 0, NULL);
5685 /* Output a symbol we can use to refer to this DIE from another CU. */
5687 static inline void
5688 output_die_symbol (die)
5689 register dw_die_ref die;
5691 char *sym = die->die_symbol;
5693 if (sym == 0)
5694 return;
5696 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
5697 /* We make these global, not weak; if the target doesn't support
5698 .linkonce, it doesn't support combining the sections, so debugging
5699 will break. */
5700 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
5701 ASM_OUTPUT_LABEL (asm_out_file, sym);
5704 /* Output the DIE and its attributes. Called recursively to generate
5705 the definitions of each child DIE. */
5707 static void
5708 output_die (die)
5709 register dw_die_ref die;
5711 register dw_attr_ref a;
5712 register dw_die_ref c;
5713 register unsigned long size;
5715 /* If someone in another CU might refer to us, set up a symbol for
5716 them to point to. */
5717 if (die->die_symbol)
5718 output_die_symbol (die);
5720 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
5721 die->die_offset, dwarf_tag_name (die->die_tag));
5723 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5725 const char *name = dwarf_attr_name (a->dw_attr);
5727 switch (AT_class (a))
5729 case dw_val_class_addr:
5730 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
5731 break;
5733 case dw_val_class_loc:
5734 size = size_of_locs (AT_loc (a));
5736 /* Output the block length for this list of location operations. */
5737 dw2_asm_output_data (constant_size (size), size, "%s", name);
5739 output_loc_sequence (AT_loc (a));
5740 break;
5742 case dw_val_class_const:
5743 /* ??? It would be slightly more efficient to use a scheme like is
5744 used for unsigned constants below, but gdb 4.x does not sign
5745 extend. Gdb 5.x does sign extend. */
5746 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
5747 break;
5749 case dw_val_class_unsigned_const:
5750 dw2_asm_output_data (constant_size (AT_unsigned (a)),
5751 AT_unsigned (a), "%s", name);
5752 break;
5754 case dw_val_class_long_long:
5756 unsigned HOST_WIDE_INT first, second;
5758 dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
5759 "%s", name);
5761 if (WORDS_BIG_ENDIAN)
5763 first = a->dw_attr_val.v.val_long_long.hi;
5764 second = a->dw_attr_val.v.val_long_long.low;
5766 else
5768 first = a->dw_attr_val.v.val_long_long.low;
5769 second = a->dw_attr_val.v.val_long_long.hi;
5771 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
5772 first, "long long constant");
5773 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
5774 second, NULL);
5776 break;
5778 case dw_val_class_float:
5780 register unsigned int i;
5782 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
5783 "%s", name);
5785 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5786 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
5787 "fp constant word %u", i);
5788 break;
5791 case dw_val_class_flag:
5792 dw2_asm_output_data (1, AT_flag (a), "%s", name);
5793 break;
5795 case dw_val_class_die_ref:
5796 if (AT_ref_external (a))
5798 char *sym = AT_ref (a)->die_symbol;
5799 if (sym == 0)
5800 abort ();
5801 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
5803 else if (AT_ref (a)->die_offset == 0)
5804 abort ();
5805 else
5806 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
5807 "%s", name);
5808 break;
5810 case dw_val_class_fde_ref:
5812 char l1[20];
5813 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
5814 a->dw_attr_val.v.val_fde_index * 2);
5815 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
5817 break;
5819 case dw_val_class_lbl_id:
5820 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
5821 break;
5823 case dw_val_class_lbl_offset:
5824 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
5825 break;
5827 case dw_val_class_str:
5828 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
5829 break;
5831 default:
5832 abort ();
5836 for (c = die->die_child; c != NULL; c = c->die_sib)
5837 output_die (c);
5839 if (die->die_child != NULL)
5841 /* Add null byte to terminate sibling list. */
5842 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
5843 die->die_offset);
5847 /* Output the compilation unit that appears at the beginning of the
5848 .debug_info section, and precedes the DIE descriptions. */
5850 static void
5851 output_compilation_unit_header ()
5853 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
5854 "Length of Compilation Unit Info");
5856 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
5858 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
5859 "Offset Into Abbrev. Section");
5861 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
5864 /* Output the compilation unit DIE and its children. */
5866 static void
5867 output_comp_unit (die)
5868 dw_die_ref die;
5870 const char *secname;
5872 if (die->die_child == 0)
5873 return;
5875 /* Mark all the DIEs in this CU so we know which get local refs. */
5876 mark_dies (die);
5878 build_abbrev_table (die);
5880 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
5881 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
5882 calc_die_sizes (die);
5884 if (die->die_symbol)
5886 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
5887 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
5888 secname = tmp;
5889 die->die_symbol = NULL;
5891 else
5892 secname = (const char *) DEBUG_INFO_SECTION;
5894 /* Output debugging information. */
5895 ASM_OUTPUT_SECTION (asm_out_file, secname);
5896 output_compilation_unit_header ();
5897 output_die (die);
5899 /* Leave the marks on the main CU, so we can check them in
5900 output_pubnames. */
5901 if (die->die_symbol)
5902 unmark_dies (die);
5905 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5906 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5907 argument list, and maybe the scope. */
5909 static const char *
5910 dwarf2_name (decl, scope)
5911 tree decl;
5912 int scope;
5914 return (*decl_printable_name) (decl, scope ? 1 : 0);
5917 /* Add a new entry to .debug_pubnames if appropriate. */
5919 static void
5920 add_pubname (decl, die)
5921 tree decl;
5922 dw_die_ref die;
5924 pubname_ref p;
5926 if (! TREE_PUBLIC (decl))
5927 return;
5929 if (pubname_table_in_use == pubname_table_allocated)
5931 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
5932 pubname_table = (pubname_ref) xrealloc
5933 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
5936 p = &pubname_table[pubname_table_in_use++];
5937 p->die = die;
5939 p->name = xstrdup (dwarf2_name (decl, 1));
5942 /* Output the public names table used to speed up access to externally
5943 visible names. For now, only generate entries for externally
5944 visible procedures. */
5946 static void
5947 output_pubnames ()
5949 register unsigned i;
5950 register unsigned long pubnames_length = size_of_pubnames ();
5952 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
5953 "Length of Public Names Info");
5955 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
5957 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
5958 "Offset of Compilation Unit Info");
5960 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
5961 "Compilation Unit Length");
5963 for (i = 0; i < pubname_table_in_use; ++i)
5965 register pubname_ref pub = &pubname_table[i];
5967 /* We shouldn't see pubnames for DIEs outside of the main CU. */
5968 if (pub->die->die_mark == 0)
5969 abort ();
5971 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
5972 "DIE offset");
5974 dw2_asm_output_nstring (pub->name, -1, "external name");
5977 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
5980 /* Add a new entry to .debug_aranges if appropriate. */
5982 static void
5983 add_arange (decl, die)
5984 tree decl;
5985 dw_die_ref die;
5987 if (! DECL_SECTION_NAME (decl))
5988 return;
5990 if (arange_table_in_use == arange_table_allocated)
5992 arange_table_allocated += ARANGE_TABLE_INCREMENT;
5993 arange_table
5994 = (arange_ref) xrealloc (arange_table,
5995 arange_table_allocated * sizeof (dw_die_ref));
5998 arange_table[arange_table_in_use++] = die;
6001 /* Output the information that goes into the .debug_aranges table.
6002 Namely, define the beginning and ending address range of the
6003 text section generated for this compilation unit. */
6005 static void
6006 output_aranges ()
6008 register unsigned i;
6009 register unsigned long aranges_length = size_of_aranges ();
6011 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6012 "Length of Address Ranges Info");
6014 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6016 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6017 "Offset of Compilation Unit Info");
6019 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6021 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6023 /* We need to align to twice the pointer size here. */
6024 if (DWARF_ARANGES_PAD_SIZE)
6026 /* Pad using a 2 byte words so that padding is correct for any
6027 pointer size. */
6028 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6029 2 * DWARF2_ADDR_SIZE);
6030 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6031 dw2_asm_output_data (2, 0, NULL);
6034 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6035 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6036 text_section_label, "Length");
6038 for (i = 0; i < arange_table_in_use; ++i)
6040 dw_die_ref die = arange_table[i];
6042 /* We shouldn't see aranges for DIEs outside of the main CU. */
6043 if (die->die_mark == 0)
6044 abort ();
6046 if (die->die_tag == DW_TAG_subprogram)
6048 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6049 "Address");
6050 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6051 get_AT_low_pc (die), "Length");
6053 else
6055 /* A static variable; extract the symbol from DW_AT_location.
6056 Note that this code isn't currently hit, as we only emit
6057 aranges for functions (jason 9/23/99). */
6059 dw_attr_ref a = get_AT (die, DW_AT_location);
6060 dw_loc_descr_ref loc;
6061 if (! a || AT_class (a) != dw_val_class_loc)
6062 abort ();
6064 loc = AT_loc (a);
6065 if (loc->dw_loc_opc != DW_OP_addr)
6066 abort ();
6068 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6069 loc->dw_loc_oprnd1.v.val_addr, "Address");
6070 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6071 get_AT_unsigned (die, DW_AT_byte_size),
6072 "Length");
6076 /* Output the terminator words. */
6077 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6078 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6082 /* Data structure containing information about input files. */
6083 struct file_info
6085 char *path; /* Complete file name. */
6086 char *fname; /* File name part. */
6087 int length; /* Length of entire string. */
6088 int file_idx; /* Index in input file table. */
6089 int dir_idx; /* Index in directory table. */
6092 /* Data structure containing information about directories with source
6093 files. */
6094 struct dir_info
6096 char *path; /* Path including directory name. */
6097 int length; /* Path length. */
6098 int prefix; /* Index of directory entry which is a prefix. */
6099 int count; /* Number of files in this directory. */
6100 int dir_idx; /* Index of directory used as base. */
6101 int used; /* Used in the end? */
6104 /* Callback function for file_info comparison. We sort by looking at
6105 the directories in the path. */
6106 static int
6107 file_info_cmp (p1, p2)
6108 const void *p1;
6109 const void *p2;
6111 const struct file_info *s1 = p1;
6112 const struct file_info *s2 = p2;
6113 unsigned char *cp1;
6114 unsigned char *cp2;
6116 /* Take care of file names without directories. */
6117 if (s1->path == s1->fname)
6118 return -1;
6119 else if (s2->path == s2->fname)
6120 return 1;
6122 cp1 = (unsigned char *) s1->path;
6123 cp2 = (unsigned char *) s2->path;
6125 while (1)
6127 ++cp1;
6128 ++cp2;
6129 /* Reached the end of the first path? */
6130 if (cp1 == (unsigned char *) s1->fname)
6131 /* It doesn't really matter in which order files from the
6132 same directory are sorted in. Therefore don't test for
6133 the second path reaching the end. */
6134 return -1;
6135 else if (cp2 == (unsigned char *) s2->fname)
6136 return 1;
6138 /* Character of current path component the same? */
6139 if (*cp1 != *cp2)
6140 return *cp1 - *cp2;
6144 /* Output the directory table and the file name table. We try to minimize
6145 the total amount of memory needed. A heuristic is used to avoid large
6146 slowdowns with many input files. */
6147 static void
6148 output_file_names ()
6150 struct file_info *files;
6151 struct dir_info *dirs;
6152 int *saved;
6153 int *savehere;
6154 int *backmap;
6155 int ndirs;
6156 int idx_offset;
6157 int i;
6158 int idx;
6160 /* Allocate the various arrays we need. */
6161 files = (struct file_info *) alloca (file_table.in_use
6162 * sizeof (struct file_info));
6163 dirs = (struct dir_info *) alloca (file_table.in_use
6164 * sizeof (struct dir_info));
6166 /* Sort the file names. */
6167 for (i = 1; i < (int) file_table.in_use; ++i)
6169 char *f;
6171 /* Skip all leading "./". */
6172 f = file_table.table[i];
6173 while (f[0] == '.' && f[1] == '/')
6174 f += 2;
6176 /* Create a new array entry. */
6177 files[i].path = f;
6178 files[i].length = strlen (f);
6179 files[i].file_idx = i;
6181 /* Search for the file name part. */
6182 f = strrchr (f, '/');
6183 files[i].fname = f == NULL ? files[i].path : f + 1;
6185 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6187 /* Find all the different directories used. */
6188 dirs[0].path = files[1].path;
6189 dirs[0].length = files[1].fname - files[1].path;
6190 dirs[0].prefix = -1;
6191 dirs[0].count = 1;
6192 dirs[0].dir_idx = 0;
6193 dirs[0].used = 0;
6194 files[1].dir_idx = 0;
6195 ndirs = 1;
6197 for (i = 2; i < (int) file_table.in_use; ++i)
6198 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6199 && memcmp (dirs[ndirs - 1].path, files[i].path,
6200 dirs[ndirs - 1].length) == 0)
6202 /* Same directory as last entry. */
6203 files[i].dir_idx = ndirs - 1;
6204 ++dirs[ndirs - 1].count;
6206 else
6208 int j;
6210 /* This is a new directory. */
6211 dirs[ndirs].path = files[i].path;
6212 dirs[ndirs].length = files[i].fname - files[i].path;
6213 dirs[ndirs].count = 1;
6214 dirs[ndirs].dir_idx = ndirs;
6215 dirs[ndirs].used = 0;
6216 files[i].dir_idx = ndirs;
6218 /* Search for a prefix. */
6219 dirs[ndirs].prefix = -1;
6220 for (j = 0; j < ndirs; ++j)
6221 if (dirs[j].length < dirs[ndirs].length
6222 && dirs[j].length > 1
6223 && (dirs[ndirs].prefix == -1
6224 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6225 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6226 dirs[ndirs].prefix = j;
6228 ++ndirs;
6231 /* Now to the actual work. We have to find a subset of the
6232 directories which allow expressing the file name using references
6233 to the directory table with the least amount of characters. We
6234 do not do an exhaustive search where we would have to check out
6235 every combination of every single possible prefix. Instead we
6236 use a heuristic which provides nearly optimal results in most
6237 cases and never is much off. */
6238 saved = (int *) alloca (ndirs * sizeof (int));
6239 savehere = (int *) alloca (ndirs * sizeof (int));
6241 memset (saved, '\0', ndirs * sizeof (saved[0]));
6242 for (i = 0; i < ndirs; ++i)
6244 int j;
6245 int total;
6247 /* We can always save some space for the current directory. But
6248 this does not mean it will be enough to justify adding the
6249 directory. */
6250 savehere[i] = dirs[i].length;
6251 total = (savehere[i] - saved[i]) * dirs[i].count;
6253 for (j = i + 1; j < ndirs; ++j)
6255 savehere[j] = 0;
6257 if (saved[j] < dirs[i].length)
6259 /* Determine whether the dirs[i] path is a prefix of the
6260 dirs[j] path. */
6261 int k;
6263 k = dirs[j].prefix;
6264 while (k != -1 && k != i)
6265 k = dirs[k].prefix;
6267 if (k == i)
6269 /* Yes it is. We can possibly safe some memory but
6270 writing the filenames in dirs[j] relative to
6271 dirs[i]. */
6272 savehere[j] = dirs[i].length;
6273 total += (savehere[j] - saved[j]) * dirs[j].count;
6278 /* Check whether we can safe enough to justify adding the dirs[i]
6279 directory. */
6280 if (total > dirs[i].length + 1)
6282 /* It's worthwhile adding. */
6283 for (j = i; j < ndirs; ++j)
6284 if (savehere[j] > 0)
6286 /* Remember how much we saved for this directory so far. */
6287 saved[j] = savehere[j];
6289 /* Remember the prefix directory. */
6290 dirs[j].dir_idx = i;
6295 /* We have to emit them in the order they appear in the file_table
6296 array since the index is used in the debug info generation. To
6297 do this efficiently we generate a back-mapping of the indices
6298 first. */
6299 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6300 for (i = 1; i < (int) file_table.in_use; ++i)
6302 backmap[files[i].file_idx] = i;
6303 /* Mark this directory as used. */
6304 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6307 /* That was it. We are ready to emit the information. First the
6308 directory name table. Here we have to make sure that the first
6309 actually emitted directory name has the index one. Zero is
6310 reserved for the current working directory. Make sure we do not
6311 confuse these indices with the one for the constructed table
6312 (even though most of the time they are identical). */
6313 idx = 1;
6314 idx_offset = dirs[0].length > 0 ? 1 : 0;
6315 for (i = 1 - idx_offset; i < ndirs; ++i)
6316 if (dirs[i].used != 0)
6318 dirs[i].used = idx++;
6319 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6320 "Directory Entry: 0x%x", dirs[i].used);
6322 dw2_asm_output_data (1, 0, "End directory table");
6324 /* Correct the index for the current working directory entry if it
6325 exists. */
6326 if (idx_offset == 0)
6327 dirs[0].used = 0;
6329 /* Now write all the file names. */
6330 for (i = 1; i < (int) file_table.in_use; ++i)
6332 int file_idx = backmap[i];
6333 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6335 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6336 "File Entry: 0x%x", i);
6338 /* Include directory index. */
6339 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6341 /* Modification time. */
6342 dw2_asm_output_data_uleb128 (0, NULL);
6344 /* File length in bytes. */
6345 dw2_asm_output_data_uleb128 (0, NULL);
6347 dw2_asm_output_data (1, 0, "End file name table");
6351 /* Output the source line number correspondence information. This
6352 information goes into the .debug_line section. */
6354 static void
6355 output_line_info ()
6357 char l1[20], l2[20], p1[20], p2[20];
6358 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6359 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6360 register unsigned opc;
6361 register unsigned n_op_args;
6362 register unsigned long lt_index;
6363 register unsigned long current_line;
6364 register long line_offset;
6365 register long line_delta;
6366 register unsigned long current_file;
6367 register unsigned long function;
6369 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
6370 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
6371 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
6372 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
6374 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
6375 "Length of Source Line Info");
6376 ASM_OUTPUT_LABEL (asm_out_file, l1);
6378 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6380 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
6381 ASM_OUTPUT_LABEL (asm_out_file, p1);
6383 dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH,
6384 "Minimum Instruction Length");
6386 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
6387 "Default is_stmt_start flag");
6389 dw2_asm_output_data (1, DWARF_LINE_BASE,
6390 "Line Base Value (Special Opcodes)");
6392 dw2_asm_output_data (1, DWARF_LINE_RANGE,
6393 "Line Range Value (Special Opcodes)");
6395 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
6396 "Special Opcode Base");
6398 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6400 switch (opc)
6402 case DW_LNS_advance_pc:
6403 case DW_LNS_advance_line:
6404 case DW_LNS_set_file:
6405 case DW_LNS_set_column:
6406 case DW_LNS_fixed_advance_pc:
6407 n_op_args = 1;
6408 break;
6409 default:
6410 n_op_args = 0;
6411 break;
6414 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
6415 opc, n_op_args);
6418 /* Write out the information about the files we use. */
6419 output_file_names ();
6420 ASM_OUTPUT_LABEL (asm_out_file, p2);
6422 /* We used to set the address register to the first location in the text
6423 section here, but that didn't accomplish anything since we already
6424 have a line note for the opening brace of the first function. */
6426 /* Generate the line number to PC correspondence table, encoded as
6427 a series of state machine operations. */
6428 current_file = 1;
6429 current_line = 1;
6430 strcpy (prev_line_label, text_section_label);
6431 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6433 register dw_line_info_ref line_info = &line_info_table[lt_index];
6435 #if 0
6436 /* Disable this optimization for now; GDB wants to see two line notes
6437 at the beginning of a function so it can find the end of the
6438 prologue. */
6440 /* Don't emit anything for redundant notes. Just updating the
6441 address doesn't accomplish anything, because we already assume
6442 that anything after the last address is this line. */
6443 if (line_info->dw_line_num == current_line
6444 && line_info->dw_file_num == current_file)
6445 continue;
6446 #endif
6448 /* Emit debug info for the address of the current line.
6450 Unfortunately, we have little choice here currently, and must always
6451 use the most general form. Gcc does not know the address delta
6452 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
6453 attributes which will give an upper bound on the address range. We
6454 could perhaps use length attributes to determine when it is safe to
6455 use DW_LNS_fixed_advance_pc. */
6457 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6458 if (0)
6460 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6461 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6462 "DW_LNS_fixed_advance_pc");
6463 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6465 else
6467 /* This can handle any delta. This takes
6468 4+DWARF2_ADDR_SIZE bytes. */
6469 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6470 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6471 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6472 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6474 strcpy (prev_line_label, line_label);
6476 /* Emit debug info for the source file of the current line, if
6477 different from the previous line. */
6478 if (line_info->dw_file_num != current_file)
6480 current_file = line_info->dw_file_num;
6481 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6482 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6483 file_table.table[current_file]);
6486 /* Emit debug info for the current line number, choosing the encoding
6487 that uses the least amount of space. */
6488 if (line_info->dw_line_num != current_line)
6490 line_offset = line_info->dw_line_num - current_line;
6491 line_delta = line_offset - DWARF_LINE_BASE;
6492 current_line = line_info->dw_line_num;
6493 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6495 /* This can handle deltas from -10 to 234, using the current
6496 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6497 takes 1 byte. */
6498 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6499 "line %lu", current_line);
6501 else
6503 /* This can handle any delta. This takes at least 4 bytes,
6504 depending on the value being encoded. */
6505 dw2_asm_output_data (1, DW_LNS_advance_line,
6506 "advance to line %lu", current_line);
6507 dw2_asm_output_data_sleb128 (line_offset, NULL);
6508 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6511 else
6513 /* We still need to start a new row, so output a copy insn. */
6514 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6518 /* Emit debug info for the address of the end of the function. */
6519 if (0)
6521 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6522 "DW_LNS_fixed_advance_pc");
6523 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
6525 else
6527 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6528 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6529 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6530 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
6533 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6534 dw2_asm_output_data_uleb128 (1, NULL);
6535 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6537 function = 0;
6538 current_file = 1;
6539 current_line = 1;
6540 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
6542 register dw_separate_line_info_ref line_info
6543 = &separate_line_info_table[lt_index];
6545 #if 0
6546 /* Don't emit anything for redundant notes. */
6547 if (line_info->dw_line_num == current_line
6548 && line_info->dw_file_num == current_file
6549 && line_info->function == function)
6550 goto cont;
6551 #endif
6553 /* Emit debug info for the address of the current line. If this is
6554 a new function, or the first line of a function, then we need
6555 to handle it differently. */
6556 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
6557 lt_index);
6558 if (function != line_info->function)
6560 function = line_info->function;
6562 /* Set the address register to the first line in the function */
6563 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6564 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6565 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6566 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6568 else
6570 /* ??? See the DW_LNS_advance_pc comment above. */
6571 if (0)
6573 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6574 "DW_LNS_fixed_advance_pc");
6575 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6577 else
6579 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6580 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6581 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6582 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6585 strcpy (prev_line_label, line_label);
6587 /* Emit debug info for the source file of the current line, if
6588 different from the previous line. */
6589 if (line_info->dw_file_num != current_file)
6591 current_file = line_info->dw_file_num;
6592 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6593 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6594 file_table.table[current_file]);
6597 /* Emit debug info for the current line number, choosing the encoding
6598 that uses the least amount of space. */
6599 if (line_info->dw_line_num != current_line)
6601 line_offset = line_info->dw_line_num - current_line;
6602 line_delta = line_offset - DWARF_LINE_BASE;
6603 current_line = line_info->dw_line_num;
6604 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6605 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6606 "line %lu", current_line);
6607 else
6609 dw2_asm_output_data (1, DW_LNS_advance_line,
6610 "advance to line %lu", current_line);
6611 dw2_asm_output_data_sleb128 (line_offset, NULL);
6612 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6615 else
6616 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6618 #if 0
6619 cont:
6620 #endif
6621 ++lt_index;
6623 /* If we're done with a function, end its sequence. */
6624 if (lt_index == separate_line_info_table_in_use
6625 || separate_line_info_table[lt_index].function != function)
6627 current_file = 1;
6628 current_line = 1;
6630 /* Emit debug info for the address of the end of the function. */
6631 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
6632 if (0)
6634 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6635 "DW_LNS_fixed_advance_pc");
6636 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6638 else
6640 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6641 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6642 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6643 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6646 /* Output the marker for the end of this sequence. */
6647 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6648 dw2_asm_output_data_uleb128 (1, NULL);
6649 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6653 /* Output the marker for the end of the line number info. */
6654 ASM_OUTPUT_LABEL (asm_out_file, l2);
6657 /* Given a pointer to a tree node for some base type, return a pointer to
6658 a DIE that describes the given type.
6660 This routine must only be called for GCC type nodes that correspond to
6661 Dwarf base (fundamental) types. */
6663 static dw_die_ref
6664 base_type_die (type)
6665 register tree type;
6667 register dw_die_ref base_type_result;
6668 register const char *type_name;
6669 register enum dwarf_type encoding;
6670 register tree name = TYPE_NAME (type);
6672 if (TREE_CODE (type) == ERROR_MARK
6673 || TREE_CODE (type) == VOID_TYPE)
6674 return 0;
6676 if (name)
6678 if (TREE_CODE (name) == TYPE_DECL)
6679 name = DECL_NAME (name);
6681 type_name = IDENTIFIER_POINTER (name);
6683 else
6684 type_name = "__unknown__";
6686 switch (TREE_CODE (type))
6688 case INTEGER_TYPE:
6689 /* Carefully distinguish the C character types, without messing
6690 up if the language is not C. Note that we check only for the names
6691 that contain spaces; other names might occur by coincidence in other
6692 languages. */
6693 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6694 && (type == char_type_node
6695 || ! strcmp (type_name, "signed char")
6696 || ! strcmp (type_name, "unsigned char"))))
6698 if (TREE_UNSIGNED (type))
6699 encoding = DW_ATE_unsigned;
6700 else
6701 encoding = DW_ATE_signed;
6702 break;
6704 /* else fall through. */
6706 case CHAR_TYPE:
6707 /* GNU Pascal/Ada CHAR type. Not used in C. */
6708 if (TREE_UNSIGNED (type))
6709 encoding = DW_ATE_unsigned_char;
6710 else
6711 encoding = DW_ATE_signed_char;
6712 break;
6714 case REAL_TYPE:
6715 encoding = DW_ATE_float;
6716 break;
6718 /* Dwarf2 doesn't know anything about complex ints, so use
6719 a user defined type for it. */
6720 case COMPLEX_TYPE:
6721 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6722 encoding = DW_ATE_complex_float;
6723 else
6724 encoding = DW_ATE_lo_user;
6725 break;
6727 case BOOLEAN_TYPE:
6728 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6729 encoding = DW_ATE_boolean;
6730 break;
6732 default:
6733 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6736 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6737 if (demangle_name_func)
6738 type_name = (*demangle_name_func) (type_name);
6740 add_AT_string (base_type_result, DW_AT_name, type_name);
6741 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6742 int_size_in_bytes (type));
6743 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6745 return base_type_result;
6748 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6749 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6750 a given type is generally the same as the given type, except that if the
6751 given type is a pointer or reference type, then the root type of the given
6752 type is the root type of the "basis" type for the pointer or reference
6753 type. (This definition of the "root" type is recursive.) Also, the root
6754 type of a `const' qualified type or a `volatile' qualified type is the
6755 root type of the given type without the qualifiers. */
6757 static tree
6758 root_type (type)
6759 register tree type;
6761 if (TREE_CODE (type) == ERROR_MARK)
6762 return error_mark_node;
6764 switch (TREE_CODE (type))
6766 case ERROR_MARK:
6767 return error_mark_node;
6769 case POINTER_TYPE:
6770 case REFERENCE_TYPE:
6771 return type_main_variant (root_type (TREE_TYPE (type)));
6773 default:
6774 return type_main_variant (type);
6778 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6779 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6781 static inline int
6782 is_base_type (type)
6783 register tree type;
6785 switch (TREE_CODE (type))
6787 case ERROR_MARK:
6788 case VOID_TYPE:
6789 case INTEGER_TYPE:
6790 case REAL_TYPE:
6791 case COMPLEX_TYPE:
6792 case BOOLEAN_TYPE:
6793 case CHAR_TYPE:
6794 return 1;
6796 case SET_TYPE:
6797 case ARRAY_TYPE:
6798 case RECORD_TYPE:
6799 case UNION_TYPE:
6800 case QUAL_UNION_TYPE:
6801 case ENUMERAL_TYPE:
6802 case FUNCTION_TYPE:
6803 case METHOD_TYPE:
6804 case POINTER_TYPE:
6805 case REFERENCE_TYPE:
6806 case FILE_TYPE:
6807 case OFFSET_TYPE:
6808 case LANG_TYPE:
6809 case VECTOR_TYPE:
6810 return 0;
6812 default:
6813 abort ();
6816 return 0;
6819 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6820 entry that chains various modifiers in front of the given type. */
6822 static dw_die_ref
6823 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6824 register tree type;
6825 register int is_const_type;
6826 register int is_volatile_type;
6827 register dw_die_ref context_die;
6829 register enum tree_code code = TREE_CODE (type);
6830 register dw_die_ref mod_type_die = NULL;
6831 register dw_die_ref sub_die = NULL;
6832 register tree item_type = NULL;
6834 if (code != ERROR_MARK)
6836 tree qualified_type;
6838 /* See if we already have the appropriately qualified variant of
6839 this type. */
6840 qualified_type
6841 = get_qualified_type (type,
6842 ((is_const_type ? TYPE_QUAL_CONST : 0)
6843 | (is_volatile_type
6844 ? TYPE_QUAL_VOLATILE : 0)));
6845 /* If we do, then we can just use its DIE, if it exists. */
6846 if (qualified_type)
6848 mod_type_die = lookup_type_die (qualified_type);
6849 if (mod_type_die)
6850 return mod_type_die;
6853 /* Handle C typedef types. */
6854 if (qualified_type && TYPE_NAME (qualified_type)
6855 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
6856 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
6858 tree type_name = TYPE_NAME (qualified_type);
6859 tree dtype = TREE_TYPE (type_name);
6860 if (qualified_type == dtype)
6862 /* For a named type, use the typedef. */
6863 gen_type_die (qualified_type, context_die);
6864 mod_type_die = lookup_type_die (qualified_type);
6867 else if (is_const_type < TYPE_READONLY (dtype)
6868 || is_volatile_type < TYPE_VOLATILE (dtype))
6869 /* cv-unqualified version of named type. Just use the unnamed
6870 type to which it refers. */
6871 mod_type_die
6872 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
6873 is_const_type, is_volatile_type,
6874 context_die);
6875 /* Else cv-qualified version of named type; fall through. */
6878 if (mod_type_die)
6879 /* OK. */
6881 else if (is_const_type)
6883 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
6884 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
6886 else if (is_volatile_type)
6888 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6889 sub_die = modified_type_die (type, 0, 0, context_die);
6891 else if (code == POINTER_TYPE)
6893 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
6894 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6895 #if 0
6896 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6897 #endif
6898 item_type = TREE_TYPE (type);
6900 else if (code == REFERENCE_TYPE)
6902 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
6903 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6904 #if 0
6905 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6906 #endif
6907 item_type = TREE_TYPE (type);
6909 else if (is_base_type (type))
6910 mod_type_die = base_type_die (type);
6911 else
6913 gen_type_die (type, context_die);
6915 /* We have to get the type_main_variant here (and pass that to the
6916 `lookup_type_die' routine) because the ..._TYPE node we have
6917 might simply be a *copy* of some original type node (where the
6918 copy was created to help us keep track of typedef names) and
6919 that copy might have a different TYPE_UID from the original
6920 ..._TYPE node. */
6921 mod_type_die = lookup_type_die (type_main_variant (type));
6922 if (mod_type_die == NULL)
6923 abort ();
6927 equate_type_number_to_die (type, mod_type_die);
6928 if (item_type)
6929 /* We must do this after the equate_type_number_to_die call, in case
6930 this is a recursive type. This ensures that the modified_type_die
6931 recursion will terminate even if the type is recursive. Recursive
6932 types are possible in Ada. */
6933 sub_die = modified_type_die (item_type,
6934 TYPE_READONLY (item_type),
6935 TYPE_VOLATILE (item_type),
6936 context_die);
6938 if (sub_die != NULL)
6939 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
6941 return mod_type_die;
6944 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6945 an enumerated type. */
6947 static inline int
6948 type_is_enum (type)
6949 register tree type;
6951 return TREE_CODE (type) == ENUMERAL_TYPE;
6954 /* Return the register number described by a given RTL node. */
6956 static unsigned int
6957 reg_number (rtl)
6958 register rtx rtl;
6960 register unsigned regno = REGNO (rtl);
6962 if (regno >= FIRST_PSEUDO_REGISTER)
6964 warning ("internal regno botch: regno = %d\n", regno);
6965 regno = 0;
6968 regno = DBX_REGISTER_NUMBER (regno);
6969 return regno;
6972 /* Return a location descriptor that designates a machine register. */
6974 static dw_loc_descr_ref
6975 reg_loc_descriptor (rtl)
6976 register rtx rtl;
6978 register dw_loc_descr_ref loc_result = NULL;
6979 register unsigned reg = reg_number (rtl);
6981 if (reg <= 31)
6982 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
6983 else
6984 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
6986 return loc_result;
6989 /* Return a location descriptor that designates a constant. */
6991 static dw_loc_descr_ref
6992 int_loc_descriptor (i)
6993 HOST_WIDE_INT i;
6995 enum dwarf_location_atom op;
6997 /* Pick the smallest representation of a constant, rather than just
6998 defaulting to the LEB encoding. */
6999 if (i >= 0)
7001 if (i <= 31)
7002 op = DW_OP_lit0 + i;
7003 else if (i <= 0xff)
7004 op = DW_OP_const1u;
7005 else if (i <= 0xffff)
7006 op = DW_OP_const2u;
7007 else if (HOST_BITS_PER_WIDE_INT == 32
7008 || i <= 0xffffffff)
7009 op = DW_OP_const4u;
7010 else
7011 op = DW_OP_constu;
7013 else
7015 if (i >= -0x80)
7016 op = DW_OP_const1s;
7017 else if (i >= -0x8000)
7018 op = DW_OP_const2s;
7019 else if (HOST_BITS_PER_WIDE_INT == 32
7020 || i >= -0x80000000)
7021 op = DW_OP_const4s;
7022 else
7023 op = DW_OP_consts;
7026 return new_loc_descr (op, i, 0);
7029 /* Return a location descriptor that designates a base+offset location. */
7031 static dw_loc_descr_ref
7032 based_loc_descr (reg, offset)
7033 unsigned reg;
7034 long int offset;
7036 register dw_loc_descr_ref loc_result;
7037 /* For the "frame base", we use the frame pointer or stack pointer
7038 registers, since the RTL for local variables is relative to one of
7039 them. */
7040 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7041 ? HARD_FRAME_POINTER_REGNUM
7042 : STACK_POINTER_REGNUM);
7044 if (reg == fp_reg)
7045 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7046 else if (reg <= 31)
7047 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7048 else
7049 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7051 return loc_result;
7054 /* Return true if this RTL expression describes a base+offset calculation. */
7056 static inline int
7057 is_based_loc (rtl)
7058 register rtx rtl;
7060 return (GET_CODE (rtl) == PLUS
7061 && ((GET_CODE (XEXP (rtl, 0)) == REG
7062 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7065 /* The following routine converts the RTL for a variable or parameter
7066 (resident in memory) into an equivalent Dwarf representation of a
7067 mechanism for getting the address of that same variable onto the top of a
7068 hypothetical "address evaluation" stack.
7070 When creating memory location descriptors, we are effectively transforming
7071 the RTL for a memory-resident object into its Dwarf postfix expression
7072 equivalent. This routine recursively descends an RTL tree, turning
7073 it into Dwarf postfix code as it goes.
7075 MODE is the mode of the memory reference, needed to handle some
7076 autoincrement addressing modes. */
7078 static dw_loc_descr_ref
7079 mem_loc_descriptor (rtl, mode)
7080 register rtx rtl;
7081 enum machine_mode mode;
7083 dw_loc_descr_ref mem_loc_result = NULL;
7084 /* Note that for a dynamically sized array, the location we will generate a
7085 description of here will be the lowest numbered location which is
7086 actually within the array. That's *not* necessarily the same as the
7087 zeroth element of the array. */
7089 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7090 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7091 #endif
7093 switch (GET_CODE (rtl))
7095 case POST_INC:
7096 case POST_DEC:
7097 case POST_MODIFY:
7098 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7099 just fall into the SUBREG code. */
7101 /* Fall through. */
7103 case SUBREG:
7104 /* The case of a subreg may arise when we have a local (register)
7105 variable or a formal (register) parameter which doesn't quite fill
7106 up an entire register. For now, just assume that it is
7107 legitimate to make the Dwarf info refer to the whole register which
7108 contains the given subreg. */
7109 rtl = SUBREG_REG (rtl);
7111 /* Fall through. */
7113 case REG:
7114 /* Whenever a register number forms a part of the description of the
7115 method for calculating the (dynamic) address of a memory resident
7116 object, DWARF rules require the register number be referred to as
7117 a "base register". This distinction is not based in any way upon
7118 what category of register the hardware believes the given register
7119 belongs to. This is strictly DWARF terminology we're dealing with
7120 here. Note that in cases where the location of a memory-resident
7121 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7122 OP_CONST (0)) the actual DWARF location descriptor that we generate
7123 may just be OP_BASEREG (basereg). This may look deceptively like
7124 the object in question was allocated to a register (rather than in
7125 memory) so DWARF consumers need to be aware of the subtle
7126 distinction between OP_REG and OP_BASEREG. */
7127 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7128 break;
7130 case MEM:
7131 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7132 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7133 break;
7135 case LABEL_REF:
7136 /* Some ports can transform a symbol ref into a label ref, because
7137 the symbol ref is too far away and has to be dumped into a constant
7138 pool. */
7139 case CONST:
7140 case SYMBOL_REF:
7141 /* Alternatively, the symbol in the constant pool can be referenced
7142 by a different symbol. */
7143 if (GET_CODE (rtl) == SYMBOL_REF
7144 && CONSTANT_POOL_ADDRESS_P (rtl))
7146 rtx tmp = get_pool_constant (rtl);
7147 /* Doesn't work for floating point constants. */
7148 if (! (GET_CODE (tmp) == CONST_DOUBLE && GET_MODE (tmp) != VOIDmode))
7149 rtl = tmp;
7153 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7154 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7155 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7156 break;
7158 case PRE_MODIFY:
7159 /* Extract the PLUS expression nested inside and fall into
7160 PLUS code bellow. */
7161 rtl = XEXP (rtl, 1);
7162 goto plus;
7164 case PRE_INC:
7165 case PRE_DEC:
7166 /* Turn these into a PLUS expression and fall into the PLUS code
7167 below. */
7168 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7169 GEN_INT (GET_CODE (rtl) == PRE_INC
7170 ? GET_MODE_UNIT_SIZE (mode)
7171 : -GET_MODE_UNIT_SIZE (mode)));
7173 /* Fall through. */
7175 case PLUS:
7176 plus:
7177 if (is_based_loc (rtl))
7178 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7179 INTVAL (XEXP (rtl, 1)));
7180 else
7182 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7184 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7185 && INTVAL (XEXP (rtl, 1)) >= 0)
7187 add_loc_descr (&mem_loc_result,
7188 new_loc_descr (DW_OP_plus_uconst,
7189 INTVAL (XEXP (rtl, 1)), 0));
7191 else
7193 add_loc_descr (&mem_loc_result,
7194 mem_loc_descriptor (XEXP (rtl, 1), mode));
7195 add_loc_descr (&mem_loc_result,
7196 new_loc_descr (DW_OP_plus, 0, 0));
7199 break;
7201 case MULT:
7202 /* If a pseudo-reg is optimized away, it is possible for it to
7203 be replaced with a MEM containing a multiply. */
7204 add_loc_descr (&mem_loc_result,
7205 mem_loc_descriptor (XEXP (rtl, 0), mode));
7206 add_loc_descr (&mem_loc_result,
7207 mem_loc_descriptor (XEXP (rtl, 1), mode));
7208 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7209 break;
7211 case CONST_INT:
7212 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7213 break;
7215 default:
7216 abort ();
7219 return mem_loc_result;
7222 /* Return a descriptor that describes the concatenation of two locations.
7223 This is typically a complex variable. */
7225 static dw_loc_descr_ref
7226 concat_loc_descriptor (x0, x1)
7227 register rtx x0, x1;
7229 dw_loc_descr_ref cc_loc_result = NULL;
7231 if (!is_pseudo_reg (x0)
7232 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7233 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7234 add_loc_descr (&cc_loc_result,
7235 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7237 if (!is_pseudo_reg (x1)
7238 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7239 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7240 add_loc_descr (&cc_loc_result,
7241 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7243 return cc_loc_result;
7246 /* Output a proper Dwarf location descriptor for a variable or parameter
7247 which is either allocated in a register or in a memory location. For a
7248 register, we just generate an OP_REG and the register number. For a
7249 memory location we provide a Dwarf postfix expression describing how to
7250 generate the (dynamic) address of the object onto the address stack. */
7252 static dw_loc_descr_ref
7253 loc_descriptor (rtl)
7254 register rtx rtl;
7256 dw_loc_descr_ref loc_result = NULL;
7257 switch (GET_CODE (rtl))
7259 case SUBREG:
7260 /* The case of a subreg may arise when we have a local (register)
7261 variable or a formal (register) parameter which doesn't quite fill
7262 up an entire register. For now, just assume that it is
7263 legitimate to make the Dwarf info refer to the whole register which
7264 contains the given subreg. */
7265 rtl = SUBREG_REG (rtl);
7267 /* Fall through. */
7269 case REG:
7270 loc_result = reg_loc_descriptor (rtl);
7271 break;
7273 case MEM:
7274 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7275 break;
7277 case CONCAT:
7278 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7279 break;
7281 default:
7282 abort ();
7285 return loc_result;
7288 /* Similar, but generate the descriptor from trees instead of rtl.
7289 This comes up particularly with variable length arrays. */
7291 static dw_loc_descr_ref
7292 loc_descriptor_from_tree (loc, addressp)
7293 tree loc;
7294 int addressp;
7296 dw_loc_descr_ref ret = NULL;
7297 int indirect_size = 0;
7298 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7299 enum dwarf_location_atom op;
7301 /* ??? Most of the time we do not take proper care for sign/zero
7302 extending the values properly. Hopefully this won't be a real
7303 problem... */
7305 switch (TREE_CODE (loc))
7307 case ERROR_MARK:
7308 break;
7310 case WITH_RECORD_EXPR:
7311 /* This case involves extracting fields from an object to determine the
7312 position of other fields. We don't try to encode this here. The
7313 only user of this is Ada, which encodes the needed information using
7314 the names of types. */
7315 return ret;
7317 case VAR_DECL:
7318 case PARM_DECL:
7320 rtx rtl = rtl_for_decl_location (loc);
7321 enum machine_mode mode = DECL_MODE (loc);
7323 if (rtl == NULL_RTX)
7324 break;
7325 else if (CONSTANT_P (rtl))
7327 ret = new_loc_descr (DW_OP_addr, 0, 0);
7328 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7329 ret->dw_loc_oprnd1.v.val_addr = rtl;
7330 indirect_size = GET_MODE_SIZE (mode);
7332 else
7334 if (GET_CODE (rtl) == MEM)
7336 indirect_size = GET_MODE_SIZE (mode);
7337 rtl = XEXP (rtl, 0);
7339 ret = mem_loc_descriptor (rtl, mode);
7342 break;
7344 case INDIRECT_REF:
7345 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7346 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
7347 break;
7349 case NOP_EXPR:
7350 case CONVERT_EXPR:
7351 case NON_LVALUE_EXPR:
7352 case SAVE_EXPR:
7353 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
7355 case COMPONENT_REF:
7356 case BIT_FIELD_REF:
7357 case ARRAY_REF:
7359 tree obj, offset;
7360 HOST_WIDE_INT bitsize, bitpos, bytepos;
7361 enum machine_mode mode;
7362 int volatilep;
7363 unsigned int alignment;
7365 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7366 &unsignedp, &volatilep, &alignment);
7367 ret = loc_descriptor_from_tree (obj, 1);
7369 if (offset != NULL_TREE)
7371 /* Variable offset. */
7372 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7373 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7376 if (addressp)
7378 /* We cannot address anything not on a unit boundary. */
7379 if (bitpos % BITS_PER_UNIT != 0)
7380 abort ();
7382 else
7384 if (bitpos % BITS_PER_UNIT != 0
7385 || bitsize % BITS_PER_UNIT != 0)
7387 /* ??? We could handle this by loading and shifting etc.
7388 Wait until someone needs it before expending the effort. */
7389 abort ();
7392 indirect_size = bitsize / BITS_PER_UNIT;
7395 bytepos = bitpos / BITS_PER_UNIT;
7396 if (bytepos > 0)
7397 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7398 else if (bytepos < 0)
7400 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7401 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7403 break;
7406 case INTEGER_CST:
7407 if (host_integerp (loc, 0))
7408 ret = int_loc_descriptor (tree_low_cst (loc, 0));
7409 break;
7411 case BIT_AND_EXPR:
7412 op = DW_OP_and;
7413 goto do_binop;
7414 case BIT_XOR_EXPR:
7415 op = DW_OP_xor;
7416 goto do_binop;
7417 case BIT_IOR_EXPR:
7418 op = DW_OP_or;
7419 goto do_binop;
7420 case TRUNC_DIV_EXPR:
7421 op = DW_OP_div;
7422 goto do_binop;
7423 case MINUS_EXPR:
7424 op = DW_OP_minus;
7425 goto do_binop;
7426 case TRUNC_MOD_EXPR:
7427 op = DW_OP_mod;
7428 goto do_binop;
7429 case MULT_EXPR:
7430 op = DW_OP_mul;
7431 goto do_binop;
7432 case LSHIFT_EXPR:
7433 op = DW_OP_shl;
7434 goto do_binop;
7435 case RSHIFT_EXPR:
7436 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
7437 goto do_binop;
7438 case PLUS_EXPR:
7439 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
7440 && host_integerp (TREE_OPERAND (loc, 1), 0))
7442 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7443 add_loc_descr (&ret,
7444 new_loc_descr (DW_OP_plus_uconst,
7445 tree_low_cst (TREE_OPERAND (loc, 1),
7447 0));
7448 break;
7450 op = DW_OP_plus;
7451 goto do_binop;
7452 case LE_EXPR:
7453 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7454 break;
7455 op = DW_OP_le;
7456 goto do_binop;
7457 case GE_EXPR:
7458 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7459 break;
7460 op = DW_OP_ge;
7461 goto do_binop;
7462 case LT_EXPR:
7463 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7464 break;
7465 op = DW_OP_lt;
7466 goto do_binop;
7467 case GT_EXPR:
7468 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7469 break;
7470 op = DW_OP_gt;
7471 goto do_binop;
7472 case EQ_EXPR:
7473 op = DW_OP_eq;
7474 goto do_binop;
7475 case NE_EXPR:
7476 op = DW_OP_ne;
7477 goto do_binop;
7479 do_binop:
7480 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7481 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
7482 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7483 break;
7485 case BIT_NOT_EXPR:
7486 op = DW_OP_not;
7487 goto do_unop;
7488 case ABS_EXPR:
7489 op = DW_OP_abs;
7490 goto do_unop;
7491 case NEGATE_EXPR:
7492 op = DW_OP_neg;
7493 goto do_unop;
7495 do_unop:
7496 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7497 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7498 break;
7500 case MAX_EXPR:
7501 loc = build (COND_EXPR, TREE_TYPE (loc),
7502 build (LT_EXPR, integer_type_node,
7503 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
7504 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
7505 /* FALLTHRU */
7507 case COND_EXPR:
7509 dw_loc_descr_ref bra_node, jump_node, tmp;
7511 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7512 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
7513 add_loc_descr (&ret, bra_node);
7515 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
7516 add_loc_descr (&ret, tmp);
7517 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
7518 add_loc_descr (&ret, jump_node);
7520 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
7521 add_loc_descr (&ret, tmp);
7522 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7523 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
7525 /* ??? Need a node to point the skip at. Use a nop. */
7526 tmp = new_loc_descr (DW_OP_nop, 0, 0);
7527 add_loc_descr (&ret, tmp);
7528 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7529 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
7531 break;
7533 default:
7534 abort ();
7537 /* If we can't fill the request for an address, die. */
7538 if (addressp && indirect_size == 0)
7539 abort ();
7541 /* If we've got an address and don't want one, dereference. */
7542 if (!addressp && indirect_size > 0)
7544 if (indirect_size > DWARF2_ADDR_SIZE)
7545 abort ();
7546 if (indirect_size == DWARF2_ADDR_SIZE)
7547 op = DW_OP_deref;
7548 else
7549 op = DW_OP_deref_size;
7550 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
7553 return ret;
7556 /* Given a value, round it up to the lowest multiple of `boundary'
7557 which is not less than the value itself. */
7559 static inline HOST_WIDE_INT
7560 ceiling (value, boundary)
7561 HOST_WIDE_INT value;
7562 unsigned int boundary;
7564 return (((value + boundary - 1) / boundary) * boundary);
7567 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
7568 pointer to the declared type for the relevant field variable, or return
7569 `integer_type_node' if the given node turns out to be an
7570 ERROR_MARK node. */
7572 static inline tree
7573 field_type (decl)
7574 register tree decl;
7576 register tree type;
7578 if (TREE_CODE (decl) == ERROR_MARK)
7579 return integer_type_node;
7581 type = DECL_BIT_FIELD_TYPE (decl);
7582 if (type == NULL_TREE)
7583 type = TREE_TYPE (decl);
7585 return type;
7588 /* Given a pointer to a tree node, return the alignment in bits for
7589 it, or else return BITS_PER_WORD if the node actually turns out to
7590 be an ERROR_MARK node. */
7592 static inline unsigned
7593 simple_type_align_in_bits (type)
7594 register tree type;
7596 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
7599 static inline unsigned
7600 simple_decl_align_in_bits (decl)
7601 register tree decl;
7603 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
7606 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7607 node, return the size in bits for the type if it is a constant, or else
7608 return the alignment for the type if the type's size is not constant, or
7609 else return BITS_PER_WORD if the type actually turns out to be an
7610 ERROR_MARK node. */
7612 static inline unsigned HOST_WIDE_INT
7613 simple_type_size_in_bits (type)
7614 register tree type;
7616 tree type_size_tree;
7618 if (TREE_CODE (type) == ERROR_MARK)
7619 return BITS_PER_WORD;
7620 type_size_tree = TYPE_SIZE (type);
7622 if (type_size_tree == NULL_TREE)
7623 return 0;
7624 if (! host_integerp (type_size_tree, 1))
7625 return TYPE_ALIGN (type);
7626 return tree_low_cst (type_size_tree, 1);
7629 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
7630 return the byte offset of the lowest addressed byte of the "containing
7631 object" for the given FIELD_DECL, or return 0 if we are unable to
7632 determine what that offset is, either because the argument turns out to
7633 be a pointer to an ERROR_MARK node, or because the offset is actually
7634 variable. (We can't handle the latter case just yet). */
7636 static HOST_WIDE_INT
7637 field_byte_offset (decl)
7638 register tree decl;
7640 unsigned int type_align_in_bits;
7641 unsigned int decl_align_in_bits;
7642 unsigned HOST_WIDE_INT type_size_in_bits;
7643 HOST_WIDE_INT object_offset_in_bits;
7644 HOST_WIDE_INT object_offset_in_bytes;
7645 tree type;
7646 tree field_size_tree;
7647 HOST_WIDE_INT bitpos_int;
7648 HOST_WIDE_INT deepest_bitpos;
7649 unsigned HOST_WIDE_INT field_size_in_bits;
7651 if (TREE_CODE (decl) == ERROR_MARK)
7652 return 0;
7654 if (TREE_CODE (decl) != FIELD_DECL)
7655 abort ();
7657 type = field_type (decl);
7658 field_size_tree = DECL_SIZE (decl);
7660 /* The size could be unspecified if there was an error, or for
7661 a flexible array member. */
7662 if (! field_size_tree)
7663 field_size_tree = bitsize_zero_node;
7665 /* We cannot yet cope with fields whose positions are variable, so
7666 for now, when we see such things, we simply return 0. Someday, we may
7667 be able to handle such cases, but it will be damn difficult. */
7668 if (! host_integerp (bit_position (decl), 0))
7669 return 0;
7671 bitpos_int = int_bit_position (decl);
7673 /* If we don't know the size of the field, pretend it's a full word. */
7674 if (host_integerp (field_size_tree, 1))
7675 field_size_in_bits = tree_low_cst (field_size_tree, 1);
7676 else
7677 field_size_in_bits = BITS_PER_WORD;
7679 type_size_in_bits = simple_type_size_in_bits (type);
7680 type_align_in_bits = simple_type_align_in_bits (type);
7681 decl_align_in_bits = simple_decl_align_in_bits (decl);
7683 /* Note that the GCC front-end doesn't make any attempt to keep track of
7684 the starting bit offset (relative to the start of the containing
7685 structure type) of the hypothetical "containing object" for a bit-
7686 field. Thus, when computing the byte offset value for the start of the
7687 "containing object" of a bit-field, we must deduce this information on
7688 our own. This can be rather tricky to do in some cases. For example,
7689 handling the following structure type definition when compiling for an
7690 i386/i486 target (which only aligns long long's to 32-bit boundaries)
7691 can be very tricky:
7693 struct S { int field1; long long field2:31; };
7695 Fortunately, there is a simple rule-of-thumb which can be
7696 used in such cases. When compiling for an i386/i486, GCC will allocate
7697 8 bytes for the structure shown above. It decides to do this based upon
7698 one simple rule for bit-field allocation. Quite simply, GCC allocates
7699 each "containing object" for each bit-field at the first (i.e. lowest
7700 addressed) legitimate alignment boundary (based upon the required
7701 minimum alignment for the declared type of the field) which it can
7702 possibly use, subject to the condition that there is still enough
7703 available space remaining in the containing object (when allocated at
7704 the selected point) to fully accommodate all of the bits of the
7705 bit-field itself. This simple rule makes it obvious why GCC allocates
7706 8 bytes for each object of the structure type shown above. When looking
7707 for a place to allocate the "containing object" for `field2', the
7708 compiler simply tries to allocate a 64-bit "containing object" at each
7709 successive 32-bit boundary (starting at zero) until it finds a place to
7710 allocate that 64- bit field such that at least 31 contiguous (and
7711 previously unallocated) bits remain within that selected 64 bit field.
7712 (As it turns out, for the example above, the compiler finds that it is
7713 OK to allocate the "containing object" 64-bit field at bit-offset zero
7714 within the structure type.) Here we attempt to work backwards from the
7715 limited set of facts we're given, and we try to deduce from those facts,
7716 where GCC must have believed that the containing object started (within
7717 the structure type). The value we deduce is then used (by the callers of
7718 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
7719 for fields (both bit-fields and, in the case of DW_AT_location, regular
7720 fields as well). */
7722 /* Figure out the bit-distance from the start of the structure to the
7723 "deepest" bit of the bit-field. */
7724 deepest_bitpos = bitpos_int + field_size_in_bits;
7726 /* This is the tricky part. Use some fancy footwork to deduce where the
7727 lowest addressed bit of the containing object must be. */
7728 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
7730 /* Round up to type_align by default. This works best for bitfields. */
7731 object_offset_in_bits += type_align_in_bits - 1;
7732 object_offset_in_bits /= type_align_in_bits;
7733 object_offset_in_bits *= type_align_in_bits;
7735 if (object_offset_in_bits > bitpos_int)
7737 /* Sigh, the decl must be packed. */
7738 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
7740 /* Round up to decl_align instead. */
7741 object_offset_in_bits += decl_align_in_bits - 1;
7742 object_offset_in_bits /= decl_align_in_bits;
7743 object_offset_in_bits *= decl_align_in_bits;
7746 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
7748 return object_offset_in_bytes;
7751 /* The following routines define various Dwarf attributes and any data
7752 associated with them. */
7754 /* Add a location description attribute value to a DIE.
7756 This emits location attributes suitable for whole variables and
7757 whole parameters. Note that the location attributes for struct fields are
7758 generated by the routine `data_member_location_attribute' below. */
7760 static void
7761 add_AT_location_description (die, attr_kind, rtl)
7762 dw_die_ref die;
7763 enum dwarf_attribute attr_kind;
7764 register rtx rtl;
7766 /* Handle a special case. If we are about to output a location descriptor
7767 for a variable or parameter which has been optimized out of existence,
7768 don't do that. A variable which has been optimized out
7769 of existence will have a DECL_RTL value which denotes a pseudo-reg.
7770 Currently, in some rare cases, variables can have DECL_RTL values which
7771 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
7772 elsewhere in the compiler. We treat such cases as if the variable(s) in
7773 question had been optimized out of existence. */
7775 if (is_pseudo_reg (rtl)
7776 || (GET_CODE (rtl) == MEM
7777 && is_pseudo_reg (XEXP (rtl, 0)))
7778 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
7779 references the internal argument pointer (a pseudo) in a function
7780 where all references to the internal argument pointer were
7781 eliminated via the optimizers. */
7782 || (GET_CODE (rtl) == MEM
7783 && GET_CODE (XEXP (rtl, 0)) == PLUS
7784 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
7785 || (GET_CODE (rtl) == CONCAT
7786 && is_pseudo_reg (XEXP (rtl, 0))
7787 && is_pseudo_reg (XEXP (rtl, 1))))
7788 return;
7790 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
7793 /* Attach the specialized form of location attribute used for data
7794 members of struct and union types. In the special case of a
7795 FIELD_DECL node which represents a bit-field, the "offset" part
7796 of this special location descriptor must indicate the distance
7797 in bytes from the lowest-addressed byte of the containing struct
7798 or union type to the lowest-addressed byte of the "containing
7799 object" for the bit-field. (See the `field_byte_offset' function
7800 above).. For any given bit-field, the "containing object" is a
7801 hypothetical object (of some integral or enum type) within which
7802 the given bit-field lives. The type of this hypothetical
7803 "containing object" is always the same as the declared type of
7804 the individual bit-field itself (for GCC anyway... the DWARF
7805 spec doesn't actually mandate this). Note that it is the size
7806 (in bytes) of the hypothetical "containing object" which will
7807 be given in the DW_AT_byte_size attribute for this bit-field.
7808 (See the `byte_size_attribute' function below.) It is also used
7809 when calculating the value of the DW_AT_bit_offset attribute.
7810 (See the `bit_offset_attribute' function below). */
7812 static void
7813 add_data_member_location_attribute (die, decl)
7814 register dw_die_ref die;
7815 register tree decl;
7817 register unsigned long offset;
7818 register dw_loc_descr_ref loc_descr;
7819 register enum dwarf_location_atom op;
7821 if (TREE_CODE (decl) == TREE_VEC)
7822 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
7823 else
7824 offset = field_byte_offset (decl);
7826 /* The DWARF2 standard says that we should assume that the structure address
7827 is already on the stack, so we can specify a structure field address
7828 by using DW_OP_plus_uconst. */
7830 #ifdef MIPS_DEBUGGING_INFO
7831 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
7832 correctly. It works only if we leave the offset on the stack. */
7833 op = DW_OP_constu;
7834 #else
7835 op = DW_OP_plus_uconst;
7836 #endif
7838 loc_descr = new_loc_descr (op, offset, 0);
7839 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
7842 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
7843 does not have a "location" either in memory or in a register. These
7844 things can arise in GNU C when a constant is passed as an actual parameter
7845 to an inlined function. They can also arise in C++ where declared
7846 constants do not necessarily get memory "homes". */
7848 static void
7849 add_const_value_attribute (die, rtl)
7850 register dw_die_ref die;
7851 register rtx rtl;
7853 switch (GET_CODE (rtl))
7855 case CONST_INT:
7856 /* Note that a CONST_INT rtx could represent either an integer
7857 or a floating-point constant. A CONST_INT is used whenever
7858 the constant will fit into a single word. In all such
7859 cases, the original mode of the constant value is wiped
7860 out, and the CONST_INT rtx is assigned VOIDmode. */
7862 HOST_WIDE_INT val = INTVAL (rtl);
7864 /* ??? We really should be using HOST_WIDE_INT throughout. */
7865 if (val < 0)
7867 if ((long) val != val)
7868 abort ();
7869 add_AT_int (die, DW_AT_const_value, (long) val);
7871 else
7873 if ((unsigned long) val != (unsigned HOST_WIDE_INT) val)
7874 abort ();
7875 add_AT_int (die, DW_AT_const_value, (unsigned long) val);
7878 break;
7880 case CONST_DOUBLE:
7881 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
7882 floating-point constant. A CONST_DOUBLE is used whenever the
7883 constant requires more than one word in order to be adequately
7884 represented. We output CONST_DOUBLEs as blocks. */
7886 register enum machine_mode mode = GET_MODE (rtl);
7888 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
7890 register unsigned length = GET_MODE_SIZE (mode) / 4;
7891 long *array = (long *) xmalloc (sizeof (long) * length);
7892 REAL_VALUE_TYPE rv;
7894 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
7895 switch (mode)
7897 case SFmode:
7898 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
7899 break;
7901 case DFmode:
7902 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
7903 break;
7905 case XFmode:
7906 case TFmode:
7907 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
7908 break;
7910 default:
7911 abort ();
7914 add_AT_float (die, DW_AT_const_value, length, array);
7916 else
7918 /* ??? We really should be using HOST_WIDE_INT throughout. */
7919 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
7920 abort ();
7921 add_AT_long_long (die, DW_AT_const_value,
7922 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
7925 break;
7927 case CONST_STRING:
7928 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
7929 break;
7931 case SYMBOL_REF:
7932 case LABEL_REF:
7933 case CONST:
7934 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
7935 break;
7937 case PLUS:
7938 /* In cases where an inlined instance of an inline function is passed
7939 the address of an `auto' variable (which is local to the caller) we
7940 can get a situation where the DECL_RTL of the artificial local
7941 variable (for the inlining) which acts as a stand-in for the
7942 corresponding formal parameter (of the inline function) will look
7943 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
7944 exactly a compile-time constant expression, but it isn't the address
7945 of the (artificial) local variable either. Rather, it represents the
7946 *value* which the artificial local variable always has during its
7947 lifetime. We currently have no way to represent such quasi-constant
7948 values in Dwarf, so for now we just punt and generate nothing. */
7949 break;
7951 default:
7952 /* No other kinds of rtx should be possible here. */
7953 abort ();
7958 static rtx
7959 rtl_for_decl_location (decl)
7960 tree decl;
7962 register rtx rtl;
7964 /* Here we have to decide where we are going to say the parameter "lives"
7965 (as far as the debugger is concerned). We only have a couple of
7966 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
7968 DECL_RTL normally indicates where the parameter lives during most of the
7969 activation of the function. If optimization is enabled however, this
7970 could be either NULL or else a pseudo-reg. Both of those cases indicate
7971 that the parameter doesn't really live anywhere (as far as the code
7972 generation parts of GCC are concerned) during most of the function's
7973 activation. That will happen (for example) if the parameter is never
7974 referenced within the function.
7976 We could just generate a location descriptor here for all non-NULL
7977 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
7978 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
7979 where DECL_RTL is NULL or is a pseudo-reg.
7981 Note however that we can only get away with using DECL_INCOMING_RTL as
7982 a backup substitute for DECL_RTL in certain limited cases. In cases
7983 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
7984 we can be sure that the parameter was passed using the same type as it is
7985 declared to have within the function, and that its DECL_INCOMING_RTL
7986 points us to a place where a value of that type is passed.
7988 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
7989 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
7990 because in these cases DECL_INCOMING_RTL points us to a value of some
7991 type which is *different* from the type of the parameter itself. Thus,
7992 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
7993 such cases, the debugger would end up (for example) trying to fetch a
7994 `float' from a place which actually contains the first part of a
7995 `double'. That would lead to really incorrect and confusing
7996 output at debug-time.
7998 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
7999 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8000 are a couple of exceptions however. On little-endian machines we can
8001 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8002 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8003 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8004 when (on a little-endian machine) a non-prototyped function has a
8005 parameter declared to be of type `short' or `char'. In such cases,
8006 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8007 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8008 passed `int' value. If the debugger then uses that address to fetch
8009 a `short' or a `char' (on a little-endian machine) the result will be
8010 the correct data, so we allow for such exceptional cases below.
8012 Note that our goal here is to describe the place where the given formal
8013 parameter lives during most of the function's activation (i.e. between
8014 the end of the prologue and the start of the epilogue). We'll do that
8015 as best as we can. Note however that if the given formal parameter is
8016 modified sometime during the execution of the function, then a stack
8017 backtrace (at debug-time) will show the function as having been
8018 called with the *new* value rather than the value which was
8019 originally passed in. This happens rarely enough that it is not
8020 a major problem, but it *is* a problem, and I'd like to fix it.
8022 A future version of dwarf2out.c may generate two additional
8023 attributes for any given DW_TAG_formal_parameter DIE which will
8024 describe the "passed type" and the "passed location" for the
8025 given formal parameter in addition to the attributes we now
8026 generate to indicate the "declared type" and the "active
8027 location" for each parameter. This additional set of attributes
8028 could be used by debuggers for stack backtraces. Separately, note
8029 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8030 NULL also. This happens (for example) for inlined-instances of
8031 inline function formal parameters which are never referenced.
8032 This really shouldn't be happening. All PARM_DECL nodes should
8033 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8034 doesn't currently generate these values for inlined instances of
8035 inline function parameters, so when we see such cases, we are
8036 just out-of-luck for the time being (until integrate.c
8037 gets fixed). */
8039 /* Use DECL_RTL as the "location" unless we find something better. */
8040 rtl = DECL_RTL_IF_SET (decl);
8042 if (TREE_CODE (decl) == PARM_DECL)
8044 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8046 tree declared_type = type_main_variant (TREE_TYPE (decl));
8047 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8049 /* This decl represents a formal parameter which was optimized out.
8050 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8051 all* cases where (rtl == NULL_RTX) just below. */
8052 if (declared_type == passed_type)
8053 rtl = DECL_INCOMING_RTL (decl);
8054 else if (! BYTES_BIG_ENDIAN
8055 && TREE_CODE (declared_type) == INTEGER_TYPE
8056 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8057 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8058 rtl = DECL_INCOMING_RTL (decl);
8061 /* If the parm was passed in registers, but lives on the stack, then
8062 make a big endian correction if the mode of the type of the
8063 parameter is not the same as the mode of the rtl. */
8064 /* ??? This is the same series of checks that are made in dbxout.c before
8065 we reach the big endian correction code there. It isn't clear if all
8066 of these checks are necessary here, but keeping them all is the safe
8067 thing to do. */
8068 else if (GET_CODE (rtl) == MEM
8069 && XEXP (rtl, 0) != const0_rtx
8070 && ! CONSTANT_P (XEXP (rtl, 0))
8071 /* Not passed in memory. */
8072 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8073 /* Not passed by invisible reference. */
8074 && (GET_CODE (XEXP (rtl, 0)) != REG
8075 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8076 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8077 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8078 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8079 #endif
8081 /* Big endian correction check. */
8082 && BYTES_BIG_ENDIAN
8083 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8084 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8085 < UNITS_PER_WORD))
8087 int offset = (UNITS_PER_WORD
8088 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8089 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8090 plus_constant (XEXP (rtl, 0), offset));
8094 if (rtl != NULL_RTX)
8096 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8097 #ifdef LEAF_REG_REMAP
8098 if (current_function_uses_only_leaf_regs)
8099 leaf_renumber_regs_insn (rtl);
8100 #endif
8103 return rtl;
8106 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8107 data attribute for a variable or a parameter. We generate the
8108 DW_AT_const_value attribute only in those cases where the given variable
8109 or parameter does not have a true "location" either in memory or in a
8110 register. This can happen (for example) when a constant is passed as an
8111 actual argument in a call to an inline function. (It's possible that
8112 these things can crop up in other ways also.) Note that one type of
8113 constant value which can be passed into an inlined function is a constant
8114 pointer. This can happen for example if an actual argument in an inlined
8115 function call evaluates to a compile-time constant address. */
8117 static void
8118 add_location_or_const_value_attribute (die, decl)
8119 register dw_die_ref die;
8120 register tree decl;
8122 register rtx rtl;
8124 if (TREE_CODE (decl) == ERROR_MARK)
8125 return;
8127 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8128 abort ();
8130 rtl = rtl_for_decl_location (decl);
8131 if (rtl == NULL_RTX)
8132 return;
8134 switch (GET_CODE (rtl))
8136 case ADDRESSOF:
8137 /* The address of a variable that was optimized away; don't emit
8138 anything. */
8139 break;
8141 case CONST_INT:
8142 case CONST_DOUBLE:
8143 case CONST_STRING:
8144 case SYMBOL_REF:
8145 case LABEL_REF:
8146 case CONST:
8147 case PLUS:
8148 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8149 add_const_value_attribute (die, rtl);
8150 break;
8152 case MEM:
8153 case REG:
8154 case SUBREG:
8155 case CONCAT:
8156 add_AT_location_description (die, DW_AT_location, rtl);
8157 break;
8159 default:
8160 abort ();
8164 /* If we don't have a copy of this variable in memory for some reason (such
8165 as a C++ member constant that doesn't have an out-of-line definition),
8166 we should tell the debugger about the constant value. */
8168 static void
8169 tree_add_const_value_attribute (var_die, decl)
8170 dw_die_ref var_die;
8171 tree decl;
8173 tree init = DECL_INITIAL (decl);
8174 tree type = TREE_TYPE (decl);
8176 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8177 && initializer_constant_valid_p (init, type) == null_pointer_node)
8178 /* OK */;
8179 else
8180 return;
8182 switch (TREE_CODE (type))
8184 case INTEGER_TYPE:
8185 if (host_integerp (init, 0))
8186 add_AT_unsigned (var_die, DW_AT_const_value,
8187 TREE_INT_CST_LOW (init));
8188 else
8189 add_AT_long_long (var_die, DW_AT_const_value,
8190 TREE_INT_CST_HIGH (init),
8191 TREE_INT_CST_LOW (init));
8192 break;
8194 default:;
8198 /* Generate an DW_AT_name attribute given some string value to be included as
8199 the value of the attribute. */
8201 static inline void
8202 add_name_attribute (die, name_string)
8203 register dw_die_ref die;
8204 register const char *name_string;
8206 if (name_string != NULL && *name_string != 0)
8208 if (demangle_name_func)
8209 name_string = (*demangle_name_func) (name_string);
8211 add_AT_string (die, DW_AT_name, name_string);
8215 /* Given a tree node describing an array bound (either lower or upper) output
8216 a representation for that bound. */
8218 static void
8219 add_bound_info (subrange_die, bound_attr, bound)
8220 register dw_die_ref subrange_die;
8221 register enum dwarf_attribute bound_attr;
8222 register tree bound;
8224 /* If this is an Ada unconstrained array type, then don't emit any debug
8225 info because the array bounds are unknown. They are parameterized when
8226 the type is instantiated. */
8227 if (contains_placeholder_p (bound))
8228 return;
8230 switch (TREE_CODE (bound))
8232 case ERROR_MARK:
8233 return;
8235 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8236 case INTEGER_CST:
8237 if (! host_integerp (bound, 0)
8238 || (bound_attr == DW_AT_lower_bound
8239 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8240 || (is_fortran () && integer_onep (bound)))))
8241 /* use the default */
8243 else
8244 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8245 break;
8247 case CONVERT_EXPR:
8248 case NOP_EXPR:
8249 case NON_LVALUE_EXPR:
8250 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8251 break;
8253 case SAVE_EXPR:
8254 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8255 access the upper bound values may be bogus. If they refer to a
8256 register, they may only describe how to get at these values at the
8257 points in the generated code right after they have just been
8258 computed. Worse yet, in the typical case, the upper bound values
8259 will not even *be* computed in the optimized code (though the
8260 number of elements will), so these SAVE_EXPRs are entirely
8261 bogus. In order to compensate for this fact, we check here to see
8262 if optimization is enabled, and if so, we don't add an attribute
8263 for the (unknown and unknowable) upper bound. This should not
8264 cause too much trouble for existing (stupid?) debuggers because
8265 they have to deal with empty upper bounds location descriptions
8266 anyway in order to be able to deal with incomplete array types.
8267 Of course an intelligent debugger (GDB?) should be able to
8268 comprehend that a missing upper bound specification in a array
8269 type used for a storage class `auto' local array variable
8270 indicates that the upper bound is both unknown (at compile- time)
8271 and unknowable (at run-time) due to optimization.
8273 We assume that a MEM rtx is safe because gcc wouldn't put the
8274 value there unless it was going to be used repeatedly in the
8275 function, i.e. for cleanups. */
8276 if (SAVE_EXPR_RTL (bound)
8277 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8279 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8280 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8281 register rtx loc = SAVE_EXPR_RTL (bound);
8283 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8284 it references an outer function's frame. */
8286 if (GET_CODE (loc) == MEM)
8288 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8290 if (XEXP (loc, 0) != new_addr)
8291 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8294 add_AT_flag (decl_die, DW_AT_artificial, 1);
8295 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8296 add_AT_location_description (decl_die, DW_AT_location, loc);
8297 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8300 /* Else leave out the attribute. */
8301 break;
8303 case VAR_DECL:
8304 case PARM_DECL:
8306 dw_die_ref decl_die = lookup_decl_die (bound);
8308 /* ??? Can this happen, or should the variable have been bound
8309 first? Probably it can, since I imagine that we try to create
8310 the types of parameters in the order in which they exist in
8311 the list, and won't have created a forward reference to a
8312 later parameter. */
8313 if (decl_die != NULL)
8314 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8315 break;
8318 default:
8320 /* Otherwise try to create a stack operation procedure to
8321 evaluate the value of the array bound. */
8323 dw_die_ref ctx, decl_die;
8324 dw_loc_descr_ref loc;
8326 loc = loc_descriptor_from_tree (bound, 0);
8327 if (loc == NULL)
8328 break;
8330 ctx = lookup_decl_die (current_function_decl);
8332 decl_die = new_die (DW_TAG_variable, ctx);
8333 add_AT_flag (decl_die, DW_AT_artificial, 1);
8334 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8335 add_AT_loc (decl_die, DW_AT_location, loc);
8337 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8338 break;
8343 /* Note that the block of subscript information for an array type also
8344 includes information about the element type of type given array type. */
8346 static void
8347 add_subscript_info (type_die, type)
8348 register dw_die_ref type_die;
8349 register tree type;
8351 #ifndef MIPS_DEBUGGING_INFO
8352 register unsigned dimension_number;
8353 #endif
8354 register tree lower, upper;
8355 register dw_die_ref subrange_die;
8357 /* The GNU compilers represent multidimensional array types as sequences of
8358 one dimensional array types whose element types are themselves array
8359 types. Here we squish that down, so that each multidimensional array
8360 type gets only one array_type DIE in the Dwarf debugging info. The draft
8361 Dwarf specification say that we are allowed to do this kind of
8362 compression in C (because there is no difference between an array or
8363 arrays and a multidimensional array in C) but for other source languages
8364 (e.g. Ada) we probably shouldn't do this. */
8366 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8367 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8368 We work around this by disabling this feature. See also
8369 gen_array_type_die. */
8370 #ifndef MIPS_DEBUGGING_INFO
8371 for (dimension_number = 0;
8372 TREE_CODE (type) == ARRAY_TYPE;
8373 type = TREE_TYPE (type), dimension_number++)
8375 #endif
8376 register tree domain = TYPE_DOMAIN (type);
8378 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8379 and (in GNU C only) variable bounds. Handle all three forms
8380 here. */
8381 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8382 if (domain)
8384 /* We have an array type with specified bounds. */
8385 lower = TYPE_MIN_VALUE (domain);
8386 upper = TYPE_MAX_VALUE (domain);
8388 /* define the index type. */
8389 if (TREE_TYPE (domain))
8391 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8392 TREE_TYPE field. We can't emit debug info for this
8393 because it is an unnamed integral type. */
8394 if (TREE_CODE (domain) == INTEGER_TYPE
8395 && TYPE_NAME (domain) == NULL_TREE
8396 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8397 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8399 else
8400 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8401 type_die);
8404 /* ??? If upper is NULL, the array has unspecified length,
8405 but it does have a lower bound. This happens with Fortran
8406 dimension arr(N:*)
8407 Since the debugger is definitely going to need to know N
8408 to produce useful results, go ahead and output the lower
8409 bound solo, and hope the debugger can cope. */
8411 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8412 if (upper)
8413 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8415 else
8416 /* We have an array type with an unspecified length. The DWARF-2
8417 spec does not say how to handle this; let's just leave out the
8418 bounds. */
8421 #ifndef MIPS_DEBUGGING_INFO
8423 #endif
8426 static void
8427 add_byte_size_attribute (die, tree_node)
8428 dw_die_ref die;
8429 register tree tree_node;
8431 register unsigned size;
8433 switch (TREE_CODE (tree_node))
8435 case ERROR_MARK:
8436 size = 0;
8437 break;
8438 case ENUMERAL_TYPE:
8439 case RECORD_TYPE:
8440 case UNION_TYPE:
8441 case QUAL_UNION_TYPE:
8442 size = int_size_in_bytes (tree_node);
8443 break;
8444 case FIELD_DECL:
8445 /* For a data member of a struct or union, the DW_AT_byte_size is
8446 generally given as the number of bytes normally allocated for an
8447 object of the *declared* type of the member itself. This is true
8448 even for bit-fields. */
8449 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8450 break;
8451 default:
8452 abort ();
8455 /* Note that `size' might be -1 when we get to this point. If it is, that
8456 indicates that the byte size of the entity in question is variable. We
8457 have no good way of expressing this fact in Dwarf at the present time,
8458 so just let the -1 pass on through. */
8460 add_AT_unsigned (die, DW_AT_byte_size, size);
8463 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8464 which specifies the distance in bits from the highest order bit of the
8465 "containing object" for the bit-field to the highest order bit of the
8466 bit-field itself.
8468 For any given bit-field, the "containing object" is a hypothetical
8469 object (of some integral or enum type) within which the given bit-field
8470 lives. The type of this hypothetical "containing object" is always the
8471 same as the declared type of the individual bit-field itself. The
8472 determination of the exact location of the "containing object" for a
8473 bit-field is rather complicated. It's handled by the
8474 `field_byte_offset' function (above).
8476 Note that it is the size (in bytes) of the hypothetical "containing object"
8477 which will be given in the DW_AT_byte_size attribute for this bit-field.
8478 (See `byte_size_attribute' above). */
8480 static inline void
8481 add_bit_offset_attribute (die, decl)
8482 register dw_die_ref die;
8483 register tree decl;
8485 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8486 tree type = DECL_BIT_FIELD_TYPE (decl);
8487 HOST_WIDE_INT bitpos_int;
8488 HOST_WIDE_INT highest_order_object_bit_offset;
8489 HOST_WIDE_INT highest_order_field_bit_offset;
8490 HOST_WIDE_INT unsigned bit_offset;
8492 /* Must be a field and a bit field. */
8493 if (!type
8494 || TREE_CODE (decl) != FIELD_DECL)
8495 abort ();
8497 /* We can't yet handle bit-fields whose offsets are variable, so if we
8498 encounter such things, just return without generating any attribute
8499 whatsoever. Likewise for variable or too large size. */
8500 if (! host_integerp (bit_position (decl), 0)
8501 || ! host_integerp (DECL_SIZE (decl), 1))
8502 return;
8504 bitpos_int = int_bit_position (decl);
8506 /* Note that the bit offset is always the distance (in bits) from the
8507 highest-order bit of the "containing object" to the highest-order bit of
8508 the bit-field itself. Since the "high-order end" of any object or field
8509 is different on big-endian and little-endian machines, the computation
8510 below must take account of these differences. */
8511 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
8512 highest_order_field_bit_offset = bitpos_int;
8514 if (! BYTES_BIG_ENDIAN)
8516 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
8517 highest_order_object_bit_offset += simple_type_size_in_bits (type);
8520 bit_offset
8521 = (! BYTES_BIG_ENDIAN
8522 ? highest_order_object_bit_offset - highest_order_field_bit_offset
8523 : highest_order_field_bit_offset - highest_order_object_bit_offset);
8525 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
8528 /* For a FIELD_DECL node which represents a bit field, output an attribute
8529 which specifies the length in bits of the given field. */
8531 static inline void
8532 add_bit_size_attribute (die, decl)
8533 register dw_die_ref die;
8534 register tree decl;
8536 /* Must be a field and a bit field. */
8537 if (TREE_CODE (decl) != FIELD_DECL
8538 || ! DECL_BIT_FIELD_TYPE (decl))
8539 abort ();
8541 if (host_integerp (DECL_SIZE (decl), 1))
8542 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
8545 /* If the compiled language is ANSI C, then add a 'prototyped'
8546 attribute, if arg types are given for the parameters of a function. */
8548 static inline void
8549 add_prototyped_attribute (die, func_type)
8550 register dw_die_ref die;
8551 register tree func_type;
8553 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
8554 && TYPE_ARG_TYPES (func_type) != NULL)
8555 add_AT_flag (die, DW_AT_prototyped, 1);
8558 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
8559 by looking in either the type declaration or object declaration
8560 equate table. */
8562 static inline void
8563 add_abstract_origin_attribute (die, origin)
8564 register dw_die_ref die;
8565 register tree origin;
8567 dw_die_ref origin_die = NULL;
8569 if (TREE_CODE (origin) != FUNCTION_DECL)
8571 /* We may have gotten separated from the block for the inlined
8572 function, if we're in an exception handler or some such; make
8573 sure that the abstract function has been written out.
8575 Doing this for nested functions is wrong, however; functions are
8576 distinct units, and our context might not even be inline. */
8577 tree fn = origin;
8578 if (TYPE_P (fn))
8579 fn = TYPE_STUB_DECL (fn);
8580 fn = decl_function_context (fn);
8581 if (fn)
8582 dwarf2out_abstract_function (fn);
8585 if (DECL_P (origin))
8586 origin_die = lookup_decl_die (origin);
8587 else if (TYPE_P (origin))
8588 origin_die = lookup_type_die (origin);
8590 if (origin_die == NULL)
8591 abort ();
8593 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
8596 /* We do not currently support the pure_virtual attribute. */
8598 static inline void
8599 add_pure_or_virtual_attribute (die, func_decl)
8600 register dw_die_ref die;
8601 register tree func_decl;
8603 if (DECL_VINDEX (func_decl))
8605 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8607 if (host_integerp (DECL_VINDEX (func_decl), 0))
8608 add_AT_loc (die, DW_AT_vtable_elem_location,
8609 new_loc_descr (DW_OP_constu,
8610 tree_low_cst (DECL_VINDEX (func_decl), 0),
8611 0));
8613 /* GNU extension: Record what type this method came from originally. */
8614 if (debug_info_level > DINFO_LEVEL_TERSE)
8615 add_AT_die_ref (die, DW_AT_containing_type,
8616 lookup_type_die (DECL_CONTEXT (func_decl)));
8620 /* Add source coordinate attributes for the given decl. */
8622 static void
8623 add_src_coords_attributes (die, decl)
8624 register dw_die_ref die;
8625 register tree decl;
8627 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
8629 add_AT_unsigned (die, DW_AT_decl_file, file_index);
8630 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8633 /* Add an DW_AT_name attribute and source coordinate attribute for the
8634 given decl, but only if it actually has a name. */
8636 static void
8637 add_name_and_src_coords_attributes (die, decl)
8638 register dw_die_ref die;
8639 register tree decl;
8641 register tree decl_name;
8643 decl_name = DECL_NAME (decl);
8644 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
8646 add_name_attribute (die, dwarf2_name (decl, 0));
8647 if (! DECL_ARTIFICIAL (decl))
8648 add_src_coords_attributes (die, decl);
8650 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
8651 && TREE_PUBLIC (decl)
8652 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
8653 && !DECL_ABSTRACT (decl))
8654 add_AT_string (die, DW_AT_MIPS_linkage_name,
8655 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
8659 /* Push a new declaration scope. */
8661 static void
8662 push_decl_scope (scope)
8663 tree scope;
8665 /* Make room in the decl_scope_table, if necessary. */
8666 if (decl_scope_table_allocated == decl_scope_depth)
8668 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
8669 decl_scope_table
8670 = (tree *) xrealloc (decl_scope_table,
8671 decl_scope_table_allocated * sizeof (tree));
8674 decl_scope_table[decl_scope_depth] = scope;
8675 decl_scope_depth++;
8678 /* Pop a declaration scope. */
8679 static inline void
8680 pop_decl_scope ()
8682 if (decl_scope_depth <= 0)
8683 abort ();
8684 --decl_scope_depth;
8687 /* Return the DIE for the scope that immediately contains this type.
8688 Non-named types get global scope. Named types nested in other
8689 types get their containing scope if it's open, or global scope
8690 otherwise. All other types (i.e. function-local named types) get
8691 the current active scope. */
8693 static dw_die_ref
8694 scope_die_for (t, context_die)
8695 register tree t;
8696 register dw_die_ref context_die;
8698 register dw_die_ref scope_die = NULL;
8699 register tree containing_scope;
8700 register int i;
8702 /* Non-types always go in the current scope. */
8703 if (! TYPE_P (t))
8704 abort ();
8706 containing_scope = TYPE_CONTEXT (t);
8708 /* Ignore namespaces for the moment. */
8709 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
8710 containing_scope = NULL_TREE;
8712 /* Ignore function type "scopes" from the C frontend. They mean that
8713 a tagged type is local to a parmlist of a function declarator, but
8714 that isn't useful to DWARF. */
8715 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
8716 containing_scope = NULL_TREE;
8718 if (containing_scope == NULL_TREE)
8719 scope_die = comp_unit_die;
8720 else if (TYPE_P (containing_scope))
8722 /* For types, we can just look up the appropriate DIE. But
8723 first we check to see if we're in the middle of emitting it
8724 so we know where the new DIE should go. */
8726 for (i = decl_scope_depth - 1; i >= 0; --i)
8727 if (decl_scope_table[i] == containing_scope)
8728 break;
8730 if (i < 0)
8732 if (debug_info_level > DINFO_LEVEL_TERSE
8733 && !TREE_ASM_WRITTEN (containing_scope))
8734 abort ();
8736 /* If none of the current dies are suitable, we get file scope. */
8737 scope_die = comp_unit_die;
8739 else
8740 scope_die = lookup_type_die (containing_scope);
8742 else
8743 scope_die = context_die;
8745 return scope_die;
8748 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
8750 static inline int local_scope_p PARAMS ((dw_die_ref));
8751 static inline int
8752 local_scope_p (context_die)
8753 dw_die_ref context_die;
8755 for (; context_die; context_die = context_die->die_parent)
8756 if (context_die->die_tag == DW_TAG_inlined_subroutine
8757 || context_die->die_tag == DW_TAG_subprogram)
8758 return 1;
8759 return 0;
8762 /* Returns nonzero iff CONTEXT_DIE is a class. */
8764 static inline int class_scope_p PARAMS ((dw_die_ref));
8765 static inline int
8766 class_scope_p (context_die)
8767 dw_die_ref context_die;
8769 return (context_die
8770 && (context_die->die_tag == DW_TAG_structure_type
8771 || context_die->die_tag == DW_TAG_union_type));
8774 /* Many forms of DIEs require a "type description" attribute. This
8775 routine locates the proper "type descriptor" die for the type given
8776 by 'type', and adds an DW_AT_type attribute below the given die. */
8778 static void
8779 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
8780 register dw_die_ref object_die;
8781 register tree type;
8782 register int decl_const;
8783 register int decl_volatile;
8784 register dw_die_ref context_die;
8786 register enum tree_code code = TREE_CODE (type);
8787 register dw_die_ref type_die = NULL;
8789 /* ??? If this type is an unnamed subrange type of an integral or
8790 floating-point type, use the inner type. This is because we have no
8791 support for unnamed types in base_type_die. This can happen if this is
8792 an Ada subrange type. Correct solution is emit a subrange type die. */
8793 if ((code == INTEGER_TYPE || code == REAL_TYPE)
8794 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
8795 type = TREE_TYPE (type), code = TREE_CODE (type);
8797 if (code == ERROR_MARK)
8798 return;
8800 /* Handle a special case. For functions whose return type is void, we
8801 generate *no* type attribute. (Note that no object may have type
8802 `void', so this only applies to function return types). */
8803 if (code == VOID_TYPE)
8804 return;
8806 type_die = modified_type_die (type,
8807 decl_const || TYPE_READONLY (type),
8808 decl_volatile || TYPE_VOLATILE (type),
8809 context_die);
8810 if (type_die != NULL)
8811 add_AT_die_ref (object_die, DW_AT_type, type_die);
8814 /* Given a tree pointer to a struct, class, union, or enum type node, return
8815 a pointer to the (string) tag name for the given type, or zero if the type
8816 was declared without a tag. */
8818 static const char *
8819 type_tag (type)
8820 register tree type;
8822 register const char *name = 0;
8824 if (TYPE_NAME (type) != 0)
8826 register tree t = 0;
8828 /* Find the IDENTIFIER_NODE for the type name. */
8829 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
8830 t = TYPE_NAME (type);
8832 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
8833 a TYPE_DECL node, regardless of whether or not a `typedef' was
8834 involved. */
8835 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8836 && ! DECL_IGNORED_P (TYPE_NAME (type)))
8837 t = DECL_NAME (TYPE_NAME (type));
8839 /* Now get the name as a string, or invent one. */
8840 if (t != 0)
8841 name = IDENTIFIER_POINTER (t);
8844 return (name == 0 || *name == '\0') ? 0 : name;
8847 /* Return the type associated with a data member, make a special check
8848 for bit field types. */
8850 static inline tree
8851 member_declared_type (member)
8852 register tree member;
8854 return (DECL_BIT_FIELD_TYPE (member)
8855 ? DECL_BIT_FIELD_TYPE (member)
8856 : TREE_TYPE (member));
8859 /* Get the decl's label, as described by its RTL. This may be different
8860 from the DECL_NAME name used in the source file. */
8862 #if 0
8863 static const char *
8864 decl_start_label (decl)
8865 register tree decl;
8867 rtx x;
8868 const char *fnname;
8869 x = DECL_RTL (decl);
8870 if (GET_CODE (x) != MEM)
8871 abort ();
8873 x = XEXP (x, 0);
8874 if (GET_CODE (x) != SYMBOL_REF)
8875 abort ();
8877 fnname = XSTR (x, 0);
8878 return fnname;
8880 #endif
8882 /* These routines generate the internal representation of the DIE's for
8883 the compilation unit. Debugging information is collected by walking
8884 the declaration trees passed in from dwarf2out_decl(). */
8886 static void
8887 gen_array_type_die (type, context_die)
8888 register tree type;
8889 register dw_die_ref context_die;
8891 register dw_die_ref scope_die = scope_die_for (type, context_die);
8892 register dw_die_ref array_die;
8893 register tree element_type;
8895 /* ??? The SGI dwarf reader fails for array of array of enum types unless
8896 the inner array type comes before the outer array type. Thus we must
8897 call gen_type_die before we call new_die. See below also. */
8898 #ifdef MIPS_DEBUGGING_INFO
8899 gen_type_die (TREE_TYPE (type), context_die);
8900 #endif
8902 array_die = new_die (DW_TAG_array_type, scope_die);
8904 #if 0
8905 /* We default the array ordering. SDB will probably do
8906 the right things even if DW_AT_ordering is not present. It's not even
8907 an issue until we start to get into multidimensional arrays anyway. If
8908 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
8909 then we'll have to put the DW_AT_ordering attribute back in. (But if
8910 and when we find out that we need to put these in, we will only do so
8911 for multidimensional arrays. */
8912 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
8913 #endif
8915 #ifdef MIPS_DEBUGGING_INFO
8916 /* The SGI compilers handle arrays of unknown bound by setting
8917 AT_declaration and not emitting any subrange DIEs. */
8918 if (! TYPE_DOMAIN (type))
8919 add_AT_unsigned (array_die, DW_AT_declaration, 1);
8920 else
8921 #endif
8922 add_subscript_info (array_die, type);
8924 add_name_attribute (array_die, type_tag (type));
8925 equate_type_number_to_die (type, array_die);
8927 /* Add representation of the type of the elements of this array type. */
8928 element_type = TREE_TYPE (type);
8930 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8931 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8932 We work around this by disabling this feature. See also
8933 add_subscript_info. */
8934 #ifndef MIPS_DEBUGGING_INFO
8935 while (TREE_CODE (element_type) == ARRAY_TYPE)
8936 element_type = TREE_TYPE (element_type);
8938 gen_type_die (element_type, context_die);
8939 #endif
8941 add_type_attribute (array_die, element_type, 0, 0, context_die);
8944 static void
8945 gen_set_type_die (type, context_die)
8946 register tree type;
8947 register dw_die_ref context_die;
8949 register dw_die_ref type_die
8950 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
8952 equate_type_number_to_die (type, type_die);
8953 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
8956 #if 0
8957 static void
8958 gen_entry_point_die (decl, context_die)
8959 register tree decl;
8960 register dw_die_ref context_die;
8962 register tree origin = decl_ultimate_origin (decl);
8963 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
8964 if (origin != NULL)
8965 add_abstract_origin_attribute (decl_die, origin);
8966 else
8968 add_name_and_src_coords_attributes (decl_die, decl);
8969 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
8970 0, 0, context_die);
8973 if (DECL_ABSTRACT (decl))
8974 equate_decl_number_to_die (decl, decl_die);
8975 else
8976 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
8978 #endif
8980 /* Remember a type in the incomplete_types_list. */
8982 static void
8983 add_incomplete_type (type)
8984 tree type;
8986 if (incomplete_types == incomplete_types_allocated)
8988 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
8989 incomplete_types_list
8990 = (tree *) xrealloc (incomplete_types_list,
8991 sizeof (tree) * incomplete_types_allocated);
8994 incomplete_types_list[incomplete_types++] = type;
8997 /* Walk through the list of incomplete types again, trying once more to
8998 emit full debugging info for them. */
9000 static void
9001 retry_incomplete_types ()
9003 register tree type;
9005 while (incomplete_types)
9007 --incomplete_types;
9008 type = incomplete_types_list[incomplete_types];
9009 gen_type_die (type, comp_unit_die);
9013 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9015 static void
9016 gen_inlined_enumeration_type_die (type, context_die)
9017 register tree type;
9018 register dw_die_ref context_die;
9020 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9021 context_die);
9022 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9023 be incomplete and such types are not marked. */
9024 add_abstract_origin_attribute (type_die, type);
9027 /* Generate a DIE to represent an inlined instance of a structure type. */
9029 static void
9030 gen_inlined_structure_type_die (type, context_die)
9031 register tree type;
9032 register dw_die_ref context_die;
9034 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9036 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9037 be incomplete and such types are not marked. */
9038 add_abstract_origin_attribute (type_die, type);
9041 /* Generate a DIE to represent an inlined instance of a union type. */
9043 static void
9044 gen_inlined_union_type_die (type, context_die)
9045 register tree type;
9046 register dw_die_ref context_die;
9048 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9050 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9051 be incomplete and such types are not marked. */
9052 add_abstract_origin_attribute (type_die, type);
9055 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9056 include all of the information about the enumeration values also. Each
9057 enumerated type name/value is listed as a child of the enumerated type
9058 DIE. */
9060 static void
9061 gen_enumeration_type_die (type, context_die)
9062 register tree type;
9063 register dw_die_ref context_die;
9065 register dw_die_ref type_die = lookup_type_die (type);
9067 if (type_die == NULL)
9069 type_die = new_die (DW_TAG_enumeration_type,
9070 scope_die_for (type, context_die));
9071 equate_type_number_to_die (type, type_die);
9072 add_name_attribute (type_die, type_tag (type));
9074 else if (! TYPE_SIZE (type))
9075 return;
9076 else
9077 remove_AT (type_die, DW_AT_declaration);
9079 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9080 given enum type is incomplete, do not generate the DW_AT_byte_size
9081 attribute or the DW_AT_element_list attribute. */
9082 if (TYPE_SIZE (type))
9084 register tree link;
9086 TREE_ASM_WRITTEN (type) = 1;
9087 add_byte_size_attribute (type_die, type);
9088 if (TYPE_STUB_DECL (type) != NULL_TREE)
9089 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9091 /* If the first reference to this type was as the return type of an
9092 inline function, then it may not have a parent. Fix this now. */
9093 if (type_die->die_parent == NULL)
9094 add_child_die (scope_die_for (type, context_die), type_die);
9096 for (link = TYPE_FIELDS (type);
9097 link != NULL; link = TREE_CHAIN (link))
9099 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9101 add_name_attribute (enum_die,
9102 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9104 if (host_integerp (TREE_VALUE (link), 0))
9106 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9107 add_AT_int (enum_die, DW_AT_const_value,
9108 tree_low_cst (TREE_VALUE (link), 0));
9109 else
9110 add_AT_unsigned (enum_die, DW_AT_const_value,
9111 tree_low_cst (TREE_VALUE (link), 0));
9115 else
9116 add_AT_flag (type_die, DW_AT_declaration, 1);
9119 /* Generate a DIE to represent either a real live formal parameter decl or to
9120 represent just the type of some formal parameter position in some function
9121 type.
9123 Note that this routine is a bit unusual because its argument may be a
9124 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9125 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9126 node. If it's the former then this function is being called to output a
9127 DIE to represent a formal parameter object (or some inlining thereof). If
9128 it's the latter, then this function is only being called to output a
9129 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9130 argument type of some subprogram type. */
9132 static dw_die_ref
9133 gen_formal_parameter_die (node, context_die)
9134 register tree node;
9135 register dw_die_ref context_die;
9137 register dw_die_ref parm_die
9138 = new_die (DW_TAG_formal_parameter, context_die);
9139 register tree origin;
9141 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9143 case 'd':
9144 origin = decl_ultimate_origin (node);
9145 if (origin != NULL)
9146 add_abstract_origin_attribute (parm_die, origin);
9147 else
9149 add_name_and_src_coords_attributes (parm_die, node);
9150 add_type_attribute (parm_die, TREE_TYPE (node),
9151 TREE_READONLY (node),
9152 TREE_THIS_VOLATILE (node),
9153 context_die);
9154 if (DECL_ARTIFICIAL (node))
9155 add_AT_flag (parm_die, DW_AT_artificial, 1);
9158 equate_decl_number_to_die (node, parm_die);
9159 if (! DECL_ABSTRACT (node))
9160 add_location_or_const_value_attribute (parm_die, node);
9162 break;
9164 case 't':
9165 /* We were called with some kind of a ..._TYPE node. */
9166 add_type_attribute (parm_die, node, 0, 0, context_die);
9167 break;
9169 default:
9170 abort ();
9173 return parm_die;
9176 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9177 at the end of an (ANSI prototyped) formal parameters list. */
9179 static void
9180 gen_unspecified_parameters_die (decl_or_type, context_die)
9181 register tree decl_or_type ATTRIBUTE_UNUSED;
9182 register dw_die_ref context_die;
9184 new_die (DW_TAG_unspecified_parameters, context_die);
9187 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9188 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9189 parameters as specified in some function type specification (except for
9190 those which appear as part of a function *definition*). */
9192 static void
9193 gen_formal_types_die (function_or_method_type, context_die)
9194 register tree function_or_method_type;
9195 register dw_die_ref context_die;
9197 register tree link;
9198 register tree formal_type = NULL;
9199 register tree first_parm_type;
9200 tree arg;
9202 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
9204 arg = DECL_ARGUMENTS (function_or_method_type);
9205 function_or_method_type = TREE_TYPE (function_or_method_type);
9207 else
9208 arg = NULL_TREE;
9210 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9212 /* Make our first pass over the list of formal parameter types and output a
9213 DW_TAG_formal_parameter DIE for each one. */
9214 for (link = first_parm_type; link; )
9216 register dw_die_ref parm_die;
9218 formal_type = TREE_VALUE (link);
9219 if (formal_type == void_type_node)
9220 break;
9222 /* Output a (nameless) DIE to represent the formal parameter itself. */
9223 parm_die = gen_formal_parameter_die (formal_type, context_die);
9224 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
9225 && link == first_parm_type)
9226 || (arg && DECL_ARTIFICIAL (arg)))
9227 add_AT_flag (parm_die, DW_AT_artificial, 1);
9229 link = TREE_CHAIN (link);
9230 if (arg)
9231 arg = TREE_CHAIN (arg);
9234 /* If this function type has an ellipsis, add a
9235 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9236 if (formal_type != void_type_node)
9237 gen_unspecified_parameters_die (function_or_method_type, context_die);
9239 /* Make our second (and final) pass over the list of formal parameter types
9240 and output DIEs to represent those types (as necessary). */
9241 for (link = TYPE_ARG_TYPES (function_or_method_type);
9242 link;
9243 link = TREE_CHAIN (link))
9245 formal_type = TREE_VALUE (link);
9246 if (formal_type == void_type_node)
9247 break;
9249 gen_type_die (formal_type, context_die);
9253 /* We want to generate the DIE for TYPE so that we can generate the
9254 die for MEMBER, which has been defined; we will need to refer back
9255 to the member declaration nested within TYPE. If we're trying to
9256 generate minimal debug info for TYPE, processing TYPE won't do the
9257 trick; we need to attach the member declaration by hand. */
9259 static void
9260 gen_type_die_for_member (type, member, context_die)
9261 tree type, member;
9262 dw_die_ref context_die;
9264 gen_type_die (type, context_die);
9266 /* If we're trying to avoid duplicate debug info, we may not have
9267 emitted the member decl for this function. Emit it now. */
9268 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9269 && ! lookup_decl_die (member))
9271 if (decl_ultimate_origin (member))
9272 abort ();
9274 push_decl_scope (type);
9275 if (TREE_CODE (member) == FUNCTION_DECL)
9276 gen_subprogram_die (member, lookup_type_die (type));
9277 else
9278 gen_variable_die (member, lookup_type_die (type));
9279 pop_decl_scope ();
9283 /* Generate the DWARF2 info for the "abstract" instance
9284 of a function which we may later generate inlined and/or
9285 out-of-line instances of. */
9287 void
9288 dwarf2out_abstract_function (decl)
9289 tree decl;
9291 register dw_die_ref old_die;
9292 tree save_fn;
9293 tree context;
9294 int was_abstract = DECL_ABSTRACT (decl);
9296 /* Make sure we have the actual abstract inline, not a clone. */
9297 decl = DECL_ORIGIN (decl);
9299 old_die = lookup_decl_die (decl);
9300 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9301 /* We've already generated the abstract instance. */
9302 return;
9304 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
9305 we don't get confused by DECL_ABSTRACT. */
9306 context = decl_class_context (decl);
9307 if (context)
9308 gen_type_die_for_member
9309 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
9311 /* Pretend we've just finished compiling this function. */
9312 save_fn = current_function_decl;
9313 current_function_decl = decl;
9315 set_decl_abstract_flags (decl, 1);
9316 dwarf2out_decl (decl);
9317 if (! was_abstract)
9318 set_decl_abstract_flags (decl, 0);
9320 current_function_decl = save_fn;
9323 /* Generate a DIE to represent a declared function (either file-scope or
9324 block-local). */
9326 static void
9327 gen_subprogram_die (decl, context_die)
9328 register tree decl;
9329 register dw_die_ref context_die;
9331 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9332 register tree origin = decl_ultimate_origin (decl);
9333 register dw_die_ref subr_die;
9334 register rtx fp_reg;
9335 register tree fn_arg_types;
9336 register tree outer_scope;
9337 register dw_die_ref old_die = lookup_decl_die (decl);
9338 register int declaration = (current_function_decl != decl
9339 || class_scope_p (context_die));
9341 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9342 be true, if we started to generate the abstract instance of an inline,
9343 decided to output its containing class, and proceeded to emit the
9344 declaration of the inline from the member list for the class. In that
9345 case, `declaration' takes priority; we'll get back to the abstract
9346 instance when we're done with the class. */
9348 /* The class-scope declaration DIE must be the primary DIE. */
9349 if (origin && declaration && class_scope_p (context_die))
9351 origin = NULL;
9352 if (old_die)
9353 abort ();
9356 if (origin != NULL)
9358 if (declaration && ! local_scope_p (context_die))
9359 abort ();
9361 /* Fixup die_parent for the abstract instance of a nested
9362 inline function. */
9363 if (old_die && old_die->die_parent == NULL)
9364 add_child_die (context_die, old_die);
9366 subr_die = new_die (DW_TAG_subprogram, context_die);
9367 add_abstract_origin_attribute (subr_die, origin);
9369 else if (old_die)
9371 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9373 if (!get_AT_flag (old_die, DW_AT_declaration)
9374 /* We can have a normal definition following an inline one in the
9375 case of redefinition of GNU C extern inlines.
9376 It seems reasonable to use AT_specification in this case. */
9377 && !get_AT_unsigned (old_die, DW_AT_inline))
9379 /* ??? This can happen if there is a bug in the program, for
9380 instance, if it has duplicate function definitions. Ideally,
9381 we should detect this case and ignore it. For now, if we have
9382 already reported an error, any error at all, then assume that
9383 we got here because of a input error, not a dwarf2 bug. */
9384 if (errorcount)
9385 return;
9386 abort ();
9389 /* If the definition comes from the same place as the declaration,
9390 maybe use the old DIE. We always want the DIE for this function
9391 that has the *_pc attributes to be under comp_unit_die so the
9392 debugger can find it. We also need to do this for abstract
9393 instances of inlines, since the spec requires the out-of-line copy
9394 to have the same parent. For local class methods, this doesn't
9395 apply; we just use the old DIE. */
9396 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
9397 && (DECL_ARTIFICIAL (decl)
9398 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9399 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9400 == (unsigned) DECL_SOURCE_LINE (decl)))))
9402 subr_die = old_die;
9404 /* Clear out the declaration attribute and the parm types. */
9405 remove_AT (subr_die, DW_AT_declaration);
9406 remove_children (subr_die);
9408 else
9410 subr_die = new_die (DW_TAG_subprogram, context_die);
9411 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9412 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9413 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9414 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9415 != (unsigned) DECL_SOURCE_LINE (decl))
9416 add_AT_unsigned
9417 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9420 else
9422 subr_die = new_die (DW_TAG_subprogram, context_die);
9424 if (TREE_PUBLIC (decl))
9425 add_AT_flag (subr_die, DW_AT_external, 1);
9427 add_name_and_src_coords_attributes (subr_die, decl);
9428 if (debug_info_level > DINFO_LEVEL_TERSE)
9430 register tree type = TREE_TYPE (decl);
9432 add_prototyped_attribute (subr_die, type);
9433 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9436 add_pure_or_virtual_attribute (subr_die, decl);
9437 if (DECL_ARTIFICIAL (decl))
9438 add_AT_flag (subr_die, DW_AT_artificial, 1);
9439 if (TREE_PROTECTED (decl))
9440 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9441 else if (TREE_PRIVATE (decl))
9442 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9445 if (declaration)
9447 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9449 add_AT_flag (subr_die, DW_AT_declaration, 1);
9451 /* The first time we see a member function, it is in the context of
9452 the class to which it belongs. We make sure of this by emitting
9453 the class first. The next time is the definition, which is
9454 handled above. The two may come from the same source text. */
9455 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9456 equate_decl_number_to_die (decl, subr_die);
9459 else if (DECL_ABSTRACT (decl))
9461 if (DECL_INLINE (decl) && !flag_no_inline)
9463 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9464 inline functions, but not for extern inline functions.
9465 We can't get this completely correct because information
9466 about whether the function was declared inline is not
9467 saved anywhere. */
9468 if (DECL_DEFER_OUTPUT (decl))
9469 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9470 else
9471 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9473 else
9474 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9476 equate_decl_number_to_die (decl, subr_die);
9478 else if (!DECL_EXTERNAL (decl))
9480 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9481 equate_decl_number_to_die (decl, subr_die);
9483 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9484 current_funcdef_number);
9485 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
9486 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
9487 current_funcdef_number);
9488 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
9490 add_pubname (decl, subr_die);
9491 add_arange (decl, subr_die);
9493 #ifdef MIPS_DEBUGGING_INFO
9494 /* Add a reference to the FDE for this routine. */
9495 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
9496 #endif
9498 /* Define the "frame base" location for this routine. We use the
9499 frame pointer or stack pointer registers, since the RTL for local
9500 variables is relative to one of them. */
9501 fp_reg
9502 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
9503 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
9505 #if 0
9506 /* ??? This fails for nested inline functions, because context_display
9507 is not part of the state saved/restored for inline functions. */
9508 if (current_function_needs_context)
9509 add_AT_location_description (subr_die, DW_AT_static_link,
9510 lookup_static_chain (decl));
9511 #endif
9514 /* Now output descriptions of the arguments for this function. This gets
9515 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
9516 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
9517 `...' at the end of the formal parameter list. In order to find out if
9518 there was a trailing ellipsis or not, we must instead look at the type
9519 associated with the FUNCTION_DECL. This will be a node of type
9520 FUNCTION_TYPE. If the chain of type nodes hanging off of this
9521 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
9522 an ellipsis at the end. */
9524 /* In the case where we are describing a mere function declaration, all we
9525 need to do here (and all we *can* do here) is to describe the *types* of
9526 its formal parameters. */
9527 if (debug_info_level <= DINFO_LEVEL_TERSE)
9529 else if (declaration)
9530 gen_formal_types_die (decl, subr_die);
9531 else
9533 /* Generate DIEs to represent all known formal parameters */
9534 register tree arg_decls = DECL_ARGUMENTS (decl);
9535 register tree parm;
9537 /* When generating DIEs, generate the unspecified_parameters DIE
9538 instead if we come across the arg "__builtin_va_alist" */
9539 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
9540 if (TREE_CODE (parm) == PARM_DECL)
9542 if (DECL_NAME (parm)
9543 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
9544 "__builtin_va_alist"))
9545 gen_unspecified_parameters_die (parm, subr_die);
9546 else
9547 gen_decl_die (parm, subr_die);
9550 /* Decide whether we need a unspecified_parameters DIE at the end.
9551 There are 2 more cases to do this for: 1) the ansi ... declaration -
9552 this is detectable when the end of the arg list is not a
9553 void_type_node 2) an unprototyped function declaration (not a
9554 definition). This just means that we have no info about the
9555 parameters at all. */
9556 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
9557 if (fn_arg_types != NULL)
9559 /* this is the prototyped case, check for ... */
9560 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
9561 gen_unspecified_parameters_die (decl, subr_die);
9563 else if (DECL_INITIAL (decl) == NULL_TREE)
9564 gen_unspecified_parameters_die (decl, subr_die);
9567 /* Output Dwarf info for all of the stuff within the body of the function
9568 (if it has one - it may be just a declaration). */
9569 outer_scope = DECL_INITIAL (decl);
9571 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
9572 node created to represent a function. This outermost BLOCK actually
9573 represents the outermost binding contour for the function, i.e. the
9574 contour in which the function's formal parameters and labels get
9575 declared. Curiously, it appears that the front end doesn't actually
9576 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
9577 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
9578 list for the function instead.) The BLOCK_VARS list for the
9579 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
9580 the function however, and we output DWARF info for those in
9581 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
9582 node representing the function's outermost pair of curly braces, and
9583 any blocks used for the base and member initializers of a C++
9584 constructor function. */
9585 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
9587 current_function_has_inlines = 0;
9588 decls_for_scope (outer_scope, subr_die, 0);
9590 #if 0 && defined (MIPS_DEBUGGING_INFO)
9591 if (current_function_has_inlines)
9593 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
9594 if (! comp_unit_has_inlines)
9596 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
9597 comp_unit_has_inlines = 1;
9600 #endif
9604 /* Generate a DIE to represent a declared data object. */
9606 static void
9607 gen_variable_die (decl, context_die)
9608 register tree decl;
9609 register dw_die_ref context_die;
9611 register tree origin = decl_ultimate_origin (decl);
9612 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
9614 dw_die_ref old_die = lookup_decl_die (decl);
9615 int declaration = (DECL_EXTERNAL (decl)
9616 || class_scope_p (context_die));
9618 if (origin != NULL)
9619 add_abstract_origin_attribute (var_die, origin);
9620 /* Loop unrolling can create multiple blocks that refer to the same
9621 static variable, so we must test for the DW_AT_declaration flag. */
9622 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
9623 copy decls and set the DECL_ABSTRACT flag on them instead of
9624 sharing them. */
9625 else if (old_die && TREE_STATIC (decl)
9626 && get_AT_flag (old_die, DW_AT_declaration) == 1)
9628 /* This is a definition of a C++ class level static. */
9629 add_AT_die_ref (var_die, DW_AT_specification, old_die);
9630 if (DECL_NAME (decl))
9632 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9634 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9635 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
9637 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9638 != (unsigned) DECL_SOURCE_LINE (decl))
9640 add_AT_unsigned (var_die, DW_AT_decl_line,
9641 DECL_SOURCE_LINE (decl));
9644 else
9646 add_name_and_src_coords_attributes (var_die, decl);
9647 add_type_attribute (var_die, TREE_TYPE (decl),
9648 TREE_READONLY (decl),
9649 TREE_THIS_VOLATILE (decl), context_die);
9651 if (TREE_PUBLIC (decl))
9652 add_AT_flag (var_die, DW_AT_external, 1);
9654 if (DECL_ARTIFICIAL (decl))
9655 add_AT_flag (var_die, DW_AT_artificial, 1);
9657 if (TREE_PROTECTED (decl))
9658 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
9660 else if (TREE_PRIVATE (decl))
9661 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
9664 if (declaration)
9665 add_AT_flag (var_die, DW_AT_declaration, 1);
9667 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
9668 equate_decl_number_to_die (decl, var_die);
9670 if (! declaration && ! DECL_ABSTRACT (decl))
9672 add_location_or_const_value_attribute (var_die, decl);
9673 add_pubname (decl, var_die);
9675 else
9676 tree_add_const_value_attribute (var_die, decl);
9679 /* Generate a DIE to represent a label identifier. */
9681 static void
9682 gen_label_die (decl, context_die)
9683 register tree decl;
9684 register dw_die_ref context_die;
9686 register tree origin = decl_ultimate_origin (decl);
9687 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
9688 register rtx insn;
9689 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9691 if (origin != NULL)
9692 add_abstract_origin_attribute (lbl_die, origin);
9693 else
9694 add_name_and_src_coords_attributes (lbl_die, decl);
9696 if (DECL_ABSTRACT (decl))
9697 equate_decl_number_to_die (decl, lbl_die);
9698 else
9700 insn = DECL_RTL (decl);
9702 /* Deleted labels are programmer specified labels which have been
9703 eliminated because of various optimisations. We still emit them
9704 here so that it is possible to put breakpoints on them. */
9705 if (GET_CODE (insn) == CODE_LABEL
9706 || ((GET_CODE (insn) == NOTE
9707 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
9709 /* When optimization is enabled (via -O) some parts of the compiler
9710 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
9711 represent source-level labels which were explicitly declared by
9712 the user. This really shouldn't be happening though, so catch
9713 it if it ever does happen. */
9714 if (INSN_DELETED_P (insn))
9715 abort ();
9717 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
9718 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
9723 /* Generate a DIE for a lexical block. */
9725 static void
9726 gen_lexical_block_die (stmt, context_die, depth)
9727 register tree stmt;
9728 register dw_die_ref context_die;
9729 int depth;
9731 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
9732 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9734 if (! BLOCK_ABSTRACT (stmt))
9736 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9737 BLOCK_NUMBER (stmt));
9738 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
9739 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9740 BLOCK_NUMBER (stmt));
9741 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
9744 decls_for_scope (stmt, stmt_die, depth);
9747 /* Generate a DIE for an inlined subprogram. */
9749 static void
9750 gen_inlined_subroutine_die (stmt, context_die, depth)
9751 register tree stmt;
9752 register dw_die_ref context_die;
9753 int depth;
9755 if (! BLOCK_ABSTRACT (stmt))
9757 register dw_die_ref subr_die
9758 = new_die (DW_TAG_inlined_subroutine, context_die);
9759 register tree decl = block_ultimate_origin (stmt);
9760 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9762 /* Emit info for the abstract instance first, if we haven't yet. */
9763 dwarf2out_abstract_function (decl);
9765 add_abstract_origin_attribute (subr_die, decl);
9766 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
9767 BLOCK_NUMBER (stmt));
9768 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
9769 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
9770 BLOCK_NUMBER (stmt));
9771 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
9772 decls_for_scope (stmt, subr_die, depth);
9773 current_function_has_inlines = 1;
9777 /* Generate a DIE for a field in a record, or structure. */
9779 static void
9780 gen_field_die (decl, context_die)
9781 register tree decl;
9782 register dw_die_ref context_die;
9784 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
9786 add_name_and_src_coords_attributes (decl_die, decl);
9787 add_type_attribute (decl_die, member_declared_type (decl),
9788 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
9789 context_die);
9791 /* If this is a bit field... */
9792 if (DECL_BIT_FIELD_TYPE (decl))
9794 add_byte_size_attribute (decl_die, decl);
9795 add_bit_size_attribute (decl_die, decl);
9796 add_bit_offset_attribute (decl_die, decl);
9799 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
9800 add_data_member_location_attribute (decl_die, decl);
9802 if (DECL_ARTIFICIAL (decl))
9803 add_AT_flag (decl_die, DW_AT_artificial, 1);
9805 if (TREE_PROTECTED (decl))
9806 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
9808 else if (TREE_PRIVATE (decl))
9809 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
9812 #if 0
9813 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9814 Use modified_type_die instead.
9815 We keep this code here just in case these types of DIEs may be needed to
9816 represent certain things in other languages (e.g. Pascal) someday. */
9817 static void
9818 gen_pointer_type_die (type, context_die)
9819 register tree type;
9820 register dw_die_ref context_die;
9822 register dw_die_ref ptr_die
9823 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
9825 equate_type_number_to_die (type, ptr_die);
9826 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9827 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9830 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
9831 Use modified_type_die instead.
9832 We keep this code here just in case these types of DIEs may be needed to
9833 represent certain things in other languages (e.g. Pascal) someday. */
9834 static void
9835 gen_reference_type_die (type, context_die)
9836 register tree type;
9837 register dw_die_ref context_die;
9839 register dw_die_ref ref_die
9840 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
9842 equate_type_number_to_die (type, ref_die);
9843 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
9844 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
9846 #endif
9848 /* Generate a DIE for a pointer to a member type. */
9849 static void
9850 gen_ptr_to_mbr_type_die (type, context_die)
9851 register tree type;
9852 register dw_die_ref context_die;
9854 register dw_die_ref ptr_die
9855 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
9857 equate_type_number_to_die (type, ptr_die);
9858 add_AT_die_ref (ptr_die, DW_AT_containing_type,
9859 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
9860 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
9863 /* Generate the DIE for the compilation unit. */
9865 static dw_die_ref
9866 gen_compile_unit_die (filename)
9867 register const char *filename;
9869 register dw_die_ref die;
9870 char producer[250];
9871 const char *wd = getpwd ();
9872 int language;
9874 die = new_die (DW_TAG_compile_unit, NULL);
9875 add_name_attribute (die, filename);
9877 if (wd != NULL && filename[0] != DIR_SEPARATOR)
9878 add_AT_string (die, DW_AT_comp_dir, wd);
9880 sprintf (producer, "%s %s", language_string, version_string);
9882 #ifdef MIPS_DEBUGGING_INFO
9883 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
9884 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
9885 not appear in the producer string, the debugger reaches the conclusion
9886 that the object file is stripped and has no debugging information.
9887 To get the MIPS/SGI debugger to believe that there is debugging
9888 information in the object file, we add a -g to the producer string. */
9889 if (debug_info_level > DINFO_LEVEL_TERSE)
9890 strcat (producer, " -g");
9891 #endif
9893 add_AT_string (die, DW_AT_producer, producer);
9895 if (strcmp (language_string, "GNU C++") == 0)
9896 language = DW_LANG_C_plus_plus;
9897 else if (strcmp (language_string, "GNU Ada") == 0)
9898 language = DW_LANG_Ada83;
9899 else if (strcmp (language_string, "GNU F77") == 0)
9900 language = DW_LANG_Fortran77;
9901 else if (strcmp (language_string, "GNU Pascal") == 0)
9902 language = DW_LANG_Pascal83;
9903 else if (strcmp (language_string, "GNU Java") == 0)
9904 language = DW_LANG_Java;
9905 else if (flag_traditional)
9906 language = DW_LANG_C;
9907 else
9908 language = DW_LANG_C89;
9910 add_AT_unsigned (die, DW_AT_language, language);
9912 return die;
9915 /* Generate a DIE for a string type. */
9917 static void
9918 gen_string_type_die (type, context_die)
9919 register tree type;
9920 register dw_die_ref context_die;
9922 register dw_die_ref type_die
9923 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
9925 equate_type_number_to_die (type, type_die);
9927 /* Fudge the string length attribute for now. */
9929 /* TODO: add string length info.
9930 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
9931 bound_representation (upper_bound, 0, 'u'); */
9934 /* Generate the DIE for a base class. */
9936 static void
9937 gen_inheritance_die (binfo, context_die)
9938 register tree binfo;
9939 register dw_die_ref context_die;
9941 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
9943 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
9944 add_data_member_location_attribute (die, binfo);
9946 if (TREE_VIA_VIRTUAL (binfo))
9947 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9948 if (TREE_VIA_PUBLIC (binfo))
9949 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
9950 else if (TREE_VIA_PROTECTED (binfo))
9951 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
9954 /* Generate a DIE for a class member. */
9956 static void
9957 gen_member_die (type, context_die)
9958 register tree type;
9959 register dw_die_ref context_die;
9961 register tree member;
9962 dw_die_ref child;
9964 /* If this is not an incomplete type, output descriptions of each of its
9965 members. Note that as we output the DIEs necessary to represent the
9966 members of this record or union type, we will also be trying to output
9967 DIEs to represent the *types* of those members. However the `type'
9968 function (above) will specifically avoid generating type DIEs for member
9969 types *within* the list of member DIEs for this (containing) type execpt
9970 for those types (of members) which are explicitly marked as also being
9971 members of this (containing) type themselves. The g++ front- end can
9972 force any given type to be treated as a member of some other
9973 (containing) type by setting the TYPE_CONTEXT of the given (member) type
9974 to point to the TREE node representing the appropriate (containing)
9975 type. */
9977 /* First output info about the base classes. */
9978 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
9980 register tree bases = TYPE_BINFO_BASETYPES (type);
9981 register int n_bases = TREE_VEC_LENGTH (bases);
9982 register int i;
9984 for (i = 0; i < n_bases; i++)
9985 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
9988 /* Now output info about the data members and type members. */
9989 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
9991 /* If we thought we were generating minimal debug info for TYPE
9992 and then changed our minds, some of the member declarations
9993 may have already been defined. Don't define them again, but
9994 do put them in the right order. */
9996 child = lookup_decl_die (member);
9997 if (child)
9998 splice_child_die (context_die, child);
9999 else
10000 gen_decl_die (member, context_die);
10003 /* Now output info about the function members (if any). */
10004 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10006 /* Don't include clones in the member list. */
10007 if (DECL_ABSTRACT_ORIGIN (member))
10008 continue;
10010 child = lookup_decl_die (member);
10011 if (child)
10012 splice_child_die (context_die, child);
10013 else
10014 gen_decl_die (member, context_die);
10018 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10019 is set, we pretend that the type was never defined, so we only get the
10020 member DIEs needed by later specification DIEs. */
10022 static void
10023 gen_struct_or_union_type_die (type, context_die)
10024 register tree type;
10025 register dw_die_ref context_die;
10027 register dw_die_ref type_die = lookup_type_die (type);
10028 register dw_die_ref scope_die = 0;
10029 register int nested = 0;
10030 int complete = (TYPE_SIZE (type)
10031 && (! TYPE_STUB_DECL (type)
10032 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10034 if (type_die && ! complete)
10035 return;
10037 if (TYPE_CONTEXT (type) != NULL_TREE
10038 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10039 nested = 1;
10041 scope_die = scope_die_for (type, context_die);
10043 if (! type_die || (nested && scope_die == comp_unit_die))
10044 /* First occurrence of type or toplevel definition of nested class. */
10046 register dw_die_ref old_die = type_die;
10048 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10049 ? DW_TAG_structure_type : DW_TAG_union_type,
10050 scope_die);
10051 equate_type_number_to_die (type, type_die);
10052 if (old_die)
10053 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10054 else
10055 add_name_attribute (type_die, type_tag (type));
10057 else
10058 remove_AT (type_die, DW_AT_declaration);
10060 /* If this type has been completed, then give it a byte_size attribute and
10061 then give a list of members. */
10062 if (complete)
10064 /* Prevent infinite recursion in cases where the type of some member of
10065 this type is expressed in terms of this type itself. */
10066 TREE_ASM_WRITTEN (type) = 1;
10067 add_byte_size_attribute (type_die, type);
10068 if (TYPE_STUB_DECL (type) != NULL_TREE)
10069 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10071 /* If the first reference to this type was as the return type of an
10072 inline function, then it may not have a parent. Fix this now. */
10073 if (type_die->die_parent == NULL)
10074 add_child_die (scope_die, type_die);
10076 push_decl_scope (type);
10077 gen_member_die (type, type_die);
10078 pop_decl_scope ();
10080 /* GNU extension: Record what type our vtable lives in. */
10081 if (TYPE_VFIELD (type))
10083 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10085 gen_type_die (vtype, context_die);
10086 add_AT_die_ref (type_die, DW_AT_containing_type,
10087 lookup_type_die (vtype));
10090 else
10092 add_AT_flag (type_die, DW_AT_declaration, 1);
10094 /* We don't need to do this for function-local types. */
10095 if (! decl_function_context (TYPE_STUB_DECL (type)))
10096 add_incomplete_type (type);
10100 /* Generate a DIE for a subroutine _type_. */
10102 static void
10103 gen_subroutine_type_die (type, context_die)
10104 register tree type;
10105 register dw_die_ref context_die;
10107 register tree return_type = TREE_TYPE (type);
10108 register dw_die_ref subr_die
10109 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10111 equate_type_number_to_die (type, subr_die);
10112 add_prototyped_attribute (subr_die, type);
10113 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10114 gen_formal_types_die (type, subr_die);
10117 /* Generate a DIE for a type definition */
10119 static void
10120 gen_typedef_die (decl, context_die)
10121 register tree decl;
10122 register dw_die_ref context_die;
10124 register dw_die_ref type_die;
10125 register tree origin;
10127 if (TREE_ASM_WRITTEN (decl))
10128 return;
10129 TREE_ASM_WRITTEN (decl) = 1;
10131 type_die = new_die (DW_TAG_typedef, context_die);
10132 origin = decl_ultimate_origin (decl);
10133 if (origin != NULL)
10134 add_abstract_origin_attribute (type_die, origin);
10135 else
10137 register tree type;
10138 add_name_and_src_coords_attributes (type_die, decl);
10139 if (DECL_ORIGINAL_TYPE (decl))
10141 type = DECL_ORIGINAL_TYPE (decl);
10143 if (type == TREE_TYPE (decl))
10144 abort ();
10145 else
10146 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10148 else
10149 type = TREE_TYPE (decl);
10150 add_type_attribute (type_die, type, TREE_READONLY (decl),
10151 TREE_THIS_VOLATILE (decl), context_die);
10154 if (DECL_ABSTRACT (decl))
10155 equate_decl_number_to_die (decl, type_die);
10158 /* Generate a type description DIE. */
10160 static void
10161 gen_type_die (type, context_die)
10162 register tree type;
10163 register dw_die_ref context_die;
10165 int need_pop;
10167 if (type == NULL_TREE || type == error_mark_node)
10168 return;
10170 /* We are going to output a DIE to represent the unqualified version of
10171 this type (i.e. without any const or volatile qualifiers) so get the
10172 main variant (i.e. the unqualified version) of this type now. */
10173 type = type_main_variant (type);
10175 if (TREE_ASM_WRITTEN (type))
10176 return;
10178 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10179 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10181 TREE_ASM_WRITTEN (type) = 1;
10182 gen_decl_die (TYPE_NAME (type), context_die);
10183 return;
10186 switch (TREE_CODE (type))
10188 case ERROR_MARK:
10189 break;
10191 case POINTER_TYPE:
10192 case REFERENCE_TYPE:
10193 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10194 ensures that the gen_type_die recursion will terminate even if the
10195 type is recursive. Recursive types are possible in Ada. */
10196 /* ??? We could perhaps do this for all types before the switch
10197 statement. */
10198 TREE_ASM_WRITTEN (type) = 1;
10200 /* For these types, all that is required is that we output a DIE (or a
10201 set of DIEs) to represent the "basis" type. */
10202 gen_type_die (TREE_TYPE (type), context_die);
10203 break;
10205 case OFFSET_TYPE:
10206 /* This code is used for C++ pointer-to-data-member types.
10207 Output a description of the relevant class type. */
10208 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10210 /* Output a description of the type of the object pointed to. */
10211 gen_type_die (TREE_TYPE (type), context_die);
10213 /* Now output a DIE to represent this pointer-to-data-member type
10214 itself. */
10215 gen_ptr_to_mbr_type_die (type, context_die);
10216 break;
10218 case SET_TYPE:
10219 gen_type_die (TYPE_DOMAIN (type), context_die);
10220 gen_set_type_die (type, context_die);
10221 break;
10223 case FILE_TYPE:
10224 gen_type_die (TREE_TYPE (type), context_die);
10225 abort (); /* No way to represent these in Dwarf yet! */
10226 break;
10228 case FUNCTION_TYPE:
10229 /* Force out return type (in case it wasn't forced out already). */
10230 gen_type_die (TREE_TYPE (type), context_die);
10231 gen_subroutine_type_die (type, context_die);
10232 break;
10234 case METHOD_TYPE:
10235 /* Force out return type (in case it wasn't forced out already). */
10236 gen_type_die (TREE_TYPE (type), context_die);
10237 gen_subroutine_type_die (type, context_die);
10238 break;
10240 case ARRAY_TYPE:
10241 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10243 gen_type_die (TREE_TYPE (type), context_die);
10244 gen_string_type_die (type, context_die);
10246 else
10247 gen_array_type_die (type, context_die);
10248 break;
10250 case VECTOR_TYPE:
10251 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10252 break;
10254 case ENUMERAL_TYPE:
10255 case RECORD_TYPE:
10256 case UNION_TYPE:
10257 case QUAL_UNION_TYPE:
10258 /* If this is a nested type whose containing class hasn't been
10259 written out yet, writing it out will cover this one, too.
10260 This does not apply to instantiations of member class templates;
10261 they need to be added to the containing class as they are
10262 generated. FIXME: This hurts the idea of combining type decls
10263 from multiple TUs, since we can't predict what set of template
10264 instantiations we'll get. */
10265 if (TYPE_CONTEXT (type)
10266 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10267 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10269 gen_type_die (TYPE_CONTEXT (type), context_die);
10271 if (TREE_ASM_WRITTEN (type))
10272 return;
10274 /* If that failed, attach ourselves to the stub. */
10275 push_decl_scope (TYPE_CONTEXT (type));
10276 context_die = lookup_type_die (TYPE_CONTEXT (type));
10277 need_pop = 1;
10279 else
10280 need_pop = 0;
10282 if (TREE_CODE (type) == ENUMERAL_TYPE)
10283 gen_enumeration_type_die (type, context_die);
10284 else
10285 gen_struct_or_union_type_die (type, context_die);
10287 if (need_pop)
10288 pop_decl_scope ();
10290 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10291 it up if it is ever completed. gen_*_type_die will set it for us
10292 when appropriate. */
10293 return;
10295 case VOID_TYPE:
10296 case INTEGER_TYPE:
10297 case REAL_TYPE:
10298 case COMPLEX_TYPE:
10299 case BOOLEAN_TYPE:
10300 case CHAR_TYPE:
10301 /* No DIEs needed for fundamental types. */
10302 break;
10304 case LANG_TYPE:
10305 /* No Dwarf representation currently defined. */
10306 break;
10308 default:
10309 abort ();
10312 TREE_ASM_WRITTEN (type) = 1;
10315 /* Generate a DIE for a tagged type instantiation. */
10317 static void
10318 gen_tagged_type_instantiation_die (type, context_die)
10319 register tree type;
10320 register dw_die_ref context_die;
10322 if (type == NULL_TREE || type == error_mark_node)
10323 return;
10325 /* We are going to output a DIE to represent the unqualified version of
10326 this type (i.e. without any const or volatile qualifiers) so make sure
10327 that we have the main variant (i.e. the unqualified version) of this
10328 type now. */
10329 if (type != type_main_variant (type))
10330 abort ();
10332 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10333 an instance of an unresolved type. */
10335 switch (TREE_CODE (type))
10337 case ERROR_MARK:
10338 break;
10340 case ENUMERAL_TYPE:
10341 gen_inlined_enumeration_type_die (type, context_die);
10342 break;
10344 case RECORD_TYPE:
10345 gen_inlined_structure_type_die (type, context_die);
10346 break;
10348 case UNION_TYPE:
10349 case QUAL_UNION_TYPE:
10350 gen_inlined_union_type_die (type, context_die);
10351 break;
10353 default:
10354 abort ();
10358 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10359 things which are local to the given block. */
10361 static void
10362 gen_block_die (stmt, context_die, depth)
10363 register tree stmt;
10364 register dw_die_ref context_die;
10365 int depth;
10367 register int must_output_die = 0;
10368 register tree origin;
10369 register tree decl;
10370 register enum tree_code origin_code;
10372 /* Ignore blocks never really used to make RTL. */
10374 if (stmt == NULL_TREE || !TREE_USED (stmt)
10375 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10376 return;
10378 /* Determine the "ultimate origin" of this block. This block may be an
10379 inlined instance of an inlined instance of inline function, so we have
10380 to trace all of the way back through the origin chain to find out what
10381 sort of node actually served as the original seed for the creation of
10382 the current block. */
10383 origin = block_ultimate_origin (stmt);
10384 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10386 /* Determine if we need to output any Dwarf DIEs at all to represent this
10387 block. */
10388 if (origin_code == FUNCTION_DECL)
10389 /* The outer scopes for inlinings *must* always be represented. We
10390 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10391 must_output_die = 1;
10392 else
10394 /* In the case where the current block represents an inlining of the
10395 "body block" of an inline function, we must *NOT* output any DIE for
10396 this block because we have already output a DIE to represent the
10397 whole inlined function scope and the "body block" of any function
10398 doesn't really represent a different scope according to ANSI C
10399 rules. So we check here to make sure that this block does not
10400 represent a "body block inlining" before trying to set the
10401 `must_output_die' flag. */
10402 if (! is_body_block (origin ? origin : stmt))
10404 /* Determine if this block directly contains any "significant"
10405 local declarations which we will need to output DIEs for. */
10406 if (debug_info_level > DINFO_LEVEL_TERSE)
10407 /* We are not in terse mode so *any* local declaration counts
10408 as being a "significant" one. */
10409 must_output_die = (BLOCK_VARS (stmt) != NULL);
10410 else
10411 /* We are in terse mode, so only local (nested) function
10412 definitions count as "significant" local declarations. */
10413 for (decl = BLOCK_VARS (stmt);
10414 decl != NULL; decl = TREE_CHAIN (decl))
10415 if (TREE_CODE (decl) == FUNCTION_DECL
10416 && DECL_INITIAL (decl))
10418 must_output_die = 1;
10419 break;
10424 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10425 DIE for any block which contains no significant local declarations at
10426 all. Rather, in such cases we just call `decls_for_scope' so that any
10427 needed Dwarf info for any sub-blocks will get properly generated. Note
10428 that in terse mode, our definition of what constitutes a "significant"
10429 local declaration gets restricted to include only inlined function
10430 instances and local (nested) function definitions. */
10431 if (must_output_die)
10433 if (origin_code == FUNCTION_DECL)
10434 gen_inlined_subroutine_die (stmt, context_die, depth);
10435 else
10436 gen_lexical_block_die (stmt, context_die, depth);
10438 else
10439 decls_for_scope (stmt, context_die, depth);
10442 /* Generate all of the decls declared within a given scope and (recursively)
10443 all of its sub-blocks. */
10445 static void
10446 decls_for_scope (stmt, context_die, depth)
10447 register tree stmt;
10448 register dw_die_ref context_die;
10449 int depth;
10451 register tree decl;
10452 register tree subblocks;
10454 /* Ignore blocks never really used to make RTL. */
10455 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10456 return;
10458 /* Output the DIEs to represent all of the data objects and typedefs
10459 declared directly within this block but not within any nested
10460 sub-blocks. Also, nested function and tag DIEs have been
10461 generated with a parent of NULL; fix that up now. */
10462 for (decl = BLOCK_VARS (stmt);
10463 decl != NULL; decl = TREE_CHAIN (decl))
10465 register dw_die_ref die;
10467 if (TREE_CODE (decl) == FUNCTION_DECL)
10468 die = lookup_decl_die (decl);
10469 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
10470 die = lookup_type_die (TREE_TYPE (decl));
10471 else
10472 die = NULL;
10474 if (die != NULL && die->die_parent == NULL)
10475 add_child_die (context_die, die);
10476 else
10477 gen_decl_die (decl, context_die);
10480 /* Output the DIEs to represent all sub-blocks (and the items declared
10481 therein) of this block. */
10482 for (subblocks = BLOCK_SUBBLOCKS (stmt);
10483 subblocks != NULL;
10484 subblocks = BLOCK_CHAIN (subblocks))
10485 gen_block_die (subblocks, context_die, depth + 1);
10488 /* Is this a typedef we can avoid emitting? */
10490 static inline int
10491 is_redundant_typedef (decl)
10492 register tree decl;
10494 if (TYPE_DECL_IS_STUB (decl))
10495 return 1;
10497 if (DECL_ARTIFICIAL (decl)
10498 && DECL_CONTEXT (decl)
10499 && is_tagged_type (DECL_CONTEXT (decl))
10500 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
10501 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
10502 /* Also ignore the artificial member typedef for the class name. */
10503 return 1;
10505 return 0;
10508 /* Generate Dwarf debug information for a decl described by DECL. */
10510 static void
10511 gen_decl_die (decl, context_die)
10512 register tree decl;
10513 register dw_die_ref context_die;
10515 register tree origin;
10517 if (TREE_CODE (decl) == ERROR_MARK)
10518 return;
10520 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10521 if (DECL_IGNORED_P (decl))
10522 return;
10524 switch (TREE_CODE (decl))
10526 case CONST_DECL:
10527 /* The individual enumerators of an enum type get output when we output
10528 the Dwarf representation of the relevant enum type itself. */
10529 break;
10531 case FUNCTION_DECL:
10532 /* Don't output any DIEs to represent mere function declarations,
10533 unless they are class members or explicit block externs. */
10534 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
10535 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
10536 break;
10538 /* If we're emitting a clone, emit info for the abstract instance. */
10539 if (DECL_ORIGIN (decl) != decl)
10540 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
10541 /* If we're emitting an out-of-line copy of an inline function,
10542 emit info for the abstract instance and set up to refer to it. */
10543 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
10544 && ! class_scope_p (context_die)
10545 /* dwarf2out_abstract_function won't emit a die if this is just
10546 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
10547 that case, because that works only if we have a die. */
10548 && DECL_INITIAL (decl) != NULL_TREE)
10550 dwarf2out_abstract_function (decl);
10551 set_decl_origin_self (decl);
10553 /* Otherwise we're emitting the primary DIE for this decl. */
10554 else if (debug_info_level > DINFO_LEVEL_TERSE)
10556 /* Before we describe the FUNCTION_DECL itself, make sure that we
10557 have described its return type. */
10558 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
10560 /* And its virtual context. */
10561 if (DECL_VINDEX (decl) != NULL_TREE)
10562 gen_type_die (DECL_CONTEXT (decl), context_die);
10564 /* And its containing type. */
10565 origin = decl_class_context (decl);
10566 if (origin != NULL_TREE)
10567 gen_type_die_for_member (origin, decl, context_die);
10570 /* Now output a DIE to represent the function itself. */
10571 gen_subprogram_die (decl, context_die);
10572 break;
10574 case TYPE_DECL:
10575 /* If we are in terse mode, don't generate any DIEs to represent any
10576 actual typedefs. */
10577 if (debug_info_level <= DINFO_LEVEL_TERSE)
10578 break;
10580 /* In the special case of a TYPE_DECL node representing the
10581 declaration of some type tag, if the given TYPE_DECL is marked as
10582 having been instantiated from some other (original) TYPE_DECL node
10583 (e.g. one which was generated within the original definition of an
10584 inline function) we have to generate a special (abbreviated)
10585 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
10586 DIE here. */
10587 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
10589 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
10590 break;
10593 if (is_redundant_typedef (decl))
10594 gen_type_die (TREE_TYPE (decl), context_die);
10595 else
10596 /* Output a DIE to represent the typedef itself. */
10597 gen_typedef_die (decl, context_die);
10598 break;
10600 case LABEL_DECL:
10601 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10602 gen_label_die (decl, context_die);
10603 break;
10605 case VAR_DECL:
10606 /* If we are in terse mode, don't generate any DIEs to represent any
10607 variable declarations or definitions. */
10608 if (debug_info_level <= DINFO_LEVEL_TERSE)
10609 break;
10611 /* Output any DIEs that are needed to specify the type of this data
10612 object. */
10613 gen_type_die (TREE_TYPE (decl), context_die);
10615 /* And its containing type. */
10616 origin = decl_class_context (decl);
10617 if (origin != NULL_TREE)
10618 gen_type_die_for_member (origin, decl, context_die);
10620 /* Now output the DIE to represent the data object itself. This gets
10621 complicated because of the possibility that the VAR_DECL really
10622 represents an inlined instance of a formal parameter for an inline
10623 function. */
10624 origin = decl_ultimate_origin (decl);
10625 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
10626 gen_formal_parameter_die (decl, context_die);
10627 else
10628 gen_variable_die (decl, context_die);
10629 break;
10631 case FIELD_DECL:
10632 /* Ignore the nameless fields that are used to skip bits, but
10633 handle C++ anonymous unions. */
10634 if (DECL_NAME (decl) != NULL_TREE
10635 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
10637 gen_type_die (member_declared_type (decl), context_die);
10638 gen_field_die (decl, context_die);
10640 break;
10642 case PARM_DECL:
10643 gen_type_die (TREE_TYPE (decl), context_die);
10644 gen_formal_parameter_die (decl, context_die);
10645 break;
10647 case NAMESPACE_DECL:
10648 /* Ignore for now. */
10649 break;
10651 default:
10652 abort ();
10656 /* Add Ada "use" clause information for SGI Workshop debugger. */
10658 void
10659 dwarf2out_add_library_unit_info (filename, context_list)
10660 const char *filename;
10661 const char *context_list;
10663 unsigned int file_index;
10665 if (filename != NULL)
10667 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
10668 tree context_list_decl
10669 = build_decl (LABEL_DECL, get_identifier (context_list),
10670 void_type_node);
10672 TREE_PUBLIC (context_list_decl) = TRUE;
10673 add_name_attribute (unit_die, context_list);
10674 file_index = lookup_filename (filename);
10675 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
10676 add_pubname (context_list_decl, unit_die);
10680 /* Write the debugging output for DECL. */
10682 void
10683 dwarf2out_decl (decl)
10684 register tree decl;
10686 register dw_die_ref context_die = comp_unit_die;
10688 if (TREE_CODE (decl) == ERROR_MARK)
10689 return;
10691 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10692 if (DECL_IGNORED_P (decl))
10693 return;
10695 switch (TREE_CODE (decl))
10697 case FUNCTION_DECL:
10698 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
10699 builtin function. Explicit programmer-supplied declarations of
10700 these same functions should NOT be ignored however. */
10701 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
10702 return;
10704 /* What we would really like to do here is to filter out all mere
10705 file-scope declarations of file-scope functions which are never
10706 referenced later within this translation unit (and keep all of ones
10707 that *are* referenced later on) but we aren't clairvoyant, so we have
10708 no idea which functions will be referenced in the future (i.e. later
10709 on within the current translation unit). So here we just ignore all
10710 file-scope function declarations which are not also definitions. If
10711 and when the debugger needs to know something about these functions,
10712 it will have to hunt around and find the DWARF information associated
10713 with the definition of the function. Note that we can't just check
10714 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
10715 definitions and which ones represent mere declarations. We have to
10716 check `DECL_INITIAL' instead. That's because the C front-end
10717 supports some weird semantics for "extern inline" function
10718 definitions. These can get inlined within the current translation
10719 unit (an thus, we need to generate DWARF info for their abstract
10720 instances so that the DWARF info for the concrete inlined instances
10721 can have something to refer to) but the compiler never generates any
10722 out-of-lines instances of such things (despite the fact that they
10723 *are* definitions). The important point is that the C front-end
10724 marks these "extern inline" functions as DECL_EXTERNAL, but we need
10725 to generate DWARF for them anyway. Note that the C++ front-end also
10726 plays some similar games for inline function definitions appearing
10727 within include files which also contain
10728 `#pragma interface' pragmas. */
10729 if (DECL_INITIAL (decl) == NULL_TREE)
10730 return;
10732 /* If we're a nested function, initially use a parent of NULL; if we're
10733 a plain function, this will be fixed up in decls_for_scope. If
10734 we're a method, it will be ignored, since we already have a DIE. */
10735 if (decl_function_context (decl))
10736 context_die = NULL;
10738 break;
10740 case VAR_DECL:
10741 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
10742 declaration and if the declaration was never even referenced from
10743 within this entire compilation unit. We suppress these DIEs in
10744 order to save space in the .debug section (by eliminating entries
10745 which are probably useless). Note that we must not suppress
10746 block-local extern declarations (whether used or not) because that
10747 would screw-up the debugger's name lookup mechanism and cause it to
10748 miss things which really ought to be in scope at a given point. */
10749 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
10750 return;
10752 /* If we are in terse mode, don't generate any DIEs to represent any
10753 variable declarations or definitions. */
10754 if (debug_info_level <= DINFO_LEVEL_TERSE)
10755 return;
10756 break;
10758 case TYPE_DECL:
10759 /* Don't emit stubs for types unless they are needed by other DIEs. */
10760 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
10761 return;
10763 /* Don't bother trying to generate any DIEs to represent any of the
10764 normal built-in types for the language we are compiling. */
10765 if (DECL_SOURCE_LINE (decl) == 0)
10767 /* OK, we need to generate one for `bool' so GDB knows what type
10768 comparisons have. */
10769 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
10770 == DW_LANG_C_plus_plus)
10771 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
10772 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
10774 return;
10777 /* If we are in terse mode, don't generate any DIEs for types. */
10778 if (debug_info_level <= DINFO_LEVEL_TERSE)
10779 return;
10781 /* If we're a function-scope tag, initially use a parent of NULL;
10782 this will be fixed up in decls_for_scope. */
10783 if (decl_function_context (decl))
10784 context_die = NULL;
10786 break;
10788 default:
10789 return;
10792 gen_decl_die (decl, context_die);
10795 /* Output a marker (i.e. a label) for the beginning of the generated code for
10796 a lexical block. */
10798 void
10799 dwarf2out_begin_block (blocknum)
10800 register unsigned blocknum;
10802 function_section (current_function_decl);
10803 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
10806 /* Output a marker (i.e. a label) for the end of the generated code for a
10807 lexical block. */
10809 void
10810 dwarf2out_end_block (blocknum)
10811 register unsigned blocknum;
10813 function_section (current_function_decl);
10814 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
10817 /* Returns nonzero if it is appropriate not to emit any debugging
10818 information for BLOCK, because it doesn't contain any instructions.
10820 Don't allow this for blocks with nested functions or local classes
10821 as we would end up with orphans, and in the presence of scheduling
10822 we may end up calling them anyway. */
10825 dwarf2out_ignore_block (block)
10826 tree block;
10828 tree decl;
10829 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
10830 if (TREE_CODE (decl) == FUNCTION_DECL
10831 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
10832 return 0;
10833 return 1;
10836 /* Lookup a filename (in the list of filenames that we know about here in
10837 dwarf2out.c) and return its "index". The index of each (known) filename is
10838 just a unique number which is associated with only that one filename.
10839 We need such numbers for the sake of generating labels
10840 (in the .debug_sfnames section) and references to those
10841 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
10842 If the filename given as an argument is not found in our current list,
10843 add it to the list and assign it the next available unique index number.
10844 In order to speed up searches, we remember the index of the filename
10845 was looked up last. This handles the majority of all searches. */
10847 static unsigned
10848 lookup_filename (file_name)
10849 const char *file_name;
10851 register unsigned i;
10853 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
10854 if (strcmp (file_name, "<internal>") == 0
10855 || strcmp (file_name, "<built-in>") == 0)
10856 return 0;
10858 /* Check to see if the file name that was searched on the previous
10859 call matches this file name. If so, return the index. */
10860 if (file_table.last_lookup_index != 0)
10861 if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0)
10862 return file_table.last_lookup_index;
10864 /* Didn't match the previous lookup, search the table */
10865 for (i = 1; i < file_table.in_use; ++i)
10866 if (strcmp (file_name, file_table.table[i]) == 0)
10868 file_table.last_lookup_index = i;
10869 return i;
10872 /* Prepare to add a new table entry by making sure there is enough space in
10873 the table to do so. If not, expand the current table. */
10874 if (i == file_table.allocated)
10876 file_table.allocated = i + FILE_TABLE_INCREMENT;
10877 file_table.table = (char **)
10878 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
10881 /* Add the new entry to the end of the filename table. */
10882 file_table.table[i] = xstrdup (file_name);
10883 file_table.in_use = i + 1;
10884 file_table.last_lookup_index = i;
10886 if (DWARF2_ASM_LINE_DEBUG_INFO)
10887 fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
10889 return i;
10892 static void
10893 init_file_table ()
10895 /* Allocate the initial hunk of the file_table. */
10896 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
10897 file_table.allocated = FILE_TABLE_INCREMENT;
10899 /* Skip the first entry - file numbers begin at 1. */
10900 file_table.in_use = 1;
10901 file_table.last_lookup_index = 0;
10904 /* Output a label to mark the beginning of a source code line entry
10905 and record information relating to this source line, in
10906 'line_info_table' for later output of the .debug_line section. */
10908 void
10909 dwarf2out_line (filename, line)
10910 register const char *filename;
10911 register unsigned line;
10913 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10915 function_section (current_function_decl);
10917 if (DWARF2_ASM_LINE_DEBUG_INFO)
10919 unsigned file_num = lookup_filename (filename);
10921 /* Emit the .loc directive understood by GNU as. */
10922 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
10924 /* Indicate that line number info exists. */
10925 ++line_info_table_in_use;
10927 /* Indicate that multiple line number tables exist. */
10928 if (DECL_SECTION_NAME (current_function_decl))
10929 ++separate_line_info_table_in_use;
10931 else if (DECL_SECTION_NAME (current_function_decl))
10933 register dw_separate_line_info_ref line_info;
10934 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
10935 separate_line_info_table_in_use);
10936 if (flag_debug_asm)
10937 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
10938 filename, line);
10940 /* expand the line info table if necessary */
10941 if (separate_line_info_table_in_use
10942 == separate_line_info_table_allocated)
10944 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10945 separate_line_info_table
10946 = (dw_separate_line_info_ref)
10947 xrealloc (separate_line_info_table,
10948 separate_line_info_table_allocated
10949 * sizeof (dw_separate_line_info_entry));
10952 /* Add the new entry at the end of the line_info_table. */
10953 line_info
10954 = &separate_line_info_table[separate_line_info_table_in_use++];
10955 line_info->dw_file_num = lookup_filename (filename);
10956 line_info->dw_line_num = line;
10957 line_info->function = current_funcdef_number;
10959 else
10961 register dw_line_info_ref line_info;
10963 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
10964 line_info_table_in_use);
10965 if (flag_debug_asm)
10966 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
10967 filename, line);
10969 /* Expand the line info table if necessary. */
10970 if (line_info_table_in_use == line_info_table_allocated)
10972 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
10973 line_info_table
10974 = (dw_line_info_ref)
10975 xrealloc (line_info_table,
10976 (line_info_table_allocated
10977 * sizeof (dw_line_info_entry)));
10980 /* Add the new entry at the end of the line_info_table. */
10981 line_info = &line_info_table[line_info_table_in_use++];
10982 line_info->dw_file_num = lookup_filename (filename);
10983 line_info->dw_line_num = line;
10988 /* Record the beginning of a new source file, for later output
10989 of the .debug_macinfo section. At present, unimplemented. */
10991 void
10992 dwarf2out_start_source_file (filename)
10993 register const char *filename ATTRIBUTE_UNUSED;
10995 if (flag_eliminate_dwarf2_dups)
10997 /* Record the beginning of the file for break_out_includes. */
10998 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
10999 add_AT_string (bincl_die, DW_AT_name, filename);
11003 /* Record the end of a source file, for later output
11004 of the .debug_macinfo section. At present, unimplemented. */
11006 void
11007 dwarf2out_end_source_file ()
11009 if (flag_eliminate_dwarf2_dups)
11011 /* Record the end of the file for break_out_includes. */
11012 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11016 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11017 the tail part of the directive line, i.e. the part which is past the
11018 initial whitespace, #, whitespace, directive-name, whitespace part. */
11020 void
11021 dwarf2out_define (lineno, buffer)
11022 register unsigned lineno ATTRIBUTE_UNUSED;
11023 register const char *buffer ATTRIBUTE_UNUSED;
11025 static int initialized = 0;
11026 if (!initialized)
11028 dwarf2out_start_source_file (primary_filename);
11029 initialized = 1;
11033 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
11034 the tail part of the directive line, i.e. the part which is past the
11035 initial whitespace, #, whitespace, directive-name, whitespace part. */
11037 void
11038 dwarf2out_undef (lineno, buffer)
11039 register unsigned lineno ATTRIBUTE_UNUSED;
11040 register const char *buffer ATTRIBUTE_UNUSED;
11044 /* Set up for Dwarf output at the start of compilation. */
11046 void
11047 dwarf2out_init (asm_out_file, main_input_filename)
11048 register FILE *asm_out_file;
11049 register const char *main_input_filename;
11051 init_file_table ();
11053 /* Remember the name of the primary input file. */
11054 primary_filename = main_input_filename;
11056 /* Add it to the file table first, under the assumption that we'll
11057 be emitting line number data for it first, which avoids having
11058 to add an initial DW_LNS_set_file. */
11059 lookup_filename (main_input_filename);
11061 /* Allocate the initial hunk of the decl_die_table. */
11062 decl_die_table
11063 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11064 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11065 decl_die_table_in_use = 0;
11067 /* Allocate the initial hunk of the decl_scope_table. */
11068 decl_scope_table
11069 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11070 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11071 decl_scope_depth = 0;
11073 /* Allocate the initial hunk of the abbrev_die_table. */
11074 abbrev_die_table
11075 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11076 sizeof (dw_die_ref));
11077 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11078 /* Zero-th entry is allocated, but unused */
11079 abbrev_die_table_in_use = 1;
11081 /* Allocate the initial hunk of the line_info_table. */
11082 line_info_table
11083 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11084 sizeof (dw_line_info_entry));
11085 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11086 /* Zero-th entry is allocated, but unused */
11087 line_info_table_in_use = 1;
11089 /* Generate the initial DIE for the .debug section. Note that the (string)
11090 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11091 will (typically) be a relative pathname and that this pathname should be
11092 taken as being relative to the directory from which the compiler was
11093 invoked when the given (base) source file was compiled. */
11094 comp_unit_die = gen_compile_unit_die (main_input_filename);
11096 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11097 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11099 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11100 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
11101 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11102 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11103 else
11104 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11105 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11106 DEBUG_INFO_SECTION_LABEL, 0);
11107 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11108 DEBUG_LINE_SECTION_LABEL, 0);
11110 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11111 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11112 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11114 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11115 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11117 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
11118 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11119 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11120 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11123 /* Output stuff that dwarf requires at the end of every file,
11124 and generate the DWARF-2 debugging info. */
11126 void
11127 dwarf2out_finish ()
11129 limbo_die_node *node, *next_node;
11130 dw_die_ref die;
11132 /* Traverse the limbo die list, and add parent/child links. The only
11133 dies without parents that should be here are concrete instances of
11134 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11135 For concrete instances, we can get the parent die from the abstract
11136 instance. */
11137 for (node = limbo_die_list; node; node = next_node)
11139 next_node = node->next;
11140 die = node->die;
11142 if (die->die_parent == NULL)
11144 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11145 if (origin)
11146 add_child_die (origin->die_parent, die);
11147 else if (die == comp_unit_die)
11149 else
11150 abort ();
11152 free (node);
11154 limbo_die_list = NULL;
11156 /* Walk through the list of incomplete types again, trying once more to
11157 emit full debugging info for them. */
11158 retry_incomplete_types ();
11160 /* We need to reverse all the dies before break_out_includes, or
11161 we'll see the end of an include file before the beginning. */
11162 reverse_all_dies (comp_unit_die);
11164 /* Generate separate CUs for each of the include files we've seen.
11165 They will go into limbo_die_list. */
11166 if (flag_eliminate_dwarf2_dups)
11167 break_out_includes (comp_unit_die);
11169 /* Traverse the DIE's and add add sibling attributes to those DIE's
11170 that have children. */
11171 add_sibling_attributes (comp_unit_die);
11172 for (node = limbo_die_list; node; node = node->next)
11173 add_sibling_attributes (node->die);
11175 /* Output a terminator label for the .text section. */
11176 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11177 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11179 #if 0
11180 /* Output a terminator label for the .data section. */
11181 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11182 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11184 /* Output a terminator label for the .bss section. */
11185 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11186 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11187 #endif
11189 /* Output the source line correspondence table. */
11190 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
11192 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11194 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11195 output_line_info ();
11198 /* We can only use the low/high_pc attributes if all of the code
11199 was in .text. */
11200 if (separate_line_info_table_in_use == 0)
11202 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11203 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11206 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11207 debug_line_section_label);
11210 #if 0 /* unimplemented */
11211 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
11212 add_AT_unsigned (die, DW_AT_macro_info, 0);
11213 #endif
11215 /* Output all of the compilation units. We put the main one last so that
11216 the offsets are available to output_pubnames. */
11217 for (node = limbo_die_list; node; node = node->next)
11218 output_comp_unit (node->die);
11219 output_comp_unit (comp_unit_die);
11221 /* Output the abbreviation table. */
11222 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
11223 output_abbrev_section ();
11225 if (pubname_table_in_use)
11227 /* Output public names table. */
11228 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
11229 output_pubnames ();
11232 /* We only put functions in the arange table, so don't write it out if
11233 we don't have any. */
11234 if (fde_table_in_use)
11236 /* Output the address range information. */
11237 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
11238 output_aranges ();
11241 #endif /* DWARF2_DEBUGGING_INFO */