* config/alpha/alpha.md (unaligned_extendhidi_be): Fix.
[official-gcc.git] / gcc / dwarf2out.c
blobca8a736bc54af4961c7873f131b43a1fe433e209
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 GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
13 version.
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 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 "libfuncs.h"
51 #include "except.h"
52 #include "dwarf2.h"
53 #include "dwarf2out.h"
54 #include "dwarf2asm.h"
55 #include "toplev.h"
56 #include "varray.h"
57 #include "ggc.h"
58 #include "md5.h"
59 #include "tm_p.h"
60 #include "diagnostic.h"
61 #include "debug.h"
63 #ifdef DWARF2_DEBUGGING_INFO
64 static void dwarf2out_source_line PARAMS ((unsigned int, const char *));
65 #endif
67 /* DWARF2 Abbreviation Glossary:
68 CFA = Canonical Frame Address
69 a fixed address on the stack which identifies a call frame.
70 We define it to be the value of SP just before the call insn.
71 The CFA register and offset, which may change during the course
72 of the function, are used to calculate its value at runtime.
73 CFI = Call Frame Instruction
74 an instruction for the DWARF2 abstract machine
75 CIE = Common Information Entry
76 information describing information common to one or more FDEs
77 DIE = Debugging Information Entry
78 FDE = Frame Description Entry
79 information describing the stack call frame, in particular,
80 how to restore registers
82 DW_CFA_... = DWARF2 CFA call frame instruction
83 DW_TAG_... = DWARF2 DIE tag */
85 /* Decide whether we want to emit frame unwind information for the current
86 translation unit. */
88 int
89 dwarf2out_do_frame ()
91 return (write_symbols == DWARF2_DEBUG
92 #ifdef DWARF2_FRAME_INFO
93 || DWARF2_FRAME_INFO
94 #endif
95 #ifdef DWARF2_UNWIND_INFO
96 || flag_unwind_tables
97 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
98 #endif
102 /* The number of the current function definition for which debugging
103 information is being generated. These numbers range from 1 up to the
104 maximum number of function definitions contained within the current
105 compilation unit. These numbers are used to create unique label id's
106 unique to each function definition. */
107 unsigned current_funcdef_number = 0;
109 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
111 /* How to start an assembler comment. */
112 #ifndef ASM_COMMENT_START
113 #define ASM_COMMENT_START ";#"
114 #endif
116 typedef struct dw_cfi_struct *dw_cfi_ref;
117 typedef struct dw_fde_struct *dw_fde_ref;
118 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
120 /* Call frames are described using a sequence of Call Frame
121 Information instructions. The register number, offset
122 and address fields are provided as possible operands;
123 their use is selected by the opcode field. */
125 typedef union dw_cfi_oprnd_struct
127 unsigned long dw_cfi_reg_num;
128 long int dw_cfi_offset;
129 const char *dw_cfi_addr;
130 struct dw_loc_descr_struct *dw_cfi_loc;
132 dw_cfi_oprnd;
134 typedef struct dw_cfi_struct
136 dw_cfi_ref dw_cfi_next;
137 enum dwarf_call_frame_info dw_cfi_opc;
138 dw_cfi_oprnd dw_cfi_oprnd1;
139 dw_cfi_oprnd dw_cfi_oprnd2;
141 dw_cfi_node;
143 /* This is how we define the location of the CFA. We use to handle it
144 as REG + OFFSET all the time, but now it can be more complex.
145 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
146 Instead of passing around REG and OFFSET, we pass a copy
147 of this structure. */
148 typedef struct cfa_loc
150 unsigned long reg;
151 long offset;
152 long base_offset;
153 int indirect; /* 1 if CFA is accessed via a dereference. */
154 } dw_cfa_location;
156 /* All call frame descriptions (FDE's) in the GCC generated DWARF
157 refer to a single Common Information Entry (CIE), defined at
158 the beginning of the .debug_frame section. This use of a single
159 CIE obviates the need to keep track of multiple CIE's
160 in the DWARF generation routines below. */
162 typedef struct dw_fde_struct
164 const char *dw_fde_begin;
165 const char *dw_fde_current_label;
166 const char *dw_fde_end;
167 dw_cfi_ref dw_fde_cfi;
168 unsigned funcdef_number;
169 unsigned nothrow : 1;
170 unsigned uses_eh_lsda : 1;
172 dw_fde_node;
174 /* Maximum size (in bytes) of an artificially generated label. */
175 #define MAX_ARTIFICIAL_LABEL_BYTES 30
177 /* The size of the target's pointer type. */
178 #ifndef PTR_SIZE
179 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
180 #endif
182 /* The size of addresses as they appear in the Dwarf 2 data.
183 Some architectures use word addresses to refer to code locations,
184 but Dwarf 2 info always uses byte addresses. On such machines,
185 Dwarf 2 addresses need to be larger than the architecture's
186 pointers. */
187 #ifndef DWARF2_ADDR_SIZE
188 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
189 #endif
191 /* The size in bytes of a DWARF field indicating an offset or length
192 relative to a debug info section, specified to be 4 bytes in the
193 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
194 as PTR_SIZE. */
196 #ifndef DWARF_OFFSET_SIZE
197 #define DWARF_OFFSET_SIZE 4
198 #endif
200 #define DWARF_VERSION 2
202 /* Round SIZE up to the nearest BOUNDARY. */
203 #define DWARF_ROUND(SIZE,BOUNDARY) \
204 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
206 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
207 #ifndef DWARF_CIE_DATA_ALIGNMENT
208 #ifdef STACK_GROWS_DOWNWARD
209 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
210 #else
211 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
212 #endif
213 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
215 /* A pointer to the base of a table that contains frame description
216 information for each routine. */
217 static dw_fde_ref fde_table;
219 /* Number of elements currently allocated for fde_table. */
220 static unsigned fde_table_allocated;
222 /* Number of elements in fde_table currently in use. */
223 static unsigned fde_table_in_use;
225 /* Size (in elements) of increments by which we may expand the
226 fde_table. */
227 #define FDE_TABLE_INCREMENT 256
229 /* A list of call frame insns for the CIE. */
230 static dw_cfi_ref cie_cfi_head;
232 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
233 attribute that accelerates the lookup of the FDE associated
234 with the subprogram. This variable holds the table index of the FDE
235 associated with the current function (body) definition. */
236 static unsigned current_funcdef_fde;
238 /* Forward declarations for functions defined in this file. */
240 static char *stripattributes PARAMS ((const char *));
241 static const char *dwarf_cfi_name PARAMS ((unsigned));
242 static dw_cfi_ref new_cfi PARAMS ((void));
243 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
244 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
245 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
246 static void lookup_cfa PARAMS ((dw_cfa_location *));
247 static void reg_save PARAMS ((const char *, unsigned,
248 unsigned, long));
249 static void initial_return_save PARAMS ((rtx));
250 static long stack_adjust_offset PARAMS ((rtx));
251 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
252 static void output_call_frame_info PARAMS ((int));
253 static void dwarf2out_stack_adjust PARAMS ((rtx));
254 static void queue_reg_save PARAMS ((const char *, rtx, long));
255 static void flush_queued_reg_saves PARAMS ((void));
256 static bool clobbers_queued_reg_save PARAMS ((rtx));
257 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
259 /* Support for complex CFA locations. */
260 static void output_cfa_loc PARAMS ((dw_cfi_ref));
261 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
262 struct dw_loc_descr_struct *));
263 static struct dw_loc_descr_struct *build_cfa_loc
264 PARAMS ((dw_cfa_location *));
265 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
267 /* How to start an assembler comment. */
268 #ifndef ASM_COMMENT_START
269 #define ASM_COMMENT_START ";#"
270 #endif
272 /* Data and reference forms for relocatable data. */
273 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
274 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
276 /* Pseudo-op for defining a new section. */
277 #ifndef SECTION_ASM_OP
278 #define SECTION_ASM_OP "\t.section\t"
279 #endif
281 #ifndef DEBUG_FRAME_SECTION
282 #define DEBUG_FRAME_SECTION ".debug_frame"
283 #endif
285 #ifndef FUNC_BEGIN_LABEL
286 #define FUNC_BEGIN_LABEL "LFB"
287 #endif
288 #ifndef FUNC_END_LABEL
289 #define FUNC_END_LABEL "LFE"
290 #endif
291 #define CIE_AFTER_SIZE_LABEL "LSCIE"
292 #define CIE_END_LABEL "LECIE"
293 #define CIE_LENGTH_LABEL "LLCIE"
294 #define FDE_LABEL "LSFDE"
295 #define FDE_AFTER_SIZE_LABEL "LASFDE"
296 #define FDE_END_LABEL "LEFDE"
297 #define FDE_LENGTH_LABEL "LLFDE"
298 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
299 #define LINE_NUMBER_END_LABEL "LELT"
300 #define LN_PROLOG_AS_LABEL "LASLTP"
301 #define LN_PROLOG_END_LABEL "LELTP"
302 #define DIE_LABEL_PREFIX "DW"
304 /* Definitions of defaults for various types of primitive assembly language
305 output operations. These may be overridden from within the tm.h file,
306 but typically, that is unnecessary. */
308 #ifdef SET_ASM_OP
309 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
310 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
311 do { \
312 fprintf (FILE, "%s", SET_ASM_OP); \
313 assemble_name (FILE, SY); \
314 fputc (',', FILE); \
315 assemble_name (FILE, HI); \
316 fputc ('-', FILE); \
317 assemble_name (FILE, LO); \
318 } while (0)
319 #endif
320 #endif /* SET_ASM_OP */
322 /* The DWARF 2 CFA column which tracks the return address. Normally this
323 is the column for PC, or the first column after all of the hard
324 registers. */
325 #ifndef DWARF_FRAME_RETURN_COLUMN
326 #ifdef PC_REGNUM
327 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
328 #else
329 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
330 #endif
331 #endif
333 /* The mapping from gcc register number to DWARF 2 CFA column number. By
334 default, we just provide columns for all registers. */
335 #ifndef DWARF_FRAME_REGNUM
336 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
337 #endif
339 /* Hook used by __throw. */
342 expand_builtin_dwarf_fp_regnum ()
344 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
347 /* The offset from the incoming value of %sp to the top of the stack frame
348 for the current function. */
349 #ifndef INCOMING_FRAME_SP_OFFSET
350 #define INCOMING_FRAME_SP_OFFSET 0
351 #endif
353 /* Return a pointer to a copy of the section string name S with all
354 attributes stripped off, and an asterisk prepended (for assemble_name). */
356 static inline char *
357 stripattributes (s)
358 const char *s;
360 char *stripped = xmalloc (strlen (s) + 2);
361 char *p = stripped;
363 *p++ = '*';
365 while (*s && *s != ',')
366 *p++ = *s++;
368 *p = '\0';
369 return stripped;
372 /* Generate code to initialize the register size table. */
374 void
375 expand_builtin_init_dwarf_reg_sizes (address)
376 tree address;
378 int i;
379 enum machine_mode mode = TYPE_MODE (char_type_node);
380 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
381 rtx mem = gen_rtx_MEM (mode, addr);
383 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
385 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
386 int size = GET_MODE_SIZE (reg_raw_mode[i]);
388 if (offset < 0)
389 continue;
391 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
395 /* Convert a DWARF call frame info. operation to its string name */
397 static const char *
398 dwarf_cfi_name (cfi_opc)
399 register unsigned cfi_opc;
401 switch (cfi_opc)
403 case DW_CFA_advance_loc:
404 return "DW_CFA_advance_loc";
405 case DW_CFA_offset:
406 return "DW_CFA_offset";
407 case DW_CFA_restore:
408 return "DW_CFA_restore";
409 case DW_CFA_nop:
410 return "DW_CFA_nop";
411 case DW_CFA_set_loc:
412 return "DW_CFA_set_loc";
413 case DW_CFA_advance_loc1:
414 return "DW_CFA_advance_loc1";
415 case DW_CFA_advance_loc2:
416 return "DW_CFA_advance_loc2";
417 case DW_CFA_advance_loc4:
418 return "DW_CFA_advance_loc4";
419 case DW_CFA_offset_extended:
420 return "DW_CFA_offset_extended";
421 case DW_CFA_restore_extended:
422 return "DW_CFA_restore_extended";
423 case DW_CFA_undefined:
424 return "DW_CFA_undefined";
425 case DW_CFA_same_value:
426 return "DW_CFA_same_value";
427 case DW_CFA_register:
428 return "DW_CFA_register";
429 case DW_CFA_remember_state:
430 return "DW_CFA_remember_state";
431 case DW_CFA_restore_state:
432 return "DW_CFA_restore_state";
433 case DW_CFA_def_cfa:
434 return "DW_CFA_def_cfa";
435 case DW_CFA_def_cfa_register:
436 return "DW_CFA_def_cfa_register";
437 case DW_CFA_def_cfa_offset:
438 return "DW_CFA_def_cfa_offset";
439 case DW_CFA_def_cfa_expression:
440 return "DW_CFA_def_cfa_expression";
442 /* SGI/MIPS specific */
443 case DW_CFA_MIPS_advance_loc8:
444 return "DW_CFA_MIPS_advance_loc8";
446 /* GNU extensions */
447 case DW_CFA_GNU_window_save:
448 return "DW_CFA_GNU_window_save";
449 case DW_CFA_GNU_args_size:
450 return "DW_CFA_GNU_args_size";
451 case DW_CFA_GNU_negative_offset_extended:
452 return "DW_CFA_GNU_negative_offset_extended";
454 default:
455 return "DW_CFA_<unknown>";
459 /* Return a pointer to a newly allocated Call Frame Instruction. */
461 static inline dw_cfi_ref
462 new_cfi ()
464 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
466 cfi->dw_cfi_next = NULL;
467 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
468 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
470 return cfi;
473 /* Add a Call Frame Instruction to list of instructions. */
475 static inline void
476 add_cfi (list_head, cfi)
477 register dw_cfi_ref *list_head;
478 register dw_cfi_ref cfi;
480 register dw_cfi_ref *p;
482 /* Find the end of the chain. */
483 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
486 *p = cfi;
489 /* Generate a new label for the CFI info to refer to. */
491 char *
492 dwarf2out_cfi_label ()
494 static char label[20];
495 static unsigned long label_num = 0;
497 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
498 ASM_OUTPUT_LABEL (asm_out_file, label);
500 return label;
503 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
504 or to the CIE if LABEL is NULL. */
506 static void
507 add_fde_cfi (label, cfi)
508 register const char *label;
509 register dw_cfi_ref cfi;
511 if (label)
513 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
515 if (*label == 0)
516 label = dwarf2out_cfi_label ();
518 if (fde->dw_fde_current_label == NULL
519 || strcmp (label, fde->dw_fde_current_label) != 0)
521 register dw_cfi_ref xcfi;
523 fde->dw_fde_current_label = label = xstrdup (label);
525 /* Set the location counter to the new label. */
526 xcfi = new_cfi ();
527 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
528 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
529 add_cfi (&fde->dw_fde_cfi, xcfi);
532 add_cfi (&fde->dw_fde_cfi, cfi);
535 else
536 add_cfi (&cie_cfi_head, cfi);
539 /* Subroutine of lookup_cfa. */
541 static inline void
542 lookup_cfa_1 (cfi, loc)
543 register dw_cfi_ref cfi;
544 register dw_cfa_location *loc;
546 switch (cfi->dw_cfi_opc)
548 case DW_CFA_def_cfa_offset:
549 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
550 break;
551 case DW_CFA_def_cfa_register:
552 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
553 break;
554 case DW_CFA_def_cfa:
555 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
556 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
557 break;
558 case DW_CFA_def_cfa_expression:
559 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
560 break;
561 default:
562 break;
566 /* Find the previous value for the CFA. */
568 static void
569 lookup_cfa (loc)
570 register dw_cfa_location *loc;
572 register dw_cfi_ref cfi;
574 loc->reg = (unsigned long) -1;
575 loc->offset = 0;
576 loc->indirect = 0;
577 loc->base_offset = 0;
579 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
580 lookup_cfa_1 (cfi, loc);
582 if (fde_table_in_use)
584 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
585 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
586 lookup_cfa_1 (cfi, loc);
590 /* The current rule for calculating the DWARF2 canonical frame address. */
591 static dw_cfa_location cfa;
593 /* The register used for saving registers to the stack, and its offset
594 from the CFA. */
595 static dw_cfa_location cfa_store;
597 /* The running total of the size of arguments pushed onto the stack. */
598 static long args_size;
600 /* The last args_size we actually output. */
601 static long old_args_size;
603 /* Entry point to update the canonical frame address (CFA).
604 LABEL is passed to add_fde_cfi. The value of CFA is now to be
605 calculated from REG+OFFSET. */
607 void
608 dwarf2out_def_cfa (label, reg, offset)
609 register const char *label;
610 unsigned reg;
611 long offset;
613 dw_cfa_location loc;
614 loc.indirect = 0;
615 loc.base_offset = 0;
616 loc.reg = reg;
617 loc.offset = offset;
618 def_cfa_1 (label, &loc);
621 /* This routine does the actual work. The CFA is now calculated from
622 the dw_cfa_location structure. */
623 static void
624 def_cfa_1 (label, loc_p)
625 register const char *label;
626 dw_cfa_location *loc_p;
628 register dw_cfi_ref cfi;
629 dw_cfa_location old_cfa, loc;
631 cfa = *loc_p;
632 loc = *loc_p;
634 if (cfa_store.reg == loc.reg && loc.indirect == 0)
635 cfa_store.offset = loc.offset;
637 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
638 lookup_cfa (&old_cfa);
640 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
641 loc.indirect == old_cfa.indirect)
643 if (loc.indirect == 0
644 || loc.base_offset == old_cfa.base_offset)
645 /* Nothing changed so no need to issue any call frame
646 instructions. */
647 return;
650 cfi = new_cfi ();
652 if (loc.reg == old_cfa.reg && !loc.indirect)
654 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
655 indicating the CFA register did not change but the offset
656 did. */
657 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
658 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
661 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
662 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
663 && !loc.indirect)
665 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
666 indicating the CFA register has changed to <register> but the
667 offset has not changed. */
668 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
669 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
671 #endif
673 else if (loc.indirect == 0)
675 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
676 indicating the CFA register has changed to <register> with
677 the specified offset. */
678 cfi->dw_cfi_opc = DW_CFA_def_cfa;
679 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
680 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
682 else
684 /* Construct a DW_CFA_def_cfa_expression instruction to
685 calculate the CFA using a full location expression since no
686 register-offset pair is available. */
687 struct dw_loc_descr_struct *loc_list;
688 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
689 loc_list = build_cfa_loc (&loc);
690 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
693 add_fde_cfi (label, cfi);
696 /* Add the CFI for saving a register. REG is the CFA column number.
697 LABEL is passed to add_fde_cfi.
698 If SREG is -1, the register is saved at OFFSET from the CFA;
699 otherwise it is saved in SREG. */
701 static void
702 reg_save (label, reg, sreg, offset)
703 register const char *label;
704 register unsigned reg;
705 register unsigned sreg;
706 register long offset;
708 register dw_cfi_ref cfi = new_cfi ();
710 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
712 /* The following comparison is correct. -1 is used to indicate that
713 the value isn't a register number. */
714 if (sreg == (unsigned int) -1)
716 if (reg & ~0x3f)
717 /* The register number won't fit in 6 bits, so we have to use
718 the long form. */
719 cfi->dw_cfi_opc = DW_CFA_offset_extended;
720 else
721 cfi->dw_cfi_opc = DW_CFA_offset;
723 #ifdef ENABLE_CHECKING
725 /* If we get an offset that is not a multiple of
726 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
727 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
728 description. */
729 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
731 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
732 abort ();
734 #endif
735 offset /= DWARF_CIE_DATA_ALIGNMENT;
736 if (offset < 0)
738 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
739 offset = -offset;
741 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
743 else if (sreg == reg)
744 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
745 return;
746 else
748 cfi->dw_cfi_opc = DW_CFA_register;
749 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
752 add_fde_cfi (label, cfi);
755 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
756 This CFI tells the unwinder that it needs to restore the window registers
757 from the previous frame's window save area.
759 ??? Perhaps we should note in the CIE where windows are saved (instead of
760 assuming 0(cfa)) and what registers are in the window. */
762 void
763 dwarf2out_window_save (label)
764 register const char *label;
766 register dw_cfi_ref cfi = new_cfi ();
767 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
768 add_fde_cfi (label, cfi);
771 /* Add a CFI to update the running total of the size of arguments
772 pushed onto the stack. */
774 void
775 dwarf2out_args_size (label, size)
776 const char *label;
777 long size;
779 register dw_cfi_ref cfi;
781 if (size == old_args_size)
782 return;
783 old_args_size = size;
785 cfi = new_cfi ();
786 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
787 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
788 add_fde_cfi (label, cfi);
791 /* Entry point for saving a register to the stack. REG is the GCC register
792 number. LABEL and OFFSET are passed to reg_save. */
794 void
795 dwarf2out_reg_save (label, reg, offset)
796 register const char *label;
797 register unsigned reg;
798 register long offset;
800 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
803 /* Entry point for saving the return address in the stack.
804 LABEL and OFFSET are passed to reg_save. */
806 void
807 dwarf2out_return_save (label, offset)
808 register const char *label;
809 register long offset;
811 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
814 /* Entry point for saving the return address in a register.
815 LABEL and SREG are passed to reg_save. */
817 void
818 dwarf2out_return_reg (label, sreg)
819 register const char *label;
820 register unsigned sreg;
822 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
825 /* Record the initial position of the return address. RTL is
826 INCOMING_RETURN_ADDR_RTX. */
828 static void
829 initial_return_save (rtl)
830 register rtx rtl;
832 unsigned int reg = (unsigned int) -1;
833 long offset = 0;
835 switch (GET_CODE (rtl))
837 case REG:
838 /* RA is in a register. */
839 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
840 break;
841 case MEM:
842 /* RA is on the stack. */
843 rtl = XEXP (rtl, 0);
844 switch (GET_CODE (rtl))
846 case REG:
847 if (REGNO (rtl) != STACK_POINTER_REGNUM)
848 abort ();
849 offset = 0;
850 break;
851 case PLUS:
852 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
853 abort ();
854 offset = INTVAL (XEXP (rtl, 1));
855 break;
856 case MINUS:
857 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
858 abort ();
859 offset = -INTVAL (XEXP (rtl, 1));
860 break;
861 default:
862 abort ();
864 break;
865 case PLUS:
866 /* The return address is at some offset from any value we can
867 actually load. For instance, on the SPARC it is in %i7+8. Just
868 ignore the offset for now; it doesn't matter for unwinding frames. */
869 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
870 abort ();
871 initial_return_save (XEXP (rtl, 0));
872 return;
873 default:
874 abort ();
877 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
880 /* Given a SET, calculate the amount of stack adjustment it
881 contains. */
883 static long
884 stack_adjust_offset (pattern)
885 rtx pattern;
887 rtx src = SET_SRC (pattern);
888 rtx dest = SET_DEST (pattern);
889 long offset = 0;
890 enum rtx_code code;
892 if (dest == stack_pointer_rtx)
894 /* (set (reg sp) (plus (reg sp) (const_int))) */
895 code = GET_CODE (src);
896 if (! (code == PLUS || code == MINUS)
897 || XEXP (src, 0) != stack_pointer_rtx
898 || GET_CODE (XEXP (src, 1)) != CONST_INT)
899 return 0;
901 offset = INTVAL (XEXP (src, 1));
903 else if (GET_CODE (dest) == MEM)
905 /* (set (mem (pre_dec (reg sp))) (foo)) */
906 src = XEXP (dest, 0);
907 code = GET_CODE (src);
909 if (! (code == PRE_DEC || code == PRE_INC
910 || code == PRE_MODIFY)
911 || XEXP (src, 0) != stack_pointer_rtx)
912 return 0;
914 if (code == PRE_MODIFY)
916 rtx val = XEXP (XEXP (src, 1), 1);
917 /* We handle only adjustments by constant amount. */
918 if (GET_CODE (XEXP (src, 1)) != PLUS ||
919 GET_CODE (val) != CONST_INT)
920 abort();
921 offset = -INTVAL (val);
923 else offset = GET_MODE_SIZE (GET_MODE (dest));
925 else
926 return 0;
928 if (code == PLUS || code == PRE_INC)
929 offset = -offset;
931 return offset;
934 /* Check INSN to see if it looks like a push or a stack adjustment, and
935 make a note of it if it does. EH uses this information to find out how
936 much extra space it needs to pop off the stack. */
938 static void
939 dwarf2out_stack_adjust (insn)
940 rtx insn;
942 long offset;
943 const char *label;
945 if (! flag_non_call_exceptions && GET_CODE (insn) == CALL_INSN)
947 /* Extract the size of the args from the CALL rtx itself. */
949 insn = PATTERN (insn);
950 if (GET_CODE (insn) == PARALLEL)
951 insn = XVECEXP (insn, 0, 0);
952 if (GET_CODE (insn) == SET)
953 insn = SET_SRC (insn);
954 if (GET_CODE (insn) != CALL)
955 abort ();
956 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
957 return;
960 /* If only calls can throw, and we have a frame pointer,
961 save up adjustments until we see the CALL_INSN. */
962 else if (! flag_non_call_exceptions
963 && cfa.reg != STACK_POINTER_REGNUM)
964 return;
966 if (GET_CODE (insn) == BARRIER)
968 /* When we see a BARRIER, we know to reset args_size to 0. Usually
969 the compiler will have already emitted a stack adjustment, but
970 doesn't bother for calls to noreturn functions. */
971 #ifdef STACK_GROWS_DOWNWARD
972 offset = -args_size;
973 #else
974 offset = args_size;
975 #endif
977 else if (GET_CODE (PATTERN (insn)) == SET)
979 offset = stack_adjust_offset (PATTERN (insn));
981 else if (GET_CODE (PATTERN (insn)) == PARALLEL
982 || GET_CODE (PATTERN (insn)) == SEQUENCE)
984 /* There may be stack adjustments inside compound insns. Search
985 for them. */
986 int j;
988 offset = 0;
989 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
991 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
992 if (GET_CODE (pattern) == SET)
993 offset += stack_adjust_offset (pattern);
996 else
997 return;
999 if (offset == 0)
1000 return;
1002 if (cfa.reg == STACK_POINTER_REGNUM)
1003 cfa.offset += offset;
1005 #ifndef STACK_GROWS_DOWNWARD
1006 offset = -offset;
1007 #endif
1008 args_size += offset;
1009 if (args_size < 0)
1010 args_size = 0;
1012 label = dwarf2out_cfi_label ();
1013 def_cfa_1 (label, &cfa);
1014 dwarf2out_args_size (label, args_size);
1017 /* We delay emitting a register save until either (a) we reach the end
1018 of the prologue or (b) the register is clobbered. This clusters
1019 register saves so that there are fewer pc advances. */
1021 struct queued_reg_save
1023 struct queued_reg_save *next;
1024 rtx reg;
1025 long cfa_offset;
1028 static struct queued_reg_save *queued_reg_saves;
1029 static const char *last_reg_save_label;
1031 static void
1032 queue_reg_save (label, reg, offset)
1033 const char *label;
1034 rtx reg;
1035 long offset;
1037 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1039 q->next = queued_reg_saves;
1040 q->reg = reg;
1041 q->cfa_offset = offset;
1042 queued_reg_saves = q;
1044 last_reg_save_label = label;
1047 static void
1048 flush_queued_reg_saves ()
1050 struct queued_reg_save *q, *next;
1052 for (q = queued_reg_saves; q ; q = next)
1054 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1055 next = q->next;
1056 free (q);
1059 queued_reg_saves = NULL;
1060 last_reg_save_label = NULL;
1063 static bool
1064 clobbers_queued_reg_save (insn)
1065 rtx insn;
1067 struct queued_reg_save *q;
1069 for (q = queued_reg_saves; q ; q = q->next)
1070 if (modified_in_p (q->reg, insn))
1071 return true;
1073 return false;
1077 /* A temporary register holding an integral value used in adjusting SP
1078 or setting up the store_reg. The "offset" field holds the integer
1079 value, not an offset. */
1080 static dw_cfa_location cfa_temp;
1082 /* Record call frame debugging information for an expression EXPR,
1083 which either sets SP or FP (adjusting how we calculate the frame
1084 address) or saves a register to the stack. LABEL indicates the
1085 address of EXPR.
1087 This function encodes a state machine mapping rtxes to actions on
1088 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1089 users need not read the source code.
1091 The High-Level Picture
1093 Changes in the register we use to calculate the CFA: Currently we
1094 assume that if you copy the CFA register into another register, we
1095 should take the other one as the new CFA register; this seems to
1096 work pretty well. If it's wrong for some target, it's simple
1097 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1099 Changes in the register we use for saving registers to the stack:
1100 This is usually SP, but not always. Again, we deduce that if you
1101 copy SP into another register (and SP is not the CFA register),
1102 then the new register is the one we will be using for register
1103 saves. This also seems to work.
1105 Register saves: There's not much guesswork about this one; if
1106 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1107 register save, and the register used to calculate the destination
1108 had better be the one we think we're using for this purpose.
1110 Except: If the register being saved is the CFA register, and the
1111 offset is non-zero, we are saving the CFA, so we assume we have to
1112 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1113 the intent is to save the value of SP from the previous frame.
1115 Invariants / Summaries of Rules
1117 cfa current rule for calculating the CFA. It usually
1118 consists of a register and an offset.
1119 cfa_store register used by prologue code to save things to the stack
1120 cfa_store.offset is the offset from the value of
1121 cfa_store.reg to the actual CFA
1122 cfa_temp register holding an integral value. cfa_temp.offset
1123 stores the value, which will be used to adjust the
1124 stack pointer. cfa_temp is also used like cfa_store,
1125 to track stores to the stack via fp or a temp reg.
1127 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1128 with cfa.reg as the first operand changes the cfa.reg and its
1129 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1130 cfa_temp.offset.
1132 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1133 expression yielding a constant. This sets cfa_temp.reg
1134 and cfa_temp.offset.
1136 Rule 5: Create a new register cfa_store used to save items to the
1137 stack.
1139 Rules 10-14: Save a register to the stack. Define offset as the
1140 difference of the original location and cfa_store's
1141 location (or cfa_temp's location if cfa_temp is used).
1143 The Rules
1145 "{a,b}" indicates a choice of a xor b.
1146 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1148 Rule 1:
1149 (set <reg1> <reg2>:cfa.reg)
1150 effects: cfa.reg = <reg1>
1151 cfa.offset unchanged
1152 cfa_temp.reg = <reg1>
1153 cfa_temp.offset = cfa.offset
1155 Rule 2:
1156 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
1157 effects: cfa.reg = sp if fp used
1158 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1159 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1160 if cfa_store.reg==sp
1162 Rule 3:
1163 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1164 effects: cfa.reg = fp
1165 cfa_offset += +/- <const_int>
1167 Rule 4:
1168 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1169 constraints: <reg1> != fp
1170 <reg1> != sp
1171 effects: cfa.reg = <reg1>
1172 cfa_temp.reg = <reg1>
1173 cfa_temp.offset = cfa.offset
1175 Rule 5:
1176 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1177 constraints: <reg1> != fp
1178 <reg1> != sp
1179 effects: cfa_store.reg = <reg1>
1180 cfa_store.offset = cfa.offset - cfa_temp.offset
1182 Rule 6:
1183 (set <reg> <const_int>)
1184 effects: cfa_temp.reg = <reg>
1185 cfa_temp.offset = <const_int>
1187 Rule 7:
1188 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1189 effects: cfa_temp.reg = <reg1>
1190 cfa_temp.offset |= <const_int>
1192 Rule 8:
1193 (set <reg> (high <exp>))
1194 effects: none
1196 Rule 9:
1197 (set <reg> (lo_sum <exp> <const_int>))
1198 effects: cfa_temp.reg = <reg>
1199 cfa_temp.offset = <const_int>
1201 Rule 10:
1202 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1203 effects: cfa_store.offset -= <const_int>
1204 cfa.offset = cfa_store.offset if cfa.reg == sp
1205 cfa.reg = sp
1206 cfa.base_offset = -cfa_store.offset
1208 Rule 11:
1209 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1210 effects: cfa_store.offset += -/+ mode_size(mem)
1211 cfa.offset = cfa_store.offset if cfa.reg == sp
1212 cfa.reg = sp
1213 cfa.base_offset = -cfa_store.offset
1215 Rule 12:
1216 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) <reg2>)
1217 effects: cfa.reg = <reg1>
1218 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1220 Rule 13:
1221 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1222 effects: cfa.reg = <reg1>
1223 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1225 Rule 14:
1226 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1227 effects: cfa.reg = <reg1>
1228 cfa.base_offset = -cfa_temp.offset
1229 cfa_temp.offset -= mode_size(mem) */
1231 static void
1232 dwarf2out_frame_debug_expr (expr, label)
1233 rtx expr;
1234 const char *label;
1236 rtx src, dest;
1237 long offset;
1239 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1240 the PARALLEL independently. The first element is always processed if
1241 it is a SET. This is for backward compatibility. Other elements
1242 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1243 flag is set in them. */
1245 if (GET_CODE (expr) == PARALLEL
1246 || GET_CODE (expr) == SEQUENCE)
1248 int par_index;
1249 int limit = XVECLEN (expr, 0);
1251 for (par_index = 0; par_index < limit; par_index++)
1253 rtx x = XVECEXP (expr, 0, par_index);
1255 if (GET_CODE (x) == SET &&
1256 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1257 dwarf2out_frame_debug_expr (x, label);
1259 return;
1262 if (GET_CODE (expr) != SET)
1263 abort ();
1265 src = SET_SRC (expr);
1266 dest = SET_DEST (expr);
1268 switch (GET_CODE (dest))
1270 case REG:
1271 /* Rule 1 */
1272 /* Update the CFA rule wrt SP or FP. Make sure src is
1273 relative to the current CFA register. */
1274 switch (GET_CODE (src))
1276 /* Setting FP from SP. */
1277 case REG:
1278 if (cfa.reg == (unsigned) REGNO (src))
1279 /* OK. */
1281 else
1282 abort ();
1284 /* We used to require that dest be either SP or FP, but the
1285 ARM copies SP to a temporary register, and from there to
1286 FP. So we just rely on the backends to only set
1287 RTX_FRAME_RELATED_P on appropriate insns. */
1288 cfa.reg = REGNO (dest);
1289 cfa_temp.reg = cfa.reg;
1290 cfa_temp.offset = cfa.offset;
1291 break;
1293 case PLUS:
1294 case MINUS:
1295 case LO_SUM:
1296 if (dest == stack_pointer_rtx)
1298 /* Rule 2 */
1299 /* Adjusting SP. */
1300 switch (GET_CODE (XEXP (src, 1)))
1302 case CONST_INT:
1303 offset = INTVAL (XEXP (src, 1));
1304 break;
1305 case REG:
1306 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1307 abort ();
1308 offset = cfa_temp.offset;
1309 break;
1310 default:
1311 abort ();
1314 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1316 /* Restoring SP from FP in the epilogue. */
1317 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1318 abort ();
1319 cfa.reg = STACK_POINTER_REGNUM;
1321 else if (GET_CODE (src) == LO_SUM)
1322 /* Assume we've set the source reg of the LO_SUM from sp. */
1324 else if (XEXP (src, 0) != stack_pointer_rtx)
1325 abort ();
1327 if (GET_CODE (src) != MINUS)
1328 offset = -offset;
1329 if (cfa.reg == STACK_POINTER_REGNUM)
1330 cfa.offset += offset;
1331 if (cfa_store.reg == STACK_POINTER_REGNUM)
1332 cfa_store.offset += offset;
1334 else if (dest == hard_frame_pointer_rtx)
1336 /* Rule 3 */
1337 /* Either setting the FP from an offset of the SP,
1338 or adjusting the FP */
1339 if (! frame_pointer_needed)
1340 abort ();
1342 if (GET_CODE (XEXP (src, 0)) == REG
1343 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1344 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1346 offset = INTVAL (XEXP (src, 1));
1347 if (GET_CODE (src) != MINUS)
1348 offset = -offset;
1349 cfa.offset += offset;
1350 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1352 else
1353 abort ();
1355 else
1357 if (GET_CODE (src) == MINUS)
1358 abort ();
1360 /* Rule 4 */
1361 if (GET_CODE (XEXP (src, 0)) == REG
1362 && REGNO (XEXP (src, 0)) == cfa.reg
1363 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1365 /* Setting a temporary CFA register that will be copied
1366 into the FP later on. */
1367 offset = - INTVAL (XEXP (src, 1));
1368 cfa.offset += offset;
1369 cfa.reg = REGNO (dest);
1370 /* Or used to save regs to the stack. */
1371 cfa_temp.reg = cfa.reg;
1372 cfa_temp.offset = cfa.offset;
1374 /* Rule 5 */
1375 else if (GET_CODE (XEXP (src, 0)) == REG
1376 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1377 && XEXP (src, 1) == stack_pointer_rtx)
1379 /* Setting a scratch register that we will use instead
1380 of SP for saving registers to the stack. */
1381 if (cfa.reg != STACK_POINTER_REGNUM)
1382 abort ();
1383 cfa_store.reg = REGNO (dest);
1384 cfa_store.offset = cfa.offset - cfa_temp.offset;
1386 /* Rule 9 */
1387 else if (GET_CODE (src) == LO_SUM
1388 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1390 cfa_temp.reg = REGNO (dest);
1391 cfa_temp.offset = INTVAL (XEXP (src, 1));
1393 else
1394 abort ();
1396 break;
1398 /* Rule 6 */
1399 case CONST_INT:
1400 cfa_temp.reg = REGNO (dest);
1401 cfa_temp.offset = INTVAL (src);
1402 break;
1404 /* Rule 7 */
1405 case IOR:
1406 if (GET_CODE (XEXP (src, 0)) != REG
1407 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1408 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1409 abort ();
1410 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1411 cfa_temp.reg = REGNO (dest);
1412 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1413 break;
1415 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1416 which will fill in all of the bits. */
1417 /* Rule 8 */
1418 case HIGH:
1419 break;
1421 default:
1422 abort ();
1424 def_cfa_1 (label, &cfa);
1425 break;
1427 case MEM:
1428 if (GET_CODE (src) != REG)
1429 abort ();
1431 /* Saving a register to the stack. Make sure dest is relative to the
1432 CFA register. */
1433 switch (GET_CODE (XEXP (dest, 0)))
1435 /* Rule 10 */
1436 /* With a push. */
1437 case PRE_MODIFY:
1438 /* We can't handle variable size modifications. */
1439 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1440 abort();
1441 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1443 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1444 || cfa_store.reg != STACK_POINTER_REGNUM)
1445 abort ();
1446 cfa_store.offset += offset;
1447 if (cfa.reg == STACK_POINTER_REGNUM)
1448 cfa.offset = cfa_store.offset;
1450 offset = -cfa_store.offset;
1451 break;
1452 /* Rule 11 */
1453 case PRE_INC:
1454 case PRE_DEC:
1455 offset = GET_MODE_SIZE (GET_MODE (dest));
1456 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1457 offset = -offset;
1459 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1460 || cfa_store.reg != STACK_POINTER_REGNUM)
1461 abort ();
1462 cfa_store.offset += offset;
1463 if (cfa.reg == STACK_POINTER_REGNUM)
1464 cfa.offset = cfa_store.offset;
1466 offset = -cfa_store.offset;
1467 break;
1469 /* Rule 12 */
1470 /* With an offset. */
1471 case PLUS:
1472 case MINUS:
1473 case LO_SUM:
1474 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1475 abort ();
1476 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1477 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1478 offset = -offset;
1480 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1481 offset -= cfa_store.offset;
1482 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1483 offset -= cfa_temp.offset;
1484 else
1485 abort ();
1486 break;
1488 /* Rule 13 */
1489 /* Without an offset. */
1490 case REG:
1491 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1492 offset = -cfa_store.offset;
1493 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1494 offset = -cfa_temp.offset;
1495 else
1496 abort ();
1497 break;
1499 /* Rule 14 */
1500 case POST_INC:
1501 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1502 abort ();
1503 offset = -cfa_temp.offset;
1504 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1505 break;
1507 default:
1508 abort ();
1511 if (REGNO (src) != STACK_POINTER_REGNUM
1512 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1513 && (unsigned) REGNO (src) == cfa.reg)
1515 /* We're storing the current CFA reg into the stack. */
1517 if (cfa.offset == 0)
1519 /* If the source register is exactly the CFA, assume
1520 we're saving SP like any other register; this happens
1521 on the ARM. */
1523 def_cfa_1 (label, &cfa);
1524 queue_reg_save (label, stack_pointer_rtx, offset);
1525 break;
1527 else
1529 /* Otherwise, we'll need to look in the stack to
1530 calculate the CFA. */
1532 rtx x = XEXP (dest, 0);
1533 if (GET_CODE (x) != REG)
1534 x = XEXP (x, 0);
1535 if (GET_CODE (x) != REG)
1536 abort ();
1537 cfa.reg = (unsigned) REGNO (x);
1538 cfa.base_offset = offset;
1539 cfa.indirect = 1;
1540 def_cfa_1 (label, &cfa);
1541 break;
1545 def_cfa_1 (label, &cfa);
1546 queue_reg_save (label, src, offset);
1547 break;
1549 default:
1550 abort ();
1554 /* Record call frame debugging information for INSN, which either
1555 sets SP or FP (adjusting how we calculate the frame address) or saves a
1556 register to the stack. If INSN is NULL_RTX, initialize our state. */
1558 void
1559 dwarf2out_frame_debug (insn)
1560 rtx insn;
1562 const char *label;
1563 rtx src;
1565 if (insn == NULL_RTX)
1567 /* Flush any queued register saves. */
1568 flush_queued_reg_saves ();
1570 /* Set up state for generating call frame debug info. */
1571 lookup_cfa (&cfa);
1572 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1573 abort ();
1574 cfa.reg = STACK_POINTER_REGNUM;
1575 cfa_store = cfa;
1576 cfa_temp.reg = -1;
1577 cfa_temp.offset = 0;
1578 return;
1581 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1582 flush_queued_reg_saves ();
1584 if (! RTX_FRAME_RELATED_P (insn))
1586 if (!ACCUMULATE_OUTGOING_ARGS)
1587 dwarf2out_stack_adjust (insn);
1588 return;
1591 label = dwarf2out_cfi_label ();
1593 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1594 if (src)
1595 insn = XEXP (src, 0);
1596 else
1597 insn = PATTERN (insn);
1599 dwarf2out_frame_debug_expr (insn, label);
1602 /* Output a Call Frame Information opcode and its operand(s). */
1604 static void
1605 output_cfi (cfi, fde, for_eh)
1606 register dw_cfi_ref cfi;
1607 register dw_fde_ref fde;
1608 int for_eh;
1610 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1612 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1613 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1614 "DW_CFA_advance_loc 0x%lx",
1615 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1617 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1619 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1620 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1621 "DW_CFA_offset, column 0x%lx",
1622 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1623 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1625 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1627 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1628 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1629 "DW_CFA_restore, column 0x%lx",
1630 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1632 else
1634 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1635 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1637 switch (cfi->dw_cfi_opc)
1639 case DW_CFA_set_loc:
1640 if (for_eh)
1641 dw2_asm_output_encoded_addr_rtx (
1642 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1643 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1644 NULL);
1645 else
1646 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1647 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1648 break;
1649 case DW_CFA_advance_loc1:
1650 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1651 fde->dw_fde_current_label, NULL);
1652 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1653 break;
1654 case DW_CFA_advance_loc2:
1655 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1656 fde->dw_fde_current_label, NULL);
1657 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1658 break;
1659 case DW_CFA_advance_loc4:
1660 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1661 fde->dw_fde_current_label, NULL);
1662 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1663 break;
1664 case DW_CFA_MIPS_advance_loc8:
1665 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1666 fde->dw_fde_current_label, NULL);
1667 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1668 break;
1669 case DW_CFA_offset_extended:
1670 case DW_CFA_GNU_negative_offset_extended:
1671 case DW_CFA_def_cfa:
1672 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1673 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1674 break;
1675 case DW_CFA_restore_extended:
1676 case DW_CFA_undefined:
1677 case DW_CFA_same_value:
1678 case DW_CFA_def_cfa_register:
1679 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1680 break;
1681 case DW_CFA_register:
1682 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1683 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
1684 break;
1685 case DW_CFA_def_cfa_offset:
1686 case DW_CFA_GNU_args_size:
1687 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1688 break;
1689 case DW_CFA_GNU_window_save:
1690 break;
1691 case DW_CFA_def_cfa_expression:
1692 output_cfa_loc (cfi);
1693 break;
1694 default:
1695 break;
1700 /* Output the call frame information used to used to record information
1701 that relates to calculating the frame pointer, and records the
1702 location of saved registers. */
1704 static void
1705 output_call_frame_info (for_eh)
1706 int for_eh;
1708 register unsigned int i;
1709 register dw_fde_ref fde;
1710 register dw_cfi_ref cfi;
1711 char l1[20], l2[20];
1712 int any_lsda_needed = 0;
1713 char augmentation[6];
1714 int augmentation_size;
1715 int fde_encoding = DW_EH_PE_absptr;
1716 int per_encoding = DW_EH_PE_absptr;
1717 int lsda_encoding = DW_EH_PE_absptr;
1719 /* If we don't have any functions we'll want to unwind out of, don't
1720 emit any EH unwind information. */
1721 if (for_eh)
1723 int any_eh_needed = 0;
1724 for (i = 0; i < fde_table_in_use; ++i)
1725 if (fde_table[i].uses_eh_lsda)
1726 any_eh_needed = any_lsda_needed = 1;
1727 else if (! fde_table[i].nothrow)
1728 any_eh_needed = 1;
1730 if (! any_eh_needed)
1731 return;
1734 /* We're going to be generating comments, so turn on app. */
1735 if (flag_debug_asm)
1736 app_enable ();
1738 if (for_eh)
1740 #ifdef EH_FRAME_SECTION_NAME
1741 named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
1742 #else
1743 tree label = get_file_function_name ('F');
1745 data_section ();
1746 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1747 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1748 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1749 #endif
1750 assemble_label ("__FRAME_BEGIN__");
1752 else
1753 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1755 /* Output the CIE. */
1756 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1757 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1758 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1759 "Length of Common Information Entry");
1760 ASM_OUTPUT_LABEL (asm_out_file, l1);
1762 /* Now that the CIE pointer is PC-relative for EH,
1763 use 0 to identify the CIE. */
1764 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1765 (for_eh ? 0 : DW_CIE_ID),
1766 "CIE Identifier Tag");
1768 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1770 augmentation[0] = 0;
1771 augmentation_size = 0;
1772 if (for_eh)
1774 char *p;
1776 /* Augmentation:
1777 z Indicates that a uleb128 is present to size the
1778 augmentation section.
1779 L Indicates the encoding (and thus presence) of
1780 an LSDA pointer in the FDE augmentation.
1781 R Indicates a non-default pointer encoding for
1782 FDE code pointers.
1783 P Indicates the presence of an encoding + language
1784 personality routine in the CIE augmentation. */
1786 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1787 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1788 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1790 p = augmentation + 1;
1791 if (eh_personality_libfunc)
1793 *p++ = 'P';
1794 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1796 if (any_lsda_needed)
1798 *p++ = 'L';
1799 augmentation_size += 1;
1801 if (fde_encoding != DW_EH_PE_absptr)
1803 *p++ = 'R';
1804 augmentation_size += 1;
1806 if (p > augmentation + 1)
1808 augmentation[0] = 'z';
1809 *p = '\0';
1812 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1813 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1815 int offset = ( 4 /* Length */
1816 + 4 /* CIE Id */
1817 + 1 /* CIE version */
1818 + strlen (augmentation) + 1 /* Augmentation */
1819 + size_of_uleb128 (1) /* Code alignment */
1820 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1821 + 1 /* RA column */
1822 + 1 /* Augmentation size */
1823 + 1 /* Personality encoding */ );
1824 int pad = -offset & (PTR_SIZE - 1);
1826 augmentation_size += pad;
1828 /* Augmentations should be small, so there's scarce need to
1829 iterate for a solution. Die if we exceed one uleb128 byte. */
1830 if (size_of_uleb128 (augmentation_size) != 1)
1831 abort ();
1834 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1836 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1838 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1839 "CIE Data Alignment Factor");
1841 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1843 if (augmentation[0])
1845 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1846 if (eh_personality_libfunc)
1848 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1849 eh_data_format_name (per_encoding));
1850 dw2_asm_output_encoded_addr_rtx (per_encoding,
1851 eh_personality_libfunc, NULL);
1853 if (any_lsda_needed)
1854 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1855 eh_data_format_name (lsda_encoding));
1856 if (fde_encoding != DW_EH_PE_absptr)
1857 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1858 eh_data_format_name (fde_encoding));
1861 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1862 output_cfi (cfi, NULL, for_eh);
1864 /* Pad the CIE out to an address sized boundary. */
1865 ASM_OUTPUT_ALIGN (asm_out_file,
1866 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1867 ASM_OUTPUT_LABEL (asm_out_file, l2);
1869 /* Loop through all of the FDE's. */
1870 for (i = 0; i < fde_table_in_use; ++i)
1872 fde = &fde_table[i];
1874 /* Don't emit EH unwind info for leaf functions that don't need it. */
1875 if (for_eh && fde->nothrow && ! fde->uses_eh_lsda)
1876 continue;
1878 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1879 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1880 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1881 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1882 "FDE Length");
1883 ASM_OUTPUT_LABEL (asm_out_file, l1);
1885 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1886 emits a target dependent sized offset when for_eh is not true.
1887 This inconsistency may confuse gdb. The only case where we need a
1888 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1889 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1890 though in order to be compatible with the dwarf_fde struct in frame.c.
1891 If the for_eh case is changed, then the struct in frame.c has
1892 to be adjusted appropriately. */
1893 if (for_eh)
1894 dw2_asm_output_delta (4, l1, "__FRAME_BEGIN__", "FDE CIE offset");
1895 else
1896 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
1897 stripattributes (DEBUG_FRAME_SECTION),
1898 "FDE CIE offset");
1900 if (for_eh)
1902 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1903 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1904 "FDE initial location");
1905 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1906 fde->dw_fde_end, fde->dw_fde_begin,
1907 "FDE address range");
1909 else
1911 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1912 "FDE initial location");
1913 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
1914 fde->dw_fde_end, fde->dw_fde_begin,
1915 "FDE address range");
1918 if (augmentation[0])
1920 if (any_lsda_needed)
1922 int size = size_of_encoded_value (lsda_encoding);
1924 if (lsda_encoding == DW_EH_PE_aligned)
1926 int offset = ( 4 /* Length */
1927 + 4 /* CIE offset */
1928 + 2 * size_of_encoded_value (fde_encoding)
1929 + 1 /* Augmentation size */ );
1930 int pad = -offset & (PTR_SIZE - 1);
1932 size += pad;
1933 if (size_of_uleb128 (size) != 1)
1934 abort ();
1937 dw2_asm_output_data_uleb128 (size, "Augmentation size");
1939 if (fde->uses_eh_lsda)
1941 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
1942 fde->funcdef_number);
1943 dw2_asm_output_encoded_addr_rtx (
1944 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
1945 "Language Specific Data Area");
1947 else
1949 if (lsda_encoding == DW_EH_PE_aligned)
1950 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1951 dw2_asm_output_data (size_of_encoded_value (lsda_encoding),
1952 0, "Language Specific Data Area (none)");
1955 else
1956 dw2_asm_output_data_uleb128 (0, "Augmentation size");
1959 /* Loop through the Call Frame Instructions associated with
1960 this FDE. */
1961 fde->dw_fde_current_label = fde->dw_fde_begin;
1962 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1963 output_cfi (cfi, fde, for_eh);
1965 /* Pad the FDE out to an address sized boundary. */
1966 ASM_OUTPUT_ALIGN (asm_out_file,
1967 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
1968 ASM_OUTPUT_LABEL (asm_out_file, l2);
1971 #ifndef EH_FRAME_SECTION_NAME
1972 if (for_eh)
1973 dw2_asm_output_data (4, 0, "End of Table");
1974 #endif
1975 #ifdef MIPS_DEBUGGING_INFO
1976 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1977 get a value of 0. Putting .align 0 after the label fixes it. */
1978 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1979 #endif
1981 /* Turn off app to make assembly quicker. */
1982 if (flag_debug_asm)
1983 app_disable ();
1986 /* Output a marker (i.e. a label) for the beginning of a function, before
1987 the prologue. */
1989 void
1990 dwarf2out_begin_prologue (line, file)
1991 unsigned int line ATTRIBUTE_UNUSED;
1992 const char *file ATTRIBUTE_UNUSED;
1994 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1995 register dw_fde_ref fde;
1997 current_function_func_begin_label = 0;
1999 #ifdef IA64_UNWIND_INFO
2000 /* ??? current_function_func_begin_label is also used by except.c
2001 for call-site information. We must emit this label if it might
2002 be used. */
2003 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2004 && ! dwarf2out_do_frame ())
2005 return;
2006 #else
2007 if (! dwarf2out_do_frame ())
2008 return;
2009 #endif
2011 ++current_funcdef_number;
2013 function_section (current_function_decl);
2014 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2015 current_funcdef_number);
2016 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2017 current_funcdef_number);
2018 current_function_func_begin_label = get_identifier (label);
2020 #ifdef IA64_UNWIND_INFO
2021 /* We can elide the fde allocation if we're not emitting debug info. */
2022 if (! dwarf2out_do_frame ())
2023 return;
2024 #endif
2026 /* Expand the fde table if necessary. */
2027 if (fde_table_in_use == fde_table_allocated)
2029 fde_table_allocated += FDE_TABLE_INCREMENT;
2030 fde_table
2031 = (dw_fde_ref) xrealloc (fde_table,
2032 fde_table_allocated * sizeof (dw_fde_node));
2035 /* Record the FDE associated with this function. */
2036 current_funcdef_fde = fde_table_in_use;
2038 /* Add the new FDE at the end of the fde_table. */
2039 fde = &fde_table[fde_table_in_use++];
2040 fde->dw_fde_begin = xstrdup (label);
2041 fde->dw_fde_current_label = NULL;
2042 fde->dw_fde_end = NULL;
2043 fde->dw_fde_cfi = NULL;
2044 fde->funcdef_number = current_funcdef_number;
2045 fde->nothrow = current_function_nothrow;
2046 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2048 args_size = old_args_size = 0;
2050 /* We only want to output line number information for the genuine
2051 dwarf2 prologue case, not the eh frame case. */
2052 #ifdef DWARF2_DEBUGGING_INFO
2053 if (file)
2054 dwarf2out_source_line (line, file);
2055 #endif
2058 /* Output a marker (i.e. a label) for the absolute end of the generated code
2059 for a function definition. This gets called *after* the epilogue code has
2060 been generated. */
2062 void
2063 dwarf2out_end_epilogue ()
2065 dw_fde_ref fde;
2066 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2068 /* Output a label to mark the endpoint of the code generated for this
2069 function. */
2070 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2071 ASM_OUTPUT_LABEL (asm_out_file, label);
2072 fde = &fde_table[fde_table_in_use - 1];
2073 fde->dw_fde_end = xstrdup (label);
2076 void
2077 dwarf2out_frame_init ()
2079 /* Allocate the initial hunk of the fde_table. */
2080 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2081 fde_table_allocated = FDE_TABLE_INCREMENT;
2082 fde_table_in_use = 0;
2084 /* Generate the CFA instructions common to all FDE's. Do it now for the
2085 sake of lookup_cfa. */
2087 #ifdef DWARF2_UNWIND_INFO
2088 /* On entry, the Canonical Frame Address is at SP. */
2089 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2090 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2091 #endif
2094 void
2095 dwarf2out_frame_finish ()
2097 /* Output call frame information. */
2098 #ifdef MIPS_DEBUGGING_INFO
2099 if (write_symbols == DWARF2_DEBUG)
2100 output_call_frame_info (0);
2101 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2102 output_call_frame_info (1);
2103 #else
2104 int for_eh = (! USING_SJLJ_EXCEPTIONS
2105 && (flag_unwind_tables || flag_exceptions));
2106 if (write_symbols == DWARF2_DEBUG || for_eh)
2107 output_call_frame_info (for_eh);
2108 #endif
2111 /* And now, the subset of the debugging information support code necessary
2112 for emitting location expressions. */
2114 typedef struct dw_val_struct *dw_val_ref;
2115 typedef struct die_struct *dw_die_ref;
2116 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2117 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2119 /* Each DIE may have a series of attribute/value pairs. Values
2120 can take on several forms. The forms that are used in this
2121 implementation are listed below. */
2123 typedef enum
2125 dw_val_class_addr,
2126 dw_val_class_offset,
2127 dw_val_class_loc,
2128 dw_val_class_loc_list,
2129 dw_val_class_const,
2130 dw_val_class_unsigned_const,
2131 dw_val_class_long_long,
2132 dw_val_class_float,
2133 dw_val_class_flag,
2134 dw_val_class_die_ref,
2135 dw_val_class_fde_ref,
2136 dw_val_class_lbl_id,
2137 dw_val_class_lbl_offset,
2138 dw_val_class_str
2140 dw_val_class;
2142 /* Describe a double word constant value. */
2143 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2145 typedef struct dw_long_long_struct
2147 unsigned long hi;
2148 unsigned long low;
2150 dw_long_long_const;
2152 /* Describe a floating point constant value. */
2154 typedef struct dw_fp_struct
2156 long *array;
2157 unsigned length;
2159 dw_float_const;
2161 /* The dw_val_node describes an attribute's value, as it is
2162 represented internally. */
2164 typedef struct dw_val_struct
2166 dw_val_class val_class;
2167 union
2169 rtx val_addr;
2170 long unsigned val_offset;
2171 dw_loc_list_ref val_loc_list;
2172 dw_loc_descr_ref val_loc;
2173 long int val_int;
2174 long unsigned val_unsigned;
2175 dw_long_long_const val_long_long;
2176 dw_float_const val_float;
2177 struct {
2178 dw_die_ref die;
2179 int external;
2180 } val_die_ref;
2181 unsigned val_fde_index;
2182 char *val_str;
2183 char *val_lbl_id;
2184 unsigned char val_flag;
2188 dw_val_node;
2190 /* Locations in memory are described using a sequence of stack machine
2191 operations. */
2193 typedef struct dw_loc_descr_struct
2195 dw_loc_descr_ref dw_loc_next;
2196 enum dwarf_location_atom dw_loc_opc;
2197 dw_val_node dw_loc_oprnd1;
2198 dw_val_node dw_loc_oprnd2;
2199 int dw_loc_addr;
2201 dw_loc_descr_node;
2203 /* Location lists are ranges + location descriptions for that range,
2204 so you can track variables that are in different places over
2205 their entire life. */
2206 typedef struct dw_loc_list_struct
2208 dw_loc_list_ref dw_loc_next;
2209 const char *begin; /* Label for begin address of range */
2210 const char *end; /* Label for end address of range */
2211 char *ll_symbol; /* Label for beginning of location list. Only on head of list */
2212 const char *section; /* Section this loclist is relative to */
2213 dw_loc_descr_ref expr;
2214 } dw_loc_list_node;
2216 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2217 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2218 unsigned long,
2219 unsigned long));
2220 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2221 dw_loc_descr_ref));
2222 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2223 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2224 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2225 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2227 /* Convert a DWARF stack opcode into its string name. */
2229 static const char *
2230 dwarf_stack_op_name (op)
2231 register unsigned op;
2233 switch (op)
2235 case DW_OP_addr:
2236 return "DW_OP_addr";
2237 case DW_OP_deref:
2238 return "DW_OP_deref";
2239 case DW_OP_const1u:
2240 return "DW_OP_const1u";
2241 case DW_OP_const1s:
2242 return "DW_OP_const1s";
2243 case DW_OP_const2u:
2244 return "DW_OP_const2u";
2245 case DW_OP_const2s:
2246 return "DW_OP_const2s";
2247 case DW_OP_const4u:
2248 return "DW_OP_const4u";
2249 case DW_OP_const4s:
2250 return "DW_OP_const4s";
2251 case DW_OP_const8u:
2252 return "DW_OP_const8u";
2253 case DW_OP_const8s:
2254 return "DW_OP_const8s";
2255 case DW_OP_constu:
2256 return "DW_OP_constu";
2257 case DW_OP_consts:
2258 return "DW_OP_consts";
2259 case DW_OP_dup:
2260 return "DW_OP_dup";
2261 case DW_OP_drop:
2262 return "DW_OP_drop";
2263 case DW_OP_over:
2264 return "DW_OP_over";
2265 case DW_OP_pick:
2266 return "DW_OP_pick";
2267 case DW_OP_swap:
2268 return "DW_OP_swap";
2269 case DW_OP_rot:
2270 return "DW_OP_rot";
2271 case DW_OP_xderef:
2272 return "DW_OP_xderef";
2273 case DW_OP_abs:
2274 return "DW_OP_abs";
2275 case DW_OP_and:
2276 return "DW_OP_and";
2277 case DW_OP_div:
2278 return "DW_OP_div";
2279 case DW_OP_minus:
2280 return "DW_OP_minus";
2281 case DW_OP_mod:
2282 return "DW_OP_mod";
2283 case DW_OP_mul:
2284 return "DW_OP_mul";
2285 case DW_OP_neg:
2286 return "DW_OP_neg";
2287 case DW_OP_not:
2288 return "DW_OP_not";
2289 case DW_OP_or:
2290 return "DW_OP_or";
2291 case DW_OP_plus:
2292 return "DW_OP_plus";
2293 case DW_OP_plus_uconst:
2294 return "DW_OP_plus_uconst";
2295 case DW_OP_shl:
2296 return "DW_OP_shl";
2297 case DW_OP_shr:
2298 return "DW_OP_shr";
2299 case DW_OP_shra:
2300 return "DW_OP_shra";
2301 case DW_OP_xor:
2302 return "DW_OP_xor";
2303 case DW_OP_bra:
2304 return "DW_OP_bra";
2305 case DW_OP_eq:
2306 return "DW_OP_eq";
2307 case DW_OP_ge:
2308 return "DW_OP_ge";
2309 case DW_OP_gt:
2310 return "DW_OP_gt";
2311 case DW_OP_le:
2312 return "DW_OP_le";
2313 case DW_OP_lt:
2314 return "DW_OP_lt";
2315 case DW_OP_ne:
2316 return "DW_OP_ne";
2317 case DW_OP_skip:
2318 return "DW_OP_skip";
2319 case DW_OP_lit0:
2320 return "DW_OP_lit0";
2321 case DW_OP_lit1:
2322 return "DW_OP_lit1";
2323 case DW_OP_lit2:
2324 return "DW_OP_lit2";
2325 case DW_OP_lit3:
2326 return "DW_OP_lit3";
2327 case DW_OP_lit4:
2328 return "DW_OP_lit4";
2329 case DW_OP_lit5:
2330 return "DW_OP_lit5";
2331 case DW_OP_lit6:
2332 return "DW_OP_lit6";
2333 case DW_OP_lit7:
2334 return "DW_OP_lit7";
2335 case DW_OP_lit8:
2336 return "DW_OP_lit8";
2337 case DW_OP_lit9:
2338 return "DW_OP_lit9";
2339 case DW_OP_lit10:
2340 return "DW_OP_lit10";
2341 case DW_OP_lit11:
2342 return "DW_OP_lit11";
2343 case DW_OP_lit12:
2344 return "DW_OP_lit12";
2345 case DW_OP_lit13:
2346 return "DW_OP_lit13";
2347 case DW_OP_lit14:
2348 return "DW_OP_lit14";
2349 case DW_OP_lit15:
2350 return "DW_OP_lit15";
2351 case DW_OP_lit16:
2352 return "DW_OP_lit16";
2353 case DW_OP_lit17:
2354 return "DW_OP_lit17";
2355 case DW_OP_lit18:
2356 return "DW_OP_lit18";
2357 case DW_OP_lit19:
2358 return "DW_OP_lit19";
2359 case DW_OP_lit20:
2360 return "DW_OP_lit20";
2361 case DW_OP_lit21:
2362 return "DW_OP_lit21";
2363 case DW_OP_lit22:
2364 return "DW_OP_lit22";
2365 case DW_OP_lit23:
2366 return "DW_OP_lit23";
2367 case DW_OP_lit24:
2368 return "DW_OP_lit24";
2369 case DW_OP_lit25:
2370 return "DW_OP_lit25";
2371 case DW_OP_lit26:
2372 return "DW_OP_lit26";
2373 case DW_OP_lit27:
2374 return "DW_OP_lit27";
2375 case DW_OP_lit28:
2376 return "DW_OP_lit28";
2377 case DW_OP_lit29:
2378 return "DW_OP_lit29";
2379 case DW_OP_lit30:
2380 return "DW_OP_lit30";
2381 case DW_OP_lit31:
2382 return "DW_OP_lit31";
2383 case DW_OP_reg0:
2384 return "DW_OP_reg0";
2385 case DW_OP_reg1:
2386 return "DW_OP_reg1";
2387 case DW_OP_reg2:
2388 return "DW_OP_reg2";
2389 case DW_OP_reg3:
2390 return "DW_OP_reg3";
2391 case DW_OP_reg4:
2392 return "DW_OP_reg4";
2393 case DW_OP_reg5:
2394 return "DW_OP_reg5";
2395 case DW_OP_reg6:
2396 return "DW_OP_reg6";
2397 case DW_OP_reg7:
2398 return "DW_OP_reg7";
2399 case DW_OP_reg8:
2400 return "DW_OP_reg8";
2401 case DW_OP_reg9:
2402 return "DW_OP_reg9";
2403 case DW_OP_reg10:
2404 return "DW_OP_reg10";
2405 case DW_OP_reg11:
2406 return "DW_OP_reg11";
2407 case DW_OP_reg12:
2408 return "DW_OP_reg12";
2409 case DW_OP_reg13:
2410 return "DW_OP_reg13";
2411 case DW_OP_reg14:
2412 return "DW_OP_reg14";
2413 case DW_OP_reg15:
2414 return "DW_OP_reg15";
2415 case DW_OP_reg16:
2416 return "DW_OP_reg16";
2417 case DW_OP_reg17:
2418 return "DW_OP_reg17";
2419 case DW_OP_reg18:
2420 return "DW_OP_reg18";
2421 case DW_OP_reg19:
2422 return "DW_OP_reg19";
2423 case DW_OP_reg20:
2424 return "DW_OP_reg20";
2425 case DW_OP_reg21:
2426 return "DW_OP_reg21";
2427 case DW_OP_reg22:
2428 return "DW_OP_reg22";
2429 case DW_OP_reg23:
2430 return "DW_OP_reg23";
2431 case DW_OP_reg24:
2432 return "DW_OP_reg24";
2433 case DW_OP_reg25:
2434 return "DW_OP_reg25";
2435 case DW_OP_reg26:
2436 return "DW_OP_reg26";
2437 case DW_OP_reg27:
2438 return "DW_OP_reg27";
2439 case DW_OP_reg28:
2440 return "DW_OP_reg28";
2441 case DW_OP_reg29:
2442 return "DW_OP_reg29";
2443 case DW_OP_reg30:
2444 return "DW_OP_reg30";
2445 case DW_OP_reg31:
2446 return "DW_OP_reg31";
2447 case DW_OP_breg0:
2448 return "DW_OP_breg0";
2449 case DW_OP_breg1:
2450 return "DW_OP_breg1";
2451 case DW_OP_breg2:
2452 return "DW_OP_breg2";
2453 case DW_OP_breg3:
2454 return "DW_OP_breg3";
2455 case DW_OP_breg4:
2456 return "DW_OP_breg4";
2457 case DW_OP_breg5:
2458 return "DW_OP_breg5";
2459 case DW_OP_breg6:
2460 return "DW_OP_breg6";
2461 case DW_OP_breg7:
2462 return "DW_OP_breg7";
2463 case DW_OP_breg8:
2464 return "DW_OP_breg8";
2465 case DW_OP_breg9:
2466 return "DW_OP_breg9";
2467 case DW_OP_breg10:
2468 return "DW_OP_breg10";
2469 case DW_OP_breg11:
2470 return "DW_OP_breg11";
2471 case DW_OP_breg12:
2472 return "DW_OP_breg12";
2473 case DW_OP_breg13:
2474 return "DW_OP_breg13";
2475 case DW_OP_breg14:
2476 return "DW_OP_breg14";
2477 case DW_OP_breg15:
2478 return "DW_OP_breg15";
2479 case DW_OP_breg16:
2480 return "DW_OP_breg16";
2481 case DW_OP_breg17:
2482 return "DW_OP_breg17";
2483 case DW_OP_breg18:
2484 return "DW_OP_breg18";
2485 case DW_OP_breg19:
2486 return "DW_OP_breg19";
2487 case DW_OP_breg20:
2488 return "DW_OP_breg20";
2489 case DW_OP_breg21:
2490 return "DW_OP_breg21";
2491 case DW_OP_breg22:
2492 return "DW_OP_breg22";
2493 case DW_OP_breg23:
2494 return "DW_OP_breg23";
2495 case DW_OP_breg24:
2496 return "DW_OP_breg24";
2497 case DW_OP_breg25:
2498 return "DW_OP_breg25";
2499 case DW_OP_breg26:
2500 return "DW_OP_breg26";
2501 case DW_OP_breg27:
2502 return "DW_OP_breg27";
2503 case DW_OP_breg28:
2504 return "DW_OP_breg28";
2505 case DW_OP_breg29:
2506 return "DW_OP_breg29";
2507 case DW_OP_breg30:
2508 return "DW_OP_breg30";
2509 case DW_OP_breg31:
2510 return "DW_OP_breg31";
2511 case DW_OP_regx:
2512 return "DW_OP_regx";
2513 case DW_OP_fbreg:
2514 return "DW_OP_fbreg";
2515 case DW_OP_bregx:
2516 return "DW_OP_bregx";
2517 case DW_OP_piece:
2518 return "DW_OP_piece";
2519 case DW_OP_deref_size:
2520 return "DW_OP_deref_size";
2521 case DW_OP_xderef_size:
2522 return "DW_OP_xderef_size";
2523 case DW_OP_nop:
2524 return "DW_OP_nop";
2525 default:
2526 return "OP_<unknown>";
2530 /* Return a pointer to a newly allocated location description. Location
2531 descriptions are simple expression terms that can be strung
2532 together to form more complicated location (address) descriptions. */
2534 static inline dw_loc_descr_ref
2535 new_loc_descr (op, oprnd1, oprnd2)
2536 register enum dwarf_location_atom op;
2537 register unsigned long oprnd1;
2538 register unsigned long oprnd2;
2540 /* Use xcalloc here so we clear out all of the long_long constant in
2541 the union. */
2542 register dw_loc_descr_ref descr
2543 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2545 descr->dw_loc_opc = op;
2546 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2547 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2548 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2549 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2551 return descr;
2555 /* Add a location description term to a location description expression. */
2557 static inline void
2558 add_loc_descr (list_head, descr)
2559 register dw_loc_descr_ref *list_head;
2560 register dw_loc_descr_ref descr;
2562 register dw_loc_descr_ref *d;
2564 /* Find the end of the chain. */
2565 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2568 *d = descr;
2571 /* Return the size of a location descriptor. */
2573 static unsigned long
2574 size_of_loc_descr (loc)
2575 register dw_loc_descr_ref loc;
2577 register unsigned long size = 1;
2579 switch (loc->dw_loc_opc)
2581 case DW_OP_addr:
2582 size += DWARF2_ADDR_SIZE;
2583 break;
2584 case DW_OP_const1u:
2585 case DW_OP_const1s:
2586 size += 1;
2587 break;
2588 case DW_OP_const2u:
2589 case DW_OP_const2s:
2590 size += 2;
2591 break;
2592 case DW_OP_const4u:
2593 case DW_OP_const4s:
2594 size += 4;
2595 break;
2596 case DW_OP_const8u:
2597 case DW_OP_const8s:
2598 size += 8;
2599 break;
2600 case DW_OP_constu:
2601 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2602 break;
2603 case DW_OP_consts:
2604 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2605 break;
2606 case DW_OP_pick:
2607 size += 1;
2608 break;
2609 case DW_OP_plus_uconst:
2610 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2611 break;
2612 case DW_OP_skip:
2613 case DW_OP_bra:
2614 size += 2;
2615 break;
2616 case DW_OP_breg0:
2617 case DW_OP_breg1:
2618 case DW_OP_breg2:
2619 case DW_OP_breg3:
2620 case DW_OP_breg4:
2621 case DW_OP_breg5:
2622 case DW_OP_breg6:
2623 case DW_OP_breg7:
2624 case DW_OP_breg8:
2625 case DW_OP_breg9:
2626 case DW_OP_breg10:
2627 case DW_OP_breg11:
2628 case DW_OP_breg12:
2629 case DW_OP_breg13:
2630 case DW_OP_breg14:
2631 case DW_OP_breg15:
2632 case DW_OP_breg16:
2633 case DW_OP_breg17:
2634 case DW_OP_breg18:
2635 case DW_OP_breg19:
2636 case DW_OP_breg20:
2637 case DW_OP_breg21:
2638 case DW_OP_breg22:
2639 case DW_OP_breg23:
2640 case DW_OP_breg24:
2641 case DW_OP_breg25:
2642 case DW_OP_breg26:
2643 case DW_OP_breg27:
2644 case DW_OP_breg28:
2645 case DW_OP_breg29:
2646 case DW_OP_breg30:
2647 case DW_OP_breg31:
2648 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2649 break;
2650 case DW_OP_regx:
2651 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2652 break;
2653 case DW_OP_fbreg:
2654 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2655 break;
2656 case DW_OP_bregx:
2657 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2658 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2659 break;
2660 case DW_OP_piece:
2661 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2662 break;
2663 case DW_OP_deref_size:
2664 case DW_OP_xderef_size:
2665 size += 1;
2666 break;
2667 default:
2668 break;
2671 return size;
2674 /* Return the size of a series of location descriptors. */
2676 static unsigned long
2677 size_of_locs (loc)
2678 register dw_loc_descr_ref loc;
2680 register unsigned long size = 0;
2682 for (; loc != NULL; loc = loc->dw_loc_next)
2684 loc->dw_loc_addr = size;
2685 size += size_of_loc_descr (loc);
2688 return size;
2691 /* Output location description stack opcode's operands (if any). */
2693 static void
2694 output_loc_operands (loc)
2695 register dw_loc_descr_ref loc;
2697 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2698 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2700 switch (loc->dw_loc_opc)
2702 #ifdef DWARF2_DEBUGGING_INFO
2703 case DW_OP_addr:
2704 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2705 break;
2706 case DW_OP_const2u:
2707 case DW_OP_const2s:
2708 dw2_asm_output_data (2, val1->v.val_int, NULL);
2709 break;
2710 case DW_OP_const4u:
2711 case DW_OP_const4s:
2712 dw2_asm_output_data (4, val1->v.val_int, NULL);
2713 break;
2714 case DW_OP_const8u:
2715 case DW_OP_const8s:
2716 if (HOST_BITS_PER_LONG < 64)
2717 abort ();
2718 dw2_asm_output_data (8, val1->v.val_int, NULL);
2719 break;
2720 case DW_OP_skip:
2721 case DW_OP_bra:
2723 int offset;
2725 if (val1->val_class == dw_val_class_loc)
2726 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2727 else
2728 abort ();
2730 dw2_asm_output_data (2, offset, NULL);
2732 break;
2733 #else
2734 case DW_OP_addr:
2735 case DW_OP_const2u:
2736 case DW_OP_const2s:
2737 case DW_OP_const4u:
2738 case DW_OP_const4s:
2739 case DW_OP_const8u:
2740 case DW_OP_const8s:
2741 case DW_OP_skip:
2742 case DW_OP_bra:
2743 /* We currently don't make any attempt to make sure these are
2744 aligned properly like we do for the main unwind info, so
2745 don't support emitting things larger than a byte if we're
2746 only doing unwinding. */
2747 abort ();
2748 #endif
2749 case DW_OP_const1u:
2750 case DW_OP_const1s:
2751 dw2_asm_output_data (1, val1->v.val_int, NULL);
2752 break;
2753 case DW_OP_constu:
2754 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2755 break;
2756 case DW_OP_consts:
2757 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2758 break;
2759 case DW_OP_pick:
2760 dw2_asm_output_data (1, val1->v.val_int, NULL);
2761 break;
2762 case DW_OP_plus_uconst:
2763 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2764 break;
2765 case DW_OP_breg0:
2766 case DW_OP_breg1:
2767 case DW_OP_breg2:
2768 case DW_OP_breg3:
2769 case DW_OP_breg4:
2770 case DW_OP_breg5:
2771 case DW_OP_breg6:
2772 case DW_OP_breg7:
2773 case DW_OP_breg8:
2774 case DW_OP_breg9:
2775 case DW_OP_breg10:
2776 case DW_OP_breg11:
2777 case DW_OP_breg12:
2778 case DW_OP_breg13:
2779 case DW_OP_breg14:
2780 case DW_OP_breg15:
2781 case DW_OP_breg16:
2782 case DW_OP_breg17:
2783 case DW_OP_breg18:
2784 case DW_OP_breg19:
2785 case DW_OP_breg20:
2786 case DW_OP_breg21:
2787 case DW_OP_breg22:
2788 case DW_OP_breg23:
2789 case DW_OP_breg24:
2790 case DW_OP_breg25:
2791 case DW_OP_breg26:
2792 case DW_OP_breg27:
2793 case DW_OP_breg28:
2794 case DW_OP_breg29:
2795 case DW_OP_breg30:
2796 case DW_OP_breg31:
2797 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2798 break;
2799 case DW_OP_regx:
2800 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2801 break;
2802 case DW_OP_fbreg:
2803 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2804 break;
2805 case DW_OP_bregx:
2806 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2807 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2808 break;
2809 case DW_OP_piece:
2810 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2811 break;
2812 case DW_OP_deref_size:
2813 case DW_OP_xderef_size:
2814 dw2_asm_output_data (1, val1->v.val_int, NULL);
2815 break;
2816 default:
2817 /* Other codes have no operands. */
2818 break;
2822 /* Output a sequence of location operations. */
2824 static void
2825 output_loc_sequence (loc)
2826 dw_loc_descr_ref loc;
2828 for (; loc != NULL; loc = loc->dw_loc_next)
2830 /* Output the opcode. */
2831 dw2_asm_output_data (1, loc->dw_loc_opc,
2832 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2834 /* Output the operand(s) (if any). */
2835 output_loc_operands (loc);
2839 /* This routine will generate the correct assembly data for a location
2840 description based on a cfi entry with a complex address. */
2842 static void
2843 output_cfa_loc (cfi)
2844 dw_cfi_ref cfi;
2846 dw_loc_descr_ref loc;
2847 unsigned long size;
2849 /* Output the size of the block. */
2850 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2851 size = size_of_locs (loc);
2852 dw2_asm_output_data_uleb128 (size, NULL);
2854 /* Now output the operations themselves. */
2855 output_loc_sequence (loc);
2858 /* This function builds a dwarf location descriptor sequence from
2859 a dw_cfa_location. */
2861 static struct dw_loc_descr_struct *
2862 build_cfa_loc (cfa)
2863 dw_cfa_location *cfa;
2865 struct dw_loc_descr_struct *head, *tmp;
2867 if (cfa->indirect == 0)
2868 abort ();
2870 if (cfa->base_offset)
2872 if (cfa->reg <= 31)
2873 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2874 else
2875 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2877 else if (cfa->reg <= 31)
2878 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2879 else
2880 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2881 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2882 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2883 add_loc_descr (&head, tmp);
2884 if (cfa->offset != 0)
2886 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2887 add_loc_descr (&head, tmp);
2889 return head;
2892 /* This function fills in aa dw_cfa_location structure from a
2893 dwarf location descriptor sequence. */
2895 static void
2896 get_cfa_from_loc_descr (cfa, loc)
2897 dw_cfa_location *cfa;
2898 struct dw_loc_descr_struct *loc;
2900 struct dw_loc_descr_struct *ptr;
2901 cfa->offset = 0;
2902 cfa->base_offset = 0;
2903 cfa->indirect = 0;
2904 cfa->reg = -1;
2906 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2908 enum dwarf_location_atom op = ptr->dw_loc_opc;
2909 switch (op)
2911 case DW_OP_reg0:
2912 case DW_OP_reg1:
2913 case DW_OP_reg2:
2914 case DW_OP_reg3:
2915 case DW_OP_reg4:
2916 case DW_OP_reg5:
2917 case DW_OP_reg6:
2918 case DW_OP_reg7:
2919 case DW_OP_reg8:
2920 case DW_OP_reg9:
2921 case DW_OP_reg10:
2922 case DW_OP_reg11:
2923 case DW_OP_reg12:
2924 case DW_OP_reg13:
2925 case DW_OP_reg14:
2926 case DW_OP_reg15:
2927 case DW_OP_reg16:
2928 case DW_OP_reg17:
2929 case DW_OP_reg18:
2930 case DW_OP_reg19:
2931 case DW_OP_reg20:
2932 case DW_OP_reg21:
2933 case DW_OP_reg22:
2934 case DW_OP_reg23:
2935 case DW_OP_reg24:
2936 case DW_OP_reg25:
2937 case DW_OP_reg26:
2938 case DW_OP_reg27:
2939 case DW_OP_reg28:
2940 case DW_OP_reg29:
2941 case DW_OP_reg30:
2942 case DW_OP_reg31:
2943 cfa->reg = op - DW_OP_reg0;
2944 break;
2945 case DW_OP_regx:
2946 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2947 break;
2948 case DW_OP_breg0:
2949 case DW_OP_breg1:
2950 case DW_OP_breg2:
2951 case DW_OP_breg3:
2952 case DW_OP_breg4:
2953 case DW_OP_breg5:
2954 case DW_OP_breg6:
2955 case DW_OP_breg7:
2956 case DW_OP_breg8:
2957 case DW_OP_breg9:
2958 case DW_OP_breg10:
2959 case DW_OP_breg11:
2960 case DW_OP_breg12:
2961 case DW_OP_breg13:
2962 case DW_OP_breg14:
2963 case DW_OP_breg15:
2964 case DW_OP_breg16:
2965 case DW_OP_breg17:
2966 case DW_OP_breg18:
2967 case DW_OP_breg19:
2968 case DW_OP_breg20:
2969 case DW_OP_breg21:
2970 case DW_OP_breg22:
2971 case DW_OP_breg23:
2972 case DW_OP_breg24:
2973 case DW_OP_breg25:
2974 case DW_OP_breg26:
2975 case DW_OP_breg27:
2976 case DW_OP_breg28:
2977 case DW_OP_breg29:
2978 case DW_OP_breg30:
2979 case DW_OP_breg31:
2980 cfa->reg = op - DW_OP_breg0;
2981 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2982 break;
2983 case DW_OP_bregx:
2984 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2985 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
2986 break;
2987 case DW_OP_deref:
2988 cfa->indirect = 1;
2989 break;
2990 case DW_OP_plus_uconst:
2991 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
2992 break;
2993 default:
2994 internal_error ("DW_LOC_OP %s not implememnted\n",
2995 dwarf_stack_op_name (ptr->dw_loc_opc));
2999 #endif /* .debug_frame support */
3001 /* And now, the support for symbolic debugging information. */
3002 #ifdef DWARF2_DEBUGGING_INFO
3004 static void dwarf2out_init PARAMS ((const char *));
3005 static void dwarf2out_finish PARAMS ((const char *));
3006 static void dwarf2out_define PARAMS ((unsigned int, const char *));
3007 static void dwarf2out_undef PARAMS ((unsigned int, const char *));
3008 static void dwarf2out_start_source_file PARAMS ((unsigned, const char *));
3009 static void dwarf2out_end_source_file PARAMS ((unsigned));
3010 static void dwarf2out_begin_block PARAMS ((unsigned, unsigned));
3011 static void dwarf2out_end_block PARAMS ((unsigned, unsigned));
3012 static bool dwarf2out_ignore_block PARAMS ((tree));
3013 static void dwarf2out_global_decl PARAMS ((tree));
3014 static void dwarf2out_abstract_function PARAMS ((tree));
3016 /* The debug hooks structure. */
3018 struct gcc_debug_hooks dwarf2_debug_hooks =
3020 dwarf2out_init,
3021 dwarf2out_finish,
3022 dwarf2out_define,
3023 dwarf2out_undef,
3024 dwarf2out_start_source_file,
3025 dwarf2out_end_source_file,
3026 dwarf2out_begin_block,
3027 dwarf2out_end_block,
3028 dwarf2out_ignore_block,
3029 dwarf2out_source_line,
3030 dwarf2out_begin_prologue,
3031 debug_nothing_int, /* end_prologue */
3032 dwarf2out_end_epilogue,
3033 debug_nothing_tree, /* begin_function */
3034 debug_nothing_int, /* end_function */
3035 dwarf2out_decl, /* function_decl */
3036 dwarf2out_global_decl,
3037 debug_nothing_tree, /* deferred_inline_function */
3038 /* The DWARF 2 backend tries to reduce debugging bloat by not
3039 emitting the abstract description of inline functions until
3040 something tries to reference them. */
3041 dwarf2out_abstract_function, /* outlining_inline_function */
3042 debug_nothing_rtx /* label */
3045 /* NOTE: In the comments in this file, many references are made to
3046 "Debugging Information Entries". This term is abbreviated as `DIE'
3047 throughout the remainder of this file. */
3049 /* An internal representation of the DWARF output is built, and then
3050 walked to generate the DWARF debugging info. The walk of the internal
3051 representation is done after the entire program has been compiled.
3052 The types below are used to describe the internal representation. */
3054 /* Various DIE's use offsets relative to the beginning of the
3055 .debug_info section to refer to each other. */
3057 typedef long int dw_offset;
3059 /* Define typedefs here to avoid circular dependencies. */
3061 typedef struct dw_attr_struct *dw_attr_ref;
3062 typedef struct dw_line_info_struct *dw_line_info_ref;
3063 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3064 typedef struct pubname_struct *pubname_ref;
3065 typedef struct dw_ranges_struct *dw_ranges_ref;
3067 /* Each entry in the line_info_table maintains the file and
3068 line number associated with the label generated for that
3069 entry. The label gives the PC value associated with
3070 the line number entry. */
3072 typedef struct dw_line_info_struct
3074 unsigned long dw_file_num;
3075 unsigned long dw_line_num;
3077 dw_line_info_entry;
3079 /* Line information for functions in separate sections; each one gets its
3080 own sequence. */
3081 typedef struct dw_separate_line_info_struct
3083 unsigned long dw_file_num;
3084 unsigned long dw_line_num;
3085 unsigned long function;
3087 dw_separate_line_info_entry;
3089 /* Each DIE attribute has a field specifying the attribute kind,
3090 a link to the next attribute in the chain, and an attribute value.
3091 Attributes are typically linked below the DIE they modify. */
3093 typedef struct dw_attr_struct
3095 enum dwarf_attribute dw_attr;
3096 dw_attr_ref dw_attr_next;
3097 dw_val_node dw_attr_val;
3099 dw_attr_node;
3101 /* The Debugging Information Entry (DIE) structure */
3103 typedef struct die_struct
3105 enum dwarf_tag die_tag;
3106 char *die_symbol;
3107 dw_attr_ref die_attr;
3108 dw_die_ref die_parent;
3109 dw_die_ref die_child;
3110 dw_die_ref die_sib;
3111 dw_offset die_offset;
3112 unsigned long die_abbrev;
3113 int die_mark;
3115 die_node;
3117 /* The pubname structure */
3119 typedef struct pubname_struct
3121 dw_die_ref die;
3122 char *name;
3124 pubname_entry;
3126 struct dw_ranges_struct
3128 int block_num;
3131 /* The limbo die list structure. */
3132 typedef struct limbo_die_struct
3134 dw_die_ref die;
3135 struct limbo_die_struct *next;
3137 limbo_die_node;
3139 /* How to start an assembler comment. */
3140 #ifndef ASM_COMMENT_START
3141 #define ASM_COMMENT_START ";#"
3142 #endif
3144 /* Define a macro which returns non-zero for a TYPE_DECL which was
3145 implicitly generated for a tagged type.
3147 Note that unlike the gcc front end (which generates a NULL named
3148 TYPE_DECL node for each complete tagged type, each array type, and
3149 each function type node created) the g++ front end generates a
3150 _named_ TYPE_DECL node for each tagged type node created.
3151 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3152 generate a DW_TAG_typedef DIE for them. */
3154 #define TYPE_DECL_IS_STUB(decl) \
3155 (DECL_NAME (decl) == NULL_TREE \
3156 || (DECL_ARTIFICIAL (decl) \
3157 && is_tagged_type (TREE_TYPE (decl)) \
3158 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3159 /* This is necessary for stub decls that \
3160 appear in nested inline functions. */ \
3161 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3162 && (decl_ultimate_origin (decl) \
3163 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3165 /* Information concerning the compilation unit's programming
3166 language, and compiler version. */
3168 extern int flag_traditional;
3170 /* Fixed size portion of the DWARF compilation unit header. */
3171 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3173 /* Fixed size portion of debugging line information prolog. */
3174 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3176 /* Fixed size portion of public names info. */
3177 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3179 /* Fixed size portion of the address range info. */
3180 #define DWARF_ARANGES_HEADER_SIZE \
3181 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3182 - DWARF_OFFSET_SIZE)
3184 /* Size of padding portion in the address range info. It must be
3185 aligned to twice the pointer size. */
3186 #define DWARF_ARANGES_PAD_SIZE \
3187 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3188 - (2 * DWARF_OFFSET_SIZE + 4))
3190 /* Use assembler line directives if available. */
3191 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3192 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3193 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3194 #else
3195 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3196 #endif
3197 #endif
3199 /* Define the architecture-dependent minimum instruction length (in bytes).
3200 In this implementation of DWARF, this field is used for information
3201 purposes only. Since GCC generates assembly language, we have
3202 no a priori knowledge of how many instruction bytes are generated
3203 for each source line, and therefore can use only the DW_LNE_set_address
3204 and DW_LNS_fixed_advance_pc line information commands. */
3206 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3207 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3208 #endif
3210 /* Minimum line offset in a special line info. opcode.
3211 This value was chosen to give a reasonable range of values. */
3212 #define DWARF_LINE_BASE -10
3214 /* First special line opcde - leave room for the standard opcodes. */
3215 #define DWARF_LINE_OPCODE_BASE 10
3217 /* Range of line offsets in a special line info. opcode. */
3218 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3220 /* Flag that indicates the initial value of the is_stmt_start flag.
3221 In the present implementation, we do not mark any lines as
3222 the beginning of a source statement, because that information
3223 is not made available by the GCC front-end. */
3224 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3226 /* This location is used by calc_die_sizes() to keep track
3227 the offset of each DIE within the .debug_info section. */
3228 static unsigned long next_die_offset;
3230 /* Record the root of the DIE's built for the current compilation unit. */
3231 static dw_die_ref comp_unit_die;
3233 /* A list of DIEs with a NULL parent waiting to be relocated. */
3234 static limbo_die_node *limbo_die_list = 0;
3236 /* Structure used by lookup_filename to manage sets of filenames. */
3237 struct file_table
3239 char **table;
3240 unsigned allocated;
3241 unsigned in_use;
3242 unsigned last_lookup_index;
3245 /* Size (in elements) of increments by which we may expand the filename
3246 table. */
3247 #define FILE_TABLE_INCREMENT 64
3249 /* Filenames referenced by this compilation unit. */
3250 static struct file_table file_table;
3252 /* Local pointer to the name of the main input file. Initialized in
3253 dwarf2out_init. */
3254 static const char *primary_filename;
3256 /* A pointer to the base of a table of references to DIE's that describe
3257 declarations. The table is indexed by DECL_UID() which is a unique
3258 number identifying each decl. */
3259 static dw_die_ref *decl_die_table;
3261 /* Number of elements currently allocated for the decl_die_table. */
3262 static unsigned decl_die_table_allocated;
3264 /* Number of elements in decl_die_table currently in use. */
3265 static unsigned decl_die_table_in_use;
3267 /* Size (in elements) of increments by which we may expand the
3268 decl_die_table. */
3269 #define DECL_DIE_TABLE_INCREMENT 256
3271 /* A pointer to the base of a table of references to declaration
3272 scopes. This table is a display which tracks the nesting
3273 of declaration scopes at the current scope and containing
3274 scopes. This table is used to find the proper place to
3275 define type declaration DIE's. */
3276 varray_type decl_scope_table;
3278 /* A pointer to the base of a list of references to DIE's that
3279 are uniquely identified by their tag, presence/absence of
3280 children DIE's, and list of attribute/value pairs. */
3281 static dw_die_ref *abbrev_die_table;
3283 /* Number of elements currently allocated for abbrev_die_table. */
3284 static unsigned abbrev_die_table_allocated;
3286 /* Number of elements in type_die_table currently in use. */
3287 static unsigned abbrev_die_table_in_use;
3289 /* Size (in elements) of increments by which we may expand the
3290 abbrev_die_table. */
3291 #define ABBREV_DIE_TABLE_INCREMENT 256
3293 /* A pointer to the base of a table that contains line information
3294 for each source code line in .text in the compilation unit. */
3295 static dw_line_info_ref line_info_table;
3297 /* Number of elements currently allocated for line_info_table. */
3298 static unsigned line_info_table_allocated;
3300 /* Number of elements in separate_line_info_table currently in use. */
3301 static unsigned separate_line_info_table_in_use;
3303 /* A pointer to the base of a table that contains line information
3304 for each source code line outside of .text in the compilation unit. */
3305 static dw_separate_line_info_ref separate_line_info_table;
3307 /* Number of elements currently allocated for separate_line_info_table. */
3308 static unsigned separate_line_info_table_allocated;
3310 /* Number of elements in line_info_table currently in use. */
3311 static unsigned line_info_table_in_use;
3313 /* Size (in elements) of increments by which we may expand the
3314 line_info_table. */
3315 #define LINE_INFO_TABLE_INCREMENT 1024
3317 /* A pointer to the base of a table that contains a list of publicly
3318 accessible names. */
3319 static pubname_ref pubname_table;
3321 /* Number of elements currently allocated for pubname_table. */
3322 static unsigned pubname_table_allocated;
3324 /* Number of elements in pubname_table currently in use. */
3325 static unsigned pubname_table_in_use;
3327 /* Size (in elements) of increments by which we may expand the
3328 pubname_table. */
3329 #define PUBNAME_TABLE_INCREMENT 64
3331 /* Array of dies for which we should generate .debug_arange info. */
3332 static dw_die_ref *arange_table;
3334 /* Number of elements currently allocated for arange_table. */
3335 static unsigned arange_table_allocated;
3337 /* Number of elements in arange_table currently in use. */
3338 static unsigned arange_table_in_use;
3340 /* Size (in elements) of increments by which we may expand the
3341 arange_table. */
3342 #define ARANGE_TABLE_INCREMENT 64
3344 /* Array of dies for which we should generate .debug_ranges info. */
3345 static dw_ranges_ref ranges_table;
3347 /* Number of elements currently allocated for ranges_table. */
3348 static unsigned ranges_table_allocated;
3350 /* Number of elements in ranges_table currently in use. */
3351 static unsigned ranges_table_in_use;
3353 /* Size (in elements) of increments by which we may expand the
3354 ranges_table. */
3355 #define RANGES_TABLE_INCREMENT 64
3357 /* Whether we have location lists that need outputting */
3358 static unsigned have_location_lists;
3360 /* A pointer to the base of a list of incomplete types which might be
3361 completed at some later time. incomplete_types_list needs to be a VARRAY
3362 because we want to tell the garbage collector about it. If we don't tell
3363 the garbage collector about it, we can garbage collect live data.
3364 Bug 4215.*/
3365 varray_type incomplete_types;
3367 /* Record whether the function being analyzed contains inlined functions. */
3368 static int current_function_has_inlines;
3369 #if 0 && defined (MIPS_DEBUGGING_INFO)
3370 static int comp_unit_has_inlines;
3371 #endif
3373 /* Array of RTXes referenced by the debugging information, which therefore
3374 must be kept around forever. We do this rather than perform GC on
3375 the dwarf info because almost all of the dwarf info lives forever, and
3376 it's easier to support non-GC frontends this way. */
3377 static varray_type used_rtx_varray;
3379 /* Forward declarations for functions defined in this file. */
3381 static int is_pseudo_reg PARAMS ((rtx));
3382 static tree type_main_variant PARAMS ((tree));
3383 static int is_tagged_type PARAMS ((tree));
3384 static const char *dwarf_tag_name PARAMS ((unsigned));
3385 static const char *dwarf_attr_name PARAMS ((unsigned));
3386 static const char *dwarf_form_name PARAMS ((unsigned));
3387 #if 0
3388 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3389 #endif
3390 static tree decl_ultimate_origin PARAMS ((tree));
3391 static tree block_ultimate_origin PARAMS ((tree));
3392 static tree decl_class_context PARAMS ((tree));
3393 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3394 static void add_AT_flag PARAMS ((dw_die_ref,
3395 enum dwarf_attribute,
3396 unsigned));
3397 static void add_AT_int PARAMS ((dw_die_ref,
3398 enum dwarf_attribute, long));
3399 static void add_AT_unsigned PARAMS ((dw_die_ref,
3400 enum dwarf_attribute,
3401 unsigned long));
3402 static void add_AT_long_long PARAMS ((dw_die_ref,
3403 enum dwarf_attribute,
3404 unsigned long,
3405 unsigned long));
3406 static void add_AT_float PARAMS ((dw_die_ref,
3407 enum dwarf_attribute,
3408 unsigned, long *));
3409 static void add_AT_string PARAMS ((dw_die_ref,
3410 enum dwarf_attribute,
3411 const char *));
3412 static void add_AT_die_ref PARAMS ((dw_die_ref,
3413 enum dwarf_attribute,
3414 dw_die_ref));
3415 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3416 enum dwarf_attribute,
3417 unsigned));
3418 static void add_AT_loc PARAMS ((dw_die_ref,
3419 enum dwarf_attribute,
3420 dw_loc_descr_ref));
3421 static void add_AT_loc_list PARAMS ((dw_die_ref,
3422 enum dwarf_attribute,
3423 dw_loc_list_ref));
3424 static void add_AT_addr PARAMS ((dw_die_ref,
3425 enum dwarf_attribute,
3426 rtx));
3427 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3428 enum dwarf_attribute,
3429 const char *));
3430 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3431 enum dwarf_attribute,
3432 const char *));
3433 static void add_AT_offset PARAMS ((dw_die_ref,
3434 enum dwarf_attribute,
3435 unsigned long));
3436 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3437 enum dwarf_attribute));
3438 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3439 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3440 static const char *get_AT_string PARAMS ((dw_die_ref,
3441 enum dwarf_attribute));
3442 static int get_AT_flag PARAMS ((dw_die_ref,
3443 enum dwarf_attribute));
3444 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3445 enum dwarf_attribute));
3446 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3447 enum dwarf_attribute));
3448 static int is_c_family PARAMS ((void));
3449 static int is_java PARAMS ((void));
3450 static int is_fortran PARAMS ((void));
3451 static void remove_AT PARAMS ((dw_die_ref,
3452 enum dwarf_attribute));
3453 static void remove_children PARAMS ((dw_die_ref));
3454 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3455 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3456 static dw_die_ref lookup_type_die PARAMS ((tree));
3457 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3458 static dw_die_ref lookup_decl_die PARAMS ((tree));
3459 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3460 static void print_spaces PARAMS ((FILE *));
3461 static void print_die PARAMS ((dw_die_ref, FILE *));
3462 static void print_dwarf_line_table PARAMS ((FILE *));
3463 static void reverse_die_lists PARAMS ((dw_die_ref));
3464 static void reverse_all_dies PARAMS ((dw_die_ref));
3465 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3466 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3467 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3468 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3469 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3470 static void compute_section_prefix PARAMS ((dw_die_ref));
3471 static int is_type_die PARAMS ((dw_die_ref));
3472 static int is_comdat_die PARAMS ((dw_die_ref));
3473 static int is_symbol_die PARAMS ((dw_die_ref));
3474 static void assign_symbol_names PARAMS ((dw_die_ref));
3475 static void break_out_includes PARAMS ((dw_die_ref));
3476 static void add_sibling_attributes PARAMS ((dw_die_ref));
3477 static void build_abbrev_table PARAMS ((dw_die_ref));
3478 static void output_location_lists PARAMS ((dw_die_ref));
3479 static unsigned long size_of_string PARAMS ((const char *));
3480 static int constant_size PARAMS ((long unsigned));
3481 static unsigned long size_of_die PARAMS ((dw_die_ref));
3482 static void calc_die_sizes PARAMS ((dw_die_ref));
3483 static void mark_dies PARAMS ((dw_die_ref));
3484 static void unmark_dies PARAMS ((dw_die_ref));
3485 static unsigned long size_of_pubnames PARAMS ((void));
3486 static unsigned long size_of_aranges PARAMS ((void));
3487 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3488 static void output_value_format PARAMS ((dw_attr_ref));
3489 static void output_abbrev_section PARAMS ((void));
3490 static void output_die_symbol PARAMS ((dw_die_ref));
3491 static void output_die PARAMS ((dw_die_ref));
3492 static void output_compilation_unit_header PARAMS ((void));
3493 static void output_comp_unit PARAMS ((dw_die_ref));
3494 static const char *dwarf2_name PARAMS ((tree, int));
3495 static void add_pubname PARAMS ((tree, dw_die_ref));
3496 static void output_pubnames PARAMS ((void));
3497 static void add_arange PARAMS ((tree, dw_die_ref));
3498 static void output_aranges PARAMS ((void));
3499 static unsigned int add_ranges PARAMS ((tree));
3500 static void output_ranges PARAMS ((void));
3501 static void output_line_info PARAMS ((void));
3502 static void output_file_names PARAMS ((void));
3503 static dw_die_ref base_type_die PARAMS ((tree));
3504 static tree root_type PARAMS ((tree));
3505 static int is_base_type PARAMS ((tree));
3506 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3507 static int type_is_enum PARAMS ((tree));
3508 static unsigned int reg_number PARAMS ((rtx));
3509 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3510 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3511 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3512 static int is_based_loc PARAMS ((rtx));
3513 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3514 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3515 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3516 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3517 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3518 static tree field_type PARAMS ((tree));
3519 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3520 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3521 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3522 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3523 static void add_AT_location_description PARAMS ((dw_die_ref,
3524 enum dwarf_attribute, rtx));
3525 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3526 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3527 static rtx rtl_for_decl_location PARAMS ((tree));
3528 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3529 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3530 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3531 static void add_bound_info PARAMS ((dw_die_ref,
3532 enum dwarf_attribute, tree));
3533 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3534 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3535 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3536 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3537 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3538 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3539 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3540 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3541 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3542 static void push_decl_scope PARAMS ((tree));
3543 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3544 static void pop_decl_scope PARAMS ((void));
3545 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3546 dw_die_ref));
3547 static const char *type_tag PARAMS ((tree));
3548 static tree member_declared_type PARAMS ((tree));
3549 #if 0
3550 static const char *decl_start_label PARAMS ((tree));
3551 #endif
3552 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3553 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3554 #if 0
3555 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3556 #endif
3557 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3558 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3559 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3560 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3561 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3562 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3563 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3564 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3565 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3566 static void gen_label_die PARAMS ((tree, dw_die_ref));
3567 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3568 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3569 static void gen_field_die PARAMS ((tree, dw_die_ref));
3570 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3571 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3572 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3573 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3574 static void gen_member_die PARAMS ((tree, dw_die_ref));
3575 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3576 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3577 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3578 static void gen_type_die PARAMS ((tree, dw_die_ref));
3579 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3580 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3581 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3582 static int is_redundant_typedef PARAMS ((tree));
3583 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3584 static unsigned lookup_filename PARAMS ((const char *));
3585 static void init_file_table PARAMS ((void));
3586 static void add_incomplete_type PARAMS ((tree));
3587 static void retry_incomplete_types PARAMS ((void));
3588 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3589 static rtx save_rtx PARAMS ((rtx));
3590 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3591 static int file_info_cmp PARAMS ((const void *, const void *));
3592 static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
3593 const char *, const char *,
3594 const char *, unsigned));
3595 static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3596 dw_loc_descr_ref,
3597 const char *, const char *, const char *));
3598 static void output_loc_list PARAMS ((dw_loc_list_ref));
3599 static char *gen_internal_sym PARAMS ((const char *));
3601 /* Section names used to hold DWARF debugging information. */
3602 #ifndef DEBUG_INFO_SECTION
3603 #define DEBUG_INFO_SECTION ".debug_info"
3604 #endif
3605 #ifndef DEBUG_ABBREV_SECTION
3606 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3607 #endif
3608 #ifndef DEBUG_ARANGES_SECTION
3609 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3610 #endif
3611 #ifndef DEBUG_MACINFO_SECTION
3612 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3613 #endif
3614 #ifndef DEBUG_LINE_SECTION
3615 #define DEBUG_LINE_SECTION ".debug_line"
3616 #endif
3617 #ifndef DEBUG_LOC_SECTION
3618 #define DEBUG_LOC_SECTION ".debug_loc"
3619 #endif
3620 #ifndef DEBUG_PUBNAMES_SECTION
3621 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3622 #endif
3623 #ifndef DEBUG_STR_SECTION
3624 #define DEBUG_STR_SECTION ".debug_str"
3625 #endif
3626 #ifndef DEBUG_RANGES_SECTION
3627 #define DEBUG_RANGES_SECTION ".debug_ranges"
3628 #endif
3630 /* Standard ELF section names for compiled code and data. */
3631 #ifndef TEXT_SECTION_NAME
3632 #define TEXT_SECTION_NAME ".text"
3633 #endif
3635 /* Labels we insert at beginning sections we can reference instead of
3636 the section names themselves. */
3638 #ifndef TEXT_SECTION_LABEL
3639 #define TEXT_SECTION_LABEL "Ltext"
3640 #endif
3641 #ifndef DEBUG_LINE_SECTION_LABEL
3642 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3643 #endif
3644 #ifndef DEBUG_INFO_SECTION_LABEL
3645 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3646 #endif
3647 #ifndef DEBUG_ABBREV_SECTION_LABEL
3648 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3649 #endif
3650 #ifndef DEBUG_LOC_SECTION_LABEL
3651 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3652 #endif
3653 #ifndef DEBUG_MACINFO_SECTION_LABEL
3654 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3655 #endif
3657 /* Definitions of defaults for formats and names of various special
3658 (artificial) labels which may be generated within this file (when the -g
3659 options is used and DWARF_DEBUGGING_INFO is in effect.
3660 If necessary, these may be overridden from within the tm.h file, but
3661 typically, overriding these defaults is unnecessary. */
3663 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3664 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3665 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3666 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3667 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3668 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3669 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3670 #ifndef TEXT_END_LABEL
3671 #define TEXT_END_LABEL "Letext"
3672 #endif
3673 #ifndef DATA_END_LABEL
3674 #define DATA_END_LABEL "Ledata"
3675 #endif
3676 #ifndef BSS_END_LABEL
3677 #define BSS_END_LABEL "Lebss"
3678 #endif
3679 #ifndef BLOCK_BEGIN_LABEL
3680 #define BLOCK_BEGIN_LABEL "LBB"
3681 #endif
3682 #ifndef BLOCK_END_LABEL
3683 #define BLOCK_END_LABEL "LBE"
3684 #endif
3685 #ifndef BODY_BEGIN_LABEL
3686 #define BODY_BEGIN_LABEL "Lbb"
3687 #endif
3688 #ifndef BODY_END_LABEL
3689 #define BODY_END_LABEL "Lbe"
3690 #endif
3691 #ifndef LINE_CODE_LABEL
3692 #define LINE_CODE_LABEL "LM"
3693 #endif
3694 #ifndef SEPARATE_LINE_CODE_LABEL
3695 #define SEPARATE_LINE_CODE_LABEL "LSM"
3696 #endif
3698 /* We allow a language front-end to designate a function that is to be
3699 called to "demangle" any name before it it put into a DIE. */
3701 static const char *(*demangle_name_func) PARAMS ((const char *));
3703 void
3704 dwarf2out_set_demangle_name_func (func)
3705 const char *(*func) PARAMS ((const char *));
3707 demangle_name_func = func;
3710 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3711 that means adding it to used_rtx_varray. If not, that means making
3712 a copy on the permanent_obstack. */
3714 static rtx
3715 save_rtx (orig)
3716 register rtx orig;
3718 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3720 return orig;
3723 /* Test if rtl node points to a pseudo register. */
3725 static inline int
3726 is_pseudo_reg (rtl)
3727 register rtx rtl;
3729 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3730 || (GET_CODE (rtl) == SUBREG
3731 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3734 /* Return a reference to a type, with its const and volatile qualifiers
3735 removed. */
3737 static inline tree
3738 type_main_variant (type)
3739 register tree type;
3741 type = TYPE_MAIN_VARIANT (type);
3743 /* There really should be only one main variant among any group of variants
3744 of a given type (and all of the MAIN_VARIANT values for all members of
3745 the group should point to that one type) but sometimes the C front-end
3746 messes this up for array types, so we work around that bug here. */
3748 if (TREE_CODE (type) == ARRAY_TYPE)
3749 while (type != TYPE_MAIN_VARIANT (type))
3750 type = TYPE_MAIN_VARIANT (type);
3752 return type;
3755 /* Return non-zero if the given type node represents a tagged type. */
3757 static inline int
3758 is_tagged_type (type)
3759 register tree type;
3761 register enum tree_code code = TREE_CODE (type);
3763 return (code == RECORD_TYPE || code == UNION_TYPE
3764 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3767 /* Convert a DIE tag into its string name. */
3769 static const char *
3770 dwarf_tag_name (tag)
3771 register unsigned tag;
3773 switch (tag)
3775 case DW_TAG_padding:
3776 return "DW_TAG_padding";
3777 case DW_TAG_array_type:
3778 return "DW_TAG_array_type";
3779 case DW_TAG_class_type:
3780 return "DW_TAG_class_type";
3781 case DW_TAG_entry_point:
3782 return "DW_TAG_entry_point";
3783 case DW_TAG_enumeration_type:
3784 return "DW_TAG_enumeration_type";
3785 case DW_TAG_formal_parameter:
3786 return "DW_TAG_formal_parameter";
3787 case DW_TAG_imported_declaration:
3788 return "DW_TAG_imported_declaration";
3789 case DW_TAG_label:
3790 return "DW_TAG_label";
3791 case DW_TAG_lexical_block:
3792 return "DW_TAG_lexical_block";
3793 case DW_TAG_member:
3794 return "DW_TAG_member";
3795 case DW_TAG_pointer_type:
3796 return "DW_TAG_pointer_type";
3797 case DW_TAG_reference_type:
3798 return "DW_TAG_reference_type";
3799 case DW_TAG_compile_unit:
3800 return "DW_TAG_compile_unit";
3801 case DW_TAG_string_type:
3802 return "DW_TAG_string_type";
3803 case DW_TAG_structure_type:
3804 return "DW_TAG_structure_type";
3805 case DW_TAG_subroutine_type:
3806 return "DW_TAG_subroutine_type";
3807 case DW_TAG_typedef:
3808 return "DW_TAG_typedef";
3809 case DW_TAG_union_type:
3810 return "DW_TAG_union_type";
3811 case DW_TAG_unspecified_parameters:
3812 return "DW_TAG_unspecified_parameters";
3813 case DW_TAG_variant:
3814 return "DW_TAG_variant";
3815 case DW_TAG_common_block:
3816 return "DW_TAG_common_block";
3817 case DW_TAG_common_inclusion:
3818 return "DW_TAG_common_inclusion";
3819 case DW_TAG_inheritance:
3820 return "DW_TAG_inheritance";
3821 case DW_TAG_inlined_subroutine:
3822 return "DW_TAG_inlined_subroutine";
3823 case DW_TAG_module:
3824 return "DW_TAG_module";
3825 case DW_TAG_ptr_to_member_type:
3826 return "DW_TAG_ptr_to_member_type";
3827 case DW_TAG_set_type:
3828 return "DW_TAG_set_type";
3829 case DW_TAG_subrange_type:
3830 return "DW_TAG_subrange_type";
3831 case DW_TAG_with_stmt:
3832 return "DW_TAG_with_stmt";
3833 case DW_TAG_access_declaration:
3834 return "DW_TAG_access_declaration";
3835 case DW_TAG_base_type:
3836 return "DW_TAG_base_type";
3837 case DW_TAG_catch_block:
3838 return "DW_TAG_catch_block";
3839 case DW_TAG_const_type:
3840 return "DW_TAG_const_type";
3841 case DW_TAG_constant:
3842 return "DW_TAG_constant";
3843 case DW_TAG_enumerator:
3844 return "DW_TAG_enumerator";
3845 case DW_TAG_file_type:
3846 return "DW_TAG_file_type";
3847 case DW_TAG_friend:
3848 return "DW_TAG_friend";
3849 case DW_TAG_namelist:
3850 return "DW_TAG_namelist";
3851 case DW_TAG_namelist_item:
3852 return "DW_TAG_namelist_item";
3853 case DW_TAG_packed_type:
3854 return "DW_TAG_packed_type";
3855 case DW_TAG_subprogram:
3856 return "DW_TAG_subprogram";
3857 case DW_TAG_template_type_param:
3858 return "DW_TAG_template_type_param";
3859 case DW_TAG_template_value_param:
3860 return "DW_TAG_template_value_param";
3861 case DW_TAG_thrown_type:
3862 return "DW_TAG_thrown_type";
3863 case DW_TAG_try_block:
3864 return "DW_TAG_try_block";
3865 case DW_TAG_variant_part:
3866 return "DW_TAG_variant_part";
3867 case DW_TAG_variable:
3868 return "DW_TAG_variable";
3869 case DW_TAG_volatile_type:
3870 return "DW_TAG_volatile_type";
3871 case DW_TAG_MIPS_loop:
3872 return "DW_TAG_MIPS_loop";
3873 case DW_TAG_format_label:
3874 return "DW_TAG_format_label";
3875 case DW_TAG_function_template:
3876 return "DW_TAG_function_template";
3877 case DW_TAG_class_template:
3878 return "DW_TAG_class_template";
3879 case DW_TAG_GNU_BINCL:
3880 return "DW_TAG_GNU_BINCL";
3881 case DW_TAG_GNU_EINCL:
3882 return "DW_TAG_GNU_EINCL";
3883 default:
3884 return "DW_TAG_<unknown>";
3888 /* Convert a DWARF attribute code into its string name. */
3890 static const char *
3891 dwarf_attr_name (attr)
3892 register unsigned attr;
3894 switch (attr)
3896 case DW_AT_sibling:
3897 return "DW_AT_sibling";
3898 case DW_AT_location:
3899 return "DW_AT_location";
3900 case DW_AT_name:
3901 return "DW_AT_name";
3902 case DW_AT_ordering:
3903 return "DW_AT_ordering";
3904 case DW_AT_subscr_data:
3905 return "DW_AT_subscr_data";
3906 case DW_AT_byte_size:
3907 return "DW_AT_byte_size";
3908 case DW_AT_bit_offset:
3909 return "DW_AT_bit_offset";
3910 case DW_AT_bit_size:
3911 return "DW_AT_bit_size";
3912 case DW_AT_element_list:
3913 return "DW_AT_element_list";
3914 case DW_AT_stmt_list:
3915 return "DW_AT_stmt_list";
3916 case DW_AT_low_pc:
3917 return "DW_AT_low_pc";
3918 case DW_AT_high_pc:
3919 return "DW_AT_high_pc";
3920 case DW_AT_language:
3921 return "DW_AT_language";
3922 case DW_AT_member:
3923 return "DW_AT_member";
3924 case DW_AT_discr:
3925 return "DW_AT_discr";
3926 case DW_AT_discr_value:
3927 return "DW_AT_discr_value";
3928 case DW_AT_visibility:
3929 return "DW_AT_visibility";
3930 case DW_AT_import:
3931 return "DW_AT_import";
3932 case DW_AT_string_length:
3933 return "DW_AT_string_length";
3934 case DW_AT_common_reference:
3935 return "DW_AT_common_reference";
3936 case DW_AT_comp_dir:
3937 return "DW_AT_comp_dir";
3938 case DW_AT_const_value:
3939 return "DW_AT_const_value";
3940 case DW_AT_containing_type:
3941 return "DW_AT_containing_type";
3942 case DW_AT_default_value:
3943 return "DW_AT_default_value";
3944 case DW_AT_inline:
3945 return "DW_AT_inline";
3946 case DW_AT_is_optional:
3947 return "DW_AT_is_optional";
3948 case DW_AT_lower_bound:
3949 return "DW_AT_lower_bound";
3950 case DW_AT_producer:
3951 return "DW_AT_producer";
3952 case DW_AT_prototyped:
3953 return "DW_AT_prototyped";
3954 case DW_AT_return_addr:
3955 return "DW_AT_return_addr";
3956 case DW_AT_start_scope:
3957 return "DW_AT_start_scope";
3958 case DW_AT_stride_size:
3959 return "DW_AT_stride_size";
3960 case DW_AT_upper_bound:
3961 return "DW_AT_upper_bound";
3962 case DW_AT_abstract_origin:
3963 return "DW_AT_abstract_origin";
3964 case DW_AT_accessibility:
3965 return "DW_AT_accessibility";
3966 case DW_AT_address_class:
3967 return "DW_AT_address_class";
3968 case DW_AT_artificial:
3969 return "DW_AT_artificial";
3970 case DW_AT_base_types:
3971 return "DW_AT_base_types";
3972 case DW_AT_calling_convention:
3973 return "DW_AT_calling_convention";
3974 case DW_AT_count:
3975 return "DW_AT_count";
3976 case DW_AT_data_member_location:
3977 return "DW_AT_data_member_location";
3978 case DW_AT_decl_column:
3979 return "DW_AT_decl_column";
3980 case DW_AT_decl_file:
3981 return "DW_AT_decl_file";
3982 case DW_AT_decl_line:
3983 return "DW_AT_decl_line";
3984 case DW_AT_declaration:
3985 return "DW_AT_declaration";
3986 case DW_AT_discr_list:
3987 return "DW_AT_discr_list";
3988 case DW_AT_encoding:
3989 return "DW_AT_encoding";
3990 case DW_AT_external:
3991 return "DW_AT_external";
3992 case DW_AT_frame_base:
3993 return "DW_AT_frame_base";
3994 case DW_AT_friend:
3995 return "DW_AT_friend";
3996 case DW_AT_identifier_case:
3997 return "DW_AT_identifier_case";
3998 case DW_AT_macro_info:
3999 return "DW_AT_macro_info";
4000 case DW_AT_namelist_items:
4001 return "DW_AT_namelist_items";
4002 case DW_AT_priority:
4003 return "DW_AT_priority";
4004 case DW_AT_segment:
4005 return "DW_AT_segment";
4006 case DW_AT_specification:
4007 return "DW_AT_specification";
4008 case DW_AT_static_link:
4009 return "DW_AT_static_link";
4010 case DW_AT_type:
4011 return "DW_AT_type";
4012 case DW_AT_use_location:
4013 return "DW_AT_use_location";
4014 case DW_AT_variable_parameter:
4015 return "DW_AT_variable_parameter";
4016 case DW_AT_virtuality:
4017 return "DW_AT_virtuality";
4018 case DW_AT_vtable_elem_location:
4019 return "DW_AT_vtable_elem_location";
4021 case DW_AT_allocated:
4022 return "DW_AT_allocated";
4023 case DW_AT_associated:
4024 return "DW_AT_associated";
4025 case DW_AT_data_location:
4026 return "DW_AT_data_location";
4027 case DW_AT_stride:
4028 return "DW_AT_stride";
4029 case DW_AT_entry_pc:
4030 return "DW_AT_entry_pc";
4031 case DW_AT_use_UTF8:
4032 return "DW_AT_use_UTF8";
4033 case DW_AT_extension:
4034 return "DW_AT_extension";
4035 case DW_AT_ranges:
4036 return "DW_AT_ranges";
4037 case DW_AT_trampoline:
4038 return "DW_AT_trampoline";
4039 case DW_AT_call_column:
4040 return "DW_AT_call_column";
4041 case DW_AT_call_file:
4042 return "DW_AT_call_file";
4043 case DW_AT_call_line:
4044 return "DW_AT_call_line";
4046 case DW_AT_MIPS_fde:
4047 return "DW_AT_MIPS_fde";
4048 case DW_AT_MIPS_loop_begin:
4049 return "DW_AT_MIPS_loop_begin";
4050 case DW_AT_MIPS_tail_loop_begin:
4051 return "DW_AT_MIPS_tail_loop_begin";
4052 case DW_AT_MIPS_epilog_begin:
4053 return "DW_AT_MIPS_epilog_begin";
4054 case DW_AT_MIPS_loop_unroll_factor:
4055 return "DW_AT_MIPS_loop_unroll_factor";
4056 case DW_AT_MIPS_software_pipeline_depth:
4057 return "DW_AT_MIPS_software_pipeline_depth";
4058 case DW_AT_MIPS_linkage_name:
4059 return "DW_AT_MIPS_linkage_name";
4060 case DW_AT_MIPS_stride:
4061 return "DW_AT_MIPS_stride";
4062 case DW_AT_MIPS_abstract_name:
4063 return "DW_AT_MIPS_abstract_name";
4064 case DW_AT_MIPS_clone_origin:
4065 return "DW_AT_MIPS_clone_origin";
4066 case DW_AT_MIPS_has_inlines:
4067 return "DW_AT_MIPS_has_inlines";
4069 case DW_AT_sf_names:
4070 return "DW_AT_sf_names";
4071 case DW_AT_src_info:
4072 return "DW_AT_src_info";
4073 case DW_AT_mac_info:
4074 return "DW_AT_mac_info";
4075 case DW_AT_src_coords:
4076 return "DW_AT_src_coords";
4077 case DW_AT_body_begin:
4078 return "DW_AT_body_begin";
4079 case DW_AT_body_end:
4080 return "DW_AT_body_end";
4081 default:
4082 return "DW_AT_<unknown>";
4086 /* Convert a DWARF value form code into its string name. */
4088 static const char *
4089 dwarf_form_name (form)
4090 register unsigned form;
4092 switch (form)
4094 case DW_FORM_addr:
4095 return "DW_FORM_addr";
4096 case DW_FORM_block2:
4097 return "DW_FORM_block2";
4098 case DW_FORM_block4:
4099 return "DW_FORM_block4";
4100 case DW_FORM_data2:
4101 return "DW_FORM_data2";
4102 case DW_FORM_data4:
4103 return "DW_FORM_data4";
4104 case DW_FORM_data8:
4105 return "DW_FORM_data8";
4106 case DW_FORM_string:
4107 return "DW_FORM_string";
4108 case DW_FORM_block:
4109 return "DW_FORM_block";
4110 case DW_FORM_block1:
4111 return "DW_FORM_block1";
4112 case DW_FORM_data1:
4113 return "DW_FORM_data1";
4114 case DW_FORM_flag:
4115 return "DW_FORM_flag";
4116 case DW_FORM_sdata:
4117 return "DW_FORM_sdata";
4118 case DW_FORM_strp:
4119 return "DW_FORM_strp";
4120 case DW_FORM_udata:
4121 return "DW_FORM_udata";
4122 case DW_FORM_ref_addr:
4123 return "DW_FORM_ref_addr";
4124 case DW_FORM_ref1:
4125 return "DW_FORM_ref1";
4126 case DW_FORM_ref2:
4127 return "DW_FORM_ref2";
4128 case DW_FORM_ref4:
4129 return "DW_FORM_ref4";
4130 case DW_FORM_ref8:
4131 return "DW_FORM_ref8";
4132 case DW_FORM_ref_udata:
4133 return "DW_FORM_ref_udata";
4134 case DW_FORM_indirect:
4135 return "DW_FORM_indirect";
4136 default:
4137 return "DW_FORM_<unknown>";
4141 /* Convert a DWARF type code into its string name. */
4143 #if 0
4144 static const char *
4145 dwarf_type_encoding_name (enc)
4146 register unsigned enc;
4148 switch (enc)
4150 case DW_ATE_address:
4151 return "DW_ATE_address";
4152 case DW_ATE_boolean:
4153 return "DW_ATE_boolean";
4154 case DW_ATE_complex_float:
4155 return "DW_ATE_complex_float";
4156 case DW_ATE_float:
4157 return "DW_ATE_float";
4158 case DW_ATE_signed:
4159 return "DW_ATE_signed";
4160 case DW_ATE_signed_char:
4161 return "DW_ATE_signed_char";
4162 case DW_ATE_unsigned:
4163 return "DW_ATE_unsigned";
4164 case DW_ATE_unsigned_char:
4165 return "DW_ATE_unsigned_char";
4166 default:
4167 return "DW_ATE_<unknown>";
4170 #endif
4172 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4173 instance of an inlined instance of a decl which is local to an inline
4174 function, so we have to trace all of the way back through the origin chain
4175 to find out what sort of node actually served as the original seed for the
4176 given block. */
4178 static tree
4179 decl_ultimate_origin (decl)
4180 register tree decl;
4182 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4183 nodes in the function to point to themselves; ignore that if
4184 we're trying to output the abstract instance of this function. */
4185 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4186 return NULL_TREE;
4188 #ifdef ENABLE_CHECKING
4189 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4190 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4191 most distant ancestor, this should never happen. */
4192 abort ();
4193 #endif
4195 return DECL_ABSTRACT_ORIGIN (decl);
4198 /* Determine the "ultimate origin" of a block. The block may be an inlined
4199 instance of an inlined instance of a block which is local to an inline
4200 function, so we have to trace all of the way back through the origin chain
4201 to find out what sort of node actually served as the original seed for the
4202 given block. */
4204 static tree
4205 block_ultimate_origin (block)
4206 register tree block;
4208 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4210 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4211 nodes in the function to point to themselves; ignore that if
4212 we're trying to output the abstract instance of this function. */
4213 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4214 return NULL_TREE;
4216 if (immediate_origin == NULL_TREE)
4217 return NULL_TREE;
4218 else
4220 register tree ret_val;
4221 register tree lookahead = immediate_origin;
4225 ret_val = lookahead;
4226 lookahead = (TREE_CODE (ret_val) == BLOCK)
4227 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4228 : NULL;
4230 while (lookahead != NULL && lookahead != ret_val);
4232 return ret_val;
4236 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4237 of a virtual function may refer to a base class, so we check the 'this'
4238 parameter. */
4240 static tree
4241 decl_class_context (decl)
4242 tree decl;
4244 tree context = NULL_TREE;
4246 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4247 context = DECL_CONTEXT (decl);
4248 else
4249 context = TYPE_MAIN_VARIANT
4250 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4252 if (context && !TYPE_P (context))
4253 context = NULL_TREE;
4255 return context;
4258 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4259 addition order, and correct that in reverse_all_dies. */
4261 static inline void
4262 add_dwarf_attr (die, attr)
4263 register dw_die_ref die;
4264 register dw_attr_ref attr;
4266 if (die != NULL && attr != NULL)
4268 attr->dw_attr_next = die->die_attr;
4269 die->die_attr = attr;
4273 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4274 static inline dw_val_class
4275 AT_class (a)
4276 dw_attr_ref a;
4278 return a->dw_attr_val.val_class;
4281 /* Add a flag value attribute to a DIE. */
4283 static inline void
4284 add_AT_flag (die, attr_kind, flag)
4285 register dw_die_ref die;
4286 register enum dwarf_attribute attr_kind;
4287 register unsigned flag;
4289 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4291 attr->dw_attr_next = NULL;
4292 attr->dw_attr = attr_kind;
4293 attr->dw_attr_val.val_class = dw_val_class_flag;
4294 attr->dw_attr_val.v.val_flag = flag;
4295 add_dwarf_attr (die, attr);
4298 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4299 static inline unsigned
4300 AT_flag (a)
4301 register dw_attr_ref a;
4303 if (a && AT_class (a) == dw_val_class_flag)
4304 return a->dw_attr_val.v.val_flag;
4306 abort ();
4309 /* Add a signed integer attribute value to a DIE. */
4311 static inline void
4312 add_AT_int (die, attr_kind, int_val)
4313 register dw_die_ref die;
4314 register enum dwarf_attribute attr_kind;
4315 register long int int_val;
4317 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4319 attr->dw_attr_next = NULL;
4320 attr->dw_attr = attr_kind;
4321 attr->dw_attr_val.val_class = dw_val_class_const;
4322 attr->dw_attr_val.v.val_int = int_val;
4323 add_dwarf_attr (die, attr);
4326 static inline long int AT_int PARAMS ((dw_attr_ref));
4327 static inline long int
4328 AT_int (a)
4329 register dw_attr_ref a;
4331 if (a && AT_class (a) == dw_val_class_const)
4332 return a->dw_attr_val.v.val_int;
4334 abort ();
4337 /* Add an unsigned integer attribute value to a DIE. */
4339 static inline void
4340 add_AT_unsigned (die, attr_kind, unsigned_val)
4341 register dw_die_ref die;
4342 register enum dwarf_attribute attr_kind;
4343 register unsigned long unsigned_val;
4345 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4347 attr->dw_attr_next = NULL;
4348 attr->dw_attr = attr_kind;
4349 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4350 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4351 add_dwarf_attr (die, attr);
4354 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4355 static inline unsigned long
4356 AT_unsigned (a)
4357 register dw_attr_ref a;
4359 if (a && AT_class (a) == dw_val_class_unsigned_const)
4360 return a->dw_attr_val.v.val_unsigned;
4362 abort ();
4365 /* Add an unsigned double integer attribute value to a DIE. */
4367 static inline void
4368 add_AT_long_long (die, attr_kind, val_hi, val_low)
4369 register dw_die_ref die;
4370 register enum dwarf_attribute attr_kind;
4371 register unsigned long val_hi;
4372 register unsigned long val_low;
4374 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4376 attr->dw_attr_next = NULL;
4377 attr->dw_attr = attr_kind;
4378 attr->dw_attr_val.val_class = dw_val_class_long_long;
4379 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4380 attr->dw_attr_val.v.val_long_long.low = val_low;
4381 add_dwarf_attr (die, attr);
4384 /* Add a floating point attribute value to a DIE and return it. */
4386 static inline void
4387 add_AT_float (die, attr_kind, length, array)
4388 register dw_die_ref die;
4389 register enum dwarf_attribute attr_kind;
4390 register unsigned length;
4391 register long *array;
4393 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4395 attr->dw_attr_next = NULL;
4396 attr->dw_attr = attr_kind;
4397 attr->dw_attr_val.val_class = dw_val_class_float;
4398 attr->dw_attr_val.v.val_float.length = length;
4399 attr->dw_attr_val.v.val_float.array = array;
4400 add_dwarf_attr (die, attr);
4403 /* Add a string attribute value to a DIE. */
4405 static inline void
4406 add_AT_string (die, attr_kind, str)
4407 register dw_die_ref die;
4408 register enum dwarf_attribute attr_kind;
4409 register const char *str;
4411 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4413 attr->dw_attr_next = NULL;
4414 attr->dw_attr = attr_kind;
4415 attr->dw_attr_val.val_class = dw_val_class_str;
4416 attr->dw_attr_val.v.val_str = xstrdup (str);
4417 add_dwarf_attr (die, attr);
4420 static inline const char *AT_string PARAMS ((dw_attr_ref));
4421 static inline const char *
4422 AT_string (a)
4423 register dw_attr_ref a;
4425 if (a && AT_class (a) == dw_val_class_str)
4426 return a->dw_attr_val.v.val_str;
4428 abort ();
4431 /* Add a DIE reference attribute value to a DIE. */
4433 static inline void
4434 add_AT_die_ref (die, attr_kind, targ_die)
4435 register dw_die_ref die;
4436 register enum dwarf_attribute attr_kind;
4437 register dw_die_ref targ_die;
4439 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4441 attr->dw_attr_next = NULL;
4442 attr->dw_attr = attr_kind;
4443 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4444 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4445 attr->dw_attr_val.v.val_die_ref.external = 0;
4446 add_dwarf_attr (die, attr);
4449 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4450 static inline dw_die_ref
4451 AT_ref (a)
4452 register dw_attr_ref a;
4454 if (a && AT_class (a) == dw_val_class_die_ref)
4455 return a->dw_attr_val.v.val_die_ref.die;
4457 abort ();
4460 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4461 static inline int
4462 AT_ref_external (a)
4463 register dw_attr_ref a;
4465 if (a && AT_class (a) == dw_val_class_die_ref)
4466 return a->dw_attr_val.v.val_die_ref.external;
4468 return 0;
4471 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4472 static inline void
4473 set_AT_ref_external (a, i)
4474 register dw_attr_ref a;
4475 int i;
4477 if (a && AT_class (a) == dw_val_class_die_ref)
4478 a->dw_attr_val.v.val_die_ref.external = i;
4479 else
4480 abort ();
4483 /* Add an FDE reference attribute value to a DIE. */
4485 static inline void
4486 add_AT_fde_ref (die, attr_kind, targ_fde)
4487 register dw_die_ref die;
4488 register enum dwarf_attribute attr_kind;
4489 register unsigned targ_fde;
4491 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4493 attr->dw_attr_next = NULL;
4494 attr->dw_attr = attr_kind;
4495 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4496 attr->dw_attr_val.v.val_fde_index = targ_fde;
4497 add_dwarf_attr (die, attr);
4500 /* Add a location description attribute value to a DIE. */
4502 static inline void
4503 add_AT_loc (die, attr_kind, loc)
4504 register dw_die_ref die;
4505 register enum dwarf_attribute attr_kind;
4506 register dw_loc_descr_ref loc;
4508 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4510 attr->dw_attr_next = NULL;
4511 attr->dw_attr = attr_kind;
4512 attr->dw_attr_val.val_class = dw_val_class_loc;
4513 attr->dw_attr_val.v.val_loc = loc;
4514 add_dwarf_attr (die, attr);
4517 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4518 static inline dw_loc_descr_ref
4519 AT_loc (a)
4520 register dw_attr_ref a;
4522 if (a && AT_class (a) == dw_val_class_loc)
4523 return a->dw_attr_val.v.val_loc;
4525 abort ();
4528 static inline void
4529 add_AT_loc_list (die, attr_kind, loc_list)
4530 register dw_die_ref die;
4531 register enum dwarf_attribute attr_kind;
4532 register dw_loc_list_ref loc_list;
4534 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4536 attr->dw_attr_next = NULL;
4537 attr->dw_attr = attr_kind;
4538 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4539 attr->dw_attr_val.v.val_loc_list = loc_list;
4540 add_dwarf_attr (die, attr);
4541 have_location_lists = 1;
4544 static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
4546 static inline dw_loc_list_ref
4547 AT_loc_list (a)
4548 register dw_attr_ref a;
4550 if (a && AT_class (a) == dw_val_class_loc_list)
4551 return a->dw_attr_val.v.val_loc_list;
4553 abort ();
4556 /* Add an address constant attribute value to a DIE. */
4558 static inline void
4559 add_AT_addr (die, attr_kind, addr)
4560 register dw_die_ref die;
4561 register enum dwarf_attribute attr_kind;
4562 rtx addr;
4564 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4566 attr->dw_attr_next = NULL;
4567 attr->dw_attr = attr_kind;
4568 attr->dw_attr_val.val_class = dw_val_class_addr;
4569 attr->dw_attr_val.v.val_addr = addr;
4570 add_dwarf_attr (die, attr);
4573 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4574 static inline rtx
4575 AT_addr (a)
4576 register dw_attr_ref a;
4578 if (a && AT_class (a) == dw_val_class_addr)
4579 return a->dw_attr_val.v.val_addr;
4581 abort ();
4584 /* Add a label identifier attribute value to a DIE. */
4586 static inline void
4587 add_AT_lbl_id (die, attr_kind, lbl_id)
4588 register dw_die_ref die;
4589 register enum dwarf_attribute attr_kind;
4590 register const char *lbl_id;
4592 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4594 attr->dw_attr_next = NULL;
4595 attr->dw_attr = attr_kind;
4596 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4597 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4598 add_dwarf_attr (die, attr);
4601 /* Add a section offset attribute value to a DIE. */
4603 static inline void
4604 add_AT_lbl_offset (die, attr_kind, label)
4605 register dw_die_ref die;
4606 register enum dwarf_attribute attr_kind;
4607 register const char *label;
4609 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4611 attr->dw_attr_next = NULL;
4612 attr->dw_attr = attr_kind;
4613 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4614 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4615 add_dwarf_attr (die, attr);
4618 /* Add an offset attribute value to a DIE. */
4620 static void
4621 add_AT_offset (die, attr_kind, offset)
4622 register dw_die_ref die;
4623 register enum dwarf_attribute attr_kind;
4624 register unsigned long offset;
4626 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4628 attr->dw_attr_next = NULL;
4629 attr->dw_attr = attr_kind;
4630 attr->dw_attr_val.val_class = dw_val_class_offset;
4631 attr->dw_attr_val.v.val_offset = offset;
4632 add_dwarf_attr (die, attr);
4635 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4636 static inline const char *
4637 AT_lbl (a)
4638 register dw_attr_ref a;
4640 if (a && (AT_class (a) == dw_val_class_lbl_id
4641 || AT_class (a) == dw_val_class_lbl_offset))
4642 return a->dw_attr_val.v.val_lbl_id;
4644 abort ();
4647 /* Get the attribute of type attr_kind. */
4649 static inline dw_attr_ref
4650 get_AT (die, attr_kind)
4651 register dw_die_ref die;
4652 register enum dwarf_attribute attr_kind;
4654 register dw_attr_ref a;
4655 register dw_die_ref spec = NULL;
4657 if (die != NULL)
4659 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4661 if (a->dw_attr == attr_kind)
4662 return a;
4664 if (a->dw_attr == DW_AT_specification
4665 || a->dw_attr == DW_AT_abstract_origin)
4666 spec = AT_ref (a);
4669 if (spec)
4670 return get_AT (spec, attr_kind);
4673 return NULL;
4676 /* Return the "low pc" attribute value, typically associated with
4677 a subprogram DIE. Return null if the "low pc" attribute is
4678 either not prsent, or if it cannot be represented as an
4679 assembler label identifier. */
4681 static inline const char *
4682 get_AT_low_pc (die)
4683 register dw_die_ref die;
4685 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4686 return a ? AT_lbl (a) : NULL;
4689 /* Return the "high pc" attribute value, typically associated with
4690 a subprogram DIE. Return null if the "high pc" attribute is
4691 either not prsent, or if it cannot be represented as an
4692 assembler label identifier. */
4694 static inline const char *
4695 get_AT_hi_pc (die)
4696 register dw_die_ref die;
4698 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4699 return a ? AT_lbl (a) : NULL;
4702 /* Return the value of the string attribute designated by ATTR_KIND, or
4703 NULL if it is not present. */
4705 static inline const char *
4706 get_AT_string (die, attr_kind)
4707 register dw_die_ref die;
4708 register enum dwarf_attribute attr_kind;
4710 register dw_attr_ref a = get_AT (die, attr_kind);
4711 return a ? AT_string (a) : NULL;
4714 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4715 if it is not present. */
4717 static inline int
4718 get_AT_flag (die, attr_kind)
4719 register dw_die_ref die;
4720 register enum dwarf_attribute attr_kind;
4722 register dw_attr_ref a = get_AT (die, attr_kind);
4723 return a ? AT_flag (a) : 0;
4726 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4727 if it is not present. */
4729 static inline unsigned
4730 get_AT_unsigned (die, attr_kind)
4731 register dw_die_ref die;
4732 register enum dwarf_attribute attr_kind;
4734 register dw_attr_ref a = get_AT (die, attr_kind);
4735 return a ? AT_unsigned (a) : 0;
4738 static inline dw_die_ref
4739 get_AT_ref (die, attr_kind)
4740 dw_die_ref die;
4741 register enum dwarf_attribute attr_kind;
4743 register dw_attr_ref a = get_AT (die, attr_kind);
4744 return a ? AT_ref (a) : NULL;
4747 static inline int
4748 is_c_family ()
4750 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4752 return (lang == DW_LANG_C || lang == DW_LANG_C89
4753 || lang == DW_LANG_C_plus_plus);
4756 static inline int
4757 is_fortran ()
4759 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4761 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4764 static inline int
4765 is_java ()
4767 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4769 return (lang == DW_LANG_Java);
4772 /* Free up the memory used by A. */
4774 static inline void free_AT PARAMS ((dw_attr_ref));
4775 static inline void
4776 free_AT (a)
4777 dw_attr_ref a;
4779 switch (AT_class (a))
4781 case dw_val_class_str:
4782 case dw_val_class_lbl_id:
4783 case dw_val_class_lbl_offset:
4784 free (a->dw_attr_val.v.val_str);
4785 break;
4787 case dw_val_class_float:
4788 free (a->dw_attr_val.v.val_float.array);
4789 break;
4791 default:
4792 break;
4795 free (a);
4798 /* Remove the specified attribute if present. */
4800 static void
4801 remove_AT (die, attr_kind)
4802 register dw_die_ref die;
4803 register enum dwarf_attribute attr_kind;
4805 register dw_attr_ref *p;
4806 register dw_attr_ref removed = NULL;
4808 if (die != NULL)
4810 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4811 if ((*p)->dw_attr == attr_kind)
4813 removed = *p;
4814 *p = (*p)->dw_attr_next;
4815 break;
4818 if (removed != 0)
4819 free_AT (removed);
4823 /* Free up the memory used by DIE. */
4825 static inline void free_die PARAMS ((dw_die_ref));
4826 static inline void
4827 free_die (die)
4828 dw_die_ref die;
4830 remove_children (die);
4831 free (die);
4834 /* Discard the children of this DIE. */
4836 static void
4837 remove_children (die)
4838 register dw_die_ref die;
4840 register dw_die_ref child_die = die->die_child;
4842 die->die_child = NULL;
4844 while (child_die != NULL)
4846 register dw_die_ref tmp_die = child_die;
4847 register dw_attr_ref a;
4849 child_die = child_die->die_sib;
4851 for (a = tmp_die->die_attr; a != NULL;)
4853 register dw_attr_ref tmp_a = a;
4855 a = a->dw_attr_next;
4856 free_AT (tmp_a);
4859 free_die (tmp_die);
4863 /* Add a child DIE below its parent. We build the lists up in reverse
4864 addition order, and correct that in reverse_all_dies. */
4866 static inline void
4867 add_child_die (die, child_die)
4868 register dw_die_ref die;
4869 register dw_die_ref child_die;
4871 if (die != NULL && child_die != NULL)
4873 if (die == child_die)
4874 abort ();
4875 child_die->die_parent = die;
4876 child_die->die_sib = die->die_child;
4877 die->die_child = child_die;
4881 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4882 is the specification, to the front of PARENT's list of children. */
4884 static void
4885 splice_child_die (parent, child)
4886 dw_die_ref parent, child;
4888 dw_die_ref *p;
4890 /* We want the declaration DIE from inside the class, not the
4891 specification DIE at toplevel. */
4892 if (child->die_parent != parent)
4894 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4895 if (tmp)
4896 child = tmp;
4899 if (child->die_parent != parent
4900 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4901 abort ();
4903 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4904 if (*p == child)
4906 *p = child->die_sib;
4907 break;
4910 child->die_sib = parent->die_child;
4911 parent->die_child = child;
4914 /* Return a pointer to a newly created DIE node. */
4916 static inline dw_die_ref
4917 new_die (tag_value, parent_die)
4918 register enum dwarf_tag tag_value;
4919 register dw_die_ref parent_die;
4921 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
4923 die->die_tag = tag_value;
4925 if (parent_die != NULL)
4926 add_child_die (parent_die, die);
4927 else
4929 limbo_die_node *limbo_node;
4931 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4932 limbo_node->die = die;
4933 limbo_node->next = limbo_die_list;
4934 limbo_die_list = limbo_node;
4937 return die;
4940 /* Return the DIE associated with the given type specifier. */
4942 static inline dw_die_ref
4943 lookup_type_die (type)
4944 register tree type;
4946 if (TREE_CODE (type) == VECTOR_TYPE)
4947 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4948 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4951 /* Equate a DIE to a given type specifier. */
4953 static inline void
4954 equate_type_number_to_die (type, type_die)
4955 register tree type;
4956 register dw_die_ref type_die;
4958 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4961 /* Return the DIE associated with a given declaration. */
4963 static inline dw_die_ref
4964 lookup_decl_die (decl)
4965 register tree decl;
4967 register unsigned decl_id = DECL_UID (decl);
4969 return (decl_id < decl_die_table_in_use
4970 ? decl_die_table[decl_id] : NULL);
4973 /* Equate a DIE to a particular declaration. */
4975 static void
4976 equate_decl_number_to_die (decl, decl_die)
4977 register tree decl;
4978 register dw_die_ref decl_die;
4980 register unsigned decl_id = DECL_UID (decl);
4981 register unsigned num_allocated;
4983 if (decl_id >= decl_die_table_allocated)
4985 num_allocated
4986 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4987 / DECL_DIE_TABLE_INCREMENT)
4988 * DECL_DIE_TABLE_INCREMENT;
4990 decl_die_table
4991 = (dw_die_ref *) xrealloc (decl_die_table,
4992 sizeof (dw_die_ref) * num_allocated);
4994 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
4995 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4996 decl_die_table_allocated = num_allocated;
4999 if (decl_id >= decl_die_table_in_use)
5000 decl_die_table_in_use = (decl_id + 1);
5002 decl_die_table[decl_id] = decl_die;
5005 /* Keep track of the number of spaces used to indent the
5006 output of the debugging routines that print the structure of
5007 the DIE internal representation. */
5008 static int print_indent;
5010 /* Indent the line the number of spaces given by print_indent. */
5012 static inline void
5013 print_spaces (outfile)
5014 FILE *outfile;
5016 fprintf (outfile, "%*s", print_indent, "");
5019 /* Print the information associated with a given DIE, and its children.
5020 This routine is a debugging aid only. */
5022 static void
5023 print_die (die, outfile)
5024 dw_die_ref die;
5025 FILE *outfile;
5027 register dw_attr_ref a;
5028 register dw_die_ref c;
5030 print_spaces (outfile);
5031 fprintf (outfile, "DIE %4lu: %s\n",
5032 die->die_offset, dwarf_tag_name (die->die_tag));
5033 print_spaces (outfile);
5034 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5035 fprintf (outfile, " offset: %lu\n", die->die_offset);
5037 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5039 print_spaces (outfile);
5040 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5042 switch (AT_class (a))
5044 case dw_val_class_addr:
5045 fprintf (outfile, "address");
5046 break;
5047 case dw_val_class_offset:
5048 fprintf (outfile, "offset");
5049 break;
5050 case dw_val_class_loc:
5051 fprintf (outfile, "location descriptor");
5052 break;
5053 case dw_val_class_loc_list:
5054 fprintf (outfile, "location list -> label:%s",
5055 AT_loc_list (a)->ll_symbol);
5056 break;
5057 case dw_val_class_const:
5058 fprintf (outfile, "%ld", AT_int (a));
5059 break;
5060 case dw_val_class_unsigned_const:
5061 fprintf (outfile, "%lu", AT_unsigned (a));
5062 break;
5063 case dw_val_class_long_long:
5064 fprintf (outfile, "constant (%lu,%lu)",
5065 a->dw_attr_val.v.val_long_long.hi,
5066 a->dw_attr_val.v.val_long_long.low);
5067 break;
5068 case dw_val_class_float:
5069 fprintf (outfile, "floating-point constant");
5070 break;
5071 case dw_val_class_flag:
5072 fprintf (outfile, "%u", AT_flag (a));
5073 break;
5074 case dw_val_class_die_ref:
5075 if (AT_ref (a) != NULL)
5077 if (AT_ref (a)->die_symbol)
5078 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5079 else
5080 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5082 else
5083 fprintf (outfile, "die -> <null>");
5084 break;
5085 case dw_val_class_lbl_id:
5086 case dw_val_class_lbl_offset:
5087 fprintf (outfile, "label: %s", AT_lbl (a));
5088 break;
5089 case dw_val_class_str:
5090 if (AT_string (a) != NULL)
5091 fprintf (outfile, "\"%s\"", AT_string (a));
5092 else
5093 fprintf (outfile, "<null>");
5094 break;
5095 default:
5096 break;
5099 fprintf (outfile, "\n");
5102 if (die->die_child != NULL)
5104 print_indent += 4;
5105 for (c = die->die_child; c != NULL; c = c->die_sib)
5106 print_die (c, outfile);
5108 print_indent -= 4;
5110 if (print_indent == 0)
5111 fprintf (outfile, "\n");
5114 /* Print the contents of the source code line number correspondence table.
5115 This routine is a debugging aid only. */
5117 static void
5118 print_dwarf_line_table (outfile)
5119 FILE *outfile;
5121 register unsigned i;
5122 register dw_line_info_ref line_info;
5124 fprintf (outfile, "\n\nDWARF source line information\n");
5125 for (i = 1; i < line_info_table_in_use; ++i)
5127 line_info = &line_info_table[i];
5128 fprintf (outfile, "%5d: ", i);
5129 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5130 fprintf (outfile, "%6ld", line_info->dw_line_num);
5131 fprintf (outfile, "\n");
5134 fprintf (outfile, "\n\n");
5137 /* Print the information collected for a given DIE. */
5139 void
5140 debug_dwarf_die (die)
5141 dw_die_ref die;
5143 print_die (die, stderr);
5146 /* Print all DWARF information collected for the compilation unit.
5147 This routine is a debugging aid only. */
5149 void
5150 debug_dwarf ()
5152 print_indent = 0;
5153 print_die (comp_unit_die, stderr);
5154 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5155 print_dwarf_line_table (stderr);
5158 /* We build up the lists of children and attributes by pushing new ones
5159 onto the beginning of the list. Reverse the lists for DIE so that
5160 they are in order of addition. */
5162 static void
5163 reverse_die_lists (die)
5164 register dw_die_ref die;
5166 register dw_die_ref c, cp, cn;
5167 register dw_attr_ref a, ap, an;
5169 for (a = die->die_attr, ap = 0; a; a = an)
5171 an = a->dw_attr_next;
5172 a->dw_attr_next = ap;
5173 ap = a;
5175 die->die_attr = ap;
5177 for (c = die->die_child, cp = 0; c; c = cn)
5179 cn = c->die_sib;
5180 c->die_sib = cp;
5181 cp = c;
5183 die->die_child = cp;
5186 /* reverse_die_lists only reverses the single die you pass it. Since
5187 we used to reverse all dies in add_sibling_attributes, which runs
5188 through all the dies, it would reverse all the dies. Now, however,
5189 since we don't call reverse_die_lists in add_sibling_attributes, we
5190 need a routine to recursively reverse all the dies. This is that
5191 routine. */
5193 static void
5194 reverse_all_dies (die)
5195 register dw_die_ref die;
5197 register dw_die_ref c;
5199 reverse_die_lists (die);
5201 for (c = die->die_child; c; c = c->die_sib)
5202 reverse_all_dies (c);
5205 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5206 the CU for the enclosing include file, if any. BINCL_DIE is the
5207 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5208 include file. */
5210 static dw_die_ref
5211 push_new_compile_unit (old_unit, bincl_die)
5212 dw_die_ref old_unit, bincl_die;
5214 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5215 dw_die_ref new_unit = gen_compile_unit_die (filename);
5216 new_unit->die_sib = old_unit;
5217 return new_unit;
5220 /* Close an include-file CU and reopen the enclosing one. */
5222 static dw_die_ref
5223 pop_compile_unit (old_unit)
5224 dw_die_ref old_unit;
5226 dw_die_ref new_unit = old_unit->die_sib;
5227 old_unit->die_sib = NULL;
5228 return new_unit;
5231 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5232 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5234 /* Calculate the checksum of a location expression. */
5236 static inline void
5237 loc_checksum (loc, ctx)
5238 dw_loc_descr_ref loc;
5239 struct md5_ctx *ctx;
5241 PROCESS (loc->dw_loc_opc);
5242 PROCESS (loc->dw_loc_oprnd1);
5243 PROCESS (loc->dw_loc_oprnd2);
5246 /* Calculate the checksum of an attribute. */
5248 static void
5249 attr_checksum (at, ctx)
5250 dw_attr_ref at;
5251 struct md5_ctx *ctx;
5253 dw_loc_descr_ref loc;
5254 rtx r;
5256 PROCESS (at->dw_attr);
5258 /* We don't care about differences in file numbering. */
5259 if (at->dw_attr == DW_AT_decl_file
5260 /* Or that this was compiled with a different compiler snapshot; if
5261 the output is the same, that's what matters. */
5262 || at->dw_attr == DW_AT_producer)
5263 return;
5265 switch (AT_class (at))
5267 case dw_val_class_const:
5268 PROCESS (at->dw_attr_val.v.val_int);
5269 break;
5270 case dw_val_class_unsigned_const:
5271 PROCESS (at->dw_attr_val.v.val_unsigned);
5272 break;
5273 case dw_val_class_long_long:
5274 PROCESS (at->dw_attr_val.v.val_long_long);
5275 break;
5276 case dw_val_class_float:
5277 PROCESS (at->dw_attr_val.v.val_float);
5278 break;
5279 case dw_val_class_flag:
5280 PROCESS (at->dw_attr_val.v.val_flag);
5281 break;
5283 case dw_val_class_str:
5284 PROCESS_STRING (AT_string (at));
5285 break;
5287 case dw_val_class_addr:
5288 r = AT_addr (at);
5289 switch (GET_CODE (r))
5291 case SYMBOL_REF:
5292 PROCESS_STRING (XSTR (r, 0));
5293 break;
5295 default:
5296 abort ();
5298 break;
5300 case dw_val_class_offset:
5301 PROCESS (at->dw_attr_val.v.val_offset);
5302 break;
5304 case dw_val_class_loc:
5305 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5306 loc_checksum (loc, ctx);
5307 break;
5309 case dw_val_class_die_ref:
5310 if (AT_ref (at)->die_offset)
5311 PROCESS (AT_ref (at)->die_offset);
5312 /* FIXME else use target die name or something. */
5314 case dw_val_class_fde_ref:
5315 case dw_val_class_lbl_id:
5316 case dw_val_class_lbl_offset:
5317 break;
5319 default:
5320 break;
5324 /* Calculate the checksum of a DIE. */
5326 static void
5327 die_checksum (die, ctx)
5328 dw_die_ref die;
5329 struct md5_ctx *ctx;
5331 dw_die_ref c;
5332 dw_attr_ref a;
5334 PROCESS (die->die_tag);
5336 for (a = die->die_attr; a; a = a->dw_attr_next)
5337 attr_checksum (a, ctx);
5339 for (c = die->die_child; c; c = c->die_sib)
5340 die_checksum (c, ctx);
5343 #undef PROCESS
5344 #undef PROCESS_STRING
5346 /* The prefix to attach to symbols on DIEs in the current comdat debug
5347 info section. */
5348 static char *comdat_symbol_id;
5350 /* The index of the current symbol within the current comdat CU. */
5351 static unsigned int comdat_symbol_number;
5353 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5354 children, and set comdat_symbol_id accordingly. */
5356 static void
5357 compute_section_prefix (unit_die)
5358 dw_die_ref unit_die;
5360 char *name;
5361 int i;
5362 unsigned char checksum[16];
5363 struct md5_ctx ctx;
5365 md5_init_ctx (&ctx);
5366 die_checksum (unit_die, &ctx);
5367 md5_finish_ctx (&ctx, checksum);
5370 const char *p = lbasename (get_AT_string (unit_die, DW_AT_name));
5371 name = (char *) alloca (strlen (p) + 64);
5372 sprintf (name, "%s.", p);
5375 clean_symbol_name (name);
5378 char *p = name + strlen (name);
5379 for (i = 0; i < 4; ++i)
5381 sprintf (p, "%.2x", checksum[i]);
5382 p += 2;
5386 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5387 comdat_symbol_number = 0;
5390 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5392 static int
5393 is_type_die (die)
5394 dw_die_ref die;
5396 switch (die->die_tag)
5398 case DW_TAG_array_type:
5399 case DW_TAG_class_type:
5400 case DW_TAG_enumeration_type:
5401 case DW_TAG_pointer_type:
5402 case DW_TAG_reference_type:
5403 case DW_TAG_string_type:
5404 case DW_TAG_structure_type:
5405 case DW_TAG_subroutine_type:
5406 case DW_TAG_union_type:
5407 case DW_TAG_ptr_to_member_type:
5408 case DW_TAG_set_type:
5409 case DW_TAG_subrange_type:
5410 case DW_TAG_base_type:
5411 case DW_TAG_const_type:
5412 case DW_TAG_file_type:
5413 case DW_TAG_packed_type:
5414 case DW_TAG_volatile_type:
5415 return 1;
5416 default:
5417 return 0;
5421 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5422 Basically, we want to choose the bits that are likely to be shared between
5423 compilations (types) and leave out the bits that are specific to individual
5424 compilations (functions). */
5426 static int
5427 is_comdat_die (c)
5428 dw_die_ref c;
5430 #if 1
5431 /* I think we want to leave base types and __vtbl_ptr_type in the
5432 main CU, as we do for stabs. The advantage is a greater
5433 likelihood of sharing between objects that don't include headers
5434 in the same order (and therefore would put the base types in a
5435 different comdat). jason 8/28/00 */
5436 if (c->die_tag == DW_TAG_base_type)
5437 return 0;
5439 if (c->die_tag == DW_TAG_pointer_type
5440 || c->die_tag == DW_TAG_reference_type
5441 || c->die_tag == DW_TAG_const_type
5442 || c->die_tag == DW_TAG_volatile_type)
5444 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5445 return t ? is_comdat_die (t) : 0;
5447 #endif
5449 return is_type_die (c);
5452 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5453 compilation unit. */
5455 static int
5456 is_symbol_die (c)
5457 dw_die_ref c;
5459 if (is_type_die (c))
5460 return 1;
5461 if (get_AT (c, DW_AT_declaration)
5462 && ! get_AT (c, DW_AT_specification))
5463 return 1;
5464 return 0;
5467 static char *
5468 gen_internal_sym (prefix)
5469 const char *prefix;
5471 char buf[256];
5472 static int label_num;
5473 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5474 return xstrdup (buf);
5477 /* Assign symbols to all worthy DIEs under DIE. */
5479 static void
5480 assign_symbol_names (die)
5481 register dw_die_ref die;
5483 register dw_die_ref c;
5485 if (is_symbol_die (die))
5487 if (comdat_symbol_id)
5489 char *p = alloca (strlen (comdat_symbol_id) + 64);
5490 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5491 comdat_symbol_id, comdat_symbol_number++);
5492 die->die_symbol = xstrdup (p);
5494 else
5495 die->die_symbol = gen_internal_sym ("LDIE");
5498 for (c = die->die_child; c != NULL; c = c->die_sib)
5499 assign_symbol_names (c);
5502 /* Traverse the DIE (which is always comp_unit_die), and set up
5503 additional compilation units for each of the include files we see
5504 bracketed by BINCL/EINCL. */
5506 static void
5507 break_out_includes (die)
5508 register dw_die_ref die;
5510 dw_die_ref *ptr;
5511 register dw_die_ref unit = NULL;
5512 limbo_die_node *node;
5514 for (ptr = &(die->die_child); *ptr; )
5516 register dw_die_ref c = *ptr;
5518 if (c->die_tag == DW_TAG_GNU_BINCL
5519 || c->die_tag == DW_TAG_GNU_EINCL
5520 || (unit && is_comdat_die (c)))
5522 /* This DIE is for a secondary CU; remove it from the main one. */
5523 *ptr = c->die_sib;
5525 if (c->die_tag == DW_TAG_GNU_BINCL)
5527 unit = push_new_compile_unit (unit, c);
5528 free_die (c);
5530 else if (c->die_tag == DW_TAG_GNU_EINCL)
5532 unit = pop_compile_unit (unit);
5533 free_die (c);
5535 else
5536 add_child_die (unit, c);
5538 else
5540 /* Leave this DIE in the main CU. */
5541 ptr = &(c->die_sib);
5542 continue;
5546 #if 0
5547 /* We can only use this in debugging, since the frontend doesn't check
5548 to make sure that we leave every include file we enter. */
5549 if (unit != NULL)
5550 abort ();
5551 #endif
5553 assign_symbol_names (die);
5554 for (node = limbo_die_list; node; node = node->next)
5556 compute_section_prefix (node->die);
5557 assign_symbol_names (node->die);
5561 /* Traverse the DIE and add a sibling attribute if it may have the
5562 effect of speeding up access to siblings. To save some space,
5563 avoid generating sibling attributes for DIE's without children. */
5565 static void
5566 add_sibling_attributes (die)
5567 register dw_die_ref die;
5569 register dw_die_ref c;
5571 if (die->die_tag != DW_TAG_compile_unit
5572 && die->die_sib && die->die_child != NULL)
5573 /* Add the sibling link to the front of the attribute list. */
5574 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5576 for (c = die->die_child; c != NULL; c = c->die_sib)
5577 add_sibling_attributes (c);
5580 /* Output all location lists for the DIE and it's children */
5581 static void
5582 output_location_lists (die)
5583 register dw_die_ref die;
5585 dw_die_ref c;
5586 dw_attr_ref d_attr;
5587 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5589 if (AT_class (d_attr) == dw_val_class_loc_list)
5591 output_loc_list (AT_loc_list (d_attr));
5594 for (c = die->die_child; c != NULL; c = c->die_sib)
5595 output_location_lists (c);
5598 /* The format of each DIE (and its attribute value pairs)
5599 is encoded in an abbreviation table. This routine builds the
5600 abbreviation table and assigns a unique abbreviation id for
5601 each abbreviation entry. The children of each die are visited
5602 recursively. */
5604 static void
5605 build_abbrev_table (die)
5606 register dw_die_ref die;
5608 register unsigned long abbrev_id;
5609 register unsigned int n_alloc;
5610 register dw_die_ref c;
5611 register dw_attr_ref d_attr, a_attr;
5613 /* Scan the DIE references, and mark as external any that refer to
5614 DIEs from other CUs (i.e. those which are not marked). */
5615 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5617 if (AT_class (d_attr) == dw_val_class_die_ref
5618 && AT_ref (d_attr)->die_mark == 0)
5620 if (AT_ref (d_attr)->die_symbol == 0)
5621 abort ();
5622 set_AT_ref_external (d_attr, 1);
5626 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5628 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5630 if (abbrev->die_tag == die->die_tag)
5632 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5634 a_attr = abbrev->die_attr;
5635 d_attr = die->die_attr;
5637 while (a_attr != NULL && d_attr != NULL)
5639 if ((a_attr->dw_attr != d_attr->dw_attr)
5640 || (value_format (a_attr) != value_format (d_attr)))
5641 break;
5643 a_attr = a_attr->dw_attr_next;
5644 d_attr = d_attr->dw_attr_next;
5647 if (a_attr == NULL && d_attr == NULL)
5648 break;
5653 if (abbrev_id >= abbrev_die_table_in_use)
5655 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5657 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5658 abbrev_die_table
5659 = (dw_die_ref *) xrealloc (abbrev_die_table,
5660 sizeof (dw_die_ref) * n_alloc);
5662 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5663 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5664 abbrev_die_table_allocated = n_alloc;
5667 ++abbrev_die_table_in_use;
5668 abbrev_die_table[abbrev_id] = die;
5671 die->die_abbrev = abbrev_id;
5672 for (c = die->die_child; c != NULL; c = c->die_sib)
5673 build_abbrev_table (c);
5676 /* Return the size of a string, including the null byte.
5678 This used to treat backslashes as escapes, and hence they were not included
5679 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5680 which treats a backslash as a backslash, escaping it if necessary, and hence
5681 we must include them in the count. */
5683 static unsigned long
5684 size_of_string (str)
5685 register const char *str;
5687 return strlen (str) + 1;
5690 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5692 static int
5693 constant_size (value)
5694 long unsigned value;
5696 int log;
5698 if (value == 0)
5699 log = 0;
5700 else
5701 log = floor_log2 (value);
5703 log = log / 8;
5704 log = 1 << (floor_log2 (log) + 1);
5706 return log;
5709 /* Return the size of a DIE, as it is represented in the
5710 .debug_info section. */
5712 static unsigned long
5713 size_of_die (die)
5714 register dw_die_ref die;
5716 register unsigned long size = 0;
5717 register dw_attr_ref a;
5719 size += size_of_uleb128 (die->die_abbrev);
5720 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5722 switch (AT_class (a))
5724 case dw_val_class_addr:
5725 size += DWARF2_ADDR_SIZE;
5726 break;
5727 case dw_val_class_offset:
5728 size += DWARF_OFFSET_SIZE;
5729 break;
5730 case dw_val_class_loc:
5732 register unsigned long lsize = size_of_locs (AT_loc (a));
5734 /* Block length. */
5735 size += constant_size (lsize);
5736 size += lsize;
5738 break;
5739 case dw_val_class_loc_list:
5740 size += DWARF_OFFSET_SIZE;
5741 break;
5742 case dw_val_class_const:
5743 size += size_of_sleb128 (AT_int (a));
5744 break;
5745 case dw_val_class_unsigned_const:
5746 size += constant_size (AT_unsigned (a));
5747 break;
5748 case dw_val_class_long_long:
5749 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5750 break;
5751 case dw_val_class_float:
5752 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5753 break;
5754 case dw_val_class_flag:
5755 size += 1;
5756 break;
5757 case dw_val_class_die_ref:
5758 size += DWARF_OFFSET_SIZE;
5759 break;
5760 case dw_val_class_fde_ref:
5761 size += DWARF_OFFSET_SIZE;
5762 break;
5763 case dw_val_class_lbl_id:
5764 size += DWARF2_ADDR_SIZE;
5765 break;
5766 case dw_val_class_lbl_offset:
5767 size += DWARF_OFFSET_SIZE;
5768 break;
5769 case dw_val_class_str:
5770 size += size_of_string (AT_string (a));
5771 break;
5772 default:
5773 abort ();
5777 return size;
5780 /* Size the debugging information associated with a given DIE.
5781 Visits the DIE's children recursively. Updates the global
5782 variable next_die_offset, on each time through. Uses the
5783 current value of next_die_offset to update the die_offset
5784 field in each DIE. */
5786 static void
5787 calc_die_sizes (die)
5788 dw_die_ref die;
5790 register dw_die_ref c;
5791 die->die_offset = next_die_offset;
5792 next_die_offset += size_of_die (die);
5794 for (c = die->die_child; c != NULL; c = c->die_sib)
5795 calc_die_sizes (c);
5797 if (die->die_child != NULL)
5798 /* Count the null byte used to terminate sibling lists. */
5799 next_die_offset += 1;
5802 /* Set the marks for a die and its children. We do this so
5803 that we know whether or not a reference needs to use FORM_ref_addr; only
5804 DIEs in the same CU will be marked. We used to clear out the offset
5805 and use that as the flag, but ran into ordering problems. */
5807 static void
5808 mark_dies (die)
5809 dw_die_ref die;
5811 register dw_die_ref c;
5812 die->die_mark = 1;
5813 for (c = die->die_child; c; c = c->die_sib)
5814 mark_dies (c);
5817 /* Clear the marks for a die and its children. */
5819 static void
5820 unmark_dies (die)
5821 dw_die_ref die;
5823 register dw_die_ref c;
5824 die->die_mark = 0;
5825 for (c = die->die_child; c; c = c->die_sib)
5826 unmark_dies (c);
5829 /* Return the size of the .debug_pubnames table generated for the
5830 compilation unit. */
5832 static unsigned long
5833 size_of_pubnames ()
5835 register unsigned long size;
5836 register unsigned i;
5838 size = DWARF_PUBNAMES_HEADER_SIZE;
5839 for (i = 0; i < pubname_table_in_use; ++i)
5841 register pubname_ref p = &pubname_table[i];
5842 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5845 size += DWARF_OFFSET_SIZE;
5846 return size;
5849 /* Return the size of the information in the .debug_aranges section. */
5851 static unsigned long
5852 size_of_aranges ()
5854 register unsigned long size;
5856 size = DWARF_ARANGES_HEADER_SIZE;
5858 /* Count the address/length pair for this compilation unit. */
5859 size += 2 * DWARF2_ADDR_SIZE;
5860 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5862 /* Count the two zero words used to terminated the address range table. */
5863 size += 2 * DWARF2_ADDR_SIZE;
5864 return size;
5867 /* Select the encoding of an attribute value. */
5869 static enum dwarf_form
5870 value_format (a)
5871 dw_attr_ref a;
5873 switch (a->dw_attr_val.val_class)
5875 case dw_val_class_addr:
5876 return DW_FORM_addr;
5877 case dw_val_class_offset:
5878 if (DWARF_OFFSET_SIZE == 4)
5879 return DW_FORM_data4;
5880 if (DWARF_OFFSET_SIZE == 8)
5881 return DW_FORM_data8;
5882 abort ();
5883 case dw_val_class_loc_list:
5884 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
5885 .debug_loc section */
5886 return DW_FORM_data4;
5887 case dw_val_class_loc:
5888 switch (constant_size (size_of_locs (AT_loc (a))))
5890 case 1:
5891 return DW_FORM_block1;
5892 case 2:
5893 return DW_FORM_block2;
5894 default:
5895 abort ();
5897 case dw_val_class_const:
5898 return DW_FORM_sdata;
5899 case dw_val_class_unsigned_const:
5900 switch (constant_size (AT_unsigned (a)))
5902 case 1:
5903 return DW_FORM_data1;
5904 case 2:
5905 return DW_FORM_data2;
5906 case 4:
5907 return DW_FORM_data4;
5908 case 8:
5909 return DW_FORM_data8;
5910 default:
5911 abort ();
5913 case dw_val_class_long_long:
5914 return DW_FORM_block1;
5915 case dw_val_class_float:
5916 return DW_FORM_block1;
5917 case dw_val_class_flag:
5918 return DW_FORM_flag;
5919 case dw_val_class_die_ref:
5920 if (AT_ref_external (a))
5921 return DW_FORM_ref_addr;
5922 else
5923 return DW_FORM_ref;
5924 case dw_val_class_fde_ref:
5925 return DW_FORM_data;
5926 case dw_val_class_lbl_id:
5927 return DW_FORM_addr;
5928 case dw_val_class_lbl_offset:
5929 return DW_FORM_data;
5930 case dw_val_class_str:
5931 return DW_FORM_string;
5933 default:
5934 abort ();
5938 /* Output the encoding of an attribute value. */
5940 static void
5941 output_value_format (a)
5942 dw_attr_ref a;
5944 enum dwarf_form form = value_format (a);
5945 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
5948 /* Output the .debug_abbrev section which defines the DIE abbreviation
5949 table. */
5951 static void
5952 output_abbrev_section ()
5954 unsigned long abbrev_id;
5956 dw_attr_ref a_attr;
5957 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5959 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5961 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
5963 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
5964 dwarf_tag_name (abbrev->die_tag));
5966 if (abbrev->die_child != NULL)
5967 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
5968 else
5969 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
5971 for (a_attr = abbrev->die_attr; a_attr != NULL;
5972 a_attr = a_attr->dw_attr_next)
5974 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
5975 dwarf_attr_name (a_attr->dw_attr));
5976 output_value_format (a_attr);
5979 dw2_asm_output_data (1, 0, NULL);
5980 dw2_asm_output_data (1, 0, NULL);
5983 /* Terminate the table. */
5984 dw2_asm_output_data (1, 0, NULL);
5987 /* Output a symbol we can use to refer to this DIE from another CU. */
5989 static inline void
5990 output_die_symbol (die)
5991 register dw_die_ref die;
5993 char *sym = die->die_symbol;
5995 if (sym == 0)
5996 return;
5998 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
5999 /* We make these global, not weak; if the target doesn't support
6000 .linkonce, it doesn't support combining the sections, so debugging
6001 will break. */
6002 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
6003 ASM_OUTPUT_LABEL (asm_out_file, sym);
6006 /* Return a new location list, given the begin and end range, and the
6007 expression. gensym tells us whether to generate a new internal
6008 symbol for this location list node, which is done for the head of
6009 the list only. */
6010 static inline dw_loc_list_ref
6011 new_loc_list (expr, begin, end, section, gensym)
6012 register dw_loc_descr_ref expr;
6013 register const char *begin;
6014 register const char *end;
6015 register const char *section;
6016 register unsigned gensym;
6018 register dw_loc_list_ref retlist
6019 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
6020 retlist->begin = begin;
6021 retlist->end = end;
6022 retlist->expr = expr;
6023 retlist->section = section;
6024 if (gensym)
6025 retlist->ll_symbol = gen_internal_sym ("LLST");
6026 return retlist;
6029 /* Add a location description expression to a location list */
6030 static inline void
6031 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
6032 register dw_loc_list_ref *list_head;
6033 register dw_loc_descr_ref descr;
6034 register const char *begin;
6035 register const char *end;
6036 register const char *section;
6038 register dw_loc_list_ref *d;
6040 /* Find the end of the chain. */
6041 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6043 /* Add a new location list node to the list */
6044 *d = new_loc_list (descr, begin, end, section, 0);
6047 /* Output the location list given to us */
6048 static void
6049 output_loc_list (list_head)
6050 register dw_loc_list_ref list_head;
6052 register dw_loc_list_ref curr=list_head;
6053 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6055 /* ??? This shouldn't be needed now that we've forced the
6056 compilation unit base address to zero when there is code
6057 in more than one section. */
6058 if (strcmp (curr->section, ".text") == 0)
6060 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6061 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT)0,
6062 "Location list base address specifier fake entry");
6063 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
6064 "Location list base address specifier base");
6066 for (curr = list_head; curr != NULL; curr=curr->dw_loc_next)
6068 int size;
6069 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6070 "Location list begin address (%s)",
6071 list_head->ll_symbol);
6072 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6073 "Location list end address (%s)",
6074 list_head->ll_symbol);
6075 size = size_of_locs (curr->expr);
6077 /* Output the block length for this list of location operations. */
6078 dw2_asm_output_data (constant_size (size), size, "%s",
6079 "Location expression size");
6081 output_loc_sequence (curr->expr);
6083 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6084 "Location list terminator begin (%s)",
6085 list_head->ll_symbol);
6086 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6087 "Location list terminator end (%s)",
6088 list_head->ll_symbol);
6090 /* Output the DIE and its attributes. Called recursively to generate
6091 the definitions of each child DIE. */
6093 static void
6094 output_die (die)
6095 register dw_die_ref die;
6097 register dw_attr_ref a;
6098 register dw_die_ref c;
6099 register unsigned long size;
6101 /* If someone in another CU might refer to us, set up a symbol for
6102 them to point to. */
6103 if (die->die_symbol)
6104 output_die_symbol (die);
6106 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6107 die->die_offset, dwarf_tag_name (die->die_tag));
6109 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6111 const char *name = dwarf_attr_name (a->dw_attr);
6113 switch (AT_class (a))
6115 case dw_val_class_addr:
6116 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6117 break;
6119 case dw_val_class_offset:
6120 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6121 "%s", name);
6122 break;
6124 case dw_val_class_loc:
6125 size = size_of_locs (AT_loc (a));
6127 /* Output the block length for this list of location operations. */
6128 dw2_asm_output_data (constant_size (size), size, "%s", name);
6130 output_loc_sequence (AT_loc (a));
6131 break;
6133 case dw_val_class_const:
6134 /* ??? It would be slightly more efficient to use a scheme like is
6135 used for unsigned constants below, but gdb 4.x does not sign
6136 extend. Gdb 5.x does sign extend. */
6137 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6138 break;
6140 case dw_val_class_unsigned_const:
6141 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6142 AT_unsigned (a), "%s", name);
6143 break;
6145 case dw_val_class_long_long:
6147 unsigned HOST_WIDE_INT first, second;
6149 dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6150 "%s", name);
6152 if (WORDS_BIG_ENDIAN)
6154 first = a->dw_attr_val.v.val_long_long.hi;
6155 second = a->dw_attr_val.v.val_long_long.low;
6157 else
6159 first = a->dw_attr_val.v.val_long_long.low;
6160 second = a->dw_attr_val.v.val_long_long.hi;
6162 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6163 first, "long long constant");
6164 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6165 second, NULL);
6167 break;
6169 case dw_val_class_float:
6171 register unsigned int i;
6173 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6174 "%s", name);
6176 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
6177 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6178 "fp constant word %u", i);
6179 break;
6182 case dw_val_class_flag:
6183 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6184 break;
6186 case dw_val_class_loc_list:
6188 char *sym = AT_loc_list (a)->ll_symbol;
6189 if (sym == 0)
6190 abort();
6191 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
6192 loc_section_label, "%s", name);
6194 break;
6196 case dw_val_class_die_ref:
6197 if (AT_ref_external (a))
6199 char *sym = AT_ref (a)->die_symbol;
6200 if (sym == 0)
6201 abort ();
6202 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6204 else if (AT_ref (a)->die_offset == 0)
6205 abort ();
6206 else
6207 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6208 "%s", name);
6209 break;
6211 case dw_val_class_fde_ref:
6213 char l1[20];
6214 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6215 a->dw_attr_val.v.val_fde_index * 2);
6216 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6218 break;
6220 case dw_val_class_lbl_id:
6221 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6222 break;
6224 case dw_val_class_lbl_offset:
6225 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6226 break;
6228 case dw_val_class_str:
6229 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6230 break;
6232 default:
6233 abort ();
6237 for (c = die->die_child; c != NULL; c = c->die_sib)
6238 output_die (c);
6240 if (die->die_child != NULL)
6242 /* Add null byte to terminate sibling list. */
6243 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6244 die->die_offset);
6248 /* Output the compilation unit that appears at the beginning of the
6249 .debug_info section, and precedes the DIE descriptions. */
6251 static void
6252 output_compilation_unit_header ()
6254 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6255 "Length of Compilation Unit Info");
6257 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6259 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6260 "Offset Into Abbrev. Section");
6262 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6265 /* Output the compilation unit DIE and its children. */
6267 static void
6268 output_comp_unit (die)
6269 dw_die_ref die;
6271 const char *secname;
6273 /* Even if there are no children of this DIE, we must output the
6274 information about the compilation unit. Otherwise, on an empty
6275 translation unit, we will generate a present, but empty,
6276 .debug_info section. IRIX 6.5 `nm' will then complain when
6277 examining the file.
6279 Mark all the DIEs in this CU so we know which get local refs. */
6280 mark_dies (die);
6282 build_abbrev_table (die);
6284 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6285 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6286 calc_die_sizes (die);
6288 if (die->die_symbol)
6290 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6291 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6292 secname = tmp;
6293 die->die_symbol = NULL;
6295 else
6296 secname = (const char *) DEBUG_INFO_SECTION;
6298 /* Output debugging information. */
6299 named_section_flags (secname, SECTION_DEBUG);
6300 output_compilation_unit_header ();
6301 output_die (die);
6303 /* Leave the marks on the main CU, so we can check them in
6304 output_pubnames. */
6305 if (die->die_symbol)
6306 unmark_dies (die);
6309 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6310 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6311 argument list, and maybe the scope. */
6313 static const char *
6314 dwarf2_name (decl, scope)
6315 tree decl;
6316 int scope;
6318 return (*decl_printable_name) (decl, scope ? 1 : 0);
6321 /* Add a new entry to .debug_pubnames if appropriate. */
6323 static void
6324 add_pubname (decl, die)
6325 tree decl;
6326 dw_die_ref die;
6328 pubname_ref p;
6330 if (! TREE_PUBLIC (decl))
6331 return;
6333 if (pubname_table_in_use == pubname_table_allocated)
6335 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6336 pubname_table = (pubname_ref) xrealloc
6337 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6340 p = &pubname_table[pubname_table_in_use++];
6341 p->die = die;
6343 p->name = xstrdup (dwarf2_name (decl, 1));
6346 /* Output the public names table used to speed up access to externally
6347 visible names. For now, only generate entries for externally
6348 visible procedures. */
6350 static void
6351 output_pubnames ()
6353 register unsigned i;
6354 register unsigned long pubnames_length = size_of_pubnames ();
6356 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6357 "Length of Public Names Info");
6359 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6361 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6362 "Offset of Compilation Unit Info");
6364 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6365 "Compilation Unit Length");
6367 for (i = 0; i < pubname_table_in_use; ++i)
6369 register pubname_ref pub = &pubname_table[i];
6371 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6372 if (pub->die->die_mark == 0)
6373 abort ();
6375 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6376 "DIE offset");
6378 dw2_asm_output_nstring (pub->name, -1, "external name");
6381 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6384 /* Add a new entry to .debug_aranges if appropriate. */
6386 static void
6387 add_arange (decl, die)
6388 tree decl;
6389 dw_die_ref die;
6391 if (! DECL_SECTION_NAME (decl))
6392 return;
6394 if (arange_table_in_use == arange_table_allocated)
6396 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6397 arange_table = (dw_die_ref *)
6398 xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref));
6401 arange_table[arange_table_in_use++] = die;
6404 /* Output the information that goes into the .debug_aranges table.
6405 Namely, define the beginning and ending address range of the
6406 text section generated for this compilation unit. */
6408 static void
6409 output_aranges ()
6411 register unsigned i;
6412 register unsigned long aranges_length = size_of_aranges ();
6414 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6415 "Length of Address Ranges Info");
6417 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6419 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6420 "Offset of Compilation Unit Info");
6422 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6424 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6426 /* We need to align to twice the pointer size here. */
6427 if (DWARF_ARANGES_PAD_SIZE)
6429 /* Pad using a 2 byte words so that padding is correct for any
6430 pointer size. */
6431 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6432 2 * DWARF2_ADDR_SIZE);
6433 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6434 dw2_asm_output_data (2, 0, NULL);
6437 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6438 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6439 text_section_label, "Length");
6441 for (i = 0; i < arange_table_in_use; ++i)
6443 dw_die_ref die = arange_table[i];
6445 /* We shouldn't see aranges for DIEs outside of the main CU. */
6446 if (die->die_mark == 0)
6447 abort ();
6449 if (die->die_tag == DW_TAG_subprogram)
6451 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6452 "Address");
6453 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6454 get_AT_low_pc (die), "Length");
6456 else
6458 /* A static variable; extract the symbol from DW_AT_location.
6459 Note that this code isn't currently hit, as we only emit
6460 aranges for functions (jason 9/23/99). */
6462 dw_attr_ref a = get_AT (die, DW_AT_location);
6463 dw_loc_descr_ref loc;
6464 if (! a || AT_class (a) != dw_val_class_loc)
6465 abort ();
6467 loc = AT_loc (a);
6468 if (loc->dw_loc_opc != DW_OP_addr)
6469 abort ();
6471 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6472 loc->dw_loc_oprnd1.v.val_addr, "Address");
6473 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6474 get_AT_unsigned (die, DW_AT_byte_size),
6475 "Length");
6479 /* Output the terminator words. */
6480 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6481 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6484 /* Add a new entry to .debug_ranges. Return the offset at which it
6485 was placed. */
6487 static unsigned int
6488 add_ranges (block)
6489 tree block;
6491 unsigned int in_use = ranges_table_in_use;
6493 if (in_use == ranges_table_allocated)
6495 ranges_table_allocated += RANGES_TABLE_INCREMENT;
6496 ranges_table = (dw_ranges_ref)
6497 xrealloc (ranges_table, (ranges_table_allocated
6498 * sizeof (struct dw_ranges_struct)));
6501 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
6502 ranges_table_in_use = in_use + 1;
6504 return in_use * 2 * DWARF2_ADDR_SIZE;
6507 static void
6508 output_ranges ()
6510 register unsigned i;
6511 static const char *const start_fmt = "Offset 0x%x";
6512 const char *fmt = start_fmt;
6514 for (i = 0; i < ranges_table_in_use; ++i)
6516 int block_num = ranges_table[i].block_num;
6518 if (block_num)
6520 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
6521 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
6523 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
6524 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
6526 /* If all code is in the text section, then the compilation
6527 unit base address defaults to DW_AT_low_pc, which is the
6528 base of the text section. */
6529 if (separate_line_info_table_in_use == 0)
6531 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
6532 text_section_label,
6533 fmt, i * 2 * DWARF2_ADDR_SIZE);
6534 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
6535 text_section_label, NULL);
6537 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6538 compilation unit base address to zero, which allows us to
6539 use absolute addresses, and not worry about whether the
6540 target supports cross-section arithmetic. */
6541 else
6543 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
6544 fmt, i * 2 * DWARF2_ADDR_SIZE);
6545 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
6548 fmt = NULL;
6550 else
6552 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6553 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6554 fmt = start_fmt;
6559 /* Data structure containing information about input files. */
6560 struct file_info
6562 char *path; /* Complete file name. */
6563 char *fname; /* File name part. */
6564 int length; /* Length of entire string. */
6565 int file_idx; /* Index in input file table. */
6566 int dir_idx; /* Index in directory table. */
6569 /* Data structure containing information about directories with source
6570 files. */
6571 struct dir_info
6573 char *path; /* Path including directory name. */
6574 int length; /* Path length. */
6575 int prefix; /* Index of directory entry which is a prefix. */
6576 int count; /* Number of files in this directory. */
6577 int dir_idx; /* Index of directory used as base. */
6578 int used; /* Used in the end? */
6581 /* Callback function for file_info comparison. We sort by looking at
6582 the directories in the path. */
6583 static int
6584 file_info_cmp (p1, p2)
6585 const void *p1;
6586 const void *p2;
6588 const struct file_info *s1 = p1;
6589 const struct file_info *s2 = p2;
6590 unsigned char *cp1;
6591 unsigned char *cp2;
6593 /* Take care of file names without directories. */
6594 if (s1->path == s1->fname)
6595 return -1;
6596 else if (s2->path == s2->fname)
6597 return 1;
6599 cp1 = (unsigned char *) s1->path;
6600 cp2 = (unsigned char *) s2->path;
6602 while (1)
6604 ++cp1;
6605 ++cp2;
6606 /* Reached the end of the first path? */
6607 if (cp1 == (unsigned char *) s1->fname)
6608 /* It doesn't really matter in which order files from the
6609 same directory are sorted in. Therefore don't test for
6610 the second path reaching the end. */
6611 return -1;
6612 else if (cp2 == (unsigned char *) s2->fname)
6613 return 1;
6615 /* Character of current path component the same? */
6616 if (*cp1 != *cp2)
6617 return *cp1 - *cp2;
6621 /* Output the directory table and the file name table. We try to minimize
6622 the total amount of memory needed. A heuristic is used to avoid large
6623 slowdowns with many input files. */
6624 static void
6625 output_file_names ()
6627 struct file_info *files;
6628 struct dir_info *dirs;
6629 int *saved;
6630 int *savehere;
6631 int *backmap;
6632 int ndirs;
6633 int idx_offset;
6634 int i;
6635 int idx;
6637 /* Allocate the various arrays we need. */
6638 files = (struct file_info *) alloca (file_table.in_use
6639 * sizeof (struct file_info));
6640 dirs = (struct dir_info *) alloca (file_table.in_use
6641 * sizeof (struct dir_info));
6643 /* Sort the file names. */
6644 for (i = 1; i < (int) file_table.in_use; ++i)
6646 char *f;
6648 /* Skip all leading "./". */
6649 f = file_table.table[i];
6650 while (f[0] == '.' && f[1] == '/')
6651 f += 2;
6653 /* Create a new array entry. */
6654 files[i].path = f;
6655 files[i].length = strlen (f);
6656 files[i].file_idx = i;
6658 /* Search for the file name part. */
6659 f = strrchr (f, '/');
6660 files[i].fname = f == NULL ? files[i].path : f + 1;
6662 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6664 /* Find all the different directories used. */
6665 dirs[0].path = files[1].path;
6666 dirs[0].length = files[1].fname - files[1].path;
6667 dirs[0].prefix = -1;
6668 dirs[0].count = 1;
6669 dirs[0].dir_idx = 0;
6670 dirs[0].used = 0;
6671 files[1].dir_idx = 0;
6672 ndirs = 1;
6674 for (i = 2; i < (int) file_table.in_use; ++i)
6675 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6676 && memcmp (dirs[ndirs - 1].path, files[i].path,
6677 dirs[ndirs - 1].length) == 0)
6679 /* Same directory as last entry. */
6680 files[i].dir_idx = ndirs - 1;
6681 ++dirs[ndirs - 1].count;
6683 else
6685 int j;
6687 /* This is a new directory. */
6688 dirs[ndirs].path = files[i].path;
6689 dirs[ndirs].length = files[i].fname - files[i].path;
6690 dirs[ndirs].count = 1;
6691 dirs[ndirs].dir_idx = ndirs;
6692 dirs[ndirs].used = 0;
6693 files[i].dir_idx = ndirs;
6695 /* Search for a prefix. */
6696 dirs[ndirs].prefix = -1;
6697 for (j = 0; j < ndirs; ++j)
6698 if (dirs[j].length < dirs[ndirs].length
6699 && dirs[j].length > 1
6700 && (dirs[ndirs].prefix == -1
6701 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6702 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6703 dirs[ndirs].prefix = j;
6705 ++ndirs;
6708 /* Now to the actual work. We have to find a subset of the
6709 directories which allow expressing the file name using references
6710 to the directory table with the least amount of characters. We
6711 do not do an exhaustive search where we would have to check out
6712 every combination of every single possible prefix. Instead we
6713 use a heuristic which provides nearly optimal results in most
6714 cases and never is much off. */
6715 saved = (int *) alloca (ndirs * sizeof (int));
6716 savehere = (int *) alloca (ndirs * sizeof (int));
6718 memset (saved, '\0', ndirs * sizeof (saved[0]));
6719 for (i = 0; i < ndirs; ++i)
6721 int j;
6722 int total;
6724 /* We can always save some space for the current directory. But
6725 this does not mean it will be enough to justify adding the
6726 directory. */
6727 savehere[i] = dirs[i].length;
6728 total = (savehere[i] - saved[i]) * dirs[i].count;
6730 for (j = i + 1; j < ndirs; ++j)
6732 savehere[j] = 0;
6734 if (saved[j] < dirs[i].length)
6736 /* Determine whether the dirs[i] path is a prefix of the
6737 dirs[j] path. */
6738 int k;
6740 k = dirs[j].prefix;
6741 while (k != -1 && k != i)
6742 k = dirs[k].prefix;
6744 if (k == i)
6746 /* Yes it is. We can possibly safe some memory but
6747 writing the filenames in dirs[j] relative to
6748 dirs[i]. */
6749 savehere[j] = dirs[i].length;
6750 total += (savehere[j] - saved[j]) * dirs[j].count;
6755 /* Check whether we can safe enough to justify adding the dirs[i]
6756 directory. */
6757 if (total > dirs[i].length + 1)
6759 /* It's worthwhile adding. */
6760 for (j = i; j < ndirs; ++j)
6761 if (savehere[j] > 0)
6763 /* Remember how much we saved for this directory so far. */
6764 saved[j] = savehere[j];
6766 /* Remember the prefix directory. */
6767 dirs[j].dir_idx = i;
6772 /* We have to emit them in the order they appear in the file_table
6773 array since the index is used in the debug info generation. To
6774 do this efficiently we generate a back-mapping of the indices
6775 first. */
6776 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6777 for (i = 1; i < (int) file_table.in_use; ++i)
6779 backmap[files[i].file_idx] = i;
6780 /* Mark this directory as used. */
6781 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6784 /* That was it. We are ready to emit the information. First the
6785 directory name table. Here we have to make sure that the first
6786 actually emitted directory name has the index one. Zero is
6787 reserved for the current working directory. Make sure we do not
6788 confuse these indices with the one for the constructed table
6789 (even though most of the time they are identical). */
6790 idx = 1;
6791 idx_offset = dirs[0].length > 0 ? 1 : 0;
6792 for (i = 1 - idx_offset; i < ndirs; ++i)
6793 if (dirs[i].used != 0)
6795 dirs[i].used = idx++;
6796 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6797 "Directory Entry: 0x%x", dirs[i].used);
6799 dw2_asm_output_data (1, 0, "End directory table");
6801 /* Correct the index for the current working directory entry if it
6802 exists. */
6803 if (idx_offset == 0)
6804 dirs[0].used = 0;
6806 /* Now write all the file names. */
6807 for (i = 1; i < (int) file_table.in_use; ++i)
6809 int file_idx = backmap[i];
6810 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6812 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6813 "File Entry: 0x%x", i);
6815 /* Include directory index. */
6816 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6818 /* Modification time. */
6819 dw2_asm_output_data_uleb128 (0, NULL);
6821 /* File length in bytes. */
6822 dw2_asm_output_data_uleb128 (0, NULL);
6824 dw2_asm_output_data (1, 0, "End file name table");
6828 /* Output the source line number correspondence information. This
6829 information goes into the .debug_line section. */
6831 static void
6832 output_line_info ()
6834 char l1[20], l2[20], p1[20], p2[20];
6835 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6836 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6837 register unsigned opc;
6838 register unsigned n_op_args;
6839 register unsigned long lt_index;
6840 register unsigned long current_line;
6841 register long line_offset;
6842 register long line_delta;
6843 register unsigned long current_file;
6844 register unsigned long function;
6846 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
6847 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
6848 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
6849 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
6851 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
6852 "Length of Source Line Info");
6853 ASM_OUTPUT_LABEL (asm_out_file, l1);
6855 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6857 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
6858 ASM_OUTPUT_LABEL (asm_out_file, p1);
6860 dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH,
6861 "Minimum Instruction Length");
6863 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
6864 "Default is_stmt_start flag");
6866 dw2_asm_output_data (1, DWARF_LINE_BASE,
6867 "Line Base Value (Special Opcodes)");
6869 dw2_asm_output_data (1, DWARF_LINE_RANGE,
6870 "Line Range Value (Special Opcodes)");
6872 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
6873 "Special Opcode Base");
6875 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6877 switch (opc)
6879 case DW_LNS_advance_pc:
6880 case DW_LNS_advance_line:
6881 case DW_LNS_set_file:
6882 case DW_LNS_set_column:
6883 case DW_LNS_fixed_advance_pc:
6884 n_op_args = 1;
6885 break;
6886 default:
6887 n_op_args = 0;
6888 break;
6891 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
6892 opc, n_op_args);
6895 /* Write out the information about the files we use. */
6896 output_file_names ();
6897 ASM_OUTPUT_LABEL (asm_out_file, p2);
6899 /* We used to set the address register to the first location in the text
6900 section here, but that didn't accomplish anything since we already
6901 have a line note for the opening brace of the first function. */
6903 /* Generate the line number to PC correspondence table, encoded as
6904 a series of state machine operations. */
6905 current_file = 1;
6906 current_line = 1;
6907 strcpy (prev_line_label, text_section_label);
6908 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6910 register dw_line_info_ref line_info = &line_info_table[lt_index];
6912 #if 0
6913 /* Disable this optimization for now; GDB wants to see two line notes
6914 at the beginning of a function so it can find the end of the
6915 prologue. */
6917 /* Don't emit anything for redundant notes. Just updating the
6918 address doesn't accomplish anything, because we already assume
6919 that anything after the last address is this line. */
6920 if (line_info->dw_line_num == current_line
6921 && line_info->dw_file_num == current_file)
6922 continue;
6923 #endif
6925 /* Emit debug info for the address of the current line.
6927 Unfortunately, we have little choice here currently, and must always
6928 use the most general form. Gcc does not know the address delta
6929 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
6930 attributes which will give an upper bound on the address range. We
6931 could perhaps use length attributes to determine when it is safe to
6932 use DW_LNS_fixed_advance_pc. */
6934 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6935 if (0)
6937 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6938 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6939 "DW_LNS_fixed_advance_pc");
6940 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6942 else
6944 /* This can handle any delta. This takes
6945 4+DWARF2_ADDR_SIZE bytes. */
6946 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6947 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6948 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6949 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6951 strcpy (prev_line_label, line_label);
6953 /* Emit debug info for the source file of the current line, if
6954 different from the previous line. */
6955 if (line_info->dw_file_num != current_file)
6957 current_file = line_info->dw_file_num;
6958 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6959 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6960 file_table.table[current_file]);
6963 /* Emit debug info for the current line number, choosing the encoding
6964 that uses the least amount of space. */
6965 if (line_info->dw_line_num != current_line)
6967 line_offset = line_info->dw_line_num - current_line;
6968 line_delta = line_offset - DWARF_LINE_BASE;
6969 current_line = line_info->dw_line_num;
6970 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6972 /* This can handle deltas from -10 to 234, using the current
6973 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6974 takes 1 byte. */
6975 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6976 "line %lu", current_line);
6978 else
6980 /* This can handle any delta. This takes at least 4 bytes,
6981 depending on the value being encoded. */
6982 dw2_asm_output_data (1, DW_LNS_advance_line,
6983 "advance to line %lu", current_line);
6984 dw2_asm_output_data_sleb128 (line_offset, NULL);
6985 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6988 else
6990 /* We still need to start a new row, so output a copy insn. */
6991 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6995 /* Emit debug info for the address of the end of the function. */
6996 if (0)
6998 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6999 "DW_LNS_fixed_advance_pc");
7000 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7002 else
7004 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7005 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7006 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7007 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7010 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7011 dw2_asm_output_data_uleb128 (1, NULL);
7012 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7014 function = 0;
7015 current_file = 1;
7016 current_line = 1;
7017 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7019 register dw_separate_line_info_ref line_info
7020 = &separate_line_info_table[lt_index];
7022 #if 0
7023 /* Don't emit anything for redundant notes. */
7024 if (line_info->dw_line_num == current_line
7025 && line_info->dw_file_num == current_file
7026 && line_info->function == function)
7027 goto cont;
7028 #endif
7030 /* Emit debug info for the address of the current line. If this is
7031 a new function, or the first line of a function, then we need
7032 to handle it differently. */
7033 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7034 lt_index);
7035 if (function != line_info->function)
7037 function = line_info->function;
7039 /* Set the address register to the first line in the function */
7040 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7041 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7042 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7043 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7045 else
7047 /* ??? See the DW_LNS_advance_pc comment above. */
7048 if (0)
7050 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7051 "DW_LNS_fixed_advance_pc");
7052 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7054 else
7056 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7057 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7058 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7059 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7062 strcpy (prev_line_label, line_label);
7064 /* Emit debug info for the source file of the current line, if
7065 different from the previous line. */
7066 if (line_info->dw_file_num != current_file)
7068 current_file = line_info->dw_file_num;
7069 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7070 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7071 file_table.table[current_file]);
7074 /* Emit debug info for the current line number, choosing the encoding
7075 that uses the least amount of space. */
7076 if (line_info->dw_line_num != current_line)
7078 line_offset = line_info->dw_line_num - current_line;
7079 line_delta = line_offset - DWARF_LINE_BASE;
7080 current_line = line_info->dw_line_num;
7081 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7082 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7083 "line %lu", current_line);
7084 else
7086 dw2_asm_output_data (1, DW_LNS_advance_line,
7087 "advance to line %lu", current_line);
7088 dw2_asm_output_data_sleb128 (line_offset, NULL);
7089 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7092 else
7093 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7095 #if 0
7096 cont:
7097 #endif
7098 ++lt_index;
7100 /* If we're done with a function, end its sequence. */
7101 if (lt_index == separate_line_info_table_in_use
7102 || separate_line_info_table[lt_index].function != function)
7104 current_file = 1;
7105 current_line = 1;
7107 /* Emit debug info for the address of the end of the function. */
7108 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7109 if (0)
7111 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7112 "DW_LNS_fixed_advance_pc");
7113 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7115 else
7117 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7118 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7119 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7120 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7123 /* Output the marker for the end of this sequence. */
7124 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7125 dw2_asm_output_data_uleb128 (1, NULL);
7126 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7130 /* Output the marker for the end of the line number info. */
7131 ASM_OUTPUT_LABEL (asm_out_file, l2);
7134 /* Given a pointer to a tree node for some base type, return a pointer to
7135 a DIE that describes the given type.
7137 This routine must only be called for GCC type nodes that correspond to
7138 Dwarf base (fundamental) types. */
7140 static dw_die_ref
7141 base_type_die (type)
7142 register tree type;
7144 register dw_die_ref base_type_result;
7145 register const char *type_name;
7146 register enum dwarf_type encoding;
7147 register tree name = TYPE_NAME (type);
7149 if (TREE_CODE (type) == ERROR_MARK
7150 || TREE_CODE (type) == VOID_TYPE)
7151 return 0;
7153 if (name)
7155 if (TREE_CODE (name) == TYPE_DECL)
7156 name = DECL_NAME (name);
7158 type_name = IDENTIFIER_POINTER (name);
7160 else
7161 type_name = "__unknown__";
7163 switch (TREE_CODE (type))
7165 case INTEGER_TYPE:
7166 /* Carefully distinguish the C character types, without messing
7167 up if the language is not C. Note that we check only for the names
7168 that contain spaces; other names might occur by coincidence in other
7169 languages. */
7170 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7171 && (type == char_type_node
7172 || ! strcmp (type_name, "signed char")
7173 || ! strcmp (type_name, "unsigned char"))))
7175 if (TREE_UNSIGNED (type))
7176 encoding = DW_ATE_unsigned;
7177 else
7178 encoding = DW_ATE_signed;
7179 break;
7181 /* else fall through. */
7183 case CHAR_TYPE:
7184 /* GNU Pascal/Ada CHAR type. Not used in C. */
7185 if (TREE_UNSIGNED (type))
7186 encoding = DW_ATE_unsigned_char;
7187 else
7188 encoding = DW_ATE_signed_char;
7189 break;
7191 case REAL_TYPE:
7192 encoding = DW_ATE_float;
7193 break;
7195 /* Dwarf2 doesn't know anything about complex ints, so use
7196 a user defined type for it. */
7197 case COMPLEX_TYPE:
7198 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7199 encoding = DW_ATE_complex_float;
7200 else
7201 encoding = DW_ATE_lo_user;
7202 break;
7204 case BOOLEAN_TYPE:
7205 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7206 encoding = DW_ATE_boolean;
7207 break;
7209 default:
7210 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
7213 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
7214 if (demangle_name_func)
7215 type_name = (*demangle_name_func) (type_name);
7217 add_AT_string (base_type_result, DW_AT_name, type_name);
7218 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7219 int_size_in_bytes (type));
7220 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7222 return base_type_result;
7225 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7226 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7227 a given type is generally the same as the given type, except that if the
7228 given type is a pointer or reference type, then the root type of the given
7229 type is the root type of the "basis" type for the pointer or reference
7230 type. (This definition of the "root" type is recursive.) Also, the root
7231 type of a `const' qualified type or a `volatile' qualified type is the
7232 root type of the given type without the qualifiers. */
7234 static tree
7235 root_type (type)
7236 register tree type;
7238 if (TREE_CODE (type) == ERROR_MARK)
7239 return error_mark_node;
7241 switch (TREE_CODE (type))
7243 case ERROR_MARK:
7244 return error_mark_node;
7246 case POINTER_TYPE:
7247 case REFERENCE_TYPE:
7248 return type_main_variant (root_type (TREE_TYPE (type)));
7250 default:
7251 return type_main_variant (type);
7255 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7256 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7258 static inline int
7259 is_base_type (type)
7260 register tree type;
7262 switch (TREE_CODE (type))
7264 case ERROR_MARK:
7265 case VOID_TYPE:
7266 case INTEGER_TYPE:
7267 case REAL_TYPE:
7268 case COMPLEX_TYPE:
7269 case BOOLEAN_TYPE:
7270 case CHAR_TYPE:
7271 return 1;
7273 case SET_TYPE:
7274 case ARRAY_TYPE:
7275 case RECORD_TYPE:
7276 case UNION_TYPE:
7277 case QUAL_UNION_TYPE:
7278 case ENUMERAL_TYPE:
7279 case FUNCTION_TYPE:
7280 case METHOD_TYPE:
7281 case POINTER_TYPE:
7282 case REFERENCE_TYPE:
7283 case FILE_TYPE:
7284 case OFFSET_TYPE:
7285 case LANG_TYPE:
7286 case VECTOR_TYPE:
7287 return 0;
7289 default:
7290 abort ();
7293 return 0;
7296 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7297 entry that chains various modifiers in front of the given type. */
7299 static dw_die_ref
7300 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7301 register tree type;
7302 register int is_const_type;
7303 register int is_volatile_type;
7304 register dw_die_ref context_die;
7306 register enum tree_code code = TREE_CODE (type);
7307 register dw_die_ref mod_type_die = NULL;
7308 register dw_die_ref sub_die = NULL;
7309 register tree item_type = NULL;
7311 if (code != ERROR_MARK)
7313 tree qualified_type;
7315 /* See if we already have the appropriately qualified variant of
7316 this type. */
7317 qualified_type
7318 = get_qualified_type (type,
7319 ((is_const_type ? TYPE_QUAL_CONST : 0)
7320 | (is_volatile_type
7321 ? TYPE_QUAL_VOLATILE : 0)));
7322 /* If we do, then we can just use its DIE, if it exists. */
7323 if (qualified_type)
7325 mod_type_die = lookup_type_die (qualified_type);
7326 if (mod_type_die)
7327 return mod_type_die;
7330 /* Handle C typedef types. */
7331 if (qualified_type && TYPE_NAME (qualified_type)
7332 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7333 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7335 tree type_name = TYPE_NAME (qualified_type);
7336 tree dtype = TREE_TYPE (type_name);
7337 if (qualified_type == dtype)
7339 /* For a named type, use the typedef. */
7340 gen_type_die (qualified_type, context_die);
7341 mod_type_die = lookup_type_die (qualified_type);
7344 else if (is_const_type < TYPE_READONLY (dtype)
7345 || is_volatile_type < TYPE_VOLATILE (dtype))
7346 /* cv-unqualified version of named type. Just use the unnamed
7347 type to which it refers. */
7348 mod_type_die
7349 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7350 is_const_type, is_volatile_type,
7351 context_die);
7352 /* Else cv-qualified version of named type; fall through. */
7355 if (mod_type_die)
7356 /* OK. */
7358 else if (is_const_type)
7360 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7361 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7363 else if (is_volatile_type)
7365 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7366 sub_die = modified_type_die (type, 0, 0, context_die);
7368 else if (code == POINTER_TYPE)
7370 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7371 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7372 #if 0
7373 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7374 #endif
7375 item_type = TREE_TYPE (type);
7377 else if (code == REFERENCE_TYPE)
7379 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7380 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7381 #if 0
7382 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7383 #endif
7384 item_type = TREE_TYPE (type);
7386 else if (is_base_type (type))
7387 mod_type_die = base_type_die (type);
7388 else
7390 gen_type_die (type, context_die);
7392 /* We have to get the type_main_variant here (and pass that to the
7393 `lookup_type_die' routine) because the ..._TYPE node we have
7394 might simply be a *copy* of some original type node (where the
7395 copy was created to help us keep track of typedef names) and
7396 that copy might have a different TYPE_UID from the original
7397 ..._TYPE node. */
7398 mod_type_die = lookup_type_die (type_main_variant (type));
7399 if (mod_type_die == NULL)
7400 abort ();
7403 /* We want to equate the qualified type to the die below. */
7404 if (qualified_type)
7405 type = qualified_type;
7408 equate_type_number_to_die (type, mod_type_die);
7409 if (item_type)
7410 /* We must do this after the equate_type_number_to_die call, in case
7411 this is a recursive type. This ensures that the modified_type_die
7412 recursion will terminate even if the type is recursive. Recursive
7413 types are possible in Ada. */
7414 sub_die = modified_type_die (item_type,
7415 TYPE_READONLY (item_type),
7416 TYPE_VOLATILE (item_type),
7417 context_die);
7419 if (sub_die != NULL)
7420 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7422 return mod_type_die;
7425 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7426 an enumerated type. */
7428 static inline int
7429 type_is_enum (type)
7430 register tree type;
7432 return TREE_CODE (type) == ENUMERAL_TYPE;
7435 /* Return the register number described by a given RTL node. */
7437 static unsigned int
7438 reg_number (rtl)
7439 register rtx rtl;
7441 register unsigned regno = REGNO (rtl);
7443 if (regno >= FIRST_PSEUDO_REGISTER)
7445 warning ("internal regno botch: regno = %d\n", regno);
7446 regno = 0;
7449 regno = DBX_REGISTER_NUMBER (regno);
7450 return regno;
7453 /* Return a location descriptor that designates a machine register. */
7455 static dw_loc_descr_ref
7456 reg_loc_descriptor (rtl)
7457 register rtx rtl;
7459 register dw_loc_descr_ref loc_result = NULL;
7460 register unsigned reg = reg_number (rtl);
7462 if (reg <= 31)
7463 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7464 else
7465 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7467 return loc_result;
7470 /* Return a location descriptor that designates a constant. */
7472 static dw_loc_descr_ref
7473 int_loc_descriptor (i)
7474 HOST_WIDE_INT i;
7476 enum dwarf_location_atom op;
7478 /* Pick the smallest representation of a constant, rather than just
7479 defaulting to the LEB encoding. */
7480 if (i >= 0)
7482 if (i <= 31)
7483 op = DW_OP_lit0 + i;
7484 else if (i <= 0xff)
7485 op = DW_OP_const1u;
7486 else if (i <= 0xffff)
7487 op = DW_OP_const2u;
7488 else if (HOST_BITS_PER_WIDE_INT == 32
7489 || i <= 0xffffffff)
7490 op = DW_OP_const4u;
7491 else
7492 op = DW_OP_constu;
7494 else
7496 if (i >= -0x80)
7497 op = DW_OP_const1s;
7498 else if (i >= -0x8000)
7499 op = DW_OP_const2s;
7500 else if (HOST_BITS_PER_WIDE_INT == 32
7501 || i >= -0x80000000)
7502 op = DW_OP_const4s;
7503 else
7504 op = DW_OP_consts;
7507 return new_loc_descr (op, i, 0);
7510 /* Return a location descriptor that designates a base+offset location. */
7512 static dw_loc_descr_ref
7513 based_loc_descr (reg, offset)
7514 unsigned reg;
7515 long int offset;
7517 register dw_loc_descr_ref loc_result;
7518 /* For the "frame base", we use the frame pointer or stack pointer
7519 registers, since the RTL for local variables is relative to one of
7520 them. */
7521 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7522 ? HARD_FRAME_POINTER_REGNUM
7523 : STACK_POINTER_REGNUM);
7525 if (reg == fp_reg)
7526 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7527 else if (reg <= 31)
7528 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7529 else
7530 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7532 return loc_result;
7535 /* Return true if this RTL expression describes a base+offset calculation. */
7537 static inline int
7538 is_based_loc (rtl)
7539 register rtx rtl;
7541 return (GET_CODE (rtl) == PLUS
7542 && ((GET_CODE (XEXP (rtl, 0)) == REG
7543 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7546 /* The following routine converts the RTL for a variable or parameter
7547 (resident in memory) into an equivalent Dwarf representation of a
7548 mechanism for getting the address of that same variable onto the top of a
7549 hypothetical "address evaluation" stack.
7551 When creating memory location descriptors, we are effectively transforming
7552 the RTL for a memory-resident object into its Dwarf postfix expression
7553 equivalent. This routine recursively descends an RTL tree, turning
7554 it into Dwarf postfix code as it goes.
7556 MODE is the mode of the memory reference, needed to handle some
7557 autoincrement addressing modes. */
7559 static dw_loc_descr_ref
7560 mem_loc_descriptor (rtl, mode)
7561 register rtx rtl;
7562 enum machine_mode mode;
7564 dw_loc_descr_ref mem_loc_result = NULL;
7565 /* Note that for a dynamically sized array, the location we will generate a
7566 description of here will be the lowest numbered location which is
7567 actually within the array. That's *not* necessarily the same as the
7568 zeroth element of the array. */
7570 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7571 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7572 #endif
7574 switch (GET_CODE (rtl))
7576 case POST_INC:
7577 case POST_DEC:
7578 case POST_MODIFY:
7579 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7580 just fall into the SUBREG code. */
7582 /* Fall through. */
7584 case SUBREG:
7585 /* The case of a subreg may arise when we have a local (register)
7586 variable or a formal (register) parameter which doesn't quite fill
7587 up an entire register. For now, just assume that it is
7588 legitimate to make the Dwarf info refer to the whole register which
7589 contains the given subreg. */
7590 rtl = SUBREG_REG (rtl);
7592 /* Fall through. */
7594 case REG:
7595 /* Whenever a register number forms a part of the description of the
7596 method for calculating the (dynamic) address of a memory resident
7597 object, DWARF rules require the register number be referred to as
7598 a "base register". This distinction is not based in any way upon
7599 what category of register the hardware believes the given register
7600 belongs to. This is strictly DWARF terminology we're dealing with
7601 here. Note that in cases where the location of a memory-resident
7602 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7603 OP_CONST (0)) the actual DWARF location descriptor that we generate
7604 may just be OP_BASEREG (basereg). This may look deceptively like
7605 the object in question was allocated to a register (rather than in
7606 memory) so DWARF consumers need to be aware of the subtle
7607 distinction between OP_REG and OP_BASEREG. */
7608 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7609 break;
7611 case MEM:
7612 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7613 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7614 break;
7616 case LABEL_REF:
7617 /* Some ports can transform a symbol ref into a label ref, because
7618 the symbol ref is too far away and has to be dumped into a constant
7619 pool. */
7620 case CONST:
7621 case SYMBOL_REF:
7622 /* Alternatively, the symbol in the constant pool might be referenced
7623 by a different symbol. */
7624 if (GET_CODE (rtl) == SYMBOL_REF
7625 && CONSTANT_POOL_ADDRESS_P (rtl))
7627 rtx tmp = get_pool_constant (rtl);
7628 if (GET_CODE (tmp) == SYMBOL_REF)
7629 rtl = tmp;
7632 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7633 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7634 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7635 break;
7637 case PRE_MODIFY:
7638 /* Extract the PLUS expression nested inside and fall into
7639 PLUS code below. */
7640 rtl = XEXP (rtl, 1);
7641 goto plus;
7643 case PRE_INC:
7644 case PRE_DEC:
7645 /* Turn these into a PLUS expression and fall into the PLUS code
7646 below. */
7647 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7648 GEN_INT (GET_CODE (rtl) == PRE_INC
7649 ? GET_MODE_UNIT_SIZE (mode)
7650 : -GET_MODE_UNIT_SIZE (mode)));
7652 /* Fall through. */
7654 case PLUS:
7655 plus:
7656 if (is_based_loc (rtl))
7657 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7658 INTVAL (XEXP (rtl, 1)));
7659 else
7661 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7663 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7664 && INTVAL (XEXP (rtl, 1)) >= 0)
7666 add_loc_descr (&mem_loc_result,
7667 new_loc_descr (DW_OP_plus_uconst,
7668 INTVAL (XEXP (rtl, 1)), 0));
7670 else
7672 add_loc_descr (&mem_loc_result,
7673 mem_loc_descriptor (XEXP (rtl, 1), mode));
7674 add_loc_descr (&mem_loc_result,
7675 new_loc_descr (DW_OP_plus, 0, 0));
7678 break;
7680 case MULT:
7681 /* If a pseudo-reg is optimized away, it is possible for it to
7682 be replaced with a MEM containing a multiply. */
7683 add_loc_descr (&mem_loc_result,
7684 mem_loc_descriptor (XEXP (rtl, 0), mode));
7685 add_loc_descr (&mem_loc_result,
7686 mem_loc_descriptor (XEXP (rtl, 1), mode));
7687 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7688 break;
7690 case CONST_INT:
7691 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7692 break;
7694 default:
7695 abort ();
7698 return mem_loc_result;
7701 /* Return a descriptor that describes the concatenation of two locations.
7702 This is typically a complex variable. */
7704 static dw_loc_descr_ref
7705 concat_loc_descriptor (x0, x1)
7706 register rtx x0, x1;
7708 dw_loc_descr_ref cc_loc_result = NULL;
7710 if (!is_pseudo_reg (x0)
7711 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7712 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7713 add_loc_descr (&cc_loc_result,
7714 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7716 if (!is_pseudo_reg (x1)
7717 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7718 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7719 add_loc_descr (&cc_loc_result,
7720 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7722 return cc_loc_result;
7725 /* Output a proper Dwarf location descriptor for a variable or parameter
7726 which is either allocated in a register or in a memory location. For a
7727 register, we just generate an OP_REG and the register number. For a
7728 memory location we provide a Dwarf postfix expression describing how to
7729 generate the (dynamic) address of the object onto the address stack. */
7731 static dw_loc_descr_ref
7732 loc_descriptor (rtl)
7733 register rtx rtl;
7735 dw_loc_descr_ref loc_result = NULL;
7736 switch (GET_CODE (rtl))
7738 case SUBREG:
7739 /* The case of a subreg may arise when we have a local (register)
7740 variable or a formal (register) parameter which doesn't quite fill
7741 up an entire register. For now, just assume that it is
7742 legitimate to make the Dwarf info refer to the whole register which
7743 contains the given subreg. */
7744 rtl = SUBREG_REG (rtl);
7746 /* Fall through. */
7748 case REG:
7749 loc_result = reg_loc_descriptor (rtl);
7750 break;
7752 case MEM:
7753 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7754 break;
7756 case CONCAT:
7757 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7758 break;
7760 default:
7761 abort ();
7764 return loc_result;
7767 /* Similar, but generate the descriptor from trees instead of rtl.
7768 This comes up particularly with variable length arrays. */
7770 static dw_loc_descr_ref
7771 loc_descriptor_from_tree (loc, addressp)
7772 tree loc;
7773 int addressp;
7775 dw_loc_descr_ref ret = NULL;
7776 int indirect_size = 0;
7777 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7778 enum dwarf_location_atom op;
7780 /* ??? Most of the time we do not take proper care for sign/zero
7781 extending the values properly. Hopefully this won't be a real
7782 problem... */
7784 switch (TREE_CODE (loc))
7786 case ERROR_MARK:
7787 break;
7789 case WITH_RECORD_EXPR:
7790 /* This case involves extracting fields from an object to determine the
7791 position of other fields. We don't try to encode this here. The
7792 only user of this is Ada, which encodes the needed information using
7793 the names of types. */
7794 return ret;
7796 case VAR_DECL:
7797 case PARM_DECL:
7799 rtx rtl = rtl_for_decl_location (loc);
7800 enum machine_mode mode = DECL_MODE (loc);
7802 if (rtl == NULL_RTX)
7803 break;
7804 else if (CONSTANT_P (rtl))
7806 ret = new_loc_descr (DW_OP_addr, 0, 0);
7807 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7808 ret->dw_loc_oprnd1.v.val_addr = rtl;
7809 indirect_size = GET_MODE_SIZE (mode);
7811 else
7813 if (GET_CODE (rtl) == MEM)
7815 indirect_size = GET_MODE_SIZE (mode);
7816 rtl = XEXP (rtl, 0);
7818 ret = mem_loc_descriptor (rtl, mode);
7821 break;
7823 case INDIRECT_REF:
7824 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7825 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
7826 break;
7828 case NOP_EXPR:
7829 case CONVERT_EXPR:
7830 case NON_LVALUE_EXPR:
7831 case SAVE_EXPR:
7832 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
7834 case COMPONENT_REF:
7835 case BIT_FIELD_REF:
7836 case ARRAY_REF:
7837 case ARRAY_RANGE_REF:
7839 tree obj, offset;
7840 HOST_WIDE_INT bitsize, bitpos, bytepos;
7841 enum machine_mode mode;
7842 int volatilep;
7843 unsigned int alignment;
7845 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7846 &unsignedp, &volatilep, &alignment);
7847 ret = loc_descriptor_from_tree (obj, 1);
7849 if (offset != NULL_TREE)
7851 /* Variable offset. */
7852 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7853 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7856 if (addressp)
7858 /* We cannot address anything not on a unit boundary. */
7859 if (bitpos % BITS_PER_UNIT != 0)
7860 abort ();
7862 else
7864 if (bitpos % BITS_PER_UNIT != 0
7865 || bitsize % BITS_PER_UNIT != 0)
7867 /* ??? We could handle this by loading and shifting etc.
7868 Wait until someone needs it before expending the effort. */
7869 abort ();
7872 indirect_size = bitsize / BITS_PER_UNIT;
7875 bytepos = bitpos / BITS_PER_UNIT;
7876 if (bytepos > 0)
7877 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7878 else if (bytepos < 0)
7880 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7881 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7883 break;
7886 case INTEGER_CST:
7887 if (host_integerp (loc, 0))
7888 ret = int_loc_descriptor (tree_low_cst (loc, 0));
7889 break;
7891 case BIT_AND_EXPR:
7892 op = DW_OP_and;
7893 goto do_binop;
7894 case BIT_XOR_EXPR:
7895 op = DW_OP_xor;
7896 goto do_binop;
7897 case BIT_IOR_EXPR:
7898 op = DW_OP_or;
7899 goto do_binop;
7900 case TRUNC_DIV_EXPR:
7901 op = DW_OP_div;
7902 goto do_binop;
7903 case MINUS_EXPR:
7904 op = DW_OP_minus;
7905 goto do_binop;
7906 case TRUNC_MOD_EXPR:
7907 op = DW_OP_mod;
7908 goto do_binop;
7909 case MULT_EXPR:
7910 op = DW_OP_mul;
7911 goto do_binop;
7912 case LSHIFT_EXPR:
7913 op = DW_OP_shl;
7914 goto do_binop;
7915 case RSHIFT_EXPR:
7916 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
7917 goto do_binop;
7918 case PLUS_EXPR:
7919 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
7920 && host_integerp (TREE_OPERAND (loc, 1), 0))
7922 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7923 add_loc_descr (&ret,
7924 new_loc_descr (DW_OP_plus_uconst,
7925 tree_low_cst (TREE_OPERAND (loc, 1),
7927 0));
7928 break;
7930 op = DW_OP_plus;
7931 goto do_binop;
7932 case LE_EXPR:
7933 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7934 break;
7935 op = DW_OP_le;
7936 goto do_binop;
7937 case GE_EXPR:
7938 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7939 break;
7940 op = DW_OP_ge;
7941 goto do_binop;
7942 case LT_EXPR:
7943 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7944 break;
7945 op = DW_OP_lt;
7946 goto do_binop;
7947 case GT_EXPR:
7948 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7949 break;
7950 op = DW_OP_gt;
7951 goto do_binop;
7952 case EQ_EXPR:
7953 op = DW_OP_eq;
7954 goto do_binop;
7955 case NE_EXPR:
7956 op = DW_OP_ne;
7957 goto do_binop;
7959 do_binop:
7960 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7961 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
7962 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7963 break;
7965 case BIT_NOT_EXPR:
7966 op = DW_OP_not;
7967 goto do_unop;
7968 case ABS_EXPR:
7969 op = DW_OP_abs;
7970 goto do_unop;
7971 case NEGATE_EXPR:
7972 op = DW_OP_neg;
7973 goto do_unop;
7975 do_unop:
7976 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7977 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7978 break;
7980 case MAX_EXPR:
7981 loc = build (COND_EXPR, TREE_TYPE (loc),
7982 build (LT_EXPR, integer_type_node,
7983 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
7984 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
7985 /* FALLTHRU */
7987 case COND_EXPR:
7989 dw_loc_descr_ref bra_node, jump_node, tmp;
7991 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7992 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
7993 add_loc_descr (&ret, bra_node);
7995 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
7996 add_loc_descr (&ret, tmp);
7997 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
7998 add_loc_descr (&ret, jump_node);
8000 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8001 add_loc_descr (&ret, tmp);
8002 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8003 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
8005 /* ??? Need a node to point the skip at. Use a nop. */
8006 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8007 add_loc_descr (&ret, tmp);
8008 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8009 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8011 break;
8013 default:
8014 abort ();
8017 /* If we can't fill the request for an address, die. */
8018 if (addressp && indirect_size == 0)
8019 abort ();
8021 /* If we've got an address and don't want one, dereference. */
8022 if (!addressp && indirect_size > 0)
8024 if (indirect_size > DWARF2_ADDR_SIZE)
8025 abort ();
8026 if (indirect_size == DWARF2_ADDR_SIZE)
8027 op = DW_OP_deref;
8028 else
8029 op = DW_OP_deref_size;
8030 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
8033 return ret;
8036 /* Given a value, round it up to the lowest multiple of `boundary'
8037 which is not less than the value itself. */
8039 static inline HOST_WIDE_INT
8040 ceiling (value, boundary)
8041 HOST_WIDE_INT value;
8042 unsigned int boundary;
8044 return (((value + boundary - 1) / boundary) * boundary);
8047 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8048 pointer to the declared type for the relevant field variable, or return
8049 `integer_type_node' if the given node turns out to be an
8050 ERROR_MARK node. */
8052 static inline tree
8053 field_type (decl)
8054 register tree decl;
8056 register tree type;
8058 if (TREE_CODE (decl) == ERROR_MARK)
8059 return integer_type_node;
8061 type = DECL_BIT_FIELD_TYPE (decl);
8062 if (type == NULL_TREE)
8063 type = TREE_TYPE (decl);
8065 return type;
8068 /* Given a pointer to a tree node, return the alignment in bits for
8069 it, or else return BITS_PER_WORD if the node actually turns out to
8070 be an ERROR_MARK node. */
8072 static inline unsigned
8073 simple_type_align_in_bits (type)
8074 register tree type;
8076 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8079 static inline unsigned
8080 simple_decl_align_in_bits (decl)
8081 register tree decl;
8083 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8086 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8087 node, return the size in bits for the type if it is a constant, or else
8088 return the alignment for the type if the type's size is not constant, or
8089 else return BITS_PER_WORD if the type actually turns out to be an
8090 ERROR_MARK node. */
8092 static inline unsigned HOST_WIDE_INT
8093 simple_type_size_in_bits (type)
8094 register tree type;
8096 tree type_size_tree;
8098 if (TREE_CODE (type) == ERROR_MARK)
8099 return BITS_PER_WORD;
8100 type_size_tree = TYPE_SIZE (type);
8102 if (type_size_tree == NULL_TREE)
8103 return 0;
8104 if (! host_integerp (type_size_tree, 1))
8105 return TYPE_ALIGN (type);
8106 return tree_low_cst (type_size_tree, 1);
8109 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
8110 return the byte offset of the lowest addressed byte of the "containing
8111 object" for the given FIELD_DECL, or return 0 if we are unable to
8112 determine what that offset is, either because the argument turns out to
8113 be a pointer to an ERROR_MARK node, or because the offset is actually
8114 variable. (We can't handle the latter case just yet). */
8116 static HOST_WIDE_INT
8117 field_byte_offset (decl)
8118 register tree decl;
8120 unsigned int type_align_in_bits;
8121 unsigned int decl_align_in_bits;
8122 unsigned HOST_WIDE_INT type_size_in_bits;
8123 HOST_WIDE_INT object_offset_in_bits;
8124 HOST_WIDE_INT object_offset_in_bytes;
8125 tree type;
8126 tree field_size_tree;
8127 HOST_WIDE_INT bitpos_int;
8128 HOST_WIDE_INT deepest_bitpos;
8129 unsigned HOST_WIDE_INT field_size_in_bits;
8131 if (TREE_CODE (decl) == ERROR_MARK)
8132 return 0;
8134 if (TREE_CODE (decl) != FIELD_DECL)
8135 abort ();
8137 type = field_type (decl);
8138 field_size_tree = DECL_SIZE (decl);
8140 /* The size could be unspecified if there was an error, or for
8141 a flexible array member. */
8142 if (! field_size_tree)
8143 field_size_tree = bitsize_zero_node;
8145 /* We cannot yet cope with fields whose positions are variable, so
8146 for now, when we see such things, we simply return 0. Someday, we may
8147 be able to handle such cases, but it will be damn difficult. */
8148 if (! host_integerp (bit_position (decl), 0))
8149 return 0;
8151 bitpos_int = int_bit_position (decl);
8153 /* If we don't know the size of the field, pretend it's a full word. */
8154 if (host_integerp (field_size_tree, 1))
8155 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8156 else
8157 field_size_in_bits = BITS_PER_WORD;
8159 type_size_in_bits = simple_type_size_in_bits (type);
8160 type_align_in_bits = simple_type_align_in_bits (type);
8161 decl_align_in_bits = simple_decl_align_in_bits (decl);
8163 /* Note that the GCC front-end doesn't make any attempt to keep track of
8164 the starting bit offset (relative to the start of the containing
8165 structure type) of the hypothetical "containing object" for a bit-
8166 field. Thus, when computing the byte offset value for the start of the
8167 "containing object" of a bit-field, we must deduce this information on
8168 our own. This can be rather tricky to do in some cases. For example,
8169 handling the following structure type definition when compiling for an
8170 i386/i486 target (which only aligns long long's to 32-bit boundaries)
8171 can be very tricky:
8173 struct S { int field1; long long field2:31; };
8175 Fortunately, there is a simple rule-of-thumb which can be
8176 used in such cases. When compiling for an i386/i486, GCC will allocate
8177 8 bytes for the structure shown above. It decides to do this based upon
8178 one simple rule for bit-field allocation. Quite simply, GCC allocates
8179 each "containing object" for each bit-field at the first (i.e. lowest
8180 addressed) legitimate alignment boundary (based upon the required
8181 minimum alignment for the declared type of the field) which it can
8182 possibly use, subject to the condition that there is still enough
8183 available space remaining in the containing object (when allocated at
8184 the selected point) to fully accommodate all of the bits of the
8185 bit-field itself. This simple rule makes it obvious why GCC allocates
8186 8 bytes for each object of the structure type shown above. When looking
8187 for a place to allocate the "containing object" for `field2', the
8188 compiler simply tries to allocate a 64-bit "containing object" at each
8189 successive 32-bit boundary (starting at zero) until it finds a place to
8190 allocate that 64- bit field such that at least 31 contiguous (and
8191 previously unallocated) bits remain within that selected 64 bit field.
8192 (As it turns out, for the example above, the compiler finds that it is
8193 OK to allocate the "containing object" 64-bit field at bit-offset zero
8194 within the structure type.) Here we attempt to work backwards from the
8195 limited set of facts we're given, and we try to deduce from those facts,
8196 where GCC must have believed that the containing object started (within
8197 the structure type). The value we deduce is then used (by the callers of
8198 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
8199 for fields (both bit-fields and, in the case of DW_AT_location, regular
8200 fields as well). */
8202 /* Figure out the bit-distance from the start of the structure to the
8203 "deepest" bit of the bit-field. */
8204 deepest_bitpos = bitpos_int + field_size_in_bits;
8206 /* This is the tricky part. Use some fancy footwork to deduce where the
8207 lowest addressed bit of the containing object must be. */
8208 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8210 /* Round up to type_align by default. This works best for bitfields. */
8211 object_offset_in_bits += type_align_in_bits - 1;
8212 object_offset_in_bits /= type_align_in_bits;
8213 object_offset_in_bits *= type_align_in_bits;
8215 if (object_offset_in_bits > bitpos_int)
8217 /* Sigh, the decl must be packed. */
8218 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8220 /* Round up to decl_align instead. */
8221 object_offset_in_bits += decl_align_in_bits - 1;
8222 object_offset_in_bits /= decl_align_in_bits;
8223 object_offset_in_bits *= decl_align_in_bits;
8226 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
8228 return object_offset_in_bytes;
8231 /* The following routines define various Dwarf attributes and any data
8232 associated with them. */
8234 /* Add a location description attribute value to a DIE.
8236 This emits location attributes suitable for whole variables and
8237 whole parameters. Note that the location attributes for struct fields are
8238 generated by the routine `data_member_location_attribute' below. */
8240 static void
8241 add_AT_location_description (die, attr_kind, rtl)
8242 dw_die_ref die;
8243 enum dwarf_attribute attr_kind;
8244 register rtx rtl;
8246 /* Handle a special case. If we are about to output a location descriptor
8247 for a variable or parameter which has been optimized out of existence,
8248 don't do that. A variable which has been optimized out
8249 of existence will have a DECL_RTL value which denotes a pseudo-reg.
8250 Currently, in some rare cases, variables can have DECL_RTL values which
8251 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
8252 elsewhere in the compiler. We treat such cases as if the variable(s) in
8253 question had been optimized out of existence. */
8255 if (is_pseudo_reg (rtl)
8256 || (GET_CODE (rtl) == MEM
8257 && is_pseudo_reg (XEXP (rtl, 0)))
8258 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
8259 references the internal argument pointer (a pseudo) in a function
8260 where all references to the internal argument pointer were
8261 eliminated via the optimizers. */
8262 || (GET_CODE (rtl) == MEM
8263 && GET_CODE (XEXP (rtl, 0)) == PLUS
8264 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
8265 || (GET_CODE (rtl) == CONCAT
8266 && is_pseudo_reg (XEXP (rtl, 0))
8267 && is_pseudo_reg (XEXP (rtl, 1))))
8268 return;
8270 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
8273 /* Attach the specialized form of location attribute used for data
8274 members of struct and union types. In the special case of a
8275 FIELD_DECL node which represents a bit-field, the "offset" part
8276 of this special location descriptor must indicate the distance
8277 in bytes from the lowest-addressed byte of the containing struct
8278 or union type to the lowest-addressed byte of the "containing
8279 object" for the bit-field. (See the `field_byte_offset' function
8280 above).. For any given bit-field, the "containing object" is a
8281 hypothetical object (of some integral or enum type) within which
8282 the given bit-field lives. The type of this hypothetical
8283 "containing object" is always the same as the declared type of
8284 the individual bit-field itself (for GCC anyway... the DWARF
8285 spec doesn't actually mandate this). Note that it is the size
8286 (in bytes) of the hypothetical "containing object" which will
8287 be given in the DW_AT_byte_size attribute for this bit-field.
8288 (See the `byte_size_attribute' function below.) It is also used
8289 when calculating the value of the DW_AT_bit_offset attribute.
8290 (See the `bit_offset_attribute' function below). */
8292 static void
8293 add_data_member_location_attribute (die, decl)
8294 register dw_die_ref die;
8295 register tree decl;
8297 register unsigned long offset;
8298 register dw_loc_descr_ref loc_descr;
8299 register enum dwarf_location_atom op;
8301 if (TREE_CODE (decl) == TREE_VEC)
8302 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8303 else
8304 offset = field_byte_offset (decl);
8306 /* The DWARF2 standard says that we should assume that the structure address
8307 is already on the stack, so we can specify a structure field address
8308 by using DW_OP_plus_uconst. */
8310 #ifdef MIPS_DEBUGGING_INFO
8311 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
8312 correctly. It works only if we leave the offset on the stack. */
8313 op = DW_OP_constu;
8314 #else
8315 op = DW_OP_plus_uconst;
8316 #endif
8318 loc_descr = new_loc_descr (op, offset, 0);
8319 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8322 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8323 does not have a "location" either in memory or in a register. These
8324 things can arise in GNU C when a constant is passed as an actual parameter
8325 to an inlined function. They can also arise in C++ where declared
8326 constants do not necessarily get memory "homes". */
8328 static void
8329 add_const_value_attribute (die, rtl)
8330 register dw_die_ref die;
8331 register rtx rtl;
8333 switch (GET_CODE (rtl))
8335 case CONST_INT:
8336 /* Note that a CONST_INT rtx could represent either an integer
8337 or a floating-point constant. A CONST_INT is used whenever
8338 the constant will fit into a single word. In all such
8339 cases, the original mode of the constant value is wiped
8340 out, and the CONST_INT rtx is assigned VOIDmode. */
8342 HOST_WIDE_INT val = INTVAL (rtl);
8344 /* ??? We really should be using HOST_WIDE_INT throughout. */
8345 if (val < 0)
8347 if ((long) val != val)
8348 abort ();
8349 add_AT_int (die, DW_AT_const_value, (long) val);
8351 else
8353 if ((unsigned long) val != (unsigned HOST_WIDE_INT) val)
8354 abort ();
8355 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
8358 break;
8360 case CONST_DOUBLE:
8361 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8362 floating-point constant. A CONST_DOUBLE is used whenever the
8363 constant requires more than one word in order to be adequately
8364 represented. We output CONST_DOUBLEs as blocks. */
8366 register enum machine_mode mode = GET_MODE (rtl);
8368 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8370 register unsigned length = GET_MODE_SIZE (mode) / 4;
8371 long *array = (long *) xmalloc (sizeof (long) * length);
8372 REAL_VALUE_TYPE rv;
8374 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8375 switch (mode)
8377 case SFmode:
8378 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8379 break;
8381 case DFmode:
8382 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8383 break;
8385 case XFmode:
8386 case TFmode:
8387 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8388 break;
8390 default:
8391 abort ();
8394 add_AT_float (die, DW_AT_const_value, length, array);
8396 else
8398 /* ??? We really should be using HOST_WIDE_INT throughout. */
8399 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8400 abort ();
8401 add_AT_long_long (die, DW_AT_const_value,
8402 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8405 break;
8407 case CONST_STRING:
8408 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8409 break;
8411 case SYMBOL_REF:
8412 case LABEL_REF:
8413 case CONST:
8414 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8415 break;
8417 case PLUS:
8418 /* In cases where an inlined instance of an inline function is passed
8419 the address of an `auto' variable (which is local to the caller) we
8420 can get a situation where the DECL_RTL of the artificial local
8421 variable (for the inlining) which acts as a stand-in for the
8422 corresponding formal parameter (of the inline function) will look
8423 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8424 exactly a compile-time constant expression, but it isn't the address
8425 of the (artificial) local variable either. Rather, it represents the
8426 *value* which the artificial local variable always has during its
8427 lifetime. We currently have no way to represent such quasi-constant
8428 values in Dwarf, so for now we just punt and generate nothing. */
8429 break;
8431 default:
8432 /* No other kinds of rtx should be possible here. */
8433 abort ();
8438 static rtx
8439 rtl_for_decl_location (decl)
8440 tree decl;
8442 register rtx rtl;
8444 /* Here we have to decide where we are going to say the parameter "lives"
8445 (as far as the debugger is concerned). We only have a couple of
8446 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8448 DECL_RTL normally indicates where the parameter lives during most of the
8449 activation of the function. If optimization is enabled however, this
8450 could be either NULL or else a pseudo-reg. Both of those cases indicate
8451 that the parameter doesn't really live anywhere (as far as the code
8452 generation parts of GCC are concerned) during most of the function's
8453 activation. That will happen (for example) if the parameter is never
8454 referenced within the function.
8456 We could just generate a location descriptor here for all non-NULL
8457 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8458 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8459 where DECL_RTL is NULL or is a pseudo-reg.
8461 Note however that we can only get away with using DECL_INCOMING_RTL as
8462 a backup substitute for DECL_RTL in certain limited cases. In cases
8463 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8464 we can be sure that the parameter was passed using the same type as it is
8465 declared to have within the function, and that its DECL_INCOMING_RTL
8466 points us to a place where a value of that type is passed.
8468 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8469 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8470 because in these cases DECL_INCOMING_RTL points us to a value of some
8471 type which is *different* from the type of the parameter itself. Thus,
8472 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8473 such cases, the debugger would end up (for example) trying to fetch a
8474 `float' from a place which actually contains the first part of a
8475 `double'. That would lead to really incorrect and confusing
8476 output at debug-time.
8478 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8479 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8480 are a couple of exceptions however. On little-endian machines we can
8481 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8482 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8483 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8484 when (on a little-endian machine) a non-prototyped function has a
8485 parameter declared to be of type `short' or `char'. In such cases,
8486 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8487 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8488 passed `int' value. If the debugger then uses that address to fetch
8489 a `short' or a `char' (on a little-endian machine) the result will be
8490 the correct data, so we allow for such exceptional cases below.
8492 Note that our goal here is to describe the place where the given formal
8493 parameter lives during most of the function's activation (i.e. between
8494 the end of the prologue and the start of the epilogue). We'll do that
8495 as best as we can. Note however that if the given formal parameter is
8496 modified sometime during the execution of the function, then a stack
8497 backtrace (at debug-time) will show the function as having been
8498 called with the *new* value rather than the value which was
8499 originally passed in. This happens rarely enough that it is not
8500 a major problem, but it *is* a problem, and I'd like to fix it.
8502 A future version of dwarf2out.c may generate two additional
8503 attributes for any given DW_TAG_formal_parameter DIE which will
8504 describe the "passed type" and the "passed location" for the
8505 given formal parameter in addition to the attributes we now
8506 generate to indicate the "declared type" and the "active
8507 location" for each parameter. This additional set of attributes
8508 could be used by debuggers for stack backtraces. Separately, note
8509 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8510 NULL also. This happens (for example) for inlined-instances of
8511 inline function formal parameters which are never referenced.
8512 This really shouldn't be happening. All PARM_DECL nodes should
8513 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8514 doesn't currently generate these values for inlined instances of
8515 inline function parameters, so when we see such cases, we are
8516 just out-of-luck for the time being (until integrate.c
8517 gets fixed). */
8519 /* Use DECL_RTL as the "location" unless we find something better. */
8520 rtl = DECL_RTL_IF_SET (decl);
8522 if (TREE_CODE (decl) == PARM_DECL)
8524 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8526 tree declared_type = type_main_variant (TREE_TYPE (decl));
8527 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8529 /* This decl represents a formal parameter which was optimized out.
8530 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8531 all* cases where (rtl == NULL_RTX) just below. */
8532 if (declared_type == passed_type)
8533 rtl = DECL_INCOMING_RTL (decl);
8534 else if (! BYTES_BIG_ENDIAN
8535 && TREE_CODE (declared_type) == INTEGER_TYPE
8536 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8537 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8538 rtl = DECL_INCOMING_RTL (decl);
8541 /* If the parm was passed in registers, but lives on the stack, then
8542 make a big endian correction if the mode of the type of the
8543 parameter is not the same as the mode of the rtl. */
8544 /* ??? This is the same series of checks that are made in dbxout.c before
8545 we reach the big endian correction code there. It isn't clear if all
8546 of these checks are necessary here, but keeping them all is the safe
8547 thing to do. */
8548 else if (GET_CODE (rtl) == MEM
8549 && XEXP (rtl, 0) != const0_rtx
8550 && ! CONSTANT_P (XEXP (rtl, 0))
8551 /* Not passed in memory. */
8552 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8553 /* Not passed by invisible reference. */
8554 && (GET_CODE (XEXP (rtl, 0)) != REG
8555 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8556 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8557 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8558 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8559 #endif
8561 /* Big endian correction check. */
8562 && BYTES_BIG_ENDIAN
8563 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8564 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8565 < UNITS_PER_WORD))
8567 int offset = (UNITS_PER_WORD
8568 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8569 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8570 plus_constant (XEXP (rtl, 0), offset));
8574 if (rtl != NULL_RTX)
8576 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8577 #ifdef LEAF_REG_REMAP
8578 if (current_function_uses_only_leaf_regs)
8579 leaf_renumber_regs_insn (rtl);
8580 #endif
8583 return rtl;
8586 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8587 data attribute for a variable or a parameter. We generate the
8588 DW_AT_const_value attribute only in those cases where the given variable
8589 or parameter does not have a true "location" either in memory or in a
8590 register. This can happen (for example) when a constant is passed as an
8591 actual argument in a call to an inline function. (It's possible that
8592 these things can crop up in other ways also.) Note that one type of
8593 constant value which can be passed into an inlined function is a constant
8594 pointer. This can happen for example if an actual argument in an inlined
8595 function call evaluates to a compile-time constant address. */
8597 static void
8598 add_location_or_const_value_attribute (die, decl)
8599 register dw_die_ref die;
8600 register tree decl;
8602 register rtx rtl;
8604 if (TREE_CODE (decl) == ERROR_MARK)
8605 return;
8607 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8608 abort ();
8610 rtl = rtl_for_decl_location (decl);
8611 if (rtl == NULL_RTX)
8612 return;
8614 /* If we don't look past the constant pool, we risk emitting a
8615 reference to a constant pool entry that isn't referenced from
8616 code, and thus is not emitted. */
8617 rtl = avoid_constant_pool_reference (rtl);
8619 switch (GET_CODE (rtl))
8621 case ADDRESSOF:
8622 /* The address of a variable that was optimized away; don't emit
8623 anything. */
8624 break;
8626 case CONST_INT:
8627 case CONST_DOUBLE:
8628 case CONST_STRING:
8629 case SYMBOL_REF:
8630 case LABEL_REF:
8631 case CONST:
8632 case PLUS:
8633 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8634 add_const_value_attribute (die, rtl);
8635 break;
8637 case MEM:
8638 case REG:
8639 case SUBREG:
8640 case CONCAT:
8641 add_AT_location_description (die, DW_AT_location, rtl);
8642 break;
8644 default:
8645 abort ();
8649 /* If we don't have a copy of this variable in memory for some reason (such
8650 as a C++ member constant that doesn't have an out-of-line definition),
8651 we should tell the debugger about the constant value. */
8653 static void
8654 tree_add_const_value_attribute (var_die, decl)
8655 dw_die_ref var_die;
8656 tree decl;
8658 tree init = DECL_INITIAL (decl);
8659 tree type = TREE_TYPE (decl);
8661 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8662 && initializer_constant_valid_p (init, type) == null_pointer_node)
8663 /* OK */;
8664 else
8665 return;
8667 switch (TREE_CODE (type))
8669 case INTEGER_TYPE:
8670 if (host_integerp (init, 0))
8671 add_AT_unsigned (var_die, DW_AT_const_value,
8672 TREE_INT_CST_LOW (init));
8673 else
8674 add_AT_long_long (var_die, DW_AT_const_value,
8675 TREE_INT_CST_HIGH (init),
8676 TREE_INT_CST_LOW (init));
8677 break;
8679 default:;
8683 /* Generate an DW_AT_name attribute given some string value to be included as
8684 the value of the attribute. */
8686 static inline void
8687 add_name_attribute (die, name_string)
8688 register dw_die_ref die;
8689 register const char *name_string;
8691 if (name_string != NULL && *name_string != 0)
8693 if (demangle_name_func)
8694 name_string = (*demangle_name_func) (name_string);
8696 add_AT_string (die, DW_AT_name, name_string);
8700 /* Given a tree node describing an array bound (either lower or upper) output
8701 a representation for that bound. */
8703 static void
8704 add_bound_info (subrange_die, bound_attr, bound)
8705 register dw_die_ref subrange_die;
8706 register enum dwarf_attribute bound_attr;
8707 register tree bound;
8709 /* If this is an Ada unconstrained array type, then don't emit any debug
8710 info because the array bounds are unknown. They are parameterized when
8711 the type is instantiated. */
8712 if (contains_placeholder_p (bound))
8713 return;
8715 switch (TREE_CODE (bound))
8717 case ERROR_MARK:
8718 return;
8720 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8721 case INTEGER_CST:
8722 if (! host_integerp (bound, 0)
8723 || (bound_attr == DW_AT_lower_bound
8724 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8725 || (is_fortran () && integer_onep (bound)))))
8726 /* use the default */
8728 else
8729 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8730 break;
8732 case CONVERT_EXPR:
8733 case NOP_EXPR:
8734 case NON_LVALUE_EXPR:
8735 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8736 break;
8738 case SAVE_EXPR:
8739 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8740 access the upper bound values may be bogus. If they refer to a
8741 register, they may only describe how to get at these values at the
8742 points in the generated code right after they have just been
8743 computed. Worse yet, in the typical case, the upper bound values
8744 will not even *be* computed in the optimized code (though the
8745 number of elements will), so these SAVE_EXPRs are entirely
8746 bogus. In order to compensate for this fact, we check here to see
8747 if optimization is enabled, and if so, we don't add an attribute
8748 for the (unknown and unknowable) upper bound. This should not
8749 cause too much trouble for existing (stupid?) debuggers because
8750 they have to deal with empty upper bounds location descriptions
8751 anyway in order to be able to deal with incomplete array types.
8752 Of course an intelligent debugger (GDB?) should be able to
8753 comprehend that a missing upper bound specification in a array
8754 type used for a storage class `auto' local array variable
8755 indicates that the upper bound is both unknown (at compile- time)
8756 and unknowable (at run-time) due to optimization.
8758 We assume that a MEM rtx is safe because gcc wouldn't put the
8759 value there unless it was going to be used repeatedly in the
8760 function, i.e. for cleanups. */
8761 if (SAVE_EXPR_RTL (bound)
8762 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8764 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8765 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8766 register rtx loc = SAVE_EXPR_RTL (bound);
8768 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8769 it references an outer function's frame. */
8771 if (GET_CODE (loc) == MEM)
8773 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8775 if (XEXP (loc, 0) != new_addr)
8776 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8779 add_AT_flag (decl_die, DW_AT_artificial, 1);
8780 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8781 add_AT_location_description (decl_die, DW_AT_location, loc);
8782 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8785 /* Else leave out the attribute. */
8786 break;
8788 case VAR_DECL:
8789 case PARM_DECL:
8791 dw_die_ref decl_die = lookup_decl_die (bound);
8793 /* ??? Can this happen, or should the variable have been bound
8794 first? Probably it can, since I imagine that we try to create
8795 the types of parameters in the order in which they exist in
8796 the list, and won't have created a forward reference to a
8797 later parameter. */
8798 if (decl_die != NULL)
8799 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8800 break;
8803 default:
8805 /* Otherwise try to create a stack operation procedure to
8806 evaluate the value of the array bound. */
8808 dw_die_ref ctx, decl_die;
8809 dw_loc_descr_ref loc;
8811 loc = loc_descriptor_from_tree (bound, 0);
8812 if (loc == NULL)
8813 break;
8815 ctx = lookup_decl_die (current_function_decl);
8817 decl_die = new_die (DW_TAG_variable, ctx);
8818 add_AT_flag (decl_die, DW_AT_artificial, 1);
8819 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8820 add_AT_loc (decl_die, DW_AT_location, loc);
8822 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8823 break;
8828 /* Note that the block of subscript information for an array type also
8829 includes information about the element type of type given array type. */
8831 static void
8832 add_subscript_info (type_die, type)
8833 register dw_die_ref type_die;
8834 register tree type;
8836 #ifndef MIPS_DEBUGGING_INFO
8837 register unsigned dimension_number;
8838 #endif
8839 register tree lower, upper;
8840 register dw_die_ref subrange_die;
8842 /* The GNU compilers represent multidimensional array types as sequences of
8843 one dimensional array types whose element types are themselves array
8844 types. Here we squish that down, so that each multidimensional array
8845 type gets only one array_type DIE in the Dwarf debugging info. The draft
8846 Dwarf specification say that we are allowed to do this kind of
8847 compression in C (because there is no difference between an array or
8848 arrays and a multidimensional array in C) but for other source languages
8849 (e.g. Ada) we probably shouldn't do this. */
8851 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8852 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8853 We work around this by disabling this feature. See also
8854 gen_array_type_die. */
8855 #ifndef MIPS_DEBUGGING_INFO
8856 for (dimension_number = 0;
8857 TREE_CODE (type) == ARRAY_TYPE;
8858 type = TREE_TYPE (type), dimension_number++)
8860 #endif
8861 register tree domain = TYPE_DOMAIN (type);
8863 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8864 and (in GNU C only) variable bounds. Handle all three forms
8865 here. */
8866 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8867 if (domain)
8869 /* We have an array type with specified bounds. */
8870 lower = TYPE_MIN_VALUE (domain);
8871 upper = TYPE_MAX_VALUE (domain);
8873 /* define the index type. */
8874 if (TREE_TYPE (domain))
8876 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8877 TREE_TYPE field. We can't emit debug info for this
8878 because it is an unnamed integral type. */
8879 if (TREE_CODE (domain) == INTEGER_TYPE
8880 && TYPE_NAME (domain) == NULL_TREE
8881 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8882 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8884 else
8885 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8886 type_die);
8889 /* ??? If upper is NULL, the array has unspecified length,
8890 but it does have a lower bound. This happens with Fortran
8891 dimension arr(N:*)
8892 Since the debugger is definitely going to need to know N
8893 to produce useful results, go ahead and output the lower
8894 bound solo, and hope the debugger can cope. */
8896 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8897 if (upper)
8898 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8900 else
8901 /* We have an array type with an unspecified length. The DWARF-2
8902 spec does not say how to handle this; let's just leave out the
8903 bounds. */
8906 #ifndef MIPS_DEBUGGING_INFO
8908 #endif
8911 static void
8912 add_byte_size_attribute (die, tree_node)
8913 dw_die_ref die;
8914 register tree tree_node;
8916 register unsigned size;
8918 switch (TREE_CODE (tree_node))
8920 case ERROR_MARK:
8921 size = 0;
8922 break;
8923 case ENUMERAL_TYPE:
8924 case RECORD_TYPE:
8925 case UNION_TYPE:
8926 case QUAL_UNION_TYPE:
8927 size = int_size_in_bytes (tree_node);
8928 break;
8929 case FIELD_DECL:
8930 /* For a data member of a struct or union, the DW_AT_byte_size is
8931 generally given as the number of bytes normally allocated for an
8932 object of the *declared* type of the member itself. This is true
8933 even for bit-fields. */
8934 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8935 break;
8936 default:
8937 abort ();
8940 /* Note that `size' might be -1 when we get to this point. If it is, that
8941 indicates that the byte size of the entity in question is variable. We
8942 have no good way of expressing this fact in Dwarf at the present time,
8943 so just let the -1 pass on through. */
8945 add_AT_unsigned (die, DW_AT_byte_size, size);
8948 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8949 which specifies the distance in bits from the highest order bit of the
8950 "containing object" for the bit-field to the highest order bit of the
8951 bit-field itself.
8953 For any given bit-field, the "containing object" is a hypothetical
8954 object (of some integral or enum type) within which the given bit-field
8955 lives. The type of this hypothetical "containing object" is always the
8956 same as the declared type of the individual bit-field itself. The
8957 determination of the exact location of the "containing object" for a
8958 bit-field is rather complicated. It's handled by the
8959 `field_byte_offset' function (above).
8961 Note that it is the size (in bytes) of the hypothetical "containing object"
8962 which will be given in the DW_AT_byte_size attribute for this bit-field.
8963 (See `byte_size_attribute' above). */
8965 static inline void
8966 add_bit_offset_attribute (die, decl)
8967 register dw_die_ref die;
8968 register tree decl;
8970 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8971 tree type = DECL_BIT_FIELD_TYPE (decl);
8972 HOST_WIDE_INT bitpos_int;
8973 HOST_WIDE_INT highest_order_object_bit_offset;
8974 HOST_WIDE_INT highest_order_field_bit_offset;
8975 HOST_WIDE_INT unsigned bit_offset;
8977 /* Must be a field and a bit field. */
8978 if (!type
8979 || TREE_CODE (decl) != FIELD_DECL)
8980 abort ();
8982 /* We can't yet handle bit-fields whose offsets are variable, so if we
8983 encounter such things, just return without generating any attribute
8984 whatsoever. Likewise for variable or too large size. */
8985 if (! host_integerp (bit_position (decl), 0)
8986 || ! host_integerp (DECL_SIZE (decl), 1))
8987 return;
8989 bitpos_int = int_bit_position (decl);
8991 /* Note that the bit offset is always the distance (in bits) from the
8992 highest-order bit of the "containing object" to the highest-order bit of
8993 the bit-field itself. Since the "high-order end" of any object or field
8994 is different on big-endian and little-endian machines, the computation
8995 below must take account of these differences. */
8996 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
8997 highest_order_field_bit_offset = bitpos_int;
8999 if (! BYTES_BIG_ENDIAN)
9001 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9002 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9005 bit_offset
9006 = (! BYTES_BIG_ENDIAN
9007 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9008 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9010 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9013 /* For a FIELD_DECL node which represents a bit field, output an attribute
9014 which specifies the length in bits of the given field. */
9016 static inline void
9017 add_bit_size_attribute (die, decl)
9018 register dw_die_ref die;
9019 register tree decl;
9021 /* Must be a field and a bit field. */
9022 if (TREE_CODE (decl) != FIELD_DECL
9023 || ! DECL_BIT_FIELD_TYPE (decl))
9024 abort ();
9026 if (host_integerp (DECL_SIZE (decl), 1))
9027 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9030 /* If the compiled language is ANSI C, then add a 'prototyped'
9031 attribute, if arg types are given for the parameters of a function. */
9033 static inline void
9034 add_prototyped_attribute (die, func_type)
9035 register dw_die_ref die;
9036 register tree func_type;
9038 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9039 && TYPE_ARG_TYPES (func_type) != NULL)
9040 add_AT_flag (die, DW_AT_prototyped, 1);
9043 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9044 by looking in either the type declaration or object declaration
9045 equate table. */
9047 static inline void
9048 add_abstract_origin_attribute (die, origin)
9049 register dw_die_ref die;
9050 register tree origin;
9052 dw_die_ref origin_die = NULL;
9054 if (TREE_CODE (origin) != FUNCTION_DECL)
9056 /* We may have gotten separated from the block for the inlined
9057 function, if we're in an exception handler or some such; make
9058 sure that the abstract function has been written out.
9060 Doing this for nested functions is wrong, however; functions are
9061 distinct units, and our context might not even be inline. */
9062 tree fn = origin;
9063 if (TYPE_P (fn))
9064 fn = TYPE_STUB_DECL (fn);
9065 fn = decl_function_context (fn);
9066 if (fn)
9067 dwarf2out_abstract_function (fn);
9070 if (DECL_P (origin))
9071 origin_die = lookup_decl_die (origin);
9072 else if (TYPE_P (origin))
9073 origin_die = lookup_type_die (origin);
9075 if (origin_die == NULL)
9076 abort ();
9078 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9081 /* We do not currently support the pure_virtual attribute. */
9083 static inline void
9084 add_pure_or_virtual_attribute (die, func_decl)
9085 register dw_die_ref die;
9086 register tree func_decl;
9088 if (DECL_VINDEX (func_decl))
9090 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9092 if (host_integerp (DECL_VINDEX (func_decl), 0))
9093 add_AT_loc (die, DW_AT_vtable_elem_location,
9094 new_loc_descr (DW_OP_constu,
9095 tree_low_cst (DECL_VINDEX (func_decl), 0),
9096 0));
9098 /* GNU extension: Record what type this method came from originally. */
9099 if (debug_info_level > DINFO_LEVEL_TERSE)
9100 add_AT_die_ref (die, DW_AT_containing_type,
9101 lookup_type_die (DECL_CONTEXT (func_decl)));
9105 /* Add source coordinate attributes for the given decl. */
9107 static void
9108 add_src_coords_attributes (die, decl)
9109 register dw_die_ref die;
9110 register tree decl;
9112 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9114 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9115 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9118 /* Add an DW_AT_name attribute and source coordinate attribute for the
9119 given decl, but only if it actually has a name. */
9121 static void
9122 add_name_and_src_coords_attributes (die, decl)
9123 register dw_die_ref die;
9124 register tree decl;
9126 register tree decl_name;
9128 decl_name = DECL_NAME (decl);
9129 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9131 add_name_attribute (die, dwarf2_name (decl, 0));
9132 if (! DECL_ARTIFICIAL (decl))
9133 add_src_coords_attributes (die, decl);
9135 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9136 && TREE_PUBLIC (decl)
9137 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9138 && !DECL_ABSTRACT (decl))
9139 add_AT_string (die, DW_AT_MIPS_linkage_name,
9140 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9144 /* Push a new declaration scope. */
9146 static void
9147 push_decl_scope (scope)
9148 tree scope;
9150 VARRAY_PUSH_TREE (decl_scope_table, scope);
9153 /* Pop a declaration scope. */
9154 static inline void
9155 pop_decl_scope ()
9157 if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0)
9158 abort ();
9159 VARRAY_POP (decl_scope_table);
9162 /* Return the DIE for the scope that immediately contains this type.
9163 Non-named types get global scope. Named types nested in other
9164 types get their containing scope if it's open, or global scope
9165 otherwise. All other types (i.e. function-local named types) get
9166 the current active scope. */
9168 static dw_die_ref
9169 scope_die_for (t, context_die)
9170 register tree t;
9171 register dw_die_ref context_die;
9173 register dw_die_ref scope_die = NULL;
9174 register tree containing_scope;
9175 register int i;
9177 /* Non-types always go in the current scope. */
9178 if (! TYPE_P (t))
9179 abort ();
9181 containing_scope = TYPE_CONTEXT (t);
9183 /* Ignore namespaces for the moment. */
9184 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9185 containing_scope = NULL_TREE;
9187 /* Ignore function type "scopes" from the C frontend. They mean that
9188 a tagged type is local to a parmlist of a function declarator, but
9189 that isn't useful to DWARF. */
9190 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9191 containing_scope = NULL_TREE;
9193 if (containing_scope == NULL_TREE)
9194 scope_die = comp_unit_die;
9195 else if (TYPE_P (containing_scope))
9197 /* For types, we can just look up the appropriate DIE. But
9198 first we check to see if we're in the middle of emitting it
9199 so we know where the new DIE should go. */
9201 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
9202 if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
9203 break;
9205 if (i < 0)
9207 if (debug_info_level > DINFO_LEVEL_TERSE
9208 && !TREE_ASM_WRITTEN (containing_scope))
9209 abort ();
9211 /* If none of the current dies are suitable, we get file scope. */
9212 scope_die = comp_unit_die;
9214 else
9215 scope_die = lookup_type_die (containing_scope);
9217 else
9218 scope_die = context_die;
9220 return scope_die;
9223 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
9225 static inline int local_scope_p PARAMS ((dw_die_ref));
9226 static inline int
9227 local_scope_p (context_die)
9228 dw_die_ref context_die;
9230 for (; context_die; context_die = context_die->die_parent)
9231 if (context_die->die_tag == DW_TAG_inlined_subroutine
9232 || context_die->die_tag == DW_TAG_subprogram)
9233 return 1;
9234 return 0;
9237 /* Returns nonzero iff CONTEXT_DIE is a class. */
9239 static inline int class_scope_p PARAMS ((dw_die_ref));
9240 static inline int
9241 class_scope_p (context_die)
9242 dw_die_ref context_die;
9244 return (context_die
9245 && (context_die->die_tag == DW_TAG_structure_type
9246 || context_die->die_tag == DW_TAG_union_type));
9249 /* Many forms of DIEs require a "type description" attribute. This
9250 routine locates the proper "type descriptor" die for the type given
9251 by 'type', and adds an DW_AT_type attribute below the given die. */
9253 static void
9254 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9255 register dw_die_ref object_die;
9256 register tree type;
9257 register int decl_const;
9258 register int decl_volatile;
9259 register dw_die_ref context_die;
9261 register enum tree_code code = TREE_CODE (type);
9262 register dw_die_ref type_die = NULL;
9264 /* ??? If this type is an unnamed subrange type of an integral or
9265 floating-point type, use the inner type. This is because we have no
9266 support for unnamed types in base_type_die. This can happen if this is
9267 an Ada subrange type. Correct solution is emit a subrange type die. */
9268 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9269 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9270 type = TREE_TYPE (type), code = TREE_CODE (type);
9272 if (code == ERROR_MARK)
9273 return;
9275 /* Handle a special case. For functions whose return type is void, we
9276 generate *no* type attribute. (Note that no object may have type
9277 `void', so this only applies to function return types). */
9278 if (code == VOID_TYPE)
9279 return;
9281 type_die = modified_type_die (type,
9282 decl_const || TYPE_READONLY (type),
9283 decl_volatile || TYPE_VOLATILE (type),
9284 context_die);
9285 if (type_die != NULL)
9286 add_AT_die_ref (object_die, DW_AT_type, type_die);
9289 /* Given a tree pointer to a struct, class, union, or enum type node, return
9290 a pointer to the (string) tag name for the given type, or zero if the type
9291 was declared without a tag. */
9293 static const char *
9294 type_tag (type)
9295 register tree type;
9297 register const char *name = 0;
9299 if (TYPE_NAME (type) != 0)
9301 register tree t = 0;
9303 /* Find the IDENTIFIER_NODE for the type name. */
9304 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9305 t = TYPE_NAME (type);
9307 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9308 a TYPE_DECL node, regardless of whether or not a `typedef' was
9309 involved. */
9310 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9311 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9312 t = DECL_NAME (TYPE_NAME (type));
9314 /* Now get the name as a string, or invent one. */
9315 if (t != 0)
9316 name = IDENTIFIER_POINTER (t);
9319 return (name == 0 || *name == '\0') ? 0 : name;
9322 /* Return the type associated with a data member, make a special check
9323 for bit field types. */
9325 static inline tree
9326 member_declared_type (member)
9327 register tree member;
9329 return (DECL_BIT_FIELD_TYPE (member)
9330 ? DECL_BIT_FIELD_TYPE (member)
9331 : TREE_TYPE (member));
9334 /* Get the decl's label, as described by its RTL. This may be different
9335 from the DECL_NAME name used in the source file. */
9337 #if 0
9338 static const char *
9339 decl_start_label (decl)
9340 register tree decl;
9342 rtx x;
9343 const char *fnname;
9344 x = DECL_RTL (decl);
9345 if (GET_CODE (x) != MEM)
9346 abort ();
9348 x = XEXP (x, 0);
9349 if (GET_CODE (x) != SYMBOL_REF)
9350 abort ();
9352 fnname = XSTR (x, 0);
9353 return fnname;
9355 #endif
9357 /* These routines generate the internal representation of the DIE's for
9358 the compilation unit. Debugging information is collected by walking
9359 the declaration trees passed in from dwarf2out_decl(). */
9361 static void
9362 gen_array_type_die (type, context_die)
9363 register tree type;
9364 register dw_die_ref context_die;
9366 register dw_die_ref scope_die = scope_die_for (type, context_die);
9367 register dw_die_ref array_die;
9368 register tree element_type;
9370 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9371 the inner array type comes before the outer array type. Thus we must
9372 call gen_type_die before we call new_die. See below also. */
9373 #ifdef MIPS_DEBUGGING_INFO
9374 gen_type_die (TREE_TYPE (type), context_die);
9375 #endif
9377 array_die = new_die (DW_TAG_array_type, scope_die);
9379 #if 0
9380 /* We default the array ordering. SDB will probably do
9381 the right things even if DW_AT_ordering is not present. It's not even
9382 an issue until we start to get into multidimensional arrays anyway. If
9383 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9384 then we'll have to put the DW_AT_ordering attribute back in. (But if
9385 and when we find out that we need to put these in, we will only do so
9386 for multidimensional arrays. */
9387 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9388 #endif
9390 #ifdef MIPS_DEBUGGING_INFO
9391 /* The SGI compilers handle arrays of unknown bound by setting
9392 AT_declaration and not emitting any subrange DIEs. */
9393 if (! TYPE_DOMAIN (type))
9394 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9395 else
9396 #endif
9397 add_subscript_info (array_die, type);
9399 add_name_attribute (array_die, type_tag (type));
9400 equate_type_number_to_die (type, array_die);
9402 /* Add representation of the type of the elements of this array type. */
9403 element_type = TREE_TYPE (type);
9405 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9406 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9407 We work around this by disabling this feature. See also
9408 add_subscript_info. */
9409 #ifndef MIPS_DEBUGGING_INFO
9410 while (TREE_CODE (element_type) == ARRAY_TYPE)
9411 element_type = TREE_TYPE (element_type);
9413 gen_type_die (element_type, context_die);
9414 #endif
9416 add_type_attribute (array_die, element_type, 0, 0, context_die);
9419 static void
9420 gen_set_type_die (type, context_die)
9421 register tree type;
9422 register dw_die_ref context_die;
9424 register dw_die_ref type_die
9425 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9427 equate_type_number_to_die (type, type_die);
9428 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9431 #if 0
9432 static void
9433 gen_entry_point_die (decl, context_die)
9434 register tree decl;
9435 register dw_die_ref context_die;
9437 register tree origin = decl_ultimate_origin (decl);
9438 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9439 if (origin != NULL)
9440 add_abstract_origin_attribute (decl_die, origin);
9441 else
9443 add_name_and_src_coords_attributes (decl_die, decl);
9444 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9445 0, 0, context_die);
9448 if (DECL_ABSTRACT (decl))
9449 equate_decl_number_to_die (decl, decl_die);
9450 else
9451 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9453 #endif
9455 /* Remember a type in the incomplete_types_list. */
9456 static void
9457 add_incomplete_type (type)
9458 tree type;
9460 VARRAY_PUSH_TREE (incomplete_types, type);
9463 /* Walk through the list of incomplete types again, trying once more to
9464 emit full debugging info for them. */
9466 static void
9467 retry_incomplete_types ()
9469 int i;
9470 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
9472 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
9476 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9478 static void
9479 gen_inlined_enumeration_type_die (type, context_die)
9480 register tree type;
9481 register dw_die_ref context_die;
9483 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9484 context_die);
9485 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9486 be incomplete and such types are not marked. */
9487 add_abstract_origin_attribute (type_die, type);
9490 /* Generate a DIE to represent an inlined instance of a structure type. */
9492 static void
9493 gen_inlined_structure_type_die (type, context_die)
9494 register tree type;
9495 register dw_die_ref context_die;
9497 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9499 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9500 be incomplete and such types are not marked. */
9501 add_abstract_origin_attribute (type_die, type);
9504 /* Generate a DIE to represent an inlined instance of a union type. */
9506 static void
9507 gen_inlined_union_type_die (type, context_die)
9508 register tree type;
9509 register dw_die_ref context_die;
9511 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9513 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9514 be incomplete and such types are not marked. */
9515 add_abstract_origin_attribute (type_die, type);
9518 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9519 include all of the information about the enumeration values also. Each
9520 enumerated type name/value is listed as a child of the enumerated type
9521 DIE. */
9523 static void
9524 gen_enumeration_type_die (type, context_die)
9525 register tree type;
9526 register dw_die_ref context_die;
9528 register dw_die_ref type_die = lookup_type_die (type);
9530 if (type_die == NULL)
9532 type_die = new_die (DW_TAG_enumeration_type,
9533 scope_die_for (type, context_die));
9534 equate_type_number_to_die (type, type_die);
9535 add_name_attribute (type_die, type_tag (type));
9537 else if (! TYPE_SIZE (type))
9538 return;
9539 else
9540 remove_AT (type_die, DW_AT_declaration);
9542 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9543 given enum type is incomplete, do not generate the DW_AT_byte_size
9544 attribute or the DW_AT_element_list attribute. */
9545 if (TYPE_SIZE (type))
9547 register tree link;
9549 TREE_ASM_WRITTEN (type) = 1;
9550 add_byte_size_attribute (type_die, type);
9551 if (TYPE_STUB_DECL (type) != NULL_TREE)
9552 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9554 /* If the first reference to this type was as the return type of an
9555 inline function, then it may not have a parent. Fix this now. */
9556 if (type_die->die_parent == NULL)
9557 add_child_die (scope_die_for (type, context_die), type_die);
9559 for (link = TYPE_FIELDS (type);
9560 link != NULL; link = TREE_CHAIN (link))
9562 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9564 add_name_attribute (enum_die,
9565 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9567 if (host_integerp (TREE_VALUE (link), 0))
9569 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9570 add_AT_int (enum_die, DW_AT_const_value,
9571 tree_low_cst (TREE_VALUE (link), 0));
9572 else
9573 add_AT_unsigned (enum_die, DW_AT_const_value,
9574 tree_low_cst (TREE_VALUE (link), 0));
9578 else
9579 add_AT_flag (type_die, DW_AT_declaration, 1);
9582 /* Generate a DIE to represent either a real live formal parameter decl or to
9583 represent just the type of some formal parameter position in some function
9584 type.
9586 Note that this routine is a bit unusual because its argument may be a
9587 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9588 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9589 node. If it's the former then this function is being called to output a
9590 DIE to represent a formal parameter object (or some inlining thereof). If
9591 it's the latter, then this function is only being called to output a
9592 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9593 argument type of some subprogram type. */
9595 static dw_die_ref
9596 gen_formal_parameter_die (node, context_die)
9597 register tree node;
9598 register dw_die_ref context_die;
9600 register dw_die_ref parm_die
9601 = new_die (DW_TAG_formal_parameter, context_die);
9602 register tree origin;
9604 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9606 case 'd':
9607 origin = decl_ultimate_origin (node);
9608 if (origin != NULL)
9609 add_abstract_origin_attribute (parm_die, origin);
9610 else
9612 add_name_and_src_coords_attributes (parm_die, node);
9613 add_type_attribute (parm_die, TREE_TYPE (node),
9614 TREE_READONLY (node),
9615 TREE_THIS_VOLATILE (node),
9616 context_die);
9617 if (DECL_ARTIFICIAL (node))
9618 add_AT_flag (parm_die, DW_AT_artificial, 1);
9621 equate_decl_number_to_die (node, parm_die);
9622 if (! DECL_ABSTRACT (node))
9623 add_location_or_const_value_attribute (parm_die, node);
9625 break;
9627 case 't':
9628 /* We were called with some kind of a ..._TYPE node. */
9629 add_type_attribute (parm_die, node, 0, 0, context_die);
9630 break;
9632 default:
9633 abort ();
9636 return parm_die;
9639 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9640 at the end of an (ANSI prototyped) formal parameters list. */
9642 static void
9643 gen_unspecified_parameters_die (decl_or_type, context_die)
9644 register tree decl_or_type ATTRIBUTE_UNUSED;
9645 register dw_die_ref context_die;
9647 new_die (DW_TAG_unspecified_parameters, context_die);
9650 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9651 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9652 parameters as specified in some function type specification (except for
9653 those which appear as part of a function *definition*). */
9655 static void
9656 gen_formal_types_die (function_or_method_type, context_die)
9657 register tree function_or_method_type;
9658 register dw_die_ref context_die;
9660 register tree link;
9661 register tree formal_type = NULL;
9662 register tree first_parm_type;
9663 tree arg;
9665 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
9667 arg = DECL_ARGUMENTS (function_or_method_type);
9668 function_or_method_type = TREE_TYPE (function_or_method_type);
9670 else
9671 arg = NULL_TREE;
9673 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9675 /* Make our first pass over the list of formal parameter types and output a
9676 DW_TAG_formal_parameter DIE for each one. */
9677 for (link = first_parm_type; link; )
9679 register dw_die_ref parm_die;
9681 formal_type = TREE_VALUE (link);
9682 if (formal_type == void_type_node)
9683 break;
9685 /* Output a (nameless) DIE to represent the formal parameter itself. */
9686 parm_die = gen_formal_parameter_die (formal_type, context_die);
9687 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
9688 && link == first_parm_type)
9689 || (arg && DECL_ARTIFICIAL (arg)))
9690 add_AT_flag (parm_die, DW_AT_artificial, 1);
9692 link = TREE_CHAIN (link);
9693 if (arg)
9694 arg = TREE_CHAIN (arg);
9697 /* If this function type has an ellipsis, add a
9698 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9699 if (formal_type != void_type_node)
9700 gen_unspecified_parameters_die (function_or_method_type, context_die);
9702 /* Make our second (and final) pass over the list of formal parameter types
9703 and output DIEs to represent those types (as necessary). */
9704 for (link = TYPE_ARG_TYPES (function_or_method_type);
9705 link;
9706 link = TREE_CHAIN (link))
9708 formal_type = TREE_VALUE (link);
9709 if (formal_type == void_type_node)
9710 break;
9712 gen_type_die (formal_type, context_die);
9716 /* We want to generate the DIE for TYPE so that we can generate the
9717 die for MEMBER, which has been defined; we will need to refer back
9718 to the member declaration nested within TYPE. If we're trying to
9719 generate minimal debug info for TYPE, processing TYPE won't do the
9720 trick; we need to attach the member declaration by hand. */
9722 static void
9723 gen_type_die_for_member (type, member, context_die)
9724 tree type, member;
9725 dw_die_ref context_die;
9727 gen_type_die (type, context_die);
9729 /* If we're trying to avoid duplicate debug info, we may not have
9730 emitted the member decl for this function. Emit it now. */
9731 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9732 && ! lookup_decl_die (member))
9734 if (decl_ultimate_origin (member))
9735 abort ();
9737 push_decl_scope (type);
9738 if (TREE_CODE (member) == FUNCTION_DECL)
9739 gen_subprogram_die (member, lookup_type_die (type));
9740 else
9741 gen_variable_die (member, lookup_type_die (type));
9742 pop_decl_scope ();
9746 /* Generate the DWARF2 info for the "abstract" instance
9747 of a function which we may later generate inlined and/or
9748 out-of-line instances of. */
9750 static void
9751 dwarf2out_abstract_function (decl)
9752 tree decl;
9754 register dw_die_ref old_die;
9755 tree save_fn;
9756 tree context;
9757 int was_abstract = DECL_ABSTRACT (decl);
9759 /* Make sure we have the actual abstract inline, not a clone. */
9760 decl = DECL_ORIGIN (decl);
9762 old_die = lookup_decl_die (decl);
9763 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9764 /* We've already generated the abstract instance. */
9765 return;
9767 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
9768 we don't get confused by DECL_ABSTRACT. */
9769 if (debug_info_level > DINFO_LEVEL_TERSE)
9771 context = decl_class_context (decl);
9772 if (context)
9773 gen_type_die_for_member
9774 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
9777 /* Pretend we've just finished compiling this function. */
9778 save_fn = current_function_decl;
9779 current_function_decl = decl;
9781 set_decl_abstract_flags (decl, 1);
9782 dwarf2out_decl (decl);
9783 if (! was_abstract)
9784 set_decl_abstract_flags (decl, 0);
9786 current_function_decl = save_fn;
9789 /* Generate a DIE to represent a declared function (either file-scope or
9790 block-local). */
9792 static void
9793 gen_subprogram_die (decl, context_die)
9794 register tree decl;
9795 register dw_die_ref context_die;
9797 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9798 register tree origin = decl_ultimate_origin (decl);
9799 register dw_die_ref subr_die;
9800 register rtx fp_reg;
9801 register tree fn_arg_types;
9802 register tree outer_scope;
9803 register dw_die_ref old_die = lookup_decl_die (decl);
9804 register int declaration = (current_function_decl != decl
9805 || class_scope_p (context_die));
9807 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9808 be true, if we started to generate the abstract instance of an inline,
9809 decided to output its containing class, and proceeded to emit the
9810 declaration of the inline from the member list for the class. In that
9811 case, `declaration' takes priority; we'll get back to the abstract
9812 instance when we're done with the class. */
9814 /* The class-scope declaration DIE must be the primary DIE. */
9815 if (origin && declaration && class_scope_p (context_die))
9817 origin = NULL;
9818 if (old_die)
9819 abort ();
9822 if (origin != NULL)
9824 if (declaration && ! local_scope_p (context_die))
9825 abort ();
9827 /* Fixup die_parent for the abstract instance of a nested
9828 inline function. */
9829 if (old_die && old_die->die_parent == NULL)
9830 add_child_die (context_die, old_die);
9832 subr_die = new_die (DW_TAG_subprogram, context_die);
9833 add_abstract_origin_attribute (subr_die, origin);
9835 else if (old_die)
9837 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9839 if (!get_AT_flag (old_die, DW_AT_declaration)
9840 /* We can have a normal definition following an inline one in the
9841 case of redefinition of GNU C extern inlines.
9842 It seems reasonable to use AT_specification in this case. */
9843 && !get_AT_unsigned (old_die, DW_AT_inline))
9845 /* ??? This can happen if there is a bug in the program, for
9846 instance, if it has duplicate function definitions. Ideally,
9847 we should detect this case and ignore it. For now, if we have
9848 already reported an error, any error at all, then assume that
9849 we got here because of a input error, not a dwarf2 bug. */
9850 if (errorcount)
9851 return;
9852 abort ();
9855 /* If the definition comes from the same place as the declaration,
9856 maybe use the old DIE. We always want the DIE for this function
9857 that has the *_pc attributes to be under comp_unit_die so the
9858 debugger can find it. We also need to do this for abstract
9859 instances of inlines, since the spec requires the out-of-line copy
9860 to have the same parent. For local class methods, this doesn't
9861 apply; we just use the old DIE. */
9862 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
9863 && (DECL_ARTIFICIAL (decl)
9864 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9865 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9866 == (unsigned) DECL_SOURCE_LINE (decl)))))
9868 subr_die = old_die;
9870 /* Clear out the declaration attribute and the parm types. */
9871 remove_AT (subr_die, DW_AT_declaration);
9872 remove_children (subr_die);
9874 else
9876 subr_die = new_die (DW_TAG_subprogram, context_die);
9877 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9878 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9879 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9880 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9881 != (unsigned) DECL_SOURCE_LINE (decl))
9882 add_AT_unsigned
9883 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9886 else
9888 subr_die = new_die (DW_TAG_subprogram, context_die);
9890 if (TREE_PUBLIC (decl))
9891 add_AT_flag (subr_die, DW_AT_external, 1);
9893 add_name_and_src_coords_attributes (subr_die, decl);
9894 if (debug_info_level > DINFO_LEVEL_TERSE)
9896 register tree type = TREE_TYPE (decl);
9898 add_prototyped_attribute (subr_die, type);
9899 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9902 add_pure_or_virtual_attribute (subr_die, decl);
9903 if (DECL_ARTIFICIAL (decl))
9904 add_AT_flag (subr_die, DW_AT_artificial, 1);
9905 if (TREE_PROTECTED (decl))
9906 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9907 else if (TREE_PRIVATE (decl))
9908 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9911 if (declaration)
9913 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9915 add_AT_flag (subr_die, DW_AT_declaration, 1);
9917 /* The first time we see a member function, it is in the context of
9918 the class to which it belongs. We make sure of this by emitting
9919 the class first. The next time is the definition, which is
9920 handled above. The two may come from the same source text. */
9921 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9922 equate_decl_number_to_die (decl, subr_die);
9925 else if (DECL_ABSTRACT (decl))
9927 if (DECL_INLINE (decl) && !flag_no_inline)
9929 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9930 inline functions, but not for extern inline functions.
9931 We can't get this completely correct because information
9932 about whether the function was declared inline is not
9933 saved anywhere. */
9934 if (DECL_DEFER_OUTPUT (decl))
9935 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9936 else
9937 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9939 else
9940 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9942 equate_decl_number_to_die (decl, subr_die);
9944 else if (!DECL_EXTERNAL (decl))
9946 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9947 equate_decl_number_to_die (decl, subr_die);
9949 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9950 current_funcdef_number);
9951 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
9952 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
9953 current_funcdef_number);
9954 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
9956 add_pubname (decl, subr_die);
9957 add_arange (decl, subr_die);
9959 #ifdef MIPS_DEBUGGING_INFO
9960 /* Add a reference to the FDE for this routine. */
9961 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
9962 #endif
9964 /* Define the "frame base" location for this routine. We use the
9965 frame pointer or stack pointer registers, since the RTL for local
9966 variables is relative to one of them. */
9967 fp_reg
9968 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
9969 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
9971 #if 0
9972 /* ??? This fails for nested inline functions, because context_display
9973 is not part of the state saved/restored for inline functions. */
9974 if (current_function_needs_context)
9975 add_AT_location_description (subr_die, DW_AT_static_link,
9976 lookup_static_chain (decl));
9977 #endif
9980 /* Now output descriptions of the arguments for this function. This gets
9981 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
9982 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
9983 `...' at the end of the formal parameter list. In order to find out if
9984 there was a trailing ellipsis or not, we must instead look at the type
9985 associated with the FUNCTION_DECL. This will be a node of type
9986 FUNCTION_TYPE. If the chain of type nodes hanging off of this
9987 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
9988 an ellipsis at the end. */
9990 /* In the case where we are describing a mere function declaration, all we
9991 need to do here (and all we *can* do here) is to describe the *types* of
9992 its formal parameters. */
9993 if (debug_info_level <= DINFO_LEVEL_TERSE)
9995 else if (declaration)
9996 gen_formal_types_die (decl, subr_die);
9997 else
9999 /* Generate DIEs to represent all known formal parameters */
10000 register tree arg_decls = DECL_ARGUMENTS (decl);
10001 register tree parm;
10003 /* When generating DIEs, generate the unspecified_parameters DIE
10004 instead if we come across the arg "__builtin_va_alist" */
10005 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10006 if (TREE_CODE (parm) == PARM_DECL)
10008 if (DECL_NAME (parm)
10009 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10010 "__builtin_va_alist"))
10011 gen_unspecified_parameters_die (parm, subr_die);
10012 else
10013 gen_decl_die (parm, subr_die);
10016 /* Decide whether we need a unspecified_parameters DIE at the end.
10017 There are 2 more cases to do this for: 1) the ansi ... declaration -
10018 this is detectable when the end of the arg list is not a
10019 void_type_node 2) an unprototyped function declaration (not a
10020 definition). This just means that we have no info about the
10021 parameters at all. */
10022 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10023 if (fn_arg_types != NULL)
10025 /* this is the prototyped case, check for ... */
10026 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10027 gen_unspecified_parameters_die (decl, subr_die);
10029 else if (DECL_INITIAL (decl) == NULL_TREE)
10030 gen_unspecified_parameters_die (decl, subr_die);
10033 /* Output Dwarf info for all of the stuff within the body of the function
10034 (if it has one - it may be just a declaration). */
10035 outer_scope = DECL_INITIAL (decl);
10037 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
10038 node created to represent a function. This outermost BLOCK actually
10039 represents the outermost binding contour for the function, i.e. the
10040 contour in which the function's formal parameters and labels get
10041 declared. Curiously, it appears that the front end doesn't actually
10042 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
10043 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
10044 list for the function instead.) The BLOCK_VARS list for the
10045 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
10046 the function however, and we output DWARF info for those in
10047 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
10048 node representing the function's outermost pair of curly braces, and
10049 any blocks used for the base and member initializers of a C++
10050 constructor function. */
10051 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10053 current_function_has_inlines = 0;
10054 decls_for_scope (outer_scope, subr_die, 0);
10056 #if 0 && defined (MIPS_DEBUGGING_INFO)
10057 if (current_function_has_inlines)
10059 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10060 if (! comp_unit_has_inlines)
10062 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10063 comp_unit_has_inlines = 1;
10066 #endif
10070 /* Generate a DIE to represent a declared data object. */
10072 static void
10073 gen_variable_die (decl, context_die)
10074 register tree decl;
10075 register dw_die_ref context_die;
10077 register tree origin = decl_ultimate_origin (decl);
10078 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
10080 dw_die_ref old_die = lookup_decl_die (decl);
10081 int declaration = (DECL_EXTERNAL (decl)
10082 || class_scope_p (context_die));
10084 if (origin != NULL)
10085 add_abstract_origin_attribute (var_die, origin);
10086 /* Loop unrolling can create multiple blocks that refer to the same
10087 static variable, so we must test for the DW_AT_declaration flag. */
10088 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10089 copy decls and set the DECL_ABSTRACT flag on them instead of
10090 sharing them. */
10091 /* ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10092 else if (old_die && TREE_STATIC (decl)
10093 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10095 /* This is a definition of a C++ class level static. */
10096 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10097 if (DECL_NAME (decl))
10099 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10101 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10102 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10104 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10105 != (unsigned) DECL_SOURCE_LINE (decl))
10107 add_AT_unsigned (var_die, DW_AT_decl_line,
10108 DECL_SOURCE_LINE (decl));
10111 else
10113 add_name_and_src_coords_attributes (var_die, decl);
10114 add_type_attribute (var_die, TREE_TYPE (decl),
10115 TREE_READONLY (decl),
10116 TREE_THIS_VOLATILE (decl), context_die);
10118 if (TREE_PUBLIC (decl))
10119 add_AT_flag (var_die, DW_AT_external, 1);
10121 if (DECL_ARTIFICIAL (decl))
10122 add_AT_flag (var_die, DW_AT_artificial, 1);
10124 if (TREE_PROTECTED (decl))
10125 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10127 else if (TREE_PRIVATE (decl))
10128 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10131 if (declaration)
10132 add_AT_flag (var_die, DW_AT_declaration, 1);
10134 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10135 equate_decl_number_to_die (decl, var_die);
10137 if (! declaration && ! DECL_ABSTRACT (decl))
10139 add_location_or_const_value_attribute (var_die, decl);
10140 add_pubname (decl, var_die);
10142 else
10143 tree_add_const_value_attribute (var_die, decl);
10146 /* Generate a DIE to represent a label identifier. */
10148 static void
10149 gen_label_die (decl, context_die)
10150 register tree decl;
10151 register dw_die_ref context_die;
10153 register tree origin = decl_ultimate_origin (decl);
10154 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
10155 register rtx insn;
10156 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10158 if (origin != NULL)
10159 add_abstract_origin_attribute (lbl_die, origin);
10160 else
10161 add_name_and_src_coords_attributes (lbl_die, decl);
10163 if (DECL_ABSTRACT (decl))
10164 equate_decl_number_to_die (decl, lbl_die);
10165 else
10167 insn = DECL_RTL (decl);
10169 /* Deleted labels are programmer specified labels which have been
10170 eliminated because of various optimisations. We still emit them
10171 here so that it is possible to put breakpoints on them. */
10172 if (GET_CODE (insn) == CODE_LABEL
10173 || ((GET_CODE (insn) == NOTE
10174 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10176 /* When optimization is enabled (via -O) some parts of the compiler
10177 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10178 represent source-level labels which were explicitly declared by
10179 the user. This really shouldn't be happening though, so catch
10180 it if it ever does happen. */
10181 if (INSN_DELETED_P (insn))
10182 abort ();
10184 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10185 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10190 /* Generate a DIE for a lexical block. */
10192 static void
10193 gen_lexical_block_die (stmt, context_die, depth)
10194 register tree stmt;
10195 register dw_die_ref context_die;
10196 int depth;
10198 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
10199 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10201 if (! BLOCK_ABSTRACT (stmt))
10203 if (BLOCK_FRAGMENT_CHAIN (stmt))
10205 tree chain;
10207 add_AT_offset (stmt_die, DW_AT_ranges, add_ranges (stmt));
10209 chain = BLOCK_FRAGMENT_CHAIN (stmt);
10212 add_ranges (chain);
10213 chain = BLOCK_FRAGMENT_CHAIN (chain);
10215 while (chain);
10216 add_ranges (NULL);
10218 else
10220 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10221 BLOCK_NUMBER (stmt));
10222 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10223 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10224 BLOCK_NUMBER (stmt));
10225 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10229 decls_for_scope (stmt, stmt_die, depth);
10232 /* Generate a DIE for an inlined subprogram. */
10234 static void
10235 gen_inlined_subroutine_die (stmt, context_die, depth)
10236 register tree stmt;
10237 register dw_die_ref context_die;
10238 int depth;
10240 if (! BLOCK_ABSTRACT (stmt))
10242 register dw_die_ref subr_die
10243 = new_die (DW_TAG_inlined_subroutine, context_die);
10244 register tree decl = block_ultimate_origin (stmt);
10245 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10247 /* Emit info for the abstract instance first, if we haven't yet. */
10248 dwarf2out_abstract_function (decl);
10250 add_abstract_origin_attribute (subr_die, decl);
10251 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10252 BLOCK_NUMBER (stmt));
10253 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10254 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10255 BLOCK_NUMBER (stmt));
10256 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10257 decls_for_scope (stmt, subr_die, depth);
10258 current_function_has_inlines = 1;
10262 /* Generate a DIE for a field in a record, or structure. */
10264 static void
10265 gen_field_die (decl, context_die)
10266 register tree decl;
10267 register dw_die_ref context_die;
10269 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
10271 add_name_and_src_coords_attributes (decl_die, decl);
10272 add_type_attribute (decl_die, member_declared_type (decl),
10273 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10274 context_die);
10276 /* If this is a bit field... */
10277 if (DECL_BIT_FIELD_TYPE (decl))
10279 add_byte_size_attribute (decl_die, decl);
10280 add_bit_size_attribute (decl_die, decl);
10281 add_bit_offset_attribute (decl_die, decl);
10284 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10285 add_data_member_location_attribute (decl_die, decl);
10287 if (DECL_ARTIFICIAL (decl))
10288 add_AT_flag (decl_die, DW_AT_artificial, 1);
10290 if (TREE_PROTECTED (decl))
10291 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10293 else if (TREE_PRIVATE (decl))
10294 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10297 #if 0
10298 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10299 Use modified_type_die instead.
10300 We keep this code here just in case these types of DIEs may be needed to
10301 represent certain things in other languages (e.g. Pascal) someday. */
10302 static void
10303 gen_pointer_type_die (type, context_die)
10304 register tree type;
10305 register dw_die_ref context_die;
10307 register dw_die_ref ptr_die
10308 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
10310 equate_type_number_to_die (type, ptr_die);
10311 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10312 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10315 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10316 Use modified_type_die instead.
10317 We keep this code here just in case these types of DIEs may be needed to
10318 represent certain things in other languages (e.g. Pascal) someday. */
10319 static void
10320 gen_reference_type_die (type, context_die)
10321 register tree type;
10322 register dw_die_ref context_die;
10324 register dw_die_ref ref_die
10325 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
10327 equate_type_number_to_die (type, ref_die);
10328 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10329 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10331 #endif
10333 /* Generate a DIE for a pointer to a member type. */
10334 static void
10335 gen_ptr_to_mbr_type_die (type, context_die)
10336 register tree type;
10337 register dw_die_ref context_die;
10339 register dw_die_ref ptr_die
10340 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
10342 equate_type_number_to_die (type, ptr_die);
10343 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10344 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10345 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10348 /* Generate the DIE for the compilation unit. */
10350 static dw_die_ref
10351 gen_compile_unit_die (filename)
10352 register const char *filename;
10354 register dw_die_ref die;
10355 char producer[250];
10356 const char *wd = getpwd ();
10357 int language;
10359 die = new_die (DW_TAG_compile_unit, NULL);
10360 add_name_attribute (die, filename);
10362 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10363 add_AT_string (die, DW_AT_comp_dir, wd);
10365 sprintf (producer, "%s %s", language_string, version_string);
10367 #ifdef MIPS_DEBUGGING_INFO
10368 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10369 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10370 not appear in the producer string, the debugger reaches the conclusion
10371 that the object file is stripped and has no debugging information.
10372 To get the MIPS/SGI debugger to believe that there is debugging
10373 information in the object file, we add a -g to the producer string. */
10374 if (debug_info_level > DINFO_LEVEL_TERSE)
10375 strcat (producer, " -g");
10376 #endif
10378 add_AT_string (die, DW_AT_producer, producer);
10380 if (strcmp (language_string, "GNU C++") == 0)
10381 language = DW_LANG_C_plus_plus;
10382 else if (strcmp (language_string, "GNU Ada") == 0)
10383 language = DW_LANG_Ada83;
10384 else if (strcmp (language_string, "GNU F77") == 0)
10385 language = DW_LANG_Fortran77;
10386 else if (strcmp (language_string, "GNU Pascal") == 0)
10387 language = DW_LANG_Pascal83;
10388 else if (strcmp (language_string, "GNU Java") == 0)
10389 language = DW_LANG_Java;
10390 else if (flag_traditional)
10391 language = DW_LANG_C;
10392 else
10393 language = DW_LANG_C89;
10395 add_AT_unsigned (die, DW_AT_language, language);
10397 return die;
10400 /* Generate a DIE for a string type. */
10402 static void
10403 gen_string_type_die (type, context_die)
10404 register tree type;
10405 register dw_die_ref context_die;
10407 register dw_die_ref type_die
10408 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10410 equate_type_number_to_die (type, type_die);
10412 /* Fudge the string length attribute for now. */
10414 /* TODO: add string length info.
10415 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10416 bound_representation (upper_bound, 0, 'u'); */
10419 /* Generate the DIE for a base class. */
10421 static void
10422 gen_inheritance_die (binfo, context_die)
10423 register tree binfo;
10424 register dw_die_ref context_die;
10426 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10428 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10429 add_data_member_location_attribute (die, binfo);
10431 if (TREE_VIA_VIRTUAL (binfo))
10432 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10433 if (TREE_VIA_PUBLIC (binfo))
10434 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10435 else if (TREE_VIA_PROTECTED (binfo))
10436 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10439 /* Generate a DIE for a class member. */
10441 static void
10442 gen_member_die (type, context_die)
10443 register tree type;
10444 register dw_die_ref context_die;
10446 register tree member;
10447 dw_die_ref child;
10449 /* If this is not an incomplete type, output descriptions of each of its
10450 members. Note that as we output the DIEs necessary to represent the
10451 members of this record or union type, we will also be trying to output
10452 DIEs to represent the *types* of those members. However the `type'
10453 function (above) will specifically avoid generating type DIEs for member
10454 types *within* the list of member DIEs for this (containing) type execpt
10455 for those types (of members) which are explicitly marked as also being
10456 members of this (containing) type themselves. The g++ front- end can
10457 force any given type to be treated as a member of some other
10458 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10459 to point to the TREE node representing the appropriate (containing)
10460 type. */
10462 /* First output info about the base classes. */
10463 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10465 register tree bases = TYPE_BINFO_BASETYPES (type);
10466 register int n_bases = TREE_VEC_LENGTH (bases);
10467 register int i;
10469 for (i = 0; i < n_bases; i++)
10470 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10473 /* Now output info about the data members and type members. */
10474 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10476 /* If we thought we were generating minimal debug info for TYPE
10477 and then changed our minds, some of the member declarations
10478 may have already been defined. Don't define them again, but
10479 do put them in the right order. */
10481 child = lookup_decl_die (member);
10482 if (child)
10483 splice_child_die (context_die, child);
10484 else
10485 gen_decl_die (member, context_die);
10488 /* Now output info about the function members (if any). */
10489 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10491 /* Don't include clones in the member list. */
10492 if (DECL_ABSTRACT_ORIGIN (member))
10493 continue;
10495 child = lookup_decl_die (member);
10496 if (child)
10497 splice_child_die (context_die, child);
10498 else
10499 gen_decl_die (member, context_die);
10503 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10504 is set, we pretend that the type was never defined, so we only get the
10505 member DIEs needed by later specification DIEs. */
10507 static void
10508 gen_struct_or_union_type_die (type, context_die)
10509 register tree type;
10510 register dw_die_ref context_die;
10512 register dw_die_ref type_die = lookup_type_die (type);
10513 register dw_die_ref scope_die = 0;
10514 register int nested = 0;
10515 int complete = (TYPE_SIZE (type)
10516 && (! TYPE_STUB_DECL (type)
10517 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10519 if (type_die && ! complete)
10520 return;
10522 if (TYPE_CONTEXT (type) != NULL_TREE
10523 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10524 nested = 1;
10526 scope_die = scope_die_for (type, context_die);
10528 if (! type_die || (nested && scope_die == comp_unit_die))
10529 /* First occurrence of type or toplevel definition of nested class. */
10531 register dw_die_ref old_die = type_die;
10533 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10534 ? DW_TAG_structure_type : DW_TAG_union_type,
10535 scope_die);
10536 equate_type_number_to_die (type, type_die);
10537 if (old_die)
10538 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10539 else
10540 add_name_attribute (type_die, type_tag (type));
10542 else
10543 remove_AT (type_die, DW_AT_declaration);
10545 /* If this type has been completed, then give it a byte_size attribute and
10546 then give a list of members. */
10547 if (complete)
10549 /* Prevent infinite recursion in cases where the type of some member of
10550 this type is expressed in terms of this type itself. */
10551 TREE_ASM_WRITTEN (type) = 1;
10552 add_byte_size_attribute (type_die, type);
10553 if (TYPE_STUB_DECL (type) != NULL_TREE)
10554 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10556 /* If the first reference to this type was as the return type of an
10557 inline function, then it may not have a parent. Fix this now. */
10558 if (type_die->die_parent == NULL)
10559 add_child_die (scope_die, type_die);
10561 push_decl_scope (type);
10562 gen_member_die (type, type_die);
10563 pop_decl_scope ();
10565 /* GNU extension: Record what type our vtable lives in. */
10566 if (TYPE_VFIELD (type))
10568 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10570 gen_type_die (vtype, context_die);
10571 add_AT_die_ref (type_die, DW_AT_containing_type,
10572 lookup_type_die (vtype));
10575 else
10577 add_AT_flag (type_die, DW_AT_declaration, 1);
10579 /* We don't need to do this for function-local types. */
10580 if (! decl_function_context (TYPE_STUB_DECL (type)))
10581 add_incomplete_type (type);
10585 /* Generate a DIE for a subroutine _type_. */
10587 static void
10588 gen_subroutine_type_die (type, context_die)
10589 register tree type;
10590 register dw_die_ref context_die;
10592 register tree return_type = TREE_TYPE (type);
10593 register dw_die_ref subr_die
10594 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10596 equate_type_number_to_die (type, subr_die);
10597 add_prototyped_attribute (subr_die, type);
10598 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10599 gen_formal_types_die (type, subr_die);
10602 /* Generate a DIE for a type definition */
10604 static void
10605 gen_typedef_die (decl, context_die)
10606 register tree decl;
10607 register dw_die_ref context_die;
10609 register dw_die_ref type_die;
10610 register tree origin;
10612 if (TREE_ASM_WRITTEN (decl))
10613 return;
10614 TREE_ASM_WRITTEN (decl) = 1;
10616 type_die = new_die (DW_TAG_typedef, context_die);
10617 origin = decl_ultimate_origin (decl);
10618 if (origin != NULL)
10619 add_abstract_origin_attribute (type_die, origin);
10620 else
10622 register tree type;
10623 add_name_and_src_coords_attributes (type_die, decl);
10624 if (DECL_ORIGINAL_TYPE (decl))
10626 type = DECL_ORIGINAL_TYPE (decl);
10628 if (type == TREE_TYPE (decl))
10629 abort ();
10630 else
10631 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10633 else
10634 type = TREE_TYPE (decl);
10635 add_type_attribute (type_die, type, TREE_READONLY (decl),
10636 TREE_THIS_VOLATILE (decl), context_die);
10639 if (DECL_ABSTRACT (decl))
10640 equate_decl_number_to_die (decl, type_die);
10643 /* Generate a type description DIE. */
10645 static void
10646 gen_type_die (type, context_die)
10647 register tree type;
10648 register dw_die_ref context_die;
10650 int need_pop;
10652 if (type == NULL_TREE || type == error_mark_node)
10653 return;
10655 /* We are going to output a DIE to represent the unqualified version of
10656 this type (i.e. without any const or volatile qualifiers) so get the
10657 main variant (i.e. the unqualified version) of this type now. */
10658 type = type_main_variant (type);
10660 if (TREE_ASM_WRITTEN (type))
10661 return;
10663 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10664 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10666 TREE_ASM_WRITTEN (type) = 1;
10667 gen_decl_die (TYPE_NAME (type), context_die);
10668 return;
10671 switch (TREE_CODE (type))
10673 case ERROR_MARK:
10674 break;
10676 case POINTER_TYPE:
10677 case REFERENCE_TYPE:
10678 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10679 ensures that the gen_type_die recursion will terminate even if the
10680 type is recursive. Recursive types are possible in Ada. */
10681 /* ??? We could perhaps do this for all types before the switch
10682 statement. */
10683 TREE_ASM_WRITTEN (type) = 1;
10685 /* For these types, all that is required is that we output a DIE (or a
10686 set of DIEs) to represent the "basis" type. */
10687 gen_type_die (TREE_TYPE (type), context_die);
10688 break;
10690 case OFFSET_TYPE:
10691 /* This code is used for C++ pointer-to-data-member types.
10692 Output a description of the relevant class type. */
10693 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10695 /* Output a description of the type of the object pointed to. */
10696 gen_type_die (TREE_TYPE (type), context_die);
10698 /* Now output a DIE to represent this pointer-to-data-member type
10699 itself. */
10700 gen_ptr_to_mbr_type_die (type, context_die);
10701 break;
10703 case SET_TYPE:
10704 gen_type_die (TYPE_DOMAIN (type), context_die);
10705 gen_set_type_die (type, context_die);
10706 break;
10708 case FILE_TYPE:
10709 gen_type_die (TREE_TYPE (type), context_die);
10710 abort (); /* No way to represent these in Dwarf yet! */
10711 break;
10713 case FUNCTION_TYPE:
10714 /* Force out return type (in case it wasn't forced out already). */
10715 gen_type_die (TREE_TYPE (type), context_die);
10716 gen_subroutine_type_die (type, context_die);
10717 break;
10719 case METHOD_TYPE:
10720 /* Force out return type (in case it wasn't forced out already). */
10721 gen_type_die (TREE_TYPE (type), context_die);
10722 gen_subroutine_type_die (type, context_die);
10723 break;
10725 case ARRAY_TYPE:
10726 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10728 gen_type_die (TREE_TYPE (type), context_die);
10729 gen_string_type_die (type, context_die);
10731 else
10732 gen_array_type_die (type, context_die);
10733 break;
10735 case VECTOR_TYPE:
10736 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10737 break;
10739 case ENUMERAL_TYPE:
10740 case RECORD_TYPE:
10741 case UNION_TYPE:
10742 case QUAL_UNION_TYPE:
10743 /* If this is a nested type whose containing class hasn't been
10744 written out yet, writing it out will cover this one, too.
10745 This does not apply to instantiations of member class templates;
10746 they need to be added to the containing class as they are
10747 generated. FIXME: This hurts the idea of combining type decls
10748 from multiple TUs, since we can't predict what set of template
10749 instantiations we'll get. */
10750 if (TYPE_CONTEXT (type)
10751 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10752 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10754 gen_type_die (TYPE_CONTEXT (type), context_die);
10756 if (TREE_ASM_WRITTEN (type))
10757 return;
10759 /* If that failed, attach ourselves to the stub. */
10760 push_decl_scope (TYPE_CONTEXT (type));
10761 context_die = lookup_type_die (TYPE_CONTEXT (type));
10762 need_pop = 1;
10764 else
10765 need_pop = 0;
10767 if (TREE_CODE (type) == ENUMERAL_TYPE)
10768 gen_enumeration_type_die (type, context_die);
10769 else
10770 gen_struct_or_union_type_die (type, context_die);
10772 if (need_pop)
10773 pop_decl_scope ();
10775 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10776 it up if it is ever completed. gen_*_type_die will set it for us
10777 when appropriate. */
10778 return;
10780 case VOID_TYPE:
10781 case INTEGER_TYPE:
10782 case REAL_TYPE:
10783 case COMPLEX_TYPE:
10784 case BOOLEAN_TYPE:
10785 case CHAR_TYPE:
10786 /* No DIEs needed for fundamental types. */
10787 break;
10789 case LANG_TYPE:
10790 /* No Dwarf representation currently defined. */
10791 break;
10793 default:
10794 abort ();
10797 TREE_ASM_WRITTEN (type) = 1;
10800 /* Generate a DIE for a tagged type instantiation. */
10802 static void
10803 gen_tagged_type_instantiation_die (type, context_die)
10804 register tree type;
10805 register dw_die_ref context_die;
10807 if (type == NULL_TREE || type == error_mark_node)
10808 return;
10810 /* We are going to output a DIE to represent the unqualified version of
10811 this type (i.e. without any const or volatile qualifiers) so make sure
10812 that we have the main variant (i.e. the unqualified version) of this
10813 type now. */
10814 if (type != type_main_variant (type))
10815 abort ();
10817 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10818 an instance of an unresolved type. */
10820 switch (TREE_CODE (type))
10822 case ERROR_MARK:
10823 break;
10825 case ENUMERAL_TYPE:
10826 gen_inlined_enumeration_type_die (type, context_die);
10827 break;
10829 case RECORD_TYPE:
10830 gen_inlined_structure_type_die (type, context_die);
10831 break;
10833 case UNION_TYPE:
10834 case QUAL_UNION_TYPE:
10835 gen_inlined_union_type_die (type, context_die);
10836 break;
10838 default:
10839 abort ();
10843 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10844 things which are local to the given block. */
10846 static void
10847 gen_block_die (stmt, context_die, depth)
10848 register tree stmt;
10849 register dw_die_ref context_die;
10850 int depth;
10852 register int must_output_die = 0;
10853 register tree origin;
10854 register tree decl;
10855 register enum tree_code origin_code;
10857 /* Ignore blocks never really used to make RTL. */
10858 if (stmt == NULL_TREE || !TREE_USED (stmt)
10859 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10860 return;
10862 /* If the block is one fragment of a non-contiguous block, do not
10863 process the variables, since they will have been done by the
10864 origin block. Do process subblocks. */
10865 if (BLOCK_FRAGMENT_ORIGIN (stmt))
10867 tree sub;
10869 for (sub= BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
10870 gen_block_die (sub, context_die, depth + 1);
10871 return;
10874 /* Determine the "ultimate origin" of this block. This block may be an
10875 inlined instance of an inlined instance of inline function, so we have
10876 to trace all of the way back through the origin chain to find out what
10877 sort of node actually served as the original seed for the creation of
10878 the current block. */
10879 origin = block_ultimate_origin (stmt);
10880 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10882 /* Determine if we need to output any Dwarf DIEs at all to represent this
10883 block. */
10884 if (origin_code == FUNCTION_DECL)
10885 /* The outer scopes for inlinings *must* always be represented. We
10886 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10887 must_output_die = 1;
10888 else
10890 /* In the case where the current block represents an inlining of the
10891 "body block" of an inline function, we must *NOT* output any DIE for
10892 this block because we have already output a DIE to represent the
10893 whole inlined function scope and the "body block" of any function
10894 doesn't really represent a different scope according to ANSI C
10895 rules. So we check here to make sure that this block does not
10896 represent a "body block inlining" before trying to set the
10897 `must_output_die' flag. */
10898 if (! is_body_block (origin ? origin : stmt))
10900 /* Determine if this block directly contains any "significant"
10901 local declarations which we will need to output DIEs for. */
10902 if (debug_info_level > DINFO_LEVEL_TERSE)
10903 /* We are not in terse mode so *any* local declaration counts
10904 as being a "significant" one. */
10905 must_output_die = (BLOCK_VARS (stmt) != NULL);
10906 else
10907 /* We are in terse mode, so only local (nested) function
10908 definitions count as "significant" local declarations. */
10909 for (decl = BLOCK_VARS (stmt);
10910 decl != NULL; decl = TREE_CHAIN (decl))
10911 if (TREE_CODE (decl) == FUNCTION_DECL
10912 && DECL_INITIAL (decl))
10914 must_output_die = 1;
10915 break;
10920 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10921 DIE for any block which contains no significant local declarations at
10922 all. Rather, in such cases we just call `decls_for_scope' so that any
10923 needed Dwarf info for any sub-blocks will get properly generated. Note
10924 that in terse mode, our definition of what constitutes a "significant"
10925 local declaration gets restricted to include only inlined function
10926 instances and local (nested) function definitions. */
10927 if (must_output_die)
10929 if (origin_code == FUNCTION_DECL)
10930 gen_inlined_subroutine_die (stmt, context_die, depth);
10931 else
10932 gen_lexical_block_die (stmt, context_die, depth);
10934 else
10935 decls_for_scope (stmt, context_die, depth);
10938 /* Generate all of the decls declared within a given scope and (recursively)
10939 all of its sub-blocks. */
10941 static void
10942 decls_for_scope (stmt, context_die, depth)
10943 register tree stmt;
10944 register dw_die_ref context_die;
10945 int depth;
10947 register tree decl;
10948 register tree subblocks;
10950 /* Ignore blocks never really used to make RTL. */
10951 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10952 return;
10954 /* Output the DIEs to represent all of the data objects and typedefs
10955 declared directly within this block but not within any nested
10956 sub-blocks. Also, nested function and tag DIEs have been
10957 generated with a parent of NULL; fix that up now. */
10958 for (decl = BLOCK_VARS (stmt);
10959 decl != NULL; decl = TREE_CHAIN (decl))
10961 register dw_die_ref die;
10963 if (TREE_CODE (decl) == FUNCTION_DECL)
10964 die = lookup_decl_die (decl);
10965 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
10966 die = lookup_type_die (TREE_TYPE (decl));
10967 else
10968 die = NULL;
10970 if (die != NULL && die->die_parent == NULL)
10971 add_child_die (context_die, die);
10972 else
10973 gen_decl_die (decl, context_die);
10976 /* Output the DIEs to represent all sub-blocks (and the items declared
10977 therein) of this block. */
10978 for (subblocks = BLOCK_SUBBLOCKS (stmt);
10979 subblocks != NULL;
10980 subblocks = BLOCK_CHAIN (subblocks))
10981 gen_block_die (subblocks, context_die, depth + 1);
10984 /* Is this a typedef we can avoid emitting? */
10986 static inline int
10987 is_redundant_typedef (decl)
10988 register tree decl;
10990 if (TYPE_DECL_IS_STUB (decl))
10991 return 1;
10993 if (DECL_ARTIFICIAL (decl)
10994 && DECL_CONTEXT (decl)
10995 && is_tagged_type (DECL_CONTEXT (decl))
10996 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
10997 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
10998 /* Also ignore the artificial member typedef for the class name. */
10999 return 1;
11001 return 0;
11004 /* Generate Dwarf debug information for a decl described by DECL. */
11006 static void
11007 gen_decl_die (decl, context_die)
11008 register tree decl;
11009 register dw_die_ref context_die;
11011 register tree origin;
11013 if (TREE_CODE (decl) == ERROR_MARK)
11014 return;
11016 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11017 if (DECL_IGNORED_P (decl))
11018 return;
11020 switch (TREE_CODE (decl))
11022 case CONST_DECL:
11023 /* The individual enumerators of an enum type get output when we output
11024 the Dwarf representation of the relevant enum type itself. */
11025 break;
11027 case FUNCTION_DECL:
11028 /* Don't output any DIEs to represent mere function declarations,
11029 unless they are class members or explicit block externs. */
11030 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11031 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11032 break;
11034 /* If we're emitting a clone, emit info for the abstract instance. */
11035 if (DECL_ORIGIN (decl) != decl)
11036 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
11037 /* If we're emitting an out-of-line copy of an inline function,
11038 emit info for the abstract instance and set up to refer to it. */
11039 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11040 && ! class_scope_p (context_die)
11041 /* dwarf2out_abstract_function won't emit a die if this is just
11042 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11043 that case, because that works only if we have a die. */
11044 && DECL_INITIAL (decl) != NULL_TREE)
11046 dwarf2out_abstract_function (decl);
11047 set_decl_origin_self (decl);
11049 /* Otherwise we're emitting the primary DIE for this decl. */
11050 else if (debug_info_level > DINFO_LEVEL_TERSE)
11052 /* Before we describe the FUNCTION_DECL itself, make sure that we
11053 have described its return type. */
11054 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11056 /* And its virtual context. */
11057 if (DECL_VINDEX (decl) != NULL_TREE)
11058 gen_type_die (DECL_CONTEXT (decl), context_die);
11060 /* And its containing type. */
11061 origin = decl_class_context (decl);
11062 if (origin != NULL_TREE)
11063 gen_type_die_for_member (origin, decl, context_die);
11066 /* Now output a DIE to represent the function itself. */
11067 gen_subprogram_die (decl, context_die);
11068 break;
11070 case TYPE_DECL:
11071 /* If we are in terse mode, don't generate any DIEs to represent any
11072 actual typedefs. */
11073 if (debug_info_level <= DINFO_LEVEL_TERSE)
11074 break;
11076 /* In the special case of a TYPE_DECL node representing the
11077 declaration of some type tag, if the given TYPE_DECL is marked as
11078 having been instantiated from some other (original) TYPE_DECL node
11079 (e.g. one which was generated within the original definition of an
11080 inline function) we have to generate a special (abbreviated)
11081 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
11082 DIE here. */
11083 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11085 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11086 break;
11089 if (is_redundant_typedef (decl))
11090 gen_type_die (TREE_TYPE (decl), context_die);
11091 else
11092 /* Output a DIE to represent the typedef itself. */
11093 gen_typedef_die (decl, context_die);
11094 break;
11096 case LABEL_DECL:
11097 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11098 gen_label_die (decl, context_die);
11099 break;
11101 case VAR_DECL:
11102 /* If we are in terse mode, don't generate any DIEs to represent any
11103 variable declarations or definitions. */
11104 if (debug_info_level <= DINFO_LEVEL_TERSE)
11105 break;
11107 /* Output any DIEs that are needed to specify the type of this data
11108 object. */
11109 gen_type_die (TREE_TYPE (decl), context_die);
11111 /* And its containing type. */
11112 origin = decl_class_context (decl);
11113 if (origin != NULL_TREE)
11114 gen_type_die_for_member (origin, decl, context_die);
11116 /* Now output the DIE to represent the data object itself. This gets
11117 complicated because of the possibility that the VAR_DECL really
11118 represents an inlined instance of a formal parameter for an inline
11119 function. */
11120 origin = decl_ultimate_origin (decl);
11121 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11122 gen_formal_parameter_die (decl, context_die);
11123 else
11124 gen_variable_die (decl, context_die);
11125 break;
11127 case FIELD_DECL:
11128 /* Ignore the nameless fields that are used to skip bits, but
11129 handle C++ anonymous unions. */
11130 if (DECL_NAME (decl) != NULL_TREE
11131 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11133 gen_type_die (member_declared_type (decl), context_die);
11134 gen_field_die (decl, context_die);
11136 break;
11138 case PARM_DECL:
11139 gen_type_die (TREE_TYPE (decl), context_die);
11140 gen_formal_parameter_die (decl, context_die);
11141 break;
11143 case NAMESPACE_DECL:
11144 /* Ignore for now. */
11145 break;
11147 default:
11148 abort ();
11152 /* Add Ada "use" clause information for SGI Workshop debugger. */
11154 void
11155 dwarf2out_add_library_unit_info (filename, context_list)
11156 const char *filename;
11157 const char *context_list;
11159 unsigned int file_index;
11161 if (filename != NULL)
11163 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
11164 tree context_list_decl
11165 = build_decl (LABEL_DECL, get_identifier (context_list),
11166 void_type_node);
11168 TREE_PUBLIC (context_list_decl) = TRUE;
11169 add_name_attribute (unit_die, context_list);
11170 file_index = lookup_filename (filename);
11171 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11172 add_pubname (context_list_decl, unit_die);
11176 /* Debug information for a global DECL. Called from toplev.c after
11177 compilation proper has finished. */
11178 static void
11179 dwarf2out_global_decl (decl)
11180 tree decl;
11182 /* Output DWARF2 information for file-scope tentative data object
11183 declarations, file-scope (extern) function declarations (which
11184 had no corresponding body) and file-scope tagged type
11185 declarations and definitions which have not yet been forced out. */
11187 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
11188 dwarf2out_decl (decl);
11191 /* Write the debugging output for DECL. */
11193 void
11194 dwarf2out_decl (decl)
11195 register tree decl;
11197 register dw_die_ref context_die = comp_unit_die;
11199 if (TREE_CODE (decl) == ERROR_MARK)
11200 return;
11202 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11203 if (DECL_IGNORED_P (decl))
11204 return;
11206 switch (TREE_CODE (decl))
11208 case FUNCTION_DECL:
11209 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11210 builtin function. Explicit programmer-supplied declarations of
11211 these same functions should NOT be ignored however. */
11212 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11213 return;
11215 /* What we would really like to do here is to filter out all mere
11216 file-scope declarations of file-scope functions which are never
11217 referenced later within this translation unit (and keep all of ones
11218 that *are* referenced later on) but we aren't clairvoyant, so we have
11219 no idea which functions will be referenced in the future (i.e. later
11220 on within the current translation unit). So here we just ignore all
11221 file-scope function declarations which are not also definitions. If
11222 and when the debugger needs to know something about these functions,
11223 it will have to hunt around and find the DWARF information associated
11224 with the definition of the function. Note that we can't just check
11225 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
11226 definitions and which ones represent mere declarations. We have to
11227 check `DECL_INITIAL' instead. That's because the C front-end
11228 supports some weird semantics for "extern inline" function
11229 definitions. These can get inlined within the current translation
11230 unit (an thus, we need to generate DWARF info for their abstract
11231 instances so that the DWARF info for the concrete inlined instances
11232 can have something to refer to) but the compiler never generates any
11233 out-of-lines instances of such things (despite the fact that they
11234 *are* definitions). The important point is that the C front-end
11235 marks these "extern inline" functions as DECL_EXTERNAL, but we need
11236 to generate DWARF for them anyway. Note that the C++ front-end also
11237 plays some similar games for inline function definitions appearing
11238 within include files which also contain
11239 `#pragma interface' pragmas. */
11240 if (DECL_INITIAL (decl) == NULL_TREE)
11241 return;
11243 /* If we're a nested function, initially use a parent of NULL; if we're
11244 a plain function, this will be fixed up in decls_for_scope. If
11245 we're a method, it will be ignored, since we already have a DIE. */
11246 if (decl_function_context (decl))
11247 context_die = NULL;
11249 break;
11251 case VAR_DECL:
11252 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11253 declaration and if the declaration was never even referenced from
11254 within this entire compilation unit. We suppress these DIEs in
11255 order to save space in the .debug section (by eliminating entries
11256 which are probably useless). Note that we must not suppress
11257 block-local extern declarations (whether used or not) because that
11258 would screw-up the debugger's name lookup mechanism and cause it to
11259 miss things which really ought to be in scope at a given point. */
11260 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11261 return;
11263 /* If we are in terse mode, don't generate any DIEs to represent any
11264 variable declarations or definitions. */
11265 if (debug_info_level <= DINFO_LEVEL_TERSE)
11266 return;
11267 break;
11269 case TYPE_DECL:
11270 /* Don't emit stubs for types unless they are needed by other DIEs. */
11271 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11272 return;
11274 /* Don't bother trying to generate any DIEs to represent any of the
11275 normal built-in types for the language we are compiling. */
11276 if (DECL_SOURCE_LINE (decl) == 0)
11278 /* OK, we need to generate one for `bool' so GDB knows what type
11279 comparisons have. */
11280 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11281 == DW_LANG_C_plus_plus)
11282 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
11283 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11285 return;
11288 /* If we are in terse mode, don't generate any DIEs for types. */
11289 if (debug_info_level <= DINFO_LEVEL_TERSE)
11290 return;
11292 /* If we're a function-scope tag, initially use a parent of NULL;
11293 this will be fixed up in decls_for_scope. */
11294 if (decl_function_context (decl))
11295 context_die = NULL;
11297 break;
11299 default:
11300 return;
11303 gen_decl_die (decl, context_die);
11306 /* Output a marker (i.e. a label) for the beginning of the generated code for
11307 a lexical block. */
11309 static void
11310 dwarf2out_begin_block (line, blocknum)
11311 unsigned int line ATTRIBUTE_UNUSED;
11312 unsigned int blocknum;
11314 function_section (current_function_decl);
11315 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11318 /* Output a marker (i.e. a label) for the end of the generated code for a
11319 lexical block. */
11321 static void
11322 dwarf2out_end_block (line, blocknum)
11323 unsigned int line ATTRIBUTE_UNUSED;
11324 unsigned int blocknum;
11326 function_section (current_function_decl);
11327 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11330 /* Returns nonzero if it is appropriate not to emit any debugging
11331 information for BLOCK, because it doesn't contain any instructions.
11333 Don't allow this for blocks with nested functions or local classes
11334 as we would end up with orphans, and in the presence of scheduling
11335 we may end up calling them anyway. */
11337 static bool
11338 dwarf2out_ignore_block (block)
11339 tree block;
11341 tree decl;
11342 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11343 if (TREE_CODE (decl) == FUNCTION_DECL
11344 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11345 return 0;
11346 return 1;
11349 /* Lookup a filename (in the list of filenames that we know about here in
11350 dwarf2out.c) and return its "index". The index of each (known) filename is
11351 just a unique number which is associated with only that one filename.
11352 We need such numbers for the sake of generating labels
11353 (in the .debug_sfnames section) and references to those
11354 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
11355 If the filename given as an argument is not found in our current list,
11356 add it to the list and assign it the next available unique index number.
11357 In order to speed up searches, we remember the index of the filename
11358 was looked up last. This handles the majority of all searches. */
11360 static unsigned
11361 lookup_filename (file_name)
11362 const char *file_name;
11364 register unsigned i;
11366 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11367 if (strcmp (file_name, "<internal>") == 0
11368 || strcmp (file_name, "<built-in>") == 0)
11369 return 0;
11371 /* Check to see if the file name that was searched on the previous
11372 call matches this file name. If so, return the index. */
11373 if (file_table.last_lookup_index != 0)
11374 if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0)
11375 return file_table.last_lookup_index;
11377 /* Didn't match the previous lookup, search the table */
11378 for (i = 1; i < file_table.in_use; ++i)
11379 if (strcmp (file_name, file_table.table[i]) == 0)
11381 file_table.last_lookup_index = i;
11382 return i;
11385 /* Prepare to add a new table entry by making sure there is enough space in
11386 the table to do so. If not, expand the current table. */
11387 if (i == file_table.allocated)
11389 file_table.allocated = i + FILE_TABLE_INCREMENT;
11390 file_table.table = (char **)
11391 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11394 /* Add the new entry to the end of the filename table. */
11395 file_table.table[i] = xstrdup (file_name);
11396 file_table.in_use = i + 1;
11397 file_table.last_lookup_index = i;
11399 if (DWARF2_ASM_LINE_DEBUG_INFO)
11400 fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
11402 return i;
11405 static void
11406 init_file_table ()
11408 /* Allocate the initial hunk of the file_table. */
11409 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11410 file_table.allocated = FILE_TABLE_INCREMENT;
11412 /* Skip the first entry - file numbers begin at 1. */
11413 file_table.in_use = 1;
11414 file_table.last_lookup_index = 0;
11417 /* Output a label to mark the beginning of a source code line entry
11418 and record information relating to this source line, in
11419 'line_info_table' for later output of the .debug_line section. */
11421 static void
11422 dwarf2out_source_line (line, filename)
11423 unsigned int line;
11424 register const char *filename;
11426 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11428 function_section (current_function_decl);
11430 /* If requested, emit something human-readable. */
11431 if (flag_debug_asm)
11432 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11433 filename, line);
11435 if (DWARF2_ASM_LINE_DEBUG_INFO)
11437 unsigned file_num = lookup_filename (filename);
11439 /* Emit the .loc directive understood by GNU as. */
11440 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11442 /* Indicate that line number info exists. */
11443 ++line_info_table_in_use;
11445 /* Indicate that multiple line number tables exist. */
11446 if (DECL_SECTION_NAME (current_function_decl))
11447 ++separate_line_info_table_in_use;
11449 else if (DECL_SECTION_NAME (current_function_decl))
11451 register dw_separate_line_info_ref line_info;
11452 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11453 separate_line_info_table_in_use);
11455 /* expand the line info table if necessary */
11456 if (separate_line_info_table_in_use
11457 == separate_line_info_table_allocated)
11459 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11460 separate_line_info_table
11461 = (dw_separate_line_info_ref)
11462 xrealloc (separate_line_info_table,
11463 separate_line_info_table_allocated
11464 * sizeof (dw_separate_line_info_entry));
11467 /* Add the new entry at the end of the line_info_table. */
11468 line_info
11469 = &separate_line_info_table[separate_line_info_table_in_use++];
11470 line_info->dw_file_num = lookup_filename (filename);
11471 line_info->dw_line_num = line;
11472 line_info->function = current_funcdef_number;
11474 else
11476 register dw_line_info_ref line_info;
11478 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11479 line_info_table_in_use);
11481 /* Expand the line info table if necessary. */
11482 if (line_info_table_in_use == line_info_table_allocated)
11484 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11485 line_info_table
11486 = (dw_line_info_ref)
11487 xrealloc (line_info_table,
11488 (line_info_table_allocated
11489 * sizeof (dw_line_info_entry)));
11492 /* Add the new entry at the end of the line_info_table. */
11493 line_info = &line_info_table[line_info_table_in_use++];
11494 line_info->dw_file_num = lookup_filename (filename);
11495 line_info->dw_line_num = line;
11500 /* Record the beginning of a new source file. */
11502 static void
11503 dwarf2out_start_source_file (lineno, filename)
11504 register unsigned int lineno;
11505 register const char *filename;
11507 if (flag_eliminate_dwarf2_dups)
11509 /* Record the beginning of the file for break_out_includes. */
11510 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11511 add_AT_string (bincl_die, DW_AT_name, filename);
11513 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11515 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11516 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
11517 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
11518 lineno);
11519 dw2_asm_output_data_uleb128 (lookup_filename (filename),
11520 "Filename we just started");
11524 /* Record the end of a source file. */
11526 static void
11527 dwarf2out_end_source_file (lineno)
11528 unsigned int lineno ATTRIBUTE_UNUSED;
11530 if (flag_eliminate_dwarf2_dups)
11532 /* Record the end of the file for break_out_includes. */
11533 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11535 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11537 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11538 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11542 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11543 the tail part of the directive line, i.e. the part which is past the
11544 initial whitespace, #, whitespace, directive-name, whitespace part. */
11546 static void
11547 dwarf2out_define (lineno, buffer)
11548 register unsigned lineno ATTRIBUTE_UNUSED;
11549 register const char *buffer ATTRIBUTE_UNUSED;
11551 static int initialized = 0;
11552 if (!initialized)
11554 dwarf2out_start_source_file (0, primary_filename);
11555 initialized = 1;
11557 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11559 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11560 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
11561 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11562 dw2_asm_output_nstring (buffer, -1, "The macro");
11566 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11567 the tail part of the directive line, i.e. the part which is past the
11568 initial whitespace, #, whitespace, directive-name, whitespace part. */
11570 static void
11571 dwarf2out_undef (lineno, buffer)
11572 register unsigned lineno ATTRIBUTE_UNUSED;
11573 register const char *buffer ATTRIBUTE_UNUSED;
11575 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11577 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11578 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
11579 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11580 dw2_asm_output_nstring (buffer, -1, "The macro");
11584 /* Set up for Dwarf output at the start of compilation. */
11586 static void
11587 dwarf2out_init (main_input_filename)
11588 register const char *main_input_filename;
11590 init_file_table ();
11592 /* Remember the name of the primary input file. */
11593 primary_filename = main_input_filename;
11595 /* Add it to the file table first, under the assumption that we'll
11596 be emitting line number data for it first, which avoids having
11597 to add an initial DW_LNS_set_file. */
11598 lookup_filename (main_input_filename);
11600 /* Allocate the initial hunk of the decl_die_table. */
11601 decl_die_table
11602 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11603 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11604 decl_die_table_in_use = 0;
11606 /* Allocate the initial hunk of the decl_scope_table. */
11607 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
11608 ggc_add_tree_varray_root (&decl_scope_table, 1);
11610 /* Allocate the initial hunk of the abbrev_die_table. */
11611 abbrev_die_table
11612 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11613 sizeof (dw_die_ref));
11614 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11615 /* Zero-th entry is allocated, but unused */
11616 abbrev_die_table_in_use = 1;
11618 /* Allocate the initial hunk of the line_info_table. */
11619 line_info_table
11620 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11621 sizeof (dw_line_info_entry));
11622 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11623 /* Zero-th entry is allocated, but unused */
11624 line_info_table_in_use = 1;
11626 /* Generate the initial DIE for the .debug section. Note that the (string)
11627 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11628 will (typically) be a relative pathname and that this pathname should be
11629 taken as being relative to the directory from which the compiler was
11630 invoked when the given (base) source file was compiled. */
11631 comp_unit_die = gen_compile_unit_die (main_input_filename);
11633 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
11634 ggc_add_tree_varray_root (&incomplete_types, 1);
11636 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11637 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11639 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11640 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
11641 DEBUG_ABBREV_SECTION_LABEL, 0);
11642 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11643 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11644 else
11645 strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME));
11646 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11647 DEBUG_INFO_SECTION_LABEL, 0);
11648 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11649 DEBUG_LINE_SECTION_LABEL, 0);
11650 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
11651 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11652 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
11653 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11654 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
11655 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11656 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11658 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11659 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
11660 DEBUG_MACINFO_SECTION_LABEL, 0);
11661 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
11664 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11666 text_section ();
11667 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11671 /* Output stuff that dwarf requires at the end of every file,
11672 and generate the DWARF-2 debugging info. */
11674 static void
11675 dwarf2out_finish (input_filename)
11676 register const char *input_filename ATTRIBUTE_UNUSED;
11678 limbo_die_node *node, *next_node;
11679 dw_die_ref die = 0;
11681 /* Traverse the limbo die list, and add parent/child links. The only
11682 dies without parents that should be here are concrete instances of
11683 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11684 For concrete instances, we can get the parent die from the abstract
11685 instance. */
11686 for (node = limbo_die_list; node; node = next_node)
11688 next_node = node->next;
11689 die = node->die;
11691 if (die->die_parent == NULL)
11693 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11694 if (origin)
11695 add_child_die (origin->die_parent, die);
11696 else if (die == comp_unit_die)
11698 else
11699 abort ();
11701 free (node);
11703 limbo_die_list = NULL;
11705 /* Walk through the list of incomplete types again, trying once more to
11706 emit full debugging info for them. */
11707 retry_incomplete_types ();
11709 /* We need to reverse all the dies before break_out_includes, or
11710 we'll see the end of an include file before the beginning. */
11711 reverse_all_dies (comp_unit_die);
11713 /* Generate separate CUs for each of the include files we've seen.
11714 They will go into limbo_die_list. */
11715 if (flag_eliminate_dwarf2_dups)
11716 break_out_includes (comp_unit_die);
11718 /* Traverse the DIE's and add add sibling attributes to those DIE's
11719 that have children. */
11720 add_sibling_attributes (comp_unit_die);
11721 for (node = limbo_die_list; node; node = node->next)
11722 add_sibling_attributes (node->die);
11724 /* Output a terminator label for the .text section. */
11725 text_section ();
11726 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11728 /* Output the source line correspondence table. We must do this
11729 even if there is no line information. Otherwise, on an empty
11730 translation unit, we will generate a present, but empty,
11731 .debug_info section. IRIX 6.5 `nm' will then complain when
11732 examining the file. */
11733 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11735 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
11736 output_line_info ();
11739 /* Output location list section if necessary. */
11740 if (have_location_lists)
11742 /* Output the location lists info. */
11743 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
11744 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
11745 DEBUG_LOC_SECTION_LABEL, 0);
11746 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
11747 output_location_lists (die);
11748 have_location_lists = 0;
11751 /* We can only use the low/high_pc attributes if all of the code was
11752 in .text. */
11753 if (separate_line_info_table_in_use == 0)
11755 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11756 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11758 /* And if it wasn't, we need to give .debug_loc and .debug_ranges
11759 an appropriate "base address". Use zero so that these addresses
11760 become absolute. */
11761 else if (have_location_lists || ranges_table_in_use)
11762 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
11764 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11765 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11766 debug_line_section_label);
11768 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11769 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
11771 /* Output all of the compilation units. We put the main one last so that
11772 the offsets are available to output_pubnames. */
11773 for (node = limbo_die_list; node; node = node->next)
11774 output_comp_unit (node->die);
11775 output_comp_unit (comp_unit_die);
11777 /* Output the abbreviation table. */
11778 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
11779 output_abbrev_section ();
11781 if (pubname_table_in_use)
11783 /* Output public names table. */
11784 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
11785 output_pubnames ();
11788 /* We only put functions in the arange table, so don't write it out if
11789 we don't have any. */
11790 if (fde_table_in_use)
11792 /* Output the address range information. */
11793 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
11794 output_aranges ();
11797 /* Output ranges section if necessary. */
11798 if (ranges_table_in_use)
11800 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
11801 output_ranges ();
11804 /* Have to end the primary source file. */
11805 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11807 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11808 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11811 #endif /* DWARF2_DEBUGGING_INFO */