* gcc.c-torture/execute/20020720-1.x: Skip test on ARM-based systems.
[official-gcc.git] / gcc / dwarf2out.c
blobf5503d48d653e56d4800aa7b95f33fdbbdecf595
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 (*targetm.asm_out.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 all_throwers_are_sibcalls : 1;
207 unsigned nothrow : 1;
208 unsigned uses_eh_lsda : 1;
210 dw_fde_node;
212 /* Maximum size (in bytes) of an artificially generated label. */
213 #define MAX_ARTIFICIAL_LABEL_BYTES 30
215 /* The size of addresses as they appear in the Dwarf 2 data.
216 Some architectures use word addresses to refer to code locations,
217 but Dwarf 2 info always uses byte addresses. On such machines,
218 Dwarf 2 addresses need to be larger than the architecture's
219 pointers. */
220 #ifndef DWARF2_ADDR_SIZE
221 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
222 #endif
224 /* The size in bytes of a DWARF field indicating an offset or length
225 relative to a debug info section, specified to be 4 bytes in the
226 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
227 as PTR_SIZE. */
229 #ifndef DWARF_OFFSET_SIZE
230 #define DWARF_OFFSET_SIZE 4
231 #endif
233 #define DWARF_VERSION 2
235 /* Round SIZE up to the nearest BOUNDARY. */
236 #define DWARF_ROUND(SIZE,BOUNDARY) \
237 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
239 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
240 #ifndef DWARF_CIE_DATA_ALIGNMENT
241 #ifdef STACK_GROWS_DOWNWARD
242 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
243 #else
244 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
245 #endif
246 #endif
248 /* A pointer to the base of a table that contains frame description
249 information for each routine. */
250 static dw_fde_ref fde_table;
252 /* Number of elements currently allocated for fde_table. */
253 static unsigned fde_table_allocated;
255 /* Number of elements in fde_table currently in use. */
256 static unsigned fde_table_in_use;
258 /* Size (in elements) of increments by which we may expand the
259 fde_table. */
260 #define FDE_TABLE_INCREMENT 256
262 /* A list of call frame insns for the CIE. */
263 static dw_cfi_ref cie_cfi_head;
265 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
266 attribute that accelerates the lookup of the FDE associated
267 with the subprogram. This variable holds the table index of the FDE
268 associated with the current function (body) definition. */
269 static unsigned current_funcdef_fde;
271 struct ht *debug_str_hash;
273 struct indirect_string_node
275 struct ht_identifier id;
276 unsigned int refcount;
277 unsigned int form;
278 char *label;
281 /* Forward declarations for functions defined in this file. */
283 static char *stripattributes PARAMS ((const char *));
284 static const char *dwarf_cfi_name PARAMS ((unsigned));
285 static dw_cfi_ref new_cfi PARAMS ((void));
286 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
287 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
288 static void lookup_cfa_1 PARAMS ((dw_cfi_ref,
289 dw_cfa_location *));
290 static void lookup_cfa PARAMS ((dw_cfa_location *));
291 static void reg_save PARAMS ((const char *, unsigned,
292 unsigned, long));
293 static void initial_return_save PARAMS ((rtx));
294 static long stack_adjust_offset PARAMS ((rtx));
295 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
296 static void output_call_frame_info PARAMS ((int));
297 static void dwarf2out_stack_adjust PARAMS ((rtx));
298 static void queue_reg_save PARAMS ((const char *, rtx, long));
299 static void flush_queued_reg_saves PARAMS ((void));
300 static bool clobbers_queued_reg_save PARAMS ((rtx));
301 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
303 /* Support for complex CFA locations. */
304 static void output_cfa_loc PARAMS ((dw_cfi_ref));
305 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
306 struct dw_loc_descr_struct *));
307 static struct dw_loc_descr_struct *build_cfa_loc
308 PARAMS ((dw_cfa_location *));
309 static void def_cfa_1 PARAMS ((const char *,
310 dw_cfa_location *));
312 /* How to start an assembler comment. */
313 #ifndef ASM_COMMENT_START
314 #define ASM_COMMENT_START ";#"
315 #endif
317 /* Data and reference forms for relocatable data. */
318 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
319 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
321 #ifndef DEBUG_FRAME_SECTION
322 #define DEBUG_FRAME_SECTION ".debug_frame"
323 #endif
325 #ifndef FUNC_BEGIN_LABEL
326 #define FUNC_BEGIN_LABEL "LFB"
327 #endif
329 #ifndef FUNC_END_LABEL
330 #define FUNC_END_LABEL "LFE"
331 #endif
333 #define FRAME_BEGIN_LABEL "Lframe"
334 #define CIE_AFTER_SIZE_LABEL "LSCIE"
335 #define CIE_END_LABEL "LECIE"
336 #define FDE_LABEL "LSFDE"
337 #define FDE_AFTER_SIZE_LABEL "LASFDE"
338 #define FDE_END_LABEL "LEFDE"
339 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
340 #define LINE_NUMBER_END_LABEL "LELT"
341 #define LN_PROLOG_AS_LABEL "LASLTP"
342 #define LN_PROLOG_END_LABEL "LELTP"
343 #define DIE_LABEL_PREFIX "DW"
345 /* The DWARF 2 CFA column which tracks the return address. Normally this
346 is the column for PC, or the first column after all of the hard
347 registers. */
348 #ifndef DWARF_FRAME_RETURN_COLUMN
349 #ifdef PC_REGNUM
350 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
351 #else
352 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
353 #endif
354 #endif
356 /* The mapping from gcc register number to DWARF 2 CFA column number. By
357 default, we just provide columns for all registers. */
358 #ifndef DWARF_FRAME_REGNUM
359 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
360 #endif
362 /* The offset from the incoming value of %sp to the top of the stack frame
363 for the current function. */
364 #ifndef INCOMING_FRAME_SP_OFFSET
365 #define INCOMING_FRAME_SP_OFFSET 0
366 #endif
368 /* Hook used by __throw. */
371 expand_builtin_dwarf_fp_regnum ()
373 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
376 /* Return a pointer to a copy of the section string name S with all
377 attributes stripped off, and an asterisk prepended (for assemble_name). */
379 static inline char *
380 stripattributes (s)
381 const char *s;
383 char *stripped = xmalloc (strlen (s) + 2);
384 char *p = stripped;
386 *p++ = '*';
388 while (*s && *s != ',')
389 *p++ = *s++;
391 *p = '\0';
392 return stripped;
395 /* Generate code to initialize the register size table. */
397 void
398 expand_builtin_init_dwarf_reg_sizes (address)
399 tree address;
401 int i;
402 enum machine_mode mode = TYPE_MODE (char_type_node);
403 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
404 rtx mem = gen_rtx_MEM (BLKmode, addr);
406 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
407 if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS)
409 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
410 HOST_WIDE_INT size = GET_MODE_SIZE (reg_raw_mode[i]);
412 if (offset < 0)
413 continue;
415 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
419 /* Convert a DWARF call frame info. operation to its string name */
421 static const char *
422 dwarf_cfi_name (cfi_opc)
423 unsigned cfi_opc;
425 switch (cfi_opc)
427 case DW_CFA_advance_loc:
428 return "DW_CFA_advance_loc";
429 case DW_CFA_offset:
430 return "DW_CFA_offset";
431 case DW_CFA_restore:
432 return "DW_CFA_restore";
433 case DW_CFA_nop:
434 return "DW_CFA_nop";
435 case DW_CFA_set_loc:
436 return "DW_CFA_set_loc";
437 case DW_CFA_advance_loc1:
438 return "DW_CFA_advance_loc1";
439 case DW_CFA_advance_loc2:
440 return "DW_CFA_advance_loc2";
441 case DW_CFA_advance_loc4:
442 return "DW_CFA_advance_loc4";
443 case DW_CFA_offset_extended:
444 return "DW_CFA_offset_extended";
445 case DW_CFA_restore_extended:
446 return "DW_CFA_restore_extended";
447 case DW_CFA_undefined:
448 return "DW_CFA_undefined";
449 case DW_CFA_same_value:
450 return "DW_CFA_same_value";
451 case DW_CFA_register:
452 return "DW_CFA_register";
453 case DW_CFA_remember_state:
454 return "DW_CFA_remember_state";
455 case DW_CFA_restore_state:
456 return "DW_CFA_restore_state";
457 case DW_CFA_def_cfa:
458 return "DW_CFA_def_cfa";
459 case DW_CFA_def_cfa_register:
460 return "DW_CFA_def_cfa_register";
461 case DW_CFA_def_cfa_offset:
462 return "DW_CFA_def_cfa_offset";
464 /* DWARF 3 */
465 case DW_CFA_def_cfa_expression:
466 return "DW_CFA_def_cfa_expression";
467 case DW_CFA_expression:
468 return "DW_CFA_expression";
469 case DW_CFA_offset_extended_sf:
470 return "DW_CFA_offset_extended_sf";
471 case DW_CFA_def_cfa_sf:
472 return "DW_CFA_def_cfa_sf";
473 case DW_CFA_def_cfa_offset_sf:
474 return "DW_CFA_def_cfa_offset_sf";
476 /* SGI/MIPS specific */
477 case DW_CFA_MIPS_advance_loc8:
478 return "DW_CFA_MIPS_advance_loc8";
480 /* GNU extensions */
481 case DW_CFA_GNU_window_save:
482 return "DW_CFA_GNU_window_save";
483 case DW_CFA_GNU_args_size:
484 return "DW_CFA_GNU_args_size";
485 case DW_CFA_GNU_negative_offset_extended:
486 return "DW_CFA_GNU_negative_offset_extended";
488 default:
489 return "DW_CFA_<unknown>";
493 /* Return a pointer to a newly allocated Call Frame Instruction. */
495 static inline dw_cfi_ref
496 new_cfi ()
498 dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
500 cfi->dw_cfi_next = NULL;
501 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
502 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
504 return cfi;
507 /* Add a Call Frame Instruction to list of instructions. */
509 static inline void
510 add_cfi (list_head, cfi)
511 dw_cfi_ref *list_head;
512 dw_cfi_ref cfi;
514 dw_cfi_ref *p;
516 /* Find the end of the chain. */
517 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
520 *p = cfi;
523 /* Generate a new label for the CFI info to refer to. */
525 char *
526 dwarf2out_cfi_label ()
528 static char label[20];
529 static unsigned long label_num = 0;
531 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
532 ASM_OUTPUT_LABEL (asm_out_file, label);
533 return label;
536 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
537 or to the CIE if LABEL is NULL. */
539 static void
540 add_fde_cfi (label, cfi)
541 const char *label;
542 dw_cfi_ref cfi;
544 if (label)
546 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
548 if (*label == 0)
549 label = dwarf2out_cfi_label ();
551 if (fde->dw_fde_current_label == NULL
552 || strcmp (label, fde->dw_fde_current_label) != 0)
554 dw_cfi_ref xcfi;
556 fde->dw_fde_current_label = label = xstrdup (label);
558 /* Set the location counter to the new label. */
559 xcfi = new_cfi ();
560 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
561 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
562 add_cfi (&fde->dw_fde_cfi, xcfi);
565 add_cfi (&fde->dw_fde_cfi, cfi);
568 else
569 add_cfi (&cie_cfi_head, cfi);
572 /* Subroutine of lookup_cfa. */
574 static inline void
575 lookup_cfa_1 (cfi, loc)
576 dw_cfi_ref cfi;
577 dw_cfa_location *loc;
579 switch (cfi->dw_cfi_opc)
581 case DW_CFA_def_cfa_offset:
582 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
583 break;
584 case DW_CFA_def_cfa_register:
585 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
586 break;
587 case DW_CFA_def_cfa:
588 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
589 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
590 break;
591 case DW_CFA_def_cfa_expression:
592 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
593 break;
594 default:
595 break;
599 /* Find the previous value for the CFA. */
601 static void
602 lookup_cfa (loc)
603 dw_cfa_location *loc;
605 dw_cfi_ref cfi;
607 loc->reg = (unsigned long) -1;
608 loc->offset = 0;
609 loc->indirect = 0;
610 loc->base_offset = 0;
612 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
613 lookup_cfa_1 (cfi, loc);
615 if (fde_table_in_use)
617 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
618 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
619 lookup_cfa_1 (cfi, loc);
623 /* The current rule for calculating the DWARF2 canonical frame address. */
624 static dw_cfa_location cfa;
626 /* The register used for saving registers to the stack, and its offset
627 from the CFA. */
628 static dw_cfa_location cfa_store;
630 /* The running total of the size of arguments pushed onto the stack. */
631 static long args_size;
633 /* The last args_size we actually output. */
634 static long old_args_size;
636 /* Entry point to update the canonical frame address (CFA).
637 LABEL is passed to add_fde_cfi. The value of CFA is now to be
638 calculated from REG+OFFSET. */
640 void
641 dwarf2out_def_cfa (label, reg, offset)
642 const char *label;
643 unsigned reg;
644 long offset;
646 dw_cfa_location loc;
647 loc.indirect = 0;
648 loc.base_offset = 0;
649 loc.reg = reg;
650 loc.offset = offset;
651 def_cfa_1 (label, &loc);
654 /* This routine does the actual work. The CFA is now calculated from
655 the dw_cfa_location structure. */
657 static void
658 def_cfa_1 (label, loc_p)
659 const char *label;
660 dw_cfa_location *loc_p;
662 dw_cfi_ref cfi;
663 dw_cfa_location old_cfa, loc;
665 cfa = *loc_p;
666 loc = *loc_p;
668 if (cfa_store.reg == loc.reg && loc.indirect == 0)
669 cfa_store.offset = loc.offset;
671 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
672 lookup_cfa (&old_cfa);
674 /* If nothing changed, no need to issue any call frame instructions. */
675 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
676 && loc.indirect == old_cfa.indirect
677 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
678 return;
680 cfi = new_cfi ();
682 if (loc.reg == old_cfa.reg && !loc.indirect)
684 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
685 indicating the CFA register did not change but the offset
686 did. */
687 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
688 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
691 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
692 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
693 && !loc.indirect)
695 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
696 indicating the CFA register has changed to <register> but the
697 offset has not changed. */
698 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
699 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
701 #endif
703 else if (loc.indirect == 0)
705 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
706 indicating the CFA register has changed to <register> with
707 the specified offset. */
708 cfi->dw_cfi_opc = DW_CFA_def_cfa;
709 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
710 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
712 else
714 /* Construct a DW_CFA_def_cfa_expression instruction to
715 calculate the CFA using a full location expression since no
716 register-offset pair is available. */
717 struct dw_loc_descr_struct *loc_list;
719 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
720 loc_list = build_cfa_loc (&loc);
721 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
724 add_fde_cfi (label, cfi);
727 /* Add the CFI for saving a register. REG is the CFA column number.
728 LABEL is passed to add_fde_cfi.
729 If SREG is -1, the register is saved at OFFSET from the CFA;
730 otherwise it is saved in SREG. */
732 static void
733 reg_save (label, reg, sreg, offset)
734 const char *label;
735 unsigned reg;
736 unsigned sreg;
737 long offset;
739 dw_cfi_ref cfi = new_cfi ();
741 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
743 /* The following comparison is correct. -1 is used to indicate that
744 the value isn't a register number. */
745 if (sreg == (unsigned int) -1)
747 if (reg & ~0x3f)
748 /* The register number won't fit in 6 bits, so we have to use
749 the long form. */
750 cfi->dw_cfi_opc = DW_CFA_offset_extended;
751 else
752 cfi->dw_cfi_opc = DW_CFA_offset;
754 #ifdef ENABLE_CHECKING
756 /* If we get an offset that is not a multiple of
757 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
758 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
759 description. */
760 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
762 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
763 abort ();
765 #endif
766 offset /= DWARF_CIE_DATA_ALIGNMENT;
767 if (offset < 0)
768 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
770 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
772 else if (sreg == reg)
773 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
774 return;
775 else
777 cfi->dw_cfi_opc = DW_CFA_register;
778 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
781 add_fde_cfi (label, cfi);
784 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
785 This CFI tells the unwinder that it needs to restore the window registers
786 from the previous frame's window save area.
788 ??? Perhaps we should note in the CIE where windows are saved (instead of
789 assuming 0(cfa)) and what registers are in the window. */
791 void
792 dwarf2out_window_save (label)
793 const char *label;
795 dw_cfi_ref cfi = new_cfi ();
797 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
798 add_fde_cfi (label, cfi);
801 /* Add a CFI to update the running total of the size of arguments
802 pushed onto the stack. */
804 void
805 dwarf2out_args_size (label, size)
806 const char *label;
807 long size;
809 dw_cfi_ref cfi;
811 if (size == old_args_size)
812 return;
814 old_args_size = size;
816 cfi = new_cfi ();
817 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
818 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
819 add_fde_cfi (label, cfi);
822 /* Entry point for saving a register to the stack. REG is the GCC register
823 number. LABEL and OFFSET are passed to reg_save. */
825 void
826 dwarf2out_reg_save (label, reg, offset)
827 const char *label;
828 unsigned reg;
829 long offset;
831 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
834 /* Entry point for saving the return address in the stack.
835 LABEL and OFFSET are passed to reg_save. */
837 void
838 dwarf2out_return_save (label, offset)
839 const char *label;
840 long offset;
842 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
845 /* Entry point for saving the return address in a register.
846 LABEL and SREG are passed to reg_save. */
848 void
849 dwarf2out_return_reg (label, sreg)
850 const char *label;
851 unsigned sreg;
853 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
856 /* Record the initial position of the return address. RTL is
857 INCOMING_RETURN_ADDR_RTX. */
859 static void
860 initial_return_save (rtl)
861 rtx rtl;
863 unsigned int reg = (unsigned int) -1;
864 HOST_WIDE_INT offset = 0;
866 switch (GET_CODE (rtl))
868 case REG:
869 /* RA is in a register. */
870 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
871 break;
873 case MEM:
874 /* RA is on the stack. */
875 rtl = XEXP (rtl, 0);
876 switch (GET_CODE (rtl))
878 case REG:
879 if (REGNO (rtl) != STACK_POINTER_REGNUM)
880 abort ();
881 offset = 0;
882 break;
884 case PLUS:
885 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
886 abort ();
887 offset = INTVAL (XEXP (rtl, 1));
888 break;
890 case MINUS:
891 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
892 abort ();
893 offset = -INTVAL (XEXP (rtl, 1));
894 break;
896 default:
897 abort ();
900 break;
902 case PLUS:
903 /* The return address is at some offset from any value we can
904 actually load. For instance, on the SPARC it is in %i7+8. Just
905 ignore the offset for now; it doesn't matter for unwinding frames. */
906 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
907 abort ();
908 initial_return_save (XEXP (rtl, 0));
909 return;
911 default:
912 abort ();
915 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
918 /* Given a SET, calculate the amount of stack adjustment it
919 contains. */
921 static long
922 stack_adjust_offset (pattern)
923 rtx pattern;
925 rtx src = SET_SRC (pattern);
926 rtx dest = SET_DEST (pattern);
927 HOST_WIDE_INT offset = 0;
928 enum rtx_code code;
930 if (dest == stack_pointer_rtx)
932 /* (set (reg sp) (plus (reg sp) (const_int))) */
933 code = GET_CODE (src);
934 if (! (code == PLUS || code == MINUS)
935 || XEXP (src, 0) != stack_pointer_rtx
936 || GET_CODE (XEXP (src, 1)) != CONST_INT)
937 return 0;
939 offset = INTVAL (XEXP (src, 1));
940 if (code == PLUS)
941 offset = -offset;
943 else if (GET_CODE (dest) == MEM)
945 /* (set (mem (pre_dec (reg sp))) (foo)) */
946 src = XEXP (dest, 0);
947 code = GET_CODE (src);
949 switch (code)
951 case PRE_MODIFY:
952 case POST_MODIFY:
953 if (XEXP (src, 0) == stack_pointer_rtx)
955 rtx val = XEXP (XEXP (src, 1), 1);
956 /* We handle only adjustments by constant amount. */
957 if (GET_CODE (XEXP (src, 1)) != PLUS ||
958 GET_CODE (val) != CONST_INT)
959 abort ();
960 offset = -INTVAL (val);
961 break;
963 return 0;
965 case PRE_DEC:
966 case POST_DEC:
967 if (XEXP (src, 0) == stack_pointer_rtx)
969 offset = GET_MODE_SIZE (GET_MODE (dest));
970 break;
972 return 0;
974 case PRE_INC:
975 case POST_INC:
976 if (XEXP (src, 0) == stack_pointer_rtx)
978 offset = -GET_MODE_SIZE (GET_MODE (dest));
979 break;
981 return 0;
983 default:
984 return 0;
987 else
988 return 0;
990 return offset;
993 /* Check INSN to see if it looks like a push or a stack adjustment, and
994 make a note of it if it does. EH uses this information to find out how
995 much extra space it needs to pop off the stack. */
997 static void
998 dwarf2out_stack_adjust (insn)
999 rtx insn;
1001 HOST_WIDE_INT offset;
1002 const char *label;
1003 int i;
1005 if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN)
1007 /* Extract the size of the args from the CALL rtx itself. */
1008 insn = PATTERN (insn);
1009 if (GET_CODE (insn) == PARALLEL)
1010 insn = XVECEXP (insn, 0, 0);
1011 if (GET_CODE (insn) == SET)
1012 insn = SET_SRC (insn);
1013 if (GET_CODE (insn) != CALL)
1014 abort ();
1016 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1017 return;
1020 /* If only calls can throw, and we have a frame pointer,
1021 save up adjustments until we see the CALL_INSN. */
1022 else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1023 return;
1025 if (GET_CODE (insn) == BARRIER)
1027 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1028 the compiler will have already emitted a stack adjustment, but
1029 doesn't bother for calls to noreturn functions. */
1030 #ifdef STACK_GROWS_DOWNWARD
1031 offset = -args_size;
1032 #else
1033 offset = args_size;
1034 #endif
1036 else if (GET_CODE (PATTERN (insn)) == SET)
1037 offset = stack_adjust_offset (PATTERN (insn));
1038 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1039 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1041 /* There may be stack adjustments inside compound insns. Search
1042 for them. */
1043 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1044 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1045 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1047 else
1048 return;
1050 if (offset == 0)
1051 return;
1053 if (cfa.reg == STACK_POINTER_REGNUM)
1054 cfa.offset += offset;
1056 #ifndef STACK_GROWS_DOWNWARD
1057 offset = -offset;
1058 #endif
1060 args_size += offset;
1061 if (args_size < 0)
1062 args_size = 0;
1064 label = dwarf2out_cfi_label ();
1065 def_cfa_1 (label, &cfa);
1066 dwarf2out_args_size (label, args_size);
1069 /* We delay emitting a register save until either (a) we reach the end
1070 of the prologue or (b) the register is clobbered. This clusters
1071 register saves so that there are fewer pc advances. */
1073 struct queued_reg_save
1075 struct queued_reg_save *next;
1076 rtx reg;
1077 long cfa_offset;
1080 static struct queued_reg_save *queued_reg_saves;
1081 static const char *last_reg_save_label;
1083 static void
1084 queue_reg_save (label, reg, offset)
1085 const char *label;
1086 rtx reg;
1087 long offset;
1089 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1091 q->next = queued_reg_saves;
1092 q->reg = reg;
1093 q->cfa_offset = offset;
1094 queued_reg_saves = q;
1096 last_reg_save_label = label;
1099 static void
1100 flush_queued_reg_saves ()
1102 struct queued_reg_save *q, *next;
1104 for (q = queued_reg_saves; q; q = next)
1106 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1107 next = q->next;
1108 free (q);
1111 queued_reg_saves = NULL;
1112 last_reg_save_label = NULL;
1115 static bool
1116 clobbers_queued_reg_save (insn)
1117 rtx insn;
1119 struct queued_reg_save *q;
1121 for (q = queued_reg_saves; q; q = q->next)
1122 if (modified_in_p (q->reg, insn))
1123 return true;
1125 return false;
1129 /* A temporary register holding an integral value used in adjusting SP
1130 or setting up the store_reg. The "offset" field holds the integer
1131 value, not an offset. */
1132 static dw_cfa_location cfa_temp;
1134 /* Record call frame debugging information for an expression EXPR,
1135 which either sets SP or FP (adjusting how we calculate the frame
1136 address) or saves a register to the stack. LABEL indicates the
1137 address of EXPR.
1139 This function encodes a state machine mapping rtxes to actions on
1140 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1141 users need not read the source code.
1143 The High-Level Picture
1145 Changes in the register we use to calculate the CFA: Currently we
1146 assume that if you copy the CFA register into another register, we
1147 should take the other one as the new CFA register; this seems to
1148 work pretty well. If it's wrong for some target, it's simple
1149 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1151 Changes in the register we use for saving registers to the stack:
1152 This is usually SP, but not always. Again, we deduce that if you
1153 copy SP into another register (and SP is not the CFA register),
1154 then the new register is the one we will be using for register
1155 saves. This also seems to work.
1157 Register saves: There's not much guesswork about this one; if
1158 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1159 register save, and the register used to calculate the destination
1160 had better be the one we think we're using for this purpose.
1162 Except: If the register being saved is the CFA register, and the
1163 offset is non-zero, we are saving the CFA, so we assume we have to
1164 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1165 the intent is to save the value of SP from the previous frame.
1167 Invariants / Summaries of Rules
1169 cfa current rule for calculating the CFA. It usually
1170 consists of a register and an offset.
1171 cfa_store register used by prologue code to save things to the stack
1172 cfa_store.offset is the offset from the value of
1173 cfa_store.reg to the actual CFA
1174 cfa_temp register holding an integral value. cfa_temp.offset
1175 stores the value, which will be used to adjust the
1176 stack pointer. cfa_temp is also used like cfa_store,
1177 to track stores to the stack via fp or a temp reg.
1179 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1180 with cfa.reg as the first operand changes the cfa.reg and its
1181 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1182 cfa_temp.offset.
1184 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1185 expression yielding a constant. This sets cfa_temp.reg
1186 and cfa_temp.offset.
1188 Rule 5: Create a new register cfa_store used to save items to the
1189 stack.
1191 Rules 10-14: Save a register to the stack. Define offset as the
1192 difference of the original location and cfa_store's
1193 location (or cfa_temp's location if cfa_temp is used).
1195 The Rules
1197 "{a,b}" indicates a choice of a xor b.
1198 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1200 Rule 1:
1201 (set <reg1> <reg2>:cfa.reg)
1202 effects: cfa.reg = <reg1>
1203 cfa.offset unchanged
1204 cfa_temp.reg = <reg1>
1205 cfa_temp.offset = cfa.offset
1207 Rule 2:
1208 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1209 {<const_int>,<reg>:cfa_temp.reg}))
1210 effects: cfa.reg = sp if fp used
1211 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1212 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1213 if cfa_store.reg==sp
1215 Rule 3:
1216 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1217 effects: cfa.reg = fp
1218 cfa_offset += +/- <const_int>
1220 Rule 4:
1221 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1222 constraints: <reg1> != fp
1223 <reg1> != sp
1224 effects: cfa.reg = <reg1>
1225 cfa_temp.reg = <reg1>
1226 cfa_temp.offset = cfa.offset
1228 Rule 5:
1229 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1230 constraints: <reg1> != fp
1231 <reg1> != sp
1232 effects: cfa_store.reg = <reg1>
1233 cfa_store.offset = cfa.offset - cfa_temp.offset
1235 Rule 6:
1236 (set <reg> <const_int>)
1237 effects: cfa_temp.reg = <reg>
1238 cfa_temp.offset = <const_int>
1240 Rule 7:
1241 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1242 effects: cfa_temp.reg = <reg1>
1243 cfa_temp.offset |= <const_int>
1245 Rule 8:
1246 (set <reg> (high <exp>))
1247 effects: none
1249 Rule 9:
1250 (set <reg> (lo_sum <exp> <const_int>))
1251 effects: cfa_temp.reg = <reg>
1252 cfa_temp.offset = <const_int>
1254 Rule 10:
1255 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1256 effects: cfa_store.offset -= <const_int>
1257 cfa.offset = cfa_store.offset if cfa.reg == sp
1258 cfa.reg = sp
1259 cfa.base_offset = -cfa_store.offset
1261 Rule 11:
1262 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1263 effects: cfa_store.offset += -/+ mode_size(mem)
1264 cfa.offset = cfa_store.offset if cfa.reg == sp
1265 cfa.reg = sp
1266 cfa.base_offset = -cfa_store.offset
1268 Rule 12:
1269 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1271 <reg2>)
1272 effects: cfa.reg = <reg1>
1273 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1275 Rule 13:
1276 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1277 effects: cfa.reg = <reg1>
1278 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1280 Rule 14:
1281 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1282 effects: cfa.reg = <reg1>
1283 cfa.base_offset = -cfa_temp.offset
1284 cfa_temp.offset -= mode_size(mem) */
1286 static void
1287 dwarf2out_frame_debug_expr (expr, label)
1288 rtx expr;
1289 const char *label;
1291 rtx src, dest;
1292 HOST_WIDE_INT offset;
1294 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1295 the PARALLEL independently. The first element is always processed if
1296 it is a SET. This is for backward compatibility. Other elements
1297 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1298 flag is set in them. */
1299 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1301 int par_index;
1302 int limit = XVECLEN (expr, 0);
1304 for (par_index = 0; par_index < limit; par_index++)
1305 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1306 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1307 || par_index == 0))
1308 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1310 return;
1313 if (GET_CODE (expr) != SET)
1314 abort ();
1316 src = SET_SRC (expr);
1317 dest = SET_DEST (expr);
1319 switch (GET_CODE (dest))
1321 case REG:
1322 /* Rule 1 */
1323 /* Update the CFA rule wrt SP or FP. Make sure src is
1324 relative to the current CFA register. */
1325 switch (GET_CODE (src))
1327 /* Setting FP from SP. */
1328 case REG:
1329 if (cfa.reg == (unsigned) REGNO (src))
1330 /* OK. */
1332 else
1333 abort ();
1335 /* We used to require that dest be either SP or FP, but the
1336 ARM copies SP to a temporary register, and from there to
1337 FP. So we just rely on the backends to only set
1338 RTX_FRAME_RELATED_P on appropriate insns. */
1339 cfa.reg = REGNO (dest);
1340 cfa_temp.reg = cfa.reg;
1341 cfa_temp.offset = cfa.offset;
1342 break;
1344 case PLUS:
1345 case MINUS:
1346 case LO_SUM:
1347 if (dest == stack_pointer_rtx)
1349 /* Rule 2 */
1350 /* Adjusting SP. */
1351 switch (GET_CODE (XEXP (src, 1)))
1353 case CONST_INT:
1354 offset = INTVAL (XEXP (src, 1));
1355 break;
1356 case REG:
1357 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1358 abort ();
1359 offset = cfa_temp.offset;
1360 break;
1361 default:
1362 abort ();
1365 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1367 /* Restoring SP from FP in the epilogue. */
1368 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1369 abort ();
1370 cfa.reg = STACK_POINTER_REGNUM;
1372 else if (GET_CODE (src) == LO_SUM)
1373 /* Assume we've set the source reg of the LO_SUM from sp. */
1375 else if (XEXP (src, 0) != stack_pointer_rtx)
1376 abort ();
1378 if (GET_CODE (src) != MINUS)
1379 offset = -offset;
1380 if (cfa.reg == STACK_POINTER_REGNUM)
1381 cfa.offset += offset;
1382 if (cfa_store.reg == STACK_POINTER_REGNUM)
1383 cfa_store.offset += offset;
1385 else if (dest == hard_frame_pointer_rtx)
1387 /* Rule 3 */
1388 /* Either setting the FP from an offset of the SP,
1389 or adjusting the FP */
1390 if (! frame_pointer_needed)
1391 abort ();
1393 if (GET_CODE (XEXP (src, 0)) == REG
1394 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1395 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1397 offset = INTVAL (XEXP (src, 1));
1398 if (GET_CODE (src) != MINUS)
1399 offset = -offset;
1400 cfa.offset += offset;
1401 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1403 else
1404 abort ();
1406 else
1408 if (GET_CODE (src) == MINUS)
1409 abort ();
1411 /* Rule 4 */
1412 if (GET_CODE (XEXP (src, 0)) == REG
1413 && REGNO (XEXP (src, 0)) == cfa.reg
1414 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1416 /* Setting a temporary CFA register that will be copied
1417 into the FP later on. */
1418 offset = - INTVAL (XEXP (src, 1));
1419 cfa.offset += offset;
1420 cfa.reg = REGNO (dest);
1421 /* Or used to save regs to the stack. */
1422 cfa_temp.reg = cfa.reg;
1423 cfa_temp.offset = cfa.offset;
1426 /* Rule 5 */
1427 else if (GET_CODE (XEXP (src, 0)) == REG
1428 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1429 && XEXP (src, 1) == stack_pointer_rtx)
1431 /* Setting a scratch register that we will use instead
1432 of SP for saving registers to the stack. */
1433 if (cfa.reg != STACK_POINTER_REGNUM)
1434 abort ();
1435 cfa_store.reg = REGNO (dest);
1436 cfa_store.offset = cfa.offset - cfa_temp.offset;
1439 /* Rule 9 */
1440 else if (GET_CODE (src) == LO_SUM
1441 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1443 cfa_temp.reg = REGNO (dest);
1444 cfa_temp.offset = INTVAL (XEXP (src, 1));
1446 else
1447 abort ();
1449 break;
1451 /* Rule 6 */
1452 case CONST_INT:
1453 cfa_temp.reg = REGNO (dest);
1454 cfa_temp.offset = INTVAL (src);
1455 break;
1457 /* Rule 7 */
1458 case IOR:
1459 if (GET_CODE (XEXP (src, 0)) != REG
1460 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1461 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1462 abort ();
1464 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1465 cfa_temp.reg = REGNO (dest);
1466 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1467 break;
1469 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1470 which will fill in all of the bits. */
1471 /* Rule 8 */
1472 case HIGH:
1473 break;
1475 default:
1476 abort ();
1479 def_cfa_1 (label, &cfa);
1480 break;
1482 case MEM:
1483 if (GET_CODE (src) != REG)
1484 abort ();
1486 /* Saving a register to the stack. Make sure dest is relative to the
1487 CFA register. */
1488 switch (GET_CODE (XEXP (dest, 0)))
1490 /* Rule 10 */
1491 /* With a push. */
1492 case PRE_MODIFY:
1493 /* We can't handle variable size modifications. */
1494 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1495 abort ();
1496 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1498 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1499 || cfa_store.reg != STACK_POINTER_REGNUM)
1500 abort ();
1502 cfa_store.offset += offset;
1503 if (cfa.reg == STACK_POINTER_REGNUM)
1504 cfa.offset = cfa_store.offset;
1506 offset = -cfa_store.offset;
1507 break;
1509 /* Rule 11 */
1510 case PRE_INC:
1511 case PRE_DEC:
1512 offset = GET_MODE_SIZE (GET_MODE (dest));
1513 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1514 offset = -offset;
1516 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1517 || cfa_store.reg != STACK_POINTER_REGNUM)
1518 abort ();
1520 cfa_store.offset += offset;
1521 if (cfa.reg == STACK_POINTER_REGNUM)
1522 cfa.offset = cfa_store.offset;
1524 offset = -cfa_store.offset;
1525 break;
1527 /* Rule 12 */
1528 /* With an offset. */
1529 case PLUS:
1530 case MINUS:
1531 case LO_SUM:
1532 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1533 abort ();
1534 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1535 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1536 offset = -offset;
1538 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1539 offset -= cfa_store.offset;
1540 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1541 offset -= cfa_temp.offset;
1542 else
1543 abort ();
1544 break;
1546 /* Rule 13 */
1547 /* Without an offset. */
1548 case REG:
1549 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1550 offset = -cfa_store.offset;
1551 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1552 offset = -cfa_temp.offset;
1553 else
1554 abort ();
1555 break;
1557 /* Rule 14 */
1558 case POST_INC:
1559 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1560 abort ();
1561 offset = -cfa_temp.offset;
1562 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1563 break;
1565 default:
1566 abort ();
1569 if (REGNO (src) != STACK_POINTER_REGNUM
1570 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1571 && (unsigned) REGNO (src) == cfa.reg)
1573 /* We're storing the current CFA reg into the stack. */
1575 if (cfa.offset == 0)
1577 /* If the source register is exactly the CFA, assume
1578 we're saving SP like any other register; this happens
1579 on the ARM. */
1580 def_cfa_1 (label, &cfa);
1581 queue_reg_save (label, stack_pointer_rtx, offset);
1582 break;
1584 else
1586 /* Otherwise, we'll need to look in the stack to
1587 calculate the CFA. */
1588 rtx x = XEXP (dest, 0);
1590 if (GET_CODE (x) != REG)
1591 x = XEXP (x, 0);
1592 if (GET_CODE (x) != REG)
1593 abort ();
1595 cfa.reg = REGNO (x);
1596 cfa.base_offset = offset;
1597 cfa.indirect = 1;
1598 def_cfa_1 (label, &cfa);
1599 break;
1603 def_cfa_1 (label, &cfa);
1604 queue_reg_save (label, src, offset);
1605 break;
1607 default:
1608 abort ();
1612 /* Record call frame debugging information for INSN, which either
1613 sets SP or FP (adjusting how we calculate the frame address) or saves a
1614 register to the stack. If INSN is NULL_RTX, initialize our state. */
1616 void
1617 dwarf2out_frame_debug (insn)
1618 rtx insn;
1620 const char *label;
1621 rtx src;
1623 if (insn == NULL_RTX)
1625 /* Flush any queued register saves. */
1626 flush_queued_reg_saves ();
1628 /* Set up state for generating call frame debug info. */
1629 lookup_cfa (&cfa);
1630 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1631 abort ();
1633 cfa.reg = STACK_POINTER_REGNUM;
1634 cfa_store = cfa;
1635 cfa_temp.reg = -1;
1636 cfa_temp.offset = 0;
1637 return;
1640 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1641 flush_queued_reg_saves ();
1643 if (! RTX_FRAME_RELATED_P (insn))
1645 if (!ACCUMULATE_OUTGOING_ARGS)
1646 dwarf2out_stack_adjust (insn);
1648 return;
1651 label = dwarf2out_cfi_label ();
1652 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1653 if (src)
1654 insn = XEXP (src, 0);
1655 else
1656 insn = PATTERN (insn);
1658 dwarf2out_frame_debug_expr (insn, label);
1661 /* Output a Call Frame Information opcode and its operand(s). */
1663 static void
1664 output_cfi (cfi, fde, for_eh)
1665 dw_cfi_ref cfi;
1666 dw_fde_ref fde;
1667 int for_eh;
1669 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1670 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1671 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1672 "DW_CFA_advance_loc 0x%lx",
1673 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1674 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1676 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1677 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1678 "DW_CFA_offset, column 0x%lx",
1679 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1680 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1682 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1683 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1684 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1685 "DW_CFA_restore, column 0x%lx",
1686 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1687 else
1689 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1690 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1692 switch (cfi->dw_cfi_opc)
1694 case DW_CFA_set_loc:
1695 if (for_eh)
1696 dw2_asm_output_encoded_addr_rtx (
1697 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1698 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1699 NULL);
1700 else
1701 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1702 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1703 break;
1705 case DW_CFA_advance_loc1:
1706 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1707 fde->dw_fde_current_label, NULL);
1708 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1709 break;
1711 case DW_CFA_advance_loc2:
1712 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1713 fde->dw_fde_current_label, NULL);
1714 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1715 break;
1717 case DW_CFA_advance_loc4:
1718 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1719 fde->dw_fde_current_label, NULL);
1720 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1721 break;
1723 case DW_CFA_MIPS_advance_loc8:
1724 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1725 fde->dw_fde_current_label, NULL);
1726 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1727 break;
1729 case DW_CFA_offset_extended:
1730 case DW_CFA_def_cfa:
1731 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1732 NULL);
1733 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1734 break;
1736 case DW_CFA_offset_extended_sf:
1737 case DW_CFA_def_cfa_sf:
1738 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1739 NULL);
1740 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1741 break;
1743 case DW_CFA_restore_extended:
1744 case DW_CFA_undefined:
1745 case DW_CFA_same_value:
1746 case DW_CFA_def_cfa_register:
1747 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1748 NULL);
1749 break;
1751 case DW_CFA_register:
1752 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1753 NULL);
1754 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num,
1755 NULL);
1756 break;
1758 case DW_CFA_def_cfa_offset:
1759 case DW_CFA_GNU_args_size:
1760 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1761 break;
1763 case DW_CFA_def_cfa_offset_sf:
1764 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1765 break;
1767 case DW_CFA_GNU_window_save:
1768 break;
1770 case DW_CFA_def_cfa_expression:
1771 case DW_CFA_expression:
1772 output_cfa_loc (cfi);
1773 break;
1775 case DW_CFA_GNU_negative_offset_extended:
1776 /* Obsoleted by DW_CFA_offset_extended_sf. */
1777 abort ();
1779 default:
1780 break;
1785 /* Output the call frame information used to used to record information
1786 that relates to calculating the frame pointer, and records the
1787 location of saved registers. */
1789 static void
1790 output_call_frame_info (for_eh)
1791 int for_eh;
1793 unsigned int i;
1794 dw_fde_ref fde;
1795 dw_cfi_ref cfi;
1796 char l1[20], l2[20], section_start_label[20];
1797 int any_lsda_needed = 0;
1798 char augmentation[6];
1799 int augmentation_size;
1800 int fde_encoding = DW_EH_PE_absptr;
1801 int per_encoding = DW_EH_PE_absptr;
1802 int lsda_encoding = DW_EH_PE_absptr;
1804 /* Don't emit a CIE if there won't be any FDEs. */
1805 if (fde_table_in_use == 0)
1806 return;
1808 /* If we don't have any functions we'll want to unwind out of, don't emit any
1809 EH unwind information. */
1810 if (for_eh)
1812 int any_eh_needed = flag_asynchronous_unwind_tables;
1814 for (i = 0; i < fde_table_in_use; i++)
1815 if (fde_table[i].uses_eh_lsda)
1816 any_eh_needed = any_lsda_needed = 1;
1817 else if (! fde_table[i].nothrow)
1818 any_eh_needed = 1;
1820 if (! any_eh_needed)
1821 return;
1824 /* We're going to be generating comments, so turn on app. */
1825 if (flag_debug_asm)
1826 app_enable ();
1828 if (for_eh)
1829 (*targetm.asm_out.eh_frame_section) ();
1830 else
1831 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1833 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1834 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1836 /* Output the CIE. */
1837 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1838 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1839 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1840 "Length of Common Information Entry");
1841 ASM_OUTPUT_LABEL (asm_out_file, l1);
1843 /* Now that the CIE pointer is PC-relative for EH,
1844 use 0 to identify the CIE. */
1845 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1846 (for_eh ? 0 : DW_CIE_ID),
1847 "CIE Identifier Tag");
1849 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1851 augmentation[0] = 0;
1852 augmentation_size = 0;
1853 if (for_eh)
1855 char *p;
1857 /* Augmentation:
1858 z Indicates that a uleb128 is present to size the
1859 augmentation section.
1860 L Indicates the encoding (and thus presence) of
1861 an LSDA pointer in the FDE augmentation.
1862 R Indicates a non-default pointer encoding for
1863 FDE code pointers.
1864 P Indicates the presence of an encoding + language
1865 personality routine in the CIE augmentation. */
1867 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1868 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1869 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1871 p = augmentation + 1;
1872 if (eh_personality_libfunc)
1874 *p++ = 'P';
1875 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1877 if (any_lsda_needed)
1879 *p++ = 'L';
1880 augmentation_size += 1;
1882 if (fde_encoding != DW_EH_PE_absptr)
1884 *p++ = 'R';
1885 augmentation_size += 1;
1887 if (p > augmentation + 1)
1889 augmentation[0] = 'z';
1890 *p = '\0';
1893 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1894 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1896 int offset = ( 4 /* Length */
1897 + 4 /* CIE Id */
1898 + 1 /* CIE version */
1899 + strlen (augmentation) + 1 /* Augmentation */
1900 + size_of_uleb128 (1) /* Code alignment */
1901 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1902 + 1 /* RA column */
1903 + 1 /* Augmentation size */
1904 + 1 /* Personality encoding */ );
1905 int pad = -offset & (PTR_SIZE - 1);
1907 augmentation_size += pad;
1909 /* Augmentations should be small, so there's scarce need to
1910 iterate for a solution. Die if we exceed one uleb128 byte. */
1911 if (size_of_uleb128 (augmentation_size) != 1)
1912 abort ();
1916 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1917 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1918 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1919 "CIE Data Alignment Factor");
1920 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1922 if (augmentation[0])
1924 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1925 if (eh_personality_libfunc)
1927 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1928 eh_data_format_name (per_encoding));
1929 dw2_asm_output_encoded_addr_rtx (per_encoding,
1930 eh_personality_libfunc, NULL);
1933 if (any_lsda_needed)
1934 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1935 eh_data_format_name (lsda_encoding));
1937 if (fde_encoding != DW_EH_PE_absptr)
1938 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1939 eh_data_format_name (fde_encoding));
1942 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1943 output_cfi (cfi, NULL, for_eh);
1945 /* Pad the CIE out to an address sized boundary. */
1946 ASM_OUTPUT_ALIGN (asm_out_file,
1947 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1948 ASM_OUTPUT_LABEL (asm_out_file, l2);
1950 /* Loop through all of the FDE's. */
1951 for (i = 0; i < fde_table_in_use; i++)
1953 fde = &fde_table[i];
1955 /* Don't emit EH unwind info for leaf functions that don't need it. */
1956 if (!flag_asynchronous_unwind_tables && for_eh
1957 && (fde->nothrow || fde->all_throwers_are_sibcalls)
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 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2047 dw2_asm_output_data (4, 0, "End of Table");
2048 #ifdef MIPS_DEBUGGING_INFO
2049 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2050 get a value of 0. Putting .align 0 after the label fixes it. */
2051 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2052 #endif
2054 /* Turn off app to make assembly quicker. */
2055 if (flag_debug_asm)
2056 app_disable ();
2059 /* Output a marker (i.e. a label) for the beginning of a function, before
2060 the prologue. */
2062 void
2063 dwarf2out_begin_prologue (line, file)
2064 unsigned int line ATTRIBUTE_UNUSED;
2065 const char *file ATTRIBUTE_UNUSED;
2067 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2068 dw_fde_ref fde;
2070 current_function_func_begin_label = 0;
2072 #ifdef IA64_UNWIND_INFO
2073 /* ??? current_function_func_begin_label is also used by except.c
2074 for call-site information. We must emit this label if it might
2075 be used. */
2076 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2077 && ! dwarf2out_do_frame ())
2078 return;
2079 #else
2080 if (! dwarf2out_do_frame ())
2081 return;
2082 #endif
2084 function_section (current_function_decl);
2085 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2086 current_function_funcdef_no);
2087 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2088 current_function_funcdef_no);
2089 current_function_func_begin_label = get_identifier (label);
2091 #ifdef IA64_UNWIND_INFO
2092 /* We can elide the fde allocation if we're not emitting debug info. */
2093 if (! dwarf2out_do_frame ())
2094 return;
2095 #endif
2097 /* Expand the fde table if necessary. */
2098 if (fde_table_in_use == fde_table_allocated)
2100 fde_table_allocated += FDE_TABLE_INCREMENT;
2101 fde_table
2102 = (dw_fde_ref) xrealloc (fde_table,
2103 fde_table_allocated * sizeof (dw_fde_node));
2106 /* Record the FDE associated with this function. */
2107 current_funcdef_fde = fde_table_in_use;
2109 /* Add the new FDE at the end of the fde_table. */
2110 fde = &fde_table[fde_table_in_use++];
2111 fde->dw_fde_begin = xstrdup (label);
2112 fde->dw_fde_current_label = NULL;
2113 fde->dw_fde_end = NULL;
2114 fde->dw_fde_cfi = NULL;
2115 fde->funcdef_number = current_function_funcdef_no;
2116 fde->nothrow = current_function_nothrow;
2117 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2118 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2120 args_size = old_args_size = 0;
2122 /* We only want to output line number information for the genuine dwarf2
2123 prologue case, not the eh frame case. */
2124 #ifdef DWARF2_DEBUGGING_INFO
2125 if (file)
2126 dwarf2out_source_line (line, file);
2127 #endif
2130 /* Output a marker (i.e. a label) for the absolute end of the generated code
2131 for a function definition. This gets called *after* the epilogue code has
2132 been generated. */
2134 void
2135 dwarf2out_end_epilogue (line, file)
2136 unsigned int line ATTRIBUTE_UNUSED;
2137 const char *file ATTRIBUTE_UNUSED;
2139 dw_fde_ref fde;
2140 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2142 /* Output a label to mark the endpoint of the code generated for this
2143 function. */
2144 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2145 current_function_funcdef_no);
2146 ASM_OUTPUT_LABEL (asm_out_file, label);
2147 fde = &fde_table[fde_table_in_use - 1];
2148 fde->dw_fde_end = xstrdup (label);
2151 void
2152 dwarf2out_frame_init ()
2154 /* Allocate the initial hunk of the fde_table. */
2155 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2156 fde_table_allocated = FDE_TABLE_INCREMENT;
2157 fde_table_in_use = 0;
2159 /* Generate the CFA instructions common to all FDE's. Do it now for the
2160 sake of lookup_cfa. */
2162 #ifdef DWARF2_UNWIND_INFO
2163 /* On entry, the Canonical Frame Address is at SP. */
2164 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2165 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2166 #endif
2169 void
2170 dwarf2out_frame_finish ()
2172 /* Output call frame information. */
2173 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2174 output_call_frame_info (0);
2176 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2177 output_call_frame_info (1);
2180 /* And now, the subset of the debugging information support code necessary
2181 for emitting location expressions. */
2183 /* We need some way to distinguish DW_OP_addr with a direct symbol
2184 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2185 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2188 typedef struct dw_val_struct *dw_val_ref;
2189 typedef struct die_struct *dw_die_ref;
2190 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2191 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2193 /* Each DIE may have a series of attribute/value pairs. Values
2194 can take on several forms. The forms that are used in this
2195 implementation are listed below. */
2197 typedef enum
2199 dw_val_class_addr,
2200 dw_val_class_offset,
2201 dw_val_class_loc,
2202 dw_val_class_loc_list,
2203 dw_val_class_range_list,
2204 dw_val_class_const,
2205 dw_val_class_unsigned_const,
2206 dw_val_class_long_long,
2207 dw_val_class_float,
2208 dw_val_class_flag,
2209 dw_val_class_die_ref,
2210 dw_val_class_fde_ref,
2211 dw_val_class_lbl_id,
2212 dw_val_class_lbl_offset,
2213 dw_val_class_str
2215 dw_val_class;
2217 /* Describe a double word constant value. */
2218 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2220 typedef struct dw_long_long_struct
2222 unsigned long hi;
2223 unsigned long low;
2225 dw_long_long_const;
2227 /* Describe a floating point constant value. */
2229 typedef struct dw_fp_struct
2231 long *array;
2232 unsigned length;
2234 dw_float_const;
2236 /* The dw_val_node describes an attribute's value, as it is
2237 represented internally. */
2239 typedef struct dw_val_struct
2241 dw_val_class val_class;
2242 union
2244 rtx val_addr;
2245 long unsigned val_offset;
2246 dw_loc_list_ref val_loc_list;
2247 dw_loc_descr_ref val_loc;
2248 long int val_int;
2249 long unsigned val_unsigned;
2250 dw_long_long_const val_long_long;
2251 dw_float_const val_float;
2252 struct
2254 dw_die_ref die;
2255 int external;
2256 } val_die_ref;
2257 unsigned val_fde_index;
2258 struct indirect_string_node *val_str;
2259 char *val_lbl_id;
2260 unsigned char val_flag;
2264 dw_val_node;
2266 /* Locations in memory are described using a sequence of stack machine
2267 operations. */
2269 typedef struct dw_loc_descr_struct
2271 dw_loc_descr_ref dw_loc_next;
2272 enum dwarf_location_atom dw_loc_opc;
2273 dw_val_node dw_loc_oprnd1;
2274 dw_val_node dw_loc_oprnd2;
2275 int dw_loc_addr;
2277 dw_loc_descr_node;
2279 /* Location lists are ranges + location descriptions for that range,
2280 so you can track variables that are in different places over
2281 their entire life. */
2282 typedef struct dw_loc_list_struct
2284 dw_loc_list_ref dw_loc_next;
2285 const char *begin; /* Label for begin address of range */
2286 const char *end; /* Label for end address of range */
2287 char *ll_symbol; /* Label for beginning of location list.
2288 Only on head of list */
2289 const char *section; /* Section this loclist is relative to */
2290 dw_loc_descr_ref expr;
2291 } dw_loc_list_node;
2293 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2294 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2295 unsigned long,
2296 unsigned long));
2297 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2298 dw_loc_descr_ref));
2299 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2300 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2301 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2302 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2304 /* Convert a DWARF stack opcode into its string name. */
2306 static const char *
2307 dwarf_stack_op_name (op)
2308 unsigned op;
2310 switch (op)
2312 case DW_OP_addr:
2313 case INTERNAL_DW_OP_tls_addr:
2314 return "DW_OP_addr";
2315 case DW_OP_deref:
2316 return "DW_OP_deref";
2317 case DW_OP_const1u:
2318 return "DW_OP_const1u";
2319 case DW_OP_const1s:
2320 return "DW_OP_const1s";
2321 case DW_OP_const2u:
2322 return "DW_OP_const2u";
2323 case DW_OP_const2s:
2324 return "DW_OP_const2s";
2325 case DW_OP_const4u:
2326 return "DW_OP_const4u";
2327 case DW_OP_const4s:
2328 return "DW_OP_const4s";
2329 case DW_OP_const8u:
2330 return "DW_OP_const8u";
2331 case DW_OP_const8s:
2332 return "DW_OP_const8s";
2333 case DW_OP_constu:
2334 return "DW_OP_constu";
2335 case DW_OP_consts:
2336 return "DW_OP_consts";
2337 case DW_OP_dup:
2338 return "DW_OP_dup";
2339 case DW_OP_drop:
2340 return "DW_OP_drop";
2341 case DW_OP_over:
2342 return "DW_OP_over";
2343 case DW_OP_pick:
2344 return "DW_OP_pick";
2345 case DW_OP_swap:
2346 return "DW_OP_swap";
2347 case DW_OP_rot:
2348 return "DW_OP_rot";
2349 case DW_OP_xderef:
2350 return "DW_OP_xderef";
2351 case DW_OP_abs:
2352 return "DW_OP_abs";
2353 case DW_OP_and:
2354 return "DW_OP_and";
2355 case DW_OP_div:
2356 return "DW_OP_div";
2357 case DW_OP_minus:
2358 return "DW_OP_minus";
2359 case DW_OP_mod:
2360 return "DW_OP_mod";
2361 case DW_OP_mul:
2362 return "DW_OP_mul";
2363 case DW_OP_neg:
2364 return "DW_OP_neg";
2365 case DW_OP_not:
2366 return "DW_OP_not";
2367 case DW_OP_or:
2368 return "DW_OP_or";
2369 case DW_OP_plus:
2370 return "DW_OP_plus";
2371 case DW_OP_plus_uconst:
2372 return "DW_OP_plus_uconst";
2373 case DW_OP_shl:
2374 return "DW_OP_shl";
2375 case DW_OP_shr:
2376 return "DW_OP_shr";
2377 case DW_OP_shra:
2378 return "DW_OP_shra";
2379 case DW_OP_xor:
2380 return "DW_OP_xor";
2381 case DW_OP_bra:
2382 return "DW_OP_bra";
2383 case DW_OP_eq:
2384 return "DW_OP_eq";
2385 case DW_OP_ge:
2386 return "DW_OP_ge";
2387 case DW_OP_gt:
2388 return "DW_OP_gt";
2389 case DW_OP_le:
2390 return "DW_OP_le";
2391 case DW_OP_lt:
2392 return "DW_OP_lt";
2393 case DW_OP_ne:
2394 return "DW_OP_ne";
2395 case DW_OP_skip:
2396 return "DW_OP_skip";
2397 case DW_OP_lit0:
2398 return "DW_OP_lit0";
2399 case DW_OP_lit1:
2400 return "DW_OP_lit1";
2401 case DW_OP_lit2:
2402 return "DW_OP_lit2";
2403 case DW_OP_lit3:
2404 return "DW_OP_lit3";
2405 case DW_OP_lit4:
2406 return "DW_OP_lit4";
2407 case DW_OP_lit5:
2408 return "DW_OP_lit5";
2409 case DW_OP_lit6:
2410 return "DW_OP_lit6";
2411 case DW_OP_lit7:
2412 return "DW_OP_lit7";
2413 case DW_OP_lit8:
2414 return "DW_OP_lit8";
2415 case DW_OP_lit9:
2416 return "DW_OP_lit9";
2417 case DW_OP_lit10:
2418 return "DW_OP_lit10";
2419 case DW_OP_lit11:
2420 return "DW_OP_lit11";
2421 case DW_OP_lit12:
2422 return "DW_OP_lit12";
2423 case DW_OP_lit13:
2424 return "DW_OP_lit13";
2425 case DW_OP_lit14:
2426 return "DW_OP_lit14";
2427 case DW_OP_lit15:
2428 return "DW_OP_lit15";
2429 case DW_OP_lit16:
2430 return "DW_OP_lit16";
2431 case DW_OP_lit17:
2432 return "DW_OP_lit17";
2433 case DW_OP_lit18:
2434 return "DW_OP_lit18";
2435 case DW_OP_lit19:
2436 return "DW_OP_lit19";
2437 case DW_OP_lit20:
2438 return "DW_OP_lit20";
2439 case DW_OP_lit21:
2440 return "DW_OP_lit21";
2441 case DW_OP_lit22:
2442 return "DW_OP_lit22";
2443 case DW_OP_lit23:
2444 return "DW_OP_lit23";
2445 case DW_OP_lit24:
2446 return "DW_OP_lit24";
2447 case DW_OP_lit25:
2448 return "DW_OP_lit25";
2449 case DW_OP_lit26:
2450 return "DW_OP_lit26";
2451 case DW_OP_lit27:
2452 return "DW_OP_lit27";
2453 case DW_OP_lit28:
2454 return "DW_OP_lit28";
2455 case DW_OP_lit29:
2456 return "DW_OP_lit29";
2457 case DW_OP_lit30:
2458 return "DW_OP_lit30";
2459 case DW_OP_lit31:
2460 return "DW_OP_lit31";
2461 case DW_OP_reg0:
2462 return "DW_OP_reg0";
2463 case DW_OP_reg1:
2464 return "DW_OP_reg1";
2465 case DW_OP_reg2:
2466 return "DW_OP_reg2";
2467 case DW_OP_reg3:
2468 return "DW_OP_reg3";
2469 case DW_OP_reg4:
2470 return "DW_OP_reg4";
2471 case DW_OP_reg5:
2472 return "DW_OP_reg5";
2473 case DW_OP_reg6:
2474 return "DW_OP_reg6";
2475 case DW_OP_reg7:
2476 return "DW_OP_reg7";
2477 case DW_OP_reg8:
2478 return "DW_OP_reg8";
2479 case DW_OP_reg9:
2480 return "DW_OP_reg9";
2481 case DW_OP_reg10:
2482 return "DW_OP_reg10";
2483 case DW_OP_reg11:
2484 return "DW_OP_reg11";
2485 case DW_OP_reg12:
2486 return "DW_OP_reg12";
2487 case DW_OP_reg13:
2488 return "DW_OP_reg13";
2489 case DW_OP_reg14:
2490 return "DW_OP_reg14";
2491 case DW_OP_reg15:
2492 return "DW_OP_reg15";
2493 case DW_OP_reg16:
2494 return "DW_OP_reg16";
2495 case DW_OP_reg17:
2496 return "DW_OP_reg17";
2497 case DW_OP_reg18:
2498 return "DW_OP_reg18";
2499 case DW_OP_reg19:
2500 return "DW_OP_reg19";
2501 case DW_OP_reg20:
2502 return "DW_OP_reg20";
2503 case DW_OP_reg21:
2504 return "DW_OP_reg21";
2505 case DW_OP_reg22:
2506 return "DW_OP_reg22";
2507 case DW_OP_reg23:
2508 return "DW_OP_reg23";
2509 case DW_OP_reg24:
2510 return "DW_OP_reg24";
2511 case DW_OP_reg25:
2512 return "DW_OP_reg25";
2513 case DW_OP_reg26:
2514 return "DW_OP_reg26";
2515 case DW_OP_reg27:
2516 return "DW_OP_reg27";
2517 case DW_OP_reg28:
2518 return "DW_OP_reg28";
2519 case DW_OP_reg29:
2520 return "DW_OP_reg29";
2521 case DW_OP_reg30:
2522 return "DW_OP_reg30";
2523 case DW_OP_reg31:
2524 return "DW_OP_reg31";
2525 case DW_OP_breg0:
2526 return "DW_OP_breg0";
2527 case DW_OP_breg1:
2528 return "DW_OP_breg1";
2529 case DW_OP_breg2:
2530 return "DW_OP_breg2";
2531 case DW_OP_breg3:
2532 return "DW_OP_breg3";
2533 case DW_OP_breg4:
2534 return "DW_OP_breg4";
2535 case DW_OP_breg5:
2536 return "DW_OP_breg5";
2537 case DW_OP_breg6:
2538 return "DW_OP_breg6";
2539 case DW_OP_breg7:
2540 return "DW_OP_breg7";
2541 case DW_OP_breg8:
2542 return "DW_OP_breg8";
2543 case DW_OP_breg9:
2544 return "DW_OP_breg9";
2545 case DW_OP_breg10:
2546 return "DW_OP_breg10";
2547 case DW_OP_breg11:
2548 return "DW_OP_breg11";
2549 case DW_OP_breg12:
2550 return "DW_OP_breg12";
2551 case DW_OP_breg13:
2552 return "DW_OP_breg13";
2553 case DW_OP_breg14:
2554 return "DW_OP_breg14";
2555 case DW_OP_breg15:
2556 return "DW_OP_breg15";
2557 case DW_OP_breg16:
2558 return "DW_OP_breg16";
2559 case DW_OP_breg17:
2560 return "DW_OP_breg17";
2561 case DW_OP_breg18:
2562 return "DW_OP_breg18";
2563 case DW_OP_breg19:
2564 return "DW_OP_breg19";
2565 case DW_OP_breg20:
2566 return "DW_OP_breg20";
2567 case DW_OP_breg21:
2568 return "DW_OP_breg21";
2569 case DW_OP_breg22:
2570 return "DW_OP_breg22";
2571 case DW_OP_breg23:
2572 return "DW_OP_breg23";
2573 case DW_OP_breg24:
2574 return "DW_OP_breg24";
2575 case DW_OP_breg25:
2576 return "DW_OP_breg25";
2577 case DW_OP_breg26:
2578 return "DW_OP_breg26";
2579 case DW_OP_breg27:
2580 return "DW_OP_breg27";
2581 case DW_OP_breg28:
2582 return "DW_OP_breg28";
2583 case DW_OP_breg29:
2584 return "DW_OP_breg29";
2585 case DW_OP_breg30:
2586 return "DW_OP_breg30";
2587 case DW_OP_breg31:
2588 return "DW_OP_breg31";
2589 case DW_OP_regx:
2590 return "DW_OP_regx";
2591 case DW_OP_fbreg:
2592 return "DW_OP_fbreg";
2593 case DW_OP_bregx:
2594 return "DW_OP_bregx";
2595 case DW_OP_piece:
2596 return "DW_OP_piece";
2597 case DW_OP_deref_size:
2598 return "DW_OP_deref_size";
2599 case DW_OP_xderef_size:
2600 return "DW_OP_xderef_size";
2601 case DW_OP_nop:
2602 return "DW_OP_nop";
2603 case DW_OP_push_object_address:
2604 return "DW_OP_push_object_address";
2605 case DW_OP_call2:
2606 return "DW_OP_call2";
2607 case DW_OP_call4:
2608 return "DW_OP_call4";
2609 case DW_OP_call_ref:
2610 return "DW_OP_call_ref";
2611 case DW_OP_GNU_push_tls_address:
2612 return "DW_OP_GNU_push_tls_address";
2613 default:
2614 return "OP_<unknown>";
2618 /* Return a pointer to a newly allocated location description. Location
2619 descriptions are simple expression terms that can be strung
2620 together to form more complicated location (address) descriptions. */
2622 static inline dw_loc_descr_ref
2623 new_loc_descr (op, oprnd1, oprnd2)
2624 enum dwarf_location_atom op;
2625 unsigned long oprnd1;
2626 unsigned long oprnd2;
2628 /* Use xcalloc here so we clear out all of the long_long constant in
2629 the union. */
2630 dw_loc_descr_ref descr
2631 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2633 descr->dw_loc_opc = op;
2634 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2635 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2636 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2637 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2639 return descr;
2643 /* Add a location description term to a location description expression. */
2645 static inline void
2646 add_loc_descr (list_head, descr)
2647 dw_loc_descr_ref *list_head;
2648 dw_loc_descr_ref descr;
2650 dw_loc_descr_ref *d;
2652 /* Find the end of the chain. */
2653 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2656 *d = descr;
2659 /* Return the size of a location descriptor. */
2661 static unsigned long
2662 size_of_loc_descr (loc)
2663 dw_loc_descr_ref loc;
2665 unsigned long size = 1;
2667 switch (loc->dw_loc_opc)
2669 case DW_OP_addr:
2670 case INTERNAL_DW_OP_tls_addr:
2671 size += DWARF2_ADDR_SIZE;
2672 break;
2673 case DW_OP_const1u:
2674 case DW_OP_const1s:
2675 size += 1;
2676 break;
2677 case DW_OP_const2u:
2678 case DW_OP_const2s:
2679 size += 2;
2680 break;
2681 case DW_OP_const4u:
2682 case DW_OP_const4s:
2683 size += 4;
2684 break;
2685 case DW_OP_const8u:
2686 case DW_OP_const8s:
2687 size += 8;
2688 break;
2689 case DW_OP_constu:
2690 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2691 break;
2692 case DW_OP_consts:
2693 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2694 break;
2695 case DW_OP_pick:
2696 size += 1;
2697 break;
2698 case DW_OP_plus_uconst:
2699 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2700 break;
2701 case DW_OP_skip:
2702 case DW_OP_bra:
2703 size += 2;
2704 break;
2705 case DW_OP_breg0:
2706 case DW_OP_breg1:
2707 case DW_OP_breg2:
2708 case DW_OP_breg3:
2709 case DW_OP_breg4:
2710 case DW_OP_breg5:
2711 case DW_OP_breg6:
2712 case DW_OP_breg7:
2713 case DW_OP_breg8:
2714 case DW_OP_breg9:
2715 case DW_OP_breg10:
2716 case DW_OP_breg11:
2717 case DW_OP_breg12:
2718 case DW_OP_breg13:
2719 case DW_OP_breg14:
2720 case DW_OP_breg15:
2721 case DW_OP_breg16:
2722 case DW_OP_breg17:
2723 case DW_OP_breg18:
2724 case DW_OP_breg19:
2725 case DW_OP_breg20:
2726 case DW_OP_breg21:
2727 case DW_OP_breg22:
2728 case DW_OP_breg23:
2729 case DW_OP_breg24:
2730 case DW_OP_breg25:
2731 case DW_OP_breg26:
2732 case DW_OP_breg27:
2733 case DW_OP_breg28:
2734 case DW_OP_breg29:
2735 case DW_OP_breg30:
2736 case DW_OP_breg31:
2737 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2738 break;
2739 case DW_OP_regx:
2740 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2741 break;
2742 case DW_OP_fbreg:
2743 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2744 break;
2745 case DW_OP_bregx:
2746 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2747 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2748 break;
2749 case DW_OP_piece:
2750 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2751 break;
2752 case DW_OP_deref_size:
2753 case DW_OP_xderef_size:
2754 size += 1;
2755 break;
2756 case DW_OP_call2:
2757 size += 2;
2758 break;
2759 case DW_OP_call4:
2760 size += 4;
2761 break;
2762 case DW_OP_call_ref:
2763 size += DWARF2_ADDR_SIZE;
2764 break;
2765 default:
2766 break;
2769 return size;
2772 /* Return the size of a series of location descriptors. */
2774 static unsigned long
2775 size_of_locs (loc)
2776 dw_loc_descr_ref loc;
2778 unsigned long size;
2780 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
2782 loc->dw_loc_addr = size;
2783 size += size_of_loc_descr (loc);
2786 return size;
2789 /* Output location description stack opcode's operands (if any). */
2791 static void
2792 output_loc_operands (loc)
2793 dw_loc_descr_ref loc;
2795 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2796 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2798 switch (loc->dw_loc_opc)
2800 #ifdef DWARF2_DEBUGGING_INFO
2801 case DW_OP_addr:
2802 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2803 break;
2804 case DW_OP_const2u:
2805 case DW_OP_const2s:
2806 dw2_asm_output_data (2, val1->v.val_int, NULL);
2807 break;
2808 case DW_OP_const4u:
2809 case DW_OP_const4s:
2810 dw2_asm_output_data (4, val1->v.val_int, NULL);
2811 break;
2812 case DW_OP_const8u:
2813 case DW_OP_const8s:
2814 if (HOST_BITS_PER_LONG < 64)
2815 abort ();
2816 dw2_asm_output_data (8, val1->v.val_int, NULL);
2817 break;
2818 case DW_OP_skip:
2819 case DW_OP_bra:
2821 int offset;
2823 if (val1->val_class == dw_val_class_loc)
2824 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2825 else
2826 abort ();
2828 dw2_asm_output_data (2, offset, NULL);
2830 break;
2831 #else
2832 case DW_OP_addr:
2833 case DW_OP_const2u:
2834 case DW_OP_const2s:
2835 case DW_OP_const4u:
2836 case DW_OP_const4s:
2837 case DW_OP_const8u:
2838 case DW_OP_const8s:
2839 case DW_OP_skip:
2840 case DW_OP_bra:
2841 /* We currently don't make any attempt to make sure these are
2842 aligned properly like we do for the main unwind info, so
2843 don't support emitting things larger than a byte if we're
2844 only doing unwinding. */
2845 abort ();
2846 #endif
2847 case DW_OP_const1u:
2848 case DW_OP_const1s:
2849 dw2_asm_output_data (1, val1->v.val_int, NULL);
2850 break;
2851 case DW_OP_constu:
2852 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2853 break;
2854 case DW_OP_consts:
2855 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2856 break;
2857 case DW_OP_pick:
2858 dw2_asm_output_data (1, val1->v.val_int, NULL);
2859 break;
2860 case DW_OP_plus_uconst:
2861 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2862 break;
2863 case DW_OP_breg0:
2864 case DW_OP_breg1:
2865 case DW_OP_breg2:
2866 case DW_OP_breg3:
2867 case DW_OP_breg4:
2868 case DW_OP_breg5:
2869 case DW_OP_breg6:
2870 case DW_OP_breg7:
2871 case DW_OP_breg8:
2872 case DW_OP_breg9:
2873 case DW_OP_breg10:
2874 case DW_OP_breg11:
2875 case DW_OP_breg12:
2876 case DW_OP_breg13:
2877 case DW_OP_breg14:
2878 case DW_OP_breg15:
2879 case DW_OP_breg16:
2880 case DW_OP_breg17:
2881 case DW_OP_breg18:
2882 case DW_OP_breg19:
2883 case DW_OP_breg20:
2884 case DW_OP_breg21:
2885 case DW_OP_breg22:
2886 case DW_OP_breg23:
2887 case DW_OP_breg24:
2888 case DW_OP_breg25:
2889 case DW_OP_breg26:
2890 case DW_OP_breg27:
2891 case DW_OP_breg28:
2892 case DW_OP_breg29:
2893 case DW_OP_breg30:
2894 case DW_OP_breg31:
2895 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2896 break;
2897 case DW_OP_regx:
2898 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2899 break;
2900 case DW_OP_fbreg:
2901 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2902 break;
2903 case DW_OP_bregx:
2904 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2905 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2906 break;
2907 case DW_OP_piece:
2908 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2909 break;
2910 case DW_OP_deref_size:
2911 case DW_OP_xderef_size:
2912 dw2_asm_output_data (1, val1->v.val_int, NULL);
2913 break;
2915 case INTERNAL_DW_OP_tls_addr:
2916 #ifdef ASM_OUTPUT_DWARF_DTPREL
2917 ASM_OUTPUT_DWARF_DTPREL (asm_out_file, DWARF2_ADDR_SIZE,
2918 val1->v.val_addr);
2919 fputc ('\n', asm_out_file);
2920 #else
2921 abort ();
2922 #endif
2923 break;
2925 default:
2926 /* Other codes have no operands. */
2927 break;
2931 /* Output a sequence of location operations. */
2933 static void
2934 output_loc_sequence (loc)
2935 dw_loc_descr_ref loc;
2937 for (; loc != NULL; loc = loc->dw_loc_next)
2939 /* Output the opcode. */
2940 dw2_asm_output_data (1, loc->dw_loc_opc,
2941 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2943 /* Output the operand(s) (if any). */
2944 output_loc_operands (loc);
2948 /* This routine will generate the correct assembly data for a location
2949 description based on a cfi entry with a complex address. */
2951 static void
2952 output_cfa_loc (cfi)
2953 dw_cfi_ref cfi;
2955 dw_loc_descr_ref loc;
2956 unsigned long size;
2958 /* Output the size of the block. */
2959 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2960 size = size_of_locs (loc);
2961 dw2_asm_output_data_uleb128 (size, NULL);
2963 /* Now output the operations themselves. */
2964 output_loc_sequence (loc);
2967 /* This function builds a dwarf location descriptor sequence from
2968 a dw_cfa_location. */
2970 static struct dw_loc_descr_struct *
2971 build_cfa_loc (cfa)
2972 dw_cfa_location *cfa;
2974 struct dw_loc_descr_struct *head, *tmp;
2976 if (cfa->indirect == 0)
2977 abort ();
2979 if (cfa->base_offset)
2981 if (cfa->reg <= 31)
2982 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2983 else
2984 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2986 else if (cfa->reg <= 31)
2987 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2988 else
2989 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2991 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2992 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2993 add_loc_descr (&head, tmp);
2994 if (cfa->offset != 0)
2996 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2997 add_loc_descr (&head, tmp);
3000 return head;
3003 /* This function fills in aa dw_cfa_location structure from a dwarf location
3004 descriptor sequence. */
3006 static void
3007 get_cfa_from_loc_descr (cfa, loc)
3008 dw_cfa_location *cfa;
3009 struct dw_loc_descr_struct *loc;
3011 struct dw_loc_descr_struct *ptr;
3012 cfa->offset = 0;
3013 cfa->base_offset = 0;
3014 cfa->indirect = 0;
3015 cfa->reg = -1;
3017 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3019 enum dwarf_location_atom op = ptr->dw_loc_opc;
3021 switch (op)
3023 case DW_OP_reg0:
3024 case DW_OP_reg1:
3025 case DW_OP_reg2:
3026 case DW_OP_reg3:
3027 case DW_OP_reg4:
3028 case DW_OP_reg5:
3029 case DW_OP_reg6:
3030 case DW_OP_reg7:
3031 case DW_OP_reg8:
3032 case DW_OP_reg9:
3033 case DW_OP_reg10:
3034 case DW_OP_reg11:
3035 case DW_OP_reg12:
3036 case DW_OP_reg13:
3037 case DW_OP_reg14:
3038 case DW_OP_reg15:
3039 case DW_OP_reg16:
3040 case DW_OP_reg17:
3041 case DW_OP_reg18:
3042 case DW_OP_reg19:
3043 case DW_OP_reg20:
3044 case DW_OP_reg21:
3045 case DW_OP_reg22:
3046 case DW_OP_reg23:
3047 case DW_OP_reg24:
3048 case DW_OP_reg25:
3049 case DW_OP_reg26:
3050 case DW_OP_reg27:
3051 case DW_OP_reg28:
3052 case DW_OP_reg29:
3053 case DW_OP_reg30:
3054 case DW_OP_reg31:
3055 cfa->reg = op - DW_OP_reg0;
3056 break;
3057 case DW_OP_regx:
3058 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3059 break;
3060 case DW_OP_breg0:
3061 case DW_OP_breg1:
3062 case DW_OP_breg2:
3063 case DW_OP_breg3:
3064 case DW_OP_breg4:
3065 case DW_OP_breg5:
3066 case DW_OP_breg6:
3067 case DW_OP_breg7:
3068 case DW_OP_breg8:
3069 case DW_OP_breg9:
3070 case DW_OP_breg10:
3071 case DW_OP_breg11:
3072 case DW_OP_breg12:
3073 case DW_OP_breg13:
3074 case DW_OP_breg14:
3075 case DW_OP_breg15:
3076 case DW_OP_breg16:
3077 case DW_OP_breg17:
3078 case DW_OP_breg18:
3079 case DW_OP_breg19:
3080 case DW_OP_breg20:
3081 case DW_OP_breg21:
3082 case DW_OP_breg22:
3083 case DW_OP_breg23:
3084 case DW_OP_breg24:
3085 case DW_OP_breg25:
3086 case DW_OP_breg26:
3087 case DW_OP_breg27:
3088 case DW_OP_breg28:
3089 case DW_OP_breg29:
3090 case DW_OP_breg30:
3091 case DW_OP_breg31:
3092 cfa->reg = op - DW_OP_breg0;
3093 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3094 break;
3095 case DW_OP_bregx:
3096 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3097 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3098 break;
3099 case DW_OP_deref:
3100 cfa->indirect = 1;
3101 break;
3102 case DW_OP_plus_uconst:
3103 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3104 break;
3105 default:
3106 internal_error ("DW_LOC_OP %s not implemented\n",
3107 dwarf_stack_op_name (ptr->dw_loc_opc));
3111 #endif /* .debug_frame support */
3113 /* And now, the support for symbolic debugging information. */
3114 #ifdef DWARF2_DEBUGGING_INFO
3116 /* .debug_str support. */
3117 static hashnode indirect_string_alloc PARAMS ((hash_table *));
3118 static int output_indirect_string PARAMS ((struct cpp_reader *,
3119 hashnode, const PTR));
3122 static void dwarf2out_init PARAMS ((const char *));
3123 static void dwarf2out_finish PARAMS ((const char *));
3124 static void dwarf2out_define PARAMS ((unsigned int, const char *));
3125 static void dwarf2out_undef PARAMS ((unsigned int, const char *));
3126 static void dwarf2out_start_source_file PARAMS ((unsigned, const char *));
3127 static void dwarf2out_end_source_file PARAMS ((unsigned));
3128 static void dwarf2out_begin_block PARAMS ((unsigned, unsigned));
3129 static void dwarf2out_end_block PARAMS ((unsigned, unsigned));
3130 static bool dwarf2out_ignore_block PARAMS ((tree));
3131 static void dwarf2out_global_decl PARAMS ((tree));
3132 static void dwarf2out_abstract_function PARAMS ((tree));
3134 /* The debug hooks structure. */
3136 const struct gcc_debug_hooks dwarf2_debug_hooks =
3138 dwarf2out_init,
3139 dwarf2out_finish,
3140 dwarf2out_define,
3141 dwarf2out_undef,
3142 dwarf2out_start_source_file,
3143 dwarf2out_end_source_file,
3144 dwarf2out_begin_block,
3145 dwarf2out_end_block,
3146 dwarf2out_ignore_block,
3147 dwarf2out_source_line,
3148 dwarf2out_begin_prologue,
3149 debug_nothing_int_charstar, /* end_prologue */
3150 dwarf2out_end_epilogue,
3151 debug_nothing_tree, /* begin_function */
3152 debug_nothing_int, /* end_function */
3153 dwarf2out_decl, /* function_decl */
3154 dwarf2out_global_decl,
3155 debug_nothing_tree, /* deferred_inline_function */
3156 /* The DWARF 2 backend tries to reduce debugging bloat by not
3157 emitting the abstract description of inline functions until
3158 something tries to reference them. */
3159 dwarf2out_abstract_function, /* outlining_inline_function */
3160 debug_nothing_rtx /* label */
3163 /* NOTE: In the comments in this file, many references are made to
3164 "Debugging Information Entries". This term is abbreviated as `DIE'
3165 throughout the remainder of this file. */
3167 /* An internal representation of the DWARF output is built, and then
3168 walked to generate the DWARF debugging info. The walk of the internal
3169 representation is done after the entire program has been compiled.
3170 The types below are used to describe the internal representation. */
3172 /* Various DIE's use offsets relative to the beginning of the
3173 .debug_info section to refer to each other. */
3175 typedef long int dw_offset;
3177 /* Define typedefs here to avoid circular dependencies. */
3179 typedef struct dw_attr_struct *dw_attr_ref;
3180 typedef struct dw_line_info_struct *dw_line_info_ref;
3181 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3182 typedef struct pubname_struct *pubname_ref;
3183 typedef struct dw_ranges_struct *dw_ranges_ref;
3185 /* Each entry in the line_info_table maintains the file and
3186 line number associated with the label generated for that
3187 entry. The label gives the PC value associated with
3188 the line number entry. */
3190 typedef struct dw_line_info_struct
3192 unsigned long dw_file_num;
3193 unsigned long dw_line_num;
3195 dw_line_info_entry;
3197 /* Line information for functions in separate sections; each one gets its
3198 own sequence. */
3199 typedef struct dw_separate_line_info_struct
3201 unsigned long dw_file_num;
3202 unsigned long dw_line_num;
3203 unsigned long function;
3205 dw_separate_line_info_entry;
3207 /* Each DIE attribute has a field specifying the attribute kind,
3208 a link to the next attribute in the chain, and an attribute value.
3209 Attributes are typically linked below the DIE they modify. */
3211 typedef struct dw_attr_struct
3213 enum dwarf_attribute dw_attr;
3214 dw_attr_ref dw_attr_next;
3215 dw_val_node dw_attr_val;
3217 dw_attr_node;
3219 /* The Debugging Information Entry (DIE) structure */
3221 typedef struct die_struct
3223 enum dwarf_tag die_tag;
3224 char *die_symbol;
3225 dw_attr_ref die_attr;
3226 dw_die_ref die_parent;
3227 dw_die_ref die_child;
3228 dw_die_ref die_sib;
3229 dw_offset die_offset;
3230 unsigned long die_abbrev;
3231 int die_mark;
3233 die_node;
3235 /* The pubname structure */
3237 typedef struct pubname_struct
3239 dw_die_ref die;
3240 char *name;
3242 pubname_entry;
3244 struct dw_ranges_struct
3246 int block_num;
3249 /* The limbo die list structure. */
3250 typedef struct limbo_die_struct
3252 dw_die_ref die;
3253 tree created_for;
3254 struct limbo_die_struct *next;
3256 limbo_die_node;
3258 /* How to start an assembler comment. */
3259 #ifndef ASM_COMMENT_START
3260 #define ASM_COMMENT_START ";#"
3261 #endif
3263 /* Define a macro which returns non-zero for a TYPE_DECL which was
3264 implicitly generated for a tagged type.
3266 Note that unlike the gcc front end (which generates a NULL named
3267 TYPE_DECL node for each complete tagged type, each array type, and
3268 each function type node created) the g++ front end generates a
3269 _named_ TYPE_DECL node for each tagged type node created.
3270 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3271 generate a DW_TAG_typedef DIE for them. */
3273 #define TYPE_DECL_IS_STUB(decl) \
3274 (DECL_NAME (decl) == NULL_TREE \
3275 || (DECL_ARTIFICIAL (decl) \
3276 && is_tagged_type (TREE_TYPE (decl)) \
3277 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3278 /* This is necessary for stub decls that \
3279 appear in nested inline functions. */ \
3280 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3281 && (decl_ultimate_origin (decl) \
3282 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3284 /* Information concerning the compilation unit's programming
3285 language, and compiler version. */
3287 /* Fixed size portion of the DWARF compilation unit header. */
3288 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3290 /* Fixed size portion of public names info. */
3291 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3293 /* Fixed size portion of the address range info. */
3294 #define DWARF_ARANGES_HEADER_SIZE \
3295 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3296 - DWARF_OFFSET_SIZE)
3298 /* Size of padding portion in the address range info. It must be
3299 aligned to twice the pointer size. */
3300 #define DWARF_ARANGES_PAD_SIZE \
3301 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3302 - (2 * DWARF_OFFSET_SIZE + 4))
3304 /* Use assembler line directives if available. */
3305 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3306 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3307 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3308 #else
3309 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3310 #endif
3311 #endif
3313 /* Minimum line offset in a special line info. opcode.
3314 This value was chosen to give a reasonable range of values. */
3315 #define DWARF_LINE_BASE -10
3317 /* First special line opcode - leave room for the standard opcodes. */
3318 #define DWARF_LINE_OPCODE_BASE 10
3320 /* Range of line offsets in a special line info. opcode. */
3321 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3323 /* Flag that indicates the initial value of the is_stmt_start flag.
3324 In the present implementation, we do not mark any lines as
3325 the beginning of a source statement, because that information
3326 is not made available by the GCC front-end. */
3327 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3329 /* This location is used by calc_die_sizes() to keep track
3330 the offset of each DIE within the .debug_info section. */
3331 static unsigned long next_die_offset;
3333 /* Record the root of the DIE's built for the current compilation unit. */
3334 static dw_die_ref comp_unit_die;
3336 /* A list of DIEs with a NULL parent waiting to be relocated. */
3337 static limbo_die_node *limbo_die_list = 0;
3339 /* Structure used by lookup_filename to manage sets of filenames. */
3340 struct file_table
3342 char **table;
3343 unsigned allocated;
3344 unsigned in_use;
3345 unsigned last_lookup_index;
3348 /* Size (in elements) of increments by which we may expand the filename
3349 table. */
3350 #define FILE_TABLE_INCREMENT 64
3352 /* Filenames referenced by this compilation unit. */
3353 static struct file_table file_table;
3355 /* Local pointer to the name of the main input file. Initialized in
3356 dwarf2out_init. */
3357 static const char *primary_filename;
3359 /* A pointer to the base of a table of references to DIE's that describe
3360 declarations. The table is indexed by DECL_UID() which is a unique
3361 number identifying each decl. */
3362 static dw_die_ref *decl_die_table;
3364 /* Number of elements currently allocated for the decl_die_table. */
3365 static unsigned decl_die_table_allocated;
3367 /* Number of elements in decl_die_table currently in use. */
3368 static unsigned decl_die_table_in_use;
3370 /* Size (in elements) of increments by which we may expand the
3371 decl_die_table. */
3372 #define DECL_DIE_TABLE_INCREMENT 256
3374 /* A pointer to the base of a list of references to DIE's that
3375 are uniquely identified by their tag, presence/absence of
3376 children DIE's, and list of attribute/value pairs. */
3377 static dw_die_ref *abbrev_die_table;
3379 /* Number of elements currently allocated for abbrev_die_table. */
3380 static unsigned abbrev_die_table_allocated;
3382 /* Number of elements in type_die_table currently in use. */
3383 static unsigned abbrev_die_table_in_use;
3385 /* Size (in elements) of increments by which we may expand the
3386 abbrev_die_table. */
3387 #define ABBREV_DIE_TABLE_INCREMENT 256
3389 /* A pointer to the base of a table that contains line information
3390 for each source code line in .text in the compilation unit. */
3391 static dw_line_info_ref line_info_table;
3393 /* Number of elements currently allocated for line_info_table. */
3394 static unsigned line_info_table_allocated;
3396 /* Number of elements in separate_line_info_table currently in use. */
3397 static unsigned separate_line_info_table_in_use;
3399 /* A pointer to the base of a table that contains line information
3400 for each source code line outside of .text in the compilation unit. */
3401 static dw_separate_line_info_ref separate_line_info_table;
3403 /* Number of elements currently allocated for separate_line_info_table. */
3404 static unsigned separate_line_info_table_allocated;
3406 /* Number of elements in line_info_table currently in use. */
3407 static unsigned line_info_table_in_use;
3409 /* Size (in elements) of increments by which we may expand the
3410 line_info_table. */
3411 #define LINE_INFO_TABLE_INCREMENT 1024
3413 /* A pointer to the base of a table that contains a list of publicly
3414 accessible names. */
3415 static pubname_ref pubname_table;
3417 /* Number of elements currently allocated for pubname_table. */
3418 static unsigned pubname_table_allocated;
3420 /* Number of elements in pubname_table currently in use. */
3421 static unsigned pubname_table_in_use;
3423 /* Size (in elements) of increments by which we may expand the
3424 pubname_table. */
3425 #define PUBNAME_TABLE_INCREMENT 64
3427 /* Array of dies for which we should generate .debug_arange info. */
3428 static dw_die_ref *arange_table;
3430 /* Number of elements currently allocated for arange_table. */
3431 static unsigned arange_table_allocated;
3433 /* Number of elements in arange_table currently in use. */
3434 static unsigned arange_table_in_use;
3436 /* Size (in elements) of increments by which we may expand the
3437 arange_table. */
3438 #define ARANGE_TABLE_INCREMENT 64
3440 /* Array of dies for which we should generate .debug_ranges info. */
3441 static dw_ranges_ref ranges_table;
3443 /* Number of elements currently allocated for ranges_table. */
3444 static unsigned ranges_table_allocated;
3446 /* Number of elements in ranges_table currently in use. */
3447 static unsigned ranges_table_in_use;
3449 /* Size (in elements) of increments by which we may expand the
3450 ranges_table. */
3451 #define RANGES_TABLE_INCREMENT 64
3453 /* Whether we have location lists that need outputting */
3454 static unsigned have_location_lists;
3456 /* Record whether the function being analyzed contains inlined functions. */
3457 static int current_function_has_inlines;
3458 #if 0 && defined (MIPS_DEBUGGING_INFO)
3459 static int comp_unit_has_inlines;
3460 #endif
3462 /* Forward declarations for functions defined in this file. */
3464 static int is_pseudo_reg PARAMS ((rtx));
3465 static tree type_main_variant PARAMS ((tree));
3466 static int is_tagged_type PARAMS ((tree));
3467 static const char *dwarf_tag_name PARAMS ((unsigned));
3468 static const char *dwarf_attr_name PARAMS ((unsigned));
3469 static const char *dwarf_form_name PARAMS ((unsigned));
3470 #if 0
3471 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3472 #endif
3473 static tree decl_ultimate_origin PARAMS ((tree));
3474 static tree block_ultimate_origin PARAMS ((tree));
3475 static tree decl_class_context PARAMS ((tree));
3476 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3477 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
3478 static void add_AT_flag PARAMS ((dw_die_ref,
3479 enum dwarf_attribute,
3480 unsigned));
3481 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
3482 static void add_AT_int PARAMS ((dw_die_ref,
3483 enum dwarf_attribute, long));
3484 static inline long int AT_int PARAMS ((dw_attr_ref));
3485 static void add_AT_unsigned PARAMS ((dw_die_ref,
3486 enum dwarf_attribute,
3487 unsigned long));
3488 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
3489 static void add_AT_long_long PARAMS ((dw_die_ref,
3490 enum dwarf_attribute,
3491 unsigned long,
3492 unsigned long));
3493 static void add_AT_float PARAMS ((dw_die_ref,
3494 enum dwarf_attribute,
3495 unsigned, long *));
3496 static void add_AT_string PARAMS ((dw_die_ref,
3497 enum dwarf_attribute,
3498 const char *));
3499 static inline const char *AT_string PARAMS ((dw_attr_ref));
3500 static int AT_string_form PARAMS ((dw_attr_ref));
3501 static void add_AT_die_ref PARAMS ((dw_die_ref,
3502 enum dwarf_attribute,
3503 dw_die_ref));
3504 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
3505 static inline int AT_ref_external PARAMS ((dw_attr_ref));
3506 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
3507 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3508 enum dwarf_attribute,
3509 unsigned));
3510 static void add_AT_loc PARAMS ((dw_die_ref,
3511 enum dwarf_attribute,
3512 dw_loc_descr_ref));
3513 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
3514 static void add_AT_loc_list PARAMS ((dw_die_ref,
3515 enum dwarf_attribute,
3516 dw_loc_list_ref));
3517 static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
3518 static void add_AT_addr PARAMS ((dw_die_ref,
3519 enum dwarf_attribute,
3520 rtx));
3521 static inline rtx AT_addr PARAMS ((dw_attr_ref));
3522 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3523 enum dwarf_attribute,
3524 const char *));
3525 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3526 enum dwarf_attribute,
3527 const char *));
3528 static void add_AT_offset PARAMS ((dw_die_ref,
3529 enum dwarf_attribute,
3530 unsigned long));
3531 static void add_AT_range_list PARAMS ((dw_die_ref,
3532 enum dwarf_attribute,
3533 unsigned long));
3534 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
3535 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3536 enum dwarf_attribute));
3537 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3538 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3539 static const char *get_AT_string PARAMS ((dw_die_ref,
3540 enum dwarf_attribute));
3541 static int get_AT_flag PARAMS ((dw_die_ref,
3542 enum dwarf_attribute));
3543 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3544 enum dwarf_attribute));
3545 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3546 enum dwarf_attribute));
3547 static int is_c_family PARAMS ((void));
3548 static int is_cxx PARAMS ((void));
3549 static int is_java PARAMS ((void));
3550 static int is_fortran PARAMS ((void));
3551 static void remove_AT PARAMS ((dw_die_ref,
3552 enum dwarf_attribute));
3553 static inline void free_die PARAMS ((dw_die_ref));
3554 static void remove_children PARAMS ((dw_die_ref));
3555 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3556 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref,
3557 tree));
3558 static dw_die_ref lookup_type_die PARAMS ((tree));
3559 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3560 static dw_die_ref lookup_decl_die PARAMS ((tree));
3561 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3562 static void print_spaces PARAMS ((FILE *));
3563 static void print_die PARAMS ((dw_die_ref, FILE *));
3564 static void print_dwarf_line_table PARAMS ((FILE *));
3565 static void reverse_die_lists PARAMS ((dw_die_ref));
3566 static void reverse_all_dies PARAMS ((dw_die_ref));
3567 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3568 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3569 static void loc_checksum PARAMS ((dw_loc_descr_ref,
3570 struct md5_ctx *));
3571 static void attr_checksum PARAMS ((dw_attr_ref,
3572 struct md5_ctx *));
3573 static void die_checksum PARAMS ((dw_die_ref,
3574 struct md5_ctx *));
3575 static void compute_section_prefix PARAMS ((dw_die_ref));
3576 static int is_type_die PARAMS ((dw_die_ref));
3577 static int is_comdat_die PARAMS ((dw_die_ref));
3578 static int is_symbol_die PARAMS ((dw_die_ref));
3579 static void assign_symbol_names PARAMS ((dw_die_ref));
3580 static void break_out_includes PARAMS ((dw_die_ref));
3581 static void add_sibling_attributes PARAMS ((dw_die_ref));
3582 static void build_abbrev_table PARAMS ((dw_die_ref));
3583 static void output_location_lists PARAMS ((dw_die_ref));
3584 static int constant_size PARAMS ((long unsigned));
3585 static unsigned long size_of_die PARAMS ((dw_die_ref));
3586 static void calc_die_sizes PARAMS ((dw_die_ref));
3587 static void mark_dies PARAMS ((dw_die_ref));
3588 static void unmark_dies PARAMS ((dw_die_ref));
3589 static unsigned long size_of_pubnames PARAMS ((void));
3590 static unsigned long size_of_aranges PARAMS ((void));
3591 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3592 static void output_value_format PARAMS ((dw_attr_ref));
3593 static void output_abbrev_section PARAMS ((void));
3594 static void output_die_symbol PARAMS ((dw_die_ref));
3595 static void output_die PARAMS ((dw_die_ref));
3596 static void output_compilation_unit_header PARAMS ((void));
3597 static void output_comp_unit PARAMS ((dw_die_ref));
3598 static const char *dwarf2_name PARAMS ((tree, int));
3599 static void add_pubname PARAMS ((tree, dw_die_ref));
3600 static void output_pubnames PARAMS ((void));
3601 static void add_arange PARAMS ((tree, dw_die_ref));
3602 static void output_aranges PARAMS ((void));
3603 static unsigned int add_ranges PARAMS ((tree));
3604 static void output_ranges PARAMS ((void));
3605 static void output_line_info PARAMS ((void));
3606 static void output_file_names PARAMS ((void));
3607 static dw_die_ref base_type_die PARAMS ((tree));
3608 static tree root_type PARAMS ((tree));
3609 static int is_base_type PARAMS ((tree));
3610 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3611 static int type_is_enum PARAMS ((tree));
3612 static unsigned int reg_number PARAMS ((rtx));
3613 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3614 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3615 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3616 static int is_based_loc PARAMS ((rtx));
3617 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3618 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3619 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3620 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3621 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3622 static tree field_type PARAMS ((tree));
3623 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3624 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3625 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3626 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3627 static void add_AT_location_description PARAMS ((dw_die_ref,
3628 enum dwarf_attribute,
3629 dw_loc_descr_ref));
3630 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3631 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3632 static rtx rtl_for_decl_location PARAMS ((tree));
3633 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3634 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3635 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3636 static void add_bound_info PARAMS ((dw_die_ref,
3637 enum dwarf_attribute, tree));
3638 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3639 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3640 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3641 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3642 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3643 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3644 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3645 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3646 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3647 static void push_decl_scope PARAMS ((tree));
3648 static void pop_decl_scope PARAMS ((void));
3649 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3650 static inline int local_scope_p PARAMS ((dw_die_ref));
3651 static inline int class_scope_p PARAMS ((dw_die_ref));
3652 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3653 dw_die_ref));
3654 static const char *type_tag PARAMS ((tree));
3655 static tree member_declared_type PARAMS ((tree));
3656 #if 0
3657 static const char *decl_start_label PARAMS ((tree));
3658 #endif
3659 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3660 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3661 #if 0
3662 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3663 #endif
3664 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3665 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3666 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3667 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3668 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3669 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3670 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3671 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3672 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3673 static void gen_label_die PARAMS ((tree, dw_die_ref));
3674 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3675 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3676 static void gen_field_die PARAMS ((tree, dw_die_ref));
3677 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3678 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3679 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3680 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3681 static void gen_member_die PARAMS ((tree, dw_die_ref));
3682 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3683 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3684 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3685 static void gen_type_die PARAMS ((tree, dw_die_ref));
3686 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3687 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3688 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3689 static int is_redundant_typedef PARAMS ((tree));
3690 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3691 static unsigned lookup_filename PARAMS ((const char *));
3692 static void init_file_table PARAMS ((void));
3693 static void retry_incomplete_types PARAMS ((void));
3694 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3695 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3696 static int file_info_cmp PARAMS ((const void *, const void *));
3697 static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
3698 const char *, const char *,
3699 const char *, unsigned));
3700 static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3701 dw_loc_descr_ref,
3702 const char *, const char *, const char *));
3703 static void output_loc_list PARAMS ((dw_loc_list_ref));
3704 static char *gen_internal_sym PARAMS ((const char *));
3705 static void mark_limbo_die_list PARAMS ((void *));
3707 /* Section names used to hold DWARF debugging information. */
3708 #ifndef DEBUG_INFO_SECTION
3709 #define DEBUG_INFO_SECTION ".debug_info"
3710 #endif
3711 #ifndef DEBUG_ABBREV_SECTION
3712 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3713 #endif
3714 #ifndef DEBUG_ARANGES_SECTION
3715 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3716 #endif
3717 #ifndef DEBUG_MACINFO_SECTION
3718 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3719 #endif
3720 #ifndef DEBUG_LINE_SECTION
3721 #define DEBUG_LINE_SECTION ".debug_line"
3722 #endif
3723 #ifndef DEBUG_LOC_SECTION
3724 #define DEBUG_LOC_SECTION ".debug_loc"
3725 #endif
3726 #ifndef DEBUG_PUBNAMES_SECTION
3727 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3728 #endif
3729 #ifndef DEBUG_STR_SECTION
3730 #define DEBUG_STR_SECTION ".debug_str"
3731 #endif
3732 #ifndef DEBUG_RANGES_SECTION
3733 #define DEBUG_RANGES_SECTION ".debug_ranges"
3734 #endif
3736 /* Standard ELF section names for compiled code and data. */
3737 #ifndef TEXT_SECTION_NAME
3738 #define TEXT_SECTION_NAME ".text"
3739 #endif
3741 /* Section flags for .debug_str section. */
3742 #ifdef HAVE_GAS_SHF_MERGE
3743 #define DEBUG_STR_SECTION_FLAGS \
3744 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
3745 #else
3746 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3747 #endif
3749 /* Labels we insert at beginning sections we can reference instead of
3750 the section names themselves. */
3752 #ifndef TEXT_SECTION_LABEL
3753 #define TEXT_SECTION_LABEL "Ltext"
3754 #endif
3755 #ifndef DEBUG_LINE_SECTION_LABEL
3756 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3757 #endif
3758 #ifndef DEBUG_INFO_SECTION_LABEL
3759 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3760 #endif
3761 #ifndef DEBUG_ABBREV_SECTION_LABEL
3762 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3763 #endif
3764 #ifndef DEBUG_LOC_SECTION_LABEL
3765 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3766 #endif
3767 #ifndef DEBUG_RANGES_SECTION_LABEL
3768 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3769 #endif
3770 #ifndef DEBUG_MACINFO_SECTION_LABEL
3771 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3772 #endif
3774 /* Definitions of defaults for formats and names of various special
3775 (artificial) labels which may be generated within this file (when the -g
3776 options is used and DWARF_DEBUGGING_INFO is in effect.
3777 If necessary, these may be overridden from within the tm.h file, but
3778 typically, overriding these defaults is unnecessary. */
3780 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3781 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3782 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3783 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3784 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3785 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3786 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3787 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3789 #ifndef TEXT_END_LABEL
3790 #define TEXT_END_LABEL "Letext"
3791 #endif
3792 #ifndef BLOCK_BEGIN_LABEL
3793 #define BLOCK_BEGIN_LABEL "LBB"
3794 #endif
3795 #ifndef BLOCK_END_LABEL
3796 #define BLOCK_END_LABEL "LBE"
3797 #endif
3798 #ifndef LINE_CODE_LABEL
3799 #define LINE_CODE_LABEL "LM"
3800 #endif
3801 #ifndef SEPARATE_LINE_CODE_LABEL
3802 #define SEPARATE_LINE_CODE_LABEL "LSM"
3803 #endif
3805 /* We allow a language front-end to designate a function that is to be
3806 called to "demangle" any name before it it put into a DIE. */
3808 static const char *(*demangle_name_func) PARAMS ((const char *));
3810 void
3811 dwarf2out_set_demangle_name_func (func)
3812 const char *(*func) PARAMS ((const char *));
3814 demangle_name_func = func;
3817 /* Test if rtl node points to a pseudo register. */
3819 static inline int
3820 is_pseudo_reg (rtl)
3821 rtx rtl;
3823 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3824 || (GET_CODE (rtl) == SUBREG
3825 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3828 /* Return a reference to a type, with its const and volatile qualifiers
3829 removed. */
3831 static inline tree
3832 type_main_variant (type)
3833 tree type;
3835 type = TYPE_MAIN_VARIANT (type);
3837 /* ??? There really should be only one main variant among any group of
3838 variants of a given type (and all of the MAIN_VARIANT values for all
3839 members of the group should point to that one type) but sometimes the C
3840 front-end messes this up for array types, so we work around that bug
3841 here. */
3842 if (TREE_CODE (type) == ARRAY_TYPE)
3843 while (type != TYPE_MAIN_VARIANT (type))
3844 type = TYPE_MAIN_VARIANT (type);
3846 return type;
3849 /* Return non-zero if the given type node represents a tagged type. */
3851 static inline int
3852 is_tagged_type (type)
3853 tree type;
3855 enum tree_code code = TREE_CODE (type);
3857 return (code == RECORD_TYPE || code == UNION_TYPE
3858 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3861 /* Convert a DIE tag into its string name. */
3863 static const char *
3864 dwarf_tag_name (tag)
3865 unsigned tag;
3867 switch (tag)
3869 case DW_TAG_padding:
3870 return "DW_TAG_padding";
3871 case DW_TAG_array_type:
3872 return "DW_TAG_array_type";
3873 case DW_TAG_class_type:
3874 return "DW_TAG_class_type";
3875 case DW_TAG_entry_point:
3876 return "DW_TAG_entry_point";
3877 case DW_TAG_enumeration_type:
3878 return "DW_TAG_enumeration_type";
3879 case DW_TAG_formal_parameter:
3880 return "DW_TAG_formal_parameter";
3881 case DW_TAG_imported_declaration:
3882 return "DW_TAG_imported_declaration";
3883 case DW_TAG_label:
3884 return "DW_TAG_label";
3885 case DW_TAG_lexical_block:
3886 return "DW_TAG_lexical_block";
3887 case DW_TAG_member:
3888 return "DW_TAG_member";
3889 case DW_TAG_pointer_type:
3890 return "DW_TAG_pointer_type";
3891 case DW_TAG_reference_type:
3892 return "DW_TAG_reference_type";
3893 case DW_TAG_compile_unit:
3894 return "DW_TAG_compile_unit";
3895 case DW_TAG_string_type:
3896 return "DW_TAG_string_type";
3897 case DW_TAG_structure_type:
3898 return "DW_TAG_structure_type";
3899 case DW_TAG_subroutine_type:
3900 return "DW_TAG_subroutine_type";
3901 case DW_TAG_typedef:
3902 return "DW_TAG_typedef";
3903 case DW_TAG_union_type:
3904 return "DW_TAG_union_type";
3905 case DW_TAG_unspecified_parameters:
3906 return "DW_TAG_unspecified_parameters";
3907 case DW_TAG_variant:
3908 return "DW_TAG_variant";
3909 case DW_TAG_common_block:
3910 return "DW_TAG_common_block";
3911 case DW_TAG_common_inclusion:
3912 return "DW_TAG_common_inclusion";
3913 case DW_TAG_inheritance:
3914 return "DW_TAG_inheritance";
3915 case DW_TAG_inlined_subroutine:
3916 return "DW_TAG_inlined_subroutine";
3917 case DW_TAG_module:
3918 return "DW_TAG_module";
3919 case DW_TAG_ptr_to_member_type:
3920 return "DW_TAG_ptr_to_member_type";
3921 case DW_TAG_set_type:
3922 return "DW_TAG_set_type";
3923 case DW_TAG_subrange_type:
3924 return "DW_TAG_subrange_type";
3925 case DW_TAG_with_stmt:
3926 return "DW_TAG_with_stmt";
3927 case DW_TAG_access_declaration:
3928 return "DW_TAG_access_declaration";
3929 case DW_TAG_base_type:
3930 return "DW_TAG_base_type";
3931 case DW_TAG_catch_block:
3932 return "DW_TAG_catch_block";
3933 case DW_TAG_const_type:
3934 return "DW_TAG_const_type";
3935 case DW_TAG_constant:
3936 return "DW_TAG_constant";
3937 case DW_TAG_enumerator:
3938 return "DW_TAG_enumerator";
3939 case DW_TAG_file_type:
3940 return "DW_TAG_file_type";
3941 case DW_TAG_friend:
3942 return "DW_TAG_friend";
3943 case DW_TAG_namelist:
3944 return "DW_TAG_namelist";
3945 case DW_TAG_namelist_item:
3946 return "DW_TAG_namelist_item";
3947 case DW_TAG_packed_type:
3948 return "DW_TAG_packed_type";
3949 case DW_TAG_subprogram:
3950 return "DW_TAG_subprogram";
3951 case DW_TAG_template_type_param:
3952 return "DW_TAG_template_type_param";
3953 case DW_TAG_template_value_param:
3954 return "DW_TAG_template_value_param";
3955 case DW_TAG_thrown_type:
3956 return "DW_TAG_thrown_type";
3957 case DW_TAG_try_block:
3958 return "DW_TAG_try_block";
3959 case DW_TAG_variant_part:
3960 return "DW_TAG_variant_part";
3961 case DW_TAG_variable:
3962 return "DW_TAG_variable";
3963 case DW_TAG_volatile_type:
3964 return "DW_TAG_volatile_type";
3965 case DW_TAG_MIPS_loop:
3966 return "DW_TAG_MIPS_loop";
3967 case DW_TAG_format_label:
3968 return "DW_TAG_format_label";
3969 case DW_TAG_function_template:
3970 return "DW_TAG_function_template";
3971 case DW_TAG_class_template:
3972 return "DW_TAG_class_template";
3973 case DW_TAG_GNU_BINCL:
3974 return "DW_TAG_GNU_BINCL";
3975 case DW_TAG_GNU_EINCL:
3976 return "DW_TAG_GNU_EINCL";
3977 default:
3978 return "DW_TAG_<unknown>";
3982 /* Convert a DWARF attribute code into its string name. */
3984 static const char *
3985 dwarf_attr_name (attr)
3986 unsigned attr;
3988 switch (attr)
3990 case DW_AT_sibling:
3991 return "DW_AT_sibling";
3992 case DW_AT_location:
3993 return "DW_AT_location";
3994 case DW_AT_name:
3995 return "DW_AT_name";
3996 case DW_AT_ordering:
3997 return "DW_AT_ordering";
3998 case DW_AT_subscr_data:
3999 return "DW_AT_subscr_data";
4000 case DW_AT_byte_size:
4001 return "DW_AT_byte_size";
4002 case DW_AT_bit_offset:
4003 return "DW_AT_bit_offset";
4004 case DW_AT_bit_size:
4005 return "DW_AT_bit_size";
4006 case DW_AT_element_list:
4007 return "DW_AT_element_list";
4008 case DW_AT_stmt_list:
4009 return "DW_AT_stmt_list";
4010 case DW_AT_low_pc:
4011 return "DW_AT_low_pc";
4012 case DW_AT_high_pc:
4013 return "DW_AT_high_pc";
4014 case DW_AT_language:
4015 return "DW_AT_language";
4016 case DW_AT_member:
4017 return "DW_AT_member";
4018 case DW_AT_discr:
4019 return "DW_AT_discr";
4020 case DW_AT_discr_value:
4021 return "DW_AT_discr_value";
4022 case DW_AT_visibility:
4023 return "DW_AT_visibility";
4024 case DW_AT_import:
4025 return "DW_AT_import";
4026 case DW_AT_string_length:
4027 return "DW_AT_string_length";
4028 case DW_AT_common_reference:
4029 return "DW_AT_common_reference";
4030 case DW_AT_comp_dir:
4031 return "DW_AT_comp_dir";
4032 case DW_AT_const_value:
4033 return "DW_AT_const_value";
4034 case DW_AT_containing_type:
4035 return "DW_AT_containing_type";
4036 case DW_AT_default_value:
4037 return "DW_AT_default_value";
4038 case DW_AT_inline:
4039 return "DW_AT_inline";
4040 case DW_AT_is_optional:
4041 return "DW_AT_is_optional";
4042 case DW_AT_lower_bound:
4043 return "DW_AT_lower_bound";
4044 case DW_AT_producer:
4045 return "DW_AT_producer";
4046 case DW_AT_prototyped:
4047 return "DW_AT_prototyped";
4048 case DW_AT_return_addr:
4049 return "DW_AT_return_addr";
4050 case DW_AT_start_scope:
4051 return "DW_AT_start_scope";
4052 case DW_AT_stride_size:
4053 return "DW_AT_stride_size";
4054 case DW_AT_upper_bound:
4055 return "DW_AT_upper_bound";
4056 case DW_AT_abstract_origin:
4057 return "DW_AT_abstract_origin";
4058 case DW_AT_accessibility:
4059 return "DW_AT_accessibility";
4060 case DW_AT_address_class:
4061 return "DW_AT_address_class";
4062 case DW_AT_artificial:
4063 return "DW_AT_artificial";
4064 case DW_AT_base_types:
4065 return "DW_AT_base_types";
4066 case DW_AT_calling_convention:
4067 return "DW_AT_calling_convention";
4068 case DW_AT_count:
4069 return "DW_AT_count";
4070 case DW_AT_data_member_location:
4071 return "DW_AT_data_member_location";
4072 case DW_AT_decl_column:
4073 return "DW_AT_decl_column";
4074 case DW_AT_decl_file:
4075 return "DW_AT_decl_file";
4076 case DW_AT_decl_line:
4077 return "DW_AT_decl_line";
4078 case DW_AT_declaration:
4079 return "DW_AT_declaration";
4080 case DW_AT_discr_list:
4081 return "DW_AT_discr_list";
4082 case DW_AT_encoding:
4083 return "DW_AT_encoding";
4084 case DW_AT_external:
4085 return "DW_AT_external";
4086 case DW_AT_frame_base:
4087 return "DW_AT_frame_base";
4088 case DW_AT_friend:
4089 return "DW_AT_friend";
4090 case DW_AT_identifier_case:
4091 return "DW_AT_identifier_case";
4092 case DW_AT_macro_info:
4093 return "DW_AT_macro_info";
4094 case DW_AT_namelist_items:
4095 return "DW_AT_namelist_items";
4096 case DW_AT_priority:
4097 return "DW_AT_priority";
4098 case DW_AT_segment:
4099 return "DW_AT_segment";
4100 case DW_AT_specification:
4101 return "DW_AT_specification";
4102 case DW_AT_static_link:
4103 return "DW_AT_static_link";
4104 case DW_AT_type:
4105 return "DW_AT_type";
4106 case DW_AT_use_location:
4107 return "DW_AT_use_location";
4108 case DW_AT_variable_parameter:
4109 return "DW_AT_variable_parameter";
4110 case DW_AT_virtuality:
4111 return "DW_AT_virtuality";
4112 case DW_AT_vtable_elem_location:
4113 return "DW_AT_vtable_elem_location";
4115 case DW_AT_allocated:
4116 return "DW_AT_allocated";
4117 case DW_AT_associated:
4118 return "DW_AT_associated";
4119 case DW_AT_data_location:
4120 return "DW_AT_data_location";
4121 case DW_AT_stride:
4122 return "DW_AT_stride";
4123 case DW_AT_entry_pc:
4124 return "DW_AT_entry_pc";
4125 case DW_AT_use_UTF8:
4126 return "DW_AT_use_UTF8";
4127 case DW_AT_extension:
4128 return "DW_AT_extension";
4129 case DW_AT_ranges:
4130 return "DW_AT_ranges";
4131 case DW_AT_trampoline:
4132 return "DW_AT_trampoline";
4133 case DW_AT_call_column:
4134 return "DW_AT_call_column";
4135 case DW_AT_call_file:
4136 return "DW_AT_call_file";
4137 case DW_AT_call_line:
4138 return "DW_AT_call_line";
4140 case DW_AT_MIPS_fde:
4141 return "DW_AT_MIPS_fde";
4142 case DW_AT_MIPS_loop_begin:
4143 return "DW_AT_MIPS_loop_begin";
4144 case DW_AT_MIPS_tail_loop_begin:
4145 return "DW_AT_MIPS_tail_loop_begin";
4146 case DW_AT_MIPS_epilog_begin:
4147 return "DW_AT_MIPS_epilog_begin";
4148 case DW_AT_MIPS_loop_unroll_factor:
4149 return "DW_AT_MIPS_loop_unroll_factor";
4150 case DW_AT_MIPS_software_pipeline_depth:
4151 return "DW_AT_MIPS_software_pipeline_depth";
4152 case DW_AT_MIPS_linkage_name:
4153 return "DW_AT_MIPS_linkage_name";
4154 case DW_AT_MIPS_stride:
4155 return "DW_AT_MIPS_stride";
4156 case DW_AT_MIPS_abstract_name:
4157 return "DW_AT_MIPS_abstract_name";
4158 case DW_AT_MIPS_clone_origin:
4159 return "DW_AT_MIPS_clone_origin";
4160 case DW_AT_MIPS_has_inlines:
4161 return "DW_AT_MIPS_has_inlines";
4163 case DW_AT_sf_names:
4164 return "DW_AT_sf_names";
4165 case DW_AT_src_info:
4166 return "DW_AT_src_info";
4167 case DW_AT_mac_info:
4168 return "DW_AT_mac_info";
4169 case DW_AT_src_coords:
4170 return "DW_AT_src_coords";
4171 case DW_AT_body_begin:
4172 return "DW_AT_body_begin";
4173 case DW_AT_body_end:
4174 return "DW_AT_body_end";
4175 case DW_AT_GNU_vector:
4176 return "DW_AT_GNU_vector";
4178 case DW_AT_VMS_rtnbeg_pd_address:
4179 return "DW_AT_VMS_rtnbeg_pd_address";
4181 default:
4182 return "DW_AT_<unknown>";
4186 /* Convert a DWARF value form code into its string name. */
4188 static const char *
4189 dwarf_form_name (form)
4190 unsigned form;
4192 switch (form)
4194 case DW_FORM_addr:
4195 return "DW_FORM_addr";
4196 case DW_FORM_block2:
4197 return "DW_FORM_block2";
4198 case DW_FORM_block4:
4199 return "DW_FORM_block4";
4200 case DW_FORM_data2:
4201 return "DW_FORM_data2";
4202 case DW_FORM_data4:
4203 return "DW_FORM_data4";
4204 case DW_FORM_data8:
4205 return "DW_FORM_data8";
4206 case DW_FORM_string:
4207 return "DW_FORM_string";
4208 case DW_FORM_block:
4209 return "DW_FORM_block";
4210 case DW_FORM_block1:
4211 return "DW_FORM_block1";
4212 case DW_FORM_data1:
4213 return "DW_FORM_data1";
4214 case DW_FORM_flag:
4215 return "DW_FORM_flag";
4216 case DW_FORM_sdata:
4217 return "DW_FORM_sdata";
4218 case DW_FORM_strp:
4219 return "DW_FORM_strp";
4220 case DW_FORM_udata:
4221 return "DW_FORM_udata";
4222 case DW_FORM_ref_addr:
4223 return "DW_FORM_ref_addr";
4224 case DW_FORM_ref1:
4225 return "DW_FORM_ref1";
4226 case DW_FORM_ref2:
4227 return "DW_FORM_ref2";
4228 case DW_FORM_ref4:
4229 return "DW_FORM_ref4";
4230 case DW_FORM_ref8:
4231 return "DW_FORM_ref8";
4232 case DW_FORM_ref_udata:
4233 return "DW_FORM_ref_udata";
4234 case DW_FORM_indirect:
4235 return "DW_FORM_indirect";
4236 default:
4237 return "DW_FORM_<unknown>";
4241 /* Convert a DWARF type code into its string name. */
4243 #if 0
4244 static const char *
4245 dwarf_type_encoding_name (enc)
4246 unsigned enc;
4248 switch (enc)
4250 case DW_ATE_address:
4251 return "DW_ATE_address";
4252 case DW_ATE_boolean:
4253 return "DW_ATE_boolean";
4254 case DW_ATE_complex_float:
4255 return "DW_ATE_complex_float";
4256 case DW_ATE_float:
4257 return "DW_ATE_float";
4258 case DW_ATE_signed:
4259 return "DW_ATE_signed";
4260 case DW_ATE_signed_char:
4261 return "DW_ATE_signed_char";
4262 case DW_ATE_unsigned:
4263 return "DW_ATE_unsigned";
4264 case DW_ATE_unsigned_char:
4265 return "DW_ATE_unsigned_char";
4266 default:
4267 return "DW_ATE_<unknown>";
4270 #endif
4272 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4273 instance of an inlined instance of a decl which is local to an inline
4274 function, so we have to trace all of the way back through the origin chain
4275 to find out what sort of node actually served as the original seed for the
4276 given block. */
4278 static tree
4279 decl_ultimate_origin (decl)
4280 tree decl;
4282 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4283 nodes in the function to point to themselves; ignore that if
4284 we're trying to output the abstract instance of this function. */
4285 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4286 return NULL_TREE;
4288 #ifdef ENABLE_CHECKING
4289 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4290 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4291 most distant ancestor, this should never happen. */
4292 abort ();
4293 #endif
4295 return DECL_ABSTRACT_ORIGIN (decl);
4298 /* Determine the "ultimate origin" of a block. The block may be an inlined
4299 instance of an inlined instance of a block which is local to an inline
4300 function, so we have to trace all of the way back through the origin chain
4301 to find out what sort of node actually served as the original seed for the
4302 given block. */
4304 static tree
4305 block_ultimate_origin (block)
4306 tree block;
4308 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4310 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4311 nodes in the function to point to themselves; ignore that if
4312 we're trying to output the abstract instance of this function. */
4313 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4314 return NULL_TREE;
4316 if (immediate_origin == NULL_TREE)
4317 return NULL_TREE;
4318 else
4320 tree ret_val;
4321 tree lookahead = immediate_origin;
4325 ret_val = lookahead;
4326 lookahead = (TREE_CODE (ret_val) == BLOCK
4327 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4329 while (lookahead != NULL && lookahead != ret_val);
4331 return ret_val;
4335 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4336 of a virtual function may refer to a base class, so we check the 'this'
4337 parameter. */
4339 static tree
4340 decl_class_context (decl)
4341 tree decl;
4343 tree context = NULL_TREE;
4345 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4346 context = DECL_CONTEXT (decl);
4347 else
4348 context = TYPE_MAIN_VARIANT
4349 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4351 if (context && !TYPE_P (context))
4352 context = NULL_TREE;
4354 return context;
4357 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4358 addition order, and correct that in reverse_all_dies. */
4360 static inline void
4361 add_dwarf_attr (die, attr)
4362 dw_die_ref die;
4363 dw_attr_ref attr;
4365 if (die != NULL && attr != NULL)
4367 attr->dw_attr_next = die->die_attr;
4368 die->die_attr = attr;
4372 static inline dw_val_class
4373 AT_class (a)
4374 dw_attr_ref a;
4376 return a->dw_attr_val.val_class;
4379 /* Add a flag value attribute to a DIE. */
4381 static inline void
4382 add_AT_flag (die, attr_kind, flag)
4383 dw_die_ref die;
4384 enum dwarf_attribute attr_kind;
4385 unsigned flag;
4387 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4389 attr->dw_attr_next = NULL;
4390 attr->dw_attr = attr_kind;
4391 attr->dw_attr_val.val_class = dw_val_class_flag;
4392 attr->dw_attr_val.v.val_flag = flag;
4393 add_dwarf_attr (die, attr);
4396 static inline unsigned
4397 AT_flag (a)
4398 dw_attr_ref a;
4400 if (a && AT_class (a) == dw_val_class_flag)
4401 return a->dw_attr_val.v.val_flag;
4403 abort ();
4406 /* Add a signed integer attribute value to a DIE. */
4408 static inline void
4409 add_AT_int (die, attr_kind, int_val)
4410 dw_die_ref die;
4411 enum dwarf_attribute attr_kind;
4412 long int int_val;
4414 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4416 attr->dw_attr_next = NULL;
4417 attr->dw_attr = attr_kind;
4418 attr->dw_attr_val.val_class = dw_val_class_const;
4419 attr->dw_attr_val.v.val_int = int_val;
4420 add_dwarf_attr (die, attr);
4423 static inline long int
4424 AT_int (a)
4425 dw_attr_ref a;
4427 if (a && AT_class (a) == dw_val_class_const)
4428 return a->dw_attr_val.v.val_int;
4430 abort ();
4433 /* Add an unsigned integer attribute value to a DIE. */
4435 static inline void
4436 add_AT_unsigned (die, attr_kind, unsigned_val)
4437 dw_die_ref die;
4438 enum dwarf_attribute attr_kind;
4439 unsigned long unsigned_val;
4441 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4443 attr->dw_attr_next = NULL;
4444 attr->dw_attr = attr_kind;
4445 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4446 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4447 add_dwarf_attr (die, attr);
4450 static inline unsigned long
4451 AT_unsigned (a)
4452 dw_attr_ref a;
4454 if (a && AT_class (a) == dw_val_class_unsigned_const)
4455 return a->dw_attr_val.v.val_unsigned;
4457 abort ();
4460 /* Add an unsigned double integer attribute value to a DIE. */
4462 static inline void
4463 add_AT_long_long (die, attr_kind, val_hi, val_low)
4464 dw_die_ref die;
4465 enum dwarf_attribute attr_kind;
4466 unsigned long val_hi;
4467 unsigned long val_low;
4469 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4471 attr->dw_attr_next = NULL;
4472 attr->dw_attr = attr_kind;
4473 attr->dw_attr_val.val_class = dw_val_class_long_long;
4474 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4475 attr->dw_attr_val.v.val_long_long.low = val_low;
4476 add_dwarf_attr (die, attr);
4479 /* Add a floating point attribute value to a DIE and return it. */
4481 static inline void
4482 add_AT_float (die, attr_kind, length, array)
4483 dw_die_ref die;
4484 enum dwarf_attribute attr_kind;
4485 unsigned length;
4486 long *array;
4488 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4490 attr->dw_attr_next = NULL;
4491 attr->dw_attr = attr_kind;
4492 attr->dw_attr_val.val_class = dw_val_class_float;
4493 attr->dw_attr_val.v.val_float.length = length;
4494 attr->dw_attr_val.v.val_float.array = array;
4495 add_dwarf_attr (die, attr);
4498 /* Add a string attribute value to a DIE. */
4500 static inline void
4501 add_AT_string (die, attr_kind, str)
4502 dw_die_ref die;
4503 enum dwarf_attribute attr_kind;
4504 const char *str;
4506 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4507 struct indirect_string_node *node;
4509 if (! debug_str_hash)
4511 debug_str_hash = ht_create (10);
4512 debug_str_hash->alloc_node = indirect_string_alloc;
4515 node = (struct indirect_string_node *)
4516 ht_lookup (debug_str_hash, (const unsigned char *) str,
4517 strlen (str), HT_ALLOC);
4518 node->refcount++;
4520 attr->dw_attr_next = NULL;
4521 attr->dw_attr = attr_kind;
4522 attr->dw_attr_val.val_class = dw_val_class_str;
4523 attr->dw_attr_val.v.val_str = node;
4524 add_dwarf_attr (die, attr);
4527 static inline const char *
4528 AT_string (a)
4529 dw_attr_ref a;
4531 if (a && AT_class (a) == dw_val_class_str)
4532 return (const char *) HT_STR (&a->dw_attr_val.v.val_str->id);
4534 abort ();
4537 /* Find out whether a string should be output inline in DIE
4538 or out-of-line in .debug_str section. */
4540 static int
4541 AT_string_form (a)
4542 dw_attr_ref a;
4544 if (a && AT_class (a) == dw_val_class_str)
4546 struct indirect_string_node *node;
4547 unsigned int len;
4548 extern int const_labelno;
4549 char label[32];
4551 node = a->dw_attr_val.v.val_str;
4552 if (node->form)
4553 return node->form;
4555 len = HT_LEN (&node->id) + 1;
4557 /* If the string is shorter or equal to the size of the reference, it is
4558 always better to put it inline. */
4559 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4560 return node->form = DW_FORM_string;
4562 /* If we cannot expect the linker to merge strings in .debug_str
4563 section, only put it into .debug_str if it is worth even in this
4564 single module. */
4565 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0
4566 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
4567 return node->form = DW_FORM_string;
4569 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
4570 ++const_labelno;
4571 node->label = xstrdup (label);
4573 return node->form = DW_FORM_strp;
4576 abort ();
4579 /* Add a DIE reference attribute value to a DIE. */
4581 static inline void
4582 add_AT_die_ref (die, attr_kind, targ_die)
4583 dw_die_ref die;
4584 enum dwarf_attribute attr_kind;
4585 dw_die_ref targ_die;
4587 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4589 attr->dw_attr_next = NULL;
4590 attr->dw_attr = attr_kind;
4591 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4592 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4593 attr->dw_attr_val.v.val_die_ref.external = 0;
4594 add_dwarf_attr (die, attr);
4597 static inline dw_die_ref
4598 AT_ref (a)
4599 dw_attr_ref a;
4601 if (a && AT_class (a) == dw_val_class_die_ref)
4602 return a->dw_attr_val.v.val_die_ref.die;
4604 abort ();
4607 static inline int
4608 AT_ref_external (a)
4609 dw_attr_ref a;
4611 if (a && AT_class (a) == dw_val_class_die_ref)
4612 return a->dw_attr_val.v.val_die_ref.external;
4614 return 0;
4617 static inline void
4618 set_AT_ref_external (a, i)
4619 dw_attr_ref a;
4620 int i;
4622 if (a && AT_class (a) == dw_val_class_die_ref)
4623 a->dw_attr_val.v.val_die_ref.external = i;
4624 else
4625 abort ();
4628 /* Add an FDE reference attribute value to a DIE. */
4630 static inline void
4631 add_AT_fde_ref (die, attr_kind, targ_fde)
4632 dw_die_ref die;
4633 enum dwarf_attribute attr_kind;
4634 unsigned targ_fde;
4636 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4638 attr->dw_attr_next = NULL;
4639 attr->dw_attr = attr_kind;
4640 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4641 attr->dw_attr_val.v.val_fde_index = targ_fde;
4642 add_dwarf_attr (die, attr);
4645 /* Add a location description attribute value to a DIE. */
4647 static inline void
4648 add_AT_loc (die, attr_kind, loc)
4649 dw_die_ref die;
4650 enum dwarf_attribute attr_kind;
4651 dw_loc_descr_ref loc;
4653 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4655 attr->dw_attr_next = NULL;
4656 attr->dw_attr = attr_kind;
4657 attr->dw_attr_val.val_class = dw_val_class_loc;
4658 attr->dw_attr_val.v.val_loc = loc;
4659 add_dwarf_attr (die, attr);
4662 static inline dw_loc_descr_ref
4663 AT_loc (a)
4664 dw_attr_ref a;
4666 if (a && AT_class (a) == dw_val_class_loc)
4667 return a->dw_attr_val.v.val_loc;
4669 abort ();
4672 static inline void
4673 add_AT_loc_list (die, attr_kind, loc_list)
4674 dw_die_ref die;
4675 enum dwarf_attribute attr_kind;
4676 dw_loc_list_ref loc_list;
4678 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4680 attr->dw_attr_next = NULL;
4681 attr->dw_attr = attr_kind;
4682 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4683 attr->dw_attr_val.v.val_loc_list = loc_list;
4684 add_dwarf_attr (die, attr);
4685 have_location_lists = 1;
4688 static inline dw_loc_list_ref
4689 AT_loc_list (a)
4690 dw_attr_ref a;
4692 if (a && AT_class (a) == dw_val_class_loc_list)
4693 return a->dw_attr_val.v.val_loc_list;
4695 abort ();
4698 /* Add an address constant attribute value to a DIE. */
4700 static inline void
4701 add_AT_addr (die, attr_kind, addr)
4702 dw_die_ref die;
4703 enum dwarf_attribute attr_kind;
4704 rtx addr;
4706 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4708 attr->dw_attr_next = NULL;
4709 attr->dw_attr = attr_kind;
4710 attr->dw_attr_val.val_class = dw_val_class_addr;
4711 attr->dw_attr_val.v.val_addr = addr;
4712 add_dwarf_attr (die, attr);
4715 static inline rtx
4716 AT_addr (a)
4717 dw_attr_ref a;
4719 if (a && AT_class (a) == dw_val_class_addr)
4720 return a->dw_attr_val.v.val_addr;
4722 abort ();
4725 /* Add a label identifier attribute value to a DIE. */
4727 static inline void
4728 add_AT_lbl_id (die, attr_kind, lbl_id)
4729 dw_die_ref die;
4730 enum dwarf_attribute attr_kind;
4731 const char *lbl_id;
4733 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4735 attr->dw_attr_next = NULL;
4736 attr->dw_attr = attr_kind;
4737 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4738 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4739 add_dwarf_attr (die, attr);
4742 /* Add a section offset attribute value to a DIE. */
4744 static inline void
4745 add_AT_lbl_offset (die, attr_kind, label)
4746 dw_die_ref die;
4747 enum dwarf_attribute attr_kind;
4748 const char *label;
4750 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4752 attr->dw_attr_next = NULL;
4753 attr->dw_attr = attr_kind;
4754 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4755 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4756 add_dwarf_attr (die, attr);
4759 /* Add an offset attribute value to a DIE. */
4761 static inline void
4762 add_AT_offset (die, attr_kind, offset)
4763 dw_die_ref die;
4764 enum dwarf_attribute attr_kind;
4765 unsigned long offset;
4767 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4769 attr->dw_attr_next = NULL;
4770 attr->dw_attr = attr_kind;
4771 attr->dw_attr_val.val_class = dw_val_class_offset;
4772 attr->dw_attr_val.v.val_offset = offset;
4773 add_dwarf_attr (die, attr);
4776 /* Add an range_list attribute value to a DIE. */
4778 static void
4779 add_AT_range_list (die, attr_kind, offset)
4780 dw_die_ref die;
4781 enum dwarf_attribute attr_kind;
4782 unsigned long offset;
4784 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4786 attr->dw_attr_next = NULL;
4787 attr->dw_attr = attr_kind;
4788 attr->dw_attr_val.val_class = dw_val_class_range_list;
4789 attr->dw_attr_val.v.val_offset = offset;
4790 add_dwarf_attr (die, attr);
4793 static inline const char *
4794 AT_lbl (a)
4795 dw_attr_ref a;
4797 if (a && (AT_class (a) == dw_val_class_lbl_id
4798 || AT_class (a) == dw_val_class_lbl_offset))
4799 return a->dw_attr_val.v.val_lbl_id;
4801 abort ();
4804 /* Get the attribute of type attr_kind. */
4806 static inline dw_attr_ref
4807 get_AT (die, attr_kind)
4808 dw_die_ref die;
4809 enum dwarf_attribute attr_kind;
4811 dw_attr_ref a;
4812 dw_die_ref spec = NULL;
4814 if (die != NULL)
4816 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4817 if (a->dw_attr == attr_kind)
4818 return a;
4819 else if (a->dw_attr == DW_AT_specification
4820 || a->dw_attr == DW_AT_abstract_origin)
4821 spec = AT_ref (a);
4823 if (spec)
4824 return get_AT (spec, attr_kind);
4827 return NULL;
4830 /* Return the "low pc" attribute value, typically associated with a subprogram
4831 DIE. Return null if the "low pc" attribute is either not present, or if it
4832 cannot be represented as an assembler label identifier. */
4834 static inline const char *
4835 get_AT_low_pc (die)
4836 dw_die_ref die;
4838 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4840 return a ? AT_lbl (a) : NULL;
4843 /* Return the "high pc" attribute value, typically associated with a subprogram
4844 DIE. Return null if the "high pc" attribute is either not present, or if it
4845 cannot be represented as an assembler label identifier. */
4847 static inline const char *
4848 get_AT_hi_pc (die)
4849 dw_die_ref die;
4851 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4853 return a ? AT_lbl (a) : NULL;
4856 /* Return the value of the string attribute designated by ATTR_KIND, or
4857 NULL if it is not present. */
4859 static inline const char *
4860 get_AT_string (die, attr_kind)
4861 dw_die_ref die;
4862 enum dwarf_attribute attr_kind;
4864 dw_attr_ref a = get_AT (die, attr_kind);
4866 return a ? AT_string (a) : NULL;
4869 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4870 if it is not present. */
4872 static inline int
4873 get_AT_flag (die, attr_kind)
4874 dw_die_ref die;
4875 enum dwarf_attribute attr_kind;
4877 dw_attr_ref a = get_AT (die, attr_kind);
4879 return a ? AT_flag (a) : 0;
4882 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4883 if it is not present. */
4885 static inline unsigned
4886 get_AT_unsigned (die, attr_kind)
4887 dw_die_ref die;
4888 enum dwarf_attribute attr_kind;
4890 dw_attr_ref a = get_AT (die, attr_kind);
4892 return a ? AT_unsigned (a) : 0;
4895 static inline dw_die_ref
4896 get_AT_ref (die, attr_kind)
4897 dw_die_ref die;
4898 enum dwarf_attribute attr_kind;
4900 dw_attr_ref a = get_AT (die, attr_kind);
4902 return a ? AT_ref (a) : NULL;
4905 static inline int
4906 is_c_family ()
4908 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4910 return (lang == DW_LANG_C || lang == DW_LANG_C89
4911 || lang == DW_LANG_C_plus_plus);
4914 static inline int
4915 is_cxx ()
4917 return (get_AT_unsigned (comp_unit_die, DW_AT_language)
4918 == DW_LANG_C_plus_plus);
4921 static inline int
4922 is_fortran ()
4924 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4926 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4929 static inline int
4930 is_java ()
4932 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4934 return (lang == DW_LANG_Java);
4937 /* Free up the memory used by A. */
4939 static inline void free_AT PARAMS ((dw_attr_ref));
4940 static inline void
4941 free_AT (a)
4942 dw_attr_ref a;
4944 switch (AT_class (a))
4946 case dw_val_class_str:
4947 if (a->dw_attr_val.v.val_str->refcount)
4948 a->dw_attr_val.v.val_str->refcount--;
4949 break;
4951 case dw_val_class_lbl_id:
4952 case dw_val_class_lbl_offset:
4953 free (a->dw_attr_val.v.val_lbl_id);
4954 break;
4956 case dw_val_class_float:
4957 free (a->dw_attr_val.v.val_float.array);
4958 break;
4960 default:
4961 break;
4964 free (a);
4967 /* Remove the specified attribute if present. */
4969 static void
4970 remove_AT (die, attr_kind)
4971 dw_die_ref die;
4972 enum dwarf_attribute attr_kind;
4974 dw_attr_ref *p;
4975 dw_attr_ref removed = NULL;
4977 if (die != NULL)
4979 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4980 if ((*p)->dw_attr == attr_kind)
4982 removed = *p;
4983 *p = (*p)->dw_attr_next;
4984 break;
4987 if (removed != 0)
4988 free_AT (removed);
4992 /* Free up the memory used by DIE. */
4994 static inline void
4995 free_die (die)
4996 dw_die_ref die;
4998 remove_children (die);
4999 free (die);
5002 /* Discard the children of this DIE. */
5004 static void
5005 remove_children (die)
5006 dw_die_ref die;
5008 dw_die_ref child_die = die->die_child;
5010 die->die_child = NULL;
5012 while (child_die != NULL)
5014 dw_die_ref tmp_die = child_die;
5015 dw_attr_ref a;
5017 child_die = child_die->die_sib;
5019 for (a = tmp_die->die_attr; a != NULL;)
5021 dw_attr_ref tmp_a = a;
5023 a = a->dw_attr_next;
5024 free_AT (tmp_a);
5027 free_die (tmp_die);
5031 /* Add a child DIE below its parent. We build the lists up in reverse
5032 addition order, and correct that in reverse_all_dies. */
5034 static inline void
5035 add_child_die (die, child_die)
5036 dw_die_ref die;
5037 dw_die_ref child_die;
5039 if (die != NULL && child_die != NULL)
5041 if (die == child_die)
5042 abort ();
5044 child_die->die_parent = die;
5045 child_die->die_sib = die->die_child;
5046 die->die_child = child_die;
5050 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5051 is the specification, to the front of PARENT's list of children. */
5053 static void
5054 splice_child_die (parent, child)
5055 dw_die_ref parent, child;
5057 dw_die_ref *p;
5059 /* We want the declaration DIE from inside the class, not the
5060 specification DIE at toplevel. */
5061 if (child->die_parent != parent)
5063 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5065 if (tmp)
5066 child = tmp;
5069 if (child->die_parent != parent
5070 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
5071 abort ();
5073 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
5074 if (*p == child)
5076 *p = child->die_sib;
5077 break;
5080 child->die_sib = parent->die_child;
5081 parent->die_child = child;
5084 /* Return a pointer to a newly created DIE node. */
5086 static inline dw_die_ref
5087 new_die (tag_value, parent_die, t)
5088 enum dwarf_tag tag_value;
5089 dw_die_ref parent_die;
5090 tree t;
5092 dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
5094 die->die_tag = tag_value;
5096 if (parent_die != NULL)
5097 add_child_die (parent_die, die);
5098 else
5100 limbo_die_node *limbo_node;
5102 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
5103 limbo_node->die = die;
5104 limbo_node->created_for = t;
5105 limbo_node->next = limbo_die_list;
5106 limbo_die_list = limbo_node;
5109 return die;
5112 /* Return the DIE associated with the given type specifier. */
5114 static inline dw_die_ref
5115 lookup_type_die (type)
5116 tree type;
5118 return TYPE_SYMTAB_DIE (type);
5121 /* Equate a DIE to a given type specifier. */
5123 static inline void
5124 equate_type_number_to_die (type, type_die)
5125 tree type;
5126 dw_die_ref type_die;
5128 TYPE_SYMTAB_DIE (type) = type_die;
5131 /* Return the DIE associated with a given declaration. */
5133 static inline dw_die_ref
5134 lookup_decl_die (decl)
5135 tree decl;
5137 unsigned decl_id = DECL_UID (decl);
5139 return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL);
5142 /* Equate a DIE to a particular declaration. */
5144 static void
5145 equate_decl_number_to_die (decl, decl_die)
5146 tree decl;
5147 dw_die_ref decl_die;
5149 unsigned int decl_id = DECL_UID (decl);
5150 unsigned int num_allocated;
5152 if (decl_id >= decl_die_table_allocated)
5154 num_allocated
5155 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5156 / DECL_DIE_TABLE_INCREMENT)
5157 * DECL_DIE_TABLE_INCREMENT;
5159 decl_die_table
5160 = (dw_die_ref *) xrealloc (decl_die_table,
5161 sizeof (dw_die_ref) * num_allocated);
5163 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5164 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5165 decl_die_table_allocated = num_allocated;
5168 if (decl_id >= decl_die_table_in_use)
5169 decl_die_table_in_use = (decl_id + 1);
5171 decl_die_table[decl_id] = decl_die;
5174 /* Keep track of the number of spaces used to indent the
5175 output of the debugging routines that print the structure of
5176 the DIE internal representation. */
5177 static int print_indent;
5179 /* Indent the line the number of spaces given by print_indent. */
5181 static inline void
5182 print_spaces (outfile)
5183 FILE *outfile;
5185 fprintf (outfile, "%*s", print_indent, "");
5188 /* Print the information associated with a given DIE, and its children.
5189 This routine is a debugging aid only. */
5191 static void
5192 print_die (die, outfile)
5193 dw_die_ref die;
5194 FILE *outfile;
5196 dw_attr_ref a;
5197 dw_die_ref c;
5199 print_spaces (outfile);
5200 fprintf (outfile, "DIE %4lu: %s\n",
5201 die->die_offset, dwarf_tag_name (die->die_tag));
5202 print_spaces (outfile);
5203 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5204 fprintf (outfile, " offset: %lu\n", die->die_offset);
5206 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5208 print_spaces (outfile);
5209 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5211 switch (AT_class (a))
5213 case dw_val_class_addr:
5214 fprintf (outfile, "address");
5215 break;
5216 case dw_val_class_offset:
5217 fprintf (outfile, "offset");
5218 break;
5219 case dw_val_class_loc:
5220 fprintf (outfile, "location descriptor");
5221 break;
5222 case dw_val_class_loc_list:
5223 fprintf (outfile, "location list -> label:%s",
5224 AT_loc_list (a)->ll_symbol);
5225 break;
5226 case dw_val_class_range_list:
5227 fprintf (outfile, "range list");
5228 break;
5229 case dw_val_class_const:
5230 fprintf (outfile, "%ld", AT_int (a));
5231 break;
5232 case dw_val_class_unsigned_const:
5233 fprintf (outfile, "%lu", AT_unsigned (a));
5234 break;
5235 case dw_val_class_long_long:
5236 fprintf (outfile, "constant (%lu,%lu)",
5237 a->dw_attr_val.v.val_long_long.hi,
5238 a->dw_attr_val.v.val_long_long.low);
5239 break;
5240 case dw_val_class_float:
5241 fprintf (outfile, "floating-point constant");
5242 break;
5243 case dw_val_class_flag:
5244 fprintf (outfile, "%u", AT_flag (a));
5245 break;
5246 case dw_val_class_die_ref:
5247 if (AT_ref (a) != NULL)
5249 if (AT_ref (a)->die_symbol)
5250 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5251 else
5252 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5254 else
5255 fprintf (outfile, "die -> <null>");
5256 break;
5257 case dw_val_class_lbl_id:
5258 case dw_val_class_lbl_offset:
5259 fprintf (outfile, "label: %s", AT_lbl (a));
5260 break;
5261 case dw_val_class_str:
5262 if (AT_string (a) != NULL)
5263 fprintf (outfile, "\"%s\"", AT_string (a));
5264 else
5265 fprintf (outfile, "<null>");
5266 break;
5267 default:
5268 break;
5271 fprintf (outfile, "\n");
5274 if (die->die_child != NULL)
5276 print_indent += 4;
5277 for (c = die->die_child; c != NULL; c = c->die_sib)
5278 print_die (c, outfile);
5280 print_indent -= 4;
5282 if (print_indent == 0)
5283 fprintf (outfile, "\n");
5286 /* Print the contents of the source code line number correspondence table.
5287 This routine is a debugging aid only. */
5289 static void
5290 print_dwarf_line_table (outfile)
5291 FILE *outfile;
5293 unsigned i;
5294 dw_line_info_ref line_info;
5296 fprintf (outfile, "\n\nDWARF source line information\n");
5297 for (i = 1; i < line_info_table_in_use; i++)
5299 line_info = &line_info_table[i];
5300 fprintf (outfile, "%5d: ", i);
5301 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5302 fprintf (outfile, "%6ld", line_info->dw_line_num);
5303 fprintf (outfile, "\n");
5306 fprintf (outfile, "\n\n");
5309 /* Print the information collected for a given DIE. */
5311 void
5312 debug_dwarf_die (die)
5313 dw_die_ref die;
5315 print_die (die, stderr);
5318 /* Print all DWARF information collected for the compilation unit.
5319 This routine is a debugging aid only. */
5321 void
5322 debug_dwarf ()
5324 print_indent = 0;
5325 print_die (comp_unit_die, stderr);
5326 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5327 print_dwarf_line_table (stderr);
5330 /* We build up the lists of children and attributes by pushing new ones
5331 onto the beginning of the list. Reverse the lists for DIE so that
5332 they are in order of addition. */
5334 static void
5335 reverse_die_lists (die)
5336 dw_die_ref die;
5338 dw_die_ref c, cp, cn;
5339 dw_attr_ref a, ap, an;
5341 for (a = die->die_attr, ap = 0; a; a = an)
5343 an = a->dw_attr_next;
5344 a->dw_attr_next = ap;
5345 ap = a;
5348 die->die_attr = ap;
5350 for (c = die->die_child, cp = 0; c; c = cn)
5352 cn = c->die_sib;
5353 c->die_sib = cp;
5354 cp = c;
5357 die->die_child = cp;
5360 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5361 reverse all dies in add_sibling_attributes, which runs through all the dies,
5362 it would reverse all the dies. Now, however, since we don't call
5363 reverse_die_lists in add_sibling_attributes, we need a routine to
5364 recursively reverse all the dies. This is that routine. */
5366 static void
5367 reverse_all_dies (die)
5368 dw_die_ref die;
5370 dw_die_ref c;
5372 reverse_die_lists (die);
5374 for (c = die->die_child; c; c = c->die_sib)
5375 reverse_all_dies (c);
5378 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5379 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5380 DIE that marks the start of the DIEs for this include file. */
5382 static dw_die_ref
5383 push_new_compile_unit (old_unit, bincl_die)
5384 dw_die_ref old_unit, bincl_die;
5386 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5387 dw_die_ref new_unit = gen_compile_unit_die (filename);
5389 new_unit->die_sib = old_unit;
5390 return new_unit;
5393 /* Close an include-file CU and reopen the enclosing one. */
5395 static dw_die_ref
5396 pop_compile_unit (old_unit)
5397 dw_die_ref old_unit;
5399 dw_die_ref new_unit = old_unit->die_sib;
5401 old_unit->die_sib = NULL;
5402 return new_unit;
5405 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5406 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5408 /* Calculate the checksum of a location expression. */
5410 static inline void
5411 loc_checksum (loc, ctx)
5412 dw_loc_descr_ref loc;
5413 struct md5_ctx *ctx;
5415 CHECKSUM (loc->dw_loc_opc);
5416 CHECKSUM (loc->dw_loc_oprnd1);
5417 CHECKSUM (loc->dw_loc_oprnd2);
5420 /* Calculate the checksum of an attribute. */
5422 static void
5423 attr_checksum (at, ctx)
5424 dw_attr_ref at;
5425 struct md5_ctx *ctx;
5427 dw_loc_descr_ref loc;
5428 rtx r;
5430 CHECKSUM (at->dw_attr);
5432 /* We don't care about differences in file numbering. */
5433 if (at->dw_attr == DW_AT_decl_file
5434 /* Or that this was compiled with a different compiler snapshot; if
5435 the output is the same, that's what matters. */
5436 || at->dw_attr == DW_AT_producer)
5437 return;
5439 switch (AT_class (at))
5441 case dw_val_class_const:
5442 CHECKSUM (at->dw_attr_val.v.val_int);
5443 break;
5444 case dw_val_class_unsigned_const:
5445 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5446 break;
5447 case dw_val_class_long_long:
5448 CHECKSUM (at->dw_attr_val.v.val_long_long);
5449 break;
5450 case dw_val_class_float:
5451 CHECKSUM (at->dw_attr_val.v.val_float);
5452 break;
5453 case dw_val_class_flag:
5454 CHECKSUM (at->dw_attr_val.v.val_flag);
5455 break;
5456 case dw_val_class_str:
5457 CHECKSUM_STRING (AT_string (at));
5458 break;
5460 case dw_val_class_addr:
5461 r = AT_addr (at);
5462 switch (GET_CODE (r))
5464 case SYMBOL_REF:
5465 CHECKSUM_STRING (XSTR (r, 0));
5466 break;
5468 default:
5469 abort ();
5471 break;
5473 case dw_val_class_offset:
5474 CHECKSUM (at->dw_attr_val.v.val_offset);
5475 break;
5477 case dw_val_class_loc:
5478 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5479 loc_checksum (loc, ctx);
5480 break;
5482 case dw_val_class_die_ref:
5483 if (AT_ref (at)->die_offset)
5484 CHECKSUM (AT_ref (at)->die_offset);
5485 /* FIXME else use target die name or something. */
5487 case dw_val_class_fde_ref:
5488 case dw_val_class_lbl_id:
5489 case dw_val_class_lbl_offset:
5490 break;
5492 default:
5493 break;
5497 /* Calculate the checksum of a DIE. */
5499 static void
5500 die_checksum (die, ctx)
5501 dw_die_ref die;
5502 struct md5_ctx *ctx;
5504 dw_die_ref c;
5505 dw_attr_ref a;
5507 CHECKSUM (die->die_tag);
5509 for (a = die->die_attr; a; a = a->dw_attr_next)
5510 attr_checksum (a, ctx);
5512 for (c = die->die_child; c; c = c->die_sib)
5513 die_checksum (c, ctx);
5516 #undef CHECKSUM
5517 #undef CHECKSUM_STRING
5519 /* The prefix to attach to symbols on DIEs in the current comdat debug
5520 info section. */
5521 static char *comdat_symbol_id;
5523 /* The index of the current symbol within the current comdat CU. */
5524 static unsigned int comdat_symbol_number;
5526 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5527 children, and set comdat_symbol_id accordingly. */
5529 static void
5530 compute_section_prefix (unit_die)
5531 dw_die_ref unit_die;
5533 const char *base = lbasename (get_AT_string (unit_die, DW_AT_name));
5534 char *name = (char *) alloca (strlen (base) + 64);
5535 char *p;
5536 int i;
5537 unsigned char checksum[16];
5538 struct md5_ctx ctx;
5540 /* Compute the checksum of the DIE, then append part of it as hex digits to
5541 the name filename of the unit. */
5543 md5_init_ctx (&ctx);
5544 die_checksum (unit_die, &ctx);
5545 md5_finish_ctx (&ctx, checksum);
5547 sprintf (name, "%s.", base);
5548 clean_symbol_name (name);
5550 p = name + strlen (name);
5551 for (i = 0; i < 4; i++)
5553 sprintf (p, "%.2x", checksum[i]);
5554 p += 2;
5557 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5558 comdat_symbol_number = 0;
5561 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5563 static int
5564 is_type_die (die)
5565 dw_die_ref die;
5567 switch (die->die_tag)
5569 case DW_TAG_array_type:
5570 case DW_TAG_class_type:
5571 case DW_TAG_enumeration_type:
5572 case DW_TAG_pointer_type:
5573 case DW_TAG_reference_type:
5574 case DW_TAG_string_type:
5575 case DW_TAG_structure_type:
5576 case DW_TAG_subroutine_type:
5577 case DW_TAG_union_type:
5578 case DW_TAG_ptr_to_member_type:
5579 case DW_TAG_set_type:
5580 case DW_TAG_subrange_type:
5581 case DW_TAG_base_type:
5582 case DW_TAG_const_type:
5583 case DW_TAG_file_type:
5584 case DW_TAG_packed_type:
5585 case DW_TAG_volatile_type:
5586 return 1;
5587 default:
5588 return 0;
5592 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5593 Basically, we want to choose the bits that are likely to be shared between
5594 compilations (types) and leave out the bits that are specific to individual
5595 compilations (functions). */
5597 static int
5598 is_comdat_die (c)
5599 dw_die_ref c;
5601 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5602 we do for stabs. The advantage is a greater likelihood of sharing between
5603 objects that don't include headers in the same order (and therefore would
5604 put the base types in a different comdat). jason 8/28/00 */
5606 if (c->die_tag == DW_TAG_base_type)
5607 return 0;
5609 if (c->die_tag == DW_TAG_pointer_type
5610 || c->die_tag == DW_TAG_reference_type
5611 || c->die_tag == DW_TAG_const_type
5612 || c->die_tag == DW_TAG_volatile_type)
5614 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5616 return t ? is_comdat_die (t) : 0;
5619 return is_type_die (c);
5622 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5623 compilation unit. */
5625 static int
5626 is_symbol_die (c)
5627 dw_die_ref c;
5629 return (is_type_die (c)
5630 || (get_AT (c, DW_AT_declaration)
5631 && !get_AT (c, DW_AT_specification)));
5634 static char *
5635 gen_internal_sym (prefix)
5636 const char *prefix;
5638 char buf[256];
5639 static int label_num;
5641 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5642 return xstrdup (buf);
5645 /* Assign symbols to all worthy DIEs under DIE. */
5647 static void
5648 assign_symbol_names (die)
5649 dw_die_ref die;
5651 dw_die_ref c;
5653 if (is_symbol_die (die))
5655 if (comdat_symbol_id)
5657 char *p = alloca (strlen (comdat_symbol_id) + 64);
5659 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5660 comdat_symbol_id, comdat_symbol_number++);
5661 die->die_symbol = xstrdup (p);
5663 else
5664 die->die_symbol = gen_internal_sym ("LDIE");
5667 for (c = die->die_child; c != NULL; c = c->die_sib)
5668 assign_symbol_names (c);
5671 /* Traverse the DIE (which is always comp_unit_die), and set up
5672 additional compilation units for each of the include files we see
5673 bracketed by BINCL/EINCL. */
5675 static void
5676 break_out_includes (die)
5677 dw_die_ref die;
5679 dw_die_ref *ptr;
5680 dw_die_ref unit = NULL;
5681 limbo_die_node *node;
5683 for (ptr = &(die->die_child); *ptr;)
5685 dw_die_ref c = *ptr;
5687 if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
5688 || (unit && is_comdat_die (c)))
5690 /* This DIE is for a secondary CU; remove it from the main one. */
5691 *ptr = c->die_sib;
5693 if (c->die_tag == DW_TAG_GNU_BINCL)
5695 unit = push_new_compile_unit (unit, c);
5696 free_die (c);
5698 else if (c->die_tag == DW_TAG_GNU_EINCL)
5700 unit = pop_compile_unit (unit);
5701 free_die (c);
5703 else
5704 add_child_die (unit, c);
5706 else
5708 /* Leave this DIE in the main CU. */
5709 ptr = &(c->die_sib);
5710 continue;
5714 #if 0
5715 /* We can only use this in debugging, since the frontend doesn't check
5716 to make sure that we leave every include file we enter. */
5717 if (unit != NULL)
5718 abort ();
5719 #endif
5721 assign_symbol_names (die);
5722 for (node = limbo_die_list; node; node = node->next)
5724 compute_section_prefix (node->die);
5725 assign_symbol_names (node->die);
5729 /* Traverse the DIE and add a sibling attribute if it may have the
5730 effect of speeding up access to siblings. To save some space,
5731 avoid generating sibling attributes for DIE's without children. */
5733 static void
5734 add_sibling_attributes (die)
5735 dw_die_ref die;
5737 dw_die_ref c;
5739 if (die->die_tag != DW_TAG_compile_unit
5740 && die->die_sib && die->die_child != NULL)
5741 /* Add the sibling link to the front of the attribute list. */
5742 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5744 for (c = die->die_child; c != NULL; c = c->die_sib)
5745 add_sibling_attributes (c);
5748 /* Output all location lists for the DIE and its children. */
5750 static void
5751 output_location_lists (die)
5752 dw_die_ref die;
5754 dw_die_ref c;
5755 dw_attr_ref d_attr;
5757 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5758 if (AT_class (d_attr) == dw_val_class_loc_list)
5759 output_loc_list (AT_loc_list (d_attr));
5761 for (c = die->die_child; c != NULL; c = c->die_sib)
5762 output_location_lists (c);
5766 /* The format of each DIE (and its attribute value pairs) is encoded in an
5767 abbreviation table. This routine builds the abbreviation table and assigns
5768 a unique abbreviation id for each abbreviation entry. The children of each
5769 die are visited recursively. */
5771 static void
5772 build_abbrev_table (die)
5773 dw_die_ref die;
5775 unsigned long abbrev_id;
5776 unsigned int n_alloc;
5777 dw_die_ref c;
5778 dw_attr_ref d_attr, a_attr;
5780 /* Scan the DIE references, and mark as external any that refer to
5781 DIEs from other CUs (i.e. those which are not marked). */
5782 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5783 if (AT_class (d_attr) == dw_val_class_die_ref
5784 && AT_ref (d_attr)->die_mark == 0)
5786 if (AT_ref (d_attr)->die_symbol == 0)
5787 abort ();
5789 set_AT_ref_external (d_attr, 1);
5792 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5794 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5796 if (abbrev->die_tag == die->die_tag)
5798 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5800 a_attr = abbrev->die_attr;
5801 d_attr = die->die_attr;
5803 while (a_attr != NULL && d_attr != NULL)
5805 if ((a_attr->dw_attr != d_attr->dw_attr)
5806 || (value_format (a_attr) != value_format (d_attr)))
5807 break;
5809 a_attr = a_attr->dw_attr_next;
5810 d_attr = d_attr->dw_attr_next;
5813 if (a_attr == NULL && d_attr == NULL)
5814 break;
5819 if (abbrev_id >= abbrev_die_table_in_use)
5821 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5823 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5824 abbrev_die_table
5825 = (dw_die_ref *) xrealloc (abbrev_die_table,
5826 sizeof (dw_die_ref) * n_alloc);
5828 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5829 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5830 abbrev_die_table_allocated = n_alloc;
5833 ++abbrev_die_table_in_use;
5834 abbrev_die_table[abbrev_id] = die;
5837 die->die_abbrev = abbrev_id;
5838 for (c = die->die_child; c != NULL; c = c->die_sib)
5839 build_abbrev_table (c);
5842 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5844 static int
5845 constant_size (value)
5846 long unsigned value;
5848 int log;
5850 if (value == 0)
5851 log = 0;
5852 else
5853 log = floor_log2 (value);
5855 log = log / 8;
5856 log = 1 << (floor_log2 (log) + 1);
5858 return log;
5861 /* Return the size of a DIE as it is represented in the
5862 .debug_info section. */
5864 static unsigned long
5865 size_of_die (die)
5866 dw_die_ref die;
5868 unsigned long size = 0;
5869 dw_attr_ref a;
5871 size += size_of_uleb128 (die->die_abbrev);
5872 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5874 switch (AT_class (a))
5876 case dw_val_class_addr:
5877 size += DWARF2_ADDR_SIZE;
5878 break;
5879 case dw_val_class_offset:
5880 size += DWARF_OFFSET_SIZE;
5881 break;
5882 case dw_val_class_loc:
5884 unsigned long lsize = size_of_locs (AT_loc (a));
5886 /* Block length. */
5887 size += constant_size (lsize);
5888 size += lsize;
5890 break;
5891 case dw_val_class_loc_list:
5892 size += DWARF_OFFSET_SIZE;
5893 break;
5894 case dw_val_class_range_list:
5895 size += DWARF_OFFSET_SIZE;
5896 break;
5897 case dw_val_class_const:
5898 size += size_of_sleb128 (AT_int (a));
5899 break;
5900 case dw_val_class_unsigned_const:
5901 size += constant_size (AT_unsigned (a));
5902 break;
5903 case dw_val_class_long_long:
5904 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5905 break;
5906 case dw_val_class_float:
5907 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5908 break;
5909 case dw_val_class_flag:
5910 size += 1;
5911 break;
5912 case dw_val_class_die_ref:
5913 size += DWARF_OFFSET_SIZE;
5914 break;
5915 case dw_val_class_fde_ref:
5916 size += DWARF_OFFSET_SIZE;
5917 break;
5918 case dw_val_class_lbl_id:
5919 size += DWARF2_ADDR_SIZE;
5920 break;
5921 case dw_val_class_lbl_offset:
5922 size += DWARF_OFFSET_SIZE;
5923 break;
5924 case dw_val_class_str:
5925 if (AT_string_form (a) == DW_FORM_strp)
5926 size += DWARF_OFFSET_SIZE;
5927 else
5928 size += HT_LEN (&a->dw_attr_val.v.val_str->id) + 1;
5929 break;
5930 default:
5931 abort ();
5935 return size;
5938 /* Size the debugging information associated with a given DIE. Visits the
5939 DIE's children recursively. Updates the global variable next_die_offset, on
5940 each time through. Uses the current value of next_die_offset to update the
5941 die_offset field in each DIE. */
5943 static void
5944 calc_die_sizes (die)
5945 dw_die_ref die;
5947 dw_die_ref c;
5949 die->die_offset = next_die_offset;
5950 next_die_offset += size_of_die (die);
5952 for (c = die->die_child; c != NULL; c = c->die_sib)
5953 calc_die_sizes (c);
5955 if (die->die_child != NULL)
5956 /* Count the null byte used to terminate sibling lists. */
5957 next_die_offset += 1;
5960 /* Set the marks for a die and its children. We do this so
5961 that we know whether or not a reference needs to use FORM_ref_addr; only
5962 DIEs in the same CU will be marked. We used to clear out the offset
5963 and use that as the flag, but ran into ordering problems. */
5965 static void
5966 mark_dies (die)
5967 dw_die_ref die;
5969 dw_die_ref c;
5971 die->die_mark = 1;
5972 for (c = die->die_child; c; c = c->die_sib)
5973 mark_dies (c);
5976 /* Clear the marks for a die and its children. */
5978 static void
5979 unmark_dies (die)
5980 dw_die_ref die;
5982 dw_die_ref c;
5984 die->die_mark = 0;
5985 for (c = die->die_child; c; c = c->die_sib)
5986 unmark_dies (c);
5989 /* Return the size of the .debug_pubnames table generated for the
5990 compilation unit. */
5992 static unsigned long
5993 size_of_pubnames ()
5995 unsigned long size;
5996 unsigned i;
5998 size = DWARF_PUBNAMES_HEADER_SIZE;
5999 for (i = 0; i < pubname_table_in_use; i++)
6001 pubname_ref p = &pubname_table[i];
6002 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
6005 size += DWARF_OFFSET_SIZE;
6006 return size;
6009 /* Return the size of the information in the .debug_aranges section. */
6011 static unsigned long
6012 size_of_aranges ()
6014 unsigned long size;
6016 size = DWARF_ARANGES_HEADER_SIZE;
6018 /* Count the address/length pair for this compilation unit. */
6019 size += 2 * DWARF2_ADDR_SIZE;
6020 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6022 /* Count the two zero words used to terminated the address range table. */
6023 size += 2 * DWARF2_ADDR_SIZE;
6024 return size;
6027 /* Select the encoding of an attribute value. */
6029 static enum dwarf_form
6030 value_format (a)
6031 dw_attr_ref a;
6033 switch (a->dw_attr_val.val_class)
6035 case dw_val_class_addr:
6036 return DW_FORM_addr;
6037 case dw_val_class_range_list:
6038 case dw_val_class_offset:
6039 if (DWARF_OFFSET_SIZE == 4)
6040 return DW_FORM_data4;
6041 if (DWARF_OFFSET_SIZE == 8)
6042 return DW_FORM_data8;
6043 abort ();
6044 case dw_val_class_loc_list:
6045 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6046 .debug_loc section */
6047 return DW_FORM_data4;
6048 case dw_val_class_loc:
6049 switch (constant_size (size_of_locs (AT_loc (a))))
6051 case 1:
6052 return DW_FORM_block1;
6053 case 2:
6054 return DW_FORM_block2;
6055 default:
6056 abort ();
6058 case dw_val_class_const:
6059 return DW_FORM_sdata;
6060 case dw_val_class_unsigned_const:
6061 switch (constant_size (AT_unsigned (a)))
6063 case 1:
6064 return DW_FORM_data1;
6065 case 2:
6066 return DW_FORM_data2;
6067 case 4:
6068 return DW_FORM_data4;
6069 case 8:
6070 return DW_FORM_data8;
6071 default:
6072 abort ();
6074 case dw_val_class_long_long:
6075 return DW_FORM_block1;
6076 case dw_val_class_float:
6077 return DW_FORM_block1;
6078 case dw_val_class_flag:
6079 return DW_FORM_flag;
6080 case dw_val_class_die_ref:
6081 if (AT_ref_external (a))
6082 return DW_FORM_ref_addr;
6083 else
6084 return DW_FORM_ref;
6085 case dw_val_class_fde_ref:
6086 return DW_FORM_data;
6087 case dw_val_class_lbl_id:
6088 return DW_FORM_addr;
6089 case dw_val_class_lbl_offset:
6090 return DW_FORM_data;
6091 case dw_val_class_str:
6092 return AT_string_form (a);
6094 default:
6095 abort ();
6099 /* Output the encoding of an attribute value. */
6101 static void
6102 output_value_format (a)
6103 dw_attr_ref a;
6105 enum dwarf_form form = value_format (a);
6107 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6110 /* Output the .debug_abbrev section which defines the DIE abbreviation
6111 table. */
6113 static void
6114 output_abbrev_section ()
6116 unsigned long abbrev_id;
6118 dw_attr_ref a_attr;
6120 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6122 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6124 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6125 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6126 dwarf_tag_name (abbrev->die_tag));
6128 if (abbrev->die_child != NULL)
6129 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6130 else
6131 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6133 for (a_attr = abbrev->die_attr; a_attr != NULL;
6134 a_attr = a_attr->dw_attr_next)
6136 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6137 dwarf_attr_name (a_attr->dw_attr));
6138 output_value_format (a_attr);
6141 dw2_asm_output_data (1, 0, NULL);
6142 dw2_asm_output_data (1, 0, NULL);
6145 /* Terminate the table. */
6146 dw2_asm_output_data (1, 0, NULL);
6149 /* Output a symbol we can use to refer to this DIE from another CU. */
6151 static inline void
6152 output_die_symbol (die)
6153 dw_die_ref die;
6155 char *sym = die->die_symbol;
6157 if (sym == 0)
6158 return;
6160 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6161 /* We make these global, not weak; if the target doesn't support
6162 .linkonce, it doesn't support combining the sections, so debugging
6163 will break. */
6164 (*targetm.asm_out.globalize_label) (asm_out_file, sym);
6166 ASM_OUTPUT_LABEL (asm_out_file, sym);
6169 /* Return a new location list, given the begin and end range, and the
6170 expression. gensym tells us whether to generate a new internal symbol for
6171 this location list node, which is done for the head of the list only. */
6173 static inline dw_loc_list_ref
6174 new_loc_list (expr, begin, end, section, gensym)
6175 dw_loc_descr_ref expr;
6176 const char *begin;
6177 const char *end;
6178 const char *section;
6179 unsigned gensym;
6181 dw_loc_list_ref retlist
6182 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
6184 retlist->begin = begin;
6185 retlist->end = end;
6186 retlist->expr = expr;
6187 retlist->section = section;
6188 if (gensym)
6189 retlist->ll_symbol = gen_internal_sym ("LLST");
6191 return retlist;
6194 /* Add a location description expression to a location list */
6196 static inline void
6197 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
6198 dw_loc_list_ref *list_head;
6199 dw_loc_descr_ref descr;
6200 const char *begin;
6201 const char *end;
6202 const char *section;
6204 dw_loc_list_ref *d;
6206 /* Find the end of the chain. */
6207 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6210 /* Add a new location list node to the list */
6211 *d = new_loc_list (descr, begin, end, section, 0);
6214 /* Output the location list given to us */
6216 static void
6217 output_loc_list (list_head)
6218 dw_loc_list_ref list_head;
6220 dw_loc_list_ref curr = list_head;
6222 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6224 /* ??? This shouldn't be needed now that we've forced the
6225 compilation unit base address to zero when there is code
6226 in more than one section. */
6227 if (strcmp (curr->section, ".text") == 0)
6229 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6230 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0,
6231 "Location list base address specifier fake entry");
6232 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
6233 "Location list base address specifier base");
6236 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
6238 unsigned long size;
6240 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6241 "Location list begin address (%s)",
6242 list_head->ll_symbol);
6243 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6244 "Location list end address (%s)",
6245 list_head->ll_symbol);
6246 size = size_of_locs (curr->expr);
6248 /* Output the block length for this list of location operations. */
6249 if (size > 0xffff)
6250 abort ();
6251 dw2_asm_output_data (2, size, "%s", "Location expression size");
6253 output_loc_sequence (curr->expr);
6256 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6257 "Location list terminator begin (%s)",
6258 list_head->ll_symbol);
6259 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6260 "Location list terminator end (%s)",
6261 list_head->ll_symbol);
6264 /* Output the DIE and its attributes. Called recursively to generate
6265 the definitions of each child DIE. */
6267 static void
6268 output_die (die)
6269 dw_die_ref die;
6271 dw_attr_ref a;
6272 dw_die_ref c;
6273 unsigned long size;
6275 /* If someone in another CU might refer to us, set up a symbol for
6276 them to point to. */
6277 if (die->die_symbol)
6278 output_die_symbol (die);
6280 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6281 die->die_offset, dwarf_tag_name (die->die_tag));
6283 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6285 const char *name = dwarf_attr_name (a->dw_attr);
6287 switch (AT_class (a))
6289 case dw_val_class_addr:
6290 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6291 break;
6293 case dw_val_class_offset:
6294 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6295 "%s", name);
6296 break;
6298 case dw_val_class_range_list:
6300 char *p = strchr (ranges_section_label, '\0');
6302 sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset);
6303 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
6304 "%s", name);
6305 *p = '\0';
6307 break;
6309 case dw_val_class_loc:
6310 size = size_of_locs (AT_loc (a));
6312 /* Output the block length for this list of location operations. */
6313 dw2_asm_output_data (constant_size (size), size, "%s", name);
6315 output_loc_sequence (AT_loc (a));
6316 break;
6318 case dw_val_class_const:
6319 /* ??? It would be slightly more efficient to use a scheme like is
6320 used for unsigned constants below, but gdb 4.x does not sign
6321 extend. Gdb 5.x does sign extend. */
6322 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6323 break;
6325 case dw_val_class_unsigned_const:
6326 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6327 AT_unsigned (a), "%s", name);
6328 break;
6330 case dw_val_class_long_long:
6332 unsigned HOST_WIDE_INT first, second;
6334 dw2_asm_output_data (1,
6335 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6336 "%s", name);
6338 if (WORDS_BIG_ENDIAN)
6340 first = a->dw_attr_val.v.val_long_long.hi;
6341 second = a->dw_attr_val.v.val_long_long.low;
6343 else
6345 first = a->dw_attr_val.v.val_long_long.low;
6346 second = a->dw_attr_val.v.val_long_long.hi;
6349 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6350 first, "long long constant");
6351 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6352 second, NULL);
6354 break;
6356 case dw_val_class_float:
6358 unsigned int i;
6360 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6361 "%s", name);
6363 for (i = 0; i < a->dw_attr_val.v.val_float.length; i++)
6364 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6365 "fp constant word %u", i);
6366 break;
6369 case dw_val_class_flag:
6370 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6371 break;
6373 case dw_val_class_loc_list:
6375 char *sym = AT_loc_list (a)->ll_symbol;
6377 if (sym == 0)
6378 abort ();
6379 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
6380 loc_section_label, "%s", name);
6382 break;
6384 case dw_val_class_die_ref:
6385 if (AT_ref_external (a))
6387 char *sym = AT_ref (a)->die_symbol;
6389 if (sym == 0)
6390 abort ();
6391 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6393 else if (AT_ref (a)->die_offset == 0)
6394 abort ();
6395 else
6396 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6397 "%s", name);
6398 break;
6400 case dw_val_class_fde_ref:
6402 char l1[20];
6404 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6405 a->dw_attr_val.v.val_fde_index * 2);
6406 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6408 break;
6410 case dw_val_class_lbl_id:
6411 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6412 break;
6414 case dw_val_class_lbl_offset:
6415 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6416 break;
6418 case dw_val_class_str:
6419 if (AT_string_form (a) == DW_FORM_strp)
6420 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
6421 a->dw_attr_val.v.val_str->label,
6422 "%s: \"%s\"", name, AT_string (a));
6423 else
6424 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6425 break;
6427 default:
6428 abort ();
6432 for (c = die->die_child; c != NULL; c = c->die_sib)
6433 output_die (c);
6435 /* Add null byte to terminate sibling list. */
6436 if (die->die_child != NULL)
6437 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6438 die->die_offset);
6441 /* Output the compilation unit that appears at the beginning of the
6442 .debug_info section, and precedes the DIE descriptions. */
6444 static void
6445 output_compilation_unit_header ()
6447 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6448 "Length of Compilation Unit Info");
6449 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6450 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6451 "Offset Into Abbrev. Section");
6452 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6455 /* Output the compilation unit DIE and its children. */
6457 static void
6458 output_comp_unit (die)
6459 dw_die_ref die;
6461 const char *secname;
6463 /* Even if there are no children of this DIE, we must output the information
6464 about the compilation unit. Otherwise, on an empty translation unit, we
6465 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6466 will then complain when examining the file. First mark all the DIEs in
6467 this CU so we know which get local refs. */
6468 mark_dies (die);
6470 build_abbrev_table (die);
6472 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6473 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6474 calc_die_sizes (die);
6476 if (die->die_symbol)
6478 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6480 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6481 secname = tmp;
6482 die->die_symbol = NULL;
6484 else
6485 secname = (const char *) DEBUG_INFO_SECTION;
6487 /* Output debugging information. */
6488 named_section_flags (secname, SECTION_DEBUG);
6489 output_compilation_unit_header ();
6490 output_die (die);
6492 /* Leave the marks on the main CU, so we can check them in
6493 output_pubnames. */
6494 if (die->die_symbol)
6495 unmark_dies (die);
6498 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
6499 output of lang_hooks.decl_printable_name for C++ looks like
6500 "A::f(int)". Let's drop the argument list, and maybe the scope. */
6502 static const char *
6503 dwarf2_name (decl, scope)
6504 tree decl;
6505 int scope;
6507 return (*lang_hooks.decl_printable_name) (decl, scope ? 1 : 0);
6510 /* Add a new entry to .debug_pubnames if appropriate. */
6512 static void
6513 add_pubname (decl, die)
6514 tree decl;
6515 dw_die_ref die;
6517 pubname_ref p;
6519 if (! TREE_PUBLIC (decl))
6520 return;
6522 if (pubname_table_in_use == pubname_table_allocated)
6524 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6525 pubname_table
6526 = (pubname_ref) xrealloc (pubname_table,
6527 (pubname_table_allocated
6528 * sizeof (pubname_entry)));
6531 p = &pubname_table[pubname_table_in_use++];
6532 p->die = die;
6533 p->name = xstrdup (dwarf2_name (decl, 1));
6536 /* Output the public names table used to speed up access to externally
6537 visible names. For now, only generate entries for externally
6538 visible procedures. */
6540 static void
6541 output_pubnames ()
6543 unsigned i;
6544 unsigned long pubnames_length = size_of_pubnames ();
6546 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6547 "Length of Public Names Info");
6548 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6549 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6550 "Offset of Compilation Unit Info");
6551 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6552 "Compilation Unit Length");
6554 for (i = 0; i < pubname_table_in_use; i++)
6556 pubname_ref pub = &pubname_table[i];
6558 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6559 if (pub->die->die_mark == 0)
6560 abort ();
6562 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6563 "DIE offset");
6565 dw2_asm_output_nstring (pub->name, -1, "external name");
6568 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6571 /* Add a new entry to .debug_aranges if appropriate. */
6573 static void
6574 add_arange (decl, die)
6575 tree decl;
6576 dw_die_ref die;
6578 if (! DECL_SECTION_NAME (decl))
6579 return;
6581 if (arange_table_in_use == arange_table_allocated)
6583 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6584 arange_table = (dw_die_ref *)
6585 xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref));
6588 arange_table[arange_table_in_use++] = die;
6591 /* Output the information that goes into the .debug_aranges table.
6592 Namely, define the beginning and ending address range of the
6593 text section generated for this compilation unit. */
6595 static void
6596 output_aranges ()
6598 unsigned i;
6599 unsigned long aranges_length = size_of_aranges ();
6601 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6602 "Length of Address Ranges Info");
6603 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6604 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6605 "Offset of Compilation Unit Info");
6606 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6607 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6609 /* We need to align to twice the pointer size here. */
6610 if (DWARF_ARANGES_PAD_SIZE)
6612 /* Pad using a 2 byte words so that padding is correct for any
6613 pointer size. */
6614 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6615 2 * DWARF2_ADDR_SIZE);
6616 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6617 dw2_asm_output_data (2, 0, NULL);
6620 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6621 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6622 text_section_label, "Length");
6624 for (i = 0; i < arange_table_in_use; i++)
6626 dw_die_ref die = arange_table[i];
6628 /* We shouldn't see aranges for DIEs outside of the main CU. */
6629 if (die->die_mark == 0)
6630 abort ();
6632 if (die->die_tag == DW_TAG_subprogram)
6634 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6635 "Address");
6636 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6637 get_AT_low_pc (die), "Length");
6639 else
6641 /* A static variable; extract the symbol from DW_AT_location.
6642 Note that this code isn't currently hit, as we only emit
6643 aranges for functions (jason 9/23/99). */
6644 dw_attr_ref a = get_AT (die, DW_AT_location);
6645 dw_loc_descr_ref loc;
6647 if (! a || AT_class (a) != dw_val_class_loc)
6648 abort ();
6650 loc = AT_loc (a);
6651 if (loc->dw_loc_opc != DW_OP_addr)
6652 abort ();
6654 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6655 loc->dw_loc_oprnd1.v.val_addr, "Address");
6656 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6657 get_AT_unsigned (die, DW_AT_byte_size),
6658 "Length");
6662 /* Output the terminator words. */
6663 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6664 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6667 /* Add a new entry to .debug_ranges. Return the offset at which it
6668 was placed. */
6670 static unsigned int
6671 add_ranges (block)
6672 tree block;
6674 unsigned int in_use = ranges_table_in_use;
6676 if (in_use == ranges_table_allocated)
6678 ranges_table_allocated += RANGES_TABLE_INCREMENT;
6679 ranges_table = (dw_ranges_ref)
6680 xrealloc (ranges_table, (ranges_table_allocated
6681 * sizeof (struct dw_ranges_struct)));
6684 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
6685 ranges_table_in_use = in_use + 1;
6687 return in_use * 2 * DWARF2_ADDR_SIZE;
6690 static void
6691 output_ranges ()
6693 unsigned i;
6694 static const char *const start_fmt = "Offset 0x%x";
6695 const char *fmt = start_fmt;
6697 for (i = 0; i < ranges_table_in_use; i++)
6699 int block_num = ranges_table[i].block_num;
6701 if (block_num)
6703 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
6704 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
6706 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
6707 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
6709 /* If all code is in the text section, then the compilation
6710 unit base address defaults to DW_AT_low_pc, which is the
6711 base of the text section. */
6712 if (separate_line_info_table_in_use == 0)
6714 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
6715 text_section_label,
6716 fmt, i * 2 * DWARF2_ADDR_SIZE);
6717 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
6718 text_section_label, NULL);
6721 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6722 compilation unit base address to zero, which allows us to
6723 use absolute addresses, and not worry about whether the
6724 target supports cross-section arithmetic. */
6725 else
6727 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
6728 fmt, i * 2 * DWARF2_ADDR_SIZE);
6729 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
6732 fmt = NULL;
6734 else
6736 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6737 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6738 fmt = start_fmt;
6743 /* Data structure containing information about input files. */
6744 struct file_info
6746 char *path; /* Complete file name. */
6747 char *fname; /* File name part. */
6748 int length; /* Length of entire string. */
6749 int file_idx; /* Index in input file table. */
6750 int dir_idx; /* Index in directory table. */
6753 /* Data structure containing information about directories with source
6754 files. */
6755 struct dir_info
6757 char *path; /* Path including directory name. */
6758 int length; /* Path length. */
6759 int prefix; /* Index of directory entry which is a prefix. */
6760 int count; /* Number of files in this directory. */
6761 int dir_idx; /* Index of directory used as base. */
6762 int used; /* Used in the end? */
6765 /* Callback function for file_info comparison. We sort by looking at
6766 the directories in the path. */
6768 static int
6769 file_info_cmp (p1, p2)
6770 const void *p1;
6771 const void *p2;
6773 const struct file_info *s1 = p1;
6774 const struct file_info *s2 = p2;
6775 unsigned char *cp1;
6776 unsigned char *cp2;
6778 /* Take care of file names without directories. We need to make sure that
6779 we return consistent values to qsort since some will get confused if
6780 we return the same value when identical operands are passed in opposite
6781 orders. So if neither has a directory, return 0 and otherwise return
6782 1 or -1 depending on which one has the directory. */
6783 if ((s1->path == s1->fname || s2->path == s2->fname))
6784 return (s2->path == s2->fname) - (s1->path == s1->fname);
6786 cp1 = (unsigned char *) s1->path;
6787 cp2 = (unsigned char *) s2->path;
6789 while (1)
6791 ++cp1;
6792 ++cp2;
6793 /* Reached the end of the first path? If so, handle like above. */
6794 if ((cp1 == (unsigned char *) s1->fname)
6795 || (cp2 == (unsigned char *) s2->fname))
6796 return ((cp2 == (unsigned char *) s2->fname)
6797 - (cp1 == (unsigned char *) s1->fname));
6799 /* Character of current path component the same? */
6800 else if (*cp1 != *cp2)
6801 return *cp1 - *cp2;
6805 /* Output the directory table and the file name table. We try to minimize
6806 the total amount of memory needed. A heuristic is used to avoid large
6807 slowdowns with many input files. */
6809 static void
6810 output_file_names ()
6812 struct file_info *files;
6813 struct dir_info *dirs;
6814 int *saved;
6815 int *savehere;
6816 int *backmap;
6817 int ndirs;
6818 int idx_offset;
6819 int i;
6820 int idx;
6822 /* Allocate the various arrays we need. */
6823 files = (struct file_info *) alloca (file_table.in_use
6824 * sizeof (struct file_info));
6825 dirs = (struct dir_info *) alloca (file_table.in_use
6826 * sizeof (struct dir_info));
6828 /* Sort the file names. */
6829 for (i = 1; i < (int) file_table.in_use; i++)
6831 char *f;
6833 /* Skip all leading "./". */
6834 f = file_table.table[i];
6835 while (f[0] == '.' && f[1] == '/')
6836 f += 2;
6838 /* Create a new array entry. */
6839 files[i].path = f;
6840 files[i].length = strlen (f);
6841 files[i].file_idx = i;
6843 /* Search for the file name part. */
6844 f = strrchr (f, '/');
6845 files[i].fname = f == NULL ? files[i].path : f + 1;
6848 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6850 /* Find all the different directories used. */
6851 dirs[0].path = files[1].path;
6852 dirs[0].length = files[1].fname - files[1].path;
6853 dirs[0].prefix = -1;
6854 dirs[0].count = 1;
6855 dirs[0].dir_idx = 0;
6856 dirs[0].used = 0;
6857 files[1].dir_idx = 0;
6858 ndirs = 1;
6860 for (i = 2; i < (int) file_table.in_use; i++)
6861 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6862 && memcmp (dirs[ndirs - 1].path, files[i].path,
6863 dirs[ndirs - 1].length) == 0)
6865 /* Same directory as last entry. */
6866 files[i].dir_idx = ndirs - 1;
6867 ++dirs[ndirs - 1].count;
6869 else
6871 int j;
6873 /* This is a new directory. */
6874 dirs[ndirs].path = files[i].path;
6875 dirs[ndirs].length = files[i].fname - files[i].path;
6876 dirs[ndirs].count = 1;
6877 dirs[ndirs].dir_idx = ndirs;
6878 dirs[ndirs].used = 0;
6879 files[i].dir_idx = ndirs;
6881 /* Search for a prefix. */
6882 dirs[ndirs].prefix = -1;
6883 for (j = 0; j < ndirs; j++)
6884 if (dirs[j].length < dirs[ndirs].length
6885 && dirs[j].length > 1
6886 && (dirs[ndirs].prefix == -1
6887 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6888 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6889 dirs[ndirs].prefix = j;
6891 ++ndirs;
6894 /* Now to the actual work. We have to find a subset of the directories which
6895 allow expressing the file name using references to the directory table
6896 with the least amount of characters. We do not do an exhaustive search
6897 where we would have to check out every combination of every single
6898 possible prefix. Instead we use a heuristic which provides nearly optimal
6899 results in most cases and never is much off. */
6900 saved = (int *) alloca (ndirs * sizeof (int));
6901 savehere = (int *) alloca (ndirs * sizeof (int));
6903 memset (saved, '\0', ndirs * sizeof (saved[0]));
6904 for (i = 0; i < ndirs; i++)
6906 int j;
6907 int total;
6909 /* We can always save some space for the current directory. But this
6910 does not mean it will be enough to justify adding the directory. */
6911 savehere[i] = dirs[i].length;
6912 total = (savehere[i] - saved[i]) * dirs[i].count;
6914 for (j = i + 1; j < ndirs; j++)
6916 savehere[j] = 0;
6917 if (saved[j] < dirs[i].length)
6919 /* Determine whether the dirs[i] path is a prefix of the
6920 dirs[j] path. */
6921 int k;
6923 k = dirs[j].prefix;
6924 while (k != -1 && k != i)
6925 k = dirs[k].prefix;
6927 if (k == i)
6929 /* Yes it is. We can possibly safe some memory but
6930 writing the filenames in dirs[j] relative to
6931 dirs[i]. */
6932 savehere[j] = dirs[i].length;
6933 total += (savehere[j] - saved[j]) * dirs[j].count;
6938 /* Check whether we can safe enough to justify adding the dirs[i]
6939 directory. */
6940 if (total > dirs[i].length + 1)
6942 /* It's worthwhile adding. */
6943 for (j = i; j < ndirs; j++)
6944 if (savehere[j] > 0)
6946 /* Remember how much we saved for this directory so far. */
6947 saved[j] = savehere[j];
6949 /* Remember the prefix directory. */
6950 dirs[j].dir_idx = i;
6955 /* We have to emit them in the order they appear in the file_table array
6956 since the index is used in the debug info generation. To do this
6957 efficiently we generate a back-mapping of the indices first. */
6958 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6959 for (i = 1; i < (int) file_table.in_use; i++)
6961 backmap[files[i].file_idx] = i;
6963 /* Mark this directory as used. */
6964 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6967 /* That was it. We are ready to emit the information. First emit the
6968 directory name table. We have to make sure the first actually emitted
6969 directory name has index one; zero is reserved for the current working
6970 directory. Make sure we do not confuse these indices with the one for the
6971 constructed table (even though most of the time they are identical). */
6972 idx = 1;
6973 idx_offset = dirs[0].length > 0 ? 1 : 0;
6974 for (i = 1 - idx_offset; i < ndirs; i++)
6975 if (dirs[i].used != 0)
6977 dirs[i].used = idx++;
6978 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6979 "Directory Entry: 0x%x", dirs[i].used);
6982 dw2_asm_output_data (1, 0, "End directory table");
6984 /* Correct the index for the current working directory entry if it
6985 exists. */
6986 if (idx_offset == 0)
6987 dirs[0].used = 0;
6989 /* Now write all the file names. */
6990 for (i = 1; i < (int) file_table.in_use; i++)
6992 int file_idx = backmap[i];
6993 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6995 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6996 "File Entry: 0x%x", i);
6998 /* Include directory index. */
6999 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
7001 /* Modification time. */
7002 dw2_asm_output_data_uleb128 (0, NULL);
7004 /* File length in bytes. */
7005 dw2_asm_output_data_uleb128 (0, NULL);
7008 dw2_asm_output_data (1, 0, "End file name table");
7012 /* Output the source line number correspondence information. This
7013 information goes into the .debug_line section. */
7015 static void
7016 output_line_info ()
7018 char l1[20], l2[20], p1[20], p2[20];
7019 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7020 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7021 unsigned opc;
7022 unsigned n_op_args;
7023 unsigned long lt_index;
7024 unsigned long current_line;
7025 long line_offset;
7026 long line_delta;
7027 unsigned long current_file;
7028 unsigned long function;
7030 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
7031 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
7032 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
7033 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
7035 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
7036 "Length of Source Line Info");
7037 ASM_OUTPUT_LABEL (asm_out_file, l1);
7039 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7040 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
7041 ASM_OUTPUT_LABEL (asm_out_file, p1);
7043 /* Define the architecture-dependent minimum instruction length (in
7044 bytes). In this implementation of DWARF, this field is used for
7045 information purposes only. Since GCC generates assembly language,
7046 we have no a priori knowledge of how many instruction bytes are
7047 generated for each source line, and therefore can use only the
7048 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7049 commands. Accordingly, we fix this as `1', which is "correct
7050 enough" for all architectures, and don't let the target override. */
7051 dw2_asm_output_data (1, 1,
7052 "Minimum Instruction Length");
7054 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
7055 "Default is_stmt_start flag");
7056 dw2_asm_output_data (1, DWARF_LINE_BASE,
7057 "Line Base Value (Special Opcodes)");
7058 dw2_asm_output_data (1, DWARF_LINE_RANGE,
7059 "Line Range Value (Special Opcodes)");
7060 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
7061 "Special Opcode Base");
7063 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
7065 switch (opc)
7067 case DW_LNS_advance_pc:
7068 case DW_LNS_advance_line:
7069 case DW_LNS_set_file:
7070 case DW_LNS_set_column:
7071 case DW_LNS_fixed_advance_pc:
7072 n_op_args = 1;
7073 break;
7074 default:
7075 n_op_args = 0;
7076 break;
7079 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
7080 opc, n_op_args);
7083 /* Write out the information about the files we use. */
7084 output_file_names ();
7085 ASM_OUTPUT_LABEL (asm_out_file, p2);
7087 /* We used to set the address register to the first location in the text
7088 section here, but that didn't accomplish anything since we already
7089 have a line note for the opening brace of the first function. */
7091 /* Generate the line number to PC correspondence table, encoded as
7092 a series of state machine operations. */
7093 current_file = 1;
7094 current_line = 1;
7095 strcpy (prev_line_label, text_section_label);
7096 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7098 dw_line_info_ref line_info = &line_info_table[lt_index];
7100 #if 0
7101 /* Disable this optimization for now; GDB wants to see two line notes
7102 at the beginning of a function so it can find the end of the
7103 prologue. */
7105 /* Don't emit anything for redundant notes. Just updating the
7106 address doesn't accomplish anything, because we already assume
7107 that anything after the last address is this line. */
7108 if (line_info->dw_line_num == current_line
7109 && line_info->dw_file_num == current_file)
7110 continue;
7111 #endif
7113 /* Emit debug info for the address of the current line.
7115 Unfortunately, we have little choice here currently, and must always
7116 use the most general form. GCC does not know the address delta
7117 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7118 attributes which will give an upper bound on the address range. We
7119 could perhaps use length attributes to determine when it is safe to
7120 use DW_LNS_fixed_advance_pc. */
7122 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7123 if (0)
7125 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7126 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7127 "DW_LNS_fixed_advance_pc");
7128 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7130 else
7132 /* This can handle any delta. This takes
7133 4+DWARF2_ADDR_SIZE bytes. */
7134 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7135 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7136 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7137 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7140 strcpy (prev_line_label, line_label);
7142 /* Emit debug info for the source file of the current line, if
7143 different from the previous line. */
7144 if (line_info->dw_file_num != current_file)
7146 current_file = line_info->dw_file_num;
7147 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7148 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7149 file_table.table[current_file]);
7152 /* Emit debug info for the current line number, choosing the encoding
7153 that uses the least amount of space. */
7154 if (line_info->dw_line_num != current_line)
7156 line_offset = line_info->dw_line_num - current_line;
7157 line_delta = line_offset - DWARF_LINE_BASE;
7158 current_line = line_info->dw_line_num;
7159 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7160 /* This can handle deltas from -10 to 234, using the current
7161 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7162 takes 1 byte. */
7163 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7164 "line %lu", current_line);
7165 else
7167 /* This can handle any delta. This takes at least 4 bytes,
7168 depending on the value being encoded. */
7169 dw2_asm_output_data (1, DW_LNS_advance_line,
7170 "advance to line %lu", current_line);
7171 dw2_asm_output_data_sleb128 (line_offset, NULL);
7172 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7175 else
7176 /* We still need to start a new row, so output a copy insn. */
7177 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7180 /* Emit debug info for the address of the end of the function. */
7181 if (0)
7183 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7184 "DW_LNS_fixed_advance_pc");
7185 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7187 else
7189 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7190 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7191 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7192 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7195 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7196 dw2_asm_output_data_uleb128 (1, NULL);
7197 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7199 function = 0;
7200 current_file = 1;
7201 current_line = 1;
7202 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7204 dw_separate_line_info_ref line_info
7205 = &separate_line_info_table[lt_index];
7207 #if 0
7208 /* Don't emit anything for redundant notes. */
7209 if (line_info->dw_line_num == current_line
7210 && line_info->dw_file_num == current_file
7211 && line_info->function == function)
7212 goto cont;
7213 #endif
7215 /* Emit debug info for the address of the current line. If this is
7216 a new function, or the first line of a function, then we need
7217 to handle it differently. */
7218 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7219 lt_index);
7220 if (function != line_info->function)
7222 function = line_info->function;
7224 /* Set the address register to the first line in the function */
7225 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7226 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7227 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7228 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7230 else
7232 /* ??? See the DW_LNS_advance_pc comment above. */
7233 if (0)
7235 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7236 "DW_LNS_fixed_advance_pc");
7237 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7239 else
7241 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7242 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7243 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7244 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7248 strcpy (prev_line_label, line_label);
7250 /* Emit debug info for the source file of the current line, if
7251 different from the previous line. */
7252 if (line_info->dw_file_num != current_file)
7254 current_file = line_info->dw_file_num;
7255 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7256 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7257 file_table.table[current_file]);
7260 /* Emit debug info for the current line number, choosing the encoding
7261 that uses the least amount of space. */
7262 if (line_info->dw_line_num != current_line)
7264 line_offset = line_info->dw_line_num - current_line;
7265 line_delta = line_offset - DWARF_LINE_BASE;
7266 current_line = line_info->dw_line_num;
7267 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7268 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7269 "line %lu", current_line);
7270 else
7272 dw2_asm_output_data (1, DW_LNS_advance_line,
7273 "advance to line %lu", current_line);
7274 dw2_asm_output_data_sleb128 (line_offset, NULL);
7275 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7278 else
7279 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7281 #if 0
7282 cont:
7283 #endif
7285 lt_index++;
7287 /* If we're done with a function, end its sequence. */
7288 if (lt_index == separate_line_info_table_in_use
7289 || separate_line_info_table[lt_index].function != function)
7291 current_file = 1;
7292 current_line = 1;
7294 /* Emit debug info for the address of the end of the function. */
7295 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7296 if (0)
7298 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7299 "DW_LNS_fixed_advance_pc");
7300 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7302 else
7304 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7305 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7306 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7307 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7310 /* Output the marker for the end of this sequence. */
7311 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7312 dw2_asm_output_data_uleb128 (1, NULL);
7313 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7317 /* Output the marker for the end of the line number info. */
7318 ASM_OUTPUT_LABEL (asm_out_file, l2);
7321 /* Given a pointer to a tree node for some base type, return a pointer to
7322 a DIE that describes the given type.
7324 This routine must only be called for GCC type nodes that correspond to
7325 Dwarf base (fundamental) types. */
7327 static dw_die_ref
7328 base_type_die (type)
7329 tree type;
7331 dw_die_ref base_type_result;
7332 const char *type_name;
7333 enum dwarf_type encoding;
7334 tree name = TYPE_NAME (type);
7336 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
7337 return 0;
7339 if (name)
7341 if (TREE_CODE (name) == TYPE_DECL)
7342 name = DECL_NAME (name);
7344 type_name = IDENTIFIER_POINTER (name);
7346 else
7347 type_name = "__unknown__";
7349 switch (TREE_CODE (type))
7351 case INTEGER_TYPE:
7352 /* Carefully distinguish the C character types, without messing
7353 up if the language is not C. Note that we check only for the names
7354 that contain spaces; other names might occur by coincidence in other
7355 languages. */
7356 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7357 && (type == char_type_node
7358 || ! strcmp (type_name, "signed char")
7359 || ! strcmp (type_name, "unsigned char"))))
7361 if (TREE_UNSIGNED (type))
7362 encoding = DW_ATE_unsigned;
7363 else
7364 encoding = DW_ATE_signed;
7365 break;
7367 /* else fall through. */
7369 case CHAR_TYPE:
7370 /* GNU Pascal/Ada CHAR type. Not used in C. */
7371 if (TREE_UNSIGNED (type))
7372 encoding = DW_ATE_unsigned_char;
7373 else
7374 encoding = DW_ATE_signed_char;
7375 break;
7377 case REAL_TYPE:
7378 encoding = DW_ATE_float;
7379 break;
7381 /* Dwarf2 doesn't know anything about complex ints, so use
7382 a user defined type for it. */
7383 case COMPLEX_TYPE:
7384 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7385 encoding = DW_ATE_complex_float;
7386 else
7387 encoding = DW_ATE_lo_user;
7388 break;
7390 case BOOLEAN_TYPE:
7391 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7392 encoding = DW_ATE_boolean;
7393 break;
7395 default:
7396 /* No other TREE_CODEs are Dwarf fundamental types. */
7397 abort ();
7400 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
7401 if (demangle_name_func)
7402 type_name = (*demangle_name_func) (type_name);
7404 add_AT_string (base_type_result, DW_AT_name, type_name);
7405 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7406 int_size_in_bytes (type));
7407 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7409 return base_type_result;
7412 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7413 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7414 a given type is generally the same as the given type, except that if the
7415 given type is a pointer or reference type, then the root type of the given
7416 type is the root type of the "basis" type for the pointer or reference
7417 type. (This definition of the "root" type is recursive.) Also, the root
7418 type of a `const' qualified type or a `volatile' qualified type is the
7419 root type of the given type without the qualifiers. */
7421 static tree
7422 root_type (type)
7423 tree type;
7425 if (TREE_CODE (type) == ERROR_MARK)
7426 return error_mark_node;
7428 switch (TREE_CODE (type))
7430 case ERROR_MARK:
7431 return error_mark_node;
7433 case POINTER_TYPE:
7434 case REFERENCE_TYPE:
7435 return type_main_variant (root_type (TREE_TYPE (type)));
7437 default:
7438 return type_main_variant (type);
7442 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7443 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7445 static inline int
7446 is_base_type (type)
7447 tree type;
7449 switch (TREE_CODE (type))
7451 case ERROR_MARK:
7452 case VOID_TYPE:
7453 case INTEGER_TYPE:
7454 case REAL_TYPE:
7455 case COMPLEX_TYPE:
7456 case BOOLEAN_TYPE:
7457 case CHAR_TYPE:
7458 return 1;
7460 case SET_TYPE:
7461 case ARRAY_TYPE:
7462 case RECORD_TYPE:
7463 case UNION_TYPE:
7464 case QUAL_UNION_TYPE:
7465 case ENUMERAL_TYPE:
7466 case FUNCTION_TYPE:
7467 case METHOD_TYPE:
7468 case POINTER_TYPE:
7469 case REFERENCE_TYPE:
7470 case FILE_TYPE:
7471 case OFFSET_TYPE:
7472 case LANG_TYPE:
7473 case VECTOR_TYPE:
7474 return 0;
7476 default:
7477 abort ();
7480 return 0;
7483 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7484 entry that chains various modifiers in front of the given type. */
7486 static dw_die_ref
7487 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7488 tree type;
7489 int is_const_type;
7490 int is_volatile_type;
7491 dw_die_ref context_die;
7493 enum tree_code code = TREE_CODE (type);
7494 dw_die_ref mod_type_die = NULL;
7495 dw_die_ref sub_die = NULL;
7496 tree item_type = NULL;
7498 if (code != ERROR_MARK)
7500 tree qualified_type;
7502 /* See if we already have the appropriately qualified variant of
7503 this type. */
7504 qualified_type
7505 = get_qualified_type (type,
7506 ((is_const_type ? TYPE_QUAL_CONST : 0)
7507 | (is_volatile_type
7508 ? TYPE_QUAL_VOLATILE : 0)));
7510 /* If we do, then we can just use its DIE, if it exists. */
7511 if (qualified_type)
7513 mod_type_die = lookup_type_die (qualified_type);
7514 if (mod_type_die)
7515 return mod_type_die;
7518 /* Handle C typedef types. */
7519 if (qualified_type && TYPE_NAME (qualified_type)
7520 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7521 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7523 tree type_name = TYPE_NAME (qualified_type);
7524 tree dtype = TREE_TYPE (type_name);
7526 if (qualified_type == dtype)
7528 /* For a named type, use the typedef. */
7529 gen_type_die (qualified_type, context_die);
7530 mod_type_die = lookup_type_die (qualified_type);
7532 else if (is_const_type < TYPE_READONLY (dtype)
7533 || is_volatile_type < TYPE_VOLATILE (dtype))
7534 /* cv-unqualified version of named type. Just use the unnamed
7535 type to which it refers. */
7536 mod_type_die
7537 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7538 is_const_type, is_volatile_type,
7539 context_die);
7541 /* Else cv-qualified version of named type; fall through. */
7544 if (mod_type_die)
7545 /* OK. */
7547 else if (is_const_type)
7549 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
7550 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7552 else if (is_volatile_type)
7554 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
7555 sub_die = modified_type_die (type, 0, 0, context_die);
7557 else if (code == POINTER_TYPE)
7559 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
7560 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7561 #if 0
7562 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7563 #endif
7564 item_type = TREE_TYPE (type);
7566 else if (code == REFERENCE_TYPE)
7568 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
7569 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7570 #if 0
7571 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7572 #endif
7573 item_type = TREE_TYPE (type);
7575 else if (is_base_type (type))
7576 mod_type_die = base_type_die (type);
7577 else
7579 gen_type_die (type, context_die);
7581 /* We have to get the type_main_variant here (and pass that to the
7582 `lookup_type_die' routine) because the ..._TYPE node we have
7583 might simply be a *copy* of some original type node (where the
7584 copy was created to help us keep track of typedef names) and
7585 that copy might have a different TYPE_UID from the original
7586 ..._TYPE node. */
7587 if (TREE_CODE (type) != VECTOR_TYPE)
7588 mod_type_die = lookup_type_die (type_main_variant (type));
7589 else
7590 /* Vectors have the debugging information in the type,
7591 not the main variant. */
7592 mod_type_die = lookup_type_die (type);
7593 if (mod_type_die == NULL)
7594 abort ();
7597 /* We want to equate the qualified type to the die below. */
7598 type = qualified_type;
7601 if (type)
7602 equate_type_number_to_die (type, mod_type_die);
7603 if (item_type)
7604 /* We must do this after the equate_type_number_to_die call, in case
7605 this is a recursive type. This ensures that the modified_type_die
7606 recursion will terminate even if the type is recursive. Recursive
7607 types are possible in Ada. */
7608 sub_die = modified_type_die (item_type,
7609 TYPE_READONLY (item_type),
7610 TYPE_VOLATILE (item_type),
7611 context_die);
7613 if (sub_die != NULL)
7614 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7616 return mod_type_die;
7619 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7620 an enumerated type. */
7622 static inline int
7623 type_is_enum (type)
7624 tree type;
7626 return TREE_CODE (type) == ENUMERAL_TYPE;
7629 /* Return the register number described by a given RTL node. */
7631 static unsigned int
7632 reg_number (rtl)
7633 rtx rtl;
7635 unsigned regno = REGNO (rtl);
7637 if (regno >= FIRST_PSEUDO_REGISTER)
7638 abort ();
7640 return DBX_REGISTER_NUMBER (regno);
7643 /* Return a location descriptor that designates a machine register or
7644 zero if there is no such. */
7646 static dw_loc_descr_ref
7647 reg_loc_descriptor (rtl)
7648 rtx rtl;
7650 dw_loc_descr_ref loc_result = NULL;
7651 unsigned reg;
7653 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
7654 return 0;
7656 reg = reg_number (rtl);
7657 if (reg <= 31)
7658 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7659 else
7660 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7662 return loc_result;
7665 /* Return a location descriptor that designates a constant. */
7667 static dw_loc_descr_ref
7668 int_loc_descriptor (i)
7669 HOST_WIDE_INT i;
7671 enum dwarf_location_atom op;
7673 /* Pick the smallest representation of a constant, rather than just
7674 defaulting to the LEB encoding. */
7675 if (i >= 0)
7677 if (i <= 31)
7678 op = DW_OP_lit0 + i;
7679 else if (i <= 0xff)
7680 op = DW_OP_const1u;
7681 else if (i <= 0xffff)
7682 op = DW_OP_const2u;
7683 else if (HOST_BITS_PER_WIDE_INT == 32
7684 || i <= 0xffffffff)
7685 op = DW_OP_const4u;
7686 else
7687 op = DW_OP_constu;
7689 else
7691 if (i >= -0x80)
7692 op = DW_OP_const1s;
7693 else if (i >= -0x8000)
7694 op = DW_OP_const2s;
7695 else if (HOST_BITS_PER_WIDE_INT == 32
7696 || i >= -0x80000000)
7697 op = DW_OP_const4s;
7698 else
7699 op = DW_OP_consts;
7702 return new_loc_descr (op, i, 0);
7705 /* Return a location descriptor that designates a base+offset location. */
7707 static dw_loc_descr_ref
7708 based_loc_descr (reg, offset)
7709 unsigned reg;
7710 long int offset;
7712 dw_loc_descr_ref loc_result;
7713 /* For the "frame base", we use the frame pointer or stack pointer
7714 registers, since the RTL for local variables is relative to one of
7715 them. */
7716 unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7717 ? HARD_FRAME_POINTER_REGNUM
7718 : STACK_POINTER_REGNUM);
7720 if (reg == fp_reg)
7721 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7722 else if (reg <= 31)
7723 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7724 else
7725 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7727 return loc_result;
7730 /* Return true if this RTL expression describes a base+offset calculation. */
7732 static inline int
7733 is_based_loc (rtl)
7734 rtx rtl;
7736 return (GET_CODE (rtl) == PLUS
7737 && ((GET_CODE (XEXP (rtl, 0)) == REG
7738 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
7739 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7742 /* The following routine converts the RTL for a variable or parameter
7743 (resident in memory) into an equivalent Dwarf representation of a
7744 mechanism for getting the address of that same variable onto the top of a
7745 hypothetical "address evaluation" stack.
7747 When creating memory location descriptors, we are effectively transforming
7748 the RTL for a memory-resident object into its Dwarf postfix expression
7749 equivalent. This routine recursively descends an RTL tree, turning
7750 it into Dwarf postfix code as it goes.
7752 MODE is the mode of the memory reference, needed to handle some
7753 autoincrement addressing modes.
7755 Return 0 if we can't represent the location. */
7757 static dw_loc_descr_ref
7758 mem_loc_descriptor (rtl, mode)
7759 rtx rtl;
7760 enum machine_mode mode;
7762 dw_loc_descr_ref mem_loc_result = NULL;
7764 /* Note that for a dynamically sized array, the location we will generate a
7765 description of here will be the lowest numbered location which is
7766 actually within the array. That's *not* necessarily the same as the
7767 zeroth element of the array. */
7769 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7770 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7771 #endif
7773 switch (GET_CODE (rtl))
7775 case POST_INC:
7776 case POST_DEC:
7777 case POST_MODIFY:
7778 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7779 just fall into the SUBREG code. */
7781 /* ... fall through ... */
7783 case SUBREG:
7784 /* The case of a subreg may arise when we have a local (register)
7785 variable or a formal (register) parameter which doesn't quite fill
7786 up an entire register. For now, just assume that it is
7787 legitimate to make the Dwarf info refer to the whole register which
7788 contains the given subreg. */
7789 rtl = SUBREG_REG (rtl);
7791 /* ... fall through ... */
7793 case REG:
7794 /* Whenever a register number forms a part of the description of the
7795 method for calculating the (dynamic) address of a memory resident
7796 object, DWARF rules require the register number be referred to as
7797 a "base register". This distinction is not based in any way upon
7798 what category of register the hardware believes the given register
7799 belongs to. This is strictly DWARF terminology we're dealing with
7800 here. Note that in cases where the location of a memory-resident
7801 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7802 OP_CONST (0)) the actual DWARF location descriptor that we generate
7803 may just be OP_BASEREG (basereg). This may look deceptively like
7804 the object in question was allocated to a register (rather than in
7805 memory) so DWARF consumers need to be aware of the subtle
7806 distinction between OP_REG and OP_BASEREG. */
7807 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
7808 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7809 break;
7811 case MEM:
7812 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7813 if (mem_loc_result != 0)
7814 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7815 break;
7817 case LABEL_REF:
7818 /* Some ports can transform a symbol ref into a label ref, because
7819 the symbol ref is too far away and has to be dumped into a constant
7820 pool. */
7821 case CONST:
7822 case SYMBOL_REF:
7823 /* Alternatively, the symbol in the constant pool might be referenced
7824 by a different symbol. */
7825 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
7827 bool marked;
7828 rtx tmp = get_pool_constant_mark (rtl, &marked);
7830 if (GET_CODE (tmp) == SYMBOL_REF)
7832 rtl = tmp;
7833 if (CONSTANT_POOL_ADDRESS_P (tmp))
7834 get_pool_constant_mark (tmp, &marked);
7835 else
7836 marked = true;
7839 /* If all references to this pool constant were optimized away,
7840 it was not output and thus we can't represent it.
7841 FIXME: might try to use DW_OP_const_value here, though
7842 DW_OP_piece complicates it. */
7843 if (!marked)
7844 return 0;
7847 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7848 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7849 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
7850 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
7851 break;
7853 case PRE_MODIFY:
7854 /* Extract the PLUS expression nested inside and fall into
7855 PLUS code below. */
7856 rtl = XEXP (rtl, 1);
7857 goto plus;
7859 case PRE_INC:
7860 case PRE_DEC:
7861 /* Turn these into a PLUS expression and fall into the PLUS code
7862 below. */
7863 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7864 GEN_INT (GET_CODE (rtl) == PRE_INC
7865 ? GET_MODE_UNIT_SIZE (mode)
7866 : -GET_MODE_UNIT_SIZE (mode)));
7868 /* ... fall through ... */
7870 case PLUS:
7871 plus:
7872 if (is_based_loc (rtl))
7873 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7874 INTVAL (XEXP (rtl, 1)));
7875 else
7877 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7878 if (mem_loc_result == 0)
7879 break;
7881 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7882 && INTVAL (XEXP (rtl, 1)) >= 0)
7883 add_loc_descr (&mem_loc_result,
7884 new_loc_descr (DW_OP_plus_uconst,
7885 INTVAL (XEXP (rtl, 1)), 0));
7886 else
7888 add_loc_descr (&mem_loc_result,
7889 mem_loc_descriptor (XEXP (rtl, 1), mode));
7890 add_loc_descr (&mem_loc_result,
7891 new_loc_descr (DW_OP_plus, 0, 0));
7894 break;
7896 case MULT:
7898 /* If a pseudo-reg is optimized away, it is possible for it to
7899 be replaced with a MEM containing a multiply. */
7900 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
7901 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
7903 if (op0 == 0 || op1 == 0)
7904 break;
7906 mem_loc_result = op0;
7907 add_loc_descr (&mem_loc_result, op1);
7908 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7909 break;
7912 case CONST_INT:
7913 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7914 break;
7916 case ADDRESSOF:
7917 /* If this is a MEM, return its address. Otherwise, we can't
7918 represent this. */
7919 if (GET_CODE (XEXP (rtl, 0)) == MEM)
7920 return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode);
7921 else
7922 return 0;
7924 default:
7925 abort ();
7928 return mem_loc_result;
7931 /* Return a descriptor that describes the concatenation of two locations.
7932 This is typically a complex variable. */
7934 static dw_loc_descr_ref
7935 concat_loc_descriptor (x0, x1)
7936 rtx x0, x1;
7938 dw_loc_descr_ref cc_loc_result = NULL;
7939 dw_loc_descr_ref x0_ref = loc_descriptor (x0);
7940 dw_loc_descr_ref x1_ref = loc_descriptor (x1);
7942 if (x0_ref == 0 || x1_ref == 0)
7943 return 0;
7945 cc_loc_result = x0_ref;
7946 add_loc_descr (&cc_loc_result,
7947 new_loc_descr (DW_OP_piece,
7948 GET_MODE_SIZE (GET_MODE (x0)), 0));
7950 add_loc_descr (&cc_loc_result, x1_ref);
7951 add_loc_descr (&cc_loc_result,
7952 new_loc_descr (DW_OP_piece,
7953 GET_MODE_SIZE (GET_MODE (x1)), 0));
7955 return cc_loc_result;
7958 /* Output a proper Dwarf location descriptor for a variable or parameter
7959 which is either allocated in a register or in a memory location. For a
7960 register, we just generate an OP_REG and the register number. For a
7961 memory location we provide a Dwarf postfix expression describing how to
7962 generate the (dynamic) address of the object onto the address stack.
7964 If we don't know how to describe it, return 0. */
7966 static dw_loc_descr_ref
7967 loc_descriptor (rtl)
7968 rtx rtl;
7970 dw_loc_descr_ref loc_result = NULL;
7972 switch (GET_CODE (rtl))
7974 case SUBREG:
7975 /* The case of a subreg may arise when we have a local (register)
7976 variable or a formal (register) parameter which doesn't quite fill
7977 up an entire register. For now, just assume that it is
7978 legitimate to make the Dwarf info refer to the whole register which
7979 contains the given subreg. */
7980 rtl = SUBREG_REG (rtl);
7982 /* ... fall through ... */
7984 case REG:
7985 loc_result = reg_loc_descriptor (rtl);
7986 break;
7988 case MEM:
7989 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7990 break;
7992 case CONCAT:
7993 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7994 break;
7996 default:
7997 abort ();
8000 return loc_result;
8003 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8004 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
8005 looking for an address. Otherwise, we return a value. If we can't make a
8006 descriptor, return 0. */
8008 static dw_loc_descr_ref
8009 loc_descriptor_from_tree (loc, addressp)
8010 tree loc;
8011 int addressp;
8013 dw_loc_descr_ref ret, ret1;
8014 int indirect_p = 0;
8015 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
8016 enum dwarf_location_atom op;
8018 /* ??? Most of the time we do not take proper care for sign/zero
8019 extending the values properly. Hopefully this won't be a real
8020 problem... */
8022 switch (TREE_CODE (loc))
8024 case ERROR_MARK:
8025 return 0;
8027 case WITH_RECORD_EXPR:
8028 case PLACEHOLDER_EXPR:
8029 /* This case involves extracting fields from an object to determine the
8030 position of other fields. We don't try to encode this here. The
8031 only user of this is Ada, which encodes the needed information using
8032 the names of types. */
8033 return 0;
8035 case CALL_EXPR:
8036 return 0;
8038 case ADDR_EXPR:
8039 /* We can support this only if we can look through conversions and
8040 find an INDIRECT_EXPR. */
8041 for (loc = TREE_OPERAND (loc, 0);
8042 TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR
8043 || TREE_CODE (loc) == NON_LVALUE_EXPR
8044 || TREE_CODE (loc) == VIEW_CONVERT_EXPR
8045 || TREE_CODE (loc) == SAVE_EXPR;
8046 loc = TREE_OPERAND (loc, 0))
8049 return (TREE_CODE (loc) == INDIRECT_REF
8050 ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp)
8051 : 0);
8053 case VAR_DECL:
8054 if (DECL_THREAD_LOCAL (loc))
8056 rtx rtl;
8058 #ifndef ASM_OUTPUT_DWARF_DTPREL
8059 /* If this is not defined, we have no way to emit the data. */
8060 return 0;
8061 #endif
8063 /* The way DW_OP_GNU_push_tls_address is specified, we can only
8064 look up addresses of objects in the current module. */
8065 if (! (*targetm.binds_local_p) (loc))
8066 return 0;
8068 rtl = rtl_for_decl_location (loc);
8069 if (rtl == NULL_RTX)
8070 return 0;
8072 if (GET_CODE (rtl) != MEM)
8073 return 0;
8074 rtl = XEXP (rtl, 0);
8075 if (! CONSTANT_P (rtl))
8076 return 0;
8078 ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0);
8079 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8080 ret->dw_loc_oprnd1.v.val_addr = rtl;
8082 ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
8083 add_loc_descr (&ret, ret1);
8085 indirect_p = 1;
8086 break;
8088 /* FALLTHRU */
8090 case PARM_DECL:
8092 rtx rtl = rtl_for_decl_location (loc);
8094 if (rtl == NULL_RTX)
8095 return 0;
8096 else if (CONSTANT_P (rtl))
8098 ret = new_loc_descr (DW_OP_addr, 0, 0);
8099 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8100 ret->dw_loc_oprnd1.v.val_addr = rtl;
8101 indirect_p = 1;
8103 else
8105 enum machine_mode mode = GET_MODE (rtl);
8107 if (GET_CODE (rtl) == MEM)
8109 indirect_p = 1;
8110 rtl = XEXP (rtl, 0);
8113 ret = mem_loc_descriptor (rtl, mode);
8116 break;
8118 case INDIRECT_REF:
8119 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8120 indirect_p = 1;
8121 break;
8123 case COMPOUND_EXPR:
8124 return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp);
8126 case NOP_EXPR:
8127 case CONVERT_EXPR:
8128 case NON_LVALUE_EXPR:
8129 case VIEW_CONVERT_EXPR:
8130 case SAVE_EXPR:
8131 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
8133 case COMPONENT_REF:
8134 case BIT_FIELD_REF:
8135 case ARRAY_REF:
8136 case ARRAY_RANGE_REF:
8138 tree obj, offset;
8139 HOST_WIDE_INT bitsize, bitpos, bytepos;
8140 enum machine_mode mode;
8141 int volatilep;
8143 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
8144 &unsignedp, &volatilep);
8146 if (obj == loc)
8147 return 0;
8149 ret = loc_descriptor_from_tree (obj, 1);
8150 if (ret == 0
8151 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
8152 return 0;
8154 if (offset != NULL_TREE)
8156 /* Variable offset. */
8157 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
8158 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8161 if (!addressp)
8162 indirect_p = 1;
8164 bytepos = bitpos / BITS_PER_UNIT;
8165 if (bytepos > 0)
8166 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8167 else if (bytepos < 0)
8169 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8170 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8172 break;
8175 case INTEGER_CST:
8176 if (host_integerp (loc, 0))
8177 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8178 else
8179 return 0;
8180 break;
8182 case TRUTH_AND_EXPR:
8183 case TRUTH_ANDIF_EXPR:
8184 case BIT_AND_EXPR:
8185 op = DW_OP_and;
8186 goto do_binop;
8188 case TRUTH_XOR_EXPR:
8189 case BIT_XOR_EXPR:
8190 op = DW_OP_xor;
8191 goto do_binop;
8193 case TRUTH_OR_EXPR:
8194 case TRUTH_ORIF_EXPR:
8195 case BIT_IOR_EXPR:
8196 op = DW_OP_or;
8197 goto do_binop;
8199 case TRUNC_DIV_EXPR:
8200 op = DW_OP_div;
8201 goto do_binop;
8203 case MINUS_EXPR:
8204 op = DW_OP_minus;
8205 goto do_binop;
8207 case TRUNC_MOD_EXPR:
8208 op = DW_OP_mod;
8209 goto do_binop;
8211 case MULT_EXPR:
8212 op = DW_OP_mul;
8213 goto do_binop;
8215 case LSHIFT_EXPR:
8216 op = DW_OP_shl;
8217 goto do_binop;
8219 case RSHIFT_EXPR:
8220 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8221 goto do_binop;
8223 case PLUS_EXPR:
8224 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8225 && host_integerp (TREE_OPERAND (loc, 1), 0))
8227 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8228 if (ret == 0)
8229 return 0;
8231 add_loc_descr (&ret,
8232 new_loc_descr (DW_OP_plus_uconst,
8233 tree_low_cst (TREE_OPERAND (loc, 1),
8235 0));
8236 break;
8239 op = DW_OP_plus;
8240 goto do_binop;
8242 case LE_EXPR:
8243 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8244 return 0;
8246 op = DW_OP_le;
8247 goto do_binop;
8249 case GE_EXPR:
8250 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8251 return 0;
8253 op = DW_OP_ge;
8254 goto do_binop;
8256 case LT_EXPR:
8257 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8258 return 0;
8260 op = DW_OP_lt;
8261 goto do_binop;
8263 case GT_EXPR:
8264 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8265 return 0;
8267 op = DW_OP_gt;
8268 goto do_binop;
8270 case EQ_EXPR:
8271 op = DW_OP_eq;
8272 goto do_binop;
8274 case NE_EXPR:
8275 op = DW_OP_ne;
8276 goto do_binop;
8278 do_binop:
8279 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8280 ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8281 if (ret == 0 || ret1 == 0)
8282 return 0;
8284 add_loc_descr (&ret, ret1);
8285 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8286 break;
8288 case TRUTH_NOT_EXPR:
8289 case BIT_NOT_EXPR:
8290 op = DW_OP_not;
8291 goto do_unop;
8293 case ABS_EXPR:
8294 op = DW_OP_abs;
8295 goto do_unop;
8297 case NEGATE_EXPR:
8298 op = DW_OP_neg;
8299 goto do_unop;
8301 do_unop:
8302 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8303 if (ret == 0)
8304 return 0;
8306 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8307 break;
8309 case MAX_EXPR:
8310 loc = build (COND_EXPR, TREE_TYPE (loc),
8311 build (LT_EXPR, integer_type_node,
8312 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8313 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8315 /* ... fall through ... */
8317 case COND_EXPR:
8319 dw_loc_descr_ref lhs
8320 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8321 dw_loc_descr_ref rhs
8322 = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8323 dw_loc_descr_ref bra_node, jump_node, tmp;
8325 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8326 if (ret == 0 || lhs == 0 || rhs == 0)
8327 return 0;
8329 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8330 add_loc_descr (&ret, bra_node);
8332 add_loc_descr (&ret, rhs);
8333 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8334 add_loc_descr (&ret, jump_node);
8336 add_loc_descr (&ret, lhs);
8337 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8338 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
8340 /* ??? Need a node to point the skip at. Use a nop. */
8341 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8342 add_loc_descr (&ret, tmp);
8343 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8344 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8346 break;
8348 default:
8349 abort ();
8352 /* Show if we can't fill the request for an address. */
8353 if (addressp && indirect_p == 0)
8354 return 0;
8356 /* If we've got an address and don't want one, dereference. */
8357 if (!addressp && indirect_p > 0)
8359 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
8361 if (size > DWARF2_ADDR_SIZE || size == -1)
8362 return 0;
8363 else if (size == DWARF2_ADDR_SIZE)
8364 op = DW_OP_deref;
8365 else
8366 op = DW_OP_deref_size;
8368 add_loc_descr (&ret, new_loc_descr (op, size, 0));
8371 return ret;
8374 /* Given a value, round it up to the lowest multiple of `boundary'
8375 which is not less than the value itself. */
8377 static inline HOST_WIDE_INT
8378 ceiling (value, boundary)
8379 HOST_WIDE_INT value;
8380 unsigned int boundary;
8382 return (((value + boundary - 1) / boundary) * boundary);
8385 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8386 pointer to the declared type for the relevant field variable, or return
8387 `integer_type_node' if the given node turns out to be an
8388 ERROR_MARK node. */
8390 static inline tree
8391 field_type (decl)
8392 tree decl;
8394 tree type;
8396 if (TREE_CODE (decl) == ERROR_MARK)
8397 return integer_type_node;
8399 type = DECL_BIT_FIELD_TYPE (decl);
8400 if (type == NULL_TREE)
8401 type = TREE_TYPE (decl);
8403 return type;
8406 /* Given a pointer to a tree node, return the alignment in bits for
8407 it, or else return BITS_PER_WORD if the node actually turns out to
8408 be an ERROR_MARK node. */
8410 static inline unsigned
8411 simple_type_align_in_bits (type)
8412 tree type;
8414 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8417 static inline unsigned
8418 simple_decl_align_in_bits (decl)
8419 tree decl;
8421 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
8424 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8425 node, return the size in bits for the type if it is a constant, or else
8426 return the alignment for the type if the type's size is not constant, or
8427 else return BITS_PER_WORD if the type actually turns out to be an
8428 ERROR_MARK node. */
8430 static inline unsigned HOST_WIDE_INT
8431 simple_type_size_in_bits (type)
8432 tree type;
8435 if (TREE_CODE (type) == ERROR_MARK)
8436 return BITS_PER_WORD;
8437 else if (TYPE_SIZE (type) == NULL_TREE)
8438 return 0;
8439 else if (host_integerp (TYPE_SIZE (type), 1))
8440 return tree_low_cst (TYPE_SIZE (type), 1);
8441 else
8442 return TYPE_ALIGN (type);
8445 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8446 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8447 or return 0 if we are unable to determine what that offset is, either
8448 because the argument turns out to be a pointer to an ERROR_MARK node, or
8449 because the offset is actually variable. (We can't handle the latter case
8450 just yet). */
8452 static HOST_WIDE_INT
8453 field_byte_offset (decl)
8454 tree decl;
8456 unsigned int type_align_in_bits;
8457 unsigned int decl_align_in_bits;
8458 unsigned HOST_WIDE_INT type_size_in_bits;
8459 HOST_WIDE_INT object_offset_in_bits;
8460 tree type;
8461 tree field_size_tree;
8462 HOST_WIDE_INT bitpos_int;
8463 HOST_WIDE_INT deepest_bitpos;
8464 unsigned HOST_WIDE_INT field_size_in_bits;
8466 if (TREE_CODE (decl) == ERROR_MARK)
8467 return 0;
8468 else if (TREE_CODE (decl) != FIELD_DECL)
8469 abort ();
8471 type = field_type (decl);
8472 field_size_tree = DECL_SIZE (decl);
8474 /* The size could be unspecified if there was an error, or for
8475 a flexible array member. */
8476 if (! field_size_tree)
8477 field_size_tree = bitsize_zero_node;
8479 /* We cannot yet cope with fields whose positions are variable, so
8480 for now, when we see such things, we simply return 0. Someday, we may
8481 be able to handle such cases, but it will be damn difficult. */
8482 if (! host_integerp (bit_position (decl), 0))
8483 return 0;
8485 bitpos_int = int_bit_position (decl);
8487 /* If we don't know the size of the field, pretend it's a full word. */
8488 if (host_integerp (field_size_tree, 1))
8489 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8490 else
8491 field_size_in_bits = BITS_PER_WORD;
8493 type_size_in_bits = simple_type_size_in_bits (type);
8494 type_align_in_bits = simple_type_align_in_bits (type);
8495 decl_align_in_bits = simple_decl_align_in_bits (decl);
8497 /* The GCC front-end doesn't make any attempt to keep track of the starting
8498 bit offset (relative to the start of the containing structure type) of the
8499 hypothetical "containing object" for a bit-field. Thus, when computing
8500 the byte offset value for the start of the "containing object" of a
8501 bit-field, we must deduce this information on our own. This can be rather
8502 tricky to do in some cases. For example, handling the following structure
8503 type definition when compiling for an i386/i486 target (which only aligns
8504 long long's to 32-bit boundaries) can be very tricky:
8506 struct S { int field1; long long field2:31; };
8508 Fortunately, there is a simple rule-of-thumb which can be used in such
8509 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8510 structure shown above. It decides to do this based upon one simple rule
8511 for bit-field allocation. GCC allocates each "containing object" for each
8512 bit-field at the first (i.e. lowest addressed) legitimate alignment
8513 boundary (based upon the required minimum alignment for the declared type
8514 of the field) which it can possibly use, subject to the condition that
8515 there is still enough available space remaining in the containing object
8516 (when allocated at the selected point) to fully accommodate all of the
8517 bits of the bit-field itself.
8519 This simple rule makes it obvious why GCC allocates 8 bytes for each
8520 object of the structure type shown above. When looking for a place to
8521 allocate the "containing object" for `field2', the compiler simply tries
8522 to allocate a 64-bit "containing object" at each successive 32-bit
8523 boundary (starting at zero) until it finds a place to allocate that 64-
8524 bit field such that at least 31 contiguous (and previously unallocated)
8525 bits remain within that selected 64 bit field. (As it turns out, for the
8526 example above, the compiler finds it is OK to allocate the "containing
8527 object" 64-bit field at bit-offset zero within the structure type.)
8529 Here we attempt to work backwards from the limited set of facts we're
8530 given, and we try to deduce from those facts, where GCC must have believed
8531 that the containing object started (within the structure type). The value
8532 we deduce is then used (by the callers of this routine) to generate
8533 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8534 and, in the case of DW_AT_location, regular fields as well). */
8536 /* Figure out the bit-distance from the start of the structure to the
8537 "deepest" bit of the bit-field. */
8538 deepest_bitpos = bitpos_int + field_size_in_bits;
8540 /* This is the tricky part. Use some fancy footwork to deduce where the
8541 lowest addressed bit of the containing object must be. */
8542 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8544 /* Round up to type_align by default. This works best for bitfields. */
8545 object_offset_in_bits += type_align_in_bits - 1;
8546 object_offset_in_bits /= type_align_in_bits;
8547 object_offset_in_bits *= type_align_in_bits;
8549 if (object_offset_in_bits > bitpos_int)
8551 /* Sigh, the decl must be packed. */
8552 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8554 /* Round up to decl_align instead. */
8555 object_offset_in_bits += decl_align_in_bits - 1;
8556 object_offset_in_bits /= decl_align_in_bits;
8557 object_offset_in_bits *= decl_align_in_bits;
8560 return object_offset_in_bits / BITS_PER_UNIT;
8563 /* The following routines define various Dwarf attributes and any data
8564 associated with them. */
8566 /* Add a location description attribute value to a DIE.
8568 This emits location attributes suitable for whole variables and
8569 whole parameters. Note that the location attributes for struct fields are
8570 generated by the routine `data_member_location_attribute' below. */
8572 static inline void
8573 add_AT_location_description (die, attr_kind, descr)
8574 dw_die_ref die;
8575 enum dwarf_attribute attr_kind;
8576 dw_loc_descr_ref descr;
8578 if (descr != 0)
8579 add_AT_loc (die, attr_kind, descr);
8582 /* Attach the specialized form of location attribute used for data members of
8583 struct and union types. In the special case of a FIELD_DECL node which
8584 represents a bit-field, the "offset" part of this special location
8585 descriptor must indicate the distance in bytes from the lowest-addressed
8586 byte of the containing struct or union type to the lowest-addressed byte of
8587 the "containing object" for the bit-field. (See the `field_byte_offset'
8588 function above).
8590 For any given bit-field, the "containing object" is a hypothetical object
8591 (of some integral or enum type) within which the given bit-field lives. The
8592 type of this hypothetical "containing object" is always the same as the
8593 declared type of the individual bit-field itself (for GCC anyway... the
8594 DWARF spec doesn't actually mandate this). Note that it is the size (in
8595 bytes) of the hypothetical "containing object" which will be given in the
8596 DW_AT_byte_size attribute for this bit-field. (See the
8597 `byte_size_attribute' function below.) It is also used when calculating the
8598 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8599 function below.) */
8601 static void
8602 add_data_member_location_attribute (die, decl)
8603 dw_die_ref die;
8604 tree decl;
8606 long offset;
8607 dw_loc_descr_ref loc_descr = 0;
8609 if (TREE_CODE (decl) == TREE_VEC)
8611 /* We're working on the TAG_inheritance for a base class. */
8612 if (TREE_VIA_VIRTUAL (decl) && is_cxx ())
8614 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8615 aren't at a fixed offset from all (sub)objects of the same
8616 type. We need to extract the appropriate offset from our
8617 vtable. The following dwarf expression means
8619 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8621 This is specific to the V3 ABI, of course. */
8623 dw_loc_descr_ref tmp;
8625 /* Make a copy of the object address. */
8626 tmp = new_loc_descr (DW_OP_dup, 0, 0);
8627 add_loc_descr (&loc_descr, tmp);
8629 /* Extract the vtable address. */
8630 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8631 add_loc_descr (&loc_descr, tmp);
8633 /* Calculate the address of the offset. */
8634 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
8635 if (offset >= 0)
8636 abort ();
8638 tmp = int_loc_descriptor (-offset);
8639 add_loc_descr (&loc_descr, tmp);
8640 tmp = new_loc_descr (DW_OP_minus, 0, 0);
8641 add_loc_descr (&loc_descr, tmp);
8643 /* Extract the offset. */
8644 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8645 add_loc_descr (&loc_descr, tmp);
8647 /* Add it to the object address. */
8648 tmp = new_loc_descr (DW_OP_plus, 0, 0);
8649 add_loc_descr (&loc_descr, tmp);
8651 else
8652 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8654 else
8655 offset = field_byte_offset (decl);
8657 if (! loc_descr)
8659 enum dwarf_location_atom op;
8661 /* The DWARF2 standard says that we should assume that the structure
8662 address is already on the stack, so we can specify a structure field
8663 address by using DW_OP_plus_uconst. */
8665 #ifdef MIPS_DEBUGGING_INFO
8666 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
8667 operator correctly. It works only if we leave the offset on the
8668 stack. */
8669 op = DW_OP_constu;
8670 #else
8671 op = DW_OP_plus_uconst;
8672 #endif
8674 loc_descr = new_loc_descr (op, offset, 0);
8677 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8680 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8681 does not have a "location" either in memory or in a register. These
8682 things can arise in GNU C when a constant is passed as an actual parameter
8683 to an inlined function. They can also arise in C++ where declared
8684 constants do not necessarily get memory "homes". */
8686 static void
8687 add_const_value_attribute (die, rtl)
8688 dw_die_ref die;
8689 rtx rtl;
8691 switch (GET_CODE (rtl))
8693 case CONST_INT:
8694 /* Note that a CONST_INT rtx could represent either an integer
8695 or a floating-point constant. A CONST_INT is used whenever
8696 the constant will fit into a single word. In all such
8697 cases, the original mode of the constant value is wiped
8698 out, and the CONST_INT rtx is assigned VOIDmode. */
8700 HOST_WIDE_INT val = INTVAL (rtl);
8702 /* ??? We really should be using HOST_WIDE_INT throughout. */
8703 if (val < 0 && (long) val == val)
8704 add_AT_int (die, DW_AT_const_value, (long) val);
8705 else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val)
8706 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
8707 else
8709 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
8710 add_AT_long_long (die, DW_AT_const_value,
8711 val >> HOST_BITS_PER_LONG, val);
8712 #else
8713 abort ();
8714 #endif
8717 break;
8719 case CONST_DOUBLE:
8720 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8721 floating-point constant. A CONST_DOUBLE is used whenever the
8722 constant requires more than one word in order to be adequately
8723 represented. We output CONST_DOUBLEs as blocks. */
8725 enum machine_mode mode = GET_MODE (rtl);
8727 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8729 unsigned length = GET_MODE_SIZE (mode) / 4;
8730 long *array = (long *) xmalloc (sizeof (long) * length);
8731 REAL_VALUE_TYPE rv;
8733 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8734 switch (mode)
8736 case SFmode:
8737 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8738 break;
8740 case DFmode:
8741 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8742 break;
8744 case XFmode:
8745 case TFmode:
8746 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8747 break;
8749 default:
8750 abort ();
8753 add_AT_float (die, DW_AT_const_value, length, array);
8755 else
8757 /* ??? We really should be using HOST_WIDE_INT throughout. */
8758 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8759 abort ();
8761 add_AT_long_long (die, DW_AT_const_value,
8762 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8765 break;
8767 case CONST_STRING:
8768 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8769 break;
8771 case SYMBOL_REF:
8772 case LABEL_REF:
8773 case CONST:
8774 add_AT_addr (die, DW_AT_const_value, rtl);
8775 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
8776 break;
8778 case PLUS:
8779 /* In cases where an inlined instance of an inline function is passed
8780 the address of an `auto' variable (which is local to the caller) we
8781 can get a situation where the DECL_RTL of the artificial local
8782 variable (for the inlining) which acts as a stand-in for the
8783 corresponding formal parameter (of the inline function) will look
8784 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8785 exactly a compile-time constant expression, but it isn't the address
8786 of the (artificial) local variable either. Rather, it represents the
8787 *value* which the artificial local variable always has during its
8788 lifetime. We currently have no way to represent such quasi-constant
8789 values in Dwarf, so for now we just punt and generate nothing. */
8790 break;
8792 default:
8793 /* No other kinds of rtx should be possible here. */
8794 abort ();
8799 static rtx
8800 rtl_for_decl_location (decl)
8801 tree decl;
8803 rtx rtl;
8805 /* Here we have to decide where we are going to say the parameter "lives"
8806 (as far as the debugger is concerned). We only have a couple of
8807 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8809 DECL_RTL normally indicates where the parameter lives during most of the
8810 activation of the function. If optimization is enabled however, this
8811 could be either NULL or else a pseudo-reg. Both of those cases indicate
8812 that the parameter doesn't really live anywhere (as far as the code
8813 generation parts of GCC are concerned) during most of the function's
8814 activation. That will happen (for example) if the parameter is never
8815 referenced within the function.
8817 We could just generate a location descriptor here for all non-NULL
8818 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8819 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8820 where DECL_RTL is NULL or is a pseudo-reg.
8822 Note however that we can only get away with using DECL_INCOMING_RTL as
8823 a backup substitute for DECL_RTL in certain limited cases. In cases
8824 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8825 we can be sure that the parameter was passed using the same type as it is
8826 declared to have within the function, and that its DECL_INCOMING_RTL
8827 points us to a place where a value of that type is passed.
8829 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8830 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8831 because in these cases DECL_INCOMING_RTL points us to a value of some
8832 type which is *different* from the type of the parameter itself. Thus,
8833 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8834 such cases, the debugger would end up (for example) trying to fetch a
8835 `float' from a place which actually contains the first part of a
8836 `double'. That would lead to really incorrect and confusing
8837 output at debug-time.
8839 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8840 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8841 are a couple of exceptions however. On little-endian machines we can
8842 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8843 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8844 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8845 when (on a little-endian machine) a non-prototyped function has a
8846 parameter declared to be of type `short' or `char'. In such cases,
8847 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8848 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8849 passed `int' value. If the debugger then uses that address to fetch
8850 a `short' or a `char' (on a little-endian machine) the result will be
8851 the correct data, so we allow for such exceptional cases below.
8853 Note that our goal here is to describe the place where the given formal
8854 parameter lives during most of the function's activation (i.e. between the
8855 end of the prologue and the start of the epilogue). We'll do that as best
8856 as we can. Note however that if the given formal parameter is modified
8857 sometime during the execution of the function, then a stack backtrace (at
8858 debug-time) will show the function as having been called with the *new*
8859 value rather than the value which was originally passed in. This happens
8860 rarely enough that it is not a major problem, but it *is* a problem, and
8861 I'd like to fix it.
8863 A future version of dwarf2out.c may generate two additional attributes for
8864 any given DW_TAG_formal_parameter DIE which will describe the "passed
8865 type" and the "passed location" for the given formal parameter in addition
8866 to the attributes we now generate to indicate the "declared type" and the
8867 "active location" for each parameter. This additional set of attributes
8868 could be used by debuggers for stack backtraces. Separately, note that
8869 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
8870 This happens (for example) for inlined-instances of inline function formal
8871 parameters which are never referenced. This really shouldn't be
8872 happening. All PARM_DECL nodes should get valid non-NULL
8873 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
8874 values for inlined instances of inline function parameters, so when we see
8875 such cases, we are just out-of-luck for the time being (until integrate.c
8876 gets fixed). */
8878 /* Use DECL_RTL as the "location" unless we find something better. */
8879 rtl = DECL_RTL_IF_SET (decl);
8881 /* When generating abstract instances, ignore everything except
8882 constants and symbols living in memory. */
8883 if (! reload_completed)
8885 if (rtl
8886 && (CONSTANT_P (rtl)
8887 || (GET_CODE (rtl) == MEM
8888 && CONSTANT_P (XEXP (rtl, 0)))))
8890 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8891 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
8892 #endif
8893 return rtl;
8895 rtl = NULL_RTX;
8897 else if (TREE_CODE (decl) == PARM_DECL)
8899 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8901 tree declared_type = type_main_variant (TREE_TYPE (decl));
8902 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8904 /* This decl represents a formal parameter which was optimized out.
8905 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8906 all cases where (rtl == NULL_RTX) just below. */
8907 if (declared_type == passed_type)
8908 rtl = DECL_INCOMING_RTL (decl);
8909 else if (! BYTES_BIG_ENDIAN
8910 && TREE_CODE (declared_type) == INTEGER_TYPE
8911 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8912 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8913 rtl = DECL_INCOMING_RTL (decl);
8916 /* If the parm was passed in registers, but lives on the stack, then
8917 make a big endian correction if the mode of the type of the
8918 parameter is not the same as the mode of the rtl. */
8919 /* ??? This is the same series of checks that are made in dbxout.c before
8920 we reach the big endian correction code there. It isn't clear if all
8921 of these checks are necessary here, but keeping them all is the safe
8922 thing to do. */
8923 else if (GET_CODE (rtl) == MEM
8924 && XEXP (rtl, 0) != const0_rtx
8925 && ! CONSTANT_P (XEXP (rtl, 0))
8926 /* Not passed in memory. */
8927 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8928 /* Not passed by invisible reference. */
8929 && (GET_CODE (XEXP (rtl, 0)) != REG
8930 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8931 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8932 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8933 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8934 #endif
8936 /* Big endian correction check. */
8937 && BYTES_BIG_ENDIAN
8938 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8939 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8940 < UNITS_PER_WORD))
8942 int offset = (UNITS_PER_WORD
8943 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8945 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8946 plus_constant (XEXP (rtl, 0), offset));
8950 if (rtl != NULL_RTX)
8952 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8953 #ifdef LEAF_REG_REMAP
8954 if (current_function_uses_only_leaf_regs)
8955 leaf_renumber_regs_insn (rtl);
8956 #endif
8959 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
8960 and will have been substituted directly into all expressions that use it.
8961 C does not have such a concept, but C++ and other languages do. */
8962 else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
8964 /* If a variable is initialized with a string constant without embedded
8965 zeros, build CONST_STRING. */
8966 if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
8967 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
8969 tree arrtype = TREE_TYPE (decl);
8970 tree enttype = TREE_TYPE (arrtype);
8971 tree domain = TYPE_DOMAIN (arrtype);
8972 tree init = DECL_INITIAL (decl);
8973 enum machine_mode mode = TYPE_MODE (enttype);
8975 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
8976 && domain
8977 && integer_zerop (TYPE_MIN_VALUE (domain))
8978 && compare_tree_int (TYPE_MAX_VALUE (domain),
8979 TREE_STRING_LENGTH (init) - 1) == 0
8980 && ((size_t) TREE_STRING_LENGTH (init)
8981 == strlen (TREE_STRING_POINTER (init)) + 1))
8982 rtl = gen_rtx_CONST_STRING (VOIDmode, TREE_STRING_POINTER (init));
8984 /* If the initializer is something that we know will expand into an
8985 immediate RTL constant, expand it now. Expanding anything else
8986 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
8987 else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST
8988 || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST)
8990 rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
8991 EXPAND_INITIALIZER);
8992 /* If expand_expr returns a MEM, it wasn't immediate. */
8993 if (rtl && GET_CODE (rtl) == MEM)
8994 abort ();
8998 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8999 if (rtl)
9000 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
9001 #endif
9003 /* If we don't look past the constant pool, we risk emitting a
9004 reference to a constant pool entry that isn't referenced from
9005 code, and thus is not emitted. */
9006 if (rtl)
9007 rtl = avoid_constant_pool_reference (rtl);
9009 return rtl;
9012 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
9013 data attribute for a variable or a parameter. We generate the
9014 DW_AT_const_value attribute only in those cases where the given variable
9015 or parameter does not have a true "location" either in memory or in a
9016 register. This can happen (for example) when a constant is passed as an
9017 actual argument in a call to an inline function. (It's possible that
9018 these things can crop up in other ways also.) Note that one type of
9019 constant value which can be passed into an inlined function is a constant
9020 pointer. This can happen for example if an actual argument in an inlined
9021 function call evaluates to a compile-time constant address. */
9023 static void
9024 add_location_or_const_value_attribute (die, decl)
9025 dw_die_ref die;
9026 tree decl;
9028 rtx rtl;
9029 dw_loc_descr_ref descr;
9031 if (TREE_CODE (decl) == ERROR_MARK)
9032 return;
9033 else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
9034 abort ();
9036 rtl = rtl_for_decl_location (decl);
9037 if (rtl == NULL_RTX)
9038 return;
9040 switch (GET_CODE (rtl))
9042 case ADDRESSOF:
9043 /* The address of a variable that was optimized away;
9044 don't emit anything. */
9045 break;
9047 case CONST_INT:
9048 case CONST_DOUBLE:
9049 case CONST_STRING:
9050 case SYMBOL_REF:
9051 case LABEL_REF:
9052 case CONST:
9053 case PLUS:
9054 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
9055 add_const_value_attribute (die, rtl);
9056 break;
9058 case MEM:
9059 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
9061 /* Need loc_descriptor_from_tree since that's where we know
9062 how to handle TLS variables. Want the object's address
9063 since the top-level DW_AT_location assumes such. See
9064 the confusion in loc_descriptor for reference. */
9065 descr = loc_descriptor_from_tree (decl, 1);
9067 else
9069 case REG:
9070 case SUBREG:
9071 case CONCAT:
9072 descr = loc_descriptor (rtl);
9074 add_AT_location_description (die, DW_AT_location, descr);
9075 break;
9077 default:
9078 abort ();
9082 /* If we don't have a copy of this variable in memory for some reason (such
9083 as a C++ member constant that doesn't have an out-of-line definition),
9084 we should tell the debugger about the constant value. */
9086 static void
9087 tree_add_const_value_attribute (var_die, decl)
9088 dw_die_ref var_die;
9089 tree decl;
9091 tree init = DECL_INITIAL (decl);
9092 tree type = TREE_TYPE (decl);
9094 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
9095 && initializer_constant_valid_p (init, type) == null_pointer_node)
9096 /* OK */;
9097 else
9098 return;
9100 switch (TREE_CODE (type))
9102 case INTEGER_TYPE:
9103 if (host_integerp (init, 0))
9104 add_AT_unsigned (var_die, DW_AT_const_value,
9105 tree_low_cst (init, 0));
9106 else
9107 add_AT_long_long (var_die, DW_AT_const_value,
9108 TREE_INT_CST_HIGH (init),
9109 TREE_INT_CST_LOW (init));
9110 break;
9112 default:;
9116 /* Generate an DW_AT_name attribute given some string value to be included as
9117 the value of the attribute. */
9119 static inline void
9120 add_name_attribute (die, name_string)
9121 dw_die_ref die;
9122 const char *name_string;
9124 if (name_string != NULL && *name_string != 0)
9126 if (demangle_name_func)
9127 name_string = (*demangle_name_func) (name_string);
9129 add_AT_string (die, DW_AT_name, name_string);
9133 /* Given a tree node describing an array bound (either lower or upper) output
9134 a representation for that bound. */
9136 static void
9137 add_bound_info (subrange_die, bound_attr, bound)
9138 dw_die_ref subrange_die;
9139 enum dwarf_attribute bound_attr;
9140 tree bound;
9142 switch (TREE_CODE (bound))
9144 case ERROR_MARK:
9145 return;
9147 /* All fixed-bounds are represented by INTEGER_CST nodes. */
9148 case INTEGER_CST:
9149 if (! host_integerp (bound, 0)
9150 || (bound_attr == DW_AT_lower_bound
9151 && (((is_c_family () || is_java ()) && integer_zerop (bound))
9152 || (is_fortran () && integer_onep (bound)))))
9153 /* use the default */
9155 else
9156 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
9157 break;
9159 case CONVERT_EXPR:
9160 case NOP_EXPR:
9161 case NON_LVALUE_EXPR:
9162 case VIEW_CONVERT_EXPR:
9163 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
9164 break;
9166 case SAVE_EXPR:
9167 /* If optimization is turned on, the SAVE_EXPRs that describe how to
9168 access the upper bound values may be bogus. If they refer to a
9169 register, they may only describe how to get at these values at the
9170 points in the generated code right after they have just been
9171 computed. Worse yet, in the typical case, the upper bound values
9172 will not even *be* computed in the optimized code (though the
9173 number of elements will), so these SAVE_EXPRs are entirely
9174 bogus. In order to compensate for this fact, we check here to see
9175 if optimization is enabled, and if so, we don't add an attribute
9176 for the (unknown and unknowable) upper bound. This should not
9177 cause too much trouble for existing (stupid?) debuggers because
9178 they have to deal with empty upper bounds location descriptions
9179 anyway in order to be able to deal with incomplete array types.
9180 Of course an intelligent debugger (GDB?) should be able to
9181 comprehend that a missing upper bound specification in an array
9182 type used for a storage class `auto' local array variable
9183 indicates that the upper bound is both unknown (at compile- time)
9184 and unknowable (at run-time) due to optimization.
9186 We assume that a MEM rtx is safe because gcc wouldn't put the
9187 value there unless it was going to be used repeatedly in the
9188 function, i.e. for cleanups. */
9189 if (SAVE_EXPR_RTL (bound)
9190 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
9192 dw_die_ref ctx = lookup_decl_die (current_function_decl);
9193 dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound);
9194 rtx loc = SAVE_EXPR_RTL (bound);
9196 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9197 it references an outer function's frame. */
9198 if (GET_CODE (loc) == MEM)
9200 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
9202 if (XEXP (loc, 0) != new_addr)
9203 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
9206 add_AT_flag (decl_die, DW_AT_artificial, 1);
9207 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9208 add_AT_location_description (decl_die, DW_AT_location,
9209 loc_descriptor (loc));
9210 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9213 /* Else leave out the attribute. */
9214 break;
9216 case VAR_DECL:
9217 case PARM_DECL:
9219 dw_die_ref decl_die = lookup_decl_die (bound);
9221 /* ??? Can this happen, or should the variable have been bound
9222 first? Probably it can, since I imagine that we try to create
9223 the types of parameters in the order in which they exist in
9224 the list, and won't have created a forward reference to a
9225 later parameter. */
9226 if (decl_die != NULL)
9227 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9228 break;
9231 default:
9233 /* Otherwise try to create a stack operation procedure to
9234 evaluate the value of the array bound. */
9236 dw_die_ref ctx, decl_die;
9237 dw_loc_descr_ref loc;
9239 loc = loc_descriptor_from_tree (bound, 0);
9240 if (loc == NULL)
9241 break;
9243 if (current_function_decl == 0)
9244 ctx = comp_unit_die;
9245 else
9246 ctx = lookup_decl_die (current_function_decl);
9248 /* If we weren't able to find a context, it's most likely the case
9249 that we are processing the return type of the function. So
9250 make a SAVE_EXPR to point to it and have the limbo DIE code
9251 find the proper die. The save_expr function doesn't always
9252 make a SAVE_EXPR, so do it ourselves. */
9253 if (ctx == 0)
9254 bound = build (SAVE_EXPR, TREE_TYPE (bound), bound,
9255 current_function_decl, NULL_TREE);
9257 decl_die = new_die (DW_TAG_variable, ctx, bound);
9258 add_AT_flag (decl_die, DW_AT_artificial, 1);
9259 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9260 add_AT_loc (decl_die, DW_AT_location, loc);
9262 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9263 break;
9268 /* Note that the block of subscript information for an array type also
9269 includes information about the element type of type given array type. */
9271 static void
9272 add_subscript_info (type_die, type)
9273 dw_die_ref type_die;
9274 tree type;
9276 #ifndef MIPS_DEBUGGING_INFO
9277 unsigned dimension_number;
9278 #endif
9279 tree lower, upper;
9280 dw_die_ref subrange_die;
9282 /* The GNU compilers represent multidimensional array types as sequences of
9283 one dimensional array types whose element types are themselves array
9284 types. Here we squish that down, so that each multidimensional array
9285 type gets only one array_type DIE in the Dwarf debugging info. The draft
9286 Dwarf specification say that we are allowed to do this kind of
9287 compression in C (because there is no difference between an array or
9288 arrays and a multidimensional array in C) but for other source languages
9289 (e.g. Ada) we probably shouldn't do this. */
9291 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9292 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9293 We work around this by disabling this feature. See also
9294 gen_array_type_die. */
9295 #ifndef MIPS_DEBUGGING_INFO
9296 for (dimension_number = 0;
9297 TREE_CODE (type) == ARRAY_TYPE;
9298 type = TREE_TYPE (type), dimension_number++)
9299 #endif
9301 tree domain = TYPE_DOMAIN (type);
9303 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9304 and (in GNU C only) variable bounds. Handle all three forms
9305 here. */
9306 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
9307 if (domain)
9309 /* We have an array type with specified bounds. */
9310 lower = TYPE_MIN_VALUE (domain);
9311 upper = TYPE_MAX_VALUE (domain);
9313 /* define the index type. */
9314 if (TREE_TYPE (domain))
9316 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9317 TREE_TYPE field. We can't emit debug info for this
9318 because it is an unnamed integral type. */
9319 if (TREE_CODE (domain) == INTEGER_TYPE
9320 && TYPE_NAME (domain) == NULL_TREE
9321 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9322 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
9324 else
9325 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9326 type_die);
9329 /* ??? If upper is NULL, the array has unspecified length,
9330 but it does have a lower bound. This happens with Fortran
9331 dimension arr(N:*)
9332 Since the debugger is definitely going to need to know N
9333 to produce useful results, go ahead and output the lower
9334 bound solo, and hope the debugger can cope. */
9336 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
9337 if (upper)
9338 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
9341 /* Otherwise we have an array type with an unspecified length. The
9342 DWARF-2 spec does not say how to handle this; let's just leave out the
9343 bounds. */
9347 static void
9348 add_byte_size_attribute (die, tree_node)
9349 dw_die_ref die;
9350 tree tree_node;
9352 unsigned size;
9354 switch (TREE_CODE (tree_node))
9356 case ERROR_MARK:
9357 size = 0;
9358 break;
9359 case ENUMERAL_TYPE:
9360 case RECORD_TYPE:
9361 case UNION_TYPE:
9362 case QUAL_UNION_TYPE:
9363 size = int_size_in_bytes (tree_node);
9364 break;
9365 case FIELD_DECL:
9366 /* For a data member of a struct or union, the DW_AT_byte_size is
9367 generally given as the number of bytes normally allocated for an
9368 object of the *declared* type of the member itself. This is true
9369 even for bit-fields. */
9370 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9371 break;
9372 default:
9373 abort ();
9376 /* Note that `size' might be -1 when we get to this point. If it is, that
9377 indicates that the byte size of the entity in question is variable. We
9378 have no good way of expressing this fact in Dwarf at the present time,
9379 so just let the -1 pass on through. */
9380 add_AT_unsigned (die, DW_AT_byte_size, size);
9383 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9384 which specifies the distance in bits from the highest order bit of the
9385 "containing object" for the bit-field to the highest order bit of the
9386 bit-field itself.
9388 For any given bit-field, the "containing object" is a hypothetical object
9389 (of some integral or enum type) within which the given bit-field lives. The
9390 type of this hypothetical "containing object" is always the same as the
9391 declared type of the individual bit-field itself. The determination of the
9392 exact location of the "containing object" for a bit-field is rather
9393 complicated. It's handled by the `field_byte_offset' function (above).
9395 Note that it is the size (in bytes) of the hypothetical "containing object"
9396 which will be given in the DW_AT_byte_size attribute for this bit-field.
9397 (See `byte_size_attribute' above). */
9399 static inline void
9400 add_bit_offset_attribute (die, decl)
9401 dw_die_ref die;
9402 tree decl;
9404 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9405 tree type = DECL_BIT_FIELD_TYPE (decl);
9406 HOST_WIDE_INT bitpos_int;
9407 HOST_WIDE_INT highest_order_object_bit_offset;
9408 HOST_WIDE_INT highest_order_field_bit_offset;
9409 HOST_WIDE_INT unsigned bit_offset;
9411 /* Must be a field and a bit field. */
9412 if (!type
9413 || TREE_CODE (decl) != FIELD_DECL)
9414 abort ();
9416 /* We can't yet handle bit-fields whose offsets are variable, so if we
9417 encounter such things, just return without generating any attribute
9418 whatsoever. Likewise for variable or too large size. */
9419 if (! host_integerp (bit_position (decl), 0)
9420 || ! host_integerp (DECL_SIZE (decl), 1))
9421 return;
9423 bitpos_int = int_bit_position (decl);
9425 /* Note that the bit offset is always the distance (in bits) from the
9426 highest-order bit of the "containing object" to the highest-order bit of
9427 the bit-field itself. Since the "high-order end" of any object or field
9428 is different on big-endian and little-endian machines, the computation
9429 below must take account of these differences. */
9430 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9431 highest_order_field_bit_offset = bitpos_int;
9433 if (! BYTES_BIG_ENDIAN)
9435 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9436 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9439 bit_offset
9440 = (! BYTES_BIG_ENDIAN
9441 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9442 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9444 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9447 /* For a FIELD_DECL node which represents a bit field, output an attribute
9448 which specifies the length in bits of the given field. */
9450 static inline void
9451 add_bit_size_attribute (die, decl)
9452 dw_die_ref die;
9453 tree decl;
9455 /* Must be a field and a bit field. */
9456 if (TREE_CODE (decl) != FIELD_DECL
9457 || ! DECL_BIT_FIELD_TYPE (decl))
9458 abort ();
9460 if (host_integerp (DECL_SIZE (decl), 1))
9461 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9464 /* If the compiled language is ANSI C, then add a 'prototyped'
9465 attribute, if arg types are given for the parameters of a function. */
9467 static inline void
9468 add_prototyped_attribute (die, func_type)
9469 dw_die_ref die;
9470 tree func_type;
9472 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9473 && TYPE_ARG_TYPES (func_type) != NULL)
9474 add_AT_flag (die, DW_AT_prototyped, 1);
9477 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9478 by looking in either the type declaration or object declaration
9479 equate table. */
9481 static inline void
9482 add_abstract_origin_attribute (die, origin)
9483 dw_die_ref die;
9484 tree origin;
9486 dw_die_ref origin_die = NULL;
9488 if (TREE_CODE (origin) != FUNCTION_DECL)
9490 /* We may have gotten separated from the block for the inlined
9491 function, if we're in an exception handler or some such; make
9492 sure that the abstract function has been written out.
9494 Doing this for nested functions is wrong, however; functions are
9495 distinct units, and our context might not even be inline. */
9496 tree fn = origin;
9498 if (TYPE_P (fn))
9499 fn = TYPE_STUB_DECL (fn);
9501 fn = decl_function_context (fn);
9502 if (fn)
9503 dwarf2out_abstract_function (fn);
9506 if (DECL_P (origin))
9507 origin_die = lookup_decl_die (origin);
9508 else if (TYPE_P (origin))
9509 origin_die = lookup_type_die (origin);
9511 if (origin_die == NULL)
9512 abort ();
9514 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9517 /* We do not currently support the pure_virtual attribute. */
9519 static inline void
9520 add_pure_or_virtual_attribute (die, func_decl)
9521 dw_die_ref die;
9522 tree func_decl;
9524 if (DECL_VINDEX (func_decl))
9526 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9528 if (host_integerp (DECL_VINDEX (func_decl), 0))
9529 add_AT_loc (die, DW_AT_vtable_elem_location,
9530 new_loc_descr (DW_OP_constu,
9531 tree_low_cst (DECL_VINDEX (func_decl), 0),
9532 0));
9534 /* GNU extension: Record what type this method came from originally. */
9535 if (debug_info_level > DINFO_LEVEL_TERSE)
9536 add_AT_die_ref (die, DW_AT_containing_type,
9537 lookup_type_die (DECL_CONTEXT (func_decl)));
9541 /* Add source coordinate attributes for the given decl. */
9543 static void
9544 add_src_coords_attributes (die, decl)
9545 dw_die_ref die;
9546 tree decl;
9548 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9550 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9551 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9554 /* Add an DW_AT_name attribute and source coordinate attribute for the
9555 given decl, but only if it actually has a name. */
9557 static void
9558 add_name_and_src_coords_attributes (die, decl)
9559 dw_die_ref die;
9560 tree decl;
9562 tree decl_name;
9564 decl_name = DECL_NAME (decl);
9565 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9567 add_name_attribute (die, dwarf2_name (decl, 0));
9568 if (! DECL_ARTIFICIAL (decl))
9569 add_src_coords_attributes (die, decl);
9571 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9572 && TREE_PUBLIC (decl)
9573 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9574 && !DECL_ABSTRACT (decl))
9575 add_AT_string (die, DW_AT_MIPS_linkage_name,
9576 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9579 #ifdef VMS_DEBUGGING_INFO
9580 /* Get the function's name, as described by its RTL. This may be different
9581 from the DECL_NAME name used in the source file. */
9582 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
9584 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
9585 XEXP (DECL_RTL (decl), 0));
9586 VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0));
9588 #endif
9591 /* Push a new declaration scope. */
9593 static void
9594 push_decl_scope (scope)
9595 tree scope;
9597 VARRAY_PUSH_TREE (decl_scope_table, scope);
9600 /* Pop a declaration scope. */
9602 static inline void
9603 pop_decl_scope ()
9605 if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0)
9606 abort ();
9608 VARRAY_POP (decl_scope_table);
9611 /* Return the DIE for the scope that immediately contains this type.
9612 Non-named types get global scope. Named types nested in other
9613 types get their containing scope if it's open, or global scope
9614 otherwise. All other types (i.e. function-local named types) get
9615 the current active scope. */
9617 static dw_die_ref
9618 scope_die_for (t, context_die)
9619 tree t;
9620 dw_die_ref context_die;
9622 dw_die_ref scope_die = NULL;
9623 tree containing_scope;
9624 int i;
9626 /* Non-types always go in the current scope. */
9627 if (! TYPE_P (t))
9628 abort ();
9630 containing_scope = TYPE_CONTEXT (t);
9632 /* Ignore namespaces for the moment. */
9633 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9634 containing_scope = NULL_TREE;
9636 /* Ignore function type "scopes" from the C frontend. They mean that
9637 a tagged type is local to a parmlist of a function declarator, but
9638 that isn't useful to DWARF. */
9639 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9640 containing_scope = NULL_TREE;
9642 if (containing_scope == NULL_TREE)
9643 scope_die = comp_unit_die;
9644 else if (TYPE_P (containing_scope))
9646 /* For types, we can just look up the appropriate DIE. But
9647 first we check to see if we're in the middle of emitting it
9648 so we know where the new DIE should go. */
9649 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
9650 if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
9651 break;
9653 if (i < 0)
9655 if (debug_info_level > DINFO_LEVEL_TERSE
9656 && !TREE_ASM_WRITTEN (containing_scope))
9657 abort ();
9659 /* If none of the current dies are suitable, we get file scope. */
9660 scope_die = comp_unit_die;
9662 else
9663 scope_die = lookup_type_die (containing_scope);
9665 else
9666 scope_die = context_die;
9668 return scope_die;
9671 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
9673 static inline int
9674 local_scope_p (context_die)
9675 dw_die_ref context_die;
9677 for (; context_die; context_die = context_die->die_parent)
9678 if (context_die->die_tag == DW_TAG_inlined_subroutine
9679 || context_die->die_tag == DW_TAG_subprogram)
9680 return 1;
9682 return 0;
9685 /* Returns nonzero if CONTEXT_DIE is a class. */
9687 static inline int
9688 class_scope_p (context_die)
9689 dw_die_ref context_die;
9691 return (context_die
9692 && (context_die->die_tag == DW_TAG_structure_type
9693 || context_die->die_tag == DW_TAG_union_type));
9696 /* Many forms of DIEs require a "type description" attribute. This
9697 routine locates the proper "type descriptor" die for the type given
9698 by 'type', and adds an DW_AT_type attribute below the given die. */
9700 static void
9701 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9702 dw_die_ref object_die;
9703 tree type;
9704 int decl_const;
9705 int decl_volatile;
9706 dw_die_ref context_die;
9708 enum tree_code code = TREE_CODE (type);
9709 dw_die_ref type_die = NULL;
9711 /* ??? If this type is an unnamed subrange type of an integral or
9712 floating-point type, use the inner type. This is because we have no
9713 support for unnamed types in base_type_die. This can happen if this is
9714 an Ada subrange type. Correct solution is emit a subrange type die. */
9715 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9716 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9717 type = TREE_TYPE (type), code = TREE_CODE (type);
9719 if (code == ERROR_MARK
9720 /* Handle a special case. For functions whose return type is void, we
9721 generate *no* type attribute. (Note that no object may have type
9722 `void', so this only applies to function return types). */
9723 || code == VOID_TYPE)
9724 return;
9726 type_die = modified_type_die (type,
9727 decl_const || TYPE_READONLY (type),
9728 decl_volatile || TYPE_VOLATILE (type),
9729 context_die);
9731 if (type_die != NULL)
9732 add_AT_die_ref (object_die, DW_AT_type, type_die);
9735 /* Given a tree pointer to a struct, class, union, or enum type node, return
9736 a pointer to the (string) tag name for the given type, or zero if the type
9737 was declared without a tag. */
9739 static const char *
9740 type_tag (type)
9741 tree type;
9743 const char *name = 0;
9745 if (TYPE_NAME (type) != 0)
9747 tree t = 0;
9749 /* Find the IDENTIFIER_NODE for the type name. */
9750 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9751 t = TYPE_NAME (type);
9753 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9754 a TYPE_DECL node, regardless of whether or not a `typedef' was
9755 involved. */
9756 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9757 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9758 t = DECL_NAME (TYPE_NAME (type));
9760 /* Now get the name as a string, or invent one. */
9761 if (t != 0)
9762 name = IDENTIFIER_POINTER (t);
9765 return (name == 0 || *name == '\0') ? 0 : name;
9768 /* Return the type associated with a data member, make a special check
9769 for bit field types. */
9771 static inline tree
9772 member_declared_type (member)
9773 tree member;
9775 return (DECL_BIT_FIELD_TYPE (member)
9776 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
9779 /* Get the decl's label, as described by its RTL. This may be different
9780 from the DECL_NAME name used in the source file. */
9782 #if 0
9783 static const char *
9784 decl_start_label (decl)
9785 tree decl;
9787 rtx x;
9788 const char *fnname;
9790 x = DECL_RTL (decl);
9791 if (GET_CODE (x) != MEM)
9792 abort ();
9794 x = XEXP (x, 0);
9795 if (GET_CODE (x) != SYMBOL_REF)
9796 abort ();
9798 fnname = XSTR (x, 0);
9799 return fnname;
9801 #endif
9803 /* These routines generate the internal representation of the DIE's for
9804 the compilation unit. Debugging information is collected by walking
9805 the declaration trees passed in from dwarf2out_decl(). */
9807 static void
9808 gen_array_type_die (type, context_die)
9809 tree type;
9810 dw_die_ref context_die;
9812 dw_die_ref scope_die = scope_die_for (type, context_die);
9813 dw_die_ref array_die;
9814 tree element_type;
9816 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9817 the inner array type comes before the outer array type. Thus we must
9818 call gen_type_die before we call new_die. See below also. */
9819 #ifdef MIPS_DEBUGGING_INFO
9820 gen_type_die (TREE_TYPE (type), context_die);
9821 #endif
9823 array_die = new_die (DW_TAG_array_type, scope_die, type);
9824 add_name_attribute (array_die, type_tag (type));
9825 equate_type_number_to_die (type, array_die);
9827 if (TREE_CODE (type) == VECTOR_TYPE)
9829 /* The frontend feeds us a representation for the vector as a struct
9830 containing an array. Pull out the array type. */
9831 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
9832 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
9835 #if 0
9836 /* We default the array ordering. SDB will probably do
9837 the right things even if DW_AT_ordering is not present. It's not even
9838 an issue until we start to get into multidimensional arrays anyway. If
9839 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9840 then we'll have to put the DW_AT_ordering attribute back in. (But if
9841 and when we find out that we need to put these in, we will only do so
9842 for multidimensional arrays. */
9843 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9844 #endif
9846 #ifdef MIPS_DEBUGGING_INFO
9847 /* The SGI compilers handle arrays of unknown bound by setting
9848 AT_declaration and not emitting any subrange DIEs. */
9849 if (! TYPE_DOMAIN (type))
9850 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9851 else
9852 #endif
9853 add_subscript_info (array_die, type);
9855 /* Add representation of the type of the elements of this array type. */
9856 element_type = TREE_TYPE (type);
9858 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9859 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9860 We work around this by disabling this feature. See also
9861 add_subscript_info. */
9862 #ifndef MIPS_DEBUGGING_INFO
9863 while (TREE_CODE (element_type) == ARRAY_TYPE)
9864 element_type = TREE_TYPE (element_type);
9866 gen_type_die (element_type, context_die);
9867 #endif
9869 add_type_attribute (array_die, element_type, 0, 0, context_die);
9872 static void
9873 gen_set_type_die (type, context_die)
9874 tree type;
9875 dw_die_ref context_die;
9877 dw_die_ref type_die
9878 = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type);
9880 equate_type_number_to_die (type, type_die);
9881 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9884 #if 0
9885 static void
9886 gen_entry_point_die (decl, context_die)
9887 tree decl;
9888 dw_die_ref context_die;
9890 tree origin = decl_ultimate_origin (decl);
9891 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
9893 if (origin != NULL)
9894 add_abstract_origin_attribute (decl_die, origin);
9895 else
9897 add_name_and_src_coords_attributes (decl_die, decl);
9898 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9899 0, 0, context_die);
9902 if (DECL_ABSTRACT (decl))
9903 equate_decl_number_to_die (decl, decl_die);
9904 else
9905 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9907 #endif
9909 /* Walk through the list of incomplete types again, trying once more to
9910 emit full debugging info for them. */
9912 static void
9913 retry_incomplete_types ()
9915 int i;
9917 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
9918 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
9921 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9923 static void
9924 gen_inlined_enumeration_type_die (type, context_die)
9925 tree type;
9926 dw_die_ref context_die;
9928 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
9930 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9931 be incomplete and such types are not marked. */
9932 add_abstract_origin_attribute (type_die, type);
9935 /* Generate a DIE to represent an inlined instance of a structure type. */
9937 static void
9938 gen_inlined_structure_type_die (type, context_die)
9939 tree type;
9940 dw_die_ref context_die;
9942 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
9944 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9945 be incomplete and such types are not marked. */
9946 add_abstract_origin_attribute (type_die, type);
9949 /* Generate a DIE to represent an inlined instance of a union type. */
9951 static void
9952 gen_inlined_union_type_die (type, context_die)
9953 tree type;
9954 dw_die_ref context_die;
9956 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
9958 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9959 be incomplete and such types are not marked. */
9960 add_abstract_origin_attribute (type_die, type);
9963 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9964 include all of the information about the enumeration values also. Each
9965 enumerated type name/value is listed as a child of the enumerated type
9966 DIE. */
9968 static void
9969 gen_enumeration_type_die (type, context_die)
9970 tree type;
9971 dw_die_ref context_die;
9973 dw_die_ref type_die = lookup_type_die (type);
9975 if (type_die == NULL)
9977 type_die = new_die (DW_TAG_enumeration_type,
9978 scope_die_for (type, context_die), type);
9979 equate_type_number_to_die (type, type_die);
9980 add_name_attribute (type_die, type_tag (type));
9982 else if (! TYPE_SIZE (type))
9983 return;
9984 else
9985 remove_AT (type_die, DW_AT_declaration);
9987 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9988 given enum type is incomplete, do not generate the DW_AT_byte_size
9989 attribute or the DW_AT_element_list attribute. */
9990 if (TYPE_SIZE (type))
9992 tree link;
9994 TREE_ASM_WRITTEN (type) = 1;
9995 add_byte_size_attribute (type_die, type);
9996 if (TYPE_STUB_DECL (type) != NULL_TREE)
9997 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9999 /* If the first reference to this type was as the return type of an
10000 inline function, then it may not have a parent. Fix this now. */
10001 if (type_die->die_parent == NULL)
10002 add_child_die (scope_die_for (type, context_die), type_die);
10004 for (link = TYPE_FIELDS (type);
10005 link != NULL; link = TREE_CHAIN (link))
10007 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
10009 add_name_attribute (enum_die,
10010 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
10012 if (host_integerp (TREE_VALUE (link), 0))
10014 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
10015 add_AT_int (enum_die, DW_AT_const_value,
10016 tree_low_cst (TREE_VALUE (link), 0));
10017 else
10018 add_AT_unsigned (enum_die, DW_AT_const_value,
10019 tree_low_cst (TREE_VALUE (link), 0));
10023 else
10024 add_AT_flag (type_die, DW_AT_declaration, 1);
10027 /* Generate a DIE to represent either a real live formal parameter decl or to
10028 represent just the type of some formal parameter position in some function
10029 type.
10031 Note that this routine is a bit unusual because its argument may be a
10032 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
10033 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
10034 node. If it's the former then this function is being called to output a
10035 DIE to represent a formal parameter object (or some inlining thereof). If
10036 it's the latter, then this function is only being called to output a
10037 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
10038 argument type of some subprogram type. */
10040 static dw_die_ref
10041 gen_formal_parameter_die (node, context_die)
10042 tree node;
10043 dw_die_ref context_die;
10045 dw_die_ref parm_die
10046 = new_die (DW_TAG_formal_parameter, context_die, node);
10047 tree origin;
10049 switch (TREE_CODE_CLASS (TREE_CODE (node)))
10051 case 'd':
10052 origin = decl_ultimate_origin (node);
10053 if (origin != NULL)
10054 add_abstract_origin_attribute (parm_die, origin);
10055 else
10057 add_name_and_src_coords_attributes (parm_die, node);
10058 add_type_attribute (parm_die, TREE_TYPE (node),
10059 TREE_READONLY (node),
10060 TREE_THIS_VOLATILE (node),
10061 context_die);
10062 if (DECL_ARTIFICIAL (node))
10063 add_AT_flag (parm_die, DW_AT_artificial, 1);
10066 equate_decl_number_to_die (node, parm_die);
10067 if (! DECL_ABSTRACT (node))
10068 add_location_or_const_value_attribute (parm_die, node);
10070 break;
10072 case 't':
10073 /* We were called with some kind of a ..._TYPE node. */
10074 add_type_attribute (parm_die, node, 0, 0, context_die);
10075 break;
10077 default:
10078 abort ();
10081 return parm_die;
10084 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
10085 at the end of an (ANSI prototyped) formal parameters list. */
10087 static void
10088 gen_unspecified_parameters_die (decl_or_type, context_die)
10089 tree decl_or_type;
10090 dw_die_ref context_die;
10092 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
10095 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
10096 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
10097 parameters as specified in some function type specification (except for
10098 those which appear as part of a function *definition*). */
10100 static void
10101 gen_formal_types_die (function_or_method_type, context_die)
10102 tree function_or_method_type;
10103 dw_die_ref context_die;
10105 tree link;
10106 tree formal_type = NULL;
10107 tree first_parm_type;
10108 tree arg;
10110 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
10112 arg = DECL_ARGUMENTS (function_or_method_type);
10113 function_or_method_type = TREE_TYPE (function_or_method_type);
10115 else
10116 arg = NULL_TREE;
10118 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
10120 /* Make our first pass over the list of formal parameter types and output a
10121 DW_TAG_formal_parameter DIE for each one. */
10122 for (link = first_parm_type; link; )
10124 dw_die_ref parm_die;
10126 formal_type = TREE_VALUE (link);
10127 if (formal_type == void_type_node)
10128 break;
10130 /* Output a (nameless) DIE to represent the formal parameter itself. */
10131 parm_die = gen_formal_parameter_die (formal_type, context_die);
10132 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
10133 && link == first_parm_type)
10134 || (arg && DECL_ARTIFICIAL (arg)))
10135 add_AT_flag (parm_die, DW_AT_artificial, 1);
10137 link = TREE_CHAIN (link);
10138 if (arg)
10139 arg = TREE_CHAIN (arg);
10142 /* If this function type has an ellipsis, add a
10143 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10144 if (formal_type != void_type_node)
10145 gen_unspecified_parameters_die (function_or_method_type, context_die);
10147 /* Make our second (and final) pass over the list of formal parameter types
10148 and output DIEs to represent those types (as necessary). */
10149 for (link = TYPE_ARG_TYPES (function_or_method_type);
10150 link && TREE_VALUE (link);
10151 link = TREE_CHAIN (link))
10152 gen_type_die (TREE_VALUE (link), context_die);
10155 /* We want to generate the DIE for TYPE so that we can generate the
10156 die for MEMBER, which has been defined; we will need to refer back
10157 to the member declaration nested within TYPE. If we're trying to
10158 generate minimal debug info for TYPE, processing TYPE won't do the
10159 trick; we need to attach the member declaration by hand. */
10161 static void
10162 gen_type_die_for_member (type, member, context_die)
10163 tree type, member;
10164 dw_die_ref context_die;
10166 gen_type_die (type, context_die);
10168 /* If we're trying to avoid duplicate debug info, we may not have
10169 emitted the member decl for this function. Emit it now. */
10170 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
10171 && ! lookup_decl_die (member))
10173 if (decl_ultimate_origin (member))
10174 abort ();
10176 push_decl_scope (type);
10177 if (TREE_CODE (member) == FUNCTION_DECL)
10178 gen_subprogram_die (member, lookup_type_die (type));
10179 else
10180 gen_variable_die (member, lookup_type_die (type));
10182 pop_decl_scope ();
10186 /* Generate the DWARF2 info for the "abstract" instance of a function which we
10187 may later generate inlined and/or out-of-line instances of. */
10189 static void
10190 dwarf2out_abstract_function (decl)
10191 tree decl;
10193 dw_die_ref old_die;
10194 tree save_fn;
10195 tree context;
10196 int was_abstract = DECL_ABSTRACT (decl);
10198 /* Make sure we have the actual abstract inline, not a clone. */
10199 decl = DECL_ORIGIN (decl);
10201 old_die = lookup_decl_die (decl);
10202 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
10203 /* We've already generated the abstract instance. */
10204 return;
10206 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10207 we don't get confused by DECL_ABSTRACT. */
10208 if (debug_info_level > DINFO_LEVEL_TERSE)
10210 context = decl_class_context (decl);
10211 if (context)
10212 gen_type_die_for_member
10213 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
10216 /* Pretend we've just finished compiling this function. */
10217 save_fn = current_function_decl;
10218 current_function_decl = decl;
10220 set_decl_abstract_flags (decl, 1);
10221 dwarf2out_decl (decl);
10222 if (! was_abstract)
10223 set_decl_abstract_flags (decl, 0);
10225 current_function_decl = save_fn;
10228 /* Generate a DIE to represent a declared function (either file-scope or
10229 block-local). */
10231 static void
10232 gen_subprogram_die (decl, context_die)
10233 tree decl;
10234 dw_die_ref context_die;
10236 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10237 tree origin = decl_ultimate_origin (decl);
10238 dw_die_ref subr_die;
10239 rtx fp_reg;
10240 tree fn_arg_types;
10241 tree outer_scope;
10242 dw_die_ref old_die = lookup_decl_die (decl);
10243 int declaration = (current_function_decl != decl
10244 || class_scope_p (context_die));
10246 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10247 started to generate the abstract instance of an inline, decided to output
10248 its containing class, and proceeded to emit the declaration of the inline
10249 from the member list for the class. If so, DECLARATION takes priority;
10250 we'll get back to the abstract instance when done with the class. */
10252 /* The class-scope declaration DIE must be the primary DIE. */
10253 if (origin && declaration && class_scope_p (context_die))
10255 origin = NULL;
10256 if (old_die)
10257 abort ();
10260 if (origin != NULL)
10262 if (declaration && ! local_scope_p (context_die))
10263 abort ();
10265 /* Fixup die_parent for the abstract instance of a nested
10266 inline function. */
10267 if (old_die && old_die->die_parent == NULL)
10268 add_child_die (context_die, old_die);
10270 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10271 add_abstract_origin_attribute (subr_die, origin);
10273 else if (old_die)
10275 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10277 if (!get_AT_flag (old_die, DW_AT_declaration)
10278 /* We can have a normal definition following an inline one in the
10279 case of redefinition of GNU C extern inlines.
10280 It seems reasonable to use AT_specification in this case. */
10281 && !get_AT_unsigned (old_die, DW_AT_inline))
10283 /* ??? This can happen if there is a bug in the program, for
10284 instance, if it has duplicate function definitions. Ideally,
10285 we should detect this case and ignore it. For now, if we have
10286 already reported an error, any error at all, then assume that
10287 we got here because of an input error, not a dwarf2 bug. */
10288 if (errorcount)
10289 return;
10290 abort ();
10293 /* If the definition comes from the same place as the declaration,
10294 maybe use the old DIE. We always want the DIE for this function
10295 that has the *_pc attributes to be under comp_unit_die so the
10296 debugger can find it. We also need to do this for abstract
10297 instances of inlines, since the spec requires the out-of-line copy
10298 to have the same parent. For local class methods, this doesn't
10299 apply; we just use the old DIE. */
10300 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
10301 && (DECL_ARTIFICIAL (decl)
10302 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10303 && (get_AT_unsigned (old_die, DW_AT_decl_line)
10304 == (unsigned) DECL_SOURCE_LINE (decl)))))
10306 subr_die = old_die;
10308 /* Clear out the declaration attribute and the parm types. */
10309 remove_AT (subr_die, DW_AT_declaration);
10310 remove_children (subr_die);
10312 else
10314 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10315 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
10316 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10317 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10318 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10319 != (unsigned) DECL_SOURCE_LINE (decl))
10320 add_AT_unsigned
10321 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10324 else
10326 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10328 if (TREE_PUBLIC (decl))
10329 add_AT_flag (subr_die, DW_AT_external, 1);
10331 add_name_and_src_coords_attributes (subr_die, decl);
10332 if (debug_info_level > DINFO_LEVEL_TERSE)
10334 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
10335 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
10336 0, 0, context_die);
10339 add_pure_or_virtual_attribute (subr_die, decl);
10340 if (DECL_ARTIFICIAL (decl))
10341 add_AT_flag (subr_die, DW_AT_artificial, 1);
10343 if (TREE_PROTECTED (decl))
10344 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10345 else if (TREE_PRIVATE (decl))
10346 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
10349 if (declaration)
10351 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10353 add_AT_flag (subr_die, DW_AT_declaration, 1);
10355 /* The first time we see a member function, it is in the context of
10356 the class to which it belongs. We make sure of this by emitting
10357 the class first. The next time is the definition, which is
10358 handled above. The two may come from the same source text. */
10359 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10360 equate_decl_number_to_die (decl, subr_die);
10363 else if (DECL_ABSTRACT (decl))
10365 if (DECL_INLINE (decl) && !flag_no_inline)
10367 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10368 inline functions, but not for extern inline functions.
10369 We can't get this completely correct because information
10370 about whether the function was declared inline is not
10371 saved anywhere. */
10372 if (DECL_DEFER_OUTPUT (decl))
10373 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10374 else
10375 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10377 else
10378 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10380 equate_decl_number_to_die (decl, subr_die);
10382 else if (!DECL_EXTERNAL (decl))
10384 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10385 equate_decl_number_to_die (decl, subr_die);
10387 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10388 current_function_funcdef_no);
10389 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10390 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10391 current_function_funcdef_no);
10392 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10394 add_pubname (decl, subr_die);
10395 add_arange (decl, subr_die);
10397 #ifdef MIPS_DEBUGGING_INFO
10398 /* Add a reference to the FDE for this routine. */
10399 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10400 #endif
10402 /* Define the "frame base" location for this routine. We use the
10403 frame pointer or stack pointer registers, since the RTL for local
10404 variables is relative to one of them. */
10405 fp_reg
10406 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10407 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10409 #if 0
10410 /* ??? This fails for nested inline functions, because context_display
10411 is not part of the state saved/restored for inline functions. */
10412 if (current_function_needs_context)
10413 add_AT_location_description (subr_die, DW_AT_static_link,
10414 loc_descriptor (lookup_static_chain (decl)));
10415 #endif
10418 /* Now output descriptions of the arguments for this function. This gets
10419 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10420 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10421 `...' at the end of the formal parameter list. In order to find out if
10422 there was a trailing ellipsis or not, we must instead look at the type
10423 associated with the FUNCTION_DECL. This will be a node of type
10424 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10425 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10426 an ellipsis at the end. */
10428 /* In the case where we are describing a mere function declaration, all we
10429 need to do here (and all we *can* do here) is to describe the *types* of
10430 its formal parameters. */
10431 if (debug_info_level <= DINFO_LEVEL_TERSE)
10433 else if (declaration)
10434 gen_formal_types_die (decl, subr_die);
10435 else
10437 /* Generate DIEs to represent all known formal parameters */
10438 tree arg_decls = DECL_ARGUMENTS (decl);
10439 tree parm;
10441 /* When generating DIEs, generate the unspecified_parameters DIE
10442 instead if we come across the arg "__builtin_va_alist" */
10443 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10444 if (TREE_CODE (parm) == PARM_DECL)
10446 if (DECL_NAME (parm)
10447 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10448 "__builtin_va_alist"))
10449 gen_unspecified_parameters_die (parm, subr_die);
10450 else
10451 gen_decl_die (parm, subr_die);
10454 /* Decide whether we need an unspecified_parameters DIE at the end.
10455 There are 2 more cases to do this for: 1) the ansi ... declaration -
10456 this is detectable when the end of the arg list is not a
10457 void_type_node 2) an unprototyped function declaration (not a
10458 definition). This just means that we have no info about the
10459 parameters at all. */
10460 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10461 if (fn_arg_types != NULL)
10463 /* this is the prototyped case, check for ... */
10464 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10465 gen_unspecified_parameters_die (decl, subr_die);
10467 else if (DECL_INITIAL (decl) == NULL_TREE)
10468 gen_unspecified_parameters_die (decl, subr_die);
10471 /* Output Dwarf info for all of the stuff within the body of the function
10472 (if it has one - it may be just a declaration). */
10473 outer_scope = DECL_INITIAL (decl);
10475 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10476 a function. This BLOCK actually represents the outermost binding contour
10477 for the function, i.e. the contour in which the function's formal
10478 parameters and labels get declared. Curiously, it appears that the front
10479 end doesn't actually put the PARM_DECL nodes for the current function onto
10480 the BLOCK_VARS list for this outer scope, but are strung off of the
10481 DECL_ARGUMENTS list for the function instead.
10483 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10484 the LABEL_DECL nodes for the function however, and we output DWARF info
10485 for those in decls_for_scope. Just within the `outer_scope' there will be
10486 a BLOCK node representing the function's outermost pair of curly braces,
10487 and any blocks used for the base and member initializers of a C++
10488 constructor function. */
10489 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10491 current_function_has_inlines = 0;
10492 decls_for_scope (outer_scope, subr_die, 0);
10494 #if 0 && defined (MIPS_DEBUGGING_INFO)
10495 if (current_function_has_inlines)
10497 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10498 if (! comp_unit_has_inlines)
10500 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10501 comp_unit_has_inlines = 1;
10504 #endif
10508 /* Generate a DIE to represent a declared data object. */
10510 static void
10511 gen_variable_die (decl, context_die)
10512 tree decl;
10513 dw_die_ref context_die;
10515 tree origin = decl_ultimate_origin (decl);
10516 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
10518 dw_die_ref old_die = lookup_decl_die (decl);
10519 int declaration = (DECL_EXTERNAL (decl)
10520 || class_scope_p (context_die));
10522 if (origin != NULL)
10523 add_abstract_origin_attribute (var_die, origin);
10525 /* Loop unrolling can create multiple blocks that refer to the same
10526 static variable, so we must test for the DW_AT_declaration flag.
10528 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10529 copy decls and set the DECL_ABSTRACT flag on them instead of
10530 sharing them.
10532 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10533 else if (old_die && TREE_STATIC (decl)
10534 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10536 /* This is a definition of a C++ class level static. */
10537 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10538 if (DECL_NAME (decl))
10540 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10542 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10543 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10545 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10546 != (unsigned) DECL_SOURCE_LINE (decl))
10548 add_AT_unsigned (var_die, DW_AT_decl_line,
10549 DECL_SOURCE_LINE (decl));
10552 else
10554 add_name_and_src_coords_attributes (var_die, decl);
10555 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
10556 TREE_THIS_VOLATILE (decl), context_die);
10558 if (TREE_PUBLIC (decl))
10559 add_AT_flag (var_die, DW_AT_external, 1);
10561 if (DECL_ARTIFICIAL (decl))
10562 add_AT_flag (var_die, DW_AT_artificial, 1);
10564 if (TREE_PROTECTED (decl))
10565 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10566 else if (TREE_PRIVATE (decl))
10567 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10570 if (declaration)
10571 add_AT_flag (var_die, DW_AT_declaration, 1);
10573 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10574 equate_decl_number_to_die (decl, var_die);
10576 if (! declaration && ! DECL_ABSTRACT (decl))
10578 add_location_or_const_value_attribute (var_die, decl);
10579 add_pubname (decl, var_die);
10581 else
10582 tree_add_const_value_attribute (var_die, decl);
10585 /* Generate a DIE to represent a label identifier. */
10587 static void
10588 gen_label_die (decl, context_die)
10589 tree decl;
10590 dw_die_ref context_die;
10592 tree origin = decl_ultimate_origin (decl);
10593 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
10594 rtx insn;
10595 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10597 if (origin != NULL)
10598 add_abstract_origin_attribute (lbl_die, origin);
10599 else
10600 add_name_and_src_coords_attributes (lbl_die, decl);
10602 if (DECL_ABSTRACT (decl))
10603 equate_decl_number_to_die (decl, lbl_die);
10604 else
10606 insn = DECL_RTL (decl);
10608 /* Deleted labels are programmer specified labels which have been
10609 eliminated because of various optimisations. We still emit them
10610 here so that it is possible to put breakpoints on them. */
10611 if (GET_CODE (insn) == CODE_LABEL
10612 || ((GET_CODE (insn) == NOTE
10613 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10615 /* When optimization is enabled (via -O) some parts of the compiler
10616 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10617 represent source-level labels which were explicitly declared by
10618 the user. This really shouldn't be happening though, so catch
10619 it if it ever does happen. */
10620 if (INSN_DELETED_P (insn))
10621 abort ();
10623 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10624 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10629 /* Generate a DIE for a lexical block. */
10631 static void
10632 gen_lexical_block_die (stmt, context_die, depth)
10633 tree stmt;
10634 dw_die_ref context_die;
10635 int depth;
10637 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
10638 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10640 if (! BLOCK_ABSTRACT (stmt))
10642 if (BLOCK_FRAGMENT_CHAIN (stmt))
10644 tree chain;
10646 add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt));
10648 chain = BLOCK_FRAGMENT_CHAIN (stmt);
10651 add_ranges (chain);
10652 chain = BLOCK_FRAGMENT_CHAIN (chain);
10654 while (chain);
10655 add_ranges (NULL);
10657 else
10659 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10660 BLOCK_NUMBER (stmt));
10661 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10662 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10663 BLOCK_NUMBER (stmt));
10664 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10668 decls_for_scope (stmt, stmt_die, depth);
10671 /* Generate a DIE for an inlined subprogram. */
10673 static void
10674 gen_inlined_subroutine_die (stmt, context_die, depth)
10675 tree stmt;
10676 dw_die_ref context_die;
10677 int depth;
10679 if (! BLOCK_ABSTRACT (stmt))
10681 dw_die_ref subr_die
10682 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
10683 tree decl = block_ultimate_origin (stmt);
10684 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10686 /* Emit info for the abstract instance first, if we haven't yet. */
10687 dwarf2out_abstract_function (decl);
10689 add_abstract_origin_attribute (subr_die, decl);
10690 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10691 BLOCK_NUMBER (stmt));
10692 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10693 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10694 BLOCK_NUMBER (stmt));
10695 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10696 decls_for_scope (stmt, subr_die, depth);
10697 current_function_has_inlines = 1;
10699 else
10700 /* We may get here if we're the outer block of function A that was
10701 inlined into function B that was inlined into function C. When
10702 generating debugging info for C, dwarf2out_abstract_function(B)
10703 would mark all inlined blocks as abstract, including this one.
10704 So, we wouldn't (and shouldn't) expect labels to be generated
10705 for this one. Instead, just emit debugging info for
10706 declarations within the block. This is particularly important
10707 in the case of initializers of arguments passed from B to us:
10708 if they're statement expressions containing declarations, we
10709 wouldn't generate dies for their abstract variables, and then,
10710 when generating dies for the real variables, we'd die (pun
10711 intended :-) */
10712 gen_lexical_block_die (stmt, context_die, depth);
10715 /* Generate a DIE for a field in a record, or structure. */
10717 static void
10718 gen_field_die (decl, context_die)
10719 tree decl;
10720 dw_die_ref context_die;
10722 dw_die_ref decl_die = new_die (DW_TAG_member, context_die, decl);
10724 add_name_and_src_coords_attributes (decl_die, decl);
10725 add_type_attribute (decl_die, member_declared_type (decl),
10726 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10727 context_die);
10729 if (DECL_BIT_FIELD_TYPE (decl))
10731 add_byte_size_attribute (decl_die, decl);
10732 add_bit_size_attribute (decl_die, decl);
10733 add_bit_offset_attribute (decl_die, decl);
10736 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10737 add_data_member_location_attribute (decl_die, decl);
10739 if (DECL_ARTIFICIAL (decl))
10740 add_AT_flag (decl_die, DW_AT_artificial, 1);
10742 if (TREE_PROTECTED (decl))
10743 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10744 else if (TREE_PRIVATE (decl))
10745 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10748 #if 0
10749 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10750 Use modified_type_die instead.
10751 We keep this code here just in case these types of DIEs may be needed to
10752 represent certain things in other languages (e.g. Pascal) someday. */
10754 static void
10755 gen_pointer_type_die (type, context_die)
10756 tree type;
10757 dw_die_ref context_die;
10759 dw_die_ref ptr_die
10760 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
10762 equate_type_number_to_die (type, ptr_die);
10763 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10764 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10767 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10768 Use modified_type_die instead.
10769 We keep this code here just in case these types of DIEs may be needed to
10770 represent certain things in other languages (e.g. Pascal) someday. */
10772 static void
10773 gen_reference_type_die (type, context_die)
10774 tree type;
10775 dw_die_ref context_die;
10777 dw_die_ref ref_die
10778 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
10780 equate_type_number_to_die (type, ref_die);
10781 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10782 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10784 #endif
10786 /* Generate a DIE for a pointer to a member type. */
10788 static void
10789 gen_ptr_to_mbr_type_die (type, context_die)
10790 tree type;
10791 dw_die_ref context_die;
10793 dw_die_ref ptr_die
10794 = new_die (DW_TAG_ptr_to_member_type,
10795 scope_die_for (type, context_die), type);
10797 equate_type_number_to_die (type, ptr_die);
10798 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10799 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10800 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10803 /* Generate the DIE for the compilation unit. */
10805 static dw_die_ref
10806 gen_compile_unit_die (filename)
10807 const char *filename;
10809 dw_die_ref die;
10810 char producer[250];
10811 const char *wd = getpwd ();
10812 const char *language_string = lang_hooks.name;
10813 int language;
10815 die = new_die (DW_TAG_compile_unit, NULL, NULL);
10816 add_name_attribute (die, filename);
10818 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10819 add_AT_string (die, DW_AT_comp_dir, wd);
10821 sprintf (producer, "%s %s", language_string, version_string);
10823 #ifdef MIPS_DEBUGGING_INFO
10824 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10825 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10826 not appear in the producer string, the debugger reaches the conclusion
10827 that the object file is stripped and has no debugging information.
10828 To get the MIPS/SGI debugger to believe that there is debugging
10829 information in the object file, we add a -g to the producer string. */
10830 if (debug_info_level > DINFO_LEVEL_TERSE)
10831 strcat (producer, " -g");
10832 #endif
10834 add_AT_string (die, DW_AT_producer, producer);
10836 if (strcmp (language_string, "GNU C++") == 0)
10837 language = DW_LANG_C_plus_plus;
10838 else if (strcmp (language_string, "GNU Ada") == 0)
10839 language = DW_LANG_Ada83;
10840 else if (strcmp (language_string, "GNU F77") == 0)
10841 language = DW_LANG_Fortran77;
10842 else if (strcmp (language_string, "GNU Pascal") == 0)
10843 language = DW_LANG_Pascal83;
10844 else if (strcmp (language_string, "GNU Java") == 0)
10845 language = DW_LANG_Java;
10846 else
10847 language = DW_LANG_C89;
10849 add_AT_unsigned (die, DW_AT_language, language);
10850 return die;
10853 /* Generate a DIE for a string type. */
10855 static void
10856 gen_string_type_die (type, context_die)
10857 tree type;
10858 dw_die_ref context_die;
10860 dw_die_ref type_die
10861 = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type);
10863 equate_type_number_to_die (type, type_die);
10865 /* ??? Fudge the string length attribute for now.
10866 TODO: add string length info. */
10867 #if 0
10868 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10869 bound_representation (upper_bound, 0, 'u');
10870 #endif
10873 /* Generate the DIE for a base class. */
10875 static void
10876 gen_inheritance_die (binfo, context_die)
10877 tree binfo;
10878 dw_die_ref context_die;
10880 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
10882 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10883 add_data_member_location_attribute (die, binfo);
10885 if (TREE_VIA_VIRTUAL (binfo))
10886 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10888 if (TREE_VIA_PUBLIC (binfo))
10889 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10890 else if (TREE_VIA_PROTECTED (binfo))
10891 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10894 /* Generate a DIE for a class member. */
10896 static void
10897 gen_member_die (type, context_die)
10898 tree type;
10899 dw_die_ref context_die;
10901 tree member;
10902 dw_die_ref child;
10904 /* If this is not an incomplete type, output descriptions of each of its
10905 members. Note that as we output the DIEs necessary to represent the
10906 members of this record or union type, we will also be trying to output
10907 DIEs to represent the *types* of those members. However the `type'
10908 function (above) will specifically avoid generating type DIEs for member
10909 types *within* the list of member DIEs for this (containing) type except
10910 for those types (of members) which are explicitly marked as also being
10911 members of this (containing) type themselves. The g++ front- end can
10912 force any given type to be treated as a member of some other (containing)
10913 type by setting the TYPE_CONTEXT of the given (member) type to point to
10914 the TREE node representing the appropriate (containing) type. */
10916 /* First output info about the base classes. */
10917 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10919 tree bases = TYPE_BINFO_BASETYPES (type);
10920 int n_bases = TREE_VEC_LENGTH (bases);
10921 int i;
10923 for (i = 0; i < n_bases; i++)
10924 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10927 /* Now output info about the data members and type members. */
10928 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10930 /* If we thought we were generating minimal debug info for TYPE
10931 and then changed our minds, some of the member declarations
10932 may have already been defined. Don't define them again, but
10933 do put them in the right order. */
10935 child = lookup_decl_die (member);
10936 if (child)
10937 splice_child_die (context_die, child);
10938 else
10939 gen_decl_die (member, context_die);
10942 /* Now output info about the function members (if any). */
10943 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10945 /* Don't include clones in the member list. */
10946 if (DECL_ABSTRACT_ORIGIN (member))
10947 continue;
10949 child = lookup_decl_die (member);
10950 if (child)
10951 splice_child_die (context_die, child);
10952 else
10953 gen_decl_die (member, context_die);
10957 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10958 is set, we pretend that the type was never defined, so we only get the
10959 member DIEs needed by later specification DIEs. */
10961 static void
10962 gen_struct_or_union_type_die (type, context_die)
10963 tree type;
10964 dw_die_ref context_die;
10966 dw_die_ref type_die = lookup_type_die (type);
10967 dw_die_ref scope_die = 0;
10968 int nested = 0;
10969 int complete = (TYPE_SIZE (type)
10970 && (! TYPE_STUB_DECL (type)
10971 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10973 if (type_die && ! complete)
10974 return;
10976 if (TYPE_CONTEXT (type) != NULL_TREE
10977 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10978 nested = 1;
10980 scope_die = scope_die_for (type, context_die);
10982 if (! type_die || (nested && scope_die == comp_unit_die))
10983 /* First occurrence of type or toplevel definition of nested class. */
10985 dw_die_ref old_die = type_die;
10987 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10988 ? DW_TAG_structure_type : DW_TAG_union_type,
10989 scope_die, type);
10990 equate_type_number_to_die (type, type_die);
10991 if (old_die)
10992 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10993 else
10994 add_name_attribute (type_die, type_tag (type));
10996 else
10997 remove_AT (type_die, DW_AT_declaration);
10999 /* If this type has been completed, then give it a byte_size attribute and
11000 then give a list of members. */
11001 if (complete)
11003 /* Prevent infinite recursion in cases where the type of some member of
11004 this type is expressed in terms of this type itself. */
11005 TREE_ASM_WRITTEN (type) = 1;
11006 add_byte_size_attribute (type_die, type);
11007 if (TYPE_STUB_DECL (type) != NULL_TREE)
11008 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
11010 /* If the first reference to this type was as the return type of an
11011 inline function, then it may not have a parent. Fix this now. */
11012 if (type_die->die_parent == NULL)
11013 add_child_die (scope_die, type_die);
11015 push_decl_scope (type);
11016 gen_member_die (type, type_die);
11017 pop_decl_scope ();
11019 /* GNU extension: Record what type our vtable lives in. */
11020 if (TYPE_VFIELD (type))
11022 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
11024 gen_type_die (vtype, context_die);
11025 add_AT_die_ref (type_die, DW_AT_containing_type,
11026 lookup_type_die (vtype));
11029 else
11031 add_AT_flag (type_die, DW_AT_declaration, 1);
11033 /* We don't need to do this for function-local types. */
11034 if (TYPE_STUB_DECL (type)
11035 && ! decl_function_context (TYPE_STUB_DECL (type)))
11036 VARRAY_PUSH_TREE (incomplete_types, type);
11040 /* Generate a DIE for a subroutine _type_. */
11042 static void
11043 gen_subroutine_type_die (type, context_die)
11044 tree type;
11045 dw_die_ref context_die;
11047 tree return_type = TREE_TYPE (type);
11048 dw_die_ref subr_die
11049 = new_die (DW_TAG_subroutine_type,
11050 scope_die_for (type, context_die), type);
11052 equate_type_number_to_die (type, subr_die);
11053 add_prototyped_attribute (subr_die, type);
11054 add_type_attribute (subr_die, return_type, 0, 0, context_die);
11055 gen_formal_types_die (type, subr_die);
11058 /* Generate a DIE for a type definition */
11060 static void
11061 gen_typedef_die (decl, context_die)
11062 tree decl;
11063 dw_die_ref context_die;
11065 dw_die_ref type_die;
11066 tree origin;
11068 if (TREE_ASM_WRITTEN (decl))
11069 return;
11071 TREE_ASM_WRITTEN (decl) = 1;
11072 type_die = new_die (DW_TAG_typedef, context_die, decl);
11073 origin = decl_ultimate_origin (decl);
11074 if (origin != NULL)
11075 add_abstract_origin_attribute (type_die, origin);
11076 else
11078 tree type;
11080 add_name_and_src_coords_attributes (type_die, decl);
11081 if (DECL_ORIGINAL_TYPE (decl))
11083 type = DECL_ORIGINAL_TYPE (decl);
11085 if (type == TREE_TYPE (decl))
11086 abort ();
11087 else
11088 equate_type_number_to_die (TREE_TYPE (decl), type_die);
11090 else
11091 type = TREE_TYPE (decl);
11093 add_type_attribute (type_die, type, TREE_READONLY (decl),
11094 TREE_THIS_VOLATILE (decl), context_die);
11097 if (DECL_ABSTRACT (decl))
11098 equate_decl_number_to_die (decl, type_die);
11101 /* Generate a type description DIE. */
11103 static void
11104 gen_type_die (type, context_die)
11105 tree type;
11106 dw_die_ref context_die;
11108 int need_pop;
11110 if (type == NULL_TREE || type == error_mark_node)
11111 return;
11113 /* We are going to output a DIE to represent the unqualified version
11114 of this type (i.e. without any const or volatile qualifiers) so
11115 get the main variant (i.e. the unqualified version) of this type
11116 now. (Vectors are special because the debugging info is in the
11117 cloned type itself). */
11118 if (TREE_CODE (type) != VECTOR_TYPE)
11119 type = type_main_variant (type);
11121 if (TREE_ASM_WRITTEN (type))
11122 return;
11124 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
11125 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
11127 /* Prevent broken recursion; we can't hand off to the same type. */
11128 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) == type)
11129 abort ();
11131 TREE_ASM_WRITTEN (type) = 1;
11132 gen_decl_die (TYPE_NAME (type), context_die);
11133 return;
11136 switch (TREE_CODE (type))
11138 case ERROR_MARK:
11139 break;
11141 case POINTER_TYPE:
11142 case REFERENCE_TYPE:
11143 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
11144 ensures that the gen_type_die recursion will terminate even if the
11145 type is recursive. Recursive types are possible in Ada. */
11146 /* ??? We could perhaps do this for all types before the switch
11147 statement. */
11148 TREE_ASM_WRITTEN (type) = 1;
11150 /* For these types, all that is required is that we output a DIE (or a
11151 set of DIEs) to represent the "basis" type. */
11152 gen_type_die (TREE_TYPE (type), context_die);
11153 break;
11155 case OFFSET_TYPE:
11156 /* This code is used for C++ pointer-to-data-member types.
11157 Output a description of the relevant class type. */
11158 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
11160 /* Output a description of the type of the object pointed to. */
11161 gen_type_die (TREE_TYPE (type), context_die);
11163 /* Now output a DIE to represent this pointer-to-data-member type
11164 itself. */
11165 gen_ptr_to_mbr_type_die (type, context_die);
11166 break;
11168 case SET_TYPE:
11169 gen_type_die (TYPE_DOMAIN (type), context_die);
11170 gen_set_type_die (type, context_die);
11171 break;
11173 case FILE_TYPE:
11174 gen_type_die (TREE_TYPE (type), context_die);
11175 abort (); /* No way to represent these in Dwarf yet! */
11176 break;
11178 case FUNCTION_TYPE:
11179 /* Force out return type (in case it wasn't forced out already). */
11180 gen_type_die (TREE_TYPE (type), context_die);
11181 gen_subroutine_type_die (type, context_die);
11182 break;
11184 case METHOD_TYPE:
11185 /* Force out return type (in case it wasn't forced out already). */
11186 gen_type_die (TREE_TYPE (type), context_die);
11187 gen_subroutine_type_die (type, context_die);
11188 break;
11190 case ARRAY_TYPE:
11191 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
11193 gen_type_die (TREE_TYPE (type), context_die);
11194 gen_string_type_die (type, context_die);
11196 else
11197 gen_array_type_die (type, context_die);
11198 break;
11200 case VECTOR_TYPE:
11201 gen_array_type_die (type, context_die);
11202 break;
11204 case ENUMERAL_TYPE:
11205 case RECORD_TYPE:
11206 case UNION_TYPE:
11207 case QUAL_UNION_TYPE:
11208 /* If this is a nested type whose containing class hasn't been written
11209 out yet, writing it out will cover this one, too. This does not apply
11210 to instantiations of member class templates; they need to be added to
11211 the containing class as they are generated. FIXME: This hurts the
11212 idea of combining type decls from multiple TUs, since we can't predict
11213 what set of template instantiations we'll get. */
11214 if (TYPE_CONTEXT (type)
11215 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
11216 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
11218 gen_type_die (TYPE_CONTEXT (type), context_die);
11220 if (TREE_ASM_WRITTEN (type))
11221 return;
11223 /* If that failed, attach ourselves to the stub. */
11224 push_decl_scope (TYPE_CONTEXT (type));
11225 context_die = lookup_type_die (TYPE_CONTEXT (type));
11226 need_pop = 1;
11228 else
11229 need_pop = 0;
11231 if (TREE_CODE (type) == ENUMERAL_TYPE)
11232 gen_enumeration_type_die (type, context_die);
11233 else
11234 gen_struct_or_union_type_die (type, context_die);
11236 if (need_pop)
11237 pop_decl_scope ();
11239 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11240 it up if it is ever completed. gen_*_type_die will set it for us
11241 when appropriate. */
11242 return;
11244 case VOID_TYPE:
11245 case INTEGER_TYPE:
11246 case REAL_TYPE:
11247 case COMPLEX_TYPE:
11248 case BOOLEAN_TYPE:
11249 case CHAR_TYPE:
11250 /* No DIEs needed for fundamental types. */
11251 break;
11253 case LANG_TYPE:
11254 /* No Dwarf representation currently defined. */
11255 break;
11257 default:
11258 abort ();
11261 TREE_ASM_WRITTEN (type) = 1;
11264 /* Generate a DIE for a tagged type instantiation. */
11266 static void
11267 gen_tagged_type_instantiation_die (type, context_die)
11268 tree type;
11269 dw_die_ref context_die;
11271 if (type == NULL_TREE || type == error_mark_node)
11272 return;
11274 /* We are going to output a DIE to represent the unqualified version of
11275 this type (i.e. without any const or volatile qualifiers) so make sure
11276 that we have the main variant (i.e. the unqualified version) of this
11277 type now. */
11278 if (type != type_main_variant (type))
11279 abort ();
11281 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11282 an instance of an unresolved type. */
11284 switch (TREE_CODE (type))
11286 case ERROR_MARK:
11287 break;
11289 case ENUMERAL_TYPE:
11290 gen_inlined_enumeration_type_die (type, context_die);
11291 break;
11293 case RECORD_TYPE:
11294 gen_inlined_structure_type_die (type, context_die);
11295 break;
11297 case UNION_TYPE:
11298 case QUAL_UNION_TYPE:
11299 gen_inlined_union_type_die (type, context_die);
11300 break;
11302 default:
11303 abort ();
11307 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11308 things which are local to the given block. */
11310 static void
11311 gen_block_die (stmt, context_die, depth)
11312 tree stmt;
11313 dw_die_ref context_die;
11314 int depth;
11316 int must_output_die = 0;
11317 tree origin;
11318 tree decl;
11319 enum tree_code origin_code;
11321 /* Ignore blocks never really used to make RTL. */
11322 if (stmt == NULL_TREE || !TREE_USED (stmt)
11323 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
11324 return;
11326 /* If the block is one fragment of a non-contiguous block, do not
11327 process the variables, since they will have been done by the
11328 origin block. Do process subblocks. */
11329 if (BLOCK_FRAGMENT_ORIGIN (stmt))
11331 tree sub;
11333 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
11334 gen_block_die (sub, context_die, depth + 1);
11336 return;
11339 /* Determine the "ultimate origin" of this block. This block may be an
11340 inlined instance of an inlined instance of inline function, so we have
11341 to trace all of the way back through the origin chain to find out what
11342 sort of node actually served as the original seed for the creation of
11343 the current block. */
11344 origin = block_ultimate_origin (stmt);
11345 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11347 /* Determine if we need to output any Dwarf DIEs at all to represent this
11348 block. */
11349 if (origin_code == FUNCTION_DECL)
11350 /* The outer scopes for inlinings *must* always be represented. We
11351 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11352 must_output_die = 1;
11353 else
11355 /* In the case where the current block represents an inlining of the
11356 "body block" of an inline function, we must *NOT* output any DIE for
11357 this block because we have already output a DIE to represent the whole
11358 inlined function scope and the "body block" of any function doesn't
11359 really represent a different scope according to ANSI C rules. So we
11360 check here to make sure that this block does not represent a "body
11361 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11362 if (! is_body_block (origin ? origin : stmt))
11364 /* Determine if this block directly contains any "significant"
11365 local declarations which we will need to output DIEs for. */
11366 if (debug_info_level > DINFO_LEVEL_TERSE)
11367 /* We are not in terse mode so *any* local declaration counts
11368 as being a "significant" one. */
11369 must_output_die = (BLOCK_VARS (stmt) != NULL);
11370 else
11371 /* We are in terse mode, so only local (nested) function
11372 definitions count as "significant" local declarations. */
11373 for (decl = BLOCK_VARS (stmt);
11374 decl != NULL; decl = TREE_CHAIN (decl))
11375 if (TREE_CODE (decl) == FUNCTION_DECL
11376 && DECL_INITIAL (decl))
11378 must_output_die = 1;
11379 break;
11384 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11385 DIE for any block which contains no significant local declarations at
11386 all. Rather, in such cases we just call `decls_for_scope' so that any
11387 needed Dwarf info for any sub-blocks will get properly generated. Note
11388 that in terse mode, our definition of what constitutes a "significant"
11389 local declaration gets restricted to include only inlined function
11390 instances and local (nested) function definitions. */
11391 if (must_output_die)
11393 if (origin_code == FUNCTION_DECL)
11394 gen_inlined_subroutine_die (stmt, context_die, depth);
11395 else
11396 gen_lexical_block_die (stmt, context_die, depth);
11398 else
11399 decls_for_scope (stmt, context_die, depth);
11402 /* Generate all of the decls declared within a given scope and (recursively)
11403 all of its sub-blocks. */
11405 static void
11406 decls_for_scope (stmt, context_die, depth)
11407 tree stmt;
11408 dw_die_ref context_die;
11409 int depth;
11411 tree decl;
11412 tree subblocks;
11414 /* Ignore blocks never really used to make RTL. */
11415 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11416 return;
11418 /* Output the DIEs to represent all of the data objects and typedefs
11419 declared directly within this block but not within any nested
11420 sub-blocks. Also, nested function and tag DIEs have been
11421 generated with a parent of NULL; fix that up now. */
11422 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
11424 dw_die_ref die;
11426 if (TREE_CODE (decl) == FUNCTION_DECL)
11427 die = lookup_decl_die (decl);
11428 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11429 die = lookup_type_die (TREE_TYPE (decl));
11430 else
11431 die = NULL;
11433 if (die != NULL && die->die_parent == NULL)
11434 add_child_die (context_die, die);
11435 else
11436 gen_decl_die (decl, context_die);
11439 /* Output the DIEs to represent all sub-blocks (and the items declared
11440 therein) of this block. */
11441 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11442 subblocks != NULL;
11443 subblocks = BLOCK_CHAIN (subblocks))
11444 gen_block_die (subblocks, context_die, depth + 1);
11447 /* Is this a typedef we can avoid emitting? */
11449 static inline int
11450 is_redundant_typedef (decl)
11451 tree decl;
11453 if (TYPE_DECL_IS_STUB (decl))
11454 return 1;
11456 if (DECL_ARTIFICIAL (decl)
11457 && DECL_CONTEXT (decl)
11458 && is_tagged_type (DECL_CONTEXT (decl))
11459 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11460 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11461 /* Also ignore the artificial member typedef for the class name. */
11462 return 1;
11464 return 0;
11467 /* Generate Dwarf debug information for a decl described by DECL. */
11469 static void
11470 gen_decl_die (decl, context_die)
11471 tree decl;
11472 dw_die_ref context_die;
11474 tree origin;
11476 if (DECL_P (decl) && DECL_IGNORED_P (decl))
11477 return;
11479 switch (TREE_CODE (decl))
11481 case ERROR_MARK:
11482 break;
11484 case CONST_DECL:
11485 /* The individual enumerators of an enum type get output when we output
11486 the Dwarf representation of the relevant enum type itself. */
11487 break;
11489 case FUNCTION_DECL:
11490 /* Don't output any DIEs to represent mere function declarations,
11491 unless they are class members or explicit block externs. */
11492 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11493 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11494 break;
11496 /* If we're emitting a clone, emit info for the abstract instance. */
11497 if (DECL_ORIGIN (decl) != decl)
11498 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
11500 /* If we're emitting an out-of-line copy of an inline function,
11501 emit info for the abstract instance and set up to refer to it. */
11502 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11503 && ! class_scope_p (context_die)
11504 /* dwarf2out_abstract_function won't emit a die if this is just
11505 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11506 that case, because that works only if we have a die. */
11507 && DECL_INITIAL (decl) != NULL_TREE)
11509 dwarf2out_abstract_function (decl);
11510 set_decl_origin_self (decl);
11513 /* Otherwise we're emitting the primary DIE for this decl. */
11514 else if (debug_info_level > DINFO_LEVEL_TERSE)
11516 /* Before we describe the FUNCTION_DECL itself, make sure that we
11517 have described its return type. */
11518 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11520 /* And its virtual context. */
11521 if (DECL_VINDEX (decl) != NULL_TREE)
11522 gen_type_die (DECL_CONTEXT (decl), context_die);
11524 /* And its containing type. */
11525 origin = decl_class_context (decl);
11526 if (origin != NULL_TREE)
11527 gen_type_die_for_member (origin, decl, context_die);
11530 /* Now output a DIE to represent the function itself. */
11531 gen_subprogram_die (decl, context_die);
11532 break;
11534 case TYPE_DECL:
11535 /* If we are in terse mode, don't generate any DIEs to represent any
11536 actual typedefs. */
11537 if (debug_info_level <= DINFO_LEVEL_TERSE)
11538 break;
11540 /* In the special case of a TYPE_DECL node representing the declaration
11541 of some type tag, if the given TYPE_DECL is marked as having been
11542 instantiated from some other (original) TYPE_DECL node (e.g. one which
11543 was generated within the original definition of an inline function) we
11544 have to generate a special (abbreviated) DW_TAG_structure_type,
11545 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11546 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11548 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11549 break;
11552 if (is_redundant_typedef (decl))
11553 gen_type_die (TREE_TYPE (decl), context_die);
11554 else
11555 /* Output a DIE to represent the typedef itself. */
11556 gen_typedef_die (decl, context_die);
11557 break;
11559 case LABEL_DECL:
11560 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11561 gen_label_die (decl, context_die);
11562 break;
11564 case VAR_DECL:
11565 /* If we are in terse mode, don't generate any DIEs to represent any
11566 variable declarations or definitions. */
11567 if (debug_info_level <= DINFO_LEVEL_TERSE)
11568 break;
11570 /* Output any DIEs that are needed to specify the type of this data
11571 object. */
11572 gen_type_die (TREE_TYPE (decl), context_die);
11574 /* And its containing type. */
11575 origin = decl_class_context (decl);
11576 if (origin != NULL_TREE)
11577 gen_type_die_for_member (origin, decl, context_die);
11579 /* Now output the DIE to represent the data object itself. This gets
11580 complicated because of the possibility that the VAR_DECL really
11581 represents an inlined instance of a formal parameter for an inline
11582 function. */
11583 origin = decl_ultimate_origin (decl);
11584 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11585 gen_formal_parameter_die (decl, context_die);
11586 else
11587 gen_variable_die (decl, context_die);
11588 break;
11590 case FIELD_DECL:
11591 /* Ignore the nameless fields that are used to skip bits but handle C++
11592 anonymous unions. */
11593 if (DECL_NAME (decl) != NULL_TREE
11594 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11596 gen_type_die (member_declared_type (decl), context_die);
11597 gen_field_die (decl, context_die);
11599 break;
11601 case PARM_DECL:
11602 gen_type_die (TREE_TYPE (decl), context_die);
11603 gen_formal_parameter_die (decl, context_die);
11604 break;
11606 case NAMESPACE_DECL:
11607 /* Ignore for now. */
11608 break;
11610 default:
11611 abort ();
11615 static void
11616 mark_limbo_die_list (ptr)
11617 void *ptr ATTRIBUTE_UNUSED;
11619 limbo_die_node *node;
11620 for (node = limbo_die_list; node; node = node->next)
11621 ggc_mark_tree (node->created_for);
11624 /* Add Ada "use" clause information for SGI Workshop debugger. */
11626 void
11627 dwarf2out_add_library_unit_info (filename, context_list)
11628 const char *filename;
11629 const char *context_list;
11631 unsigned int file_index;
11633 if (filename != NULL)
11635 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL);
11636 tree context_list_decl
11637 = build_decl (LABEL_DECL, get_identifier (context_list),
11638 void_type_node);
11640 TREE_PUBLIC (context_list_decl) = TRUE;
11641 add_name_attribute (unit_die, context_list);
11642 file_index = lookup_filename (filename);
11643 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11644 add_pubname (context_list_decl, unit_die);
11648 /* Output debug information for global decl DECL. Called from toplev.c after
11649 compilation proper has finished. */
11651 static void
11652 dwarf2out_global_decl (decl)
11653 tree decl;
11655 /* Output DWARF2 information for file-scope tentative data object
11656 declarations, file-scope (extern) function declarations (which had no
11657 corresponding body) and file-scope tagged type declarations and
11658 definitions which have not yet been forced out. */
11659 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
11660 dwarf2out_decl (decl);
11663 /* Write the debugging output for DECL. */
11665 void
11666 dwarf2out_decl (decl)
11667 tree decl;
11669 dw_die_ref context_die = comp_unit_die;
11671 switch (TREE_CODE (decl))
11673 case ERROR_MARK:
11674 return;
11676 case FUNCTION_DECL:
11677 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11678 builtin function. Explicit programmer-supplied declarations of
11679 these same functions should NOT be ignored however. */
11680 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11681 return;
11683 /* What we would really like to do here is to filter out all mere
11684 file-scope declarations of file-scope functions which are never
11685 referenced later within this translation unit (and keep all of ones
11686 that *are* referenced later on) but we aren't clairvoyant, so we have
11687 no idea which functions will be referenced in the future (i.e. later
11688 on within the current translation unit). So here we just ignore all
11689 file-scope function declarations which are not also definitions. If
11690 and when the debugger needs to know something about these functions,
11691 it will have to hunt around and find the DWARF information associated
11692 with the definition of the function.
11694 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11695 nodes represent definitions and which ones represent mere
11696 declarations. We have to check DECL_INITIAL instead. That's because
11697 the C front-end supports some weird semantics for "extern inline"
11698 function definitions. These can get inlined within the current
11699 translation unit (an thus, we need to generate Dwarf info for their
11700 abstract instances so that the Dwarf info for the concrete inlined
11701 instances can have something to refer to) but the compiler never
11702 generates any out-of-lines instances of such things (despite the fact
11703 that they *are* definitions).
11705 The important point is that the C front-end marks these "extern
11706 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11707 them anyway. Note that the C++ front-end also plays some similar games
11708 for inline function definitions appearing within include files which
11709 also contain `#pragma interface' pragmas. */
11710 if (DECL_INITIAL (decl) == NULL_TREE)
11711 return;
11713 /* If we're a nested function, initially use a parent of NULL; if we're
11714 a plain function, this will be fixed up in decls_for_scope. If
11715 we're a method, it will be ignored, since we already have a DIE. */
11716 if (decl_function_context (decl))
11717 context_die = NULL;
11718 break;
11720 case VAR_DECL:
11721 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11722 declaration and if the declaration was never even referenced from
11723 within this entire compilation unit. We suppress these DIEs in
11724 order to save space in the .debug section (by eliminating entries
11725 which are probably useless). Note that we must not suppress
11726 block-local extern declarations (whether used or not) because that
11727 would screw-up the debugger's name lookup mechanism and cause it to
11728 miss things which really ought to be in scope at a given point. */
11729 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11730 return;
11732 /* If we are in terse mode, don't generate any DIEs to represent any
11733 variable declarations or definitions. */
11734 if (debug_info_level <= DINFO_LEVEL_TERSE)
11735 return;
11736 break;
11738 case TYPE_DECL:
11739 /* Don't emit stubs for types unless they are needed by other DIEs. */
11740 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11741 return;
11743 /* Don't bother trying to generate any DIEs to represent any of the
11744 normal built-in types for the language we are compiling. */
11745 if (DECL_SOURCE_LINE (decl) == 0)
11747 /* OK, we need to generate one for `bool' so GDB knows what type
11748 comparisons have. */
11749 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11750 == DW_LANG_C_plus_plus)
11751 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
11752 && ! DECL_IGNORED_P (decl))
11753 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11755 return;
11758 /* If we are in terse mode, don't generate any DIEs for types. */
11759 if (debug_info_level <= DINFO_LEVEL_TERSE)
11760 return;
11762 /* If we're a function-scope tag, initially use a parent of NULL;
11763 this will be fixed up in decls_for_scope. */
11764 if (decl_function_context (decl))
11765 context_die = NULL;
11767 break;
11769 default:
11770 return;
11773 gen_decl_die (decl, context_die);
11776 /* Output a marker (i.e. a label) for the beginning of the generated code for
11777 a lexical block. */
11779 static void
11780 dwarf2out_begin_block (line, blocknum)
11781 unsigned int line ATTRIBUTE_UNUSED;
11782 unsigned int blocknum;
11784 function_section (current_function_decl);
11785 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11788 /* Output a marker (i.e. a label) for the end of the generated code for a
11789 lexical block. */
11791 static void
11792 dwarf2out_end_block (line, blocknum)
11793 unsigned int line ATTRIBUTE_UNUSED;
11794 unsigned int blocknum;
11796 function_section (current_function_decl);
11797 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11800 /* Returns nonzero if it is appropriate not to emit any debugging
11801 information for BLOCK, because it doesn't contain any instructions.
11803 Don't allow this for blocks with nested functions or local classes
11804 as we would end up with orphans, and in the presence of scheduling
11805 we may end up calling them anyway. */
11807 static bool
11808 dwarf2out_ignore_block (block)
11809 tree block;
11811 tree decl;
11813 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11814 if (TREE_CODE (decl) == FUNCTION_DECL
11815 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11816 return 0;
11818 return 1;
11821 /* Lookup FILE_NAME (in the list of filenames that we know about here in
11822 dwarf2out.c) and return its "index". The index of each (known) filename is
11823 just a unique number which is associated with only that one filename. We
11824 need such numbers for the sake of generating labels (in the .debug_sfnames
11825 section) and references to those files numbers (in the .debug_srcinfo
11826 and.debug_macinfo sections). If the filename given as an argument is not
11827 found in our current list, add it to the list and assign it the next
11828 available unique index number. In order to speed up searches, we remember
11829 the index of the filename was looked up last. This handles the majority of
11830 all searches. */
11832 static unsigned
11833 lookup_filename (file_name)
11834 const char *file_name;
11836 unsigned i;
11838 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11839 if (strcmp (file_name, "<internal>") == 0
11840 || strcmp (file_name, "<built-in>") == 0)
11841 return 0;
11843 /* Check to see if the file name that was searched on the previous
11844 call matches this file name. If so, return the index. */
11845 if (file_table.last_lookup_index != 0)
11846 if (0 == strcmp (file_name,
11847 file_table.table[file_table.last_lookup_index]))
11848 return file_table.last_lookup_index;
11850 /* Didn't match the previous lookup, search the table */
11851 for (i = 1; i < file_table.in_use; i++)
11852 if (strcmp (file_name, file_table.table[i]) == 0)
11854 file_table.last_lookup_index = i;
11855 return i;
11858 /* Prepare to add a new table entry by making sure there is enough space in
11859 the table to do so. If not, expand the current table. */
11860 if (i == file_table.allocated)
11862 file_table.allocated = i + FILE_TABLE_INCREMENT;
11863 file_table.table = (char **)
11864 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11867 /* Add the new entry to the end of the filename table. */
11868 file_table.table[i] = xstrdup (file_name);
11869 file_table.in_use = i + 1;
11870 file_table.last_lookup_index = i;
11872 if (DWARF2_ASM_LINE_DEBUG_INFO)
11874 fprintf (asm_out_file, "\t.file %u ", i);
11875 output_quoted_string (asm_out_file, file_name);
11876 fputc ('\n', asm_out_file);
11879 return i;
11882 static void
11883 init_file_table ()
11885 /* Allocate the initial hunk of the file_table. */
11886 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11887 file_table.allocated = FILE_TABLE_INCREMENT;
11889 /* Skip the first entry - file numbers begin at 1. */
11890 file_table.in_use = 1;
11891 file_table.last_lookup_index = 0;
11894 /* Output a label to mark the beginning of a source code line entry
11895 and record information relating to this source line, in
11896 'line_info_table' for later output of the .debug_line section. */
11898 static void
11899 dwarf2out_source_line (line, filename)
11900 unsigned int line;
11901 const char *filename;
11903 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11905 function_section (current_function_decl);
11907 /* If requested, emit something human-readable. */
11908 if (flag_debug_asm)
11909 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11910 filename, line);
11912 if (DWARF2_ASM_LINE_DEBUG_INFO)
11914 unsigned file_num = lookup_filename (filename);
11916 /* Emit the .loc directive understood by GNU as. */
11917 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11919 /* Indicate that line number info exists. */
11920 line_info_table_in_use++;
11922 /* Indicate that multiple line number tables exist. */
11923 if (DECL_SECTION_NAME (current_function_decl))
11924 separate_line_info_table_in_use++;
11926 else if (DECL_SECTION_NAME (current_function_decl))
11928 dw_separate_line_info_ref line_info;
11929 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11930 separate_line_info_table_in_use);
11932 /* expand the line info table if necessary */
11933 if (separate_line_info_table_in_use
11934 == separate_line_info_table_allocated)
11936 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11937 separate_line_info_table
11938 = (dw_separate_line_info_ref)
11939 xrealloc (separate_line_info_table,
11940 separate_line_info_table_allocated
11941 * sizeof (dw_separate_line_info_entry));
11944 /* Add the new entry at the end of the line_info_table. */
11945 line_info
11946 = &separate_line_info_table[separate_line_info_table_in_use++];
11947 line_info->dw_file_num = lookup_filename (filename);
11948 line_info->dw_line_num = line;
11949 line_info->function = current_function_funcdef_no;
11951 else
11953 dw_line_info_ref line_info;
11955 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11956 line_info_table_in_use);
11958 /* Expand the line info table if necessary. */
11959 if (line_info_table_in_use == line_info_table_allocated)
11961 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11962 line_info_table
11963 = (dw_line_info_ref)
11964 xrealloc (line_info_table,
11965 (line_info_table_allocated
11966 * sizeof (dw_line_info_entry)));
11969 /* Add the new entry at the end of the line_info_table. */
11970 line_info = &line_info_table[line_info_table_in_use++];
11971 line_info->dw_file_num = lookup_filename (filename);
11972 line_info->dw_line_num = line;
11977 /* Record the beginning of a new source file. */
11979 static void
11980 dwarf2out_start_source_file (lineno, filename)
11981 unsigned int lineno;
11982 const char *filename;
11984 if (flag_eliminate_dwarf2_dups)
11986 /* Record the beginning of the file for break_out_includes. */
11987 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
11988 add_AT_string (bincl_die, DW_AT_name, filename);
11991 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11993 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11994 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
11995 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
11996 lineno);
11997 dw2_asm_output_data_uleb128 (lookup_filename (filename),
11998 "Filename we just started");
12002 /* Record the end of a source file. */
12004 static void
12005 dwarf2out_end_source_file (lineno)
12006 unsigned int lineno ATTRIBUTE_UNUSED;
12008 if (flag_eliminate_dwarf2_dups)
12009 /* Record the end of the file for break_out_includes. */
12010 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
12012 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12014 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12015 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12019 /* Called from debug_define in toplev.c. The `buffer' parameter contains
12020 the tail part of the directive line, i.e. the part which is past the
12021 initial whitespace, #, whitespace, directive-name, whitespace part. */
12023 static void
12024 dwarf2out_define (lineno, buffer)
12025 unsigned lineno ATTRIBUTE_UNUSED;
12026 const char *buffer ATTRIBUTE_UNUSED;
12028 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12030 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12031 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
12032 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
12033 dw2_asm_output_nstring (buffer, -1, "The macro");
12037 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
12038 the tail part of the directive line, i.e. the part which is past the
12039 initial whitespace, #, whitespace, directive-name, whitespace part. */
12041 static void
12042 dwarf2out_undef (lineno, buffer)
12043 unsigned lineno ATTRIBUTE_UNUSED;
12044 const char *buffer ATTRIBUTE_UNUSED;
12046 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12048 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12049 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
12050 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
12051 dw2_asm_output_nstring (buffer, -1, "The macro");
12055 /* Set up for Dwarf output at the start of compilation. */
12057 static void
12058 dwarf2out_init (main_input_filename)
12059 const char *main_input_filename;
12061 init_file_table ();
12063 /* Remember the name of the primary input file. */
12064 primary_filename = main_input_filename;
12066 /* Add it to the file table first, under the assumption that we'll
12067 be emitting line number data for it first, which avoids having
12068 to add an initial DW_LNS_set_file. */
12069 lookup_filename (main_input_filename);
12071 /* Allocate the initial hunk of the decl_die_table. */
12072 decl_die_table
12073 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
12074 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
12075 decl_die_table_in_use = 0;
12077 /* Allocate the initial hunk of the decl_scope_table. */
12078 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
12080 /* Allocate the initial hunk of the abbrev_die_table. */
12081 abbrev_die_table
12082 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
12083 sizeof (dw_die_ref));
12084 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
12085 /* Zero-th entry is allocated, but unused */
12086 abbrev_die_table_in_use = 1;
12088 /* Allocate the initial hunk of the line_info_table. */
12089 line_info_table
12090 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
12091 sizeof (dw_line_info_entry));
12092 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
12094 /* Zero-th entry is allocated, but unused */
12095 line_info_table_in_use = 1;
12097 /* Generate the initial DIE for the .debug section. Note that the (string)
12098 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
12099 will (typically) be a relative pathname and that this pathname should be
12100 taken as being relative to the directory from which the compiler was
12101 invoked when the given (base) source file was compiled. */
12102 comp_unit_die = gen_compile_unit_die (main_input_filename);
12104 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
12106 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
12108 ggc_add_root (&limbo_die_list, 1, 1, mark_limbo_die_list);
12110 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
12111 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
12112 DEBUG_ABBREV_SECTION_LABEL, 0);
12113 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12114 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
12115 else
12116 strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME));
12118 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
12119 DEBUG_INFO_SECTION_LABEL, 0);
12120 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
12121 DEBUG_LINE_SECTION_LABEL, 0);
12122 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
12123 DEBUG_RANGES_SECTION_LABEL, 0);
12124 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12125 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
12126 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
12127 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
12128 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12129 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
12131 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12133 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12134 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
12135 DEBUG_MACINFO_SECTION_LABEL, 0);
12136 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
12139 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12141 text_section ();
12142 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
12146 /* Allocate a string in .debug_str hash table. */
12148 static hashnode
12149 indirect_string_alloc (tab)
12150 hash_table *tab ATTRIBUTE_UNUSED;
12152 struct indirect_string_node *node;
12154 node = xmalloc (sizeof (struct indirect_string_node));
12155 node->refcount = 0;
12156 node->form = 0;
12157 node->label = NULL;
12159 return (hashnode) node;
12162 /* A helper function for dwarf2out_finish called through
12163 ht_forall. Emit one queued .debug_str string. */
12165 static int
12166 output_indirect_string (pfile, h, v)
12167 struct cpp_reader *pfile ATTRIBUTE_UNUSED;
12168 hashnode h;
12169 const PTR v ATTRIBUTE_UNUSED;
12171 struct indirect_string_node *node = (struct indirect_string_node *) h;
12173 if (node->form == DW_FORM_strp)
12175 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
12176 ASM_OUTPUT_LABEL (asm_out_file, node->label);
12177 assemble_string ((const char *) HT_STR (&node->id),
12178 HT_LEN (&node->id) + 1);
12181 return 1;
12184 /* Output stuff that dwarf requires at the end of every file,
12185 and generate the DWARF-2 debugging info. */
12187 static void
12188 dwarf2out_finish (input_filename)
12189 const char *input_filename ATTRIBUTE_UNUSED;
12191 limbo_die_node *node, *next_node;
12192 dw_die_ref die = 0;
12194 /* Traverse the limbo die list, and add parent/child links. The only
12195 dies without parents that should be here are concrete instances of
12196 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12197 For concrete instances, we can get the parent die from the abstract
12198 instance. */
12199 for (node = limbo_die_list; node; node = next_node)
12201 next_node = node->next;
12202 die = node->die;
12204 if (die->die_parent == NULL)
12206 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
12207 tree context;
12209 if (origin)
12210 add_child_die (origin->die_parent, die);
12211 else if (die == comp_unit_die)
12213 /* If this was an expression for a bound involved in a function
12214 return type, it may be a SAVE_EXPR for which we weren't able
12215 to find a DIE previously. So try now. */
12216 else if (node->created_for
12217 && TREE_CODE (node->created_for) == SAVE_EXPR
12218 && 0 != (origin = (lookup_decl_die
12219 (SAVE_EXPR_CONTEXT
12220 (node->created_for)))))
12221 add_child_die (origin, die);
12222 else if (errorcount > 0 || sorrycount > 0)
12223 /* It's OK to be confused by errors in the input. */
12224 add_child_die (comp_unit_die, die);
12225 else if (node->created_for
12226 && ((DECL_P (node->created_for)
12227 && (context = DECL_CONTEXT (node->created_for)))
12228 || (TYPE_P (node->created_for)
12229 && (context = TYPE_CONTEXT (node->created_for))))
12230 && TREE_CODE (context) == FUNCTION_DECL)
12232 /* In certain situations, the lexical block containing a
12233 nested function can be optimized away, which results
12234 in the nested function die being orphaned. Likewise
12235 with the return type of that nested function. Force
12236 this to be a child of the containing function. */
12237 origin = lookup_decl_die (context);
12238 if (! origin)
12239 abort ();
12240 add_child_die (origin, die);
12242 else
12243 abort ();
12246 free (node);
12249 limbo_die_list = NULL;
12251 /* Walk through the list of incomplete types again, trying once more to
12252 emit full debugging info for them. */
12253 retry_incomplete_types ();
12255 /* We need to reverse all the dies before break_out_includes, or
12256 we'll see the end of an include file before the beginning. */
12257 reverse_all_dies (comp_unit_die);
12259 /* Generate separate CUs for each of the include files we've seen.
12260 They will go into limbo_die_list. */
12261 if (flag_eliminate_dwarf2_dups)
12262 break_out_includes (comp_unit_die);
12264 /* Traverse the DIE's and add add sibling attributes to those DIE's
12265 that have children. */
12266 add_sibling_attributes (comp_unit_die);
12267 for (node = limbo_die_list; node; node = node->next)
12268 add_sibling_attributes (node->die);
12270 /* Output a terminator label for the .text section. */
12271 text_section ();
12272 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
12274 /* Output the source line correspondence table. We must do this
12275 even if there is no line information. Otherwise, on an empty
12276 translation unit, we will generate a present, but empty,
12277 .debug_info section. IRIX 6.5 `nm' will then complain when
12278 examining the file. */
12279 if (! DWARF2_ASM_LINE_DEBUG_INFO)
12281 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12282 output_line_info ();
12285 /* Output location list section if necessary. */
12286 if (have_location_lists)
12288 /* Output the location lists info. */
12289 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
12290 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
12291 DEBUG_LOC_SECTION_LABEL, 0);
12292 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
12293 output_location_lists (die);
12294 have_location_lists = 0;
12297 /* We can only use the low/high_pc attributes if all of the code was
12298 in .text. */
12299 if (separate_line_info_table_in_use == 0)
12301 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
12302 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
12305 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12306 "base address". Use zero so that these addresses become absolute. */
12307 else if (have_location_lists || ranges_table_in_use)
12308 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
12310 if (debug_info_level >= DINFO_LEVEL_NORMAL)
12311 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
12312 debug_line_section_label);
12314 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12315 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
12317 /* Output all of the compilation units. We put the main one last so that
12318 the offsets are available to output_pubnames. */
12319 for (node = limbo_die_list; node; node = node->next)
12320 output_comp_unit (node->die);
12322 output_comp_unit (comp_unit_die);
12324 /* Output the abbreviation table. */
12325 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12326 output_abbrev_section ();
12328 /* Output public names table if necessary. */
12329 if (pubname_table_in_use)
12331 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
12332 output_pubnames ();
12335 /* Output the address range information. We only put functions in the arange
12336 table, so don't write it out if we don't have any. */
12337 if (fde_table_in_use)
12339 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
12340 output_aranges ();
12343 /* Output ranges section if necessary. */
12344 if (ranges_table_in_use)
12346 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
12347 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
12348 output_ranges ();
12351 /* Have to end the primary source file. */
12352 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12354 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12355 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12356 dw2_asm_output_data (1, 0, "End compilation unit");
12359 /* If we emitted any DW_FORM_strp form attribute, output the string
12360 table too. */
12361 if (debug_str_hash)
12362 ht_forall (debug_str_hash, output_indirect_string, NULL);
12364 #else
12366 /* This should never be used, but its address is needed for comparisons. */
12367 const struct gcc_debug_hooks dwarf2_debug_hooks;
12369 #endif /* DWARF2_DEBUGGING_INFO */
12371 #include "gt-dwarf2out.h"