Add missing file
[official-gcc.git] / gcc / dwarf2out.c
blob7631dc4f862f76a4566d5710ddc31f2e4bcac42e
1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
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: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
35 information. */
37 #include "config.h"
38 #include "system.h"
39 #include "tree.h"
40 #include "flags.h"
41 #include "real.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"
62 #include "target.h"
63 #include "langhooks.h"
64 #include "hashtable.h"
66 #ifdef DWARF2_DEBUGGING_INFO
67 static void dwarf2out_source_line PARAMS ((unsigned int, const char *));
68 #endif
70 /* DWARF2 Abbreviation Glossary:
71 CFA = Canonical Frame Address
72 a fixed address on the stack which identifies a call frame.
73 We define it to be the value of SP just before the call insn.
74 The CFA register and offset, which may change during the course
75 of the function, are used to calculate its value at runtime.
76 CFI = Call Frame Instruction
77 an instruction for the DWARF2 abstract machine
78 CIE = Common Information Entry
79 information describing information common to one or more FDEs
80 DIE = Debugging Information Entry
81 FDE = Frame Description Entry
82 information describing the stack call frame, in particular,
83 how to restore registers
85 DW_CFA_... = DWARF2 CFA call frame instruction
86 DW_TAG_... = DWARF2 DIE tag */
88 /* Decide whether we want to emit frame unwind information for the current
89 translation unit. */
91 int
92 dwarf2out_do_frame ()
94 return (write_symbols == DWARF2_DEBUG
95 || write_symbols == VMS_AND_DWARF2_DEBUG
96 #ifdef DWARF2_FRAME_INFO
97 || DWARF2_FRAME_INFO
98 #endif
99 #ifdef DWARF2_UNWIND_INFO
100 || flag_unwind_tables
101 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
102 #endif
106 /* The size of the target's pointer type. */
107 #ifndef PTR_SIZE
108 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
109 #endif
111 /* Default version of targetm.eh_frame_section. Note this must appear
112 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
113 guards. */
115 void
116 default_eh_frame_section ()
118 #ifdef EH_FRAME_SECTION_NAME
119 named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
120 #else
121 tree label = get_file_function_name ('F');
123 data_section ();
124 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
125 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
126 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
127 #endif
130 /* Array of RTXes referenced by the debugging information, which therefore
131 must be kept around forever. */
132 static GTY(()) varray_type used_rtx_varray;
134 /* A pointer to the base of a list of incomplete types which might be
135 completed at some later time. incomplete_types_list needs to be a VARRAY
136 because we want to tell the garbage collector about it. */
137 static GTY(()) varray_type incomplete_types;
139 /* A pointer to the base of a table of references to declaration
140 scopes. This table is a display which tracks the nesting
141 of declaration scopes at the current scope and containing
142 scopes. This table is used to find the proper place to
143 define type declaration DIE's. */
144 static GTY(()) varray_type decl_scope_table;
146 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
148 /* How to start an assembler comment. */
149 #ifndef ASM_COMMENT_START
150 #define ASM_COMMENT_START ";#"
151 #endif
153 typedef struct dw_cfi_struct *dw_cfi_ref;
154 typedef struct dw_fde_struct *dw_fde_ref;
155 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
157 /* Call frames are described using a sequence of Call Frame
158 Information instructions. The register number, offset
159 and address fields are provided as possible operands;
160 their use is selected by the opcode field. */
162 typedef union dw_cfi_oprnd_struct
164 unsigned long dw_cfi_reg_num;
165 long int dw_cfi_offset;
166 const char *dw_cfi_addr;
167 struct dw_loc_descr_struct *dw_cfi_loc;
169 dw_cfi_oprnd;
171 typedef struct dw_cfi_struct
173 dw_cfi_ref dw_cfi_next;
174 enum dwarf_call_frame_info dw_cfi_opc;
175 dw_cfi_oprnd dw_cfi_oprnd1;
176 dw_cfi_oprnd dw_cfi_oprnd2;
178 dw_cfi_node;
180 /* This is how we define the location of the CFA. We use to handle it
181 as REG + OFFSET all the time, but now it can be more complex.
182 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
183 Instead of passing around REG and OFFSET, we pass a copy
184 of this structure. */
185 typedef struct cfa_loc
187 unsigned long reg;
188 long offset;
189 long base_offset;
190 int indirect; /* 1 if CFA is accessed via a dereference. */
191 } dw_cfa_location;
193 /* All call frame descriptions (FDE's) in the GCC generated DWARF
194 refer to a single Common Information Entry (CIE), defined at
195 the beginning of the .debug_frame section. This use of a single
196 CIE obviates the need to keep track of multiple CIE's
197 in the DWARF generation routines below. */
199 typedef struct dw_fde_struct
201 const char *dw_fde_begin;
202 const char *dw_fde_current_label;
203 const char *dw_fde_end;
204 dw_cfi_ref dw_fde_cfi;
205 unsigned funcdef_number;
206 unsigned nothrow : 1;
207 unsigned uses_eh_lsda : 1;
209 dw_fde_node;
211 /* Maximum size (in bytes) of an artificially generated label. */
212 #define MAX_ARTIFICIAL_LABEL_BYTES 30
214 /* The size of addresses as they appear in the Dwarf 2 data.
215 Some architectures use word addresses to refer to code locations,
216 but Dwarf 2 info always uses byte addresses. On such machines,
217 Dwarf 2 addresses need to be larger than the architecture's
218 pointers. */
219 #ifndef DWARF2_ADDR_SIZE
220 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
221 #endif
223 /* The size in bytes of a DWARF field indicating an offset or length
224 relative to a debug info section, specified to be 4 bytes in the
225 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
226 as PTR_SIZE. */
228 #ifndef DWARF_OFFSET_SIZE
229 #define DWARF_OFFSET_SIZE 4
230 #endif
232 #define DWARF_VERSION 2
234 /* Round SIZE up to the nearest BOUNDARY. */
235 #define DWARF_ROUND(SIZE,BOUNDARY) \
236 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
238 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
239 #ifndef DWARF_CIE_DATA_ALIGNMENT
240 #ifdef STACK_GROWS_DOWNWARD
241 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
242 #else
243 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
244 #endif
245 #endif
247 /* A pointer to the base of a table that contains frame description
248 information for each routine. */
249 static dw_fde_ref fde_table;
251 /* Number of elements currently allocated for fde_table. */
252 static unsigned fde_table_allocated;
254 /* Number of elements in fde_table currently in use. */
255 static unsigned fde_table_in_use;
257 /* Size (in elements) of increments by which we may expand the
258 fde_table. */
259 #define FDE_TABLE_INCREMENT 256
261 /* A list of call frame insns for the CIE. */
262 static dw_cfi_ref cie_cfi_head;
264 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
265 attribute that accelerates the lookup of the FDE associated
266 with the subprogram. This variable holds the table index of the FDE
267 associated with the current function (body) definition. */
268 static unsigned current_funcdef_fde;
270 struct ht *debug_str_hash;
272 struct indirect_string_node
274 struct ht_identifier id;
275 unsigned int refcount;
276 unsigned int form;
277 char *label;
280 /* Forward declarations for functions defined in this file. */
282 static char *stripattributes PARAMS ((const char *));
283 static const char *dwarf_cfi_name PARAMS ((unsigned));
284 static dw_cfi_ref new_cfi PARAMS ((void));
285 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
286 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
287 static void lookup_cfa_1 PARAMS ((dw_cfi_ref,
288 dw_cfa_location *));
289 static void lookup_cfa PARAMS ((dw_cfa_location *));
290 static void reg_save PARAMS ((const char *, unsigned,
291 unsigned, long));
292 static void initial_return_save PARAMS ((rtx));
293 static long stack_adjust_offset PARAMS ((rtx));
294 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
295 static void output_call_frame_info PARAMS ((int));
296 static void dwarf2out_stack_adjust PARAMS ((rtx));
297 static void queue_reg_save PARAMS ((const char *, rtx, long));
298 static void flush_queued_reg_saves PARAMS ((void));
299 static bool clobbers_queued_reg_save PARAMS ((rtx));
300 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
302 /* Support for complex CFA locations. */
303 static void output_cfa_loc PARAMS ((dw_cfi_ref));
304 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
305 struct dw_loc_descr_struct *));
306 static struct dw_loc_descr_struct *build_cfa_loc
307 PARAMS ((dw_cfa_location *));
308 static void def_cfa_1 PARAMS ((const char *,
309 dw_cfa_location *));
311 /* How to start an assembler comment. */
312 #ifndef ASM_COMMENT_START
313 #define ASM_COMMENT_START ";#"
314 #endif
316 /* Data and reference forms for relocatable data. */
317 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
318 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
320 #ifndef DEBUG_FRAME_SECTION
321 #define DEBUG_FRAME_SECTION ".debug_frame"
322 #endif
324 #ifndef FUNC_BEGIN_LABEL
325 #define FUNC_BEGIN_LABEL "LFB"
326 #endif
328 #ifndef FUNC_END_LABEL
329 #define FUNC_END_LABEL "LFE"
330 #endif
332 #define FRAME_BEGIN_LABEL "Lframe"
333 #define CIE_AFTER_SIZE_LABEL "LSCIE"
334 #define CIE_END_LABEL "LECIE"
335 #define CIE_LENGTH_LABEL "LLCIE"
336 #define FDE_LABEL "LSFDE"
337 #define FDE_AFTER_SIZE_LABEL "LASFDE"
338 #define FDE_END_LABEL "LEFDE"
339 #define FDE_LENGTH_LABEL "LLFDE"
340 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
341 #define LINE_NUMBER_END_LABEL "LELT"
342 #define LN_PROLOG_AS_LABEL "LASLTP"
343 #define LN_PROLOG_END_LABEL "LELTP"
344 #define DIE_LABEL_PREFIX "DW"
346 /* The DWARF 2 CFA column which tracks the return address. Normally this
347 is the column for PC, or the first column after all of the hard
348 registers. */
349 #ifndef DWARF_FRAME_RETURN_COLUMN
350 #ifdef PC_REGNUM
351 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
352 #else
353 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
354 #endif
355 #endif
357 /* The mapping from gcc register number to DWARF 2 CFA column number. By
358 default, we just provide columns for all registers. */
359 #ifndef DWARF_FRAME_REGNUM
360 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
361 #endif
363 /* The offset from the incoming value of %sp to the top of the stack frame
364 for the current function. */
365 #ifndef INCOMING_FRAME_SP_OFFSET
366 #define INCOMING_FRAME_SP_OFFSET 0
367 #endif
369 /* Hook used by __throw. */
372 expand_builtin_dwarf_fp_regnum ()
374 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
377 /* Return a pointer to a copy of the section string name S with all
378 attributes stripped off, and an asterisk prepended (for assemble_name). */
380 static inline char *
381 stripattributes (s)
382 const char *s;
384 char *stripped = xmalloc (strlen (s) + 2);
385 char *p = stripped;
387 *p++ = '*';
389 while (*s && *s != ',')
390 *p++ = *s++;
392 *p = '\0';
393 return stripped;
396 /* Generate code to initialize the register size table. */
398 void
399 expand_builtin_init_dwarf_reg_sizes (address)
400 tree address;
402 int i;
403 enum machine_mode mode = TYPE_MODE (char_type_node);
404 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
405 rtx mem = gen_rtx_MEM (BLKmode, addr);
407 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
408 if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS)
410 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
411 HOST_WIDE_INT size = GET_MODE_SIZE (reg_raw_mode[i]);
413 if (offset < 0)
414 continue;
416 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
420 /* Convert a DWARF call frame info. operation to its string name */
422 static const char *
423 dwarf_cfi_name (cfi_opc)
424 unsigned cfi_opc;
426 switch (cfi_opc)
428 case DW_CFA_advance_loc:
429 return "DW_CFA_advance_loc";
430 case DW_CFA_offset:
431 return "DW_CFA_offset";
432 case DW_CFA_restore:
433 return "DW_CFA_restore";
434 case DW_CFA_nop:
435 return "DW_CFA_nop";
436 case DW_CFA_set_loc:
437 return "DW_CFA_set_loc";
438 case DW_CFA_advance_loc1:
439 return "DW_CFA_advance_loc1";
440 case DW_CFA_advance_loc2:
441 return "DW_CFA_advance_loc2";
442 case DW_CFA_advance_loc4:
443 return "DW_CFA_advance_loc4";
444 case DW_CFA_offset_extended:
445 return "DW_CFA_offset_extended";
446 case DW_CFA_restore_extended:
447 return "DW_CFA_restore_extended";
448 case DW_CFA_undefined:
449 return "DW_CFA_undefined";
450 case DW_CFA_same_value:
451 return "DW_CFA_same_value";
452 case DW_CFA_register:
453 return "DW_CFA_register";
454 case DW_CFA_remember_state:
455 return "DW_CFA_remember_state";
456 case DW_CFA_restore_state:
457 return "DW_CFA_restore_state";
458 case DW_CFA_def_cfa:
459 return "DW_CFA_def_cfa";
460 case DW_CFA_def_cfa_register:
461 return "DW_CFA_def_cfa_register";
462 case DW_CFA_def_cfa_offset:
463 return "DW_CFA_def_cfa_offset";
465 /* DWARF 3 */
466 case DW_CFA_def_cfa_expression:
467 return "DW_CFA_def_cfa_expression";
468 case DW_CFA_expression:
469 return "DW_CFA_expression";
470 case DW_CFA_offset_extended_sf:
471 return "DW_CFA_offset_extended_sf";
472 case DW_CFA_def_cfa_sf:
473 return "DW_CFA_def_cfa_sf";
474 case DW_CFA_def_cfa_offset_sf:
475 return "DW_CFA_def_cfa_offset_sf";
477 /* SGI/MIPS specific */
478 case DW_CFA_MIPS_advance_loc8:
479 return "DW_CFA_MIPS_advance_loc8";
481 /* GNU extensions */
482 case DW_CFA_GNU_window_save:
483 return "DW_CFA_GNU_window_save";
484 case DW_CFA_GNU_args_size:
485 return "DW_CFA_GNU_args_size";
486 case DW_CFA_GNU_negative_offset_extended:
487 return "DW_CFA_GNU_negative_offset_extended";
489 default:
490 return "DW_CFA_<unknown>";
494 /* Return a pointer to a newly allocated Call Frame Instruction. */
496 static inline dw_cfi_ref
497 new_cfi ()
499 dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
501 cfi->dw_cfi_next = NULL;
502 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
503 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
505 return cfi;
508 /* Add a Call Frame Instruction to list of instructions. */
510 static inline void
511 add_cfi (list_head, cfi)
512 dw_cfi_ref *list_head;
513 dw_cfi_ref cfi;
515 dw_cfi_ref *p;
517 /* Find the end of the chain. */
518 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
521 *p = cfi;
524 /* Generate a new label for the CFI info to refer to. */
526 char *
527 dwarf2out_cfi_label ()
529 static char label[20];
530 static unsigned long label_num = 0;
532 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
533 ASM_OUTPUT_LABEL (asm_out_file, label);
534 return label;
537 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
538 or to the CIE if LABEL is NULL. */
540 static void
541 add_fde_cfi (label, cfi)
542 const char *label;
543 dw_cfi_ref cfi;
545 if (label)
547 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
549 if (*label == 0)
550 label = dwarf2out_cfi_label ();
552 if (fde->dw_fde_current_label == NULL
553 || strcmp (label, fde->dw_fde_current_label) != 0)
555 dw_cfi_ref xcfi;
557 fde->dw_fde_current_label = label = xstrdup (label);
559 /* Set the location counter to the new label. */
560 xcfi = new_cfi ();
561 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
562 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
563 add_cfi (&fde->dw_fde_cfi, xcfi);
566 add_cfi (&fde->dw_fde_cfi, cfi);
569 else
570 add_cfi (&cie_cfi_head, cfi);
573 /* Subroutine of lookup_cfa. */
575 static inline void
576 lookup_cfa_1 (cfi, loc)
577 dw_cfi_ref cfi;
578 dw_cfa_location *loc;
580 switch (cfi->dw_cfi_opc)
582 case DW_CFA_def_cfa_offset:
583 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
584 break;
585 case DW_CFA_def_cfa_register:
586 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
587 break;
588 case DW_CFA_def_cfa:
589 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
590 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
591 break;
592 case DW_CFA_def_cfa_expression:
593 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
594 break;
595 default:
596 break;
600 /* Find the previous value for the CFA. */
602 static void
603 lookup_cfa (loc)
604 dw_cfa_location *loc;
606 dw_cfi_ref cfi;
608 loc->reg = (unsigned long) -1;
609 loc->offset = 0;
610 loc->indirect = 0;
611 loc->base_offset = 0;
613 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
614 lookup_cfa_1 (cfi, loc);
616 if (fde_table_in_use)
618 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
619 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
620 lookup_cfa_1 (cfi, loc);
624 /* The current rule for calculating the DWARF2 canonical frame address. */
625 static dw_cfa_location cfa;
627 /* The register used for saving registers to the stack, and its offset
628 from the CFA. */
629 static dw_cfa_location cfa_store;
631 /* The running total of the size of arguments pushed onto the stack. */
632 static long args_size;
634 /* The last args_size we actually output. */
635 static long old_args_size;
637 /* Entry point to update the canonical frame address (CFA).
638 LABEL is passed to add_fde_cfi. The value of CFA is now to be
639 calculated from REG+OFFSET. */
641 void
642 dwarf2out_def_cfa (label, reg, offset)
643 const char *label;
644 unsigned reg;
645 long offset;
647 dw_cfa_location loc;
648 loc.indirect = 0;
649 loc.base_offset = 0;
650 loc.reg = reg;
651 loc.offset = offset;
652 def_cfa_1 (label, &loc);
655 /* This routine does the actual work. The CFA is now calculated from
656 the dw_cfa_location structure. */
658 static void
659 def_cfa_1 (label, loc_p)
660 const char *label;
661 dw_cfa_location *loc_p;
663 dw_cfi_ref cfi;
664 dw_cfa_location old_cfa, loc;
666 cfa = *loc_p;
667 loc = *loc_p;
669 if (cfa_store.reg == loc.reg && loc.indirect == 0)
670 cfa_store.offset = loc.offset;
672 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
673 lookup_cfa (&old_cfa);
675 /* If nothing changed, no need to issue any call frame instructions. */
676 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
677 && loc.indirect == old_cfa.indirect
678 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
679 return;
681 cfi = new_cfi ();
683 if (loc.reg == old_cfa.reg && !loc.indirect)
685 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
686 indicating the CFA register did not change but the offset
687 did. */
688 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
689 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
692 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
693 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
694 && !loc.indirect)
696 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
697 indicating the CFA register has changed to <register> but the
698 offset has not changed. */
699 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
700 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
702 #endif
704 else if (loc.indirect == 0)
706 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
707 indicating the CFA register has changed to <register> with
708 the specified offset. */
709 cfi->dw_cfi_opc = DW_CFA_def_cfa;
710 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
711 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
713 else
715 /* Construct a DW_CFA_def_cfa_expression instruction to
716 calculate the CFA using a full location expression since no
717 register-offset pair is available. */
718 struct dw_loc_descr_struct *loc_list;
720 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
721 loc_list = build_cfa_loc (&loc);
722 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
725 add_fde_cfi (label, cfi);
728 /* Add the CFI for saving a register. REG is the CFA column number.
729 LABEL is passed to add_fde_cfi.
730 If SREG is -1, the register is saved at OFFSET from the CFA;
731 otherwise it is saved in SREG. */
733 static void
734 reg_save (label, reg, sreg, offset)
735 const char *label;
736 unsigned reg;
737 unsigned sreg;
738 long offset;
740 dw_cfi_ref cfi = new_cfi ();
742 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
744 /* The following comparison is correct. -1 is used to indicate that
745 the value isn't a register number. */
746 if (sreg == (unsigned int) -1)
748 if (reg & ~0x3f)
749 /* The register number won't fit in 6 bits, so we have to use
750 the long form. */
751 cfi->dw_cfi_opc = DW_CFA_offset_extended;
752 else
753 cfi->dw_cfi_opc = DW_CFA_offset;
755 #ifdef ENABLE_CHECKING
757 /* If we get an offset that is not a multiple of
758 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
759 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
760 description. */
761 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
763 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
764 abort ();
766 #endif
767 offset /= DWARF_CIE_DATA_ALIGNMENT;
768 if (offset < 0)
769 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
771 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
773 else if (sreg == reg)
774 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
775 return;
776 else
778 cfi->dw_cfi_opc = DW_CFA_register;
779 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
782 add_fde_cfi (label, cfi);
785 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
786 This CFI tells the unwinder that it needs to restore the window registers
787 from the previous frame's window save area.
789 ??? Perhaps we should note in the CIE where windows are saved (instead of
790 assuming 0(cfa)) and what registers are in the window. */
792 void
793 dwarf2out_window_save (label)
794 const char *label;
796 dw_cfi_ref cfi = new_cfi ();
798 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
799 add_fde_cfi (label, cfi);
802 /* Add a CFI to update the running total of the size of arguments
803 pushed onto the stack. */
805 void
806 dwarf2out_args_size (label, size)
807 const char *label;
808 long size;
810 dw_cfi_ref cfi;
812 if (size == old_args_size)
813 return;
815 old_args_size = size;
817 cfi = new_cfi ();
818 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
819 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
820 add_fde_cfi (label, cfi);
823 /* Entry point for saving a register to the stack. REG is the GCC register
824 number. LABEL and OFFSET are passed to reg_save. */
826 void
827 dwarf2out_reg_save (label, reg, offset)
828 const char *label;
829 unsigned reg;
830 long offset;
832 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
835 /* Entry point for saving the return address in the stack.
836 LABEL and OFFSET are passed to reg_save. */
838 void
839 dwarf2out_return_save (label, offset)
840 const char *label;
841 long offset;
843 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
846 /* Entry point for saving the return address in a register.
847 LABEL and SREG are passed to reg_save. */
849 void
850 dwarf2out_return_reg (label, sreg)
851 const char *label;
852 unsigned sreg;
854 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
857 /* Record the initial position of the return address. RTL is
858 INCOMING_RETURN_ADDR_RTX. */
860 static void
861 initial_return_save (rtl)
862 rtx rtl;
864 unsigned int reg = (unsigned int) -1;
865 HOST_WIDE_INT offset = 0;
867 switch (GET_CODE (rtl))
869 case REG:
870 /* RA is in a register. */
871 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
872 break;
874 case MEM:
875 /* RA is on the stack. */
876 rtl = XEXP (rtl, 0);
877 switch (GET_CODE (rtl))
879 case REG:
880 if (REGNO (rtl) != STACK_POINTER_REGNUM)
881 abort ();
882 offset = 0;
883 break;
885 case PLUS:
886 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
887 abort ();
888 offset = INTVAL (XEXP (rtl, 1));
889 break;
891 case MINUS:
892 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
893 abort ();
894 offset = -INTVAL (XEXP (rtl, 1));
895 break;
897 default:
898 abort ();
901 break;
903 case PLUS:
904 /* The return address is at some offset from any value we can
905 actually load. For instance, on the SPARC it is in %i7+8. Just
906 ignore the offset for now; it doesn't matter for unwinding frames. */
907 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
908 abort ();
909 initial_return_save (XEXP (rtl, 0));
910 return;
912 default:
913 abort ();
916 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
919 /* Given a SET, calculate the amount of stack adjustment it
920 contains. */
922 static long
923 stack_adjust_offset (pattern)
924 rtx pattern;
926 rtx src = SET_SRC (pattern);
927 rtx dest = SET_DEST (pattern);
928 HOST_WIDE_INT offset = 0;
929 enum rtx_code code;
931 if (dest == stack_pointer_rtx)
933 /* (set (reg sp) (plus (reg sp) (const_int))) */
934 code = GET_CODE (src);
935 if (! (code == PLUS || code == MINUS)
936 || XEXP (src, 0) != stack_pointer_rtx
937 || GET_CODE (XEXP (src, 1)) != CONST_INT)
938 return 0;
940 offset = INTVAL (XEXP (src, 1));
941 if (code == PLUS)
942 offset = -offset;
944 else if (GET_CODE (dest) == MEM)
946 /* (set (mem (pre_dec (reg sp))) (foo)) */
947 src = XEXP (dest, 0);
948 code = GET_CODE (src);
950 switch (code)
952 case PRE_MODIFY:
953 case POST_MODIFY:
954 if (XEXP (src, 0) == stack_pointer_rtx)
956 rtx val = XEXP (XEXP (src, 1), 1);
957 /* We handle only adjustments by constant amount. */
958 if (GET_CODE (XEXP (src, 1)) != PLUS ||
959 GET_CODE (val) != CONST_INT)
960 abort ();
961 offset = -INTVAL (val);
962 break;
964 return 0;
966 case PRE_DEC:
967 case POST_DEC:
968 if (XEXP (src, 0) == stack_pointer_rtx)
970 offset = GET_MODE_SIZE (GET_MODE (dest));
971 break;
973 return 0;
975 case PRE_INC:
976 case POST_INC:
977 if (XEXP (src, 0) == stack_pointer_rtx)
979 offset = -GET_MODE_SIZE (GET_MODE (dest));
980 break;
982 return 0;
984 default:
985 return 0;
988 else
989 return 0;
991 return offset;
994 /* Check INSN to see if it looks like a push or a stack adjustment, and
995 make a note of it if it does. EH uses this information to find out how
996 much extra space it needs to pop off the stack. */
998 static void
999 dwarf2out_stack_adjust (insn)
1000 rtx insn;
1002 HOST_WIDE_INT offset;
1003 const char *label;
1004 int i;
1006 if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN)
1008 /* Extract the size of the args from the CALL rtx itself. */
1009 insn = PATTERN (insn);
1010 if (GET_CODE (insn) == PARALLEL)
1011 insn = XVECEXP (insn, 0, 0);
1012 if (GET_CODE (insn) == SET)
1013 insn = SET_SRC (insn);
1014 if (GET_CODE (insn) != CALL)
1015 abort ();
1017 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1018 return;
1021 /* If only calls can throw, and we have a frame pointer,
1022 save up adjustments until we see the CALL_INSN. */
1023 else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1024 return;
1026 if (GET_CODE (insn) == BARRIER)
1028 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1029 the compiler will have already emitted a stack adjustment, but
1030 doesn't bother for calls to noreturn functions. */
1031 #ifdef STACK_GROWS_DOWNWARD
1032 offset = -args_size;
1033 #else
1034 offset = args_size;
1035 #endif
1037 else if (GET_CODE (PATTERN (insn)) == SET)
1038 offset = stack_adjust_offset (PATTERN (insn));
1039 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1040 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1042 /* There may be stack adjustments inside compound insns. Search
1043 for them. */
1044 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1045 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1046 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1048 else
1049 return;
1051 if (offset == 0)
1052 return;
1054 if (cfa.reg == STACK_POINTER_REGNUM)
1055 cfa.offset += offset;
1057 #ifndef STACK_GROWS_DOWNWARD
1058 offset = -offset;
1059 #endif
1061 args_size += offset;
1062 if (args_size < 0)
1063 args_size = 0;
1065 label = dwarf2out_cfi_label ();
1066 def_cfa_1 (label, &cfa);
1067 dwarf2out_args_size (label, args_size);
1070 /* We delay emitting a register save until either (a) we reach the end
1071 of the prologue or (b) the register is clobbered. This clusters
1072 register saves so that there are fewer pc advances. */
1074 struct queued_reg_save
1076 struct queued_reg_save *next;
1077 rtx reg;
1078 long cfa_offset;
1081 static struct queued_reg_save *queued_reg_saves;
1082 static const char *last_reg_save_label;
1084 static void
1085 queue_reg_save (label, reg, offset)
1086 const char *label;
1087 rtx reg;
1088 long offset;
1090 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1092 q->next = queued_reg_saves;
1093 q->reg = reg;
1094 q->cfa_offset = offset;
1095 queued_reg_saves = q;
1097 last_reg_save_label = label;
1100 static void
1101 flush_queued_reg_saves ()
1103 struct queued_reg_save *q, *next;
1105 for (q = queued_reg_saves; q; q = next)
1107 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1108 next = q->next;
1109 free (q);
1112 queued_reg_saves = NULL;
1113 last_reg_save_label = NULL;
1116 static bool
1117 clobbers_queued_reg_save (insn)
1118 rtx insn;
1120 struct queued_reg_save *q;
1122 for (q = queued_reg_saves; q; q = q->next)
1123 if (modified_in_p (q->reg, insn))
1124 return true;
1126 return false;
1130 /* A temporary register holding an integral value used in adjusting SP
1131 or setting up the store_reg. The "offset" field holds the integer
1132 value, not an offset. */
1133 static dw_cfa_location cfa_temp;
1135 /* Record call frame debugging information for an expression EXPR,
1136 which either sets SP or FP (adjusting how we calculate the frame
1137 address) or saves a register to the stack. LABEL indicates the
1138 address of EXPR.
1140 This function encodes a state machine mapping rtxes to actions on
1141 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1142 users need not read the source code.
1144 The High-Level Picture
1146 Changes in the register we use to calculate the CFA: Currently we
1147 assume that if you copy the CFA register into another register, we
1148 should take the other one as the new CFA register; this seems to
1149 work pretty well. If it's wrong for some target, it's simple
1150 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1152 Changes in the register we use for saving registers to the stack:
1153 This is usually SP, but not always. Again, we deduce that if you
1154 copy SP into another register (and SP is not the CFA register),
1155 then the new register is the one we will be using for register
1156 saves. This also seems to work.
1158 Register saves: There's not much guesswork about this one; if
1159 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1160 register save, and the register used to calculate the destination
1161 had better be the one we think we're using for this purpose.
1163 Except: If the register being saved is the CFA register, and the
1164 offset is non-zero, we are saving the CFA, so we assume we have to
1165 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1166 the intent is to save the value of SP from the previous frame.
1168 Invariants / Summaries of Rules
1170 cfa current rule for calculating the CFA. It usually
1171 consists of a register and an offset.
1172 cfa_store register used by prologue code to save things to the stack
1173 cfa_store.offset is the offset from the value of
1174 cfa_store.reg to the actual CFA
1175 cfa_temp register holding an integral value. cfa_temp.offset
1176 stores the value, which will be used to adjust the
1177 stack pointer. cfa_temp is also used like cfa_store,
1178 to track stores to the stack via fp or a temp reg.
1180 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1181 with cfa.reg as the first operand changes the cfa.reg and its
1182 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1183 cfa_temp.offset.
1185 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1186 expression yielding a constant. This sets cfa_temp.reg
1187 and cfa_temp.offset.
1189 Rule 5: Create a new register cfa_store used to save items to the
1190 stack.
1192 Rules 10-14: Save a register to the stack. Define offset as the
1193 difference of the original location and cfa_store's
1194 location (or cfa_temp's location if cfa_temp is used).
1196 The Rules
1198 "{a,b}" indicates a choice of a xor b.
1199 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1201 Rule 1:
1202 (set <reg1> <reg2>:cfa.reg)
1203 effects: cfa.reg = <reg1>
1204 cfa.offset unchanged
1205 cfa_temp.reg = <reg1>
1206 cfa_temp.offset = cfa.offset
1208 Rule 2:
1209 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1210 {<const_int>,<reg>:cfa_temp.reg}))
1211 effects: cfa.reg = sp if fp used
1212 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1213 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1214 if cfa_store.reg==sp
1216 Rule 3:
1217 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1218 effects: cfa.reg = fp
1219 cfa_offset += +/- <const_int>
1221 Rule 4:
1222 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1223 constraints: <reg1> != fp
1224 <reg1> != sp
1225 effects: cfa.reg = <reg1>
1226 cfa_temp.reg = <reg1>
1227 cfa_temp.offset = cfa.offset
1229 Rule 5:
1230 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1231 constraints: <reg1> != fp
1232 <reg1> != sp
1233 effects: cfa_store.reg = <reg1>
1234 cfa_store.offset = cfa.offset - cfa_temp.offset
1236 Rule 6:
1237 (set <reg> <const_int>)
1238 effects: cfa_temp.reg = <reg>
1239 cfa_temp.offset = <const_int>
1241 Rule 7:
1242 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1243 effects: cfa_temp.reg = <reg1>
1244 cfa_temp.offset |= <const_int>
1246 Rule 8:
1247 (set <reg> (high <exp>))
1248 effects: none
1250 Rule 9:
1251 (set <reg> (lo_sum <exp> <const_int>))
1252 effects: cfa_temp.reg = <reg>
1253 cfa_temp.offset = <const_int>
1255 Rule 10:
1256 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1257 effects: cfa_store.offset -= <const_int>
1258 cfa.offset = cfa_store.offset if cfa.reg == sp
1259 cfa.reg = sp
1260 cfa.base_offset = -cfa_store.offset
1262 Rule 11:
1263 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1264 effects: cfa_store.offset += -/+ mode_size(mem)
1265 cfa.offset = cfa_store.offset if cfa.reg == sp
1266 cfa.reg = sp
1267 cfa.base_offset = -cfa_store.offset
1269 Rule 12:
1270 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1272 <reg2>)
1273 effects: cfa.reg = <reg1>
1274 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1276 Rule 13:
1277 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1278 effects: cfa.reg = <reg1>
1279 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1281 Rule 14:
1282 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1283 effects: cfa.reg = <reg1>
1284 cfa.base_offset = -cfa_temp.offset
1285 cfa_temp.offset -= mode_size(mem) */
1287 static void
1288 dwarf2out_frame_debug_expr (expr, label)
1289 rtx expr;
1290 const char *label;
1292 rtx src, dest;
1293 HOST_WIDE_INT offset;
1295 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1296 the PARALLEL independently. The first element is always processed if
1297 it is a SET. This is for backward compatibility. Other elements
1298 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1299 flag is set in them. */
1300 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1302 int par_index;
1303 int limit = XVECLEN (expr, 0);
1305 for (par_index = 0; par_index < limit; par_index++)
1306 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1307 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1308 || par_index == 0))
1309 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1311 return;
1314 if (GET_CODE (expr) != SET)
1315 abort ();
1317 src = SET_SRC (expr);
1318 dest = SET_DEST (expr);
1320 switch (GET_CODE (dest))
1322 case REG:
1323 /* Rule 1 */
1324 /* Update the CFA rule wrt SP or FP. Make sure src is
1325 relative to the current CFA register. */
1326 switch (GET_CODE (src))
1328 /* Setting FP from SP. */
1329 case REG:
1330 if (cfa.reg == (unsigned) REGNO (src))
1331 /* OK. */
1333 else
1334 abort ();
1336 /* We used to require that dest be either SP or FP, but the
1337 ARM copies SP to a temporary register, and from there to
1338 FP. So we just rely on the backends to only set
1339 RTX_FRAME_RELATED_P on appropriate insns. */
1340 cfa.reg = REGNO (dest);
1341 cfa_temp.reg = cfa.reg;
1342 cfa_temp.offset = cfa.offset;
1343 break;
1345 case PLUS:
1346 case MINUS:
1347 case LO_SUM:
1348 if (dest == stack_pointer_rtx)
1350 /* Rule 2 */
1351 /* Adjusting SP. */
1352 switch (GET_CODE (XEXP (src, 1)))
1354 case CONST_INT:
1355 offset = INTVAL (XEXP (src, 1));
1356 break;
1357 case REG:
1358 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1359 abort ();
1360 offset = cfa_temp.offset;
1361 break;
1362 default:
1363 abort ();
1366 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1368 /* Restoring SP from FP in the epilogue. */
1369 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1370 abort ();
1371 cfa.reg = STACK_POINTER_REGNUM;
1373 else if (GET_CODE (src) == LO_SUM)
1374 /* Assume we've set the source reg of the LO_SUM from sp. */
1376 else if (XEXP (src, 0) != stack_pointer_rtx)
1377 abort ();
1379 if (GET_CODE (src) != MINUS)
1380 offset = -offset;
1381 if (cfa.reg == STACK_POINTER_REGNUM)
1382 cfa.offset += offset;
1383 if (cfa_store.reg == STACK_POINTER_REGNUM)
1384 cfa_store.offset += offset;
1386 else if (dest == hard_frame_pointer_rtx)
1388 /* Rule 3 */
1389 /* Either setting the FP from an offset of the SP,
1390 or adjusting the FP */
1391 if (! frame_pointer_needed)
1392 abort ();
1394 if (GET_CODE (XEXP (src, 0)) == REG
1395 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1396 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1398 offset = INTVAL (XEXP (src, 1));
1399 if (GET_CODE (src) != MINUS)
1400 offset = -offset;
1401 cfa.offset += offset;
1402 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1404 else
1405 abort ();
1407 else
1409 if (GET_CODE (src) == MINUS)
1410 abort ();
1412 /* Rule 4 */
1413 if (GET_CODE (XEXP (src, 0)) == REG
1414 && REGNO (XEXP (src, 0)) == cfa.reg
1415 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1417 /* Setting a temporary CFA register that will be copied
1418 into the FP later on. */
1419 offset = - INTVAL (XEXP (src, 1));
1420 cfa.offset += offset;
1421 cfa.reg = REGNO (dest);
1422 /* Or used to save regs to the stack. */
1423 cfa_temp.reg = cfa.reg;
1424 cfa_temp.offset = cfa.offset;
1427 /* Rule 5 */
1428 else if (GET_CODE (XEXP (src, 0)) == REG
1429 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1430 && XEXP (src, 1) == stack_pointer_rtx)
1432 /* Setting a scratch register that we will use instead
1433 of SP for saving registers to the stack. */
1434 if (cfa.reg != STACK_POINTER_REGNUM)
1435 abort ();
1436 cfa_store.reg = REGNO (dest);
1437 cfa_store.offset = cfa.offset - cfa_temp.offset;
1440 /* Rule 9 */
1441 else if (GET_CODE (src) == LO_SUM
1442 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1444 cfa_temp.reg = REGNO (dest);
1445 cfa_temp.offset = INTVAL (XEXP (src, 1));
1447 else
1448 abort ();
1450 break;
1452 /* Rule 6 */
1453 case CONST_INT:
1454 cfa_temp.reg = REGNO (dest);
1455 cfa_temp.offset = INTVAL (src);
1456 break;
1458 /* Rule 7 */
1459 case IOR:
1460 if (GET_CODE (XEXP (src, 0)) != REG
1461 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1462 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1463 abort ();
1465 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1466 cfa_temp.reg = REGNO (dest);
1467 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1468 break;
1470 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1471 which will fill in all of the bits. */
1472 /* Rule 8 */
1473 case HIGH:
1474 break;
1476 default:
1477 abort ();
1480 def_cfa_1 (label, &cfa);
1481 break;
1483 case MEM:
1484 if (GET_CODE (src) != REG)
1485 abort ();
1487 /* Saving a register to the stack. Make sure dest is relative to the
1488 CFA register. */
1489 switch (GET_CODE (XEXP (dest, 0)))
1491 /* Rule 10 */
1492 /* With a push. */
1493 case PRE_MODIFY:
1494 /* We can't handle variable size modifications. */
1495 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1496 abort ();
1497 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1499 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1500 || cfa_store.reg != STACK_POINTER_REGNUM)
1501 abort ();
1503 cfa_store.offset += offset;
1504 if (cfa.reg == STACK_POINTER_REGNUM)
1505 cfa.offset = cfa_store.offset;
1507 offset = -cfa_store.offset;
1508 break;
1510 /* Rule 11 */
1511 case PRE_INC:
1512 case PRE_DEC:
1513 offset = GET_MODE_SIZE (GET_MODE (dest));
1514 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1515 offset = -offset;
1517 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1518 || cfa_store.reg != STACK_POINTER_REGNUM)
1519 abort ();
1521 cfa_store.offset += offset;
1522 if (cfa.reg == STACK_POINTER_REGNUM)
1523 cfa.offset = cfa_store.offset;
1525 offset = -cfa_store.offset;
1526 break;
1528 /* Rule 12 */
1529 /* With an offset. */
1530 case PLUS:
1531 case MINUS:
1532 case LO_SUM:
1533 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1534 abort ();
1535 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1536 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1537 offset = -offset;
1539 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1540 offset -= cfa_store.offset;
1541 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1542 offset -= cfa_temp.offset;
1543 else
1544 abort ();
1545 break;
1547 /* Rule 13 */
1548 /* Without an offset. */
1549 case REG:
1550 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1551 offset = -cfa_store.offset;
1552 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1553 offset = -cfa_temp.offset;
1554 else
1555 abort ();
1556 break;
1558 /* Rule 14 */
1559 case POST_INC:
1560 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1561 abort ();
1562 offset = -cfa_temp.offset;
1563 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1564 break;
1566 default:
1567 abort ();
1570 if (REGNO (src) != STACK_POINTER_REGNUM
1571 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1572 && (unsigned) REGNO (src) == cfa.reg)
1574 /* We're storing the current CFA reg into the stack. */
1576 if (cfa.offset == 0)
1578 /* If the source register is exactly the CFA, assume
1579 we're saving SP like any other register; this happens
1580 on the ARM. */
1581 def_cfa_1 (label, &cfa);
1582 queue_reg_save (label, stack_pointer_rtx, offset);
1583 break;
1585 else
1587 /* Otherwise, we'll need to look in the stack to
1588 calculate the CFA. */
1589 rtx x = XEXP (dest, 0);
1591 if (GET_CODE (x) != REG)
1592 x = XEXP (x, 0);
1593 if (GET_CODE (x) != REG)
1594 abort ();
1596 cfa.reg = REGNO (x);
1597 cfa.base_offset = offset;
1598 cfa.indirect = 1;
1599 def_cfa_1 (label, &cfa);
1600 break;
1604 def_cfa_1 (label, &cfa);
1605 queue_reg_save (label, src, offset);
1606 break;
1608 default:
1609 abort ();
1613 /* Record call frame debugging information for INSN, which either
1614 sets SP or FP (adjusting how we calculate the frame address) or saves a
1615 register to the stack. If INSN is NULL_RTX, initialize our state. */
1617 void
1618 dwarf2out_frame_debug (insn)
1619 rtx insn;
1621 const char *label;
1622 rtx src;
1624 if (insn == NULL_RTX)
1626 /* Flush any queued register saves. */
1627 flush_queued_reg_saves ();
1629 /* Set up state for generating call frame debug info. */
1630 lookup_cfa (&cfa);
1631 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1632 abort ();
1634 cfa.reg = STACK_POINTER_REGNUM;
1635 cfa_store = cfa;
1636 cfa_temp.reg = -1;
1637 cfa_temp.offset = 0;
1638 return;
1641 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1642 flush_queued_reg_saves ();
1644 if (! RTX_FRAME_RELATED_P (insn))
1646 if (!ACCUMULATE_OUTGOING_ARGS)
1647 dwarf2out_stack_adjust (insn);
1649 return;
1652 label = dwarf2out_cfi_label ();
1653 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1654 if (src)
1655 insn = XEXP (src, 0);
1656 else
1657 insn = PATTERN (insn);
1659 dwarf2out_frame_debug_expr (insn, label);
1662 /* Output a Call Frame Information opcode and its operand(s). */
1664 static void
1665 output_cfi (cfi, fde, for_eh)
1666 dw_cfi_ref cfi;
1667 dw_fde_ref fde;
1668 int for_eh;
1670 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1671 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1672 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1673 "DW_CFA_advance_loc 0x%lx",
1674 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1675 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1677 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1678 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1679 "DW_CFA_offset, column 0x%lx",
1680 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1681 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1683 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1684 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1685 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1686 "DW_CFA_restore, column 0x%lx",
1687 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1688 else
1690 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1691 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1693 switch (cfi->dw_cfi_opc)
1695 case DW_CFA_set_loc:
1696 if (for_eh)
1697 dw2_asm_output_encoded_addr_rtx (
1698 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1699 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1700 NULL);
1701 else
1702 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1703 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1704 break;
1706 case DW_CFA_advance_loc1:
1707 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1708 fde->dw_fde_current_label, NULL);
1709 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1710 break;
1712 case DW_CFA_advance_loc2:
1713 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1714 fde->dw_fde_current_label, NULL);
1715 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1716 break;
1718 case DW_CFA_advance_loc4:
1719 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1720 fde->dw_fde_current_label, NULL);
1721 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1722 break;
1724 case DW_CFA_MIPS_advance_loc8:
1725 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1726 fde->dw_fde_current_label, NULL);
1727 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1728 break;
1730 case DW_CFA_offset_extended:
1731 case DW_CFA_def_cfa:
1732 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1733 NULL);
1734 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1735 break;
1737 case DW_CFA_offset_extended_sf:
1738 case DW_CFA_def_cfa_sf:
1739 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1740 NULL);
1741 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1742 break;
1744 case DW_CFA_restore_extended:
1745 case DW_CFA_undefined:
1746 case DW_CFA_same_value:
1747 case DW_CFA_def_cfa_register:
1748 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1749 NULL);
1750 break;
1752 case DW_CFA_register:
1753 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1754 NULL);
1755 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num,
1756 NULL);
1757 break;
1759 case DW_CFA_def_cfa_offset:
1760 case DW_CFA_GNU_args_size:
1761 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1762 break;
1764 case DW_CFA_def_cfa_offset_sf:
1765 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1766 break;
1768 case DW_CFA_GNU_window_save:
1769 break;
1771 case DW_CFA_def_cfa_expression:
1772 case DW_CFA_expression:
1773 output_cfa_loc (cfi);
1774 break;
1776 case DW_CFA_GNU_negative_offset_extended:
1777 /* Obsoleted by DW_CFA_offset_extended_sf. */
1778 abort ();
1780 default:
1781 break;
1786 /* Output the call frame information used to used to record information
1787 that relates to calculating the frame pointer, and records the
1788 location of saved registers. */
1790 static void
1791 output_call_frame_info (for_eh)
1792 int for_eh;
1794 unsigned int i;
1795 dw_fde_ref fde;
1796 dw_cfi_ref cfi;
1797 char l1[20], l2[20], section_start_label[20];
1798 int any_lsda_needed = 0;
1799 char augmentation[6];
1800 int augmentation_size;
1801 int fde_encoding = DW_EH_PE_absptr;
1802 int per_encoding = DW_EH_PE_absptr;
1803 int lsda_encoding = DW_EH_PE_absptr;
1805 /* Don't emit a CIE if there won't be any FDEs. */
1806 if (fde_table_in_use == 0)
1807 return;
1809 /* If we don't have any functions we'll want to unwind out of, don't emit any
1810 EH unwind information. */
1811 if (for_eh)
1813 int any_eh_needed = flag_asynchronous_unwind_tables;
1815 for (i = 0; i < fde_table_in_use; i++)
1816 if (fde_table[i].uses_eh_lsda)
1817 any_eh_needed = any_lsda_needed = 1;
1818 else if (! fde_table[i].nothrow)
1819 any_eh_needed = 1;
1821 if (! any_eh_needed)
1822 return;
1825 /* We're going to be generating comments, so turn on app. */
1826 if (flag_debug_asm)
1827 app_enable ();
1829 if (for_eh)
1830 (*targetm.asm_out.eh_frame_section) ();
1831 else
1832 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1834 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1835 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1837 /* Output the CIE. */
1838 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1839 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1840 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1841 "Length of Common Information Entry");
1842 ASM_OUTPUT_LABEL (asm_out_file, l1);
1844 /* Now that the CIE pointer is PC-relative for EH,
1845 use 0 to identify the CIE. */
1846 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1847 (for_eh ? 0 : DW_CIE_ID),
1848 "CIE Identifier Tag");
1850 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1852 augmentation[0] = 0;
1853 augmentation_size = 0;
1854 if (for_eh)
1856 char *p;
1858 /* Augmentation:
1859 z Indicates that a uleb128 is present to size the
1860 augmentation section.
1861 L Indicates the encoding (and thus presence) of
1862 an LSDA pointer in the FDE augmentation.
1863 R Indicates a non-default pointer encoding for
1864 FDE code pointers.
1865 P Indicates the presence of an encoding + language
1866 personality routine in the CIE augmentation. */
1868 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1869 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1870 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1872 p = augmentation + 1;
1873 if (eh_personality_libfunc)
1875 *p++ = 'P';
1876 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1878 if (any_lsda_needed)
1880 *p++ = 'L';
1881 augmentation_size += 1;
1883 if (fde_encoding != DW_EH_PE_absptr)
1885 *p++ = 'R';
1886 augmentation_size += 1;
1888 if (p > augmentation + 1)
1890 augmentation[0] = 'z';
1891 *p = '\0';
1894 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1895 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1897 int offset = ( 4 /* Length */
1898 + 4 /* CIE Id */
1899 + 1 /* CIE version */
1900 + strlen (augmentation) + 1 /* Augmentation */
1901 + size_of_uleb128 (1) /* Code alignment */
1902 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1903 + 1 /* RA column */
1904 + 1 /* Augmentation size */
1905 + 1 /* Personality encoding */ );
1906 int pad = -offset & (PTR_SIZE - 1);
1908 augmentation_size += pad;
1910 /* Augmentations should be small, so there's scarce need to
1911 iterate for a solution. Die if we exceed one uleb128 byte. */
1912 if (size_of_uleb128 (augmentation_size) != 1)
1913 abort ();
1917 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1918 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1919 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1920 "CIE Data Alignment Factor");
1921 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1923 if (augmentation[0])
1925 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1926 if (eh_personality_libfunc)
1928 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1929 eh_data_format_name (per_encoding));
1930 dw2_asm_output_encoded_addr_rtx (per_encoding,
1931 eh_personality_libfunc, NULL);
1934 if (any_lsda_needed)
1935 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1936 eh_data_format_name (lsda_encoding));
1938 if (fde_encoding != DW_EH_PE_absptr)
1939 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1940 eh_data_format_name (fde_encoding));
1943 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1944 output_cfi (cfi, NULL, for_eh);
1946 /* Pad the CIE out to an address sized boundary. */
1947 ASM_OUTPUT_ALIGN (asm_out_file,
1948 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1949 ASM_OUTPUT_LABEL (asm_out_file, l2);
1951 /* Loop through all of the FDE's. */
1952 for (i = 0; i < fde_table_in_use; i++)
1954 fde = &fde_table[i];
1956 /* Don't emit EH unwind info for leaf functions that don't need it. */
1957 if (!flag_asynchronous_unwind_tables && for_eh && fde->nothrow
1958 && ! fde->uses_eh_lsda)
1959 continue;
1961 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1962 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1963 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1964 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1965 "FDE Length");
1966 ASM_OUTPUT_LABEL (asm_out_file, l1);
1968 if (for_eh)
1969 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
1970 else
1971 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
1972 "FDE CIE offset");
1974 if (for_eh)
1976 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1977 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1978 "FDE initial location");
1979 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1980 fde->dw_fde_end, fde->dw_fde_begin,
1981 "FDE address range");
1983 else
1985 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1986 "FDE initial location");
1987 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
1988 fde->dw_fde_end, fde->dw_fde_begin,
1989 "FDE address range");
1992 if (augmentation[0])
1994 if (any_lsda_needed)
1996 int size = size_of_encoded_value (lsda_encoding);
1998 if (lsda_encoding == DW_EH_PE_aligned)
2000 int offset = ( 4 /* Length */
2001 + 4 /* CIE offset */
2002 + 2 * size_of_encoded_value (fde_encoding)
2003 + 1 /* Augmentation size */ );
2004 int pad = -offset & (PTR_SIZE - 1);
2006 size += pad;
2007 if (size_of_uleb128 (size) != 1)
2008 abort ();
2011 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2013 if (fde->uses_eh_lsda)
2015 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2016 fde->funcdef_number);
2017 dw2_asm_output_encoded_addr_rtx (
2018 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2019 "Language Specific Data Area");
2021 else
2023 if (lsda_encoding == DW_EH_PE_aligned)
2024 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2025 dw2_asm_output_data
2026 (size_of_encoded_value (lsda_encoding), 0,
2027 "Language Specific Data Area (none)");
2030 else
2031 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2034 /* Loop through the Call Frame Instructions associated with
2035 this FDE. */
2036 fde->dw_fde_current_label = fde->dw_fde_begin;
2037 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2038 output_cfi (cfi, fde, for_eh);
2040 /* Pad the FDE out to an address sized boundary. */
2041 ASM_OUTPUT_ALIGN (asm_out_file,
2042 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2043 ASM_OUTPUT_LABEL (asm_out_file, l2);
2046 #ifndef EH_FRAME_SECTION_NAME
2047 if (for_eh)
2048 dw2_asm_output_data (4, 0, "End of Table");
2049 #endif
2050 #ifdef MIPS_DEBUGGING_INFO
2051 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2052 get a value of 0. Putting .align 0 after the label fixes it. */
2053 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2054 #endif
2056 /* Turn off app to make assembly quicker. */
2057 if (flag_debug_asm)
2058 app_disable ();
2061 /* Output a marker (i.e. a label) for the beginning of a function, before
2062 the prologue. */
2064 void
2065 dwarf2out_begin_prologue (line, file)
2066 unsigned int line ATTRIBUTE_UNUSED;
2067 const char *file ATTRIBUTE_UNUSED;
2069 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2070 dw_fde_ref fde;
2072 current_function_func_begin_label = 0;
2074 #ifdef IA64_UNWIND_INFO
2075 /* ??? current_function_func_begin_label is also used by except.c
2076 for call-site information. We must emit this label if it might
2077 be used. */
2078 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2079 && ! dwarf2out_do_frame ())
2080 return;
2081 #else
2082 if (! dwarf2out_do_frame ())
2083 return;
2084 #endif
2086 function_section (current_function_decl);
2087 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2088 current_function_funcdef_no);
2089 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2090 current_function_funcdef_no);
2091 current_function_func_begin_label = get_identifier (label);
2093 #ifdef IA64_UNWIND_INFO
2094 /* We can elide the fde allocation if we're not emitting debug info. */
2095 if (! dwarf2out_do_frame ())
2096 return;
2097 #endif
2099 /* Expand the fde table if necessary. */
2100 if (fde_table_in_use == fde_table_allocated)
2102 fde_table_allocated += FDE_TABLE_INCREMENT;
2103 fde_table
2104 = (dw_fde_ref) xrealloc (fde_table,
2105 fde_table_allocated * sizeof (dw_fde_node));
2108 /* Record the FDE associated with this function. */
2109 current_funcdef_fde = fde_table_in_use;
2111 /* Add the new FDE at the end of the fde_table. */
2112 fde = &fde_table[fde_table_in_use++];
2113 fde->dw_fde_begin = xstrdup (label);
2114 fde->dw_fde_current_label = NULL;
2115 fde->dw_fde_end = NULL;
2116 fde->dw_fde_cfi = NULL;
2117 fde->funcdef_number = current_function_funcdef_no;
2118 fde->nothrow = current_function_nothrow;
2119 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2121 args_size = old_args_size = 0;
2123 /* We only want to output line number information for the genuine dwarf2
2124 prologue case, not the eh frame case. */
2125 #ifdef DWARF2_DEBUGGING_INFO
2126 if (file)
2127 dwarf2out_source_line (line, file);
2128 #endif
2131 /* Output a marker (i.e. a label) for the absolute end of the generated code
2132 for a function definition. This gets called *after* the epilogue code has
2133 been generated. */
2135 void
2136 dwarf2out_end_epilogue ()
2138 dw_fde_ref fde;
2139 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2141 /* Output a label to mark the endpoint of the code generated for this
2142 function. */
2143 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2144 current_function_funcdef_no);
2145 ASM_OUTPUT_LABEL (asm_out_file, label);
2146 fde = &fde_table[fde_table_in_use - 1];
2147 fde->dw_fde_end = xstrdup (label);
2150 void
2151 dwarf2out_frame_init ()
2153 /* Allocate the initial hunk of the fde_table. */
2154 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2155 fde_table_allocated = FDE_TABLE_INCREMENT;
2156 fde_table_in_use = 0;
2158 /* Generate the CFA instructions common to all FDE's. Do it now for the
2159 sake of lookup_cfa. */
2161 #ifdef DWARF2_UNWIND_INFO
2162 /* On entry, the Canonical Frame Address is at SP. */
2163 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2164 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2165 #endif
2168 void
2169 dwarf2out_frame_finish ()
2171 /* Output call frame information. */
2172 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2173 output_call_frame_info (0);
2175 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2176 output_call_frame_info (1);
2179 /* And now, the subset of the debugging information support code necessary
2180 for emitting location expressions. */
2182 typedef struct dw_val_struct *dw_val_ref;
2183 typedef struct die_struct *dw_die_ref;
2184 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2185 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2187 /* Each DIE may have a series of attribute/value pairs. Values
2188 can take on several forms. The forms that are used in this
2189 implementation are listed below. */
2191 typedef enum
2193 dw_val_class_addr,
2194 dw_val_class_offset,
2195 dw_val_class_loc,
2196 dw_val_class_loc_list,
2197 dw_val_class_range_list,
2198 dw_val_class_const,
2199 dw_val_class_unsigned_const,
2200 dw_val_class_long_long,
2201 dw_val_class_float,
2202 dw_val_class_flag,
2203 dw_val_class_die_ref,
2204 dw_val_class_fde_ref,
2205 dw_val_class_lbl_id,
2206 dw_val_class_lbl_offset,
2207 dw_val_class_str
2209 dw_val_class;
2211 /* Describe a double word constant value. */
2212 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2214 typedef struct dw_long_long_struct
2216 unsigned long hi;
2217 unsigned long low;
2219 dw_long_long_const;
2221 /* Describe a floating point constant value. */
2223 typedef struct dw_fp_struct
2225 long *array;
2226 unsigned length;
2228 dw_float_const;
2230 /* The dw_val_node describes an attribute's value, as it is
2231 represented internally. */
2233 typedef struct dw_val_struct
2235 dw_val_class val_class;
2236 union
2238 rtx val_addr;
2239 long unsigned val_offset;
2240 dw_loc_list_ref val_loc_list;
2241 dw_loc_descr_ref val_loc;
2242 long int val_int;
2243 long unsigned val_unsigned;
2244 dw_long_long_const val_long_long;
2245 dw_float_const val_float;
2246 struct
2248 dw_die_ref die;
2249 int external;
2250 } val_die_ref;
2251 unsigned val_fde_index;
2252 struct indirect_string_node *val_str;
2253 char *val_lbl_id;
2254 unsigned char val_flag;
2258 dw_val_node;
2260 /* Locations in memory are described using a sequence of stack machine
2261 operations. */
2263 typedef struct dw_loc_descr_struct
2265 dw_loc_descr_ref dw_loc_next;
2266 enum dwarf_location_atom dw_loc_opc;
2267 dw_val_node dw_loc_oprnd1;
2268 dw_val_node dw_loc_oprnd2;
2269 int dw_loc_addr;
2271 dw_loc_descr_node;
2273 /* Location lists are ranges + location descriptions for that range,
2274 so you can track variables that are in different places over
2275 their entire life. */
2276 typedef struct dw_loc_list_struct
2278 dw_loc_list_ref dw_loc_next;
2279 const char *begin; /* Label for begin address of range */
2280 const char *end; /* Label for end address of range */
2281 char *ll_symbol; /* Label for beginning of location list.
2282 Only on head of list */
2283 const char *section; /* Section this loclist is relative to */
2284 dw_loc_descr_ref expr;
2285 } dw_loc_list_node;
2287 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2288 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2289 unsigned long,
2290 unsigned long));
2291 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2292 dw_loc_descr_ref));
2293 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2294 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2295 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2296 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2298 /* Convert a DWARF stack opcode into its string name. */
2300 static const char *
2301 dwarf_stack_op_name (op)
2302 unsigned op;
2304 switch (op)
2306 case DW_OP_addr:
2307 return "DW_OP_addr";
2308 case DW_OP_deref:
2309 return "DW_OP_deref";
2310 case DW_OP_const1u:
2311 return "DW_OP_const1u";
2312 case DW_OP_const1s:
2313 return "DW_OP_const1s";
2314 case DW_OP_const2u:
2315 return "DW_OP_const2u";
2316 case DW_OP_const2s:
2317 return "DW_OP_const2s";
2318 case DW_OP_const4u:
2319 return "DW_OP_const4u";
2320 case DW_OP_const4s:
2321 return "DW_OP_const4s";
2322 case DW_OP_const8u:
2323 return "DW_OP_const8u";
2324 case DW_OP_const8s:
2325 return "DW_OP_const8s";
2326 case DW_OP_constu:
2327 return "DW_OP_constu";
2328 case DW_OP_consts:
2329 return "DW_OP_consts";
2330 case DW_OP_dup:
2331 return "DW_OP_dup";
2332 case DW_OP_drop:
2333 return "DW_OP_drop";
2334 case DW_OP_over:
2335 return "DW_OP_over";
2336 case DW_OP_pick:
2337 return "DW_OP_pick";
2338 case DW_OP_swap:
2339 return "DW_OP_swap";
2340 case DW_OP_rot:
2341 return "DW_OP_rot";
2342 case DW_OP_xderef:
2343 return "DW_OP_xderef";
2344 case DW_OP_abs:
2345 return "DW_OP_abs";
2346 case DW_OP_and:
2347 return "DW_OP_and";
2348 case DW_OP_div:
2349 return "DW_OP_div";
2350 case DW_OP_minus:
2351 return "DW_OP_minus";
2352 case DW_OP_mod:
2353 return "DW_OP_mod";
2354 case DW_OP_mul:
2355 return "DW_OP_mul";
2356 case DW_OP_neg:
2357 return "DW_OP_neg";
2358 case DW_OP_not:
2359 return "DW_OP_not";
2360 case DW_OP_or:
2361 return "DW_OP_or";
2362 case DW_OP_plus:
2363 return "DW_OP_plus";
2364 case DW_OP_plus_uconst:
2365 return "DW_OP_plus_uconst";
2366 case DW_OP_shl:
2367 return "DW_OP_shl";
2368 case DW_OP_shr:
2369 return "DW_OP_shr";
2370 case DW_OP_shra:
2371 return "DW_OP_shra";
2372 case DW_OP_xor:
2373 return "DW_OP_xor";
2374 case DW_OP_bra:
2375 return "DW_OP_bra";
2376 case DW_OP_eq:
2377 return "DW_OP_eq";
2378 case DW_OP_ge:
2379 return "DW_OP_ge";
2380 case DW_OP_gt:
2381 return "DW_OP_gt";
2382 case DW_OP_le:
2383 return "DW_OP_le";
2384 case DW_OP_lt:
2385 return "DW_OP_lt";
2386 case DW_OP_ne:
2387 return "DW_OP_ne";
2388 case DW_OP_skip:
2389 return "DW_OP_skip";
2390 case DW_OP_lit0:
2391 return "DW_OP_lit0";
2392 case DW_OP_lit1:
2393 return "DW_OP_lit1";
2394 case DW_OP_lit2:
2395 return "DW_OP_lit2";
2396 case DW_OP_lit3:
2397 return "DW_OP_lit3";
2398 case DW_OP_lit4:
2399 return "DW_OP_lit4";
2400 case DW_OP_lit5:
2401 return "DW_OP_lit5";
2402 case DW_OP_lit6:
2403 return "DW_OP_lit6";
2404 case DW_OP_lit7:
2405 return "DW_OP_lit7";
2406 case DW_OP_lit8:
2407 return "DW_OP_lit8";
2408 case DW_OP_lit9:
2409 return "DW_OP_lit9";
2410 case DW_OP_lit10:
2411 return "DW_OP_lit10";
2412 case DW_OP_lit11:
2413 return "DW_OP_lit11";
2414 case DW_OP_lit12:
2415 return "DW_OP_lit12";
2416 case DW_OP_lit13:
2417 return "DW_OP_lit13";
2418 case DW_OP_lit14:
2419 return "DW_OP_lit14";
2420 case DW_OP_lit15:
2421 return "DW_OP_lit15";
2422 case DW_OP_lit16:
2423 return "DW_OP_lit16";
2424 case DW_OP_lit17:
2425 return "DW_OP_lit17";
2426 case DW_OP_lit18:
2427 return "DW_OP_lit18";
2428 case DW_OP_lit19:
2429 return "DW_OP_lit19";
2430 case DW_OP_lit20:
2431 return "DW_OP_lit20";
2432 case DW_OP_lit21:
2433 return "DW_OP_lit21";
2434 case DW_OP_lit22:
2435 return "DW_OP_lit22";
2436 case DW_OP_lit23:
2437 return "DW_OP_lit23";
2438 case DW_OP_lit24:
2439 return "DW_OP_lit24";
2440 case DW_OP_lit25:
2441 return "DW_OP_lit25";
2442 case DW_OP_lit26:
2443 return "DW_OP_lit26";
2444 case DW_OP_lit27:
2445 return "DW_OP_lit27";
2446 case DW_OP_lit28:
2447 return "DW_OP_lit28";
2448 case DW_OP_lit29:
2449 return "DW_OP_lit29";
2450 case DW_OP_lit30:
2451 return "DW_OP_lit30";
2452 case DW_OP_lit31:
2453 return "DW_OP_lit31";
2454 case DW_OP_reg0:
2455 return "DW_OP_reg0";
2456 case DW_OP_reg1:
2457 return "DW_OP_reg1";
2458 case DW_OP_reg2:
2459 return "DW_OP_reg2";
2460 case DW_OP_reg3:
2461 return "DW_OP_reg3";
2462 case DW_OP_reg4:
2463 return "DW_OP_reg4";
2464 case DW_OP_reg5:
2465 return "DW_OP_reg5";
2466 case DW_OP_reg6:
2467 return "DW_OP_reg6";
2468 case DW_OP_reg7:
2469 return "DW_OP_reg7";
2470 case DW_OP_reg8:
2471 return "DW_OP_reg8";
2472 case DW_OP_reg9:
2473 return "DW_OP_reg9";
2474 case DW_OP_reg10:
2475 return "DW_OP_reg10";
2476 case DW_OP_reg11:
2477 return "DW_OP_reg11";
2478 case DW_OP_reg12:
2479 return "DW_OP_reg12";
2480 case DW_OP_reg13:
2481 return "DW_OP_reg13";
2482 case DW_OP_reg14:
2483 return "DW_OP_reg14";
2484 case DW_OP_reg15:
2485 return "DW_OP_reg15";
2486 case DW_OP_reg16:
2487 return "DW_OP_reg16";
2488 case DW_OP_reg17:
2489 return "DW_OP_reg17";
2490 case DW_OP_reg18:
2491 return "DW_OP_reg18";
2492 case DW_OP_reg19:
2493 return "DW_OP_reg19";
2494 case DW_OP_reg20:
2495 return "DW_OP_reg20";
2496 case DW_OP_reg21:
2497 return "DW_OP_reg21";
2498 case DW_OP_reg22:
2499 return "DW_OP_reg22";
2500 case DW_OP_reg23:
2501 return "DW_OP_reg23";
2502 case DW_OP_reg24:
2503 return "DW_OP_reg24";
2504 case DW_OP_reg25:
2505 return "DW_OP_reg25";
2506 case DW_OP_reg26:
2507 return "DW_OP_reg26";
2508 case DW_OP_reg27:
2509 return "DW_OP_reg27";
2510 case DW_OP_reg28:
2511 return "DW_OP_reg28";
2512 case DW_OP_reg29:
2513 return "DW_OP_reg29";
2514 case DW_OP_reg30:
2515 return "DW_OP_reg30";
2516 case DW_OP_reg31:
2517 return "DW_OP_reg31";
2518 case DW_OP_breg0:
2519 return "DW_OP_breg0";
2520 case DW_OP_breg1:
2521 return "DW_OP_breg1";
2522 case DW_OP_breg2:
2523 return "DW_OP_breg2";
2524 case DW_OP_breg3:
2525 return "DW_OP_breg3";
2526 case DW_OP_breg4:
2527 return "DW_OP_breg4";
2528 case DW_OP_breg5:
2529 return "DW_OP_breg5";
2530 case DW_OP_breg6:
2531 return "DW_OP_breg6";
2532 case DW_OP_breg7:
2533 return "DW_OP_breg7";
2534 case DW_OP_breg8:
2535 return "DW_OP_breg8";
2536 case DW_OP_breg9:
2537 return "DW_OP_breg9";
2538 case DW_OP_breg10:
2539 return "DW_OP_breg10";
2540 case DW_OP_breg11:
2541 return "DW_OP_breg11";
2542 case DW_OP_breg12:
2543 return "DW_OP_breg12";
2544 case DW_OP_breg13:
2545 return "DW_OP_breg13";
2546 case DW_OP_breg14:
2547 return "DW_OP_breg14";
2548 case DW_OP_breg15:
2549 return "DW_OP_breg15";
2550 case DW_OP_breg16:
2551 return "DW_OP_breg16";
2552 case DW_OP_breg17:
2553 return "DW_OP_breg17";
2554 case DW_OP_breg18:
2555 return "DW_OP_breg18";
2556 case DW_OP_breg19:
2557 return "DW_OP_breg19";
2558 case DW_OP_breg20:
2559 return "DW_OP_breg20";
2560 case DW_OP_breg21:
2561 return "DW_OP_breg21";
2562 case DW_OP_breg22:
2563 return "DW_OP_breg22";
2564 case DW_OP_breg23:
2565 return "DW_OP_breg23";
2566 case DW_OP_breg24:
2567 return "DW_OP_breg24";
2568 case DW_OP_breg25:
2569 return "DW_OP_breg25";
2570 case DW_OP_breg26:
2571 return "DW_OP_breg26";
2572 case DW_OP_breg27:
2573 return "DW_OP_breg27";
2574 case DW_OP_breg28:
2575 return "DW_OP_breg28";
2576 case DW_OP_breg29:
2577 return "DW_OP_breg29";
2578 case DW_OP_breg30:
2579 return "DW_OP_breg30";
2580 case DW_OP_breg31:
2581 return "DW_OP_breg31";
2582 case DW_OP_regx:
2583 return "DW_OP_regx";
2584 case DW_OP_fbreg:
2585 return "DW_OP_fbreg";
2586 case DW_OP_bregx:
2587 return "DW_OP_bregx";
2588 case DW_OP_piece:
2589 return "DW_OP_piece";
2590 case DW_OP_deref_size:
2591 return "DW_OP_deref_size";
2592 case DW_OP_xderef_size:
2593 return "DW_OP_xderef_size";
2594 case DW_OP_nop:
2595 return "DW_OP_nop";
2596 default:
2597 return "OP_<unknown>";
2601 /* Return a pointer to a newly allocated location description. Location
2602 descriptions are simple expression terms that can be strung
2603 together to form more complicated location (address) descriptions. */
2605 static inline dw_loc_descr_ref
2606 new_loc_descr (op, oprnd1, oprnd2)
2607 enum dwarf_location_atom op;
2608 unsigned long oprnd1;
2609 unsigned long oprnd2;
2611 /* Use xcalloc here so we clear out all of the long_long constant in
2612 the union. */
2613 dw_loc_descr_ref descr
2614 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2616 descr->dw_loc_opc = op;
2617 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2618 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2619 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2620 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2622 return descr;
2626 /* Add a location description term to a location description expression. */
2628 static inline void
2629 add_loc_descr (list_head, descr)
2630 dw_loc_descr_ref *list_head;
2631 dw_loc_descr_ref descr;
2633 dw_loc_descr_ref *d;
2635 /* Find the end of the chain. */
2636 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2639 *d = descr;
2642 /* Return the size of a location descriptor. */
2644 static unsigned long
2645 size_of_loc_descr (loc)
2646 dw_loc_descr_ref loc;
2648 unsigned long size = 1;
2650 switch (loc->dw_loc_opc)
2652 case DW_OP_addr:
2653 size += DWARF2_ADDR_SIZE;
2654 break;
2655 case DW_OP_const1u:
2656 case DW_OP_const1s:
2657 size += 1;
2658 break;
2659 case DW_OP_const2u:
2660 case DW_OP_const2s:
2661 size += 2;
2662 break;
2663 case DW_OP_const4u:
2664 case DW_OP_const4s:
2665 size += 4;
2666 break;
2667 case DW_OP_const8u:
2668 case DW_OP_const8s:
2669 size += 8;
2670 break;
2671 case DW_OP_constu:
2672 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2673 break;
2674 case DW_OP_consts:
2675 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2676 break;
2677 case DW_OP_pick:
2678 size += 1;
2679 break;
2680 case DW_OP_plus_uconst:
2681 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2682 break;
2683 case DW_OP_skip:
2684 case DW_OP_bra:
2685 size += 2;
2686 break;
2687 case DW_OP_breg0:
2688 case DW_OP_breg1:
2689 case DW_OP_breg2:
2690 case DW_OP_breg3:
2691 case DW_OP_breg4:
2692 case DW_OP_breg5:
2693 case DW_OP_breg6:
2694 case DW_OP_breg7:
2695 case DW_OP_breg8:
2696 case DW_OP_breg9:
2697 case DW_OP_breg10:
2698 case DW_OP_breg11:
2699 case DW_OP_breg12:
2700 case DW_OP_breg13:
2701 case DW_OP_breg14:
2702 case DW_OP_breg15:
2703 case DW_OP_breg16:
2704 case DW_OP_breg17:
2705 case DW_OP_breg18:
2706 case DW_OP_breg19:
2707 case DW_OP_breg20:
2708 case DW_OP_breg21:
2709 case DW_OP_breg22:
2710 case DW_OP_breg23:
2711 case DW_OP_breg24:
2712 case DW_OP_breg25:
2713 case DW_OP_breg26:
2714 case DW_OP_breg27:
2715 case DW_OP_breg28:
2716 case DW_OP_breg29:
2717 case DW_OP_breg30:
2718 case DW_OP_breg31:
2719 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2720 break;
2721 case DW_OP_regx:
2722 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2723 break;
2724 case DW_OP_fbreg:
2725 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2726 break;
2727 case DW_OP_bregx:
2728 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2729 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2730 break;
2731 case DW_OP_piece:
2732 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2733 break;
2734 case DW_OP_deref_size:
2735 case DW_OP_xderef_size:
2736 size += 1;
2737 break;
2738 default:
2739 break;
2742 return size;
2745 /* Return the size of a series of location descriptors. */
2747 static unsigned long
2748 size_of_locs (loc)
2749 dw_loc_descr_ref loc;
2751 unsigned long size;
2753 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
2755 loc->dw_loc_addr = size;
2756 size += size_of_loc_descr (loc);
2759 return size;
2762 /* Output location description stack opcode's operands (if any). */
2764 static void
2765 output_loc_operands (loc)
2766 dw_loc_descr_ref loc;
2768 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2769 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2771 switch (loc->dw_loc_opc)
2773 #ifdef DWARF2_DEBUGGING_INFO
2774 case DW_OP_addr:
2775 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2776 break;
2777 case DW_OP_const2u:
2778 case DW_OP_const2s:
2779 dw2_asm_output_data (2, val1->v.val_int, NULL);
2780 break;
2781 case DW_OP_const4u:
2782 case DW_OP_const4s:
2783 dw2_asm_output_data (4, val1->v.val_int, NULL);
2784 break;
2785 case DW_OP_const8u:
2786 case DW_OP_const8s:
2787 if (HOST_BITS_PER_LONG < 64)
2788 abort ();
2789 dw2_asm_output_data (8, val1->v.val_int, NULL);
2790 break;
2791 case DW_OP_skip:
2792 case DW_OP_bra:
2794 int offset;
2796 if (val1->val_class == dw_val_class_loc)
2797 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2798 else
2799 abort ();
2801 dw2_asm_output_data (2, offset, NULL);
2803 break;
2804 #else
2805 case DW_OP_addr:
2806 case DW_OP_const2u:
2807 case DW_OP_const2s:
2808 case DW_OP_const4u:
2809 case DW_OP_const4s:
2810 case DW_OP_const8u:
2811 case DW_OP_const8s:
2812 case DW_OP_skip:
2813 case DW_OP_bra:
2814 /* We currently don't make any attempt to make sure these are
2815 aligned properly like we do for the main unwind info, so
2816 don't support emitting things larger than a byte if we're
2817 only doing unwinding. */
2818 abort ();
2819 #endif
2820 case DW_OP_const1u:
2821 case DW_OP_const1s:
2822 dw2_asm_output_data (1, val1->v.val_int, NULL);
2823 break;
2824 case DW_OP_constu:
2825 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2826 break;
2827 case DW_OP_consts:
2828 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2829 break;
2830 case DW_OP_pick:
2831 dw2_asm_output_data (1, val1->v.val_int, NULL);
2832 break;
2833 case DW_OP_plus_uconst:
2834 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2835 break;
2836 case DW_OP_breg0:
2837 case DW_OP_breg1:
2838 case DW_OP_breg2:
2839 case DW_OP_breg3:
2840 case DW_OP_breg4:
2841 case DW_OP_breg5:
2842 case DW_OP_breg6:
2843 case DW_OP_breg7:
2844 case DW_OP_breg8:
2845 case DW_OP_breg9:
2846 case DW_OP_breg10:
2847 case DW_OP_breg11:
2848 case DW_OP_breg12:
2849 case DW_OP_breg13:
2850 case DW_OP_breg14:
2851 case DW_OP_breg15:
2852 case DW_OP_breg16:
2853 case DW_OP_breg17:
2854 case DW_OP_breg18:
2855 case DW_OP_breg19:
2856 case DW_OP_breg20:
2857 case DW_OP_breg21:
2858 case DW_OP_breg22:
2859 case DW_OP_breg23:
2860 case DW_OP_breg24:
2861 case DW_OP_breg25:
2862 case DW_OP_breg26:
2863 case DW_OP_breg27:
2864 case DW_OP_breg28:
2865 case DW_OP_breg29:
2866 case DW_OP_breg30:
2867 case DW_OP_breg31:
2868 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2869 break;
2870 case DW_OP_regx:
2871 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2872 break;
2873 case DW_OP_fbreg:
2874 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2875 break;
2876 case DW_OP_bregx:
2877 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2878 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2879 break;
2880 case DW_OP_piece:
2881 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2882 break;
2883 case DW_OP_deref_size:
2884 case DW_OP_xderef_size:
2885 dw2_asm_output_data (1, val1->v.val_int, NULL);
2886 break;
2887 default:
2888 /* Other codes have no operands. */
2889 break;
2893 /* Output a sequence of location operations. */
2895 static void
2896 output_loc_sequence (loc)
2897 dw_loc_descr_ref loc;
2899 for (; loc != NULL; loc = loc->dw_loc_next)
2901 /* Output the opcode. */
2902 dw2_asm_output_data (1, loc->dw_loc_opc,
2903 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2905 /* Output the operand(s) (if any). */
2906 output_loc_operands (loc);
2910 /* This routine will generate the correct assembly data for a location
2911 description based on a cfi entry with a complex address. */
2913 static void
2914 output_cfa_loc (cfi)
2915 dw_cfi_ref cfi;
2917 dw_loc_descr_ref loc;
2918 unsigned long size;
2920 /* Output the size of the block. */
2921 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2922 size = size_of_locs (loc);
2923 dw2_asm_output_data_uleb128 (size, NULL);
2925 /* Now output the operations themselves. */
2926 output_loc_sequence (loc);
2929 /* This function builds a dwarf location descriptor sequence from
2930 a dw_cfa_location. */
2932 static struct dw_loc_descr_struct *
2933 build_cfa_loc (cfa)
2934 dw_cfa_location *cfa;
2936 struct dw_loc_descr_struct *head, *tmp;
2938 if (cfa->indirect == 0)
2939 abort ();
2941 if (cfa->base_offset)
2943 if (cfa->reg <= 31)
2944 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2945 else
2946 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2948 else if (cfa->reg <= 31)
2949 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2950 else
2951 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2953 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2954 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2955 add_loc_descr (&head, tmp);
2956 if (cfa->offset != 0)
2958 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2959 add_loc_descr (&head, tmp);
2962 return head;
2965 /* This function fills in aa dw_cfa_location structure from a dwarf location
2966 descriptor sequence. */
2968 static void
2969 get_cfa_from_loc_descr (cfa, loc)
2970 dw_cfa_location *cfa;
2971 struct dw_loc_descr_struct *loc;
2973 struct dw_loc_descr_struct *ptr;
2974 cfa->offset = 0;
2975 cfa->base_offset = 0;
2976 cfa->indirect = 0;
2977 cfa->reg = -1;
2979 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2981 enum dwarf_location_atom op = ptr->dw_loc_opc;
2983 switch (op)
2985 case DW_OP_reg0:
2986 case DW_OP_reg1:
2987 case DW_OP_reg2:
2988 case DW_OP_reg3:
2989 case DW_OP_reg4:
2990 case DW_OP_reg5:
2991 case DW_OP_reg6:
2992 case DW_OP_reg7:
2993 case DW_OP_reg8:
2994 case DW_OP_reg9:
2995 case DW_OP_reg10:
2996 case DW_OP_reg11:
2997 case DW_OP_reg12:
2998 case DW_OP_reg13:
2999 case DW_OP_reg14:
3000 case DW_OP_reg15:
3001 case DW_OP_reg16:
3002 case DW_OP_reg17:
3003 case DW_OP_reg18:
3004 case DW_OP_reg19:
3005 case DW_OP_reg20:
3006 case DW_OP_reg21:
3007 case DW_OP_reg22:
3008 case DW_OP_reg23:
3009 case DW_OP_reg24:
3010 case DW_OP_reg25:
3011 case DW_OP_reg26:
3012 case DW_OP_reg27:
3013 case DW_OP_reg28:
3014 case DW_OP_reg29:
3015 case DW_OP_reg30:
3016 case DW_OP_reg31:
3017 cfa->reg = op - DW_OP_reg0;
3018 break;
3019 case DW_OP_regx:
3020 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3021 break;
3022 case DW_OP_breg0:
3023 case DW_OP_breg1:
3024 case DW_OP_breg2:
3025 case DW_OP_breg3:
3026 case DW_OP_breg4:
3027 case DW_OP_breg5:
3028 case DW_OP_breg6:
3029 case DW_OP_breg7:
3030 case DW_OP_breg8:
3031 case DW_OP_breg9:
3032 case DW_OP_breg10:
3033 case DW_OP_breg11:
3034 case DW_OP_breg12:
3035 case DW_OP_breg13:
3036 case DW_OP_breg14:
3037 case DW_OP_breg15:
3038 case DW_OP_breg16:
3039 case DW_OP_breg17:
3040 case DW_OP_breg18:
3041 case DW_OP_breg19:
3042 case DW_OP_breg20:
3043 case DW_OP_breg21:
3044 case DW_OP_breg22:
3045 case DW_OP_breg23:
3046 case DW_OP_breg24:
3047 case DW_OP_breg25:
3048 case DW_OP_breg26:
3049 case DW_OP_breg27:
3050 case DW_OP_breg28:
3051 case DW_OP_breg29:
3052 case DW_OP_breg30:
3053 case DW_OP_breg31:
3054 cfa->reg = op - DW_OP_breg0;
3055 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3056 break;
3057 case DW_OP_bregx:
3058 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3059 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3060 break;
3061 case DW_OP_deref:
3062 cfa->indirect = 1;
3063 break;
3064 case DW_OP_plus_uconst:
3065 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3066 break;
3067 default:
3068 internal_error ("DW_LOC_OP %s not implemented\n",
3069 dwarf_stack_op_name (ptr->dw_loc_opc));
3073 #endif /* .debug_frame support */
3075 /* And now, the support for symbolic debugging information. */
3076 #ifdef DWARF2_DEBUGGING_INFO
3078 /* .debug_str support. */
3079 static hashnode indirect_string_alloc PARAMS ((hash_table *));
3080 static int output_indirect_string PARAMS ((struct cpp_reader *,
3081 hashnode, const PTR));
3084 static void dwarf2out_init PARAMS ((const char *));
3085 static void dwarf2out_finish PARAMS ((const char *));
3086 static void dwarf2out_define PARAMS ((unsigned int, const char *));
3087 static void dwarf2out_undef PARAMS ((unsigned int, const char *));
3088 static void dwarf2out_start_source_file PARAMS ((unsigned, const char *));
3089 static void dwarf2out_end_source_file PARAMS ((unsigned));
3090 static void dwarf2out_begin_block PARAMS ((unsigned, unsigned));
3091 static void dwarf2out_end_block PARAMS ((unsigned, unsigned));
3092 static bool dwarf2out_ignore_block PARAMS ((tree));
3093 static void dwarf2out_global_decl PARAMS ((tree));
3094 static void dwarf2out_abstract_function PARAMS ((tree));
3096 /* The debug hooks structure. */
3098 const struct gcc_debug_hooks dwarf2_debug_hooks =
3100 dwarf2out_init,
3101 dwarf2out_finish,
3102 dwarf2out_define,
3103 dwarf2out_undef,
3104 dwarf2out_start_source_file,
3105 dwarf2out_end_source_file,
3106 dwarf2out_begin_block,
3107 dwarf2out_end_block,
3108 dwarf2out_ignore_block,
3109 dwarf2out_source_line,
3110 dwarf2out_begin_prologue,
3111 debug_nothing_int, /* end_prologue */
3112 dwarf2out_end_epilogue,
3113 debug_nothing_tree, /* begin_function */
3114 debug_nothing_int, /* end_function */
3115 dwarf2out_decl, /* function_decl */
3116 dwarf2out_global_decl,
3117 debug_nothing_tree, /* deferred_inline_function */
3118 /* The DWARF 2 backend tries to reduce debugging bloat by not
3119 emitting the abstract description of inline functions until
3120 something tries to reference them. */
3121 dwarf2out_abstract_function, /* outlining_inline_function */
3122 debug_nothing_rtx /* label */
3125 /* NOTE: In the comments in this file, many references are made to
3126 "Debugging Information Entries". This term is abbreviated as `DIE'
3127 throughout the remainder of this file. */
3129 /* An internal representation of the DWARF output is built, and then
3130 walked to generate the DWARF debugging info. The walk of the internal
3131 representation is done after the entire program has been compiled.
3132 The types below are used to describe the internal representation. */
3134 /* Various DIE's use offsets relative to the beginning of the
3135 .debug_info section to refer to each other. */
3137 typedef long int dw_offset;
3139 /* Define typedefs here to avoid circular dependencies. */
3141 typedef struct dw_attr_struct *dw_attr_ref;
3142 typedef struct dw_line_info_struct *dw_line_info_ref;
3143 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3144 typedef struct pubname_struct *pubname_ref;
3145 typedef struct dw_ranges_struct *dw_ranges_ref;
3147 /* Each entry in the line_info_table maintains the file and
3148 line number associated with the label generated for that
3149 entry. The label gives the PC value associated with
3150 the line number entry. */
3152 typedef struct dw_line_info_struct
3154 unsigned long dw_file_num;
3155 unsigned long dw_line_num;
3157 dw_line_info_entry;
3159 /* Line information for functions in separate sections; each one gets its
3160 own sequence. */
3161 typedef struct dw_separate_line_info_struct
3163 unsigned long dw_file_num;
3164 unsigned long dw_line_num;
3165 unsigned long function;
3167 dw_separate_line_info_entry;
3169 /* Each DIE attribute has a field specifying the attribute kind,
3170 a link to the next attribute in the chain, and an attribute value.
3171 Attributes are typically linked below the DIE they modify. */
3173 typedef struct dw_attr_struct
3175 enum dwarf_attribute dw_attr;
3176 dw_attr_ref dw_attr_next;
3177 dw_val_node dw_attr_val;
3179 dw_attr_node;
3181 /* The Debugging Information Entry (DIE) structure */
3183 typedef struct die_struct
3185 enum dwarf_tag die_tag;
3186 char *die_symbol;
3187 dw_attr_ref die_attr;
3188 dw_die_ref die_parent;
3189 dw_die_ref die_child;
3190 dw_die_ref die_sib;
3191 dw_offset die_offset;
3192 unsigned long die_abbrev;
3193 int die_mark;
3195 die_node;
3197 /* The pubname structure */
3199 typedef struct pubname_struct
3201 dw_die_ref die;
3202 char *name;
3204 pubname_entry;
3206 struct dw_ranges_struct
3208 int block_num;
3211 /* The limbo die list structure. */
3212 typedef struct limbo_die_struct
3214 dw_die_ref die;
3215 tree created_for;
3216 struct limbo_die_struct *next;
3218 limbo_die_node;
3220 /* How to start an assembler comment. */
3221 #ifndef ASM_COMMENT_START
3222 #define ASM_COMMENT_START ";#"
3223 #endif
3225 /* Define a macro which returns non-zero for a TYPE_DECL which was
3226 implicitly generated for a tagged type.
3228 Note that unlike the gcc front end (which generates a NULL named
3229 TYPE_DECL node for each complete tagged type, each array type, and
3230 each function type node created) the g++ front end generates a
3231 _named_ TYPE_DECL node for each tagged type node created.
3232 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3233 generate a DW_TAG_typedef DIE for them. */
3235 #define TYPE_DECL_IS_STUB(decl) \
3236 (DECL_NAME (decl) == NULL_TREE \
3237 || (DECL_ARTIFICIAL (decl) \
3238 && is_tagged_type (TREE_TYPE (decl)) \
3239 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3240 /* This is necessary for stub decls that \
3241 appear in nested inline functions. */ \
3242 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3243 && (decl_ultimate_origin (decl) \
3244 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3246 /* Information concerning the compilation unit's programming
3247 language, and compiler version. */
3249 /* Fixed size portion of the DWARF compilation unit header. */
3250 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3252 /* Fixed size portion of debugging line information prolog. */
3253 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3255 /* Fixed size portion of public names info. */
3256 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3258 /* Fixed size portion of the address range info. */
3259 #define DWARF_ARANGES_HEADER_SIZE \
3260 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3261 - DWARF_OFFSET_SIZE)
3263 /* Size of padding portion in the address range info. It must be
3264 aligned to twice the pointer size. */
3265 #define DWARF_ARANGES_PAD_SIZE \
3266 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3267 - (2 * DWARF_OFFSET_SIZE + 4))
3269 /* Use assembler line directives if available. */
3270 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3271 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3272 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3273 #else
3274 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3275 #endif
3276 #endif
3278 /* Minimum line offset in a special line info. opcode.
3279 This value was chosen to give a reasonable range of values. */
3280 #define DWARF_LINE_BASE -10
3282 /* First special line opcode - leave room for the standard opcodes. */
3283 #define DWARF_LINE_OPCODE_BASE 10
3285 /* Range of line offsets in a special line info. opcode. */
3286 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3288 /* Flag that indicates the initial value of the is_stmt_start flag.
3289 In the present implementation, we do not mark any lines as
3290 the beginning of a source statement, because that information
3291 is not made available by the GCC front-end. */
3292 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3294 /* This location is used by calc_die_sizes() to keep track
3295 the offset of each DIE within the .debug_info section. */
3296 static unsigned long next_die_offset;
3298 /* Record the root of the DIE's built for the current compilation unit. */
3299 static dw_die_ref comp_unit_die;
3301 /* A list of DIEs with a NULL parent waiting to be relocated. */
3302 static limbo_die_node *limbo_die_list = 0;
3304 /* Structure used by lookup_filename to manage sets of filenames. */
3305 struct file_table
3307 char **table;
3308 unsigned allocated;
3309 unsigned in_use;
3310 unsigned last_lookup_index;
3313 /* Size (in elements) of increments by which we may expand the filename
3314 table. */
3315 #define FILE_TABLE_INCREMENT 64
3317 /* Filenames referenced by this compilation unit. */
3318 static struct file_table file_table;
3320 /* Local pointer to the name of the main input file. Initialized in
3321 dwarf2out_init. */
3322 static const char *primary_filename;
3324 /* A pointer to the base of a table of references to DIE's that describe
3325 declarations. The table is indexed by DECL_UID() which is a unique
3326 number identifying each decl. */
3327 static dw_die_ref *decl_die_table;
3329 /* Number of elements currently allocated for the decl_die_table. */
3330 static unsigned decl_die_table_allocated;
3332 /* Number of elements in decl_die_table currently in use. */
3333 static unsigned decl_die_table_in_use;
3335 /* Size (in elements) of increments by which we may expand the
3336 decl_die_table. */
3337 #define DECL_DIE_TABLE_INCREMENT 256
3339 /* A pointer to the base of a list of references to DIE's that
3340 are uniquely identified by their tag, presence/absence of
3341 children DIE's, and list of attribute/value pairs. */
3342 static dw_die_ref *abbrev_die_table;
3344 /* Number of elements currently allocated for abbrev_die_table. */
3345 static unsigned abbrev_die_table_allocated;
3347 /* Number of elements in type_die_table currently in use. */
3348 static unsigned abbrev_die_table_in_use;
3350 /* Size (in elements) of increments by which we may expand the
3351 abbrev_die_table. */
3352 #define ABBREV_DIE_TABLE_INCREMENT 256
3354 /* A pointer to the base of a table that contains line information
3355 for each source code line in .text in the compilation unit. */
3356 static dw_line_info_ref line_info_table;
3358 /* Number of elements currently allocated for line_info_table. */
3359 static unsigned line_info_table_allocated;
3361 /* Number of elements in separate_line_info_table currently in use. */
3362 static unsigned separate_line_info_table_in_use;
3364 /* A pointer to the base of a table that contains line information
3365 for each source code line outside of .text in the compilation unit. */
3366 static dw_separate_line_info_ref separate_line_info_table;
3368 /* Number of elements currently allocated for separate_line_info_table. */
3369 static unsigned separate_line_info_table_allocated;
3371 /* Number of elements in line_info_table currently in use. */
3372 static unsigned line_info_table_in_use;
3374 /* Size (in elements) of increments by which we may expand the
3375 line_info_table. */
3376 #define LINE_INFO_TABLE_INCREMENT 1024
3378 /* A pointer to the base of a table that contains a list of publicly
3379 accessible names. */
3380 static pubname_ref pubname_table;
3382 /* Number of elements currently allocated for pubname_table. */
3383 static unsigned pubname_table_allocated;
3385 /* Number of elements in pubname_table currently in use. */
3386 static unsigned pubname_table_in_use;
3388 /* Size (in elements) of increments by which we may expand the
3389 pubname_table. */
3390 #define PUBNAME_TABLE_INCREMENT 64
3392 /* Array of dies for which we should generate .debug_arange info. */
3393 static dw_die_ref *arange_table;
3395 /* Number of elements currently allocated for arange_table. */
3396 static unsigned arange_table_allocated;
3398 /* Number of elements in arange_table currently in use. */
3399 static unsigned arange_table_in_use;
3401 /* Size (in elements) of increments by which we may expand the
3402 arange_table. */
3403 #define ARANGE_TABLE_INCREMENT 64
3405 /* Array of dies for which we should generate .debug_ranges info. */
3406 static dw_ranges_ref ranges_table;
3408 /* Number of elements currently allocated for ranges_table. */
3409 static unsigned ranges_table_allocated;
3411 /* Number of elements in ranges_table currently in use. */
3412 static unsigned ranges_table_in_use;
3414 /* Size (in elements) of increments by which we may expand the
3415 ranges_table. */
3416 #define RANGES_TABLE_INCREMENT 64
3418 /* Whether we have location lists that need outputting */
3419 static unsigned have_location_lists;
3421 /* Record whether the function being analyzed contains inlined functions. */
3422 static int current_function_has_inlines;
3423 #if 0 && defined (MIPS_DEBUGGING_INFO)
3424 static int comp_unit_has_inlines;
3425 #endif
3427 /* Forward declarations for functions defined in this file. */
3429 static int is_pseudo_reg PARAMS ((rtx));
3430 static tree type_main_variant PARAMS ((tree));
3431 static int is_tagged_type PARAMS ((tree));
3432 static const char *dwarf_tag_name PARAMS ((unsigned));
3433 static const char *dwarf_attr_name PARAMS ((unsigned));
3434 static const char *dwarf_form_name PARAMS ((unsigned));
3435 #if 0
3436 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3437 #endif
3438 static tree decl_ultimate_origin PARAMS ((tree));
3439 static tree block_ultimate_origin PARAMS ((tree));
3440 static tree decl_class_context PARAMS ((tree));
3441 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3442 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
3443 static void add_AT_flag PARAMS ((dw_die_ref,
3444 enum dwarf_attribute,
3445 unsigned));
3446 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
3447 static void add_AT_int PARAMS ((dw_die_ref,
3448 enum dwarf_attribute, long));
3449 static inline long int AT_int PARAMS ((dw_attr_ref));
3450 static void add_AT_unsigned PARAMS ((dw_die_ref,
3451 enum dwarf_attribute,
3452 unsigned long));
3453 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
3454 static void add_AT_long_long PARAMS ((dw_die_ref,
3455 enum dwarf_attribute,
3456 unsigned long,
3457 unsigned long));
3458 static void add_AT_float PARAMS ((dw_die_ref,
3459 enum dwarf_attribute,
3460 unsigned, long *));
3461 static void add_AT_string PARAMS ((dw_die_ref,
3462 enum dwarf_attribute,
3463 const char *));
3464 static inline const char *AT_string PARAMS ((dw_attr_ref));
3465 static int AT_string_form PARAMS ((dw_attr_ref));
3466 static void add_AT_die_ref PARAMS ((dw_die_ref,
3467 enum dwarf_attribute,
3468 dw_die_ref));
3469 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
3470 static inline int AT_ref_external PARAMS ((dw_attr_ref));
3471 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
3472 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3473 enum dwarf_attribute,
3474 unsigned));
3475 static void add_AT_loc PARAMS ((dw_die_ref,
3476 enum dwarf_attribute,
3477 dw_loc_descr_ref));
3478 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
3479 static void add_AT_loc_list PARAMS ((dw_die_ref,
3480 enum dwarf_attribute,
3481 dw_loc_list_ref));
3482 static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
3483 static void add_AT_addr PARAMS ((dw_die_ref,
3484 enum dwarf_attribute,
3485 rtx));
3486 static inline rtx AT_addr PARAMS ((dw_attr_ref));
3487 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3488 enum dwarf_attribute,
3489 const char *));
3490 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3491 enum dwarf_attribute,
3492 const char *));
3493 static void add_AT_offset PARAMS ((dw_die_ref,
3494 enum dwarf_attribute,
3495 unsigned long));
3496 static void add_AT_range_list PARAMS ((dw_die_ref,
3497 enum dwarf_attribute,
3498 unsigned long));
3499 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
3500 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3501 enum dwarf_attribute));
3502 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3503 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3504 static const char *get_AT_string PARAMS ((dw_die_ref,
3505 enum dwarf_attribute));
3506 static int get_AT_flag PARAMS ((dw_die_ref,
3507 enum dwarf_attribute));
3508 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3509 enum dwarf_attribute));
3510 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3511 enum dwarf_attribute));
3512 static int is_c_family PARAMS ((void));
3513 static int is_cxx PARAMS ((void));
3514 static int is_java PARAMS ((void));
3515 static int is_fortran PARAMS ((void));
3516 static void remove_AT PARAMS ((dw_die_ref,
3517 enum dwarf_attribute));
3518 static inline void free_die PARAMS ((dw_die_ref));
3519 static void remove_children PARAMS ((dw_die_ref));
3520 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3521 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref,
3522 tree));
3523 static dw_die_ref lookup_type_die PARAMS ((tree));
3524 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3525 static dw_die_ref lookup_decl_die PARAMS ((tree));
3526 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3527 static void print_spaces PARAMS ((FILE *));
3528 static void print_die PARAMS ((dw_die_ref, FILE *));
3529 static void print_dwarf_line_table PARAMS ((FILE *));
3530 static void reverse_die_lists PARAMS ((dw_die_ref));
3531 static void reverse_all_dies PARAMS ((dw_die_ref));
3532 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3533 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3534 static void loc_checksum PARAMS ((dw_loc_descr_ref,
3535 struct md5_ctx *));
3536 static void attr_checksum PARAMS ((dw_attr_ref,
3537 struct md5_ctx *));
3538 static void die_checksum PARAMS ((dw_die_ref,
3539 struct md5_ctx *));
3540 static void compute_section_prefix PARAMS ((dw_die_ref));
3541 static int is_type_die PARAMS ((dw_die_ref));
3542 static int is_comdat_die PARAMS ((dw_die_ref));
3543 static int is_symbol_die PARAMS ((dw_die_ref));
3544 static void assign_symbol_names PARAMS ((dw_die_ref));
3545 static void break_out_includes PARAMS ((dw_die_ref));
3546 static void add_sibling_attributes PARAMS ((dw_die_ref));
3547 static void build_abbrev_table PARAMS ((dw_die_ref));
3548 static void output_location_lists PARAMS ((dw_die_ref));
3549 static int constant_size PARAMS ((long unsigned));
3550 static unsigned long size_of_die PARAMS ((dw_die_ref));
3551 static void calc_die_sizes PARAMS ((dw_die_ref));
3552 static void mark_dies PARAMS ((dw_die_ref));
3553 static void unmark_dies PARAMS ((dw_die_ref));
3554 static unsigned long size_of_pubnames PARAMS ((void));
3555 static unsigned long size_of_aranges PARAMS ((void));
3556 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3557 static void output_value_format PARAMS ((dw_attr_ref));
3558 static void output_abbrev_section PARAMS ((void));
3559 static void output_die_symbol PARAMS ((dw_die_ref));
3560 static void output_die PARAMS ((dw_die_ref));
3561 static void output_compilation_unit_header PARAMS ((void));
3562 static void output_comp_unit PARAMS ((dw_die_ref));
3563 static const char *dwarf2_name PARAMS ((tree, int));
3564 static void add_pubname PARAMS ((tree, dw_die_ref));
3565 static void output_pubnames PARAMS ((void));
3566 static void add_arange PARAMS ((tree, dw_die_ref));
3567 static void output_aranges PARAMS ((void));
3568 static unsigned int add_ranges PARAMS ((tree));
3569 static void output_ranges PARAMS ((void));
3570 static void output_line_info PARAMS ((void));
3571 static void output_file_names PARAMS ((void));
3572 static dw_die_ref base_type_die PARAMS ((tree));
3573 static tree root_type PARAMS ((tree));
3574 static int is_base_type PARAMS ((tree));
3575 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3576 static int type_is_enum PARAMS ((tree));
3577 static unsigned int reg_number PARAMS ((rtx));
3578 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3579 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3580 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3581 static int is_based_loc PARAMS ((rtx));
3582 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3583 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3584 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3585 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3586 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3587 static tree field_type PARAMS ((tree));
3588 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3589 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3590 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3591 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3592 static void add_AT_location_description PARAMS ((dw_die_ref,
3593 enum dwarf_attribute, rtx));
3594 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3595 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3596 static rtx rtl_for_decl_location PARAMS ((tree));
3597 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3598 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3599 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3600 static void add_bound_info PARAMS ((dw_die_ref,
3601 enum dwarf_attribute, tree));
3602 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3603 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3604 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3605 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3606 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3607 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3608 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3609 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3610 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3611 static void push_decl_scope PARAMS ((tree));
3612 static void pop_decl_scope PARAMS ((void));
3613 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3614 static inline int local_scope_p PARAMS ((dw_die_ref));
3615 static inline int class_scope_p PARAMS ((dw_die_ref));
3616 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3617 dw_die_ref));
3618 static const char *type_tag PARAMS ((tree));
3619 static tree member_declared_type PARAMS ((tree));
3620 #if 0
3621 static const char *decl_start_label PARAMS ((tree));
3622 #endif
3623 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3624 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3625 #if 0
3626 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3627 #endif
3628 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3629 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3630 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3631 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3632 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3633 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3634 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3635 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3636 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3637 static void gen_label_die PARAMS ((tree, dw_die_ref));
3638 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3639 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3640 static void gen_field_die PARAMS ((tree, dw_die_ref));
3641 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3642 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3643 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3644 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3645 static void gen_member_die PARAMS ((tree, dw_die_ref));
3646 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3647 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3648 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3649 static void gen_type_die PARAMS ((tree, dw_die_ref));
3650 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3651 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3652 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3653 static int is_redundant_typedef PARAMS ((tree));
3654 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3655 static unsigned lookup_filename PARAMS ((const char *));
3656 static void init_file_table PARAMS ((void));
3657 static void retry_incomplete_types PARAMS ((void));
3658 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3659 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3660 static int file_info_cmp PARAMS ((const void *, const void *));
3661 static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
3662 const char *, const char *,
3663 const char *, unsigned));
3664 static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3665 dw_loc_descr_ref,
3666 const char *, const char *, const char *));
3667 static void output_loc_list PARAMS ((dw_loc_list_ref));
3668 static char *gen_internal_sym PARAMS ((const char *));
3669 static void mark_limbo_die_list PARAMS ((void *));
3671 /* Section names used to hold DWARF debugging information. */
3672 #ifndef DEBUG_INFO_SECTION
3673 #define DEBUG_INFO_SECTION ".debug_info"
3674 #endif
3675 #ifndef DEBUG_ABBREV_SECTION
3676 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3677 #endif
3678 #ifndef DEBUG_ARANGES_SECTION
3679 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3680 #endif
3681 #ifndef DEBUG_MACINFO_SECTION
3682 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3683 #endif
3684 #ifndef DEBUG_LINE_SECTION
3685 #define DEBUG_LINE_SECTION ".debug_line"
3686 #endif
3687 #ifndef DEBUG_LOC_SECTION
3688 #define DEBUG_LOC_SECTION ".debug_loc"
3689 #endif
3690 #ifndef DEBUG_PUBNAMES_SECTION
3691 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3692 #endif
3693 #ifndef DEBUG_STR_SECTION
3694 #define DEBUG_STR_SECTION ".debug_str"
3695 #endif
3696 #ifndef DEBUG_RANGES_SECTION
3697 #define DEBUG_RANGES_SECTION ".debug_ranges"
3698 #endif
3700 /* Standard ELF section names for compiled code and data. */
3701 #ifndef TEXT_SECTION_NAME
3702 #define TEXT_SECTION_NAME ".text"
3703 #endif
3705 /* Section flags for .debug_str section. */
3706 #ifdef HAVE_GAS_SHF_MERGE
3707 #define DEBUG_STR_SECTION_FLAGS \
3708 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
3709 #else
3710 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3711 #endif
3713 /* Labels we insert at beginning sections we can reference instead of
3714 the section names themselves. */
3716 #ifndef TEXT_SECTION_LABEL
3717 #define TEXT_SECTION_LABEL "Ltext"
3718 #endif
3719 #ifndef DEBUG_LINE_SECTION_LABEL
3720 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3721 #endif
3722 #ifndef DEBUG_INFO_SECTION_LABEL
3723 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3724 #endif
3725 #ifndef DEBUG_ABBREV_SECTION_LABEL
3726 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3727 #endif
3728 #ifndef DEBUG_LOC_SECTION_LABEL
3729 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3730 #endif
3731 #ifndef DEBUG_RANGES_SECTION_LABEL
3732 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3733 #endif
3734 #ifndef DEBUG_MACINFO_SECTION_LABEL
3735 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3736 #endif
3738 /* Definitions of defaults for formats and names of various special
3739 (artificial) labels which may be generated within this file (when the -g
3740 options is used and DWARF_DEBUGGING_INFO is in effect.
3741 If necessary, these may be overridden from within the tm.h file, but
3742 typically, overriding these defaults is unnecessary. */
3744 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3745 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3746 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3747 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3748 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3749 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3750 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3751 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3753 #ifndef TEXT_END_LABEL
3754 #define TEXT_END_LABEL "Letext"
3755 #endif
3756 #ifndef DATA_END_LABEL
3757 #define DATA_END_LABEL "Ledata"
3758 #endif
3759 #ifndef BSS_END_LABEL
3760 #define BSS_END_LABEL "Lebss"
3761 #endif
3762 #ifndef BLOCK_BEGIN_LABEL
3763 #define BLOCK_BEGIN_LABEL "LBB"
3764 #endif
3765 #ifndef BLOCK_END_LABEL
3766 #define BLOCK_END_LABEL "LBE"
3767 #endif
3768 #ifndef BODY_BEGIN_LABEL
3769 #define BODY_BEGIN_LABEL "Lbb"
3770 #endif
3771 #ifndef BODY_END_LABEL
3772 #define BODY_END_LABEL "Lbe"
3773 #endif
3774 #ifndef LINE_CODE_LABEL
3775 #define LINE_CODE_LABEL "LM"
3776 #endif
3777 #ifndef SEPARATE_LINE_CODE_LABEL
3778 #define SEPARATE_LINE_CODE_LABEL "LSM"
3779 #endif
3781 /* We allow a language front-end to designate a function that is to be
3782 called to "demangle" any name before it it put into a DIE. */
3784 static const char *(*demangle_name_func) PARAMS ((const char *));
3786 void
3787 dwarf2out_set_demangle_name_func (func)
3788 const char *(*func) PARAMS ((const char *));
3790 demangle_name_func = func;
3793 /* Test if rtl node points to a pseudo register. */
3795 static inline int
3796 is_pseudo_reg (rtl)
3797 rtx rtl;
3799 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3800 || (GET_CODE (rtl) == SUBREG
3801 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3804 /* Return a reference to a type, with its const and volatile qualifiers
3805 removed. */
3807 static inline tree
3808 type_main_variant (type)
3809 tree type;
3811 type = TYPE_MAIN_VARIANT (type);
3813 /* ??? There really should be only one main variant among any group of
3814 variants of a given type (and all of the MAIN_VARIANT values for all
3815 members of the group should point to that one type) but sometimes the C
3816 front-end messes this up for array types, so we work around that bug
3817 here. */
3818 if (TREE_CODE (type) == ARRAY_TYPE)
3819 while (type != TYPE_MAIN_VARIANT (type))
3820 type = TYPE_MAIN_VARIANT (type);
3822 return type;
3825 /* Return non-zero if the given type node represents a tagged type. */
3827 static inline int
3828 is_tagged_type (type)
3829 tree type;
3831 enum tree_code code = TREE_CODE (type);
3833 return (code == RECORD_TYPE || code == UNION_TYPE
3834 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3837 /* Convert a DIE tag into its string name. */
3839 static const char *
3840 dwarf_tag_name (tag)
3841 unsigned tag;
3843 switch (tag)
3845 case DW_TAG_padding:
3846 return "DW_TAG_padding";
3847 case DW_TAG_array_type:
3848 return "DW_TAG_array_type";
3849 case DW_TAG_class_type:
3850 return "DW_TAG_class_type";
3851 case DW_TAG_entry_point:
3852 return "DW_TAG_entry_point";
3853 case DW_TAG_enumeration_type:
3854 return "DW_TAG_enumeration_type";
3855 case DW_TAG_formal_parameter:
3856 return "DW_TAG_formal_parameter";
3857 case DW_TAG_imported_declaration:
3858 return "DW_TAG_imported_declaration";
3859 case DW_TAG_label:
3860 return "DW_TAG_label";
3861 case DW_TAG_lexical_block:
3862 return "DW_TAG_lexical_block";
3863 case DW_TAG_member:
3864 return "DW_TAG_member";
3865 case DW_TAG_pointer_type:
3866 return "DW_TAG_pointer_type";
3867 case DW_TAG_reference_type:
3868 return "DW_TAG_reference_type";
3869 case DW_TAG_compile_unit:
3870 return "DW_TAG_compile_unit";
3871 case DW_TAG_string_type:
3872 return "DW_TAG_string_type";
3873 case DW_TAG_structure_type:
3874 return "DW_TAG_structure_type";
3875 case DW_TAG_subroutine_type:
3876 return "DW_TAG_subroutine_type";
3877 case DW_TAG_typedef:
3878 return "DW_TAG_typedef";
3879 case DW_TAG_union_type:
3880 return "DW_TAG_union_type";
3881 case DW_TAG_unspecified_parameters:
3882 return "DW_TAG_unspecified_parameters";
3883 case DW_TAG_variant:
3884 return "DW_TAG_variant";
3885 case DW_TAG_common_block:
3886 return "DW_TAG_common_block";
3887 case DW_TAG_common_inclusion:
3888 return "DW_TAG_common_inclusion";
3889 case DW_TAG_inheritance:
3890 return "DW_TAG_inheritance";
3891 case DW_TAG_inlined_subroutine:
3892 return "DW_TAG_inlined_subroutine";
3893 case DW_TAG_module:
3894 return "DW_TAG_module";
3895 case DW_TAG_ptr_to_member_type:
3896 return "DW_TAG_ptr_to_member_type";
3897 case DW_TAG_set_type:
3898 return "DW_TAG_set_type";
3899 case DW_TAG_subrange_type:
3900 return "DW_TAG_subrange_type";
3901 case DW_TAG_with_stmt:
3902 return "DW_TAG_with_stmt";
3903 case DW_TAG_access_declaration:
3904 return "DW_TAG_access_declaration";
3905 case DW_TAG_base_type:
3906 return "DW_TAG_base_type";
3907 case DW_TAG_catch_block:
3908 return "DW_TAG_catch_block";
3909 case DW_TAG_const_type:
3910 return "DW_TAG_const_type";
3911 case DW_TAG_constant:
3912 return "DW_TAG_constant";
3913 case DW_TAG_enumerator:
3914 return "DW_TAG_enumerator";
3915 case DW_TAG_file_type:
3916 return "DW_TAG_file_type";
3917 case DW_TAG_friend:
3918 return "DW_TAG_friend";
3919 case DW_TAG_namelist:
3920 return "DW_TAG_namelist";
3921 case DW_TAG_namelist_item:
3922 return "DW_TAG_namelist_item";
3923 case DW_TAG_packed_type:
3924 return "DW_TAG_packed_type";
3925 case DW_TAG_subprogram:
3926 return "DW_TAG_subprogram";
3927 case DW_TAG_template_type_param:
3928 return "DW_TAG_template_type_param";
3929 case DW_TAG_template_value_param:
3930 return "DW_TAG_template_value_param";
3931 case DW_TAG_thrown_type:
3932 return "DW_TAG_thrown_type";
3933 case DW_TAG_try_block:
3934 return "DW_TAG_try_block";
3935 case DW_TAG_variant_part:
3936 return "DW_TAG_variant_part";
3937 case DW_TAG_variable:
3938 return "DW_TAG_variable";
3939 case DW_TAG_volatile_type:
3940 return "DW_TAG_volatile_type";
3941 case DW_TAG_MIPS_loop:
3942 return "DW_TAG_MIPS_loop";
3943 case DW_TAG_format_label:
3944 return "DW_TAG_format_label";
3945 case DW_TAG_function_template:
3946 return "DW_TAG_function_template";
3947 case DW_TAG_class_template:
3948 return "DW_TAG_class_template";
3949 case DW_TAG_GNU_BINCL:
3950 return "DW_TAG_GNU_BINCL";
3951 case DW_TAG_GNU_EINCL:
3952 return "DW_TAG_GNU_EINCL";
3953 default:
3954 return "DW_TAG_<unknown>";
3958 /* Convert a DWARF attribute code into its string name. */
3960 static const char *
3961 dwarf_attr_name (attr)
3962 unsigned attr;
3964 switch (attr)
3966 case DW_AT_sibling:
3967 return "DW_AT_sibling";
3968 case DW_AT_location:
3969 return "DW_AT_location";
3970 case DW_AT_name:
3971 return "DW_AT_name";
3972 case DW_AT_ordering:
3973 return "DW_AT_ordering";
3974 case DW_AT_subscr_data:
3975 return "DW_AT_subscr_data";
3976 case DW_AT_byte_size:
3977 return "DW_AT_byte_size";
3978 case DW_AT_bit_offset:
3979 return "DW_AT_bit_offset";
3980 case DW_AT_bit_size:
3981 return "DW_AT_bit_size";
3982 case DW_AT_element_list:
3983 return "DW_AT_element_list";
3984 case DW_AT_stmt_list:
3985 return "DW_AT_stmt_list";
3986 case DW_AT_low_pc:
3987 return "DW_AT_low_pc";
3988 case DW_AT_high_pc:
3989 return "DW_AT_high_pc";
3990 case DW_AT_language:
3991 return "DW_AT_language";
3992 case DW_AT_member:
3993 return "DW_AT_member";
3994 case DW_AT_discr:
3995 return "DW_AT_discr";
3996 case DW_AT_discr_value:
3997 return "DW_AT_discr_value";
3998 case DW_AT_visibility:
3999 return "DW_AT_visibility";
4000 case DW_AT_import:
4001 return "DW_AT_import";
4002 case DW_AT_string_length:
4003 return "DW_AT_string_length";
4004 case DW_AT_common_reference:
4005 return "DW_AT_common_reference";
4006 case DW_AT_comp_dir:
4007 return "DW_AT_comp_dir";
4008 case DW_AT_const_value:
4009 return "DW_AT_const_value";
4010 case DW_AT_containing_type:
4011 return "DW_AT_containing_type";
4012 case DW_AT_default_value:
4013 return "DW_AT_default_value";
4014 case DW_AT_inline:
4015 return "DW_AT_inline";
4016 case DW_AT_is_optional:
4017 return "DW_AT_is_optional";
4018 case DW_AT_lower_bound:
4019 return "DW_AT_lower_bound";
4020 case DW_AT_producer:
4021 return "DW_AT_producer";
4022 case DW_AT_prototyped:
4023 return "DW_AT_prototyped";
4024 case DW_AT_return_addr:
4025 return "DW_AT_return_addr";
4026 case DW_AT_start_scope:
4027 return "DW_AT_start_scope";
4028 case DW_AT_stride_size:
4029 return "DW_AT_stride_size";
4030 case DW_AT_upper_bound:
4031 return "DW_AT_upper_bound";
4032 case DW_AT_abstract_origin:
4033 return "DW_AT_abstract_origin";
4034 case DW_AT_accessibility:
4035 return "DW_AT_accessibility";
4036 case DW_AT_address_class:
4037 return "DW_AT_address_class";
4038 case DW_AT_artificial:
4039 return "DW_AT_artificial";
4040 case DW_AT_base_types:
4041 return "DW_AT_base_types";
4042 case DW_AT_calling_convention:
4043 return "DW_AT_calling_convention";
4044 case DW_AT_count:
4045 return "DW_AT_count";
4046 case DW_AT_data_member_location:
4047 return "DW_AT_data_member_location";
4048 case DW_AT_decl_column:
4049 return "DW_AT_decl_column";
4050 case DW_AT_decl_file:
4051 return "DW_AT_decl_file";
4052 case DW_AT_decl_line:
4053 return "DW_AT_decl_line";
4054 case DW_AT_declaration:
4055 return "DW_AT_declaration";
4056 case DW_AT_discr_list:
4057 return "DW_AT_discr_list";
4058 case DW_AT_encoding:
4059 return "DW_AT_encoding";
4060 case DW_AT_external:
4061 return "DW_AT_external";
4062 case DW_AT_frame_base:
4063 return "DW_AT_frame_base";
4064 case DW_AT_friend:
4065 return "DW_AT_friend";
4066 case DW_AT_identifier_case:
4067 return "DW_AT_identifier_case";
4068 case DW_AT_macro_info:
4069 return "DW_AT_macro_info";
4070 case DW_AT_namelist_items:
4071 return "DW_AT_namelist_items";
4072 case DW_AT_priority:
4073 return "DW_AT_priority";
4074 case DW_AT_segment:
4075 return "DW_AT_segment";
4076 case DW_AT_specification:
4077 return "DW_AT_specification";
4078 case DW_AT_static_link:
4079 return "DW_AT_static_link";
4080 case DW_AT_type:
4081 return "DW_AT_type";
4082 case DW_AT_use_location:
4083 return "DW_AT_use_location";
4084 case DW_AT_variable_parameter:
4085 return "DW_AT_variable_parameter";
4086 case DW_AT_virtuality:
4087 return "DW_AT_virtuality";
4088 case DW_AT_vtable_elem_location:
4089 return "DW_AT_vtable_elem_location";
4091 case DW_AT_allocated:
4092 return "DW_AT_allocated";
4093 case DW_AT_associated:
4094 return "DW_AT_associated";
4095 case DW_AT_data_location:
4096 return "DW_AT_data_location";
4097 case DW_AT_stride:
4098 return "DW_AT_stride";
4099 case DW_AT_entry_pc:
4100 return "DW_AT_entry_pc";
4101 case DW_AT_use_UTF8:
4102 return "DW_AT_use_UTF8";
4103 case DW_AT_extension:
4104 return "DW_AT_extension";
4105 case DW_AT_ranges:
4106 return "DW_AT_ranges";
4107 case DW_AT_trampoline:
4108 return "DW_AT_trampoline";
4109 case DW_AT_call_column:
4110 return "DW_AT_call_column";
4111 case DW_AT_call_file:
4112 return "DW_AT_call_file";
4113 case DW_AT_call_line:
4114 return "DW_AT_call_line";
4116 case DW_AT_MIPS_fde:
4117 return "DW_AT_MIPS_fde";
4118 case DW_AT_MIPS_loop_begin:
4119 return "DW_AT_MIPS_loop_begin";
4120 case DW_AT_MIPS_tail_loop_begin:
4121 return "DW_AT_MIPS_tail_loop_begin";
4122 case DW_AT_MIPS_epilog_begin:
4123 return "DW_AT_MIPS_epilog_begin";
4124 case DW_AT_MIPS_loop_unroll_factor:
4125 return "DW_AT_MIPS_loop_unroll_factor";
4126 case DW_AT_MIPS_software_pipeline_depth:
4127 return "DW_AT_MIPS_software_pipeline_depth";
4128 case DW_AT_MIPS_linkage_name:
4129 return "DW_AT_MIPS_linkage_name";
4130 case DW_AT_MIPS_stride:
4131 return "DW_AT_MIPS_stride";
4132 case DW_AT_MIPS_abstract_name:
4133 return "DW_AT_MIPS_abstract_name";
4134 case DW_AT_MIPS_clone_origin:
4135 return "DW_AT_MIPS_clone_origin";
4136 case DW_AT_MIPS_has_inlines:
4137 return "DW_AT_MIPS_has_inlines";
4139 case DW_AT_sf_names:
4140 return "DW_AT_sf_names";
4141 case DW_AT_src_info:
4142 return "DW_AT_src_info";
4143 case DW_AT_mac_info:
4144 return "DW_AT_mac_info";
4145 case DW_AT_src_coords:
4146 return "DW_AT_src_coords";
4147 case DW_AT_body_begin:
4148 return "DW_AT_body_begin";
4149 case DW_AT_body_end:
4150 return "DW_AT_body_end";
4151 case DW_AT_GNU_vector:
4152 return "DW_AT_GNU_vector";
4154 case DW_AT_VMS_rtnbeg_pd_address:
4155 return "DW_AT_VMS_rtnbeg_pd_address";
4157 default:
4158 return "DW_AT_<unknown>";
4162 /* Convert a DWARF value form code into its string name. */
4164 static const char *
4165 dwarf_form_name (form)
4166 unsigned form;
4168 switch (form)
4170 case DW_FORM_addr:
4171 return "DW_FORM_addr";
4172 case DW_FORM_block2:
4173 return "DW_FORM_block2";
4174 case DW_FORM_block4:
4175 return "DW_FORM_block4";
4176 case DW_FORM_data2:
4177 return "DW_FORM_data2";
4178 case DW_FORM_data4:
4179 return "DW_FORM_data4";
4180 case DW_FORM_data8:
4181 return "DW_FORM_data8";
4182 case DW_FORM_string:
4183 return "DW_FORM_string";
4184 case DW_FORM_block:
4185 return "DW_FORM_block";
4186 case DW_FORM_block1:
4187 return "DW_FORM_block1";
4188 case DW_FORM_data1:
4189 return "DW_FORM_data1";
4190 case DW_FORM_flag:
4191 return "DW_FORM_flag";
4192 case DW_FORM_sdata:
4193 return "DW_FORM_sdata";
4194 case DW_FORM_strp:
4195 return "DW_FORM_strp";
4196 case DW_FORM_udata:
4197 return "DW_FORM_udata";
4198 case DW_FORM_ref_addr:
4199 return "DW_FORM_ref_addr";
4200 case DW_FORM_ref1:
4201 return "DW_FORM_ref1";
4202 case DW_FORM_ref2:
4203 return "DW_FORM_ref2";
4204 case DW_FORM_ref4:
4205 return "DW_FORM_ref4";
4206 case DW_FORM_ref8:
4207 return "DW_FORM_ref8";
4208 case DW_FORM_ref_udata:
4209 return "DW_FORM_ref_udata";
4210 case DW_FORM_indirect:
4211 return "DW_FORM_indirect";
4212 default:
4213 return "DW_FORM_<unknown>";
4217 /* Convert a DWARF type code into its string name. */
4219 #if 0
4220 static const char *
4221 dwarf_type_encoding_name (enc)
4222 unsigned enc;
4224 switch (enc)
4226 case DW_ATE_address:
4227 return "DW_ATE_address";
4228 case DW_ATE_boolean:
4229 return "DW_ATE_boolean";
4230 case DW_ATE_complex_float:
4231 return "DW_ATE_complex_float";
4232 case DW_ATE_float:
4233 return "DW_ATE_float";
4234 case DW_ATE_signed:
4235 return "DW_ATE_signed";
4236 case DW_ATE_signed_char:
4237 return "DW_ATE_signed_char";
4238 case DW_ATE_unsigned:
4239 return "DW_ATE_unsigned";
4240 case DW_ATE_unsigned_char:
4241 return "DW_ATE_unsigned_char";
4242 default:
4243 return "DW_ATE_<unknown>";
4246 #endif
4248 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4249 instance of an inlined instance of a decl which is local to an inline
4250 function, so we have to trace all of the way back through the origin chain
4251 to find out what sort of node actually served as the original seed for the
4252 given block. */
4254 static tree
4255 decl_ultimate_origin (decl)
4256 tree decl;
4258 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4259 nodes in the function to point to themselves; ignore that if
4260 we're trying to output the abstract instance of this function. */
4261 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4262 return NULL_TREE;
4264 #ifdef ENABLE_CHECKING
4265 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4266 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4267 most distant ancestor, this should never happen. */
4268 abort ();
4269 #endif
4271 return DECL_ABSTRACT_ORIGIN (decl);
4274 /* Determine the "ultimate origin" of a block. The block may be an inlined
4275 instance of an inlined instance of a block which is local to an inline
4276 function, so we have to trace all of the way back through the origin chain
4277 to find out what sort of node actually served as the original seed for the
4278 given block. */
4280 static tree
4281 block_ultimate_origin (block)
4282 tree block;
4284 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4286 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4287 nodes in the function to point to themselves; ignore that if
4288 we're trying to output the abstract instance of this function. */
4289 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4290 return NULL_TREE;
4292 if (immediate_origin == NULL_TREE)
4293 return NULL_TREE;
4294 else
4296 tree ret_val;
4297 tree lookahead = immediate_origin;
4301 ret_val = lookahead;
4302 lookahead = (TREE_CODE (ret_val) == BLOCK
4303 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4305 while (lookahead != NULL && lookahead != ret_val);
4307 return ret_val;
4311 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4312 of a virtual function may refer to a base class, so we check the 'this'
4313 parameter. */
4315 static tree
4316 decl_class_context (decl)
4317 tree decl;
4319 tree context = NULL_TREE;
4321 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4322 context = DECL_CONTEXT (decl);
4323 else
4324 context = TYPE_MAIN_VARIANT
4325 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4327 if (context && !TYPE_P (context))
4328 context = NULL_TREE;
4330 return context;
4333 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4334 addition order, and correct that in reverse_all_dies. */
4336 static inline void
4337 add_dwarf_attr (die, attr)
4338 dw_die_ref die;
4339 dw_attr_ref attr;
4341 if (die != NULL && attr != NULL)
4343 attr->dw_attr_next = die->die_attr;
4344 die->die_attr = attr;
4348 static inline dw_val_class
4349 AT_class (a)
4350 dw_attr_ref a;
4352 return a->dw_attr_val.val_class;
4355 /* Add a flag value attribute to a DIE. */
4357 static inline void
4358 add_AT_flag (die, attr_kind, flag)
4359 dw_die_ref die;
4360 enum dwarf_attribute attr_kind;
4361 unsigned flag;
4363 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4365 attr->dw_attr_next = NULL;
4366 attr->dw_attr = attr_kind;
4367 attr->dw_attr_val.val_class = dw_val_class_flag;
4368 attr->dw_attr_val.v.val_flag = flag;
4369 add_dwarf_attr (die, attr);
4372 static inline unsigned
4373 AT_flag (a)
4374 dw_attr_ref a;
4376 if (a && AT_class (a) == dw_val_class_flag)
4377 return a->dw_attr_val.v.val_flag;
4379 abort ();
4382 /* Add a signed integer attribute value to a DIE. */
4384 static inline void
4385 add_AT_int (die, attr_kind, int_val)
4386 dw_die_ref die;
4387 enum dwarf_attribute attr_kind;
4388 long int int_val;
4390 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4392 attr->dw_attr_next = NULL;
4393 attr->dw_attr = attr_kind;
4394 attr->dw_attr_val.val_class = dw_val_class_const;
4395 attr->dw_attr_val.v.val_int = int_val;
4396 add_dwarf_attr (die, attr);
4399 static inline long int
4400 AT_int (a)
4401 dw_attr_ref a;
4403 if (a && AT_class (a) == dw_val_class_const)
4404 return a->dw_attr_val.v.val_int;
4406 abort ();
4409 /* Add an unsigned integer attribute value to a DIE. */
4411 static inline void
4412 add_AT_unsigned (die, attr_kind, unsigned_val)
4413 dw_die_ref die;
4414 enum dwarf_attribute attr_kind;
4415 unsigned long unsigned_val;
4417 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4419 attr->dw_attr_next = NULL;
4420 attr->dw_attr = attr_kind;
4421 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4422 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4423 add_dwarf_attr (die, attr);
4426 static inline unsigned long
4427 AT_unsigned (a)
4428 dw_attr_ref a;
4430 if (a && AT_class (a) == dw_val_class_unsigned_const)
4431 return a->dw_attr_val.v.val_unsigned;
4433 abort ();
4436 /* Add an unsigned double integer attribute value to a DIE. */
4438 static inline void
4439 add_AT_long_long (die, attr_kind, val_hi, val_low)
4440 dw_die_ref die;
4441 enum dwarf_attribute attr_kind;
4442 unsigned long val_hi;
4443 unsigned long val_low;
4445 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4447 attr->dw_attr_next = NULL;
4448 attr->dw_attr = attr_kind;
4449 attr->dw_attr_val.val_class = dw_val_class_long_long;
4450 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4451 attr->dw_attr_val.v.val_long_long.low = val_low;
4452 add_dwarf_attr (die, attr);
4455 /* Add a floating point attribute value to a DIE and return it. */
4457 static inline void
4458 add_AT_float (die, attr_kind, length, array)
4459 dw_die_ref die;
4460 enum dwarf_attribute attr_kind;
4461 unsigned length;
4462 long *array;
4464 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4466 attr->dw_attr_next = NULL;
4467 attr->dw_attr = attr_kind;
4468 attr->dw_attr_val.val_class = dw_val_class_float;
4469 attr->dw_attr_val.v.val_float.length = length;
4470 attr->dw_attr_val.v.val_float.array = array;
4471 add_dwarf_attr (die, attr);
4474 /* Add a string attribute value to a DIE. */
4476 static inline void
4477 add_AT_string (die, attr_kind, str)
4478 dw_die_ref die;
4479 enum dwarf_attribute attr_kind;
4480 const char *str;
4482 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4483 struct indirect_string_node *node;
4485 if (! debug_str_hash)
4487 debug_str_hash = ht_create (10);
4488 debug_str_hash->alloc_node = indirect_string_alloc;
4491 node = (struct indirect_string_node *)
4492 ht_lookup (debug_str_hash, (const unsigned char *) str,
4493 strlen (str), HT_ALLOC);
4494 node->refcount++;
4496 attr->dw_attr_next = NULL;
4497 attr->dw_attr = attr_kind;
4498 attr->dw_attr_val.val_class = dw_val_class_str;
4499 attr->dw_attr_val.v.val_str = node;
4500 add_dwarf_attr (die, attr);
4503 static inline const char *
4504 AT_string (a)
4505 dw_attr_ref a;
4507 if (a && AT_class (a) == dw_val_class_str)
4508 return (const char *) HT_STR (&a->dw_attr_val.v.val_str->id);
4510 abort ();
4513 /* Find out whether a string should be output inline in DIE
4514 or out-of-line in .debug_str section. */
4516 static int
4517 AT_string_form (a)
4518 dw_attr_ref a;
4520 if (a && AT_class (a) == dw_val_class_str)
4522 struct indirect_string_node *node;
4523 unsigned int len;
4524 extern int const_labelno;
4525 char label[32];
4527 node = a->dw_attr_val.v.val_str;
4528 if (node->form)
4529 return node->form;
4531 len = HT_LEN (&node->id) + 1;
4533 /* If the string is shorter or equal to the size of the reference, it is
4534 always better to put it inline. */
4535 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4536 return node->form = DW_FORM_string;
4538 /* If we cannot expect the linker to merge strings in .debug_str
4539 section, only put it into .debug_str if it is worth even in this
4540 single module. */
4541 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0
4542 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
4543 return node->form = DW_FORM_string;
4545 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
4546 ++const_labelno;
4547 node->label = xstrdup (label);
4549 return node->form = DW_FORM_strp;
4552 abort ();
4555 /* Add a DIE reference attribute value to a DIE. */
4557 static inline void
4558 add_AT_die_ref (die, attr_kind, targ_die)
4559 dw_die_ref die;
4560 enum dwarf_attribute attr_kind;
4561 dw_die_ref targ_die;
4563 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4565 attr->dw_attr_next = NULL;
4566 attr->dw_attr = attr_kind;
4567 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4568 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4569 attr->dw_attr_val.v.val_die_ref.external = 0;
4570 add_dwarf_attr (die, attr);
4573 static inline dw_die_ref
4574 AT_ref (a)
4575 dw_attr_ref a;
4577 if (a && AT_class (a) == dw_val_class_die_ref)
4578 return a->dw_attr_val.v.val_die_ref.die;
4580 abort ();
4583 static inline int
4584 AT_ref_external (a)
4585 dw_attr_ref a;
4587 if (a && AT_class (a) == dw_val_class_die_ref)
4588 return a->dw_attr_val.v.val_die_ref.external;
4590 return 0;
4593 static inline void
4594 set_AT_ref_external (a, i)
4595 dw_attr_ref a;
4596 int i;
4598 if (a && AT_class (a) == dw_val_class_die_ref)
4599 a->dw_attr_val.v.val_die_ref.external = i;
4600 else
4601 abort ();
4604 /* Add an FDE reference attribute value to a DIE. */
4606 static inline void
4607 add_AT_fde_ref (die, attr_kind, targ_fde)
4608 dw_die_ref die;
4609 enum dwarf_attribute attr_kind;
4610 unsigned targ_fde;
4612 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4614 attr->dw_attr_next = NULL;
4615 attr->dw_attr = attr_kind;
4616 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4617 attr->dw_attr_val.v.val_fde_index = targ_fde;
4618 add_dwarf_attr (die, attr);
4621 /* Add a location description attribute value to a DIE. */
4623 static inline void
4624 add_AT_loc (die, attr_kind, loc)
4625 dw_die_ref die;
4626 enum dwarf_attribute attr_kind;
4627 dw_loc_descr_ref loc;
4629 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4631 attr->dw_attr_next = NULL;
4632 attr->dw_attr = attr_kind;
4633 attr->dw_attr_val.val_class = dw_val_class_loc;
4634 attr->dw_attr_val.v.val_loc = loc;
4635 add_dwarf_attr (die, attr);
4638 static inline dw_loc_descr_ref
4639 AT_loc (a)
4640 dw_attr_ref a;
4642 if (a && AT_class (a) == dw_val_class_loc)
4643 return a->dw_attr_val.v.val_loc;
4645 abort ();
4648 static inline void
4649 add_AT_loc_list (die, attr_kind, loc_list)
4650 dw_die_ref die;
4651 enum dwarf_attribute attr_kind;
4652 dw_loc_list_ref loc_list;
4654 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4656 attr->dw_attr_next = NULL;
4657 attr->dw_attr = attr_kind;
4658 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4659 attr->dw_attr_val.v.val_loc_list = loc_list;
4660 add_dwarf_attr (die, attr);
4661 have_location_lists = 1;
4664 static inline dw_loc_list_ref
4665 AT_loc_list (a)
4666 dw_attr_ref a;
4668 if (a && AT_class (a) == dw_val_class_loc_list)
4669 return a->dw_attr_val.v.val_loc_list;
4671 abort ();
4674 /* Add an address constant attribute value to a DIE. */
4676 static inline void
4677 add_AT_addr (die, attr_kind, addr)
4678 dw_die_ref die;
4679 enum dwarf_attribute attr_kind;
4680 rtx addr;
4682 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4684 attr->dw_attr_next = NULL;
4685 attr->dw_attr = attr_kind;
4686 attr->dw_attr_val.val_class = dw_val_class_addr;
4687 attr->dw_attr_val.v.val_addr = addr;
4688 add_dwarf_attr (die, attr);
4691 static inline rtx
4692 AT_addr (a)
4693 dw_attr_ref a;
4695 if (a && AT_class (a) == dw_val_class_addr)
4696 return a->dw_attr_val.v.val_addr;
4698 abort ();
4701 /* Add a label identifier attribute value to a DIE. */
4703 static inline void
4704 add_AT_lbl_id (die, attr_kind, lbl_id)
4705 dw_die_ref die;
4706 enum dwarf_attribute attr_kind;
4707 const char *lbl_id;
4709 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4711 attr->dw_attr_next = NULL;
4712 attr->dw_attr = attr_kind;
4713 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4714 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4715 add_dwarf_attr (die, attr);
4718 /* Add a section offset attribute value to a DIE. */
4720 static inline void
4721 add_AT_lbl_offset (die, attr_kind, label)
4722 dw_die_ref die;
4723 enum dwarf_attribute attr_kind;
4724 const char *label;
4726 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4728 attr->dw_attr_next = NULL;
4729 attr->dw_attr = attr_kind;
4730 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4731 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4732 add_dwarf_attr (die, attr);
4735 /* Add an offset attribute value to a DIE. */
4737 static inline void
4738 add_AT_offset (die, attr_kind, offset)
4739 dw_die_ref die;
4740 enum dwarf_attribute attr_kind;
4741 unsigned long offset;
4743 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4745 attr->dw_attr_next = NULL;
4746 attr->dw_attr = attr_kind;
4747 attr->dw_attr_val.val_class = dw_val_class_offset;
4748 attr->dw_attr_val.v.val_offset = offset;
4749 add_dwarf_attr (die, attr);
4752 /* Add an range_list attribute value to a DIE. */
4754 static void
4755 add_AT_range_list (die, attr_kind, offset)
4756 dw_die_ref die;
4757 enum dwarf_attribute attr_kind;
4758 unsigned long offset;
4760 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4762 attr->dw_attr_next = NULL;
4763 attr->dw_attr = attr_kind;
4764 attr->dw_attr_val.val_class = dw_val_class_range_list;
4765 attr->dw_attr_val.v.val_offset = offset;
4766 add_dwarf_attr (die, attr);
4769 static inline const char *
4770 AT_lbl (a)
4771 dw_attr_ref a;
4773 if (a && (AT_class (a) == dw_val_class_lbl_id
4774 || AT_class (a) == dw_val_class_lbl_offset))
4775 return a->dw_attr_val.v.val_lbl_id;
4777 abort ();
4780 /* Get the attribute of type attr_kind. */
4782 static inline dw_attr_ref
4783 get_AT (die, attr_kind)
4784 dw_die_ref die;
4785 enum dwarf_attribute attr_kind;
4787 dw_attr_ref a;
4788 dw_die_ref spec = NULL;
4790 if (die != NULL)
4792 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4793 if (a->dw_attr == attr_kind)
4794 return a;
4795 else if (a->dw_attr == DW_AT_specification
4796 || a->dw_attr == DW_AT_abstract_origin)
4797 spec = AT_ref (a);
4799 if (spec)
4800 return get_AT (spec, attr_kind);
4803 return NULL;
4806 /* Return the "low pc" attribute value, typically associated with a subprogram
4807 DIE. Return null if the "low pc" attribute is either not present, or if it
4808 cannot be represented as an assembler label identifier. */
4810 static inline const char *
4811 get_AT_low_pc (die)
4812 dw_die_ref die;
4814 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4816 return a ? AT_lbl (a) : NULL;
4819 /* Return the "high pc" attribute value, typically associated with a subprogram
4820 DIE. Return null if the "high pc" attribute is either not present, or if it
4821 cannot be represented as an assembler label identifier. */
4823 static inline const char *
4824 get_AT_hi_pc (die)
4825 dw_die_ref die;
4827 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4829 return a ? AT_lbl (a) : NULL;
4832 /* Return the value of the string attribute designated by ATTR_KIND, or
4833 NULL if it is not present. */
4835 static inline const char *
4836 get_AT_string (die, attr_kind)
4837 dw_die_ref die;
4838 enum dwarf_attribute attr_kind;
4840 dw_attr_ref a = get_AT (die, attr_kind);
4842 return a ? AT_string (a) : NULL;
4845 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4846 if it is not present. */
4848 static inline int
4849 get_AT_flag (die, attr_kind)
4850 dw_die_ref die;
4851 enum dwarf_attribute attr_kind;
4853 dw_attr_ref a = get_AT (die, attr_kind);
4855 return a ? AT_flag (a) : 0;
4858 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4859 if it is not present. */
4861 static inline unsigned
4862 get_AT_unsigned (die, attr_kind)
4863 dw_die_ref die;
4864 enum dwarf_attribute attr_kind;
4866 dw_attr_ref a = get_AT (die, attr_kind);
4868 return a ? AT_unsigned (a) : 0;
4871 static inline dw_die_ref
4872 get_AT_ref (die, attr_kind)
4873 dw_die_ref die;
4874 enum dwarf_attribute attr_kind;
4876 dw_attr_ref a = get_AT (die, attr_kind);
4878 return a ? AT_ref (a) : NULL;
4881 static inline int
4882 is_c_family ()
4884 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4886 return (lang == DW_LANG_C || lang == DW_LANG_C89
4887 || lang == DW_LANG_C_plus_plus);
4890 static inline int
4891 is_cxx ()
4893 return (get_AT_unsigned (comp_unit_die, DW_AT_language)
4894 == DW_LANG_C_plus_plus);
4897 static inline int
4898 is_fortran ()
4900 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4902 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4905 static inline int
4906 is_java ()
4908 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4910 return (lang == DW_LANG_Java);
4913 /* Free up the memory used by A. */
4915 static inline void free_AT PARAMS ((dw_attr_ref));
4916 static inline void
4917 free_AT (a)
4918 dw_attr_ref a;
4920 switch (AT_class (a))
4922 case dw_val_class_str:
4923 if (a->dw_attr_val.v.val_str->refcount)
4924 a->dw_attr_val.v.val_str->refcount--;
4925 break;
4927 case dw_val_class_lbl_id:
4928 case dw_val_class_lbl_offset:
4929 free (a->dw_attr_val.v.val_lbl_id);
4930 break;
4932 case dw_val_class_float:
4933 free (a->dw_attr_val.v.val_float.array);
4934 break;
4936 default:
4937 break;
4940 free (a);
4943 /* Remove the specified attribute if present. */
4945 static void
4946 remove_AT (die, attr_kind)
4947 dw_die_ref die;
4948 enum dwarf_attribute attr_kind;
4950 dw_attr_ref *p;
4951 dw_attr_ref removed = NULL;
4953 if (die != NULL)
4955 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4956 if ((*p)->dw_attr == attr_kind)
4958 removed = *p;
4959 *p = (*p)->dw_attr_next;
4960 break;
4963 if (removed != 0)
4964 free_AT (removed);
4968 /* Free up the memory used by DIE. */
4970 static inline void
4971 free_die (die)
4972 dw_die_ref die;
4974 remove_children (die);
4975 free (die);
4978 /* Discard the children of this DIE. */
4980 static void
4981 remove_children (die)
4982 dw_die_ref die;
4984 dw_die_ref child_die = die->die_child;
4986 die->die_child = NULL;
4988 while (child_die != NULL)
4990 dw_die_ref tmp_die = child_die;
4991 dw_attr_ref a;
4993 child_die = child_die->die_sib;
4995 for (a = tmp_die->die_attr; a != NULL;)
4997 dw_attr_ref tmp_a = a;
4999 a = a->dw_attr_next;
5000 free_AT (tmp_a);
5003 free_die (tmp_die);
5007 /* Add a child DIE below its parent. We build the lists up in reverse
5008 addition order, and correct that in reverse_all_dies. */
5010 static inline void
5011 add_child_die (die, child_die)
5012 dw_die_ref die;
5013 dw_die_ref child_die;
5015 if (die != NULL && child_die != NULL)
5017 if (die == child_die)
5018 abort ();
5020 child_die->die_parent = die;
5021 child_die->die_sib = die->die_child;
5022 die->die_child = child_die;
5026 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5027 is the specification, to the front of PARENT's list of children. */
5029 static void
5030 splice_child_die (parent, child)
5031 dw_die_ref parent, child;
5033 dw_die_ref *p;
5035 /* We want the declaration DIE from inside the class, not the
5036 specification DIE at toplevel. */
5037 if (child->die_parent != parent)
5039 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5041 if (tmp)
5042 child = tmp;
5045 if (child->die_parent != parent
5046 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
5047 abort ();
5049 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
5050 if (*p == child)
5052 *p = child->die_sib;
5053 break;
5056 child->die_sib = parent->die_child;
5057 parent->die_child = child;
5060 /* Return a pointer to a newly created DIE node. */
5062 static inline dw_die_ref
5063 new_die (tag_value, parent_die, t)
5064 enum dwarf_tag tag_value;
5065 dw_die_ref parent_die;
5066 tree t;
5068 dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
5070 die->die_tag = tag_value;
5072 if (parent_die != NULL)
5073 add_child_die (parent_die, die);
5074 else
5076 limbo_die_node *limbo_node;
5078 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
5079 limbo_node->die = die;
5080 limbo_node->created_for = t;
5081 limbo_node->next = limbo_die_list;
5082 limbo_die_list = limbo_node;
5085 return die;
5088 /* Return the DIE associated with the given type specifier. */
5090 static inline dw_die_ref
5091 lookup_type_die (type)
5092 tree type;
5094 return TYPE_SYMTAB_DIE (type);
5097 /* Equate a DIE to a given type specifier. */
5099 static inline void
5100 equate_type_number_to_die (type, type_die)
5101 tree type;
5102 dw_die_ref type_die;
5104 TYPE_SYMTAB_DIE (type) = type_die;
5107 /* Return the DIE associated with a given declaration. */
5109 static inline dw_die_ref
5110 lookup_decl_die (decl)
5111 tree decl;
5113 unsigned decl_id = DECL_UID (decl);
5115 return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL);
5118 /* Equate a DIE to a particular declaration. */
5120 static void
5121 equate_decl_number_to_die (decl, decl_die)
5122 tree decl;
5123 dw_die_ref decl_die;
5125 unsigned int decl_id = DECL_UID (decl);
5126 unsigned int num_allocated;
5128 if (decl_id >= decl_die_table_allocated)
5130 num_allocated
5131 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5132 / DECL_DIE_TABLE_INCREMENT)
5133 * DECL_DIE_TABLE_INCREMENT;
5135 decl_die_table
5136 = (dw_die_ref *) xrealloc (decl_die_table,
5137 sizeof (dw_die_ref) * num_allocated);
5139 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5140 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5141 decl_die_table_allocated = num_allocated;
5144 if (decl_id >= decl_die_table_in_use)
5145 decl_die_table_in_use = (decl_id + 1);
5147 decl_die_table[decl_id] = decl_die;
5150 /* Keep track of the number of spaces used to indent the
5151 output of the debugging routines that print the structure of
5152 the DIE internal representation. */
5153 static int print_indent;
5155 /* Indent the line the number of spaces given by print_indent. */
5157 static inline void
5158 print_spaces (outfile)
5159 FILE *outfile;
5161 fprintf (outfile, "%*s", print_indent, "");
5164 /* Print the information associated with a given DIE, and its children.
5165 This routine is a debugging aid only. */
5167 static void
5168 print_die (die, outfile)
5169 dw_die_ref die;
5170 FILE *outfile;
5172 dw_attr_ref a;
5173 dw_die_ref c;
5175 print_spaces (outfile);
5176 fprintf (outfile, "DIE %4lu: %s\n",
5177 die->die_offset, dwarf_tag_name (die->die_tag));
5178 print_spaces (outfile);
5179 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5180 fprintf (outfile, " offset: %lu\n", die->die_offset);
5182 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5184 print_spaces (outfile);
5185 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5187 switch (AT_class (a))
5189 case dw_val_class_addr:
5190 fprintf (outfile, "address");
5191 break;
5192 case dw_val_class_offset:
5193 fprintf (outfile, "offset");
5194 break;
5195 case dw_val_class_loc:
5196 fprintf (outfile, "location descriptor");
5197 break;
5198 case dw_val_class_loc_list:
5199 fprintf (outfile, "location list -> label:%s",
5200 AT_loc_list (a)->ll_symbol);
5201 break;
5202 case dw_val_class_range_list:
5203 fprintf (outfile, "range list");
5204 break;
5205 case dw_val_class_const:
5206 fprintf (outfile, "%ld", AT_int (a));
5207 break;
5208 case dw_val_class_unsigned_const:
5209 fprintf (outfile, "%lu", AT_unsigned (a));
5210 break;
5211 case dw_val_class_long_long:
5212 fprintf (outfile, "constant (%lu,%lu)",
5213 a->dw_attr_val.v.val_long_long.hi,
5214 a->dw_attr_val.v.val_long_long.low);
5215 break;
5216 case dw_val_class_float:
5217 fprintf (outfile, "floating-point constant");
5218 break;
5219 case dw_val_class_flag:
5220 fprintf (outfile, "%u", AT_flag (a));
5221 break;
5222 case dw_val_class_die_ref:
5223 if (AT_ref (a) != NULL)
5225 if (AT_ref (a)->die_symbol)
5226 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5227 else
5228 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5230 else
5231 fprintf (outfile, "die -> <null>");
5232 break;
5233 case dw_val_class_lbl_id:
5234 case dw_val_class_lbl_offset:
5235 fprintf (outfile, "label: %s", AT_lbl (a));
5236 break;
5237 case dw_val_class_str:
5238 if (AT_string (a) != NULL)
5239 fprintf (outfile, "\"%s\"", AT_string (a));
5240 else
5241 fprintf (outfile, "<null>");
5242 break;
5243 default:
5244 break;
5247 fprintf (outfile, "\n");
5250 if (die->die_child != NULL)
5252 print_indent += 4;
5253 for (c = die->die_child; c != NULL; c = c->die_sib)
5254 print_die (c, outfile);
5256 print_indent -= 4;
5258 if (print_indent == 0)
5259 fprintf (outfile, "\n");
5262 /* Print the contents of the source code line number correspondence table.
5263 This routine is a debugging aid only. */
5265 static void
5266 print_dwarf_line_table (outfile)
5267 FILE *outfile;
5269 unsigned i;
5270 dw_line_info_ref line_info;
5272 fprintf (outfile, "\n\nDWARF source line information\n");
5273 for (i = 1; i < line_info_table_in_use; i++)
5275 line_info = &line_info_table[i];
5276 fprintf (outfile, "%5d: ", i);
5277 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5278 fprintf (outfile, "%6ld", line_info->dw_line_num);
5279 fprintf (outfile, "\n");
5282 fprintf (outfile, "\n\n");
5285 /* Print the information collected for a given DIE. */
5287 void
5288 debug_dwarf_die (die)
5289 dw_die_ref die;
5291 print_die (die, stderr);
5294 /* Print all DWARF information collected for the compilation unit.
5295 This routine is a debugging aid only. */
5297 void
5298 debug_dwarf ()
5300 print_indent = 0;
5301 print_die (comp_unit_die, stderr);
5302 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5303 print_dwarf_line_table (stderr);
5306 /* We build up the lists of children and attributes by pushing new ones
5307 onto the beginning of the list. Reverse the lists for DIE so that
5308 they are in order of addition. */
5310 static void
5311 reverse_die_lists (die)
5312 dw_die_ref die;
5314 dw_die_ref c, cp, cn;
5315 dw_attr_ref a, ap, an;
5317 for (a = die->die_attr, ap = 0; a; a = an)
5319 an = a->dw_attr_next;
5320 a->dw_attr_next = ap;
5321 ap = a;
5324 die->die_attr = ap;
5326 for (c = die->die_child, cp = 0; c; c = cn)
5328 cn = c->die_sib;
5329 c->die_sib = cp;
5330 cp = c;
5333 die->die_child = cp;
5336 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5337 reverse all dies in add_sibling_attributes, which runs through all the dies,
5338 it would reverse all the dies. Now, however, since we don't call
5339 reverse_die_lists in add_sibling_attributes, we need a routine to
5340 recursively reverse all the dies. This is that routine. */
5342 static void
5343 reverse_all_dies (die)
5344 dw_die_ref die;
5346 dw_die_ref c;
5348 reverse_die_lists (die);
5350 for (c = die->die_child; c; c = c->die_sib)
5351 reverse_all_dies (c);
5354 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5355 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5356 DIE that marks the start of the DIEs for this include file. */
5358 static dw_die_ref
5359 push_new_compile_unit (old_unit, bincl_die)
5360 dw_die_ref old_unit, bincl_die;
5362 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5363 dw_die_ref new_unit = gen_compile_unit_die (filename);
5365 new_unit->die_sib = old_unit;
5366 return new_unit;
5369 /* Close an include-file CU and reopen the enclosing one. */
5371 static dw_die_ref
5372 pop_compile_unit (old_unit)
5373 dw_die_ref old_unit;
5375 dw_die_ref new_unit = old_unit->die_sib;
5377 old_unit->die_sib = NULL;
5378 return new_unit;
5381 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5382 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5384 /* Calculate the checksum of a location expression. */
5386 static inline void
5387 loc_checksum (loc, ctx)
5388 dw_loc_descr_ref loc;
5389 struct md5_ctx *ctx;
5391 CHECKSUM (loc->dw_loc_opc);
5392 CHECKSUM (loc->dw_loc_oprnd1);
5393 CHECKSUM (loc->dw_loc_oprnd2);
5396 /* Calculate the checksum of an attribute. */
5398 static void
5399 attr_checksum (at, ctx)
5400 dw_attr_ref at;
5401 struct md5_ctx *ctx;
5403 dw_loc_descr_ref loc;
5404 rtx r;
5406 CHECKSUM (at->dw_attr);
5408 /* We don't care about differences in file numbering. */
5409 if (at->dw_attr == DW_AT_decl_file
5410 /* Or that this was compiled with a different compiler snapshot; if
5411 the output is the same, that's what matters. */
5412 || at->dw_attr == DW_AT_producer)
5413 return;
5415 switch (AT_class (at))
5417 case dw_val_class_const:
5418 CHECKSUM (at->dw_attr_val.v.val_int);
5419 break;
5420 case dw_val_class_unsigned_const:
5421 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5422 break;
5423 case dw_val_class_long_long:
5424 CHECKSUM (at->dw_attr_val.v.val_long_long);
5425 break;
5426 case dw_val_class_float:
5427 CHECKSUM (at->dw_attr_val.v.val_float);
5428 break;
5429 case dw_val_class_flag:
5430 CHECKSUM (at->dw_attr_val.v.val_flag);
5431 break;
5432 case dw_val_class_str:
5433 CHECKSUM_STRING (AT_string (at));
5434 break;
5436 case dw_val_class_addr:
5437 r = AT_addr (at);
5438 switch (GET_CODE (r))
5440 case SYMBOL_REF:
5441 CHECKSUM_STRING (XSTR (r, 0));
5442 break;
5444 default:
5445 abort ();
5447 break;
5449 case dw_val_class_offset:
5450 CHECKSUM (at->dw_attr_val.v.val_offset);
5451 break;
5453 case dw_val_class_loc:
5454 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5455 loc_checksum (loc, ctx);
5456 break;
5458 case dw_val_class_die_ref:
5459 if (AT_ref (at)->die_offset)
5460 CHECKSUM (AT_ref (at)->die_offset);
5461 /* FIXME else use target die name or something. */
5463 case dw_val_class_fde_ref:
5464 case dw_val_class_lbl_id:
5465 case dw_val_class_lbl_offset:
5466 break;
5468 default:
5469 break;
5473 /* Calculate the checksum of a DIE. */
5475 static void
5476 die_checksum (die, ctx)
5477 dw_die_ref die;
5478 struct md5_ctx *ctx;
5480 dw_die_ref c;
5481 dw_attr_ref a;
5483 CHECKSUM (die->die_tag);
5485 for (a = die->die_attr; a; a = a->dw_attr_next)
5486 attr_checksum (a, ctx);
5488 for (c = die->die_child; c; c = c->die_sib)
5489 die_checksum (c, ctx);
5492 #undef CHECKSUM
5493 #undef CHECKSUM_STRING
5495 /* The prefix to attach to symbols on DIEs in the current comdat debug
5496 info section. */
5497 static char *comdat_symbol_id;
5499 /* The index of the current symbol within the current comdat CU. */
5500 static unsigned int comdat_symbol_number;
5502 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5503 children, and set comdat_symbol_id accordingly. */
5505 static void
5506 compute_section_prefix (unit_die)
5507 dw_die_ref unit_die;
5509 const char *base = lbasename (get_AT_string (unit_die, DW_AT_name));
5510 char *name = (char *) alloca (strlen (base) + 64);
5511 char *p;
5512 int i;
5513 unsigned char checksum[16];
5514 struct md5_ctx ctx;
5516 /* Compute the checksum of the DIE, then append part of it as hex digits to
5517 the name filename of the unit. */
5519 md5_init_ctx (&ctx);
5520 die_checksum (unit_die, &ctx);
5521 md5_finish_ctx (&ctx, checksum);
5523 sprintf (name, "%s.", base);
5524 clean_symbol_name (name);
5526 p = name + strlen (name);
5527 for (i = 0; i < 4; i++)
5529 sprintf (p, "%.2x", checksum[i]);
5530 p += 2;
5533 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5534 comdat_symbol_number = 0;
5537 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5539 static int
5540 is_type_die (die)
5541 dw_die_ref die;
5543 switch (die->die_tag)
5545 case DW_TAG_array_type:
5546 case DW_TAG_class_type:
5547 case DW_TAG_enumeration_type:
5548 case DW_TAG_pointer_type:
5549 case DW_TAG_reference_type:
5550 case DW_TAG_string_type:
5551 case DW_TAG_structure_type:
5552 case DW_TAG_subroutine_type:
5553 case DW_TAG_union_type:
5554 case DW_TAG_ptr_to_member_type:
5555 case DW_TAG_set_type:
5556 case DW_TAG_subrange_type:
5557 case DW_TAG_base_type:
5558 case DW_TAG_const_type:
5559 case DW_TAG_file_type:
5560 case DW_TAG_packed_type:
5561 case DW_TAG_volatile_type:
5562 return 1;
5563 default:
5564 return 0;
5568 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5569 Basically, we want to choose the bits that are likely to be shared between
5570 compilations (types) and leave out the bits that are specific to individual
5571 compilations (functions). */
5573 static int
5574 is_comdat_die (c)
5575 dw_die_ref c;
5577 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5578 we do for stabs. The advantage is a greater likelihood of sharing between
5579 objects that don't include headers in the same order (and therefore would
5580 put the base types in a different comdat). jason 8/28/00 */
5582 if (c->die_tag == DW_TAG_base_type)
5583 return 0;
5585 if (c->die_tag == DW_TAG_pointer_type
5586 || c->die_tag == DW_TAG_reference_type
5587 || c->die_tag == DW_TAG_const_type
5588 || c->die_tag == DW_TAG_volatile_type)
5590 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5592 return t ? is_comdat_die (t) : 0;
5595 return is_type_die (c);
5598 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5599 compilation unit. */
5601 static int
5602 is_symbol_die (c)
5603 dw_die_ref c;
5605 return (is_type_die (c)
5606 || (get_AT (c, DW_AT_declaration)
5607 && !get_AT (c, DW_AT_specification)));
5610 static char *
5611 gen_internal_sym (prefix)
5612 const char *prefix;
5614 char buf[256];
5615 static int label_num;
5617 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5618 return xstrdup (buf);
5621 /* Assign symbols to all worthy DIEs under DIE. */
5623 static void
5624 assign_symbol_names (die)
5625 dw_die_ref die;
5627 dw_die_ref c;
5629 if (is_symbol_die (die))
5631 if (comdat_symbol_id)
5633 char *p = alloca (strlen (comdat_symbol_id) + 64);
5635 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5636 comdat_symbol_id, comdat_symbol_number++);
5637 die->die_symbol = xstrdup (p);
5639 else
5640 die->die_symbol = gen_internal_sym ("LDIE");
5643 for (c = die->die_child; c != NULL; c = c->die_sib)
5644 assign_symbol_names (c);
5647 /* Traverse the DIE (which is always comp_unit_die), and set up
5648 additional compilation units for each of the include files we see
5649 bracketed by BINCL/EINCL. */
5651 static void
5652 break_out_includes (die)
5653 dw_die_ref die;
5655 dw_die_ref *ptr;
5656 dw_die_ref unit = NULL;
5657 limbo_die_node *node;
5659 for (ptr = &(die->die_child); *ptr;)
5661 dw_die_ref c = *ptr;
5663 if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
5664 || (unit && is_comdat_die (c)))
5666 /* This DIE is for a secondary CU; remove it from the main one. */
5667 *ptr = c->die_sib;
5669 if (c->die_tag == DW_TAG_GNU_BINCL)
5671 unit = push_new_compile_unit (unit, c);
5672 free_die (c);
5674 else if (c->die_tag == DW_TAG_GNU_EINCL)
5676 unit = pop_compile_unit (unit);
5677 free_die (c);
5679 else
5680 add_child_die (unit, c);
5682 else
5684 /* Leave this DIE in the main CU. */
5685 ptr = &(c->die_sib);
5686 continue;
5690 #if 0
5691 /* We can only use this in debugging, since the frontend doesn't check
5692 to make sure that we leave every include file we enter. */
5693 if (unit != NULL)
5694 abort ();
5695 #endif
5697 assign_symbol_names (die);
5698 for (node = limbo_die_list; node; node = node->next)
5700 compute_section_prefix (node->die);
5701 assign_symbol_names (node->die);
5705 /* Traverse the DIE and add a sibling attribute if it may have the
5706 effect of speeding up access to siblings. To save some space,
5707 avoid generating sibling attributes for DIE's without children. */
5709 static void
5710 add_sibling_attributes (die)
5711 dw_die_ref die;
5713 dw_die_ref c;
5715 if (die->die_tag != DW_TAG_compile_unit
5716 && die->die_sib && die->die_child != NULL)
5717 /* Add the sibling link to the front of the attribute list. */
5718 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5720 for (c = die->die_child; c != NULL; c = c->die_sib)
5721 add_sibling_attributes (c);
5724 /* Output all location lists for the DIE and its children. */
5726 static void
5727 output_location_lists (die)
5728 dw_die_ref die;
5730 dw_die_ref c;
5731 dw_attr_ref d_attr;
5733 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5734 if (AT_class (d_attr) == dw_val_class_loc_list)
5735 output_loc_list (AT_loc_list (d_attr));
5737 for (c = die->die_child; c != NULL; c = c->die_sib)
5738 output_location_lists (c);
5742 /* The format of each DIE (and its attribute value pairs) is encoded in an
5743 abbreviation table. This routine builds the abbreviation table and assigns
5744 a unique abbreviation id for each abbreviation entry. The children of each
5745 die are visited recursively. */
5747 static void
5748 build_abbrev_table (die)
5749 dw_die_ref die;
5751 unsigned long abbrev_id;
5752 unsigned int n_alloc;
5753 dw_die_ref c;
5754 dw_attr_ref d_attr, a_attr;
5756 /* Scan the DIE references, and mark as external any that refer to
5757 DIEs from other CUs (i.e. those which are not marked). */
5758 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5759 if (AT_class (d_attr) == dw_val_class_die_ref
5760 && AT_ref (d_attr)->die_mark == 0)
5762 if (AT_ref (d_attr)->die_symbol == 0)
5763 abort ();
5765 set_AT_ref_external (d_attr, 1);
5768 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5770 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5772 if (abbrev->die_tag == die->die_tag)
5774 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5776 a_attr = abbrev->die_attr;
5777 d_attr = die->die_attr;
5779 while (a_attr != NULL && d_attr != NULL)
5781 if ((a_attr->dw_attr != d_attr->dw_attr)
5782 || (value_format (a_attr) != value_format (d_attr)))
5783 break;
5785 a_attr = a_attr->dw_attr_next;
5786 d_attr = d_attr->dw_attr_next;
5789 if (a_attr == NULL && d_attr == NULL)
5790 break;
5795 if (abbrev_id >= abbrev_die_table_in_use)
5797 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5799 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5800 abbrev_die_table
5801 = (dw_die_ref *) xrealloc (abbrev_die_table,
5802 sizeof (dw_die_ref) * n_alloc);
5804 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5805 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5806 abbrev_die_table_allocated = n_alloc;
5809 ++abbrev_die_table_in_use;
5810 abbrev_die_table[abbrev_id] = die;
5813 die->die_abbrev = abbrev_id;
5814 for (c = die->die_child; c != NULL; c = c->die_sib)
5815 build_abbrev_table (c);
5818 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5820 static int
5821 constant_size (value)
5822 long unsigned value;
5824 int log;
5826 if (value == 0)
5827 log = 0;
5828 else
5829 log = floor_log2 (value);
5831 log = log / 8;
5832 log = 1 << (floor_log2 (log) + 1);
5834 return log;
5837 /* Return the size of a DIE as it is represented in the
5838 .debug_info section. */
5840 static unsigned long
5841 size_of_die (die)
5842 dw_die_ref die;
5844 unsigned long size = 0;
5845 dw_attr_ref a;
5847 size += size_of_uleb128 (die->die_abbrev);
5848 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5850 switch (AT_class (a))
5852 case dw_val_class_addr:
5853 size += DWARF2_ADDR_SIZE;
5854 break;
5855 case dw_val_class_offset:
5856 size += DWARF_OFFSET_SIZE;
5857 break;
5858 case dw_val_class_loc:
5860 unsigned long lsize = size_of_locs (AT_loc (a));
5862 /* Block length. */
5863 size += constant_size (lsize);
5864 size += lsize;
5866 break;
5867 case dw_val_class_loc_list:
5868 size += DWARF_OFFSET_SIZE;
5869 break;
5870 case dw_val_class_range_list:
5871 size += DWARF_OFFSET_SIZE;
5872 break;
5873 case dw_val_class_const:
5874 size += size_of_sleb128 (AT_int (a));
5875 break;
5876 case dw_val_class_unsigned_const:
5877 size += constant_size (AT_unsigned (a));
5878 break;
5879 case dw_val_class_long_long:
5880 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5881 break;
5882 case dw_val_class_float:
5883 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5884 break;
5885 case dw_val_class_flag:
5886 size += 1;
5887 break;
5888 case dw_val_class_die_ref:
5889 size += DWARF_OFFSET_SIZE;
5890 break;
5891 case dw_val_class_fde_ref:
5892 size += DWARF_OFFSET_SIZE;
5893 break;
5894 case dw_val_class_lbl_id:
5895 size += DWARF2_ADDR_SIZE;
5896 break;
5897 case dw_val_class_lbl_offset:
5898 size += DWARF_OFFSET_SIZE;
5899 break;
5900 case dw_val_class_str:
5901 if (AT_string_form (a) == DW_FORM_strp)
5902 size += DWARF_OFFSET_SIZE;
5903 else
5904 size += HT_LEN (&a->dw_attr_val.v.val_str->id) + 1;
5905 break;
5906 default:
5907 abort ();
5911 return size;
5914 /* Size the debugging information associated with a given DIE. Visits the
5915 DIE's children recursively. Updates the global variable next_die_offset, on
5916 each time through. Uses the current value of next_die_offset to update the
5917 die_offset field in each DIE. */
5919 static void
5920 calc_die_sizes (die)
5921 dw_die_ref die;
5923 dw_die_ref c;
5925 die->die_offset = next_die_offset;
5926 next_die_offset += size_of_die (die);
5928 for (c = die->die_child; c != NULL; c = c->die_sib)
5929 calc_die_sizes (c);
5931 if (die->die_child != NULL)
5932 /* Count the null byte used to terminate sibling lists. */
5933 next_die_offset += 1;
5936 /* Set the marks for a die and its children. We do this so
5937 that we know whether or not a reference needs to use FORM_ref_addr; only
5938 DIEs in the same CU will be marked. We used to clear out the offset
5939 and use that as the flag, but ran into ordering problems. */
5941 static void
5942 mark_dies (die)
5943 dw_die_ref die;
5945 dw_die_ref c;
5947 die->die_mark = 1;
5948 for (c = die->die_child; c; c = c->die_sib)
5949 mark_dies (c);
5952 /* Clear the marks for a die and its children. */
5954 static void
5955 unmark_dies (die)
5956 dw_die_ref die;
5958 dw_die_ref c;
5960 die->die_mark = 0;
5961 for (c = die->die_child; c; c = c->die_sib)
5962 unmark_dies (c);
5965 /* Return the size of the .debug_pubnames table generated for the
5966 compilation unit. */
5968 static unsigned long
5969 size_of_pubnames ()
5971 unsigned long size;
5972 unsigned i;
5974 size = DWARF_PUBNAMES_HEADER_SIZE;
5975 for (i = 0; i < pubname_table_in_use; i++)
5977 pubname_ref p = &pubname_table[i];
5978 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
5981 size += DWARF_OFFSET_SIZE;
5982 return size;
5985 /* Return the size of the information in the .debug_aranges section. */
5987 static unsigned long
5988 size_of_aranges ()
5990 unsigned long size;
5992 size = DWARF_ARANGES_HEADER_SIZE;
5994 /* Count the address/length pair for this compilation unit. */
5995 size += 2 * DWARF2_ADDR_SIZE;
5996 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5998 /* Count the two zero words used to terminated the address range table. */
5999 size += 2 * DWARF2_ADDR_SIZE;
6000 return size;
6003 /* Select the encoding of an attribute value. */
6005 static enum dwarf_form
6006 value_format (a)
6007 dw_attr_ref a;
6009 switch (a->dw_attr_val.val_class)
6011 case dw_val_class_addr:
6012 return DW_FORM_addr;
6013 case dw_val_class_range_list:
6014 case dw_val_class_offset:
6015 if (DWARF_OFFSET_SIZE == 4)
6016 return DW_FORM_data4;
6017 if (DWARF_OFFSET_SIZE == 8)
6018 return DW_FORM_data8;
6019 abort ();
6020 case dw_val_class_loc_list:
6021 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6022 .debug_loc section */
6023 return DW_FORM_data4;
6024 case dw_val_class_loc:
6025 switch (constant_size (size_of_locs (AT_loc (a))))
6027 case 1:
6028 return DW_FORM_block1;
6029 case 2:
6030 return DW_FORM_block2;
6031 default:
6032 abort ();
6034 case dw_val_class_const:
6035 return DW_FORM_sdata;
6036 case dw_val_class_unsigned_const:
6037 switch (constant_size (AT_unsigned (a)))
6039 case 1:
6040 return DW_FORM_data1;
6041 case 2:
6042 return DW_FORM_data2;
6043 case 4:
6044 return DW_FORM_data4;
6045 case 8:
6046 return DW_FORM_data8;
6047 default:
6048 abort ();
6050 case dw_val_class_long_long:
6051 return DW_FORM_block1;
6052 case dw_val_class_float:
6053 return DW_FORM_block1;
6054 case dw_val_class_flag:
6055 return DW_FORM_flag;
6056 case dw_val_class_die_ref:
6057 if (AT_ref_external (a))
6058 return DW_FORM_ref_addr;
6059 else
6060 return DW_FORM_ref;
6061 case dw_val_class_fde_ref:
6062 return DW_FORM_data;
6063 case dw_val_class_lbl_id:
6064 return DW_FORM_addr;
6065 case dw_val_class_lbl_offset:
6066 return DW_FORM_data;
6067 case dw_val_class_str:
6068 return AT_string_form (a);
6070 default:
6071 abort ();
6075 /* Output the encoding of an attribute value. */
6077 static void
6078 output_value_format (a)
6079 dw_attr_ref a;
6081 enum dwarf_form form = value_format (a);
6083 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6086 /* Output the .debug_abbrev section which defines the DIE abbreviation
6087 table. */
6089 static void
6090 output_abbrev_section ()
6092 unsigned long abbrev_id;
6094 dw_attr_ref a_attr;
6096 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6098 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6100 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6101 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6102 dwarf_tag_name (abbrev->die_tag));
6104 if (abbrev->die_child != NULL)
6105 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6106 else
6107 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6109 for (a_attr = abbrev->die_attr; a_attr != NULL;
6110 a_attr = a_attr->dw_attr_next)
6112 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6113 dwarf_attr_name (a_attr->dw_attr));
6114 output_value_format (a_attr);
6117 dw2_asm_output_data (1, 0, NULL);
6118 dw2_asm_output_data (1, 0, NULL);
6121 /* Terminate the table. */
6122 dw2_asm_output_data (1, 0, NULL);
6125 /* Output a symbol we can use to refer to this DIE from another CU. */
6127 static inline void
6128 output_die_symbol (die)
6129 dw_die_ref die;
6131 char *sym = die->die_symbol;
6133 if (sym == 0)
6134 return;
6136 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6137 /* We make these global, not weak; if the target doesn't support
6138 .linkonce, it doesn't support combining the sections, so debugging
6139 will break. */
6140 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
6142 ASM_OUTPUT_LABEL (asm_out_file, sym);
6145 /* Return a new location list, given the begin and end range, and the
6146 expression. gensym tells us whether to generate a new internal symbol for
6147 this location list node, which is done for the head of the list only. */
6149 static inline dw_loc_list_ref
6150 new_loc_list (expr, begin, end, section, gensym)
6151 dw_loc_descr_ref expr;
6152 const char *begin;
6153 const char *end;
6154 const char *section;
6155 unsigned gensym;
6157 dw_loc_list_ref retlist
6158 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
6160 retlist->begin = begin;
6161 retlist->end = end;
6162 retlist->expr = expr;
6163 retlist->section = section;
6164 if (gensym)
6165 retlist->ll_symbol = gen_internal_sym ("LLST");
6167 return retlist;
6170 /* Add a location description expression to a location list */
6172 static inline void
6173 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
6174 dw_loc_list_ref *list_head;
6175 dw_loc_descr_ref descr;
6176 const char *begin;
6177 const char *end;
6178 const char *section;
6180 dw_loc_list_ref *d;
6182 /* Find the end of the chain. */
6183 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6186 /* Add a new location list node to the list */
6187 *d = new_loc_list (descr, begin, end, section, 0);
6190 /* Output the location list given to us */
6192 static void
6193 output_loc_list (list_head)
6194 dw_loc_list_ref list_head;
6196 dw_loc_list_ref curr = list_head;
6198 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6200 /* ??? This shouldn't be needed now that we've forced the
6201 compilation unit base address to zero when there is code
6202 in more than one section. */
6203 if (strcmp (curr->section, ".text") == 0)
6205 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6206 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0,
6207 "Location list base address specifier fake entry");
6208 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
6209 "Location list base address specifier base");
6212 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
6214 unsigned long size;
6216 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6217 "Location list begin address (%s)",
6218 list_head->ll_symbol);
6219 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6220 "Location list end address (%s)",
6221 list_head->ll_symbol);
6222 size = size_of_locs (curr->expr);
6224 /* Output the block length for this list of location operations. */
6225 if (size > 0xffff)
6226 abort ();
6227 dw2_asm_output_data (2, size, "%s", "Location expression size");
6229 output_loc_sequence (curr->expr);
6232 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6233 "Location list terminator begin (%s)",
6234 list_head->ll_symbol);
6235 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6236 "Location list terminator end (%s)",
6237 list_head->ll_symbol);
6240 /* Output the DIE and its attributes. Called recursively to generate
6241 the definitions of each child DIE. */
6243 static void
6244 output_die (die)
6245 dw_die_ref die;
6247 dw_attr_ref a;
6248 dw_die_ref c;
6249 unsigned long size;
6251 /* If someone in another CU might refer to us, set up a symbol for
6252 them to point to. */
6253 if (die->die_symbol)
6254 output_die_symbol (die);
6256 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6257 die->die_offset, dwarf_tag_name (die->die_tag));
6259 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6261 const char *name = dwarf_attr_name (a->dw_attr);
6263 switch (AT_class (a))
6265 case dw_val_class_addr:
6266 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6267 break;
6269 case dw_val_class_offset:
6270 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6271 "%s", name);
6272 break;
6274 case dw_val_class_range_list:
6276 char *p = strchr (ranges_section_label, '\0');
6278 sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset);
6279 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
6280 "%s", name);
6281 *p = '\0';
6283 break;
6285 case dw_val_class_loc:
6286 size = size_of_locs (AT_loc (a));
6288 /* Output the block length for this list of location operations. */
6289 dw2_asm_output_data (constant_size (size), size, "%s", name);
6291 output_loc_sequence (AT_loc (a));
6292 break;
6294 case dw_val_class_const:
6295 /* ??? It would be slightly more efficient to use a scheme like is
6296 used for unsigned constants below, but gdb 4.x does not sign
6297 extend. Gdb 5.x does sign extend. */
6298 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6299 break;
6301 case dw_val_class_unsigned_const:
6302 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6303 AT_unsigned (a), "%s", name);
6304 break;
6306 case dw_val_class_long_long:
6308 unsigned HOST_WIDE_INT first, second;
6310 dw2_asm_output_data (1,
6311 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6312 "%s", name);
6314 if (WORDS_BIG_ENDIAN)
6316 first = a->dw_attr_val.v.val_long_long.hi;
6317 second = a->dw_attr_val.v.val_long_long.low;
6319 else
6321 first = a->dw_attr_val.v.val_long_long.low;
6322 second = a->dw_attr_val.v.val_long_long.hi;
6325 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6326 first, "long long constant");
6327 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6328 second, NULL);
6330 break;
6332 case dw_val_class_float:
6334 unsigned int i;
6336 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6337 "%s", name);
6339 for (i = 0; i < a->dw_attr_val.v.val_float.length; i++)
6340 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6341 "fp constant word %u", i);
6342 break;
6345 case dw_val_class_flag:
6346 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6347 break;
6349 case dw_val_class_loc_list:
6351 char *sym = AT_loc_list (a)->ll_symbol;
6353 if (sym == 0)
6354 abort ();
6355 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
6356 loc_section_label, "%s", name);
6358 break;
6360 case dw_val_class_die_ref:
6361 if (AT_ref_external (a))
6363 char *sym = AT_ref (a)->die_symbol;
6365 if (sym == 0)
6366 abort ();
6367 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6369 else if (AT_ref (a)->die_offset == 0)
6370 abort ();
6371 else
6372 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6373 "%s", name);
6374 break;
6376 case dw_val_class_fde_ref:
6378 char l1[20];
6380 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6381 a->dw_attr_val.v.val_fde_index * 2);
6382 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6384 break;
6386 case dw_val_class_lbl_id:
6387 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6388 break;
6390 case dw_val_class_lbl_offset:
6391 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6392 break;
6394 case dw_val_class_str:
6395 if (AT_string_form (a) == DW_FORM_strp)
6396 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
6397 a->dw_attr_val.v.val_str->label,
6398 "%s: \"%s\"", name, AT_string (a));
6399 else
6400 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6401 break;
6403 default:
6404 abort ();
6408 for (c = die->die_child; c != NULL; c = c->die_sib)
6409 output_die (c);
6411 /* Add null byte to terminate sibling list. */
6412 if (die->die_child != NULL)
6413 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6414 die->die_offset);
6417 /* Output the compilation unit that appears at the beginning of the
6418 .debug_info section, and precedes the DIE descriptions. */
6420 static void
6421 output_compilation_unit_header ()
6423 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6424 "Length of Compilation Unit Info");
6425 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6426 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6427 "Offset Into Abbrev. Section");
6428 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6431 /* Output the compilation unit DIE and its children. */
6433 static void
6434 output_comp_unit (die)
6435 dw_die_ref die;
6437 const char *secname;
6439 /* Even if there are no children of this DIE, we must output the information
6440 about the compilation unit. Otherwise, on an empty translation unit, we
6441 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6442 will then complain when examining the file. First mark all the DIEs in
6443 this CU so we know which get local refs. */
6444 mark_dies (die);
6446 build_abbrev_table (die);
6448 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6449 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6450 calc_die_sizes (die);
6452 if (die->die_symbol)
6454 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6456 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6457 secname = tmp;
6458 die->die_symbol = NULL;
6460 else
6461 secname = (const char *) DEBUG_INFO_SECTION;
6463 /* Output debugging information. */
6464 named_section_flags (secname, SECTION_DEBUG);
6465 output_compilation_unit_header ();
6466 output_die (die);
6468 /* Leave the marks on the main CU, so we can check them in
6469 output_pubnames. */
6470 if (die->die_symbol)
6471 unmark_dies (die);
6474 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
6475 output of lang_hooks.decl_printable_name for C++ looks like
6476 "A::f(int)". Let's drop the argument list, and maybe the scope. */
6478 static const char *
6479 dwarf2_name (decl, scope)
6480 tree decl;
6481 int scope;
6483 return (*lang_hooks.decl_printable_name) (decl, scope ? 1 : 0);
6486 /* Add a new entry to .debug_pubnames if appropriate. */
6488 static void
6489 add_pubname (decl, die)
6490 tree decl;
6491 dw_die_ref die;
6493 pubname_ref p;
6495 if (! TREE_PUBLIC (decl))
6496 return;
6498 if (pubname_table_in_use == pubname_table_allocated)
6500 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6501 pubname_table
6502 = (pubname_ref) xrealloc (pubname_table,
6503 (pubname_table_allocated
6504 * sizeof (pubname_entry)));
6507 p = &pubname_table[pubname_table_in_use++];
6508 p->die = die;
6509 p->name = xstrdup (dwarf2_name (decl, 1));
6512 /* Output the public names table used to speed up access to externally
6513 visible names. For now, only generate entries for externally
6514 visible procedures. */
6516 static void
6517 output_pubnames ()
6519 unsigned i;
6520 unsigned long pubnames_length = size_of_pubnames ();
6522 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6523 "Length of Public Names Info");
6524 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6525 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6526 "Offset of Compilation Unit Info");
6527 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6528 "Compilation Unit Length");
6530 for (i = 0; i < pubname_table_in_use; i++)
6532 pubname_ref pub = &pubname_table[i];
6534 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6535 if (pub->die->die_mark == 0)
6536 abort ();
6538 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6539 "DIE offset");
6541 dw2_asm_output_nstring (pub->name, -1, "external name");
6544 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6547 /* Add a new entry to .debug_aranges if appropriate. */
6549 static void
6550 add_arange (decl, die)
6551 tree decl;
6552 dw_die_ref die;
6554 if (! DECL_SECTION_NAME (decl))
6555 return;
6557 if (arange_table_in_use == arange_table_allocated)
6559 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6560 arange_table = (dw_die_ref *)
6561 xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref));
6564 arange_table[arange_table_in_use++] = die;
6567 /* Output the information that goes into the .debug_aranges table.
6568 Namely, define the beginning and ending address range of the
6569 text section generated for this compilation unit. */
6571 static void
6572 output_aranges ()
6574 unsigned i;
6575 unsigned long aranges_length = size_of_aranges ();
6577 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6578 "Length of Address Ranges Info");
6579 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6580 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6581 "Offset of Compilation Unit Info");
6582 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6583 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6585 /* We need to align to twice the pointer size here. */
6586 if (DWARF_ARANGES_PAD_SIZE)
6588 /* Pad using a 2 byte words so that padding is correct for any
6589 pointer size. */
6590 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6591 2 * DWARF2_ADDR_SIZE);
6592 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6593 dw2_asm_output_data (2, 0, NULL);
6596 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6597 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6598 text_section_label, "Length");
6600 for (i = 0; i < arange_table_in_use; i++)
6602 dw_die_ref die = arange_table[i];
6604 /* We shouldn't see aranges for DIEs outside of the main CU. */
6605 if (die->die_mark == 0)
6606 abort ();
6608 if (die->die_tag == DW_TAG_subprogram)
6610 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6611 "Address");
6612 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6613 get_AT_low_pc (die), "Length");
6615 else
6617 /* A static variable; extract the symbol from DW_AT_location.
6618 Note that this code isn't currently hit, as we only emit
6619 aranges for functions (jason 9/23/99). */
6620 dw_attr_ref a = get_AT (die, DW_AT_location);
6621 dw_loc_descr_ref loc;
6623 if (! a || AT_class (a) != dw_val_class_loc)
6624 abort ();
6626 loc = AT_loc (a);
6627 if (loc->dw_loc_opc != DW_OP_addr)
6628 abort ();
6630 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6631 loc->dw_loc_oprnd1.v.val_addr, "Address");
6632 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6633 get_AT_unsigned (die, DW_AT_byte_size),
6634 "Length");
6638 /* Output the terminator words. */
6639 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6640 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6643 /* Add a new entry to .debug_ranges. Return the offset at which it
6644 was placed. */
6646 static unsigned int
6647 add_ranges (block)
6648 tree block;
6650 unsigned int in_use = ranges_table_in_use;
6652 if (in_use == ranges_table_allocated)
6654 ranges_table_allocated += RANGES_TABLE_INCREMENT;
6655 ranges_table = (dw_ranges_ref)
6656 xrealloc (ranges_table, (ranges_table_allocated
6657 * sizeof (struct dw_ranges_struct)));
6660 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
6661 ranges_table_in_use = in_use + 1;
6663 return in_use * 2 * DWARF2_ADDR_SIZE;
6666 static void
6667 output_ranges ()
6669 unsigned i;
6670 static const char *const start_fmt = "Offset 0x%x";
6671 const char *fmt = start_fmt;
6673 for (i = 0; i < ranges_table_in_use; i++)
6675 int block_num = ranges_table[i].block_num;
6677 if (block_num)
6679 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
6680 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
6682 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
6683 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
6685 /* If all code is in the text section, then the compilation
6686 unit base address defaults to DW_AT_low_pc, which is the
6687 base of the text section. */
6688 if (separate_line_info_table_in_use == 0)
6690 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
6691 text_section_label,
6692 fmt, i * 2 * DWARF2_ADDR_SIZE);
6693 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
6694 text_section_label, NULL);
6697 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6698 compilation unit base address to zero, which allows us to
6699 use absolute addresses, and not worry about whether the
6700 target supports cross-section arithmetic. */
6701 else
6703 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
6704 fmt, i * 2 * DWARF2_ADDR_SIZE);
6705 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
6708 fmt = NULL;
6710 else
6712 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6713 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6714 fmt = start_fmt;
6719 /* Data structure containing information about input files. */
6720 struct file_info
6722 char *path; /* Complete file name. */
6723 char *fname; /* File name part. */
6724 int length; /* Length of entire string. */
6725 int file_idx; /* Index in input file table. */
6726 int dir_idx; /* Index in directory table. */
6729 /* Data structure containing information about directories with source
6730 files. */
6731 struct dir_info
6733 char *path; /* Path including directory name. */
6734 int length; /* Path length. */
6735 int prefix; /* Index of directory entry which is a prefix. */
6736 int count; /* Number of files in this directory. */
6737 int dir_idx; /* Index of directory used as base. */
6738 int used; /* Used in the end? */
6741 /* Callback function for file_info comparison. We sort by looking at
6742 the directories in the path. */
6744 static int
6745 file_info_cmp (p1, p2)
6746 const void *p1;
6747 const void *p2;
6749 const struct file_info *s1 = p1;
6750 const struct file_info *s2 = p2;
6751 unsigned char *cp1;
6752 unsigned char *cp2;
6754 /* Take care of file names without directories. We need to make sure that
6755 we return consistent values to qsort since some will get confused if
6756 we return the same value when identical operands are passed in opposite
6757 orders. So if neither has a directory, return 0 and otherwise return
6758 1 or -1 depending on which one has the directory. */
6759 if ((s1->path == s1->fname || s2->path == s2->fname))
6760 return (s2->path == s2->fname) - (s1->path == s1->fname);
6762 cp1 = (unsigned char *) s1->path;
6763 cp2 = (unsigned char *) s2->path;
6765 while (1)
6767 ++cp1;
6768 ++cp2;
6769 /* Reached the end of the first path? If so, handle like above. */
6770 if ((cp1 == (unsigned char *) s1->fname)
6771 || (cp2 == (unsigned char *) s2->fname))
6772 return ((cp2 == (unsigned char *) s2->fname)
6773 - (cp1 == (unsigned char *) s1->fname));
6775 /* Character of current path component the same? */
6776 else if (*cp1 != *cp2)
6777 return *cp1 - *cp2;
6781 /* Output the directory table and the file name table. We try to minimize
6782 the total amount of memory needed. A heuristic is used to avoid large
6783 slowdowns with many input files. */
6785 static void
6786 output_file_names ()
6788 struct file_info *files;
6789 struct dir_info *dirs;
6790 int *saved;
6791 int *savehere;
6792 int *backmap;
6793 int ndirs;
6794 int idx_offset;
6795 int i;
6796 int idx;
6798 /* Allocate the various arrays we need. */
6799 files = (struct file_info *) alloca (file_table.in_use
6800 * sizeof (struct file_info));
6801 dirs = (struct dir_info *) alloca (file_table.in_use
6802 * sizeof (struct dir_info));
6804 /* Sort the file names. */
6805 for (i = 1; i < (int) file_table.in_use; i++)
6807 char *f;
6809 /* Skip all leading "./". */
6810 f = file_table.table[i];
6811 while (f[0] == '.' && f[1] == '/')
6812 f += 2;
6814 /* Create a new array entry. */
6815 files[i].path = f;
6816 files[i].length = strlen (f);
6817 files[i].file_idx = i;
6819 /* Search for the file name part. */
6820 f = strrchr (f, '/');
6821 files[i].fname = f == NULL ? files[i].path : f + 1;
6824 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6826 /* Find all the different directories used. */
6827 dirs[0].path = files[1].path;
6828 dirs[0].length = files[1].fname - files[1].path;
6829 dirs[0].prefix = -1;
6830 dirs[0].count = 1;
6831 dirs[0].dir_idx = 0;
6832 dirs[0].used = 0;
6833 files[1].dir_idx = 0;
6834 ndirs = 1;
6836 for (i = 2; i < (int) file_table.in_use; i++)
6837 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6838 && memcmp (dirs[ndirs - 1].path, files[i].path,
6839 dirs[ndirs - 1].length) == 0)
6841 /* Same directory as last entry. */
6842 files[i].dir_idx = ndirs - 1;
6843 ++dirs[ndirs - 1].count;
6845 else
6847 int j;
6849 /* This is a new directory. */
6850 dirs[ndirs].path = files[i].path;
6851 dirs[ndirs].length = files[i].fname - files[i].path;
6852 dirs[ndirs].count = 1;
6853 dirs[ndirs].dir_idx = ndirs;
6854 dirs[ndirs].used = 0;
6855 files[i].dir_idx = ndirs;
6857 /* Search for a prefix. */
6858 dirs[ndirs].prefix = -1;
6859 for (j = 0; j < ndirs; j++)
6860 if (dirs[j].length < dirs[ndirs].length
6861 && dirs[j].length > 1
6862 && (dirs[ndirs].prefix == -1
6863 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6864 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6865 dirs[ndirs].prefix = j;
6867 ++ndirs;
6870 /* Now to the actual work. We have to find a subset of the directories which
6871 allow expressing the file name using references to the directory table
6872 with the least amount of characters. We do not do an exhaustive search
6873 where we would have to check out every combination of every single
6874 possible prefix. Instead we use a heuristic which provides nearly optimal
6875 results in most cases and never is much off. */
6876 saved = (int *) alloca (ndirs * sizeof (int));
6877 savehere = (int *) alloca (ndirs * sizeof (int));
6879 memset (saved, '\0', ndirs * sizeof (saved[0]));
6880 for (i = 0; i < ndirs; i++)
6882 int j;
6883 int total;
6885 /* We can always save some space for the current directory. But this
6886 does not mean it will be enough to justify adding the directory. */
6887 savehere[i] = dirs[i].length;
6888 total = (savehere[i] - saved[i]) * dirs[i].count;
6890 for (j = i + 1; j < ndirs; j++)
6892 savehere[j] = 0;
6893 if (saved[j] < dirs[i].length)
6895 /* Determine whether the dirs[i] path is a prefix of the
6896 dirs[j] path. */
6897 int k;
6899 k = dirs[j].prefix;
6900 while (k != -1 && k != i)
6901 k = dirs[k].prefix;
6903 if (k == i)
6905 /* Yes it is. We can possibly safe some memory but
6906 writing the filenames in dirs[j] relative to
6907 dirs[i]. */
6908 savehere[j] = dirs[i].length;
6909 total += (savehere[j] - saved[j]) * dirs[j].count;
6914 /* Check whether we can safe enough to justify adding the dirs[i]
6915 directory. */
6916 if (total > dirs[i].length + 1)
6918 /* It's worthwhile adding. */
6919 for (j = i; j < ndirs; j++)
6920 if (savehere[j] > 0)
6922 /* Remember how much we saved for this directory so far. */
6923 saved[j] = savehere[j];
6925 /* Remember the prefix directory. */
6926 dirs[j].dir_idx = i;
6931 /* We have to emit them in the order they appear in the file_table array
6932 since the index is used in the debug info generation. To do this
6933 efficiently we generate a back-mapping of the indices first. */
6934 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6935 for (i = 1; i < (int) file_table.in_use; i++)
6937 backmap[files[i].file_idx] = i;
6939 /* Mark this directory as used. */
6940 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6943 /* That was it. We are ready to emit the information. First emit the
6944 directory name table. We have to make sure the first actually emitted
6945 directory name has index one; zero is reserved for the current working
6946 directory. Make sure we do not confuse these indices with the one for the
6947 constructed table (even though most of the time they are identical). */
6948 idx = 1;
6949 idx_offset = dirs[0].length > 0 ? 1 : 0;
6950 for (i = 1 - idx_offset; i < ndirs; i++)
6951 if (dirs[i].used != 0)
6953 dirs[i].used = idx++;
6954 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6955 "Directory Entry: 0x%x", dirs[i].used);
6958 dw2_asm_output_data (1, 0, "End directory table");
6960 /* Correct the index for the current working directory entry if it
6961 exists. */
6962 if (idx_offset == 0)
6963 dirs[0].used = 0;
6965 /* Now write all the file names. */
6966 for (i = 1; i < (int) file_table.in_use; i++)
6968 int file_idx = backmap[i];
6969 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6971 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6972 "File Entry: 0x%x", i);
6974 /* Include directory index. */
6975 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6977 /* Modification time. */
6978 dw2_asm_output_data_uleb128 (0, NULL);
6980 /* File length in bytes. */
6981 dw2_asm_output_data_uleb128 (0, NULL);
6984 dw2_asm_output_data (1, 0, "End file name table");
6988 /* Output the source line number correspondence information. This
6989 information goes into the .debug_line section. */
6991 static void
6992 output_line_info ()
6994 char l1[20], l2[20], p1[20], p2[20];
6995 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6996 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6997 unsigned opc;
6998 unsigned n_op_args;
6999 unsigned long lt_index;
7000 unsigned long current_line;
7001 long line_offset;
7002 long line_delta;
7003 unsigned long current_file;
7004 unsigned long function;
7006 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
7007 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
7008 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
7009 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
7011 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
7012 "Length of Source Line Info");
7013 ASM_OUTPUT_LABEL (asm_out_file, l1);
7015 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7016 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
7017 ASM_OUTPUT_LABEL (asm_out_file, p1);
7019 /* Define the architecture-dependent minimum instruction length (in
7020 bytes). In this implementation of DWARF, this field is used for
7021 information purposes only. Since GCC generates assembly language,
7022 we have no a priori knowledge of how many instruction bytes are
7023 generated for each source line, and therefore can use only the
7024 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7025 commands. Accordingly, we fix this as `1', which is "correct
7026 enough" for all architectures, and don't let the target override. */
7027 dw2_asm_output_data (1, 1,
7028 "Minimum Instruction Length");
7030 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
7031 "Default is_stmt_start flag");
7032 dw2_asm_output_data (1, DWARF_LINE_BASE,
7033 "Line Base Value (Special Opcodes)");
7034 dw2_asm_output_data (1, DWARF_LINE_RANGE,
7035 "Line Range Value (Special Opcodes)");
7036 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
7037 "Special Opcode Base");
7039 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
7041 switch (opc)
7043 case DW_LNS_advance_pc:
7044 case DW_LNS_advance_line:
7045 case DW_LNS_set_file:
7046 case DW_LNS_set_column:
7047 case DW_LNS_fixed_advance_pc:
7048 n_op_args = 1;
7049 break;
7050 default:
7051 n_op_args = 0;
7052 break;
7055 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
7056 opc, n_op_args);
7059 /* Write out the information about the files we use. */
7060 output_file_names ();
7061 ASM_OUTPUT_LABEL (asm_out_file, p2);
7063 /* We used to set the address register to the first location in the text
7064 section here, but that didn't accomplish anything since we already
7065 have a line note for the opening brace of the first function. */
7067 /* Generate the line number to PC correspondence table, encoded as
7068 a series of state machine operations. */
7069 current_file = 1;
7070 current_line = 1;
7071 strcpy (prev_line_label, text_section_label);
7072 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7074 dw_line_info_ref line_info = &line_info_table[lt_index];
7076 #if 0
7077 /* Disable this optimization for now; GDB wants to see two line notes
7078 at the beginning of a function so it can find the end of the
7079 prologue. */
7081 /* Don't emit anything for redundant notes. Just updating the
7082 address doesn't accomplish anything, because we already assume
7083 that anything after the last address is this line. */
7084 if (line_info->dw_line_num == current_line
7085 && line_info->dw_file_num == current_file)
7086 continue;
7087 #endif
7089 /* Emit debug info for the address of the current line.
7091 Unfortunately, we have little choice here currently, and must always
7092 use the most general form. GCC does not know the address delta
7093 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7094 attributes which will give an upper bound on the address range. We
7095 could perhaps use length attributes to determine when it is safe to
7096 use DW_LNS_fixed_advance_pc. */
7098 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7099 if (0)
7101 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7102 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7103 "DW_LNS_fixed_advance_pc");
7104 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7106 else
7108 /* This can handle any delta. This takes
7109 4+DWARF2_ADDR_SIZE bytes. */
7110 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7111 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7112 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7113 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7116 strcpy (prev_line_label, line_label);
7118 /* Emit debug info for the source file of the current line, if
7119 different from the previous line. */
7120 if (line_info->dw_file_num != current_file)
7122 current_file = line_info->dw_file_num;
7123 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7124 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7125 file_table.table[current_file]);
7128 /* Emit debug info for the current line number, choosing the encoding
7129 that uses the least amount of space. */
7130 if (line_info->dw_line_num != current_line)
7132 line_offset = line_info->dw_line_num - current_line;
7133 line_delta = line_offset - DWARF_LINE_BASE;
7134 current_line = line_info->dw_line_num;
7135 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7136 /* This can handle deltas from -10 to 234, using the current
7137 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7138 takes 1 byte. */
7139 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7140 "line %lu", current_line);
7141 else
7143 /* This can handle any delta. This takes at least 4 bytes,
7144 depending on the value being encoded. */
7145 dw2_asm_output_data (1, DW_LNS_advance_line,
7146 "advance to line %lu", current_line);
7147 dw2_asm_output_data_sleb128 (line_offset, NULL);
7148 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7151 else
7152 /* We still need to start a new row, so output a copy insn. */
7153 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7156 /* Emit debug info for the address of the end of the function. */
7157 if (0)
7159 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7160 "DW_LNS_fixed_advance_pc");
7161 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7163 else
7165 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7166 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7167 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7168 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7171 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7172 dw2_asm_output_data_uleb128 (1, NULL);
7173 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7175 function = 0;
7176 current_file = 1;
7177 current_line = 1;
7178 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7180 dw_separate_line_info_ref line_info
7181 = &separate_line_info_table[lt_index];
7183 #if 0
7184 /* Don't emit anything for redundant notes. */
7185 if (line_info->dw_line_num == current_line
7186 && line_info->dw_file_num == current_file
7187 && line_info->function == function)
7188 goto cont;
7189 #endif
7191 /* Emit debug info for the address of the current line. If this is
7192 a new function, or the first line of a function, then we need
7193 to handle it differently. */
7194 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7195 lt_index);
7196 if (function != line_info->function)
7198 function = line_info->function;
7200 /* Set the address register to the first line in the function */
7201 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7202 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7203 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7204 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7206 else
7208 /* ??? See the DW_LNS_advance_pc comment above. */
7209 if (0)
7211 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7212 "DW_LNS_fixed_advance_pc");
7213 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7215 else
7217 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7218 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7219 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7220 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7224 strcpy (prev_line_label, line_label);
7226 /* Emit debug info for the source file of the current line, if
7227 different from the previous line. */
7228 if (line_info->dw_file_num != current_file)
7230 current_file = line_info->dw_file_num;
7231 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7232 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7233 file_table.table[current_file]);
7236 /* Emit debug info for the current line number, choosing the encoding
7237 that uses the least amount of space. */
7238 if (line_info->dw_line_num != current_line)
7240 line_offset = line_info->dw_line_num - current_line;
7241 line_delta = line_offset - DWARF_LINE_BASE;
7242 current_line = line_info->dw_line_num;
7243 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7244 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7245 "line %lu", current_line);
7246 else
7248 dw2_asm_output_data (1, DW_LNS_advance_line,
7249 "advance to line %lu", current_line);
7250 dw2_asm_output_data_sleb128 (line_offset, NULL);
7251 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7254 else
7255 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7257 #if 0
7258 cont:
7259 #endif
7261 lt_index++;
7263 /* If we're done with a function, end its sequence. */
7264 if (lt_index == separate_line_info_table_in_use
7265 || separate_line_info_table[lt_index].function != function)
7267 current_file = 1;
7268 current_line = 1;
7270 /* Emit debug info for the address of the end of the function. */
7271 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7272 if (0)
7274 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7275 "DW_LNS_fixed_advance_pc");
7276 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7278 else
7280 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7281 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7282 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7283 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7286 /* Output the marker for the end of this sequence. */
7287 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7288 dw2_asm_output_data_uleb128 (1, NULL);
7289 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7293 /* Output the marker for the end of the line number info. */
7294 ASM_OUTPUT_LABEL (asm_out_file, l2);
7297 /* Given a pointer to a tree node for some base type, return a pointer to
7298 a DIE that describes the given type.
7300 This routine must only be called for GCC type nodes that correspond to
7301 Dwarf base (fundamental) types. */
7303 static dw_die_ref
7304 base_type_die (type)
7305 tree type;
7307 dw_die_ref base_type_result;
7308 const char *type_name;
7309 enum dwarf_type encoding;
7310 tree name = TYPE_NAME (type);
7312 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
7313 return 0;
7315 if (name)
7317 if (TREE_CODE (name) == TYPE_DECL)
7318 name = DECL_NAME (name);
7320 type_name = IDENTIFIER_POINTER (name);
7322 else
7323 type_name = "__unknown__";
7325 switch (TREE_CODE (type))
7327 case INTEGER_TYPE:
7328 /* Carefully distinguish the C character types, without messing
7329 up if the language is not C. Note that we check only for the names
7330 that contain spaces; other names might occur by coincidence in other
7331 languages. */
7332 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7333 && (type == char_type_node
7334 || ! strcmp (type_name, "signed char")
7335 || ! strcmp (type_name, "unsigned char"))))
7337 if (TREE_UNSIGNED (type))
7338 encoding = DW_ATE_unsigned;
7339 else
7340 encoding = DW_ATE_signed;
7341 break;
7343 /* else fall through. */
7345 case CHAR_TYPE:
7346 /* GNU Pascal/Ada CHAR type. Not used in C. */
7347 if (TREE_UNSIGNED (type))
7348 encoding = DW_ATE_unsigned_char;
7349 else
7350 encoding = DW_ATE_signed_char;
7351 break;
7353 case REAL_TYPE:
7354 encoding = DW_ATE_float;
7355 break;
7357 /* Dwarf2 doesn't know anything about complex ints, so use
7358 a user defined type for it. */
7359 case COMPLEX_TYPE:
7360 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7361 encoding = DW_ATE_complex_float;
7362 else
7363 encoding = DW_ATE_lo_user;
7364 break;
7366 case BOOLEAN_TYPE:
7367 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7368 encoding = DW_ATE_boolean;
7369 break;
7371 default:
7372 /* No other TREE_CODEs are Dwarf fundamental types. */
7373 abort ();
7376 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
7377 if (demangle_name_func)
7378 type_name = (*demangle_name_func) (type_name);
7380 add_AT_string (base_type_result, DW_AT_name, type_name);
7381 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7382 int_size_in_bytes (type));
7383 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7385 return base_type_result;
7388 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7389 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7390 a given type is generally the same as the given type, except that if the
7391 given type is a pointer or reference type, then the root type of the given
7392 type is the root type of the "basis" type for the pointer or reference
7393 type. (This definition of the "root" type is recursive.) Also, the root
7394 type of a `const' qualified type or a `volatile' qualified type is the
7395 root type of the given type without the qualifiers. */
7397 static tree
7398 root_type (type)
7399 tree type;
7401 if (TREE_CODE (type) == ERROR_MARK)
7402 return error_mark_node;
7404 switch (TREE_CODE (type))
7406 case ERROR_MARK:
7407 return error_mark_node;
7409 case POINTER_TYPE:
7410 case REFERENCE_TYPE:
7411 return type_main_variant (root_type (TREE_TYPE (type)));
7413 default:
7414 return type_main_variant (type);
7418 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7419 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7421 static inline int
7422 is_base_type (type)
7423 tree type;
7425 switch (TREE_CODE (type))
7427 case ERROR_MARK:
7428 case VOID_TYPE:
7429 case INTEGER_TYPE:
7430 case REAL_TYPE:
7431 case COMPLEX_TYPE:
7432 case BOOLEAN_TYPE:
7433 case CHAR_TYPE:
7434 return 1;
7436 case SET_TYPE:
7437 case ARRAY_TYPE:
7438 case RECORD_TYPE:
7439 case UNION_TYPE:
7440 case QUAL_UNION_TYPE:
7441 case ENUMERAL_TYPE:
7442 case FUNCTION_TYPE:
7443 case METHOD_TYPE:
7444 case POINTER_TYPE:
7445 case REFERENCE_TYPE:
7446 case FILE_TYPE:
7447 case OFFSET_TYPE:
7448 case LANG_TYPE:
7449 case VECTOR_TYPE:
7450 return 0;
7452 default:
7453 abort ();
7456 return 0;
7459 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7460 entry that chains various modifiers in front of the given type. */
7462 static dw_die_ref
7463 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7464 tree type;
7465 int is_const_type;
7466 int is_volatile_type;
7467 dw_die_ref context_die;
7469 enum tree_code code = TREE_CODE (type);
7470 dw_die_ref mod_type_die = NULL;
7471 dw_die_ref sub_die = NULL;
7472 tree item_type = NULL;
7474 if (code != ERROR_MARK)
7476 tree qualified_type;
7478 /* See if we already have the appropriately qualified variant of
7479 this type. */
7480 qualified_type
7481 = get_qualified_type (type,
7482 ((is_const_type ? TYPE_QUAL_CONST : 0)
7483 | (is_volatile_type
7484 ? TYPE_QUAL_VOLATILE : 0)));
7486 /* If we do, then we can just use its DIE, if it exists. */
7487 if (qualified_type)
7489 mod_type_die = lookup_type_die (qualified_type);
7490 if (mod_type_die)
7491 return mod_type_die;
7494 /* Handle C typedef types. */
7495 if (qualified_type && TYPE_NAME (qualified_type)
7496 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7497 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7499 tree type_name = TYPE_NAME (qualified_type);
7500 tree dtype = TREE_TYPE (type_name);
7502 if (qualified_type == dtype)
7504 /* For a named type, use the typedef. */
7505 gen_type_die (qualified_type, context_die);
7506 mod_type_die = lookup_type_die (qualified_type);
7508 else if (is_const_type < TYPE_READONLY (dtype)
7509 || is_volatile_type < TYPE_VOLATILE (dtype))
7510 /* cv-unqualified version of named type. Just use the unnamed
7511 type to which it refers. */
7512 mod_type_die
7513 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7514 is_const_type, is_volatile_type,
7515 context_die);
7517 /* Else cv-qualified version of named type; fall through. */
7520 if (mod_type_die)
7521 /* OK. */
7523 else if (is_const_type)
7525 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
7526 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7528 else if (is_volatile_type)
7530 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
7531 sub_die = modified_type_die (type, 0, 0, context_die);
7533 else if (code == POINTER_TYPE)
7535 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
7536 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7537 #if 0
7538 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7539 #endif
7540 item_type = TREE_TYPE (type);
7542 else if (code == REFERENCE_TYPE)
7544 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
7545 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7546 #if 0
7547 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7548 #endif
7549 item_type = TREE_TYPE (type);
7551 else if (is_base_type (type))
7552 mod_type_die = base_type_die (type);
7553 else
7555 gen_type_die (type, context_die);
7557 /* We have to get the type_main_variant here (and pass that to the
7558 `lookup_type_die' routine) because the ..._TYPE node we have
7559 might simply be a *copy* of some original type node (where the
7560 copy was created to help us keep track of typedef names) and
7561 that copy might have a different TYPE_UID from the original
7562 ..._TYPE node. */
7563 if (TREE_CODE (type) != VECTOR_TYPE)
7564 mod_type_die = lookup_type_die (type_main_variant (type));
7565 else
7566 /* Vectors have the debugging information in the type,
7567 not the main variant. */
7568 mod_type_die = lookup_type_die (type);
7569 if (mod_type_die == NULL)
7570 abort ();
7573 /* We want to equate the qualified type to the die below. */
7574 type = qualified_type;
7577 if (type)
7578 equate_type_number_to_die (type, mod_type_die);
7579 if (item_type)
7580 /* We must do this after the equate_type_number_to_die call, in case
7581 this is a recursive type. This ensures that the modified_type_die
7582 recursion will terminate even if the type is recursive. Recursive
7583 types are possible in Ada. */
7584 sub_die = modified_type_die (item_type,
7585 TYPE_READONLY (item_type),
7586 TYPE_VOLATILE (item_type),
7587 context_die);
7589 if (sub_die != NULL)
7590 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7592 return mod_type_die;
7595 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7596 an enumerated type. */
7598 static inline int
7599 type_is_enum (type)
7600 tree type;
7602 return TREE_CODE (type) == ENUMERAL_TYPE;
7605 /* Return the register number described by a given RTL node. */
7607 static unsigned int
7608 reg_number (rtl)
7609 rtx rtl;
7611 unsigned regno = REGNO (rtl);
7613 if (regno >= FIRST_PSEUDO_REGISTER)
7614 abort ();
7616 return DBX_REGISTER_NUMBER (regno);
7619 /* Return a location descriptor that designates a machine register or
7620 zero if there is no such. */
7622 static dw_loc_descr_ref
7623 reg_loc_descriptor (rtl)
7624 rtx rtl;
7626 dw_loc_descr_ref loc_result = NULL;
7627 unsigned reg;
7629 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
7630 return 0;
7632 reg = reg_number (rtl);
7633 if (reg <= 31)
7634 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7635 else
7636 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7638 return loc_result;
7641 /* Return a location descriptor that designates a constant. */
7643 static dw_loc_descr_ref
7644 int_loc_descriptor (i)
7645 HOST_WIDE_INT i;
7647 enum dwarf_location_atom op;
7649 /* Pick the smallest representation of a constant, rather than just
7650 defaulting to the LEB encoding. */
7651 if (i >= 0)
7653 if (i <= 31)
7654 op = DW_OP_lit0 + i;
7655 else if (i <= 0xff)
7656 op = DW_OP_const1u;
7657 else if (i <= 0xffff)
7658 op = DW_OP_const2u;
7659 else if (HOST_BITS_PER_WIDE_INT == 32
7660 || i <= 0xffffffff)
7661 op = DW_OP_const4u;
7662 else
7663 op = DW_OP_constu;
7665 else
7667 if (i >= -0x80)
7668 op = DW_OP_const1s;
7669 else if (i >= -0x8000)
7670 op = DW_OP_const2s;
7671 else if (HOST_BITS_PER_WIDE_INT == 32
7672 || i >= -0x80000000)
7673 op = DW_OP_const4s;
7674 else
7675 op = DW_OP_consts;
7678 return new_loc_descr (op, i, 0);
7681 /* Return a location descriptor that designates a base+offset location. */
7683 static dw_loc_descr_ref
7684 based_loc_descr (reg, offset)
7685 unsigned reg;
7686 long int offset;
7688 dw_loc_descr_ref loc_result;
7689 /* For the "frame base", we use the frame pointer or stack pointer
7690 registers, since the RTL for local variables is relative to one of
7691 them. */
7692 unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7693 ? HARD_FRAME_POINTER_REGNUM
7694 : STACK_POINTER_REGNUM);
7696 if (reg == fp_reg)
7697 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7698 else if (reg <= 31)
7699 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7700 else
7701 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7703 return loc_result;
7706 /* Return true if this RTL expression describes a base+offset calculation. */
7708 static inline int
7709 is_based_loc (rtl)
7710 rtx rtl;
7712 return (GET_CODE (rtl) == PLUS
7713 && ((GET_CODE (XEXP (rtl, 0)) == REG
7714 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
7715 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7718 /* The following routine converts the RTL for a variable or parameter
7719 (resident in memory) into an equivalent Dwarf representation of a
7720 mechanism for getting the address of that same variable onto the top of a
7721 hypothetical "address evaluation" stack.
7723 When creating memory location descriptors, we are effectively transforming
7724 the RTL for a memory-resident object into its Dwarf postfix expression
7725 equivalent. This routine recursively descends an RTL tree, turning
7726 it into Dwarf postfix code as it goes.
7728 MODE is the mode of the memory reference, needed to handle some
7729 autoincrement addressing modes.
7731 Return 0 if we can't represent the location. */
7733 static dw_loc_descr_ref
7734 mem_loc_descriptor (rtl, mode)
7735 rtx rtl;
7736 enum machine_mode mode;
7738 dw_loc_descr_ref mem_loc_result = NULL;
7740 /* Note that for a dynamically sized array, the location we will generate a
7741 description of here will be the lowest numbered location which is
7742 actually within the array. That's *not* necessarily the same as the
7743 zeroth element of the array. */
7745 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7746 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7747 #endif
7749 switch (GET_CODE (rtl))
7751 case POST_INC:
7752 case POST_DEC:
7753 case POST_MODIFY:
7754 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7755 just fall into the SUBREG code. */
7757 /* ... fall through ... */
7759 case SUBREG:
7760 /* The case of a subreg may arise when we have a local (register)
7761 variable or a formal (register) parameter which doesn't quite fill
7762 up an entire register. For now, just assume that it is
7763 legitimate to make the Dwarf info refer to the whole register which
7764 contains the given subreg. */
7765 rtl = SUBREG_REG (rtl);
7767 /* ... fall through ... */
7769 case REG:
7770 /* Whenever a register number forms a part of the description of the
7771 method for calculating the (dynamic) address of a memory resident
7772 object, DWARF rules require the register number be referred to as
7773 a "base register". This distinction is not based in any way upon
7774 what category of register the hardware believes the given register
7775 belongs to. This is strictly DWARF terminology we're dealing with
7776 here. Note that in cases where the location of a memory-resident
7777 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7778 OP_CONST (0)) the actual DWARF location descriptor that we generate
7779 may just be OP_BASEREG (basereg). This may look deceptively like
7780 the object in question was allocated to a register (rather than in
7781 memory) so DWARF consumers need to be aware of the subtle
7782 distinction between OP_REG and OP_BASEREG. */
7783 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
7784 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7785 break;
7787 case MEM:
7788 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7789 if (mem_loc_result != 0)
7790 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7791 break;
7793 case LABEL_REF:
7794 /* Some ports can transform a symbol ref into a label ref, because
7795 the symbol ref is too far away and has to be dumped into a constant
7796 pool. */
7797 case CONST:
7798 case SYMBOL_REF:
7799 /* Alternatively, the symbol in the constant pool might be referenced
7800 by a different symbol. */
7801 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
7803 bool marked;
7804 rtx tmp = get_pool_constant_mark (rtl, &marked);
7806 if (GET_CODE (tmp) == SYMBOL_REF)
7808 rtl = tmp;
7809 if (CONSTANT_POOL_ADDRESS_P (tmp))
7810 get_pool_constant_mark (tmp, &marked);
7811 else
7812 marked = true;
7815 /* If all references to this pool constant were optimized away,
7816 it was not output and thus we can't represent it.
7817 FIXME: might try to use DW_OP_const_value here, though
7818 DW_OP_piece complicates it. */
7819 if (!marked)
7820 return 0;
7823 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7824 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7825 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
7826 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
7827 break;
7829 case PRE_MODIFY:
7830 /* Extract the PLUS expression nested inside and fall into
7831 PLUS code below. */
7832 rtl = XEXP (rtl, 1);
7833 goto plus;
7835 case PRE_INC:
7836 case PRE_DEC:
7837 /* Turn these into a PLUS expression and fall into the PLUS code
7838 below. */
7839 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7840 GEN_INT (GET_CODE (rtl) == PRE_INC
7841 ? GET_MODE_UNIT_SIZE (mode)
7842 : -GET_MODE_UNIT_SIZE (mode)));
7844 /* ... fall through ... */
7846 case PLUS:
7847 plus:
7848 if (is_based_loc (rtl))
7849 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7850 INTVAL (XEXP (rtl, 1)));
7851 else
7853 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7854 if (mem_loc_result == 0)
7855 break;
7857 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7858 && INTVAL (XEXP (rtl, 1)) >= 0)
7859 add_loc_descr (&mem_loc_result,
7860 new_loc_descr (DW_OP_plus_uconst,
7861 INTVAL (XEXP (rtl, 1)), 0));
7862 else
7864 add_loc_descr (&mem_loc_result,
7865 mem_loc_descriptor (XEXP (rtl, 1), mode));
7866 add_loc_descr (&mem_loc_result,
7867 new_loc_descr (DW_OP_plus, 0, 0));
7870 break;
7872 case MULT:
7874 /* If a pseudo-reg is optimized away, it is possible for it to
7875 be replaced with a MEM containing a multiply. */
7876 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
7877 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
7879 if (op0 == 0 || op1 == 0)
7880 break;
7882 mem_loc_result = op0;
7883 add_loc_descr (&mem_loc_result, op1);
7884 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7885 break;
7888 case CONST_INT:
7889 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7890 break;
7892 case ADDRESSOF:
7893 /* If this is a MEM, return its address. Otherwise, we can't
7894 represent this. */
7895 if (GET_CODE (XEXP (rtl, 0)) == MEM)
7896 return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode);
7897 else
7898 return 0;
7900 default:
7901 abort ();
7904 return mem_loc_result;
7907 /* Return a descriptor that describes the concatenation of two locations.
7908 This is typically a complex variable. */
7910 static dw_loc_descr_ref
7911 concat_loc_descriptor (x0, x1)
7912 rtx x0, x1;
7914 dw_loc_descr_ref cc_loc_result = NULL;
7915 dw_loc_descr_ref x0_ref = loc_descriptor (x0);
7916 dw_loc_descr_ref x1_ref = loc_descriptor (x1);
7918 if (x0_ref == 0 || x1_ref == 0)
7919 return 0;
7921 cc_loc_result = x0_ref;
7922 add_loc_descr (&cc_loc_result,
7923 new_loc_descr (DW_OP_piece,
7924 GET_MODE_SIZE (GET_MODE (x0)), 0));
7926 add_loc_descr (&cc_loc_result, x1_ref);
7927 add_loc_descr (&cc_loc_result,
7928 new_loc_descr (DW_OP_piece,
7929 GET_MODE_SIZE (GET_MODE (x1)), 0));
7931 return cc_loc_result;
7934 /* Output a proper Dwarf location descriptor for a variable or parameter
7935 which is either allocated in a register or in a memory location. For a
7936 register, we just generate an OP_REG and the register number. For a
7937 memory location we provide a Dwarf postfix expression describing how to
7938 generate the (dynamic) address of the object onto the address stack.
7940 If we don't know how to describe it, return 0. */
7942 static dw_loc_descr_ref
7943 loc_descriptor (rtl)
7944 rtx rtl;
7946 dw_loc_descr_ref loc_result = NULL;
7948 switch (GET_CODE (rtl))
7950 case SUBREG:
7951 /* The case of a subreg may arise when we have a local (register)
7952 variable or a formal (register) parameter which doesn't quite fill
7953 up an entire register. For now, just assume that it is
7954 legitimate to make the Dwarf info refer to the whole register which
7955 contains the given subreg. */
7956 rtl = SUBREG_REG (rtl);
7958 /* ... fall through ... */
7960 case REG:
7961 loc_result = reg_loc_descriptor (rtl);
7962 break;
7964 case MEM:
7965 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7966 break;
7968 case CONCAT:
7969 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7970 break;
7972 default:
7973 abort ();
7976 return loc_result;
7979 /* Similar, but generate the descriptor from trees instead of rtl. This comes
7980 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
7981 looking for an address. Otherwise, we return a value. If we can't make a
7982 descriptor, return 0. */
7984 static dw_loc_descr_ref
7985 loc_descriptor_from_tree (loc, addressp)
7986 tree loc;
7987 int addressp;
7989 dw_loc_descr_ref ret, ret1;
7990 int indirect_p = 0;
7991 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7992 enum dwarf_location_atom op;
7994 /* ??? Most of the time we do not take proper care for sign/zero
7995 extending the values properly. Hopefully this won't be a real
7996 problem... */
7998 switch (TREE_CODE (loc))
8000 case ERROR_MARK:
8001 return 0;
8003 case WITH_RECORD_EXPR:
8004 case PLACEHOLDER_EXPR:
8005 /* This case involves extracting fields from an object to determine the
8006 position of other fields. We don't try to encode this here. The
8007 only user of this is Ada, which encodes the needed information using
8008 the names of types. */
8009 return 0;
8011 case CALL_EXPR:
8012 return 0;
8014 case ADDR_EXPR:
8015 /* We can support this only if we can look through conversions and
8016 find an INDIRECT_EXPR. */
8017 for (loc = TREE_OPERAND (loc, 0);
8018 TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR
8019 || TREE_CODE (loc) == NON_LVALUE_EXPR
8020 || TREE_CODE (loc) == VIEW_CONVERT_EXPR
8021 || TREE_CODE (loc) == SAVE_EXPR;
8022 loc = TREE_OPERAND (loc, 0))
8025 return (TREE_CODE (loc) == INDIRECT_REF
8026 ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp)
8027 : 0);
8029 case VAR_DECL:
8030 case PARM_DECL:
8032 rtx rtl = rtl_for_decl_location (loc);
8034 if (rtl == NULL_RTX)
8035 return 0;
8036 else if (CONSTANT_P (rtl))
8038 ret = new_loc_descr (DW_OP_addr, 0, 0);
8039 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8040 ret->dw_loc_oprnd1.v.val_addr = rtl;
8041 indirect_p = 1;
8043 else
8045 enum machine_mode mode = GET_MODE (rtl);
8047 if (GET_CODE (rtl) == MEM)
8049 indirect_p = 1;
8050 rtl = XEXP (rtl, 0);
8053 ret = mem_loc_descriptor (rtl, mode);
8056 break;
8058 case INDIRECT_REF:
8059 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8060 indirect_p = 1;
8061 break;
8063 case COMPOUND_EXPR:
8064 return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp);
8066 case NOP_EXPR:
8067 case CONVERT_EXPR:
8068 case NON_LVALUE_EXPR:
8069 case VIEW_CONVERT_EXPR:
8070 case SAVE_EXPR:
8071 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
8073 case COMPONENT_REF:
8074 case BIT_FIELD_REF:
8075 case ARRAY_REF:
8076 case ARRAY_RANGE_REF:
8078 tree obj, offset;
8079 HOST_WIDE_INT bitsize, bitpos, bytepos;
8080 enum machine_mode mode;
8081 int volatilep;
8083 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
8084 &unsignedp, &volatilep);
8086 if (obj == loc)
8087 return 0;
8089 ret = loc_descriptor_from_tree (obj, 1);
8090 if (ret == 0
8091 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
8092 return 0;
8094 if (offset != NULL_TREE)
8096 /* Variable offset. */
8097 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
8098 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8101 if (!addressp)
8102 indirect_p = 1;
8104 bytepos = bitpos / BITS_PER_UNIT;
8105 if (bytepos > 0)
8106 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8107 else if (bytepos < 0)
8109 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8110 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8112 break;
8115 case INTEGER_CST:
8116 if (host_integerp (loc, 0))
8117 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8118 else
8119 return 0;
8120 break;
8122 case TRUTH_AND_EXPR:
8123 case TRUTH_ANDIF_EXPR:
8124 case BIT_AND_EXPR:
8125 op = DW_OP_and;
8126 goto do_binop;
8128 case TRUTH_XOR_EXPR:
8129 case BIT_XOR_EXPR:
8130 op = DW_OP_xor;
8131 goto do_binop;
8133 case TRUTH_OR_EXPR:
8134 case TRUTH_ORIF_EXPR:
8135 case BIT_IOR_EXPR:
8136 op = DW_OP_or;
8137 goto do_binop;
8139 case TRUNC_DIV_EXPR:
8140 op = DW_OP_div;
8141 goto do_binop;
8143 case MINUS_EXPR:
8144 op = DW_OP_minus;
8145 goto do_binop;
8147 case TRUNC_MOD_EXPR:
8148 op = DW_OP_mod;
8149 goto do_binop;
8151 case MULT_EXPR:
8152 op = DW_OP_mul;
8153 goto do_binop;
8155 case LSHIFT_EXPR:
8156 op = DW_OP_shl;
8157 goto do_binop;
8159 case RSHIFT_EXPR:
8160 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8161 goto do_binop;
8163 case PLUS_EXPR:
8164 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8165 && host_integerp (TREE_OPERAND (loc, 1), 0))
8167 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8168 if (ret == 0)
8169 return 0;
8171 add_loc_descr (&ret,
8172 new_loc_descr (DW_OP_plus_uconst,
8173 tree_low_cst (TREE_OPERAND (loc, 1),
8175 0));
8176 break;
8179 op = DW_OP_plus;
8180 goto do_binop;
8182 case LE_EXPR:
8183 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8184 return 0;
8186 op = DW_OP_le;
8187 goto do_binop;
8189 case GE_EXPR:
8190 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8191 return 0;
8193 op = DW_OP_ge;
8194 goto do_binop;
8196 case LT_EXPR:
8197 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8198 return 0;
8200 op = DW_OP_lt;
8201 goto do_binop;
8203 case GT_EXPR:
8204 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8205 return 0;
8207 op = DW_OP_gt;
8208 goto do_binop;
8210 case EQ_EXPR:
8211 op = DW_OP_eq;
8212 goto do_binop;
8214 case NE_EXPR:
8215 op = DW_OP_ne;
8216 goto do_binop;
8218 do_binop:
8219 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8220 ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8221 if (ret == 0 || ret1 == 0)
8222 return 0;
8224 add_loc_descr (&ret, ret1);
8225 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8226 break;
8228 case TRUTH_NOT_EXPR:
8229 case BIT_NOT_EXPR:
8230 op = DW_OP_not;
8231 goto do_unop;
8233 case ABS_EXPR:
8234 op = DW_OP_abs;
8235 goto do_unop;
8237 case NEGATE_EXPR:
8238 op = DW_OP_neg;
8239 goto do_unop;
8241 do_unop:
8242 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8243 if (ret == 0)
8244 return 0;
8246 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8247 break;
8249 case MAX_EXPR:
8250 loc = build (COND_EXPR, TREE_TYPE (loc),
8251 build (LT_EXPR, integer_type_node,
8252 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8253 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8255 /* ... fall through ... */
8257 case COND_EXPR:
8259 dw_loc_descr_ref lhs
8260 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8261 dw_loc_descr_ref rhs
8262 = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8263 dw_loc_descr_ref bra_node, jump_node, tmp;
8265 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8266 if (ret == 0 || lhs == 0 || rhs == 0)
8267 return 0;
8269 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8270 add_loc_descr (&ret, bra_node);
8272 add_loc_descr (&ret, rhs);
8273 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8274 add_loc_descr (&ret, jump_node);
8276 add_loc_descr (&ret, lhs);
8277 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8278 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
8280 /* ??? Need a node to point the skip at. Use a nop. */
8281 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8282 add_loc_descr (&ret, tmp);
8283 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8284 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8286 break;
8288 default:
8289 abort ();
8292 /* Show if we can't fill the request for an address. */
8293 if (addressp && indirect_p == 0)
8294 return 0;
8296 /* If we've got an address and don't want one, dereference. */
8297 if (!addressp && indirect_p > 0)
8299 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
8301 if (size > DWARF2_ADDR_SIZE || size == -1)
8302 return 0;
8303 else if (size == DWARF2_ADDR_SIZE)
8304 op = DW_OP_deref;
8305 else
8306 op = DW_OP_deref_size;
8308 add_loc_descr (&ret, new_loc_descr (op, size, 0));
8311 return ret;
8314 /* Given a value, round it up to the lowest multiple of `boundary'
8315 which is not less than the value itself. */
8317 static inline HOST_WIDE_INT
8318 ceiling (value, boundary)
8319 HOST_WIDE_INT value;
8320 unsigned int boundary;
8322 return (((value + boundary - 1) / boundary) * boundary);
8325 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8326 pointer to the declared type for the relevant field variable, or return
8327 `integer_type_node' if the given node turns out to be an
8328 ERROR_MARK node. */
8330 static inline tree
8331 field_type (decl)
8332 tree decl;
8334 tree type;
8336 if (TREE_CODE (decl) == ERROR_MARK)
8337 return integer_type_node;
8339 type = DECL_BIT_FIELD_TYPE (decl);
8340 if (type == NULL_TREE)
8341 type = TREE_TYPE (decl);
8343 return type;
8346 /* Given a pointer to a tree node, return the alignment in bits for
8347 it, or else return BITS_PER_WORD if the node actually turns out to
8348 be an ERROR_MARK node. */
8350 static inline unsigned
8351 simple_type_align_in_bits (type)
8352 tree type;
8354 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8357 static inline unsigned
8358 simple_decl_align_in_bits (decl)
8359 tree decl;
8361 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8364 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8365 node, return the size in bits for the type if it is a constant, or else
8366 return the alignment for the type if the type's size is not constant, or
8367 else return BITS_PER_WORD if the type actually turns out to be an
8368 ERROR_MARK node. */
8370 static inline unsigned HOST_WIDE_INT
8371 simple_type_size_in_bits (type)
8372 tree type;
8375 if (TREE_CODE (type) == ERROR_MARK)
8376 return BITS_PER_WORD;
8377 else if (TYPE_SIZE (type) == NULL_TREE)
8378 return 0;
8379 else if (host_integerp (TYPE_SIZE (type), 1))
8380 return tree_low_cst (TYPE_SIZE (type), 1);
8381 else
8382 return TYPE_ALIGN (type);
8385 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8386 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8387 or return 0 if we are unable to determine what that offset is, either
8388 because the argument turns out to be a pointer to an ERROR_MARK node, or
8389 because the offset is actually variable. (We can't handle the latter case
8390 just yet). */
8392 static HOST_WIDE_INT
8393 field_byte_offset (decl)
8394 tree decl;
8396 unsigned int type_align_in_bits;
8397 unsigned int decl_align_in_bits;
8398 unsigned HOST_WIDE_INT type_size_in_bits;
8399 HOST_WIDE_INT object_offset_in_bits;
8400 tree type;
8401 tree field_size_tree;
8402 HOST_WIDE_INT bitpos_int;
8403 HOST_WIDE_INT deepest_bitpos;
8404 unsigned HOST_WIDE_INT field_size_in_bits;
8406 if (TREE_CODE (decl) == ERROR_MARK)
8407 return 0;
8408 else if (TREE_CODE (decl) != FIELD_DECL)
8409 abort ();
8411 type = field_type (decl);
8412 field_size_tree = DECL_SIZE (decl);
8414 /* The size could be unspecified if there was an error, or for
8415 a flexible array member. */
8416 if (! field_size_tree)
8417 field_size_tree = bitsize_zero_node;
8419 /* We cannot yet cope with fields whose positions are variable, so
8420 for now, when we see such things, we simply return 0. Someday, we may
8421 be able to handle such cases, but it will be damn difficult. */
8422 if (! host_integerp (bit_position (decl), 0))
8423 return 0;
8425 bitpos_int = int_bit_position (decl);
8427 /* If we don't know the size of the field, pretend it's a full word. */
8428 if (host_integerp (field_size_tree, 1))
8429 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8430 else
8431 field_size_in_bits = BITS_PER_WORD;
8433 type_size_in_bits = simple_type_size_in_bits (type);
8434 type_align_in_bits = simple_type_align_in_bits (type);
8435 decl_align_in_bits = simple_decl_align_in_bits (decl);
8437 /* The GCC front-end doesn't make any attempt to keep track of the starting
8438 bit offset (relative to the start of the containing structure type) of the
8439 hypothetical "containing object" for a bit-field. Thus, when computing
8440 the byte offset value for the start of the "containing object" of a
8441 bit-field, we must deduce this information on our own. This can be rather
8442 tricky to do in some cases. For example, handling the following structure
8443 type definition when compiling for an i386/i486 target (which only aligns
8444 long long's to 32-bit boundaries) can be very tricky:
8446 struct S { int field1; long long field2:31; };
8448 Fortunately, there is a simple rule-of-thumb which can be used in such
8449 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8450 structure shown above. It decides to do this based upon one simple rule
8451 for bit-field allocation. GCC allocates each "containing object" for each
8452 bit-field at the first (i.e. lowest addressed) legitimate alignment
8453 boundary (based upon the required minimum alignment for the declared type
8454 of the field) which it can possibly use, subject to the condition that
8455 there is still enough available space remaining in the containing object
8456 (when allocated at the selected point) to fully accommodate all of the
8457 bits of the bit-field itself.
8459 This simple rule makes it obvious why GCC allocates 8 bytes for each
8460 object of the structure type shown above. When looking for a place to
8461 allocate the "containing object" for `field2', the compiler simply tries
8462 to allocate a 64-bit "containing object" at each successive 32-bit
8463 boundary (starting at zero) until it finds a place to allocate that 64-
8464 bit field such that at least 31 contiguous (and previously unallocated)
8465 bits remain within that selected 64 bit field. (As it turns out, for the
8466 example above, the compiler finds it is OK to allocate the "containing
8467 object" 64-bit field at bit-offset zero within the structure type.)
8469 Here we attempt to work backwards from the limited set of facts we're
8470 given, and we try to deduce from those facts, where GCC must have believed
8471 that the containing object started (within the structure type). The value
8472 we deduce is then used (by the callers of this routine) to generate
8473 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8474 and, in the case of DW_AT_location, regular fields as well). */
8476 /* Figure out the bit-distance from the start of the structure to the
8477 "deepest" bit of the bit-field. */
8478 deepest_bitpos = bitpos_int + field_size_in_bits;
8480 /* This is the tricky part. Use some fancy footwork to deduce where the
8481 lowest addressed bit of the containing object must be. */
8482 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8484 /* Round up to type_align by default. This works best for bitfields. */
8485 object_offset_in_bits += type_align_in_bits - 1;
8486 object_offset_in_bits /= type_align_in_bits;
8487 object_offset_in_bits *= type_align_in_bits;
8489 if (object_offset_in_bits > bitpos_int)
8491 /* Sigh, the decl must be packed. */
8492 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8494 /* Round up to decl_align instead. */
8495 object_offset_in_bits += decl_align_in_bits - 1;
8496 object_offset_in_bits /= decl_align_in_bits;
8497 object_offset_in_bits *= decl_align_in_bits;
8500 return object_offset_in_bits / BITS_PER_UNIT;
8503 /* The following routines define various Dwarf attributes and any data
8504 associated with them. */
8506 /* Add a location description attribute value to a DIE.
8508 This emits location attributes suitable for whole variables and
8509 whole parameters. Note that the location attributes for struct fields are
8510 generated by the routine `data_member_location_attribute' below. */
8512 static void
8513 add_AT_location_description (die, attr_kind, rtl)
8514 dw_die_ref die;
8515 enum dwarf_attribute attr_kind;
8516 rtx rtl;
8518 dw_loc_descr_ref descr = loc_descriptor (rtl);
8520 if (descr != 0)
8521 add_AT_loc (die, attr_kind, descr);
8524 /* Attach the specialized form of location attribute used for data members of
8525 struct and union types. In the special case of a FIELD_DECL node which
8526 represents a bit-field, the "offset" part of this special location
8527 descriptor must indicate the distance in bytes from the lowest-addressed
8528 byte of the containing struct or union type to the lowest-addressed byte of
8529 the "containing object" for the bit-field. (See the `field_byte_offset'
8530 function above).
8532 For any given bit-field, the "containing object" is a hypothetical object
8533 (of some integral or enum type) within which the given bit-field lives. The
8534 type of this hypothetical "containing object" is always the same as the
8535 declared type of the individual bit-field itself (for GCC anyway... the
8536 DWARF spec doesn't actually mandate this). Note that it is the size (in
8537 bytes) of the hypothetical "containing object" which will be given in the
8538 DW_AT_byte_size attribute for this bit-field. (See the
8539 `byte_size_attribute' function below.) It is also used when calculating the
8540 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8541 function below.) */
8543 static void
8544 add_data_member_location_attribute (die, decl)
8545 dw_die_ref die;
8546 tree decl;
8548 long offset;
8549 dw_loc_descr_ref loc_descr = 0;
8551 if (TREE_CODE (decl) == TREE_VEC)
8553 /* We're working on the TAG_inheritance for a base class. */
8554 if (TREE_VIA_VIRTUAL (decl) && is_cxx ())
8556 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8557 aren't at a fixed offset from all (sub)objects of the same
8558 type. We need to extract the appropriate offset from our
8559 vtable. The following dwarf expression means
8561 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8563 This is specific to the V3 ABI, of course. */
8565 dw_loc_descr_ref tmp;
8567 /* Make a copy of the object address. */
8568 tmp = new_loc_descr (DW_OP_dup, 0, 0);
8569 add_loc_descr (&loc_descr, tmp);
8571 /* Extract the vtable address. */
8572 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8573 add_loc_descr (&loc_descr, tmp);
8575 /* Calculate the address of the offset. */
8576 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
8577 if (offset >= 0)
8578 abort ();
8580 tmp = int_loc_descriptor (-offset);
8581 add_loc_descr (&loc_descr, tmp);
8582 tmp = new_loc_descr (DW_OP_minus, 0, 0);
8583 add_loc_descr (&loc_descr, tmp);
8585 /* Extract the offset. */
8586 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8587 add_loc_descr (&loc_descr, tmp);
8589 /* Add it to the object address. */
8590 tmp = new_loc_descr (DW_OP_plus, 0, 0);
8591 add_loc_descr (&loc_descr, tmp);
8593 else
8594 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8596 else
8597 offset = field_byte_offset (decl);
8599 if (! loc_descr)
8601 enum dwarf_location_atom op;
8603 /* The DWARF2 standard says that we should assume that the structure
8604 address is already on the stack, so we can specify a structure field
8605 address by using DW_OP_plus_uconst. */
8607 #ifdef MIPS_DEBUGGING_INFO
8608 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
8609 operator correctly. It works only if we leave the offset on the
8610 stack. */
8611 op = DW_OP_constu;
8612 #else
8613 op = DW_OP_plus_uconst;
8614 #endif
8616 loc_descr = new_loc_descr (op, offset, 0);
8619 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8622 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8623 does not have a "location" either in memory or in a register. These
8624 things can arise in GNU C when a constant is passed as an actual parameter
8625 to an inlined function. They can also arise in C++ where declared
8626 constants do not necessarily get memory "homes". */
8628 static void
8629 add_const_value_attribute (die, rtl)
8630 dw_die_ref die;
8631 rtx rtl;
8633 switch (GET_CODE (rtl))
8635 case CONST_INT:
8636 /* Note that a CONST_INT rtx could represent either an integer
8637 or a floating-point constant. A CONST_INT is used whenever
8638 the constant will fit into a single word. In all such
8639 cases, the original mode of the constant value is wiped
8640 out, and the CONST_INT rtx is assigned VOIDmode. */
8642 HOST_WIDE_INT val = INTVAL (rtl);
8644 /* ??? We really should be using HOST_WIDE_INT throughout. */
8645 if (val < 0 && (long) val == val)
8646 add_AT_int (die, DW_AT_const_value, (long) val);
8647 else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val)
8648 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
8649 else
8651 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
8652 add_AT_long_long (die, DW_AT_const_value,
8653 val >> HOST_BITS_PER_LONG, val);
8654 #else
8655 abort ();
8656 #endif
8659 break;
8661 case CONST_DOUBLE:
8662 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8663 floating-point constant. A CONST_DOUBLE is used whenever the
8664 constant requires more than one word in order to be adequately
8665 represented. We output CONST_DOUBLEs as blocks. */
8667 enum machine_mode mode = GET_MODE (rtl);
8669 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8671 unsigned length = GET_MODE_SIZE (mode) / 4;
8672 long *array = (long *) xmalloc (sizeof (long) * length);
8673 REAL_VALUE_TYPE rv;
8675 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8676 switch (mode)
8678 case SFmode:
8679 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8680 break;
8682 case DFmode:
8683 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8684 break;
8686 case XFmode:
8687 case TFmode:
8688 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8689 break;
8691 default:
8692 abort ();
8695 add_AT_float (die, DW_AT_const_value, length, array);
8697 else
8699 /* ??? We really should be using HOST_WIDE_INT throughout. */
8700 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8701 abort ();
8703 add_AT_long_long (die, DW_AT_const_value,
8704 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8707 break;
8709 case CONST_STRING:
8710 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8711 break;
8713 case SYMBOL_REF:
8714 case LABEL_REF:
8715 case CONST:
8716 add_AT_addr (die, DW_AT_const_value, rtl);
8717 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
8718 break;
8720 case PLUS:
8721 /* In cases where an inlined instance of an inline function is passed
8722 the address of an `auto' variable (which is local to the caller) we
8723 can get a situation where the DECL_RTL of the artificial local
8724 variable (for the inlining) which acts as a stand-in for the
8725 corresponding formal parameter (of the inline function) will look
8726 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8727 exactly a compile-time constant expression, but it isn't the address
8728 of the (artificial) local variable either. Rather, it represents the
8729 *value* which the artificial local variable always has during its
8730 lifetime. We currently have no way to represent such quasi-constant
8731 values in Dwarf, so for now we just punt and generate nothing. */
8732 break;
8734 default:
8735 /* No other kinds of rtx should be possible here. */
8736 abort ();
8741 static rtx
8742 rtl_for_decl_location (decl)
8743 tree decl;
8745 rtx rtl;
8747 /* Here we have to decide where we are going to say the parameter "lives"
8748 (as far as the debugger is concerned). We only have a couple of
8749 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8751 DECL_RTL normally indicates where the parameter lives during most of the
8752 activation of the function. If optimization is enabled however, this
8753 could be either NULL or else a pseudo-reg. Both of those cases indicate
8754 that the parameter doesn't really live anywhere (as far as the code
8755 generation parts of GCC are concerned) during most of the function's
8756 activation. That will happen (for example) if the parameter is never
8757 referenced within the function.
8759 We could just generate a location descriptor here for all non-NULL
8760 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8761 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8762 where DECL_RTL is NULL or is a pseudo-reg.
8764 Note however that we can only get away with using DECL_INCOMING_RTL as
8765 a backup substitute for DECL_RTL in certain limited cases. In cases
8766 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8767 we can be sure that the parameter was passed using the same type as it is
8768 declared to have within the function, and that its DECL_INCOMING_RTL
8769 points us to a place where a value of that type is passed.
8771 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8772 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8773 because in these cases DECL_INCOMING_RTL points us to a value of some
8774 type which is *different* from the type of the parameter itself. Thus,
8775 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8776 such cases, the debugger would end up (for example) trying to fetch a
8777 `float' from a place which actually contains the first part of a
8778 `double'. That would lead to really incorrect and confusing
8779 output at debug-time.
8781 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8782 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8783 are a couple of exceptions however. On little-endian machines we can
8784 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8785 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8786 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8787 when (on a little-endian machine) a non-prototyped function has a
8788 parameter declared to be of type `short' or `char'. In such cases,
8789 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8790 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8791 passed `int' value. If the debugger then uses that address to fetch
8792 a `short' or a `char' (on a little-endian machine) the result will be
8793 the correct data, so we allow for such exceptional cases below.
8795 Note that our goal here is to describe the place where the given formal
8796 parameter lives during most of the function's activation (i.e. between the
8797 end of the prologue and the start of the epilogue). We'll do that as best
8798 as we can. Note however that if the given formal parameter is modified
8799 sometime during the execution of the function, then a stack backtrace (at
8800 debug-time) will show the function as having been called with the *new*
8801 value rather than the value which was originally passed in. This happens
8802 rarely enough that it is not a major problem, but it *is* a problem, and
8803 I'd like to fix it.
8805 A future version of dwarf2out.c may generate two additional attributes for
8806 any given DW_TAG_formal_parameter DIE which will describe the "passed
8807 type" and the "passed location" for the given formal parameter in addition
8808 to the attributes we now generate to indicate the "declared type" and the
8809 "active location" for each parameter. This additional set of attributes
8810 could be used by debuggers for stack backtraces. Separately, note that
8811 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
8812 This happens (for example) for inlined-instances of inline function formal
8813 parameters which are never referenced. This really shouldn't be
8814 happening. All PARM_DECL nodes should get valid non-NULL
8815 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
8816 values for inlined instances of inline function parameters, so when we see
8817 such cases, we are just out-of-luck for the time being (until integrate.c
8818 gets fixed). */
8820 /* Use DECL_RTL as the "location" unless we find something better. */
8821 rtl = DECL_RTL_IF_SET (decl);
8823 /* When generating abstract instances, ignore everything except
8824 constants and symbols living in memory. */
8825 if (! reload_completed)
8827 if (rtl
8828 && (CONSTANT_P (rtl)
8829 || (GET_CODE (rtl) == MEM
8830 && CONSTANT_P (XEXP (rtl, 0)))))
8832 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8833 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
8834 #endif
8835 return rtl;
8837 rtl = NULL_RTX;
8839 else if (TREE_CODE (decl) == PARM_DECL)
8841 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8843 tree declared_type = type_main_variant (TREE_TYPE (decl));
8844 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8846 /* This decl represents a formal parameter which was optimized out.
8847 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8848 all cases where (rtl == NULL_RTX) just below. */
8849 if (declared_type == passed_type)
8850 rtl = DECL_INCOMING_RTL (decl);
8851 else if (! BYTES_BIG_ENDIAN
8852 && TREE_CODE (declared_type) == INTEGER_TYPE
8853 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8854 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8855 rtl = DECL_INCOMING_RTL (decl);
8858 /* If the parm was passed in registers, but lives on the stack, then
8859 make a big endian correction if the mode of the type of the
8860 parameter is not the same as the mode of the rtl. */
8861 /* ??? This is the same series of checks that are made in dbxout.c before
8862 we reach the big endian correction code there. It isn't clear if all
8863 of these checks are necessary here, but keeping them all is the safe
8864 thing to do. */
8865 else if (GET_CODE (rtl) == MEM
8866 && XEXP (rtl, 0) != const0_rtx
8867 && ! CONSTANT_P (XEXP (rtl, 0))
8868 /* Not passed in memory. */
8869 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8870 /* Not passed by invisible reference. */
8871 && (GET_CODE (XEXP (rtl, 0)) != REG
8872 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8873 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8874 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8875 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8876 #endif
8878 /* Big endian correction check. */
8879 && BYTES_BIG_ENDIAN
8880 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8881 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8882 < UNITS_PER_WORD))
8884 int offset = (UNITS_PER_WORD
8885 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8887 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8888 plus_constant (XEXP (rtl, 0), offset));
8892 if (rtl != NULL_RTX)
8894 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8895 #ifdef LEAF_REG_REMAP
8896 if (current_function_uses_only_leaf_regs)
8897 leaf_renumber_regs_insn (rtl);
8898 #endif
8901 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
8902 and will have been substituted directly into all expressions that use it.
8903 C does not have such a concept, but C++ and other languages do. */
8904 else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
8906 /* If a variable is initialized with a string constant without embedded
8907 zeros, build CONST_STRING. */
8908 if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
8909 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
8911 tree arrtype = TREE_TYPE (decl);
8912 tree enttype = TREE_TYPE (arrtype);
8913 tree domain = TYPE_DOMAIN (arrtype);
8914 tree init = DECL_INITIAL (decl);
8915 enum machine_mode mode = TYPE_MODE (enttype);
8917 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
8918 && domain
8919 && integer_zerop (TYPE_MIN_VALUE (domain))
8920 && compare_tree_int (TYPE_MAX_VALUE (domain),
8921 TREE_STRING_LENGTH (init) - 1) == 0
8922 && ((size_t) TREE_STRING_LENGTH (init)
8923 == strlen (TREE_STRING_POINTER (init)) + 1))
8924 rtl = gen_rtx_CONST_STRING (VOIDmode, TREE_STRING_POINTER (init));
8926 /* If the initializer is something that we know will expand into an
8927 immediate RTL constant, expand it now. Expanding anything else
8928 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
8929 else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST
8930 || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST)
8932 rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
8933 EXPAND_INITIALIZER);
8934 /* If expand_expr returns a MEM, it wasn't immediate. */
8935 if (rtl && GET_CODE (rtl) == MEM)
8936 abort ();
8940 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8941 if (rtl)
8942 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
8943 #endif
8944 return rtl;
8947 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8948 data attribute for a variable or a parameter. We generate the
8949 DW_AT_const_value attribute only in those cases where the given variable
8950 or parameter does not have a true "location" either in memory or in a
8951 register. This can happen (for example) when a constant is passed as an
8952 actual argument in a call to an inline function. (It's possible that
8953 these things can crop up in other ways also.) Note that one type of
8954 constant value which can be passed into an inlined function is a constant
8955 pointer. This can happen for example if an actual argument in an inlined
8956 function call evaluates to a compile-time constant address. */
8958 static void
8959 add_location_or_const_value_attribute (die, decl)
8960 dw_die_ref die;
8961 tree decl;
8963 rtx rtl;
8965 if (TREE_CODE (decl) == ERROR_MARK)
8966 return;
8967 else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8968 abort ();
8970 rtl = rtl_for_decl_location (decl);
8971 if (rtl == NULL_RTX)
8972 return;
8974 /* If we don't look past the constant pool, we risk emitting a
8975 reference to a constant pool entry that isn't referenced from
8976 code, and thus is not emitted. */
8977 rtl = avoid_constant_pool_reference (rtl);
8979 switch (GET_CODE (rtl))
8981 case ADDRESSOF:
8982 /* The address of a variable that was optimized away; don't emit
8983 anything. */
8984 break;
8986 case CONST_INT:
8987 case CONST_DOUBLE:
8988 case CONST_STRING:
8989 case SYMBOL_REF:
8990 case LABEL_REF:
8991 case CONST:
8992 case PLUS:
8993 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8994 add_const_value_attribute (die, rtl);
8995 break;
8997 case MEM:
8998 case REG:
8999 case SUBREG:
9000 case CONCAT:
9001 add_AT_location_description (die, DW_AT_location, rtl);
9002 break;
9004 default:
9005 abort ();
9009 /* If we don't have a copy of this variable in memory for some reason (such
9010 as a C++ member constant that doesn't have an out-of-line definition),
9011 we should tell the debugger about the constant value. */
9013 static void
9014 tree_add_const_value_attribute (var_die, decl)
9015 dw_die_ref var_die;
9016 tree decl;
9018 tree init = DECL_INITIAL (decl);
9019 tree type = TREE_TYPE (decl);
9021 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
9022 && initializer_constant_valid_p (init, type) == null_pointer_node)
9023 /* OK */;
9024 else
9025 return;
9027 switch (TREE_CODE (type))
9029 case INTEGER_TYPE:
9030 if (host_integerp (init, 0))
9031 add_AT_unsigned (var_die, DW_AT_const_value,
9032 tree_low_cst (init, 0));
9033 else
9034 add_AT_long_long (var_die, DW_AT_const_value,
9035 TREE_INT_CST_HIGH (init),
9036 TREE_INT_CST_LOW (init));
9037 break;
9039 default:;
9043 /* Generate an DW_AT_name attribute given some string value to be included as
9044 the value of the attribute. */
9046 static inline void
9047 add_name_attribute (die, name_string)
9048 dw_die_ref die;
9049 const char *name_string;
9051 if (name_string != NULL && *name_string != 0)
9053 if (demangle_name_func)
9054 name_string = (*demangle_name_func) (name_string);
9056 add_AT_string (die, DW_AT_name, name_string);
9060 /* Given a tree node describing an array bound (either lower or upper) output
9061 a representation for that bound. */
9063 static void
9064 add_bound_info (subrange_die, bound_attr, bound)
9065 dw_die_ref subrange_die;
9066 enum dwarf_attribute bound_attr;
9067 tree bound;
9069 switch (TREE_CODE (bound))
9071 case ERROR_MARK:
9072 return;
9074 /* All fixed-bounds are represented by INTEGER_CST nodes. */
9075 case INTEGER_CST:
9076 if (! host_integerp (bound, 0)
9077 || (bound_attr == DW_AT_lower_bound
9078 && (((is_c_family () || is_java ()) && integer_zerop (bound))
9079 || (is_fortran () && integer_onep (bound)))))
9080 /* use the default */
9082 else
9083 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
9084 break;
9086 case CONVERT_EXPR:
9087 case NOP_EXPR:
9088 case NON_LVALUE_EXPR:
9089 case VIEW_CONVERT_EXPR:
9090 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
9091 break;
9093 case SAVE_EXPR:
9094 /* If optimization is turned on, the SAVE_EXPRs that describe how to
9095 access the upper bound values may be bogus. If they refer to a
9096 register, they may only describe how to get at these values at the
9097 points in the generated code right after they have just been
9098 computed. Worse yet, in the typical case, the upper bound values
9099 will not even *be* computed in the optimized code (though the
9100 number of elements will), so these SAVE_EXPRs are entirely
9101 bogus. In order to compensate for this fact, we check here to see
9102 if optimization is enabled, and if so, we don't add an attribute
9103 for the (unknown and unknowable) upper bound. This should not
9104 cause too much trouble for existing (stupid?) debuggers because
9105 they have to deal with empty upper bounds location descriptions
9106 anyway in order to be able to deal with incomplete array types.
9107 Of course an intelligent debugger (GDB?) should be able to
9108 comprehend that a missing upper bound specification in an array
9109 type used for a storage class `auto' local array variable
9110 indicates that the upper bound is both unknown (at compile- time)
9111 and unknowable (at run-time) due to optimization.
9113 We assume that a MEM rtx is safe because gcc wouldn't put the
9114 value there unless it was going to be used repeatedly in the
9115 function, i.e. for cleanups. */
9116 if (SAVE_EXPR_RTL (bound)
9117 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
9119 dw_die_ref ctx = lookup_decl_die (current_function_decl);
9120 dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound);
9121 rtx loc = SAVE_EXPR_RTL (bound);
9123 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9124 it references an outer function's frame. */
9125 if (GET_CODE (loc) == MEM)
9127 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
9129 if (XEXP (loc, 0) != new_addr)
9130 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
9133 add_AT_flag (decl_die, DW_AT_artificial, 1);
9134 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9135 add_AT_location_description (decl_die, DW_AT_location, loc);
9136 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9139 /* Else leave out the attribute. */
9140 break;
9142 case VAR_DECL:
9143 case PARM_DECL:
9145 dw_die_ref decl_die = lookup_decl_die (bound);
9147 /* ??? Can this happen, or should the variable have been bound
9148 first? Probably it can, since I imagine that we try to create
9149 the types of parameters in the order in which they exist in
9150 the list, and won't have created a forward reference to a
9151 later parameter. */
9152 if (decl_die != NULL)
9153 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9154 break;
9157 default:
9159 /* Otherwise try to create a stack operation procedure to
9160 evaluate the value of the array bound. */
9162 dw_die_ref ctx, decl_die;
9163 dw_loc_descr_ref loc;
9165 loc = loc_descriptor_from_tree (bound, 0);
9166 if (loc == NULL)
9167 break;
9169 if (current_function_decl == 0)
9170 ctx = comp_unit_die;
9171 else
9172 ctx = lookup_decl_die (current_function_decl);
9174 /* If we weren't able to find a context, it's most likely the case
9175 that we are processing the return type of the function. So
9176 make a SAVE_EXPR to point to it and have the limbo DIE code
9177 find the proper die. The save_expr function doesn't always
9178 make a SAVE_EXPR, so do it ourselves. */
9179 if (ctx == 0)
9180 bound = build (SAVE_EXPR, TREE_TYPE (bound), bound,
9181 current_function_decl, NULL_TREE);
9183 decl_die = new_die (DW_TAG_variable, ctx, bound);
9184 add_AT_flag (decl_die, DW_AT_artificial, 1);
9185 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9186 add_AT_loc (decl_die, DW_AT_location, loc);
9188 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9189 break;
9194 /* Note that the block of subscript information for an array type also
9195 includes information about the element type of type given array type. */
9197 static void
9198 add_subscript_info (type_die, type)
9199 dw_die_ref type_die;
9200 tree type;
9202 #ifndef MIPS_DEBUGGING_INFO
9203 unsigned dimension_number;
9204 #endif
9205 tree lower, upper;
9206 dw_die_ref subrange_die;
9208 /* The GNU compilers represent multidimensional array types as sequences of
9209 one dimensional array types whose element types are themselves array
9210 types. Here we squish that down, so that each multidimensional array
9211 type gets only one array_type DIE in the Dwarf debugging info. The draft
9212 Dwarf specification say that we are allowed to do this kind of
9213 compression in C (because there is no difference between an array or
9214 arrays and a multidimensional array in C) but for other source languages
9215 (e.g. Ada) we probably shouldn't do this. */
9217 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9218 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9219 We work around this by disabling this feature. See also
9220 gen_array_type_die. */
9221 #ifndef MIPS_DEBUGGING_INFO
9222 for (dimension_number = 0;
9223 TREE_CODE (type) == ARRAY_TYPE;
9224 type = TREE_TYPE (type), dimension_number++)
9225 #endif
9227 tree domain = TYPE_DOMAIN (type);
9229 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9230 and (in GNU C only) variable bounds. Handle all three forms
9231 here. */
9232 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
9233 if (domain)
9235 /* We have an array type with specified bounds. */
9236 lower = TYPE_MIN_VALUE (domain);
9237 upper = TYPE_MAX_VALUE (domain);
9239 /* define the index type. */
9240 if (TREE_TYPE (domain))
9242 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9243 TREE_TYPE field. We can't emit debug info for this
9244 because it is an unnamed integral type. */
9245 if (TREE_CODE (domain) == INTEGER_TYPE
9246 && TYPE_NAME (domain) == NULL_TREE
9247 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9248 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
9250 else
9251 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9252 type_die);
9255 /* ??? If upper is NULL, the array has unspecified length,
9256 but it does have a lower bound. This happens with Fortran
9257 dimension arr(N:*)
9258 Since the debugger is definitely going to need to know N
9259 to produce useful results, go ahead and output the lower
9260 bound solo, and hope the debugger can cope. */
9262 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
9263 if (upper)
9264 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
9267 /* Otherwise we have an array type with an unspecified length. The
9268 DWARF-2 spec does not say how to handle this; let's just leave out the
9269 bounds. */
9273 static void
9274 add_byte_size_attribute (die, tree_node)
9275 dw_die_ref die;
9276 tree tree_node;
9278 unsigned size;
9280 switch (TREE_CODE (tree_node))
9282 case ERROR_MARK:
9283 size = 0;
9284 break;
9285 case ENUMERAL_TYPE:
9286 case RECORD_TYPE:
9287 case UNION_TYPE:
9288 case QUAL_UNION_TYPE:
9289 size = int_size_in_bytes (tree_node);
9290 break;
9291 case FIELD_DECL:
9292 /* For a data member of a struct or union, the DW_AT_byte_size is
9293 generally given as the number of bytes normally allocated for an
9294 object of the *declared* type of the member itself. This is true
9295 even for bit-fields. */
9296 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9297 break;
9298 default:
9299 abort ();
9302 /* Note that `size' might be -1 when we get to this point. If it is, that
9303 indicates that the byte size of the entity in question is variable. We
9304 have no good way of expressing this fact in Dwarf at the present time,
9305 so just let the -1 pass on through. */
9306 add_AT_unsigned (die, DW_AT_byte_size, size);
9309 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9310 which specifies the distance in bits from the highest order bit of the
9311 "containing object" for the bit-field to the highest order bit of the
9312 bit-field itself.
9314 For any given bit-field, the "containing object" is a hypothetical object
9315 (of some integral or enum type) within which the given bit-field lives. The
9316 type of this hypothetical "containing object" is always the same as the
9317 declared type of the individual bit-field itself. The determination of the
9318 exact location of the "containing object" for a bit-field is rather
9319 complicated. It's handled by the `field_byte_offset' function (above).
9321 Note that it is the size (in bytes) of the hypothetical "containing object"
9322 which will be given in the DW_AT_byte_size attribute for this bit-field.
9323 (See `byte_size_attribute' above). */
9325 static inline void
9326 add_bit_offset_attribute (die, decl)
9327 dw_die_ref die;
9328 tree decl;
9330 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9331 tree type = DECL_BIT_FIELD_TYPE (decl);
9332 HOST_WIDE_INT bitpos_int;
9333 HOST_WIDE_INT highest_order_object_bit_offset;
9334 HOST_WIDE_INT highest_order_field_bit_offset;
9335 HOST_WIDE_INT unsigned bit_offset;
9337 /* Must be a field and a bit field. */
9338 if (!type
9339 || TREE_CODE (decl) != FIELD_DECL)
9340 abort ();
9342 /* We can't yet handle bit-fields whose offsets are variable, so if we
9343 encounter such things, just return without generating any attribute
9344 whatsoever. Likewise for variable or too large size. */
9345 if (! host_integerp (bit_position (decl), 0)
9346 || ! host_integerp (DECL_SIZE (decl), 1))
9347 return;
9349 bitpos_int = int_bit_position (decl);
9351 /* Note that the bit offset is always the distance (in bits) from the
9352 highest-order bit of the "containing object" to the highest-order bit of
9353 the bit-field itself. Since the "high-order end" of any object or field
9354 is different on big-endian and little-endian machines, the computation
9355 below must take account of these differences. */
9356 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9357 highest_order_field_bit_offset = bitpos_int;
9359 if (! BYTES_BIG_ENDIAN)
9361 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9362 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9365 bit_offset
9366 = (! BYTES_BIG_ENDIAN
9367 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9368 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9370 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9373 /* For a FIELD_DECL node which represents a bit field, output an attribute
9374 which specifies the length in bits of the given field. */
9376 static inline void
9377 add_bit_size_attribute (die, decl)
9378 dw_die_ref die;
9379 tree decl;
9381 /* Must be a field and a bit field. */
9382 if (TREE_CODE (decl) != FIELD_DECL
9383 || ! DECL_BIT_FIELD_TYPE (decl))
9384 abort ();
9386 if (host_integerp (DECL_SIZE (decl), 1))
9387 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9390 /* If the compiled language is ANSI C, then add a 'prototyped'
9391 attribute, if arg types are given for the parameters of a function. */
9393 static inline void
9394 add_prototyped_attribute (die, func_type)
9395 dw_die_ref die;
9396 tree func_type;
9398 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9399 && TYPE_ARG_TYPES (func_type) != NULL)
9400 add_AT_flag (die, DW_AT_prototyped, 1);
9403 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9404 by looking in either the type declaration or object declaration
9405 equate table. */
9407 static inline void
9408 add_abstract_origin_attribute (die, origin)
9409 dw_die_ref die;
9410 tree origin;
9412 dw_die_ref origin_die = NULL;
9414 if (TREE_CODE (origin) != FUNCTION_DECL)
9416 /* We may have gotten separated from the block for the inlined
9417 function, if we're in an exception handler or some such; make
9418 sure that the abstract function has been written out.
9420 Doing this for nested functions is wrong, however; functions are
9421 distinct units, and our context might not even be inline. */
9422 tree fn = origin;
9424 if (TYPE_P (fn))
9425 fn = TYPE_STUB_DECL (fn);
9427 fn = decl_function_context (fn);
9428 if (fn)
9429 dwarf2out_abstract_function (fn);
9432 if (DECL_P (origin))
9433 origin_die = lookup_decl_die (origin);
9434 else if (TYPE_P (origin))
9435 origin_die = lookup_type_die (origin);
9437 if (origin_die == NULL)
9438 abort ();
9440 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9443 /* We do not currently support the pure_virtual attribute. */
9445 static inline void
9446 add_pure_or_virtual_attribute (die, func_decl)
9447 dw_die_ref die;
9448 tree func_decl;
9450 if (DECL_VINDEX (func_decl))
9452 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9454 if (host_integerp (DECL_VINDEX (func_decl), 0))
9455 add_AT_loc (die, DW_AT_vtable_elem_location,
9456 new_loc_descr (DW_OP_constu,
9457 tree_low_cst (DECL_VINDEX (func_decl), 0),
9458 0));
9460 /* GNU extension: Record what type this method came from originally. */
9461 if (debug_info_level > DINFO_LEVEL_TERSE)
9462 add_AT_die_ref (die, DW_AT_containing_type,
9463 lookup_type_die (DECL_CONTEXT (func_decl)));
9467 /* Add source coordinate attributes for the given decl. */
9469 static void
9470 add_src_coords_attributes (die, decl)
9471 dw_die_ref die;
9472 tree decl;
9474 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9476 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9477 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9480 /* Add an DW_AT_name attribute and source coordinate attribute for the
9481 given decl, but only if it actually has a name. */
9483 static void
9484 add_name_and_src_coords_attributes (die, decl)
9485 dw_die_ref die;
9486 tree decl;
9488 tree decl_name;
9490 decl_name = DECL_NAME (decl);
9491 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9493 add_name_attribute (die, dwarf2_name (decl, 0));
9494 if (! DECL_ARTIFICIAL (decl))
9495 add_src_coords_attributes (die, decl);
9497 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9498 && TREE_PUBLIC (decl)
9499 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9500 && !DECL_ABSTRACT (decl))
9501 add_AT_string (die, DW_AT_MIPS_linkage_name,
9502 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9505 #ifdef VMS_DEBUGGING_INFO
9506 /* Get the function's name, as described by its RTL. This may be different
9507 from the DECL_NAME name used in the source file. */
9508 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
9510 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
9511 XEXP (DECL_RTL (decl), 0));
9512 VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0));
9514 #endif
9517 /* Push a new declaration scope. */
9519 static void
9520 push_decl_scope (scope)
9521 tree scope;
9523 VARRAY_PUSH_TREE (decl_scope_table, scope);
9526 /* Pop a declaration scope. */
9528 static inline void
9529 pop_decl_scope ()
9531 if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0)
9532 abort ();
9534 VARRAY_POP (decl_scope_table);
9537 /* Return the DIE for the scope that immediately contains this type.
9538 Non-named types get global scope. Named types nested in other
9539 types get their containing scope if it's open, or global scope
9540 otherwise. All other types (i.e. function-local named types) get
9541 the current active scope. */
9543 static dw_die_ref
9544 scope_die_for (t, context_die)
9545 tree t;
9546 dw_die_ref context_die;
9548 dw_die_ref scope_die = NULL;
9549 tree containing_scope;
9550 int i;
9552 /* Non-types always go in the current scope. */
9553 if (! TYPE_P (t))
9554 abort ();
9556 containing_scope = TYPE_CONTEXT (t);
9558 /* Ignore namespaces for the moment. */
9559 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9560 containing_scope = NULL_TREE;
9562 /* Ignore function type "scopes" from the C frontend. They mean that
9563 a tagged type is local to a parmlist of a function declarator, but
9564 that isn't useful to DWARF. */
9565 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9566 containing_scope = NULL_TREE;
9568 if (containing_scope == NULL_TREE)
9569 scope_die = comp_unit_die;
9570 else if (TYPE_P (containing_scope))
9572 /* For types, we can just look up the appropriate DIE. But
9573 first we check to see if we're in the middle of emitting it
9574 so we know where the new DIE should go. */
9575 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
9576 if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
9577 break;
9579 if (i < 0)
9581 if (debug_info_level > DINFO_LEVEL_TERSE
9582 && !TREE_ASM_WRITTEN (containing_scope))
9583 abort ();
9585 /* If none of the current dies are suitable, we get file scope. */
9586 scope_die = comp_unit_die;
9588 else
9589 scope_die = lookup_type_die (containing_scope);
9591 else
9592 scope_die = context_die;
9594 return scope_die;
9597 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
9599 static inline int
9600 local_scope_p (context_die)
9601 dw_die_ref context_die;
9603 for (; context_die; context_die = context_die->die_parent)
9604 if (context_die->die_tag == DW_TAG_inlined_subroutine
9605 || context_die->die_tag == DW_TAG_subprogram)
9606 return 1;
9608 return 0;
9611 /* Returns nonzero if CONTEXT_DIE is a class. */
9613 static inline int
9614 class_scope_p (context_die)
9615 dw_die_ref context_die;
9617 return (context_die
9618 && (context_die->die_tag == DW_TAG_structure_type
9619 || context_die->die_tag == DW_TAG_union_type));
9622 /* Many forms of DIEs require a "type description" attribute. This
9623 routine locates the proper "type descriptor" die for the type given
9624 by 'type', and adds an DW_AT_type attribute below the given die. */
9626 static void
9627 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9628 dw_die_ref object_die;
9629 tree type;
9630 int decl_const;
9631 int decl_volatile;
9632 dw_die_ref context_die;
9634 enum tree_code code = TREE_CODE (type);
9635 dw_die_ref type_die = NULL;
9637 /* ??? If this type is an unnamed subrange type of an integral or
9638 floating-point type, use the inner type. This is because we have no
9639 support for unnamed types in base_type_die. This can happen if this is
9640 an Ada subrange type. Correct solution is emit a subrange type die. */
9641 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9642 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9643 type = TREE_TYPE (type), code = TREE_CODE (type);
9645 if (code == ERROR_MARK
9646 /* Handle a special case. For functions whose return type is void, we
9647 generate *no* type attribute. (Note that no object may have type
9648 `void', so this only applies to function return types). */
9649 || code == VOID_TYPE)
9650 return;
9652 type_die = modified_type_die (type,
9653 decl_const || TYPE_READONLY (type),
9654 decl_volatile || TYPE_VOLATILE (type),
9655 context_die);
9657 if (type_die != NULL)
9658 add_AT_die_ref (object_die, DW_AT_type, type_die);
9661 /* Given a tree pointer to a struct, class, union, or enum type node, return
9662 a pointer to the (string) tag name for the given type, or zero if the type
9663 was declared without a tag. */
9665 static const char *
9666 type_tag (type)
9667 tree type;
9669 const char *name = 0;
9671 if (TYPE_NAME (type) != 0)
9673 tree t = 0;
9675 /* Find the IDENTIFIER_NODE for the type name. */
9676 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9677 t = TYPE_NAME (type);
9679 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9680 a TYPE_DECL node, regardless of whether or not a `typedef' was
9681 involved. */
9682 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9683 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9684 t = DECL_NAME (TYPE_NAME (type));
9686 /* Now get the name as a string, or invent one. */
9687 if (t != 0)
9688 name = IDENTIFIER_POINTER (t);
9691 return (name == 0 || *name == '\0') ? 0 : name;
9694 /* Return the type associated with a data member, make a special check
9695 for bit field types. */
9697 static inline tree
9698 member_declared_type (member)
9699 tree member;
9701 return (DECL_BIT_FIELD_TYPE (member)
9702 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
9705 /* Get the decl's label, as described by its RTL. This may be different
9706 from the DECL_NAME name used in the source file. */
9708 #if 0
9709 static const char *
9710 decl_start_label (decl)
9711 tree decl;
9713 rtx x;
9714 const char *fnname;
9716 x = DECL_RTL (decl);
9717 if (GET_CODE (x) != MEM)
9718 abort ();
9720 x = XEXP (x, 0);
9721 if (GET_CODE (x) != SYMBOL_REF)
9722 abort ();
9724 fnname = XSTR (x, 0);
9725 return fnname;
9727 #endif
9729 /* These routines generate the internal representation of the DIE's for
9730 the compilation unit. Debugging information is collected by walking
9731 the declaration trees passed in from dwarf2out_decl(). */
9733 static void
9734 gen_array_type_die (type, context_die)
9735 tree type;
9736 dw_die_ref context_die;
9738 dw_die_ref scope_die = scope_die_for (type, context_die);
9739 dw_die_ref array_die;
9740 tree element_type;
9742 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9743 the inner array type comes before the outer array type. Thus we must
9744 call gen_type_die before we call new_die. See below also. */
9745 #ifdef MIPS_DEBUGGING_INFO
9746 gen_type_die (TREE_TYPE (type), context_die);
9747 #endif
9749 array_die = new_die (DW_TAG_array_type, scope_die, type);
9750 add_name_attribute (array_die, type_tag (type));
9751 equate_type_number_to_die (type, array_die);
9753 if (TREE_CODE (type) == VECTOR_TYPE)
9755 /* The frontend feeds us a representation for the vector as a struct
9756 containing an array. Pull out the array type. */
9757 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
9758 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
9761 #if 0
9762 /* We default the array ordering. SDB will probably do
9763 the right things even if DW_AT_ordering is not present. It's not even
9764 an issue until we start to get into multidimensional arrays anyway. If
9765 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9766 then we'll have to put the DW_AT_ordering attribute back in. (But if
9767 and when we find out that we need to put these in, we will only do so
9768 for multidimensional arrays. */
9769 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9770 #endif
9772 #ifdef MIPS_DEBUGGING_INFO
9773 /* The SGI compilers handle arrays of unknown bound by setting
9774 AT_declaration and not emitting any subrange DIEs. */
9775 if (! TYPE_DOMAIN (type))
9776 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9777 else
9778 #endif
9779 add_subscript_info (array_die, type);
9781 /* Add representation of the type of the elements of this array type. */
9782 element_type = TREE_TYPE (type);
9784 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9785 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9786 We work around this by disabling this feature. See also
9787 add_subscript_info. */
9788 #ifndef MIPS_DEBUGGING_INFO
9789 while (TREE_CODE (element_type) == ARRAY_TYPE)
9790 element_type = TREE_TYPE (element_type);
9792 gen_type_die (element_type, context_die);
9793 #endif
9795 add_type_attribute (array_die, element_type, 0, 0, context_die);
9798 static void
9799 gen_set_type_die (type, context_die)
9800 tree type;
9801 dw_die_ref context_die;
9803 dw_die_ref type_die
9804 = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type);
9806 equate_type_number_to_die (type, type_die);
9807 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9810 #if 0
9811 static void
9812 gen_entry_point_die (decl, context_die)
9813 tree decl;
9814 dw_die_ref context_die;
9816 tree origin = decl_ultimate_origin (decl);
9817 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
9819 if (origin != NULL)
9820 add_abstract_origin_attribute (decl_die, origin);
9821 else
9823 add_name_and_src_coords_attributes (decl_die, decl);
9824 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9825 0, 0, context_die);
9828 if (DECL_ABSTRACT (decl))
9829 equate_decl_number_to_die (decl, decl_die);
9830 else
9831 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9833 #endif
9835 /* Walk through the list of incomplete types again, trying once more to
9836 emit full debugging info for them. */
9838 static void
9839 retry_incomplete_types ()
9841 int i;
9843 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
9844 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
9847 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9849 static void
9850 gen_inlined_enumeration_type_die (type, context_die)
9851 tree type;
9852 dw_die_ref context_die;
9854 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
9856 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9857 be incomplete and such types are not marked. */
9858 add_abstract_origin_attribute (type_die, type);
9861 /* Generate a DIE to represent an inlined instance of a structure type. */
9863 static void
9864 gen_inlined_structure_type_die (type, context_die)
9865 tree type;
9866 dw_die_ref context_die;
9868 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
9870 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9871 be incomplete and such types are not marked. */
9872 add_abstract_origin_attribute (type_die, type);
9875 /* Generate a DIE to represent an inlined instance of a union type. */
9877 static void
9878 gen_inlined_union_type_die (type, context_die)
9879 tree type;
9880 dw_die_ref context_die;
9882 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
9884 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9885 be incomplete and such types are not marked. */
9886 add_abstract_origin_attribute (type_die, type);
9889 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9890 include all of the information about the enumeration values also. Each
9891 enumerated type name/value is listed as a child of the enumerated type
9892 DIE. */
9894 static void
9895 gen_enumeration_type_die (type, context_die)
9896 tree type;
9897 dw_die_ref context_die;
9899 dw_die_ref type_die = lookup_type_die (type);
9901 if (type_die == NULL)
9903 type_die = new_die (DW_TAG_enumeration_type,
9904 scope_die_for (type, context_die), type);
9905 equate_type_number_to_die (type, type_die);
9906 add_name_attribute (type_die, type_tag (type));
9908 else if (! TYPE_SIZE (type))
9909 return;
9910 else
9911 remove_AT (type_die, DW_AT_declaration);
9913 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9914 given enum type is incomplete, do not generate the DW_AT_byte_size
9915 attribute or the DW_AT_element_list attribute. */
9916 if (TYPE_SIZE (type))
9918 tree link;
9920 TREE_ASM_WRITTEN (type) = 1;
9921 add_byte_size_attribute (type_die, type);
9922 if (TYPE_STUB_DECL (type) != NULL_TREE)
9923 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9925 /* If the first reference to this type was as the return type of an
9926 inline function, then it may not have a parent. Fix this now. */
9927 if (type_die->die_parent == NULL)
9928 add_child_die (scope_die_for (type, context_die), type_die);
9930 for (link = TYPE_FIELDS (type);
9931 link != NULL; link = TREE_CHAIN (link))
9933 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
9935 add_name_attribute (enum_die,
9936 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9938 if (host_integerp (TREE_VALUE (link), 0))
9940 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9941 add_AT_int (enum_die, DW_AT_const_value,
9942 tree_low_cst (TREE_VALUE (link), 0));
9943 else
9944 add_AT_unsigned (enum_die, DW_AT_const_value,
9945 tree_low_cst (TREE_VALUE (link), 0));
9949 else
9950 add_AT_flag (type_die, DW_AT_declaration, 1);
9953 /* Generate a DIE to represent either a real live formal parameter decl or to
9954 represent just the type of some formal parameter position in some function
9955 type.
9957 Note that this routine is a bit unusual because its argument may be a
9958 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9959 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9960 node. If it's the former then this function is being called to output a
9961 DIE to represent a formal parameter object (or some inlining thereof). If
9962 it's the latter, then this function is only being called to output a
9963 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9964 argument type of some subprogram type. */
9966 static dw_die_ref
9967 gen_formal_parameter_die (node, context_die)
9968 tree node;
9969 dw_die_ref context_die;
9971 dw_die_ref parm_die
9972 = new_die (DW_TAG_formal_parameter, context_die, node);
9973 tree origin;
9975 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9977 case 'd':
9978 origin = decl_ultimate_origin (node);
9979 if (origin != NULL)
9980 add_abstract_origin_attribute (parm_die, origin);
9981 else
9983 add_name_and_src_coords_attributes (parm_die, node);
9984 add_type_attribute (parm_die, TREE_TYPE (node),
9985 TREE_READONLY (node),
9986 TREE_THIS_VOLATILE (node),
9987 context_die);
9988 if (DECL_ARTIFICIAL (node))
9989 add_AT_flag (parm_die, DW_AT_artificial, 1);
9992 equate_decl_number_to_die (node, parm_die);
9993 if (! DECL_ABSTRACT (node))
9994 add_location_or_const_value_attribute (parm_die, node);
9996 break;
9998 case 't':
9999 /* We were called with some kind of a ..._TYPE node. */
10000 add_type_attribute (parm_die, node, 0, 0, context_die);
10001 break;
10003 default:
10004 abort ();
10007 return parm_die;
10010 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
10011 at the end of an (ANSI prototyped) formal parameters list. */
10013 static void
10014 gen_unspecified_parameters_die (decl_or_type, context_die)
10015 tree decl_or_type;
10016 dw_die_ref context_die;
10018 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
10021 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
10022 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
10023 parameters as specified in some function type specification (except for
10024 those which appear as part of a function *definition*). */
10026 static void
10027 gen_formal_types_die (function_or_method_type, context_die)
10028 tree function_or_method_type;
10029 dw_die_ref context_die;
10031 tree link;
10032 tree formal_type = NULL;
10033 tree first_parm_type;
10034 tree arg;
10036 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
10038 arg = DECL_ARGUMENTS (function_or_method_type);
10039 function_or_method_type = TREE_TYPE (function_or_method_type);
10041 else
10042 arg = NULL_TREE;
10044 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
10046 /* Make our first pass over the list of formal parameter types and output a
10047 DW_TAG_formal_parameter DIE for each one. */
10048 for (link = first_parm_type; link; )
10050 dw_die_ref parm_die;
10052 formal_type = TREE_VALUE (link);
10053 if (formal_type == void_type_node)
10054 break;
10056 /* Output a (nameless) DIE to represent the formal parameter itself. */
10057 parm_die = gen_formal_parameter_die (formal_type, context_die);
10058 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
10059 && link == first_parm_type)
10060 || (arg && DECL_ARTIFICIAL (arg)))
10061 add_AT_flag (parm_die, DW_AT_artificial, 1);
10063 link = TREE_CHAIN (link);
10064 if (arg)
10065 arg = TREE_CHAIN (arg);
10068 /* If this function type has an ellipsis, add a
10069 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10070 if (formal_type != void_type_node)
10071 gen_unspecified_parameters_die (function_or_method_type, context_die);
10073 /* Make our second (and final) pass over the list of formal parameter types
10074 and output DIEs to represent those types (as necessary). */
10075 for (link = TYPE_ARG_TYPES (function_or_method_type);
10076 link && TREE_VALUE (link);
10077 link = TREE_CHAIN (link))
10078 gen_type_die (TREE_VALUE (link), context_die);
10081 /* We want to generate the DIE for TYPE so that we can generate the
10082 die for MEMBER, which has been defined; we will need to refer back
10083 to the member declaration nested within TYPE. If we're trying to
10084 generate minimal debug info for TYPE, processing TYPE won't do the
10085 trick; we need to attach the member declaration by hand. */
10087 static void
10088 gen_type_die_for_member (type, member, context_die)
10089 tree type, member;
10090 dw_die_ref context_die;
10092 gen_type_die (type, context_die);
10094 /* If we're trying to avoid duplicate debug info, we may not have
10095 emitted the member decl for this function. Emit it now. */
10096 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
10097 && ! lookup_decl_die (member))
10099 if (decl_ultimate_origin (member))
10100 abort ();
10102 push_decl_scope (type);
10103 if (TREE_CODE (member) == FUNCTION_DECL)
10104 gen_subprogram_die (member, lookup_type_die (type));
10105 else
10106 gen_variable_die (member, lookup_type_die (type));
10108 pop_decl_scope ();
10112 /* Generate the DWARF2 info for the "abstract" instance of a function which we
10113 may later generate inlined and/or out-of-line instances of. */
10115 static void
10116 dwarf2out_abstract_function (decl)
10117 tree decl;
10119 dw_die_ref old_die;
10120 tree save_fn;
10121 tree context;
10122 int was_abstract = DECL_ABSTRACT (decl);
10124 /* Make sure we have the actual abstract inline, not a clone. */
10125 decl = DECL_ORIGIN (decl);
10127 old_die = lookup_decl_die (decl);
10128 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
10129 /* We've already generated the abstract instance. */
10130 return;
10132 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10133 we don't get confused by DECL_ABSTRACT. */
10134 if (debug_info_level > DINFO_LEVEL_TERSE)
10136 context = decl_class_context (decl);
10137 if (context)
10138 gen_type_die_for_member
10139 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
10142 /* Pretend we've just finished compiling this function. */
10143 save_fn = current_function_decl;
10144 current_function_decl = decl;
10146 set_decl_abstract_flags (decl, 1);
10147 dwarf2out_decl (decl);
10148 if (! was_abstract)
10149 set_decl_abstract_flags (decl, 0);
10151 current_function_decl = save_fn;
10154 /* Generate a DIE to represent a declared function (either file-scope or
10155 block-local). */
10157 static void
10158 gen_subprogram_die (decl, context_die)
10159 tree decl;
10160 dw_die_ref context_die;
10162 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10163 tree origin = decl_ultimate_origin (decl);
10164 dw_die_ref subr_die;
10165 rtx fp_reg;
10166 tree fn_arg_types;
10167 tree outer_scope;
10168 dw_die_ref old_die = lookup_decl_die (decl);
10169 int declaration = (current_function_decl != decl
10170 || class_scope_p (context_die));
10172 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10173 started to generate the abstract instance of an inline, decided to output
10174 its containing class, and proceeded to emit the declaration of the inline
10175 from the member list for the class. If so, DECLARATION takes priority;
10176 we'll get back to the abstract instance when done with the class. */
10178 /* The class-scope declaration DIE must be the primary DIE. */
10179 if (origin && declaration && class_scope_p (context_die))
10181 origin = NULL;
10182 if (old_die)
10183 abort ();
10186 if (origin != NULL)
10188 if (declaration && ! local_scope_p (context_die))
10189 abort ();
10191 /* Fixup die_parent for the abstract instance of a nested
10192 inline function. */
10193 if (old_die && old_die->die_parent == NULL)
10194 add_child_die (context_die, old_die);
10196 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10197 add_abstract_origin_attribute (subr_die, origin);
10199 else if (old_die)
10201 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10203 if (!get_AT_flag (old_die, DW_AT_declaration)
10204 /* We can have a normal definition following an inline one in the
10205 case of redefinition of GNU C extern inlines.
10206 It seems reasonable to use AT_specification in this case. */
10207 && !get_AT_unsigned (old_die, DW_AT_inline))
10209 /* ??? This can happen if there is a bug in the program, for
10210 instance, if it has duplicate function definitions. Ideally,
10211 we should detect this case and ignore it. For now, if we have
10212 already reported an error, any error at all, then assume that
10213 we got here because of an input error, not a dwarf2 bug. */
10214 if (errorcount)
10215 return;
10216 abort ();
10219 /* If the definition comes from the same place as the declaration,
10220 maybe use the old DIE. We always want the DIE for this function
10221 that has the *_pc attributes to be under comp_unit_die so the
10222 debugger can find it. We also need to do this for abstract
10223 instances of inlines, since the spec requires the out-of-line copy
10224 to have the same parent. For local class methods, this doesn't
10225 apply; we just use the old DIE. */
10226 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
10227 && (DECL_ARTIFICIAL (decl)
10228 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10229 && (get_AT_unsigned (old_die, DW_AT_decl_line)
10230 == (unsigned) DECL_SOURCE_LINE (decl)))))
10232 subr_die = old_die;
10234 /* Clear out the declaration attribute and the parm types. */
10235 remove_AT (subr_die, DW_AT_declaration);
10236 remove_children (subr_die);
10238 else
10240 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10241 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
10242 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10243 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10244 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10245 != (unsigned) DECL_SOURCE_LINE (decl))
10246 add_AT_unsigned
10247 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10250 else
10252 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10254 if (TREE_PUBLIC (decl))
10255 add_AT_flag (subr_die, DW_AT_external, 1);
10257 add_name_and_src_coords_attributes (subr_die, decl);
10258 if (debug_info_level > DINFO_LEVEL_TERSE)
10260 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
10261 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
10262 0, 0, context_die);
10265 add_pure_or_virtual_attribute (subr_die, decl);
10266 if (DECL_ARTIFICIAL (decl))
10267 add_AT_flag (subr_die, DW_AT_artificial, 1);
10269 if (TREE_PROTECTED (decl))
10270 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10271 else if (TREE_PRIVATE (decl))
10272 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
10275 if (declaration)
10277 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10279 add_AT_flag (subr_die, DW_AT_declaration, 1);
10281 /* The first time we see a member function, it is in the context of
10282 the class to which it belongs. We make sure of this by emitting
10283 the class first. The next time is the definition, which is
10284 handled above. The two may come from the same source text. */
10285 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10286 equate_decl_number_to_die (decl, subr_die);
10289 else if (DECL_ABSTRACT (decl))
10291 if (DECL_INLINE (decl) && !flag_no_inline)
10293 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10294 inline functions, but not for extern inline functions.
10295 We can't get this completely correct because information
10296 about whether the function was declared inline is not
10297 saved anywhere. */
10298 if (DECL_DEFER_OUTPUT (decl))
10299 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10300 else
10301 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10303 else
10304 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10306 equate_decl_number_to_die (decl, subr_die);
10308 else if (!DECL_EXTERNAL (decl))
10310 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10311 equate_decl_number_to_die (decl, subr_die);
10313 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10314 current_function_funcdef_no);
10315 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10316 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10317 current_function_funcdef_no);
10318 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10320 add_pubname (decl, subr_die);
10321 add_arange (decl, subr_die);
10323 #ifdef MIPS_DEBUGGING_INFO
10324 /* Add a reference to the FDE for this routine. */
10325 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10326 #endif
10328 /* Define the "frame base" location for this routine. We use the
10329 frame pointer or stack pointer registers, since the RTL for local
10330 variables is relative to one of them. */
10331 fp_reg
10332 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10333 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10335 #if 0
10336 /* ??? This fails for nested inline functions, because context_display
10337 is not part of the state saved/restored for inline functions. */
10338 if (current_function_needs_context)
10339 add_AT_location_description (subr_die, DW_AT_static_link,
10340 lookup_static_chain (decl));
10341 #endif
10344 /* Now output descriptions of the arguments for this function. This gets
10345 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10346 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10347 `...' at the end of the formal parameter list. In order to find out if
10348 there was a trailing ellipsis or not, we must instead look at the type
10349 associated with the FUNCTION_DECL. This will be a node of type
10350 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10351 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10352 an ellipsis at the end. */
10354 /* In the case where we are describing a mere function declaration, all we
10355 need to do here (and all we *can* do here) is to describe the *types* of
10356 its formal parameters. */
10357 if (debug_info_level <= DINFO_LEVEL_TERSE)
10359 else if (declaration)
10360 gen_formal_types_die (decl, subr_die);
10361 else
10363 /* Generate DIEs to represent all known formal parameters */
10364 tree arg_decls = DECL_ARGUMENTS (decl);
10365 tree parm;
10367 /* When generating DIEs, generate the unspecified_parameters DIE
10368 instead if we come across the arg "__builtin_va_alist" */
10369 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10370 if (TREE_CODE (parm) == PARM_DECL)
10372 if (DECL_NAME (parm)
10373 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10374 "__builtin_va_alist"))
10375 gen_unspecified_parameters_die (parm, subr_die);
10376 else
10377 gen_decl_die (parm, subr_die);
10380 /* Decide whether we need an unspecified_parameters DIE at the end.
10381 There are 2 more cases to do this for: 1) the ansi ... declaration -
10382 this is detectable when the end of the arg list is not a
10383 void_type_node 2) an unprototyped function declaration (not a
10384 definition). This just means that we have no info about the
10385 parameters at all. */
10386 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10387 if (fn_arg_types != NULL)
10389 /* this is the prototyped case, check for ... */
10390 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10391 gen_unspecified_parameters_die (decl, subr_die);
10393 else if (DECL_INITIAL (decl) == NULL_TREE)
10394 gen_unspecified_parameters_die (decl, subr_die);
10397 /* Output Dwarf info for all of the stuff within the body of the function
10398 (if it has one - it may be just a declaration). */
10399 outer_scope = DECL_INITIAL (decl);
10401 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10402 a function. This BLOCK actually represents the outermost binding contour
10403 for the function, i.e. the contour in which the function's formal
10404 parameters and labels get declared. Curiously, it appears that the front
10405 end doesn't actually put the PARM_DECL nodes for the current function onto
10406 the BLOCK_VARS list for this outer scope, but are strung off of the
10407 DECL_ARGUMENTS list for the function instead.
10409 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10410 the LABEL_DECL nodes for the function however, and we output DWARF info
10411 for those in decls_for_scope. Just within the `outer_scope' there will be
10412 a BLOCK node representing the function's outermost pair of curly braces,
10413 and any blocks used for the base and member initializers of a C++
10414 constructor function. */
10415 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10417 current_function_has_inlines = 0;
10418 decls_for_scope (outer_scope, subr_die, 0);
10420 #if 0 && defined (MIPS_DEBUGGING_INFO)
10421 if (current_function_has_inlines)
10423 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10424 if (! comp_unit_has_inlines)
10426 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10427 comp_unit_has_inlines = 1;
10430 #endif
10434 /* Generate a DIE to represent a declared data object. */
10436 static void
10437 gen_variable_die (decl, context_die)
10438 tree decl;
10439 dw_die_ref context_die;
10441 tree origin = decl_ultimate_origin (decl);
10442 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
10444 dw_die_ref old_die = lookup_decl_die (decl);
10445 int declaration = (DECL_EXTERNAL (decl)
10446 || class_scope_p (context_die));
10448 if (origin != NULL)
10449 add_abstract_origin_attribute (var_die, origin);
10451 /* Loop unrolling can create multiple blocks that refer to the same
10452 static variable, so we must test for the DW_AT_declaration flag.
10454 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10455 copy decls and set the DECL_ABSTRACT flag on them instead of
10456 sharing them.
10458 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10459 else if (old_die && TREE_STATIC (decl)
10460 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10462 /* This is a definition of a C++ class level static. */
10463 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10464 if (DECL_NAME (decl))
10466 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10468 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10469 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10471 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10472 != (unsigned) DECL_SOURCE_LINE (decl))
10474 add_AT_unsigned (var_die, DW_AT_decl_line,
10475 DECL_SOURCE_LINE (decl));
10478 else
10480 add_name_and_src_coords_attributes (var_die, decl);
10481 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
10482 TREE_THIS_VOLATILE (decl), context_die);
10484 if (TREE_PUBLIC (decl))
10485 add_AT_flag (var_die, DW_AT_external, 1);
10487 if (DECL_ARTIFICIAL (decl))
10488 add_AT_flag (var_die, DW_AT_artificial, 1);
10490 if (TREE_PROTECTED (decl))
10491 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10492 else if (TREE_PRIVATE (decl))
10493 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10496 if (declaration)
10497 add_AT_flag (var_die, DW_AT_declaration, 1);
10499 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10500 equate_decl_number_to_die (decl, var_die);
10502 if (! declaration && ! DECL_ABSTRACT (decl))
10504 add_location_or_const_value_attribute (var_die, decl);
10505 add_pubname (decl, var_die);
10507 else
10508 tree_add_const_value_attribute (var_die, decl);
10511 /* Generate a DIE to represent a label identifier. */
10513 static void
10514 gen_label_die (decl, context_die)
10515 tree decl;
10516 dw_die_ref context_die;
10518 tree origin = decl_ultimate_origin (decl);
10519 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
10520 rtx insn;
10521 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10523 if (origin != NULL)
10524 add_abstract_origin_attribute (lbl_die, origin);
10525 else
10526 add_name_and_src_coords_attributes (lbl_die, decl);
10528 if (DECL_ABSTRACT (decl))
10529 equate_decl_number_to_die (decl, lbl_die);
10530 else
10532 insn = DECL_RTL (decl);
10534 /* Deleted labels are programmer specified labels which have been
10535 eliminated because of various optimisations. We still emit them
10536 here so that it is possible to put breakpoints on them. */
10537 if (GET_CODE (insn) == CODE_LABEL
10538 || ((GET_CODE (insn) == NOTE
10539 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10541 /* When optimization is enabled (via -O) some parts of the compiler
10542 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10543 represent source-level labels which were explicitly declared by
10544 the user. This really shouldn't be happening though, so catch
10545 it if it ever does happen. */
10546 if (INSN_DELETED_P (insn))
10547 abort ();
10549 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10550 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10555 /* Generate a DIE for a lexical block. */
10557 static void
10558 gen_lexical_block_die (stmt, context_die, depth)
10559 tree stmt;
10560 dw_die_ref context_die;
10561 int depth;
10563 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
10564 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10566 if (! BLOCK_ABSTRACT (stmt))
10568 if (BLOCK_FRAGMENT_CHAIN (stmt))
10570 tree chain;
10572 add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt));
10574 chain = BLOCK_FRAGMENT_CHAIN (stmt);
10577 add_ranges (chain);
10578 chain = BLOCK_FRAGMENT_CHAIN (chain);
10580 while (chain);
10581 add_ranges (NULL);
10583 else
10585 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10586 BLOCK_NUMBER (stmt));
10587 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10588 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10589 BLOCK_NUMBER (stmt));
10590 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10594 decls_for_scope (stmt, stmt_die, depth);
10597 /* Generate a DIE for an inlined subprogram. */
10599 static void
10600 gen_inlined_subroutine_die (stmt, context_die, depth)
10601 tree stmt;
10602 dw_die_ref context_die;
10603 int depth;
10605 if (! BLOCK_ABSTRACT (stmt))
10607 dw_die_ref subr_die
10608 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
10609 tree decl = block_ultimate_origin (stmt);
10610 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10612 /* Emit info for the abstract instance first, if we haven't yet. */
10613 dwarf2out_abstract_function (decl);
10615 add_abstract_origin_attribute (subr_die, decl);
10616 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10617 BLOCK_NUMBER (stmt));
10618 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10619 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10620 BLOCK_NUMBER (stmt));
10621 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10622 decls_for_scope (stmt, subr_die, depth);
10623 current_function_has_inlines = 1;
10625 else
10626 /* We may get here if we're the outer block of function A that was
10627 inlined into function B that was inlined into function C. When
10628 generating debugging info for C, dwarf2out_abstract_function(B)
10629 would mark all inlined blocks as abstract, including this one.
10630 So, we wouldn't (and shouldn't) expect labels to be generated
10631 for this one. Instead, just emit debugging info for
10632 declarations within the block. This is particularly important
10633 in the case of initializers of arguments passed from B to us:
10634 if they're statement expressions containing declarations, we
10635 wouldn't generate dies for their abstract variables, and then,
10636 when generating dies for the real variables, we'd die (pun
10637 intended :-) */
10638 gen_lexical_block_die (stmt, context_die, depth);
10641 /* Generate a DIE for a field in a record, or structure. */
10643 static void
10644 gen_field_die (decl, context_die)
10645 tree decl;
10646 dw_die_ref context_die;
10648 dw_die_ref decl_die = new_die (DW_TAG_member, context_die, decl);
10650 add_name_and_src_coords_attributes (decl_die, decl);
10651 add_type_attribute (decl_die, member_declared_type (decl),
10652 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10653 context_die);
10655 if (DECL_BIT_FIELD_TYPE (decl))
10657 add_byte_size_attribute (decl_die, decl);
10658 add_bit_size_attribute (decl_die, decl);
10659 add_bit_offset_attribute (decl_die, decl);
10662 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10663 add_data_member_location_attribute (decl_die, decl);
10665 if (DECL_ARTIFICIAL (decl))
10666 add_AT_flag (decl_die, DW_AT_artificial, 1);
10668 if (TREE_PROTECTED (decl))
10669 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10670 else if (TREE_PRIVATE (decl))
10671 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10674 #if 0
10675 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10676 Use modified_type_die instead.
10677 We keep this code here just in case these types of DIEs may be needed to
10678 represent certain things in other languages (e.g. Pascal) someday. */
10680 static void
10681 gen_pointer_type_die (type, context_die)
10682 tree type;
10683 dw_die_ref context_die;
10685 dw_die_ref ptr_die
10686 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
10688 equate_type_number_to_die (type, ptr_die);
10689 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10690 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10693 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10694 Use modified_type_die instead.
10695 We keep this code here just in case these types of DIEs may be needed to
10696 represent certain things in other languages (e.g. Pascal) someday. */
10698 static void
10699 gen_reference_type_die (type, context_die)
10700 tree type;
10701 dw_die_ref context_die;
10703 dw_die_ref ref_die
10704 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
10706 equate_type_number_to_die (type, ref_die);
10707 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10708 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10710 #endif
10712 /* Generate a DIE for a pointer to a member type. */
10714 static void
10715 gen_ptr_to_mbr_type_die (type, context_die)
10716 tree type;
10717 dw_die_ref context_die;
10719 dw_die_ref ptr_die
10720 = new_die (DW_TAG_ptr_to_member_type,
10721 scope_die_for (type, context_die), type);
10723 equate_type_number_to_die (type, ptr_die);
10724 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10725 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10726 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10729 /* Generate the DIE for the compilation unit. */
10731 static dw_die_ref
10732 gen_compile_unit_die (filename)
10733 const char *filename;
10735 dw_die_ref die;
10736 char producer[250];
10737 const char *wd = getpwd ();
10738 const char *language_string = lang_hooks.name;
10739 int language;
10741 die = new_die (DW_TAG_compile_unit, NULL, NULL);
10742 add_name_attribute (die, filename);
10744 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10745 add_AT_string (die, DW_AT_comp_dir, wd);
10747 sprintf (producer, "%s %s", language_string, version_string);
10749 #ifdef MIPS_DEBUGGING_INFO
10750 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10751 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10752 not appear in the producer string, the debugger reaches the conclusion
10753 that the object file is stripped and has no debugging information.
10754 To get the MIPS/SGI debugger to believe that there is debugging
10755 information in the object file, we add a -g to the producer string. */
10756 if (debug_info_level > DINFO_LEVEL_TERSE)
10757 strcat (producer, " -g");
10758 #endif
10760 add_AT_string (die, DW_AT_producer, producer);
10762 if (strcmp (language_string, "GNU C++") == 0)
10763 language = DW_LANG_C_plus_plus;
10764 else if (strcmp (language_string, "GNU Ada") == 0)
10765 language = DW_LANG_Ada83;
10766 else if (strcmp (language_string, "GNU F77") == 0)
10767 language = DW_LANG_Fortran77;
10768 else if (strcmp (language_string, "GNU Pascal") == 0)
10769 language = DW_LANG_Pascal83;
10770 else if (strcmp (language_string, "GNU Java") == 0)
10771 language = DW_LANG_Java;
10772 else
10773 language = DW_LANG_C89;
10775 add_AT_unsigned (die, DW_AT_language, language);
10776 return die;
10779 /* Generate a DIE for a string type. */
10781 static void
10782 gen_string_type_die (type, context_die)
10783 tree type;
10784 dw_die_ref context_die;
10786 dw_die_ref type_die
10787 = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type);
10789 equate_type_number_to_die (type, type_die);
10791 /* ??? Fudge the string length attribute for now.
10792 TODO: add string length info. */
10793 #if 0
10794 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10795 bound_representation (upper_bound, 0, 'u');
10796 #endif
10799 /* Generate the DIE for a base class. */
10801 static void
10802 gen_inheritance_die (binfo, context_die)
10803 tree binfo;
10804 dw_die_ref context_die;
10806 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
10808 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10809 add_data_member_location_attribute (die, binfo);
10811 if (TREE_VIA_VIRTUAL (binfo))
10812 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10814 if (TREE_VIA_PUBLIC (binfo))
10815 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10816 else if (TREE_VIA_PROTECTED (binfo))
10817 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10820 /* Generate a DIE for a class member. */
10822 static void
10823 gen_member_die (type, context_die)
10824 tree type;
10825 dw_die_ref context_die;
10827 tree member;
10828 dw_die_ref child;
10830 /* If this is not an incomplete type, output descriptions of each of its
10831 members. Note that as we output the DIEs necessary to represent the
10832 members of this record or union type, we will also be trying to output
10833 DIEs to represent the *types* of those members. However the `type'
10834 function (above) will specifically avoid generating type DIEs for member
10835 types *within* the list of member DIEs for this (containing) type except
10836 for those types (of members) which are explicitly marked as also being
10837 members of this (containing) type themselves. The g++ front- end can
10838 force any given type to be treated as a member of some other (containing)
10839 type by setting the TYPE_CONTEXT of the given (member) type to point to
10840 the TREE node representing the appropriate (containing) type. */
10842 /* First output info about the base classes. */
10843 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10845 tree bases = TYPE_BINFO_BASETYPES (type);
10846 int n_bases = TREE_VEC_LENGTH (bases);
10847 int i;
10849 for (i = 0; i < n_bases; i++)
10850 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10853 /* Now output info about the data members and type members. */
10854 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10856 /* If we thought we were generating minimal debug info for TYPE
10857 and then changed our minds, some of the member declarations
10858 may have already been defined. Don't define them again, but
10859 do put them in the right order. */
10861 child = lookup_decl_die (member);
10862 if (child)
10863 splice_child_die (context_die, child);
10864 else
10865 gen_decl_die (member, context_die);
10868 /* Now output info about the function members (if any). */
10869 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10871 /* Don't include clones in the member list. */
10872 if (DECL_ABSTRACT_ORIGIN (member))
10873 continue;
10875 child = lookup_decl_die (member);
10876 if (child)
10877 splice_child_die (context_die, child);
10878 else
10879 gen_decl_die (member, context_die);
10883 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10884 is set, we pretend that the type was never defined, so we only get the
10885 member DIEs needed by later specification DIEs. */
10887 static void
10888 gen_struct_or_union_type_die (type, context_die)
10889 tree type;
10890 dw_die_ref context_die;
10892 dw_die_ref type_die = lookup_type_die (type);
10893 dw_die_ref scope_die = 0;
10894 int nested = 0;
10895 int complete = (TYPE_SIZE (type)
10896 && (! TYPE_STUB_DECL (type)
10897 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10899 if (type_die && ! complete)
10900 return;
10902 if (TYPE_CONTEXT (type) != NULL_TREE
10903 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10904 nested = 1;
10906 scope_die = scope_die_for (type, context_die);
10908 if (! type_die || (nested && scope_die == comp_unit_die))
10909 /* First occurrence of type or toplevel definition of nested class. */
10911 dw_die_ref old_die = type_die;
10913 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10914 ? DW_TAG_structure_type : DW_TAG_union_type,
10915 scope_die, type);
10916 equate_type_number_to_die (type, type_die);
10917 if (old_die)
10918 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10919 else
10920 add_name_attribute (type_die, type_tag (type));
10922 else
10923 remove_AT (type_die, DW_AT_declaration);
10925 /* If this type has been completed, then give it a byte_size attribute and
10926 then give a list of members. */
10927 if (complete)
10929 /* Prevent infinite recursion in cases where the type of some member of
10930 this type is expressed in terms of this type itself. */
10931 TREE_ASM_WRITTEN (type) = 1;
10932 add_byte_size_attribute (type_die, type);
10933 if (TYPE_STUB_DECL (type) != NULL_TREE)
10934 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10936 /* If the first reference to this type was as the return type of an
10937 inline function, then it may not have a parent. Fix this now. */
10938 if (type_die->die_parent == NULL)
10939 add_child_die (scope_die, type_die);
10941 push_decl_scope (type);
10942 gen_member_die (type, type_die);
10943 pop_decl_scope ();
10945 /* GNU extension: Record what type our vtable lives in. */
10946 if (TYPE_VFIELD (type))
10948 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10950 gen_type_die (vtype, context_die);
10951 add_AT_die_ref (type_die, DW_AT_containing_type,
10952 lookup_type_die (vtype));
10955 else
10957 add_AT_flag (type_die, DW_AT_declaration, 1);
10959 /* We don't need to do this for function-local types. */
10960 if (TYPE_STUB_DECL (type)
10961 && ! decl_function_context (TYPE_STUB_DECL (type)))
10962 VARRAY_PUSH_TREE (incomplete_types, type);
10966 /* Generate a DIE for a subroutine _type_. */
10968 static void
10969 gen_subroutine_type_die (type, context_die)
10970 tree type;
10971 dw_die_ref context_die;
10973 tree return_type = TREE_TYPE (type);
10974 dw_die_ref subr_die
10975 = new_die (DW_TAG_subroutine_type,
10976 scope_die_for (type, context_die), type);
10978 equate_type_number_to_die (type, subr_die);
10979 add_prototyped_attribute (subr_die, type);
10980 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10981 gen_formal_types_die (type, subr_die);
10984 /* Generate a DIE for a type definition */
10986 static void
10987 gen_typedef_die (decl, context_die)
10988 tree decl;
10989 dw_die_ref context_die;
10991 dw_die_ref type_die;
10992 tree origin;
10994 if (TREE_ASM_WRITTEN (decl))
10995 return;
10997 TREE_ASM_WRITTEN (decl) = 1;
10998 type_die = new_die (DW_TAG_typedef, context_die, decl);
10999 origin = decl_ultimate_origin (decl);
11000 if (origin != NULL)
11001 add_abstract_origin_attribute (type_die, origin);
11002 else
11004 tree type;
11006 add_name_and_src_coords_attributes (type_die, decl);
11007 if (DECL_ORIGINAL_TYPE (decl))
11009 type = DECL_ORIGINAL_TYPE (decl);
11011 if (type == TREE_TYPE (decl))
11012 abort ();
11013 else
11014 equate_type_number_to_die (TREE_TYPE (decl), type_die);
11016 else
11017 type = TREE_TYPE (decl);
11019 add_type_attribute (type_die, type, TREE_READONLY (decl),
11020 TREE_THIS_VOLATILE (decl), context_die);
11023 if (DECL_ABSTRACT (decl))
11024 equate_decl_number_to_die (decl, type_die);
11027 /* Generate a type description DIE. */
11029 static void
11030 gen_type_die (type, context_die)
11031 tree type;
11032 dw_die_ref context_die;
11034 int need_pop;
11036 if (type == NULL_TREE || type == error_mark_node)
11037 return;
11039 /* We are going to output a DIE to represent the unqualified version
11040 of this type (i.e. without any const or volatile qualifiers) so
11041 get the main variant (i.e. the unqualified version) of this type
11042 now. (Vectors are special because the debugging info is in the
11043 cloned type itself). */
11044 if (TREE_CODE (type) != VECTOR_TYPE)
11045 type = type_main_variant (type);
11047 if (TREE_ASM_WRITTEN (type))
11048 return;
11050 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
11051 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
11053 /* Prevent broken recursion; we can't hand off to the same type. */
11054 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) == type)
11055 abort ();
11057 TREE_ASM_WRITTEN (type) = 1;
11058 gen_decl_die (TYPE_NAME (type), context_die);
11059 return;
11062 switch (TREE_CODE (type))
11064 case ERROR_MARK:
11065 break;
11067 case POINTER_TYPE:
11068 case REFERENCE_TYPE:
11069 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
11070 ensures that the gen_type_die recursion will terminate even if the
11071 type is recursive. Recursive types are possible in Ada. */
11072 /* ??? We could perhaps do this for all types before the switch
11073 statement. */
11074 TREE_ASM_WRITTEN (type) = 1;
11076 /* For these types, all that is required is that we output a DIE (or a
11077 set of DIEs) to represent the "basis" type. */
11078 gen_type_die (TREE_TYPE (type), context_die);
11079 break;
11081 case OFFSET_TYPE:
11082 /* This code is used for C++ pointer-to-data-member types.
11083 Output a description of the relevant class type. */
11084 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
11086 /* Output a description of the type of the object pointed to. */
11087 gen_type_die (TREE_TYPE (type), context_die);
11089 /* Now output a DIE to represent this pointer-to-data-member type
11090 itself. */
11091 gen_ptr_to_mbr_type_die (type, context_die);
11092 break;
11094 case SET_TYPE:
11095 gen_type_die (TYPE_DOMAIN (type), context_die);
11096 gen_set_type_die (type, context_die);
11097 break;
11099 case FILE_TYPE:
11100 gen_type_die (TREE_TYPE (type), context_die);
11101 abort (); /* No way to represent these in Dwarf yet! */
11102 break;
11104 case FUNCTION_TYPE:
11105 /* Force out return type (in case it wasn't forced out already). */
11106 gen_type_die (TREE_TYPE (type), context_die);
11107 gen_subroutine_type_die (type, context_die);
11108 break;
11110 case METHOD_TYPE:
11111 /* Force out return type (in case it wasn't forced out already). */
11112 gen_type_die (TREE_TYPE (type), context_die);
11113 gen_subroutine_type_die (type, context_die);
11114 break;
11116 case ARRAY_TYPE:
11117 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
11119 gen_type_die (TREE_TYPE (type), context_die);
11120 gen_string_type_die (type, context_die);
11122 else
11123 gen_array_type_die (type, context_die);
11124 break;
11126 case VECTOR_TYPE:
11127 gen_array_type_die (type, context_die);
11128 break;
11130 case ENUMERAL_TYPE:
11131 case RECORD_TYPE:
11132 case UNION_TYPE:
11133 case QUAL_UNION_TYPE:
11134 /* If this is a nested type whose containing class hasn't been written
11135 out yet, writing it out will cover this one, too. This does not apply
11136 to instantiations of member class templates; they need to be added to
11137 the containing class as they are generated. FIXME: This hurts the
11138 idea of combining type decls from multiple TUs, since we can't predict
11139 what set of template instantiations we'll get. */
11140 if (TYPE_CONTEXT (type)
11141 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
11142 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
11144 gen_type_die (TYPE_CONTEXT (type), context_die);
11146 if (TREE_ASM_WRITTEN (type))
11147 return;
11149 /* If that failed, attach ourselves to the stub. */
11150 push_decl_scope (TYPE_CONTEXT (type));
11151 context_die = lookup_type_die (TYPE_CONTEXT (type));
11152 need_pop = 1;
11154 else
11155 need_pop = 0;
11157 if (TREE_CODE (type) == ENUMERAL_TYPE)
11158 gen_enumeration_type_die (type, context_die);
11159 else
11160 gen_struct_or_union_type_die (type, context_die);
11162 if (need_pop)
11163 pop_decl_scope ();
11165 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11166 it up if it is ever completed. gen_*_type_die will set it for us
11167 when appropriate. */
11168 return;
11170 case VOID_TYPE:
11171 case INTEGER_TYPE:
11172 case REAL_TYPE:
11173 case COMPLEX_TYPE:
11174 case BOOLEAN_TYPE:
11175 case CHAR_TYPE:
11176 /* No DIEs needed for fundamental types. */
11177 break;
11179 case LANG_TYPE:
11180 /* No Dwarf representation currently defined. */
11181 break;
11183 default:
11184 abort ();
11187 TREE_ASM_WRITTEN (type) = 1;
11190 /* Generate a DIE for a tagged type instantiation. */
11192 static void
11193 gen_tagged_type_instantiation_die (type, context_die)
11194 tree type;
11195 dw_die_ref context_die;
11197 if (type == NULL_TREE || type == error_mark_node)
11198 return;
11200 /* We are going to output a DIE to represent the unqualified version of
11201 this type (i.e. without any const or volatile qualifiers) so make sure
11202 that we have the main variant (i.e. the unqualified version) of this
11203 type now. */
11204 if (type != type_main_variant (type))
11205 abort ();
11207 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11208 an instance of an unresolved type. */
11210 switch (TREE_CODE (type))
11212 case ERROR_MARK:
11213 break;
11215 case ENUMERAL_TYPE:
11216 gen_inlined_enumeration_type_die (type, context_die);
11217 break;
11219 case RECORD_TYPE:
11220 gen_inlined_structure_type_die (type, context_die);
11221 break;
11223 case UNION_TYPE:
11224 case QUAL_UNION_TYPE:
11225 gen_inlined_union_type_die (type, context_die);
11226 break;
11228 default:
11229 abort ();
11233 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11234 things which are local to the given block. */
11236 static void
11237 gen_block_die (stmt, context_die, depth)
11238 tree stmt;
11239 dw_die_ref context_die;
11240 int depth;
11242 int must_output_die = 0;
11243 tree origin;
11244 tree decl;
11245 enum tree_code origin_code;
11247 /* Ignore blocks never really used to make RTL. */
11248 if (stmt == NULL_TREE || !TREE_USED (stmt)
11249 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
11250 return;
11252 /* If the block is one fragment of a non-contiguous block, do not
11253 process the variables, since they will have been done by the
11254 origin block. Do process subblocks. */
11255 if (BLOCK_FRAGMENT_ORIGIN (stmt))
11257 tree sub;
11259 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
11260 gen_block_die (sub, context_die, depth + 1);
11262 return;
11265 /* Determine the "ultimate origin" of this block. This block may be an
11266 inlined instance of an inlined instance of inline function, so we have
11267 to trace all of the way back through the origin chain to find out what
11268 sort of node actually served as the original seed for the creation of
11269 the current block. */
11270 origin = block_ultimate_origin (stmt);
11271 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11273 /* Determine if we need to output any Dwarf DIEs at all to represent this
11274 block. */
11275 if (origin_code == FUNCTION_DECL)
11276 /* The outer scopes for inlinings *must* always be represented. We
11277 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11278 must_output_die = 1;
11279 else
11281 /* In the case where the current block represents an inlining of the
11282 "body block" of an inline function, we must *NOT* output any DIE for
11283 this block because we have already output a DIE to represent the whole
11284 inlined function scope and the "body block" of any function doesn't
11285 really represent a different scope according to ANSI C rules. So we
11286 check here to make sure that this block does not represent a "body
11287 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11288 if (! is_body_block (origin ? origin : stmt))
11290 /* Determine if this block directly contains any "significant"
11291 local declarations which we will need to output DIEs for. */
11292 if (debug_info_level > DINFO_LEVEL_TERSE)
11293 /* We are not in terse mode so *any* local declaration counts
11294 as being a "significant" one. */
11295 must_output_die = (BLOCK_VARS (stmt) != NULL);
11296 else
11297 /* We are in terse mode, so only local (nested) function
11298 definitions count as "significant" local declarations. */
11299 for (decl = BLOCK_VARS (stmt);
11300 decl != NULL; decl = TREE_CHAIN (decl))
11301 if (TREE_CODE (decl) == FUNCTION_DECL
11302 && DECL_INITIAL (decl))
11304 must_output_die = 1;
11305 break;
11310 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11311 DIE for any block which contains no significant local declarations at
11312 all. Rather, in such cases we just call `decls_for_scope' so that any
11313 needed Dwarf info for any sub-blocks will get properly generated. Note
11314 that in terse mode, our definition of what constitutes a "significant"
11315 local declaration gets restricted to include only inlined function
11316 instances and local (nested) function definitions. */
11317 if (must_output_die)
11319 if (origin_code == FUNCTION_DECL)
11320 gen_inlined_subroutine_die (stmt, context_die, depth);
11321 else
11322 gen_lexical_block_die (stmt, context_die, depth);
11324 else
11325 decls_for_scope (stmt, context_die, depth);
11328 /* Generate all of the decls declared within a given scope and (recursively)
11329 all of its sub-blocks. */
11331 static void
11332 decls_for_scope (stmt, context_die, depth)
11333 tree stmt;
11334 dw_die_ref context_die;
11335 int depth;
11337 tree decl;
11338 tree subblocks;
11340 /* Ignore blocks never really used to make RTL. */
11341 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11342 return;
11344 /* Output the DIEs to represent all of the data objects and typedefs
11345 declared directly within this block but not within any nested
11346 sub-blocks. Also, nested function and tag DIEs have been
11347 generated with a parent of NULL; fix that up now. */
11348 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
11350 dw_die_ref die;
11352 if (TREE_CODE (decl) == FUNCTION_DECL)
11353 die = lookup_decl_die (decl);
11354 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11355 die = lookup_type_die (TREE_TYPE (decl));
11356 else
11357 die = NULL;
11359 if (die != NULL && die->die_parent == NULL)
11360 add_child_die (context_die, die);
11361 else
11362 gen_decl_die (decl, context_die);
11365 /* Output the DIEs to represent all sub-blocks (and the items declared
11366 therein) of this block. */
11367 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11368 subblocks != NULL;
11369 subblocks = BLOCK_CHAIN (subblocks))
11370 gen_block_die (subblocks, context_die, depth + 1);
11373 /* Is this a typedef we can avoid emitting? */
11375 static inline int
11376 is_redundant_typedef (decl)
11377 tree decl;
11379 if (TYPE_DECL_IS_STUB (decl))
11380 return 1;
11382 if (DECL_ARTIFICIAL (decl)
11383 && DECL_CONTEXT (decl)
11384 && is_tagged_type (DECL_CONTEXT (decl))
11385 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11386 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11387 /* Also ignore the artificial member typedef for the class name. */
11388 return 1;
11390 return 0;
11393 /* Generate Dwarf debug information for a decl described by DECL. */
11395 static void
11396 gen_decl_die (decl, context_die)
11397 tree decl;
11398 dw_die_ref context_die;
11400 tree origin;
11402 if (DECL_P (decl) && DECL_IGNORED_P (decl))
11403 return;
11405 switch (TREE_CODE (decl))
11407 case ERROR_MARK:
11408 break;
11410 case CONST_DECL:
11411 /* The individual enumerators of an enum type get output when we output
11412 the Dwarf representation of the relevant enum type itself. */
11413 break;
11415 case FUNCTION_DECL:
11416 /* Don't output any DIEs to represent mere function declarations,
11417 unless they are class members or explicit block externs. */
11418 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11419 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11420 break;
11422 /* If we're emitting a clone, emit info for the abstract instance. */
11423 if (DECL_ORIGIN (decl) != decl)
11424 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
11426 /* If we're emitting an out-of-line copy of an inline function,
11427 emit info for the abstract instance and set up to refer to it. */
11428 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11429 && ! class_scope_p (context_die)
11430 /* dwarf2out_abstract_function won't emit a die if this is just
11431 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11432 that case, because that works only if we have a die. */
11433 && DECL_INITIAL (decl) != NULL_TREE)
11435 dwarf2out_abstract_function (decl);
11436 set_decl_origin_self (decl);
11439 /* Otherwise we're emitting the primary DIE for this decl. */
11440 else if (debug_info_level > DINFO_LEVEL_TERSE)
11442 /* Before we describe the FUNCTION_DECL itself, make sure that we
11443 have described its return type. */
11444 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11446 /* And its virtual context. */
11447 if (DECL_VINDEX (decl) != NULL_TREE)
11448 gen_type_die (DECL_CONTEXT (decl), context_die);
11450 /* And its containing type. */
11451 origin = decl_class_context (decl);
11452 if (origin != NULL_TREE)
11453 gen_type_die_for_member (origin, decl, context_die);
11456 /* Now output a DIE to represent the function itself. */
11457 gen_subprogram_die (decl, context_die);
11458 break;
11460 case TYPE_DECL:
11461 /* If we are in terse mode, don't generate any DIEs to represent any
11462 actual typedefs. */
11463 if (debug_info_level <= DINFO_LEVEL_TERSE)
11464 break;
11466 /* In the special case of a TYPE_DECL node representing the declaration
11467 of some type tag, if the given TYPE_DECL is marked as having been
11468 instantiated from some other (original) TYPE_DECL node (e.g. one which
11469 was generated within the original definition of an inline function) we
11470 have to generate a special (abbreviated) DW_TAG_structure_type,
11471 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11472 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11474 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11475 break;
11478 if (is_redundant_typedef (decl))
11479 gen_type_die (TREE_TYPE (decl), context_die);
11480 else
11481 /* Output a DIE to represent the typedef itself. */
11482 gen_typedef_die (decl, context_die);
11483 break;
11485 case LABEL_DECL:
11486 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11487 gen_label_die (decl, context_die);
11488 break;
11490 case VAR_DECL:
11491 /* If we are in terse mode, don't generate any DIEs to represent any
11492 variable declarations or definitions. */
11493 if (debug_info_level <= DINFO_LEVEL_TERSE)
11494 break;
11496 /* Output any DIEs that are needed to specify the type of this data
11497 object. */
11498 gen_type_die (TREE_TYPE (decl), context_die);
11500 /* And its containing type. */
11501 origin = decl_class_context (decl);
11502 if (origin != NULL_TREE)
11503 gen_type_die_for_member (origin, decl, context_die);
11505 /* Now output the DIE to represent the data object itself. This gets
11506 complicated because of the possibility that the VAR_DECL really
11507 represents an inlined instance of a formal parameter for an inline
11508 function. */
11509 origin = decl_ultimate_origin (decl);
11510 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11511 gen_formal_parameter_die (decl, context_die);
11512 else
11513 gen_variable_die (decl, context_die);
11514 break;
11516 case FIELD_DECL:
11517 /* Ignore the nameless fields that are used to skip bits but handle C++
11518 anonymous unions. */
11519 if (DECL_NAME (decl) != NULL_TREE
11520 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11522 gen_type_die (member_declared_type (decl), context_die);
11523 gen_field_die (decl, context_die);
11525 break;
11527 case PARM_DECL:
11528 gen_type_die (TREE_TYPE (decl), context_die);
11529 gen_formal_parameter_die (decl, context_die);
11530 break;
11532 case NAMESPACE_DECL:
11533 /* Ignore for now. */
11534 break;
11536 default:
11537 abort ();
11541 static void
11542 mark_limbo_die_list (ptr)
11543 void *ptr ATTRIBUTE_UNUSED;
11545 limbo_die_node *node;
11546 for (node = limbo_die_list; node; node = node->next)
11547 ggc_mark_tree (node->created_for);
11550 /* Add Ada "use" clause information for SGI Workshop debugger. */
11552 void
11553 dwarf2out_add_library_unit_info (filename, context_list)
11554 const char *filename;
11555 const char *context_list;
11557 unsigned int file_index;
11559 if (filename != NULL)
11561 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL);
11562 tree context_list_decl
11563 = build_decl (LABEL_DECL, get_identifier (context_list),
11564 void_type_node);
11566 TREE_PUBLIC (context_list_decl) = TRUE;
11567 add_name_attribute (unit_die, context_list);
11568 file_index = lookup_filename (filename);
11569 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11570 add_pubname (context_list_decl, unit_die);
11574 /* Output debug information for global decl DECL. Called from toplev.c after
11575 compilation proper has finished. */
11577 static void
11578 dwarf2out_global_decl (decl)
11579 tree decl;
11581 /* Output DWARF2 information for file-scope tentative data object
11582 declarations, file-scope (extern) function declarations (which had no
11583 corresponding body) and file-scope tagged type declarations and
11584 definitions which have not yet been forced out. */
11585 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
11586 dwarf2out_decl (decl);
11589 /* Write the debugging output for DECL. */
11591 void
11592 dwarf2out_decl (decl)
11593 tree decl;
11595 dw_die_ref context_die = comp_unit_die;
11597 switch (TREE_CODE (decl))
11599 case ERROR_MARK:
11600 return;
11602 case FUNCTION_DECL:
11603 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11604 builtin function. Explicit programmer-supplied declarations of
11605 these same functions should NOT be ignored however. */
11606 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11607 return;
11609 /* What we would really like to do here is to filter out all mere
11610 file-scope declarations of file-scope functions which are never
11611 referenced later within this translation unit (and keep all of ones
11612 that *are* referenced later on) but we aren't clairvoyant, so we have
11613 no idea which functions will be referenced in the future (i.e. later
11614 on within the current translation unit). So here we just ignore all
11615 file-scope function declarations which are not also definitions. If
11616 and when the debugger needs to know something about these functions,
11617 it will have to hunt around and find the DWARF information associated
11618 with the definition of the function.
11620 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11621 nodes represent definitions and which ones represent mere
11622 declarations. We have to check DECL_INITIAL instead. That's because
11623 the C front-end supports some weird semantics for "extern inline"
11624 function definitions. These can get inlined within the current
11625 translation unit (an thus, we need to generate Dwarf info for their
11626 abstract instances so that the Dwarf info for the concrete inlined
11627 instances can have something to refer to) but the compiler never
11628 generates any out-of-lines instances of such things (despite the fact
11629 that they *are* definitions).
11631 The important point is that the C front-end marks these "extern
11632 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11633 them anyway. Note that the C++ front-end also plays some similar games
11634 for inline function definitions appearing within include files which
11635 also contain `#pragma interface' pragmas. */
11636 if (DECL_INITIAL (decl) == NULL_TREE)
11637 return;
11639 /* If we're a nested function, initially use a parent of NULL; if we're
11640 a plain function, this will be fixed up in decls_for_scope. If
11641 we're a method, it will be ignored, since we already have a DIE. */
11642 if (decl_function_context (decl))
11643 context_die = NULL;
11644 break;
11646 case VAR_DECL:
11647 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11648 declaration and if the declaration was never even referenced from
11649 within this entire compilation unit. We suppress these DIEs in
11650 order to save space in the .debug section (by eliminating entries
11651 which are probably useless). Note that we must not suppress
11652 block-local extern declarations (whether used or not) because that
11653 would screw-up the debugger's name lookup mechanism and cause it to
11654 miss things which really ought to be in scope at a given point. */
11655 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11656 return;
11658 /* If we are in terse mode, don't generate any DIEs to represent any
11659 variable declarations or definitions. */
11660 if (debug_info_level <= DINFO_LEVEL_TERSE)
11661 return;
11662 break;
11664 case TYPE_DECL:
11665 /* Don't emit stubs for types unless they are needed by other DIEs. */
11666 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11667 return;
11669 /* Don't bother trying to generate any DIEs to represent any of the
11670 normal built-in types for the language we are compiling. */
11671 if (DECL_SOURCE_LINE (decl) == 0)
11673 /* OK, we need to generate one for `bool' so GDB knows what type
11674 comparisons have. */
11675 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11676 == DW_LANG_C_plus_plus)
11677 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
11678 && ! DECL_IGNORED_P (decl))
11679 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11681 return;
11684 /* If we are in terse mode, don't generate any DIEs for types. */
11685 if (debug_info_level <= DINFO_LEVEL_TERSE)
11686 return;
11688 /* If we're a function-scope tag, initially use a parent of NULL;
11689 this will be fixed up in decls_for_scope. */
11690 if (decl_function_context (decl))
11691 context_die = NULL;
11693 break;
11695 default:
11696 return;
11699 gen_decl_die (decl, context_die);
11702 /* Output a marker (i.e. a label) for the beginning of the generated code for
11703 a lexical block. */
11705 static void
11706 dwarf2out_begin_block (line, blocknum)
11707 unsigned int line ATTRIBUTE_UNUSED;
11708 unsigned int blocknum;
11710 function_section (current_function_decl);
11711 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11714 /* Output a marker (i.e. a label) for the end of the generated code for a
11715 lexical block. */
11717 static void
11718 dwarf2out_end_block (line, blocknum)
11719 unsigned int line ATTRIBUTE_UNUSED;
11720 unsigned int blocknum;
11722 function_section (current_function_decl);
11723 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11726 /* Returns nonzero if it is appropriate not to emit any debugging
11727 information for BLOCK, because it doesn't contain any instructions.
11729 Don't allow this for blocks with nested functions or local classes
11730 as we would end up with orphans, and in the presence of scheduling
11731 we may end up calling them anyway. */
11733 static bool
11734 dwarf2out_ignore_block (block)
11735 tree block;
11737 tree decl;
11739 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11740 if (TREE_CODE (decl) == FUNCTION_DECL
11741 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11742 return 0;
11744 return 1;
11747 /* Lookup FILE_NAME (in the list of filenames that we know about here in
11748 dwarf2out.c) and return its "index". The index of each (known) filename is
11749 just a unique number which is associated with only that one filename. We
11750 need such numbers for the sake of generating labels (in the .debug_sfnames
11751 section) and references to those files numbers (in the .debug_srcinfo
11752 and.debug_macinfo sections). If the filename given as an argument is not
11753 found in our current list, add it to the list and assign it the next
11754 available unique index number. In order to speed up searches, we remember
11755 the index of the filename was looked up last. This handles the majority of
11756 all searches. */
11758 static unsigned
11759 lookup_filename (file_name)
11760 const char *file_name;
11762 unsigned i;
11764 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11765 if (strcmp (file_name, "<internal>") == 0
11766 || strcmp (file_name, "<built-in>") == 0)
11767 return 0;
11769 /* Check to see if the file name that was searched on the previous
11770 call matches this file name. If so, return the index. */
11771 if (file_table.last_lookup_index != 0)
11772 if (0 == strcmp (file_name,
11773 file_table.table[file_table.last_lookup_index]))
11774 return file_table.last_lookup_index;
11776 /* Didn't match the previous lookup, search the table */
11777 for (i = 1; i < file_table.in_use; i++)
11778 if (strcmp (file_name, file_table.table[i]) == 0)
11780 file_table.last_lookup_index = i;
11781 return i;
11784 /* Prepare to add a new table entry by making sure there is enough space in
11785 the table to do so. If not, expand the current table. */
11786 if (i == file_table.allocated)
11788 file_table.allocated = i + FILE_TABLE_INCREMENT;
11789 file_table.table = (char **)
11790 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11793 /* Add the new entry to the end of the filename table. */
11794 file_table.table[i] = xstrdup (file_name);
11795 file_table.in_use = i + 1;
11796 file_table.last_lookup_index = i;
11798 if (DWARF2_ASM_LINE_DEBUG_INFO)
11800 fprintf (asm_out_file, "\t.file %u ", i);
11801 output_quoted_string (asm_out_file, file_name);
11802 fputc ('\n', asm_out_file);
11805 return i;
11808 static void
11809 init_file_table ()
11811 /* Allocate the initial hunk of the file_table. */
11812 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11813 file_table.allocated = FILE_TABLE_INCREMENT;
11815 /* Skip the first entry - file numbers begin at 1. */
11816 file_table.in_use = 1;
11817 file_table.last_lookup_index = 0;
11820 /* Output a label to mark the beginning of a source code line entry
11821 and record information relating to this source line, in
11822 'line_info_table' for later output of the .debug_line section. */
11824 static void
11825 dwarf2out_source_line (line, filename)
11826 unsigned int line;
11827 const char *filename;
11829 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11831 function_section (current_function_decl);
11833 /* If requested, emit something human-readable. */
11834 if (flag_debug_asm)
11835 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11836 filename, line);
11838 if (DWARF2_ASM_LINE_DEBUG_INFO)
11840 unsigned file_num = lookup_filename (filename);
11842 /* Emit the .loc directive understood by GNU as. */
11843 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11845 /* Indicate that line number info exists. */
11846 line_info_table_in_use++;
11848 /* Indicate that multiple line number tables exist. */
11849 if (DECL_SECTION_NAME (current_function_decl))
11850 separate_line_info_table_in_use++;
11852 else if (DECL_SECTION_NAME (current_function_decl))
11854 dw_separate_line_info_ref line_info;
11855 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11856 separate_line_info_table_in_use);
11858 /* expand the line info table if necessary */
11859 if (separate_line_info_table_in_use
11860 == separate_line_info_table_allocated)
11862 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11863 separate_line_info_table
11864 = (dw_separate_line_info_ref)
11865 xrealloc (separate_line_info_table,
11866 separate_line_info_table_allocated
11867 * sizeof (dw_separate_line_info_entry));
11870 /* Add the new entry at the end of the line_info_table. */
11871 line_info
11872 = &separate_line_info_table[separate_line_info_table_in_use++];
11873 line_info->dw_file_num = lookup_filename (filename);
11874 line_info->dw_line_num = line;
11875 line_info->function = current_function_funcdef_no;
11877 else
11879 dw_line_info_ref line_info;
11881 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11882 line_info_table_in_use);
11884 /* Expand the line info table if necessary. */
11885 if (line_info_table_in_use == line_info_table_allocated)
11887 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11888 line_info_table
11889 = (dw_line_info_ref)
11890 xrealloc (line_info_table,
11891 (line_info_table_allocated
11892 * sizeof (dw_line_info_entry)));
11895 /* Add the new entry at the end of the line_info_table. */
11896 line_info = &line_info_table[line_info_table_in_use++];
11897 line_info->dw_file_num = lookup_filename (filename);
11898 line_info->dw_line_num = line;
11903 /* Record the beginning of a new source file. */
11905 static void
11906 dwarf2out_start_source_file (lineno, filename)
11907 unsigned int lineno;
11908 const char *filename;
11910 if (flag_eliminate_dwarf2_dups)
11912 /* Record the beginning of the file for break_out_includes. */
11913 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
11914 add_AT_string (bincl_die, DW_AT_name, filename);
11917 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11919 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11920 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
11921 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
11922 lineno);
11923 dw2_asm_output_data_uleb128 (lookup_filename (filename),
11924 "Filename we just started");
11928 /* Record the end of a source file. */
11930 static void
11931 dwarf2out_end_source_file (lineno)
11932 unsigned int lineno ATTRIBUTE_UNUSED;
11934 if (flag_eliminate_dwarf2_dups)
11935 /* Record the end of the file for break_out_includes. */
11936 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
11938 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11940 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11941 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11945 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11946 the tail part of the directive line, i.e. the part which is past the
11947 initial whitespace, #, whitespace, directive-name, whitespace part. */
11949 static void
11950 dwarf2out_define (lineno, buffer)
11951 unsigned lineno ATTRIBUTE_UNUSED;
11952 const char *buffer ATTRIBUTE_UNUSED;
11954 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11956 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11957 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
11958 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11959 dw2_asm_output_nstring (buffer, -1, "The macro");
11963 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11964 the tail part of the directive line, i.e. the part which is past the
11965 initial whitespace, #, whitespace, directive-name, whitespace part. */
11967 static void
11968 dwarf2out_undef (lineno, buffer)
11969 unsigned lineno ATTRIBUTE_UNUSED;
11970 const char *buffer ATTRIBUTE_UNUSED;
11972 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11974 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11975 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
11976 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11977 dw2_asm_output_nstring (buffer, -1, "The macro");
11981 /* Set up for Dwarf output at the start of compilation. */
11983 static void
11984 dwarf2out_init (main_input_filename)
11985 const char *main_input_filename;
11987 init_file_table ();
11989 /* Remember the name of the primary input file. */
11990 primary_filename = main_input_filename;
11992 /* Add it to the file table first, under the assumption that we'll
11993 be emitting line number data for it first, which avoids having
11994 to add an initial DW_LNS_set_file. */
11995 lookup_filename (main_input_filename);
11997 /* Allocate the initial hunk of the decl_die_table. */
11998 decl_die_table
11999 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
12000 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
12001 decl_die_table_in_use = 0;
12003 /* Allocate the initial hunk of the decl_scope_table. */
12004 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
12006 /* Allocate the initial hunk of the abbrev_die_table. */
12007 abbrev_die_table
12008 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
12009 sizeof (dw_die_ref));
12010 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
12011 /* Zero-th entry is allocated, but unused */
12012 abbrev_die_table_in_use = 1;
12014 /* Allocate the initial hunk of the line_info_table. */
12015 line_info_table
12016 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
12017 sizeof (dw_line_info_entry));
12018 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
12020 /* Zero-th entry is allocated, but unused */
12021 line_info_table_in_use = 1;
12023 /* Generate the initial DIE for the .debug section. Note that the (string)
12024 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
12025 will (typically) be a relative pathname and that this pathname should be
12026 taken as being relative to the directory from which the compiler was
12027 invoked when the given (base) source file was compiled. */
12028 comp_unit_die = gen_compile_unit_die (main_input_filename);
12030 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
12032 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
12034 ggc_add_root (&limbo_die_list, 1, 1, mark_limbo_die_list);
12036 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
12037 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
12038 DEBUG_ABBREV_SECTION_LABEL, 0);
12039 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12040 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
12041 else
12042 strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME));
12044 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
12045 DEBUG_INFO_SECTION_LABEL, 0);
12046 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
12047 DEBUG_LINE_SECTION_LABEL, 0);
12048 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
12049 DEBUG_RANGES_SECTION_LABEL, 0);
12050 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12051 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
12052 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
12053 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
12054 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12055 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
12057 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12059 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12060 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
12061 DEBUG_MACINFO_SECTION_LABEL, 0);
12062 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
12065 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12067 text_section ();
12068 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
12072 /* Allocate a string in .debug_str hash table. */
12074 static hashnode
12075 indirect_string_alloc (tab)
12076 hash_table *tab ATTRIBUTE_UNUSED;
12078 struct indirect_string_node *node;
12080 node = xmalloc (sizeof (struct indirect_string_node));
12081 node->refcount = 0;
12082 node->form = 0;
12083 node->label = NULL;
12085 return (hashnode) node;
12088 /* A helper function for dwarf2out_finish called through
12089 ht_forall. Emit one queued .debug_str string. */
12091 static int
12092 output_indirect_string (pfile, h, v)
12093 struct cpp_reader *pfile ATTRIBUTE_UNUSED;
12094 hashnode h;
12095 const PTR v ATTRIBUTE_UNUSED;
12097 struct indirect_string_node *node = (struct indirect_string_node *) h;
12099 if (node->form == DW_FORM_strp)
12101 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
12102 ASM_OUTPUT_LABEL (asm_out_file, node->label);
12103 assemble_string ((const char *) HT_STR (&node->id),
12104 HT_LEN (&node->id) + 1);
12107 return 1;
12110 /* Output stuff that dwarf requires at the end of every file,
12111 and generate the DWARF-2 debugging info. */
12113 static void
12114 dwarf2out_finish (input_filename)
12115 const char *input_filename ATTRIBUTE_UNUSED;
12117 limbo_die_node *node, *next_node;
12118 dw_die_ref die = 0;
12120 /* Traverse the limbo die list, and add parent/child links. The only
12121 dies without parents that should be here are concrete instances of
12122 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12123 For concrete instances, we can get the parent die from the abstract
12124 instance. */
12125 for (node = limbo_die_list; node; node = next_node)
12127 next_node = node->next;
12128 die = node->die;
12130 if (die->die_parent == NULL)
12132 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
12133 tree context;
12135 if (origin)
12136 add_child_die (origin->die_parent, die);
12137 else if (die == comp_unit_die)
12139 /* If this was an expression for a bound involved in a function
12140 return type, it may be a SAVE_EXPR for which we weren't able
12141 to find a DIE previously. So try now. */
12142 else if (node->created_for
12143 && TREE_CODE (node->created_for) == SAVE_EXPR
12144 && 0 != (origin = (lookup_decl_die
12145 (SAVE_EXPR_CONTEXT
12146 (node->created_for)))))
12147 add_child_die (origin, die);
12148 else if (errorcount > 0 || sorrycount > 0)
12149 /* It's OK to be confused by errors in the input. */
12150 add_child_die (comp_unit_die, die);
12151 else if (node->created_for
12152 && ((DECL_P (node->created_for)
12153 && (context = DECL_CONTEXT (node->created_for)))
12154 || (TYPE_P (node->created_for)
12155 && (context = TYPE_CONTEXT (node->created_for))))
12156 && TREE_CODE (context) == FUNCTION_DECL)
12158 /* In certain situations, the lexical block containing a
12159 nested function can be optimized away, which results
12160 in the nested function die being orphaned. Likewise
12161 with the return type of that nested function. Force
12162 this to be a child of the containing function. */
12163 origin = lookup_decl_die (context);
12164 if (! origin)
12165 abort ();
12166 add_child_die (origin, die);
12168 else
12169 abort ();
12172 free (node);
12175 limbo_die_list = NULL;
12177 /* Walk through the list of incomplete types again, trying once more to
12178 emit full debugging info for them. */
12179 retry_incomplete_types ();
12181 /* We need to reverse all the dies before break_out_includes, or
12182 we'll see the end of an include file before the beginning. */
12183 reverse_all_dies (comp_unit_die);
12185 /* Generate separate CUs for each of the include files we've seen.
12186 They will go into limbo_die_list. */
12187 if (flag_eliminate_dwarf2_dups)
12188 break_out_includes (comp_unit_die);
12190 /* Traverse the DIE's and add add sibling attributes to those DIE's
12191 that have children. */
12192 add_sibling_attributes (comp_unit_die);
12193 for (node = limbo_die_list; node; node = node->next)
12194 add_sibling_attributes (node->die);
12196 /* Output a terminator label for the .text section. */
12197 text_section ();
12198 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
12200 /* Output the source line correspondence table. We must do this
12201 even if there is no line information. Otherwise, on an empty
12202 translation unit, we will generate a present, but empty,
12203 .debug_info section. IRIX 6.5 `nm' will then complain when
12204 examining the file. */
12205 if (! DWARF2_ASM_LINE_DEBUG_INFO)
12207 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12208 output_line_info ();
12211 /* Output location list section if necessary. */
12212 if (have_location_lists)
12214 /* Output the location lists info. */
12215 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
12216 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
12217 DEBUG_LOC_SECTION_LABEL, 0);
12218 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
12219 output_location_lists (die);
12220 have_location_lists = 0;
12223 /* We can only use the low/high_pc attributes if all of the code was
12224 in .text. */
12225 if (separate_line_info_table_in_use == 0)
12227 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
12228 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
12231 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12232 "base address". Use zero so that these addresses become absolute. */
12233 else if (have_location_lists || ranges_table_in_use)
12234 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
12236 if (debug_info_level >= DINFO_LEVEL_NORMAL)
12237 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
12238 debug_line_section_label);
12240 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12241 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
12243 /* Output all of the compilation units. We put the main one last so that
12244 the offsets are available to output_pubnames. */
12245 for (node = limbo_die_list; node; node = node->next)
12246 output_comp_unit (node->die);
12248 output_comp_unit (comp_unit_die);
12250 /* Output the abbreviation table. */
12251 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12252 output_abbrev_section ();
12254 /* Output public names table if necessary. */
12255 if (pubname_table_in_use)
12257 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
12258 output_pubnames ();
12261 /* Output the address range information. We only put functions in the arange
12262 table, so don't write it out if we don't have any. */
12263 if (fde_table_in_use)
12265 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
12266 output_aranges ();
12269 /* Output ranges section if necessary. */
12270 if (ranges_table_in_use)
12272 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
12273 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
12274 output_ranges ();
12277 /* Have to end the primary source file. */
12278 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12280 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12281 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12282 dw2_asm_output_data (1, 0, "End compilation unit");
12285 /* If we emitted any DW_FORM_strp form attribute, output the string
12286 table too. */
12287 if (debug_str_hash)
12288 ht_forall (debug_str_hash, output_indirect_string, NULL);
12290 #else
12292 /* This should never be used, but its address is needed for comparisons. */
12293 const struct gcc_debug_hooks dwarf2_debug_hooks;
12295 #endif /* DWARF2_DEBUGGING_INFO */
12297 #include "gt-dwarf2out.h"